newton.Mesh#
- class newton.Mesh(vertices, indices, normals=None, uvs=None, compute_inertia=True, is_solid=True, maxhullvert=MESH_MAXHULLVERT, color=None)[source]#
Bases:
object
Represents 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=MESH_MAXHULLVERT, color=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_inertia is True. This computation is only valid if the mesh is closed (two-manifold).
- Parameters:
vertices (Sequence[Vec3] | nparray) – List or array of mesh vertices, shape (N, 3).
indices (Sequence[int] | nparray) – Flattened list or array of triangle indices (3 per triangle).
normals (Sequence[Vec3] | nparray | None, optional) – Optional per-vertex normals, shape (N, 3).
uvs (Sequence[Vec2] | nparray | None, optional) – Optional per-vertex UVs, shape (N, 2).
compute_inertia (bool, optional) – If True, compute mass, inertia tensor, and center of mass (default: True).
is_solid (bool, optional) – If True, mesh is assumed solid for inertia computation (default: True).
maxhullvert (int, optional) – Max vertices for convex hull approximation (default: 64).
color (Vec3 | None, optional) – Optional per-mesh base color (values in [0, 1]).
- 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:
- Returns:
A new Mesh object with the specified properties.
- Return type:
- finalize(device=None, requires_grad=False)#
Construct a simulation-ready Warp Mesh object from the mesh data and return its ID.
- Parameters:
device (Devicelike, optional) – Device on which to allocate mesh buffers.
requires_grad (bool, optional) – If True, mesh points and velocities are allocated with gradient tracking.
- Returns:
The ID of the simulation-ready Warp Mesh.
- Return type:
wp.uint64