wireface 1.1.0 → 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
@@ -244,6 +244,17 @@
244
244
  /* ── Babylon scene ── */
245
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
246
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;
247
258
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
248
259
  // we never pick on pointer-move; saves a per-frame ray test
249
260
  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);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);
@@ -573,6 +573,13 @@ function computeMouthParams() {
573
573
  const canvas = document.getElementById('renderCanvas');
574
574
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true, antialias: true });
575
575
  const scene = new BABYLON.Scene(engine);
576
+ // v1.1.1: use right-handed coordinate system so the face's +Z forward (built
577
+ // by warpToFace) naturally points at the default ArcRotateCamera. Removes
578
+ // the need for a 180° Y-flip at the faceRoot to make front view correct, and
579
+ // fixes the "profile shows back of head" bug — view alphas now map to the
580
+ // natural side of the face, as the user requested ("find a way to ... relax
581
+ // those on init so we can use view as designed").
582
+ scene.useRightHandedSystem = true;
576
583
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
577
584
 
578
585
  /* camera — orbit around the face */
@@ -0,0 +1,147 @@
1
+ <!DOCTYPE html>
2
+ <!--
3
+ wireface — minimal CDN playground
4
+ Repository: https://github.com/styk-tv/wireface
5
+ npm: https://www.npmjs.com/package/wireface
6
+ Copyright (c) 2026 Peter Styk
7
+ Released under the MIT License — see LICENSE in the repository root.
8
+
9
+ Self-contained, ~100 lines. Drop an mp3 onto the canvas, switch
10
+ between two preset characters, hit ▶ play. Library + Babylon both
11
+ loaded from CDN. Designed to be as close as possible to a copy-paste
12
+ for playground.babylonjs.com — see SPEC.WIREFACE.BABYLON.9.0 §6.
13
+ -->
14
+ <html lang="en">
15
+ <head>
16
+ <meta charset="utf-8">
17
+ <meta name="viewport" content="width=device-width,initial-scale=1">
18
+ <title>wireface — playground</title>
19
+ <style>
20
+ html,body { margin:0; height:100%; background:#000; color:#f4f4f0; font-family: ui-monospace, monospace; }
21
+ #app { display:grid; grid-template-rows:auto 1fr auto; height:100%; }
22
+ header { padding:12px 16px; border-bottom:1px solid rgba(255,255,255,.12); display:flex; gap:18px; align-items:center; font-size:11px; letter-spacing:.16em; text-transform:uppercase; }
23
+ header b { color:#f5e663; letter-spacing:.3em; font-weight:500; }
24
+ header .hint { color:#888; }
25
+ .canvas-wrap { position:relative; min-height:0; background:#000; }
26
+ canvas { width:100%; height:100%; display:block; outline:none; touch-action:none; }
27
+ .drop-overlay { position:absolute; inset:0; display:grid; place-items:center;
28
+ background:rgba(0,0,0,.6); border:2px dashed #f5e663; color:#f5e663;
29
+ font-size:12px; letter-spacing:.2em; text-transform:uppercase; pointer-events:none; opacity:0;
30
+ transition:opacity .15s; }
31
+ .canvas-wrap.drag-over .drop-overlay { opacity:1; }
32
+ .controls { display:flex; gap:8px; align-items:center; padding:10px 16px; border-top:1px solid rgba(255,255,255,.12); font-size:11px; }
33
+ button { font-family:inherit; font-size:10px; letter-spacing:.16em; text-transform:uppercase;
34
+ background:transparent; color:#f4f4f0; border:1px solid rgba(255,255,255,.22);
35
+ padding:8px 14px; cursor:pointer; transition:all .12s; }
36
+ button:hover:not(:disabled) { background:#f4f4f0; color:#000; border-color:#f4f4f0; }
37
+ button.on { background:#f5e663; color:#000; border-color:#f5e663; }
38
+ button:disabled { opacity:.3; cursor:not-allowed; }
39
+ .audio-name { font-size:10px; color:#888; margin-left:auto; padding-left:14px; border-left:2px solid rgba(255,255,255,.22); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:300px; }
40
+ </style>
41
+ </head>
42
+ <body>
43
+ <div id="app">
44
+ <header>
45
+ <b>WIREFACE</b>
46
+ <span class="hint">drop .mp3 onto the face · switch presets · play</span>
47
+ </header>
48
+ <div class="canvas-wrap" id="wrap">
49
+ <canvas id="cv"></canvas>
50
+ <div class="drop-overlay">drop an audio file</div>
51
+ </div>
52
+ <div class="controls">
53
+ <button data-preset="A" class="on">preset A · red wire</button>
54
+ <button data-preset="B">preset B · low-poly blue</button>
55
+ <button id="btn-play">▶ play</button>
56
+ <button id="btn-stop">■ stop</button>
57
+ <span class="audio-name" id="audio-name">no audio loaded</span>
58
+ </div>
59
+ </div>
60
+
61
+ <!-- Babylon v9 + wireface from CDN -->
62
+ <script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
63
+ <script src="https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js"></script>
64
+
65
+ <script>
66
+ /* Two character presets baked-in — same shape as
67
+ examples/presets/asset-th5rha.json (red wire) and asset-ydr7de.json
68
+ (low-poly blue). Trimmed to just the renderConfig fields that
69
+ matter for the visual. The lib fills in defaults for everything
70
+ else (per-feature colors null = inherit, channelGains 1.0, etc.). */
71
+ const PRESETS = {
72
+ A: {
73
+ name: 'red wire',
74
+ renderConfig: {
75
+ meshCols: 21, meshRows: 21, fragment: true, glow: true,
76
+ mouthHole: true, mouthHoleSize: 1.15, eyeHoles: true, eyeDepth: 5,
77
+ lineThickness: 0.4, lipVertAmp: 4, lipPressForce: 3,
78
+ pupils: true, irisSize: 3.3,
79
+ lineColor: '#541717', baseColor: '#ff8585', fadeColor: '#f00000',
80
+ pupilColor: '#c4b0b0', irisColor: '#ff0000', browColor: '#616161',
81
+ depthFade: 1, mouthAnchor: true, eyeAnchor: true,
82
+ },
83
+ },
84
+ B: {
85
+ name: 'low-poly blue',
86
+ renderConfig: {
87
+ meshCols: 7, meshRows: 9, fragment: true, glow: true,
88
+ mouthHole: true, mouthHoleSize: 1.85, eyeHoles: false, eyeDepth: 1,
89
+ scaleNose: 1.15, scaleEyes: 2, scaleMouth: 2,
90
+ lineThickness: 1, lipVertAmp: 1.6,
91
+ pupils: true, irisSize: 2,
92
+ lineColor: '#181616', baseColor: '#7a86c2', fadeColor: '#f00000',
93
+ pupilColor: '#3a2727', irisColor: '#170303',
94
+ depthFade: 0.4, mouthAnchor: true,
95
+ },
96
+ },
97
+ };
98
+
99
+ /* Boot one wireface instance against the canvas. */
100
+ const wf = createWireface(document.getElementById('cv'));
101
+ wf.setLoop(true);
102
+ wf.loadPreset(PRESETS.A);
103
+
104
+ /* Preset switcher. */
105
+ for (const btn of document.querySelectorAll('[data-preset]')) {
106
+ btn.addEventListener('click', () => {
107
+ document.querySelectorAll('[data-preset]').forEach(b => b.classList.remove('on'));
108
+ btn.classList.add('on');
109
+ wf.loadPreset(PRESETS[btn.dataset.preset]);
110
+ });
111
+ }
112
+
113
+ /* Transport. */
114
+ const playBtn = document.getElementById('btn-play');
115
+ const stopBtn = document.getElementById('btn-stop');
116
+ playBtn.addEventListener('click', () => {
117
+ if (wf.isPlaying()) { wf.pause(); playBtn.textContent = '▶ play'; }
118
+ else { wf.play(); playBtn.textContent = '❚❚ pause'; }
119
+ });
120
+ stopBtn.addEventListener('click', () => { wf.stop(); playBtn.textContent = '▶ play'; });
121
+
122
+ /* Drag-drop audio onto the canvas wrap. */
123
+ const wrap = document.getElementById('wrap');
124
+ const audioLabel = document.getElementById('audio-name');
125
+ wrap.addEventListener('dragenter', e => { e.preventDefault(); wrap.classList.add('drag-over'); });
126
+ wrap.addEventListener('dragover', e => { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; });
127
+ wrap.addEventListener('dragleave', e => {
128
+ if (e.target === wrap || !wrap.contains(e.relatedTarget)) wrap.classList.remove('drag-over');
129
+ });
130
+ wrap.addEventListener('drop', async e => {
131
+ e.preventDefault();
132
+ wrap.classList.remove('drag-over');
133
+ const file = e.dataTransfer.files && e.dataTransfer.files[0];
134
+ if (!file) return;
135
+ try {
136
+ await wf.loadAudio(file);
137
+ audioLabel.textContent = file.name;
138
+ } catch (err) {
139
+ audioLabel.textContent = 'decode failed: ' + err.message;
140
+ }
141
+ });
142
+
143
+ /* Expose for console poking. */
144
+ window.wf = wf;
145
+ </script>
146
+ </body>
147
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireface",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
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
@@ -244,6 +244,17 @@
244
244
  /* ── Babylon scene ── */
245
245
  const engine = new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: false, stencil: false, antialias: true });
246
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;
247
258
  scene.clearColor = new BABYLON.Color4(0, 0, 0, 1);
248
259
  // we never pick on pointer-move; saves a per-frame ray test
249
260
  scene.skipPointerMovePicking = true;