The Geometry3D
object is the parent object of geometry objects
tfg.io.triangle_mesh.Trimesh(
vertices=None, faces=None, face_normals=None, vertex_normals=None,
face_colors=None, vertex_colors=None, face_attributes=None,
vertex_attributes=None, metadata=None, process=True, validate=False,
use_embree=True, initial_cache=None, visual=None, **kwargs
)
which are three dimensional, including Trimesh, PointCloud, and Scene objects.
Attributes  

area

Summed area of all triangles in the current mesh.
Returnsarea : float Surface area of mesh 
area_faces

The area of each face in the mesh.
Returnsarea_faces : (n, ) float Area of each face 
body_count

How many connected groups of vertices exist in this mesh.
Note that this number may differ from result in mesh.split,
which is calculated from FACE rather than vertex adjacency.
Returnscount : int Number of connected vertex groups 
bounding_box

An axis aligned bounding box for the current mesh.
Returnsaabb : 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.
Returnsobb : 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.
Returnsmincyl : trimesh.primitives.Cylinder Cylinder primitive containing current mesh 
bounding_primitive

The minimum volume primitive (box, sphere, or cylinder) that
bounds the mesh.
Returnsbounding_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 Returnsminball : trimesh.primitives.Sphere Sphere primitive containing current mesh 
bounds

The axis aligned bounds of the faces of the mesh.
Returnsbounds : (2, 3) float or None Bounding box with [min, max] coordinates If mesh is empty will return None 
center_mass

The point in space which is the center of mass/volume.
If the current mesh is not watertight this is meaningless garbage unless it was explicitly set. Returnscenter_mass : (3, ) float Volumetric center of mass of the mesh 
centroid

The point in space which is the average of the triangle
centroids weighted by the area of each triangle.
This will be valid even for nonwatertight meshes, unlike self.center_mass Returnscentroid : (3, ) float The average vertex weighted by face area 
convex_hull

Returns a Trimesh object representing the convex hull of
the current mesh.
Returnsconvex : trimesh.Trimesh Mesh of convex hull of current mesh 
density

The density of the mesh.
Returnsdensity : float The density of the mesh. 
edges

Edges of the mesh (derived from faces).
Returnsedges : (n, 2) int List of vertex indices making up edges 
edges_face

Which face does each edge belong to.
Returnsedges_face : (n, ) int Index of self.faces 
edges_sorted

Edges sorted along axis 1
Returnsedges_sorted : (n, 2) Same as self.edges but sorted along axis 1 
edges_sorted_tree

A KDTree for mapping edges back to edge index.
Returnstree : scipy.spatial.cKDTree Tree when queried with edges will return their index in mesh.edges_sorted 
edges_sparse

Edges in sparse bool COO graph format where connected
vertices are True.
Returnssparse: (len(self.vertices), len(self.vertices)) bool Sparse graph in COO format 
edges_unique

The unique edges of the mesh.
Returnsedges_unique : (n, 2) int Vertex indices for unique edges 
edges_unique_inverse

Return the inverse required to reproduce
self.edges_sorted from self.edges_unique.
Useful for referencing edge properties: mesh.edges_unique[mesh.edges_unique_inverse] == m.edges_sorted Returnsinverse : (len(self.edges), ) int Indexes of self.edges_unique 
edges_unique_length

How long is each unique edge.
Returnslength : (len(self.edges_unique), ) float Length of each unique edge 
euler_number

Return the Euler characteristic (a topological invariant) for the mesh
In order to guarantee correctness, this should be called after
remove_unreferenced_vertices
Returnseuler_number : int Topological invariant 
extents

The length, width, and height of the axis aligned
bounding box of the mesh.
Returnsextents : (3, ) float or None Array containing axis aligned [length, width, height] If mesh is empty returns None 
face_adjacency

Find faces that share an edge, which we call here 'adjacent'.
Returnsadjacency : (n, 2) int Pairs of faces which share an edge ExamplesIn [1]: mesh = trimesh.load('models/featuretype.STL') In [2]: mesh.face_adjacency Out[2]: array([[ 0, 1], [ 2, 3], [ 0, 3], ..., [1112, 949], [3467, 3475], [1113, 3475]]) In [3]: mesh.faces[mesh.face_adjacency[0]] Out[3]: TrackedArray([[ 1, 0, 408], [1239, 0, 1]], dtype=int64) In [4]: import networkx as nx In [5]: graph = nx.from_edgelist(mesh.face_adjacency) In [6]: groups = nx.connected_components(graph) 
face_adjacency_angles

