Answers for "Read Vertices in a specific order?"
http://answers.unity.com/questions/1261049/read-vertices-in-a-specific-order.html
The latest answers for the question "Read Vertices in a specific order?"Answer by JonHUnity
http://answers.unity.com/answers/1262150/view.html
The order of the vertices in a Mesh are determined by the order they were assigned when created. Unless explicitly documented by your importer or by the code which generated your mesh, there are no guarantees about the order of the vertices in the array.
Your picture looks like your mesh is a procedurally generated flat plane. To accomplish this with a specific order to the vertices, I recommend generating the mesh yourself. For example, to create a grid-based mesh, you can do something like the following:
public class CreateMesh : MonoBehaviour {
const int width = 100;
const int height = 100;
// Generate the mesh with a well-known vertex order
void Start () {
Mesh mesh = gameObject.AddComponent<MeshFilter>().mesh;
gameObject.AddComponent<MeshRenderer>();
mesh.vertices = GenerateVertices(width, height);
mesh.triangles = GenerateTriangles(width, height);
}
private int[] GenerateTriangles(int width, int height)
{
//generate two triangles per vertex except the last column and last row
int[] triangles = new int[(width - 1) * (height - 1) * 6];
for (int y = 0; y < height - 1; y++ )
{
for (int x = 0; x < width - 1; x++ )
{
triangles[(y * (width - 1) + x) * 6 ] = y * width + x;
triangles[(y * (width - 1) + x) * 6 + 1] = y * width + x + 1;
triangles[(y * (width - 1) + x) * 6 + 2] = y * width + x + 1 + width;
triangles[(y * (width - 1) + x) * 6 + 3] = y * width + x;
triangles[(y * (width - 1) + x) * 6 + 4] = y * width + x + 1 + width;
triangles[(y * (width - 1) + x) * 6 + 5] = y * width + x + width;
}
}
return triangles;
}
Vector3[] GenerateVertices(int width, int height)
{
Vector3[] vertices = new Vector3[width * height];
for (int y = 0; y < height; y++ )
{
for (int x = 0; x < width; x++ )
{
vertices[y * width + x] = new Vector3(x / (float)width, y / (float) height);
}
}
return vertices;
}
void Update () {
Mesh mesh = this.gameObject.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
SetVertex(vertices, 10, 12, .55f);//set the z component of the vertex at x=10, y=12 to .55
mesh.vertices = vertices;
}
private void SetVertex(Vector3[] verts, int x, int y, float z)
{
verts[width * y + x].z = z;
}
}Tue, 25 Oct 2016 12:38:22 GMTJonHUnity