google / brax

Massively parallel rigidbody physics simulation on accelerator hardware.
Apache License 2.0
2.14k stars 234 forks source link

Collision with hollow object with openings #408

Closed eleninisioti closed 8 months ago

eleninisioti commented 8 months ago

I would like to add an object in the environment that is an obstacle with openings on the sides the agent can enter from. I thought of using a cylinder but I see it is not supported by brax. Do you have any insight on why this is the case? If I wanted to add support for it I guess I would need to modify geometry/contact.py. There I see there is support for collisions with convex objects, so am wondering why a cylinder is not covered.

Or I am open to suggestions on using other types of shapes that are hollow with openings. For example it seems that collisions with arbitrary mesh is supported, so I could define a cylinder as a mesh?

btaba commented 8 months ago

Hi @eleninisioti , convex<>convex collisions are generally not performant in Brax, so I would try to stick to primitives (capsules) or primitives with convex collisions. If cylinder is required for your use-case, consider implementing a cylinder collision function, for example here is a cylinder<>sphere collision implementation that doesn't deal with meshes:

https://github.com/google-deepmind/mujoco/blob/3f3d5a3b49547bb125f6b2c2fdea4eba039875e7/src/engine/engine_collision_primitive.c#L326

Or try to reduce the vertex size of your cylinder and use the convex functions with the expectation that convex<>convex may significantly slow down your simulation.