takahirox / THREE.ZipLoader

Zip archived model file Loading helper for Three.js
MIT License
14 stars 7 forks source link

Zip Loader not OBJ loading? #4

Open Thundros opened 4 years ago

Thundros commented 4 years ago

Hi @takahirox ! So I'm trying to load a 3d model & mtl file located inside of a zip file. The zip loading works fine. but when I do this

var manager = new THREE.LoadingManager ( );

var url = 'res/game/assets/models/OBJ/female/female.zip';

new Promise ( function( resolve, reject ) {

    if ( url.match( /\.zip$/ ) ) {

        new THREE.ZipLoader ( ).load ( url ).then ( function ( zip ) {

            manager.setURLModifier ( zip.urlResolver );

            resolve ( zip.find ( /\.(obj|mtl)$/i ) [ 0 ] );

        } );

    } else {

        resolve ( url );

    }

} ).then ( function ( file ) {

    new THREE.GLTFLoader ( manager ).load ( file, function ( gltf ) {

        var object = gltf.scene;

        object.traverse ( function ( obj ) {

            if ( obj.material && obj.material.isMeshStandardMaterial ) {

                obj.material.envMap = envMap;

            }

        } );

        scene.add ( object );

    } );

} ).then ( function ( file ) {

    new THREE.OBJLoader ( manager ).load ( file, function ( obj ) {

        var object = obj.scene;

        object.traverse ( function ( obj ) {

            if ( obj.material && obj.material.isMeshStandardMaterial ) {

                obj.material.envMap = envMap;

            }

        } );

        scene.add ( object );

    } );

} );

I get a whole bunch of warnings such as :

OBJLoader.js:706 THREE.OBJLoader: Unexpected line: "<script src="res/game/src/js/loaders/OBJLoader.js"></script>"

and I get 1 error :

TypeError: Cannot read property 'traverse' of undefined
    at main.js:190
    at Object.onLoad (OBJLoader.js:445)
    at XMLHttpRequest.<anonymous> (three.js:36863)

How can I fix this?

Thank You! <3

Thundros commented 4 years ago

@takahirox : Hello?