Browse Source

Fix indices merger

David Catuhe 7 years ago
parent
commit
fa6b16b36c
2 changed files with 11 additions and 10 deletions
  1. 8 8
      src/Mesh/babylon.mesh.ts
  2. 3 2
      src/Mesh/babylon.mesh.vertexData.ts

+ 8 - 8
src/Mesh/babylon.mesh.ts

@@ -3421,11 +3421,11 @@
 
         /**
          * Merge the array of meshes into a single mesh for performance reasons.
-         * @param {Array<Mesh>} meshes - The vertices source.  They should all be of the same material.  Entries can empty
-         * @param {boolean} disposeSource - When true (default), dispose of the vertices from the source meshes
-         * @param {boolean} allow32BitsIndices - When the sum of the vertices > 64k, this must be set to true.
-         * @param {Mesh} meshSubclass - When set, vertices inserted into this Mesh.  Meshes can then be merged into a Mesh sub-class.
-         * @param {boolean} subdivideWithSubMeshes - When true (false default), subdivide mesh to his subMesh array with meshes source.
+         * @param meshes - The vertices source.  They should all be of the same material.  Entries can empty
+         * @param disposeSource - When true (default), dispose of the vertices from the source meshes
+         * @param allow32BitsIndices - When the sum of the vertices > 64k, this must be set to true.
+         * @param meshSubclass - When set, vertices inserted into this Mesh.  Meshes can then be merged into a Mesh sub-class.
+         * @param subdivideWithSubMeshes - When true (false default), subdivide mesh to his subMesh array with meshes source.
          */
         public static MergeMeshes(meshes: Array<Mesh>, disposeSource = true, allow32BitsIndices?: boolean, meshSubclass?: Mesh, subdivideWithSubMeshes?: boolean): Nullable<Mesh> {
             var index: number;
@@ -3452,12 +3452,12 @@
             var source: Nullable<Mesh> = null;
             for (index = 0; index < meshes.length; index++) {
                 if (meshes[index]) {
-                    meshes[index].computeWorldMatrix(true);
+                    const wm = meshes[index].computeWorldMatrix(true);
                     otherVertexData = VertexData.ExtractFromMesh(meshes[index], true, true);
-                    otherVertexData.transform(meshes[index].getWorldMatrix());
+                    otherVertexData.transform(wm);
 
                     if (vertexData) {
-                        vertexData.merge(otherVertexData);
+                        vertexData.merge(otherVertexData, allow32BitsIndices);
                     } else {
                         vertexData = otherVertexData;
                         source = meshes[index];

+ 3 - 2
src/Mesh/babylon.mesh.vertexData.ts

@@ -384,9 +384,10 @@
         /**
          * Merges the passed VertexData into the current one
          * @param other the VertexData to be merged into the current one  
+         * @param use32BitsIndices defines a boolean indicating if indices must be store in a 32 bits array
          * @returns the modified VertexData 
          */
-        public merge(other: VertexData): VertexData {
+        public merge(other: VertexData, use32BitsIndices = false): VertexData {
             this._validate();
             other._validate();
 
@@ -418,7 +419,7 @@
 
                 if (isSrcTypedArray) {
                     var len = this.indices.length + other.indices.length;
-                    var temp = this.indices instanceof Uint32Array ? new Uint32Array(len) : new Uint16Array(len);
+                    var temp = use32BitsIndices || this.indices instanceof Uint32Array ? new Uint32Array(len) : new Uint16Array(len);
                     temp.set(this.indices);
 
                     let decal = this.indices.length;