From fadad895b2f44044b829e7ffe83174d8ecd8a487 Mon Sep 17 00:00:00 2001 From: Antonioya Date: Mon, 3 Dec 2018 16:26:31 +0100 Subject: T58338 Edit Mode rotation doesn't work if object is far away from world origin The fix code was done by Brecht Van Lommel, I only tested that the solution works. --- source/blender/editors/transform/transform.c | 27 +------------------ .../editors/transform/transform_conversions.c | 31 +++++----------------- .../blender/editors/transform/transform_generics.c | 21 +++------------ 3 files changed, 11 insertions(+), 68 deletions(-) (limited to 'source') diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index d05fc058184..f27887a2aa2 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1776,32 +1776,7 @@ static void drawHelpline(bContext *C, int x, int y, void *customdata) (float)t->mval[1], }; - /* grease pencil only can edit one object at time because GP has - * multiframe edition that replaces multiobject edition. - * If multiobject edition is added, maybe this code will need - * an update - */ - if ((t->flag & T_POINTS) && (t->options & CTX_GPENCIL_STROKES) && - (t->around != V3D_AROUND_ACTIVE)) - { - Object *ob = CTX_data_active_object(C); - if ((ob) && (ob->type == OB_GPENCIL)) { - FOREACH_TRANS_DATA_CONTAINER(t, tc) { - float vecrot[3]; - copy_v3_v3(vecrot, t->center_global); - mul_m4_v3(ob->obmat, vecrot); - projectFloatViewEx(t, vecrot, cent, V3D_PROJ_TEST_CLIP_ZERO); - } - } - else { - /* normally, never must be used */ - projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO); - } - } - else { - projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO); - } - + projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO); /* Offset the values for the area region. */ const float offset[2] = { t->ar->winrct.xmin, diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 3de39654779..c111c1d3e73 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -8262,9 +8262,6 @@ static void createTransGPencil(bContext *C, TransInfo *t) unit_m3(mtx); /* Second Pass: Build transdata array */ - int totselected = 0; - float global_center[3] = { 0.0f, 0.0f, 0.0f }; - for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { /* only editable and visible layers are considered */ if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) { @@ -8381,10 +8378,6 @@ static void createTransGPencil(bContext *C, TransInfo *t) if (pt->flag & GP_SPOINT_SELECT) { td->flag |= TD_SELECTED; - - /* prepare center */ - add_v3_v3(global_center, &pt->x); - totselected++; } /* for other transform modes (e.g. shrink-fatten), need to additional data @@ -8399,24 +8392,18 @@ static void createTransGPencil(bContext *C, TransInfo *t) if ((gps->flag & (GP_STROKE_3DSPACE | GP_STROKE_2DSPACE | GP_STROKE_2DIMAGE)) == 0) { /* screenspace */ td->protectflag = OB_LOCK_LOCZ | OB_LOCK_ROTZ | OB_LOCK_SCALEZ; - - /* apply matrix transformation relative to parent */ - copy_m3_m4(td->smtx, inverse_diff_mat); /* final position */ - copy_m3_m4(td->mtx, diff_mat); /* display position */ - copy_m3_m4(td->axismtx, diff_mat); /* axis orientation */ } else { /* configure 2D dataspace points so that they don't play up... */ if (gps->flag & (GP_STROKE_2DSPACE | GP_STROKE_2DIMAGE)) { td->protectflag = OB_LOCK_LOCZ | OB_LOCK_ROTZ | OB_LOCK_SCALEZ; - // XXX: matrices may need to be different? } - - /* apply parent transformations */ - copy_m3_m4(td->smtx, inverse_diff_mat); /* final position */ - copy_m3_m4(td->mtx, diff_mat); /* display position */ - copy_m3_m4(td->axismtx, diff_mat); /* axis orientation */ } + /* apply parent transformations */ + copy_m3_m4(td->smtx, inverse_diff_mat); /* final position */ + copy_m3_m4(td->mtx, diff_mat); /* display position */ + copy_m3_m4(td->axismtx, diff_mat); /* axis orientation */ + /* Triangulation must be calculated again, so save the stroke for recalc function */ td->extra = gps; @@ -8443,13 +8430,6 @@ static void createTransGPencil(bContext *C, TransInfo *t) } } } - - /* set global center */ - CLAMP_MIN(totselected, 1); - mul_v3_fl(global_center, 1.0f / totselected); - add_v3_v3(global_center, obact->obmat[3]); - copy_v3_v3(t->center_global, global_center); - t->flag |= T_OVERRIDE_CENTER; } static int countAndCleanTransDataContainer(TransInfo *t) @@ -8525,6 +8505,7 @@ void createTransData(bContext *C, TransInfo *t) t->options |= CTX_GPENCIL_STROKES; t->flag |= T_POINTS; + initTransDataContainers_FromObjectData(t, ob, NULL, 0); createTransGPencil(C, t); countAndCleanTransDataContainer(t); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 0a7d139d7a1..2e358c1cc92 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1203,7 +1203,7 @@ void initTransDataContainers_FromObjectData(TransInfo *t, Object *obact, Object const eObjectMode object_mode = obact ? obact->mode : OB_MODE_OBJECT; const short object_type = obact ? obact->type : -1; - if ((object_mode & OB_MODE_EDIT) || + if ((object_mode & OB_MODE_EDIT) || (t->options & CTX_GPENCIL_STROKES) || ((object_mode & OB_MODE_POSE) && (object_type == OB_ARMATURE))) { if (t->data_container) { @@ -1238,6 +1238,9 @@ void initTransDataContainers_FromObjectData(TransInfo *t, Object *obact, Object tc->poseobj = objects[i]; tc->use_local_mat = true; } + else if (t->options & CTX_GPENCIL_STROKES) { + tc->use_local_mat = true; + } if (tc->use_local_mat) { BLI_assert((t->flag & T_2D_EDIT) == 0); @@ -1874,22 +1877,6 @@ void calculateCenterCursor(TransInfo *t, float r_center[3]) } r_center[2] = 0.0f; } - else if (t->options & CTX_GPENCIL_STROKES) { - /* move cursor in local space */ - TransData *td = NULL; - FOREACH_TRANS_DATA_CONTAINER (t, tc) { - float mat[3][3], imat[3][3]; - - td = tc->data; - Object *ob = td->ob; - if (ob) { - sub_v3_v3v3(r_center, r_center, ob->obmat[3]); - copy_m3_m4(mat, ob->obmat); - invert_m3_m3(imat, mat); - mul_m3_v3(imat, r_center); - } - } - } } void calculateCenterCursor2D(TransInfo *t, float r_center[2]) -- cgit v1.2.3