Return the angle between adjacent faces
Returnsadjacency_angle : (n, ) float Angle between adjacent faces Each value corresponds with self.face_adjacency 
face_adjacency_convex

Return faces which are adjacent and locally convex.
What this means is that given faces A and B, the one vertex in B that is not shared with A, projected onto the plane of A has a projection that is zero or negative. Returnsare_convex : (len(self.face_adjacency), ) bool Face pairs that are locally convex 
face_adjacency_edges

Returns the edges that are shared by the adjacent faces.
Returnsedges : (n, 2) int Vertex indices which correspond to face_adjacency 
face_adjacency_edges_tree

A KDTree for mapping edges back face adjacency index.
Returnstree : scipy.spatial.cKDTree Tree when queried with SORTED edges will return their index in mesh.face_adjacency 
face_adjacency_projections

The projection of the nonshared vertex of a triangle onto
its adjacent face
Returnsprojections : (len(self.face_adjacency), ) float Dot product of vertex onto plane of adjacent triangle. 
face_adjacency_radius

The approximate radius of a cylinder that fits inside adjacent faces.
Returnsradii : (len(self.face_adjacency), ) float Approximate radius formed by triangle pair 
face_adjacency_span

The approximate perpendicular projection of the nonshared
vertices in a pair of adjacent faces onto the shared edge of
the two faces.
Returnsspan : (len(self.face_adjacency), ) float Approximate span between the nonshared vertices 
face_adjacency_tree

An Rtree of face adjacencies.
Returnstree: rtree.index Where each edge in self.face_adjacency has a rectangular cell 
face_adjacency_unshared

Return the vertex index of the two vertices not in the shared
edge between two adjacent faces
Returnsvid_unshared : (len(mesh.face_adjacency), 2) int Indexes of mesh.vertices 
face_angles

Returns the angle at each vertex of a face.
Returnsangles : (len(self.faces), 3) float Angle at each vertex of a face 
face_angles_sparse

A sparse matrix representation of the face angles.
Returnssparse : scipy.sparse.coo_matrix Float sparse matrix with with shape: (len(self.vertices), len(self.faces)) 
face_normals

Return the unit normal vector for each face.
If a face is degenerate and a normal can't be generated a zero magnitude unit vector will be returned for that face. Returnsnormals : (len(self.faces), 3) np.float64 Normal vectors of each face 
faces

The faces of the mesh.
This is regarded as core information which cannot be regenerated from cache, and as such is stored in self._data which tracks the array for changes and clears cached values of the mesh if this is altered. Returnsfaces : (n, 3) int Representing triangles which reference self.vertices 
faces_sparse

A sparse matrix representation of the faces.
Returnssparse : scipy.sparse.coo_matrix Has properties: dtype : bool shape : (len(self.vertices), len(self.faces)) 
faces_unique_edges

For each face return which indexes in mesh.unique_edges constructs
that face.
Returnsfaces_unique_edges : (len(self.faces), 3) int Indexes of self.edges_unique that construct self.faces ExamplesIn [0]: mesh.faces[:2] Out[0]: TrackedArray([[ 1, 6946, 24224], [ 6946, 1727, 24225]]) In [1]: mesh.edges_unique[mesh.faces_unique_edges[:2]] Out[1]: array([[[ 1, 6946], [ 6946, 24224], [ 1, 24224]], [[ 1727, 6946], [ 1727, 24225], [ 6946, 24225]]]) 
facets

Return a list of face indices for coplanar adjacent faces.
Returnsfacets : (n, ) sequence of (m, ) int Groups of indexes of self.faces 
facets_area

Return an array containing the area of each facet.
Returnsarea : (len(self.facets), ) float Total area of each facet (group of faces) 
facets_boundary

Return the edges which represent the boundary of each facet
Returnsedges_boundary : sequence of (n, 2) int Indices of self.vertices 
facets_normal

Return the normal of each facet
Returnsnormals: (len(self.facets), 3) float A unit normal vector for each facet 
facets_on_hull

Find which facets of the mesh are on the convex hull.
Returnson_hull : (len(mesh.facets), ) bool is A facet on the meshes convex hull or not 
facets_origin

