Cloth Physics
by Robert Stewart · 10/23/2005 (4:50 pm) · 95 comments
Download Code File
This addition will add cloth physics to the Torque Game Engine.
This is a work in progress. Uses Melv's fxRenderObject code.
This should be ported to the Item class.
This has been updated, the class has been ported to shapebase, thanks to Johan Carlsson.
Note on what I think should happen next
Adding this to the existing particle system would allow us to use collision I think, and it will allow the cloth to be blown in TGE wind.
Another idea would be to have each vertice its own object(item). Imagine 20 health kits all linked toghether like cloth, the health kit would be invisible and a texture would be applied to the space like it is now, although you could drag each healthkit, it will move like if you were pinching that piece of cloth.
This addition will add cloth physics to the Torque Game Engine.
This is a work in progress. Uses Melv's fxRenderObject code.
This should be ported to the Item class.
This has been updated, the class has been ported to shapebase, thanks to Johan Carlsson.
Note on what I think should happen next
Adding this to the existing particle system would allow us to use collision I think, and it will allow the cloth to be blown in TGE wind.
Another idea would be to have each vertice its own object(item). Imagine 20 health kits all linked toghether like cloth, the health kit would be invisible and a texture would be applied to the space like it is now, although you could drag each healthkit, it will move like if you were pinching that piece of cloth.
About the author
Recent Blogs
• My game• RTS Kit A* Pathfinding Cont.
• RTS Kit A* Pathfinding
• I'm Back
• Plan for Robert Stewart
#2
10/23/2005 (4:55 pm)
I worked on a similar thing for a while along the same lines. When the Zip comes online I will check it out and see if there is any tips I can give you from what I learned. Being you are willing to show it, you must have made if futher than I.
#3
10/23/2005 (6:32 pm)
repost file, link got corrupted
#4
10/23/2005 (9:02 pm)
Gah! need download! :)
#5
10/24/2005 (4:23 am)
Please reupload this because i am excited to try it out
#6
EDIT: Works now
10/26/2005 (7:43 pm)
Sorry, i never saw this resource get approaved, I will try and re upload my changes.. If I can find them I have been busy on other stuff lately.EDIT: Works now
#7
I also don't really see any type of collision based stuff in this code, so I'm guessing that you can't really collide with the cloth at all... is that correct? In your updateCloth() function you call satisfyConstraints()... but I'm not quite sure what is happening in satisfyConstraints(). It seems like you are trying to stop the cloth from colliding with an imaginary sphere...
Anyway, some more general comments/explanation for this code would be great... but without a proper collision scheme it won't be terribly useful...
Thanks for the resource regardless... it would be a great starting point for someone starting their own cloth implementation!
Stephane
10/26/2005 (10:32 pm)
Okay... just at first glance (without compiling the code or anything), you shouldn't be updating your cloth in the renderObject function. This should happen in processTick() of your object. That way the cloth is part of the simulation and will be affected by things like $timescale (the scale of time in the simulation) and other time based effects. You can then also do interpolation in interpolateTick().I also don't really see any type of collision based stuff in this code, so I'm guessing that you can't really collide with the cloth at all... is that correct? In your updateCloth() function you call satisfyConstraints()... but I'm not quite sure what is happening in satisfyConstraints(). It seems like you are trying to stop the cloth from colliding with an imaginary sphere...
Anyway, some more general comments/explanation for this code would be great... but without a proper collision scheme it won't be terribly useful...
Thanks for the resource regardless... it would be a great starting point for someone starting their own cloth implementation!
Stephane
#8
10/26/2005 (10:35 pm)
My bad... I didn't know fxRenderObject was a child of SceneObject (SceneObject doesn't have processTick functionality). Might you not want to consider making your object a child of GameBase (which has processTick, interpolateTick, etc.)?
#9
10/27/2005 (9:30 am)
Stephane, that is an awesome idea about the GameBase. That is probrally the whole problem. Because when the TIMESCALE is screwed up even a little bit it goes wacky. Adding collision would be trivial, that I can work on soon as I get the rendering done properly.
#10
10/27/2005 (12:40 pm)
Boy i hope someone gets it working :) i sure could use it, i dread having to hand animate all the clothing for my characters.
#12
It surely looks weird, I'm not even sure it works at all?
Any suggestion how to configure it?
Any chance you could send me the starter.fps/data/shapes/bot/bot_skin.jpg?
It might work better?
btw. the default configuration with QuadRotateSpeed set to 90.0f crashes the application (or freezes it).
Edit: Oh. I see that the QuadRotateSpeed isn't used anywhere!
Edit: Screenshot of how it looks: http://www.fred.nu/Torque/strange_cloth.jpg
Edit. Scaled down cloth looks like this, it seams like the wind is grabbing a hold but it doesn't strait thing out. I'vent figured out how the initial points and weights are set, gone look at that next...
10/30/2005 (7:28 am)
>> Ok so at the moment, it displays a wierd looking cloth. It surely looks weird, I'm not even sure it works at all?
Any suggestion how to configure it?
Any chance you could send me the starter.fps/data/shapes/bot/bot_skin.jpg?
It might work better?
btw. the default configuration with QuadRotateSpeed set to 90.0f crashes the application (or freezes it).
Edit: Oh. I see that the QuadRotateSpeed isn't used anywhere!
Edit: Screenshot of how it looks: http://www.fred.nu/Torque/strange_cloth.jpg
Edit. Scaled down cloth looks like this, it seams like the wind is grabbing a hold but it doesn't strait thing out. I'vent figured out how the initial points and weights are set, gone look at that next...
#13
Also the solver seems really slow? I though the verlet solver would be really speedy?
10/30/2005 (9:58 am)
Hm, I changed mClothRes to CLOTH_RESOLUTION in renderObject. I can't see what mClothRes comes from?Also the solver seems really slow? I though the verlet solver would be really speedy?
#14
10/30/2005 (9:59 am)
What different is it between setuptype=0 and setuptype=1
#15
NOTE: The solver speed would be for the same reason, it needs to go through processtick. Oh and you can use any texture.
NOTE: I heard that item is a good place to start a new gamebase object.
10/30/2005 (10:03 am)
That screenshot is exactly what happens in my extrernal app when TIMESCALE is not set properly. So basically what needs to happen, is this needs to be ported to over to a shapebase object, so it will have processtick. If I get time I will do this my self.NOTE: The solver speed would be for the same reason, it needs to go through processtick. Oh and you can use any texture.
NOTE: I heard that item is a good place to start a new gamebase object.
#16
I've started to try to make a port to a class I've based on the Item/ItemData classes (called ClothItem).
But since I'm still learning TGE and my C++ skills need some improvements I can't promise anything at this point.
I alson don't have the time at the moment :-(
I'm guessing that even though I think it's an overkill to network the cloth it's good thing to make the Item networked.
At the moment my ClothItem has physics behavior (e.g. responds to gravity) which I think I need to turn of and
let the cloth simuation controll the gravity(?)
(I can post the cut&paste I've made of Item if you find it useful?)
10/31/2005 (1:54 am)
Thanks Robert.I've started to try to make a port to a class I've based on the Item/ItemData classes (called ClothItem).
But since I'm still learning TGE and my C++ skills need some improvements I can't promise anything at this point.
I alson don't have the time at the moment :-(
I'm guessing that even though I think it's an overkill to network the cloth it's good thing to make the Item networked.
At the moment my ClothItem has physics behavior (e.g. responds to gravity) which I think I need to turn of and
let the cloth simuation controll the gravity(?)
(I can post the cut&paste I've made of Item if you find it useful?)
#17
10/31/2005 (8:29 am)
I have my own version of the item class, although I only spent a few mintues, that is really how much time I have lately. I would be glad to see yours. For now you should let the cloth simulation handle gravity, soon as this gets publicly ported to a shapebase class I will make it work with the Torque enviroment a little better. I even plan on writing a cloth editor for TGE.
#18
Got the cloth-sim into a Item-based class and sorted out some problems (most of them added by me :-)
http://www.fred.nu/Torque/good_cloth_1.jpg
http://slask.fred.nu/longclip.avi
http://slask.fred.nu/shortclip.avi
I get a box that gets render above evertything, I think it comes from fxRenderObject, I'm gone remove that next.
FPS is at about 25 which is what I get without the ClothItem compiled in so I'm guessing it's really fast :-)
11/03/2005 (6:06 am)
Ok, I did some work on this (i stole some time).Got the cloth-sim into a Item-based class and sorted out some problems (most of them added by me :-)
http://www.fred.nu/Torque/good_cloth_1.jpg
http://slask.fred.nu/longclip.avi
http://slask.fred.nu/shortclip.avi
I get a box that gets render above evertything, I think it comes from fxRenderObject, I'm gone remove that next.
FPS is at about 25 which is what I get without the ClothItem compiled in so I'm guessing it's really fast :-)
#19
11/03/2005 (9:27 am)
wow. looks good! But why an Item class? Why not static shape?
#20
I cant find the right codec to watch your videos either.
11/03/2005 (10:05 am)
Johan, good job. Any chance you will share your changes? Just so we could improve performance and add extra features? It's up to you, it will just save me some time.I cant find the right codec to watch your videos either.

Torque Owner Robert Stewart