OBJ questions and MTL files


#1

Trying to upload OBJ files, these generally come with .MTL files which carry the texture information, yet Hifi doesnt seem to recognize the mtl and there isnt anywhere to apply it.
It does work if you upload an OBJ and have the textures in a separate folder, but how do we work with commercially available OBJ files with their accompanying MTL?
Please anybody :smile:

Thanks


#2

When a .mtl file is referenced from an .obj, we merge the filename against the url of the .obj we are reading. So the short answer is to put the .mtl file and all the textures it references in the same folder as the .obj, and make sure your server serves them all.

The .obj “standard” doesn’t specify how other files (.mtl, .jpg, .png, etc.) are resolved. Lots of modeling systems have a “materials” library or search path, but of course, that’s not part of the .obj file. That’s why we do the above. By the way, it’s also not uncommon for some modeling systems to fail to define a .mtl library and material at all, and yet still expect that you pick up a texture of the same name as the .obj (but with .png or .jpg extension). So, in addition to the above, if the .obj specifies uv coordinates and yet does not specify a material, we will automatically look for -obj-filename-.jpg and -obj-filename.png in the same place.

Hope that helps!


#3

Thanks for the info.
Just to be sure, you say "put the .mtl file and all the textures it references in the same folder as the .obj"
So this means we always need the textures separate in all cases with obj?
They dont embed textures?


#4

The .obj file defines geometry, references materials, and provides the mapping of vertices to uv-coordinates on the material. The reference to a material consists of two parts in the .obj file: a reference to one or more “libraries” of materials, and for each submesh, a reference to a material defined in one of the libraries. The libraries (and the materials defined by them) are not within the .obj file itself. A material library consists of a separate file with an .mtl file extension. The material library may refer to one or more textures, which simply specified by name within the .mtl. So, the textures are not within either the .obj file nor the .mtl file, and the .mtl is not within the .obj file.


#5

Excellent description, thank you.