From 5304c6ed7d6288ac40bbc79391668c397e30afb8 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 10 Jun 2021 11:33:53 +0200 Subject: 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! --- source/blender/blenkernel/intern/deform.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/deform.c') 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 { -- cgit v1.2.3