[Bf-blender-cvs] [8a432c1a406] master: Transform: shear redo support for other orientations

Campbell Barton noreply at git.blender.org
Wed Feb 27 14:24:52 CET 2019


Commit: 8a432c1a4061492fbb0b8c1880a2408444e8009a
Author: Campbell Barton
Date:   Thu Feb 28 00:19:37 2019 +1100
Branches: master
https://developer.blender.org/rB8a432c1a4061492fbb0b8c1880a2408444e8009a

Transform: shear redo support for other orientations

Shear gizmo now uses a single orientation and sets
different ortho axis instead of constructing a different matrix for
each handle - allowing the redo panel to select orientations.

===================================================================

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_gizmo_3d.c

===================================================================

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 53c5fbddcdb..0c9fe0fbaf9 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2159,15 +2159,29 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 		RNA_property_boolean_set(op->ptr, prop, (t->flag & T_NO_MIRROR) == 0);
 	}
 
-	short orientation = (t->con.mode & CON_APPLY) ? t->con.orientation : t->orientation.unset;
-	if (orientation == V3D_ORIENT_CUSTOM) {
-		const int orientation_index_custom = BKE_scene_transform_orientation_get_index(
-		        t->scene, t->orientation.custom);
-		/* Maybe we need a t->con.custom_orientation?
-		 * Seems like it would always match t->orientation.custom. */
-		orientation = V3D_ORIENT_CUSTOM + orientation_index_custom;
-		BLI_assert(orientation >= V3D_ORIENT_CUSTOM);
+	/* Orientastion used for redo. */
+	short orientation;
+	if (t->con.mode & CON_APPLY) {
+		orientation = t->con.orientation;
+		if (orientation == V3D_ORIENT_CUSTOM) {
+			const int orientation_index_custom = BKE_scene_transform_orientation_get_index(
+			        t->scene, t->orientation.custom);
+			/* Maybe we need a t->con.custom_orientation?
+			 * Seems like it would always match t->orientation.custom. */
+			orientation = V3D_ORIENT_CUSTOM + orientation_index_custom;
+			BLI_assert(orientation >= V3D_ORIENT_CUSTOM);
+		}
+	}
+	else if ((t->orientation.user == V3D_ORIENT_CUSTOM_MATRIX) &&
+	         (prop = RNA_struct_find_property(op->ptr, "orient_matrix_type")))
+	{
+		orientation = RNA_property_enum_get(op->ptr, prop);
 	}
+	else {
+		/* We're not using an orientation, use the fallback. */
+		orientation = t->orientation.unset;
+	}
+
 
 	if ((prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
 		if (t->flag & T_MODAL) {
@@ -2177,6 +2191,14 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
 					RNA_property_enum_set(op->ptr, prop, orient_axis);
 				}
 			}
+			else {
+				RNA_property_enum_set(op->ptr, prop, t->orient_axis);
+			}
+		}
+	}
+	if ((prop = RNA_struct_find_property(op->ptr, "orient_axis_ortho"))) {
+		if (t->flag & T_MODAL) {
+			RNA_property_enum_set(op->ptr, prop, t->orient_axis_ortho);
 		}
 	}
 
@@ -3414,6 +3436,11 @@ static void initShear_mouseInputMode(TransInfo *t)
 		cross_v3_v3v3(dir, t->orient_matrix[t->orient_axis_ortho], t->orient_matrix[t->orient_axis]);
 	}
 
+	/* Without this, half the gizmo handles move in the opposite direction. */
+	if ((t->orient_axis_ortho + 1) % 3 != t->orient_axis) {
+		negate_v3(dir);
+	}
+
 	mul_mat3_m4_v3(t->viewmat, dir);
 	if (normalize_v2(dir) == 0.0f) {
 		dir[0] = 1.0f;
@@ -3429,21 +3456,13 @@ static void initShear(TransInfo *t)
 	t->transform = applyShear;
 	t->handleEvent = handleEventShear;
 
-	t->orient_axis = 2;
-	t->orient_axis_ortho = 1;
-
+	if (t->orient_axis == t->orient_axis_ortho) {
+		t->orient_axis = 2;
+		t->orient_axis_ortho = 1;
+	}
 	if (t->orient_matrix_is_set == false) {
 		t->orient_matrix_is_set = true;
-		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);
-		}
+		copy_m3_m3(t->orient_matrix, t->spacemtx);
 	}
 
 	initShear_mouseInputMode(t);
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index fb52918de9b..46eeb049b42 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1518,6 +1518,13 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 		t->around = V3D_AROUND_CENTER_BOUNDS;
 	}
 
+	if ((prop = RNA_struct_find_property(op->ptr, "orient_axis"))) {
+		t->orient_axis = RNA_property_enum_get(op->ptr, prop);
+	}
+	if ((prop = RNA_struct_find_property(op->ptr, "orient_axis_ortho"))) {
+		t->orient_axis_ortho = RNA_property_enum_get(op->ptr, prop);
+	}
+
 	if (op && ((prop = RNA_struct_find_property(op->ptr, "orient_matrix")) &&
 	           RNA_property_is_set(op->ptr, prop)) &&
 	    ((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 1839b08f6a1..7cf526f69fc 100644
--- a/source/blender/editors/transform/transform_gizmo_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_3d.c
@@ -2203,18 +2203,13 @@ static void WIDGETGROUP_xform_shear_refresh(const bContext *C, wmGizmoGroup *gzg
 				WM_gizmo_set_matrix_rotation_from_yz_axis(gz, rv3d->twmat[i_ortho_a], rv3d->twmat[i]);
 				WM_gizmo_set_matrix_location(gz, rv3d->twmat[3]);
 
-				float axis[3];
-				if (j == 0) {
-					copy_v3_v3(axis, tbounds.axis[i_ortho_b]);
-				}
-				else {
-					negate_v3_v3(axis, tbounds.axis[i_ortho_b]);
-				}
-				float orient_matrix[3][3];
-				cross_v3_v3v3(orient_matrix[0], tbounds.axis[i_ortho_a], axis);
-				copy_v3_v3(orient_matrix[1], tbounds.axis[i_ortho_a]);
-				copy_v3_v3(orient_matrix[2], axis);
-				RNA_float_set_array(&gzop->ptr, "orient_matrix", &orient_matrix[0][0]);
+				RNA_float_set_array(&gzop->ptr, "orient_matrix", &tbounds.axis[0][0]);
+				RNA_enum_set(&gzop->ptr, "orient_type", orient_slot->type);
+				RNA_enum_set(&gzop->ptr, "orient_matrix_type", orient_slot->type);
+
+				RNA_enum_set(&gzop->ptr, "orient_axis", i_ortho_b);
+				RNA_enum_set(&gzop->ptr, "orient_axis_ortho", i_ortho_a);
+
 				mul_v3_fl(gz->matrix_basis[0], 0.5f);
 				mul_v3_fl(gz->matrix_basis[1], 6.0f);
 			}



More information about the Bf-blender-cvs mailing list