newton.usd.get_mesh#

newton.usd.get_mesh(source: Prim | Stage | str | PathLike[str], load_normals: bool = False, load_uvs: bool = False, maxhullvert: int | None = None, face_varying_normal_conversion: Literal['vertex_averaging', 'angle_weighted', 'vertex_splitting'] = 'vertex_splitting', vertex_splitting_angle_threshold_deg: float = 25.0, preserve_facevarying_uvs: bool = False, return_uv_indices: Literal[False] = False, root_path: str | None = None, compute_inertia: bool = True, apply_stage_units: bool = True) Mesh[source]#
newton.usd.get_mesh(source: Prim, load_normals: bool = False, load_uvs: bool = False, maxhullvert: int | None = None, face_varying_normal_conversion: Literal['vertex_averaging', 'angle_weighted', 'vertex_splitting'] = 'vertex_splitting', vertex_splitting_angle_threshold_deg: float = 25.0, preserve_facevarying_uvs: bool = False, return_uv_indices: Literal[True] = True, root_path: None = None, compute_inertia: bool = True, apply_stage_units: bool = True) tuple[Mesh, ndarray | None]
newton.usd.get_mesh(source: None = None, load_normals: bool = False, load_uvs: bool = False, maxhullvert: int | None = None, face_varying_normal_conversion: Literal['vertex_averaging', 'angle_weighted', 'vertex_splitting'] = 'vertex_splitting', vertex_splitting_angle_threshold_deg: float = 25.0, preserve_facevarying_uvs: bool = False, return_uv_indices: Literal[False] = False, root_path: str | None = None, compute_inertia: bool = True, apply_stage_units: bool = True, *, prim: Prim) Mesh
newton.usd.get_mesh(source: None = None, load_normals: bool = False, load_uvs: bool = False, maxhullvert: int | None = None, face_varying_normal_conversion: Literal['vertex_averaging', 'angle_weighted', 'vertex_splitting'] = 'vertex_splitting', vertex_splitting_angle_threshold_deg: float = 25.0, preserve_facevarying_uvs: bool = False, return_uv_indices: Literal[True] = True, root_path: None = None, compute_inertia: bool = True, apply_stage_units: bool = True, *, prim: Prim) tuple[Mesh, ndarray | None]

Load a triangle mesh from a USD mesh prim, stage, file path, or URL.

When source is a mesh prim, the mesh is loaded in the prim’s local coordinates. When source is a stage, path, URL, or non-mesh prim, all UsdGeom.Mesh prims under root_path are merged into one newton.Mesh with authored transforms applied relative to that root.

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:
  • source – USD mesh prim, stage, file path, or URL to load the mesh from.

  • prim – Legacy keyword alias for source when loading a USD prim.

  • load_normals – Whether to load the normals.

  • load_uvs – Whether to load the UVs.

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

  • face_varying_normal_conversion

    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 – 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 vertex_splitting_angle_threshold_deg will be split into different vertex clusters. Lower = more splits (sharper), higher = fewer splits (smoother).

  • preserve_facevarying_uvs – If True, keep faceVarying UVs in their original corner layout and avoid UV-driven vertex splitting. The returned mesh keeps its original topology. This is useful when the caller needs the original UV indexing (e.g., panel-space cloth).

  • return_uv_indices – If True, return a tuple (mesh, uv_indices) where uv_indices is a flattened triangle index buffer for the UVs when available. For faceVarying UVs and preserve_facevarying_uvs=True, these indices reference the face-varying UV array. Only supported for a single UsdGeom.Mesh prim when root_path is None.

  • root_path – USD prim path to use as the merge root for stage, file path, URL, or non-mesh prim sources. Defaults to the stage pseudo-root for stages and paths, or the provided prim for non-mesh prim sources.

  • compute_inertia – If True, compute mass properties for the returned newton.Mesh.

  • apply_stage_units – If True, convert merged stage, file path, URL, or non-mesh prim sources from authored USD distance units to meters. Single mesh prim sources keep their authored coordinates for backward compatibility unless root_path is provided.

Returns:

The loaded mesh, or (mesh, uv_indices) if return_uv_indices is True.

Return type:

newton.Mesh