-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
Rework Mass
and Inertia
and add GlobalAngularInertia
in 3D
#500
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Jondolf
added
C-Enhancement
New feature or request
A-Dynamics
Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on
labels
Aug 24, 2024
…tia` constructors
Jondolf
added
the
C-Breaking-Change
This change removes or changes behavior or APIs, requiring users to adapt
label
Oct 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Dynamics
Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on
C-Breaking-Change
This change removes or changes behavior or APIs, requiring users to adapt
C-Enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Part of the ongoing mass property rework proposed in #499.
Currently, the inverses of
Mass
andInertia
(poor name, since mass is also inertia) are cached in theInverseMass
andInverseInertia
components. They are updated automatically.This dependency is confusing and adds complexity. The physics engine primarily just needs the inverse mass properties, while
Mass
andInertia
are mainly a user-facing API. In addition, when theMass
orInertia
are changed, their inverses will be out of sync until the systems responsible for updating them run. The components for the inverse and non-inverse versions should be more tightly coupled or combined to reduce complexity and lessen misuse.In 3D, angular inertia also depends on the orientation of the object. The local angular inertia tensor is stored in
Inertia
, and the world-space version is currently computed multiple times per substep. This is expensive. The rotation is only changed once per substep, during position/rotation integration, so the world-space angular inertia should be cached in its own read-only component.Solution
Remove
InverseMass
andInverseInertia
, and instead store the inverses inMass
andAngularInertia
directly. This internal representation is abstracted away through constructors and getters.2D:
3D:
Notice how
Inertia
was also renamed toAngularInertia
to be more explicit.Mass
andAngularInertia
also have a lot more helpers and documentation than before.Secondly, in 3D, the world-space angular inertia is now cached in a
GlobalAngularInertia
component. It is updated after position/rotation integration and when the local angular inertia is changed.Discussion
We might still want the non-inverse versions to be stored as well, at least for angular inertia. I'm not sure if it would be worth it though, so it would need benchmarking.
We could also consider storing the world-space angular inertia in
AngularInertia
directly, and design the API such that the local and global versions are always kept in sync. This would require taking a rotation in constructors though, and make the type less general-purpose, so I don't think it's worth it at this point.We could also consider caching the effective mass and angular inertia, which takes
LockedAxes
into account. They are quite cheap to compute though, so I'm not sure if it would be worth it. Needs benchmarking.Migration Guide
InverseMass
andInverseInertia
have been removed, andInertia
has been renamed toAngularInertia
. Use the methods onMass
andAngularInertia
to access the inverse versions.Mass
andAngularInertia
can no longer be constructed manually. Use the constructors such asnew
orfrom_inverse
instead.ColliderMassProperties
now only stores rawmass
,angular_inertia
, andcenter_of_mass
values.RigidBodyQueryItem
methodseffective_inv_mass
andeffective_world_inv_inertia
have been renamed toeffective_inverse_mass
andeffective_global_inverse_inertia
.