forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.js
More file actions
100 lines (75 loc) · 3.01 KB
/
animation.js
File metadata and controls
100 lines (75 loc) · 3.01 KB
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
pc.extend(pc, function () {
'use strict';
var AnimationHandler = function () {
};
AnimationHandler.prototype = {
load: function (url, callback) {
pc.http.get(url, function (err, response) {
if (err) {
callback(pc.string.format("Error loading animation resource: {0} [{1}]", url, err));
} else {
callback(null, response);
}
}.bind(this));
},
open: function (url, data) {
return this["_parseAnimationV" + data.animation.version](data);
},
_parseAnimationV3: function (data) {
var animData = data.animation;
var anim = new pc.Animation();
anim.setName(animData.name);
anim.duration = animData.duration;
for (var i = 0; i < animData.nodes.length; i++) {
var node = new pc.Node();
var n = animData.nodes[i];
node._name = n.name;
for (var j = 0; j < n.keys.length; j++) {
var k = n.keys[j];
var t = k.time;
var p = k.pos;
var r = k.rot;
var s = k.scale;
var pos = new pc.Vec3(p[0], p[1], p[2]);
var rot = new pc.Quat().setFromEulerAngles(r[0], r[1], r[2]);
var scl = new pc.Vec3(s[0], s[1], s[2]);
var key = new pc.Key(t, pos, rot, scl);
node._keys.push(key);
}
anim.addNode(node);
}
return anim;
},
_parseAnimationV4: function (data) {
var animData = data.animation;
var anim = new pc.Animation();
anim.setName(animData.name);
anim.duration = animData.duration;
for (var i = 0; i < animData.nodes.length; i++) {
var node = new pc.Node();
var n = animData.nodes[i];
node._name = n.name;
var defPos = n.defaults.p;
var defRot = n.defaults.r;
var defScl = n.defaults.s;
for (var j = 0; j < n.keys.length; j++) {
var k = n.keys[j];
var t = k.t;
var p = defPos ? defPos : k.p;
var r = defRot ? defRot : k.r;
var s = defScl ? defScl : k.s;
var pos = new pc.Vec3(p[0], p[1], p[2]);
var rot = new pc.Quat().setFromEulerAngles(r[0], r[1], r[2]);
var scl = new pc.Vec3(s[0], s[1], s[2]);
var key = new pc.Key(t, pos, rot, scl);
node._keys.push(key);
}
anim.addNode(node);
}
return anim;
}
};
return {
AnimationHandler: AnimationHandler
};
}());