# How can I make deformable body in python?

**URL:** <https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959>\
**Category:** Isaac Sim\
**Tags:** physx, gpu, python\
**Created:** [June 17, 2023, 6:00am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959 "2023-06-17T06:00:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuya\_t](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Yuya\_t](https://forums.developer.nvidia.com/u/Yuya_t)\
**Post date:** [June 17, 2023, 6:00am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/1 "2023-06-17T06:00:19Z")

</div>

I want to make deformable body in python program.  
But, I have the following error.  
What should I do to make deformable body in python?  
Please tell me the solution.

[Error] [omni.physx.plugin] Deformable Body feature is only supported on GPU. Please enable GPU dynamics flag in Property/Scene of physics scene!

![GPU_error](https://global.discourse-cdn.com/nvidia/original/4X/5/3/3/53301ff260bef0e89d3911ec0280a868ec15b16d.png)

```auto
from omni.isaac.examples.base_sample import BaseSample
import numpy as np
import math

from omni.physx.scripts import deformableUtils, physicsUtils  
import omni.physxdemos as demo
import omni.usd

from pxr import UsdGeom, Sdf, Gf, PhysxSchema, UsdPhysics

import omni.physx
from pxr import UsdGeom

import omni
import carb 

class HelloWorld(BaseSample):  
    def __init__ (self) -> None: 
        super(). __init__ ()
        return

    def setup_scene(self):
        world = self.get_world()
        
        world.scene.add_default_ground_plane()
        
        stage = omni.usd.get_context().get_stage()
        physics_scene = UsdPhysics.Scene.Define(stage, Sdf.Path("/World/physicsScene"))
        physx_scene = PhysxSchema.PhysxSceneAPI.Apply(physics_scene.GetPrim())
        physx_scene.CreateEnableGPUDynamicsAttr().Set(True) #enable GPU
        
        world.set_simulation_dt(physics_dt=1.0 / 600.0, rendering_dt=1.0 / 60.0) #change dt
        
        #make cube
        result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Cube")
        # Get the prim
        cube_prim = stage.GetPrimAtPath(path)
        
        xform = UsdGeom.Xformable(cube_prim)
        transform = xform.AddTransformOp()
        mat = Gf.Matrix4d()
        xform.AddTranslateOp().Set(Gf.Vec3d(0.0,0.0,1.0))   
        mat.SetRotateOnly(Gf.Rotation(Gf.Vec3d(0,0,0), 290))  
        xform.AddScaleOp().Set(Gf.Vec3f(0.5, 0.5, 0.5))
        transform.Set(mat)
        
        simulation_resolution = 10

        # Apply PhysxDeformableBodyAPI and PhysxCollisionAPI to skin mesh and set parameter to default values
        success = deformableUtils.add_physx_deformable_body(
            stage,
            xform.GetPath(),
            collision_simplification=True,
            simulation_hexahedral_resolution=simulation_resolution,
            self_collision=False,
        )

        # Create a deformable body material and set it on the deformable body
        deformable_material_path = omni.usd.get_stage_next_free_path(stage, "Cube", True)
        deformableUtils.add_deformable_body_material(
            stage,
            deformable_material_path,
            youngs_modulus=10000.0,
            poissons_ratio=0.49,
            damping_scale=0.0,
            dynamic_friction=0.5,
        )
        physicsUtils.add_physics_material_to_prim(stage, xform.GetPrim(), deformable_material_path)       
    
    async def setup_post_load(self):        
        self._world = self.get_world()
        return

```

---

<div class="post-metadata">

**Author:** ![AlesBorovicka](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/alesborovicka/32/21824_2.png) [@AlesBorovicka](https://forums.developer.nvidia.com/u/AlesBorovicka)\
**Post date:** [June 19, 2023, 11:08am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/2 "2023-06-19T11:08:40Z")

</div>

Hi,  
ah yes, this does ring a bell, I think this is a duplicate issue of this forum question:

> [@GPU dynamics flag only takes effect after manually opening physicsScene in the GUI](https://forums.developer.nvidia.com/t/gpu-dynamics-flag-only-takes-effect-after-manually-opening-physicsscene-in-the-gui/248922/8):
>
> I’m using Isaac Sim 2022.2.1 with Kit 104.2. Launching Isaac from python doesn’t have the Help tab but I assume is using the same Kit version. I didn’t know that particles where not fully supported on Isaac. For me they work good, except fot the issue explained in this post. I’m developing a project that needs to simulate fluids and connects to ROS, that’s why is handy to have a python script launching the simulation With the line I posted previously, which set Fabric/Flatcache, the particles …

See the answer from Kelly at the end, I think its the same issue. The GPU dynamics on a physics scene needs to be enabled, but is somehow turned off by the Isaac scripts.

Regards,  
Ales

---

<div class="post-metadata">

**Author:** ![Yuya\_t](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Yuya\_t](https://forums.developer.nvidia.com/u/Yuya_t)\
**Post date:** [June 21, 2023, 4:32am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/3 "2023-06-21T04:32:27Z")

</div>

Thanks, Ales.

I added SimulationContext(set\_defaults=False), but I got the same error. Is there something wrong with my program’s coding?

```auto
from omni.isaac.examples.base_sample import BaseSample
import numpy as np
import math

from omni.physx.scripts import deformableUtils, physicsUtils  
import omni.physxdemos as demo
import omni.usd

from pxr import UsdGeom, Sdf, Gf, PhysxSchema, UsdPhysics

import omni.physx
from pxr import UsdGeom

import omni
import carb 

from omni.isaac.core import SimulationContext

class HelloWorld(BaseSample):  
    def __init__ (self) -> None: 
        super(). __init__ ()
        return

    def setup_scene(self):
        #world = self.get_world()
        world = SimulationContext(set_defaults=False)
        
        world.scene.add_default_ground_plane()
        
        stage = omni.usd.get_context().get_stage()
        physics_scene = UsdPhysics.Scene.Define(stage, Sdf.Path("/World/physicsScene"))
        physx_scene = PhysxSchema.PhysxSceneAPI.Apply(physics_scene.GetPrim())
        
        physx_scene.CreateEnableGPUDynamicsAttr().Set(True) #enable GPU
        
        world.set_simulation_dt(physics_dt=1.0 / 600.0, rendering_dt=1.0 / 60.0) #change dt
        
        #make cube
        result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Cube")
        # Get the prim
        cube_prim = stage.GetPrimAtPath(path)
        
        xform = UsdGeom.Xformable(cube_prim)
        transform = xform.AddTransformOp()
        mat = Gf.Matrix4d()
        xform.AddTranslateOp().Set(Gf.Vec3d(0.0,0.0,1.0))   
        mat.SetRotateOnly(Gf.Rotation(Gf.Vec3d(0,0,0), 290))  
        xform.AddScaleOp().Set(Gf.Vec3f(0.5, 0.5, 0.5))
        transform.Set(mat)
        
        simulation_resolution = 10

        # Apply PhysxDeformableBodyAPI and PhysxCollisionAPI to skin mesh and set parameter to default values
        success = deformableUtils.add_physx_deformable_body(
            stage,
            xform.GetPath(),
            collision_simplification=True,
            simulation_hexahedral_resolution=simulation_resolution,
            self_collision=False,
        )

        # Create a deformable body material and set it on the deformable body
        deformable_material_path = omni.usd.get_stage_next_free_path(stage, "Cube", True)
        deformableUtils.add_deformable_body_material(
            stage,
            deformable_material_path,
            youngs_modulus=10000.0,
            poissons_ratio=0.49,
            damping_scale=0.0,
            dynamic_friction=0.5,
        )
        physicsUtils.add_physics_material_to_prim(stage, xform.GetPrim(), deformable_material_path)       
    
    async def setup_post_load(self):        
        self._world = self.get_world()
        return

```

---

<div class="post-metadata">

**Author:** ![AlesBorovicka](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/alesborovicka/32/21824_2.png) [@AlesBorovicka](https://forums.developer.nvidia.com/u/AlesBorovicka)\
**Post date:** [June 21, 2023, 12:32pm UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/4 "2023-06-21T12:32:29Z")

</div>

I think what you need are these lines:

```auto
# Configure the physics scene to use GPU dynamics for particles (fluids)
physics_context = simulation_context.get_physics_context()
physics_context.enable_gpu_dynamics(True)

```

---

<div class="post-metadata">

**Author:** ![Yuya\_t](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Yuya\_t](https://forums.developer.nvidia.com/u/Yuya_t)\
**Post date:** [June 22, 2023, 7:13am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/5 "2023-06-22T07:13:30Z")

</div>

Thanks for the fast reply Ales.  
I tried to add your lines, but I got same error.  
Is it wrong to write the following?

```auto
from omni.isaac.examples.base_sample import BaseSample
import numpy as np
import math

from omni.physx.scripts import deformableUtils, physicsUtils  
import omni.physxdemos as demo
import omni.usd

from pxr import UsdGeom, Sdf, Gf, PhysxSchema, UsdPhysics

import omni.physx
from pxr import UsdGeom

import omni
import carb 

from omni.isaac.core import SimulationContext

class HelloWorld(BaseSample):  
    def __init__ (self) -> None: 
        super(). __init__ ()
        return

    def setup_scene(self):
        #world = self.get_world()
        world = SimulationContext(set_defaults=False)
        
        world.scene.add_default_ground_plane()
        
        stage = omni.usd.get_context().get_stage()
        
        # Configure the physics scene to use GPU dynamics for particles (fluids)
        physics_context = world.get_physics_context()
        physics_context.enable_gpu_dynamics(True)
        
        world.set_simulation_dt(physics_dt=1.0 / 600.0, rendering_dt=1.0 / 60.0) #change dt
        
        #make cube
        result, path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Cube")
        # Get the prim
        cube_prim = stage.GetPrimAtPath(path)
        
        xform = UsdGeom.Xformable(cube_prim)
        transform = xform.AddTransformOp()
        mat = Gf.Matrix4d()
        xform.AddTranslateOp().Set(Gf.Vec3d(0.0,0.0,1.0))   
        mat.SetRotateOnly(Gf.Rotation(Gf.Vec3d(0,0,0), 290))  
        xform.AddScaleOp().Set(Gf.Vec3f(0.5, 0.5, 0.5))
        transform.Set(mat)
        
        simulation_resolution = 10

        # Apply PhysxDeformableBodyAPI and PhysxCollisionAPI to skin mesh and set parameter to default values
        success = deformableUtils.add_physx_deformable_body(
            stage,
            xform.GetPath(),
            collision_simplification=True,
            simulation_hexahedral_resolution=simulation_resolution,
            self_collision=False,
        )

        # Create a deformable body material and set it on the deformable body
        deformable_material_path = omni.usd.get_stage_next_free_path(stage, "Cube", True)
        deformableUtils.add_deformable_body_material(
            stage,
            deformable_material_path,
            youngs_modulus=10000.0,
            poissons_ratio=0.49,
            damping_scale=0.0,
            dynamic_friction=0.5,
        )
        physicsUtils.add_physics_material_to_prim(stage, xform.GetPrim(), deformable_material_path) 
            
    
    async def setup_post_load(self):        
        self._world = self.get_world()
        return

```

---

<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 11, 2023, 10:21pm UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/6 "2023-07-11T22:21:11Z")

</div>

Hi @Yuya_t - The error message you’re seeing is indicating that the GPU dynamics flag needs to be enabled in the physics scene properties. This is because deformable bodies in PhysX require GPU acceleration.

You are already enabling GPU dynamics in your code with the line physics\_context.enable\_gpu\_dynamics(True). However, it seems like this is not taking effect.

One possible reason could be that the GPU dynamics flag needs to be set before the physics scene is created. If the physics scene is already created before this line is executed, the change might not take effect.

You can try moving the enable\_gpu\_dynamics(True) line to be before the world.scene.add\_default\_ground\_plane() line, like this:

physics\_context = world.get\_physics\_context()  
physics\_context.enable\_gpu\_dynamics(True)

world.scene.add\_default\_ground\_plane()  
This ensures that the GPU dynamics flag is set before the physics scene is created.

If this doesn’t solve the issue, it could be that your system doesn’t support GPU acceleration, or the necessary GPU drivers are not installed. You can check if your system supports GPU acceleration and if the necessary drivers are installed.

---

<div class="post-metadata">

**Author:** ![Yuya\_t](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Yuya\_t](https://forums.developer.nvidia.com/u/Yuya_t)\
**Post date:** [July 12, 2023, 5:31am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/7 "2023-07-12T05:31:08Z")

</div>

Thank you for reply @rthaker .  
I tried your opinion, but I didn’t solve error.

I enabled gpu again at GUI, the problem was solved.

---

<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:11pm UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/8 "2023-07-18T15:11:04Z")

</div>

Hi @Yuya_t - There is a new Isaac Sim release coming around Aug/Sep timeframe. I think this should not happen with that latest release.

---

<div class="post-metadata">

**Author:** ![Yuya\_t](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Yuya\_t](https://forums.developer.nvidia.com/u/Yuya_t)\
**Post date:** [July 19, 2023, 6:01am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/9 "2023-07-19T06:01:06Z")

</div>

That’s good news! I am expectantly waiting for that.

---

<div class="post-metadata">

**Author:** ![tge13751](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tge13751](https://forums.developer.nvidia.com/u/tge13751)\
**Post date:** [February 28, 2024, 9:36am UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/10 "2024-02-28T09:36:15Z")

</div>

Try this one bro ;) - Worked at Isaac Sim 2023.1.1

```auto
from omni.isaac.core.physics_context.physics_context import PhysicsContext
...
        self._scene = PhysicsContext()
        self._scene.set_solver_type("TGS")
        self._scene.set_broadphase_type("GPU")
        self._scene.enable_gpu_dynamics(flag=True)

```

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/system/32/68080_2.png) [@system](https://forums.developer.nvidia.com/u/system)\
**Post date:** [March 20, 2024, 10:22pm UTC](https://forums.developer.nvidia.com/t/how-can-i-make-deformable-body-in-python/256959/11 "2024-03-20T22:22:27Z")

</div>

Closed on March 20, 2024, 10:22pm UTC

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