Use render mode but hide some viewports

Hello,

I’d like to be able to use headless=False and render the main Viewport without rendering the viewports of other cameras that I create. I view in the code that there are 2 functions that are supposed to hide viewport_windows: set_visible() or show_hide_window(). However, when I use this function, I can’t get any image from the SyntheticDataHelper.

Here is my code:

from omni.isaac.kit import SimulationApp
headless = False
simulation_app = SimulationApp({"headless": headless})

import omni
from omni.isaac.core.utils.prims import create_prim
from omni.isaac.synthetic_utils import SyntheticDataHelper
sd_helper = SyntheticDataHelper()


camera_prim_path = "/World/camera"
create_prim(prim_path=camera_prim_path,
            prim_type="Camera")
stage = omni.usd.get_context().get_stage()
camera_prim = stage.GetPrimAtPath(camera_prim_path)

# Set as current camera
viewport_interface = omni.kit.viewport_legacy.get_viewport_interface()
viewport_handle = viewport_interface.create_instance()
num_viewports = len(viewport_interface.get_instance_list())
viewport_window = viewport_interface.get_viewport_window(viewport_handle)

# Hide the window
viewport_window.set_visible(False)
# Other function that give the same result
# viewport_window.show_hide_window(False)

viewport_window.set_active_camera(camera_prim_path)

gt = sd_helper.get_groundtruth(
            [
                "rgb",
                "depth",
                "instanceSegmentation",
            ],
            viewport_window,
        )

print(gt)

It gives me the following result:

'rgb': array([], shape=(0, 0, 4), dtype=uint8), 'depth': array([], shape=(0, 0), dtype=float32), 'instanceSegmentation': array([], shape=(0, 0), dtype=uint32), 'state': {'rgb': True, 'depth': True, 'instanceSegmentation': True}}

while if the option set_visible is commented it gives:

{'rgb': array([[[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]],

       [[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]],

       [[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]],

       ...,

       [[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]],

       [[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]],

       [[  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        ...,
        [  0,   0,   0, 255],
        [  0,   0,   0, 255],
        [  0,   0,   0, 255]]], dtype=uint8), 'depth': array([[inf, inf, inf, ..., inf, inf, inf],
       [inf, inf, inf, ..., inf, inf, inf],
       [inf, inf, inf, ..., inf, inf, inf],
       ...,
       [inf, inf, inf, ..., inf, inf, inf],
       [inf, inf, inf, ..., inf, inf, inf],
       [inf, inf, inf, ..., inf, inf, inf]], dtype=float32), 'instanceSegmentation': array([[0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       ...,
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0],
       [0, 0, 0, ..., 0, 0, 0]], dtype=uint32), 'state': {'rgb': True, 'depth': True, 'instanceSegmentation': True}}

Do Someone know if there is a solution to my problem?

1 Like

Viewports must be visible for them to render, when they are hidden they stop rendering to save resources.

We are working on a separate way to create “headless” viewports via hydratexture objects for the next release so there is a way to support your usecase.

2 Likes