wireface 1.1.4 → 1.1.5

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/dist/wireface.js CHANGED
@@ -1367,26 +1367,38 @@
1367
1367
  for (const v of Object.keys(VISEME_PARAMS)) {
1368
1368
  if (v !== 'sil') stateTarget['viseme_' + v] = 0;
1369
1369
  }
1370
- // Heuristic mapping
1371
- if (eSib > 0.35 && eSib > eMid * 0.8) {
1372
- stateTarget.viseme_SS = Math.min(1, eSib * 1.3);
1373
- stateTarget.viseme_FF = Math.min(0.6, eAir * 1.2);
1370
+ // Proportional viseme allocation. v1.1.5: previous version was a
1371
+ // winner-takes-all branch tree where viseme_aa fired for any vowel-
1372
+ // like sound with low+mid energy, dominating with avg ~0.77 on TTS
1373
+ // input and leaving the mouth stuck wide-open. This approach instead
1374
+ // distributes amp across visemes by their corresponding band's share
1375
+ // of total energy, so the mouth shape blends through the audio's
1376
+ // formant spectrum frame-by-frame.
1377
+ const totalE = eLow + eMid + eHi + eSib + 1e-6;
1378
+ // Sibilants — sharp, high-energy fricatives. Boost separately because
1379
+ // they need to register as distinct mouth shapes (close lips + teeth)
1380
+ // even at modest absolute energy.
1381
+ if (eSib > 0.20) {
1382
+ stateTarget.viseme_SS = Math.min(1, eSib * 1.4);
1383
+ if (eAir > 0.20) stateTarget.viseme_FF = Math.min(0.7, eAir * 0.9);
1374
1384
  }
1385
+ // Vowels — proportional distribution across F1/F2 bands.
1386
+ // viseme_O uses low energy when low dominates (back rounded vowel).
1387
+ // viseme_aa uses mid energy (open vowel — F1 mid+low balanced).
1388
+ // viseme_E uses mid energy in front vowel range.
1389
+ // viseme_I uses high energy (high F2 = front close vowel).
1390
+ // viseme_U uses low when low dominates AND amp moderate (closed back).
1391
+ const wLow = eLow / totalE, wMid = eMid / totalE, wHi = eHi / totalE;
1375
1392
  if (eLow > eMid && eLow > 0.18) {
1376
- if (eHi > 0.25) {
1377
- stateTarget.viseme_aa = Math.min(1, eLow * 1.2);
1378
- } else {
1379
- stateTarget.viseme_O = Math.min(1, eLow * 1.2);
1380
- stateTarget.viseme_U = Math.min(0.7, eLow * 0.9);
1381
- }
1382
- } else if (eMid > 0.20) {
1383
- if (eHi > eMid * 0.6) {
1384
- stateTarget.viseme_I = Math.min(1, eHi * 1.4);
1385
- stateTarget.viseme_E = Math.min(0.7, eMid * 1.1);
1386
- } else {
1387
- stateTarget.viseme_E = Math.min(1, eMid * 1.3);
1388
- stateTarget.viseme_aa = Math.min(0.4, eLow * 0.9);
1389
- }
1393
+ // back vowel territory
1394
+ stateTarget.viseme_O = Math.min(1, eLow * 1.1 * (eHi < 0.20 ? 1.1 : 0.8));
1395
+ stateTarget.viseme_aa = Math.min(1, wMid * amp * 1.6);
1396
+ if (eHi < 0.18) stateTarget.viseme_U = Math.min(0.7, eLow * 0.9);
1397
+ } else if (eMid >= eLow * 0.9) {
1398
+ // mid / front vowel territory
1399
+ stateTarget.viseme_aa = Math.min(1, wLow * amp * 1.6);
1400
+ stateTarget.viseme_E = Math.min(1, wMid * amp * 1.4);
1401
+ if (eHi > 0.18) stateTarget.viseme_I = Math.min(1, wHi * amp * 1.5);
1390
1402
  }
1391
1403
  }
1392
1404
 
