瀏覽代碼

feedback addressed

Cedric Guillemet 5 年之前
父節點
當前提交
0268e53470
共有 1 個文件被更改,包括 25 次插入21 次删除
  1. 25 21
      src/Gizmos/gizmo.ts

+ 25 - 21
src/Gizmos/gizmo.ts

@@ -90,7 +90,9 @@ export class Gizmo implements IDisposable {
     }
 
     private _beforeRenderObserver: Nullable<Observer<Scene>>;
+    private _tempQuaternion = new Quaternion(0, 0, 0, 1);
     private _tempVector = new Vector3();
+    private _tempVector2 = new Vector3();
 
     /**
      * Creates a gizmo
@@ -163,47 +165,49 @@ export class Gizmo implements IDisposable {
         if (!this._attachedNode) {
             return;
         }
-        var inheritsTargetCamera = this._attachedNode.getClassName() === "FreeCamera"
-                        || this._attachedNode.getClassName() === "FlyCamera"
-                        || this._attachedNode.getClassName() === "ArcFollowCamera"
-                        || this._attachedNode.getClassName() === "TargetCamera"
-                        || this._attachedNode.getClassName() === "TouchCamera"
-                        || this._attachedNode.getClassName() === "UniversalCamera";
-        if  (this._attachedNode.getClassName() === "ArcRotateCamera" || inheritsTargetCamera) {
+
+        if  ((<Camera>this._attachedNode)._isCamera) {
             var camera = this._attachedNode as Camera;
-            var transformQuaternion = new Quaternion(0, 0, 0, 1);
-            var position = new Vector3(0, 0, 0);
-            var scaling = new Vector3(1, 1, 1);
             if (camera.parent) {
                 var parentInv = new Matrix();
                 var localMat = new Matrix();
                 camera.parent.getWorldMatrix().invertToRef(parentInv);
-                this._attachedNode._worldMatrix.multiplyToRef(parentInv, localMat);
-                localMat.decompose(scaling, transformQuaternion, position);
+                this._attachedNode.getWorldMatrix().multiplyToRef(parentInv, localMat);
+                localMat.decompose(this._tempVector2, this._tempQuaternion, this._tempVector);
             } else {
-                this._attachedNode._worldMatrix.decompose(scaling, transformQuaternion, position);
+                this._attachedNode.getWorldMatrix().decompose(this._tempVector2, this._tempQuaternion, this._tempVector);
             }
-            camera.position = position;
+
+            var inheritsTargetCamera = this._attachedNode.getClassName() === "FreeCamera"
+            || this._attachedNode.getClassName() === "FlyCamera"
+            || this._attachedNode.getClassName() === "ArcFollowCamera"
+            || this._attachedNode.getClassName() === "TargetCamera"
+            || this._attachedNode.getClassName() === "TouchCamera"
+            || this._attachedNode.getClassName() === "UniversalCamera";
+
             if (inheritsTargetCamera) {
                 var targetCamera = this._attachedNode as TargetCamera;
-                var angles = transformQuaternion.toEulerAngles();
-                targetCamera.rotation = angles;
+                targetCamera.rotation = this._tempQuaternion.toEulerAngles();
+                if (targetCamera.rotationQuaternion) {
+                    targetCamera.rotationQuaternion.copyFrom(this._tempQuaternion);
+                }
             }
+
+            camera.position.copyFrom(this._tempVector);
         } else if (this._attachedNode.getClassName() === "Mesh" || this._attachedNode.getClassName() === "AbstractMesh" || this._attachedNode.getClassName() === "TransformNode") {
             var transform = this._attachedNode as TransformNode;
-            var transformQuaternion = new Quaternion(0, 0, 0, 1);
             if (transform.parent) {
                 var parentInv = new Matrix();
                 var localMat = new Matrix();
                 transform.parent.getWorldMatrix().invertToRef(parentInv);
                 this._attachedNode._worldMatrix.multiplyToRef(parentInv, localMat);
-                localMat.decompose(transform.scaling, transformQuaternion, transform.position);
+                localMat.decompose(transform.scaling, this._tempQuaternion, transform.position);
             } else {
-                this._attachedNode._worldMatrix.decompose(transform.scaling, transformQuaternion, transform.position);
+                this._attachedNode._worldMatrix.decompose(transform.scaling, this._tempQuaternion, transform.position);
             }
-            transform.rotation = transformQuaternion.toEulerAngles();
+            transform.rotation = this._tempQuaternion.toEulerAngles();
             if (transform.rotationQuaternion) {
-                transform.rotationQuaternion = transformQuaternion;
+                transform.rotationQuaternion.copyFrom(this._tempQuaternion);
             }
         } else if (this._attachedNode.getClassName() === "Bone") {
             var bone = this._attachedNode as Bone;