Browse Source

Revert "use unordered_set to accelerate the vertix merging"

This reverts commit 0ffb91fbf15921582552ab7b4fca5eaa3aa0150f.
motazmuhammad 3 years ago
parent
commit
5d8b1649a4
1 changed files with 15 additions and 8 deletions
  1. 15 8
      code/PostProcessing/JoinVerticesProcess.cpp

+ 15 - 8
code/PostProcessing/JoinVerticesProcess.cpp

@@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #include <assimp/TinyFormatter.h>
 #include <assimp/TinyFormatter.h>
 #include <stdio.h>
 #include <stdio.h>
 #include <unordered_set>
 #include <unordered_set>
+#include <unordered_map>
 
 
 using namespace Assimp;
 using namespace Assimp;
 // ------------------------------------------------------------------------------------------------
 // ------------------------------------------------------------------------------------------------
@@ -258,7 +259,7 @@ return seed;
 template<>
 template<>
 struct std::equal_to<Vertex> {
 struct std::equal_to<Vertex> {
     bool operator()(const Vertex &lhs, const Vertex &rhs) const {
     bool operator()(const Vertex &lhs, const Vertex &rhs) const {
-        return lhs.position.Equal(rhs.position);
+        return areVerticesEqual(lhs, rhs, false);
     }
     }
 };
 };
 int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
 int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
@@ -333,9 +334,10 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
             uniqueAnimatedVertices[animMeshIndex].reserve(pMesh->mNumVertices);
             uniqueAnimatedVertices[animMeshIndex].reserve(pMesh->mNumVertices);
         }
         }
     }
     }
-    std::unordered_set<Vertex> m;
-    m.reserve(pMesh->mNumVertices);
+    std::unordered_map<Vertex,int> vertex2Index;
+    vertex2Index.reserve(pMesh->mNumVertices);
     // Now check each vertex if it brings something new to the table
     // Now check each vertex if it brings something new to the table
+    int newIndex = 0;
     for( unsigned int a = 0; a < pMesh->mNumVertices; a++)  {
     for( unsigned int a = 0; a < pMesh->mNumVertices; a++)  {
         if (usedVertexIndices.find(a) == usedVertexIndices.end()) {
         if (usedVertexIndices.find(a) == usedVertexIndices.end()) {
             continue;
             continue;
@@ -343,17 +345,22 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex)
 
 
         // collect the vertex data
         // collect the vertex data
         Vertex v(pMesh,a);
         Vertex v(pMesh,a);
-        auto it = m.find(v);
-        if (it == m.end()) {
-            m.insert(v);
+        auto it = vertex2Index.find(v);
+        if (it == vertex2Index.end()) {
+            vertex2Index[v] = newIndex;
+            replaceIndex[a] = newIndex++;
             uniqueVertices.push_back(v);
             uniqueVertices.push_back(v);
             if (hasAnimMeshes) {
             if (hasAnimMeshes) {
                 for (unsigned int animMeshIndex = 0; animMeshIndex < pMesh->mNumAnimMeshes; animMeshIndex++) {
                 for (unsigned int animMeshIndex = 0; animMeshIndex < pMesh->mNumAnimMeshes; animMeshIndex++) {
                     Vertex aniMeshVertex(pMesh->mAnimMeshes[animMeshIndex], a);
                     Vertex aniMeshVertex(pMesh->mAnimMeshes[animMeshIndex], a);
-                    uniqueAnimatedVertices[animMeshIndex].push_back(aniMeshVertex);
+                    uniqueAnimatedVertices[animMeshIndex].push_back(v);
                 }
                 }
             }
             }
-        } 
+
+        }
+        else {
+            replaceIndex[a] = it->second;
+            }
 
 
 
 
     }
     }