@escapeaihq/client-core 0.4.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/LICENSE +21 -0
- package/README.md +122 -0
- package/dist/api.d.ts +836 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +781 -0
- package/dist/api.js.map +1 -0
- package/dist/audio.d.ts +278 -0
- package/dist/audio.d.ts.map +1 -0
- package/dist/audio.js +758 -0
- package/dist/audio.js.map +1 -0
- package/dist/audioProtocol.d.ts +101 -0
- package/dist/audioProtocol.d.ts.map +1 -0
- package/dist/audioProtocol.js +62 -0
- package/dist/audioProtocol.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/visemeGeometry.d.ts +198 -0
- package/dist/visemeGeometry.d.ts.map +1 -0
- package/dist/visemeGeometry.js +297 -0
- package/dist/visemeGeometry.js.map +1 -0
- package/dist/visemeScheduler.d.ts +28 -0
- package/dist/visemeScheduler.d.ts.map +1 -0
- package/dist/visemeScheduler.js +94 -0
- package/dist/visemeScheduler.js.map +1 -0
- package/dist/websocket.d.ts +196 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +250 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +40 -0
- package/src/__tests__/api-pollers.test.ts +524 -0
- package/src/__tests__/audio.test.ts +714 -0
- package/src/__tests__/visemeGeometry.test.ts +465 -0
- package/src/__tests__/visemeScheduler.test.ts +256 -0
- package/src/api.ts +1577 -0
- package/src/audio.ts +934 -0
- package/src/audioProtocol.ts +163 -0
- package/src/index.ts +28 -0
- package/src/visemeGeometry.ts +353 -0
- package/src/visemeScheduler.ts +133 -0
- package/src/websocket.ts +385 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the math helpers used by hybrid-PNG and richer-Persona
|
|
3
|
+
* rendering modes. Includes a sanity check against an actual Wonton
|
|
4
|
+
* bundle's mouth_paths to make sure the computed clip ellipse covers
|
|
5
|
+
* every viseme's extent (no clipping).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
combineDonutPath,
|
|
10
|
+
computeMouthClipEllipse,
|
|
11
|
+
computeTeethTongueGeom,
|
|
12
|
+
computeVisemeOpenness,
|
|
13
|
+
deriveInnerLipPath,
|
|
14
|
+
LIP_THICKNESS_FRACTION,
|
|
15
|
+
OPENNESS_FLOOR,
|
|
16
|
+
parsePathPoints,
|
|
17
|
+
pointsBBox,
|
|
18
|
+
teethOpacityFromOpenness,
|
|
19
|
+
unionMouthPathsBBox,
|
|
20
|
+
} from '../visemeGeometry';
|
|
21
|
+
|
|
22
|
+
// Real mouth_paths from Wonton bundle 322a1d4b — captured from production
|
|
23
|
+
// CloudWatch on 2026-04-27 to make sure our math stays correct against
|
|
24
|
+
// real data, not just synthetic fixtures.
|
|
25
|
+
const WONTON_MOUTH_PATHS: Record<string, string> = {
|
|
26
|
+
ee: 'M 561.14,601.96 C 598.42,596.77 637.53,587.87 674.49,599.80 C 709.64,588.46 746.65,597.84 781.26,606.15 C 766.52,651.90 723.37,689.86 673.01,685.15 C 620.57,688.17 579.69,647.13 561.14,601.96',
|
|
27
|
+
fv: 'M 595.61,634.82 C 608.76,604.79 647.77,580.13 680.52,594.28 C 711.15,578.23 751.74,601.54 761.74,632.07 C 756.02,668.44 716.83,689.14 682.35,685.85 C 646.25,687.99 611.16,667.24 595.61,634.82',
|
|
28
|
+
rest: 'M 591.73,625.95 C 614.93,608.22 646.87,586.29 676.82,602.28 C 705.56,586.58 735.19,609.28 755.30,628.10 C 738.77,655.80 708.17,675.73 674.94,673.18 C 640.21,675.20 609.78,654.06 591.73,625.95',
|
|
29
|
+
r: 'M 598.45,639.46 C 609.03,611.10 645.32,587.30 675.52,600.59 C 703.65,586.03 741.23,609.03 748.00,637.74 C 741.85,671.45 707.25,693.76 673.91,691.17 C 640.30,693.66 607.72,671.86 598.45,639.46',
|
|
30
|
+
aei: 'M 591.78,644.73 C 599.85,611.11 641.40,583.03 675.53,596.87 C 707.67,581.74 749.84,609.41 754.33,642.80 C 751.42,681.52 712.96,710.01 675.02,706.49 C 636.49,709.50 600.22,681.99 591.78,644.73',
|
|
31
|
+
bmp: 'M 591.67,627.51 C 613.04,607.21 645.95,584.45 676.21,600.57 C 705.44,584.84 736.39,608.31 754.86,629.46 C 737.86,656.19 706.65,673.18 674.62,670.80 C 641.21,672.58 610.36,654.26 591.67,627.51',
|
|
32
|
+
th: 'M 590.67,635.07 C 603.75,604.74 643.54,582.50 676.00,595.10 C 705.89,581.22 747.19,602.47 754.84,633.69 C 750.48,672.34 714.84,704.54 675.04,700.99 C 634.42,704.11 600.70,672.30 590.67,635.07',
|
|
33
|
+
qw: 'M 617.47,637.40 C 615.72,610.64 648.99,582.01 674.90,597.33 C 699.65,582.21 733.33,610.60 729.87,636.56 C 730.81,667.30 706.30,698.96 673.12,696.25 C 639.38,699.85 616.20,668.17 617.47,637.40',
|
|
34
|
+
cdgknstxyz:
|
|
35
|
+
'M 594.94,631.12 C 611.87,607.00 646.26,587.03 675.82,600.58 C 704.62,587.07 738.37,607.86 752.95,632.56 C 742.26,664.08 707.24,680.80 675.37,678.47 C 642.06,679.62 609.88,660.79 594.94,631.12',
|
|
36
|
+
l: 'M 589.47,632.62 C 605.07,604.35 643.12,583.90 675.07,596.23 C 705.14,582.54 743.53,601.43 757.63,629.30 C 751.84,667.99 714.17,696.56 675.29,693.69 C 636.06,697.32 599.63,669.90 589.47,632.62',
|
|
37
|
+
o: 'M 607.87,638.15 C 617.15,613.60 647.85,586.05 675.24,602.22 C 701.55,586.73 731.78,614.50 736.88,639.44 C 730.64,668.88 703.55,693.55 672.16,691.01 C 639.81,693.76 614.06,667.98 607.87,638.15',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe('parsePathPoints', () => {
|
|
41
|
+
it('extracts 13 points from a single M+4C path', () => {
|
|
42
|
+
const points = parsePathPoints(WONTON_MOUTH_PATHS.rest);
|
|
43
|
+
// M + 4 × (2 controls + 1 endpoint) = 1 + 12 = 13 points
|
|
44
|
+
expect(points).toHaveLength(13);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('parses negative coordinates correctly', () => {
|
|
48
|
+
const points = parsePathPoints('M -10.5,20 C 30,-40 50,60 70,80');
|
|
49
|
+
expect(points).toEqual([
|
|
50
|
+
{ x: -10.5, y: 20 },
|
|
51
|
+
{ x: 30, y: -40 },
|
|
52
|
+
{ x: 50, y: 60 },
|
|
53
|
+
{ x: 70, y: 80 },
|
|
54
|
+
]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('returns empty array for unparseable input', () => {
|
|
58
|
+
expect(parsePathPoints('')).toEqual([]);
|
|
59
|
+
expect(parsePathPoints('not a path')).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('pointsBBox', () => {
|
|
64
|
+
it('returns null for empty input', () => {
|
|
65
|
+
expect(pointsBBox([])).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('finds correct bbox for scattered points', () => {
|
|
69
|
+
expect(
|
|
70
|
+
pointsBBox([
|
|
71
|
+
{ x: 1, y: 2 },
|
|
72
|
+
{ x: 5, y: -3 },
|
|
73
|
+
{ x: -7, y: 8 },
|
|
74
|
+
]),
|
|
75
|
+
).toEqual({ minX: -7, maxX: 5, minY: -3, maxY: 8 });
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('unionMouthPathsBBox', () => {
|
|
80
|
+
it('returns null for empty mouth paths', () => {
|
|
81
|
+
expect(unionMouthPathsBBox({})).toBeNull();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('covers every viseme path control point against real data', () => {
|
|
85
|
+
const union = unionMouthPathsBBox(WONTON_MOUTH_PATHS);
|
|
86
|
+
expect(union).not.toBeNull();
|
|
87
|
+
// Verify every individual viseme's bbox is contained within the union.
|
|
88
|
+
for (const [viseme, d] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
89
|
+
const bb = pointsBBox(parsePathPoints(d));
|
|
90
|
+
expect(bb).not.toBeNull();
|
|
91
|
+
expect(bb!.minX).toBeGreaterThanOrEqual(union!.minX);
|
|
92
|
+
expect(bb!.maxX).toBeLessThanOrEqual(union!.maxX);
|
|
93
|
+
expect(bb!.minY).toBeGreaterThanOrEqual(union!.minY);
|
|
94
|
+
expect(bb!.maxY).toBeLessThanOrEqual(union!.maxY);
|
|
95
|
+
// Sanity: every viseme should match the source naming.
|
|
96
|
+
expect(WONTON_MOUTH_PATHS[viseme]).toBe(d);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('computeMouthClipEllipse', () => {
|
|
102
|
+
it('returns null for empty mouth paths', () => {
|
|
103
|
+
expect(computeMouthClipEllipse({})).toBeNull();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('produces an ellipse that contains every viseme control point', () => {
|
|
107
|
+
// The whole point of the 1.6/1.8 margin factors is that no viseme's
|
|
108
|
+
// mouth gets clipped at any animation phase. Verify against real data.
|
|
109
|
+
const ellipse = computeMouthClipEllipse(WONTON_MOUTH_PATHS);
|
|
110
|
+
expect(ellipse).not.toBeNull();
|
|
111
|
+
const { cx, cy, rx, ry } = ellipse!;
|
|
112
|
+
for (const [viseme, d] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
113
|
+
for (const p of parsePathPoints(d)) {
|
|
114
|
+
// (x-cx)²/rx² + (y-cy)²/ry² should be ≤ 1 for every point inside
|
|
115
|
+
// the ellipse. Allow a tiny epsilon for float arithmetic.
|
|
116
|
+
const score = ((p.x - cx) / rx) ** 2 + ((p.y - cy) / ry) ** 2;
|
|
117
|
+
expect(score).toBeLessThanOrEqual(1 + 1e-9);
|
|
118
|
+
// Just for clearer test failure messages:
|
|
119
|
+
if (score > 1) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Viseme ${viseme} point (${p.x}, ${p.y}) outside clip ellipse (score ${score.toFixed(4)})`,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('feather stdDeviation is proportional to the smaller radius', () => {
|
|
129
|
+
const ellipse = computeMouthClipEllipse(WONTON_MOUTH_PATHS);
|
|
130
|
+
expect(ellipse).not.toBeNull();
|
|
131
|
+
const expected = Math.min(ellipse!.rx, ellipse!.ry) * 0.1;
|
|
132
|
+
expect(ellipse!.featherStdDev).toBeCloseTo(expected, 6);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('feather stdDeviation has a minimum of 1px', () => {
|
|
136
|
+
// Tiny synthetic mouth path — degenerate paths shouldn't produce a
|
|
137
|
+
// 0-sigma blur (no feather, hard edge).
|
|
138
|
+
const tiny = {
|
|
139
|
+
rest: 'M 100,100 C 100.5,100 101,100.1 101,100.2 C 101,100.3 101,100.4 101,100.5 C 100.5,100.5 100,100.4 100,100.3 C 100,100.2 100,100.1 100,100',
|
|
140
|
+
};
|
|
141
|
+
const ellipse = computeMouthClipEllipse(tiny);
|
|
142
|
+
expect(ellipse).not.toBeNull();
|
|
143
|
+
expect(ellipse!.featherStdDev).toBeGreaterThanOrEqual(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('is centered on the union bbox center', () => {
|
|
147
|
+
const ellipse = computeMouthClipEllipse(WONTON_MOUTH_PATHS);
|
|
148
|
+
const union = unionMouthPathsBBox(WONTON_MOUTH_PATHS);
|
|
149
|
+
expect(ellipse!.cx).toBeCloseTo((union!.minX + union!.maxX) / 2, 6);
|
|
150
|
+
expect(ellipse!.cy).toBeCloseTo((union!.minY + union!.maxY) / 2, 6);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('deriveInnerLipPath', () => {
|
|
155
|
+
it('preserves M+4C topology (13 points, 26 numbers)', () => {
|
|
156
|
+
for (const [, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
157
|
+
const innerD = deriveInnerLipPath(outerD);
|
|
158
|
+
const points = parsePathPoints(innerD);
|
|
159
|
+
expect(points).toHaveLength(13);
|
|
160
|
+
// The path string must start with 'M' and contain exactly 4 'C'
|
|
161
|
+
// commands so WAAPI can interpolate it.
|
|
162
|
+
expect(innerD).toMatch(/^M /);
|
|
163
|
+
expect(innerD.match(/C /g)).toHaveLength(4);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('keeps the corners (Left, Right) unchanged', () => {
|
|
168
|
+
for (const [, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
169
|
+
const outerPts = parsePathPoints(outerD);
|
|
170
|
+
const innerPts = parsePathPoints(deriveInnerLipPath(outerD));
|
|
171
|
+
// Left = index 0 (M start) and 12 (close); Right = index 6 (end of C2)
|
|
172
|
+
expect(innerPts[0]).toEqual(outerPts[0]);
|
|
173
|
+
expect(innerPts[6]).toEqual(outerPts[6]);
|
|
174
|
+
expect(innerPts[12]).toEqual(outerPts[12]);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('shifts Up/Lo midpoints by exactly LIP_THICKNESS_FRACTION · h', () => {
|
|
179
|
+
for (const [, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
180
|
+
const outerPts = parsePathPoints(outerD);
|
|
181
|
+
const innerPts = parsePathPoints(deriveInnerLipPath(outerD));
|
|
182
|
+
const Up = outerPts[3];
|
|
183
|
+
const Lo = outerPts[9];
|
|
184
|
+
const h = Lo.y - Up.y;
|
|
185
|
+
const expectedShift = h * LIP_THICKNESS_FRACTION;
|
|
186
|
+
// Inner Up.y > outer Up.y (shifted DOWN by expectedShift). Path
|
|
187
|
+
// d-string rounds to 2 decimals, so 1-decimal precision suffices.
|
|
188
|
+
expect(innerPts[3].y).toBeCloseTo(Up.y + expectedShift, 1);
|
|
189
|
+
// Inner Lo.y < outer Lo.y (shifted UP by expectedShift)
|
|
190
|
+
expect(innerPts[9].y).toBeCloseTo(Lo.y - expectedShift, 1);
|
|
191
|
+
// X-coordinates unchanged for midpoints (we only shift vertically)
|
|
192
|
+
expect(innerPts[3].x).toBe(Up.x);
|
|
193
|
+
expect(innerPts[9].x).toBe(Lo.x);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('inner ring is fully contained within the outer ring (vertically)', () => {
|
|
198
|
+
// Closed-form check: the inner ring's vertical extent must lie
|
|
199
|
+
// strictly inside the outer ring's vertical extent.
|
|
200
|
+
for (const [viseme, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
201
|
+
const outerPts = parsePathPoints(outerD);
|
|
202
|
+
const innerPts = parsePathPoints(deriveInnerLipPath(outerD));
|
|
203
|
+
const outerBB = pointsBBox(outerPts)!;
|
|
204
|
+
const innerBB = pointsBBox(innerPts)!;
|
|
205
|
+
expect(innerBB.minY).toBeGreaterThanOrEqual(outerBB.minY - 1e-9);
|
|
206
|
+
expect(innerBB.maxY).toBeLessThanOrEqual(outerBB.maxY + 1e-9);
|
|
207
|
+
if (innerBB.minY < outerBB.minY || innerBB.maxY > outerBB.maxY) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`Inner ring escaped outer ring vertically for viseme ${viseme}`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('inner ring height is roughly half the outer ring height', () => {
|
|
216
|
+
// With LIP_THICKNESS_FRACTION = 0.25, anchors are shifted by 0.25h
|
|
217
|
+
// each, so inner ring spans (1 - 0.5)·h = 0.5·h vertically (between
|
|
218
|
+
// the midpoint anchors). Bezier control bulge adds a bit but the
|
|
219
|
+
// anchor-to-anchor span should be exactly half.
|
|
220
|
+
for (const [, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
221
|
+
const outerPts = parsePathPoints(outerD);
|
|
222
|
+
const innerPts = parsePathPoints(deriveInnerLipPath(outerD));
|
|
223
|
+
const outerSpan = outerPts[9].y - outerPts[3].y; // Lo.y - Up.y
|
|
224
|
+
const innerSpan = innerPts[9].y - innerPts[3].y; // innerLo.y - innerUp.y
|
|
225
|
+
// Path d-string rounds to 2 decimals, so 1-decimal tolerance suffices.
|
|
226
|
+
expect(innerSpan).toBeCloseTo(outerSpan * (1 - 2 * LIP_THICKNESS_FRACTION), 1);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('returns the input unchanged for non-13-point paths', () => {
|
|
231
|
+
expect(deriveInnerLipPath('M 0,0 L 10,10')).toBe('M 0,0 L 10,10');
|
|
232
|
+
expect(deriveInnerLipPath('')).toBe('');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('returns the input unchanged for degenerate (h≤0) paths', () => {
|
|
236
|
+
// All 13 points at the same y → h = 0
|
|
237
|
+
const flat =
|
|
238
|
+
'M 0,5 C 1,5 2,5 3,5 C 4,5 5,5 6,5 C 7,5 8,5 9,5 C 10,5 11,5 12,5';
|
|
239
|
+
expect(deriveInnerLipPath(flat)).toBe(flat);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it('control-point shift respects segment direction (concrete check)', () => {
|
|
243
|
+
// For Wonton's rest viseme:
|
|
244
|
+
// Left=(591.73,625.95), Up=(676.82,602.28), Lo=(674.94,673.18)
|
|
245
|
+
// h = 673.18 - 602.28 = 70.90 → shift = 17.725
|
|
246
|
+
// Segment 1 (Left→Up) ctrl1 should shift DOWN by 1/3 · shift = 5.908
|
|
247
|
+
// Original ctrl1 = (614.93, 608.22) → inner ctrl1 = (614.93, 614.13)
|
|
248
|
+
const outerD = WONTON_MOUTH_PATHS.rest;
|
|
249
|
+
const innerPts = parsePathPoints(deriveInnerLipPath(outerD));
|
|
250
|
+
expect(innerPts[1].x).toBeCloseTo(614.93, 2);
|
|
251
|
+
expect(innerPts[1].y).toBeCloseTo(614.13, 1);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe('combineDonutPath', () => {
|
|
256
|
+
it('joins outer + inner with a single space', () => {
|
|
257
|
+
const outer = 'M 0,0 C 1,1 2,2 3,3';
|
|
258
|
+
const inner = 'M 4,4 C 5,5 6,6 7,7';
|
|
259
|
+
expect(combineDonutPath(outer, inner)).toBe(`${outer} ${inner}`);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('produces 52 numbers when applied to real M+4C paths', () => {
|
|
263
|
+
// Outer: 26 numbers; Inner derived: 26 numbers. Total 52.
|
|
264
|
+
// WAAPI requires identical numeric topology across viseme keyframes.
|
|
265
|
+
const totals = new Set<number>();
|
|
266
|
+
for (const [, outerD] of Object.entries(WONTON_MOUTH_PATHS)) {
|
|
267
|
+
const innerD = deriveInnerLipPath(outerD);
|
|
268
|
+
const donut = combineDonutPath(outerD, innerD);
|
|
269
|
+
const numbers = donut.match(/-?\d+(?:\.\d+)?/g) ?? [];
|
|
270
|
+
totals.add(numbers.length);
|
|
271
|
+
}
|
|
272
|
+
expect(totals.size).toBe(1);
|
|
273
|
+
expect([...totals][0]).toBe(52);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('computeTeethTongueGeom', () => {
|
|
278
|
+
it('returns null for empty mouth paths', () => {
|
|
279
|
+
expect(computeTeethTongueGeom({})).toBeNull();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('upper teeth sit above lower teeth, both above tongue baseline', () => {
|
|
283
|
+
const geom = computeTeethTongueGeom(WONTON_MOUTH_PATHS);
|
|
284
|
+
expect(geom).not.toBeNull();
|
|
285
|
+
const { upperTeeth, lowerTeeth, tongue } = geom!;
|
|
286
|
+
// Upper teeth's bottom edge must be above lower teeth's top edge.
|
|
287
|
+
expect(upperTeeth.y + upperTeeth.height).toBeLessThan(lowerTeeth.y);
|
|
288
|
+
// Tongue ellipse center is between the two teeth strips.
|
|
289
|
+
expect(tongue.cy).toBeGreaterThan(upperTeeth.y + upperTeeth.height);
|
|
290
|
+
expect(tongue.cy).toBeLessThan(lowerTeeth.y);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('teeth widths are equal and centered on the union bbox center', () => {
|
|
294
|
+
const geom = computeTeethTongueGeom(WONTON_MOUTH_PATHS);
|
|
295
|
+
const union = unionMouthPathsBBox(WONTON_MOUTH_PATHS)!;
|
|
296
|
+
const cx = (union.minX + union.maxX) / 2;
|
|
297
|
+
expect(geom!.upperTeeth.width).toBe(geom!.lowerTeeth.width);
|
|
298
|
+
expect(geom!.upperTeeth.x + geom!.upperTeeth.width / 2).toBeCloseTo(cx, 4);
|
|
299
|
+
expect(geom!.lowerTeeth.x + geom!.lowerTeeth.width / 2).toBeCloseTo(cx, 4);
|
|
300
|
+
expect(geom!.tongue.cx).toBeCloseTo(cx, 4);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('teeth and tongue all fit within the union bbox', () => {
|
|
304
|
+
// We rely on the inner-lip-ring clip path to actually crop these to
|
|
305
|
+
// the morphing mouth, but the geometry shouldn't overflow the union
|
|
306
|
+
// bbox even before clipping.
|
|
307
|
+
const geom = computeTeethTongueGeom(WONTON_MOUTH_PATHS)!;
|
|
308
|
+
const u = unionMouthPathsBBox(WONTON_MOUTH_PATHS)!;
|
|
309
|
+
expect(geom.upperTeeth.x).toBeGreaterThanOrEqual(u.minX);
|
|
310
|
+
expect(geom.upperTeeth.x + geom.upperTeeth.width).toBeLessThanOrEqual(u.maxX);
|
|
311
|
+
expect(geom.lowerTeeth.x).toBeGreaterThanOrEqual(u.minX);
|
|
312
|
+
expect(geom.lowerTeeth.x + geom.lowerTeeth.width).toBeLessThanOrEqual(u.maxX);
|
|
313
|
+
expect(geom.tongue.cx - geom.tongue.rx).toBeGreaterThanOrEqual(u.minX);
|
|
314
|
+
expect(geom.tongue.cx + geom.tongue.rx).toBeLessThanOrEqual(u.maxX);
|
|
315
|
+
expect(geom.tongue.cy - geom.tongue.ry).toBeGreaterThanOrEqual(u.minY);
|
|
316
|
+
expect(geom.tongue.cy + geom.tongue.ry).toBeLessThanOrEqual(u.maxY);
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe('computeVisemeOpenness', () => {
|
|
321
|
+
it('returns null for empty input', () => {
|
|
322
|
+
expect(computeVisemeOpenness({})).toBeNull();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('produces a value in [0, 1] for every viseme in real bundle data', () => {
|
|
326
|
+
const openness = computeVisemeOpenness(WONTON_MOUTH_PATHS);
|
|
327
|
+
expect(openness).not.toBeNull();
|
|
328
|
+
for (const v of Object.keys(WONTON_MOUTH_PATHS)) {
|
|
329
|
+
expect(openness![v]).toBeGreaterThanOrEqual(0);
|
|
330
|
+
expect(openness![v]).toBeLessThanOrEqual(1);
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('most closed viseme is at 0 and most open is at 1', () => {
|
|
335
|
+
const openness = computeVisemeOpenness(WONTON_MOUTH_PATHS)!;
|
|
336
|
+
const minVal = Math.min(...Object.values(openness));
|
|
337
|
+
const maxVal = Math.max(...Object.values(openness));
|
|
338
|
+
expect(minVal).toBe(0);
|
|
339
|
+
expect(maxVal).toBe(1);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it('Wonton "aei" is most open and "bmp" is most closed', () => {
|
|
343
|
+
// Sanity check against the actual data so a regression in the path
|
|
344
|
+
// ordering would surface immediately.
|
|
345
|
+
const openness = computeVisemeOpenness(WONTON_MOUTH_PATHS)!;
|
|
346
|
+
expect(openness.aei).toBe(1);
|
|
347
|
+
expect(openness.bmp).toBe(0);
|
|
348
|
+
// rest, fv, bmp are all closed-ish
|
|
349
|
+
expect(openness.rest).toBeLessThan(0.1);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe('teethOpacityFromOpenness', () => {
|
|
354
|
+
it('returns 0 at openness = 0', () => {
|
|
355
|
+
expect(teethOpacityFromOpenness(0)).toBe(0);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('returns 0 at and below the floor', () => {
|
|
359
|
+
expect(teethOpacityFromOpenness(OPENNESS_FLOOR)).toBe(0);
|
|
360
|
+
expect(teethOpacityFromOpenness(0.05)).toBe(0);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('returns 1 at openness = 1', () => {
|
|
364
|
+
expect(teethOpacityFromOpenness(1)).toBe(1);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('clamps above 1', () => {
|
|
368
|
+
expect(teethOpacityFromOpenness(2)).toBe(1);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('ramps linearly above the floor', () => {
|
|
372
|
+
// (0.5 - 0.15) * 1.5 = 0.525
|
|
373
|
+
expect(teethOpacityFromOpenness(0.5)).toBeCloseTo(0.525, 6);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('Wonton mapping: closed visemes hide teeth, open visemes show them', () => {
|
|
377
|
+
const openness = computeVisemeOpenness(WONTON_MOUTH_PATHS)!;
|
|
378
|
+
// Closed visemes: opacity 0
|
|
379
|
+
expect(teethOpacityFromOpenness(openness.bmp)).toBe(0);
|
|
380
|
+
expect(teethOpacityFromOpenness(openness.rest)).toBe(0);
|
|
381
|
+
// Wide-open visemes: high opacity
|
|
382
|
+
expect(teethOpacityFromOpenness(openness.aei)).toBeGreaterThan(0.9);
|
|
383
|
+
expect(teethOpacityFromOpenness(openness.th)).toBeGreaterThan(0.9);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it('respects override floor + slope', () => {
|
|
387
|
+
// Custom floor=0.3 → openness < 0.3 yields 0
|
|
388
|
+
expect(teethOpacityFromOpenness(0.2, { floor: 0.3 })).toBe(0);
|
|
389
|
+
// Custom slope=3 doubles the rise rate
|
|
390
|
+
expect(
|
|
391
|
+
teethOpacityFromOpenness(0.5, { floor: 0, slope: 3 }),
|
|
392
|
+
).toBeCloseTo(1, 4); // 0.5 * 3 = 1.5, clamped to 1
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// ── Property tests across the tuner's slider ranges ───────────────────
|
|
397
|
+
//
|
|
398
|
+
// The Visuals tab of the persona tuner lets the user drag these
|
|
399
|
+
// constants. Verify that for any value the slider can produce, the
|
|
400
|
+
// math invariants the rendering relies on still hold (no negative
|
|
401
|
+
// dimensions, inner ring stays inside outer ring, ellipse contains
|
|
402
|
+
// every viseme, opacities clamped to [0, 1]).
|
|
403
|
+
//
|
|
404
|
+
// Sweep grids are coarse on purpose — they cover the slider extents +
|
|
405
|
+
// a couple of mid-points; finer-grained values share the same math.
|
|
406
|
+
|
|
407
|
+
describe('property tests across slider ranges', () => {
|
|
408
|
+
it.each([0.05, 0.15, 0.25, 0.35, 0.45])(
|
|
409
|
+
'inner ring stays inside outer ring for lipThicknessFraction=%s',
|
|
410
|
+
(lipThicknessFraction) => {
|
|
411
|
+
for (const outerD of Object.values(WONTON_MOUTH_PATHS)) {
|
|
412
|
+
const innerD = deriveInnerLipPath(outerD, { lipThicknessFraction });
|
|
413
|
+
const outerBB = pointsBBox(parsePathPoints(outerD))!;
|
|
414
|
+
const innerBB = pointsBBox(parsePathPoints(innerD))!;
|
|
415
|
+
expect(innerBB.minY).toBeGreaterThanOrEqual(outerBB.minY - 1e-9);
|
|
416
|
+
expect(innerBB.maxY).toBeLessThanOrEqual(outerBB.maxY + 1e-9);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
);
|
|
420
|
+
|
|
421
|
+
it.each([1.2, 1.6, 2.0, 2.5])(
|
|
422
|
+
'clip ellipse contains every viseme point for marginX=%s, marginY=2.0',
|
|
423
|
+
(marginX) => {
|
|
424
|
+
const ellipse = computeMouthClipEllipse(WONTON_MOUTH_PATHS, {
|
|
425
|
+
marginX,
|
|
426
|
+
marginY: 2.0,
|
|
427
|
+
});
|
|
428
|
+
expect(ellipse).not.toBeNull();
|
|
429
|
+
const { cx, cy, rx, ry } = ellipse!;
|
|
430
|
+
for (const outerD of Object.values(WONTON_MOUTH_PATHS)) {
|
|
431
|
+
for (const p of parsePathPoints(outerD)) {
|
|
432
|
+
const score = ((p.x - cx) / rx) ** 2 + ((p.y - cy) / ry) ** 2;
|
|
433
|
+
expect(score).toBeLessThanOrEqual(1 + 1e-9);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
it.each([0, 0.05, 0.15, 0.3])(
|
|
440
|
+
'feather stdDeviation stays at >= 1 for featherFactor=%s',
|
|
441
|
+
(featherFactor) => {
|
|
442
|
+
const ellipse = computeMouthClipEllipse(WONTON_MOUTH_PATHS, {
|
|
443
|
+
featherFactor,
|
|
444
|
+
});
|
|
445
|
+
expect(ellipse).not.toBeNull();
|
|
446
|
+
expect(ellipse!.featherStdDev).toBeGreaterThanOrEqual(1);
|
|
447
|
+
},
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
it.each([
|
|
451
|
+
[0, 1],
|
|
452
|
+
[0.15, 1.5],
|
|
453
|
+
[0.5, 0.5],
|
|
454
|
+
[0.9, 4],
|
|
455
|
+
])(
|
|
456
|
+
'teeth opacity stays in [0, 1] for floor=%s, slope=%s across openness sweep',
|
|
457
|
+
(floor, slope) => {
|
|
458
|
+
for (let openness = 0; openness <= 1; openness += 0.1) {
|
|
459
|
+
const op = teethOpacityFromOpenness(openness, { floor, slope });
|
|
460
|
+
expect(op).toBeGreaterThanOrEqual(0);
|
|
461
|
+
expect(op).toBeLessThanOrEqual(1);
|
|
462
|
+
}
|
|
463
|
+
},
|
|
464
|
+
);
|
|
465
|
+
});
|