瀏覽代碼

new mesh type : LineSystem

jbousquie 9 年之前
父節點
當前提交
5200488655
共有 2 個文件被更改,包括 53 次插入1 次删除
  1. 25 1
      src/Mesh/babylon.mesh.vertexData.ts
  2. 28 0
      src/Mesh/babylon.meshBuilder.ts

+ 25 - 1
src/Mesh/babylon.mesh.vertexData.ts

@@ -1106,7 +1106,31 @@
 
             return vertexData;
         }
-
+        
+        public static CreateLineSystem(options: {lines: Vector3[][]}): VertexData {
+            var indices = [];
+            var positions = [];
+            var lines = options.lines;
+            var idx = 0;
+            
+            for (var l = 0; l < lines.length; l++) {
+                var points = lines[l];
+                for (var index = 0; index < points.length; index++) {
+                    positions.push(points[index].x, points[index].y, points[index].z);
+                    
+                    if (index > 0) {
+                        indices.push(idx - 1);
+                        indices.push(idx);
+                    }
+                    idx ++;
+                }               
+            }
+            var vertexData = new VertexData();
+            vertexData.indices = indices;
+            vertexData.positions = positions;
+            return vertexData;
+        }
+        
         public static CreateLines(options: { points: Vector3[] }): VertexData {
             var indices = [];
             var positions = [];

+ 28 - 0
src/Mesh/babylon.meshBuilder.ts

@@ -151,6 +151,34 @@
 
             return torusKnot;
         }
+        
+        public static CreateLineSystem(name: string, options: {lines: Vector3[][], updatable: boolean, instance?: LinesMesh}, scene: Scene): LinesMesh {
+            var instance = options.instance;
+            var lines = options.lines;
+            
+            if (instance) { // lines update
+                var positionFunction = positions => {
+                    var i = 0;
+                    for (var l = 0; l < lines.length; l++) {
+                        var points = lines[l];
+                        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;
+                        }
+                    }
+                };
+                instance.updateMeshPositions(positionFunction, false);
+                return instance;
+            }
+            
+            // line system creation
+            var lineSystem = new LinesMesh(name, scene);
+            var vertexData = VertexData.CreateLineSystem(options);
+            vertexData.applyToMesh(lineSystem, options.updatable);
+            return lineSystem;
+        }
 
         public static CreateLines(name: string, options: { points: Vector3[], updatable?: boolean, instance?: LinesMesh }, scene: Scene): LinesMesh {
             var instance = options.instance;