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
This commit is contained in:
Philipp Oeser
2023-09-04 12:43:56 +02:00
committed by Philipp Oeser
parent 938d43c317
commit 30e3caaf82

View File

@@ -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<const bNodeTree *>(
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*/)