1
votes

I have downloaded a free model from turbosquid. It contains an obj and mtl, and textures (specular, bump map, etc...). For now I am just interested about the mtl and obj file. So I downloaded a free model from here (it's a car). Then I loaded the model using this code:

var loader= new THREE.OBJMTLLoader();
loader.load("./L200-Obj/L200-Obj.obj","./L200-Obj/L200-Obj.mtl",function(object) {
    scene.add(object);
}

I already checked the paths and they're ok (I tried to log object, it's an alive and valid object). Now the problem is that I see a black screen, and the reason is that the mtl file is somehow "not considered". If I try to add the material:

object.traverse(function(child) {
    child.material= someMaterial;
});

Then I see the car with the material that I've set, and the shape of the car is fine. I also tried to load the textures:

var map= THREE.ImageUtils.loadTexture("./L200-Obj/truck_color-silver.jpg");
var bumpMap= THREE.ImageUtils.loadTexture("./L200-Obj/truck_bump.jpg");
var specularMap= THREE.ImageUtils.loadTexture("./L200-Obj/truck_spec.jpg");
var material= new THREE.MeshPhongMaterial({
    map: map,
    specularMap: specularMap,
    bumpMap: bumpMap
});
// Set it as material with the above code

And they're fine, the car looks ok, but the question is: shouldn't the obj and mtl files be enough to display the car with it's colors? Shouldn't I see the car with it's colors even if I don't set the material? Am I doing something wrong?

1
The car model you linked to is described as using Quads...which I thought are not handled by THREE.js?steveOw

1 Answers

2
votes

Take a look at the mtl file in notepad. The names of the image files is listed. Maybe when you created the mtl file, the pathway to its location(s) at that time is still in the mtl file. If so, and your mtl is in the same folder as the obj, just rename the files in the mtl as if they were in the same folder as the obj... ie don't need the pathway. You can edit the file names in wordpad.