Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFalk David <falkdavid@gmx.de>2020-08-15 14:10:37 +0300
committerFalk David <falkdavid@gmx.de>2020-08-15 14:10:37 +0300
commit8bd1469d86d43fe9e896ea0b487a22ea896fcd17 (patch)
tree4cac5c8607acc354f7d562e2cb911fbff58cd5d0
parentb221d8d0a32a74d912cc0fa204565410eee95dcf (diff)
GPencil: Add corner angle parameter
This parameter allows the user to control at what angle corners are detected and considered by the fitting algorithm.
-rw-r--r--release/scripts/startup/bl_ui/space_view3d.py1
-rw-r--r--source/blender/blenkernel/BKE_gpencil_curve.h5
-rw-r--r--source/blender/blenkernel/intern/gpencil_curve.c35
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_edit_curve.c2
-rw-r--r--source/blender/editors/gpencil/gpencil_select.c4
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c2
-rw-r--r--source/blender/makesdna/DNA_gpencil_types.h4
-rw-r--r--source/blender/makesrna/intern/rna_gpencil.c8
9 files changed, 43 insertions, 20 deletions
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 */
float curve_edit_threshold;
- char _pad[4];
+ /** Curve Editing corner angle (less or equal is treated as corner) */
+ float curve_corner_angle;
/* Palettes */
/** List of bGPDpalette's - Deprecated (2.78 - 2.79 only). */
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index 962ea90aa29..45e0286c215 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -2394,6 +2394,14 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
RNA_def_property_ui_range(prop, FLT_MIN, 10.0, 2, 5);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ /* Curve editing corner angle. */
+ prop = RNA_def_property(srna, "curve_corner_angle", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_float_sdna(prop, NULL, "curve_corner_angle");
+ RNA_def_property_float_default(prop, M_PI_2);
+ RNA_def_property_range(prop, 0.0f, M_PI);
+ RNA_def_property_ui_text(prop, "Corner Angle", "Angle threshold to be treated as corners.");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+
prop = RNA_def_property(srna, "use_multiedit", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_STROKE_MULTIEDIT);
RNA_def_property_ui_text(prop,