[Bf-blender-cvs] [c40efe078f4] temp-gpencil-bezier-v2: GPencil: Fix compiler errors and change geom update

Falk David noreply at git.blender.org
Thu Jan 21 13:26:39 CET 2021


Commit: c40efe078f478ed6edc2b18ce27ca1a8f24c9d68
Author: Falk David
Date:   Thu Jan 21 13:25:29 2021 +0100
Branches: temp-gpencil-bezier-v2
https://developer.blender.org/rBc40efe078f478ed6edc2b18ce27ca1a8f24c9d68

GPencil: Fix compiler errors and change geom update

These changes are mainly to make blender compile.
The code that was commented out will be removed later.

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

M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 981f5d50353..3e1a096c231 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1290,19 +1290,25 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *gpd, bGPDstroke *gps)
     return;
   }
 
-  if (gps->editcurve != NULL) {
-    if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
-      /* curve geometry was updated: stroke needs recalculation */
-      if (gps->flag & GP_STROKE_NEEDS_CURVE_UPDATE) {
-        bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
-        BKE_gpencil_stroke_update_geometry_from_editcurve(
-            gps, gpd->curve_edit_resolution, is_adaptive);
-        gps->flag &= ~GP_STROKE_NEEDS_CURVE_UPDATE;
-      }
-    }
-    else {
-      /* stroke geometry was updated: editcurve needs recalculation */
-      gps->editcurve->flag |= GP_CURVE_NEEDS_STROKE_UPDATE;
+  /* If the stroke is a curve, update stroke points first. */
+  if (GPENCIL_STROKE_IS_CURVE(gps)) {
+
+    /* If the stroke geometry was updated, refit the curve.
+     * NOTE: Normally the stroke points of a curve should not be updated directly. Only if it is
+     * unavoidable. */
+    if (gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
+      BKE_gpencil_stroke_editcurve_update(
+          gps, gpd->curve_edit_threshold, gpd->curve_edit_corner_angle);
+      gps->editcurve->flag &= ~GP_CURVE_NEEDS_STROKE_UPDATE;
+      gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+    }
+
+    /* If curve geometry was updated, stroke points need recalculation. */
+    if (gps->flag & GP_STROKE_NEEDS_CURVE_UPDATE) {
+      bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
+      BKE_gpencil_stroke_update_geometry_from_editcurve(
+          gps, gpd->curve_edit_resolution, is_adaptive);
+      gps->flag &= ~GP_STROKE_NEEDS_CURVE_UPDATE;
     }
   }
 
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index b5269bbfacf..883d2ed8ec8 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -207,21 +207,21 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
     ob->mode = mode;
   }
 
-  /* Recalculate editcurves for strokes where the geometry/vertex colors have changed */
-  if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
-    GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
-    {
-      if (gpc->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
-        BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
-        /* Update the selection from the stroke to the curve. */
-        BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
-
-        gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
-        BKE_gpencil_stroke_geometry_update(gpd, gps);
-      }
-    }
-    GP_EDITABLE_CURVES_END(gps_iter);
-  }
+  // /* Recalculate editcurves for strokes where the geometry/vertex colors have changed */
+  // if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+  //   GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
+  //   {
+  //     if (gpc->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
+  //       BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
+  //       /* Update the selection from the stroke to the curve. */
+  //       BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+
+  //       gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+  //       BKE_gpencil_stroke_geometry_update(gpd, gps);
+  //     }
+  //   }
+  //   GP_EDITABLE_CURVES_END(gps_iter);
+  // }
 
   /* setup other modes */
   ED_gpencil_setup_modes(C, gpd, mode);
@@ -3784,14 +3784,14 @@ static int gpencil_strokes_reproject_exec(bContext *C, wmOperator *op)
 
       ED_gpencil_stroke_reproject(depsgraph, &gsc, sctx, gpl, gpf_, gps, mode, keep_original);
 
