Fix T91826: Inconsistent node socket name identifier separator

Previously both `.` and `_` were used as separators when finding
a unique name for a socket. This removes the use of `.`, since `_`
was more common. It also does versioning for all of a file's node
trees to make sure that they all use the `_` convention.

Differential Revision: https://developer.blender.org/D13181
This commit is contained in:
Hans Goudey 2021-11-12 12:22:43 -06:00
parent cbca71a7cf
commit d845ba481c
4 changed files with 49 additions and 2 deletions

View File

@ -1542,7 +1542,7 @@ static bNodeSocket *make_socket(bNodeTree *ntree,
}
/* make the identifier unique */
BLI_uniquename_cb(
unique_identifier_check, lb, "socket", '.', auto_identifier, sizeof(auto_identifier));
unique_identifier_check, lb, "socket", '_', auto_identifier, sizeof(auto_identifier));
bNodeSocket *sock = (bNodeSocket *)MEM_callocN(sizeof(bNodeSocket), "sock");
sock->in_out = in_out;

View File

@ -783,7 +783,6 @@ void do_versions_after_linking_300(Main *bmain, ReportList *UNUSED(reports))
*/
{
/* Keep this block, even when empty. */
}
}
@ -1273,6 +1272,18 @@ static void version_geometry_nodes_set_position_node_offset(bNodeTree *ntree)
}
}
static void version_node_tree_socket_id_delim(bNodeTree *ntree)
{
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) {
version_node_socket_id_delim(socket);
}
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
version_node_socket_id_delim(socket);
}
}
}
/* NOLINTNEXTLINE: readability-function-size */
void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
{
@ -2160,5 +2171,12 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain)
*/
{
/* Keep this block, even when empty. */
FOREACH_NODETREE_BEGIN (bmain, ntree, id) {
if (ntree->type != NTREE_CUSTOM) {
version_node_tree_socket_id_delim(ntree);
}
}
FOREACH_NODETREE_END;
}
}

View File

@ -27,6 +27,7 @@
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_ref.hh"
#include "BKE_animsys.h"
#include "BKE_lib_id.h"
@ -37,6 +38,8 @@
#include "versioning_common.h"
using blender::StringRef;
ARegion *do_versions_add_region_if_not_found(ListBase *regionbase,
int region_type,
const char *name,
@ -101,6 +104,30 @@ static void change_node_socket_name(ListBase *sockets, const char *old_name, con
}
}
/**
* Convert `SocketName.001` unique name format to `SocketName_001`. Previously both were used.
*/
void version_node_socket_id_delim(bNodeSocket *socket)
{
StringRef name = socket->name;
StringRef id = socket->identifier;
if (!id.startswith(name)) {
/* We only need to affect the case where the identifier starts with the name. */
return;
}
StringRef id_number = id.drop_known_prefix(name);
if (id_number.is_empty()) {
/* The name was already unique, and didn't need numbers at the end for the id. */
return;
}
if (id_number.startswith(".")) {
socket->identifier[name.size()] = '_';
}
}
void version_node_socket_name(bNodeTree *ntree,
const int node_type,
const char *old_name,

View File

@ -62,6 +62,8 @@ void version_node_socket_index_animdata(
void version_node_id(struct bNodeTree *ntree, const int node_type, const char *new_name);
void version_node_socket_id_delim(bNodeSocket *socket);
#ifdef __cplusplus
}
#endif