Python: Camera Scene Partitions#

This example renders three cameras from the same viewpoint: the left orange cube, the right blue torus, and both objects. All three views share the ground and studio environment.

Three cameras rendering the left cube, right torus, and both objects

Left only, right only, and both partitions, with shared ground and lighting.#

cd examples/python/camera-scene-partitions
uv run main.py
uv run main.py --rrd _output/camera-scene-partitions.rrd
uv run main.py --no-rr --png _output/camera-scene-partitions.png

The left and right cameras select left and right with omni:scenePartition. The third camera has no partition selector. The scene enables omni:rtx:scenePartitioning:showAllPartitionsByDefault on /Render/OmniverseGlobalRenderSettings so that camera sees both objects. Each RenderProduct sets omni:rtx:scenePartitioning:excludeBackgroundDomeLightInPartition to false to retain the shared studio lighting.

The snippet below shows how the example loads the authored scene, renders the left-only, right-only, and combined RenderProducts together, and maps each LdrColor output to CPU memory.

renderer = ovrtx.Renderer()
stage = ovstage.Stage("ovrtx.example.camera-scene-partitions")
renderer.attach_ovstage(stage)

ordinal = 1
ovstage.population.open_usd(
    stage,
    str(Path(__file__).with_name("scene_partitions.usda")),
    ordinal=ordinal,
)
stage.advance_write_floor(ordinal, ovstage.Scope.ALL).wait()

render_product_paths = ("/Render/Left", "/Render/Right", "/Render/Both")
products = None
for _ in range(40):
    products = renderer.step(
        render_products=set(render_product_paths),
        delta_time=1.0 / 60.0,
        ordinal=ordinal,
    )

# Verify every partition camera produced output before accessing its first frame.
if not all(products[path].frames for path in render_product_paths):
    raise RuntimeError("Not all scene-partition cameras produced an image")

images = {}
for render_product_path in render_product_paths:
    frame = products[render_product_path].frames[0]
    mapped = frame.render_vars["/Render/LdrColor"].map(device=ovrtx.Device.CPU)
    images[render_product_path] = np.from_dlpack(mapped).copy()
    del mapped, frame

See Scene Partitions for the visibility rules.