Code equivalent of Add > Physics > Rigid body with colliders preset

Isaac Sim Version

4.5.0
4.2.0
4.1.0
4.0.0
4.5.0
2023.1.1
2023.1.0-hotfix.1
Other (please specify):

Operating System

Ubuntu 22.04
Ubuntu 20.04
Windows 11
Windows 10
Other (please specify):

GPU Information

  • Model:
  • Driver Version:

Topic Description

Detailed Description

If I create a Xform and a Mesh and apply Rigid Body with colliders preset from the GUI, it behaves correctly, but I want to be able to turn this on and off via code.

Steps to Reproduce

  1. Create Xform
  2. Create Child Cube Mesh
  3. Run the scripts
        # Apply all physics APIs
        UsdPhysics.RigidBodyAPI.Apply(prim)
        PhysxSchema.PhysxRigidBodyAPI.Apply(prim)
        UsdPhysics.CollisionAPI.Apply(prim)
        PhysxSchema.PhysxCollisionAPI.Apply(prim)

Demo

The one in the left I used the GUI:

Add > Physics > Rigid body with colliders preset 

The on in the right:

        # Apply all physics APIs
        UsdPhysics.RigidBodyAPI.Apply(prim)
        PhysxSchema.PhysxRigidBodyAPI.Apply(prim)
        UsdPhysics.CollisionAPI.Apply(prim)
        PhysxSchema.PhysxCollisionAPI.Apply(prim)

Why they behave differently? How to achieve the same behavior from code?

Thanks!

Do you set schemas attributes (like RigidBodyEnabled one) after applying them? If you only apply them, it doesn’t has any effect except prepending schemas in apiSchemas prim list:

def Mesh "Cube" (
    prepend apiSchemas = ["PhysicsRigidBodyAPI", "PhysxRigidBodyAPI", "PhysicsCollisionAPI", "PhysxCollisionAPI", "PhysxConvexHullCollisionAPI", "PhysicsMeshCollisionAPI"]
)

I know that applying ‘Rigid Body with colliders preset’ to prim sets at least these attributes (and one token):

uniform token physics:approximation = "convexHull"
bool physics:collisionEnabled = 1
bool physics:kinematicEnabled = 0
bool physics:rigidBodyEnabled = 1

You can check it by yourself. Create stage with two cubes. Add ‘Rigid Body with colliders preset’ to one of them with GUI and perform your code on another. Then save your file as .usda and see the difference between them.

1 Like