www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Mizuki Takase on December 12, 2006, 10:45:02 pm

Title: A clothing problem~!
Post by: Mizuki Takase on December 12, 2006, 10:45:02 pm
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...

(http://www.cs.uno.edu/~tvle/misc/clothproblem.png)


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...
Code: [Select]

    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...
Title: A clothing problem~!
Post by: Mizuki Takase on December 13, 2006, 06:53:55 pm
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?
Title: A clothing problem~!
Post by: cyberkilla on December 13, 2006, 07:19:17 pm
This looks interesting.

I cant really give any advice because I have no idea how it works right now:)
Title: A clothing problem~!
Post by: EgonOlsen on December 13, 2006, 10:25:36 pm
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).
Title: A clothing problem~!
Post by: Mizuki Takase on December 14, 2006, 06:07:44 am
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...
Title: A clothing problem~!
Post by: EgonOlsen on December 17, 2006, 12:33:57 am
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.
Title: A clothing problem~!
Post by: Mizuki Takase on December 22, 2006, 10:46:59 pm
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...
Title: A clothing problem~!
Post by: EgonOlsen on December 23, 2006, 01:58:40 pm
Not some...NEXT year!  :wink:
Title: Re: A clothing problem~!
Post by: EgonOlsen on July 17, 2007, 09:33:55 pm
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...
Title: Re: A clothing problem~!
Post by: cyberkilla on July 17, 2007, 09:54:37 pm
Perhaps an email would be faster. I will try to contact.
Title: Re: A clothing problem~!
Post by: Mizuki Takase on July 18, 2007, 10:49:26 pm
^_^ I emailed you the running example to "hostmaster" email. Please do ask me for anything or everything about the code~!
Title: Re: A clothing problem~!
Post by: EgonOlsen on July 18, 2007, 11:43:03 pm
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?
Title: Re: A clothing problem~!
Post by: Mizuki Takase on July 19, 2007, 06:01:37 am
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!
Title: Re: A clothing problem~!
Post by: cyberkilla on July 19, 2007, 04:45:28 pm
I hope there will be screenshots of this creation :D
Title: Re: A clothing problem~!
Post by: EgonOlsen on July 25, 2007, 09:02:36 pm
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...
Title: Re: A clothing problem~!
Post by: Mizuki Takase on July 25, 2007, 09:40:05 pm
To me, the part that kills a lot of frames per second is calculating the distance between a vertice and the object the cloth will collide. I wanted to see if I can calculate half of the vertices and then use that data to make an average for the vertices that I did not calculate for. Its just a dream though.