5

Blog Entry #13

posted in Papervision3D

Papervision3D Collada to WOWPolygon

mixed logo wowpoly and papervision
Last week I was looking for 3d physics engine that works with papervision collada files.
I didnt know what to do. It was the first time I've ever used physics
I decide to use WOWEngine.

First I Made WSphere and WPlane collide. Then I rendered them as Pv3D SPhere and Pv3D Plane following this tutorial. I felt happy and almighty !

For my next trick, I wanted to make a complex ground using collada file. I searched the interwebs, found the right class to use : WOWPolygon , but not really of use of Papervision3D.
After a day of try , I finally got a result.
Here is the swf in actionusing wow poly

This is a way to create WOWPolygon from Papervision3D DisplayObject3D :

Thanx to Daniele from Milan for his/her update.

  1.  
  2. //Retrieving the "ground" of the collada, it's called "pPlane1" in my .dae source;
  3.       var ground:DisplayObject3D = Levels.getChildByName("pPlane1" , true);
  4.       ground.material.doubleSided = true;
  5.      
  6.       //For each face of the ground;
  7.       for (var i:int = 0; i < ground.geometry.faces.length; i++)
  8.       {
  9.         //store the currentface as Triangle3D;
  10.         var tri:Triangle3D = ground.geometry.faces[i];
  11.         var VertArray:Array = new Array();
  12.        
  13.         //for each vertice of the face;
  14.         for (var u:int = 0; u < tri.vertices.length; u++)
  15.         {
  16.           //Store the currentVertice;
  17.           var Vert:Vertex3D = tri.vertices[u];
  18.           //Convert it to a WOW Vertrex (invert axis);
  19.  
  20. /**********************
  21. * UPDATE FROM DANIELE
  22. **********************/        
  23. var n:Number3D = new Number3D(Vert.x,Vert.y,Vert.z);
  24. Matrix3D.multiplyVector4x4(tri.instance.transform,n);
  25. var VerticesNow:WVertex = new WVertex( -(ground.x + n.x) , -(ground.y + n.y) , -(ground.z + n.z));
  26.           //And push the WVertex to the VerticesArray;
  27.           VertArray.push(VerticesNow);
  28.          
  29.           //Three following lines are optionnally , just display a cube in each WVertice to show you the differents between Papervision and WOW axis;
  30.           var cub:Cube = new Cube(new MaterialsList( { all:new WireframeMaterial(0xff9900) } ) , 50, 50, 50);
  31.           cub.x = VerticesNow.x , cub.y = VerticesNow.y , cub.z = VerticesNow.z;
  32.           _rootNode.addChild(cub);
  33.          
  34.         }
  35.         //Now create a WOWPolygon with VertArray;
  36.         var Poly:WOWPolygon = new WOWPolygon(VertArray[2] , VertArray[1] , VertArray[0]);
  37.         //Property of a WOWParticle
  38.         Poly.fixed = true;
  39.         Poly.collidable = true;
  40.         Poly.elasticity = 0.5;
  41.         Poly.friction = 0.02;
  42.         //Add the Poly to the physical Engine;
  43.         wowEngine.addParticle(Poly);
  44.         //We can Add Collision Function if we need;
  45.         //Poly.activCollisionEvent(Bouncing);
  46.        
  47.       }
  48.  

source code here
full source zip here

4 comments about this entry

1

posted by : Daniele
from : Milan
January 9, 2009, 11:42 am
website :

Very Usefull example... but I have a problem... usign your code as is it doesn't take care about scala or trasformation... I tried to add:

  1.  
  2.  tri.instance.geometry.transformVertices(tri.instance.transform);
  3.  

al line 12... but have a problem with rotation... I think! Any suggestion?

2

posted by : Daniele
from : Milan
January 9, 2009, 1:20 pm
website :

I solved in this way... tell me if you think is correct: After line 17 insert this:

  1.  
  2. var n:Number3D = new Number3D(Vert.x,Vert.y,Vert.z);
  3. Matrix3D.multiplyVector4x4(tri.instance.transform,n);
  4.  

and replace line 19 with this:

  1.  
  2. var n:Number3D = new Number3D(Vert.x,Vert.y,Vert.z);
  3. Matrix3D.multiplyVector4x4(tri.instance.transform,n);
  4.  

Daniele

3

posted by : Thomas
from : Brussels
January 10, 2009, 12:36 am
website : http://badou.biz/blog/

@Daniele Thanx for your support about transformations, I did not think about it. The line 19 will be this

  1.  
  2. var VerticesNow:WVertex = new WVertex( -(ground.x + n.x) , -(ground.y + n.y) , -(ground.z + n.z));
  3.  

isnt it ?

4

posted by : Seraf
from : fRANCE
September 9, 2009, 9:57 am
website : seraf.mediabox.fr

nice !

Write a comment

edit




Insert :


Search Engine

Search blog entries


Search

Recommended Feed

keep your mind opened ...