newton.Mesh#
- class newton.Mesh(vertices, indices, normals=None, uvs=None, compute_inertia=True, is_solid=True, maxhullvert=None, color=None, roughness=None, metallic=None, texture=None)[source]#
Bases:
objectRepresents a triangle mesh for collision and simulation.
This class encapsulates a triangle mesh, including its geometry, physical properties, and utility methods for simulation. Meshes are typically used for collision detection, visualization, and inertia computation in physics simulation.
Example
Load a mesh from an OBJ file using OpenMesh and create a Newton Mesh:
import numpy as np import newton import openmesh m = openmesh.read_trimesh("mesh.obj") mesh_points = np.array(m.points()) mesh_indices = np.array(m.face_vertex_indices(), dtype=np.int32).flatten() mesh = newton.Mesh(mesh_points, mesh_indices)
- __init__(vertices, indices, normals=None, uvs=None, compute_inertia=True, is_solid=True, maxhullvert=None, color=None, roughness=None, metallic=None, texture=None)#
Construct a Mesh object from a triangle mesh.
The mesh’s center of mass and inertia tensor are automatically calculated using a density of 1.0 if
compute_inertiais True. This computation is only valid if the mesh is closed (two-manifold).- Parameters:
vertices (Sequence[list[float] | tuple[float, float, float] | vec3f] | ndarray[Any, dtype[Any]]) – List or array of mesh vertices, shape (N, 3).
indices (Sequence[int] | ndarray[Any, dtype[Any]]) – Flattened list or array of triangle indices (3 per triangle).
normals (Sequence[list[float] | tuple[float, float, float] | vec3f] | ndarray[Any, dtype[Any]] | None) – Optional per-vertex normals, shape (N, 3).
uvs (Sequence[list[float] | tuple[float, float] | vec2f] | ndarray[Any, dtype[Any]] | None) – Optional per-vertex UVs, shape (N, 2).
compute_inertia (bool) – If True, compute mass, inertia tensor, and center of mass (default: True).
is_solid (bool) – If True, mesh is assumed solid for inertia computation (default: True).
maxhullvert (int | None) – Max vertices for convex hull approximation (default:
MAX_HULL_VERTICES).color (list[float] | tuple[float, float, float] | vec3f | None) – Optional per-mesh base color (values in [0, 1]).
roughness (float | None) – Optional mesh roughness in [0, 1].
metallic (float | None) – Optional mesh metallic in [0, 1].
texture (str | ndarray[Any, dtype[Any]] | None) – Optional texture path/URL or image data (H, W, C).
- compute_convex_hull(replace=False)#
Compute and return the convex hull of this mesh.
- copy(vertices=None, indices=None, recompute_inertia=False)#
Create a copy of this mesh, optionally with new vertices or indices.
- Parameters:
vertices (Sequence[list[float] | tuple[float, float, float] | vec3f] | ndarray[Any, dtype[Any]] | None) – New vertices to use (default: current vertices).
indices (Sequence[int] | ndarray[Any, dtype[Any]] | None) – New indices to use (default: current indices).
recompute_inertia (bool) – If True, recompute inertia properties (default: False).
- Returns:
A new Mesh object with the specified properties.
- finalize(device=None, requires_grad=False)#
Construct a simulation-ready Warp Mesh object from the mesh data and return its ID.
- MAX_HULL_VERTICES = 64#