[Bf-blender-cvs] [03bccd0010f] blender2.8: Cleanup: move editmesh spin gizmo into own file

Campbell Barton noreply at git.blender.org
Tue Sep 18 01:45:07 CEST 2018


Commit: 03bccd0010f158bdb4ccd4c5263978a2630e9985
Author: Campbell Barton
Date:   Tue Sep 18 09:47:56 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB03bccd0010f158bdb4ccd4c5263978a2630e9985

Cleanup: move editmesh spin gizmo into own file

To mix both initial spin and redo ends up being more involved,
move into own file.

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

M	source/blender/editors/mesh/CMakeLists.txt
M	source/blender/editors/mesh/editmesh_extrude_spin.c
A	source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
M	source/blender/editors/mesh/mesh_intern.h

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

diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt
index 592b87fe20c..7dfdf0729c0 100644
--- a/source/blender/editors/mesh/CMakeLists.txt
+++ b/source/blender/editors/mesh/CMakeLists.txt
@@ -50,6 +50,7 @@ set(SRC
 	editmesh_extrude.c
 	editmesh_extrude_screw.c
 	editmesh_extrude_spin.c
+	editmesh_extrude_spin_gizmo.c
 	editmesh_inset.c
 	editmesh_intersect.c
 	editmesh_knife.c
diff --git a/source/blender/editors/mesh/editmesh_extrude_spin.c b/source/blender/editors/mesh/editmesh_extrude_spin.c
index ec15919ab4e..87814bc44c6 100644
--- a/source/blender/editors/mesh/editmesh_extrude_spin.c
+++ b/source/blender/editors/mesh/editmesh_extrude_spin.c
@@ -56,400 +56,6 @@
 
 #define USE_GIZMO
 
-#ifdef USE_GIZMO
-#include "ED_gizmo_library.h"
-#include "ED_undo.h"
-#endif
-
-/* -------------------------------------------------------------------- */
-/** \name Spin Gizmo
- * \{ */
-
-#ifdef USE_GIZMO
-typedef struct GizmoSpinGroup {
-	/* Arrow to change plane depth. */
-	struct wmGizmo *translate_z;
-	/* Translate XYZ */
-	struct wmGizmo *translate_c;
-	/* For grabbing the gizmo and moving freely. */
-	struct wmGizmo *rotate_c;
-	/* Spin angle */
-	struct wmGizmo *angle_z;
-
-	/* We could store more vars here! */
-	struct {
-		bContext *context;
-		wmOperatorType *ot;
-		wmOperator *op;
-		PropertyRNA *prop_axis_co;
-		PropertyRNA *prop_axis_no;
-		PropertyRNA *prop_angle;
-
-		float rotate_axis[3];
-		float rotate_up[3];
-	} data;
-} GizmoSpinGroup;
-
-/**
- * XXX. calling redo from property updates is not great.
- * This is needed because changing the RNA doesn't cause a redo
- * and we're not using operator UI which does just this.
- */
-static void gizmo_spin_exec(GizmoSpinGroup *ggd)
-{
-	wmOperator *op = ggd->data.op;
-	if (op == WM_operator_last_redo((bContext *)ggd->data.context)) {
-		ED_undo_operator_repeat((bContext *)ggd->data.context, op);
-	}
-}
-
-static void gizmo_mesh_spin_update_from_op(GizmoSpinGroup *ggd)
-{
-	wmOperator *op = ggd->data.op;
-
-	float plane_co[3], plane_no[3];
-
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
-
-	WM_gizmo_set_matrix_location(ggd->translate_z, plane_co);
-	WM_gizmo_set_matrix_location(ggd->rotate_c, plane_co);
-	WM_gizmo_set_matrix_location(ggd->angle_z, plane_co);
-	/* translate_c location comes from the property. */
-
-	WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_z, plane_no);
-	WM_gizmo_set_matrix_rotation_from_z_axis(ggd->angle_z, plane_no);
-
-	WM_gizmo_set_scale(ggd->translate_c, 0.2);
-
-	RegionView3D *rv3d = ED_view3d_context_rv3d(ggd->data.context);
-	if (rv3d) {
-		normalize_v3_v3(ggd->data.rotate_axis, rv3d->viewinv[2]);
-		normalize_v3_v3(ggd->data.rotate_up, rv3d->viewinv[1]);
-
-		/* ensure its orthogonal */
-		project_plane_normalized_v3_v3v3(ggd->data.rotate_up, ggd->data.rotate_up, ggd->data.rotate_axis);
-		normalize_v3(ggd->data.rotate_up);
-
-		WM_gizmo_set_matrix_rotation_from_z_axis(ggd->translate_c, plane_no);
-		WM_gizmo_set_matrix_rotation_from_yz_axis(ggd->rotate_c, plane_no, ggd->data.rotate_axis);
-
-		/* show the axis instead of mouse cursor */
-		RNA_enum_set(ggd->rotate_c->ptr, "draw_options",
-		             ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_MIRROR |
-		             ED_GIZMO_DIAL_DRAW_FLAG_ANGLE_START_Y);
-
-	}
-}
-
-/* depth callbacks */
-static void gizmo_spin_prop_depth_get(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	float plane_co[3], plane_no[3];
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
-
-	value[0] = dot_v3v3(plane_no, plane_co) - dot_v3v3(plane_no, gz->matrix_basis[3]);
-}
-
-static void gizmo_spin_prop_depth_set(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        const void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	const float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	float plane_co[3], plane[4];
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, plane_co);
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane);
-	normalize_v3(plane);
-
-	plane[3] = -value[0] - dot_v3v3(plane, gz->matrix_basis[3]);
-
-	/* Keep our location, may be offset simply to be inside the viewport. */
-	closest_to_plane_normalized_v3(plane_co, plane, plane_co);
-
-	RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_co, plane_co);
-
-	gizmo_spin_exec(ggd);
-}
-
-/* translate callbacks */
-static void gizmo_spin_prop_translate_get(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 3);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_co, value);
-}
-
-static void gizmo_spin_prop_translate_set(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        const void *value)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-
-	BLI_assert(gz_prop->type->array_length == 3);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_co, value);
-
-	gizmo_spin_exec(ggd);
-}
-
-/* angle callbacks */
-static void gizmo_spin_prop_axis_angle_get(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	float plane_no[4];
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
-	normalize_v3(plane_no);
-
-	float plane_no_proj[3];
-	project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis);
-
-	if (!is_zero_v3(plane_no_proj)) {
-		const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis);
-		value[0] = angle;
-	}
-	else {
-		value[0] = 0.0f;
-	}
-}
-
-static void gizmo_spin_prop_axis_angle_set(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        const void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	const float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-
-	float plane_no[4];
-	RNA_property_float_get_array(op->ptr, ggd->data.prop_axis_no, plane_no);
-	normalize_v3(plane_no);
-
-	float plane_no_proj[3];
-	project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, ggd->data.rotate_axis);
-
-	if (!is_zero_v3(plane_no_proj)) {
-		const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, ggd->data.rotate_up, ggd->data.rotate_axis);
-		const float angle_delta = angle - angle_compat_rad(value[0], angle);
-		if (angle_delta != 0.0f) {
-			float mat[3][3];
-			axis_angle_normalized_to_mat3(mat, ggd->data.rotate_axis, angle_delta);
-			mul_m3_v3(mat, plane_no);
-
-			/* re-normalize - seems acceptable */
-			RNA_property_float_set_array(op->ptr, ggd->data.prop_axis_no, plane_no);
-
-			gizmo_spin_exec(ggd);
-		}
-	}
-}
-
-/* angle callbacks */
-static void gizmo_spin_prop_angle_get(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	float *value = value_p;
-
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-	value[0] = RNA_property_float_get(op->ptr, ggd->data.prop_angle);
-}
-
-static void gizmo_spin_prop_angle_set(
-        const wmGizmo *gz, wmGizmoProperty *gz_prop,
-        const void *value_p)
-{
-	GizmoSpinGroup *ggd = gz->parent_gzgroup->customdata;
-	wmOperator *op = ggd->data.op;
-	BLI_assert(gz_prop->type->array_length == 1);
-	UNUSED_VARS_NDEBUG(gz_prop);
-	const float *value = value_p;
-	RNA_property_float_set(op->ptr, ggd->data.prop_angle, value[0]);
-
-	gizmo_spin_exec(ggd);
-}
-
-static bool gizmo_mesh_spin_poll(const bContext *C, wmGizmoGroupType *gzgt)
-{
-	wmOperator *op = WM_operator_last_redo(C);
-	if (op == NULL || !STREQ(op->type->idname, "MESH_OT_spin")) {
-		WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
-		return false;
-	}
-	return true;
-}
-
-
-static void gizmo_mesh_spin_redo_modal_from_setup(
-        const bContext *C, wmGizmoGroup *gzgroup)
-{
-	/* Start off dragging. */
-	struct GizmoSpinGroup *ggd = gzgroup->customdata;
-	wmWindow *win = CTX_wm_window(C);
-	wmGizmo *gz = ggd->angle_z;
-	wmGizmoMap *gzmap = gzgroup->parent_gzmap;
-	WM_gizmo_modal_set_from_setup(
-	        gzmap, (bContext *)C, gz, 0, win->eventstate);
-}
-
-static void gizmo_mesh_spin_setup(const bContext *C, wmGizmoGroup *gzgroup)
-{
-	wmOperatorType *ot = WM_operatortype_find("MESH_OT_spin", true);
-	wmOperator *op = WM_operator_last_redo(C);
-
-	if ((op == NULL) || (op->type != ot)) {
-		return;
-	}
-
-	struct GizmoSpinGroup *ggd = MEM_callocN(sizeof(GizmoSpinGroup), __func__);
-	gzgroup->customdata = ggd;
-
-	const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true);
-	const wmGizmoType *gzt_move = WM_gizmotype_find("GIZMO_GT_move_3d", true);
-	const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true);
-
-	ggd->translate_z = WM_gizmo_new_ptr(gzt_arrow, gzgroup, NULL);
-	ggd->translate_c = WM_gizmo_new_ptr(gzt_move, gzgroup, NULL);
-	ggd->rotate_c = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
-	ggd->angle_z = WM_gizmo_new_ptr(gzt_dial, gzgroup, NULL);
-
-	UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_z->color);
-	UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, ggd->translate_c->color);
-	UI_GetThemeColor3fv(TH_GIZMO_SECONDARY, ggd->rotate_c->color);
-	UI_GetThemeColor3fv(TH_AXIS_Z, ggd->angle_z->color);
-
-
-	RNA_enum_set(

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list