Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransformControls: fix some edge case transforms #27719

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

AlaricBaraou
Copy link
Contributor

Related issue: #21840

Description

Unexpected transform happens when using TransformControls under theese three specific conditions:

  • When the object has a rotated parent
  • The coordinate space is set to 'world'
  • TranslationSnap is a numeric value

Addiotionnaly if the scene had a rotation, it would also mess up the TransformControls expected behaviour.

Both have been fixed in this PR.

*note, changed a snap value in the demo that was wayy to high to be usable with translate

fixtransform.mp4

This contribution is funded by Alaric Baraou 🦦

this.matrixWorldNeedsUpdate = false;
this.matrixWorld.copy( this.matrix );

super.updateMatrixWorld( false );
Copy link
Collaborator

@Mugen87 Mugen87 Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm your PR fixes the issue but the approach isn't ideal, tbh. We need to find a solution without influencing how the world transformation matrix is computed.

If not, this will cause issues when we rethink the update matrix process and lifecycle in three.js and try to find a more optimized implementation. Ideally, components just request a world matrix and do not modify their computation.

In other words, TransformControls has to work with an unmodified version of the scene's transformation hierarchy. Fixing the controls in combination with rotated ancestor nodes has to be done in a way that the rotation is correctly taken into account and not ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this match your requirements ?

If we replace my block

// if TransformControls has a parent, set its local position to the inverse of the parent world in order to have a worldMatrix to identity
if ( this.parent ) {

			this._transformMatrixWorldInv.copy( this.parent.matrixWorld ).invert();
			this._transformMatrixWorldInv.decompose( this.position, this.rotation, this.scale );

}

super.updateMatrixWorld( true );

That way we don't influence how the world transformation matrix is computed, we just set the TransformControls local position.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks indeed better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!
I'll push that commit later today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, it should be good now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants