OpenMotionLab/MotionGPT
118
1.. _scene_guide:2 3Creating Scenes4===============5 6Before you render anything, you need to put all of your lights, cameras,7and meshes into a scene. The :class:`.Scene` object keeps track of the relative8poses of these primitives by inserting them into :class:`.Node` objects and9keeping them in a directed acyclic graph.10 11Adding Objects12--------------13 14To create a :class:`.Scene`, simply call the constructor. You can optionally15specify an ambient light color and a background color:16 17>>> scene = pyrender.Scene(ambient_light=[0.02, 0.02, 0.02],18... bg_color=[1.0, 1.0, 1.0])19 20You can add objects to a scene by first creating a :class:`.Node` object21and adding the object and its pose to the :class:`.Node`. Poses are specified22as 4x4 homogenous transformation matrices that are stored in the node's23:attr:`.Node.matrix` attribute. Note that the :class:`.Node`24constructor requires you to specify whether you're adding a mesh, light,25or camera.26 27>>> mesh = pyrender.Mesh.from_trimesh(tm)28>>> light = pyrender.PointLight(color=[1.0, 1.0, 1.0], intensity=2.0)29>>> cam = pyrender.PerspectiveCamera(yfov=np.pi / 3.0, aspectRatio=1.414)30>>> nm = pyrender.Node(mesh=mesh, matrix=np.eye(4))31>>> nl = pyrender.Node(light=light, matrix=np.eye(4))32>>> nc = pyrender.Node(camera=cam, matrix=np.eye(4))33>>> scene.add_node(nm)34>>> scene.add_node(nl)35>>> scene.add_node(nc)36 37You can also add objects directly to a scene with the :meth:`.Scene.add` function,38which takes care of creating a :class:`.Node` for you.39 40>>> scene.add(mesh, pose=np.eye(4))41>>> scene.add(light, pose=np.eye(4))42>>> scene.add(cam, pose=np.eye(4))43 44Nodes can be hierarchical, in which case the node's :attr:`.Node.matrix`45specifies that node's pose relative to its parent frame. You can add nodes to46a scene hierarchically by specifying a parent node in your calls to47:meth:`.Scene.add` or :meth:`.Scene.add_node`:48 49>>> scene.add_node(nl, parent_node=nc)50>>> scene.add(cam, parent_node=nm)51 52If you add multiple cameras to a scene, you can specify which one to render from53by setting the :attr:`.Scene.main_camera_node` attribute.54 55Updating Objects56----------------57 58You can update the poses of existing nodes with the :meth:`.Scene.set_pose`59function. Simply call it with a :class:`.Node` that is already in the scene60and the new pose of that node with respect to its parent as a 4x4 homogenous61transformation matrix:62 63>>> scene.set_pose(nl, pose=np.eye(4))64 65If you want to get the local pose of a node, you can just access its66:attr:`.Node.matrix` attribute. However, if you want to the get67the pose of a node *with respect to the world frame*, you can call the68:meth:`.Scene.get_pose` method.69 70>>> tf = scene.get_pose(nl)71 72Removing Objects73----------------74 75Finally, you can remove a :class:`.Node` and all of its children from the76scene with the :meth:`.Scene.remove_node` function:77 78>>> scene.remove_node(nl)79 