PDA

View Full Version : Blender -> Export .Obj -> .mtl's Missing Texture


hangt5
2005.07.04, 12:17 AM
When i create an object in blender, assign it a material that has a texture, and export that cube to .obj the accompanying .MTL file doesn't have any information about the texture i assigned. It has all the ambient/diffuse/specular properties but it never defines the path to the texture.

Does anyone know if this is a problem with blender? Or am i not doing something properly?

Leisure Suit Lurie
2005.07.04, 12:23 AM
Does obj require it to do that?

It should give a name for the texture no?

hangt5
2005.07.04, 12:31 AM
Sorry your right, but it doesnt do that either.

For example: Heres an .obj

# Blender OBJ File: /Users/joe/Objects/blockCube.blend
# www.blender.org
mtllib blockCube.mtl
o Cube_Cube
v 0.984054 1.000000 -1.000000
v 0.984054 -1.000000 -1.000000
v -1.015947 -1.000000 -1.000000
v -1.015946 1.000000 -1.000000
v 0.984054 0.999999 1.000000
v 0.984053 -1.000001 1.000000
v -1.015947 -1.000000 1.000000
v -1.015946 1.000000 1.000000
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vt 0.0 0.0 0.0
vn 0.577349 0.577349 -0.577349
vn 0.577349 -0.577349 -0.577349
vn -0.577349 -0.577349 -0.577349
vn -0.577349 0.577349 -0.577349
vn 0.577349 0.577349 0.577349
vn -0.577349 0.577349 0.577349
vn -0.577349 -0.577349 0.577349
vn 0.577349 -0.577349 0.577349
vn 0.577349 0.577349 -0.577349
vn 0.577349 0.577349 0.577349
vn 0.577349 -0.577349 0.577349
vn 0.577349 -0.577349 -0.577349
vn 0.577349 -0.577349 -0.577349
vn 0.577349 -0.577349 0.577349
vn -0.577349 -0.577349 0.577349
vn -0.577349 -0.577349 -0.577349
vn -0.577349 -0.577349 -0.577349
vn -0.577349 -0.577349 0.577349
vn -0.577349 0.577349 0.577349
vn -0.577349 0.577349 -0.577349
vn 0.577349 0.577349 0.577349
vn 0.577349 0.577349 -0.577349
vn -0.577349 0.577349 -0.577349
vn -0.577349 0.577349 0.577349
usemtl Material
f 1/1/1 2/2/2 3/3/3 4/4/4
f 5/5/5 8/6/6 7/7/7 6/8/8
f 1/9/9 5/10/10 6/11/11 2/12/12
f 2/13/13 6/14/14 7/15/15 3/16/16
f 3/17/17 7/18/18 8/19/19 4/20/20
f 5/21/21 1/22/22 4/23/23 8/24/24


And its accompanying .MTL

# Blender MTL File: /Users/joe/Objects/blockCube.blend
newmtl Material
Ns 96.0784313725
Kd 0.811992 0.800000 0.800000
Ka 1.000000 1.000000 1.000000
Ks 1.000000 1.000000 1.000000
d 1.000000
illum 2



The .blender version of this file has a nice wood texture attached to the material.

Fenris
2005.07.04, 03:40 AM
Ah. .obj's notion of a material differs pretty heavily from Blender's: Blender thinks a material is shininess, color, texture - the works; while .obj defines material as diffuse color, shininess, specularity and emissive components. No texture, I'm afraid. You need to bake the texture from Blender and then apply that by hand in OpenGL.

hangt5
2005.07.04, 02:50 PM
Could you explain what you mean by "bake the texture from blender"?

And thanks a lot for the info, that explains a lot.

