浏览代码

added alignWithNormal function to AbstractMesh

Adam Bowman 7 年之前
父节点
当前提交
7d66027f76
共有 1 个文件被更改,包括 21 次插入0 次删除
  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 axis0 = Tmp.Vector3[0];
+            var axis1 = Tmp.Vector3[1];
+            Vector3.CrossToRef(upDirection, normal, axis0);
+            Vector3.CrossToRef(normal, axis0, axis1);
+
+            if(this.rotationQuaternion){
+                Quaternion.RotationQuaternionFromAxisToRef(axis1, normal, axis0, this.rotationQuaternion);
+            }else{
+                Vector3.RotationFromAxisToRef(axis1, normal, axis0, this.rotation);
+            }
+            return this;
+        }
 
         protected checkOcclusionQuery() {
             var engine = this.getEngine();