MjViewer

Struct MjViewer 

Source
pub struct MjViewer<'m> { /* private fields */ }
Expand description

A Rust-native implementation of the MuJoCo viewer. To confirm to rust safety rules, the viewer doesn’t store a mutable reference to the MjData struct, but it instead accepts it as a parameter at its methods.

Currently supported (to be expanded in the future):

  • Visualization of the 3D scene,
  • Close via Ctrl + Q or by closing the window,
  • Body tracking via Ctrl + double left-click,
  • Escape from tracked camera via Esc.

Only passive mode is available, which means the user must call MjViewer::sync to update the state inside the viewer.

Implementations§

Source§

impl<'m> MjViewer<'m>

Source

pub fn launch_passive( model: &'m MjModel, scene_max_ngeom: usize, ) -> Result<Self, MjViewerError>

Launches the MuJoCo viewer. A Result struct is returned that either contains MjViewer or a MjViewerError.

Examples found in repository?
examples/rust_viewer.rs (line 28)
25fn main() {
26    let model = MjModel::from_xml_string(EXAMPLE_MODEL).expect("could not load the model");
27    let mut data = model.make_data();  // or MjData::new(&model);
28    let mut viewer = MjViewer::launch_passive(&model, 100)
29        .expect("could not launch the viewer");
30    while viewer.running() {
31        viewer.sync(&mut data);
32        data.step();
33        std::thread::sleep(Duration::from_millis(2));
34    }
35}
Source

pub fn running(&self) -> bool

Checks whether the window is still open.

Examples found in repository?
examples/rust_viewer.rs (line 30)
25fn main() {
26    let model = MjModel::from_xml_string(EXAMPLE_MODEL).expect("could not load the model");
27    let mut data = model.make_data();  // or MjData::new(&model);
28    let mut viewer = MjViewer::launch_passive(&model, 100)
29        .expect("could not launch the viewer");
30    while viewer.running() {
31        viewer.sync(&mut data);
32        data.step();
33        std::thread::sleep(Duration::from_millis(2));
34    }
35}
Source

pub fn sync(&mut self, data: &mut MjData<'_>)

Examples found in repository?
examples/rust_viewer.rs (line 31)
25fn main() {
26    let model = MjModel::from_xml_string(EXAMPLE_MODEL).expect("could not load the model");
27    let mut data = model.make_data();  // or MjData::new(&model);
28    let mut viewer = MjViewer::launch_passive(&model, 100)
29        .expect("could not launch the viewer");
30    while viewer.running() {
31        viewer.sync(&mut data);
32        data.step();
33        std::thread::sleep(Duration::from_millis(2));
34    }
35}

Trait Implementations§

Source§

impl<'m> Debug for MjViewer<'m>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'m> Freeze for MjViewer<'m>

§

impl<'m> RefUnwindSafe for MjViewer<'m>

§

impl<'m> !Send for MjViewer<'m>

§

impl<'m> !Sync for MjViewer<'m>

§

impl<'m> Unpin for MjViewer<'m>

§

impl<'m> UnwindSafe for MjViewer<'m>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.