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

Improved error-handling for scaling #925

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

mihe
Copy link
Contributor

@mihe mihe commented Jul 25, 2024

Fixes #912.

This refactors the error-handling for scaling introduced in #810.

The current usage of JPH::Shape::IsValidScale poses some problems in the context of Godot, since the tolerance of JPH::Shape::IsValidScale is (understandably) quite small, and Godot doesn't do any sort of automatic orthonormalization of its transforms, which means that it doesn't take many frames for something like the rotation of a CharacterBody3D to start messing with the orthogonality of its transforms, thereby resulting in weird scaling and potentially causing JPH::Shape::IsValidScale to fail.

The technically correct resolution to this would of course be for the user to just orthonormalize its transforms, or for this extension to disregard scaling completely (like Godot Physics does), but given the friction involved with this, and the fact that some users have come to appreciate and rely on the (undocumented) support for scaling in this extension, a compromise has been reached instead.

This PR makes use of the newly introduced JPH::Shape::MakeScaleValid, which takes any arbitrary scaling and changes it just enough to be valid for the given shape. This means that we can make sure that Jolt always receives a correct scaling, but better yet we can also check to see how different this new valid scaling is from the one we put in, and emit an error based on a tolerance that we define ourselves.

So this effectively raises the tolerance from 0.0001-ish to 0.01. This will make sure that clearly incorrect scaling, such as deliberately scaling a capsule or sphere non-uniformly, will emit errors, but scaling as a result of accumulative precision errors are only reported if they're really bad.

Note that the correction of the scale (i.e. JPH::Shape::MakeScaleValid) happens regardless of build, whereas the error-reporting only happens in editor/debug builds.

@mihe mihe added enhancement New feature or request topic:runtime Concerning runtime behavior (or its source code) refactoring Changes something without altering its functionality labels Jul 25, 2024
@mihe mihe force-pushed the better-scale-errors branch 5 times, most recently from 903cdc4 to a503006 Compare July 25, 2024 13:38
@mihe mihe force-pushed the better-scale-errors branch from a503006 to b99b286 Compare July 25, 2024 14:24
@mihe mihe merged commit 456be6d into godot-jolt:master Jul 25, 2024
182 checks passed
@mihe mihe deleted the better-scale-errors branch July 25, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring Changes something without altering its functionality topic:runtime Concerning runtime behavior (or its source code)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PhysicalBone3D causes errors about failing to scale body
1 participant