Giter Club home page Giter Club logo

mjcf's Introduction

MJCF for Rust

This is a rust interface to MJCF files. MJCF is the modeling language used by MuJoCo.
This uses the serde library to convert between the XML-based MJCF files and native rust data-structures.

For more information about the MJCF file format, see the official documentation:
https://mujoco.readthedocs.io/en/stable/XMLreference.html

Installation & Usage

  1. Install from crates.io:
    cargo add mjcf

  2. Read the documentation:
    cargo doc --package mjcf --open
    And the corresponding MJCF XML Reference.

  3. Use the function mjcf::from_str to parse an MJCF XML string into the native rust data structures.
    Use the function mjcf::to_string to serialize the rust data structures into an MJCF XML string.

Example

let mjcf_string = std::fs::read_to_string("my_mujoco_model.xml").unwrap();

// Deserialize the string into rust struct's.
let mut mujoco = mjcf::from_str(&mjcf_string).unwrap();

// Let's add another body to this model.
let worldbody = mujoco.worldbody.as_mut().unwrap();
let mut new_body = mjcf::Body::default();
new_body.name = "my_body".to_string();
worldbody.body.push(new_body);

// Serialize the modified data into a string.
let mjcf_string = mjcf::to_string(&mujoco).unwrap();

std::fs::write("modified_mujoco_model.xml", mjcf_string).unwrap();

mjcf-fmt

Tests

This library is tested using MJCF files which were scraped from the internet. In order to run the tests you need to clone this GIT repository and all of its submodules using the following command:
git clone --recurse-submodules

Test Asset Sources:

mjcf's People

Contributors

ctrl-z-9000-times avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.