Harold Martinez 6 年之前
父節點
當前提交
99b4fc0ee1
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      src/Meshes/transformNode.ts

+ 13 - 2
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;
@@ -352,6 +353,7 @@ export class TransformNode extends Node {
      * Returns a Vector3.
      */
     public get absolutePosition(): Vector3 {
+        this._syncAbsoluteScalingAndRotation();
         return this._absolutePosition;
     }
 
@@ -360,6 +362,7 @@ export class TransformNode extends Node {
      * Returns a Vector3.
      */
     public get absoluteScaling(): Vector3 {
+        this._syncAbsoluteScalingAndRotation();
         return this._absoluteScaling;
     }
 
@@ -1096,8 +1099,9 @@ export class TransformNode extends Node {
 
         this._afterComputeWorldMatrix();
 
-        // Update absolute transform values
-        this._worldMatrix.decompose(this._absoluteScaling, this._absoluteRotationQuaternion, this._absolutePosition);
+        // 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);
@@ -1328,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;
+        }
+    }
 }