diff --git a/exts/maticodes.viewport.reticle/config/extension.toml b/exts/maticodes.viewport.reticle/config/extension.toml index f815761..91753c0 100644 --- a/exts/maticodes.viewport.reticle/config/extension.toml +++ b/exts/maticodes.viewport.reticle/config/extension.toml @@ -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 "] diff --git a/exts/maticodes.viewport.reticle/docs/CHANGELOG.md b/exts/maticodes.viewport.reticle/docs/CHANGELOG.md index 1dc5804..cfcbed7 100644 --- a/exts/maticodes.viewport.reticle/docs/CHANGELOG.md +++ b/exts/maticodes.viewport.reticle/docs/CHANGELOG.md @@ -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. diff --git a/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/extension.py b/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/extension.py index 3d82454..6c8df75 100644 --- a/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/extension.py +++ b/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/extension.py @@ -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): diff --git a/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/views.py b/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/views.py index 9df4ecb..9fc56f2 100644 --- a/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/views.py +++ b/exts/maticodes.viewport.reticle/maticodes/viewport/reticle/views.py @@ -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) @@ -49,17 +50,15 @@ 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): @@ -70,8 +69,9 @@ def on_window_changed(self, *args): 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) + res = self.vp_win.viewport_api.resolution + width = res[0] + height = res[1] self._aspect_ratio = width / height self.build_viewport_overlay() @@ -86,8 +86,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():