Transform: default to user-defined orientation

Previously we tried this but reverted (see 64d40c82c3)
because there wasn't a predictable set of keys to use global-space.

Now the keys are swapped:

- 'GX' always transforms in the user defined orientation.
- 'GXX' always transforms in global space.

As before 'GXXX' cycles back to disabling constraints.

This does have a down side that GXX won't be used for local-space
when the user has global space set.
Also, when global is the user-orientation, pressing GX and GXX
does the same thing.

Note: examples here use GX but could be any transform-mode/axis.
This commit is contained in:
2018-11-28 10:01:16 +11:00
parent 437d7d7cb9
commit 6491d50d02
5 changed files with 50 additions and 32 deletions

View File

@@ -992,13 +992,10 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, char cm
}
}
else if (!edit_2d) {
if (cmode == axis) {
if (t->con.orientation != V3D_MANIP_GLOBAL) {
stopConstraint(t);
}
else {
short orientation = (t->current_orientation != V3D_MANIP_GLOBAL ?
t->current_orientation : V3D_MANIP_LOCAL);
if (cmode != axis) {
/* First press, constraint to an axis. */
t->orientation.index = 1;
const short orientation = t->orientation.types[t->orientation.index];
if (is_plane == false) {
setUserConstraint(t, orientation, constraint_axis, msg2);
}
@@ -1006,13 +1003,21 @@ static void transform_event_xyz_constraint(TransInfo *t, short key_type, char cm
setUserConstraint(t, orientation, constraint_plane, msg3);
}
}
else {
/* Successive presses on existing axis, cycle orientation modes. */
t->orientation.index = (t->orientation.index + 1) % ARRAY_SIZE(t->orientation.types);
if (t->orientation.index == 0) {
stopConstraint(t);
}
else {
const short orientation = t->orientation.types[t->orientation.index];
if (is_plane == false) {
setUserConstraint(t, V3D_MANIP_GLOBAL, constraint_axis, msg2);
setUserConstraint(t, orientation, constraint_axis, msg2);
}
else {
setUserConstraint(t, V3D_MANIP_GLOBAL, constraint_plane, msg3);
setUserConstraint(t, orientation, constraint_plane, msg3);
}
}
}
}
@@ -2122,12 +2127,12 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
if (t->spacetype == SPACE_VIEW3D) {
if ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
!RNA_property_is_set(op->ptr, prop) &&
(t->current_orientation != V3D_MANIP_CUSTOM_MATRIX))
(t->orientation.user != V3D_MANIP_CUSTOM_MATRIX))
{
t->scene->orientation_type = t->current_orientation;
BLI_assert(((t->scene->orientation_index_custom == -1) && (t->custom_orientation == NULL)) ||
t->scene->orientation_type = t->orientation.user;
BLI_assert(((t->scene->orientation_index_custom == -1) && (t->orientation.custom == NULL)) ||
(BKE_scene_transform_orientation_get_index(
t->scene, t->custom_orientation) == t->scene->orientation_index_custom));
t->scene, t->orientation.custom) == t->scene->orientation_index_custom));
}
}
}
@@ -2153,13 +2158,13 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
/* constraint orientation can be global, even if user selects something else
* so use the orientation in the constraint if set */
short orientation = (t->con.mode & CON_APPLY) ? t->con.orientation : t->current_orientation;
short orientation = (t->con.mode & CON_APPLY) ? t->con.orientation : t->orientation.user;
if (orientation == V3D_MANIP_CUSTOM) {
const int orientation_index_custom = BKE_scene_transform_orientation_get_index(
t->scene, t->custom_orientation);
t->scene, t->orientation.custom);
/* Maybe we need a t->con.custom_orientation? Seems like it would always match t->custom_orientation. */
/* Maybe we need a t->con.custom_orientation? Seems like it would always match t->orientation.custom. */
orientation = V3D_MANIP_CUSTOM + orientation_index_custom;
BLI_assert(orientation >= V3D_MANIP_CUSTOM);
}
@@ -2420,7 +2425,7 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->con.mode |= CON_AXIS2;
}
setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
setUserConstraint(t, t->orientation.user, t->con.mode, "%s");
}
}

View File

@@ -503,8 +503,14 @@ typedef struct TransInfo {
/*************** NEW STUFF *********************/
short launch_event; /* event type used to launch transform */
short current_orientation;
TransformOrientation *custom_orientation; /* this gets used when current_orientation is V3D_MANIP_CUSTOM */
/* Always: 'orientation_types[orientation_index]' */
struct {
short user;
short index;
short types[3];
/* this gets used when current_orientation is V3D_MANIP_CUSTOM */
TransformOrientation *custom;
} orientation;
short gizmo_flag; /* backup from view3d, to restore on end */
short prop_mode;

View File

@@ -709,7 +709,7 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
{
char orientation_str[128];
BLI_snprintf(orientation_str, sizeof(orientation_str), "%s \"%s\"",
IFACE_("custom orientation"), t->custom_orientation->name);
IFACE_("custom orientation"), t->orientation.custom->name);
BLI_snprintf(text, sizeof(text), ftext, orientation_str);
setConstraint(t, t->spacemtx, mode, text);
break;

View File

@@ -1395,10 +1395,17 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->around = V3D_AROUND_CURSOR;
}
t->current_orientation = t->scene->orientation_type;
t->custom_orientation = BKE_scene_transform_orientation_find(
t->orientation.user = t->scene->orientation_type;
t->orientation.custom = BKE_scene_transform_orientation_find(
t->scene, t->scene->orientation_index_custom);
t->orientation.index = 0;
ARRAY_SET_ITEMS(
t->orientation.types,
V3D_MANIP_GLOBAL, /* Value isn't used (first index is no constraint). */
t->orientation.user,
V3D_MANIP_GLOBAL);
/* exceptional case */
if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
@@ -1489,8 +1496,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
RNA_property_is_set(op->ptr, prop)))
{
RNA_property_float_get_array(op->ptr, prop, &t->spacemtx[0][0]);
t->current_orientation = V3D_MANIP_CUSTOM_MATRIX;
t->custom_orientation = 0;
t->orientation.user = V3D_MANIP_CUSTOM_MATRIX;
t->orientation.custom = 0;
}
else if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
RNA_property_is_set(op->ptr, prop)))
@@ -1509,8 +1516,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
t->current_orientation = orientation;
t->custom_orientation = custom_orientation;
t->orientation.user = orientation;
t->orientation.custom = custom_orientation;
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&

View File

@@ -432,7 +432,7 @@ void initTransformOrientation(bContext *C, TransInfo *t)
Object *ob = CTX_data_active_object(C);
Object *obedit = CTX_data_active_object(C);
switch (t->current_orientation) {
switch (t->orientation.user) {
case V3D_MANIP_GLOBAL:
unit_m3(t->spacemtx);
BLI_strncpy(t->spacename, IFACE_("global"), sizeof(t->spacename));
@@ -492,9 +492,9 @@ void initTransformOrientation(bContext *C, TransInfo *t)
BLI_strncpy(t->spacename, IFACE_("custom"), sizeof(t->spacename));
break;
case V3D_MANIP_CUSTOM:
BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename));
BLI_strncpy(t->spacename, t->orientation.custom->name, sizeof(t->spacename));
if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) {
if (applyTransformOrientation(t->orientation.custom, t->spacemtx, t->spacename)) {
/* pass */
}
else {