Просмотр исходного кода

added Bone.getDirection, Bone.getDirectionToRef, Bone.setRotationMatrix, Matrix.FromXYZAxesToRef; removed some unnecessary referencese to BABYLON in Bone class

Adam Bowman 9 лет назад
Родитель
Сommit
3f6611e2af
2 измененных файлов с 64 добавлено и 2 удалено
  1. 35 2
      src/Bones/babylon.bone.ts
  2. 29 0
      src/Math/babylon.math.ts

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

@@ -316,8 +316,8 @@
             
         }
 
-        public setAxisAngle (axis: Vector3, angle: number, space: BABYLON.Space, mesh: BABYLON.AbstractMesh): void {
-
+        public setAxisAngle (axis: Vector3, angle: number, space: BABYLON.Space = BABYLON.Space.LOCAL, mesh: BABYLON.AbstractMesh = null): void {
+            
             var rotMat = BABYLON.Tmp.Matrix[0];
             BABYLON.Matrix.RotationAxisToRef(axis, angle, rotMat);
             var rotMatInv = BABYLON.Tmp.Matrix[1];
@@ -329,6 +329,18 @@
 
         }
 
+        public setRotationMatrix (rotMat: Matrix, space: BABYLON.Space = BABYLON.Space.LOCAL, mesh: BABYLON.AbstractMesh = null) {
+
+            var rotMatInv = BABYLON.Tmp.Matrix[1];
+            
+            this._getNegativeRotationToRef(rotMatInv, space, mesh);
+
+            rotMatInv.multiplyToRef(rotMat, rotMat);
+            
+            this._rotateWithMatrix(rotMat, space, mesh);
+
+        }
+
         private _rotateWithMatrix (rmat:BABYLON.Matrix, space = BABYLON.Space.LOCAL, mesh: BABYLON.AbstractMesh = null): void {
 
             var lmat = this.getLocalMatrix();
@@ -491,5 +503,26 @@
 
         }
 
+        public getDirection (localAxis: Vector3){
+
+            var result = BABYLON.Vector3.Zero();
+
+            this.getDirectionToRef(localAxis, result);
+            
+            return result;
+
+        }
+
+        public getDirectionToRef (localAxis: Vector3, result: Vector3) {
+
+            this._skeleton.computeAbsoluteTransforms();
+            BABYLON.Vector3.TransformNormalToRef(localAxis, this.getAbsoluteTransform(), result);
+            
+            if (this._scaleVector.x != 1 || this._scaleVector.y != 1 || this._scaleVector.z != 1) {
+                result.normalize();
+            }
+
+        }
+
     }
 } 

+ 29 - 0
src/Math/babylon.math.ts

@@ -3116,6 +3116,35 @@
             result.m[14] = temp3 * plane.d;
             result.m[15] = 1.0;
         }
+
+        public static FromXYZAxesToRef(xaxis: Vector3, yaxis: Vector3, zaxis: Vector3, mat: Matrix) {
+            
+            mat.m[0] = xaxis.x;
+            mat.m[1] = xaxis.y;
+            mat.m[2] = xaxis.z;
+
+            mat.m[3] = 0;
+            
+            mat.m[4] = yaxis.x;
+            mat.m[5] = yaxis.y;
+            mat.m[6] = yaxis.z;
+            
+            mat.m[7] = 0;
+            
+            mat.m[8] = zaxis.x;
+            mat.m[9] = zaxis.y;
+            mat.m[10] = zaxis.z;
+            
+            mat.m[11] = 0;
+            
+            mat.m[12] = 0;
+            mat.m[13] = 0;
+            mat.m[14] = 0;
+            
+            mat.m[15] = 1;
+
+        }
+
     }
 
     export class Plane {