[Bf-blender-cvs] [a58c6a9cd93] greasepencil-object: GPencil: Make active Subdivide by pixel distance

Antonio Vazquez noreply at git.blender.org
Sun Aug 18 21:03:44 CEST 2019


Commit: a58c6a9cd9301bfd8c6bb331bf96f1570084f71c
Author: Antonio Vazquez
Date:   Sun Aug 18 21:03:37 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rBa58c6a9cd9301bfd8c6bb331bf96f1570084f71c

GPencil: Make active Subdivide by pixel distance

Now the subdivision is base on the distance in pixels between last two mouse positions.

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

M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 614a5233b7b..0e8d99cafdc 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -627,9 +627,6 @@ static void gp_subdivide_buffer(tGPsdata *p, int step)
     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;
 
@@ -637,6 +634,9 @@ static void gp_subdivide_buffer(tGPsdata *p, int step)
   gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure(
       gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false);
 
+  tGPspoint *pt_prev = ((tGPspoint *)(gpd->runtime.sbuffer) + idx - 1);
+  tGPspoint *pt_cur = ((tGPspoint *)(gpd->runtime.sbuffer) + idx);
+
   /* 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);
@@ -842,10 +842,20 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
     gpd->runtime.sbuffer_used++;
 
     /* 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);
+    if ((brush->gpencil_settings->active_subdivide > 0) && (gpd->runtime.sbuffer_used > 1)) {
+      const int idx = gpd->runtime.sbuffer_used - 1;
+      tGPspoint *pt_prev = ((tGPspoint *)(gpd->runtime.sbuffer) + idx - 1);
+      tGPspoint *pt_cur = ((tGPspoint *)(gpd->runtime.sbuffer) + idx);
+      /* Calc distance to determine how many subdivisions. */
+      float dist = len_v2v2(&pt_prev->x, &pt_cur->x);
+      const float segment_dist = GP_MAX_ACTIVE_SUBDIV - brush->gpencil_settings->active_subdivide +
+                                 1;
+      if (dist > segment_dist) {
+        float steps = (dist / segment_dist) + 1.0f;
+        CLAMP_MIN(steps, 1.0f);
+        gp_subdivide_buffer(p, (int)steps);
+      }
     }
-
     /* 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++) {
@@ -882,7 +892,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
       bGPDspoint *pts;
       MDeformVert *dvert = NULL;
 
-      /* first time point is adding to temporary buffer -- need to allocate new point in stroke */
+      /* first time point is adding to temporary buffer -- need to allocate new point in stroke
+       */
       if (gpd->runtime.sbuffer_used == 0) {
         gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
         if (gps->dvert != NULL) {
@@ -3230,7 +3241,8 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
   /* TODO: set any additional settings that we can take from the events?
    * TODO? if tablet is erasing, force eraser to be on? */
 
-  /* TODO: move cursor setting stuff to stroke-start so that paintmode can be changed midway... */
+  /* TODO: move cursor setting stuff to stroke-start so that paintmode can be changed midway...
+   */
 
   /* if eraser is on, draw radial aid */
   if (p->paintmode == GP_PAINTMODE_ERASER) {
@@ -3578,7 +3590,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
   }
 
   /* toggle painting mode upon mouse-button movement
-   * - LEFTMOUSE  = standard drawing (all) / straight line drawing (all) / polyline (toolbox only)
+   * - LEFTMOUSE  = standard drawing (all) / straight line drawing (all) / polyline (toolbox
+   * only)
    * - RIGHTMOUSE = polyline (hotkey) / eraser (all)
    *   (Disabling RIGHTMOUSE case here results in bugs like [#32647])
    * also making sure we have a valid event value, to not exit too early
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 0de7d8bdd16..16e79601301 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -37,6 +37,7 @@ struct MDeformVert;
 #define GP_DEFAULT_PIX_FACTOR 1.0f
 #define GP_DEFAULT_GRID_LINES 4
 #define GP_MAX_INPUT_SAMPLES 10
+#define GP_MAX_ACTIVE_SUBDIV 20
 
 /* ***************************************** */
 /* GP Stroke Points */
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index f9a14a50a32..67342df4161 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -1298,7 +1298,7 @@ static void rna_def_gpencil_options(BlenderRNA *brna)
   /* 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_range(prop, 0, GP_MAX_ACTIVE_SUBDIV);
   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);



More information about the Bf-blender-cvs mailing list