[Bf-blender-cvs] [e3098de2a1f] master: GPencil: Fix unreported switch direction not flipping weights

Henrik Dick noreply at git.blender.org
Tue Aug 17 22:20:32 CEST 2021


Commit: e3098de2a1fedd98d9f31d3cb562116f0945b7f9
Author: Henrik Dick
Date:   Tue Aug 17 22:16:16 2021 +0200
Branches: master
https://developer.blender.org/rBe3098de2a1fedd98d9f31d3cb562116f0945b7f9

GPencil:  Fix unreported switch direction not flipping weights

There was an unreported bug that switch direction would not switch the order of the vertex group weights. This caused join to do it wrong as well.

Changed to use `BLI_array_reverse` function here to reverse both the normal points and the weights, therefore simplifying the code.

Differential Revision: https://developer.blender.org/D12251

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

M	source/blender/blenkernel/intern/gpencil_geom.cc

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

diff --git a/source/blender/blenkernel/intern/gpencil_geom.cc b/source/blender/blenkernel/intern/gpencil_geom.cc
index f2042d3098c..0f218d6166c 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.cc
+++ b/source/blender/blenkernel/intern/gpencil_geom.cc
@@ -31,6 +31,7 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_array_utils.h"
 #include "BLI_blenlib.h"
 #include "BLI_float3.hh"
 #include "BLI_ghash.h"
@@ -2817,46 +2818,12 @@ void BKE_gpencil_stroke_set_random_color(bGPDstroke *gps)
 /* Flip stroke. */
 void BKE_gpencil_stroke_flip(bGPDstroke *gps)
 {
-  int end = gps->totpoints - 1;
+  /* Reverse points. */
+  BLI_array_reverse(gps->points, gps->totpoints);
 
-  for (int i = 0; i < gps->totpoints / 2; i++) {
-    bGPDspoint *point, *point2;
-    bGPDspoint pt;
-
-    /* save first point */
-    point = &gps->points[i];
-    pt.x = point->x;
-    pt.y = point->y;
-    pt.z = point->z;
-    pt.flag = point->flag;
-    pt.pressure = point->pressure;
-    pt.strength = point->strength;
-    pt.time = point->time;
-    copy_v4_v4(pt.vert_color, point->vert_color);
-
-    /* replace first point with last point */
-    point2 = &gps->points[end];
-    point->x = point2->x;
-    point->y = point2->y;
-    point->z = point2->z;
-    point->flag = point2->flag;
-    point->pressure = point2->pressure;
-    point->strength = point2->strength;
-    point->time = point2->time;
-    copy_v4_v4(point->vert_color, point2->vert_color);
-
-    /* replace last point with first saved before */
-    point = &gps->points[end];
-    point->x = pt.x;
-    point->y = pt.y;
-    point->z = pt.z;
-    point->flag = pt.flag;
-    point->pressure = pt.pressure;
-    point->strength = pt.strength;
-    point->time = pt.time;
-    copy_v4_v4(point->vert_color, pt.vert_color);
-
-    end--;
+  /* Reverse vertex groups if available. */
+  if (gps->dvert) {
+    BLI_array_reverse(gps->dvert, gps->totpoints);
   }
 }



More information about the Bf-blender-cvs mailing list