[Bf-blender-cvs] [a273d3014ba] temp-gpencil-bezier-stroke-type: GPencil: Remove curve refitting in BKE geom update

Falk David noreply at git.blender.org
Fri Apr 30 19:31:04 CEST 2021


Commit: a273d3014bacb46a2d438c933ce53c66ebb7be35
Author: Falk David
Date:   Fri Apr 30 19:30:47 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rBa273d3014bacb46a2d438c933ce53c66ebb7be35

GPencil: Remove curve refitting in BKE geom update

Use (renamed) `BKE_gpencil_stroke_refit_curve` to do the refitting,
because passing the paramters of the fitting function through the `gpd`
was not a good solution. Now this function must be called before the
`BKE_gpencil_stroke_geometry_update` separately.

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

M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/BKE_gpencil_geom.h
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_sculpt_paint.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 0ba2c531da9..b4767b3fcfc 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -56,10 +56,10 @@ void BKE_gpencil_stroke_editcurve_regenerate_single(struct bGPDstroke *gps,
                                                     uint32_t start_idx,
                                                     uint32_t end_idx,
                                                     const float error_threshold);
-void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps,
-                                         const float threshold,
-                                         const float corner_angle,
-                                         const enum eGPStrokeGeoUpdateFlag flag);
+void BKE_gpencil_stroke_refit_curve(struct bGPDstroke *gps,
+                                    const float threshold,
+                                    const float corner_angle,
+                                    const enum eGPStrokeGeoUpdateFlag flag);
 void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPdata *gpd,
                                                  struct bGPDstroke *gps,
                                                  struct bGPDcurve *gpc);
diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index 22eea69477c..7c958460f8c 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -143,6 +143,7 @@ void BKE_gpencil_stroke_2d_flat_ref(const struct bGPDspoint *ref_points,
                                     const float scale,
                                     int *r_direction);
 void BKE_gpencil_stroke_fill_triangulate(struct bGPDstroke *gps);
+
 void BKE_gpencil_stroke_geometry_update(struct bGPdata *gpd,
                                         struct bGPDstroke *gps,
                                         const eGPStrokeGeoUpdateFlag flag);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 80120236dcf..1ab6a1283a5 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -1165,7 +1165,7 @@ void BKE_gpencil_stroke_editcurve_regenerate_single(bGPDstroke *gps,
  * be sharp (non-aligned handles).
  * \param flag: Flag for refitting options (see eGPStrokeGeoUpdateFlag).
  */
-void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps,
+void BKE_gpencil_stroke_refit_curve(bGPDstroke *gps,
                                          const float threshold,
                                          const float corner_angle,
                                          const eGPStrokeGeoUpdateFlag flag)
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 2cc2f47625b..0cd41f255ee 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1314,21 +1314,11 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *gpd,
   }
 
   /* Update curve points first if it's a bezier stroke. */
-  if (GPENCIL_STROKE_TYPE_BEZIER(gps)) {
-    /* Refit the curve to the polyline points. */
-    // TODO GPXX (These lines must be removed and moved to new function)
-    // if (GP_GEO_UPDATE_CURVE_REFIT_ANY(flag)) {
-    //  const float threshold = gpd->curve_edit_threshold;
-    //  const float corner_angle = gpd->curve_edit_corner_angle;
-    //  BKE_gpencil_stroke_editcurve_update(gps, threshold, corner_angle, flag);
-    //}
-
+  if (GPENCIL_STROKE_TYPE_BEZIER(gps) && GP_GEO_UPDATE_POLYLINE_REGENERATE_ANY(flag)) {
     /* Regenerate the polyline points from the curve data. */
-    if (GP_GEO_UPDATE_POLYLINE_REGENERATE_ANY(flag)) {
-      const uint resolution = gpd->curve_edit_resolution;
-      const bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
-      BKE_gpencil_stroke_update_geometry_from_editcurve(gps, resolution, is_adaptive, flag);
-    }
+    const uint resolution = gpd->curve_edit_resolution;
+    const bool is_adaptive = gpd->flag & GP_DATA_CURVE_ADAPTIVE_RESOLUTION;
+    BKE_gpencil_stroke_update_geometry_from_editcurve(gps, resolution, is_adaptive, flag);
   }
 
   /* Triangulate the stroke. */
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index 75a27f5dff1..925375d7103 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -172,7 +172,7 @@ static int gpencil_stroke_set_type_exec(bContext *C, wmOperator *op)
             continue;
           }
 
