浏览代码

Merge pull request #6620 from haroldma/master

 Add absolute scale and rotation to transform node
David Catuhe 6 年之前
父节点
当前提交
01f7072eb6
共有 2 个文件被更改,包括 30 次插入0 次删除
  1. 1 0
      dist/preview release/what's new.md
  2. 29 0
      src/Meshes/transformNode.ts

+ 1 - 0
dist/preview release/what's new.md

@@ -58,6 +58,7 @@
 
 ### Meshes
 - Added new CreateTiledPlane and CreateTiledBox ([JohnK](https://github.com/BabylonJSGuide/))
+- Added absolute scaling and rotation getters ([haroldma](https://github.com/haroldma))
 
 ### Physics
 - Update Ammo.js library to support global collision contact callbacks ([MackeyK24](https://github.com/MackeyK24/))

+ 29 - 0
src/Meshes/transformNode.ts

@@ -57,6 +57,7 @@ export class TransformNode extends Node {
     protected _scaling = Vector3.One();
     protected _isDirty = false;
     private _transformToBoneReferal: Nullable<TransformNode> = null;
+    private _isAbsoluteSynced = false;
 
     @serialize("billboardMode")
     private _billboardMode = TransformNode.BILLBOARDMODE_NONE;
@@ -145,6 +146,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 +357,24 @@ export class TransformNode extends Node {
     }
 
     /**
+     * Returns the current mesh absolute scaling.
+     * Returns a Vector3.
+     */
+    public get absoluteScaling(): Vector3 {
+        this._syncAbsoluteScalingAndRotation();
+        return this._absoluteScaling;
+    }
+
+    /**
+     * Returns the current mesh absolute rotation.
+     * Returns a Quaternion.
+     */
+    public get absoluteRotationQuaternion(): Quaternion {
+        this._syncAbsoluteScalingAndRotation();
+        return this._absoluteRotationQuaternion;
+    }
+
+    /**
      * Sets a new matrix to apply before all other transformation
      * @param matrix defines the transform matrix
      * @returns the current TransformNode
@@ -1080,6 +1101,7 @@ export class TransformNode extends Node {
 
         // Absolute position
         this._absolutePosition.copyFromFloats(this._worldMatrix.m[12], this._worldMatrix.m[13], this._worldMatrix.m[14]);
+        this._isAbsoluteSynced = false;
 
         // Callbacks
         this.onAfterWorldMatrixUpdateObservable.notifyObservers(this);
@@ -1310,4 +1332,11 @@ export class TransformNode extends Node {
 
         return this;
     }
+
+    private _syncAbsoluteScalingAndRotation(): void {
+        if (!this._isAbsoluteSynced) {
+            this._worldMatrix.decompose(this._absoluteScaling, this._absoluteRotationQuaternion);
+            this._isAbsoluteSynced = true;
+        }
+    }
 }