From a22aa75bca5da546abb320edefe2da0ae3316535 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Wed, 31 Aug 2022 22:27:34 +0200 Subject: [PATCH] fix vertices being joined duplicating weights This bug causes weights to duplicate, i.e. one bone will have several (equal) weights assigned to the same vertex - which then has the potential to cause even bigger problems when combined with `LimitBoneWeightsProcess`. --- code/PostProcessing/JoinVerticesProcess.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/PostProcessing/JoinVerticesProcess.cpp b/code/PostProcessing/JoinVerticesProcess.cpp index 84e742115..aed865e30 100644 --- a/code/PostProcessing/JoinVerticesProcess.cpp +++ b/code/PostProcessing/JoinVerticesProcess.cpp @@ -394,6 +394,16 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) { const aiVertexWeight& ow = bone->mWeights[ b ]; // if the vertex is a unique one, translate it if ( !( replaceIndex[ ow.mVertexId ] & 0x80000000 ) ) { + bool weightAlreadyExists = false; + for (std::vector::iterator vit = newWeights.begin(); vit != newWeights.end(); ++vit) { + if (vit->mVertexId == replaceIndex[ow.mVertexId]) { + weightAlreadyExists = true; + break; + } + } + if (weightAlreadyExists) { + continue; + } aiVertexWeight nw; nw.mVertexId = replaceIndex[ ow.mVertexId ]; nw.mWeight = ow.mWeight;