[Bf-blender-cvs] [9616b72] object_nodes: Fix node socket update callbacks exiting early because of missing output connection.

Lukas Tönne noreply at git.blender.org
Fri May 13 15:49:00 CEST 2016


Commit: 9616b72e57b54fd0ac05177754f4faac587fa352
Author: Lukas Tönne
Date:   Fri May 13 15:46:15 2016 +0200
Branches: object_nodes
https://developer.blender.org/rB9616b72e57b54fd0ac05177754f4faac587fa352

Fix node socket update callbacks exiting early because of missing output connection.

Outputs are currently identified in the nodes via the DO_OUTPUT flag. This is not
nicely accessible for pynodes and needs to be reimplemented in a proper way.
Until then this optimization for node recalculation should just be ignored for texnodes,
so nodes now have a callback for checking usage, and will always be considered used by default.

===================================================================

M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/editors/space_node/node_draw.c
M	source/blender/editors/space_node/node_edit.c
M	source/blender/editors/space_node/node_intern.h
M	source/blender/editors/space_node/node_relationships.c
M	source/blender/nodes/composite/node_composite_util.c
M	source/blender/nodes/intern/node_util.c
M	source/blender/nodes/intern/node_util.h
M	source/blender/nodes/shader/node_shader_util.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 794649a..e928ab0 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -185,6 +185,8 @@ typedef struct bNodeType {
 	/// Optional tweak area polling (for grabbing).
 	int (*tweak_area_func)(struct bNode *node, int x, int y);
 	
+	/// Return true when the node is used for final results (connected to output).
+	bool (*is_used)(struct bNodeTree *ntree, struct bNode *node);
 	/// Called when the node is updated in the editor.
 	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
 	/// Check and update if internal ID data has changed.
@@ -462,6 +464,7 @@ void            nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
 void            nodeRemSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
 bool            nodeLinkIsHidden(struct bNodeLink *link);
 void            nodeInternalRelink(struct bNodeTree *ntree, struct bNode *node);
+bool            nodeIsUsed(struct bNodeTree *ntree, struct bNode *node);
 
 void            nodeToView(struct bNode *node, float x, float y, float *rx, float *ry);
 void            nodeFromView(struct bNode *node, float x, float y, float *rx, float *ry);
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index d2bcbe9..27f8fb8 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1087,6 +1087,16 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node)
 	}
 }
 
+
+bool nodeIsUsed(bNodeTree *ntree, bNode *node)
+{
+	if (node->typeinfo->is_used)
+		return node->typeinfo->is_used(ntree, node);
+	else
+		return true;
+}
+
+
 void nodeToView(bNode *node, float x, float y, float *rx, float *ry)
 {
 	if (node->parent) {
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index 7222a6b..697a4c6 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -168,12 +168,7 @@ void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node)
 	if (!ntree)
 		return;
 
-	bool do_tag_update = true;
-	if (node != NULL) {
-		if (!node_connected_to_output(ntree, node)) {
-			do_tag_update = false;
-		}
-	}
+	bool do_tag_update = node == NULL || nodeIsUsed(ntree, node);
 
 	/* look through all datablocks, to support groups */
 	if (do_tag_update) {
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index b8722d9..1c20a88 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -1249,7 +1249,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
 			node->flag &= ~NODE_ACTIVE;
 			nodeSetSelected(newnode, true);
 
-			do_tag_update |= (do_tag_update || node_connected_to_output(ntree, newnode));
+			do_tag_update |= (do_tag_update || nodeIsUsed(ntree, newnode));
 		}
 		
 		/* make sure we don't copy new nodes again! */
@@ -1630,7 +1630,7 @@ static int node_mute_exec(bContext *C, wmOperator *UNUSED(op))
 		if ((node->flag & SELECT) && node->typeinfo->update_internal_links) {
 			node->flag ^= NODE_MUTED;
 			snode_update(snode, node);
-			do_tag_update |= (do_tag_update || node_connected_to_output(snode->edittree, node));
+			do_tag_update |= (do_tag_update || nodeIsUsed(snode->edittree, node));
 		}
 	}
 	
