Nodes: expose multi-input sockets to custom nodes in the Python API

Currently the multi-input sockets are not exposed to the custom nodes
Python API. This makes some features cumbersome to implement if one
wants a node to process an arbitrary number of inputs.
One workaround is to make inputs duplicate themselves when a link is
created, but a proper multi-input would be easier to use for both
add-on developers and users.

This commit exposes a new `use_multi_input` boolean parameter when
creating a new node socket. This makes it possible to declare a
multi-input, while still leaving the existing `is_multi_input`
property read-only so that existing nodes cannot be made unstable.

The parameter is optional so existing scripts stay compatible. It also
raises an error when used on output sockets, since it makes no sense
for those to be multi-input.

The Custom Node Tree Python template was updated to reflect this
change by making one of the inputs of the custom node multi-input.

Pull Request: https://projects.blender.org/blender/blender/pulls/114474
This commit is contained in:
Damien Picard
2024-02-12 20:28:56 +01:00
committed by Hans Goudey
parent 4f68fa453f
commit 1410615079
3 changed files with 21 additions and 11 deletions

View File

@@ -99,7 +99,7 @@ class MyCustomNode(MyCustomTreeNode, Node):
def init(self, context):
self.inputs.new('CustomSocketType', "Hello")
self.inputs.new('NodeSocketFloat', "World")
self.inputs.new('NodeSocketVector', "!")
self.inputs.new('NodeSocketVector', "!", use_multi_input=True)
self.outputs.new('NodeSocketColor', "How")
self.outputs.new('NodeSocketColor', "are")