[Bf-blender-cvs] [2967da622b5] temp-gpencil-bezier-stroke-type: GPencil: WIP geometry update flag

Falk David noreply at git.blender.org
Tue Apr 13 11:29:20 CEST 2021


Commit: 2967da622b533c7220564ca187c1fd813ae32e56
Author: Falk David
Date:   Tue Apr 13 11:28:56 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB2967da622b533c7220564ca187c1fd813ae32e56

GPencil: WIP geometry update flag

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

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

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

diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index bb3247d489c..15471286094 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -67,7 +67,8 @@ void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPdata *gpd,
                                                  struct bGPDcurve *gpc);
 void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps,
                                                        const uint resolution,
-                                                       const bool is_adaptive);
+                                                       const bool is_adaptive,
+                                                       const eGPStrokeGeoUpdateFlag flag);
 void BKE_gpencil_editcurve_recalculate_handles(struct bGPDstroke *gps);
 void BKE_gpencil_editcurve_subdivide(struct bGPDstroke *gps, const int cuts);
 void BKE_gpencil_editcurve_simplify_adaptive(struct bGPDstroke *gps, const float threshold);
diff --git a/source/blender/blenkernel/BKE_gpencil_geom.h b/source/blender/blenkernel/BKE_gpencil_geom.h
index a9bd0a524c4..82a6283a20c 100644
--- a/source/blender/blenkernel/BKE_gpencil_geom.h
+++ b/source/blender/blenkernel/BKE_gpencil_geom.h
@@ -38,6 +38,37 @@ struct bGPDspoint;
 struct bGPDstroke;
 struct bGPdata;
 
+typedef enum eGPStrokeGeoUpdateFlag {
+  /* Default geometry update. Triangulate the stroke, update UVs and bounding box. If the stroke
+     type is bezier, regenerate the polyline first. */
+  GP_GEO_UPDATE_DEFAULT = 0,
+  /* Refit the curve point positions. */
+  GP_GEO_UPDATE_CURVE_REFIT_POSITION = (1 << 1),
+  /* Refit the curve point pressures. */
+  GP_GEO_UPDATE_CURVE_REFIT_PRESSURE = (1 << 2),
+  /* Refit the curve point strengths. */
+  GP_GEO_UPDATE_CURVE_REFIT_STRENGTH = (1 << 3),
+  /* Refit the curve point vertex colors. */
+  GP_GEO_UPDATE_CURVE_REFIT_COLOR = (1 << 4),
+  /* Refit the curve point weights. */
+  GP_GEO_UPDATE_CURVE_REFIT_WEIGHT = (1 << 5),
+  /* Do a partial refit. Uses the `GP_SPOINT_TAG` point flag to determin what curve segments need
+     to be refitted. */
+  GP_GEO_UPDATE_CURVE_PARTIAL_REFIT = (1 << 6),
+
+  /* Add additional flags here: (1 << 7), (2 << 7), ... */
+  /* GP_GEO_UPDATE_XXX = (1 << 7), */
+} eGPStrokeGeoUpdateFlag;
+
+/* Refit all attributes. */
+#define GP_GEO_UPDATE_CURVE_REFIT_ALL \
+  (GP_GEO_UPDATE_CURVE_REFIT_POSITION | GP_GEO_UPDATE_CURVE_REFIT_PRESSURE | \
+   GP_GEO_UPDATE_CURVE_REFIT_STRENGTH | GP_GEO_UPDATE_CURVE_REFIT_COLOR | \
+   GP_GEO_UPDATE_CURVE_REFIT_WEIGHT)
+
+/* Check if any curve refitting is done. */
+#define GP_GEO_UPDATE_CURVE_REFIT_ANY(flag) (flag & GP_GEO_UPDATE_CURVE_REFIT_ALL)
+
 /* Object boundbox. */
 bool BKE_gpencil_data_minmax(const struct bGPdata *gpd, float r_min[3], float r_max[3]);
 bool BKE_gpencil_stroke_minmax(const struct bGPDstroke *gps,
@@ -78,7 +109,9 @@ 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);
+void BKE_gpencil_stroke_geometry_update(struct bGPdata *gpd,
+                                        struct bGPDstroke *gps,
+                                        const eGPStrokeGeoUpdateFlag flag);
 void BKE_gpencil_stroke_uv_update(struct bGPDstroke *gps);
 
 void BKE_gpencil_transform(struct bGPdata *gpd, const float mat[4][4]);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index b0a7e2c99d1..984eaae3b1a 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -1469,7 +1469,8 @@ static float *gpencil_stroke_points_from_editcurve_fixed_resolu(bGPDcurve_point
  */
 void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
                                                        const uint resolution,
-                                                       const bool adaptive)
+                                                       const bool adaptive,
+                                                       const eGPStrokeGeoUpdateFlag flag)
 {
   if (gps == NULL || gps->editcurve == NULL) {
     return;
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 59fa97ad062..121a0703c7a 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -1286,35 +1286,30 @@ void BKE_gpencil_stroke_uv_update(bGPDstroke *gps)
  * \param gpd: Grease pencil data-block
  * \param gps: Grease pencil stroke
  */
-void BKE_gpencil_stroke_geometry_update(bGPdata *gpd, bGPDstroke *gps)
+void BKE_gpencil_stroke_geometry_update(bGPdata *gpd,
+                                        bGPDstroke *gps,
+                                        const eGPStrokeGeoUpdateFlag flag)
 {
   if (gps == NULL) {
     return;
   }
 
-  /* Update stroke points first if it's a bezier stroke. */
+  /* Update curve points first if it's a bezier stroke. */
   if (GPENCIL_STROKE_TYPE_BEZIER(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. Sculpting bezier strokes also makes use of this. */
-    if (gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
+    if (GP_GEO_UPDATE_CURVE_REFIT_ANY(flag)) {
       /* TODO: Make do-partial-update variable */
-      BKE_gpencil_stroke_editcurve_update(
-          gps, gpd->curve_edit_threshold, gpd->curve_edit_corner_angle, false);
-      gps->editcurve->flag &= ~GP_CURVE_NEEDS_STROKE_UPDATE;
-      gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
+      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, false);
     }
 
     /* 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;
-    }
+    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. */
   if (gps->totpoints > 2) {
     BKE_gpencil_stroke_fill_triangulate(gps);
   }
@@ -1323,7 +1318,7 @@ void BKE_gpencil_stroke_geometry_update(bGPdata *gpd, bGPDstroke *gps)
     MEM_SAFE_FREE(gps->triangles);
   }
 
-  /* calc uv data along the stroke */
+  /* Calc UV data along the stroke. */
   BKE_gpencil_stroke_uv_update(gps);
 
   /* Calc stroke bounding box. */



More information about the Bf-blender-cvs mailing list