Light Green
Light Blue
Gris Souris
Cloth Simulator
Désolé, seulement en anglais !

This is the documentation for a small program I wrote that simulates the behaviour of a piece of cloth draped over various shapes:

You can download the source code here (it includes this documentation) or a linux binary here. It is distributed under the GPL license. If anybody makes executables for other platforms, please let me know so I can add a link here.

Christoph Hormann made a windows executable here. Thanks! I've also made one a little while ago. It is more recent than the previous one, but I'm not sure whether it is version 0.4.1 (which is what it will report) or something a little more recent. You can get it here.


From version 0.4.1 to 0.4.2:

Note that I left the project alone for a long time between v0.4.0 and 0.4.1 and there are things I hadn't documented and am not sure I remember right. (Actually, some of the changes didn't even make it into CVS and I can't remember what the h*ll they were for).

From version 0.4.0 to 0.4.1:

From version 0.3.1 to 0.4.0:

From version 0.3.0 to 0.3.1:

From version 0.2.0 to 0.3.0:

From version 0.1.0 to 0.2.0:


The program takes an input file made of three parts: a global_settings section, a cloth definition and object definitions. The parts must appear in that order, but only the cloth section is mandatory. Here is a very simple sample that drapes a piece of cloth over a cylinder (like a napkin over a round table):

global_settings {
  step 0.2

cloth {
  x_size 50
  y_size 50

cylinder { -2*z, -z, 20 } // Table top
/* Note that *z* is the up-pointing vector */

That's it. You can run it with cloth -s20000 to produce the file which you can then include into a POVray scene file:

#version unofficial MegaPov 0.6;

global_settings {
  assumed_gamma 1.0

camera {
  location 50*x-75*z+25*y
  look_at -10*y
  angle 40

light_source {
  <1000, 1000, -1000>
  rgb 1

object {
  #include ""
  pigment {
    object {
      sphere { 1.5*x+y, 0.5 }
      pigment {
        object {
          box { <0, 0.5, -0.5>, <1, 1.5, 0.5> }
          color rgb 0.75
          color rgb 0.25
      pigment { color rgb 0.5 }
    warp { repeat 2*x }
    warp { repeat 2*y }
    scale 0.025

cylinder { // ground
  -60*y, -30*y, 100
  pigment {
    color rgb <0, 0, 1>, color rgb <0.9, 0.9, 1>
    scale 5

union {
  cylinder { -2*y, -1.01*y, 19 }
  cylinder { -35*y, -1.5*y, 2 }
  pigment { color rgb 1 }

The result is the picture in the upper right corner.

The global_settings section.

There are two parameters in this section:

The cloth section.

This section defines all the parameters that define the piece of cloth:

All these are optional, look into for the default values. Most of these values do not depend on the others, so if you want to run tests in low resolution and then increase x_size and y_size while decreasing dist you should get pretty much the same results (the only exception is stiffness).

Unless you specified position or read_file the piece of cloth starts centered at the origin and horizontal. If you want to change this, you can transform it after having given all the parameters by adding any number of translation and rotations (see Note that these transformations are applied even if you specified a position or read the data from a file!

In addition to these transformations, it is also possible to attach a point of the cloth to a position. The syntax for this is: attach { u, v, where [, speed] } where u and v are the cloth coordinates (if you used the position keyword, u goes from 0 at orig to 1 at orig+dir1 and v goes from 0 at orig to 1 at orig+dir2), and where is a vector specifying the position to which the point should be attached (if you want good results, it should be reasonably near to the position the point would naturally have at the beginning). The speed parameter is a facultative vector that specifies how the point should move during the simulation. Note that any translation or rotation applied after the point is attached will affect the position where it is attached (this is also true if the cloth position is loaded from a file after the point is attached. That way you can give the point a speed and have it properly placed from one animation frame to the next).

Adding objects for the cloth to interact with.

After the cloth definition, you can add any number of cylinders, boxes, spheres and ground planes (although of course having several ground planes doesn't make lot of sense and will only serve to slow down the program). The syntax is similar to that of POVray, except that an additional parameter can be added after the others to specify how smooth the surface of the object is (the higher the parameter, the more friction there will be whe the cloth touches it).

It is also possible to specify a height field object. As in POVray the object will fill a cube from <0, 0, 0> to <1, 1, 1>. The syntax is: height_field { tga "filename" TRANSFORMS } . The available transformations are scale and translate. Unfortunately, this object doesn't work right yet :-(

Specifying vectors.

As in POVray, you can specify a vector either by giving its coordinates between angled brackets (eg: <1,2,3>) or as an expression featuring the constants x, y and z, floating point numbers and vectors in brackets. However you cannot specify a number and have it expand automatically (eg: giving 1.0 where a vector is expected will give a parse error). Moreover the axis system for the input file is not the same as in POV: y and z are inverted (z is up and y points into the screen). But the output follows the POVray conventions and is therefore directly usable in POV.

Command line options.

Type cloth --help for help on how to use the program (if you don't specify input and output files, standard input and output are used):

flash:~/prog/cloth> ./cloth --help
cloth 0.2.0
Usage: cloth [OPTIONS]...
   -h         --help               Print help and exit
   -V         --version            Print version and exit
   -iSTRING   --in-file=STRING     Input file
   -oSTRING   --out-file=STRING    Output file
   -sINT      --steps=INT          Number of simulation steps
   -rSTRING   --raw-output=STRING  Output raw data to file


Compteur de visites : counter

HTML 4.01 Transitional validé CSS validé
Dernière mise à jour le samedi 27 janvier 2007 à 7 h 45