From 5d8b1649a403a54b3ea4b34f299dfdb111577ef5 Mon Sep 17 00:00:00 2001 From: motazmuhammad Date: Fri, 13 May 2022 19:59:16 +0100 Subject: [PATCH] Revert "use unordered_set to accelerate the vertix merging" This reverts commit 0ffb91fbf15921582552ab7b4fca5eaa3aa0150f. --- code/PostProcessing/JoinVerticesProcess.cpp | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/code/PostProcessing/JoinVerticesProcess.cpp b/code/PostProcessing/JoinVerticesProcess.cpp index 7d170e2bb..56e1ad520 100644 --- a/code/PostProcessing/JoinVerticesProcess.cpp +++ b/code/PostProcessing/JoinVerticesProcess.cpp @@ -54,6 +54,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace Assimp; // ------------------------------------------------------------------------------------------------ @@ -258,7 +259,7 @@ return seed; template<> struct std::equal_to { 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) @@ -333,9 +334,10 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) uniqueAnimatedVertices[animMeshIndex].reserve(pMesh->mNumVertices); } } - std::unordered_set m; - m.reserve(pMesh->mNumVertices); + std::unordered_map vertex2Index; + vertex2Index.reserve(pMesh->mNumVertices); // Now check each vertex if it brings something new to the table + int newIndex = 0; for( unsigned int a = 0; a < pMesh->mNumVertices; a++) { if (usedVertexIndices.find(a) == usedVertexIndices.end()) { continue; @@ -343,17 +345,22 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) // collect the vertex data 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); if (hasAnimMeshes) { for (unsigned int animMeshIndex = 0; animMeshIndex < pMesh->mNumAnimMeshes; animMeshIndex++) { Vertex aniMeshVertex(pMesh->mAnimMeshes[animMeshIndex], a); - uniqueAnimatedVertices[animMeshIndex].push_back(aniMeshVertex); + uniqueAnimatedVertices[animMeshIndex].push_back(v); } } - } + + } + else { + replaceIndex[a] = it->second; + } }