Node Groups: expose the SOCK_HIDE_VALUE flag for node group inputs.

This flag specifies that even when the socket is not connected,
the node should not display the input field for the constant input
value. This is useful for inputs like Normal, which have special
handling for the missing input case and don't use a constant value.
Currently there is no way to change this flag from Python, and
through UI it can only be done by re-creating the socket.

This patch exposes the flag through RNA and UI, makes sure it
is properly updated when changed, and adds special handling to
ensure that it is correctly set when creating a node group from
a node set that includes reroute nodes.

Differential Revision: https://developer.blender.org/D8395
This commit is contained in:
2020-07-27 15:03:23 +03:00
parent b016e7f258
commit 9306037ed3
6 changed files with 87 additions and 11 deletions

View File

@@ -3576,6 +3576,8 @@ static void std_node_socket_interface_draw(bContext *UNUSED(C), uiLayout *layout
break;
}
}
uiItemR(layout, ptr, "hide_value", DEFAULT_FLAGS, NULL, 0);
}
void ED_init_standard_node_socket_type(bNodeSocketType *stype)

View File

@@ -56,6 +56,7 @@
#include "UI_resources.h"
#include "NOD_common.h"
#include "NOD_socket.h"
#include "node_intern.h" /* own include */
static bool node_group_operator_active(bContext *C)
@@ -719,8 +720,8 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
Main *bmain = CTX_data_main(C);
bNodeTree *ngroup = (bNodeTree *)gnode->id;
bNodeLink *link, *linkn;
bNode *node, *nextn;
bNodeSocket *sock;
bNode *node, *nextn, *link_node;
bNodeSocket *sock, *link_sock;
ListBase anim_basepaths = {NULL, NULL};
float min[2], max[2], real_min[2], real_max[2], center[2];
int totselect;
@@ -821,12 +822,9 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
*/
nodeRemLink(ntree, link);
}
else if (fromselect && toselect) {
BLI_remlink(&ntree->links, link);
BLI_addtail(&ngroup->links, link);
}
else if (toselect) {
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->tonode, link->tosock);
else if (toselect && !fromselect) {
node_socket_skip_reroutes(&ntree->links, link->tonode, link->tosock, &link_node, &link_sock);
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock);
bNodeSocket *input_sock;
/* update the group node and interface node sockets,
@@ -843,7 +841,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
link->tonode = gnode;
link->tosock = node_group_find_input_socket(gnode, iosock->identifier);
}
else if (fromselect) {
else if (fromselect && !toselect) {
/* First check whether the source of this link is already connected to an output.
* If yes, reuse that output instead of duplicating it. */
bool connected = false;
@@ -859,8 +857,9 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
}
if (!connected) {
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(
ngroup, link->fromnode, link->fromsock);
node_socket_skip_reroutes(
&ntree->links, link->fromnode, link->fromsock, &link_node, &link_sock);
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock);
bNodeSocket *output_sock;
/* update the group node and interface node sockets,
@@ -880,6 +879,19 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
}
}
/* move internal links */
for (link = ntree->links.first; link; link = linkn) {
int fromselect = node_group_make_use_node(link->fromnode, gnode);
int toselect = node_group_make_use_node(link->tonode, gnode);
linkn = link->next;
if (fromselect && toselect) {
BLI_remlink(&ntree->links, link);
BLI_addtail(&ngroup->links, link);
}
}
/* move nodes in the group to the center */
for (node = ngroup->nodes.first; node; node = node->next) {
if (node_group_make_use_node(node, gnode) && !node->parent) {

View File

@@ -8466,6 +8466,12 @@ static void rna_def_node_socket_interface(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Is Output", "True if the socket is an output, otherwise input");
prop = RNA_def_property(srna, "hide_value", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_HIDE_VALUE);
RNA_def_property_ui_text(
prop, "Hide Value", "Hide the socket input value even when the socket is not connected");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update");
/* registration */
prop = RNA_def_property(srna, "bl_socket_idname", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "typeinfo->idname");

View File

@@ -48,6 +48,11 @@ void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node);
void node_socket_init_default_value(struct bNodeSocket *sock);
void node_socket_copy_default_value(struct bNodeSocket *to, const struct bNodeSocket *from);
void node_socket_skip_reroutes(struct ListBase *links,
struct bNode *node,
struct bNodeSocket *socket,
struct bNode **r_node,
struct bNodeSocket **r_socket);
void register_standard_node_socket_types(void);
#ifdef __cplusplus

View File

@@ -132,6 +132,9 @@ static bNodeSocket *group_verify_socket(
if (sock) {
strcpy(sock->name, iosock->name);
const int mask = SOCK_HIDE_VALUE;
sock->flag = (sock->flag & ~mask) | (iosock->flag & mask);
if (iosock->typeinfo->interface_verify_socket) {
iosock->typeinfo->interface_verify_socket(ntree, iosock, gnode, sock, "interface");
}

View File

@@ -356,6 +356,54 @@ void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from)
to->flag |= (from->flag & SOCK_HIDE_VALUE);
}
void node_socket_skip_reroutes(
ListBase *links, bNode *node, bNodeSocket *socket, bNode **r_node, bNodeSocket **r_socket)
{
const int loop_limit = 100; /* Limit in case there is a connection cycle. */
if (socket->in_out == SOCK_IN) {
bNodeLink *first_link = (bNodeLink *)links->first;
for (int i = 0; node->type == NODE_REROUTE && i < loop_limit; i++) {
bNodeLink *link = first_link;
for (; link; link = link->next) {
if (link->fromnode == node && link->tonode != node) {
break;
}
}
if (link) {
node = link->tonode;
socket = link->tosock;
}
else {
break;
}
}
}
else {
for (int i = 0; node->type == NODE_REROUTE && i < loop_limit; i++) {
bNodeSocket *input = (bNodeSocket *)node->inputs.first;
if (input && input->link) {
node = input->link->fromnode;
socket = input->link->fromsock;
}
else {
break;
}
}
}
if (r_node) {
*r_node = node;
}
if (r_socket) {
*r_socket = socket;
}
}
static void standard_node_socket_interface_init_socket(bNodeTree *UNUSED(ntree),
bNodeSocket *stemp,
bNode *UNUSED(node),