Source code for isaaclab.sim.spawners.materials.physics_materials
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.# All rights reserved.## SPDX-License-Identifier: BSD-3-Clausefrom__future__importannotationsfromtypingimportTYPE_CHECKINGimportisaacsim.core.utils.primsasprim_utilsimportisaacsim.core.utils.stageasstage_utilsfrompxrimportPhysxSchema,Usd,UsdPhysics,UsdShadefromisaaclab.sim.utilsimportclone,safe_set_attribute_on_usd_schemaifTYPE_CHECKING:from.importphysics_materials_cfg
[docs]@clonedefspawn_rigid_body_material(prim_path:str,cfg:physics_materials_cfg.RigidBodyMaterialCfg)->Usd.Prim:"""Create material with rigid-body physics properties. Rigid body materials are used to define the physical properties to meshes of a rigid body. These include the friction, restitution, and their respective combination modes. For more information on rigid body material, please refer to the `documentation on PxMaterial <https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/_api_build/classPxBaseMaterial.html>`_. .. note:: This function is decorated with :func:`clone` that resolves prim path into list of paths if the input prim path is a regex pattern. This is done to support spawning multiple assets from a single and cloning the USD prim at the given path expression. Args: prim_path: The prim path or pattern to spawn the asset at. If the prim path is a regex pattern, then the asset is spawned at all the matching prim paths. cfg: The configuration for the physics material. Returns: The spawned rigid body material prim. Raises: ValueError: When a prim already exists at the specified prim path and is not a material. """# create material prim if no prim existsifnotprim_utils.is_prim_path_valid(prim_path):_=UsdShade.Material.Define(stage_utils.get_current_stage(),prim_path)# obtain primprim=prim_utils.get_prim_at_path(prim_path)# check if prim is a materialifnotprim.IsA(UsdShade.Material):raiseValueError(f"A prim already exists at path: '{prim_path}' but is not a material.")# retrieve the USD rigid-body apiusd_physics_material_api=UsdPhysics.MaterialAPI(prim)ifnotusd_physics_material_api:usd_physics_material_api=UsdPhysics.MaterialAPI.Apply(prim)# retrieve the collision apiphysx_material_api=PhysxSchema.PhysxMaterialAPI(prim)ifnotphysx_material_api:physx_material_api=PhysxSchema.PhysxMaterialAPI.Apply(prim)# convert to dictcfg=cfg.to_dict()delcfg["func"]# set into USD APIforattr_namein["static_friction","dynamic_friction","restitution"]:value=cfg.pop(attr_name,None)safe_set_attribute_on_usd_schema(usd_physics_material_api,attr_name,value,camel_case=True)# set into PhysX APIforattr_name,valueincfg.items():safe_set_attribute_on_usd_schema(physx_material_api,attr_name,value,camel_case=True)# return the primreturnprim
[docs]@clonedefspawn_deformable_body_material(prim_path:str,cfg:physics_materials_cfg.DeformableBodyMaterialCfg)->Usd.Prim:"""Create material with deformable-body physics properties. Deformable body materials are used to define the physical properties to meshes of a deformable body. These include the friction and deformable body properties. For more information on deformable body material, please refer to the documentation on `PxFEMSoftBodyMaterial`_. .. note:: This function is decorated with :func:`clone` that resolves prim path into list of paths if the input prim path is a regex pattern. This is done to support spawning multiple assets from a single and cloning the USD prim at the given path expression. Args: prim_path: The prim path or pattern to spawn the asset at. If the prim path is a regex pattern, then the asset is spawned at all the matching prim paths. cfg: The configuration for the physics material. Returns: The spawned deformable body material prim. Raises: ValueError: When a prim already exists at the specified prim path and is not a material. .. _PxFEMSoftBodyMaterial: https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/_api_build/structPxFEMSoftBodyMaterialModel.html """# create material prim if no prim existsifnotprim_utils.is_prim_path_valid(prim_path):_=UsdShade.Material.Define(stage_utils.get_current_stage(),prim_path)# obtain primprim=prim_utils.get_prim_at_path(prim_path)# check if prim is a materialifnotprim.IsA(UsdShade.Material):raiseValueError(f"A prim already exists at path: '{prim_path}' but is not a material.")# retrieve the deformable-body apiphysx_deformable_body_material_api=PhysxSchema.PhysxDeformableBodyMaterialAPI(prim)ifnotphysx_deformable_body_material_api:physx_deformable_body_material_api=PhysxSchema.PhysxDeformableBodyMaterialAPI.Apply(prim)# convert to dictcfg=cfg.to_dict()delcfg["func"]# set into PhysX APIforattr_name,valueincfg.items():safe_set_attribute_on_usd_schema(physx_deformable_body_material_api,attr_name,value,camel_case=True)# return the primreturnprim