newton.usd.get_mesh#

newton.usd.get_mesh(prim, load_normals=False, load_uvs=False, maxhullvert=MESH_MAXHULLVERT, face_varying_normal_conversion='vertex_averaging', vertex_splitting_angle_threshold_deg=25.0, verbose=False)[source]#

Load a triangle mesh from a USD prim that has the UsdGeom.Mesh schema.

Example

from pxr import Usd
import newton.examples
import newton.usd

usd_stage = Usd.Stage.Open(newton.examples.get_asset("bunny.usd"))
demo_mesh = newton.usd.get_mesh(usd_stage.GetPrimAtPath("/root/bunny"), load_normals=True)

builder = newton.ModelBuilder()
body_mesh = builder.add_body()
builder.add_shape_mesh(body_mesh, mesh=demo_mesh)

assert len(demo_mesh.vertices) == 6102
assert len(demo_mesh.indices) == 36600
assert len(demo_mesh.normals) == 6102
Parameters:
  • prim (Usd.Prim) – The USD prim to load the mesh from.

  • load_normals (bool) – Whether to load the normals.

  • load_uvs (bool) – Whether to load the UVs.

  • maxhullvert (int) – The maximum number of vertices for the convex hull approximation.

  • face_varying_normal_conversion (Literal["vertex_averaging", "angle_weighted", "vertex_splitting"]) –

    This argument specifies how to convert “faceVarying” normals (normals defined per-corner rather than per-vertex) into per-vertex normals for the mesh. If load_normals is False, this argument is ignored. The options are summarized below:

    Method

    Description

    "vertex_averaging"

    For each vertex, averages all the normals of the corners that share that vertex. This produces smooth shading except at explicit vertex splits. This method is the most efficient.

    "angle_weighted"

    For each vertex, computes a weighted average of the normals of the corners it belongs to, using the corner angle as a weight (i.e., larger face angles contribute more), for more visually-accurate smoothing at sharp edges.

    "vertex_splitting"

    Splits a vertex into multiple vertices if the difference between the corner normals exceeds a threshold angle (see vertex_splitting_angle_threshold_deg). This preserves sharp features by assigning separate (duplicated) vertices to corners with widely different normals.

  • vertex_splitting_angle_threshold_deg (float) – The threshold angle in degrees for splitting vertices based on the face normals in case of faceVarying normals and face_varying_normal_conversion is “vertex_splitting”. Corners whose normals differ by more than angle_deg will be split into different vertex clusters. Lower = more splits (sharper), higher = fewer splits (smoother).

  • verbose (bool) – Whether to print verbose output for debugging.

Returns:

The loaded mesh.

Return type:

newton.Mesh