@@ -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,{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)return;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)}();const e=h.flipFace?Math.PI:0;O.rotation.x=.35*p.headRotateX,O.rotation.y=e+.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)return;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)}();const e=h.flipFace?Math.PI:0;O.rotation.x=.35*p.headRotateX,O.rotation.y=e+.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);const l=e+o+n+i+1e-6;i>.2&&(w.viseme_SS=Math.min(1,1.4*i),r>.2&&(w.viseme_FF=Math.min(.7,.9*r)));const a=e/l,u=o/l,c=n/l;e>o&&e>.18?(w.viseme_O=Math.min(1,1.1*e*(n<.2?1.1:.8)),w.viseme_aa=Math.min(1,u*s*1.6),n<.18&&(w.viseme_U=Math.min(.7,.9*e))):o>=.9*e&&(w.viseme_aa=Math.min(1,a*s*1.6),w.viseme_E=Math.min(1,u*s*1.4),n>.18&&(w.viseme_I=Math.min(1,c*s*1.5)))}(),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);
@@ -33,8 +33,11 @@
33
33
  /* PRESETS — full preset literals exactly as exported by the editor's
34
34
  "save preset → ↓ download" button. Append your own at the end; the UI
35
35
  adapts automatically (←/→ wraps the array). PR yours into
36
- examples/presets/ AND/OR append here so they land on the playground. */
36
+ examples/presets/ AND/OR append here so they land on the playground.
37
+ First two are the loaded-on-init pair. */
37
38
  const PRESETS = [
39
+ {"version":"wireface-v010","createdAt":"2026-05-01T14:17:22.023Z","renderConfig":{"meshCols":17,"meshRows":23,"scaleNose":0.7000000000000001,"scaleEyes":0.45,"scaleMouth":1.1,"reactivity":0.22,"spread":1,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":1.9500000000000002,"eyeHoles":true,"eyeDepth":0,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"8pgwi9","name":"Wireface-001_8pgwi9"},
40
+ {"version":"wireface-v010","createdAt":"2026-05-01T15:13:02.043Z","renderConfig":{"meshCols":9,"meshRows":9,"scaleNose":1.05,"scaleEyes":1.4,"scaleMouth":1.5500000000000003,"reactivity":0.3,"spread":1.6500000000000001,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":0.9500000000000001,"eyeHoles":true,"eyeDepth":3.1500000000000004,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"kln33e","name":"Wireface-001_kln33e"},
38
41
  {"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
42
  {"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
43
  // ← append more here. the UI adapts to whatever length this array is.
@@ -0,0 +1 @@
1
+ {"version":"wireface-v010","createdAt":"2026-05-01T14:17:22.023Z","renderConfig":{"meshCols":17,"meshRows":23,"scaleNose":0.7000000000000001,"scaleEyes":0.45,"scaleMouth":1.1,"reactivity":0.22,"spread":1,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":1.9500000000000002,"eyeHoles":true,"eyeDepth":0,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{"viseme_sil":1,"viseme_PP":1,"viseme_FF":1,"viseme_TH":1,"viseme_DD":1,"viseme_kk":1,"viseme_CH":1,"viseme_SS":1,"viseme_nn":1,"viseme_RR":1,"viseme_aa":1,"viseme_E":1,"viseme_I":1,"viseme_O":1,"viseme_U":1,"jawOpen":1,"mouthSmile":1,"mouthPucker":1,"eyeBlinkLeft":1,"eyeBlinkRight":1,"eyeLookH":1,"eyeLookV":1,"eyeSquint":1,"browInnerUp":1,"browOuterUp":1,"browDown":1,"noseSneer":1,"headRotateX":1,"headRotateY":1,"headRotateZ":1},"channelGainSliders":{"viseme_sil":0,"viseme_PP":0,"viseme_FF":0,"viseme_TH":0,"viseme_DD":0,"viseme_kk":0,"viseme_CH":0,"viseme_SS":0,"viseme_nn":0,"viseme_RR":0,"viseme_aa":0,"viseme_E":0,"viseme_I":0,"viseme_O":0,"viseme_U":0,"jawOpen":0,"mouthSmile":0,"mouthPucker":0,"eyeBlinkLeft":0,"eyeBlinkRight":0,"eyeLookH":0,"eyeLookV":0,"eyeSquint":0,"browInnerUp":0,"browOuterUp":0,"browDown":0,"noseSneer":0,"headRotateX":0,"headRotateY":0,"headRotateZ":0},"activeMood":"neutral","moodTargetWeights":{"neutral":1,"happy":0,"sad":0,"angry":0,"fear":0,"surprise":0,"sleep":0},"audioName":"Wireface-001-kokoro-santa.mp3","lineColor":"#ffffff","pupilColor":"#3e0f0f","id":"8pgwi9","name":"Wireface-001_8pgwi9"}
@@ -0,0 +1 @@
1
+ {"version":"wireface-v010","createdAt":"2026-05-01T15:13:02.043Z","renderConfig":{"meshCols":9,"meshRows":9,"scaleNose":1.05,"scaleEyes":1.4,"scaleMouth":1.5500000000000003,"reactivity":0.3,"spread":1.6500000000000001,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":0.9500000000000001,"eyeHoles":true,"eyeDepth":3.1500000000000004,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{"viseme_sil":1,"viseme_PP":1,"viseme_FF":1,"viseme_TH":1,"viseme_DD":1,"viseme_kk":1,"viseme_CH":1,"viseme_SS":1,"viseme_nn":1,"viseme_RR":1,"viseme_aa":1,"viseme_E":1,"viseme_I":1,"viseme_O":1,"viseme_U":1,"jawOpen":1,"mouthSmile":1,"mouthPucker":1,"eyeBlinkLeft":1,"eyeBlinkRight":1,"eyeLookH":1,"eyeLookV":1,"eyeSquint":1,"browInnerUp":1,"browOuterUp":1,"browDown":1,"noseSneer":1,"headRotateX":1,"headRotateY":1,"headRotateZ":1},"channelGainSliders":{"viseme_sil":0,"viseme_PP":0,"viseme_FF":0,"viseme_TH":0,"viseme_DD":0,"viseme_kk":0,"viseme_CH":0,"viseme_SS":0,"viseme_nn":0,"viseme_RR":0,"viseme_aa":0,"viseme_E":0,"viseme_I":0,"viseme_O":0,"viseme_U":0,"jawOpen":0,"mouthSmile":0,"mouthPucker":0,"eyeBlinkLeft":0,"eyeBlinkRight":0,"eyeLookH":0,"eyeLookV":0,"eyeSquint":0,"browInnerUp":0,"browOuterUp":0,"browDown":0,"noseSneer":0,"headRotateX":0,"headRotateY":0,"headRotateZ":0},"activeMood":"neutral","moodTargetWeights":{"neutral":1,"happy":0,"sad":0,"angry":0,"fear":0,"surprise":0,"sleep":0},"audioName":"Wireface-001-kokoro-santa.mp3","lineColor":"#ffffff","pupilColor":"#3e0f0f","id":"kln33e","name":"Wireface-001_kln33e"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireface",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
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
@@ -1367,26 +1367,38 @@
1367
1367
  for (const v of Object.keys(VISEME_PARAMS)) {
1368
1368
  if (v !== 'sil') stateTarget['viseme_' + v] = 0;
1369
1369
  }
1370
- // Heuristic mapping
1371
- if (eSib > 0.35 && eSib > eMid * 0.8) {
1372
- stateTarget.viseme_SS = Math.min(1, eSib * 1.3);
1373
- stateTarget.viseme_FF = Math.min(0.6, eAir * 1.2);
1370
+ // Proportional viseme allocation. v1.1.5: previous version was a
1371
+ // winner-takes-all branch tree where viseme_aa fired for any vowel-
1372
+ // like sound with low+mid energy, dominating with avg ~0.77 on TTS
1373
+ // input and leaving the mouth stuck wide-open. This approach instead
1374
+ // distributes amp across visemes by their corresponding band's share
1375
+ // of total energy, so the mouth shape blends through the audio's
1376
+ // formant spectrum frame-by-frame.
1377
+ const totalE = eLow + eMid + eHi + eSib + 1e-6;
1378
+ // Sibilants — sharp, high-energy fricatives. Boost separately because
1379
+ // they need to register as distinct mouth shapes (close lips + teeth)
1380
+ // even at modest absolute energy.
1381
+ if (eSib > 0.20) {
1382
+ stateTarget.viseme_SS = Math.min(1, eSib * 1.4);
1383
+ if (eAir > 0.20) stateTarget.viseme_FF = Math.min(0.7, eAir * 0.9);
1374
1384
  }
1385
+ // Vowels — proportional distribution across F1/F2 bands.
1386
+ // viseme_O uses low energy when low dominates (back rounded vowel).
1387
+ // viseme_aa uses mid energy (open vowel — F1 mid+low balanced).
1388
+ // viseme_E uses mid energy in front vowel range.
1389
+ // viseme_I uses high energy (high F2 = front close vowel).
1390
+ // viseme_U uses low when low dominates AND amp moderate (closed back).
1391
+ const wLow = eLow / totalE, wMid = eMid / totalE, wHi = eHi / totalE;
1375
1392
  if (eLow > eMid && eLow > 0.18) {
1376
- if (eHi > 0.25) {
1377
- stateTarget.viseme_aa = Math.min(1, eLow * 1.2);
1378
- } else {
1379
- stateTarget.viseme_O = Math.min(1, eLow * 1.2);
1380
- stateTarget.viseme_U = Math.min(0.7, eLow * 0.9);
1381
- }
1382
- } else if (eMid > 0.20) {
1383
- if (eHi > eMid * 0.6) {
1384
- stateTarget.viseme_I = Math.min(1, eHi * 1.4);
1385
- stateTarget.viseme_E = Math.min(0.7, eMid * 1.1);
1386
- } else {
1387
- stateTarget.viseme_E = Math.min(1, eMid * 1.3);
1388
- stateTarget.viseme_aa = Math.min(0.4, eLow * 0.9);
1389
- }
1393
+ // back vowel territory
1394
+ stateTarget.viseme_O = Math.min(1, eLow * 1.1 * (eHi < 0.20 ? 1.1 : 0.8));
1395
+ stateTarget.viseme_aa = Math.min(1, wMid * amp * 1.6);
1396
+ if (eHi < 0.18) stateTarget.viseme_U = Math.min(0.7, eLow * 0.9);
1397
+ } else if (eMid >= eLow * 0.9) {
1398
+ // mid / front vowel territory
1399
+ stateTarget.viseme_aa = Math.min(1, wLow * amp * 1.6);
1400
+ stateTarget.viseme_E = Math.min(1, wMid * amp * 1.4);
1401
+ if (eHi > 0.18) stateTarget.viseme_I = Math.min(1, wHi * amp * 1.5);
1390
1402
  }
1391
1403
  }
1392
1404