Pārlūkot izejas kodu

CreateXXX() takes in account the facetData partitioning changes

jbousquie 8 gadi atpakaļ
vecāks
revīzija
e42ab8e13f
2 mainītis faili ar 37 papildinājumiem un 17 dzēšanām
  1. 31 13
      src/Mesh/babylon.mesh.ts
  2. 6 4
      src/Mesh/babylon.meshBuilder.ts

+ 31 - 13
src/Mesh/babylon.mesh.ts

@@ -135,18 +135,15 @@
         public get facetNb(): number {
             return this._facetNb;
         }
-
         /**
          * The number of subdivisions per axis in the partioning space
          */
         public get partitioningSubdivisions(): number {
             return this._partitioningSubdivisions;
         }
-
         public set partitioningSubdivisions(nb: number) {
             this._partitioningSubdivisions = nb;
         } 
-
         /**
          * The ratio to apply to the bouding box size to set to the partioning space.  
          * Ex : 1.01 (default) the partioning space is 1% bigger than the bounding box.
@@ -154,10 +151,15 @@
         public get partitioningBBoxRatio(): number {
             return this._partitioningBBoxRatio;
         }
-
         public set partitioningBBoxRatio(ratio: number) {
             this._partitioningBBoxRatio = ratio;
         }
+        /**
+         * Read-only : is the feature facetData enabled ?
+         */
+        public get isFacetDataEnabled(): boolean {
+            return this._facetDataEnabled;
+        }
 
         // Will be used to save a source mesh reference, If any
         private _source: BABYLON.Mesh = null; 
@@ -1828,16 +1830,8 @@
             var positions = this.getVerticesData(VertexBuffer.PositionKind);
             var indices = this.getIndices();
             var normals = this.getVerticesData(VertexBuffer.NormalKind);
-            var options = {
-                facetNormals: this.getFacetLocalNormals(), 
-                facetPositions: this.getFacetLocalPositions(), 
-                facetPartitioning: this._facetPartitioning, 
-                bInfo: this.getBoundingInfo(),
-                ratio: this._partitioningBBoxRatio,
-                partitioningSubdivisions: this._partitioningSubdivisions
-            };
+            var options = this.getFacetDataParameters();
             VertexData.ComputeNormals(positions, indices, normals, options);
-            this.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
             return this;
         }
         /**
@@ -1861,6 +1855,15 @@
             return this._facetPositions;           
         }
         /**
+         * Returns the facetLocalPartioning array
+         */
+        public getFacetLocalPartitioning(): number[][] {
+            if (!this._facetPartitioning) {
+                this.updateFacetData();
+            }
+            return this._facetPartitioning;
+        }
+        /**
          * Returns the i-th facet position in the world system.
          * This method allocates a new Vector3 per call.
          */
@@ -1998,6 +2001,21 @@
             }
             return closest;
         }
+        /**
+         * Returns object "parameter" set with all the required parameters for facetData computation with ComputeNormals()
+         */
+        public getFacetDataParameters(): any {
+            var params = {
+                facetNormals: this.getFacetLocalNormals(), 
+                facetPositions: this.getFacetLocalPositions(),
+                facetPartitioning: this.getFacetLocalPartitioning(),
+                bInfo: this.getBoundingInfo(),
+                partitioningSubdivisions: this.partitioningSubdivisions,
+                ratio: this.partitioningBBoxRatio
+            };
+            return params;
+        }
+
         // Statics
         /**
          * Returns a new Mesh object what is a deep copy of the passed mesh. 

+ 6 - 4
src/Mesh/babylon.meshBuilder.ts

@@ -187,10 +187,11 @@
                 instance._boundingInfo = new BoundingInfo(Tmp.Vector3[0], Tmp.Vector3[1]);
                 instance._boundingInfo.update(instance._worldMatrix);
                 instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);
-                if (!(instance.areNormalsFrozen)) {
+                if (!(instance.areNormalsFrozen) || instance.isFacetDataEnabled) {
                     var indices = instance.getIndices();
                     var normals = instance.getVerticesData(VertexBuffer.NormalKind);
-                    VertexData.ComputeNormals(positions, indices, normals);
+                    var params = instance.isFacetDataEnabled ? instance.getFacetDataParameters() : null;
+                    VertexData.ComputeNormals(positions, indices, normals, params);
 
                     if ((<any>instance)._closePath) {
                         var indexFirst: number = 0;
@@ -211,8 +212,9 @@
                             normals[indexLast + 2] = normals[indexFirst + 2];
                         }
                     }
-
-                    instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
+                    if (!(instance.areNormalsFrozen)) {
+                        instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
+                    }
                 }
 
                 return instance;