gz-physics
gz-physics copied to clipboard
bullet-featherstone: Use a single contact manifold for each convex decomposed mesh collision
🦟 Bug fix
Marked as draft for debugging windows build
Summary
Contact point optimization for convex decomposed mesh collisions in bullet-featherstone plugin. This PR reduces the number of contact points generated for convex decomposed mesh collision by using a single contact manifold.
Previously when a mesh collision is decomposed into multiple convex hull shape, each convex hull shape has a corresponding contact manifold which can generate up to 4 contact points (4 is the default limit in bullet). This slows down sim especially when querying contact points (via GetContactsFromLastStep
). This PR overrides the btCollisionDispatcher
class in order to update the contact manifolds stored in bullet. It post processes the contact points, generates a single contact manifold for each collision associated with convex hull shapes, and clears the exiting contact manifolds.
Note: it would be more efficient if we can do this inside bullet to avoid generating all the contact manifolds in the first place.
Before: many points can be generated from one convex decomposed mesh collision.
After: limit contact points to <= 4
Here're remotery graphs showing before and after the fix for a scene with multiple convex decomposed meshes. Note objects were auto-deactivated when these graphs were captured.
Before: >200 contact points
After: 20 contact points
Notable speedups are:
-
PhysicsPrivate::Step
: 0.153ms -> 0.097ms -
PhysicsPrivate::UpdateCollision
: 0.528ms -> 0.135ms
Checklist
- [x] Signed all commits for DCO
- [x] Added tests
- [ ] Updated documentation (as needed)
- [ ] Updated migration guide (as needed)
- [ ] Consider updating Python bindings (if the library has them)
- [ ]
codecheck
passed (See contributing) - [ ] All tests passed (See test coverage)
- [ ] While waiting for a review on your PR, please help review another open pull request to support the maintainers
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by
messages.