这个 gltf 文件中的框的索引是如何工作的?

How does the indexing of the box in this gltf file work?

所以根据我的理解,如果我想使用索引三角形渲染一个盒子,我需要 8 个顶点(用于 8 个角点)和 36 个索引(盒子有 6 个边,每边 2 个三角形和 3 个索引每个三角形,6*2*3=36).

因此请考虑找到的 gltf 文件 here。这是一个正确的文件,我可以看到正确数量的顶点和索引。然而指数是:

[0, 1, 2, 3, 2, 1, 4, 5, 6, 7, 6, 5, 8, 9, 10, 11, 10, 9, 12, 13, 14, 15, 14, 13, 16, 17, 18, 19, 18, 17, 20, 21, 22, 23, 22, 21]

如果我没看错的话。我认为这些数字永远不会超过 7(因为只有 8 个顶点需要索引)。我是不是读错了文件,或者这个索引是如何工作的?

您没有正确阅读文件。除了立方体没有 8 个顶点。它有 24 个。之所以这样,是因为它们除了存储位置数据外,还存储 normals. OpenGL allows for single-indexing, that is positions, normals, tangets etc. cannot be indexed separately. This means that some vertices need to be duplicated, to be able to be indexed properly. This is explained well here.