Skip to content

Commit c4b0b8d

Browse files
authored
Merge pull request #9 from rpapallas/main
Added optional parameters
2 parents 5e09649 + f9f6840 commit c4b0b8d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ Double-click on a geom and hold `Ctrl` to apply forces (right) and torques (left
4848

4949
Press `ESC` to quit.
5050
Other key bindings are shown in the overlay menu (almost similar to `mujoco-py`).
51+
52+
# Optional Parameters
53+
54+
- `title`: set the title of the window, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, title='My Demo')` (defaults to `mujoco-python-viewer`).
55+
- `width`: set the window width, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, width=300)` (defaults to full screen's width).
56+
- `height`: set the window height, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, height=300)` (defaults to full screen's height).

mujoco_viewer/mujoco_viewer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class MujocoViewer:
11-
def __init__(self, model, data):
11+
def __init__(self, model, data, title="mujoco-python-viewer", width=None, height=None):
1212
self.model = model
1313
self.data = data
1414

@@ -39,9 +39,15 @@ def __init__(self, model, data):
3939

4040
# glfw init
4141
glfw.init()
42-
width, height = glfw.get_video_mode(glfw.get_primary_monitor()).size
42+
43+
if not width:
44+
width, _ = glfw.get_video_mode(glfw.get_primary_monitor()).size
45+
46+
if not height:
47+
_, height = glfw.get_video_mode(glfw.get_primary_monitor()).size
48+
4349
self.window = glfw.create_window(
44-
width, height, "mujoco-python-viewer", None, None)
50+
width, height, title, None, None)
4551
glfw.make_context_current(self.window)
4652
glfw.swap_interval(1)
4753

0 commit comments

Comments
 (0)