Author Topic: A clothing problem~!  (Read 11985 times)

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
A clothing problem~!
« 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...




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...

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
A clothing problem~!
« Reply #1 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?

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
A clothing problem~!
« Reply #2 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:)
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
A clothing problem~!
« Reply #3 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).

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
A clothing problem~!
« Reply #4 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
A clothing problem~!
« Reply #5 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.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
A clothing problem~!
« Reply #6 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
A clothing problem~!
« Reply #7 on: December 23, 2006, 01:58:40 pm »
Not some...NEXT year!  :wink:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A clothing problem~!
« Reply #8 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...

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Re: A clothing problem~!
« Reply #9 on: July 17, 2007, 09:54:37 pm »
Perhaps an email would be faster. I will try to contact.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Re: A clothing problem~!
« Reply #10 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~!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A clothing problem~!
« Reply #11 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?

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Re: A clothing problem~!
« Reply #12 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!

Offline cyberkilla

  • float
  • ****
  • Posts: 413
    • View Profile
    • http://futurerp.net
Re: A clothing problem~!
« Reply #13 on: July 19, 2007, 04:45:28 pm »
I hope there will be screenshots of this creation :D
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A clothing problem~!
« Reply #14 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...
« Last Edit: July 25, 2007, 09:40:03 pm by EgonOlsen »