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

Inconsistent Behavior with Mesh Attachment and mj_recompile() #369

Open
d-dimos opened this issue Jan 16, 2025 · 0 comments
Open

Inconsistent Behavior with Mesh Attachment and mj_recompile() #369

d-dimos opened this issue Jan 16, 2025 · 0 comments
Assignees

Comments

@d-dimos
Copy link

d-dimos commented Jan 16, 2025

Description:
I encountered inconsistent behavior when attaching a new mesh to the simulation worldbody and recompiling.

Steps to Reproduce:

  1. Initialize a global mjSpec object (global_spec) and compile it into mjModel and mjData.
  2. Parse a new XML file into a temporary mjSpec object (child_spec).
  3. Attach the worldbody from child_spec to global_spec and recompile.

Code Example:

mjsBody* child_world_body = mjs_findBody(child_spec, "world");
mjsBody* global_world_body = mjs_findBody(global_spec, "world");

mjsFrame* attachment_frame = mjs_addFrame(global_world_body, NULL);
mjsBody* attached_body_to_frame = mjs_attachBody(attachment_frame, child_world_body, "attached-", "-frame");

mj_recompile(global_spec, NULL, m, d);

mj_deleteSpec(child_spec);

Temporary XML file: (parsed into child_spec)

<mujoco>
  <default>
    <default class="visual">
        <geom type="mesh" contype="0" conaffinity="0" group="2"/>
    </default>
    <default class="collision">
      <geom group="3" type="mesh"/>
    </default>
  </default>
  
  <asset>
    <mesh file="path/to/one.obj" scale="0.03 0.03 0.03"/>
  </asset>
  
  <worldbody>
    <body name="one" pos="5 -2 1">
    	<geom mesh="one" class="visual"/>
    	<geom mesh="one" class="collision"/>
    </body>
  </worldbody>
</mujoco>

Expectation: (after recompilation)

Image

Result: (after recompilation)

Image
  • The visualization is incomplete (e.g., a "hemi-sphere").
  • Collisions are (???) consistent, as the agent seems to interact with an invisible object which is located where the true mesh would be.

To verify that the mesh can be loaded successfully, I included the following lines:

<mujoco>
  <asset>
    <mesh file="path/to/one.obj" scale="0.03 0.03 0.03"/>
  </asset>
  
  <worldbody>
    <body name="one" pos="5 -2 1">
    	<geom mesh="one" class="visual"/>
    	<geom mesh="one" class="collision"/>
    </body>
  </worldbody>
</mujoco>

directly to the initial XML used for the initial instantiation (task.xml). In this test, I did not use any recompilation.
The mesh is loaded successfully (as part of the initial global_spec):

Image

Question:
Is this a bug in how MuJoCo handles <default> definitions during recompilation? If not, what changes are necessary to ensure the expected behavior when using attachment and recompilation?

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

No branches or pull requests

2 participants