diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2019-08-10 14:15:20 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2019-08-10 14:15:20 +0300 |
commit | 553b581f25c1782c4231816965cd3f6ce58a449a (patch) | |
tree | a0a3c6675126b9455366c7776a288106e352891f /source/blender/blenkernel/intern | |
parent | 41f8f08e5188ed3d859c8e896ce700cb15ddf67b (diff) |
GPencil: Improves Close stroke when the closing gap is very small
For very small gaps, we don't need generate geometry.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/gpencil.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 6fea938edc7..ed4c6848751 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -2313,6 +2313,12 @@ bool BKE_gpencil_close_stroke(bGPDstroke *gps) pt2 = &gps->points[0]; float dist_close = len_v3v3(&pt1->x, &pt2->x); + /* if the distance to close is very small, don't need add points and just enable cyclic. */ + if (dist_close <= dist_avg) { + gps->flag |= GP_STROKE_CYCLIC; + return true; + } + /* Calc number of points required using the average distance. */ int tot_newpoints = MAX2(dist_close / dist_avg, 1); @@ -2329,9 +2335,11 @@ bool BKE_gpencil_close_stroke(bGPDstroke *gps) pt2 = &gps->points[0]; bGPDspoint *pt = &gps->points[old_tot]; for (int i = 1; i < tot_newpoints + 1; i++, pt++) { - float step = ((float)i / (float)tot_newpoints); + float step = (tot_newpoints > 1) ? ((float)i / (float)tot_newpoints) : 0.99f; /* Clamp last point to be near, but not on top of first point. */ - CLAMP(step, 0.0f, 0.99f); + if ((tot_newpoints > 1) && (i == tot_newpoints)) { + step *= 0.99f; + } /* Average point. */ interp_v3_v3v3(&pt->x, &pt1->x, &pt2->x, step); @@ -2363,7 +2371,6 @@ bool BKE_gpencil_close_stroke(bGPDstroke *gps) return true; } - /* Dissolve points in stroke */ void BKE_gpencil_dissolve_points(bGPDframe *gpf, bGPDstroke *gps, const short tag) { |