0
我想加載簡單的3d模型cube.3ds,但發生下一個錯誤:當我讀取索引到我的向量,向量包含:[0,1,2,3,...] 。這不正確。我發現幾乎相同的主題:Assimp and D3D model loading: Mesh not being displayed in D3D,但我沒有找到答案。任何人都可以詳細描述從網格加載索引的算法。非常感謝!Assimp不正確加載索引
我想加載簡單的3d模型cube.3ds,但發生下一個錯誤:當我讀取索引到我的向量,向量包含:[0,1,2,3,...] 。這不正確。我發現幾乎相同的主題:Assimp and D3D model loading: Mesh not being displayed in D3D,但我沒有找到答案。任何人都可以詳細描述從網格加載索引的算法。非常感謝!Assimp不正確加載索引
下面是一個從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