From 91c3066c89e647e7edba3f88dd08cdb7e464f9ab Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 31 Jan 2023 15:59:52 +0100 Subject: Support reimport appending * Add API: `EditorFileSystem::reimport_append(path)`, thread safe, what can be used from importers when they generate new files within the import process. * Added a `remap.gen_param` custom value to .import files, which can be used by importers to store data needed to generate this file again or not. This API is added to allow the GLTF2 importer to properly extract png files as textures. --- editor/import/editor_import_plugin.cpp | 16 ++++++++++++++++ editor/import/editor_import_plugin.h | 3 +++ 2 files changed, 19 insertions(+) (limited to 'editor/import') diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index fb14dcf888..0d387999ef 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -31,6 +31,7 @@ #include "editor_import_plugin.h" #include "core/object/script_language.h" +#include "editor/editor_file_system.h" EditorImportPlugin::EditorImportPlugin() { } @@ -187,6 +188,20 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on."); } +Error EditorImportPlugin::_append_import_external_resource(const String &p_file, const Dictionary &p_custom_options, const String &p_custom_importer) { + HashMap options; + List keys; + p_custom_options.get_key_list(&keys); + for (const Variant &K : keys) { + options.insert(K, p_custom_options[K]); + } + return append_import_external_resource(p_file, options, p_custom_importer); +} + +Error EditorImportPlugin::append_import_external_resource(const String &p_file, const HashMap &p_custom_options, const String &p_custom_importer) { + return EditorFileSystem::get_singleton()->reimport_append(p_file, p_custom_options, p_custom_importer); +} + void EditorImportPlugin::_bind_methods() { GDVIRTUAL_BIND(_get_importer_name) GDVIRTUAL_BIND(_get_visible_name) @@ -200,4 +215,5 @@ void EditorImportPlugin::_bind_methods() { GDVIRTUAL_BIND(_get_import_order) GDVIRTUAL_BIND(_get_option_visibility, "path", "option_name", "options") GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files"); + ClassDB::bind_method(D_METHOD("append_import_external_resource", "path", "custom_options", "custom_importer"), &EditorImportPlugin::_append_import_external_resource, DEFVAL(Dictionary()), DEFVAL(String())); } diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 0f79ba4783..8014bc54d5 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -53,6 +53,8 @@ protected: GDVIRTUAL3RC(bool, _get_option_visibility, String, StringName, Dictionary) GDVIRTUAL5RC(int, _import, String, String, Dictionary, TypedArray, TypedArray) + Error _append_import_external_resource(const String &p_file, const Dictionary &p_custom_options = Dictionary(), const String &p_custom_importer = String()); + public: EditorImportPlugin(); virtual String get_importer_name() const override; @@ -67,6 +69,7 @@ public: virtual void get_import_options(const String &p_path, List *r_options, int p_preset) const override; virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap &p_options) const override; virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata = nullptr) override; + Error append_import_external_resource(const String &p_file, const HashMap &p_custom_options = HashMap(), const String &p_custom_importer = String()); }; #endif // EDITOR_IMPORT_PLUGIN_H -- cgit v1.2.3