Hiya!
I have a function that creates 3D meshes procedurally from the given parameters. It creates a four-sided box, which is (for example) 1.0 wide, 1.0 high and 100.0 long. The box is then subdivided into multiple parts, so if the aforementioned box is subdivided to three parts, it will have vertices at 0f, 33.3f, 66.7f and 100.0f on the longest sides. Now, I have the vertex generation code up and running, but I have a problem generating the triangle lists from the vertices. The box does only contain the sides, not the caps.
The picture here shows a box with a division index of 2. So, the data I already have is the vertex positions, marked as red on the picture. Now, I need to create the triangles, which is done by specifying the three vertices that make up the triangle, for example (0, 1, 2, 1, 2, 3) would make two triangle from the corner points 0, 1, 2 and 3, which are the vertex indices. The problem is, how can this be done for any subdivision count? I have already implemented it for a plane, but the box gives me a brainache because I would like to share the vertices with sides and so on.
Thanks in advance for any help and suggestions :)