我試圖在我的遊戲引擎中實現邊緣崩潰,有一個由Assimp引起的問題。從face.mNumIndices
解析的索引始終是增量索引。邊緣崩潰與屁股
當我檢查索引列表時,值應該是0,1,2,3,4....,999...
。但我知道這是Assimp使用的某種mechanism,並且該對象被渲染爲正確。但是網格簡化還有另外一個問題,我不能爲這個索引生成半邊結構。我堅持了這一兩天,並沒有回答。我應該放棄Assimp嗎?任何意見表示讚賞。
編輯: 我的頂點是在臉部之間共享的,我用來在這裏獲取數據的代碼。
BasicRenderModel* AssimpLoader::ProcessMeshBasicVersion(aiMesh * mesh, const aiScene * scene)
{
//std::vector<Vertex> vertices;
float *vertices = new float[mesh->mNumVertices * 3];
int vertexLength = mesh->mNumVertices * 3;
float *normals = new float[mesh->mNumVertices * 3];
int normalLength = mesh->mNumVertices * 3;
float *texCoords = new float[mesh->mNumVertices * 2];
int texCoordLength = mesh->mNumVertices * 2;
std::vector<int> indicesList;
int *indices;
int indexLength;
//std::vector<Texture> textures;
std::map<TextureType, std::vector<Texture>> textures;
for (GLuint i = 0; i < mesh->mNumVertices; i++)
{
// Process vertex positions, normals and texture coordinates
vertices[i * 3] = mesh->mVertices[i].x;
vertices[i * 3 + 1] = mesh->mVertices[i].y;
vertices[i * 3 + 2] = mesh->mVertices[i].z;
normals[i * 3] = mesh->mNormals[i].x;
normals[i * 3 + 1] = mesh->mNormals[i].y;
normals[i * 3 + 2] = mesh->mNormals[i].z;
if (mesh->mTextureCoords[0]) // Does the mesh contain texture coordinates?
{
texCoords[i * 2] = mesh->mTextureCoords[0][i].x;
texCoords[i * 2 + 1] = mesh->mTextureCoords[0][i].y;
}
else
texCoords[i * 2] = texCoords[i * 2 + 1] = 0.0f;
Debug::Log("vertex: " + std::to_string(vertices[i * 3]) + "," + std::to_string(vertices[i * 3 + 1]) + "," + std::to_string(vertices[i * 3 + 2]));
}
// Process indices
for (GLuint i = 0; i < mesh->mNumFaces; i++)
{
aiFace face = mesh->mFaces[i];
for (GLuint j = 0; j < face.mNumIndices; j++)
indicesList.push_back(face.mIndices[j]);
}
indices = new int[indicesList.size()];
indexLength = indicesList.size();
for (int i = 0; i < (int)indicesList.size(); i++)
indices[i] = indicesList[i];
return this->loader.LoadRenderModel(vertices, vertexLength, indices, indexLength, texCoords, texCoordLength, normals, normalLength);
}
和上面由代碼生成的this object和指數的結果的頂點是here
比較結果和OBJ文件。對於樹對象,obj文件有624個頂點,但Assimp有927個頂點,來自obj的索引是310(行)* 3 = 930,但從Assimp讀取的索引是927個索引。我認爲Assimp處理背後的數據,並生成指定的索引和頂點。
如果我需要重新計算索引,那意味着我需要檢查每個頂點的所有頂點以找出哪些頂點相同並構造索引。無法弄清楚如何解決這個問題..
增加指數是好的。什麼是問題?你認爲多個頂點應該合併成一個,但它們不是?如果沒有看到數據,這將是有問題的。 – keltar
@keltar,對於使用邊緣塌陷,由於沒有找到相反的索引對,或者我誤解了邊緣塌陷,我找不到相反的邊緣? – Tokenyet
如果你想合併臉部之間的頂點然後是,這些索引本身是不可合併的。這實際上取決於你如何決定你算作'頂點' - 一些軟件認爲它只是位置,而GL/D3D/assimp /等。將所有屬性組合爲單個頂點,並且如果至少有一個數不同 - 則有不同的頂點。所以我再問一次 - 你是否100%確定你的數據具有在面之間共享的頂點(這包括位置,法線,紋理座標等等)?如果是這樣,請添加說明您的問題的數據示例。 – keltar