[Bf-blender-cvs] [80fb943e4f5] blender2.8: Transform: map mouse input to shear direction

Campbell Barton noreply at git.blender.org
Wed Oct 17 08:19:19 CEST 2018


Commit: 80fb943e4f5326aa5cdebb7be1c54044bcc6da92
Author: Campbell Barton
Date:   Wed Oct 17 16:30:15 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB80fb943e4f5326aa5cdebb7be1c54044bcc6da92

Transform: map mouse input to shear direction

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

M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_input.c

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

diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 989e7e9c924..ec689808ce3 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -3341,13 +3341,42 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
 /** \name Transform Shear
  * \{ */
 
+static void initShear_mouseInputMode(TransInfo *t)
+{
+	float dir[3];
+
+	if (t->custom.mode.data == NULL) {
+		copy_v3_v3(dir, t->axis_ortho);
+	}
+	else {
+		cross_v3_v3v3(dir, t->axis_ortho, t->axis);
+	}
+
+	mul_mat3_m4_v3(t->viewmat, dir);
+	if (normalize_v2(dir) == 0.0f) {
+		dir[0] = 1.0f;
+	}
+	setCustomPointsFromDirection(t, &t->mouse, dir);
+
+	initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO);
+}
+
 static void initShear(TransInfo *t)
 {
 	t->mode = TFM_SHEAR;
 	t->transform = applyShear;
 	t->handleEvent = handleEventShear;
 
-	initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
+	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);
+	}
+
+	initShear_mouseInputMode(t);
 
 	t->idx_max = 0;
 	t->num.idx_max = 0;
@@ -3360,15 +3389,6 @@ static void initShear(TransInfo *t)
 	t->num.unit_type[0] = B_UNIT_NONE;  /* Don't think we have any unit here? */
 
 	t->flag |= T_NO_CONSTRAINT;
-
-	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);
-	}
 }
 
 static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
@@ -3378,25 +3398,24 @@ static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
 	if (event->type == MIDDLEMOUSE && event->val == KM_PRESS) {
 		/* Use custom.mode.data pointer to signal Shear direction */
 		if (t->custom.mode.data == NULL) {
-			initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_RATIO);
 			t->custom.mode.data = (void *)1;
 		}
 		else {
-			initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
 			t->custom.mode.data = NULL;
 		}
+		initShear_mouseInputMode(t);
 
 		status = TREDRAW_HARD;
 	}
 	else if (event->type == XKEY && event->val == KM_PRESS) {
-		initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO);
 		t->custom.mode.data = NULL;
+		initShear_mouseInputMode(t);
 
 		status = TREDRAW_HARD;
 	}
 	else if (event->type == YKEY && event->val == KM_PRESS) {
-		initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_RATIO);
 		t->custom.mode.data = (void *)1;
+		initShear_mouseInputMode(t);
 
 		status = TREDRAW_HARD;
 	}
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 7d981f86e38..d777b034e76 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -825,6 +825,7 @@ eRedrawFlag handleMouseInput(struct TransInfo *t, struct MouseInput *mi, const s
 void applyMouseInput(struct TransInfo *t, struct MouseInput *mi, const int mval[2], float output[3]);
 
 void setCustomPoints(TransInfo *t, MouseInput *mi, const int start[2], const int end[2]);
+void setCustomPointsFromDirection(TransInfo *t, MouseInput *mi, const float dir[2]);
 void setInputPostFct(MouseInput *mi, void	(*post)(struct TransInfo *t, float values[3]));
 
 /*********************** Generics ********************************/
diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c
index 971b9f74c65..cdac18f7584 100644
--- a/source/blender/editors/transform/transform_input.c
+++ b/source/blender/editors/transform/transform_input.c
@@ -137,6 +137,18 @@ void setCustomPoints(TransInfo *UNUSED(t), MouseInput *mi, const int mval_start[
 	data[3] = mval_end[1];
 }
 
+void setCustomPointsFromDirection(TransInfo *t, MouseInput *mi, const float dir[2])
+{
+	BLI_ASSERT_UNIT_V2(dir);
+	const int win_axis = t->ar ? ((abs(t->ar->winx * dir[0]) + abs(t->ar->winy * dir[1])) / 2) : 1;
+	const int mval_start[2] = {
+		mi->imval[0] + dir[0] * win_axis,
+		mi->imval[1] + dir[1] * win_axis,
+	};
+	const int mval_end[2] = {mi->imval[0], mi->imval[1]};
+	setCustomPoints(t, mi, mval_start, mval_end);
+}
+
 static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const double mval[2], float output[3])
 {
 	double length;



More information about the Bf-blender-cvs mailing list