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 36 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
@lorycontixd lorycontixd force-pushed the add_mesh_support branch 4 times, most recently from bf8bd78 to 195cb68 Compare May 20, 2024 15:56
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.

@@ -74,6 +75,7 @@ style =
pre-commit
testing =
idyntree >= 12.2.1
networkx
Copy link
Member

Choose a reason for hiding this comment

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

What is this new dependency used for?

src/jaxsim/parsers/descriptions/collision.py Outdated Show resolved Hide resolved
src/jaxsim/parsers/descriptions/collision.py Outdated Show resolved Hide resolved
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.

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
tests/conftest.py Outdated Show resolved Hide resolved
@diegoferigo
Copy link
Member

Reminder to myself: bump the version of the ROD dependency before merging this PR.

@lorycontixd lorycontixd force-pushed the add_mesh_support branch 2 times, most recently from 0dddfc1 to c28ae05 Compare June 12, 2024 15:28
@flferretti
Copy link
Collaborator

@lorycontixd if you see commits pushed by a bot, don't worry. We can squash those. This should stop as soon as #197 gets merged

@lorycontixd
Copy link
Author

I was wondering 😂 Thanks for letting me know!

src/jaxsim/parsers/descriptions/collision.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
lorycontixd and others added 14 commits July 5, 2024 16:08
- Restructured mesh_collision creation method
- Removed unnecessary hash inheritance
- Implemented AAP algorithm
- Restructured collision parsing to accept the new algorithms
- Wrote tests for AAP algorithm
- Updated JaxSim dependencies
- New mesh wrapping algorithms (mesh decimation, object mapping, aap, select points over axis)
- Implemented tests of above except first algorithm
- Updated manifold3d dependency (used in object mapping)
- Restructured meshes module
- Renamed some function paramaeters
- Added a few tests
TODO: migrate MeshMapping static class to inheritance structure
- Redefined methods using classes
- Adapted rod parser to new structure
- Reimplemented tests with new structure
Implement a set of new mesh wrapping algorithms for extra performance
- Removed a line that would always set the extracted points to the vertices
- Added a few debug lines using logger
- Added string magics on mesh wrapping methods for easier logging
- Added log to indicate number of extracted points
- Added extra check on objectmapping method
@lorycontixd
Copy link
Author

Must find a way to inject the wrapping method from outside the api (create_mesh_collision func.) for each mesh, if needed.

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