[Bf-blender-cvs] [8bd1469d86d] soc-2020-greasepencil-curve: GPencil: Add corner angle parameter

Falk David noreply at git.blender.org
Sat Aug 15 13:13:02 CEST 2020


Commit: 8bd1469d86d43fe9e896ea0b487a22ea896fcd17
Author: Falk David
Date:   Sat Aug 15 13:10:37 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rB8bd1469d86d43fe9e896ea0b487a22ea896fcd17

GPencil: Add corner angle parameter

This parameter allows the user to control at what angle corners are
detected and considered by the fitting algorithm.

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/intern/gpencil_curve.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
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 72f0128965c..f7070c46078 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6951,6 +6951,7 @@ class VIEW3D_PT_gpencil_curve_edit(Panel):
         col = layout.column(align=True)
         col.prop(gpd, "edit_curve_resolution")
         col.prop(gpd, "curve_edit_threshold")
+        col.prop(gpd, "curve_corner_angle")
         col.prop(gpd, "use_adaptive_curve_resolution")
 
 
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index dd41762c046..7709b165c11 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -43,8 +43,9 @@ void BKE_gpencil_convert_curve(struct Main *bmain,
                                const float sample);
 
 struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
-                                                        float error_threshold);
-void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps, float error_threshold);
+                                                        float error_threshold,
+                                                        float corner_angle);
+void BKE_gpencil_stroke_editcurve_update(struct bGPDstroke *gps, float error_threshold, float corner_angle);
 void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
 void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
 void BKE_gpencil_strokes_selected_update_editcurve(struct bGPdata *gpd);
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index 881ce019d32..b82d1552e5e 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -565,7 +565,7 @@ void BKE_gpencil_convert_curve(Main *bmain,
 /**
  * Creates a bGPDcurve by doing a cubic curve fitting on the grease pencil stroke points.
  */
-bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_threshold)
+bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_threshold, float corner_angle)
 {
   if (gps->totpoints < 1) {
     return NULL;
@@ -588,8 +588,8 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
     copy_v4_v4(cpt->vert_color, pt->vert_color);
 
     /* default handle type */
-    bezt->h1 |= HD_ALIGN;
-    bezt->h2 |= HD_ALIGN;
+    bezt->h1 = HD_ALIGN;
+    bezt->h2 = HD_ALIGN;
 
     cpt->point_index = 0;
 
@@ -620,9 +620,6 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
     calc_flag |= CURVE_FIT_CALC_CYCLIC;
   }
 
-  /* TODO: make this a parameter */
-  float corner_angle = M_PI_2;
-
   float *r_cubic_array = NULL;
   unsigned int r_cubic_array_len = 0;
   unsigned int *r_cubic_orig_index = NULL;
@@ -666,12 +663,26 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
     mul_v4_v4fl(cpt->vert_color, &ctrl_point[5], diag_length);
 
     /* default handle type */
-    bezt->h1 |= HD_ALIGN;
-    bezt->h2 |= HD_ALIGN;
+    bezt->h1 = HD_ALIGN;
+    bezt->h2 = HD_ALIGN;
 
     cpt->point_index = r_cubic_orig_index[i];
   }
 
