[Bf-blender-cvs] [50017dcfcb4] greasepencil-object: GPencil: First steps for the new Smear tool

Antonio Vazquez noreply at git.blender.org
Mon Nov 11 10:18:42 CET 2019


Commit: 50017dcfcb4fd6baae40bbac03aad56b26b13913
Author: Antonio Vazquez
Date:   Sun Nov 10 17:39:37 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB50017dcfcb4fd6baae40bbac03aad56b26b13913

GPencil: First steps for the new Smear tool

Note: Still not working.

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

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
M	source/blender/makesdna/DNA_brush_types.h

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index c4a82b80830..54258202086 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3461,8 +3461,6 @@ def km_grease_pencil_stroke_vertex_smear(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 99d66729cad..8d8faa829f7 100644
--- a/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
+++ b/release/scripts/presets/keyconfig/keymap_data/industry_compatible_data.py
@@ -2656,8 +2656,6 @@ def km_grease_pencil_stroke_vertex_smear(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 e7b4a1c520a..fac1cec9b2a 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 in ('DRAW', 'BLUR'):
+    if brush.gpencil_vertex_tool in ('DRAW', 'BLUR', 'SMEAR'):
         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 188a07feebb..180721511b5 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 not in ('BLUR', 'AVERAGE'):
+        if brush.gpencil_vertex_tool not in ('BLUR', 'AVERAGE', 'SMEAR'):
             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 395877e369b..bfcaf894d4f 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 in ('BLUR', 'AVERAGE'):
+        if context.region.type == 'TOOL_HEADER' or brush.gpencil_vertex_tool in ('BLUR', 'AVERAGE', 'SMEAR'):
             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 in ('BLUR', 'AVERAGE'):
+        if brush.gpencil_vertex_tool in ('BLUR', 'AVERAGE', 'SMEAR'):
             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 b02c85e6d0c..6ac611194e7 100644
--- a/source/blender/editors/gpencil/gpencil_vertex_paint.c
+++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c
@@ -59,6 +59,7 @@
 /* ************************************************ */
 /* General Brush Editing Context */
 #define GP_SELECT_BUFFER_CHUNK 256
+#define GP_GRID_PIXEL_SIZE 10.0f
 
 /* Temp Flags while Painting. */
 typedef enum eGPDvertex_brush_Flag {
@@ -68,8 +69,25 @@ typedef enum eGPDvertex_brush_Flag {
   GP_VERTEX_FLAG_TMP_INVERT = (1 << 1),
 } eGPDvertex_brush_Flag;
 
+/* Grid of Colors for Smear. */
+typedef struct tGP_Grid {
+  /** Lower right corner of rectangle of grid cell. */
+  float bottom_a[2];
+  /** Lower left corner of rectangle of grid cell. */
+  float bottom_b[2];
+  /** Upper right corner of rectangle of grid cell. */
+  float top_a[2];
+  /** Upper left corner of rectangle of grid cell. */
+  float top_b[2];
+  /** Average Color */
+  float color[4];
+  /** Total points included. */
+  int totcol;
+
+} tGP_Grid;
+
 /* List of points affected by brush. */
-typedef struct tGP_selected {
+typedef struct tGP_Selected {
   /** Referenced stroke. */
   bGPDstroke *gps;
   /** Point index in points array. */
@@ -78,7 +96,7 @@ typedef struct tGP_selected {
   int pc[2];
   /** Color */
   float color[4];
-} tGP_selected;
+} tGP_Selected;
 
 /* Context for brush operators */
 typedef struct tGP_BrushVertexpaintData {
@@ -114,8 +132,10 @@ typedef struct tGP_BrushVertexpaintData {
   float mval[2], mval_prev[2];
   float pressure, pressure_prev;
 
-  /* - effect vector */
-  float dvec[3];
+  /* - Effect 2D vector */
+  float dvec[2];
+  /* Angle relative to Down 2D vector (0, -1} vector */
+  float angle;
 
   /* - multiframe falloff factor */
   float mf_falloff;
@@ -125,33 +145,42 @@ typedef struct tGP_BrushVertexpaintData {
 
   /* Temp data to save selected points */
   /** Stroke buffer. */
-  tGP_selected *pbuffer;
+  tGP_Selected *pbuffer;
   /** Number of elements currently used in cache. */
   int pbuffer_used;
   /** Number of total elements available in cache. */
   int pbuffer_size;
 
+  /** Grid of average colors */
+  tGP_Grid *grid;
+  /** Total number of rows. */
+  int grid_row;
+  /** Total number of cells in the grid. */
+  int grid_size;
+  /** Grid is ready to use */
+  bool grid_ready;
+
 } tGP_BrushVertexpaintData;
 
 /* Ensure the buffer to hold temp selected point size is enough to save all points selected. */
-static tGP_selected *gpencil_select_buffer_ensure(tGP_selected *buffer_array,
+static tGP_Selected *gpencil_select_buffer_ensure(tGP_Selected *buffer_array,
                                                   int *buffer_size,
                                                   int *buffer_used,
                                                   const bool clear)
 {
-  tGP_selected *p = NULL;
+  tGP_Selected *p = NULL;
 
   /* By default a buffer is created with one block with a predefined number of free slots,
    * if the size is not enough, the cache is reallocated adding a new block of free slots.
    * This is done in order to keep cache small and improve speed. */
   if (*buffer_used + 1 > *buffer_size) {
     if ((*buffer_size == 0) || (buffer_array == NULL)) {
-      p = MEM_callocN(sizeof(struct tGP_selected) * GP_SELECT_BUFFER_CHUNK, __func__);
+      p = MEM_callocN(sizeof(struct tGP_Selected) * GP_SELECT_BUFFER_CHUNK, __func__);
       *buffer_size = GP_SELECT_BUFFER_CHUNK;
     }
     else {
       *buffer_size += GP_SELECT_BUFFER_CHUNK;
-      p = MEM_recallocN(buffer_array, sizeof(struct tGP_selected) * *buffer_size);
+      p = MEM_recallocN(buffer_array, sizeof(struct tGP_Selected) * *buffer_size);
     }
 
     if (p == NULL) {
@@ -165,7 +194,7 @@ static tGP_selected *gpencil_select_buffer_ensure(tGP_selected *buffer_array,
   if (clear) {
     *buffer_used = 0;
     if (buffer_array != NULL) {
-      memset(buffer_array, 0, sizeof(tGP_selected) * *buffer_size);
+      memset(buffer_array, 0, sizeof(tGP_Selected) * *buffer_size);
     }
   }
 
@@ -223,20 +252,162 @@ static float brush_influence_calc(tGP_BrushVertexpaintData *gso, const int radiu
 }
 
 /* Compute effect vector for directional brushes. */
-static void brush_grab_calc_dvec(tGP_BrushVertexpaintData *gso)
+static void brush_calc_dvec_2d(tGP_BrushVertexpaintData *gso)
+{
+  const float vaxis[2] = {0.0f, -1.0f};
+
+  gso->dvec[0] = (float)(gso->mval[0] - gso->mval_prev[0]);
+  gso->dvec[1] = (float)(gso->mval[1] - gso->mval_prev[1]);
+
+  normalize_v2(gso->dvec);
+  gso->angle = angle_signed_v2v2(vaxis, gso->dvec);
+}
+
+/* Init a grid of cells around mouse position.
+ *
+ * For each Cell.
+ *
+ *      Top A *--------* Top B
+ *            |        |
+ *            |        |
+ *   Bottom A *--------* Bottom B
+ *
+ * The cell is rotated using the relative angle of the movement of the mouse.
+ * The number of cells is calculated using the brush size and a predefined
+ * number of pixels (see: GP_GRID_PIXEL_SIZE)
+ */
+
+static void gp_grid_init(tGP_BrushVertexpaintData *gso)
+{
+  tGP_Grid *grid;
+  float bottom_a[2], bottom_b[2];
+  float top_a[2], top_b[2];
+  int grid_index = 0;
+
+  bottom_a[0] = gso->brush_rect.xmin;
+  bottom_a[1] = gso->brush_rect.ymax - GP_GRID_PIXEL_SIZE;
+
+  /* Calc all cell of the grid from top/left. */
+  for (int y = gso->grid_row - 1; y >= 0; y--) {
+    bottom_b[1] = bottom_a[1];
+    top_a[1] = bottom_a[1] + GP_GRID_PIXEL_SIZE;
+    top_b[1] = top_a[1];
+    for (int x = 0; x < gso->grid_row; x++) {
+      bottom_b[0] = bottom_a[0] + GP_GRID_PIXEL_SIZE;
+      top_a[0] = bottom_a[0];
+      top_b[0] = bottom_b[0];
+
+      grid = &gso->grid[grid_index];
+
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list