trimesh.scene.scene¶
Classes:

The Geometry3D object is the parent object of geometry objects which are three dimensional, including Trimesh, PointCloud, and Scene objects. 

A simple scene graph which can be rendered directly via pyglet/openGL or through other endpoints such as a raytracer. 

Functions:

Concatenate multiple scene objects into one scene. 

Given a geometry, list of geometries, or a Scene return them as a single Scene object. 

class
trimesh.scene.scene.
Scene
(geometry=None, base_frame='world', metadata={}, graph=None, camera=None, lights=None, camera_transform=None)¶ Bases:
trimesh.parent.Geometry3D
A simple scene graph which can be rendered directly via pyglet/openGL or through other endpoints such as a raytracer. Meshes are added by name, which can then be moved by updating transform in the transform tree.
Methods:
add_geometry
(geometry[, node_name, …])Add a geometry to the scene.
apply_transform
(transform)Apply a transform to every geometry in the scene.
Calculate the trimesh.scene.Camera origin and ray direction vectors.
convert_units
(desired[, guess])If geometry has units defined convert them to new units.
copy
()Return a deep copy of the current scene
crc
()Return a new scene where each unique geometry is only included once and transforms are discarded.
delete_geometry
(names)Delete one more multiple geometries from the scene and also remove any node in the transform graph which references it.
dump
([concatenate])Append all meshes in scene freezing transforms.
explode
([vector, origin])Explode a scene around a point and vector.
export
([file_obj, file_type])Export a snapshot of the current scene.
md5
()MD5 of scene which will change when meshes or transforms are changed
rezero
()Move the current scene so that the AABB of the whole scene is centered at the origin.
save_image
([resolution])Get a PNG image of a scene.
scaled
(scale)Return a copy of the current scene, with meshes and scene transforms scaled to the requested factor.
set_camera
([angles, distance, center, …])Create a camera object for self.camera, and add a transform to self.graph for it.
show
([viewer])Display the current scene.
Attributes:
What is the summed area of every geometry which has area.
Return the overall bounding box of the scene.
A list of points that represent the corners of the AABB of every geometry in the scene.
Get the single camera for the scene.
Get camera transform in the base frame
Return the center of the bounding box for the scene.
The convex hull of the whole scene
Return a sequence of node keys of identical meshes.
Return the axis aligned box size of the current scene.
Look up geometries by identifier MD5
Does the scene have anything in it.
Is every geometry connected to the root node.
Get a list of the lights in the scene.
The approximate scale of the mesh
Return a correctly transformed polygon soup of the current scene.
Which node of self.graph does each triangle come from.
Get the units for every model in the scene, and raise a ValueError if there are mixed units.

add_geometry
(geometry, node_name=None, geom_name=None, parent_node_name=None, transform=None)¶ Add a geometry to the scene.
If the mesh has multiple transforms defined in its metadata, they will all be copied into the TransformForest of the current scene automatically.
 Parameters
geometry (Trimesh, Path2D, Path3D PointCloud or list) – Geometry to initially add to the scene
base_frame (str or hashable) – Name of base frame
metadata (dict) – Any metadata about the scene
graph (TransformForest or None) – A passed transform graph to use
 Returns
node_name – Name of node in self.graph
 Return type
str

apply_transform
(transform)¶ Apply a transform to every geometry in the scene.
 Parameters
transform ((4, 4)) – Homogeneous transformation matrix

property
area
¶ What is the summed area of every geometry which has area.
 Returns
area – Summed area of every instanced geometry
 Return type
float

property
bounds
¶ Return the overall bounding box of the scene.
 Returns
bounds – Position of [min, max] bounding box Returns None if no valid bounds exist
 Return type
(2, 3) float or None

property
bounds_corners
¶ A list of points that represent the corners of the AABB of every geometry in the scene.
This can be useful if you want to take the AABB in a specific frame.
 Returns
corners
 Return type
(n, 3) float, points in space

property
camera
¶ Get the single camera for the scene. If not manually set one will abe automatically generated.
 Returns
camera – Camera object defined for the scene
 Return type
trimesh.scene.Camera

camera_rays
()¶ Calculate the trimesh.scene.Camera origin and ray direction vectors. Returns one ray per pixel as set in camera.resolution
 Returns
origin ((n, 3) float) – Ray origins in space
vectors ((n, 3) float) – Ray direction unit vectors in world coordinates
pixels ((n, 2) int) – Which pixel does each ray correspond to in an image

property
camera_transform
¶ Get camera transform in the base frame
 Returns
camera_transform – Camera transform in the base frame
 Return type
(4, 4) float

property
centroid
¶ Return the center of the bounding box for the scene.
 Returns
centroid – Point for center of bounding box
 Return type
float

convert_units
(desired, guess=False)¶ If geometry has units defined convert them to new units.
Returns a new scene with geometries and transforms scaled.
 Parameters
