Skip to content

Commit a90d9ff

Browse files
authored
Update README.md
1 parent 44dd9d8 commit a90d9ff

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ pip install mujoco-python-viewer
1919
```
2020

2121
# Usage
22-
22+
#### How to render in a window?
2323
```py
2424
import mujoco
2525
import mujoco_viewer
@@ -45,13 +45,28 @@ viewer.close()
4545
The render should pop up and the simulation should be running.
4646
Double-click on a geom and hold `Ctrl` to apply forces (right) and torques (left).
4747

48-
4948
![ezgif-2-6758c40cdf](https://user-images.githubusercontent.com/16384313/161459985-a47e74dc-92c9-4a0b-99fc-92d1b5b04163.gif)
5049

5150

5251
Press `ESC` to quit.
5352
Other key bindings are shown in the overlay menu (Press `H` or hold `Alt`).
5453

54+
55+
56+
#### How to render offscreen?
57+
```py
58+
import mujoco
59+
import mujoco_viewer
60+
61+
model = mujoco.MjModel.from_xml_path('humanoid.xml')
62+
data = mujoco.MjData(model)
63+
64+
viewer = mujoco_viewer.MujocoViewer(model, data, 'offscreen')
65+
mujoco.mj_forward(model, data)
66+
img = viewer.read_pixels(camid=2)
67+
## do something cool with img
68+
```
69+
5570
# Optional Parameters
5671

5772
- `title`: set the title of the window, for example: `viewer = mujoco_viewer.MujocoViewer(model, data, title='My Demo')` (defaults to `mujoco-python-viewer`).

0 commit comments

Comments
 (0)