-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node searcher zoom & edited node growth/shrink animation #3327
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2d0420c
Reverting commit 0836ce741d7e9c69e9ded088fdb567b535bcebca
vitvakatu 284211b
Merge branch 'develop' into wip/vitvakatu/revert-adding-node
vitvakatu bdcdeca
fix clippy warnings about missing docs
vitvakatu aa3eaa1
Implement edited node growth/shrink animation and fixed searcher zoom
vitvakatu 21bc3b6
fixes after merge
vitvakatu 43c2920
Additional fixes
vitvakatu 72c848d
self-review, expand docs
vitvakatu d2a1f28
Merge branch 'develop' into wip/vitvakatu/searcher-zoom-181181221
vitvakatu 4d62004
slightly adjust formatting
vitvakatu dfae133
update changelog
vitvakatu 930400a
Refactor growth/shrink animation to a separate module
vitvakatu 0dd3bac
Merge branch 'develop' into wip/vitvakatu/searcher-zoom-181181221
vitvakatu 7db923a
Various review fixes
vitvakatu 437758a
Simplify shrinking animation implementation
vitvakatu 9673a0e
Merge branch 'develop' into wip/vitvakatu/searcher-zoom-181181221
vitvakatu 2ee7236
Merge branch 'develop' into wip/vitvakatu/searcher-zoom-181181221
vitvakatu 68a9470
Implement flexible animation duration
vitvakatu 1bc10c6
Fix formatting
vitvakatu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
app/gui/view/graph-editor/src/component/node/growth_animation.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//! Edited node growth/shrink animation implementation. | ||
//! | ||
//! When the user starts editing of the node - it smoothly growth in size to match the 1.0x zoom | ||
//! factor size. After editing is finished, the node smothly shrinks to its original size. This is | ||
//! implemented by using a separate `edited_node` camera that is moved in synchronization with | ||
//! `node_searcher` camera. | ||
|
||
use ensogl::prelude::*; | ||
|
||
use crate::GraphEditorModelWithNetwork; | ||
use crate::NodeId; | ||
use enso_frp as frp; | ||
use ensogl::animation::easing::EndStatus::Normal; | ||
use ensogl::display::Scene; | ||
use ensogl::Animation; | ||
use ensogl::Easing; | ||
|
||
/// Describes the "speed" of growth/shrink animation. | ||
/// | ||
/// To determine the duration of the blending animation, we divide the length of the camera path by | ||
/// this value. This is primarily used to move the edited node back to the `main` layer once editing | ||
/// is done. If the camera is already at its destination – the duration would be close to zero, so | ||
/// we would immediately change the layer of the node. If the camera needs to travel a lot - we | ||
/// increase the animation duration proportionally so that the layer would be changed later. | ||
/// | ||
/// The exact value is selected empirically. The maximum camera travel distance is about 9000.0 | ||
/// units, so our coefficient determines the maximum animation duration as 600 ms. | ||
const ANIMATION_LENGTH_COEFFIENT: f32 = 15.0; | ||
|
||
/// Initialize edited node growth/shrink animator. It would handle scene layer change for the edited | ||
/// node as well. | ||
pub fn initialize_edited_node_animator( | ||
model: &GraphEditorModelWithNetwork, | ||
frp: &crate::Frp, | ||
scene: &Scene, | ||
) { | ||
let network = &frp.network; | ||
let out = &frp.output; | ||
let searcher_cam = scene.layers.node_searcher.camera(); | ||
let edited_node_cam = scene.layers.edited_node.camera(); | ||
let main_cam = scene.layers.main.camera(); | ||
|
||
let growth_animation = Animation::new(network); | ||
let animation_blending = Easing::new(network); | ||
|
||
frp::extend! { network | ||
let searcher_cam_frp = searcher_cam.frp(); | ||
let main_cam_frp = main_cam.frp(); | ||
|
||
|
||
// === Starting node editing === | ||
|
||
previous_edited_node <- out.node_editing_started.previous(); | ||
_eval <- out.node_editing_started.map2(&previous_edited_node, f!([model] (current, previous) { | ||
model.move_node_to_main_layer(*previous); | ||
model.move_node_to_edited_node_layer(*current); | ||
})); | ||
|
||
|
||
// === Edited node camera position animation === | ||
|
||
is_growing <- bool(&out.node_editing_finished, &out.node_editing_started); | ||
edited_node_cam_target <- switch(&is_growing, &main_cam_frp.position, &searcher_cam_frp.position); | ||
growth_animation.target <+ edited_node_cam_target; | ||
|
||
camera_path_length <- all_with | ||
(&growth_animation.value, &growth_animation.target, |v, t| (v - t).magnitude()); | ||
on_node_editing_start_or_finish <- any(&out.node_editing_started, &out.node_editing_finished); | ||
start_animation_blending <- camera_path_length.sample(&on_node_editing_start_or_finish); | ||
eval start_animation_blending ((length) { | ||
animation_blending.set_duration(*length / ANIMATION_LENGTH_COEFFIENT); | ||
animation_blending.stop_and_rewind(0.0); | ||
animation_blending.target(1.0); | ||
}); | ||
|
||
// We want to: | ||
// 1. Smothly animate edited node camera from `main_cam` position to `searcher_cam` position when we | ||
// start/finish node editing so that the edited node "grows" or "shrinks" to reach the correct | ||
// visible size. This is `growth_animation`. | ||
// 2. Keep `searcher_cam` and `edited_node_cam` at the same position everywhen else so that the | ||
// searcher and the edited node are at the same visible position at all times. This is | ||
// `edited_node_cam_target`. | ||
// | ||
// Enabling/disabling "follow me" mode for the edited node camera is hard | ||
// to implement and leads to serious visualization lags. To avoid that, we blend these two | ||
// components together using `animation_blending` as a weight coefficient. This allows a very smooth | ||
// transition between "follow me" mode and node growth/shrink animation. | ||
edited_node_cam_position <- all_with3 | ||
(&edited_node_cam_target, &growth_animation.value, &animation_blending.value, |target,animation,weight| { | ||
let weight = Vector3::from_element(*weight); | ||
let inv_weight = Vector3::from_element(1.0) - weight; | ||
target.component_mul(&weight) + animation.component_mul(&inv_weight) | ||
}); | ||
eval edited_node_cam_position([edited_node_cam] (pos) edited_node_cam.set_position(*pos)); | ||
|
||
|
||
// === Finishing shrinking animation === | ||
|
||
on_animation_end <- animation_blending.on_end.filter(|end_status| *end_status == Normal); | ||
shrinking_finished <- on_animation_end.gate_not(&is_growing); | ||
node_that_finished_editing <- out.node_editing_started.sample(&shrinking_finished); | ||
eval node_that_finished_editing ([model] (id) { | ||
model.move_node_to_main_layer(*id); | ||
}); | ||
} | ||
} | ||
|
||
|
||
// === Helpers === | ||
|
||
impl GraphEditorModelWithNetwork { | ||
/// Move node to the `edited_node` scene layer, so that it is rendered by the separate camera. | ||
fn move_node_to_edited_node_layer(&self, node_id: NodeId) { | ||
if let Some(node) = self.nodes.get_cloned(&node_id) { | ||
node.model.move_to_edited_node_layer(); | ||
} | ||
} | ||
|
||
/// Move node to the `main` scene layer, so that it is rendered by the main camera. | ||
fn move_node_to_main_layer(&self, node_id: NodeId) { | ||
if let Some(node) = self.nodes.get_cloned(&node_id) { | ||
node.model.move_to_main_layer(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we format such lines this way instead, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done