newton.TetMesh#

class newton.TetMesh(vertices, tet_indices, k_mu=None, k_lambda=None, k_damp=None, density=None, custom_attributes=None)[source]#

Bases: object

Represents a tetrahedral mesh for volumetric deformable simulation.

Stores vertex positions (surface + interior nodes), tetrahedral element connectivity, and an optional surface triangle mesh. If no surface mesh is provided, it is automatically computed from the open (unshared) faces of the tetrahedra.

Optionally carries per-element material arrays and a density value loaded from file. These are used as defaults by builder methods and can be overridden at instantiation time.

Example

Create a TetMesh from raw arrays:

import numpy as np
import newton

vertices = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.float32)
tet_indices = np.array([0, 1, 2, 3], dtype=np.int32)
tet_mesh = newton.TetMesh(vertices, tet_indices)
static compute_surface_triangles(tet_indices)#

Extract boundary triangles from tetrahedral element indices.

Finds faces that belong to exactly one tetrahedron (boundary faces) using a vectorized approach.

Parameters:

tet_indices (ndarray) – Flattened tetrahedral element indices (4 per tet).

Returns:

Flattened boundary triangle indices, 3 per triangle, int32.

Return type:

ndarray

static create_from_file(filename)#

Load a TetMesh from a volumetric mesh file.

Supports .vtk, .msh, .vtu, and other formats with tetrahedral cells via meshio. Also supports .npz files saved by TetMesh.save() (numpy only, no extra dependencies).

Parameters:

filename (str) – Path to the volumetric mesh file.

Returns:

A new TetMesh instance.

Return type:

TetMesh

static create_from_usd(prim)#

Load a tetrahedral mesh from a USD prim with the UsdGeom.TetMesh schema.

Reads vertex positions from the points attribute and tetrahedral connectivity from tetVertexIndices. If a physics material is bound to the prim (via material:binding:physics) and contains youngsModulus, poissonsRatio, or density attributes (under the omniphysics: or physxDeformableBody: namespaces), those values are read and converted to Lame parameters (k_mu, k_lambda) and density on the returned TetMesh. Material properties are set to None if not present.

Example

from pxr import Usd
import newton
import newton.usd

usd_stage = Usd.Stage.Open("tetmesh.usda")
tetmesh = newton.usd.get_tetmesh(usd_stage.GetPrimAtPath("/MyTetMesh"))

# tetmesh.vertices  -- np.ndarray, shape (N, 3)
# tetmesh.tet_indices -- np.ndarray, flattened (4 per tet)
Parameters:

prim – The USD prim to load the tetrahedral mesh from.

Returns:

A newton.TetMesh with vertex positions and tet connectivity.

Return type:

TetMesh

__init__(vertices, tet_indices, k_mu=None, k_lambda=None, k_damp=None, density=None, custom_attributes=None)#

Construct a TetMesh from vertex positions and tet connectivity.

Parameters:
  • vertices (Sequence[list[float] | tuple[float, float, float] | vec3f] | ndarray) – Vertex positions [m], shape (N, 3).

  • tet_indices (Sequence[int] | ndarray) – Tetrahedral element indices, flattened (4 per tet).

  • k_mu (ndarray | float | None) – First elastic Lame parameter [Pa]. Scalar (uniform) or per-element array of shape (tet_count,).

  • k_lambda (ndarray | float | None) – Second elastic Lame parameter [Pa]. Scalar (uniform) or per-element array of shape (tet_count,).

  • k_damp (ndarray | float | None) – Rayleigh damping coefficient [-] (dimensionless). Scalar (uniform) or per-element array of shape (tet_count,).

  • density (float | None) – Uniform density [kg/m^3] for mass computation.

  • custom_attributes (dict[str, np.ndarray] | dict[str, tuple[np.ndarray, Model.AttributeFrequency]] | None) – Dictionary of named custom arrays with their AttributeFrequency. Each value can be either a bare array (frequency auto-inferred from length) or a (array, frequency) tuple.

save(filename)#

Save the TetMesh to a file.

For .npz, saves all arrays via numpy.savez() (no extra dependencies). For other formats (.vtk, .msh, .vtu, etc.), uses meshio.

Parameters:

filename (str) – Path to write the file to.

property density: float | None#

Uniform density [kg/m^3] or None.

property k_damp: ndarray | None#

Per-element Rayleigh damping coefficient [-], shape (tet_count,) or None.

property k_lambda: ndarray | None#

Per-element second Lame parameter [Pa], shape (tet_count,) or None.

property k_mu: ndarray | None#

Per-element first Lame parameter [Pa], shape (tet_count,) or None.

property surface_tri_indices: ndarray#

Surface triangle indices (open faces), flattened, 3 per tri.

Automatically computed from tet connectivity at construction time by extracting boundary faces (faces belonging to exactly one tet).

property tet_count: int#

Number of tetrahedral elements.

property tet_indices: ndarray#

Tetrahedral element indices, flattened, 4 per tet.

property vertex_count: int#

Number of vertices.

property vertices: ndarray#

Vertex positions [m], shape (N, 3), float32.