newton.TetMesh#
- class newton.TetMesh(vertices, tet_indices, k_mu=None, k_lambda=None, k_damp=None, density=None, custom_attributes=None)[source]#
Bases:
objectRepresents 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.
- 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.npzfiles saved byTetMesh.save()(numpy only, no extra dependencies).
- static create_from_usd(prim)#
Load a tetrahedral mesh from a USD prim with the
UsdGeom.TetMeshschema.Reads vertex positions from the
pointsattribute and tetrahedral connectivity fromtetVertexIndices. If a physics material is bound to the prim (viamaterial:binding:physics) and containsyoungsModulus,poissonsRatio, ordensityattributes (under theomniphysics:orphysxDeformableBody:namespaces), those values are read and converted to Lame parameters (k_mu,k_lambda) and density on the returned TetMesh. Material properties are set toNoneif 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.TetMeshwith vertex positions and tet connectivity.- Return type:
- __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 vianumpy.savez()(no extra dependencies). For other formats (.vtk,.msh,.vtu, etc.), uses meshio.- Parameters:
filename (str) – Path to write the file to.
- 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.