Skip to content

Flexcomp seems to ignore the VFS #2805

@Flo-Wo

Description

@Flo-Wo

Intro

Dear MuJoCo-team,

thank you for providing and maintaining such a great simulator. Currently, I am working as an SDE intern at Amazon robotics, using MuJoCo for large-scale simulations. Within our software stack, we are also using flexcomp elements.

My setup

  • Python 3.10
  • MuJoCo: 3.3.5 & 3.3.4
  • macOS: Sequoia 15.6

What's happening? What did you expect?

When loading a stl-file inside a flexcomp tag, I would expect the file to be resolved by the VFS. Instead mujoco expects the file to be in the current working directory.

In the MWE below this is not a big problem, but for more complex setups and files downloaded via custom plugins, this is very tedious or even impossible respectively.

Steps for reproduction

  1. Download a mesh, e.g. scad-p35.stl from https://www.printables.com/model/358708-nonconvex-regularization-examples/files
  2. Run the MWE below:
  • If the stl-file is in the same folder as the python-file, everything works.
  • If the file is only in /meshes and in the VFS, but not in the cwd, the model compilation fails.

Minimal model for reproduction

minimal XML
<mujoco>
  <worldbody>
    <body name="flex_body" pos="0 0 1">
      <flexcomp name="flex_object" type="mesh" file="scad-p35.stl" rigid="true">
        <contact contype="1" conaffinity="1"/>
      </flexcomp>
    </body>
  </worldbody>
</mujoco>

Code required for reproduction

import mujoco

# example stl-file taken from https://www.printables.com/model/358708-nonconvex-regularization-examples/files
meshname = "scad-p35.stl"

xml_model = f"""
<mujoco>
  <!-- with or without assets yields the same outcome -->
  <asset>
    <mesh name="mesh" file="{meshname}"/>
  </asset>
  <worldbody>
    <body name="flex_body" pos="0 0 1">
      <flexcomp name="flex_object" type="mesh" file="{meshname}" rigid="true">
        <contact contype="1" conaffinity="1"/>
      </flexcomp>
    </body>
  </worldbody>
</mujoco>
"""

with open(f"./meshes/{meshname}", "rb") as f:
    stl_data = f.read()

vfs = {}
vfs[meshname] = stl_data

# works, if scad-p35.stl is in the same folder
# fails, if scad-p35.stl is only in meshes/
model = mujoco.MjModel.from_xml_string(xml_model, vfs)
data = mujoco.MjData(model)

mujoco.mj_step(model, data)
print("Model compiled and stepped successfully")

# visualize
import mujoco.viewer
mujoco.viewer.launch(model)

Confirmations

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions