Metadata-Version: 2.3
Name: rerun-loader-mjcf
Version: 0.5.0
Summary: A Rerun data loader for MJCF (MuJoCo XML) files
Author: Jafar Uruc
Author-email: Jafar Uruc <jafar@reimaginerobotics.ai>
License: MIT License
         
         Copyright (c) 2025 Reimagine Robotics
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: mujoco>=3.3.0
Requires-Dist: numpy>=2
Requires-Dist: rerun-sdk>=0.27.2
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/reimagine-Robotics/rerun-loader-mjcf
Project-URL: Issues, https://github.com/reimagine-Robotics/rerun-loader-mjcf/issues
Project-URL: Repository, https://github.com/reimagine-Robotics/rerun-loader-mjcf
Description-Content-Type: text/markdown

# rerun-loader-mjcf
[![CI](https://github.com/Reimagine-Robotics/rerun-loader-mjcf/actions/workflows/ci.yml/badge.svg)](https://github.com/Reimagine-Robotics/rerun-loader-mjcf/actions/workflows/ci.yml)

A [Rerun](https://rerun.io/) 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](https://github.com/google-deepmind/mujoco_menagerie):*
```bash
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](https://github.com/google-deepmind/mujoco_menagerie)*

## Installation

```bash
pip install rerun-loader-mjcf
```

## Usage

### CLI

```bash
rerun-loader-mjcf robot.xml
```

To run a real-time simulation loop:

```bash
rerun-loader-mjcf robot.xml --simulate
```

Or run directly without installing:

```bash
uvx rerun-loader-mjcf robot.xml
```

### Python API

```python
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)
```

### Recording Simulations

For efficient batch recording of simulations, use `MJCFRecorder`:

```python
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)
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

```bash
uv run pre-commit run -a
```

## Credits

Inspired by [rerun-loader-python-example-urdf](https://github.com/rerun-io/rerun-loader-python-example-urdf).

## What's Next

- Integrate [mujoco-rs](https://github.com/jafarAbdi/mujoco-rs) to implement a native Rust loader similar to [loader_urdf.rs](https://github.com/rerun-io/rerun/blob/main/crates/store/re_data_loader/src/loader_urdf.rs)
