Write position bounds to gltf file.

This commit is contained in:
Viktor Kovacs 2021-03-28 16:30:02 +02:00
parent a35bceadea
commit b4832a7cd0
3 changed files with 20 additions and 1 deletions

View File

@ -267,6 +267,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
material : primitive.material
};
let bounds = primitive.GetBounds ();
mainJson.accessors.push ({
bufferView : bufferViewIndex,
byteOffset : 0,
@ -279,6 +280,8 @@ OV.ExporterGltf = class extends OV.ExporterBase
byteOffset : 0,
componentType : this.components.number.type,
count : primitive.vertices.length / 3,
min : bounds.min,
max : bounds.max,
type : 'VEC3'
});
mainJson.accessors.push ({

View File

@ -17,7 +17,7 @@ OV.BinaryWriter = class
{
this.position = position;
}
End ()
{
return this.position >= this.arrayBuffer.byteLength;

View File

@ -9,6 +9,22 @@ OV.MeshPrimitiveBuffer = class
this.material = null;
}
GetBounds ()
{
let min = [Infinity, Infinity, Infinity];
let max = [-Infinity, -Infinity, -Infinity];
for (let i = 0; i < this.vertices.length / 3; i++) {
for (let j = 0; j < 3; j++) {
min[j] = Math.min (min[j], this.vertices[i * 3 + j]);
max[j] = Math.max (max[j], this.vertices[i * 3 + j]);
}
}
return {
min : min,
max : max
}
}
GetByteLength (indexTypeSize, numberTypeSize)
{
let indexCount = this.indices.length;