+  if (r_corners_index_len > 0 && r_corners_index_array != NULL) {
+    int start = 0, end = r_corners_index_len;
+    if ((r_corners_index_len > 1) && (calc_flag & CURVE_FIT_CALC_CYCLIC) == 0) {
+      start = 1;
+      end = r_corners_index_len - 1;
+    }
+    for (int i = start; i < end; i++) {
+      bGPDcurve_point *cpt = &editcurve->curve_points[r_corners_index_array[i]];
+      BezTriple *bezt = &cpt->bezt;
+      bezt->h1 = HD_FREE;
+      bezt->h2 = HD_FREE;
+    }
+  }
+
   MEM_freeN(points);
   if (r_cubic_array) {
     free(r_cubic_array);
@@ -690,7 +701,7 @@ bGPDcurve *BKE_gpencil_stroke_editcurve_generate(bGPDstroke *gps, float error_th
 /**
  * Updates the editcurve for a stroke. Frees the old curve if one exists and generates a new one.
  */
-void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
+void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold, float corner_angle)
 {
   if (gps == NULL || gps->totpoints < 0) {
     return;
@@ -700,7 +711,7 @@ void BKE_gpencil_stroke_editcurve_update(bGPDstroke *gps, float error_threshold)
     BKE_gpencil_free_stroke_editcurve(gps);
   }
 
-  bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_generate(gps, error_threshold);
+  bGPDcurve *editcurve = BKE_gpencil_stroke_editcurve_generate(gps, error_threshold, corner_angle);
   if (editcurve == NULL) {
     return;
   }
@@ -1291,14 +1302,14 @@ void BKE_gpencil_strokes_selected_update_editcurve(bGPdata *gpd)
 
           /* Generate the curve if there is none or the stroke was changed */
           if (gps->editcurve == NULL) {
-            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
             /* Continue if curve could not be generated. */
             if (gps->editcurve == NULL) {
               continue;
             }
           }
           else if (gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
-            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
           }
           /* Update the selection from the stroke to the curve. */
           BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 82a09a63039..d4c77598ee8 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -209,7 +209,7 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
     GP_EDITABLE_CURVES_BEGIN(gps_iter, C, gpl, gps, gpc)
     {
       if (gpc->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
-        BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+        BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
         /* Update the selection from the stroke to the curve. */
         BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
 
diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c
index e7adaead34e..71d42946372 100644
--- a/source/blender/editors/gpencil/gpencil_edit_curve.c
+++ b/source/blender/editors/gpencil/gpencil_edit_curve.c
@@ -89,7 +89,7 @@ static int gpencil_stroke_enter_editcurve_mode_exec(bContext *C, wmOperator *op)
           /* only allow selected and non-converted strokes to be transformed */
           if ((gps->flag & GP_STROKE_SELECT && gps->editcurve == NULL) ||
               (gps->editcurve != NULL && gps->editcurve->flag & GP_CURVE_NEEDS_STROKE_UPDATE)) {
-            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+            BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
             /* 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;
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 1e1cdeba7a1..1f502693563 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -1820,7 +1820,7 @@ static bool gpencil_generic_stroke_select(bContext *C,
     }
 
     // if (is_curve_edit && (hit || whole) && gps->editcurve == NULL) {
-    //   BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+    //   BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
     //   BKE_gpencil_curve_sync_selection(gps);
     //   gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
     //   BKE_gpencil_stroke_geometry_update(gpd, gps);
@@ -2237,7 +2237,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(hit_stroke, gpd->curve_edit_threshold);
+      BKE_gpencil_stroke_editcurve_update(hit_stroke, gpd->curve_edit_threshold, gpd->curve_corner_angle);
       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 1d8a6e5f537..8426584aa7b 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -2654,7 +2654,7 @@ void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
 
       /* Make sure stroke has an editcurve */
       if (gps->editcurve == NULL) {
-        BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold);
+        BKE_gpencil_stroke_editcurve_update(gps, gpd->curve_edit_threshold, gpd->curve_corner_angle);
         gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
         BKE_gpencil_stroke_geometry_update(gpd, gps);
       }
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 94bf6a7b519..3554a1d5851 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -39,6 +39,7 @@ struct Curve;
 
 #define GP_DEFAULT_CURVE_RESOLUTION 32
 #define GP_DEFAULT_CURVE_ERROR 0.1f
+#define GP_DEFAULT_CURVE_CORNER_ANGLE 1.57079632679489661923 /* pi/2 */
 
 /* ***************************************** */
 /* GP Stroke Points */
@@ -632,7 +633,8 @@ typedef struct bGPdata {
   int editcurve_resolution;
   /** Curve Editing error threshold */
   floa

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list