-      if (is_curve_edit && gps->editcurve != NULL) {
-        BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
-        /* Update the selection from the stroke to the curve. */
-        BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+      // if (is_curve_edit && gps->editcurve != NULL) {
+      //   BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
+      //   /* Update the selection from the stroke to the curve. */
+      //   BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
 
-        gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
-        BKE_gpencil_stroke_geometry_update(gpd, gps);
-      }
+      //   gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+      //   BKE_gpencil_stroke_geometry_update(gpd, gps);
+      // }
 
       changed = true;
     }
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 570a03b3808..a1777cbbe9f 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -154,6 +154,7 @@ static int gpencil_stroke_make_curve_exec(bContext *C, wmOperator *op)
         BKE_gpencil_stroke_editcurve_update(gps, threshold, corner_angle);
         if (gps->editcurve != NULL) {
           bGPDcurve *gpc = gps->editcurve;
+          gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
           BKE_gpencil_stroke_geometry_update(gpd, gps);
 
           /* Select all curve points. */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index a00d21bf88a..8e84b6e555c 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -156,31 +156,29 @@ static bool gpencil_3d_point_to_screen_space(ARegion *region,
 static void deselect_all_selected(bContext *C)
 {
   CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
-    /* deselect stroke and its points if selected */
-    if (gps->flag & GP_STROKE_SELECT) {
-      bGPDspoint *pt;
-      int i;
+    if (GPENCIL_STROKE_IS_CURVE(gps)) {
+      bGPDcurve *gpc = gps->editcurve;
 
-      /* deselect points */
-      for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
-        pt->flag &= ~GP_SPOINT_SELECT;
+      if(gpc->flag & GP_CURVE_SELECT) {
+        /* Deselect the curve points. */
+        for (uint32_t i = 0; i < gpc->tot_curve_points; i++) {
+          bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
+          BezTriple *bezt = &gpc_pt->bezt;
+          gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
+          BEZT_DESEL_ALL(bezt);
+        }
+        gpc->flag &= ~GP_CURVE_SELECT;
       }
-
-      /* deselect stroke itself too */
-      gps->flag &= ~GP_STROKE_SELECT;
     }
-
-    /* deselect curve and curve points */
-    if (gps->editcurve != NULL) {
-      bGPDcurve *gpc = gps->editcurve;
-      for (int j = 0; j < gpc->tot_curve_points; j++) {
-        bGPDcurve_point *gpc_pt = &gpc->curve_points[j];
-        BezTriple *bezt = &gpc_pt->bezt;
-        gpc_pt->flag &= ~GP_CURVE_POINT_SELECT;
-        BEZT_DESEL_ALL(bezt);
+    else {
+      if (gps->flag & GP_STROKE_SELECT) {
+        /* Deselect the points. */
+        for (uint32_t i = 0; i < gps->totpoints; i++) {
+          bGPDspoint *pt = &gps->points[i];
+          pt->flag &= ~GP_SPOINT_SELECT;
+        }
+        gps->flag &= ~GP_STROKE_SELECT;
       }
-
-      gpc->flag &= ~GP_CURVE_SELECT;
     }
   }
   CTX_DATA_END;
@@ -234,7 +232,6 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
 {
   bGPdata *gpd = ED_gpencil_data_get_active(C);
   int action = RNA_enum_get(op->ptr, "action");
-  const bool is_curve_edit = (bool)GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd);
 
   if (gpd == NULL) {
     BKE_report(op->reports, RPT_ERROR, "No Grease Pencil data");
@@ -254,12 +251,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
     }
   }
 
-  if (is_curve_edit) {
-    ED_gpencil_select_curve_toggle_all(C, action);
-  }
-  else {
-    ED_gpencil_select_toggle_all(C, action);
-  }
+  ED_gpencil_select_toggle_all(C, action);
 
   /* updates */
   DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
@@ -1309,7 +1301,7 @@ static bool gpencil_stroke_do_circle_sel(bGPdata *gpd,
 
   /* If curve edit mode, generate the curve. */
   if (is_curve_edit && hit && gps_active->editcurve == NULL) {
-    BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps_active);
+    // BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps_active);
     gps_active->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
     /* Select all curve points. */
     select_all_curve_points(gps_active, gps_active->editcurve, false);
@@ -1886,7 +1878,7 @@ static bool gpencil_generic_stroke_select(bContext *C,
 
     /* If curve edit mode, generate the curve. */
     if (is_curve_edit && (hit || whole) && gps_active->editcurve == NULL) {
-      BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps_active);
+      // BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps_active);
       gps_active->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
       /* Select all curve points. */
       select_all_curve_points(gps_active, gps_active->editcurve, false);
@@ -2304,7 +2296,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
   if (whole) {
     /* Generate editcurve if it does not exist */
     if (is_curve_edit && hit_curve == NULL) {
-      BKE_gpencil_stroke_editcurve_update(gpd, hit_layer, hit_stroke);
+      // BKE_gpencil_stroke_editcurve_update(gpd, hit_layer, hit_stroke);
       hit_stroke->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
       BKE_gpencil_stroke_geometry_update(gpd, hit_stroke);
       hit_curve = hit_stroke->editcurve;
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 42e3055ef65..f01330104f5 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2569,9 +2569,18 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
     action = SEL_SELECT;
 
     CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
-      if (gps->flag & GP_STROKE_SELECT) {
-        action = SEL_DESELECT;
-        break; /* XXX: this only gets out of the inner loop. */
+      if (GPENCIL_STROKE_IS_CURVE(gps)) {
+        bGPDcurve *gpc = gps->edit

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list