file_path
stringlengths 21
224
| content
stringlengths 0
80.8M
|
---|---|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_14/docs/README.md | # Developer Office Hour - 10/14/2022
This is the sample code from the Developer Office Hour held on 10/14/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- Why doesn't OV Code start?
- How do I inject my custom menu item into an existing context menu?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/maticodes/doh_2023_08_25/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_08_25] Dev Office Hours Extension (2023-08-25) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_08_25] Dev Office Hours Extension (2023-08-25) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/maticodes/doh_2023_08_25/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/scripts/add_sbsar.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
omni.kit.commands.execute('AddSbsarReferenceAndBindCommand', sbsar_path=r"C:\Users\mcodesal\Downloads\blueberry_skin.sbsar",
target_prim_path="/World/Sphere")
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/scripts/get_selected_meshes.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Usd, UsdGeom
stage = omni.usd.get_context().get_stage()
selection = omni.usd.get_context().get_selection().get_selected_prim_paths()
meshes = []
for path in selection:
prim = stage.GetPrimAtPath(path)
if prim.IsA(UsdGeom.Mesh):
meshes.append(prim)
print("Selected meshes:")
print(meshes) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-08-25: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-08-25"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_08_25".
[[python.module]]
name = "maticodes.doh_2023_08_25"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_25/docs/README.md | # Developer Office Hour - 08/25/2023
This is the sample code from the Developer Office Hour held on 08/25/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:17 - How do I get just the mesh prims from my current selection?
- 08:26 - How do I programmatically add an SBSAR material to my USD Stage?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/maticodes/doh_2023_04_28/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_04_28] Dev Office Hours Extension (2023-04-28) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_04_28] Dev Office Hours Extension (2023-04-28) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/maticodes/doh_2023_04_28/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/toggle_hud.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.viewport.utility as okvu
okvu.toggle_global_visibility() |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/custom_attrs.py |
# SPDX-License-Identifier: Apache-2.0
# Docs: https://docs.omniverse.nvidia.com/prod_kit/prod_kit/programmer_ref/usd/properties/create-attribute.html
import omni.usd
from pxr import Usd, Sdf
stage = omni.usd.get_context().get_stage()
prim: Usd.Prim = stage.GetPrimAtPath("/World/Cylinder")
attr: Usd.Attribute = prim.CreateAttribute("mySecondAttr", Sdf.ValueTypeNames.Bool)
attr.Set(False)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/custom_global_data.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
layer = stage.GetRootLayer()
print(type(layer))
layer.SetCustomLayerData({"Hello": "World"})
stage.DefinePrim("/World/Hello", "HelloWorld")
stage.DefinePrim("/World/MyTypeless") |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/make_unselectable.py | # SPDX-License-Identifier: Apache-2.0
# Docs: https://docs.omniverse.nvidia.com/kit/docs/omni.usd/latest/omni.usd/omni.usd.UsdContext.html#omni.usd.UsdContext.set_pickable
import omni.usd
ctx = omni.usd.get_context()
ctx.set_pickable("/", True) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/scripts/change_viewport_camera.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.viewport.utility as vu
from pxr import Sdf
vp_api = vu.get_active_viewport()
vp_api.camera_path = "/World/Camera_01"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-04-28: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-04-28"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_04_28".
[[python.module]]
name = "maticodes.doh_2023_04_28"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_28/docs/README.md | # Developer Office Hour - 04/28/2023
This is the sample code from the Developer Office Hour held on 04/28/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:18 - How do I make a prim unselectable in the viewport?
- 07:50 - How do I create custom properties?
- 26:00 - Can I write custom components for prims link in Unity?
- 50:21 - How can I toggle the stats heads up display on the viewport?
- 66:00 - How can you switch cameras on the active viewport?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/maticodes/doh_2023_09_01/extension.py | # SPDX-License-Identifier: Apache-2.0
import subprocess
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
result = subprocess.check_output(["python", "-c", "print('Hello World')"])
print(result.decode())
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_09_01] Dev Office Hours Extension (2023-09-01) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_09_01] Dev Office Hours Extension (2023-09-01) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/maticodes/doh_2023_09_01/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/scripts/logging.py | # SPDX-License-Identifier: Apache-2.0
import logging
import carb
logger = logging.getLogger()
print("Hello")
carb.log_info("World")
logger.info("Omniverse")
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/scripts/xforming.py | # SPDX-License-Identifier: Apache-2.0
from pxr import UsdGeom
import omni.usd
stage = omni.usd.get_context().get_stage()
cube = stage.GetPrimAtPath("/World/Xform/Cube")
cube_xformable = UsdGeom.Xformable(cube)
transform = cube_xformable.GetLocalTransformation()
print(transform)
transform2 = cube_xformable.GetLocalTransformation()
print(transform2)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-09-01: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-09-01"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_09_01".
[[python.module]]
name = "maticodes.doh_2023_09_01"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_01/docs/README.md | # Developer Office Hour - 09/01/2023
This is the sample code from the Developer Office Hour held on 09/01/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 7:27 - How do I validate my assets to make sure they are up-to-date with the latest USD specification?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/maticodes/doh_2022_10_28/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_10_28] Dev Office Hours Extension (2022-10-28) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
import omni.kit.commands
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cone')
from pxr import UsdGeom
stage = omni.usd.get_context().get_stage()
sphere = UsdGeom.Sphere.Define(stage, "/World/MySphere")
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_10_28] Dev Office Hours Extension (2022-10-28) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/maticodes/doh_2022_10_28/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/scripts/usd_watcher.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Gf
stage = omni.usd.get_context().get_stage()
cube = stage.GetPrimAtPath("/World/Cube")
def print_size(changed_path):
print("Size Changed:", changed_path)
def print_pos(changed_path):
print(changed_path)
if changed_path.IsPrimPath():
prim_path = changed_path
else:
prim_path = changed_path.GetPrimPath()
prim = stage.GetPrimAtPath(prim_path)
local_transform = omni.usd.get_local_transform_SRT(prim)
print("Translation: ", local_transform[3])
def print_world_pos(changed_path):
world_transform: Gf.Matrix4d = omni.usd.get_world_transform_matrix(prim)
translation: Gf.Vec3d = world_transform.ExtractTranslation()
print(translation)
size_attr = cube.GetAttribute("size")
cube_sub = omni.usd.get_watcher().subscribe_to_change_info_path(cube.GetPath(), print_world_pos)
cube_size_sub = omni.usd.get_watcher().subscribe_to_change_info_path(size_attr.GetPath(), print_size)
cube_sub = None
cube_size_sub = None |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/scripts/extras.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
if prim:
print("Prim Exists")
from pxr import UsdGeom
# e.g., find all prims of type UsdGeom.Mesh
mesh_prims = [x for x in stage.Traverse() if x.IsA(UsdGeom.Mesh)]
mesh_prims = []
for x in stage.Traverse():
if x.IsA(UsdGeom.Mesh):
mesh_prims.append(x)
print(mesh_prims) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/scripts/docking.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
my_window = ui.Window("Example Window", width=300, height=300)
with my_window.frame:
with ui.VStack():
f = ui.FloatField()
def clicked(f=f):
print("clicked")
f.model.set_value(f.model.get_value_as_float() + 1)
ui.Button("Plus One", clicked_fn=clicked)
my_window.dock_in_window("Property", ui.DockPosition.SAME)
ui.dock_window_in_window(my_window.title, "Property", ui.DockPosition.RIGHT, 0.2)
my_window.deferred_dock_in("Content", ui.DockPolicy.TARGET_WINDOW_IS_ACTIVE)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-10-28: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-10-28"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_10_28".
[[python.module]]
name = "maticodes.doh_2022_10_28"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_28/docs/README.md | # Developer Office Hour - 10/28/2022
This is the sample code from the Developer Office Hour held on 10/28/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I dock my window?
- How do I subscribe to changes to a prim or attribute? (omni.usd.get_watcher())
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/maticodes/doh_2022_09_23/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_09_23] Dev Office Hours Extension (2022-09-23) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_09_23] Dev Office Hours Extension (2022-09-23) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/maticodes/doh_2022_09_23/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/combobox_selected_item.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
my_window = ui.Window("Example Window", width=300, height=300)
combo_sub = None
options = ["One", "Two", "Three"]
with my_window.frame:
with ui.VStack():
combo_model: ui.AbstractItemModel = ui.ComboBox(0, *options).model
def combo_changed(item_model: ui.AbstractItemModel, item: ui.AbstractItem):
value_model = item_model.get_item_value_model(item)
current_index = value_model.as_int
option = options[current_index]
print(f"Selected '{option}' at index {current_index}.")
combo_sub = combo_model.subscribe_item_changed_fn(combo_changed)
def clicked():
value_model = combo_model.get_item_value_model()
current_index = value_model.as_int
option = options[current_index]
print(f"Button Clicked! Selected '{option}' at index {current_index}.")
ui.Button("Print Combo Selection", clicked_fn=clicked)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/use_tokens.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/py/kit/docs/guide/tokens.html
import carb.tokens
from pathlib import Path
path = Path("${shared_documents}") / "maticodes.foo"
resolved_path = carb.tokens.get_tokens_interface().resolve(str(path))
print(resolved_path) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/simple_instancer.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Usd, UsdGeom, Sdf, Gf
stage: Usd.Stage = omni.usd.get_context().get_stage()
prim_path = Sdf.Path("/World/MyInstancer")
instancer: UsdGeom.PointInstancer = UsdGeom.PointInstancer.Define(stage, prim_path)
proto_container = UsdGeom.Scope.Define(stage, prim_path.AppendPath("Prototypes"))
shapes = []
shapes.append(UsdGeom.Cube.Define(stage, proto_container.GetPath().AppendPath("Cube")))
shapes.append(UsdGeom.Sphere.Define(stage, proto_container.GetPath().AppendPath("Sphere")))
shapes.append(UsdGeom.Cone.Define(stage, proto_container.GetPath().AppendPath("Cone")))
instancer.CreatePositionsAttr([Gf.Vec3f(0, 0, 0), Gf.Vec3f(2, 0, 0), Gf.Vec3f(4, 0, 0)])
instancer.CreatePrototypesRel().SetTargets([shape.GetPath() for shape in shapes])
instancer.CreateProtoIndicesAttr([0, 1, 2]) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/scripts/one_widget_in_container.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
my_window = ui.Window("Example Window", width=300, height=300)
with my_window.frame:
with ui.VStack():
with ui.CollapsableFrame():
with ui.VStack():
ui.FloatField()
ui.FloatField()
ui.Button("Button 1") |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-09-23: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-09-23"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_09_23".
[[python.module]]
name = "maticodes.doh_2022_09_23"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_23/docs/README.md | # Developer Office Hour - 09/23/2022
This is the sample code from the Developer Office Hour held on 09/23/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I query the selected item in a ui.ComboBox?
- How do I use Kit tokens?
- Why do I only see one widget in my UI container?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/maticodes/doh_2022_09_09/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.kit.commands
import omni.ui as ui
import omni.usd
from pxr import Gf, Sdf
# Check out: USDColorModel
# C:\ext_projects\omni-dev-office-hours\app\kit\exts\omni.example.ui\omni\example\ui\scripts\colorwidget_doc.py
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self._color_model = None
self._color_changed_subs = []
self._path_model = None
self._change_info_path_subscription = None
self._path_changed_sub = None
self._stage = omni.usd.get_context().get_stage()
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("Property Path")
self._path_model = ui.StringField().model
self._path_changed_sub = self._path_model.subscribe_value_changed_fn(
self._on_path_changed
)
ui.Label("Color")
with ui.HStack(spacing=5):
self._color_model = ui.ColorWidget(width=0, height=0).model
for item in self._color_model.get_item_children():
component = self._color_model.get_item_value_model(item)
self._color_changed_subs.append(component.subscribe_value_changed_fn(self._on_color_changed))
ui.FloatField(component)
def _on_mtl_attr_changed(self, path):
color_attr = self._stage.GetAttributeAtPath(path)
color_model_items = self._color_model.get_item_children()
if color_attr:
color = color_attr.Get()
for i in range(len(color)):
component = self._color_model.get_item_value_model(color_model_items[i])
component.set_value(color[i])
def _on_path_changed(self, model):
if Sdf.Path.IsValidPathString(model.as_string):
attr_path = Sdf.Path(model.as_string)
color_attr = self._stage.GetAttributeAtPath(attr_path)
if color_attr:
self._change_info_path_subscription = omni.usd.get_watcher().subscribe_to_change_info_path(
attr_path,
self._on_mtl_attr_changed
)
def _on_color_changed(self, model):
values = []
for item in self._color_model.get_item_children():
component = self._color_model.get_item_value_model(item)
values.append(component.as_float)
if Sdf.Path.IsValidPathString(self._path_model.as_string):
attr_path = Sdf.Path(self._path_model.as_string)
color_attr = self._stage.GetAttributeAtPath(attr_path)
if color_attr:
color_attr.Set(Gf.Vec3f(*values[0:3]))
def destroy(self) -> None:
self._change_info_path_subscription = None
self._color_changed_subs = None
self._path_changed_sub = None
return super().destroy()
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_09_09] Dev Office Hours Extension (2022-09-09) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_09_09] Dev Office Hours Extension (2022-09-09) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/maticodes/doh_2022_09_09/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/scripts/undo_group.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
import omni.kit.undo
# Requires Ctrl+Z twice to undo
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube')
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube')
# Grouped into one undo
with omni.kit.undo.group():
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube')
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube') |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/scripts/skip_undo_history.py | # SPDX-License-Identifier: Apache-2.0
import omni.kit.commands
import omni.kit.primitive.mesh as mesh_cmds
# Creates history
omni.kit.commands.execute('CreateMeshPrimWithDefaultXform',
prim_type='Cube')
# Doesn't create history
mesh_cmds.CreateMeshPrimWithDefaultXformCommand("Cube").do()
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-09-09: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-09-09"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_09_09".
[[python.module]]
name = "maticodes.doh_2022_09_09"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_09/docs/README.md | # Developer Office Hour - 09/09/2022
This is the sample code from the Developer Office Hour held on 09/09/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I connect a ColorWidget to the base color of a material at a specific path?
- How do I create an undo group?
- How do I avoid adding a command to the undo history?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_18/maticodes/doh_2023_08_18/extension.py | # SPDX-License-Identifier: Apache-2.0
import asyncio
from pathlib import Path
import carb
import omni.ext
import omni.ui as ui
import omni.usd
test_stage_path = Path(__file__).parent.parent.parent / "data" / "test_stage.usd"
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info(test_stage_path)
# Synch option
# omni.usd.get_context().open_stage(str(test_stage_path))
# Async Option
# asyncio.ensure_future(self.open_stage())
# Async with Callback
omni.usd.get_context().open_stage_with_callback(str(test_stage_path), self.on_stage_open_finished)
ui.Button("Click Me", clicked_fn=clicked)
async def open_stage(self):
(result, error) = await omni.usd.get_context().open_stage_async(str(test_stage_path))
#Now that we've waited for the scene to open, we should be able to get the stage
stage = omni.usd.get_context().get_stage()
print (f"opened stage {stage} with result {result}")
def on_stage_open_finished(self, result: bool, path: str):
stage = omni.usd.get_context().get_stage()
print (f"opened stage {stage} with result {result}")
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_08_18] Dev Office Hours Extension (2023-08-18) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_08_18] Dev Office Hours Extension (2023-08-18) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_18/maticodes/doh_2023_08_18/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_18/scripts/my_script.py | # SPDX-License-Identifier: Apache-2.0 |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_18/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-08-18: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-08-18"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_08_18".
[[python.module]]
name = "maticodes.doh_2023_08_18"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_08_18/docs/README.md | # Developer Office Hour - 08/18/2023
This is the sample code from the Developer Office Hour held on 08/18/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:16 - How do I programmatically open a Stage in Kit?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/maticodes/doh_2022_08_26/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_08_26] Dev Office Hours Extension (2022-08-26) startup")
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_08_26] Dev Office Hours Extension (2022-08-26) shutdown")
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/maticodes/doh_2022_08_26/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/maticodes/doh_2022_08_26/math.py | # SPDX-License-Identifier: Apache-2.0
def add(a, b):
return a + b |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/scripts/get_world_pos.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
from pxr import Usd, Gf
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Xform/Cube")
matrix:Gf.Matrix4d = omni.usd.get_world_transform_matrix(prim, time_code=Usd.TimeCode.Default())
translation = matrix.ExtractTranslation()
print(translation) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/scripts/mouse_cursor_shape.py | # SPDX-License-Identifier: Apache-2.0
####################################
# MUST ENABLE omni.kit.window.cursor
####################################
import carb
import omni.kit.window.cursor
cursor = omni.kit.window.cursor.get_main_window_cursor()
# OPTIONS:
# carb.windowing.CursorStandardShape.ARROW
# carb.windowing.CursorStandardShape.IBEAM
# carb.windowing.CursorStandardShape.VERTICAL_RESIZE
# carb.windowing.CursorStandardShape.HORIZONTAL_RESIZE
# carb.windowing.CursorStandardShape.HAND
# carb.windowing.CursorStandardShape.CROSSHAIR
cursor.override_cursor_shape(carb.windowing.CursorStandardShape.CROSSHAIR)
# clear back to arrow
cursor.clear_overridden_cursor_shape() |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/scripts/refresh_combobox.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
def next_num(n):
while True:
yield n
n += 1
my_window = ui.Window("Example Window", width=300, height=300)
item_changed_sub = None
with my_window.frame:
with ui.VStack():
combo = ui.ComboBox(0, "Option1", "Option2", "Option3")
# I'm just using this to generate unique data
nums = next_num(0)
def clicked():
# clear the list
items = combo.model.get_item_children()
for item in items:
combo.model.remove_item(item)
# generate a new list
for x in range(5):
combo.model.append_child_item(None, ui.SimpleIntModel(next(nums)))
ui.Button("Regenerate Combo", clicked_fn=clicked) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/scripts/focus_prim.py | # SPDX-License-Identifier: Apache-2.0
#######################################
# MUST ENABLE omni.kit.viewport.utility
#######################################
from omni.kit.viewport.utility import get_active_viewport, frame_viewport_selection
import omni.usd
# Select what you want to focus on
selection = omni.usd.get_selection()
selection.set_selected_prim_paths(["/World/Cube"], True)
# focus on selection
active_viewport = get_active_viewport()
if active_viewport:
frame_viewport_selection(active_viewport) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/scripts/corner_rounding.py | # SPDX-License-Identifier: Apache-2.0
import omni.ui as ui
my_window = ui.Window("Example Window", width=300, height=300)
with my_window.frame:
with ui.VStack():
ui.Rectangle(style={
"background_color": ui.color(1.0, 0.0, 0.0),
"border_radius":20.0
})
ui.Rectangle(style={
"background_color": ui.color(0.0, 1.0, 0.0),
"border_radius":20.0,
"corner_flag": ui.CornerFlag.BOTTOM
})
ui.Rectangle(style={
"background_color": ui.color(0.0, 0.0, 1.0),
"border_radius":20.0,
"corner_flag": ui.CornerFlag.TOP
})
ui.Rectangle(style={
"background_color": ui.color(1.0, 0.0, 1.0),
"border_radius":20.0,
"corner_flag": ui.CornerFlag.TOP_RIGHT
}) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-08-26: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-08-26"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_08_26".
[[python.module]]
name = "maticodes.doh_2022_08_26"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_26/docs/README.md | # Developer Office Hour - 08/26/2022
This is the sample code from the Developer Office Hour held on 08/26/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I execute arbitrary code from VSCode in Omniverse?
- How do I create omni.ui.Rectangle with only top or bottom rounded corners?
- How do I update a list of items in a ui.ComboBox without rebuilding the widget?
- How do I change the shape of the mouse cursor?
- How do I get the world position of a prim?
- What are the conventions for naming extensions?
- How do I add a custom window in the Window menu?
- How do I share Python code between extensions?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_26/maticodes/doh_2023_05_26/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_05_26] Dev Office Hours Extension (2023-05-26) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_05_26] Dev Office Hours Extension (2023-05-26) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_26/maticodes/doh_2023_05_26/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_26/scripts/get_references.py | # SPDX-License-Identifier: Apache-2.0
import omni.usd
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Xform")
refs = prim.GetMetadata("references").ApplyOperations([])
for ref in refs:
print(ref.primPath)
print(ref.assetPath)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_26/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-05-26: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-05-26"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_05_26".
[[python.module]]
name = "maticodes.doh_2023_05_26"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_26/docs/README.md | # Developer Office Hour - 05/26/2023
This is the sample code from the Developer Office Hour held on 05/26/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:29 - How do I get an Omniverse app to pick up a new environment variable?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/maticodes/doh_2023_04_07/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_04_07] Dev Office Hours Extension (2023-04-07) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_04_07] Dev Office Hours Extension (2023-04-07) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/maticodes/doh_2023_04_07/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/scripts/current_frame_number.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.timeline
itimeline = omni.timeline.get_timeline_interface()
current_seconds = itimeline.get_current_time()
fps = itimeline.get_time_codes_per_seconds()
current_frame = current_seconds * fps
print(f"Current Frame: {current_frame}") |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/scripts/get_local_transform.py | # SPDX-License-Identifier: Apache-2.0
from pxr import Gf, UsdGeom, Usd
import omni.usd
def decompose_matrix(mat: Gf.Matrix4d):
reversed_ident_mtx = reversed(Gf.Matrix3d())
translate = mat.ExtractTranslation()
scale = Gf.Vec3d(*(v.GetLength() for v in mat.ExtractRotationMatrix()))
#must remove scaling from mtx before calculating rotations
mat.Orthonormalize()
#without reversed this seems to return angles in ZYX order
rotate = Gf.Vec3d(*reversed(mat.ExtractRotation().Decompose(*reversed_ident_mtx)))
return translate, rotate, scale
stage = omni.usd.get_context().get_stage()
prim = stage.GetPrimAtPath("/World/Cube")
xform = UsdGeom.Xformable(prim)
local_transformation: Gf.Matrix4d = xform.GetLocalTransformation()
print(decompose_matrix(local_transformation))
def get_local_rot(prim: Usd.Prim):
return prim.GetAttribute("xformOp:rotateXYZ").Get()
print(get_local_rot(prim))
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/scripts/sceneui_behavior.py | # SPDX-License-Identifier: Apache-2.0
from omni.kit.viewport.utility import get_active_viewport_window
import omni.ui as ui
from omni.kit.scripting import BehaviorScript
from omni.ui import scene as sc
from omni.ui import color as cl
class NewScript(BehaviorScript):
def on_init(self):
print(f"{__class__.__name__}.on_init()->{self.prim_path}")
self.viewport_window = get_active_viewport_window()
self.frame = self.viewport_window.get_frame("Super Duper Cool!")
def on_destroy(self):
print(f"{__class__.__name__}.on_destroy()->{self.prim_path}")
def test(self):
print("Hello")
def on_play(self):
print(f"{__class__.__name__}.on_play()->{self.prim_path}")
with self.frame:
# Create a default SceneView (it has a default camera-model)
self._scene_view = sc.SceneView()
# Add the manipulator into the SceneView's scene
with self._scene_view.scene:
sc.Rectangle(5, 5, thickness=2, wireframe=False, color=cl.red)
# Register the SceneView with the Viewport to get projection and view updates
self.viewport_window.viewport_api.add_scene_view(self._scene_view)
def on_pause(self):
print(f"{__class__.__name__}.on_pause()->{self.prim_path}")
def on_stop(self):
print(f"{__class__.__name__}.on_stop()->{self.prim_path}")
if self._scene_view:
# Empty the SceneView of any elements it may have
self._scene_view.scene.clear()
# Be a good citizen, and un-register the SceneView from Viewport updates
if self.viewport_window:
self.viewport_window.viewport_api.remove_scene_view(self._scene_view)
# Remove our references to these objects
self._scene_view = None
self.frame.destroy()
def on_update(self, current_time: float, delta_time: float):
# print(f"{__class__.__name__}.on_update(current_time={current_time}, delta_time={delta_time})->{self.prim_path}")
pass
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-04-07: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-04-07"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_04_07".
[[python.module]]
name = "maticodes.doh_2023_04_07"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_04_07/docs/README.md | # Developer Office Hour - 04/07/2023
This is the sample code from the Developer Office Hour held on 04/07/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- Where can I find extension API documentation?
- How do I get the current frame number?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/maticodes/doh_2023_05_05/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_05_05] Dev Office Hours Extension (2023-05-05) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_05_05] Dev Office Hours Extension (2023-05-05) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/maticodes/doh_2023_05_05/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/scripts/omnilive.py | # SPDX-License-Identifier: Apache-2.0
from omni.kit.usd.layers import get_live_syncing
import omni.client
import asyncio
UNIQUE_SESSION_NAME = "my_unique_session"
# Get the interface
live_syncing = get_live_syncing()
# Create a session
live_session = live_syncing.create_live_session(UNIQUE_SESSION_NAME)
# Simulate joining a session
for session in live_syncing.get_all_live_sessions():
if session.name == UNIQUE_SESSION_NAME:
live_syncing.join_live_session(session)
break
# Merge changes into base layer and disconnect from live session
loop = asyncio.get_event_loop()
loop.create_task(live_syncing.merge_and_stop_live_session_async(layer_identifier=session.base_layer_identifier))
# Disconnect from live session without merging. When you reconnect, changes will still be in your live session.
live_syncing.stop_live_session(session.base_layer_identifier)
# Delete the session once you're all done. You can add a callback for the second arg to know if completed.
omni.client.delete_with_callback(session.url, lambda: None) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/scripts/change_renderer.py | # SPDX-License-Identifier: Apache-2.0
# RTX Path Tracing
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("omni.kit.viewport.actions", "set_renderer_rtx_pathtracing")
action.execute()
# RTX Real-Time
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("omni.kit.viewport.actions", "set_renderer_rtx_realtime")
action.execute()
# Storm
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("omni.kit.viewport.actions", "set_renderer_pxr_storm")
action.execute()
# Iray
import omni.kit.actions.core
action_registry = omni.kit.actions.core.get_action_registry()
action = action_registry.get_action("omni.kit.viewport.actions", "set_renderer_iray")
action.execute() |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/scripts/change_variants.py | # SPDX-License-Identifier: Apache-2.0
from pxr import Usd, UsdGeom
import omni.usd
stage = omni.usd.get_context().get_stage()
world_prim = stage.GetPrimAtPath("/World")
vset = world_prim.GetVariantSets().AddVariantSet('shapes')
vset.AddVariant('cube')
vset.AddVariant('sphere')
vset.AddVariant('cone')
vset.SetVariantSelection('cube')
with vset.GetVariantEditContext():
UsdGeom.Cube.Define(stage, "/World/Cube")
vset.SetVariantSelection('sphere')
with vset.GetVariantEditContext():
UsdGeom.Sphere.Define(stage, "/World/Sphere")
vset.SetVariantSelection('cone')
with vset.GetVariantEditContext():
UsdGeom.Cone.Define(stage, "/World/Cone")
stage = omni.usd.get_context().get_stage()
world_prim = stage.GetPrimAtPath("/World")
vsets = world_prim.GetVariantSets()
vset = vsets.GetVariantSet("shapes")
vset.SetVariantSelection("cone") |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-05-05: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-05-05"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_05_05".
[[python.module]]
name = "maticodes.doh_2023_05_05"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_05_05/docs/README.md | # Developer Office Hour - 05/05/2023
This is the sample code from the Developer Office Hour held on 05/05/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- 02:05 - How can I programmatically create and join an OmniLive session?
- 14:17 - How can I programmatically change the renderer to RTX Real-Time, RTX Path Tracing, Iray, or Storm?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/maticodes/doh_2022_12_09/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_12_09] Dev Office Hours Extension (2022-12-09) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_12_09] Dev Office Hours Extension (2022-12-09) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/maticodes/doh_2022_12_09/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/scripts/screenshot_viewport.py | # SPDX-License-Identifier: Apache-2.0
from omni.kit.viewport.utility import get_active_viewport, capture_viewport_to_file
vp_api = get_active_viewport()
capture_viewport_to_file(vp_api, r"C:\temp\screenshot.png") |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/scripts/collect_asset.py | # SPDX-License-Identifier: Apache-2.0
import asyncio
from omni.kit.tool.collect.collector import Collector
async def collect_async(input_usd, output_dir, usd_only, flat_collection, mtl_only, prog_cb, finish_cb):
"""Collect input_usd related assets to output_dir.
Args:
input_usd (str): The usd stage to be collected.
output_dir (str): The target dir to collect the usd stage to.
usd_only (bool): Collects usd files only or not. It will ignore all asset types.
flat_collection (bool): Collects stage without keeping the original dir structure.
mtl_only (bool): Collects material and textures only or not. It will ignore all other asset types.
prog_cb: Progress callback function
finish_cb: Finish callback function
"""
collector = Collector(input_usd, output_dir, usd_only, flat_collection, mtl_only)
await collector.collect(prog_cb, finish_cb)
def finished():
print("Finished!")
asyncio.ensure_future(collect_async(r"C:\temp\bookcase.usd", r"C:\temp\test_collect",
False, False, False, None, finished)) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-12-09: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-12-09"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_12_09".
[[python.module]]
name = "maticodes.doh_2022_12_09"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_09/docs/README.md | # Developer Office Hour - 12/09/2022
This is the sample code from the Developer Office Hour held on 12/09/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I Collect Asset using Python to share a full Omniverse project?
- How do I capture a screenshot of the viewport?
- How do I change the visibility of a prim using Action Graph?
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_03_31/maticodes/doh_2023_03_31/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
import omni.audioplayer
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
# audio_player = omni.audioplayer.AudioPlayer()
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_03_31] Dev Office Hours Extension (2023-03-31) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_03_31] Dev Office Hours Extension (2023-03-31) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_03_31/maticodes/doh_2023_03_31/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_03_31/scripts/viewport_ui.py | # SPDX-License-Identifier: Apache-2.0
from omni.kit.scripting import BehaviorScript
from omni.kit.viewport.utility import get_active_viewport_window
import omni.ui as ui
class ViewportUi(BehaviorScript):
def on_init(self):
# print(f"{__class__.__name__}.on_init()->{self.prim_path}")
self.frame = None
def on_destroy(self):
print(f"{__class__.__name__}.on_destroy()->{self.prim_path}")
if self.frame is not None:
self.frame.destroy()
self.frame = None
def test(self):
print("Hello World!")
def on_play(self):
print(f"{__class__.__name__}.on_play()->{self.prim_path}")
self.viewport_window = get_active_viewport_window()
self.frame = self.viewport_window.get_frame("Really cool id")
with self.frame:
with ui.Placer(offset_x=10, offset_y=50):
with ui.HStack():
ui.Button("Test", width=50, height=50, clicked_fn=self.test)
def on_pause(self):
print(f"{__class__.__name__}.on_pause()->{self.prim_path}")
def on_stop(self):
print(f"{__class__.__name__}.on_stop()->{self.prim_path}")
if self.frame is not None:
self.frame.destroy()
self.frame = None
def on_update(self, current_time: float, delta_time: float):
# print(f"{__class__.__name__}.on_update(current_time={current_time}, delta_time={delta_time})->{self.prim_path}")
pass
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_03_31/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-03-31: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-03-31"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
"omni.audioplayer" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_03_31".
[[python.module]]
name = "maticodes.doh_2023_03_31"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_03_31/docs/README.md | # Developer Office Hour - 03/31/2023
This is the sample code from the Developer Office Hour held on 03/31/2023, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- How do I add UI widgets to the viewport in a BehaviorScript (Python Scripting Component)?
- How do I add extension dependencies to my custom extension? |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/maticodes/doh_2022_12_16/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2022_12_16] Dev Office Hours Extension (2022-12-16) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2022_12_16] Dev Office Hours Extension (2022-12-16) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/maticodes/doh_2022_12_16/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/scripts/script_node.py | # SPDX-License-Identifier: Apache-2.0
# This script is executed the first time the script node computes, or the next time it computes after this script
# is modified or the 'Reset' button is pressed.
# The following callback functions may be defined in this script:
# setup(db): Called immediately after this script is executed
# compute(db): Called every time the node computes (should always be defined)
# cleanup(db): Called when the node is deleted or the reset button is pressed (if setup(db) was called before)
# Defining setup(db) and cleanup(db) is optional, but if compute(db) is not defined then this script node will run
# in legacy mode, where the entire script is executed on every compute and the callback functions above are ignored.
# Available variables:
# db: og.Database The node interface, attributes are db.inputs.data, db.outputs.data.
# Use db.log_error, db.log_warning to report problems.
# Note that this is available outside of the callbacks only to support legacy mode.
# og: The OmniGraph module
# Import statements, function/class definitions, and global variables may be placed outside of the callbacks.
# Variables may also be added to the db.internal_state state object.
# Example code snippet:
import math
UNITS = "cm"
def calculate_circumfrence(radius):
return 2 * math.pi * radius
def setup(db):
state = db.internal_state
state.radius = 1
def compute(db):
state = db.internal_state
circumfrence = calculate_circumfrence(state.radius)
print(f"{circumfrence} {UNITS}")
print(f"My Input: {db.inputs.my_input}")
db.outputs.foo = False
state.radius += 1
# To see more examples, click on the Code Snippets button below. |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/scripts/file_import.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/kit/docs/omni.kit.window.file_importer/latest/Overview.html
from omni.kit.window.file_importer import get_file_importer
from typing import List
file_importer = get_file_importer()
def import_handler(filename: str, dirname: str, selections: List[str] = []):
# NOTE: Get user inputs from self._import_options, if needed.
print(f"> Import '{filename}' from '{dirname}' or selected files '{selections}'")
file_importer.show_window(
title="Import File",
import_handler=import_handler
)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/scripts/file_exporter.py | # SPDX-License-Identifier: Apache-2.0
# https://docs.omniverse.nvidia.com/kit/docs/omni.kit.window.file_exporter/latest/index.html
from omni.kit.window.file_exporter import get_file_exporter
from typing import List
file_exporter = get_file_exporter()
def export_handler(filename: str, dirname: str, extension: str = "", selections: List[str] = []):
# NOTE: Get user inputs from self._export_options, if needed.
print(f"> Export As '{filename}{extension}' to '{dirname}' with additional selections '{selections}'")
file_exporter.show_window(
title="Export As ...",
export_button_label="Save",
export_handler=export_handler,
) |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2022-12-16: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2022-12-16"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2022_12_16".
[[python.module]]
name = "maticodes.doh_2022_12_16"
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_16/docs/README.md | # Developer Office Hour - 12/16/2022
This is the sample code from the Developer Office Hour held on 12/16/2022, Mati answered some developer questions
from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD.
## Questions
- Where are the API docs for extensions?
- How do I browse for a file for import?
- How do I browse for a file for export?
- How do I use the Script Node? (using compute function)
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/maticodes/doh_2023_09_08/extension.py | # SPDX-License-Identifier: Apache-2.0
import carb
import omni.ext
import omni.ui as ui
class MyWindow(ui.Window):
def __init__(self, title: str = None, **kwargs):
super().__init__(title, **kwargs)
self.frame.set_build_fn(self._build_window)
def _build_window(self):
with ui.ScrollingFrame():
with ui.VStack(height=0):
ui.Label("My Label")
def clicked():
carb.log_info("Button Clicked!")
ui.Button("Click Me", clicked_fn=clicked)
class MyExtension(omni.ext.IExt):
def on_startup(self, ext_id):
carb.log_info("[maticodes.doh_2023_09_08] Dev Office Hours Extension (2023-09-08) startup")
self._window = MyWindow("MyWindow", width=300, height=300)
def on_shutdown(self):
carb.log_info("[maticodes.doh_2023_09_08] Dev Office Hours Extension (2023-09-08) shutdown")
if self._window:
self._window.destroy()
self._window = None
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/maticodes/doh_2023_09_08/__init__.py | # SPDX-License-Identifier: Apache-2.0
from .extension import *
|
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/scripts/sub_event.py | # SPDX-License-Identifier: Apache-2.0
# App/Subscribe to Update Events
import carb.events
import omni.kit.app
update_stream = omni.kit.app.get_app().get_update_event_stream()
def on_update(e: carb.events.IEvent):
print(f"Update: {e.payload['dt']}")
sub = update_stream.create_subscription_to_pop(on_update, name="My Subscription Name")
# Remember to cleanup your subscription when you're done with them (e.g. during shutdown)
# sub = None |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/scripts/trigger_every_N.py |
# App/Subscribe to Update Events
import carb.events
import omni.kit.app
import omni.timeline
update_stream = omni.kit.app.get_app().get_update_event_stream()
every_N = 5 # seconds
elapsed = 0
update_sub = None
def on_update(e: carb.events.IEvent):
global elapsed
elapsed += e.payload["dt"]
if elapsed >= every_N:
print(f"{every_N} seconds have passed. Fire!")
elapsed = 0
# print(f"Update: {elapsed}")
def on_play(e: carb.events.IEvent):
global update_sub
update_sub = update_stream.create_subscription_to_pop(on_update, name="My Subscription Name")
def on_stop(e: carb.events.IEvent):
global update_sub
update_sub = None
itimeline: omni.timeline.ITimeline = omni.timeline.get_timeline_interface()
play_sub = itimeline.get_timeline_event_stream().create_subscription_to_pop_by_type(omni.timeline.TimelineEventType.PLAY, on_play)
stop_sub = itimeline.get_timeline_event_stream().create_subscription_to_pop_by_type(omni.timeline.TimelineEventType.STOP, on_stop)
# Remember to unsub by setting variables to None.
update_sub = None
play_sub = None
stop_sub = None |
mati-nvidia/developer-office-hours/exts/maticodes.doh_2023_09_08/config/extension.toml | [package]
# Semantic Versionning is used: https://semver.org/
version = "1.0.0"
# The title and description fields are primarily for displaying extension info in UI
title = "2023-09-08: Dev Office Hours"
description="Sample code from the Dev Office Hour held on 2023-09-08"
# Path (relative to the root) or content of readme markdown file for UI.
readme = "docs/README.md"
# URL of the extension source repository.
repository = ""
# One of categories for UI.
category = "Example"
# Keywords for the extension
keywords = ["kit", "example"]
# Use omni.ui to build simple UI
[dependencies]
"omni.kit.uiapp" = {}
# Main python module this extension provides, it will be publicly available as "import maticodes.doh_2023_09_08".
[[python.module]]
name = "maticodes.doh_2023_09_08"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.