Add physics to primitive through python scripting

Hello, how can I add physics (rigid body collisions preset) to a primitive (Xform) in omniverse through python scripting? I am aware of how to do it via the front-end UI, but would like a python script to do it instead. The closest I’ve seen in the docs is How can I turn off the collision of the robot while simulation is running? - #2 by AlesBorovicka. I’ve tried something below based on the OpenUSD documentation ( Universal Scene Description: UsdPhysicsRigidBodyAPI Class Reference (openusd.org)) which prints true but does not add the physics to the body.

rigidBodyAPI = UsdPhysics.RigidBodyAPI(self._prim)
rigidBodyAPI.CreateRigidBodyEnabledAttr()
rigidBodyAPI.GetRigidBodyEnabledAttr().Set(True)
print(f’{rigidBodyAPI.GetRigidBodyEnabledAttr().Get()}')

Hi,
this adds just the rigid body part, meaning it wont collide.

You can use the helper script that the UX is using:

from omni.physx.scripts.utils import setRigidBody

setRigidBody(prim_path, "convexHull", True)

Regards,
Ales

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