### CameraModel Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Illustrates creating a CameraModel and SceneView with a custom orthographic projection matrix. ```python proj = [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 2e-7, 0, 0, 0, 1, 1] camera = sc.CameraModel(proj, 1) scene_view = sc.SceneView(camera, aspect_ratio_policy=...) ``` -------------------------------- ### Create Line with Gestures Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Example of creating a 3D line segment with specified start and end points, color, thickness, and associated gesture handlers. ```python sc.Line( [-50, 0, 0], [50, 0, 0], color=ui.color.beige, thickness=10, gestures=[ sc.ClickGesture(...), sc.DoubleClickGesture(...), Move(transform, manager=manager) ] ) ``` -------------------------------- ### Instantiate GestureWindowExample Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/api-reference/omni_example_gesture_window.md Creates and displays a GestureWindowExample window with specified dimensions. This is the primary way to launch the example. ```python from omni.example.gesture_window.window import GestureWindowExample window = GestureWindowExample("Gesture Example", width=500, height=500) # Window is created and displayed with scene view content ``` -------------------------------- ### Window Gesture Integration Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md This example shows how to integrate gestures within a custom UI window. It defines a SceneView and adds gesture recognizers to UI elements within the scene. ```python # extension.py import omni.ext from .window import GestureWindowExample class OmniExampleGestureExtension(omni.ext.IExt): def on_startup(self, ext_id): self._window = GestureWindowExample("Gesture Example", width=500, height=500) def on_shutdown(self): if self._window: self._window.destroy() self._window = None ``` ```python # window.py from omni.ui import scene as sc import omni.ui as ui proj = [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 2e-7, 0, 0, 0, 1, 1] class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs): super().__init__(title, **kwargs) self.label = None self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: with ui.VStack(): self.label = ui.Label("Sender: None\nAction: None") scene_view = sc.SceneView( sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT ) with scene_view.scene: sc.Rectangle( 2, 2, color=ui.color.beige, gestures=[ sc.ClickGesture(lambda s: setcolor(s, ui.color.blue)), sc.HoverGesture(on_began_fn=lambda s: setcolor(s, ui.color.black)) ] ) def print_action(self, sender, action): self.label.text = f"Sender: {sender}\nAction: {action}" ``` -------------------------------- ### GestureState Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Shows how to check the current state of a gesture to execute different logic. ```python from omni.ui import scene as sc if gesture.state == sc.GestureState.BEGAN: print("Gesture just started") elif gesture.state == sc.GestureState.CHANGED: print("Gesture in progress") elif gesture.state == sc.GestureState.ENDED: print("Gesture completed") ``` -------------------------------- ### Window Gesture Manager Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Implement a custom gesture manager for windows. This example prevents unnamed gestures when a named gesture begins. ```python class Manager(sc.GestureManager): def should_prevent(self, gesture: AbstractGesture, preventer: AbstractGesture) -> bool: # Prevent unnamed gestures when named gestures start if gesture.name != "gesture_name" and preventer.state == sc.GestureState.BEGAN: return True return False ``` -------------------------------- ### Window Composition Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Illustrates the composition of UI elements within a window, showing the nesting of frames, layouts, and scene elements. ```text Window └── Frame └── VStack ├── Label └── SceneView └── Scene ├── Transform │ └── Rectangle │ └── Gestures └── Transform └── Rectangle └── Gestures ``` -------------------------------- ### Viewport Gesture Integration Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md This example demonstrates a complete integration of gesture handling within a viewport using a custom manipulator. It includes setting up the manipulator, defining gesture behaviors, and managing gesture events. ```python # extension.py import omni.ext from omni.kit.viewport.registry import RegisterScene from .line import LineManipulator class OmniExampleGestureExtension(omni.ext.IExt): def on_startup(self, ext_id): self._line = RegisterScene(LineManipulator, "Line Gesture") def on_shutdown(self): self._line = None ``` ```python # line.py from omni.ui import scene as sc import omni.ui as ui def setcolor(sender, color): sender.color = color class Manager(sc.GestureManager): def should_prevent(self, gesture, preventer) -> bool: if gesture.name == "SelectionDrag" and preventer.state == sc.GestureState.BEGAN: return True if gesture.name == "SelectionClick" and preventer.name == "color_change": return True return False manager = Manager() class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current class LineManipulator(sc.Manipulator): def on_build(self) -> None: transform = sc.Transform() with transform: sc.Line( [-50, 0, 0], [50, 0, 0], color=ui.color.beige, thickness=10, gestures=[ sc.ClickGesture(lambda s: setcolor(s, ui.color.green), manager=manager), sc.DoubleClickGesture(lambda s: setcolor(s, ui.color.beige), manager=manager), Move(transform, manager=manager) ] ) ``` -------------------------------- ### GesturePayload Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Demonstrates how to use the 'moved' property from GesturePayload to get screen position deltas for transformations. ```python class Move(sc.DragGesture): def on_changed(self): # Get mouse movement translate = self.sender.gesture_payload.moved # (dx, dy) # Create translation matrix current = sc.Matrix44.get_translation_matrix(*translate) # Apply to transform self.__transform.transform *= current ``` -------------------------------- ### Initialize and Start OmniExampleGestureExtension Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/api-reference/omni_example_gesture_viewport.md Instantiates and starts the main extension class. This is typically called by the extension framework upon enabling the extension. ```python extension = OmniExampleGestureExtension() extension.on_startup("omni.example.gesture_viewport") # LineManipulator is now registered as "Line Gesture" in the viewport ``` -------------------------------- ### Complete Window.py Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md This is the complete Python code for the window class, integrating the setcolor function and the click gesture for the rectangle. This file should be saved after adding the gesture callback. ```python import omni.ui as ui from omni.ui import scene as sc proj = [0.5,0,0,0,0,0.5,0,0,0,0,2e-7,0,0,0,1,1] def setcolor(sender, color): sender.color = color class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs) -> None: super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: with ui.VStack(): scene_view = sc.SceneView(sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT) with scene_view.scene: transform = sc.Transform() with transform: sc.Rectangle( 2, 2, color=ui.color.beige, thickness=5, gesture=sc.ClickGesture(lambda s: setcolor(s, ui.color.blue)) ) ``` -------------------------------- ### on_startup(ext_id) Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Called when the extension is enabled. Use this method to initialize extension resources, create UI elements, register with framework components, and start background tasks. The framework is fully initialized at this point, allowing access to omni.ui and omni.kit APIs. ```APIDOC ## on_startup(ext_id) ### Description Called when the extension is enabled. Use this method to initialize extension resources, create UI elements, register with framework components, and start background tasks. The framework is fully initialized at this point, allowing access to omni.ui and omni.kit APIs. ### Method Signature ```python def on_startup(self, ext_id: str) -> None ``` ### Parameters #### Path Parameters - **ext_id** (str) - Required - Unique extension identifier (e.g., "omni.example.gesture_viewport") ### Purpose - Initialize extension resources - Create UI windows or scenes - Register with framework components (viewport, event listeners, etc.) - Start any background tasks ### Guaranteed State - Framework is fully initialized - Other dependencies are loaded - Can access omni.ui and omni.kit APIs ### Error Handling - Uncaught exceptions prevent extension from loading - Should validate dependencies before use ``` -------------------------------- ### Viewport Gesture Manager Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Implement a custom gesture manager for viewports. This example prevents 'SelectionDrag' if another gesture has just begun, or 'SelectionClick' if a 'color_change' gesture is active. ```python class Manager(sc.GestureManager): def should_prevent(self, gesture: AbstractGesture, preventer: AbstractGesture) -> bool: # Prevent SelectionDrag if another gesture just started if gesture.name == "SelectionDrag" and preventer.state == sc.GestureState.BEGAN: return True # Prevent SelectionClick if color_change gesture is active if gesture.name == "SelectionClick" and preventer.name == "color_change": return True return False ``` -------------------------------- ### HoverGesture Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Demonstrates how to instantiate HoverGesture with callback functions for different hover events. This example shows usage with and without a manager. ```python # First rectangle with manager sic.HoverGesture( on_began_fn=lambda s: setcolor(s, ui.color.black), on_changed_fn=lambda s: self.print_action(s, "Hover Changed"), on_ended_fn=lambda s: self.print_action(s, "Hover End") ) # Second rectangle without manager sic.HoverGesture( on_began_fn=lambda s: setcolor(s, ui.color.black), on_changed_fn=lambda s: self.print_action(s, "Hover Changed"), on_ended_fn=lambda s: self.print_action(s, "Hover End") ) ``` -------------------------------- ### Viewport Extension Startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Initializes a viewport extension by creating and registering a manipulator. This manipulator becomes visible in the viewport and starts responding to gestures upon successful startup. ```python class OmniExampleGestureExtension(omni.ext.IExt): def on_startup(self, ext_id): # 1. Extension ID is available print(f"[{ext_id}] Starting...") # 2. Create the manipulator and register with viewport self._line = RegisterScene(LineManipulator, "Line Gesture") # This instantiates LineManipulator and calls its on_build() # 3. Manipulator is now visible in viewport # Gestures are active and responding to user input ``` -------------------------------- ### Example CHANGELOG.md Entry Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md A sample entry for a CHANGELOG.md file following keepachangelog.com conventions. It includes version, date, and a list of changes. ```markdown ## [1.0.0] - 2023-XX-XX ### Added - Initial release - Gesture viewport example - Gesture window example ``` -------------------------------- ### Complete Gesture Window Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Provides a full Python script for an Omniverse Kit extension window that includes a `SceneView` and a `Rectangle` with interactive `DragGesture` states. This code should be saved as `window.py`. ```python import omni.ui as ui from omni.ui import scene as sc proj = [0.5,0,0,0,0,0.5,0,0,0,0,2e-7,0,0,0,1,1] def setcolor(sender, color): sender.color = color class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs) -> None: super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: with ui.VStack(): scene_view = sc.SceneView(sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT) with scene_view.scene: transform = sc.Transform() with transform: sc.Rectangle( 2, 2, color=ui.color.beige, thickness=5, gesture= sc.DragGesture( on_began_fn=lambda s: setcolor(s, ui.color.indigo), on_changed_fn=lambda s: setcolor(s, ui.color.lightblue), on_ended_fn=lambda s: setcolor(s, ui.color.beige) ) ) ``` -------------------------------- ### Extension Configuration Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/README.md This TOML snippet shows the basic structure for configuring an Omniverse Kit extension, including package metadata and Python module dependencies. ```toml [package] version = "1.0.0" title = "omni example gesture viewport" description = "Example gesture extension" [dependencies] "omni.kit.uiapp" = {} [[python.module]] name = "omni.example.gesture_viewport" ``` -------------------------------- ### Instantiate UI Window on Extension Startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md This Python code replaces the default extension logic to create and display the `GestureWindowExample` UI window when the extension starts. It imports the necessary `GestureWindowExample` class and handles window destruction on shutdown. Ensure `omni.ext` and the local `window` module are imported. ```python import omni.ext from .window import GestureWindowExample # Any class derived from `omni.ext.IExt` in top level module (defined in `python.modules` of `extension.toml`) will be # instantiated when extension gets enabled and `on_startup(ext_id)` will be called. Later when extension gets disabled # on_shutdown() is called. class OmniExampleGestureExtension(omni.ext.IExt): # ext_id is current extension id. It can be used with extension manager to query additional information, like where # this extension is located on filesystem. def on_startup(self, ext_id): print("[omni.example.gesture] omni example gesture startup") self._window = GestureWindowExample("Gesture Example", width=500, height=500) def on_shutdown(self): print("[omni.example.gesture] omni example gesture shutdown") if self._window: self._window.destroy() self._window = None ``` -------------------------------- ### Python Module Import Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Demonstrates how users can import the extension's public API. This is used for accessing functionalities provided by the extension. ```python import omni.example.gesture_viewport from omni.example.gesture_viewport import some_public_function ``` ```python import omni.example.gesture_window from omni.example.gesture_window import GestureWindowExample ``` -------------------------------- ### Common Gesture Usage Examples Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/README.md Examples of common gesture implementations including click, double-click, drag, and hover. These can be used to trigger various UI or scene interactions. ```python # Click to change color sc.ClickGesture(lambda s: setcolor(s, ui.color.blue)) ``` ```python # Double-click to reset sc.DoubleClickGesture(lambda s: setcolor(s, ui.color.beige)) ``` ```python # Drag to move Move(transform, manager=manager) ``` ```python # Hover for feedback sc.HoverGesture( on_began_fn=lambda s: setcolor(s, ui.color.black), on_ended_fn=lambda s: setcolor(s, ui.color.beige) ) ``` -------------------------------- ### AbstractGesture Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Demonstrates how to access gesture properties like name and state to control gesture behavior. ```python def should_prevent(self, gesture: AbstractGesture, preventer: AbstractGesture) -> bool: # Access gesture properties if gesture.name == "SelectionDrag": return True if preventer.state == sc.GestureState.BEGAN: return True ``` -------------------------------- ### LineManipulator on_build() Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/api-reference/omni_example_gesture_viewport.md The on_build method is called automatically by the framework. It constructs the interactive line, including visual elements and gesture handlers for click, double-click, and drag. ```python # on_build is called automatically by the framework when needed # It creates the interactive line with all gesture handlers ``` -------------------------------- ### Create Label with Custom Formatting Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Example of creating a text label in 3D space with specified text content, size, alignment, and color. ```python sc.Label( "Click and Drag the Line to Move me\nClick or Double Click to Change color", size=18, alignment=ui.Alignment.CENTER, color=ui.color.blue ) ``` -------------------------------- ### GestureState Usage Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Shows how to use the GestureState enumeration within a manager's should_prevent method to control gesture behavior based on the current state. ```python # In Manager.should_prevent if preventer.state == sc.GestureState.BEGAN: return True # Prevent other gestures when one just started ``` -------------------------------- ### Complete window.py for Multiple Shapes Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md This is the full content of `window.py` after incorporating the code for handling multiple shapes with gestures. It includes necessary imports, class definitions, and the scene setup with two rectangles. ```python import omni.ui as ui from omni.ui import scene as sc from functools import partial proj = [0.5,0,0,0,0,0.5,0,0,0,0,2e-7,0,0,0,1,1] class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved # Move transform to the direction mouse moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current def setcolor(sender, color): sender.color = color class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs) -> None: super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: with ui.VStack(): scene_view = sc.SceneView(sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT) with scene_view.scene: transform = sc.Transform() with transform: sc.Rectangle( 2, 2, color=ui.color.beige, thickness=5, gestures=[ Move(transform), sc.ClickGesture(lambda s: setcolor(s, ui.color.red)), sc.DoubleClickGesture(lambda s: setcolor(s, ui.color.beige)) ] ) transform = sc.Transform(transform=sc.Matrix44.get_translation_matrix(0,0,-1)) with transform: sc.Rectangle( 2, 2, color=ui.color.olive, thickness=5, gestures=[ Move(transform), sc.ClickGesture(lambda s: setcolor(s, ui.color.blue)), sc.DoubleClickGesture(lambda s: setcolor(s, ui.color.olive)) ] ) ``` -------------------------------- ### ClickGesture Usage in Window Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Demonstrates ClickGesture usage within a window. The first example changes a rectangle's color to blue, while the second changes it to red without a manager. ```python # First rectangle: beige -> blue on click sic.ClickGesture( lambda s: setcolor(s, ui.color.blue), manager=manager, name="gesture_name" ) # Second rectangle: olive -> red on click (no manager) sic.ClickGesture(lambda s: setcolor(s, ui.color.red)) ``` -------------------------------- ### Initialize SceneView with Camera Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Demonstrates setting up a SceneView, which acts as a container for rendering a 3D scene within the UI, specifying camera properties and aspect ratio policy. ```python scene_view = sc.SceneView( sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT ) with scene_view.scene: # Add shapes here sc.Rectangle(...) ``` -------------------------------- ### Extension Startup and Shutdown Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Standard pattern for implementing extension lifecycle methods `on_startup` and `on_shutdown` in Kit extensions. Resources should be managed within these methods. ```python import omni.ext class MyExtension(omni.ext.IExt): def on_startup(self, ext_id: str): # Called when enabled self._resource = create_resource() def on_shutdown(self): # Called when disabled if self._resource: self._resource.destroy() self._resource = None ``` -------------------------------- ### Handle Startup Errors Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Implement a try-except block in `on_startup` to catch and report exceptions. Uncaught exceptions will prevent the extension from loading. ```python def on_startup(self, ext_id): try: self._window = GestureWindowExample("Gesture Example", width=500, height=500) except Exception as e: print(f"[{ext_id}] Startup failed: {e}") # If critical error, extension may be disabled raise ``` -------------------------------- ### Window Extension Startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Initializes a window extension by creating a UI window instance. The window's content is built lazily when it becomes visible, and gestures become active at that point. ```python class OmniExampleGestureExtension(omni.ext.IExt): def on_startup(self, ext_id): # 1. Create window instance self._window = GestureWindowExample("Gesture Example", width=500, height=500) # This: # - Creates omni.ui.Window with title "Gesture Example" # - Registers build callback (_build_fn) # - Does NOT yet execute _build_fn # 2. Window is displayed # 3. When window becomes visible, _build_fn is called # 4. _build_fn creates scene view and rectangles # 5. Gestures become active ``` -------------------------------- ### on_startup Method Signature Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md The signature for the `on_startup` method, called when an extension is enabled. It's used for initializing resources and registering with framework components. ```python def on_startup(self, ext_id: str) -> None: ``` -------------------------------- ### Create a 3D Line Segment Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Use sc.Line to create a 3D line segment. Specify start and end points, color, thickness, and optional gesture handlers. The start and end points cannot be changed after initialization. ```python from omni.ui import scene as sc import omni.ui as ui sc.Line( [-50, 0, 0], [50, 0, 0], color=ui.color.beige, thickness=10, gestures=[...] ) ``` -------------------------------- ### Set and Create Color Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Demonstrates how to set a predefined color constant or create a custom RGBA color. Use predefined constants for common states and Color(r, g, b, a) for custom colors. ```python import omni.ui as ui # Set color shape.color = ui.color.green # Create custom color (RGBA, 0.0-1.0) custom = ui.color.Color(0.5, 0.5, 0.5, 1.0) ``` -------------------------------- ### DoubleClickGesture Usage in Viewport Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Example of using DoubleClickGesture in a viewport to reset the line color to beige on a double-click. ```python # Resets line color from any state to beige on double-click sic.DoubleClickGesture( lambda s: setcolor(s, ui.color.beige), mouse_button=0, name="color_change", manager=manager ) ``` -------------------------------- ### Create UI Window Instance Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Instantiate a UI window by inheriting from ui.Window and providing a title and other window properties. ```python from omni.example.gesture_window.window import GestureWindowExample window = GestureWindowExample("Gesture Example", width=500, height=500) ``` -------------------------------- ### Transform Hierarchy Example Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Visual representation of the transform hierarchy in the gesture manipulator. Demonstrates nested transforms and their children. ```text Manipulator └── Transform (root) ├── Line │ └── Gestures │ ├── ClickGesture │ ├── DoubleClickGesture │ └── Move (owns transform reference) └── Transform (offset) └── Label ``` -------------------------------- ### sc.Line Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Represents a 3D line segment. It is defined by its start and end points, color, thickness, and optional gesture handlers. ```APIDOC ## sc.Line ### Description Creates a 3D line segment shape. ### Constructor ```python sc.Line( start_point: list[float], # [x, y, z] end_point: list[float], # [x, y, z] color: Color = ui.color.white, thickness: float = 1.0, gestures: list[AbstractGesture] = None ) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **start_point** (list[float]) - Required - [x, y, z] starting position - **end_point** (list[float]) - Required - [x, y, z] ending position - **color** (Color) - Optional - Line color (default: white) - **thickness** (float) - Optional - Line width in pixels (default: 1.0) - **gestures** (list) - Optional - Gesture handlers (default: None) ### Properties - **color** (Color) - Settable - Line color (can change via gesture) - **thickness** (float) - Settable - Line width - **start_point** (list[float]) - Not Settable - Start position (set in constructor) - **end_point** (list[float]) - Not Settable - End position (set in constructor) ### Request Example ```python from omni.ui import scene as sc import omni.ui as ui sc.Line( [-50, 0, 0], [50, 0, 0], color=ui.color.beige, thickness=10, gestures=[...] ) ``` ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Add Extension Dependency Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Add this line to the [dependencies] section of your .kit file to include the 'my.spawn_prims.ext' extension. ```json "my.spawn_prims.ext" = {} ``` -------------------------------- ### Implement a Gesture Manager to Prevent Gestures Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Create a `sc.GestureManager` to control gesture interactions. This example prevents the 'SelectionDrag' gesture when it begins. ```python class Manager(sc.GestureManager): def should_prevent(self, gesture: sc.AbstractGesture, preventer: sc.AbstractGesture) -> bool: if gesture.name == "SelectionDrag" and preventer.state == sc.GestureState.BEGAN: return True manager=Manager() ``` -------------------------------- ### ClickGesture Usage in Viewport Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Example of using ClickGesture in a viewport to change the line color of a shape from beige to green upon clicking. ```python # Changes line color from beige to green on click sic.ClickGesture( lambda s: setcolor(s, ui.color.green), mouse_button=0, name="color_change", manager=manager ) ``` -------------------------------- ### Import Window Extension Entry Point Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Import the main module for the window extension. This loads the extension's Python package. ```python import omni.example.gesture_window # Loads extension.py on demand ``` -------------------------------- ### Launch Application (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Execute this command in the terminal to launch the application after building. Select the desired editor application from the prompt. ```bash ./repo.sh launch ``` -------------------------------- ### Window Manager Gesture Prevention Logic Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Example implementation of GestureManager for window interactions. Prevents gestures if they are not 'gesture_name' and a 'BEGAN' gesture is present. ```python class Manager(sc.GestureManager): def should_prevent(self, gesture: AbstractGesture, preventer: AbstractGesture) -> bool: if gesture.name != "gesture_name" and preventer.state == sc.GestureState.BEGAN: return True return False ``` -------------------------------- ### OmniExampleGestureExtension.on_startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/api-reference/omni_example_gesture_window.md Called when the extension is enabled. This method creates and displays a GestureWindowExample window. ```APIDOC ## OmniExampleGestureExtension.on_startup ### Description Called when the extension is enabled. Creates and displays a GestureWindowExample window with title "Gesture Example", width 500, height 500. ### Method on_startup(ext_id: str) ### Parameters #### Path Parameters - **ext_id** (str) - Yes - Description: Extension identifier string passed by framework ### Returns None ### Example ```python extension = OmniExampleGestureExtension() extension.on_startup("omni.example.gesture_window") # GestureWindowExample window is now visible ``` ``` -------------------------------- ### Declare Extension Dependencies Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Explicitly declare all extension dependencies using the `[dependencies]` table. This ensures proper installation and avoids runtime errors. ```toml [dependencies] "omni.kit.uiapp" = {} ``` -------------------------------- ### DragGesture Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Captures and manages mouse drag events. It provides callbacks for the start, change, and end of a drag operation, enabling custom manipulation behaviors. ```APIDOC ## DragGesture ### Description Captures and manages mouse drag events. It provides callbacks for the start, change, and end of a drag operation, enabling custom manipulation behaviors. This is a base class, often extended for specific drag functionalities like moving objects. ### Constructor `omni.ui.scene.DragGesture(on_began_fn: callable = None, on_changed_fn: callable = None, on_ended_fn: callable = None, mouse_button: int = 0, modifiers: int = 0, check_mouse_moved: bool = True, name: str = None, manager: GestureManager = None)` ### Parameters #### Parameters - **on_began_fn** (callable) - Optional - Callback function executed when the drag operation begins. - **on_changed_fn** (callable) - Optional - Callback function executed during the drag movement. - **on_ended_fn** (callable) - Optional - Callback function executed when the drag operation ends. - **mouse_button** (int) - Optional - The mouse button to track for the drag. Defaults to 0 (left button). - **modifiers** (int) - Optional - A bitmask representing keyboard modifier keys. - **check_mouse_moved** (bool) - Optional - If True, the gesture only triggers on 2D screen position changes. If False, it triggers even if only the 3D object's position changes due to camera movement. Defaults to True. - **name** (str) - Optional - A unique identifier for the gesture. - **manager** (GestureManager) - Optional - The gesture manager instance. ### Gesture Payload Access gesture-specific data via `self.sender.gesture_payload` within callbacks. Key properties include: - **moved**: A tuple `(dx, dy)` representing the 2D screen movement in pixels. ### Usage Example (Custom Move Implementation) ```python class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current ``` ### `check_mouse_moved` Behavior - **True**: The gesture updates only when the 2D screen position of the cursor changes. This filters out movements caused solely by camera manipulation. - **False**: The gesture updates even if the 2D screen position remains the same, as long as the underlying 3D object's position has changed (e.g., due to camera rotation or panning around the object). ``` -------------------------------- ### Build Kit Extensions on Linux and Windows Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Commands to build the Omniverse Kit extensions. Use the appropriate script for your operating system. ```bash # Linux ./repo.sh build ``` ```bash # Windows .\repo.bat build ``` -------------------------------- ### Initialize Gesture Window Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/EXTENSION_LIFECYCLE.md Initializes a ui.Window subclass, registers a build callback, and prepares the window for display. ```python class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) ``` -------------------------------- ### Integrate Gesture into Scene Element Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Pass an instance of your custom gesture to the scene element's constructor. This example integrates the `Move` gesture into a `sc.Line`. ```python # line.py import omni.ui as ui from omni.ui import scene as sc class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved # Move transform to the direction mouse moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current class LineManipulator(sc.Manipulator): def __init__(self, desc: dict, **kwargs) -> None: super().__init__(**kwargs) def on_build(self) -> None: transform = sc.Transform() with transform: sc.Line( [-50, 0, 0], [50, 0, 0], color = ui.color.beige, thickness=10, gesture=Move(transform) ) ``` -------------------------------- ### Implement a Custom Drag Gesture Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Define a custom drag gesture by subclassing `sc.DragGesture`. This example shows how to move a transform based on mouse movement. ```python class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved # Move transform to the direction mouse moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current ``` -------------------------------- ### DoubleClickGesture Usage in Window Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Shows DoubleClickGesture usage in a window. The first example resets a rectangle's color to beige, and the second resets it to olive. ```python # First rectangle: double-click resets to beige sic.DoubleClickGesture( lambda s: setcolor(s, ui.color.beige), manager=manager, name="gesture_name" ) # Second rectangle: double-click resets to olive sic.DoubleClickGesture(lambda s: setcolor(s, ui.color.olive)) ``` -------------------------------- ### Safe Window Startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Safely initializes a window object within a try-except block, catching and re-raising exceptions to indicate startup failure. ```python def on_startup(self, ext_id): try: self._window = GestureWindowExample("Title", width=500, height=500) except Exception as e: print(f"Failed: {e}") raise ``` -------------------------------- ### DragGesture Constructor Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Defines the constructor for DragGesture, including callbacks for drag start, change, and end, along with parameters for mouse button, modifiers, and movement checks. ```python sc.DragGesture( on_began_fn: callable = None, on_changed_fn: callable = None, on_ended_fn: callable = None, mouse_button: int = 0, modifiers: int = 0, check_mouse_moved: bool = True, name: str = None, manager: GestureManager = None ) ``` -------------------------------- ### Import Viewport Extension Entry Point Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Import the main module for the viewport extension. This loads the extension's Python package. ```python import omni.example.gesture_viewport # Loads extension.py on demand ``` -------------------------------- ### Viewport Manager Gesture Prevention Logic Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/TYPES_REFERENCE.md Example implementation of GestureManager for viewport interactions. Prevents 'SelectionDrag' if a 'BEGAN' gesture is present, and 'SelectionClick' if 'color_change' is active. ```python class Manager(sc.GestureManager): def should_prevent(self, gesture: AbstractGesture, preventer: AbstractGesture) -> bool: if gesture.name == "SelectionDrag" and preventer.state == sc.GestureState.BEGAN: return True if gesture.name == "SelectionClick" and preventer.name == "color_change": return True return False ``` -------------------------------- ### Create New Extension (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/README.md Use this command to create a new extension from a template on Linux. ```bash ./repo.sh template new ``` -------------------------------- ### Create SceneView with Camera Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md Instantiate a SceneView, providing a CameraModel with the defined projection matrix. The aspect ratio policy ensures the scene scales correctly. ```python scene_view = sc.SceneView(sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT) ``` -------------------------------- ### OmniExampleGestureExtension.on_startup Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/api-reference/omni_example_gesture_viewport.md Called when the extension is enabled. It registers the LineManipulator scene with the viewport. ```APIDOC ## OmniExampleGestureExtension.on_startup(ext_id) ### Description Called when the extension is enabled. Registers the LineManipulator scene with the viewport using RegisterScene. ### Method `on_startup` ### Parameters #### Path Parameters - **ext_id** (str) - Required - Extension identifier string passed by framework ### Returns None ### Example ```python extension = OmniExampleGestureExtension() extension.on_startup("omni.example.gesture_viewport") # LineManipulator is now registered as "Line Gesture" in the viewport ``` ``` -------------------------------- ### Define Orthographic Projection Matrix Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Provides an example of an orthographic projection matrix scaled by 0.5 in X/Y, suitable for defining the camera's view in a 3D scene. ```python proj = [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 2e-7, 0, 0, 0, 1, 1] # Orthographic projection scaled by 0.5 in X/Y # Near plane: 2e-7, Far plane: effectively infinite ``` -------------------------------- ### Change Shape Color with Modifier Key Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/USAGE_EXAMPLES.md Shows how to trigger a color change with a click gesture when a specific modifier key is held down. This example changes the color to green. ```python # With modifier key sc.ClickGesture(lambda s: change_color(s, ui.color.green), modifiers=0x1) ``` -------------------------------- ### Create and Manage a UI Window Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Define a custom UI window by inheriting from omni.ui.Window. Set the build function to define the UI content. Manage the window's lifecycle by creating it in on_startup and destroying it in on_shutdown. ```python import omni.ui as ui class MyWindow(ui.Window): def __init__(self, title: str, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: # Build UI content pass # In on_startup self._window = MyWindow("Title", width=500, height=500) # In on_shutdown if self._window: self._window.destroy() self._window = None ``` -------------------------------- ### Define Custom Environment Variable in extension.toml Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/CONFIGURATION_REFERENCE.md Example of how to define a custom environment variable within an extension.toml file. This is not used in the sample but shows potential custom usage. ```toml # Would be added to extension.toml if needed [environment] MY_GESTURE_SETTING = "value" ``` -------------------------------- ### Create and Manipulate Transform Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Demonstrates creating a Transform object, initializing it with a translation, and applying further transformations. ```python sc.Transform() transform = sc.Transform( transform=sc.Matrix44.get_translation_matrix(0, 20, 0) ) transform.transform *= sc.Matrix44.get_translation_matrix(dx, dy, dz) ``` -------------------------------- ### Create Window with Scene View and Gestures Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/USAGE_EXAMPLES.md This Python snippet shows how to create a UI window with a scene view that includes an interactive rectangle. It demonstrates attaching click, hover, and move gestures to the rectangle and updating a status label based on gesture events. ```python import omni.ui as ui from omni.ui import scene as sc class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs): super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): # Projection matrix for orthographic view proj = [0.5, 0, 0, 0, 0, 0.5, 0, 0, 0, 0, 2e-7, 0, 0, 0, 1, 1] with self.frame: with ui.VStack(): # Status label self.label = ui.Label("Status: Ready", alignment=ui.Alignment.CENTER) # Scene view scene_view = sc.SceneView( sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT ) with scene_view.scene: # Create interactive rectangle transform = sc.Transform() with transform: sc.Rectangle( width=2, height=2, color=ui.color.beige, gestures=[ sc.ClickGesture(lambda s: self.update_status("Clicked")), Move(transform), sc.HoverGesture(on_began_fn=lambda s: self.update_status("Hovering")) ] ) def update_status(self, message: str): self.label.text = f"Status: {message}" # In extension def on_startup(self, ext_id): self._window = GestureWindowExample("Gesture Demo", width=500, height=500) def on_shutdown(self): if self._window: self._window.destroy() self._window = None ``` -------------------------------- ### Gesture Manager Prevention Logic Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/QUICK_REFERENCE.md Example of implementing the `should_prevent` method in a custom GestureManager to conditionally prevent gestures. This snippet prevents 'drag' gestures when another gesture begins. ```python from omni.ui.scene import GestureManager class Manager(GestureManager): def should_prevent(self, gesture, preventer) -> bool: if gesture.name == "drag" and preventer.state == GestureState.BEGAN: return True return False ``` -------------------------------- ### Build Application with New Extensions (Linux) Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/README.md Rebuild your application after adding new extensions to ensure they are populated to the build directory on Linux. ```bash ./repo.sh build ``` -------------------------------- ### HoverGesture Constructor Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Defines the HoverGesture class, used for detecting mouse hover events over shapes. It accepts callback functions for hover start, change, and end, along with optional modifier keys. ```python sc.HoverGesture( on_began_fn: callable = None, on_changed_fn: callable = None, on_ended_fn: callable = None, modifiers: int = 0 ) ``` -------------------------------- ### Create Rectangle with Gestures Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/GESTURES_GUIDE.md Illustrates creating a 2D rectangle in 3D space with custom dimensions, color, border thickness, and gesture handlers. ```python sc.Rectangle( 2, 2, color=ui.color.beige, thickness=5, gestures=[ sc.ClickGesture(...), sc.DoubleClickGesture(...), Move(transform, manager=manager), sc.HoverGesture(...) ] ) ``` -------------------------------- ### Constrained Drag Gesture Variations Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/_autodocs/USAGE_EXAMPLES.md Provides variations for constraining drag gestures to different axes or planes. These examples demonstrate how to modify the transformation matrix for Y-axis only, Z-axis only, or XY plane movement. ```python # Y-axis only matrix = sc.Matrix44.get_translation_matrix(0, dy, 0) ``` ```python # Z-axis only (depth) matrix = sc.Matrix44.get_translation_matrix(0, 0, dz) ``` ```python # XY plane matrix = sc.Matrix44.get_translation_matrix(dx, dy, 0) ``` -------------------------------- ### Complete Kit Extension Sample with Custom Gesture Source: https://github.com/nvidia-omniverse/kit-extension-sample-gestures/blob/main/docs/tutorial.md The full Python code for the Kit Extension Sample, including the custom Move gesture implementation and its integration into a SceneView. ```python import omni.ui as ui from omni.ui import scene as sc from functools import partial proj = [0.5,0,0,0,0,0.5,0,0,0,0,2e-7,0,0,0,1,1] class Move(sc.DragGesture): def __init__(self, transform: sc.Transform, **kwargs): super().__init__(**kwargs) self.__transform = transform def on_changed(self): translate = self.sender.gesture_payload.moved # Move transform to the direction mouse moved current = sc.Matrix44.get_translation_matrix(*translate) self.__transform.transform *= current def setcolor(sender, color): sender.color = color class GestureWindowExample(ui.Window): def __init__(self, title: str, **kwargs) -> None: super().__init__(title, **kwargs) self.frame.set_build_fn(self._build_fn) def _build_fn(self): with self.frame: with ui.VStack(): scene_view = sc.SceneView(sc.CameraModel(proj, 1), aspect_ratio_policy=sc.AspectRatioPolicy.PRESERVE_ASPECT_FIT) with scene_view.scene: transform = sc.Transform() with transform: sc.Rectangle( 2, 2, color=ui.color.beige, thickness=5, gesture= Move(transform) ) ```