Scatter 2d and check collisions between instances

How can we scatter 2d multiple times (with different parameters) so we can also check for collisions between individual instances?

@pcallender @dennis.lynch @jiehanw

see other thread - Collision Detection for Scatter not working well - #3 by hclever

The other thread is about collisions with racks and static objects. This thread is about collisions between instances.

Right - but i initially thought that the same thing might be leading to both issues (not using rep.sequential) but this is not the case for the other thread. it may be for this - can you better describe what you are doing here -

are you trying to first, run some scatter (say with non-colliding “workers”) and then run another scatter (say with non colliding “cones”) and then make sure none of the cones collides with either themselves or the workers? Or are do you mean something else by “individual instances”?

Yes - currently I try to achieve that by supplying different seeds.

Got it - then you’ll want to do something like this -

with rep.sequential():
with items1:
rep.scatter2d()
with items2:
rep.scatter2d(no_collision=items1)
`

The seed shouldn’t matter so long as you do collision checking. if it samples the same seed on the next scatter, it will just reject everything overlapping and get to the next sample that isn’t overlapping.

The reason you need rep sequential is that without it, the nodes are not guaranteed to execute in sequence. In my snippet, you need to guarantee items1 has been updated before passing it as a no_collision param to the next scatter.

-Henry

How do I do rep.sequential() in the Replicator YAML?

good question. Here is an example snippet that should work (it works for me, let me know if it does for you).

Note how the scatter nodes use they same seed (they are not specified) but the second scatter with the cubes does not overlap the spheres. If you comment out the “no_coll_prims: [spheres]” line then the cubes should coincide with the spheres as they are sampled from the same seed.

stage_unit_setting:
  settings.set_stage_meters_per_unit:
    meters_per_unit: 1

stage_up_axis_setting:
  settings.set_stage_up_axis:
    up_axis: "Z"

light:
  create.light:
    light_type: distant

sphere:
  create.sphere:
    semantics: [["class", "sphere"]]
    position: [1, 0, 1]
    count: 15
cube:
  create.cube:
    semantics: [["class", "cube"]]
    position: [1, 2, 2]
    count: 15
plane:
  create.plane:
    semantics: [["class", "plane"]]
    visible: false
    scale: 10

register_scatter2d:
  randomizer.register:
    get_scatter2d:
      inputs:
        input_plane: null
      spheres:
        get.prims:
          semantics: [['class', 'sphere']]
      cubes:
        get.prims:
          semantics: [['class', 'cube']]

      sequential:
        utils.sequential: null

      with.sequential:
        with.spheres:
          randomizer.scatter_2d:
            surface_prims: [input_plane]
            check_for_collisions: true
        with.cubes:
          randomizer.scatter_2d:
            surface_prims: [input_plane]
            check_for_collisions: true
            no_coll_prims: [spheres]

trigger:
  trigger.on_frame:
    max_execs: 30
    rt_subframes: 12

with_trigger:
  with.trigger:
    # randomizer.get_scatter2d: null
    randomizer.get_scatter2d:
      input_plane: plane

camera:
  create.camera:
    position: [5, 0, 0]

render_product:
  create.render_product:
    camera: camera
    resolution: [1024, 1024]

writer:
  writers.get:
    name: "BasicWriter"
    init_params:
      output_dir: "_output"
      rgb: True

writer_attach:
  writer.attach:
    render_products: render_product

1 Like