[Bf-blender-cvs] [77a80d9f2ff] blender2.8: Gizmo: show dial handle for unconstrained extrude

Campbell Barton noreply at git.blender.org
Wed Nov 21 07:17:12 CET 2018


Commit: 77a80d9f2ff98619c383a1d46e69c1bbcc3a68b7
Author: Campbell Barton
Date:   Wed Nov 21 17:15:53 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB77a80d9f2ff98619c383a1d46e69c1bbcc3a68b7

Gizmo: show dial handle for unconstrained extrude

Now only show an arrow when extrude was constrained on an axis.

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

M	source/blender/editors/transform/transform_gizmo_extrude_3d.c

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

diff --git a/source/blender/editors/transform/transform_gizmo_extrude_3d.c b/source/blender/editors/transform/transform_gizmo_extrude_3d.c
index 58017b7cac4..1dc50f476fa 100644
--- a/source/blender/editors/transform/transform_gizmo_extrude_3d.c
+++ b/source/blender/editors/transform/transform_gizmo_extrude_3d.c
@@ -62,6 +62,7 @@ static const float extrude_button_offset_scale = 1.5f;
 static const float extrude_arrow_scale = 1.0f;
 static const float extrude_arrow_xyz_axis_scale = 1.0f;
 static const float extrude_arrow_normal_axis_scale = 1.0f;
+static const float extrude_dial_scale = 0.2;
 
 static const uchar shape_plus[] = {
 	0x5f, 0xfb, 0x40, 0xee, 0x25, 0xda, 0x11, 0xbf, 0x4, 0xa0, 0x0, 0x80, 0x4, 0x5f, 0x11,
@@ -75,8 +76,9 @@ static const uchar shape_plus[] = {
 typedef struct GizmoExtrudeGroup {
 
 	/* XYZ & normal. */
-	struct wmGizmo *invoke_xyz_no[4];
-	struct wmGizmo *adjust;
+	wmGizmo *invoke_xyz_no[4];
+	/* Constrained & unconstrained (arrow & circle). */
+	wmGizmo *adjust[2];
 	int             adjust_axis;
 
 	/* Copied from the transform operator,
@@ -115,10 +117,10 @@ static void gizmo_mesh_extrude_orientation_matrix_set_for_adjust(
 {
 	/* Set orientation without location. */
 	for (int j = 0; j < 3; j++) {
-		copy_v3_v3(ggd->adjust->matrix_basis[j], mat[j]);
+		copy_v3_v3(ggd->adjust[0]->matrix_basis[j], mat[j]);
 	}
 	/* nop when (i == 2). */
-	swap_v3_v3(ggd->adjust->matrix_basis[ggd->adjust_axis], ggd->adjust->matrix_basis[2]);
+	swap_v3_v3(ggd->adjust[0]->matrix_basis[ggd->adjust_axis], ggd->adjust[0]->matrix_basis[2]);
 }
 
 static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup)
@@ -128,8 +130,10 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup)
 
 	const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
 	const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_button_2d", true);
+	const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true);
 
-	ggd->adjust = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL);
+	ggd->adjust[0] = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL);
+	ggd->adjust[1] = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
 	for (int i = 0; i < 4; i++) {
 		ggd->invoke_xyz_no[i] = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL);
 		ggd->invoke_xyz_no[i]->flag |= WM_GIZMO_DRAW_OFFSET_SCALE;
@@ -170,14 +174,16 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup)
 		UI_GetThemeColor3fv(TH_AXIS_X + i, ggd->invoke_xyz_no[i]->color);
 	}
 	UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->invoke_xyz_no[3]->color);
-	UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->adjust->color);
+	for (int i = 0; i < 2; i++) {
+		UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->adjust[i]->color);
+	}
 
 	for (int i = 0; i < 4; i++) {
 		WM_gizmo_set_scale(ggd->invoke_xyz_no[i], extrude_button_scale);
 	}
-	WM_gizmo_set_scale(ggd->adjust, extrude_arrow_scale);
-
-	WM_gizmo_set_flag(ggd->adjust, WM_GIZMO_DRAW_VALUE, true);
+	WM_gizmo_set_scale(ggd->adjust[0], extrude_arrow_scale);
+	WM_gizmo_set_scale(ggd->adjust[1], extrude_dial_scale);
+	ggd->adjust[1]->line_width = 2.0f;
 
 	/* XYZ & normal axis extrude. */
 	for (int i = 0; i < 4; i++) {
@@ -192,11 +198,12 @@ static void gizmo_mesh_extrude_setup(const bContext *C, wmGizmoGroup *gzgroup)
 	}
 
 	/* Adjust extrude. */
-	{
-		PointerRNA *ptr = WM_gizmo_operator_set(ggd->adjust, 0, ggd->ot_extrude, NULL);
+	for (int i = 0; i < 2; i++) {
+		wmGizmo *gz = ggd->adjust[i];
+		PointerRNA *ptr = WM_gizmo_operator_set(gz, 0, ggd->ot_extrude, NULL);
 		PointerRNA macroptr = RNA_pointer_get(ptr, "TRANSFORM_OT_translate");
 		RNA_boolean_set(&macroptr, "release_confirm", true);
-		wmGizmoOpElem *gzop = WM_gizmo_operator_get(ggd->adjust, 0);
+		wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0);
 		gzop->is_redo = true;
 	}
 }
@@ -208,7 +215,9 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 	for (int i = 0; i < 4; i++) {
 		WM_gizmo_set_flag(ggd->invoke_xyz_no[i], WM_GIZMO_HIDDEN, true);
 	}
