Skip to main content

mjcf_rs/
lib.rs

1//! ## MJCF parser
2//!
3//! Pure-Rust parser for the [MuJoCo XML (MJCF) format](https://mujoco.readthedocs.io/en/stable/XMLreference.html).
4//!
5//! ### Disclaimer
6//!
7//! Most of this crate — source, tests, and documentation — was produced by
8//! an AI coding assistant working iteratively from MJCF reference scenes
9//! (primarily the [MuJoCo Menagerie](https://github.com/google-deepmind/mujoco_menagerie)),
10//! under human direction and review.
11//!
12//! ### Quick start
13//!
14//! ```no_run
15//! use mjcf_rs::Model;
16//! let model = Model::from_file("robot.xml").unwrap();
17//! println!("{} bodies", model.bodies_iter().count());
18//! ```
19//!
20//! ### What this crate does
21//!
22//! - Reads MJCF XML and produces a typed AST.
23//! - Resolves `<include file="…"/>` recursively (with cycle detection).
24//! - Resolves `<default>` class inheritance — every concrete element has its
25//!   final attributes baked in.
26//! - Normalizes angle units to radians (`<compiler angle="degree">` is the
27//!   MJCF default).
28//! - Records `<compiler eulerseq>` so the conversion side can apply Euler
29//!   triples in the correct order.
30//!
31//! ### What this crate does **not** do
32//!
33//! - Simulate anything. Pair this with `rapier3d-mjcf` for that.
34//! - Cover MJCF features that are out of scope for `rapier3d-mjcf`. See the
35//!   `rapier3d-mjcf` README for the complete list.
36
37#![warn(missing_docs)]
38
39pub mod assets;
40pub mod body;
41pub mod compiler;
42pub mod contact;
43pub mod equality;
44mod error;
45pub mod extras;
46mod loader;
47pub mod model;
48pub mod normals;
49pub mod tendon;
50pub mod types;
51
52#[cfg(feature = "msh")]
53pub mod msh;
54
55pub use error::*;
56pub use model::*;
57pub use types::*;
58
59/// A pose: a 3D rigid-body transform (rotation + translation), backed by
60/// [`glamx::DPose3`]. MJCF's several rotation specifications (`quat`,
61/// `axisangle`, `euler`, `xyaxes`, `zaxis`) are all collapsed into the
62/// quaternion stored here by the loader.
63pub use glamx::DPose3 as Pose;
64/// Re-export of [`glam`], the math library backing [`Pose`], so
65/// downstream crates can name [`glam::DQuat`]/[`glam::DVec3`] without taking a
66/// direct dependency on glam.
67pub use glamx::glam;