[Bf-blender-cvs] [a3a069f4935] blender2.8: Tool System: cursor tool now transforms on drag

Campbell Barton noreply at git.blender.org
Fri May 25 19:44:20 CEST 2018


Commit: a3a069f4935f72225ad7a0dc23bfc36b9fbed079
Author: Campbell Barton
Date:   Fri May 25 19:43:23 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBa3a069f4935f72225ad7a0dc23bfc36b9fbed079

Tool System: cursor tool now transforms on drag

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

M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
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_conversions.c
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_ops.c
M	source/blender/editors/transform/transform_snap.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 2be5b792f01..814c26ce796 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -88,6 +88,10 @@ class _defs_view3d_generic:
             icon="ops.generic.cursor",
             keymap=(
                 ("view3d.cursor3d", dict(), dict(type='ACTIONMOUSE', value='PRESS')),
+                ("transform.translate",
+                 dict(release_confirm=True, cursor_transform=True),
+                 dict(type='EVT_TWEAK_A', value='ANY'),
+                ),
             ),
         )
 
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index e17d02abcd7..1e3c8995314 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -102,6 +102,7 @@ enum TfmMode {
 #define CTX_MASK            (1 << 7)
 #define CTX_PAINT_CURVE     (1 << 8)
 #define CTX_GPENCIL_STROKES (1 << 9)
+#define CTX_CURSOR          (1 << 10)
 
 /* Standalone call to get the transformation center corresponding to the current situation
  * returns 1 if successful, 0 otherwise (usually means there's no selection)
@@ -152,6 +153,7 @@ int BIF_countTransformOrientation(const struct bContext *C);
 #define P_NO_TEXSPACE   (1 << 11)
 #define P_CENTER        (1 << 12)
 #define P_GPENCIL_EDIT  (1 << 13)
+#define P_CURSOR_EDIT   (1 << 14)
 
 void Transform_Properties(struct wmOperatorType *ot, int flags);
 
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index e20ef264a93..a4d08b15a6d 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2118,6 +2118,12 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
 
 	t->state = TRANS_STARTING;
 
+	if ((prop = RNA_struct_find_property(op->ptr, "cursor_transform")) && RNA_property_is_set(op->ptr, prop)) {
+		if (RNA_property_boolean_get(op->ptr, prop)) {
+			options |= CTX_CURSOR;
+		}
+	}
+
 	if ((prop = RNA_struct_find_property(op->ptr, "texture_space")) && RNA_property_is_set(op->ptr, prop)) {
 		if (RNA_property_boolean_get(op->ptr, prop)) {
 			options |= CTX_TEXTURE;
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index a8a71c95e37..b9f42a0d9fc 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -557,6 +557,8 @@ typedef struct TransInfo {
 #define T_TEXTURE		(1 << 3)
 	/* transforming the camera while in camera view */
 #define T_CAMERA		(1 << 4)
+	/* transforming the 3D cursor. */
+#define T_CURSOR		(1 << 5)
 		 // trans on points, having no rotation/scale
 #define T_POINTS		(1 << 6)
 /**
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index c1251a39171..c8b09eef04b 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -345,6 +345,43 @@ static void createTransTexspace(TransInfo *t)
 	copy_v3_v3(td->ext->isize, td->ext->size);
 }
 
+static void createTransCursor3D(TransInfo *t)
+{
+	TransData *td;
+
+	Scene *scene = t->scene;
+	View3D *v3d = ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) ? t->view : NULL;
+	View3DCursor *cursor = ED_view3d_cursor3d_get(scene, v3d);
+
+	if ((cursor == &scene->cursor) && ID_IS_LINKED(scene)) {
+		BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
+		return;
+	}
+
+	{
+		BLI_assert(t->data_container_len == 1);
+		TransDataContainer *tc = t->data_container;
+		tc->data_len = 1;
+		td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
+		td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
+	}
+
+	td->flag = TD_SELECTED;
+	copy_v3_v3(td->center, cursor->location);
+	td->ob = NULL;
+
+	unit_m3(td->mtx);
+	quat_to_mat3(td->axismtx, cursor->rotation);
+	normalize_m3(td->axismtx);
+	pseudoinverse_m3_m3(td->smtx, td->mtx, PSEUDOINVERSE_EPSILON);
+
+	td->loc = cursor->location;
+	copy_v3_v3(td->iloc, cursor->location);
+
+	td->ext->quat = cursor->rotation;
+	copy_qt_qt(td->ext->iquat, cursor->rotation);
+}
+
 /* ********************* edge (for crease) ***** */
 
 static void createTransEdge(TransInfo *t)
@@ -6696,6 +6733,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
 	{
 		/* do nothing */
 	}
+	else if (t->flag & T_CURSOR) {
+		/* do nothing */
+	}
 	else { /* Objects */
 		int i;
 
@@ -8328,7 +8368,14 @@ void createTransData(bContext *C, TransInfo *t)
 	t->data_len_all = -1;
 
 	/* if tests must match recalcData for correct updates */
-	if (t->options & CTX_TEXTURE) {
+	if (t->options & CTX_CURSOR) {
+		t->flag |= T_CURSOR;
+		t->obedit_type = -1;
+
+		createTransCursor3D(t);
+		countAndCleanTransDataContainer(t);
+	}
+	else if (t->options & CTX_TEXTURE) {
 		t->flag |= T_TEXTURE;
 		t->obedit_type = -1;
 
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 7d37dde1d8c..576bfddd28c 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -1007,6 +1007,11 @@ static void recalcData_objects(TransInfo *t)
 	}
 }
 
+static void recalcData_cursor(TransInfo *t)
+{
+	DEG_id_tag_update(&t->scene->id, DEG_TAG_COPY_ON_WRITE);
+}
+
 /* helper for recalcData() - for sequencer transforms */
 static void recalcData_sequencer(TransInfo *t)
 {
@@ -1056,7 +1061,10 @@ static void recalcData_gpencil_strokes(TransInfo *t)
 void recalcData(TransInfo *t)
 {
 	/* if tests must match createTransData for correct updates */
-	if (t->options & CTX_TEXTURE) {
+	if (t->options & CTX_CURSOR) {
+		recalcData_cursor(t);
+	}
+	else if (t->options & CTX_TEXTURE) {
 		recalcData_objects(t);
 	}
 	else if (t->options & CTX_EDGE) {
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 10b51079a9a..73dd0392a25 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -563,6 +563,10 @@ void Transform_Properties(struct wmOperatorType *ot, int flags)
 		RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
 	}
 
+	if (flags & P_CURSOR_EDIT) {
+		RNA_def_boolean(ot->srna, "cursor_transform", 0, "Transform Cursor", "");
+	}
+
 	if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
 		RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
 		prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
@@ -609,7 +613,10 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
 
 	WM_operatortype_props_advanced_begin(ot);
 
-	Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
+	Transform_Properties(
+	        ot,
+	        P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS |
+	        P_GPENCIL_EDIT | P_CURSOR_EDIT);
 }
 
 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 4607bb5b8ba..10de7f3ea36 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -550,7 +550,9 @@ static void initSnappingMode(TransInfo *t)
 		{
 			/* In "Edit Strokes" mode, Snap tool can perform snap to selected or active objects (see T49632)
 			 * TODO: perform self snap in gpencil_strokes */
-			t->tsnap.modeSelect = ((t->options & CTX_GPENCIL_STROKES) != 0) ? SNAP_ALL : SNAP_NOT_SELECTED;
+			t->tsnap.modeSelect = (
+			        ((t->options & (CTX_GPENCIL_STROKES | CTX_CURSOR)) != 0) ?
+			        SNAP_ALL : SNAP_NOT_SELECTED);
 		}
 		else {
 			/* Grid if snap is not possible */



More information about the Bf-blender-cvs mailing list