[Bf-blender-cvs] [01fb8a555bd] master: Nodes: Improve search weights for mix node sockets
Hans Goudey
noreply at git.blender.org
Thu Dec 8 18:59:18 CET 2022
Commit: 01fb8a555bdc49ec4d8bbbb63174e5bd832623d7
Author: Hans Goudey
Date: Thu Dec 8 11:03:10 2022 -0600
Branches: master
https://developer.blender.org/rB01fb8a555bdc49ec4d8bbbb63174e5bd832623d7
Nodes: Improve search weights for mix node sockets
Based on feedback from Simon Thommes, for link-drag-serach it's most
useful to have the A and B sockets connected, first, then the factor
sockets, then the special color mix operations. This addresses that by
adding the search items in order and decrementing a weight manually
as items are added.
===================================================================
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 f7548452e9f..68344153591 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mix.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_mix.cc
@@ -158,17 +158,7 @@ static void node_mix_gather_link_searches(GatherLinkSearchOpParams ¶ms)
return;
}
- 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);
- }
- }
-
+ int weight = 0;
if (params.in_out() == SOCK_OUT) {
params.add_item(IFACE_("Result"), [type](LinkSearchOpParams ¶ms) {
bNode &node = params.add_node("ShaderNodeMix");
@@ -177,29 +167,58 @@ static void node_mix_gather_link_searches(GatherLinkSearchOpParams ¶ms)
});
}
else {
+ 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");
+ },
+ weight);
+ weight--;
+ 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");
+ },
+ weight);
+ weight--;
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 = 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 (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");
+ },
+ weight);
+ weight--;
+ }
+ 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");
+ },
+ weight);
+ weight--;
+ }
+
+ if (type != SOCK_RGBA) {
+ weight--;
+ }
+ 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);
}
- 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