How to handle COLLADA indices?

I wrote a simple reader for the COLLADA file format, and it seems to work fine. Now I have a cubic grid exported using Blender, which is divided along the edges and triangulated, so it should have 12 triangles (2 per face), 24 vertices (4 per face) and 36 indexes (6 per face). This grid also has normal data and UV maps.

The COLLADA file has 24 vertices, 12 normals and 36 UVs, so I assume that the normals are triangles and the UV is the index. The polylist counter for triangles is 12, which is correct, and vcount has twelve three, so this is also correct. Now <p> , which is an index list, contains 108 entries, where 0, 3, 6, etc. - vertex indices, 1, 4, 7, etc. They are normal indices and 2, 5, 8, etc. They are UV indexes.

I have an internal structure for vertices consisting of position ( vec3 ), normal ( vec3 ) and UV coordinate ( vec2 ). To draw meshes, I use OpenGL vertex buffers and have a separate index list.

The thing is, shouldn't I have 24 vertices after loading the mesh? 108 entries in <p> translate to 36 vertices. What is the problem here with indexes?

I may miss something really simple here, but I just canโ€™t just see it.

The COLLADA file is here .

+4
source share
1 answer

Well, I found a solution, had to clear my mind with a simple plane. Since each face is a triangle, a finite number of vertices was three times as many as indicated in the count attribute of the polylist. So for the cube there were 36 - not 24. In the end, 36 really draws the cube correctly. So basically, my brain was going crazy.

+6
source

All Articles