소스 검색

Merge pull request #2185 from BabylonJSGuide/master

CreatePolygon
David Catuhe 8 년 전
부모
커밋
1c4a49fde2
3개의 변경된 파일104개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      src/Mesh/babylon.mesh.ts
  2. 22 0
      src/Mesh/babylon.mesh.vertexData.ts
  3. 48 0
      src/Mesh/babylon.meshBuilder.ts

+ 34 - 0
src/Mesh/babylon.mesh.ts

@@ -2506,6 +2506,40 @@
         }
         }
 
 
         /**
         /**
+         * Creates a polygon mesh.
+         * Please consider using the same method from the MeshBuilder class instead. 
+         * The polygon's shape will depend on the input parameters and is constructed paralell to a ground mesh.
+         * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
+         * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
+         * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
+         * Remember you can only change the shape positions, not their number when updating a polygon.
+         */
+        public static CreatePolygon(name: string, shape: Vector3[], scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh {
+            var options = {
+                shape: shape,
+                holes: holes,
+                updatable: updatable,
+                sideOrientation: sideOrientation
+            }
+            return MeshBuilder.CreatePolygon(name, options, scene);
+		}
+
+       /**
+         * Creates an extruded polygon mesh, with depth in the Y direction. 
+         * Please consider using the same method from the MeshBuilder class instead. 
+		*/
+        public static ExtrudePolygon(name: string, shape: Vector3[], depth: number, scene: Scene, holes?: Vector3[][], updatable?: boolean, sideOrientation?: number): Mesh {
+            var options = {
+                shape: shape,
+                holes: holes,
+                depth: depth,
+                updatable: updatable,
+                sideOrientation: sideOrientation
+            }
+            return MeshBuilder.ExtrudePolygon(name, options, scene);
+		}
+
+        /**
          * Creates an extruded shape mesh.    
          * Creates an extruded shape mesh.    
          * The extrusion is a parametric shape :  http://doc.babylonjs.com/tutorials/Parametric_Shapes.  It has no predefined shape. Its final shape will depend on the input parameters.  
          * The extrusion is a parametric shape :  http://doc.babylonjs.com/tutorials/Parametric_Shapes.  It has no predefined shape. Its final shape will depend on the input parameters.  
          * Please consider using the same method from the MeshBuilder class instead.    
          * Please consider using the same method from the MeshBuilder class instead.    

+ 22 - 0
src/Mesh/babylon.mesh.vertexData.ts

@@ -1619,6 +1619,28 @@
         }
         }
 
 
         /**
         /**
+         * Re-creates the VertexData of the Polygon for sideOrientation.  
+         */
+        public static CreatePolygon(polygon: Mesh, sideOrientation: number) {
+			var positions = polygon.getVerticesData(VertexBuffer.PositionKind);
+			var normals = polygon.getVerticesData(VertexBuffer.NormalKind);
+			var uvs = polygon.getVerticesData(VertexBuffer.UVKind);
+			var indices = polygon.getIndices();
+
+			// sides
+            VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs);
+            
+            // Result
+            var vertexData = new VertexData();
+            vertexData.indices = indices;
+            vertexData.positions = positions;
+            vertexData.normals = normals;
+            vertexData.uvs = uvs;
+            return vertexData;
+			
+		}
+
+        /**
          * Creates the VertexData of the IcoSphere.  
          * Creates the VertexData of the IcoSphere.  
          */
          */
         public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {
         public static CreateIcoSphere(options: { radius?: number, radiusX?: number, radiusY?: number, radiusZ?: number, flat?: boolean, subdivisions?: number, sideOrientation?: number, frontUVs?: Vector4, backUVs?: Vector4 }): VertexData {

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

@@ -782,6 +782,54 @@
         }
         }
 
 
         /**
         /**
+         * Creates a polygon mesh.
+         * The polygon's shape will depend on the input parameters and is constructed paralell to a ground mesh.
+         * The parameter `shape` is a required array of successive Vector3 representing the corners of the polygon in th XoZ plane, that is y = 0 for all vectors.
+         * You can set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE
+         * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.
+         * Remember you can only change the shape positions, not their number when updating a polygon.
+         */
+        public static CreatePolygon(name: string, options: {shape: Vector3[], holes?: Vector3[][], depth?: number, updatable?: boolean, sideOrientation?: number}, scene: Scene): Mesh {
+            options.sideOrientation = MeshBuilder.updateSideOrientation(options.sideOrientation, scene);
+			var shape = options.shape;
+			var holes = options.holes;
+			var depth = options.depth || 0;
+			var contours: Array<Vector2> = [];
+			var hole: Array<Vector2> = [];
+			for(var i=0; i < shape.length; i++) {
+				contours[i] = new Vector2(shape[i].x, shape[i].z);
+			}
+			var epsilon = 0.00000001;
+			if(contours[0].equalsWithEpsilon(contours[contours.length - 1], epsilon)) {
+					contours.pop();
+			}
+			
+			var polygonTriangulation = new PolygonMeshBuilder(name, contours, scene);
+			for(var hNb = 0; hNb < holes.length; hNb++) {
+				hole = [];
+				for(var hPoint = 0; hPoint < holes[hNb].length; hPoint++) {
+					hole.push(new Vector2(holes[hNb][hPoint].x, holes[hNb][hPoint].z));
+				}
+				polygonTriangulation.addHole(hole);
+			}
+			var polygon = polygonTriangulation.build(options.updatable, depth);
+            polygon.sideOrientation = options.sideOrientation;
+			var vertexData = VertexData.CreatePolygon(polygon, options.sideOrientation);
+            vertexData.applyToMesh(polygon, options.updatable);			
+			
+            return polygon;
+		};
+
+        /**
+         * Creates an extruded polygon mesh, with depth in th Y direction. 
+		*/
+
+		public static ExtrudePolygon(name: string, options: {shape: Vector3[], holes?: Vector3[][], depth?: number, updatable?: boolean, sideOrientation?: number}, scene: Scene): Mesh {
+			return MeshBuilder.CreatePolygon(name, options, scene);
+		};
+         
+
+        /**
          * Creates a tube mesh.    
          * Creates a tube mesh.    
          * The tube is a parametric shape :  http://doc.babylonjs.com/tutorials/Parametric_Shapes.  It has no predefined shape. Its final shape will depend on the input parameters.    
          * The tube is a parametric shape :  http://doc.babylonjs.com/tutorials/Parametric_Shapes.  It has no predefined shape. Its final shape will depend on the input parameters.    
          *
          *