diff options
author | Bastien Montagne <bastien@blender.org> | 2021-06-10 12:33:53 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-06-10 12:33:53 +0300 |
commit | 5304c6ed7d6288ac40bbc79391668c397e30afb8 (patch) | |
tree | bdbaa0b1b582b24c6961238e157b450b033929cc /source | |
parent | b669fd376afb19de313392e8f5cd8cf1915c2249 (diff) |
DataTransfer: Fix vertices being wrongly added to vgroup.
Previously, a vertex from destination mesh would always be added to all
transferred vgroup (with a 0.0 weight), even if none of its matching
sources in source mesh belonged to the matching source vgroups.
Now a destination vertex is only added to a given destination vgroup if
at least one of its source vertices belong to the matching source
vgroup.
Issue found and initial investigation by @pls in D11524, thanks!
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/deform.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 7832f3cd882..e6ef569d4b9 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -1130,11 +1130,13 @@ static void vgroups_datatransfer_interp(const CustomDataTransferLayerMap *laymap MDeformWeight *dw_dst = BKE_defvert_find_index(data_dst, idx_dst); float weight_src = 0.0f, weight_dst = 0.0f; + bool has_dw_sources = false; if (sources) { for (i = count; i--;) { for (j = data_src[i]->totweight; j--;) { if ((dw_src = &data_src[i]->dw[j])->def_nr == idx_src) { weight_src += dw_src->weight * weights[i]; + has_dw_sources = true; break; } } @@ -1152,7 +1154,14 @@ static void vgroups_datatransfer_interp(const CustomDataTransferLayerMap *laymap CLAMP(weight_src, 0.0f, 1.0f); - if (!dw_dst) { + /* Do not create a destination MDeformWeight data if we had no sources at all. */ + if (!has_dw_sources) { + BLI_assert(weight_src == 0.0f); + if (dw_dst) { + dw_dst->weight = weight_src; + } + } + else if (!dw_dst) { BKE_defvert_add_index_notest(data_dst, idx_dst, weight_src); } else { |