|
|
@@ -36,6 +36,12 @@
|
|
|
#include "os/keyboard.h"
|
|
|
#include "project_settings.h"
|
|
|
|
|
|
+// For onion skinning
|
|
|
+#include "editor/plugins/canvas_item_editor_plugin.h"
|
|
|
+#include "editor/plugins/spatial_editor_plugin.h"
|
|
|
+#include "scene/main/viewport.h"
|
|
|
+#include "servers/visual_server.h"
|
|
|
+
|
|
|
void AnimationPlayerEditor::_node_removed(Node *p_node) {
|
|
|
|
|
|
if (player && player == p_node) {
|
|
|
@@ -98,6 +104,8 @@ void AnimationPlayerEditor::_notification(int p_what) {
|
|
|
|
|
|
tool_anim->get_popup()->connect("id_pressed", this, "_animation_tool_menu");
|
|
|
|
|
|
+ onion_skinning->get_popup()->connect("id_pressed", this, "_onion_skinning_menu");
|
|
|
+
|
|
|
blend_editor.next->connect("item_selected", this, "_blend_editor_next_changed");
|
|
|
|
|
|
get_tree()->connect("node_removed", this, "_node_removed");
|
|
|
@@ -132,6 +140,7 @@ void AnimationPlayerEditor::_notification(int p_what) {
|
|
|
resource_edit_anim->set_icon(get_icon("EditResource", "EditorIcons"));
|
|
|
pin->set_icon(get_icon("Pin", "EditorIcons"));
|
|
|
tool_anim->set_icon(get_icon("Tools", "EditorIcons"));
|
|
|
+ onion_skinning->set_icon(get_icon("Onion", "EditorIcons"));
|
|
|
|
|
|
} break;
|
|
|
}
|
|
|
@@ -809,6 +818,7 @@ void AnimationPlayerEditor::_update_player() {
|
|
|
resource_edit_anim->set_disabled(animlist.size() == 0);
|
|
|
save_anim->set_disabled(animlist.size() == 0);
|
|
|
tool_anim->set_disabled(player == NULL);
|
|
|
+ onion_skinning->set_disabled(player == NULL);
|
|
|
|
|
|
int active_idx = -1;
|
|
|
for (List<StringName>::Element *E = animlist.front(); E; E = E->next()) {
|
|
|
@@ -855,6 +865,9 @@ void AnimationPlayerEditor::_update_player() {
|
|
|
|
|
|
void AnimationPlayerEditor::edit(AnimationPlayer *p_player) {
|
|
|
|
|
|
+ if (onion.enabled)
|
|
|
+ _start_onion_skinning();
|
|
|
+
|
|
|
if (player && pin->is_pressed())
|
|
|
return; //ignore, pinned
|
|
|
player = p_player;
|
|
|
@@ -869,6 +882,55 @@ void AnimationPlayerEditor::edit(AnimationPlayer *p_player) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void AnimationPlayerEditor::forward_force_draw_over_viewport(Control *p_overlay) {
|
|
|
+
|
|
|
+ if (!onion.can_overlay)
|
|
|
+ return;
|
|
|
+
|
|
|
+ // Can happen on viewport resize, at least
|
|
|
+ if (!_are_onion_layers_valid())
|
|
|
+ return;
|
|
|
+
|
|
|
+ RID ci = p_overlay->get_canvas_item();
|
|
|
+ Rect2 src_rect = p_overlay->get_global_rect();
|
|
|
+ // Re-flip since captures are already flipped
|
|
|
+ src_rect.position.y = onion.capture_size.y - (src_rect.position.y + src_rect.size.y);
|
|
|
+ src_rect.size.y *= -1;
|
|
|
+
|
|
|
+ Rect2 dst_rect = Rect2(Point2(), p_overlay->get_size());
|
|
|
+
|
|
|
+ float alpha_step = 1.0 / (onion.steps + 1);
|
|
|
+
|
|
|
+ int cidx = 0;
|
|
|
+ if (onion.past) {
|
|
|
+ float alpha = 0;
|
|
|
+ do {
|
|
|
+ alpha += alpha_step;
|
|
|
+
|
|
|
+ if (onion.captures_valid[cidx]) {
|
|
|
+ VS::get_singleton()->canvas_item_add_texture_rect_region(
|
|
|
+ ci, dst_rect, VS::get_singleton()->viewport_get_texture(onion.captures[cidx]), src_rect, Color(1, 1, 1, alpha));
|
|
|
+ }
|
|
|
+
|
|
|
+ cidx++;
|
|
|
+ } while (cidx < onion.steps);
|
|
|
+ }
|
|
|
+ if (onion.future) {
|
|
|
+ float alpha = 1;
|
|
|
+ int base_cidx = cidx;
|
|
|
+ do {
|
|
|
+ alpha -= alpha_step;
|
|
|
+
|
|
|
+ if (onion.captures_valid[cidx]) {
|
|
|
+ VS::get_singleton()->canvas_item_add_texture_rect_region(
|
|
|
+ ci, dst_rect, VS::get_singleton()->viewport_get_texture(onion.captures[cidx]), src_rect, Color(1, 1, 1, alpha));
|
|
|
+ }
|
|
|
+
|
|
|
+ cidx++;
|
|
|
+ } while (cidx < base_cidx + onion.steps); // In case there's the present capture at the end, skip it
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void AnimationPlayerEditor::_animation_duplicate() {
|
|
|
|
|
|
if (!animation->get_item_count())
|
|
|
@@ -1100,6 +1162,70 @@ void AnimationPlayerEditor::_animation_save_menu(int p_option) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void AnimationPlayerEditor::_onion_skinning_menu(int p_option) {
|
|
|
+
|
|
|
+ PopupMenu *menu = onion_skinning->get_popup();
|
|
|
+ int idx = menu->get_item_index(p_option);
|
|
|
+
|
|
|
+ switch (p_option) {
|
|
|
+
|
|
|
+ case ONION_SKINNING_ENABLE: {
|
|
|
+
|
|
|
+ onion.enabled = !onion.enabled;
|
|
|
+ menu->set_item_checked(idx, onion.enabled);
|
|
|
+
|
|
|
+ if (onion.enabled)
|
|
|
+ _start_onion_skinning();
|
|
|
+ else
|
|
|
+ _stop_onion_skinning();
|
|
|
+
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_PAST: {
|
|
|
+
|
|
|
+ // Ensure at least one of past/future is checjed
|
|
|
+ onion.past = onion.future ? !onion.past : true;
|
|
|
+ menu->set_item_checked(idx, onion.past);
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_FUTURE: {
|
|
|
+
|
|
|
+ // Ensure at least one of past/future is checjed
|
|
|
+ onion.future = onion.past ? !onion.future : true;
|
|
|
+ menu->set_item_checked(idx, onion.future);
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_1_STEP: // Fall-through
|
|
|
+ case ONION_SKINNING_2_STEPS:
|
|
|
+ case ONION_SKINNING_3_STEPS: {
|
|
|
+
|
|
|
+ onion.steps = (p_option - ONION_SKINNING_1_STEP) + 1;
|
|
|
+ int one_frame_idx = menu->get_item_index(ONION_SKINNING_1_STEP);
|
|
|
+ for (int i = 0; i <= ONION_SKINNING_LAST_STEPS_OPTION - ONION_SKINNING_1_STEP; i++) {
|
|
|
+ menu->set_item_checked(one_frame_idx + i, onion.steps == i + 1);
|
|
|
+ }
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_DIFFERENCES_ONLY: {
|
|
|
+
|
|
|
+ onion.differences_only = !onion.differences_only;
|
|
|
+ menu->set_item_checked(idx, onion.differences_only);
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_FORCE_WHITE_MODULATE: {
|
|
|
+
|
|
|
+ onion.force_white_modulate = !onion.force_white_modulate;
|
|
|
+ menu->set_item_checked(idx, onion.force_white_modulate);
|
|
|
+ } break;
|
|
|
+
|
|
|
+ case ONION_SKINNING_INCLUDE_GIZMOS: {
|
|
|
+
|
|
|
+ onion.include_gizmos = !onion.include_gizmos;
|
|
|
+ menu->set_item_checked(idx, onion.include_gizmos);
|
|
|
+ } break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
|
|
|
|
|
|
Ref<InputEventKey> k = p_ev;
|
|
|
@@ -1126,6 +1252,237 @@ void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void AnimationPlayerEditor::_editor_visibility_changed() {
|
|
|
+
|
|
|
+ if (is_visible()) {
|
|
|
+ _start_onion_skinning();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+bool AnimationPlayerEditor::_are_onion_layers_valid() {
|
|
|
+
|
|
|
+ ERR_FAIL_COND_V(!onion.past && !onion.future, false);
|
|
|
+
|
|
|
+ Point2 capture_size = get_tree()->get_root()->get_size();
|
|
|
+ return onion.captures.size() == onion.get_needed_capture_count() && onion.capture_size == capture_size;
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_allocate_onion_layers() {
|
|
|
+
|
|
|
+ _free_onion_layers();
|
|
|
+
|
|
|
+ int captures = onion.get_needed_capture_count();
|
|
|
+ Point2 capture_size = get_tree()->get_root()->get_size();
|
|
|
+
|
|
|
+ onion.captures.resize(captures);
|
|
|
+ onion.captures_valid.resize(captures);
|
|
|
+
|
|
|
+ for (int i = 0; i < captures; i++) {
|
|
|
+ bool is_present = onion.differences_only && i == captures - 1;
|
|
|
+
|
|
|
+ // Each capture is a viewport with a canvas item attached that renders a full-size rect with the contents of the main viewport
|
|
|
+ onion.captures[i] = VS::get_singleton()->viewport_create();
|
|
|
+ VS::get_singleton()->viewport_set_usage(onion.captures[i], VS::VIEWPORT_USAGE_2D);
|
|
|
+ VS::get_singleton()->viewport_set_size(onion.captures[i], capture_size.width, capture_size.height);
|
|
|
+ VS::get_singleton()->viewport_set_update_mode(onion.captures[i], VS::VIEWPORT_UPDATE_ALWAYS);
|
|
|
+ VS::get_singleton()->viewport_set_transparent_background(onion.captures[i], !is_present);
|
|
|
+ VS::get_singleton()->viewport_set_vflip(onion.captures[i], true);
|
|
|
+ VS::get_singleton()->viewport_attach_canvas(onion.captures[i], onion.capture.canvas);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Reset the capture canvas item to the current root viewport texture (defensive)
|
|
|
+ VS::get_singleton()->canvas_item_clear(onion.capture.canvas_item);
|
|
|
+ VS::get_singleton()->canvas_item_add_texture_rect(onion.capture.canvas_item, Rect2(Point2(), capture_size), get_tree()->get_root()->get_texture()->get_rid());
|
|
|
+
|
|
|
+ onion.capture_size = capture_size;
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_free_onion_layers() {
|
|
|
+
|
|
|
+ for (int i = 0; i < onion.captures.size(); i++) {
|
|
|
+ if (onion.captures[i].is_valid()) {
|
|
|
+ VS::get_singleton()->free(onion.captures[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ onion.captures.clear();
|
|
|
+ onion.captures_valid.clear();
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_prepare_onion_layers_1() {
|
|
|
+
|
|
|
+ // This would be called per viewport and we want to act once only
|
|
|
+ int64_t frame = get_tree()->get_frame();
|
|
|
+ if (frame == onion.last_frame)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (!onion.enabled || !is_processing() || !is_visible() || !get_player()) {
|
|
|
+ _stop_onion_skinning();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ onion.last_frame = frame;
|
|
|
+
|
|
|
+ // Refresh viewports with no onion layers overlaid
|
|
|
+ onion.can_overlay = false;
|
|
|
+ plugin->update_overlays();
|
|
|
+
|
|
|
+ if (player->is_playing())
|
|
|
+ return;
|
|
|
+
|
|
|
+ // And go to next step afterwards
|
|
|
+ call_deferred("_prepare_onion_layers_2");
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_prepare_onion_layers_2() {
|
|
|
+
|
|
|
+ Ref<Animation> anim = player->get_animation(player->get_current_animation());
|
|
|
+ if (!anim.is_valid())
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (!_are_onion_layers_valid())
|
|
|
+ _allocate_onion_layers();
|
|
|
+
|
|
|
+ // Hide superfluous elements that would make the overlay unnecessary cluttered
|
|
|
+ Dictionary canvas_edit_state;
|
|
|
+ Dictionary spatial_edit_state;
|
|
|
+ if (SpatialEditor::get_singleton()->is_visible()) {
|
|
|
+ // 3D
|
|
|
+ spatial_edit_state = SpatialEditor::get_singleton()->get_state();
|
|
|
+ Dictionary new_state = spatial_edit_state.copy();
|
|
|
+ new_state["show_grid"] = false;
|
|
|
+ new_state["show_origin"] = false;
|
|
|
+ Array orig_vp = spatial_edit_state["viewports"];
|
|
|
+ Array vp;
|
|
|
+ vp.resize(4);
|
|
|
+ for (int i = 0; i < vp.size(); i++) {
|
|
|
+ Dictionary d = ((Dictionary)orig_vp[i]).copy();
|
|
|
+ d["use_environment"] = false;
|
|
|
+ d["doppler"] = false;
|
|
|
+ d["gizmos"] = onion.include_gizmos ? d["gizmos"] : Variant(false);
|
|
|
+ d["information"] = false;
|
|
|
+ vp[i] = d;
|
|
|
+ }
|
|
|
+ new_state["viewports"] = vp;
|
|
|
+ // TODO: Save/restore only affected entries
|
|
|
+ SpatialEditor::get_singleton()->set_state(new_state);
|
|
|
+ } else { // CanvasItemEditor
|
|
|
+ // 2D
|
|
|
+ canvas_edit_state = CanvasItemEditor::get_singleton()->get_state();
|
|
|
+ Dictionary new_state = canvas_edit_state.copy();
|
|
|
+ new_state["show_grid"] = false;
|
|
|
+ new_state["show_rulers"] = false;
|
|
|
+ new_state["show_guides"] = false;
|
|
|
+ new_state["show_helpers"] = false;
|
|
|
+ // TODO: Save/restore only affected entries
|
|
|
+ CanvasItemEditor::get_singleton()->set_state(new_state);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Tweak the root viewport to ensure it's rendered before our target
|
|
|
+ RID root_vp = get_tree()->get_root()->get_viewport_rid();
|
|
|
+ Rect2 root_vp_screen_rect = get_tree()->get_root()->get_attach_to_screen_rect();
|
|
|
+ VS::get_singleton()->viewport_attach_to_screen(root_vp, Rect2());
|
|
|
+ VS::get_singleton()->viewport_set_update_mode(root_vp, VS::VIEWPORT_UPDATE_ALWAYS);
|
|
|
+
|
|
|
+ RID present_rid;
|
|
|
+ if (onion.differences_only) {
|
|
|
+ // Capture present scene as it is
|
|
|
+ VS::get_singleton()->canvas_item_set_material(onion.capture.canvas_item, RID());
|
|
|
+ present_rid = onion.captures[onion.captures.size() - 1];
|
|
|
+ VS::get_singleton()->viewport_set_active(present_rid, true);
|
|
|
+ VS::get_singleton()->viewport_set_parent_viewport(root_vp, present_rid);
|
|
|
+ VS::get_singleton()->draw(false);
|
|
|
+ VS::get_singleton()->viewport_set_active(present_rid, false);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Backup current animation state
|
|
|
+ AnimatedValuesBackup values_backup = player->backup_animated_values();
|
|
|
+ float cpos = player->get_current_animation_position();
|
|
|
+
|
|
|
+ // Render every past/future step with the capture shader
|
|
|
+
|
|
|
+ VS::get_singleton()->canvas_item_set_material(onion.capture.canvas_item, onion.capture.material->get_rid());
|
|
|
+ onion.capture.material->set_shader_param("bkg_color", GLOBAL_GET("rendering/environment/default_clear_color"));
|
|
|
+ onion.capture.material->set_shader_param("differences_only", onion.differences_only);
|
|
|
+ onion.capture.material->set_shader_param("present", onion.differences_only ? VS::get_singleton()->viewport_get_texture(present_rid) : RID());
|
|
|
+
|
|
|
+ int step_off_a = onion.past ? -onion.steps : 0;
|
|
|
+ int step_off_b = onion.future ? onion.steps : 0;
|
|
|
+ int cidx = 0;
|
|
|
+ onion.capture.material->set_shader_param("dir_color", onion.force_white_modulate ? Color(1, 1, 1) : Color(EDITOR_GET("editors/animation/onion_layers_past_color")));
|
|
|
+ for (int step_off = step_off_a; step_off <= step_off_b; step_off++) {
|
|
|
+
|
|
|
+ if (step_off == 0) {
|
|
|
+ // Skip present step and switch to the color of future
|
|
|
+ if (!onion.force_white_modulate)
|
|
|
+ onion.capture.material->set_shader_param("dir_color", EDITOR_GET("editors/animation/onion_layers_future_color"));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ float pos = cpos + step_off * anim->get_step();
|
|
|
+
|
|
|
+ bool valid = anim->has_loop() || pos >= 0 && pos <= anim->get_length();
|
|
|
+ onion.captures_valid[cidx] = valid;
|
|
|
+ if (valid) {
|
|
|
+ player->seek(pos, true);
|
|
|
+ get_tree()->flush_transform_notifications(); // Needed for transforms of Spatials
|
|
|
+ values_backup.update_skeletons(); // Needed for Skeletons
|
|
|
+
|
|
|
+ VS::get_singleton()->viewport_set_active(onion.captures[cidx], true);
|
|
|
+ VS::get_singleton()->viewport_set_parent_viewport(root_vp, onion.captures[cidx]);
|
|
|
+ VS::get_singleton()->draw(false);
|
|
|
+ VS::get_singleton()->viewport_set_active(onion.captures[cidx], false);
|
|
|
+ }
|
|
|
+
|
|
|
+ cidx++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Restore root viewport
|
|
|
+ VS::get_singleton()->viewport_set_parent_viewport(root_vp, RID());
|
|
|
+ VS::get_singleton()->viewport_attach_to_screen(root_vp, root_vp_screen_rect);
|
|
|
+ VS::get_singleton()->viewport_set_update_mode(root_vp, VS::VIEWPORT_UPDATE_WHEN_VISIBLE);
|
|
|
+
|
|
|
+ // Restore animation state
|
|
|
+ // (Seeking with update=true wouldn't do the trick because the current value of the properties
|
|
|
+ // may not match their value for the current point in the animation)
|
|
|
+ player->seek(cpos, false);
|
|
|
+ player->restore_animated_values(values_backup);
|
|
|
+
|
|
|
+ // Restor state of main editors
|
|
|
+ if (SpatialEditor::get_singleton()->is_visible()) {
|
|
|
+ // 3D
|
|
|
+ SpatialEditor::get_singleton()->set_state(spatial_edit_state);
|
|
|
+ } else { // CanvasItemEditor
|
|
|
+ // 2D
|
|
|
+ CanvasItemEditor::get_singleton()->set_state(canvas_edit_state);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Update viewports with skin layers overlaid for the actual engine loop render
|
|
|
+ onion.can_overlay = true;
|
|
|
+ plugin->update_overlays();
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_start_onion_skinning() {
|
|
|
+
|
|
|
+ // FIXME: Using "idle_frame" makes onion layers update one frame behing the current
|
|
|
+ if (!get_tree()->is_connected("idle_frame", this, "call_deferred")) {
|
|
|
+ get_tree()->connect("idle_frame", this, "call_deferred", varray("_prepare_onion_layers_1"));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditor::_stop_onion_skinning() {
|
|
|
+
|
|
|
+ if (get_tree()->is_connected("idle_frame", this, "call_deferred")) {
|
|
|
+
|
|
|
+ get_tree()->disconnect("idle_frame", this, "call_deferred");
|
|
|
+
|
|
|
+ _free_onion_layers();
|
|
|
+
|
|
|
+ // Clean up the overlay
|
|
|
+ onion.can_overlay = false;
|
|
|
+ plugin->update_overlays();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void AnimationPlayerEditor::_bind_methods() {
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &AnimationPlayerEditor::_gui_input);
|
|
|
@@ -1165,6 +1522,10 @@ void AnimationPlayerEditor::_bind_methods() {
|
|
|
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &AnimationPlayerEditor::_unhandled_key_input);
|
|
|
ClassDB::bind_method(D_METHOD("_animation_tool_menu"), &AnimationPlayerEditor::_animation_tool_menu);
|
|
|
ClassDB::bind_method(D_METHOD("_animation_save_menu"), &AnimationPlayerEditor::_animation_save_menu);
|
|
|
+ ClassDB::bind_method(D_METHOD("_onion_skinning_menu"), &AnimationPlayerEditor::_onion_skinning_menu);
|
|
|
+ ClassDB::bind_method(D_METHOD("_editor_visibility_changed"), &AnimationPlayerEditor::_editor_visibility_changed);
|
|
|
+ ClassDB::bind_method(D_METHOD("_prepare_onion_layers_1"), &AnimationPlayerEditor::_prepare_onion_layers_1);
|
|
|
+ ClassDB::bind_method(D_METHOD("_prepare_onion_layers_2"), &AnimationPlayerEditor::_prepare_onion_layers_2);
|
|
|
}
|
|
|
|
|
|
AnimationPlayerEditor *AnimationPlayerEditor::singleton = NULL;
|
|
|
@@ -1173,8 +1534,10 @@ AnimationPlayer *AnimationPlayerEditor::get_player() const {
|
|
|
|
|
|
return player;
|
|
|
}
|
|
|
-AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
|
|
|
+
|
|
|
+AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlayerEditorPlugin *p_plugin) {
|
|
|
editor = p_editor;
|
|
|
+ plugin = p_plugin;
|
|
|
singleton = this;
|
|
|
|
|
|
updating = false;
|
|
|
@@ -1301,6 +1664,29 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
|
|
|
//tool_anim->get_popup()->add_item("Edit Anim Resource",TOOL_PASTE_ANIM);
|
|
|
hb->add_child(tool_anim);
|
|
|
|
|
|
+ onion_skinning = memnew(MenuButton);
|
|
|
+ //onion_skinning->set_flat(false);
|
|
|
+ onion_skinning->set_tooltip(TTR("Onion Skinning"));
|
|
|
+ onion_skinning->get_popup()->add_check_shortcut(ED_SHORTCUT("animation_player_editor/onion_skinning", TTR("Enable Onion Skinning")), ONION_SKINNING_ENABLE);
|
|
|
+ onion_skinning->get_popup()->add_separator();
|
|
|
+ onion_skinning->get_popup()->add_item(TTR("Directions"), -1);
|
|
|
+ onion_skinning->get_popup()->set_item_disabled(onion_skinning->get_popup()->get_item_count() - 1, true);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("Past"), ONION_SKINNING_PAST);
|
|
|
+ onion_skinning->get_popup()->set_item_checked(onion_skinning->get_popup()->get_item_count() - 1, true);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("Future"), ONION_SKINNING_FUTURE);
|
|
|
+ onion_skinning->get_popup()->add_separator();
|
|
|
+ onion_skinning->get_popup()->add_item(TTR("Depth"), -1);
|
|
|
+ onion_skinning->get_popup()->set_item_disabled(onion_skinning->get_popup()->get_item_count() - 1, true);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("1 step"), ONION_SKINNING_1_STEP);
|
|
|
+ onion_skinning->get_popup()->set_item_checked(onion_skinning->get_popup()->get_item_count() - 1, true);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("2 steps"), ONION_SKINNING_2_STEPS);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("3 steps"), ONION_SKINNING_3_STEPS);
|
|
|
+ onion_skinning->get_popup()->add_separator();
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("Differences Only"), ONION_SKINNING_DIFFERENCES_ONLY);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("Force White Modulate"), ONION_SKINNING_FORCE_WHITE_MODULATE);
|
|
|
+ onion_skinning->get_popup()->add_check_item(TTR("Include Gizmos (3D)"), ONION_SKINNING_INCLUDE_GIZMOS);
|
|
|
+ hb->add_child(onion_skinning);
|
|
|
+
|
|
|
pin = memnew(ToolButton);
|
|
|
pin->set_toggle_mode(true);
|
|
|
hb->add_child(pin);
|
|
|
@@ -1387,6 +1773,68 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
|
|
|
key_editor->connect("animation_step_changed", this, "_animation_key_editor_anim_step_changed");
|
|
|
|
|
|
_update_player();
|
|
|
+
|
|
|
+ // Onion skinning
|
|
|
+
|
|
|
+ key_editor->connect("visibility_changed", this, "_editor_visibility_changed");
|
|
|
+
|
|
|
+ onion.enabled = false;
|
|
|
+ onion.past = true;
|
|
|
+ onion.future = false;
|
|
|
+ onion.steps = 1;
|
|
|
+ onion.differences_only = false;
|
|
|
+ onion.force_white_modulate = false;
|
|
|
+ onion.include_gizmos = false;
|
|
|
+
|
|
|
+ onion.last_frame = 0;
|
|
|
+ onion.can_overlay = false;
|
|
|
+ onion.capture_size = Size2();
|
|
|
+ onion.capture.canvas = VS::get_singleton()->canvas_create();
|
|
|
+ onion.capture.canvas_item = VS::get_singleton()->canvas_item_create();
|
|
|
+ VS::get_singleton()->canvas_item_set_parent(onion.capture.canvas_item, onion.capture.canvas);
|
|
|
+
|
|
|
+ onion.capture.material = Ref<ShaderMaterial>(memnew(ShaderMaterial));
|
|
|
+
|
|
|
+ onion.capture.shader = Ref<Shader>(memnew(Shader));
|
|
|
+ onion.capture.shader->set_code(" \
|
|
|
+ shader_type canvas_item; \
|
|
|
+ \
|
|
|
+ uniform vec4 bkg_color; \
|
|
|
+ uniform vec4 dir_color; \
|
|
|
+ uniform bool differences_only; \
|
|
|
+ uniform sampler2D present; \
|
|
|
+ \
|
|
|
+ float zero_if_equal(vec4 a, vec4 b) { \
|
|
|
+ return smoothstep(0.0, 0.005, length(a.rgb - b.rgb) / sqrt(3.0)); \
|
|
|
+ } \
|
|
|
+ \
|
|
|
+ void fragment() { \
|
|
|
+ vec4 capture_samp = texture(TEXTURE, UV); \
|
|
|
+ vec4 present_samp = texture(present, UV); \
|
|
|
+ float bkg_mask = zero_if_equal(capture_samp, bkg_color); \
|
|
|
+ float diff_mask = 1.0 - zero_if_equal(present_samp, bkg_color); \
|
|
|
+ diff_mask = min(1.0, diff_mask + float(!differences_only)); \
|
|
|
+ COLOR = vec4(capture_samp.rgb * dir_color.rgb, bkg_mask * diff_mask); \
|
|
|
+ } \
|
|
|
+ ");
|
|
|
+ VS::get_singleton()->material_set_shader(onion.capture.material->get_rid(), onion.capture.shader->get_rid());
|
|
|
+}
|
|
|
+
|
|
|
+AnimationPlayerEditor::~AnimationPlayerEditor() {
|
|
|
+
|
|
|
+ _free_onion_layers();
|
|
|
+ VS::get_singleton()->free(onion.capture.canvas);
|
|
|
+ VS::get_singleton()->free(onion.capture.canvas_item);
|
|
|
+}
|
|
|
+
|
|
|
+void AnimationPlayerEditorPlugin::_notification(int p_what) {
|
|
|
+
|
|
|
+ switch (p_what) {
|
|
|
+ case NOTIFICATION_ENTER_TREE: {
|
|
|
+
|
|
|
+ set_force_draw_over_forwarding_enabled();
|
|
|
+ } break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void AnimationPlayerEditorPlugin::edit(Object *p_object) {
|
|
|
@@ -1420,7 +1868,7 @@ void AnimationPlayerEditorPlugin::make_visible(bool p_visible) {
|
|
|
AnimationPlayerEditorPlugin::AnimationPlayerEditorPlugin(EditorNode *p_node) {
|
|
|
|
|
|
editor = p_node;
|
|
|
- anim_editor = memnew(AnimationPlayerEditor(editor));
|
|
|
+ anim_editor = memnew(AnimationPlayerEditor(editor, this));
|
|
|
anim_editor->set_undo_redo(editor->get_undo_redo());
|
|
|
|
|
|
editor->add_bottom_panel_item(TTR("Animation"), anim_editor);
|