[Bf-blender-cvs] [ab320d1ef6b] temp-angavrilov-constraints: Weight Paint: avoid creating very small values with locked weights.

Alexander Gavrilov noreply at git.blender.org
Thu Dec 24 12:43:24 CET 2020


Commit: ab320d1ef6bf557171049704f7d4f84015fc9783
Author: Alexander Gavrilov
Date:   Thu Dec 24 14:30:51 2020 +0300
Branches: temp-angavrilov-constraints
https://developer.blender.org/rBab320d1ef6bf557171049704f7d4f84015fc9783

Weight Paint: avoid creating very small values with locked weights.

When painting using Auto-Normalize or Lock Relative with some
groups locked, the locked weights may not add up precisely to
1 because of precision limitations, which results in creating
nonzero weights close to FLT_EPSILON. With Lock Relative display
mode this is very obvious and annoying (random red points amid
black or blue), so add an epsilon check to consider less than
1e-6 unlocked weight to be the same as 0.

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

M	source/blender/blenkernel/BKE_deform.h
M	source/blender/blenkernel/intern/deform.c
M	source/blender/editors/sculpt_paint/paint_vertex.c

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

diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index 2f3ec69418f..5d581b695af 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -80,6 +80,9 @@ float BKE_defvert_multipaint_collective_weight(const struct MDeformVert *dv,
                                                int defbase_tot_sel,
                                                bool is_normalized);
 
+/* This much unlocked weight is considered equivalent to none. */
+#define VERTEX_WEIGHT_EPSILON 1e-6f
+
 float BKE_defvert_calc_lock_relative_weight(float weight,
                                             float locked_weight,
                                             float unlocked_weight);
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index f7cf4faf7cb..23a23013d3d 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -899,7 +899,7 @@ float BKE_defvert_calc_lock_relative_weight(float weight,
   }
 
   /* handle division by zero */
-  if (locked_weight >= 1.0f) {
+  if (locked_weight >= 1.0f - VERTEX_WEIGHT_EPSILON) {
     if (weight != 0.0f) {
       return 1.0f;
     }
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 9e9e0f441f7..04f6c03d1ae 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -415,7 +415,12 @@ static float wpaint_undo_lock_relative(
   /* In auto-normalize mode, or when there is no unlocked weight,
    * compute based on locked weight. */
   if (auto_normalize || free_weight <= 0.0f) {
-    weight *= (1.0f - locked_weight);
+    if (locked_weight < 1.0f - VERTEX_WEIGHT_EPSILON) {
+      weight *= (1.0f - locked_weight);
+    }
+    else {
+      weight = 0;
+    }
   }
   else {
     /* When dealing with full unlocked weight, don't paint, as it is always displayed as 1. */
@@ -518,7 +523,7 @@ static bool do_weight_paint_normalize_all_locked(MDeformVert *dvert,
     return false;
   }
 
-  if (lock_weight >= 1.0f) {
+  if (lock_weight >= 1.0f - VERTEX_WEIGHT_EPSILON) {
     /* locked groups make it impossible to fully normalize,
      * zero out what we can and return false */
     for (i = dvert->totweight, dw = dvert->dw; i != 0; i--, dw++) {



More information about the Bf-blender-cvs mailing list