[Bf-blender-cvs] [8ddf9f06ab8] asset-browser-snap-dragging: Initial prototype for snapping plane feedback while dragging assets
Julian Eisel
noreply at git.blender.org
Wed Apr 21 19:27:45 CEST 2021
Commit: 8ddf9f06ab82b1164b40ef9b7ed4ecadede9fb06
Author: Julian Eisel
Date: Wed Apr 21 19:20:35 2021 +0200
Branches: asset-browser-snap-dragging
https://developer.blender.org/rB8ddf9f06ab82b1164b40ef9b7ed4ecadede9fb06
Initial prototype for snapping plane feedback while dragging assets
Shows the same grid overlay as the Add Object tool when dragging an
asset into a 3D view. Uses the gizmo-system for that.
How visibility of gizmo-groups is managed is rather tricky, for now I
hacked things a bit to work. I have ideas to make this nicer.
Besides that, this is generally a design that I think can work in
master: Just like tools, drop-boxes can set a gizmo-group to use while
they are active. If the gizmo-group supports usage while dragging, it is
drawn.
===================================================================
M source/blender/editors/include/ED_gizmo_library.h
M source/blender/editors/include/ED_gizmo_utils.h
M source/blender/editors/screen/screen_edit.c
M source/blender/editors/space_api/spacetypes.c
M source/blender/editors/space_view3d/space_view3d.c
M source/blender/editors/space_view3d/view3d_placement.c
M source/blender/editors/util/gizmo_utils.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/gizmo/WM_gizmo_types.h
M source/blender/windowmanager/intern/wm_dragdrop.c
M source/blender/windowmanager/intern/wm_event_system.c
===================================================================
diff --git a/source/blender/editors/include/ED_gizmo_library.h b/source/blender/editors/include/ED_gizmo_library.h
index 571519e52f7..f2fed128423 100644
--- a/source/blender/editors/include/ED_gizmo_library.h
+++ b/source/blender/editors/include/ED_gizmo_library.h
@@ -40,6 +40,7 @@ void ED_gizmotypes_preselect_3d(void);
void ED_gizmotypes_primitive_3d(void);
void ED_gizmotypes_blank_3d(void);
void ED_gizmotypes_snap_3d(void);
+void ED_gizmotypes_placement_3d(void);
struct ARegion;
struct Depsgraph;
diff --git a/source/blender/editors/include/ED_gizmo_utils.h b/source/blender/editors/include/ED_gizmo_utils.h
index 0cfc3df9d54..285523fe78a 100644
--- a/source/blender/editors/include/ED_gizmo_utils.h
+++ b/source/blender/editors/include/ED_gizmo_utils.h
@@ -42,6 +42,12 @@ bool ED_gizmo_poll_or_unlink_delayed_from_tool_ex(const struct bContext *C,
bool ED_gizmo_poll_or_unlink_delayed_from_tool(const struct bContext *C,
struct wmGizmoGroupType *gzgt);
+bool ED_gizmo_poll_from_tool_ex(const struct bContext *C, const char *gzgt_idname);
+bool ED_gizmo_poll_from_tool(const struct bContext *C, const struct wmGizmoGroupType *gzgt);
+
+bool ED_gizmo_poll_from_dropbox_ex(const struct bContext *C, const char *gzgt_idname);
+bool ED_gizmo_poll_from_dropbox(const struct bContext *C, const struct wmGizmoGroupType *gzgt);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 7ad8eada3b9..999202d51e2 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -769,6 +769,14 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
if (WM_gizmo_highlight_set(gzmap, NULL)) {
ED_region_tag_redraw_no_rebuild(region_prev);
}
+
+ /* TODO deduplicate (wm_handlers_do_gizmo_handler().) */
+ const ListBase *groups = WM_gizmomap_group_list(gzmap);
+ LISTBASE_FOREACH (wmGizmoGroup *, gzgroup, groups) {
+ if (gzgroup->type->flag & WM_GIZMOGROUPTYPE_ATTACHED_TO_CURSOR) {
+ ED_region_tag_redraw_editor_overlays(region_prev);
+ }
+ }
}
}
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index adb824b8934..89849f4ba29 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -140,6 +140,7 @@ void ED_spacetypes_init(void)
ED_gizmotypes_cage_2d();
ED_gizmotypes_cage_3d();
ED_gizmotypes_snap_3d();
+ ED_gizmotypes_placement_3d();
/* Register types for operators and gizmos. */
const ListBase *spacetypes = BKE_spacetypes_list();
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index e6916c34a88..1e959f576b6 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -688,12 +688,14 @@ static void view3d_lightcache_update(bContext *C)
static void view3d_dropboxes(void)
{
ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
- WM_dropbox_add(lb,
- "OBJECT_OT_add_named",
- view3d_ob_drop_poll,
- view3d_ob_drop_copy,
- WM_drag_free_imported_drag_ID);
+ wmDropBox *dropbox;
+
+ dropbox = WM_dropbox_add(lb,
+ "OBJECT_OT_add_named",
+ view3d_ob_drop_poll,
+ view3d_ob_drop_copy,
+ WM_drag_free_imported_drag_ID);
+ WM_dropbox_gizmogroup_set(dropbox, "VIEW3D_GGT_placement");
WM_dropbox_add(lb,
"OBJECT_OT_drop_named_material",
view3d_mat_drop_poll,
@@ -714,11 +716,12 @@ static void view3d_dropboxes(void)
view3d_volume_drop_poll,
view3d_id_path_drop_copy,
WM_drag_free_imported_drag_ID);
- WM_dropbox_add(lb,
- "OBJECT_OT_collection_instance_add",
- view3d_collection_drop_poll,
- view3d_collection_drop_copy,
- WM_drag_free_imported_drag_ID);
+ dropbox = WM_dropbox_add(lb,
+ "OBJECT_OT_collection_instance_add",
+ view3d_collection_drop_poll,
+ view3d_collection_drop_copy,
+ WM_drag_free_imported_drag_ID);
+ WM_dropbox_gizmogroup_set(dropbox, "VIEW3D_GGT_placement");
WM_dropbox_add(lb,
"OBJECT_OT_data_instance_add",
view3d_object_data_drop_poll,
diff --git a/source/blender/editors/space_view3d/view3d_placement.c b/source/blender/editors/space_view3d/view3d_placement.c
index 1afdcdd2993..816755071ec 100644
--- a/source/blender/editors/space_view3d/view3d_placement.c
+++ b/source/blender/editors/space_view3d/view3d_placement.c
@@ -30,6 +30,7 @@
#include "DNA_scene_types.h"
#include "DNA_vfont_types.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
@@ -64,7 +65,6 @@
static const char *view3d_gzgt_placement_id = "VIEW3D_GGT_placement";
-static void preview_plane_cursor_setup(wmGizmoGroup *gzgroup);
static void preview_plane_cursor_visible_set(wmGizmoGroup *gzgroup, bool do_draw);
/**
@@ -1762,8 +1762,20 @@ static void WIDGETGROUP_placement_setup(const bContext *UNUSED(C), wmGizmoGroup
gizmo->flag |= WM_GIZMO_HIDDEN_KEYMAP;
}
- /* Sets the gizmos custom-data which has it's own free callback. */
- preview_plane_cursor_setup(gzgroup);
+ {
+ const wmGizmoType *gzt_plane = WM_gizmotype_find("GIZMO_GT_placement_plane_3d", true);
+ gizmo = WM_gizmo_new_ptr(gzt_plane, gzgroup, NULL);
+
+ WM_gizmo_set_color(gizmo, (float[4]){1.0f, 1.0f, 1.0f, 1.0f});
+
+ /* Don't handle any events, this is for display only. */
+ gizmo->flag |= WM_GIZMO_HIDDEN_KEYMAP;
+ }
+}
+
+static bool WIDGETGROUP_placement_poll(const bContext *C, wmGizmoGroupType *gzgt)
+{
+ return ED_gizmo_poll_from_dropbox(C, gzgt) || ED_gizmo_poll_from_tool(C, gzgt);
}
void VIEW3D_GGT_placement(wmGizmoGroupType *gzgt)
@@ -1771,12 +1783,13 @@ void VIEW3D_GGT_placement(wmGizmoGroupType *gzgt)
gzgt->name = "Placement Widget";
gzgt->idname = view3d_gzgt_placement_id;
- gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_SCALE | WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL;
+ gzgt->flag |= WM_GIZMOGROUPTYPE_3D | WM_GIZMOGROUPTYPE_SCALE | WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL |
+ WM_GIZMOGROUPTYPE_ATTACHED_TO_CURSOR;
gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
- gzgt->poll = ED_gizmo_poll_or_unlink_delayed_from_tool;
+ gzgt->poll = WIDGETGROUP_placement_poll;
gzgt->setup = WIDGETGROUP_placement_setup;
}
@@ -1972,9 +1985,8 @@ struct PlacementCursor {
float persmat_prev[4][4];
};
-static void cursor_plane_draw(bContext *C, int x, int y, void *customdata)
+static void cursor_plane_draw_ex(const bContext *C, const int mval[2], struct PlacementCursor *plc)
{
- struct PlacementCursor *plc = (struct PlacementCursor *)customdata;
ARegion *region = CTX_wm_region(C);
const RegionView3D *rv3d = region->regiondata;
@@ -1994,6 +2006,9 @@ static void cursor_plane_draw(bContext *C, int x, int y, void *customdata)
return;
}
+ GPU_line_smooth(false);
+ GPU_line_width(1.0f);
+
/* Check this gizmo group is in the region. */
{
wmGizmoMap *gzmap = region->gizmo_map;
@@ -2004,8 +2019,6 @@ static void cursor_plane_draw(bContext *C, int x, int y, void *customdata)
}
}
- const int mval[2] = {x - region->winrct.xmin, y - region->winrct.ymin};
-
/* Update matrix? */
if ((plc->mval_prev[0] != mval[0]) || (plc->mval_prev[1] != mval[1]) ||
!equals_m4m4(plc->persmat_prev, rv3d->persmat)) {
@@ -2055,7 +2068,10 @@ static void cursor_plane_draw(bContext *C, int x, int y, void *customdata)
}
/* Setup viewport & matrix. */
- wmViewport(®ion->winrct);
+ if (plc->paintcursor) {
+ /* Paint cursors are on window level, need to set the viewport. */
+ wmViewport(®ion->winrct);
+ }
GPU_matrix_push_projection();
GPU_matrix_push();
GPU_matrix_projection_set(rv3d->winmat);
@@ -2099,6 +2115,14 @@ static void cursor_plane_draw(bContext *C, int x, int y, void *customdata)
}
}
+static void cursor_plane_draw_cursor_fn(bContext *C, int x, int y, void *customdata)
+{
+ struct PlacementCursor *plc = (struct PlacementCursor *)customdata;
+ const ARegion *region = CTX_wm_region(C);
+ const int mval[2] = {x - region->winrct.xmin, y - region->winrct.ymin};
+ cursor_plane_draw_ex(C, mval, plc);
+}
+
static void preview_plane_cursor_free(void *customdata)
{
struct PlacementCursor *plc = customdata;
@@ -2111,13 +2135,13 @@ static void preview_plane_cursor_free(void *customdata)
MEM_freeN(plc);
}
-static void preview_plane_cursor_setup(wmGizmoGroup *gzgroup)
+static void UNUSED_FUNCTION(preview_plane_cursor_setup)(wmGizmoGroup *gzgroup)
{
BLI_assert(gzgroup->customdata == NULL);
struct PlacementCursor *plc = MEM_callocN(sizeof(*plc), __func__);
plc->gzgroup = gzgroup;
plc->paintcursor = WM_paint_cursor_activate(
- SPACE_VIEW3D, RGN_TYPE_WINDOW, NULL, cursor_plane_draw, plc);
+ SPACE_VIEW3D, RGN_TYPE_WINDOW, NULL, cursor_plane_draw_cursor_fn, plc);
gzgroup->customdata = plc;
gzgroup->customdata_free = preview_plane_cursor_free;
@@ -2131,3 +2155,59 @@ static void preview_plane_cursor_visible_set(wmGizmoGroup *gzgroup, bool do_draw
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Placement Plane Gizmo
+ * \{ */
+
+struct PlacementPlaneGizmo {
+ wmGizmo gizmo;
+ struct PlacementCursor *plc;
+};
+
+static void gizmo_placement_plane_setup(wmGizmo *gz)
+{
+ struct PlacementPlaneGizmo *plane_gz = (struct PlacementPlaneGizmo *)gz;
+ plane_gz->plc = MEM_callocN(sizeof(*plane_gz->plc), __func__);
+ plane_gz->plc->gzgroup = gz->parent_gzgroup;
+}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list