[Bf-blender-cvs] [c581abc31c6] temp-gpencil-interpolate: GPencil: Add stroke smoothing for interpolated strokes
Antonio Vazquez
noreply at git.blender.org
Wed Dec 23 16:14:31 CET 2020
Commit: c581abc31c61c2e4969e3d94e2c47490d3fff242
Author: Antonio Vazquez
Date: Wed Dec 23 16:14:27 2020 +0100
Branches: temp-gpencil-interpolate
https://developer.blender.org/rBc581abc31c61c2e4969e3d94e2c47490d3fff242
GPencil: Add stroke smoothing for interpolated strokes
===================================================================
M release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M source/blender/editors/gpencil/gpencil_edit.c
M source/blender/editors/gpencil/gpencil_intern.h
M source/blender/editors/gpencil/gpencil_interpolate.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 29d4cdcf601..c2fae529bd5 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -1956,6 +1956,8 @@ class _defs_gpencil_paint:
row = layout.row()
row.prop(props, "layers")
row.prop(props, "flip")
+ row.prop(props, "smooth_factor")
+ row.prop(props, "smooth_steps")
return dict(
idname="builtin.interpolate",
@@ -2138,6 +2140,8 @@ class _defs_gpencil_edit:
row.prop(props, "layers")
row.prop(props, "interpolate_selected_only")
row.prop(props, "flip")
+ row.prop(props, "smooth_factor")
+ row.prop(props, "smooth_steps")
return dict(
idname="builtin.interpolate",
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 0486afec391..2c876b0795c 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -3917,7 +3917,7 @@ void GPENCIL_OT_recalc_geometry(wmOperatorType *ot)
* \{ */
/* helper to smooth */
-static void gpencil_smooth_stroke(bContext *C, wmOperator *op)
+static void gpencil_interpolate_smooth_stroke(bContext *C, wmOperator *op)
{
const int repeat = RNA_int_get(op->ptr, "repeat");
float factor = RNA_float_get(op->ptr, "factor");
@@ -4123,7 +4123,7 @@ static int gpencil_stroke_subdivide_exec(bContext *C, wmOperator *op)
if (changed) {
/* smooth stroke */
- gpencil_smooth_stroke(C, op);
+ gpencil_interpolate_smooth_stroke(C, op);
}
}
@@ -4810,7 +4810,7 @@ static int gpencil_stroke_smooth_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- gpencil_smooth_stroke(C, op);
+ gpencil_interpolate_smooth_stroke(C, op);
/* notifiers */
DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 1ea725753e4..75f82903a7a 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -154,6 +154,10 @@ typedef struct tGPDinterpolate {
float high_limit;
/** flag from toolsettings */
int flag;
+ /** smooth factor */
+ float smooth_factor;
+ /** smooth iterations */
+ int smooth_steps;
NumInput num; /* numeric input */
} tGPDinterpolate;
diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c
index b1083df6a2f..7cedf696d4b 100644
--- a/source/blender/editors/gpencil/gpencil_interpolate.c
+++ b/source/blender/editors/gpencil/gpencil_interpolate.c
@@ -172,6 +172,23 @@ static void gpencil_stroke_pair_table(bContext *C,
}
}
+static void gpencil_interpolate_smooth_stroke(bGPDstroke *gps,
+ float smooth_factor,
+ int smooth_steps)
+{
+ if (smooth_factor == 0.0f) {
+ return;
+ }
+
+ float reduce = 0.0f;
+ for (int r = 0; r < smooth_steps; r++) {
+ for (int i = 0; i < gps->totpoints - 1; i++) {
+ BKE_gpencil_stroke_smooth(gps, i, smooth_factor - reduce);
+ BKE_gpencil_stroke_smooth_strength(gps, i, smooth_factor);
+ }
+ reduce += 0.25f; /* reduce the factor */
+ }
+}
/* Perform interpolation */
static void gpencil_interpolate_update_points(const bGPDstroke *gps_from,
const bGPDstroke *gps_to,
@@ -386,6 +403,7 @@ static void gpencil_interpolate_set_points(bContext *C, tGPDinterpolate *tgpi)
/* Update points position. */
gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, tgpil->factor);
+ gpencil_interpolate_smooth_stroke(new_stroke, tgpi->smooth_factor, tgpi->smooth_steps);
/* Calc geometry data. */
BKE_gpencil_stroke_geometry_update(gpd, new_stroke);
@@ -530,6 +548,9 @@ static bool gpencil_interpolate_set_init_values(bContext *C, wmOperator *op, tGP
GP_TOOLFLAG_INTERPOLATE_ONLY_SELECTED);
SET_FLAG_FROM_TEST(tgpi->flag, RNA_boolean_get(op->ptr, "flip"), GP_TOOLFLAG_INTERPOLATE_FLIP);
+ tgpi->smooth_factor = RNA_float_get(op->ptr, "smooth_factor");
+ tgpi->smooth_steps = RNA_int_get(op->ptr, "smooth_steps");
+
/* Untag strokes to be sure nothing is pending due any canceled process. */
LISTBASE_FOREACH (bGPDlayer *, gpl, &tgpi->gpd->layers) {
gpencil_interpolate_untag_strokes(gpl);
@@ -799,6 +820,26 @@ void GPENCIL_OT_interpolate(wmOperatorType *ot)
"Flip Strokes",
"Invert destination stroke to match start and end with source stroke");
+ RNA_def_int(ot->srna,
+ "smooth_steps",
+ 1,
+ 1,
+ 3,
+ "Iterations",
+ "Number of times to smooth newly created strokes",
+ 1,
+ 3);
+
+ RNA_def_float(ot->srna,
+ "smooth_factor",
+ 0.0f,
+ 0.0f,
+ 2.0f,
+ "Smooth",
+ "Amount of smoothing to apply to interpolated strokes, to reduce jitter/noise",
+ 0.0f,
+ 2.0f);
+
prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "");
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
@@ -1028,6 +1069,9 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
(RNA_boolean_get(op->ptr, "interpolate_selected_only") != 0));
const bool flip = RNA_boolean_get(op->ptr, "flip");
+ const float smooth_factor = RNA_float_get(op->ptr, "smooth_factor");
+ const int smooth_steps = RNA_int_get(op->ptr, "smooth_steps");
+
const eGP_Interpolate_Type type = RNA_enum_get(op->ptr, "type");
if (ipo_settings->custom_ipo == NULL) {
@@ -1151,6 +1195,7 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op)
/* Update points position. */
gpencil_interpolate_update_points(gps_from, gps_to, new_stroke, factor);
+ gpencil_interpolate_smooth_stroke(new_stroke, smooth_factor, smooth_steps);
/* Calc geometry data. */
BKE_gpencil_stroke_geometry_update(gpd, new_stroke);
@@ -1202,6 +1247,8 @@ static void gpencil_interpolate_seq_ui(bContext *C, wmOperator *op)
uiItemR(col, &ptr, "layers", 0, NULL, ICON_NONE);
uiItemR(col, &ptr, "interpolate_selected_only", 0, NULL, ICON_NONE);
uiItemR(col, &ptr, "flip", 0, NULL, ICON_NONE);
+ uiItemR(col, &ptr, "smooth_factor", 0, NULL, ICON_NONE);
+ uiItemR(col, &ptr, "smooth_steps", 0, NULL, ICON_NONE);
uiItemR(col, &ptr, "type", 0, NULL, ICON_NONE);
if (type == GP_IPO_CURVEMAP) {
@@ -1356,12 +1403,33 @@ void GPENCIL_OT_interpolate_sequence(wmOperatorType *ot)
"Flip Strokes",
"Invert destination stroke to match start and end with source stroke");
+ RNA_def_int(ot->srna,
+ "smooth_steps",
+ 1,
+ 1,
+ 3,
+ "Iterations",
+ "Number of times to smooth newly created strokes",
+ 1,
+ 3);
+
+ RNA_def_float(ot->srna,
+ "smooth_factor",
+ 0.0f,
+ 0.0f,
+ 2.0f,
+ "Smooth",
+ "Amount of smoothing to apply to interpolated strokes, to reduce jitter/noise",
+ 0.0f,
+ 2.0f);
+
RNA_def_enum(ot->srna,
"type",
gpencil_interpolation_type_items,
0,
"Type",
"Interpolation method to use the next time 'Interpolate Sequence' is run");
+
RNA_def_enum(
ot->srna,
"easing",
@@ -1370,6 +1438,7 @@ void GPENCIL_OT_interpolate_sequence(wmOperatorType *ot)
"Easing",
"Which ends of the segment between the preceding and following grease pencil frames "
"easing interpolation is applied to");
+
RNA_def_float(ot->srna,
"back",
1.702f,
@@ -1379,6 +1448,7 @@ void GPENCIL_OT_interpolate_sequence(wmOperatorType *ot)
"Amount of overshoot for 'back' easing",
0.0f,
FLT_MAX);
+
RNA_def_float(ot->srna,
"amplitude",
0.15f,
@@ -1388,6 +1458,7 @@ void GPENCIL_OT_interpolate_sequence(wmOperatorType *ot)
"Amount to boost elastic bounces for 'elastic' easing",
0.0f,
FLT_MAX);
+
RNA_def_float(ot->srna,
"period",
0.15f,
More information about the Bf-blender-cvs
mailing list