다음은 메쉬 색인에 액세스 할 때 assimp 샘플 코드에서 가져온 예제입니다.
for (; n < nd->mNumMeshes; ++n)
{
const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
apply_material(sc->mMaterials[mesh->mMaterialIndex]);
if(mesh->mNormals == NULL) {
glDisable(GL_LIGHTING);
} else {
glEnable(GL_LIGHTING);
}
for (t = 0; t < mesh->mNumFaces; ++t) {
const struct aiFace* face = &mesh->mFaces[t];
GLenum face_mode;
switch(face->mNumIndices) {
case 1: face_mode = GL_POINTS; break;
case 2: face_mode = GL_LINES; break;
case 3: face_mode = GL_TRIANGLES; break;
default: face_mode = GL_POLYGON; break;
}
glBegin(face_mode);
for(i = 0; i < face->mNumIndices; i++) {
int index = face->mIndices[i];
if(mesh->mColors[0] != NULL)
glColor4fv((GLfloat*)&mesh->mColors[0][index]);
if(mesh->mNormals != NULL)
glNormal3fv(&mesh->mNormals[index].x);
glVertex3fv(&mesh->mVertices[index].x);
}
glEnd();
}
}
이 코드를 이용해 주셔서 감사합니다. 그러나 나의 실수는 다른 곳에서 일어났다. assimp를 통해 장면을 읽을 때, 나는 단지 aiProcess_Triangulate 플래그만을 전달했지만, 인덱스를 제대로로드하려면 aiProcess_JoinIdenticalVertices를 전달해야합니다. – eugene