[Bf-blender-cvs] [677e027f206] master: Fix T73625: GPencil array offset wrong whe use Scale or Rotation

Antonio Vazquez noreply at git.blender.org
Fri Feb 7 16:36:28 CET 2020


Commit: 677e027f2069dac18891db931c860542cbcb4bbe
Author: Antonio Vazquez
Date:   Fri Feb 7 16:35:26 2020 +0100
Branches: master
https://developer.blender.org/rB677e027f2069dac18891db931c860542cbcb4bbe

Fix T73625: GPencil array offset wrong whe use Scale or Rotation

This is not 100% a bug but a design change. The old method used the object origin as pivot point for Scale a nd Rotation, so when you moved the stroke in edit mode, the whole array ittems where offset because the pivot point distance changed.

Now, before applying scale and rotation, the stroke is moved to object origin to keep the offset when scale or rotate, so these transformations are done in stroke local space.

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

M	source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c

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

diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
index bb70b548675..e258fbdccd1 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
@@ -228,24 +228,34 @@ static void generate_geometry(GpencilModifierData *md,
     for (gps = gpf->strokes.first, idx = 0; gps; gps = gps->next, idx++) {
       /* check if stroke can be duplicated */
       if (valid_strokes[idx]) {
-        /* Duplicate stroke */
-        bGPDstroke *gps_dst = MEM_dupallocN(gps);
-        gps_dst->points = MEM_dupallocN(gps->points);
-        if (gps->dvert) {
-          gps_dst->dvert = MEM_dupallocN(gps->dvert);
-          BKE_gpencil_stroke_weights_duplicate(gps, gps_dst);
+        /* Calculate original stroke center (only first loop). */
+        float r_min[3], r_max[3], center[3];
+        if (x == 1) {
+          INIT_MINMAX(r_min, r_max);
+          BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
+          add_v3_v3v3(center, r_min, r_max);
+          mul_v3_fl(center, 0.5f);
+          sub_v3_v3v3(center, center, ob->obmat[3]);
         }
-        gps_dst->triangles = MEM_dupallocN(gps->triangles);
+
+        /* Duplicate stroke */
+        bGPDstroke *gps_dst = BKE_gpencil_stroke_duplicate(gps);
 
         /* Move points */
         for (int i = 0; i < gps->totpoints; i++) {
           bGPDspoint *pt = &gps_dst->points[i];
+          /* Apply object local transform (Rot/Scale). */
           if (mmd->object) {
-            /* apply local changes (rot/scale) */
             mul_m4_v3(mat, &pt->x);
           }
-          /* global changes */
-          mul_m4_v3(current_offset, &pt->x);
+          /* Translate to object origin. */
+          float fpt[3];
+          sub_v3_v3v3(fpt, &pt->x, center);
+          /* Global Rotate and scale. */
+          mul_mat3_m4_v3(current_offset, fpt);
+          /* Global translate. */
+          add_v3_v3(fpt, center);
+          add_v3_v3v3(&pt->x, fpt, current_offset[3]);
         }
 
         /* if replace material, use new one */



More information about the Bf-blender-cvs mailing list