Browse Source

Merge pull request #896 from jbousquie/feature.LatheCap

added caps to Lathe
David Catuhe 9 years ago
parent
commit
1a67186848
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/Mesh/babylon.meshBuilder.ts

+ 10 - 1
src/Mesh/babylon.meshBuilder.ts

@@ -265,7 +265,7 @@
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable, sideOrientation, instance);
             return MeshBuilder._ExtrudeShapeGeneric(name, shape, path, null, null, scaleFunction, rotationFunction, ribbonCloseArray, ribbonClosePath, cap, true, scene, updatable, sideOrientation, instance);
         }
         }
 
 
-        public static CreateLathe(name: string, options: { shape: Vector3[], radius?: number, tessellation?: number, arc?: number, closed?: boolean, updatable?: boolean, sideOrientation?: number }, scene: Scene): Mesh {
+        public static CreateLathe(name: string, options: { shape: Vector3[], radius?: number, tessellation?: number, arc?: number, closed?: boolean, updatable?: boolean, sideOrientation?: number, cap?: number }, scene: Scene): Mesh {
             var arc: number = (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var arc: number = (options.arc <= 0 || options.arc > 1) ? 1.0 : options.arc || 1.0;
             var closed: boolean = (options.closed === undefined) ? true : options.closed;
             var closed: boolean = (options.closed === undefined) ? true : options.closed;
             var shape = options.shape;
             var shape = options.shape;
@@ -273,6 +273,7 @@
             var tessellation = options.tessellation || 64;
             var tessellation = options.tessellation || 64;
             var updatable = options.updatable;
             var updatable = options.updatable;
             var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
             var sideOrientation = (options.sideOrientation === 0) ? 0 : options.sideOrientation || Mesh.DEFAULTSIDE;
+            var cap = options.cap || Mesh.NO_CAP;
             var pi2 = Math.PI * 2;
             var pi2 = Math.PI * 2;
             var paths = new Array();
             var paths = new Array();
 
 
@@ -283,10 +284,18 @@
             var path = new Array<Vector3>();;
             var path = new Array<Vector3>();;
             for (i = 0; i <= tessellation; i++) {
             for (i = 0; i <= tessellation; i++) {
                 var path: Vector3[] = [];
                 var path: Vector3[] = [];
+                if (cap == Mesh.CAP_START || cap == Mesh.CAP_ALL) {
+                    path.push(new Vector3(0, shape[0].y ,0));
+                    path.push(new Vector3(shape[0].x, shape[0].y, shape[0].x));
+                }
                 for (p = 0; p < shape.length; p++) {
                 for (p = 0; p < shape.length; p++) {
                     rotated = new Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y , Math.sin(i * step) * shape[p].x * radius);
                     rotated = new Vector3(Math.cos(i * step) * shape[p].x * radius, shape[p].y , Math.sin(i * step) * shape[p].x * radius);
                     path.push(rotated);
                     path.push(rotated);
                 }
                 }
+                if (cap == Mesh.CAP_END || cap == Mesh.CAP_ALL) {
+                    path.push(new Vector3(Math.cos(i * step) * shape[shape.length - 1].x * radius, shape[shape.length - 1].y, Math.sin(i * step) * shape[shape.length - 1].x * radius));
+                    path.push(new Vector3(0, shape[shape.length - 1].y ,0));
+                }
                 paths.push(path);
                 paths.push(path);
             }
             }