Unable to load MJCFs using <compiler meshdir="\path">
Hi all!
I am working with (complex) custom .mjcf
models in Isaac Gym, which contain a lot of different mesh assets. To avoid repetition of paths and make assembling multi-level mjcfs
with includes easier, .mjcf
xml
allows you to prepend a path to all of your meshes by setting the meshdir
attribute of your compiler
element. However, Isaac Gym does not seem to prepend these paths to the file
attribute of mesh
assets, and throws an error such as
[Error] [carb.gym.plugin] *** Failed to load '/home/someuser/isaac_gym_env/isaacgymenvs/tasks/../../assets/mjcf/somemodel.stl'!
I am right now working around this in a very rudimentary way - if anyone knows a more elegant approach, or, better yet, a fix, it would be great!
Minimal reproducing example
To reproduce this error, create a directory named mesh_test
in the assets/mjcf
folder of your IsaacGymEnvs repo, place an arbitrary stl
file named base.stl
in it, and modify nv_ant.xml
as follows:
<mujoco model="ant">
<custom>
<numeric data="0.0 0.0 0.55 1.0 0.0 0.0 0.0 0.0 1.0 0.0 -1.0 0.0 -1.0 0.0 1.0" name="init_qpos"/>
</custom>
<default>
<joint armature="0.01" damping="0.1" limited="true"/>
<geom condim="3" density="5.0" friction="1.5 0.1 0.1" margin="0.01" rgba="0.97 0.38 0.06 1"/>
</default>
<compiler inertiafromgeom="true" angle="degree"/>
<option timestep="0.016" iterations="50" tolerance="1e-10" solver="Newton" jacobian="dense" cone="pyramidal"/>
<size nconmax="50" njmax="200" nstack="10000"/>
<visual>
<map force="0.1" zfar="30"/>
<rgba haze="0.15 0.25 0.35 1"/>
<quality shadowsize="2048"/>
<global offwidth="800" offheight="800"/>
</visual>
<!-- Test: Does IsaacGym support the "meshdir" argument of the compiler? -->
<!-- This should work, but crashes the simulation: -->
<compiler meshdir="mesh_test"/>
<asset>
<mesh name="base" file="base.stl" scale="0.001 0.001 0.001"/>
</asset>
<!-- This works, but causes problems for large/multilevel models
<asset>
<mesh name="base" file="mesh_test/base.stl" scale="0.0001 0.0001 0.0001"/>
</asset>
-->
<asset>
<texture type="skybox" builtin="gradient" rgb1="0.3 0.5 0.7" rgb2="0 0 0" width="512" height="512"/>
<texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2" width="512" height="512" mark="cross" markrgb=".8 .8 .8"/>
<texture name="texgeom" type="cube" builtin="flat" mark="cross" width="127" height="1278"
rgb1="0.8 0.6 0.4" rgb2="0.8 0.6 0.4" markrgb="1 1 1" random="0.01"/>
<material name="matplane" reflectance="0.3" texture="texplane" texrepeat="1 1" texuniform="true"/>
<material name="matgeom" texture="texgeom" texuniform="true" rgba="0.8 0.6 .4 1"/>
</asset>
<worldbody>
<geom name="floor" pos="0 0 0" size="0 0 .25" type="plane" material="matplane" condim="3"/>
<light directional="false" diffuse=".2 .2 .2" specular="0 0 0" pos="0 0 5" dir="0 0 -1" castshadow="false"/>
<light mode="targetbodycom" target="torso" directional="false" diffuse=".8 .8 .8" specular="0.3 0.3 0.3" pos="0 0 4.0" dir="0 0 -1"/>
<body name="torso" pos="0 0 0.75">
<freejoint name="root"/>
<geom mesh="base"/>
<geom name="torso_geom" pos="0 0 0" size="0.25" type="sphere"/>
<geom fromto="0.0 0.0 0.0 0.2 0.2 0.0" name="aux_1_geom" size="0.08" type="capsule" rgba=".999 .2 .1 1"/>
<geom fromto="0.0 0.0 0.0 -0.2 0.2 0.0" name="aux_2_geom" size="0.08" type="capsule"/>
<geom fromto="0.0 0.0 0.0 -0.2 -0.2 0.0" name="aux_3_geom" size="0.08" type="capsule"/>
<geom fromto="0.0 0.0 0.0 0.2 -0.2 0.0" name="aux_4_geom" size="0.08" type="capsule" rgba=".999 .2 .02 1"/>
<body name="front_left_leg" pos="0.2 0.2 0">
<joint axis="0 0 1" name="hip_1" pos="0.0 0.0 0.0" range="-40 40" type="hinge"/>
<geom fromto="0.0 0.0 0.0 0.2 0.2 0.0" name="left_leg_geom" size="0.08" type="capsule" rgba=".999 .2 .1 1"/>
<body pos="0.2 0.2 0" name="front_left_foot">
<joint axis="-1 1 0" name="ankle_1" pos="0.0 0.0 0.0" range="30 100" type="hinge"/>
<geom fromto="0.0 0.0 0.0 0.4 0.4 0.0" name="left_ankle_geom" size="0.08" type="capsule" rgba=".999 .2 .1 1"/>
</body>
</body>
<body name="front_right_leg" pos="-0.2 0.2 0">
<joint axis="0 0 1" name="hip_2" pos="0.0 0.0 0.0" range="-40 40" type="hinge"/>
<geom fromto="0.0 0.0 0.0 -0.2 0.2 0.0" name="right_leg_geom" size="0.08" type="capsule"/>
<body pos="-0.2 0.2 0" name="front_right_foot">
<joint axis="1 1 0" name="ankle_2" pos="0.0 0.0 0.0" range="-100 -30" type="hinge"/>
<geom fromto="0.0 0.0 0.0 -0.4 0.4 0.0" name="right_ankle_geom" size="0.08" type="capsule"/>
</body>
</body>
<body name="left_back_leg" pos="-0.2 -0.2 0">
<joint axis="0 0 1" name="hip_3" pos="0.0 0.0 0.0" range="-40 40" type="hinge"/>
<geom fromto="0.0 0.0 0.0 -0.2 -0.2 0.0" name="back_leg_geom" size="0.08" type="capsule"/>
<body pos="-0.2 -0.2 0" name="left_back_foot">
<joint axis="-1 1 0" name="ankle_3" pos="0.0 0.0 0.0" range="-100 -30" type="hinge"/>
<geom fromto="0.0 0.0 0.0 -0.4 -0.4 0.0" name="third_ankle_geom" size="0.08" type="capsule"/>
</body>
</body>
<body name="right_back_leg" pos="0.2 -0.2 0">
<joint axis="0 0 1" name="hip_4" pos="0.0 0.0 0.0" range="-40 40" type="hinge"/>
<geom fromto="0.0 0.0 0.0 0.2 -0.2 0.0" name="rightback_leg_geom" size="0.08" type="capsule" rgba=".999 .2 .1 1"/>
<body pos="0.2 -0.2 0" name="right_back_foot">
<joint axis="1 1 0" name="ankle_4" pos="0.0 0.0 0.0" range="30 100" type="hinge"/>
<geom fromto="0.0 0.0 0.0 0.4 -0.4 0.0" name="fourth_ankle_geom" size="0.08" type="capsule" rgba=".999 .2 .1 1"/>
</body>
</body>
</body>
</worldbody>
<actuator>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="hip_4" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="ankle_4" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="hip_1" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="ankle_1" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="hip_2" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="ankle_2" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="hip_3" gear="15"/>
<motor ctrllimited="true" ctrlrange="-1.0 1.0" joint="ankle_3" gear="15"/>
</actuator>
</mujoco>
This modification should crash python train.py task=Ant
. You can also see that it loads correctly if you comment L24-L27 and uncomment L29-L32.
Current quick fix
Right now, I just modify all my paths to point to the right directory by hand (see the example above). This is problematic as:
- It makes modifications longer/more prone to errors.
- If I use a file from a submodule that is being modified all the time for other projects, I have to update the paths for all new versions.
Thanks in advance!
Ben