diff options
author | Nathan Warden <nathan@nathanwarden.com> | 2017-11-06 23:22:37 -0500 |
---|---|---|
committer | Nathan Warden <nathan@nathanwarden.com> | 2017-11-07 00:06:11 -0500 |
commit | 400db80d25d5e19fe68bbd3f04115c1578af7eac (patch) | |
tree | 9a40f07220b6ca947b5527bfc94e6ee16755c0e6 /editor/import/resource_importer_scene.cpp | |
parent | 9437db7bc59a33b134306e8fa46eede2fb4ffde6 (diff) |
Fixed a bug where materials weren't assigned to scene on first import.
Diffstat (limited to 'editor/import/resource_importer_scene.cpp')
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 660db9ac27..aa6e40056c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -858,12 +858,11 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String String ext_name = p_base_path.plus_file(_make_extname(mat->get_name()) + ".material"); if (p_keep_materials && FileAccess::exists(ext_name)) { //if exists, use it - Ref<Material> existing = ResourceLoader::load(ext_name); - p_materials[mat] = existing; + p_materials[mat] = ResourceLoader::load(ext_name); } else { ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); - p_materials[mat] = mat; + p_materials[mat] = ResourceLoader::load(ext_name); } } @@ -887,7 +886,8 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String String ext_name = p_base_path.plus_file(_make_extname(mesh->get_name()) + ".mesh"); ResourceSaver::save(ext_name, mesh, ResourceSaver::FLAG_CHANGE_PATH); - p_meshes[mesh] = mesh; + p_meshes[mesh] = ResourceLoader::load(ext_name); + p_node->set(E->get().name, p_meshes[mesh]); mesh_just_added = true; } } @@ -907,18 +907,24 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String ; if (FileAccess::exists(ext_name)) { //if exists, use it - Ref<Material> existing = ResourceLoader::load(ext_name); - p_materials[mat] = existing; + p_materials[mat] = ResourceLoader::load(ext_name); } else { ResourceSaver::save(ext_name, mat, ResourceSaver::FLAG_CHANGE_PATH); - p_materials[mat] = mat; + p_materials[mat] = ResourceLoader::load(ext_name); } } if (p_materials[mat] != mat) { mesh->surface_set_material(i, p_materials[mat]); + + //re-save the mesh since a material is now assigned + if (p_make_meshes) { + String ext_name = p_base_path.plus_file(_make_extname(mesh->get_name()) + ".mesh"); + ResourceSaver::save(ext_name, mesh, ResourceSaver::FLAG_CHANGE_PATH); + p_meshes[mesh] = ResourceLoader::load(ext_name); + } } } |