diff options
Diffstat (limited to 'editor')
38 files changed, 448 insertions, 110 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 39e6df4450..2b9007de04 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -1160,6 +1160,17 @@ void EditorExport::add_export_preset(const Ref<EditorExportPreset> &p_preset, in export_presets.insert(p_at_pos, p_preset); } +String EditorExportPlatform::test_etc2() const { + + String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name"); + bool etc2_supported = ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc"); + + if (driver == "GLES2" && !etc2_supported) { + return TTR("Target platform requires 'ETC' texture compression for GLES2. Enable support in Project Settings."); + } + return String(); +} + int EditorExport::get_export_preset_count() const { return export_presets.size(); diff --git a/editor/editor_export.h b/editor/editor_export.h index c7c2b76327..bd864c528c 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -258,6 +258,7 @@ public: virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_device, int p_debug_flags) { return OK; } virtual Ref<Texture> get_run_icon() const { return get_logo(); } + String test_etc2() const; //generic test for etc2 since most platforms use it virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const = 0; virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const = 0; diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index ea36410cc3..3d9d5e26be 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -42,6 +42,8 @@ #include "editor_settings.h" EditorFileSystem *EditorFileSystem::singleton = NULL; +//the name is the version, to keep compatibility with different versions of Godot +#define CACHE_FILE_NAME "filesystem_cache5" void EditorFileSystemDirectory::sort_files() { @@ -203,14 +205,30 @@ void EditorFileSystem::_scan_filesystem() { String project = ProjectSettings::get_singleton()->get_resource_path(); - String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache4"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(CACHE_FILE_NAME); FileAccess *f = FileAccess::open(fscache, FileAccess::READ); + bool first = true; if (f) { //read the disk cache while (!f->eof_reached()) { String l = f->get_line().strip_edges(); + if (first) { + if (first_scan) { + // only use this on first scan, afterwards it gets ignored + // this is so on first reimport we synchronize versions, then + // we dont care until editor restart. This is for usability mainly so + // your workflow is not killed after changing a setting by forceful reimporting + // everything there is. + filesystem_settings_version_for_import = l.strip_edges(); + if (filesystem_settings_version_for_import != ResourceFormatImporter::get_singleton()->get_import_settings_hash()) { + revalidate_import_files = true; + } + } + first = false; + continue; + } if (l == String()) continue; @@ -291,25 +309,22 @@ void EditorFileSystem::_scan_filesystem() { memdelete(d); - f = FileAccess::open(fscache, FileAccess::WRITE); - if (f == NULL) { - ERR_PRINTS("Error writing fscache: " + fscache); - } else { - _save_filesystem_cache(new_filesystem, f); - f->close(); - memdelete(f); + if (!first_scan) { + //on the first scan this is done from the main thread after re-importing + _save_filesystem_cache(); } scanning = false; } void EditorFileSystem::_save_filesystem_cache() { - String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache4"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(CACHE_FILE_NAME); FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE); if (f == NULL) { ERR_PRINTS("Error writing fscache: " + fscache); } else { + f->store_line(filesystem_settings_version_for_import); _save_filesystem_cache(filesystem, f); f->close(); memdelete(f); @@ -327,6 +342,15 @@ bool EditorFileSystem::_test_for_reimport(const String &p_path, bool p_only_impo if (!reimport_on_missing_imported_files && p_only_imported_files) return false; + if (!FileAccess::exists(p_path + ".import")) { + return true; + } + + if (!ResourceFormatImporter::get_singleton()->are_import_settings_valid(p_path)) { + //reimport settings are not valid, reimport + return true; + } + Error err; FileAccess *f = FileAccess::open(p_path + ".import", FileAccess::READ, &err); @@ -562,6 +586,13 @@ bool EditorFileSystem::_update_scan_actions() { reimport_files(reimports); } + if (first_scan) { + //only on first scan this is valid and updated, then settings changed. + revalidate_import_files = false; + filesystem_settings_version_for_import = ResourceFormatImporter::get_singleton()->get_import_settings_hash(); + _save_filesystem_cache(); + } + if (reloads.size()) { emit_signal("resources_reload", reloads); } @@ -595,7 +626,7 @@ void EditorFileSystem::scan() { emit_signal("filesystem_changed"); emit_signal("sources_changed", sources_changed.size() > 0); _queue_update_script_classes(); - + first_scan = false; } else { ERR_FAIL_COND(thread); @@ -737,11 +768,20 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, DirAccess fi->deps = fc->deps; fi->modified_time = fc->modification_time; fi->import_modified_time = fc->import_modification_time; + fi->import_valid = fc->import_valid; fi->script_class_name = fc->script_class_name; fi->script_class_extends = fc->script_class_extends; fi->script_class_icon_path = fc->script_class_icon_path; + if (revalidate_import_files && !ResourceFormatImporter::get_singleton()->are_import_settings_valid(path)) { + ItemAction ia; + ia.action = ItemAction::ACTION_FILE_TEST_REIMPORT; + ia.dir = p_dir; + ia.file = E->get(); + scan_actions.push_back(ia); + } + if (fc->type == String()) { fi->type = ResourceLoader::get_resource_type(path); //there is also the chance that file type changed due to reimport, must probably check this somehow here (or kind of note it for next time in another file?) @@ -1101,6 +1141,7 @@ void EditorFileSystem::_notification(int p_what) { emit_signal("filesystem_changed"); emit_signal("sources_changed", sources_changed.size() > 0); _queue_update_script_classes(); + first_scan = false; } } else if (!scanning) { @@ -1117,6 +1158,7 @@ void EditorFileSystem::_notification(int p_what) { emit_signal("filesystem_changed"); emit_signal("sources_changed", sources_changed.size() > 0); _queue_update_script_classes(); + first_scan = false; } } } break; @@ -1569,8 +1611,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { List<String> import_variants; List<String> gen_files; - - Error err = importer->import(p_file, base_path, params, &import_variants, &gen_files); + Variant metadata; + Error err = importer->import(p_file, base_path, params, &import_variants, &gen_files, &metadata); if (err != OK) { ERR_PRINTS("Error importing: " + p_file); @@ -1615,6 +1657,10 @@ void EditorFileSystem::_reimport_file(const String &p_file) { f->store_line("valid=false"); } + if (metadata != Variant()) { + f->store_line("metadata=" + metadata.get_construct_string()); + } + f->store_line(""); f->store_line("[deps]\n"); @@ -1815,6 +1861,8 @@ EditorFileSystem::EditorFileSystem() { scan_total = 0; update_script_classes_queued = false; + first_scan = true; + revalidate_import_files = false; } EditorFileSystem::~EditorFileSystem() { diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index bb892baf57..2a9e325454 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -143,7 +143,10 @@ class EditorFileSystem : public Node { bool abort_scan; bool scanning; bool importing; + bool first_scan; float scan_total; + String filesystem_settings_version_for_import; + bool revalidate_import_files; void _scan_filesystem(); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8c9974404e..67fba4f278 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -291,6 +291,8 @@ void EditorNode::_notification(int p_what) { get_tree()->get_root()->set_as_audio_listener_2d(false); get_tree()->set_auto_accept_quit(false); get_tree()->connect("files_dropped", this, "_dropped_files"); + + /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } if (p_what == NOTIFICATION_EXIT_TREE) { @@ -305,7 +307,8 @@ void EditorNode::_notification(int p_what) { _editor_select(EDITOR_3D); _update_debug_options(); - _load_docks(); + + /* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */ } if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) { @@ -528,6 +531,10 @@ void EditorNode::_sources_changed(bool p_exist) { if (waiting_for_first_scan) { + EditorResourcePreview::get_singleton()->start(); //start previes now that it's safe + + _load_docks(); + if (defer_load_scene != "") { load_scene(defer_load_scene); @@ -1017,6 +1024,35 @@ bool EditorNode::_validate_scene_recursive(const String &p_filename, Node *p_nod return false; } +static bool _find_edited_resources(const Ref<Resource> &p_resource, Set<Ref<Resource> > &edited_resources) { + + if (p_resource->is_edited()) { + edited_resources.insert(p_resource); + return true; + } + + List<PropertyInfo> plist; + + p_resource->get_property_list(&plist); + + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + if (E->get().type == Variant::OBJECT && E->get().usage & PROPERTY_USAGE_STORAGE && !(E->get().usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT)) { + RES res = p_resource->get(E->get().name); + if (res.is_null()) { + continue; + } + if (res->get_path().is_resource_file()) { //not a subresource, continue + continue; + } + if (_find_edited_resources(res, edited_resources)) { + return true; + } + } + } + + return false; +} + void EditorNode::_save_scene(String p_file, int idx) { Node *scene = editor_data.get_edited_scene_root(idx); @@ -1080,16 +1116,28 @@ void EditorNode::_save_scene(String p_file, int idx) { //_save_edited_subresources(scene, processed, flg); { //instead, just find globally unsaved subresources and save them + Set<Ref<Resource> > edited_subresources; + List<Ref<Resource> > cached; ResourceCache::get_cached_resources(&cached); for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) { Ref<Resource> res = E->get(); - if (res->is_edited() && res->get_path().is_resource_file()) { + if (!res->get_path().is_resource_file()) + continue; + //not only check if this resourec is edited, check contained subresources too + if (_find_edited_resources(res, edited_subresources)) { ResourceSaver::save(res->get_path(), res, flg); - res->set_edited(false); } } + + // clear later, because user may have put the same subresource in two different resources, + // which will be shared until the next reload + + for (Set<Ref<Resource> >::Element *E = edited_subresources.front(); E; E = E->next()) { + Ref<Resource> res = E->get(); + res->set_edited(false); + } } editor_data.save_editor_external_data(); @@ -2542,6 +2590,7 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor, bool p_config_chan singleton->editor_plugins_over->get_plugins_list().erase(p_editor); singleton->remove_child(p_editor); singleton->editor_data.remove_editor_plugin(p_editor); + singleton->get_editor_plugins_force_input_forwarding()->remove_plugin(p_editor); } void EditorNode::_update_addon_config() { @@ -3631,6 +3680,8 @@ void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p } p_layout->set_value(p_section, "dock_filesystem_split", filesystem_dock->get_split_offset()); + p_layout->set_value(p_section, "dock_filesystem_display_mode", filesystem_dock->get_display_mode()); + p_layout->set_value(p_section, "dock_filesystem_file_list_display_mode", filesystem_dock->get_file_list_display_mode()); for (int i = 0; i < vsplits.size(); i++) { @@ -3818,6 +3869,17 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String int fs_split_ofs = 0; if (p_layout->has_section_key(p_section, "dock_filesystem_split")) { fs_split_ofs = p_layout->get_value(p_section, "dock_filesystem_split"); + filesystem_dock->set_split_offset(fs_split_ofs); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_display_mode")) { + FileSystemDock::DisplayMode dock_filesystem_display_mode = FileSystemDock::DisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_display_mode"))); + filesystem_dock->set_display_mode(dock_filesystem_display_mode); + } + + if (p_layout->has_section_key(p_section, "dock_filesystem_file_list_display_mode")) { + FileSystemDock::FileListDisplayMode dock_filesystem_file_list_display_mode = FileSystemDock::FileListDisplayMode(int(p_layout->get_value(p_section, "dock_filesystem_file_list_display_mode"))); + filesystem_dock->set_file_list_display_mode(dock_filesystem_file_list_display_mode); } filesystem_dock->set_split_offset(fs_split_ofs); @@ -5579,9 +5641,10 @@ EditorNode::EditorNode() { node_dock = memnew(NodeDock); filesystem_dock = memnew(FileSystemDock(this)); - filesystem_dock->set_file_list_display_mode(int(EditorSettings::get_singleton()->get("docks/filesystem/files_display_mode"))); filesystem_dock->connect("open", this, "open_request"); + filesystem_dock->set_file_list_display_mode(FileSystemDock::FILE_LIST_DISPLAY_LIST); filesystem_dock->connect("instance", this, "_instance_request"); + filesystem_dock->connect("display_mode_changed", this, "_save_docks"); // Scene: Top left dock_slot[DOCK_SLOT_LEFT_UR]->add_child(scene_tree_dock); @@ -6059,6 +6122,10 @@ void EditorPluginList::add_plugin(EditorPlugin *p_plugin) { plugins_list.push_back(p_plugin); } +void EditorPluginList::remove_plugin(EditorPlugin *p_plugin) { + plugins_list.erase(p_plugin); +} + bool EditorPluginList::empty() { return plugins_list.empty(); } diff --git a/editor/editor_node.h b/editor/editor_node.h index 46a65b56fa..433441c29e 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -837,6 +837,7 @@ public: void forward_spatial_draw_over_viewport(Control *p_overlay); void forward_spatial_force_draw_over_viewport(Control *p_overlay); void add_plugin(EditorPlugin *p_plugin); + void remove_plugin(EditorPlugin *p_plugin); void clear(); bool empty(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 0851485208..0f6c6349ed 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -418,13 +418,14 @@ void EditorPropertyArray::_length_changed(double p_page) { return; Variant array = object->get_array(); + int previous_size = array.call("size"); + array.call("resize", int(p_page)); - emit_changed(get_edited_property(), array, "", false); if (array.get_type() == Variant::ARRAY) { if (subtype != Variant::NIL) { int size = array.call("size"); - for (int i = 0; i < size; i++) { + for (int i = previous_size; i < size; i++) { if (array.get(i).get_type() == Variant::NIL) { Variant::CallError ce; array.set(i, Variant::construct(subtype, NULL, 0, ce)); @@ -432,7 +433,16 @@ void EditorPropertyArray::_length_changed(double p_page) { } } array = array.call("duplicate"); //dupe, so undo/redo works better + } else { + int size = array.call("size"); + // Pool*Array don't initialize their elements, have to do it manually + for (int i = previous_size; i < size; i++) { + Variant::CallError ce; + array.set(i, Variant::construct(array.get(i).get_type(), NULL, 0, ce)); + } } + + emit_changed(get_edited_property(), array, "", false); object->set_array(array); update_property(); } diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 1fa1fe9070..e0c292dc87 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -417,6 +417,10 @@ void EditorResourcePreview::check_for_invalidation(const String &p_path) { } } +void EditorResourcePreview::start() { + ERR_FAIL_COND(thread); + thread = Thread::create(_thread_func, this); +} void EditorResourcePreview::stop() { if (thread) { exit = true; @@ -428,13 +432,12 @@ void EditorResourcePreview::stop() { } EditorResourcePreview::EditorResourcePreview() { + thread = NULL; singleton = this; preview_mutex = Mutex::create(); preview_sem = Semaphore::create(); order = 0; exit = false; - - thread = Thread::create(_thread_func, this); } EditorResourcePreview::~EditorResourcePreview() { diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 85ac78d58f..c958bfbb74 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -126,6 +126,7 @@ public: void remove_preview_generator(const Ref<EditorResourcePreviewGenerator> &p_generator); void check_for_invalidation(const String &p_path); + void start(); void stop(); EditorResourcePreview(); diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 887a102aa4..06cadca1c0 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -32,6 +32,7 @@ #include "editor_export.h" #include "editor_node.h" +#include "editor_scale.h" void EditorRunNative::_notification(int p_what) { @@ -49,7 +50,7 @@ void EditorRunNative::_notification(int p_what) { im->clear_mipmaps(); if (!im->empty()) { - im->resize(16, 16); + im->resize(16 * EDSCALE, 16 * EDSCALE); Ref<ImageTexture> small_icon; small_icon.instance(); small_icon->create_from_image(im, 0); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index cbd8df315a..741a210950 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -389,12 +389,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("docks/scene_tree/relationship_line_color", Color::html("464646")); // FileSystem - _initial_set("docks/filesystem/display_mode", 0); - hints["docks/filesystem/display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/display_mode", PROPERTY_HINT_ENUM, "Tree only, Split"); _initial_set("docks/filesystem/thumbnail_size", 64); hints["docks/filesystem/thumbnail_size"] = PropertyInfo(Variant::INT, "docks/filesystem/thumbnail_size", PROPERTY_HINT_RANGE, "32,128,16"); - _initial_set("docks/filesystem/files_display_mode", 0); - hints["docks/filesystem/files_display_mode"] = PropertyInfo(Variant::INT, "docks/filesystem/files_display_mode", PROPERTY_HINT_ENUM, "Thumbnails,List"); _initial_set("docks/filesystem/always_show_folders", true); // Property editor diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index ce1d545510..ad3ce90afd 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -193,6 +193,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ int fc = 0; //count them and find version String version; + String contents_dir; while (ret == UNZ_OK) { @@ -225,6 +226,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ } version = data_str; + contents_dir = file.get_base_dir().trim_suffix("/").trim_suffix("\\"); } if (file.get_file().size() != 0) { @@ -268,7 +270,9 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ char fname[16384]; unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); - String file = String(fname).get_file(); + String file_path(fname); + + String file = file_path.get_file(); if (file.size() == 0) { ret = unzGoToNextFile(pkg); @@ -283,6 +287,23 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ unzReadCurrentFile(pkg, data.ptrw(), data.size()); unzCloseCurrentFile(pkg); + String base_dir = file_path.get_base_dir().trim_suffix("/").trim_suffix("\\"); + + if (base_dir != contents_dir && base_dir.begins_with(contents_dir)) { + base_dir = base_dir.substr(contents_dir.length(), file_path.length()).trim_prefix("/").trim_prefix("\\"); + file = base_dir.plus_file(file); + + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + ERR_CONTINUE(!da); + + String output_dir = template_path.plus_file(base_dir); + + if (!DirAccess::exists(output_dir)) { + Error mkdir_err = da->make_dir_recursive(output_dir); + ERR_CONTINUE(mkdir_err != OK); + } + } + if (p) { p->step(TTR("Importing:") + " " + file, fc); } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index b1aa75e124..0c3c222085 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -66,7 +66,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->set_selectable(0, true); String lpath = p_dir->get_path(); subdirectory_item->set_metadata(0, lpath); - if (!p_select_in_favorites && (path == lpath || ((display_mode_setting == DISPLAY_MODE_SETTING_SPLIT) && path.get_base_dir() == lpath))) { + if (!p_select_in_favorites && (path == lpath || ((display_mode == DISPLAY_MODE_SPLIT) && path.get_base_dir() == lpath))) { subdirectory_item->select(0); } @@ -84,7 +84,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand); // Create all items for the files in the subdirectory - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { for (int i = 0; i < p_dir->get_file_count(); i++) { String file_name = p_dir->get_file(i); @@ -229,19 +229,21 @@ void FileSystemDock::_update_tree(const Vector<String> p_uncollapsed_paths, bool updating_tree = false; } +void FileSystemDock::set_display_mode(DisplayMode p_display_mode) { + display_mode = p_display_mode; + emit_signal("display_mode_changed"); + _update_display_mode(false); +} + void FileSystemDock::_update_display_mode(bool p_force) { // Compute the new display mode - DisplayMode new_display_mode = (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) ? DISPLAY_MODE_TREE_ONLY : DISPLAY_MODE_SPLIT; - - if (p_force || new_display_mode != display_mode || old_display_mode_setting != display_mode_setting) { - display_mode = new_display_mode; - old_display_mode_setting = display_mode_setting; - button_toggle_display_mode->set_pressed(display_mode_setting == DISPLAY_MODE_SETTING_SPLIT ? true : false); + if (p_force || old_display_mode != display_mode) { + button_toggle_display_mode->set_pressed(display_mode == DISPLAY_MODE_SPLIT ? true : false); switch (display_mode) { case DISPLAY_MODE_TREE_ONLY: tree->show(); tree->set_v_size_flags(SIZE_EXPAND_FILL); - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { tree_search_box->show(); } else { tree_search_box->hide(); @@ -262,6 +264,7 @@ void FileSystemDock::_update_display_mode(bool p_force) { _update_file_list(true); break; } + old_display_mode = display_mode; } } @@ -269,9 +272,6 @@ void FileSystemDock::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_RESIZED: { - _update_display_mode(); - } break; case NOTIFICATION_ENTER_TREE: { if (initialized) @@ -302,7 +302,6 @@ void FileSystemDock::_notification(int p_what) { current_path->connect("text_entered", this, "_navigate_to_path"); - display_mode_setting = DisplayModeSetting(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); _update_display_mode(); @@ -362,27 +361,10 @@ void FileSystemDock::_notification(int p_what) { file_list_search_box->set_right_icon(get_icon("Search", ei)); file_list_search_box->set_clear_button_enabled(true); - bool should_update_files = false; - - // Update file list display mode - int new_file_list_mode = int(EditorSettings::get_singleton()->get("docks/filesystem/files_display_mode")); - if (new_file_list_mode != file_list_display_mode) { - set_file_list_display_mode(new_file_list_mode); - _update_file_list_display_mode_button(); - should_update_files = true; - } - - // Update display of files in tree - display_mode_setting = DisplayModeSetting(int(EditorSettings::get_singleton()->get("docks/filesystem/display_mode"))); - // Update always showfolders bool new_always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); if (new_always_show_folders != always_show_folders) { always_show_folders = new_always_show_folders; - should_update_files = true; - } - - if (should_update_files) { _update_file_list(true); } @@ -530,6 +512,7 @@ void FileSystemDock::_update_file_list_display_mode_button() { button_file_list_display_mode->set_icon(get_icon("FileList", "EditorIcons")); button_file_list_display_mode->set_tooltip(TTR("View items as a list.")); } + emit_signal("display_mode_changed"); } void FileSystemDock::_change_file_display() { @@ -1695,9 +1678,7 @@ void FileSystemDock::_rescan() { } void FileSystemDock::_toggle_split_mode(bool p_active) { - display_mode_setting = p_active ? DISPLAY_MODE_SETTING_SPLIT : DISPLAY_MODE_SETTING_TREE_ONLY; - EditorSettings::get_singleton()->set("docks/filesystem/display_mode", int(display_mode_setting)); - _update_display_mode(); + set_display_mode(p_active ? DISPLAY_MODE_SPLIT : DISPLAY_MODE_TREE_ONLY); } void FileSystemDock::fix_dependencies(const String &p_for_file) { @@ -1709,7 +1690,7 @@ void FileSystemDock::focus_on_filter() { file_list_search_box->grab_focus(); } -void FileSystemDock::set_file_list_display_mode(int p_mode) { +void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { if (p_mode == file_list_display_mode) return; @@ -2219,7 +2200,7 @@ void FileSystemDock::_update_import_dock() { // List selected Vector<String> selected; - if (display_mode_setting == DISPLAY_MODE_SETTING_TREE_ONLY) { + if (display_mode == DISPLAY_MODE_TREE_ONLY) { // Use the tree selected = _tree_get_selected(); @@ -2334,6 +2315,8 @@ void FileSystemDock::_bind_methods() { ADD_SIGNAL(MethodInfo("folder_removed", PropertyInfo(Variant::STRING, "folder"))); ADD_SIGNAL(MethodInfo("files_moved", PropertyInfo(Variant::STRING, "old_file"), PropertyInfo(Variant::STRING, "new_file"))); ADD_SIGNAL(MethodInfo("folder_moved", PropertyInfo(Variant::STRING, "old_folder"), PropertyInfo(Variant::STRING, "new_file"))); + + ADD_SIGNAL(MethodInfo("display_mode_changed")); } FileSystemDock::FileSystemDock(EditorNode *p_editor) { @@ -2564,11 +2547,10 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { history_max_size = 20; history.push_back("res://"); - display_mode = DISPLAY_MODE_SPLIT; + display_mode = DISPLAY_MODE_TREE_ONLY; + old_display_mode = DISPLAY_MODE_TREE_ONLY; file_list_display_mode = FILE_LIST_DISPLAY_THUMBNAILS; - display_mode_setting = DISPLAY_MODE_SETTING_TREE_ONLY; - old_display_mode_setting = DISPLAY_MODE_SETTING_TREE_ONLY; always_show_folders = false; } diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 237413acc4..e31afee23e 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -65,17 +65,12 @@ public: FILE_LIST_DISPLAY_LIST }; -private: - enum DisplayModeSetting { - DISPLAY_MODE_SETTING_TREE_ONLY, - DISPLAY_MODE_SETTING_SPLIT, - }; - enum DisplayMode { DISPLAY_MODE_TREE_ONLY, DISPLAY_MODE_SPLIT, }; +private: enum FileMenu { FILE_OPEN, FILE_INSTANCE, @@ -123,8 +118,7 @@ private: FileListDisplayMode file_list_display_mode; DisplayMode display_mode; - DisplayModeSetting display_mode_setting; - DisplayModeSetting old_display_mode_setting; + DisplayMode old_display_mode; PopupMenu *file_list_popup; PopupMenu *tree_popup; @@ -287,12 +281,16 @@ public: void fix_dependencies(const String &p_for_file); - void set_file_list_display_mode(int p_mode); - int get_split_offset() { return split_box->get_split_offset(); } void set_split_offset(int p_offset) { split_box->set_split_offset(p_offset); } void select_file(const String &p_file); + void set_display_mode(DisplayMode p_display_mode); + DisplayMode get_display_mode() { return display_mode; } + + void set_file_list_display_mode(FileListDisplayMode p_mode); + FileListDisplayMode get_file_list_display_mode() { return file_list_display_mode; }; + FileSystemDock(EditorNode *p_editor); ~FileSystemDock(); }; diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index e365471733..98f4947c2d 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -130,7 +130,7 @@ bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map return get_script_instance()->call("get_option_visibility", p_option, d); } -Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("import")), ERR_UNAVAILABLE); Dictionary options; diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 607d99e6e2..d396dd6d5b 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -51,7 +51,7 @@ public: virtual int get_import_order() const; virtual void get_import_options(List<ImportOption> *r_options, int p_preset) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata = NULL); }; #endif //EDITOR_IMPORT_PLUGIN_H diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp index b568cbda9b..18e53fc783 100644 --- a/editor/import/resource_importer_bitmask.cpp +++ b/editor/import/resource_importer_bitmask.cpp @@ -78,7 +78,7 @@ void ResourceImporterBitMap::get_import_options(List<ImportOption> *r_options, i r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5)); } -Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { int create_from = p_options["create_from"]; float threshold = p_options["threshold"]; diff --git a/editor/import/resource_importer_bitmask.h b/editor/import/resource_importer_bitmask.h index 7cfb0c4a98..166fa998e4 100644 --- a/editor/import/resource_importer_bitmask.h +++ b/editor/import/resource_importer_bitmask.h @@ -51,7 +51,7 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); ResourceImporterBitMap(); ~ResourceImporterBitMap(); diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index be5ce34c25..b4b3e0e551 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -77,7 +77,7 @@ void ResourceImporterCSVTranslation::get_import_options(List<ImportOption> *r_op r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "delimiter", PROPERTY_HINT_ENUM, "Comma,Semicolon,Tab"), 0)); } -Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { bool compress = p_options["compress"]; diff --git a/editor/import/resource_importer_csv_translation.h b/editor/import/resource_importer_csv_translation.h index cf16826535..6785b68d87 100644 --- a/editor/import/resource_importer_csv_translation.h +++ b/editor/import/resource_importer_csv_translation.h @@ -48,7 +48,7 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); ResourceImporterCSVTranslation(); }; diff --git a/editor/import/resource_importer_image.cpp b/editor/import/resource_importer_image.cpp index c3421466f2..1259e81be7 100644 --- a/editor/import/resource_importer_image.cpp +++ b/editor/import/resource_importer_image.cpp @@ -74,7 +74,7 @@ String ResourceImporterImage::get_preset_name(int p_idx) const { void ResourceImporterImage::get_import_options(List<ImportOption> *r_options, int p_preset) const { } -Error ResourceImporterImage::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterImage::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); if (!f) { diff --git a/editor/import/resource_importer_image.h b/editor/import/resource_importer_image.h index ffe05bdf58..3d5b99db2c 100644 --- a/editor/import/resource_importer_image.h +++ b/editor/import/resource_importer_image.h @@ -49,7 +49,7 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); ResourceImporterImage(); }; diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index e38265b619..7e3c4cecf4 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -191,7 +191,7 @@ void ResourceImporterLayeredTexture::_save_tex(const Vector<Ref<Image> > &p_imag memdelete(f); } -Error ResourceImporterLayeredTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterLayeredTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { int compress_mode = p_options["compress/mode"]; int no_bptc_if_rgb = p_options["compress/no_bptc_if_rgb"]; @@ -252,6 +252,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const } String extension = get_save_extension(); + Array formats_imported; if (compress_mode == COMPRESS_VIDEO_RAM) { //must import in all formats, in order of priority (so platform choses the best supported one. IE, etc2 over etc). @@ -270,6 +271,8 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const encode_bptc = false; } } + + formats_imported.push_back("bptc"); } if (encode_bptc) { @@ -284,23 +287,27 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const _save_tex(slices, p_save_path + ".s3tc." + extension, compress_mode, Image::COMPRESS_S3TC, mipmaps, tex_flags); r_platform_variants->push_back("s3tc"); ok_on_pc = true; + formats_imported.push_back("s3tc"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { _save_tex(slices, p_save_path + ".etc2." + extension, compress_mode, Image::COMPRESS_ETC2, mipmaps, tex_flags); r_platform_variants->push_back("etc2"); + formats_imported.push_back("etc2"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { _save_tex(slices, p_save_path + ".etc." + extension, compress_mode, Image::COMPRESS_ETC, mipmaps, tex_flags); r_platform_variants->push_back("etc"); + formats_imported.push_back("etc"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { _save_tex(slices, p_save_path + ".pvrtc." + extension, compress_mode, Image::COMPRESS_PVRTC4, mipmaps, tex_flags); r_platform_variants->push_back("pvrtc"); + formats_imported.push_back("pvrtc"); } if (!ok_on_pc) { @@ -311,9 +318,79 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const _save_tex(slices, p_save_path + "." + extension, compress_mode, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags); } + if (r_metadata) { + Dictionary metadata; + metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM; + if (formats_imported.size()) { + metadata["imported_formats"] = formats_imported; + } + *r_metadata = metadata; + } + return OK; } +const char *ResourceImporterLayeredTexture::compression_formats[] = { + "bptc", + "s3tc", + "etc", + "etc2", + "pvrtc", + NULL +}; +String ResourceImporterLayeredTexture::get_import_settings_string() const { + + String s; + + int index = 0; + while (compression_formats[index]) { + String setting_path = "rendering/vram_compression/import_" + String(compression_formats[index]); + bool test = ProjectSettings::get_singleton()->get(setting_path); + if (test) { + s += String(compression_formats[index]); + } + index++; + } + + return s; +} + +bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_path) const { + + //will become invalid if formats are missing to import + Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); + + if (!metadata.has("vram_texture")) { + return false; + } + + bool vram = metadata["vram_texture"]; + if (!vram) { + return true; //do not care about non vram + } + + Vector<String> formats_imported; + if (metadata.has("imported_formats")) { + formats_imported = metadata["imported_formats"]; + } + + int index = 0; + bool valid = true; + while (compression_formats[index]) { + String setting_path = "rendering/vram_compression/import_" + String(compression_formats[index]); + bool test = ProjectSettings::get_singleton()->get(setting_path); + if (test) { + if (formats_imported.find(compression_formats[index]) == -1) { + valid = false; + break; + } + } + index++; + } + + return valid; +} + ResourceImporterLayeredTexture *ResourceImporterLayeredTexture::singleton = NULL; ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() { diff --git a/editor/import/resource_importer_layered_texture.h b/editor/import/resource_importer_layered_texture.h index 6a616e09d6..6b393886b7 100644 --- a/editor/import/resource_importer_layered_texture.h +++ b/editor/import/resource_importer_layered_texture.h @@ -40,6 +40,7 @@ class ResourceImporterLayeredTexture : public ResourceImporter { GDCLASS(ResourceImporterLayeredTexture, ResourceImporter) bool is_3d; + static const char *compression_formats[]; protected: static void _texture_reimport_srgb(const Ref<StreamTexture> &p_tex); @@ -76,10 +77,13 @@ public: void _save_tex(const Vector<Ref<Image> > &p_images, const String &p_to_path, int p_compress_mode, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags); - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); void update_imports(); + virtual bool are_import_settings_valid(const String &p_path) const; + virtual String get_import_settings_string() const; + void set_3d(bool p_3d) { is_3d = p_3d; } ResourceImporterLayeredTexture(); ~ResourceImporterLayeredTexture(); diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 030b54a589..e950421476 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -499,7 +499,7 @@ bool ResourceImporterOBJ::get_option_visibility(const String &p_option, const Ma return true; } -Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { List<Ref<Mesh> > meshes; diff --git a/editor/import/resource_importer_obj.h b/editor/import/resource_importer_obj.h index effc56ad95..b2a53f582c 100644 --- a/editor/import/resource_importer_obj.h +++ b/editor/import/resource_importer_obj.h @@ -61,7 +61,7 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); ResourceImporterOBJ(); }; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index ad436b2797..76552575da 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1183,7 +1183,7 @@ Ref<Animation> ResourceImporterScene::import_animation_from_other_importer(Edito return importer->import_animation(p_path, p_flags, p_bake_fps); } -Error ResourceImporterScene::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterScene::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { String src_path = p_source_file; diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 9d06b411d6..99f8b1a8e0 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -153,7 +153,7 @@ public: void _filter_tracks(Node *scene, const String &p_text); void _optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle); - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); Node *import_scene_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps); Ref<Animation> import_animation_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index a3bc9d0ec9..631b2359c5 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -219,7 +219,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options, r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "svg/scale", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 1.0)); } -void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal) { +void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_force_po2_for_compressed) { FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE); f->store_8('G'); @@ -227,8 +227,20 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String f->store_8('S'); f->store_8('T'); //godot streamable texture - f->store_32(p_image->get_width()); - f->store_32(p_image->get_height()); + bool resize_to_po2 = false; + + if (p_compress_mode == COMPRESS_VIDEO_RAM && p_force_po2_for_compressed && (p_mipmaps || p_texture_flags & Texture::FLAG_REPEAT)) { + resize_to_po2 = true; + f->store_16(next_power_of_2(p_image->get_width())); + f->store_16(p_image->get_width()); + f->store_16(next_power_of_2(p_image->get_height())); + f->store_16(p_image->get_height()); + } else { + f->store_16(p_image->get_width()); + f->store_16(0); + f->store_16(p_image->get_height()); + f->store_16(0); + } f->store_32(p_texture_flags); uint32_t format = 0; @@ -310,6 +322,9 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String case COMPRESS_VIDEO_RAM: { Ref<Image> image = p_image->duplicate(); + if (resize_to_po2) { + image->resize_to_po2(); + } if (p_mipmaps) { image->generate_mipmaps(p_force_normal); } @@ -360,7 +375,7 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String memdelete(f); } -Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { int compress_mode = p_options["compress/mode"]; float lossy = p_options["compress/lossy_quality"]; @@ -386,6 +401,8 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String if (err != OK) return err; + Array formats_imported; + int tex_flags = 0; if (repeat > 0) tex_flags |= Texture::FLAG_REPEAT; @@ -470,6 +487,8 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String can_bptc = false; } } + + formats_imported.push_back("bptc"); } if (!can_bptc && is_hdr && !force_rgbe) { @@ -478,26 +497,30 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String } if (can_bptc || can_s3tc) { - _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, can_bptc ? Image::COMPRESS_BPTC : Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, can_bptc ? Image::COMPRESS_BPTC : Image::COMPRESS_S3TC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false); r_platform_variants->push_back("s3tc"); + formats_imported.push_back("s3tc"); ok_on_pc = true; } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc2")) { - _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false); r_platform_variants->push_back("etc2"); + formats_imported.push_back("etc2"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_etc")) { - _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true); r_platform_variants->push_back("etc"); + formats_imported.push_back("etc"); } if (ProjectSettings::get_singleton()->get("rendering/vram_compression/import_pvrtc")) { - _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + _save_stex(image, p_save_path + ".pvrtc.stex", compress_mode, lossy, Image::COMPRESS_PVRTC4, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, true); r_platform_variants->push_back("pvrtc"); + formats_imported.push_back("pvrtc"); } if (!ok_on_pc) { @@ -505,12 +528,81 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String } } else { //import normally - _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal); + _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, tex_flags, stream, detect_3d, detect_srgb, force_rgbe, detect_normal, force_normal, false); } + if (r_metadata) { + Dictionary metadata; + metadata["vram_texture"] = compress_mode == COMPRESS_VIDEO_RAM; + if (formats_imported.size()) { + metadata["imported_formats"] = formats_imported; + } + *r_metadata = metadata; + } return OK; } +const char *ResourceImporterTexture::compression_formats[] = { + "bptc", + "s3tc", + "etc", + "etc2", + "pvrtc", + NULL +}; +String ResourceImporterTexture::get_import_settings_string() const { + + String s; + + int index = 0; + while (compression_formats[index]) { + String setting_path = "rendering/vram_compression/import_" + String(compression_formats[index]); + bool test = ProjectSettings::get_singleton()->get(setting_path); + if (test) { + s += String(compression_formats[index]); + } + index++; + } + + return s; +} + +bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) const { + + //will become invalid if formats are missing to import + Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); + + if (!metadata.has("vram_texture")) { + return false; + } + + bool vram = metadata["vram_texture"]; + if (!vram) { + return true; //do not care about non vram + } + + Vector<String> formats_imported; + if (metadata.has("imported_formats")) { + formats_imported = metadata["imported_formats"]; + } + + int index = 0; + bool valid = true; + while (compression_formats[index]) { + String setting_path = "rendering/vram_compression/import_" + String(compression_formats[index]); + bool test = ProjectSettings::get_singleton()->get(setting_path); + if (test) { + if (formats_imported.find(compression_formats[index]) == -1) { + valid = false; + break; + } + } + index++; + } + + return valid; +} + ResourceImporterTexture *ResourceImporterTexture::singleton = NULL; ResourceImporterTexture::ResourceImporterTexture() { diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h index 408af1edcf..ef74e4e41e 100644 --- a/editor/import/resource_importer_texture.h +++ b/editor/import/resource_importer_texture.h @@ -54,6 +54,7 @@ protected: static void _texture_reimport_normal(const Ref<StreamTexture> &p_tex); static ResourceImporterTexture *singleton; + static const char *compression_formats[]; public: static ResourceImporterTexture *get_singleton() { return singleton; } @@ -83,12 +84,15 @@ public: virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; - void _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal); + void _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_force_rgbe, bool p_detect_normal, bool p_force_normal, bool p_force_po2_for_compressed); - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); void update_imports(); + virtual bool are_import_settings_valid(const String &p_path) const; + virtual String get_import_settings_string() const; + ResourceImporterTexture(); ~ResourceImporterTexture(); }; diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index 76ab7a7037..857d8992fd 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -82,7 +82,7 @@ void ResourceImporterWAV::get_import_options(List<ImportOption> *r_options, int r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Disabled,RAM (Ima-ADPCM)"), 0)); } -Error ResourceImporterWAV::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { +Error ResourceImporterWAV::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { /* STEP 1, READ WAVE FILE */ diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h index 755dea3d84..f993f9e7bc 100644 --- a/editor/import/resource_importer_wav.h +++ b/editor/import/resource_importer_wav.h @@ -161,7 +161,7 @@ public: } } - virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL); ResourceImporterWAV(); }; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index eef3358260..afe2573898 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -231,6 +231,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { } pb->set_percent_visible(false); + pb->set_custom_minimum_size(Vector2(0, 14) * EDSCALE); animations[E->get()] = pb; node->add_child(pb); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 071a0287e6..58d7968723 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -92,7 +92,12 @@ Ref<Texture> EditorTexturePreviewPlugin::generate(const RES &p_from, const Size2 if (!tex.is_valid()) { return Ref<Texture>(); } + Ref<Image> atlas = tex->get_data(); + if (!atlas.is_valid()) { + return Ref<Texture>(); + } + img = atlas->get_rect(atex->get_region()); } else if (ltex.is_valid()) { img = ltex->to_image(); @@ -845,15 +850,16 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c font->draw(canvas_item, pos, sampled_text); - VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture - preview_done = false; + VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture VS::get_singleton()->request_frame_drawn_callback(const_cast<EditorFontPreviewPlugin *>(this), "_preview_done", Variant()); while (!preview_done) { OS::get_singleton()->delay_usec(10); } + VS::get_singleton()->canvas_item_clear(canvas_item); + Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture); ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>()); @@ -878,7 +884,11 @@ Ref<Texture> EditorFontPreviewPlugin::generate_from_path(const String &p_path, c Ref<Texture> EditorFontPreviewPlugin::generate(const RES &p_from, const Size2 p_size) const { - return generate_from_path(p_from->get_path(), p_size); + String path = p_from->get_path(); + if (!FileAccess::exists(path)) { + return Ref<Texture>(); + } + return generate_from_path(path, p_size); } EditorFontPreviewPlugin::EditorFontPreviewPlugin() { diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index cc2e65cf6d..020a68a7ed 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -53,6 +53,7 @@ void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) { get_text_edit()->set_text(p_shader->get_code()); + _validate_script(); _line_col_changed(); } diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 364b0085f7..6256b8b055 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -60,6 +60,7 @@ public: RID instance; Ref<ArrayMesh> mesh; + Ref<Material> material; RID skeleton; bool billboard; bool unscaled; @@ -103,7 +104,7 @@ protected: public: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false); - void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); + void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID(), const Ref<Material> &p_material = Ref<Material>()); void add_collision_segments(const Vector<Vector3> &p_lines); void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh); void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 1bcb7513e0..5f4c4a610a 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -1425,6 +1425,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { workspace->update(); } else { creating_shape = true; + edited_collision_shape = Ref<ConvexPolygonShape2D>(); current_shape.resize(0); current_shape.push_back(snap_point(pos)); workspace->update(); @@ -1444,6 +1445,7 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { } else if (tools[SHAPE_NEW_RECTANGLE]->is_pressed()) { if (mb.is_valid()) { if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) { + edited_collision_shape = Ref<ConvexPolygonShape2D>(); current_shape.resize(0); current_shape.push_back(snap_point(shape_anchor)); current_shape.push_back(snap_point(shape_anchor + Vector2(current_tile_region.size.x, 0))); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 7a4b7d091f..0a8e7ea779 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -179,7 +179,7 @@ void EditorSpatialGizmo::Instance::create_instance(Spatial *p_base, bool p_hidde VS::get_singleton()->instance_set_layer_mask(instance, layer); //gizmos are 26 } -void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const RID &p_skeleton) { +void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const RID &p_skeleton, const Ref<Material> &p_material) { ERR_FAIL_COND(!spatial_node); Instance ins; @@ -187,9 +187,13 @@ void EditorSpatialGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard ins.billboard = p_billboard; ins.mesh = p_mesh; ins.skeleton = p_skeleton; + ins.material = p_material; if (valid) { ins.create_instance(spatial_node, hidden); VS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform()); + if (ins.material.is_valid()) { + VS::get_singleton()->instance_geometry_set_material_override(ins.instance, p_material->get_rid()); + } } instances.push_back(ins); @@ -726,7 +730,7 @@ void EditorSpatialGizmo::set_plugin(EditorSpatialGizmoPlugin *p_plugin) { void EditorSpatialGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard"), &EditorSpatialGizmo::add_lines, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "billboard", "skeleton"), &EditorSpatialGizmo::add_mesh, DEFVAL(false), DEFVAL(RID())); + ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "billboard", "skeleton", "material"), &EditorSpatialGizmo::add_mesh, DEFVAL(false), DEFVAL(RID()), DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("add_collision_segments", "segments"), &EditorSpatialGizmo::add_collision_segments); ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles"), &EditorSpatialGizmo::add_collision_triangles); ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale"), &EditorSpatialGizmo::add_unscaled_billboard, DEFVAL(1)); @@ -3519,9 +3523,8 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { if (Object::cast_to<ConcavePolygonShape>(*s)) { Ref<ConcavePolygonShape> cs2 = s; - Ref<ArrayMesh> mesh = cs2->get_debug_mesh()->duplicate(); - mesh->surface_set_material(0, material); - p_gizmo->add_mesh(mesh); + Ref<ArrayMesh> mesh = cs2->get_debug_mesh(); + p_gizmo->add_mesh(mesh, false, RID(), material); } if (Object::cast_to<RayShape>(*s)) { |