diff --git a/modules/gltf/editor/editor_scene_importer_blend.cpp b/modules/gltf/editor/editor_scene_importer_blend.cpp index 542e00e56089..2db46adef414 100644 --- a/modules/gltf/editor/editor_scene_importer_blend.cpp +++ b/modules/gltf/editor/editor_scene_importer_blend.cpp @@ -319,6 +319,8 @@ Node *EditorSceneFormatImporterBlend::import_scene(const String &p_path, uint32_ state->set_import_as_skeleton_bones(true); } state->set_scene_name(blend_basename); + state->set_extract_path(p_path.get_base_dir()); + state->set_extract_prefix(blend_basename); err = gltf->append_from_file(sink.get_basename() + ".gltf", state, p_flags, base_dir); if (err != OK) { if (r_err) { diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 9b835c456c59..fd03259cf8ce 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3501,8 +3501,8 @@ void GLTFDocument::_parse_image_save_image(Ref p_state, const Vector< } #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && handling == GLTFState::GLTFHandleBinary::HANDLE_BINARY_EXTRACT_TEXTURES) { - if (p_state->base_path.is_empty()) { - WARN_PRINT("glTF: Couldn't extract image because the base path is empty. It will be loaded directly instead, uncompressed."); + if (p_state->extract_path.is_empty()) { + WARN_PRINT("glTF: Couldn't extract image because the base and extract paths are empty. It will be loaded directly instead, uncompressed."); } else { if (p_image->get_name().is_empty()) { WARN_PRINT(vformat("glTF: Image index '%d' did not have a name. It will be automatically given a name based on its index.", p_index)); @@ -3511,7 +3511,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().path_join(p_state->filename.get_basename() + "_" + p_image->get_name()); + String file_path = p_state->get_extract_path().path_join(p_state->get_extract_prefix() + "_" + p_image->get_name()); file_path += p_file_extension.is_empty() ? ".png" : p_file_extension; if (FileAccess::exists(file_path + ".import")) { Ref config; @@ -7349,7 +7349,7 @@ PackedByteArray GLTFDocument::generate_buffer(Ref p_state) { Error GLTFDocument::write_to_filesystem(Ref p_state, const String &p_path) { Ref state = p_state; ERR_FAIL_COND_V(state.is_null(), ERR_INVALID_PARAMETER); - state->base_path = p_path.get_base_dir(); + state->set_base_path(p_path.get_base_dir()); state->filename = p_path.get_file(); Error err = _serialize(state); if (err != OK) { @@ -7462,7 +7462,7 @@ Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pa Ref file_access; file_access.instantiate(); file_access->open_custom(p_bytes.ptr(), p_bytes.size()); - state->base_path = p_base_path.get_base_dir(); + state->set_base_path(p_base_path.get_base_dir()); err = _parse(p_state, state->base_path, file_access); ERR_FAIL_COND_V(err != OK, err); for (Ref ext : document_extensions) { @@ -7479,7 +7479,7 @@ Error GLTFDocument::append_from_file(String p_path, Ref p_state, uint if (state == Ref()) { state.instantiate(); } - state->filename = p_path.get_file().get_basename(); + state->set_filename(p_path.get_file().get_basename()); state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS; state->discard_meshes_and_materials = p_flags & GLTF_IMPORT_DISCARD_MESHES_AND_MATERIALS; state->force_generate_tangents = p_flags & GLTF_IMPORT_GENERATE_TANGENT_ARRAYS; @@ -7493,7 +7493,7 @@ Error GLTFDocument::append_from_file(String p_path, Ref p_state, uint if (base_path.is_empty()) { base_path = p_path.get_base_dir(); } - state->base_path = base_path; + state->set_base_path(base_path); err = _parse(p_state, base_path, file); ERR_FAIL_COND_V(err != OK, err); for (Ref ext : document_extensions) { diff --git a/modules/gltf/gltf_state.cpp b/modules/gltf/gltf_state.cpp index 7763874d028a..2488e73d080a 100644 --- a/modules/gltf/gltf_state.cpp +++ b/modules/gltf/gltf_state.cpp @@ -397,8 +397,27 @@ String GLTFState::get_base_path() { return base_path; } -void GLTFState::set_base_path(String p_base_path) { +void GLTFState::set_base_path(const String &p_base_path) { base_path = p_base_path; + if (extract_path.is_empty()) { + extract_path = p_base_path; + } +} + +String GLTFState::get_extract_path() { + return extract_path; +} + +void GLTFState::set_extract_path(const String &p_extract_path) { + extract_path = p_extract_path; +} + +String GLTFState::get_extract_prefix() { + return extract_prefix; +} + +void GLTFState::set_extract_prefix(const String &p_extract_prefix) { + extract_prefix = p_extract_prefix; } String GLTFState::get_filename() const { @@ -407,6 +426,9 @@ String GLTFState::get_filename() const { void GLTFState::set_filename(const String &p_filename) { filename = p_filename; + if (extract_prefix.is_empty()) { + extract_prefix = p_filename.get_basename(); + } } Variant GLTFState::get_additional_data(const StringName &p_extension_name) { diff --git a/modules/gltf/gltf_state.h b/modules/gltf/gltf_state.h index 795404919263..042384f54666 100644 --- a/modules/gltf/gltf_state.h +++ b/modules/gltf/gltf_state.h @@ -51,6 +51,8 @@ class GLTFState : public Resource { protected: String base_path; + String extract_path; + String extract_prefix; String filename; Dictionary json; int major_version = 0; @@ -186,7 +188,13 @@ class GLTFState : public Resource { void set_scene_name(String p_scene_name); String get_base_path(); - void set_base_path(String p_base_path); + void set_base_path(const String &p_base_path); + + String get_extract_path(); + void set_extract_path(const String &p_extract_path); + + String get_extract_prefix(); + void set_extract_prefix(const String &p_extract_prefix); String get_filename() const; void set_filename(const String &p_filename);