-
Notifications
You must be signed in to change notification settings - Fork 0
/
Morphing.h
46 lines (34 loc) · 1.25 KB
/
Morphing.h
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
//point(<geometry>geometry, string attribute_name, int pointnumber)
vector npos = point(1, "P", @ptnum % npoints(1));// point position from second input, equivalent to @P fpr first input
vector min, max, nmin, nmax;
getbbox(0, min, max);
getbbox(0, nmin, nmax);
float gradrange = 100 * chf("morphing_grad_range");
float offset = fit(@P.y, max.y, min.x, 1, gradrange);
offset += rand(@P) * chi("rand_offset");
float noffset = fit(npos.y, nmax.y, nmin.x, 1, gradrange);
offset += rand(npos) * chi("rand_offset");
float f = fit(@Frame, offset,
100 + noffset - gradrange - chi("rand_offset"),
0.0,
1.0);
f = chramp("ramp", f);
vector center = getbbox_center(0);
vector ncenter = getbbox_center(1);
vector currentPos = @P;
vector ncurrentPos = @P;
//rotation
float angle = 3.1415926535897932384 * 2.0 * f * chi("rotation_cycle");
matrix mat = ident();
rotate(mat, angle, set(0,1,0));
@P *= mat;
npos *= mat;
// turbulence noise
float sinf = sin(f * 3.1415926535897932384);
float noiseval = (noise(@P + currentPos * 100.0) - 0.5);
vector dir = normalize(@P - center) * sinf * noiseval;
float nnoiseval = (noise(npos + ncurrentPos * 100.0) - 0.5);
vector ndir = normalize(npos - ncenter) * sinf * nnoiseval;
@P += dir;
npos += dir;
@P = lerp(@P, npos, f);