Posts Tagged ‘demo’

Papervision3D – Max3DS Parser bug

Friday, March 27th, 2009

Since papervision added the Max3DS parser I’ve been working with it instead of DAE. Although there’s a bug that I noticed when I imported an asymmetric model to my scene. It appear to be mirrored at the X axis. I was in a rush so I took the easy way, and flipped my model before export the 3ds file.

After that I tried to chage the 3ds parser to import the file correctly but it was taking me much more time than I had, so I wrote this method to fix the mesh after parsing.

Here is my scene in 3D Max

objects

Note that the box is behind the teapot and the cylinder is in front of it.

Here is a picture of the PPV scene when I import them usign Max3DS parser.

objects_fliped

And here it is after running my script

objects_normalized

I didn’t test it for complex models, but this will work just fine in 90% of the cases.

Here is the script:

normalize(object3ds);
 
function normalize(max3ds:Max3DS):void{
	max3ds.rotationX = 0;
	max3ds.rotationY = 0;
	max3ds.rotationZ = 0;
 
	for each(var mesh:DisplayObject3D in max3ds.children){
		mesh.scaleZ *= -1;
		mesh.rotationX *= -1;
		mesh.rotationY *= -1;
		mesh.rotationZ *= -1;
 
		var m:Matrix3D =  new Matrix3D();
		m.calculateMultiply(m, Matrix3D.rotationX(mesh.rotationX*Math.PI/180));
		m.calculateMultiply(m, Matrix3D.rotationY(mesh.rotationY*Math.PI/180));
		m.calculateMultiply(m, Matrix3D.rotationZ(mesh.rotationZ*Math.PI/180));
 
		m.calculateMultiply(m, Matrix3D.scaleMatrix(mesh.scaleX, mesh.scaleY, mesh.scaleZ));
 
		for(var i:Number = 0; i<mesh.geometry.vertices.length; i++){
			var vertex:* = mesh.geometry.vertices[i];
 
			var vx :Number = vertex.x;
			var vy :Number = vertex.y;
			var vz :Number = vertex.z;
 
			var tx :Number = vx * m.n11 + vy * m.n12 + vz * m.n13 + m.n14;
			var ty :Number = vx * m.n21 + vy * m.n22 + vz * m.n23 + m.n24;
			var tz :Number = vx * m.n31 + vy * m.n32 + vz * m.n33 + m.n34;
 
			vertex.x = tx;
			vertex.y = ty;
			vertex.z = tz;
		}
 
 
		mesh.rotationX = 0;
		mesh.rotationY = 0;
		mesh.rotationZ = 0;
		mesh.scaleZ *= -1;
 
		mesh.geometry.flipFaces();
	}
}

Demo
Source

PaperPlane Test

Tuesday, March 24th, 2009

Early experiments of nothing that could become something.

Use the arrows to control the plane
Speed up pressing space

Demo

plane

Source