diff --git a/source/export/exportergltf.js b/source/export/exportergltf.js index 16a77a0..c009e63 100644 --- a/source/export/exportergltf.js +++ b/source/export/exportergltf.js @@ -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 ({ diff --git a/source/io/binarywriter.js b/source/io/binarywriter.js index 45db254..7655e80 100644 --- a/source/io/binarywriter.js +++ b/source/io/binarywriter.js @@ -17,7 +17,7 @@ OV.BinaryWriter = class { this.position = position; } - + End () { return this.position >= this.arrayBuffer.byteLength; diff --git a/source/model/meshbuffer.js b/source/model/meshbuffer.js index df203a4..cadc6f6 100644 --- a/source/model/meshbuffer.js +++ b/source/model/meshbuffer.js @@ -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;