[Bf-blender-cvs] [f7dc6a63fb5] blender2.8: Gizmo: optional custom orientations for transform

Campbell Barton noreply at git.blender.org
Wed Dec 19 10:59:31 CET 2018


Commit: f7dc6a63fb5a62eb6141fee375e30d94c1d83fa8
Author: Campbell Barton
Date:   Wed Dec 19 20:51:04 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBf7dc6a63fb5a62eb6141fee375e30d94c1d83fa8

Gizmo: optional custom orientations for transform

This aims to resolve a conflict where some users want to keep keyboard
axis setting global, even when the orientation is set to something else.

Move/rotate/scale can optionally each have a separate orientation.

Some UI changes will be made next.

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

M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenkernel/BKE_scene.h
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/editors/include/ED_transform.h
M	source/blender/editors/mesh/editmesh_extrude_spin_gizmo.c
M	source/blender/editors/mesh/editmesh_select.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_generics.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/editors/transform/transform_gizmo_extrude_3d.c
M	source/blender/editors/transform/transform_ops.c
M	source/blender/editors/transform/transform_orientations.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 68b487ffe44..590d4299968 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -64,6 +64,17 @@ class _template_widget:
             props = tool.gizmo_group_properties("VIEW3D_GGT_xform_extrude")
             layout.prop(props, "axis_type", expand=True)
 
+    class TRANSFORM_GGT_gizmo:
+        @staticmethod
+        def draw_settings_with_index(context, layout, index):
+            row = layout.row(align=True)
+            scene = context.scene
+            orientation_slot = scene.transform_orientation_slots[index]
+            value = orientation_slot.use
+            row.prop(orientation_slot, "use", text="", icon='LINKED' if value else 'UNLINKED')
+            if not value:
+                row.prop(orientation_slot, "type", text="")
+
 
 class _defs_view3d_generic:
     @ToolDef.from_fn
@@ -202,6 +213,8 @@ class _defs_transform:
 
     @ToolDef.from_fn
     def translate():
