Skip to content

Instantly share code, notes, and snippets.

@jcliberatol
Last active February 3, 2017 15:24
Show Gist options
  • Save jcliberatol/e1bc852dec78061d20de013c654ba34e to your computer and use it in GitHub Desktop.
Save jcliberatol/e1bc852dec78061d20de013c654ba34e to your computer and use it in GitHub Desktop.
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 ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment