diff options
Diffstat (limited to 'source/blender/blenkernel/intern/node.c')
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 0ff6b7abbca..3112e8dc13d 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -147,6 +147,7 @@ static bNodeSocket *make_socket(bNodeTree *UNUSED(ntree), int in_out, const char sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF); sock->type = type; sock->storage = NULL; + sock->flag |= SOCK_COLLAPSED; sock->default_value = node_socket_make_default_value(type); node_socket_init_default_value(type, sock->default_value); @@ -346,6 +347,7 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) { bNode *nnode = MEM_callocN(sizeof(bNode), "dupli node"); bNodeSocket *sock, *oldsock; + bNodeLink *link, *oldlink; *nnode = *node; /* can be called for nodes outside a node tree (e.g. clipboard) */ @@ -385,6 +387,15 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) sock->cache = NULL; } + BLI_duplicatelist(&nnode->internal_links, &node->internal_links); + oldlink = node->internal_links.first; + for (link = nnode->internal_links.first; link; link = link->next, oldlink = oldlink->next) { + link->fromnode = nnode; + link->tonode = nnode; + link->fromsock = link->fromsock->new_sock; + link->tosock = link->tosock->new_sock; + } + /* don't increase node->id users, freenode doesn't decrement either */ if (node->typeinfo->copystoragefunc) @@ -392,7 +403,13 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) node->new_node = nnode; nnode->new_node = NULL; - nnode->preview = NULL; + + /* only shader nodes get pleasant preview updating this way, compo uses own system */ + if (node->preview && ntree->type == NTREE_SHADER) { + nnode->preview = MEM_dupallocN(node->preview); + if (node->preview->rect) + nnode->preview->rect = MEM_dupallocN(node->preview->rect); + } if (ntree) ntree->update |= NTREE_UPDATE_NODES; @@ -523,15 +540,12 @@ void nodeRemSocketLinks(bNodeTree *ntree, bNodeSocket *sock) void nodeInternalRelink(bNodeTree *ntree, bNode *node) { bNodeLink *link, *link_next; - ListBase intlinks; - if (!node->typeinfo->internal_connect) + if (node->internal_links.first == NULL) return; - intlinks = node->typeinfo->internal_connect(ntree, node); - /* store link pointers in output sockets, for efficient lookup */ - for (link = intlinks.first; link; link = link->next) + for (link = node->internal_links.first; link; link = link->next) link->tosock->link = link; /* redirect downstream links */ @@ -565,8 +579,6 @@ void nodeInternalRelink(bNodeTree *ntree, bNode *node) if (link->tonode == node) nodeRemLink(ntree, link); } - - BLI_freelistN(&intlinks); } void nodeToView(bNode *node, float x, float y, float *rx, float *ry) @@ -713,7 +725,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, const short do_id_use } node->new_node = NULL; - /* nnode= */ nodeCopyNode(newtree, node); /* sets node->new */ + /* nnode = */ nodeCopyNode(newtree, node); /* sets node->new */ /* make sure we don't copy new nodes again! */ if (node == last) @@ -818,7 +830,7 @@ void nodeFreePreview(bNode *node) MEM_freeN(node->preview->rect); MEM_freeN(node->preview); node->preview = NULL; - } + } } static void node_init_preview(bNode *node, int xsize, int ysize) @@ -861,7 +873,7 @@ void ntreeInitPreview(bNodeTree *ntree, int xsize, int ysize) node_init_preview(node, xsize, ysize); if (node->type == NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) ntreeInitPreview((bNodeTree *)node->id, xsize, ysize); - } + } } static void nodeClearPreview(bNode *node) @@ -883,7 +895,7 @@ void ntreeClearPreview(bNodeTree *ntree) nodeClearPreview(node); if (node->type == NODE_GROUP && (node->flag & NODE_GROUP_EDIT)) ntreeClearPreview((bNodeTree *)node->id); - } + } } /* hack warning! this function is only used for shader previews, and @@ -988,6 +1000,8 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node) MEM_freeN(sock); } + BLI_freelistN(&node->internal_links); + nodeFreePreview(node); MEM_freeN(node); @@ -999,6 +1013,7 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node) /* do not free ntree itself here, BKE_libblock_free calls this function too */ void ntreeFreeTree_ex(bNodeTree *ntree, const short do_id_user) { + bNodeTree *tntree; bNode *node, *next; bNodeSocket *sock; @@ -1055,6 +1070,14 @@ void ntreeFreeTree_ex(bNodeTree *ntree, const short do_id_user) for (sock = ntree->outputs.first; sock; sock = sock->next) node_socket_free_default_value(sock->type, sock->default_value); BLI_freelistN(&ntree->outputs); + + /* if ntree is not part of library, free the libblock data explicitly */ + for (tntree = G.main->nodetree.first; tntree; tntree = tntree->id.next) + if (tntree == ntree) + break; + if (tntree == NULL) { + BKE_libblock_free_data(&ntree->id); + } } /* same as ntreeFreeTree_ex but always manage users */ void ntreeFreeTree(bNodeTree *ntree) @@ -1816,6 +1839,8 @@ void ntreeUpdateTree(bNodeTree *ntree) ntreetype->update_node(ntree, node); else if (node->typeinfo->updatefunc) node->typeinfo->updatefunc(ntree, node); + + nodeUpdateInternalLinks(ntree, node); } } @@ -1853,6 +1878,9 @@ void nodeUpdate(bNodeTree *ntree, bNode *node) ntreetype->update_node(ntree, node); else if (node->typeinfo->updatefunc) node->typeinfo->updatefunc(ntree, node); + + nodeUpdateInternalLinks(ntree, node); + /* clear update flag */ node->update = 0; } @@ -1892,9 +1920,21 @@ int nodeUpdateID(bNodeTree *ntree, ID *id) } } + for (node = ntree->nodes.first; node; node = node->next) { + nodeUpdateInternalLinks(ntree, node); + } + return change; } +void nodeUpdateInternalLinks(bNodeTree *ntree, bNode *node) +{ + BLI_freelistN(&node->internal_links); + + if (node->typeinfo && node->typeinfo->update_internal_links) + node->typeinfo->update_internal_links(ntree, node); +} + /* ************* node type access ********** */ @@ -1967,7 +2007,7 @@ void node_type_base(bNodeTreeType *ttype, bNodeType *ntype, int type, const char /* Default muting stuff. */ if (ttype) - ntype->internal_connect = ttype->internal_connect; + ntype->update_internal_links = ttype->update_internal_links; /* default size values */ ntype->width = 140; @@ -2063,9 +2103,9 @@ void node_type_exec_new(struct bNodeType *ntype, ntype->newexecfunc = newexecfunc; } -void node_type_internal_connect(bNodeType *ntype, ListBase (*internal_connect)(bNodeTree *, bNode *)) +void node_type_internal_links(bNodeType *ntype, void (*update_internal_links)(bNodeTree *, bNode *)) { - ntype->internal_connect = internal_connect; + ntype->update_internal_links = update_internal_links; } void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out)) @@ -2198,6 +2238,7 @@ static void registerCompositNodes(bNodeTreeType *ttype) register_node_type_cmp_bokehimage(ttype); register_node_type_cmp_bokehblur(ttype); register_node_type_cmp_switch(ttype); + register_node_type_cmp_pixelate(ttype); register_node_type_cmp_mask(ttype); register_node_type_cmp_trackpos(ttype); |