Hello,
I’m currently experimenting with replicator in Omniverse and would like to randomize the camera position such that it is always on the surface of a sphere with a specified radius.
I have a function that calculates that point:
def get_point_on_hemisphere(radius, azimuth_deg=None, polar_deg=None):
# azimut is horizontal
# polar is vertical
if azimuth_deg is None:
theta = random.uniform(0, 2 * math.pi)
else:
theta = azimuth_deg * (math.pi / 180)
if polar_deg is None:
phi = random.uniform(0, 2 * math.pi)
else:
phi = azimuth_deg * (math.pi / 180)
# convert spherical coordinates to cartesian coordinates
x = radius * math.sin(phi) * math.cos(theta)
y = radius * math.sin(phi) * math.sin(theta)
z = radius * math.cos(phi)
return (x, y, z)
However, when I use this function in the following way, it doesn’t work as expected (I guess this is only called once for the node creation):
def randomize_camera_position_on_hemisphere(camera, look_at, distance, azimut_deg, polar_deg):
with camera:
position = utils.get_point_on_hemisphere(radius=distance, azimuth_deg=azimut_deg, polar_deg=polar_deg)
rep.modify.pose(
position=position,
look_at=look_at
)
return camera.node
with rep.trigger.on_custom_event(event_name=rand_name):
azimut_deg = random.uniform(0, 360)
polar_deg = random.uniform(0, 90)
randomize_camera_position_on_hemisphere(camera=camera,
look_at=look_at,
distance=distance,
azimut_deg=azimut_deg,
polar_deg=polar_deg)
Additionally, I tried creating a custom replicator function based on the following post: How to get current frame number in Replicator - Omniverse / Developer - NVIDIA Developer Forums
Unfortunately, I couldn’t get it to work. Is there a new way to create custom replicator functions in Omniverse? If so, could you provide some guidance or examples?
Thank you for your help!