Fix repeated transform constraint orientations

On some occasions, as in cases where transform operations are triggered
via gizmos, the constrain orientations that can be toggled with
multiple clicks of X, Y or Z were repeated.

There is no use in maintaining repeated orientations.
This commit is contained in:
Germano Cavalcante 2023-01-26 07:54:04 -03:00 committed by Germano Cavalcante
parent f19f50d288
commit 3b4486424a
2 changed files with 27 additions and 12 deletions

View File

@ -1001,6 +1001,9 @@ void postSelectConstraint(TransInfo *t)
static void setNearestAxis2d(TransInfo *t)
{
/* Clear any prior constraint flags. */
t->con.mode &= ~(CON_AXIS0 | CON_AXIS1 | CON_AXIS2);
/* no correction needed... just use whichever one is lower */
if (abs(t->mval[0] - t->con.imval[0]) < abs(t->mval[1] - t->con.imval[1])) {
t->con.mode |= CON_AXIS1;
@ -1014,6 +1017,9 @@ static void setNearestAxis2d(TransInfo *t)
static void setNearestAxis3d(TransInfo *t)
{
/* Clear any prior constraint flags. */
t->con.mode &= ~(CON_AXIS0 | CON_AXIS1 | CON_AXIS2);
float zfac;
float mvec[3], proj[3];
float len[3];
@ -1090,10 +1096,7 @@ static void setNearestAxis3d(TransInfo *t)
void setNearestAxis(TransInfo *t)
{
/* clear any prior constraint flags */
t->con.mode &= ~CON_AXIS0;
t->con.mode &= ~CON_AXIS1;
t->con.mode &= ~CON_AXIS2;
eTConstraint mode_prev = t->con.mode;
/* constraint setting - depends on spacetype */
if (t->spacetype == SPACE_VIEW3D) {
@ -1105,7 +1108,9 @@ void setNearestAxis(TransInfo *t)
setNearestAxis2d(t);
}
projection_matrix_calc(t, t->con.pmtx);
if (mode_prev != t->con.mode) {
projection_matrix_calc(t, t->con.pmtx);
}
}
/** \} */

View File

@ -440,6 +440,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
{
short orient_types[3];
short orient_type_apply = O_DEFAULT;
float custom_matrix[3][3];
int orient_type_scene = V3D_ORIENT_GLOBAL;
@ -502,14 +503,23 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->is_orient_default_overwrite = true;
}
}
else if (t->con.mode & CON_APPLY) {
orient_type_set = orient_type_scene;
}
else if (orient_type_scene == V3D_ORIENT_GLOBAL) {
orient_type_set = V3D_ORIENT_LOCAL;
if (orient_type_set == -1) {
if (orient_type_scene == V3D_ORIENT_GLOBAL) {
orient_type_set = V3D_ORIENT_LOCAL;
}
else {
orient_type_set = V3D_ORIENT_GLOBAL;
}
if (t->con.mode & CON_APPLY) {
orient_type_apply = O_SCENE;
}
}
else {
orient_type_set = V3D_ORIENT_GLOBAL;
if (t->con.mode & CON_APPLY) {
orient_type_apply = O_SET;
}
}
BLI_assert(!ELEM(-1, orient_type_default, orient_type_set));
@ -546,7 +556,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
transform_orientations_current_set(t, (t->con.mode & CON_APPLY) ? 2 : 0);
transform_orientations_current_set(t, orient_type_apply);
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&