From 26d146b6c9d67bf37797714c8fe430246938882b Mon Sep 17 00:00:00 2001 From: trollodel <33117082+trollodel@users.noreply.github.com> Date: Fri, 9 Dec 2022 17:01:40 +0100 Subject: Ensure that generated import IDs are unique --- editor/import/scene_import_settings.cpp | 16 ++++++++-------- editor/import/scene_import_settings.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp index 730aa3bd61..f73cbec7eb 100644 --- a/editor/import/scene_import_settings.cpp +++ b/editor/import/scene_import_settings.cpp @@ -137,24 +137,23 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref &p_ma String import_id; bool has_import_id = false; - bool created = false; - if (!material_set.has(p_material)) { - material_set.insert(p_material); - created = true; - } - if (p_material->has_meta("import_id")) { import_id = p_material->get_meta("import_id"); has_import_id = true; } else if (!p_material->get_name().is_empty()) { import_id = p_material->get_name(); has_import_id = true; + } else if (unnamed_material_name_map.has(p_material)) { + import_id = unnamed_material_name_map[p_material]; } else { - import_id = "@MATERIAL:" + itos(material_set.size() - 1); + import_id = "@MATERIAL:" + itos(material_map.size()); + unnamed_material_name_map[p_material] = import_id; } + bool created = false; if (!material_map.has(import_id)) { MaterialData md; + created = true; md.has_import_id = has_import_id; md.material = p_material; @@ -164,6 +163,7 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref &p_ma } MaterialData &material_data = material_map[import_id]; + ERR_FAIL_COND(p_material != material_data.material); Ref icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons")); @@ -553,9 +553,9 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati base_path = p_path; - material_set.clear(); mesh_set.clear(); material_map.clear(); + unnamed_material_name_map.clear(); mesh_map.clear(); node_map.clear(); defaults.clear(); diff --git a/editor/import/scene_import_settings.h b/editor/import/scene_import_settings.h index 0e12a83116..691c5eebd0 100644 --- a/editor/import/scene_import_settings.h +++ b/editor/import/scene_import_settings.h @@ -107,6 +107,7 @@ class SceneImportSettings : public ConfirmationDialog { HashMap settings; }; HashMap material_map; + HashMap, String> unnamed_material_name_map; struct MeshData { bool has_import_id; @@ -141,7 +142,6 @@ class SceneImportSettings : public ConfirmationDialog { void _fill_scene(Node *p_node, TreeItem *p_parent_item); HashSet> mesh_set; - HashSet> material_set; String selected_type; String selected_id; -- cgit v1.2.3