Mesh#
- class voxel.Mesh(vertices, faces)#
A triangular mesh in 3D world space.
- new(vertices) Mesh#
Construct a new mesh instance with the provided vertices, while preserving any unchanged properties of the original.
- Parameters:
vertices (Tensor) – The new vertices tensor replacement.
- to(device) Mesh#
Move the mesh (vertex and face tensors) to a device.
- Parameters:
device (device) – The target device.
- Returns:
Mesh – A new mesh instance.
- cpu() Mesh#
Move the mesh vertex and face tensors to the CPU.
- Returns:
Mesh – A new mesh instance with the data on the CPU.
- cuda() Mesh#
Move the mesh vertex and face tensors to the GPU.
- Returns:
Mesh – A new mesh instance with the data on the GPU.
- type(dtype) Mesh#
Cast the mesh vertices to a new data type.
- Parameters:
dtype (torch.dtype) – The target vertex data type.
- Returns:
Mesh – A new mesh instance with the casted vertices.
- save(filename, fmt=None, **kwargs) None#
Save the mesh to a file.
- Parameters:
filename (PathLike) – The path to the file to save.
fmt (str, optional) – The format of the file. If None, the format is determined by the file extension.
**kwargs (Any) – Additional arguments passed to the file writing method.
- property edges: Tensor#
All directional edges in the mesh, with shape (E, 2). Note these are not unique.
- property uniform_laplacian: Tensor#
The sparse uniform Laplacian matrix for the mesh connectivity. Note that it is generally faster to use the
gather()orsmooth_features()methods for diffusing features on the mesh graph.
- property edge_face: Tensor#
Face indices corresponding to each directional edge in the mesh, with shape (E,).
- property unique_edge_indices: tuple#
Indices that extract all unique edges from the directional edge list.
- property vertex_normals: Tensor#
Vertex (unit) normals, computed from face normals weighted by their angle.
- gather(features, reduce='mean') Tensor#
Gather and reduce neighboring vertex features across mesh edges, i.e. for each vertex, combine the features of its adjacent vertices.
- Parameters:
features (Tensor) – Per-vertex features of shape \((V, C)\).
reduce (str, optional) – Reduction applied over each vertex’s neighbors, e.g. ‘mean’, ‘sum’, ‘amax’, or ‘amin’. Defaults to ‘mean’.
- Returns:
Tensor – Reduced per-vertex features matching the input shape.
- smooth_mesh(alpha=0.5, iterations=1) Mesh#
Smooth the mesh vertex positions with the uniform Laplacian operator.
- smooth_features(features, alpha=0.5, iterations=1) Tensor#
Smooth vertex features with the uniform Laplacian operator. Note that this does not actually use the sparse Laplacian matrix, but rather the vertex gather method, which is roughly 2x faster.
- Parameters:
- Returns:
Tensor – Smoothed features matching the input shape.
- transform(transform) Mesh#
Transform mesh vertex coordinates with an affine matrix.
- Parameters:
transform (AffineMatrix) – Affine transformation.
- Returns:
Mesh – Transformed mesh.
- bounds(margin=None, *components) BoundingBox#
Compute the axis-aligned bounding box enclosing the mesh vertices.
- Parameters:
- Returns:
BoundingBox – Bounding box enclosing the vertices.
- extract_submesh(vertex_mask) Mesh#
Extract a submesh containing only the vertices included in an input mask.
- Parameters:
vertex_mask (Tensor) – A boolean vertex mask indicating which vertices to include in the submesh.
- Returns:
Mesh – Extracted mesh with a subset of vertices and remapped face indices.
- largest_connected_components(k=1) Tensor#
Compute a mask indicating the top k largest connected components in the mesh graph, where ‘largest’ is defined by number of vertices. This method uses scipy under the hood and therefore runs on the CPU.
- Parameters:
k (int, optional) – The top k largest components to include. Defaults to 1.
- Returns:
Tensor – A boolean vertex mask representing vertices in the top k components.