After loading a material using MTLLoader and applying it to my model loaded with OBJLoader, the model itself mysteriously disappears.
MTLLoader.setPath( 'models/' );
var url = "model.mtl";
MTLLoader.load( url, function( materials ) {
materials.preload();
OBJLoader.setPath( 'models/' );
OBJLoader.load( 'model.obj', function ( object ) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.material = materials ; // this is causing the issue
}
scene.add( object );
});
});
I am aware that the recommended way to set materials with MTLLoader is by using
OBJLoader.setMaterials(materials)
, but I prefer the method I've implemented above. However, for some reason, the object disappears without any errors when done this way. Can anyone shed light on why this might be happening?