Using the Replicator with a fully developed scene#

Learning Objectives#

Through this tutorial you will learn how to use a previously developed scene with Replicator. Here, we will show you how you can randomize what is visible on the scene, but you should be able to use any of the randomizers following this structure.

Open an existing scene#

Through this example we will show you how to use two scenes. One with the generic NVIDIA assets and the other leveraging the warehouse of Isaac Sim, the Omniverse robotics simulation application. For both of them make sure you have followed Setting up nucleus server and for the Isaac Sim example that you have downloaded the Isaac folder.

Attic Scene#

In this example, you will be using the Attic scene provided by NVIDIA via a local Nucleus server. To set up a local nucleus server, follow instructions in Setting up nucleus server. Once a local nucleus server is set up the Attic scene can be found in the folder omniverse://localhost/NVIDIA/Samples/OldAttic/Attic_NVIDIA.usd through the content browser. For faster rendering you can switch the rendering mode to realtime.

Randomizing the scene

To run the following script follow set up instructions in Setting up the Script Editor.

In this script, we import omni.replicator and start a new USD layer. We do this such that all of the randomization and changes to the scene are self contained within the new layer. Without adding the new layer to the USD file, the changes made via the script will alter the scene permanently. Then we attach the render product. Notice that in this scene we are using a different camera than the one the viewport defaults to. This will lead to a new viewport when the script is run showing the captured perspective.

import omni.replicator.core as rep

with rep.new_layer():
    render_product = rep.create.render_product('/Root/Camera', (2048, 1024))

We select an asset, in this case the bear in the couch from the scene; then we label it and randomize its visibility. Lastly, we register the randomizer.

def hide_bear():
    bear = rep.get.prims(path_pattern='/Root/Geometry/Bear')
    with bear:
        rep.modify.semantics([('class', 'bear')])
        rep.modify.visibility(rep.distribution.choice([True, False]))
    return bear.node
rep.randomizer.register(hide_bear)

Randomizer is triggered for 100 frames.

with rep.trigger.on_frame(num_frames=100):
    rep.randomizer.hide_bear()

To see this in action run the script and then run Replicator by clicking in the leftmost corner on Replicator and then run as shown in Running and Previewing Replicator. Full code for ease of copying below.

import omni.replicator.core as rep
with rep.new_layer():

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

    render_product = rep.create.render_product('/Root/Camera', (2048, 1024))

    def hide_bear():
        bear = rep.get.prims(path_pattern='/Root/Geometry/Bear')
        with bear:
            rep.modify.semantics([('class', 'bear')])
            rep.modify.visibility(rep.distribution.choice([True, False]))
        return bear.node

    rep.randomizer.register(hide_bear)

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

Isaac Sim Warehouse scene#

In this example we will be using the warehouse from Isaac Sim. Isaac Sim has multiple assets for the industrial use case in the NVIDIA assets. You will find them in the folder omniverse://localhost/NVIDIA/Assets/Isaac/2022.1/Isaac in your local Setting up nucleus server.

First open the scene through the content browser the warehouse scene found in omniverse://localhost/NVIDIA/Assets/Isaac/2022.1/Isaac/Environments/Simple_Warehouse/warehouse_multiple_shelves.usd.

Randomizing the scene

To run the following script follow set up instructions in Setting up the Script Editor.

First import replicator and create a render_product. Notice in this tutorial we use a camera that was already set up in the scene.

import omni.replicator.core as rep

with rep.new_layer():
    render_product = rep.create.render_product('/Root/Camera', (2048, 1024))

Get the prim you want to randomize and randomize in the way you want. In this case we are looking for the prim of the KLT boxes and for the randomization we are toggling visibility. Then you register your randomizer.

def hide_boxes():
    boxes = rep.get.prims(path_pattern='SmallKLT_Visual_\d\d\d', prim_types=['Xform'])
    with boxes:
        rep.modify.visibility(rep.distribution.choice([True, False]))
    return boxes.node
rep.randomizer.register(hide_boxes)

Lastly a randomization is triggered for 100 frames. To run it make sure to click on the top corner Replicator then run. Notice here we don’t have a writer, so it won’t be stored. In other tutorials we show you how to use BasicWriter or crate a custom writer.

with rep.trigger.on_frame(num_frames=100):
    rep.randomizer.hide_boxes()

Full script can be found below:

import omni.replicator.core as rep

with rep.new_layer():

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

    render_product = rep.create.render_product('/Root/Camera', (2048, 1024))

    def hide_boxes():
        boxes = rep.get.prims(path_pattern='SmallKLT_Visual_\d\d\d$', prim_types=['Xform'])
        with boxes:
            rep.modify.visibility(rep.distribution.choice([True, False]))
        return boxes.node

    rep.randomizer.register(hide_boxes)

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