[Bf-blender-cvs] [17ec934756c] temp-gpencil-bezier-stroke-type: GPencil: Use geom update flags in update functions

Falk David noreply at git.blender.org
Fri Apr 16 22:03:43 CEST 2021


Commit: 17ec934756ccccd73a965194d531da52c0679483
Author: Falk David
Date:   Fri Apr 16 21:49:00 2021 +0200
Branches: temp-gpencil-bezier-stroke-type
https://developer.blender.org/rB17ec934756ccccd73a965194d531da52c0679483

GPencil: Use geom update flags in update functions

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

M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/intern/gpencil_curve.c
M	source/blender/editors/gpencil/gpencil_edit_curve.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 373c0590736..5e474849900 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -49,9 +49,9 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
 struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
                                                         const float error_threshold,
                                                         const float corner_angle);
-struct bGPDcurve *BKE_gpencil_stroke_editcurve_regenerate(struct bGPDstroke *gps,
-                                                          const float error_threshold,
-                                                          const float corner_angle);
+struct bGPDcurve *BKE_gpencil_stroke_editcurve_tagged_segments_update(struct bGPDstroke *gps,
+                                                                      const float error_threshold,
+                                                                      const float corner_angle);
 void BKE_gpencil_stroke_editcurve_regenerate_single(struct bGPDstroke *gps,
                                                     uint32_t start_idx,
                                                     uint32_t end_idx,
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 3651576246a..82eec1b6f54 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -893,9 +893,9 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps,
  * Creates a bGPDcurve by doing a cubic curve fitting on the tagged segments (parts of the curve
  * with at least one bGPDspoint with GP_SPOINT_TAG).
  */
-bGPDcurve *BKE_gpencil_stroke_editcurve_regenerate(bGPDstroke *gps,
-                                                   const float error_threshold,
-                                                   const float corner_angle)
+bGPDcurve *BKE_gpencil_stroke_editcurve_tagged_segments_update(bGPDstroke *gps,
+                                                               const float error_threshold,
+                                                               const float corner_angle)
 {
   if (gps->totpoints < 3) {
     BKE_gpencil_free_stroke_editcurve(gps);
@@ -1109,10 +1109,7 @@ void BKE_gpencil_stroke_editcurve_regenerate_single(bGPDstroke *gps,
  * amount from the stroke.
  * \param corner_angle: If angles greater than this amount are detected during fitting, they will
  * be sharp (non-aligned handles).
- * \param do_partial_update: If false, will delete the old curve and do a full update. If true,
- * will check what points were changed using the GP_SPOINT_TAG point flag and only update the
- * segments that should be updated and keep the others. If all segments were affected, will do a
- * full update.
+ * \param flag: Flag for refitting options (see eGPStrokeGeoUpdateFlag).
  */
 void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps,
                                          const float threshold,
@@ -1127,7 +1124,7 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps,
   short prev_flag = 0;
 
   /* If editcurve exists save the selection to the stroke points (only for syncing later). */
-  if (GPENCIL_STROKE_TYPE_BEZIER(gps)) {
+  if (gps->editcurve != NULL) {
     BKE_gpencil_stroke_editcurve_sync_selection(NULL, gps, gps->editcurve);
   }
 
@@ -1150,7 +1147,8 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps,
     }
     else {
       /* Some segments are unchanged. Do a partial update. */
-      editcurve = BKE_gpencil_stroke_editcurve_regenerate(gps, threshold, corner_angle);
+      editcurve = BKE_gpencil_stroke_editcurve_tagged_segments_update(
+          gps, threshold, corner_angle);
       gpencil_clear_point_tag(gps);
     }
   }
@@ -1169,15 +1167,12 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps,
     return;
   }
 
-  /* Assign pointer. This makes the stroke a bezier stroke. */
+  /* Assign pointer. This makes the stroke a bezier stroke now. */
   gps->editcurve = editcurve;
   if (prev_flag) {
     gps->editcurve->flag = prev_flag;
   }
 
-  /* Free the poly weights (if not null). Should no longer be used. */
-  BKE_gpencil_free_stroke_weights(gps);
-
   if ((flag & GP_GEO_UPDATE_CURVE_PARTIAL_REFIT)) {
     BKE_gpencil_editcurve_recalculate_handles(gps);
   }
@@ -1285,28 +1280,36 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPdata *gpd, bGPDstroke *gps,
   }
 }
 
