Fix issues with custom tracks on reimport

(cherry picked from commit 4313a7bdc8)
This commit is contained in:
lordkettune 2020-06-29 19:10:18 -07:00 committed by Rémi Verschelde
parent 4c54f39dbe
commit c68ef4d754
2 changed files with 8 additions and 7 deletions

View File

@ -973,10 +973,9 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
ERR_CONTINUE(anim.is_null()); ERR_CONTINUE(anim.is_null());
if (!p_animations.has(anim)) { if (!p_animations.has(anim)) {
// Tracks from source file should be set as imported, anything else is a custom track.
// We are making external files so they are modifiable
for (int i = 0; i < anim->get_track_count(); i++) { for (int i = 0; i < anim->get_track_count(); i++) {
anim->track_set_imported(i, false); anim->track_set_imported(i, true);
} }
String ext_name; String ext_name;
@ -988,10 +987,9 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
} }
if (FileAccess::exists(ext_name) && p_keep_animations) { if (FileAccess::exists(ext_name) && p_keep_animations) {
//try to keep custom animation tracks // Copy custom animation tracks from previously imported files.
Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true); Ref<Animation> old_anim = ResourceLoader::load(ext_name, "Animation", true);
if (old_anim.is_valid()) { if (old_anim.is_valid()) {
//meergeee
for (int i = 0; i < old_anim->get_track_count(); i++) { for (int i = 0; i < old_anim->get_track_count(); i++) {
if (!old_anim->track_is_imported(i)) { if (!old_anim->track_is_imported(i)) {
old_anim->copy_track(i, anim); old_anim->copy_track(i, anim);
@ -1001,7 +999,7 @@ void ResourceImporterScene::_make_external_resources(Node *p_node, const String
} }
} }
anim->set_path(ext_name, true); //if not set, then its never saved externally anim->set_path(ext_name, true); // Set path to save externally.
ResourceSaver::save(ext_name, anim, ResourceSaver::FLAG_CHANGE_PATH); ResourceSaver::save(ext_name, anim, ResourceSaver::FLAG_CHANGE_PATH);
p_animations[anim] = anim; p_animations[anim] = anim;
} }

View File

@ -2732,7 +2732,10 @@ void Animation::copy_track(int p_track, Ref<Animation> p_to_animation) {
p_to_animation->track_set_enabled(dst_track, track_is_enabled(p_track)); p_to_animation->track_set_enabled(dst_track, track_is_enabled(p_track));
p_to_animation->track_set_interpolation_type(dst_track, track_get_interpolation_type(p_track)); p_to_animation->track_set_interpolation_type(dst_track, track_get_interpolation_type(p_track));
p_to_animation->track_set_interpolation_loop_wrap(dst_track, track_get_interpolation_loop_wrap(p_track)); p_to_animation->track_set_interpolation_loop_wrap(dst_track, track_get_interpolation_loop_wrap(p_track));
if (track_get_type(p_track) == TYPE_VALUE) {
p_to_animation->value_track_set_update_mode(dst_track, value_track_get_update_mode(p_track)); p_to_animation->value_track_set_update_mode(dst_track, value_track_get_update_mode(p_track));
}
for (int i = 0; i < track_get_key_count(p_track); i++) { for (int i = 0; i < track_get_key_count(p_track); i++) {
p_to_animation->track_insert_key(dst_track, track_get_key_time(p_track, i), track_get_key_value(p_track, i), track_get_key_transition(p_track, i)); p_to_animation->track_insert_key(dst_track, track_get_key_time(p_track, i), track_get_key_value(p_track, i), track_get_key_transition(p_track, i));
} }