A clothing problem~!

Started by Mizuki Takase, December 12, 2006, 10:45:02 PM

Previous topic - Next topic

Mizuki Takase

I have been constantly deleting my own thread about this topic simply because I am not completely proud or happy with what I have done... Because I wanted clothing simulation sooooo badly~ I did some googling and yahooing for such, and encountered a C++ source for clothing simulation... I decided to try translating the code from C++ to JPCT, and I did sort of got it to work... My problem is that the rested cloth looks like this...




I know that cannot possibly be correct because I did not apply any forces onto the cloth yet... Since I can not find out how to contact the original author, I decided to try to tackle the problem myself, but as usual, failed... Here is the complete source and a texture for my project!
*editted: I took the file down for now!*

Anyway, I suspect that the problem has something to do with the way the SpringConstraints are set up; SpringConstraints hold data on how far particles along a plane can stretch...

   int off = 0;
   for(int i = 0; i < numParticles; i++){
     if(i % (gridx) < gridx-1 && i < numParticles-gridx || i == 0){
       //System.out.println("i: "+i+" 1");
       constraints[off++] = new SpringConstraint(particles[i],particles[i+1],spacing,stff);
       constraints[off++] = new SpringConstraint(particles[i],particles[i+gridx],spacing,stff);
       constraints[off++] = new SpringConstraint(particles[i],particles[i+gridx+1],spacing*rt2,diagstff);
       if(i % gridx > 0){
         //System.out.println("i: "+i+" 1a");
         constraints[off++] =  new SpringConstraint(particles[i],particles[i+gridx-1],spacing*rt2,diagstff);
       }
     }else if ((i % (gridx) == gridx-1) && (i < (gridx*gridy-(gridx)))){
       //System.out.println("i: "+i+" 2");
       constraints[off++] = new SpringConstraint(particles[i],particles[i+gridx],spacing,stff);
       constraints[off++] = new SpringConstraint(particles[i],particles[i+gridx-1],spacing*rt2,diagstff);
     }else if (i > numParticles-2){
       //System.out.println("i: "+i+" 3");
     }else{
       //System.out.println("i: "+i+" 4");
       constraints[off++] = new SpringConstraint(particles[i],particles[i+1],spacing,stff);
     }
   }


To Egon: this code is updated from the last time I sent it to you...

To everyone: you can use your mouse to click and drag some vertices/particles around... Since I pretty much used Egon's code, "w" is wireframe mode and "x" is hardware render mode... You cannot play with the vertices on hardware render mode...

If there is anyone knowledgeable on such a subject, I would love to be your friend, since my game programming background is pretty much non-existent...

Mizuki Takase

Imagine a plane that is created by Primitives.getPlane(9,1). The wireframe of the plane looks like a bunch of vertices in a grid-like shape. How can I get GenericVertexController.getSourceMesh() to give me the vertices in a row-column fashion?

cyberkilla

This looks interesting.

I cant really give any advice because I have no idea how it works right now:)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

EgonOlsen

Quote from: "Mizuki Takase"Imagine a plane that is created by Primitives.getPlane(9,1). The wireframe of the plane looks like a bunch of vertices in a grid-like shape. How can I get GenericVertexController.getSourceMesh() to give me the vertices in a row-column fashion?
You can't. You have to sort them yourself, i.e. build an index list that translates the row-column-stuff into the actual indices (only once and use the sorted index list from there on).

Mizuki Takase

Okay then, I am a little confused! When you did your introduction to VertexControllers, you posted some code there...
http://www.jpct.net/forum/viewtopic.php?t=58&highlight=sin

When I first saw that, I thought to myself that the getSourceMesh() had to have given you the vertices in some sorted order otherwise you would have gotten random vertices going up or down...

EgonOlsen

Quote from: "Mizuki Takase"When I first saw that, I thought to myself that the getSourceMesh() had to have given you the vertices in some sorted order otherwise you would have gotten random vertices going up or down...
No, it works, because it takes the x-coordinate of the vertices to calculate the sin from that. Order doesn't matter here.

Mizuki Takase

THANK YOU EGON!!! The problem is that I made a bad assumption that the getSourceMesh() would have given the SimpleVectors in some sort of order... Anyway! I just need to do self collision onto the cloth and also make the cloth deform in all three coordinates, and it will then be perfect~! I wonder how I can extend the cloth simulation to work on actual meshes of shirts and dresses. There is not a lot of documentation on that topic. Atleast grid shaped pieces of cloth works~! I really hope to contribute this some year...

EgonOlsen

Not some...NEXT year!  :wink:

EgonOlsen

Are you still here? The code you gave me (at least the code that i was able to find) was from September 06. Do you have an updated version of it? I would like to have a look at it to see if i can use it to simulate turning book pages with it...

cyberkilla

Perhaps an email would be faster. I will try to contact.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Mizuki Takase

^_^ I emailed you the running example to "hostmaster" email. Please do ask me for anything or everything about the code~!

EgonOlsen

Looks very cool and pretty...clothy. However, that's a little problem, because i would like to behave it more like paper. Is there any way (some value to play around with) to make it behave less wobbly?

Mizuki Takase

Very yes! At the ClothController.java's constructor, you can find silly things like stff, which is the stiffness of the cloth. mass and gravity also helps too! The biggest problem with Cloth simulation is that cloth can be easily unstable. Big numbers tend to make the cloth react very messy!

cyberkilla

I hope there will be screenshots of this creation :D
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

EgonOlsen

#14
After playing around with it a little bit, i think that cloth simulation is not really feasible for simulating paper. Something much simpler may do the job, but i'm too lazy to do it ATM...