Expand description
§MuJoCo-rs
A wrapper around the MuJoCo C library with a Rust-native viewer. If you’re familiar with MuJoCo, this should be pretty straightforward to use as the wrappers mainly encapsulate some C structs or just rename them to match Rust’s PascalCase style.
The main structs are wrappers::mj_model::MjModel and wrappers::mj_data::MjData.
These two structs (and some others) wrap the C structure in order to achieve memory safety.
Their fields aren’t publicly exposed and can instead be manipulated through views
(e.g., MjData::joint and then wrappers::mj_data::MjJointDataInfo::view).
To access the wrapped attributes directly, call the corresponding ffi() methods
(e.g., MjData::ffi).
§MuJoCo version
MuJoCo-rs relies on MuJoCo 3.8.0.
§Documentation
A more guided documentation can be obtained here.
§Missing library errors
Guided documentation also contains information on how to configure MuJoCo. MuJoCo-rs cannot fully configure it itself due to MuJoCo being a shared C library. As a result, you may encounter load-time errors about missing libraries.
Information on how to configure MuJoCo and resolve these issues is available here.
§3D viewer
The Rust-native viewer is available (viewer::MjViewer) when the viewer / viewer-ui feature is enabled,
as well as MuJoCo’s C++ one (crate::cpp_viewer::MjViewerCpp).
The C++ viewer, however, requires manual compilation of a patched MuJoCo repository,
like described here.
§Model editing
MjModel can be procedurally generated through the model editing module.
The specification representing the model is wrappers::mj_editing::MjSpec.
§Functions
Most functions are wrapped under methods at different structs. Some functions
are available under the wrappers::fun module.
If a certain function can’t be found, you can use the raw FFI bindings, available under
the mujoco_c module. Note that to access the lower-level ffi structs inside wrappers,
ffi() or ffi_mut() must be called (e.g., MjData::ffi and MjModel::ffi).
§Cargo features
This crate has the following public features:
-
viewer: enables the Rust-native MuJoCo viewer.viewer-ui: enables the (additional) user UI within the viewer. This also allows users to add customeguiwidgets to the viewer.
-
cpp-viewer: enables the Rust wrapper around the C++ MuJoCo viewer. This requires static linking to a modified fork of MuJoCo, as described in installation. -
renderer: enables offscreen rendering for writing RGB and depth data to memory or file.renderer-winit-fallback: enables the invisible window fallback (based on winit) when offscreen rendering fails to initialize. Note that true offscreen rendering is only available on Linux platforms when the video driver supports it. On Windows and macOS, this feature must always be enabled when therendererfeature is enabled.
-
auto-download-mujoco: MuJoCo dependency will be automatically downloaded to the specified path.- This is only available on Linux and Windows.
- The environment variable
MUJOCO_DOWNLOAD_DIRmust be set to the absolute path of the download location. - Downloaded MuJoCo library is still a shared library. See installation for information on complete configuration.
By default, no optional features are enabled. Enable the features you need explicitly
(e.g. cargo add mujoco-rs --features "viewer-ui renderer-winit-fallback" for support
with the viewer and the viewer’s extra UI, and the render with invisible window as a fallback).
Modules§
- cpp_
viewer - Wrapper around MuJoCo’s original C++ viewer (also named Simulate).
- error
- Error types for MuJoCo-rs operations.
- mujoco_
c - Raw MuJoCo C and C++ FFI bindings (auto-generated).
- prelude
- Commonly used items.
- renderer
- Module related to implementation of the
MjRenderer. - util
- Utility types and macros used throughout the crate.
- viewer
- Module related to implementation of the
MjViewer. For implementation of the C++ wrapper, seecrate::cpp_viewer::MjViewerCpp(enabled by thecpp-viewercargo feature). - vis_
common - Common visualization utilities shared by the viewer and off-screen renderer.
- wrappers
- A set of wrappers around the MuJoCo types and functions.
Functions§
- get_
mujoco_ version Deprecated - Returns the version string of the MuJoCo library.
- mujoco_
version - Returns the version string of the MuJoCo library.