diff options
Diffstat (limited to 'editor/import')
-rw-r--r-- | editor/import/audio_stream_import_settings.cpp | 14 | ||||
-rw-r--r-- | editor/import/collada.cpp | 8 | ||||
-rw-r--r-- | editor/import/dynamic_font_import_settings.cpp | 13 | ||||
-rw-r--r-- | editor/import/editor_import_plugin.cpp | 4 | ||||
-rw-r--r-- | editor/import/resource_importer_layered_texture.cpp | 22 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 237 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.h | 13 | ||||
-rw-r--r-- | editor/import/resource_importer_texture.cpp | 33 | ||||
-rw-r--r-- | editor/import/resource_importer_texture_atlas.cpp | 4 |
9 files changed, 167 insertions, 181 deletions
diff --git a/editor/import/audio_stream_import_settings.cpp b/editor/import/audio_stream_import_settings.cpp index e3da82a5cb..d94b517003 100644 --- a/editor/import/audio_stream_import_settings.cpp +++ b/editor/import/audio_stream_import_settings.cpp @@ -76,7 +76,7 @@ void AudioStreamImportSettings::_notification(int p_what) { void AudioStreamImportSettings::_draw_preview() { Rect2 rect = _preview->get_rect(); - Size2 size = rect.size; + Size2 rect_size = rect.size; Ref<AudioStreamPreview> preview = AudioStreamPreviewGenerator::get_singleton()->generate_preview(stream); float preview_offset = zoom_bar->get_value(); @@ -85,7 +85,7 @@ void AudioStreamImportSettings::_draw_preview() { Ref<Font> beat_font = get_theme_font(SNAME("main"), SNAME("EditorFonts")); int main_size = get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts")); Vector<Vector2> lines; - lines.resize(size.width * 2); + lines.resize(rect_size.width * 2); Color color_active = get_theme_color(SNAME("contrast_color_2"), SNAME("Editor")); Color color_inactive = color_active; color_inactive.a *= 0.5; @@ -107,9 +107,9 @@ void AudioStreamImportSettings::_draw_preview() { } } - for (int i = 0; i < size.width; i++) { - float ofs = preview_offset + i * preview_len / size.width; - float ofs_n = preview_offset + (i + 1) * preview_len / size.width; + for (int i = 0; i < rect_size.width; i++) { + float ofs = preview_offset + i * preview_len / rect_size.width; + float ofs_n = preview_offset + (i + 1) * preview_len / rect_size.width; float max = preview->get_max(ofs, ofs_n) * 0.5 + 0.5; float min = preview->get_min(ofs, ofs_n) * 0.5 + 0.5; @@ -139,8 +139,8 @@ void AudioStreamImportSettings::_draw_preview() { int bar_beats = stream->get_bar_beats(); int last_text_end_x = 0; - for (int i = 0; i < size.width; i++) { - float ofs = preview_offset + i * preview_len / size.width; + for (int i = 0; i < rect_size.width; i++) { + float ofs = preview_offset + i * preview_len / rect_size.width; int beat = int(ofs / beat_size); if (beat != prev_beat) { String text = itos(beat); diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index 5d8e453395..7cf35c519b 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -2036,11 +2036,7 @@ void Collada::_merge_skeletons(VisualScene *p_vscene, Node *p_node) { ERR_CONTINUE(!state.scene_map.has(nodeid)); //weird, it should have it... -#ifdef NO_SAFE_CAST - NodeJoint *nj = static_cast<NodeJoint *>(state.scene_map[nodeid]); -#else NodeJoint *nj = dynamic_cast<NodeJoint *>(state.scene_map[nodeid]); -#endif ERR_CONTINUE(!nj); //broken collada ERR_CONTINUE(!nj->owner); //weird, node should have a skeleton owner @@ -2197,11 +2193,7 @@ bool Collada::_move_geometry_to_skeletons(VisualScene *p_vscene, Node *p_node, L String nodeid = ng->skeletons[0]; ERR_FAIL_COND_V(!state.scene_map.has(nodeid), false); //weird, it should have it... -#ifdef NO_SAFE_CAST - NodeJoint *nj = static_cast<NodeJoint *>(state.scene_map[nodeid]); -#else NodeJoint *nj = dynamic_cast<NodeJoint *>(state.scene_map[nodeid]); -#endif ERR_FAIL_COND_V(!nj, false); ERR_FAIL_COND_V(!nj->owner, false); //weird, node should have a skeleton owner diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index c1761339b2..5585c8edd2 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -949,11 +949,11 @@ void DynamicFontImportSettings::_re_import() { void DynamicFontImportSettings::open_settings(const String &p_path) { // Load base font data. - Vector<uint8_t> data = FileAccess::get_file_as_array(p_path); + Vector<uint8_t> font_data = FileAccess::get_file_as_array(p_path); // Load font for preview. font_preview.instantiate(); - font_preview->set_data(data); + font_preview->set_data(font_data); String font_name = vformat("%s (%s)", font_preview->get_font_name(), font_preview->get_font_style_name()); String sample; @@ -976,7 +976,7 @@ void DynamicFontImportSettings::open_settings(const String &p_path) { // Load second copy of font with MSDF disabled for the glyph table and metadata extraction. font_main.instantiate(); - font_main->set_data(data); + font_main->set_data(font_data); font_main->set_multichannel_signed_distance_field(false); text_edit->add_theme_font_override("font", font_main); @@ -1009,6 +1009,7 @@ void DynamicFontImportSettings::open_settings(const String &p_path) { vars_list_root = vars_list->create_item(); + import_settings_data->settings.clear(); import_settings_data->defaults.clear(); for (List<ResourceImporter::ImportOption>::Element *E = options_general.front(); E; E = E->next()) { import_settings_data->defaults[E->get().option.name] = E->get().default_value; @@ -1035,7 +1036,7 @@ void DynamicFontImportSettings::open_settings(const String &p_path) { double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0; int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0; Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D(); - Vector2i size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0); + Vector2i font_size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0); String cfg_name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i); TreeItem *vars_item = vars_list->create_item(vars_list_root); @@ -1060,8 +1061,8 @@ void DynamicFontImportSettings::open_settings(const String &p_path) { import_variation_data_custom->options = options_variations; vars_item->set_metadata(0, import_variation_data_custom); - import_variation_data_custom->set("size", size.x); - import_variation_data_custom->set("outline_size", size.y); + import_variation_data_custom->set("size", font_size.x); + import_variation_data_custom->set("outline_size", font_size.y); import_variation_data_custom->set("variation_opentype", variation); import_variation_data_custom->set("variation_embolden", embolden); import_variation_data_custom->set("variation_face_index", face_index); diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 5211f003c1..5d684fc5db 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -154,7 +154,7 @@ bool EditorImportPlugin::get_option_visibility(const String &p_path, const Strin d[E->key] = E->value; ++E; } - bool visible; + bool visible = false; if (GDVIRTUAL_CALL(_get_option_visibility, p_path, p_option, d, visible)) { return visible; } @@ -172,7 +172,7 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa ++E; } - int err; + int err = 0; if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) { Error ret_err = Error(err); diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index ed83535421..e1df78e741 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -186,9 +186,7 @@ void ResourceImporterLayeredTexture::_save_tex(Vector<Ref<Image>> p_images, cons int mm_d = MAX(1, d >> 1); for (int i = 0; i < mm_d; i++) { - Ref<Image> mm; - mm.instantiate(); - mm->create(mm_w, mm_h, false, p_images[0]->get_format()); + Ref<Image> mm = Image::create_empty(mm_w, mm_h, false, p_images[0]->get_format()); Vector3 pos; pos.z = float(i) * float(d) / float(mm_d) + 0.5; for (int x = 0; x < mm_w; x++) { @@ -396,12 +394,12 @@ Error ResourceImporterLayeredTexture::import(const String &p_source_file, const texture_import->used_channels = used_channels; _check_compress_ctex(p_source_file, texture_import); if (r_metadata) { - Dictionary metadata; - metadata["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED; + Dictionary meta; + meta["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED; if (formats_imported.size()) { - metadata["imported_formats"] = formats_imported; + meta["imported_formats"] = formats_imported; } - *r_metadata = metadata; + *r_metadata = meta; } return OK; @@ -432,20 +430,20 @@ String ResourceImporterLayeredTexture::get_import_settings_string() const { bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_path) const { //will become invalid if formats are missing to import - Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); + Dictionary meta = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); - if (!metadata.has("vram_texture")) { + if (!meta.has("vram_texture")) { return false; } - bool vram = metadata["vram_texture"]; + bool vram = meta["vram_texture"]; if (!vram) { return true; //do not care about non vram } Vector<String> formats_imported; - if (metadata.has("imported_formats")) { - formats_imported = metadata["imported_formats"]; + if (meta.has("imported_formats")) { + formats_imported = meta["imported_formats"]; } int index = 0; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index b5798a5784..756d61f712 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -953,43 +953,49 @@ Node *ResourceImporterScene::_pre_fix_animations(Node *p_node, Node *p_root, con if (Object::cast_to<AnimationPlayer>(p_node)) { AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node); + List<StringName> anims; + ap->get_animation_list(&anims); - Array animation_clips; - { - int clip_count = node_settings["clips/amount"]; + for (const StringName &name : anims) { + Ref<Animation> anim = ap->get_animation(name); + Array animation_slices; - for (int i = 0; i < clip_count; i++) { - String name = node_settings["clip_" + itos(i + 1) + "/name"]; - int from_frame = node_settings["clip_" + itos(i + 1) + "/start_frame"]; - int end_frame = node_settings["clip_" + itos(i + 1) + "/end_frame"]; - Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)node_settings["clip_" + itos(i + 1) + "/loop_mode"]); - bool save_to_file = node_settings["clip_" + itos(i + 1) + "/save_to_file/enabled"]; - bool save_to_path = node_settings["clip_" + itos(i + 1) + "/save_to_file/path"]; - bool save_to_file_keep_custom = node_settings["clip_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"]; + if (p_animation_data.has(name)) { + Dictionary anim_settings = p_animation_data[name]; + int slices_count = anim_settings["slices/amount"]; + + for (int i = 0; i < slices_count; i++) { + String slice_name = anim_settings["slice_" + itos(i + 1) + "/name"]; + int from_frame = anim_settings["slice_" + itos(i + 1) + "/start_frame"]; + int end_frame = anim_settings["slice_" + itos(i + 1) + "/end_frame"]; + Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)anim_settings["slice_" + itos(i + 1) + "/loop_mode"]); + bool save_to_file = anim_settings["slice_" + itos(i + 1) + "/save_to_file/enabled"]; + bool save_to_path = anim_settings["slice_" + itos(i + 1) + "/save_to_file/path"]; + bool save_to_file_keep_custom = anim_settings["slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"]; + + animation_slices.push_back(slice_name); + animation_slices.push_back(from_frame / p_animation_fps); + animation_slices.push_back(end_frame / p_animation_fps); + animation_slices.push_back(loop_mode); + animation_slices.push_back(save_to_file); + animation_slices.push_back(save_to_path); + animation_slices.push_back(save_to_file_keep_custom); + } + } - animation_clips.push_back(name); - animation_clips.push_back(from_frame / p_animation_fps); - animation_clips.push_back(end_frame / p_animation_fps); - animation_clips.push_back(loop_mode); - animation_clips.push_back(save_to_file); - animation_clips.push_back(save_to_path); - animation_clips.push_back(save_to_file_keep_custom); + if (animation_slices.size() > 0) { + _create_slices(ap, anim, animation_slices, true); } } - if (animation_clips.size()) { - _create_clips(ap, animation_clips, true); - } else { - List<StringName> anims; - ap->get_animation_list(&anims); - AnimationImportTracks import_tracks_mode[TRACK_CHANNEL_MAX] = { - AnimationImportTracks(int(node_settings["import_tracks/position"])), - AnimationImportTracks(int(node_settings["import_tracks/rotation"])), - AnimationImportTracks(int(node_settings["import_tracks/scale"])) - }; - if (anims.size() > 1 && (import_tracks_mode[0] != ANIMATION_IMPORT_TRACKS_IF_PRESENT || import_tracks_mode[1] != ANIMATION_IMPORT_TRACKS_IF_PRESENT || import_tracks_mode[2] != ANIMATION_IMPORT_TRACKS_IF_PRESENT)) { - _optimize_track_usage(ap, import_tracks_mode); - } + AnimationImportTracks import_tracks_mode[TRACK_CHANNEL_MAX] = { + AnimationImportTracks(int(node_settings["import_tracks/position"])), + AnimationImportTracks(int(node_settings["import_tracks/rotation"])), + AnimationImportTracks(int(node_settings["import_tracks/scale"])) + }; + + if (anims.size() > 1 && (import_tracks_mode[0] != ANIMATION_IMPORT_TRACKS_IF_PRESENT || import_tracks_mode[1] != ANIMATION_IMPORT_TRACKS_IF_PRESENT || import_tracks_mode[2] != ANIMATION_IMPORT_TRACKS_IF_PRESENT)) { + _optimize_track_usage(ap, import_tracks_mode); } } @@ -1408,144 +1414,138 @@ Ref<Animation> ResourceImporterScene::_save_animation_to_file(Ref<Animation> ani return anim; } -void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_clips, bool p_bake_all) { - if (!anim->has_animation("default")) { - ERR_FAIL_COND_MSG(p_clips.size() > 0, "To create clips, animations must be named \"default\"."); - return; - } +void ResourceImporterScene::_create_slices(AnimationPlayer *ap, Ref<Animation> anim, const Array &p_slices, bool p_bake_all) { + Ref<AnimationLibrary> al = ap->get_animation_library(ap->find_animation_library(anim)); - 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]; - float from = p_clips[i + 1]; - float to = p_clips[i + 2]; - Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)p_clips[i + 3]); - bool save_to_file = p_clips[i + 4]; - String save_to_path = p_clips[i + 5]; - bool keep_current = p_clips[i + 6]; + for (int i = 0; i < p_slices.size(); i += 7) { + String name = p_slices[i]; + float from = p_slices[i + 1]; + float to = p_slices[i + 2]; + Animation::LoopMode loop_mode = static_cast<Animation::LoopMode>((int)p_slices[i + 3]); + bool save_to_file = p_slices[i + 4]; + String save_to_path = p_slices[i + 5]; + bool keep_current = p_slices[i + 6]; if (from >= to) { continue; } Ref<Animation> new_anim = memnew(Animation); - for (int j = 0; j < default_anim->get_track_count(); j++) { + for (int j = 0; j < anim->get_track_count(); j++) { List<float> keys; - int kc = default_anim->track_get_key_count(j); + int kc = anim->track_get_key_count(j); int dtrack = -1; for (int k = 0; k < kc; k++) { - float kt = default_anim->track_get_key_time(j, k); + float kt = anim->track_get_key_time(j, k); if (kt >= from && kt < to) { //found a key within range, so create track if (dtrack == -1) { - new_anim->add_track(default_anim->track_get_type(j)); + new_anim->add_track(anim->track_get_type(j)); dtrack = new_anim->get_track_count() - 1; - new_anim->track_set_path(dtrack, default_anim->track_get_path(j)); + new_anim->track_set_path(dtrack, anim->track_get_path(j)); if (kt > (from + 0.01) && k > 0) { - if (default_anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { + if (anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { Vector3 p; - default_anim->position_track_interpolate(j, from, &p); + anim->position_track_interpolate(j, from, &p); new_anim->position_track_insert_key(dtrack, 0, p); - } else if (default_anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { Quaternion r; - default_anim->rotation_track_interpolate(j, from, &r); + anim->rotation_track_interpolate(j, from, &r); new_anim->rotation_track_insert_key(dtrack, 0, r); - } else if (default_anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { Vector3 s; - default_anim->scale_track_interpolate(j, from, &s); + anim->scale_track_interpolate(j, from, &s); new_anim->scale_track_insert_key(dtrack, 0, s); - } else if (default_anim->track_get_type(j) == Animation::TYPE_VALUE) { - Variant var = default_anim->value_track_interpolate(j, from); + } else if (anim->track_get_type(j) == Animation::TYPE_VALUE) { + Variant var = anim->value_track_interpolate(j, from); new_anim->track_insert_key(dtrack, 0, var); - } else if (default_anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { + } else if (anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { float interp; - default_anim->blend_shape_track_interpolate(j, from, &interp); + anim->blend_shape_track_interpolate(j, from, &interp); new_anim->blend_shape_track_insert_key(dtrack, 0, interp); } } } - if (default_anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { + if (anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { Vector3 p; - default_anim->position_track_get_key(j, k, &p); + anim->position_track_get_key(j, k, &p); new_anim->position_track_insert_key(dtrack, kt - from, p); - } else if (default_anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { Quaternion r; - default_anim->rotation_track_get_key(j, k, &r); + anim->rotation_track_get_key(j, k, &r); new_anim->rotation_track_insert_key(dtrack, kt - from, r); - } else if (default_anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { Vector3 s; - default_anim->scale_track_get_key(j, k, &s); + anim->scale_track_get_key(j, k, &s); new_anim->scale_track_insert_key(dtrack, kt - from, s); - } else if (default_anim->track_get_type(j) == Animation::TYPE_VALUE) { - Variant var = default_anim->track_get_key_value(j, k); + } else if (anim->track_get_type(j) == Animation::TYPE_VALUE) { + Variant var = anim->track_get_key_value(j, k); new_anim->track_insert_key(dtrack, kt - from, var); - } else if (default_anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { + } else if (anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { float interp; - default_anim->blend_shape_track_get_key(j, k, &interp); + anim->blend_shape_track_get_key(j, k, &interp); new_anim->blend_shape_track_insert_key(dtrack, kt - from, interp); } } if (dtrack != -1 && kt >= to) { - if (default_anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { + if (anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { Vector3 p; - default_anim->position_track_interpolate(j, to, &p); + anim->position_track_interpolate(j, to, &p); new_anim->position_track_insert_key(dtrack, to - from, p); - } else if (default_anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { Quaternion r; - default_anim->rotation_track_interpolate(j, to, &r); + anim->rotation_track_interpolate(j, to, &r); new_anim->rotation_track_insert_key(dtrack, to - from, r); - } else if (default_anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { Vector3 s; - default_anim->scale_track_interpolate(j, to, &s); + anim->scale_track_interpolate(j, to, &s); new_anim->scale_track_insert_key(dtrack, to - from, s); - } else if (default_anim->track_get_type(j) == Animation::TYPE_VALUE) { - Variant var = default_anim->value_track_interpolate(j, to); + } else if (anim->track_get_type(j) == Animation::TYPE_VALUE) { + Variant var = anim->value_track_interpolate(j, to); new_anim->track_insert_key(dtrack, to - from, var); - } else if (default_anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { + } else if (anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { float interp; - default_anim->blend_shape_track_interpolate(j, to, &interp); + anim->blend_shape_track_interpolate(j, to, &interp); new_anim->blend_shape_track_insert_key(dtrack, to - from, interp); } } } if (dtrack == -1 && p_bake_all) { - new_anim->add_track(default_anim->track_get_type(j)); + new_anim->add_track(anim->track_get_type(j)); dtrack = new_anim->get_track_count() - 1; - new_anim->track_set_path(dtrack, default_anim->track_get_path(j)); - if (default_anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { + new_anim->track_set_path(dtrack, anim->track_get_path(j)); + if (anim->track_get_type(j) == Animation::TYPE_POSITION_3D) { Vector3 p; - default_anim->position_track_interpolate(j, from, &p); + anim->position_track_interpolate(j, from, &p); new_anim->position_track_insert_key(dtrack, 0, p); - default_anim->position_track_interpolate(j, to, &p); + anim->position_track_interpolate(j, to, &p); new_anim->position_track_insert_key(dtrack, to - from, p); - } else if (default_anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_ROTATION_3D) { Quaternion r; - default_anim->rotation_track_interpolate(j, from, &r); + anim->rotation_track_interpolate(j, from, &r); new_anim->rotation_track_insert_key(dtrack, 0, r); - default_anim->rotation_track_interpolate(j, to, &r); + anim->rotation_track_interpolate(j, to, &r); new_anim->rotation_track_insert_key(dtrack, to - from, r); - } else if (default_anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { + } else if (anim->track_get_type(j) == Animation::TYPE_SCALE_3D) { Vector3 s; - default_anim->scale_track_interpolate(j, from, &s); + anim->scale_track_interpolate(j, from, &s); new_anim->scale_track_insert_key(dtrack, 0, s); - default_anim->scale_track_interpolate(j, to, &s); + anim->scale_track_interpolate(j, to, &s); new_anim->scale_track_insert_key(dtrack, to - from, s); - } else if (default_anim->track_get_type(j) == Animation::TYPE_VALUE) { - Variant var = default_anim->value_track_interpolate(j, from); + } else if (anim->track_get_type(j) == Animation::TYPE_VALUE) { + Variant var = anim->value_track_interpolate(j, from); new_anim->track_insert_key(dtrack, 0, var); - Variant to_var = default_anim->value_track_interpolate(j, to); + Variant to_var = anim->value_track_interpolate(j, to); new_anim->track_insert_key(dtrack, to - from, to_var); - } else if (default_anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { + } else if (anim->track_get_type(j) == Animation::TYPE_BLEND_SHAPE) { float interp; - default_anim->blend_shape_track_interpolate(j, from, &interp); + anim->blend_shape_track_interpolate(j, from, &interp); new_anim->blend_shape_track_insert_key(dtrack, 0, interp); - default_anim->blend_shape_track_interpolate(j, to, &interp); + anim->blend_shape_track_interpolate(j, to, &interp); new_anim->blend_shape_track_insert_key(dtrack, to - from, interp); } } @@ -1562,7 +1562,7 @@ void ResourceImporterScene::_create_clips(AnimationPlayer *anim, const Array &p_ } } - al->remove_animation("default"); // Remove default (no longer needed). + al->remove_animation(ap->find_animation(anim)); // Remove original animation (no longer needed). } void ResourceImporterScene::_optimize_animations(AnimationPlayer *anim, float p_max_vel_error, float p_max_ang_error, int p_prc_error) { @@ -1642,6 +1642,17 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "save_to_file/path", PROPERTY_HINT_SAVE_FILE, "*.res,*.tres"), "")); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "save_to_file/keep_custom_tracks"), "")); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/amount", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0)); + + for (int i = 0; i < 256; i++) { + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/name"), "")); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/start_frame"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/end_frame"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Pingpong"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/save_to_file/path", PROPERTY_HINT_SAVE_FILE, ".res,*.tres"), "")); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"), false)); + } } break; case INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE: { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "import/skip_import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); @@ -1654,17 +1665,6 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_tracks/position", PROPERTY_HINT_ENUM, "IfPresent,IfPresentForAll,Never"), 1)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_tracks/rotation", PROPERTY_HINT_ENUM, "IfPresent,IfPresentForAll,Never"), 1)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "import_tracks/scale", PROPERTY_HINT_ENUM, "IfPresent,IfPresentForAll,Never"), 1)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slices/amount", PROPERTY_HINT_RANGE, "0,256,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0)); - - for (int i = 0; i < 256; i++) { - r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/name"), "")); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/start_frame"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/end_frame"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "slice_" + itos(i + 1) + "/loop_mode", PROPERTY_HINT_ENUM, "None,Linear,Pingpong"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); - r_options->push_back(ImportOption(PropertyInfo(Variant::STRING, "slice_" + itos(i + 1) + "/save_to_file/path", PROPERTY_HINT_SAVE_FILE, ".res,*.tres"), "")); - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "slice_" + itos(i + 1) + "/save_to_file/keep_custom_tracks"), false)); - } } break; case INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE: { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "import/skip_import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); @@ -1767,6 +1767,13 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor if (p_option == "save_to_file/path" || p_option == "save_to_file/keep_custom_tracks") { return p_options["save_to_file/enabled"]; } + if (p_option.begins_with("slice_")) { + int max_slice = p_options["slices/amount"]; + int slice = p_option.get_slice("_", 1).to_int() - 1; + if (slice >= max_slice) { + return false; + } + } } break; case INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE: { if (p_option.begins_with("optimizer/") && p_option != "optimizer/enabled" && !bool(p_options["optimizer/enabled"])) { @@ -1775,14 +1782,6 @@ bool ResourceImporterScene::get_internal_option_visibility(InternalImportCategor if (p_option.begins_with("compression/") && p_option != "compression/enabled" && !bool(p_options["compression/enabled"])) { return false; } - - if (p_option.begins_with("slice_")) { - int max_slice = p_options["slices/amount"]; - int slice = p_option.get_slice("_", 1).to_int() - 1; - if (slice >= max_slice) { - return false; - } - } } break; case INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE: { const bool use_retarget = p_options["retarget/bone_map"].get_validated_object() != nullptr; diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 77bc06533c..498e9f2964 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -35,11 +35,13 @@ #include "core/io/resource_importer.h" #include "core/variant/dictionary.h" #include "scene/3d/importer_mesh_instance_3d.h" -#include "scene/3d/node_3d.h" #include "scene/resources/animation.h" +#include "scene/resources/box_shape_3d.h" +#include "scene/resources/capsule_shape_3d.h" +#include "scene/resources/cylinder_shape_3d.h" #include "scene/resources/mesh.h" #include "scene/resources/shape_3d.h" -#include "scene/resources/skin.h" +#include "scene/resources/sphere_shape_3d.h" class Material; class AnimationPlayer; @@ -281,7 +283,7 @@ public: Node *_post_fix_animations(Node *p_node, Node *p_root, const Dictionary &p_node_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); + void _create_slices(AnimationPlayer *ap, Ref<Animation> anim, const Array &p_clips, bool p_bake_all); void _optimize_animations(AnimationPlayer *anim, float p_max_vel_error, float p_max_ang_error, int p_prc_error); void _compress_animations(AnimationPlayer *anim, int p_page_size_kb); @@ -311,11 +313,6 @@ public: 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" -#include "scene/resources/capsule_shape_3d.h" -#include "scene/resources/cylinder_shape_3d.h" -#include "scene/resources/sphere_shape_3d.h" - template <class M> Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<Mesh> &p_mesh, const M &p_options) { ShapeType generate_shape_type = SHAPE_TYPE_DECOMPOSE_CONVEX; diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index c06756ff0b..ed3f1ff489 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -233,7 +233,8 @@ void ResourceImporterTexture::get_import_options(const String &p_path, List<Impo 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)); - if (p_path.get_extension() == "svg") { + // Do path based customization only if a path was passed. + if (p_path.is_empty() || p_path.get_extension() == "svg") { r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "svg/scale", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 1.0)); // Editor use only, applies to SVG. @@ -669,23 +670,23 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String } if (r_metadata) { - Dictionary metadata; - metadata["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED; + Dictionary meta; + meta["vram_texture"] = compress_mode == COMPRESS_VRAM_COMPRESSED; if (formats_imported.size()) { - metadata["imported_formats"] = formats_imported; + meta["imported_formats"] = formats_imported; } if (editor_image.is_valid()) { - metadata["has_editor_variant"] = true; + meta["has_editor_variant"] = true; if (use_editor_scale) { - metadata["editor_scale"] = EDSCALE; + meta["editor_scale"] = EDSCALE; } if (convert_editor_colors) { - metadata["editor_dark_theme"] = EditorSettings::get_singleton()->is_dark_theme(); + meta["editor_dark_theme"] = EditorSettings::get_singleton()->is_dark_theme(); } } - *r_metadata = metadata; + *r_metadata = meta; } return OK; } @@ -715,29 +716,29 @@ String ResourceImporterTexture::get_import_settings_string() const { bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) const { //will become invalid if formats are missing to import - Dictionary metadata = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); + Dictionary meta = ResourceFormatImporter::get_singleton()->get_resource_metadata(p_path); - if (metadata.has("has_editor_variant")) { - if (metadata.has("editor_scale") && (float)metadata["editor_scale"] != EDSCALE) { + if (meta.has("has_editor_variant")) { + if (meta.has("editor_scale") && (float)meta["editor_scale"] != EDSCALE) { return false; } - if (metadata.has("editor_dark_theme") && (bool)metadata["editor_dark_theme"] != EditorSettings::get_singleton()->is_dark_theme()) { + if (meta.has("editor_dark_theme") && (bool)meta["editor_dark_theme"] != EditorSettings::get_singleton()->is_dark_theme()) { return false; } } - if (!metadata.has("vram_texture")) { + if (!meta.has("vram_texture")) { return false; } - bool vram = metadata["vram_texture"]; + bool vram = meta["vram_texture"]; if (!vram) { return true; // Do not care about non-VRAM. } Vector<String> formats_imported; - if (metadata.has("imported_formats")) { - formats_imported = metadata["imported_formats"]; + if (meta.has("imported_formats")) { + formats_imported = meta["imported_formats"]; } int index = 0; diff --git a/editor/import/resource_importer_texture_atlas.cpp b/editor/import/resource_importer_texture_atlas.cpp index 9171f04f42..bf22a9377e 100644 --- a/editor/import/resource_importer_texture_atlas.cpp +++ b/editor/import/resource_importer_texture_atlas.cpp @@ -273,9 +273,7 @@ Error ResourceImporterTextureAtlas::import_group_file(const String &p_group_file EditorAtlasPacker::chart_pack(charts, atlas_width, atlas_height); //blit the atlas - Ref<Image> new_atlas; - new_atlas.instantiate(); - new_atlas->create(atlas_width, atlas_height, false, Image::FORMAT_RGBA8); + Ref<Image> new_atlas = Image::create_empty(atlas_width, atlas_height, false, Image::FORMAT_RGBA8); for (int i = 0; i < pack_data_files.size(); i++) { PackData &pack_data = pack_data_files.write[i]; |