wireface 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -28
- package/dist/wireface.js +10 -4
- package/dist/wireface.min.js +1 -1
- package/examples/demo.html +7 -4
- package/package.json +1 -1
- package/wireface.js +10 -4
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# wireface
|
|
2
2
|
|
|
3
|
-
](https://www.npmjs.com/package/wireface)
|
|
4
|
+
[](https://www.npmjs.com/package/wireface)
|
|
5
|
+
[](https://bundlephobia.com/package/wireface)
|
|
6
|
+
[](https://www.jsdelivr.com/package/npm/wireface)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://github.com/styk-tv/wireface)
|
|
9
|
+
[](https://www.babylonjs.com/)
|
|
4
10
|
|
|
5
|
-
**
|
|
11
|
+
**A drop-in lipsync renderer for stylized character profiles — no rigged avatar, no ML inference, no server roundtrip.** wireface analyses voice or TTS audio in the browser and drives a wireframe face mesh through 28 expression channels (15 visemes + jaw, lips, blinks, eye gaze, squint, brows, nose, head rotation). Each character is one JSON preset — mesh resolution, colors, depth fade, glow, mood weights, channel gains — saved from the bundled editor and replayed by a single JS file. One canvas, one peer dependency (Babylon.js v9), one `createWireface(canvas)` call. Each instance is fully independent, so a page can host as many talking heads as it has audio sources.
|
|
6
12
|
|
|
7
|
-
|
|
13
|
+

|
|
8
14
|
|
|
9
15
|
- repo: <https://github.com/styk-tv/wireface>
|
|
10
16
|
- npm: <https://www.npmjs.com/package/wireface>
|
|
@@ -153,8 +159,9 @@ A preset is one plain object — exactly the shape produced by the editor's **sa
|
|
|
153
159
|
| | `lipPressForce` | `0..N` | "press" force for closure visemes (`PP`, `MM`-like) |
|
|
154
160
|
| | `jawExtend` / `mouthGrow` | offsets | static mouth shape biases |
|
|
155
161
|
| **holes / depth** | `mouthHole` / `eyeHoles` | bool | cut holes in the mesh |
|
|
156
|
-
| | `mouthHoleSize` | `~
|
|
157
|
-
| | `
|
|
162
|
+
| | `mouthHoleSize` | `~0.4..2` | mouth-hole ellipse radius multiplier |
|
|
163
|
+
| | `eyeHoleSize` | `~0.4..2` | eye-hole ellipse radius multiplier (per-eye) |
|
|
164
|
+
| | `eyeDepth` | `0..5+` | how deep eye sockets recess into the parametric warp |
|
|
158
165
|
| | `mouthAnchor` / `eyeAnchor` | bool | pin anchor rings to track shape changes |
|
|
159
166
|
| | `overlayTracksMesh` | bool | minimal-line overlays follow mesh deformation |
|
|
160
167
|
| **style** | `lineColor` | hex | wire color |
|
|
@@ -250,36 +257,27 @@ examples/presets/asset-ydr7de.json → right
|
|
|
250
257
|
|
|
251
258
|
---
|
|
252
259
|
|
|
253
|
-
##
|
|
260
|
+
## Contribute
|
|
254
261
|
|
|
255
|
-
|
|
262
|
+
Issues, PRs, and ideas are very welcome. Anything that's fair game:
|
|
256
263
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
264
|
+
- new viseme / expression channels, or better channel mapping for non-English phonetics
|
|
265
|
+
- mood blends, idle micro-motion presets, eye-look behaviors
|
|
266
|
+
- performance / memory tweaks (smaller draws, tighter geometry rebuilds, WebGPU path)
|
|
267
|
+
- alternative renderers (svg, 2d-canvas) sharing the same channel surface
|
|
268
|
+
- new preset packs (drop them in [`examples/presets/`](examples/presets/))
|
|
269
|
+
- editor UX: keyboard shortcuts, undo, multi-channel keyframing
|
|
270
|
+
- docs, typos, clearer onboarding
|
|
262
271
|
|
|
263
|
-
|
|
272
|
+
Open an [issue](https://github.com/styk-tv/wireface/issues) or send a PR — small ones are perfect.
|
|
264
273
|
|
|
265
|
-
|
|
266
|
-
npm install
|
|
267
|
-
npm run build
|
|
268
|
-
```
|
|
274
|
+
## Show & tell
|
|
269
275
|
|
|
270
|
-
|
|
276
|
+
Built something with wireface? Please share it. There's a dedicated space:
|
|
271
277
|
|
|
272
|
-
|
|
273
|
-
# bump → commit → tag → push tag → CI publishes to npm with provenance
|
|
274
|
-
npm version 1.0.1
|
|
275
|
-
git push --follow-tags
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
The workflow expects an **`NPM_TOKEN`** repo secret (an npm "Automation" token, not "Publish"). Set it once with:
|
|
278
|
+
- 👉 **[GitHub Discussions → Show & Tell](https://github.com/styk-tv/wireface/discussions/categories/show-and-tell)** — drop a screenshot, a video, a CodePen, a deployed URL, or a `.json` preset you're proud of. Other people's presets are the best kind of docs.
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
gh secret set NPM_TOKEN -R styk-tv/wireface
|
|
282
|
-
```
|
|
280
|
+
If you build a public tool / site / experiment with it, a star on the repo is a small thank-you that makes a real difference.
|
|
283
281
|
|
|
284
282
|
---
|
|
285
283
|
|
package/dist/wireface.js
CHANGED
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
meshVisible: true,
|
|
162
162
|
loopAudio: true,
|
|
163
163
|
mouthHole: true, mouthHoleSize: 1.0,
|
|
164
|
-
eyeHoles: false, eyeDepth: 1.0,
|
|
164
|
+
eyeHoles: false, eyeHoleSize: 1.0, eyeDepth: 1.0,
|
|
165
165
|
mouthAnchor: true, eyeAnchor: false,
|
|
166
166
|
lineThickness: 1.0,
|
|
167
167
|
lipVertAmp: 1.6, lipPressForce: 1.0,
|
|
@@ -467,10 +467,15 @@
|
|
|
467
467
|
if (du*du + dv*dv < 1) return false;
|
|
468
468
|
}
|
|
469
469
|
if (config.eyeHoles) {
|
|
470
|
+
// eye-hole ellipse — sized to roughly match the eye feature radius
|
|
471
|
+
// so the cut is visibly meaningful at typical mesh densities.
|
|
472
|
+
// eyeHoleSize is a multiplier (mirrors mouthHoleSize).
|
|
473
|
+
const eRU = 0.105 * config.eyeHoleSize;
|
|
474
|
+
const eRV = 0.075 * config.eyeHoleSize;
|
|
470
475
|
const ucen = (baseUVs[a].u + baseUVs[b].u + baseUVs[c].u) / 3;
|
|
471
476
|
const vcen = (baseUVs[a].v + baseUVs[b].v + baseUVs[c].v) / 3;
|
|
472
|
-
const dl = ((ucen-0.30)/
|
|
473
|
-
const dr = ((ucen-0.70)/
|
|
477
|
+
const dl = ((ucen-0.30)/eRU)**2 + ((vcen-0.40)/eRV)**2;
|
|
478
|
+
const dr = ((ucen-0.70)/eRU)**2 + ((vcen-0.40)/eRV)**2;
|
|
474
479
|
if (dl < 1 || dr < 1) return false;
|
|
475
480
|
}
|
|
476
481
|
return true;
|
|
@@ -1337,6 +1342,7 @@
|
|
|
1337
1342
|
if (rc.mouthHole !== undefined && rc.mouthHole !== config.mouthHole) needRebuild = true;
|
|
1338
1343
|
if (rc.eyeHoles !== undefined && rc.eyeHoles !== config.eyeHoles) needRebuild = true;
|
|
1339
1344
|
if (rc.mouthHoleSize !== undefined && rc.mouthHoleSize !== config.mouthHoleSize) needRebuild = true;
|
|
1345
|
+
if (rc.eyeHoleSize !== undefined && rc.eyeHoleSize !== config.eyeHoleSize) needRebuild = true;
|
|
1340
1346
|
if (rc.eyeDepth !== undefined && rc.eyeDepth !== config.eyeDepth) needRebuild = true;
|
|
1341
1347
|
|
|
1342
1348
|
Object.assign(config, rc);
|
|
@@ -1360,7 +1366,7 @@
|
|
|
1360
1366
|
applyMeshVisibility();
|
|
1361
1367
|
applyMinimalVisibility();
|
|
1362
1368
|
if (rc.lineThickness !== undefined) rebuildMinimalLines();
|
|
1363
|
-
if (rc.irisSize !== undefined)
|
|
1369
|
+
if (rc.irisSize !== undefined || rc.pupils !== undefined) rebuildPupils();
|
|
1364
1370
|
if (rc.lipVertAmp !== undefined || rc.lipPressForce !== undefined) identifyAnchorRings();
|
|
1365
1371
|
}
|
|
1366
1372
|
if (rc.glow !== undefined) applyGlow();
|
package/dist/wireface.min.js
CHANGED
|
@@ -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,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 N=new BABYLON.StandardMaterial("browMat",M);N.emissiveColor=new BABYLON.Color3(1,1,1),N.disableLighting=!0,N.specularColor=new BABYLON.Color3(0,0,0);const S=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)}S.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 V(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 D(){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 U=null,H=[],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(){U&&(U.dispose(),U=null);const e=c.meshCols,o=c.meshRows;H=[],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}),H.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=(T[e].u+T[o].u+T[n].u)/3,r=(T[e].v+T[o].v+T[n].v)/3;if(((t-.3)/.085)**2+((r-.4)/.045)**2<1||((t-.7)/.085)**2+((r-.4)/.045)**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,H.length),U=new BABYLON.Mesh("face",M),U.parent=z;const r=H.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]=H[e].x,E[3*e+1]=H[e].y,E[3*e+2]=H[e].z,H[e].z<K&&(K=H[e].z),H[e].z>X&&(X=H[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(U,!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:V(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(){U&&(U.isVisible=!!c.meshVisible)}function le(){S&&S.getChildMeshes().forEach(e=>e.isVisible=!!c.minimal)}function ue(){if(!U)return;U._edgesRenderer&&U.disableEdgesRendering();const e=c.lineThickness;switch(c.mode){case"wire":U.material=A,A.wireframe=!0,A.alpha=1;break;case"edges":U.material=R,R.alpha=1,R.wireframe=!1,U.enableEdgesRendering(.9999),U.edgesWidth=4*e,U.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1);break;case"shaded":U.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=S),i}let ve=null,Be=null;function be(){const e=D();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 Ne(){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 Se(){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=N,Oe.push({brow:e,mesh:o})}const t=Ne();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(U){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=D();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=H[s].x-n.x,c=H[s].y-n.y,f=H[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=D().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=H[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=D();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=V(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<H.length;e++)E[3*e]=H[e].x+q[e].x,E[3*e+1]=H[e].y+q[e].y,E[3*e+2]=H[e].z+q[e].z;if(U.updateVerticesData(BABYLON.VertexBuffer.PositionKind,E),c.depthFade>.001){const e=X-K||1,o=c.depthFade;for(let t=0;t<H.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}U.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z)}else if(Q){for(let e=0;e<H.length;e++)Z[4*e]=W[0],Z[4*e+1]=W[1],Z[4*e+2]=W[2],Z[4*e+3]=1;U.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z),Q=!1}"edges"!==c.mode&&"shaded"!==c.mode||(BABYLON.VertexData.ComputeNormals(E,I,G),U.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=Ne();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(),Ve=0,De=.8+2*Math.random(),Ue=0,He=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]),U&&U._edgesRenderer&&(U.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,N.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(),Se(),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){Ve+=e,Ve>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),Ve=0,je=1.5+3.5*Math.random()),Ue+=e,Ue>De&&!y.eyeLookH&&(He=.6*(Math.random()-.5),Te=.4*(Math.random()-.5),Ue=0,De=.7+2.5*Math.random()),w.eyeLookH=He,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.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(),Se(),we()):(ue(),se(),ae(),le(),void 0!==o.lineThickness&&Se(),void 0!==o.irisSize&&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 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);
|
package/examples/demo.html
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<!--
|
|
3
|
-
wireface
|
|
3
|
+
wireface — two-instance demo for wireface.js
|
|
4
|
+
Repository: https://github.com/styk-tv/wireface
|
|
5
|
+
npm: https://www.npmjs.com/package/wireface
|
|
4
6
|
Copyright (c) 2026 Peter Styk
|
|
5
7
|
Released under the MIT License — see LICENSE in the repository root.
|
|
6
8
|
-->
|
|
@@ -184,9 +186,10 @@
|
|
|
184
186
|
</section>
|
|
185
187
|
</main>
|
|
186
188
|
|
|
187
|
-
<!-- Babylon (peer)
|
|
188
|
-
<script src="https://cdn.
|
|
189
|
-
|
|
189
|
+
<!-- Babylon (peer) — pinned to v9 for reproducibility -->
|
|
190
|
+
<script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
|
|
191
|
+
<!-- library — for local file:// runs use ./wireface.js, for CDN use the URL below -->
|
|
192
|
+
<script src="../wireface.js"></script>
|
|
190
193
|
|
|
191
194
|
<script>
|
|
192
195
|
/* Mount one wireface instance per panel and wire per-instance drag-drop +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wireface",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Minimal embeddable wireframe lipsync face renderer — drives expressive character profiles from voice or TTS audio in the browser.",
|
|
5
5
|
"main": "wireface.js",
|
|
6
6
|
"browser": "wireface.js",
|
package/wireface.js
CHANGED
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
meshVisible: true,
|
|
162
162
|
loopAudio: true,
|
|
163
163
|
mouthHole: true, mouthHoleSize: 1.0,
|
|
164
|
-
eyeHoles: false, eyeDepth: 1.0,
|
|
164
|
+
eyeHoles: false, eyeHoleSize: 1.0, eyeDepth: 1.0,
|
|
165
165
|
mouthAnchor: true, eyeAnchor: false,
|
|
166
166
|
lineThickness: 1.0,
|
|
167
167
|
lipVertAmp: 1.6, lipPressForce: 1.0,
|
|
@@ -467,10 +467,15 @@
|
|
|
467
467
|
if (du*du + dv*dv < 1) return false;
|
|
468
468
|
}
|
|
469
469
|
if (config.eyeHoles) {
|
|
470
|
+
// eye-hole ellipse — sized to roughly match the eye feature radius
|
|
471
|
+
// so the cut is visibly meaningful at typical mesh densities.
|
|
472
|
+
// eyeHoleSize is a multiplier (mirrors mouthHoleSize).
|
|
473
|
+
const eRU = 0.105 * config.eyeHoleSize;
|
|
474
|
+
const eRV = 0.075 * config.eyeHoleSize;
|
|
470
475
|
const ucen = (baseUVs[a].u + baseUVs[b].u + baseUVs[c].u) / 3;
|
|
471
476
|
const vcen = (baseUVs[a].v + baseUVs[b].v + baseUVs[c].v) / 3;
|
|
472
|
-
const dl = ((ucen-0.30)/
|
|
473
|
-
const dr = ((ucen-0.70)/
|
|
477
|
+
const dl = ((ucen-0.30)/eRU)**2 + ((vcen-0.40)/eRV)**2;
|
|
478
|
+
const dr = ((ucen-0.70)/eRU)**2 + ((vcen-0.40)/eRV)**2;
|
|
474
479
|
if (dl < 1 || dr < 1) return false;
|
|
475
480
|
}
|
|
476
481
|
return true;
|
|
@@ -1337,6 +1342,7 @@
|
|
|
1337
1342
|
if (rc.mouthHole !== undefined && rc.mouthHole !== config.mouthHole) needRebuild = true;
|
|
1338
1343
|
if (rc.eyeHoles !== undefined && rc.eyeHoles !== config.eyeHoles) needRebuild = true;
|
|
1339
1344
|
if (rc.mouthHoleSize !== undefined && rc.mouthHoleSize !== config.mouthHoleSize) needRebuild = true;
|
|
1345
|
+
if (rc.eyeHoleSize !== undefined && rc.eyeHoleSize !== config.eyeHoleSize) needRebuild = true;
|
|
1340
1346
|
if (rc.eyeDepth !== undefined && rc.eyeDepth !== config.eyeDepth) needRebuild = true;
|
|
1341
1347
|
|
|
1342
1348
|
Object.assign(config, rc);
|
|
@@ -1360,7 +1366,7 @@
|
|
|
1360
1366
|
applyMeshVisibility();
|
|
1361
1367
|
applyMinimalVisibility();
|
|
1362
1368
|
if (rc.lineThickness !== undefined) rebuildMinimalLines();
|
|
1363
|
-
if (rc.irisSize !== undefined)
|
|
1369
|
+
if (rc.irisSize !== undefined || rc.pupils !== undefined) rebuildPupils();
|
|
1364
1370
|
if (rc.lipVertAmp !== undefined || rc.lipPressForce !== undefined) identifyAnchorRings();
|
|
1365
1371
|
}
|
|
1366
1372
|
if (rc.glow !== undefined) applyGlow();
|