menagerie
Helpers for loading models from the MuJoCo Menagerie submodule.
The MuJoCo Menagerie (google-deepmind/mujoco_menagerie) is an optional
dependency distributed as a git submodule under third_party/mujoco_menagerie
in this repository. Initialise it once with::
git submodule update --init third_party/mujoco_menagerie
Then models can be loaded with a single call::
from openscvx.integrations.menagerie import get_xml_path, load_mjmodel
mj_model = load_mjmodel("skydio_x2")
Discovery order¶
MUJOCO_MENAGERIE_PATHenvironment variable.<repo_root>/third_party/mujoco_menagerie(the git submodule).~/mujoco_menagerie(common manual install location).
XML file selection (prefer_mjx=True)¶
If the model directory contains an mjx_*.xml file it is preferred over the
standard XML because it has been tuned for MJX (reduced contacts, simplified
geoms, etc.). Scene XML files (scene*.xml) are always excluded unless the
caller explicitly names the file.
Example¶
Load the Skydio X2 and disable contacts for MJX differentiability::
import mujoco
import mujoco.mjx as mjx
from openscvx.integrations.menagerie import load_mjmodel
mj_model = load_mjmodel("skydio_x2")
mj_model.opt.disableflags |= mujoco.mjtDisableBit.mjDSBL_CONTACT
mjx_model = mjx.put_model(mj_model)
find_menagerie_root() -> Path | None
¶
Return the path to the mujoco_menagerie root directory, or None.
Checks, in order:
1. MUJOCO_MENAGERIE_PATH environment variable.
2. <repo_root>/third_party/mujoco_menagerie (git submodule).
3. ~/mujoco_menagerie.
Source code in openscvx/integrations/menagerie.py
get_asset_dir(model_name: str) -> Path
¶
Return the assets/ sub-directory for model_name, if it exists.
Useful for loading mesh and texture files for custom visualisers.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no |
Source code in openscvx/integrations/menagerie.py
get_model_dir(model_name: str) -> Path
¶
Return the directory for model_name inside the menagerie.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model directory (e.g. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the menagerie root or the model cannot be found. |
Source code in openscvx/integrations/menagerie.py
get_xml_path(model_name: str, prefer_mjx: bool = True) -> Path
¶
Return the path to the best XML file for model_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model directory (e.g. |
required |
prefer_mjx
|
bool
|
When |
True
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the selected XML file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no XML file can be found. |
Source code in openscvx/integrations/menagerie.py
list_models() -> list[str]
¶
Return the names of all models available in the menagerie.
Returns an empty list if the menagerie is not found.
Source code in openscvx/integrations/menagerie.py
load_mjmodel(model_name: str, prefer_mjx: bool = True) -> 'mujoco.MjModel'
¶
Load a mujoco.MjModel for model_name from the menagerie.
Asset paths (meshes, textures) are resolved automatically by MuJoCo relative to the XML file, so the full mesh geometry is available without any extra configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model directory (e.g. |
required |
prefer_mjx
|
bool
|
Prefer |
True
|
Returns:
| Type | Description |
|---|---|
'mujoco.MjModel'
|
A |
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
FileNotFoundError
|
If the menagerie or model cannot be found. |
Example::
import mujoco.mjx as mjx
from openscvx.integrations.menagerie import load_mjmodel
mj_model = load_mjmodel("skydio_x2")
mj_model.opt.disableflags |= mujoco.mjtDisableBit.mjDSBL_CONTACT
mjx_model = mjx.put_model(mj_model)