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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
define.class(function(require, exports){
this.End = function(){
}
this.delay = 0
this.interrupt = false
this.repeat = 1
this.bounce = false
this.type = float32
this.motion = float.ease.linear
this.speed = 1
this.interpolator = mix
this.atConstructor = function(config, obj, key, track, first_value, last_value){
this.config = config
this.obj = obj
this.key = key
this.track = track
if (config.motion) this.motion = config.motion
if (track) {
if (track.bounce) this.bounce = track.bounce
if (track.repeat) this.repeat = track.repeat
if (track.speed) this.speed = track.speed
}
if(typeof this.motion === 'string') this.motion = float.ease[this.motion] || float.ease.linear
if(!config) debugger
if(config.type) this.type = config.type
this.first_value = first_value
this.last_value = last_value
}
this.compute = function(local_time, time_skew){
if(!this.order){
this.order = [0]
this.values = {}
this.end_time = 0
for(var key in this.track){
var time = parseFloat(key)
if(parseFloat(key) == time){
var desc = {}
var value = this.track[key]
if(value === undefined) continue
if(value && typeof value == 'object' && value.value !== undefined){
desc.value = this.type(value.value)
if(value.motion) desc.motion = (typeof value.motion === 'string'? float.ease[value.motion]: value.motion) || this.motion
}
else{
desc.value = this.type(value)
}
this.values[key] = desc
this.order.push(key)
if(time > this.end_time) this.end_time = time
}
}
if(!this.track && this.config.duration !== undefined){
var duration = this.config.duration
this.order.push(duration)
this.values[duration] = {value:this.type(this.last_value)}
if(duration > this.end_time) this.end_time = duration
}
this.order.sort()
}
if(this.delay !== undefined){
if(local_time - this.delay <= 0) local_time = 0
else local_time -= this.delay
}
if(this.reverse_time !== undefined){
local_time = this.reverse_time - (local_time - this.reverse_time)
}
var norm_time = (local_time / this.end_time) * this.speed
var end_gap = undefined
if (this.bounce){
if(norm_time >= this.repeat) end_gap = norm_time - this.repeat, norm_time = this.repeat
norm_time = norm_time % 2
if(norm_time > 1) norm_time = 2 - norm_time
}
else if (this.repeat){
if(norm_time >= this.repeat) end_gap = norm_time - this.repeat, norm_time = this.repeat - 0.000001
norm_time = norm_time % 1
}
if(norm_time < 0){
end_gap = -norm_time
}
if(end_gap !== undefined){
var end = new this.End()
end.last_value = norm_time >= 0.99? this.values[this.order[this.order.length - 1]].value: this.values[this.order[0]].value
end.skew = end_gap * this.end_time
return end
}
if(norm_time > 1) norm_time = 1
if(norm_time < 0) norm_time = 0
var motion_time = this.motion(norm_time)
if(motion_time < 0.001 ) motion_time = 0
if(motion_time > 0.999 ) motion_time = 1
var track_time = motion_time * this.end_time
var key1, key2
if(!this.clamped && (track_time <= this.order[0] || track_time >= this.order[this.order.length-1])){
if(track_time <= this.order[0]){
key1 = this.order[0]
key2 = this.order[1]
}
else{
key1 = this.order[this.order.length - 2] || 0
key2 = this.order[this.order.length - 1]
}
}
else{
for(var i = 0, len = this.order.length; i<len; i++){
var key = this.order[i]
if(track_time <= key){
key1 = this.order[i-1] || 0
key2 = key
break
}
}
}
if(key1 !== undefined){
if(key2 === undefined) return key1 in this.values? this.values[key1].value: this.first_value
else{
var inter_key_time
if(Math.abs(key2 - key1) <0.0001) inter_key_time = 0
else inter_key_time = (track_time - key1) / (key2 - key1)
var value1 = key1 in this.values? this.values[key1]: {value:this.first_value}
var value2 = this.values[key2]
if(value2.motion) inter_key_time = value2.motion(inter_key_time)
var out = mix(value1.value, value2.value, inter_key_time)
return out
}
}
}
})
|