2016-11-30 92 views
0

我試圖在我的遊戲引擎中實現邊緣崩潰,有一個由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處理背後的數據,並生成指定的索引和頂點。

如果我需要重新計算索引,那意味着我需要檢查每個頂點的所有頂點以找出哪些頂點相同並構造索引。無法弄清楚如何解決這個問題..

+0

增加指數是好的。什麼是問題?你認爲多個頂點應該合併成一個,但它們不是?如果沒有看到數據,這將是有問題的。 – keltar

+0

@keltar,對於使用邊緣塌陷,由於沒有找到相反的索引對,或者我誤解了邊緣塌陷,我找不到相反的邊緣? – Tokenyet

+0

如果你想合併臉部之間的頂點然後是,這些索引本身是不可合併的。這實際上取決於你如何決定你算作'頂點' - 一些軟件認爲它只是位置,而GL/D3D/assimp /等。將所有屬性組合爲單個頂點,並且如果至少有一個數不同 - 則有不同的頂點。所以我再問一次 - 你是否100%確定你的數據具有在面之間共享的頂點(這包括位置,法線,紋理座標等等)?如果是這樣,請添加說明您的問題的數據示例。 – keltar

回答

0

有兩個重要的事情,使該算法與Assimp Importer合作。

  1. 模型應該共享的頂點與面孔,如果模型不是,它應該與3D模型軟件中的一些選項來完成。我在問題部分提供的樹對象,我需要刪除雙打(刪除重複的頂點)在攪拌機和正常應該只是一個。

  2. 另一件事需要注意的是,後處理選項與assimp。檢查Assimp文檔,有一個標誌aiProcess_JoinIdenticalVertices,如果不啓用,Assimp將生成唯一頂點的完全唯一索引。有更多的信息在here