Scripting a mesh uv procedurally.

I’m having trouble finding adequate information on mesh uv mapping in unity. I’ve done lots of uv mapping by hand, but I’ve never really approached it by code, any information or direction is helpful, thanks in advance :). The goal of my research is to put the final touches on a procedurally generated terrain mesh, of which understanding and procedurally wrapping a uv map is the last step. If you can help with the understanding part, I don’t expect you to code it for me :p.

What I know:
Uvs are held in an Vector2*[ ] array, which are filled, generally with values from 0 - 1 unless you are scaling or repeating the texture.

What I don’t know:
How many entries, and what values to insert, per vertex. In particular I’m still learning how unity interprets data supplied to mesh.uv/uv2.

Edit: *Accidently wrote int, also, this is in c#, I forgot to mention what language.

I wrote an OBJ importer. Feel free to dissect it to learn anything you can. It’s not optimized, though. So it actually creates duplicate vertices instead of combining them when everything matches.

In general, I believe Unity is limited to 1 UV coordinate per vertex. If you need multiple, you need multiple vertexes. (For sharp lines, etc.)

I appreciate the link, I’ll be dissecting that tonight. So would I simply generate a uv coordinate for each vertex? Is there an order to enter them in like in the case of triangles?

I think I have a lead I’m going to go with for now, at least it’s something to move forward on, please correct me on mistakes in my concept. So uvs are inserted in triplets likes triangles, each one plotted on a 1x1 2d plot, on a reversed scale in unity, so 0.0 is the bottom left (more appropriately anyway). That was a small piece I was missing.

With this, my concept is to map each polygon to the top or bottom triangle of a tiled texture, so 00,01,11 and 00,10,11. This would result in each 1x1 square of the ground mesh repeating the texture, looking very ugly as a mipmap, but it would work right?

Everything is per-vertex (normals, uvs, etc.); that’s how the hardware works.

–Eric