The standard Unity cloth simulator (based off of PhysX engine) was disatisfying and buggy. It struggled with interacting with enclosed objects such as the sleeve of a characters arm, usually requiring pinning to the object to tame the erratic collisions. I wanted a cloth simulator that could reliably handle capsule and sphere collision. I was not as interested with the simulation being realtime, although in the end a few heuristics for character-to-cloth interaction made it possible to be realtime. Instead I was interested in using this for my project in realtime data-driven cloth simulation, so reliability was a priority over speed.
Description
The algorithm used was a verlet-integration approach, also referred to as position-based dynamics in the literature. This approach is conditionally stable because the velocities are directly computed from the change in position of point particles due to position-contraint satisfaction. My specific implementation is inspired by T. Jakobsen, 2003 and J. Bender et al, 2015.
The codebase for the project can be found here. Below are a few screenshots exhibiting the use case of a cloth shirt on a character built of spheres and capsules. As is typical, the collision region of the object geometry is larger than the geometry’s mesh to avoid visual penetrations.
Another addition to allow for realtime speeds is what is referred to as “Smart Static Colliders” (SSCs). Becasue collision detection and resolution is the most expensive part of physics simulations, anything to reduce the number of collision checks is important. Hence research in data structures like bounded-volume hierarchies is always popular. SSCs is a quick and dirty wolution based on speed-ups for cloths where the relationship between the cloth particles and the rigid bodies it collides with are mostly constant (e.g. clothing on a character will always interact with the same parts of the body). During the first few frames of the character’s motion, a second region around the rigid body is used to keep track of all vertices that might collide with the rigid body; these are added to a vertex list for that rigid body and that vertex list remains unchanged. Below is an example of the SSC ‘baking’ region highlighted in blue.
Further Improvements
There is lots of work still to do on this to make it a competitive cloth simulator to eventually use in a video game. I’ve just listed some of them below.
(1) Improve SSC approach so that it is more adaptive. Either this includes using a BVH-esque design, or smartly recomputing the vertices lists.
(2) Port from C# to C++ for obvious speed-up gain.
(3) Cloth-to-cloth interaction is not implemented because this is very computationally demanding and my use cases for this simulator have not needed this yet. For this, a BVH structure would be crucical.