Przeglądaj źródła

Merge pull request #6018 from bghgary/skin-bb-fix

Fix a bug with bounding box calculation when using skeleton.overrideMesh #2
David Catuhe 6 lat temu
rodzic
commit
bd4b9ea2e6
2 zmienionych plików z 15 dodań i 13 usunięć
  1. 12 11
      src/Gizmos/gizmo.ts
  2. 3 2
      src/Meshes/abstractMesh.ts

+ 12 - 11
src/Gizmos/gizmo.ts

@@ -93,31 +93,32 @@ export class Gizmo implements IDisposable {
      */
      */
     protected _update() {
     protected _update() {
         if (this.attachedMesh) {
         if (this.attachedMesh) {
+            const effectiveMesh = this.attachedMesh._effectiveMesh || this.attachedMesh;
             if (this.updateGizmoRotationToMatchAttachedMesh) {
             if (this.updateGizmoRotationToMatchAttachedMesh) {
                 if (!this._rootMesh.rotationQuaternion) {
                 if (!this._rootMesh.rotationQuaternion) {
                     this._rootMesh.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._rootMesh.rotation.y, this._rootMesh.rotation.x, this._rootMesh.rotation.z);
                     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
                 // Remove scaling before getting rotation matrix to get rotation matrix unmodified by scale
-                this._tempVector.copyFrom(this.attachedMesh.scaling);
-                if (this.attachedMesh.scaling.x < 0) {
-                    this.attachedMesh.scaling.x *= -1;
+                this._tempVector.copyFrom(effectiveMesh.scaling);
+                if (effectiveMesh.scaling.x < 0) {
+                    effectiveMesh.scaling.x *= -1;
                 }
                 }
-                if (this.attachedMesh.scaling.y < 0) {
-                    this.attachedMesh.scaling.y *= -1;
+                if (effectiveMesh.scaling.y < 0) {
+                    effectiveMesh.scaling.y *= -1;
                 }
                 }
-                if (this.attachedMesh.scaling.z < 0) {
-                    this.attachedMesh.scaling.z *= -1;
+                if (effectiveMesh.scaling.z < 0) {
+                    effectiveMesh.scaling.z *= -1;
                 }
                 }
-                this.attachedMesh.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);
-                this.attachedMesh.scaling.copyFrom(this._tempVector);
-                this.attachedMesh.computeWorldMatrix();
+                effectiveMesh.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);
+                effectiveMesh.scaling.copyFrom(this._tempVector);
+                effectiveMesh.computeWorldMatrix();
                 Quaternion.FromRotationMatrixToRef(this._tmpMatrix, this._rootMesh.rotationQuaternion);
                 Quaternion.FromRotationMatrixToRef(this._tmpMatrix, this._rootMesh.rotationQuaternion);
             } else if (this._rootMesh.rotationQuaternion) {
             } else if (this._rootMesh.rotationQuaternion) {
                 this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);
                 this._rootMesh.rotationQuaternion.set(0, 0, 0, 1);
             }
             }
             if (this.updateGizmoPositionToMatchAttachedMesh) {
             if (this.updateGizmoPositionToMatchAttachedMesh) {
-                this._rootMesh.position.copyFrom(this.attachedMesh.absolutePosition);
+                this._rootMesh.position.copyFrom(effectiveMesh.absolutePosition);
             }
             }
             if (this._updateScale && this.gizmoLayer.utilityLayerScene.activeCamera && this.attachedMesh) {
             if (this._updateScale && this.gizmoLayer.utilityLayerScene.activeCamera && this.attachedMesh) {
                 var cameraPosition = this.gizmoLayer.utilityLayerScene.activeCamera.globalPosition;
                 var cameraPosition = this.gizmoLayer.utilityLayerScene.activeCamera.globalPosition;

+ 3 - 2
src/Meshes/abstractMesh.ts

@@ -1205,7 +1205,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
                 var matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;
                 var matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;
 
 
                 this.skeleton.prepare();
                 this.skeleton.prepare();
-                var skeletonMatrices = this.skeleton.getTransformMatrices(this._effectiveMesh);
+                var skeletonMatrices = this.skeleton.getTransformMatrices(this);
 
 
                 var tempVector = Tmp.Vector3[0];
                 var tempVector = Tmp.Vector3[0];
                 var finalMatrix = Tmp.Matrix[0];
                 var finalMatrix = Tmp.Matrix[0];
@@ -1277,7 +1277,8 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         this._updateBoundingInfo();
         this._updateBoundingInfo();
     }
     }
 
 
-    protected get _effectiveMesh(): AbstractMesh {
+    /** @hidden */
+    public get _effectiveMesh(): AbstractMesh {
         return (this.skeleton && this.skeleton.overrideMesh) || this;
         return (this.skeleton && this.skeleton.overrideMesh) || this;
     }
     }