Problem with dummy cube example in Script Editor for SDG

I am trying to capture photos of a cube in the view of the camera and I am not sure why every captured photo is black and why I can’t see any randomization when I click on Replicator → Step or Replicator → Start after hitting Run on Script Editor Python code.

Here’s the dummy script:

# click on Replicator --> Start to start the capture
# with current state of the code, everything is captured as black

import omni.replicator.core as rep
from datetime import datetime

with rep.new_layer():

    camera = rep.create.camera(position=(0, 0, 1000))

    render_product = rep.create.render_product(camera, (1024, 1024))

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(100, -200 , 100) )

    with rep.trigger.on_frame(num_frames=10):
        with cube:
            rep.modify.pose(
                position=rep.distribution.uniform((-100, -100, -100), (200, 200, 200)),
                scale=rep.distribution.uniform(0.1, 2))


    timestamp = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")

    writer.initialize( output_dir="/home/mona/Desktop/Isaac_Sim_Dummy_Out/cube_out/" + timestamp, rgb=True,   bounding_box_2d_tight=True)

    writer.attach([render_product])

    rep.orchestrator.preview()

and here’s the screenshot of my window:

as a basic goal, I want the following:

  1. spawn a cube
  2. create a camera
  3. create a plane
  4. make sure the cube is always spawn inside the plane
  5. make sure the camera is always taking photos of the cube

If you could guide me to a tutorial that does these minimal things I’d really appreciate. Some of the tutorials start too big and some are just too minimal and I am not sure how to fill in the gaps.

Also, everytime I click on Run, I get this warning: Overridden in multiple layers as shown below.

I used this other code, still cannot see the cube after I click on run and then Replicator → Start and also all captured frames are black. Can you please help me fix this problem?

import omni.replicator.core as rep
from datetime import datetime

# Randomize the camera position using basic uniform distribution

with rep.new_layer():

    # Create camera
    # https://docs.omniverse.nvidia.com/py/replicator/source/extensions/omni.replicator.core/docs/API.html#omni.replicator.core.create.camera
    camera = rep.create.camera(focus_distance=200,f_stop=0.5)

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(0, 0, 0))
    render_product  = rep.create.render_product(camera, (1024, 1024))
    timestamp = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="/home/mona/Desktop/Isaac_Sim_Dummy_Out/cube_out/" + timestamp, rgb=True, bounding_box_2d_tight=True)
    writer.attach([render_product])

    with rep.trigger.on_frame(num_frames=10):
        with camera:
            rep.modify.pose(position=rep.distribution.uniform((-500, 200, -500), (500, 500, 500)), look_at=(0,0,0))

The example is taken from Randomizing a camera’s position uniformly from Camera Examples — Omniverse Extensions documentation

Here’s what I see after clicking on Run and then Replicator → Start.

Here’s another script I used. I still have problem:


import omni.replicator.core as rep
from datetime import datetime
from pxr import UsdPhysics, PhysxSchema, Gf, PhysicsSchemaTools, UsdGeom
import omni.graph.core as og

import numpy as np
# Randomize the camera position using basic uniform distribution

with rep.new_layer():

    # Create camera
    # https://docs.omniverse.nvidia.com/py/replicator/source/extensions/omni.replicator.core/docs/API.html#omni.replicator.core.create.camera
    camera = rep.create.camera(focus_distance=200,f_stop=0.5)
    camera_positions = [(-5, -5, 10), (5, 5, 20)]

    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(0, 0, 0))    
    plane = rep.create.plane(scale=100, visible=True)
    
 
        
    def randomize_cube():
        cube = rep.get.prims(semantics=[('class', 'cube')])
        with cube:
            rep.modify.pose(
                position=rep.distribution.uniform((-40, -40, 40), (40, 40, 40)),
                rotation=rep.distribution.uniform((0, 0, 0), (90, 90, 0)),
                scale=rep.distribution.normal(3, 7),
                color =rep.distribution.uniform((0,0,0), (1,1,1))
            )
        return cube.node
    
    rep.randomizer.register(randomize_cube)
    
    
  
    
    render_product  = rep.create.render_product(camera, (1024, 1024))
    timestamp = datetime.now().strftime("%Y_%m_%d-%I_%M_%S_%p")
    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="/home/mona/Desktop/Isaac_Sim_Dummy_Out/cube_out/" + timestamp, rgb=True, bounding_box_2d_tight=True)
    writer.attach([render_product])

    with rep.trigger.on_frame(num_frames=10):
        rep.randomizer.randomize_cube()
        with camera:
            rep.modify.pose(position=rep.distribution.choice(camera_positions), look_at=(0, 0, 0))

Here’s what I see after clicking on run:

Also, still when I click on Replicator → Step or Replicator → start the position doesn’t change neither the color of cube despite registering the randomize_cube function in rep.

Further, still all captured frames are black.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.