Merge pull request #59764 from reduz/blender-import-autodetect
This commit is contained in:
commit
4263f02f28
12 changed files with 499 additions and 23 deletions
|
|
@ -520,6 +520,45 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo
|
|||
return false; //nothing changed
|
||||
}
|
||||
|
||||
bool EditorFileSystem::_scan_import_support(Vector<String> reimports) {
|
||||
if (import_support_queries.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
Map<String, int> import_support_test;
|
||||
Vector<bool> import_support_tested;
|
||||
import_support_tested.resize(import_support_queries.size());
|
||||
for (int i = 0; i < import_support_queries.size(); i++) {
|
||||
import_support_tested.write[i] = false;
|
||||
if (import_support_queries[i]->is_active()) {
|
||||
Vector<String> extensions = import_support_queries[i]->get_file_extensions();
|
||||
for (int j = 0; j < extensions.size(); j++) {
|
||||
import_support_test.insert(extensions[j], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (import_support_test.size() == 0) {
|
||||
return false; //well nothing to do
|
||||
}
|
||||
|
||||
for (int i = 0; i < reimports.size(); i++) {
|
||||
Map<String, int>::Element *E = import_support_test.find(reimports[i].get_extension());
|
||||
if (E) {
|
||||
import_support_tested.write[E->get()] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < import_support_tested.size(); i++) {
|
||||
if (import_support_tested[i]) {
|
||||
if (import_support_queries.write[i]->query()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EditorFileSystem::_update_scan_actions() {
|
||||
sources_changed.clear();
|
||||
|
||||
|
|
@ -612,7 +651,7 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||
if (_scan_extensions()) {
|
||||
//needs editor restart
|
||||
//extensions also may provide filetypes to be imported, so they must run before importing
|
||||
if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save&Restart"), TTR("Continue"))) {
|
||||
if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save & Restart"), TTR("Continue"))) {
|
||||
if (!first_scan) {
|
||||
EditorNode::get_singleton()->save_all_scenes();
|
||||
}
|
||||
|
|
@ -621,7 +660,12 @@ bool EditorFileSystem::_update_scan_actions() {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (reimports.size()) {
|
||||
if (_scan_import_support(reimports)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
reimport_files(reimports);
|
||||
} else {
|
||||
//reimport files will update the uid cache file so if nothing was reimported, update it manually
|
||||
|
|
@ -2274,6 +2318,7 @@ static void _scan_extensions_dir(EditorFileSystemDirectory *d, Set<String> &exte
|
|||
bool EditorFileSystem::_scan_extensions() {
|
||||
EditorFileSystemDirectory *d = get_filesystem();
|
||||
Set<String> extensions;
|
||||
|
||||
_scan_extensions_dir(d, extensions);
|
||||
|
||||
//verify against loaded extensions
|
||||
|
|
@ -2374,6 +2419,14 @@ void EditorFileSystem::_update_extensions() {
|
|||
}
|
||||
}
|
||||
|
||||
void EditorFileSystem::add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
|
||||
ERR_FAIL_COND(import_support_queries.find(p_query) != -1);
|
||||
import_support_queries.push_back(p_query);
|
||||
}
|
||||
void EditorFileSystem::remove_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query) {
|
||||
import_support_queries.erase(p_query);
|
||||
}
|
||||
|
||||
EditorFileSystem::EditorFileSystem() {
|
||||
ResourceLoader::import = _resource_import;
|
||||
reimport_on_missing_imported_files = GLOBAL_DEF("editor/import/reimport_missing_imported_files", true);
|
||||
|
|
|
|||
|
|
@ -109,6 +109,37 @@ public:
|
|||
~EditorFileSystemDirectory();
|
||||
};
|
||||
|
||||
class EditorFileSystemImportFormatSupportQuery : public RefCounted {
|
||||
GDCLASS(EditorFileSystemImportFormatSupportQuery, RefCounted);
|
||||
|
||||
protected:
|
||||
GDVIRTUAL0RC(bool, _is_active)
|
||||
GDVIRTUAL0RC(Vector<String>, _get_file_extensions)
|
||||
GDVIRTUAL0RC(bool, _query)
|
||||
static void _bind_methods() {
|
||||
GDVIRTUAL_BIND(_is_active);
|
||||
GDVIRTUAL_BIND(_get_file_extensions);
|
||||
GDVIRTUAL_BIND(_query);
|
||||
}
|
||||
|
||||
public:
|
||||
virtual bool is_active() const {
|
||||
bool ret = false;
|
||||
GDVIRTUAL_REQUIRED_CALL(_is_active, ret);
|
||||
return ret;
|
||||
}
|
||||
virtual Vector<String> get_file_extensions() const {
|
||||
Vector<String> ret;
|
||||
GDVIRTUAL_REQUIRED_CALL(_get_file_extensions, ret);
|
||||
return ret;
|
||||
}
|
||||
virtual bool query() {
|
||||
bool ret = false;
|
||||
GDVIRTUAL_REQUIRED_CALL(_query, ret);
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
class EditorFileSystem : public Node {
|
||||
GDCLASS(EditorFileSystem, Node);
|
||||
|
||||
|
|
@ -257,6 +288,9 @@ class EditorFileSystem : public Node {
|
|||
static ResourceUID::ID _resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate);
|
||||
|
||||
bool _scan_extensions();
|
||||
bool _scan_import_support(Vector<String> reimports);
|
||||
|
||||
Vector<Ref<EditorFileSystemImportFormatSupportQuery>> import_support_queries;
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
|
@ -289,6 +323,8 @@ public:
|
|||
|
||||
static bool _should_skip_directory(const String &p_path);
|
||||
|
||||
void add_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query);
|
||||
void remove_import_format_support_query(Ref<EditorFileSystemImportFormatSupportQuery> p_query);
|
||||
EditorFileSystem();
|
||||
~EditorFileSystem();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3920,6 +3920,7 @@ void EditorNode::register_editor_types() {
|
|||
GDREGISTER_CLASS(EditorScriptPicker);
|
||||
|
||||
GDREGISTER_ABSTRACT_CLASS(FileSystemDock);
|
||||
GDREGISTER_VIRTUAL_CLASS(EditorFileSystemImportFormatSupportQuery);
|
||||
|
||||
GDREGISTER_CLASS(EditorScenePostImport);
|
||||
GDREGISTER_CLASS(EditorCommandPalette);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue