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:
authorDalai Felinto <dfelinto@gmail.com>2014-07-23 18:33:29 +0400
committerDalai Felinto <dfelinto@gmail.com>2014-07-23 18:46:13 +0400
commite0d40471364aafca967b6ebd5266ae7d7f78dee4 (patch)
tree6757212b24ccc5f827ebb9a8aefe3017ec4f5a9a /source/blender/nodes
parent8d3bfef538c6393048373c3642a7f626193271dc (diff)
Bake-API: Test for cyclic node connection
If the active image node contributes to the final material shader (meaning it's either directly or indirectly connected to an Output Node) the user will receive an alert about circular dependency. Similar to what we do for Blender internal the baking will still happen, but the user will receive the alert which should prevent the image saving to happen if the result was not intentional. Core function to check for node output written by Lukas Toenne. Reviewers: lukastoenne, campbellbarton Differential Revision: https://developer.blender.org/D673
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/intern/node_common.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/nodes/intern/node_common.c b/source/blender/nodes/intern/node_common.c
index ae834f9e7cc..c58c9c902ec 100644
--- a/source/blender/nodes/intern/node_common.c
+++ b/source/blender/nodes/intern/node_common.c
@@ -336,6 +336,40 @@ void ntree_update_reroute_nodes(bNodeTree *ntree)
node_reroute_inherit_type_recursive(ntree, node);
}
+static bool node_is_connected_to_output_recursive(bNodeTree *ntree, bNode *node)
+{
+ bNodeLink *link;
+
+ /* avoid redundant checks, and infinite loops in case of cyclic node links */
+ if (node->done)
+ return false;
+ node->done = 1;
+
+ /* main test, done before child loop so it catches output nodes themselves as well */
+ if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->flag & NODE_DO_OUTPUT)
+ return true;
+
+ /* test all connected nodes, first positive find is sufficient to return true */
+ for (link = ntree->links.first; link; link = link->next) {
+ if (link->fromnode == node) {
+ if (node_is_connected_to_output_recursive(ntree, link->tonode))
+ return true;
+ }
+ }
+ return false;
+}
+
+bool BKE_node_is_connected_to_output(bNodeTree *ntree, bNode *node)
+{
+ bNode *tnode;
+
+ /* clear flags */
+ for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
+ tnode->done = 0;
+
+ return node_is_connected_to_output_recursive(ntree, node);
+}
+
void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree)
{
bNode *node;