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§
- Mjcf
Actuator Binding <actuator>ready to drive a rapier joint motor.- Mjcf
Actuator Handle - Per-actuator handle resolved against the inserted joint set. Returned
alongside
MjcfRobotHandles::jointsso callers can drive each actuator without having to walk the actuator → joint-index → handle indirection themselves. - Mjcf
Body - One body from the MJCF model materialized as a rapier rigid-body and its colliders.
- Mjcf
Body Handle - A handle to one inserted rigid-body.
- Mjcf
Collider Handle - A handle to one inserted collider.
- Mjcf
Contact Hooks - Hook implementation honouring MJCF’s
<contact><exclude>(suppress contact between two collider sets) and<contact><pair>(override friction / margin on a specific pair). - Mjcf
Equality Joint - One
<equality>constraint materialized as an extra rapier joint. - Mjcf
Joint - One joint from the MJCF model materialized as a rapier
GenericJoint. - Mjcf
Joint Handle - A handle to one inserted joint (typed by the joint set used).
- Mjcf
Loader Options - Configuration for
MjcfRobot::from_model. - Mjcf
Multibody Options - Options applied to multibody joints created from the MJCF joints.
- Mjcf
Qpos Dof - One MJCF joint’s slot in a keyframe’s
qpos/qvelarrays, resolved to where it must be written in the rapier model. - Mjcf
Render Material - PBR shading parameters resolved from an MJCF
<material>, expressed in the metallic-roughness model a modern renderer consumes. MuJoCo’s legacy Phongspecular/shininessare folded in here too:reflectancecarries the specular intensity, androughnessfalls back to1 − shininesswhen the material doesn’t setroughnessexplicitly. - Mjcf
Robot - A robot loaded from an MJCF file: a flat list of bodies, joints, and extras.
- Mjcf
Robot Handles - All handles produced by inserting a
MjcfRobotinto rapier. - Mjcf
Sensor Binding <sensor>definition resolved against the rapier handles. The simulation itself is up to the user — callMjcfRobot::read_sensorto query.- Mjcf
Visual Mesh - A render-only mesh declared by an MJCF
<geom>(typically a<geom type="mesh">withcontype = 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. - Pair
Override - Friction / margin override for a specific collider pair, sourced from a
<contact><pair>element.
Enums§
- Contact
Filter Mode - How the loader maps MJCF
contype/conaffinityto rapierInteractionGroups. - Mjcf
DofKind - The MJCF joint kind backing one keyframe
qpos/qvelslot. Decides how manyqpos/qvelscalars the slot consumes and how they are written to the rapier model. - Mjcf
Sensor Value - One scalar / vector / quaternion reading from a sensor.
- Sensor
Object Ref - Resolved subject of a sensor.