Skip to content

newton_visuals

USD visual mesh import for the Newton physics backend.

Bake visual-only shapes into the simulation stage in physics_backends.newton_backend.NewtonBackend.

VisualImportResult dataclass

Summary of render-only visual shapes added to a Newton builder.

Source code in OmniGibson/omnigibson/physics_backends/newton_visuals.py
@dataclass(frozen=True)
class VisualImportResult:
    """Summary of render-only visual shapes added to a Newton builder."""

    shape_indices: tuple
    body_indices: tuple
    mesh_sources: tuple

add_usd_visual_shapes(newton, builder, stage, root_path, path_body_map, *, label_prefix=None)

Add USD meshes (under root_path on the current stage) as render-only shapes.

Source code in OmniGibson/omnigibson/physics_backends/newton_visuals.py
def add_usd_visual_shapes(newton, builder, stage, root_path, path_body_map, *, label_prefix=None):
    """Add USD meshes (under ``root_path`` on the current stage) as render-only shapes."""
    visual_shape_indices = []
    visual_body_indices = []
    visual_mesh_sources = []

    visual_cfg = newton.ModelBuilder.ShapeConfig(
        has_shape_collision=False,
        has_particle_collision=False,
        is_visible=True,
        is_solid=True,
        density=0.0,
    )

    root_prim = stage.GetPrimAtPath(root_path)
    for prim in Usd.PrimRange(root_prim):
        if prim.GetTypeName() != "Mesh":
            continue
        if _is_enabled_collider(prim) or not _is_effectively_visible(prim) or not _has_render_purpose(prim):
            continue

        body_path = _nearest_imported_body_path(prim, path_body_map)
        if body_path is None:
            continue

        body_idx = path_body_map[body_path]
        xform, scale = _mesh_xform_relative_to_body(prim, body_idx, body_path)
        # Bake scale into the mesh points
        meshes = _load_render_meshes(newton, prim, scale)
        if not meshes:
            continue

        for mesh_label, mesh in meshes:
            label = str(prim.GetPath())
            if mesh_label:
                label = f"{label}/{mesh_label}"
            if label_prefix:
                label = f"{label_prefix}/{label}"
            shape_idx = builder.add_shape_mesh(
                body_idx,
                xform=xform,
                mesh=mesh,
                cfg=visual_cfg,
                color=_viewer_color_for_mesh(mesh),
                label=label,
            )
            visual_shape_indices.append(shape_idx)
            visual_body_indices.append(body_idx)
            visual_mesh_sources.append(mesh)

    return VisualImportResult(tuple(visual_shape_indices), tuple(visual_body_indices), tuple(visual_mesh_sources))