Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/mjviser/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ def merge_geoms(mj_model: mujoco.MjModel, geom_ids: list[int]) -> trimesh.Trimes
"""Merge multiple geoms into a single trimesh in local body space."""
meshes = []
for geom_id in geom_ids:
if mj_model.geom_type[geom_id] in (mjtGeom.mjGEOM_MESH, mjtGeom.mjGEOM_SDF):
# int() cast: geom_type is a numpy scalar, and `np_scalar in (enum, ...)`
# evaluates `enum == np_scalar`, which is False for pybind11 enums.
if int(mj_model.geom_type[geom_id]) in (int(mjtGeom.mjGEOM_MESH), int(mjtGeom.mjGEOM_SDF)):
meshes.append(mujoco_mesh_to_trimesh(mj_model, geom_id))
else:
meshes.append(create_primitive_mesh(mj_model, geom_id))
Expand Down
9 changes: 9 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,15 @@ def test_merge_geoms(simple_model):
assert len(mesh.vertices) > 0


def test_merge_geoms_with_mesh_geom(cubemap_model):
# Regression: geom_type is a numpy scalar, and the enum membership test in
# merge_geoms silently evaluated False for mesh geoms, raising
# "ValueError: Unsupported shape type: 7".
mesh = merge_geoms(cubemap_model, [0])
assert isinstance(mesh, trimesh.Trimesh)
assert len(mesh.vertices) > 0


def test_group_geoms_by_visual_compat_splits_textured_hfield():
xml = """
<mujoco>
Expand Down