Skip to content

Misleading example demo_MBS_collision_trimesh #541

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

Open
bmo-Scape opened this issue Jan 22, 2025 · 2 comments
Open

Misleading example demo_MBS_collision_trimesh #541

bmo-Scape opened this issue Jan 22, 2025 · 2 comments

Comments

@bmo-Scape
Copy link

Based on the example demo_MBS_collision_trimesh, one might think that Chrono/bullet is able to do collision checking of concave meshes. Also, visually inspecting the simulation suggests that this is perfectly feasible (adding 30 objects instead of 15 and removed the spheres):

Image

The objects are lying nicely stacked on each other and the simulation seems reasonable.

But using a different mesh, namely just the simplest possible cube instead but through a ChTriangleMeshConnected-object like this:

// const auto mesh = ChTriangleMeshConnected::CreateFromWavefrontFile(GetChronoDataFile("models/bulldozer/shoe_view.obj"), false, true);
const auto mesh = ChTriangleMeshConnected::CreateFromSTLFile("PathToBasicCube.stl", false);

, the simulation looks like this, where lots of the objects are lying inside each other:

Image

Instead of assuming that the code is able to do this kind of collision checking, I would suggest that that example is modified to copy the triangles from mesh into a std::shared_ptr<ChTriangleMeshSoup> and then set that on the ChCollisionShapeTriangleMesh. This would result in ChCollisionModelBullet::injectTriangleMesh(...) creating convex decompositions of the meshes and therefore a much more stable simulation. Also, that approach would be usable as a starting approach for others wanting to implement something that requires simulations using concave meshes.

@bmo-Scape
Copy link
Author

Hmm, using the convex decomposition might be slightly less trivial than what I initially thought because doing the above (creating a ChTriangleMeshSoup for the collision chape) in debug mode leads to an assert failure in "chrono_thirdparty\HACDv2\dgGoogol.cpp" line 280:

HACD_ASSERT (hacd::HaI64 (A.m_mantissa[0]) >= 0);

@bmo-Scape
Copy link
Author

A final update is that it seems to work even better when being even more explicit about using convex hulls for the collision shape.

Add the following after having loaded and scaled the mesh:

// using HACDv2 convex decomposition for collision shape. Using ChTriangleMeshConnected directly will NOT give the desired/correct collisions.
auto pDecomposition = chrono_types::make_shared<ChConvexDecompositionHACDv2>();
pDecomposition->AddTriangleMesh(*mesh);
pDecomposition->SetParameters(512,   // max hull count
                             256,   // max hull merge
                             64,    // max hull vettices
                             0.2f,  // concavity
                             0.0f,  // small cluster threshold
                             1e-9f  // fuse tolerance
);

pDecomposition->ComputeConvexDecomposition();

std::vector<std::shared_ptr<ChCollisionShapeConvexHull>> CollisionShapes;
for (unsigned int j = 0; j < pDecomposition->GetHullCount(); j++) {
    std::vector<ChVector3d> ptlist;
    pDecomposition->GetConvexHullResult(j, ptlist);
    if (ptlist.size() > 0) {
        const auto shape_hull = chrono_types::make_shared<ChCollisionShapeConvexHull>(mesh_mat, ptlist);
        CollisionShapes.push_back(shape_hull);
    }
}

And then add those to the falling shapes like this:

for (const std::shared_ptr<ChCollisionShapeConvexHull>& pCollisionShape : CollisionShapes) {
    falling->AddCollisionShape(pCollisionShape);
}

That gives the following nice pile of objects:
Image

And when changing to the simple boxes, the objects no longer intersect:
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant