Extension: omni.kit.scene_view.usd-1.2.3

Documentation Generated: Dec 17, 2024

Overview#

The OpenUSD Scene View extension is an alternative renderer for the omni.ui.scene.SceneView system, that uses USD Primitives to draw the various elements instead of the primitives provided by OmniUI.

There are however a few key differences.

Viewport Only#

One key difference is that because USD Primitives are used, they only really make sense as part of the viewport, and

Mouse Gestures#

To enable mouse gesture support, you’ll need to add to your kit file.

[settings]
exts."omni.kit.scene_view.usd".use_mouse_input = true

Or use the following python snippet:

import carb.settings

carb.settings.get_settings().set("/exts/omni.kit.scene_view.usd/use_mouse_input", True)

Examples#

Example demonstrates drawing some simple shapes and lines. This is effectively identical to using omni.ui.scene.SceneView.

from math import pi
from omni.ui import scene as sc, color as cl
from omni.kit.viewport.utility import get_active_viewport_window
from omni.kit.scene_view.usd import UsdSceneView

if (win := get_active_viewport_window()):
    with win.get_frame("usd_scene"):
        # UsdSceneView() is used in place of sc.SceneView()
        s = UsdSceneView()
        win.viewport_api.add_scene_view(s)
        # Otherwise the rest of the code remains unchanged
        with s.scene:
            with sc.Transform():
                with sc.Transform(transform=sc.Matrix44.get_translation_matrix(50, 50, 50)):
                    sc.Arc(100, begin=0, end=pi*2, wireframe=True, thickness=10, color=cl.yellow)
                    sc.Arc(100, begin=0, end=pi*2, wireframe=False, thickness=10, color=cl.yellow)
                    sc.Arc(50, begin=0, end=pi, wireframe=True, thickness=10, color=cl.red)

                with sc.Transform(transform=sc.Matrix44.get_translation_matrix(-100, 0, 0)):
                    sc.Arc(100, begin=0, end=pi*2, wireframe=True, thickness=10, color=cl.yellow)
                    sc.Arc(100, begin=0, end=pi*2, wireframe=False, thickness=10, color=cl.yellow)
                    sc.Arc(50, begin=0, end=pi, wireframe=True, thickness=10, color=cl.red)

Example of using mouse gestures. Shows how to enable mouse input, and how you can disable selection on the underlying primitives.

import asyncio
from omni.ui import scene as sc, color as cl
from omni.kit.viewport.utility import get_active_viewport_window
from omni.kit.scene_view.usd import UsdSceneView
import omni.usd

import carb.settings

carb.settings.get_settings().set("/exts/omni.kit.scene_view.usd/use_mouse_input", True)

if (win := get_active_viewport_window()):
    with win.get_frame("usd_scene"):
        # UsdSceneView() is used in place of sc.SceneView()
        s = UsdSceneView()
        win.viewport_api.add_scene_view(s)
        # Otherwise the rest of the code remains unchanged
        with s.scene:
            sc.Line(
                [-1, 0, 0],
                [1, 0, 0],
                color=cl.blue,
                thickness=5,
                gesture=[
                    sc.ClickGesture(
                        on_ended_fn=lambda shape: print(f"Clicked on {shape}")
                    ),
                    # Hover gesture blocks the shape from being picked with the selection tool.
                    sc.HoverGesture(
                        on_began_fn=lambda shape: omni.usd.get_context().set_pickable(s.get_base_path(), False),
                        on_changed_fn=lambda shape: print(f"Hovered over {shape}"),
                        on_ended_fn=lambda shape: omni.usd.get_context().set_pickable(s.get_base_path(), True)
                    )]
            )