Is there a working example of how to get frame number in Replicator? All examples are broken or require delving into ogn, which is, umm.. not my plan

I hate to ask for someone to make this simpler, but does anyone have a code snippet that gets the frame number so I can move the camera along a line or something? (I’m trying to do some structure from motion tests so I need a controlled set of camera positions, not random ones.)

Getting the frame number inside the writer doesn’t do me any good except name the file, does it?

I’m not sure where to execute this, when I put it inside
with rep.trigger.on_frame(num_frames=5): # , rt_subframes=100):

I get
2023-09-24 01:06:50 [Error] [omni.ui.python] UnboundLocalError: local variable ‘time’ referenced before assignment

I don’t know about Replicator, but I have an extension called Camera Keys, the source code is here:

The relevant code is located in Extensions.py.

This is how to get the current frame

usd_context = omni.usd.get_context()
stage = usd_context.get_stage()
active_viewport = get_active_viewport()
camera_path = active_viewport.camera_path
camera = stage.GetPrimAtPath("/World/Camera")                    
timeline = omni.timeline.get_timeline_interface()
current_frame = timeline.get_current_time() * 
    timeline.get_time_codes_per_seconds()

There is other code that might help you. Mati wrote the move camera forward code, and I was able to figure out the rest.

  with camera:
                
      theta = np.linspace(0, 2*np.pi, 213)
      rad = np.random.uniform(2000, 3000, theta.shape)  # generate a random radius
      x = rad * np.cos(theta)
      z = rad * np.sin(theta)
      # y = np.full(theta.shape, 4500)  # create y-vector of constant 1000
      y = np.random.uniform(4000, 5000, theta.shape)  # create y-vector of random values between 4000 and 5000
                
      x_list = x.tolist()
      y_list = y.tolist()
      z_list = z.tolist()
      camera_positions = list(zip(x_list, y_list, z_list)) 
      # get a reference to the timeline
      timeline = omni.timeline.get_timeline_interface()                                
      # get the current time
      time = timeline.get_current_time()
      # get the frames per second
      fps = timeline.get_time_codes_per_seconds()
      # set the current frame
      frame = time * fps
      camPos = camera_positions[int(frame)]
      rep.modify.pose(position=camPos, look_at= looky)

  rep.orchestrator.run(num_frames=24, start_timeline=True)

But since this is only run once, (because replicator does the iterations in some ogn that I don’t understand, yet) I just get time = 0 and therefore one camera position.

@holdendp i am wondering if this thread is relevant?

I thought that was the script I was emulating. However I don’t have a usd with a moving camera (or know how to do that) as he mentions so perhaps that’s the missing piece.

What if I make list of cameras with this?:
https://docs.omniverse.nvidia.com/extensions/latest/ext_replicator/camera_examples.html#multiple-cameras-with-basic-writer

Multiple Cameras with Basic Writer

formatting isn’t working but link should.

Would it be fine if you feed the camera a predefined list of positions?

1 Like

I AM actually using a predefined list, just getting them randomly, how do I get them in order? Or even guaranteed to visit each one once. AFAIK I still get a random sampling of them.

rep.distribution.sequence will iterate over the values as a sequence

1 Like

I did not know that. I will try that today!

edit:
That works. Thanks!

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