[Bf-blender-cvs] [1048abd3787] soc-2020-greasepencil-curve: GPencil: Add BKE to recalculate handle positions

Falk David noreply at git.blender.org
Wed Jul 1 00:46:04 CEST 2020


Commit: 1048abd3787b1b2c8f7b21eabedc243f34ebdf06
Author: Falk David
Date:   Wed Jul 1 00:41:55 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB1048abd3787b1b2c8f7b21eabedc243f34ebdf06

GPencil: Add BKE to recalculate handle positions

This function will update the handle position depending on the handle
type that the BezTriple handles have.

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

M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/intern/gpencil_curve.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index eb9a02f7702..f16e8ae7acb 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -50,6 +50,7 @@ void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPDstroke *gps, struct
 void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
 void BKE_gpencil_selected_strokes_editcurve_update(struct bGPdata *gpd);
 void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps);
+void BKE_gpencil_editcurve_recalculate_handles(struct bGPDstroke *gps);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index b0c0e819fa5..d69c43e9120 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -505,6 +505,10 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
     cpt->strength = orig_pt->strength;
     copy_v4_v4(cpt->vert_color, orig_pt->vert_color);
 
+    /* default handle type */
+    bezt->h1 |= HD_ALIGN;
+    bezt->h2 |= HD_ALIGN;
+
     cpt->point_index = r_cubic_orig_index[i];
   }
 
@@ -763,4 +767,34 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps)
   MEM_freeN(points);
 }
 
+void BKE_gpencil_editcurve_recalculate_handles(bGPDstroke *gps)
+{
+  if (gps == NULL || gps->editcurve == NULL) {
+    return;
+  }
+
+  bool changed = false;
+  bGPDcurve *gpc = gps->editcurve;
+  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;
+
+      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;
+
+      BKE_nurb_handle_calc(bezt, bezt_prev, bezt_next, false, 0);
+      changed = true;
+    }
+  }
+
+  if (changed) {
+    gpc->flag |= GP_CURVE_RECALC_GEOMETRY;
+  }
+}
+
 /** \} */



More information about the Bf-blender-cvs mailing list