浏览代码

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`.
Gargaj 3 年之前
父节点
当前提交
a22aa75bca
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      code/PostProcessing/JoinVerticesProcess.cpp

+ 10 - 0
code/PostProcessing/JoinVerticesProcess.cpp

@@ -394,6 +394,16 @@ int JoinVerticesProcess::ProcessMesh( aiMesh* pMesh, unsigned int meshIndex) {
                 const aiVertexWeight& ow = bone->mWeights[ b ];
                 const aiVertexWeight& ow = bone->mWeights[ b ];
                 // if the vertex is a unique one, translate it
                 // if the vertex is a unique one, translate it
                 if ( !( replaceIndex[ ow.mVertexId ] & 0x80000000 ) ) {
                 if ( !( replaceIndex[ ow.mVertexId ] & 0x80000000 ) ) {
+                    bool weightAlreadyExists = false;
+                    for (std::vector<aiVertexWeight>::iterator vit = newWeights.begin(); vit != newWeights.end(); ++vit) {
+                        if (vit->mVertexId == replaceIndex[ow.mVertexId]) {
+                            weightAlreadyExists = true;
+                            break;
+                        }
+                    }
+                    if (weightAlreadyExists) {
+                        continue;
+                    }                    
                     aiVertexWeight nw;
                     aiVertexWeight nw;
                     nw.mVertexId = replaceIndex[ ow.mVertexId ];
                     nw.mVertexId = replaceIndex[ ow.mVertexId ];
                     nw.mWeight = ow.mWeight;
                     nw.mWeight = ow.mWeight;