WOW & Papervision3D cloth physics effects.

April 28th, 2009

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.

Categories: Actionscript 3.0, Papervision, Physics | Tags: , | 4 Comments

Portfolio site finally published!!

April 7th, 2009


Well after trying to squeeze it in between other projects and work I have finally managed to complete my portfolio site. This is vital if I intend to pitch myself and my services to clients to try and ensure that I get future work. I still have a few things to add before I am 110% happy with it but it has everything that I want at the moment, so I thought as it is the parent site to this blog I thought I would share it with you. UltraVisual main site. I do intend to keep it as updated as possible so hopefully as I finish projects the site should continue to grow.

Categories: Background, News, UltraVisual | Tags: , | No Comments