| Crates.io | rusty_mujoco |
| lib.rs | rusty_mujoco |
| version | 0.1.1 |
| created_at | 2025-07-28 04:06:59.194592+00 |
| updated_at | 2025-09-15 23:11:57.943744+00 |
| description | Rust bindings for the MuJoCo physics simulator |
| homepage | https://crates.io/crates/rusty_mujoco |
| repository | https://github.com/rust-control/rusty_mujoco |
| max_upload_size | |
| id | 1770649 |
| size | 621,001 |
mjModel automatically calls mj_deleteModel in its Drop implementation, preventing memory leaks.ObjectId<T> type system replaces raw integer IDs to:
mj_name2id lookups.MUJOCO_DIR environment variable set to the path of the MuJoCo directory (e.g. $HOME/.mujoco/mujoco-3.3.2)For example on x86_64 Linux, run:
wget https://github.com/google-deepmind/mujoco/releases/download/3.3.2/mujoco-3.3.2-linux-x86_64.tar.gz
tar -xzf mujoco-3.3.2-linux-x86_64.tar.gz
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 to mujoco-3.3.2/lib/libmujoco.so there,
and insert to your shell config file:
# example on Linux with /usr/local/lib/
export MUJOCO_DIR="/usr/local/lib/mujoco-3.3.2"
Or if you'd like to avoid to install MuJoCo to such a system directory:
# example on Linux with $HOME/.mujoco/
export MUJOCO_DIR="$HOME/.mujoco/mujoco-3.3.2"
export LD_LIBRARY_PATH="$MUJOCO_DIR/lib:$LD_LIBRARY_PATH"
Depending on your setting, be sure to specify $MUJOCO_DIR/lib as shared library path
when executing your app (for example LD_LIBRARY_PATH=$MUJOCO_DIR/lib cargo run on Linux)
[dependencies]
rusty_mujoco = "0.1"
glfw = "0.60"
use rusty_mujoco::{mj_loadXML, mj_makeData, mj_name2id, mj_step, mjr_render, mjv_updateScene};
use rusty_mujoco::{mjrContext, mjrRect, mjvScene, mjvCamera, mjvOption, mjtCatBit, mjtFontScale};
let xml_path: String = todo!();
let camera_name: Option<String> = todo!();
let model = mj_loadXML(xml_path).expect("Failed to load XML file");
let mut data = mj_makeData(&model);
let mut glfw = glfw::init(glfw::fail_on_errors).expect("Failed to initialize GLFW");
let (mut window, _) = glfw
.create_window(1200, 900, "Acrobot Simulation", glfw::WindowMode::Windowed)
.expect("Failed to create GLFW window");
window.set_size_polling(true);
window.set_close_polling(true);
glfw::Context::make_current(&mut *window);
let con = mjrContext::new(&model, mjtFontScale::X150);
let opt = mjvOption::default();
let mut scn = mjvScene::new(&model, 2000);
let mut cam = mjvCamera::default();
camera_name.map(|name| cam.set_fixedcamid(mj_name2id(&model, &name).expect("No camera of such name in the model")));
while !window.should_close() {
while data.time() < glfw.get_time() {
mj_step(&model, &mut data);
}
let viewport = {
let (width, height) = window.get_framebuffer_size();
mjrRect::new(0, 0, width as u32, height as u32)
};
mjv_updateScene(
&model,
&mut data,
&opt,
None, /* No perturbation */
&mut cam,
mjtCatBit::ALL,
&mut scn,
);
mjr_render(viewport, &mut scn, &con);
glfw::Context::swap_buffers(&mut *window);
glfw.poll_events();
}
See examples/visualize_left_object.rs for full example and examples/README.md for the description.
rusty_mujoco is licensed under MIT LICENSE.