Skip to content

add support for mjGEOM_SDF - #31

Merged
kevinzakka merged 2 commits into
mujocolab:mainfrom
nmarticorena:feat-add-sdf-support
Aug 7, 2026
Merged

kevinzakka merged 2 commits into
mujocolab:mainfrom
nmarticorena:feat-add-sdf-support

Conversation

@nmarticorena

Copy link
Copy Markdown
Contributor

Hi @kevinzakka, first thanks for all the effort on both mjviser and mjlab there are awesome tools to use.

This really small pr aims to add the capability to mjviser to use mjGEOM_SDF objects.

From the mujoco docs the SDF plugin for custom shapes in a mesh-free manner, by defining methods computing a signed distance field and its gradient at query points that is quite useful for non-convex geometries, due to the sdf plugin computes a visual mesh for rendering using marching cubes the only requirement for mjviser is treating mjGEOM_SDF as a mesh.

Currently when trying to load the xml example scene bowl.xm gets the current output:

Traceback (most recent call last):
  File "/home/vlu/Documents/extras/mjviser/.venv/bin/mjviser", line 10, in <module>
    sys.exit(main())
             ~~~~^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/__main__.py", line 123, in main
    Viewer(model, data, server=server).run()
    ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/viewer.py", line 76, in __init__
    self.scene = ViserMujocoScene(self._server, model, num_envs=num_envs)
                 ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/scene.py", line 200, in __init__
    self._add_fixed_geometry()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/scene.py", line 1104, in _add_fixed_geometry
    merge_geoms(self.mj_model, sub_geom_ids),
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/conversions.py", line 588, in merge_geoms
    meshes.append(create_primitive_mesh(mj_model, geom_id))
                  ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/conversions.py", line 307, in create_primitive_mesh
    mesh = _create_shape_mesh(geom_type, mj_model.geom_size[geom_id])
  File "/home/vlu/Documents/extras/mjviser/src/mjviser/conversions.py", line 281, in _create_shape_mesh
    raise ValueError(f"Unsupported shape type: {geom_type}")
ValueError: Unsupported shape type: 8

After this small change the behavior is as expected
mjGEOM_SDF

@kevinzakka
kevinzakka self-requested a review August 7, 2026 01:46

@kevinzakka kevinzakka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @nmarticorena!

@kevinzakka

Copy link
Copy Markdown
Contributor

Could you just fix the lint formatting test?

@nmarticorena

Copy link
Copy Markdown
Contributor Author

Thanks for the quick response!, changes applied

@kevinzakka
kevinzakka merged commit ae0b219 into mujocolab:main Aug 7, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

2 participants