Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2021-07-06 20:36:11 +0300
committerLukas Tönne <lukas.toenne@gmail.com>2021-07-06 20:36:11 +0300
commit586cf8b1905257bf0f7d9c20b5333271f9cab3e9 (patch)
tree5fa77626641c47f4274b9145a1f1702512fc92b6 /source/blender/makesrna
parent933eddc9a113b40849895922f2dc350305809ebd (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/makesrna')
-rw-r--r--source/blender/makesrna/RNA_access.h1
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c26
2 files changed, 19 insertions, 8 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 876229411e0..782d0924d21 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -450,6 +450,7 @@ extern StructRNA RNA_NodeOutputFileSlotFile;
extern StructRNA RNA_NodeOutputFileSlotLayer;
extern StructRNA RNA_NodeSocket;
extern StructRNA RNA_NodeSocketInterface;
+extern StructRNA RNA_NodeSocketStandard;
extern StructRNA RNA_NodeTree;
extern StructRNA RNA_NoiseGpencilModifier;
extern StructRNA RNA_NoiseTexture;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 0a120837191..0afb9da9547 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -799,7 +799,7 @@ const EnumPropertyItem *rna_node_socket_type_itemf(void *data,
tmp.value = i;
tmp.identifier = stype->idname;
tmp.icon = RNA_struct_ui_icon(srna);
- tmp.name = RNA_struct_ui_name(srna);
+ tmp.name = nodeSocketTypeLabel(stype);
tmp.description = RNA_struct_ui_description(srna);
RNA_enum_item_add(&item, &totitem, &tmp);
@@ -1025,8 +1025,7 @@ static void rna_NodeTree_get_from_context(
RNA_parameter_list_free(&list);
}
-static bool rna_NodeTree_valid_socket_type(eNodeSocketDatatype socket_type,
- bNodeTreeType *ntreetype)
+static bool rna_NodeTree_valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
{
extern FunctionRNA rna_NodeTree_valid_socket_type_func;
@@ -1040,7 +1039,7 @@ static bool rna_NodeTree_valid_socket_type(eNodeSocketDatatype socket_type,
func = &rna_NodeTree_valid_socket_type_func;
RNA_parameter_list_create(&list, &ptr, func);
- RNA_parameter_set_lookup(&list, "type", &socket_type);
+ RNA_parameter_set_lookup(&list, "idname", &socket_type->idname);
ntreetype->rna_ext.call(NULL, &ptr, func, &list);
RNA_parameter_get_lookup(&list, "valid", &ret);
@@ -2866,7 +2865,7 @@ static void rna_NodeSocket_type_set(PointerRNA *ptr, int value)
bNodeSocket *sock = (bNodeSocket *)ptr->data;
bNode *node;
nodeFindNode(ntree, sock, &node, NULL);
- nodeModifySocketType(ntree, node, sock, value, 0);
+ nodeModifySocketTypeStatic(ntree, node, sock, value, 0);
}
static void rna_NodeSocket_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
@@ -10176,7 +10175,7 @@ static void rna_def_node_socket(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Node Socket", "Input or output socket of a node");
RNA_def_struct_sdna(srna, "bNodeSocket");
RNA_def_struct_refine_func(srna, "rna_NodeSocket_refine");
- RNA_def_struct_ui_icon(srna, ICON_PLUGIN);
+ RNA_def_struct_ui_icon(srna, ICON_NONE);
RNA_def_struct_path_func(srna, "rna_NodeSocket_path");
RNA_def_struct_register_funcs(
srna, "rna_NodeSocket_register", "rna_NodeSocket_unregister", NULL);
@@ -10281,6 +10280,11 @@ static void rna_def_node_socket(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "ID Name", "");
+ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "typeinfo->label");
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+ RNA_def_property_ui_text(prop, "Type Label", "Label to display for the socket type in the UI");
+
/* draw socket */
func = RNA_def_function(srna, "draw", NULL);
RNA_def_function_ui_description(func, "Draw socket");
@@ -10369,6 +10373,11 @@ static void rna_def_node_socket_interface(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "ID Name", "");
+ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "typeinfo->label");
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+ RNA_def_property_ui_text(prop, "Type Label", "Label to display for the socket type in the UI");
+
func = RNA_def_function(srna, "draw", NULL);
RNA_def_function_ui_description(func, "Draw template settings");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
@@ -11879,11 +11888,12 @@ static void rna_def_nodetree(BlenderRNA *brna)
func, "result_3", "ID", "From ID", "Original ID data-block selected from the context");
RNA_def_function_output(func, parm);
- /* Check for support of a socket type. */
+ /* Check for support of a socket type with a type identifier. */
func = RNA_def_function(srna, "valid_socket_type", NULL);
RNA_def_function_ui_description(func, "Check if the socket type is valid for the node tree");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL);
- parm = RNA_def_enum(func, "type", node_socket_type_items, 0, "", "");
+ parm = RNA_def_string(
+ func, "idname", "NodeSocket", MAX_NAME, "Socket Type", "Identifier of the socket type");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
RNA_def_function_return(func, RNA_def_boolean(func, "valid", false, "", ""));
}