-
Notifications
You must be signed in to change notification settings - Fork 42
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
bullet-featherstone: Support convex decomposition for meshes #606
Conversation
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #606 +/- ##
==========================================
+ Coverage 78.32% 78.91% +0.59%
==========================================
Files 140 140
Lines 8069 8173 +104
==========================================
+ Hits 6320 6450 +130
+ Misses 1749 1723 -26 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
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 was tinkering with this by changing the //mesh/@optimization
value in the test to both an empty string and convex_hull
to for comparison's sake, and I realized from the console output that we are computing convex decompositions of all the submeshes and then adding them all to a btCompoundShape
. For comparison, when using bullet collisions in dartsim (which stores mesh information with submeshes in an Assimp Scene), all the submeshes are merged together into a single mesh:
I think convex_decomposition
and convex_hull
operations should apply to the fusion of all submeshes, unless only a single submesh is specified, in which case it would act only on that submesh. In the unoptimized case, we could also consider merging to a single mesh shape instead of using btCompoundShape
(this can happen in separate pull requests)
std::vector<common::SubMesh> decomposed = | ||
std::move(meshManager.ConvexDecomposition(*s.get(), maxConvexHulls)); | ||
|
||
gzdbg << "Optimizing mesh using convex decomposition. " << std::endl; |
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.
we may want to remove this, but it has been very helpful for testing
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.
shortened the debug msg to one line. 1f2aaa7
I can also remove this msg completely if preferred.
this->triangleMeshes.back().get())); | ||
this->meshesGImpact.back()->updateBound(); | ||
this->meshesGImpact.back()->setMargin(btScalar(0.01)); | ||
compoundShape->addChildShape(btTransform::getIdentity(), |
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 currently uses btCompoundShape
to join submeshes
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 to merge all submeses before decomposition, which addresses the comment about fusing all submeshes first before doing optimization.
Note that the decomposed submeshes are then still joined together using btCompoundShape
. Same for the unoptimized case. I can change this to using a single mesh in a follow-up PR.
hmm ok to make this happen, we'll need to:
I'll work on these changes |
Signed-off-by: Ian Chen <[email protected]>
|
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
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.
The code LGTM! but I did see a weird behavior while testing.
frameDataModelOptimizedBody.pose.translation().z(), tol); | ||
EXPECT_NEAR(0.0, frameDataModelOptimizedBody.linearVelocity.z(), tol); | ||
|
||
initialModelPose.Pos() += gz::math::Vector3d(0, 2, 0); |
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.
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 added an integration test for this. In the test I set <max_convex_hulls>
to 64 which prevents this penetration. 2099054
The generated convex hulls looked fine with either 16 or 64 max_convex_hulls
so something else is not right. This is something to look into next.
Signed-off-by: Ian Chen <[email protected]>
I found that by setting a small diff --git a/bullet-featherstone/src/Base.cc b/bullet-featherstone/src/Base.cc
index ac66f574..80a04ced 100644
--- a/bullet-featherstone/src/Base.cc
+++ b/bullet-featherstone/src/Base.cc
@@ -49,6 +49,7 @@ WorldInfo::WorldInfo(std::string name_)
// the penentration impulse depends on the erp2 parameter so set to a small
// value (default in bullet is 0.2).
this->world->getSolverInfo().m_erp2 = btScalar(0.02);
+ this->world->getSolverInfo().m_globalCfm = btScalar(0.001); by default |
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Supports convex decomposition on meshes. Bullet-featherstone implementation will parse the new mesh optimization attribute, decompose the mesh into convex meshes, and builds btConvexHullShape collision shapes. Signed-off-by: Ian Chen <[email protected]>
Supports convex decomposition on meshes. Bullet-featherstone implementation will parse the new mesh optimization attribute, decompose the mesh into convex meshes, and builds btConvexHullShape collision shapes. Signed-off-by: Ian Chen <[email protected]>
🎉 New feature
Replaces #603
Depends on
Summary
Supports convex decomposition on meshes. Bullet-featherstone implementation will parse the new mesh
simplificationoptimization attribute introduced in gazebosim/sdformat#1380, decompses the mesh into convex meshes, and buildsbtConvexHullShape
collision shapes.Compared to
btGImpactMeshes
(which is currently used for all meshes), the convex hulls seems to be more stable, do not have gaps between meshes (collision margins can be set to 1mm instead of 1cm), and some manual testing shows potentially faster performance (dependent on the number of submeshes generated)Added test to verify that convex decomposition flag is parsed and valid collisions are generated.
Other changes:
m_erp2
value is now only set when there are meshes in the scene. The param was reduced to improve stability in bullet-featherstone: Improve mesh collision stability #600. I think we do not need to do it globally when there are no meshes in the world as the instability seems to only come from meshes.The value is also bumped up a little too prevent to much penetration - This will likely need more tuning as we do more testing with bullet.To Test
Run gz sim with bullet-featherstone plugin and a world that has a model (e.g. Cordless Drill Simplified) that uses mesh decomposition:
Checklist
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.