pub struct MjModel(/* private fields */);
Expand description
A Rust-safe wrapper around mjModel. Automatically clean after itself on destruction.
Implementations§
Source§impl MjModel
impl MjModel
Sourcepub fn from_xml<T: AsRef<Path>>(path: T) -> Result<Self, Error>
pub fn from_xml<T: AsRef<Path>>(path: T) -> Result<Self, Error>
Loads the model from an XML file. To load from a virtual file system, use MjModel::from_xml_vfs
.
Sourcepub fn from_xml_vfs<T: AsRef<Path>>(path: T, vfs: &MjVfs) -> Result<Self, Error>
pub fn from_xml_vfs<T: AsRef<Path>>(path: T, vfs: &MjVfs) -> Result<Self, Error>
Loads the model from an XML file, located in a virtual file system (vfs
).
Sourcepub fn from_xml_string(data: &str) -> Result<Self, Error>
pub fn from_xml_string(data: &str) -> Result<Self, Error>
Loads the model from an XML string.
Sourcepub fn from_buffer(data: &[u8]) -> Result<Self, Error>
pub fn from_buffer(data: &[u8]) -> Result<Self, Error>
Loads the model from MJB raw data.
Sourcepub fn save_last_xml(&self, filename: &str) -> Result<()>
pub fn save_last_xml(&self, filename: &str) -> Result<()>
Saves the last XML loaded.
Sourcepub fn make_data<'m>(&'m self) -> MjData<'m>
pub fn make_data<'m>(&'m self) -> MjData<'m>
Creates a new MjData
instances linked to this model.
Sourcepub fn actuator(&self, name: &str) -> Option<MjActuatorModelInfo>
pub fn actuator(&self, name: &str) -> Option<MjActuatorModelInfo>
Obtains a MjActuatorModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjActuatorModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn sensor(&self, name: &str) -> Option<MjSensorModelInfo>
pub fn sensor(&self, name: &str) -> Option<MjSensorModelInfo>
Obtains a MjSensorModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjSensorModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn tendon(&self, name: &str) -> Option<MjTendonModelInfo>
pub fn tendon(&self, name: &str) -> Option<MjTendonModelInfo>
Obtains a MjTendonModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjTendonModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn joint(&self, name: &str) -> Option<MjJointModelInfo>
pub fn joint(&self, name: &str) -> Option<MjJointModelInfo>
Obtains a MjJointModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjJointModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn geom(&self, name: &str) -> Option<MjGeomModelInfo>
pub fn geom(&self, name: &str) -> Option<MjGeomModelInfo>
Obtains a MjGeomModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjGeomModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn body(&self, name: &str) -> Option<MjBodyModelInfo>
pub fn body(&self, name: &str) -> Option<MjBodyModelInfo>
Obtains a MjBodyModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjBodyModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn camera(&self, name: &str) -> Option<MjCameraModelInfo>
pub fn camera(&self, name: &str) -> Option<MjCameraModelInfo>
Obtains a MjCameraModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjCameraModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn key(&self, name: &str) -> Option<MjKeyModelInfo>
pub fn key(&self, name: &str) -> Option<MjKeyModelInfo>
Obtains a MjKeyModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjKeyModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn tuple(&self, name: &str) -> Option<MjTupleModelInfo>
pub fn tuple(&self, name: &str) -> Option<MjTupleModelInfo>
Obtains a MjTupleModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjTupleModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn texture(&self, name: &str) -> Option<MjTextureModelInfo>
pub fn texture(&self, name: &str) -> Option<MjTextureModelInfo>
Obtains a MjTextureModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjTextureModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn site(&self, name: &str) -> Option<MjSiteModelInfo>
pub fn site(&self, name: &str) -> Option<MjSiteModelInfo>
Obtains a MjSiteModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjSiteModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn pair(&self, name: &str) -> Option<MjPairModelInfo>
pub fn pair(&self, name: &str) -> Option<MjPairModelInfo>
Obtains a MjPairModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjPairModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn numeric(&self, name: &str) -> Option<MjNumericModelInfo>
pub fn numeric(&self, name: &str) -> Option<MjNumericModelInfo>
Obtains a MjNumericModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjNumericModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn material(&self, name: &str) -> Option<MjMaterialModelInfo>
pub fn material(&self, name: &str) -> Option<MjMaterialModelInfo>
Obtains a MjMaterialModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjMaterialModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn light(&self, name: &str) -> Option<MjLightModelInfo>
pub fn light(&self, name: &str) -> Option<MjLightModelInfo>
Obtains a MjLightModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjLightModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn equality(&self, name: &str) -> Option<MjEqualityModelInfo>
pub fn equality(&self, name: &str) -> Option<MjEqualityModelInfo>
Obtains a MjEqualityModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjEqualityModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn hfield(&self, name: &str) -> Option<MjHfieldModelInfo>
pub fn hfield(&self, name: &str) -> Option<MjHfieldModelInfo>
Obtains a MjHfieldModelInfo
struct containing information about the name, id, and indices required for obtaining references to the correct locations in MjModel
. The actual view can be obtained via MjHfieldModelInfo::view
.
§Panics
A panic will occur if name
contains \0
characters.
Sourcepub fn name2id(&self, type_: MjtObj, name: &str) -> i32
👎Deprecated
pub fn name2id(&self, type_: MjtObj, name: &str) -> i32
Deprecated alias for MjModel::name_to_id
.
Sourcepub fn name_to_id(&self, type_: MjtObj, name: &str) -> i32
pub fn name_to_id(&self, type_: MjtObj, name: &str) -> i32
Translates name
to the correct id. Wrapper around mj_name2id
.
§Panics
When the name
contains ‘\0’ characters, a panic occurs.
Sourcepub fn save(&self, filename: Option<&str>, buffer: Option<&mut [u8]>)
pub fn save(&self, filename: Option<&str>, buffer: Option<&mut [u8]>)
Save model to binary MJB file or memory buffer; buffer has precedence when given.
§Panics
When the filename
contains ‘\0’ characters, a panic occurs.
Sourcepub fn print_formatted(
&self,
filename: &str,
float_format: &str,
) -> Result<(), NulError>
pub fn print_formatted( &self, filename: &str, float_format: &str, ) -> Result<(), NulError>
Print mjModel to text file, specifying format. float_format must be a valid printf-style format string for a single float value.
Sourcepub fn state_size(&self, spec: c_uint) -> c_int
pub fn state_size(&self, spec: c_uint) -> c_int
Return size of state specification. The bits of the integer spec correspond to element fields of MjtState
.
Sourcepub fn is_pyramidal(&self) -> bool
pub fn is_pyramidal(&self) -> bool
Determine type of friction cone.
Sourcepub fn is_dual(&self) -> bool
pub fn is_dual(&self) -> bool
Determine type of solver (PGS is dual, CG and Newton are primal).
Sourcepub fn id_to_name(&self, type_: MjtObj, id: c_int) -> Option<&str>
pub fn id_to_name(&self, type_: MjtObj, id: c_int) -> Option<&str>
Get name of object with the specified MjtObj
type and id, returns NULL if name not found.
Wraps mj_id2name
.
Sourcepub fn get_totalmass(&self) -> MjtNum
pub fn get_totalmass(&self) -> MjtNum
Sum all body masses.
Sourcepub fn set_totalmass(&mut self, newmass: MjtNum)
pub fn set_totalmass(&mut self, newmass: MjtNum)
Scale body masses and inertias to achieve specified total mass.
Source§impl MjModel
Public attribute methods.
impl MjModel
Public attribute methods.
Sourcepub fn stat(&self) -> &MjStatistic
pub fn stat(&self) -> &MjStatistic
An immmutable reference to model statistics.
Sourcepub fn stat_mut(&mut self) -> &mut MjStatistic
pub fn stat_mut(&mut self) -> &mut MjStatistic
A mutable reference to model statistics.