Hello,
I recently started playing around with Unity, and I noticed there are problems related to importing UV coordinates .OBJ import, which I was going to use since I wanted to just manually enter in my geometry data in a text file. For example, the UVs seem to get thrown away for this example plane file:
v 1.0 0.0 1.0
v 1.0 0 -1.0
v -1.0 0 -1.0
v -1.0 0 1.0
vt 0.0 1.0
vt 1.0 1.0
vt 1.0 0.0
vt 0.0 0.0
vn 0.0 1.0 0.0
vn 0.0 1.0 0.0
vn 0.0 1.0 0.0
vn 0.0 1.0 0.0
g test_object
f 1/1/1 2/2/2 3/3/3
f 3/3/3 4/4/4 1/1/1
I read there may be some way to import OBJ if you have some sort of material files to import as well, but I don’t know what the format is of these things- does anyone have an example OBJ and MATERIAL file that work together and don’t throw away the UV coordinates?
Also, is there another ASCII format that I can easily make with a text editor that Unity will import correctly instead, too?
Thanks!
I’m not sure if it’s a bug or intentional, but you need a .mtl file if you want to import UVs from .obj files - otherwise it just throws them away. Here’s a typical .mtl file:
newmtl Material0
Ka 0.937255 0.933333 0.941176
Kd 1 0.972549 1
Ks 0.109804 0.109804 0.109804
Ns 100
map_Kd TextureName.jpg
I don’t know if Unity pays any attention to all or any of the lines in the .mtl file, as I haven’t tested it thoroughly. Here’s a page which describes the meaning of each of the parameters.
Your .obj file must contain (begin with?) a line which tells the importer the name of the .mtl file:
mtllib ObjFileName.mtl
The name of the two files don’t have to match, but it would probably be a good idea, unless you really want to make several .obj files share one .mtl file. Finally, the .mtl file should be located in the same folder as the .obj file.
Hope that helps. 
The material half of an OBJ is an MTL file. Do a search on the web for free models that include both files. I haven’t used OBJs for a while, but I do remember certain programs being able to export them better than others in regards to the materials. For instance Maya does a very good job with OBJs while I remember LightWave being horrible at retaining the material information.
[Edit] Here’s an exported OBJ cube from Maya with the MTL file.
25024–903–$objcube_160.zip (1 KB)
I put the .mtl in the same folder, added the map_Kd to the .mtl file, and added a Textures folder in the same directory and it worked. Thanks a lot guys, especially for the quick response.
I’ve been playing around with Unity for a few days now and I’m surprised this has been the first thing that didn’t “just work” when I tried it. Other than this problem, the ease of use for Unity has been unbelievably nice for a game engine.
For the Unity developers, is there a reason the .mtl file is required? Since you can assign a material anyway to the Mesh Renderer component, I don’t see why the texture coordinates couldn’t be saved and then restored when the a shader is put on the object.
I believe they use the FBX SDK to import OBJ and there is a bug in that they are waiting for a fix to correct this.
-Jon