Fix: MaterialX export can end up with duplicate node names

With chains of nodes with the same name.

Pull Request: https://projects.blender.org/blender/blender/pulls/145800
This commit is contained in:
Brecht Van Lommel
2025-09-05 16:36:49 +02:00
committed by Brecht Van Lommel
parent 0760b2d5aa
commit a6108f69f2
2 changed files with 7 additions and 2 deletions

View File

@@ -142,15 +142,18 @@ std::string NodeGraph::unique_node_name(const bNode *node,
}
/* Ensure the name does not conflict with other nodes in the graph, which may happen when
* another Blender node name happens to match the complete name here. */
* another Blender node name happens to match the complete name here. Can not just check
* the graph because the node with this name might not get added to it immediately. */
name = BLI_uniquename_cb(
[this](const StringRef check_name) {
return check_name == export_params.output_node_name ||
graph_element_->getNode(check_name) != nullptr;
graph_element_->getNode(check_name) != nullptr ||
used_node_names_.contains(check_name);
},
'_',
name);
used_node_names_.add(name);
key_to_name_map_.add_new(key, name);
return name;
}

View File

@@ -12,6 +12,7 @@
#include "node_item.h"
#include "BLI_map.hh"
#include "BLI_set.hh"
#include "BLI_string_ref.hh"
struct bNode;
@@ -61,6 +62,7 @@ struct NodeGraph {
MaterialX::GraphElement *graph_element_ = nullptr;
Map<NodeKey, const std::string> root_key_to_name_map_;
Map<NodeKey, const std::string> &key_to_name_map_;
Set<std::string> used_node_names_;
std::string node_name_prefix_;
};