[Bf-blender-cvs] [85a11fd2b31] soc-2020-greasepencil-curve: GPencil: Review of curve <> stroke conversion

Falk David noreply at git.blender.org
Fri Jul 3 17:21:33 CEST 2020


Commit: 85a11fd2b31275a74f092011a1e22016c5b1a379
Author: Falk David
Date:   Fri Jul 3 17:20:12 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB85a11fd2b31275a74f092011a1e22016c5b1a379

GPencil: Review of curve <> stroke conversion

This commit introduces a new flag GP_STROKE_NEEDS_CURVE_UPDATE in the stroke
that replaces GP_CURVE_RECALC_GEOMETRY. The name was not consistent and
it didn't make much sense to have it in the editcurve. Another flag was
added: GP_CURVE_NEEDS_STROKE_UPDATE. This indicates that the curve data
is dirty and needs to be regenerated.

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

M	source/blender/blenkernel/intern/gpencil_curve.c
M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/transform/transform_convert_gpencil.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 385123a71d8..0159ac836e5 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -528,7 +528,7 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
 }
 
 /**
- * Updates the editcurve for a stroke.
+ * Updates the editcurve for a stroke. Frees the old curve if one exists and generates a new one.
  */
 void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
 {
@@ -544,8 +544,7 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
   if (editcurve == NULL) {
     return;
   }
-  /* update the selection based on the selected points in the stroke */
-  BKE_gpencil_editcurve_stroke_sync_selection(gps, editcurve);
+
   gps->editcurve = editcurve;
 }
 
@@ -607,44 +606,6 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc
   }
 }
 
-/**
- * Update editcurve for all selected strokes.
- */
-void BKE_gpencil_selected_strokes_editcurve_update(bGPdata *gpd)
-{
-  if (gpd == NULL) {
-    return;
-  }
-
-  const bool is_multiedit = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd);
-
-  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
-    if (!BKE_gpencil_layer_is_editable(gpl)) {
-      continue;
-    }
-    bGPDframe *init_gpf = (is_multiedit) ? gpl->frames.first : gpl->actframe;
-    for (bGPDframe *gpf = init_gpf; gpf; gpf = gpf->next) {
-      if ((gpf == gpl->actframe) || ((gpf->flag & GP_FRAME_SELECT) && is_multiedit)) {
-        LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
-          /* skip deselected stroke */
-          if (!(gps->flag & GP_STROKE_SELECT)) {
-            continue;
-          }
-
-          if (gps->editcurve == NULL) {
-            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
-            if (gps->editcurve != NULL) {
-              gps->editcurve->resolution = gpd->editcurve_resolution;
-              gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
-            }
-          }
-          BKE_gpencil_stroke_geometry_update(gpd, gps);
-        }
-      }
-    }
-  }
-}
-
 static void gpencil_interpolate_fl_from_to(
     float from, float to, float *point_offset, int it, int stride)
 {
@@ -770,6 +731,7 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
     copy_v4_v4(pt->vert_color, &points[i][5]);
   }
 
+  /* free temp data */
   MEM_freeN(points);
 }
 
@@ -784,13 +746,19 @@ void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
 
   bool changed = false;
   bGPDcurve *gpc = gps->editcurve;
