[Bf-blender-cvs] [32660201aca] master: Fixes T84651: Weight paint gradient doesn't auto-normalize weights

Campbell Barton noreply at git.blender.org
Sat Feb 13 11:18:40 CET 2021


Commit: 32660201acaa1138c0fed6ef3fa38f69daa3dac3
Author: Campbell Barton
Date:   Sat Feb 13 21:13:27 2021 +1100
Branches: master
https://developer.blender.org/rB32660201acaa1138c0fed6ef3fa38f69daa3dac3

Fixes T84651: Weight paint gradient doesn't auto-normalize weights

Auto-normalize when the option is enabled.

Ref D10239 by @PratikPB2123 with minor edits.

===================================================================

M	source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c

===================================================================

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;
 }



More information about the Bf-blender-cvs mailing list