In my attempt to assign a map to every object loaded with OBJLoader in an obj file, I encountered a problem. When trying to assign a different map to only one object from the file while keeping the rest with the previous map, the map changes for every object.
function loadOBJ( geometry, name ) {
loader.load( geometry, function( object ){
object.traverse( function (child) {
if ( child instanceof THREE.Mesh ) {
child.material.map = map;
child.material.envMap = textureCube;
child.castShadow = true;
child.receiveShadow = true;
child.material.needsUpdate = true;
}
});
object.children[0].material.map = new THREE.TextureLoader().load("img/ground.jpg");
object.name = name;
scene.add( object );
console.log(object.name);
});
}
Even when I run a traverse only for object.children[0] and assign the map there, the result remains the same. What could I be doing wrong?