Commit: 8da22e5293c8b860fa65577e93ca37caee166fbc
Author: Antonio Vazquez
Date:   Sat Nov 9 17:45:49 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB8da22e5293c8b860fa65577e93ca37caee166fbc

GPencil: New Blur Tool for Vertex Paint

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

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       release/scripts/startup/bl_ui/space_view3d.py
M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/editors/gpencil/gpencil_vertex_paint.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py 
b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index c84d43c41ba..c4a82b80830 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3413,8 +3413,6 @@ def km_grease_pencil_stroke_vertex_blur(params):
         # Tint
         ("gpencil.vertex_paint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
          {"properties": [("wait_for_input", False)]}),
-        ("gpencil.vertex_paint", {"type": 'LEFTMOUSE', "value": 'PRESS', 
"ctrl": True},
-         {"properties": [("wait_for_input", False)]}),
         # Brush strength
         ("wm.radial_control", {"type": 'F', "value": 'PRESS', "shift": True},
          {"properties": [("data_path_primary", 
'tool_settings.gpencil_vertex_paint.brush.gpencil_settings.pen_strength')]}),
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 b9b3d6a6515..99d66729cad 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -2608,8 +2608,6 @@ def km_grease_pencil_stroke_vertex_blur(params):
         # Tint
         ("gpencil.vertex_paint", {"type": 'LEFTMOUSE', "value": 'PRESS'},
          {"properties": [("wait_for_input", False)]}),
