浏览代码

Fix issue with facet depth sorting

David Catuhe 6 年之前
父节点
当前提交
bbaad2eb1b
共有 3 个文件被更改,包括 12 次插入6 次删除
  1. 4 2
      src/Meshes/abstractMesh.ts
  2. 5 2
      src/Meshes/geometry.ts
  3. 3 2
      src/Meshes/mesh.ts

+ 4 - 2
src/Meshes/abstractMesh.ts

@@ -1793,7 +1793,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
                 data.depthSortedIndices[f * 3 + 1] = indices![sind + 1];
                 data.depthSortedIndices[f * 3 + 2] = indices![sind + 2];
             }
-            this.updateIndices(data.depthSortedIndices);
+            this.updateIndices(data.depthSortedIndices, undefined, true);
         }
 
         return this;
@@ -2032,9 +2032,11 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
     /**
      * Updates the AbstractMesh indices array
      * @param indices defines the data source
+     * @param offset defines the offset in the index buffer where to store the new data (can be null)
+     * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)
      * @returns the current mesh
      */
-    public updateIndices(indices: IndicesArray): AbstractMesh {
+    public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): AbstractMesh {
         return this;
     }
 

+ 5 - 2
src/Meshes/geometry.ts

@@ -523,8 +523,9 @@ export class Geometry implements IGetSetVerticesData {
      * Update index buffer
      * @param indices defines the indices to store in the index buffer
      * @param offset defines the offset in the target buffer where to store the data
+     * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)
      */
-    public updateIndices(indices: IndicesArray, offset?: number): void {
+    public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): void {
         if (!this._indexBuffer) {
             return;
         }
@@ -534,7 +535,9 @@ export class Geometry implements IGetSetVerticesData {
         } else {
             const needToUpdateSubMeshes = indices.length !== this._indices.length;
 
-            this._indices = indices;
+            if (!gpuMemoryOnly) {
+                this._indices = indices.slice();
+            }
             this._engine.updateDynamicIndexBuffer(this._indexBuffer, indices, offset);
             if (needToUpdateSubMeshes) {
                 for (const mesh of this._meshes) {

+ 3 - 2
src/Meshes/mesh.ts

@@ -1238,14 +1238,15 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
      * Update the current index buffer
      * @param indices defines the source data
      * @param offset defines the offset in the index buffer where to store the new data (can be null)
+     * @param gpuMemoryOnly defines a boolean indicating that only the GPU memory must be updated leaving the CPU version of the indices unchanged (false by default)
      * @returns the current mesh
      */
-    public updateIndices(indices: IndicesArray, offset?: number): Mesh {
+    public updateIndices(indices: IndicesArray, offset?: number, gpuMemoryOnly = false): Mesh {
         if (!this._geometry) {
             return this;
         }
 
-        this._geometry.updateIndices(indices, offset);
+        this._geometry.updateIndices(indices, offset, gpuMemoryOnly);
         return this;
     }