Return a point on the facet plane.
Returnsorigins : (len(self.facets), 3) float A point on each facet plane 
identifier

Return a float vector which is unique to the mesh
and is robust to rotation and translation.
Returnsidentifier : (6, ) float Identifying properties of the current mesh 
identifier_md5

An MD5 of the rotation invariant identifier vector
Returnshashed : str MD5 hash of the identifier vector 
is_convex

Check if a mesh is convex or not.
Returnsis_convex: bool Is mesh convex or not 
is_empty

Does the current mesh have data defined.
Returnsempty : bool If True, no data is set on the current mesh 
is_volume

Check if a mesh has all the properties required to represent
a valid volume, rather than just a surface.
These properties include being watertight, having consistent winding and outward facing normals. Returnsvalid : bool Does the mesh represent a volume 
is_watertight

Check if a mesh is watertight by making sure every edge is
included in two faces.
Returnsis_watertight : bool Is mesh watertight or not 
is_winding_consistent

Does the mesh have consistent winding or not.
A mesh with consistent winding has each shared edge
going in an opposite direction from the other in the pair.
Returnsconsistent : bool Is winding is consistent or not 
kdtree

Return a scipy.spatial.cKDTree of the vertices of the mesh.
Not cached as this lead to observed memory issues and segfaults.
Returnstree : scipy.spatial.cKDTree Contains mesh.vertices 
mass

Mass of the current mesh, based on specified density and
volume. If the current mesh isn't watertight this is garbage.
Returnsmass : float Mass of the current mesh 
mass_properties

Returns the mass properties of the current mesh.
Assumes uniform density, and result is probably garbage if mesh isn't watertight. Returnsproperties : dict With keys: 'volume' : in global units^3 'mass' : From specified density 'density' : Included again for convenience (same as kwarg density) 'inertia' : Taken at the center of mass and aligned with global coordinate system 'center_mass' : Center of mass location, in global coordinate system 
moment_inertia

Return the moment of inertia matrix of the current mesh.
If mesh isn't watertight this is garbage.
Returnsinertia : (3, 3) float Moment of inertia of the current mesh 
principal_inertia_components

Return the principal components of inertia
Ordering corresponds to mesh.principal_inertia_vectors Returnscomponents : (3, ) float Principal components of inertia 
principal_inertia_transform

A transform which moves the current mesh so the principal
inertia vectors are on the X,Y, and Z axis, and the centroid is
at the origin.
Returnstransform : (4, 4) float Homogeneous transformation matrix 
principal_inertia_vectors

Return the principal axis of inertia as unit vectors.
The order corresponds to mesh.principal_inertia_components .
Returnsvectors : (3, 3) float Three vectors pointing along the principal axis of inertia directions 
referenced_vertices

Which vertices in the current mesh are referenced by a face.
Returnsreferenced : (len(self.vertices), ) bool Which vertices are referenced by a face 
scale

A metric for the overall scale of the mesh, the length of the
diagonal of the axis aligned bounding box of the mesh.
Returnsscale : float The length of the meshes AABB diagonal 
symmetry

Check whether a mesh has rotational symmetry around
an axis (radial) or point (spherical).
Returnssymmetry: None, 'radial', 'spherical' What kind of symmetry does the mesh have. 
symmetry_axis

If a mesh has rotational symmetry, return the axis.
Returnsaxis : (3, ) float Axis around which a 2D profile was revolved to create this mesh. 
symmetry_section

If a mesh has rotational symmetry return the two
vectors which make up a section coordinate frame.
Returnssection : (2, 3) float Vectors to take a section along 
triangles

Actual triangles of the mesh (points, not indexes)
Returnstriangles : (n, 3, 3) float Points of triangle vertices 
triangles_center

The center of each triangle (barycentric [1/3, 1/3, 1/3])
Returnstriangles_center : (len(self.faces), 3) float Center of each triangular face 
triangles_cross

The cross product of two edges of each triangle.
Returnscrosses : (n, 3) float Cross product of each triangle 
triangles_tree

An Rtree containing each face of the mesh.
Returnstree : rtree.index Each triangle in self.faces has a rectangular cell 
units

Definition of units for the mesh.
Returnsunits : str Unit system mesh is in, or None if not defined 
vertex_adjacency_graph

