Przeglądaj źródła

Merge pull request #3209 from abow/master

added alignWithNormal function to AbstractMesh
David Catuhe 7 lat temu
rodzic
commit
0b952d7b21
1 zmienionych plików z 21 dodań i 0 usunięć
  1. 21 0
      src/Mesh/babylon.abstractMesh.ts

+ 21 - 0
src/Mesh/babylon.abstractMesh.ts

@@ -1778,6 +1778,27 @@
             VertexData.ComputeNormals(positions, indices, normals, { useRightHandedSystem: this.getScene().useRightHandedSystem });
             this.setVerticesData(VertexBuffer.NormalKind, normals, updatable);
         }
+        /**
+         * Align the mesh with a normal.
+         * Returns the mesh.  
+         */
+        public alignWithNormal(normal:BABYLON.Vector3, upDirection?:BABYLON.Vector3):AbstractMesh{       
+            if(!upDirection){
+                upDirection = BABYLON.Axis.Y;
+            }
+            
+            var axisX = Tmp.Vector3[0];
+            var axisZ = Tmp.Vector3[1];
+            Vector3.CrossToRef(upDirection, normal, axisZ);
+            Vector3.CrossToRef(normal, axisZ, axisX);
+            
+            if(this.rotationQuaternion){
+                Quaternion.RotationQuaternionFromAxisToRef(axisX, normal, axisZ, this.rotationQuaternion);
+            }else{
+                Vector3.RotationFromAxisToRef(axisX, normal, axisZ, this.rotation);
+            }
+            return this;
+        }
 
         protected checkOcclusionQuery() {
             var engine = this.getEngine();