- Offers safe, low-level Rust wrappers for the entire MuJoCo API.
- Provides getters for all struct fields and setters for user-modifiable fields, instead of allowing direct field access.
- Implements automatic resource management via Rust's RAII pattern.
For example,
mjModelautomatically callsmj_deleteModelin itsDropimplementation, preventing memory leaks. - Emphasizes type-safety and efficiency within a lean binding interface.
For instance, the
ObjectId<T>type system replaces raw integer IDs to:- Ensure compile-time safety for all object-related operations.
- Improve performance by eliminating the need for repeated
mj_name2idlookups.
Requirements
- MuJoCo 3.3.2 downloaded and installed
- Additionally, if you place mujoco library in a non-standard directory of the platform,
you need
MUJOCO_LIBenvironment variable set to the path of the directory containinglibmujoco.soormujoco.lib(e.g.$HOME/.mujoco/mujoco-3.3.2/libwhen you placed the official release above in~/.mujoco)
Note / Tips
-
For example on x86_64 Linux, run:
to download & expand MuJoCo 3.3.2.
On other platforms, do the same with the appropriate archive file for your system. -
One way to setup is to install MuJoCo to a default standard path like
/usr/local/lib/(or a folder in PATH on Windows), then if needed create symlink tomujoco-3.3.2/lib/libmujoco.sothere, and insert to your shell config file:# example on Linux with /usr/local/lib/Or if you'd like to avoid to install MuJoCo to such a system directory:
# example on Linux with $HOME/.mujoco/ -
Or, you can get MuJoCo library through Python toolchain like
uvorpip. -
Depending on your setting, be sure to specify
$MUJOCO_LIBas shared library path when executing your app (for exampleLD_LIBRARY_PATH=$MUJOCO_LIB cargo runon Linux)
Example
[]
= "0.2"
= "0.60"
use ;
use ;
let xml_path: String = todo!;
let camera_name: = todo!;
let model = mj_loadXML.expect;
let mut data = mj_makeData;
let mut glfw = init.expect;
let = glfw
.create_window
.expect;
window.set_size_polling;
window.set_close_polling;
make_current;
let con = new;
let opt = default;
let mut scn = new;
let mut cam = default;
camera_name.map;
while !window.should_close
See examples/visualize_left_object.rs for full example and examples/README.md for the description.
Previous Works
- TheButlah/mujoco-rs : archived by the owner on Sep 19, 2021.
- MuJoCo-Rust/MuJoCo-Rust : seems not maintained anymore (last commit on 2 years ago) and not compatible with MuJoCo 3+.
License
rusty_mujoco is licensed under Apache Lisense, Version 2.0).