Geometry Nodes: use dynamic declaration for switch node #113413

Merged
Hans Goudey merged 7 commits from JacquesLucke/blender:switch-dynamic-declaration into main 2023-12-13 17:33:35 +01:00
2 changed files with 56 additions and 49 deletions
Showing only changes of commit a739eeb4a5 - Show all commits

View File

@ -1021,6 +1021,35 @@ static void versioning_node_group_sort_sockets_recursive(bNodeTreeInterfacePanel
}
}
static void version_socket_identifier_suffixes_for_dynamic_types(ListBase sockets,
const char *separator)
{
LISTBASE_FOREACH (bNodeSocket *, socket, &sockets) {
if (socket->is_available()) {
if (char *pos = strstr(socket->identifier, separator)) {
/* End the identifier at the separator so that the old suffix is ignored. */
*pos = '\0';
}
}
else {
/* Rename existing identifiers so that they don't conflict with the renamed one. Those will
* be removed after versioning code. */
BLI_strncat(socket->identifier, "_deprecated", sizeof(socket->identifier));
}
}
}
static void versioning_switch_node_dynamic_socket(bNodeTree &ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree.nodes) {
if (node->type != GEO_NODE_SWITCH) {
continue;
}
version_socket_identifier_suffixes_for_dynamic_types(node->inputs, "_");
version_socket_identifier_suffixes_for_dynamic_types(node->outputs, "_");
}
}
static void enable_geometry_nodes_is_modifier(Main &bmain)
{
/* Any node group with a first socket geometry output can potentially be a modifier. Previously
@ -1697,5 +1726,11 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
*/
{
/* Keep this block, even when empty. */
LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
if (ntree->type == NTREE_GEOMETRY) {
versioning_switch_node_dynamic_socket(*ntree);
}
}
}
}

View File

@ -8,6 +8,7 @@
#include "UI_resources.hh"
#include "NOD_rna_define.hh"
#include "NOD_socket.hh"
#include "NOD_socket_search_link.hh"
#include "RNA_enum_types.hh"
@ -18,57 +19,28 @@ namespace blender::nodes::node_geo_switch_cc {
NODE_STORAGE_FUNCS(NodeSwitch)
static void node_declare(NodeDeclarationBuilder &b)
static void node_declare_dynamic(const bNodeTree & /*ntree*/,

Is there the chance to note the type of value in anythere?

Is there the chance to note the type of value in anythere?
const bNode &node,
NodeDeclarationBuilder &b)
{
b.add_input<decl::Bool>("Switch").default_value(false).supports_field();
b.add_input<decl::Bool>("Switch", "Switch_001").default_value(false);
const NodeSwitch &storage = node_storage(node);
const eNodeSocketDatatype socket_type = eNodeSocketDatatype(storage.input_type);
const bool supports_field = socket_type_supports_fields(socket_type);
b.add_input<decl::Float>("False").supports_field();
b.add_input<decl::Float>("True").supports_field();
b.add_input<decl::Int>("False", "False_001").min(-100000).max(100000).supports_field();
b.add_input<decl::Int>("True", "True_001").min(-100000).max(100000).supports_field();
b.add_input<decl::Bool>("False", "False_002").default_value(false).hide_value().supports_field();
b.add_input<decl::Bool>("True", "True_002").default_value(true).hide_value().supports_field();
b.add_input<decl::Vector>("False", "False_003").supports_field();
b.add_input<decl::Vector>("True", "True_003").supports_field();
auto &switch_decl = b.add_input<decl::Bool>("Switch").default_value(false);
auto &false_decl = b.add_input(socket_type, "False");
auto &true_decl = b.add_input(socket_type, "True");
auto &output_decl = b.add_output(socket_type, "Output");
b.add_input<decl::Color>("False", "False_004")
.default_value({0.8f, 0.8f, 0.8f, 1.0f})
.supports_field();
b.add_input<decl::Color>("True", "True_004")
.default_value({0.8f, 0.8f, 0.8f, 1.0f})
.supports_field();
b.add_input<decl::String>("False", "False_005").supports_field();
b.add_input<decl::String>("True", "True_005").supports_field();
b.add_input<decl::Geometry>("False", "False_006");
b.add_input<decl::Geometry>("True", "True_006");
b.add_input<decl::Object>("False", "False_007");
b.add_input<decl::Object>("True", "True_007");
b.add_input<decl::Collection>("False", "False_008");
b.add_input<decl::Collection>("True", "True_008");
b.add_input<decl::Texture>("False", "False_009");
b.add_input<decl::Texture>("True", "True_009");
b.add_input<decl::Material>("False", "False_010");
b.add_input<decl::Material>("True", "True_010");
b.add_input<decl::Image>("False", "False_011");
b.add_input<decl::Image>("True", "True_011");
b.add_input<decl::Rotation>("False", "False_012").supports_field();
b.add_input<decl::Rotation>("True", "True_012").supports_field();
b.add_output<decl::Float>("Output").dependent_field().reference_pass_all();
b.add_output<decl::Int>("Output", "Output_001").dependent_field().reference_pass_all();
b.add_output<decl::Bool>("Output", "Output_002").dependent_field().reference_pass_all();
b.add_output<decl::Vector>("Output", "Output_003").dependent_field().reference_pass_all();
b.add_output<decl::Color>("Output", "Output_004").dependent_field().reference_pass_all();
b.add_output<decl::String>("Output", "Output_005").dependent_field().reference_pass_all();
b.add_output<decl::Geometry>("Output", "Output_006").propagate_all();
b.add_output<decl::Object>("Output", "Output_007");
b.add_output<decl::Collection>("Output", "Output_008");
b.add_output<decl::Texture>("Output", "Output_009");
b.add_output<decl::Material>("Output", "Output_010");
b.add_output<decl::Image>("Output", "Output_011");
b.add_output<decl::Rotation>("Output", "Output_012").propagate_all().reference_pass_all();
if (supports_field) {
switch_decl.supports_field();
false_decl.supports_field();
true_decl.supports_field();
output_decl.dependent_field().reference_pass_all();
}
if (socket_type == SOCK_GEOMETRY) {
output_decl.propagate_all();
}
}
static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
@ -311,7 +283,7 @@ static void register_node()
static bNodeType ntype;
geo_node_type_base(&ntype, GEO_NODE_SWITCH, "Switch", NODE_CLASS_CONVERTER);
ntype.declare = node_declare;
ntype.declare_dynamic = node_declare_dynamic;
ntype.initfunc = node_init;
ntype.updatefunc = node_update;
node_type_storage(&ntype, "NodeSwitch", node_free_standard_storage, node_copy_standard_storage);