Browse Source

Merge pull request #6133 from bghgary/gizmo-fix

Fix bug with bounding box gizmos on skinned meshes
David Catuhe 6 years ago
parent
commit
f4938d386c
2 changed files with 19 additions and 14 deletions
  1. 19 1
      src/Gizmos/boundingBoxGizmo.ts
  2. 0 13
      src/Gizmos/gizmo.ts

+ 19 - 1
src/Gizmos/boundingBoxGizmo.ts

@@ -382,9 +382,20 @@ export class BoundingBoxGizmo extends Gizmo {
     public updateBoundingBox() {
         if (this.attachedMesh) {
             PivotTools._RemoveAndStorePivotPoint(this.attachedMesh);
+
+            // Store original parent
             var originalParent = this.attachedMesh.parent;
             this.attachedMesh.setParent(null);
+
+            // Store original skelton override mesh
+            var originalSkeletonOverrideMesh = null;
+            if (this.attachedMesh.skeleton) {
+                originalSkeletonOverrideMesh = this.attachedMesh.skeleton.overrideMesh;
+                this.attachedMesh.skeleton.overrideMesh = null;
+            }
+
             this._update();
+
             // Rotate based on axis
             if (!this.attachedMesh.rotationQuaternion) {
                 this.attachedMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.attachedMesh.rotation.y, this.attachedMesh.rotation.x, this.attachedMesh.rotation.z);
@@ -412,10 +423,17 @@ export class BoundingBoxGizmo extends Gizmo {
             this._lineBoundingBox.computeWorldMatrix();
             this._anchorMesh.position.copyFrom(this._lineBoundingBox.absolutePosition);
 
-            // restore position/rotation values
+            // Restore position/rotation values
             this.attachedMesh.rotationQuaternion.copyFrom(this._tmpQuaternion);
             this.attachedMesh.position.copyFrom(this._tmpVector);
+
+            // Restore original parent
             this.attachedMesh.setParent(originalParent);
+
+            // Restore original skeleton override mesh
+            if (this.attachedMesh.skeleton) {
+                this.attachedMesh.skeleton.overrideMesh = originalSkeletonOverrideMesh;
+            }
         }
 
         this._updateRotationSpheres();

+ 0 - 13
src/Gizmos/gizmo.ts

@@ -99,20 +99,7 @@ export class Gizmo implements IDisposable {
                     this._rootMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._rootMesh.rotation.y, this._rootMesh.rotation.x, this._rootMesh.rotation.z);
                 }
 
-                // Remove scaling before getting rotation matrix to get rotation matrix unmodified by scale
-                this._tempVector.copyFrom(effectiveMesh.scaling);
-                if (effectiveMesh.scaling.x < 0) {
-                    effectiveMesh.scaling.x *= -1;
-                }
-                if (effectiveMesh.scaling.y < 0) {
-                    effectiveMesh.scaling.y *= -1;
-                }
-                if (effectiveMesh.scaling.z < 0) {
-                    effectiveMesh.scaling.z *= -1;
-                }
                 effectiveMesh.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);
-                effectiveMesh.scaling.copyFrom(this._tempVector);
-                effectiveMesh.computeWorldMatrix();
                 Quaternion.FromRotationMatrixToRef(this._tmpMatrix, this._rootMesh.rotationQuaternion);
             } else if (this._rootMesh.rotationQuaternion) {
                 this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);