瀏覽代碼

Merge pull request #703 from jbousquie/feature.Options_Parameter_On_CreateXXX_Methods

Feature.options parameter on create xxx methods
David Catuhe 10 年之前
父節點
當前提交
ea52264d52
共有 2 個文件被更改,包括 76 次插入30 次删除
  1. 56 24
      src/Mesh/babylon.mesh.ts
  2. 20 6
      src/Mesh/babylon.mesh.vertexData.ts

+ 56 - 24
src/Mesh/babylon.mesh.ts

@@ -1246,14 +1246,37 @@
         }
         }
 
 
         // Statics
         // Statics
-        public static CreateRibbon(name: string, pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number, scene: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE, ribbonInstance: Mesh = null): Mesh {
-            if (ribbonInstance) {   // existing ribbon instance update
+        public static CreateRibbon(name: string, pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number, scene: Scene, updatable?: boolean, sideOrientation?: number, instance?: Mesh): Mesh;
+        public static CreateRibbon(name: string, options: {pathArray?: Vector3[][], closeArray?: boolean, closePath?: boolean, offset?: number, updatable?: boolean, sideOrientation?: number, instance?: Mesh}, scene: Scene): Mesh;
+        public static CreateRibbon(name: string, options: any, closeArrayOrScene: any, closePath?: boolean, offset?: number, scene?: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE, instance: Mesh = null): Mesh {
+            var pathArray;
+            if (closeArrayOrScene instanceof Scene) {
+                scene = closeArrayOrScene;
+                updatable = options.updatable;
+                if (options.instance) { // instance case
+                    pathArray = options.pathArray;
+                    instance = options.instance;
+                    closePath = options.closePath;
+                    var closeArray = options.closeArray;
+                }
+            } else {
+                pathArray = options;
+                options = {
+                    pathArray: pathArray,
+                    closeArray: closeArrayOrScene,
+                    closePath: closePath,
+                    offset: offset,
+                    sideOrientation: sideOrientation,
+                }
+            }
+
+            if (instance) {   // existing ribbon instance update
                 // positionFunction : ribbon case
                 // positionFunction : ribbon case
                 // only pathArray and sideOrientation parameters are taken into account for positions update
                 // only pathArray and sideOrientation parameters are taken into account for positions update
                 var positionFunction = positions => {
                 var positionFunction = positions => {
                     var minlg = pathArray[0].length;
                     var minlg = pathArray[0].length;
                     var i = 0;
                     var i = 0;
-                    var ns = (ribbonInstance.sideOrientation === Mesh.DOUBLESIDE) ? 2 : 1;
+                    var ns = (instance.sideOrientation === Mesh.DOUBLESIDE) ? 2 : 1;
                     for (var si = 1; si <= ns; si++) {
                     for (var si = 1; si <= ns; si++) {
                         for (var p = 0; p < pathArray.length; p++) {
                         for (var p = 0; p < pathArray.length; p++) {
                             var path = pathArray[p];
                             var path = pathArray[p];
@@ -1267,7 +1290,7 @@
                                 j++;
                                 j++;
                                 i += 3;
                                 i += 3;
                             }
                             }
-                            if ((<any>ribbonInstance)._closePath) {
+                            if ((<any>instance)._closePath) {
                                 positions[i] = path[0].x;
                                 positions[i] = path[0].x;
                                 positions[i + 1] = path[0].y;
                                 positions[i + 1] = path[0].y;
                                 positions[i + 2] = path[0].z;
                                 positions[i + 2] = path[0].z;
@@ -1276,21 +1299,21 @@
                         }
                         }
                     }
                     }
                 };
                 };
-                var positions = ribbonInstance.getVerticesData(VertexBuffer.PositionKind);
+                var positions = instance.getVerticesData(VertexBuffer.PositionKind);
                 positionFunction(positions);
                 positionFunction(positions);
-                ribbonInstance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);
-                if (!(ribbonInstance.areNormalsFrozen)) {
-                    var indices = ribbonInstance.getIndices();
-                    var normals = ribbonInstance.getVerticesData(VertexBuffer.NormalKind);
+                instance.updateVerticesData(VertexBuffer.PositionKind, positions, false, false);
+                if (!(instance.areNormalsFrozen)) {
+                    var indices = instance.getIndices();
+                    var normals = instance.getVerticesData(VertexBuffer.NormalKind);
                     VertexData.ComputeNormals(positions, indices, normals);
                     VertexData.ComputeNormals(positions, indices, normals);
 
 
-                    if ((<any>ribbonInstance)._closePath) {
+                    if ((<any>instance)._closePath) {
                         var indexFirst: number = 0;
                         var indexFirst: number = 0;
                         var indexLast: number = 0;
                         var indexLast: number = 0;
                         for (var p = 0; p < pathArray.length; p++) {
                         for (var p = 0; p < pathArray.length; p++) {
-                            indexFirst = (<any>ribbonInstance)._idx[p] * 3;
+                            indexFirst = (<any>instance)._idx[p] * 3;
                             if (p + 1 < pathArray.length) {
                             if (p + 1 < pathArray.length) {
-                                indexLast = ((<any>ribbonInstance)._idx[p + 1] - 1) * 3;
+                                indexLast = ((<any>instance)._idx[p + 1] - 1) * 3;
                             }
                             }
                             else {
                             else {
                                 indexLast = normals.length - 3;
                                 indexLast = normals.length - 3;
@@ -1304,17 +1327,17 @@
                         }
                         }
                     }
                     }
 
 
-                    ribbonInstance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
+                    instance.updateVerticesData(VertexBuffer.NormalKind, normals, false, false);
                 }
                 }
 
 
-                return ribbonInstance;
+                return instance;
             }
             }
             else {  // new ribbon creation
             else {  // new ribbon creation
 
 
                 var ribbon = new Mesh(name, scene);
                 var ribbon = new Mesh(name, scene);
                 ribbon.sideOrientation = sideOrientation;
                 ribbon.sideOrientation = sideOrientation;
 
 
-                var vertexData = VertexData.CreateRibbon(pathArray, closeArray, closePath, offset, sideOrientation);
+                var vertexData = VertexData.CreateRibbon(options);
                 if (closePath) {
                 if (closePath) {
                     (<any>ribbon)._idx = (<any>vertexData)._idx;
                     (<any>ribbon)._idx = (<any>vertexData)._idx;
                 }
                 }
@@ -1376,18 +1399,27 @@
         }
         }
 
 
         // Cylinder and cone
         // Cylinder and cone
-        public static CreateCylinder(name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: any, scene: Scene, updatable?: any, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
-            // subdivisions is a new parameter, we need to support old signature
-            if (scene === undefined || !(scene instanceof Scene)) {
-                if (scene !== undefined) {
-                    updatable = scene;
+        public static CreateCylinder(name: string, height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: number, scene: Scene, updatable?: boolean, sideOrientation?: number): Mesh;
+        public static CreateCylinder(name: string, options: {height?: number, diameterTop?: number, diameterBottom?: number, tessellation?: number, subdivisions?: number, updatable?: boolean, sideOrientation?: number}, scene: any): Mesh
+        public static CreateCylinder(name: string, options: any, diameterTopOrScene: any, diameterBottom?: number, tessellation?: number, subdivisions?: number, scene?: Scene, updatable?: boolean, sideOrientation: number = Mesh.DEFAULTSIDE): Mesh {
+        
+            if (diameterTopOrScene instanceof Scene ) {
+                scene = diameterTopOrScene;
+                updatable = options.updatable;
+            } else {
+                var height = options;
+                options = {
+                    height: height,
+                    diameterTop: diameterTopOrScene,
+                    diameterBottom: diameterBottom,
+                    tessellation: tessellation,
+                    subdivisions: subdivisions,
+                    sideOrientation: sideOrientation
                 }
                 }
-                scene = <Scene>subdivisions;
-                subdivisions = 1;
-            }
 
 
+            }
             var cylinder = new Mesh(name, scene);
             var cylinder = new Mesh(name, scene);
-            var vertexData = VertexData.CreateCylinder(height, diameterTop, diameterBottom, tessellation, subdivisions, sideOrientation);
+            var vertexData = VertexData.CreateCylinder(options);
 
 
             vertexData.applyToMesh(cylinder, updatable);
             vertexData.applyToMesh(cylinder, updatable);
 
 

+ 20 - 6
src/Mesh/babylon.mesh.vertexData.ts

@@ -381,12 +381,17 @@
             return result;
             return result;
         }
         }
 
 
-        public static CreateRibbon(pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number, sideOrientation: number = Mesh.DEFAULTSIDE): VertexData {
-            closeArray = closeArray || false;
-            closePath = closePath || false;
+        public static CreateRibbon(pathArray: Vector3[][], closeArray: boolean, closePath: boolean, offset: number, sideOrientation?: number): VertexData;
+        public static CreateRibbon(options: {pathArray?: Vector3[][], closeArray?: boolean, closePath?: boolean, offset?: number, sideOrientation?: number}): VertexData;
+        public static CreateRibbon(options: any, closeArray?: boolean, closePath?: boolean, offset?: number, sideOrientation: number = Mesh.DEFAULTSIDE): VertexData {
+
+            var pathArray = pathArray || options.pathArray;
+            closeArray = closeArray || options.closeArray || false;
+            closePath = closePath || options.closePath || false;
             var defaultOffset = Math.floor(pathArray[0].length / 2);
             var defaultOffset = Math.floor(pathArray[0].length / 2);
-            offset = offset || defaultOffset;
+            offset = offset || options.offset || defaultOffset;
             offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
             offset = offset > defaultOffset ? defaultOffset : Math.floor(offset); // offset max allowed : defaultOffset
+            sideOrientation = sideOrientation || options.sideOrientation || Mesh.DEFAULTSIDE;
 
 
             var positions: number[] = [];
             var positions: number[] = [];
             var indices: number[] = [];
             var indices: number[] = [];
@@ -777,8 +782,17 @@
             return vertexData;
             return vertexData;
         }
         }
 
 
-        // Cylinder and cone (made using ribbons)
-        public static CreateCylinder(height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: number = 1, sideOrientation: number = Mesh.DEFAULTSIDE): VertexData {
+        // Cylinder and cone 
+        public static CreateCylinder(options: {height?: number, diameterTop?: number, diameterBottom?: number, tessellation?: number, subdivisions?: number, sideOrientation?: number}): VertexData;
+        public static CreateCylinder(height: number, diameterTop: number, diameterBottom: number, tessellation: number, subdivisions: number, sideOrientation?: number): VertexData;
+        public static CreateCylinder(options: any, diameterTop?: number, diameterBottom?: number, tessellation?: number, subdivisions?: number, sideOrientation: number = Mesh.DEFAULTSIDE): VertexData {
+            var height = height || options.height || 3;
+            diameterTop = diameterTop || options.diameterTop || 1;
+            diameterBottom = diameterBottom || options.diameterBottom || 1;
+            tessellation = tessellation || options.tessellation || 24;
+            subdivisions = subdivisions || options.subdivisions || 1;
+                
+            sideOrientation = sideOrientation || options.sideOrientation || Mesh.DEFAULTSIDE;
 
 
             var indices = [];
             var indices = [];
             var positions = [];
             var positions = [];