-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathanimation-block.js
82 lines (63 loc) · 1.78 KB
/
animation-block.js
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
import r from 'restructure';
import Nofs from './nofs';
export default function (type) {
return new r.Struct({
interpolationType: r.uint16le,
globalSequenceID: r.int16le,
timestamps: new Nofs(new Nofs(r.uint32le)),
values: new Nofs(new Nofs(type)),
trackCount: function () {
return this.values.length;
},
tracks: function () {
const tracks = [];
for (let trackIndex = 0; trackIndex < this.trackCount; trackIndex++) {
const track = {};
// Corresponds to offset in animations array of MD2.
track.animationIndex = trackIndex;
track.timestamps = this.timestamps[trackIndex] || [];
track.values = this.values[trackIndex] || [];
tracks.push(track);
}
return tracks;
},
maxTrackLength: function () {
let max = 0;
this.tracks.forEach((track) => {
if (track.timestamps.length > max) {
max = track.timestamps.length;
}
});
return max;
},
keyframeCount: function () {
let keyframeCount = 0;
for (let i = 0, len = this.tracks.length; i < len; ++i) {
keyframeCount += this.tracks[i].timestamps.length;
}
return keyframeCount;
},
firstKeyframe: function () {
if (this.tracks.length === 0) {
return null;
} else {
for (let i = 0, len = this.tracks.length; i < len; ++i) {
const track = this.tracks[i];
if (track.timestamps.length > 0) {
return {
timestamp: track.timestamps[0],
value: track.values[0],
};
}
}
return null;
}
},
empty: function () {
return this.maxTrackLength === 0;
},
animated: function () {
return !this.empty;
},
});
}