dm_control
dm_control copied to clipboard
Adding skin file to mjcf model
Hello, I'm relatively new to Mujoco and the dm_control package. I've encountered the following issue, that I am not able to solve on my own.
At first I wanted to add a skin file via the mjcf interface of dm_control but this didn't work and the following error appeared.
│ ~/.pyenv/versions/3.8.10/lib/python3.8/site-packages/dm_control/mjcf/skin.py:85 in │
│ serialize │
│ │
│ 82 out.write(skin.texcoords.astype('<f4').tobytes()) │
│ 83 out.write(skin.faces.astype('<i4').tobytes()) │
│ 84 for bone in skin.bones: │
│ ❱ 85 │ body_bytes = bone.body().full_identifier.encode('utf-8') │
│ 86 │ if len(body_bytes) > MAX_BODY_NAME_LENGTH: │
│ 87 │ raise ValueError( │
│ 88 │ │ 'body name is longer than permitted by the skin file format '
AttributeError: 'NoneType' object has no attribute 'full_identifier'
To make sure this is not due to my wrong way of using the library I created a minimal xml file that works in the basic mujoco viewer. The skin file will be displayed correctly. Here is the minimal xml file
<mujoco model="Banjuu">
<asset>
<skin file="niku_skin.skn" />
</asset>
<worldbody>
<body name="nagahosoiB1" pos="0 0 0.1">
<composite prefix="nagahosoi" type="rope" count="3 1 1" spacing="0.04" offset="0 0 2">
<joint kind="main" damping="0.025" stiffness="0.0"/>
<geom type="capsule" size=".008 .013" rgba=".8 .2 .1 1" mass="0.004" />
</composite>
</body>
</worldbody>
</mujoco>
If I'm running this minimal script and loading the above minimal.xml I get the same exception as before even though the same xml file worked in mujoco.viewer.launch
from dm_control import composer
from dm_control import viewer
from dm_control import mjcf
class Environment(composer.Entity):
def _build(self, environment_xml: str):
self._model = mjcf.from_path(environment_xml)
@property
def mjcf_model(self):
return self._model
class ExampleTask(composer.Task):
def __init__(self, environment_xml: str):
super().__init__()
self._root_entity = Environment(environment_xml)
self._task_observables = {}
@property
def root_entity(self):
return self._root_entity
@property
def task_observables(self):
return self._task_observables
def get_reward(self, physics):
return 0
def create_and_view(environment_xml: str):
task= ExampleTask(environment_xml)
env = composer.Environment(task)
env.reset()
viewer.launch(env)
if __name__ == "__main__":
create_and_view("minimal.xml")
Commenting out the <skin file=" will fix the error and I see the composite displayed correctly but adding the file attribute seems to mess things up. If there is some way to circumvent that please let me know