From ec1333bfdf4fc2d5db7edb769d617e8dfa88e4d5 Mon Sep 17 00:00:00 2001 From: Sebastian Matusik Date: Thu, 5 Jul 2018 14:38:58 +0100 Subject: [PATCH] JoinVerticesProcess should only try to deduplicate used vertices. --- code/JoinVerticesProcess.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/code/JoinVerticesProcess.cpp b/code/JoinVerticesProcess.cpp index 7f7bcae41..b91f44048 100644 --- a/code/JoinVerticesProcess.cpp +++ b/code/JoinVerticesProcess.cpp @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace Assimp; // ------------------------------------------------------------------------------------------------ @@ -239,6 +240,19 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) return 0; } + // We should care only about used vertices, not all of them + // (this can happen due to original file vertices buffer being used by + // multiple meshes) + std::unordered_set usedVertexIndices; + usedVertexIndices.reserve(pMesh->mNumVertices); + for( unsigned int a = 0; a < pMesh->mNumFaces; a++) + { + aiFace& face = pMesh->mFaces[a]; + for( unsigned int b = 0; b < face.mNumIndices; b++) { + usedVertexIndices.insert(face.mIndices[b]); + } + } + // We'll never have more vertices afterwards. std::vector uniqueVertices; uniqueVertices.reserve( pMesh->mNumVertices); @@ -292,6 +306,10 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) // Now check each vertex if it brings something new to the table for( unsigned int a = 0; a < pMesh->mNumVertices; a++) { + if (usedVertexIndices.find(a) == usedVertexIndices.end()) { + continue; + } + // collect the vertex data Vertex v(pMesh,a);