I am following this tutorial on how to load Maya models with Three.js.
Everything is fine, but tutorial only explains how to load models with one texture.
He
it appears the tutorial your following is ignoring the materials from the JSON model format and simply passing the geometry and a straight text reference to a single texture file like so:
var loader = new THREE.JSONLoader(),
callbackKey = function(geometry) {createScene(geometry, 0, 0, 0, 15, "chameleon.jpg")};
loader.load("chameleon.js", callbackKey);
The JSONLoader not only pulls in the geometry but all the materials in an array. (see: https://github.com/mrdoob/three.js/blob/master/src/loaders/JSONLoader.js line 45) You can then pass this array to the MeshFaceMaterial(arrayOfMaterials) like so:
var loader = new THREE.JSONLoader();,
callbackKey = function(geometry, materials) {createScene(geometry, materials, 0, 0, 0, 15, )};
loader.load("chameleon.js", callbackKey);
Then in your createScene function you change the first line to be:
zmesh = new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials));
Edit: Adding details on fixing Maya exports
So your model is loading but black. In this case the issue is in the model file chameleon.js
. Have a look at each material's colorAmbient
and colorDiffuse
property. Notice they're all [0.0, 0.0, 0.0]. This is a known obj export bug in Maya. So you have 3 options to fix it.
1) Open the chameleon.js
file and alter all the colorAmbient
and colorDiffuse
lines to something like this (you'll need to play with the values to make it look right)
"colorAmbient" : [0.8, 0.8, 0.8],
"colorDiffuse" : [0.8, 0.8, 0.8],
OR
2) In Maya before applying your diffuse map, always make sure to apply a default color value first. For some reason once the map is on you can no longer access the color property and the exporter uses the default value of 0.
OR
3) After exporting from Maya you can alter the OBJ file by change these lines from:
Kd 0.00 0.00 0.00
To
Kd 0.80 0.80 0.80
I've tested this here at home and your model is looking good, let me know how it goes?