Skip to content

Mesh

voxel.Mesh(vertices, faces)

A triangular mesh in 3D world space.

Parameters:

  • vertices (Tensor) –

    Vertex coordinates of shape (V, 3).

  • faces (Tensor) –

    Triangular face integer indices of shape (F, 3).

vertices: torch.Tensor property writable

Point positions represented by a (V, 3) tensor.

faces: torch.Tensor property writable

Triangle faces represented by a (F, 3) tensor.

num_vertices: int property

Total number of vertices in the mesh.

num_faces: int property

Total number of faces in the mesh.

device: torch.device property

The device of the mesh vertex and face tensors.

triangles: torch.Tensor property

Triangle coordinate array with shape (F, 3, 3).

triangles_cross: torch.Tensor property

Vertex cross-product with shape (F, 3).

edges: torch.Tensor property

All directional edges in the mesh, with shape (E, 2). Note these are not unique.

uniform_laplacian: torch.Tensor property

The sparse uniform Laplacian matrix for the mesh connectivity. Note that it is generally faster to use the gather() or smooth_features() methods for diffusing features on the mesh graph.

edge_face: torch.Tensor property

Face indices corresponding to each directional edge in the mesh, with shape (E,).

unique_edge_indices: tuple property

Indices that extract all unique edges from the directional edge list.

unique_edges: torch.Tensor property

Unique bi-directional edges in the mesh, with shape (U, 2).

adjacent_faces: torch.Tensor property

Adjacent face indices corresponding to each edge in unique_edges.

face_normals: torch.Tensor property

Face (unit) normals with shape (F, 3).

face_areas: torch.Tensor property

Face areas with shape (F,)

face_angles: torch.Tensor property

Face angles (in radians) with shape (F, 3).

vertex_normals: torch.Tensor property

Vertex (unit) normals, computed from face normals weighted by their angle.

vertex_areas: torch.Tensor property

The total face surface area contributed to each vertex.

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 (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, default: None ) –

    The format of the file. If None, the format is determined by the file extension.

  • **kwargs (Any, default: {} ) –

    Additional arguments passed to the file writing method.

flip_faces() -> vx.Mesh

Flip triangular face directions.

gather(features, reduce='mean') -> torch.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, default: 'mean' ) –

    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.

Parameters:

  • alpha (float, default: 0.5 ) –

    Smoothing factor between 0 and 1. Defaults to 0.5.

  • iterations (int, default: 1 ) –

    Number of smoothing iterations. Defaults to 1.

Returns:

  • Mesh

    Smoothed mesh.

smooth_features(features, alpha=0.5, iterations=1) -> torch.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:

  • features (Tensor) –

    Input features to smooth of the shape \((V,)\) or \((V, C)\).

  • alpha (float, default: 0.5 ) –

    Smoothing factor between 0 and 1. Defaults to 0.5.

  • iterations (int, default: 1 ) –

    Number of smoothing iterations. Defaults to 1.

Returns:

  • Tensor

    Smoothed features matching the input shape.

transform(transform) -> Mesh

Transform mesh vertex coordinates with an affine matrix.

Parameters:

Returns:

  • Mesh

    Transformed mesh.

bounds(margin=None, *components) -> vx.BoundingBox

Compute the axis-aligned bounding box enclosing the mesh vertices.

Parameters:

  • margin (float or Tensor, default: None ) –

    Margin (in vertex units) to expand the bounds. Can be a positive or negative delta.

  • *components (float, default: () ) –

    Additional components of margin, allowing values to be passed as separate positional arguments, e.g. bounds(1, 2, 3).

Returns:

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) -> torch.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, default: 1 ) –

    The top k largest components to include. Defaults to 1.

Returns:

  • Tensor

    A boolean vertex mask representing vertices in the top k components.