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

Add MassPropertyPlugin #532

Merged
merged 4 commits into from
Oct 13, 2024
Merged

Add MassPropertyPlugin #532

merged 4 commits into from
Oct 13, 2024

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Oct 13, 2024

Objective

Logic related to mass properties is currently a bit scattered around (PreparePlugin, ColliderBackendPlugin...), and there is also no way to opt out of automatic updating of mass properties. It would be nice to encapsulate this logic inside a single plugin, especially as we rework mass properties (#499) and add more APIs and functionality for working with mass.

This also contributes to the goal of removing PreparePlugin, which is currently full of various miscallaneous and unrelated logic.

Solution

Add a MassPropertyPlugin. It updates mass properties of rigid bodies when colliders are added or removed, or when their ColliderMassProperties are updated. It also logs warnings for invalid mass properties, and updates GlobalAngularInertia.

Previously, the logic for updating mass properties based on ColliderMassProperties changes was heavily tied to the ColliderMassProperties update logic in ColliderBackendPlugin, because it required knowing both the previous and new mass properties of the collider. Same for mass property updates caused by adding or removing colliders.

Now, it doesn't directly change the body's mass properties, but instead triggers an OnColliderMassPropertiesChanged event that the MassPropertyPlugin (and users) can react to. This makes the collider logic only responsible for managing ColliderMassProperties, and the logic for rigid bodies is self-contained.


Migration Guide

The MassPropertyPlugin is now needed to update mass properties automatically based on attached colliders. Most apps won't need to add it manually, as it is included in the PhysicsPlugins plugin group by default.

@Jondolf Jondolf added C-Enhancement New feature or request 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-Code-Quality Improvements to code readability, maintainability, or best practices labels Oct 13, 2024
@Jondolf Jondolf added this to the 0.2 milestone Oct 13, 2024
@Jondolf Jondolf merged commit 55d6815 into main Oct 13, 2024
4 checks passed
@Jondolf Jondolf deleted the mass-property-plugin branch October 13, 2024 21:12
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-Code-Quality Improvements to code readability, maintainability, or best practices C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant