From 129fddfd57302fecc483c2d372a76ae30c67c3db Mon Sep 17 00:00:00 2001 From: alteredq Date: Sun, 6 Mar 2011 22:56:36 +0100 Subject: [PATCH] Fixed flipped normals workaround in max exporter. Hope so. At least now hacked face normals correspond to face normals computed from scratch in Geometry. (If only max didn't have zillion ways how to achieve the same visual results :/. I tracked this flipped normals/faces business down to XForm modifier - it doesn't get collapsed properly when making TriMesh / Editable_mesh snapshots. At least Editable_mesh snapshot differs in way that is exploitable for workaround hack.) --- utils/exporters/max/ThreeJSExporter.ms | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/utils/exporters/max/ThreeJSExporter.ms b/utils/exporters/max/ThreeJSExporter.ms index 6b879712..e8678760 100644 --- a/utils/exporters/max/ThreeJSExporter.ms +++ b/utils/exporters/max/ThreeJSExporter.ms @@ -309,8 +309,6 @@ rollout ThreeJSExporter "ThreeJSExporter" hasUVs = true - if exportNormal.checked and exportUv.checked and hasUVs then - triangles = #() trianglesUvs = #() trianglesNormals = #() @@ -479,7 +477,7 @@ rollout ThreeJSExporter "ThreeJSExporter" ------------------------------------------------------------------------------------- -- Extract normals from mesh - function ExtractNormals obj whereto = + function ExtractNormals obj whereto needsFlip = ( if smoothNormal.checked then ( @@ -490,6 +488,14 @@ rollout ThreeJSExporter "ThreeJSExporter" ( n = GetNormal obj i + + if needsFlip then + ( + n.x *= -1 + n.y *= -1 + n.z *= -1 + ) + append whereto n ) @@ -504,6 +510,14 @@ rollout ThreeJSExporter "ThreeJSExporter" ( n = GetFaceNormal obj i + + if needsFlip then + ( + n.x *= -1 + n.y *= -1 + n.z *= -1 + ) + append whereto n ) @@ -724,7 +738,7 @@ rollout ThreeJSExporter "ThreeJSExporter" ExtractMaterials meshObj meshMaterial mergedMaterials ExtractVertices meshObj mergedVertices - ExtractNormals meshObj mergedNormals + ExtractNormals meshObj mergedNormals needsFlip ExtractUvs meshObj mergedUvs --ExtractFaces meshObj zmaterial mergedFaces mergedVertices.count mergedUvs.count