mrdoob/three.js — Issue #1066: Error exporting normals from .mtl file
Author: canassa
Created: 2012-01-10 18:10:58+00:00
State: open

This is a 2 in 1 issue.

I have a .mtl and .obj file exported from 3D Studio Max, the .mtl has the following line that specifies the normal map:

map_bump -bm 1.5000 corpo_nrm.jpg

First, the obj_to_three.py ignored the normals, after a little digging I found culprit:

if (chunks[0] == "map_bump" or chunks[0] == "bump") and len(chunks) == 2:

As you can see, the .mtl from Max has a "-bm 1.5000" parameters which increases the chunk size to 4 so the above if is never true.

I fixed my exporter, it generated a json model with this material:

"materials": [	{
"DbgColor" : 15658734,
"DbgIndex" : 0,
"DbgName" : "clothes",
"colorAmbient" : [0.3725, 0.3725, 0.3725],
"colorDiffuse" : [0.3725, 0.3725, 0.3725],
"colorSpecular" : [0.049399999999999999, 0.054100000000000002, 0.054100000000000002],
"illumination" : 2,
"mapAmbient" : "corpo_dif.jpg",
"mapBump" : "corpo_nrm.jpg",
"mapDiffuse" : "corpo_dif.jpg",
"opticalDensity" : 1.5,
"specularCoef" : 19.0,
"transparency" : 0.0
},

This let to another problem, the normal texture was set as "mapBump", but the Three loader looks for "mapNormal":

if ( m.mapNormal && texture_path ) {
create_texture( mpars, "normalMap", m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap );
}

I changed "mapBump" to "mapNormal" and everything worked.