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.
This commit is contained in:
Antonio Vazquez 2020-02-07 16:35:26 +01:00
parent faf08954d5
commit 677e027f20
Notes: blender-bot 2023-02-14 07:25:46 +01:00
Referenced by issue #73625, Array offset with multiple shapes
1 changed files with 20 additions and 10 deletions

View File

@ -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 */