This project has moved and is read-only. For the latest updates, please go here.

Cloth simulation possible?

Topics: User Forum
Jan 15, 2013 at 12:49 PM
Edited Jan 15, 2013 at 12:50 PM

Hi all, I've been playing around with the Farseer engine and I'm very impressed so far.


I was playing around with it and wanted to have something like cloth in order to have small items of clothing/capes/flags etc simulate being blown in the wind. I tried a very crude approach with paths of very small objects but the results weren't even close :P


There's a post over on: The Box2D forums which mentions someone porting exactly what I need to Farseer but its a few years old so I doubt the topic is still checked!

Jan 15, 2013 at 3:34 PM
Edited Jan 15, 2013 at 3:37 PM

If you just need eycandy you are much better off doing it in a GPU shader without physics. 

Farseer and Box2D don't support soft bodies (cloth is an example of a  2D soft body) so you'll need to simulate them using some sort of mass-springs system (distance joints in Farseer). This can have decent results but it's not exactly the same. Actually Farseer already has an example - the Web in the TestBed. Just to add to the thread you mentioned for cloth you'll need 3 types of links - structural (cover compression and elongation deformations), bend and shear to make it realistic.


At the end of the day it's many bodies with many joints which means slow simulation. For example I need an expandable balloon-like pressured body that can grow and shrink. I use prismatic joints with appropriate limits enabled between perimeter bodies representing the outer "border" and center bodies representing the "core" with a mixture of kinematic and dynamic control. It's quite CPU intensive especially when a lot of contacts are created during collisions, although it's physically quite realistic. In my case this soft body is central to my simulation so I cannot just fake it through a GPU shader. Unfortunately there are no free 2D soft body engines available and the 3D ones (Bullet, PhysX) also have their own sets of issues so for me this contraption is the closest I could get. You might manage with just the graphics.

Jan 15, 2013 at 4:49 PM

Thanks for the reply. I had a feeling it may be CPU intensive but I thought if I kept them fairly small it would be all right. I don't need it to be a real simulation, I just thought it might look cool.

I don't really know much about using the GPU to do such a thing sadly, I've only ever programmed boring software. I know very little about effects and almost nothing about Shaders. I don't even know how to Draw function or spritebatch class in XNA (other than to draw textures at a position/rotation/scale!).

Jan 19, 2013 at 9:00 PM

Wow, I remember that thread on Box2D waaay back. Paril is a friend of mine, and mattbettcher have done a lot of work on Farseer Physics.

Anyway, as jerrysb wrote, you are much better of doing this in another way. I would bet that there is a lot of examples on how to do cloth simulation on the GPU using Verlet integration. I've seen a couple on CPU the past years, and they are quite stable and fast.