diff --git a/README.md b/README.md index 962ae8d..69c4175 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,9 @@ Double-click on a geom and hold `Ctrl` to apply forces (right) and torques (left Press `ESC` to quit. Other key bindings are shown in the overlay menu (almost similar to `mujoco-py`). + +# Optional Parameters + +- `title`: set the title of the window, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, title='My Demo')` (defaults to `mujoco-python-viewer`). +- `width`: set the window width, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, width=300)` (defaults to full screen's width). +- `height`: set the window height, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, height=300)` (defaults to full screen's height). diff --git a/mujoco_viewer/mujoco_viewer.py b/mujoco_viewer/mujoco_viewer.py index f82f1ee..ff146aa 100644 --- a/mujoco_viewer/mujoco_viewer.py +++ b/mujoco_viewer/mujoco_viewer.py @@ -8,7 +8,7 @@ class MujocoViewer: - def __init__(self, model, data): + def __init__(self, model, data, title="mujoco-python-viewer", width=None, height=None): self.model = model self.data = data @@ -39,9 +39,15 @@ def __init__(self, model, data): # glfw init glfw.init() - width, height = glfw.get_video_mode(glfw.get_primary_monitor()).size + + if not width: + width, _ = glfw.get_video_mode(glfw.get_primary_monitor()).size + + if not height: + _, height = glfw.get_video_mode(glfw.get_primary_monitor()).size + self.window = glfw.create_window( - width, height, "mujoco-python-viewer", None, None) + width, height, title, None, None) glfw.make_context_current(self.window) glfw.swap_interval(1)