- Home /
Set UVs depending on input
I've made a function, to create basically a face for the a mesh, that i'm building through scripting. Altho, vertice, triangles and normals is all setup and calculated, UV's is not.
I honestly, have no idea how to setup the UV's, neither how it corresponds to what is what (An explanation too would be appreciated)
This is my create face code. It takes "Input" (A position, width and height) and then changes this, depending on that. I would think, that how it works?
Code:
private void CreateFace(Vector3 position,int width, int height) {
Mesh_Vertices.Add(new Vector3(position.x, position.y, 0));
Mesh_Vertices.Add(new Vector3(position.x+width, position.y, 0));
Mesh_Vertices.Add(new Vector3(position.x, position.y+height, 0));
Mesh_Vertices.Add(new Vector3(position.x+width, position.y+height, 0));
int a = Mesh_Vertices.Count-1;
int b = a-1;
int c = a-2;
int d = a-3;
Mesh_Triangles.Add(a);
Mesh_Triangles.Add(b);
Mesh_Triangles.Add(d);
Mesh_Triangles.Add(d);
Mesh_Triangles.Add(c);
Mesh_Triangles.Add(a);
//This isn't correctly setup.
Mesh_Uvs.Add(new Vector2(0,0));
Mesh_Uvs.Add(new Vector2(1,0));
Mesh_Uvs.Add(new Vector2(0,1));
Mesh_Uvs.Add(new Vector2(1,1));
}
Answer by HappyMoo · Jan 16, 2014 at 04:22 AM
Your uv coordinates are coordinates within your texture, having 0,0 at bottom/left and 1,1 at the top right.
so if your texture is 256x128 px in size and you have 64x64 tiles defined, this would make 4x2 tiles, which means if you want to grab the bottom/left tile, your texture coordinates defining the diagonal of that tile, would be 0,0 / 0.25,0.5
What's the problem with your setup right now? Is the texture mirrored?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
uv sub meshes in cube c# 0 Answers
Distribute terrain in zones 3 Answers
How do I texture a mesh runtime? 2 Answers
Multiple Cars not working 1 Answer