Skip to content

Missing mesh_* fields from mjx.Model #2685

@hartikainen

Description

@hartikainen

The feature, motivation and pitch

I was playing around with the mjx.Model meshes and noticed that there are some mesh_* fields missing from the definition. Specifically, these exist in the mujoco.MjModel but not in mjx.Model:

  • mesh_facenum
  • mesh_normaladr
  • mesh_normalnum
  • mesh_normal
  • mesh_facenormal
  • mesh_facetexcoord
  • mesh_scale
  • mesh_pathadr
  • mesh_polynum
  • mesh_polyadr
  • mesh_polynormal
  • mesh_polyvertadr
  • mesh_polyvertnum
  • mesh_polyvert
  • mesh_polymapadr
  • mesh_polymapnum
  • mesh_polymap

I thought that maybe these are omitted for purpose, but it feels weird that, for example, mesh_faceadr is defined but mesh_facenum is not because to access the faces of a specific mesh, I think, you need both.

Should these fields be included in the mjx.Model?

Alternatives

I can pass the mujoco.MjModel instance around together with mjx.Model and access the fields from that.

Additional context

import mujoco
from mujoco import mjx


MESH_FIELDS = [
    "mesh_vertadr",
    "mesh_vertnum",
    "mesh_faceadr",
    "mesh_facenum",
    "mesh_bvhadr",
    "mesh_bvhnum",
    "mesh_normaladr",
    "mesh_normalnum",
    "mesh_texcoordadr",
    "mesh_texcoordnum",
    "mesh_graphadr",
    "mesh_vert",
    "mesh_normal",
    "mesh_texcoord",
    "mesh_face",
    "mesh_facenormal",
    "mesh_facetexcoord",
    "mesh_graph",
    "mesh_scale",
    "mesh_pos",
    "mesh_quat",
    "mesh_pathadr",
    "mesh_polynum",
    "mesh_polyadr",
    "mesh_polynormal",
    "mesh_polyvertadr",
    "mesh_polyvertnum",
    "mesh_polyvert",
    "mesh_polymapadr",
    "mesh_polymapnum",
    "mesh_polymap",
]

xml = """
<mujoco>
  <asset>
    <mesh name="tetrahedron" vertex="0 0 1  1 -1 0  1 1 0  -1 0 0" face="0 1 2  0 2 3  0 3 1  1 3 2"/>
  </asset>
  <worldbody>
    <geom name="mesh_geom" type="mesh" mesh="tetrahedron" pos="0 0 1.5" mass="1"/>
    <geom name="sphere_geom" type="sphere" size="0.3" pos="-1 0 1" mass="1"/>
    <geom name="box_geom" type="box" size="0.2 0.3 0.4" pos="1 0 1" mass="1"/>
  </worldbody>
</mujoco>
"""

spec = mujoco.MjSpec.from_string(xml)
model = spec.compile()
modelx = mjx.put_model(model)

fields_present = []
fields_missing = []

for field in MESH_FIELDS:
    assert hasattr(model, field), f"Field {field} is not present in `mujoco.Model`."
    if hasattr(modelx, field):
        fields_present.append(field)
    else:
        fields_missing.append(field)

print("Fields present in `mjx.Model`:")
for field in fields_present:
    print(f"  - {field}")
print("\nFields missing in `mjx.Model`:")
for field in fields_missing:
    print(f"  - {field}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    MJXUsing JAX to run on GPUenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions