2011-10-23 17:52:20 +00:00
|
|
|
/*
|
2011-09-05 21:01:50 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2011-09-05 21:01:50 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2007 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup nodes
|
2011-09-05 21:01:50 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-09-30 15:44:08 +02:00
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstring>
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
2021-10-01 11:42:00 +02:00
|
|
|
#include "BLI_map.hh"
|
|
|
|
|
#include "BLI_multi_value_map.hh"
|
|
|
|
|
#include "BLI_set.hh"
|
|
|
|
|
#include "BLI_stack.hh"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BLI_string.h"
|
2021-12-14 10:56:12 -06:00
|
|
|
#include "BLI_string_ref.hh"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2012-03-17 14:42:44 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_node.h"
|
2021-12-21 15:18:56 +01:00
|
|
|
#include "BKE_node_tree_update.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
|
#include "RNA_types.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "NOD_common.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "node_common.h"
|
2012-05-22 14:13:33 +00:00
|
|
|
#include "node_util.h"
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2021-10-01 11:42:00 +02:00
|
|
|
using blender::Map;
|
|
|
|
|
using blender::MultiValueMap;
|
|
|
|
|
using blender::Set;
|
|
|
|
|
using blender::Stack;
|
2021-12-14 10:56:12 -06:00
|
|
|
using blender::StringRef;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2020-11-06 16:14:43 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Group
|
|
|
|
|
* \{ */
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
static bNodeSocket *find_matching_socket(ListBase &sockets, StringRef identifier)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-12-14 10:56:12 -06:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, socket, &sockets) {
|
|
|
|
|
if (socket->identifier == identifier) {
|
|
|
|
|
return socket;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-30 15:44:08 +02:00
|
|
|
return nullptr;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
bNodeSocket *node_group_find_input_socket(bNode *groupnode, const char *identifier)
|
|
|
|
|
{
|
|
|
|
|
return find_matching_socket(groupnode->inputs, identifier);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identifier)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-12-14 10:56:12 -06:00
|
|
|
return find_matching_socket(groupnode->outputs, identifier);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-11 09:51:53 -06:00
|
|
|
void node_group_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2016-09-19 16:46:20 +02:00
|
|
|
BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Data-Block"), maxlen);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 18:43:23 +02:00
|
|
|
bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **disabled_hint)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-04-12 18:43:23 +02:00
|
|
|
if (node->typeinfo->poll(node->typeinfo, nodetree, disabled_hint)) {
|
2013-05-27 08:04:07 +00:00
|
|
|
bNodeTree *grouptree = (bNodeTree *)node->id;
|
2019-04-22 13:31:31 +10:00
|
|
|
if (grouptree) {
|
2021-04-12 18:43:23 +02:00
|
|
|
return nodeGroupPoll(nodetree, grouptree, disabled_hint);
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2020-08-07 12:40:49 +02:00
|
|
|
|
|
|
|
|
return true; /* without a linked node tree, group node is always ok */
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2020-08-07 12:40:49 +02:00
|
|
|
|
|
|
|
|
return false;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-12 18:43:23 +02:00
|
|
|
bool nodeGroupPoll(bNodeTree *nodetree, bNodeTree *grouptree, const char **r_disabled_hint)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-04-12 18:43:23 +02:00
|
|
|
bool valid = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-10 17:48:41 +00:00
|
|
|
/* unspecified node group, generally allowed
|
|
|
|
|
* (if anything, should be avoided on operator level)
|
|
|
|
|
*/
|
2021-09-30 15:44:08 +02:00
|
|
|
if (grouptree == nullptr) {
|
2021-04-12 18:43:23 +02:00
|
|
|
return true;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 13:31:31 +10:00
|
|
|
if (nodetree == grouptree) {
|
2021-12-01 21:55:04 -05:00
|
|
|
*r_disabled_hint = TIP_("Nesting a node group inside of itself is not allowed");
|
2021-04-12 18:43:23 +02:00
|
|
|
return false;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-30 15:44:08 +02:00
|
|
|
LISTBASE_FOREACH (bNode *, node, &grouptree->nodes) {
|
2021-04-12 18:43:23 +02:00
|
|
|
if (node->typeinfo->poll_instance &&
|
|
|
|
|
!node->typeinfo->poll_instance(node, nodetree, r_disabled_hint)) {
|
|
|
|
|
valid = false;
|
2013-03-18 16:34:57 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
return valid;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
static void add_new_socket_from_interface(bNodeTree &node_tree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
const bNodeSocket &interface_socket,
|
|
|
|
|
const eNodeSocketInOut in_out)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-12-14 10:56:12 -06:00
|
|
|
bNodeSocket *socket = nodeAddSocket(&node_tree,
|
|
|
|
|
&node,
|
|
|
|
|
in_out,
|
|
|
|
|
interface_socket.idname,
|
|
|
|
|
interface_socket.identifier,
|
|
|
|
|
interface_socket.name);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
if (interface_socket.typeinfo->interface_init_socket) {
|
|
|
|
|
interface_socket.typeinfo->interface_init_socket(
|
|
|
|
|
&node_tree, &interface_socket, &node, socket, "interface");
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2021-12-14 10:56:12 -06:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
static void update_socket_to_match_interface(bNodeTree &node_tree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
bNodeSocket &socket_to_update,
|
|
|
|
|
const bNodeSocket &interface_socket)
|
|
|
|
|
{
|
|
|
|
|
strcpy(socket_to_update.name, interface_socket.name);
|
2020-07-27 15:03:23 +03:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
const int mask = SOCK_HIDE_VALUE;
|
|
|
|
|
socket_to_update.flag = (socket_to_update.flag & ~mask) | (interface_socket.flag & mask);
|
2021-07-06 18:36:11 +01:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
/* Update socket type if necessary */
|
|
|
|
|
if (socket_to_update.typeinfo != interface_socket.typeinfo) {
|
|
|
|
|
nodeModifySocketType(&node_tree, &node, &socket_to_update, interface_socket.idname);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
if (interface_socket.typeinfo->interface_verify_socket) {
|
|
|
|
|
interface_socket.typeinfo->interface_verify_socket(
|
|
|
|
|
&node_tree, &interface_socket, &node, &socket_to_update, "interface");
|
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-14 10:56:12 -06:00
|
|
|
/**
|
|
|
|
|
* Used for group nodes and group input/output nodes to update the list of input or output sockets
|
|
|
|
|
* on a node to match the provided interface. Assumes that \a verify_lb is the node's matching
|
|
|
|
|
* input or output socket list, depending on whether the node is a group input/output or a group
|
|
|
|
|
* node.
|
|
|
|
|
*/
|
|
|
|
|
static void group_verify_socket_list(bNodeTree &node_tree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
const ListBase &interface_sockets,
|
|
|
|
|
ListBase &verify_lb,
|
|
|
|
|
const eNodeSocketInOut in_out)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
2021-12-14 10:56:12 -06:00
|
|
|
ListBase old_sockets = verify_lb;
|
|
|
|
|
BLI_listbase_clear(&verify_lb);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (const bNodeSocket *, interface_socket, &interface_sockets) {
|
|
|
|
|
bNodeSocket *matching_socket = find_matching_socket(old_sockets, interface_socket->identifier);
|
|
|
|
|
if (matching_socket) {
|
|
|
|
|
/* If a socket with the same identifier exists in the previous socket list, update it
|
|
|
|
|
* with the correct name, type, etc. Then move it from the old list to the new one. */
|
|
|
|
|
update_socket_to_match_interface(node_tree, node, *matching_socket, *interface_socket);
|
|
|
|
|
BLI_remlink(&old_sockets, matching_socket);
|
|
|
|
|
BLI_addtail(&verify_lb, matching_socket);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2021-12-14 10:56:12 -06:00
|
|
|
else {
|
|
|
|
|
/* If there was no socket withe the same identifier already, simply create a new socket
|
|
|
|
|
* based on the interface socket, which will already add it to the new list. */
|
|
|
|
|
add_new_socket_from_interface(node_tree, node, *interface_socket, in_out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove leftover sockets that didn't match the node group's interface. */
|
|
|
|
|
LISTBASE_FOREACH_MUTABLE (bNodeSocket *, unused_socket, &old_sockets) {
|
|
|
|
|
nodeRemoveSocket(&node_tree, &node, unused_socket);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
/* check inputs and outputs, and remove or insert them */
|
2021-09-30 15:44:08 +02:00
|
|
|
if (node->id == nullptr) {
|
2019-04-20 20:25:22 +02:00
|
|
|
nodeRemoveAllSockets(ntree, node);
|
|
|
|
|
}
|
2020-11-19 14:23:48 +01:00
|
|
|
else if ((ID_IS_LINKED(node->id) && (node->id->tag & LIB_TAG_MISSING))) {
|
2021-09-29 07:29:15 +10:00
|
|
|
/* Missing data-block, leave sockets unchanged so that when it comes back
|
2020-11-19 14:23:48 +01:00
|
|
|
* the links remain valid. */
|
|
|
|
|
}
|
2019-04-20 20:25:22 +02:00
|
|
|
else {
|
|
|
|
|
bNodeTree *ngroup = (bNodeTree *)node->id;
|
2021-12-14 10:56:12 -06:00
|
|
|
group_verify_socket_list(*ntree, *node, ngroup->inputs, node->inputs, SOCK_IN);
|
|
|
|
|
group_verify_socket_list(*ntree, *node, ngroup->outputs, node->outputs, SOCK_OUT);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-06 16:14:43 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Frame
|
|
|
|
|
* \{ */
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void node_frame_init(bNodeTree *UNUSED(ntree), bNode *node)
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2021-12-24 22:17:49 -05:00
|
|
|
NodeFrame *data = MEM_cnew<NodeFrame>("frame node storage");
|
2012-05-22 14:13:33 +00:00
|
|
|
node->storage = data;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
data->flag |= NODE_FRAME_SHRINK;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
data->label_size = 20;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void register_node_type_frame(void)
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
|
/* frame type is used for all tree types, needs dynamic allocation */
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeType *ntype = MEM_cnew<bNodeType>("frame node type");
|
2020-02-28 13:28:16 +01:00
|
|
|
ntype->free_self = (void (*)(bNodeType *))MEM_freeN;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2013-05-29 15:38:51 +00:00
|
|
|
node_type_base(ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND);
|
2012-05-22 14:13:33 +00:00
|
|
|
node_type_init(ntype, node_frame_init);
|
|
|
|
|
node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage);
|
2011-09-05 21:01:50 +00:00
|
|
|
node_type_size(ntype, 150, 100, 0);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeRegisterType(ntype);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2020-11-06 16:14:43 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node Re-Route
|
|
|
|
|
* \{ */
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
static void node_reroute_init(bNodeTree *ntree, bNode *node)
|
2012-08-06 16:25:38 +00:00
|
|
|
{
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: Cannot use socket templates for this, since it would reset the socket type
|
2012-08-06 16:25:38 +00:00
|
|
|
* on each file read via the template verification procedure.
|
|
|
|
|
*/
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, "Input", "Input");
|
|
|
|
|
nodeAddStaticSocket(ntree, node, SOCK_OUT, SOCK_RGBA, PROP_NONE, "Output", "Output");
|
2012-08-06 16:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void register_node_type_reroute(void)
|
2012-08-06 18:49:28 +00:00
|
|
|
{
|
|
|
|
|
/* frame type is used for all tree types, needs dynamic allocation */
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeType *ntype = MEM_cnew<bNodeType>("frame node type");
|
2020-02-28 13:28:16 +01:00
|
|
|
ntype->free_self = (void (*)(bNodeType *))MEM_freeN;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
node_type_base(ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0);
|
2012-08-06 18:49:28 +00:00
|
|
|
node_type_init(ntype, node_reroute_init);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeRegisterType(ntype);
|
2012-08-06 18:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-01 11:42:00 +02:00
|
|
|
static void propagate_reroute_type_from_start_socket(
|
|
|
|
|
bNodeSocket *start_socket,
|
|
|
|
|
const MultiValueMap<bNodeSocket *, bNodeLink *> &links_map,
|
|
|
|
|
Map<bNode *, const bNodeSocketType *> &r_reroute_types)
|
2012-06-12 08:28:25 +00:00
|
|
|
{
|
2021-10-01 11:42:00 +02:00
|
|
|
Stack<bNode *> nodes_to_check;
|
|
|
|
|
for (bNodeLink *link : links_map.lookup(start_socket)) {
|
|
|
|
|
if (link->tonode->type == NODE_REROUTE) {
|
|
|
|
|
nodes_to_check.push(link->tonode);
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2021-10-01 11:42:00 +02:00
|
|
|
if (link->fromnode->type == NODE_REROUTE) {
|
|
|
|
|
nodes_to_check.push(link->fromnode);
|
2015-05-06 11:46:47 +02:00
|
|
|
}
|
2012-08-06 18:49:28 +00:00
|
|
|
}
|
2021-10-01 11:42:00 +02:00
|
|
|
const bNodeSocketType *current_type = start_socket->typeinfo;
|
|
|
|
|
while (!nodes_to_check.is_empty()) {
|
|
|
|
|
bNode *reroute_node = nodes_to_check.pop();
|
|
|
|
|
BLI_assert(reroute_node->type == NODE_REROUTE);
|
|
|
|
|
if (r_reroute_types.add(reroute_node, current_type)) {
|
|
|
|
|
for (bNodeLink *link : links_map.lookup((bNodeSocket *)reroute_node->inputs.first)) {
|
|
|
|
|
if (link->fromnode->type == NODE_REROUTE) {
|
|
|
|
|
nodes_to_check.push(link->fromnode);
|
|
|
|
|
}
|
2013-07-31 12:26:01 +00:00
|
|
|
}
|
2021-10-01 11:42:00 +02:00
|
|
|
for (bNodeLink *link : links_map.lookup((bNodeSocket *)reroute_node->outputs.first)) {
|
|
|
|
|
if (link->tonode->type == NODE_REROUTE) {
|
|
|
|
|
nodes_to_check.push(link->tonode);
|
|
|
|
|
}
|
2013-07-31 12:26:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-12 08:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-06 18:49:28 +00:00
|
|
|
void ntree_update_reroute_nodes(bNodeTree *ntree)
|
2012-06-01 12:38:03 +00:00
|
|
|
{
|
2021-10-01 11:42:00 +02:00
|
|
|
/* Contains nodes that are linked to at least one reroute node. */
|
|
|
|
|
Set<bNode *> nodes_linked_with_reroutes;
|
|
|
|
|
/* Contains all links that are linked to at least one reroute node. */
|
|
|
|
|
MultiValueMap<bNodeSocket *, bNodeLink *> links_map;
|
|
|
|
|
/* Build acceleration data structures for the algorithm below. */
|
|
|
|
|
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
|
|
|
|
if (link->fromsock == nullptr || link->tosock == nullptr) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (link->fromnode->type != NODE_REROUTE && link->tonode->type != NODE_REROUTE) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (link->fromnode->type != NODE_REROUTE) {
|
|
|
|
|
nodes_linked_with_reroutes.add(link->fromnode);
|
|
|
|
|
}
|
|
|
|
|
if (link->tonode->type != NODE_REROUTE) {
|
|
|
|
|
nodes_linked_with_reroutes.add(link->tonode);
|
|
|
|
|
}
|
|
|
|
|
links_map.add(link->fromsock, link);
|
|
|
|
|
links_map.add(link->tosock, link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Will contain the socket type for every linked reroute node. */
|
|
|
|
|
Map<bNode *, const bNodeSocketType *> reroute_types;
|
|
|
|
|
|
|
|
|
|
/* Propagate socket types from left to right. */
|
|
|
|
|
for (bNode *start_node : nodes_linked_with_reroutes) {
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, output_socket, &start_node->outputs) {
|
|
|
|
|
propagate_reroute_type_from_start_socket(output_socket, links_map, reroute_types);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-10-01 11:42:00 +02:00
|
|
|
/* Propagate socket types from right to left. This affects reroute nodes that haven't been
|
|
|
|
|
* changed in the the loop above. */
|
|
|
|
|
for (bNode *start_node : nodes_linked_with_reroutes) {
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input_socket, &start_node->inputs) {
|
|
|
|
|
propagate_reroute_type_from_start_socket(input_socket, links_map, reroute_types);
|
|
|
|
|
}
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-10-01 11:42:00 +02:00
|
|
|
/* Actually update reroute nodes with changed types. */
|
2021-10-12 09:13:21 -05:00
|
|
|
for (const auto item : reroute_types.items()) {
|
2021-10-01 11:42:00 +02:00
|
|
|
bNode *reroute_node = item.key;
|
|
|
|
|
const bNodeSocketType *socket_type = item.value;
|
|
|
|
|
bNodeSocket *input_socket = (bNodeSocket *)reroute_node->inputs.first;
|
|
|
|
|
bNodeSocket *output_socket = (bNodeSocket *)reroute_node->outputs.first;
|
|
|
|
|
|
|
|
|
|
if (input_socket->typeinfo != socket_type) {
|
|
|
|
|
nodeModifySocketType(ntree, reroute_node, input_socket, socket_type->idname);
|
|
|
|
|
}
|
|
|
|
|
if (output_socket->typeinfo != socket_type) {
|
|
|
|
|
nodeModifySocketType(ntree, reroute_node, output_socket, socket_type->idname);
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
2012-10-01 07:54:37 +00:00
|
|
|
|
2014-07-23 11:33:29 -03:00
|
|
|
static bool node_is_connected_to_output_recursive(bNodeTree *ntree, bNode *node)
|
|
|
|
|
{
|
|
|
|
|
bNodeLink *link;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-23 11:33:29 -03:00
|
|
|
/* avoid redundant checks, and infinite loops in case of cyclic node links */
|
2019-04-22 13:31:31 +10:00
|
|
|
if (node->done) {
|
2014-07-23 11:33:29 -03:00
|
|
|
return false;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2014-07-23 11:33:29 -03:00
|
|
|
node->done = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-23 11:33:29 -03:00
|
|
|
/* main test, done before child loop so it catches output nodes themselves as well */
|
2019-04-22 13:31:31 +10:00
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->flag & NODE_DO_OUTPUT) {
|
2014-07-23 11:33:29 -03:00
|
|
|
return true;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-23 11:33:29 -03:00
|
|
|
/* test all connected nodes, first positive find is sufficient to return true */
|
2021-09-30 15:44:08 +02:00
|
|
|
for (link = (bNodeLink *)ntree->links.first; link; link = link->next) {
|
2014-07-23 11:33:29 -03:00
|
|
|
if (link->fromnode == node) {
|
2019-04-22 13:31:31 +10:00
|
|
|
if (node_is_connected_to_output_recursive(ntree, link->tonode)) {
|
2014-07-23 11:33:29 -03:00
|
|
|
return true;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2014-07-23 11:33:29 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BKE_node_is_connected_to_output(bNodeTree *ntree, bNode *node)
|
|
|
|
|
{
|
|
|
|
|
bNode *tnode;
|
|
|
|
|
|
|
|
|
|
/* clear flags */
|
2021-09-30 15:44:08 +02:00
|
|
|
for (tnode = (bNode *)ntree->nodes.first; tnode; tnode = tnode->next) {
|
2014-07-23 11:33:29 -03:00
|
|
|
tnode->done = 0;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2014-07-23 11:33:29 -03:00
|
|
|
|
|
|
|
|
return node_is_connected_to_output_recursive(ntree, node);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree)
|
2012-10-01 07:54:37 +00:00
|
|
|
{
|
|
|
|
|
bNode *node;
|
|
|
|
|
|
2021-09-30 15:44:08 +02:00
|
|
|
for (node = (bNode *)ntree->nodes.first; node; node = node->next) {
|
2012-10-01 07:54:37 +00:00
|
|
|
if (node->id == id) {
|
2021-09-30 15:44:08 +02:00
|
|
|
node->id = nullptr;
|
2012-10-01 07:54:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
2020-11-06 16:14:43 +11:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Node #GROUP_INPUT / #GROUP_OUTPUT
|
|
|
|
|
* \{ */
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
|
static void node_group_input_init(bNodeTree *ntree, bNode *node)
|
|
|
|
|
{
|
2019-04-20 20:25:22 +02:00
|
|
|
node_group_input_update(ntree, node);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNodeSocket *node_group_input_find_socket(bNode *node, const char *identifier)
|
|
|
|
|
{
|
|
|
|
|
bNodeSocket *sock;
|
2021-09-30 15:44:08 +02:00
|
|
|
for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) {
|
2019-04-22 13:31:31 +10:00
|
|
|
if (STREQ(sock->identifier, identifier)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
return sock;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-30 15:44:08 +02:00
|
|
|
return nullptr;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
void node_group_input_update(bNodeTree *ntree, bNode *node)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2021-09-30 15:44:08 +02:00
|
|
|
bNodeSocket *extsock = (bNodeSocket *)node->outputs.last;
|
2014-04-23 12:00:28 +02:00
|
|
|
bNodeLink *link, *linknext, *exposelink;
|
2013-03-18 16:34:57 +00:00
|
|
|
/* Adding a tree socket and verifying will remove the extension socket!
|
|
|
|
|
* This list caches the existing links from the extension socket
|
|
|
|
|
* so they can be recreated after verification.
|
|
|
|
|
*/
|
|
|
|
|
ListBase tmplinks;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* find links from the extension socket and store them */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&tmplinks);
|
2021-09-30 15:44:08 +02:00
|
|
|
for (link = (bNodeLink *)ntree->links.first; link; link = linknext) {
|
2014-04-23 12:00:28 +02:00
|
|
|
linknext = link->next;
|
2019-04-22 13:31:31 +10:00
|
|
|
if (nodeLinkIsHidden(link)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
continue;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (link->fromsock == extsock) {
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeLink *tlink = MEM_cnew<bNodeLink>("temporary link");
|
2013-03-18 16:34:57 +00:00
|
|
|
*tlink = *link;
|
|
|
|
|
BLI_addtail(&tmplinks, tlink);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
nodeRemLink(ntree, link);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
/* find valid link to expose */
|
2021-09-30 15:44:08 +02:00
|
|
|
exposelink = nullptr;
|
|
|
|
|
for (link = (bNodeLink *)tmplinks.first; link; link = link->next) {
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX Multiple sockets can be connected to the extension socket at once,
|
|
|
|
|
* in that case the arbitrary first link determines name and type.
|
|
|
|
|
* This could be improved by choosing the "best" type among all links,
|
|
|
|
|
* whatever that means.
|
|
|
|
|
*/
|
2014-04-23 12:00:28 +02:00
|
|
|
if (link->tosock->type != SOCK_CUSTOM) {
|
|
|
|
|
exposelink = link;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
if (exposelink) {
|
|
|
|
|
bNodeSocket *gsock, *newsock;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->tonode, exposelink->tosock);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
node_group_input_update(ntree, node);
|
2013-03-18 16:34:57 +00:00
|
|
|
newsock = node_group_input_find_socket(node, gsock->identifier);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* redirect links from the extension socket */
|
2021-09-30 15:44:08 +02:00
|
|
|
for (link = (bNodeLink *)tmplinks.first; link; link = link->next) {
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeAddLink(ntree, node, newsock, link->tonode, link->tosock);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
BLI_freelistN(&tmplinks);
|
2019-04-20 20:25:22 +02:00
|
|
|
|
|
|
|
|
/* check inputs and outputs, and remove or insert them */
|
|
|
|
|
{
|
|
|
|
|
/* value_in_out inverted for interface nodes to get correct socket value_property */
|
2021-12-14 10:56:12 -06:00
|
|
|
group_verify_socket_list(*ntree, *node, ntree->inputs, node->outputs, SOCK_OUT);
|
2019-04-20 20:25:22 +02:00
|
|
|
|
|
|
|
|
/* add virtual extension socket */
|
|
|
|
|
nodeAddSocket(ntree, node, SOCK_OUT, "NodeSocketVirtual", "__extend__", "");
|
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void register_node_type_group_input(void)
|
|
|
|
|
{
|
|
|
|
|
/* used for all tree types, needs dynamic allocation */
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeType *ntype = MEM_cnew<bNodeType>("node type");
|
2020-02-28 13:28:16 +01:00
|
|
|
ntype->free_self = (void (*)(bNodeType *))MEM_freeN;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-05-29 15:38:51 +00:00
|
|
|
node_type_base(ntype, NODE_GROUP_INPUT, "Group Input", NODE_CLASS_INTERFACE, 0);
|
2013-06-01 12:45:42 +00:00
|
|
|
node_type_size(ntype, 140, 80, 400);
|
2013-03-18 16:34:57 +00:00
|
|
|
node_type_init(ntype, node_group_input_init);
|
2019-04-20 20:25:22 +02:00
|
|
|
node_type_update(ntype, node_group_input_update);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeRegisterType(ntype);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_group_output_init(bNodeTree *ntree, bNode *node)
|
|
|
|
|
{
|
2019-04-20 20:25:22 +02:00
|
|
|
node_group_output_update(ntree, node);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bNodeSocket *node_group_output_find_socket(bNode *node, const char *identifier)
|
|
|
|
|
{
|
|
|
|
|
bNodeSocket *sock;
|
2021-09-30 15:44:08 +02:00
|
|
|
for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) {
|
2019-04-22 13:31:31 +10:00
|
|
|
if (STREQ(sock->identifier, identifier)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
return sock;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
|
|
|
|
}
|
2021-09-30 15:44:08 +02:00
|
|
|
return nullptr;
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
void node_group_output_update(bNodeTree *ntree, bNode *node)
|
2013-03-18 16:34:57 +00:00
|
|
|
{
|
2021-09-30 15:44:08 +02:00
|
|
|
bNodeSocket *extsock = (bNodeSocket *)node->inputs.last;
|
2014-04-23 12:00:28 +02:00
|
|
|
bNodeLink *link, *linknext, *exposelink;
|
2013-03-18 16:34:57 +00:00
|
|
|
/* Adding a tree socket and verifying will remove the extension socket!
|
|
|
|
|
* This list caches the existing links to the extension socket
|
|
|
|
|
* so they can be recreated after verification.
|
|
|
|
|
*/
|
|
|
|
|
ListBase tmplinks;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* find links to the extension socket and store them */
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(&tmplinks);
|
2021-09-30 15:44:08 +02:00
|
|
|
for (link = (bNodeLink *)ntree->links.first; link; link = linknext) {
|
2014-04-23 12:00:28 +02:00
|
|
|
linknext = link->next;
|
2019-04-22 13:31:31 +10:00
|
|
|
if (nodeLinkIsHidden(link)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
continue;
|
2019-04-22 13:31:31 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (link->tosock == extsock) {
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeLink *tlink = MEM_cnew<bNodeLink>("temporary link");
|
2013-03-18 16:34:57 +00:00
|
|
|
*tlink = *link;
|
|
|
|
|
BLI_addtail(&tmplinks, tlink);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
nodeRemLink(ntree, link);
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
/* find valid link to expose */
|
2021-09-30 15:44:08 +02:00
|
|
|
exposelink = nullptr;
|
|
|
|
|
for (link = (bNodeLink *)tmplinks.first; link; link = link->next) {
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX Multiple sockets can be connected to the extension socket at once,
|
|
|
|
|
* in that case the arbitrary first link determines name and type.
|
|
|
|
|
* This could be improved by choosing the "best" type among all links,
|
|
|
|
|
* whatever that means.
|
|
|
|
|
*/
|
2014-04-23 12:00:28 +02:00
|
|
|
if (link->fromsock->type != SOCK_CUSTOM) {
|
|
|
|
|
exposelink = link;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
if (exposelink) {
|
|
|
|
|
bNodeSocket *gsock, *newsock;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX what if connecting virtual to virtual socket?? */
|
|
|
|
|
gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-20 20:25:22 +02:00
|
|
|
node_group_output_update(ntree, node);
|
2013-03-18 16:34:57 +00:00
|
|
|
newsock = node_group_output_find_socket(node, gsock->identifier);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
/* redirect links to the extension socket */
|
2021-09-30 15:44:08 +02:00
|
|
|
for (link = (bNodeLink *)tmplinks.first; link; link = link->next) {
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-23 12:00:28 +02:00
|
|
|
BLI_freelistN(&tmplinks);
|
2019-04-20 20:25:22 +02:00
|
|
|
|
|
|
|
|
/* check inputs and outputs, and remove or insert them */
|
|
|
|
|
{
|
|
|
|
|
/* value_in_out inverted for interface nodes to get correct socket value_property */
|
2021-12-14 10:56:12 -06:00
|
|
|
group_verify_socket_list(*ntree, *node, ntree->outputs, node->inputs, SOCK_IN);
|
2019-04-20 20:25:22 +02:00
|
|
|
|
|
|
|
|
/* add virtual extension socket */
|
|
|
|
|
nodeAddSocket(ntree, node, SOCK_IN, "NodeSocketVirtual", "__extend__", "");
|
|
|
|
|
}
|
2013-03-18 16:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void register_node_type_group_output(void)
|
|
|
|
|
{
|
|
|
|
|
/* used for all tree types, needs dynamic allocation */
|
2021-12-24 22:17:49 -05:00
|
|
|
bNodeType *ntype = MEM_cnew<bNodeType>("node type");
|
2020-02-28 13:28:16 +01:00
|
|
|
ntype->free_self = (void (*)(bNodeType *))MEM_freeN;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-05-29 15:38:51 +00:00
|
|
|
node_type_base(ntype, NODE_GROUP_OUTPUT, "Group Output", NODE_CLASS_INTERFACE, 0);
|
2013-06-01 12:45:42 +00:00
|
|
|
node_type_size(ntype, 140, 80, 400);
|
2013-03-18 16:34:57 +00:00
|
|
|
node_type_init(ntype, node_group_output_init);
|
2019-04-20 20:25:22 +02:00
|
|
|
node_type_update(ntype, node_group_output_update);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-11-25 15:01:25 +01:00
|
|
|
ntype->no_muting = true;
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
nodeRegisterType(ntype);
|
|
|
|
|
}
|
2020-11-06 16:14:43 +11:00
|
|
|
|
|
|
|
|
/** \} */
|