# Script for Convex Decomposition Collisions

**URL:** <https://forums.developer.nvidia.com/t/script-for-convex-decomposition-collisions/259649>\
**Category:** Isaac Sim\
**Tags:** collision, physx, usd, api\
**Created:** [July 12, 2023, 10:43pm UTC](https://forums.developer.nvidia.com/t/script-for-convex-decomposition-collisions/259649 "2023-07-12T22:43:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![christopher117](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@christopher117](https://forums.developer.nvidia.com/u/christopher117)\
**Post date:** [July 12, 2023, 10:43pm UTC](https://forums.developer.nvidia.com/t/script-for-convex-decomposition-collisions/259649/1 "2023-07-12T22:43:30Z")

</div>

Hello everyone, I have a small problem and would like to ask if anyone knows something about how to solve this. I wrote a small script to add collisionAPI to an object. As I do not yet specify which approximation for the collision mesh I want to use (triangle mesh, convex hull, convex decomposition, …) it automatically applies the convex hull approximation. I would like to use convex decomposition, though.  
Unfortunately, I cannot just set the attribute “pyhsics:approximation” to “convexDecomposition” because a Token is expected (I am unsure of how this mechanic works…). Does anyone know how to set these kinds of specific attributes correctly?

Here is a cleaned and minimal working version of the script that loads a usd file, sets the CollisionAPI and then saves it:

def add\_collision(usd\_path\_load, usd\_path\_save):  
usd\_context = get\_context()  
stage = usd\_context.open\_stage(usd\_path\_load)  
stage = get\_context().get\_stage()  
rigidPrim = stage.GetPrimAtPath(“/World/model\_normalized/mesh”)  
UsdPhysics.CollisionAPI.Apply(rigidPrim)  
# rigidPrim.GetAttribute(“physics:approximation”).Set(“convexDecomposition”)  
stage.Export(usd\_path\_save)

GetAttribute(): [Universal Scene Description: UsdPrim Class Reference](https://openusd.org/release/api/class_usd_prim.html#a31225ac7165f58726f000ab1d67e9e61)

---

<div class="post-metadata">

**Author:** ![rthaker](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/rthaker/32/171374_2.png) [@rthaker](https://forums.developer.nvidia.com/u/rthaker)\
**Post date:** [July 18, 2023, 3:45pm UTC](https://forums.developer.nvidia.com/t/script-for-convex-decomposition-collisions/259649/2 "2023-07-18T15:45:29Z")

</div>

Hi @christopher117 - The `physics:approximation` attribute expects a token, which is a specific type of string used in USD to represent a limited set of predefined values. In this case, the valid tokens for `physics:approximation` are `none`, `convexHull`, `box`, `capsule`, `sphere`, `plane`, and `convexDecomposition`.

To set the `physics:approximation` attribute to `convexDecomposition`, you can use the `UsdPhysics.Tokens` class, which provides predefined tokens for all the valid values. Here’s how you can modify your script:

```auto
def add_collision(usd_path_load, usd_path_save):
    usd_context = get_context()
    stage = usd_context.open_stage(usd_path_load)
    stage = get_context().get_stage()
    rigidPrim = stage.GetPrimAtPath("/World/model_normalized/mesh")
    collisionAPI = UsdPhysics.CollisionAPI.Apply(rigidPrim)
    collisionAPI.GetPhysicsApproximationAttr().Set(UsdPhysics.Tokens.convexDecomposition)
    stage.Export(usd_path_save)

```

In this script, `UsdPhysics.Tokens.convexDecomposition` is a token representing the string `"convexDecomposition"`. The `GetPhysicsApproximationAttr().Set()` method is used to set the `physics:approximation` attribute of the `CollisionAPI`.

Please note that the actual path to your mesh and the context setup might need to be adjusted according to your specific setup.

---

<div class="post-metadata">

**Author:** ![sadelello](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sadelello](https://forums.developer.nvidia.com/u/sadelello)\
**Post date:** [December 30, 2024, 6:25pm UTC](https://forums.developer.nvidia.com/t/script-for-convex-decomposition-collisions/259649/3 "2024-12-30T18:25:49Z")

</div>

When I try and run this in Isaac Sim 4.2 I get the following error: AttributeError: ‘MeshCollisionAPI’ object has no attribute ‘GetPhysicsApproximationAttr’. Did you mean: ‘GetApproximationAttr’?

And when I use GetApproximationAttr instead, the sim will run, but the physics collider approximation will still have a convex hull instead of the convex decomposition token that was passed using: collisionAPI.GetApproximationAttr().Set(“convexDecomposition”).
