-
Notifications
You must be signed in to change notification settings - Fork 9
Add cloth object #198
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
Merged
Merged
Add cloth object #198
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c3f1c5
add cloth object
24c2649
update example
4ae3394
add unittest
c90e825
update
c767af1
remove
d2531af
Merge branch 'main' into cj/add-cloth-object
59640dc
fix arena position in soft | cloth
d79b6c4
update
a0fadee
update
593bb84
update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| Creating a cloth simulation | ||
| =========================== | ||
|
|
||
| .. currentmodule:: embodichain.lab.sim | ||
|
|
||
| This tutorial shows how to create a cloth simulation using ``SimulationManager``. It covers procedurally generating a grid mesh, configuring a deformable cloth object, adding a rigid body for interaction, and running the simulation loop. | ||
|
|
||
| The Code | ||
| ~~~~~~~~ | ||
|
|
||
| The tutorial corresponds to the ``create_cloth.py`` script in the ``scripts/tutorials/sim`` directory. | ||
|
|
||
| .. dropdown:: Code for create_cloth.py | ||
| :icon: code | ||
|
|
||
| .. literalinclude:: ../../../scripts/tutorials/sim/create_cloth.py | ||
| :language: python | ||
| :linenos: | ||
|
|
||
|
|
||
| The Code Explained | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Generating the cloth mesh | ||
| -------------------------- | ||
|
|
||
| Unlike the soft-body tutorial where a pre-existing mesh file is loaded, cloth objects are typically defined by a flat 2-D surface. The helper function ``create_2d_grid_mesh`` generates a rectangular grid mesh procedurally using PyTorch, then saves it to a temporary ``.ply`` file via Open3D so that the simulation can load it. | ||
|
|
||
| Loading a mesh from file also works for cloth objects, but generating a grid in code allows for easy customization of the cloth dimensions and resolution. | ||
|
|
||
| The function accepts the physical dimensions (``width``, ``height``) and the number of subdivisions (``nx``, ``ny``). A finer grid gives more cloth-like wrinkle detail at the cost of simulation performance. | ||
|
|
||
| .. literalinclude:: ../../../scripts/tutorials/sim/create_cloth.py | ||
| :language: python | ||
| :start-at: def create_2d_grid_mesh | ||
| :end-at: return verts, faces | ||
|
|
||
| Configuring the simulation | ||
| -------------------------- | ||
|
|
||
| The simulation environment is configured with :class:`SimulationManagerCfg`. For cloth simulation the device must be set to ``cuda``. The ``arena_space`` parameter controls the spacing between parallel environments so that objects in neighboring environments do not overlap. | ||
|
|
||
| .. literalinclude:: ../../../scripts/tutorials/sim/create_cloth.py | ||
| :language: python | ||
| :start-at: # Configure the simulation | ||
| :end-at: print("[INFO]: Scene setup complete!") | ||
|
|
||
| Adding a cloth object to the scene | ||
| ------------------------------------ | ||
|
|
||
| The grid mesh generated earlier is saved to disk and then passed to :meth:`SimulationManager.add_cloth_object`. The physical properties of the cloth are controlled through :class:`cfg.ClothObjectCfg` together with :class:`cfg.ClothPhysicalAttributesCfg`: | ||
|
|
||
| - :class:`cfg.MeshCfg` — references the ``.ply`` file written to the system temp directory | ||
| - :class:`cfg.ClothPhysicalAttributesCfg` — material parameters: | ||
|
|
||
| - ``mass`` — total mass of the cloth panel (kg) | ||
| - ``youngs`` / ``poissons`` — elastic stiffness and compressibility | ||
| - ``thickness`` — collision thickness of the cloth surface | ||
| - ``bending_stiffness`` / ``bending_damping`` — resistance to and dissipation of bending motion | ||
| - ``dynamic_friction`` — friction between the cloth and other objects | ||
| - ``min_position_iters`` — solver iteration count for position constraints | ||
|
|
||
| .. literalinclude:: ../../../scripts/tutorials/sim/create_cloth.py | ||
| :language: python | ||
| :start-at: cloth_verts, cloth_faces = create_2d_grid_mesh | ||
| :end-at: ) | ||
| :end-before: padding_box_cfg | ||
|
|
||
| Adding a rigid body for interaction | ||
| ------------------------------------- | ||
|
|
||
| A small cubic rigid body (``padding_box``) is placed beneath the cloth so the cloth drapes over it. It is added with :meth:`SimulationManager.add_rigid_object` using :class:`cfg.RigidObjectCfg` and :class:`cfg.RigidBodyAttributesCfg`: | ||
|
|
||
| - :class:`cfg.CubeCfg` — defines the box dimensions | ||
| - ``body_type="dynamic"`` — the box responds to physics; change to ``"static"`` for a fixed obstacle | ||
| - ``static_friction`` / ``dynamic_friction`` — surface friction keeps the cloth from sliding off too easily | ||
|
|
||
| .. literalinclude:: ../../../scripts/tutorials/sim/create_cloth.py | ||
| :language: python | ||
| :start-at: padding_box_cfg = RigidObjectCfg( | ||
| :end-at: print("[INFO]: Add soft object complete!") | ||
|
|
||
| The Code Execution | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To run the script and see the result, execute the following command: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python scripts/tutorials/sim/create_cloth.py | ||
|
|
||
| A window should appear showing a cloth panel falling and draping over a small rigid box. To stop the simulation, close the window or press ``Ctrl+C`` in the terminal. | ||
|
|
||
| You can also pass arguments to customise the simulation. For example, to run in headless mode with ``n`` parallel environments: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| python scripts/tutorials/sim/create_cloth.py --headless --num_envs <n> | ||
|
|
||
| Now that we have a basic understanding of how to create a cloth scene, let's move on to more advanced topics. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ Tutorials | |
|
|
||
| create_scene | ||
| create_softbody | ||
| create_cloth | ||
| rigid_object_group | ||
| robot | ||
| add_robot | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dexsimis imported here but not used anywhere in this module. Please remove the unused import to avoid lint issues and reduce import overhead.