[Bf-blender-cvs] [acb875be38f] greasepencil-object: GPencil: New Active Subdivide for Brushes

Antonio Vazquez noreply at git.blender.org
Sun Aug 18 17:50:41 CEST 2019


Commit: acb875be38f9db3260d84f25d1d0f44fc41bb454
Author: Antonio Vazquez
Date:   Sun Aug 18 17:50:32 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBacb875be38f9db3260d84f25d1d0f44fc41bb454

GPencil: New Active Subdivide for Brushes

This new option subdivide the last stroke segment while drawing.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 2c46d4357e0..e904773f95b 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1832,6 +1832,7 @@ class VIEW3D_PT_tools_grease_pencil_brush_option(View3DPanel, Panel):
             col.separator()
 
             col.prop(gp_settings, "active_smooth_factor")
+            col.prop(gp_settings, "active_subdivide_steps")
             col.separator()
 
             col.prop(gp_settings, "angle", slider=True)
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 84477599f6a..614a5233b7b 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -612,6 +612,54 @@ static void gp_smooth_buffer(tGPsdata *p, float inf, int idx)
   ptc->pressure = interpf(ptc->pressure, pressure, inf);
 }
 
+/* Apply subdivide to buffer while drawing
+ *
+ * \param p: Temp data
+ * \param step: Number of steps
+ */
+static void gp_subdivide_buffer(tGPsdata *p, int step)
+{
+  bGPdata *gpd = p->gpd;
+  const int idx = gpd->runtime.sbuffer_used - 1;
+
+  /* Do nothing if not enough points to subdivide out */
+  if (gpd->runtime.sbuffer_used < 2) {
+    return;
+  }
+
+  tGPspoint *pt_prev = ((tGPspoint *)(gpd->runtime.sbuffer) + idx - 1);
+  tGPspoint *pt_cur = ((tGPspoint *)(gpd->runtime.sbuffer) + idx);
+
+  /* Increase used points. */
+  gpd->runtime.sbuffer_used += step;
+
+  /* check if still room in buffer or add more */
+  gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
+      gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
+
+  /* Copy values of current point to last point. */
+  tGPspoint *pt_last = ((tGPspoint *)(gpd->runtime.sbuffer) + idx + step);
+  copy_v2_v2(&pt_last->x, &pt_cur->x);
+  pt_last->pressure = pt_cur->pressure;
+  pt_last->strength = pt_cur->strength;
+  pt_last->time = pt_cur->time;
+  pt_last->uv_fac = pt_cur->uv_fac;
+  pt_last->uv_rot = pt_cur->uv_fac;
+
+  /* Interpolate points in the midle. */
+  float const ifactor = 1.0f / (float)(step + 1);
+  for (int i = 0; i < step; i++) {
+    pt_cur = ((tGPspoint *)(gpd->runtime.sbuffer) + idx + i);
+    float f = ifactor * (i + 1);
+    interp_v2_v2v2(&pt_cur->x, &pt_prev->x, &pt_last->x, f);
+    pt_cur->pressure = interpf(pt_prev->pressure, pt_last->pressure, f);
+    pt_cur->strength = interpf(pt_prev->strength, pt_last->strength, f);
+    pt_cur->time = interpf(pt_prev->time, pt_last->time, f);
+    pt_cur->uv_fac = interpf(pt_prev->uv_fac, pt_last->uv_fac, f);
+    pt_cur->uv_rot = interpf(pt_prev->uv_rot, pt_last->uv_rot, f);
+  }
+}
+
 /* add current stroke-point to buffer (returns whether point was successfully added) */
 static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure, double curtime)
 {
@@ -793,7 +841,12 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
     /* increment counters */
     gpd->runtime.sbuffer_used++;
 
-    /* smooth while drawing previous points with a reduction factor for previous */
+    /* Subdivide while drawing two last points (current and previous). */
+    if (brush->gpencil_settings->active_subdivide > 0) {
+      gp_subdivide_buffer(p, brush->gpencil_settings->active_subdivide);
+    }
+
+    /* Smooth while drawing previous points with a reduction factor for previous. */
     if (brush->gpencil_settings->active_smooth > 0.0f) {
       for (int s = 0; s < 3; s++) {
         gp_smooth_buffer(p,
diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h
index 4327c28ba69..f259df82d97 100644
--- a/source/blender/makesdna/DNA_brush_types.h
+++ b/source/blender/makesdna/DNA_brush_types.h
@@ -83,7 +83,8 @@ typedef struct BrushGpencilSettings {
   short fill_leak;
   /** Fill zoom factor */
   short fill_factor;
-  char _pad_1[4];
+  /** Subdivide while drawing factor. */
+  int active_subdivide;
 
   /** Number of simplify steps. */
   int fill_simplylvl;
@@ -486,7 +487,7 @@ typedef enum eBrushUVSculptTool {
         SCULPT_TOOL_THUMB, \
         SCULPT_TOOL_LAYER, \
 \
-        /* These brushes could handle dynamic topology, \ \
+        /* These brushes could handle dynamic topology, \ \ \
          * but user feedback indicates it's better not to */ \
         SCULPT_TOOL_SMOOTH, \
         SCULPT_TOOL_MASK) == 0)
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index ee439147956..f9a14a50a32 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1291,7 +1291,15 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   prop = RNA_def_property(srna, "active_smooth_factor", PROP_FLOAT, PROP_FACTOR);
   RNA_def_property_float_sdna(prop, NULL, "active_smooth");
   RNA_def_property_range(prop, 0.0f, 1.0f);
-  RNA_def_property_ui_text(prop, "Active Smooth", "Amount of smoothing while drawing ");
+  RNA_def_property_ui_text(prop, "Active Smooth", "Amount of smoothing while drawing");
+  RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+  RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
+
+  /* active subdivide factor while drawing */
+  prop = RNA_def_property(srna, "active_subdivide_steps", PROP_INT, PROP_FACTOR);
+  RNA_def_property_int_sdna(prop, NULL, "active_subdivide");
+  RNA_def_property_range(prop, 0, 20);
+  RNA_def_property_ui_text(prop, "Active Subdivide", "Amount of subdividing while drawing");
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
   RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
@@ -1299,7 +1307,7 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   RNA_def_property_float_sdna(prop, NULL, "era_strength_f");
   RNA_def_property_range(prop, 0.0, 100.0);
   RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
-  RNA_def_property_ui_text(prop, "Affect Stroke Strength", "Amount of erasing for strength ");
+  RNA_def_property_ui_text(prop, "Affect Stroke Strength", "Amount of erasing for strength");
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
   RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);
 
@@ -1307,7 +1315,7 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   RNA_def_property_float_sdna(prop, NULL, "era_thickness_f");
   RNA_def_property_range(prop, 0.0, 100.0);
   RNA_def_property_ui_range(prop, 0.0, 100.0, 10, 1);
-  RNA_def_property_ui_text(prop, "Affect Stroke Thickness", "Amount of erasing for thickness ");
+  RNA_def_property_ui_text(prop, "Affect Stroke Thickness", "Amount of erasing for thickness");
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
   RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL);



More information about the Bf-blender-cvs mailing list