ffi_attributes/
ffi_attributes.rs1use std::time::Duration;
9
10use mujoco_rs::viewer::MjViewer;
11use mujoco_rs::prelude::*;
12
13
14const EXAMPLE_MODEL: &str = "
15<mujoco>
16 <worldbody>
17 <light ambient=\"0.2 0.2 0.2\"/>
18 <body name=\"ball\">
19 <geom name=\"green_sphere\" pos=\".2 .2 .2\" size=\".1\" rgba=\"0 1 0 1\" mass=\"0.1\" solref=\"0.004 1\"/>
20 <joint type=\"free\"/>
21 </body>
22
23 <geom name=\"floor\" type=\"plane\" size=\"10 10 1\" euler=\"5 0 0\" solref=\"0.004 1\"/>
24
25 </worldbody>
26</mujoco>
27";
28
29fn main() {
30 let model = MjModel::from_xml_string(EXAMPLE_MODEL).expect("could not load the model");
31
32 let timestep = model.ffi().opt.timestep;
35 let mut data = model.make_data(); let mut viewer = MjViewer::launch_passive(&model, 100)
39 .expect("could not launch the viewer");
40
41 while viewer.running() {
42 viewer.sync(&mut data);
43 data.step();
44 std::thread::sleep(Duration::from_secs_f64(timestep));
45 }
46}