I am trying to randomize objects positions and prevent them from colliding to each other but with the scatter_3d I still get collisions
here is the code
import omni.replicator.core as rep
import omni
camera = rep.create.camera(
clipping_range=((0.01, 100000)),
focal_length=3.7,
focus_distance=0,
f_stop=0,
horizontal_aperture=3.896,
projection_type=“fisheye_equidistant”,
fisheye_max_fov=98,
)
render_product = rep.create.render_product(camera, (1280, 720))
with rep.new_layer():
def dome_lights():
lights = rep.create.light(
light_type=“Dome”,
rotation=rep.distribution.uniform((0, 0, 0), (360, 360, 360)),
temperature=rep.distribution.normal(6500, 500),
intensity=rep.distribution.normal(1000, 500),
texture=rep.distribution.choice([
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/adams_place_bridge_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/bathroom_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/en_suite_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/carpentry_shop_01_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/autoshop_01_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/hospital_room_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/old_bus_depot_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/studio_small_04_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/vulture_hide_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/wooden_lounge_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Indoor/lebombo_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Clear/evening_road_01_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Clear/sunflowers_4k.hdr’,
‘omniverse://localhost/NVIDIA/Assets/Skies/Clear/venice_sunset_4k.hdr’
])
)
return lights.node
def randomize_sphere_lights():
lights = rep.create.light(
light_type=“Sphere”,
color=rep.distribution.uniform((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)),
intensity=rep.distribution.uniform(100000, 3000000),
position=rep.distribution.uniform((-250, -250, -250), (250, 250, 100)),
scale=rep.distribution.uniform(1, 20),
count=10,
)
return lights.node
MOD = ‘omniverse://192.168.24.212/Library/usd/onshape_imports/kona_module_01/kona_module_edit.usd’
volume = rep.create.sphere(scale=4, visible=False)
def mod():
mod = rep.create.from_usd(MOD, count=5)
with mod:
rep.modify.pose(
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
)
rep.modify.visibility(rep.distribution.choice([True, False]))
rep.randomizer.scatter_3d(volume, check_for_collisions=True)
return mod.node
mats3 = rep.create.material_omnipbr(
metallic=rep.distribution.uniform(0.0, 1.0),
roughness=rep.distribution.uniform(0.0, 1.0),
diffuse=rep.distribution.uniform((0, 0, 0), (1, 1, 1)),
count=20,
)
spheres = rep.create.sphere(
scale=0.2,
count=20)
def get_spheres():
with spheres:
rep.modify.pose(
position=rep.distribution.uniform((-1.5,-1.5,-1.5), (1.5,1.5,1.5)),
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
)
rep.randomizer.materials(mats3)
rep.physics.collider()
rep.physics.rigid_body()
rep.randomizer.scatter_3d(volume, check_for_collisions=True)
return spheres.node
mats1 = rep.create.material_omnipbr(
metallic=rep.distribution.uniform(0.0, 1.0),
roughness=rep.distribution.uniform(0.0, 1.0),
diffuse=rep.distribution.uniform((0, 0, 0), (1, 1, 1)),
count=20,
)
cone = rep.create.cone(
scale=0.2,
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
count=20)
def get_cone():
with cone:
rep.modify.pose(
position=rep.distribution.uniform((-1.5,-1.5,-1.5), (1.5,1.5,1.5)),
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
)
rep.randomizer.materials(mats1)
rep.physics.collider()
rep.physics.rigid_body()
rep.randomizer.scatter_3d(volume, check_for_collisions=True)
return cone.node
mats2 = rep.create.material_omnipbr(
metallic=rep.distribution.uniform(0.0, 1.0),
roughness=rep.distribution.uniform(0.0, 1.0),
diffuse=rep.distribution.uniform((0, 0, 0), (1, 1, 1)),
count=20,
)
cylinder = rep.create.cylinder(
scale=0.2,
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
count=20)
def get_cylinder():
with cylinder:
rep.modify.pose(
position=rep.distribution.uniform((-1.5,-1.5,-1.5), (1.5,1.5,1.5)),
rotation=rep.distribution.uniform((-360, -360, -360), (360, 360, 360)),
)
rep.randomizer.materials(mats2)
rep.physics.collider()
rep.physics.rigid_body()
rep.randomizer.scatter_3d(volume, check_for_collisions=True)
return cylinder.node
rep.randomizer.register(dome_lights)
with rep.trigger.on_frame(num_frames=1000,interval=20):
rep.randomizer.dome_lights()
rep.randomizer.register(randomize_sphere_lights)
with rep.trigger.on_frame(num_frames=1000):
rep.randomizer.randomize_sphere_lights()
rep.randomizer.register(mod)
with rep.trigger.on_frame(num_frames=1000):
rep.randomizer.mod()
with rep.trigger.on_frame(interval=20, num_frames=1000):
with camera:
rep.modify.pose(
position=rep.distribution.uniform((0.6, 0.6, 0.6), (1.5, 1.5, 1.5)),
look_at=“/World”,
)
rep.randomizer.register(get_spheres)
with rep.trigger.on_frame(num_frames=1000):
rep.randomizer.get_spheres()
rep.randomizer.register(get_cone)
with rep.trigger.on_frame(num_frames=1000):
rep.randomizer.get_cone()
rep.randomizer.register(get_cylinder)
with rep.trigger.on_frame(num_frames=1000):
rep.randomizer.get_cylinder()