wireface 1.0.2 → 1.1.1

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  [![stars](https://img.shields.io/github/stars/styk-tv/wireface?style=flat&logo=github)](https://github.com/styk-tv/wireface)
9
9
  [![babylon](https://img.shields.io/badge/babylon.js-v9-bb464b)](https://www.babylonjs.com/)
10
10
 
11
- **A drop-in lipsync renderer for stylized character profiles — no rigged avatar, no ML inference, no server roundtrip.** wireface analyses voice or TTS audio in the browser and drives a wireframe face mesh through 28 expression channels (15 visemes + jaw, lips, blinks, eye gaze, squint, brows, nose, head rotation). Each character is one JSON preset — mesh resolution, colors, depth fade, glow, mood weights, channel gains — saved from the bundled editor and replayed by a single JS file. One canvas, one peer dependency (Babylon.js v9), one `createWireface(canvas)` call. Each instance is fully independent, so a page can host as many talking heads as it has audio sources.
11
+ **A drop-in lipsync renderer for stylized character profiles — no rigged avatar, no ML inference, no server roundtrip.** wireface analyses voice or TTS audio in the browser and drives a wireframe face mesh through **30 expression channels** — 15 visemes from the [Oculus Lipsync](https://developer.oculus.com/documentation/native/audio-ovrlipsync-viseme-reference/) phoneme alphabet plus 15 [ARKit-style](https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation) face blendshapes (jaw, lips, blinks, eye gaze, squint, brows, nose, head rotation). Each character is one JSON preset — mesh resolution, colors, depth fade, glow, mood weights, channel gains — saved from the bundled editor and replayed by a single JS file. One canvas, one peer dependency (Babylon.js v9), one `createWireface(canvas)` call. Each instance is fully independent, so a page can host as many talking heads as it has audio sources.
12
12
 
13
13
  ![wireface](docs/wireface.png)
14
14
 
@@ -281,6 +281,61 @@ If you build a public tool / site / experiment with it, a star on the repo is a
281
281
 
282
282
  ---
283
283
 
284
+ ## References
285
+
286
+ The channel grammar is the union of two well-established blendshape
287
+ inventories. Pick one to read end-to-end and the other will look familiar.
288
+
289
+ ### Oculus Lipsync · 15 visemes (mouth-shape primitives)
290
+
291
+ The 15 viseme channels (`viseme_sil`, `viseme_PP`, `viseme_FF`, `viseme_TH`,
292
+ `viseme_DD`, `viseme_kk`, `viseme_CH`, `viseme_SS`, `viseme_nn`, `viseme_RR`,
293
+ `viseme_aa`, `viseme_E`, `viseme_I`, `viseme_O`, `viseme_U`) come from the
294
+ Oculus Lipsync SDK's phoneme alphabet. The same set ships with HeadTTS,
295
+ Kokoro, ovrlipsync, and most "phoneme alignment" pipelines. Audio FFT
296
+ estimates the active viseme each frame and the renderer weighted-sums the
297
+ `(open, width, round, smile, lipPress, jaw)` targets.
298
+
299
+ - [Oculus Audio SDK — Viseme Reference](https://developer.oculus.com/documentation/native/audio-ovrlipsync-viseme-reference/)
300
+ — the canonical 15-viseme table plus example audio cues per phoneme.
301
+ - [Oculus Lipsync overview](https://developer.oculus.com/documentation/native/audio-ovrlipsync-native/)
302
+ — what the SDK does and why the 15-viseme split.
303
+
304
+ ### ARKit · 15-of-52 face blendshapes (additive face shape)
305
+
306
+ The remaining 15 channels (`jawOpen`, `mouthSmile`, `mouthPucker`,
307
+ `eyeBlinkLeft/Right`, `eyeLookH/V`, `eyeSquint`, `browInnerUp/OuterUp/Down`,
308
+ `noseSneer`, `headRotateX/Y/Z`) are a curated subset of Apple ARKit's full
309
+ 52-blendshape inventory, named to match. ARKit blendshapes are the
310
+ de-facto industry standard for face animation since iPhone X / TrueDepth;
311
+ glTF face blendshapes, MetaHuman, NVIDIA Audio2Face, and Ready Player Me
312
+ all use compatible naming.
313
+
314
+ - [ARKit `BlendShapeLocation` reference](https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation)
315
+ — full 52-blendshape list with semantic names + face-region grouping.
316
+ - [ARKit Face Tracking overview](https://developer.apple.com/documentation/arkit/tracking_and_visualizing_faces)
317
+ — what ARKit's blendshapes mean and how they're estimated from the
318
+ TrueDepth depth+IR camera.
319
+
320
+ ### Why this split?
321
+
322
+ A renderer that only knew Oculus visemes would lipsync audio but couldn't
323
+ emote. A renderer that only knew ARKit blendshapes would emote but
324
+ lipsync poorly (ARKit's mouth blendshapes are continuous 0..1 dilations,
325
+ not phoneme-aligned). Combining both gives **mouth that lipsyncs from
326
+ audio + face that emotes from explicit channels** — they layer additively
327
+ in `computeMouthParams()` so both signals can drive the face simultaneously
328
+ without conflict.
329
+
330
+ The full grammar (channel names, ranges, smoothing, drive maps, preset
331
+ JSON shape, invariants) is in
332
+ [`SPEC.WIREFACE.GRAMMAR.v1.0.md`](SPEC.WIREFACE.GRAMMAR.v1.0.md).
333
+ Babylon.js setup details (multi-instance scenes, multi-canvas pages,
334
+ playground integration) are in
335
+ [`SPEC.WIREFACE.BABYLON.9.0.md`](SPEC.WIREFACE.BABYLON.9.0.md).
336
+
337
+ ---
338
+
284
339
  ## License
285
340
 
286
341
  MIT © 2026 Peter Styk — see [`LICENSE`](LICENSE).
package/dist/wireface.js CHANGED
@@ -168,10 +168,25 @@
168
168
  overlayTracksMesh: true,
169
169
  moodTransitionTime: 0.6,
170
170
  lineColor: '#ffffff', pupilColor: '#ffffff',
171
+ // Per-feature minimal-line overrides. null = inherit lineColor (backward
172
+ // compat with v1.0.x presets). Each feature can be hidden individually
173
+ // even when the master `minimal` is on. Each has its own thickness
174
+ // multiplier on top of the global `lineThickness`.
175
+ mouthColor: null, eyeColor: null, noseColor: null,
176
+ minimalMouth: true, minimalEyes: true, minimalNose: true, minimalBrows: true,
177
+ mouthLineThickness: 1.0, eyeLineThickness: 1.0, noseLineThickness: 1.0, browLineThickness: 1.0,
171
178
  baseColor: '#ffffff', fadeColor: '#000000', depthFade: 0.0,
179
+ // exponent applied to the per-vertex fade weight. >1 darkens the back
180
+ // faster (so silhouette edges actually reach fadeColor in wire mode);
181
+ // <1 brightens it. 1.0 = linear, original behavior.
182
+ depthFadeCurve: 1.0,
172
183
  irisColor: '#000000', irisSize: 1.6,
173
184
  browColor: '#ffffff',
174
185
  jawExtend: 0.0, mouthGrow: 0.0,
186
+ // experimental — static z push of upper-mouth and lower-jaw regions for
187
+ // animal / crocodile-mouth distortions. Stack on top of jawExtend (which
188
+ // is jawOpen-driven). Default 0 = current behavior.
189
+ upperJawProtrude: 0.0, lowerJawProtrude: 0.0,
175
190
  cameraView: 'three-q', // initial view
176
191
  };
177
192
 
@@ -229,6 +244,17 @@
229
244
  /* ── Babylon scene ── */
230
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
231
246
  const scene = new BABYLON.Scene(engine);
247
+ // v1.1.1: right-handed coordinate system. Babylon defaults to LH where +Z
248
+ // is into the screen, so a face built with +Z=nose-forward by warpToFace
249
+ // would render facing AWAY from the default ArcRotateCamera at -Z (the
250
+ // user would see the back of the head). RH flips Z so +Z is out-of-screen,
251
+ // which means the face naturally faces the camera AND the camera view
252
+ // alphas (front=-π/2, profile=0, three-q=-π/2-0.6) map to the
253
+ // conventionally-correct sides of the face — front shows the front,
254
+ // profile shows the face's right, three-quarter is a proper portrait
255
+ // angle. Fixes the "everything is flipped so views start incorrectly"
256
+ // bug without touching warpToFace, faceRoot.rotation, or any view alpha.
257
+ scene.useRightHandedSystem = true;
232
258
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
233
259
  // we never pick on pointer-move; saves a per-frame ray test
234
260
  scene.skipPointerMovePicking = true;
@@ -272,15 +298,23 @@
272
298
  wireMat.alpha = 1;
273
299
  wireMat.useVertexColor = true;
274
300
 
275
- const minimalMat = new BABYLON.StandardMaterial('minimalMat', scene);
276
- minimalMat.emissiveColor = new BABYLON.Color3(1, 1, 1);
277
- minimalMat.disableLighting = true;
278
- minimalMat.specularColor = new BABYLON.Color3(0, 0, 0);
279
-
280
- const browMat = new BABYLON.StandardMaterial('browMat', scene);
281
- browMat.emissiveColor = new BABYLON.Color3(1, 1, 1);
282
- browMat.disableLighting = true;
283
- browMat.specularColor = new BABYLON.Color3(0, 0, 0);
301
+ /* one material per minimal-line feature so each can have its own color
302
+ independent of the others. lineColor is the shared fallback; if a
303
+ per-feature color (mouthColor/eyeColor/noseColor) is null the feature
304
+ inherits lineColor at apply time. */
305
+ function makeMinimalMat(name) {
306
+ const m = new BABYLON.StandardMaterial(name, scene);
307
+ m.emissiveColor = new BABYLON.Color3(1, 1, 1);
308
+ m.disableLighting = true;
309
+ m.specularColor = new BABYLON.Color3(0, 0, 0);
310
+ return m;
311
+ }
312
+ const mouthMat = makeMinimalMat('mouthMat');
313
+ const eyeMat = makeMinimalMat('eyeMat');
314
+ const noseMat = makeMinimalMat('noseMat');
315
+ const browMat = makeMinimalMat('browMat');
316
+ // legacy alias — some downstream code still references minimalMat
317
+ const minimalMat = mouthMat;
284
318
 
285
319
  const minimalGroup = new BABYLON.TransformNode('minimal', scene);
286
320
  minimalGroup.parent = faceRoot;
@@ -311,8 +345,12 @@
311
345
  let z = (1 - xRel*xRel * 0.55 - yRel*yRel * 0.55) * 0.22;
312
346
  if (z < -0.05) z = -0.05;
313
347
 
314
- // eye sockets recess (gaussian — broad and bowl-shaped)
315
- const eyeY = 0.30;
348
+ // eye sockets recess (gaussian — broad and bowl-shaped).
349
+ // Centered at yRel=0.20 → UV v=0.40 to align with the eye opening
350
+ // (eye-hole puncture, minimal-line eyelid overlay, eye_blink shapes
351
+ // are all at v=0.40). Original v011 used yRel=0.30 which placed the
352
+ // bowl above the eye opening.
353
+ const eyeY = 0.20;
316
354
  const eyeL_d = ((xRel + 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
317
355
  const eyeR_d = ((xRel - 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
318
356
  const eyeRecess = 0.045 * config.eyeDepth;
@@ -732,6 +770,45 @@
732
770
  }
733
771
  }
734
772
 
773
+ /* Static jaw-protrude passes — push the upper-mouth and lower-jaw
774
+ regions forward (z+) independent of jawOpen. Used together they
775
+ form the snout / animal / crocodile-mouth distortion. Each is a
776
+ smooth tent ramp in v-space:
777
+ - upper: peaks at v=0.62 (just above the mouth), tapers off by
778
+ v=0.45 (top) and v=0.72 (mouth line)
779
+ - lower: peaks at v=0.85 (chin tip), tapers off by v=0.70 (mouth)
780
+ and v=1.0 (bottom of grid)
781
+ Magnitude is `protrude * 0.18` for both — at amt=3 (slider max),
782
+ lower jaw juts forward ~0.54 z-units which is comparable to the
783
+ nose tip's z=0.22, giving a clearly elongated jaw silhouette. */
784
+ function applyUpperJawProtrude(disp) {
785
+ const amt = config.upperJawProtrude;
786
+ if (amt < 0.001) return;
787
+ const push = amt * 0.18;
788
+ for (let i = 0; i < baseUVs.length; i++) {
789
+ const v = baseUVs[i].v;
790
+ if (v < 0.45 || v > 0.72) continue;
791
+ // tent: 0 at edges, 1 at v=0.62
792
+ const w = v < 0.62 ? (v - 0.45) / 0.17 : (0.72 - v) / 0.10;
793
+ disp[i].z += push * w;
794
+ }
795
+ }
796
+ function applyLowerJawProtrude(disp) {
797
+ const amt = config.lowerJawProtrude;
798
+ if (amt < 0.001) return;
799
+ const push = amt * 0.18;
800
+ for (let i = 0; i < baseUVs.length; i++) {
801
+ const v = baseUVs[i].v;
802
+ if (v < 0.70) continue;
803
+ // tent: 0 at v=0.70, 1 at v=0.85, tapers to 0.5 at v=1.0
804
+ let w;
805
+ if (v < 0.85) w = (v - 0.70) / 0.15;
806
+ else w = 1 - (v - 0.85) / 0.30; // ramp down past chin tip
807
+ if (w < 0) w = 0;
808
+ disp[i].z += push * w;
809
+ }
810
+ }
811
+
735
812
  function applyMouthAnchors(disp) {
736
813
  if (!config.mouthAnchor) return;
737
814
  const p = computeMouthParams();
@@ -894,12 +971,18 @@
894
971
  return out;
895
972
  }
896
973
 
897
- function makeTube(name, points, radius, instance) {
898
- const r = instance ? radius : radius * config.lineThickness;
974
+ /* makeTube creates a new tube OR updates an existing one in-place.
975
+ Final radius = baseRadius * featureMul * config.lineThickness — applied
976
+ in BOTH new and instance forms. Babylon's CreateTube instance-form
977
+ applies opts.radius every call (it does not preserve the radius from
978
+ construction), so updateMinimal MUST pass the current featureMul each
979
+ frame or the tube collapses to (base × 1 × lineThickness). */
980
+ function makeTube(name, points, radius, mat, featureMul, instance) {
981
+ const r = radius * (featureMul == null ? 1 : featureMul) * config.lineThickness;
899
982
  const opts = { path: points, radius: r, tessellation: 6, updatable: true };
900
983
  if (instance) opts.instance = instance;
901
984
  const tube = BABYLON.MeshBuilder.CreateTube(name, opts, scene);
902
- if (!instance) { tube.material = minimalMat; tube.parent = minimalGroup; }
985
+ if (!instance) { tube.material = mat || mouthMat; tube.parent = minimalGroup; }
903
986
  return tube;
904
987
  }
905
988
 
@@ -992,39 +1075,44 @@
992
1075
  if (noseLeftMesh) { noseLeftMesh.dispose(); noseLeftMesh = null; }
993
1076
  if (noseRightMesh) { noseRightMesh.dispose(); noseRightMesh = null; }
994
1077
  const { upper, lower } = mouthLipPaths();
995
- mouthUpperMesh = makeTube('mouth_u', upper, 0.010);
996
- mouthLowerMesh = makeTube('mouth_l', lower, 0.010);
1078
+ mouthUpperMesh = makeTube('mouth_u', upper, 0.010, mouthMat, config.mouthLineThickness);
1079
+ mouthLowerMesh = makeTube('mouth_l', lower, 0.010, mouthMat, config.mouthLineThickness);
997
1080
  for (const eye of eyeData) {
998
- const u = makeTube('eye_' + eye.side + '_u', eyePath(eye, true), 0.0085);
999
- const l = makeTube('eye_' + eye.side + '_l', eyePath(eye, false), 0.0085);
1081
+ const u = makeTube('eye_' + eye.side + '_u', eyePath(eye, true), 0.0085, eyeMat, config.eyeLineThickness);
1082
+ const l = makeTube('eye_' + eye.side + '_l', eyePath(eye, false), 0.0085, eyeMat, config.eyeLineThickness);
1000
1083
  eyeMeshes.push({ eye, upper: u, lower: l });
1001
1084
  }
1002
1085
  for (const brow of browData) {
1003
- const m = makeTube('brow_' + brow.side, browPath(brow), 0.011);
1004
- m.material = browMat;
1086
+ const m = makeTube('brow_' + brow.side, browPath(brow), 0.011, browMat, config.browLineThickness);
1005
1087
  browMeshes.push({ brow, mesh: m });
1006
1088
  }
1007
1089
  const np = nosePaths();
1008
- noseBridgeMesh = makeTube('nose_b', np.bridge, 0.009);
1009
- noseLeftMesh = makeTube('nose_l', np.leftN, 0.0085);
1010
- noseRightMesh = makeTube('nose_r', np.rightN, 0.0085);
1090
+ noseBridgeMesh = makeTube('nose_b', np.bridge, 0.009, noseMat, config.noseLineThickness);
1091
+ noseLeftMesh = makeTube('nose_l', np.leftN, 0.0085, noseMat, config.noseLineThickness);
1092
+ noseRightMesh = makeTube('nose_r', np.rightN, 0.0085, noseMat, config.noseLineThickness);
1011
1093
  applyMinimalVisibility();
1094
+ applyMinimalSubVisibility();
1012
1095
  }
1013
1096
 
1014
1097
  function updateMinimal() {
1015
1098
  if (!mouthUpperMesh) return;
1099
+ // Babylon's CreateTube instance-form applies opts.radius EVERY call —
1100
+ // it doesn't preserve the radius from construction. So we must pass the
1101
+ // current per-feature thickness multiplier on every frame, otherwise
1102
+ // the tube collapses back to (base × 1 × lineThickness) and the
1103
+ // per-feature slider has no visible effect.
1016
1104
  const mp = mouthLipPaths();
1017
- makeTube('', mp.upper, 0.010, mouthUpperMesh);
1018
- makeTube('', mp.lower, 0.010, mouthLowerMesh);
1105
+ makeTube('', mp.upper, 0.010, null, config.mouthLineThickness, mouthUpperMesh);
1106
+ makeTube('', mp.lower, 0.010, null, config.mouthLineThickness, mouthLowerMesh);
1019
1107
  for (const em of eyeMeshes) {
1020
- makeTube('', eyePath(em.eye, true), 0.0085, em.upper);
1021
- makeTube('', eyePath(em.eye, false), 0.0085, em.lower);
1108
+ makeTube('', eyePath(em.eye, true), 0.0085, null, config.eyeLineThickness, em.upper);
1109
+ makeTube('', eyePath(em.eye, false), 0.0085, null, config.eyeLineThickness, em.lower);
1022
1110
  }
1023
- for (const bm of browMeshes) makeTube('', browPath(bm.brow), 0.011, bm.mesh);
1111
+ for (const bm of browMeshes) makeTube('', browPath(bm.brow), 0.011, null, config.browLineThickness, bm.mesh);
1024
1112
  const np = nosePaths();
1025
- makeTube('', np.bridge, 0.009, noseBridgeMesh);
1026
- makeTube('', np.leftN, 0.0085, noseLeftMesh);
1027
- makeTube('', np.rightN, 0.0085, noseRightMesh);
1113
+ makeTube('', np.bridge, 0.009, null, config.noseLineThickness, noseBridgeMesh);
1114
+ makeTube('', np.leftN, 0.0085, null, config.noseLineThickness, noseLeftMesh);
1115
+ makeTube('', np.rightN, 0.0085, null, config.noseLineThickness, noseRightMesh);
1028
1116
  }
1029
1117
 
1030
1118
  /* ── per-frame face update ── */
@@ -1045,6 +1133,8 @@
1045
1133
  applyFeatureScales(_dispBuf);
1046
1134
  applyJawExtension(_dispBuf);
1047
1135
  applyMouthGrow(_dispBuf);
1136
+ applyUpperJawProtrude(_dispBuf);
1137
+ applyLowerJawProtrude(_dispBuf);
1048
1138
  applyMouthAnchors(_dispBuf);
1049
1139
  applyEyeAnchors(_dispBuf);
1050
1140
  // write final positions
@@ -1054,12 +1144,20 @@
1054
1144
  _posBuf[3*i+2] = baseVertices[i].z + _dispBuf[i].z;
1055
1145
  }
1056
1146
  mesh.updateVerticesData(BABYLON.VertexBuffer.PositionKind, _posBuf);
1057
- // depth fade colors
1147
+ // depth fade colors. raw t = (zMax - z) / zRange, then exponentiated by
1148
+ // depthFadeCurve. >1 darkens back faster (so silhouette edges actually
1149
+ // hit fadeColor in wire mode despite line interpolation lifting them);
1150
+ // <1 brightens back. Then scaled by depthFade.
1058
1151
  if (config.depthFade > 0.001) {
1059
- const zRange = (_zMax - _zMin) || 1, f = config.depthFade;
1152
+ const zRange = (_zMax - _zMin) || 1;
1153
+ const f = config.depthFade;
1154
+ const curve = config.depthFadeCurve > 0 ? config.depthFadeCurve : 1;
1060
1155
  for (let i = 0; i < baseVertices.length; i++) {
1061
1156
  const z = _posBuf[3*i + 2];
1062
- const t = Math.max(0, Math.min(1, (_zMax - z) / zRange)) * f;
1157
+ let t = (_zMax - z) / zRange;
1158
+ if (t < 0) t = 0; else if (t > 1) t = 1;
1159
+ if (curve !== 1) t = Math.pow(t, curve);
1160
+ t *= f;
1063
1161
  _colBuf[4*i ] = _baseRGB[0] * (1 - t) + _fadeRGB[0] * t;
1064
1162
  _colBuf[4*i+1] = _baseRGB[1] * (1 - t) + _fadeRGB[1] * t;
1065
1163
  _colBuf[4*i+2] = _baseRGB[2] * (1 - t) + _fadeRGB[2] * t;
@@ -1275,10 +1373,44 @@
1275
1373
  }
1276
1374
  }
1277
1375
 
1278
- /* ── color application ── */
1376
+ /* ── color application ──
1377
+ Per-feature mouth/eye/nose materials inherit lineColor when their
1378
+ per-feature override is null. So applyLineColor pushes into all three
1379
+ inheriting materials; the per-feature setters override that. */
1279
1380
  function applyLineColor(hex) {
1280
1381
  config.lineColor = hex;
1281
- minimalMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1382
+ const c = BABYLON.Color3.FromHexString(hex);
1383
+ if (!config.mouthColor) mouthMat.emissiveColor = c;
1384
+ if (!config.eyeColor) eyeMat.emissiveColor = c;
1385
+ if (!config.noseColor) noseMat.emissiveColor = c;
1386
+ }
1387
+ function applyMouthColor(hex) {
1388
+ config.mouthColor = hex;
1389
+ mouthMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1390
+ }
1391
+ function applyEyeColor(hex) {
1392
+ config.eyeColor = hex;
1393
+ eyeMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1394
+ }
1395
+ function applyNoseColor(hex) {
1396
+ config.noseColor = hex;
1397
+ noseMat.emissiveColor = BABYLON.Color3.FromHexString(hex || config.lineColor);
1398
+ }
1399
+ function applyBrowColor(hex) {
1400
+ config.browColor = hex;
1401
+ browMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1402
+ }
1403
+ /* per-feature visibility — independent of master `minimal` (which still
1404
+ hides the whole minimalGroup). Each feature toggles its own meshes. */
1405
+ function applyMinimalSubVisibility() {
1406
+ const setVis = (m, v) => { if (m) m.isVisible = v; };
1407
+ setVis(mouthUpperMesh, !!config.minimalMouth);
1408
+ setVis(mouthLowerMesh, !!config.minimalMouth);
1409
+ for (const em of eyeMeshes) { setVis(em.upper, !!config.minimalEyes); setVis(em.lower, !!config.minimalEyes); }
1410
+ for (const bm of browMeshes) setVis(bm.mesh, !!config.minimalBrows);
1411
+ setVis(noseBridgeMesh, !!config.minimalNose);
1412
+ setVis(noseLeftMesh, !!config.minimalNose);
1413
+ setVis(noseRightMesh, !!config.minimalNose);
1282
1414
  }
1283
1415
  function applyPupilColor(hex) {
1284
1416
  config.pupilColor = hex;
@@ -1300,10 +1432,6 @@
1300
1432
  config.irisColor = hex;
1301
1433
  if (irisMat) irisMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1302
1434
  }
1303
- function applyBrowColor(hex) {
1304
- config.browColor = hex;
1305
- browMat.emissiveColor = BABYLON.Color3.FromHexString(hex);
1306
- }
1307
1435
 
1308
1436
  /* ── views ── */
1309
1437
  const VIEWS = {
@@ -1335,8 +1463,12 @@
1335
1463
  applyFadeColor(config.fadeColor);
1336
1464
  applyLineColor(config.lineColor);
1337
1465
  applyBrowColor(config.browColor);
1466
+ if (config.mouthColor) applyMouthColor(config.mouthColor);
1467
+ if (config.eyeColor) applyEyeColor(config.eyeColor);
1468
+ if (config.noseColor) applyNoseColor(config.noseColor);
1338
1469
  applyPupilColor(config.pupilColor);
1339
1470
  applyIrisColor(config.irisColor);
1471
+ applyMinimalSubVisibility();
1340
1472
  applyGlow();
1341
1473
  setView(config.cameraView);
1342
1474
 
@@ -1373,6 +1505,15 @@
1373
1505
  if (rc.eyeHoleSize !== undefined && rc.eyeHoleSize !== config.eyeHoleSize) needRebuild = true;
1374
1506
  if (rc.eyeDepth !== undefined && rc.eyeDepth !== config.eyeDepth) needRebuild = true;
1375
1507
 
1508
+ // any per-feature thickness change requires rebuilding the affected
1509
+ // tubes (CreateTube radius is fixed at construction)
1510
+ const featureThicknessChanged =
1511
+ rc.lineThickness !== undefined ||
1512
+ rc.mouthLineThickness !== undefined ||
1513
+ rc.eyeLineThickness !== undefined ||
1514
+ rc.noseLineThickness !== undefined ||
1515
+ rc.browLineThickness !== undefined;
1516
+
1376
1517
  Object.assign(config, rc);
1377
1518
  if (p.lineColor) applyLineColor(p.lineColor);
1378
1519
  if (p.pupilColor) applyPupilColor(p.pupilColor);
@@ -1382,6 +1523,9 @@
1382
1523
  if (rc.pupilColor) applyPupilColor(rc.pupilColor);
1383
1524
  if (rc.irisColor) applyIrisColor(rc.irisColor);
1384
1525
  if (rc.browColor) applyBrowColor(rc.browColor);
1526
+ if (rc.mouthColor !== undefined) applyMouthColor(rc.mouthColor);
1527
+ if (rc.eyeColor !== undefined) applyEyeColor(rc.eyeColor);
1528
+ if (rc.noseColor !== undefined) applyNoseColor(rc.noseColor);
1385
1529
 
1386
1530
  if (needRebuild) {
1387
1531
  rebuildMesh();
@@ -1393,10 +1537,15 @@
1393
1537
  applyFaceFlip();
1394
1538
  applyMeshVisibility();
1395
1539
  applyMinimalVisibility();
1396
- if (rc.lineThickness !== undefined) rebuildMinimalLines();
1540
+ if (featureThicknessChanged) rebuildMinimalLines();
1397
1541
  if (rc.irisSize !== undefined || rc.pupils !== undefined) rebuildPupils();
1398
1542
  if (rc.lipVertAmp !== undefined || rc.lipPressForce !== undefined) identifyAnchorRings();
1399
1543
  }
1544
+ // per-feature visibility toggles always apply (cheap; no rebuild)
1545
+ if (rc.minimalMouth !== undefined || rc.minimalEyes !== undefined ||
1546
+ rc.minimalNose !== undefined || rc.minimalBrows !== undefined) {
1547
+ applyMinimalSubVisibility();
1548
+ }
1400
1549
  if (rc.glow !== undefined) applyGlow();
1401
1550
  // channel gains
1402
1551
  if (p.channelGains) {
@@ -1 +1 @@
1
- !function(e){"use strict";const o={viseme_sil:{range:[0,1],def:1},viseme_PP:{range:[0,1],def:0},viseme_FF:{range:[0,1],def:0},viseme_TH:{range:[0,1],def:0},viseme_DD:{range:[0,1],def:0},viseme_kk:{range:[0,1],def:0},viseme_CH:{range:[0,1],def:0},viseme_SS:{range:[0,1],def:0},viseme_nn:{range:[0,1],def:0},viseme_RR:{range:[0,1],def:0},viseme_aa:{range:[0,1],def:0},viseme_E:{range:[0,1],def:0},viseme_I:{range:[0,1],def:0},viseme_O:{range:[0,1],def:0},viseme_U:{range:[0,1],def:0},jawOpen:{range:[0,1],def:0},mouthSmile:{range:[-1,1],def:0},mouthPucker:{range:[0,1],def:0},eyeBlinkLeft:{range:[0,1],def:0},eyeBlinkRight:{range:[0,1],def:0},eyeLookH:{range:[-1,1],def:0},eyeLookV:{range:[-1,1],def:0},eyeSquint:{range:[0,1],def:0},browInnerUp:{range:[0,1],def:0},browOuterUp:{range:[-1,1],def:0},browDown:{range:[0,1],def:0},noseSneer:{range:[0,1],def:0},headRotateX:{range:[-1,1],def:0},headRotateY:{range:[-1,1],def:0},headRotateZ:{range:[-1,1],def:0}},t=Object.keys(o),n={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},r={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},i=Object.keys(r),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],a={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(n).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},l={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeHoleSize:1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,cameraView:"three-q"};function d(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function c(e,c){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const h=Object.assign({},u,c||{}),f=(e,o,t)=>new BABYLON.Vector3(e,o,t),m={};for(const e of Object.keys(l)){const o=l[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};t.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const g={},v={};for(const e of i)g[e]=0,v[e]=0;g.neutral=1,v.neutral=1;let B="neutral";const b=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),x=new BABYLON.Scene(b);x.clearColor=new BABYLON.Color4(0,0,0,1),x.skipPointerMovePicking=!0;const L=new BABYLON.GlowLayer("glow",x,{mainTextureFixedSize:1024,blurKernelSize:32});L.intensity=0;const C=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),x);C.minZ=.1,C.maxZ=100,C.lowerRadiusLimit=1.5,C.upperRadiusLimit=12,C.wheelDeltaPercentage=.01;const M=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}C.attachControl(e,!0);try{navigator.getGamepads=M}catch(e){}const O=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),x);O.intensity=.9,O.groundColor=new BABYLON.Color3(.1,.1,.14);const z=new BABYLON.TransformNode("faceRoot",x),R=new BABYLON.StandardMaterial("faceMat",x);R.diffuseColor=new BABYLON.Color3(.05,.05,.07),R.emissiveColor=new BABYLON.Color3(.012,.012,.02),R.specularColor=new BABYLON.Color3(.2,.22,.28),R.specularPower=48,R.backFaceCulling=!1,R.useVertexColor=!0;const A=new BABYLON.StandardMaterial("wireMat",x);A.emissiveColor=new BABYLON.Color3(1,1,1),A.disableLighting=!0,A.wireframe=!0,A.backFaceCulling=!1,A.alpha=1,A.useVertexColor=!0;const k=new BABYLON.StandardMaterial("minimalMat",x);k.emissiveColor=new BABYLON.Color3(1,1,1),k.disableLighting=!0,k.specularColor=new BABYLON.Color3(0,0,0);const S=new BABYLON.StandardMaterial("browMat",x);S.emissiveColor=new BABYLON.Color3(1,1,1),S.disableLighting=!0,S.specularColor=new BABYLON.Color3(0,0,0);const N=new BABYLON.TransformNode("minimal",x);function P(e,o){const t=2*(e-.5),n=2*(.5-o),r=.95*n,i=Math.max(0,1-r*r);let s=t*(.8*Math.sqrt(i)),a=1*n;n<-.4&&(a=1.55*(n+.4)-.4),n>.7&&(a=.7+.45*(n-.7));let l=.22*(1-t*t*.55-n*n*.55);l<-.05&&(l=-.05);const u=((t+.45)/.3)**2+((n-.3)/.18)**2,d=((t-.45)/.3)**2+((n-.3)/.18)**2,c=.045*h.eyeDepth;l-=c*Math.exp(-u),l-=c*Math.exp(-d);const m=(t/.7)**2+((n-.55)/.1)**2;l+=.045*Math.exp(-m);const p=(t/.18)**2+((n-.05)/.4)**2;l+=.22*Math.exp(-p);const w=(t/.55)**2+((n+.45)/.2)**2;l+=.06*Math.exp(-w);const y=((t+.55)/.3)**2+((n-.05)/.28)**2,_=((t-.55)/.3)**2+((n-.05)/.28)**2;return l+=.04*Math.exp(-y),l+=.04*Math.exp(-_),f(s,a,l)}N.parent=z;const Y=P(.5,.69);function j(e,o,t){const n=Y.x,r=Y.y,i=Y.z,s=.27*(1+.4*t.width)*(1-.4*t.round),a=h.lipVertAmp,l=h.lipPressForce,u=.16*t.open*a,d=.012*t.lipPress*a*l,c=.09*t.jaw*a,m=.05*t.smile,p=.07*t.round,w=.007*(1-.55*t.lipPress),y=.022*(1-.55*t.lipPress);let _;if(o){const e=r+u/2-d+.4*m;_=[[-1,r+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,r+m,.5*-p]]}else{const e=r-u/2+d-c;_=[[-1,r+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,r+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let g=0;for(;g<_.length-1&&e>_[g+1][0];)g++;g=Math.min(g,_.length-2);const v=(e-_[g][0])/(_[g+1][0]-_[g][0]),B=_[g][1]*(1-v)+_[g+1][1]*v,b=_[g][2]*(1-v)+_[g+1][2]*v;return f(n+e*s,B,i+b)}function H(e,o,t,n,r){const i=(e+1)/2*Math.PI,s=t.center.x+Math.cos(Math.PI-i)*t.hw,a=.012*r,l=(t.center.y+(o?1:-1)*Math.sin(i)*t.hh)*(1-n)+t.center.y*n+(o?-a:.5*a),u=t.center.z+.018+.012*Math.sin(i);return f(s,l,u)}function U(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const t of Object.keys(n)){const r=p["viseme_"+t]||0;if(r<=0)continue;e+=r;const i=n[t];o.open+=i.open*r,o.width+=i.width*r,o.round+=i.round*r,o.smile+=i.smile*r,o.lipPress+=i.lipPress*r,o.jaw+=i.jaw*r}if(e>1){const t=1/e;o.open*=t,o.width*=t,o.round*=t,o.smile*=t,o.lipPress*=t,o.jaw*=t}o.smile+=p.mouthSmile;const t=p.mouthPucker;return o.round+=.7*t,o.width+=.4*-t,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let V=null,D=[],T=[],F=[],I=[],q=null,E=null,G=null,Z=null,K=0,X=0,W=[1,1,1],J=[0,0,0],Q=!1,$=[],ee=[];const oe={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function te(){V&&(V.dispose(),V=null);const e=h.meshCols,o=h.meshRows;D=[],T=[],F=[];for(let t=0;t<o;t++)for(let n=0;n<e;n++){const r=n/(e-1),i=t/(o-1);T.push({u:r,v:i}),D.push(P(r,i))}const t=e=>{if(!h.fragment)return!0;const o=2*(T[e].u-.5),t=2*(.5-T[e].v);return o*o*1.2+t*t*.95<1},n=(e,o,n)=>{((e,o,n)=>{if(!t(e)||!t(o)||!t(n))return!1;if(h.mouthHole){const t=.5,r=.69,i=.18*h.mouthHoleSize,s=.075*h.mouthHoleSize,a=((T[e].u+T[o].u+T[n].u)/3-t)/i,l=((T[e].v+T[o].v+T[n].v)/3-r)/s;if(a*a+l*l<1)return!1}if(h.eyeHoles){const t=.105*h.eyeHoleSize,r=.075*h.eyeHoleSize,i=(T[e].u+T[o].u+T[n].u)/3,s=(T[e].v+T[o].v+T[n].v)/3;if(((i-.3)/t)**2+((s-.4)/r)**2<1||((i-.7)/t)**2+((s-.4)/r)**2<1)return!1}return!0})(e,o,n)&&F.push(e,o,n)};for(let t=0;t<o-1;t++)for(let o=0;o<e-1;o++){const r=t*e+o,i=t*e+(o+1),s=(t+1)*e+o,a=(t+1)*e+(o+1);(t+o)%2==0?(n(r,i,a),n(r,a,s)):(n(r,i,s),n(i,a,s))}I=function(e,o){const t=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const n=e[o],r=e[o+1],i=e[o+2];t[n].add(r),t[n].add(i),t[r].add(n),t[r].add(i),t[i].add(n),t[i].add(r)}return t.map(e=>Array.from(e))}(F,D.length),V=new BABYLON.Mesh("face",x),V.parent=z;const r=D.length;E=new Float32Array(3*r),G=new Float32Array(3*r),Z=new Float32Array(4*r),q=new Array(r),K=1/0,X=-1/0;for(let e=0;e<r;e++)E[3*e]=D[e].x,E[3*e+1]=D[e].y,E[3*e+2]=D[e].z,D[e].z<K&&(K=D[e].z),D[e].z>X&&(X=D[e].z),q[e]=f(0,0,0),Z[4*e]=1,Z[4*e+1]=1,Z[4*e+2]=1,Z[4*e+3]=1;BABYLON.VertexData.ComputeNormals(E,F,G);const i=new BABYLON.VertexData;i.positions=Array.from(E),i.indices=F,i.normals=Array.from(G),i.colors=Array.from(Z),i.applyToMesh(V,!0),ue(),se(),ae(),ne(),Q=!0}function ne(){$=[],ee=[];const e=.18*h.mouthHoleSize,o=.075*h.mouthHoleSize;for(let t=0;t<T.length;t++){const n=(T[t].u-.5)/e,r=(T[t].v-.69)/o,i=n*n+r*r;if(i<4){const e=T[t].v<.69,o=Math.max(-1,Math.min(1,n));let r=i<=1?i:(4-i)/3;r=Math.max(0,Math.min(1,r)),$.push({idx:t,isUpper:e,xRel:o,weight:r,baselineTarget:j(o,e,oe)})}}const t=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of t)for(let o=0;o<T.length;o++){const t=(T[o].u-e.cu)/e.ru,n=(T[o].v-e.cv)/e.rv,r=t*t+n*n;if(r<4){const n=T[o].v<e.cv,i=Math.max(-1,Math.min(1,t));let s=r<=1?r:(4-r)/3;s=Math.max(0,Math.min(1,s));const a=P(e.cu,e.cv);ee.push({idx:o,side:e.side,isUpper:n,xRel:i,weight:s,eyeDef:{center:a,hw:e.hw,hh:e.hh},baselineTarget:H(i,n,{center:a,hw:e.hw,hh:e.hh},0,0)})}}}function re(e,o,t,n){if(Math.abs(t)<.001)return;const r=o.uv[0],i=o.uv[1],s=o.radius*n,a=s*s,l=o.dir.x*t,u=o.dir.y*t,d=o.dir.z*t;for(let o=0;o<T.length;o++){const t=T[o].u-r,n=T[o].v-i,s=t*t+n*n;if(s>4*a)continue;const c=Math.exp(-s/a);e[o].x+=l*c,e[o].y+=u*c,e[o].z+=d*c}}const ie=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return h.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return h.scaleMouth}}];function se(){z&&(z.rotation.y=h.flipFace?Math.PI:0)}function ae(){V&&(V.isVisible=!!h.meshVisible)}function le(){N&&N.getChildMeshes().forEach(e=>e.isVisible=!!h.minimal)}function ue(){if(!V)return;V._edgesRenderer&&V.disableEdgesRendering();const e=h.lineThickness;switch(h.mode){case"wire":V.material=A,A.wireframe=!0,A.alpha=1;break;case"edges":V.material=R,R.alpha=1,R.wireframe=!1,V.enableEdgesRendering(.9999),V.edgesWidth=4*e,V.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1);break;case"shaded":V.material=R,R.alpha=1,R.wireframe=!1}}let de=null,ce=null,he=null,fe=null,me=null,pe=null;function we(){if(ce&&(ce.dispose(),ce=null),he&&(he.dispose(),he=null),me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),!h.pupils)return;de||(de=new BABYLON.StandardMaterial("pupilMat",x),de.emissiveColor=BABYLON.Color3.FromHexString(h.pupilColor),de.disableLighting=!0,de.backFaceCulling=!1),fe||(fe=new BABYLON.StandardMaterial("irisMat",x),fe.emissiveColor=BABYLON.Color3.FromHexString(h.irisColor),fe.disableLighting=!0,fe.backFaceCulling=!1);const e=.035*h.irisSize;me=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},x),pe=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},x),me.material=pe.material=fe,me.parent=pe.parent=z,ce=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},x),he=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},x),ce.material=he.material=de,ce.parent=he.parent=z}function ye(e,o){const t=P(e,o);if(!h.overlayTracksMesh)return t;const n=function(e,o){if(!q)return f(0,0,0);const t=.0036;let n=0,r=0,i=0,s=0;for(let a=0;a<T.length;a++){const l=T[a].u-e,u=T[a].v-o,d=l*l+u*u;if(d<t){const e=1-Math.sqrt(d/t);n+=e,r+=q[a].x*e,i+=q[a].y*e,s+=q[a].z*e}}return 0===n?f(0,0,0):f(r/n,i/n,s/n)}(e,o);return f(t.x+n.x,t.y+n.y,t.z+n.z)}function _e(e,o=18){const t=[],n=e.length,r=o=>e[Math.max(0,Math.min(n-1,o))];for(let e=0;e<n-1;e++){const n=r(e-1),i=r(e),s=r(e+1),a=r(e+2);for(let e=0;e<o;e++){const r=e/o,l=r*r,u=r*l,d=.5*(2*i.x+(-n.x+s.x)*r+(2*n.x-5*i.x+4*s.x-a.x)*l+(-n.x+3*i.x-3*s.x+a.x)*u),c=.5*(2*i.y+(-n.y+s.y)*r+(2*n.y-5*i.y+4*s.y-a.y)*l+(-n.y+3*i.y-3*s.y+a.y)*u),h=.5*(2*i.z+(-n.z+s.z)*r+(2*n.z-5*i.z+4*s.z-a.z)*l+(-n.z+3*i.z-3*s.z+a.z)*u);t.push(f(d,c,h))}}return t.push(e[n-1]),t}function ge(e,o,t,n){const r={path:o,radius:n?t:t*h.lineThickness,tessellation:6,updatable:!0};n&&(r.instance=n);const i=BABYLON.MeshBuilder.CreateTube(e,r,x);return n||(i.material=k,i.parent=N),i}let ve=null,Be=null;function be(){const e=U();return{upper:_e([-1,-.45,0,.45,1].map(o=>j(o,!0,e)),18),lower:_e([-1,-.5,0,.5,1].map(o=>j(o,!1,e)),18)}}const xe=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let Le=[];function Ce(e,o){const t="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,n=p.eyeSquint,r=ye(e.uv[0],e.uv[1]),i=[],s=.012*n;for(let n=0;n<=12;n++){const a=n/12*Math.PI,l=r.x+Math.cos(Math.PI-a)*e.hw,u=(r.y+(o?1:-1)*Math.sin(a)*e.hh)*(1-t)+r.y*t+(o?-s:.5*s),d=r.z+.018+.012*Math.sin(a);i.push(f(l,u,d))}return i}const Me=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Oe=[];function ze(e){const o=ye(e.uv[0],e.uv[1]),t="L"===e.side?-1:1,n=.085*p.browInnerUp-.05*p.browDown,r=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,i=o.x+-.1*t,s=o.x,a=o.x+.1*t,l=o.y+n,u=o.y+.5*(n+r)+.005,d=o.y+r-.005,c=o.z+.018;return _e([f(i,l,c),f(s,u,c+.01),f(a,d,c)],12)}let Re=null,Ae=null,ke=null;function Se(){const e=.025*p.noseSneer,o=ye(.5,.4),t=ye(.5,.55),n=_e([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+t.y),.5*(o.z+t.z)+.05),f(t.x,t.y+.03,t.z+.05)],14),r=t.y+.01;return{bridge:n,leftN:_e([f(t.x,r,t.z+.05),f(t.x-.06-e,r-.03,t.z+.02),f(t.x-.04,r-.05,t.z+.005),f(t.x-.01,r-.02,t.z+.03)],10),rightN:_e([f(t.x,r,t.z+.05),f(t.x+.06+e,r-.03,t.z+.02),f(t.x+.04,r-.05,t.z+.005),f(t.x+.01,r-.02,t.z+.03)],10)}}function Ne(){ve&&(ve.dispose(),ve=null),Be&&(Be.dispose(),Be=null);for(const e of Le)e.upper.dispose(),e.lower.dispose();Le=[];for(const e of Oe)e.mesh.dispose();Oe=[],Re&&(Re.dispose(),Re=null),Ae&&(Ae.dispose(),Ae=null),ke&&(ke.dispose(),ke=null);const{upper:e,lower:o}=be();ve=ge("mouth_u",e,.01),Be=ge("mouth_l",o,.01);for(const e of xe){const o=ge("eye_"+e.side+"_u",Ce(e,!0),.0085),t=ge("eye_"+e.side+"_l",Ce(e,!1),.0085);Le.push({eye:e,upper:o,lower:t})}for(const e of Me){const o=ge("brow_"+e.side,ze(e),.011);o.material=S,Oe.push({brow:e,mesh:o})}const t=Se();Re=ge("nose_b",t.bridge,.009),Ae=ge("nose_l",t.leftN,.0085),ke=ge("nose_r",t.rightN,.0085),le()}const Pe={};function Ye(){if(V){for(let e=0;e<t.length;e++){const o=t[e];Pe[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<q.length;e++)q[e].x=q[e].y=q[e].z=0;!function(e){const o=h.spread,t=U();re(e,m.mouth_jaw_drop,t.jaw,o),re(e,m.mouth_open_lower,t.open,o),re(e,m.mouth_open_upper,.4*t.open,o);const n=t.smile;n>0?(re(e,m.mouth_smile_L,n,o),re(e,m.mouth_smile_R,n,o)):n<0&&(re(e,m.mouth_frown_L,-n,o),re(e,m.mouth_frown_R,-n,o)),re(e,m.mouth_round_L,t.round,o),re(e,m.mouth_round_R,t.round,o),re(e,m.mouth_round_top,t.round,o),re(e,m.mouth_round_bot,t.round,o),re(e,m.mouth_press_top,t.lipPress,o),re(e,m.mouth_press_bot,t.lipPress,o),t.width>0&&(re(e,m.mouth_width_L,t.width,o),re(e,m.mouth_width_R,t.width,o)),re(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),re(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),re(e,m.eye_blink_R_up,p.eyeBlinkRight,o),re(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),re(e,m.eye_squint_L,p.eyeSquint,o),re(e,m.eye_squint_R,p.eyeSquint,o),re(e,m.brow_inner_L,p.browInnerUp,o),re(e,m.brow_inner_R,p.browInnerUp,o),p.browOuterUp>=0?(re(e,m.brow_outer_L,p.browOuterUp,o),re(e,m.brow_outer_R,p.browOuterUp,o)):(re(e,m.brow_down_L,.6*-p.browOuterUp,o),re(e,m.brow_down_R,.6*-p.browOuterUp,o)),re(e,m.brow_down_L,p.browDown,o),re(e,m.brow_down_R,p.browDown,o),re(e,m.nose_sneer_L,p.noseSneer,o),re(e,m.nose_sneer_R,p.noseSneer,o)}(q),h.reactivity>0&&function(e,o){if(o<=0)return;const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const t=I[r];if(0===t.length){n[r]=f(e[r].x,e[r].y,e[r].z);continue}let i=0,s=0,a=0;for(const o of t)i+=e[o].x,s+=e[o].y,a+=e[o].z;i/=t.length,s/=t.length,a/=t.length,n[r]=f(e[r].x*(1-o)+i*o,e[r].y*(1-o)+s*o,e[r].z*(1-o)+a*o)}for(let o=0;o<t;o++)e[o].x=n[o].x,e[o].y=n[o].y,e[o].z=n[o].z}(q,h.reactivity),function(e){for(const o of ie){const t=o.scale;if(Math.abs(t-1)<.001)continue;const n=P(o.uv[0],o.uv[1]),r=o.radiusUV*o.radiusUV,i=4*r;for(let s=0;s<T.length;s++){const a=T[s].u-o.uv[0],l=T[s].v-o.uv[1],u=a*a+l*l;if(u>i)continue;const d=Math.exp(-u/r),c=D[s].x-n.x,h=D[s].y-n.y,f=D[s].z-n.z,m=(t-1)*d;e[s].x+=c*m,e[s].y+=h*m,e[s].z+=f*m}}}(q),function(e){const o=h.jawExtend;if(o<.001)return;const t=p.jawOpen||0;if(t<.001)return;const n=t*o*.1;for(let o=0;o<T.length;o++){const t=T[o].v;if(t<.55)continue;const r=Math.min(1,(t-.55)/.45);e[o].z+=n*r}}(q),function(e){const o=h.mouthGrow;if(o<.001)return;const t=U().open;if(t<.001)return;const n=t*o,r=.0625;for(let o=0;o<T.length;o++){const t=T[o].u-.5,i=T[o].v-.69,s=t*t+i*i;if(s>r)continue;const a=1-Math.sqrt(s/r),l=D[o];e[o].x+=(l.x-Y.x)*n*a*.4,e[o].y+=(l.y-Y.y)*n*a*.4,e[o].z+=n*a*.05}}(q),function(e){if(!h.mouthAnchor)return;const o=U();for(const t of $){const n=j(t.xRel,t.isUpper,o),r=n.x-t.baselineTarget.x,i=n.y-t.baselineTarget.y,s=n.z-t.baselineTarget.z,a=t.weight;e[t.idx].x=e[t.idx].x*(1-a)+r*a,e[t.idx].y=e[t.idx].y*(1-a)+i*a,e[t.idx].z=e[t.idx].z*(1-a)+s*a}}(q),function(e){if(!h.eyeAnchor)return;const o=p.eyeBlinkLeft,t=p.eyeBlinkRight,n=p.eyeSquint;for(const r of ee){const i="L"===r.side?o:t,s=H(r.xRel,r.isUpper,r.eyeDef,i,n),a=s.x-r.baselineTarget.x,l=s.y-r.baselineTarget.y,u=s.z-r.baselineTarget.z,d=r.weight;e[r.idx].x=e[r.idx].x*(1-d)+a*d,e[r.idx].y=e[r.idx].y*(1-d)+l*d,e[r.idx].z=e[r.idx].z*(1-d)+u*d}}(q);for(let e=0;e<D.length;e++)E[3*e]=D[e].x+q[e].x,E[3*e+1]=D[e].y+q[e].y,E[3*e+2]=D[e].z+q[e].z;if(V.updateVerticesData(BABYLON.VertexBuffer.PositionKind,E),h.depthFade>.001){const e=X-K||1,o=h.depthFade;for(let t=0;t<D.length;t++){const n=E[3*t+2],r=Math.max(0,Math.min(1,(X-n)/e))*o;Z[4*t]=W[0]*(1-r)+J[0]*r,Z[4*t+1]=W[1]*(1-r)+J[1]*r,Z[4*t+2]=W[2]*(1-r)+J[2]*r,Z[4*t+3]=1}V.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z)}else if(Q){for(let e=0;e<D.length;e++)Z[4*e]=W[0],Z[4*e+1]=W[1],Z[4*e+2]=W[2],Z[4*e+3]=1;V.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z),Q=!1}"edges"!==h.mode&&"shaded"!==h.mode||(BABYLON.VertexData.ComputeNormals(E,F,G),V.updateVerticesData(BABYLON.VertexBuffer.NormalKind,G)),function(){if(!ce||!he)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,t=P(.3,.4),n=P(.7,.4);me&&pe&&(me.position.set(t.x+.6*e,t.y+.6*o,t.z+.045),pe.position.set(n.x+.6*e,n.y+.6*o,n.z+.045)),ce.position.set(t.x+e,t.y+o,t.z+.05),he.position.set(n.x+e,n.y+o,n.z+.05);const r=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);ce.isVisible=he.isVisible=r<.85,me&&pe&&(me.isVisible=pe.isVisible=r<.85)}(),h.minimal&&function(){if(!ve)return;const e=be();ge("",e.upper,.01,ve),ge("",e.lower,.01,Be);for(const e of Le)ge("",Ce(e.eye,!0),.0085,e.upper),ge("",Ce(e.eye,!1),.0085,e.lower);for(const e of Oe)ge("",ze(e.brow),.011,e.mesh);const o=Se();ge("",o.bridge,.009,Re),ge("",o.leftN,.0085,Ae),ge("",o.rightN,.0085,ke)}(),z.rotation.x=.35*p.headRotateX,z.rotation.y=.5*p.headRotateY,z.rotation.z=.3*p.headRotateZ;for(let e=0;e<t.length;e++)p[t[e]]=Pe[t[e]]}}let je=1.5+3*Math.random(),He=0,Ue=.8+2*Math.random(),Ve=0,De=0,Te=0,Fe=0;let Ie=null,qe=null,Ee=null,Ge=null,Ze=0,Ke=0,Xe=!1,We=null;function Je(){Ie||(Ie=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Ie.state&&Ie.resume()}function Qe(){if(Ee){try{Ee.stop()}catch(e){}try{Ee.disconnect()}catch(e){}Ee=null}if(Ge){try{Ge.disconnect()}catch(e){}Ge=null}Xe=!1}function $e(){return Ie&&qe?Xe?Ie.currentTime-Ze:Ke||0:0}function eo(e,o){if(!We)return 0;const t=Ie.sampleRate/2/We.length,n=Math.max(0,Math.floor(e/t)),r=Math.min(We.length-1,Math.ceil(o/t));let i=0,s=0;for(let e=n;e<=r;e++)i+=We[e],s++;return s?i/s/255:0}function oo(e){h.lineColor=e,k.emissiveColor=BABYLON.Color3.FromHexString(e)}function to(e){h.pupilColor=e,de&&(de.emissiveColor=BABYLON.Color3.FromHexString(e))}function no(e){h.baseColor=e,W=d(e),Q=!0,A.emissiveColor=new BABYLON.Color3(W[0],W[1],W[2]),V&&V._edgesRenderer&&(V.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1))}function ro(e){h.fadeColor=e,J=d(e),Q=!0}function io(e){h.irisColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function so(e){h.browColor=e,S.emissiveColor=BABYLON.Color3.FromHexString(e)}const ao={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let lo=!1;function uo(e){if("orbit"===e)return void(lo=!0);lo=!1;const o=ao[e];o&&(C.alpha=o.alpha,C.beta=o.beta,C.radius=o.radius)}function co(){L.intensity=h.glow?.85:0}te(),we(),Ne(),no(h.baseColor),ro(h.fadeColor),oo(h.lineColor),so(h.browColor),to(h.pupilColor),io(h.irisColor),co(),uo(h.cameraView);let ho=performance.now(),fo=!1;b.runRenderLoop(()=>{if(fo)return;const e=performance.now(),o=Math.min(.05,(e-ho)/1e3);ho=e,function(e){He+=e,He>je&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=v.sleep>.5?1:0,w.eyeBlinkRight=v.sleep>.5?1:0},110),He=0,je=1.5+3.5*Math.random()),Ve+=e,Ve>Ue&&!y.eyeLookH&&(De=.6*(Math.random()-.5),Te=.4*(Math.random()-.5),Ve=0,Ue=.7+2.5*Math.random()),w.eyeLookH=De,w.eyeLookV=Te,Fe+=e,w.headRotateX=.04*Math.sin(.27*Fe),w.headRotateY=.06*Math.sin(.19*Fe),w.headRotateZ=.03*Math.sin(.11*Fe)}(o),Xe&&function(){if(!Ge)return;Ge.getByteFrequencyData(We);const e=eo(200,700),o=eo(700,2e3),t=eo(2e3,4e3),r=eo(4e3,8e3),i=eo(1500,5e3),s=Math.max(e,o,t,r);if(s<.08){for(const e of Object.keys(n))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(n))"sil"!==e&&(w["viseme_"+e]=0);r>.35&&r>.8*o&&(w.viseme_SS=Math.min(1,1.3*r),w.viseme_FF=Math.min(.6,1.2*i)),e>o&&e>.18?t>.25?w.viseme_aa=Math.min(1,1.2*e):(w.viseme_O=Math.min(1,1.2*e),w.viseme_U=Math.min(.7,.9*e)):o>.2&&(t>.6*o?(w.viseme_I=Math.min(1,1.4*t),w.viseme_E=Math.min(.7,1.1*o)):(w.viseme_E=Math.min(1,1.3*o),w.viseme_aa=Math.min(.4,.9*e)))}(),function(e){const o=Math.max(.05,h.moodTransitionTime)/4,t=1-Math.pow(.5,e/o);for(const e of i)v[e]+=(g[e]-v[e])*t;for(const e of s){let o=0;for(const t of i)o+=(r[t][e]||0)*v[t];w[e]=o}}(o),function(e){for(const o of t){if(y[o]){p[o]=w[o];continue}const t=a[o]||a.default,n=1-Math.exp(-t*e*30);p[o]=p[o]+(w[o]-p[o])*n}}(o),Ye(),lo&&(C.alpha+=.3*o),x.render()});const mo=()=>b.resize();function po(e){if(!e)return;const o=e.renderConfig||{};let n=!1;if(void 0!==o.meshCols&&o.meshCols!==h.meshCols&&(n=!0),void 0!==o.meshRows&&o.meshRows!==h.meshRows&&(n=!0),void 0!==o.fragment&&o.fragment!==h.fragment&&(n=!0),void 0!==o.mouthHole&&o.mouthHole!==h.mouthHole&&(n=!0),void 0!==o.eyeHoles&&o.eyeHoles!==h.eyeHoles&&(n=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==h.mouthHoleSize&&(n=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==h.eyeHoleSize&&(n=!0),void 0!==o.eyeDepth&&o.eyeDepth!==h.eyeDepth&&(n=!0),Object.assign(h,o),e.lineColor&&oo(e.lineColor),e.pupilColor&&to(e.pupilColor),o.baseColor&&no(o.baseColor),o.fadeColor&&ro(o.fadeColor),o.lineColor&&oo(o.lineColor),o.pupilColor&&to(o.pupilColor),o.irisColor&&io(o.irisColor),o.browColor&&so(o.browColor),n?(te(),Ne(),we()):(ue(),se(),ae(),le(),void 0!==o.lineThickness&&Ne(),void 0===o.irisSize&&void 0===o.pupils||we(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||ne()),void 0!==o.glow&&co(),e.channelGains)for(const o of t)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&r[e.activeMood]){B=e.activeMood;for(const e of i)g[e]=e===B?1:0}}return window.addEventListener("resize",mo),{loadAudio:async function(e){Je();const o=await e.arrayBuffer();qe=await Ie.decodeAudioData(o.slice(0)),Ke=0},play(e){qe&&function(e){qe&&(Je(),Ee=Ie.createBufferSource(),Ee.buffer=qe,Ee.loop=!!h.loopAudio,Ge=Ie.createAnalyser(),Ge.fftSize=1024,Ge.smoothingTimeConstant=.4,We=new Uint8Array(Ge.frequencyBinCount),Ee.connect(Ge),Ge.connect(Ie.destination),Ze=Ie.currentTime-(e||0),Ee.start(0,e||0),Ee.onended=()=>{if(!h.loopAudio){Xe=!1;for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Xe=!0)}(void 0!==e?e:Ke)},pause(){Xe&&(Ke=$e(),Qe())},stop(){Ke=0,Qe();for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){h.loopAudio=!!e,Ee&&(Ee.loop=!!e)},setMood(e){if(r[e]){B=e;for(const o of i)g[o]=o===e?1:0}},setChannel(e,t){if(!o[e])return;const n=o[e].range,r=Math.max(n[0],Math.min(n[1],t));w[e]=r,p[e]=r,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:uo,loadPreset:po,setRenderConfig(e){po({renderConfig:e})},getRenderConfig:()=>Object.assign({},h),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,t){o[e]&&(_[e]=t)},getChannelNames:()=>t.slice(),getMoodNames:()=>i.slice(),isPlaying:()=>Xe,getDuration:()=>qe?qe.duration:0,getPosition:()=>$e(),getActiveMood:()=>B,dispose(){fo=!0;try{Qe()}catch(e){}if(Ie){try{Ie.close()}catch(e){}Ie=null}window.removeEventListener("resize",mo);try{b.stopRenderLoop()}catch(e){}try{x.dispose()}catch(e){}try{b.dispose()}catch(e){}}}}e.createWireface=c,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:c})}("undefined"!=typeof window?window:globalThis);
1
+ !function(e){"use strict";const o={viseme_sil:{range:[0,1],def:1},viseme_PP:{range:[0,1],def:0},viseme_FF:{range:[0,1],def:0},viseme_TH:{range:[0,1],def:0},viseme_DD:{range:[0,1],def:0},viseme_kk:{range:[0,1],def:0},viseme_CH:{range:[0,1],def:0},viseme_SS:{range:[0,1],def:0},viseme_nn:{range:[0,1],def:0},viseme_RR:{range:[0,1],def:0},viseme_aa:{range:[0,1],def:0},viseme_E:{range:[0,1],def:0},viseme_I:{range:[0,1],def:0},viseme_O:{range:[0,1],def:0},viseme_U:{range:[0,1],def:0},jawOpen:{range:[0,1],def:0},mouthSmile:{range:[-1,1],def:0},mouthPucker:{range:[0,1],def:0},eyeBlinkLeft:{range:[0,1],def:0},eyeBlinkRight:{range:[0,1],def:0},eyeLookH:{range:[-1,1],def:0},eyeLookV:{range:[-1,1],def:0},eyeSquint:{range:[0,1],def:0},browInnerUp:{range:[0,1],def:0},browOuterUp:{range:[-1,1],def:0},browDown:{range:[0,1],def:0},noseSneer:{range:[0,1],def:0},headRotateX:{range:[-1,1],def:0},headRotateY:{range:[-1,1],def:0},headRotateZ:{range:[-1,1],def:0}},n=Object.keys(o),t={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},i={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},r=Object.keys(i),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],l={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(t).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},a={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeHoleSize:1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",mouthColor:null,eyeColor:null,noseColor:null,minimalMouth:!0,minimalEyes:!0,minimalNose:!0,minimalBrows:!0,mouthLineThickness:1,eyeLineThickness:1,noseLineThickness:1,browLineThickness:1,baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,depthFadeCurve:1,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,upperJawProtrude:0,lowerJawProtrude:0,cameraView:"three-q"};function c(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function d(e,d){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const h=Object.assign({},u,d||{}),f=(e,o,n)=>new BABYLON.Vector3(e,o,n),m={};for(const e of Object.keys(a)){const o=a[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};n.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const v={},g={};for(const e of r)v[e]=0,g[e]=0;v.neutral=1,g.neutral=1;let b="neutral";const B=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),C=new BABYLON.Scene(B);C.useRightHandedSystem=!0,C.clearColor=new BABYLON.Color4(0,0,0,1),C.skipPointerMovePicking=!0;const L=new BABYLON.GlowLayer("glow",C,{mainTextureFixedSize:1024,blurKernelSize:32});L.intensity=0;const x=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),C);x.minZ=.1,x.maxZ=100,x.lowerRadiusLimit=1.5,x.upperRadiusLimit=12,x.wheelDeltaPercentage=.01;const M=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}x.attachControl(e,!0);try{navigator.getGamepads=M}catch(e){}const k=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),C);k.intensity=.9,k.groundColor=new BABYLON.Color3(.1,.1,.14);const O=new BABYLON.TransformNode("faceRoot",C),z=new BABYLON.StandardMaterial("faceMat",C);z.diffuseColor=new BABYLON.Color3(.05,.05,.07),z.emissiveColor=new BABYLON.Color3(.012,.012,.02),z.specularColor=new BABYLON.Color3(.2,.22,.28),z.specularPower=48,z.backFaceCulling=!1,z.useVertexColor=!0;const R=new BABYLON.StandardMaterial("wireMat",C);function A(e){const o=new BABYLON.StandardMaterial(e,C);return o.emissiveColor=new BABYLON.Color3(1,1,1),o.disableLighting=!0,o.specularColor=new BABYLON.Color3(0,0,0),o}R.emissiveColor=new BABYLON.Color3(1,1,1),R.disableLighting=!0,R.wireframe=!0,R.backFaceCulling=!1,R.alpha=1,R.useVertexColor=!0;const N=A("mouthMat"),S=A("eyeMat"),P=A("noseMat"),T=A("browMat"),Y=new BABYLON.TransformNode("minimal",C);function j(e,o){const n=2*(e-.5),t=2*(.5-o),i=.95*t,r=Math.max(0,1-i*i);let s=n*(.8*Math.sqrt(r)),l=1*t;t<-.4&&(l=1.55*(t+.4)-.4),t>.7&&(l=.7+.45*(t-.7));let a=.22*(1-n*n*.55-t*t*.55);a<-.05&&(a=-.05);const u=((n+.45)/.3)**2+((t-.2)/.18)**2,c=((n-.45)/.3)**2+((t-.2)/.18)**2,d=.045*h.eyeDepth;a-=d*Math.exp(-u),a-=d*Math.exp(-c);const m=(n/.7)**2+((t-.55)/.1)**2;a+=.045*Math.exp(-m);const p=(n/.18)**2+((t-.05)/.4)**2;a+=.22*Math.exp(-p);const w=(n/.55)**2+((t+.45)/.2)**2;a+=.06*Math.exp(-w);const y=((n+.55)/.3)**2+((t-.05)/.28)**2,_=((n-.55)/.3)**2+((t-.05)/.28)**2;return a+=.04*Math.exp(-y),a+=.04*Math.exp(-_),f(s,l,a)}Y.parent=O;const H=j(.5,.69);function V(e,o,n){const t=H.x,i=H.y,r=H.z,s=.27*(1+.4*n.width)*(1-.4*n.round),l=h.lipVertAmp,a=h.lipPressForce,u=.16*n.open*l,c=.012*n.lipPress*l*a,d=.09*n.jaw*l,m=.05*n.smile,p=.07*n.round,w=.007*(1-.55*n.lipPress),y=.022*(1-.55*n.lipPress);let _;if(o){const e=i+u/2-c+.4*m;_=[[-1,i+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,i+m,.5*-p]]}else{const e=i-u/2+c-d;_=[[-1,i+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,i+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let v=0;for(;v<_.length-1&&e>_[v+1][0];)v++;v=Math.min(v,_.length-2);const g=(e-_[v][0])/(_[v+1][0]-_[v][0]),b=_[v][1]*(1-g)+_[v+1][1]*g,B=_[v][2]*(1-g)+_[v+1][2]*g;return f(t+e*s,b,r+B)}function U(e,o,n,t,i){const r=(e+1)/2*Math.PI,s=n.center.x+Math.cos(Math.PI-r)*n.hw,l=.012*i,a=(n.center.y+(o?1:-1)*Math.sin(r)*n.hh)*(1-t)+n.center.y*t+(o?-l:.5*l),u=n.center.z+.018+.012*Math.sin(r);return f(s,a,u)}function D(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const n of Object.keys(t)){const i=p["viseme_"+n]||0;if(i<=0)continue;e+=i;const r=t[n];o.open+=r.open*i,o.width+=r.width*i,o.round+=r.round*i,o.smile+=r.smile*i,o.lipPress+=r.lipPress*i,o.jaw+=r.jaw*i}if(e>1){const n=1/e;o.open*=n,o.width*=n,o.round*=n,o.smile*=n,o.lipPress*=n,o.jaw*=n}o.smile+=p.mouthSmile;const n=p.mouthPucker;return o.round+=.7*n,o.width+=.4*-n,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let F=null,I=[],E=[],q=[],G=[],Z=null,K=null,J=null,X=null,W=0,Q=0,$=[1,1,1],ee=[0,0,0],oe=!1,ne=[],te=[];const ie={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function re(){F&&(F.dispose(),F=null);const e=h.meshCols,o=h.meshRows;I=[],E=[],q=[];for(let n=0;n<o;n++)for(let t=0;t<e;t++){const i=t/(e-1),r=n/(o-1);E.push({u:i,v:r}),I.push(j(i,r))}const n=e=>{if(!h.fragment)return!0;const o=2*(E[e].u-.5),n=2*(.5-E[e].v);return o*o*1.2+n*n*.95<1},t=(e,o,t)=>{((e,o,t)=>{if(!n(e)||!n(o)||!n(t))return!1;if(h.mouthHole){const n=.5,i=.69,r=.18*h.mouthHoleSize,s=.075*h.mouthHoleSize,l=((E[e].u+E[o].u+E[t].u)/3-n)/r,a=((E[e].v+E[o].v+E[t].v)/3-i)/s;if(l*l+a*a<1)return!1}if(h.eyeHoles){const n=.105*h.eyeHoleSize,i=.075*h.eyeHoleSize,r=(E[e].u+E[o].u+E[t].u)/3,s=(E[e].v+E[o].v+E[t].v)/3;if(((r-.3)/n)**2+((s-.4)/i)**2<1||((r-.7)/n)**2+((s-.4)/i)**2<1)return!1}return!0})(e,o,t)&&q.push(e,o,t)};for(let n=0;n<o-1;n++)for(let o=0;o<e-1;o++){const i=n*e+o,r=n*e+(o+1),s=(n+1)*e+o,l=(n+1)*e+(o+1);(n+o)%2==0?(t(i,r,l),t(i,l,s)):(t(i,r,s),t(r,l,s))}G=function(e,o){const n=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const t=e[o],i=e[o+1],r=e[o+2];n[t].add(i),n[t].add(r),n[i].add(t),n[i].add(r),n[r].add(t),n[r].add(i)}return n.map(e=>Array.from(e))}(q,I.length),F=new BABYLON.Mesh("face",C),F.parent=O;const i=I.length;K=new Float32Array(3*i),J=new Float32Array(3*i),X=new Float32Array(4*i),Z=new Array(i),W=1/0,Q=-1/0;for(let e=0;e<i;e++)K[3*e]=I[e].x,K[3*e+1]=I[e].y,K[3*e+2]=I[e].z,I[e].z<W&&(W=I[e].z),I[e].z>Q&&(Q=I[e].z),Z[e]=f(0,0,0),X[4*e]=1,X[4*e+1]=1,X[4*e+2]=1,X[4*e+3]=1;BABYLON.VertexData.ComputeNormals(K,q,J);const r=new BABYLON.VertexData;r.positions=Array.from(K),r.indices=q,r.normals=Array.from(J),r.colors=Array.from(X),r.applyToMesh(F,!0),he(),ue(),ce(),se(),oe=!0}function se(){ne=[],te=[];const e=.18*h.mouthHoleSize,o=.075*h.mouthHoleSize;for(let n=0;n<E.length;n++){const t=(E[n].u-.5)/e,i=(E[n].v-.69)/o,r=t*t+i*i;if(r<4){const e=E[n].v<.69,o=Math.max(-1,Math.min(1,t));let i=r<=1?r:(4-r)/3;i=Math.max(0,Math.min(1,i)),ne.push({idx:n,isUpper:e,xRel:o,weight:i,baselineTarget:V(o,e,ie)})}}const n=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of n)for(let o=0;o<E.length;o++){const n=(E[o].u-e.cu)/e.ru,t=(E[o].v-e.cv)/e.rv,i=n*n+t*t;if(i<4){const t=E[o].v<e.cv,r=Math.max(-1,Math.min(1,n));let s=i<=1?i:(4-i)/3;s=Math.max(0,Math.min(1,s));const l=j(e.cu,e.cv);te.push({idx:o,side:e.side,isUpper:t,xRel:r,weight:s,eyeDef:{center:l,hw:e.hw,hh:e.hh},baselineTarget:U(r,t,{center:l,hw:e.hw,hh:e.hh},0,0)})}}}function le(e,o,n,t){if(Math.abs(n)<.001)return;const i=o.uv[0],r=o.uv[1],s=o.radius*t,l=s*s,a=o.dir.x*n,u=o.dir.y*n,c=o.dir.z*n;for(let o=0;o<E.length;o++){const n=E[o].u-i,t=E[o].v-r,s=n*n+t*t;if(s>4*l)continue;const d=Math.exp(-s/l);e[o].x+=a*d,e[o].y+=u*d,e[o].z+=c*d}}const ae=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return h.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return h.scaleMouth}}];function ue(){O&&(O.rotation.y=h.flipFace?Math.PI:0)}function ce(){F&&(F.isVisible=!!h.meshVisible)}function de(){Y&&Y.getChildMeshes().forEach(e=>e.isVisible=!!h.minimal)}function he(){if(!F)return;F._edgesRenderer&&F.disableEdgesRendering();const e=h.lineThickness;switch(h.mode){case"wire":F.material=R,R.wireframe=!0,R.alpha=1;break;case"edges":F.material=z,z.alpha=1,z.wireframe=!1,F.enableEdgesRendering(.9999),F.edgesWidth=4*e,F.edgesColor=new BABYLON.Color4($[0],$[1],$[2],1);break;case"shaded":F.material=z,z.alpha=1,z.wireframe=!1}}let fe=null,me=null,pe=null,we=null,ye=null,_e=null;function ve(){if(me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),ye&&(ye.dispose(),ye=null),_e&&(_e.dispose(),_e=null),!h.pupils)return;fe||(fe=new BABYLON.StandardMaterial("pupilMat",C),fe.emissiveColor=BABYLON.Color3.FromHexString(h.pupilColor),fe.disableLighting=!0,fe.backFaceCulling=!1),we||(we=new BABYLON.StandardMaterial("irisMat",C),we.emissiveColor=BABYLON.Color3.FromHexString(h.irisColor),we.disableLighting=!0,we.backFaceCulling=!1);const e=.035*h.irisSize;ye=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},C),_e=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},C),ye.material=_e.material=we,ye.parent=_e.parent=O,me=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},C),pe=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},C),me.material=pe.material=fe,me.parent=pe.parent=O}function ge(e,o){const n=j(e,o);if(!h.overlayTracksMesh)return n;const t=function(e,o){if(!Z)return f(0,0,0);const n=.0036;let t=0,i=0,r=0,s=0;for(let l=0;l<E.length;l++){const a=E[l].u-e,u=E[l].v-o,c=a*a+u*u;if(c<n){const e=1-Math.sqrt(c/n);t+=e,i+=Z[l].x*e,r+=Z[l].y*e,s+=Z[l].z*e}}return 0===t?f(0,0,0):f(i/t,r/t,s/t)}(e,o);return f(n.x+t.x,n.y+t.y,n.z+t.z)}function be(e,o=18){const n=[],t=e.length,i=o=>e[Math.max(0,Math.min(t-1,o))];for(let e=0;e<t-1;e++){const t=i(e-1),r=i(e),s=i(e+1),l=i(e+2);for(let e=0;e<o;e++){const i=e/o,a=i*i,u=i*a,c=.5*(2*r.x+(-t.x+s.x)*i+(2*t.x-5*r.x+4*s.x-l.x)*a+(-t.x+3*r.x-3*s.x+l.x)*u),d=.5*(2*r.y+(-t.y+s.y)*i+(2*t.y-5*r.y+4*s.y-l.y)*a+(-t.y+3*r.y-3*s.y+l.y)*u),h=.5*(2*r.z+(-t.z+s.z)*i+(2*t.z-5*r.z+4*s.z-l.z)*a+(-t.z+3*r.z-3*s.z+l.z)*u);n.push(f(c,d,h))}}return n.push(e[t-1]),n}function Be(e,o,n,t,i,r){const s={path:o,radius:n*(null==i?1:i)*h.lineThickness,tessellation:6,updatable:!0};r&&(s.instance=r);const l=BABYLON.MeshBuilder.CreateTube(e,s,C);return r||(l.material=t||N,l.parent=Y),l}let Ce=null,Le=null;function xe(){const e=D();return{upper:be([-1,-.45,0,.45,1].map(o=>V(o,!0,e)),18),lower:be([-1,-.5,0,.5,1].map(o=>V(o,!1,e)),18)}}const Me=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let ke=[];function Oe(e,o){const n="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,t=p.eyeSquint,i=ge(e.uv[0],e.uv[1]),r=[],s=.012*t;for(let t=0;t<=12;t++){const l=t/12*Math.PI,a=i.x+Math.cos(Math.PI-l)*e.hw,u=(i.y+(o?1:-1)*Math.sin(l)*e.hh)*(1-n)+i.y*n+(o?-s:.5*s),c=i.z+.018+.012*Math.sin(l);r.push(f(a,u,c))}return r}const ze=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Re=[];function Ae(e){const o=ge(e.uv[0],e.uv[1]),n="L"===e.side?-1:1,t=.085*p.browInnerUp-.05*p.browDown,i=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,r=o.x+-.1*n,s=o.x,l=o.x+.1*n,a=o.y+t,u=o.y+.5*(t+i)+.005,c=o.y+i-.005,d=o.z+.018;return be([f(r,a,d),f(s,u,d+.01),f(l,c,d)],12)}let Ne=null,Se=null,Pe=null;function Te(){const e=.025*p.noseSneer,o=ge(.5,.4),n=ge(.5,.55),t=be([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+n.y),.5*(o.z+n.z)+.05),f(n.x,n.y+.03,n.z+.05)],14),i=n.y+.01;return{bridge:t,leftN:be([f(n.x,i,n.z+.05),f(n.x-.06-e,i-.03,n.z+.02),f(n.x-.04,i-.05,n.z+.005),f(n.x-.01,i-.02,n.z+.03)],10),rightN:be([f(n.x,i,n.z+.05),f(n.x+.06+e,i-.03,n.z+.02),f(n.x+.04,i-.05,n.z+.005),f(n.x+.01,i-.02,n.z+.03)],10)}}function Ye(){Ce&&(Ce.dispose(),Ce=null),Le&&(Le.dispose(),Le=null);for(const e of ke)e.upper.dispose(),e.lower.dispose();ke=[];for(const e of Re)e.mesh.dispose();Re=[],Ne&&(Ne.dispose(),Ne=null),Se&&(Se.dispose(),Se=null),Pe&&(Pe.dispose(),Pe=null);const{upper:e,lower:o}=xe();Ce=Be("mouth_u",e,.01,N,h.mouthLineThickness),Le=Be("mouth_l",o,.01,N,h.mouthLineThickness);for(const e of Me){const o=Be("eye_"+e.side+"_u",Oe(e,!0),.0085,S,h.eyeLineThickness),n=Be("eye_"+e.side+"_l",Oe(e,!1),.0085,S,h.eyeLineThickness);ke.push({eye:e,upper:o,lower:n})}for(const e of ze){const o=Be("brow_"+e.side,Ae(e),.011,T,h.browLineThickness);Re.push({brow:e,mesh:o})}const n=Te();Ne=Be("nose_b",n.bridge,.009,P,h.noseLineThickness),Se=Be("nose_l",n.leftN,.0085,P,h.noseLineThickness),Pe=Be("nose_r",n.rightN,.0085,P,h.noseLineThickness),de(),uo()}const je={};function He(){if(F){for(let e=0;e<n.length;e++){const o=n[e];je[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<Z.length;e++)Z[e].x=Z[e].y=Z[e].z=0;!function(e){const o=h.spread,n=D();le(e,m.mouth_jaw_drop,n.jaw,o),le(e,m.mouth_open_lower,n.open,o),le(e,m.mouth_open_upper,.4*n.open,o);const t=n.smile;t>0?(le(e,m.mouth_smile_L,t,o),le(e,m.mouth_smile_R,t,o)):t<0&&(le(e,m.mouth_frown_L,-t,o),le(e,m.mouth_frown_R,-t,o)),le(e,m.mouth_round_L,n.round,o),le(e,m.mouth_round_R,n.round,o),le(e,m.mouth_round_top,n.round,o),le(e,m.mouth_round_bot,n.round,o),le(e,m.mouth_press_top,n.lipPress,o),le(e,m.mouth_press_bot,n.lipPress,o),n.width>0&&(le(e,m.mouth_width_L,n.width,o),le(e,m.mouth_width_R,n.width,o)),le(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),le(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),le(e,m.eye_blink_R_up,p.eyeBlinkRight,o),le(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),le(e,m.eye_squint_L,p.eyeSquint,o),le(e,m.eye_squint_R,p.eyeSquint,o),le(e,m.brow_inner_L,p.browInnerUp,o),le(e,m.brow_inner_R,p.browInnerUp,o),p.browOuterUp>=0?(le(e,m.brow_outer_L,p.browOuterUp,o),le(e,m.brow_outer_R,p.browOuterUp,o)):(le(e,m.brow_down_L,.6*-p.browOuterUp,o),le(e,m.brow_down_R,.6*-p.browOuterUp,o)),le(e,m.brow_down_L,p.browDown,o),le(e,m.brow_down_R,p.browDown,o),le(e,m.nose_sneer_L,p.noseSneer,o),le(e,m.nose_sneer_R,p.noseSneer,o)}(Z),h.reactivity>0&&function(e,o){if(o<=0)return;const n=e.length,t=new Array(n);for(let i=0;i<n;i++){const n=G[i];if(0===n.length){t[i]=f(e[i].x,e[i].y,e[i].z);continue}let r=0,s=0,l=0;for(const o of n)r+=e[o].x,s+=e[o].y,l+=e[o].z;r/=n.length,s/=n.length,l/=n.length,t[i]=f(e[i].x*(1-o)+r*o,e[i].y*(1-o)+s*o,e[i].z*(1-o)+l*o)}for(let o=0;o<n;o++)e[o].x=t[o].x,e[o].y=t[o].y,e[o].z=t[o].z}(Z,h.reactivity),function(e){for(const o of ae){const n=o.scale;if(Math.abs(n-1)<.001)continue;const t=j(o.uv[0],o.uv[1]),i=o.radiusUV*o.radiusUV,r=4*i;for(let s=0;s<E.length;s++){const l=E[s].u-o.uv[0],a=E[s].v-o.uv[1],u=l*l+a*a;if(u>r)continue;const c=Math.exp(-u/i),d=I[s].x-t.x,h=I[s].y-t.y,f=I[s].z-t.z,m=(n-1)*c;e[s].x+=d*m,e[s].y+=h*m,e[s].z+=f*m}}}(Z),function(e){const o=h.jawExtend;if(o<.001)return;const n=p.jawOpen||0;if(n<.001)return;const t=n*o*.1;for(let o=0;o<E.length;o++){const n=E[o].v;if(n<.55)continue;const i=Math.min(1,(n-.55)/.45);e[o].z+=t*i}}(Z),function(e){const o=h.mouthGrow;if(o<.001)return;const n=D().open;if(n<.001)return;const t=n*o,i=.0625;for(let o=0;o<E.length;o++){const n=E[o].u-.5,r=E[o].v-.69,s=n*n+r*r;if(s>i)continue;const l=1-Math.sqrt(s/i),a=I[o];e[o].x+=(a.x-H.x)*t*l*.4,e[o].y+=(a.y-H.y)*t*l*.4,e[o].z+=t*l*.05}}(Z),function(e){const o=h.upperJawProtrude;if(o<.001)return;const n=.18*o;for(let o=0;o<E.length;o++){const t=E[o].v;if(t<.45||t>.72)continue;const i=t<.62?(t-.45)/.17:(.72-t)/.1;e[o].z+=n*i}}(Z),function(e){const o=h.lowerJawProtrude;if(o<.001)return;const n=.18*o;for(let o=0;o<E.length;o++){const t=E[o].v;if(t<.7)continue;let i;i=t<.85?(t-.7)/.15:1-(t-.85)/.3,i<0&&(i=0),e[o].z+=n*i}}(Z),function(e){if(!h.mouthAnchor)return;const o=D();for(const n of ne){const t=V(n.xRel,n.isUpper,o),i=t.x-n.baselineTarget.x,r=t.y-n.baselineTarget.y,s=t.z-n.baselineTarget.z,l=n.weight;e[n.idx].x=e[n.idx].x*(1-l)+i*l,e[n.idx].y=e[n.idx].y*(1-l)+r*l,e[n.idx].z=e[n.idx].z*(1-l)+s*l}}(Z),function(e){if(!h.eyeAnchor)return;const o=p.eyeBlinkLeft,n=p.eyeBlinkRight,t=p.eyeSquint;for(const i of te){const r="L"===i.side?o:n,s=U(i.xRel,i.isUpper,i.eyeDef,r,t),l=s.x-i.baselineTarget.x,a=s.y-i.baselineTarget.y,u=s.z-i.baselineTarget.z,c=i.weight;e[i.idx].x=e[i.idx].x*(1-c)+l*c,e[i.idx].y=e[i.idx].y*(1-c)+a*c,e[i.idx].z=e[i.idx].z*(1-c)+u*c}}(Z);for(let e=0;e<I.length;e++)K[3*e]=I[e].x+Z[e].x,K[3*e+1]=I[e].y+Z[e].y,K[3*e+2]=I[e].z+Z[e].z;if(F.updateVerticesData(BABYLON.VertexBuffer.PositionKind,K),h.depthFade>.001){const e=Q-W||1,o=h.depthFade,n=h.depthFadeCurve>0?h.depthFadeCurve:1;for(let t=0;t<I.length;t++){const i=K[3*t+2];let r=(Q-i)/e;r<0?r=0:r>1&&(r=1),1!==n&&(r=Math.pow(r,n)),r*=o,X[4*t]=$[0]*(1-r)+ee[0]*r,X[4*t+1]=$[1]*(1-r)+ee[1]*r,X[4*t+2]=$[2]*(1-r)+ee[2]*r,X[4*t+3]=1}F.updateVerticesData(BABYLON.VertexBuffer.ColorKind,X)}else if(oe){for(let e=0;e<I.length;e++)X[4*e]=$[0],X[4*e+1]=$[1],X[4*e+2]=$[2],X[4*e+3]=1;F.updateVerticesData(BABYLON.VertexBuffer.ColorKind,X),oe=!1}"edges"!==h.mode&&"shaded"!==h.mode||(BABYLON.VertexData.ComputeNormals(K,q,J),F.updateVerticesData(BABYLON.VertexBuffer.NormalKind,J)),function(){if(!me||!pe)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,n=j(.3,.4),t=j(.7,.4);ye&&_e&&(ye.position.set(n.x+.6*e,n.y+.6*o,n.z+.045),_e.position.set(t.x+.6*e,t.y+.6*o,t.z+.045)),me.position.set(n.x+e,n.y+o,n.z+.05),pe.position.set(t.x+e,t.y+o,t.z+.05);const i=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);me.isVisible=pe.isVisible=i<.85,ye&&_e&&(ye.isVisible=_e.isVisible=i<.85)}(),h.minimal&&function(){if(!Ce)return;const e=xe();Be("",e.upper,.01,null,h.mouthLineThickness,Ce),Be("",e.lower,.01,null,h.mouthLineThickness,Le);for(const e of ke)Be("",Oe(e.eye,!0),.0085,null,h.eyeLineThickness,e.upper),Be("",Oe(e.eye,!1),.0085,null,h.eyeLineThickness,e.lower);for(const e of Re)Be("",Ae(e.brow),.011,null,h.browLineThickness,e.mesh);const o=Te();Be("",o.bridge,.009,null,h.noseLineThickness,Ne),Be("",o.leftN,.0085,null,h.noseLineThickness,Se),Be("",o.rightN,.0085,null,h.noseLineThickness,Pe)}(),O.rotation.x=.35*p.headRotateX,O.rotation.y=.5*p.headRotateY,O.rotation.z=.3*p.headRotateZ;for(let e=0;e<n.length;e++)p[n[e]]=je[n[e]]}}let Ve=1.5+3*Math.random(),Ue=0,De=.8+2*Math.random(),Fe=0,Ie=0,Ee=0,qe=0;let Ge=null,Ze=null,Ke=null,Je=null,Xe=0,We=0,Qe=!1,$e=null;function eo(){Ge||(Ge=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Ge.state&&Ge.resume()}function oo(){if(Ke){try{Ke.stop()}catch(e){}try{Ke.disconnect()}catch(e){}Ke=null}if(Je){try{Je.disconnect()}catch(e){}Je=null}Qe=!1}function no(){return Ge&&Ze?Qe?Ge.currentTime-Xe:We||0:0}function to(e,o){if(!$e)return 0;const n=Ge.sampleRate/2/$e.length,t=Math.max(0,Math.floor(e/n)),i=Math.min($e.length-1,Math.ceil(o/n));let r=0,s=0;for(let e=t;e<=i;e++)r+=$e[e],s++;return s?r/s/255:0}function io(e){h.lineColor=e;const o=BABYLON.Color3.FromHexString(e);h.mouthColor||(N.emissiveColor=o),h.eyeColor||(S.emissiveColor=o),h.noseColor||(P.emissiveColor=o)}function ro(e){h.mouthColor=e,N.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function so(e){h.eyeColor=e,S.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function lo(e){h.noseColor=e,P.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function ao(e){h.browColor=e,T.emissiveColor=BABYLON.Color3.FromHexString(e)}function uo(){const e=(e,o)=>{e&&(e.isVisible=o)};e(Ce,!!h.minimalMouth),e(Le,!!h.minimalMouth);for(const o of ke)e(o.upper,!!h.minimalEyes),e(o.lower,!!h.minimalEyes);for(const o of Re)e(o.mesh,!!h.minimalBrows);e(Ne,!!h.minimalNose),e(Se,!!h.minimalNose),e(Pe,!!h.minimalNose)}function co(e){h.pupilColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function ho(e){h.baseColor=e,$=c(e),oe=!0,R.emissiveColor=new BABYLON.Color3($[0],$[1],$[2]),F&&F._edgesRenderer&&(F.edgesColor=new BABYLON.Color4($[0],$[1],$[2],1))}function fo(e){h.fadeColor=e,ee=c(e),oe=!0}function mo(e){h.irisColor=e,we&&(we.emissiveColor=BABYLON.Color3.FromHexString(e))}const po={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let wo=!1;function yo(e){if("orbit"===e)return void(wo=!0);wo=!1;const o=po[e];o&&(x.alpha=o.alpha,x.beta=o.beta,x.radius=o.radius)}function _o(){L.intensity=h.glow?.85:0}re(),ve(),Ye(),ho(h.baseColor),fo(h.fadeColor),io(h.lineColor),ao(h.browColor),h.mouthColor&&ro(h.mouthColor),h.eyeColor&&so(h.eyeColor),h.noseColor&&lo(h.noseColor),co(h.pupilColor),mo(h.irisColor),uo(),_o(),yo(h.cameraView);let vo=performance.now(),go=!1;B.runRenderLoop(()=>{if(go)return;const e=performance.now(),o=Math.min(.05,(e-vo)/1e3);vo=e,function(e){Ue+=e,Ue>Ve&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=g.sleep>.5?1:0,w.eyeBlinkRight=g.sleep>.5?1:0},110),Ue=0,Ve=1.5+3.5*Math.random()),Fe+=e,Fe>De&&!y.eyeLookH&&(Ie=.6*(Math.random()-.5),Ee=.4*(Math.random()-.5),Fe=0,De=.7+2.5*Math.random()),w.eyeLookH=Ie,w.eyeLookV=Ee,qe+=e,w.headRotateX=.04*Math.sin(.27*qe),w.headRotateY=.06*Math.sin(.19*qe),w.headRotateZ=.03*Math.sin(.11*qe)}(o),Qe&&function(){if(!Je)return;Je.getByteFrequencyData($e);const e=to(200,700),o=to(700,2e3),n=to(2e3,4e3),i=to(4e3,8e3),r=to(1500,5e3),s=Math.max(e,o,n,i);if(s<.08){for(const e of Object.keys(t))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(t))"sil"!==e&&(w["viseme_"+e]=0);i>.35&&i>.8*o&&(w.viseme_SS=Math.min(1,1.3*i),w.viseme_FF=Math.min(.6,1.2*r)),e>o&&e>.18?n>.25?w.viseme_aa=Math.min(1,1.2*e):(w.viseme_O=Math.min(1,1.2*e),w.viseme_U=Math.min(.7,.9*e)):o>.2&&(n>.6*o?(w.viseme_I=Math.min(1,1.4*n),w.viseme_E=Math.min(.7,1.1*o)):(w.viseme_E=Math.min(1,1.3*o),w.viseme_aa=Math.min(.4,.9*e)))}(),function(e){const o=Math.max(.05,h.moodTransitionTime)/4,n=1-Math.pow(.5,e/o);for(const e of r)g[e]+=(v[e]-g[e])*n;for(const e of s){let o=0;for(const n of r)o+=(i[n][e]||0)*g[n];w[e]=o}}(o),function(e){for(const o of n){if(y[o]){p[o]=w[o];continue}const n=l[o]||l.default,t=1-Math.exp(-n*e*30);p[o]=p[o]+(w[o]-p[o])*t}}(o),He(),wo&&(x.alpha+=.3*o),C.render()});const bo=()=>B.resize();function Bo(e){if(!e)return;const o=e.renderConfig||{};let t=!1;void 0!==o.meshCols&&o.meshCols!==h.meshCols&&(t=!0),void 0!==o.meshRows&&o.meshRows!==h.meshRows&&(t=!0),void 0!==o.fragment&&o.fragment!==h.fragment&&(t=!0),void 0!==o.mouthHole&&o.mouthHole!==h.mouthHole&&(t=!0),void 0!==o.eyeHoles&&o.eyeHoles!==h.eyeHoles&&(t=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==h.mouthHoleSize&&(t=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==h.eyeHoleSize&&(t=!0),void 0!==o.eyeDepth&&o.eyeDepth!==h.eyeDepth&&(t=!0);const s=void 0!==o.lineThickness||void 0!==o.mouthLineThickness||void 0!==o.eyeLineThickness||void 0!==o.noseLineThickness||void 0!==o.browLineThickness;if(Object.assign(h,o),e.lineColor&&io(e.lineColor),e.pupilColor&&co(e.pupilColor),o.baseColor&&ho(o.baseColor),o.fadeColor&&fo(o.fadeColor),o.lineColor&&io(o.lineColor),o.pupilColor&&co(o.pupilColor),o.irisColor&&mo(o.irisColor),o.browColor&&ao(o.browColor),void 0!==o.mouthColor&&ro(o.mouthColor),void 0!==o.eyeColor&&so(o.eyeColor),void 0!==o.noseColor&&lo(o.noseColor),t?(re(),Ye(),ve()):(he(),ue(),ce(),de(),s&&Ye(),void 0===o.irisSize&&void 0===o.pupils||ve(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||se()),void 0===o.minimalMouth&&void 0===o.minimalEyes&&void 0===o.minimalNose&&void 0===o.minimalBrows||uo(),void 0!==o.glow&&_o(),e.channelGains)for(const o of n)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&i[e.activeMood]){b=e.activeMood;for(const e of r)v[e]=e===b?1:0}}return window.addEventListener("resize",bo),{loadAudio:async function(e){eo();const o=await e.arrayBuffer();Ze=await Ge.decodeAudioData(o.slice(0)),We=0},play(e){Ze&&function(e){Ze&&(eo(),Ke=Ge.createBufferSource(),Ke.buffer=Ze,Ke.loop=!!h.loopAudio,Je=Ge.createAnalyser(),Je.fftSize=1024,Je.smoothingTimeConstant=.4,$e=new Uint8Array(Je.frequencyBinCount),Ke.connect(Je),Je.connect(Ge.destination),Xe=Ge.currentTime-(e||0),Ke.start(0,e||0),Ke.onended=()=>{if(!h.loopAudio){Qe=!1;for(const e of Object.keys(t))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Qe=!0)}(void 0!==e?e:We)},pause(){Qe&&(We=no(),oo())},stop(){We=0,oo();for(const e of Object.keys(t))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){h.loopAudio=!!e,Ke&&(Ke.loop=!!e)},setMood(e){if(i[e]){b=e;for(const o of r)v[o]=o===e?1:0}},setChannel(e,n){if(!o[e])return;const t=o[e].range,i=Math.max(t[0],Math.min(t[1],n));w[e]=i,p[e]=i,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:yo,loadPreset:Bo,setRenderConfig(e){Bo({renderConfig:e})},getRenderConfig:()=>Object.assign({},h),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,n){o[e]&&(_[e]=n)},getChannelNames:()=>n.slice(),getMoodNames:()=>r.slice(),isPlaying:()=>Qe,getDuration:()=>Ze?Ze.duration:0,getPosition:()=>no(),getActiveMood:()=>b,dispose(){go=!0;try{oo()}catch(e){}if(Ge){try{Ge.close()}catch(e){}Ge=null}window.removeEventListener("resize",bo);try{B.stopRenderLoop()}catch(e){}try{C.dispose()}catch(e){}try{B.dispose()}catch(e){}}}}e.createWireface=d,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:d})}("undefined"!=typeof window?window:globalThis);