Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-02-13 13:13:27 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-02-13 13:17:35 +0300
commit32660201acaa1138c0fed6ef3fa38f69daa3dac3 (patch)
tree2b92f11ab29b2373ee02bc2acd22657c0297b488 /source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
parent376eedae164f1ad3dde0b091f6f85f2936ff51ad (diff)
Fixes T84651: Weight paint gradient doesn't auto-normalize weights
Auto-normalize when the option is enabled. Ref D10239 by @PratikPB2123 with minor edits.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c')
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
index 8fd5759d695..8277b485578 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
@@ -573,6 +573,7 @@ typedef struct WPGradient_vertStore {
enum {
VGRAD_STORE_NOP = 0,
VGRAD_STORE_DW_EXIST = (1 << 0),
+ VGRAD_STORE_IS_MODIFIED = (1 << 1)
} flag;
} WPGradient_vertStore;
@@ -609,6 +610,8 @@ static void gradientVert_update(WPGradient_userData *grad_data, int index)
/* Optionally restrict to assigned vertices only. */
if (grad_data->use_vgroup_restrict && ((vs->flag & VGRAD_STORE_DW_EXIST) == 0)) {
+ /* In this case the vertex will never have been touched. */
+ BLI_assert((vs->flag & VGRAD_STORE_IS_MODIFIED) == 0);
return;
}
@@ -637,6 +640,7 @@ static void gradientVert_update(WPGradient_userData *grad_data, int index)
tool, vs->weight_orig, grad_data->weightpaint, alpha * grad_data->brush->alpha);
CLAMP(testw, 0.0f, 1.0f);
dw->weight = testw;
+ vs->flag |= VGRAD_STORE_IS_MODIFIED;
}
else {
MDeformVert *dv = &me->dvert[index];
@@ -652,6 +656,7 @@ static void gradientVert_update(WPGradient_userData *grad_data, int index)
BKE_defvert_remove_group(dv, dw);
}
}
+ vs->flag &= ~VGRAD_STORE_IS_MODIFIED;
}
}
@@ -856,6 +861,20 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op)
MEM_freeN(vert_cache);
}
+ if (scene->toolsettings->auto_normalize) {
+ const int vgroup_num = BLI_listbase_count(&ob->defbase);
+ bool *vgroup_validmap = BKE_object_defgroup_validmap_get(ob, vgroup_num);
+ if (vgroup_validmap != NULL) {
+ MDeformVert *dvert = me->dvert;
+ for (int i = 0; i < me->totvert; i++) {
+ if ((data.vert_cache->elem[i].flag & VGRAD_STORE_IS_MODIFIED) != 0) {
+ BKE_defvert_normalize_lock_single(&dvert[i], vgroup_validmap, vgroup_num, data.def_nr);
+ }
+ }
+ MEM_freeN(vgroup_validmap);
+ }
+ }
+
return OPERATOR_FINISHED;
}