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

Fix Node3D.set_global_rotation() resetting node scale. #90584

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

BMagnu
Copy link
Contributor

@BMagnu BMagnu commented Apr 12, 2024

Fixes #74162.

The error was caused because the basis for the target global transform was entirely recreated. This process did not account for the scale of the basis of the current global transform.
This PR amends this by scaling the recreated basis for the global transform by the current global scale of the Node3D. Note that this scaling has to be done from the current global scale and not from the local scale of the Node3D.
This is important, otherwise a scaled parent of the Node3D would cause incorrect results on overwriting the global transform basis.

@BMagnu BMagnu requested a review from a team as a code owner April 12, 2024 16:43
@AThousandShips AThousandShips added this to the 4.3 milestone Apr 12, 2024
Copy link
Member

@ajreckof ajreckof left a comment

Choose a reason for hiding this comment

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

LGTM

@akien-mga akien-mga changed the title Fix Node3D.set_global_rotation() resetting node scale. Fix Node3D.set_global_rotation() resetting node scale. Apr 13, 2024
Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

@aaronfranke I think this is correct?

@AThousandShips
Copy link
Member

This should be valid to fix, but I wouldn't cherry pick it as it at least mildly breaks compatibility, people might very well rely on it resetting scale and this would break their code

@BMagnu
Copy link
Contributor Author

BMagnu commented Apr 16, 2024

Agreed, cherry picking it back into 4.2 is dangerous as only a patch-level fix for this reason.
Still, should be fine for the yet-unreleased 4.3

scene/3d/node_3d.cpp Outdated Show resolved Hide resolved
@BMagnu BMagnu force-pushed the fix_global_rotation_matrix branch from a4e6d4b to 7b07540 Compare April 16, 2024 11:17
@BMagnu BMagnu requested a review from aaronfranke April 16, 2024 11:17
@aaronfranke
Copy link
Member

This should be valid to fix, but I wouldn't cherry pick it as it at least mildly breaks compatibility, people might very well rely on it resetting scale and this would break their code

I would lean towards cherry-picking this. It is really weird for setting the rotation to change the scale. I would assume most users are using this method with unscaled objects, or else they would've run into this bug before.

@BMagnu BMagnu force-pushed the fix_global_rotation_matrix branch from 7b07540 to dd97ff4 Compare April 16, 2024 11:42
This was caused because the basis for the target global transform was entirely recreated. This process did not account for the scale of the basis of the current global transform.
This PR amends this by scaling the recreated basis for the global transform by the current global scale of the Node3D.
Note that this scaling has to be done from the current global scale and not from the local scale of the Node3D, otherwise issues would arise if parents of this Node3D would be scaled.
@AThousandShips
Copy link
Member

or else they would've run into this bug before.

This bug was discovered before 4.0 released so it's absolutely been run into, the report in question is from march last year, so just after 4.0, and there was a report before that with less details from January of the same year, so I don't think this is necessarily unnoticed

@akien-mga akien-mga merged commit d2ec371 into godotengine:master Apr 18, 2024
16 checks passed
@akien-mga
Copy link
Member

akien-mga commented Apr 18, 2024

Thanks! And congrats for your first merged Godot contribution 🎉

@BMagnu BMagnu deleted the fix_global_rotation_matrix branch April 18, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting the global rotation of a Node3D does not retain its scale
6 participants