hi, I’ve been generating meshes via Mesh class. Regular planes are simple, since there geometer is a big loop with a single cut. but for more complex planes such as this im unsure how one would map the triangles or UVs.
reading this doc(Unity - Manual: Using the Mesh Class) tells me that the vertices follow a “clock-wise” rule, which is easy to implement on a 4 vert plane. but a 4 vert with an inset? there
can anyone explain how one would work out which vert is which? assuming the lower left most is 0?
here is the mesh im trying to generate:
trial and error seems to be getting me nowhere as hopelessly deformed meshes pop up in front of my screen. why is this overlooked in the docs, it has regular one 4 vert plane and nothing else…All I know is that the triangles need to be a 30 sized array, with number ranging from 0-7.
the vertices themselves are there, after trial an error of seen the deformed geometry wap itself.
I don’t understand how the UV’s work either, with regular planes the vector values are 1 or 0. are they based on ratios between vertices? I don’t even know where to start with these guys.
if it helps here is a snippet of plane-gen code
mesh.vertices = new Vector3[] {
Manager.GUI.ScreenToWorldPoint(new Vector3(0f,0f,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(padding,padding,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width,padding,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width + padding,0f,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width, height, 0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3(width + padding, height + padding, 0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3 (padding, height,0f)),
Manager.GUI.ScreenToWorldPoint(new Vector3 (0f, height + padding,0f)),
};
mesh.triangles = new int[] {
0, 5, 6,
0, 6, 2,
0, 4, 1,
0 ,4, 3,
0 ,3, 4,
7, 5, 2,
3, 4, 5,
5, 3, 2,
6, 0, 2,
3, 4, 1
};
mesh.uv = new Vector2[] {
new Vector2(0,0), new Vector2(1,0),
new Vector2(1,1), new Vector2(0,1),
new Vector2(0,0), new Vector2(1,0),
new Vector2(1,1), new Vector2(1,1)
};
mesh.RecalculateNormals();
I just punched random numbers for the triangles and UVs as you can tell.
thanks in advance