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

Merged
Hans Goudey merged 2 commits from pioverfour/blender:dp_multi_input_socket_rna into main 2024-02-12 20:29:07 +01:00
3 changed files with 21 additions and 11 deletions
Showing only changes of commit 2ef36715ae - Show all commits

View File

@ -613,14 +613,12 @@ static PyObject *osl_update_node_func(PyObject * /*self*/, PyObject *args)
if (!found_existing) {
/* Create new socket. */
BL::NodeSocket b_sock = (param->isoutput) ? b_node.outputs.create(b_data,
socket_type.c_str(),
param_label.c_str(),
param->name.c_str()) :
b_node.inputs.create(b_data,
socket_type.c_str(),
param_label.c_str(),
param->name.c_str());
BL::NodeSocket b_sock =
(param->isoutput) ?
b_node.outputs.create(
b_data, socket_type.c_str(), param_label.c_str(), param->name.c_str(), false) :
b_node.inputs.create(
b_data, socket_type.c_str(), param_label.c_str(), param->name.c_str(), false);
/* set default value */
if (data_type == BL::NodeSocket::type_VALUE) {

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")

View File

@ -2197,7 +2197,8 @@ static bNodeSocket *rna_Node_inputs_new(ID *id,
ReportList *reports,
const char *type,
const char *name,
const char *identifier)
const char *identifier,
const bool use_multi_input)
{
if (!allow_changing_sockets(node)) {
BKE_report(reports, RPT_ERROR, "Cannot add socket to built-in node");
@ -2211,6 +2212,9 @@ static bNodeSocket *rna_Node_inputs_new(ID *id,
BKE_report(reports, RPT_ERROR, "Unable to create socket");
}
else {
if (use_multi_input) {
sock->flag |= SOCK_MULTI_INPUT;
}
ED_node_tree_propagate_change(nullptr, bmain, ntree);
WM_main_add_notifier(NC_NODE | NA_EDITED, ntree);
}
@ -2224,13 +2228,19 @@ static bNodeSocket *rna_Node_outputs_new(ID *id,
ReportList *reports,
const char *type,
const char *name,
const char *identifier)
const char *identifier,
const bool use_multi_input)
{
if (!allow_changing_sockets(node)) {
BKE_report(reports, RPT_ERROR, "Cannot add socket to built-in node");
return nullptr;
}
if (use_multi_input) {
BKE_report(reports, RPT_ERROR, "Output sockets cannot be multi-input");
return nullptr;
}
bNodeTree *ntree = reinterpret_cast<bNodeTree *>(id);
bNodeSocket *sock = nodeAddSocket(ntree, node, SOCK_OUT, type, identifier, name);
@ -9489,6 +9499,8 @@ static void rna_def_node_sockets_api(BlenderRNA *brna, PropertyRNA *cprop, int i
parm = RNA_def_string(func, "name", nullptr, MAX_NAME, "Name", "");
RNA_def_parameter_flags(parm, PropertyFlag(0), PARM_REQUIRED);
RNA_def_string(func, "identifier", nullptr, MAX_NAME, "Identifier", "Unique socket identifier");
RNA_def_boolean(
func, "use_multi_input", false, "", "Make the socket a multi-input. Only valid for inputs");
/* return value */
parm = RNA_def_pointer(func, "socket", "NodeSocket", "", "New socket");
RNA_def_function_return(func, parm);