Hi Danielle,
The scatter nodes (scatter2D and scatter3D) have the capability of checking for collisions within sampled prims and also from a list of other provided prims in the scene. You can use scatter2d for surfaces (e.g. unstacked bricks on a pallet) and scatter3d for randomizing within volumes (e.g. confetti in a room)
Here’s an example with scatter2d that uses a sequence of scatters to put objects of heterogeneous types on various surfaces and check for collisions with other things in the scene.
import omni.replicator.core as rep
import asyncio
async def main():
with rep.new_layer():
mat1 = rep.create.material_omnipbr(
diffuse=(0.1, 0.1, 0.1),
roughness=0.99,
metallic=0.99,
emissive_color=(0.1, 0.1, 0.7),
emissive_intensity=500,
)
mat2 = rep.create.material_omnipbr(
diffuse_texture=rep.distribution.choice(rep.example.TEXTURES),
roughness_texture=rep.distribution.choice(rep.example.TEXTURES),
metallic_texture=rep.distribution.choice(rep.example.TEXTURES),
emissive_texture=rep.distribution.choice(rep.example.TEXTURES),
emissive_intensity=1000,
)
mat3 = rep.create.material_omnipbr(
diffuse_texture=rep.distribution.choice(rep.example.TEXTURES),
roughness_texture=rep.distribution.choice(rep.example.TEXTURES),
metallic_texture=rep.distribution.choice(rep.example.TEXTURES),
emissive_texture=rep.distribution.choice(rep.example.TEXTURES),
emissive_intensity=200,
)
cylinder = rep.create.cylinder(semantics=[('class', 'cylinder')], material=mat1, scale=(2.7, 4, 2.7), position=(-100, 50, -50), visible=True)
plane_samp = rep.create.plane(scale=3, material=mat2, rotation=(20, 0, 0), visible=True)
sphere_samp = rep.create.sphere(scale=2.4, material=mat3, position = (0, 100, -180), visible=True)
def randomize_spheres():
spheres = rep.create.sphere(position=rep.distribution.uniform((0,0,0), (100,100,100)), scale=0.4, count=20) #48
cubes = rep.create.cube(position=rep.distribution.uniform((0,0,0), (100,100,100)), scale=0.33, count=20) #48
cones = rep.create.cone(position=rep.distribution.uniform((0,0,0), (100,100,100)), scale=0.33, count=20) #48
with rep.utils.sequential():
with spheres:
rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (0.4, 0.4, 0.4)))
rep.randomizer.scatter_2d([plane_samp, sphere_samp], no_coll_prims=[cylinder], check_for_collisions=True)
with cubes:
rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (0.4, 0.4, 0.4)))
rep.randomizer.scatter_2d([plane_samp, sphere_samp], no_coll_prims=[cylinder, spheres], check_for_collisions=True)
with cones:
rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (0.4, 0.4, 0.4)))
rep.randomizer.scatter_2d([plane_samp, sphere_samp], no_coll_prims=[cylinder, spheres, cubes], check_for_collisions=True)
return spheres.node
rep.randomizer.register(randomize_spheres)
with rep.trigger.on_frame(num_frames=10):
rep.randomizer.randomize_spheres()
asyncio.ensure_future(main())