Scatter_2d collisions with static objects

Is there any way to avoid collisions with objects not included into the scatter node?

I have the following code as an example. I want the cubes to move, the sphere to stay at the given position, and avoid collisions. Nevertheless, when I execute the script after some replicator steps the collision with the sphere occurs.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 0, 0))
    cube1 = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 0 , 100) )
    cube2 = rep.create.cube(semantics=[('class', 'cube')],  position=(-200, 0 , 100) )
    plane = rep.create.plane(scale=3, visible=False)

    def get_shapes():
        shapes = rep.get.prims(semantics=[('class', 'cube')])
        with shapes:
            rep.randomizer.scatter_2d(plane, check_for_collisions=True)
        return shapes.node

    rep.randomizer.register(get_shapes)

    with rep.trigger.on_frame(num_frames=30):
        rep.randomizer.get_shapes()

Hello @jorge29! I’ve shared your post with the dev team for further assistance.

Hi Jorge, welcome to the developer forums.

This is a really good concern and an important limitation in the current version of replicator. I made a fix for it a couple months ago to accommodate for this and similar situations, but never merged it in, so I need to update a few things and push the code (however I do not know when that will be seen in the released version of replicator you have access to – will check on this too). It’s at the top of my priority list. Will keep you posted!

It’s possible there is a way to wrangle things together with the current version of replicator but I don’t know what it is if so – so I’m going to focus on getting it done right in my updates to Scatter2d and Scatter3d.

Thank you for your response @hclever .
Also, since the release of code 3.1 and isaac sim 2.0 the check_for_collisions argument of scatter _2d seems to be ignored. Collisions occur between the objects into the scatter node no matter the value.

Jorge,

This is good to know. I will also look into this other issue with collisions.

Today I got a version of the scatter3d node running that will do something similar to what you need – I will do the scatter2d one next. These changes won’t be reflected in the public version until the next release, so I will just give you some python code to replace the existing nodes when I have it ready.

-Henry

Hi Jorge, I have a fix for this. I sampled some spheres across 2 planes and checked for collisions with a large sphere that intersects the planes to show an example:


Script:

import omni.replicator.core as rep
 
with rep.new_layer():
    sphere1 = rep.create.sphere(semantics=[('class', 'sphere')], scale=3, position=(-100, 50, -100), visible=True)
    plane = rep.create.plane(scale=3, visible=True)
    plane2 = rep.create.plane(scale=2, position = (0, 100, -150), rotation=(45, 0, 0), visible=True)


    def randomize_spheres():
        spheres = rep.create.sphere(scale=0.4, count=30)
        with spheres:
            rep.randomizer.scatter_2d([plane, plane2], volume_excl_prims=[sphere1], check_for_collisions=True)
        return spheres.node

    rep.randomizer.register(randomize_spheres)

    with rep.trigger.on_frame(interval=10, num_frames=1):
        rep.randomizer.randomize_spheres()

rep.orchestrator.run()

I also have some files for you – you can replace the existing python files in your replicator codebase with these, which should fix things for you. Let me know if you have trouble - happy to help more.
omni.replicator/source/extensions/omni.replicator.core/python/_impl/nodes/OgnScatter2D.py:
OgnScatter2D.py (16.1 KB)

omni.replicator/source/extensions/omni.replicator.core/python/_impl/nodes/OgnScatter2D.ogn:
OgnScatter2D.ogn (1.8 KB)

omni.replicator/source/extensions/omni.replicator.core/python/scripts/randomizer.py:
randomizer.py (17.8 KB)

/home/hclever/git1/omni.replicator/source/extensions/omni.replicator.core/python/scripts/utils/utils.py:
utils.py (44.1 KB)

Thank you for your help @hclever.
I have this error
2023-01-02 18:48:48 [Error] [omni.kit.app.plugin] [py stderr]: AttributeError: module ‘omni.replicator.core.scripts.utils.viewport_manager’ has no attribute ‘_clear_context’

I think I also need to replace the viewport_manager.py script in utils.

viewport_manager.py (12.2 KB)
I hope this is enough to fix it! I have been working on our latest internal branch, which is a bit newer from yours – thus the problem. It’s possible I may have to go back to your release version and do the updates on that (but hopefully not).

-Henry

Now I have this following errors:

2023-01-03 16:20:36 [Error] [omni.graph.core.plugin] Node::getAttribute() - attribute /Replicator/SDGPipeline/OgnScatter2D.inputs:volumeExclPrim not found
2023-01-03 16:20:36 [Error] [omni.graph] Invalid AttributeObj object in Py_Attribute in getAttrObj
2023-01-03 16:20:36 [Error] [omni.graph.core.plugin] class omni::graph::core::Attribute::getPointerFromHandle - handle is 0
2023-01-03 16:20:36 [Error] [omni.graph.core.plugin] Invalid attrObj passed into Attribute::connectAttrsEx

Perhaps I also need to replace OgnScatter2DDatabase.py??

Weird - it seems like it’s not picking up the new Ogn file. It is different from the last one in that it has the attribute /Replicator/SDGPipeline/OgnScatter2D.inputs:volumeExclPrim .

Can you make sure you copied that file in correctly? I’m going to look on my end and see if it’s something that needs to be built rather than just c+p code. If that’s the case I’ll help you with a workaround.

I’m exploring this build question now on my end -

This is the problem . Will get you a workaround soon.

I’m having some trouble with the workaround so I will need to hard code some things for you unless the code can be rebuilt on your end (which I don’t think it can). Do you have a set number of objects besides those sampled that you want to check for collisions on ? Or do you want to check for collisions on every other object in the scene (which will require me to automatically add collision meshes to everything in the scene except the stuff you are sampling)?

Yes, I have a set number of static objects. In the real scene that I am trying to randomize the static objects are fixed. Those objects include buildings, trees, and other static structures that I am no expecting to have variations.

How many do you have? Do you have just one surface?

10 static objects over just one surface. The objects I want to randomize are almost 100.

OK - I have your workaround. Here is a code snippet -

import omni.replicator.core as rep
 
with rep.new_layer():
    sphere1 = rep.create.sphere(semantics=[('class', 'sphere')], scale=3, position=(-100, 50, -100), visible=True)
    plane2 = rep.create.plane(scale=4, position = (0, 100, -150), rotation=(45, 0, 0), visible=True)


    def randomize_spheres():
        spheres = rep.create.sphere(scale=0.4, count=30)
        with spheres:
            rep.randomizer.scatter_2d([plane2, sphere1], check_for_collisions=True)
        return spheres.node

    rep.randomizer.register(randomize_spheres)

    with rep.trigger.on_frame(interval=10, num_frames=1):
        rep.randomizer.randomize_spheres()

rep.orchestrator.run()

Note the list of [plane2, sphere1] that is input to the scatter node. The first item in the list (i.e. plane2) is the surface prim, the next and every other item in the list are 3D exclusion prims. So you can have 1 surface and up to N exclusion volumes in a list of N+1 size.

Attached is the scatter2d.py node – use this instead of the previous one and let me know if it works.
OgnScatter2D.py (16.8 KB)

It works now!! Thank you for your help @hclever.

I replaced the following scripts
-OgnScatter2D.py
-randomizer.py
-utils.py
-viewport_manager.py

Just a comment. I see some small collisions occurring with the sampled objects from time to time. For me it is completely useful. I can allow those small collisions.
image

Excellent!

These small collisions are due to the refinement of the convex hull computation – I think it has a max of 64 vertices. It’s possible to refine further, but I haven’t had a use case yet where I needed it to be more precise.

-Henry

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.