compas-dev / compas_fab

Robotic fabrication package for the COMPAS Framework.
https://compas.dev/compas_fab/
MIT License
108 stars 32 forks source link

PyBullet client: check if collision meshes are convex #322

Closed inesariza closed 2 years ago

inesariza commented 2 years ago

Feature Request

As a user of the PyBullet client, I want to check if collision meshes are convex before any collision detection operation is performed.

Details

Is your feature request related to a problem? Please describe. Even if using this client often one could forget the implicit rule that meshes need to be convex. It would be great to check for this automatically.

Describe the solution you'd like Ideally, when adding collision meshes to the scene, concave meshes raise a warning telling the user that a convex hull operation will be performed. The user can then decide if continuing with the convex hull or updating inputs (decomposing the input meshes to make them convex).

Describe alternatives you've considered Alternatively, the user gets a warning message for each convex hull operation including the name of the mesh that has been wrapped.

beverlylytle commented 2 years ago

I see why this would be a useful feature for you, but I'm worried about the performance cost. I don't think compas has a is_convex method for meshes, and it doesn't look like pybullet exposes such a thing in it's api. So if i were to write such a function in python, I think this would be a very time consuming operation depending on the complexity of the meshes involved. (I think the runtime would be on the order of #vertices*#faces.) I would be tempted to hide such checks behind a flag so that users who don't want to deal with this performance hit could avoid it, but that would go against the request that this check is automatic. The other option is to automatically apply V-HACD to each mesh, breaking it into convex pieces. Pybullet comes with V-HACD, but only for meshes stored in obj files.

Or am I wrong @gonzalocasas ? is there a quick and painless way in compas/python to check if meshes are convex?

inesariza commented 2 years ago

thank you for your assessment and reply, @beverlylytle!

Sounds like the convexity check would be costly and would not really solve the problem (i.e., that we want convex meshes).

Having the option of applying V-HACD would be best for most cases. For this solution then, the only limitation is that we need .objs instead of compas meshes?

beverlylytle commented 2 years ago

Yes. What could be done is adding a flag somewhere... maybe on load_robot and also the planning scene methods, which would apply V-HACD when the flag is True. (Behind the scenes, the PyBulletClient already does a lot of converting compas meshes to obj files to load into the pybullet server.) So, handling convexity would not be automatic, but semi-automatic ;)