@algorisys/tinyfly 0.77.0 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/lib/addons/characters.js +1139 -793
- package/lib/addons/maps.js +442 -0
- package/lib/browser/tinyfly-maps.iife.js +1 -0
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +2235 -1889
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/types/characters/character.d.ts +19 -0
- package/lib/types/characters/hand.d.ts +57 -4
- package/lib/types/characters/hands/draw-cartoon-hand.d.ts +39 -0
- package/lib/types/characters/hands/hand-rig.d.ts +116 -0
- package/lib/types/characters/hands/index.d.ts +3 -0
- package/lib/types/characters/index.d.ts +1 -0
- package/lib/types/maps/cities.d.ts +13 -0
- package/lib/types/maps/index.d.ts +12 -0
- package/lib/types/maps/map-target.d.ts +125 -0
- package/lib/types/maps/projection.d.ts +66 -0
- package/lib/types/maps/tiles.d.ts +67 -0
- package/lib/types/maps/world-110m.d.ts +13 -0
- package/lib/types/maps/world.d.ts +53 -0
- package/package.json +6 -2
package/lib/addons/characters.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import { s as
|
|
2
|
-
import { a as
|
|
3
|
-
import { createRandom as
|
|
4
|
-
function
|
|
1
|
+
import { s as Ht, b as We, p as ae, c as Ut } from "./sketch-CA8ZXhxI.js";
|
|
2
|
+
import { a as Fo } from "./sketch-CA8ZXhxI.js";
|
|
3
|
+
import { createRandom as $e, hashSeed as Re } from "@algorisys/tinyfly";
|
|
4
|
+
function yt(t, e, n) {
|
|
5
5
|
const o = t.length;
|
|
6
6
|
if (o < 2) return [];
|
|
7
|
-
const
|
|
7
|
+
const s = [], r = [], h = (i) => e + (n - e) * i / (o - 1);
|
|
8
8
|
return t.forEach((i, l) => {
|
|
9
|
-
const a = t[Math.max(0, l - 1)],
|
|
10
|
-
|
|
11
|
-
}), [...
|
|
12
|
-
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
const
|
|
17
|
-
t.beginPath(), t.moveTo(
|
|
18
|
-
for (const i of
|
|
9
|
+
const a = t[Math.max(0, l - 1)], f = t[Math.min(o - 1, l + 1)], g = Math.hypot(f.x - a.x, f.y - a.y) || 1, m = h(l) / 2, c = -(f.y - a.y) / g * m, d = (f.x - a.x) / g * m;
|
|
10
|
+
s.push({ x: i.x + c, y: i.y + d }), r.push({ x: i.x - c, y: i.y - d });
|
|
11
|
+
}), [...s, ...r.reverse()];
|
|
12
|
+
}
|
|
13
|
+
function Xt(t, e, n, o) {
|
|
14
|
+
const s = e.length;
|
|
15
|
+
if (s < 2) return;
|
|
16
|
+
const r = yt(e, n, o), h = (i) => n + (o - n) * i / (s - 1);
|
|
17
|
+
t.beginPath(), t.moveTo(r[0].x, r[0].y);
|
|
18
|
+
for (const i of r.slice(1)) t.lineTo(i.x, i.y);
|
|
19
19
|
t.closePath(), t.fill(), e.forEach((i, l) => {
|
|
20
|
-
l !== 0 && l !==
|
|
20
|
+
l !== 0 && l !== s - 1 && s > 3 || (t.beginPath(), t.arc(i.x, i.y, h(l) / 2, 0, Math.PI * 2), t.fill());
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
for (let i = 0; i <=
|
|
26
|
-
const l = i /
|
|
27
|
-
x:
|
|
28
|
-
y:
|
|
23
|
+
function tt(t, e, n, o, s = 16) {
|
|
24
|
+
const r = { x: 2 * e.x - (t.x + n.x) / 2, y: 2 * e.y - (t.y + n.y) / 2 }, h = [];
|
|
25
|
+
for (let i = 0; i <= s; i++) {
|
|
26
|
+
const l = i / s, a = l < 0.5 ? { x: t.x + (e.x - t.x) * 2 * l, y: t.y + (e.y - t.y) * 2 * l } : { x: e.x + (n.x - e.x) * (2 * l - 1), y: e.y + (n.y - e.y) * (2 * l - 1) }, f = 1 - l, g = {
|
|
27
|
+
x: f * f * t.x + 2 * f * l * r.x + l * l * n.x,
|
|
28
|
+
y: f * f * t.y + 2 * f * l * r.y + l * l * n.y
|
|
29
29
|
};
|
|
30
30
|
h.push({ x: a.x + (g.x - a.x) * o, y: a.y + (g.y - a.y) * o });
|
|
31
31
|
}
|
|
32
32
|
return h;
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const et = {
|
|
35
35
|
lean: 0,
|
|
36
36
|
headTilt: 0,
|
|
37
37
|
leftShoulder: 18,
|
|
@@ -57,10 +57,10 @@ const G = {
|
|
|
57
57
|
turn: 0,
|
|
58
58
|
sit: 0
|
|
59
59
|
};
|
|
60
|
-
function
|
|
61
|
-
return { ...
|
|
60
|
+
function L(t) {
|
|
61
|
+
return { ...et, ...t };
|
|
62
62
|
}
|
|
63
|
-
const
|
|
63
|
+
const ce = {
|
|
64
64
|
mouth: 0,
|
|
65
65
|
smile: 0,
|
|
66
66
|
mouthWidth: 1,
|
|
@@ -71,204 +71,204 @@ const zt = {
|
|
|
71
71
|
browTilt: 0,
|
|
72
72
|
lookX: 0,
|
|
73
73
|
lookY: 0
|
|
74
|
-
},
|
|
75
|
-
neutral:
|
|
76
|
-
happy:
|
|
77
|
-
joyful:
|
|
78
|
-
sad:
|
|
79
|
-
crying:
|
|
80
|
-
surprised:
|
|
81
|
-
shocked:
|
|
82
|
-
angry:
|
|
83
|
-
furious:
|
|
84
|
-
worried:
|
|
85
|
-
scared:
|
|
86
|
-
confused:
|
|
87
|
-
skeptical:
|
|
88
|
-
thinking:
|
|
89
|
-
sleepy:
|
|
90
|
-
disgusted:
|
|
91
|
-
smug:
|
|
92
|
-
wink:
|
|
74
|
+
}, $ = (t) => ({ ...ce, ...t }), X = {
|
|
75
|
+
neutral: ce,
|
|
76
|
+
happy: $({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
|
|
77
|
+
joyful: $({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
|
|
78
|
+
sad: $({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
|
|
79
|
+
crying: $({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
|
|
80
|
+
surprised: $({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
|
|
81
|
+
shocked: $({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
|
|
82
|
+
angry: $({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
|
|
83
|
+
furious: $({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
|
|
84
|
+
worried: $({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
|
|
85
|
+
scared: $({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
|
|
86
|
+
confused: $({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
|
|
87
|
+
skeptical: $({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
|
|
88
|
+
thinking: $({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
|
|
89
|
+
sleepy: $({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
|
|
90
|
+
disgusted: $({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
|
|
91
|
+
smug: $({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
|
|
92
|
+
wink: $({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
|
|
93
93
|
};
|
|
94
|
-
function
|
|
95
|
-
return { ...t, ...typeof e == "string" ?
|
|
96
|
-
}
|
|
97
|
-
const
|
|
98
|
-
rest:
|
|
99
|
-
wave:
|
|
100
|
-
cheer:
|
|
101
|
-
shrug:
|
|
102
|
-
point:
|
|
94
|
+
function Be(t, e) {
|
|
95
|
+
return { ...t, ...typeof e == "string" ? X[e] : e };
|
|
96
|
+
}
|
|
97
|
+
const Ye = {
|
|
98
|
+
rest: et,
|
|
99
|
+
wave: L({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...X.happy }),
|
|
100
|
+
cheer: L({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...X.joyful }),
|
|
101
|
+
shrug: L({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...X.confused, lookX: 0, lookY: 0 }),
|
|
102
|
+
point: L({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
|
|
103
103
|
// The forearm passes 180° to fold back in, so the hand reaches the chin.
|
|
104
|
-
think:
|
|
105
|
-
handsOnHips:
|
|
106
|
-
sad:
|
|
107
|
-
surprised:
|
|
104
|
+
think: L({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...X.thinking }),
|
|
105
|
+
handsOnHips: L({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
|
|
106
|
+
sad: L({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...X.sad }),
|
|
107
|
+
surprised: L({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...X.surprised }),
|
|
108
108
|
// Squash and stretch: the wind-up before a jump (or the landing), and the jump itself.
|
|
109
|
-
crouch:
|
|
109
|
+
crouch: L({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
|
|
110
110
|
// Seated, hands resting on the knees. Arm angles spread outward per side, so
|
|
111
111
|
// reaching forward (+x, the way the figure faces) is negative for the left arm.
|
|
112
|
-
sit:
|
|
113
|
-
jump:
|
|
114
|
-
},
|
|
115
|
-
function
|
|
112
|
+
sit: L({ sit: 1, turn: 0.5, leftShoulder: -25, rightShoulder: 25, leftElbow: -55, rightElbow: 55 }),
|
|
113
|
+
jump: L({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...X.joyful })
|
|
114
|
+
}, fe = Object.keys(et);
|
|
115
|
+
function Le(t, e, n) {
|
|
116
116
|
const o = { ...t };
|
|
117
|
-
for (const
|
|
117
|
+
for (const s of fe) o[s] = t[s] + (e[s] - t[s]) * n;
|
|
118
118
|
return o;
|
|
119
119
|
}
|
|
120
|
-
const
|
|
121
|
-
function
|
|
122
|
-
const o = Math.sin(t * Math.PI * 2) * n,
|
|
120
|
+
const Wt = 24, Gt = 4, Jt = 28, Fe = 40;
|
|
121
|
+
function Ne(t, e = et, n = 1) {
|
|
122
|
+
const o = Math.sin(t * Math.PI * 2) * n, s = Math.cos(t * Math.PI * 2) * n, r = (a) => a <= Fe, h = (a) => r(a) ? 22 * o : a, i = r(e.leftShoulder) ? e.leftElbow - Jt * Math.max(0, -o) : e.leftElbow, l = r(e.rightShoulder) ? e.rightElbow + Jt * Math.max(0, o) : e.rightElbow;
|
|
123
123
|
return {
|
|
124
124
|
...e,
|
|
125
125
|
// Lean into the walk, and keep the head a little more level than the body.
|
|
126
|
-
lean: e.lean +
|
|
127
|
-
headTilt: e.headTilt -
|
|
126
|
+
lean: e.lean + Gt * n,
|
|
127
|
+
headTilt: e.headTilt - Gt * 0.5 * n,
|
|
128
128
|
leftElbow: i,
|
|
129
129
|
rightElbow: l,
|
|
130
130
|
// Left foot forward while swing > 0, right foot back; then the other way.
|
|
131
|
-
leftHip: -
|
|
132
|
-
rightHip: -
|
|
131
|
+
leftHip: -Wt * o,
|
|
132
|
+
rightHip: -Wt * o,
|
|
133
133
|
// The leg swinging forward lifts, its shin trailing backward (-x). A positive
|
|
134
134
|
// knee folds toward the centre, which is backward only for the right leg.
|
|
135
|
-
leftKnee: -30 * Math.max(0,
|
|
136
|
-
rightKnee: 30 * Math.max(0, -
|
|
135
|
+
leftKnee: -30 * Math.max(0, s),
|
|
136
|
+
rightKnee: 30 * Math.max(0, -s),
|
|
137
137
|
// Arms swing against the legs: left arm back while the left foot is forward.
|
|
138
138
|
leftShoulder: h(e.leftShoulder),
|
|
139
139
|
rightShoulder: h(e.rightShoulder)
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
-
function
|
|
143
|
-
return 4 * ((
|
|
142
|
+
function go(t, e = 1) {
|
|
143
|
+
return 4 * (($t + wt) * t) * Math.sin(Wt * e * Math.PI / 180);
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function Ce(t) {
|
|
146
146
|
const e = Math.abs(Math.sin(t / 65)), n = 0.55 + 0.45 * Math.sin(t / 310);
|
|
147
147
|
return e * n;
|
|
148
148
|
}
|
|
149
|
-
const
|
|
150
|
-
function
|
|
151
|
-
return
|
|
149
|
+
const de = 0.12, zt = 0.46, Ue = 1 - 2 * de, Xe = 0.1, De = 0.21, qe = 0.19, $t = 0.24, wt = 0.22, ue = 0.12, Ke = 0.14, ge = 0.33, jt = 0.7, Zt = 0.3, Ge = 0.35, Je = [1.7, 1.05], ze = [1.3, 0.75], Qt = [1.45, 0.85], je = [1.15, 0.75], Vt = 0.06, Ze = 0.7, Qe = 0.65, Ve = 0.3, tn = 0.02, en = 0.012, nn = 12, on = 0.25, ct = 90, sn = 0.25, rn = 0.01, V = (t) => Math.min(1, Math.max(0, t ?? 0));
|
|
150
|
+
function yo(t, e = 1) {
|
|
151
|
+
return wt * t * e;
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
function
|
|
155
|
-
const h = Math.max(1, Math.min(
|
|
153
|
+
const Rt = -0.12, ye = 0.4, D = (t) => t * Math.PI / 180, ln = (t, e) => ({ x: e * Math.sin(D(t)), y: Math.cos(D(t)) }), me = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), pe = (t, e, n, o) => t - 0.3 * e - n * 0.14 * e - Math.max(0, o - 1) * 0.12 * e;
|
|
154
|
+
function hn(t, e, n, o, s, r) {
|
|
155
|
+
const h = Math.max(1, Math.min(r * 0.6, Ke * n)), i = V(e.turn), l = (ue + ge * i) * n, a = o + Rt * n, f = l + e.lookX * 0.08 * n, g = e.lookY * 0.07 * n, m = [
|
|
156
156
|
// The left eye is on the far side; turning closes it up more than the near one.
|
|
157
|
-
{ x: -0.34 * n * (1 -
|
|
158
|
-
{ x: 0.34 * n * (1 -
|
|
157
|
+
{ x: -0.34 * n * (1 - jt * i), squeeze: 1 - jt * i, open: e.leftEye, brow: e.leftBrow, side: -1 },
|
|
158
|
+
{ x: 0.34 * n * (1 - Zt * i), squeeze: 1 - Zt * i, open: e.rightEye, brow: e.rightBrow, side: 1 }
|
|
159
159
|
];
|
|
160
|
-
t.fillStyle =
|
|
161
|
-
for (const
|
|
162
|
-
const
|
|
163
|
-
if (
|
|
164
|
-
const
|
|
165
|
-
t.beginPath(), t.moveTo(
|
|
160
|
+
t.fillStyle = s, t.strokeStyle = s, t.lineWidth = h;
|
|
161
|
+
for (const p of m) {
|
|
162
|
+
const x = me(p.open, e.blink);
|
|
163
|
+
if (x < 0.2) {
|
|
164
|
+
const T = e.smile > 0.5 ? -0.12 * n : 0.06 * n;
|
|
165
|
+
t.beginPath(), t.moveTo(p.x + l - 0.12 * n, a), t.quadraticCurveTo(p.x + l, a + T, p.x + l + 0.12 * n, a), t.stroke();
|
|
166
166
|
} else {
|
|
167
|
-
if (
|
|
168
|
-
const
|
|
169
|
-
t.beginPath(), t.ellipse(
|
|
167
|
+
if (x > 1.2) {
|
|
168
|
+
const P = 0.13 * n * x;
|
|
169
|
+
t.beginPath(), t.ellipse(p.x + l, a, P * 0.85, P, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = s;
|
|
170
170
|
}
|
|
171
|
-
const
|
|
172
|
-
t.beginPath(), t.ellipse(
|
|
171
|
+
const T = x > 1.2 ? 0.075 * n : 0.1 * n;
|
|
172
|
+
t.beginPath(), t.ellipse(p.x + f, a + g, T, T * 1.1 * Math.min(x, 1), 0, 0, Math.PI * 2), t.fill();
|
|
173
173
|
}
|
|
174
|
-
const E =
|
|
174
|
+
const E = pe(a, n, p.brow, x), b = p.x + l - p.side * 0.13 * n * p.squeeze, M = p.x + l + p.side * 0.13 * n * p.squeeze;
|
|
175
175
|
t.beginPath(), t.moveTo(M, E), t.lineTo(b, E - e.browTilt * 0.1 * n), t.stroke();
|
|
176
176
|
}
|
|
177
|
-
const
|
|
178
|
-
if (t.beginPath(),
|
|
179
|
-
t.moveTo(l - d,
|
|
177
|
+
const c = o + ye * n, d = 0.25 * n * Math.max(0.3, e.mouthWidth) * (1 - Ge * i), u = Math.min(1, Math.max(0, e.mouth));
|
|
178
|
+
if (t.beginPath(), u <= 0.05) {
|
|
179
|
+
t.moveTo(l - d, c), t.quadraticCurveTo(l, c + e.smile * 0.25 * n, l + d, c), t.stroke();
|
|
180
180
|
return;
|
|
181
181
|
}
|
|
182
|
-
const
|
|
183
|
-
e.smile > 0.3 ? (t.moveTo(l - d,
|
|
182
|
+
const y = 0.3 * n * u;
|
|
183
|
+
e.smile > 0.3 ? (t.moveTo(l - d, c - 0.05 * n), t.lineTo(l + d, c - 0.05 * n), t.quadraticCurveTo(l, c + y * 2, l - d, c - 0.05 * n)) : e.smile < -0.3 ? (t.moveTo(l - d, c + y * 0.6), t.lineTo(l + d, c + y * 0.6), t.quadraticCurveTo(l, c - y * 1.4, l - d, c + y * 0.6)) : t.ellipse(l, c, d * 0.8, y, 0, 0, Math.PI * 2), t.fill();
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
const n = e.height ?? 300, o = Math.min(3, Math.max(0.3, t.stretch ?? 1)),
|
|
187
|
-
const v =
|
|
188
|
-
return
|
|
185
|
+
function we(t, e) {
|
|
186
|
+
const n = e.height ?? 300, o = Math.min(3, Math.max(0.3, t.stretch ?? 1)), s = Math.sqrt(o), r = (e.headSize ?? 2 * de) / 2, h = e.headSize === void 0 ? Ue : 1 - 2 * r, i = r * n, l = V(t.sit), a = t.leftHip + (-ct - t.leftHip) * l, f = t.leftKnee + (-ct - t.leftKnee) * l, g = t.rightHip + (ct - t.rightHip) * l, m = t.rightKnee + (ct - t.rightKnee) * l, c = e.classic === !0, d = V(t.turn), u = (k, w, S) => {
|
|
187
|
+
const v = D(w - S) / 2, A = d + (1 - d) * k * Ze;
|
|
188
|
+
return c ? { x: 0, y: 0 } : { x: Math.cos(v) * Vt * A, y: Math.abs(Math.sin(v)) * Vt };
|
|
189
189
|
};
|
|
190
|
-
let
|
|
191
|
-
if (l > 0 || !
|
|
192
|
-
const
|
|
193
|
-
|
|
190
|
+
let y = 0;
|
|
191
|
+
if (l > 0 || !c) {
|
|
192
|
+
const k = (v, A, W) => $t * Math.cos(D(A)) + wt * Math.cos(D(A - W)) + u(v, A, W).y, w = Math.max(k(-1, a, f), k(1, g, m)), S = c ? Math.min(1, l / sn) : 1;
|
|
193
|
+
y = (zt - w) * S * n * o;
|
|
194
194
|
}
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
return { x:
|
|
198
|
-
},
|
|
199
|
-
const v =
|
|
200
|
-
return { root: { x: 0, y:
|
|
201
|
-
},
|
|
202
|
-
const v = { x:
|
|
203
|
-
return { root: v, joint:
|
|
204
|
-
},
|
|
205
|
-
const
|
|
206
|
-
return { x:
|
|
195
|
+
const p = -zt * n * o + y, x = -h * n * o + y, E = c ? 0 : (tn * V(t.turn) + en * l) * n * o, b = E === 0 ? [{ x: 0, y: p }, { x: 0, y: x }] : tt({ x: 0, y: p }, { x: -E, y: (p + x) / 2 }, { x: 0, y: x }, 1, 8), M = x + Xe * n * o, T = (e.shoulderWidth ?? 0) * n * Math.cos(d * Math.PI / 2), P = (k, w, S, v, A) => {
|
|
196
|
+
const W = ln(S, v);
|
|
197
|
+
return { x: k + W.x * A * n, y: w + W.y * A * n };
|
|
198
|
+
}, I = (k, w, S) => {
|
|
199
|
+
const v = P(0, p, w, k, $t * o);
|
|
200
|
+
return { root: { x: 0, y: p }, joint: v, end: P(v.x, v.y, w - S, k, wt * o) };
|
|
201
|
+
}, O = (k, w, S) => {
|
|
202
|
+
const v = { x: k * T, y: M }, A = P(v.x, v.y, w, k, De * s);
|
|
203
|
+
return { root: v, joint: A, end: P(A.x, A.y, w + S, k, qe * s) };
|
|
204
|
+
}, H = { left: I(-1, a, f), right: I(1, g, m) }, _ = (k, w, S, v) => {
|
|
205
|
+
const A = u(k, S, v);
|
|
206
|
+
return { x: w.end.x + A.x * n * o, y: w.end.y + A.y * n * o };
|
|
207
207
|
};
|
|
208
208
|
return {
|
|
209
209
|
height: n,
|
|
210
210
|
facing: (e.facing ?? 1) < 0 ? -1 : 1,
|
|
211
211
|
stretch: o,
|
|
212
212
|
lineWidth: e.lineWidth ?? n * 0.025,
|
|
213
|
-
rubber: Math.min(1, Math.max(
|
|
213
|
+
rubber: Math.min(1, Math.max(c ? 0 : Ve, e.rubber ?? 0)),
|
|
214
214
|
r: i,
|
|
215
215
|
// The head keeps its area: taller and narrower when stretched.
|
|
216
216
|
headRx: i / Math.sqrt(o),
|
|
217
217
|
headRy: i * Math.sqrt(o),
|
|
218
|
-
hipY:
|
|
219
|
-
neckY:
|
|
220
|
-
drop:
|
|
221
|
-
lean:
|
|
222
|
-
classic:
|
|
223
|
-
legs:
|
|
224
|
-
toes: { left:
|
|
218
|
+
hipY: p,
|
|
219
|
+
neckY: x,
|
|
220
|
+
drop: y,
|
|
221
|
+
lean: c ? t.lean : t.lean + nn * Math.sin(Math.PI * l),
|
|
222
|
+
classic: c,
|
|
223
|
+
legs: H,
|
|
224
|
+
toes: { left: _(-1, H.left, a, f), right: _(1, H.right, g, m) },
|
|
225
225
|
spine: b,
|
|
226
226
|
arms: {
|
|
227
|
-
left:
|
|
228
|
-
right:
|
|
227
|
+
left: O(-1, t.leftShoulder, t.leftElbow),
|
|
228
|
+
right: O(1, t.rightShoulder, t.rightElbow)
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
}
|
|
232
|
-
const
|
|
233
|
-
function
|
|
234
|
-
const o = Math.cos(n),
|
|
235
|
-
return { x: e.x +
|
|
232
|
+
const rt = (t, e) => e === 0 ? [t.root, t.joint, t.end] : tt(t.root, t.joint, t.end, e);
|
|
233
|
+
function Bt(t, e, n) {
|
|
234
|
+
const o = Math.cos(n), s = Math.sin(n), r = t.x - e.x, h = t.y - e.y;
|
|
235
|
+
return { x: e.x + r * o - h * s, y: e.y + r * s + h * o };
|
|
236
236
|
}
|
|
237
|
-
function
|
|
238
|
-
const n =
|
|
239
|
-
const [
|
|
240
|
-
return Math.atan2(E.y -
|
|
237
|
+
function be(t, e) {
|
|
238
|
+
const n = D(t.lean), o = D(e.headTilt), s = { x: 0, y: t.hipY }, r = (p) => ({ x: t.facing * p.x, y: p.y }), h = (p) => r(Bt(p, s, n)), i = (p) => h(Bt({ x: p.x, y: p.y + t.neckY }, { x: 0, y: t.neckY }, o)), l = rt(t.arms.left, t.rubber).map(h), a = rt(t.arms.right, t.rubber).map(h), f = (p) => {
|
|
239
|
+
const [x, E] = p.slice(-2);
|
|
240
|
+
return Math.atan2(E.y - x.y, E.x - x.x);
|
|
241
241
|
};
|
|
242
242
|
let g = 1 / 0;
|
|
243
|
-
for (const [
|
|
243
|
+
for (const [p, x] of [
|
|
244
244
|
[e.leftBrow, e.leftEye],
|
|
245
245
|
[e.rightBrow, e.rightEye]
|
|
246
246
|
]) {
|
|
247
|
-
const E =
|
|
247
|
+
const E = pe(Rt, 1, p, me(x, e.blink));
|
|
248
248
|
g = Math.min(g, E, E - e.browTilt * 0.1);
|
|
249
249
|
}
|
|
250
|
-
const
|
|
250
|
+
const m = { left: r(t.legs.left.end), right: r(t.legs.right.end) }, c = { left: r(t.toes.left), right: r(t.toes.right) }, d = { left: Math.max(m.left.y, c.left.y), right: Math.max(m.right.y, c.right.y) }, u = Math.max(d.left, d.right), y = rn * t.height;
|
|
251
251
|
return {
|
|
252
252
|
facing: t.facing,
|
|
253
253
|
height: t.height,
|
|
254
254
|
stretch: t.stretch,
|
|
255
255
|
lineWidth: t.lineWidth,
|
|
256
|
-
hip:
|
|
256
|
+
hip: s,
|
|
257
257
|
neck: h({ x: 0, y: t.neckY }),
|
|
258
258
|
shoulders: { left: h(t.arms.left.root), right: h(t.arms.right.root) },
|
|
259
259
|
elbows: { left: h(t.arms.left.joint), right: h(t.arms.right.joint) },
|
|
260
260
|
hands: { left: h(t.arms.left.end), right: h(t.arms.right.end) },
|
|
261
|
-
knees: { left:
|
|
262
|
-
feet:
|
|
263
|
-
toes:
|
|
264
|
-
feetY:
|
|
265
|
-
grounded: { left: d.left >=
|
|
266
|
-
handAngle: { left:
|
|
261
|
+
knees: { left: r(t.legs.left.joint), right: r(t.legs.right.joint) },
|
|
262
|
+
feet: m,
|
|
263
|
+
toes: c,
|
|
264
|
+
feetY: u,
|
|
265
|
+
grounded: { left: d.left >= u - y, right: d.right >= u - y },
|
|
266
|
+
handAngle: { left: f(l), right: f(a) },
|
|
267
267
|
limbs: {
|
|
268
268
|
leftArm: l,
|
|
269
269
|
rightArm: a,
|
|
270
|
-
leftLeg:
|
|
271
|
-
rightLeg:
|
|
270
|
+
leftLeg: rt(t.legs.left, t.rubber).map(r),
|
|
271
|
+
rightLeg: rt(t.legs.right, t.rubber).map(r),
|
|
272
272
|
spine: t.spine.map(h)
|
|
273
273
|
},
|
|
274
274
|
head: {
|
|
@@ -277,31 +277,31 @@ function se(t, e) {
|
|
|
277
277
|
ry: t.headRy,
|
|
278
278
|
// Mirroring a turn reverses it.
|
|
279
279
|
angle: t.facing * (n + o),
|
|
280
|
-
eyeY:
|
|
280
|
+
eyeY: Rt,
|
|
281
281
|
browTopY: g,
|
|
282
|
-
mouthY:
|
|
283
|
-
faceX: t.facing * (
|
|
282
|
+
mouthY: ye,
|
|
283
|
+
faceX: t.facing * (ue + ge * V(e.turn))
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
function
|
|
288
|
-
return
|
|
287
|
+
function an(t, e = {}) {
|
|
288
|
+
return be(we(t, e), t);
|
|
289
289
|
}
|
|
290
|
-
function
|
|
291
|
-
return
|
|
290
|
+
function mo(t, e, n) {
|
|
291
|
+
return Bt({ x: t.center.x + e * t.rx, y: t.center.y + n * t.ry }, t.center, t.angle);
|
|
292
292
|
}
|
|
293
|
-
function
|
|
294
|
-
const o = (
|
|
293
|
+
function cn(t, e, n) {
|
|
294
|
+
const o = (r) => ({ x: r.x + e, y: r.y + n }), s = (r) => ({ left: o(r.left), right: o(r.right) });
|
|
295
295
|
return {
|
|
296
296
|
...t,
|
|
297
297
|
hip: o(t.hip),
|
|
298
298
|
neck: o(t.neck),
|
|
299
|
-
shoulders:
|
|
300
|
-
elbows:
|
|
301
|
-
hands:
|
|
302
|
-
knees:
|
|
303
|
-
feet:
|
|
304
|
-
toes:
|
|
299
|
+
shoulders: s(t.shoulders),
|
|
300
|
+
elbows: s(t.elbows),
|
|
301
|
+
hands: s(t.hands),
|
|
302
|
+
knees: s(t.knees),
|
|
303
|
+
feet: s(t.feet),
|
|
304
|
+
toes: s(t.toes),
|
|
305
305
|
feetY: t.feetY + n,
|
|
306
306
|
grounded: { ...t.grounded },
|
|
307
307
|
handAngle: { ...t.handAngle },
|
|
@@ -315,182 +315,628 @@ function Ke(t, e, n) {
|
|
|
315
315
|
head: { ...t.head, center: o(t.head.center) }
|
|
316
316
|
};
|
|
317
317
|
}
|
|
318
|
-
function
|
|
319
|
-
const
|
|
318
|
+
function fn(t, e, n = {}, o = 0) {
|
|
319
|
+
const s = we(e, n), r = n.color ?? "#1e293b", h = n.layers ?? {}, i = n.layers ? be(s, e) : void 0, l = n.sketch ? Ht(t, n.sketch, o) : void 0, a = n.sketch && n.layers ? Ht(t, n.sketch, o) : void 0, f = (b) => {
|
|
320
320
|
t.save(), b(), t.restore();
|
|
321
321
|
}, g = (b) => {
|
|
322
|
-
b && i &&
|
|
323
|
-
},
|
|
324
|
-
|
|
325
|
-
}, d = (b, M,
|
|
322
|
+
b && i && f(() => b(t, i, o, a));
|
|
323
|
+
}, m = () => t.scale(s.facing, 1), c = () => {
|
|
324
|
+
m(), t.translate(0, s.hipY), t.rotate(D(s.lean)), t.translate(0, -s.hipY);
|
|
325
|
+
}, d = (b, M, T) => {
|
|
326
326
|
if (l) return M ? l.curve(b) : l.line(b);
|
|
327
|
-
if (
|
|
327
|
+
if (s.classic) {
|
|
328
328
|
t.beginPath(), t.moveTo(b[0].x, b[0].y);
|
|
329
|
-
for (const
|
|
329
|
+
for (const P of b.slice(1)) t.lineTo(P.x, P.y);
|
|
330
330
|
t.stroke();
|
|
331
331
|
return;
|
|
332
332
|
}
|
|
333
|
-
|
|
334
|
-
},
|
|
335
|
-
|
|
336
|
-
},
|
|
337
|
-
if (
|
|
338
|
-
const M =
|
|
339
|
-
t.beginPath(), t.arc(M.x, M.y,
|
|
333
|
+
Xt(t, b, T[0] * s.lineWidth, T[1] * s.lineWidth);
|
|
334
|
+
}, u = (b, M) => d(rt(b, s.rubber), s.rubber > 0, M), y = (b) => {
|
|
335
|
+
s.classic || d([s.legs[b].end, s.toes[b]], !1, je);
|
|
336
|
+
}, p = (b) => {
|
|
337
|
+
if (s.classic || l) return;
|
|
338
|
+
const M = s.arms[b].end;
|
|
339
|
+
t.beginPath(), t.arc(M.x, M.y, Qe * s.lineWidth, 0, Math.PI * 2), t.fill();
|
|
340
340
|
};
|
|
341
|
-
t.save(), t.strokeStyle =
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
t.save(), t.strokeStyle = r, t.fillStyle = r, t.lineWidth = s.lineWidth, t.lineCap = "round", t.lineJoin = "round";
|
|
342
|
+
const x = (b) => {
|
|
343
|
+
f(() => {
|
|
344
|
+
c(), u(s.arms[b], ze), p(b);
|
|
345
345
|
});
|
|
346
346
|
const M = h.sleeve;
|
|
347
|
-
M && i &&
|
|
348
|
-
}, E =
|
|
349
|
-
g(h.behind),
|
|
350
|
-
|
|
351
|
-
}), E &&
|
|
352
|
-
|
|
353
|
-
const { left: b, right: M } = { left:
|
|
347
|
+
M && i && f(() => M(t, i, b, o, a));
|
|
348
|
+
}, E = V(e.turn) > on;
|
|
349
|
+
g(h.behind), f(() => {
|
|
350
|
+
m(), u(s.legs.left, Qt), y("left"), u(s.legs.right, Qt), y("right");
|
|
351
|
+
}), E && x("left"), f(() => {
|
|
352
|
+
c(), d(s.spine, s.spine.length > 2, Je);
|
|
353
|
+
const { left: b, right: M } = { left: s.arms.left.root, right: s.arms.right.root };
|
|
354
354
|
if (b.x !== M.x)
|
|
355
|
-
if (
|
|
355
|
+
if (s.classic) d([b, M], !1, [1, 1]);
|
|
356
356
|
else {
|
|
357
|
-
const
|
|
358
|
-
d(
|
|
357
|
+
const T = { x: (b.x + M.x) / 2, y: b.y - 0.3 * Math.abs(M.x - b.x) };
|
|
358
|
+
d(tt(b, T, M, 1, 8), !0, [1.1, 1.1]);
|
|
359
359
|
}
|
|
360
|
-
}), g(h.body), E ||
|
|
361
|
-
|
|
362
|
-
const b = -
|
|
363
|
-
t.beginPath(), t.ellipse(0, b,
|
|
360
|
+
}), g(h.body), E || x("left"), x("right"), g(h.behindHead), f(() => {
|
|
361
|
+
c(), t.translate(0, s.neckY), t.rotate(D(e.headTilt));
|
|
362
|
+
const b = -s.headRy;
|
|
363
|
+
t.beginPath(), t.ellipse(0, b, s.headRx, s.headRy, 0, 0, Math.PI * 2);
|
|
364
364
|
const M = n.headFill ?? "#ffffff";
|
|
365
365
|
if (M !== "none" && (t.fillStyle = M, t.fill()), l) {
|
|
366
|
-
l.ellipse(0, b,
|
|
367
|
-
const
|
|
368
|
-
t.translate(
|
|
366
|
+
l.ellipse(0, b, s.headRx, s.headRy);
|
|
367
|
+
const T = l.nudge();
|
|
368
|
+
t.translate(T.x, T.y);
|
|
369
369
|
} else
|
|
370
370
|
t.stroke();
|
|
371
|
-
t.translate(0, b), t.scale(
|
|
372
|
-
}), g(h.overHead), g(h.front), t.restore(), n.label && (t.save(), t.fillStyle =
|
|
371
|
+
t.translate(0, b), t.scale(s.headRx / s.r, s.headRy / s.r), hn(t, e, s.r, 0, r, s.lineWidth);
|
|
372
|
+
}), g(h.overHead), g(h.front), t.restore(), n.label && (t.save(), t.fillStyle = r, t.font = n.labelFont ?? `700 ${Math.round(s.height * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(n.label, 0, -s.height * s.stretch - 0.04 * s.height + s.drop), t.restore());
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function Me(t, e) {
|
|
375
375
|
const n = { ...t };
|
|
376
|
-
let o = t.walking > 0 ?
|
|
377
|
-
return t.talk > 0 && (o = { ...o, mouth: Math.max(o.mouth, t.talk *
|
|
376
|
+
let o = t.walking > 0 ? Le(n, Ne(t.walk, n), t.walking) : n;
|
|
377
|
+
return t.talk > 0 && (o = { ...o, mouth: Math.max(o.mouth, t.talk * Ce(e)) }), o;
|
|
378
378
|
}
|
|
379
|
-
function
|
|
380
|
-
const e = t.style ?? {}, n = e.height ?? 300, o = n * 0.8,
|
|
379
|
+
function po(t) {
|
|
380
|
+
const e = t.style ?? {}, n = e.height ?? 300, o = n * 0.8, s = { ...L(t.pose ?? {}), walk: 0, walking: 0, talk: 0, rubber: e.rubber ?? 0 };
|
|
381
381
|
return {
|
|
382
382
|
type: "custom",
|
|
383
383
|
x: t.x - o / 2,
|
|
384
384
|
y: t.y - n,
|
|
385
385
|
width: o,
|
|
386
386
|
height: n,
|
|
387
|
-
props: { ...
|
|
387
|
+
props: { ...s },
|
|
388
388
|
figureStyle: e,
|
|
389
|
-
draw(
|
|
389
|
+
draw(r, h, i) {
|
|
390
390
|
const l = h.props;
|
|
391
|
-
|
|
391
|
+
r.translate(o / 2, n), fn(r, Me(l, i), { ...e, rubber: l.rubber }, i);
|
|
392
392
|
}
|
|
393
393
|
};
|
|
394
394
|
}
|
|
395
|
-
function
|
|
395
|
+
function wo(t, e, n) {
|
|
396
396
|
const o = t.figureStyle;
|
|
397
397
|
if (!o) throw new Error("stickFigureAt: the target was not made by stickFigureTarget");
|
|
398
|
-
const
|
|
399
|
-
let
|
|
400
|
-
for (const [a,
|
|
401
|
-
typeof
|
|
402
|
-
const i =
|
|
403
|
-
return { pose: i, joints:
|
|
404
|
-
}
|
|
405
|
-
function
|
|
398
|
+
const s = { ...t.props };
|
|
399
|
+
let r = 0, h = 0;
|
|
400
|
+
for (const [a, f] of e.state?.values.get(n) ?? [])
|
|
401
|
+
typeof f == "number" && (a === "x" || a === "motionPathX" ? r = f : a === "y" || a === "motionPathY" ? h = f : a in s && (s[a] = f));
|
|
402
|
+
const i = Me(s, e.time), l = an(i, { ...o, rubber: s.rubber });
|
|
403
|
+
return { pose: i, joints: cn(l, t.x + r + t.width / 2, t.y + h + t.height) };
|
|
404
|
+
}
|
|
405
|
+
function bo(t, e) {
|
|
406
406
|
const n = [];
|
|
407
|
-
return e.forEach((o,
|
|
408
|
-
const
|
|
409
|
-
n.push(o.expression ?
|
|
410
|
-
}),
|
|
407
|
+
return e.forEach((o, s) => {
|
|
408
|
+
const r = s === 0 ? et : n[s - 1], h = typeof o.pose == "string" ? Ye[o.pose] : { ...r, ...o.pose };
|
|
409
|
+
n.push(o.expression ? Be(h, o.expression) : h);
|
|
410
|
+
}), fe.filter((o) => n.some((s) => s[o] !== et[o])).map((o) => ({
|
|
411
411
|
id: `${t}-${o}`,
|
|
412
412
|
target: t,
|
|
413
413
|
property: o,
|
|
414
|
-
keyframes: e.map((
|
|
415
|
-
time:
|
|
416
|
-
value: n[
|
|
417
|
-
...
|
|
414
|
+
keyframes: e.map((s, r) => ({
|
|
415
|
+
time: s.time,
|
|
416
|
+
value: n[r][o],
|
|
417
|
+
...s.easing ? { easing: s.easing } : {}
|
|
418
418
|
}))
|
|
419
419
|
}));
|
|
420
420
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
421
|
+
const dn = ["thumb", "index", "middle", "ring", "pinky"], kt = {
|
|
422
|
+
"thumb.curl": 0.15,
|
|
423
|
+
"thumb.across": 0.15,
|
|
424
|
+
"index.curl": 0.12,
|
|
425
|
+
"middle.curl": 0.16,
|
|
426
|
+
"ring.curl": 0.2,
|
|
427
|
+
"pinky.curl": 0.25,
|
|
428
|
+
spread: 0.25,
|
|
429
|
+
turn: 0,
|
|
430
|
+
bend: 0,
|
|
431
|
+
tilt: 0,
|
|
432
|
+
roll: 0
|
|
433
|
+
};
|
|
434
|
+
function R(t = {}) {
|
|
435
|
+
return { ...kt, ...t };
|
|
436
|
+
}
|
|
437
|
+
const B = (t, e, n, o, s) => ({
|
|
438
|
+
"thumb.curl": t,
|
|
439
|
+
"index.curl": e,
|
|
440
|
+
"middle.curl": n,
|
|
441
|
+
"ring.curl": o,
|
|
442
|
+
"pinky.curl": s
|
|
443
|
+
}), un = {
|
|
444
|
+
relaxed: kt,
|
|
445
|
+
open: R({ ...B(0, 0, 0, 0, 0), "thumb.across": 0, spread: 0.55 }),
|
|
446
|
+
spread: R({ ...B(0, 0, 0, 0, 0), "thumb.across": 0, spread: 1 }),
|
|
447
|
+
flat: R({ ...B(0, 0, 0, 0, 0), "thumb.across": 0.35, spread: 0 }),
|
|
448
|
+
fist: R({ ...B(0.7, 1, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
|
|
449
|
+
point: R({ ...B(0.75, 0, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
|
|
450
|
+
/** The fist on its side, knuckles toward the viewer, the thumb up */
|
|
451
|
+
thumbsUp: R({ ...B(0, 1, 1, 1, 1), "thumb.across": 0, spread: 0, roll: 70 }),
|
|
452
|
+
peace: R({ ...B(0.75, 0, 0, 1, 1), "thumb.across": 0.9, spread: 1 }),
|
|
453
|
+
ok: R({ ...B(0.12, 0.6, 0.1, 0.15, 0.2), "thumb.across": 0.55, spread: 0.6 }),
|
|
454
|
+
pinch: R({ ...B(0.1, 0.65, 0.75, 0.85, 0.9), "thumb.across": 0.55, spread: 0 }),
|
|
455
|
+
cupped: R({ ...B(0.25, 0.4, 0.4, 0.4, 0.4), "thumb.across": 0.4, spread: 0.05, turn: 2 }),
|
|
456
|
+
wave: R({ ...B(0, 0.05, 0.05, 0.1, 0.12), "thumb.across": 0, spread: 0.7, turn: 2 }),
|
|
457
|
+
/** Holding a pencil to write: thumb and middle finger pinch it, the index finger rests on top */
|
|
458
|
+
pencilGrip: R({ ...B(0.1, 0.6, 0.72, 0.88, 0.95), "thumb.across": 0.5, spread: 0, turn: 0.8, bend: 10 }),
|
|
459
|
+
/** Holding a handle, a cup or a bar: every finger wrapped round it */
|
|
460
|
+
hold: R({ ...B(0.5, 0.7, 0.72, 0.74, 0.76), "thumb.across": 0.75, spread: 0, turn: 1 })
|
|
461
|
+
};
|
|
462
|
+
function Mo(t, e, n) {
|
|
463
|
+
const o = { ...t };
|
|
464
|
+
for (const [s, r] of Object.entries(e)) {
|
|
465
|
+
const h = t[s] ?? r;
|
|
466
|
+
o[s] = h + (r - h) * n;
|
|
467
|
+
}
|
|
468
|
+
return o;
|
|
469
|
+
}
|
|
470
|
+
const gn = {
|
|
471
|
+
index: { knuckle: [-0.16, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.125, fan: -1 },
|
|
472
|
+
middle: { knuckle: [-0.055, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.13, fan: -0.2 },
|
|
473
|
+
ring: { knuckle: [0.05, 0.475, -0.02], bones: [0.2, 0.125, 0.1], width: 0.122, fan: 0.55 },
|
|
474
|
+
pinky: { knuckle: [0.15, 0.43, -0.02], bones: [0.16, 0.1, 0.085], width: 0.108, fan: 1.25 }
|
|
475
|
+
}, yn = {
|
|
476
|
+
index: { knuckle: [-0.14, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.15, fan: -1 },
|
|
477
|
+
middle: { knuckle: [0, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.155, fan: 0 },
|
|
478
|
+
pinky: { knuckle: [0.14, 0.45, -0.02], bones: [0.19, 0.115, 0.095], width: 0.145, fan: 1 }
|
|
479
|
+
}, C = {
|
|
480
|
+
base: [-0.11, 0.1, -0.05],
|
|
481
|
+
bones: [0.2, 0.15, 0.12],
|
|
482
|
+
widths: [0.2, 0.145, 0.135],
|
|
483
|
+
/** Where the thumb points with `across` 0 and 1 */
|
|
484
|
+
out: [-0.7, 0.68, -0.22],
|
|
485
|
+
across: [0.35, 0.5, -0.8]
|
|
486
|
+
}, mn = [82, 100, 62], pn = [48, 72], wn = 3, bn = 13, Mn = 0.035, kn = -0.075, xn = [
|
|
487
|
+
[-0.17, 0],
|
|
488
|
+
[-0.215, 0.12],
|
|
489
|
+
[-0.235, 0.26],
|
|
490
|
+
[-0.225, 0.4],
|
|
491
|
+
[-0.185, 0.49],
|
|
492
|
+
[-0.075, 0.525],
|
|
493
|
+
[0.05, 0.51],
|
|
494
|
+
[0.16, 0.465],
|
|
495
|
+
[0.215, 0.4],
|
|
496
|
+
[0.225, 0.26],
|
|
497
|
+
[0.2, 0.1],
|
|
498
|
+
[0.16, 0]
|
|
499
|
+
], J = (t) => t * Math.PI / 180, Yt = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], mt = (t, e) => [t[0] * e, t[1] * e, t[2] * e], Lt = (t, e) => [t[1] * e[2] - t[2] * e[1], t[2] * e[0] - t[0] * e[2], t[0] * e[1] - t[1] * e[0]], st = (t) => {
|
|
500
|
+
const e = Math.hypot(t[0], t[1], t[2]) || 1;
|
|
501
|
+
return [t[0] / e, t[1] / e, t[2] / e];
|
|
502
|
+
};
|
|
503
|
+
function j(t, e, n) {
|
|
504
|
+
const o = Math.cos(n), s = Math.sin(n), r = Lt(e, t), h = e[0] * t[0] + e[1] * t[1] + e[2] * t[2];
|
|
505
|
+
return [
|
|
506
|
+
t[0] * o + r[0] * s + e[0] * h * (1 - o),
|
|
507
|
+
t[1] * o + r[1] * s + e[1] * h * (1 - o),
|
|
508
|
+
t[2] * o + r[2] * s + e[2] * h * (1 - o)
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
const te = [1, 0, 0], ee = [0, 1, 0], lt = [0, 0, 1];
|
|
512
|
+
function En(t, e, n) {
|
|
513
|
+
const o = J(t.fan * (wn + bn * n)), s = [Math.sin(o), Math.cos(o), 0], r = [Math.cos(o), -Math.sin(o), 0], h = [t.knuckle];
|
|
514
|
+
let i = 0;
|
|
515
|
+
t.bones.forEach((f, g) => {
|
|
516
|
+
i += J(mn[g] * e), h.push(Yt(h[g], mt(j(s, r, -i), f)));
|
|
517
|
+
});
|
|
518
|
+
const l = j(lt, r, -i), a = h.map((f, g) => t.width * (1 - 0.14 * (g / (h.length - 1))));
|
|
519
|
+
return { joints: h, back: l, widths: a };
|
|
520
|
+
}
|
|
521
|
+
function Sn(t, e, n = 1, o = 1) {
|
|
522
|
+
const s = Math.min(1, Math.max(0, e)), r = st(Yt(mt(st(C.out), 1 - s), mt(st(C.across), s))), h = st(Lt(lt, r)), i = st(Lt(r, h)), l = [[C.base[0] * o, C.base[1], C.base[2]]];
|
|
523
|
+
let a = 0;
|
|
524
|
+
C.bones.forEach((m, c) => {
|
|
525
|
+
c > 0 && (a += J(pn[c - 1] * t)), l.push(Yt(l[c], mt(j(r, h, a), m)));
|
|
526
|
+
});
|
|
527
|
+
const f = j(i, h, a), g = [...C.widths, C.widths[C.widths.length - 1] * 0.92].map((m) => m * n);
|
|
528
|
+
return { joints: l, back: f, widths: g };
|
|
529
|
+
}
|
|
530
|
+
function Ft(t, e = {}) {
|
|
531
|
+
const n = { ...kt, ...t }, o = e.size ?? 100, s = e.side ?? "right", r = s === "left" ? -1 : 1, h = J(e.angle ?? 0), i = e.fingers === 4, l = Math.max(0.5, e.plump ?? 1), a = 1 + (l - 1) * 0.7, f = (k) => ({
|
|
532
|
+
...k,
|
|
533
|
+
knuckle: [k.knuckle[0] * a, k.knuckle[1], k.knuckle[2]],
|
|
534
|
+
width: k.width * l
|
|
535
|
+
}), g = J(n.bend ?? 0), m = J(n.tilt ?? 0), c = J(90 * (n.turn ?? 0)), d = (k) => j(j(j(k, te, -g), lt, -m), ee, c), u = Math.cos(h), y = Math.sin(h), p = J(n.roll ?? 0), x = Math.cos(p), E = Math.sin(p), b = (k) => {
|
|
536
|
+
const w = k[0] * o, S = -k[1] * o, v = (w * x - S * E) * r, A = w * E + S * x;
|
|
537
|
+
return { x: v * u - A * y, y: v * y + A * u };
|
|
538
|
+
}, M = (k) => {
|
|
539
|
+
const w = b(k), S = Math.hypot(w.x, w.y);
|
|
540
|
+
return S > 1e-6 * o ? { x: w.x / S, y: w.y / S } : { x: 0, y: 0 };
|
|
541
|
+
}, T = {
|
|
542
|
+
thumb: Sn(n["thumb.curl"] ?? 0, n["thumb.across"] ?? 0, l, a)
|
|
543
|
+
}, P = i ? yn : gn;
|
|
544
|
+
for (const k of dn) {
|
|
545
|
+
const w = P[k];
|
|
546
|
+
w && (T[k] = En(f(w), n[`${k}.curl`] ?? 0, n.spread ?? 0));
|
|
547
|
+
}
|
|
548
|
+
const I = {};
|
|
549
|
+
for (const [k, w] of Object.entries(T)) {
|
|
550
|
+
const S = w.joints.map(d), v = d(w.back);
|
|
551
|
+
I[k] = {
|
|
552
|
+
points: S.map(b),
|
|
553
|
+
depths: S.map((A) => A[2] * o),
|
|
554
|
+
widths: w.widths.map((A) => A * o),
|
|
555
|
+
nail: v[2],
|
|
556
|
+
back: M(v)
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
const O = xn.flatMap(([k, w]) => [d([k * a, w, Mn]), d([k * a, w, kn])]), H = Tn(O.map(b)), _ = O.reduce((k, w) => k + w[2], 0) / O.length * o;
|
|
560
|
+
return {
|
|
561
|
+
size: o,
|
|
562
|
+
side: s,
|
|
563
|
+
wrist: { x: 0, y: 0 },
|
|
564
|
+
palm: H,
|
|
565
|
+
palmDepth: _,
|
|
566
|
+
palmFacing: -d(lt)[2],
|
|
567
|
+
fingers: I,
|
|
568
|
+
axes: { up: M(d(ee)), across: M(d(te)), out: M(d(lt)) },
|
|
569
|
+
curls: Object.fromEntries(Object.keys(I).map((k) => [k, n[`${k}.curl`] ?? 0]))
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function Pn(t, e) {
|
|
573
|
+
const n = (s) => ({ x: s.x + e.x - t.wrist.x, y: s.y + e.y - t.wrist.y }), o = {};
|
|
574
|
+
for (const [s, r] of Object.entries(t.fingers))
|
|
575
|
+
o[s] = { ...r, points: r.points.map(n) };
|
|
576
|
+
return { ...t, wrist: n(t.wrist), palm: t.palm.map(n), fingers: o };
|
|
577
|
+
}
|
|
578
|
+
function Tn(t) {
|
|
579
|
+
const e = [...t].sort((r, h) => r.x - h.x || r.y - h.y);
|
|
580
|
+
if (e.length < 3) return e;
|
|
581
|
+
const n = (r, h, i) => (h.x - r.x) * (i.y - r.y) - (h.y - r.y) * (i.x - r.x), o = [];
|
|
582
|
+
for (const r of e) {
|
|
583
|
+
for (; o.length >= 2 && n(o[o.length - 2], o[o.length - 1], r) <= 0; ) o.pop();
|
|
584
|
+
o.push(r);
|
|
585
|
+
}
|
|
586
|
+
const s = [];
|
|
587
|
+
for (const r of [...e].reverse()) {
|
|
588
|
+
for (; s.length >= 2 && n(s[s.length - 2], s[s.length - 1], r) <= 0; ) s.pop();
|
|
589
|
+
s.push(r);
|
|
590
|
+
}
|
|
591
|
+
return [...o.slice(0, -1), ...s.slice(0, -1)];
|
|
592
|
+
}
|
|
593
|
+
function ne(t, e, n, o, s, r = 0, h = 1, i = 40) {
|
|
594
|
+
const l = Math.cos(s), a = Math.sin(s);
|
|
595
|
+
return Array.from({ length: i + 1 }, (f, g) => {
|
|
596
|
+
const m = r + Math.PI * 2 * h * g / i, c = Math.cos(m) * n, d = Math.sin(m) * o;
|
|
597
|
+
return { x: t + c * l - d * a, y: e + c * a + d * l };
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
function ke(t, e) {
|
|
601
|
+
return e.look === "pencil" ? On(t, e) : vn(t, e.ink, e.look);
|
|
602
|
+
}
|
|
603
|
+
function bt(t, e, n = !1) {
|
|
604
|
+
t.beginPath(), t.moveTo(e[0].x, e[0].y);
|
|
605
|
+
for (const o of e.slice(1)) t.lineTo(o.x, o.y);
|
|
606
|
+
n && t.closePath();
|
|
607
|
+
}
|
|
608
|
+
function vn(t, e, n) {
|
|
609
|
+
const o = n === "silhouette", s = o ? 1.25 : 1;
|
|
610
|
+
return {
|
|
611
|
+
look: n,
|
|
612
|
+
ink: e,
|
|
613
|
+
limb(r, h, i) {
|
|
614
|
+
t.fillStyle = e, Xt(t, r, h * s, i * s);
|
|
615
|
+
},
|
|
616
|
+
line(r, h) {
|
|
617
|
+
r.length < 2 || (t.strokeStyle = e, t.lineWidth = h * s, t.lineCap = "round", t.lineJoin = "round", bt(t, r), t.stroke());
|
|
618
|
+
},
|
|
619
|
+
shape(r, h, i) {
|
|
620
|
+
bt(t, r, !0), (h !== null || o) && (t.fillStyle = o ? e : h, t.fill()), !(i <= 0) && (t.strokeStyle = e, t.lineWidth = i * s, t.lineJoin = "round", t.stroke());
|
|
621
|
+
},
|
|
622
|
+
ellipse(r, h, i, l, a, f, g) {
|
|
623
|
+
t.beginPath(), t.ellipse(r, h, i, l, a, 0, Math.PI * 2), (f !== null || o) && (t.fillStyle = o ? e : f, t.fill()), !(g <= 0) && (t.strokeStyle = e, t.lineWidth = g * s, t.stroke());
|
|
624
|
+
},
|
|
625
|
+
dot(r, h, i) {
|
|
626
|
+
t.fillStyle = e, t.beginPath(), t.arc(r, h, i * s, 0, Math.PI * 2), t.fill();
|
|
627
|
+
},
|
|
628
|
+
guide() {
|
|
629
|
+
},
|
|
630
|
+
guideEllipse() {
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
function In(t, e) {
|
|
635
|
+
const n = [t[0]];
|
|
636
|
+
let o = 0;
|
|
637
|
+
for (let h = 1; h < t.length; h++) {
|
|
638
|
+
const i = t[h - 1], l = t[h], a = Math.hypot(l.x - i.x, l.y - i.y);
|
|
639
|
+
let f = e - o;
|
|
640
|
+
for (; f < a; ) {
|
|
641
|
+
const g = f / a;
|
|
642
|
+
n.push({ x: i.x + (l.x - i.x) * g, y: i.y + (l.y - i.y) * g }), f += e;
|
|
643
|
+
}
|
|
644
|
+
o = a - (f - e);
|
|
645
|
+
}
|
|
646
|
+
const s = t[t.length - 1], r = n[n.length - 1];
|
|
647
|
+
return Math.hypot(s.x - r.x, s.y - r.y) > e * 0.25 ? n.push(s) : n[n.length - 1] = s, n;
|
|
648
|
+
}
|
|
649
|
+
function An(t, e) {
|
|
650
|
+
const n = t.length;
|
|
651
|
+
return t.map((o, s) => {
|
|
652
|
+
const r = t[Math.max(0, s - 1)], h = t[Math.min(n - 1, s + 1)], i = Math.hypot(h.x - r.x, h.y - r.y) || 1, l = e(n === 1 ? 0 : s / (n - 1));
|
|
653
|
+
return { x: o.x - (h.y - r.y) / i * l, y: o.y + (h.x - r.x) / i * l };
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
function oe(t) {
|
|
657
|
+
const e = [0.6, 1.4, 2.9].map((o) => ({
|
|
658
|
+
frequency: o * (0.8 + t.next() * 0.4),
|
|
659
|
+
phase: t.next() * Math.PI * 2,
|
|
660
|
+
amount: 0.5 + t.next() * 0.5
|
|
661
|
+
})), n = e.reduce((o, s) => o + s.amount, 0);
|
|
662
|
+
return (o) => e.reduce((s, r) => s + r.amount * Math.sin(Math.PI * 2 * r.frequency * o + r.phase), 0) / n;
|
|
663
|
+
}
|
|
664
|
+
function On(t, e) {
|
|
665
|
+
const n = e.pencil ?? {}, o = e.ink, s = n.roughness ?? Math.max(1, e.lineWidth * 0.12), r = Math.max(1, Math.round(n.passes ?? 2)), h = Math.min(1, Math.max(0, n.pressure ?? 0.25)), i = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), l = We(e.time, n.boil ?? 8);
|
|
666
|
+
let a = 0;
|
|
667
|
+
const f = (d, u, y = !1) => $e(Re(`${e.seed}:${y ? "paper" : l}:${d}:${u}`)), g = (d, u, y, p, x, E = 0) => {
|
|
668
|
+
if (d.length < 2) return;
|
|
669
|
+
const b = d.slice(1).reduce((_, k, w) => _ + Math.hypot(k.x - d[w].x, k.y - d[w].y), 0);
|
|
670
|
+
let M = In(d, Math.max(1.5, Math.min(e.lineWidth * 0.8, b / 24)));
|
|
671
|
+
if (E > 0 && M.length >= 2) {
|
|
672
|
+
const [_, k] = [M[M.length - 2], M[M.length - 1]], w = Math.hypot(k.x - _.x, k.y - _.y) || 1;
|
|
673
|
+
M = [...M, { x: k.x + (k.x - _.x) / w * E, y: k.y + (k.y - _.y) / w * E }];
|
|
674
|
+
}
|
|
675
|
+
const T = oe(y), P = oe(y), I = M.length, O = [], H = [];
|
|
676
|
+
M.forEach((_, k) => {
|
|
677
|
+
const w = I === 1 ? 0 : k / (I - 1), S = M[Math.max(0, k - 1)], v = M[Math.min(I - 1, k + 1)], A = Math.hypot(v.x - S.x, v.y - S.y) || 1, W = -(v.y - S.y) / A, nt = (v.x - S.x) / A, at = T(w) * x, xt = Math.min(1, w / 0.08, (1 - w) / 0.08), Et = (0.55 + 0.45 * Math.sqrt(Math.max(0, xt))) * (1 + h * P(w)), q = Math.max(0.3, u(w) * Et / 2), ot = _.x + W * at, Z = _.y + nt * at;
|
|
678
|
+
O.push({ x: ot + W * q, y: Z + nt * q }), H.push({ x: ot - W * q, y: Z - nt * q });
|
|
679
|
+
}), t.save(), t.globalAlpha *= p, t.fillStyle = o, bt(t, [...O, ...H.reverse()], !0), t.fill(), t.restore();
|
|
680
|
+
}, m = (d, u) => {
|
|
681
|
+
const y = a++, p = f(y, 99, !0);
|
|
682
|
+
if (p.next() < i) {
|
|
683
|
+
const M = (p.next() * 2 - 1) * e.lineWidth * 1.4, T = (p.next() * 2 - 1) * e.lineWidth * 1.4, P = d.map((I) => ({ x: I.x + M, y: I.y + T }));
|
|
684
|
+
g(P, (I) => u(I) * 1.8, f(y, 98, !0), 0.035, s), g(P, (I) => u(I) * 0.45, f(y, 97, !0), 0.12, s * 1.5);
|
|
685
|
+
}
|
|
686
|
+
const x = d.slice(1).reduce((M, T, P) => M + Math.hypot(T.x - d[P].x, T.y - d[P].y), 0), E = u(0.5) > 4 && x > u(0.5) * 6, b = E ? [-0.3, 0.3, 0] : [0];
|
|
687
|
+
for (let M = 0; M < r; M++) {
|
|
688
|
+
const T = M === 0;
|
|
689
|
+
b.forEach((P, I) => {
|
|
690
|
+
const O = f(y, M * 10 + I), H = P === 0 ? d : An(d, (k) => u(k) * P * Math.sqrt(Math.sin(Math.PI * k))), _ = !T && P === 0 ? e.lineWidth * (0.3 + O.next() * 0.8) : 0;
|
|
691
|
+
g(H, (k) => u(k) * (E ? 0.5 : 1) * (T ? 1 : 0.6), O, T ? 0.85 : 0.45, s * (T ? 0.6 : 1), _);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
}, c = (d, u, y, p, x, E) => {
|
|
695
|
+
const M = f(a, 50).next() * Math.PI * 2;
|
|
696
|
+
m(ne(d, u, y, p, x, M, 1.08, 48), () => E);
|
|
697
|
+
};
|
|
698
|
+
return {
|
|
699
|
+
look: "pencil",
|
|
700
|
+
ink: o,
|
|
701
|
+
limb(d, u, y) {
|
|
702
|
+
m(d, (p) => u + (y - u) * p);
|
|
703
|
+
},
|
|
704
|
+
line(d, u) {
|
|
705
|
+
m(d, () => u);
|
|
706
|
+
},
|
|
707
|
+
shape(d, u, y) {
|
|
708
|
+
u !== null && (t.save(), t.globalAlpha *= 0.88, t.fillStyle = u, bt(t, d, !0), t.fill(), t.restore()), y > 0 && m([...d, d[0]], () => y);
|
|
709
|
+
},
|
|
710
|
+
ellipse(d, u, y, p, x, E, b) {
|
|
711
|
+
E !== null && (t.save(), t.globalAlpha *= 0.9, t.fillStyle = E, t.beginPath(), t.ellipse(d, u, y, p, x, 0, Math.PI * 2), t.fill(), t.restore()), c(d, u, y, p, x, b);
|
|
712
|
+
},
|
|
713
|
+
dot(d, u, y) {
|
|
714
|
+
t.save(), t.globalAlpha *= 0.9, t.fillStyle = o, t.beginPath(), t.arc(d, u, y, 0, Math.PI * 2), t.fill(), t.restore();
|
|
715
|
+
},
|
|
716
|
+
guide(d) {
|
|
717
|
+
if (n.construction === !1 || d.length < 2) return;
|
|
718
|
+
const u = a++;
|
|
719
|
+
g(d, () => Math.max(0.6, e.lineWidth * 0.18), f(u, 0), 0.28, s * 1.2, e.lineWidth);
|
|
720
|
+
},
|
|
721
|
+
guideEllipse(d, u, y, p, x) {
|
|
722
|
+
if (n.construction === !1) return;
|
|
723
|
+
const E = a++, b = f(E, 0), M = ne(d, u, y, p, x, b.next() * Math.PI * 2, 1.12, 48);
|
|
724
|
+
g(M, () => Math.max(0.6, e.lineWidth * 0.18), b, 0.28, s * 1.5);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const _n = "#f1c9a5", Hn = "#2f2f33";
|
|
729
|
+
function xe(t, e, n, o = {}, s = 0) {
|
|
730
|
+
const r = Pn(Ft(n, o), e), h = o.ink ?? Hn, i = o.lineWidth ?? r.size * 0.035, l = o.pen ?? ke(t, {
|
|
731
|
+
look: o.look ?? "clean",
|
|
732
|
+
ink: h,
|
|
733
|
+
lineWidth: i,
|
|
734
|
+
seed: o.seed ?? 1,
|
|
735
|
+
time: s,
|
|
736
|
+
pencil: { construction: !1, ...o.pencil }
|
|
737
|
+
}), a = o.skin ?? _n, f = o.nails ?? !0, g = [
|
|
738
|
+
{
|
|
739
|
+
depth: r.palmDepth,
|
|
740
|
+
draw: () => Wn(l, r, a, i)
|
|
741
|
+
}
|
|
742
|
+
];
|
|
743
|
+
for (const m of Object.values(r.fingers)) {
|
|
744
|
+
const c = m.depths.reduce((d, u) => d + u, 0) / m.depths.length;
|
|
745
|
+
g.push({
|
|
746
|
+
depth: c,
|
|
747
|
+
draw: () => $n(t, l, m, a, i, f)
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
if (o.prop) {
|
|
751
|
+
const m = o.prop;
|
|
752
|
+
g.push({ depth: m.depth, draw: () => m.draw(l) });
|
|
753
|
+
}
|
|
754
|
+
t.save(), t.lineCap = "round", t.lineJoin = "round";
|
|
755
|
+
for (const m of [...g].sort((c, d) => c.depth - d.depth)) m.draw();
|
|
756
|
+
return t.restore(), r;
|
|
757
|
+
}
|
|
758
|
+
function Wn(t, e, n, o) {
|
|
759
|
+
if (t.shape(e.palm, n, o), e.palmFacing < -0.3 && t.look !== "silhouette") {
|
|
760
|
+
const { up: s } = e.axes;
|
|
761
|
+
for (const [r, h] of Object.entries(e.fingers)) {
|
|
762
|
+
const i = e.curls[r] ?? 0;
|
|
763
|
+
if (r === "thumb" || i < 0.5) continue;
|
|
764
|
+
const l = h.points[0], a = h.widths[0] * 0.42, f = { x: l.x - s.x * a * 0.2, y: l.y - s.y * a * 0.2 }, g = Math.atan2(s.y, s.x), m = Array.from({ length: 7 }, (c, d) => {
|
|
765
|
+
const u = g - Math.PI / 2 + Math.PI * d / 6;
|
|
766
|
+
return { x: f.x + Math.cos(u) * a, y: f.y + Math.sin(u) * a };
|
|
767
|
+
});
|
|
768
|
+
t.line(m, o * 0.6);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
if (e.palmFacing > 0.45 && t.look !== "silhouette") {
|
|
772
|
+
const { up: s, across: r } = e.axes, h = e.size, i = e.wrist, l = (f, g) => ({
|
|
773
|
+
x: i.x + (r.x * f + s.x * g) * h,
|
|
774
|
+
y: i.y + (r.y * f + s.y * g) * h
|
|
775
|
+
}), a = e.side === "left" ? -1 : 1;
|
|
776
|
+
t.line([l(-0.15 * a, 0.36), l(-0.04 * a, 0.3), l(0.1 * a, 0.33)], o * 0.5);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
function $n(t, e, n, o, s, r) {
|
|
780
|
+
const { widths: h } = n, i = Rn(n.points, 2), l = n.points[0], a = i[i.length - 1], f = h[0], g = h[h.length - 1];
|
|
781
|
+
if (t.save(), e.look !== "silhouette") {
|
|
782
|
+
t.beginPath(), t.rect(l.x - 1e5, l.y - 1e5, 2e5, 2e5);
|
|
783
|
+
const u = f / 2 + s * 1.6;
|
|
784
|
+
t.moveTo(l.x + u, l.y), t.arc(l.x, l.y, u, 0, Math.PI * 2), t.clip("evenodd");
|
|
785
|
+
}
|
|
786
|
+
if (e.limb(i, f + 2 * s, g + 2 * s), t.restore(), e.look !== "silhouette" && (t.fillStyle = o, Xt(t, i, f, g)), e.look === "silhouette" || !r || n.nail < 0.25) return;
|
|
787
|
+
const m = i[i.length - 2], c = Bn({ x: a.x - m.x, y: a.y - m.y }) ?? {
|
|
788
|
+
x: 0,
|
|
789
|
+
y: -1
|
|
790
|
+
}, d = {
|
|
791
|
+
x: a.x - c.x * g * 0.22 + n.back.x * g * 0.1,
|
|
792
|
+
y: a.y - c.y * g * 0.22 + n.back.y * g * 0.1
|
|
793
|
+
};
|
|
794
|
+
e.ellipse(d.x, d.y, g * 0.24 * Math.max(0.35, n.nail), g * 0.19, Math.atan2(c.y, c.x), "#f8e3d3", s * 0.45);
|
|
795
|
+
}
|
|
796
|
+
function Rn(t, e) {
|
|
797
|
+
let n = t;
|
|
798
|
+
for (let o = 0; o < e; o++) {
|
|
799
|
+
if (n.length < 3) return n;
|
|
800
|
+
const s = [n[0]];
|
|
801
|
+
for (let r = 0; r < n.length - 1; r++) {
|
|
802
|
+
const h = n[r], i = n[r + 1];
|
|
803
|
+
r > 0 && s.push({ x: h.x * 0.75 + i.x * 0.25, y: h.y * 0.75 + i.y * 0.25 }), r < n.length - 2 && s.push({ x: h.x * 0.25 + i.x * 0.75, y: h.y * 0.25 + i.y * 0.75 });
|
|
804
|
+
}
|
|
805
|
+
s.push(n[n.length - 1]), n = s;
|
|
806
|
+
}
|
|
807
|
+
return n;
|
|
808
|
+
}
|
|
809
|
+
const Bn = (t) => {
|
|
810
|
+
const e = Math.hypot(t.x, t.y);
|
|
811
|
+
return e > 1e-6 ? { x: t.x / e, y: t.y / e } : null;
|
|
812
|
+
};
|
|
813
|
+
function Yn(t, e, n = {}, o) {
|
|
814
|
+
const s = n.length ?? 240, r = 9, h = 28, i = s - 22;
|
|
815
|
+
t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -30) * Math.PI / 180), t.fillStyle = n.color ?? "#f4c542", t.fillRect(h, -r, i - h, 2 * r), t.fillStyle = "#e8b4a0", t.fillRect(i, -r, s - i, 2 * r), t.fillStyle = "#f1dcbf", t.beginPath(), t.moveTo(0, 0), t.lineTo(h, -r), t.lineTo(h, r), t.closePath(), t.fill(), t.fillStyle = n.outline ?? "#2f2f33", t.beginPath(), t.moveTo(0, 0), t.lineTo(h * 0.35, -r * 0.35), t.lineTo(h * 0.35, r * 0.35), t.closePath(), t.fill(), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round", t.lineCap = "round";
|
|
424
816
|
const l = [
|
|
425
|
-
[{ x: 0, y: 0 }, { x: h, y: -
|
|
426
|
-
[{ x: h, y: -
|
|
427
|
-
[{ x: i, y: -
|
|
817
|
+
[{ x: 0, y: 0 }, { x: h, y: -r }, { x: s, y: -r }, { x: s, y: r }, { x: h, y: r }, { x: 0, y: 0 }],
|
|
818
|
+
[{ x: h, y: -r }, { x: h, y: r }],
|
|
819
|
+
[{ x: i, y: -r }, { x: i, y: r }]
|
|
428
820
|
];
|
|
429
|
-
for (const a of l)
|
|
821
|
+
for (const a of l) Te(t, a, o);
|
|
430
822
|
t.restore();
|
|
431
823
|
}
|
|
432
|
-
function
|
|
433
|
-
const
|
|
824
|
+
function Ee(t, e, n = {}, o) {
|
|
825
|
+
const s = n.length ?? 90, r = n.thickness ?? 34;
|
|
434
826
|
t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -35) * Math.PI / 180);
|
|
435
|
-
const h = -
|
|
436
|
-
t.fillStyle = n.color ?? "#f4a7b9", t.fillRect(0, h,
|
|
827
|
+
const h = -r / 2;
|
|
828
|
+
t.fillStyle = n.color ?? "#f4a7b9", t.fillRect(0, h, s, r), t.fillStyle = "#e9edf2", t.fillRect(s * 0.45, h, s * 0.55, r), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round";
|
|
437
829
|
const i = [
|
|
438
830
|
{ x: 0, y: h },
|
|
439
|
-
{ x:
|
|
440
|
-
{ x:
|
|
831
|
+
{ x: s, y: h },
|
|
832
|
+
{ x: s, y: -h },
|
|
441
833
|
{ x: 0, y: -h },
|
|
442
834
|
{ x: 0, y: h }
|
|
443
|
-
], l = [{ x:
|
|
835
|
+
], l = [{ x: s * 0.45, y: h }, { x: s * 0.45, y: -h }];
|
|
444
836
|
if (o)
|
|
445
837
|
o.line(i), o.line(l);
|
|
446
838
|
else
|
|
447
839
|
for (const a of [i, l]) {
|
|
448
840
|
t.beginPath(), t.moveTo(a[0].x, a[0].y);
|
|
449
|
-
for (const
|
|
841
|
+
for (const f of a.slice(1)) t.lineTo(f.x, f.y);
|
|
450
842
|
t.stroke();
|
|
451
843
|
}
|
|
452
844
|
t.restore();
|
|
453
845
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
846
|
+
const Se = 150, Ln = { pencil: 44, eraser: 30 };
|
|
847
|
+
function Pe(t, e, n = {}, o) {
|
|
848
|
+
const s = n.tool ?? "pencil", r = n.skin ?? "#f1c9a5", h = n.outline ?? "#2f2f33", i = n.scale ?? 1, l = Math.min(1, Math.max(0, n.lift ?? 0)), a = (n.angle ?? -30) * Math.PI / 180, f = o ? o.nudge(0.6) : { x: 0, y: 0 }, g = Se * i * (1 + 0.05 * l);
|
|
849
|
+
l > 0 && (t.save(), t.fillStyle = h, t.globalAlpha = 0.15 * l, t.beginPath(), t.ellipse(e.x, e.y, 9 * i, 4 * i, 0, 0, Math.PI * 2), t.fill(), t.restore());
|
|
850
|
+
const m = { x: e.x + f.x + 6 * l * i, y: e.y + f.y - 18 * l * i }, c = un.pencilGrip, d = (P) => {
|
|
851
|
+
const I = P.fingers.thumb, O = P.fingers.index, H = P.fingers.middle, _ = se([I.points[3], O.points[3], H.points[3]]), k = se([I.points[1], O.points[0]]), w = (I.depths[3] + O.depths[3] + H.depths[3]) / 3;
|
|
852
|
+
return { pinch: _, direction: Math.atan2(k.y - _.y, k.x - _.x), depth: w };
|
|
853
|
+
}, u = Ft(c, { size: g }), y = a - d(u).direction, p = Ft(c, { size: g, angle: y * 180 / Math.PI }), x = d(p), E = Ln[s] * i, b = { x: x.pinch.x - Math.cos(a) * E, y: x.pinch.y - Math.sin(a) * E }, M = { x: m.x - b.x, y: m.y - b.y }, T = p.axes.up;
|
|
854
|
+
Fn(t, M, { x: -T.x, y: -T.y }, g, n.arm ?? 300 * i, r, n.sleeve ?? "#5b7db1", h), xe(t, M, c, {
|
|
855
|
+
size: g,
|
|
856
|
+
angle: y * 180 / Math.PI,
|
|
857
|
+
skin: r,
|
|
858
|
+
ink: h,
|
|
859
|
+
lineWidth: 3 * i,
|
|
860
|
+
prop: {
|
|
861
|
+
depth: x.depth,
|
|
862
|
+
draw: () => {
|
|
863
|
+
t.save(), t.translate(m.x, m.y), t.scale(i, i), s === "eraser" ? Ee(t, { x: 0, y: 0 }, { angle: a * 180 / Math.PI, outline: h }, o) : Yn(t, { x: 0, y: 0 }, { angle: a * 180 / Math.PI, length: 190, outline: h }, o), t.restore();
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
const se = (t) => ({
|
|
869
|
+
x: t.reduce((e, n) => e + n.x, 0) / t.length,
|
|
870
|
+
y: t.reduce((e, n) => e + n.y, 0) / t.length
|
|
871
|
+
});
|
|
872
|
+
function Fn(t, e, n, o, s, r, h, i) {
|
|
873
|
+
const l = { x: -n.y, y: n.x }, a = o * 0.15, f = (u, y, p) => ({
|
|
874
|
+
x: e.x + n.x * u + l.x * y * p,
|
|
875
|
+
y: e.y + n.y * u + l.y * y * p
|
|
876
|
+
}), g = f(s, 0, 0), m = (u) => {
|
|
877
|
+
const y = t.createLinearGradient(e.x, e.y, g.x, g.y);
|
|
878
|
+
return y.addColorStop(0, u), y.addColorStop(0.6, u), y.addColorStop(1, Nn(u)), y;
|
|
879
|
+
}, c = Math.min(o * 0.55, s * 0.35);
|
|
880
|
+
t.save(), t.lineJoin = "round", t.lineCap = "round", t.lineWidth = 3 * (o / Se), t.beginPath(), t.moveTo(f(-o * 0.1, -1, a).x, f(-o * 0.1, -1, a).y), t.lineTo(f(c + 4, -1, a * 1.1).x, f(c + 4, -1, a * 1.1).y), t.lineTo(f(c + 4, 1, a * 1.1).x, f(c + 4, 1, a * 1.1).y), t.lineTo(f(-o * 0.1, 1, a).x, f(-o * 0.1, 1, a).y), t.closePath(), t.fillStyle = r, t.fill(), t.strokeStyle = i, t.beginPath(), t.moveTo(f(0, -1, a).x, f(0, -1, a).y), t.lineTo(f(c, -1, a * 1.1).x, f(c, -1, a * 1.1).y), t.moveTo(f(0, 1, a).x, f(0, 1, a).y), t.lineTo(f(c, 1, a * 1.1).x, f(c, 1, a * 1.1).y), t.stroke();
|
|
881
|
+
const d = [f(c, -1, a * 1.3), f(s, -1, a * 1.5), f(s, 1, a * 1.5), f(c, 1, a * 1.3)];
|
|
882
|
+
t.beginPath(), d.forEach((u, y) => y ? t.lineTo(u.x, u.y) : t.moveTo(u.x, u.y)), t.closePath(), t.fillStyle = m(h), t.fill(), t.strokeStyle = m(i), t.beginPath(), t.moveTo(d[1].x, d[1].y), t.lineTo(d[0].x, d[0].y), t.lineTo(d[3].x, d[3].y), t.lineTo(d[2].x, d[2].y), t.stroke(), t.restore();
|
|
883
|
+
}
|
|
884
|
+
function ko(t, e, n = {}) {
|
|
885
|
+
const o = n.offstage ?? { x: 2e3, y: 1400 }, s = n.enter ?? 450, r = n.exit ?? 450, h = n.linger ?? 1500, i = [...t].filter((u) => u.path.length > 0).sort((u, y) => u.start - y.start), l = (u) => u.tool ?? "pencil", a = (u) => {
|
|
886
|
+
const y = Math.min(1, Math.max(0, u));
|
|
887
|
+
return y * y * (3 - 2 * y);
|
|
888
|
+
}, f = (u, y, p) => ({ x: u.x + (y.x - u.x) * p, y: u.y + (y.y - u.y) * p }), g = i.find((u) => e >= u.start && e <= u.end);
|
|
889
|
+
if (g) {
|
|
890
|
+
const u = g.end - g.start, y = u > 0 ? (e - g.start) / u : 1;
|
|
891
|
+
return { at: Ut(g.path, y), tool: l(g), lift: 0, drawing: !0 };
|
|
892
|
+
}
|
|
893
|
+
const m = [...i].reverse().find((u) => u.end < e), c = i.find((u) => u.start > e), d = (u) => u.path[u.path.length - 1];
|
|
894
|
+
if (m && c && c.start - m.end <= h) {
|
|
895
|
+
const u = (e - m.end) / (c.start - m.end), y = u < 0.5 ? l(m) : l(c);
|
|
896
|
+
return { at: f(d(m), c.path[0], a(u)), tool: y, lift: Math.sin(Math.PI * u), drawing: !1 };
|
|
897
|
+
}
|
|
898
|
+
if (c && c.start - e <= s) {
|
|
899
|
+
const u = 1 - (c.start - e) / s;
|
|
900
|
+
return { at: f(o, c.path[0], a(u)), tool: l(c), lift: 1 - a(u), drawing: !1 };
|
|
901
|
+
}
|
|
902
|
+
if (m && e - m.end <= r) {
|
|
903
|
+
const u = (e - m.end) / r;
|
|
904
|
+
return { at: f(d(m), o, a(u)), tool: l(m), lift: a(u), drawing: !1 };
|
|
905
|
+
}
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
function xo(t, e, n, o = 0.08, s = 32) {
|
|
909
|
+
const r = Math.PI * 2 * (1 + o), h = [];
|
|
910
|
+
for (let i = 0; i <= s; i++) {
|
|
911
|
+
const l = -Math.PI / 2 + r * i / s;
|
|
472
912
|
h.push({ x: t + Math.cos(l) * n, y: e + Math.sin(l) * n });
|
|
473
913
|
}
|
|
474
914
|
return h;
|
|
475
915
|
}
|
|
476
|
-
function
|
|
477
|
-
const { path: e } = t, n = e.map((i) => i.x), o = e.map((i) => i.y),
|
|
916
|
+
function Eo(t) {
|
|
917
|
+
const { path: e } = t, n = e.map((i) => i.x), o = e.map((i) => i.y), s = Math.min(...n), r = Math.min(...o), h = t.hand === !1 ? void 0 : t.hand === !0 || t.hand === void 0 ? {} : t.hand;
|
|
478
918
|
return {
|
|
479
919
|
type: "custom",
|
|
480
|
-
x:
|
|
481
|
-
y:
|
|
482
|
-
width: Math.max(1, Math.max(...n) -
|
|
483
|
-
height: Math.max(1, Math.max(...o) -
|
|
920
|
+
x: s,
|
|
921
|
+
y: r,
|
|
922
|
+
width: Math.max(1, Math.max(...n) - s),
|
|
923
|
+
height: Math.max(1, Math.max(...o) - r),
|
|
484
924
|
props: { draw: 0 },
|
|
485
925
|
draw(i, l, a) {
|
|
486
|
-
const
|
|
487
|
-
i.translate(-
|
|
488
|
-
const g = t.sketch ?
|
|
489
|
-
|
|
926
|
+
const f = Math.min(1, Math.max(0, Number(l.props?.draw ?? 0)));
|
|
927
|
+
i.translate(-s, -r), i.strokeStyle = t.color ?? "#2f2f33", i.lineWidth = t.lineWidth ?? 5, i.lineCap = "round", i.lineJoin = "round";
|
|
928
|
+
const g = t.sketch ? Ht(i, t.sketch, a) : void 0;
|
|
929
|
+
f > 0 && (g ? t.smooth ? g.curve(e, f) : g.line(e, f) : Te(i, ae(e, f))), h && f > 0 && f < 1 && Pe(i, Ut(e, f), h, g);
|
|
490
930
|
}
|
|
491
931
|
};
|
|
492
932
|
}
|
|
493
|
-
function
|
|
933
|
+
function Nn(t) {
|
|
934
|
+
const e = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(t.trim());
|
|
935
|
+
if (!e) return "rgba(0, 0, 0, 0)";
|
|
936
|
+
const n = e[1].length === 3 ? [...e[1]].map((h) => h + h).join("") : e[1], [o, s, r] = [0, 2, 4].map((h) => parseInt(n.slice(h, h + 2), 16));
|
|
937
|
+
return `rgba(${o}, ${s}, ${r}, 0)`;
|
|
938
|
+
}
|
|
939
|
+
function Te(t, e, n) {
|
|
494
940
|
if (!(e.length < 2)) {
|
|
495
941
|
if (n) return n.line(e);
|
|
496
942
|
t.beginPath(), t.moveTo(e[0].x, e[0].y);
|
|
@@ -498,352 +944,217 @@ function he(t, e, n) {
|
|
|
498
944
|
t.stroke();
|
|
499
945
|
}
|
|
500
946
|
}
|
|
501
|
-
const
|
|
502
|
-
function
|
|
503
|
-
const
|
|
947
|
+
const ft = 1e5;
|
|
948
|
+
function So(t, e, n, o, s = 6) {
|
|
949
|
+
const r = [], h = Math.max(1, Math.round(s));
|
|
504
950
|
for (let i = 0; i <= h; i++)
|
|
505
|
-
|
|
506
|
-
return
|
|
951
|
+
r.push({ x: i % 2 === 0 ? t : t + n, y: e + o * i / h });
|
|
952
|
+
return r;
|
|
507
953
|
}
|
|
508
|
-
function
|
|
954
|
+
function ve(t, e, n, o) {
|
|
509
955
|
if (o <= 0 || e.length === 0) return;
|
|
510
|
-
const
|
|
511
|
-
t.beginPath(), t.rect(-
|
|
956
|
+
const s = ae(e, o), r = n / 2, h = (i) => {
|
|
957
|
+
t.beginPath(), t.rect(-ft, -ft, 2 * ft, 2 * ft), i(), t.clip("evenodd");
|
|
512
958
|
};
|
|
513
|
-
for (const i of
|
|
959
|
+
for (const i of s)
|
|
514
960
|
h(() => {
|
|
515
|
-
t.moveTo(i.x +
|
|
961
|
+
t.moveTo(i.x + r, i.y), t.arc(i.x, i.y, r, 0, Math.PI * 2);
|
|
516
962
|
});
|
|
517
|
-
for (let i = 1; i <
|
|
518
|
-
const l =
|
|
519
|
-
if (
|
|
520
|
-
const g = -(a.y - l.y) /
|
|
963
|
+
for (let i = 1; i < s.length; i++) {
|
|
964
|
+
const l = s[i - 1], a = s[i], f = Math.hypot(a.x - l.x, a.y - l.y);
|
|
965
|
+
if (f === 0) continue;
|
|
966
|
+
const g = -(a.y - l.y) / f * r, m = (a.x - l.x) / f * r;
|
|
521
967
|
h(() => {
|
|
522
|
-
t.moveTo(l.x + g, l.y +
|
|
968
|
+
t.moveTo(l.x + g, l.y + m), t.lineTo(a.x + g, a.y + m), t.lineTo(a.x - g, a.y - m), t.lineTo(l.x - g, l.y - m), t.closePath();
|
|
523
969
|
});
|
|
524
970
|
}
|
|
525
971
|
}
|
|
526
|
-
function
|
|
527
|
-
t.save(),
|
|
972
|
+
function Po(t, e, n, o, s) {
|
|
973
|
+
t.save(), ve(t, e, n, o), s(), t.restore();
|
|
528
974
|
}
|
|
529
|
-
function
|
|
530
|
-
const n = e.width ?? 40, o = e.hand === !0 ? {} : e.hand || void 0,
|
|
975
|
+
function To(t, e) {
|
|
976
|
+
const n = e.width ?? 40, o = e.hand === !0 ? {} : e.hand || void 0, s = e.eraser === !1 ? void 0 : e.eraser === !0 || e.eraser === void 0 ? {} : e.eraser;
|
|
531
977
|
return {
|
|
532
978
|
...t,
|
|
533
979
|
props: { ...t.props, erase: 0 },
|
|
534
|
-
draw(
|
|
980
|
+
draw(r, h, i) {
|
|
535
981
|
const l = Number(h.props?.erase ?? 0);
|
|
536
|
-
if (
|
|
537
|
-
const a =
|
|
538
|
-
o ?
|
|
982
|
+
if (r.save(), ve(r, e.path, n, l), t.draw(r, h, i), r.restore(), !s || l <= 0 || l >= 1) return;
|
|
983
|
+
const a = Ut(e.path, l);
|
|
984
|
+
o ? Pe(r, a, { ...o, tool: "eraser" }) : Ee(r, a, s);
|
|
539
985
|
}
|
|
540
986
|
};
|
|
541
987
|
}
|
|
542
|
-
const
|
|
543
|
-
function
|
|
544
|
-
const
|
|
545
|
-
return [t, e *
|
|
988
|
+
const K = (t) => t * Math.PI / 180;
|
|
989
|
+
function Ie([t, e, n], o) {
|
|
990
|
+
const s = Math.cos(o), r = Math.sin(o);
|
|
991
|
+
return [t, e * s + n * r, -e * r + n * s];
|
|
546
992
|
}
|
|
547
|
-
function
|
|
548
|
-
const
|
|
549
|
-
return [t *
|
|
993
|
+
function Ae([t, e, n], o) {
|
|
994
|
+
const s = Math.cos(o), r = Math.sin(o);
|
|
995
|
+
return [t * s - e * r, t * r + e * s, n];
|
|
550
996
|
}
|
|
551
|
-
function
|
|
552
|
-
const
|
|
553
|
-
return [t *
|
|
997
|
+
function ht([t, e, n], o) {
|
|
998
|
+
const s = Math.cos(o), r = Math.sin(o);
|
|
999
|
+
return [t * s + n * r, e, -t * r + n * s];
|
|
554
1000
|
}
|
|
555
|
-
const
|
|
556
|
-
function
|
|
557
|
-
const n =
|
|
1001
|
+
const Tt = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], re = (t, e) => [t[0] * e, t[1] * e, t[2] * e], pt = (t, e) => Ae(Ie(t, e.swing), e.spread);
|
|
1002
|
+
function vt(t, e) {
|
|
1003
|
+
const n = ht(t, e);
|
|
558
1004
|
return { point: { x: n[0], y: -n[1] }, depth: n[2] };
|
|
559
1005
|
}
|
|
560
|
-
function
|
|
561
|
-
const o = n.height,
|
|
562
|
-
for (const
|
|
563
|
-
const
|
|
564
|
-
if (
|
|
565
|
-
const v =
|
|
566
|
-
let
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
}), i[
|
|
1006
|
+
function Dt(t, e, n) {
|
|
1007
|
+
const o = n.height, s = K(90 * (e.turn ?? 0)), h = [0, t.hipHeight * o * (t.boneScale?.(e, null) ?? 1), 0], i = {};
|
|
1008
|
+
for (const w of t.chains) {
|
|
1009
|
+
const S = w.parent ? i[w.parent] : void 0;
|
|
1010
|
+
if (w.parent && !S) throw new Error(`body plan ${t.id}: chain ${w.id} comes before its parent ${w.parent}`);
|
|
1011
|
+
const v = w.at ?? (S ? S.joints3.length - 1 : 0), A = S ? S.joints3[v] : h, W = S ? S.frames[Math.max(0, v - 1)] : { swing: 0, spread: 0 }, nt = w.offset ? Tt(A, pt(re(w.offset, o), W)) : A, at = w.side ?? 1, xt = t.boneScale?.(e, w) ?? 1, Et = t.angles(e, w), q = [nt], ot = [];
|
|
1012
|
+
let Z = W.swing, St = W.spread;
|
|
1013
|
+
w.bones.forEach((_e, Kt) => {
|
|
1014
|
+
const Pt = Et[Kt] ?? { swing: 0, spread: 0 };
|
|
1015
|
+
Z += K(Pt.swing), St += K(Pt.spread) * at, ot.push({ swing: Z, spread: St });
|
|
1016
|
+
const He = ht(pt(w.rest, { swing: Z, spread: St }), K(Pt.yaw ?? 0));
|
|
1017
|
+
q.push(Tt(q[Kt], re(He, _e.length * o * xt)));
|
|
1018
|
+
}), i[w.id] = { joints3: q, frames: ot };
|
|
573
1019
|
}
|
|
574
|
-
const l = i[t.head.on], a = t.headPose?.(e) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 },
|
|
575
|
-
for (const
|
|
576
|
-
const { joints3:
|
|
577
|
-
|
|
578
|
-
id:
|
|
579
|
-
joints3:
|
|
1020
|
+
const l = i[t.head.on], a = t.headPose?.(e) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 }, f = l.frames[l.frames.length - 1], g = t.head.size / 2 * o, m = g * a.sx, c = g * a.sy, d = (w) => pt(ht(Ie(Ae(w, -K(a.tilt)), -K(a.nod)), K(a.yaw)), f), u = Tt(l.joints3[l.joints3.length - 1], d([0, c, 0])), y = {};
|
|
1021
|
+
for (const w of t.chains) {
|
|
1022
|
+
const { joints3: S, frames: v } = i[w.id], A = S.map((W) => vt(W, s));
|
|
1023
|
+
y[w.id] = {
|
|
1024
|
+
id: w.id,
|
|
1025
|
+
joints3: S,
|
|
580
1026
|
frames: v,
|
|
581
|
-
points:
|
|
582
|
-
depths:
|
|
1027
|
+
points: A.map((W) => W.point),
|
|
1028
|
+
depths: A.map((W) => W.depth)
|
|
583
1029
|
};
|
|
584
1030
|
}
|
|
585
|
-
const
|
|
586
|
-
const
|
|
587
|
-
return { x: E.x +
|
|
588
|
-
},
|
|
589
|
-
for (const
|
|
590
|
-
const
|
|
591
|
-
center: M(
|
|
592
|
-
depth:
|
|
593
|
-
rx:
|
|
594
|
-
ry:
|
|
1031
|
+
const p = vt(u, s), x = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map((w) => ht(d(w), s)), E = vt(h, s).point, b = K(e.roll ?? 0), M = (w) => {
|
|
1032
|
+
const S = w.x - E.x, v = w.y - E.y;
|
|
1033
|
+
return { x: E.x + S * Math.cos(b) - v * Math.sin(b), y: E.y + S * Math.sin(b) + v * Math.cos(b) };
|
|
1034
|
+
}, T = ([w, S, v]) => [w * Math.cos(b) + S * Math.sin(b), -w * Math.sin(b) + S * Math.cos(b), v];
|
|
1035
|
+
for (const w of Object.values(y)) w.points = w.points.map(M);
|
|
1036
|
+
const P = {
|
|
1037
|
+
center: M(p.point),
|
|
1038
|
+
depth: p.depth,
|
|
1039
|
+
rx: m,
|
|
1040
|
+
ry: c,
|
|
595
1041
|
angle: 0,
|
|
596
|
-
axes:
|
|
597
|
-
},
|
|
598
|
-
|
|
599
|
-
const
|
|
600
|
-
if ("head" in
|
|
601
|
-
const
|
|
602
|
-
return
|
|
1042
|
+
axes: x.map(T)
|
|
1043
|
+
}, I = P.axes[1];
|
|
1044
|
+
P.angle = Math.atan2(I[0], I[1]);
|
|
1045
|
+
const O = (w) => {
|
|
1046
|
+
if ("head" in w) return { x: P.center.x + I[0] * c, y: P.center.y - I[1] * c };
|
|
1047
|
+
const S = y[w.chain];
|
|
1048
|
+
return S.points[Math.min(w.joint, S.points.length - 1)];
|
|
603
1049
|
};
|
|
604
|
-
let
|
|
605
|
-
(n.contact ?? "ground") === "ground" && (
|
|
606
|
-
const
|
|
607
|
-
for (const
|
|
608
|
-
|
|
609
|
-
const
|
|
1050
|
+
let H = 0;
|
|
1051
|
+
(n.contact ?? "ground") === "ground" && (H = -Math.max(...t.contacts.map((w) => O(w).y))), H -= (e.lift ?? 0) * o;
|
|
1052
|
+
const _ = (w) => ({ x: w.x, y: w.y + H });
|
|
1053
|
+
for (const w of Object.values(y)) w.points = w.points.map(_);
|
|
1054
|
+
P.center = _(P.center);
|
|
1055
|
+
const k = t.contacts.map((w) => ({ spec: w, point: O(w) }));
|
|
610
1056
|
return {
|
|
611
1057
|
height: o,
|
|
612
|
-
view:
|
|
613
|
-
chains:
|
|
614
|
-
head:
|
|
615
|
-
hip:
|
|
616
|
-
contacts:
|
|
617
|
-
groundY: Math.max(...
|
|
1058
|
+
view: s,
|
|
1059
|
+
chains: y,
|
|
1060
|
+
head: P,
|
|
1061
|
+
hip: _(M(E)),
|
|
1062
|
+
contacts: k,
|
|
1063
|
+
groundY: Math.max(...k.map((w) => w.point.y))
|
|
618
1064
|
};
|
|
619
1065
|
}
|
|
620
|
-
function
|
|
621
|
-
const [
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
], l = Math.hypot(e, n, o) || 1, a = (
|
|
1066
|
+
function Oe(t, [e, n, o]) {
|
|
1067
|
+
const [s, r, h] = t.axes, i = [
|
|
1068
|
+
s[0] * e * t.rx + r[0] * n * t.ry + h[0] * o * t.rx,
|
|
1069
|
+
s[1] * e * t.rx + r[1] * n * t.ry + h[1] * o * t.rx,
|
|
1070
|
+
s[2] * e * t.rx + r[2] * n * t.ry + h[2] * o * t.rx
|
|
1071
|
+
], l = Math.hypot(e, n, o) || 1, a = (s[2] * e + r[2] * n + h[2] * o) / l;
|
|
626
1072
|
return { point: { x: t.center.x + i[0], y: t.center.y - i[1] }, depth: t.depth + i[2], facing: a };
|
|
627
1073
|
}
|
|
628
|
-
const
|
|
629
|
-
const e =
|
|
1074
|
+
const dt = (t) => t * 180 / Math.PI, Q = (t, e) => [t[0] - e[0], t[1] - e[1], t[2] - e[2]], It = (t, e) => t[0] * e[0] + t[1] * e[1] + t[2] * e[2], it = (t) => Math.hypot(t[0], t[1], t[2]), Nt = (t) => {
|
|
1075
|
+
const e = it(t) || 1;
|
|
630
1076
|
return [t[0] / e, t[1] / e, t[2] / e];
|
|
631
|
-
},
|
|
632
|
-
function
|
|
633
|
-
const [e, n, o] =
|
|
1077
|
+
}, ut = (t) => Math.atan2(Math.sin(t), Math.cos(t));
|
|
1078
|
+
function ie(t) {
|
|
1079
|
+
const [e, n, o] = Nt(t);
|
|
634
1080
|
return { swing: Math.asin(Math.max(-1, Math.min(1, o))), spread: Math.atan2(e, -n) };
|
|
635
1081
|
}
|
|
636
|
-
function
|
|
637
|
-
const
|
|
638
|
-
if (!
|
|
639
|
-
if (
|
|
1082
|
+
function Cn(t, e, n, o, s) {
|
|
1083
|
+
const r = t.chains.find((H) => H.id === n);
|
|
1084
|
+
if (!r) throw new Error(`reach: no chain ${n} in ${t.id}`);
|
|
1085
|
+
if (r.bones.length < 2 || r.rest[1] > -0.99) throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);
|
|
640
1086
|
if (!t.withAngles) throw new Error(`reach: the ${t.id} plan cannot set angles`);
|
|
641
|
-
const h =
|
|
642
|
-
let
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
l[0] + a * (
|
|
646
|
-
l[1] + a * (
|
|
647
|
-
l[2] + a * (
|
|
648
|
-
], M = [l[0] + d[0] *
|
|
649
|
-
{ swing:
|
|
650
|
-
{ swing:
|
|
1087
|
+
const h = Dt(t, { ...e, turn: 0, roll: 0, lift: 0 }, { height: s.height, contact: "none" }), i = h.chains[n], l = i.joints3[0], a = it(Q(i.joints3[1], i.joints3[0])), f = it(Q(i.joints3[2], i.joints3[1])), g = r.parent ? h.chains[r.parent].frames[Math.max(0, (r.at ?? h.chains[r.parent].joints3.length - 1) - 1)] : { swing: 0, spread: 0 }, m = Q(o, l), c = Math.min(a + f - 1e-6, Math.max(Math.abs(a - f) + 1e-6, it(m))), d = Nt(m), u = r.parent !== null, y = pt(r.pole ?? (u ? [0, -0.35, -1] : [0, 0, 1]), g);
|
|
1088
|
+
let p = Q(y, [d[0] * It(y, d), d[1] * It(y, d), d[2] * It(y, d)]);
|
|
1089
|
+
it(p) < 1e-6 && (p = ht([1, 0, 0], 0)), p = Nt(p);
|
|
1090
|
+
const x = (a * a + c * c - f * f) / (2 * a * c), E = Math.sqrt(Math.max(0, 1 - x * x)), b = [
|
|
1091
|
+
l[0] + a * (x * d[0] + E * p[0]),
|
|
1092
|
+
l[1] + a * (x * d[1] + E * p[1]),
|
|
1093
|
+
l[2] + a * (x * d[2] + E * p[2])
|
|
1094
|
+
], M = [l[0] + d[0] * c, l[1] + d[1] * c, l[2] + d[2] * c], T = r.side ?? 1, P = ie(Q(b, l)), I = ie(Q(M, b)), O = [
|
|
1095
|
+
{ swing: dt(ut(P.swing - g.swing)), spread: dt(ut(P.spread - g.spread)) * T },
|
|
1096
|
+
{ swing: dt(ut(I.swing - P.swing)), spread: dt(ut(I.spread - P.spread)) * T }
|
|
651
1097
|
];
|
|
652
|
-
return t.withAngles(e,
|
|
653
|
-
}
|
|
654
|
-
function Xt(t, e, n, o, r, s = 0, h = 1, i = 40) {
|
|
655
|
-
const l = Math.cos(r), a = Math.sin(r);
|
|
656
|
-
return Array.from({ length: i + 1 }, (c, g) => {
|
|
657
|
-
const y = s + Math.PI * 2 * h * g / i, f = Math.cos(y) * n, d = Math.sin(y) * o;
|
|
658
|
-
return { x: t + f * l - d * a, y: e + f * a + d * l };
|
|
659
|
-
});
|
|
660
|
-
}
|
|
661
|
-
function ze(t, e) {
|
|
662
|
-
return e.look === "pencil" ? Ve(t, e) : Ge(t, e.ink, e.look);
|
|
663
|
-
}
|
|
664
|
-
function ft(t, e, n = !1) {
|
|
665
|
-
t.beginPath(), t.moveTo(e[0].x, e[0].y);
|
|
666
|
-
for (const o of e.slice(1)) t.lineTo(o.x, o.y);
|
|
667
|
-
n && t.closePath();
|
|
1098
|
+
return t.withAngles(e, r, O);
|
|
668
1099
|
}
|
|
669
|
-
|
|
670
|
-
|
|
1100
|
+
const Un = 0.34, G = 0.12, N = -0.4, U = (t, e, n) => t[e] ?? n, Xn = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), Dn = 0.45, qn = 0.35, Kn = 0.7;
|
|
1101
|
+
function Mt(t, e, n) {
|
|
1102
|
+
const o = (c) => Math.sqrt(Math.max(0, 1 - c.x * c.x - c.y * c.y)), s = Oe(t, [n.x, n.y, o(n)]).facing, r = t.axes[2], h = Math.atan2(r[0], r[2]), i = Math.cos(h), l = i >= 0 ? 1 : -1, a = l * Math.max(qn, Math.abs(i)), f = l * Math.max(Kn, Math.abs(i)), g = Math.cos(t.angle), m = Math.sin(t.angle);
|
|
671
1103
|
return {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
t.
|
|
676
|
-
},
|
|
677
|
-
line(s, h) {
|
|
678
|
-
s.length < 2 || (t.strokeStyle = e, t.lineWidth = h * r, t.lineCap = "round", t.lineJoin = "round", ft(t, s), t.stroke());
|
|
679
|
-
},
|
|
680
|
-
shape(s, h, i) {
|
|
681
|
-
ft(t, s, !0), (h !== null || o) && (t.fillStyle = o ? e : h, t.fill()), !(i <= 0) && (t.strokeStyle = e, t.lineWidth = i * r, t.lineJoin = "round", t.stroke());
|
|
682
|
-
},
|
|
683
|
-
ellipse(s, h, i, l, a, c, g) {
|
|
684
|
-
t.beginPath(), t.ellipse(s, h, i, l, a, 0, Math.PI * 2), (c !== null || o) && (t.fillStyle = o ? e : c, t.fill()), !(g <= 0) && (t.strokeStyle = e, t.lineWidth = g * r, t.stroke());
|
|
685
|
-
},
|
|
686
|
-
dot(s, h, i) {
|
|
687
|
-
t.fillStyle = e, t.beginPath(), t.arc(s, h, i * r, 0, Math.PI * 2), t.fill();
|
|
688
|
-
},
|
|
689
|
-
guide() {
|
|
690
|
-
},
|
|
691
|
-
guideEllipse() {
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
function Ze(t, e) {
|
|
696
|
-
const n = [t[0]];
|
|
697
|
-
let o = 0;
|
|
698
|
-
for (let h = 1; h < t.length; h++) {
|
|
699
|
-
const i = t[h - 1], l = t[h], a = Math.hypot(l.x - i.x, l.y - i.y);
|
|
700
|
-
let c = e - o;
|
|
701
|
-
for (; c < a; ) {
|
|
702
|
-
const g = c / a;
|
|
703
|
-
n.push({ x: i.x + (l.x - i.x) * g, y: i.y + (l.y - i.y) * g }), c += e;
|
|
704
|
-
}
|
|
705
|
-
o = a - (c - e);
|
|
706
|
-
}
|
|
707
|
-
const r = t[t.length - 1], s = n[n.length - 1];
|
|
708
|
-
return Math.hypot(r.x - s.x, r.y - s.y) > e * 0.25 ? n.push(r) : n[n.length - 1] = r, n;
|
|
709
|
-
}
|
|
710
|
-
function Qe(t, e) {
|
|
711
|
-
const n = t.length;
|
|
712
|
-
return t.map((o, r) => {
|
|
713
|
-
const s = t[Math.max(0, r - 1)], h = t[Math.min(n - 1, r + 1)], i = Math.hypot(h.x - s.x, h.y - s.y) || 1, l = e(n === 1 ? 0 : r / (n - 1));
|
|
714
|
-
return { x: o.x - (h.y - s.y) / i * l, y: o.y + (h.x - s.x) / i * l };
|
|
715
|
-
});
|
|
716
|
-
}
|
|
717
|
-
function qt(t) {
|
|
718
|
-
const e = [0.6, 1.4, 2.9].map((o) => ({
|
|
719
|
-
frequency: o * (0.8 + t.next() * 0.4),
|
|
720
|
-
phase: t.next() * Math.PI * 2,
|
|
721
|
-
amount: 0.5 + t.next() * 0.5
|
|
722
|
-
})), n = e.reduce((o, r) => o + r.amount, 0);
|
|
723
|
-
return (o) => e.reduce((r, s) => r + s.amount * Math.sin(Math.PI * 2 * s.frequency * o + s.phase), 0) / n;
|
|
724
|
-
}
|
|
725
|
-
function Ve(t, e) {
|
|
726
|
-
const n = e.pencil ?? {}, o = e.ink, r = n.roughness ?? Math.max(1, e.lineWidth * 0.12), s = Math.max(1, Math.round(n.passes ?? 2)), h = Math.min(1, Math.max(0, n.pressure ?? 0.25)), i = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), l = ye(e.time, n.boil ?? 8);
|
|
727
|
-
let a = 0;
|
|
728
|
-
const c = (d, w, m = !1) => me(pe(`${e.seed}:${m ? "paper" : l}:${d}:${w}`)), g = (d, w, m, u, k, E = 0) => {
|
|
729
|
-
if (d.length < 2) return;
|
|
730
|
-
const b = d.slice(1).reduce((I, x, p) => I + Math.hypot(x.x - d[p].x, x.y - d[p].y), 0);
|
|
731
|
-
let M = Ze(d, Math.max(1.5, Math.min(e.lineWidth * 0.8, b / 24)));
|
|
732
|
-
if (E > 0 && M.length >= 2) {
|
|
733
|
-
const [I, x] = [M[M.length - 2], M[M.length - 1]], p = Math.hypot(x.x - I.x, x.y - I.y) || 1;
|
|
734
|
-
M = [...M, { x: x.x + (x.x - I.x) / p * E, y: x.y + (x.y - I.y) / p * E }];
|
|
735
|
-
}
|
|
736
|
-
const P = qt(m), S = qt(m), W = M.length, H = [], Y = [];
|
|
737
|
-
M.forEach((I, x) => {
|
|
738
|
-
const p = W === 1 ? 0 : x / (W - 1), T = M[Math.max(0, x - 1)], v = M[Math.min(W - 1, x + 1)], O = Math.hypot(v.x - T.x, v.y - T.y) || 1, A = -(v.y - T.y) / O, Z = (v.x - T.x) / O, nt = P(p) * k, ut = Math.min(1, p / 0.08, (1 - p) / 0.08), gt = (0.55 + 0.45 * Math.sqrt(Math.max(0, ut))) * (1 + h * S(p)), X = Math.max(0.3, w(p) * gt / 2), Q = I.x + A * nt, D = I.y + Z * nt;
|
|
739
|
-
H.push({ x: Q + A * X, y: D + Z * X }), Y.push({ x: Q - A * X, y: D - Z * X });
|
|
740
|
-
}), t.save(), t.globalAlpha *= u, t.fillStyle = o, ft(t, [...H, ...Y.reverse()], !0), t.fill(), t.restore();
|
|
741
|
-
}, y = (d, w) => {
|
|
742
|
-
const m = a++, u = c(m, 99, !0);
|
|
743
|
-
if (u.next() < i) {
|
|
744
|
-
const M = (u.next() * 2 - 1) * e.lineWidth * 1.4, P = (u.next() * 2 - 1) * e.lineWidth * 1.4, S = d.map((W) => ({ x: W.x + M, y: W.y + P }));
|
|
745
|
-
g(S, (W) => w(W) * 1.8, c(m, 98, !0), 0.035, r), g(S, (W) => w(W) * 0.45, c(m, 97, !0), 0.12, r * 1.5);
|
|
746
|
-
}
|
|
747
|
-
const k = d.slice(1).reduce((M, P, S) => M + Math.hypot(P.x - d[S].x, P.y - d[S].y), 0), E = w(0.5) > 4 && k > w(0.5) * 6, b = E ? [-0.3, 0.3, 0] : [0];
|
|
748
|
-
for (let M = 0; M < s; M++) {
|
|
749
|
-
const P = M === 0;
|
|
750
|
-
b.forEach((S, W) => {
|
|
751
|
-
const H = c(m, M * 10 + W), Y = S === 0 ? d : Qe(d, (x) => w(x) * S * Math.sqrt(Math.sin(Math.PI * x))), I = !P && S === 0 ? e.lineWidth * (0.3 + H.next() * 0.8) : 0;
|
|
752
|
-
g(Y, (x) => w(x) * (E ? 0.5 : 1) * (P ? 1 : 0.6), H, P ? 0.85 : 0.45, r * (P ? 0.6 : 1), I);
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
}, f = (d, w, m, u, k, E) => {
|
|
756
|
-
const M = c(a, 50).next() * Math.PI * 2;
|
|
757
|
-
y(Xt(d, w, m, u, k, M, 1.08, 48), () => E);
|
|
758
|
-
};
|
|
759
|
-
return {
|
|
760
|
-
look: "pencil",
|
|
761
|
-
ink: o,
|
|
762
|
-
limb(d, w, m) {
|
|
763
|
-
y(d, (u) => w + (m - w) * u);
|
|
764
|
-
},
|
|
765
|
-
line(d, w) {
|
|
766
|
-
y(d, () => w);
|
|
767
|
-
},
|
|
768
|
-
shape(d, w, m) {
|
|
769
|
-
w !== null && (t.save(), t.globalAlpha *= 0.88, t.fillStyle = w, ft(t, d, !0), t.fill(), t.restore()), m > 0 && y([...d, d[0]], () => m);
|
|
770
|
-
},
|
|
771
|
-
ellipse(d, w, m, u, k, E, b) {
|
|
772
|
-
E !== null && (t.save(), t.globalAlpha *= 0.9, t.fillStyle = E, t.beginPath(), t.ellipse(d, w, m, u, k, 0, Math.PI * 2), t.fill(), t.restore()), f(d, w, m, u, k, b);
|
|
773
|
-
},
|
|
774
|
-
dot(d, w, m) {
|
|
775
|
-
t.save(), t.globalAlpha *= 0.9, t.fillStyle = o, t.beginPath(), t.arc(d, w, m, 0, Math.PI * 2), t.fill(), t.restore();
|
|
776
|
-
},
|
|
777
|
-
guide(d) {
|
|
778
|
-
if (n.construction === !1 || d.length < 2) return;
|
|
779
|
-
const w = a++;
|
|
780
|
-
g(d, () => Math.max(0.6, e.lineWidth * 0.18), c(w, 0), 0.28, r * 1.2, e.lineWidth);
|
|
781
|
-
},
|
|
782
|
-
guideEllipse(d, w, m, u, k) {
|
|
783
|
-
if (n.construction === !1) return;
|
|
784
|
-
const E = a++, b = c(E, 0), M = Xt(d, w, m, u, k, b.next() * Math.PI * 2, 1.12, 48);
|
|
785
|
-
g(M, () => Math.max(0.6, e.lineWidth * 0.18), b, 0.28, r * 1.5);
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
const tn = 0.34, U = 0.12, L = -0.4, F = (t, e, n) => t[e] ?? n, en = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), nn = 0.45, on = 0.35, sn = 0.7;
|
|
790
|
-
function dt(t, e, n) {
|
|
791
|
-
const o = (f) => Math.sqrt(Math.max(0, 1 - f.x * f.x - f.y * f.y)), r = de(t, [n.x, n.y, o(n)]).facing, s = t.axes[2], h = Math.atan2(s[0], s[2]), i = Math.cos(h), l = i >= 0 ? 1 : -1, a = l * Math.max(on, Math.abs(i)), c = l * Math.max(sn, Math.abs(i)), g = Math.cos(t.angle), y = Math.sin(t.angle);
|
|
792
|
-
return {
|
|
793
|
-
facing: r,
|
|
794
|
-
points: e.map((f) => {
|
|
795
|
-
const d = nn * Math.sin(h) + n.x * a + (f.x - n.x) * c, w = f.y + s[1] * o(f), m = d * t.rx, u = w * t.ry;
|
|
796
|
-
return { x: t.center.x + m * g + u * y, y: t.center.y + m * y - u * g };
|
|
1104
|
+
facing: s,
|
|
1105
|
+
points: e.map((c) => {
|
|
1106
|
+
const d = Dn * Math.sin(h) + n.x * a + (c.x - n.x) * f, u = c.y + r[1] * o(c), y = d * t.rx, p = u * t.ry;
|
|
1107
|
+
return { x: t.center.x + y * g + p * m, y: t.center.y + y * m - p * g };
|
|
797
1108
|
})
|
|
798
1109
|
};
|
|
799
1110
|
}
|
|
800
|
-
const
|
|
801
|
-
const h =
|
|
1111
|
+
const gt = (t, e, n, o = 12) => Array.from({ length: o + 1 }, (s, r) => {
|
|
1112
|
+
const h = r / o, i = 1 - h;
|
|
802
1113
|
return { x: i * i * t.x + 2 * i * h * e.x + h * h * n.x, y: i * i * t.y + 2 * i * h * e.y + h * h * n.y };
|
|
803
|
-
}),
|
|
804
|
-
const i = Math.PI * 2 * h /
|
|
1114
|
+
}), At = (t, e, n, o, s = 16) => Array.from({ length: s }, (r, h) => {
|
|
1115
|
+
const i = Math.PI * 2 * h / s;
|
|
805
1116
|
return { x: t + Math.cos(i) * n, y: e + Math.sin(i) * o };
|
|
806
|
-
}),
|
|
807
|
-
function
|
|
808
|
-
const
|
|
809
|
-
for (const
|
|
810
|
-
const
|
|
811
|
-
if (h(E,
|
|
812
|
-
const b = { x: E, y:
|
|
1117
|
+
}), le = 0.05;
|
|
1118
|
+
function Gn(t, e, n, o) {
|
|
1119
|
+
const s = Math.max(1, Math.min(o * 0.6, 0.14 * e.rx)), r = (p, x) => Mt(e, p, x).points, h = (p, x) => Mt(e, [], { x: p, y: x }).facing, i = U(n, "smile", 0), l = U(n, "blink", 0), a = U(n, "lookX", 0), f = U(n, "lookY", 0), g = U(n, "browTilt", 0);
|
|
1120
|
+
for (const p of [1, -1]) {
|
|
1121
|
+
const x = p === 1 ? "left" : "right", E = Un * p;
|
|
1122
|
+
if (h(E, G) < le) continue;
|
|
1123
|
+
const b = { x: E, y: G }, M = Xn(U(n, `eye.${x}`, 1), l);
|
|
813
1124
|
if (M < 0.2) {
|
|
814
|
-
const
|
|
815
|
-
t.line(
|
|
1125
|
+
const O = i > 0.5 ? 0.12 : -0.06;
|
|
1126
|
+
t.line(r(gt({ x: E - 0.12, y: G }, { x: E, y: G + O }, { x: E + 0.12, y: G }), b), s);
|
|
816
1127
|
} else {
|
|
817
1128
|
if (M > 1.2) {
|
|
818
|
-
const
|
|
819
|
-
t.shape(
|
|
1129
|
+
const k = 0.13 * M;
|
|
1130
|
+
t.shape(r(At(E, G, k * 0.85, k), b), "#ffffff", s);
|
|
820
1131
|
}
|
|
821
|
-
const
|
|
822
|
-
t.shape(
|
|
1132
|
+
const O = M > 1.2 ? 0.075 : 0.1, H = E + a * 0.08, _ = G - f * 0.07;
|
|
1133
|
+
t.shape(r(At(H, _, O, O * 1.1 * Math.min(M, 1)), b), t.ink, 0);
|
|
823
1134
|
}
|
|
824
|
-
const
|
|
825
|
-
t.line(
|
|
1135
|
+
const T = G + 0.3 + U(n, `brow.${x}`, 0) * 0.14 + Math.max(0, M - 1) * 0.12, P = { x: E + p * 0.13, y: T }, I = { x: E - p * 0.13, y: T + g * 0.1 };
|
|
1136
|
+
t.line(r([P, { x: (P.x + I.x) / 2, y: (P.y + I.y) / 2 }, I], { x: E, y: T }), s);
|
|
826
1137
|
}
|
|
827
|
-
const
|
|
828
|
-
if (h(0,
|
|
829
|
-
const
|
|
1138
|
+
const m = { x: 0, y: N };
|
|
1139
|
+
if (h(0, N) < -le) return;
|
|
1140
|
+
const c = 0.25 * Math.max(0.3, U(n, "mouthWidth", 1)), d = Math.min(1, Math.max(0, U(n, "mouth", 0)));
|
|
830
1141
|
if (d <= 0.05) {
|
|
831
|
-
t.line(
|
|
1142
|
+
t.line(r(gt({ x: -c, y: N }, { x: 0, y: N - i * 0.25 }, { x: c, y: N }), m), s);
|
|
832
1143
|
return;
|
|
833
1144
|
}
|
|
834
|
-
const
|
|
835
|
-
let
|
|
1145
|
+
const u = 0.3 * d;
|
|
1146
|
+
let y;
|
|
836
1147
|
if (i > 0.3) {
|
|
837
|
-
const
|
|
838
|
-
|
|
1148
|
+
const p = N + 0.05;
|
|
1149
|
+
y = [...gt({ x: c, y: p }, { x: 0, y: N - u * 2 }, { x: -c, y: p })];
|
|
839
1150
|
} else if (i < -0.3) {
|
|
840
|
-
const
|
|
841
|
-
|
|
1151
|
+
const p = N - u * 0.6;
|
|
1152
|
+
y = [...gt({ x: c, y: p }, { x: 0, y: N + u * 1.4 }, { x: -c, y: p })];
|
|
842
1153
|
} else
|
|
843
|
-
|
|
844
|
-
t.shape(
|
|
1154
|
+
y = At(0, N, c * 0.8, u);
|
|
1155
|
+
t.shape(r(y, m), t.ink, 0);
|
|
845
1156
|
}
|
|
846
|
-
const
|
|
1157
|
+
const Ot = 0.215, _t = 0.205, Jn = 0.065, he = 0.035, zn = 0.165, jn = 0.155, Zn = 12, z = {
|
|
847
1158
|
turn: 0,
|
|
848
1159
|
lean: 0,
|
|
849
1160
|
side: 0,
|
|
@@ -881,24 +1192,24 @@ const kt = 0.215, Et = 0.205, ln = 0.065, Kt = 0.035, hn = 0.165, an = 0.155, cn
|
|
|
881
1192
|
lookX: 0,
|
|
882
1193
|
lookY: 0
|
|
883
1194
|
};
|
|
884
|
-
function
|
|
885
|
-
return { ...
|
|
1195
|
+
function F(t = {}) {
|
|
1196
|
+
return { ...z, ...t };
|
|
886
1197
|
}
|
|
887
|
-
function
|
|
1198
|
+
function Y(t, e) {
|
|
888
1199
|
const n = {};
|
|
889
|
-
for (const o of ["left", "right"]) for (const [
|
|
1200
|
+
for (const o of ["left", "right"]) for (const [s, r] of Object.entries(e)) n[`${t}.${o}.${s}`] = r;
|
|
890
1201
|
return n;
|
|
891
1202
|
}
|
|
892
|
-
const
|
|
893
|
-
rest:
|
|
894
|
-
wave:
|
|
895
|
-
cheer:
|
|
896
|
-
point:
|
|
897
|
-
handsOnHips:
|
|
898
|
-
think:
|
|
899
|
-
shrug:
|
|
900
|
-
sit:
|
|
901
|
-
kneel:
|
|
1203
|
+
const Qn = {
|
|
1204
|
+
rest: z,
|
|
1205
|
+
wave: F({ "arm.right.spread": 115, "arm.right.bend": 55, "arm.right.elbow": 0, "head.tilt": -6, smile: 0.9 }),
|
|
1206
|
+
cheer: F({ ...Y("arm", { spread: 140, bend: 20, elbow: 0 }), mouth: 0.6, smile: 1, "eye.left": 0, "eye.right": 0 }),
|
|
1207
|
+
point: F({ "arm.right.spread": 88, "arm.right.elbow": 0, "arm.right.bend": 0, "head.turn": -20, smile: 0.4 }),
|
|
1208
|
+
handsOnHips: F({ ...Y("arm", { spread: 50, bend: -105, elbow: 0 }), ...Y("leg", { spread: 9 }), smile: 0.8 }),
|
|
1209
|
+
think: F({ "arm.right.spread": 22, "arm.right.bend": -150, "arm.right.elbow": 0, "head.tilt": 10, lookX: -0.5, lookY: -0.8, smile: 0 }),
|
|
1210
|
+
shrug: F({ ...Y("arm", { spread: 35, bend: 75, elbow: 0 }), "head.tilt": -10, smile: -0.2 }),
|
|
1211
|
+
sit: F({ ...Y("leg", { swing: 90, knee: 90, spread: 4 }), ...Y("arm", { swing: 25, elbow: 45, spread: 8 }) }),
|
|
1212
|
+
kneel: F({
|
|
902
1213
|
"leg.left.swing": 90,
|
|
903
1214
|
"leg.left.knee": 90,
|
|
904
1215
|
// The back thigh leans back a little so its knee meets the ground beside the
|
|
@@ -906,24 +1217,24 @@ const fn = {
|
|
|
906
1217
|
"leg.right.swing": -18,
|
|
907
1218
|
"leg.right.knee": 108,
|
|
908
1219
|
"leg.right.ankle": 16,
|
|
909
|
-
|
|
1220
|
+
...Y("arm", { swing: 20, elbow: 30 })
|
|
910
1221
|
}),
|
|
911
|
-
crouch:
|
|
1222
|
+
crouch: F({ ...Y("leg", { swing: 75, knee: 140, spread: 6 }), lean: 25, ...Y("arm", { swing: 50, elbow: 40 }), "head.nod": -15 }),
|
|
912
1223
|
// On hands and knees: the back nearly level, arms straight down, the toes
|
|
913
1224
|
// pointed back along the ground.
|
|
914
|
-
crawl:
|
|
915
|
-
lieDown:
|
|
1225
|
+
crawl: F({ lean: 82, "head.nod": -35, ...Y("arm", { swing: 80, elbow: 0, spread: 4 }), ...Y("leg", { knee: 92, ankle: -88 }) }),
|
|
1226
|
+
lieDown: F({ roll: 90, ...Y("arm", { spread: 8 }), "head.nod": 0 })
|
|
916
1227
|
};
|
|
917
|
-
function
|
|
918
|
-
const e = t.headSize ?? 0.3, n = t.shoulderWidth ?? 0.06, o = t.hipWidth ?? 0.022,
|
|
1228
|
+
function Vn(t = {}) {
|
|
1229
|
+
const e = t.headSize ?? 0.3, n = t.shoulderWidth ?? 0.06, o = t.hipWidth ?? 0.022, s = Math.max(0.12, 1 - e - he - (Ot + _t)), r = (l) => ({
|
|
919
1230
|
id: `arm.${l}`,
|
|
920
1231
|
parent: "spine",
|
|
921
1232
|
offset: [(l === "left" ? 1 : -1) * n, -0.035, 0],
|
|
922
1233
|
rest: [0, -1, 0],
|
|
923
1234
|
side: l === "left" ? 1 : -1,
|
|
924
1235
|
bones: [
|
|
925
|
-
{ length:
|
|
926
|
-
{ length:
|
|
1236
|
+
{ length: zn, width: [1.25, 0.9] },
|
|
1237
|
+
{ length: jn, width: [0.9, 0.75] }
|
|
927
1238
|
]
|
|
928
1239
|
}), h = (l) => ({
|
|
929
1240
|
id: `leg.${l}`,
|
|
@@ -932,14 +1243,14 @@ function dn(t = {}) {
|
|
|
932
1243
|
rest: [0, -1, 0],
|
|
933
1244
|
side: l === "left" ? 1 : -1,
|
|
934
1245
|
bones: [
|
|
935
|
-
{ length:
|
|
936
|
-
{ length:
|
|
937
|
-
{ length:
|
|
1246
|
+
{ length: Ot, width: [1.45, 1.05] },
|
|
1247
|
+
{ length: _t, width: [1.05, 0.85] },
|
|
1248
|
+
{ length: Jn, width: [0.95, 0.7] }
|
|
938
1249
|
]
|
|
939
|
-
}), i = (l, a) => l[a] ??
|
|
1250
|
+
}), i = (l, a) => l[a] ?? z[a] ?? 0;
|
|
940
1251
|
return {
|
|
941
1252
|
id: "human",
|
|
942
|
-
hipHeight:
|
|
1253
|
+
hipHeight: Ot + _t,
|
|
943
1254
|
// Tie order: legs, then the body, then the arms (in front of the chest unless turned away), then the head.
|
|
944
1255
|
chains: [
|
|
945
1256
|
h("left"),
|
|
@@ -949,13 +1260,13 @@ function dn(t = {}) {
|
|
|
949
1260
|
parent: null,
|
|
950
1261
|
rest: [0, 1, 0],
|
|
951
1262
|
bones: [
|
|
952
|
-
{ length:
|
|
953
|
-
{ length:
|
|
1263
|
+
{ length: s / 2, width: [1.7, 1.4] },
|
|
1264
|
+
{ length: s / 2, width: [1.4, 1.1] }
|
|
954
1265
|
]
|
|
955
1266
|
},
|
|
956
|
-
{ id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length:
|
|
957
|
-
|
|
958
|
-
|
|
1267
|
+
{ id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length: he, width: [1, 0.9] }] },
|
|
1268
|
+
r("left"),
|
|
1269
|
+
r("right")
|
|
959
1270
|
],
|
|
960
1271
|
head: { on: "neck", size: e },
|
|
961
1272
|
contacts: [
|
|
@@ -973,37 +1284,37 @@ function dn(t = {}) {
|
|
|
973
1284
|
],
|
|
974
1285
|
angles(l, a) {
|
|
975
1286
|
if (a.id === "spine") {
|
|
976
|
-
const
|
|
1287
|
+
const c = -i(l, "lean") / 2, d = i(l, "side") / 2;
|
|
977
1288
|
return [
|
|
978
|
-
{ swing:
|
|
979
|
-
{ swing:
|
|
1289
|
+
{ swing: c, spread: d },
|
|
1290
|
+
{ swing: c, spread: d }
|
|
980
1291
|
];
|
|
981
1292
|
}
|
|
982
1293
|
if (a.id === "neck") return [{ swing: 0, spread: 0 }];
|
|
983
|
-
const [
|
|
984
|
-
return
|
|
985
|
-
{ swing:
|
|
986
|
-
{ swing:
|
|
1294
|
+
const [f, g] = a.id.split("."), m = (c) => i(l, `${f}.${g}.${c}`);
|
|
1295
|
+
return f === "arm" ? [
|
|
1296
|
+
{ swing: m("swing"), spread: m("spread") },
|
|
1297
|
+
{ swing: m("elbow"), spread: m("bend") }
|
|
987
1298
|
] : [
|
|
988
|
-
{ swing:
|
|
989
|
-
{ swing: -
|
|
1299
|
+
{ swing: m("swing"), spread: m("spread") },
|
|
1300
|
+
{ swing: -m("knee"), spread: 0 },
|
|
990
1301
|
// The foot points forward, square to the shin, turned out a little.
|
|
991
|
-
{ swing: 90 +
|
|
1302
|
+
{ swing: 90 + m("ankle"), spread: 0, yaw: Zn * (a.side ?? 1) }
|
|
992
1303
|
];
|
|
993
1304
|
},
|
|
994
|
-
withAngles(l, a,
|
|
995
|
-
const [g,
|
|
1305
|
+
withAngles(l, a, f) {
|
|
1306
|
+
const [g, m] = a.id.split("."), c = (d) => `${g}.${m}.${d}`;
|
|
996
1307
|
return g === "arm" ? {
|
|
997
1308
|
...l,
|
|
998
|
-
[
|
|
999
|
-
[
|
|
1000
|
-
[
|
|
1001
|
-
[
|
|
1002
|
-
} : g === "leg" ? { ...l, [
|
|
1309
|
+
[c("swing")]: f[0].swing,
|
|
1310
|
+
[c("spread")]: f[0].spread,
|
|
1311
|
+
[c("elbow")]: f[1].swing,
|
|
1312
|
+
[c("bend")]: f[1].spread
|
|
1313
|
+
} : g === "leg" ? { ...l, [c("swing")]: f[0].swing, [c("spread")]: f[0].spread, [c("knee")]: -f[1].swing } : l;
|
|
1003
1314
|
},
|
|
1004
1315
|
boneScale(l, a) {
|
|
1005
|
-
const
|
|
1006
|
-
return a?.id.startsWith("arm.") ? Math.sqrt(
|
|
1316
|
+
const f = Math.min(3, Math.max(0.3, i(l, "stretch")));
|
|
1317
|
+
return a?.id.startsWith("arm.") ? Math.sqrt(f) : f;
|
|
1007
1318
|
},
|
|
1008
1319
|
headPose(l) {
|
|
1009
1320
|
const a = Math.min(3, Math.max(0.3, i(l, "stretch")));
|
|
@@ -1035,18 +1346,18 @@ function dn(t = {}) {
|
|
|
1035
1346
|
}
|
|
1036
1347
|
};
|
|
1037
1348
|
}
|
|
1038
|
-
function
|
|
1349
|
+
function vo(t) {
|
|
1039
1350
|
const e = t.split(".");
|
|
1040
1351
|
if (e.length === 3) {
|
|
1041
|
-
const [o,
|
|
1042
|
-
return `${`${
|
|
1352
|
+
const [o, s, r] = e;
|
|
1353
|
+
return `${`${s === "left" ? "Left" : "Right"} ${o}`} · ${{
|
|
1043
1354
|
swing: "forward / back",
|
|
1044
1355
|
spread: "out / in",
|
|
1045
1356
|
elbow: "elbow bend",
|
|
1046
1357
|
bend: "forearm out / in",
|
|
1047
1358
|
knee: "knee bend",
|
|
1048
1359
|
ankle: "foot tilt"
|
|
1049
|
-
}[
|
|
1360
|
+
}[r] ?? r}`;
|
|
1050
1361
|
}
|
|
1051
1362
|
return {
|
|
1052
1363
|
turn: "View (front → side → back)",
|
|
@@ -1071,126 +1382,150 @@ function $n(t) {
|
|
|
1071
1382
|
lookY: "Look up / down"
|
|
1072
1383
|
}[t] ?? t;
|
|
1073
1384
|
}
|
|
1074
|
-
const
|
|
1385
|
+
const to = {
|
|
1075
1386
|
leftEye: "eye.left",
|
|
1076
1387
|
rightEye: "eye.right",
|
|
1077
1388
|
leftBrow: "brow.left",
|
|
1078
1389
|
rightBrow: "brow.right"
|
|
1079
|
-
},
|
|
1080
|
-
Object.entries(
|
|
1390
|
+
}, Io = Object.fromEntries(
|
|
1391
|
+
Object.entries(X).map(([t, e]) => [
|
|
1081
1392
|
t,
|
|
1082
|
-
Object.fromEntries(Object.entries(e).map(([n, o]) => [
|
|
1393
|
+
Object.fromEntries(Object.entries(e).map(([n, o]) => [to[n] ?? n, o]))
|
|
1083
1394
|
])
|
|
1084
1395
|
);
|
|
1085
|
-
function
|
|
1086
|
-
const e = (t.proportions ?? "bold") === "bold", n = t.figure ?? "fluid", o = t.look ?? "clean",
|
|
1396
|
+
function Ao(t = {}) {
|
|
1397
|
+
const e = (t.proportions ?? "bold") === "bold", n = t.figure ?? "fluid", o = t.look ?? "clean", s = t.height ?? 300, r = n === "stick";
|
|
1087
1398
|
return {
|
|
1088
|
-
plan: t.plan ??
|
|
1399
|
+
plan: t.plan ?? Vn({
|
|
1089
1400
|
headSize: t.headSize ?? (e ? 0.3 : 0.24),
|
|
1090
|
-
shoulderWidth:
|
|
1091
|
-
hipWidth:
|
|
1401
|
+
shoulderWidth: r ? 0 : t.shoulderWidth ?? 0.06,
|
|
1402
|
+
hipWidth: r ? 0 : t.hipWidth ?? 0.022
|
|
1092
1403
|
}),
|
|
1093
1404
|
figure: n,
|
|
1094
1405
|
look: o,
|
|
1095
|
-
height:
|
|
1096
|
-
lineWidth: t.lineWidth ??
|
|
1406
|
+
height: s,
|
|
1407
|
+
lineWidth: t.lineWidth ?? s * (e ? 0.045 : 0.022),
|
|
1097
1408
|
ink: t.ink ?? (o === "pencil" ? "#2f2f33" : "#1e293b"),
|
|
1098
1409
|
skin: t.skin ?? (o === "pencil" ? "none" : "#ffffff"),
|
|
1099
1410
|
seed: t.seed ?? 1,
|
|
1100
1411
|
pencil: t.pencil ?? {},
|
|
1101
1412
|
layers: t.layers ?? {},
|
|
1102
|
-
contact: t.contact ?? "ground"
|
|
1413
|
+
contact: t.contact ?? "ground",
|
|
1414
|
+
hands: t.hands ?? "dot",
|
|
1415
|
+
handSize: t.handSize ?? 0.17
|
|
1103
1416
|
};
|
|
1104
1417
|
}
|
|
1105
|
-
function
|
|
1106
|
-
const { point:
|
|
1107
|
-
return { point:
|
|
1108
|
-
}
|
|
1109
|
-
const
|
|
1110
|
-
function
|
|
1111
|
-
return t.figure === "stick" ?
|
|
1112
|
-
}
|
|
1113
|
-
function
|
|
1114
|
-
const n = t.plan.id === "human" ? { ...
|
|
1115
|
-
t.plan.chains.forEach((
|
|
1116
|
-
const d = o.chains[
|
|
1117
|
-
|
|
1118
|
-
const
|
|
1119
|
-
h[
|
|
1120
|
-
}),
|
|
1121
|
-
const l = [...t.plan.chains.map((
|
|
1122
|
-
for (const [
|
|
1123
|
-
const
|
|
1124
|
-
|
|
1418
|
+
function Oo(t, e, n, o) {
|
|
1419
|
+
const { point: s, facing: r } = Oe(t, [e, n, o]);
|
|
1420
|
+
return { point: s, facing: r };
|
|
1421
|
+
}
|
|
1422
|
+
const Ct = (t) => t.rest[1] < -0.5, eo = 0.3;
|
|
1423
|
+
function no(t, e, n) {
|
|
1424
|
+
return t.figure === "stick" ? Ct(e) ? n.slice(0, 3) : n : Ct(e) && n.length >= 3 ? tt(n[0], n[1], n[2], eo) : n.length === 3 ? tt(n[0], n[1], n[2], 1) : n;
|
|
1425
|
+
}
|
|
1426
|
+
function qt(t, e) {
|
|
1427
|
+
const n = t.plan.id === "human" ? { ...z, ...e } : e, o = Dt(t.plan, n, { height: t.height, contact: t.contact }), s = {}, r = {}, h = {}, i = 0.01 * t.height;
|
|
1428
|
+
t.plan.chains.forEach((c) => {
|
|
1429
|
+
const d = o.chains[c.id];
|
|
1430
|
+
s[c.id] = d.points;
|
|
1431
|
+
const u = d.depths.reduce((E, b) => E + b, 0) / d.depths.length, y = c.parent ? o.chains[c.parent] : void 0, p = y ? y.depths[c.at ?? y.depths.length - 1] : 0, x = u - p;
|
|
1432
|
+
h[c.id] = Math.abs(x) < i ? 0 : x, r[c.id] = { points: no(t, c, d.points), depth: u };
|
|
1433
|
+
}), r.head = { points: [o.head.center], depth: o.head.depth }, h.head = 0;
|
|
1434
|
+
const l = [...t.plan.chains.map((c) => c.id), "head"], a = [...l].sort((c, d) => h[c] - h[d] || l.indexOf(c) - l.indexOf(d)), f = { hip: o.hip };
|
|
1435
|
+
for (const [c, [d, u]] of Object.entries(t.plan.landmarks ?? {})) {
|
|
1436
|
+
const y = o.chains[d]?.points;
|
|
1437
|
+
y && (f[c] = y[Math.min(u, y.length - 1)]);
|
|
1125
1438
|
}
|
|
1126
1439
|
const g = {};
|
|
1127
|
-
for (const [
|
|
1128
|
-
const
|
|
1440
|
+
for (const [c, d] of Object.entries(f)) g[c] = d.y >= o.groundY - 0.01 * t.height;
|
|
1441
|
+
const m = {
|
|
1129
1442
|
height: t.height,
|
|
1130
1443
|
lineWidth: t.lineWidth,
|
|
1131
1444
|
turn: n.turn ?? 0,
|
|
1132
|
-
points:
|
|
1133
|
-
chains:
|
|
1134
|
-
parts:
|
|
1445
|
+
points: f,
|
|
1446
|
+
chains: s,
|
|
1447
|
+
parts: r,
|
|
1135
1448
|
head: o.head,
|
|
1136
1449
|
groundY: o.groundY,
|
|
1137
1450
|
grounded: g
|
|
1138
1451
|
};
|
|
1139
|
-
return { skeleton: o, joints:
|
|
1452
|
+
return { skeleton: o, joints: m, order: a };
|
|
1140
1453
|
}
|
|
1141
|
-
function
|
|
1142
|
-
return
|
|
1454
|
+
function oo(t, e) {
|
|
1455
|
+
return qt(t, e).joints;
|
|
1143
1456
|
}
|
|
1144
|
-
function
|
|
1457
|
+
function so(t, e, n) {
|
|
1145
1458
|
const { head: o } = n;
|
|
1146
1459
|
t.guideEllipse(o.center.x, o.center.y, o.rx * 1.03, o.ry * 1.03, o.angle);
|
|
1147
|
-
const
|
|
1148
|
-
h.facing > 0 && t.guide(h.points), t.guide(
|
|
1460
|
+
const s = Array.from({ length: 13 }, (l, a) => ({ x: 0, y: -0.95 + 1.9 * a / 12 })), r = Array.from({ length: 13 }, (l, a) => ({ x: -0.95 + 1.9 * a / 12, y: 0.12 })), h = Mt(o, s, { x: 0, y: 0 });
|
|
1461
|
+
h.facing > 0 && t.guide(h.points), t.guide(Mt(o, r, { x: 0, y: 0.12 }).points), t.guide(n.chains.spine ?? []);
|
|
1149
1462
|
const i = e.lineWidth * 0.9;
|
|
1150
1463
|
for (const l of ["shoulder.left", "shoulder.right", "elbow.left", "elbow.right", "hip.left", "hip.right", "knee.left", "knee.right"]) {
|
|
1151
1464
|
const a = n.points[l];
|
|
1152
1465
|
a && t.guideEllipse(a.x, a.y, i, i, 0);
|
|
1153
1466
|
}
|
|
1154
1467
|
}
|
|
1155
|
-
function
|
|
1156
|
-
const
|
|
1157
|
-
if (
|
|
1158
|
-
const { head:
|
|
1159
|
-
|
|
1468
|
+
function ro(t, e, n, o, s, r) {
|
|
1469
|
+
const h = n.lineWidth;
|
|
1470
|
+
if (s === "head") {
|
|
1471
|
+
const { head: c } = o, d = n.skin === "none" ? null : n.skin;
|
|
1472
|
+
e.ellipse(c.center.x, c.center.y, c.rx, c.ry, c.angle, d, h), e.look !== "silhouette" && Gn(e, c, r, h);
|
|
1160
1473
|
return;
|
|
1161
1474
|
}
|
|
1162
|
-
const
|
|
1163
|
-
if (
|
|
1164
|
-
if (
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1475
|
+
const i = n.plan.chains.find((c) => c.id === s), l = o.chains[s], a = o.parts[s].points;
|
|
1476
|
+
if (n.figure === "stick") {
|
|
1477
|
+
if (s === "neck") return;
|
|
1478
|
+
const c = s === "spine" ? [...l, ...o.chains.neck?.slice(1) ?? []] : a;
|
|
1479
|
+
e.line(c, h);
|
|
1167
1480
|
return;
|
|
1168
1481
|
}
|
|
1169
|
-
const
|
|
1170
|
-
if (
|
|
1171
|
-
const [
|
|
1172
|
-
if (
|
|
1173
|
-
|
|
1482
|
+
const f = (c, d) => [i.bones[c].width[0] * h, i.bones[d].width[1] * h];
|
|
1483
|
+
if (Ct(i)) {
|
|
1484
|
+
const [c, d] = f(0, 1);
|
|
1485
|
+
if (e.limb(a, c, d), i.bones.length >= 3)
|
|
1486
|
+
e.limb([l[2], l[3]], i.bones[2].width[0] * h, i.bones[2].width[1] * h);
|
|
1487
|
+
else if (n.hands === "cartoon" && s.startsWith("arm."))
|
|
1488
|
+
lo(t, e, n, l, s.endsWith(".left") ? "left" : "right", r);
|
|
1174
1489
|
else {
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1490
|
+
const u = l[l.length - 1];
|
|
1491
|
+
e.dot(u.x, u.y, h * 0.62);
|
|
1177
1492
|
}
|
|
1178
1493
|
return;
|
|
1179
1494
|
}
|
|
1180
|
-
if (
|
|
1181
|
-
const
|
|
1182
|
-
|
|
1183
|
-
const [
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1186
|
-
|
|
1495
|
+
if (s === "spine") {
|
|
1496
|
+
const c = o.points["hip.left"], d = o.points["hip.right"];
|
|
1497
|
+
c && d && Math.hypot(c.x - d.x, c.y - d.y) > 0.5 && e.limb([c, d], h * 1.3, h * 1.3);
|
|
1498
|
+
const [u, y] = f(0, i.bones.length - 1);
|
|
1499
|
+
e.limb(a, u, y);
|
|
1500
|
+
const p = o.points["shoulder.left"], x = o.points["shoulder.right"];
|
|
1501
|
+
p && x && Math.hypot(p.x - x.x, p.y - x.y) > 0.5 && e.limb(tt(p, l[l.length - 1], x, 1, 10), h * 1.15, h * 1.15);
|
|
1187
1502
|
return;
|
|
1188
1503
|
}
|
|
1189
|
-
const [
|
|
1190
|
-
|
|
1504
|
+
const [g, m] = f(0, i.bones.length - 1);
|
|
1505
|
+
e.limb(a, g, m);
|
|
1506
|
+
}
|
|
1507
|
+
function io(t, e) {
|
|
1508
|
+
const n = `hand.${e}.`, o = {};
|
|
1509
|
+
for (const [h, i] of Object.entries(t)) h.startsWith(n) && (o[h.slice(n.length)] = i);
|
|
1510
|
+
const s = t.turn ?? 0, r = e === "right" ? 1 - s : 1 + s;
|
|
1511
|
+
return { ...kt, ...o, turn: r + (o.turn ?? 0) };
|
|
1512
|
+
}
|
|
1513
|
+
function lo(t, e, n, o, s, r) {
|
|
1514
|
+
const h = o[o.length - 1], i = o[o.length - 2], l = Math.atan2(h.x - i.x, -(h.y - i.y)) * 180 / Math.PI;
|
|
1515
|
+
xe(t, h, io(r, s), {
|
|
1516
|
+
size: n.handSize * n.height,
|
|
1517
|
+
side: s,
|
|
1518
|
+
angle: l,
|
|
1519
|
+
pen: e,
|
|
1520
|
+
skin: n.skin === "none" ? "#ffffff" : n.skin,
|
|
1521
|
+
// A cartoon glove: three fingers and a thumb, plump enough to match the limbs.
|
|
1522
|
+
fingers: 4,
|
|
1523
|
+
plump: 1.6,
|
|
1524
|
+
lineWidth: n.lineWidth * 0.3
|
|
1525
|
+
});
|
|
1191
1526
|
}
|
|
1192
|
-
function
|
|
1193
|
-
const
|
|
1527
|
+
function ho(t, e, n, o = 0) {
|
|
1528
|
+
const s = e.plan.id === "human" ? { ...z, ...n } : n, { joints: r, order: h } = qt(e, s), i = ke(t, {
|
|
1194
1529
|
look: e.look,
|
|
1195
1530
|
ink: e.ink,
|
|
1196
1531
|
lineWidth: e.lineWidth,
|
|
@@ -1198,163 +1533,174 @@ function bn(t, e, n, o = 0) {
|
|
|
1198
1533
|
time: o,
|
|
1199
1534
|
pencil: e.pencil
|
|
1200
1535
|
}), l = (a) => {
|
|
1201
|
-
a && (t.save(), a(t,
|
|
1536
|
+
a && (t.save(), a(t, r, i, o), t.restore());
|
|
1202
1537
|
};
|
|
1203
|
-
t.save(), t.lineCap = "round", t.lineJoin = "round", e.look === "pencil" && e.pencil.construction !== !1 &&
|
|
1538
|
+
t.save(), t.lineCap = "round", t.lineJoin = "round", e.look === "pencil" && e.pencil.construction !== !1 && so(i, e, r), l(e.layers.behind);
|
|
1204
1539
|
for (const a of h) {
|
|
1205
|
-
const
|
|
1206
|
-
l(
|
|
1540
|
+
const f = e.layers.parts?.[a];
|
|
1541
|
+
l(f?.under), ro(t, i, e, r, a, s), l(f?.over);
|
|
1207
1542
|
}
|
|
1208
1543
|
l(e.layers.front), t.restore();
|
|
1209
1544
|
}
|
|
1210
|
-
function
|
|
1545
|
+
function _o(t, e, n) {
|
|
1211
1546
|
const o = { ...t };
|
|
1212
|
-
for (const [
|
|
1213
|
-
const h = t[
|
|
1214
|
-
o[
|
|
1547
|
+
for (const [s, r] of Object.entries(e)) {
|
|
1548
|
+
const h = t[s] ?? r;
|
|
1549
|
+
o[s] = h + (r - h) * n;
|
|
1215
1550
|
}
|
|
1216
1551
|
return o;
|
|
1217
1552
|
}
|
|
1218
|
-
function
|
|
1219
|
-
const
|
|
1220
|
-
let
|
|
1553
|
+
function Ho(t, e, n, o) {
|
|
1554
|
+
const s = t.plan.id === "human" ? { ...z, ...e } : e;
|
|
1555
|
+
let r;
|
|
1221
1556
|
if (Array.isArray(o))
|
|
1222
|
-
|
|
1557
|
+
r = o;
|
|
1223
1558
|
else {
|
|
1224
|
-
const { skeleton: h } =
|
|
1225
|
-
|
|
1559
|
+
const { skeleton: h } = qt(t, s), i = Dt(t.plan, { ...s, roll: 0 }, { height: t.height, contact: "none" }), l = (s.roll ?? 0) * Math.PI / 180, a = o.x - h.hip.x, f = o.y - h.hip.y, g = i.hip.x + a * Math.cos(-l) - f * Math.sin(-l), m = i.hip.y + a * Math.sin(-l) + f * Math.cos(-l), c = Math.PI / 2 * (s.turn ?? 0), d = o.depth ?? h.chains[n].depths[h.chains[n].depths.length - 1], u = Math.cos(c), y = Math.sin(c);
|
|
1560
|
+
r = [g * u - d * y, -m, g * y + d * u];
|
|
1226
1561
|
}
|
|
1227
|
-
return
|
|
1562
|
+
return Cn(t.plan, s, n, r, { height: t.height });
|
|
1228
1563
|
}
|
|
1229
|
-
function
|
|
1230
|
-
const { character: e } = t, n = e.height * 0.8, o = e.height,
|
|
1564
|
+
function Wo(t) {
|
|
1565
|
+
const { character: e } = t, n = e.height * 0.8, o = e.height, s = e.plan.id === "human" ? z : {};
|
|
1231
1566
|
return {
|
|
1232
1567
|
type: "custom",
|
|
1233
1568
|
x: t.x - n / 2,
|
|
1234
1569
|
y: t.y - o,
|
|
1235
1570
|
width: n,
|
|
1236
1571
|
height: o,
|
|
1237
|
-
props: { ...
|
|
1572
|
+
props: { ...s, ...t.pose },
|
|
1238
1573
|
character: e,
|
|
1239
|
-
draw(
|
|
1240
|
-
|
|
1574
|
+
draw(r, h, i) {
|
|
1575
|
+
r.translate(n / 2, o), ho(r, e, h.props, i);
|
|
1241
1576
|
}
|
|
1242
1577
|
};
|
|
1243
1578
|
}
|
|
1244
|
-
function
|
|
1245
|
-
const o = (
|
|
1579
|
+
function ao(t, e, n) {
|
|
1580
|
+
const o = (r) => ({ x: r.x + e, y: r.y + n }), s = (r) => Object.fromEntries(Object.entries(r).map(([h, i]) => [h, i.map(o)]));
|
|
1246
1581
|
return {
|
|
1247
1582
|
...t,
|
|
1248
|
-
points: Object.fromEntries(Object.entries(t.points).map(([
|
|
1249
|
-
chains:
|
|
1250
|
-
parts: Object.fromEntries(Object.entries(t.parts).map(([
|
|
1583
|
+
points: Object.fromEntries(Object.entries(t.points).map(([r, h]) => [r, o(h)])),
|
|
1584
|
+
chains: s(t.chains),
|
|
1585
|
+
parts: Object.fromEntries(Object.entries(t.parts).map(([r, h]) => [r, { ...h, points: h.points.map(o) }])),
|
|
1251
1586
|
head: { ...t.head, center: o(t.head.center) },
|
|
1252
1587
|
groundY: t.groundY + n
|
|
1253
1588
|
};
|
|
1254
1589
|
}
|
|
1255
|
-
function
|
|
1590
|
+
function $o(t, e, n) {
|
|
1256
1591
|
const o = t.character;
|
|
1257
1592
|
if (!o) throw new Error("characterAt: the target was not made by characterTarget");
|
|
1258
|
-
const
|
|
1259
|
-
let
|
|
1593
|
+
const s = { ...t.props };
|
|
1594
|
+
let r = 0, h = 0;
|
|
1260
1595
|
for (const [l, a] of e.state?.values.get(n) ?? [])
|
|
1261
|
-
typeof a == "number" && (l === "x" || l === "motionPathX" ?
|
|
1262
|
-
const i =
|
|
1263
|
-
return { pose:
|
|
1596
|
+
typeof a == "number" && (l === "x" || l === "motionPathX" ? r = a : l === "y" || l === "motionPathY" ? h = a : l in s && (s[l] = a));
|
|
1597
|
+
const i = oo(o, s);
|
|
1598
|
+
return { pose: s, joints: ao(i, t.x + r + t.width / 2, t.y + h + t.height) };
|
|
1264
1599
|
}
|
|
1265
|
-
function
|
|
1600
|
+
function Ro(t, e, n = z) {
|
|
1266
1601
|
const o = [];
|
|
1267
|
-
return e.forEach((
|
|
1268
|
-
const i = h === 0 ? n : o[h - 1], l = typeof
|
|
1269
|
-
o.push(l ? { ...l, turn: i.turn ?? 0 } : { ...i, ...
|
|
1270
|
-
}), Object.keys(n).filter((
|
|
1271
|
-
id: `${t}-${
|
|
1602
|
+
return e.forEach((r, h) => {
|
|
1603
|
+
const i = h === 0 ? n : o[h - 1], l = typeof r.pose == "string" ? Qn[r.pose] : void 0;
|
|
1604
|
+
o.push(l ? { ...l, turn: i.turn ?? 0 } : { ...i, ...r.pose });
|
|
1605
|
+
}), Object.keys(n).filter((r) => o.some((h) => (h[r] ?? n[r]) !== n[r])).map((r) => ({
|
|
1606
|
+
id: `${t}-${r}`,
|
|
1272
1607
|
target: t,
|
|
1273
|
-
property:
|
|
1608
|
+
property: r,
|
|
1274
1609
|
keyframes: e.map((h, i) => ({
|
|
1275
1610
|
time: h.time,
|
|
1276
|
-
value: o[i][
|
|
1611
|
+
value: o[i][r] ?? n[r],
|
|
1277
1612
|
...h.easing ? { easing: h.easing } : {}
|
|
1278
1613
|
}))
|
|
1279
1614
|
}));
|
|
1280
1615
|
}
|
|
1281
|
-
const
|
|
1282
|
-
function
|
|
1283
|
-
const e = t.shirt ?? "#e2493b", n = t.trousers ?? "#24476b", o = (i) => i.lineWidth * 0.45,
|
|
1284
|
-
const
|
|
1285
|
-
l.shape(
|
|
1286
|
-
},
|
|
1287
|
-
const a = i.chains.spine,
|
|
1288
|
-
l.shape(
|
|
1616
|
+
const co = (t, e, n) => t.slice(Math.floor((t.length - 1) * e), Math.ceil((t.length - 1) * n) + 1);
|
|
1617
|
+
function Bo(t = {}) {
|
|
1618
|
+
const e = t.shirt ?? "#e2493b", n = t.trousers ?? "#24476b", o = (i) => i.lineWidth * 0.45, s = (i, l, a) => {
|
|
1619
|
+
const f = i.parts[`leg.${a}`].points;
|
|
1620
|
+
l.shape(yt(f, i.height * 0.08, i.height * 0.05), n, o(i));
|
|
1621
|
+
}, r = (i, l) => {
|
|
1622
|
+
const a = i.chains.spine, f = a[0], g = a[a.length - 1], m = { x: f.x - (g.x - f.x) * 0.25, y: f.y - (g.y - f.y) * 0.25 };
|
|
1623
|
+
l.shape(yt([m, ...i.parts.spine.points], i.height * 0.15, i.height * 0.14), e, o(i));
|
|
1289
1624
|
}, h = (i, l, a) => {
|
|
1290
|
-
const
|
|
1291
|
-
l.shape(
|
|
1292
|
-
const E = (
|
|
1293
|
-
l.line(b.slice(1), o(i)), l.line(M.slice(Math.ceil(
|
|
1625
|
+
const f = i.parts[`arm.${a}`].points, g = f[0], m = i.chains.spine[i.chains.spine.length - 1], d = [{ x: g.x + (m.x - g.x) * 0.45, y: g.y + (m.y - g.y) * 0.45 }, ...co(f, 0, 0.45)], u = yt(d, i.height * 0.085, i.height * 0.06), y = d.length, p = u.slice(0, y), x = u.slice(y).reverse();
|
|
1626
|
+
l.shape(u, e, 0);
|
|
1627
|
+
const E = (T) => Math.hypot(T[1].x - m.x, T[1].y - m.y), [b, M] = E(p) > E(x) ? [p, x] : [x, p];
|
|
1628
|
+
l.line(b.slice(1), o(i)), l.line(M.slice(Math.ceil(y * 0.45)), o(i)), l.line([p[y - 1], x[y - 1]], o(i));
|
|
1294
1629
|
};
|
|
1295
1630
|
return {
|
|
1296
1631
|
parts: {
|
|
1297
|
-
"leg.left": { over: (i, l, a) =>
|
|
1298
|
-
"leg.right": { over: (i, l, a) =>
|
|
1299
|
-
spine: { over: (i, l, a) =>
|
|
1632
|
+
"leg.left": { over: (i, l, a) => s(l, a, "left") },
|
|
1633
|
+
"leg.right": { over: (i, l, a) => s(l, a, "right") },
|
|
1634
|
+
spine: { over: (i, l, a) => r(l, a) },
|
|
1300
1635
|
"arm.left": { over: (i, l, a) => h(l, a, "left") },
|
|
1301
1636
|
"arm.right": { over: (i, l, a) => h(l, a, "right") }
|
|
1302
1637
|
}
|
|
1303
1638
|
};
|
|
1304
1639
|
}
|
|
1305
1640
|
export {
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1641
|
+
X as EXPRESSIONS,
|
|
1642
|
+
dn as FINGERS,
|
|
1643
|
+
kt as HAND_REST,
|
|
1644
|
+
un as HAND_SHAPES,
|
|
1645
|
+
Io as HUMAN_EXPRESSIONS,
|
|
1646
|
+
Qn as HUMAN_POSES,
|
|
1647
|
+
z as HUMAN_REST,
|
|
1648
|
+
Ye as POSES,
|
|
1649
|
+
et as REST_POSE,
|
|
1650
|
+
Bo as basicOutfit,
|
|
1651
|
+
Le as blendPose,
|
|
1652
|
+
We as boilFrame,
|
|
1653
|
+
Ao as character,
|
|
1654
|
+
$o as characterAt,
|
|
1655
|
+
io as characterHandPose,
|
|
1656
|
+
oo as characterJoints,
|
|
1657
|
+
Ro as characterPoseTracks,
|
|
1658
|
+
Wo as characterTarget,
|
|
1659
|
+
xo as circlePath,
|
|
1660
|
+
ve as clipErased,
|
|
1661
|
+
ke as createPen,
|
|
1662
|
+
xe as drawCartoonHand,
|
|
1663
|
+
ho as drawCharacter,
|
|
1664
|
+
Ee as drawEraser,
|
|
1665
|
+
Pe as drawHand,
|
|
1666
|
+
Yn as drawPencil,
|
|
1667
|
+
fn as drawStickFigure,
|
|
1668
|
+
Eo as drawnPathTarget,
|
|
1669
|
+
ne as ellipsePoints,
|
|
1670
|
+
To as erasable,
|
|
1671
|
+
ko as handAt,
|
|
1672
|
+
Ft as handJoints,
|
|
1673
|
+
Pn as handJointsAt,
|
|
1674
|
+
R as handPose,
|
|
1675
|
+
mo as headPoint,
|
|
1676
|
+
vo as humanFieldLabel,
|
|
1677
|
+
Vn as humanPlan,
|
|
1678
|
+
F as humanPose,
|
|
1679
|
+
ao as jointsInScene,
|
|
1680
|
+
cn as jointsToScene,
|
|
1681
|
+
Mo as mixHandPoses,
|
|
1682
|
+
_o as mixPoses,
|
|
1683
|
+
ae as partialPath,
|
|
1684
|
+
Fo as pathLength,
|
|
1685
|
+
Ut as pointAlong,
|
|
1686
|
+
Oo as pointOnHead,
|
|
1687
|
+
L as pose,
|
|
1688
|
+
bo as poseTracks,
|
|
1689
|
+
Ho as reachCharacter,
|
|
1690
|
+
Me as resolveStickPose,
|
|
1691
|
+
j as rotateAbout,
|
|
1692
|
+
tt as rubberLimb,
|
|
1693
|
+
So as scrubPath,
|
|
1694
|
+
yo as seatHeight,
|
|
1695
|
+
Ht as sketchPen,
|
|
1696
|
+
wo as stickFigureAt,
|
|
1697
|
+
an as stickFigureJoints,
|
|
1698
|
+
po as stickFigureTarget,
|
|
1699
|
+
go as strideLength,
|
|
1700
|
+
Ce as talkingMouth,
|
|
1701
|
+
Xt as taperedLine,
|
|
1702
|
+
yt as taperedOutline,
|
|
1703
|
+
Ne as walkPose,
|
|
1704
|
+
Po as withErased,
|
|
1705
|
+
Be as withExpression
|
|
1360
1706
|
};
|