summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/dynamic_font_import_settings.cpp1020
-rw-r--r--editor/import/dynamic_font_import_settings.h90
-rw-r--r--editor/import/post_import_plugin_skeleton_renamer.cpp178
-rw-r--r--editor/import/post_import_plugin_skeleton_renamer.h46
-rw-r--r--editor/import/post_import_plugin_skeleton_rest_fixer.cpp418
-rw-r--r--editor/import/post_import_plugin_skeleton_rest_fixer.h46
-rw-r--r--editor/import/resource_importer_bmfont.cpp12
-rw-r--r--editor/import/resource_importer_dynamic_font.cpp192
-rw-r--r--editor/import/resource_importer_dynamic_font.h3
-rw-r--r--editor/import/resource_importer_imagefont.cpp17
-rw-r--r--editor/import/resource_importer_layered_texture.cpp2
-rw-r--r--editor/import/resource_importer_scene.cpp136
-rw-r--r--editor/import/resource_importer_scene.h4
-rw-r--r--editor/import/resource_importer_texture.cpp8
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp26
-rw-r--r--editor/import/resource_importer_wav.cpp64
-rw-r--r--editor/import/scene_import_settings.cpp63
-rw-r--r--editor/import/scene_import_settings.h1
18 files changed, 1342 insertions, 984 deletions
diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp
index e546f01205..ee13a1a9c1 100644
--- a/editor/import/dynamic_font_import_settings.cpp
+++ b/editor/import/dynamic_font_import_settings.cpp
@@ -41,50 +41,44 @@
/* Settings data */
/*************************************************************************/
-class DynamicFontImportSettingsData : public RefCounted {
- GDCLASS(DynamicFontImportSettingsData, RefCounted)
- friend class DynamicFontImportSettings;
-
- HashMap<StringName, Variant> settings;
- HashMap<StringName, Variant> defaults;
- List<ResourceImporter::ImportOption> options;
- DynamicFontImportSettings *owner = nullptr;
-
- bool _set(const StringName &p_name, const Variant &p_value) {
- if (defaults.has(p_name) && defaults[p_name] == p_value) {
- settings.erase(p_name);
- } else {
- settings[p_name] = p_value;
- }
- return true;
+bool DynamicFontImportSettingsData::_set(const StringName &p_name, const Variant &p_value) {
+ if (defaults.has(p_name) && defaults[p_name] == p_value) {
+ settings.erase(p_name);
+ } else {
+ settings[p_name] = p_value;
}
+ return true;
+}
- bool _get(const StringName &p_name, Variant &r_ret) const {
- if (settings.has(p_name)) {
- r_ret = settings[p_name];
- return true;
- }
- if (defaults.has(p_name)) {
- r_ret = defaults[p_name];
- return true;
- }
- return false;
+bool DynamicFontImportSettingsData::_get(const StringName &p_name, Variant &r_ret) const {
+ if (settings.has(p_name)) {
+ r_ret = settings[p_name];
+ return true;
+ }
+ if (defaults.has(p_name)) {
+ r_ret = defaults[p_name];
+ return true;
}
+ return false;
+}
- void _get_property_list(List<PropertyInfo> *p_list) const {
- for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
- if (owner && owner->import_settings_data.is_valid()) {
- if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size" || E->get().option.name == "oversampling")) {
- continue;
- }
- if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) {
- continue;
- }
+void DynamicFontImportSettingsData::_get_property_list(List<PropertyInfo> *p_list) const {
+ for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
+ if (owner && owner->import_settings_data.is_valid()) {
+ if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size" || E->get().option.name == "oversampling")) {
+ continue;
+ }
+ if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) {
+ continue;
}
- p_list->push_back(E->get().option);
}
+ p_list->push_back(E->get().option);
}
-};
+}
+
+Ref<FontFile> DynamicFontImportSettingsData::get_font() const {
+ return fd;
+}
/*************************************************************************/
/* Glyph ranges */
@@ -454,54 +448,32 @@ void DynamicFontImportSettings::_add_glyph_range_item(int32_t p_start, int32_t p
void DynamicFontImportSettings::_main_prop_changed(const String &p_edited_property) {
// Update font preview.
- if (p_edited_property == "antialiased") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_antialiased(import_settings_data->get("antialiased"));
- }
- } else if (p_edited_property == "generate_mipmaps") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_generate_mipmaps(import_settings_data->get("generate_mipmaps"));
- }
- } else if (p_edited_property == "multichannel_signed_distance_field") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
- }
- _variation_selected();
- _variations_validate();
- } else if (p_edited_property == "msdf_pixel_range") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
- }
- } else if (p_edited_property == "msdf_size") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_msdf_size(import_settings_data->get("msdf_size"));
- }
- } else if (p_edited_property == "force_autohinter") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_force_autohinter(import_settings_data->get("force_autohinter"));
- }
- } else if (p_edited_property == "hinting") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
- }
- } else if (p_edited_property == "subpixel_positioning") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
- }
- } else if (p_edited_property == "embolden") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_embolden(import_settings_data->get("embolden"));
- }
- } else if (p_edited_property == "transform") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_transform(import_settings_data->get("transform"));
- }
- } else if (p_edited_property == "oversampling") {
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_oversampling(import_settings_data->get("oversampling"));
+ if (font_preview.is_valid()) {
+ if (p_edited_property == "antialiased") {
+ font_preview->set_antialiased(import_settings_data->get("antialiased"));
+ } else if (p_edited_property == "generate_mipmaps") {
+ font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps"));
+ } else if (p_edited_property == "multichannel_signed_distance_field") {
+ font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
+ _variation_selected();
+ _variations_validate();
+ } else if (p_edited_property == "msdf_pixel_range") {
+ font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
+ } else if (p_edited_property == "msdf_size") {
+ font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
+ } else if (p_edited_property == "force_autohinter") {
+ font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
+ } else if (p_edited_property == "hinting") {
+ font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
+ } else if (p_edited_property == "subpixel_positioning") {
+ font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
+ } else if (p_edited_property == "oversampling") {
+ font_preview->set_oversampling(import_settings_data->get("oversampling"));
}
}
+
font_preview_label->add_theme_font_override("font", font_preview);
+ font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE);
font_preview_label->update();
}
@@ -530,6 +502,7 @@ void DynamicFontImportSettings::_variation_add() {
import_variation_data->options = options_variations;
inspector_vars->edit(import_variation_data.ptr());
import_variation_data->notify_property_list_changed();
+ import_variation_data->fd = font_main;
vars_item->set_metadata(0, import_variation_data);
@@ -544,6 +517,10 @@ void DynamicFontImportSettings::_variation_selected() {
inspector_vars->edit(import_variation_data.ptr());
import_variation_data->notify_property_list_changed();
+
+ label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(import_variation_data->selected_glyphs.size()));
+ _range_selected();
+ _change_text_opts();
}
}
@@ -607,63 +584,91 @@ void DynamicFontImportSettings::_variations_validate() {
}
/*************************************************************************/
-/* Page 3 callbacks: Text to select glyphs */
+/* Page 2.1 callbacks: Text to select glyphs */
/*************************************************************************/
void DynamicFontImportSettings::_change_text_opts() {
- Vector<String> ftr = ftr_edit->get_text().split(",");
- for (int i = 0; i < ftr.size(); i++) {
- Vector<String> tokens = ftr[i].split("=");
- if (tokens.size() == 2) {
- text_edit->set_opentype_feature(tokens[0], tokens[1].to_int());
- } else if (tokens.size() == 1) {
- text_edit->set_opentype_feature(tokens[0], 1);
- }
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
}
- text_edit->set_language(lang_edit->get_text());
+ if (import_variation_data.is_null()) {
+ return;
+ }
+
+ Ref<FontVariation> font_main_text;
+ font_main_text.instantiate();
+ font_main_text->set_base_font(font_main);
+ font_main_text->set_opentype_features(text_settings_data->get("opentype_features"));
+ font_main_text->set_variation_opentype(import_variation_data->get("variation_opentype"));
+ font_main_text->set_variation_embolden(import_variation_data->get("variation_embolden"));
+ font_main_text->set_variation_face_index(import_variation_data->get("variation_face_index"));
+ font_main_text->set_variation_transform(import_variation_data->get("variation_transform"));
+
+ text_edit->add_theme_font_override("font", font_main_text);
}
void DynamicFontImportSettings::_glyph_clear() {
- selected_glyphs.clear();
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return;
+ }
+
+ import_variation_data->selected_glyphs.clear();
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(import_variation_data->selected_glyphs.size()));
_range_selected();
}
void DynamicFontImportSettings::_glyph_text_selected() {
- Dictionary ftrs;
- Vector<String> ftr = ftr_edit->get_text().split(",");
- for (int i = 0; i < ftr.size(); i++) {
- Vector<String> tokens = ftr[i].split("=");
- if (tokens.size() == 2) {
- ftrs[tokens[0]] = tokens[1].to_int();
- } else if (tokens.size() == 1) {
- ftrs[tokens[0]] = 1;
- }
- }
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return;
+ }
RID text_rid = TS->create_shaped_text();
if (text_rid.is_valid()) {
- TS->shaped_text_add_string(text_rid, text_edit->get_text(), font_main->get_rids(), 16, ftrs, text_edit->get_language());
+ TS->shaped_text_add_string(text_rid, text_edit->get_text(), font_main->get_rids(), 16, text_settings_data->get("opentype_features"), text_settings_data->get("language"));
TS->shaped_text_shape(text_rid);
const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
for (int i = 0; i < gl_size; i++) {
if (gl[i].font_rid.is_valid() && gl[i].index != 0) {
- selected_glyphs.insert(gl[i].index);
+ import_variation_data->selected_glyphs.insert(gl[i].index);
}
}
TS->free_rid(text_rid);
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(import_variation_data->selected_glyphs.size()));
}
_range_selected();
}
/*************************************************************************/
-/* Page 4 callbacks: Character map */
+/* Page 2.2 callbacks: Character map */
/*************************************************************************/
void DynamicFontImportSettings::_glyph_selected() {
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return;
+ }
+
TreeItem *item = glyph_table->get_selected();
ERR_FAIL_NULL(item);
@@ -681,7 +686,7 @@ void DynamicFontImportSettings::_glyph_selected() {
item->clear_custom_bg_color(glyph_table->get_selected_column());
}
}
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(import_variation_data->selected_glyphs.size()));
item = glyph_tree->get_selected();
ERR_FAIL_NULL(item);
@@ -694,7 +699,7 @@ void DynamicFontImportSettings::_glyph_selected() {
total_chars--;
}
- if (selected_chars.has(i)) {
+ if (import_variation_data->selected_chars.has(i)) {
selected_count++;
}
}
@@ -724,6 +729,16 @@ void DynamicFontImportSettings::_range_selected() {
}
void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return;
+ }
+
glyph_table->clear();
TreeItem *root = glyph_table->create_item();
@@ -736,6 +751,8 @@ void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
TreeItem *item = nullptr;
int col = 0;
+ Ref<Font> font_main_big = font_main->duplicate();
+
for (int32_t c = p_start; c <= p_end; c++) {
if (col == 0) {
item = glyph_table->create_item(root);
@@ -748,7 +765,7 @@ void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
if (font_main->has_char(c)) {
item->set_text(col + 1, String::chr(c));
item->set_custom_color(col + 1, Color(1, 1, 1));
- if (selected_chars.has(c) || (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size(SNAME("font_size")) * 2, c)))) {
+ if (import_variation_data->selected_chars.has(c) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) {
item->set_custom_color(col + 1, fcol);
item->set_custom_bg_color(col + 1, scol);
} else {
@@ -761,7 +778,8 @@ void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
item->set_metadata(col + 1, c);
item->set_text_alignment(col + 1, HORIZONTAL_ALIGNMENT_CENTER);
item->set_selectable(col + 1, true);
- item->set_custom_font(col + 1, font_main);
+
+ item->set_custom_font(col + 1, font_main_big);
item->set_custom_font_size(col + 1, get_theme_font_size(SNAME("font_size")) * 2);
col++;
@@ -769,41 +787,61 @@ void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
col = 0;
}
}
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(import_variation_data->selected_glyphs.size()));
}
bool DynamicFontImportSettings::_char_update(int32_t p_char) {
- if (selected_chars.has(p_char)) {
- selected_chars.erase(p_char);
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return false;
+ }
+
+ if (import_variation_data->selected_chars.has(p_char)) {
+ import_variation_data->selected_chars.erase(p_char);
return false;
- } else if (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size(SNAME("font_size")) * 2, p_char))) {
- selected_glyphs.erase(font_main->get_data(0)->get_glyph_index(get_theme_font_size(SNAME("font_size")) * 2, p_char));
+ } else if (font_main.is_valid() && font_main.is_valid() && import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, p_char))) {
+ import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, p_char));
return false;
} else {
- selected_chars.insert(p_char);
+ import_variation_data->selected_chars.insert(p_char);
return true;
}
}
void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) {
+ Ref<DynamicFontImportSettingsData> import_variation_data;
+
+ TreeItem *vars_item = vars_list->get_selected();
+ if (vars_item) {
+ import_variation_data = vars_item->get_metadata(0);
+ }
+ if (import_variation_data.is_null()) {
+ return;
+ }
+
bool all_selected = true;
for (int32_t i = p_start; i <= p_end; i++) {
if (font_main->has_char(i)) {
- if (font_main->get_data(0).is_valid()) {
- all_selected = all_selected && (selected_chars.has(i) || (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size(SNAME("font_size")) * 2, i))));
+ if (font_main.is_valid()) {
+ all_selected = all_selected && (import_variation_data->selected_chars.has(i) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, i)));
} else {
- all_selected = all_selected && selected_chars.has(i);
+ all_selected = all_selected && import_variation_data->selected_chars.has(i);
}
}
}
for (int32_t i = p_start; i <= p_end; i++) {
if (font_main->has_char(i)) {
if (!all_selected) {
- selected_chars.insert(i);
+ import_variation_data->selected_chars.insert(i);
} else {
- selected_chars.erase(i);
- if (font_main->get_data(0).is_valid()) {
- selected_glyphs.erase(font_main->get_data(0)->get_glyph_index(get_theme_font_size(SNAME("font_size")) * 2, i));
+ import_variation_data->selected_chars.erase(i);
+ if (font_main.is_valid()) {
+ import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, i));
}
}
}
@@ -816,106 +854,6 @@ void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) {
}
/*************************************************************************/
-/* Page 5 callbacks: CMetadata override */
-/*************************************************************************/
-
-void DynamicFontImportSettings::_lang_add() {
- locale_select->popup_locale_dialog();
-}
-
-void DynamicFontImportSettings::_lang_add_item(const String &p_locale) {
- TreeItem *lang_item = lang_list->create_item(lang_list_root);
- ERR_FAIL_NULL(lang_item);
-
- lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- lang_item->set_editable(0, true);
- lang_item->set_checked(0, false);
- lang_item->set_text(1, p_locale);
- lang_item->set_editable(1, true);
- lang_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- lang_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
-}
-
-void DynamicFontImportSettings::_lang_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
- if (p_button != MouseButton::LEFT) {
- return;
- }
-
- TreeItem *lang_item = (TreeItem *)p_item;
- ERR_FAIL_NULL(lang_item);
-
- lang_list_root->remove_child(lang_item);
- memdelete(lang_item);
-}
-
-void DynamicFontImportSettings::_ot_add() {
- menu_ot->set_position(ot_list->get_screen_transform().xform(ot_list->get_local_mouse_position()));
- menu_ot->set_size(Vector2(1, 1));
- menu_ot->popup();
-}
-
-void DynamicFontImportSettings::_ot_add_item(int p_option) {
- String name = TS->tag_to_name(p_option);
- for (TreeItem *ot_item = ot_list_root->get_first_child(); ot_item; ot_item = ot_item->get_next()) {
- if (ot_item->get_text(0) == name) {
- return;
- }
- }
- TreeItem *ot_item = ot_list->create_item(ot_list_root);
- ERR_FAIL_NULL(ot_item);
-
- ot_item->set_text(0, name);
- ot_item->set_editable(0, false);
- ot_item->set_text(1, "1");
- ot_item->set_editable(1, true);
- ot_item->add_button(2, ot_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- ot_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
-}
-
-void DynamicFontImportSettings::_ot_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
- if (p_button != MouseButton::LEFT) {
- return;
- }
-
- TreeItem *ot_item = (TreeItem *)p_item;
- ERR_FAIL_NULL(ot_item);
-
- ot_list_root->remove_child(ot_item);
- memdelete(ot_item);
-}
-
-void DynamicFontImportSettings::_script_add() {
- menu_scripts->set_position(script_list->get_screen_position() + script_list->get_local_mouse_position());
- menu_scripts->reset_size();
- menu_scripts->popup();
-}
-
-void DynamicFontImportSettings::_script_add_item(int p_option) {
- TreeItem *script_item = script_list->create_item(script_list_root);
- ERR_FAIL_NULL(script_item);
-
- script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- script_item->set_editable(0, true);
- script_item->set_checked(0, false);
- script_item->set_text(1, script_codes[p_option]);
- script_item->set_editable(1, true);
- script_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- script_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
-}
-
-void DynamicFontImportSettings::_script_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
- if (p_button != MouseButton::LEFT) {
- return;
- }
-
- TreeItem *script_item = (TreeItem *)p_item;
- ERR_FAIL_NULL(script_item);
-
- script_list_root->remove_child(script_item);
- memdelete(script_item);
-}
-
-/*************************************************************************/
/* Common */
/*************************************************************************/
@@ -934,10 +872,7 @@ void DynamicFontImportSettings::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
- add_lang->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- add_script->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
add_var->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- add_ot->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
} break;
}
}
@@ -945,6 +880,7 @@ void DynamicFontImportSettings::_notification(int p_what) {
void DynamicFontImportSettings::_re_import() {
HashMap<StringName, Variant> main_settings;
+ main_settings["face_index"] = import_settings_data->get("face_index");
main_settings["antialiased"] = import_settings_data->get("antialiased");
main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps");
main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field");
@@ -953,90 +889,40 @@ void DynamicFontImportSettings::_re_import() {
main_settings["force_autohinter"] = import_settings_data->get("force_autohinter");
main_settings["hinting"] = import_settings_data->get("hinting");
main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning");
- main_settings["embolden"] = import_settings_data->get("embolden");
- main_settings["transform"] = import_settings_data->get("transform");
main_settings["oversampling"] = import_settings_data->get("oversampling");
+ main_settings["fallbacks"] = import_settings_data->get("fallbacks");
main_settings["compress"] = import_settings_data->get("compress");
- Vector<String> variations;
+ Array configurations;
for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) {
- String variation;
Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
ERR_FAIL_NULL(import_variation_data);
- String name = vars_item->get_text(0);
- variation += ("name=" + name);
+ Dictionary preload_config;
+ preload_config["name"] = vars_item->get_text(0);
+
for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) {
- if (!variation.is_empty()) {
- variation += ",";
- }
- variation += (String(E.key) + "=" + String(E.value));
- }
- variations.push_back(variation);
- }
- main_settings["preload/configurations"] = variations;
-
- Vector<String> langs_enabled;
- Vector<String> langs_disabled;
- for (TreeItem *lang_item = lang_list_root->get_first_child(); lang_item; lang_item = lang_item->get_next()) {
- bool selected = lang_item->is_checked(0);
- String name = lang_item->get_text(1);
- if (selected) {
- langs_enabled.push_back(name);
- } else {
- langs_disabled.push_back(name);
- }
- }
- main_settings["support_overrides/language_enabled"] = langs_enabled;
- main_settings["support_overrides/language_disabled"] = langs_disabled;
-
- Vector<String> scripts_enabled;
- Vector<String> scripts_disabled;
- for (TreeItem *script_item = script_list_root->get_first_child(); script_item; script_item = script_item->get_next()) {
- bool selected = script_item->is_checked(0);
- String name = script_item->get_text(1);
- if (selected) {
- scripts_enabled.push_back(name);
- } else {
- scripts_disabled.push_back(name);
+ preload_config[E.key] = E.value;
}
- }
- main_settings["support_overrides/script_enabled"] = scripts_enabled;
- main_settings["support_overrides/script_disabled"] = scripts_disabled;
-
- if (!selected_chars.is_empty()) {
- Vector<String> ranges;
- char32_t start = selected_chars.front()->get();
- for (RBSet<char32_t>::Element *E = selected_chars.front()->next(); E; E = E->next()) {
- if (E->prev() && ((E->prev()->get() + 1) != E->get())) {
- ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(E->prev()->get(), 16));
- start = E->get();
- }
+
+ Array chars;
+ for (const char32_t &E : import_variation_data->selected_chars) {
+ chars.push_back(E);
}
- ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(selected_chars.back()->get(), 16));
- main_settings["preload/char_ranges"] = ranges;
- }
+ preload_config["chars"] = chars;
- if (!selected_glyphs.is_empty()) {
- Vector<String> ranges;
- int32_t start = selected_glyphs.front()->get();
- for (RBSet<int32_t>::Element *E = selected_glyphs.front()->next(); E; E = E->next()) {
- if (E->prev() && ((E->prev()->get() + 1) != E->get())) {
- ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(E->prev()->get(), 16));
- start = E->get();
- }
+ Array glyphs;
+ for (const int32_t &E : import_variation_data->selected_glyphs) {
+ glyphs.push_back(E);
}
- ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(selected_glyphs.back()->get(), 16));
- main_settings["preload/glyph_ranges"] = ranges;
- }
+ preload_config["glyphs"] = glyphs;
- Dictionary ot_ov;
- for (TreeItem *ot_item = ot_list_root->get_first_child(); ot_item; ot_item = ot_item->get_next()) {
- String tag = ot_item->get_text(0);
- int32_t value = ot_item->get_text(1).to_int();
- ot_ov[tag] = value;
+ configurations.push_back(preload_config);
}
- main_settings["opentype_feature_overrides"] = ot_ov;
+ main_settings["preload"] = configurations;
+ main_settings["language_support"] = import_settings_data->get("language_support");
+ main_settings["script_support"] = import_settings_data->get("script_support");
+ main_settings["opentype_features"] = import_settings_data->get("opentype_features");
if (OS::get_singleton()->is_stdout_verbose()) {
print_line("Import settings:");
@@ -1053,33 +939,33 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
Vector<uint8_t> data = FileAccess::get_file_as_array(p_path);
// Load font for preview.
- Ref<FontData> dfont_prev;
- dfont_prev.instantiate();
- dfont_prev->set_data(data);
-
font_preview.instantiate();
- font_preview->add_data(dfont_prev);
+ font_preview->set_data(data);
+ String font_name = vformat("%s (%s)", font_preview->get_font_name(), font_preview->get_font_style_name());
String sample;
static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀";
for (int i = 0; i < sample_base.length(); i++) {
- if (dfont_prev->has_char(sample_base[i])) {
+ if (font_preview->has_char(sample_base[i])) {
sample += sample_base[i];
}
}
if (sample.is_empty()) {
- sample = dfont_prev->get_supported_chars().substr(0, 6);
+ sample = font_preview->get_supported_chars().substr(0, 6);
}
font_preview_label->set_text(sample);
- // Load second copy of font with MSDF disabled for the glyph table and metadata extraction.
- Ref<FontData> dfont_main;
- dfont_main.instantiate();
- dfont_main->set_data(data);
- dfont_main->set_multichannel_signed_distance_field(false);
+ Ref<Font> bold_font = get_theme_font(SNAME("bold"), SNAME("EditorFonts"));
+ if (bold_font.is_valid() && bold_font.is_valid()) {
+ font_name_label->add_theme_font_override("bold_font", bold_font);
+ }
+ font_name_label->set_text(font_name);
+ // Load second copy of font with MSDF disabled for the glyph table and metadata extraction.
font_main.instantiate();
- font_main->add_data(dfont_main);
+ font_main->set_data(data);
+ font_main->set_multichannel_signed_distance_field(false);
+
text_edit->add_theme_font_override("font", font_main);
base_path = p_path;
@@ -1087,35 +973,27 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
inspector_vars->edit(nullptr);
inspector_general->edit(nullptr);
- int gww = get_theme_font(SNAME("font"))->get_string_size("00000", get_theme_font_size(SNAME("font_size"))).x + 50;
+ text_settings_data.instantiate();
+ ERR_FAIL_NULL(text_settings_data);
+
+ text_settings_data->owner = this;
+
+ for (List<ResourceImporter::ImportOption>::Element *F = options_text.front(); F; F = F->next()) {
+ text_settings_data->defaults[F->get().option.name] = F->get().default_value;
+ }
+
+ text_settings_data->fd = font_main;
+ text_settings_data->options = options_text;
+
+ inspector_text->edit(text_settings_data.ptr());
+
+ int gww = get_theme_font(SNAME("font"))->get_string_size("00000").x + 50;
glyph_table->set_column_custom_minimum_width(0, gww);
glyph_table->clear();
vars_list->clear();
- lang_list->clear();
- script_list->clear();
- ot_list->clear();
-
- selected_chars.clear();
- selected_glyphs.clear();
- text_edit->set_text(String());
vars_list_root = vars_list->create_item();
- lang_list_root = lang_list->create_item();
- script_list_root = script_list->create_item();
- ot_list_root = ot_list->create_item();
-
- options_variations.clear();
- Dictionary var_list = dfont_main->get_supported_variation_list();
- for (int i = 0; i < var_list.size(); i++) {
- int32_t tag = var_list.get_key_at_index(i);
- Vector3i value = var_list.get_value_at_index(i);
- options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, TS->tag_to_name(tag), PROPERTY_HINT_RANGE, itos(value.x) + "," + itos(value.y) + ",1"), value.z));
- }
- options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16));
- options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0));
- options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "extra_spacing_glyph"), 0));
- options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "extra_spacing_space"), 0));
import_settings_data->defaults.clear();
for (List<ResourceImporter::ImportOption>::Element *E = options_general.front(); E; E = E->next()) {
@@ -1134,157 +1012,58 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
for (List<String>::Element *E = keys.front(); E; E = E->next()) {
String key = E->get();
print_verbose(String(" ") + key + " == " + String(config->get_value("params", key)));
- if (key == "preload/char_ranges") {
- Vector<String> ranges = config->get_value("params", key);
- for (int i = 0; i < ranges.size(); i++) {
- int32_t start, end;
- Vector<String> tokens = ranges[i].split("-");
- if (tokens.size() == 2) {
- if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start) || !ResourceImporterDynamicFont::_decode_range(tokens[1], end)) {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- } else if (tokens.size() == 1) {
- if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start)) {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- end = start;
- } else {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- for (int32_t j = start; j <= end; j++) {
- selected_chars.insert(j);
- }
- }
- } else if (key == "preload/glyph_ranges") {
- Vector<String> ranges = config->get_value("params", key);
- for (int i = 0; i < ranges.size(); i++) {
- int32_t start, end;
- Vector<String> tokens = ranges[i].split("-");
- if (tokens.size() == 2) {
- if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start) || !ResourceImporterDynamicFont::_decode_range(tokens[1], end)) {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- } else if (tokens.size() == 1) {
- if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start)) {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- end = start;
- } else {
- WARN_PRINT("Invalid range: \"" + ranges[i] + "\"");
- continue;
- }
- for (int32_t j = start; j <= end; j++) {
- selected_glyphs.insert(j);
- }
- }
- } else if (key == "preload/configurations") {
- Vector<String> variations = config->get_value("params", key);
- for (int i = 0; i < variations.size(); i++) {
+ if (key == "preload") {
+ Array preload_configurations = config->get_value("params", key);
+ for (int i = 0; i < preload_configurations.size(); i++) {
+ Dictionary preload_config = preload_configurations[i];
+
+ Dictionary variation = preload_config.has("variation_opentype") ? preload_config["variation_opentype"].operator Dictionary() : Dictionary();
+ double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0;
+ int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0;
+ Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D();
+ Vector2i size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0);
+ String cfg_name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i);
+
TreeItem *vars_item = vars_list->create_item(vars_list_root);
ERR_FAIL_NULL(vars_item);
- vars_item->set_text(0, TTR("Configuration") + " " + itos(i));
+ vars_item->set_text(0, cfg_name);
vars_item->set_editable(0, true);
vars_item->add_button(1, vars_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation"));
vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75));
Ref<DynamicFontImportSettingsData> import_variation_data_custom;
import_variation_data_custom.instantiate();
- import_variation_data_custom->owner = this;
ERR_FAIL_NULL(import_variation_data_custom);
+ import_variation_data_custom->owner = this;
for (List<ResourceImporter::ImportOption>::Element *F = options_variations.front(); F; F = F->next()) {
import_variation_data_custom->defaults[F->get().option.name] = F->get().default_value;
}
- import_variation_data_custom->options = options_variations;
+ import_variation_data_custom->fd = font_main;
+ import_variation_data_custom->options = options_variations;
vars_item->set_metadata(0, import_variation_data_custom);
- Vector<String> variation_tags = variations[i].split(",");
- for (int j = 0; j < variation_tags.size(); j++) {
- Vector<String> tokens = variation_tags[j].split("=");
- if (tokens[0] == "name") {
- vars_item->set_text(0, tokens[1]);
- } else if (tokens[0] == "size" || tokens[0] == "outline_size" || tokens[0] == "extra_spacing_space" || tokens[0] == "extra_spacing_glyph") {
- import_variation_data_custom->set(tokens[0], tokens[1].to_int());
- } else {
- import_variation_data_custom->set(tokens[0], tokens[1].to_float());
- }
+
+ import_variation_data_custom->set("size", size.x);
+ import_variation_data_custom->set("outline_size", size.y);
+ import_variation_data_custom->set("variation_opentype", variation);
+ import_variation_data_custom->set("variation_embolden", embolden);
+ import_variation_data_custom->set("variation_face_index", face_index);
+ import_variation_data_custom->set("variation_transform", transform);
+
+ Array chars = preload_config["chars"];
+ for (int j = 0; j < chars.size(); j++) {
+ char32_t c = chars[j].operator int();
+ import_variation_data_custom->selected_chars.insert(c);
}
- }
- } else if (key == "support_overrides/language_enabled") {
- PackedStringArray _langs = config->get_value("params", key);
- for (int i = 0; i < _langs.size(); i++) {
- TreeItem *lang_item = lang_list->create_item(lang_list_root);
- ERR_FAIL_NULL(lang_item);
-
- lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- lang_item->set_editable(0, true);
- lang_item->set_checked(0, true);
- lang_item->set_text(1, _langs[i]);
- lang_item->set_editable(1, true);
- lang_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- }
- } else if (key == "support_overrides/language_disabled") {
- PackedStringArray _langs = config->get_value("params", key);
- for (int i = 0; i < _langs.size(); i++) {
- TreeItem *lang_item = lang_list->create_item(lang_list_root);
- ERR_FAIL_NULL(lang_item);
-
- lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- lang_item->set_editable(0, true);
- lang_item->set_checked(0, false);
- lang_item->set_text(1, _langs[i]);
- lang_item->set_editable(1, true);
- lang_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- }
- } else if (key == "support_overrides/script_enabled") {
- PackedStringArray _scripts = config->get_value("params", key);
- for (int i = 0; i < _scripts.size(); i++) {
- TreeItem *script_item = script_list->create_item(script_list_root);
- ERR_FAIL_NULL(script_item);
-
- script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- script_item->set_editable(0, true);
- script_item->set_checked(0, true);
- script_item->set_text(1, _scripts[i]);
- script_item->set_editable(1, true);
- script_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- }
- } else if (key == "support_overrides/script_disabled") {
- PackedStringArray _scripts = config->get_value("params", key);
- for (int i = 0; i < _scripts.size(); i++) {
- TreeItem *script_item = script_list->create_item(script_list_root);
- ERR_FAIL_NULL(script_item);
-
- script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- script_item->set_editable(0, true);
- script_item->set_checked(0, false);
- script_item->set_text(1, _scripts[i]);
- script_item->set_editable(1, true);
- script_item->add_button(2, lang_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- }
- } else if (key == "opentype_feature_overrides") {
- Dictionary features = config->get_value("params", key);
- for (const Variant *ftr = features.next(nullptr); ftr != nullptr; ftr = features.next(ftr)) {
- TreeItem *ot_item = ot_list->create_item(ot_list_root);
- ERR_FAIL_NULL(ot_item);
- int32_t value = features[*ftr];
- if (ftr->get_type() == Variant::STRING) {
- ot_item->set_text(0, *ftr);
- } else {
- ot_item->set_text(0, TS->tag_to_name(*ftr));
+
+ Array glyphs = preload_config["glyphs"];
+ for (int j = 0; j < glyphs.size(); j++) {
+ int32_t c = glyphs[j];
+ import_variation_data_custom->selected_glyphs.insert(c);
}
- ot_item->set_editable(0, false);
- ot_item->set_text(1, itos(value));
- ot_item->set_editable(1, true);
- ot_item->add_button(2, ot_list->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), BUTTON_REMOVE_VAR, false, TTR("Remove"));
- ot_item->set_button_color(2, 0, Color(1, 1, 1, 0.75));
}
} else {
Variant value = config->get_value("params", key);
@@ -1292,60 +1071,26 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
}
}
}
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ import_settings_data->fd = font_main;
import_settings_data->options = options_general;
inspector_general->edit(import_settings_data.ptr());
import_settings_data->notify_property_list_changed();
- if (font_preview->get_data_count() > 0) {
- font_preview->get_data(0)->set_antialiased(import_settings_data->get("antialiased"));
- font_preview->get_data(0)->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
- font_preview->get_data(0)->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
- font_preview->get_data(0)->set_msdf_size(import_settings_data->get("msdf_size"));
- font_preview->get_data(0)->set_force_autohinter(import_settings_data->get("force_autohinter"));
- font_preview->get_data(0)->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
- font_preview->get_data(0)->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
- font_preview->get_data(0)->set_embolden(import_settings_data->get("embolden"));
- font_preview->get_data(0)->set_transform(import_settings_data->get("transform"));
- font_preview->get_data(0)->set_oversampling(import_settings_data->get("oversampling"));
+ if (font_preview.is_valid()) {
+ font_preview->set_antialiased(import_settings_data->get("antialiased"));
+ font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
+ font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
+ font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
+ font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
+ font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
+ font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
+ font_preview->set_oversampling(import_settings_data->get("oversampling"));
}
font_preview_label->add_theme_font_override("font", font_preview);
+ font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE);
font_preview_label->update();
- menu_ot->clear();
- menu_ot_ss->clear();
- menu_ot_cv->clear();
- menu_ot_cu->clear();
- bool have_ss = false;
- bool have_cv = false;
- bool have_cu = false;
- Dictionary features = font_preview->get_feature_list();
- for (const Variant *ftr = features.next(nullptr); ftr != nullptr; ftr = features.next(ftr)) {
- String ftr_name = TS->tag_to_name(*ftr);
- if (ftr_name.begins_with("stylistic_set_")) {
- menu_ot_ss->add_item(ftr_name.capitalize(), (int32_t)*ftr);
- have_ss = true;
- } else if (ftr_name.begins_with("character_variant_")) {
- menu_ot_cv->add_item(ftr_name.capitalize(), (int32_t)*ftr);
- have_cv = true;
- } else if (ftr_name.begins_with("custom_")) {
- menu_ot_cu->add_item(ftr_name.replace("custom_", ""), (int32_t)*ftr);
- have_cu = true;
- } else {
- menu_ot->add_item(ftr_name.capitalize(), (int32_t)*ftr);
- }
- }
- if (have_ss) {
- menu_ot->add_submenu_item(RTR("Stylistic Sets"), "SSMenu");
- }
- if (have_cv) {
- menu_ot->add_submenu_item(RTR("Character Variants"), "CVMenu");
- }
- if (have_cu) {
- menu_ot->add_submenu_item(RTR("Custom"), "CUMenu");
- }
-
_variations_validate();
popup_centered_ratio();
@@ -1360,6 +1105,8 @@ DynamicFontImportSettings *DynamicFontImportSettings::get_singleton() {
DynamicFontImportSettings::DynamicFontImportSettings() {
singleton = this;
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "antialiased"), true));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
@@ -1368,44 +1115,29 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One half of a pixel,One quarter of a pixel"), 1));
- options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0.f));
- options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::TRANSFORM2D, "transform"), Transform2D()));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0));
- options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false));
-
- // Popup menus
-
- locale_select = memnew(EditorLocaleDialog);
- locale_select->connect("locale_selected", callable_mp(this, &DynamicFontImportSettings::_lang_add_item));
- add_child(locale_select);
- menu_scripts = memnew(PopupMenu);
- menu_scripts->set_name("Script");
- script_codes = TranslationServer::get_singleton()->get_all_scripts();
- for (int i = 0; i < script_codes.size(); i++) {
- menu_scripts->add_item(TranslationServer::get_singleton()->get_script_name(script_codes[i]) + " (" + script_codes[i] + ")", i);
- }
- add_child(menu_scripts);
- menu_scripts->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_script_add_item));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary()));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "script_support"), Dictionary()));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
- menu_ot = memnew(PopupMenu);
- add_child(menu_ot);
- menu_ot->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_ot_add_item));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Font")), Array()));
- menu_ot_cv = memnew(PopupMenu);
- menu_ot_cv->set_name("CVMenu");
- menu_ot->add_child(menu_ot_cv);
- menu_ot_cv->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_ot_add_item));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false));
- menu_ot_ss = memnew(PopupMenu);
- menu_ot_ss->set_name("SSMenu");
- menu_ot->add_child(menu_ot_ss);
- menu_ot_ss->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_ot_add_item));
+ options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
+ options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), ""));
- menu_ot_cu = memnew(PopupMenu);
- menu_ot_cu->set_name("CUMenu");
- menu_ot->add_child(menu_ot_cu);
- menu_ot_cu->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_ot_add_item));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Variation", PROPERTY_HINT_NONE, "variation", PROPERTY_USAGE_GROUP), Variant()));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "variation_opentype"), Dictionary()));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "variation_embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "variation_face_index"), 0));
+ options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::TRANSFORM2D, "variation_transform"), Transform2D()));
Color warn_color = (EditorNode::get_singleton()) ? EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("warning_color"), SNAME("Editor")) : Color(1, 1, 0);
@@ -1418,6 +1150,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
main_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
main_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
main_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ main_pages->set_theme_type_variation("TabContainerOdd");
root_vb->add_child(main_pages);
label_warn = memnew(Label);
@@ -1434,7 +1167,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
main_pages->add_child(page1_vb);
page1_description = memnew(Label);
- page1_description->set_text(TTR("Select font rendering options:"));
+ page1_description->set_text(TTR("Select font rendering options, fallback font, and metadata override:"));
page1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
page1_vb->add_child(page1_description);
@@ -1443,15 +1176,25 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
page1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
page1_vb->add_child(page1_hb);
+ VBoxContainer *page1_lbl_vb = memnew(VBoxContainer);
+ page1_lbl_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ page1_lbl_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page1_hb->add_child(page1_lbl_vb);
+
+ font_name_label = memnew(Label);
+ font_name_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
+ font_name_label->set_clip_text(true);
+ font_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page1_lbl_vb->add_child(font_name_label);
+
font_preview_label = memnew(Label);
- font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE);
font_preview_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
font_preview_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
- font_preview_label->set_autowrap_mode(Label::AUTOWRAP_ARBITRARY);
+ font_preview_label->set_autowrap_mode(TextServer::AUTOWRAP_ARBITRARY);
font_preview_label->set_clip_text(true);
font_preview_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
font_preview_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page1_hb->add_child(font_preview_label);
+ page1_lbl_vb->add_child(font_preview_label);
inspector_general = memnew(EditorInspector);
inspector_general->set_v_size_flags(Control::SIZE_EXPAND_FILL);
@@ -1461,13 +1204,13 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 2 layout: Configurations
VBoxContainer *page2_vb = memnew(VBoxContainer);
- page2_vb->set_name(TTR("Sizes and Variations"));
+ page2_vb->set_name(TTR("Pre-render configurations"));
main_pages->add_child(page2_vb);
page2_description = memnew(Label);
- page2_description->set_text(TTR("Add font size, variation coordinates, and extra spacing combinations to pre-render:"));
+ page2_description->set_text(TTR("Add font size, and variation coordinates, and select glyphs to pre-render:"));
page2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page2_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
+ page2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
page2_vb->add_child(page2_description);
HSplitContainer *page2_hb = memnew(HSplitContainer);
@@ -1509,53 +1252,49 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
inspector_vars = memnew(EditorInspector);
inspector_vars->set_v_size_flags(Control::SIZE_EXPAND_FILL);
inspector_vars->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_variation_changed));
- page2_hb->add_child(inspector_vars);
-
- // Page 3 layout: Text to select glyphs
- VBoxContainer *page3_vb = memnew(VBoxContainer);
- page3_vb->set_name(TTR("Glyphs from the Text"));
- main_pages->add_child(page3_vb);
+ page2_side_vb->add_child(inspector_vars);
- page3_description = memnew(Label);
- page3_description->set_text(TTR("Enter a text to shape and add all required glyphs to pre-render list:"));
- page3_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page3_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
- page3_vb->add_child(page3_description);
+ preload_pages = memnew(TabContainer);
+ preload_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
+ preload_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ preload_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page2_hb->add_child(preload_pages);
- HBoxContainer *ot_hb = memnew(HBoxContainer);
- page3_vb->add_child(ot_hb);
- ot_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ // Page 2.1 layout: Text to select glyphs
+ VBoxContainer *page2_1_vb = memnew(VBoxContainer);
+ page2_1_vb->set_name(TTR("Glyphs from the Text"));
+ preload_pages->add_child(page2_1_vb);
- Label *label_ed_ftr = memnew(Label);
- ot_hb->add_child(label_ed_ftr);
- label_ed_ftr->set_text(TTR("OpenType features:"));
+ page2_1_description = memnew(Label);
+ page2_1_description->set_text(TTR("Enter a text to shape and add all required glyphs to pre-render list:"));
+ page2_1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page2_1_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
+ page2_1_vb->add_child(page2_1_description);
- ftr_edit = memnew(LineEdit);
- ot_hb->add_child(ftr_edit);
- ftr_edit->connect("text_changed", callable_mp(this, &DynamicFontImportSettings::_change_text_opts));
- ftr_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ HSplitContainer *page2_1_hb = memnew(HSplitContainer);
+ page2_1_vb->add_child(page2_1_hb);
+ page2_1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page2_1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- Label *label_ed_lang = memnew(Label);
- ot_hb->add_child(label_ed_lang);
- label_ed_lang->set_text(TTR("Text language:"));
+ inspector_text = memnew(EditorInspector);
- lang_edit = memnew(LineEdit);
- ot_hb->add_child(lang_edit);
- lang_edit->connect("text_changed", callable_mp(this, &DynamicFontImportSettings::_change_text_opts));
- lang_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ inspector_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ inspector_text->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE));
+ inspector_text->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_change_text_opts));
+ page2_1_hb->add_child(inspector_text);
text_edit = memnew(TextEdit);
- page3_vb->add_child(text_edit);
+ page2_1_hb->add_child(text_edit);
text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
text_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
HBoxContainer *text_hb = memnew(HBoxContainer);
- page3_vb->add_child(text_hb);
+ page2_1_vb->add_child(text_hb);
text_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
label_glyphs = memnew(Label);
text_hb->add_child(label_glyphs);
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(0));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(0));
label_glyphs->set_custom_minimum_size(Size2(50 * EDSCALE, 0));
Button *btn_fill = memnew(Button);
@@ -1568,21 +1307,21 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
btn_clear->set_text(TTR("Clear glyph list"));
btn_clear->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_glyph_clear));
- // Page 4 layout: Character map
- VBoxContainer *page4_vb = memnew(VBoxContainer);
- page4_vb->set_name(TTR("Glyphs from the Character Map"));
- main_pages->add_child(page4_vb);
+ // Page 2.2 layout: Character map
+ VBoxContainer *page2_2_vb = memnew(VBoxContainer);
+ page2_2_vb->set_name(TTR("Glyphs from the Character Map"));
+ preload_pages->add_child(page2_2_vb);
- page4_description = memnew(Label);
- page4_description->set_text(TTR("Add or remove additional glyphs from the character map to pre-render list:\nNote: Some stylistic alternatives and glyph variants do not have one-to-one correspondence to character, and not shown in this map, use \"Glyphs from the text\" to add these."));
- page4_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page4_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
- page4_vb->add_child(page4_description);
+ page2_2_description = memnew(Label);
+ page2_2_description->set_text(TTR("Add or remove glyphs from the character map to pre-render list:\nNote: Some stylistic alternatives and glyph variants do not have one-to-one correspondence to character, and not shown in this map, use \"Glyphs from the text\" tab to add these."));
+ page2_2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ page2_2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
+ page2_2_vb->add_child(page2_2_description);
HSplitContainer *glyphs_split = memnew(HSplitContainer);
glyphs_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
glyphs_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page4_vb->add_child(glyphs_split);
+ page2_2_vb->add_child(glyphs_split);
glyph_table = memnew(Tree);
glyphs_split->add_child(glyph_table);
@@ -1619,106 +1358,11 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
_add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name);
}
- // Page 4 layout: Metadata override
- VBoxContainer *page5_vb = memnew(VBoxContainer);
- page5_vb->set_name(TTR("Metadata Override"));
- main_pages->add_child(page5_vb);
-
- page5_description = memnew(Label);
- page5_description->set_text(TTR("Add or remove language and script support overrides, to control fallback font selection order:"));
- page5_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- page5_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART);
- page5_vb->add_child(page5_description);
-
- HBoxContainer *hb_lang = memnew(HBoxContainer);
- page5_vb->add_child(hb_lang);
-
- label_langs = memnew(Label);
- label_langs->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
- label_langs->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- label_langs->set_text(TTR("Language support overrides"));
- hb_lang->add_child(label_langs);
-
- add_lang = memnew(Button);
- hb_lang->add_child(add_lang);
- add_lang->set_tooltip(TTR("Add language override"));
- add_lang->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- add_lang->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_lang_add));
-
- lang_list = memnew(Tree);
- page5_vb->add_child(lang_list);
- lang_list->set_hide_root(true);
- lang_list->set_columns(3);
- lang_list->set_column_expand(0, false); // Check
- lang_list->set_column_custom_minimum_width(0, 50 * EDSCALE);
- lang_list->set_column_expand(1, true);
- lang_list->set_column_custom_minimum_width(1, 80 * EDSCALE);
- lang_list->set_column_expand(2, false);
- lang_list->set_column_custom_minimum_width(2, 50 * EDSCALE);
- lang_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_lang_remove));
- lang_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
-
- HBoxContainer *hb_script = memnew(HBoxContainer);
- page5_vb->add_child(hb_script);
-
- label_script = memnew(Label);
- label_script->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
- label_script->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- label_script->set_text(TTR("Script support overrides"));
- hb_script->add_child(label_script);
-
- add_script = memnew(Button);
- hb_script->add_child(add_script);
- add_script->set_tooltip(TTR("Add script override"));
- add_script->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- add_script->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_script_add));
-
- script_list = memnew(Tree);
- page5_vb->add_child(script_list);
- script_list->set_hide_root(true);
- script_list->set_columns(3);
- script_list->set_column_expand(0, false);
- script_list->set_column_custom_minimum_width(0, 50 * EDSCALE);
- script_list->set_column_expand(1, true);
- script_list->set_column_custom_minimum_width(1, 80 * EDSCALE);
- script_list->set_column_expand(2, false);
- script_list->set_column_custom_minimum_width(2, 50 * EDSCALE);
- script_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_script_remove));
- script_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
-
- HBoxContainer *hb_ot = memnew(HBoxContainer);
- page5_vb->add_child(hb_ot);
-
- label_ot = memnew(Label);
- label_ot->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
- label_ot->set_h_size_flags(Control::SIZE_EXPAND_FILL);
- label_ot->set_text(TTR("OpenType feature overrides"));
- hb_ot->add_child(label_ot);
-
- add_ot = memnew(Button);
- hb_ot->add_child(add_ot);
- add_ot->set_tooltip(TTR("Add feature override"));
- add_ot->set_icon(add_var->get_theme_icon(SNAME("Add"), SNAME("EditorIcons")));
- add_ot->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_ot_add));
-
- ot_list = memnew(Tree);
- page5_vb->add_child(ot_list);
- ot_list->set_hide_root(true);
- ot_list->set_columns(3);
- ot_list->set_column_expand(0, true);
- ot_list->set_column_custom_minimum_width(0, 80 * EDSCALE);
- ot_list->set_column_expand(1, true);
- ot_list->set_column_custom_minimum_width(1, 80 * EDSCALE);
- ot_list->set_column_expand(2, false);
- ot_list->set_column_custom_minimum_width(2, 50 * EDSCALE);
- ot_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_ot_remove));
- ot_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
-
// Common
import_settings_data.instantiate();
import_settings_data->owner = this;
- get_ok_button()->set_text(TTR("Reimport"));
- get_cancel_button()->set_text(TTR("Close"));
+ set_ok_button_text(TTR("Reimport"));
+ set_cancel_button_text(TTR("Close"));
}
diff --git a/editor/import/dynamic_font_import_settings.h b/editor/import/dynamic_font_import_settings.h
index ba75c98057..a1f763b445 100644
--- a/editor/import/dynamic_font_import_settings.h
+++ b/editor/import/dynamic_font_import_settings.h
@@ -45,7 +45,30 @@
#include "scene/resources/font.h"
#include "servers/text_server.h"
-class DynamicFontImportSettingsData;
+class DynamicFontImportSettings;
+
+class DynamicFontImportSettingsData : public RefCounted {
+ GDCLASS(DynamicFontImportSettingsData, RefCounted)
+ friend class DynamicFontImportSettings;
+
+ HashMap<StringName, Variant> settings;
+ HashMap<StringName, Variant> defaults;
+ List<ResourceImporter::ImportOption> options;
+ DynamicFontImportSettings *owner = nullptr;
+
+ HashSet<char32_t> selected_chars;
+ HashSet<int32_t> selected_glyphs;
+
+ Ref<FontFile> fd;
+
+public:
+ bool _set(const StringName &p_name, const Variant &p_value);
+ bool _get(const StringName &p_name, Variant &r_ret) const;
+ void _get_property_list(List<PropertyInfo> *p_list) const;
+
+ Ref<FontFile> get_font() const;
+};
+
class EditorFileDialog;
class EditorInspector;
class EditorLocaleDialog;
@@ -67,21 +90,19 @@ class DynamicFontImportSettings : public ConfirmationDialog {
List<ResourceImporter::ImportOption> options_variations;
List<ResourceImporter::ImportOption> options_general;
- EditorLocaleDialog *locale_select = nullptr;
- Vector<String> script_codes;
-
// Root layout
Label *label_warn = nullptr;
TabContainer *main_pages = nullptr;
// Page 1 layout: Rendering Options
Label *page1_description = nullptr;
+ Label *font_name_label = nullptr;
Label *font_preview_label = nullptr;
EditorInspector *inspector_general = nullptr;
void _main_prop_changed(const String &p_edited_property);
- // Page 2 layout: Configurations
+ // Page 2 layout: Preload Configurations
Label *page2_description = nullptr;
Label *label_vars = nullptr;
Button *add_var = nullptr;
@@ -95,19 +116,23 @@ class DynamicFontImportSettings : public ConfirmationDialog {
void _variation_changed(const String &p_edited_property);
void _variations_validate();
- // Page 3 layout: Text to select glyphs
- Label *page3_description = nullptr;
+ TabContainer *preload_pages = nullptr;
+
+ // Page 2.1 layout: Text to select glyphs
+ Label *page2_1_description = nullptr;
Label *label_glyphs = nullptr;
TextEdit *text_edit = nullptr;
- LineEdit *ftr_edit = nullptr;
- LineEdit *lang_edit = nullptr;
+ EditorInspector *inspector_text = nullptr;
+
+ List<ResourceImporter::ImportOption> options_text;
+ Ref<DynamicFontImportSettingsData> text_settings_data;
void _change_text_opts();
void _glyph_text_selected();
void _glyph_clear();
- // Page 4 layout: Character map
- Label *page4_description = nullptr;
+ // Page 2.2 layout: Character map
+ Label *page2_2_description = nullptr;
Tree *glyph_table = nullptr;
Tree *glyph_tree = nullptr;
TreeItem *glyph_root = nullptr;
@@ -119,51 +144,12 @@ class DynamicFontImportSettings : public ConfirmationDialog {
bool _char_update(int32_t p_char);
void _range_update(int32_t p_start, int32_t p_end);
- // Page 5 layout: Metadata override
- Label *page5_description = nullptr;
- Button *add_lang = nullptr;
- Button *add_script = nullptr;
- Button *add_ot = nullptr;
-
- PopupMenu *menu_scripts = nullptr;
- PopupMenu *menu_ot = nullptr;
- PopupMenu *menu_ot_ss = nullptr;
- PopupMenu *menu_ot_cv = nullptr;
- PopupMenu *menu_ot_cu = nullptr;
-
- Tree *lang_list = nullptr;
- TreeItem *lang_list_root = nullptr;
- Label *label_langs = nullptr;
-
- Tree *script_list = nullptr;
- TreeItem *script_list_root = nullptr;
- Label *label_script = nullptr;
-
- Tree *ot_list = nullptr;
- TreeItem *ot_list_root = nullptr;
- Label *label_ot = nullptr;
-
- void _lang_add();
- void _lang_add_item(const String &p_locale);
- void _lang_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
-
- void _script_add();
- void _script_add_item(int p_option);
- void _script_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
-
- void _ot_add();
- void _ot_add_item(int p_option);
- void _ot_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
-
// Common
void _add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name);
- Ref<Font> font_preview;
- Ref<Font> font_main;
-
- RBSet<char32_t> selected_chars;
- RBSet<int32_t> selected_glyphs;
+ Ref<FontFile> font_preview;
+ Ref<FontFile> font_main;
void _re_import();
diff --git a/editor/import/post_import_plugin_skeleton_renamer.cpp b/editor/import/post_import_plugin_skeleton_renamer.cpp
new file mode 100644
index 0000000000..bf84348ac3
--- /dev/null
+++ b/editor/import/post_import_plugin_skeleton_renamer.cpp
@@ -0,0 +1,178 @@
+/*************************************************************************/
+/* post_import_plugin_skeleton_renamer.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "post_import_plugin_skeleton_renamer.h"
+
+#include "editor/import/scene_import_settings.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
+#include "scene/3d/skeleton_3d.h"
+#include "scene/animation/animation_player.h"
+#include "scene/resources/bone_map.h"
+
+void PostImportPluginSkeletonRenamer::get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) {
+ if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) {
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/bone_renamer/rename_bones"), true));
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/bone_renamer/unique_node/make_unique"), true));
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "retarget/bone_renamer/unique_node/skeleton_name"), "GeneralSkeleton"));
+ }
+}
+
+void PostImportPluginSkeletonRenamer::internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) {
+ if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) {
+ // Prepare objects.
+ Object *map = p_options["retarget/bone_map"].get_validated_object();
+ if (!map || !bool(p_options["retarget/bone_renamer/rename_bones"])) {
+ return;
+ }
+ BoneMap *bone_map = Object::cast_to<BoneMap>(map);
+ Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);
+
+ // Rename bones in Skeleton3D.
+ {
+ int len = skeleton->get_bone_count();
+ for (int i = 0; i < len; i++) {
+ StringName bn = bone_map->find_profile_bone_name(skeleton->get_bone_name(i));
+ if (bn) {
+ skeleton->set_bone_name(i, bn);
+ }
+ }
+ }
+
+ // Rename bones in Skin.
+ {
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "ImporterMeshInstance3D");
+ while (nodes.size()) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(nodes.pop_back());
+ Ref<Skin> skin = mi->get_skin();
+ if (skin.is_valid()) {
+ Node *node = mi->get_node(mi->get_skeleton_path());
+ if (node) {
+ Skeleton3D *mesh_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (mesh_skeleton && node == skeleton) {
+ int len = skin->get_bind_count();
+ for (int i = 0; i < len; i++) {
+ StringName bn = bone_map->find_profile_bone_name(skin->get_bind_name(i));
+ if (bn) {
+ skin->set_bind_name(i, bn);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Rename bones in AnimationPlayer.
+ {
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer");
+ while (nodes.size()) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back());
+ List<StringName> anims;
+ ap->get_animation_list(&anims);
+ for (const StringName &name : anims) {
+ Ref<Animation> anim = ap->get_animation(name);
+ int len = anim->get_track_count();
+ for (int i = 0; i < len; i++) {
+ if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
+ continue;
+ }
+ String track_path = String(anim->track_get_path(i).get_concatenated_names());
+ Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
+ if (node) {
+ Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (track_skeleton && track_skeleton == skeleton) {
+ StringName bn = bone_map->find_profile_bone_name(anim->track_get_path(i).get_subname(0));
+ if (bn) {
+ anim->track_set_path(i, track_path + ":" + bn);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Rename bones in all Nodes by calling method.
+ {
+ Vector<Variant> vargs;
+ vargs.push_back(p_base_scene);
+ vargs.push_back(skeleton);
+ vargs.push_back(bone_map);
+ const Variant **argptrs = (const Variant **)alloca(sizeof(const Variant **) * vargs.size());
+ const Variant *args = vargs.ptr();
+ uint32_t argcount = vargs.size();
+ for (uint32_t i = 0; i < argcount; i++) {
+ argptrs[i] = &args[i];
+ }
+
+ TypedArray<Node> nodes = p_base_scene->find_children("*");
+ while (nodes.size()) {
+ Node *nd = Object::cast_to<Node>(nodes.pop_back());
+ Callable::CallError ce;
+ nd->callp("_notify_skeleton_bones_renamed", argptrs, argcount, ce);
+ }
+ }
+
+ // Make unique skeleton.
+ if (bool(p_options["retarget/bone_renamer/unique_node/make_unique"])) {
+ String unique_name = String(p_options["retarget/bone_renamer/unique_node/skeleton_name"]);
+ ERR_FAIL_COND_MSG(unique_name == String(), "Skeleton unique name cannot be empty.");
+
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer");
+ while (nodes.size()) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back());
+ List<StringName> anims;
+ ap->get_animation_list(&anims);
+ for (const StringName &name : anims) {
+ Ref<Animation> anim = ap->get_animation(name);
+ int track_len = anim->get_track_count();
+ for (int i = 0; i < track_len; i++) {
+ if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
+ continue;
+ }
+ String track_path = String(anim->track_get_path(i).get_concatenated_names());
+ Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
+ if (node) {
+ Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (track_skeleton && track_skeleton == skeleton) {
+ anim->track_set_path(i, String("%") + unique_name + String(":") + anim->track_get_path(i).get_concatenated_subnames());
+ }
+ }
+ }
+ }
+ }
+ skeleton->set_name(unique_name);
+ skeleton->set_unique_name_in_owner(true);
+ }
+ }
+}
+
+PostImportPluginSkeletonRenamer::PostImportPluginSkeletonRenamer() {
+}
diff --git a/editor/import/post_import_plugin_skeleton_renamer.h b/editor/import/post_import_plugin_skeleton_renamer.h
new file mode 100644
index 0000000000..73cbabd1c5
--- /dev/null
+++ b/editor/import/post_import_plugin_skeleton_renamer.h
@@ -0,0 +1,46 @@
+/*************************************************************************/
+/* post_import_plugin_skeleton_renamer.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef POST_IMPORT_PLUGIN_SKELETON_RENAMER_H
+#define POST_IMPORT_PLUGIN_SKELETON_RENAMER_H
+
+#include "resource_importer_scene.h"
+
+class PostImportPluginSkeletonRenamer : public EditorScenePostImportPlugin {
+ GDCLASS(PostImportPluginSkeletonRenamer, EditorScenePostImportPlugin);
+
+public:
+ virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) override;
+ virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) override;
+
+ PostImportPluginSkeletonRenamer();
+};
+
+#endif // POST_IMPORT_PLUGIN_SKELETON_RENAMER_H
diff --git a/editor/import/post_import_plugin_skeleton_rest_fixer.cpp b/editor/import/post_import_plugin_skeleton_rest_fixer.cpp
new file mode 100644
index 0000000000..8b0d8c8729
--- /dev/null
+++ b/editor/import/post_import_plugin_skeleton_rest_fixer.cpp
@@ -0,0 +1,418 @@
+/*************************************************************************/
+/* post_import_plugin_skeleton_rest_fixer.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "post_import_plugin_skeleton_rest_fixer.h"
+
+#include "editor/import/scene_import_settings.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
+#include "scene/3d/skeleton_3d.h"
+#include "scene/animation/animation_player.h"
+#include "scene/resources/animation.h"
+#include "scene/resources/bone_map.h"
+
+void PostImportPluginSkeletonRestFixer::get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) {
+ if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) {
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/rest_fixer/overwrite_axis"), true));
+
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "retarget/rest_fixer/fix_silhouette/enable"), false));
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "retarget/rest_fixer/fix_silhouette/threshold"), 15));
+
+ // TODO: PostImportPlugin need to be implemented such as validate_option(PropertyInfo &property, const Dictionary &p_options).
+ // get_internal_option_visibility() is not sufficient because it can only retrieve options implemented in the core and can only read option values.
+ // r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "retarget/rest_fixer/filter", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::STRING_NAME, PROPERTY_HINT_ENUM, "Hips,Spine,Chest")), Array()));
+ r_options->push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "retarget/rest_fixer/fix_silhouette/filter", PROPERTY_HINT_ARRAY_TYPE, "StringName"), Array()));
+ }
+}
+
+void PostImportPluginSkeletonRestFixer::internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) {
+ if (p_category == INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE) {
+ // Prepare objects.
+ Object *map = p_options["retarget/bone_map"].get_validated_object();
+ if (!map) {
+ return;
+ }
+ BoneMap *bone_map = Object::cast_to<BoneMap>(map);
+ Ref<SkeletonProfile> profile = bone_map->get_profile();
+ if (!profile.is_valid()) {
+ return;
+ }
+ Skeleton3D *src_skeleton = Object::cast_to<Skeleton3D>(p_node);
+ if (!src_skeleton) {
+ return;
+ }
+ bool is_renamed = bool(p_options["retarget/bone_renamer/rename_bones"]);
+ Array filter = p_options["retarget/rest_fixer/fix_silhouette/filter"];
+ bool is_rest_changed = false;
+
+ // Build profile skeleton.
+ Skeleton3D *prof_skeleton = memnew(Skeleton3D);
+ {
+ int prof_bone_len = profile->get_bone_size();
+ // Add single bones.
+ for (int i = 0; i < prof_bone_len; i++) {
+ prof_skeleton->add_bone(profile->get_bone_name(i));
+ prof_skeleton->set_bone_rest(i, profile->get_reference_pose(i));
+ }
+ // Set parents.
+ for (int i = 0; i < prof_bone_len; i++) {
+ int parent = profile->find_bone(profile->get_bone_parent(i));
+ if (parent >= 0) {
+ prof_skeleton->set_bone_parent(i, parent);
+ }
+ }
+ }
+
+ // Complement Rotation track for compatibility between defference rests.
+ {
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer");
+ while (nodes.size()) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back());
+ List<StringName> anims;
+ ap->get_animation_list(&anims);
+ for (const StringName &name : anims) {
+ Ref<Animation> anim = ap->get_animation(name);
+ int track_len = anim->get_track_count();
+
+ // Detect does the animetion have skeleton's TRS track.
+ String track_path;
+ bool found_skeleton = false;
+ for (int i = 0; i < track_len; i++) {
+ if (anim->track_get_path(i).get_subname_count() != 1 || !(anim->track_get_type(i) == Animation::TYPE_POSITION_3D || anim->track_get_type(i) == Animation::TYPE_ROTATION_3D || anim->track_get_type(i) == Animation::TYPE_SCALE_3D)) {
+ continue;
+ }
+ track_path = String(anim->track_get_path(i).get_concatenated_names());
+ Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
+ if (node) {
+ Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (track_skeleton && track_skeleton == src_skeleton) {
+ found_skeleton = true;
+ break;
+ }
+ }
+ }
+
+ if (found_skeleton) {
+ // Search and insert rot track if it doesn't exist.
+ for (int prof_idx = 0; prof_idx < prof_skeleton->get_bone_count(); prof_idx++) {
+ String bone_name = is_renamed ? prof_skeleton->get_bone_name(prof_idx) : String(bone_map->get_skeleton_bone_name(prof_skeleton->get_bone_name(prof_idx)));
+ if (bone_name == String()) {
+ continue;
+ }
+ int src_idx = src_skeleton->find_bone(bone_name);
+ if (src_idx == -1) {
+ continue;
+ }
+ String insert_path = track_path + ":" + bone_name;
+ int rot_track = anim->find_track(insert_path, Animation::TYPE_ROTATION_3D);
+ if (rot_track == -1) {
+ int track = anim->add_track(Animation::TYPE_ROTATION_3D);
+ anim->track_set_path(track, insert_path);
+ anim->rotation_track_insert_key(track, 0, src_skeleton->get_bone_rest(src_idx).basis.get_rotation_quaternion());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Fix silhouette.
+ Vector<Transform3D> silhouette_diff; // Transform values to be ignored when overwrite axis.
+ silhouette_diff.resize(src_skeleton->get_bone_count());
+ Transform3D *silhouette_diff_w = silhouette_diff.ptrw();
+ if (bool(p_options["retarget/rest_fixer/fix_silhouette/enable"])) {
+ LocalVector<Transform3D> old_skeleton_global_rest;
+ for (int i = 0; i < src_skeleton->get_bone_count(); i++) {
+ old_skeleton_global_rest.push_back(src_skeleton->get_bone_global_rest(i));
+ }
+
+ Vector<int> bones_to_process = prof_skeleton->get_parentless_bones();
+ while (bones_to_process.size() > 0) {
+ int prof_idx = bones_to_process[0];
+ bones_to_process.erase(prof_idx);
+ Vector<int> prof_children = prof_skeleton->get_bone_children(prof_idx);
+ for (int i = 0; i < prof_children.size(); i++) {
+ bones_to_process.push_back(prof_children[i]);
+ }
+
+ // Calc virtual/looking direction with origins.
+ bool is_filtered = false;
+ for (int i = 0; i < filter.size(); i++) {
+ if (String(filter[i]) == prof_skeleton->get_bone_name(prof_idx)) {
+ is_filtered = true;
+ break;
+ }
+ }
+ if (is_filtered) {
+ continue;
+ }
+
+ int src_idx = src_skeleton->find_bone(is_renamed ? prof_skeleton->get_bone_name(prof_idx) : String(bone_map->get_skeleton_bone_name(prof_skeleton->get_bone_name(prof_idx))));
+ if (src_idx < 0 || profile->get_tail_direction(prof_idx) == SkeletonProfile::TAIL_DIRECTION_END) {
+ continue;
+ }
+ Vector3 prof_tail;
+ Vector3 src_tail;
+ if (profile->get_tail_direction(prof_idx) == SkeletonProfile::TAIL_DIRECTION_AVERAGE_CHILDREN) {
+ PackedInt32Array prof_bone_children = prof_skeleton->get_bone_children(prof_idx);
+ int children_size = prof_bone_children.size();
+ if (children_size == 0) {
+ continue;
+ }
+ bool exist_all_children = true;
+ for (int i = 0; i < children_size; i++) {
+ int prof_child_idx = prof_bone_children[i];
+ int src_child_idx = src_skeleton->find_bone(is_renamed ? prof_skeleton->get_bone_name(prof_child_idx) : String(bone_map->get_skeleton_bone_name(prof_skeleton->get_bone_name(prof_child_idx))));
+ if (src_child_idx < 0) {
+ exist_all_children = false;
+ break;
+ }
+ prof_tail = prof_tail + prof_skeleton->get_bone_global_rest(prof_child_idx).origin;
+ src_tail = src_tail + src_skeleton->get_bone_global_rest(src_child_idx).origin;
+ }
+ if (!exist_all_children) {
+ continue;
+ }
+ prof_tail = prof_tail / children_size;
+ src_tail = src_tail / children_size;
+ }
+ if (profile->get_tail_direction(prof_idx) == SkeletonProfile::TAIL_DIRECTION_SPECIFIC_CHILD) {
+ int prof_tail_idx = prof_skeleton->find_bone(profile->get_bone_tail(prof_idx));
+ if (prof_tail_idx < 0) {
+ continue;
+ }
+ int src_tail_idx = src_skeleton->find_bone(is_renamed ? prof_skeleton->get_bone_name(prof_tail_idx) : String(bone_map->get_skeleton_bone_name(prof_skeleton->get_bone_name(prof_tail_idx))));
+ if (src_tail_idx < 0) {
+ continue;
+ }
+ prof_tail = prof_skeleton->get_bone_global_rest(prof_tail_idx).origin;
+ src_tail = src_skeleton->get_bone_global_rest(src_tail_idx).origin;
+ }
+
+ Vector3 prof_head = prof_skeleton->get_bone_global_rest(prof_idx).origin;
+ Vector3 src_head = src_skeleton->get_bone_global_rest(src_idx).origin;
+
+ Vector3 prof_dir = prof_tail - prof_head;
+ Vector3 src_dir = src_tail - src_head;
+
+ // Rotate rest.
+ if (Math::abs(Math::rad2deg(src_dir.angle_to(prof_dir))) > float(p_options["retarget/rest_fixer/fix_silhouette/threshold"])) {
+ // Get rotation difference.
+ Vector3 up_vec; // Need to rotate other than roll axis.
+ switch (Vector3(abs(src_dir.x), abs(src_dir.y), abs(src_dir.z)).min_axis_index()) {
+ case Vector3::AXIS_X: {
+ up_vec = Vector3(1, 0, 0);
+ } break;
+ case Vector3::AXIS_Y: {
+ up_vec = Vector3(0, 1, 0);
+ } break;
+ case Vector3::AXIS_Z: {
+ up_vec = Vector3(0, 0, 1);
+ } break;
+ }
+ Basis src_b;
+ src_b = src_b.looking_at(src_dir, up_vec);
+ Basis prof_b;
+ prof_b = src_b.looking_at(prof_dir, up_vec);
+ if (prof_b.is_equal_approx(Basis())) {
+ continue; // May not need to rotate.
+ }
+ Basis diff_b = prof_b * src_b.inverse();
+
+ // Apply rotation difference as global transform to skeleton.
+ Basis src_pg;
+ int src_parent = src_skeleton->get_bone_parent(src_idx);
+ if (src_parent >= 0) {
+ src_pg = src_skeleton->get_bone_global_rest(src_parent).basis;
+ }
+ Transform3D fixed_rest = Transform3D(src_pg.inverse() * diff_b * src_pg * src_skeleton->get_bone_rest(src_idx).basis, src_skeleton->get_bone_rest(src_idx).origin);
+ src_skeleton->set_bone_rest(src_idx, fixed_rest);
+ }
+ }
+
+ // For skin modification in overwrite rest.
+ for (int i = 0; i < src_skeleton->get_bone_count(); i++) {
+ silhouette_diff_w[i] = old_skeleton_global_rest[i] * src_skeleton->get_bone_global_rest(i).inverse();
+ }
+
+ is_rest_changed = true;
+ }
+
+ // Overwrite axis.
+ if (bool(p_options["retarget/rest_fixer/overwrite_axis"])) {
+ LocalVector<Transform3D> old_skeleton_rest;
+ LocalVector<Transform3D> old_skeleton_global_rest;
+ for (int i = 0; i < src_skeleton->get_bone_count(); i++) {
+ old_skeleton_rest.push_back(src_skeleton->get_bone_rest(i));
+ old_skeleton_global_rest.push_back(src_skeleton->get_bone_global_rest(i));
+ }
+
+ Vector<Basis> diffs;
+ diffs.resize(src_skeleton->get_bone_count());
+ Basis *diffs_w = diffs.ptrw();
+
+ Vector<int> bones_to_process = src_skeleton->get_parentless_bones();
+ while (bones_to_process.size() > 0) {
+ int src_idx = bones_to_process[0];
+ bones_to_process.erase(src_idx);
+ Vector<int> src_children = src_skeleton->get_bone_children(src_idx);
+ for (int i = 0; i < src_children.size(); i++) {
+ bones_to_process.push_back(src_children[i]);
+ }
+
+ Basis tgt_rot;
+ StringName src_bone_name = is_renamed ? StringName(src_skeleton->get_bone_name(src_idx)) : bone_map->find_profile_bone_name(src_skeleton->get_bone_name(src_idx));
+ if (src_bone_name != StringName()) {
+ Basis src_pg;
+ int src_parent_idx = src_skeleton->get_bone_parent(src_idx);
+ if (src_parent_idx >= 0) {
+ src_pg = src_skeleton->get_bone_global_rest(src_parent_idx).basis;
+ }
+
+ int prof_idx = profile->find_bone(src_bone_name);
+ if (prof_idx >= 0) {
+ tgt_rot = src_pg.inverse() * prof_skeleton->get_bone_global_rest(prof_idx).basis; // Mapped bone uses reference pose.
+ }
+ /*
+ // If there is rest-relative animation, this logic may be work fine, but currently not so...
+ } else {
+ // tgt_rot = src_pg.inverse() * old_skeleton_global_rest[src_idx].basis; // Non-Mapped bone keeps global rest.
+ }
+ */
+ }
+
+ if (src_skeleton->get_bone_parent(src_idx) >= 0) {
+ diffs_w[src_idx] = tgt_rot.inverse() * diffs[src_skeleton->get_bone_parent(src_idx)] * src_skeleton->get_bone_rest(src_idx).basis;
+ } else {
+ diffs_w[src_idx] = tgt_rot.inverse() * src_skeleton->get_bone_rest(src_idx).basis;
+ }
+
+ Basis diff;
+ if (src_skeleton->get_bone_parent(src_idx) >= 0) {
+ diff = diffs[src_skeleton->get_bone_parent(src_idx)];
+ }
+ src_skeleton->set_bone_rest(src_idx, Transform3D(tgt_rot, diff.xform(src_skeleton->get_bone_rest(src_idx).origin)));
+ }
+
+ // Fix skin.
+ {
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "ImporterMeshInstance3D");
+ while (nodes.size()) {
+ ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(nodes.pop_back());
+ Ref<Skin> skin = mi->get_skin();
+ if (skin.is_valid()) {
+ Node *node = mi->get_node(mi->get_skeleton_path());
+ if (node) {
+ Skeleton3D *mesh_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (mesh_skeleton && node == src_skeleton) {
+ int skin_len = skin->get_bind_count();
+ for (int i = 0; i < skin_len; i++) {
+ StringName bn = skin->get_bind_name(i);
+ int bone_idx = src_skeleton->find_bone(bn);
+ if (bone_idx >= 0) {
+ Transform3D new_rest = silhouette_diff[i] * src_skeleton->get_bone_global_rest(bone_idx);
+ skin->set_bind_pose(i, new_rest.inverse());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Fix animation.
+ {
+ TypedArray<Node> nodes = p_base_scene->find_children("*", "AnimationPlayer");
+ while (nodes.size()) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(nodes.pop_back());
+ List<StringName> anims;
+ ap->get_animation_list(&anims);
+ for (const StringName &name : anims) {
+ Ref<Animation> anim = ap->get_animation(name);
+ int track_len = anim->get_track_count();
+ for (int i = 0; i < track_len; i++) {
+ if (anim->track_get_path(i).get_subname_count() != 1 || anim->track_get_type(i) != Animation::TYPE_ROTATION_3D) {
+ continue;
+ }
+
+ if (anim->track_is_compressed(i)) {
+ continue; // TODO: Adopt to compressed track.
+ }
+
+ String track_path = String(anim->track_get_path(i).get_concatenated_names());
+ Node *node = (ap->get_node(ap->get_root()))->get_node(NodePath(track_path));
+ if (node) {
+ Skeleton3D *track_skeleton = Object::cast_to<Skeleton3D>(node);
+ if (track_skeleton && track_skeleton == src_skeleton) {
+ StringName bn = anim->track_get_path(i).get_subname(0);
+ if (bn) {
+ int bone_idx = src_skeleton->find_bone(bn);
+
+ Quaternion old_rest = old_skeleton_rest[bone_idx].basis.get_rotation_quaternion();
+ Quaternion new_rest = src_skeleton->get_bone_rest(bone_idx).basis.get_rotation_quaternion();
+ Quaternion old_pg;
+ Quaternion new_pg;
+ int parent_idx = src_skeleton->get_bone_parent(bone_idx);
+ if (parent_idx >= 0) {
+ old_pg = old_skeleton_global_rest[parent_idx].basis.get_rotation_quaternion();
+ new_pg = src_skeleton->get_bone_global_rest(parent_idx).basis.get_rotation_quaternion();
+ }
+
+ int key_len = anim->track_get_key_count(i);
+ for (int j = 0; j < key_len; j++) {
+ Quaternion qt = static_cast<Quaternion>(anim->track_get_key_value(i, j));
+ anim->track_set_key_value(i, j, new_pg.inverse() * old_pg * qt * old_rest.inverse() * old_pg.inverse() * new_pg * new_rest);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ is_rest_changed = true;
+ }
+
+ // Init skeleton pose to new rest.
+ if (is_rest_changed) {
+ for (int i = 0; i < src_skeleton->get_bone_count(); i++) {
+ Transform3D fixed_rest = src_skeleton->get_bone_rest(i);
+ src_skeleton->set_bone_pose_position(i, fixed_rest.origin);
+ src_skeleton->set_bone_pose_rotation(i, fixed_rest.basis.get_rotation_quaternion());
+ src_skeleton->set_bone_pose_scale(i, fixed_rest.basis.get_scale());
+ }
+ }
+
+ memdelete(prof_skeleton);
+ }
+}
+
+PostImportPluginSkeletonRestFixer::PostImportPluginSkeletonRestFixer() {
+}
diff --git a/editor/import/post_import_plugin_skeleton_rest_fixer.h b/editor/import/post_import_plugin_skeleton_rest_fixer.h
new file mode 100644
index 0000000000..11e9d08e88
--- /dev/null
+++ b/editor/import/post_import_plugin_skeleton_rest_fixer.h
@@ -0,0 +1,46 @@
+/*************************************************************************/
+/* post_import_plugin_skeleton_rest_fixer.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef POST_IMPORT_PLUGIN_SKELETON_REST_FIXER_H
+#define POST_IMPORT_PLUGIN_SKELETON_REST_FIXER_H
+
+#include "resource_importer_scene.h"
+
+class PostImportPluginSkeletonRestFixer : public EditorScenePostImportPlugin {
+ GDCLASS(PostImportPluginSkeletonRestFixer, EditorScenePostImportPlugin);
+
+public:
+ virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options) override;
+ virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) override;
+
+ PostImportPluginSkeletonRestFixer();
+};
+
+#endif // POST_IMPORT_PLUGIN_SKELETON_REST_FIXER_H
diff --git a/editor/import/resource_importer_bmfont.cpp b/editor/import/resource_importer_bmfont.cpp
index 8a40b113b9..987ca4b911 100644
--- a/editor/import/resource_importer_bmfont.cpp
+++ b/editor/import/resource_importer_bmfont.cpp
@@ -52,7 +52,7 @@ String ResourceImporterBMFont::get_save_extension() const {
}
String ResourceImporterBMFont::get_resource_type() const {
- return "FontData";
+ return "FontFile";
}
bool ResourceImporterBMFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@@ -60,19 +60,25 @@ bool ResourceImporterBMFont::get_option_visibility(const String &p_path, const S
}
void ResourceImporterBMFont::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
+ r_options->push_back(ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Font")), Array()));
+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
}
Error ResourceImporterBMFont::import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
print_verbose("Importing BMFont font from: " + p_source_file);
- Ref<FontData> font;
+ Array fallbacks = p_options["fallbacks"];
+
+ Ref<FontFile> font;
font.instantiate();
Error err = font->load_bitmap_font(p_source_file);
ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot load font to file \"" + p_source_file + "\".");
- int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
+ font->set_fallbacks(fallbacks);
+
+ int flg = 0;
if ((bool)p_options["compress"]) {
flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS;
}
diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cpp
index 04f6a0b7af..f1a70ff30a 100644
--- a/editor/import/resource_importer_dynamic_font.cpp
+++ b/editor/import/resource_importer_dynamic_font.cpp
@@ -50,7 +50,9 @@ void ResourceImporterDynamicFont::get_recognized_extensions(List<String> *p_exte
if (p_extensions) {
#ifdef MODULE_FREETYPE_ENABLED
p_extensions->push_back("ttf");
+ p_extensions->push_back("ttc");
p_extensions->push_back("otf");
+ p_extensions->push_back("otc");
p_extensions->push_back("woff");
p_extensions->push_back("woff2");
p_extensions->push_back("pfb");
@@ -64,7 +66,7 @@ String ResourceImporterDynamicFont::get_save_extension() const {
}
String ResourceImporterDynamicFont::get_resource_type() const {
- return "FontData";
+ return "FontFile";
}
bool ResourceImporterDynamicFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@@ -101,6 +103,8 @@ String ResourceImporterDynamicFont::get_preset_name(int p_idx) const {
void ResourceImporterDynamicFont::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
bool msdf = p_preset == PRESET_MSDF;
+ r_options->push_back(ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "antialiased"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), (msdf) ? true : false));
@@ -110,63 +114,19 @@ void ResourceImporterDynamicFont::get_import_options(const String &p_path, List<
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One half of a pixel,One quarter of a pixel"), 1));
- r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0.f));
- r_options->push_back(ImportOption(PropertyInfo(Variant::TRANSFORM2D, "transform"), Transform2D()));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
- r_options->push_back(ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_feature_overrides"), Dictionary()));
-
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/char_ranges"), Vector<String>()));
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/glyph_ranges"), Vector<String>()));
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/configurations"), Vector<String>()));
-
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/language_enabled"), Vector<String>()));
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/language_disabled"), Vector<String>()));
-
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/script_enabled"), Vector<String>()));
- r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/script_disabled"), Vector<String>()));
-}
+ r_options->push_back(ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Font")), Array()));
-bool ResourceImporterDynamicFont::_decode_variation(const String &p_token, Dictionary &r_variations, Vector2i &r_size, String &r_name, Vector2i &r_spacing) {
- Vector<String> tokens = p_token.split("=");
- if (tokens.size() == 2) {
- if (tokens[0] == "name") {
- r_name = tokens[1];
- } else if (tokens[0] == "size") {
- r_size.x = tokens[1].to_int();
- } else if (tokens[0] == "outline_size") {
- r_size.y = tokens[1].to_int();
- } else if (tokens[0] == "spacing_space") {
- r_spacing.x = tokens[1].to_int();
- } else if (tokens[0] == "spacing_glyph") {
- r_spacing.y = tokens[1].to_int();
- } else {
- r_variations[tokens[0]] = tokens[1].to_float();
- }
- return true;
- } else {
- WARN_PRINT("Invalid variation: '" + p_token + "'.");
- return false;
- }
-}
+ r_options->push_back(ImportOption(PropertyInfo(Variant::NIL, "Compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
-bool ResourceImporterDynamicFont::_decode_range(const String &p_token, int32_t &r_pos) {
- if (p_token.begins_with("U+") || p_token.begins_with("u+") || p_token.begins_with("0x")) {
- // Unicode character hex index.
- r_pos = p_token.substr(2).hex_to_int();
- return true;
- } else if (p_token.length() == 3 && p_token[0] == '\'' && p_token[2] == '\'') {
- // Unicode character.
- r_pos = p_token.unicode_at(1);
- return true;
- } else if (p_token.is_numeric()) {
- // Unicode character decimal index.
- r_pos = p_token.to_int();
- return true;
- } else {
- return false;
- }
+ // Hide from the main UI, only for advanced import dialog.
+ r_options->push_back(ImportOption(PropertyInfo(Variant::ARRAY, "preload", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), Array()));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), Dictionary()));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::DICTIONARY, "script_support", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), Dictionary()));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), Dictionary()));
}
bool ResourceImporterDynamicFont::has_advanced_options() const {
@@ -184,20 +144,19 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
bool msdf = p_options["multichannel_signed_distance_field"];
int px_range = p_options["msdf_pixel_range"];
int px_size = p_options["msdf_size"];
- Dictionary ot_ov = p_options["opentype_feature_overrides"];
+ Dictionary ot_ov = p_options["opentype_features"];
bool autohinter = p_options["force_autohinter"];
int hinting = p_options["hinting"];
int subpixel_positioning = p_options["subpixel_positioning"];
real_t oversampling = p_options["oversampling"];
- real_t embolden = p_options["embolden"];
- Transform2D transform = p_options["transform"];
+ Array fallbacks = p_options["fallbacks"];
// Load base font data.
Vector<uint8_t> data = FileAccess::get_file_as_array(p_source_file);
// Create font.
- Ref<FontData> font;
+ Ref<FontFile> font;
font.instantiate();
font->set_data(data);
font->set_antialiased(antialiased);
@@ -209,105 +168,52 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
font->set_fixed_size(0);
font->set_force_autohinter(autohinter);
font->set_subpixel_positioning((TextServer::SubpixelPositioning)subpixel_positioning);
- font->set_embolden(embolden);
- font->set_transform(transform);
font->set_hinting((TextServer::Hinting)hinting);
font->set_oversampling(oversampling);
+ font->set_fallbacks(fallbacks);
- Vector<String> lang_en = p_options["support_overrides/language_enabled"];
- for (int i = 0; i < lang_en.size(); i++) {
- font->set_language_support_override(lang_en[i], true);
+ Dictionary langs = p_options["language_support"];
+ for (int i = 0; i < langs.size(); i++) {
+ String key = langs.get_key_at_index(i);
+ bool enabled = langs.get_value_at_index(i);
+ font->set_language_support_override(key, enabled);
}
- Vector<String> lang_dis = p_options["support_overrides/language_disabled"];
- for (int i = 0; i < lang_dis.size(); i++) {
- font->set_language_support_override(lang_dis[i], false);
+ Dictionary scripts = p_options["script_support"];
+ for (int i = 0; i < scripts.size(); i++) {
+ String key = scripts.get_key_at_index(i);
+ bool enabled = scripts.get_value_at_index(i);
+ font->set_script_support_override(key, enabled);
}
- Vector<String> scr_en = p_options["support_overrides/script_enabled"];
- for (int i = 0; i < scr_en.size(); i++) {
- font->set_script_support_override(scr_en[i], true);
- }
+ Array preload_configurations = p_options["preload"];
- Vector<String> scr_dis = p_options["support_overrides/script_disabled"];
- for (int i = 0; i < scr_dis.size(); i++) {
- font->set_script_support_override(scr_dis[i], false);
- }
+ for (int i = 0; i < preload_configurations.size(); i++) {
+ Dictionary preload_config = preload_configurations[i];
- Vector<String> variations = p_options["preload/configurations"];
- Vector<String> char_ranges = p_options["preload/char_ranges"];
- Vector<String> gl_ranges = p_options["preload/glyph_ranges"];
-
- for (int i = 0; i < variations.size(); i++) {
- String name;
- Dictionary var;
- Vector2i size = Vector2(16, 0);
- Vector2i spacing;
-
- Vector<String> variation_tags = variations[i].split(",");
- for (int j = 0; j < variation_tags.size(); j++) {
- if (!_decode_variation(variation_tags[j], var, size, name, spacing)) {
- WARN_PRINT(vformat(TTR("Invalid variation: \"%s\""), variations[i]));
- continue;
- }
- }
- RID conf = font->find_cache(var);
-
- for (int j = 0; j < char_ranges.size(); j++) {
- int32_t start, end;
- Vector<String> tokens = char_ranges[j].split("-");
- if (tokens.size() == 2) {
- if (!_decode_range(tokens[0], start) || !_decode_range(tokens[1], end)) {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j]));
- continue;
- }
- } else if (tokens.size() == 1) {
- if (!_decode_range(tokens[0], start)) {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j]));
- continue;
- }
- end = start;
- } else {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j]));
- continue;
- }
-
- // Preload character ranges for each variations / sizes.
- print_verbose(vformat(TTR("Pre-rendering range U+%s...%s from configuration \"%s\" (%d / %d)..."), String::num_int64(start, 16), String::num_int64(end, 16), name, i + 1, variations.size()));
- TS->font_render_range(conf, size, start, end);
- }
+ Dictionary variation = preload_config.has("variation_opentype") ? preload_config["variation_opentype"].operator Dictionary() : Dictionary();
+ double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0;
+ int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0;
+ Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D();
+ Vector2i size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0);
+ String name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i);
- for (int j = 0; j < gl_ranges.size(); j++) {
- int32_t start, end;
- Vector<String> tokens = gl_ranges[j].split("-");
- if (tokens.size() == 2) {
- if (!_decode_range(tokens[0], start) || !_decode_range(tokens[1], end)) {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j]));
- continue;
- }
- } else if (tokens.size() == 1) {
- if (!_decode_range(tokens[0], start)) {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j]));
- continue;
- }
- end = start;
- } else {
- WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j]));
- continue;
- }
-
- // Preload glyph range for each variations / sizes.
- print_verbose(vformat(TTR("Pre-rendering glyph range 0x%s...%s from configuration \"%s\" (%d / %d)..."), String::num_int64(start, 16), String::num_int64(end, 16), name, i + 1, variations.size()));
- for (int32_t k = start; k <= end; k++) {
- TS->font_render_glyph(conf, size, k);
- }
+ RID conf_rid = font->find_variation(variation, face_index, embolden, transform);
+
+ Array chars = preload_config["chars"];
+ for (int j = 0; j < chars.size(); j++) {
+ char32_t c = chars[j].operator int();
+ TS->font_render_range(conf_rid, size, c, c);
}
- TS->font_set_spacing(conf, size.x, TextServer::SPACING_SPACE, spacing.x);
- TS->font_set_spacing(conf, size.x, TextServer::SPACING_GLYPH, spacing.y);
+ Array glyphs = preload_config["glyphs"];
+ for (int j = 0; j < glyphs.size(); j++) {
+ int32_t c = glyphs[j];
+ TS->font_render_glyph(conf_rid, size, c);
+ }
}
- int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
+ int flg = 0;
if ((bool)p_options["compress"]) {
flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS;
}
diff --git a/editor/import/resource_importer_dynamic_font.h b/editor/import/resource_importer_dynamic_font.h
index c0b6c094b0..a05c8bab05 100644
--- a/editor/import/resource_importer_dynamic_font.h
+++ b/editor/import/resource_importer_dynamic_font.h
@@ -43,9 +43,6 @@ class ResourceImporterDynamicFont : public ResourceImporter {
};
public:
- static bool _decode_range(const String &p_token, int32_t &r_pos);
- static bool _decode_variation(const String &p_token, Dictionary &r_variations, Vector2i &r_size, String &r_name, Vector2i &r_spacing);
-
virtual String get_importer_name() const override;
virtual String get_visible_name() const override;
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
diff --git a/editor/import/resource_importer_imagefont.cpp b/editor/import/resource_importer_imagefont.cpp
index bbcd336575..ea84d4c883 100644
--- a/editor/import/resource_importer_imagefont.cpp
+++ b/editor/import/resource_importer_imagefont.cpp
@@ -52,7 +52,7 @@ String ResourceImporterImageFont::get_save_extension() const {
}
String ResourceImporterImageFont::get_resource_type() const {
- return "FontData";
+ return "FontFile";
}
bool ResourceImporterImageFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
@@ -64,6 +64,9 @@ void ResourceImporterImageFont::get_import_options(const String &p_path, List<Im
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "columns"), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "rows"), 1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "font_size"), 14));
+
+ r_options->push_back(ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Font")), Array()));
+
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
}
@@ -92,8 +95,9 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
int rows = p_options["rows"];
int base_size = p_options["font_size"];
Vector<String> ranges = p_options["character_ranges"];
+ Array fallbacks = p_options["fallbacks"];
- Ref<FontData> font;
+ Ref<FontFile> font;
font.instantiate();
font->set_antialiased(false);
font->set_generate_mipmaps(false);
@@ -103,11 +107,12 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
font->set_force_autohinter(false);
font->set_hinting(TextServer::HINTING_NONE);
font->set_oversampling(1.0f);
+ font->set_fallbacks(fallbacks);
Ref<Image> img;
img.instantiate();
Error err = ImageLoader::load_image(p_source_file, img);
- ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_READ, TTR("Can't load font texture: ") + "\"" + p_source_file + "\".");
+ ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_READ, TTR("Can't load font texture:") + " \"" + p_source_file + "\".");
font->set_texture_image(0, Vector2i(base_size, 0), 0, img);
int count = columns * rows;
@@ -145,10 +150,10 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
ERR_FAIL_COND_V_MSG(pos >= count, ERR_CANT_CREATE, "Too many characters in range.");
}
}
- font->set_ascent(0, base_size, 0.5 * chr_height);
- font->set_descent(0, base_size, 0.5 * chr_height);
+ font->set_cache_ascent(0, base_size, 0.5 * chr_height);
+ font->set_cache_descent(0, base_size, 0.5 * chr_height);
- int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS;
+ int flg = 0;
if ((bool)p_options["compress"]) {
flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS;
}
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index bacd09592e..a5dfd67d18 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -367,7 +367,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
for (int j = 0; j < hslices; j++) {
int x = slice_w * j;
int y = slice_h * i;
- Ref<Image> slice = image->get_rect(Rect2(x, y, slice_w, slice_h));
+ Ref<Image> slice = image->get_rect(Rect2i(x, y, slice_w, slice_h));
ERR_CONTINUE(slice.is_null() || slice->is_empty());
if (slice->get_width() != slice_w || slice->get_height() != slice_h) {
slice->resize(slice_w, slice_h);
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 80230bc316..860269bfcb 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -144,11 +144,11 @@ Variant EditorScenePostImportPlugin::get_option_value(const StringName &p_name)
ERR_FAIL_COND_V_MSG(current_options == nullptr && current_options_dict == nullptr, Variant(), "get_option_value called from a function where option values are not available.");
ERR_FAIL_COND_V_MSG(current_options && !current_options->has(p_name), Variant(), "get_option_value called with unexisting option argument: " + String(p_name));
ERR_FAIL_COND_V_MSG(current_options_dict && !current_options_dict->has(p_name), Variant(), "get_option_value called with unexisting option argument: " + String(p_name));
- if (current_options) {
- (*current_options)[p_name];
+ if (current_options && current_options->has(p_name)) {
+ return (*current_options)[p_name];
}
- if (current_options_dict) {
- (*current_options_dict)[p_name];
+ if (current_options_dict && current_options_dict->has(p_name)) {
+ return (*current_options_dict)[p_name];
}
return Variant();
}
@@ -232,6 +232,7 @@ void EditorScenePostImportPlugin::_bind_methods() {
BIND_ENUM_CONSTANT(INTERNAL_IMPORT_CATEGORY_MATERIAL);
BIND_ENUM_CONSTANT(INTERNAL_IMPORT_CATEGORY_ANIMATION);
BIND_ENUM_CONSTANT(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE);
+ BIND_ENUM_CONSTANT(INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE);
BIND_ENUM_CONSTANT(INTERNAL_IMPORT_CATEGORY_MAX);
}
@@ -658,6 +659,44 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMap<R
}
}
}
+ } else if (_teststr(name, "vehicle")) {
+ if (isroot) {
+ return p_node;
+ }
+
+ Node *owner = p_node->get_owner();
+ Node3D *s = Object::cast_to<Node3D>(p_node);
+ VehicleBody3D *bv = memnew(VehicleBody3D);
+ String n = _fixstr(p_node->get_name(), "vehicle");
+ bv->set_name(n);
+ p_node->replace_by(bv);
+ p_node->set_name(n);
+ bv->add_child(p_node);
+ bv->set_owner(owner);
+ p_node->set_owner(owner);
+ bv->set_transform(s->get_transform());
+ s->set_transform(Transform3D());
+
+ p_node = bv;
+ } else if (_teststr(name, "wheel")) {
+ if (isroot) {
+ return p_node;
+ }
+
+ Node *owner = p_node->get_owner();
+ Node3D *s = Object::cast_to<Node3D>(p_node);
+ VehicleWheel3D *bv = memnew(VehicleWheel3D);
+ String n = _fixstr(p_node->get_name(), "wheel");
+ bv->set_name(n);
+ p_node->replace_by(bv);
+ p_node->set_name(n);
+ bv->add_child(p_node);
+ bv->set_owner(owner);
+ p_node->set_owner(owner);
+ bv->set_transform(s->get_transform());
+ s->set_transform(Transform3D());
+
+ p_node = bv;
} else if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
//last attempt, maybe collision inside the mesh data
@@ -728,6 +767,27 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
}
{
+ //make sure this is unique
+ node_settings = node_settings.duplicate(true);
+ //fill node settings for this node with default values
+ List<ImportOption> iopts;
+ if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE, &iopts);
+ } else if (Object::cast_to<AnimationPlayer>(p_node)) {
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, &iopts);
+ } else if (Object::cast_to<Skeleton3D>(p_node)) {
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE, &iopts);
+ } else {
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_NODE, &iopts);
+ }
+ for (const ImportOption &E : iopts) {
+ if (!node_settings.has(E.option.name)) {
+ node_settings[E.option.name] = E.default_value;
+ }
+ }
+ }
+
+ {
ObjectID node_id = p_node->get_instance_id();
for (int i = 0; i < post_importer_plugins.size(); i++) {
post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_NODE, p_root, p_node, Ref<Resource>(), node_settings);
@@ -747,6 +807,16 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
}
}
+ if (Object::cast_to<Skeleton3D>(p_node)) {
+ ObjectID node_id = p_node->get_instance_id();
+ for (int i = 0; i < post_importer_plugins.size(); i++) {
+ post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE, p_root, p_node, Ref<Resource>(), node_settings);
+ if (ObjectDB::get_instance(node_id) == nullptr) { //may have been erased, so do not continue
+ break;
+ }
+ }
+ }
+
if (Object::cast_to<ImporterMeshInstance3D>(p_node)) {
ImporterMeshInstance3D *mi = Object::cast_to<ImporterMeshInstance3D>(p_node);
@@ -761,6 +831,16 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
if (!mat_id.is_empty() && p_material_data.has(mat_id)) {
Dictionary matdata = p_material_data[mat_id];
+ {
+ //fill node settings for this node with default values
+ List<ImportOption> iopts;
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_MATERIAL, &iopts);
+ for (const ImportOption &E : iopts) {
+ if (!matdata.has(E.option.name)) {
+ matdata[E.option.name] = E.default_value;
+ }
+ }
+ }
for (int j = 0; j < post_importer_plugins.size(); j++) {
post_importer_plugins.write[j]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MATERIAL, p_root, p_node, mat, matdata);
@@ -928,19 +1008,6 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
if (Object::cast_to<AnimationPlayer>(p_node)) {
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
- {
- //make sure this is unique
- node_settings = node_settings.duplicate(true);
- //fill node settings for this node with default values
- List<ImportOption> iopts;
- get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, &iopts);
- for (const ImportOption &E : iopts) {
- if (!node_settings.has(E.option.name)) {
- node_settings[E.option.name] = E.default_value;
- }
- }
- }
-
for (int i = 0; i < post_importer_plugins.size(); i++) {
post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, p_root, p_node, Ref<Resource>(), node_settings);
}
@@ -1077,7 +1144,7 @@ Ref<Animation> ResourceImporterScene::_save_animation_to_file(Ref<Animation> ani
}
if (ResourceCache::has(p_save_to_path)) {
- Ref<Animation> old_anim = Ref<Resource>(ResourceCache::get(p_save_to_path));
+ Ref<Animation> old_anim = ResourceCache::get_ref(p_save_to_path);
if (old_anim.is_valid()) {
old_anim->copy_from(anim);
anim = old_anim;
@@ -1347,6 +1414,10 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"), false));
}
} break;
+ case INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE: {
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "import/skip_import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::OBJECT, "retarget/bone_map", PROPERTY_HINT_RESOURCE_TYPE, "BoneMap", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), Variant()));
+ } break;
default: {
}
}
@@ -1461,6 +1532,12 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor
}
}
} break;
+ case INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE: {
+ const bool use_retarget = p_options["retarget/bone_map"].get_validated_object() != nullptr;
+ if (p_option != "retarget/bone_map" && p_option.begins_with("retarget/")) {
+ return use_retarget;
+ }
+ } break;
default: {
}
}
@@ -1496,6 +1573,8 @@ bool ResourceImporterScene::get_internal_option_update_view_required(InternalImp
} break;
case INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE: {
} break;
+ case INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE: {
+ } break;
default: {
}
}
@@ -1584,6 +1663,16 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
if (!mesh_id.is_empty() && p_mesh_data.has(mesh_id)) {
Dictionary mesh_settings = p_mesh_data[mesh_id];
+ {
+ //fill node settings for this node with default values
+ List<ImportOption> iopts;
+ get_internal_import_options(INTERNAL_IMPORT_CATEGORY_MESH, &iopts);
+ for (const ImportOption &E : iopts) {
+ if (!mesh_settings.has(E.option.name)) {
+ mesh_settings[E.option.name] = E.default_value;
+ }
+ }
+ }
if (mesh_settings.has("generate/shadow_meshes")) {
int shadow_meshes = mesh_settings["generate/shadow_meshes"];
@@ -1673,7 +1762,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
}
if (!save_to_file.is_empty()) {
- Ref<Mesh> existing = Ref<Resource>(ResourceCache::get(save_to_file));
+ Ref<Mesh> existing = ResourceCache::get_ref(save_to_file);
if (existing.is_valid()) {
//if somehow an existing one is useful, create
existing->reset_state();
@@ -1883,7 +1972,7 @@ void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, Ani
}
}
-Node *ResourceImporterScene::pre_import(const String &p_source_file) {
+Node *ResourceImporterScene::pre_import(const String &p_source_file, const HashMap<StringName, Variant> &p_options) {
Ref<EditorSceneFormatImporter> importer;
String ext = p_source_file.get_extension().to_lower();
@@ -1908,8 +1997,13 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file) {
ERR_FAIL_COND_V(!importer.is_valid(), nullptr);
+ int bake_fps = 30;
+ if (p_options.has(SNAME("animation/fps"))) {
+ bake_fps = p_options[SNAME("animation/fps")];
+ }
+
Error err = OK;
- Node *scene = importer->import_scene(p_source_file, EditorSceneFormatImporter::IMPORT_ANIMATION | EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, HashMap<StringName, Variant>(), 15, nullptr, &err);
+ Node *scene = importer->import_scene(p_source_file, EditorSceneFormatImporter::IMPORT_ANIMATION | EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, p_options, bake_fps, nullptr, &err);
if (!scene || err != OK) {
return nullptr;
}
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index 16cf3d651d..b77c1dccb4 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -106,6 +106,7 @@ public:
INTERNAL_IMPORT_CATEGORY_MATERIAL,
INTERNAL_IMPORT_CATEGORY_ANIMATION,
INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,
+ INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE,
INTERNAL_IMPORT_CATEGORY_MAX
};
@@ -259,6 +260,7 @@ public:
INTERNAL_IMPORT_CATEGORY_MATERIAL = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MATERIAL,
INTERNAL_IMPORT_CATEGORY_ANIMATION = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION,
INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE,
+ INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE,
INTERNAL_IMPORT_CATEGORY_MAX = EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MAX
};
@@ -279,7 +281,7 @@ public:
void _optimize_animations(AnimationPlayer *anim, float p_max_lin_error, float p_max_ang_error, float p_max_angle);
void _compress_animations(AnimationPlayer *anim, int p_page_size_kb);
- Node *pre_import(const String &p_source_file);
+ Node *pre_import(const String &p_source_file, const HashMap<StringName, Variant> &p_options);
virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
virtual bool has_advanced_options() const override;
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 5364b53b57..deb3047864 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -104,24 +104,30 @@ void ResourceImporterTexture::update_imports() {
bool changed = false;
if (E.value.flags & MAKE_NORMAL_FLAG && int(cf->get_value("params", "compress/normal_map")) == 0) {
+ print_line(vformat(TTR("%s: Texture detected as used as a normal map in 3D. Enabling red-green texture compression to reduce memory usage (blue channel is discarded)."), String(E.key)));
cf->set_value("params", "compress/normal_map", 1);
changed = true;
}
if (E.value.flags & MAKE_ROUGHNESS_FLAG && int(cf->get_value("params", "roughness/mode")) == 0) {
+ print_line(vformat(TTR("%s: Texture detected as used as a roughness map in 3D. Enabling roughness limiter based on the detected associated normal map at %s."), String(E.key), E.value.normal_path_for_roughness));
cf->set_value("params", "roughness/mode", E.value.channel_for_roughness + 2);
cf->set_value("params", "roughness/src_normal", E.value.normal_path_for_roughness);
changed = true;
}
if (E.value.flags & MAKE_3D_FLAG && bool(cf->get_value("params", "detect_3d/compress_to"))) {
- int compress_to = cf->get_value("params", "detect_3d/compress_to");
+ const int compress_to = cf->get_value("params", "detect_3d/compress_to");
+ String compress_string;
cf->set_value("params", "detect_3d/compress_to", 0);
if (compress_to == 1) {
cf->set_value("params", "compress/mode", COMPRESS_VRAM_COMPRESSED);
+ compress_string = "VRAM Compressed (S3TC/ETC/BPTC)";
} else if (compress_to == 2) {
cf->set_value("params", "compress/mode", COMPRESS_BASIS_UNIVERSAL);
+ compress_string = "Basis Universal";
}
+ print_line(vformat(TTR("%s: Texture detected as used in 3D. Enabling mipmap generation and setting the texture compression mode to %s."), String(E.key), compress_string));
cf->set_value("params", "mipmaps/generate", true);
changed = true;
}
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index aa338a6c0d..93afb3381e 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -88,13 +88,7 @@ Error ResourceImporterTextureAtlas::import(const String &p_source_file, const St
//use an xpm because it's size independent, the editor images are vector and size dependent
//it's a simple hack
Ref<Image> broken = memnew(Image((const char **)atlas_import_failed_xpm));
- Ref<ImageTexture> broken_texture;
- broken_texture.instantiate();
- broken_texture->create_from_image(broken);
-
- String target_file = p_save_path + ".tex";
-
- ResourceSaver::save(target_file, broken_texture);
+ ResourceSaver::save(p_save_path + ".tex", ImageTexture::create_from_image(broken));
return OK;
}
@@ -218,7 +212,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
EditorAtlasPacker::Chart chart;
- Rect2 used_rect = Rect2(Vector2(), image->get_size());
+ Rect2i used_rect = Rect2i(Vector2i(), image->get_size());
if (trim_alpha_border_from_region) {
// Clip a region from the image.
used_rect = image->get_used_rect();
@@ -226,9 +220,9 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
pack_data.region = used_rect;
chart.vertices.push_back(used_rect.position);
- chart.vertices.push_back(used_rect.position + Vector2(used_rect.size.x, 0));
- chart.vertices.push_back(used_rect.position + Vector2(used_rect.size.x, used_rect.size.y));
- chart.vertices.push_back(used_rect.position + Vector2(0, used_rect.size.y));
+ chart.vertices.push_back(used_rect.position + Vector2i(used_rect.size.x, 0));
+ chart.vertices.push_back(used_rect.position + Vector2i(used_rect.size.x, used_rect.size.y));
+ chart.vertices.push_back(used_rect.position + Vector2i(0, used_rect.size.y));
EditorAtlasPacker::Chart::Face f;
f.vertex[0] = 0;
f.vertex[1] = 1;
@@ -306,13 +300,9 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
//update cache if existing, else create
Ref<Texture2D> cache;
- if (ResourceCache::has(p_group_file)) {
- Resource *resptr = ResourceCache::get(p_group_file);
- cache.reference_ptr(resptr);
- } else {
- Ref<ImageTexture> res_cache;
- res_cache.instantiate();
- res_cache->create_from_image(new_atlas);
+ cache = ResourceCache::get_ref(p_group_file);
+ if (!cache.is_valid()) {
+ Ref<ImageTexture> res_cache = ImageTexture::create_from_image(new_atlas);
res_cache->set_path(p_group_file);
cache = res_cache;
}
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 362940dc17..f0ba1eb7a1 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -162,7 +162,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
//Consider revision for engine version 3.0
compression_code = file->get_16();
if (compression_code != 1 && compression_code != 3) {
- ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
+ ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM or IEEE float instead.");
}
format_channels = file->get_16();
@@ -180,6 +180,10 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32).");
}
+ if (compression_code == 3 && format_bits % 32) {
+ ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Invalid amount of bits in the IEEE float sample (should be 32 or 64).");
+ }
+
/* Don't need anything else, continue */
format_found = true;
}
@@ -208,36 +212,46 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
data.resize(frames * format_channels);
- if (format_bits == 8) {
- for (int i = 0; i < frames * format_channels; i++) {
- // 8 bit samples are UNSIGNED
+ if (compression_code == 1) {
+ if (format_bits == 8) {
+ for (int i = 0; i < frames * format_channels; i++) {
+ // 8 bit samples are UNSIGNED
- data.write[i] = int8_t(file->get_8() - 128) / 128.f;
- }
- } else if (format_bits == 32 && compression_code == 3) {
- for (int i = 0; i < frames * format_channels; i++) {
- //32 bit IEEE Float
+ data.write[i] = int8_t(file->get_8() - 128) / 128.f;
+ }
+ } else if (format_bits == 16) {
+ for (int i = 0; i < frames * format_channels; i++) {
+ //16 bit SIGNED
- data.write[i] = file->get_float();
- }
- } else if (format_bits == 16) {
- for (int i = 0; i < frames * format_channels; i++) {
- //16 bit SIGNED
+ data.write[i] = int16_t(file->get_16()) / 32768.f;
+ }
+ } else {
+ for (int i = 0; i < frames * format_channels; i++) {
+ //16+ bits samples are SIGNED
+ // if sample is > 16 bits, just read extra bytes
+
+ uint32_t s = 0;
+ for (int b = 0; b < (format_bits >> 3); b++) {
+ s |= ((uint32_t)file->get_8()) << (b * 8);
+ }
+ s <<= (32 - format_bits);
- data.write[i] = int16_t(file->get_16()) / 32768.f;
+ data.write[i] = (int32_t(s) >> 16) / 32768.f;
+ }
}
- } else {
- for (int i = 0; i < frames * format_channels; i++) {
- //16+ bits samples are SIGNED
- // if sample is > 16 bits, just read extra bytes
-
- uint32_t s = 0;
- for (int b = 0; b < (format_bits >> 3); b++) {
- s |= ((uint32_t)file->get_8()) << (b * 8);
+ } else if (compression_code == 3) {
+ if (format_bits == 32) {
+ for (int i = 0; i < frames * format_channels; i++) {
+ //32 bit IEEE Float
+
+ data.write[i] = file->get_float();
}
- s <<= (32 - format_bits);
+ } else if (format_bits == 64) {
+ for (int i = 0; i < frames * format_channels; i++) {
+ //64 bit IEEE Float
- data.write[i] = (int32_t(s) >> 16) / 32768.f;
+ data.write[i] = file->get_double();
+ }
}
}
diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp
index 83dff30dfa..0e2967dc42 100644
--- a/editor/import/scene_import_settings.cpp
+++ b/editor/import/scene_import_settings.cpp
@@ -135,6 +135,12 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
String import_id;
bool has_import_id = false;
+ bool created = false;
+ if (!material_set.has(p_material)) {
+ material_set.insert(p_material);
+ created = true;
+ }
+
if (p_material->has_meta("import_id")) {
import_id = p_material->get_meta("import_id");
has_import_id = true;
@@ -142,7 +148,7 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
import_id = p_material->get_name();
has_import_id = true;
} else {
- import_id = "@MATERIAL:" + itos(material_set.size());
+ import_id = "@MATERIAL:" + itos(material_set.size() - 1);
}
if (!material_map.has(import_id)) {
@@ -160,14 +166,12 @@ void SceneImportSettings::_fill_material(Tree *p_tree, const Ref<Material> &p_ma
Ref<Texture2D> icon = get_theme_icon(SNAME("StandardMaterial3D"), SNAME("EditorIcons"));
TreeItem *item = p_tree->create_item(p_parent);
- item->set_text(0, p_material->get_name());
- item->set_icon(0, icon);
-
- bool created = false;
- if (!material_set.has(p_material)) {
- material_set.insert(p_material);
- created = true;
+ if (p_material->get_name().is_empty()) {
+ item->set_text(0, TTR("<Unnamed Material>"));
+ } else {
+ item->set_text(0, p_material->get_name());
}
+ item->set_icon(0, icon);
item->set_meta("type", "Material");
item->set_meta("import_id", import_id);
@@ -339,6 +343,8 @@ void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) {
category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;
} else if (Object::cast_to<AnimationPlayer>(p_node)) {
category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;
+ } else if (Object::cast_to<Skeleton3D>(p_node)) {
+ category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;
} else {
category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;
}
@@ -536,12 +542,6 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati
scene_import_settings_data->settings = nullptr;
scene_import_settings_data->path = p_path;
- scene = ResourceImporterScene::get_scene_singleton()->pre_import(p_path); // Use the scene singleton here because we want to see the full thing.
- if (scene == nullptr) {
- EditorNode::get_singleton()->show_warning(TTR("Error opening scene"));
- return;
- }
-
// Visibility
data_mode->set_tab_hidden(1, p_for_animation);
data_mode->set_tab_hidden(2, p_for_animation);
@@ -587,6 +587,12 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati
}
}
+ scene = ResourceImporterScene::get_scene_singleton()->pre_import(p_path, defaults); // Use the scene singleton here because we want to see the full thing.
+ if (scene == nullptr) {
+ EditorNode::get_singleton()->show_warning(TTR("Error opening scene"));
+ return;
+ }
+
first_aabb = true;
_update_scene();
@@ -604,6 +610,9 @@ void SceneImportSettings::open_settings(const String &p_path, bool p_for_animati
_update_view_gizmos();
_update_camera();
+ // Start with the root item (Scene) selected.
+ scene_tree->get_root()->select(0);
+
if (p_for_animation) {
set_title(vformat(TTR("Advanced Import Settings for AnimationLibrary '%s'"), base_path.get_file()));
} else {
@@ -617,6 +626,13 @@ SceneImportSettings *SceneImportSettings::get_singleton() {
return singleton;
}
+Node *SceneImportSettings::get_selected_node() {
+ if (selected_id == "") {
+ return nullptr;
+ }
+ return node_map[selected_id].node;
+}
+
void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
selecting = true;
scene_import_settings_data->hide_options = false;
@@ -657,6 +673,8 @@ void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
scene_import_settings_data->hide_options = editing_animation;
} else if (Object::cast_to<AnimationPlayer>(nd.node)) {
scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;
+ } else if (Object::cast_to<Skeleton3D>(nd.node)) {
+ scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;
} else {
scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;
scene_import_settings_data->hide_options = editing_animation;
@@ -1041,7 +1059,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
}
external_paths->set_title(TTR("Extract Materials to Resource Files"));
- external_paths->get_ok_button()->set_text(TTR("Extract"));
+ external_paths->set_ok_button_text(TTR("Extract"));
} break;
case ACTION_CHOOSE_MESH_SAVE_PATHS: {
for (const KeyValue<String, MeshData> &E : mesh_map) {
@@ -1094,7 +1112,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
}
external_paths->set_title(TTR("Set paths to save meshes as resource files on Reimport"));
- external_paths->get_ok_button()->set_text(TTR("Set Paths"));
+ external_paths->set_ok_button_text(TTR("Set Paths"));
} break;
case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {
for (const KeyValue<String, AnimationData> &E : animation_map) {
@@ -1140,7 +1158,7 @@ void SceneImportSettings::_save_dir_callback(const String &p_path) {
}
external_paths->set_title(TTR("Set paths to save animations as resource files on Reimport"));
- external_paths->get_ok_button()->set_text(TTR("Set Paths"));
+ external_paths->set_ok_button_text(TTR("Set Paths"));
} break;
}
@@ -1229,6 +1247,7 @@ SceneImportSettings::SceneImportSettings() {
data_mode = memnew(TabContainer);
tree_split->add_child(data_mode);
data_mode->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
+ data_mode->set_theme_type_variation("TabContainerOdd");
property_split = memnew(HSplitContainer);
tree_split->add_child(property_split);
@@ -1328,8 +1347,8 @@ SceneImportSettings::SceneImportSettings() {
scene_import_settings_data = memnew(SceneImportSettingsData);
- get_ok_button()->set_text(TTR("Reimport"));
- get_cancel_button()->set_text(TTR("Close"));
+ set_ok_button_text(TTR("Reimport"));
+ set_cancel_button_text(TTR("Close"));
external_paths = memnew(ConfirmationDialog);
add_child(external_paths);
@@ -1353,7 +1372,7 @@ SceneImportSettings::SceneImportSettings() {
HBoxContainer *extension_hb = memnew(HBoxContainer);
save_path->get_vbox()->add_child(extension_hb);
extension_hb->add_spacer();
- extension_hb->add_child(memnew(Label(TTR("Save Extension: "))));
+ extension_hb->add_child(memnew(Label(TTR("Save Extension:"))));
external_extension_type = memnew(OptionButton);
extension_hb->add_child(external_extension_type);
external_extension_type->add_item(TTR("Text: *.tres"));
@@ -1363,8 +1382,8 @@ SceneImportSettings::SceneImportSettings() {
item_save_path = memnew(EditorFileDialog);
item_save_path->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
- item_save_path->add_filter("*.tres; " + TTR("Text Resource"));
- item_save_path->add_filter("*.res; " + TTR("Binary Resource"));
+ item_save_path->add_filter("*.tres", TTR("Text Resource"));
+ item_save_path->add_filter("*.res", TTR("Binary Resource"));
add_child(item_save_path);
item_save_path->connect("file_selected", callable_mp(this, &SceneImportSettings::_save_path_changed));
diff --git a/editor/import/scene_import_settings.h b/editor/import/scene_import_settings.h
index 81d13166ab..b5cf82f64b 100644
--- a/editor/import/scene_import_settings.h
+++ b/editor/import/scene_import_settings.h
@@ -201,6 +201,7 @@ public:
void update_view();
void open_settings(const String &p_path, bool p_for_animation = false);
static SceneImportSettings *get_singleton();
+ Node *get_selected_node();
SceneImportSettings();
~SceneImportSettings();
};