Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_switch.cc
| Show All 22 Lines | |||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "FN_multi_function_signature.hh" | #include "FN_multi_function_signature.hh" | ||||
| namespace blender::nodes::node_geo_switch_cc { | namespace blender::nodes::node_geo_switch_cc { | ||||
| static void geo_node_switch_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Bool>(N_("Switch")).default_value(false).supports_field(); | b.add_input<decl::Bool>(N_("Switch")).default_value(false).supports_field(); | ||||
| b.add_input<decl::Bool>(N_("Switch"), "Switch_001").default_value(false); | b.add_input<decl::Bool>(N_("Switch"), "Switch_001").default_value(false); | ||||
| b.add_input<decl::Float>(N_("False")).supports_field(); | b.add_input<decl::Float>(N_("False")).supports_field(); | ||||
| b.add_input<decl::Float>(N_("True")).supports_field(); | b.add_input<decl::Float>(N_("True")).supports_field(); | ||||
| b.add_input<decl::Int>(N_("False"), "False_001").min(-100000).max(100000).supports_field(); | b.add_input<decl::Int>(N_("False"), "False_001").min(-100000).max(100000).supports_field(); | ||||
| b.add_input<decl::Int>(N_("True"), "True_001").min(-100000).max(100000).supports_field(); | b.add_input<decl::Int>(N_("True"), "True_001").min(-100000).max(100000).supports_field(); | ||||
| Show All 38 Lines | static void node_declare(NodeDeclarationBuilder &b) | ||||
| b.add_output<decl::Geometry>(N_("Output"), "Output_006"); | b.add_output<decl::Geometry>(N_("Output"), "Output_006"); | ||||
| b.add_output<decl::Object>(N_("Output"), "Output_007"); | b.add_output<decl::Object>(N_("Output"), "Output_007"); | ||||
| b.add_output<decl::Collection>(N_("Output"), "Output_008"); | b.add_output<decl::Collection>(N_("Output"), "Output_008"); | ||||
| b.add_output<decl::Texture>(N_("Output"), "Output_009"); | b.add_output<decl::Texture>(N_("Output"), "Output_009"); | ||||
| b.add_output<decl::Material>(N_("Output"), "Output_010"); | b.add_output<decl::Material>(N_("Output"), "Output_010"); | ||||
| b.add_output<decl::Image>(N_("Output"), "Output_011"); | b.add_output<decl::Image>(N_("Output"), "Output_011"); | ||||
| } | } | ||||
| static void geo_node_switch_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | ||||
| { | { | ||||
| uiItemR(layout, ptr, "input_type", 0, "", ICON_NONE); | uiItemR(layout, ptr, "input_type", 0, "", ICON_NONE); | ||||
| } | } | ||||
| static void geo_node_switch_init(bNodeTree *UNUSED(tree), bNode *node) | static void node_init(bNodeTree *UNUSED(tree), bNode *node) | ||||
| { | { | ||||
| NodeSwitch *data = (NodeSwitch *)MEM_callocN(sizeof(NodeSwitch), __func__); | NodeSwitch *data = (NodeSwitch *)MEM_callocN(sizeof(NodeSwitch), __func__); | ||||
| data->input_type = SOCK_GEOMETRY; | data->input_type = SOCK_GEOMETRY; | ||||
| node->storage = data; | node->storage = data; | ||||
| } | } | ||||
| static void geo_node_switch_update(bNodeTree *ntree, bNode *node) | static void node_update(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| NodeSwitch *node_storage = (NodeSwitch *)node->storage; | NodeSwitch *node_storage = (NodeSwitch *)node->storage; | ||||
| int index = 0; | int index = 0; | ||||
| bNodeSocket *field_switch = (bNodeSocket *)node->inputs.first; | bNodeSocket *field_switch = (bNodeSocket *)node->inputs.first; | ||||
| bNodeSocket *non_field_switch = (bNodeSocket *)field_switch->next; | bNodeSocket *non_field_switch = (bNodeSocket *)field_switch->next; | ||||
| const bool fields_type = ELEM((eNodeSocketDatatype)node_storage->input_type, | const bool fields_type = ELEM((eNodeSocketDatatype)node_storage->input_type, | ||||
| SOCK_FLOAT, | SOCK_FLOAT, | ||||
| ▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | else { | ||||
| params.set_input_unused(name_true); | params.set_input_unused(name_true); | ||||
| if (params.lazy_require_input(name_false)) { | if (params.lazy_require_input(name_false)) { | ||||
| return; | return; | ||||
| } | } | ||||
| params.set_output(name_output, params.extract_input<T>(name_false)); | params.set_output(name_output, params.extract_input<T>(name_false)); | ||||
| } | } | ||||
| } | } | ||||
| static void geo_node_switch_exec(GeoNodeExecParams params) | static void node_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| const NodeSwitch &storage = *(const NodeSwitch *)params.node().storage; | const NodeSwitch &storage = *(const NodeSwitch *)params.node().storage; | ||||
| const eNodeSocketDatatype data_type = static_cast<eNodeSocketDatatype>(storage.input_type); | const eNodeSocketDatatype data_type = static_cast<eNodeSocketDatatype>(storage.input_type); | ||||
| switch (data_type) { | switch (data_type) { | ||||
| case SOCK_FLOAT: { | case SOCK_FLOAT: { | ||||
| switch_fields<float>(params, ""); | switch_fields<float>(params, ""); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| void register_node_type_geo_switch() | void register_node_type_geo_switch() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_geo_switch_cc; | namespace file_ns = blender::nodes::node_geo_switch_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTER, 0); | geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTER, 0); | ||||
| ntype.declare = file_ns::geo_node_switch_declare; | ntype.declare = file_ns::node_declare; | ||||
| node_type_init(&ntype, file_ns::geo_node_switch_init); | node_type_init(&ntype, file_ns::node_init); | ||||
| node_type_update(&ntype, file_ns::geo_node_switch_update); | node_type_update(&ntype, file_ns::node_update); | ||||
| node_type_storage(&ntype, "NodeSwitch", node_free_standard_storage, node_copy_standard_storage); | node_type_storage(&ntype, "NodeSwitch", node_free_standard_storage, node_copy_standard_storage); | ||||
| ntype.geometry_node_execute = file_ns::geo_node_switch_exec; | ntype.geometry_node_execute = file_ns::node_exec; | ||||
| ntype.geometry_node_execute_supports_laziness = true; | ntype.geometry_node_execute_supports_laziness = true; | ||||
| ntype.draw_buttons = file_ns::geo_node_switch_layout; | ntype.draw_buttons = file_ns::node_layout; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||