wireface 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/wireface.js CHANGED
@@ -285,36 +285,58 @@
285
285
  const minimalGroup = new BABYLON.TransformNode('minimal', scene);
286
286
  minimalGroup.parent = faceRoot;
287
287
 
288
- /* ─── 4a. parametric warp (u,v) → 3D face surface ─── */
288
+ /* ─── 4a. parametric warp: grid (u,v) → face surface (x,y,z) ───
289
+ Ported verbatim from the v011 editor. Uses an elliptical taper so the
290
+ silhouette is oval, not rectangular. Then layers feature bumps (eye
291
+ sockets, brow ridge, nose, mouth, cheeks) as gaussian falloffs in
292
+ xRel/yRel space (xRel = (u-0.5)*2, yRel = (0.5-v)*2). This shape's
293
+ z-range (≈0.10..0.30) is what lets depthFade produce a visible
294
+ gradient instead of pinning the silhouette to black. */
289
295
  function warpToFace(u, v) {
290
- const xRel = (u - 0.5) * 2;
291
- const yRel = (0.5 - v) * 2;
296
+ const xRel = (u - 0.5) * 2; // -1..1 left to right
297
+ const yRel = (0.5 - v) * 2; // 1..-1 top to bottom
298
+
299
+ // strong elliptical taper — boundary of the grid maps to an oval
292
300
  const yNorm = yRel * 0.95;
293
301
  const ovalT = Math.max(0, 1 - yNorm * yNorm);
294
- const x = xRel * Math.sqrt(ovalT) * 0.80;
295
- const y = yRel * 0.95;
296
- let z = (Math.cos(xRel * Math.PI * 0.5)) * (Math.cos(yRel * Math.PI * 0.5)) * 0.18;
297
- // nose ridge
298
- const nU = 0.50, nV = 0.50;
299
- const dn = Math.hypot((u-nU), (v-nV)) / 0.16;
300
- if (dn < 1.6) z += (1 - Math.min(1, dn)) * 0.085;
301
- // brow ridge
302
- const dbL = Math.hypot((u-0.30), (v-0.27)) / 0.10;
303
- const dbR = Math.hypot((u-0.70), (v-0.27)) / 0.10;
304
- if (dbL < 1.6) z += (1 - Math.min(1, dbL)) * 0.020;
305
- if (dbR < 1.6) z += (1 - Math.min(1, dbR)) * 0.020;
306
- // eye sockets recess
307
- const deL = Math.hypot((u-0.30)/0.085, (v-0.40)/0.045);
308
- const deR = Math.hypot((u-0.70)/0.085, (v-0.40)/0.045);
309
- if (deL < 1.5) z -= (1 - Math.min(1, deL)) * 0.030 * config.eyeDepth;
310
- if (deR < 1.5) z -= (1 - Math.min(1, deR)) * 0.030 * config.eyeDepth;
311
- // chin protrusion
312
- if (v > 0.85) z += (v - 0.85) * 0.6 * 0.10 * Math.max(0, 1 - Math.abs(xRel) * 1.2);
313
- // cheek bulge
314
- const cheekL = Math.hypot((u-0.22)/0.10, (v-0.62)/0.08);
315
- const cheekR = Math.hypot((u-0.78)/0.10, (v-0.62)/0.08);
316
- if (cheekL < 1.6) z += (1 - Math.min(1, cheekL)) * 0.018;
317
- if (cheekR < 1.6) z += (1 - Math.min(1, cheekR)) * 0.018;
302
+ const widthAtY = Math.sqrt(ovalT) * 0.80;
303
+ let x = xRel * widthAtY;
304
+
305
+ // y stays linear; chin extends + forehead squashes
306
+ let y = yRel * 1.0;
307
+ if (yRel < -0.4) y = -0.4 + (yRel + 0.4) * 1.55;
308
+ if (yRel > 0.7) y = 0.7 + (yRel - 0.7) * 0.45;
309
+
310
+ // base z bulge — quadratic falloff from center
311
+ let z = (1 - xRel*xRel * 0.55 - yRel*yRel * 0.55) * 0.22;
312
+ if (z < -0.05) z = -0.05;
313
+
314
+ // eye sockets recess (gaussian — broad and bowl-shaped)
315
+ const eyeY = 0.30;
316
+ const eyeL_d = ((xRel + 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
317
+ const eyeR_d = ((xRel - 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
318
+ const eyeRecess = 0.045 * config.eyeDepth;
319
+ z -= eyeRecess * Math.exp(-eyeL_d);
320
+ z -= eyeRecess * Math.exp(-eyeR_d);
321
+
322
+ // brow ridge bumps forward
323
+ const brow_d = (xRel / 0.7) ** 2 + ((yRel - 0.55) / 0.10) ** 2;
324
+ z += 0.045 * Math.exp(-brow_d);
325
+
326
+ // nose — the dominant z bump
327
+ const nose_d = (xRel / 0.18) ** 2 + ((yRel - 0.05) / 0.40) ** 2;
328
+ z += 0.22 * Math.exp(-nose_d);
329
+
330
+ // mouth area pushed slightly forward
331
+ const mouth_d = (xRel / 0.55) ** 2 + ((yRel + 0.45) / 0.20) ** 2;
332
+ z += 0.06 * Math.exp(-mouth_d);
333
+
334
+ // cheekbones
335
+ const cheekL_d = ((xRel + 0.55) / 0.30) ** 2 + ((yRel - 0.05) / 0.28) ** 2;
336
+ const cheekR_d = ((xRel - 0.55) / 0.30) ** 2 + ((yRel - 0.05) / 0.28) ** 2;
337
+ z += 0.04 * Math.exp(-cheekL_d);
338
+ z += 0.04 * Math.exp(-cheekR_d);
339
+
318
340
  return V(x, y, z);
319
341
  }
320
342
 
@@ -585,9 +607,9 @@
585
607
  const spread = config.spread;
586
608
  const p = computeMouthParams();
587
609
  // mouth
588
- applyShape(disp, SHAPES.mouth_jaw_drop, p.jaw, spread);
589
- applyShape(disp, SHAPES.mouth_open_lower, p.open, spread);
590
- applyShape(disp, SHAPES.mouth_open_upper, p.open, spread);
610
+ applyShape(disp, SHAPES.mouth_jaw_drop, p.jaw, spread);
611
+ applyShape(disp, SHAPES.mouth_open_lower, p.open, spread);
612
+ applyShape(disp, SHAPES.mouth_open_upper, p.open * 0.4, spread);
591
613
  const sm = p.smile;
592
614
  if (sm > 0) { applyShape(disp, SHAPES.mouth_smile_L, sm, spread); applyShape(disp, SHAPES.mouth_smile_R, sm, spread); }
593
615
  else if (sm < 0) { applyShape(disp, SHAPES.mouth_frown_L, -sm, spread); applyShape(disp, SHAPES.mouth_frown_R, -sm, spread); }
@@ -611,10 +633,16 @@
611
633
  // brows
612
634
  applyShape(disp, SHAPES.brow_inner_L, state.browInnerUp, spread);
613
635
  applyShape(disp, SHAPES.brow_inner_R, state.browInnerUp, spread);
614
- applyShape(disp, SHAPES.brow_outer_L, Math.max(0, state.browOuterUp), spread);
615
- applyShape(disp, SHAPES.brow_outer_R, Math.max(0, state.browOuterUp), spread);
616
- applyShape(disp, SHAPES.brow_down_L, state.browDown + Math.max(0,-state.browOuterUp), spread);
617
- applyShape(disp, SHAPES.brow_down_R, state.browDown + Math.max(0,-state.browOuterUp), spread);
636
+ // v011: browOuterUp >= 0 lifts outer brow; < 0 drives brow_down at 0.6x
637
+ if (state.browOuterUp >= 0) {
638
+ applyShape(disp, SHAPES.brow_outer_L, state.browOuterUp, spread);
639
+ applyShape(disp, SHAPES.brow_outer_R, state.browOuterUp, spread);
640
+ } else {
641
+ applyShape(disp, SHAPES.brow_down_L, -state.browOuterUp * 0.6, spread);
642
+ applyShape(disp, SHAPES.brow_down_R, -state.browOuterUp * 0.6, spread);
643
+ }
644
+ applyShape(disp, SHAPES.brow_down_L, state.browDown, spread);
645
+ applyShape(disp, SHAPES.brow_down_R, state.browDown, spread);
618
646
  // nose
619
647
  applyShape(disp, SHAPES.nose_sneer_L, state.noseSneer, spread);
620
648
  applyShape(disp, SHAPES.nose_sneer_R, state.noseSneer, spread);
@@ -1 +1 @@
1
- !function(e){"use strict";const o={viseme_sil:{range:[0,1],def:1},viseme_PP:{range:[0,1],def:0},viseme_FF:{range:[0,1],def:0},viseme_TH:{range:[0,1],def:0},viseme_DD:{range:[0,1],def:0},viseme_kk:{range:[0,1],def:0},viseme_CH:{range:[0,1],def:0},viseme_SS:{range:[0,1],def:0},viseme_nn:{range:[0,1],def:0},viseme_RR:{range:[0,1],def:0},viseme_aa:{range:[0,1],def:0},viseme_E:{range:[0,1],def:0},viseme_I:{range:[0,1],def:0},viseme_O:{range:[0,1],def:0},viseme_U:{range:[0,1],def:0},jawOpen:{range:[0,1],def:0},mouthSmile:{range:[-1,1],def:0},mouthPucker:{range:[0,1],def:0},eyeBlinkLeft:{range:[0,1],def:0},eyeBlinkRight:{range:[0,1],def:0},eyeLookH:{range:[-1,1],def:0},eyeLookV:{range:[-1,1],def:0},eyeSquint:{range:[0,1],def:0},browInnerUp:{range:[0,1],def:0},browOuterUp:{range:[-1,1],def:0},browDown:{range:[0,1],def:0},noseSneer:{range:[0,1],def:0},headRotateX:{range:[-1,1],def:0},headRotateY:{range:[-1,1],def:0},headRotateZ:{range:[-1,1],def:0}},t=Object.keys(o),n={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},r={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},i=Object.keys(r),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],a={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(n).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},l={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeHoleSize:1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,cameraView:"three-q"};function d(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function h(e,h){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const c=Object.assign({},u,h||{}),f=(e,o,t)=>new BABYLON.Vector3(e,o,t),m={};for(const e of Object.keys(l)){const o=l[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};t.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const g={},v={};for(const e of i)g[e]=0,v[e]=0;g.neutral=1,v.neutral=1;let B="neutral";const b=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),M=new BABYLON.Scene(b);M.clearColor=new BABYLON.Color4(0,0,0,1),M.skipPointerMovePicking=!0;const x=new BABYLON.GlowLayer("glow",M,{mainTextureFixedSize:1024,blurKernelSize:32});x.intensity=0;const L=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),M);L.minZ=.1,L.maxZ=100,L.lowerRadiusLimit=1.5,L.upperRadiusLimit=12,L.wheelDeltaPercentage=.01;const C=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}L.attachControl(e,!0);try{navigator.getGamepads=C}catch(e){}const O=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),M);O.intensity=.9,O.groundColor=new BABYLON.Color3(.1,.1,.14);const z=new BABYLON.TransformNode("faceRoot",M),R=new BABYLON.StandardMaterial("faceMat",M);R.diffuseColor=new BABYLON.Color3(.05,.05,.07),R.emissiveColor=new BABYLON.Color3(.012,.012,.02),R.specularColor=new BABYLON.Color3(.2,.22,.28),R.specularPower=48,R.backFaceCulling=!1,R.useVertexColor=!0;const A=new BABYLON.StandardMaterial("wireMat",M);A.emissiveColor=new BABYLON.Color3(1,1,1),A.disableLighting=!0,A.wireframe=!0,A.backFaceCulling=!1,A.alpha=1,A.useVertexColor=!0;const k=new BABYLON.StandardMaterial("minimalMat",M);k.emissiveColor=new BABYLON.Color3(1,1,1),k.disableLighting=!0,k.specularColor=new BABYLON.Color3(0,0,0);const S=new BABYLON.StandardMaterial("browMat",M);S.emissiveColor=new BABYLON.Color3(1,1,1),S.disableLighting=!0,S.specularColor=new BABYLON.Color3(0,0,0);const N=new BABYLON.TransformNode("minimal",M);function P(e,o){const t=2*(e-.5),n=2*(.5-o),r=.95*n,i=Math.max(0,1-r*r),s=t*Math.sqrt(i)*.8,a=.95*n;let l=Math.cos(t*Math.PI*.5)*Math.cos(n*Math.PI*.5)*.18;const u=Math.hypot(e-.5,o-.5)/.16;u<1.6&&(l+=.085*(1-Math.min(1,u)));const d=Math.hypot(e-.3,o-.27)/.1,h=Math.hypot(e-.7,o-.27)/.1;d<1.6&&(l+=.02*(1-Math.min(1,d))),h<1.6&&(l+=.02*(1-Math.min(1,h)));const m=Math.hypot((e-.3)/.085,(o-.4)/.045),p=Math.hypot((e-.7)/.085,(o-.4)/.045);m<1.5&&(l-=.03*(1-Math.min(1,m))*c.eyeDepth),p<1.5&&(l-=.03*(1-Math.min(1,p))*c.eyeDepth),o>.85&&(l+=.6*(o-.85)*.1*Math.max(0,1-1.2*Math.abs(t)));const w=Math.hypot((e-.22)/.1,(o-.62)/.08),y=Math.hypot((e-.78)/.1,(o-.62)/.08);return w<1.6&&(l+=.018*(1-Math.min(1,w))),y<1.6&&(l+=.018*(1-Math.min(1,y))),f(s,a,l)}N.parent=z;const Y=P(.5,.69);function j(e,o,t){const n=Y.x,r=Y.y,i=Y.z,s=.27*(1+.4*t.width)*(1-.4*t.round),a=c.lipVertAmp,l=c.lipPressForce,u=.16*t.open*a,d=.012*t.lipPress*a*l,h=.09*t.jaw*a,m=.05*t.smile,p=.07*t.round,w=.007*(1-.55*t.lipPress),y=.022*(1-.55*t.lipPress);let _;if(o){const e=r+u/2-d+.4*m;_=[[-1,r+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,r+m,.5*-p]]}else{const e=r-u/2+d-h;_=[[-1,r+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,r+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let g=0;for(;g<_.length-1&&e>_[g+1][0];)g++;g=Math.min(g,_.length-2);const v=(e-_[g][0])/(_[g+1][0]-_[g][0]),B=_[g][1]*(1-v)+_[g+1][1]*v,b=_[g][2]*(1-v)+_[g+1][2]*v;return f(n+e*s,B,i+b)}function H(e,o,t,n,r){const i=(e+1)/2*Math.PI,s=t.center.x+Math.cos(Math.PI-i)*t.hw,a=.012*r,l=(t.center.y+(o?1:-1)*Math.sin(i)*t.hh)*(1-n)+t.center.y*n+(o?-a:.5*a),u=t.center.z+.018+.012*Math.sin(i);return f(s,l,u)}function V(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const t of Object.keys(n)){const r=p["viseme_"+t]||0;if(r<=0)continue;e+=r;const i=n[t];o.open+=i.open*r,o.width+=i.width*r,o.round+=i.round*r,o.smile+=i.smile*r,o.lipPress+=i.lipPress*r,o.jaw+=i.jaw*r}if(e>1){const t=1/e;o.open*=t,o.width*=t,o.round*=t,o.smile*=t,o.lipPress*=t,o.jaw*=t}o.smile+=p.mouthSmile;const t=p.mouthPucker;return o.round+=.7*t,o.width+=.4*-t,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let D=null,U=[],T=[],I=[],F=[],q=null,E=null,G=null,Z=null,K=0,X=0,W=[1,1,1],J=[0,0,0],Q=!1,$=[],ee=[];const oe={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function te(){D&&(D.dispose(),D=null);const e=c.meshCols,o=c.meshRows;U=[],T=[],I=[];for(let t=0;t<o;t++)for(let n=0;n<e;n++){const r=n/(e-1),i=t/(o-1);T.push({u:r,v:i}),U.push(P(r,i))}const t=e=>{if(!c.fragment)return!0;const o=2*(T[e].u-.5),t=2*(.5-T[e].v);return o*o*1.2+t*t*.95<1},n=(e,o,n)=>{((e,o,n)=>{if(!t(e)||!t(o)||!t(n))return!1;if(c.mouthHole){const t=.5,r=.69,i=.18*c.mouthHoleSize,s=.075*c.mouthHoleSize,a=((T[e].u+T[o].u+T[n].u)/3-t)/i,l=((T[e].v+T[o].v+T[n].v)/3-r)/s;if(a*a+l*l<1)return!1}if(c.eyeHoles){const t=.105*c.eyeHoleSize,r=.075*c.eyeHoleSize,i=(T[e].u+T[o].u+T[n].u)/3,s=(T[e].v+T[o].v+T[n].v)/3;if(((i-.3)/t)**2+((s-.4)/r)**2<1||((i-.7)/t)**2+((s-.4)/r)**2<1)return!1}return!0})(e,o,n)&&I.push(e,o,n)};for(let t=0;t<o-1;t++)for(let o=0;o<e-1;o++){const r=t*e+o,i=t*e+(o+1),s=(t+1)*e+o,a=(t+1)*e+(o+1);(t+o)%2==0?(n(r,i,a),n(r,a,s)):(n(r,i,s),n(i,a,s))}F=function(e,o){const t=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const n=e[o],r=e[o+1],i=e[o+2];t[n].add(r),t[n].add(i),t[r].add(n),t[r].add(i),t[i].add(n),t[i].add(r)}return t.map(e=>Array.from(e))}(I,U.length),D=new BABYLON.Mesh("face",M),D.parent=z;const r=U.length;E=new Float32Array(3*r),G=new Float32Array(3*r),Z=new Float32Array(4*r),q=new Array(r),K=1/0,X=-1/0;for(let e=0;e<r;e++)E[3*e]=U[e].x,E[3*e+1]=U[e].y,E[3*e+2]=U[e].z,U[e].z<K&&(K=U[e].z),U[e].z>X&&(X=U[e].z),q[e]=f(0,0,0),Z[4*e]=1,Z[4*e+1]=1,Z[4*e+2]=1,Z[4*e+3]=1;BABYLON.VertexData.ComputeNormals(E,I,G);const i=new BABYLON.VertexData;i.positions=Array.from(E),i.indices=I,i.normals=Array.from(G),i.colors=Array.from(Z),i.applyToMesh(D,!0),ue(),se(),ae(),ne(),Q=!0}function ne(){$=[],ee=[];const e=.18*c.mouthHoleSize,o=.075*c.mouthHoleSize;for(let t=0;t<T.length;t++){const n=(T[t].u-.5)/e,r=(T[t].v-.69)/o,i=n*n+r*r;if(i<4){const e=T[t].v<.69,o=Math.max(-1,Math.min(1,n));let r=i<=1?i:(4-i)/3;r=Math.max(0,Math.min(1,r)),$.push({idx:t,isUpper:e,xRel:o,weight:r,baselineTarget:j(o,e,oe)})}}const t=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of t)for(let o=0;o<T.length;o++){const t=(T[o].u-e.cu)/e.ru,n=(T[o].v-e.cv)/e.rv,r=t*t+n*n;if(r<4){const n=T[o].v<e.cv,i=Math.max(-1,Math.min(1,t));let s=r<=1?r:(4-r)/3;s=Math.max(0,Math.min(1,s));const a=P(e.cu,e.cv);ee.push({idx:o,side:e.side,isUpper:n,xRel:i,weight:s,eyeDef:{center:a,hw:e.hw,hh:e.hh},baselineTarget:H(i,n,{center:a,hw:e.hw,hh:e.hh},0,0)})}}}function re(e,o,t,n){if(Math.abs(t)<.001)return;const r=o.uv[0],i=o.uv[1],s=o.radius*n,a=s*s,l=o.dir.x*t,u=o.dir.y*t,d=o.dir.z*t;for(let o=0;o<T.length;o++){const t=T[o].u-r,n=T[o].v-i,s=t*t+n*n;if(s>4*a)continue;const h=Math.exp(-s/a);e[o].x+=l*h,e[o].y+=u*h,e[o].z+=d*h}}const ie=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return c.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return c.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return c.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return c.scaleMouth}}];function se(){z&&(z.rotation.y=c.flipFace?Math.PI:0)}function ae(){D&&(D.isVisible=!!c.meshVisible)}function le(){N&&N.getChildMeshes().forEach(e=>e.isVisible=!!c.minimal)}function ue(){if(!D)return;D._edgesRenderer&&D.disableEdgesRendering();const e=c.lineThickness;switch(c.mode){case"wire":D.material=A,A.wireframe=!0,A.alpha=1;break;case"edges":D.material=R,R.alpha=1,R.wireframe=!1,D.enableEdgesRendering(.9999),D.edgesWidth=4*e,D.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1);break;case"shaded":D.material=R,R.alpha=1,R.wireframe=!1}}let de=null,he=null,ce=null,fe=null,me=null,pe=null;function we(){if(he&&(he.dispose(),he=null),ce&&(ce.dispose(),ce=null),me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),!c.pupils)return;de||(de=new BABYLON.StandardMaterial("pupilMat",M),de.emissiveColor=BABYLON.Color3.FromHexString(c.pupilColor),de.disableLighting=!0,de.backFaceCulling=!1),fe||(fe=new BABYLON.StandardMaterial("irisMat",M),fe.emissiveColor=BABYLON.Color3.FromHexString(c.irisColor),fe.disableLighting=!0,fe.backFaceCulling=!1);const e=.035*c.irisSize;me=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},M),pe=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},M),me.material=pe.material=fe,me.parent=pe.parent=z,he=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},M),ce=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},M),he.material=ce.material=de,he.parent=ce.parent=z}function ye(e,o){const t=P(e,o);if(!c.overlayTracksMesh)return t;const n=function(e,o){if(!q)return f(0,0,0);const t=.0036;let n=0,r=0,i=0,s=0;for(let a=0;a<T.length;a++){const l=T[a].u-e,u=T[a].v-o,d=l*l+u*u;if(d<t){const e=1-Math.sqrt(d/t);n+=e,r+=q[a].x*e,i+=q[a].y*e,s+=q[a].z*e}}return 0===n?f(0,0,0):f(r/n,i/n,s/n)}(e,o);return f(t.x+n.x,t.y+n.y,t.z+n.z)}function _e(e,o=18){const t=[],n=e.length,r=o=>e[Math.max(0,Math.min(n-1,o))];for(let e=0;e<n-1;e++){const n=r(e-1),i=r(e),s=r(e+1),a=r(e+2);for(let e=0;e<o;e++){const r=e/o,l=r*r,u=r*l,d=.5*(2*i.x+(-n.x+s.x)*r+(2*n.x-5*i.x+4*s.x-a.x)*l+(-n.x+3*i.x-3*s.x+a.x)*u),h=.5*(2*i.y+(-n.y+s.y)*r+(2*n.y-5*i.y+4*s.y-a.y)*l+(-n.y+3*i.y-3*s.y+a.y)*u),c=.5*(2*i.z+(-n.z+s.z)*r+(2*n.z-5*i.z+4*s.z-a.z)*l+(-n.z+3*i.z-3*s.z+a.z)*u);t.push(f(d,h,c))}}return t.push(e[n-1]),t}function ge(e,o,t,n){const r={path:o,radius:n?t:t*c.lineThickness,tessellation:6,updatable:!0};n&&(r.instance=n);const i=BABYLON.MeshBuilder.CreateTube(e,r,M);return n||(i.material=k,i.parent=N),i}let ve=null,Be=null;function be(){const e=V();return{upper:_e([-1,-.45,0,.45,1].map(o=>j(o,!0,e)),18),lower:_e([-1,-.5,0,.5,1].map(o=>j(o,!1,e)),18)}}const Me=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let xe=[];function Le(e,o){const t="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,n=p.eyeSquint,r=ye(e.uv[0],e.uv[1]),i=[],s=.012*n;for(let n=0;n<=12;n++){const a=n/12*Math.PI,l=r.x+Math.cos(Math.PI-a)*e.hw,u=(r.y+(o?1:-1)*Math.sin(a)*e.hh)*(1-t)+r.y*t+(o?-s:.5*s),d=r.z+.018+.012*Math.sin(a);i.push(f(l,u,d))}return i}const Ce=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Oe=[];function ze(e){const o=ye(e.uv[0],e.uv[1]),t="L"===e.side?-1:1,n=.085*p.browInnerUp-.05*p.browDown,r=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,i=o.x+-.1*t,s=o.x,a=o.x+.1*t,l=o.y+n,u=o.y+.5*(n+r)+.005,d=o.y+r-.005,h=o.z+.018;return _e([f(i,l,h),f(s,u,h+.01),f(a,d,h)],12)}let Re=null,Ae=null,ke=null;function Se(){const e=.025*p.noseSneer,o=ye(.5,.4),t=ye(.5,.55),n=_e([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+t.y),.5*(o.z+t.z)+.05),f(t.x,t.y+.03,t.z+.05)],14),r=t.y+.01;return{bridge:n,leftN:_e([f(t.x,r,t.z+.05),f(t.x-.06-e,r-.03,t.z+.02),f(t.x-.04,r-.05,t.z+.005),f(t.x-.01,r-.02,t.z+.03)],10),rightN:_e([f(t.x,r,t.z+.05),f(t.x+.06+e,r-.03,t.z+.02),f(t.x+.04,r-.05,t.z+.005),f(t.x+.01,r-.02,t.z+.03)],10)}}function Ne(){ve&&(ve.dispose(),ve=null),Be&&(Be.dispose(),Be=null);for(const e of xe)e.upper.dispose(),e.lower.dispose();xe=[];for(const e of Oe)e.mesh.dispose();Oe=[],Re&&(Re.dispose(),Re=null),Ae&&(Ae.dispose(),Ae=null),ke&&(ke.dispose(),ke=null);const{upper:e,lower:o}=be();ve=ge("mouth_u",e,.01),Be=ge("mouth_l",o,.01);for(const e of Me){const o=ge("eye_"+e.side+"_u",Le(e,!0),.0085),t=ge("eye_"+e.side+"_l",Le(e,!1),.0085);xe.push({eye:e,upper:o,lower:t})}for(const e of Ce){const o=ge("brow_"+e.side,ze(e),.011);o.material=S,Oe.push({brow:e,mesh:o})}const t=Se();Re=ge("nose_b",t.bridge,.009),Ae=ge("nose_l",t.leftN,.0085),ke=ge("nose_r",t.rightN,.0085),le()}const Pe={};function Ye(){if(D){for(let e=0;e<t.length;e++){const o=t[e];Pe[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<q.length;e++)q[e].x=q[e].y=q[e].z=0;!function(e){const o=c.spread,t=V();re(e,m.mouth_jaw_drop,t.jaw,o),re(e,m.mouth_open_lower,t.open,o),re(e,m.mouth_open_upper,t.open,o);const n=t.smile;n>0?(re(e,m.mouth_smile_L,n,o),re(e,m.mouth_smile_R,n,o)):n<0&&(re(e,m.mouth_frown_L,-n,o),re(e,m.mouth_frown_R,-n,o)),re(e,m.mouth_round_L,t.round,o),re(e,m.mouth_round_R,t.round,o),re(e,m.mouth_round_top,t.round,o),re(e,m.mouth_round_bot,t.round,o),re(e,m.mouth_press_top,t.lipPress,o),re(e,m.mouth_press_bot,t.lipPress,o),t.width>0&&(re(e,m.mouth_width_L,t.width,o),re(e,m.mouth_width_R,t.width,o)),re(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),re(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),re(e,m.eye_blink_R_up,p.eyeBlinkRight,o),re(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),re(e,m.eye_squint_L,p.eyeSquint,o),re(e,m.eye_squint_R,p.eyeSquint,o),re(e,m.brow_inner_L,p.browInnerUp,o),re(e,m.brow_inner_R,p.browInnerUp,o),re(e,m.brow_outer_L,Math.max(0,p.browOuterUp),o),re(e,m.brow_outer_R,Math.max(0,p.browOuterUp),o),re(e,m.brow_down_L,p.browDown+Math.max(0,-p.browOuterUp),o),re(e,m.brow_down_R,p.browDown+Math.max(0,-p.browOuterUp),o),re(e,m.nose_sneer_L,p.noseSneer,o),re(e,m.nose_sneer_R,p.noseSneer,o)}(q),c.reactivity>0&&function(e,o){if(o<=0)return;const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const t=F[r];if(0===t.length){n[r]=f(e[r].x,e[r].y,e[r].z);continue}let i=0,s=0,a=0;for(const o of t)i+=e[o].x,s+=e[o].y,a+=e[o].z;i/=t.length,s/=t.length,a/=t.length,n[r]=f(e[r].x*(1-o)+i*o,e[r].y*(1-o)+s*o,e[r].z*(1-o)+a*o)}for(let o=0;o<t;o++)e[o].x=n[o].x,e[o].y=n[o].y,e[o].z=n[o].z}(q,c.reactivity),function(e){for(const o of ie){const t=o.scale;if(Math.abs(t-1)<.001)continue;const n=P(o.uv[0],o.uv[1]),r=o.radiusUV*o.radiusUV,i=4*r;for(let s=0;s<T.length;s++){const a=T[s].u-o.uv[0],l=T[s].v-o.uv[1],u=a*a+l*l;if(u>i)continue;const d=Math.exp(-u/r),h=U[s].x-n.x,c=U[s].y-n.y,f=U[s].z-n.z,m=(t-1)*d;e[s].x+=h*m,e[s].y+=c*m,e[s].z+=f*m}}}(q),function(e){const o=c.jawExtend;if(o<.001)return;const t=p.jawOpen||0;if(t<.001)return;const n=t*o*.1;for(let o=0;o<T.length;o++){const t=T[o].v;if(t<.55)continue;const r=Math.min(1,(t-.55)/.45);e[o].z+=n*r}}(q),function(e){const o=c.mouthGrow;if(o<.001)return;const t=V().open;if(t<.001)return;const n=t*o,r=.0625;for(let o=0;o<T.length;o++){const t=T[o].u-.5,i=T[o].v-.69,s=t*t+i*i;if(s>r)continue;const a=1-Math.sqrt(s/r),l=U[o];e[o].x+=(l.x-Y.x)*n*a*.4,e[o].y+=(l.y-Y.y)*n*a*.4,e[o].z+=n*a*.05}}(q),function(e){if(!c.mouthAnchor)return;const o=V();for(const t of $){const n=j(t.xRel,t.isUpper,o),r=n.x-t.baselineTarget.x,i=n.y-t.baselineTarget.y,s=n.z-t.baselineTarget.z,a=t.weight;e[t.idx].x=e[t.idx].x*(1-a)+r*a,e[t.idx].y=e[t.idx].y*(1-a)+i*a,e[t.idx].z=e[t.idx].z*(1-a)+s*a}}(q),function(e){if(!c.eyeAnchor)return;const o=p.eyeBlinkLeft,t=p.eyeBlinkRight,n=p.eyeSquint;for(const r of ee){const i="L"===r.side?o:t,s=H(r.xRel,r.isUpper,r.eyeDef,i,n),a=s.x-r.baselineTarget.x,l=s.y-r.baselineTarget.y,u=s.z-r.baselineTarget.z,d=r.weight;e[r.idx].x=e[r.idx].x*(1-d)+a*d,e[r.idx].y=e[r.idx].y*(1-d)+l*d,e[r.idx].z=e[r.idx].z*(1-d)+u*d}}(q);for(let e=0;e<U.length;e++)E[3*e]=U[e].x+q[e].x,E[3*e+1]=U[e].y+q[e].y,E[3*e+2]=U[e].z+q[e].z;if(D.updateVerticesData(BABYLON.VertexBuffer.PositionKind,E),c.depthFade>.001){const e=X-K||1,o=c.depthFade;for(let t=0;t<U.length;t++){const n=E[3*t+2],r=Math.max(0,Math.min(1,(X-n)/e))*o;Z[4*t]=W[0]*(1-r)+J[0]*r,Z[4*t+1]=W[1]*(1-r)+J[1]*r,Z[4*t+2]=W[2]*(1-r)+J[2]*r,Z[4*t+3]=1}D.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z)}else if(Q){for(let e=0;e<U.length;e++)Z[4*e]=W[0],Z[4*e+1]=W[1],Z[4*e+2]=W[2],Z[4*e+3]=1;D.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z),Q=!1}"edges"!==c.mode&&"shaded"!==c.mode||(BABYLON.VertexData.ComputeNormals(E,I,G),D.updateVerticesData(BABYLON.VertexBuffer.NormalKind,G)),function(){if(!he||!ce)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,t=P(.3,.4),n=P(.7,.4);me&&pe&&(me.position.set(t.x+.6*e,t.y+.6*o,t.z+.045),pe.position.set(n.x+.6*e,n.y+.6*o,n.z+.045)),he.position.set(t.x+e,t.y+o,t.z+.05),ce.position.set(n.x+e,n.y+o,n.z+.05);const r=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);he.isVisible=ce.isVisible=r<.85,me&&pe&&(me.isVisible=pe.isVisible=r<.85)}(),c.minimal&&function(){if(!ve)return;const e=be();ge("",e.upper,.01,ve),ge("",e.lower,.01,Be);for(const e of xe)ge("",Le(e.eye,!0),.0085,e.upper),ge("",Le(e.eye,!1),.0085,e.lower);for(const e of Oe)ge("",ze(e.brow),.011,e.mesh);const o=Se();ge("",o.bridge,.009,Re),ge("",o.leftN,.0085,Ae),ge("",o.rightN,.0085,ke)}(),z.rotation.x=.35*p.headRotateX,z.rotation.y=.5*p.headRotateY,z.rotation.z=.3*p.headRotateZ;for(let e=0;e<t.length;e++)p[t[e]]=Pe[t[e]]}}let je=1.5+3*Math.random(),He=0,Ve=.8+2*Math.random(),De=0,Ue=0,Te=0,Ie=0;let Fe=null,qe=null,Ee=null,Ge=null,Ze=0,Ke=0,Xe=!1,We=null;function Je(){Fe||(Fe=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Fe.state&&Fe.resume()}function Qe(){if(Ee){try{Ee.stop()}catch(e){}try{Ee.disconnect()}catch(e){}Ee=null}if(Ge){try{Ge.disconnect()}catch(e){}Ge=null}Xe=!1}function $e(){return Fe&&qe?Xe?Fe.currentTime-Ze:Ke||0:0}function eo(e,o){if(!We)return 0;const t=Fe.sampleRate/2/We.length,n=Math.max(0,Math.floor(e/t)),r=Math.min(We.length-1,Math.ceil(o/t));let i=0,s=0;for(let e=n;e<=r;e++)i+=We[e],s++;return s?i/s/255:0}function oo(e){c.lineColor=e,k.emissiveColor=BABYLON.Color3.FromHexString(e)}function to(e){c.pupilColor=e,de&&(de.emissiveColor=BABYLON.Color3.FromHexString(e))}function no(e){c.baseColor=e,W=d(e),Q=!0,A.emissiveColor=new BABYLON.Color3(W[0],W[1],W[2]),D&&D._edgesRenderer&&(D.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1))}function ro(e){c.fadeColor=e,J=d(e),Q=!0}function io(e){c.irisColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function so(e){c.browColor=e,S.emissiveColor=BABYLON.Color3.FromHexString(e)}const ao={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let lo=!1;function uo(e){if("orbit"===e)return void(lo=!0);lo=!1;const o=ao[e];o&&(L.alpha=o.alpha,L.beta=o.beta,L.radius=o.radius)}function ho(){x.intensity=c.glow?.85:0}te(),we(),Ne(),no(c.baseColor),ro(c.fadeColor),oo(c.lineColor),so(c.browColor),to(c.pupilColor),io(c.irisColor),ho(),uo(c.cameraView);let co=performance.now(),fo=!1;b.runRenderLoop(()=>{if(fo)return;const e=performance.now(),o=Math.min(.05,(e-co)/1e3);co=e,function(e){He+=e,He>je&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=v.sleep>.5?1:0,w.eyeBlinkRight=v.sleep>.5?1:0},110),He=0,je=1.5+3.5*Math.random()),De+=e,De>Ve&&!y.eyeLookH&&(Ue=.6*(Math.random()-.5),Te=.4*(Math.random()-.5),De=0,Ve=.7+2.5*Math.random()),w.eyeLookH=Ue,w.eyeLookV=Te,Ie+=e,w.headRotateX=.04*Math.sin(.27*Ie),w.headRotateY=.06*Math.sin(.19*Ie),w.headRotateZ=.03*Math.sin(.11*Ie)}(o),Xe&&function(){if(!Ge)return;Ge.getByteFrequencyData(We);const e=eo(200,700),o=eo(700,2e3),t=eo(2e3,4e3),r=eo(4e3,8e3),i=eo(1500,5e3),s=Math.max(e,o,t,r);if(s<.08){for(const e of Object.keys(n))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(n))"sil"!==e&&(w["viseme_"+e]=0);r>.35&&r>.8*o&&(w.viseme_SS=Math.min(1,1.3*r),w.viseme_FF=Math.min(.6,1.2*i)),e>o&&e>.18?t>.25?w.viseme_aa=Math.min(1,1.2*e):(w.viseme_O=Math.min(1,1.2*e),w.viseme_U=Math.min(.7,.9*e)):o>.2&&(t>.6*o?(w.viseme_I=Math.min(1,1.4*t),w.viseme_E=Math.min(.7,1.1*o)):(w.viseme_E=Math.min(1,1.3*o),w.viseme_aa=Math.min(.4,.9*e)))}(),function(e){const o=Math.max(.05,c.moodTransitionTime)/4,t=1-Math.pow(.5,e/o);for(const e of i)v[e]+=(g[e]-v[e])*t;for(const e of s){let o=0;for(const t of i)o+=(r[t][e]||0)*v[t];w[e]=o}}(o),function(e){for(const o of t){if(y[o]){p[o]=w[o];continue}const t=a[o]||a.default,n=1-Math.exp(-t*e*30);p[o]=p[o]+(w[o]-p[o])*n}}(o),Ye(),lo&&(L.alpha+=.3*o),M.render()});const mo=()=>b.resize();function po(e){if(!e)return;const o=e.renderConfig||{};let n=!1;if(void 0!==o.meshCols&&o.meshCols!==c.meshCols&&(n=!0),void 0!==o.meshRows&&o.meshRows!==c.meshRows&&(n=!0),void 0!==o.fragment&&o.fragment!==c.fragment&&(n=!0),void 0!==o.mouthHole&&o.mouthHole!==c.mouthHole&&(n=!0),void 0!==o.eyeHoles&&o.eyeHoles!==c.eyeHoles&&(n=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==c.mouthHoleSize&&(n=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==c.eyeHoleSize&&(n=!0),void 0!==o.eyeDepth&&o.eyeDepth!==c.eyeDepth&&(n=!0),Object.assign(c,o),e.lineColor&&oo(e.lineColor),e.pupilColor&&to(e.pupilColor),o.baseColor&&no(o.baseColor),o.fadeColor&&ro(o.fadeColor),o.lineColor&&oo(o.lineColor),o.pupilColor&&to(o.pupilColor),o.irisColor&&io(o.irisColor),o.browColor&&so(o.browColor),n?(te(),Ne(),we()):(ue(),se(),ae(),le(),void 0!==o.lineThickness&&Ne(),void 0===o.irisSize&&void 0===o.pupils||we(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||ne()),void 0!==o.glow&&ho(),e.channelGains)for(const o of t)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&r[e.activeMood]){B=e.activeMood;for(const e of i)g[e]=e===B?1:0}}return window.addEventListener("resize",mo),{loadAudio:async function(e){Je();const o=await e.arrayBuffer();qe=await Fe.decodeAudioData(o.slice(0)),Ke=0},play(e){qe&&function(e){qe&&(Je(),Ee=Fe.createBufferSource(),Ee.buffer=qe,Ee.loop=!!c.loopAudio,Ge=Fe.createAnalyser(),Ge.fftSize=1024,Ge.smoothingTimeConstant=.4,We=new Uint8Array(Ge.frequencyBinCount),Ee.connect(Ge),Ge.connect(Fe.destination),Ze=Fe.currentTime-(e||0),Ee.start(0,e||0),Ee.onended=()=>{if(!c.loopAudio){Xe=!1;for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Xe=!0)}(void 0!==e?e:Ke)},pause(){Xe&&(Ke=$e(),Qe())},stop(){Ke=0,Qe();for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){c.loopAudio=!!e,Ee&&(Ee.loop=!!e)},setMood(e){if(r[e]){B=e;for(const o of i)g[o]=o===e?1:0}},setChannel(e,t){if(!o[e])return;const n=o[e].range,r=Math.max(n[0],Math.min(n[1],t));w[e]=r,p[e]=r,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:uo,loadPreset:po,setRenderConfig(e){po({renderConfig:e})},getRenderConfig:()=>Object.assign({},c),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,t){o[e]&&(_[e]=t)},getChannelNames:()=>t.slice(),getMoodNames:()=>i.slice(),isPlaying:()=>Xe,getDuration:()=>qe?qe.duration:0,getPosition:()=>$e(),getActiveMood:()=>B,dispose(){fo=!0;try{Qe()}catch(e){}if(Fe){try{Fe.close()}catch(e){}Fe=null}window.removeEventListener("resize",mo);try{b.stopRenderLoop()}catch(e){}try{M.dispose()}catch(e){}try{b.dispose()}catch(e){}}}}e.createWireface=h,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:h})}("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}},t=Object.keys(o),n={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},r={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},i=Object.keys(r),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],a={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(n).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},l={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeHoleSize:1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,cameraView:"three-q"};function d(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function c(e,c){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const h=Object.assign({},u,c||{}),f=(e,o,t)=>new BABYLON.Vector3(e,o,t),m={};for(const e of Object.keys(l)){const o=l[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};t.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const g={},v={};for(const e of i)g[e]=0,v[e]=0;g.neutral=1,v.neutral=1;let B="neutral";const b=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),x=new BABYLON.Scene(b);x.clearColor=new BABYLON.Color4(0,0,0,1),x.skipPointerMovePicking=!0;const L=new BABYLON.GlowLayer("glow",x,{mainTextureFixedSize:1024,blurKernelSize:32});L.intensity=0;const C=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),x);C.minZ=.1,C.maxZ=100,C.lowerRadiusLimit=1.5,C.upperRadiusLimit=12,C.wheelDeltaPercentage=.01;const M=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}C.attachControl(e,!0);try{navigator.getGamepads=M}catch(e){}const O=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),x);O.intensity=.9,O.groundColor=new BABYLON.Color3(.1,.1,.14);const z=new BABYLON.TransformNode("faceRoot",x),R=new BABYLON.StandardMaterial("faceMat",x);R.diffuseColor=new BABYLON.Color3(.05,.05,.07),R.emissiveColor=new BABYLON.Color3(.012,.012,.02),R.specularColor=new BABYLON.Color3(.2,.22,.28),R.specularPower=48,R.backFaceCulling=!1,R.useVertexColor=!0;const A=new BABYLON.StandardMaterial("wireMat",x);A.emissiveColor=new BABYLON.Color3(1,1,1),A.disableLighting=!0,A.wireframe=!0,A.backFaceCulling=!1,A.alpha=1,A.useVertexColor=!0;const k=new BABYLON.StandardMaterial("minimalMat",x);k.emissiveColor=new BABYLON.Color3(1,1,1),k.disableLighting=!0,k.specularColor=new BABYLON.Color3(0,0,0);const S=new BABYLON.StandardMaterial("browMat",x);S.emissiveColor=new BABYLON.Color3(1,1,1),S.disableLighting=!0,S.specularColor=new BABYLON.Color3(0,0,0);const N=new BABYLON.TransformNode("minimal",x);function P(e,o){const t=2*(e-.5),n=2*(.5-o),r=.95*n,i=Math.max(0,1-r*r);let s=t*(.8*Math.sqrt(i)),a=1*n;n<-.4&&(a=1.55*(n+.4)-.4),n>.7&&(a=.7+.45*(n-.7));let l=.22*(1-t*t*.55-n*n*.55);l<-.05&&(l=-.05);const u=((t+.45)/.3)**2+((n-.3)/.18)**2,d=((t-.45)/.3)**2+((n-.3)/.18)**2,c=.045*h.eyeDepth;l-=c*Math.exp(-u),l-=c*Math.exp(-d);const m=(t/.7)**2+((n-.55)/.1)**2;l+=.045*Math.exp(-m);const p=(t/.18)**2+((n-.05)/.4)**2;l+=.22*Math.exp(-p);const w=(t/.55)**2+((n+.45)/.2)**2;l+=.06*Math.exp(-w);const y=((t+.55)/.3)**2+((n-.05)/.28)**2,_=((t-.55)/.3)**2+((n-.05)/.28)**2;return l+=.04*Math.exp(-y),l+=.04*Math.exp(-_),f(s,a,l)}N.parent=z;const Y=P(.5,.69);function j(e,o,t){const n=Y.x,r=Y.y,i=Y.z,s=.27*(1+.4*t.width)*(1-.4*t.round),a=h.lipVertAmp,l=h.lipPressForce,u=.16*t.open*a,d=.012*t.lipPress*a*l,c=.09*t.jaw*a,m=.05*t.smile,p=.07*t.round,w=.007*(1-.55*t.lipPress),y=.022*(1-.55*t.lipPress);let _;if(o){const e=r+u/2-d+.4*m;_=[[-1,r+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,r+m,.5*-p]]}else{const e=r-u/2+d-c;_=[[-1,r+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,r+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let g=0;for(;g<_.length-1&&e>_[g+1][0];)g++;g=Math.min(g,_.length-2);const v=(e-_[g][0])/(_[g+1][0]-_[g][0]),B=_[g][1]*(1-v)+_[g+1][1]*v,b=_[g][2]*(1-v)+_[g+1][2]*v;return f(n+e*s,B,i+b)}function H(e,o,t,n,r){const i=(e+1)/2*Math.PI,s=t.center.x+Math.cos(Math.PI-i)*t.hw,a=.012*r,l=(t.center.y+(o?1:-1)*Math.sin(i)*t.hh)*(1-n)+t.center.y*n+(o?-a:.5*a),u=t.center.z+.018+.012*Math.sin(i);return f(s,l,u)}function U(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const t of Object.keys(n)){const r=p["viseme_"+t]||0;if(r<=0)continue;e+=r;const i=n[t];o.open+=i.open*r,o.width+=i.width*r,o.round+=i.round*r,o.smile+=i.smile*r,o.lipPress+=i.lipPress*r,o.jaw+=i.jaw*r}if(e>1){const t=1/e;o.open*=t,o.width*=t,o.round*=t,o.smile*=t,o.lipPress*=t,o.jaw*=t}o.smile+=p.mouthSmile;const t=p.mouthPucker;return o.round+=.7*t,o.width+=.4*-t,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let V=null,D=[],T=[],F=[],I=[],q=null,E=null,G=null,Z=null,K=0,X=0,W=[1,1,1],J=[0,0,0],Q=!1,$=[],ee=[];const oe={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function te(){V&&(V.dispose(),V=null);const e=h.meshCols,o=h.meshRows;D=[],T=[],F=[];for(let t=0;t<o;t++)for(let n=0;n<e;n++){const r=n/(e-1),i=t/(o-1);T.push({u:r,v:i}),D.push(P(r,i))}const t=e=>{if(!h.fragment)return!0;const o=2*(T[e].u-.5),t=2*(.5-T[e].v);return o*o*1.2+t*t*.95<1},n=(e,o,n)=>{((e,o,n)=>{if(!t(e)||!t(o)||!t(n))return!1;if(h.mouthHole){const t=.5,r=.69,i=.18*h.mouthHoleSize,s=.075*h.mouthHoleSize,a=((T[e].u+T[o].u+T[n].u)/3-t)/i,l=((T[e].v+T[o].v+T[n].v)/3-r)/s;if(a*a+l*l<1)return!1}if(h.eyeHoles){const t=.105*h.eyeHoleSize,r=.075*h.eyeHoleSize,i=(T[e].u+T[o].u+T[n].u)/3,s=(T[e].v+T[o].v+T[n].v)/3;if(((i-.3)/t)**2+((s-.4)/r)**2<1||((i-.7)/t)**2+((s-.4)/r)**2<1)return!1}return!0})(e,o,n)&&F.push(e,o,n)};for(let t=0;t<o-1;t++)for(let o=0;o<e-1;o++){const r=t*e+o,i=t*e+(o+1),s=(t+1)*e+o,a=(t+1)*e+(o+1);(t+o)%2==0?(n(r,i,a),n(r,a,s)):(n(r,i,s),n(i,a,s))}I=function(e,o){const t=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const n=e[o],r=e[o+1],i=e[o+2];t[n].add(r),t[n].add(i),t[r].add(n),t[r].add(i),t[i].add(n),t[i].add(r)}return t.map(e=>Array.from(e))}(F,D.length),V=new BABYLON.Mesh("face",x),V.parent=z;const r=D.length;E=new Float32Array(3*r),G=new Float32Array(3*r),Z=new Float32Array(4*r),q=new Array(r),K=1/0,X=-1/0;for(let e=0;e<r;e++)E[3*e]=D[e].x,E[3*e+1]=D[e].y,E[3*e+2]=D[e].z,D[e].z<K&&(K=D[e].z),D[e].z>X&&(X=D[e].z),q[e]=f(0,0,0),Z[4*e]=1,Z[4*e+1]=1,Z[4*e+2]=1,Z[4*e+3]=1;BABYLON.VertexData.ComputeNormals(E,F,G);const i=new BABYLON.VertexData;i.positions=Array.from(E),i.indices=F,i.normals=Array.from(G),i.colors=Array.from(Z),i.applyToMesh(V,!0),ue(),se(),ae(),ne(),Q=!0}function ne(){$=[],ee=[];const e=.18*h.mouthHoleSize,o=.075*h.mouthHoleSize;for(let t=0;t<T.length;t++){const n=(T[t].u-.5)/e,r=(T[t].v-.69)/o,i=n*n+r*r;if(i<4){const e=T[t].v<.69,o=Math.max(-1,Math.min(1,n));let r=i<=1?i:(4-i)/3;r=Math.max(0,Math.min(1,r)),$.push({idx:t,isUpper:e,xRel:o,weight:r,baselineTarget:j(o,e,oe)})}}const t=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of t)for(let o=0;o<T.length;o++){const t=(T[o].u-e.cu)/e.ru,n=(T[o].v-e.cv)/e.rv,r=t*t+n*n;if(r<4){const n=T[o].v<e.cv,i=Math.max(-1,Math.min(1,t));let s=r<=1?r:(4-r)/3;s=Math.max(0,Math.min(1,s));const a=P(e.cu,e.cv);ee.push({idx:o,side:e.side,isUpper:n,xRel:i,weight:s,eyeDef:{center:a,hw:e.hw,hh:e.hh},baselineTarget:H(i,n,{center:a,hw:e.hw,hh:e.hh},0,0)})}}}function re(e,o,t,n){if(Math.abs(t)<.001)return;const r=o.uv[0],i=o.uv[1],s=o.radius*n,a=s*s,l=o.dir.x*t,u=o.dir.y*t,d=o.dir.z*t;for(let o=0;o<T.length;o++){const t=T[o].u-r,n=T[o].v-i,s=t*t+n*n;if(s>4*a)continue;const c=Math.exp(-s/a);e[o].x+=l*c,e[o].y+=u*c,e[o].z+=d*c}}const ie=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return h.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return h.scaleMouth}}];function se(){z&&(z.rotation.y=h.flipFace?Math.PI:0)}function ae(){V&&(V.isVisible=!!h.meshVisible)}function le(){N&&N.getChildMeshes().forEach(e=>e.isVisible=!!h.minimal)}function ue(){if(!V)return;V._edgesRenderer&&V.disableEdgesRendering();const e=h.lineThickness;switch(h.mode){case"wire":V.material=A,A.wireframe=!0,A.alpha=1;break;case"edges":V.material=R,R.alpha=1,R.wireframe=!1,V.enableEdgesRendering(.9999),V.edgesWidth=4*e,V.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1);break;case"shaded":V.material=R,R.alpha=1,R.wireframe=!1}}let de=null,ce=null,he=null,fe=null,me=null,pe=null;function we(){if(ce&&(ce.dispose(),ce=null),he&&(he.dispose(),he=null),me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),!h.pupils)return;de||(de=new BABYLON.StandardMaterial("pupilMat",x),de.emissiveColor=BABYLON.Color3.FromHexString(h.pupilColor),de.disableLighting=!0,de.backFaceCulling=!1),fe||(fe=new BABYLON.StandardMaterial("irisMat",x),fe.emissiveColor=BABYLON.Color3.FromHexString(h.irisColor),fe.disableLighting=!0,fe.backFaceCulling=!1);const e=.035*h.irisSize;me=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},x),pe=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},x),me.material=pe.material=fe,me.parent=pe.parent=z,ce=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},x),he=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},x),ce.material=he.material=de,ce.parent=he.parent=z}function ye(e,o){const t=P(e,o);if(!h.overlayTracksMesh)return t;const n=function(e,o){if(!q)return f(0,0,0);const t=.0036;let n=0,r=0,i=0,s=0;for(let a=0;a<T.length;a++){const l=T[a].u-e,u=T[a].v-o,d=l*l+u*u;if(d<t){const e=1-Math.sqrt(d/t);n+=e,r+=q[a].x*e,i+=q[a].y*e,s+=q[a].z*e}}return 0===n?f(0,0,0):f(r/n,i/n,s/n)}(e,o);return f(t.x+n.x,t.y+n.y,t.z+n.z)}function _e(e,o=18){const t=[],n=e.length,r=o=>e[Math.max(0,Math.min(n-1,o))];for(let e=0;e<n-1;e++){const n=r(e-1),i=r(e),s=r(e+1),a=r(e+2);for(let e=0;e<o;e++){const r=e/o,l=r*r,u=r*l,d=.5*(2*i.x+(-n.x+s.x)*r+(2*n.x-5*i.x+4*s.x-a.x)*l+(-n.x+3*i.x-3*s.x+a.x)*u),c=.5*(2*i.y+(-n.y+s.y)*r+(2*n.y-5*i.y+4*s.y-a.y)*l+(-n.y+3*i.y-3*s.y+a.y)*u),h=.5*(2*i.z+(-n.z+s.z)*r+(2*n.z-5*i.z+4*s.z-a.z)*l+(-n.z+3*i.z-3*s.z+a.z)*u);t.push(f(d,c,h))}}return t.push(e[n-1]),t}function ge(e,o,t,n){const r={path:o,radius:n?t:t*h.lineThickness,tessellation:6,updatable:!0};n&&(r.instance=n);const i=BABYLON.MeshBuilder.CreateTube(e,r,x);return n||(i.material=k,i.parent=N),i}let ve=null,Be=null;function be(){const e=U();return{upper:_e([-1,-.45,0,.45,1].map(o=>j(o,!0,e)),18),lower:_e([-1,-.5,0,.5,1].map(o=>j(o,!1,e)),18)}}const xe=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let Le=[];function Ce(e,o){const t="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,n=p.eyeSquint,r=ye(e.uv[0],e.uv[1]),i=[],s=.012*n;for(let n=0;n<=12;n++){const a=n/12*Math.PI,l=r.x+Math.cos(Math.PI-a)*e.hw,u=(r.y+(o?1:-1)*Math.sin(a)*e.hh)*(1-t)+r.y*t+(o?-s:.5*s),d=r.z+.018+.012*Math.sin(a);i.push(f(l,u,d))}return i}const Me=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Oe=[];function ze(e){const o=ye(e.uv[0],e.uv[1]),t="L"===e.side?-1:1,n=.085*p.browInnerUp-.05*p.browDown,r=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,i=o.x+-.1*t,s=o.x,a=o.x+.1*t,l=o.y+n,u=o.y+.5*(n+r)+.005,d=o.y+r-.005,c=o.z+.018;return _e([f(i,l,c),f(s,u,c+.01),f(a,d,c)],12)}let Re=null,Ae=null,ke=null;function Se(){const e=.025*p.noseSneer,o=ye(.5,.4),t=ye(.5,.55),n=_e([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+t.y),.5*(o.z+t.z)+.05),f(t.x,t.y+.03,t.z+.05)],14),r=t.y+.01;return{bridge:n,leftN:_e([f(t.x,r,t.z+.05),f(t.x-.06-e,r-.03,t.z+.02),f(t.x-.04,r-.05,t.z+.005),f(t.x-.01,r-.02,t.z+.03)],10),rightN:_e([f(t.x,r,t.z+.05),f(t.x+.06+e,r-.03,t.z+.02),f(t.x+.04,r-.05,t.z+.005),f(t.x+.01,r-.02,t.z+.03)],10)}}function Ne(){ve&&(ve.dispose(),ve=null),Be&&(Be.dispose(),Be=null);for(const e of Le)e.upper.dispose(),e.lower.dispose();Le=[];for(const e of Oe)e.mesh.dispose();Oe=[],Re&&(Re.dispose(),Re=null),Ae&&(Ae.dispose(),Ae=null),ke&&(ke.dispose(),ke=null);const{upper:e,lower:o}=be();ve=ge("mouth_u",e,.01),Be=ge("mouth_l",o,.01);for(const e of xe){const o=ge("eye_"+e.side+"_u",Ce(e,!0),.0085),t=ge("eye_"+e.side+"_l",Ce(e,!1),.0085);Le.push({eye:e,upper:o,lower:t})}for(const e of Me){const o=ge("brow_"+e.side,ze(e),.011);o.material=S,Oe.push({brow:e,mesh:o})}const t=Se();Re=ge("nose_b",t.bridge,.009),Ae=ge("nose_l",t.leftN,.0085),ke=ge("nose_r",t.rightN,.0085),le()}const Pe={};function Ye(){if(V){for(let e=0;e<t.length;e++){const o=t[e];Pe[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<q.length;e++)q[e].x=q[e].y=q[e].z=0;!function(e){const o=h.spread,t=U();re(e,m.mouth_jaw_drop,t.jaw,o),re(e,m.mouth_open_lower,t.open,o),re(e,m.mouth_open_upper,.4*t.open,o);const n=t.smile;n>0?(re(e,m.mouth_smile_L,n,o),re(e,m.mouth_smile_R,n,o)):n<0&&(re(e,m.mouth_frown_L,-n,o),re(e,m.mouth_frown_R,-n,o)),re(e,m.mouth_round_L,t.round,o),re(e,m.mouth_round_R,t.round,o),re(e,m.mouth_round_top,t.round,o),re(e,m.mouth_round_bot,t.round,o),re(e,m.mouth_press_top,t.lipPress,o),re(e,m.mouth_press_bot,t.lipPress,o),t.width>0&&(re(e,m.mouth_width_L,t.width,o),re(e,m.mouth_width_R,t.width,o)),re(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),re(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),re(e,m.eye_blink_R_up,p.eyeBlinkRight,o),re(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),re(e,m.eye_squint_L,p.eyeSquint,o),re(e,m.eye_squint_R,p.eyeSquint,o),re(e,m.brow_inner_L,p.browInnerUp,o),re(e,m.brow_inner_R,p.browInnerUp,o),p.browOuterUp>=0?(re(e,m.brow_outer_L,p.browOuterUp,o),re(e,m.brow_outer_R,p.browOuterUp,o)):(re(e,m.brow_down_L,.6*-p.browOuterUp,o),re(e,m.brow_down_R,.6*-p.browOuterUp,o)),re(e,m.brow_down_L,p.browDown,o),re(e,m.brow_down_R,p.browDown,o),re(e,m.nose_sneer_L,p.noseSneer,o),re(e,m.nose_sneer_R,p.noseSneer,o)}(q),h.reactivity>0&&function(e,o){if(o<=0)return;const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const t=I[r];if(0===t.length){n[r]=f(e[r].x,e[r].y,e[r].z);continue}let i=0,s=0,a=0;for(const o of t)i+=e[o].x,s+=e[o].y,a+=e[o].z;i/=t.length,s/=t.length,a/=t.length,n[r]=f(e[r].x*(1-o)+i*o,e[r].y*(1-o)+s*o,e[r].z*(1-o)+a*o)}for(let o=0;o<t;o++)e[o].x=n[o].x,e[o].y=n[o].y,e[o].z=n[o].z}(q,h.reactivity),function(e){for(const o of ie){const t=o.scale;if(Math.abs(t-1)<.001)continue;const n=P(o.uv[0],o.uv[1]),r=o.radiusUV*o.radiusUV,i=4*r;for(let s=0;s<T.length;s++){const a=T[s].u-o.uv[0],l=T[s].v-o.uv[1],u=a*a+l*l;if(u>i)continue;const d=Math.exp(-u/r),c=D[s].x-n.x,h=D[s].y-n.y,f=D[s].z-n.z,m=(t-1)*d;e[s].x+=c*m,e[s].y+=h*m,e[s].z+=f*m}}}(q),function(e){const o=h.jawExtend;if(o<.001)return;const t=p.jawOpen||0;if(t<.001)return;const n=t*o*.1;for(let o=0;o<T.length;o++){const t=T[o].v;if(t<.55)continue;const r=Math.min(1,(t-.55)/.45);e[o].z+=n*r}}(q),function(e){const o=h.mouthGrow;if(o<.001)return;const t=U().open;if(t<.001)return;const n=t*o,r=.0625;for(let o=0;o<T.length;o++){const t=T[o].u-.5,i=T[o].v-.69,s=t*t+i*i;if(s>r)continue;const a=1-Math.sqrt(s/r),l=D[o];e[o].x+=(l.x-Y.x)*n*a*.4,e[o].y+=(l.y-Y.y)*n*a*.4,e[o].z+=n*a*.05}}(q),function(e){if(!h.mouthAnchor)return;const o=U();for(const t of $){const n=j(t.xRel,t.isUpper,o),r=n.x-t.baselineTarget.x,i=n.y-t.baselineTarget.y,s=n.z-t.baselineTarget.z,a=t.weight;e[t.idx].x=e[t.idx].x*(1-a)+r*a,e[t.idx].y=e[t.idx].y*(1-a)+i*a,e[t.idx].z=e[t.idx].z*(1-a)+s*a}}(q),function(e){if(!h.eyeAnchor)return;const o=p.eyeBlinkLeft,t=p.eyeBlinkRight,n=p.eyeSquint;for(const r of ee){const i="L"===r.side?o:t,s=H(r.xRel,r.isUpper,r.eyeDef,i,n),a=s.x-r.baselineTarget.x,l=s.y-r.baselineTarget.y,u=s.z-r.baselineTarget.z,d=r.weight;e[r.idx].x=e[r.idx].x*(1-d)+a*d,e[r.idx].y=e[r.idx].y*(1-d)+l*d,e[r.idx].z=e[r.idx].z*(1-d)+u*d}}(q);for(let e=0;e<D.length;e++)E[3*e]=D[e].x+q[e].x,E[3*e+1]=D[e].y+q[e].y,E[3*e+2]=D[e].z+q[e].z;if(V.updateVerticesData(BABYLON.VertexBuffer.PositionKind,E),h.depthFade>.001){const e=X-K||1,o=h.depthFade;for(let t=0;t<D.length;t++){const n=E[3*t+2],r=Math.max(0,Math.min(1,(X-n)/e))*o;Z[4*t]=W[0]*(1-r)+J[0]*r,Z[4*t+1]=W[1]*(1-r)+J[1]*r,Z[4*t+2]=W[2]*(1-r)+J[2]*r,Z[4*t+3]=1}V.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z)}else if(Q){for(let e=0;e<D.length;e++)Z[4*e]=W[0],Z[4*e+1]=W[1],Z[4*e+2]=W[2],Z[4*e+3]=1;V.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z),Q=!1}"edges"!==h.mode&&"shaded"!==h.mode||(BABYLON.VertexData.ComputeNormals(E,F,G),V.updateVerticesData(BABYLON.VertexBuffer.NormalKind,G)),function(){if(!ce||!he)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,t=P(.3,.4),n=P(.7,.4);me&&pe&&(me.position.set(t.x+.6*e,t.y+.6*o,t.z+.045),pe.position.set(n.x+.6*e,n.y+.6*o,n.z+.045)),ce.position.set(t.x+e,t.y+o,t.z+.05),he.position.set(n.x+e,n.y+o,n.z+.05);const r=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);ce.isVisible=he.isVisible=r<.85,me&&pe&&(me.isVisible=pe.isVisible=r<.85)}(),h.minimal&&function(){if(!ve)return;const e=be();ge("",e.upper,.01,ve),ge("",e.lower,.01,Be);for(const e of Le)ge("",Ce(e.eye,!0),.0085,e.upper),ge("",Ce(e.eye,!1),.0085,e.lower);for(const e of Oe)ge("",ze(e.brow),.011,e.mesh);const o=Se();ge("",o.bridge,.009,Re),ge("",o.leftN,.0085,Ae),ge("",o.rightN,.0085,ke)}(),z.rotation.x=.35*p.headRotateX,z.rotation.y=.5*p.headRotateY,z.rotation.z=.3*p.headRotateZ;for(let e=0;e<t.length;e++)p[t[e]]=Pe[t[e]]}}let je=1.5+3*Math.random(),He=0,Ue=.8+2*Math.random(),Ve=0,De=0,Te=0,Fe=0;let Ie=null,qe=null,Ee=null,Ge=null,Ze=0,Ke=0,Xe=!1,We=null;function Je(){Ie||(Ie=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Ie.state&&Ie.resume()}function Qe(){if(Ee){try{Ee.stop()}catch(e){}try{Ee.disconnect()}catch(e){}Ee=null}if(Ge){try{Ge.disconnect()}catch(e){}Ge=null}Xe=!1}function $e(){return Ie&&qe?Xe?Ie.currentTime-Ze:Ke||0:0}function eo(e,o){if(!We)return 0;const t=Ie.sampleRate/2/We.length,n=Math.max(0,Math.floor(e/t)),r=Math.min(We.length-1,Math.ceil(o/t));let i=0,s=0;for(let e=n;e<=r;e++)i+=We[e],s++;return s?i/s/255:0}function oo(e){h.lineColor=e,k.emissiveColor=BABYLON.Color3.FromHexString(e)}function to(e){h.pupilColor=e,de&&(de.emissiveColor=BABYLON.Color3.FromHexString(e))}function no(e){h.baseColor=e,W=d(e),Q=!0,A.emissiveColor=new BABYLON.Color3(W[0],W[1],W[2]),V&&V._edgesRenderer&&(V.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1))}function ro(e){h.fadeColor=e,J=d(e),Q=!0}function io(e){h.irisColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function so(e){h.browColor=e,S.emissiveColor=BABYLON.Color3.FromHexString(e)}const ao={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let lo=!1;function uo(e){if("orbit"===e)return void(lo=!0);lo=!1;const o=ao[e];o&&(C.alpha=o.alpha,C.beta=o.beta,C.radius=o.radius)}function co(){L.intensity=h.glow?.85:0}te(),we(),Ne(),no(h.baseColor),ro(h.fadeColor),oo(h.lineColor),so(h.browColor),to(h.pupilColor),io(h.irisColor),co(),uo(h.cameraView);let ho=performance.now(),fo=!1;b.runRenderLoop(()=>{if(fo)return;const e=performance.now(),o=Math.min(.05,(e-ho)/1e3);ho=e,function(e){He+=e,He>je&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=v.sleep>.5?1:0,w.eyeBlinkRight=v.sleep>.5?1:0},110),He=0,je=1.5+3.5*Math.random()),Ve+=e,Ve>Ue&&!y.eyeLookH&&(De=.6*(Math.random()-.5),Te=.4*(Math.random()-.5),Ve=0,Ue=.7+2.5*Math.random()),w.eyeLookH=De,w.eyeLookV=Te,Fe+=e,w.headRotateX=.04*Math.sin(.27*Fe),w.headRotateY=.06*Math.sin(.19*Fe),w.headRotateZ=.03*Math.sin(.11*Fe)}(o),Xe&&function(){if(!Ge)return;Ge.getByteFrequencyData(We);const e=eo(200,700),o=eo(700,2e3),t=eo(2e3,4e3),r=eo(4e3,8e3),i=eo(1500,5e3),s=Math.max(e,o,t,r);if(s<.08){for(const e of Object.keys(n))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(n))"sil"!==e&&(w["viseme_"+e]=0);r>.35&&r>.8*o&&(w.viseme_SS=Math.min(1,1.3*r),w.viseme_FF=Math.min(.6,1.2*i)),e>o&&e>.18?t>.25?w.viseme_aa=Math.min(1,1.2*e):(w.viseme_O=Math.min(1,1.2*e),w.viseme_U=Math.min(.7,.9*e)):o>.2&&(t>.6*o?(w.viseme_I=Math.min(1,1.4*t),w.viseme_E=Math.min(.7,1.1*o)):(w.viseme_E=Math.min(1,1.3*o),w.viseme_aa=Math.min(.4,.9*e)))}(),function(e){const o=Math.max(.05,h.moodTransitionTime)/4,t=1-Math.pow(.5,e/o);for(const e of i)v[e]+=(g[e]-v[e])*t;for(const e of s){let o=0;for(const t of i)o+=(r[t][e]||0)*v[t];w[e]=o}}(o),function(e){for(const o of t){if(y[o]){p[o]=w[o];continue}const t=a[o]||a.default,n=1-Math.exp(-t*e*30);p[o]=p[o]+(w[o]-p[o])*n}}(o),Ye(),lo&&(C.alpha+=.3*o),x.render()});const mo=()=>b.resize();function po(e){if(!e)return;const o=e.renderConfig||{};let n=!1;if(void 0!==o.meshCols&&o.meshCols!==h.meshCols&&(n=!0),void 0!==o.meshRows&&o.meshRows!==h.meshRows&&(n=!0),void 0!==o.fragment&&o.fragment!==h.fragment&&(n=!0),void 0!==o.mouthHole&&o.mouthHole!==h.mouthHole&&(n=!0),void 0!==o.eyeHoles&&o.eyeHoles!==h.eyeHoles&&(n=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==h.mouthHoleSize&&(n=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==h.eyeHoleSize&&(n=!0),void 0!==o.eyeDepth&&o.eyeDepth!==h.eyeDepth&&(n=!0),Object.assign(h,o),e.lineColor&&oo(e.lineColor),e.pupilColor&&to(e.pupilColor),o.baseColor&&no(o.baseColor),o.fadeColor&&ro(o.fadeColor),o.lineColor&&oo(o.lineColor),o.pupilColor&&to(o.pupilColor),o.irisColor&&io(o.irisColor),o.browColor&&so(o.browColor),n?(te(),Ne(),we()):(ue(),se(),ae(),le(),void 0!==o.lineThickness&&Ne(),void 0===o.irisSize&&void 0===o.pupils||we(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||ne()),void 0!==o.glow&&co(),e.channelGains)for(const o of t)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&r[e.activeMood]){B=e.activeMood;for(const e of i)g[e]=e===B?1:0}}return window.addEventListener("resize",mo),{loadAudio:async function(e){Je();const o=await e.arrayBuffer();qe=await Ie.decodeAudioData(o.slice(0)),Ke=0},play(e){qe&&function(e){qe&&(Je(),Ee=Ie.createBufferSource(),Ee.buffer=qe,Ee.loop=!!h.loopAudio,Ge=Ie.createAnalyser(),Ge.fftSize=1024,Ge.smoothingTimeConstant=.4,We=new Uint8Array(Ge.frequencyBinCount),Ee.connect(Ge),Ge.connect(Ie.destination),Ze=Ie.currentTime-(e||0),Ee.start(0,e||0),Ee.onended=()=>{if(!h.loopAudio){Xe=!1;for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Xe=!0)}(void 0!==e?e:Ke)},pause(){Xe&&(Ke=$e(),Qe())},stop(){Ke=0,Qe();for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){h.loopAudio=!!e,Ee&&(Ee.loop=!!e)},setMood(e){if(r[e]){B=e;for(const o of i)g[o]=o===e?1:0}},setChannel(e,t){if(!o[e])return;const n=o[e].range,r=Math.max(n[0],Math.min(n[1],t));w[e]=r,p[e]=r,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:uo,loadPreset:po,setRenderConfig(e){po({renderConfig:e})},getRenderConfig:()=>Object.assign({},h),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,t){o[e]&&(_[e]=t)},getChannelNames:()=>t.slice(),getMoodNames:()=>i.slice(),isPlaying:()=>Xe,getDuration:()=>qe?qe.duration:0,getPosition:()=>$e(),getActiveMood:()=>B,dispose(){fo=!0;try{Qe()}catch(e){}if(Ie){try{Ie.close()}catch(e){}Ie=null}window.removeEventListener("resize",mo);try{b.stopRenderLoop()}catch(e){}try{x.dispose()}catch(e){}try{b.dispose()}catch(e){}}}}e.createWireface=c,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:c})}("undefined"!=typeof window?window:globalThis);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireface",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Minimal embeddable wireframe lipsync face renderer — drives expressive character profiles from voice or TTS audio in the browser.",
5
5
  "main": "wireface.js",
6
6
  "browser": "wireface.js",
package/wireface.js CHANGED
@@ -285,36 +285,58 @@
285
285
  const minimalGroup = new BABYLON.TransformNode('minimal', scene);
286
286
  minimalGroup.parent = faceRoot;
287
287
 
288
- /* ─── 4a. parametric warp (u,v) → 3D face surface ─── */
288
+ /* ─── 4a. parametric warp: grid (u,v) → face surface (x,y,z) ───
289
+ Ported verbatim from the v011 editor. Uses an elliptical taper so the
290
+ silhouette is oval, not rectangular. Then layers feature bumps (eye
291
+ sockets, brow ridge, nose, mouth, cheeks) as gaussian falloffs in
292
+ xRel/yRel space (xRel = (u-0.5)*2, yRel = (0.5-v)*2). This shape's
293
+ z-range (≈0.10..0.30) is what lets depthFade produce a visible
294
+ gradient instead of pinning the silhouette to black. */
289
295
  function warpToFace(u, v) {
290
- const xRel = (u - 0.5) * 2;
291
- const yRel = (0.5 - v) * 2;
296
+ const xRel = (u - 0.5) * 2; // -1..1 left to right
297
+ const yRel = (0.5 - v) * 2; // 1..-1 top to bottom
298
+
299
+ // strong elliptical taper — boundary of the grid maps to an oval
292
300
  const yNorm = yRel * 0.95;
293
301
  const ovalT = Math.max(0, 1 - yNorm * yNorm);
294
- const x = xRel * Math.sqrt(ovalT) * 0.80;
295
- const y = yRel * 0.95;
296
- let z = (Math.cos(xRel * Math.PI * 0.5)) * (Math.cos(yRel * Math.PI * 0.5)) * 0.18;
297
- // nose ridge
298
- const nU = 0.50, nV = 0.50;
299
- const dn = Math.hypot((u-nU), (v-nV)) / 0.16;
300
- if (dn < 1.6) z += (1 - Math.min(1, dn)) * 0.085;
301
- // brow ridge
302
- const dbL = Math.hypot((u-0.30), (v-0.27)) / 0.10;
303
- const dbR = Math.hypot((u-0.70), (v-0.27)) / 0.10;
304
- if (dbL < 1.6) z += (1 - Math.min(1, dbL)) * 0.020;
305
- if (dbR < 1.6) z += (1 - Math.min(1, dbR)) * 0.020;
306
- // eye sockets recess
307
- const deL = Math.hypot((u-0.30)/0.085, (v-0.40)/0.045);
308
- const deR = Math.hypot((u-0.70)/0.085, (v-0.40)/0.045);
309
- if (deL < 1.5) z -= (1 - Math.min(1, deL)) * 0.030 * config.eyeDepth;
310
- if (deR < 1.5) z -= (1 - Math.min(1, deR)) * 0.030 * config.eyeDepth;
311
- // chin protrusion
312
- if (v > 0.85) z += (v - 0.85) * 0.6 * 0.10 * Math.max(0, 1 - Math.abs(xRel) * 1.2);
313
- // cheek bulge
314
- const cheekL = Math.hypot((u-0.22)/0.10, (v-0.62)/0.08);
315
- const cheekR = Math.hypot((u-0.78)/0.10, (v-0.62)/0.08);
316
- if (cheekL < 1.6) z += (1 - Math.min(1, cheekL)) * 0.018;
317
- if (cheekR < 1.6) z += (1 - Math.min(1, cheekR)) * 0.018;
302
+ const widthAtY = Math.sqrt(ovalT) * 0.80;
303
+ let x = xRel * widthAtY;
304
+
305
+ // y stays linear; chin extends + forehead squashes
306
+ let y = yRel * 1.0;
307
+ if (yRel < -0.4) y = -0.4 + (yRel + 0.4) * 1.55;
308
+ if (yRel > 0.7) y = 0.7 + (yRel - 0.7) * 0.45;
309
+
310
+ // base z bulge — quadratic falloff from center
311
+ let z = (1 - xRel*xRel * 0.55 - yRel*yRel * 0.55) * 0.22;
312
+ if (z < -0.05) z = -0.05;
313
+
314
+ // eye sockets recess (gaussian — broad and bowl-shaped)
315
+ const eyeY = 0.30;
316
+ const eyeL_d = ((xRel + 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
317
+ const eyeR_d = ((xRel - 0.45) / 0.30) ** 2 + ((yRel - eyeY) / 0.18) ** 2;
318
+ const eyeRecess = 0.045 * config.eyeDepth;
319
+ z -= eyeRecess * Math.exp(-eyeL_d);
320
+ z -= eyeRecess * Math.exp(-eyeR_d);
321
+
322
+ // brow ridge bumps forward
323
+ const brow_d = (xRel / 0.7) ** 2 + ((yRel - 0.55) / 0.10) ** 2;
324
+ z += 0.045 * Math.exp(-brow_d);
325
+
326
+ // nose — the dominant z bump
327
+ const nose_d = (xRel / 0.18) ** 2 + ((yRel - 0.05) / 0.40) ** 2;
328
+ z += 0.22 * Math.exp(-nose_d);
329
+
330
+ // mouth area pushed slightly forward
331
+ const mouth_d = (xRel / 0.55) ** 2 + ((yRel + 0.45) / 0.20) ** 2;
332
+ z += 0.06 * Math.exp(-mouth_d);
333
+
334
+ // cheekbones
335
+ const cheekL_d = ((xRel + 0.55) / 0.30) ** 2 + ((yRel - 0.05) / 0.28) ** 2;
336
+ const cheekR_d = ((xRel - 0.55) / 0.30) ** 2 + ((yRel - 0.05) / 0.28) ** 2;
337
+ z += 0.04 * Math.exp(-cheekL_d);
338
+ z += 0.04 * Math.exp(-cheekR_d);
339
+
318
340
  return V(x, y, z);
319
341
  }
320
342
 
@@ -585,9 +607,9 @@
585
607
  const spread = config.spread;
586
608
  const p = computeMouthParams();
587
609
  // mouth
588
- applyShape(disp, SHAPES.mouth_jaw_drop, p.jaw, spread);
589
- applyShape(disp, SHAPES.mouth_open_lower, p.open, spread);
590
- applyShape(disp, SHAPES.mouth_open_upper, p.open, spread);
610
+ applyShape(disp, SHAPES.mouth_jaw_drop, p.jaw, spread);
611
+ applyShape(disp, SHAPES.mouth_open_lower, p.open, spread);
612
+ applyShape(disp, SHAPES.mouth_open_upper, p.open * 0.4, spread);
591
613
  const sm = p.smile;
592
614
  if (sm > 0) { applyShape(disp, SHAPES.mouth_smile_L, sm, spread); applyShape(disp, SHAPES.mouth_smile_R, sm, spread); }
593
615
  else if (sm < 0) { applyShape(disp, SHAPES.mouth_frown_L, -sm, spread); applyShape(disp, SHAPES.mouth_frown_R, -sm, spread); }
@@ -611,10 +633,16 @@
611
633
  // brows
612
634
  applyShape(disp, SHAPES.brow_inner_L, state.browInnerUp, spread);
613
635
  applyShape(disp, SHAPES.brow_inner_R, state.browInnerUp, spread);
614
- applyShape(disp, SHAPES.brow_outer_L, Math.max(0, state.browOuterUp), spread);
615
- applyShape(disp, SHAPES.brow_outer_R, Math.max(0, state.browOuterUp), spread);
616
- applyShape(disp, SHAPES.brow_down_L, state.browDown + Math.max(0,-state.browOuterUp), spread);
617
- applyShape(disp, SHAPES.brow_down_R, state.browDown + Math.max(0,-state.browOuterUp), spread);
636
+ // v011: browOuterUp >= 0 lifts outer brow; < 0 drives brow_down at 0.6x
637
+ if (state.browOuterUp >= 0) {
638
+ applyShape(disp, SHAPES.brow_outer_L, state.browOuterUp, spread);
639
+ applyShape(disp, SHAPES.brow_outer_R, state.browOuterUp, spread);
640
+ } else {
641
+ applyShape(disp, SHAPES.brow_down_L, -state.browOuterUp * 0.6, spread);
642
+ applyShape(disp, SHAPES.brow_down_R, -state.browOuterUp * 0.6, spread);
643
+ }
644
+ applyShape(disp, SHAPES.brow_down_L, state.browDown, spread);
645
+ applyShape(disp, SHAPES.brow_down_R, state.browDown, spread);
618
646
  // nose
619
647
  applyShape(disp, SHAPES.nose_sneer_L, state.noseSneer, spread);
620
648
  applyShape(disp, SHAPES.nose_sneer_R, state.noseSneer, spread);