Turn off and on visibility with Python Code for Specific Annotations

Topic Description

Turn off and on visibility with Python code for specific annotations.

Detailed Description

What I am trying to achieve. I created these images in Blender to showcase the end result I want to achieve with Python code inside of Isaac Sim. The main computer vision task related to this synthetic image dataset is to capture the opening of a bin. How I am going about it:

  1. Creating the bin
  2. Creating a 2D plane that sits on top of the opening of the bin
  3. Turn off the visibility of the plane (the opening) only when capturing the RGB images
  4. Turn on the visibility of the plane (the opening) when capturing the semantic segmentation masks images.

Please how can I do this inside of the script editor?
Thank you

Isaac Sim Version

4.2.0

Operating System

Windows 11

GPU Information

  • Model: Nvidia GeForce RTX 4070 Laptop GPU
  • Driver Version: 32.0.15.6614

Additional Information

What I’ve Tried

import omni.replicator.core as rep

#Paths to the assets
first_asset_path = "/bin1/RL_KLT_6280"  # Path to the first asset in the scene
second_asset_path = "/opening/RL_KLT_6280_002"  # Path to the second asset in the scene

#Specify the exact position for the second asset relative to the first
second_asset_position = (0, 0, 0)  # Adjust as needed

with rep.new_layer():

    #Add Default Light
    distance_light = rep.create.light(rotation=(315, 0, 0), intensity=3000, light_type="distant")

    # Create Camera
    camera = rep.create.camera(position=(923.04092, 923.04098, -976.00001))
    
    # Create a render product for the camera
    render_product = rep.create.render_product(camera, (1024, 1024))

    def load_and_move_assets():
        # Load the first asset
        first_asset = rep.get.prim_at_path(first_asset_path)

        # Define randomization for the first asset's position and rotation
        with first_asset:
            rep.modify.pose(
                position=rep.distribution.uniform((-500, 50, -500), (500, 50, 500)),
                rotation=rep.distribution.uniform((0, -180, 0), (0, 180, 0)),
            )

        # Load the second asset
        second_asset = rep.create.from_usd(second_asset_path, semantics=[('class', 'opening')])

        # Parent the second asset to the first asset and set its position relative to the first
        rep.modify.parent(second_asset, parent=first_asset)
        with second_asset:
            rep.modify.pose(position=second_asset_position)

        # Set visibility for the second asset
        with second_asset:
            rep.modify.visibility(render_product=render_product, visible=False, output_type="rgb")
            rep.modify.visibility(render_product=render_product, visible=True, output_type="semantic_segmentation")

        return first_asset.node, second_asset.node

    # Register randomizer for loading and positioning the assets
    rep.randomizer.register(load_and_move_assets)

    # Setup randomization
    with rep.trigger.on_frame(num_frames=100):
        rep.randomizer.load_and_move_assets()

    # Set up the output writer with the new output directory
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="C:/Users/elina/Documents/isaac_sim_practice/bin_randomizer_fix/output", 
                      rgb=True, 
                      semantic_segmentation=True, 
                      bounding_box_2d_tight=True)
    writer.attach([render_product])

The parameters in your code snippet are not listed in PYTHON API — Omni Replicator 1.11.16 documentation.

Could you let me know which code or API documentation you referred to when implementing your code? This will help clarify the discrepancy and ensure we are aligned with the correct documentation.