OpenGL 将顶点视为单个长向量
(position, normal, texcoord[0]…texcoord[n], attrib[0]…attrib[n])
并且这些长向量被索引。您的问题属于同一类别,例如如何使用具有多个法线的共享顶点。规范的答案是,这些顶点实际上是不共享的,因为从长远来看它们并不相同。
因此,您需要做的是遍历面的索引数组并构造“长”顶点,将它们添加到具有唯一性约束的(新)列表中;来自顶点→索引的(散列)映射服务于这项工作。像这样的东西
next_uniq_index = 0
for f in faces:
for i in f.indices:
vpos = vertices[i.vertex]
norm = normals[i.normal]
texc = texcoords[i.texcoord]
vert = tuple(vpos, norm, texc)
key
if uniq_vertices.has_key(key):
uniq_faces_indices.append(uniq_vertices[key].index)
else:
uniq_vertices[key] = {vertex = key, index = next_uniq_index}
next_uniq_index = next_uniq_index + 1