[Bf-blender-cvs] [6ebad22091c] master: Transform: fix rotate redo behavior
Campbell Barton
noreply at git.blender.org
Tue Feb 26 11:18:11 CET 2019
Commit: 6ebad22091c06f1e11e5efca7f19b1800e91fe09
Author: Campbell Barton
Date: Tue Feb 26 20:22:54 2019 +1100
Branches: master
https://developer.blender.org/rB6ebad22091c06f1e11e5efca7f19b1800e91fe09
Transform: fix rotate redo behavior
- Add XYZ option.
- Orientation now works as expected.
Now a redo for rotation works logically,
setting the axis to Z & the orientation to view.
Resolves T57205
===================================================================
M source/blender/editors/include/ED_transform.h
M source/blender/editors/transform/transform.c
M source/blender/editors/transform/transform.h
M source/blender/editors/transform/transform_generics.c
M source/blender/editors/transform/transform_gizmo_3d.c
M source/blender/editors/transform/transform_ops.c
===================================================================
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 08f1dc37e75..88e821091f5 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -134,8 +134,8 @@ int BIF_countTransformOrientation(const struct bContext *C);
#define P_MIRROR (1 << 0)
#define P_MIRROR_DUMMY (P_MIRROR | (1 << 9))
#define P_PROPORTIONAL (1 << 1)
-#define P_AXIS (1 << 2)
-#define P_AXIS_ORTHO (1 << 16)
+#define P_ORIENT_AXIS (1 << 2)
+#define P_ORIENT_AXIS_ORTHO (1 << 16)
#define P_SNAP (1 << 3)
#define P_GEO_SNAP (P_SNAP | (1 << 4))
#define P_ALIGN_SNAP (P_GEO_SNAP | (1 << 5))
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index e10d32716ac..9e86c4cb686 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2156,12 +2156,15 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
RNA_float_set(op->ptr, "proportional_size", t->prop_size);
}
- if ((prop = RNA_struct_find_property(op->ptr, "axis"))) {
- RNA_property_float_set_array(op->ptr, prop, t->axis);
- }
-
- if ((prop = RNA_struct_find_property(op->ptr, "axis_ortho"))) {
- RNA_property_float_set_array(op->ptr, prop, t->axis_ortho);
+ if ((prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
+ if (t->flag & T_MODAL) {
+ if (t->con.mode & CON_APPLY) {
+ int orient_axis = constraintModeToIndex(t);
+ if (orient_axis != -1) {
+ RNA_property_enum_set(op->ptr, prop, orient_axis);
+ }
+ }
+ }
}
if ((prop = RNA_struct_find_property(op->ptr, "mirror"))) {
@@ -2194,9 +2197,12 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
RNA_enum_set(op->ptr, "constraint_matrix_orientation", orientation);
}
}
- if (t->con.mode & CON_APPLY || (t->orientation.unset != V3D_ORIENT_GLOBAL)) {
+ if (t->con.mode & CON_APPLY) {
RNA_float_set_array(op->ptr, "constraint_matrix", &t->con.mtx[0][0]);
}
+ else if (t->orient_matrix_is_set) {
+ RNA_float_set_array(op->ptr, "constraint_matrix", &t->orient_matrix[0][0]);
+ }
else {
RNA_float_set_array(op->ptr, "constraint_matrix", &t->spacemtx[0][0]);
}
@@ -2577,15 +2583,15 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
/* Transformation axis from operator */
- if ((prop = RNA_struct_find_property(op->ptr, "axis")) && RNA_property_is_set(op->ptr, prop)) {
- RNA_property_float_get_array(op->ptr, prop, t->axis);
- normalize_v3(t->axis);
- copy_v3_v3(t->axis_orig, t->axis);
+ if ((prop = RNA_struct_find_property(op->ptr, "orient_axis")) &&
+ RNA_property_is_set(op->ptr, prop))
+ {
+ t->orient_axis = RNA_property_enum_get(op->ptr, prop);
}
-
- if ((prop = RNA_struct_find_property(op->ptr, "axis_ortho")) && RNA_property_is_set(op->ptr, prop)) {
- RNA_property_float_get_array(op->ptr, prop, t->axis_ortho);
- normalize_v3(t->axis_ortho);
+ if ((prop = RNA_struct_find_property(op->ptr, "orient_axis_ortho")) &&
+ RNA_property_is_set(op->ptr, prop))
+ {
+ t->orient_axis_ortho = RNA_property_enum_get(op->ptr, prop);
}
/* Constraint init from operator */
@@ -3396,10 +3402,10 @@ static void initShear_mouseInputMode(TransInfo *t)
float dir[3];
if (t->custom.mode.data == NULL) {
- copy_v3_v3(dir, t->axis_ortho);
+ copy_v3_v3(dir, t->orient_matrix[t->orient_axis_ortho]);
}
else {
- cross_v3_v3v3(dir, t->axis_ortho, t->axis);
+ cross_v3_v3v3(dir, t->orient_matrix[t->orient_axis_ortho], t->orient_matrix[t->orient_axis]);
}
mul_mat3_m4_v3(t->viewmat, dir);
@@ -3417,13 +3423,20 @@ static void initShear(TransInfo *t)
t->transform = applyShear;
t->handleEvent = handleEventShear;
- if (is_zero_v3(t->axis)) {
- negate_v3_v3(t->axis, t->viewinv[2]);
- normalize_v3(t->axis);
- }
- if (is_zero_v3(t->axis_ortho)) {
- copy_v3_v3(t->axis_ortho, t->viewinv[0]);
- normalize_v3(t->axis_ortho);
+ t->orient_axis = 2;
+ t->orient_axis_ortho = 1;
+
+ if (t->orient_matrix_is_set == false) {
+ float *axis = t->orient_matrix[t->orient_axis];
+ float *axis_ortho = t->orient_matrix[t->orient_axis_ortho];
+ if (is_zero_v3(axis)) {
+ negate_v3_v3(axis, t->viewinv[2]);
+ normalize_v3(axis);
+ }
+ if (is_zero_v3(axis_ortho)) {
+ copy_v3_v3(axis_ortho, t->viewinv[0]);
+ normalize_v3(axis_ortho);
+ }
}
initShear_mouseInputMode(t);
@@ -3512,8 +3525,8 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
else
smat[0][1] = value;
- copy_v3_v3(axismat_inv[0], t->axis_ortho);
- copy_v3_v3(axismat_inv[2], t->axis);
+ copy_v3_v3(axismat_inv[0], t->orient_matrix[t->orient_axis_ortho]);
+ copy_v3_v3(axismat_inv[2], t->orient_matrix[t->orient_axis]);
cross_v3_v3v3(axismat_inv[1], axismat_inv[0], axismat_inv[2]);
invert_m3_m3(axismat, axismat_inv);
@@ -4100,8 +4113,10 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
static void postInputRotation(TransInfo *t, float values[3])
{
+ float axis_final[3];
+ copy_v3_v3(axis_final, t->orient_matrix[t->orient_axis]);
if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
- t->con.applyRot(t, NULL, NULL, t->axis, values);
+ t->con.applyRot(t, NULL, NULL, axis_final, values);
}
}
@@ -4127,17 +4142,16 @@ static void initRotation(TransInfo *t)
if (t->flag & T_2D_EDIT)
t->flag |= T_NO_CONSTRAINT;
- if (t->options & CTX_PAINT_CURVE) {
- t->axis[0] = 0.0;
- t->axis[1] = 0.0;
- t->axis[2] = -1.0;
- }
- else {
- negate_v3_v3(t->axis, t->viewinv[2]);
- normalize_v3(t->axis);
+ if (t->orient_matrix_is_set == false) {
+ if ((t->options & CTX_PAINT_CURVE) == 0) {
+ t->orientation.unset = V3D_ORIENT_VIEW;
+ copy_m3_m4(t->orient_matrix, t->viewinv);
+ normalize_m3(t->orient_matrix);
+ negate_m3(t->orient_matrix);
+ }
}
- copy_v3_v3(t->axis_orig, t->axis);
+ t->orient_axis = 2;
}
/* Used by Transform Rotation and Transform Normal Rotation */
@@ -4446,12 +4460,11 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
snapGridIncrement(t, &final);
+ float axis_final[3];
+ copy_v3_v3(axis_final, t->orient_matrix[t->orient_axis]);
+
if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
- t->con.applyRot(t, NULL, NULL, t->axis, NULL);
- }
- else {
- /* reset axis if constraint is not set */
- copy_v3_v3(t->axis, t->axis_orig);
+ t->con.applyRot(t, NULL, NULL, axis_final, NULL);
}
applySnapping(t, &final);
@@ -4463,7 +4476,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
headerRotation(t, str, final);
- applyRotationValue(t, final, t->axis);
+ applyRotationValue(t, final, axis_final);
recalcData(t);
@@ -4654,10 +4667,14 @@ static void initNormalRotation(TransInfo *t)
storeCustomLNorValue(tc, bm);
}
- negate_v3_v3(t->axis, t->viewinv[2]);
- normalize_v3(t->axis);
+ if (t->orient_matrix_is_set == false) {
+ t->orientation.unset = V3D_ORIENT_VIEW;
+ copy_m3_m4(t->orient_matrix, t->viewinv);
+ normalize_m3(t->orient_matrix);
+ negate_m3(t->orient_matrix);
+ }
- copy_v3_v3(t->axis_orig, t->axis);
+ t->orient_axis = 2;
}
/* Works by getting custom normal from clnor_data, transform, then store */
@@ -4665,12 +4682,11 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2]))
{
char str[UI_MAX_DRAW_STR];
+ float axis_final[3];
+ copy_v3_v3(axis_final, t->orient_matrix[t->orient_axis]);
+
if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
- t->con.applyRot(t, NULL, NULL, t->axis, NULL);
- }
- else {
- /* reset axis if constraint is not set */
- copy_v3_v3(t->axis, t->axis_orig);
+ t->con.applyRot(t, NULL, NULL, axis_final, NULL);
}
FOREACH_TRANS_DATA_CONTAINER(t, tc) {
@@ -4683,7 +4699,7 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2]))
float axis[3];
float mat[3][3];
float angle = t->values[0];
- copy_v3_v3(axis, t->axis);
+ copy_v3_v3(axis, axis_final);
snapGridIncrement(t, &angle);
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index b234dabdc0b..d6121948b90 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -628,10 +628,11 @@ typedef struct TransInfo {
/** Offset applied ontop of modal input. */
float values_modal_offset[4];
float auto_values[4];
- float axis[3];
- /** TransCon can change 'axis', store the original value here. */
- float axis_orig[3];
- float axis_ortho[3];
+
+ int orient_axis;
+ int orient_axis_ortho;
+ float orient_matrix[3][3];
+ bool orient_matrix_is_set;
/** remove elements if operator is canceled. */
bool remove_on_cancel;
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 9dc64d9fd49..0e848227378 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1337,6 +1337,11 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
unit_m3(t->mat);
+ unit_m3(t->orient_matrix);
+ negate_m3(t->orient_matrix);
+ /* Leave 't->orient_matrix_is_set' to false,
+ * so we overwrite it when we have a useful value. */
+
/* if there's an event, we're modal */
if (event) {
t->flag |= T_MODAL;
@@ -1522,6 +1527,9 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
RNA_enum_get(op->ptr, "constraint_matrix_orientation"))))
{
RNA_property_float_get_array(op->ptr, prop, &t->spacemtx[0][0]);
+ /* Some transform modes use this to operate on an axis. */
+ copy_m3_m3(t->orient_matrix, t->spacemtx);
+ t->orient_matrix_is_set = true;
t->orientation.user = V3D_ORIENT_CUSTOM_MATRIX;
t->orientation.custom = 0;
if (t->flag & T_MODAL) {
diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c
index bba91ec3b00..efc3bfdb5c2 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -1325,7 +1325,7 @@ void drawDial
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list