OpenMotionLab/MotionGPT
118
1.. _viewer_guide:2 3Live Scene Viewer4=================5 6Standard Usage7--------------8In addition to the offscreen renderer, Pyrender comes with a live scene viewer.9In its standard invocation, calling the :class:`.Viewer`'s constructor will10immediately pop a viewing window that you can navigate around in.11 12>>> pyrender.Viewer(scene)13 14By default, the viewer uses your scene's lighting. If you'd like to start with15some additional lighting that moves around with the camera, you can specify that16with:17 18>>> pyrender.Viewer(scene, use_raymond_lighting=True)19 20For a full list of the many options that the :class:`.Viewer` supports, check out its21documentation.22 23.. image:: /_static/rotation.gif24 25Running the Viewer in a Separate Thread26---------------------------------------27If you'd like to animate your models, you'll want to run the viewer in a28separate thread so that you can update the scene while the viewer is running.29To do this, first pop the viewer in a separate thread by calling its constructor30with the ``run_in_thread`` option set:31 32>>> v = pyrender.Viewer(scene, run_in_thread=True)33 34Then, you can manipulate the :class:`.Scene` while the viewer is running to35animate things. However, be careful to acquire the viewer's36:attr:`.Viewer.render_lock` before editing the scene to prevent data corruption:37 38>>> i = 039>>> while True:40... pose = np.eye(4)41... pose[:3,3] = [i, 0, 0]42... v.render_lock.acquire()43... scene.set_pose(mesh_node, pose)44... v.render_lock.release()45... i += 0.0146 47.. image:: /_static/scissors.gif48 49You can wait on the viewer to be closed manually:50 51>>> while v.is_active:52... pass53 54Or you can close it from the main thread forcibly.55Make sure to still loop and block for the viewer to actually exit before using56the scene object again.57 58>>> v.close_external()59>>> while v.is_active:60... pass61 62 