-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 create physical bone when up vector is collinear to child origin #48310
Fix create physical bone when up vector is collinear to child origin #48310
Conversation
What happens if the first one succeeds and the second test fails? |
Good question, I was asking myself this question too yesterday night before sleeping... In Transform::set_look_at...
... the check is done only if MATH_CHECKS is defined. Then, in case of failure, the error is thrown and the basis and origin change, which happen in the next lines, won't happen. However, I am wondering if MATH_CHECKS is always defined in the editor. Currently it is defined in math_defs.h:
But if DEBUG_ENABLED is not enabled in the editor, then the vectors check must be done before using set_look_at... Thus, I need to change the PR... [EDIT] : wondering also if the join transform is correct, since it was unchanged for some time... |
bd53eeb
to
b7c2761
Compare
I have changed the solution: up is now checked before being used in set_look_at. The first top comment is also changed to show exactly that. |
b7c2761
to
ad02d87
Compare
Can you rebase? I'll try get some review on this pr. |
ad02d87
to
0162d8f
Compare
Thank you! Just done rebasing this morning |
0162d8f
to
d2eb1ef
Compare
@pouleyKetchoupp Is this something in your area? |
The code itself looks fine, I've just tested this PR and the 3.x PR (#48327):
Also there's another PR #53515 that addresses issues around the same area. Might be worth checking what the best way to handle all these cases is. |
I think this bug is caused by Basis::looking_at being non-robust, which is really bad for a game engine. (Imagine bugs in a game where you can trick the AI to walk the wrong direction if you go directly above it) The best fix would be for Basis::looking_at to be changed to handle this corner case internally rather than force all callers to do this work. (Though I'd understand if such a breaking change would only be done in 4.x) Anyway, given this flaw in Basis::looking_at, I think this fix looks great. |
Side note: #53515 appears to address a different bug: namely the fact that the bone is offset along the wrong axis in 3.x, I think because the basis is not aligned to the bone. we can test this if this is still a problem once #48327 is merged, but #48327 is a more complete fix by backporting the looking_at instead of assuming that the bones are aligned to their children. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I meant to say please use (up.cross(...).is_equal_approx(Vector3()) instead of .length == 0
conceptually it seems fine
72d8738
to
ee77999
Compare
Thanks a lot for the feedback! I have applied the requested change and rebase the branch to master. |
I have noticed only DAE bones are broken, but not GLTF ones. |
@Blackiris Is DAE broken without this PR applied? or does it only break in combination with this PR. Can you please upload the DAE model you are testing. Reproduction project? Is an issue filed? |
@lyuma Sorry I wasn't clear. Here are the results I get with the following project (1 model saved as .dae and .glb) Before this commit: After this commit To conclude,
I think it still needs some work to understand and fix the issues before validating this PR |
ee77999
to
ffb8f86
Compare
I have created the specific issue for the DAE bones #56242 as it is a different issue compared to this one. |
ffb8f86
to
234637a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I remember reviewing this. I think it's fine for this purpose.
Long term, I'd think this type of fix ought to belong inside Basis::looking_at
itself. For example, I could imagine a game developer using looking_at
in an AI script, and having hard-to-reproduce bugs caused by these pole vectors)
Thanks! |
Fix issue #39757 but for Godot 4.0
When generating physical bone,
set_look_at
is used to change the bone direction.body_transform.set_look_at(Vector3(0, 0, 0), child_rest.origin);
However, if the vector child_rest.origin is collinear with the default up vector =Vector3(0, 1, 0), the cross product cannot generate a third vector (with length > 0) and
set_look_at
fails.In order to avoid this issue, we first compute an up vector not collinear:
And then use it
Please find a reproduction project for Godot 4.0 at #39757 (comment)
Bugsquad edit: