So, I think I'm starting to get a hang of this 3d stuff, I have now reached a point where I need to do some texture mapping. My question though is how do I create/obtain my texture coordinates. I have an understanding of [u,v] coordinates, but now the question is, "How do I make them"? Looking at my .obj files, I see that they have vt coordinates, I'm not entirely sure how those were produced, but how can I manipulate them to my liking?
I need to do the mapping programatically as the texture will be changing throughout my program. I am currently working with MayaVI , but I feel that working with this stuff is somewhat universal. Thanks for the help!
Texture coordinates are usually not generated but assigned manually. This happens in the 3D modelling application of your choice using a GUI (not by writing them into the 3D file). When the mesh is exported the UV coordinates are exported with the rest of the mesh data.
Automatic texture mapping of geometry is complex. It's not as simple as just flattening out all triangles. After all you want to paint a texture on the unwrapped faces, so having larger chunks of connected faces (not thousands of individual triangles) is essential. You also want to avoid seams / hide the seams. There are various tools which might do a decent job in some respects, but I personally prefer unwrapping by hand with quality 3D modelling software. More control, better results (at the cost of some design time).
For simple meshes (quads, cubes, 2D grid terrains) you can do it manually in the OBJ file or algorithmic.
Also basic transformation (moving, rotating and scaling) of texture coordinates can easily be done in the vertex shader.