diff options
Diffstat (limited to 'source/blender/nodes/function/nodes')
5 files changed, 131 insertions, 5 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc index 615ad4c6733..3a145311a08 100644 --- a/source/blender/nodes/function/nodes/node_fn_boolean_math.cc +++ b/source/blender/nodes/function/nodes/node_fn_boolean_math.cc @@ -19,7 +19,7 @@ #include "RNA_enum_types.h" -#include "node_function_util.h" +#include "node_function_util.hh" static bNodeSocketTemplate fn_node_boolean_math_in[] = { {SOCK_BOOLEAN, N_("Boolean")}, @@ -50,6 +50,33 @@ static void node_boolean_math_label(bNodeTree *UNUSED(ntree), bNode *node, char BLI_strncpy(label, IFACE_(name), maxlen); } +static const blender::fn::MultiFunction &get_multi_function(bNode &bnode) +{ + static blender::fn::CustomMF_SI_SI_SO<bool, bool, bool> and_fn{ + "And", [](bool a, bool b) { return a && b; }}; + static blender::fn::CustomMF_SI_SI_SO<bool, bool, bool> or_fn{ + "Or", [](bool a, bool b) { return a || b; }}; + static blender::fn::CustomMF_SI_SO<bool, bool> not_fn{"Not", [](bool a) { return !a; }}; + + switch (bnode.custom1) { + case NODE_BOOLEAN_MATH_AND: + return and_fn; + case NODE_BOOLEAN_MATH_OR: + return or_fn; + case NODE_BOOLEAN_MATH_NOT: + return not_fn; + } + + BLI_assert(false); + return blender::fn::dummy_multi_function; +} + +static void node_boolean_expand_in_mf_network(blender::bke::NodeMFNetworkBuilder &builder) +{ + const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode()); + builder.set_matching_fn(fn); +} + void register_node_type_fn_boolean_math() { static bNodeType ntype; @@ -58,5 +85,6 @@ void register_node_type_fn_boolean_math() node_type_socket_templates(&ntype, fn_node_boolean_math_in, fn_node_boolean_math_out); node_type_label(&ntype, node_boolean_math_label); node_type_update(&ntype, node_boolean_math_update); + ntype.expand_in_mf_network = node_boolean_expand_in_mf_network; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_combine_strings.cc b/source/blender/nodes/function/nodes/node_fn_combine_strings.cc index 1b6091451d9..a880933bc12 100644 --- a/source/blender/nodes/function/nodes/node_fn_combine_strings.cc +++ b/source/blender/nodes/function/nodes/node_fn_combine_strings.cc @@ -1,4 +1,20 @@ -#include "node_function_util.h" +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "node_function_util.hh" static bNodeSocketTemplate fn_node_combine_strings_in[] = { {SOCK_STRING, N_("A")}, @@ -11,11 +27,20 @@ static bNodeSocketTemplate fn_node_combine_strings_out[] = { {-1, ""}, }; +static void fn_node_combine_strings_expand_in_mf_network( + blender::bke::NodeMFNetworkBuilder &builder) +{ + static blender::fn::CustomMF_SI_SI_SO<std::string, std::string, std::string> combine_fn{ + "Combine Strings", [](const std::string &a, const std::string &b) { return a + b; }}; + builder.set_matching_fn(combine_fn); +} + void register_node_type_fn_combine_strings() { static bNodeType ntype; fn_node_type_base(&ntype, FN_NODE_COMBINE_STRINGS, "Combine Strings", 0, 0); node_type_socket_templates(&ntype, fn_node_combine_strings_in, fn_node_combine_strings_out); + ntype.expand_in_mf_network = fn_node_combine_strings_expand_in_mf_network; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_float_compare.cc b/source/blender/nodes/function/nodes/node_fn_float_compare.cc index 9788402850b..fb2c4d88caf 100644 --- a/source/blender/nodes/function/nodes/node_fn_float_compare.cc +++ b/source/blender/nodes/function/nodes/node_fn_float_compare.cc @@ -14,12 +14,14 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <cmath> + #include "BLI_listbase.h" #include "BLI_string.h" #include "RNA_enum_types.h" -#include "node_function_util.h" +#include "node_function_util.hh" static bNodeSocketTemplate fn_node_float_compare_in[] = { {SOCK_FLOAT, N_("A"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f}, @@ -54,6 +56,46 @@ static void node_float_compare_label(bNodeTree *UNUSED(ntree), BLI_strncpy(label, IFACE_(name), maxlen); } +static const blender::fn::MultiFunction &get_multi_function(bNode &node) +{ + static blender::fn::CustomMF_SI_SI_SO<float, float, bool> less_than_fn{ + "Less Than", [](float a, float b) { return a < b; }}; + static blender::fn::CustomMF_SI_SI_SO<float, float, bool> less_equal_fn{ + "Less Equal", [](float a, float b) { return a <= b; }}; + static blender::fn::CustomMF_SI_SI_SO<float, float, bool> greater_than_fn{ + "Greater Than", [](float a, float b) { return a > b; }}; + static blender::fn::CustomMF_SI_SI_SO<float, float, bool> greater_equal_fn{ + "Greater Equal", [](float a, float b) { return a >= b; }}; + static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, bool> equal_fn{ + "Equal", [](float a, float b, float epsilon) { return std::abs(a - b) <= epsilon; }}; + static blender::fn::CustomMF_SI_SI_SI_SO<float, float, float, bool> not_equal_fn{ + "Not Equal", [](float a, float b, float epsilon) { return std::abs(a - b) > epsilon; }}; + + switch (node.custom1) { + case NODE_FLOAT_COMPARE_LESS_THAN: + return less_than_fn; + case NODE_FLOAT_COMPARE_LESS_EQUAL: + return less_equal_fn; + case NODE_FLOAT_COMPARE_GREATER_THAN: + return greater_than_fn; + case NODE_FLOAT_COMPARE_GREATER_EQUAL: + return greater_equal_fn; + case NODE_FLOAT_COMPARE_EQUAL: + return equal_fn; + case NODE_FLOAT_COMPARE_NOT_EQUAL: + return not_equal_fn; + } + + BLI_assert(false); + return blender::fn::dummy_multi_function; +} + +static void node_float_compare_expand_in_mf_network(blender::bke::NodeMFNetworkBuilder &builder) +{ + const blender::fn::MultiFunction &fn = get_multi_function(builder.bnode()); + builder.set_matching_fn(fn); +} + void register_node_type_fn_float_compare() { static bNodeType ntype; @@ -62,5 +104,6 @@ void register_node_type_fn_float_compare() node_type_socket_templates(&ntype, fn_node_float_compare_in, fn_node_float_compare_out); node_type_label(&ntype, node_float_compare_label); node_type_update(&ntype, node_float_compare_update); + ntype.expand_in_mf_network = node_float_compare_expand_in_mf_network; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_group_instance_id.cc b/source/blender/nodes/function/nodes/node_fn_group_instance_id.cc index 2ac86ee2407..c61c941ee0d 100644 --- a/source/blender/nodes/function/nodes/node_fn_group_instance_id.cc +++ b/source/blender/nodes/function/nodes/node_fn_group_instance_id.cc @@ -1,15 +1,45 @@ -#include "node_function_util.h" +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "node_function_util.hh" static bNodeSocketTemplate fn_node_group_instance_id_out[] = { {SOCK_STRING, N_("Identifier")}, {-1, ""}, }; +static void fn_node_group_instance_id_expand_in_mf_network( + blender::bke::NodeMFNetworkBuilder &builder) +{ + const blender::bke::DNode &node = builder.dnode(); + std::string id = "/"; + for (const blender::bke::DParentNode *parent = node.parent(); parent; + parent = parent->parent()) { + id = "/" + parent->node_ref().name() + id; + } + builder.construct_and_set_matching_fn<blender::fn::CustomMF_Constant<std::string>>( + std::move(id)); +} + void register_node_type_fn_group_instance_id() { static bNodeType ntype; fn_node_type_base(&ntype, FN_NODE_GROUP_INSTANCE_ID, "Group Instance ID", 0, 0); node_type_socket_templates(&ntype, nullptr, fn_node_group_instance_id_out); + ntype.expand_in_mf_network = fn_node_group_instance_id_expand_in_mf_network; nodeRegisterType(&ntype); } diff --git a/source/blender/nodes/function/nodes/node_fn_switch.cc b/source/blender/nodes/function/nodes/node_fn_switch.cc index cb721058875..281ddb05c76 100644 --- a/source/blender/nodes/function/nodes/node_fn_switch.cc +++ b/source/blender/nodes/function/nodes/node_fn_switch.cc @@ -15,7 +15,7 @@ */ #include "BLI_listbase.h" -#include "node_function_util.h" +#include "node_function_util.hh" static bNodeSocketTemplate fn_node_switch_in[] = { {SOCK_BOOLEAN, N_("Switch")}, |