Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Emara <mail@OmarEmara.dev>2021-11-29 14:01:53 +0300
committerOmar Emara <mail@OmarEmara.dev>2021-11-29 14:01:53 +0300
commitf1118ee51ea02c3c4ca6f088e81dc6dbba1ba7fe (patch)
tree8980aa1d5f1d422e82fed575013d3beb97aa42ab /source/blender/nodes/intern
parentab2a7aa0da81678b19e3362b93f89e8302da65d8 (diff)
Nodes: Support internal links for custom sockets
Currently, nodes with custom sockets do not get their internal links populated. So operators like Delete And Reconnect don't work with such nodes. This patch put custom sockets into consideration when computing priorities for internal links such that sockets of the same idname get connected. Additionally, the patch cleanup the function in the process to avoid redundant code repetition. Reviewed By: Jacques Lucke Differential Revision: https://developer.blender.org/D13386
Diffstat (limited to 'source/blender/nodes/intern')
-rw-r--r--source/blender/nodes/intern/node_util.c101
1 files changed, 20 insertions, 81 deletions
diff --git a/source/blender/nodes/intern/node_util.c b/source/blender/nodes/intern/node_util.c
index 231030030eb..ecd08431e18 100644
--- a/source/blender/nodes/intern/node_util.c
+++ b/source/blender/nodes/intern/node_util.c
@@ -351,11 +351,11 @@ void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
* `< 0`: never connect these types.
* `>= 0`: priority of connection (higher values chosen first).
*/
-static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype to)
+static int node_datatype_priority(const bNodeSocketType *from, const bNodeSocketType *to)
{
- switch (to) {
+ switch (to->type) {
case SOCK_RGBA:
- switch (from) {
+ switch (from->type) {
case SOCK_RGBA:
return 4;
case SOCK_FLOAT:
@@ -364,11 +364,10 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
return 2;
case SOCK_BOOLEAN:
return 1;
- default:
- return -1;
}
+ return -1;
case SOCK_VECTOR:
- switch (from) {
+ switch (from->type) {
case SOCK_VECTOR:
return 4;
case SOCK_FLOAT:
@@ -377,11 +376,10 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
return 2;
case SOCK_BOOLEAN:
return 1;
- default:
- return -1;
}
+ return -1;
case SOCK_FLOAT:
- switch (from) {
+ switch (from->type) {
case SOCK_FLOAT:
return 5;
case SOCK_INT:
@@ -392,11 +390,10 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
return 2;
case SOCK_VECTOR:
return 1;
- default:
- return -1;
}
+ return -1;
case SOCK_INT:
- switch (from) {
+ switch (from->type) {
case SOCK_INT:
return 5;
case SOCK_FLOAT:
@@ -407,11 +404,10 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
return 2;
case SOCK_VECTOR:
return 1;
- default:
- return -1;
}
+ return -1;
case SOCK_BOOLEAN:
- switch (from) {
+ switch (from->type) {
case SOCK_BOOLEAN:
return 5;
case SOCK_INT:
@@ -422,74 +418,17 @@ static int node_datatype_priority(eNodeSocketDatatype from, eNodeSocketDatatype
return 2;
case SOCK_VECTOR:
return 1;
- default:
- return -1;
- }
- case SOCK_SHADER:
- switch (from) {
- case SOCK_SHADER:
- return 1;
- default:
- return -1;
- }
- case SOCK_STRING:
- switch (from) {
- case SOCK_STRING:
- return 1;
- default:
- return -1;
}
- case SOCK_OBJECT: {
- switch (from) {
- case SOCK_OBJECT:
- return 1;
- default:
- return -1;
- }
- }
- case SOCK_GEOMETRY: {
- switch (from) {
- case SOCK_GEOMETRY:
- return 1;
- default:
- return -1;
- }
- }
- case SOCK_COLLECTION: {
- switch (from) {
- case SOCK_COLLECTION:
- return 1;
- default:
- return -1;
- }
- }
- case SOCK_TEXTURE: {
- switch (from) {
- case SOCK_TEXTURE:
- return 1;
- default:
- return -1;
- }
- }
- case SOCK_IMAGE: {
- switch (from) {
- case SOCK_IMAGE:
- return 1;
- default:
- return -1;
- }
- }
- case SOCK_MATERIAL: {
- switch (from) {
- case SOCK_MATERIAL:
- return 1;
- default:
- return -1;
- }
- }
- default:
return -1;
}
+
+ /* The rest of the socket types only allow an internal link if both the input and output socket
+ * have the same type. If the sockets are custom, we check the idname instead. */
+ if (to->type == from->type && (to->type != SOCK_CUSTOM || STREQ(to->idname, from->idname))) {
+ return 1;
+ }
+
+ return -1;
}
/* select a suitable input socket for an output */
@@ -505,7 +444,7 @@ static bNodeSocket *select_internal_link_input(bNode *node, bNodeSocket *output)
bool sel_is_linked = false;
for (input = node->inputs.first, i = 0; input; input = input->next, i++) {
- int priority = node_datatype_priority(input->type, output->type);
+ int priority = node_datatype_priority(input->typeinfo, output->typeinfo);
bool is_linked = (input->link != NULL);
bool preferred;