From a784a65dbe7d373de58f89e689dc5fbbb22cb164 Mon Sep 17 00:00:00 2001 From: Sietse Brouwer Date: Fri, 2 Jun 2023 15:04:19 +0200 Subject: [PATCH] Fix #108473: unreliable auto-normalize results when weight painting in GPencil Painting weights in Grease Pencil with the auto-normalize option enabled, gave unpredictable results when vertex groups with a weight of zero were involved. This patch resolves the issue. Vertex weights of zero are excluded from auto-normalization. Which is a better fit for the Grease Pencil workflow, where weights are mostly painted from scratch since the 'parent to armature with automatic weights' operator doesn't give good results. Pull Request: https://projects.blender.org/blender/blender/pulls/108524 --- .../editors/gpencil_legacy/gpencil_weight_paint.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/blender/editors/gpencil_legacy/gpencil_weight_paint.c b/source/blender/editors/gpencil_legacy/gpencil_weight_paint.c index fb800c33581..212914ad662 100644 --- a/source/blender/editors/gpencil_legacy/gpencil_weight_paint.c +++ b/source/blender/editors/gpencil_legacy/gpencil_weight_paint.c @@ -418,7 +418,8 @@ static bool do_weight_paint_normalize_all_unlocked(MDeformVert *dvert, dw = dvert->dw; for (int i = dvert->totweight; i != 0; i--, dw++) { - if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr]) { + /* Auto-normalize is only applied on bone-deformed vertex groups that have weight already. */ + if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr] && dw->weight > FLT_EPSILON) { sum += dw->weight; if (vgroup_locked[dw->def_nr] || (lock_active_vgroup && active_vgroup == dw->def_nr)) { @@ -460,7 +461,8 @@ static bool do_weight_paint_normalize_all_unlocked(MDeformVert *dvert, dw = dvert->dw; for (int i = dvert->totweight; i != 0; i--, dw++) { - if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr]) { + if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr] && dw->weight > FLT_EPSILON) + { if ((vgroup_locked[dw->def_nr] == false) && !(lock_active_vgroup && active_vgroup == dw->def_nr)) { dw->weight *= fac; @@ -475,7 +477,8 @@ static bool do_weight_paint_normalize_all_unlocked(MDeformVert *dvert, dw = dvert->dw; for (int i = dvert->totweight; i != 0; i--, dw++) { - if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr]) { + if (dw->def_nr < defbase_tot && vgroup_bone_deformed[dw->def_nr] && dw->weight > FLT_EPSILON) + { if ((vgroup_locked[dw->def_nr] == false) && !(lock_active_vgroup && active_vgroup == dw->def_nr)) { dw->weight = fac;