I'm attempting to create a 3d game using OpenGL. I have a very basic world and am now working on a character. I want to map a texture to the head which will be oval shaped. How do I do the mapping? I know how to map to flat surface. I'm wondering if the normals can be used to help but I've never done this before and when I search Google I don't have any luck.
I'm planning on doing this all programmatically and not using Blender or Maya if that makes any difference.
I'm guessing from your post that you're fine with geometry?
For automatic mapping in the general case, your guess is a good idea — start from each vertex and follow its normal outwards until you hit a well-defined outer primitive, then copy the texture location inwards from that.
In this case I think probably the key is in how you generate your geometry. If you're doing something like creating 8 rings of 16 points, effectively iterating around one circle in an outer loop and another in an inner loop then you can simultaneously iterate u and v to get a mapping. You get some irregularly sized polygons and the mapping becomes troublesome at the poles, but the area around where the face would be works quite well.
If you want a more equal size of polygon and a reliable mapping in all areas then start with an over-tesselated cube (eg, a grid of 8x8 quads per surface instead of just one) and map the texture coordinates in any meaningful way. Think in terms of the net of a cube. Then deform the cube into a sphere by working out the vector from the centre to each point and moving the point so that it is the radius of the sphere from the centre. Finally, deform the sphere into the oval by scaling different axes differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With