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.
This commit is contained in:
Antonio Vazquez 2018-12-03 16:26:31 +01:00
parent 3235a3081c
commit fadad895b2
Notes: blender-bot 2023-05-22 12:40:41 +02:00
Referenced by issue #58338, GP Edit Mode rotation doesn't work if object is far away from world origin
3 changed files with 11 additions and 68 deletions

View File

@ -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,

View File

@ -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);

View File

@ -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])