How to programmatically apply Convex Decomposition with Shrink Wrap to match Isaac Sim UI defaults?

Context

I have a scene containing rigid body prims with meshes which have concave areas.
I apply the Convex Decomposition collision approximation but when visualizing the colliders I can see they are not very accurate to the mesh boundaries.

Notice the cube looks like it is floating off the surface of the tray.

I am using code similar to the following

mesh_collision_api = UsdPhysics.MeshCollisionAPI.Apply(prim)
mesh_collision_api.GetApproximationAttr().Set(UsdPhysics.Tokens.convexDecomposition)

You can see it results in these properties on the mesh prim.

Manual application of Convex Decomposition

I noticed if I toggle the approximation method through the UI, such as changing to Convex Hull and then back to Convex Decomposition, I get an extended set of prim attributes for physxConvexDecompositionCollision

One notable attribute is physxConvexDecompositionCollision:shrinkWrap

If I enable this property, the collider is very accurate and acceptable. 👍

Programmatic Application of Shrink Wrap

The issue I have is that when I try to apply the shrink wrap using code it does NOT behave the same way.

shrink_wrap_attr = prim.CreateAttribute(
    "physxConvexDecompositionCollision:shrinkWrap",
    Sdf.ValueTypeNames.Bool,
)
if shrink_wrap_attr is not None:
    shrink_wrap_attr.Set(apply_shrink_wrap_for_decomposition)

This does apply the shrink wrap effect; however, the approximation is different, notice the smaller gap.

Also, I do NOT see the attribute in shown next to other Collider > Advanced properties

It is only in the RAW USD Properties

Question

How to programmatically apply Collision API with Convex Decomposition approximation using Shrink Wrap to match the UI?

I realize I could use omni.kit.commands.execute('ChangeProperty', ....) commands but I would like to avoid this.

Perhaps there is a special Convex Decomposition Collision API I can apply to the prim?

Ok, I think I found a solution

physx_convexdecomp_api = PhysxSchema.PhysxConvexDecompositionCollisionAPI.Apply(prim)
physx_convexdecomp_api.GetShrinkWrapAttr().Set(True)

It is hard to know about these APIs to the lack of typing information in the code.

See other forum issue: How to get python typing information for the pxr PhysxSchema? - Omniverse / Isaac Sim - NVIDIA Developer Forums

Docs: PhysxSchemaPhysxConvexDecompositionCollisionAPI Class Reference (nvidia.com)

The tray collider mesh is now approximating well and the cube appears to rest on it as expected.

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