Answers for "Triangulation Problems"
http://answers.unity.com/questions/1084151/triangulation-problems.html
The latest answers for the question "Triangulation Problems"Answer by Bunny83
http://answers.unity.com/answers/1084203/view.html
You have to multiply y by xMax, not yMax
int v = x + (y * xMax);
Further more when creating the triangle indices you should reduce the limits of your for loops by 1
for (int x = 0; x < xMax-1; x++) {
for (int y = 0; y < yMax-1; y++) {
I just checked your 2 triangles and your second triangle is facing the wrong way. It need to be clockwise. The first one is clockwise, the second one is counter clockwise. So the second one is facing backwards.
The size of the triangles array is also too small. There are two rows with each 4 quads:
0 1 2 3 4
Q1 Q2 Q3 Q4
5 6 7 8 9
Q5 Q6 Q7 Q8
10 11 12 13 14
That means since each quad requires two triangles and each triangle 3 indices you need
int[] triangles = new int[ (xMax-1) * (yMax-1) * 2 * 3 ];
So finally it should look something like:
Vector3[] vertices = new Vector3[xMax * yMax];
int[] triangles = new int[ (xMax-1) * (yMax-1) * 6 ];
// vertices
for (int y = 0; y < yMax; y++)
{
for (int x = 0; x < xMax; x++)
{
int v = x + (y * xMax);
vertices[v] = new Vector3(x,y,0);
}
}
// triangles
int t = 0;
for (int y = 0; y < yMax-1; y++)
{
for (int x = 0; x < xMax-1; x++)
{
int v = x + (y * xMax);
triangles[t++] = v;
triangles[t++] = v + 1;
triangles[t++] = v + xMax;
triangles[t++] = v + 1;
triangles[t++] = v + xMax + 1;
triangles[t++] = v + xMax;
}
}Sun, 18 Oct 2015 22:26:05 GMTBunny83