Add show_{left,right}_ui kwarg to viewer.launch(_passive).
Fixes #857 PiperOrigin-RevId: 572333909 Change-Id: I12247fe856afddf808eb8f386a594acac47c34b5
This commit is contained in:
committed by
Copybara-Service
parent
2e15574b58
commit
a1d0cbd654
@@ -294,11 +294,17 @@ while True:
|
||||
break
|
||||
|
||||
# Otherwise, launch the viewer.
|
||||
model, data, handle_return, key_callback = task
|
||||
model, data, handle_return, key_callback, show_left_ui, show_right_ui = task
|
||||
ctypes.CDLL(None).mjpython_show_dock_icon()
|
||||
mujoco.viewer._launch_internal(
|
||||
model, data, run_physics_thread=False, handle_return=handle_return,
|
||||
key_callback=key_callback)
|
||||
model,
|
||||
data,
|
||||
run_physics_thread=False,
|
||||
handle_return=handle_return,
|
||||
key_callback=key_callback,
|
||||
show_left_ui=show_left_ui,
|
||||
show_right_ui=show_right_ui,
|
||||
)
|
||||
ctypes.CDLL(None).mjpython_hide_dock_icon()
|
||||
|
||||
finally:
|
||||
|
||||
@@ -314,7 +314,17 @@ PYBIND11_MODULE(_simulate, pymodule) {
|
||||
const auto max_length = sizeof_arr(sim.load_error);
|
||||
std::strncpy(sim.load_error, error.c_str(), max_length - 1);
|
||||
sim.load_error[max_length - 1] = '\0';
|
||||
}));
|
||||
}))
|
||||
.def_property("ui0_enable", GetIfNotNull(&mujoco::Simulate::ui0_enable),
|
||||
CallIfNotNull(+[](mujoco::Simulate& sim, int enabled) {
|
||||
sim.ui0_enable = enabled;
|
||||
}),
|
||||
py::call_guard<py::gil_scoped_release>())
|
||||
.def_property("ui1_enable", GetIfNotNull(&mujoco::Simulate::ui1_enable),
|
||||
CallIfNotNull(+[](mujoco::Simulate& sim, int enabled) {
|
||||
sim.ui1_enable = enabled;
|
||||
}),
|
||||
py::call_guard<py::gil_scoped_release>());
|
||||
|
||||
pymodule.def("set_glfw_dlhandle", [](std::uintptr_t dlhandle) {
|
||||
mujoco::Glfw(reinterpret_cast<void*>(dlhandle));
|
||||
|
||||
+32
-6
@@ -319,6 +319,8 @@ def _launch_internal(
|
||||
loader: Optional[_InternalLoaderType] = None,
|
||||
handle_return: Optional['queue.Queue[Handle]'] = None,
|
||||
key_callback: Optional[KeyCallbackType] = None,
|
||||
show_left_ui: bool = True,
|
||||
show_right_ui: bool = True,
|
||||
) -> None:
|
||||
"""Internal API, so that the public API has more readable type annotations."""
|
||||
if model is None and data is not None:
|
||||
@@ -351,6 +353,9 @@ def _launch_internal(
|
||||
cam, opt, pert, user_scn, run_physics_thread, key_callback
|
||||
)
|
||||
|
||||
simulate.ui0_enable = show_left_ui
|
||||
simulate.ui1_enable = show_right_ui
|
||||
|
||||
# Initialize GLFW if not using mjpython.
|
||||
if _MJPYTHON is None:
|
||||
if not glfw.init():
|
||||
@@ -385,13 +390,23 @@ def _launch_internal(
|
||||
simulate.destroy()
|
||||
|
||||
|
||||
def launch(model: Optional[mujoco.MjModel] = None,
|
||||
data: Optional[mujoco.MjData] = None,
|
||||
*,
|
||||
loader: Optional[LoaderType] = None) -> None:
|
||||
def launch(
|
||||
model: Optional[mujoco.MjModel] = None,
|
||||
data: Optional[mujoco.MjData] = None,
|
||||
*,
|
||||
loader: Optional[LoaderType] = None,
|
||||
show_left_ui: bool = True,
|
||||
show_right_ui: bool = True,
|
||||
) -> None:
|
||||
"""Launches the Simulate GUI."""
|
||||
_launch_internal(
|
||||
model, data, run_physics_thread=True, loader=loader)
|
||||
model,
|
||||
data,
|
||||
run_physics_thread=True,
|
||||
loader=loader,
|
||||
show_left_ui=show_left_ui,
|
||||
show_right_ui=show_right_ui,
|
||||
)
|
||||
|
||||
|
||||
def launch_from_path(path: str) -> None:
|
||||
@@ -404,6 +419,8 @@ def launch_passive(
|
||||
data: mujoco.MjData,
|
||||
*,
|
||||
key_callback: Optional[KeyCallbackType] = None,
|
||||
show_left_ui: bool = True,
|
||||
show_right_ui: bool = True,
|
||||
) -> Handle:
|
||||
"""Launches a passive Simulate GUI without blocking the running thread."""
|
||||
if not isinstance(model, mujoco.MjModel):
|
||||
@@ -425,6 +442,8 @@ def launch_passive(
|
||||
run_physics_thread=False,
|
||||
handle_return=handle_return,
|
||||
key_callback=key_callback,
|
||||
show_left_ui=show_left_ui,
|
||||
show_right_ui=show_right_ui,
|
||||
),
|
||||
)
|
||||
thread.daemon = True
|
||||
@@ -434,7 +453,14 @@ def launch_passive(
|
||||
raise RuntimeError(
|
||||
'`launch_passive` requires that the Python script be run under '
|
||||
'`mjpython` on macOS')
|
||||
_MJPYTHON.launch_on_ui_thread(model, data, handle_return, key_callback)
|
||||
_MJPYTHON.launch_on_ui_thread(
|
||||
model,
|
||||
data,
|
||||
handle_return,
|
||||
key_callback,
|
||||
show_left_ui,
|
||||
show_right_ui,
|
||||
)
|
||||
|
||||
return handle_return.get()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user