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: 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=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_inertia is True. This computation is only valid if the mesh is closed (two-manifold).

Parameters:
compute_convex_hull(replace=False)#

Compute and return the convex hull of this mesh.

Parameters:

replace (bool) – If True, replace this mesh’s vertices/indices with the convex hull (in-place). If False, return a new Mesh for the convex hull.

Returns:

The convex hull mesh (either new or self, depending on replace).

Return type:

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.

finalize(device=None, requires_grad=False)#

Construct a simulation-ready Warp Mesh object from the mesh data and return its ID.

Parameters:
  • device (Device | str | None) – Device on which to allocate mesh buffers.

  • requires_grad (bool) – If True, mesh points and velocities are allocated with gradient tracking.

Returns:

The ID of the simulation-ready Warp Mesh.

Return type:

uint64

MAX_HULL_VERTICES = 64#