Papervision3D – Max3DS Parser bug

Desde que o papervision adicionou o Max3DS parser, eu venho usando ele invés de trabalhar com DAE. Entretanto existe um bug que eu notei quando importei um modelo assimétrico na minha cena. Ele estava espelhado no eixo X. Como estava correndo eu tomei o cmainho mais fácil, espelhei meu modelo antes de exportar o arquivo 3ds.

Depois disso eu tentei mudar o parser para importar o arquivo corretamente mas estava me tomando mais tempo do que eu tinha, então escrevi esse método para concertar o mesh depois do parsionamento.

Aqui está minha cena no 3D Max

objects

Note que o cubo está atrás da chaleira e o cilindro na frente dela.

Aqui está uma imagem da cena no PPV quando eu importo eles usando o Max3DS

objects_fliped

Depois de rodar meu script

objects_normalized

Eu não testei ele para modelos mais complexos, mas ele vai funcionar em 90% dos casos.

Aqui está o 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