Papervision3D – Max3DS Parser bug

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

Tags: , , , , ,

4 Responses to “Papervision3D – Max3DS Parser bug”

  1. Chris says:

    Thanks a lot for this!

  2. Delcasda says:

    It is working for me.

    Many thanks!!

  3. Thanks, but i had problem with textures.

    When you flip the model the textures have same coordinates
    I tried to flip bitmap before apply it on to a material but with no result.
    could you help please :-/

  4. Marek says:

    When I use your method I can see rectangles on my model, as if I haven’t smoothend my model with use of smoothing groups in 3ds max.

Leave a Reply