-        ("gpencil.vertex_paint", {"type": 'LEFTMOUSE', "value": 'PRESS', 
"ctrl": True},
-         {"properties": [("wait_for_input", False)]}),
         # Brush strength
         ("wm.radial_control", {"type": 'F', "value": 'PRESS', "shift": True},
          {"properties": [("data_path_primary", 
'tool_settings.gpencil_vertex_paint.brush.gpencil_settings.pen_strength')]}),
diff --git a/release/scripts/startup/bl_ui/properties_paint_common.py 
b/release/scripts/startup/bl_ui/properties_paint_common.py
index 3d81662affe..e7b4a1c520a 100644
--- a/release/scripts/startup/bl_ui/properties_paint_common.py
+++ b/release/scripts/startup/bl_ui/properties_paint_common.py
@@ -505,7 +505,7 @@ def brush_basic_gpencil_vertex_settings(layout, _context, 
brush, tool, *, compac
     row.prop(brush, "size", text="Radius")
     row.prop(gp_settings, "use_pressure", text="", icon='STYLUS_PRESSURE')
 
-    if brush.gpencil_vertex_tool == 'DRAW':
+    if brush.gpencil_vertex_tool in ('DRAW', 'BLUR'):
         row = layout.row(align=True)
         row.prop(gp_settings, "pen_strength", slider=True)
         row.prop(gp_settings, "use_strength_pressure", text="", 
icon='STYLUS_PRESSURE')
diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index bb9c6ed3c9e..188a07feebb 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -432,7 +432,7 @@ class _draw_tool_settings_context_mode:
         settings = tool_settings.gpencil_vertex_paint
         row.template_ID_preview(settings, "brush", rows=3, cols=8, 
hide_buttons=True)
 
-        if brush.gpencil_vertex_tool != 'AVERAGE':
+        if brush.gpencil_vertex_tool not in ('BLUR', 'AVERAGE'):
             row.separator(factor=0.4)
             row.prop(brush, "color", text="")
         
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 262649e695f..395877e369b 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -2290,7 +2290,7 @@ class 
VIEW3D_PT_tools_grease_pencil_brush_vertex(View3DPanel, Panel):
         if ob is None or brush is None:
             return False
 
-        if context.region.type == 'TOOL_HEADER' or brush.gpencil_vertex_tool 
== 'AVERAGE':
+        if context.region.type == 'TOOL_HEADER' or brush.gpencil_vertex_tool 
in ('BLUR', 'AVERAGE'):
             return False
 
         return True
@@ -2370,7 +2370,7 @@ class 
VIEW3D_PT_tools_grease_pencil_brush_vertex_palette(View3DPanel, Panel):
         if ob is None or brush is None:
             return False
 
-        if brush.gpencil_vertex_tool == 'AVERAGE':
+        if brush.gpencil_vertex_tool in ('BLUR', 'AVERAGE'):
             return False
 
         return True
diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c 
b/source/blender/editors/gpencil/gpencil_vertex_paint.c
index d0b57cbced9..b02c85e6d0c 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -76,6 +76,8 @@ typedef struct tGP_selected {
   int pt_index;
   /** Position */
   int pc[2];
+  /** Color */
+  float color[4];
 } tGP_selected;
 
 /* Context for brush operators */
@@ -318,6 +320,78 @@ static bool brush_replace_apply(tGP_BrushVertexpaintData 
*gso,
   return true;
 }
 
+/* Get surrounding color. */
+static bool get_surrounding_color(tGP_BrushVertexpaintData *gso,
+                                  bGPDstroke *gps,
+                                  int pt_index,
+                                  float r_color[3])
+{
+  tGP_selected *selected = NULL;
+  bGPDstroke *gps_selected = NULL;
+  bGPDspoint *pt = NULL;
+
+  int totcol = 0;
+  zero_v3(r_color);
+
+  /* Average the surrounding points except current one. */
+  for (int i = 0; i < gso->pbuffer_used; i++) {
+    selected = &gso->pbuffer[i];
+    gps_selected = selected->gps;
+    /* current point is not evaluated. */
+    if ((gps_selected == gps) && (selected->pt_index == pt_index)) {
+      continue;
+    }
+
+    pt = &gps->points[selected->pt_index];
+
+    /* Add stroke mix color (only if used). */
+    if (pt->mix_color[3] > 0.0f) {
+      add_v3_v3(r_color, selected->color);
+      totcol++;
+    }
+  }
+  if (totcol > 0) {
+    mul_v3_fl(r_color, (1.0f / (float)totcol));
+    return true;
+  }
+
+  return false;
+}
+
+/* Blur Brush */
+static bool brush_blur_apply(tGP_BrushVertexpaintData *gso,
+                             bGPDstroke *gps,
+                             int pt_index,
+                             const int radius,
+                             const int co[2])
+{
+  Brush *brush = gso->brush;
+
+  /* Attenuate factor to get a smoother tinting. */
+  float inf = (brush_influence_calc(gso, radius, co) * 
brush->gpencil_settings->draw_strength) /
+              100.0f;
+  float inf_fill = (gso->pressure * brush->gpencil_settings->draw_strength) / 
1000.0f;
+
+  bGPDspoint *pt = &gps->points[pt_index];
+
+  /* Get surrounding color. */
+  float blur_color[3];
+  if (get_surrounding_color(gso, gps, pt_index, blur_color)) {
+    /* Apply color to Stroke point. */
+    if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) {
+      interp_v3_v3v3(pt->mix_color, pt->mix_color, blur_color, inf);
+    }
+
+    /* Apply color to Fill area (all with same color and factor). */
+    if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) {
+      interp_v3_v3v3(gps->mix_color_fill, gps->mix_color_fill, blur_color, 
inf_fill);
+    }
+    return true;
+  }
+
+  return false;
+}
+
 /* Average Brush */
 static bool brush_average_apply(tGP_BrushVertexpaintData *gso,
                                 bGPDstroke *gps,
@@ -327,8 +401,6 @@ static bool brush_average_apply(tGP_BrushVertexpaintData 
*gso,
                                 float average_color[3])
 {
   Brush *brush = gso->brush;
-  float final_color[3];
-  copy_v3_v3(final_color, average_color);
 
   /* Attenuate factor to get a smoother tinting. */
   float inf = (brush_influence_calc(gso, radius, co) * 
brush->gpencil_settings->draw_strength) /
@@ -352,14 +424,14 @@ static bool brush_average_apply(tGP_BrushVertexpaintData 
*gso,
   /* Apply color to Stroke point. */
   if (GPENCIL_TINT_VERTEX_COLOR_STROKE(brush)) {
     CLAMP(alpha, 0.0f, 1.0f);
-    interp_v3_v3v3(pt->mix_color, pt->mix_color, final_color, inf);
+    interp_v3_v3v3(pt->mix_color, pt->mix_color, average_color, inf);
     pt->mix_color[3] = alpha;
   }
 
   /* Apply color to Fill area (all with same color and factor). */
   if (GPENCIL_TINT_VERTEX_COLOR_FILL(brush)) {
     CLAMP(alpha_fill, 0.0f, 1.0f);
-    copy_v3_v3(gps->mix_color_fill, final_color);
+    copy_v3_v3(gps->mix_color_fill, average_color);
     gps->mix_color_fill[3] = alpha_fill;
   }
 
@@ -466,6 +538,8 @@ static void gp_save_selected_point(tGP_BrushVertexpaintData 
*gso,
                                    int pc[2])
 {
   tGP_selected *selected;
+  bGPDspoint *pt = &gps->points[index];
+
   /* Ensure the array to save the list of selected points is big enough. */
   gso->pbuffer = gpencil_select_buffer_ensure(
       gso->pbuffer, &gso->pbuffer_size, &gso->pbuffer_used, false);
@@ -474,6 +548,7 @@ static void gp_save_selected_point(tGP_BrushVertexpaintData 
*gso,
   selected->gps = gps;
   selected->pt_index = index;
   copy_v2_v2_int(selected->pc, pc);
+  copy_v4_v4(selected->color, pt->mix_color);
 
   gso->pbuffer_used++;
 }
@@ -683,8 +758,8 @@ static bool gp_vertexpaint_brush_do_frame(bContext *C,
         changed |= true;
         break;
       }
-      case GPVERTEX_TOOL_REPLACE: {
-        brush_replace_apply(gso, selected->gps, selected->pt_index, radius, 
selected->pc);
+      case GPVERTEX_TOOL_BLUR: {
+        brush_blur_apply(gso, selected->gps, selected->pt_index, radius, 
selected->pc);
         changed |= true;
         break;
       }
@@ -694,6 +769,11 @@ static bool gp_vertexpaint_brush_do_frame(bContext *C,
         changed |= true;
         break;
       }
+      case GPVERTEX_TOOL_REPLACE: {
+        brush_replace_apply(gso, selected->gps, selected->pt_index, radius, 
selected->pc);
+        changed |= true;
+        break;
+      }
 
       default:
         printf("ERROR: Unknown type of GPencil Vertex Paint brush\n");

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to