Load .obj file and dependencies in three js

I have a zip that I fetch server side - from there I return a list of urls to the client. This list of file path contains an obj file, the textures, and material files. Is it possible to load these separately i to three js? I see a setPath method on the obj and mtl loaders but these files wont be in a directory so relative pathing won’t work.

1 answer

  • answered 2018-04-14 15:55 Don McCurdy

    Consider using a LoadingManager to adjust the paths as needed:

    var manager = new THREE.LoadingManager();
    manager.setURLModifier((url) => {
      return url.replace('/foo/', '/bar/');
    });
    var loader = new THREE.OBJLoader(manager);
    loader.load( ... );
    

    three.js r91