@@ -1671,7 +1671,7 @@ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
 		next = node->next;
 		if (node->flag & SELECT) {
 			/* check id user here, nodeFreeNode is called for free dbase too */
-			do_tag_update |= (do_tag_update || node_connected_to_output(snode->edittree, node));
+			do_tag_update |= (do_tag_update || nodeIsUsed(snode->edittree, node));
 			if (node->id)
 				id_us_min(node->id);
 			nodeFreeNode(snode->edittree, node);
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 6b8fa0b..444e811 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -155,8 +155,6 @@ void NODE_OT_group_edit(struct wmOperatorType *ot);
 
 
 /* node_relationships.c */
-bool node_connected_to_output(struct bNodeTree *ntree, struct bNode *node);
-
 void NODE_OT_link(struct wmOperatorType *ot);
 void NODE_OT_link_make(struct wmOperatorType *ot);
 void NODE_OT_links_cut(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_node/node_relationships.c b/source/blender/editors/space_node/node_relationships.c
index 71953f4..8cf0043 100644
--- a/source/blender/editors/space_node/node_relationships.c
+++ b/source/blender/editors/space_node/node_relationships.c
@@ -61,104 +61,6 @@
 
 #include "node_intern.h"  /* own include */
 
-/* ****************** Relations helpers *********************** */
-
-static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree,
-                                            bNode *from,
-                                            bNode *to)
-{
-	if (from->flag & NODE_TEST) {
-		return false;
-	}
-	from->flag |= NODE_TEST;
-	for (bNodeLink *link = ntree->links.first; link != NULL; link = link->next) {
-		if (link->fromnode == from) {
-			if (link->tonode == to) {
-				return true;
-			}
-			else {
-				if (ntree_check_nodes_connected_dfs(ntree, link->tonode, to)) {
-					return true;
-				}
-			}
-		}
-	}
-	return false;
-}
-
-static bool ntree_check_nodes_connected(bNodeTree *ntree, bNode *from, bNode *to)
-{
-	if (from == to) {
-		return true;
-	}
-	ntreeNodeFlagSet(ntree, NODE_TEST, false);
-	return ntree_check_nodes_connected_dfs(ntree, from, to);
-}
-
-static bool node_group_has_output_dfs(bNode *node)
-{
-	bNodeTree *ntree = (bNodeTree *)node->id;
-	if (ntree->id.tag & LIB_TAG_DOIT) {
-		return false;
-	}
-	ntree->id.tag |= LIB_TAG_DOIT;
-	for (bNode *current_node = ntree->nodes.first;
-	     current_node != NULL;
-	     current_node = current_node->next)
-	{
-		if (current_node->type == NODE_GROUP) {
-			if (current_node->id && node_group_has_output_dfs(current_node)) {
-				return true;
-			}
-		}
-		if (current_node->flag & NODE_DO_OUTPUT &&
-		    current_node->type != NODE_GROUP_OUTPUT)
-		{
-			return true;
-		}
-	}
-	return false;
-}
-
-static bool node_group_has_output(bNode *node)
-{
-	Main *bmain = G.main;
-	BLI_assert(node->type == NODE_GROUP);
-	bNodeTree *ntree = (bNodeTree *)node->id;
-	if (ntree == NULL) {
-		return false;
-	}
-	BKE_main_id_tag_listbase(&bmain->nodetree, LIB_TAG_DOIT, false);
-	return node_group_has_output_dfs(node);
-}
-
-bool node_connected_to_output(bNodeTree *ntree, bNode *node)
-{
-	for (bNode *current_node = ntree->nodes.first;
-	     current_node != NULL;
-	     current_node = current_node->next)
-	{
-		/* Special case for group nodes -- if modified node connected to a group
-		 * with active output inside we consider refresh is needed.
-		 *
-		 * We could make check more grained here by taking which socket the node
-		 * is connected to and so eventually.
-		 */
-		if (current_node->type == NODE_GROUP &&
-		    ntree_check_nodes_connected(ntree, node, current_node) &&
-		    node_group_has_output(current_node))
-		{
-			return true;
-		}
-		if (current_node->flag & NODE_DO_OUTPUT) {
-			if (ntree_check_nodes_connected(ntree, node, current_node)) {
-				return true;
-			}
-		}
-	}
-	return false;
-}
-
 /* ****************** Add *********************** */
 
 
@@ -600,7 +502,7 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links)
 			node_remove_extra_links(snode, link);
 
 			if (link->tonode) {
-				do_tag_update |= (do_tag_update || node_connected_to_output(ntree, link->tonode));
+				do_tag_update |= (do_tag_update || nodeIsUsed(ntree, link->tonode));
 			}
 		}
 		else {
@@ -757,7 +659,7 @@ static bNodeLinkDrag *node_link_init(SpaceNode *snode, float cursor[2], bool det
 					 * using TEST flag.
 					 */
 					oplink->flag &= ~NODE_LINK_TEST;
-					if (node_connected_to_output(snode->edittree, link->tonode)) {
+					if (nodeIsUsed(snode->edittree, link->tonode)) {
 						oplink->flag |= NODE_LINK_TEST;
 					}
 
@@ -776,7 +678,7 @@ static bNodeLinkDrag *node_link_init(SpaceNode *snode, float cursor[2], bool det
 			oplink->fromsock = sock;
 			oplink->flag |= NODE_LINK_VALID;
 			oplink->flag &= ~NODE_LINK_TEST;
-			if (node_connected_to_output(snode->edittree, node)) {
+			if (nodeIsUsed(snode->edittree, node)) {
 				oplink->flag |= NODE_LINK_TEST;
 			}
 
@@ -801,7 +703,7 @@ static bNodeLinkDrag *node_link_init(SpaceNode *snode, float cursor[2], bool det
 					oplink->next = oplink->prev = NULL;
 					oplink->flag |= NODE_LINK_VALID;
 					oplink->flag &= ~NODE_LINK_TEST;
-					if (node_connected_to_output(snode->edittree, link->tonode)) {
+					if (nodeIsUsed(snode->edittree, link->tonode)) {
 						oplink->flag |= NODE_LINK_TEST;
 					}
 
@@ -820,7 +722,7 @@ static bNodeLinkDrag *node_link_init(SpaceNode *snode, float cursor[2], bool det
 			oplink->tosock = sock;
 			oplink->flag |= NODE_LINK_VALID;
 			oplink->flag &= ~NODE_LINK_TEST;
-			if (node_connected_to_output(snode->edittree, node)) {
+			if (nodeIsUsed(snode->edittree, node)) {
 				oplink->flag |= NODE_LINK_TEST;
 			}
 
@@ -986,7 +888,7 @@ static int cut_links_exec(bContext *C, wmOperator *op)
 					found = true;
 				}
 
-				do_tag_update |= (do_tag_update || node_connected_to_output(snode->edittree, link->tonode));
+				do_tag_update |= (do_tag_update || nodeIsUsed(snode->edittree, link->tonode));
 
 				snode_update(snode, link->tonode);
 				nodeRemLink(snode->edittree, link);
diff --git a/source/blender/nodes/composite/node_composite_util.c b/source/blender/nodes/composite/node_composite_util.c
index c6b1d37..96b7c6b 100644
--- a/source/blender/nodes/composite/node_composite_util.c
+++ b/source/blender/nodes/composite/node_composite_util.c
@@ -57,4 +57,5 @@ void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short ncla
 	ntype->updatefunc = cmp_node_update_default;
 	ntype->insert_link = node_insert_link_default;
 	ntype->update_internal_links = node_update_internal_links_default;
+	ntype->is_used = node_conn

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list