Extension: omni.kit.scene_view.opengl-1.3.0 |
Documentation Generated: Dec 17, 2024 |
Overview#
Introduction#
omni.kit.scene_view.opengl
provides an OpenGL drawing backend for omni.ui.scene
.
The usage is the same as omni.ui.scene
for creating items, the only difference is in how the top-level
SceneView
object is created.
How to create a simple OpenGLSceneView#
Python#
Import the required packages:
import omni.ui as ui
from omni.ui_scene import scene as sc
from omni.kit.scene_view.opengl import OpenGLSceneView
Create a simple model to deliver view and projection to the
omni.ui.scene.SceneView
\
class SimpleModel(sc.AbstractManipulatorModel):
def __init__(self, view = None, projection = None):
super().__init__()
self.__view = view or [0.7071067811865476, -0.4082482839677536, 0.5773502737830688, 0,
2.7755575615628914e-17, 0.8164965874238355, 0.5773502600027396, 0,
-0.7071067811865477, -0.40824828396775353, 0.5773502737830687, 0,
5.246555321336316e-14, -0.0000097441642310514, -866.0254037844385, 1]
self.__projection = projection or [1.7320507843521864, 0, 0, 0,
0, 2.911189413558437, 0, 0,
0, 0, -1.00000020000002, -1,
0, 0, -2.00000020000002, 0]
def get_as_floats(self, item):
"""Called by SceneView to get projection and view matrices"""
if item == self.get_item("projection"):
return self.__projection
if item == self.get_item("view"):
return self.__view
Create an
omni.ui.Window
and an OpenGLSceneView in it.
window = ui.Window("OpenGLSceneView", width=512, height=512)
with window.frame:
gl_sceneview = OpenGLSceneView(SimpleModel())
with gl_sceneview.scene:
sc.Arc(250, axis=0, tesselation=64, color=[1, 0, 0, 1])
sc.Arc(250, axis=1, tesselation=64, color=[0, 1, 0, 1])
sc.Arc(250, axis=2, tesselation=64, color=[0, 0, 1, 1])
Depth Compositing#
Because the drawing is done with OpenGL, it is also possible to do in Viewport drawing that is depth-composited.
This can be accomplished with the ViewportOpenGLSceneView
class, which also handles setting up the Viewport
to output a depth channel to clip against.
Python#
from omni.ui_scene import scene as sc
from omni.kit.scene_view.opengl import ViewportOpenGLSceneView
from omni.kit.viewport.utility import get_active_viewport_window
def build_fn(gl_scene_view):
with gl_scene_view.scene:
sc.Arc(45, axis=1, tesselation=64, color=[1, 0.9, 0.4, 1], wireframe=False, thickness=50)
# Use a static helper method to set everything up
# Just provide a ViewportWindow, unique identifier, and a callable function to build the scene
#
ui_frame, gl_scene_view = ViewportOpenGLSceneView.create_in_viewport_window(get_active_viewport_window(),
"demo.unique.identifier",
build_fn)