Sfoglia il codice sorgente

Plane mesh from a Plane (Math)

This addition will take a source (math) plane and transform the newly
created plane to its center coordinates. Can be helpful.
Raanan Weber 9 anni fa
parent
commit
8b6506388d
2 ha cambiato i file con 16 aggiunte e 1 eliminazioni
  1. 6 0
      src/Mesh/babylon.meshBuilder.js
  2. 10 1
      src/Mesh/babylon.meshBuilder.ts

+ 6 - 0
src/Mesh/babylon.meshBuilder.js

@@ -265,6 +265,12 @@ var BABYLON;
             var plane = new BABYLON.Mesh(name, scene);
             var vertexData = BABYLON.VertexData.CreatePlane(options);
             vertexData.applyToMesh(plane, options.updatable);
+            if (options.sourcePlane) {
+                plane.translate(options.sourcePlane.normal, options.sourcePlane.d);
+                var product = Math.acos(BABYLON.Vector3.Dot(options.sourcePlane.normal, BABYLON.Axis.Z));
+                var vectorProduct = BABYLON.Vector3.Cross(BABYLON.Axis.Z, options.sourcePlane.normal);
+                plane.rotate(vectorProduct, product);
+            }
             return plane;
         };
         MeshBuilder.CreateGround = function (name, options, scene) {

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

@@ -297,12 +297,21 @@
             return lathe;
         }
 
-        public static CreatePlane(name: string, options: { size?: number, width?: number, height?: number, sideOrientation?: number, updatable?: boolean }, scene: Scene): Mesh {
+        public static CreatePlane(name: string, options: { size?: number, width?: number, height?: number, sideOrientation?: number, updatable?: boolean, sourcePlane?: Plane }, scene: Scene): Mesh {
             var plane = new Mesh(name, scene);
 
             var vertexData = VertexData.CreatePlane(options);
 
             vertexData.applyToMesh(plane, options.updatable);
+            
+            if(options.sourcePlane) {
+                plane.translate(options.sourcePlane.normal, options.sourcePlane.d);
+                
+                var product = Math.acos(Vector3.Dot(options.sourcePlane.normal, Axis.Z));
+                var vectorProduct = Vector3.Cross(Axis.Z, options.sourcePlane.normal);
+                
+                plane.rotate(vectorProduct, product);
+            }
 
             return plane;
         }