Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top