Live Scene Viewer¶
Standard Usage¶
In addition to the offscreen renderer, Pyrender comes with a live scene viewer.
In its standard invocation, calling the Viewer
’s constructor will
immediately pop a viewing window that you can navigate around in.
>>> pyrender.Viewer(scene)
By default, the viewer uses your scene’s lighting. If you’d like to start with some additional lighting that moves around with the camera, you can specify that with:
>>> pyrender.Viewer(scene, use_raymond_lighting=True)
For a full list of the many options that the Viewer
supports, check out its
documentation.

Running the Viewer in a Separate Thread¶
If you’d like to animate your models, you’ll want to run the viewer in a
separate thread so that you can update the scene while the viewer is running.
To do this, first pop the viewer in a separate thread by calling its constructor
with the run_in_thread
option set:
>>> v = pyrender.Viewer(scene, run_in_thread=True)
Then, you can manipulate the Scene
while the viewer is running to
animate things. However, be careful to acquire the viewer’s
Viewer.render_lock
before editing the scene to prevent data corruption:
>>> i = 0
>>> while True:
... pose = np.eye(4)
... pose[:3,3] = [i, 0, 0]
... v.render_lock.acquire()
... scene.set_pose(mesh_node, pose)
... v.render_lock.release()
... i += 0.01

You can wait on the viewer to be closed manually:
>>> while v.is_active:
... pass
Or you can close it from the main thread forcibly. Make sure to still loop and block for the viewer to actually exit before using the scene object again.
>>> v.close_external()
>>> while v.is_active:
... pass