Nodes: Add node group assets to search menus

Currently node group assets are supported, but using them by dragging
from the asset browser is cumbersome. This patch adds all node group
assets from user asset libraries and the current file libraries to the
add node search menu and the link drag search menu.

Node groups added through the search will have their "options" hidden,
meaning the data-block selector is displayed. This helps keep the UI
clean, and the selector shouldn't be necessary anyway.

To make that possible, metadata like the node tree type and its inputs
and outputs has to be saved in the file. This requires re-saving the
files that contain the assets with the patch applied.

The node add search operator is moved from Python to C++ to ease
development and allow more flexibility. It supports a tooltip that
gives the description of assets.

Currently the node groups are added with the asset system's existing
"Append & Reuse" behavior. It's likely that linking should be possible
in the future too, but for now the idea is to use the more foolproof
option that doesn't create dependencies between files.

Because loading assets can potentially take a long time, the search
menu refreshes its items as new assets are loaded. However, changing
the search field is necessary to see the update.

Differential Revision: https://developer.blender.org/D15568
This commit is contained in:
2022-09-19 11:57:10 -05:00
parent 862de9187f
commit bdb5754147
14 changed files with 613 additions and 83 deletions

View File

@@ -149,78 +149,6 @@ class NODE_OT_add_node(NodeAddOperator, Operator):
bl_options = {'REGISTER', 'UNDO'}
class NODE_OT_add_search(NodeAddOperator, Operator):
'''Add a node to the active tree'''
bl_idname = "node.add_search"
bl_label = "Search and Add Node"
bl_options = {'REGISTER', 'UNDO'}
bl_property = "node_item"
_enum_item_hack = []
# Create an enum list from node items
def node_enum_items(self, context):
import nodeitems_utils
enum_items = NODE_OT_add_search._enum_item_hack
enum_items.clear()
for index, item in enumerate(nodeitems_utils.node_items_iter(context)):
if isinstance(item, nodeitems_utils.NodeItem):
enum_items.append(
(str(index),
item.label,
"",
index,
))
return enum_items
# Look up the item based on index
def find_node_item(self, context):
import nodeitems_utils
node_item = int(self.node_item)
for index, item in enumerate(nodeitems_utils.node_items_iter(context)):
if index == node_item:
return item
return None
node_item: EnumProperty(
name="Node Type",
description="Node type",
items=NODE_OT_add_search.node_enum_items,
)
def execute(self, context):
item = self.find_node_item(context)
# no need to keep
self._enum_item_hack.clear()
if item:
# apply settings from the node item
for setting in item.settings.items():
ops = self.settings.add()
ops.name = setting[0]
ops.value = setting[1]
self.create_node(context, item.nodetype)
if self.use_transform:
bpy.ops.node.translate_attach_remove_on_cancel(
'INVOKE_DEFAULT')
return {'FINISHED'}
else:
return {'CANCELLED'}
def invoke(self, context, event):
self.store_mouse_cursor(context, event)
# Delayed execution in the search popup
context.window_manager.invoke_search_popup(self)
return {'CANCELLED'}
class NODE_OT_collapse_hide_unused_toggle(Operator):
'''Toggle collapsed nodes and hide unused sockets'''
bl_idname = "node.collapse_hide_unused_toggle"
@@ -276,7 +204,6 @@ classes = (
NodeSetting,
NODE_OT_add_node,
NODE_OT_add_search,
NODE_OT_collapse_hide_unused_toggle,
NODE_OT_tree_path_parent,
)