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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use std::time::Duration;
use amethyst_assets::{Asset, Handle, Result};
use fnv::FnvHashMap;
use specs::{Component, DenseVecStorage, Entity, VecStorage};
use interpolation::InterpolationType;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AnimationOutput {
Translation(Vec<[f32; 3]>),
Rotation(Vec<[f32; 4]>),
Scale(Vec<[f32; 3]>),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sampler {
pub input: Vec<f32>,
pub output: AnimationOutput,
pub ty: InterpolationType,
}
impl Asset for Sampler {
type Data = Self;
type HandleStorage = VecStorage<Handle<Self>>;
}
impl Into<Result<Sampler>> for Sampler {
fn into(self) -> Result<Sampler> {
Ok(self)
}
}
#[derive(Debug, Clone)]
pub struct AnimationHierarchy {
pub nodes: FnvHashMap<usize, Entity>,
}
impl Component for AnimationHierarchy {
type Storage = DenseVecStorage<Self>;
}
#[derive(Clone, Debug)]
pub struct Animation {
pub nodes: Vec<(usize, Handle<Sampler>)>,
}
impl Asset for Animation {
type Data = Self;
type HandleStorage = VecStorage<Handle<Self>>;
}
impl Into<Result<Animation>> for Animation {
fn into(self) -> Result<Animation> {
Ok(self)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ControlState {
Requested,
Running(Duration),
Paused(Duration),
Abort,
Done,
}
impl ControlState {
pub fn is_running(&self) -> bool {
match *self {
ControlState::Running(..) => true,
_ => false,
}
}
pub fn is_paused(&self) -> bool {
match *self {
ControlState::Paused(_) => true,
_ => false,
}
}
}
#[derive(Debug, Clone)]
pub enum RestState {
Translation([f32; 3]),
Rotation([f32; 4]),
Scale([f32; 3]),
}
#[derive(Debug, Clone)]
pub enum EndControl {
Loop(Option<u32>),
Normal,
}
#[derive(Clone)]
pub struct SamplerControl {
pub sampler: Handle<Sampler>,
pub state: ControlState,
pub end: EndControl,
pub after: RestState,
}
#[derive(Clone, Default)]
pub struct SamplerControlSet {
pub translation: Option<SamplerControl>,
pub rotation: Option<SamplerControl>,
pub scale: Option<SamplerControl>,
}
impl Component for SamplerControlSet {
type Storage = DenseVecStorage<Self>;
}
#[derive(Clone, Debug)]
pub enum AnimationCommand {
Start,
Pause,
Abort,
}
#[derive(Clone, Debug)]
pub struct AnimationControl {
pub animation: Handle<Animation>,
pub end: EndControl,
pub state: ControlState,
pub command: AnimationCommand,
}
impl Component for AnimationControl {
type Storage = DenseVecStorage<Self>;
}
pub struct AnimationSet {
pub animations: Vec<Handle<Animation>>,
}
impl Component for AnimationSet {
type Storage = DenseVecStorage<Self>;
}