newton.Mesh#

class newton.Mesh(vertices, indices, compute_inertia=True, is_solid=True)#

Describes a triangle collision mesh for simulation

Example mesh creation from a triangle OBJ mesh file:#

See load_mesh() which is provided as a utility function.

import numpy as np
import warp as wp
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)
vertices#

Mesh 3D vertices points

Type:

List[Vec3]

indices#

Mesh indices as a flattened list of vertex indices describing triangles

Type:

List[int]

I#

3x3 inertia matrix of the mesh assuming density of 1.0 (around the center of mass)

Type:

Mat33

mass#

The total mass of the body assuming density of 1.0

Type:

float

com#

The center of mass of the body

Type:

Vec3

Methods

__init__(vertices, indices[, ...])

Construct a Mesh object from a triangle mesh

finalize([device, requires_grad])

Constructs a simulation-ready Mesh object from the mesh data and returns its ID.

__init__(vertices, indices, compute_inertia=True, is_solid=True)#

Construct a Mesh object from a triangle mesh

The mesh center of mass and inertia tensor will automatically be calculated using a density of 1.0. This computation is only valid if the mesh is closed (two-manifold).

Parameters:
  • vertices (Sequence[list[float] | tuple[float, float, float] | vec3f]) – List of vertices in the mesh

  • indices (Sequence[int]) – List of triangle indices, 3 per-element

  • compute_inertia – If True, the mass, inertia tensor and center of mass will be computed assuming density of 1.0

  • is_solid – If True, the mesh is assumed to be a solid during inertia computation, otherwise it is assumed to be a hollow surface

finalize(device=None, requires_grad=False)#

Constructs a simulation-ready Mesh object from the mesh data and returns its ID.

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

  • requires_grad (bool) – If True, the mesh points and velocity arrays will be allocated with gradient tracking enabled

Returns:

The ID of the simulation-ready Mesh

Return type:

uint64