-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmorph.cpp
executable file
·35 lines (31 loc) · 1013 Bytes
/
morph.cpp
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
#include "morph.hpp"
#include "geometry.hpp"
using namespace std;
Vec3 blend (const vector<Mesh> &targets, const vector<double> &w,
const Vec2 &u) {
Vec3 x = Vec3(0);
for (int m = 0; m < targets.size(); m++) {
if (w[m] == 0)
continue;
Face *face = get_enclosing_face(targets[m], u);
if (!face)
continue;
Vec3 b = get_barycentric_coords(u, face);
x += w[m]*(b[0]*face->v[0]->node->x
+ b[1]*face->v[1]->node->x
+ b[2]*face->v[2]->node->x);
}
return x;
}
Vec3 Morph::pos (double t, const Vec2 &u) const {
return blend(targets, weights.pos(t), u);
}
void apply (const Morph &morph, double t) {
for (int n = 0; n < morph.mesh->nodes.size(); n++) {
Node *node = morph.mesh->nodes[n];
Vec3 x = Vec3(0);
for (int v = 0; v < node->verts.size(); v++)
x += morph.pos(t, node->verts[v]->u);
node->x = x/(double)node->verts.size();
}
}