Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds APIs for spawning deformable meshes #613

Merged
merged 42 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f3ec164
initial commit
Mayankm96 Jul 1, 2024
31e49cb
adds deformable schema
Mayankm96 Jul 1, 2024
1718962
adds material binding
Mayankm96 Jul 1, 2024
6422130
fixes to run code
Mayankm96 Jul 1, 2024
97bc8e6
makes the example nicer
Mayankm96 Jul 1, 2024
4fca0a5
fixes function usage
Mayankm96 Jul 1, 2024
490540a
adds thorougher docstrings
Mayankm96 Jul 2, 2024
71e6bf0
adds collider api
Mayankm96 Jul 2, 2024
6ab3822
changes rest offset to be zero
Mayankm96 Jul 2, 2024
2ac2e3b
random poisson
Mayankm96 Jul 2, 2024
3bd3225
runs formatter
Mayankm96 Jul 2, 2024
3348dbd
fixes spawn prims docs
Mayankm96 Jul 2, 2024
85edb3b
adds demo mention
Mayankm96 Jul 2, 2024
a59c371
adds api docs
Mayankm96 Jul 2, 2024
cfb2ad4
fix all code links
Mayankm96 Jul 2, 2024
67cc50e
puts note at the right place
Mayankm96 Jul 2, 2024
39f21c8
adds link to geom mesh
Mayankm96 Jul 2, 2024
9b2ebfa
fixes docs
Mayankm96 Jul 2, 2024
9081117
Merge branch 'main' into feature/deformable-spawn
Mayankm96 Jul 2, 2024
292f5b8
fixes ordering of code
Mayankm96 Jul 2, 2024
7021172
adds more docs for clarity
Mayankm96 Jul 2, 2024
b0062dc
adds some more docs
Mayankm96 Jul 2, 2024
c6a0a2f
fixes for removing the mass api
Mayankm96 Jul 2, 2024
edd1594
fixes to demo script to showcase cloning
Mayankm96 Jul 2, 2024
dfae7b4
fix instructions
Mayankm96 Jul 2, 2024
cf2d2d4
adjusts camera view for nice view
Mayankm96 Jul 2, 2024
16fb522
readds mass props
Mayankm96 Jul 3, 2024
26e3ef6
Merge branch 'main' into feature/deformable-spawn
Dhoeller19 Jul 4, 2024
0c45449
fix orbit references
Mayankm96 Jul 4, 2024
80239d9
Merge branch 'main' into feature/deformable-spawn
Mayankm96 Jul 5, 2024
7d6d359
adds rigid body props to mesh
Mayankm96 Jul 5, 2024
357d6c3
adds check for material specification
Mayankm96 Jul 5, 2024
7416247
fixes todo link
Mayankm96 Jul 5, 2024
346627d
adds proper collision approx for meshes
Mayankm96 Jul 5, 2024
75bd974
adds a check mesh script
Mayankm96 Jul 5, 2024
733d8e7
Merge branch 'main' into feature/deformable-spawn
Mayankm96 Jul 5, 2024
8d7ee08
Update source/extensions/omni.isaac.lab/omni/isaac/lab/sim/spawners/m…
Dhoeller19 Jul 12, 2024
3fdf9b2
Update source/extensions/omni.isaac.lab/omni/isaac/lab/sim/spawners/m…
Dhoeller19 Jul 12, 2024
97b99cb
Update source/extensions/omni.isaac.lab/omni/isaac/lab/sim/spawners/m…
Dhoeller19 Jul 12, 2024
2063af9
Merge branch 'main' into feature/deformable-spawn
Mayankm96 Jul 13, 2024
987b6c2
updates changelog
Mayankm96 Jul 13, 2024
93b25c3
add danger notice
Mayankm96 Jul 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

Locally, the schemas are defined in the following files:

