wireface 1.1.0 → 1.1.2

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
 
@@ -265,12 +265,27 @@ Issues, PRs, and ideas are very welcome. Anything that's fair game:
265
265
  - mood blends, idle micro-motion presets, eye-look behaviors
266
266
  - performance / memory tweaks (smaller draws, tighter geometry rebuilds, WebGPU path)
267
267
  - alternative renderers (svg, 2d-canvas) sharing the same channel surface
268
- - new preset packs (drop them in [`examples/presets/`](examples/presets/))
269
268
  - editor UX: keyboard shortcuts, undo, multi-channel keyframing
270
269
  - docs, typos, clearer onboarding
271
270
 
272
271
  Open an [issue](https://github.com/styk-tv/wireface/issues) or send a PR — small ones are perfect.
273
272
 
273
+ ### 🎨 Send us your presets!
274
+
275
+ The single most useful contribution is **a preset of your own face**. Take
276
+ the [editor](examples/editor.html), tune sliders + colours + channel gains
277
+ until you've got something that feels like a character to you, then hit
278
+ **+ save preset → ↓ download** and submit a PR adding the JSON to
279
+ [`examples/presets/`](examples/presets/) with a one-line README entry
280
+ describing the vibe (e.g. "scared crocodile", "neon priest", "low-poly
281
+ robot"). Author yourself in the filename or a comment — we'll keep
282
+ attribution intact.
283
+
284
+ The two presets bundled today (`asset-th5rha`, `asset-ydr7de`) are
285
+ starting points, not the canon. The library's whole point is character
286
+ variety, and the only way that scales is community-built preset packs.
287
+ Same kind of generosity that built the demoscene.
288
+
274
289
  ## Show & tell
275
290
 
276
291
  Built something with wireface? Please share it. There's a dedicated space:
@@ -281,6 +296,61 @@ If you build a public tool / site / experiment with it, a star on the repo is a
281
296
 
282
297
  ---
283
298
 
299
+ ## References
300
+
301
+ The channel grammar is the union of two well-established blendshape
302
+ inventories. Pick one to read end-to-end and the other will look familiar.
303
+
304
+ ### Oculus Lipsync · 15 visemes (mouth-shape primitives)
305
+
306
+ The 15 viseme channels (`viseme_sil`, `viseme_PP`, `viseme_FF`, `viseme_TH`,
307
+ `viseme_DD`, `viseme_kk`, `viseme_CH`, `viseme_SS`, `viseme_nn`, `viseme_RR`,
308
+ `viseme_aa`, `viseme_E`, `viseme_I`, `viseme_O`, `viseme_U`) come from the
309
+ Oculus Lipsync SDK's phoneme alphabet. The same set ships with HeadTTS,
310
+ Kokoro, ovrlipsync, and most "phoneme alignment" pipelines. Audio FFT
311
+ estimates the active viseme each frame and the renderer weighted-sums the
312
+ `(open, width, round, smile, lipPress, jaw)` targets.
313
+
314
+ - [Oculus Audio SDK — Viseme Reference](https://developer.oculus.com/documentation/native/audio-ovrlipsync-viseme-reference/)
315
+ — the canonical 15-viseme table plus example audio cues per phoneme.
316
+ - [Oculus Lipsync overview](https://developer.oculus.com/documentation/native/audio-ovrlipsync-native/)
317
+ — what the SDK does and why the 15-viseme split.
318
+
319
+ ### ARKit · 15-of-52 face blendshapes (additive face shape)
320
+
321
+ The remaining 15 channels (`jawOpen`, `mouthSmile`, `mouthPucker`,
322
+ `eyeBlinkLeft/Right`, `eyeLookH/V`, `eyeSquint`, `browInnerUp/OuterUp/Down`,
323
+ `noseSneer`, `headRotateX/Y/Z`) are a curated subset of Apple ARKit's full
324
+ 52-blendshape inventory, named to match. ARKit blendshapes are the
325
+ de-facto industry standard for face animation since iPhone X / TrueDepth;
326
+ glTF face blendshapes, MetaHuman, NVIDIA Audio2Face, and Ready Player Me
327
+ all use compatible naming.
328
+
329
+ - [ARKit `BlendShapeLocation` reference](https://developer.apple.com/documentation/arkit/arfaceanchor/blendshapelocation)
330
+ — full 52-blendshape list with semantic names + face-region grouping.
331
+ - [ARKit Face Tracking overview](https://developer.apple.com/documentation/arkit/tracking_and_visualizing_faces)
332
+ — what ARKit's blendshapes mean and how they're estimated from the
333
+ TrueDepth depth+IR camera.
334
+
335
+ ### Why this split?
336
+
337
+ A renderer that only knew Oculus visemes would lipsync audio but couldn't
338
+ emote. A renderer that only knew ARKit blendshapes would emote but
339
+ lipsync poorly (ARKit's mouth blendshapes are continuous 0..1 dilations,
340
+ not phoneme-aligned). Combining both gives **mouth that lipsyncs from
341
+ audio + face that emotes from explicit channels** — they layer additively
342
+ in `computeMouthParams()` so both signals can drive the face simultaneously
343
+ without conflict.
344
+
345
+ The full grammar (channel names, ranges, smoothing, drive maps, preset
346
+ JSON shape, invariants) is in
347
+ [`SPEC.WIREFACE.GRAMMAR.v1.0.md`](SPEC.WIREFACE.GRAMMAR.v1.0.md).
348
+ Babylon.js setup details (multi-instance scenes, multi-canvas pages,
349
+ playground integration) are in
350
+ [`SPEC.WIREFACE.BABYLON.9.0.md`](SPEC.WIREFACE.BABYLON.9.0.md).
351
+
352
+ ---
353
+
284
354
  ## License
285
355
 
286
356
  MIT © 2026 Peter Styk — see [`LICENSE`](LICENSE).
package/dist/wireface.js CHANGED
@@ -243,7 +243,26 @@
243
243
 
244
244
  /* ── Babylon scene ── */
245
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
246
- const scene = new BABYLON.Scene(engine);
246
+ // v1.1.2: useRightHandedSystem MUST be set via Scene constructor options
247
+ // (not by post-construction property assignment) — the post-assign path
248
+ // gets silently no-op'd somewhere in Babylon 9.5's scene init pipeline,
249
+ // so the scene boots in LH despite our request. The constructor option
250
+ // sticks. Verified empirically with playwright: post-assign showed
251
+ // `scene.useRightHandedSystem === false` at first frame, but options-form
252
+ // shows true.
253
+ //
254
+ // Why we want RH at all: Babylon's LH default puts +Z into the screen.
255
+ // warpToFace builds the face with +Z = nose-forward, so in LH the face
256
+ // would render facing AWAY from the default ArcRotateCamera at -Z (user
257
+ // sees back of head, profile shows wrong side). RH flips Z so +Z is
258
+ // out-of-screen, geometry naturally faces the camera, and the camera
259
+ // view alphas (front=-π/2, profile=0, three-q=-π/2-0.6) map to the
260
+ // conventionally-correct sides of the face — front shows the front,
261
+ // profile shows the face's right, three-quarter is a proper portrait
262
+ // angle. No geometry change, no faceRoot.rotation flip, no view-alpha
263
+ // rewiring.
264
+ const scene = new BABYLON.Scene(engine, { useRightHandedSystem: true });
265
+ scene.useRightHandedSystem = true; // belt and braces — also assign post-ctor
247
266
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
248
267
  // we never pick on pointer-move; saves a per-frame ray test
249
268
  scene.skipPointerMovePicking = true;
@@ -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}},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.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);
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,{useRightHandedSystem:!0});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);
@@ -572,7 +572,11 @@ function computeMouthParams() {
572
572
 
573
573
  const canvas = document.getElementById('renderCanvas');
574
574
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true, antialias: true });
575
- const scene = new BABYLON.Scene(engine);
575
+ // v1.1.2: useRightHandedSystem must be passed via constructor options
576
+ // (post-construction property assign gets silently no-op'd by Babylon 9.5's
577
+ // scene init in some paths). Keeps both forms for resilience.
578
+ const scene = new BABYLON.Scene(engine, { useRightHandedSystem: true });
579
+ scene.useRightHandedSystem = true;
576
580
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
577
581
 
