瀏覽代碼

Merge pull request #5644 from barroij/IndexBufferSizeBug

Index buffer size bug
sebavan 6 年之前
父節點
當前提交
17613f89ec
共有 2 個文件被更改,包括 13 次插入6 次删除
  1. 2 1
      dist/preview release/what's new.md
  2. 11 5
      src/Mesh/babylon.geometry.ts

+ 2 - 1
dist/preview release/what's new.md

@@ -84,7 +84,7 @@
 - Add support for setting renderingGroupId and creating instances to `AxesViewer` ([bghgary](https://github.com/bghgary))
 - Invert vScale of compressed ktx textures as they are inverted in the file and UNPACK_FLIP_Y_WEBGL is not supported by ktx ([TrevorDev](https://github.com/TrevorDev))
 - Enable dragging in boundingBoxGizmo without needing a parent ([TrevorDev](https://github.com/TrevorDev))
-- Added per mesh culling strategy ([jerome](https://github.com/jbousquie))  
+- Added per mesh culling strategy ([jerome](https://github.com/jbousquie))
 
 ### glTF Loader
 
@@ -145,6 +145,7 @@
 - Update Picking so that when the picked Mesh is a LinesMesh, the index of the picked line is returned in the `faceId` property of the `PickingInfo`, as we do with face index the picked Mesh is made of triangle faces ([barroij](https://github.com/barroij))
 - Do not clone mesh observables ([Sebavan](https://github.com/Sebavan))
 - Fixed Inspector resolution with AMD loader ([Sebavan](https://github.com/Sebavan))
+- Fix a bug when a call to `updateIndices` leads to changing the size of the index buffer by recreating the subMeshes in that case ([barroij](https://github.com/barroij))
 
 ### Viewer
 

+ 11 - 5
src/Mesh/babylon.geometry.ts

@@ -516,7 +516,15 @@ module BABYLON {
             if (!this._indexBufferIsUpdatable) {
                 this.setIndices(indices, null, true);
             } else {
+                const needToUpdateSubMeshes = indices.length !== this._indices.length;
+
+                this._indices = indices;
                 this._engine.updateDynamicIndexBuffer(this._indexBuffer, indices, offset);
+                if (needToUpdateSubMeshes) {
+                    for (const mesh of this._meshes) {
+                        mesh._createGlobalSubMesh(true);
+                    }
+                }
             }
         }
 
@@ -543,12 +551,10 @@ module BABYLON {
                 this._totalVertices = totalVertices;
             }
 
-            var meshes = this._meshes;
-            var numOfMeshes = meshes.length;
-
-            for (var index = 0; index < numOfMeshes; index++) {
-                meshes[index]._createGlobalSubMesh(true);
+            for (const mesh of this._meshes) {
+                mesh._createGlobalSubMesh(true);
             }
+
             this.notifyUpdate();
         }