I wrote a simple reader for the COLLADA
file format, and it seems to work OK. Now, I have a Blender-exported cube mesh which is edge-splitted and triangulated, so it should have 12 triangles (2 per face), 24 vertices (4 per face) and 36 indices (6 per face). This mesh also has normal data and UV maps.
The COLLADA
file has 24 vertices, 12 normals, and 36 UVs, so I assume the normals are per-triangle and the UVs are per-index. The polylist
count for triangles is 12, which is correct, and the vcount
has twelve '3's, so that's correct too. Now, the <p>
which is the index list has 108 entries, where 0, 3, 6 etc. are vertex indices, 1, 4, 7 etc. are normal indices and 2, 5, 8 etc. are UV indices.
I have an internal struct for vertices, which consists of position (vec3
), normal (vec3
) and UV coordinate (vec2
). To draw the meshes, I use OpenGL's vertex buffers, and have a separate list of indices.
The thing is, shouldn't I have 24 vertices after loading the mesh? The 108 entries in <p>
translates into 36 vertices. What's the problem here with the indices?
I may be missing something really simple here, but can't just see it.
The COLLADA
file is here.
Okay, I found the solution, had to clear my mind with a simple plane. As every face is a triangle, the final count of vertices was three times the count described in the polylist's count attribute. So, for the cube, it was 36 - not 24. In the end, the 36 does draw the cube correctly. So, it was mainly just my brain going nuts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With