{"id":15903169,"url":"https://github.com/stillonearth/bevy_mujoco","last_synced_at":"2025-05-05T22:32:58.346Z","repository":{"id":63667422,"uuid":"560842318","full_name":"stillonearth/bevy_mujoco","owner":"stillonearth","description":"Render MuJoCo scenes in bevy","archived":false,"fork":false,"pushed_at":"2025-04-27T15:14:07.000Z","size":288,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-03T11:06:10.627Z","etag":null,"topics":["bevy","mujoco"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stillonearth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-02T11:47:49.000Z","updated_at":"2025-04-27T15:14:10.000Z","dependencies_parsed_at":"2024-08-26T10:51:15.722Z","dependency_job_id":"fe2ccb3a-a20b-4609-a6eb-7d3ae5a88252","html_url":"https://github.com/stillonearth/bevy_mujoco","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stillonearth%2Fbevy_mujoco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stillonearth%2Fbevy_mujoco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stillonearth%2Fbevy_mujoco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stillonearth%2Fbevy_mujoco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stillonearth","download_url":"https://codeload.github.com/stillonearth/bevy_mujoco/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252586378,"owners_count":21772286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy","mujoco"],"created_at":"2024-10-06T12:01:14.417Z","updated_at":"2025-05-05T22:32:58.021Z","avatar_url":"https://github.com/stillonearth.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Bevy MuJoCo\r\n\r\n[![Crates.io](https://img.shields.io/crates/v/bevy_mujoco.svg)](https://crates.io/crates/bevy_mujoco)\r\n[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/bevyengine/bevy#license)\r\n[![Crates.io](https://img.shields.io/crates/d/bevy_mujoco.svg)](https://crates.io/crates/bevy_mujoco)\r\n[![Rust](https://github.com/stillonearth/bevy_mujoco/workflows/CI/badge.svg)](https://github.com/stillonearth/bevy_mujoco/actions)\r\n\r\nhttps://user-images.githubusercontent.com/97428129/210613348-82a5e59d-96af-42a9-a94a-c47093eb8297.mp4\r\n\r\nImport MJCF files into Bevy and run simulations with MuJoCo.\r\n\r\n## Implementation Notes\r\n\r\nMuJoCo has 2 modes with different coordinate systems for bodies\r\n\r\n1. `paused` mode where all translations and rotations are extracted from `mj_Model` in `MuJoCo-Rust` as `body.pos`, `body.quat` in parent's body coordinate system. To make them work nice with bevy the body structure from mujoco has to be transformed to a tree structure with `body_tree()` call. Then `body_tree` is spawned into the bevy world recursively — a nice contraption to do it in `setup_mujoco`.\r\n\r\n2. `simulation` mode where translations are extracted from `sim.xpos()` and `sim.xquat()` — and this time they are in global frame. Since bodies are spawned hierarchically translations and rotations need to be converted to a parent coordinate system — it happens in `simulate_physics`.\r\n\r\n## Getting Started\r\n\r\n### MuJoCo Dependency\r\n- `MuJoCo` 2.3.5 installed in `~/.local/mujoco` for Linux or `C:/Program Files/Mujoco` for Windows\r\n- _nightly_ Rust. Compile with `cargo +nightly build`\r\n\r\n### Usage\r\n\r\n```rust\r\n// 1. Import bevy_mujoco\r\nuse bevy_mujoco::*;\r\n// 2. Setup bevy_mujoco Plugin. MuJoCo Plugin would spawn entities to the world\r\nfn main() {\r\n    App::new()\r\n        .add_plugins(DefaultPlugins)\r\n        .insert_resource(MuJoCoPluginSettings {\r\n            model_xml_path: \"assets/unitree_a1/scene.xml\".to_string(),\r\n            pause_simulation: false,\r\n            target_fps: 600.0, // this is not actual fps (bug in bevy_mujoco),\r\n                               // the bigger the value, the slower the simulation\r\n        })\r\n        .add_plugins(MuJoCoPlugin)\r\n        .add_systems(Startup, setup)\r\n        .add_systems(Update, robot_control_loop)\r\n        .run();\r\n}\r\n// 3. You can control your robots here\r\nfn robot_control_loop(mut mujoco_resources: ResMut\u003cMuJoCoResources\u003e) {\r\n    // prepare simulation data for the NN\r\n    let qpos = mujoco_resources.state.qpos.clone();\r\n    let qvel = mujoco_resources.state.qvel.clone();\r\n    let cfrc_ext = mujoco_resources.state.cfrc_ext.clone();\r\n\r\n    // Compute input -\u003e control values here and fill control\r\n    // ...\r\n    let mut control: Vec\u003cf32\u003e = Vec::new();\r\n\r\n    mujoco_resources.control.data = input_vec;\r\n}\r\n```\r\n\r\n**copy build.rs to root of your project to use in with Windows environments. it will copy mujoco.dll to a build dir of your application**\r\n\r\nTo run tests and example initialize [`mujoco_menagerie`](https://github.com/deepmind/mujoco_menagerie) submobule with\r\n\r\n```bash\r\ncd bevy_mujoco\r\ngit submodule init\r\ngit submodule update\r\n```\r\n\r\nSee [example](https://github.com/stillonearth/bevy_quadruped_neural_control) for simulating Unitree A1 robot.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillonearth%2Fbevy_mujoco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstillonearth%2Fbevy_mujoco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstillonearth%2Fbevy_mujoco/lists"}