ShadedVertex


«
Reply #2  Posted
20160618 07:48:52 » 

Alright, this isn't really confusing if you think about it. I assure you, there's no LCM calculation involved.
Following common sense, there should be fewer triangles than vertices, because for every three vertices, there's at least one triangle. That means the number of vertices has to be three times the number of triangles, and (no. of vertices)/3 = (no. of triangles).
Right?
Well...yeah, kinda, but like I said, for every three vertices, there's AT LEAST one triangle. But that's not the case for most models, because there are hundreds of triangles in the models we use, and one vertex can be a part of multiple triangles (which is why we use the index buffer).
That means we can't calculate the number of triangles using the number of vertices, but we CAN calculate the number of triangles using the length of the indices array.
Let's say we've got a 2D quad:
vertices = {1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0};
As you can see, there's a repetition, because we're using the same vertex for two triangles (since a quadrilateral consists of two triangles). Look at the third vertex (1, 1, 0). It's used twice. The first vertex is also used twice.
So we use the index buffer and it looks a little something like this:
vertices = {1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0}; indices = {0, 1, 2, 2, 0, 3};
Now, the vertex array doesn't have any repetition, but the indices array does.
That's why we can't take the vertex array's length and divide it by three to get the number of triangles. We have to use the indices array's length and divided it by three to get the number of triangles (three vertices for every triangle, as mentioned above).
