[Bf-blender-cvs] [59db505b55a] greasepencil-object: GPencil: Simplify Merge by Distance operator

Antonio Vazquez noreply at git.blender.org
Wed Aug 7 20:12:58 CEST 2019


Commit: 59db505b55ac41cd5f7c7903a68c72e678a53f91
Author: Antonio Vazquez
Date:   Wed Aug 7 20:12:46 2019 +0200
Branches: greasepencil-object
https://developer.blender.org/rB59db505b55ac41cd5f7c7903a68c72e678a53f91

GPencil: Simplify Merge by Distance operator

The old method to interpolate the position created a wrong merge. Now, always the secondary point is merged with the first one, except the last point.

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

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

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 82f1217a88d..858f8be6dff 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -2731,6 +2731,8 @@ void BKE_gpencil_merge_distance_stroke(bGPDframe *gpf,
                                        const float threshold,
                                        const bool use_unselected)
 {
+  bGPDspoint *pt = NULL;
+  bGPDspoint *pt_next = NULL;
   float tagged = false;
   /* Use square distance to speed up loop */
   const float th_square = threshold * threshold;
@@ -2741,13 +2743,13 @@ void BKE_gpencil_merge_distance_stroke(bGPDframe *gpf,
   int i = 0;
   int step = 1;
   while ((i < gps->totpoints - 1) && (i + step < gps->totpoints)) {
-    bGPDspoint *pt = &gps->points[i];
+    pt = &gps->points[i];
     if (pt->flag & GP_SPOINT_TAG) {
       i++;
       step = 1;
       continue;
     }
-    bGPDspoint *pt_next = &gps->points[i + step];
+    pt_next = &gps->points[i + step];
     /* Do not recalc tagged points. */
     if (pt_next->flag & GP_SPOINT_TAG) {
       step++;
@@ -2764,18 +2766,6 @@ void BKE_gpencil_merge_distance_stroke(bGPDframe *gpf,
     float len_square = len_squared_v3v3(&pt->x, &pt_next->x);
     if (len_square <= th_square) {
       tagged = true;
-      /* Interpolated factor depends if extremes or mid points. By default mid point. */
-      float factor = 0.5f;
-      /* For first point use, 1st extreme. */
-      if (i == 0) {
-        factor = 0.0f;
-      }
-      /* For last point use, 2nd extreme. */
-      else if (i == gps->totpoints - 2) {
-        factor = 1.0f;
-      }
-      /* Move first point to interpolated point. */
-      interp_v3_v3v3(&pt->x, &pt->x, &pt_next->x, factor);
       if (i != gps->totpoints - 1) {
         /* Tag second point for delete. */
         pt_next->flag |= GP_SPOINT_TAG;
@@ -2792,6 +2782,13 @@ void BKE_gpencil_merge_distance_stroke(bGPDframe *gpf,
       step = 1;
     }
   }
+
+  /* Always untag extremes. */
+  pt = &gps->points[0];
+  pt->flag &= ~GP_SPOINT_TAG;
+  pt = &gps->points[gps->totpoints - 1];
+  pt->flag &= ~GP_SPOINT_TAG;
+
   /* Dissolve tagged points */
   if (tagged) {
     BKE_gpencil_dissolve_points(gpf, gps, GP_SPOINT_TAG);



More information about the Bf-blender-cvs mailing list