From fea4165ca8e952cef8cb8c636b4399ffdaebbdb5 Mon Sep 17 00:00:00 2001 From: Lyuma Date: Mon, 25 Dec 2023 00:58:38 -0800 Subject: [PATCH] gltf: fix three bugs which prevented extracted textures from being refreshed. 1. Extracted texture paths in `GLTFDocument::_parse_image_save_image` at the project root started with res:/// which broke cache invalidation 2. md5 hashes were not being written to generator_parameters for new imports, which led Godot to think the file was manually created. 3. `EditorFileSystem::reimport_append` must emit the `resources_reimported` signal in order for the resource cache to be updated. --- editor/editor_file_system.cpp | 8 +++++++- modules/gltf/gltf_document.cpp | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 807f0c8eb74..ad11f6135c4 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -2436,7 +2436,13 @@ void EditorFileSystem::reimport_files(const Vector &p_files) { Error EditorFileSystem::reimport_append(const String &p_file, const HashMap &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters) { ERR_FAIL_COND_V_MSG(!importing, ERR_INVALID_PARAMETER, "Can only append files to import during a current reimport process."); - return _reimport_file(p_file, p_custom_options, p_custom_importer, &p_generator_parameters); + Error ret = _reimport_file(p_file, p_custom_options, p_custom_importer, &p_generator_parameters); + + // Emit the resource_reimported signal for the single file we just reimported. + Vector reloads; + reloads.append(p_file); + emit_signal(SNAME("resources_reimported"), reloads); + return ret; } Error EditorFileSystem::_resource_import(const String &p_path) { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 4060f7f6268..ee093a1f1b1 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3218,7 +3218,7 @@ void GLTFDocument::_parse_image_save_image(Ref p_state, const Vector< bool must_import = true; Vector img_data = p_image->get_data(); Dictionary generator_parameters; - String file_path = p_state->get_base_path() + "/" + p_state->filename.get_basename() + "_" + p_image->get_name(); + String file_path = p_state->get_base_path().path_join(p_state->filename.get_basename() + "_" + p_image->get_name()); file_path += p_file_extension.is_empty() ? ".png" : p_file_extension; if (FileAccess::exists(file_path + ".import")) { Ref config; @@ -3230,6 +3230,8 @@ void GLTFDocument::_parse_image_save_image(Ref p_state, const Vector< if (!generator_parameters.has("md5")) { must_import = false; // Didn't come from a gltf document; don't overwrite. } + } + if (must_import) { String existing_md5 = generator_parameters["md5"]; unsigned char md5_hash[16]; CryptoCore::md5(img_data.ptr(), img_data.size(), md5_hash);