From 30e3caaf8291811f9c86a5721a67a976d18e5af2 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Mon, 4 Sep 2023 12:43:56 +0200 Subject: [PATCH] Fix #111779: drop asset shading group to GN editor still imports Dropbox poll function was not sufficiently checking compatibility, so we could end up calling `WM_drag_get_local_ID_or_import_from_asset`. The asset might not actually be used because of further checks later (so it would end up as an orphan which would go away after save/reload), but still the import should be avoided. This fixes the case for dropping a shader nodegroup to the Geometry Nodes Editor by getting asset metadata (and checking if the nodetree type matches editor) in the dropbox poll function. Will check on other possible cases of drag-drop to incompatible editors next. Pull Request: https://projects.blender.org/blender/blender/pulls/111921 --- .../blender/editors/space_node/space_node.cc | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index 419f74353ca..cfd33ddad45 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -6,6 +6,9 @@ * \ingroup spnode */ + +#include "AS_asset_representation.hh" + #include "BLI_string.h" #include "DNA_ID.h" @@ -17,8 +20,10 @@ #include "MEM_guardedalloc.h" +#include "BKE_asset.h" #include "BKE_context.h" #include "BKE_gpencil_legacy.h" +#include "BKE_idprop.h" #include "BKE_lib_id.h" #include "BKE_lib_query.h" #include "BKE_lib_remap.h" @@ -674,9 +679,36 @@ static void node_main_region_draw(const bContext *C, ARegion *region) /* ************* dropboxes ************* */ -static bool node_group_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/) +static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/) { - return WM_drag_is_ID_type(drag, ID_NT); + SpaceNode *snode = CTX_wm_space_node(C); + + if (!WM_drag_is_ID_type(drag, ID_NT)) { + return false; + } + + if (drag->type == WM_DRAG_ID) { + const bNodeTree *node_tree = reinterpret_cast( + WM_drag_get_local_ID(drag, ID_NT)); + if (!node_tree) { + return false; + } + return node_tree->type == snode->edittree->type; + } + + if (drag->type == WM_DRAG_ASSET) { + const wmDragAsset *asset_data = WM_drag_get_asset_data(drag, ID_NT); + if (!asset_data) { + return false; + } + const AssetMetaData *metadata = &asset_data->asset->get_metadata(); + const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type"); + if (!tree_type || IDP_Int(tree_type) != snode->edittree->type) { + return false; + } + } + + return true; } static bool node_object_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)