I have the files .mtl
, .obj
, and several .jpg
textures. I have been attempting to use different textures in the export loader OBJ, and while I can see my object on the scene, it appears as a black
color. Can anyone spot what might be incorrect or missing in my code?
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath('models/LivingRoom/Sample/');
mtlLoader.load( 'small plant.mtl', function( materials ) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('models/LivingRoom/Sample/');
objLoader.load( 'small plant.obj', function ( object ) {
var geometry = object.children[ 0 ].geometry;
var materials = [];
var mat1 = new THREE.MeshLambertMaterial( { map : THREE.ImageUtils.loadTexture('models/LivingRoom/Sample/Listik-2.jpg')});
var mat2 = new THREE.MeshLambertMaterial({ map : THREE.ImageUtils.loadTexture('models/LivingRoom/Sample/22_zemlya_oboi_1920x1080.jpg')});
materials.push(mat1);
materials.push(mat2);
mesh = THREE.SceneUtils.createMultiMaterialObject(geometry, materials);
mesh = THREE.SceneUtils.createMultiMaterialObject(geometry, threeDTexture);
object.traverse(function (child) {
if (child instanceof THREE.Mesh) {
child.materials = materials;
}
});
},
function ( xhr ) {
returnValue = ( xhr.loaded / xhr.total * 100 ) + '% loaded';
console.log(returnValue);
},
function ( error ) {
console.log( 'An error happened' );
}
);
});