Commit: 8dbbac43bb38442e69e8dcd6a02c424ffb7855df Author: Jacques Lucke Date: Mon Apr 20 15:27:12 2020 +0200 Branches: master https://developer.blender.org/rB8dbbac43bb38442e69e8dcd6a02c424ffb7855df
Simulations: Add Boolean Math, Switch and Float Compare node UI Reviewers: brecht Differential Revision: https://developer.blender.org/D7424 =================================================================== M release/scripts/startup/nodeitems_builtins.py M source/blender/blenkernel/BKE_node.h M source/blender/blenkernel/intern/node.c M source/blender/editors/space_node/drawnode.c M source/blender/makesdna/DNA_node_types.h M source/blender/makesrna/RNA_access.h M source/blender/makesrna/RNA_enum_types.h M source/blender/makesrna/intern/rna_nodetree.c M source/blender/nodes/CMakeLists.txt A source/blender/nodes/NOD_function.h M source/blender/nodes/NOD_static_types.h A source/blender/nodes/function/node_function_util.cc A source/blender/nodes/function/node_function_util.h A source/blender/nodes/function/nodes/node_fn_boolean_math.cc A source/blender/nodes/function/nodes/node_fn_float_compare.cc A source/blender/nodes/function/nodes/node_fn_switch.cc =================================================================== diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index fd601035288..fd169027c76 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -524,6 +524,9 @@ simulation_node_categories = [ NodeItem("ShaderNodeCombineXYZ"), NodeItem("ShaderNodeSeparateHSV"), NodeItem("ShaderNodeCombineHSV"), + NodeItem("FunctionNodeBooleanMath"), + NodeItem("FunctionNodeFloatCompare"), + NodeItem("FunctionNodeSwitch"), ]), SimulationNodeCategory("SIM_GROUP", "Group", items=node_group_items), SimulationNodeCategory("SIM_LAYOUT", "Layout", items=[ diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 38bf3d828f7..ea2a84f14f9 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -1302,6 +1302,16 @@ int ntreeTexExecTree(struct bNodeTree *ntree, /** \} */ +/* -------------------------------------------------------------------- */ +/** \name Function Nodes + * \{ */ + +#define FN_NODE_BOOLEAN_MATH 1200 +#define FN_NODE_SWITCH 1201 +#define FN_NODE_FLOAT_COMPARE 1202 + +/** \} */ + void init_nodesystem(void); void free_nodesystem(void); diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 2237d061fe1..6c67ff14dac 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -67,6 +67,7 @@ #include "NOD_common.h" #include "NOD_composite.h" +#include "NOD_function.h" #include "NOD_shader.h" #include "NOD_simulation.h" #include "NOD_socket.h" @@ -4242,6 +4243,13 @@ static void registerSimulationNodes(void) register_node_type_sim_particle_attribute(); } +static void registerFunctionNodes(void) +{ + register_node_type_fn_boolean_math(); + register_node_type_fn_float_compare(); + register_node_type_fn_switch(); +} + void init_nodesystem(void) { nodetreetypes_hash = BLI_ghash_str_new("nodetreetypes_hash gh"); @@ -4266,6 +4274,7 @@ void init_nodesystem(void) registerShaderNodes(); registerTextureNodes(); registerSimulationNodes(); + registerFunctionNodes(); } void free_nodesystem(void) diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 4670f0fc6f6..70f3db1e2ab 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -3179,6 +3179,40 @@ static void node_simulation_set_butfunc(bNodeType *ntype) } } +/* ****************** BUTTON CALLBACKS FOR FUNCTION NODES ***************** */ + +static void node_function_buts_boolean_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); +} + +static void node_function_buts_float_compare(uiLayout *layout, + bContext *UNUSED(C), + PointerRNA *ptr) +{ + uiItemR(layout, ptr, "operation", 0, "", ICON_NONE); +} + +static void node_function_buts_switch(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) +{ + uiItemR(layout, ptr, "data_type", 0, "", ICON_NONE); +} + +static void node_function_set_butfunc(bNodeType *ntype) +{ + switch (ntype->type) { + case FN_NODE_BOOLEAN_MATH: + ntype->draw_buttons = node_function_buts_boolean_math; + break; + case FN_NODE_FLOAT_COMPARE: + ntype->draw_buttons = node_function_buts_float_compare; + break; + case FN_NODE_SWITCH: + ntype->draw_buttons = node_function_buts_switch; + break; + } +} + /* ****** init draw callbacks for all tree types, only called in usiblender.c, once ************ */ static void node_property_update_default(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) @@ -3288,6 +3322,7 @@ void ED_node_init_butfuncs(void) node_shader_set_butfunc(ntype); node_texture_set_butfunc(ntype); node_simulation_set_butfunc(ntype); + node_function_set_butfunc(ntype); /* define update callbacks for socket properties */ node_template_properties_update(ntype); diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 81911116b66..4ff0e531168 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -1308,6 +1308,23 @@ enum { NODE_VECTOR_MATH_TANGENT = 23, }; +/* Boolean math node operations. */ +enum { + NODE_BOOLEAN_MATH_AND = 0, + NODE_BOOLEAN_MATH_OR = 1, + NODE_BOOLEAN_MATH_NOT = 2, +}; + +/* Float compare node operations. */ +enum { + NODE_FLOAT_COMPARE_LESS_THAN = 0, + NODE_FLOAT_COMPARE_LESS_EQUAL = 1, + NODE_FLOAT_COMPARE_GREATER_THAN = 2, + NODE_FLOAT_COMPARE_GREATER_EQUAL = 3, + NODE_FLOAT_COMPARE_EQUAL = 4, + NODE_FLOAT_COMPARE_NOT_EQUAL = 5, +}; + /* Clamp node types. */ enum { NODE_CLAMP_MINMAX = 0, diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index a77d07dfe17..d2e27bdbcad 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -259,6 +259,7 @@ extern StructRNA RNA_FreestyleLineStyle; extern StructRNA RNA_FreestyleModuleSettings; extern StructRNA RNA_FreestyleSettings; extern StructRNA RNA_Function; +extern StructRNA RNA_FunctionNode; extern StructRNA RNA_GPencilFrame; extern StructRNA RNA_GPencilInterpolateSettings; extern StructRNA RNA_GPencilLayer; diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h index fef98f9da4b..b2f9c90b7f5 100644 --- a/source/blender/makesrna/RNA_enum_types.h +++ b/source/blender/makesrna/RNA_enum_types.h @@ -191,6 +191,8 @@ extern const EnumPropertyItem rna_enum_node_socket_in_out_items[]; extern const EnumPropertyItem rna_enum_node_math_items[]; extern const EnumPropertyItem rna_enum_mapping_type_items[]; extern const EnumPropertyItem rna_enum_node_vec_math_items[]; +extern const EnumPropertyItem rna_enum_node_boolean_math_items[]; +extern const EnumPropertyItem rna_enum_node_float_compare_items[]; extern const EnumPropertyItem rna_enum_node_filter_items[]; extern const EnumPropertyItem rna_enum_node_map_range_items[]; extern const EnumPropertyItem rna_enum_node_clamp_items[]; diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 0c4583983a8..9242ad7237f 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -101,6 +101,18 @@ static const EnumPropertyItem particle_attribute_socket_type_items[] = { {0, NULL, 0, NULL, NULL}, }; +static const EnumPropertyItem node_socket_data_type_items[] = { + {SOCK_FLOAT, "FLOAT", 0, "Float", ""}, + {SOCK_INT, "INT", 0, "Int", ""}, + {SOCK_BOOLEAN, "BOOLEAN", 0, "Boolean", ""}, + {SOCK_VECTOR, "VECTOR", 0, "Vector", ""}, + {SOCK_STRING, "STRING", 0, "String", ""}, + {SOCK_RGBA, "RGBA", 0, "Color", ""}, + {SOCK_OBJECT, "OBJECT", 0, "Object", ""}, + {SOCK_IMAGE, "IMAGE", 0, "Image", ""}, + {0, NULL, 0, NULL, NULL}, +}; + static const EnumPropertyItem node_quality_items[] = { {NTREE_QUALITY_HIGH, "HIGH", 0, "High", "High quality"}, {NTREE_QUALITY_MEDIUM, "MEDIUM", 0, "Medium", "Medium quality"}, @@ -261,6 +273,47 @@ const EnumPropertyItem rna_enum_node_vec_math_items[] = { {0, NULL, 0, NULL, NULL}, }; +const EnumPropertyItem rna_enum_node_boolean_math_items[] = { + {NODE_BOOLEAN_MATH_AND, "AND", 0, "And", "Outputs true only when both inputs are true"}, + {NODE_BOOLEAN_MATH_OR, "OR", 0, "Or", "Outputs or when at least one of the inputs is true"}, + {NODE_BOOLEAN_MATH_NOT, "NOT", 0, "Not", "Outputs the opposite of the input"}, + {0, NULL, 0, NULL, NULL}, +}; + +const EnumPropertyItem rna_enum_node_float_compare_items[] = { + {NODE_FLOAT_COMPARE_LESS_THAN, + "LESS_THAN", + 0, + "A < B", + "True when the first input is smaller than second input"}, + {NODE_FLOAT_COMPARE_LESS_EQUAL, + "LESS_EQUAL", + 0, + "A <= B", + "True when the first input is smaller than the second input or equal"}, + {NODE_FLOAT_COMPARE_GREATER_THAN, + "GREATER_THAN", + 0, + "A > B", + "True when the first input is greater than the second input"}, + {NODE_FLOAT_COMPARE_GREATER_EQUAL, + "GREATER_EQUAL", + 0, + "A >= B", + "True when the first input is greater than the second input or equal"}, + {NODE_FLOAT_COMPARE_EQUAL, + "EQUAL", + 0, + "A = B", + "True when both inputs are approximately equal"}, + {NODE_FLOAT_COMPARE_NOT_EQUAL, + "NOT_EQUAL", + 0, + "A != B", + "True when both inputs are not approximately equal"}, + {0, NULL, 0, NULL, NULL}, +}; + const EnumPropertyItem rna_enum_node_map_range_items[] = { {NODE_MAP_RANGE_LINEAR, "LINEAR", @@ -700,6 +753,20 @@ static const EnumPropertyItem *rna_node_static_type_itemf(bContext *UNUSED(C), # undef DefNode } + if (RNA_struct_is_a(ptr->type, &RNA_FunctionNode)) { +# define DefNode(Category, ID, DefFunc, EnumName, StructName, UIName, UIDesc) \ + if (STREQ(#Category, "FunctionNode")) { \ + tmp.value = ID; \ + tmp.identifier = EnumName; \ + tmp.name = UIName; \ + tmp.description = UIDesc; \ + tmp.icon = ICON_NONE; \ + RNA_enum_item_add(&item, &totitem, &tmp); \ + } +# include "../../nodes/NOD_static_types.h" +# undef DefNode + } + RNA_enum_item_end(&item, &totitem); *r_free = true; @@ -1838,6 +1905,28 @@ static StructRNA *rna_SimulationNode_register(Main *bmain, return nt->rna_ext.srna; } +static StructRNA *rna_FunctionNode_register(Main *bmain, + ReportList *reports, + void *data, + const char *identifier, + StructValidateFunc validate, + StructCallbackFunc call, + StructFreeFunc free) +{ + bNodeType *nt = rna_Node_register_base( + @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list [email protected] https://lists.blender.org/mailman/listinfo/bf-blender-cvs