-          BKE_gpencil_stroke_editcurve_update(gps, threshold, corner_angle, GP_GEO_UPDATE_DEFAULT);
+          BKE_gpencil_stroke_refit_curve(gps, threshold, corner_angle, GP_GEO_UPDATE_DEFAULT);
           if (gps->editcurve != NULL) {
             bGPDcurve *gpc = gps->editcurve;
             BKE_gpencil_stroke_geometry_update(gpd, gps, GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL);
diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
index 53187f4d087..f8f739ae9fd 100644
--- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c
+++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c
@@ -54,6 +54,7 @@
 #include "BKE_context.h"
 #include "BKE_deform.h"
 #include "BKE_gpencil.h"
+#include "BKE_gpencil_curve.h"
 #include "BKE_gpencil_geom.h"
 #include "BKE_gpencil_modifier.h"
 #include "BKE_main.h"
@@ -96,6 +97,8 @@ typedef struct tGP_BrushEditData {
   ScrArea *area;
   ARegion *region;
 
+  ToolSettings *ts;
+
   /* Current GPencil datablock */
   bGPdata *gpd;
 
@@ -291,7 +294,7 @@ static void gpencil_recalc_geometry_tag(bGPDstroke *gps)
 }
 
 /* Recalc any stroke tagged. */
-static void gpencil_update_geometry(bGPdata *gpd)
+static void gpencil_update_geometry(bGPdata *gpd, ToolSettings *ts)
 {
   if (gpd == NULL) {
     return;
@@ -305,8 +308,11 @@ static void gpencil_update_geometry(bGPdata *gpd)
 
       LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
         if (gps->flag & GP_STROKE_TAG) {
-          BKE_gpencil_stroke_geometry_update(
-              gpd, gps, GP_GEO_UPDATE_CURVE_REFIT_ALL | GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL);
+          BKE_gpencil_stroke_refit_curve(gps,
+                                              ts->gpencil_curve_fit_threshold,
+                                              ts->gpencil_curve_fit_corner_angle,
+                                              GP_GEO_UPDATE_CURVE_REFIT_ALL);
+          BKE_gpencil_stroke_geometry_update(gpd, gps, GP_GEO_UPDATE_POLYLINE_REGENERATE_ALL);
           gps->flag &= ~GP_STROKE_TAG;
         }
       }
@@ -1162,6 +1168,7 @@ static bool gpencil_sculpt_brush_init(bContext *C, wmOperator *op)
   gso->bmain = CTX_data_main(C);
   /* store state */
   gso->settings = gpencil_sculpt_get_settings(scene);
+  gso->ts = ts;
 
   /* Random generator, only init once. */
   uint rng_seed = (uint)(PIL_check_seconds_timer_i() & UINT_MAX);
@@ -1305,7 +1312,7 @@ static void gpencil_sculpt_brush_exit(bContext *C, wmOperator *op)
   gso->brush->gpencil_settings->sculpt_flag &= ~GP_SCULPT_FLAG_TMP_INVERT;
 
   /* Update geometry data for tagged strokes. */
-  gpencil_update_geometry(gso->gpd);
+  gpencil_update_geometry(gso->gpd, gso->ts);
 
   /* free operator data */
   MEM_freeN(gso);



More information about the Bf-blender-cvs mailing list