diff options
author | Miguel Porces <cmporces> | 2019-03-16 20:48:22 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-03-16 22:36:35 +0300 |
commit | 9e152f919f2f86cbe3530c6adc34373ebc703904 (patch) | |
tree | e3434b83601c03e659b4a1bfd4ae5027f58fa3f5 /source/blender/makesrna | |
parent | 5797a5fc65c87b69460d910a82d219b5e3ea12ad (diff) |
Python API: add Python-defined node groups for shaders and compositing.
This was already supported for Cycles shader nodes, but now also works for
Eevee and compositing nodes. Instead of a generic NodeCustomGroup, now
there is ShaderNodeCustomGroup and CompositorNodeCustomGroup that can be
subclassed and registered.
Differential Revision: https://developer.blender.org/D4370
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 74f47f76dc3..591cabac98f 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -192,6 +192,8 @@ static const EnumPropertyItem prop_shader_output_target_items[] = { #include "NOD_common.h" #include "NOD_socket.h" +#include "NOD_shader.h" +#include "NOD_composite.h" #include "RE_engine.h" #include "RE_pipeline.h" @@ -451,6 +453,13 @@ static const EnumPropertyItem *rna_node_static_type_itemf(bContext *UNUSED(C), P tmp.icon = ICON_NONE; RNA_enum_item_add(&item, &totitem, &tmp); + tmp.value = NODE_CUSTOM_GROUP; + tmp.identifier = "CUSTOM GROUP"; + tmp.name = "CustomGroup"; + tmp.description = "Custom Group Node"; + tmp.icon = ICON_NONE; + RNA_enum_item_add(&item, &totitem, &tmp); + tmp.value = NODE_UNDEFINED; tmp.identifier = "UNDEFINED"; tmp.name = "UNDEFINED"; @@ -2460,6 +2469,50 @@ static StructRNA *rna_NodeCustomGroup_register( return nt->ext.srna; } +static StructRNA *rna_ShaderNodeCustomGroup_register( + Main * bmain, ReportList *reports, + void *data, const char *identifier, + StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) +{ + bNodeType * nt = rna_Node_register_base(bmain, reports, &RNA_ShaderNodeCustomGroup, data, identifier, validate, call, free); + + if (!nt) + return NULL; + + nt->verifyfunc = node_group_verify; + nt->type = NODE_CUSTOM_GROUP; + + register_node_type_sh_custom_group(nt); + + nodeRegisterType(nt); + + WM_main_add_notifier(NC_NODE | NA_EDITED, NULL); + + return nt->ext.srna; +} + +static StructRNA *rna_CompositorNodeCustomGroup_register( + Main *bmain, ReportList *reports, + void *data, const char *identifier, + StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) +{ + bNodeType *nt = rna_Node_register_base(bmain, reports, &RNA_CompositorNodeCustomGroup, data, identifier, validate, call, free); + if (!nt) + return NULL; + + nt->verifyfunc = node_group_verify; + nt->type = NODE_CUSTOM_GROUP; + + register_node_type_cmp_custom_group(nt); + + nodeRegisterType(nt); + + WM_main_add_notifier(NC_NODE | NA_EDITED, NULL); + + return nt->ext.srna; +} + + static void rna_CompositorNode_tag_need_exec(bNode *node) { node->need_exec = true; @@ -3410,15 +3463,16 @@ static void def_group(StructRNA *srna) RNA_def_property_ui_text(prop, "Interface", "Interface socket data"); } -static void def_custom_group(BlenderRNA *brna) +static void def_custom_group(BlenderRNA *brna, const char *struct_name, const char *base_name, + const char *ui_name, const char *ui_desc, const char *reg_func) { StructRNA *srna; - srna = RNA_def_struct(brna, "NodeCustomGroup", "Node"); - RNA_def_struct_ui_text(srna, "Custom Group", "Base node type for custom registered node group types"); + srna = RNA_def_struct(brna, struct_name, base_name); + RNA_def_struct_ui_text(srna, ui_name, ui_desc); RNA_def_struct_sdna(srna, "bNode"); - RNA_def_struct_register_funcs(srna, "rna_NodeCustomGroup_register", "rna_Node_unregister", NULL); + RNA_def_struct_register_funcs(srna, reg_func, "rna_Node_unregister", NULL); def_group(srna); } @@ -8616,7 +8670,9 @@ void RNA_def_nodetree(BlenderRNA *brna) define_specific_node(brna, "ShaderNodeGroup", "ShaderNode", "Group", "", def_group); define_specific_node(brna, "CompositorNodeGroup", "CompositorNode", "Group", "", def_group); define_specific_node(brna, "TextureNodeGroup", "TextureNode", "Group", "", def_group); - def_custom_group(brna); + def_custom_group(brna, "ShaderNodeCustomGroup", "ShaderNode", "Shader Custom Group", "Custom Shader Group Node for Python nodes", "rna_ShaderNodeCustomGroup_register"); + def_custom_group(brna, "CompositorNodeCustomGroup", "CompositorNode", "Compositor Custom Group", "Custom Compositor Group Node for Python nodes", "rna_CompositorNodeCustomGroup_register"); + def_custom_group(brna, "NodeCustomGroup", "Node", "Custom Group", "Base node type for custom registered node group types", "rna_NodeCustomGroup_register"); /* special socket types */ rna_def_cmp_output_file_slot_file(brna); |