From d4e1458db3a0e0eaf80219dc8e6d10cb27620793 Mon Sep 17 00:00:00 2001 From: Henrik Dick Date: Fri, 25 Mar 2022 11:51:45 +0100 Subject: GPencil: Improve smooth operation This patch makes the grease pencil smooth operation symmetric. It also increases the performance a lot if strong smoothing is required. Additionally there is an option for the position smooth operation to keep the shape closer to the original for more iterations. Since the result differs from the previous algorithm, versioning is used to change the iterations and factor to match the old result. Differential Revision: http://developer.blender.org/D14325 --- .../blender/editors/gpencil/gpencil_interpolate.c | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) (limited to 'source/blender/editors/gpencil/gpencil_interpolate.c') diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c index 65060e1bab5..8630b7f23d4 100644 --- a/source/blender/editors/gpencil/gpencil_interpolate.c +++ b/source/blender/editors/gpencil/gpencil_interpolate.c @@ -310,23 +310,6 @@ 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_point(gps, i, smooth_factor - reduce, false); - 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, @@ -553,7 +536,15 @@ 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); + BKE_gpencil_stroke_smooth(new_stroke, + tgpi->smooth_factor, + tgpi->smooth_steps, + true, + true, + false, + false, + true, + NULL); /* Calc geometry data. */ BKE_gpencil_stroke_geometry_update(gpd, new_stroke); @@ -1385,7 +1376,8 @@ 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); + BKE_gpencil_stroke_smooth( + new_stroke, smooth_factor, smooth_steps, true, true, false, false, true, NULL); /* Calc geometry data. */ BKE_gpencil_stroke_geometry_update(gpd, new_stroke); -- cgit v1.2.3