[Bf-blender-cvs] [aaaef87fd2c] greasepencil-object: GPencil: Change Weight Paint to Blend values

Antonio Vazquez noreply at git.blender.org
Fri Feb 14 20:25:29 CET 2020


Commit: aaaef87fd2c49f7b6adee7e9f7fa40001d216d20
Author: Antonio Vazquez
Date:   Fri Feb 14 20:25:17 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBaaaef87fd2c49f7b6adee7e9f7fa40001d216d20

GPencil: Change Weight Paint to Blend values

Before, to substract weights it was necessary to press Ctrl key, but now the weight paint work equals to mesh weight paint blending weights and the Ctrl key is not used anymore.

This also allows to define the target weight easily.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
M	release/scripts/startup/bl_ui/properties_paint_common.py
M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/gpencil/gpencil_weight_paint.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index c55f115a9de..121e7f6e05e 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3577,8 +3577,6 @@ def km_grease_pencil_stroke_weight_draw(_params):
          # Draw
         ("gpencil.weight_paint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
          {"properties": [("wait_for_input", False)]}),
-        ("gpencil.weight_paint", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
-         {"properties": [("wait_for_input", False)]}),
     ])
 
     return keymap
diff --git a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
index 5be21a45aa0..ffda6d21379 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -2731,8 +2731,6 @@ def km_grease_pencil_stroke_weight_draw(_params):
     items.extend([
         ("gpencil.weight_paint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
          {"properties": [("wait_for_input", False)]}),
-        ("gpencil.weight_paint", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True},
-         {"properties": [("wait_for_input", False)]}),
     ])
 
     return keymap
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py b/release/scripts/startup/bl_ui/properties_paint_common.py
index 3a2bd94ce89..4e21c6cb06f 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -1122,7 +1122,7 @@ def brush_basic_gpencil_weight_settings(layout, _context, brush, *, compact=Fals
     row.prop(brush, "strength", slider=True)
     row.prop(brush, "use_pressure_strength", text="")
 
-    layout.prop(gp_settings, "weight", slider=True)
+    layout.prop(brush, "weight", slider=True)
 
 
 def brush_basic_gpencil_vertex_settings(layout, _context, brush, *, compact=False):
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 3cc11467f70..bc4875c50b9 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -294,9 +294,6 @@ void BKE_gpencil_brush_preset_set(Main *bmain, Brush *brush, const short type)
   brush->gpencil_settings->vertex_mode = GPPAINT_MODE_STROKE;
   brush->gpencil_settings->vertex_factor = 1.0f;
 
-  /* Set default weight. */
-  brush->gpencil_settings->weight = 1.0f;
-
   switch (type) {
     case GP_BRUSH_PRESET_AIRBRUSH: {
       brush->size = 300.0f;
diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c
index bbc442f467d..f629c84cb61 100644
--- a/source/blender/editors/gpencil/gpencil_weight_paint.c
+++ b/source/blender/editors/gpencil/gpencil_weight_paint.c
@@ -63,14 +63,6 @@
 /* General Brush Editing Context */
 #define GP_SELECT_BUFFER_CHUNK 256
 
-/* Temp Flags while Painting. */
-typedef enum eGPDweight_brush_Flag {
-  /* invert the effect of the brush */
-  GP_WEIGHT_FLAG_INVERT = (1 << 0),
-  /* temporary invert action */
-  GP_WEIGHT_FLAG_TMP_INVERT = (1 << 1),
-} eGPDweight_brush_Flag;
-
 /* Grid of Colors for Smear. */
 typedef struct tGP_Grid {
   /** Lower right corner of rectangle of grid cell. */
@@ -108,7 +100,6 @@ typedef struct tGP_BrushWeightpaintData {
   bGPdata *gpd;
 
   Brush *brush;
-  eGPDweight_brush_Flag flag;
 
   /* Space Conversion Data */
   GP_SpaceConversion gsc;
@@ -192,20 +183,6 @@ static tGP_Selected *gpencil_select_buffer_ensure(tGP_Selected *buffer_array,
 
 /* Brush Operations ------------------------------- */
 
-/* Invert behavior of brush? */
-static bool brush_invert_check(tGP_BrushWeightpaintData *gso)
-{
-  /* The basic setting is no inverted */
-  bool invert = false;
-
-  /* During runtime, the user can hold down the Ctrl key to invert the basic behavior */
-  if (gso->flag & GP_WEIGHT_FLAG_INVERT) {
-    invert ^= true;
-  }
-
-  return invert;
-}
-
 /* Compute strength of effect. */
 static float brush_influence_calc(tGP_BrushWeightpaintData *gso, const int radius, const int co[2])
 {
@@ -223,6 +200,7 @@ static float brush_influence_calc(tGP_BrushWeightpaintData *gso, const int radiu
   int mval_i[2];
   round_v2i_v2fl(mval_i, gso->mval);
   float distance = (float)len_v2v2_int(mval_i, co);
+  influence *= 1.0f - (distance / max_ff(radius, 1e-8));
 
   /* Apply Brush curve. */
   float brush_fallof = BKE_brush_curve_strength(brush, distance, (float)radius);
@@ -262,11 +240,8 @@ static bool brush_draw_apply(tGP_BrushWeightpaintData *gso,
   MDeformVert *dvert = gps->dvert + pt_index;
   float inf;
 
-  /* Compute strength of effect
-   * - We divide the strength by 10, so that users can set "sane" values.
-   *   Otherwise, good default values are in the range of 0.093
-   */
-  inf = brush_influence_calc(gso, radius, co) / 10.0f;
+  /* Compute strength of effect */
+  inf = brush_influence_calc(gso, radius, co);
 
   /* need a vertex group */
   if (gso->vrgroup == -1) {
@@ -282,25 +257,12 @@ static bool brush_draw_apply(tGP_BrushWeightpaintData *gso,
       return false;
     }
   }
-  /* get current weight */
+  /* Get current weight and blend. */
   MDeformWeight *dw = defvert_verify_index(dvert, gso->vrgroup);
-  float curweight = dw ? dw->weight : 0.0f;
-
-  if (brush_invert_check(gso)) {
-    curweight -= inf;
-  }
-  else {
-    /* increase weight */
-    curweight += inf;
-    /* verify maximum target weight */
-    CLAMP_MAX(curweight, gso->brush->weight);
-  }
-
-  CLAMP(curweight, 0.0f, 1.0f);
   if (dw) {
-    dw->weight = curweight;
+    dw->weight = interpf(dw->weight, gso->brush->weight, inf);
+    CLAMP(dw->weight, 0.0f, 1.0f);
   }
-
   return true;
 }
 
@@ -308,9 +270,7 @@ static bool brush_draw_apply(tGP_BrushWeightpaintData *gso,
 /* Header Info */
 static void gp_weightpaint_brush_header_set(bContext *C)
 {
-  ED_workspace_status_text(C,
-                           TIP_("GPencil Weight Paint: LMB to paint | RMB/Escape to Exit"
-                                " | Ctrl to Invert Action"));
+  ED_workspace_status_text(C, TIP_("GPencil Weight Paint: LMB to paint | RMB/Escape to Exit"));
 }
 
 /* ************************************************ */
@@ -388,9 +348,6 @@ static void gp_weightpaint_brush_exit(bContext *C, wmOperator *op)
   ED_workspace_status_text(C, NULL);
   ED_gpencil_toggle_brush_cursor(C, false, NULL);
 
-  /* Disable temp invert flag. */
-  gso->brush->flag &= ~GP_WEIGHT_FLAG_TMP_INVERT;
-
   /* Free operator data */
   MEM_SAFE_FREE(gso->pbuffer);
   MEM_SAFE_FREE(gso);
@@ -689,13 +646,6 @@ static void gp_weightpaint_brush_apply(bContext *C, wmOperator *op, PointerRNA *
 
   gso->pressure = RNA_float_get(itemptr, "pressure");
 
-  if (RNA_boolean_get(itemptr, "pen_flip")) {
-    gso->flag |= GP_WEIGHT_FLAG_INVERT;
-  }
-  else {
-    gso->flag &= ~GP_WEIGHT_FLAG_INVERT;
-  }
-
   /* Store coordinates as reference, if operator just started running */
   if (gso->first) {
     gso->mval_prev[0] = gso->mval[0];
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 7c353bf3b4a..f80193ce826 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -114,13 +114,11 @@ typedef struct BrushGpencilSettings {
 
   /** eGP_Sculpt_Flag. */
   int sculpt_flag;
-  /** Target weight. */
-  float weight;
   /** eGP_Sculpt_Mode_Flag. */
   int sculpt_mode_flag;
   /** Preset type (used to reset brushes - internal). */
   short preset_type;
-  char _pad3[2];
+  char _pad3[6];
 
   struct CurveMapping *curve_sensitivity;
   struct CurveMapping *curve_strength;
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index b9cad12cdc3..4cc99434e99 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1430,16 +1430,6 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Vertex Color Factor", "Factor used to mix vertex color to get final color");
 
-  /* Target Weight. */
-  prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_FACTOR);
-  RNA_def_property_range(prop, 0.0, 1.0);
-  RNA_def_property_ui_text(prop,
-                           "Weight",
-                           "Target weight (define a maximum range limit for the weight. Any value "
-                           "above will be clamped)");
-  RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-  RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL);
-
   /* Flags */
   prop = RNA_def_property(srna, "use_pressure", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_PRESSURE);



More information about the Bf-blender-cvs mailing list