This repository is still currently under development, so everything is still in testing mode. A lot of things will break, download at your own risk :/
Disclaimer: This project is in a paused state so there won't be more updates. In the future, if there are any changes to this project, I will post an issue update on this repository. Stay tune!
My goal is to replicate what this legend did: https://youtu.be/kCGHXlLR3l8 (A smooth and interactive cloth simulation)
Currently, my cloth simulation uses Postion Based Dynamics and supports:
- Distance Constraint
- Bending Constraint
- Point Triangle Distance Constraint (Self Collision)
- Aerodynamics (Wind Effect)
Features comming soon:
- Vivace Gauss Seidel Method for optimization on GPU (random graph coloring)
- Primitive Shape Collision (Sphere, Box and Capsule)
Check out my YouTube Playlist where I record my journey on how I approach this problem!
Support me on Patreon so that I can allocate more time to work on this project!
*Note: The GPU version is not fully developed yet, this tutorial section will not work for the GPU version.
- Create a mesh in Blender that you want to simulate.
- Use my custom Blender Addon - Blender Mesh to JSON to transform your mesh into PBD form and export it into your Unity's
StreamingAssets
folder. - Create an empty GameObject in Unity.
- Drag and drop
CPUClothSimulation.cs
orGPUClothSimulation.cs
script onto the GameObject. (Check Cloth Configurations for more cloth parameters' information.) - Select the correct JSON file that the Blender Cloth Exporter Tool exports using the button -
Select JSON File
. - Press the button -
Load Data from JSON
. - Put in your
Front Material
andBack Material
. - Press
Build Mesh
to build the mesh that you have modeled in Blender. - Press
Create Back Side
to build the other side of the mesh. - Press
Apply Materials
to apply materials on both sides.
These are the similar parameters in both CPU and GPU Cloth Simulation:
This determines the front material and back material for the cloth.
Tweak these parameters to change the behaviour for the cloth.
- Gravity: Constant acceleration.
- Compression Stiffness: Coefficient for distance constraint when 2 particles are too close together.
- Stretch Stiffness: Coefficient for distance constraint when 2 particles are too far away.
- Bending Stiffness: Coefficient for bending constraint when 2 neighbor triangles are not at their rest angle.
- Thickness: Cloth thickness for all collisions.
- Damping: Multiplier of velocity for every simulation to reduce velocity (as air resistance).
Tweak these parameters to balance between accuracy and performance.
- Iteration Steps: Number of iterations to solve constraints for every simulation.
- Delta Time Step: Time pass between 2 simulations.
- Start Simulation On Play: Choose if you want to start the simulation once you enter play mode.
This project is under MIT License.