From 33e036b8c217c2b1092036d7979a078a030e4bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 1 Mar 2018 21:04:08 +0100 Subject: [PATCH] 2to3 exporter: Add a hack to convert rotation values in Animation tracks Fixes #16836. Also fix the missing renames for "playback/active" and "playback/speed". --- editor/editor_export_godot3.cpp | 50 ++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/editor/editor_export_godot3.cpp b/editor/editor_export_godot3.cpp index ce036b25a4e..86c9370e9dd 100644 --- a/editor/editor_export_godot3.cpp +++ b/editor/editor_export_godot3.cpp @@ -368,8 +368,11 @@ static const char *prop_renames[][2] = { { "geometry/depth_scale", "use_depth_scale" }, { "geometry/visible_in_all_rooms", "visible_in_all_rooms" }, { "geometry/use_baked_light", "use_in_baked_light" }, - { "playback/process_mode", "playback_process_mode" }, + // Properly renamed for AnimationPlayer, but not AnimationTreePlayer, so handle manually + //{ "playback/active", "playback_active" }, { "playback/default_blend_time", "playback_default_blend_time" }, + { "playback/process_mode", "playback_process_mode" }, + { "playback/speed", "playback_speed" }, { "root/root", "root_node" }, { "stream/stream", "stream" }, { "stream/play", "playing" }, @@ -527,8 +530,21 @@ void EditorExportGodot3::_find_files(EditorFileSystemDirectory *p_dir, List *p_props) { + // To fix 2D rotations in the properties of Animation tracks (see below), + // we need to locate stuff like this: + // tracks/0/path = NodePath("Sprite:transform/rot") + // And then modify the 'values' key of 'tracks/0/keys'. + // This is going to be hacky. + // We'll assume that we get properties in the correct order, so that the path will come before the keys + // Otherwise we'd have to keep a stack of the track keys we found to later compare them to track paths + // that match rotation_deg... + bool fix_animation_rotation = (p_type == "Animation"); + String found_track_number = ""; + for (List::Element *E = p_props->front(); E; E = E->next()) { + /* Fixes for 2D rotations */ + // 2D rotations are now clockwise to match the downward Y base // Do this before the renaming, as afterwards we can't distinguish // between 2D and 3D rotations_degrees @@ -536,6 +552,31 @@ void EditorExportGodot3::_rename_properties(const String &p_type, Listget().value = E->get().value.operator real_t() * -1.0; } + if (fix_animation_rotation) { + String prop_name = E->get().name; + if (prop_name.begins_with("tracks/") && prop_name.ends_with("/path")) { + String path_value = E->get().value; + if (path_value.find("transform/rot") != 1) { + // We found a track 'path' with a "transform/rot" NodePath, its 'keys' need to be fixed + found_track_number = prop_name.substr(prop_name.find("/path") - 1, 1); + } + } else if (found_track_number != "" && prop_name.begins_with("tracks/") && prop_name.ends_with("/keys") && prop_name.find(found_track_number) != -1) { + // Bingo! We found keys matching the track number we had spotted + print_line("Found Animation track with 2D rotations, fixing their sign."); + Dictionary track_keys = E->get().value; + if (track_keys.has("values")) { + Array values = track_keys["values"]; + for (int i = 0; i < values.size(); i++) { + values[i] = values[i].operator real_t() * -1.0; + } + track_keys["values"] = values; + E->get().value = track_keys; + } else { + print_line("Tried to change rotation in Animation tracks, but no value set found."); + } + } + } + /* Do the actual renaming */ if (prop_rename_map.has(E->get().name)) { @@ -556,6 +597,13 @@ void EditorExportGodot3::_rename_properties(const String &p_type, Listget().value = 2; } } + + // AnimationPlayer's "playback/active" was renamed to "playback_active", but not AnimationTrrePlayer's + // We rename manually only for AnimationPlayer + if (E->get().name == "playback/active" && p_type == "AnimationPlayer") { + print_line("yep"); + E->get().name = "playback_active"; + } } }