newton.usd.get_mesh#
- newton.usd.get_mesh(source: Usd.Prim | Usd.Stage | str | os.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, load_visual_materials: bool = True) Mesh[source]#
- newton.usd.get_mesh(source: Usd.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, load_visual_materials: bool = True) tuple[Mesh, np.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: Usd.Prim, load_visual_materials: bool = True) 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: Usd.Prim, load_visual_materials: bool = True) tuple[Mesh, np.ndarray | None]
Load a triangle mesh from a USD mesh prim, stage, file path, or URL.
When
sourceis a mesh prim, the mesh is loaded in the prim’s local coordinates. Whensourceis a stage, path, URL, or non-mesh prim, allUsdGeom.Meshprims underroot_pathare merged into onenewton.Meshwith authored transforms applied relative to that root.With
load_normals=True, shading is resolved to per-vertex normals on the triangulated mesh. Missing normals are faceted fornoneandbilinearsubdivision schemes and smooth otherwise. Faceted shading duplicates triangle vertices. Source subdivision control surfaces are not evaluated or retained; viewers receive final triangles and normals. Useload_normals=Falsefor geometry-only loading without normal-driven vertex splitting.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
sourcewhen loading a USD prim.load_normals – Whether to load authored normals or generate missing normals and convert them to the per-vertex representation used by
Mesh. This may split vertices to represent sharp shading.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 authored “uniform” or “faceVarying” normals (normals defined per-corner rather than per-vertex) into per-vertex normals for the mesh. If
load_normalsis 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 authored uniform or faceVarying normals when
face_varying_normal_conversionis “vertex_splitting”. Corners whose normals differ by more thanvertex_splitting_angle_threshold_degwill 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 can still split vertices for normals when
load_normals=True. 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)whereuv_indicesis a flattened triangle index buffer for the UVs when available. For faceVarying UVs andpreserve_facevarying_uvs=True, these indices reference the face-varying UV array. Only supported for a singleUsdGeom.Meshprim whenroot_pathis 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_pathis provided.load_visual_materials – If True, resolve the mesh’s visual material and populate
newton.Mesh.color,newton.Mesh.texture,newton.Mesh.metallic, andnewton.Mesh.roughness. Resolution also covers materials bound through an instance prototype or aUsdGeom.Subsetchild, and thedisplayColorprimvar fallback. If False, those attributes keep theirnewton.Meshdefaults; set it to False when only mesh geometry is needed. Ifload_uvsis True, the material’s shader network may still be inspected to select the UV primvar used by the texture.
- Returns:
The loaded mesh, or
(mesh, uv_indices)ifreturn_uv_indicesis True.- Return type: