[Bf-blender-cvs] [4cda368ef68] greasepencil-object: GPencil: Improve Close stroke function for very small gaps

Antonioya noreply at git.blender.org
Tue Jul 16 12:13:59 CEST 2019


Commit: 4cda368ef68a755eac1a8e336ee7505c17761ccf
Author: Antonioya
Date:   Tue Jul 16 11:31:05 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4cda368ef68a755eac1a8e336ee7505c17761ccf

GPencil: Improve Close stroke function for very small gaps

When the gap is very small, don't need to add new points to the stroke, just cyclic.

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

M	source/blender/blenkernel/intern/gpencil.c

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 2c67f89cc14..a8e120d8225 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1994,6 +1994,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);
 
@@ -2010,9 +2016,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);



More information about the Bf-blender-cvs mailing list