Last active
February 3, 2017 15:24
-
-
Save jcliberatol/e1bc852dec78061d20de013c654ba34e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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