Skip to main content

Crate rapier3d_mjcf

Crate rapier3d_mjcf 

Source
Expand description

§MJCF loader for the Rapier physics engine

Rapier is a set of 2D and 3D physics engines for games, animation, and robotics. The rapier3d-mjcf crate lets you convert a MuJoCo MJCF XML file into a set of rigid-bodies, colliders, and joints, for use with the rapier3d physics engine.

§Disclaimer

Most of this crate — source, tests, and documentation — was produced by an AI coding assistant working iteratively from MJCF reference scenes (primarily the MuJoCo Menagerie), under human direction and review.

use rapier3d::prelude::*;
use rapier3d_mjcf::{MjcfLoaderOptions, MjcfRobot};

let mut bodies = RigidBodySet::new();
let mut colliders = ColliderSet::new();
let mut impulse_joints = ImpulseJointSet::new();

let (robot, _model) =
    MjcfRobot::from_file("robot.xml", MjcfLoaderOptions::default()).unwrap();
robot.insert_using_impulse_joints(&mut bodies, &mut colliders, &mut impulse_joints);

See the crate-level README for a feature matrix.

Re-exports§

pub use mjcf_rs;

Structs§

MjcfActuatorBinding
<actuator> ready to drive a rapier joint motor.
MjcfActuatorHandle
Per-actuator handle resolved against the inserted joint set. Returned alongside MjcfRobotHandles::joints so callers can drive each actuator without having to walk the actuator → joint-index → handle indirection themselves.
MjcfBody
One body from the MJCF model materialized as a rapier rigid-body and its colliders.
MjcfBodyHandle
A handle to one inserted rigid-body.
MjcfColliderHandle
A handle to one inserted collider.
MjcfContactHooks
Hook implementation honouring MJCF’s <contact><exclude> (suppress contact between two collider sets) and <contact><pair> (override friction / margin on a specific pair).
MjcfEqualityJoint
One <equality> constraint materialized as an extra rapier joint.
MjcfJoint
One joint from the MJCF model materialized as a rapier GenericJoint.
MjcfJointHandle
A handle to one inserted joint (typed by the joint set used).
MjcfLoaderOptions
Configuration for MjcfRobot::from_model.
MjcfMultibodyOptions
Options applied to multibody joints created from the MJCF joints.
MjcfQposDof
One MJCF joint’s slot in a keyframe’s qpos / qvel arrays, resolved to where it must be written in the rapier model.
MjcfRenderMaterial
PBR shading parameters resolved from an MJCF <material>, expressed in the metallic-roughness model a modern renderer consumes. MuJoCo’s legacy Phong specular/shininess are folded in here too: reflectance carries the specular intensity, and roughness falls back to 1 − shininess when the material doesn’t set roughness explicitly.
MjcfRobot
A robot loaded from an MJCF file: a flat list of bodies, joints, and extras.
MjcfRobotHandles
All handles produced by inserting a MjcfRobot into rapier.
MjcfSensorBinding
<sensor> definition resolved against the rapier handles. The simulation itself is up to the user — call MjcfRobot::read_sensor to query.
MjcfVisualMesh
A render-only mesh declared by an MJCF <geom> (typically a <geom type="mesh"> with contype = conaffinity = 0). The loader surfaces these so the caller can render them attached to the parent body without inserting them into the physics collider set.
PairOverride
Friction / margin override for a specific collider pair, sourced from a <contact><pair> element.

Enums§

ContactFilterMode
How the loader maps MJCF contype / conaffinity to rapier InteractionGroups.
MjcfDofKind
The MJCF joint kind backing one keyframe qpos/qvel slot. Decides how many qpos / qvel scalars the slot consumes and how they are written to the rapier model.
MjcfSensorValue
One scalar / vector / quaternion reading from a sensor.
SensorObjectRef
Resolved subject of a sensor.