Преглед на файлове

added Lines mesh position update

jbousquie преди 10 години
родител
ревизия
a87a252982
променени са 1 файла, в които са добавени 35 реда и са изтрити 11 реда
  1. 35 11
      Babylon/Mesh/babylon.mesh.ts

+ 35 - 11
Babylon/Mesh/babylon.mesh.ts

@@ -434,14 +434,16 @@
         // updates the mesh positions according to the positionFunction returned values.
         // updates the mesh positions according to the positionFunction returned values.
         // The positionFunction argument must be a javascript function accepting the mesh "positions" array as parameter.
         // The positionFunction argument must be a javascript function accepting the mesh "positions" array as parameter.
         // This dedicated positionFunction computes new mesh positions according to the given mesh type.
         // This dedicated positionFunction computes new mesh positions according to the given mesh type.
-        public updateMeshPositions(positionFunction): void {
+        public updateMeshPositions(positionFunction, computeNormals: boolean = true): void {
             var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             var positions = this.getVerticesData(BABYLON.VertexBuffer.PositionKind);
             positionFunction(positions);
             positionFunction(positions);
-            var indices = this.getIndices();
-            var normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
             this.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
             this.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
-            BABYLON.VertexData.ComputeNormals(positions, indices, normals);
-            this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
+            if (computeNormals) {
+                var indices = this.getIndices();
+                var normals = this.getVerticesData(BABYLON.VertexBuffer.NormalKind);
+                BABYLON.VertexData.ComputeNormals(positions, indices, normals);
+                this.updateVerticesData(BABYLON.VertexBuffer.NormalKind, normals, false, false);
+            }
         }
         }
 
 
 
 
@@ -1195,7 +1197,7 @@
                 };
                 };
                 var sideOrientation = ribbonInstance.sideOrientation;
                 var sideOrientation = ribbonInstance.sideOrientation;
                 var positionFunction = positionsOfRibbon(pathArray, sideOrientation);
                 var positionFunction = positionsOfRibbon(pathArray, sideOrientation);
-                ribbonInstance.updateMeshPositions(positionFunction);
+                ribbonInstance.updateMeshPositions(positionFunction, true);
 
 
                 return ribbonInstance;
                 return ribbonInstance;
 
 
@@ -1270,14 +1272,36 @@
         }
         }
 
 
         // Lines
         // Lines
-        public static CreateLines(name: string, points: Vector3[], scene: Scene, updatable?: boolean): LinesMesh {
-            var lines = new LinesMesh(name, scene, updatable);
+        public static CreateLines(name: string, points: Vector3[], scene: Scene, updatable?: boolean, linesInstance: LinesMesh = null): LinesMesh {
+            if (linesInstance) { // lines update
+                var positionsOfLines = function(points) {
+                    var positionFunction = function(positions) {
+                        var i = 0;
+                        for(var p = 0; p < points.length; p++) {
+                            positions[i] = points[p].x;
+                            positions[i + 1] = points[p].y;
+                            positions[i + 2] = points[p].z;
+                            i += 3;
+                        }
+                    };
+                    return positionFunction;
+                };
+                var positionFunction = positionsOfLines(points);
+                linesInstance.updateMeshPositions(positionFunction, false);
+
+                return linesInstance;
+
+            }
+            else { // lines creation
+
+                var lines = new LinesMesh(name, scene, updatable);
 
 
-            var vertexData = VertexData.CreateLines(points);
+                var vertexData = VertexData.CreateLines(points);
 
 
-            vertexData.applyToMesh(lines, updatable);
+                vertexData.applyToMesh(lines, updatable);
 
 
-            return lines;
+                return lines;
+            }
         }
         }
 
 
         // Extrusion
         // Extrusion