2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2007 Blender Foundation.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): Lukas Toenne.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/nodes/intern/node_common.c
35 #include "DNA_action_types.h"
36 #include "DNA_anim_types.h"
37 #include "DNA_node_types.h"
39 #include "BLI_listbase.h"
40 #include "BLI_string.h"
41 #include "BLI_utildefines.h"
43 #include "BLF_translation.h"
45 #include "BKE_action.h"
46 #include "BKE_animsys.h"
47 #include "BKE_global.h"
48 #include "BKE_library.h"
52 #include "BKE_utildefines.h"
54 #include "RNA_access.h"
55 #include "RNA_types.h"
57 #include "MEM_guardedalloc.h"
59 #include "node_common.h"
60 #include "node_util.h"
61 #include "node_exec.h"
62 #include "NOD_socket.h"
66 bNodeSocket *node_group_find_input(bNode *gnode, bNodeSocket *gsock)
69 for (sock=gnode->inputs.first; sock; sock=sock->next)
70 if (sock->groupsock == gsock)
75 bNodeSocket *node_group_find_output(bNode *gnode, bNodeSocket *gsock)
78 for (sock=gnode->outputs.first; sock; sock=sock->next)
79 if (sock->groupsock == gsock)
84 bNodeSocket *node_group_add_extern_socket(bNodeTree *UNUSED(ntree), ListBase *lb, int in_out, bNodeSocket *gsock)
88 if (gsock->flag & SOCK_INTERNAL)
91 sock= MEM_callocN(sizeof(bNodeSocket), "sock");
93 /* make a copy of the group socket */
96 sock->next = sock->prev = NULL;
97 sock->new_sock = NULL;
99 /* group sockets are dynamically added */
100 sock->flag |= SOCK_DYNAMIC;
102 sock->own_index = gsock->own_index;
103 sock->groupsock = gsock;
104 sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF);
106 sock->default_value = node_socket_make_default_value(sock->type);
107 node_socket_copy_default_value(sock->type, sock->default_value, gsock->default_value);
110 BLI_addtail(lb, sock);
115 bNode *node_group_make_from_selected(bNodeTree *ntree)
117 bNodeLink *link, *linkn;
118 bNode *node, *gnode, *nextn;
121 ListBase anim_basepaths = {NULL, NULL};
122 float min[2], max[2];
126 INIT_MINMAX2(min, max);
128 /* is there something to group? also do some clearing */
129 for (node= ntree->nodes.first; node; node= node->next) {
130 if (node->flag & NODE_SELECT) {
131 /* no groups in groups */
132 if (node->type==NODE_GROUP)
134 DO_MINMAX2((&node->locx), min, max);
139 if (totnode==0) return NULL;
141 /* check if all connections are OK, no unselected node has both
142 * inputs and outputs to a selection */
143 for (link= ntree->links.first; link; link= link->next) {
144 if (link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT)
145 link->tonode->done |= 1;
146 if (link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT)
147 link->fromnode->done |= 2;
150 for (node= ntree->nodes.first; node; node= node->next) {
151 if ((node->flag & NODE_SELECT)==0)
158 /* OK! new nodetree */
159 ngroup= ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP);
161 /* move nodes over */
162 for (node= ntree->nodes.first; node; node= nextn) {
164 if (node->flag & NODE_SELECT) {
165 /* keep track of this node's RNA "base" path (the part of the pat identifying the node)
166 * if the old nodetree has animation data which potentially covers this node
172 RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
173 path = RNA_path_from_ID_to_struct(&ptr);
176 BLI_addtail(&anim_basepaths, BLI_genericNodeN(path));
179 /* ensure valid parent pointers, detach if parent stays outside the group */
180 if (node->parent && !(node->parent->flag & NODE_SELECT))
181 nodeDetachNode(node);
183 /* change node-collection membership */
184 BLI_remlink(&ntree->nodes, node);
185 BLI_addtail(&ngroup->nodes, node);
187 node->locx-= 0.5f*(min[0]+max[0]);
188 node->locy-= 0.5f*(min[1]+max[1]);
192 /* move animation data over */
194 LinkData *ld, *ldn=NULL;
196 BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths);
198 /* paths + their wrappers need to be freed */
199 for (ld = anim_basepaths.first; ld; ld = ldn) {
203 BLI_freelinkN(&anim_basepaths, ld);
207 /* node groups don't use internal cached data */
208 ntreeFreeCache(ngroup);
210 /* make group node */
211 ntemp.type = NODE_GROUP;
212 ntemp.ngroup = ngroup;
213 gnode= nodeAddNode(ntree, &ntemp);
214 gnode->locx= 0.5f*(min[0]+max[0]);
215 gnode->locy= 0.5f*(min[1]+max[1]);
217 /* relink external sockets */
218 for (link= ntree->links.first; link; link= linkn) {
221 if (link->fromnode && link->tonode && (link->fromnode->flag & link->tonode->flag & NODE_SELECT)) {
222 BLI_remlink(&ntree->links, link);
223 BLI_addtail(&ngroup->links, link);
225 else if (link->tonode && (link->tonode->flag & NODE_SELECT)) {
226 gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN);
227 link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock);
228 link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock);
229 link->tonode = gnode;
231 else if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) {
232 /* search for existing group node socket */
233 for (gsock=ngroup->outputs.first; gsock; gsock=gsock->next)
234 if (gsock->link && gsock->link->fromsock==link->fromsock)
237 gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT);
238 gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock);
239 link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock);
242 link->fromsock = node_group_find_output(gnode, gsock);
243 link->fromnode = gnode;
247 /* update of the group tree */
248 ngroup->update |= NTREE_UPDATE;
249 ntreeUpdateTree(ngroup);
250 /* update of the tree containing the group instance node */
251 ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
252 ntreeUpdateTree(ntree);
257 /* returns 1 if its OK */
258 int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
260 bNodeLink *link, *linkn;
262 bNodeTree *ngroup, *wgroup;
263 ListBase anim_basepaths = {NULL, NULL};
265 ngroup= (bNodeTree *)gnode->id;
266 if (ngroup==NULL) return 0;
268 /* clear new pointers, set in copytree */
269 for (node= ntree->nodes.first; node; node= node->next)
270 node->new_node= NULL;
272 /* wgroup is a temporary copy of the NodeTree we're merging in
273 * - all of wgroup's nodes are transferred across to their new home
274 * - ngroup (i.e. the source NodeTree) is left unscathed
276 wgroup= ntreeCopyTree(ngroup);
278 /* add the nodes into the ntree */
279 for (node= wgroup->nodes.first; node; node= nextn) {
282 /* keep track of this node's RNA "base" path (the part of the pat identifying the node)
283 * if the old nodetree has animation data which potentially covers this node
289 RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr);
290 path = RNA_path_from_ID_to_struct(&ptr);
293 BLI_addtail(&anim_basepaths, BLI_genericNodeN(path));
297 BLI_remlink(&wgroup->nodes, node);
298 BLI_addtail(&ntree->nodes, node);
300 node->locx += gnode->locx;
301 node->locy += gnode->locy;
303 node->flag |= NODE_SELECT;
306 /* restore external links to and from the gnode */
307 for (link= ntree->links.first; link; link= link->next) {
308 if (link->fromnode==gnode) {
309 if (link->fromsock->groupsock) {
310 bNodeSocket *gsock= link->fromsock->groupsock;
312 if (gsock->link->fromnode) {
313 /* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */
314 link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL);
315 link->fromsock = gsock->link->fromsock->new_sock;
318 /* group output directly maps to group input */
319 bNodeSocket *insock= node_group_find_input(gnode, gsock->link->fromsock);
321 link->fromnode = insock->link->fromnode;
322 link->fromsock = insock->link->fromsock;
327 /* copy the default input value from the group socket default to the external socket */
328 node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value);
333 /* remove internal output links, these are not used anymore */
334 for (link=wgroup->links.first; link; link= linkn) {
337 nodeRemLink(wgroup, link);
339 /* restore links from internal nodes */
340 for (link= wgroup->links.first; link; link= link->next) {
341 /* indicates link to group input */
342 if (!link->fromnode) {
343 /* NB: can't use find_group_node_input here,
344 * because gnode sockets still point to the old tree!
347 for (insock= gnode->inputs.first; insock; insock= insock->next)
348 if (insock->groupsock->new_sock == link->fromsock)
351 link->fromnode = insock->link->fromnode;
352 link->fromsock = insock->link->fromsock;
355 /* copy the default input value from the group node socket default to the internal socket */
356 node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value);
357 nodeRemLink(wgroup, link);
362 /* add internal links to the ntree */
363 for (link= wgroup->links.first; link; link= linkn) {
365 BLI_remlink(&wgroup->links, link);
366 BLI_addtail(&ntree->links, link);
369 /* and copy across the animation,
370 * note that the animation data's action can be NULL here */
372 LinkData *ld, *ldn=NULL;
375 /* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */
376 waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action);
378 /* now perform the moving */
379 BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths);
381 /* paths + their wrappers need to be freed */
382 for (ld = anim_basepaths.first; ld; ld = ldn) {
386 BLI_freelinkN(&anim_basepaths, ld);
389 /* free temp action too */
391 BKE_libblock_free(&G.main->action, waction);
395 /* delete the group instance. this also removes old input links! */
396 nodeFreeNode(ntree, gnode);
398 /* free the group tree (takes care of user count) */
399 BKE_libblock_free(&G.main->nodetree, wgroup);
401 ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
402 ntreeUpdateTree(ntree);
407 bNodeSocket *node_group_add_socket(bNodeTree *ngroup, const char *name, int type, int in_out)
409 bNodeSocketType *stype = ntreeGetSocketType(type);
410 bNodeSocket *gsock = MEM_callocN(sizeof(bNodeSocket), "bNodeSocket");
412 BLI_strncpy(gsock->name, name, sizeof(gsock->name));
414 /* group sockets are dynamically added */
415 gsock->flag |= SOCK_DYNAMIC;
417 gsock->next = gsock->prev = NULL;
418 gsock->new_sock = NULL;
420 /* assign new unique index */
421 gsock->own_index = ngroup->cur_index++;
422 gsock->limit = (in_out==SOCK_IN ? 0xFFF : 1);
424 if (stype->value_structsize > 0)
425 gsock->default_value = MEM_callocN(stype->value_structsize, "default socket value");
427 BLI_addtail(in_out==SOCK_IN ? &ngroup->inputs : &ngroup->outputs, gsock);
429 ngroup->update |= (in_out==SOCK_IN ? NTREE_UPDATE_GROUP_IN : NTREE_UPDATE_GROUP_OUT);
434 bNodeSocket *node_group_expose_socket(bNodeTree *ngroup, bNodeSocket *sock, int in_out)
436 bNodeSocket *gsock= node_group_add_socket(ngroup, sock->name, sock->type, in_out);
438 /* initialize the default value. */
439 node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
444 void node_group_expose_all_sockets(bNodeTree *ngroup)
447 bNodeSocket *sock, *gsock;
449 for (node=ngroup->nodes.first; node; node=node->next) {
450 for (sock=node->inputs.first; sock; sock=sock->next) {
451 if (!sock->link && !nodeSocketIsHidden(sock)) {
452 gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_IN);
454 /* initialize the default value. */
455 node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
457 sock->link = nodeAddLink(ngroup, NULL, gsock, node, sock);
460 for (sock=node->outputs.first; sock; sock=sock->next) {
461 if (nodeCountSocketLinks(ngroup, sock)==0 && !nodeSocketIsHidden(sock)) {
462 gsock = node_group_add_socket(ngroup, sock->name, sock->type, SOCK_OUT);
464 /* initialize the default value. */
465 node_socket_copy_default_value(gsock->type, gsock->default_value, sock->default_value);
467 gsock->link = nodeAddLink(ngroup, node, sock, NULL, gsock);
473 void node_group_remove_socket(bNodeTree *ngroup, bNodeSocket *gsock, int in_out)
475 nodeRemSocketLinks(ngroup, gsock);
479 BLI_remlink(&ngroup->inputs, gsock);
480 ngroup->update |= NTREE_UPDATE_GROUP_IN;
483 BLI_remlink(&ngroup->outputs, gsock);
484 ngroup->update |= NTREE_UPDATE_GROUP_OUT;
488 if (gsock->default_value)
489 MEM_freeN(gsock->default_value);
494 /* groups display their internal tree name as label */
495 const char *node_group_label(bNode *node)
497 return (node->id)? node->id->name+2: IFACE_("Missing Datablock");
500 int node_group_valid(bNodeTree *ntree, bNodeTemplate *ntemp)
502 bNodeTemplate childtemp;
505 /* regular groups cannot be recursive */
506 if (ntree == ntemp->ngroup)
509 /* make sure all children are valid */
510 for (node=ntemp->ngroup->nodes.first; node; node=node->next) {
511 childtemp = nodeMakeTemplate(node);
512 if (!nodeValid(ntree, &childtemp))
519 bNodeTemplate node_group_template(bNode *node)
522 ntemp.type = NODE_GROUP;
523 ntemp.ngroup = (bNodeTree*)node->id;
527 void node_group_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
529 node->id = (ID*)ntemp->ngroup;
531 /* NB: group socket input/output roles are inverted internally!
532 * Group "inputs" work as outputs in links and vice versa.
536 for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next)
537 node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock);
538 for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next)
539 node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock);
543 static bNodeSocket *group_verify_socket(bNodeTree *ntree, ListBase *lb, int in_out, bNodeSocket *gsock)
547 /* group sockets tagged as internal are not exposed ever */
548 if (gsock->flag & SOCK_INTERNAL)
551 for (sock= lb->first; sock; sock= sock->next) {
552 if (sock->own_index==gsock->own_index)
556 sock->groupsock = gsock;
558 BLI_strncpy(sock->name, gsock->name, sizeof(sock->name));
559 if (gsock->type != sock->type)
560 nodeSocketSetType(sock, gsock->type);
562 /* XXX hack: group socket input/output roles are inverted internally,
563 * need to change the limit value when making actual node sockets from them.
565 sock->limit = (in_out==SOCK_IN ? 1 : 0xFFF);
567 BLI_remlink(lb, sock);
572 return node_group_add_extern_socket(ntree, NULL, in_out, gsock);
576 static void group_verify_socket_list(bNodeTree *ntree, bNode *node, ListBase *lb, int in_out, ListBase *glb)
578 bNodeSocket *sock, *nextsock, *gsock;
580 /* step by step compare */
581 for (gsock= glb->first; gsock; gsock=gsock->next) {
582 /* abusing new_sock pointer for verification here! only used inside this function */
583 gsock->new_sock= group_verify_socket(ntree, lb, in_out, gsock);
585 /* leftovers are removed */
586 for (sock=lb->first; sock; sock=nextsock) {
588 if (sock->flag & SOCK_DYNAMIC)
589 nodeRemoveSocket(ntree, node, sock);
591 /* and we put back the verified sockets */
592 for (gsock= glb->first; gsock; gsock=gsock->next) {
593 if (gsock->new_sock) {
594 BLI_addtail(lb, gsock->new_sock);
595 gsock->new_sock = NULL;
600 /* make sure all group node in ntree, which use ngroup, are sync'd */
601 void node_group_verify(struct bNodeTree *ntree, struct bNode *node, struct ID *id)
603 /* check inputs and outputs, and remove or insert them */
605 bNodeTree *ngroup= (bNodeTree*)node->id;
606 group_verify_socket_list(ntree, node, &node->inputs, SOCK_IN, &ngroup->inputs);
607 group_verify_socket_list(ntree, node, &node->outputs, SOCK_OUT, &ngroup->outputs);
611 struct bNodeTree *node_group_edit_get(bNode *node)
613 if (node->flag & NODE_GROUP_EDIT)
614 return (bNodeTree*)node->id;
619 struct bNodeTree *node_group_edit_set(bNode *node, int edit)
622 bNodeTree *ngroup= (bNodeTree*)node->id;
625 ntreeMakeLocal(ngroup);
627 node->flag |= NODE_GROUP_EDIT;
632 node->flag &= ~NODE_GROUP_EDIT;
637 void node_group_edit_clear(bNode *node)
639 bNodeTree *ngroup= (bNodeTree*)node->id;
642 node->flag &= ~NODE_GROUP_EDIT;
645 for (inode=ngroup->nodes.first; inode; inode=inode->next)
646 nodeGroupEditClear(inode);
649 void node_group_link(bNodeTree *ntree, bNodeSocket *sock, int in_out)
651 node_group_expose_socket(ntree, sock, in_out);
656 /* Essentially a group node with slightly different behavior.
657 * The internal tree is executed several times, with each output being re-used
658 * as an input in the next iteration. For this purpose, input and output socket
659 * lists are kept identical!
662 bNodeTemplate node_forloop_template(bNode *node)
665 ntemp.type = NODE_FORLOOP;
666 ntemp.ngroup = (bNodeTree*)node->id;
670 void node_forloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
674 node->id = (ID*)ntemp->ngroup;
676 sock = nodeAddSocket(ntree, node, SOCK_IN, "Iterations", SOCK_FLOAT);
677 node_socket_set_default_value_float(sock->default_value, PROP_UNSIGNED, 1, 0, 10000);
679 /* NB: group socket input/output roles are inverted internally!
680 * Group "inputs" work as outputs in links and vice versa.
684 for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next)
685 node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock);
686 for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next)
687 node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock);
691 void node_forloop_init_tree(bNodeTree *ntree)
694 sock = node_group_add_socket(ntree, "Iteration", SOCK_FLOAT, SOCK_IN);
695 sock->flag |= SOCK_INTERNAL;
698 static void loop_sync(bNodeTree *ntree, int sync_in_out)
700 bNodeSocket *sock, *sync, *nsync, *mirror;
703 if (sync_in_out==SOCK_IN) {
704 sock = ntree->outputs.first;
706 sync = ntree->inputs.first;
707 sync_lb = &ntree->inputs;
710 sock = ntree->inputs.first;
712 sync = ntree->outputs.first;
713 sync_lb = &ntree->outputs;
716 /* NB: the sock->storage pointer is used here directly to store the own_index int
717 * out the mirrored socket counterpart!
721 /* skip static and internal sockets on the sync side (preserves socket order!) */
722 while (sync && ((sync->flag & SOCK_INTERNAL) || !(sync->flag & SOCK_DYNAMIC)))
725 if (sync && !(sync->flag & SOCK_INTERNAL) && (sync->flag & SOCK_DYNAMIC)) {
726 if (sock->storage==NULL) {
727 /* if mirror index is 0, the sockets is newly added and a new mirror must be created. */
728 mirror = node_group_expose_socket(ntree, sock, sync_in_out);
729 /* store the mirror index */
730 sock->storage = SET_INT_IN_POINTER(mirror->own_index);
731 mirror->storage = SET_INT_IN_POINTER(sock->own_index);
732 /* move mirror to the right place */
733 BLI_remlink(sync_lb, mirror);
735 BLI_insertlinkbefore(sync_lb, sync, mirror);
737 BLI_addtail(sync_lb, mirror);
740 /* look up the mirror socket */
741 for (mirror=sync; mirror; mirror=mirror->next)
742 if (mirror->own_index == GET_INT_FROM_POINTER(sock->storage))
744 /* make sure the name is the same (only for identification by user, no deeper meaning) */
745 BLI_strncpy(mirror->name, sock->name, sizeof(mirror->name));
746 /* fix the socket order if necessary */
747 if (mirror != sync) {
748 BLI_remlink(sync_lb, mirror);
749 BLI_insertlinkbefore(sync_lb, sync, mirror);
759 /* remaining sockets in sync_lb are leftovers from deleted sockets, remove them */
762 if (!(sync->flag & SOCK_INTERNAL) && (sync->flag & SOCK_DYNAMIC))
763 node_group_remove_socket(ntree, sync, sync_in_out);
768 void node_loop_update_tree(bNodeTree *ngroup)
770 /* make sure inputs & outputs are identical */
771 if (ngroup->update & NTREE_UPDATE_GROUP_IN)
772 loop_sync(ngroup, SOCK_OUT);
773 if (ngroup->update & NTREE_UPDATE_GROUP_OUT)
774 loop_sync(ngroup, SOCK_IN);
777 void node_whileloop_init(bNodeTree *ntree, bNode *node, bNodeTemplate *ntemp)
781 node->id = (ID*)ntemp->ngroup;
783 sock = nodeAddSocket(ntree, node, SOCK_IN, "Condition", SOCK_FLOAT);
784 node_socket_set_default_value_float(sock->default_value, PROP_NONE, 1, 0, 1);
787 node->custom1 = 10000;
789 /* NB: group socket input/output roles are inverted internally!
790 * Group "inputs" work as outputs in links and vice versa.
794 for (gsock=ntemp->ngroup->inputs.first; gsock; gsock=gsock->next)
795 node_group_add_extern_socket(ntree, &node->inputs, SOCK_IN, gsock);
796 for (gsock=ntemp->ngroup->outputs.first; gsock; gsock=gsock->next)
797 node_group_add_extern_socket(ntree, &node->outputs, SOCK_OUT, gsock);
801 void node_whileloop_init_tree(bNodeTree *ntree)
804 sock = node_group_add_socket(ntree, "Condition", SOCK_FLOAT, SOCK_OUT);
805 sock->flag |= SOCK_INTERNAL;
808 bNodeTemplate node_whileloop_template(bNode *node)
811 ntemp.type = NODE_WHILELOOP;
812 ntemp.ngroup = (bNodeTree*)node->id;
818 static void node_frame_init(bNodeTree *UNUSED(ntree), bNode *node, bNodeTemplate *UNUSED(ntemp))
820 NodeFrame *data = (NodeFrame *)MEM_callocN(sizeof(NodeFrame), "frame node storage");
821 node->storage = data;
823 data->flag |= NODE_FRAME_SHRINK;
825 data->label_size = 20;
828 void register_node_type_frame(bNodeTreeType *ttype)
830 /* frame type is used for all tree types, needs dynamic allocation */
831 bNodeType *ntype= MEM_callocN(sizeof(bNodeType), "frame node type");
833 node_type_base(ttype, ntype, NODE_FRAME, "Frame", NODE_CLASS_LAYOUT, NODE_BACKGROUND|NODE_OPTIONS);
834 node_type_init(ntype, node_frame_init);
835 node_type_storage(ntype, "NodeFrame", node_free_standard_storage, node_copy_standard_storage);
836 node_type_size(ntype, 150, 100, 0);
837 node_type_compatibility(ntype, NODE_OLD_SHADING|NODE_NEW_SHADING);
839 ntype->needs_free = 1;
840 nodeRegisterType(ttype, ntype);
844 /* **************** REROUTE ******************** */
846 static bNodeSocketTemplate node_reroute_in[]= {
847 { SOCK_RGBA, 1, "Input", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
850 static bNodeSocketTemplate node_reroute_out[]= {
851 { SOCK_RGBA, 0, "Output", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
855 /* simple, only a single input and output here */
856 ListBase node_reroute_internal_connect(bNodeTree *ntree, bNode *node)
861 ret.first = ret.last = NULL;
863 /* Security check! */
867 link = MEM_callocN(sizeof(bNodeLink), "internal node link");
868 link->fromnode = node;
869 link->fromsock = node->inputs.first;
871 link->tosock = node->outputs.first;
872 /* internal link is always valid */
873 link->flag |= NODE_LINK_VALID;
874 BLI_addtail(&ret, link);
879 void register_node_type_reroute(bNodeTreeType *ttype)
881 /* frame type is used for all tree types, needs dynamic allocation */
882 bNodeType *ntype= MEM_callocN(sizeof(bNodeType), "frame node type");
884 node_type_base(ttype, ntype, NODE_REROUTE, "Reroute", NODE_CLASS_LAYOUT, 0);
885 node_type_socket_templates(ntype, node_reroute_in, node_reroute_out);
886 node_type_internal_connect(ntype, node_reroute_internal_connect);
888 ntype->needs_free = 1;
889 nodeRegisterType(ttype, ntype);