* ``_isaac_sim/kit/extsPhysics/omni.usd.schema.physics/plugins/UsdPhysics/resources/UsdPhysics/schema.usda``
* ``_isaac_sim/kit/extsPhysics/omni.usd.schema.physx/plugins/PhysxSchema/resources/PhysxSchema/schema.usda``
* ``_isaac_sim/extsPhysics/omni.usd.schema.physics/plugins/UsdPhysics/resources/UsdPhysics/schema.usda``
* ``_isaac_sim/extsPhysics/omni.usd.schema.physx/plugins/PhysxSchema/resources/generatedSchema.usda``

"""

Expand All @@ -38,12 +38,14 @@
define_collision_properties,
define_mass_properties,
define_rigid_body_properties,
define_deformable_body_properties,
modify_articulation_root_properties,
modify_collision_properties,
modify_fixed_tendon_properties,
modify_joint_drive_properties,
modify_mass_properties,
modify_rigid_body_properties,
modify_deformable_body_properties,
)
from .schemas_cfg import (
ArticulationRootPropertiesCfg,
Expand All @@ -52,4 +54,5 @@
JointDrivePropertiesCfg,
MassPropertiesCfg,
RigidBodyPropertiesCfg,
DeformableBodyPropertiesCfg,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import carb
import omni.isaac.core.utils.stage as stage_utils
import omni.physx.scripts.utils as physx_utils
from omni.physx.scripts import deformableUtils
from pxr import PhysxSchema, Usd, UsdPhysics

from ..utils import apply_nested, find_global_fixed_joint_prim, safe_set_attribute_on_usd_schema
from ..utils import apply_nested, find_global_fixed_joint_prim, safe_set_attribute_on_usd_schema, get_all_matching_child_prims
from . import schemas_cfg

"""
Expand Down Expand Up @@ -538,7 +539,7 @@ def modify_joint_drive_properties(
.. caution::

We highly recommend modifying joint properties of articulations through the functionalities in the
:mod:`omni.isaac.lab.actuators` module. The methods here are for setting simulation low-level
:mod:`omni.isaac.orbit.actuators` module. The methods here are for setting simulation low-level
properties only.

.. _UsdPhysics.DriveAPI: https://openusd.org/dev/api/class_usd_physics_drive_a_p_i.html
Expand Down Expand Up @@ -651,3 +652,157 @@ def modify_fixed_tendon_properties(
safe_set_attribute_on_usd_schema(physx_tendon_axis_api, attr_name, value, camel_case=True)
# success
return True


"""
Deformable body properties.
"""


def define_deformable_body_properties(
prim_path: str, cfg: schemas_cfg.DeformableBodyPropertiesCfg, stage: Usd.Stage | None = None
):
"""Apply the deformable body schema on the input prim and set its properties.

See :func:`modify_deformable_body_properties` for more details on how the properties are set.

Args:
prim_path: The prim path where to apply the deformable body schema.
cfg: The configuration for the deformable body.
stage: The stage where to find the prim. Defaults to None, in which case the
current stage is used.

Raises:
ValueError: When the prim path is not valid.
TypeError: When the prim already has conflicting API schemas.
"""
# obtain stage
if stage is None:
stage = stage_utils.get_current_stage()
# get USD prim
prim = stage.GetPrimAtPath(prim_path)
# check if prim path is valid
if not prim.IsValid():
raise ValueError(f"Prim path '{prim_path}' is not valid.")

# traverse the prim and get the mesh
matching_prims = get_all_matching_child_prims(prim_path, lambda p: p.GetTypeName() == "Mesh")
# check if the mesh is valid
if len(matching_prims) == 0:
raise ValueError(f"Could not find any mesh in '{prim_path}'. Please check asset.")
elif len(matching_prims) > 1:
# get list of all meshes found
mesh_paths = [p.GetPrimPath() for p in matching_prims]
raise ValueError(
f"Found multiple meshes in '{prim_path}': {mesh_paths}."
" Deformable body schema can only be applied to one mesh."
)

# get deformable-body USD prim
mesh_prim = matching_prims[0]
# check if prim has deformable-body applied on it
if not PhysxSchema.PhysxDeformableBodyAPI(mesh_prim):
PhysxSchema.PhysxDeformableBodyAPI.Apply(mesh_prim)
# set deformable body properties
modify_deformable_body_properties(mesh_prim.GetPrimPath(), cfg, stage)


@apply_nested
def modify_deformable_body_properties(
prim_path: str, cfg: schemas_cfg.DeformableBodyPropertiesCfg, stage: Usd.Stage | None = None
):
"""Modify PhysX parameters for a deformable body prim.

A `deformable body`_ is a single body that can be simulated by PhysX. Unlike rigid bodies, deformable bodies
support relative motion of the nodes in the mesh. Consequently, they can be used to simulate deformations
under applied forces.

PhysX soft body simulation employs Finite Element Analysis (FEA) to simulate the deformations of the mesh.
It uses two tetrahedral meshes to represent the deformable body:

1. **Simulation mesh**: This mesh is used for the simulation and is the one that is deformed by the solver.
2. **Collision mesh**: This mesh only needs to match the surface of the simulation mesh and is used for
collision detection.

For most applications, we assume that the above two meshes are computed from the "render mesh" of the deformable
body. The render mesh is the mesh that is visible in the scene and is used for rendering purposes. It is composed
of triangles and is the one that is used to compute the above meshes based on PhysX cookings.

The schema comprises of attributes that belong to the `PhysxDeformableBodyAPI`_. schemas containing the PhysX
parameters for the deformable body.

.. note::
We assume that the USD file for a deformable body contains a single mesh.
If the USD file contains multiple meshes, then the first mesh is used.

.. _deformable body: https://nvidia-omniverse.github.io/PhysX/physx/5.4.0/docs/SoftBodies.html
.. _PhysxDeformableBodyAPI: https://docs.omniverse.nvidia.com/kit/docs/omni_usd_schema_physics/104.2/class_physx_schema_physx_deformable_a_p_i.html

Args:
prim_path: The prim path to the deformable body.
cfg: The configuration for the deformable body.
stage: The stage where to find the prim. Defaults to None, in which case the
current stage is used.

Returns:
True if the properties were successfully set, False otherwise.

Raises:
ValueError: If the input prim path is not valid.
ValueError: If the input prim path does not contain a mesh or contains multiple meshes.
"""
# obtain stage
if stage is None:
stage = stage_utils.get_current_stage()

# get deformable-body USD prim
deformable_body_prim = stage.GetPrimAtPath(prim_path)

# check if the prim is valid and has the deformable-body API
if not deformable_body_prim.IsValid() or not PhysxSchema.PhysxDeformableBodyAPI(deformable_body_prim):
return False

# retrieve the physx deformable-body api
physx_deformable_body_api = PhysxSchema.PhysxDeformableBodyAPI(deformable_body_prim)
# retrieve the physx deformable api
physx_deformable_api = PhysxSchema.PhysxDeformableAPI(physx_deformable_body_api)

# convert to dict
cfg = cfg.to_dict()
# set into deformable body API
attr_kwargs = {
attr_name: cfg.pop(attr_name)
for attr_name in [
"kinematic_enabled",
"collision_simplification",
"collision_simplification_remeshing",
"collision_simplification_remeshing_resolution",
"collision_simplification_target_triangle_count",
"collision_simplification_force_conforming",
"simulation_hexahedral_resolution",
"solver_position_iteration_count",
"vertex_velocity_damping",
"sleep_damping",
"sleep_threshold",
"settling_threshold",
"self_collision",
"self_collision_filter_distance",
]
}
status = deformableUtils.add_physx_deformable_body(stage, prim_path=prim_path, **attr_kwargs)
# check if the deformable body was successfully added
if not status:
return False

# obtain the PhysX collision API (this is set when the deformable body is added)
physx_collision_api = PhysxSchema.PhysxCollisionAPI(deformable_body_prim)

# set into PhysX API
for attr_name, value in cfg.items():
if attr_name in ["rest_offset", "collision_offset"]:
safe_set_attribute_on_usd_schema(physx_collision_api, attr_name, value, camel_case=True)
else:
safe_set_attribute_on_usd_schema(physx_deformable_api, attr_name, value, camel_case=True)

# success
return True
Loading
Loading