WOW & Papervision3D cloth physics effects.

Cloth Demo

Well after some time of seeing many examples available across the web, I finally decided to see how hard it would be to simulate cloth dynamics in 3D in actionscript and have to say with the help of Papervision3d and the WOW physics library that it was actually incredibally easy! I have never tackled WOW but have seen a few examples of what it is capable of, but as it is based on Alex Coves APE library which I have used a fair bit and as with APE, WOW is also very easy to implement.
The whole process of creating the cloth is very simple and I will run through this now for you.

Firstly the papervision world is created and this is made even simpler with the already created BasicView which my document class extends. With in this we add a Plane, which is basically a grid of triangles with a vertex at each cross point.

We then target the vertex geometry of the plane itself by creating an array and assigning each vertex to this array.

Actionscript:
  1. pVerts = rug.geometry.vertices;

Then the WOWEngine is added to the scene, which will handle all of the physics mathematics. To this we add gravity (addMasslessForce) and an array of WOW particles with which we create a grid of particles to mirror the grid structure of the plane itself.

Actionscript:
  1. private function initWOW():void
  2.         {
  3.             wowEngine = new WOWEngine(.3);
  4.             wowEngine.addMasslessForce(new WVector(0, 30, 0));
  5.             wowVerts = new Array();
  6.  
  7.             for(i = 0; i<pVerts.length; i++)
  8.             {
  9.                 var wp:WParticle = new WParticle(pVerts[i].x, -pVerts[i].y, pVerts[i].z, false, 10);
  10.                 wp.elasticity = 0;
  11.                 wp.friction = 0;
  12.                 wowEngine.addParticle(wp);
  13.                 wowVerts.push(wp);
  14.             }
  15.         }

During the ENTER_FRAME loop function which handles the rendering for the papervision scene, we also update the WOW world with the following function:

Actionscript:
  1. wowEngine.step();

and update the geometry of the cloth based on the position of the constrained WOW particles like so:

Actionscript:
  1. for(i = 0; i <pVerts.length; i++)
  2.             {
  3.                 pVerts[i].x = wowVerts[i].px;
  4.                 pVerts[i].y = -wowVerts[i].py;
  5.                 pVerts[i].z = wowVerts[i].pz;
  6.             }

All this added to some simple functionality to make the cloth clickable and draggable makes a pretty effective cloth demo thats darn fun to play with.

Check out the source here.

and the demo here.

You can leave a response, or trackback from your own site.

4 Responses to “WOW & Papervision3D cloth physics effects.”

  1. [...] effects. VA:F [1.1.7_509]please wait…Rating: 0.0/5 (0 votes cast) This article was found on . Click here to visit the full article on the original website.Well after some time of seeing many examples available across then web, I finally decided to see [...]

  2. JamesD says:

    Thanks for the useful info. It’s so interesting

  3. [...] findest du hier was:WOW & Papervision3D cloth physics effects. | UltraVisual Blog zuhause hab ich aber auch noch was, wenn dir das nicht reicht __________________ hang loose [ [...]

  4. John says:

    Hi!
    This is great, I’m trying to use it as a starting point in one of my projects. How did you calculate the position of the wowVerts that holds the cloth? I would like to add some more and having some problems figuring out this logic.
    I would really appreciate it if you could replay by mail.
    Thanks!

Leave a Reply

Powered by WordPress | AT&T Cell Phones for Sale at iFreeCellPhones.com | Thanks to PalmPreBlog.com, MMORPGs and Online Shopping