Jelajahi Sumber

-added Bone.getRotation and Bone.getRotationToRef -fixed Bone.getDirection (wrong values if mesh has moved)

Adam Bowman 8 tahun lalu
induk
melakukan
0ce65af2f3
1 mengubah file dengan 35 tambahan dan 4 penghapusan
  1. 35 4
      src/Bones/babylon.bone.ts

+ 35 - 4
src/Bones/babylon.bone.ts

@@ -511,26 +511,57 @@
 
         }
 
-        public getDirection (localAxis: Vector3){
+        public getDirection (localAxis: Vector3, mesh: AbstractMesh): Vector3{
 
             var result = Vector3.Zero();
 
-            this.getDirectionToRef(localAxis, result);
+            this.getDirectionToRef(localAxis, mesh, result);
             
             return result;
 
         }
 
-        public getDirectionToRef (localAxis: Vector3, result: Vector3) {
+        public getDirectionToRef (localAxis: Vector3, mesh: AbstractMesh, result: Vector3): void {
 
             this._skeleton.computeAbsoluteTransforms();
-            Vector3.TransformNormalToRef(localAxis, this.getAbsoluteTransform(), result);
             
+            var mat = BABYLON.Tmp.Matrix[0];
+
+            mat.copyFrom(this.getAbsoluteTransform());
+
+            if(mesh){
+                mat.multiplyToRef(mesh.getWorldMatrix(), mat);
+            }
+
+            Vector3.TransformNormalToRef(localAxis, mat, result);
+
             if (this._scaleVector.x != 1 || this._scaleVector.y != 1 || this._scaleVector.z != 1) {
                 result.normalize();
             }
 
         }
 
+        public getRotation(mesh: AbstractMesh): Quaternion {
+
+            var result = Quaternion.Identity();
+
+            this.getRotationToRef(mesh, result);
+
+            return result;
+
+        }
+
+        public getRotationToRef(mesh: AbstractMesh, result: Quaternion): void{
+
+            var mat = Tmp.Matrix[0];
+            var amat = this.getAbsoluteTransform();
+            var wmat = mesh.getWorldMatrix();
+
+            amat.multiplyToRef(wmat, mat);
+
+            mat.decompose(Tmp.Vector3[0], result, Tmp.Vector3[1]);
+
+        }
+
     }
 }