Blender -> Export .Obj -> .mtl's Missing Texture

Member
Posts: 153
Joined: 2004.12
Post: #1
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?

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #2
Does obj require it to do that?

It should give a name for the texture no?

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #3
Sorry your right, but it doesnt do that either.

For example: Heres an .obj
Code:
# 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

Code:
# 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.

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #4
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.
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #5
Could you explain what you mean by "bake the texture from blender"?

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

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #6
And does anyone know if blender exports texture coordinates? None of my .obj's have any of those either :'(

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #7
well, it would have to. It uses opengl Rasp

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #8
Nayr Wrote:well, it would have to. It uses opengl Rasp

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

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Moderator
Posts: 133
Joined: 2008.05
Post: #9
Use UVMapper to get texture coordinates for a .obj file.
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #10
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.

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #11
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 from the documentation. I also found this tutorial 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.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Moderator
Posts: 529
Joined: 2003.03
Post: #12
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.

"Yes, well, that's the sort of blinkered, Philistine pig-ignorance I've come to expect from you non-creative garbage."
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #13
NCarter Wrote: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 from the documentation. I also found this tutorial 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 Smile

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

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multimedia Fusion 2 and iOS Export Module Jeff_CT 0 4,341 Aug 24, 2011 08:26 PM
Last Post: Jeff_CT
  Missing 'filelist' file Talyn 2 2,738 Dec 10, 2008 05:04 PM
Last Post: ThemsAllTook
  Is blender great for making games? jdmmade 24 14,930 Jun 29, 2006 06:50 AM
Last Post: ferum
  Open/Save As versus Import/Export? WhatMeWorry 1 3,349 Jan 15, 2006 09:33 PM
Last Post: OneSadCookie