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.

Revisions

  1. jcliberatol revised this gist Feb 3, 2017. 1 changed file with 38 additions and 38 deletions.
    76 changes: 38 additions & 38 deletions mtl_obj_load_sample.js
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,44 @@
    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 );
    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 ) {
    //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__;
    //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;
    } );
    }
    //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();
    __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 ) );
    }
    mtlLoader.load( __T.resourcePath + name + '.mtl', functor( idx, name ) );
    }
  2. jcliberatol created this gist Feb 3, 2017.
    44 changes: 44 additions & 0 deletions mtl_obj_load_sample.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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 ) );
    }