Fix #113134: Use a valid socket in node groups for custom nodes

Custom node trees may not suppor the default NodeSocketFloat socket
type. In case this default type is not supported, search all registered
socket types and pick the first one that is supported by the custom
node tree.

Pull Request: https://projects.blender.org/blender/blender/pulls/113330
This commit is contained in:
Lukas Tönne 2023-10-06 14:33:35 +02:00
parent 271f634a84
commit dd9c906840
1 changed files with 19 additions and 3 deletions

View File

@ -288,7 +288,23 @@ class NODE_OT_interface_item_new(NodeInterfaceOperator, Operator):
default='INPUT',
)
socket_type = 'NodeSocketFloat'
# Returns a valid socket type for the given tree or None.
@staticmethod
def find_valid_socket_type(tree):
socket_type = 'NodeSocketFloat'
# Try the default float socket type
if tree.valid_socket_type(socket_type):
return socket_type
# Custom nodes may not support float sockets, search all
# registered socket subclasses.
types_to_check = [bpy.types.NodeSocket]
while types_to_check:
t = types_to_check.pop()
idname = getattr(t, "bl_idname", "")
if tree.valid_socket_type(idname):
return idname
# Test all subclasses
types_to_check.extend(t.__subclasses__())
def execute(self, context):
snode = context.space_data
@ -300,9 +316,9 @@ class NODE_OT_interface_item_new(NodeInterfaceOperator, Operator):
active_pos = active_item.position if active_item else -1
if self.item_type == 'INPUT':
item = interface.new_socket("Socket", socket_type=self.socket_type, in_out='INPUT')
item = interface.new_socket("Socket", socket_type=self.find_valid_socket_type(tree), in_out='INPUT')
elif self.item_type == 'OUTPUT':
item = interface.new_socket("Socket", socket_type=self.socket_type, in_out='OUTPUT')
item = interface.new_socket("Socket", socket_type=self.find_valid_socket_type(tree), in_out='OUTPUT')
elif self.item_type == 'PANEL':
item = interface.new_panel("Panel")
else: