file_path
stringlengths
21
202
content
stringlengths
19
1.02M
size
int64
19
1.02M
lang
stringclasses
8 values
avg_line_length
float64
5.88
100
max_line_length
int64
12
993
alphanum_fraction
float64
0.27
0.93
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/what_is_sc.py
# SPDX-License-Identifier: Apache-2.0 from omni.ui import scene as sc
70
Python
22.666659
37
0.771429
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/get_local.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/Cube_01") scale, rotate, rot_order, translate = omni.usd.get_local_transform_SRT(prim, time=Usd.TimeCode.Default()) print(scale, rotate, rot_order, translate) # Gf.Vec3d # (Double, Double, Double) # Gf.Matrix4d # (Double, Double, Double, Double) # (Double, Double, Double, Double) # (Double, Double, Double, Double) # (Double, Double, Double, Double) matrix:Gf.Matrix4d = omni.usd.get_local_transform_matrix(prim, time_code=Usd.TimeCode.Default()) print(matrix)
622
Python
28.666665
105
0.731511
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/define_ui_colors.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui from omni.ui import color as cl my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): ui.Label("AABBGGRR", style={"color": 0xFF00FFFF}) # STAY AWAY FROM ui.Label("Float RGB", style={"color": cl(1.0, 1.0, 0.0)}) ui.Label("Float RGBA", style={"color": cl(1.0, 1.0, 0.0, 0.5)}) ui.Label("Int RGB", style={"color": cl(255, 255, 0)}) ui.Label("Int RGBA", style={"color": cl(255, 255, 0, 128)}) ui.Label("Oops RGB", style={"color": cl(1, 1, 0)}) ui.Label("Web Hex RGB", style={"color": cl("#FFFF00")}) ui.Label("Web Hex rgb", style={"color": cl("#ffff00")}) ui.Label("Web Hex RGBA", style={"color": cl("#FFFF0088")}) ui.Label("Float RGB White", style={"color": cl(1.0, 1.0, 1.0)}) ui.Label("Float RGB 50%", style={"color": cl(0.5, 0.5, 0.5)}) ui.Label("Float Greyscale White", style={"color": cl(1.0)}) ui.Label("Float Greyscale 50%", style={"color": cl(0.5)}) ui.Label("Int Greyscale White", style={"color": cl(255)}) ui.Label("Int Greyscale 50%", style={"color": cl(128)}) ui.Label("Web Color Name", style={"color": cl.yellow})
1,305
Python
39.812499
74
0.555556
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/add_menu.py
# SPDX-License-Identifier: Apache-2.0 import omni.kit.ui menu_path = "File/Foo" menu_path2 = "File/Foo/Bar" def on_menu_click(menu_path, toggled): print(menu_path) print(toggled) menu = omni.kit.ui.get_editor_menu().add_item(menu_path, on_menu_click) menu = omni.kit.ui.get_editor_menu().add_item(menu_path2, on_menu_click, True) omni.kit.ui.get_editor_menu().remove_item(menu) import omni.kit.menu.utils from omni.kit.menu.utils import MenuItemDescription menu_item = MenuItemDescription( name="Hello World!", glyph="save.svg", onclick_fn=lambda: print("Hello World!"), # hotkey=( # carb.input.KEYBOARD_MODIFIER_FLAG_CONTROL | carb.input.KEYBOARD_MODIFIER_FLAG_ALT, # carb.input.KeyboardInput.S, #), ) menus = [menu_item] omni.kit.menu.utils.add_menu_items([menu_item], "File") omni.kit.menu.utils.remove_menu_items([menu_item], "File", rebuild_menus=True) # omni.kit.ui.get_editor_menu().convert_to_new_menu
963
Python
25.054053
91
0.699896
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/scripts/what_is_cl.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui from omni.ui import color as cl # import omni.ui.color as color my_window = ui.Window("Example Window", width=300, height=300) with my_window.frame: with ui.VStack(): ui.Label("Hello World!", style={"color": cl(0.0, 1.0, 0.0)})
303
Python
22.384614
68
0.673267
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_09_02/docs/README.md
# Developer Office Hour - 09/02/2022 This is the sample code from the Developer Office Hour held on 09/02/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - What's the difference between a shape and a mesh? - How do I import cl? - How do I import sc? - How do I define UI colors? - How do I add an item to a menu?
405
Markdown
39.599996
194
0.748148
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/maticodes/doh_2022_11_18/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext from omni.kit.viewport.utility import get_active_viewport_window import omni.ui as ui class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): carb.log_info("[maticodes.doh_2022_11_18] Dev Office Hours Extension (2022-11-18) startup") self.custom_frame = None viewport_window = get_active_viewport_window() if viewport_window is not None: self.custom_frame: ui.Frame = viewport_window.get_frame(ext_id) with self.custom_frame: with ui.VStack(): ui.Spacer() with ui.HStack(height=0): ui.Spacer() ui.Button("Hello", width=0, height=0) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_11_18] Dev Office Hours Extension (2022-11-18) shutdown") self.custom_frame.destroy() self.custom_frame = None
990
Python
32.033332
100
0.59596
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/scripts/placer_model.py
# SPDX-License-Identifier: Apache-2.0 import omni.ui as ui my_window = ui.Window("Example Window", width=300, height=300) model = ui.SimpleFloatModel() sub = None with my_window.frame: with ui.VStack(): ui.FloatSlider(model=model) def body_moved(body, model): if body.offset_x.value > 100: body.offset_x.value = 100 elif body.offset_x.value < 0: body.offset_x.value = 0 model.set_value(body.offset_x.value / 100.0) body = ui.Placer(draggable=True, drag_axis=ui.Axis.X, offset_x=0) with body: rect = ui.Rectangle(width=25, height=25, style={"background_color": ui.color.red}) body.set_offset_x_changed_fn(lambda _, b=body, m=model: body_moved(b, m)) def slider_moved(model, body): body.offset_x.value = model.as_float * 100 sub = model.subscribe_value_changed_fn(lambda m=model, b=body: slider_moved(m, b))
996
Python
34.607142
94
0.589357
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_11_18/docs/README.md
# Developer Office Hour - 11/18/2022 This is the sample code from the Developer Office Hour held on 11/18/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I add widgets on top of the viewport? (ViewportWindow.get_frame) - How do I use value model with ui.Placer? - How do I see all of the code from the UI documentation examples?
431
Markdown
46.999995
114
0.770302
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/scripts/usd_update_stream.py
# SPDX-License-Identifier: Apache-2.0 import omni.usd from pxr import UsdGeom, Gf stage = omni.usd.get_context().get_stage() cube = stage.GetPrimAtPath("/World/Cube") 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) world_transform = omni.usd.get_world_transform_matrix(prim) translation: Gf.Vec3d = world_transform.ExtractTranslation() rotation: Gf.Rotation = world_transform.ExtractRotation() scale: Gf.Vec3d = Gf.Vec3d(*(v.GetLength() for v in world_transform.ExtractRotationMatrix())) print(translation, rotation, scale) cube_move_sub = omni.usd.get_watcher().subscribe_to_change_info_path(cube.GetPath(), print_pos)
813
Python
37.761903
97
0.719557
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/scripts/create_viewport.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.kit.viewport.utility as vp_utils from omni.kit.widget.viewport.api import ViewportAPI vp_window = vp_utils.create_viewport_window("My Viewport") vp_window.viewport_api.fill_frame = True vp_api: ViewportAPI = vp_window.viewport_api carb.settings.get_settings().set('/rtx/rendermode', "PathTracing") vp_api.set_hd_engine("rtx")
392
Python
27.071427
66
0.770408
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_10_07/docs/README.md
# Developer Office Hour - 10/07/2022 This is the sample code from the Developer Office Hour held on 10/07/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I create another viewport? - How do I use the Script Node?
315
Markdown
38.499995
114
0.771429
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/maticodes/doh_2022_12_02/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): with ui.HStack(height=0): ui.Label("My Label") MyCoolComponent() def clicked(): carb.log_info("Button Clicked!") ui.Button("Click Me", clicked_fn=clicked) class MyCoolComponent: def __init__(self): with ui.VStack(): ui.Label("Moar labels- asdfasdfasdf") ui.Label("Even moar labels") with ui.HStack(): ui.Button("Ok") ui.Button("Cancel") class MyExtension(omni.ext.IExt): def on_startup(self, ext_id): """_summary_ Args: ext_id (_type_): _description_ """ carb.log_info("[maticodes.doh_2022_12_02] Dev Office Hours Extension (2022-12-02) startup") self._window = MyWindow("MyWindow", width=300, height=300) def on_shutdown(self): carb.log_info("[maticodes.doh_2022_12_02] Dev Office Hours Extension (2022-12-02) shutdown") if self._window: self._window.destroy() self._window = None
1,442
Python
28.448979
100
0.549237
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/scripts/spawn_objects.py
# SPDX-License-Identifier: Apache-2.0 import carb.events import omni.kit.app import omni.kit.commands import logging time_since_last_create = 0 update_stream = omni.kit.app.get_app().get_update_event_stream() def on_update(e: carb.events.IEvent): global time_since_last_create carb.log_info(f"Update: {e.payload['dt']}") time_since_last_create += e.payload['dt'] carb.log_info(f"time since: {time_since_last_create}") if time_since_last_create > 2: carb.log_info("Creating cube") omni.kit.commands.execute('CreateMeshPrimWithDefaultXform', prim_type='Cube') time_since_last_create = 0 sub = update_stream.create_subscription_to_pop(on_update, name="My Subscription Name") sub = None
745
Python
27.692307
86
0.69396
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_12_02/docs/README.md
# Developer Office Hour - 12/02/2022 This is the sample code from the Developer Office Hour held on 12/02/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I uninstall an extension? - How do I export USDZ? - Where is the extension I was working on? - How do I create complex UI without so much indented Python code?
416
Markdown
40.699996
114
0.769231
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/maticodes/doh_2022_08_12/extension.py
# SPDX-License-Identifier: Apache-2.0 import carb import omni.ext from omni.kit.viewport.utility import get_active_viewport_window import omni.ui as ui from .viewport_scene import ViewportScene from .object_info_model import ObjectInfoModel class MyWindow(ui.Window): def __init__(self, title: str = None, delegate=None, **kwargs): super().__init__(title, **kwargs) self._viewport_scene = None self.obj_info_model = kwargs["obj_info_model"] self.frame.set_build_fn(self._build_window) def _build_window(self): with ui.ScrollingFrame(): with ui.VStack(height=0): ui.Label("My Label 2") ui.StringField() ui.StringField(password_mode=True) def clicked(): self.obj_info_model.populate() ui.Button("Reload Object Info", clicked_fn=clicked) def destroy(self) -> None: return super().destroy() class MyExtension(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): # Get the active Viewport (which at startup is the default Viewport) viewport_window = get_active_viewport_window() # Issue an error if there is no Viewport if not viewport_window: carb.log_error(f"No Viewport Window to add {ext_id} scene to") return # Build out the scene model = ObjectInfoModel() self._viewport_scene = ViewportScene(viewport_window, ext_id, model) self._window = MyWindow("MyWindow", obj_info_model=model, width=300, height=300) def on_shutdown(self): if self._window: self._window.destroy() self._window = None if self._viewport_scene: self._viewport_scene.destroy() self._viewport_scene = None
1,997
Python
31.754098
119
0.618928
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/viewport_popup_notification.py
# SPDX-License-Identifier: Apache-2.0 # https://docs.omniverse.nvidia.com/py/kit/source/extensions/omni.kit.notification_manager/docs/index.html?highlight=omni%20kit%20notification_manager# import carb def clicked_ok(): carb.log_info("User clicked ok") def clicked_cancel(): carb.log_info("User clicked cancel") import omni.kit.notification_manager as nm ok_button = nm.NotificationButtonInfo("OK", on_complete=clicked_ok) cancel_button = nm.NotificationButtonInfo("CANCEL", on_complete=clicked_cancel) notification_info = nm.post_notification( "Notification Example", hide_after_timeout=False, duration=0, status=nm.NotificationStatus.WARNING, button_infos=[ok_button, cancel_button], )
723
Python
27.959999
151
0.755187
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/create_many_prims.py
# SPDX-License-Identifier: Apache-2.0 from pxr import UsdGeom import omni.kit.commands import omni.usd stage = omni.usd.get_context().get_stage() cube_paths = [] for i in range(10): cube_path = omni.usd.get_stage_next_free_path(stage, "/World/Cube", prepend_default_prim=False) cube_paths.append(cube_path) omni.kit.commands.execute("CreatePrim", prim_type="Cube", prim_path=cube_path) # UsdGeom.Cube.Define(stage, cube_path)
445
Python
28.733331
99
0.719101
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/refer_to_child_prim.py
# SPDX-License-Identifier: Apache-2.0 # https://docs.omniverse.nvidia.com/prod_usd/prod_usd/quick-start/hierarchy.html import omni.usd stage = omni.usd.get_context().get_stage() starting_prim = stage.GetPrimAtPath("/World/New") for shape in starting_prim.GetChildren(): print(shape) for shape_child in shape.GetChildren(): print(shape_child) for prim in stage.Traverse(): print(prim)
408
Python
24.562498
80
0.720588
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/create_group_anywhere.py
# SPDX-License-Identifier: Apache-2.0 from pxr import Sdf import omni.kit.commands import omni.usd stage = omni.usd.get_context().get_stage() children = [] for i in range(3): child = omni.usd.get_stage_next_free_path(stage, "/World/Cube", prepend_default_prim=False) children.append(child) omni.kit.commands.execute("CreatePrim", prim_type="Cube", prim_path=child) group_path = Sdf.Path("/World/New/Hello") omni.kit.commands.execute("CreatePrimWithDefaultXformCommand", prim_type="Scope", prim_path=str(group_path)) for child in children: prim = stage.GetPrimAtPath(child) name = prim.GetName() omni.kit.commands.execute("MovePrim", path_from=child, path_to=group_path.AppendPath(name))
715
Python
33.095237
108
0.731469
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/scripts/does_prim_exist.py
# SPDX-License-Identifier: Apache-2.0 from pxr import Usd, UsdGeom import omni.usd stage = omni.usd.get_context().get_stage() prim = stage.GetPrimAtPath("/World/New/Hello") print(prim) print(prim.IsValid()) prim = stage.GetPrimAtPath("/World/New/Fake") print(prim) print(prim.IsValid())
290
Python
19.785713
46
0.737931
mati-nvidia/developer-office-hours/exts/maticodes.doh_2022_08_12/docs/README.md
# Developer Office Hour - 08/12/2022 This is the sample code from the Developer Office Hour held on 08/12/2022, Mati answered some developer questions from the NVIDIA Omniverse forums regarding Kit, Omniverse Code, Python, and USD. ## Questions - How do I create many prims at available prim paths? - How do I create a group at a specific prim path? - Is there a way to check if a prim exists? - How do I refer to the child of a prim without giving the prim path? - How can I create a notification popup in the viewport with a log message? - How do I show labels in the viewport for multiple prims? ...
605
Markdown
45.615381
114
0.758678