578
582
  /* camera — orbit around the face */
@@ -0,0 +1,83 @@
1
+ <!DOCTYPE html>
2
+ <!--
3
+ wireface — playground · https://github.com/styk-tv/wireface
4
+ MIT © 2026 Peter Styk
5
+
6
+ Minimal: canvas, sample audio loops, ←/→ cycle presets, space toggles.
7
+ Add your own: clone the repo, open examples/editor.html in a browser,
8
+ tune sliders + colours, hit "save preset → ↓ download", paste the JSON
9
+ literal into the PRESETS array below, send a PR.
10
+ -->
11
+ <html lang="en">
12
+ <head>
13
+ <meta charset="utf-8">
14
+ <meta name="viewport" content="width=device-width,initial-scale=1">
15
+ <title>wireface</title>
16
+ <style>
17
+ html,body { margin:0; height:100%; background:#000; overflow:hidden; }
18
+ canvas { width:100vw; height:100vh; display:block; outline:none; touch-action:none; }
19
+ /* one tiny bottom-right link, dim, hover-brightens. nothing else. */
20
+ a { position:fixed; bottom:10px; right:14px; font:10px ui-monospace,monospace;
21
+ letter-spacing:.18em; text-transform:uppercase; color:rgba(255,255,255,.28);
22
+ text-decoration:none; mix-blend-mode:difference; }
23
+ a:hover { color:rgba(255,255,255,.9); }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <canvas id="cv"></canvas>
28
+ <a href="https://github.com/styk-tv/wireface" target="_blank">github · ←/→ swap · space play</a>
29
+
30
+ <script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
31
+ <script src="https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js"></script>
32
+ <script>
33
+ /* PRESETS — full preset literals exactly as exported by the editor's
34
+ "save preset → ↓ download" button. Append your own at the end; the UI
35
+ adapts automatically (←/→ wraps the array). PR yours into
36
+ examples/presets/ AND/OR append here so they land on the playground. */
37
+ const PRESETS = [
38
+ {"version":"wireface-v010","createdAt":"2026-05-01T02:19:44.566Z","renderConfig":{"meshCols":21,"meshRows":21,"scaleNose":0.4,"scaleEyes":1.35,"scaleMouth":0.4,"reactivity":0.24,"spread":0.9,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":1.15,"eyeHoles":true,"eyeDepth":5,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":0.4,"lipVertAmp":4,"lipPressForce":3,"overlayTracksMesh":true,"moodTransitionTime":0.05,"lineColor":"#541717","pupilColor":"#c4b0b0","baseColor":"#ff8585","fadeColor":"#f00000","depthFade":1,"irisColor":"#ff0000","irisSize":3.3,"browColor":"#616161","jawExtend":0,"mouthGrow":0},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"th5rha","name":"asset__post__th5rha"},
39
+ {"version":"wireface-v010","createdAt":"2026-05-01T02:00:12.074Z","renderConfig":{"meshCols":7,"meshRows":9,"scaleNose":1.15,"scaleEyes":2,"scaleMouth":2,"reactivity":0.26,"spread":0.8,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":1.85,"eyeHoles":false,"eyeDepth":1,"mouthAnchor":true,"eyeAnchor":false,"lineThickness":1,"lipVertAmp":1.6,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.05,"lineColor":"#181616","pupilColor":"#3a2727","baseColor":"#7a86c2","fadeColor":"#f00000","depthFade":0.4,"irisColor":"#170303","irisSize":2,"browColor":"#616161","jawExtend":0,"mouthGrow":0},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"ydr7de","name":"asset__post__ydr7de"},
40
+ // ← append more here. the UI adapts to whatever length this array is.
41
+ ];
42
+
43
+ const wf = createWireface(document.getElementById('cv'));
44
+ wf.setLoop(true);
45
+
46
+ let idx = 0;
47
+ const apply = () => wf.loadPreset(PRESETS[idx]);
48
+ apply();
49
+
50
+ document.addEventListener('keydown', e => {
51
+ if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
52
+ idx = (idx + 1) % PRESETS.length; apply();
53
+ } else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
54
+ idx = (idx - 1 + PRESETS.length) % PRESETS.length; apply();
55
+ } else if (e.key === ' ') {
56
+ wf.isPlaying() ? wf.pause() : wf.play();
57
+ e.preventDefault();
58
+ }
59
+ });
60
+
61
+ /* fetch the bundled TTS sample from jsDelivr's GitHub mirror (CORS-friendly,
62
+ raw.githubusercontent.com isn't) and start playback. Browser autoplay
63
+ policies require a user gesture for audio; on the playground that gesture
64
+ is the click on the Run button so it works there. Locally, if it doesn't,
65
+ space toggles play/pause. */
66
+ fetch('https://cdn.jsdelivr.net/gh/styk-tv/wireface@main/examples/Wireface-001-kokoro-santa.mp3')
67
+ .then(r => r.blob())
68
+ .then(blob => wf.loadAudio(new File([blob], 'sample.mp3')))
69
+ .then(() => wf.play())
70
+ .catch(() => {});
71
+
72
+ /* drag-drop your own .mp3 to override the sample */
73
+ window.addEventListener('dragover', e => e.preventDefault());
74
+ window.addEventListener('drop', async e => {
75
+ e.preventDefault();
76
+ const f = e.dataTransfer.files && e.dataTransfer.files[0];
77
+ if (f) { await wf.loadAudio(f); wf.play(); }
78
+ });
79
+
80
+ window.wf = wf;
81
+ </script>
82
+ </body>
83
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireface",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Minimal embeddable wireframe lipsync face renderer — drives expressive character profiles from voice or TTS audio in the browser.",
5
5
  "main": "wireface.js",
6
6
  "browser": "wireface.js",
package/wireface.js CHANGED
@@ -243,7 +243,26 @@
243
243
 
244
244
  /* ── Babylon scene ── */
245
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
246
- const scene = new BABYLON.Scene(engine);
246
+ // v1.1.2: useRightHandedSystem MUST be set via Scene constructor options
247
+ // (not by post-construction property assignment) — the post-assign path
248
+ // gets silently no-op'd somewhere in Babylon 9.5's scene init pipeline,
249
+ // so the scene boots in LH despite our request. The constructor option
250
+ // sticks. Verified empirically with playwright: post-assign showed
251
+ // `scene.useRightHandedSystem === false` at first frame, but options-form
252
+ // shows true.
253
+ //
254
+ // Why we want RH at all: Babylon's LH default puts +Z into the screen.
255
+ // warpToFace builds the face with +Z = nose-forward, so in LH the face
256
+ // would render facing AWAY from the default ArcRotateCamera at -Z (user
257
+ // sees back of head, profile shows wrong side). RH flips Z so +Z is
258
+ // out-of-screen, geometry naturally faces the camera, and the camera
259
+ // view alphas (front=-π/2, profile=0, three-q=-π/2-0.6) map to the
260
+ // conventionally-correct sides of the face — front shows the front,
261
+ // profile shows the face's right, three-quarter is a proper portrait
262
+ // angle. No geometry change, no faceRoot.rotation flip, no view-alpha
263
+ // rewiring.
264
+ const scene = new BABYLON.Scene(engine, { useRightHandedSystem: true });
265
+ scene.useRightHandedSystem = true; // belt and braces — also assign post-ctor
247
266
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
248
267
  // we never pick on pointer-move; saves a per-frame ray test
249
268
  scene.skipPointerMovePicking = true;