hangt5
2005.07.04, 03:36 PM
And does anyone know if blender exports texture coordinates? None of my .obj's have any of those either :'(

Duane
2005.07.04, 03:53 PM
well, it would have to. It uses opengl :p

hangt5
2005.07.04, 04:23 PM
well, it would have to. It uses opengl :p

Take a look at the example i posted. all the VT's are 0,0,0

LongJumper
2005.07.04, 04:44 PM
Use UVMapper to get texture coordinates for a .obj file.

hangt5
2005.07.04, 08:45 PM
You would think blender would export the UV info considering they MUST have it handy somewhere...

This whole thing is kind of ridiculous.

I was originally using .obj's exported from cinema 4d. Cinema doesn't export .mtl's so i started using .fbx's (which has the material information stored right in the file.) FBX is basically a total mess so i moved back over to .obj's except I'm now using blender so i can use the .mtl. Now i find out Blender exports .mtl's but apparently no UV info.

Its like there's a mass conspiracy to get you to use as many different programs and formats as possible before you just create your own... which sounds damn appealing right now.

Edit: sorry about the rant and thanks for the program. Il check it out tonight.

NCarter
2005.07.05, 04:36 AM
Blender certainly does export UVs to OBJ format, and it also has a built-in UV mapping editor. I've used it to texture a little spaceship, and that exported to OBJ format fine, so I can confirm that it works.

If you're getting 0,0,0 for every vt, that means you haven't set up the mapping in Blender at all, or you've somehow cancelled it all out. Try this:

Select your object and switch into UV Face Select mode in the 3D window's menu.
If necessary, select all (press 'a') so that all the faces get their edges highlighted.
In the 3D window's Face menu, select Unwrap UVs (or press 'u').
From the next menu that appears, choose whatever mapping you want... maybe start with Cube or Standard 1/1. LSCM will unwrap your object to make it flat, but you need to add seams first (read the links below for that).
Switch a window (preferably a separate one from the 3D window) into UV/Image Editor mode. You should see a square or a pattern of faces that look a bit like your object.
In the UV/Image Editor window, use the little popup menu next to the UV menu to select the texture you want to use from your material (assuming you've already set up your material correctly). Hopefully you'll be able to see the texture in the window, and you can select and move vertices and faces around in UV space until you get the result you want.
If you then export the OBJ file, it should have proper UVs. You may still need to do something with the .mtl file to make it do what you want. I usually just hand-edit as necessary.
Here's the relevant page on UV mapping (http://www.blender.org/modules/documentation/htmlI/x5138.html) from the documentation. I also found this tutorial (http://biorust.com/index.php?page=tutorial_detail&tutid=85) quite helpful.

One other thing... make sure you have the latest version of Blender. They've just added a load of new features, and some of them improve the UV/Image Editor quite a lot.

EDIT: It's commonly the case that 3D software won't export exactly what you want. If that bothers you, and you're using a scriptable program like Cinema 4D or Blender, why not write your own OBJ export script, or an exporter for your own custom format? Alternatively, you could write a command line script to postprocess the exported files.

Leisure Suit Lurie
2005.07.05, 11:40 AM
As far as obj and CInema4D goes:

it reverses normals
it inverts the v in uvs

At least these are reversed as far as OpenGL is concerned.

hangt5
2005.07.05, 03:20 PM
Blender certainly does export UVs to OBJ format, and it also has a built-in UV mapping editor. I've used it to texture a little spaceship, and that exported to OBJ format fine, so I can confirm that it works.

If you're getting 0,0,0 for every vt, that means you haven't set up the mapping in Blender at all, or you've somehow cancelled it all out. Try this:

Select your object and switch into UV Face Select mode in the 3D window's menu.
If necessary, select all (press 'a') so that all the faces get their edges highlighted.
In the 3D window's Face menu, select Unwrap UVs (or press 'u').
From the next menu that appears, choose whatever mapping you want... maybe start with Cube or Standard 1/1. LSCM will unwrap your object to make it flat, but you need to add seams first (read the links below for that).
Switch a window (preferably a separate one from the 3D window) into UV/Image Editor mode. You should see a square or a pattern of faces that look a bit like your object.
In the UV/Image Editor window, use the little popup menu next to the UV menu to select the texture you want to use from your material (assuming you've already set up your material correctly). Hopefully you'll be able to see the texture in the window, and you can select and move vertices and faces around in UV space until you get the result you want.
If you then export the OBJ file, it should have proper UVs. You may still need to do something with the .mtl file to make it do what you want. I usually just hand-edit as necessary.
Here's the relevant page on UV mapping (http://www.blender.org/modules/documentation/htmlI/x5138.html) from the documentation. I also found this tutorial (http://biorust.com/index.php?page=tutorial_detail&tutid=85) quite helpful.

One other thing... make sure you have the latest version of Blender. They've just added a load of new features, and some of them improve the UV/Image Editor quite a lot.

EDIT: It's commonly the case that 3D software won't export exactly what you want. If that bothers you, and you're using a scriptable program like Cinema 4D or Blender, why not write your own OBJ export script, or an exporter for your own custom format? Alternatively, you could write a command line script to postprocess the exported files.

Thanks a lot for the help :)

I was selecting the mapping info from the shader window. I guess i never explicitly mapped the models UV info.