Returns a networkx graph representing the vertices and their connections
in the mesh.
Returnsgraph: networkx.Graph Graph representing vertices and edges between them where vertices are nodes and edges are edges ExamplesThis is useful for getting nearby vertices for a given vertex, potentially for some simple smoothing techniques. mesh = trimesh.primitives.Box() graph = mesh.vertex_adjacency_graph graph.neighbors(0)

vertex_defects

Return the vertex defects, or (2*pi) minus the sum of the angles
of every face that includes that vertex.
If a vertex is only included by coplanar triangles, this will be zero. For convex regions this is positive, and concave negative. Returnsvertex_defect : (len(self.vertices), ) float Vertex defect at the every vertex 
vertex_degree

Return the number of faces each vertex is included in.
Returnsdegree : (len(self.vertices), ) int Number of faces each vertex is included in 
vertex_faces

A representation of the face indices that correspond to each vertex.
Returnsvertex_faces : (n,m) int Each row contains the face indices that correspond to the given vertex, padded with 1 up to the max number of faces corresponding to any one vertex Where n == len(self.vertices), m == max number of faces for a single vertex 
vertex_neighbors

The vertex neighbors of each vertex of the mesh, determined from
the cached vertex_adjacency_graph, if already existent.
Returnsvertex_neighbors : (len(self.vertices), ) int Represents immediate neighbors of each vertex along the edge of a triangle ExamplesThis is useful for getting nearby vertices for a given vertex, potentially for some simple smoothing techniques.

vertex_normals

The vertex normals of the mesh. If the normals were loaded
we check to make sure we have the same number of vertex
normals and vertices before returning them. If there are
no vertex normals defined or a shape mismatch we calculate
the vertex normals from the mean normals of the faces the
vertex is used in.
Returnsvertex_normals : (n, 3) float Represents the surface normal at each vertex. Where n == len(self.vertices) 
vertices

The vertices of the mesh.
This is regarded as core information which cannot be generated from cache and as such is stored in self._data which tracks the array for changes and clears cached values of the mesh if this is altered. Returnsvertices : (n, 3) float Points in cartesian space referenced by self.faces 
visual

Get the stored visuals for the current mesh.
Returnsvisual : ColorVisuals or TextureVisuals Contains visual information about the mesh 
volume

