[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34845] branches/particles-2010/source/ blender: Added basic groups-inside-groups feature.

Lukas Toenne lukas.toenne at googlemail.com
Mon Feb 14 15:32:49 CET 2011


Revision: 34845
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34845
Author:   lukastoenne
Date:     2011-02-14 14:32:49 +0000 (Mon, 14 Feb 2011)
Log Message:
-----------
Added basic groups-inside-groups feature. This makes it possible to add groups inside other groups, but only if the group tree does not contain itself on any level to avoid infinite recursion. Limited recursion can be implemented by specialized group nodes later that don't have this restriction.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/editors/space_node/node_edit.c
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/node_exec.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2011-02-14 12:43:28 UTC (rev 34844)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2011-02-14 14:32:49 UTC (rev 34845)
@@ -106,19 +106,14 @@
 	/* detail buttons on panel */
 	void (*buttonfunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
 	const char *(*labelfunc)(struct bNode *);
-
+	
 	/* called when the node is updated (e.g. linked) in the editor. */
 	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
-
+	
 	void (*initfunc)(struct bNode *);
 	void (*freestoragefunc)(struct bNode *);
 	void (*copystoragefunc)(struct bNode *, struct bNode *);
 	
-	/* for use with dynamic typedefs */
-	struct ID *id;
-	void *pynode; /* holds pointer to python script */
-	void *pydict; /* holds pointer to python script dictionary (scope)*/
-
 	/* gpu */
 	int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
 } bNodeType;
@@ -232,6 +227,9 @@
 
 void			nodeAddToPreview(struct bNode *, float *, int, int);
 
+struct bNode	*nodeAddNode(struct bNodeTree *ntree, int type);
+struct bNode	*nodeAddGroupNode(struct bNodeTree *ntree, struct bNodeTree *ngroup);
+struct bNode	*nodeAddDynamicNode(struct bNodeTree *ntree, int type);
 void			nodeUnlinkNode(struct bNodeTree *ntree, struct bNode *node);
 void			nodeUniqueName(struct bNodeTree *ntree, struct bNode *node);
 struct bNodeSocket *nodeAddInputSocket(struct bNodeTree *ntree, struct bNode *node, const char *name, int type);
@@ -251,10 +249,7 @@
 void			nodeAssignInputPanel(struct bNode *node, struct bNodeSocket *socket, struct bNodeSocketPanel *panel);
 void			nodeAssignOutputPanel(struct bNode *node, struct bNodeSocket *socket, struct bNodeSocketPanel *panel);
 
-void			nodeAddSocketsFromType(struct bNodeTree *ntree, struct bNode *node, struct bNodeType *ntype);
-struct bNode	*nodeAddNodeType(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup, struct ID *id);
 void			nodeRegisterType(struct ListBase *typelist, const struct bNodeType *ntype) ;
-void			nodeUpdateType(struct bNodeTree *ntree, struct bNode* node, struct bNodeType *ntype);
 void			nodeMakeDynamicType(struct bNode *node);
 int				nodeDynamicUnlinkText(struct ID *txtid);
 
@@ -287,6 +282,8 @@
 
 /* ************** Groups ****************** */
 
+int				ntreeGroupAllowed(struct bNodeTree *ntree, int type, struct bNodeTree *ngroup);
+
 struct bNode	*nodeMakeGroupFromSelected(struct bNodeTree *ntree);
 int				nodeGroupUnGroup(struct bNodeTree *ntree, struct bNode *gnode);
 

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c	2011-02-14 12:43:28 UTC (rev 34844)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c	2011-02-14 14:32:49 UTC (rev 34845)
@@ -98,11 +98,11 @@
 	}
 }
 
