Przeglądaj źródła

Merge pull request #779 from RaananW/create-plane-from-plane

Create a plane (mesh) using plane(math) coordinates
David Catuhe 9 lat temu
rodzic
commit
4c9e871e23

+ 2 - 2
src/Mesh/babylon.abstractMesh.ts

@@ -227,7 +227,7 @@
             return this._isWorldMatrixFrozen;
         }
 
-        public rotate(axis: Vector3, amount: number, space: Space): void {
+        public rotate(axis: Vector3, amount: number, space?: Space): void {
             axis.normalize();
 
             if (!this.rotationQuaternion) {
@@ -251,7 +251,7 @@
             }
         }
 
-        public translate(axis: Vector3, distance: number, space: Space): void {
+        public translate(axis: Vector3, distance: number, space?: Space): void {
             var displacementVector = axis.scale(distance);
 
             if (!space || space === Space.LOCAL) {

+ 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;
         }