Skip to content

Commit 1da9b3c

Browse files
1 parent d97796d commit 1da9b3c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/dev/core/src/Gizmos/boundingBoxGizmo.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,26 @@ export class BoundingBoxGizmo extends Gizmo implements IBoundingBoxGizmo {
764764

765765
return this._cornerMesh.clone();
766766
}
767+
768+
/**
769+
* returns true if the combination of non uniform scaling and rotation of the attached mesh is not supported
770+
* In that case, the matrix is skewed and the bounding box gizmo will not work correctly
771+
* @returns True if the combination is not supported, otherwise false.
772+
*/
773+
protected _hasInvalidNonUniformScaling() {
774+
return (
775+
this._attachedMesh?.parent instanceof TransformNode &&
776+
this._attachedMesh?.parent.absoluteScaling.isNonUniformWithinEpsilon(0.001) &&
777+
((this._attachedMesh?.rotationQuaternion && !this._attachedMesh?.rotationQuaternion.equalsWithEpsilon(Quaternion.Identity(), Epsilon)) ||
778+
this._attachedMesh?.rotation.equalsWithEpsilon(Vector3.Zero(), Epsilon) === false)
779+
);
780+
}
767781
protected override _attachedNodeChanged(value: Nullable<AbstractMesh>) {
768782
if (value) {
783+
if (this._hasInvalidNonUniformScaling()) {
784+
Logger.Warn("BoundingBoxGizmo controls are not supported on meshes with non-uniform scaling and rotation");
785+
return;
786+
}
769787
// Reset anchor mesh to match attached mesh's scale
770788
// This is needed to avoid invalid box/anchor position on first drag
771789
this._anchorMesh.scaling.setAll(1);
@@ -814,7 +832,7 @@ export class BoundingBoxGizmo extends Gizmo implements IBoundingBoxGizmo {
814832
* Updates the bounding box information for the Gizmo
815833
*/
816834
public updateBoundingBox() {
817-
if (this.attachedMesh) {
835+
if (this.attachedMesh && !this._hasInvalidNonUniformScaling()) {
818836
PivotTools._RemoveAndStorePivotPoint(this.attachedMesh);
819837

820838
// Store original parent

0 commit comments

Comments
 (0)