Skip to content

Commit

Permalink
Fix some bugs in the advanced scene import
Browse files Browse the repository at this point in the history
- Start with the scene item selected, instead of showing an invalid view
- Don't crash when selecting unnamed materials.
  • Loading branch information
trollodel committed May 13, 2022
1 parent 29cf36f commit a73b0f1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions editor/import/scene_import_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &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 {
import_id = "@MATERIAL:" + itos(material_set.size());
import_id = "@MATERIAL:" + itos(material_set.size() - 1);
}

if (!material_map.has(import_id)) {
Expand All @@ -160,14 +166,12 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
Ref<Texture2D> icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons"));

TreeItem *item = p_tree->create_item(p_parent);
item->set_text(0, p_material->get_name());
item->set_icon(0, icon);

bool created = false;
if (!material_set.has(p_material)) {
material_set.insert(p_material);
created = true;
if (p_material->get_name().is_empty()) {
item->set_text(0, TTR("<Unnamed Material>"));
} else {
item->set_text(0, p_material->get_name());
}
item->set_icon(0, icon);

item->set_meta("type", "Material");
item->set_meta("import_id", import_id);
Expand Down Expand Up @@ -604,6 +608,9 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati
_update_view_gizmos();
_update_camera();

// Start with the root item (Scene) selected.
scene_tree->get_root()->select(0);

if (p_for_animation) {
set_title(vformat(TTR("Advanced Import Settings for AnimationLibrary '%s'"), base_path.get_file()));
} else {
Expand Down

0 comments on commit a73b0f1

Please sign in to comment.