diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index e63de3205..8bc563d6f 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -107,6 +107,7 @@ public: virtual String get_resource_type() const = 0; virtual float get_priority() const { return 1.0; } virtual int get_import_order() const { return IMPORT_ORDER_DEFAULT; } + virtual bool use_on_initial_import() const { return true; } struct ImportOption { PropertyInfo option; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 6899a6fc9..3dab8cf34 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1806,6 +1806,30 @@ void EditorFileSystem::_reimport_file(const String &p_file) { } } + if (load_default && !importer->use_on_initial_import()) { + FileAccess *f = FileAccess::open(p_file + ".import", FileAccess::WRITE); + ERR_FAIL_COND_MSG(!f, "Cannot open file from path '" + p_file + ".import'."); + + f->store_line("[remap]"); + f->store_line(""); + f->store_line("importer=\"keep\""); + f->store_line(""); + + f->close(); + memdelete(f); + + //update modified times, to avoid reimport + fs->files[cpos]->modified_time = FileAccess::get_modified_time(p_file); + fs->files[cpos]->import_modified_time = FileAccess::get_modified_time(p_file + ".import"); + fs->files[cpos]->deps.clear(); + fs->files[cpos]->type = ""; + fs->files[cpos]->import_valid = false; + + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); + + return; + } + //mix with default params, in case a parameter is missing List opts; diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 48b090b73..cc1f810fd 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -87,6 +87,13 @@ int EditorImportPlugin::get_import_order() const { return get_script_instance()->call("get_import_order"); } +bool EditorImportPlugin::use_on_initial_import() const { + if (!(get_script_instance() && get_script_instance()->has_method("use_on_initial_import"))) { + return ResourceImporter::use_on_initial_import(); + } + return get_script_instance()->call("use_on_initial_import"); +} + void EditorImportPlugin::get_import_options(List *r_options, int p_preset) const { ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_import_options"))); Array needed; @@ -162,6 +169,7 @@ void EditorImportPlugin::_bind_methods() { ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::REAL, "get_priority")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_import_order")); + ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "use_on_initial_import")); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files"))); } diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index ab81ed07d..c1945eac2 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -51,6 +51,7 @@ public: virtual String get_resource_type() const; virtual float get_priority() const; virtual int get_import_order() const; + virtual bool use_on_initial_import() const; virtual void get_import_options(List *r_options, int p_preset) const; virtual bool get_option_visibility(const String &p_option, const RBMap &p_options) const; virtual Error import(const String &p_source_file, const String &p_save_path, const RBMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata = nullptr);