-static bNodeType *node_get_type(bNodeTree *ntree, int type, ID *id)
- {
+static bNodeType *node_get_type(bNodeTree *ntree, int type)
+{
 	bNodeType *ntype = ntreeGetType(ntree->type)->node_types.first;
 	for(; ntype; ntype= ntype->next)
-		if(ntype->type==type && id==ntype->id )
+		if(ntype->type==type)
 			return ntype;
 	
 	return NULL;
@@ -114,26 +114,18 @@
 	
 	for(node= ntree->nodes.first; node; node= next) {
 		next= node->next;
+		
+		node->typeinfo= node_get_type(ntree, node->type);
+		
 		if(node->type==NODE_DYNAMIC) {
-			bNodeType *stype= NULL;
-			if(node->id==NULL) { /* empty script node */
-				stype= node_get_type(ntree, node->type, NULL);
-			} else { /* not an empty script node */
-				stype= node_get_type(ntree, node->type, node->id);
-				if(!stype) {
-					stype= node_get_type(ntree, node->type, NULL);
-					/* needed info if the pynode script fails now: */
-					if (node->id) node->storage= ntree;
-				} else {
-					node->custom1= 0;
-					node->custom1= BSET(node->custom1,NODE_DYNAMIC_ADDEXIST);
-				}
+			/* needed info if the pynode script fails now: */
+			node->storage= ntree;
+			if(node->id!=NULL) { /* not an empty script node */
+				node->custom1= 0;
+				node->custom1= BSET(node->custom1,NODE_DYNAMIC_ADDEXIST);
 			}
-			node->typeinfo= stype;
 			if(node->typeinfo)
 				node->typeinfo->initfunc(node);
-		} else {
-			node->typeinfo= node_get_type(ntree, node->type, NULL);
 		}
 
 		if(node->typeinfo==NULL) {
@@ -478,6 +470,22 @@
 	nodeRegisterType(lb, &ntype);
 }
 
+int ntreeGroupAllowed(bNodeTree *ntree, int UNUSED(type), bNodeTree *ngroup)
+{
+	bNode *node;
+	
+	/* XXX make a node type callback for this! */
+	if (ntree == ngroup)
+		return 0;
+	
+	for (node=ngroup->nodes.first; node; node=node->next) {
+		if (node->type==NODE_GROUP && node->id) {
+			return ntreeGroupAllowed(ntree, node->type, (bNodeTree*)node->id);
+		}
+	}
+	return 1;
+}
+
 bNodeSocket *nodeFindGroupNodeInput(bNode *gnode, bNodeSocket *gsock)
 {
 	bNodeSocket *sock;
@@ -584,7 +592,7 @@
 	}
 	
 	/* make group node */
-	gnode= nodeAddNodeType(ntree, NODE_GROUP, ngroup, NULL);
+	gnode= nodeAddGroupNode(ntree, ngroup);
 	gnode->locx= 0.5f*(min[0]+max[0]);
 	gnode->locy= 0.5f*(min[1]+max[1]);
 	
@@ -994,7 +1002,7 @@
 }
 
 /* ************** Add stuff ********** */
-void nodeAddSocketsFromType(bNodeTree *ntree, bNode *node, bNodeType *ntype)
+static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType *ntype)
 {
 	bNodeSocketTemplate *sockdef;
 	bNodeSocket *sock;
@@ -1057,70 +1065,103 @@
 	BLI_uniquename(&ntree->nodes, node, "Node", '.', offsetof(bNode, name), sizeof(node->name));
 }
 
-bNode *nodeAddNodeType(bNodeTree *ntree, int type, bNodeTree *ngroup, ID *id)
+static bNode *make_node(bNodeTree *ntree, bNodeType *ntype, const char *name)
 {
 	bNode *node= NULL;
-	bNodeType *ntype= NULL;
 
-	if (ngroup && BLI_findindex(&G.main->nodetree, ngroup)==-1) {
-		printf("nodeAddNodeType() error: '%s' not in main->nodetree\n", ngroup->id.name);
-		return NULL;
-	}
-
-	if(type>=NODE_DYNAMIC_MENU) {
-		int a=0, idx= type-NODE_DYNAMIC_MENU;
-		ntype= ntreeGetType(ntree->type)->node_types.first;
-		while(ntype) {
-			if(ntype->type==NODE_DYNAMIC) {
-				if(a==idx)
-					break;
-				a++;
-			}
-			ntype= ntype->next;
-		}
-	} else
-		ntype= node_get_type(ntree, type, id);
-
 	node= MEM_callocN(sizeof(bNode), "new node");
-	BLI_addtail(&ntree->nodes, node);
-	node->typeinfo= ntype;
-	if(type>=NODE_DYNAMIC_MENU)
-		node->custom2= type; /* for node_dynamic_init */
-
-	if(ngroup)
-		BLI_strncpy(node->name, ngroup->id.name+2, NODE_MAXSTR);
-	else if(type>NODE_DYNAMIC_MENU) {
-		BLI_strncpy(node->name, ntype->id->name+2, NODE_MAXSTR);
-	}
-	else
-		BLI_strncpy(node->name, ntype->name, NODE_MAXSTR);
-
+	
+	BLI_strncpy(node->name, name, NODE_MAXSTR);
 	nodeUniqueName(ntree, node);
-	
 	node->type= ntype->type;
+	node->typeinfo= ntype;
 	node->flag= NODE_SELECT|ntype->flag;
 	node->width= ntype->width;
 	node->miniwidth= 42.0f;		/* small value only, allows print of first chars */
+	
+	return node;
+}
 
-	if(type==NODE_GROUP)
-		node->id= (ID *)ngroup;
+bNode *nodeAddNode(bNodeTree *ntree, int type)
+{
+	bNode *node;
+	bNodeType *ntype;
+	
+	ntype= node_get_type(ntree, type);
+	node= make_node(ntree, ntype, ntype->name);
+	BLI_addtail(&ntree->nodes, node);
+	
+	/* XXX need init handler later? */
+	if(ntype->initfunc!=NULL)
+		ntype->initfunc(node);
+	
+	node_add_sockets_from_type(ntree, node, ntype);
+	
+	return node;
+}
 
-	nodeAddSocketsFromType(ntree, node, ntype);
+bNode *nodeAddGroupNode(bNodeTree *ntree, bNodeTree *ngroup)
+{
+	bNode *node;
+	bNodeType *ntype;
 	
-	/* need init handler later? */
-	/* got it-bob*/
+	if (BLI_findindex(&G.main->nodetree, ngroup)==-1) {
+//		printf("nodeAddNode() error: '%s' not in main->nodetree\n", ngroup->id.name);
+		return NULL;
+	}
+	
+	ntype= node_get_type(ntree, NODE_GROUP);
+	node= make_node(ntree, ntype, ngroup->id.name+2);
+	node->id= &ngroup->id;
+	BLI_addtail(&ntree->nodes, node);
+
+	/* XXX need init handler later? */
 	if(ntype->initfunc!=NULL)
 		ntype->initfunc(node);
 	
+	node_add_sockets_from_type(ntree, node, ntype);
+	
 	return node;
 }
 
+bNode *nodeAddDynamicNode(bNodeTree *ntree, int type)
+{
+	bNode *node;
+	bNodeType *ntype;
+	
+	int a=0, idx= type-NODE_DYNAMIC_MENU;
+	ntype= ntreeGetType(ntree->type)->node_types.first;
+	while(ntype) {
+		if(ntype->type==NODE_DYNAMIC) {
+			if(a==idx)
+				break;
+			a++;
+		}
+		ntype= ntype->next;
+	}
+	
+	ntype= node_get_type(ntree, type);
+	/* XXX todo */
+	node= make_node(ntree, ntype, ntype->name);
+//	node= make_node(ntree, ntype, ntype->id->name+2);
+	node->custom2= type; /* for node_dynamic_init */
+	BLI_addtail(&ntree->nodes, node);
+	
+	/* XXX need init handler later? */
+	if(ntype->initfunc!=NULL)
+		ntype->initfunc(node);
+	
+	node_add_sockets_from_type(ntree, node, ntype);
+	
+	return node;
+}
+
 void nodeMakeDynamicType(bNode *node)
 {
 	/* find SH_DYNAMIC_NODE ntype */
 	bNodeType *ntype= ntreeGetType(NTREE_SHADER)->node_types.first;
 	while(ntype) {
-		if(ntype->type==NODE_DYNAMIC && ntype->id==NULL)
+		if(ntype->type==NODE_DYNAMIC)
 			break;
 		ntype= ntype->next;
 	}
@@ -1784,6 +1825,8 @@
 {
 	bNode *node;
 	
+	printf("============================================================\n");
+	
 	if(ntree==NULL) return;
 	
 	for(node= ntree->nodes.first; node; node= node->next)
@@ -2208,12 +2251,12 @@
 	ntype->labelfunc = labelfunc;
 }
 
-static bNodeType *is_nodetype_registered(ListBase *typelist, int type, ID *id) 
+static bNodeType *is_nodetype_registered(ListBase *typelist, int type) 
 {
 	bNodeType *ntype= typelist->first;
 	
 	for(;ntype; ntype= ntype->next )
-		if(ntype->type==type && ntype->id==id)
+		if(ntype->type==type)
 			return ntype;
 	
 	return NULL;
@@ -2222,7 +2265,7 @@
 /* type can be from a static array, we make copy for duplicate types (like group) */
 void nodeRegisterType(ListBase *typelist, const bNodeType *ntype) 
 {
-	bNodeType *found= is_nodetype_registered(typelist, ntype->type, ntype->id);
+	bNodeType *found= is_nodetype_registered(typelist, ntype->type);
 	
 	if(found==NULL) {
 		bNodeType *ntypen= MEM_callocN(sizeof(bNodeType), "node type");
@@ -2402,7 +2445,7 @@
 	bNodeType *next= NULL;
 	while(ntype) {
 		next= ntype->next;
-		if(ntype->type==NODE_DYNAMIC && ntype->id!=NULL) {
+		if(ntype->type==NODE_DYNAMIC) {
 			BLI_remlink(list, ntype);
 			if(ntype->inputs) {
 				MEM_freeN(ntype->inputs);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list