if ( res.type == 'obj/mtl' ) { var mtlLoader = new THREE.MTLLoader(); var objLoader = new THREE.OBJLoader(); //load the mtl var rsn = resnames var idx = i //This returns a function to upload each resource var functor = function ( idx, name ) { return function ( materials ) { materials.preload(); materials.side = THREE.DoubleSide; //Set the material to the object loader of the object objLoader.setMaterials( materials ); //Save the materials in the storage object __T.resourceStorage[ resnames[ idx ] ].materials = materials; //Folder path objLoader.setPath( __T.resourcePath ); objLoader.load( name + '.obj', function ( object ) { //There are problems sometimes when prototype is group and not object 3d var tmp = new THREE.Object3D() object.__proto__ = tmp.__proto__; //Only needed if you need textures on both sides if ( object instanceof THREE.Object3D ) { object.traverse( function ( mesh ) { if ( !( mesh instanceof THREE.Mesh ) ) return; console.log( mesh.material ); mesh.material.side = THREE.DoubleSide; } ); } __T.resourceStorage[ rsn[ idx ] ].object = object; __T.resourceStorage[ rsn[ idx ] ].loaded = true; //Calls a function that manages when all resources are loaded every resource calls it. checkResources(); } ); } } mtlLoader.load( __T.resourcePath + name + '.mtl', functor( idx, name ) ); }