Hi I am new to three.js. For some reason when I add a new model in .obj and .mtl into my three.js code, the color will become white, despite whatever the original color or texture is. The following is a snippet of the code responsible for the pig model:
// pigmodel
var objLoader = new OBJLoader();
var mtlLoader = new MTLLoader();
function loadpigmodel( x, y, z, ang, scale ) {mtlLoader.setPath( './images/' ); mtlLoader.load( 'Pig1.mtl', function ( loadedMesh ) { objLoader.setMaterials( loadedMesh ); objLoader.load( './images/Pig1.obj', function ( object ) { switch ( scale ) { case 'big': object.scale.set( 100, 100, 100 ); break; case 'small': object.scale.set( 90, 90, 90 ); break; default: }
The code above simulates a pigsty with some compost boxes. As you can see, the pig displayed in the code is white, even though it should be pink. The fence should also have wooden texture, but instead, it is also white.
The two .mtl file looks like this:
newmtl Pig1
Ka 0.000000 0.000000 0.000000
Kd 0.505882 0.396078 0.356863
Ks 0.330000 0.330000 0.330000
map_Kd pigskin.jpg
and this:
newmtl Material
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.161519 0.069714 0.038927
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2newmtl Material.003
Ns 96.078431
Ka 1.000000 1.000000 1.000000
Kd 0.549348 0.285120 0.296990
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.000000
d 1.000000
illum 2
Both of them doesn’t seem to work. We suspect that there is something wrong with the mtl files overlapping and leads to the malfunction. This is the full code The full code and the mtl files are included in this hyperlink.