desired (str) – Desired final unit system: ‘inches’, ‘mm’, etc.
guess (bool) – Is the converter allowed to guess scale when models don’t have it specified in their metadata.
 Returns
scaled – Copy of scene with scaling applied and units set for every model
 Return type

property
convex_hull
¶ The convex hull of the whole scene
 Returns
hull
 Return type
Trimesh object, convex hull of all meshes in scene

copy
()¶ Return a deep copy of the current scene
 Returns
copied – Copy of the current scene
 Return type

crc
()¶

deduplicated
()¶ Return a new scene where each unique geometry is only included once and transforms are discarded.
 Returns
dedupe – One copy of each unique geometry from scene
 Return type

delete_geometry
(names)¶ Delete one more multiple geometries from the scene and also remove any node in the transform graph which references it.
 Parameters
name (hashable) – Name that references self.geometry

dump
(concatenate=False)¶ Append all meshes in scene freezing transforms.

property
duplicate_nodes
¶ Return a sequence of node keys of identical meshes.
Will include meshes with different geometry but identical spatial hashes as well as meshes repeated by self.nodes.
 Returns
duplicates – Keys of self.nodes that represent identical geometry
 Return type
sequenc

explode
(vector=None, origin=None)¶ Explode a scene around a point and vector.
 Parameters
vector ((3,) float or float) – Explode radially around a direction vector or spherically
origin ((3,) float) – Point to explode around

export
(file_obj=None, file_type=None, **kwargs)¶ Export a snapshot of the current scene.
 Parameters
file_obj (str, filelike, or None) – File object to export to
file_type (str or None) – What encoding to use for meshes IE: dict, dict64, stl
 Returns
export – Only returned if file_obj is None
 Return type
bytes

property
extents
¶ Return the axis aligned box size of the current scene.
 Returns
extents – Bounding box sides length
 Return type
(3,) float

property
geometry_identifiers
¶ Look up geometries by identifier MD5
 Returns
identifiers – {Identifier MD5: key in self.geometry}
 Return type
dict

property
has_camera
¶

property
is_empty
¶ Does the scene have anything in it.
 Returns
is_empty
 Return type
bool, True if nothing is in the scene

property
is_valid
¶ Is every geometry connected to the root node.
 Returns
is_valid – Does every geometry have a transform
 Return type
bool

property
lights
¶ Get a list of the lights in the scene. If nothing is set it will generate some automatically.
 Returns
lights – Lights in the scene.
 Return type

md5
()¶ MD5 of scene which will change when meshes or transforms are changed
 Returns
hashed – MD5 hash of scene
 Return type
str

rezero
()¶ Move the current scene so that the AABB of the whole scene is centered at the origin.
Does this by changing the base frame to a new, offset base frame.

save_image
(resolution=None, **kwargs)¶ Get a PNG image of a scene.
 Parameters
resolution ((2,) int) – Resolution to render image
**kwargs – Passed to SceneViewer constructor
 Returns
png – Render of scene as a PNG
 Return type
bytes

property
scale
¶ The approximate scale of the mesh
 Returns
scale – The mean of the bounding box edge lengths
 Return type
float

scaled
(scale)¶ Return a copy of the current scene, with meshes and scene transforms scaled to the requested factor.
 Parameters
scale (float) – Factor to scale meshes and transforms
 Returns
scaled – A copy of the current scene but scaled
 Return type

set_camera
(angles=None, distance=None, center=None, resolution=None, fov=None)¶ Create a camera object for self.camera, and add a transform to self.graph for it.
If arguments are not passed sane defaults will be figured out which show the mesh roughly centered.
 Parameters
angles ((3,) float) – Initial euler angles in radians
distance (float) – Distance from centroid
center ((3,) float) – Point camera should be center on
camera (Camera object) – Object that stores camera parameters

show
(viewer=None, **kwargs)¶ Display the current scene.
 Parameters
viewer (str) – What kind of viewer to open, including ‘gl’ to open a pyglet window, ‘notebook’ for a jupyter notebook or None
kwargs (dict) – Includes smooth, which will turn on or off automatic smooth shading

property
triangles
¶ Return a correctly transformed polygon soup of the current scene.
 Returns
triangles – Triangles in space
 Return type
(n, 3, 3) float

property
triangles_node
¶ Which node of self.graph does each triangle come from.
 Returns
triangles_index – Node name for each triangle
 Return type
(len(self.triangles),)

property
units
¶ Get the units for every model in the scene, and raise a ValueError if there are mixed units.
 Returns
units – Units for every model in the scene
 Return type
str


trimesh.scene.scene.
append_scenes
(iterable, common=['world'])¶ Concatenate multiple scene objects into one scene.
 Parameters
 Returns
result – Scene containing all geometry
 Return type

trimesh.scene.scene.
split_scene
(geometry, **kwargs)¶ Given a geometry, list of geometries, or a Scene return them as a single Scene object.
 Parameters
geometry (splittable) –
 Returns
scene
 Return type