Scene

class pyrender.Scene(nodes=None, bg_color=None, ambient_light=None, name=None)[source]

Bases: object

A hierarchical scene graph.

Parameters:
  • nodes (list of Node) – The set of all nodes in the scene.
  • bg_color ((4,) float, optional) – Background color of scene.
  • ambient_light ((3,) float, optional) – Color of ambient light. Defaults to no ambient light.
  • name (str, optional) – The user-defined name of this object.

Attributes Summary

ambient_light The ambient light in the scene.
bg_color The scene background color.
bounds The axis-aligned bounds of the scene.
camera_nodes The nodes containing cameras in the scene.
cameras The cameras in the scene.
centroid The centroid of the scene’s axis-aligned bounding box (AABB).
directional_light_nodes The nodes containing directional lights.
directional_lights The directional lights in the scene.
extents The lengths of the axes of the scene’s AABB.
light_nodes The nodes containing lights.
lights The lights in the scene.
main_camera_node The node containing the main camera in the scene.
mesh_nodes The nodes containing meshes.
meshes The meshes in the scene.
name The user-defined name of this object.
nodes Set of nodes in the scene.
point_light_nodes The nodes containing point lights.
point_lights The point lights in the scene.
scale The length of the diagonal of the scene’s AABB.
spot_light_nodes The nodes containing spot lights.
spot_lights The spot lights in the scene.

Methods Summary

add(obj[, name, pose, parent_node, parent_name]) Add an object (mesh, light, or camera) to the scene.
add_node(node[, parent_node]) Add a Node to the scene.
clear() Clear out all nodes to form an empty scene.
from_trimesh_scene(trimesh_scene[, …]) Create a Scene from a trimesh.scene.scene.Scene.
get_nodes([node, name, obj, obj_name]) Search for existing nodes.
get_pose(node) Get the world-frame pose of a node in the scene.
has_node(node) Check if a node is already in the scene.
remove_node(node) Remove a node and all its children from the scene.
set_pose(node, pose) Set the local-frame pose of a node in the scene.

Attributes Documentation

ambient_light

The ambient light in the scene.

Type:(3,) float
bg_color

The scene background color.

Type:(3,) float
bounds

The axis-aligned bounds of the scene.

Type:(2,3) float
camera_nodes

The nodes containing cameras in the scene.

Type:set of Node
cameras

The cameras in the scene.

Type:set of Camera
centroid

The centroid of the scene’s axis-aligned bounding box (AABB).

Type:(3,) float
directional_light_nodes

The nodes containing directional lights.

Type:set of Node
directional_lights

The directional lights in the scene.

Type:set of DirectionalLight
extents

The lengths of the axes of the scene’s AABB.

Type:(3,) float
light_nodes

The nodes containing lights.

Type:set of Node
lights

The lights in the scene.

Type:set of Light
main_camera_node

The node containing the main camera in the scene.

Type:set of Node
mesh_nodes

The nodes containing meshes.

Type:set of Node
meshes

The meshes in the scene.

Type:set of Mesh
name

The user-defined name of this object.

Type:str
nodes

Set of nodes in the scene.

Type:set of Node
point_light_nodes

The nodes containing point lights.

Type:set of Node
point_lights

The point lights in the scene.

Type:set of PointLight
scale

The length of the diagonal of the scene’s AABB.

Type:(3,) float
spot_light_nodes

The nodes containing spot lights.

Type:set of Node
spot_lights

The spot lights in the scene.

Type:set of SpotLight

Methods Documentation

add(obj, name=None, pose=None, parent_node=None, parent_name=None)[source]

Add an object (mesh, light, or camera) to the scene.

Parameters:
  • obj (Mesh, Light, or Camera) – The object to add to the scene.
  • name (str) – A name for the new node to be created.
  • pose ((4,4) float) – The local pose of this node relative to its parent node.
  • parent_node (Node) – The parent of this Node. If None, the new node is a root node.
  • parent_name (str) – The name of the parent node, can be specified instead of parent_node.
Returns:

node – The newly-created and inserted node.

Return type:

Node

add_node(node, parent_node=None)[source]

Add a Node to the scene.

Parameters:
  • node (Node) – The node to be added.
  • parent_node (Node) – The parent of this Node. If None, the new node is a root node.
clear()[source]

Clear out all nodes to form an empty scene.

static from_trimesh_scene(trimesh_scene, bg_color=None, ambient_light=None)[source]

Create a Scene from a trimesh.scene.scene.Scene.

Parameters:
  • trimesh_scene (trimesh.scene.scene.Scene) – Scene with :class:~`trimesh.base.Trimesh` objects.
  • bg_color ((4,) float) – Background color for the created scene.
  • ambient_light ((3,) float or None) – Ambient light in the scene.
Returns:

scene_pr – A scene containing the same geometry as the trimesh scene.

Return type:

Scene

get_nodes(node=None, name=None, obj=None, obj_name=None)[source]

Search for existing nodes. Only nodes matching all specified parameters is returned, or None if no such node exists.

Parameters:
  • node (Node, optional) – If present, returns this node if it is in the scene.
  • name (str) – A name for the Node.
  • obj (Mesh, Light, or Camera) – An object that is attached to the node.
  • obj_name (str) – The name of an object that is attached to the node.
Returns:

nodes – The nodes that match all query terms.

Return type:

set of Node

get_pose(node)[source]

Get the world-frame pose of a node in the scene.

Parameters:node (Node) – The node to find the pose of.
Returns:pose – The transform matrix for this node.
Return type:(4,4) float
has_node(node)[source]

Check if a node is already in the scene.

Parameters:node (Node) – The node to be checked.
Returns:has_node – True if the node is already in the scene and false otherwise.
Return type:bool
remove_node(node)[source]

Remove a node and all its children from the scene.

Parameters:node (Node) – The node to be removed.
set_pose(node, pose)[source]

Set the local-frame pose of a node in the scene.

Parameters:
  • node (Node) – The node to set the pose of.
  • pose ((4,4) float) – The pose to set the node to.