-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaeSmoothPath.js
42 lines (34 loc) · 1.13 KB
/
aeSmoothPath.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
sourcePath = //Use a path from a shape layer;
// Example: thisComp.layer("Shape Layer 1").content("Rectangle 1").content("Path 1").path;
cv = sourcePath.points();
pathIsClosed = sourcePath.isClosed();
if (!pathIsClosed) {
thisLength = cv.length;
cv.splice(0, 0, cv[0]);
cv.push(cv[thisLength]);
}
// quadratic curve bezier approximation.
points = [];
intan = [];
outtan = [];
for (var i = 0; i < cv.length; i++) {
if (i == 0) {
pos = cv[i] + div(cv[i + 1] - cv[i], 2);
points.push(pos);
intan.push((cv[i] - pos) * (2 / 3));
outtan.push((cv[i + 1] - pos) * (2 / 3));
} else if (i == cv.length - 1) {
if (pathIsClosed) {
pos = cv[i] + div(cv[0] - cv[i], 2);
points.push(pos);
intan.push((cv[i] - pos) * (2 / 3));
outtan.push((cv[0] - pos) * (2 / 3));
}
} else {
pos = cv[i] + div(cv[i + 1] - cv[i], 2);
points.push(pos);
intan.push((cv[i] - pos) * (2 / 3));
outtan.push((cv[i + 1] - pos) * (2 / 3));
}
}
createPath(points, intan, outtan, pathIsClosed);