I am currently testing out the scatter_2d function with the following code:
import omni.replicator.core as rep
import omni.usd
#rep.settings.carb_settings("/omni/replicator/RTSubframes", 10)
with rep.new_layer():
camera = rep.create.camera(position=(1000, 1000, 1000), look_at=(0,0,0))
render_product = rep.create.render_product(camera, (1024, 1024))
torus = rep.create.torus(semantics=[('class', 'torus')] , position=(0, -200 , 100),count=3)
sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100),count=3)
cube = rep.create.cube(semantics=[('class', 'cube')], position=(100, -200 , 100),count=3 )
mats = rep.create.material_omnipbr(diffuse=rep.distribution.uniform((0, 0, 0), (1, 1, 1)), count=100)
plane = rep.create.plane(scale=10, visible=True)
def get_shapes():
with rep.utils.sequential():
shapes = rep.get.prims(semantics=[('class', 'cube'), ('class', 'sphere'), ('class', 'torus')])
# with torus:
# rep.randomizer.scatter_2d(surface_prims=plane, offset=50, check_for_collisions=True)
# with cube:
# rep.randomizer.scatter_2d(surface_prims=plane, offset=200, check_for_collisions=True)
# with sphere:
# rep.randomizer.scatter_2d(surface_prims=plane, offset=125, check_for_collisions=True)
with shapes:
rep.randomizer.texture(textures=[
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Paper/textures/cardboard_new_01_diff.jpg',
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Plastic/textures/pcb_solder_mask_diff.jpg',
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Stone/textures/baltic_brown_diff.png',
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/rough_gravel_rough.jpg',
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Wood/textures/bark_oak_mask.jpg',
'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Fabric/textures/cotton_roughly_woven_norm.jpg'
])
# rep.modify.pose(
# position=rep.distribution.uniform((-200, 100, -200), (200, 500, 200)),
# scale=rep.distribution.uniform(0.1, 2))
rep.randomizer.scatter_2d(surface_prims=plane, check_for_collisions=True)
rep.randomizer.materials(mats)
rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))
return shapes.node
rep.randomizer.register(get_shapes)
with rep.trigger.on_frame(num_frames=10,rt_subframes=10):
rep.randomizer.get_shapes()
# with camera:
# rep.modify.pose(position=rep.distribution.uniform((-500, 200, -500), (500, 500, 500)), look_at=(0,0,0))
# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize( output_dir="D:/omniverse/output", rgb=True, instance_segmentation=True,
colorize_instance_segmentation=False, instance_id_segmentation=True,
colorize_instance_id_segmentation=True)
writer.attach([render_product])
rep.orchestrator.preview()
However, the shapes generated often collide as shown in an example below:
I have seen previous topics on the post including the one using sequential as well as the post with replacement python files. I have tried replacing the python files although I am not sure whether the proper files were replaced given the difference in pathing on windows systems.
Also, is there a way to ensure a minimum distance between generated objects when using scatter_2d?