diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2021-07-06 20:36:11 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2021-07-06 20:36:11 +0300 |
commit | 586cf8b1905257bf0f7d9c20b5333271f9cab3e9 (patch) | |
tree | 5fa77626641c47f4274b9145a1f1702512fc92b6 /source/blender/blenkernel/BKE_node.h | |
parent | 933eddc9a113b40849895922f2dc350305809ebd (diff) |
Nodes: Adds button to groups to change type of sockets.
The menu lists all socket types that are valid for the node tree.
Changing a socket type updates all instances of the group and keeps
existing links to the socket.
If changing the socket type leads to incorrect node connections the
links are flagged as invalid (red) and ignored but not removed. This is
so users don't lose information and can then fix resulting issues.
For example: Changing a Color socket to a Shader socket can cause an
invalid Shader-to-Color connection.
Implementation details:
The new `NODE_OT_tree_socket_change_type` operator uses the generic
`rna_node_socket_type_itemf` function to list all eligible socket types.
It uses the tree type's `valid_socket_type` callback to test for valid
types. In addition it also checks the subtype, because multiple RNA
types are registered for the same base type. The `valid_socket_type`
callback has been modified slightly to accept full socket types instead
of just the base type enum, so that custom (python) socket types can be
used by this operator.
The `nodeModifySocketType` function is now called when group nodes
encounter a socket type mismatch, instead of replacing the socket
entirely. This ensures that links are kept to/from group nodes as well
as group input/output nodes. The `nodeModifySocketType` function now
also takes a full `bNodeSocketType` instead of just the base and subtype
enum (a shortcut `nodeModifySocketTypeStatic` exists for when only
static types are used).
Differential Revision: https://developer.blender.org/D10912
Diffstat (limited to 'source/blender/blenkernel/BKE_node.h')
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 7f4189a3a4a..301fe875d79 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -141,7 +141,10 @@ typedef void *SocketGetCPPValueFunction; * Defines the appearance and behavior of a socket in the UI. */ typedef struct bNodeSocketType { - char idname[64]; /* identifier name */ + /* Identifier name */ + char idname[64]; + /* Type label */ + char label[64]; void (*draw)(struct bContext *C, struct uiLayout *layout, @@ -412,7 +415,7 @@ typedef struct bNodeTreeType { void (*node_add_init)(struct bNodeTree *ntree, struct bNode *bnode); /* Check if the socket type is valid for this tree type. */ - bool (*valid_socket_type)(enum eNodeSocketDatatype socket_type, struct bNodeTreeType *ntreetype); + bool (*valid_socket_type)(struct bNodeTreeType *ntreetype, struct bNodeSocketType *socket_type); /* RNA integration */ ExtensionRNA rna_ext; @@ -554,8 +557,12 @@ void nodeRegisterSocketType(struct bNodeSocketType *stype); void nodeUnregisterSocketType(struct bNodeSocketType *stype); bool nodeSocketIsRegistered(struct bNodeSocket *sock); struct GHashIterator *nodeSocketTypeGetIterator(void); +const char *nodeSocketTypeLabel(const bNodeSocketType *stype); + +bool nodeIsStaticSocketType(const struct bNodeSocketType *stype); const char *nodeStaticSocketType(int type, int subtype); const char *nodeStaticSocketInterfaceType(int type, int subtype); +const char *nodeStaticSocketLabel(int type, int subtype); /* helper macros for iterating over node types */ #define NODE_SOCKET_TYPES_BEGIN(stype) \ @@ -605,7 +612,11 @@ struct bNodeSocket *nodeInsertStaticSocket(struct bNodeTree *ntree, const char *name); void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock); void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node); -void nodeModifySocketType( +void nodeModifySocketType(struct bNodeTree *ntree, + struct bNode *node, + struct bNodeSocket *sock, + const char *idname); +void nodeModifySocketTypeStatic( struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock, int type, int subtype); struct bNode *nodeAddNode(const struct bContext *C, struct bNodeTree *ntree, const char *idname); |