-static void gpencil_interpolate_fl_from_to(
+static float smooth_interpf(const float target, const float origin, const float t)
+{
+  float fac = 3.0f * t * t - 2.0f * t * t * t;  // smooth
+  return interpf(target, origin, fac);
+}
+
+static void smooth_interp_v4_v4v4(float *r, const float *a, const float *b, const float t)
+{
+  float fac = 3.0f * t * t - 2.0f * t * t * t;  // smooth
+  interp_v4_v4v4(r, a, b, fac);
+}
+
+static void gpencil_interp_stride_fl_from_to(
     float from, float to, float *point_offset, int it, int stride)
 {
   /* smooth interpolation */
   float *r = point_offset;
   for (int i = 0; i <= it; i++) {
-    float fac = (float)i / (float)it;
-    fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;  // smooth
-    *r = interpf(to, from, fac);
+    *r = smooth_interpf(to, from, (float)i / (float)it);
     r = POINTER_OFFSET(r, stride);
   }
 }
 
-static void gpencil_interpolate_v4_from_to(
+static void gpencil_interp_stride_v4_from_to(
     float from[4], float to[4], float *point_offset, int it, int stride)
 {
   /* smooth interpolation */
   float *r = point_offset;
   for (int i = 0; i <= it; i++) {
-    float fac = (float)i / (float)it;
-    fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;  // smooth
-    interp_v4_v4v4(r, from, to, fac);
+    smooth_interp_v4_v4v4(r, from, to, (float)i / (float)it);
     r = POINTER_OFFSET(r, stride);
   }
 }
@@ -1325,49 +1328,66 @@ static float gpencil_approximate_curve_segment_arclength(bGPDcurve_point *cpt_st
   return (chord_len + net_len) / 2.0f;
 }
 
-static void gpencil_calculate_stroke_points_curve_segment(
-    bGPDcurve_point *cpt, bGPDcurve_point *cpt_next, float *points_offset, int resolu, int stride)
+/* Helper: Interpolate curve point attributes from curve point pair into point array. */
+static void gpencil_calculate_stroke_points_curve_segment(bGPDcurve_point *cpt,
+                                                          bGPDcurve_point *cpt_next,
+                                                          float *points_offset,
+                                                          int resolu,
+                                                          int stride,
+                                                          const eGPStrokeGeoUpdateFlag flag)
 {
-  /* sample points on all 3 axis between two curve points */
-  for (uint axis = 0; axis < 3; axis++) {
-    BKE_curve_forward_diff_bezier(cpt->bezt.vec[1][axis],
-                                  cpt->bezt.vec[2][axis],
-                                  cpt_next->bezt.vec[0][axis],
-                                  cpt_next->bezt.vec[1][axis],
-                                  POINTER_OFFSET(points_offset, sizeof(float) * axis),
-                                  (int)resolu,
-                                  stride);
+  const bool update_all_attributes = (flag == GP_GEO_UPDATE_DEFAULT);
+
+  if (update_all_attributes || (flag & GP_GEO_UPDATE_POLYLINE_POSITION)) {
+    /* sample points on all 3 axis between two curve points */
+    for (uint axis = 0; axis < 3; axis++) {
+      BKE_curve_forward_diff_bezier(cpt->bezt.vec[1][axis],
+                                    cpt->bezt.vec[2][axis],
+                                    cpt_next->bezt.vec[0][axis],
+                                    cpt_next->bezt.vec[1][axis],
+                                    POINTER_OFFSET(points_offset, sizeof(float) * axis),
+                                    (int)resolu,
+                                    stride);
+    }
   }
 
   /* interpolate other attributes */
-  gpencil_interpolate_fl_from_to(cpt->pressure,
-                                 cpt_next->pressure,
-                                 POINTER_OFFSET(points_offset, sizeof(float) * 3),
-                                 resolu,
-                                 stride);
-  gpencil_interpolate_fl_from_to(cpt->strength,
-                                 cpt_next->strength,
-                                 POINTER_OFFSET(points_offset, sizeof(float) * 4),
-                                 resolu,
-                                 stride);
-  gpencil_interpolate_v4_from_to(cpt->vert_color,
-                                 cpt_next->vert_color,
-                                 POINTER_OFFSET(points_offset, sizeof(float) * 5),
-                                 resolu,
-                                 stride);
+  if (update_all_attributes || (flag & GP_GEO_UPDATE_POLYLINE_PRESSURE)) {
+    gpencil_interp_stride_fl_from_to(cpt->pressure,
+                                     cpt_next->pressure,
+                                     POINTER_OFFSET(points_offset, sizeof(float) * 3),
+                                     resolu,
+                                     stride);
+  }
+  if (update_all_attributes || (flag & GP_GEO_UPDATE_POLYLINE_STRENGTH)) {
+    gpencil_interp_stride_fl_from_to(cpt->strength,
+                                     cpt_next->strength,
+                                     POINTER_OFFSET(points_offset, sizeof(float) * 4),
+                                     resolu,
+                                     stride);
+  }
+  if (update_all_attributes || (flag & GP_GEO_UPDATE_POLYLINE_COLOR)) {
+    gpencil_interp_stride_v4_from_to(cpt->vert_color,
+                                     cpt_next->vert_color,
+                                     POINTER_OFFSET(points_offset, sizeof(float) * 5),
+                                     resolu,
+                                     stride);
+  }
 }
 
 static float *gpencil_stroke_points_from_editcurve_adaptive_resolu(
     bGPDcurve_point *curve_point_array,


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list