Unexpected Collision Behaviour with Replicator Python API

I have been trying to make a custom physics scene with the Replicator Python API by following this tutorial:

https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_replicator/physics_example.html

No matter what I try, the objects in my scene always fall and settle on an invisible surface offset from the floor. I’ve tried using cubes, planes, and custom USD’s and they always end up hovering above some surface after falling.

I’ve simplified the scene down to just a cube falling on a plane to try to reproduce the issue and got the same result.

Here’s the script I’m running with ./python.sh:

from omni.isaac.kit import SimulationApp

kit = SimulationApp({'headless': False, 'renderer': "RayTracedLighting", 'num_frames': 100})


def run_orchestrator():
    rep.orchestrator.run()

    # Wait until started
    while not rep.orchestrator.get_is_started():
        kit.update()

    # Wait until stopped
    while rep.orchestrator.get_is_started():
        kit.update()

    rep.BackendDispatch.wait_until_done()

    rep.orchestrator.stop()


import omni.replicator.core as rep
with rep.new_layer():
    with rep.create.cube():
        rep.physics.collider()
        rep.modify.pose(position=(0,0,10), scale=0.01)
        rep.physics.rigid_body(
                velocity=0,
                angular_velocity=0
        )
        rep.physics.physics_material(
            static_friction=0.7,
            dynamic_friction=0.5,
            restitution=0.2
        )
        rep.physics.mass(
            mass=10,
        )

    floor = rep.create.plane(position=(0,0,0), scale=0.1)

    with floor:
        rep.physics.collider()

    camera = rep.create.camera()
    render_product = rep.create.render_product(camera, (1024, 1024))

    def sphere_lights(num):
        lights = rep.create.light(
            light_type="Sphere",
            temperature=6000,
            intensity=30000,
            position=rep.distribution.uniform((-3, -3, 12), (-3, 3, 15)),
            scale=1,
            count=num
        )
        return lights.node
    rep.randomizer.register(sphere_lights)

    with rep.trigger.on_time(interval=1000,num=1):
        rep.randomizer.sphere_lights(10)

        with camera:
            rep.modify.pose(position=(16, 0, 12), rotation=(0, -15, 0))


    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(output_dir="/tmp/omni_output/", rgb=True)
    writer.attach([render_product])

    run_orchestrator()
kit.update()
kit.close()

Here’s the resulting scene after the cube has settled down:

Any help would be appreciated, since the tutorials are not much to go off of.

2 Likes

I’m experiencing this problem as well! Any ideas on what the issue might be?

Hi @iyevenko

I’ve run this by the eng team and they were able to repro. I’ll circle back when I have a bit more info.

Thanks!

2 Likes

Hi @iyevenko , the fix will be in the next release. It’s a problem when the meters_per_unit in ths scene is too small.

Hi @jiehanw , thanks for investigating this issue! Is there a workaround we can implement to get it working in the current release?

You can get the usd prim and using:

prim.GetAttribute("physxCollision:contactOffset").Set(0.2)
prim.GetAttribute("physxCollision:restOffset").Set(0.2)

Setting them to smaller value will have more accurate collision.

Running prim.GetAttribute(“physxCollision:contactOffset”).Set(0.2) throws the following error:

‘Empty typeName for </Replicator/Cube_Xform.physxCollision:contactOffset>’

I see it in the GUI on the same prim under “Raw USD Properties → Contact Offset”. Modifying it there after running the script works, but I’d like to be able to modify this in code. Could you please send the exact lines I should add to my original example to get it work as expected?

1 Like

Ah you have to enable the physics’ API:

 collision_api = UsdPhysics.CollisionAPI.Apply(prim)
physx_collision_api = PhysxSchema.PhysxCollisionAPI.Apply(prim)
mesh_collision_api = UsdPhysics.MeshCollisionAPI.Apply(prim)
1 Like

Thanks, this fixed the issue. This should really be documented somewhere though!

This is a bug that user should not worry about this. This will be fixed in the next release.

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