Description
Is your feature request related to a problem? Please describe.
A common problem we are experiencing with users using MuJoCo with iCub models (see robotology/icub-models#155 for a related issue) are related to the fact that the MuJoCo URDF parser strips any path information from the filename
attribute of meshes. See
Lines 565 to 572 in 7c534a0
Describe the solution you'd like
Possible solutions include look for meshes specified via package://
URIs by inspecting the values of ROS_PACKAGE_PATH
(for ROS1-style packages) or AMENT_PREFIX_PATH
(for ROS2-style packages). This can be done without any specific dependency on ROS via some dedicated code. For an example of how this is implemented in other libraries that consume URDFs like iDynTree or Pinocchio see the following snippets:
- iDynTree: https://github.com/robotology/idyntree/blob/ff407448de6fbc635353dbdb31dcc3d913f15820/src/model/src/SolidShapes.cpp#L216-L308
- pinocchio: https://github.com/stack-of-tasks/pinocchio/blob/0caf0ca4d07e63834cdc420c703993662c59e01b/src/parsers/urdf/geometry.cpp#L460-L462 and https://github.com/stack-of-tasks/pinocchio/blob/0caf0ca4d07e63834cdc420c703993662c59e01b/src/utils/file-explorer.cpp#L55
For reference, a similar logic is implemented in the following minimal Python package https://github.com/ami-iit/resolve-robotics-uri-py/blob/main/src/resolve_robotics_uri_py/resolve_robotics_uri_py.py#L19-L68 . This code is not directly usable in the mujoco C++ URDF parser, but it just meant to show how the logic works.
Describe alternatives you've considered
An alternative choice done by Drake, is instead not to hardcode the lookup for any environment variable inside the library itself, but rather expose an API for users to specify the directories in which to look for files specified via package://
URIs, see RobotLocomotion/drake-external-examples#170 for an example of this. While this may require more work on the users to actually successfully parse URDF files, that would also a way to fix the problem.
Additional context
I will be happy to eventually work on this, but I would like to understand if maintainers are interested in this.