0
votes

I am working on implementing a website that the users cloud be upload their 3d models. And they see it. When i am uploading obj-mtl-texture the force me to use blob url. I have the all textures blob urls one bye one but i dont have parent url. I want load textures to mtl loader how can i do it without setTexturePath() func.

I am trying the export obj model to gltf from three.js.

mtlLoader.setTexturePath(URL.createObjectURL(textureFolder));
    mtlLoader.load(URL.createObjectURL(mtlFile), (materials) => {
      materials.preload();
      objLoader.setMaterials(materials);
      objLoader.load(URL.createObjectURL(objFile),
        // called when resource is loaded
        (object) => {
          scene.add(object);
          exporter.parse(scene, (gltf) => {
            console.log(gltf);
            gltfFile = gltf2file(gltf, file.name);
            resolve(gltfFile);
          });
        },
        // called when loading is in progresses
        (xhr) => {
          console.log(`${(xhr.loaded / xhr.total) * 100}% loaded`);
        },
        // called when loading has errors
        (error) => {
          console.log(error);
          reject(new Error('Error occurred when converting file to gltf'));
        });
    },
    // called when loading is in progresses
    (xhr) => {
      console.log(`${(xhr.loaded / xhr.total) * 100}% loaded`);
    },
    // called when loading has errors
    (error) => {
      console.log('mtl error');
      console.log(error);
      reject(new Error('Error occurred when converting file to gltf'));
    });
  });

Is there anyone can show me the way loading textures one bye one without using setTexturePath()

thanks in advence

1

1 Answers

1
votes

I solved the problem with setting custom loadingManager for MTLLoader

Example code here

const loadingManagerMTL = new THREE.LoadingManager();
  loadingManagerMTL.setURLModifier((url) => {
    let newUrl;
    for (let i = 0; i < textureFolder.files.length; i++) {
      if (url === textureFolder.files[i].name) {
        newUrl = URL.createObjectURL(textureFolder.files[i]);
      }
    }
    return newUrl;
  });

  const mtlLoader = new MTLLoader(loadingManagerMTL);

Now you can customize your loading manager as you wish...

You can use loading manager for another loaders to like OBJLoader