summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/collada.cpp66
-rw-r--r--editor/import/collada.h76
-rw-r--r--editor/import/dynamic_font_import_settings.cpp112
-rw-r--r--editor/import/dynamic_font_import_settings.h15
-rw-r--r--editor/import/editor_import_collada.cpp93
-rw-r--r--editor/import/editor_import_collada.h3
-rw-r--r--editor/import/editor_import_plugin.cpp16
-rw-r--r--editor/import/editor_import_plugin.h4
-rw-r--r--editor/import/resource_importer_bitmask.cpp4
-rw-r--r--editor/import/resource_importer_bitmask.h4
-rw-r--r--editor/import/resource_importer_bmfont.cpp4
-rw-r--r--editor/import/resource_importer_bmfont.h4
-rw-r--r--editor/import/resource_importer_csv_translation.cpp9
-rw-r--r--editor/import/resource_importer_csv_translation.h4
-rw-r--r--editor/import/resource_importer_dynamic_font.cpp22
-rw-r--r--editor/import/resource_importer_dynamic_font.h4
-rw-r--r--editor/import/resource_importer_image.cpp15
-rw-r--r--editor/import/resource_importer_image.h4
-rw-r--r--editor/import/resource_importer_imagefont.cpp7
-rw-r--r--editor/import/resource_importer_imagefont.h4
-rw-r--r--editor/import/resource_importer_layered_texture.cpp36
-rw-r--r--editor/import/resource_importer_layered_texture.h10
-rw-r--r--editor/import/resource_importer_obj.cpp24
-rw-r--r--editor/import/resource_importer_obj.h7
-rw-r--r--editor/import/resource_importer_scene.cpp255
-rw-r--r--editor/import/resource_importer_scene.h67
-rw-r--r--editor/import/resource_importer_shader_file.cpp8
-rw-r--r--editor/import/resource_importer_shader_file.h4
-rw-r--r--editor/import/resource_importer_texture.cpp119
-rw-r--r--editor/import/resource_importer_texture.h18
-rw-r--r--editor/import/resource_importer_texture_atlas.cpp18
-rw-r--r--editor/import/resource_importer_texture_atlas.h6
-rw-r--r--editor/import/resource_importer_wav.cpp72
-rw-r--r--editor/import/resource_importer_wav.h4
-rw-r--r--editor/import/scene_import_settings.cpp166
-rw-r--r--editor/import/scene_import_settings.h101
36 files changed, 813 insertions, 572 deletions
diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp
index fe32399fc6..f4d19fe8b6 100644
--- a/editor/import/collada.cpp
+++ b/editor/import/collada.cpp
@@ -58,7 +58,7 @@ Transform3D Collada::get_root_transform() const {
return unit_scale_transform;
}
-void Collada::Vertex::fix_unit_scale(Collada &state) {
+void Collada::Vertex::fix_unit_scale(const Collada &state) {
#ifdef COLLADA_IMPORT_SCALE_SCENE
vertex *= state.state.unit_scale;
#endif
@@ -105,15 +105,15 @@ Transform3D Collada::fix_transform(const Transform3D &p_transform) {
static Transform3D _read_transform_from_array(const Vector<float> &array, int ofs = 0) {
Transform3D tr;
// i wonder why collada matrices are transposed, given that's opposed to opengl..
- tr.basis.elements[0][0] = array[0 + ofs];
- tr.basis.elements[0][1] = array[1 + ofs];
- tr.basis.elements[0][2] = array[2 + ofs];
- tr.basis.elements[1][0] = array[4 + ofs];
- tr.basis.elements[1][1] = array[5 + ofs];
- tr.basis.elements[1][2] = array[6 + ofs];
- tr.basis.elements[2][0] = array[8 + ofs];
- tr.basis.elements[2][1] = array[9 + ofs];
- tr.basis.elements[2][2] = array[10 + ofs];
+ tr.basis.rows[0][0] = array[0 + ofs];
+ tr.basis.rows[0][1] = array[1 + ofs];
+ tr.basis.rows[0][2] = array[2 + ofs];
+ tr.basis.rows[1][0] = array[4 + ofs];
+ tr.basis.rows[1][1] = array[5 + ofs];
+ tr.basis.rows[1][2] = array[6 + ofs];
+ tr.basis.rows[2][0] = array[8 + ofs];
+ tr.basis.rows[2][1] = array[9 + ofs];
+ tr.basis.rows[2][2] = array[10 + ofs];
tr.origin.x = array[3 + ofs];
tr.origin.y = array[7 + ofs];
tr.origin.z = array[11 + ofs];
@@ -122,7 +122,7 @@ static Transform3D _read_transform_from_array(const Vector<float> &array, int of
/* STRUCTURES */
-Transform3D Collada::Node::compute_transform(Collada &state) const {
+Transform3D Collada::Node::compute_transform(const Collada &state) const {
Transform3D xform;
for (int i = 0; i < xform_list.size(); i++) {
@@ -210,15 +210,15 @@ Vector<float> Collada::AnimationTrack::get_value_at_time(float p_time) const {
ret.resize(16);
Transform3D tr;
// i wonder why collada matrices are transposed, given that's opposed to opengl..
- ret.write[0] = interp.basis.elements[0][0];
- ret.write[1] = interp.basis.elements[0][1];
- ret.write[2] = interp.basis.elements[0][2];
- ret.write[4] = interp.basis.elements[1][0];
- ret.write[5] = interp.basis.elements[1][1];
- ret.write[6] = interp.basis.elements[1][2];
- ret.write[8] = interp.basis.elements[2][0];
- ret.write[9] = interp.basis.elements[2][1];
- ret.write[10] = interp.basis.elements[2][2];
+ ret.write[0] = interp.basis.rows[0][0];
+ ret.write[1] = interp.basis.rows[0][1];
+ ret.write[2] = interp.basis.rows[0][2];
+ ret.write[4] = interp.basis.rows[1][0];
+ ret.write[5] = interp.basis.rows[1][1];
+ ret.write[6] = interp.basis.rows[1][2];
+ ret.write[8] = interp.basis.rows[2][0];
+ ret.write[9] = interp.basis.rows[2][1];
+ ret.write[10] = interp.basis.rows[2][2];
ret.write[3] = interp.origin.x;
ret.write[7] = interp.origin.y;
ret.write[11] = interp.origin.z;
@@ -1645,12 +1645,12 @@ void Collada::_parse_animation(XMLParser &parser) {
return;
}
- Map<String, Vector<float>> float_sources;
- Map<String, Vector<String>> string_sources;
- Map<String, int> source_strides;
- Map<String, Map<String, String>> samplers;
- Map<String, Vector<String>> source_param_names;
- Map<String, Vector<String>> source_param_types;
+ HashMap<String, Vector<float>> float_sources;
+ HashMap<String, Vector<String>> string_sources;
+ HashMap<String, int> source_strides;
+ HashMap<String, HashMap<String, String>> samplers;
+ HashMap<String, Vector<String>> source_param_names;
+ HashMap<String, Vector<String>> source_param_types;
String id = "";
if (parser.has_attribute("id")) {
@@ -1685,7 +1685,7 @@ void Collada::_parse_animation(XMLParser &parser) {
}
} else if (name == "sampler") {
current_sampler = parser.get_attribute_value("id");
- samplers[current_sampler] = Map<String, String>();
+ samplers[current_sampler] = HashMap<String, String>();
} else if (name == "param") {
if (parser.has_attribute("name")) {
source_param_names[current_source].push_back(parser.get_attribute_value("name"));
@@ -1718,7 +1718,7 @@ void Collada::_parse_animation(XMLParser &parser) {
String source = _uri_to_id(channel_sources[i]);
String target = channel_targets[i];
ERR_CONTINUE(!samplers.has(source));
- Map<String, String> &sampler = samplers[source];
+ HashMap<String, String> &sampler = samplers[source];
ERR_CONTINUE(!sampler.has("INPUT")); //no input semantic? wtf?
String input_id = _uri_to_id(sampler["INPUT"]);
@@ -2029,7 +2029,7 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) {
NodeGeometry *gnode = static_cast<NodeGeometry *>(p_node);
if (gnode->controller) {
// recount skeletons used
- Set<NodeSkeleton *> skeletons;
+ HashSet<NodeSkeleton *> skeletons;
for (int i = 0; i < gnode->skeletons.size(); i++) {
String nodeid = gnode->skeletons[i];
@@ -2049,11 +2049,11 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) {
if (skeletons.size() > 1) {
//do the merger!!
- Set<NodeSkeleton *>::Element *E = skeletons.front();
- NodeSkeleton *base = E->get();
+ HashSet<NodeSkeleton *>::Iterator E = skeletons.begin();
+ NodeSkeleton *base = *E;
- for (E = E->next(); E; E = E->next()) {
- NodeSkeleton *merged = E->get();
+ for (++E; E; ++E) {
+ NodeSkeleton *merged = *E;
_remove_node(p_vscene, merged);
for (int i = 0; i < merged->children.size(); i++) {
_joint_set_owner(merged->children[i], base);
diff --git a/editor/import/collada.h b/editor/import/collada.h
index b5e4cd9983..f1d9c5593f 100644
--- a/editor/import/collada.h
+++ b/editor/import/collada.h
@@ -33,7 +33,7 @@
#include "core/config/project_settings.h"
#include "core/io/xml_parser.h"
-#include "core/templates/map.h"
+#include "core/templates/rb_map.h"
#include "scene/resources/material.h"
class Collada {
@@ -54,7 +54,7 @@ public:
struct Effect {
String name;
- Map<String, Variant> params;
+ HashMap<String, Variant> params;
struct Channel {
int uv_idx = 0;
@@ -131,13 +131,13 @@ public:
int stride = 0;
};
- Map<String, Source> sources;
+ HashMap<String, Source> sources;
struct Vertices {
- Map<String, String> sources;
+ HashMap<String, String> sources;
};
- Map<String, Vertices> vertices;
+ HashMap<String, Vertices> vertices;
struct Primitives {
struct SourceRef {
@@ -146,7 +146,7 @@ public:
};
String material;
- Map<String, SourceRef> sources;
+ HashMap<String, SourceRef> sources;
Vector<float> polygons;
Vector<float> indices;
int count = 0;
@@ -171,9 +171,9 @@ public:
int stride = 0;
};
- Map<String, Source> sources;
+ HashMap<String, Source> sources;
- Map<String, String> control_vertices;
+ HashMap<String, String> control_vertices;
CurveData() {}
};
@@ -191,10 +191,10 @@ public:
Source() {}
};
- Map<String, Source> sources;
+ HashMap<String, Source> sources;
struct Joints {
- Map<String, String> sources;
+ HashMap<String, String> sources;
} joints;
struct Weights {
@@ -204,13 +204,13 @@ public:
};
String material;
- Map<String, SourceRef> sources;
+ HashMap<String, SourceRef> sources;
Vector<float> sets;
Vector<float> indices;
int count = 0;
} weights;
- Map<String, Transform3D> bone_rest_map;
+ HashMap<String, Transform3D> bone_rest_map;
SkinControllerData() {}
};
@@ -226,9 +226,9 @@ public:
Source() {}
};
- Map<String, Source> sources;
+ HashMap<String, Source> sources;
- Map<String, String> targets;
+ HashMap<String, String> targets;
MorphControllerData() {}
};
@@ -266,7 +266,7 @@ public:
}
}
- void fix_unit_scale(Collada &state);
+ void fix_unit_scale(const Collada &state);
bool operator<(const Vertex &p_vert) const {
if (uid == p_vert.uid) {
@@ -348,7 +348,7 @@ public:
Node *parent = nullptr;
- Transform3D compute_transform(Collada &state) const;
+ Transform3D compute_transform(const Collada &state) const;
Transform3D get_global_transform() const;
Transform3D get_transform() const;
@@ -382,7 +382,7 @@ public:
String target;
};
- Map<String, Material> material_map;
+ HashMap<String, Material> material_map;
Vector<String> skeletons;
NodeGeometry() { type = TYPE_GEOMETRY; }
@@ -476,28 +476,28 @@ public:
}
} version;
- Map<String, CameraData> camera_data_map;
- Map<String, MeshData> mesh_data_map;
- Map<String, LightData> light_data_map;
- Map<String, CurveData> curve_data_map;
+ HashMap<String, CameraData> camera_data_map;
+ HashMap<String, MeshData> mesh_data_map;
+ HashMap<String, LightData> light_data_map;
+ HashMap<String, CurveData> curve_data_map;
- Map<String, String> mesh_name_map;
- Map<String, String> morph_name_map;
- Map<String, String> morph_ownership_map;
- Map<String, SkinControllerData> skin_controller_data_map;
- Map<String, MorphControllerData> morph_controller_data_map;
+ HashMap<String, String> mesh_name_map;
+ HashMap<String, String> morph_name_map;
+ HashMap<String, String> morph_ownership_map;
+ HashMap<String, SkinControllerData> skin_controller_data_map;
+ HashMap<String, MorphControllerData> morph_controller_data_map;
- Map<String, Image> image_map;
- Map<String, Material> material_map;
- Map<String, Effect> effect_map;
+ HashMap<String, Image> image_map;
+ HashMap<String, Material> material_map;
+ HashMap<String, Effect> effect_map;
- Map<String, VisualScene> visual_scene_map;
- Map<String, Node *> scene_map;
- Set<String> idref_joints;
- Map<String, String> sid_to_node_map;
- //Map<String,NodeJoint*> bone_map;
+ HashMap<String, VisualScene> visual_scene_map;
+ HashMap<String, Node *> scene_map;
+ HashSet<String> idref_joints;
+ HashMap<String, String> sid_to_node_map;
+ //RBMap<String,NodeJoint*> bone_map;
- Map<String, Transform3D> bone_rest_map;
+ HashMap<String, Transform3D> bone_rest_map;
String local_path;
String root_visual_scene;
@@ -505,8 +505,8 @@ public:
Vector<AnimationClip> animation_clips;
Vector<AnimationTrack> animation_tracks;
- Map<String, Vector<int>> referenced_tracks;
- Map<String, Vector<int>> by_id_tracks;
+ HashMap<String, Vector<int>> referenced_tracks;
+ HashMap<String, Vector<int>> by_id_tracks;
float animation_length = 0;
@@ -524,7 +524,7 @@ public:
int get_uv_channel(String p_name);
private: // private stuff
- Map<String, int> channel_map;
+ HashMap<String, int> channel_map;
void _parse_asset(XMLParser &parser);
void _parse_image(XMLParser &parser);
diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp
index ebfb0b32fb..5e203a3e39 100644
--- a/editor/import/dynamic_font_import_settings.cpp
+++ b/editor/import/dynamic_font_import_settings.cpp
@@ -45,8 +45,8 @@ class DynamicFontImportSettingsData : public RefCounted {
GDCLASS(DynamicFontImportSettingsData, RefCounted)
friend class DynamicFontImportSettings;
- Map<StringName, Variant> settings;
- Map<StringName, Variant> defaults;
+ HashMap<StringName, Variant> settings;
+ HashMap<StringName, Variant> defaults;
List<ResourceImporter::ImportOption> options;
DynamicFontImportSettings *owner = nullptr;
@@ -454,10 +454,18 @@ 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 (p_edited_property == "face_index") {
+ if (font_preview->get_data_count() > 0) {
+ font_preview->get_data(0)->set_face_index(import_settings_data->get("face_index"));
+ }
+ } else 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"));
@@ -484,6 +492,14 @@ void DynamicFontImportSettings::_main_prop_changed(const String &p_edited_proper
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"));
@@ -535,7 +551,11 @@ void DynamicFontImportSettings::_variation_selected() {
}
}
-void DynamicFontImportSettings::_variation_remove(Object *p_item, int p_column, int p_id) {
+void DynamicFontImportSettings::_variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
+ if (p_button != MouseButton::LEFT) {
+ return;
+ }
+
TreeItem *vars_item = (TreeItem *)p_item;
ERR_FAIL_NULL(vars_item);
@@ -569,10 +589,10 @@ void DynamicFontImportSettings::_variations_validate() {
for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) {
if (vars_item_b != vars_item_a) {
bool match = true;
- for (Map<StringName, Variant>::Element *E = import_variation_data_a->settings.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Variant> &E : import_variation_data_a->settings) {
Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0);
ERR_FAIL_NULL(import_variation_data_b);
- match = match && (import_variation_data_b->settings[E->key()] == E->get());
+ match = match && (import_variation_data_b->settings[E.key] == E.value);
}
if (match) {
warn = TTR("Warning: Multiple configurations have identical settings. Duplicates will be ignored.");
@@ -609,7 +629,7 @@ void DynamicFontImportSettings::_change_text_opts() {
void DynamicFontImportSettings::_glyph_clear() {
selected_glyphs.clear();
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(selected_glyphs.size()));
_range_selected();
}
@@ -637,8 +657,8 @@ void DynamicFontImportSettings::_glyph_text_selected() {
selected_glyphs.insert(gl[i].index);
}
}
- TS->free(text_rid);
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ TS->free_rid(text_rid);
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(selected_glyphs.size()));
}
_range_selected();
}
@@ -665,7 +685,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(selected_glyphs.size()));
item = glyph_tree->get_selected();
ERR_FAIL_NULL(item);
@@ -753,7 +773,7 @@ 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(selected_glyphs.size()));
}
bool DynamicFontImportSettings::_char_update(int32_t p_char) {
@@ -767,7 +787,6 @@ bool DynamicFontImportSettings::_char_update(int32_t p_char) {
selected_chars.insert(p_char);
return true;
}
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
}
void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) {
@@ -821,7 +840,11 @@ void DynamicFontImportSettings::_lang_add_item(const String &p_locale) {
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) {
+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);
@@ -853,7 +876,11 @@ void DynamicFontImportSettings::_ot_add_item(int p_option) {
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) {
+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);
@@ -880,7 +907,11 @@ void DynamicFontImportSettings::_script_add_item(int p_option) {
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) {
+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);
@@ -916,15 +947,19 @@ void DynamicFontImportSettings::_notification(int p_what) {
}
void DynamicFontImportSettings::_re_import() {
- Map<StringName, Variant> main_settings;
+ 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");
main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range");
main_settings["msdf_size"] = import_settings_data->get("msdf_size");
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["compress"] = import_settings_data->get("compress");
@@ -936,11 +971,11 @@ void DynamicFontImportSettings::_re_import() {
String name = vars_item->get_text(0);
variation += ("name=" + name);
- for (Map<StringName, Variant>::Element *E = import_variation_data->settings.front(); E; E = E->next()) {
+ for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) {
if (!variation.is_empty()) {
variation += ",";
}
- variation += (String(E->key()) + "=" + String(E->get()));
+ variation += (String(E.key) + "=" + String(E.value));
}
variations.push_back(variation);
}
@@ -977,7 +1012,7 @@ void DynamicFontImportSettings::_re_import() {
if (!selected_chars.is_empty()) {
Vector<String> ranges;
char32_t start = selected_chars.front()->get();
- for (Set<char32_t>::Element *E = selected_chars.front()->next(); E; E = E->next()) {
+ 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();
@@ -990,7 +1025,7 @@ void DynamicFontImportSettings::_re_import() {
if (!selected_glyphs.is_empty()) {
Vector<String> ranges;
int32_t start = selected_glyphs.front()->get();
- for (Set<int32_t>::Element *E = selected_glyphs.front()->next(); E; E = E->next()) {
+ 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();
@@ -1010,8 +1045,8 @@ void DynamicFontImportSettings::_re_import() {
if (OS::get_singleton()->is_stdout_verbose()) {
print_line("Import settings:");
- for (Map<StringName, Variant>::Element *E = main_settings.front(); E; E = E->next()) {
- print_line(String(" ") + String(E->key()).utf8().get_data() + " == " + String(E->get()).utf8().get_data());
+ for (const KeyValue<StringName, Variant> &E : main_settings) {
+ print_line(String(" ") + String(E.key).utf8().get_data() + " == " + String(E.value).utf8().get_data());
}
}
@@ -1262,13 +1297,14 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
}
}
}
- label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size()));
+ label_glyphs->set_text(TTR("Preloaded glyphs:") + " " + itos(selected_glyphs.size()));
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_face_index(import_settings_data->get("face_index"));
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"));
@@ -1276,6 +1312,8 @@ void DynamicFontImportSettings::open_settings(const String &p_path) {
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"));
}
font_preview_label->add_theme_font_override("font", font_preview);
@@ -1328,13 +1366,17 @@ DynamicFontImportSettings *DynamicFontImportSettings::get_singleton() {
DynamicFontImportSettings::DynamicFontImportSettings() {
singleton = this;
+ options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "face_index"), 0));
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));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
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));
@@ -1380,8 +1422,10 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
add_child(root_vb);
main_pages = memnew(TabContainer);
+ 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);
@@ -1394,7 +1438,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 1 layout: Rendering Options
VBoxContainer *page1_vb = memnew(VBoxContainer);
- page1_vb->set_meta("_tab_name", TTR("Rendering options"));
+ page1_vb->set_name(TTR("Rendering Options"));
main_pages->add_child(page1_vb);
page1_description = memnew(Label);
@@ -1425,7 +1469,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 2 layout: Configurations
VBoxContainer *page2_vb = memnew(VBoxContainer);
- page2_vb->set_meta("_tab_name", TTR("Sizes and variations"));
+ page2_vb->set_name(TTR("Sizes and Variations"));
main_pages->add_child(page2_vb);
page2_description = memnew(Label);
@@ -1467,7 +1511,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
vars_list->set_column_expand(1, false);
vars_list->set_column_custom_minimum_width(1, 50 * EDSCALE);
vars_list->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_variation_selected));
- vars_list->connect("button_pressed", callable_mp(this, &DynamicFontImportSettings::_variation_remove));
+ vars_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_variation_remove));
vars_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
inspector_vars = memnew(EditorInspector);
@@ -1477,7 +1521,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 3 layout: Text to select glyphs
VBoxContainer *page3_vb = memnew(VBoxContainer);
- page3_vb->set_meta("_tab_name", TTR("Glyphs from the text"));
+ page3_vb->set_name(TTR("Glyphs from the Text"));
main_pages->add_child(page3_vb);
page3_description = memnew(Label);
@@ -1519,7 +1563,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
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);
@@ -1534,7 +1578,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 4 layout: Character map
VBoxContainer *page4_vb = memnew(VBoxContainer);
- page4_vb->set_meta("_tab_name", TTR("Glyphs from the character map"));
+ page4_vb->set_name(TTR("Glyphs from the Character Map"));
main_pages->add_child(page4_vb);
page4_description = memnew(Label);
@@ -1563,7 +1607,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
}
glyph_table->add_theme_style_override("selected", glyph_table->get_theme_stylebox(SNAME("bg")));
glyph_table->add_theme_style_override("selected_focus", glyph_table->get_theme_stylebox(SNAME("bg")));
- glyph_table->add_theme_constant_override("hseparation", 0);
+ glyph_table->add_theme_constant_override("h_separation", 0);
glyph_table->set_h_size_flags(Control::SIZE_EXPAND_FILL);
glyph_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
@@ -1585,7 +1629,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
// Page 4 layout: Metadata override
VBoxContainer *page5_vb = memnew(VBoxContainer);
- page5_vb->set_meta("_tab_name", TTR("Metadata override"));
+ page5_vb->set_name(TTR("Metadata Override"));
main_pages->add_child(page5_vb);
page5_description = memnew(Label);
@@ -1619,7 +1663,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
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_pressed", callable_mp(this, &DynamicFontImportSettings::_lang_remove));
+ 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);
@@ -1647,7 +1691,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
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_pressed", callable_mp(this, &DynamicFontImportSettings::_script_remove));
+ 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);
@@ -1675,7 +1719,7 @@ DynamicFontImportSettings::DynamicFontImportSettings() {
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_pressed", callable_mp(this, &DynamicFontImportSettings::_ot_remove));
+ ot_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_ot_remove));
ot_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
// Common
diff --git a/editor/import/dynamic_font_import_settings.h b/editor/import/dynamic_font_import_settings.h
index 7b2a9184a4..ba75c98057 100644
--- a/editor/import/dynamic_font_import_settings.h
+++ b/editor/import/dynamic_font_import_settings.h
@@ -33,6 +33,7 @@
#include "editor/import/resource_importer_dynamic_font.h"
+#include "core/templates/rb_set.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/item_list.h"
#include "scene/gui/option_button.h"
@@ -66,7 +67,7 @@ class DynamicFontImportSettings : public ConfirmationDialog {
List<ResourceImporter::ImportOption> options_variations;
List<ResourceImporter::ImportOption> options_general;
- EditorLocaleDialog *locale_select;
+ EditorLocaleDialog *locale_select = nullptr;
Vector<String> script_codes;
// Root layout
@@ -90,7 +91,7 @@ class DynamicFontImportSettings : public ConfirmationDialog {
void _variation_add();
void _variation_selected();
- void _variation_remove(Object *p_item, int p_column, int p_id);
+ void _variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _variation_changed(const String &p_edited_property);
void _variations_validate();
@@ -144,15 +145,15 @@ class DynamicFontImportSettings : public ConfirmationDialog {
void _lang_add();
void _lang_add_item(const String &p_locale);
- void _lang_remove(Object *p_item, int p_column, int p_id);
+ 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);
+ 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);
+ void _ot_remove(Object *p_item, int p_column, int p_id, MouseButton p_button);
// Common
@@ -161,8 +162,8 @@ class DynamicFontImportSettings : public ConfirmationDialog {
Ref<Font> font_preview;
Ref<Font> font_main;
- Set<char32_t> selected_chars;
- Set<int32_t> selected_glyphs;
+ RBSet<char32_t> selected_chars;
+ RBSet<int32_t> selected_glyphs;
void _re_import();
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index 3b5a82b2c3..8d44329022 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -67,34 +67,34 @@ struct ColladaImport {
bool use_mesh_builtin_materials = false;
float bake_fps = 15;
- Map<String, NodeMap> node_map; //map from collada node to engine node
- Map<String, String> node_name_map; //map from collada node to engine node
- Map<String, Ref<ImporterMesh>> mesh_cache;
- Map<String, Ref<Curve3D>> curve_cache;
- Map<String, Ref<Material>> material_cache;
- Map<Collada::Node *, Skeleton3D *> skeleton_map;
+ HashMap<String, NodeMap> node_map; //map from collada node to engine node
+ HashMap<String, String> node_name_map; //map from collada node to engine node
+ HashMap<String, Ref<ImporterMesh>> mesh_cache;
+ HashMap<String, Ref<Curve3D>> curve_cache;
+ HashMap<String, Ref<Material>> material_cache;
+ HashMap<Collada::Node *, Skeleton3D *> skeleton_map;
- Map<Skeleton3D *, Map<String, int>> skeleton_bone_map;
+ HashMap<Skeleton3D *, HashMap<String, int>> skeleton_bone_map;
- Set<String> valid_animated_nodes;
+ HashSet<String> valid_animated_nodes;
Vector<int> valid_animated_properties;
- Map<String, bool> bones_with_animation;
+ HashMap<String, bool> bones_with_animation;
- Set<String> mesh_unique_names;
- Set<String> material_unique_names;
+ HashSet<String> mesh_unique_names;
+ HashSet<String> material_unique_names;
Error _populate_skeleton(Skeleton3D *p_skeleton, Collada::Node *p_node, int &r_bone, int p_parent);
Error _create_scene_skeletons(Collada::Node *p_node);
Error _create_scene(Collada::Node *p_node, Node3D *p_parent);
Error _create_resources(Collada::Node *p_node, bool p_use_compression);
Error _create_material(const String &p_target);
- Error _create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes = Vector<Ref<ImporterMesh>>(), bool p_use_compression = false, bool p_use_mesh_material = false);
+ Error _create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const HashMap<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes = Vector<Ref<ImporterMesh>>(), bool p_use_compression = false, bool p_use_mesh_material = false);
Error load(const String &p_path, int p_flags, bool p_force_make_tangents = false, bool p_use_compression = false);
void _fix_param_animation_tracks();
void create_animation(int p_clip, bool p_import_value_tracks);
void create_animations(bool p_import_value_tracks);
- Set<String> tracks_in_clips;
+ HashSet<String> tracks_in_clips;
Vector<String> missing_textures;
void _pre_process_lights(Collada::Node *p_node);
@@ -467,7 +467,7 @@ Error ColladaImport::_create_material(const String &p_target) {
return OK;
}
-Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const Map<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
+Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p_mesh, const HashMap<String, Collada::NodeGeometry::Material> &p_material_map, const Collada::MeshData &meshdata, const Transform3D &p_local_xform, const Vector<int> &bone_remap, const Collada::SkinControllerData *p_skin_controller, const Collada::MorphControllerData *p_morph_data, Vector<Ref<ImporterMesh>> p_morph_meshes, bool p_use_compression, bool p_use_mesh_material) {
bool local_xform_mirror = p_local_xform.basis.determinant() < 0;
if (p_morph_data) {
@@ -637,7 +637,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p
/* ADD WEIGHTS IF EXIST */
/************************/
- Map<int, Vector<Collada::Vertex::Weight>> pre_weights;
+ HashMap<int, Vector<Collada::Vertex::Weight>> pre_weights;
bool has_weights = false;
@@ -727,7 +727,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p
has_weights = true;
}
- Set<Collada::Vertex> vertex_set; //vertex set will be the vertices
+ RBSet<Collada::Vertex> vertex_set; //vertex set will be the vertices
List<int> indices_list; //indices will be the indices
/**************************/
@@ -875,8 +875,8 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p
Vector<Collada::Vertex> vertex_array; //there we go, vertex array
vertex_array.resize(vertex_set.size());
- for (Set<Collada::Vertex>::Element *F = vertex_set.front(); F; F = F->next()) {
- vertex_array.write[F->get().idx] = F->get();
+ for (const Collada::Vertex &F : vertex_set) {
+ vertex_array.write[F.idx] = F;
}
if (has_weights) {
@@ -994,13 +994,12 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ImporterMesh> &p
Array a = p_morph_meshes[mi]->get_surface_arrays(surface);
//add valid weight and bone arrays if they exist, TODO check if they are unique to shape (generally not)
- if (has_weights) {
- a[Mesh::ARRAY_WEIGHTS] = d[Mesh::ARRAY_WEIGHTS];
- a[Mesh::ARRAY_BONES] = d[Mesh::ARRAY_BONES];
+ // Enforce blend shape mask array format
+ for (int mj = 0; mj < Mesh::ARRAY_MAX; mj++) {
+ if (!(Mesh::ARRAY_FORMAT_BLEND_SHAPE_MASK & (1 << mj))) {
+ a[mj] = Variant();
+ }
}
-
- a[Mesh::ARRAY_INDEX] = Variant();
- //a.resize(Mesh::ARRAY_MAX); //no need for index
mr.push_back(a);
}
@@ -1128,7 +1127,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres
Skeleton3D *sk = Object::cast_to<Skeleton3D>(nmsk.node);
ERR_FAIL_COND_V(!sk, ERR_INVALID_DATA);
ERR_FAIL_COND_V(!skeleton_bone_map.has(sk), ERR_INVALID_DATA);
- Map<String, int> &bone_remap_map = skeleton_bone_map[sk];
+ HashMap<String, int> &bone_remap_map = skeleton_bone_map[sk];
meshid = skin->base;
@@ -1453,7 +1452,7 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) {
//main anim
}
- Set<int> track_filter;
+ HashSet<int> track_filter;
if (p_clip == -1) {
for (int i = 0; i < collada.state.animation_clips.size(); i++) {
@@ -1508,14 +1507,14 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) {
bool tracks_found = false;
- for (Set<String>::Element *E = valid_animated_nodes.front(); E; E = E->next()) {
+ for (const String &E : valid_animated_nodes) {
// take snapshots
- if (!collada.state.scene_map.has(E->get())) {
+ if (!collada.state.scene_map.has(E)) {
continue;
}
- NodeMap &nm = node_map[E->get()];
+ NodeMap &nm = node_map[E];
String path = scene->get_path_to(nm.node);
if (nm.bone >= 0) {
@@ -1526,7 +1525,7 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) {
bool found_anim = false;
- Collada::Node *cn = collada.state.scene_map[E->get()];
+ Collada::Node *cn = collada.state.scene_map[E];
if (cn->ignore_anim) {
continue;
}
@@ -1666,7 +1665,7 @@ void ColladaImport::create_animation(int p_clip, bool p_import_value_tracks) {
if (nm.bone >= 0) {
if (found_anim) {
- bones_with_animation[E->get()] = true;
+ bones_with_animation[E] = true;
}
}
@@ -1755,7 +1754,7 @@ void EditorSceneFormatImporterCollada::get_extensions(List<String> *r_extensions
r_extensions->push_back("dae");
}
-Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
+Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
if (r_err) {
*r_err = OK;
}
@@ -1802,7 +1801,14 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3
name = state.animations[i]->get_name();
}
- ap->add_animation(name, state.animations[i]);
+ Ref<AnimationLibrary> library;
+ if (!ap->has_animation_library("")) {
+ library.instantiate();
+ ap->add_animation_library("", library);
+ } else {
+ library = ap->get_animation_library("");
+ }
+ library->add_animation(name, state.animations[i]);
}
state.scene->add_child(ap, true);
ap->set_owner(state.scene);
@@ -1811,26 +1817,5 @@ Node *EditorSceneFormatImporterCollada::import_scene(const String &p_path, uint3
return state.scene;
}
-Ref<Animation> EditorSceneFormatImporterCollada::import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) {
- ColladaImport state;
-
- state.use_mesh_builtin_materials = false;
-
- Error err = state.load(p_path, Collada::IMPORT_FLAG_ANIMATION, p_flags & EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS);
- ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot load animation from file '" + p_path + "'.");
-
- state.create_animations(true);
- if (state.scene) {
- memdelete(state.scene);
- }
-
- if (state.animations.size() == 0) {
- return Ref<Animation>();
- }
- Ref<Animation> anim = state.animations[0];
-
- return anim;
-}
-
EditorSceneFormatImporterCollada::EditorSceneFormatImporterCollada() {
}
diff --git a/editor/import/editor_import_collada.h b/editor/import/editor_import_collada.h
index c32d785d1c..e45db47440 100644
--- a/editor/import/editor_import_collada.h
+++ b/editor/import/editor_import_collada.h
@@ -39,8 +39,7 @@ class EditorSceneFormatImporterCollada : public EditorSceneFormatImporter {
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
- virtual Node *import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr) override;
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) override;
+ virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps = nullptr, Error *r_err = nullptr) override;
EditorSceneFormatImporterCollada();
};
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
index f7d373ef60..e822b4963a 100644
--- a/editor/import/editor_import_plugin.cpp
+++ b/editor/import/editor_import_plugin.cpp
@@ -147,12 +147,12 @@ void EditorImportPlugin::get_import_options(const String &p_path, List<ResourceI
ERR_FAIL_MSG("Unimplemented _get_import_options in add-on.");
}
-bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool EditorImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
Dictionary d;
- Map<StringName, Variant>::Element *E = p_options.front();
+ HashMap<StringName, Variant>::ConstIterator E = p_options.begin();
while (E) {
- d[E->key()] = E->get();
- E = E->next();
+ d[E->key] = E->value;
+ ++E;
}
bool visible;
if (GDVIRTUAL_CALL(_get_option_visibility, p_path, p_option, d, visible)) {
@@ -162,14 +162,14 @@ bool EditorImportPlugin::get_option_visibility(const String &p_path, const Strin
ERR_FAIL_V_MSG(false, "Unimplemented _get_option_visibility in add-on.");
}
-Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error EditorImportPlugin::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) {
Dictionary options;
Array platform_variants, gen_files;
- Map<StringName, Variant>::Element *E = p_options.front();
+ HashMap<StringName, Variant>::ConstIterator E = p_options.begin();
while (E) {
- options[E->key()] = E->get();
- E = E->next();
+ options[E->key] = E->value;
+ ++E;
}
int err;
diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h
index 6cff8fb917..44fbd41962 100644
--- a/editor/import/editor_import_plugin.h
+++ b/editor/import/editor_import_plugin.h
@@ -64,8 +64,8 @@ public:
virtual float get_priority() const override;
virtual int get_import_order() const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata = nullptr) override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
+ 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, Variant *r_metadata = nullptr) override;
};
#endif //EDITOR_IMPORT_PLUGIN_H
diff --git a/editor/import/resource_importer_bitmask.cpp b/editor/import/resource_importer_bitmask.cpp
index 46d15e8989..966719dc48 100644
--- a/editor/import/resource_importer_bitmask.cpp
+++ b/editor/import/resource_importer_bitmask.cpp
@@ -55,7 +55,7 @@ String ResourceImporterBitMap::get_resource_type() const {
return "BitMap";
}
-bool ResourceImporterBitMap::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterBitMap::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -72,7 +72,7 @@ void ResourceImporterBitMap::get_import_options(const String &p_path, List<Impor
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "threshold", PROPERTY_HINT_RANGE, "0,1,0.01"), 0.5));
}
-Error ResourceImporterBitMap::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterBitMap::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) {
int create_from = p_options["create_from"];
float threshold = p_options["threshold"];
Ref<Image> image;
diff --git a/editor/import/resource_importer_bitmask.h b/editor/import/resource_importer_bitmask.h
index 6dd6843171..8682ab80a3 100644
--- a/editor/import/resource_importer_bitmask.h
+++ b/editor/import/resource_importer_bitmask.h
@@ -47,8 +47,8 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
+ 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;
ResourceImporterBitMap();
~ResourceImporterBitMap();
diff --git a/editor/import/resource_importer_bmfont.cpp b/editor/import/resource_importer_bmfont.cpp
index 8a655fbc0c..8a40b113b9 100644
--- a/editor/import/resource_importer_bmfont.cpp
+++ b/editor/import/resource_importer_bmfont.cpp
@@ -55,7 +55,7 @@ String ResourceImporterBMFont::get_resource_type() const {
return "FontData";
}
-bool ResourceImporterBMFont::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterBMFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -63,7 +63,7 @@ void ResourceImporterBMFont::get_import_options(const String &p_path, List<Impor
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true));
}
-Error ResourceImporterBMFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+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;
diff --git a/editor/import/resource_importer_bmfont.h b/editor/import/resource_importer_bmfont.h
index e5a96e2c40..0711302bd5 100644
--- a/editor/import/resource_importer_bmfont.h
+++ b/editor/import/resource_importer_bmfont.h
@@ -46,9 +46,9 @@ public:
virtual String get_resource_type() const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterBMFont();
};
diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp
index f0ee14bdcb..0b3622e3c0 100644
--- a/editor/import/resource_importer_csv_translation.cpp
+++ b/editor/import/resource_importer_csv_translation.cpp
@@ -55,7 +55,7 @@ String ResourceImporterCSVTranslation::get_resource_type() const {
return "Translation";
}
-bool ResourceImporterCSVTranslation::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterCSVTranslation::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -72,7 +72,7 @@ void ResourceImporterCSVTranslation::get_import_options(const String &p_path, Li
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "delimiter", PROPERTY_HINT_ENUM, "Comma,Semicolon,Tab"), 0));
}
-Error ResourceImporterCSVTranslation::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterCSVTranslation::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) {
bool compress = p_options["compress"];
String delimiter;
@@ -88,9 +88,8 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const
break;
}
- FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ);
-
- ERR_FAIL_COND_V_MSG(!f, ERR_INVALID_PARAMETER, "Cannot open file from path '" + p_source_file + "'.");
+ Ref<FileAccess> f = FileAccess::open(p_source_file, FileAccess::READ);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_INVALID_PARAMETER, "Cannot open file from path '" + p_source_file + "'.");
Vector<String> line = f->get_csv_line(delimiter);
ERR_FAIL_COND_V(line.size() <= 1, ERR_PARSE_ERROR);
diff --git a/editor/import/resource_importer_csv_translation.h b/editor/import/resource_importer_csv_translation.h
index 8f6cf94984..306aafa843 100644
--- a/editor/import/resource_importer_csv_translation.h
+++ b/editor/import/resource_importer_csv_translation.h
@@ -47,9 +47,9 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterCSVTranslation();
};
diff --git a/editor/import/resource_importer_dynamic_font.cpp b/editor/import/resource_importer_dynamic_font.cpp
index 70fc87ea3f..a92b0fe280 100644
--- a/editor/import/resource_importer_dynamic_font.cpp
+++ b/editor/import/resource_importer_dynamic_font.cpp
@@ -50,9 +50,11 @@ 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("woff2");
p_extensions->push_back("pfb");
p_extensions->push_back("pfm");
#endif
@@ -67,7 +69,7 @@ String ResourceImporterDynamicFont::get_resource_type() const {
return "FontData";
}
-bool ResourceImporterDynamicFont::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterDynamicFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
if (p_option == "msdf_pixel_range" && !bool(p_options["multichannel_signed_distance_field"])) {
return false;
}
@@ -101,7 +103,10 @@ 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::INT, "face_index"), 0));
+
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));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
@@ -109,6 +114,8 @@ 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));
@@ -173,10 +180,13 @@ void ResourceImporterDynamicFont::show_advanced_options(const String &p_path) {
DynamicFontImportSettings::get_singleton()->open_settings(p_path);
}
-Error ResourceImporterDynamicFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterDynamicFont::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 dynamic font from: " + p_source_file);
+ int face_index = p_options["face_index"];
+
bool antialiased = p_options["antialiased"];
+ bool generate_mipmaps = p_options["generate_mipmaps"];
bool msdf = p_options["multichannel_signed_distance_field"];
int px_range = p_options["msdf_pixel_range"];
int px_size = p_options["msdf_size"];
@@ -186,6 +196,8 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
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"];
// Load base font data.
Vector<uint8_t> data = FileAccess::get_file_as_array(p_source_file);
@@ -194,7 +206,9 @@ Error ResourceImporterDynamicFont::import(const String &p_source_file, const Str
Ref<FontData> font;
font.instantiate();
font->set_data(data);
+ font->set_face_index(face_index);
font->set_antialiased(antialiased);
+ font->set_generate_mipmaps(generate_mipmaps);
font->set_multichannel_signed_distance_field(msdf);
font->set_msdf_pixel_range(px_range);
font->set_msdf_size(px_size);
@@ -202,6 +216,8 @@ 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);
diff --git a/editor/import/resource_importer_dynamic_font.h b/editor/import/resource_importer_dynamic_font.h
index 2761b418e1..c0b6c094b0 100644
--- a/editor/import/resource_importer_dynamic_font.h
+++ b/editor/import/resource_importer_dynamic_font.h
@@ -56,12 +56,12 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
bool has_advanced_options() const override;
void show_advanced_options(const String &p_path) override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterDynamicFont();
};
diff --git a/editor/import/resource_importer_image.cpp b/editor/import/resource_importer_image.cpp
index e6a822d827..fa7c4cd24f 100644
--- a/editor/import/resource_importer_image.cpp
+++ b/editor/import/resource_importer_image.cpp
@@ -55,7 +55,7 @@ String ResourceImporterImage::get_resource_type() const {
return "Image";
}
-bool ResourceImporterImage::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterImage::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -70,11 +70,10 @@ String ResourceImporterImage::get_preset_name(int p_idx) const {
void ResourceImporterImage::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
}
-Error ResourceImporterImage::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
- FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ);
-
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'.");
+Error ResourceImporterImage::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) {
+ Ref<FileAccess> f = FileAccess::open(p_source_file, FileAccess::READ);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_OPEN, "Cannot open file from path '" + p_source_file + "'.");
uint64_t len = f->get_length();
Vector<uint8_t> data;
@@ -82,10 +81,8 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p
f->get_buffer(data.ptrw(), len);
- memdelete(f);
-
f = FileAccess::open(p_save_path + ".image", FileAccess::WRITE);
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_CREATE, "Cannot create file in path '" + p_save_path + ".image'.");
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_CREATE, "Cannot create file in path '" + p_save_path + ".image'.");
//save the header GDIM
const uint8_t header[4] = { 'G', 'D', 'I', 'M' };
@@ -95,8 +92,6 @@ Error ResourceImporterImage::import(const String &p_source_file, const String &p
//SAVE the actual image
f->store_buffer(data.ptr(), len);
- memdelete(f);
-
return OK;
}
diff --git a/editor/import/resource_importer_image.h b/editor/import/resource_importer_image.h
index 81aedc91e8..a1a345287e 100644
--- a/editor/import/resource_importer_image.h
+++ b/editor/import/resource_importer_image.h
@@ -48,9 +48,9 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterImage();
};
diff --git a/editor/import/resource_importer_imagefont.cpp b/editor/import/resource_importer_imagefont.cpp
index 1338cf03a8..30c349d0f2 100644
--- a/editor/import/resource_importer_imagefont.cpp
+++ b/editor/import/resource_importer_imagefont.cpp
@@ -55,7 +55,7 @@ String ResourceImporterImageFont::get_resource_type() const {
return "FontData";
}
-bool ResourceImporterImageFont::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterImageFont::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -85,7 +85,7 @@ bool ResourceImporterImageFont::_decode_range(const String &p_token, int32_t &r_
}
}
-Error ResourceImporterImageFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterImageFont::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 image font from: " + p_source_file);
int columns = p_options["columns"];
@@ -96,6 +96,7 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
Ref<FontData> font;
font.instantiate();
font->set_antialiased(false);
+ font->set_generate_mipmaps(false);
font->set_multichannel_signed_distance_field(false);
font->set_fixed_size(base_size);
font->set_subpixel_positioning(TextServer::SUBPIXEL_POSITIONING_DISABLED);
@@ -106,7 +107,7 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
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;
diff --git a/editor/import/resource_importer_imagefont.h b/editor/import/resource_importer_imagefont.h
index c1116d5a83..f46bc8c19b 100644
--- a/editor/import/resource_importer_imagefont.h
+++ b/editor/import/resource_importer_imagefont.h
@@ -48,9 +48,9 @@ public:
virtual String get_resource_type() const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterImageFont();
};
diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp
index 7071042818..bacd09592e 100644
--- a/editor/import/resource_importer_layered_texture.cpp
+++ b/editor/import/resource_importer_layered_texture.cpp
@@ -85,16 +85,16 @@ void ResourceImporterLayeredTexture::get_recognized_extensions(List<String> *p_e
String ResourceImporterLayeredTexture::get_save_extension() const {
switch (mode) {
case MODE_CUBEMAP: {
- return "scube";
+ return "ccube";
} break;
case MODE_2D_ARRAY: {
- return "stexarray";
+ return "ctexarray";
} break;
case MODE_CUBEMAP_ARRAY: {
- return "scubearray";
+ return "ccubearray";
} break;
case MODE_3D: {
- return "stex3d";
+ return "ctex3d";
} break;
}
@@ -104,22 +104,22 @@ String ResourceImporterLayeredTexture::get_save_extension() const {
String ResourceImporterLayeredTexture::get_resource_type() const {
switch (mode) {
case MODE_CUBEMAP: {
- return "StreamCubemap";
+ return "CompressedCubemap";
} break;
case MODE_2D_ARRAY: {
- return "StreamTexture2DArray";
+ return "CompressedTexture2DArray";
} break;
case MODE_CUBEMAP_ARRAY: {
- return "StreamCubemapArray";
+ return "CompressedCubemapArray";
} break;
case MODE_3D: {
- return "StreamTexture3D";
+ return "CompressedTexture3D";
} break;
}
ERR_FAIL_V(String());
}
-bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterLayeredTexture::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
if (p_option == "compress/lossy_quality" && p_options.has("compress/mode")) {
return int(p_options["compress/mode"]) == COMPRESS_LOSSY;
}
@@ -257,13 +257,13 @@ void ResourceImporterLayeredTexture::_save_tex(Vector<Ref<Image>> p_images, cons
}
}
- FileAccessRef f = FileAccess::open(p_to_path, FileAccess::WRITE);
+ Ref<FileAccess> f = FileAccess::open(p_to_path, FileAccess::WRITE);
f->store_8('G');
f->store_8('S');
f->store_8('T');
f->store_8('L');
- f->store_32(StreamTextureLayered::FORMAT_VERSION);
+ f->store_32(CompressedTextureLayered::FORMAT_VERSION);
f->store_32(p_images.size()); // For 2d layers or 3d depth.
f->store_32(mode);
f->store_32(0);
@@ -274,17 +274,15 @@ void ResourceImporterLayeredTexture::_save_tex(Vector<Ref<Image>> p_images, cons
f->store_32(0);
for (int i = 0; i < p_images.size(); i++) {
- ResourceImporterTexture::save_to_stex_format(f, p_images[i], ResourceImporterTexture::CompressMode(p_compress_mode), used_channels, p_vram_compression, p_lossy);
+ ResourceImporterTexture::save_to_ctex_format(f, p_images[i], ResourceImporterTexture::CompressMode(p_compress_mode), used_channels, p_vram_compression, p_lossy);
}
for (int i = 0; i < mipmap_images.size(); i++) {
- ResourceImporterTexture::save_to_stex_format(f, mipmap_images[i], ResourceImporterTexture::CompressMode(p_compress_mode), used_channels, p_vram_compression, p_lossy);
+ ResourceImporterTexture::save_to_ctex_format(f, mipmap_images[i], ResourceImporterTexture::CompressMode(p_compress_mode), used_channels, p_vram_compression, p_lossy);
}
-
- f->close();
}
-Error ResourceImporterLayeredTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterLayeredTexture::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) {
int compress_mode = p_options["compress/mode"];
float lossy = p_options["compress/lossy_quality"];
int hdr_compression = p_options["compress/hdr_compression"];
@@ -393,7 +391,7 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const
texture_import->bptc_ldr = bptc_ldr;
texture_import->mipmaps = mipmaps;
texture_import->used_channels = used_channels;
- _check_compress_stex(texture_import);
+ _check_compress_ctex(texture_import);
if (r_metadata) {
Dictionary metadata;
metadata["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED;
@@ -474,7 +472,7 @@ ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() {
ResourceImporterLayeredTexture::~ResourceImporterLayeredTexture() {
}
-void ResourceImporterLayeredTexture::_check_compress_stex(Ref<LayeredTextureImport> r_texture_import) {
+void ResourceImporterLayeredTexture::_check_compress_ctex(Ref<LayeredTextureImport> r_texture_import) {
String extension = get_save_extension();
ERR_FAIL_NULL(r_texture_import->csource);
if (r_texture_import->compress_mode != COMPRESS_VRAM_COMPRESSED) {
@@ -544,5 +542,5 @@ void ResourceImporterLayeredTexture::_check_compress_stex(Ref<LayeredTextureImpo
}
return;
}
- EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC.");
+ EditorNode::add_io_error(TTR("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC."));
}
diff --git a/editor/import/resource_importer_layered_texture.h b/editor/import/resource_importer_layered_texture.h
index edd981c63d..5a29010c3b 100644
--- a/editor/import/resource_importer_layered_texture.h
+++ b/editor/import/resource_importer_layered_texture.h
@@ -35,7 +35,7 @@
#include "core/io/resource_importer.h"
#include "core/object/ref_counted.h"
-class StreamTexture2D;
+class CompressedTexture2D;
class LayeredTextureImport : public RefCounted {
GDCLASS(LayeredTextureImport, RefCounted);
@@ -43,7 +43,7 @@ class LayeredTextureImport : public RefCounted {
public:
Image::CompressSource *csource = nullptr;
String save_path;
- Map<StringName, Variant> options;
+ HashMap<StringName, Variant> options;
List<String> *platform_variants = nullptr;
Ref<Image> image = nullptr;
Array formats_imported;
@@ -87,7 +87,7 @@ protected:
static ResourceImporterLayeredTexture *singleton;
public:
- void _check_compress_stex(Ref<LayeredTextureImport> r_texture_import);
+ void _check_compress_ctex(Ref<LayeredTextureImport> r_texture_import);
static ResourceImporterLayeredTexture *get_singleton() { return singleton; }
virtual String get_importer_name() const override;
@@ -108,11 +108,11 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
void _save_tex(Vector<Ref<Image>> p_images, const String &p_to_path, int p_compress_mode, float p_lossy, Image::CompressMode p_vram_compression, Image::CompressSource p_csource, Image::UsedChannels used_channels, bool p_mipmaps, bool p_force_po2);
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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 are_import_settings_valid(const String &p_path) const override;
virtual String get_import_settings_string() const override;
diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp
index 9042f1e32c..6fbfecfdfa 100644
--- a/editor/import/resource_importer_obj.cpp
+++ b/editor/import/resource_importer_obj.cpp
@@ -43,9 +43,9 @@ uint32_t EditorOBJImporter::get_import_flags() const {
return IMPORT_SCENE;
}
-static Error _parse_material_library(const String &p_path, Map<String, Ref<StandardMaterial3D>> &material_map, List<String> *r_missing_deps) {
- FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path));
+static Error _parse_material_library(const String &p_path, HashMap<String, Ref<StandardMaterial3D>> &material_map, List<String> *r_missing_deps) {
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_OPEN, vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path));
Ref<StandardMaterial3D> current;
String current_name;
@@ -203,8 +203,8 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Stand
}
static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_single_mesh, bool p_generate_tangents, bool p_optimize, Vector3 p_scale_mesh, Vector3 p_offset_mesh, List<String> *r_missing_deps) {
- FileAccessRef f = FileAccess::open(p_path, FileAccess::READ);
- ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path));
+ Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
+ ERR_FAIL_COND_V_MSG(f.is_null(), ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path));
Ref<ArrayMesh> mesh;
mesh.instantiate();
@@ -219,7 +219,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
Vector<Vector2> uvs;
String name;
- Map<String, Map<String, Ref<StandardMaterial3D>>> material_map;
+ HashMap<String, HashMap<String, Ref<StandardMaterial3D>>> material_map;
Ref<SurfaceTool> surf_tool = memnew(SurfaceTool);
surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
@@ -402,7 +402,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
current_material_library = l.replace("mtllib", "").strip_edges();
if (!material_map.has(current_material_library)) {
- Map<String, Ref<StandardMaterial3D>> lib;
+ HashMap<String, Ref<StandardMaterial3D>> lib;
String lib_path = current_material_library;
if (lib_path.is_relative_path()) {
lib_path = p_path.get_base_dir().plus_file(current_material_library);
@@ -422,7 +422,7 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
return OK;
}
-Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
+Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
List<Ref<Mesh>> meshes;
Error err = _parse_obj(p_path, meshes, false, p_flags & IMPORT_GENERATE_TANGENT_ARRAYS, false, Vector3(1, 1, 1), Vector3(0, 0, 0), r_missing_deps);
@@ -457,10 +457,6 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, co
return scene;
}
-Ref<Animation> EditorOBJImporter::import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) {
- return Ref<Animation>();
-}
-
void EditorOBJImporter::get_extensions(List<String> *r_extensions) const {
r_extensions->push_back("obj");
}
@@ -509,11 +505,11 @@ void ResourceImporterOBJ::get_import_options(const String &p_path, List<ImportOp
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "optimize_mesh"), true));
}
-bool ResourceImporterOBJ::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterOBJ::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
-Error ResourceImporterOBJ::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterOBJ::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) {
List<Ref<Mesh>> meshes;
Error err = _parse_obj(p_source_file, meshes, true, p_options["generate_tangents"], p_options["optimize_mesh"], p_options["scale_mesh"], p_options["offset_mesh"], nullptr);
diff --git a/editor/import/resource_importer_obj.h b/editor/import/resource_importer_obj.h
index d7e3f0209d..3da9f02adb 100644
--- a/editor/import/resource_importer_obj.h
+++ b/editor/import/resource_importer_obj.h
@@ -39,8 +39,7 @@ class EditorOBJImporter : public EditorSceneFormatImporter {
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
- virtual Node *import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override;
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) override;
+ virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override;
EditorOBJImporter();
};
@@ -60,9 +59,9 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
// Threaded import can currently cause deadlocks, see GH-48265.
virtual bool can_import_threaded() const override { return false; }
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index e7c605aaf0..f2975b1d7a 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -74,7 +74,7 @@ void EditorSceneFormatImporter::get_extensions(List<String> *r_extensions) const
ERR_FAIL();
}
-Node *EditorSceneFormatImporter::import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
+Node *EditorSceneFormatImporter::import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
Dictionary options_dict;
for (const KeyValue<StringName, Variant> &elem : p_options) {
options_dict[elem.key] = elem.value;
@@ -87,26 +87,13 @@ Node *EditorSceneFormatImporter::import_scene(const String &p_path, uint32_t p_f
ERR_FAIL_V(nullptr);
}
-Ref<Animation> EditorSceneFormatImporter::import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) {
- Dictionary options_dict;
- for (const KeyValue<StringName, Variant> &elem : p_options) {
- options_dict[elem.key] = elem.value;
- }
- Ref<Animation> ret;
- if (GDVIRTUAL_CALL(_import_animation, p_path, p_flags, options_dict, p_bake_fps, ret)) {
- return ret;
- }
-
- ERR_FAIL_V(nullptr);
-}
-
void EditorSceneFormatImporter::get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options) {
GDVIRTUAL_CALL(_get_import_options, p_path);
}
-Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) {
+Variant EditorSceneFormatImporter::get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options) {
Variant ret;
- GDVIRTUAL_CALL(_get_option_visibility, p_path, p_option, ret);
+ GDVIRTUAL_CALL(_get_option_visibility, p_path, p_for_animation, p_option, ret);
return ret;
}
@@ -114,15 +101,15 @@ void EditorSceneFormatImporter::_bind_methods() {
GDVIRTUAL_BIND(_get_import_flags);
GDVIRTUAL_BIND(_get_extensions);
GDVIRTUAL_BIND(_import_scene, "path", "flags", "options", "bake_fps");
- GDVIRTUAL_BIND(_import_animation, "path", "flags", "options", "bake_fps");
GDVIRTUAL_BIND(_get_import_options, "path");
- GDVIRTUAL_BIND(_get_option_visibility, "path", "option");
+ GDVIRTUAL_BIND(_get_option_visibility, "path", "for_animation", "option");
BIND_CONSTANT(IMPORT_SCENE);
BIND_CONSTANT(IMPORT_ANIMATION);
BIND_CONSTANT(IMPORT_FAIL_ON_MISSING_DEPENDENCIES);
BIND_CONSTANT(IMPORT_GENERATE_TANGENT_ARRAYS);
BIND_CONSTANT(IMPORT_USE_NAMED_SKIN_BINDS);
+ BIND_CONSTANT(IMPORT_DISCARD_MESHES_AND_MATERIALS);
}
/////////////////////////////////
@@ -179,14 +166,14 @@ void EditorScenePostImportPlugin::get_internal_import_options(InternalImportCate
GDVIRTUAL_CALL(_get_internal_import_options, p_category);
current_option_list = nullptr;
}
-Variant EditorScenePostImportPlugin::get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const {
+Variant EditorScenePostImportPlugin::get_internal_option_visibility(InternalImportCategory p_category, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
current_options = &p_options;
Variant ret;
- GDVIRTUAL_CALL(_get_internal_option_visibility, p_category, p_option, ret);
+ GDVIRTUAL_CALL(_get_internal_option_visibility, p_category, p_for_animation, p_option, ret);
current_options = nullptr;
return ret;
}
-Variant EditorScenePostImportPlugin::get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const {
+Variant EditorScenePostImportPlugin::get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
current_options = &p_options;
Variant ret;
GDVIRTUAL_CALL(_get_internal_option_update_view_required, p_category, p_option, ret);
@@ -194,7 +181,7 @@ Variant EditorScenePostImportPlugin::get_internal_option_update_view_required(In
return ret;
}
-void EditorScenePostImportPlugin::internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, RES p_resource, const Dictionary &p_options) {
+void EditorScenePostImportPlugin::internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options) {
current_options_dict = &p_options;
GDVIRTUAL_CALL(_internal_process, p_category, p_base_scene, p_node, p_resource);
current_options_dict = nullptr;
@@ -205,20 +192,20 @@ void EditorScenePostImportPlugin::get_import_options(const String &p_path, List<
GDVIRTUAL_CALL(_get_import_options, p_path);
current_option_list = nullptr;
}
-Variant EditorScenePostImportPlugin::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+Variant EditorScenePostImportPlugin::get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
current_options = &p_options;
Variant ret;
- GDVIRTUAL_CALL(_get_option_visibility, p_path, p_option, ret);
+ GDVIRTUAL_CALL(_get_option_visibility, p_path, p_for_animation, p_option, ret);
current_options = nullptr;
return ret;
}
-void EditorScenePostImportPlugin::pre_process(Node *p_scene, const Map<StringName, Variant> &p_options) {
+void EditorScenePostImportPlugin::pre_process(Node *p_scene, const HashMap<StringName, Variant> &p_options) {
current_options = &p_options;
GDVIRTUAL_CALL(_pre_process, p_scene);
current_options = nullptr;
}
-void EditorScenePostImportPlugin::post_process(Node *p_scene, const Map<StringName, Variant> &p_options) {
+void EditorScenePostImportPlugin::post_process(Node *p_scene, const HashMap<StringName, Variant> &p_options) {
current_options = &p_options;
GDVIRTUAL_CALL(_post_process, p_scene);
current_options = nullptr;
@@ -231,11 +218,11 @@ void EditorScenePostImportPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_import_option_advanced", "type", "name", "default_value", "hint", "hint_string", "usage_flags"), &EditorScenePostImportPlugin::add_import_option_advanced, DEFVAL(PROPERTY_HINT_NONE), DEFVAL(""), DEFVAL(PROPERTY_USAGE_DEFAULT));
GDVIRTUAL_BIND(_get_internal_import_options, "category");
- GDVIRTUAL_BIND(_get_internal_option_visibility, "category", "option");
+ GDVIRTUAL_BIND(_get_internal_option_visibility, "category", "for_animation", "option");
GDVIRTUAL_BIND(_get_internal_option_update_view_required, "category", "option");
GDVIRTUAL_BIND(_internal_process, "category", "base_node", "node", "resource");
GDVIRTUAL_BIND(_get_import_options, "path");
- GDVIRTUAL_BIND(_get_option_visibility, "path", "option");
+ GDVIRTUAL_BIND(_get_option_visibility, "path", "for_animation", "option");
GDVIRTUAL_BIND(_pre_process, "scene");
GDVIRTUAL_BIND(_post_process, "scene");
@@ -251,11 +238,11 @@ void EditorScenePostImportPlugin::_bind_methods() {
/////////////////////////////////////////////////////////
String ResourceImporterScene::get_importer_name() const {
- return "scene";
+ return animation_importer ? "animation_library" : "scene";
}
String ResourceImporterScene::get_visible_name() const {
- return "Scene";
+ return animation_importer ? "Animation Library" : "Scene";
}
void ResourceImporterScene::get_recognized_extensions(List<String> *p_extensions) const {
@@ -265,38 +252,46 @@ void ResourceImporterScene::get_recognized_extensions(List<String> *p_extensions
}
String ResourceImporterScene::get_save_extension() const {
- return "scn";
+ return animation_importer ? "res" : "scn";
}
String ResourceImporterScene::get_resource_type() const {
- return "PackedScene";
+ return animation_importer ? "AnimationLibrary" : "PackedScene";
}
int ResourceImporterScene::get_format_version() const {
return 1;
}
-bool ResourceImporterScene::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
- if (p_option.begins_with("animation/")) {
+bool ResourceImporterScene::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
+ if (animation_importer) {
+ if (p_option == "animation/import") { // Option ignored, animation always imported.
+ return false;
+ }
+ } else if (p_option.begins_with("animation/")) {
if (p_option != "animation/import" && !bool(p_options["animation/import"])) {
return false;
}
}
+ if (animation_importer && (p_option.begins_with("nodes/") || p_option.begins_with("meshes/") || p_option.begins_with("skins/"))) {
+ return false; // Nothing to do here for animations.
+ }
+
if (p_option == "meshes/lightmap_texel_size" && int(p_options["meshes/light_baking"]) != 2) {
// Only display the lightmap texel size import option when using the Static Lightmaps light baking mode.
return false;
}
for (int i = 0; i < post_importer_plugins.size(); i++) {
- Variant ret = post_importer_plugins.write[i]->get_option_visibility(p_path, p_option, p_options);
+ Variant ret = post_importer_plugins.write[i]->get_option_visibility(p_path, animation_importer, p_option, p_options);
if (ret.get_type() == Variant::BOOL) {
return ret;
}
}
for (Ref<EditorSceneFormatImporter> importer : importers) {
- Variant ret = importer->get_option_visibility(p_path, p_option, p_options);
+ Variant ret = importer->get_option_visibility(p_path, animation_importer, p_option, p_options);
if (ret.get_type() == Variant::BOOL) {
return ret;
}
@@ -372,7 +367,7 @@ static void _pre_gen_shape_list(Ref<ImporterMesh> &mesh, Vector<Ref<Shape3D>> &r
}
}
-Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &r_collision_map, Pair<PackedVector3Array, PackedInt32Array> *r_occluder_arrays, List<Pair<NodePath, Node *>> &r_node_renames) {
+Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &r_collision_map, Pair<PackedVector3Array, PackedInt32Array> *r_occluder_arrays, List<Pair<NodePath, Node *>> &r_node_renames) {
// Children first.
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *r = _pre_fix_node(p_node->get_child(i), p_root, r_collision_map, r_occluder_arrays, r_node_renames);
@@ -471,9 +466,11 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I
static const char *loop_strings[loop_string_count] = { "loop_mode", "loop", "cycle" };
for (int i = 0; i < loop_string_count; i++) {
if (_teststr(animname, loop_strings[i])) {
- anim->set_loop_mode(Animation::LoopMode::LOOP_LINEAR);
+ anim->set_loop_mode(Animation::LOOP_LINEAR);
animname = _fixstr(animname, loop_strings[i]);
- ap->rename_animation(E, animname);
+
+ Ref<AnimationLibrary> library = ap->get_animation_library(ap->find_animation_library(anim));
+ library->rename_animation(E, animname);
}
}
}
@@ -661,6 +658,44 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I
}
}
}
+ } 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
@@ -707,7 +742,7 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<I
return p_node;
}
-Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, Set<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps) {
+Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, HashSet<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps) {
// children first
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *r = _post_fix_node(p_node->get_child(i), p_root, collision_map, r_occluder_arrays, r_scanned_meshes, p_node_data, p_material_data, p_animation_data, p_animation_fps);
@@ -718,13 +753,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
bool isroot = p_node == p_root;
- String import_id;
-
- if (p_node->has_meta("import_id")) {
- import_id = p_node->get_meta("import_id");
- } else {
- import_id = "PATH:" + p_root->get_path_to(p_node);
- }
+ String import_id = p_node->get_meta("import_id", "PATH:" + p_root->get_path_to(p_node));
Dictionary node_settings;
if (p_node_data.has(import_id)) {
@@ -739,7 +768,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
{
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, RES(), node_settings);
+ post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_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;
}
@@ -749,7 +778,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
if (Object::cast_to<ImporterMeshInstance3D>(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_MESH_3D_NODE, p_root, p_node, RES(), node_settings);
+ post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_MESH_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;
}
@@ -766,12 +795,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
for (int i = 0; i < m->get_surface_count(); i++) {
Ref<Material> mat = m->get_surface_material(i);
if (mat.is_valid()) {
- String mat_id;
- if (mat->has_meta("import_id")) {
- mat_id = mat->get_meta("import_id");
- } else {
- mat_id = mat->get_name();
- }
+ String mat_id = mat->get_meta("import_id", mat->get_name());
if (!mat_id.is_empty() && p_material_data.has(mat_id)) {
Dictionary matdata = p_material_data[mat_id];
@@ -956,7 +980,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
}
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, RES(), node_settings);
+ post_importer_plugins.write[i]->internal_process(EditorScenePostImportPlugin::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, p_root, p_node, Ref<Resource>(), node_settings);
}
bool use_optimizer = node_settings["optimizer/enabled"];
@@ -1019,7 +1043,8 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map<Ref<
Ref<Animation> saved_anim = _save_animation_to_file(anim, save, path, keep_custom);
if (saved_anim != anim) {
- ap->add_animation(name, saved_anim); //replace
+ Ref<AnimationLibrary> al = ap->get_animation_library(ap->find_animation_library(anim));
+ al->add_animation(name, saved_anim); //replace
}
}
}
@@ -1109,6 +1134,7 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_
}
Ref<Animation> default_anim = anim->get_animation("default");
+ Ref<AnimationLibrary> al = anim->get_animation_library(anim->find_animation(default_anim));
for (int i = 0; i < p_clips.size(); i += 7) {
String name = p_clips[i];
@@ -1246,15 +1272,16 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_
new_anim->set_loop_mode(loop_mode);
new_anim->set_length(to - from);
- anim->add_animation(name, new_anim);
+
+ al->add_animation(name, new_anim);
Ref<Animation> saved_anim = _save_animation_to_file(new_anim, save_to_file, save_to_path, keep_current);
if (saved_anim != new_anim) {
- anim->add_animation(name, saved_anim);
+ al->add_animation(name, saved_anim);
}
}
- anim->remove_animation("default"); //remove default (no longer needed)
+ al->remove_animation("default"); // Remove default (no longer needed).
}
void ResourceImporterScene::_optimize_animations(AnimationPlayer *anim, float p_max_lin_error, float p_max_ang_error, float p_max_angle) {
@@ -1367,7 +1394,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
}
}
-bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
if (p_options.has("import/skip_import") && p_option != "import/skip_import" && bool(p_options["import/skip_import"])) {
return false; //if skip import
}
@@ -1477,7 +1504,7 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor
}
for (int i = 0; i < post_importer_plugins.size(); i++) {
- Variant ret = post_importer_plugins.write[i]->get_internal_option_visibility(EditorScenePostImportPlugin::InternalImportCategory(p_category), p_option, p_options);
+ Variant ret = post_importer_plugins.write[i]->get_internal_option_visibility(EditorScenePostImportPlugin::InternalImportCategory(p_category), animation_importer, p_option, p_options);
if (ret.get_type() == Variant::BOOL) {
return ret;
}
@@ -1486,7 +1513,7 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor
return true;
}
-bool ResourceImporterScene::get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterScene::get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
switch (p_category) {
case INTERNAL_IMPORT_CATEGORY_NODE: {
} break;
@@ -1542,7 +1569,7 @@ void ResourceImporterScene::get_import_options(const String &p_path, List<Import
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/generate_lods"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/create_shadow_meshes"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Static (VoxelGI/SDFGI),Static Lightmaps (VoxelGI/SDFGI/LightmapGI),Dynamic (VoxelGI only)", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 1));
- r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.2));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "skins/use_named_skins"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 30));
@@ -1591,13 +1618,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m
bool bake_lightmaps = p_light_bake_mode == LIGHT_BAKE_STATIC_LIGHTMAPS;
String save_to_file;
- String mesh_id;
-
- if (src_mesh_node->get_mesh()->has_meta("import_id")) {
- mesh_id = src_mesh_node->get_mesh()->get_meta("import_id");
- } else {
- mesh_id = src_mesh_node->get_mesh()->get_name();
- }
+ String mesh_id = src_mesh_node->get_mesh()->get_meta("import_id", src_mesh_node->get_mesh()->get_name());
if (!mesh_id.is_empty() && p_mesh_data.has(mesh_id)) {
Dictionary mesh_settings = p_mesh_data[mesh_id];
@@ -1754,7 +1775,7 @@ void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, Ani
p_player->get_animation_list(&anims);
Node *parent = p_player->get_parent();
ERR_FAIL_COND(parent == nullptr);
- OrderedHashMap<NodePath, uint32_t> used_tracks[TRACK_CHANNEL_MAX];
+ HashMap<NodePath, uint32_t> used_tracks[TRACK_CHANNEL_MAX];
bool tracks_to_add = false;
static const Animation::TrackType track_types[TRACK_CHANNEL_MAX] = { Animation::TYPE_POSITION_3D, Animation::TYPE_ROTATION_3D, Animation::TYPE_SCALE_3D, Animation::TYPE_BLEND_SHAPE };
for (const StringName &I : anims) {
@@ -1807,12 +1828,12 @@ void ResourceImporterScene::_optimize_track_usage(AnimationPlayer *p_player, Ani
used_tracks[j][path] = pass;
}
- for (OrderedHashMap<NodePath, uint32_t>::Element J = used_tracks[j].front(); J; J = J.next()) {
- if (J.get() == pass) {
+ for (const KeyValue<NodePath, uint32_t> &J : used_tracks[j]) {
+ if (J.value == pass) {
continue;
}
- NodePath path = J.key();
+ NodePath path = J.key;
Node *n = parent->get_node(path);
if (j == TRACK_CHANNEL_BLEND_SHAPE) {
@@ -1926,19 +1947,19 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file) {
ERR_FAIL_COND_V(!importer.is_valid(), nullptr);
Error err = OK;
- Node *scene = importer->import_scene(p_source_file, EditorSceneFormatImporter::IMPORT_ANIMATION | EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, Map<StringName, Variant>(), 15, nullptr, &err);
+ Node *scene = importer->import_scene(p_source_file, EditorSceneFormatImporter::IMPORT_ANIMATION | EditorSceneFormatImporter::IMPORT_GENERATE_TANGENT_ARRAYS, HashMap<StringName, Variant>(), 15, nullptr, &err);
if (!scene || err != OK) {
return nullptr;
}
- Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
+ HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
List<Pair<NodePath, Node *>> node_renames;
_pre_fix_node(scene, scene, collision_map, nullptr, node_renames);
return scene;
}
-Error ResourceImporterScene::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterScene::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) {
const String &src_path = p_source_file;
Ref<EditorSceneFormatImporter> importer;
@@ -1969,8 +1990,13 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
int import_flags = 0;
- if (bool(p_options["animation/import"])) {
+ if (animation_importer) {
import_flags |= EditorSceneFormatImporter::IMPORT_ANIMATION;
+ import_flags |= EditorSceneFormatImporter::IMPORT_DISCARD_MESHES_AND_MATERIALS;
+ } else {
+ if (bool(p_options["animation/import"])) {
+ import_flags |= EditorSceneFormatImporter::IMPORT_ANIMATION;
+ }
}
if (bool(p_options["skins/use_named_skins"])) {
@@ -2006,8 +2032,8 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
animation_data = subresources["animations"];
}
- Set<Ref<ImporterMesh>> scanned_meshes;
- Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
+ HashSet<Ref<ImporterMesh>> scanned_meshes;
+ HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> collision_map;
Pair<PackedVector3Array, PackedInt32Array> occluder_arrays;
List<Pair<NodePath, Node *>> node_renames;
@@ -2086,14 +2112,13 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
_generate_meshes(scene, mesh_data, gen_lods, create_shadow_meshes, LightBakeMode(light_bake_mode), lightmap_texel_size, src_lightmap_cache, mesh_lightmap_caches);
if (mesh_lightmap_caches.size()) {
- FileAccessRef f = FileAccess::open(p_source_file + ".unwrap_cache", FileAccess::WRITE);
- if (f) {
+ Ref<FileAccess> f = FileAccess::open(p_source_file + ".unwrap_cache", FileAccess::WRITE);
+ if (f.is_valid()) {
f->store_32(mesh_lightmap_caches.size());
for (int i = 0; i < mesh_lightmap_caches.size(); i++) {
String md5 = String::md5(mesh_lightmap_caches[i].ptr());
f->store_buffer(mesh_lightmap_caches[i].ptr(), mesh_lightmap_caches[i].size());
}
- f->close();
}
}
err = OK;
@@ -2135,11 +2160,35 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
progress.step(TTR("Saving..."), 104);
- Ref<PackedScene> packer = memnew(PackedScene);
- packer->pack(scene);
- print_verbose("Saving scene to: " + p_save_path + ".scn");
- err = ResourceSaver::save(p_save_path + ".scn", packer); //do not take over, let the changed files reload themselves
- ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'.");
+ if (animation_importer) {
+ Ref<AnimationLibrary> library;
+ for (int i = 0; i < scene->get_child_count(); i++) {
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(scene->get_child(i));
+ if (ap) {
+ List<StringName> libs;
+ ap->get_animation_library_list(&libs);
+ if (libs.size()) {
+ library = ap->get_animation_library(libs.front()->get());
+ break;
+ }
+ }
+ }
+
+ if (!library.is_valid()) {
+ library.instantiate(); // Will be empty
+ }
+
+ print_verbose("Saving animation to: " + p_save_path + ".scn");
+ err = ResourceSaver::save(p_save_path + ".res", library); //do not take over, let the changed files reload themselves
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save animation to file '" + p_save_path + ".res'.");
+
+ } else {
+ Ref<PackedScene> packer = memnew(PackedScene);
+ packer->pack(scene);
+ print_verbose("Saving scene to: " + p_save_path + ".scn");
+ err = ResourceSaver::save(p_save_path + ".scn", packer); //do not take over, let the changed files reload themselves
+ ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save scene to file '" + p_save_path + ".scn'.");
+ }
memdelete(scene);
@@ -2149,17 +2198,26 @@ Error ResourceImporterScene::import(const String &p_source_file, const String &p
return OK;
}
-ResourceImporterScene *ResourceImporterScene::singleton = nullptr;
+ResourceImporterScene *ResourceImporterScene::scene_singleton = nullptr;
+ResourceImporterScene *ResourceImporterScene::animation_singleton = nullptr;
+
+Vector<Ref<EditorSceneFormatImporter>> ResourceImporterScene::importers;
+Vector<Ref<EditorScenePostImportPlugin>> ResourceImporterScene::post_importer_plugins;
bool ResourceImporterScene::ResourceImporterScene::has_advanced_options() const {
return true;
}
void ResourceImporterScene::ResourceImporterScene::show_advanced_options(const String &p_path) {
- SceneImportSettings::get_singleton()->open_settings(p_path);
+ SceneImportSettings::get_singleton()->open_settings(p_path, animation_importer);
}
-ResourceImporterScene::ResourceImporterScene() {
- singleton = this;
+ResourceImporterScene::ResourceImporterScene(bool p_animation_import) {
+ if (p_animation_import) {
+ animation_singleton = this;
+ } else {
+ scene_singleton = this;
+ }
+ animation_importer = p_animation_import;
}
void ResourceImporterScene::add_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority) {
@@ -2188,6 +2246,11 @@ void ResourceImporterScene::remove_importer(Ref<EditorSceneFormatImporter> p_imp
importers.erase(p_importer);
}
+void ResourceImporterScene::clean_up_importer_plugins() {
+ importers.clear();
+ post_importer_plugins.clear();
+}
+
///////////////////////////////////////
uint32_t EditorSceneFormatImporterESCN::get_import_flags() const {
@@ -2198,7 +2261,7 @@ void EditorSceneFormatImporterESCN::get_extensions(List<String> *r_extensions) c
r_extensions->push_back("escn");
}
-Node *EditorSceneFormatImporterESCN::import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
+Node *EditorSceneFormatImporterESCN::import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) {
Error error;
Ref<PackedScene> ps = ResourceFormatLoaderText::singleton->load(p_path, p_path, &error);
ERR_FAIL_COND_V_MSG(!ps.is_valid(), nullptr, "Cannot load scene as text resource from path '" + p_path + "'.");
@@ -2208,7 +2271,3 @@ Node *EditorSceneFormatImporterESCN::import_scene(const String &p_path, uint32_t
return scene;
}
-
-Ref<Animation> EditorSceneFormatImporterESCN::import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) {
- ERR_FAIL_V(Ref<Animation>());
-}
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index a819be682d..16cf3d651d 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -56,9 +56,8 @@ protected:
GDVIRTUAL0RC(int, _get_import_flags)
GDVIRTUAL0RC(Vector<String>, _get_extensions)
GDVIRTUAL4R(Object *, _import_scene, String, uint32_t, Dictionary, uint32_t)
- GDVIRTUAL4R(Ref<Animation>, _import_animation, String, uint32_t, Dictionary, uint32_t)
GDVIRTUAL1(_get_import_options, String)
- GDVIRTUAL2RC(Variant, _get_option_visibility, String, String)
+ GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String)
public:
enum ImportFlags {
@@ -67,14 +66,14 @@ public:
IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 4,
IMPORT_GENERATE_TANGENT_ARRAYS = 8,
IMPORT_USE_NAMED_SKIN_BINDS = 16,
+ IMPORT_DISCARD_MESHES_AND_MATERIALS = 32, //used for optimizing animation import
};
virtual uint32_t get_import_flags() const;
virtual void get_extensions(List<String> *r_extensions) const;
- virtual Node *import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr);
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps);
+ virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr);
virtual void get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options);
- virtual Variant get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options);
+ virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options);
EditorSceneFormatImporter() {}
};
@@ -111,18 +110,18 @@ public:
};
private:
- mutable const Map<StringName, Variant> *current_options = nullptr;
+ mutable const HashMap<StringName, Variant> *current_options = nullptr;
mutable const Dictionary *current_options_dict = nullptr;
List<ResourceImporter::ImportOption> *current_option_list = nullptr;
InternalImportCategory current_category = INTERNAL_IMPORT_CATEGORY_MAX;
protected:
GDVIRTUAL1(_get_internal_import_options, int)
- GDVIRTUAL2RC(Variant, _get_internal_option_visibility, int, String)
+ GDVIRTUAL3RC(Variant, _get_internal_option_visibility, int, bool, String)
GDVIRTUAL2RC(Variant, _get_internal_option_update_view_required, int, String)
- GDVIRTUAL4(_internal_process, int, Node *, Node *, RES)
+ GDVIRTUAL4(_internal_process, int, Node *, Node *, Ref<Resource>)
GDVIRTUAL1(_get_import_options, String)
- GDVIRTUAL2RC(Variant, _get_option_visibility, String, String)
+ GDVIRTUAL3RC(Variant, _get_option_visibility, String, bool, String)
GDVIRTUAL1(_pre_process, Node *)
GDVIRTUAL1(_post_process, Node *)
@@ -134,16 +133,16 @@ public:
void add_import_option_advanced(Variant::Type p_type, const String &p_name, Variant p_default_value, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = String(), int p_usage_flags = PROPERTY_USAGE_DEFAULT);
virtual void get_internal_import_options(InternalImportCategory p_category, List<ResourceImporter::ImportOption> *r_options);
- virtual Variant get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const;
- virtual Variant get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const;
+ virtual Variant get_internal_option_visibility(InternalImportCategory p_category, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options) const;
+ virtual Variant get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;
- virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, RES p_resource, const Dictionary &p_options);
+ virtual void internal_process(InternalImportCategory p_category, Node *p_base_scene, Node *p_node, Ref<Resource> p_resource, const Dictionary &p_options);
virtual void get_import_options(const String &p_path, List<ResourceImporter::ImportOption> *r_options);
- virtual Variant get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const;
+ virtual Variant get_option_visibility(const String &p_path, bool p_for_animation, const String &p_option, const HashMap<StringName, Variant> &p_options) const;
- virtual void pre_process(Node *p_scene, const Map<StringName, Variant> &p_options);
- virtual void post_process(Node *p_scene, const Map<StringName, Variant> &p_options);
+ virtual void pre_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);
+ virtual void post_process(Node *p_scene, const HashMap<StringName, Variant> &p_options);
EditorScenePostImportPlugin() {}
};
@@ -153,9 +152,11 @@ VARIANT_ENUM_CAST(EditorScenePostImportPlugin::InternalImportCategory)
class ResourceImporterScene : public ResourceImporter {
GDCLASS(ResourceImporterScene, ResourceImporter);
- Vector<Ref<EditorSceneFormatImporter>> importers;
+ static Vector<Ref<EditorSceneFormatImporter>> importers;
+ static Vector<Ref<EditorScenePostImportPlugin>> post_importer_plugins;
- static ResourceImporterScene *singleton;
+ static ResourceImporterScene *scene_singleton;
+ static ResourceImporterScene *animation_singleton;
enum LightBakeMode {
LIGHT_BAKE_DISABLED,
@@ -225,18 +226,21 @@ class ResourceImporterScene : public ResourceImporter {
void _optimize_track_usage(AnimationPlayer *p_player, AnimationImportTracks *p_track_actions);
- mutable Vector<Ref<EditorScenePostImportPlugin>> post_importer_plugins;
+ bool animation_importer = false;
public:
- static ResourceImporterScene *get_singleton() { return singleton; }
+ static ResourceImporterScene *get_scene_singleton() { return scene_singleton; }
+ static ResourceImporterScene *get_animation_singleton() { return animation_singleton; }
- void add_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority = false);
- void remove_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin);
+ static void add_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority = false);
+ static void remove_post_importer_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin);
const Vector<Ref<EditorSceneFormatImporter>> &get_importers() const { return importers; }
- void add_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority = false);
- void remove_importer(Ref<EditorSceneFormatImporter> p_importer);
+ static void add_importer(Ref<EditorSceneFormatImporter> p_importer, bool p_first_priority = false);
+ static void remove_importer(Ref<EditorSceneFormatImporter> p_importer);
+
+ static void clean_up_importer_plugins();
virtual String get_importer_name() const override;
virtual String get_visible_name() const override;
@@ -259,16 +263,16 @@ public:
};
void get_internal_import_options(InternalImportCategory p_category, List<ImportOption> *r_options) const;
- bool get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const;
- bool get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const Map<StringName, Variant> &p_options) const;
+ bool get_internal_option_visibility(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;
+ bool get_internal_option_update_view_required(InternalImportCategory p_category, const String &p_option, const HashMap<StringName, Variant> &p_options) const;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
// Import scenes *after* everything else (such as textures).
virtual int get_import_order() const override { return ResourceImporter::IMPORT_ORDER_SCENE; }
- Node *_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &r_collision_map, Pair<PackedVector3Array, PackedInt32Array> *r_occluder_arrays, List<Pair<NodePath, Node *>> &r_node_renames);
- Node *_post_fix_node(Node *p_node, Node *p_root, Map<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, Set<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps);
+ Node *_pre_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &r_collision_map, Pair<PackedVector3Array, PackedInt32Array> *r_occluder_arrays, List<Pair<NodePath, Node *>> &r_node_renames);
+ Node *_post_fix_node(Node *p_node, Node *p_root, HashMap<Ref<ImporterMesh>, Vector<Ref<Shape3D>>> &collision_map, Pair<PackedVector3Array, PackedInt32Array> &r_occluder_arrays, HashSet<Ref<ImporterMesh>> &r_scanned_meshes, const Dictionary &p_node_data, const Dictionary &p_material_data, const Dictionary &p_animation_data, float p_animation_fps);
Ref<Animation> _save_animation_to_file(Ref<Animation> anim, bool p_save_to_file, String p_save_to_path, bool p_keep_custom_tracks);
void _create_clips(AnimationPlayer *anim, const Array &p_clips, bool p_bake_all);
@@ -276,14 +280,14 @@ public:
void _compress_animations(AnimationPlayer *anim, int p_page_size_kb);
Node *pre_import(const String &p_source_file);
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
virtual void show_advanced_options(const String &p_path) override;
virtual bool can_import_threaded() const override { return false; }
- ResourceImporterScene();
+ ResourceImporterScene(bool p_animation_import = false);
template <class M>
static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<Mesh> &p_mesh, const M &p_options);
@@ -298,8 +302,7 @@ class EditorSceneFormatImporterESCN : public EditorSceneFormatImporter {
public:
virtual uint32_t get_import_flags() const override;
virtual void get_extensions(List<String> *r_extensions) const override;
- virtual Node *import_scene(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override;
- virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, const Map<StringName, Variant> &p_options, int p_bake_fps) override;
+ virtual Node *import_scene(const String &p_path, uint32_t p_flags, const HashMap<StringName, Variant> &p_options, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override;
};
#include "scene/resources/box_shape_3d.h"
diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp
index cc34259a2d..64839bf199 100644
--- a/editor/import/resource_importer_shader_file.cpp
+++ b/editor/import/resource_importer_shader_file.cpp
@@ -68,7 +68,7 @@ String ResourceImporterShaderFile::get_preset_name(int p_idx) const {
void ResourceImporterShaderFile::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
}
-bool ResourceImporterShaderFile::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterShaderFile::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -82,18 +82,18 @@ static String _include_function(const String &p_path, void *userpointer) {
include = base_path->plus_file(include);
}
- FileAccessRef file_inc = FileAccess::open(include, FileAccess::READ, &err);
+ Ref<FileAccess> file_inc = FileAccess::open(include, FileAccess::READ, &err);
if (err != OK) {
return String();
}
return file_inc->get_as_utf8_string();
}
-Error ResourceImporterShaderFile::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterShaderFile::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) {
/* STEP 1, Read shader code */
Error err;
- FileAccessRef file = FileAccess::open(p_source_file, FileAccess::READ, &err);
+ Ref<FileAccess> file = FileAccess::open(p_source_file, FileAccess::READ, &err);
ERR_FAIL_COND_V(err != OK, ERR_CANT_OPEN);
ERR_FAIL_COND_V(!file.operator->(), ERR_CANT_OPEN);
diff --git a/editor/import/resource_importer_shader_file.h b/editor/import/resource_importer_shader_file.h
index 858c2e783c..9d0ef88b05 100644
--- a/editor/import/resource_importer_shader_file.h
+++ b/editor/import/resource_importer_shader_file.h
@@ -47,9 +47,9 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterShaderFile();
};
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index 35a20e85c1..deb3047864 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -37,7 +37,7 @@
#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
-void ResourceImporterTexture::_texture_reimport_roughness(const Ref<StreamTexture2D> &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) {
+void ResourceImporterTexture::_texture_reimport_roughness(const Ref<CompressedTexture2D> &p_tex, const String &p_normal_path, RS::TextureDetectRoughnessChannel p_channel) {
ERR_FAIL_COND(p_tex.is_null());
MutexLock lock(singleton->mutex);
@@ -53,7 +53,7 @@ void ResourceImporterTexture::_texture_reimport_roughness(const Ref<StreamTextur
singleton->make_flags[path].normal_path_for_roughness = p_normal_path;
}
-void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture2D> &p_tex) {
+void ResourceImporterTexture::_texture_reimport_3d(const Ref<CompressedTexture2D> &p_tex) {
ERR_FAIL_COND(p_tex.is_null());
MutexLock lock(singleton->mutex);
@@ -67,7 +67,7 @@ void ResourceImporterTexture::_texture_reimport_3d(const Ref<StreamTexture2D> &p
singleton->make_flags[path].flags |= MAKE_3D_FLAG;
}
-void ResourceImporterTexture::_texture_reimport_normal(const Ref<StreamTexture2D> &p_tex) {
+void ResourceImporterTexture::_texture_reimport_normal(const Ref<CompressedTexture2D> &p_tex) {
ERR_FAIL_COND(p_tex.is_null());
MutexLock lock(singleton->mutex);
@@ -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;
}
@@ -153,14 +159,14 @@ void ResourceImporterTexture::get_recognized_extensions(List<String> *p_extensio
}
String ResourceImporterTexture::get_save_extension() const {
- return "stex";
+ return "ctex";
}
String ResourceImporterTexture::get_resource_type() const {
- return "StreamTexture2D";
+ return "CompressedTexture2D";
}
-bool ResourceImporterTexture::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterTexture::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
if (p_option == "compress/lossy_quality") {
int compress_mode = int(p_options["compress/mode"]);
if (compress_mode != COMPRESS_LOSSY && compress_mode != COMPRESS_VRAM_COMPRESSED) {
@@ -171,6 +177,11 @@ bool ResourceImporterTexture::get_option_visibility(const String &p_path, const
if (compress_mode < COMPRESS_VRAM_COMPRESSED) {
return false;
}
+ } else if (p_option == "compress/normal_map") {
+ int compress_mode = int(p_options["compress/mode"]);
+ if (compress_mode == COMPRESS_LOSSLESS) {
+ return false;
+ }
} else if (p_option == "mipmaps/limit") {
return p_options["mipmaps/generate"];
@@ -193,12 +204,12 @@ int ResourceImporterTexture::get_preset_count() const {
String ResourceImporterTexture::get_preset_name(int p_idx) const {
static const char *preset_names[] = {
- "2D/3D (Auto-Detect)",
- "2D",
- "3D",
+ TTRC("2D/3D (Auto-Detect)"),
+ TTRC("2D"),
+ TTRC("3D"),
};
- return preset_names[p_idx];
+ return TTRGET(preset_names[p_idx]);
}
void ResourceImporterTexture::get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const {
@@ -208,7 +219,6 @@ void ResourceImporterTexture::get_import_options(const String &p_path, List<Impo
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/bptc_ldr", PROPERTY_HINT_ENUM, "Disabled,Enabled,RGBA Only"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/normal_map", PROPERTY_HINT_ENUM, "Detect,Enable,Disabled"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/channel_pack", PROPERTY_HINT_ENUM, "sRGB Friendly,Optimized"), 0));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress/streamed"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "mipmaps/generate"), (p_preset == PRESET_3D ? true : false)));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "mipmaps/limit", PROPERTY_HINT_RANGE, "-1,256"), -1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "roughness/mode", PROPERTY_HINT_ENUM, "Detect,Disabled,Red,Green,Blue,Alpha,Gray"), 0));
@@ -217,6 +227,7 @@ void ResourceImporterTexture::get_import_options(const String &p_path, List<Impo
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/premult_alpha"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/normal_map_invert_y"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/hdr_as_srgb"), false));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "process/hdr_clamp_exposure"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "process/size_limit", PROPERTY_HINT_RANGE, "0,4096,1"), 0));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "detect_3d/compress_to", PROPERTY_HINT_ENUM, "Disabled,VRAM Compressed,Basis Universal"), (p_preset == PRESET_DETECT) ? 1 : 0));
@@ -225,13 +236,13 @@ void ResourceImporterTexture::get_import_options(const String &p_path, List<Impo
}
}
-void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality) {
+void ResourceImporterTexture::save_to_ctex_format(Ref<FileAccess> f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality) {
switch (p_compress_mode) {
case COMPRESS_LOSSLESS: {
bool lossless_force_png = ProjectSettings::get_singleton()->get("rendering/textures/lossless_compression/force_png") ||
!Image::_webp_mem_loader_func; // WebP module disabled.
bool use_webp = !lossless_force_png && p_image->get_width() <= 16383 && p_image->get_height() <= 16383; // WebP has a size limit
- f->store_32(use_webp ? StreamTexture2D::DATA_FORMAT_WEBP : StreamTexture2D::DATA_FORMAT_PNG);
+ f->store_32(use_webp ? CompressedTexture2D::DATA_FORMAT_WEBP : CompressedTexture2D::DATA_FORMAT_PNG);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
f->store_32(p_image->get_mipmap_count());
@@ -253,7 +264,7 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
} break;
case COMPRESS_LOSSY: {
- f->store_32(StreamTexture2D::DATA_FORMAT_WEBP);
+ f->store_32(CompressedTexture2D::DATA_FORMAT_WEBP);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
f->store_32(p_image->get_mipmap_count());
@@ -273,7 +284,7 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
image->compress_from_channels(p_compress_format, p_channels, p_lossy_quality);
- f->store_32(StreamTexture2D::DATA_FORMAT_IMAGE);
+ f->store_32(CompressedTexture2D::DATA_FORMAT_IMAGE);
f->store_16(image->get_width());
f->store_16(image->get_height());
f->store_32(image->get_mipmap_count());
@@ -285,7 +296,7 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
f->store_buffer(r, dl);
} break;
case COMPRESS_VRAM_UNCOMPRESSED: {
- f->store_32(StreamTexture2D::DATA_FORMAT_IMAGE);
+ f->store_32(CompressedTexture2D::DATA_FORMAT_IMAGE);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
f->store_32(p_image->get_mipmap_count());
@@ -299,7 +310,7 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
} break;
case COMPRESS_BASIS_UNIVERSAL: {
- f->store_32(StreamTexture2D::DATA_FORMAT_BASIS_UNIVERSAL);
+ f->store_32(CompressedTexture2D::DATA_FORMAT_BASIS_UNIVERSAL);
f->store_16(p_image->get_width());
f->store_16(p_image->get_height());
f->store_32(p_image->get_mipmap_count());
@@ -317,35 +328,35 @@ void ResourceImporterTexture::save_to_stex_format(FileAccess *f, const Ref<Image
}
}
-void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel) {
- FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
- ERR_FAIL_NULL(f);
+void ResourceImporterTexture::_save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_roughness, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel) {
+ Ref<FileAccess> f = FileAccess::open(p_to_path, FileAccess::WRITE);
+ ERR_FAIL_COND(f.is_null());
f->store_8('G');
f->store_8('S');
f->store_8('T');
f->store_8('2'); //godot streamable texture 2D
//format version
- f->store_32(StreamTexture2D::FORMAT_VERSION);
+ f->store_32(CompressedTexture2D::FORMAT_VERSION);
//texture may be resized later, so original size must be saved first
f->store_32(p_image->get_width());
f->store_32(p_image->get_height());
uint32_t flags = 0;
if (p_streamable) {
- flags |= StreamTexture2D::FORMAT_BIT_STREAM;
+ flags |= CompressedTexture2D::FORMAT_BIT_STREAM;
}
if (p_mipmaps) {
- flags |= StreamTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
+ flags |= CompressedTexture2D::FORMAT_BIT_HAS_MIPMAPS; //mipmaps bit
}
if (p_detect_3d) {
- flags |= StreamTexture2D::FORMAT_BIT_DETECT_3D;
+ flags |= CompressedTexture2D::FORMAT_BIT_DETECT_3D;
}
if (p_detect_roughness) {
- flags |= StreamTexture2D::FORMAT_BIT_DETECT_ROUGNESS;
+ flags |= CompressedTexture2D::FORMAT_BIT_DETECT_ROUGNESS;
}
if (p_detect_normal) {
- flags |= StreamTexture2D::FORMAT_BIT_DETECT_NORMAL;
+ flags |= CompressedTexture2D::FORMAT_BIT_DETECT_NORMAL;
}
f->store_32(flags);
@@ -394,12 +405,10 @@ void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String
Image::UsedChannels used_channels = image->detect_used_channels(csource);
- save_to_stex_format(f, image, p_compress_mode, used_channels, p_vram_compression, p_lossy_quality);
-
- memdelete(f);
+ save_to_ctex_format(f, image, p_compress_mode, used_channels, p_vram_compression, p_lossy_quality);
}
-Error ResourceImporterTexture::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterTexture::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) {
CompressMode compress_mode = CompressMode(int(p_options["compress/mode"]));
const float lossy = p_options["compress/lossy_quality"];
const int pack_channels = p_options["compress/channel_pack"];
@@ -408,9 +417,11 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
const bool fix_alpha_border = p_options["process/fix_alpha_border"];
const bool premult_alpha = p_options["process/premult_alpha"];
const bool normal_map_invert_y = p_options["process/normal_map_invert_y"];
- const bool stream = p_options["compress/streamed"];
+ // Support for texture streaming is not implemented yet.
+ const bool stream = false;
const int size_limit = p_options["process/size_limit"];
const bool hdr_as_srgb = p_options["process/hdr_as_srgb"];
+ const bool hdr_clamp_exposure = p_options["process/hdr_clamp_exposure"];
const int normal = p_options["compress/normal_map"];
const int hdr_compression = p_options["compress/hdr_compression"];
const int bptc_ldr = p_options["compress/bptc_ldr"];
@@ -482,6 +493,34 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
}
}
+ if (hdr_clamp_exposure) {
+ // Clamp HDR exposure following Filament's tonemapping formula.
+ // This can be used to reduce fireflies in environment maps or reduce the influence
+ // of the sun from an HDRI panorama on environment lighting (when a DirectionalLight3D is used instead).
+ const int height = image->get_height();
+ const int width = image->get_width();
+
+ // These values are chosen arbitrarily and seem to produce good results with 4,096 samples.
+ const float linear = 4096.0;
+ const float compressed = 16384.0;
+
+ for (int i = 0; i < width; i++) {
+ for (int j = 0; j < height; j++) {
+ const Color color = image->get_pixel(i, j);
+ const float luma = color.get_luminance();
+
+ Color clamped_color;
+ if (luma <= linear) {
+ clamped_color = color;
+ } else {
+ clamped_color = (color / luma) * ((linear * linear - compressed * luma) / (2 * linear - compressed - luma));
+ }
+
+ image->set_pixel(i, j, clamped_color);
+ }
+ }
+ }
+
if (compress_mode == COMPRESS_BASIS_UNIVERSAL && image->get_format() >= Image::FORMAT_RF) {
//basis universal does not support float formats, fall back
compress_mode = COMPRESS_VRAM_COMPRESSED;
@@ -540,29 +579,29 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
if (!bptc_ldr && can_s3tc && is_ldr) {
image_compress_mode = Image::COMPRESS_S3TC;
}
- _save_stex(image, p_save_path + ".s3tc.stex", compress_mode, lossy, image_compress_mode, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
+ _save_ctex(image, p_save_path + ".s3tc.ctex", compress_mode, lossy, image_compress_mode, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("s3tc");
formats_imported.push_back("s3tc");
}
if (ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc2")) {
- _save_stex(image, p_save_path + ".etc2.stex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
+ _save_ctex(image, p_save_path + ".etc2.ctex", compress_mode, lossy, Image::COMPRESS_ETC2, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("etc2");
formats_imported.push_back("etc2");
}
if (ProjectSettings::get_singleton()->get("rendering/textures/vram_compression/import_etc")) {
- _save_stex(image, p_save_path + ".etc.stex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
+ _save_ctex(image, p_save_path + ".etc.ctex", compress_mode, lossy, Image::COMPRESS_ETC, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, true, mipmap_limit, normal_image, roughness_channel);
r_platform_variants->push_back("etc");
formats_imported.push_back("etc");
}
if (!ok_on_pc) {
- EditorNode::add_io_error("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC.");
+ EditorNode::add_io_error(TTR("Warning, no suitable PC VRAM compression enabled in Project Settings. This texture will not display correctly on PC."));
}
} else {
//import normally
- _save_stex(image, p_save_path + ".stex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
+ _save_ctex(image, p_save_path + ".ctex", compress_mode, lossy, Image::COMPRESS_S3TC /*this is ignored */, mipmaps, stream, detect_3d, detect_roughness, detect_normal, force_normal, srgb_friendly_pack, false, mipmap_limit, normal_image, roughness_channel);
}
if (r_metadata) {
@@ -638,9 +677,9 @@ ResourceImporterTexture *ResourceImporterTexture::singleton = nullptr;
ResourceImporterTexture::ResourceImporterTexture() {
singleton = this;
- StreamTexture2D::request_3d_callback = _texture_reimport_3d;
- StreamTexture2D::request_roughness_callback = _texture_reimport_roughness;
- StreamTexture2D::request_normal_callback = _texture_reimport_normal;
+ CompressedTexture2D::request_3d_callback = _texture_reimport_3d;
+ CompressedTexture2D::request_roughness_callback = _texture_reimport_roughness;
+ CompressedTexture2D::request_normal_callback = _texture_reimport_normal;
}
ResourceImporterTexture::~ResourceImporterTexture() {
diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h
index ea2318fb33..7def2d4f77 100644
--- a/editor/import/resource_importer_texture.h
+++ b/editor/import/resource_importer_texture.h
@@ -37,7 +37,7 @@
#include "scene/resources/texture.h"
#include "servers/rendering_server.h"
-class StreamTexture2D;
+class CompressedTexture2D;
class ResourceImporterTexture : public ResourceImporter {
GDCLASS(ResourceImporterTexture, ResourceImporter);
@@ -65,19 +65,19 @@ protected:
RS::TextureDetectRoughnessChannel channel_for_roughness = RS::TEXTURE_DETECT_ROUGHNESS_R;
};
- Map<StringName, MakeInfo> make_flags;
+ HashMap<StringName, MakeInfo> make_flags;
- static void _texture_reimport_roughness(const Ref<StreamTexture2D> &p_tex, const String &p_normal_path, RenderingServer::TextureDetectRoughnessChannel p_channel);
- static void _texture_reimport_3d(const Ref<StreamTexture2D> &p_tex);
- static void _texture_reimport_normal(const Ref<StreamTexture2D> &p_tex);
+ static void _texture_reimport_roughness(const Ref<CompressedTexture2D> &p_tex, const String &p_normal_path, RenderingServer::TextureDetectRoughnessChannel p_channel);
+ static void _texture_reimport_3d(const Ref<CompressedTexture2D> &p_tex);
+ static void _texture_reimport_normal(const Ref<CompressedTexture2D> &p_tex);
static ResourceImporterTexture *singleton;
static const char *compression_formats[];
- void _save_stex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel);
+ void _save_ctex(const Ref<Image> &p_image, const String &p_to_path, CompressMode p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, bool p_streamable, bool p_detect_3d, bool p_detect_srgb, bool p_detect_normal, bool p_force_normal, bool p_srgb_friendly, bool p_force_po2_for_compressed, uint32_t p_limit_mipmap, const Ref<Image> &p_normal, Image::RoughnessChannel p_roughness_channel);
public:
- static void save_to_stex_format(FileAccess *f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality);
+ static void save_to_ctex_format(Ref<FileAccess> f, const Ref<Image> &p_image, CompressMode p_compress_mode, Image::UsedChannels p_channels, Image::CompressMode p_compress_format, float p_lossy_quality);
static ResourceImporterTexture *get_singleton() { return singleton; }
virtual String get_importer_name() const override;
@@ -96,9 +96,9 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
void update_imports();
diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp
index cd481e009e..aa338a6c0d 100644
--- a/editor/import/resource_importer_texture_atlas.cpp
+++ b/editor/import/resource_importer_texture_atlas.cpp
@@ -59,7 +59,7 @@ String ResourceImporterTextureAtlas::get_resource_type() const {
return "Texture2D";
}
-bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterTextureAtlas::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
return true;
}
@@ -82,7 +82,7 @@ String ResourceImporterTextureAtlas::get_option_group_file() const {
return "atlas_file";
}
-Error ResourceImporterTextureAtlas::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterTextureAtlas::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) {
/* If this happens, it's because the atlas_file field was not filled, so just import a broken texture */
//use an xpm because it's size independent, the editor images are vector and size dependent
@@ -188,7 +188,7 @@ static void _plot_triangle(Vector2i *vertices, const Vector2i &p_offset, bool p_
}
}
-Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant>> &p_source_file_options, const Map<String, String> &p_base_paths) {
+Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file, const HashMap<String, HashMap<StringName, Variant>> &p_source_file_options, const HashMap<String, String> &p_base_paths) {
ERR_FAIL_COND_V(p_source_file_options.size() == 0, ERR_BUG); //should never happen
Vector<EditorAtlasPacker::Chart> charts;
@@ -197,10 +197,10 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
pack_data_files.resize(p_source_file_options.size());
int idx = 0;
- for (const Map<String, Map<StringName, Variant>>::Element *E = p_source_file_options.front(); E; E = E->next(), idx++) {
+ for (const KeyValue<String, HashMap<StringName, Variant>> &E : p_source_file_options) {
PackData &pack_data = pack_data_files.write[idx];
- const String &source = E->key();
- const Map<StringName, Variant> &options = E->get();
+ const String &source = E.key;
+ const HashMap<StringName, Variant> &options = E.value;
Ref<Image> image;
image.instantiate();
@@ -271,6 +271,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
pack_data.chart_vertices.push_back(polygons[j]);
}
}
+ idx++;
}
//pack the charts
@@ -318,7 +319,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
//save the images
idx = 0;
- for (const Map<String, Map<StringName, Variant>>::Element *E = p_source_file_options.front(); E; E = E->next(), idx++) {
+ for (const KeyValue<String, HashMap<StringName, Variant>> &E : p_source_file_options) {
PackData &pack_data = pack_data_files.write[idx];
Ref<Texture2D> texture;
@@ -394,8 +395,9 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file
//mesh
}
- String save_path = p_base_paths[E->key()] + ".res";
+ String save_path = p_base_paths[E.key] + ".res";
ResourceSaver::save(save_path, texture);
+ idx++;
}
return OK;
diff --git a/editor/import/resource_importer_texture_atlas.h b/editor/import/resource_importer_texture_atlas.h
index a5e47dee99..971eb067df 100644
--- a/editor/import/resource_importer_texture_atlas.h
+++ b/editor/import/resource_importer_texture_atlas.h
@@ -61,11 +61,11 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
virtual String get_option_group_file() const override;
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
- virtual Error import_group_file(const String &p_group_file, const Map<String, Map<StringName, Variant>> &p_source_file_options, const Map<String, String> &p_base_paths) override;
+ 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 Error import_group_file(const String &p_group_file, const HashMap<String, HashMap<StringName, Variant>> &p_source_file_options, const HashMap<String, String> &p_base_paths) override;
ResourceImporterTextureAtlas();
};
diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp
index 8cb9a47fb5..362940dc17 100644
--- a/editor/import/resource_importer_wav.cpp
+++ b/editor/import/resource_importer_wav.cpp
@@ -58,11 +58,16 @@ String ResourceImporterWAV::get_resource_type() const {
return "AudioStreamSample";
}
-bool ResourceImporterWAV::get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const {
+bool ResourceImporterWAV::get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const {
if (p_option == "force/max_rate_hz" && !bool(p_options["force/max_rate"])) {
return false;
}
+ // Don't show begin/end loop points if loop mode is auto-detected or disabled.
+ if ((int)p_options["edit/loop_mode"] < 2 && (p_option == "edit/loop_begin" || p_option == "edit/loop_end")) {
+ return false;
+ }
+
return true;
}
@@ -81,15 +86,18 @@ void ResourceImporterWAV::get_import_options(const String &p_path, List<ImportOp
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "force/max_rate_hz", PROPERTY_HINT_RANGE, "11025,192000,1,exp"), 44100));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/trim"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/normalize"), false));
- r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "edit/loop"), false));
+ // Keep the `edit/loop_mode` enum in sync with AudioStreamSample::LoopMode (note: +1 offset due to "Detect From WAV").
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_mode", PROPERTY_HINT_ENUM, "Detect From WAV,Disabled,Forward,Ping-Pong,Backward", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_begin"), 0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "edit/loop_end"), -1));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "compress/mode", PROPERTY_HINT_ENUM, "Disabled,RAM (Ima-ADPCM)"), 0));
}
-Error ResourceImporterWAV::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
+Error ResourceImporterWAV::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) {
/* STEP 1, READ WAVE FILE */
Error err;
- FileAccess *file = FileAccess::open(p_source_file, FileAccess::READ, &err);
+ Ref<FileAccess> file = FileAccess::open(p_source_file, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(err != OK, ERR_CANT_OPEN, "Cannot open file '" + p_source_file + "'.");
@@ -99,8 +107,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
file->get_buffer((uint8_t *)&riff, 4); //RIFF
if (riff[0] != 'R' || riff[1] != 'I' || riff[2] != 'F' || riff[3] != 'F') {
- file->close();
- memdelete(file);
ERR_FAIL_V(ERR_FILE_UNRECOGNIZED);
}
@@ -114,15 +120,17 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
file->get_buffer((uint8_t *)&wave, 4); //RIFF
if (wave[0] != 'W' || wave[1] != 'A' || wave[2] != 'V' || wave[3] != 'E') {
- file->close();
- memdelete(file);
ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Not a WAV file (no WAVE RIFF header).");
}
+ // Let users override potential loop points from the WAV.
+ // We parse the WAV loop points only with "Detect From WAV" (0).
+ int import_loop_mode = p_options["edit/loop_mode"];
+
int format_bits = 0;
int format_channels = 0;
- AudioStreamSample::LoopMode loop = AudioStreamSample::LOOP_DISABLED;
+ AudioStreamSample::LoopMode loop_mode = AudioStreamSample::LOOP_DISABLED;
uint16_t compression_code = 1;
bool format_found = false;
bool data_found = false;
@@ -154,15 +162,11 @@ 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) {
- file->close();
- memdelete(file);
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead.");
}
format_channels = file->get_16();
if (format_channels != 1 && format_channels != 2) {
- file->close();
- memdelete(file);
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not stereo or mono).");
}
@@ -173,8 +177,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
format_bits = file->get_16(); // bits per sample
if (format_bits % 8 || format_bits == 0) {
- file->close();
- memdelete(file);
ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32).");
}
@@ -194,8 +196,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
frames = chunksize;
if (format_channels == 0) {
- file->close();
- memdelete(file);
ERR_FAIL_COND_V(format_channels == 0, ERR_INVALID_DATA);
}
frames /= format_channels;
@@ -242,14 +242,12 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
}
if (file->eof_reached()) {
- file->close();
- memdelete(file);
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Premature end of file.");
}
}
- if (chunkID[0] == 's' && chunkID[1] == 'm' && chunkID[2] == 'p' && chunkID[3] == 'l') {
- //loop point info!
+ if (import_loop_mode == 0 && chunkID[0] == 's' && chunkID[1] == 'm' && chunkID[2] == 'p' && chunkID[3] == 'l') {
+ // Loop point info!
/**
* Consider exploring next document:
@@ -270,11 +268,11 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
int loop_type = file->get_32();
if (loop_type == 0x00 || loop_type == 0x01 || loop_type == 0x02) {
if (loop_type == 0x00) {
- loop = AudioStreamSample::LOOP_FORWARD;
+ loop_mode = AudioStreamSample::LOOP_FORWARD;
} else if (loop_type == 0x01) {
- loop = AudioStreamSample::LOOP_PINGPONG;
+ loop_mode = AudioStreamSample::LOOP_PINGPONG;
} else if (loop_type == 0x02) {
- loop = AudioStreamSample::LOOP_BACKWARD;
+ loop_mode = AudioStreamSample::LOOP_BACKWARD;
}
loop_begin = file->get_32();
loop_end = file->get_32();
@@ -283,9 +281,6 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
file->seek(file_pos + chunksize);
}
- file->close();
- memdelete(file);
-
// STEP 2, APPLY CONVERSIONS
bool is16 = format_bits != 8;
@@ -346,7 +341,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
}
}
- if (loop) {
+ if (loop_mode) {
loop_begin = (int)(loop_begin * (float)new_data_frames / (float)frames);
loop_end = (int)(loop_end * (float)new_data_frames / (float)frames);
}
@@ -377,7 +372,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
bool trim = p_options["edit/trim"];
- if (trim && !loop && format_channels > 0) {
+ if (trim && (loop_mode != AudioStreamSample::LOOP_DISABLED) && format_channels > 0) {
int first = 0;
int last = (frames / format_channels) - 1;
bool found = false;
@@ -421,12 +416,17 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
}
}
- bool make_loop = p_options["edit/loop"];
-
- if (make_loop && !loop) {
- loop = AudioStreamSample::LOOP_FORWARD;
- loop_begin = 0;
- loop_end = frames;
+ if (import_loop_mode >= 2) {
+ loop_mode = (AudioStreamSample::LoopMode)(import_loop_mode - 1);
+ loop_begin = p_options["edit/loop_begin"];
+ loop_end = p_options["edit/loop_end"];
+ // Wrap around to max frames, so `-1` can be used to select the end, etc.
+ if (loop_begin < 0) {
+ loop_begin = CLAMP(loop_begin + frames + 1, 0, frames);
+ }
+ if (loop_end < 0) {
+ loop_end = CLAMP(loop_end + frames + 1, 0, frames);
+ }
}
int compression = p_options["compress/mode"];
@@ -512,7 +512,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
sample->set_data(dst_data);
sample->set_format(dst_format);
sample->set_mix_rate(rate);
- sample->set_loop_mode(loop);
+ sample->set_loop_mode(loop_mode);
sample->set_loop_begin(loop_begin);
sample->set_loop_end(loop_end);
sample->set_stereo(format_channels == 2);
diff --git a/editor/import/resource_importer_wav.h b/editor/import/resource_importer_wav.h
index 2316ce80e5..739ec9b181 100644
--- a/editor/import/resource_importer_wav.h
+++ b/editor/import/resource_importer_wav.h
@@ -47,7 +47,7 @@ public:
virtual String get_preset_name(int p_idx) const override;
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const override;
- virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const override;
+ virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
static void _compress_ima_adpcm(const Vector<float> &p_data, Vector<uint8_t> &dst_data) {
static const int16_t _ima_adpcm_step_table[89] = {
@@ -140,7 +140,7 @@ public:
}
}
- virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override;
+ 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;
ResourceImporterWAV();
};
diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp
index 4e06253041..99d1658405 100644
--- a/editor/import/scene_import_settings.cpp
+++ b/editor/import/scene_import_settings.cpp
@@ -43,10 +43,12 @@
class SceneImportSettingsData : public Object {
GDCLASS(SceneImportSettingsData, Object)
friend class SceneImportSettings;
- Map<StringName, Variant> *settings = nullptr;
- Map<StringName, Variant> current;
- Map<StringName, Variant> defaults;
+ HashMap<StringName, Variant> *settings = nullptr;
+ HashMap<StringName, Variant> current;
+ HashMap<StringName, Variant> defaults;
List<ResourceImporter::ImportOption> options;
+ bool hide_options = false;
+ String path;
ResourceImporterScene::InternalImportCategory category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;
@@ -60,8 +62,26 @@ class SceneImportSettingsData : public Object {
current[p_name] = p_value;
- if (ResourceImporterScene::get_singleton()->get_internal_option_update_view_required(category, p_name, current)) {
- SceneImportSettings::get_singleton()->update_view();
+ if (SceneImportSettings::get_singleton()->is_editing_animation()) {
+ if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ if (ResourceImporterScene::get_animation_singleton()->get_option_visibility(path, p_name, current)) {
+ SceneImportSettings::get_singleton()->update_view();
+ }
+ } else {
+ if (ResourceImporterScene::get_animation_singleton()->get_internal_option_update_view_required(category, p_name, current)) {
+ SceneImportSettings::get_singleton()->update_view();
+ }
+ }
+ } else {
+ if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ if (ResourceImporterScene::get_scene_singleton()->get_option_visibility(path, p_name, current)) {
+ SceneImportSettings::get_singleton()->update_view();
+ }
+ } else {
+ if (ResourceImporterScene::get_scene_singleton()->get_internal_option_update_view_required(category, p_name, current)) {
+ SceneImportSettings::get_singleton()->update_view();
+ }
+ }
}
return true;
@@ -82,9 +102,30 @@ class SceneImportSettingsData : public Object {
return false;
}
void _get_property_list(List<PropertyInfo> *p_list) const {
+ if (hide_options) {
+ return;
+ }
for (const ResourceImporter::ImportOption &E : options) {
- if (ResourceImporterScene::get_singleton()->get_internal_option_visibility(category, E.option.name, current)) {
- p_list->push_back(E.option);
+ if (SceneImportSettings::get_singleton()->is_editing_animation()) {
+ if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ if (ResourceImporterScene::get_animation_singleton()->get_option_visibility(path, E.option.name, current)) {
+ p_list->push_back(E.option);
+ }
+ } else {
+ if (ResourceImporterScene::get_animation_singleton()->get_internal_option_visibility(category, E.option.name, current)) {
+ p_list->push_back(E.option);
+ }
+ }
+ } else {
+ if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ if (ResourceImporterScene::get_scene_singleton()->get_option_visibility(path, E.option.name, current)) {
+ p_list->push_back(E.option);
+ }
+ } else {
+ if (ResourceImporterScene::get_scene_singleton()->get_internal_option_visibility(category, E.option.name, current)) {
+ p_list->push_back(E.option);
+ }
+ }
}
}
}
@@ -326,7 +367,9 @@ void SceneImportSettings::_fill_scene(Node *p_node, TreeItem *p_parent_item) {
}
MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);
if (mesh_node && mesh_node->get_mesh().is_valid()) {
- _fill_mesh(scene_tree, mesh_node->get_mesh(), item);
+ if (!editing_animation) {
+ _fill_mesh(scene_tree, mesh_node->get_mesh(), item);
+ }
// Add the collider view.
MeshInstance3D *collider_view = memnew(MeshInstance3D);
@@ -365,6 +408,9 @@ void SceneImportSettings::_update_scene() {
}
void SceneImportSettings::_update_view_gizmos() {
+ if (!is_visible()) {
+ return;
+ }
for (const KeyValue<String, NodeData> &e : node_map) {
bool generate_collider = false;
if (e.value.settings.has(SNAME("generate/physics"))) {
@@ -377,7 +423,8 @@ void SceneImportSettings::_update_view_gizmos() {
continue;
}
- TypedArray<Node> descendants = mesh_node->find_nodes("collider_view", "MeshInstance3D");
+ TypedArray<Node> descendants = mesh_node->find_children("collider_view", "MeshInstance3D");
+
CRASH_COND_MSG(descendants.is_empty(), "This is unreachable, since the collider view is always created even when the collision is not used! If this is triggered there is a bug on the function `_fill_scene`.");
MeshInstance3D *collider_view = static_cast<MeshInstance3D *>(descendants[0].operator Object *());
@@ -447,20 +494,24 @@ void SceneImportSettings::_update_camera() {
camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2);
Transform3D xf;
- xf.basis = Basis(Vector3(0, 1, 0), rot_y) * Basis(Vector3(1, 0, 0), rot_x);
+ xf.basis = Basis(Vector3(1, 0, 0), rot_x) * Basis(Vector3(0, 1, 0), rot_y);
xf.origin = center;
xf.translate(0, 0, camera_size);
camera->set_transform(xf);
}
-void SceneImportSettings::_load_default_subresource_settings(Map<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category) {
+void SceneImportSettings::_load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category) {
if (base_subresource_settings.has(p_type)) {
Dictionary d = base_subresource_settings[p_type];
if (d.has(p_import_id)) {
d = d[p_import_id];
List<ResourceImporterScene::ImportOption> options;
- ResourceImporterScene::get_singleton()->get_internal_import_options(p_category, &options);
+ if (editing_animation) {
+ ResourceImporterScene::get_animation_singleton()->get_internal_import_options(p_category, &options);
+ } else {
+ ResourceImporterScene::get_scene_singleton()->get_internal_import_options(p_category, &options);
+ }
for (const ResourceImporterScene::ImportOption &E : options) {
String key = E.option.name;
if (d.has(key)) {
@@ -472,21 +523,32 @@ void SceneImportSettings::_load_default_subresource_settings(Map<StringName, Var
}
void SceneImportSettings::update_view() {
- _update_view_gizmos();
+ update_view_timer->start();
}
-void SceneImportSettings::open_settings(const String &p_path) {
+void SceneImportSettings::open_settings(const String &p_path, bool p_for_animation) {
if (scene) {
memdelete(scene);
scene = nullptr;
}
+
+ editing_animation = p_for_animation;
scene_import_settings_data->settings = nullptr;
- scene = ResourceImporterScene::get_singleton()->pre_import(p_path);
+ 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);
+
+ action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_EXTRACT_MATERIALS), p_for_animation);
+ action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_CHOOSE_MESH_SAVE_PATHS), p_for_animation);
+
base_path = p_path;
material_set.clear();
@@ -496,6 +558,8 @@ void SceneImportSettings::open_settings(const String &p_path) {
node_map.clear();
defaults.clear();
+ mesh_preview->hide();
+
selected_id = "";
selected_type = "";
@@ -529,6 +593,8 @@ void SceneImportSettings::open_settings(const String &p_path) {
base_viewport->add_child(scene);
+ inspector->edit(nullptr);
+
if (first_aabb) {
contents_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
first_aabb = false;
@@ -538,7 +604,11 @@ void SceneImportSettings::open_settings(const String &p_path) {
_update_view_gizmos();
_update_camera();
- set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file()));
+ if (p_for_animation) {
+ set_title(vformat(TTR("Advanced Import Settings for AnimationLibrary '%s'"), base_path.get_file()));
+ } else {
+ set_title(vformat(TTR("Advanced Import Settings for Scene '%s'"), base_path.get_file()));
+ }
}
SceneImportSettings *SceneImportSettings::singleton = nullptr;
@@ -549,6 +619,7 @@ SceneImportSettings *SceneImportSettings::get_singleton() {
void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
selecting = true;
+ scene_import_settings_data->hide_options = false;
if (p_type == "Node") {
node_selected->hide(); //always hide just in case
@@ -583,10 +654,12 @@ void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
scene_import_settings_data->settings = &nd.settings;
if (mi) {
scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;
+ 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 {
scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;
+ scene_import_settings_data->hide_options = editing_animation;
}
}
} else if (p_type == "Animation") {
@@ -669,24 +742,36 @@ void SceneImportSettings::_select(Tree *p_from, String p_type, String p_id) {
List<ResourceImporter::ImportOption> options;
- if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
- ResourceImporterScene::get_singleton()->get_import_options(base_path, &options);
+ if (editing_animation) {
+ if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ ResourceImporterScene::get_animation_singleton()->get_import_options(base_path, &options);
+ } else {
+ ResourceImporterScene::get_animation_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);
+ }
+
} else {
- ResourceImporterScene::get_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);
+ if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {
+ ResourceImporterScene::get_scene_singleton()->get_import_options(base_path, &options);
+ } else {
+ ResourceImporterScene::get_scene_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);
+ }
}
scene_import_settings_data->defaults.clear();
scene_import_settings_data->current.clear();
- for (const ResourceImporter::ImportOption &E : options) {
- scene_import_settings_data->defaults[E.option.name] = E.default_value;
- //needed for visibility toggling (fails if something is missing)
- if (scene_import_settings_data->settings->has(E.option.name)) {
- scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name];
- } else {
- scene_import_settings_data->current[E.option.name] = E.default_value;
+ if (scene_import_settings_data->settings) {
+ for (const ResourceImporter::ImportOption &E : options) {
+ scene_import_settings_data->defaults[E.option.name] = E.default_value;
+ //needed for visibility toggling (fails if something is missing)
+ if (scene_import_settings_data->settings->has(E.option.name)) {
+ scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name];
+ } else {
+ scene_import_settings_data->current[E.option.name] = E.default_value;
+ }
}
}
+
scene_import_settings_data->options = options;
inspector->edit(scene_import_settings_data);
scene_import_settings_data->notify_property_list_changed();
@@ -767,7 +852,7 @@ void SceneImportSettings::_viewport_input(const Ref<InputEvent> &p_input) {
}
void SceneImportSettings::_re_import() {
- Map<StringName, Variant> main_settings;
+ HashMap<StringName, Variant> main_settings;
main_settings = defaults;
main_settings.erase("_subresources");
@@ -834,7 +919,7 @@ void SceneImportSettings::_re_import() {
main_settings["_subresources"] = subresources;
}
- EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "scene", main_settings);
+ EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings);
}
void SceneImportSettings::_notification(int p_what) {
@@ -842,6 +927,10 @@ void SceneImportSettings::_notification(int p_what) {
case NOTIFICATION_READY: {
connect("confirmed", callable_mp(this, &SceneImportSettings::_re_import));
} break;
+
+ case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ inspector->set_property_name_style(EditorPropertyNameProcessor::get_settings_style());
+ } break;
}
}
@@ -880,7 +969,11 @@ void SceneImportSettings::_save_path_changed(const String &p_path) {
}
}
-void SceneImportSettings::_browse_save_callback(Object *p_item, int p_column, int p_id) {
+void SceneImportSettings::_browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button) {
+ if (p_button != MouseButton::LEFT) {
+ return;
+ }
+
TreeItem *item = Object::cast_to<TreeItem>(p_item);
String path = item->get_text(1);
@@ -1136,6 +1229,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);
@@ -1229,6 +1323,7 @@ SceneImportSettings::SceneImportSettings() {
inspector = memnew(EditorInspector);
inspector->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
+ inspector->set_property_name_style(EditorPropertyNameProcessor::get_settings_style());
property_split->add_child(inspector);
@@ -1241,7 +1336,7 @@ SceneImportSettings::SceneImportSettings() {
add_child(external_paths);
external_path_tree = memnew(Tree);
external_paths->add_child(external_path_tree);
- external_path_tree->connect("button_pressed", callable_mp(this, &SceneImportSettings::_browse_save_callback));
+ external_path_tree->connect("button_clicked", callable_mp(this, &SceneImportSettings::_browse_save_callback));
external_paths->connect("confirmed", callable_mp(this, &SceneImportSettings::_save_dir_confirm));
external_path_tree->set_columns(3);
external_path_tree->set_column_titles_visible(true);
@@ -1259,7 +1354,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"));
@@ -1269,12 +1364,17 @@ SceneImportSettings::SceneImportSettings() {
item_save_path = memnew(EditorFileDialog);
item_save_path->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
- item_save_path->add_filter("*.tres;Text Resource");
- item_save_path->add_filter("*.res;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));
save_path->connect("dir_selected", callable_mp(this, &SceneImportSettings::_save_dir_callback));
+
+ update_view_timer = memnew(Timer);
+ update_view_timer->set_wait_time(0.2);
+ update_view_timer->connect("timeout", callable_mp(this, &SceneImportSettings::_update_view_gizmos));
+ add_child(update_view_timer);
}
SceneImportSettings::~SceneImportSettings() {
diff --git a/editor/import/scene_import_settings.h b/editor/import/scene_import_settings.h
index b51f342729..81d13166ab 100644
--- a/editor/import/scene_import_settings.h
+++ b/editor/import/scene_import_settings.h
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef SCENEIMPORTSETTINGS_H
-#define SCENEIMPORTSETTINGS_H
+#ifndef SCENE_IMPORT_SETTINGS_H
+#define SCENE_IMPORT_SETTINGS_H
#include "editor/import/resource_importer_scene.h"
#include "scene/3d/camera_3d.h"
@@ -62,85 +62,85 @@ class SceneImportSettings : public ConfirmationDialog {
Node *scene = nullptr;
- HSplitContainer *tree_split;
- HSplitContainer *property_split;
- TabContainer *data_mode;
- Tree *scene_tree;
- Tree *mesh_tree;
- Tree *material_tree;
+ HSplitContainer *tree_split = nullptr;
+ HSplitContainer *property_split = nullptr;
+ TabContainer *data_mode = nullptr;
+ Tree *scene_tree = nullptr;
+ Tree *mesh_tree = nullptr;
+ Tree *material_tree = nullptr;
- EditorInspector *inspector;
+ EditorInspector *inspector = nullptr;
- SubViewport *base_viewport;
+ SubViewport *base_viewport = nullptr;
- Camera3D *camera;
+ Camera3D *camera = nullptr;
bool first_aabb = false;
AABB contents_aabb;
- DirectionalLight3D *light;
+ DirectionalLight3D *light = nullptr;
Ref<ArrayMesh> selection_mesh;
- MeshInstance3D *node_selected;
+ MeshInstance3D *node_selected = nullptr;
- MeshInstance3D *mesh_preview;
+ MeshInstance3D *mesh_preview = nullptr;
Ref<SphereMesh> material_preview;
Ref<StandardMaterial3D> collider_mat;
- float cam_rot_x;
- float cam_rot_y;
- float cam_zoom;
+ float cam_rot_x = 0.0f;
+ float cam_rot_y = 0.0f;
+ float cam_zoom = 0.0f;
void _update_scene();
struct MaterialData {
bool has_import_id;
Ref<Material> material;
- TreeItem *scene_node;
- TreeItem *mesh_node;
- TreeItem *material_node;
+ TreeItem *scene_node = nullptr;
+ TreeItem *mesh_node = nullptr;
+ TreeItem *material_node = nullptr;
float cam_rot_x = -Math_PI / 4;
float cam_rot_y = -Math_PI / 4;
float cam_zoom = 1;
- Map<StringName, Variant> settings;
+ HashMap<StringName, Variant> settings;
};
- Map<String, MaterialData> material_map;
+ HashMap<String, MaterialData> material_map;
struct MeshData {
bool has_import_id;
Ref<Mesh> mesh;
- TreeItem *scene_node;
- TreeItem *mesh_node;
+ TreeItem *scene_node = nullptr;
+ TreeItem *mesh_node = nullptr;
float cam_rot_x = -Math_PI / 4;
float cam_rot_y = -Math_PI / 4;
float cam_zoom = 1;
- Map<StringName, Variant> settings;
+ HashMap<StringName, Variant> settings;
};
- Map<String, MeshData> mesh_map;
+ HashMap<String, MeshData> mesh_map;
struct AnimationData {
Ref<Animation> animation;
- TreeItem *scene_node;
- Map<StringName, Variant> settings;
+ TreeItem *scene_node = nullptr;
+ HashMap<StringName, Variant> settings;
};
- Map<String, AnimationData> animation_map;
+ HashMap<String, AnimationData> animation_map;
struct NodeData {
- Node *node;
- TreeItem *scene_node;
- Map<StringName, Variant> settings;
+ Node *node = nullptr;
+ TreeItem *scene_node = nullptr;
+ HashMap<StringName, Variant> settings;
};
- Map<String, NodeData> node_map;
+ HashMap<String, NodeData> node_map;
void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);
void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);
void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);
void _fill_scene(Node *p_node, TreeItem *p_parent_item);
- Set<Ref<Mesh>> mesh_set;
- Set<Ref<Material>> material_set;
+ HashSet<Ref<Mesh>> mesh_set;
+ HashSet<Ref<Material>> material_set;
String selected_type;
String selected_id;
@@ -156,48 +156,53 @@ class SceneImportSettings : public ConfirmationDialog {
void _viewport_input(const Ref<InputEvent> &p_input);
- Map<StringName, Variant> defaults;
+ HashMap<StringName, Variant> defaults;
- SceneImportSettingsData *scene_import_settings_data;
+ SceneImportSettingsData *scene_import_settings_data = nullptr;
void _re_import();
String base_path;
- MenuButton *action_menu;
+ MenuButton *action_menu = nullptr;
- ConfirmationDialog *external_paths;
- Tree *external_path_tree;
- EditorFileDialog *save_path;
- OptionButton *external_extension_type;
+ ConfirmationDialog *external_paths = nullptr;
+ Tree *external_path_tree = nullptr;
+ EditorFileDialog *save_path = nullptr;
+ OptionButton *external_extension_type = nullptr;
- EditorFileDialog *item_save_path;
+ EditorFileDialog *item_save_path = nullptr;
void _menu_callback(int p_id);
void _save_dir_callback(const String &p_path);
- int current_action;
+ int current_action = 0;
Vector<TreeItem *> save_path_items;
TreeItem *save_path_item = nullptr;
void _save_path_changed(const String &p_path);
- void _browse_save_callback(Object *p_item, int p_column, int p_id);
+ void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _save_dir_confirm();
Dictionary base_subresource_settings;
- void _load_default_subresource_settings(Map<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);
+ void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);
+
+ bool editing_animation = false;
+
+ Timer *update_view_timer;
protected:
void _notification(int p_what);
public:
+ bool is_editing_animation() const { return editing_animation; }
void update_view();
- void open_settings(const String &p_path);
+ void open_settings(const String &p_path, bool p_for_animation = false);
static SceneImportSettings *get_singleton();
SceneImportSettings();
~SceneImportSettings();
};
-#endif // SCENEIMPORTSETTINGS_H
+#endif // SCENE_IMPORT_SETTINGS_H