[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30689] branches/particles-2010/source/ blender: Group nodes work with operator sockets.
Lukas Toenne
lukas.toenne at googlemail.com
Sat Jul 24 12:07:22 CEST 2010
Revision: 30689
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30689
Author: lukastoenne
Date: 2010-07-24 12:07:22 +0200 (Sat, 24 Jul 2010)
Log Message:
-----------
Group nodes work with operator sockets. Very basic implementation still, that does not work well with multiple operator sockets in a group and especially socket lists on the input side.
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/makesdna/DNA_node_types.h
branches/particles-2010/source/blender/nodes/intern/node_tree_simulation.c
Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-07-24 09:26:05 UTC (rev 30688)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-07-24 10:07:22 UTC (rev 30689)
@@ -73,9 +73,11 @@
/* after this line is used internal only */
struct ListBase verified; /* used during verify_types */
- struct bNodeSocket *internsock; /* group nodes, the internal socket counterpart */
+
+ /* group nodes, the internal socket counterpart */
+ struct bNode *internnode;
+ struct bNodeSocket *internsock;
int own_index; /* verify group nodes */
-
} bNodeSocketType;
typedef struct bNodeType {
@@ -168,10 +170,11 @@
void ntreeSocketUseFlags(struct bNodeTree *ntree);
-void ntreeSolveOrder(struct bNodeTree *ntree);
-void ntreeUpdateListSockets(struct bNodeTree *ntree);
-void ntreeUpdateSocketTypes(struct bNodeTree *ntree);
-void ntreeUpdateLinks(struct bNodeTree *ntree);
+void ntreeUpdate(struct bNodeTree *ntree);
+//void ntreeSolveOrder(struct bNodeTree *ntree);
+//void ntreeUpdateListSockets(struct bNodeTree *ntree);
+//void ntreeUpdateSocketTypes(struct bNodeTree *ntree);
+//void ntreeUpdateLinks(struct bNodeTree *ntree);
void ntreeBeginExecTree(struct bNodeTree *ntree);
void ntreeExecTree(struct bNodeTree *ntree, void *callerdata, int thread);
Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-07-24 09:26:05 UTC (rev 30688)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c 2010-07-24 10:07:22 UTC (rev 30689)
@@ -159,6 +159,7 @@
sock->type= stype->type;
sock->to_index= stype->own_index;
+ sock->tonode= stype->internnode;
sock->tosock= stype->internsock;
sock->ns.vec[0]= stype->val1;
@@ -187,6 +188,7 @@
sock->type= stype->type;
sock->to_index= stype->own_index;
+ sock->tonode= stype->internnode;
sock->tosock= stype->internsock;
sock->ns.vec[0]= stype->val1;
@@ -238,6 +240,7 @@
else sock->limit= stype->limit;
sock->ns.min= stype->min;
sock->ns.max= stype->max;
+ sock->tonode= stype->internnode;
sock->tosock= stype->internsock;
sock->stype = stype;
@@ -452,7 +455,8 @@
inputs[a]= *stype;
inputs[a].own_index= sock->own_index;
- inputs[a].internsock= sock;
+ inputs[a].internnode= node;
+ inputs[a].internsock= sock;
a++;
}
if (!sock->next || sock->next->stype != sock->stype)
@@ -479,6 +483,7 @@
outputs[a]= *stype;
outputs[a].own_index= sock->own_index;
+ outputs[a].internnode= node;
outputs[a].internsock= sock;
a++;
}
@@ -631,8 +636,7 @@
}
}
- /* update node levels */
- ntreeSolveOrder(ntree);
+ ntreeUpdate(ntree);
return gnode;
}
@@ -814,9 +818,9 @@
nodeFreeNode(ntree, gnode);
/* solve order goes fine, but the level tags not... doing it twice works for now. solve this once */
- ntreeSolveOrder(ntree);
- ntreeSolveOrder(ntree);
-
+ ntreeUpdate(ntree);
+ ntreeUpdate(ntree);
+
return 1;
}
@@ -838,82 +842,6 @@
}
/* ************** Add stuff ********** */
-void ntreeUpdateListSockets(bNodeTree *ntree)
-{
- bNode *node;
- bNodeSocketType *stype;
- bNodeSocket *sock, *next_sock;
-
- /* nodes are presumed fully verified, stype and socket list are in sync */
- for (node=ntree->nodes.first; node; node = node->next) {
- stype= node->typeinfo->inputs;
- sock= node->inputs.first;
- while (sock) {
- if (stype->flag & SOCK_LIST) {
- /* step through all sockets of this type (i.e. the list) */
- while (sock && sock->stype == stype) {
- if (!sock->link) {
- next_sock = sock->next;
- node_rem_socket(ntree, &node->inputs, sock);
- sock = next_sock;
- }
- else {
- sock = sock->next;
- }
- }
- /* add an unlinked last socket, so the list can be extended */
- node_insert_before_socket_type(&node->inputs, sock, stype);
- } else {
- while (sock && sock->stype == stype) {
- sock = sock->next;
- }
- }
-
- ++stype;
- }
- }
-}
-
-#if 0 /* XXX more atomic way of updating list sockets only for the indicated socket when it changed (not working yet) - phonybone */
-void nodeUpdateListSocket(bNodeTree *ntree, bNode *tonode, bNodeSocket *tosock)
-{
- int list_socket= 0;
- bNodeSocketType *stype;
- bNodeSocket *sock, *last_found= NULL;
-
- if (!tonode || !tosock)
- return;
-
- /* XXX should be easier to determine socket type - can own_index be used for this? */
- stype= tonode->typeinfo->inputs;
- while (stype->type != -1 && (tosock->to_index != stype->own_index || strncmp(tosock->name, stype->name, NODE_MAXSTR)!=0)) ++stype;
- if (stype->type == -1)
- return;
-
- /* XXX needs a more generic way of allowing list sockets - phonybone */
- /* XXX should only be allowed for inputs */
- list_socket= nodeIsListSocket(stype);
- if (!list_socket)
- return;
-
- sock= tonode->inputs.first;
- while (sock) {
- if (sock->type == tosock->type) {
- /* remove unlinked sockets */
- if (last_found && !last_found->link)
- node_rem_socket(ntree, &tonode->inputs, last_found);
- last_found = sock;
- }
- sock = sock->next;
- }
- /* make sure the last socket is unlinked, so the list can be extended */
- if (last_found && last_found->link) {
- printf("extending socket list\n");
- node_add_socket_type(&tonode->inputs, stype);
- }
-}
-#endif
-
void nodeAddSockets(bNode *node, bNodeType *ntype)
{
bNodeSocketType *stype;
@@ -1093,44 +1021,6 @@
}
}
-void ntreeUpdateLinks(bNodeTree *ntree)
-{
- bNodeLink *link;
-
- for (link = ntree->links.first; link; link = link->next) {
- int valid = 1;
- if (link->fromsock == NULL || link->tosock == NULL) {
- /* don't assume bad links when they're incomplete (e.g. in modal operator) */
- valid = 1;
- }
- else {
- int fromtype = link->fromsock->type;
- int totype = link->tosock->type;
- /* non-simulation sockets can convert anything */
- if (ELEM3(fromtype, SOCK_VALUE, SOCK_RGBA, SOCK_VECTOR) && ELEM3(totype, SOCK_VALUE, SOCK_RGBA, SOCK_VECTOR)) {
- valid = 1;
- }
- /* SOCK_ANY sockets adapt to the other side */
- else if (fromtype == SOCK_ANY || totype == SOCK_ANY) {
- valid = 1;
- /* int and float implicitely convertible */
- }
- else if (ELEM3(fromtype, SOCK_INT, SOCK_FLOAT, SOCK_BOOL) && ELEM3(totype, SOCK_INT, SOCK_FLOAT, SOCK_BOOL)) {
- valid = 1;
- }
- /* by default only allow perfect type matches */
- else {
- valid = (fromtype == totype);
- }
- }
-
- if (valid)
- link->flag |= NLINK_VALID;
- else
- link->flag &= ~NLINK_VALID;
- }
-}
-
bNodeTree *ntreeAddTree(int type)
{
bNodeTreeTypeInfo *treetype= ntreeGetTypeInfo(type);
@@ -1221,7 +1111,7 @@
}
/* weird this is required... there seem to be link pointers wrong still? */
/* anyhoo, doing this solves crashes on copying entire tree (copy scene) and delete nodes */
- ntreeSolveOrder(newtree);
+ ntreeUpdate(ntree);
return newtree;
}
@@ -1684,7 +1574,7 @@
if(sock->link) {
has_inputlinks= 1;
fromnode= sock->link->fromnode;
- if(fromnode->done==0) {
+ if(fromnode && fromnode->done==0) {
fromnode->level= node_recurs_check(fromnode, nsort, level);
}
}
@@ -1699,7 +1589,7 @@
return 0xFFF;
}
-void ntreeSolveOrder(bNodeTree *ntree)
+static void ntreeSolveOrder(bNodeTree *ntree)
{
bNode *node, **nodesort, **nsort;
bNodeSocket *sock;
@@ -1721,7 +1611,8 @@
return;
for(link= ntree->links.first; link; link= link->next) {
- link->tosock->link= link;
+ if (link->tosock)
+ link->tosock->link= link;
}
nsort= nodesort= MEM_callocN(totnode*sizeof(void *), "sorted node array");
@@ -1779,13 +1670,49 @@
might be different for editor or for "real" use... */
}
+static void ntreeUpdateListSockets(bNodeTree *ntree)
+{
+ bNode *node;
+ bNodeSocketType *stype;
+ bNodeSocket *sock, *next_sock;
+
+ /* nodes are presumed fully verified, stype and socket list are in sync */
+ for (node=ntree->nodes.first; node; node = node->next) {
+ stype= node->typeinfo->inputs;
+ sock= node->inputs.first;
+ while (sock) {
+ if (stype->flag & SOCK_LIST) {
+ /* step through all sockets of this type (i.e. the list) */
+ while (sock && sock->stype == stype) {
+ if (!sock->link) {
+ next_sock = sock->next;
+ node_rem_socket(ntree, &node->inputs, sock);
+ sock = next_sock;
+ }
+ else {
+ sock = sock->next;
+ }
+ }
+ /* add an unlinked last socket, so the list can be extended */
+ node_insert_before_socket_type(&node->inputs, sock, stype);
+ } else {
+ while (sock && sock->stype == stype) {
+ sock = sock->next;
+ }
+ }
+
+ ++stype;
+ }
+ }
+}
+
static int socktype_greater_than(int a, int b)
{
static int prefmap[] = { 0, 6, 5, 0, 1, 2, 3, 4 };
return prefmap[a] > prefmap[b];
}
-void ntreeUpdateSocketTypes(bNodeTree *ntree)
+static void ntreeUpdateSocketTypes(bNodeTree *ntree)
{
bNode *node;
bNodeSocket *sock, *fromsock;
@@ -1877,6 +1804,52 @@
} while (resolved > 0);
}
+static void ntreeUpdateLinks(bNodeTree *ntree)
+{
+ bNodeLink *link;
+
+ for (link = ntree->links.first; link; link = link->next) {
+ int valid = 1;
+ if (link->fromsock == NULL || link->tosock == NULL) {
+ /* don't assume bad links when they're incomplete (e.g. in modal operator) */
+ valid = 1;
+ }
+ else {
+ int fromtype = link->fromsock->type;
+ int totype = link->tosock->type;
+ /* non-simulation sockets can convert anything */
+ if (ELEM3(fromtype, SOCK_VALUE, SOCK_RGBA, SOCK_VECTOR) && ELEM3(totype, SOCK_VALUE, SOCK_RGBA, SOCK_VECTOR)) {
+ valid = 1;
+ }
+ /* SOCK_ANY sockets adapt to the other side */
+ else if (fromtype == SOCK_ANY || totype == SOCK_ANY) {
+ valid = 1;
+ /* int and float implicitely convertible */
+ }
+ else if (ELEM3(fromtype, SOCK_INT, SOCK_FLOAT, SOCK_BOOL) && ELEM3(totype, SOCK_INT, SOCK_FLOAT, SOCK_BOOL)) {
+ valid = 1;
+ }
+ /* by default only allow perfect type matches */
+ else {
+ valid = (fromtype == totype);
+ }
+ }
+
+ if (valid)
+ link->flag |= NLINK_VALID;
+ else
+ link->flag &= ~NLINK_VALID;
+ }
+}
+
+void ntreeUpdate(bNodeTree *ntree)
+{
+ ntreeSolveOrder(ntree);
+ ntreeUpdateListSockets(ntree);
+ ntreeUpdateSocketTypes(ntree);
+ ntreeUpdateLinks(ntree);
+}
+
/* Should be callback! */
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list