Skip to main content

A browser-based 3D viewer for MuJoCo

Project description

mjc_viewer

PyPI Python Version PyPI version Open In Colab

mjc_viewer is a browser-based 3D viewer for MuJoCo that can render static trajectories from JSON.

Installation

The recommended way to install this package is via PyPI:

pip install mjc_viewer

Usage

import numpy as np
import mujoco
from mjc_viewer import Serializer, Trajectory

# Load your MuJoCo model.
model = mujoco.MjModel.from_xml_path("humanoid.xml")
data = mujoco.MjData(model)

# Create a Serializer and Trajectory instance.
serializer = Serializer(model)
trajectory = Trajectory(data)

# Simulate for 3 seconds.
trajectory.reset()
while data.time < 3.0:
    data.ctrl = np.random.uniform(*model.actuator_ctrlrange.T)
    mujoco.mj_step(model, data)
    trajectory.step()

html = serializer.render(trajectory)
with open("traj.html", "w") as f:
    f.write(html)
# You can now open traj.html in a browser or render in a notebook with
# `IPython.display.HTML`.

Todos

  • Robustify XML parser
  • Parse lights
  • Add support for meshes and height fields
  • Better default camera / light settings
  • Figure out plane reflection
  • Someday, make it interactive

Acknowledgements

mjc_viewer is heavily adapted from Brax's javascript viewer, full credit goes to its developers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mjc_viewer-0.0.5.tar.gz (19.1 kB view hashes)

Uploaded Source

Built Distribution

mjc_viewer-0.0.5-py3-none-any.whl (21.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page