+        def draw_settings(context, layout, tool):
+            _template_widget.TRANSFORM_GGT_gizmo.draw_settings_with_index(context, layout, 1)
         return dict(
             text="Move",
             # cursor='SCROLL_XY',
@@ -209,10 +222,13 @@ class _defs_transform:
             widget="TRANSFORM_GGT_gizmo",
             operator="transform.translate",
             keymap="3D View Tool: Move",
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
     def rotate():
+        def draw_settings(context, layout, tool):
+            _template_widget.TRANSFORM_GGT_gizmo.draw_settings_with_index(context, layout, 2)
         return dict(
             text="Rotate",
             # cursor='SCROLL_XY',
@@ -220,10 +236,13 @@ class _defs_transform:
             widget="TRANSFORM_GGT_gizmo",
             operator="transform.rotate",
             keymap="3D View Tool: Rotate",
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
     def scale():
+        def draw_settings(context, layout, tool):
+            _template_widget.TRANSFORM_GGT_gizmo.draw_settings_with_index(context, layout, 3)
         return dict(
             text="Scale",
             # cursor='SCROLL_XY',
@@ -231,15 +250,19 @@ class _defs_transform:
             widget="TRANSFORM_GGT_gizmo",
             operator="transform.resize",
             keymap="3D View Tool: Scale",
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
     def scale_cage():
+        def draw_settings(context, layout, tool):
+            _template_widget.TRANSFORM_GGT_gizmo.draw_settings_with_index(context, layout, 3)
         return dict(
             text="Scale Cage",
             icon="ops.transform.resize.cage",
             widget="VIEW3D_GGT_xform_cage",
             operator="transform.resize",
+            draw_settings=draw_settings,
         )
 
     @ToolDef.from_fn
@@ -252,6 +275,8 @@ class _defs_transform:
             props = tool.gizmo_group_properties("TRANSFORM_GGT_gizmo")
             layout.prop(props, "drag_action")
 
+            _template_widget.TRANSFORM_GGT_gizmo.draw_settings_with_index(context, layout, 1)
+
         return dict(
             text="Transform",
             description=(
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 825fd5f2a00..8f3132f690f 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -121,16 +121,16 @@ class VIEW3D_HT_header(Header):
 
         # Orientation
         if object_mode in {'OBJECT', 'EDIT', 'POSE', 'EDIT_GPENCIL'}:
-            orientation = scene.transform_orientation
-            current_orientation = scene.current_orientation
+            orient_slot = scene.transform_orientation_slots[0]
+            custom_orientation = orient_slot.custom_orientation
 
-            if not current_orientation:
-                trans_orientation = bpy.types.Scene.bl_rna.properties["transform_orientation"].enum_items[orientation]
-                trans_icon = getattr(trans_orientation, "icon", "BLANK1")
+            if custom_orientation is None:
+                trans_orientation = bpy.types.TransformOrientationSlot.bl_rna.properties["type"].enum_items[orient_slot.type]
+                trans_icon = getattr(trans_orientation, "icon", 'BLANK1')
                 trans_name = getattr(trans_orientation, "name", "Orientation")
             else:
                 trans_icon = 'OBJECT_ORIGIN'
-                trans_name = getattr(current_orientation, "name", "Orientation")
+                trans_name = getattr(custom_orientation, "name", "Orientation")
 
             row = layout.row(align=True)
 
@@ -5258,11 +5258,12 @@ class VIEW3D_PT_transform_orientations(Panel):
         layout.label(text="Transform Orientations")
 
         scene = context.scene
-        orientation = scene.current_orientation
+        orient_slot = scene.transform_orientation_slots[0]
+        orientation = orient_slot.custom_orientation
 
         row = layout.row()
         col = row.column()
-        col.prop(scene, "transform_orientation", expand=True)
+        col.prop(orient_slot, "type", expand=True)
         row.operator("transform.create_orientation", text="", icon='ADD', emboss=False).use = True
 
         if orientation:
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 6344d29a2a0..fd1ba56fd8b 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -139,6 +139,10 @@ float BKE_scene_frame_get(const struct Scene *scene);
 float BKE_scene_frame_get_from_ctime(const struct Scene *scene, const float frame);
 void  BKE_scene_frame_set(struct Scene *scene, double cfra);
 
+struct TransformOrientationSlot *BKE_scene_orientation_slot_get(struct Scene *scene, int flag);
+void BKE_scene_orientation_slot_set_index(struct TransformOrientationSlot *orient_slot, int orientation);
+int BKE_scene_orientation_slot_get_index(const struct TransformOrientationSlot *orient_slot);
+
 /* **  Scene evaluation ** */
 
 void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 3de1ddb1e1e..05603efb2c3 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -864,7 +864,9 @@ void BKE_scene_init(Scene *sce)
 	sce->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR;
 	sce->toolsettings->annotate_thickness = 3;
 
-	sce->orientation_index_custom = -1;
+	for (int i = 0; i < ARRAY_SIZE(sce->orientation_slots); i++) {
+		sce->orientation_slots[i].index_custom = -1;
+	}
 
 	/* Master Collection */
 	sce->master_collection = BKE_collection_master_add();
@@ -1321,7 +1323,6 @@ float BKE_scene_frame_get_from_ctime(const Scene *scene, const float frame)
 
 	return ctime;
 }
-
 /**
  * Sets the frame int/float components.
  */
@@ -1332,6 +1333,52 @@ void BKE_scene_frame_set(struct Scene *scene, double cfra)
 	scene->r.cfra = (int)intpart;
 }
 
+
+/* -------------------------------------------------------------------- */
+/** \name Scene Orientation Slots
+ * \{ */
+
+TransformOrientationSlot *BKE_scene_orientation_slot_get(Scene *scene, int flag)
+{
+	BLI_assert(flag && !(flag & ~(SCE_GIZMO_SHOW_TRANSLATE | SCE_GIZMO_SHOW_ROTATE | SCE_GIZMO_SHOW_SCALE)));
+	int index = SCE_ORIENT_DEFAULT;
+	if (flag & SCE_GIZMO_SHOW_TRANSLATE) {
+		index = SCE_ORIENT_TRANSLATE;
+	}
+	else if (flag & SCE_GIZMO_SHOW_ROTATE) {
+		index = SCE_ORIENT_ROTATE;
+	}
+	else if (flag & SCE_GIZMO_SHOW_SCALE) {
+		index = SCE_ORIENT_SCALE;
+	}
+
+	if ((scene->orientation_slots[index].flag & SELECT) == 0) {
+		index = SCE_ORIENT_DEFAULT;
+	}
+	return &scene->orientation_slots[index];
+}
+
+/**
+ * Activate a transform orientation in a 3D view based on an enum value.
+ *
+ * \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation
+ * with index \a orientation - #V3D_MANIP_CUSTOM gets activated.
+ */
+void BKE_scene_orientation_slot_set_index(TransformOrientationSlot *orient_slot, int orientation)
+{
+	const bool is_custom = orientation >= V3D_MANIP_CUSTOM;
+	orient_slot->type = is_custom ? V3D_MANIP_CUSTOM : orientation;
+	orient_slot->index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1;
+}
+
+int BKE_scene_orientation_slot_get_index(const TransformOrientationSlot *orient_slot)
+{
+	return (orient_slot->type == V3D_MANIP_CUSTOM) ? (orient_slot->type + orient_slot->index_custom) : orient_slot->type;
+}
+
+/** \} */
+
+
 /* That's like really a bummer, because currently animation data for armatures
  * might want to use pose, and pose might be missing on the object.
  * This happens when changing visible layers, which leads to situations when
@@ -2166,11 +2213,16 @@ void BKE_scene_transform_orientation_remove(
         Scene *scene, TransformOrientation *orientation)
 {
 	const int orientation_index = BKE_scene_transform_orientation_get_index(scene, orientation);
-	if (scene->orientation_index_custom == orientation_index) {
-		/* could also use orientation_index-- */
-		scene->orientation_type = V3D_MANIP_GLOBAL;
-		scene->orientation_index_custom = -1;
+
+	for (int i = 0; i < ARRAY_SIZE(scene->orientation_slots); i++) {
+		TransformOrientationSlot *orient_slot = &scene->orientation_slots[i];
+		if (orient_slot->index_custom == orientation_index) {
+			/* could also use orientation_index-- */
+			orient_slot->type = V3D_MANIP_GLOBAL;
+			orient_slot->index_custom = -1;
+		}
 	}
+
 	BLI_freelinkN(&scene->transform_spaces, orientation);
 }
 
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 0c9b9806425..9b3add62722 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -1230,12 +1230,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 			}
 		}
 
-		if (!DNA_struct_elem_find(fd->filesdna, "Scen

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list