-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheasings.rs
120 lines (107 loc) · 3.35 KB
/
easings.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use bevy::{core_pipeline::bloom::BloomSettings, pbr::NotShadowCaster, prelude::*};
use bevy_motiongfx::prelude::*;
fn main() {
App::new()
// Bevy plugins
.add_plugins(DefaultPlugins)
// Custom plugins
.add_plugins(MotionGfxPlugin)
.add_systems(Startup, (setup, easings))
.add_systems(Update, timeline_movement)
.run();
}
fn easings(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
let easings = [
ease::linear,
ease::sine::ease_in_out,
ease::quad::ease_in_out,
ease::cubic::ease_in_out,
ease::quart::ease_in_out,
ease::quint::ease_in_out,
ease::expo::ease_in_out,
ease::circ::ease_in_out,
ease::back::ease_in_out,
ease::elastic::ease_in_out,
];
let capacity = easings.len();
// Color palette
let palette = ColorPalette::default();
// Create spheres
let mut spheres = Vec::with_capacity(capacity);
let mesh_handle = meshes.add(Sphere::default());
let material = StandardMaterial {
base_color: Color::WHITE,
emissive: palette.get(ColorKey::Blue) * 100.0,
..default()
};
for i in 0..capacity {
let sphere = commands.spawn(NotShadowCaster).build_pbr(
Transform::from_translation(Vec3::new(-5.0, (i as f32) - (capacity as f32) * 0.5, 0.0))
.with_scale(Vec3::ONE),
mesh_handle.clone(),
material.clone(),
);
spheres.push(sphere);
}
// Generate sequence
let sequence = spheres
.iter_mut()
.zip(easings)
.map(|(s, e)| {
commands
.add_motion(
s.to_translation_x(s.transform.translation.x + 10.0)
.with_ease(e)
.animate(4.0),
)
.add_motion(
s.to_emissive(palette.get(ColorKey::Red) * 100.0)
.animate(4.0),
)
.all()
})
.collect::<Vec<_>>()
.all();
commands.spawn(SequencePlayerBundle {
sequence,
..default()
});
}
fn setup(mut commands: Commands) {
// Camera
commands
.spawn(Camera3dBundle {
camera: Camera {
hdr: true,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, 15.0),
tonemapping: bevy::core_pipeline::tonemapping::Tonemapping::AcesFitted,
..default()
})
.insert(BloomSettings::default());
}
fn timeline_movement(
mut q_timelines: Query<(&mut SequencePlayer, &mut SequenceController)>,
keys: Res<ButtonInput<KeyCode>>,
time: Res<Time>,
) {
for (mut sequence_player, mut sequence_time) in q_timelines.iter_mut() {
if keys.pressed(KeyCode::KeyD) {
sequence_time.target_time += time.delta_seconds();
}
if keys.pressed(KeyCode::KeyA) {
sequence_time.target_time -= time.delta_seconds();
}
if keys.just_pressed(KeyCode::Space) {
if keys.pressed(KeyCode::ShiftLeft) {
sequence_player.time_scale = -1.0;
} else {
sequence_player.time_scale = 1.0;
}
}
if keys.just_pressed(KeyCode::Escape) {
sequence_player.time_scale = 0.0;
}
}
}