Hey guys,
Been working on generating meshes in unity and am now trying to find a more automated and efficient way to generate the triangle int array.
This is the sequence I need to generate.
0, 1, 3,
0, 3, 2,
2, 3, 5,
2, 5, 4,
4, 5, 7,
4, 7, 6…
This is pretty much just working through the triangles in the below image, starting from the bottom and moving in a clockwise rotation through the vertices.
At the moment I am hard coding all the values in like so.
triangleArray = new int[] {
0, 1, 3,
0, 3, 2,
2, 3, 5,
2, 5, 4,
4, 5, 7,
4, 7, 6,
6, 7, 9,
6, 9, 8,
8, 9, 11,
8, 11, 10,
10, 11, 13,
10, 13, 12,
12, 13, 15,
12, 15, 14,
14, 15, 17,
14, 17, 16,
16, 17, 19,
16, 19, 18,
18, 19, 21,
18, 21, 20
};
But this is not ideal due to the meshes being procedural with varying heights and vertex counts.
So can anyone assist me on coding a function do generate that sequence dependent on the vertex count?.
Regards
- Matt
