Skip to main content

rerun-loader-mjcf

CI

A Rerun external data loader for MJCF (MuJoCo XML) files.

https://github.com/user-attachments/assets/a9f95ed6-1441-4ce0-bef8-c3fb1e720d56

Simulating fourier_n1 and boston_dynamics_spot from mujoco_menagerie:

uv run rerun-loader-mjcf --simulate mujoco_menagerie/fourier_n1/scene.xml
uv run rerun-loader-mjcf --simulate mujoco_menagerie/boston_dynamics_spot/scene.xml

https://github.com/user-attachments/assets/36aab5aa-134f-49a3-92d4-efb6b61e9354

Loading all robots from mujoco_menagerie

Installation

pip install rerun-loader-mjcf

Usage

CLI

rerun-loader-mjcf robot.xml

To run a real-time simulation loop:

rerun-loader-mjcf robot.xml --simulate

Or run directly without installing:

uvx rerun-loader-mjcf robot.xml

Python API

import mujoco
import rerun as rr
import rerun_loader_mjcf

model = mujoco.MjModel.from_xml_path("robot.xml")
data = mujoco.MjData(model)

rr.init("mjcf_viewer", spawn=True)
logger = rerun_loader_mjcf.MJCFLogger(model)

rr.set_time("frame", sequence=0)
logger.log_model()

data.qpos[0] += 0.5
mujoco.mj_forward(model, data)

rr.set_time("frame", sequence=1)
logger.log_data(data)

Options

logger = rerun_loader_mjcf.MJCFLogger(
    model,
    entity_path_prefix="robot",  # Prefix for all entity paths
    opacity=0.5,                 # Transparency (0.0 to 1.0)
    log_collision=True,          # Log collision geometries (default: False)
)

When log_collision=True, collision geometries are logged to a separate entity path ({prefix}/collision_geometries/) which can be toggled in the Rerun viewer.

To log collision geometries but hide them by default:

import rerun.blueprint as rrb

logger = rerun_loader_mjcf.MJCFLogger(model, log_collision=True)
rr.set_time("sim_time", duration=0.0)
logger.log_model()

blueprint = rrb.Spatial3DView(
    overrides={logger.paths.collision_root: rrb.EntityBehavior(visible=False)}
)
rr.send_blueprint(blueprint)

Dynamic Body Colors

You can change body colors during simulation (e.g., for highlighting):

# Set a body to red
logger.set_body_color(body_id=5, rgba=[1.0, 0.0, 0.0, 1.0])

# Reset to original color
logger.reset_body_color(body_id=5)

# Reset with custom opacity
logger.reset_body_color(body_id=5, opacity=0.5)

Recording Simulations

For efficient batch recording of simulations, use MJCFRecorder:

import mujoco
import rerun as rr
import rerun_loader_mjcf

model = mujoco.MjModel.from_xml_path("robot.xml")
data = mujoco.MjData(model)

rr.init("simulation", spawn=True)

logger = rerun_loader_mjcf.MJCFLogger(model)
rr.set_time("sim_time", duration=0.0)
logger.log_model()

# With simulation time (default: uses duration=data.time)
with rerun_loader_mjcf.MJCFRecorder(logger) as recorder:
    while data.time < 5.0:
        mujoco.mj_step(model, data)
        recorder.record(data)

# With explicit sequence index
with rerun_loader_mjcf.MJCFRecorder(logger, timeline_name="frame") as recorder:
    for i in range(1000):
        mujoco.mj_step(model, data)
        recorder.record(data, sequence=i)

# With explicit timestamp
with rerun_loader_mjcf.MJCFRecorder(logger, timeline_name="sim_time") as recorder:
    while data.time < 5.0:
        mujoco.mj_step(model, data)
        recorder.record(data, timestamp=data.time)

Lint

uv run pre-commit run -a

Credits

Inspired by rerun-loader-python-example-urdf.

What's Next

Metadata

Release files for rerun-loader-mjcf 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rerun-loader-mjcf 1.0.1
File Size Uploaded
rerun_loader_mjcf-1.0.1.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rerun-loader-mjcf 1.0.1
File Interpreter ABI Platform
rerun_loader_mjcf-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / rerun_loader_mjcf-1.0.1.tar.gz

Download URL rerun_loader_mjcf-1.0.1.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e41d05bcb4963e6f6fa06d1afab5c99901385f07eaf925f145262cf2112bbd30
BLAKE2b-256 checksum
How to use checksums
fa049ce0af976cdfea7eb06d9cab19075ba7fadca8fac93388339186af2c486b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / rerun_loader_mjcf-1.0.1-py3-none-any.whl

Download URL rerun_loader_mjcf-1.0.1-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8aaee454285a7fcc7e2184f9528eafcc6140cca3db49e597e53c95de3fd836e8
BLAKE2b-256 checksum
How to use checksums
f18cc36d7dab449ec6e0b0a686276abcbff35abe61d1459f8a9cec0ef9ad4fcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page