ソースを参照

Add absolute scale and rotation to transform node

Harold Martinez 6 年 前
コミット
2c37816b2e
1 ファイル変更20 行追加2 行削除
  1. 20 2
      src/Meshes/transformNode.ts

+ 20 - 2
src/Meshes/transformNode.ts

@@ -145,6 +145,8 @@ export class TransformNode extends Node {
 
     private _usePivotMatrix = false;
     private _absolutePosition = Vector3.Zero();
+    private _absoluteScaling = Vector3.Zero();
+    private _absoluteRotationQuaternion = Quaternion.Identity();
     private _pivotMatrix = Matrix.Identity();
     private _pivotMatrixInverse: Matrix;
     protected _postMultiplyPivotMatrix = false;
@@ -354,6 +356,22 @@ export class TransformNode extends Node {
     }
 
     /**
+     * Returns the current mesh absolute scaling.
+     * Returns a Vector3.
+     */
+    public get absoluteScaling(): Vector3 {
+        return this._absoluteScaling;
+    }
+
+    /**
+     * Returns the current mesh absolute scaling.
+     * Returns a Vector3.
+     */
+    public get absoluteRotationQuaternion(): Quaternion {
+        return this._absoluteRotationQuaternion;
+    }
+
+    /**
      * Sets a new matrix to apply before all other transformation
      * @param matrix defines the transform matrix
      * @returns the current TransformNode
@@ -1078,8 +1096,8 @@ export class TransformNode extends Node {
 
         this._afterComputeWorldMatrix();
 
-        // Absolute position
-        this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
+        // Update absolute transform values
+        this._worldMatrix.decompose(this._absoluteScaling, this._absoluteRotationQuaternion, this._absolutePosition);
 
         // Callbacks
         this.onAfterWorldMatrixUpdateObservable.notifyObservers(this);