-	WM_gizmo_set_flag(ggd->adjust, WM_GIZMO_HIDDEN, true);
+	for (int i = 0; i < 2; i++) {
+		WM_gizmo_set_flag(ggd->adjust[i], WM_GIZMO_HIDDEN, true);
+	}
 
 	if (G.moving) {
 		return;
@@ -271,7 +280,10 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 	wmOperator *op_xform = has_redo ? op->macro.last : NULL;
 
 	bool adjust_is_flip = false;
+	wmGizmo *gz_adjust = NULL;
+
 	if (has_redo) {
+		gz_adjust = ggd->adjust[1];
 		/* We can't access this from 'ot->last_properties'
 		 * because some properties use skip-save. */
 		RNA_float_get_array(op_xform->ptr, "constraint_matrix", &ggd->redo_xform.constraint_matrix[0][0]);
@@ -283,6 +295,7 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 			if (ggd->redo_xform.constraint_axis[i]) {
 				adjust_is_flip = ggd->redo_xform.value[i] < 0.0f;
 				ggd->adjust_axis = i;
+				gz_adjust = ggd->adjust[0];
 				break;
 			}
 		}
@@ -290,26 +303,26 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 
 	/* Needed for normal orientation. */
 	gizmo_mesh_extrude_orientation_matrix_set(ggd, tbounds.axis);
-	if (has_redo) {
-		gizmo_mesh_extrude_orientation_matrix_set_for_adjust(ggd, ggd->redo_xform.constraint_matrix);
-		if (adjust_is_flip) {
-			negate_v3(ggd->adjust->matrix_basis[2]);
-		}
-	}
 
 	/* Location. */
 	for (int i = 0; i < axis_len_used; i++) {
 		WM_gizmo_set_matrix_location(ggd->invoke_xyz_no[i], tbounds.center);
 	}
-	WM_gizmo_set_matrix_location(ggd->adjust, tbounds.center);
-
 	/* Un-hide. */
 	for (int i = 0; i < axis_len_used; i++) {
 		WM_gizmo_set_flag(ggd->invoke_xyz_no[i], WM_GIZMO_HIDDEN, false);
 	}
-	WM_gizmo_set_flag(ggd->adjust, WM_GIZMO_HIDDEN, !has_redo);
 
-	/* Operator properties. */
+	if (has_redo) {
+		if (gz_adjust == ggd->adjust[0]) {
+			gizmo_mesh_extrude_orientation_matrix_set_for_adjust(ggd, ggd->redo_xform.constraint_matrix);
+			if (adjust_is_flip) {
+				negate_v3(ggd->adjust[0]->matrix_basis[2]);
+			}
+		}
+		WM_gizmo_set_matrix_location(gz_adjust, tbounds.center);
+		WM_gizmo_set_flag(gz_adjust, WM_GIZMO_HIDDEN, false);
+	}
 
 	/* Redo with current settings. */
 	if (has_redo) {
@@ -317,7 +330,8 @@ static void gizmo_mesh_extrude_refresh(const bContext *C, wmGizmoGroup *gzgroup)
 			RNA_enum_set(
 			        ggd->invoke_xyz_no[i]->ptr,
 			        "draw_options",
-			        (dot_v3v3(ggd->adjust->matrix_basis[2],
+			        ((gz_adjust == ggd->adjust[0]) &&
+			         dot_v3v3(ggd->adjust[0]->matrix_basis[2],
 			                  ggd->invoke_xyz_no[i]->matrix_offset[3]) > 0.98f) ? 0 : ED_GIZMO_BUTTON_SHOW_HELPLINE);
 		}
 	}
@@ -362,18 +376,26 @@ static void gizmo_mesh_extrude_draw_prepare(const bContext *C, wmGizmoGroup *gzg
 			gz->temp.f = dot_v3v3(rv3d->viewinv[2], gz->matrix_offset[3]);
 		}
 		BLI_listbase_sort(&gzgroup->gizmos, WM_gizmo_cmp_temp_fl_reverse);
+
+		if ((ggd->adjust[1]->flag & WM_GIZMO_HIDDEN) == 0) {
+			copy_v3_v3(ggd->adjust[1]->matrix_basis[0], rv3d->viewinv[0]);
+			copy_v3_v3(ggd->adjust[1]->matrix_basis[1], rv3d->viewinv[1]);
+			copy_v3_v3(ggd->adjust[1]->matrix_basis[2], rv3d->viewinv[2]);
+		}
 	}
 }
 
 static void gizmo_mesh_extrude_invoke_prepare(const bContext *UNUSED(C), wmGizmoGroup *gzgroup, wmGizmo *gz)
 {
 	GizmoExtrudeGroup *ggd = gzgroup->customdata;
-	if (gz == ggd->adjust) {
+	if (ELEM(gz, ggd->adjust[0], ggd->adjust[1])) {
 		/* Set properties for redo. */
-		wmGizmoOpElem *gzop = WM_gizmo_operator_get(ggd->adjust, 0);
+		wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0);
 		PointerRNA macroptr = RNA_pointer_get(&gzop->ptr, "TRANSFORM_OT_translate");
-		RNA_float_set_array(&macroptr, "constraint_matrix", &ggd->redo_xform.constraint_matrix[0][0]);
-		RNA_boolean_set_array(&macroptr, "constraint_axis", ggd->redo_xform.constraint_axis);
+		if (gz == ggd->adjust[0]) {
+			RNA_float_set_array(&macroptr, "constraint_matrix", &ggd->redo_xform.constraint_matrix[0][0]);
+			RNA_boolean_set_array(&macroptr, "constraint_axis", ggd->redo_xform.constraint_axis);
+		}
 		RNA_float_set_array(&macroptr, "value", ggd->redo_xform.value);
 	}
 	else {



More information about the Bf-blender-cvs mailing list