From 3f5902cebfa4078af928ef5fe88a5f58a96d75ad Mon Sep 17 00:00:00 2001 From: Octi Zhang Date: Thu, 1 Oct 2026 15:50:59 -0700 Subject: [PATCH] Fix first RTX capture and simplify color output aliases --- .../newton-rtx-first-capture.fixed.rst | 2 ++ .../newton/newton_visualizer.py | 26 +++++--------- .../test/test_newton_adapter.py | 34 ++++--------------- .../test/visualizer_integration_utils.py | 4 +++ 4 files changed, 20 insertions(+), 46 deletions(-) create mode 100644 source/isaaclab_visualizers/changelog.d/newton-rtx-first-capture.fixed.rst diff --git a/source/isaaclab_visualizers/changelog.d/newton-rtx-first-capture.fixed.rst b/source/isaaclab_visualizers/changelog.d/newton-rtx-first-capture.fixed.rst new file mode 100644 index 000000000000..ee9cf9a1eaab --- /dev/null +++ b/source/isaaclab_visualizers/changelog.d/newton-rtx-first-capture.fixed.rst @@ -0,0 +1,2 @@ +* Fixed the first asynchronous Newton RTX frame capture failing to find the color output before viewer warm-up. +* Resolved Newton RTX color-output aliases from the returned render-variable keys without depending on package version metadata. diff --git a/source/isaaclab_visualizers/isaaclab_visualizers/newton/newton_visualizer.py b/source/isaaclab_visualizers/isaaclab_visualizers/newton/newton_visualizer.py index ba742986b436..aab824a7e883 100644 --- a/source/isaaclab_visualizers/isaaclab_visualizers/newton/newton_visualizer.py +++ b/source/isaaclab_visualizers/isaaclab_visualizers/newton/newton_visualizer.py @@ -8,8 +8,6 @@ from __future__ import annotations import contextlib -import functools -import importlib.metadata import logging import math import os @@ -70,20 +68,6 @@ logger = logging.getLogger(__name__) -@functools.cache -def _ovrtx_keys_render_vars_by_prim_path() -> bool: - """Whether the installed ovrtx (0.5 or newer) keys ``frame.render_vars`` by RenderVar prim path. - - Mirrors ``isaaclab_ov.renderers.ovrtx_compat.uses_prim_path_render_vars``, which this package cannot import. - """ - from packaging.version import InvalidVersion, Version - - try: - return Version(importlib.metadata.version("ovrtx")) >= Version("0.5") - except (importlib.metadata.PackageNotFoundError, InvalidVersion): - return False - - def _newton_scalar_base_name(name: str) -> str: """Strip a trailing ``[N]`` component index from a scalar name to get the term base name.""" if name.endswith("]") and "[" in name: @@ -763,8 +747,8 @@ def _render_products(self, products) -> None: # TODO: Workaround until Newton's ViewerRTX accepts both keys. ovrtx 0.5 keys render vars by # prim path ("/Render/Vars/LdrColor"), but ViewerRTX looks up "LdrColor" and silently skips # the blit and capture otherwise, leaving the window black. - if products and _ovrtx_keys_render_vars_by_prim_path(): - for _, product in products.items(): + if products: + for product in products.values(): for frame in product.frames: if "/Render/Vars/LdrColor" in frame.render_vars: frame.render_vars.setdefault("LdrColor", frame.render_vars["/Render/Vars/LdrColor"]) @@ -775,6 +759,12 @@ def get_frame(self) -> np.ndarray: # TODO: Use Newton's public RGB capture API when one becomes available. return np.ascontiguousarray(self._capture_screenshot_pixels()[..., :3]) + def _capture_screenshot_pixels(self) -> np.ndarray: + """Normalize the first asynchronous result before Newton reads its color output.""" + if self._render_products is None and self._render_result is not None: + self._render_products = self._render_result.wait().fetch() + return super()._capture_screenshot_pixels() + def _init_window(self) -> None: """Create the viewer window and immediately apply Isaac Lab UI patches.""" super()._init_window() diff --git a/source/isaaclab_visualizers/test/test_newton_adapter.py b/source/isaaclab_visualizers/test/test_newton_adapter.py index 8efe1cffd305..2f5d41826502 100644 --- a/source/isaaclab_visualizers/test/test_newton_adapter.py +++ b/source/isaaclab_visualizers/test/test_newton_adapter.py @@ -187,52 +187,30 @@ def test_newton_marker_registry_lifecycle(marker_registry: _MarkerRegistry): assert marker_registry.groups == {} -@pytest.mark.parametrize("prim_path_keys", [True, False]) -def test_newton_rtx_viewer_aliases_ldr_color_when_render_vars_use_prim_paths( - monkeypatch: pytest.MonkeyPatch, prim_path_keys: bool -): +def test_newton_rtx_viewer_aliases_ldr_color_when_render_vars_use_prim_paths(): """ovrtx 0.5 keys render vars by prim path, but Newton's ViewerRTX looks up ``LdrColor``.""" - monkeypatch.setattr(newton_visualizer_module, "_ovrtx_keys_render_vars_by_prim_path", lambda: prim_path_keys) by_path = SimpleNamespace(render_vars={"/Render/Vars/LdrColor": "ldr"}) + by_name = SimpleNamespace(render_vars={"LdrColor": "legacy"}) by_both = SimpleNamespace(render_vars={"LdrColor": "short", "/Render/Vars/LdrColor": "path"}) other = SimpleNamespace(render_vars={"/Render/Vars/Depth": "depth"}) viewer = NewtonViewerRTX.__new__(NewtonViewerRTX) - viewer._render_products = {"/Render/Product": SimpleNamespace(frames=[by_path, by_both, other])} + viewer._render_products = {"/Render/Product": SimpleNamespace(frames=[by_path, by_name, by_both, other])} - assert by_path.render_vars.get("LdrColor") == ("ldr" if prim_path_keys else None) + assert by_path.render_vars["LdrColor"] == "ldr" + assert by_name.render_vars == {"LdrColor": "legacy"} assert by_both.render_vars["LdrColor"] == "short" # an existing short name is never overwritten assert "LdrColor" not in other.render_vars # ovrtx hands back new frame objects every step, and ViewerRTX reassigns them each time next_frame = SimpleNamespace(render_vars={"/Render/Vars/LdrColor": "next"}) viewer._render_products = {"/Render/Product": SimpleNamespace(frames=[next_frame])} - assert next_frame.render_vars.get("LdrColor") == ("next" if prim_path_keys else None) + assert next_frame.render_vars["LdrColor"] == "next" viewer._render_products = None assert viewer._render_products is None -@pytest.mark.parametrize( - "installed,expected", - [("0.4.2", False), ("0.5.0.377615", True), ("not-a-version", False), (None, False)], -) -def test_ovrtx_keys_render_vars_by_prim_path_follows_installed_version( - monkeypatch: pytest.MonkeyPatch, installed: str | None, expected: bool -): - def _version(_name: str) -> str: - if installed is None: - raise newton_visualizer_module.importlib.metadata.PackageNotFoundError - return installed - - monkeypatch.setattr(newton_visualizer_module.importlib.metadata, "version", _version) - newton_visualizer_module._ovrtx_keys_render_vars_by_prim_path.cache_clear() - try: - assert newton_visualizer_module._ovrtx_keys_render_vars_by_prim_path() is expected - finally: - newton_visualizer_module._ovrtx_keys_render_vars_by_prim_path.cache_clear() - - def test_sanitize_newton_marker_group_id_rewrites_invalid_chars_into_usd_path(): """The registry ``prim_path::id`` key is rewritten into a USD-safe prim path.""" # The ``::`` the registry key carries is what the RTX USD stage rejects. diff --git a/source/isaaclab_visualizers/test/visualizer_integration_utils.py b/source/isaaclab_visualizers/test/visualizer_integration_utils.py index 616694631553..2232514046f6 100644 --- a/source/isaaclab_visualizers/test/visualizer_integration_utils.py +++ b/source/isaaclab_visualizers/test/visualizer_integration_utils.py @@ -1693,6 +1693,10 @@ def _step_env() -> None: assert rtx_viewer is not None, "Newton RTX viewer was not created." with _visualizer_debug_case("newton_rtx", backend_kind): + # The first async capture must succeed before warm-up can suppress its error. + first_frame = rtx_visualizers[0].render_rgb_array() + width, height = _CARTPOLE_NEWTON_INTEGRATION_WINDOW_SIZE + assert first_frame is not None and first_frame.shape == (height, width, 3) _run_newton_viewer_frame_motion_test( env, rtx_viewer,