flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.35k stars 415 forks source link

Using fcl::Convexd meshes with broadphase collision managers #583

Open JeffHough opened 1 year ago

JeffHough commented 1 year ago

I'm currently using FCL to perform collision detection on non-convex shapes, which I have broken down into several convex meshes. I then group together these convex meshes into fcl::BVHModel<fcl::OBBRSSd> models to create rigid bodies, and perform the collision checks using the fcl::DynamicAABBTreeCollisionManagerd broadphase collision manager (these are the settings which I have found to have the highest speed).

I recently noticed while rereading the documentation that fcl supports a fcl::Convex<> primative type. Presumably, this would use a better support function at the narrowphase level, and give a pretty significant speed boost compared to assuming the meshes may be non-convex. However, I cannot seem to find a way to add a convex mesh file into any broadphase collision managers?

Basically, my current code looks something like this:

  using Model = fcl::BVHModel<fcl::OBBRSSd>;

  // Creation of the collision objects:
  for (int i = 0 ; i < number_of_rigid_bodies ; ++i) {
    auto rigid_body = std::make_shared<Model>();
    rigid_body->beginModel();

    for (for const auto& mesh_file : mesh_files) {
      // Load in the object_geometry geometry:
      rigid_body->addSubModel(mesh_file.vertices, mesh_file.triangles);
    }
    rigid_body->endModel();

    // Use the meshes above to create a new collision object
    rigid_bodies[i] = new fcl::CollisionObjectd(rigid_body, Eigen::Matrix4d::Identity());

    // Compute the axis-aligned bounding box of the new object as a whole:
    rigid_bodies.back()->computeAABB();
  }

And I would like to tell fcl to treat the lowest level meshes as convex, so changing this line:

rigid_body->addSubModel(mesh_file.vertices, mesh_file.triangles);

to something like this:

rigid_body->addSubModel(fcl::Convexd(mesh_file.vertices, mesh_file.triangles));

Thanks!

OxDuke commented 1 year ago

With the current implementation of fcl, I don't think you are able to do:

And I would like to tell fcl to treat the lowest level meshes as convex, so changing this line:

The way I would do it is to create a bunch of fcl::CollisionObject<> using fcl::Convex<> as the collision geometry, and add these collision objects into a broadphase collision manager (e.g. fcl::DynamicAABBTreeCollisionManager<>).