Assets: Get asset path via new identifier (not via file browser hacks)

With the asset identifier introduced in the previous commit, we can now
locate an asset just from its `AssetRepresentation`, without requiring
information from the asset library and the file browser storage. With
this we can remove some hacks and function parameters. A RNA/BPY
function is also affected, but I didn't remove the paramter to keep
compatibility. It's simply ignored and not required anymore, noted this
in the parameter description (noted for T102877).
This commit is contained in:
2022-11-30 19:24:24 +01:00
parent f68da703a5
commit ccc9eef1b9
17 changed files with 47 additions and 148 deletions

View File

@@ -67,7 +67,6 @@ static void add_node_search_listen_fn(const wmRegionListenerParams *params, void
}
static void search_items_for_asset_metadata(const bNodeTree &node_tree,
const AssetLibraryReference &library_ref,
const AssetHandle asset,
Vector<AddNodeItem> &search_items)
{
@@ -82,10 +81,10 @@ static void search_items_for_asset_metadata(const bNodeTree &node_tree,
item.identifier = node_tree.typeinfo->group_idname;
item.description = asset_data.description == nullptr ? "" : asset_data.description;
item.asset = asset;
item.after_add_fn = [asset, library_ref](const bContext &C, bNodeTree &node_tree, bNode &node) {
item.after_add_fn = [asset](const bContext &C, bNodeTree &node_tree, bNode &node) {
Main &bmain = *CTX_data_main(&C);
node.flag &= ~NODE_OPTIONS;
node.id = asset::get_local_id_from_asset_or_append_and_reuse(bmain, library_ref, asset);
node.id = asset::get_local_id_from_asset_or_append_and_reuse(bmain, asset);
id_us_plus(node.id);
BKE_ntree_update_tag_node_property(&node_tree, &node);
DEG_relations_tag_update(&bmain);
@@ -113,7 +112,7 @@ static void gather_search_items_for_asset_library(const bContext &C,
/* If an asset with the same name has already been added, skip this. */
return true;
}
search_items_for_asset_metadata(node_tree, library_ref, asset, search_items);
search_items_for_asset_metadata(node_tree, asset, search_items);
return true;
});
}

View File

@@ -141,7 +141,6 @@ static void add_existing_group_input_fn(nodes::LinkSearchOpParams &params,
*/
static void search_link_ops_for_asset_metadata(const bNodeTree &node_tree,
const bNodeSocket &socket,
const AssetLibraryReference &library_ref,
const AssetHandle asset,
Vector<SocketLinkOperation> &search_link_ops)
{
@@ -186,13 +185,13 @@ static void search_link_ops_for_asset_metadata(const bNodeTree &node_tree,
search_link_ops.append(
{asset_name + " " + UI_MENU_ARROW_SEP + socket_name,
[library_ref, asset, socket_property, in_out](nodes::LinkSearchOpParams &params) {
[asset, socket_property, in_out](nodes::LinkSearchOpParams &params) {
Main &bmain = *CTX_data_main(&params.C);
bNode &node = params.add_node(params.node_tree.typeinfo->group_idname);
node.flag &= ~NODE_OPTIONS;
node.id = asset::get_local_id_from_asset_or_append_and_reuse(bmain, library_ref, asset);
node.id = asset::get_local_id_from_asset_or_append_and_reuse(bmain, asset);
id_us_plus(node.id);
BKE_ntree_update_tag_node_property(&params.node_tree, &node);
DEG_relations_tag_update(&bmain);
@@ -232,7 +231,7 @@ static void gather_search_link_ops_for_asset_library(const bContext &C,
if (skip_local && ED_asset_handle_get_local_id(&asset) != nullptr) {
return true;
}
search_link_ops_for_asset_metadata(node_tree, socket, library_ref, asset, search_link_ops);
search_link_ops_for_asset_metadata(node_tree, socket, asset, search_link_ops);
return true;
});
}

View File

@@ -372,17 +372,14 @@ void NODE_OT_add_group(wmOperatorType *ot)
/** \name Add Node Group Asset Operator
* \{ */
static bool add_node_group_asset(const bContext &C,
const AssetLibraryReference &library_ref,
const AssetHandle asset,
ReportList &reports)
static bool add_node_group_asset(const bContext &C, const AssetHandle asset, ReportList &reports)
{
Main &bmain = *CTX_data_main(&C);
SpaceNode &snode = *CTX_wm_space_node(&C);
bNodeTree &edit_tree = *snode.edittree;
bNodeTree *node_group = reinterpret_cast<bNodeTree *>(
asset::get_local_id_from_asset_or_append_and_reuse(bmain, library_ref, asset));
asset::get_local_id_from_asset_or_append_and_reuse(bmain, asset));
if (!node_group) {
return false;
}
@@ -439,7 +436,7 @@ static int node_add_group_asset_invoke(bContext *C, wmOperator *op, const wmEven
snode.runtime->cursor /= UI_DPI_FAC;
if (!add_node_group_asset(*C, *library_ref, handle, *op->reports)) {
if (!add_node_group_asset(*C, handle, *op->reports)) {
return OPERATOR_CANCELLED;
}