Skip to content

Problem using a wndow viewer and an offscreen viewer at the same time #35

@jodyxha

Description

@jodyxha

I would like to have a simulation (which is shown in a window) of which images are taken at regular intervals.
So i added a offscreen viewer to the example code like this

import mujoco
import mujoco_viewer

model = mujoco.MjModel.from_xml_path('~/mujoco/mujoco-2.3.5/model/humanoid/humanoid.xml')
data = mujoco.MjData(model)
# create the viewer objects
viewer = mujoco_viewer.MujocoViewer(model, data)
viewer1 = mujoco_viewer.MujocoViewer(model, data, 'offscreen')
imgs = []
for i in range(10000):
    if viewer.is_alive:
        mujoco.mj_step(model, data)
        viewer.render()
        if (i % 100) == 0:
            print("Doing so,for %d"%i)
            img = viewer1.read_pixels(camid=0)
            imgs.append(img)
    else:
        break
viewer.close()
viewer1.close()
# do something with the images

When i do it this way, the normal window is not opened. When i exchange the order of the viewer creations, the viewer window opens but the window remains black.
Is it possible at all to have a window viewer and a offscreen viewer in the same simulation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions