diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-29 13:20:55 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-08-29 13:55:03 +0300 |
commit | c1582667cabe025bd3a1ee4a3db27e2b3fd9e42a (patch) | |
tree | a5c30c895723b3edad465ae986acc111791be740 /source/blender | |
parent | 9ca03ba4104429b4304ec012feb98ea6d923cb04 (diff) |
Add utility function to copy default values from one tree to another
The trees should match in nodes layout completely.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 7 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.c | 30 | ||||
-rw-r--r-- | source/blender/nodes/NOD_socket.h | 2 | ||||
-rw-r--r-- | source/blender/nodes/intern/node_socket.c | 2 |
4 files changed, 39 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5e50d37e145..5bc47f62b64 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1050,4 +1050,11 @@ int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target, void init_nodesystem(void); void free_nodesystem(void); +/* -------------------------------------------------------------------- */ +/* evaluation support, */ + +void BKE_nodetree_copy_default_values(struct bNodeTree *ntree_dst, + const struct bNodeTree *ntree_src); + + #endif /* __BKE_NODE_H__ */ diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index f0b5fc9c610..1c24d72759e 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3804,3 +3804,33 @@ void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer } } } + +static void node_copy_default_values_list(ListBase *sockets_dst, + const ListBase *sockets_src) +{ + bNodeSocket *sock_dst = sockets_dst->first; + const bNodeSocket *sock_src = sockets_src->first; + while (sock_dst != NULL) { + node_socket_copy_default_value(sock_dst, sock_src); + sock_dst = sock_dst->next; + sock_src = sock_src->next; + } +} + +static void node_copy_default_values(bNode *node_dst, const bNode *node_src) +{ + node_copy_default_values_list(&node_dst->inputs, &node_src->inputs); + node_copy_default_values_list(&node_dst->outputs, &node_src->outputs); +} + +void BKE_nodetree_copy_default_values(bNodeTree *ntree_dst, + const bNodeTree *ntree_src) +{ + bNode *node_dst = ntree_dst->nodes.first; + const bNode *node_src = ntree_src->nodes.first; + while (node_dst != NULL) { + node_copy_default_values(node_dst, node_src); + node_dst = node_dst->next; + node_src = node_src->next; + } +} diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h index 5c8875593e7..e311adc45eb 100644 --- a/source/blender/nodes/NOD_socket.h +++ b/source/blender/nodes/NOD_socket.h @@ -49,7 +49,7 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struc void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node); void node_socket_init_default_value(struct bNodeSocket *sock); -void node_socket_copy_default_value(struct bNodeSocket *to, struct bNodeSocket *from); +void node_socket_copy_default_value(struct bNodeSocket *to, const struct bNodeSocket *from); void register_standard_node_socket_types(void); #endif diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c index 01c642b063d..ddd25b237a0 100644 --- a/source/blender/nodes/intern/node_socket.c +++ b/source/blender/nodes/intern/node_socket.c @@ -267,7 +267,7 @@ void node_socket_init_default_value(bNodeSocket *sock) } } -void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from) +void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from) { /* sanity check */ if (to->type != from->type) |