From 65600937fa8de29c9a1296490dcb657f503dd30e Mon Sep 17 00:00:00 2001 From: kanarus Date: Mon, 28 Jul 2025 23:23:25 +0900 Subject: [PATCH 1/2] docs: improve default functions notes --- examples/visualize_left_object.rs | 8 +++----- src/functions/opengl_rendering.rs | 6 +++++- src/functions/visualization.rs | 6 ++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/visualize_left_object.rs b/examples/visualize_left_object.rs index 9a242e1..1bab5f2 100644 --- a/examples/visualize_left_object.rs +++ b/examples/visualize_left_object.rs @@ -1,5 +1,5 @@ use rusty_mujoco::{mj_loadXML, mj_makeData, mj_step}; -use rusty_mujoco::{mjr_makeContext, mjr_render, mjrContext, mjrRect, mjtCatBit, mjtFontScale, mjv_makeScene, mjv_updateScene, mjvCamera, mjvOption, mjvScene}; +use rusty_mujoco::{mjr_makeContext, mjr_render, mjrContext, mjrRect, mjtCatBit, mjtFontScale, mjv_updateScene, mjvCamera, mjvOption, mjvScene}; struct Args { xml_path: String, @@ -49,11 +49,9 @@ fn main() { glfw::Context::make_current(&mut *window); let opt = mjvOption::default(); - let mut scn = mjvScene::default(); - let mut con = mjrContext::default(); + let con = mjrContext::new(&model, mjtFontScale::X150); + let mut scn = mjvScene::new(&model, 2000); let mut cam = mjvCamera::default(); - mjv_makeScene(&model, &mut scn, 2000); - mjr_makeContext(&model, &mut con, mjtFontScale::X150); camera_name.map(|name| cam.set_fixedcamid(model.object_id(&name).expect("No camera of such name in the model"))); while !window.should_close() { diff --git a/src/functions/opengl_rendering.rs b/src/functions/opengl_rendering.rs index c74d53f..da03885 100644 --- a/src/functions/opengl_rendering.rs +++ b/src/functions/opengl_rendering.rs @@ -27,6 +27,10 @@ pub fn mjr_defaultContext() -> mjrContext { unsafe { c.assume_init() } } impl Default for mjrContext { + /// Internally calls [`mjr_defaultContext`]. + /// + /// **note**: Be sure to call [`mjr_makeContext`] for the returned `mjrContext` to allocate resources + /// before using it in rendering. fn default() -> Self { mjr_defaultContext() } @@ -42,7 +46,7 @@ pub fn mjr_makeContext(m: &mjModel, con: &mut mjrContext, fontscale: mjtFontScal } } impl mjrContext { - /// Create a new `mjrContext` with the default font scale. + /// Create a new `mjrContext` with given font scale. /// /// This internally calls: /// diff --git a/src/functions/visualization.rs b/src/functions/visualization.rs index 407a46f..d043541 100644 --- a/src/functions/visualization.rs +++ b/src/functions/visualization.rs @@ -110,8 +110,10 @@ pub fn mjv_defaultScene() -> mjvScene { unsafe { c.assume_init() } } impl Default for mjvScene { - /// **note**: Call [`mjv_makeScene`] to allocate resources in abstract scene - /// before starting a simulation with the `mjvScene`. + /// Internally calls [`mjv_defaultScene`]. + /// + /// **note**: Be sure to call [`mjv_makeScene`] for the returned `mjvScene` to allocate resources in abstract scene + /// before using it in rendering. fn default() -> Self { mjv_defaultScene() } From 04d5cb410fceeb18c506803bb7de20e0af37b5df Mon Sep 17 00:00:00 2001 From: kanarus Date: Mon, 28 Jul 2025 23:27:32 +0900 Subject: [PATCH 2/2] tidy example --- examples/visualize_left_object.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/visualize_left_object.rs b/examples/visualize_left_object.rs index 1bab5f2..eba466d 100644 --- a/examples/visualize_left_object.rs +++ b/examples/visualize_left_object.rs @@ -1,5 +1,5 @@ -use rusty_mujoco::{mj_loadXML, mj_makeData, mj_step}; -use rusty_mujoco::{mjr_makeContext, mjr_render, mjrContext, mjrRect, mjtCatBit, mjtFontScale, mjv_updateScene, mjvCamera, mjvOption, mjvScene}; +use rusty_mujoco::{mj_loadXML, mj_makeData, mj_step, mjr_render, mjv_updateScene}; +use rusty_mujoco::{mjrContext, mjrRect, mjtCatBit, mjtFontScale, mjvCamera, mjvOption, mjvScene}; struct Args { xml_path: String,