Volume of the current mesh calculated using a surface
integral. If the current mesh isn't watertight this is
garbage.
Returnsvolume : float Volume of the current mesh 
Methods
apply_obb
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
apply_scale(
scaling
)
Scale the mesh.
Parameters
scaling : float or (3,) float Scale factor to apply to the mesh
apply_transform
apply_transform(
matrix
)
Transform mesh by a homogeneous transformation matrix.
Does the bookkeeping to avoid recomputing things so this function should be used rather than directly modifying self.vertices if possible.
Parameters
matrix : (4, 4) float Homogeneous transformation matrix
apply_translation
apply_translation(
translation
)
Translate the current mesh.
Parameters
translation : (3,) float Translation in XYZ
compute_stable_poses
compute_stable_poses(
center_mass=None, sigma=0.0, n_samples=1, threshold=0.0
)
Computes stable orientations of a mesh and their quasistatic probabilites.
This method samples the location of the center of mass from a multivariate gaussian (mean at com, cov equal to identity times sigma) over n_samples. For each sample, it computes the stable resting poses of the mesh on a a planar workspace and evaluates the probabilities of landing in each pose if the object is dropped onto the table randomly.
This method returns the 4x4 homogeneous transform matrices that place the shape against the planar surface with the zaxis pointing upwards and a list of the probabilities for each pose. The transforms and probabilties that are returned are sorted, with the most probable pose first.
Parameters
center_mass : (3, ) float The object center of mass (if None, this method assumes uniform density and watertightness and computes a center of mass explicitly) sigma : float The covariance for the multivariate gaussian used to sample center of mass locations n_samples : int The number of samples of the center of mass location threshold : float The probability value at which to threshold returned stable poses
Returns
transforms : (n, 4, 4) float The homogeneous matrices that transform the object to rest in a stable pose, with the new zaxis pointing upwards from the table and the object just touching the table.
probs : (n, ) float A probability ranging from 0.0 to 1.0 for each pose
contains
contains(
points
)
Given an array of points determine whether or not they are inside the mesh. This raises an error if called on a nonwatertight mesh.
Parameters
points : (n, 3) float Points in cartesian space
Returns
contains : (n, ) bool Whether or not each point is inside the mesh
convert_units
convert_units(
desired, guess=False
)
Convert the units of the mesh into a specified unit.
Parameters
desired : string Units to convert to (eg 'inches') guess : boolean If self.units are not defined should we guess the current units of the document and then convert?
convex_decomposition
convex_decomposition(
maxhulls=20, **kwargs
)
Compute an approximate convex decomposition of a mesh.
testVHACD Parameters which can be passed as kwargs:
Name Default
resolution 100000 max. concavity 0.001 plane downsampling 4 convexhull downsampling 4 alpha 0.05 beta 0.05 maxhulls 10 pca 0 mode 0 max. vertices per convexhull 64 min. volume to add vertices to convexhulls 0.0001 convexhull approximation 1 OpenCL acceleration 1 OpenCL platform ID 0 OpenCL device ID 0 output output.wrl log log.txt
Parameters
maxhulls : int Maximum number of convex hulls to return **kwargs : testVHACD keyword arguments
Returns
meshes : list of trimesh.Trimesh List of convex meshes that approximate the original
copy
copy(
include_cache=False
)
Safely return a copy of the current mesh.
By default, copied meshes will have emptied cache to avoid memory issues and so may be slow on initial operations until caches are regenerated.
Current object will never have its cache cleared.
Parameters
include_cache : bool If True, will shallow copy cached data to new mesh
Returns
copied : trimesh.Trimesh Copy of current mesh
crc
crc()
A zlib.adler32 checksum for the current mesh data.
This is about 5x faster than an MD5, and the checksum is checked every time something is requested from the cache so it gets called a lot.
Returns
crc : int Checksum of current mesh data
difference
difference(
other, engine=None, **kwargs
)
Boolean difference between this mesh and n other meshes
Parameters
other : trimesh.Trimesh, or list of trimesh.Trimesh objects Meshes to difference
Returns
difference : trimesh.Trimesh Difference between self and other Trimesh objects
eval_cached
eval_cached(
statement, *args
)
Evaluate a statement and cache the result before returning.
Statements are evaluated inside the Trimesh object, and
Parameters
statement : str Statement of valid python code *args : list Available inside statement as args[0], etc
Returns
result : result of running eval on statement with args
Examples
r = mesh.eval_cached('np.dot(self.vertices, args[0])', [0, 0, 1])
export
export(
file_obj=None, file_type=None, **kwargs
)
Export the current mesh to a file object. If file_obj is a filename, file will be written there.
Supported formats are stl, off, ply, collada, json, dict, glb, dict64, msgpack.
Parameters
file_obj: open writeable file object str, file name where to save the mesh None, if you would like this function to return the export blob file_type: str Which file type to export as. If file name is passed this is not required
fill_holes
fill_holes()
Fill single triangle and single quad holes in the current mesh.
Returns
watertight : bool Is the mesh watertight after the function completes
fix_normals
fix_normals(
*args, **kwargs
)
Find and fix problems with self.face_normals and self.faces winding direction.
For face normals ensure that vectors are consistently pointed outwards, and that self.faces is wound in the correct direction for all connected components.
Parameters
multibody : None or bool Fix normals across multiple bodies if None automatically pick from body_count
intersection
intersection(
other, engine=None, **kwargs
)
Boolean intersection between this mesh and n other meshes
Parameters
other : trimesh.Trimesh, or list of trimesh.Trimesh objects Meshes to calculate intersections with
Returns
intersection : trimesh.Trimesh Mesh of the volume contained by all passed meshes
invert
invert()
Invert the mesh inplace by reversing the winding of every face and negating normals without dumping the cache.
Alters self.faces
by reversing columns, and negating
self.face_normals
and self.vertex_normals
.
md5
md5()
An MD5 of the core geometry information for the mesh, faces and vertices.
Generated from TrackedArray which subclasses np.ndarray to monitor array for changes and returns a correct lazily evaluated md5 so it only has to recalculate the hash occasionally, rather than on every call.
Returns
md5 : string MD5 of everything in the DataStore
merge_vertices
merge_vertices(
**kwargs
)
If a mesh has vertices that are closer than trimesh.constants.tol.merge reindex faces to reference the same index for both vertices.
Parameters
mesh : Trimesh object Mesh to merge vertices on use_tex : bool If True for textured meshes merge vertices with identical positions AND UV coordinates. use_norm : bool If True meshes with vertex normals defined will only have vertices merged with identical normal digits_vertex : None or int Number of digits to consider for vertex position digits_norm : int Number of digits to consider for unit normals digits_uv : int Number of digits to consider for UV coordinates
outline
outline(
face_ids=None, **kwargs
)
Given a list of face indexes find the outline of those faces and return it as a Path3D.
The outline is defined here as every edge which is only included by a single triangle.
Note that this implies a nonwatertight mesh as the outline of a watertight mesh is an empty path.
Parameters
face_ids : (n, ) int Indices to compute the outline of. If None, outline of full mesh will be computed. **kwargs: passed to Path3D constructor
Returns
path : Path3D Curve in 3D of the outline
process
process(
validate=False, **kwargs
)
Do processing to make a mesh useful.
Does this by:
1) removing NaN and Inf values 2) merging duplicate vertices
If validate:
3) Remove triangles which have one edge of their rectangular 2D oriented bounding box shorter than tol.merge 4) remove duplicated triangles 5) ensure triangles are consistently wound and normals face outwards
Parameters
validate : bool If True, remove degenerate and duplicate faces
Returns
self: trimesh.Trimesh Current mesh
register
register(
other, **kwargs
)
Align a mesh with another mesh or a PointCloud using the principal axes of inertia as a starting point which is refined by iterative closest point.
Parameters
mesh : trimesh.Trimesh object Mesh to align with other other : trimesh.Trimesh or (n, 3) float Mesh or points in space samples : int Number of samples from mesh surface to align icp_first : int How many ICP iterations for the 9 possible combinations of icp_final : int How many ICP itertations for the closest candidate from the wider search
Returns
mesh_to_other : (4, 4) float Transform to align mesh to the other object cost : float Average square distance per point
remove_degenerate_faces
remove_degenerate_faces(
height=tol.merge
)
Remove degenerate faces (faces without 3 unique vertex indices) from the current mesh.
If a height is specified, it will remove any face with a 2D oriented bounding box with one edge shorter than that height.
If not specified, it will remove any face with a zero normal.
Parameters
height : float If specified removes faces with an oriented bounding box shorter than this on one side.
Returns
nondegenerate : (len(self.faces), ) bool Mask used to remove faces
remove_duplicate_faces
remove_duplicate_faces()
On the current mesh remove any faces which are duplicates.
Alters self.faces
to remove duplicate faces
remove_infinite_values
remove_infinite_values()
Ensure that every vertex and face consists of finite numbers. This will remove vertices or faces containing np.nan and np.inf
Alters self.faces
and self.vertices
remove_unreferenced_vertices
remove_unreferenced_vertices()
Remove all vertices in the current mesh which are not referenced by a face.
rezero
rezero()
Translate the mesh so that all vertex vertices are positive.
Alters self.vertices
.
sample
sample(
count, return_index=False
)
Return random samples distributed across the surface of the mesh
Parameters
count : int Number of points to sample return_index : bool If True will also return the index of which face each sample was taken from.
Returns
samples : (count, 3) float Points on surface of mesh face_index : (count, ) int Index of self.faces
scene
scene(
**kwargs
)
Returns a Scene object containing the current mesh.
Returns
scene : trimesh.scene.scene.Scene Contains just the current mesh
section
section(
plane_normal, plane_origin, **kwargs
)
Returns a 3D cross section of the current mesh and a plane defined by origin and normal.
Parameters
plane_normal: (3) vector for plane normal Normal vector of section plane plane_origin : (3, ) float Point on the cross section plane
Returns
intersections: Path3D or None Curve of intersection
section_multiplane
section_multiplane(
plane_origin, plane_normal, heights
)
Return multiple parallel cross sections of the current mesh in 2D.
Parameters
plane_normal: (3) vector for plane normal Normal vector of section plane plane_origin : (3, ) float Point on the cross section plane heights : (n, ) float Each section is offset by height along the plane normal.
Returns
paths : (n, ) Path2D or None 2D cross sections at specified heights. path.metadata['to_3D'] contains transform to return 2D section back into 3D space.
show
show(
**kwargs
)
Render the mesh in an opengl window. Requires pyglet.
Parameters
smooth : bool Run smooth shading on mesh or not, large meshes will be slow
Returns
scene : trimesh.scene.Scene Scene with current mesh in it
slice_plane
slice_plane(
plane_origin, plane_normal, cap=False, **kwargs
)
Slice the mesh with a plane, returning a new mesh that is the portion of the original mesh to the positive normal side of the plane
plane_origin : (3,) float Point on plane to intersect with mesh plane_normal : (3,) float Normal vector of plane to intersect with mesh cap : bool If True, cap the result with a triangulated polygon cached_dots : (n, 3) float If an external function has stored dot products pass them here to avoid recomputing
Returns
new_mesh: trimesh.Trimesh or None Subset of current mesh that intersects the half plane to the positive normal side of the plane
smoothed
smoothed(
*args, **kwargs
)
Return a version of the current mesh which will render nicely, without changing source mesh.
Parameters
angle : float or None
Angle in radians face pairs with angles
smaller than this will appear smoothed
facet_minarea : float or None
Minimum area fraction to consider
IE for facets_minarea=25
only facets larger
than mesh.area / 25
will be considered.
Returns
smoothed : trimesh.Trimesh Non watertight version of current mesh which will render nicely with smooth shading
split
split(
*args, **kwargs
)
Returns a list of Trimesh objects, based on face connectivity. Splits into individual components, sometimes referred to as 'bodies'
Parameters
only_watertight : bool Only return watertight meshes and discard remainder adjacency : None or (n, 2) int Override face adjacency with custom values
Returns
meshes : (n, ) trimesh.Trimesh Separate bodies from original mesh
subdivide
subdivide(
face_index=None
)
Subdivide a mesh, with each subdivided face replaced with four smaller faces.
Parameters
face_index: (m, ) int or None If None all faces of mesh will be subdivided If (m, ) int array of indices: only specified faces will be subdivided. Note that in this case the mesh will generally no longer be manifold, as the additional vertex on the midpoint will not be used by the adjacent faces to the faces specified, and an additional postprocessing step will be required to make resulting mesh watertight
submesh
submesh(
faces_sequence, **kwargs
)
Return a subset of the mesh.
Parameters
faces_sequence : sequence (m, ) int Face indices of mesh only_watertight : bool Only return submeshes which are watertight append : bool Return a single mesh which has the faces appended. if this flag is set, only_watertight is ignored
Returns
if append : trimesh.Trimesh object else : list of trimesh.Trimesh objects
to_dict
to_dict()
Return a dictionary representation of the current mesh, with keys that can be used as the kwargs for the Trimesh constructor, eg:
a = Trimesh(**other_mesh.to_dict())
Returns
result : dict With keys that match trimesh constructor
union
union(
other, engine=None, **kwargs
)
Boolean union between this mesh and n other meshes
Parameters
other : Trimesh or (n, ) Trimesh Other meshes to union engine : None or str Which backend to use
Returns
union : trimesh.Trimesh Union of self and other Trimesh objects
unmerge_vertices
unmerge_vertices()
Removes all face references so that every face contains three unique vertex indices and no faces are adjacent.
unwrap
unwrap(
**kwargs
)
Returns a Trimesh object equivalent to the current mesh where the vertices have been assigned uv texture coordinates.
The vertices may be split into as many as necessary by the unwrapping algorithm, depending on how many uv maps they appear in.
Requires blender.
Returns
unwrapped : trimesh.Trimesh Mesh with unwrapped uv coordinates
update_faces
update_faces(
mask
)
In many cases, we will want to remove specific faces. However, there is additional bookkeeping to do this cleanly. This function updates the set of faces with a validity mask, as well as keeping track of normals and colors.
Parameters
valid : (m) int or (len(self.faces)) bool Mask to remove faces
update_vertices
update_vertices(
mask, inverse=None
)
Update vertices with a mask.
Parameters
vertex_mask : (len(self.vertices)) bool Array of which vertices to keep inverse : (len(self.vertices)) int Array to reconstruct vertex references such as output by np.unique
voxelized
voxelized(
pitch, method='subdivide', **kwargs
)
Return a VoxelGrid object representing the current mesh discretized into voxels at the specified pitch
Parameters
pitch : float
The edge length of a single voxel
method: implementation key. See trimesh.voxel.creation.voxelizers
**kwargs: additional kwargs passed to the specified implementation.
Returns
voxelized : VoxelGrid object Representing the current mesh
__add__
__add__(
other
)
Concatenate the mesh with another mesh.
Parameters
other : trimesh.Trimesh object Mesh to be concatenated with self
Returns
concat : trimesh.Trimesh Mesh object of combined result
__radd__
__radd__(
other
)
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