gz-physics icon indicating copy to clipboard operation
gz-physics copied to clipboard

bullet-featherstone: Use a single contact manifold for each convex decomposed mesh collision

Open iche033 opened this issue 7 months ago • 2 comments

🦟 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. bullet_mesh_contacts

After: limit contact points to <= 4 bullet_mesh_contacts_single_manifold

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 bullet_deactivated_profile_cropped

After: 20 contact points bullet_deactivated_with_fix_profile_cropped

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.

iche033 avatar Jul 03 '24 02:07 iche033