-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.js
111 lines (105 loc) · 7.4 KB
/
animation.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
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
/* Animation */
/* catmull rom interpolation by zerustu */
/* no option used (or force catmull rom) */
function animation_catmullrom_rotation(entity,model,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
var anim_moment= entity.getAge()%(total_time*20)
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
model.getBone(bone).setRotation(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
function animation_catmullrom_position(entity,model,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
var anim_moment= entity.getAge()%(total_time*20)
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
model.getBone(bone).setPosition(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
/* "Use a custom time variable" used but not "use bone pointer instead of bone name" */
function ct_animation_catmullrom_rotation(anim_moment,model,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
model.getBone(bone).setRotation(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
function ct_animation_catmullrom_position(anim_moment,model,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
model.getBone(bone).setPosition(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
/* "use bone pointer instead of bone name" used but not "Use a custom time variable" */
function sm_animation_catmullrom_rotation(entity,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
var anim_moment= entity.getAge()%(total_time*20)
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
bone.setRotation(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
function sm_animation_catmullrom_position(entity,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
var anim_moment= entity.getAge()%(total_time*20)
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
bone.setPosition(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
/* "Use a custom time variable" AND "use bone pointer instead of bone name" */
function sm_ct_animation_catmullrom_rotation(anim_moment,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
bone.setRotation(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
function sm_ct_animation_catmullrom_position(anim_moment,frame,total_time,bone,original_positionX,original_positionY,original_positionZ){
for (var i=0; i<frame.length-2;i=i+2){
if (anim_moment>=(frame[i]*20)&&anim_moment<=(frame[i+2]*20)){
var t = (anim_moment-(frame[i]*20))/(frame[i+2]*20-frame[i]*20)
var res_1 = frame[i+1][0][0]*Math.pow(t, 3) + frame[i+1][0][1]*Math.pow(t, 2) + frame[i+1][0][2]*t + frame[i+1][0][3];
var res_2 = frame[i+1][1][0]*Math.pow(t, 3) + frame[i+1][1][1]*Math.pow(t, 2) + frame[i+1][1][2]*t + frame[i+1][1][3];
var res_3 = frame[i+1][2][0]*Math.pow(t, 3) + frame[i+1][2][1]*Math.pow(t, 2) + frame[i+1][2][2]*t + frame[i+1][2][3];
bone.setPosition(res_1+original_positionX,res_2+original_positionY,res_3+original_positionZ);
}
}
}
function init(entity, model){
}
function update(entity, model){
// Place here the animation
}
function tick(entity, model){
}