Forráskód Böngészése

updated Mesh.CreateDashSize call signature : supports now options parameter

jbousquie 10 éve
szülő
commit
3bb10bf45e
1 módosított fájl, 42 hozzáadás és 16 törlés
  1. 42 16
      src/Mesh/babylon.mesh.ts

+ 42 - 16
src/Mesh/babylon.mesh.ts

@@ -1261,12 +1261,14 @@
                 }
             } else {
                 pathArray = options;
-                options = {
-                    pathArray: pathArray,
-                    closeArray: closeArrayOrScene,
-                    closePath: closePath,
-                    offset: offset,
-                    sideOrientation: sideOrientation
+                if (!instance) {
+                    options = {
+                        pathArray: pathArray,
+                        closeArray: closeArrayOrScene,
+                        closePath: closePath,
+                        offset: offset,
+                        sideOrientation: sideOrientation
+                    }
                 }
             }
 
@@ -1511,9 +1513,10 @@
             var points: Vector3[];
             if (Array.isArray(options)) {
                 points = options;
-                options = {
-                    points: points,
-                    instance: instance
+                if (!instance) {
+                    options = {
+                        points: points
+                    }
                 }
             } else {
                 instance = options.instance;
@@ -1542,8 +1545,31 @@
         }
 
         // Dashed Lines
-        public static CreateDashedLines(name: string, points: Vector3[], dashSize: number, gapSize: number, dashNb: number, scene: Scene, updatable?: boolean, linesInstance: LinesMesh = null): LinesMesh {
-            if (linesInstance) {  //  dashed lines update
+        public static CreateDashedLines(name: string, points: Vector3[], dashSize: number, gapSize: number, dashNb: number, scene: Scene, updatable?: boolean, instance?: LinesMesh): LinesMesh;
+        public static CreateDashedLines(name: string, options: { points: Vector3[], dashSize?: number, gapSize?: number, dashNb?: number, updatable?: boolean, instance?: LinesMesh }, scene: Scene): LinesMesh;
+        public static CreateDashedLines(name: string, options: any, dashSizeOrScene: any, gapSize?: number, dashNb?: number, scene?: Scene, updatable?: boolean, instance?: LinesMesh):LinesMesh {
+            var points: Vector3[];
+            var dashSize: number;
+            if (Array.isArray(options)) {
+                points = options;
+                dashSize = dashSizeOrScene;
+                if (!instance) {
+                    options = {
+                        points: points,
+                        dashSize: dashSize,
+                        gapSize: gapSize,
+                        dashNb: dashNb
+                    }    
+                }
+            } else {
+                scene = dashSizeOrScene,
+                points = options.points;
+                instance = options.instance;
+                gapSize = options.gapSize;
+                dashNb = options.dashNb;
+                dashSize = options.dashSize;
+            }
+            if (instance) {  //  dashed lines update
                 var positionFunction = (positions: number[]): void => {
                     var curvect = Vector3.Zero();
                     var nbSeg = positions.length / 6;
@@ -1560,7 +1586,7 @@
                         lg += curvect.length();
                     }
                     shft = lg / nbSeg;
-                    dashshft = (<any>linesInstance).dashSize * shft / ((<any>linesInstance).dashSize + (<any>linesInstance).gapSize);
+                    dashshft = (<any>instance).dashSize * shft / ((<any>instance).dashSize + (<any>instance).gapSize);
                     for (i = 0; i < points.length - 1; i++) {
                         points[i + 1].subtractToRef(points[i], curvect);
                         nb = Math.floor(curvect.length() / shft);
@@ -1585,13 +1611,13 @@
                         p += 3;
                     }
                 };
-                linesInstance.updateMeshPositions(positionFunction, false);
-                return linesInstance;
+                instance.updateMeshPositions(positionFunction, false);
+                return instance;
             }
             // dashed lines creation
             var dashedLines = new LinesMesh(name, scene);
-            var vertexData = VertexData.CreateDashedLines(points, dashSize, gapSize, dashNb);
-            vertexData.applyToMesh(dashedLines, updatable);
+            var vertexData = VertexData.CreateDashedLines(options);
+            vertexData.applyToMesh(dashedLines, updatable || options.updatable);
             (<any>dashedLines).dashSize = dashSize;
             (<any>dashedLines).gapSize = gapSize;
             return dashedLines;