Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenloader/intern/versioning_common.cc
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup blenloader | * \ingroup blenloader | ||||
| */ | */ | ||||
| /* allow readfile to use deprecated functionality */ | /* allow readfile to use deprecated functionality */ | ||||
| #define DNA_DEPRECATED_ALLOW | #define DNA_DEPRECATED_ALLOW | ||||
| #include <cstring> | #include <cstring> | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "DNA_screen_types.h" | #include "DNA_screen_types.h" | ||||
| #include "BLI_array.hh" | |||||
| #include "BLI_index_range.hh" | |||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_map.hh" | #include "BLI_map.hh" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_ref.hh" | #include "BLI_string_ref.hh" | ||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_attribute.hh" | |||||
| #include "BKE_attribute_math.hh" | |||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_main_namemap.h" | #include "BKE_main_namemap.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "versioning_common.h" | #include "versioning_common.h" | ||||
| ▲ Show 20 Lines • Show All 216 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree.links) { | LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree.links) { | ||||
| if (link->tonode == &old_node) { | if (link->tonode == &old_node) { | ||||
| bNodeSocket *old_socket = link->tosock; | bNodeSocket *old_socket = link->tosock; | ||||
| if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) { | if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) { | ||||
| bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_IN, new_identifier->c_str()); | bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_IN, new_identifier->c_str()); | ||||
| link->tonode = &new_node; | link->tonode = &new_node; | ||||
| link->tosock = new_socket; | link->tosock = new_socket; | ||||
| old_socket->link = nullptr; | old_socket->link = nullptr; | ||||
HooglyBoogly: I think this is a prefix rather than a suffix | |||||
| } | } | ||||
| } | } | ||||
| if (link->fromnode == &old_node) { | if (link->fromnode == &old_node) { | ||||
| bNodeSocket *old_socket = link->fromsock; | bNodeSocket *old_socket = link->fromsock; | ||||
| if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) { | if (const std::string *new_identifier = map.lookup_ptr_as(old_socket->identifier)) { | ||||
| bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_OUT, new_identifier->c_str()); | bNodeSocket *new_socket = nodeFindSocket(&new_node, SOCK_OUT, new_identifier->c_str()); | ||||
| link->fromnode = &new_node; | link->fromnode = &new_node; | ||||
| link->fromsock = new_socket; | link->fromsock = new_socket; | ||||
| old_socket->link = nullptr; | old_socket->link = nullptr; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* param: inout: true: input, false: output. */ | |||||
| void sockets_change_type_identifier_names(bNodeSocket *socket, int node_type, bool inout) | |||||
| { | |||||
| blender::Array<std::string> names = blender::Array<std::string>({ | |||||
| "Value_" + blender::bke::type_name_identifier<blender::float3>(), | |||||
| "Value_" + blender::bke::type_name_identifier<float>(), | |||||
| "Value_" + blender::bke::type_name_identifier<blender::ColorGeometry4f>(), | |||||
| "Value_" + blender::bke::type_name_identifier<bool>(), | |||||
| "Value_" + blender::bke::type_name_identifier<int>(), | |||||
| }); | |||||
| switch (node_type) { | |||||
| case (GEO_NODE_CAPTURE_ATTRIBUTE): { | |||||
| /* First typed socket. */ | |||||
| socket = socket->next; | |||||
| break; | |||||
| } | |||||
| case (GEO_NODE_RAYCAST): { | |||||
| /* First typed socket. */ | |||||
| socket = socket->next; | |||||
| if (!inout) { | |||||
| socket = socket->next->next->next; | |||||
| } | |||||
| break; | |||||
| } | |||||
| default: { | |||||
| return; | |||||
| } | |||||
| } | |||||
| for (const std::string &name : names.as_span().drop_back(1)) { | |||||
| STRNCPY(socket->identifier, name.c_str()); | |||||
| socket = socket->next; | |||||
| } | |||||
| STRNCPY(socket->identifier, names.last().c_str()); | |||||
| } | |||||
| void node_switch_sockets_change_type_identifier_names(bNodeSocket *socket, | |||||
| const bool double_step, | |||||
| const std::string prefix) | |||||
| { | |||||
| blender::Array<std::string> names({ | |||||
| prefix + blender::bke::type_name_identifier<float>(), | |||||
| prefix + blender::bke::type_name_identifier<int>(), | |||||
| prefix + blender::bke::type_name_identifier<bool>(), | |||||
| prefix + blender::bke::type_name_identifier<blender::float3>(), | |||||
| prefix + blender::bke::type_name_identifier<blender::ColorGeometry4f>(), | |||||
| prefix + blender::bke::type_name_identifier<std::string>(), | |||||
| prefix + "Geometry", | |||||
| prefix + "Object", | |||||
| prefix + "Collection", | |||||
| prefix + "Texture", | |||||
| prefix + "Material", | |||||
| prefix + "Image", | |||||
| }); | |||||
| for (const std::string &name : names.as_span().drop_back(1)) { | |||||
| STRNCPY(socket->identifier, name.c_str()); | |||||
| socket = socket->next; | |||||
| if (double_step) { | |||||
| socket = socket->next; | |||||
| } | |||||
| } | |||||
| STRNCPY(socket->identifier, names.last().c_str()); | |||||
| } | |||||
| /* param: inout: true: in, false: out. */ | |||||
| void version_node_socket_attribute_type_name_inout(bNodeSocket *socket, int node_type, bool inout) | |||||
| { | |||||
| if (inout) { | |||||
| if (node_type == GEO_NODE_SWITCH) { | |||||
| STRNCPY(socket->identifier, "Switch_Field"); | |||||
| socket = socket->next; | |||||
| STRNCPY(socket->identifier, "Switch_Single"); | |||||
| socket = socket->next; | |||||
| node_switch_sockets_change_type_identifier_names(socket, true, "False_"); | |||||
| node_switch_sockets_change_type_identifier_names(socket->next, true, "True_"); | |||||
| } | |||||
| else { | |||||
| sockets_change_type_identifier_names(socket, node_type, true); | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (node_type == GEO_NODE_SWITCH) { | |||||
| node_switch_sockets_change_type_identifier_names(socket, false, ""); | |||||
| } | |||||
| else { | |||||
| sockets_change_type_identifier_names(socket, node_type, false); | |||||
| } | |||||
| } | |||||
| } | |||||
| No newline at end of file | |||||
I think this is a prefix rather than a suffix