tfg.io.triangle_mesh.Scene

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.

area What is the summed area of every geometry which has area.

Returns

area : float Summed area of every instanced geometry

bounding_box An axis aligned bounding box for the current mesh.

Returns

aabb : trimesh.primitives.Box Box object with transform and extents defined representing the axis aligned bounding box of the mesh

bounding_box_oriented An oriented bounding box for the current mesh.

Returns

obb : trimesh.primitives.Box Box object with transform and extents defined representing the minimum volume oriented bounding box of the mesh

bounding_cylinder A minimum volume bounding cylinder for the current mesh.

Returns

mincyl : trimesh.primitives.Cylinder Cylinder primitive containing current mesh

bounding_primitive The minimum volume primitive (box, sphere, or cylinder) that bounds the mesh.

Returns

bounding_primitive : object Smallest primitive which bounds the mesh: trimesh.primitives.Sphere trimesh.primitives.Box trimesh.primitives.Cylinder

bounding_sphere A minimum volume bounding sphere for the current mesh.

Note that the Sphere primitive returned has an unpadded exact sphere_radius so while the distance of every vertex of the current mesh from sphere_center will be less than sphere_radius, the faceted sphere primitive may not contain every vertex.

Returns

minball : trimesh.primitives.Sphere Sphere primitive containing current mesh

bounds Return the overall bounding box of the scene.

Returns

bounds : (2, 3) float or None Position of [min, max] bounding box Returns None if no valid bounds exist

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: (n, 3) float, points in space

camera Get the single camera for the scene. If not manually set one will abe automatically generated.

Returns

camera : trimesh.scene.Camera Camera object defined for the scene

camera_transform Get camera transform in the base frame

Returns

camera_transform : (4, 4) float Camera transform in the base frame

centroid Return the center of the bounding box for the scene.

Returns

centroid : (3) float Point for center of bounding box

convex_hull The convex hull of the whole scene

Returns

hull: Trimesh object, convex hull of all meshes in scene

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 : (m) sequenc Keys of self.nodes that represent identical geometry

extents Return the axis aligned box size of the current scene.

Returns

extents : (3,) float Bounding box sides length

geometry_identifiers Look up geometries by identifier MD5

Returns

identifiers : dict {Identifier MD5: key in self.geometry}

has_camera

is_empty Does the scene have anything in it.

Returns

is_empty: bool, True if nothing is in the scene

is_valid Is every geometry connected to the root node.

Returns

is_valid : bool Does every geometry have a transform

lights Get a list of the lights in the scene. If nothing is set it will generate some automatically.

Returns

lights : [trimesh.scene.lighting.Light] Lights in the scene.

scale The approximate scale of the mesh

Returns

scale : float The mean of the bounding box edge lengths

triangles Return a correctly transformed polygon soup of the current scene.

Returns

triangles : (n, 3, 3) float Triangles in space

triangles_node Which node of self.graph does each triangle come from.

Returns

triangles_index : (len(self.triangles),) Node name for each triangle

units Get the units for every model in the scene, and raise a ValueError if there are mixed units.

Returns

units : str Units for every model in the scene

Methods

add_geometry

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 : str Name of node in self.graph

apply_obb

Apply the oriented bounding box transform to the current mesh.

This will result in a mesh with an AABB centered at the origin and the same dimensions as the OBB.

Returns

matrix : (4, 4) float Transformation matrix that was applied to mesh to move it into OBB frame

apply_scale

Scale the mesh.

Parameters

scaling : float or (3,) float Scale factor to apply to the mesh

apply_transform

Apply a transform to every geometry in the scene.

Parameters

transform : (4, 4) Homogeneous transformation matrix

apply_translation

Translate the current mesh.

Parameters

translation : (3,) float Translation in XYZ

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

convert_units

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 : trimesh.Scene Copy of scene with scaling applied and units set for every model

copy

Return a deep copy of the current scene

Returns

copied : trimesh.Scene Copy of the current scene

crc

deduplicated

Return a new scene where each unique geometry is only included once and transforms are discarded.

Returns

dedupe : Scene One copy of each unique geometry from scene

delete_geometry

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

Append all meshes in scene freezing transforms.

Parameters

concatenate : bool If True, concatenate results into single mesh

Returns

dumped : (n,) Trimesh or Trimesh Trimesh objects transformed to their location the scene.graph

explode

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

Export a snapshot of the current scene.

Parameters

file_obj : str, file-like, or None File object to export to file_type : str or None What encoding to use for meshes IE: dict, dict64, stl

Returns

export : bytes Only returned if file_obj is None

md5

MD5 of scene which will change when meshes or transforms are changed

Returns

hashed : str MD5 hash of scene

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

Get a PNG image of a scene.

Parameters

resolution : (2,) int Resolution to render image **kwargs Passed to SceneViewer constructor

Returns

png : bytes Render of scene as a PNG

scaled

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 : trimesh.Scene A copy of the current scene but scaled

set_camera

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

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

__add__

Concatenate the current scene with another scene or mesh.

Parameters

other : trimesh.Scene, trimesh.Trimesh, trimesh.Path Other object to append into the result scene

Returns

appended : trimesh.Scene Scene with geometry from both scenes

__radd__

Concatenate the geometry allowing concatenation with built in sum() function: sum(Iterable[trimesh.Trimesh])

Parameters

other : Geometry Geometry or 0

Returns

concat : Geometry Geometry of combined result