Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
matiascodesal committed Sep 10, 2022
2 parents daea205 + 7444be3 commit b34c6b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion exts/maticodes.viewport.reticle/config/extension.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
version = "1.3.0"
version = "1.4.0"
title = "Camera Reticle"
description="Adds a camera reticle featuring composition guidelines, safe area guidelines, and letterbox."
authors=["Matias Codesal <[email protected]>"]
Expand Down
5 changes: 5 additions & 0 deletions exts/maticodes.viewport.reticle/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [1.4.0] - 2022-09-09
### Added
- Fixed bad use of viewport window frame for VP Next
- Now use ViewportAPI.subscribe_to_view_change() on VP Next

## [1.3.0] - 2022-07-10
### Added
- `omni.kit.viewport.utility` dependency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def on_startup(self, ext_id):
viewport_window = get_active_viewport_window()
if viewport_window is not None:
reticle_model = ReticleModel()
self.reticle = ReticleOverlay(reticle_model, viewport_window)
self.reticle = ReticleOverlay(reticle_model, viewport_window, ext_id)
self.reticle.build_viewport_overlay()

def on_shutdown(self):
Expand Down
44 changes: 24 additions & 20 deletions exts/maticodes.viewport.reticle/maticodes/viewport/reticle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,27 @@ class ReticleOverlay:
"""
_instances = []

def __init__(self, model: ReticleModel, vp_win):
def __init__(self, model: ReticleModel, vp_win: ui.Window, ext_id: str):
"""ReticleOverlay constructor
Args:
model (ReticleModel): The reticle model
vp_win (Window): The viewport window to build the overlay on.
ext_id (str): The extension id.
"""
self.model = model
self.vp_win = vp_win
self.ext_id = ext_id
# Rebuild the overlay whenever the viewport window changes
self.vp_win.set_height_changed_fn(self.on_window_changed)
self.vp_win.set_width_changed_fn(self.on_window_changed)
settings = carb.settings.get_settings()
self._viewport_subs = []
self._viewport_subs.append(settings.subscribe_to_node_change_events(constants.SETTING_RESOLUTION_WIDTH,
self.on_window_changed))
self._viewport_subs.append(settings.subscribe_to_node_change_events(constants.SETTING_RESOLUTION_HEIGHT,
self.on_window_changed))
self._viewport_subs.append(settings.subscribe_to_node_change_events(constants.SETTING_RESOLUTION_FILL,
self.on_window_changed))
self._view_change_sub = None
try:
# VP2 resolution change sub
self._view_change_sub = self.vp_win.viewport_api.subscribe_to_view_change(self.on_window_changed)
except AttributeError:
carb.log_info("Using Viewport Legacy: Reticle will not automatically update on resolution changes.")

# Rebuild the overlay whenever the model changes
self.model.add_reticle_changed_fn(self.build_viewport_overlay)
ReticleOverlay._instances.append(self)
Expand All @@ -49,29 +50,33 @@ def get_instances(cls):
"""Get all created instances of ReticleOverlay"""
return cls._instances

def __del__(self):
self.destroy()

def destroy(self):
settings = carb.settings.get_settings()
for sub in self._viewport_subs:
settings.unsubscribe_to_change_events(sub)
self._viewport_subs = None
self._view_change_sub = None
self.scene_view.scene.clear()
self.scene_view = None
self.reticle_menu.destroy()
self.reticle_menu = None
self.vp_win.frame.clear()
self.vp_win.destroy()
self.vp_win = None

def on_window_changed(self, *args):
"""Update aspect ratio and rebuild overlay when viewport window changes."""
if self.vp_win is None:
return

settings = carb.settings.get_settings()
fill = settings.get(constants.SETTING_RESOLUTION_FILL)
if type(self.vp_win).__name__ == "LegacyViewportWindow":
fill = settings.get(constants.SETTING_RESOLUTION_FILL)
else:
fill = self.vp_win.viewport_api.fill_frame

if fill:
width = self.vp_win.frame.computed_width + 8
height = self.vp_win.height
else:
width = settings.get(constants.SETTING_RESOLUTION_WIDTH)
height = settings.get(constants.SETTING_RESOLUTION_HEIGHT)
width, height = self.vp_win.viewport_api.resolution
self._aspect_ratio = width / height
self.build_viewport_overlay()

Expand All @@ -86,8 +91,7 @@ def get_aspect_ratio_flip_threshold(self):
def build_viewport_overlay(self, *args):
"""Build all viewport graphics and ReticleMenu button."""
if self.vp_win is not None:
self.vp_win.frame.clear()
with self.vp_win.frame:
with self.vp_win.get_frame(self.ext_id):
with ui.ZStack():
# Set the aspect ratio policy depending if the viewport is wider than it is taller or vice versa.
if self.vp_win.width / self.vp_win.height > self.get_aspect_ratio_flip_threshold():
Expand Down

0 comments on commit b34c6b6

Please sign in to comment.