[Bf-blender-cvs] [b20e89f69c4] master: Cleanup: Return early in mix node link-drag-search
Hans Goudey
noreply at git.blender.org
Thu Dec 8 18:59:18 CET 2022
Commit: b20e89f69c4c6a97a79fb7e8eb2a28e76dd28430
Author: Hans Goudey
Date: Thu Dec 8 10:46:41 2022 -0600
Branches: master
https://developer.blender.org/rBb20e89f69c4c6a97a79fb7e8eb2a28e76dd28430
Cleanup: Return early in mix node link-drag-search
Also simplify the handling for different socket types a bit.
===================================================================
M source/blender/nodes/shader/nodes/node_shader_mix.cc
===================================================================
diff --git a/source/blender/nodes/shader/nodes/node_shader_mix.cc b/source/blender/nodes/shader/nodes/node_shader_mix.cc
index 6c627052005..f7548452e9f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mix.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mix.cc
@@ -141,56 +141,65 @@ class SocketSearchOp {
static void node_mix_gather_link_searches(GatherLinkSearchOpParams ¶ms)
{
- const eNodeSocketDatatype sock_type = static_cast<eNodeSocketDatatype>(
- params.other_socket().type);
-
- if (ELEM(sock_type, SOCK_BOOLEAN, SOCK_FLOAT, SOCK_RGBA, SOCK_VECTOR, SOCK_INT)) {
- const eNodeSocketDatatype type = ELEM(sock_type, SOCK_BOOLEAN, SOCK_INT) ? SOCK_FLOAT :
- sock_type;
-
- const int weight = ELEM(params.other_socket().type, SOCK_RGBA) ? 0 : -1;
- const std::string socket_name = params.in_out() == SOCK_IN ? "A" : "Result";
- for (const EnumPropertyItem *item = rna_enum_ramp_blend_items; item->identifier != nullptr;
- item++) {
- if (item->name != nullptr && item->identifier[0] != '\0') {
- params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
- SocketSearchOp{socket_name, item->value},
- weight);
- }
- }
+ eNodeSocketDatatype type;
+ switch (eNodeSocketDatatype(params.other_socket().type)) {
+ case SOCK_BOOLEAN:
+ case SOCK_INT:
+ case SOCK_FLOAT:
+ type = SOCK_FLOAT;
+ break;
+ case SOCK_VECTOR:
+ type = SOCK_VECTOR;
+ break;
+ case SOCK_RGBA:
+ type = SOCK_RGBA;
+ break;
+ default:
+ return;
+ }
- if (params.in_out() == SOCK_OUT) {
- params.add_item(IFACE_("Result"), [type](LinkSearchOpParams ¶ms) {
- bNode &node = params.add_node("ShaderNodeMix");
- node_storage(node).data_type = type;
- params.update_and_connect_available_socket(node, "Result");
- });
+ const int weight = ELEM(params.other_socket().type, SOCK_RGBA) ? 0 : -1;
+ const std::string socket_name = params.in_out() == SOCK_IN ? "A" : "Result";
+ for (const EnumPropertyItem *item = rna_enum_ramp_blend_items; item->identifier != nullptr;
+ item++) {
+ if (item->name != nullptr && item->identifier[0] != '\0') {
+ params.add_item(CTX_IFACE_(BLT_I18NCONTEXT_ID_NODETREE, item->name),
+ SocketSearchOp{socket_name, item->value},
+ weight);
}
- else {
- if (ELEM(sock_type, SOCK_VECTOR, SOCK_RGBA)) {
- params.add_item(IFACE_("Factor (Non-Uniform)"), [](LinkSearchOpParams ¶ms) {
- bNode &node = params.add_node("ShaderNodeMix");
- node_storage(node).data_type = SOCK_VECTOR;
- node_storage(node).factor_mode = NODE_MIX_MODE_NON_UNIFORM;
- params.update_and_connect_available_socket(node, "Factor");
- });
- }
- params.add_item(IFACE_("Factor"), [type](LinkSearchOpParams ¶ms) {
+ }
+
+ if (params.in_out() == SOCK_OUT) {
+ params.add_item(IFACE_("Result"), [type](LinkSearchOpParams ¶ms) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "Result");
+ });
+ }
+ else {
+ if (ELEM(type, SOCK_VECTOR, SOCK_RGBA)) {
+ params.add_item(IFACE_("Factor (Non-Uniform)"), [](LinkSearchOpParams ¶ms) {
bNode &node = params.add_node("ShaderNodeMix");
- node_storage(node).data_type = type;
+ node_storage(node).data_type = SOCK_VECTOR;
+ node_storage(node).factor_mode = NODE_MIX_MODE_NON_UNIFORM;
params.update_and_connect_available_socket(node, "Factor");
});
- params.add_item(IFACE_("A"), [type](LinkSearchOpParams ¶ms) {
- bNode &node = params.add_node("ShaderNodeMix");
- node_storage(node).data_type = type;
- params.update_and_connect_available_socket(node, "A");
- });
- params.add_item(IFACE_("B"), [type](LinkSearchOpParams ¶ms) {
- bNode &node = params.add_node("ShaderNodeMix");
- node_storage(node).data_type = type;
- params.update_and_connect_available_socket(node, "B");
- });
}
+ params.add_item(IFACE_("Factor"), [type](LinkSearchOpParams ¶ms) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "Factor");
+ });
+ params.add_item(IFACE_("A"), [type](LinkSearchOpParams ¶ms) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "A");
+ });
+ params.add_item(IFACE_("B"), [type](LinkSearchOpParams ¶ms) {
+ bNode &node = params.add_node("ShaderNodeMix");
+ node_storage(node).data_type = type;
+ params.update_and_connect_available_socket(node, "B");
+ });
}
}
More information about the Bf-blender-cvs
mailing list