diff options
author | Jacques Lucke <jacques@blender.org> | 2021-08-30 18:13:46 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-08-30 18:23:05 +0300 |
commit | 1e69a25043120cc8dddc3f58622eb50e1443def1 (patch) | |
tree | 16bcb3eb98215dbbd5c54880cb3d14544e316d3f /source/blender/blenkernel/intern | |
parent | e8684eff301d09e25b4e7ef6221a5289661da2e3 (diff) |
Nodes: add more flexible method to declare sockets of a node
Previously, built-in nodes had to implement "socket templates"
(`bNodeSocketTemplate`) to tell Blender which sockets they have.
It was nice that this was declarative, but this approach was way
too rigid and was cumbersome to use in many cases.
This commit starts to move us away from this rigid structure
by letting nodes implement a function that declares the sockets
the node has. Right now this is used as a direct replacement
of the "socket template" approach to keep the refactor smaller.
It's just a bit easier to read and write.
In the future we want to support more complex features like
dynamic numbers of sockets and type inferencing. Those features
will be easier to build on this new approach.
This new approach can live side by side with `bNodeSocketTemplate`
for a while. That makes it easier to update nodes one by one.
Note: In `bNodeSocketTemplate` socket identifiers were made
unique automatically. In this new approach, one has to specify
unique identifiers manually (unless the name is unique already).
Differential Revision: https://developer.blender.org/D12335
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index fb43d1fc87f..48d747e2bf3 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -79,6 +79,7 @@ #include "NOD_composite.h" #include "NOD_function.h" #include "NOD_geometry.h" +#include "NOD_node_declaration.hh" #include "NOD_shader.h" #include "NOD_socket.h" #include "NOD_texture.h" @@ -887,7 +888,7 @@ void ntreeBlendReadLib(struct BlendLibReader *reader, struct bNodeTree *ntree) * to match the static layout. */ if (!BLO_read_lib_is_undo(reader)) { LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node_verify_socket_templates(ntree, node); + node_verify_sockets(ntree, node, false); } } } @@ -1011,6 +1012,13 @@ IDTypeInfo IDType_ID_NT = { static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, bNodeType *ntype) { + if (ntype->declare != nullptr) { + blender::nodes::NodeDeclaration node_decl; + blender::nodes::NodeDeclarationBuilder builder{node_decl}; + ntype->declare(builder); + node_decl.build(*ntree, *node); + return; + } bNodeSocketTemplate *sockdef; /* bNodeSocket *sock; */ /* UNUSED */ @@ -1916,6 +1924,14 @@ static void node_socket_free(bNodeTree *UNUSED(ntree), void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock) { + nodeRemoveSocketEx(ntree, node, sock, true); +} + +void nodeRemoveSocketEx(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + bool do_id_user) +{ LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { if (link->fromsock == sock || link->tosock == sock) { nodeRemLink(ntree, link); @@ -1926,7 +1942,7 @@ void nodeRemoveSocket(bNodeTree *ntree, bNode *node, bNodeSocket *sock) BLI_remlink(&node->inputs, sock); BLI_remlink(&node->outputs, sock); - node_socket_free(ntree, sock, node, true); + node_socket_free(ntree, sock, node, do_id_user); MEM_freeN(sock); node->update |= NODE_UPDATE; |