Skip to content
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

Add mesh support #156

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

lorycontixd
Copy link

@lorycontixd lorycontixd commented May 20, 2024

This pull requests aims to extend Jaxsim's parsing functionalities on robot descriptions to meshes.
It does so by using third-party library trimesh to parse the mesh file, and custom algorithm create_mesh_collisions to wrap a mesh with collidable points.


📚 Documentation preview 📚: https://jaxsim--156.org.readthedocs.build//156/

@flferretti
Copy link
Collaborator

@lorycontixd do you prefer a squash and merge or can you please clean the commit history?

Copy link
Collaborator

@flferretti flferretti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lorycontixd! I wrote some initial comments

.vscode/settings.json Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
tests/test_parser_mesh.py Outdated Show resolved Hide resolved
Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @lorycontixd, it's a great start. First minor changes, I'll review the logic in more detail after these ones are addressed.

.vscode/settings.json Outdated Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
src/jaxsim/parsers/rod/parser.py Outdated Show resolved Hide resolved
- Moved mesh parsing logic inside method for creating mesh collisions
- Removed vs code settings
- Removed empty mesh parsing test
Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments on trimesh usage. Almost good on my side, I'll do a final check tomorrow.

src/jaxsim/parsers/rod/parser.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
@diegoferigo
Copy link
Member

For the records, this is the function called to load a mesh in trimesh:

https://trimesh.org/trimesh.html#trimesh.load

@flferretti
Copy link
Collaborator

@diegoferigo before merging this, do we want to set meshes support as default or should it be activated using an environment variable?

@diegoferigo
Copy link
Member

@diegoferigo before merging this, do we want to set meshes support as default or should it be activated using an environment variable?

Yes I need to properly assess the implications of merging this PR on existing appplications. Automatically adding the collidable points of all meshes is a huge change of behavior and it will make existing simulations unbearably slow.

@lorycontixd
Copy link
Author

lorycontixd commented May 21, 2024

@diegoferigo @flferretti As of now, random point sampling from a mesh is supported. I think it would be a good idea if I tried to benchmark different values of sampling points and find a good tradeoff between performance and simulation results.

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost ready, last comments on the changes before started assessing the new default behavior of mesh collisions in JaxSim.

setup.cfg Show resolved Hide resolved
src/jaxsim/parsers/descriptions/collision.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/descriptions/collision.py Outdated Show resolved Hide resolved
Comment on lines +335 to +336
if mesh_collision is not None:
collisions.append(mesh_collision)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this ever happen? I guess that in the case utils.create_mesh_collision fails, an exception is raised.

Comment on lines +233 to +235
if mesh.is_empty:
logging.warning(f"Mesh {collision.geometry.mesh.uri} is empty, ignoring it")
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can this happpen? The mesh variable is populated by trimesh. If the parsing fails, I'd expect that trimesh raises. If the library does not raise, I'd change the code as follows:

Suggested change
if mesh.is_empty:
logging.warning(f"Mesh {collision.geometry.mesh.uri} is empty, ignoring it")
return
if mesh.is_empty:
raise RuntimeError(f"Failed to process '{file}' with trimesh")

src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/rod/utils.py Outdated Show resolved Hide resolved
- Remove leftover comments
- MeshMappingMethods inherit from IntEnum instead of Enum
- Added center comparison for MeshCollision object
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

Successfully merging this pull request may close these issues.

None yet

3 participants