Dynamic mesh creation and UVs

Just for making things clear, I’m a developer. I have only minimal knowledge of how 3D texturing works.

In my project I created a dynamic mesh. Everything goes fine, except for UVS: I just cant understand in any way what do UVs do :smile:

In all examples and example projects I found this code useful for assigning values to the UV array:

for(int a=0;a<UVs.Length;a++) 
{ [INDENT]UVs[a] = new Vector2(Verts[a].x,Verts[a].y);// "Verts" is the vertices array
[/INDENT]}

I only understood that there is some relation between the vertices and the UVs (usually the length of UVs is the same as the length of the vertices - and I am using the verices array to initialize the UVs values).

The code works perfectly, but what exactly the above code does? What’s the information stored by the UVs array?
I need to control in more detail the way the mesh is textured.

Thanks for help
Simone

The texture UV is an extra component to EACH vertex that defines what coordinate of texture to use. Since x, y, z are used to define it’s position in 3D space, the u, v are to define its texture position in a 2D texture. (0,0) is bottom left (1,1) is top right.

Thanks a lot callahan!, now i understand.
I didnt know that the u and v were the relative positions of the textures.

In case you’re still interested, the bit of code you posted performs simple planar UV mapping (which is just one of many ways to assign texture coordinates to vertices).

Ok thanks. Now I have the knowledge to understand that

Simone