Unable to load texture with obj file

Hello Everyone
I am trying to upload texture with obj file but it showing this error

THREE.Object3D.add: object not an instance of THREE.Object3D.

here is my code

	  var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath('new/obj/');
mtlLoader.load('coat_.mtl', function(materials) {
  materials.preload();
  var objLoader = new THREE.OBJLoader2();
  objLoader.setMaterials(materials);
  objLoader.setPath('new/obj/');
  objLoader.load('coat_.obj', function(object) {
    //object.position.y = -95;
    scene.add(object);
  });
});

Can you please use THREE.OBJLoader and not THREE.OBJLoader2? Otherwise you have to write your code like in this example:

https://threejs.org/examples/#webgl_loader_obj2

Notice that both loaders have a slightly different API.

1 Like