3
$\begingroup$

I just asked(and found a solution) to a question here, which talks about how I encountered a texturing problem with my own Wavefront Model Parser. The problem was that some models that I was loading would be textured just fine, like models from Legend of Zelda. While other models would not be textured correctly, like Claptrap from borderlands. As it turns out, the issue was not with my parser, but due to the fact that those two models were crafted for two different API's. Nintendo uses OpenGL for Zelda/All Nintendo DS games. While DirectX is used for Borderlands. Why was this a problem? Well, OpenGL and DirectX have different texture-origins. OpenGL has its texture origin at the bottom left hand corner, while DirectX is top-left hand corner. In order to get my texture for Claptrap to render correctly I had to open the diffuse texture up in gimp and flip it vertically, thus inverting it for use with OpenGL.

This led me to an interesting question. I had opened both models in Blender before sending them into my own program. And Blender correctly textured them both. So how does Blender know which culture(OpenGL or DirectX) to use when attempting to texture a model?

I should also mention that both Models were in .obj format. The only difference is that one was created for OpenGL UV's in mind, while the other was DirectX UV's. I want to know how Blender decides which UV format/culture the .obj uses.

$\endgroup$
6
  • $\begingroup$ I think Blender doesn't know that and afaik uses OpenGL for drawing viewport in particular; so that's why the result is the same for both models. $\endgroup$
    – Mr Zak
    Nov 2, 2015 at 23:49
  • $\begingroup$ @MrZak So how does it know to flip the DirectX texture coordinates if that is the case? Both of the models I used were in .obj format, so it's not the model format that it detects. $\endgroup$
    – Krythic
    Nov 2, 2015 at 23:51
  • $\begingroup$ Did you try to see these models' textures drawn in programs which use DirectX for redrawing(like 3DS Max)? It may be some problem of the file format, which flips texture coordinates for some reason. Also look at this thread $\endgroup$
    – Mr Zak
    Nov 3, 2015 at 0:06
  • $\begingroup$ @MrZak I did not. But I used them in my program(Follow the link provided in my OP). Which used OpenGL bottom left 0,0. The DirectX model was incorrectly textured, while the OpenGL one was fine. Once I flipped the DirectX model texture vertically, it worked just fine(because it had been inverted to work with OpenGL). $\endgroup$
    – Krythic
    Nov 3, 2015 at 0:11
  • $\begingroup$ @MrZak I'm actually very excited to figure out how Blender does this. I can't even wrap my head around it because if you flip coordinates (DirectX->OpenGL), you still end up with one being invalid for UV mapping. I don't understand how it knows when to invert and when to ignore inversion of textureCoordinates. $\endgroup$
    – Krythic
    Nov 3, 2015 at 0:18

1 Answer 1

2
+50
$\begingroup$

Blender's probably reading the instructions in the mtl (material library) file that accompanies the obj file.

According to the mtl specifications mtl files can include a parameter (-o) that instructs the program reading the file to reverse the texture's origin in the horizontal (u) or vertical (v) directions:

Quoting from the specification document:

The -o option offsets the position of the texture map on the surface by shifting the position of the map origin. The default is 0, 0, 0.

"u" is the value for the horizontal direction of the texture

"v" is an optional argument. "v" is the value for the vertical direction of the texture.

"w" is an optional argument. "w" is the value used for the depth of a 3D texture.

-o v   # This should reverse the texture's origin in the vertical direction

Open your OBJ's MTL files in a text editor and see if you can find anything that resembles this.

$\endgroup$
7
  • $\begingroup$ I didn't give Blender the .mtl, nor was it near the .obj. I already considered that! $\endgroup$
    – Krythic
    Nov 5, 2015 at 15:19
  • 1
    $\begingroup$ The mtl doesn't exist? Wonder how blender knew to associate the texture file with the OBJ file. Not sure if the obj can include the mtl inline, but that's worth inspecting. $\endgroup$
    – TLousky
    Nov 5, 2015 at 15:22
  • $\begingroup$ Because I dropped the texture onto the model after it had loaded it. See why this is so odd? $\endgroup$
    – Krythic
    Nov 5, 2015 at 15:23
  • $\begingroup$ There has to be something in the .obj it reads. Or some other weird kungfu it does with the order of the UV coordinates. $\endgroup$
    – Krythic
    Nov 5, 2015 at 15:27
  • $\begingroup$ I'm at work so I can't look at the claptrap .obj. But can -o parameter be declared in the .obj? I will reiterate, the .mtl was not present on the machine when blender loaded the mesh. $\endgroup$
    – Krythic
    Nov 5, 2015 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .