forked from errno-mmd/readfacevmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpschanger.cc
74 lines (68 loc) · 1.71 KB
/
fpschanger.cc
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
#include "fpschanger.h"
#include <vector>
#include "VMD.h"
#include "interpolate.h"
vector<VMD_Frame> change_fps_bone(const vector<VMD_Frame>& v, float srcfps, float tgtfps, bool bezier)
{
vector<VMD_Frame> v1;
if (v.size() == 0) {
return v1;
}
VMD_Frame prev = v[0];
v1.push_back(v[0]);
int next_frame = 1;
for (unsigned int i = 1; i < v.size(); ) {
if (v[i].number == prev.number) {
i++;
continue;
}
float t_tgt = float(next_frame) / tgtfps;
float t = float(v[i].number) / srcfps;
if (t >= t_tgt) {
float t_prev = float(prev.number) / srcfps;
float ratio = (t_tgt - t_prev) / (t - t_prev);
VMD_Frame f = make_intermediate_frame(prev, v[i], ratio, bezier);
f.number = next_frame;
v1.push_back(f);
next_frame++;
// iはインクリメントしない
} else {
prev = v[i];
i++;
continue;
}
}
return v1;
}
vector<VMD_Morph> change_fps_morph(const vector<VMD_Morph>& v, float srcfps, float tgtfps)
{
vector<VMD_Morph> v1;
if (v.size() == 0) {
return v1;
}
VMD_Morph prev = v[0];
v1.push_back(v[0]);
int next_frame = 1;
for (unsigned int i = 1; i < v.size(); ) {
if (v[i].frame == prev.frame) {
i++;
continue;
}
float t_tgt = float(next_frame) / tgtfps;
float t = float(v[i].frame) / srcfps;
if (t >= t_tgt) {
float t_prev = float(prev.frame) / srcfps;
float ratio = (t_tgt - t_prev) / (t - t_prev);
VMD_Morph f = make_intermediate_morph(prev, v[i], ratio);
f.frame = next_frame;
v1.push_back(f);
next_frame++;
// iはインクリメントしない
} else {
prev = v[i];
i++;
continue;
}
}
return v1;
}