Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping Wavefront .obj's vt to OpenGL texture coordinates

an artist friend has sent me an .obj file exported by 3DS Max 2009 which contains three texture coordinates as parameters to the vt command. And that's correct according to .obj specification. However, I'm not sure how to map U-V-W coordinates that are provided for a regular 2D .jpg texture.

This is relatively important for me, since I've played with 3DS Max trying to figure out how to force it to export just U-V coordinates, but there appears to be no straightfoward way. In this case this is just a skybox, but in other cases it might be something way more complex and not hand-fixable.

Thanks!

like image 940
Ivan Vučica Avatar asked Dec 23 '22 11:12

Ivan Vučica


2 Answers

There's a section in the article What Is UVW Mapping? that explains:

You might question why you need a depth coordinate like W for a 2D plane. One reason is because it's sometimes useful to be able to flip the orientation of a map, relative to its geometry. To do this, you need the third coordinate. The W coordinate also has a meaning for 3-dimensional procedural materials.

In your case, you can simply ignore the W coordinate and only read the first two floats of lines that begin with vt. This assumes that you're not very worried about the extra space taken by the W coordinate since .obj is quite an inefficient file format to begin with.

Personally I don't like using .obj in OpenGL because it provides vertex normals per face instead of per vertex. To light an object properly you must either duplicate vertices or calculate normals by averaging the surrounding vertex normals in a face. If you want to explore more efficient alternatives, take a look at binary formats, such as the thoroughly documented .md2 format. Also consider using glDrawElements if you're not utilizing it already.

like image 85
Kai Avatar answered Jan 11 '23 09:01

Kai


sorry if I misunderstand your question. But could't you simply ignore the third parameter, w? As I understand it, w is just a coordinate in a plane perpendicular to the plane described by u and v, so it is rarely needed for simple 2d texture mapping.

hope this helps.

like image 30
david h Avatar answered Jan 11 '23 09:01

david h