Skip to main content

Utilities to programatically create MuJoCo XML configuration files

Project description

mjxml

Programmatic, type-checked helpers for composing MuJoCo XML. Define assets and worldbody elements in Python (with Pydantic validation), serialize to XML, and write files you can load in MuJoCo.

Highlights

  • Strong typing and validation via Pydantic v2.
  • Easy XML serialization: to_xml(), to_xml_str(), write().
  • Assets: TextureAsset, MeshAsset, HFieldAsset, ModelAsset.
  • Bodies: Geom (with many MuJoCo attributes), WorldBody base.
  • Utilities: Defaults blocks, rotation helpers, and runtime type protocols.

Requirements

  • Python >= 3.13
  • Runtime deps: numpy, pydantic

Install

From a checkout of this repository:

pip install -e .

For development (tests and linting):

pip install pytest ruff

If you run examples or tests without installing, set PYTHONPATH to include src.

export PYTHONPATH=src

Quickstart

Below are minimal examples showing how to construct elements and serialize them.

Texture asset

from asset.texture import TextureAsset

tex = TextureAsset(
		name="tex_grid",
		file="albedo.png",
		type="2d",
		colorspace="srgb",
		content_type="image/png",
		nchannel=3,
)

# ElementTree element
elem = tex.to_xml()

# Pretty string
print(tex.to_xml_str())

# Write to a file
tex.write("texture.xml")

Generated <texture> will include only attributes you set and perform validation (e.g., nchannel must be 1, 3, or 4; random in [0,1]).

Mesh asset

from asset.mesh import MeshAsset

mesh = MeshAsset(
		name="m_cube",
		file="cube.obj",
		content_type="model/obj",
		scale=[1.0, 1.0, 1.0],
		inertia="exact",
)

print(mesh.to_xml_str())

MeshAsset supports inline data (vertex/normal/texcoord/face), reference poses (refpos/refquat), and procedural builtin shapes.

Height field asset

from asset.hfield import HFieldAsset

hfield = HFieldAsset(
		name="terrain",
		file="height.png",
		content_type="image/png",
		nrow=256,
		ncol=256,
		size=[5.0, 5.0, 1.0, 0.0],  # required
)

print(hfield.to_xml_str())

size is required and encodes (radius_x, radius_y, elevation_z, base_z).

Geom

from body.geom import Geom

g = Geom(
		name="box1",
		type="box",
		size=[0.5, 0.5, 0.5],
		rgba=[0.8, 0.2, 0.2, 1.0],
		friction=[0.5, 0.1, 0.01],
)

print(g.to_xml_str())

If friction is provided, condim is emitted as its length, matching MuJoCo’s behavior.

Testing

Run the unit tests with pytest.

pytest -q -s

Status

This repository is under active development; expect minor API adjustments. A high-level MujocoModel aggregator is planned but not yet included.

Roadmap

  • [✅] High-level Wrapper: MujocoModel class to aggregate assets, worldbody, and other sections.
  • [✅] Body Elements: Support for joint, site, camera.
  • [=] Sections: Support for actuator, sensor, equality, contact, tendon.
  • [❌] IO: Parsing existing XML files for round-trip editing.
  • [❌] Docs: Comprehensive API documentation and more examples.

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

mjxml-0.1.1.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mjxml-0.1.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file mjxml-0.1.1.tar.gz.

File metadata

  • Download URL: mjxml-0.1.1.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mjxml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ab0ea75880cd790e3a8b20d20424d56cd2209da78ba9f06a3ee8b66442f70b53
MD5 2e5182e56dd905d7ae6c22fa76bfb72f
BLAKE2b-256 314f047a3b2d4c896da7318fd681a1657433d5af1e8147320800f53b9b1f0fa7

See more details on using hashes here.

File details

Details for the file mjxml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mjxml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mjxml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c882c20bf8996c0009ad2b5df0b71d13be7bf7813220692ba6c87e281798f4a
MD5 3a8d2acde203525cf2ce014405dc5b48
BLAKE2b-256 2619bbe2d1684cb69e420bdc56bd228e20b6af9ba1b032d1f945013c3381f8b2

See more details on using hashes here.

Supported by

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