+  if (gpc->tot_curve_points < 1) {
+    return;
+  }
+
   for (int i = 0; i < gpc->tot_curve_points; i++) {
     bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
-    if (gpc_pt->flag & GP_CURVE_POINT_SELECT) {
-      bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
-      bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ? &gpc->curve_points[i + 1] :
-                                                                       NULL;
-
+    bGPDcurve_point *gpc_pt_prev = (i > 0) ? &gpc->curve_points[i - 1] : NULL;
+    bGPDcurve_point *gpc_pt_next = (i < gpc->tot_curve_points - 1) ? &gpc->curve_points[i + 1] :
+                                                                     NULL;
+    /* update handle if point or neighbour is selected */
+    if (gpc_pt->flag & GP_CURVE_POINT_SELECT ||
+        (gpc_pt_prev != NULL && gpc_pt_prev->flag & GP_CURVE_POINT_SELECT) ||
+        (gpc_pt_next != NULL && gpc_pt_next->flag & GP_CURVE_POINT_SELECT)) {
       BezTriple *bezt = &gpc_pt->bezt;
       BezTriple *bezt_prev = gpc_pt_prev != NULL ? &gpc_pt_prev->bezt : NULL;
       BezTriple *bezt_next = gpc_pt_next != NULL ? &gpc_pt_next->bezt : NULL;
@@ -801,7 +769,7 @@ void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
   }
 
   if (changed) {
-    gpc->flag |= GP_CURVE_RECALC_GEOMETRY;
+    gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
   }
 }
 
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 313699f3836..01c6c52cc12 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1210,15 +1210,15 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *gpd, bGPDstroke *gps)
 
   if (gps->editcurve != NULL) {
     if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
-      /* editcurve needs update */
-      if (gps->editcurve->flag & GP_CURVE_RECALC_GEOMETRY) {
+      /* curve geometry was updated: stroke needs recalculation */
+      if (gps->flag & GP_STROKE_NEEDS_CURVE_UPDATE) {
         BKE_gpencil_stroke_update_geometry_from_editcurve(gps);
-        gps->editcurve->flag &= ~GP_CURVE_RECALC_GEOMETRY;
+        gps->flag &= ~GP_STROKE_NEEDS_CURVE_UPDATE;
       }
     }
     else {
-      /* geometry was updated: editcurve needs recalculation */
-      gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+      /* stroke geometry was updated: editcurve needs recalculation */
+      gps->editcurve->flag |= GP_CURVE_NEEDS_STROKE_UPDATE;
     }
   }
 
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 6edc6009fac..748cc53e7e3 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -87,11 +87,12 @@ static int gpencil_stroke_enter_editcurve_mode(bContext *C, wmOperator *op)
       if (gpf == gpl->actframe) {
         LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
           /* only allow selected and non-converted strokes to be transformed */
-          if (gps->flag & GP_STROKE_SELECT && gps->editcurve == NULL) {
+          if (gps->flag & GP_STROKE_SELECT && gps->editcurve == NULL || 
+              (gps->editcurve != NULL && gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE)) {
             BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
             if (gps->editcurve != NULL) {
               gps->editcurve->resolution = gpd->editcurve_resolution;
-              gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+              gps->editcurve->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
             }
             BKE_gpencil_stroke_geometry_update(gpd, gps);
           }
@@ -165,8 +166,7 @@ static int gpencil_editcurve_set_handle_type_exec(bContext *C, wmOperator *op)
 
         BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, false, 0);
 
-        /* TODO: recalculate curve when handles change */
-        gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+        gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
         BKE_gpencil_stroke_geometry_update(gpd, gps);
       }
     }
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index fc359b697c1..e1732eeded0 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2667,11 +2667,11 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action, float error_thr
       bGPdata *gpd = ob->data;
       bool selected = false;
 
-      /* Make sure stroke has a curve */
+      /* Make sure stroke has an editcurve */
       if (gps->editcurve == NULL) {
         BKE_gpencil_stroke_editcurve_update(gps, error_threshold);
         gps->editcurve->resolution = gpd->editcurve_resolution;
-        gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+        gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
         BKE_gpencil_stroke_geometry_update(gpd, gps);
       }
 
diff --git a/source/blender/editors/transform/transform_convert_gpencil.c b/source/blender/editors/transform/transform_convert_gpencil.c
index 2009ac30b19..fb4569e284e 100644
--- a/source/blender/editors/transform/transform_convert_gpencil.c
+++ b/source/blender/editors/transform/transform_convert_gpencil.c
@@ -336,6 +336,7 @@ void createTransGPencil(bContext *C, TransInfo *t)
 
               /* save falloff factor */
               gps->runtime.multi_frame_falloff = falloff;
+
               if (is_curve_edit) {
                 createTransGPencil_curve_center_get(gpc, center);
 
@@ -352,8 +353,9 @@ void createTransGPencil(bContext *C, TransInfo *t)
                     BezTriple *bezt = &gpc_pt->bezt;
                     for (int j = 0; j < 3; j++) {
                       td->flag = 0;
-                      /* always do transform if control point is selected */
-                      if (bezt->f2 & SELECT || BEZT_ISSEL_IDX(bezt, j)) {
+                      /* always do transform if control point is selected or if proportional
+                       * editing is enabled. Otherwise only look at selected handles */
+                      if (bezt->f2 & SELECT || BEZT_ISSEL_IDX(bezt, j) || is_prop_edit) {
                         copy_v3_v3(td->iloc, bezt->vec[j]);
                         if ((gpc->flag & GP_CURVE_SELECT) &&
                             (ts->transform_pivot_point == V3D_AROUND_LOCAL_ORIGINS)) {
@@ -366,6 +368,7 @@ void createTransGPencil(bContext *C, TransInfo *t)
                         td->loc = bezt->vec[j];
                         td->flag |= TD_SELECTED;
 
+                        /* can only change thickness and strength if control point is selected */
                         if (j == 1) {
                           if (t->mode != TFM_MIRROR) {
                             if (t->mode != TFM_GPENCIL_OPACITY) {
@@ -513,7 +516,7 @@ void recalcData_gpencil_strokes(TransInfo *t)
     if ((gps != NULL) && (!BLI_ghash_haskey(strokes, gps))) {
       if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd) && gps->editcurve != NULL) {
         BKE_gpencil_editcurve_recalculate_handles(gps);
-        gps->editcurve->flag |= GP_CURVE_RECALC_GEOMETRY;
+        gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
       }
       /* Calc geometry data. */
       BKE_gpencil_stroke_geometry_update(gpd, gps);
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index f5833cd3a7e..57a01970904 100644
--- a/source/blender/makesdna/DNA_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list