Is there a good way to add deformable objects within a python standalone script?
I saw in the tutorial how to add such an object within an extension, but I could not figure out how to add it in a standalone script.
For example, is there code to add an object set up as a deformable object in one USD file to another world?
Or is there a way to set up an object as a deformable object after loading the object described in the USD file?
Hi,
yes you should be able to do so, you can check the deformable body demo and display the script (most physics demos are generated through a python code). You can enable the demos - Window->Simulation->Physics->Demos.
I am pasting here the code snippet anyway:
import omni
from omni.physx.scripts import deformableUtils, physicsUtils
import omni.physxdemos as demo
import omni.usd
from pxr import UsdGeom, UsdLux, Gf, UsdPhysics
class DeformableBodyDemo(demo.Base):
title = "Deformable Body"
category = demo.Categories.DEFORMABLES
short_description = "Deformable body scene setup"
description = "This snippet sets up a deformable body scene"
@staticmethod
def create_sphere_mesh(stage, target_path):
_, tmp_path = omni.kit.commands.execute("CreateMeshPrim", prim_type="Sphere")
omni.kit.commands.execute("MovePrim", path_from=tmp_path, path_to=target_path)
omni.usd.get_context().get_selection().set_selected_prim_paths([], False)
return UsdGeom.Mesh.Get(stage, target_path)
def create(self, stage):
default_prim_path, scene = demo.setup_physics_scene(self, stage)
room = demo.get_demo_room(self, stage, zoom = 0.5)
# Create sphere mesh used as the 'skin mesh' for the deformable body
skin_mesh = self.create_sphere_mesh(stage, default_prim_path + "/deformableBody")
physicsUtils.set_or_add_translate_op(skin_mesh, translate=Gf.Vec3f(0.0, 0.0, 300.0))
physicsUtils.set_or_add_orient_op(skin_mesh, orient=Gf.Quatf(0.707, 0.707, 0, 0))
physicsUtils.set_or_add_scale_op(skin_mesh, scale=Gf.Vec3f(2.0, 2.0, 0.5))
color = demo.get_primary_color()
skin_mesh.CreateDisplayColorAttr().Set([color])
# Create tet meshes for simulation and collision based on the skin mesh
simulation_resolution = 10
# Apply PhysxDeformableBodyAPI and PhysxCollisionAPI to skin mesh and set parameter to default values
success = deformableUtils.add_physx_deformable_body(
stage,
skin_mesh.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, default_prim_path + "/deformableBodyMaterial", 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, skin_mesh.GetPrim(), deformable_material_path)
Regards,
Ales
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.