-
Notifications
You must be signed in to change notification settings - Fork 50
bullet-featherstone: Use a single contact manifold for each convex decomposed mesh collision #664
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
base: gz-physics7
Are you sure you want to change the base?
Conversation
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
…collision in get contacts from last step Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Looks like there are several test failures in windows and I don't see any in the stable branch (https://build.osrfoundation.org/view/gz-harmonic/job/gz_physics-7-win/) |
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
Fixed and this PR is ready for review again. The test failures were due to RTTI access violation when doing a |
@azeey to review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this was not a walk in the park :), but I think I finally understand how things are working. I don't see any major problems, but it would be good to test what happens when objects are removed. Another point is about the ambiguity with the collision index. I'm wondering if we can find a way around that. No worries if you don't have time to tackle that right now though.
{ | ||
if (_childIndex >= 0 && _childIndex < childCount) | ||
{ | ||
// todo(iche033) We do not have sufficient info to determine which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like something that could happen fairly frequently, i.e, a link that has a primitive collider as well as a convex decomposed mesh. Or it could be a link that has multiple convex decomposed mesh colliders. I guess returning nullptr
here means that we won't be consolidating the contact points from this shape right? Just checking my understanding.
} | ||
|
||
///////////////////////////////////////////////// | ||
void GzCollisionDispatcher::RemoveManifoldByCollisionObject( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of the for
loops are entering the block. I checked this with a Coverage
build locally. Can we add a test that covers this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated MeshContact
test in collisions.cc
to remove the model with convex decomposed mesh collision. It should trigger this call. 15d4ede
{ | ||
const btCollisionShape *shape = _compoundShape->getChildShape(i); | ||
if (this->HasConvexHullChildShapes(shape)) | ||
return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test that covers this?
auto manifoldIt = this->manifoldsToKeep.find(_manifold); | ||
if (manifoldIt != this->manifoldsToKeep.end()) | ||
this->manifoldsToKeep.erase(manifoldIt); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to also remove it from customManifolds
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only be called for contact manifolds owned by bullet, and not the custom ones created by gz-physics. I tested manually by removing models with convex decomposed collisions and did not notice that custom manifolds were passed to this function.
if (this->customManifolds.find(contactManifold) != | ||
this->customManifolds.end()) | ||
{ | ||
contactManifold->refreshContactPoints(ob0->getWorldTransform(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Do you know that Bullet itself won't be doing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember I had to keep this call for the multi body link transform to be updated. As a test, I dropped a model with convex decomposed collisions on the ground -> this worked fine, but as soon as I moved it to a different pose, its transforms are not updated.
// -> comopundShape -> convexShape0 | ||
// -> convexShape1 | ||
// A _childIndex of 1 is ambiguous as it could refer to either | ||
// boxShape1 or convexShape1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the getUserIndex
or getUserPointer
to help with this somehow?
Signed-off-by: Ian Chen <ichen@openrobotics.org>
I addressed most of the comments but not all. I still need to figure out how to resolve the issue with ambiguous collision index and then add a test. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## gz-physics7 #664 +/- ##
===============================================
+ Coverage 78.32% 79.54% +1.21%
===============================================
Files 140 144 +4
Lines 8069 8799 +730
===============================================
+ Hits 6320 6999 +679
- Misses 1749 1800 +51 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🦟 Bug fix
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 thebtCollisionDispatcher
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.097msPhysicsPrivate::UpdateCollision
: 0.528ms -> 0.135msChecklist
codecheck
passed (See contributing)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.