wireface 1.1.5 → 1.3.0
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 +58 -5
- package/dist/wireface.js +767 -63
- package/dist/wireface.min.js +1 -1
- package/examples/behaviours.html +164 -0
- package/examples/editor.html +15 -0
- package/examples/playground-snippet.js +68 -0
- package/examples/playground.html +70 -10
- package/package.json +3 -1
- package/wireface.js +767 -63
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}},n=Object.keys(o),t={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},i={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},r=Object.keys(i),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],l={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(t).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},a={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeHoleSize:1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",mouthColor:null,eyeColor:null,noseColor:null,minimalMouth:!0,minimalEyes:!0,minimalNose:!0,minimalBrows:!0,mouthLineThickness:1,eyeLineThickness:1,noseLineThickness:1,browLineThickness:1,baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,depthFadeCurve:1,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,upperJawProtrude:0,lowerJawProtrude:0,cameraView:"three-q"};function c(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function d(e,d){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const h=Object.assign({},u,d||{}),f=(e,o,n)=>new BABYLON.Vector3(e,o,n),m={};for(const e of Object.keys(a)){const o=a[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};n.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const v={},g={};for(const e of r)v[e]=0,g[e]=0;v.neutral=1,g.neutral=1;let b="neutral";const B=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),C=new BABYLON.Scene(B,{useRightHandedSystem:!0});C.useRightHandedSystem=!0,C.clearColor=new BABYLON.Color4(0,0,0,1),C.skipPointerMovePicking=!0;const L=new BABYLON.GlowLayer("glow",C,{mainTextureFixedSize:1024,blurKernelSize:32});L.intensity=0;const x=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),C);x.minZ=.1,x.maxZ=100,x.lowerRadiusLimit=1.5,x.upperRadiusLimit=12,x.wheelDeltaPercentage=.01;const M=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}x.attachControl(e,!0);try{navigator.getGamepads=M}catch(e){}const k=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),C);k.intensity=.9,k.groundColor=new BABYLON.Color3(.1,.1,.14);const O=new BABYLON.TransformNode("faceRoot",C),z=new BABYLON.StandardMaterial("faceMat",C);z.diffuseColor=new BABYLON.Color3(.05,.05,.07),z.emissiveColor=new BABYLON.Color3(.012,.012,.02),z.specularColor=new BABYLON.Color3(.2,.22,.28),z.specularPower=48,z.backFaceCulling=!1,z.useVertexColor=!0;const R=new BABYLON.StandardMaterial("wireMat",C);function A(e){const o=new BABYLON.StandardMaterial(e,C);return o.emissiveColor=new BABYLON.Color3(1,1,1),o.disableLighting=!0,o.specularColor=new BABYLON.Color3(0,0,0),o}R.emissiveColor=new BABYLON.Color3(1,1,1),R.disableLighting=!0,R.wireframe=!0,R.backFaceCulling=!1,R.alpha=1,R.useVertexColor=!0;const N=A("mouthMat"),S=A("eyeMat"),P=A("noseMat"),T=A("browMat"),Y=new BABYLON.TransformNode("minimal",C);function j(e,o){const n=2*(e-.5),t=2*(.5-o),i=.95*t,r=Math.max(0,1-i*i);let s=n*(.8*Math.sqrt(r)),l=1*t;t<-.4&&(l=1.55*(t+.4)-.4),t>.7&&(l=.7+.45*(t-.7));let a=.22*(1-n*n*.55-t*t*.55);a<-.05&&(a=-.05);const u=((n+.45)/.3)**2+((t-.2)/.18)**2,c=((n-.45)/.3)**2+((t-.2)/.18)**2,d=.045*h.eyeDepth;a-=d*Math.exp(-u),a-=d*Math.exp(-c);const m=(n/.7)**2+((t-.55)/.1)**2;a+=.045*Math.exp(-m);const p=(n/.18)**2+((t-.05)/.4)**2;a+=.22*Math.exp(-p);const w=(n/.55)**2+((t+.45)/.2)**2;a+=.06*Math.exp(-w);const y=((n+.55)/.3)**2+((t-.05)/.28)**2,_=((n-.55)/.3)**2+((t-.05)/.28)**2;return a+=.04*Math.exp(-y),a+=.04*Math.exp(-_),f(s,l,a)}Y.parent=O;const H=j(.5,.69);function V(e,o,n){const t=H.x,i=H.y,r=H.z,s=.27*(1+.4*n.width)*(1-.4*n.round),l=h.lipVertAmp,a=h.lipPressForce,u=.16*n.open*l,c=.012*n.lipPress*l*a,d=.09*n.jaw*l,m=.05*n.smile,p=.07*n.round,w=.007*(1-.55*n.lipPress),y=.022*(1-.55*n.lipPress);let _;if(o){const e=i+u/2-c+.4*m;_=[[-1,i+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,i+m,.5*-p]]}else{const e=i-u/2+c-d;_=[[-1,i+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,i+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let v=0;for(;v<_.length-1&&e>_[v+1][0];)v++;v=Math.min(v,_.length-2);const g=(e-_[v][0])/(_[v+1][0]-_[v][0]),b=_[v][1]*(1-g)+_[v+1][1]*g,B=_[v][2]*(1-g)+_[v+1][2]*g;return f(t+e*s,b,r+B)}function U(e,o,n,t,i){const r=(e+1)/2*Math.PI,s=n.center.x+Math.cos(Math.PI-r)*n.hw,l=.012*i,a=(n.center.y+(o?1:-1)*Math.sin(r)*n.hh)*(1-t)+n.center.y*t+(o?-l:.5*l),u=n.center.z+.018+.012*Math.sin(r);return f(s,a,u)}function D(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const n of Object.keys(t)){const i=p["viseme_"+n]||0;if(i<=0)continue;e+=i;const r=t[n];o.open+=r.open*i,o.width+=r.width*i,o.round+=r.round*i,o.smile+=r.smile*i,o.lipPress+=r.lipPress*i,o.jaw+=r.jaw*i}if(e>1){const n=1/e;o.open*=n,o.width*=n,o.round*=n,o.smile*=n,o.lipPress*=n,o.jaw*=n}o.smile+=p.mouthSmile;const n=p.mouthPucker;return o.round+=.7*n,o.width+=.4*-n,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let F=null,I=[],E=[],q=[],G=[],Z=null,K=null,J=null,X=null,W=0,Q=0,$=[1,1,1],ee=[0,0,0],oe=!1,ne=[],te=[];const ie={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function re(){F&&(F.dispose(),F=null);const e=h.meshCols,o=h.meshRows;I=[],E=[],q=[];for(let n=0;n<o;n++)for(let t=0;t<e;t++){const i=t/(e-1),r=n/(o-1);E.push({u:i,v:r}),I.push(j(i,r))}const n=e=>{if(!h.fragment)return!0;const o=2*(E[e].u-.5),n=2*(.5-E[e].v);return o*o*1.2+n*n*.95<1},t=(e,o,t)=>{((e,o,t)=>{if(!n(e)||!n(o)||!n(t))return!1;if(h.mouthHole){const n=.5,i=.69,r=.18*h.mouthHoleSize,s=.075*h.mouthHoleSize,l=((E[e].u+E[o].u+E[t].u)/3-n)/r,a=((E[e].v+E[o].v+E[t].v)/3-i)/s;if(l*l+a*a<1)return!1}if(h.eyeHoles){const n=.105*h.eyeHoleSize,i=.075*h.eyeHoleSize,r=(E[e].u+E[o].u+E[t].u)/3,s=(E[e].v+E[o].v+E[t].v)/3;if(((r-.3)/n)**2+((s-.4)/i)**2<1||((r-.7)/n)**2+((s-.4)/i)**2<1)return!1}return!0})(e,o,t)&&q.push(e,o,t)};for(let n=0;n<o-1;n++)for(let o=0;o<e-1;o++){const i=n*e+o,r=n*e+(o+1),s=(n+1)*e+o,l=(n+1)*e+(o+1);(n+o)%2==0?(t(i,r,l),t(i,l,s)):(t(i,r,s),t(r,l,s))}G=function(e,o){const n=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const t=e[o],i=e[o+1],r=e[o+2];n[t].add(i),n[t].add(r),n[i].add(t),n[i].add(r),n[r].add(t),n[r].add(i)}return n.map(e=>Array.from(e))}(q,I.length),F=new BABYLON.Mesh("face",C),F.parent=O;const i=I.length;K=new Float32Array(3*i),J=new Float32Array(3*i),X=new Float32Array(4*i),Z=new Array(i),W=1/0,Q=-1/0;for(let e=0;e<i;e++)K[3*e]=I[e].x,K[3*e+1]=I[e].y,K[3*e+2]=I[e].z,I[e].z<W&&(W=I[e].z),I[e].z>Q&&(Q=I[e].z),Z[e]=f(0,0,0),X[4*e]=1,X[4*e+1]=1,X[4*e+2]=1,X[4*e+3]=1;BABYLON.VertexData.ComputeNormals(K,q,J);const r=new BABYLON.VertexData;r.positions=Array.from(K),r.indices=q,r.normals=Array.from(J),r.colors=Array.from(X),r.applyToMesh(F,!0),he(),ue(),ce(),se(),oe=!0}function se(){ne=[],te=[];const e=.18*h.mouthHoleSize,o=.075*h.mouthHoleSize;for(let n=0;n<E.length;n++){const t=(E[n].u-.5)/e,i=(E[n].v-.69)/o,r=t*t+i*i;if(r<4){const e=E[n].v<.69,o=Math.max(-1,Math.min(1,t));let i=r<=1?r:(4-r)/3;i=Math.max(0,Math.min(1,i)),ne.push({idx:n,isUpper:e,xRel:o,weight:i,baselineTarget:V(o,e,ie)})}}const n=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of n)for(let o=0;o<E.length;o++){const n=(E[o].u-e.cu)/e.ru,t=(E[o].v-e.cv)/e.rv,i=n*n+t*t;if(i<4){const t=E[o].v<e.cv,r=Math.max(-1,Math.min(1,n));let s=i<=1?i:(4-i)/3;s=Math.max(0,Math.min(1,s));const l=j(e.cu,e.cv);te.push({idx:o,side:e.side,isUpper:t,xRel:r,weight:s,eyeDef:{center:l,hw:e.hw,hh:e.hh},baselineTarget:U(r,t,{center:l,hw:e.hw,hh:e.hh},0,0)})}}}function le(e,o,n,t){if(Math.abs(n)<.001)return;const i=o.uv[0],r=o.uv[1],s=o.radius*t,l=s*s,a=o.dir.x*n,u=o.dir.y*n,c=o.dir.z*n;for(let o=0;o<E.length;o++){const n=E[o].u-i,t=E[o].v-r,s=n*n+t*t;if(s>4*l)continue;const d=Math.exp(-s/l);e[o].x+=a*d,e[o].y+=u*d,e[o].z+=c*d}}const ae=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return h.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return h.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return h.scaleMouth}}];function ue(){O&&(O.rotation.y=h.flipFace?Math.PI:0)}function ce(){F&&(F.isVisible=!!h.meshVisible)}function de(){Y&&Y.getChildMeshes().forEach(e=>e.isVisible=!!h.minimal)}function he(){if(!F)return;F._edgesRenderer&&F.disableEdgesRendering();const e=h.lineThickness;switch(h.mode){case"wire":F.material=R,R.wireframe=!0,R.alpha=1;break;case"edges":F.material=z,z.alpha=1,z.wireframe=!1,F.enableEdgesRendering(.9999),F.edgesWidth=4*e,F.edgesColor=new BABYLON.Color4($[0],$[1],$[2],1);break;case"shaded":F.material=z,z.alpha=1,z.wireframe=!1}}let fe=null,me=null,pe=null,we=null,ye=null,_e=null;function ve(){if(me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),ye&&(ye.dispose(),ye=null),_e&&(_e.dispose(),_e=null),!h.pupils)return;fe||(fe=new BABYLON.StandardMaterial("pupilMat",C),fe.emissiveColor=BABYLON.Color3.FromHexString(h.pupilColor),fe.disableLighting=!0,fe.backFaceCulling=!1),we||(we=new BABYLON.StandardMaterial("irisMat",C),we.emissiveColor=BABYLON.Color3.FromHexString(h.irisColor),we.disableLighting=!0,we.backFaceCulling=!1);const e=.035*h.irisSize;ye=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},C),_e=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},C),ye.material=_e.material=we,ye.parent=_e.parent=O,me=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},C),pe=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},C),me.material=pe.material=fe,me.parent=pe.parent=O}function ge(e,o){const n=j(e,o);if(!h.overlayTracksMesh)return n;const t=function(e,o){if(!Z)return f(0,0,0);const n=.0036;let t=0,i=0,r=0,s=0;for(let l=0;l<E.length;l++){const a=E[l].u-e,u=E[l].v-o,c=a*a+u*u;if(c<n){const e=1-Math.sqrt(c/n);t+=e,i+=Z[l].x*e,r+=Z[l].y*e,s+=Z[l].z*e}}return 0===t?f(0,0,0):f(i/t,r/t,s/t)}(e,o);return f(n.x+t.x,n.y+t.y,n.z+t.z)}function be(e,o=18){const n=[],t=e.length,i=o=>e[Math.max(0,Math.min(t-1,o))];for(let e=0;e<t-1;e++){const t=i(e-1),r=i(e),s=i(e+1),l=i(e+2);for(let e=0;e<o;e++){const i=e/o,a=i*i,u=i*a,c=.5*(2*r.x+(-t.x+s.x)*i+(2*t.x-5*r.x+4*s.x-l.x)*a+(-t.x+3*r.x-3*s.x+l.x)*u),d=.5*(2*r.y+(-t.y+s.y)*i+(2*t.y-5*r.y+4*s.y-l.y)*a+(-t.y+3*r.y-3*s.y+l.y)*u),h=.5*(2*r.z+(-t.z+s.z)*i+(2*t.z-5*r.z+4*s.z-l.z)*a+(-t.z+3*r.z-3*s.z+l.z)*u);n.push(f(c,d,h))}}return n.push(e[t-1]),n}function Be(e,o,n,t,i,r){const s={path:o,radius:n*(null==i?1:i)*h.lineThickness,tessellation:6,updatable:!0};r&&(s.instance=r);const l=BABYLON.MeshBuilder.CreateTube(e,s,C);return r||(l.material=t||N,l.parent=Y),l}let Ce=null,Le=null;function xe(){const e=D();return{upper:be([-1,-.45,0,.45,1].map(o=>V(o,!0,e)),18),lower:be([-1,-.5,0,.5,1].map(o=>V(o,!1,e)),18)}}const Me=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let ke=[];function Oe(e,o){const n="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,t=p.eyeSquint,i=ge(e.uv[0],e.uv[1]),r=[],s=.012*t;for(let t=0;t<=12;t++){const l=t/12*Math.PI,a=i.x+Math.cos(Math.PI-l)*e.hw,u=(i.y+(o?1:-1)*Math.sin(l)*e.hh)*(1-n)+i.y*n+(o?-s:.5*s),c=i.z+.018+.012*Math.sin(l);r.push(f(a,u,c))}return r}const ze=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Re=[];function Ae(e){const o=ge(e.uv[0],e.uv[1]),n="L"===e.side?-1:1,t=.085*p.browInnerUp-.05*p.browDown,i=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,r=o.x+-.1*n,s=o.x,l=o.x+.1*n,a=o.y+t,u=o.y+.5*(t+i)+.005,c=o.y+i-.005,d=o.z+.018;return be([f(r,a,d),f(s,u,d+.01),f(l,c,d)],12)}let Ne=null,Se=null,Pe=null;function Te(){const e=.025*p.noseSneer,o=ge(.5,.4),n=ge(.5,.55),t=be([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+n.y),.5*(o.z+n.z)+.05),f(n.x,n.y+.03,n.z+.05)],14),i=n.y+.01;return{bridge:t,leftN:be([f(n.x,i,n.z+.05),f(n.x-.06-e,i-.03,n.z+.02),f(n.x-.04,i-.05,n.z+.005),f(n.x-.01,i-.02,n.z+.03)],10),rightN:be([f(n.x,i,n.z+.05),f(n.x+.06+e,i-.03,n.z+.02),f(n.x+.04,i-.05,n.z+.005),f(n.x+.01,i-.02,n.z+.03)],10)}}function Ye(){Ce&&(Ce.dispose(),Ce=null),Le&&(Le.dispose(),Le=null);for(const e of ke)e.upper.dispose(),e.lower.dispose();ke=[];for(const e of Re)e.mesh.dispose();Re=[],Ne&&(Ne.dispose(),Ne=null),Se&&(Se.dispose(),Se=null),Pe&&(Pe.dispose(),Pe=null);const{upper:e,lower:o}=xe();Ce=Be("mouth_u",e,.01,N,h.mouthLineThickness),Le=Be("mouth_l",o,.01,N,h.mouthLineThickness);for(const e of Me){const o=Be("eye_"+e.side+"_u",Oe(e,!0),.0085,S,h.eyeLineThickness),n=Be("eye_"+e.side+"_l",Oe(e,!1),.0085,S,h.eyeLineThickness);ke.push({eye:e,upper:o,lower:n})}for(const e of ze){const o=Be("brow_"+e.side,Ae(e),.011,T,h.browLineThickness);Re.push({brow:e,mesh:o})}const n=Te();Ne=Be("nose_b",n.bridge,.009,P,h.noseLineThickness),Se=Be("nose_l",n.leftN,.0085,P,h.noseLineThickness),Pe=Be("nose_r",n.rightN,.0085,P,h.noseLineThickness),de(),uo()}const je={};function He(){if(!F)return;for(let e=0;e<n.length;e++){const o=n[e];je[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<Z.length;e++)Z[e].x=Z[e].y=Z[e].z=0;!function(e){const o=h.spread,n=D();le(e,m.mouth_jaw_drop,n.jaw,o),le(e,m.mouth_open_lower,n.open,o),le(e,m.mouth_open_upper,.4*n.open,o);const t=n.smile;t>0?(le(e,m.mouth_smile_L,t,o),le(e,m.mouth_smile_R,t,o)):t<0&&(le(e,m.mouth_frown_L,-t,o),le(e,m.mouth_frown_R,-t,o)),le(e,m.mouth_round_L,n.round,o),le(e,m.mouth_round_R,n.round,o),le(e,m.mouth_round_top,n.round,o),le(e,m.mouth_round_bot,n.round,o),le(e,m.mouth_press_top,n.lipPress,o),le(e,m.mouth_press_bot,n.lipPress,o),n.width>0&&(le(e,m.mouth_width_L,n.width,o),le(e,m.mouth_width_R,n.width,o)),le(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),le(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),le(e,m.eye_blink_R_up,p.eyeBlinkRight,o),le(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),le(e,m.eye_squint_L,p.eyeSquint,o),le(e,m.eye_squint_R,p.eyeSquint,o),le(e,m.brow_inner_L,p.browInnerUp,o),le(e,m.brow_inner_R,p.browInnerUp,o),p.browOuterUp>=0?(le(e,m.brow_outer_L,p.browOuterUp,o),le(e,m.brow_outer_R,p.browOuterUp,o)):(le(e,m.brow_down_L,.6*-p.browOuterUp,o),le(e,m.brow_down_R,.6*-p.browOuterUp,o)),le(e,m.brow_down_L,p.browDown,o),le(e,m.brow_down_R,p.browDown,o),le(e,m.nose_sneer_L,p.noseSneer,o),le(e,m.nose_sneer_R,p.noseSneer,o)}(Z),h.reactivity>0&&function(e,o){if(o<=0)return;const n=e.length,t=new Array(n);for(let i=0;i<n;i++){const n=G[i];if(0===n.length){t[i]=f(e[i].x,e[i].y,e[i].z);continue}let r=0,s=0,l=0;for(const o of n)r+=e[o].x,s+=e[o].y,l+=e[o].z;r/=n.length,s/=n.length,l/=n.length,t[i]=f(e[i].x*(1-o)+r*o,e[i].y*(1-o)+s*o,e[i].z*(1-o)+l*o)}for(let o=0;o<n;o++)e[o].x=t[o].x,e[o].y=t[o].y,e[o].z=t[o].z}(Z,h.reactivity),function(e){for(const o of ae){const n=o.scale;if(Math.abs(n-1)<.001)continue;const t=j(o.uv[0],o.uv[1]),i=o.radiusUV*o.radiusUV,r=4*i;for(let s=0;s<E.length;s++){const l=E[s].u-o.uv[0],a=E[s].v-o.uv[1],u=l*l+a*a;if(u>r)continue;const c=Math.exp(-u/i),d=I[s].x-t.x,h=I[s].y-t.y,f=I[s].z-t.z,m=(n-1)*c;e[s].x+=d*m,e[s].y+=h*m,e[s].z+=f*m}}}(Z),function(e){const o=h.jawExtend;if(o<.001)return;const n=p.jawOpen||0;if(n<.001)return;const t=n*o*.1;for(let o=0;o<E.length;o++){const n=E[o].v;if(n<.55)continue;const i=Math.min(1,(n-.55)/.45);e[o].z+=t*i}}(Z),function(e){const o=h.mouthGrow;if(o<.001)return;const n=D().open;if(n<.001)return;const t=n*o,i=.0625;for(let o=0;o<E.length;o++){const n=E[o].u-.5,r=E[o].v-.69,s=n*n+r*r;if(s>i)continue;const l=1-Math.sqrt(s/i),a=I[o];e[o].x+=(a.x-H.x)*t*l*.4,e[o].y+=(a.y-H.y)*t*l*.4,e[o].z+=t*l*.05}}(Z),function(e){const o=h.upperJawProtrude;if(o<.001)return;const n=.18*o;for(let o=0;o<E.length;o++){const t=E[o].v;if(t<.45||t>.72)continue;const i=t<.62?(t-.45)/.17:(.72-t)/.1;e[o].z+=n*i}}(Z),function(e){const o=h.lowerJawProtrude;if(o<.001)return;const n=.18*o;for(let o=0;o<E.length;o++){const t=E[o].v;if(t<.7)continue;let i;i=t<.85?(t-.7)/.15:1-(t-.85)/.3,i<0&&(i=0),e[o].z+=n*i}}(Z),function(e){if(!h.mouthAnchor)return;const o=D();for(const n of ne){const t=V(n.xRel,n.isUpper,o),i=t.x-n.baselineTarget.x,r=t.y-n.baselineTarget.y,s=t.z-n.baselineTarget.z,l=n.weight;e[n.idx].x=e[n.idx].x*(1-l)+i*l,e[n.idx].y=e[n.idx].y*(1-l)+r*l,e[n.idx].z=e[n.idx].z*(1-l)+s*l}}(Z),function(e){if(!h.eyeAnchor)return;const o=p.eyeBlinkLeft,n=p.eyeBlinkRight,t=p.eyeSquint;for(const i of te){const r="L"===i.side?o:n,s=U(i.xRel,i.isUpper,i.eyeDef,r,t),l=s.x-i.baselineTarget.x,a=s.y-i.baselineTarget.y,u=s.z-i.baselineTarget.z,c=i.weight;e[i.idx].x=e[i.idx].x*(1-c)+l*c,e[i.idx].y=e[i.idx].y*(1-c)+a*c,e[i.idx].z=e[i.idx].z*(1-c)+u*c}}(Z);for(let e=0;e<I.length;e++)K[3*e]=I[e].x+Z[e].x,K[3*e+1]=I[e].y+Z[e].y,K[3*e+2]=I[e].z+Z[e].z;if(F.updateVerticesData(BABYLON.VertexBuffer.PositionKind,K),h.depthFade>.001){const e=Q-W||1,o=h.depthFade,n=h.depthFadeCurve>0?h.depthFadeCurve:1;for(let t=0;t<I.length;t++){const i=K[3*t+2];let r=(Q-i)/e;r<0?r=0:r>1&&(r=1),1!==n&&(r=Math.pow(r,n)),r*=o,X[4*t]=$[0]*(1-r)+ee[0]*r,X[4*t+1]=$[1]*(1-r)+ee[1]*r,X[4*t+2]=$[2]*(1-r)+ee[2]*r,X[4*t+3]=1}F.updateVerticesData(BABYLON.VertexBuffer.ColorKind,X)}else if(oe){for(let e=0;e<I.length;e++)X[4*e]=$[0],X[4*e+1]=$[1],X[4*e+2]=$[2],X[4*e+3]=1;F.updateVerticesData(BABYLON.VertexBuffer.ColorKind,X),oe=!1}"edges"!==h.mode&&"shaded"!==h.mode||(BABYLON.VertexData.ComputeNormals(K,q,J),F.updateVerticesData(BABYLON.VertexBuffer.NormalKind,J)),function(){if(!me||!pe)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,n=j(.3,.4),t=j(.7,.4);ye&&_e&&(ye.position.set(n.x+.6*e,n.y+.6*o,n.z+.045),_e.position.set(t.x+.6*e,t.y+.6*o,t.z+.045)),me.position.set(n.x+e,n.y+o,n.z+.05),pe.position.set(t.x+e,t.y+o,t.z+.05);const i=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);me.isVisible=pe.isVisible=i<.85,ye&&_e&&(ye.isVisible=_e.isVisible=i<.85)}(),h.minimal&&function(){if(!Ce)return;const e=xe();Be("",e.upper,.01,null,h.mouthLineThickness,Ce),Be("",e.lower,.01,null,h.mouthLineThickness,Le);for(const e of ke)Be("",Oe(e.eye,!0),.0085,null,h.eyeLineThickness,e.upper),Be("",Oe(e.eye,!1),.0085,null,h.eyeLineThickness,e.lower);for(const e of Re)Be("",Ae(e.brow),.011,null,h.browLineThickness,e.mesh);const o=Te();Be("",o.bridge,.009,null,h.noseLineThickness,Ne),Be("",o.leftN,.0085,null,h.noseLineThickness,Se),Be("",o.rightN,.0085,null,h.noseLineThickness,Pe)}();const e=h.flipFace?Math.PI:0;O.rotation.x=.35*p.headRotateX,O.rotation.y=e+.5*p.headRotateY,O.rotation.z=.3*p.headRotateZ;for(let e=0;e<n.length;e++)p[n[e]]=je[n[e]]}let Ve=1.5+3*Math.random(),Ue=0,De=.8+2*Math.random(),Fe=0,Ie=0,Ee=0,qe=0;let Ge=null,Ze=null,Ke=null,Je=null,Xe=0,We=0,Qe=!1,$e=null;function eo(){Ge||(Ge=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Ge.state&&Ge.resume()}function oo(){if(Ke){try{Ke.stop()}catch(e){}try{Ke.disconnect()}catch(e){}Ke=null}if(Je){try{Je.disconnect()}catch(e){}Je=null}Qe=!1}function no(){return Ge&&Ze?Qe?Ge.currentTime-Xe:We||0:0}function to(e,o){if(!$e)return 0;const n=Ge.sampleRate/2/$e.length,t=Math.max(0,Math.floor(e/n)),i=Math.min($e.length-1,Math.ceil(o/n));let r=0,s=0;for(let e=t;e<=i;e++)r+=$e[e],s++;return s?r/s/255:0}function io(e){h.lineColor=e;const o=BABYLON.Color3.FromHexString(e);h.mouthColor||(N.emissiveColor=o),h.eyeColor||(S.emissiveColor=o),h.noseColor||(P.emissiveColor=o)}function ro(e){h.mouthColor=e,N.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function so(e){h.eyeColor=e,S.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function lo(e){h.noseColor=e,P.emissiveColor=BABYLON.Color3.FromHexString(e||h.lineColor)}function ao(e){h.browColor=e,T.emissiveColor=BABYLON.Color3.FromHexString(e)}function uo(){const e=(e,o)=>{e&&(e.isVisible=o)};e(Ce,!!h.minimalMouth),e(Le,!!h.minimalMouth);for(const o of ke)e(o.upper,!!h.minimalEyes),e(o.lower,!!h.minimalEyes);for(const o of Re)e(o.mesh,!!h.minimalBrows);e(Ne,!!h.minimalNose),e(Se,!!h.minimalNose),e(Pe,!!h.minimalNose)}function co(e){h.pupilColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function ho(e){h.baseColor=e,$=c(e),oe=!0,R.emissiveColor=new BABYLON.Color3($[0],$[1],$[2]),F&&F._edgesRenderer&&(F.edgesColor=new BABYLON.Color4($[0],$[1],$[2],1))}function fo(e){h.fadeColor=e,ee=c(e),oe=!0}function mo(e){h.irisColor=e,we&&(we.emissiveColor=BABYLON.Color3.FromHexString(e))}const po={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let wo=!1;function yo(e){if("orbit"===e)return void(wo=!0);wo=!1;const o=po[e];o&&(x.alpha=o.alpha,x.beta=o.beta,x.radius=o.radius)}function _o(){L.intensity=h.glow?.85:0}re(),ve(),Ye(),ho(h.baseColor),fo(h.fadeColor),io(h.lineColor),ao(h.browColor),h.mouthColor&&ro(h.mouthColor),h.eyeColor&&so(h.eyeColor),h.noseColor&&lo(h.noseColor),co(h.pupilColor),mo(h.irisColor),uo(),_o(),yo(h.cameraView);let vo=performance.now(),go=!1;B.runRenderLoop(()=>{if(go)return;const e=performance.now(),o=Math.min(.05,(e-vo)/1e3);vo=e,function(e){Ue+=e,Ue>Ve&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=g.sleep>.5?1:0,w.eyeBlinkRight=g.sleep>.5?1:0},110),Ue=0,Ve=1.5+3.5*Math.random()),Fe+=e,Fe>De&&!y.eyeLookH&&(Ie=.6*(Math.random()-.5),Ee=.4*(Math.random()-.5),Fe=0,De=.7+2.5*Math.random()),w.eyeLookH=Ie,w.eyeLookV=Ee,qe+=e,w.headRotateX=.04*Math.sin(.27*qe),w.headRotateY=.06*Math.sin(.19*qe),w.headRotateZ=.03*Math.sin(.11*qe)}(o),Qe&&function(){if(!Je)return;Je.getByteFrequencyData($e);const e=to(200,700),o=to(700,2e3),n=to(2e3,4e3),i=to(4e3,8e3),r=to(1500,5e3),s=Math.max(e,o,n,i);if(s<.08){for(const e of Object.keys(t))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(t))"sil"!==e&&(w["viseme_"+e]=0);const l=e+o+n+i+1e-6;i>.2&&(w.viseme_SS=Math.min(1,1.4*i),r>.2&&(w.viseme_FF=Math.min(.7,.9*r)));const a=e/l,u=o/l,c=n/l;e>o&&e>.18?(w.viseme_O=Math.min(1,1.1*e*(n<.2?1.1:.8)),w.viseme_aa=Math.min(1,u*s*1.6),n<.18&&(w.viseme_U=Math.min(.7,.9*e))):o>=.9*e&&(w.viseme_aa=Math.min(1,a*s*1.6),w.viseme_E=Math.min(1,u*s*1.4),n>.18&&(w.viseme_I=Math.min(1,c*s*1.5)))}(),function(e){const o=Math.max(.05,h.moodTransitionTime)/4,n=1-Math.pow(.5,e/o);for(const e of r)g[e]+=(v[e]-g[e])*n;for(const e of s){let o=0;for(const n of r)o+=(i[n][e]||0)*g[n];w[e]=o}}(o),function(e){for(const o of n){if(y[o]){p[o]=w[o];continue}const n=l[o]||l.default,t=1-Math.exp(-n*e*30);p[o]=p[o]+(w[o]-p[o])*t}}(o),He(),wo&&(x.alpha+=.3*o),C.render()});const bo=()=>B.resize();function Bo(e){if(!e)return;const o=e.renderConfig||{};let t=!1;void 0!==o.meshCols&&o.meshCols!==h.meshCols&&(t=!0),void 0!==o.meshRows&&o.meshRows!==h.meshRows&&(t=!0),void 0!==o.fragment&&o.fragment!==h.fragment&&(t=!0),void 0!==o.mouthHole&&o.mouthHole!==h.mouthHole&&(t=!0),void 0!==o.eyeHoles&&o.eyeHoles!==h.eyeHoles&&(t=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==h.mouthHoleSize&&(t=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==h.eyeHoleSize&&(t=!0),void 0!==o.eyeDepth&&o.eyeDepth!==h.eyeDepth&&(t=!0);const s=void 0!==o.lineThickness||void 0!==o.mouthLineThickness||void 0!==o.eyeLineThickness||void 0!==o.noseLineThickness||void 0!==o.browLineThickness;if(Object.assign(h,o),e.lineColor&&io(e.lineColor),e.pupilColor&&co(e.pupilColor),o.baseColor&&ho(o.baseColor),o.fadeColor&&fo(o.fadeColor),o.lineColor&&io(o.lineColor),o.pupilColor&&co(o.pupilColor),o.irisColor&&mo(o.irisColor),o.browColor&&ao(o.browColor),void 0!==o.mouthColor&&ro(o.mouthColor),void 0!==o.eyeColor&&so(o.eyeColor),void 0!==o.noseColor&&lo(o.noseColor),t?(re(),Ye(),ve()):(he(),ue(),ce(),de(),s&&Ye(),void 0===o.irisSize&&void 0===o.pupils||ve(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||se()),void 0===o.minimalMouth&&void 0===o.minimalEyes&&void 0===o.minimalNose&&void 0===o.minimalBrows||uo(),void 0!==o.glow&&_o(),e.channelGains)for(const o of n)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&i[e.activeMood]){b=e.activeMood;for(const e of r)v[e]=e===b?1:0}}return window.addEventListener("resize",bo),{loadAudio:async function(e){eo();const o=await e.arrayBuffer();Ze=await Ge.decodeAudioData(o.slice(0)),We=0},play(e){Ze&&function(e){Ze&&(eo(),Ke=Ge.createBufferSource(),Ke.buffer=Ze,Ke.loop=!!h.loopAudio,Je=Ge.createAnalyser(),Je.fftSize=1024,Je.smoothingTimeConstant=.4,$e=new Uint8Array(Je.frequencyBinCount),Ke.connect(Je),Je.connect(Ge.destination),Xe=Ge.currentTime-(e||0),Ke.start(0,e||0),Ke.onended=()=>{if(!h.loopAudio){Qe=!1;for(const e of Object.keys(t))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Qe=!0)}(void 0!==e?e:We)},pause(){Qe&&(We=no(),oo())},stop(){We=0,oo();for(const e of Object.keys(t))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){h.loopAudio=!!e,Ke&&(Ke.loop=!!e)},setMood(e){if(i[e]){b=e;for(const o of r)v[o]=o===e?1:0}},setChannel(e,n){if(!o[e])return;const t=o[e].range,i=Math.max(t[0],Math.min(t[1],n));w[e]=i,p[e]=i,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:yo,loadPreset:Bo,setRenderConfig(e){Bo({renderConfig:e})},getRenderConfig:()=>Object.assign({},h),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,n){o[e]&&(_[e]=n)},getChannelNames:()=>n.slice(),getMoodNames:()=>r.slice(),isPlaying:()=>Qe,getDuration:()=>Ze?Ze.duration:0,getPosition:()=>no(),getActiveMood:()=>b,dispose(){go=!0;try{oo()}catch(e){}if(Ge){try{Ge.close()}catch(e){}Ge=null}window.removeEventListener("resize",bo);try{B.stopRenderLoop()}catch(e){}try{C.dispose()}catch(e){}try{B.dispose()}catch(e){}}}}e.createWireface=d,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:d})}("undefined"!=typeof window?window:globalThis);
|
|
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",mouthColor:null,eyeColor:null,noseColor:null,minimalMouth:!0,minimalEyes:!0,minimalNose:!0,minimalBrows:!0,mouthLineThickness:1,eyeLineThickness:1,noseLineThickness:1,browLineThickness:1,baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,depthFadeCurve:1,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,upperJawProtrude:0,lowerJawProtrude:0,cameraView:"three-q",backgroundColor:"#000000"},c={asleep:{yaw:.6,pitch:.1,zoom:.8,dim:.55,mood:"sleep",toward:!1},parked:{yaw:.65,pitch:.05,zoom:.82,dim:.6,mood:"neutral",toward:!0},idle:{yaw:.45,pitch:0,zoom:.9,dim:.75,mood:"neutral",toward:!0},waiting:{yaw:.3,pitch:0,zoom:.95,dim:.85,mood:"neutral",toward:!0},busy:{yaw:.25,pitch:.22,zoom:1,dim:.9,mood:"fear",toward:!1},listen:{yaw:0,pitch:-.04,zoom:1.1,dim:1,mood:"neutral",toward:!1},speak:{yaw:0,pitch:0,zoom:1.22,dim:1,mood:"persona",toward:!1},attend:{yaw:0,pitch:-.06,zoom:1.35,dim:1,mood:"happy",toward:!1},important:{yaw:0,pitch:-.08,zoom:1.35,dim:1,mood:"surprise",toward:!1},cut:{yaw:.15,pitch:.08,zoom:1.05,dim:.9,mood:"surprise",toward:!1},point:{yaw:0,pitch:-.03,zoom:1.7,dim:1,mood:"persona"},distant:{yaw:.5,pitch:.04,zoom:.55,dim:.7,mood:"neutral",toward:!0},away:{yaw:.8,pitch:.06,zoom:.9,dim:.8,mood:"neutral"},work:{yaw:.3,pitch:.32,zoom:.95,dim:.85,mood:"neutral"},jump:{yaw:0,pitch:-.06,zoom:1.3,dim:1,mood:"surprise",hop:.3,for:1.6},closeup:{yaw:0,pitch:0,zoom:2.2,dim:1,mood:"persona",focus:"center"},"closeup-eyes":{yaw:0,pitch:0,zoom:2.4,dim:1,mood:"persona",focus:"eyes"},"closeup-nose":{yaw:0,pitch:0,zoom:3,dim:1,mood:"persona",focus:"nose"},"closeup-mouth":{yaw:0,pitch:0,zoom:2.8,dim:1,mood:"persona",focus:"mouth"}},d={face:0,center:-.08,eyes:.2,nose:-.05,mouth:-.38},h={headRotateX:1,headRotateY:1,headRotateZ:1},f={jawOpen:1};for(const e of Object.keys(n))f["viseme_"+e]=1;function m(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]}const p=48e3,w=1024,y=8e5/p,g=new Uint16Array(w),v=new Float32Array(512),b=new Float32Array(512),_=new Float32Array(w);for(let e=0;e<w;e++){let o=0;for(let t=0;t<10;t++)o|=(e>>t&1)<<9-t;g[e]=o,_[e]=.42-.5*Math.cos(2*Math.PI*e/w)+.08*Math.cos(4*Math.PI*e/w)}for(let e=0;e<512;e++)v[e]=Math.cos(2*Math.PI*e/w),b[e]=Math.sin(2*Math.PI*e/w);function M(e,M){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const B=Object.assign({},u,M||{}),C=(e,o,t)=>new BABYLON.Vector3(e,o,t),L={};for(const e of Object.keys(l)){const o=l[e];L[e]={uv:o.uv,dir:C(o.d[0],o.d[1],o.d[2]),radius:o.r}}const x={},k={},z={},A={},O={},R={};t.forEach(e=>{x[e]=o[e].def,k[e]=o[e].def,R[e]=1});const N={},S={};for(const e of i)N[e]=0,S[e]=0;N.neutral=1,S.neutral=1;let P="neutral";const T=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),j=new BABYLON.Scene(T,{useRightHandedSystem:!0});j.useRightHandedSystem=!0,j.clearColor=new BABYLON.Color4(0,0,0,1),j.skipPointerMovePicking=!0;const Y=new BABYLON.GlowLayer("glow",j,{mainTextureFixedSize:1024,blurKernelSize:32});Y.intensity=0;const F=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),j);F.minZ=.1,F.maxZ=100,F.lowerRadiusLimit=1.5,F.upperRadiusLimit=12,F.wheelDeltaPercentage=.01;const H=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}F.attachControl(e,!0);try{navigator.getGamepads=H}catch(e){}const U=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),j);U.intensity=.9,U.groundColor=new BABYLON.Color3(.1,.1,.14);const I=new BABYLON.TransformNode("faceRoot",j),D=new BABYLON.StandardMaterial("faceMat",j);D.diffuseColor=new BABYLON.Color3(.05,.05,.07),D.emissiveColor=new BABYLON.Color3(.012,.012,.02),D.specularColor=new BABYLON.Color3(.2,.22,.28),D.specularPower=48,D.backFaceCulling=!1,D.useVertexColor=!0;const V=new BABYLON.StandardMaterial("wireMat",j);function E(e){const o=new BABYLON.StandardMaterial(e,j);return o.emissiveColor=new BABYLON.Color3(1,1,1),o.disableLighting=!0,o.specularColor=new BABYLON.Color3(0,0,0),o}V.emissiveColor=new BABYLON.Color3(1,1,1),V.disableLighting=!0,V.wireframe=!0,V.backFaceCulling=!1,V.alpha=1,V.useVertexColor=!0;const q=E("mouthMat"),G=E("eyeMat"),Z=E("noseMat"),X=E("browMat"),K=new BABYLON.TransformNode("minimal",j);function J(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-.2)/.18)**2,c=((t-.45)/.3)**2+((n-.2)/.18)**2,d=.045*B.eyeDepth;l-=d*Math.exp(-u),l-=d*Math.exp(-c);const h=(t/.7)**2+((n-.55)/.1)**2;l+=.045*Math.exp(-h);const f=(t/.18)**2+((n-.05)/.4)**2;l+=.22*Math.exp(-f);const m=(t/.55)**2+((n+.45)/.2)**2;l+=.06*Math.exp(-m);const p=((t+.55)/.3)**2+((n-.05)/.28)**2,w=((t-.55)/.3)**2+((n-.05)/.28)**2;return l+=.04*Math.exp(-p),l+=.04*Math.exp(-w),C(s,a,l)}K.parent=I;const W=J(.5,.69);function $(e,o,t){const n=W.x,r=W.y,i=W.z,s=.27*(1+.4*t.width)*(1-.4*t.round),a=B.lipVertAmp,l=B.lipPressForce,u=.16*t.open*a,c=.012*t.lipPress*a*l,d=.09*t.jaw*a,h=.05*t.smile,f=.07*t.round,m=.007*(1-.55*t.lipPress),p=.022*(1-.55*t.lipPress);let w;if(o){const e=r+u/2-c+.4*h;w=[[-1,r+h,.5*-f],[-.45,e+.012,.012],[0,e-m,.018+f],[.45,e+.012,.012],[1,r+h,.5*-f]]}else{const e=r-u/2+c-d;w=[[-1,r+h,.5*-f],[-.5,e-.005,.014],[0,e-p,.022+1.1*f],[.5,e-.005,.014],[1,r+h,.5*-f]]}e=Math.max(-1,Math.min(1,e));let y=0;for(;y<w.length-1&&e>w[y+1][0];)y++;y=Math.min(y,w.length-2);const g=(e-w[y][0])/(w[y+1][0]-w[y][0]),v=w[y][1]*(1-g)+w[y+1][1]*g,b=w[y][2]*(1-g)+w[y+1][2]*g;return C(n+e*s,v,i+b)}function Q(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 C(s,l,u)}function ee(){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=x["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+=x.mouthSmile;const t=x.mouthPucker;return o.round+=.7*t,o.width+=.4*-t,o.open+=.6*x.jawOpen,o.jaw+=.7*x.jawOpen,o}let oe=null,te=[],ne=[],re=[],ie=[],se=null,ae=null,le=null,ue=null,ce=0,de=0,he=[1,1,1],fe=[0,0,0],me=!1,pe=[],we=[];const ye={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function ge(){oe&&(oe.dispose(),oe=null);const e=B.meshCols,o=B.meshRows;te=[],ne=[],re=[];for(let t=0;t<o;t++)for(let n=0;n<e;n++){const r=n/(e-1),i=t/(o-1);ne.push({u:r,v:i}),te.push(J(r,i))}const t=e=>{if(!B.fragment)return!0;const o=2*(ne[e].u-.5),t=2*(.5-ne[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(B.mouthHole){const t=.5,r=.69,i=.18*B.mouthHoleSize,s=.075*B.mouthHoleSize,a=((ne[e].u+ne[o].u+ne[n].u)/3-t)/i,l=((ne[e].v+ne[o].v+ne[n].v)/3-r)/s;if(a*a+l*l<1)return!1}if(B.eyeHoles){const t=.105*B.eyeHoleSize,r=.075*B.eyeHoleSize,i=(ne[e].u+ne[o].u+ne[n].u)/3,s=(ne[e].v+ne[o].v+ne[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)&&re.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))}ie=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))}(re,te.length),oe=new BABYLON.Mesh("face",j),oe.parent=I;const r=te.length;ae=new Float32Array(3*r),le=new Float32Array(3*r),ue=new Float32Array(4*r),se=new Array(r),ce=1/0,de=-1/0;for(let e=0;e<r;e++)ae[3*e]=te[e].x,ae[3*e+1]=te[e].y,ae[3*e+2]=te[e].z,te[e].z<ce&&(ce=te[e].z),te[e].z>de&&(de=te[e].z),se[e]=C(0,0,0),ue[4*e]=1,ue[4*e+1]=1,ue[4*e+2]=1,ue[4*e+3]=1;BABYLON.VertexData.ComputeNormals(ae,re,le);const i=new BABYLON.VertexData;i.positions=Array.from(ae),i.indices=re,i.normals=Array.from(le),i.colors=Array.from(ue),i.applyToMesh(oe,!0),Le(),Me(),Be(),ve(),me=!0}function ve(){pe=[],we=[];const e=.18*B.mouthHoleSize,o=.075*B.mouthHoleSize;for(let t=0;t<ne.length;t++){const n=(ne[t].u-.5)/e,r=(ne[t].v-.69)/o,i=n*n+r*r;if(i<4){const e=ne[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)),pe.push({idx:t,isUpper:e,xRel:o,weight:r,baselineTarget:$(o,e,ye)})}}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<ne.length;o++){const t=(ne[o].u-e.cu)/e.ru,n=(ne[o].v-e.cv)/e.rv,r=t*t+n*n;if(r<4){const n=ne[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=J(e.cu,e.cv);we.push({idx:o,side:e.side,isUpper:n,xRel:i,weight:s,eyeDef:{center:a,hw:e.hw,hh:e.hh},baselineTarget:Q(i,n,{center:a,hw:e.hw,hh:e.hh},0,0)})}}}function be(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,c=o.dir.z*t;for(let o=0;o<ne.length;o++){const t=ne[o].u-r,n=ne[o].v-i,s=t*t+n*n;if(s>4*a)continue;const d=Math.exp(-s/a);e[o].x+=l*d,e[o].y+=u*d,e[o].z+=c*d}}const _e=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return B.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return B.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return B.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return B.scaleMouth}}];function Me(){I&&(I.rotation.y=B.flipFace?Math.PI:0)}function Be(){oe&&(oe.isVisible=!!B.meshVisible)}function Ce(){K&&K.getChildMeshes().forEach(e=>e.isVisible=!!B.minimal)}function Le(){if(!oe)return;oe._edgesRenderer&&oe.disableEdgesRendering();const e=B.lineThickness;switch(B.mode){case"wire":oe.material=V,V.wireframe=!0,V.alpha=1;break;case"edges":oe.material=D,D.alpha=1,D.wireframe=!1,oe.enableEdgesRendering(.9999),oe.edgesWidth=4*e,oe.edgesColor=new BABYLON.Color4(he[0],he[1],he[2],1);break;case"shaded":oe.material=D,D.alpha=1,D.wireframe=!1}}let xe=null,ke=null,ze=null,Ae=null,Oe=null,Re=null;function Ne(){if(ke&&(ke.dispose(),ke=null),ze&&(ze.dispose(),ze=null),Oe&&(Oe.dispose(),Oe=null),Re&&(Re.dispose(),Re=null),!B.pupils)return;xe||(xe=new BABYLON.StandardMaterial("pupilMat",j),xe.emissiveColor=BABYLON.Color3.FromHexString(B.pupilColor),xe.disableLighting=!0,xe.backFaceCulling=!1),Ae||(Ae=new BABYLON.StandardMaterial("irisMat",j),Ae.emissiveColor=BABYLON.Color3.FromHexString(B.irisColor),Ae.disableLighting=!0,Ae.backFaceCulling=!1);const e=.035*B.irisSize;Oe=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},j),Re=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},j),Oe.material=Re.material=Ae,Oe.parent=Re.parent=I,ke=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},j),ze=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},j),ke.material=ze.material=xe,ke.parent=ze.parent=I}function Se(e,o){const t=J(e,o);if(!B.overlayTracksMesh)return t;const n=function(e,o){if(!se)return C(0,0,0);const t=.0036;let n=0,r=0,i=0,s=0;for(let a=0;a<ne.length;a++){const l=ne[a].u-e,u=ne[a].v-o,c=l*l+u*u;if(c<t){const e=1-Math.sqrt(c/t);n+=e,r+=se[a].x*e,i+=se[a].y*e,s+=se[a].z*e}}return 0===n?C(0,0,0):C(r/n,i/n,s/n)}(e,o);return C(t.x+n.x,t.y+n.y,t.z+n.z)}function Pe(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,c=.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),d=.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(C(c,d,h))}}return t.push(e[n-1]),t}function Te(e,o,t,n,r,i){const s={path:o,radius:t*(null==r?1:r)*B.lineThickness,tessellation:6,updatable:!0};i&&(s.instance=i);const a=BABYLON.MeshBuilder.CreateTube(e,s,j);return i||(a.material=n||q,a.parent=K),a}let je=null,Ye=null;function Fe(){const e=ee();return{upper:Pe([-1,-.45,0,.45,1].map(o=>$(o,!0,e)),18),lower:Pe([-1,-.5,0,.5,1].map(o=>$(o,!1,e)),18)}}const He=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let Ue=[];function Ie(e,o){const t="L"===e.side?x.eyeBlinkLeft:x.eyeBlinkRight,n=x.eyeSquint,r=Se(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),c=r.z+.018+.012*Math.sin(a);i.push(C(l,u,c))}return i}const De=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Ve=[];function Ee(e){const o=Se(e.uv[0],e.uv[1]),t="L"===e.side?-1:1,n=.085*x.browInnerUp-.05*x.browDown,r=.07*(x.browOuterUp>=0?x.browOuterUp:0)-.05*x.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,c=o.y+r-.005,d=o.z+.018;return Pe([C(i,l,d),C(s,u,d+.01),C(a,c,d)],12)}let qe=null,Ge=null,Ze=null;function Xe(){const e=.025*x.noseSneer,o=Se(.5,.4),t=Se(.5,.55),n=Pe([C(o.x,o.y-.02,o.z+.02),C(o.x-.005,.5*(o.y+t.y),.5*(o.z+t.z)+.05),C(t.x,t.y+.03,t.z+.05)],14),r=t.y+.01;return{bridge:n,leftN:Pe([C(t.x,r,t.z+.05),C(t.x-.06-e,r-.03,t.z+.02),C(t.x-.04,r-.05,t.z+.005),C(t.x-.01,r-.02,t.z+.03)],10),rightN:Pe([C(t.x,r,t.z+.05),C(t.x+.06+e,r-.03,t.z+.02),C(t.x+.04,r-.05,t.z+.005),C(t.x+.01,r-.02,t.z+.03)],10)}}function Ke(){je&&(je.dispose(),je=null),Ye&&(Ye.dispose(),Ye=null);for(const e of Ue)e.upper.dispose(),e.lower.dispose();Ue=[];for(const e of Ve)e.mesh.dispose();Ve=[],qe&&(qe.dispose(),qe=null),Ge&&(Ge.dispose(),Ge=null),Ze&&(Ze.dispose(),Ze=null);const{upper:e,lower:o}=Fe();je=Te("mouth_u",e,.01,q,B.mouthLineThickness),Ye=Te("mouth_l",o,.01,q,B.mouthLineThickness);for(const e of He){const o=Te("eye_"+e.side+"_u",Ie(e,!0),.0085,G,B.eyeLineThickness),t=Te("eye_"+e.side+"_l",Ie(e,!1),.0085,G,B.eyeLineThickness);Ue.push({eye:e,upper:o,lower:t})}for(const e of De){const o=Te("brow_"+e.side,Ee(e),.011,X,B.browLineThickness);Ve.push({brow:e,mesh:o})}const t=Xe();qe=Te("nose_b",t.bridge,.009,Z,B.noseLineThickness),Ge=Te("nose_l",t.leftN,.0085,Z,B.noseLineThickness),Ze=Te("nose_r",t.rightN,.0085,Z,B.noseLineThickness),Ce(),Eo()}const Je={};function We(){if(!oe)return;for(let e=0;e<t.length;e++){const o=t[e];Je[o]=x[o],x[o]=x[o]*(R[o]||1)}for(let e=0;e<se.length;e++)se[e].x=se[e].y=se[e].z=0;!function(e){const o=B.spread,t=ee();be(e,L.mouth_jaw_drop,t.jaw,o),be(e,L.mouth_open_lower,t.open,o),be(e,L.mouth_open_upper,.4*t.open,o);const n=t.smile;n>0?(be(e,L.mouth_smile_L,n,o),be(e,L.mouth_smile_R,n,o)):n<0&&(be(e,L.mouth_frown_L,-n,o),be(e,L.mouth_frown_R,-n,o)),be(e,L.mouth_round_L,t.round,o),be(e,L.mouth_round_R,t.round,o),be(e,L.mouth_round_top,t.round,o),be(e,L.mouth_round_bot,t.round,o),be(e,L.mouth_press_top,t.lipPress,o),be(e,L.mouth_press_bot,t.lipPress,o),t.width>0&&(be(e,L.mouth_width_L,t.width,o),be(e,L.mouth_width_R,t.width,o)),be(e,L.eye_blink_L_up,x.eyeBlinkLeft,o),be(e,L.eye_blink_L_lo,x.eyeBlinkLeft,o),be(e,L.eye_blink_R_up,x.eyeBlinkRight,o),be(e,L.eye_blink_R_lo,x.eyeBlinkRight,o),be(e,L.eye_squint_L,x.eyeSquint,o),be(e,L.eye_squint_R,x.eyeSquint,o),be(e,L.brow_inner_L,x.browInnerUp,o),be(e,L.brow_inner_R,x.browInnerUp,o),x.browOuterUp>=0?(be(e,L.brow_outer_L,x.browOuterUp,o),be(e,L.brow_outer_R,x.browOuterUp,o)):(be(e,L.brow_down_L,.6*-x.browOuterUp,o),be(e,L.brow_down_R,.6*-x.browOuterUp,o)),be(e,L.brow_down_L,x.browDown,o),be(e,L.brow_down_R,x.browDown,o),be(e,L.nose_sneer_L,x.noseSneer,o),be(e,L.nose_sneer_R,x.noseSneer,o)}(se),B.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=ie[r];if(0===t.length){n[r]=C(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]=C(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}(se,B.reactivity),function(e){for(const o of _e){const t=o.scale;if(Math.abs(t-1)<.001)continue;const n=J(o.uv[0],o.uv[1]),r=o.radiusUV*o.radiusUV,i=4*r;for(let s=0;s<ne.length;s++){const a=ne[s].u-o.uv[0],l=ne[s].v-o.uv[1],u=a*a+l*l;if(u>i)continue;const c=Math.exp(-u/r),d=te[s].x-n.x,h=te[s].y-n.y,f=te[s].z-n.z,m=(t-1)*c;e[s].x+=d*m,e[s].y+=h*m,e[s].z+=f*m}}}(se),function(e){const o=B.jawExtend;if(o<.001)return;const t=x.jawOpen||0;if(t<.001)return;const n=t*o*.1;for(let o=0;o<ne.length;o++){const t=ne[o].v;if(t<.55)continue;const r=Math.min(1,(t-.55)/.45);e[o].z+=n*r}}(se),function(e){const o=B.mouthGrow;if(o<.001)return;const t=ee().open;if(t<.001)return;const n=t*o,r=.0625;for(let o=0;o<ne.length;o++){const t=ne[o].u-.5,i=ne[o].v-.69,s=t*t+i*i;if(s>r)continue;const a=1-Math.sqrt(s/r),l=te[o];e[o].x+=(l.x-W.x)*n*a*.4,e[o].y+=(l.y-W.y)*n*a*.4,e[o].z+=n*a*.05}}(se),function(e){const o=B.upperJawProtrude;if(o<.001)return;const t=.18*o;for(let o=0;o<ne.length;o++){const n=ne[o].v;if(n<.45||n>.72)continue;const r=n<.62?(n-.45)/.17:(.72-n)/.1;e[o].z+=t*r}}(se),function(e){const o=B.lowerJawProtrude;if(o<.001)return;const t=.18*o;for(let o=0;o<ne.length;o++){const n=ne[o].v;if(n<.7)continue;let r;r=n<.85?(n-.7)/.15:1-(n-.85)/.3,r<0&&(r=0),e[o].z+=t*r}}(se),function(e){if(!B.mouthAnchor)return;const o=ee();for(const t of pe){const n=$(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}}(se),function(e){if(!B.eyeAnchor)return;const o=x.eyeBlinkLeft,t=x.eyeBlinkRight,n=x.eyeSquint;for(const r of we){const i="L"===r.side?o:t,s=Q(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,c=r.weight;e[r.idx].x=e[r.idx].x*(1-c)+a*c,e[r.idx].y=e[r.idx].y*(1-c)+l*c,e[r.idx].z=e[r.idx].z*(1-c)+u*c}}(se);for(let e=0;e<te.length;e++)ae[3*e]=te[e].x+se[e].x,ae[3*e+1]=te[e].y+se[e].y,ae[3*e+2]=te[e].z+se[e].z;if(oe.updateVerticesData(BABYLON.VertexBuffer.PositionKind,ae),B.depthFade>.001){const e=de-ce||1,o=B.depthFade,t=B.depthFadeCurve>0?B.depthFadeCurve:1;for(let n=0;n<te.length;n++){const r=ae[3*n+2];let i=(de-r)/e;i<0?i=0:i>1&&(i=1),1!==t&&(i=Math.pow(i,t)),i*=o,ue[4*n]=he[0]*(1-i)+fe[0]*i,ue[4*n+1]=he[1]*(1-i)+fe[1]*i,ue[4*n+2]=he[2]*(1-i)+fe[2]*i,ue[4*n+3]=1}oe.updateVerticesData(BABYLON.VertexBuffer.ColorKind,ue)}else if(me){for(let e=0;e<te.length;e++)ue[4*e]=he[0],ue[4*e+1]=he[1],ue[4*e+2]=he[2],ue[4*e+3]=1;oe.updateVerticesData(BABYLON.VertexBuffer.ColorKind,ue),me=!1}"edges"!==B.mode&&"shaded"!==B.mode||(BABYLON.VertexData.ComputeNormals(ae,re,le),oe.updateVerticesData(BABYLON.VertexBuffer.NormalKind,le)),function(){if(!ke||!ze)return;const e=.05*x.eyeLookH,o=.035*x.eyeLookV,t=J(.3,.4),n=J(.7,.4);Oe&&Re&&(Oe.position.set(t.x+.6*e,t.y+.6*o,t.z+.045),Re.position.set(n.x+.6*e,n.y+.6*o,n.z+.045)),ke.position.set(t.x+e,t.y+o,t.z+.05),ze.position.set(n.x+e,n.y+o,n.z+.05);const r=.5*(x.eyeBlinkLeft+x.eyeBlinkRight);ke.isVisible=ze.isVisible=r<.85,Oe&&Re&&(Oe.isVisible=Re.isVisible=r<.85)}(),B.minimal&&function(){if(!je)return;const e=Fe();Te("",e.upper,.01,null,B.mouthLineThickness,je),Te("",e.lower,.01,null,B.mouthLineThickness,Ye);for(const e of Ue)Te("",Ie(e.eye,!0),.0085,null,B.eyeLineThickness,e.upper),Te("",Ie(e.eye,!1),.0085,null,B.eyeLineThickness,e.lower);for(const e of Ve)Te("",Ee(e.brow),.011,null,B.browLineThickness,e.mesh);const o=Xe();Te("",o.bridge,.009,null,B.noseLineThickness,qe),Te("",o.leftN,.0085,null,B.noseLineThickness,Ge),Te("",o.rightN,.0085,null,B.noseLineThickness,Ze)}();const e=B.flipFace?Math.PI:0;I.rotation.x=.35*x.headRotateX,I.rotation.y=e+.5*x.headRotateY,I.rotation.z=.3*x.headRotateZ;for(let e=0;e<t.length;e++)x[t[e]]=Je[t[e]]}let $e=0;let Qe=1.5+3*Math.random(),eo=0,oo=.8+2*Math.random(),to=0,no=0,ro=0,io=0;const so={headRotateX:0,headRotateY:0,headRotateZ:0};let ao=null,lo=null,uo=null,co=null,ho=0,fo=0,mo=!1,po=null,wo=null,yo=!1,go=null;function vo(){ao||(ao=new(window.AudioContext||window.webkitAudioContext)),"suspended"===ao.state&&ao.resume()}function bo(){if(uo){try{uo.stop()}catch(e){}try{uo.disconnect()}catch(e){}uo=null}if(co){try{co.disconnect()}catch(e){}co=null}if(wo){try{wo.disconnect()}catch(e){}wo=null}mo=!1}function _o(){for(const e of Object.keys(n))k["viseme_"+e]=0;k.viseme_sil=1,k.jawOpen=0}function Mo(e,o){if(!e.createConstantSource)return null;const t=e.createConstantSource();return t.offset.value=1e-9,t.connect(o),t.start(),t}const Bo=["viseme_sil","jawOpen","viseme_SS","viseme_FF","viseme_O","viseme_aa","viseme_U","viseme_E","viseme_I"],Co=new Float32Array([1,0,0,0,0,0,0,0,0]);function Lo(e){for(const e of Object.keys(n))k["viseme_"+e]=0;for(let o=0;o<Bo.length;o++)k[Bo[o]]=e[o]}function xo(e,o,t,n){const r=o/2/e.length,i=Math.max(0,Math.floor(t/r)),s=Math.min(e.length-1,Math.ceil(n/r));let a=0,l=0;for(let o=i;o<=s;o++)a+=e[o],l++;return l?a/l/255:0}function ko(e,o,t){return function(e,o,t,n,r,i){i.fill(0);const s=Math.max(e,o,t,n);if(s<.08)return i[0]=1,i;i[1]=.7*s;const a=e+o+t+n+1e-6;n>.2&&(i[2]=Math.min(1,1.4*n),r>.2&&(i[3]=Math.min(.7,.9*r)));const l=e/a,u=o/a,c=t/a;return e>o&&e>.18?(i[4]=Math.min(1,1.1*e*(t<.2?1.1:.8)),i[5]=Math.min(1,u*s*1.6),t<.18&&(i[6]=Math.min(.7,.9*e))):o>=.9*e&&(i[5]=Math.min(1,l*s*1.6),i[7]=Math.min(1,u*s*1.4),t>.18&&(i[8]=Math.min(1,c*s*1.5))),i}(xo(e,o,200,700),xo(e,o,700,2e3),xo(e,o,2e3,4e3),xo(e,o,4e3,8e3),xo(e,o,1500,5e3),t)}const zo=new Float32Array(9);const Ao={};function Oo(e,o){const t=Ao[e];if(t)for(const n of t.slice())try{n(o)}catch(o){"undefined"!=typeof console&&console.error("[wireface] "+e+" listener",o)}}const Ro={frames:[],head:0,prev:null,ring:new Float32Array(w),ringPos:0,sinceHop:0,mag:new Float32Array(512),bytes:new Uint8Array(512),re:new Float32Array(w),im:new Float32Array(w),end:-1,segT0:0,segN:0,phase:0,last:0,inRate:0,run:void 0,ended:!1,cut:[],active:!1,spoke:!1,spokeRun:void 0,dry:0,lead:.08,release:.18,snapUntil:0,gain:null,sources:[]},No=new Float32Array(9),So=()=>Math.max(0,(Ro.end-performance.now())/1e3);function Po(e,o){const t=Ro.re,n=Ro.im,r=Ro.ring;for(let e=0;e<w;e++)t[e]=r[Ro.ringPos+e&1023]*_[e],n[e]=0;!function(e,o){for(let t=0;t<w;t++){const n=g[t];if(n>t){let r=e[t];e[t]=e[n],e[n]=r,r=o[t],o[t]=o[n],o[n]=r}}for(let t=2;t<=w;t<<=1){const n=t>>1,r=w/t;for(let i=0;i<w;i+=t)for(let t=0,s=0;t<n;t++,s+=r){const r=v[s],a=-b[s],l=i+t,u=l+n,c=e[u]*r-o[u]*a,d=e[u]*a+o[u]*r;e[u]=e[l]-c,o[u]=o[l]-d,e[l]+=c,o[l]+=d}}}(t,n);const i=Ro.mag,s=Ro.bytes;for(let e=0;e<512;e++){const o=Math.sqrt(t[e]*t[e]+n[e]*n[e])/w;i[e]=.4*i[e]+.6*o;const r=i[e]>0?Math.floor(255/70*(20*Math.log10(i[e])+100)):0;s[e]=r<0?0:r>255?255:r}Ro.frames.push({t:e,run:o,v:ko(s,p,new Float32Array(9))})}function To(e,o){const t=void 0===e,n=[];for(let r=Ro.head;r<Ro.frames.length;r++){const i=Ro.frames[r];(t||i.run===e)&&(void 0===o||i.t>=o)||n.push(i)}Ro.frames=n,Ro.head=0;for(const n of Ro.sources.slice())if((t||n.run===e)&&(void 0===o||n.startP>=o)){try{n.src.onended=null,n.src.stop(),n.src.disconnect()}catch(e){}Ro.sources.splice(Ro.sources.indexOf(n),1)}}function jo(e){const o=void 0!==e?e:Ro.run;if(void 0!==o&&Ro.cut.indexOf(o)<0&&(Ro.cut.push(o),Ro.cut.length>256&&Ro.cut.shift()),To(e),void 0===e||e===Ro.run){const e=Ro.frames.length?Ro.frames[Ro.frames.length-1]:null;Ro.end=e?e.t:-1,Ro.ended=!1,Ro.run=e?e.run:void 0,Ro.inRate=0}!Ro.spoke||void 0!==e&&e!==Ro.spokeRun||(Ro.spoke=!1,Ro.prev=null,Ro.snapUntil=performance.now()+400,_o(),Oo("speechend",{run:Ro.spokeRun,reason:"cut"})),Ro.head>=Ro.frames.length&&!Ro.spoke&&(Ro.active=!1,Ro.prev=null,mo||go||_o())}function Yo(){if(jo(),go){if(go.node)try{go.node.disconnect(go.an)}catch(e){}if(go.keep)try{go.keep.stop(),go.keep.disconnect()}catch(e){}try{go.an.disconnect()}catch(e){}try{go.sink.disconnect()}catch(e){}go=null,mo||_o()}}function Fo(){return ao&&lo?mo?ao.currentTime-ho:fo||0:0}function Ho(e){B.lineColor=e;const o=BABYLON.Color3.FromHexString(e);B.mouthColor||(q.emissiveColor=o),B.eyeColor||(G.emissiveColor=o),B.noseColor||(Z.emissiveColor=o)}function Uo(e){B.mouthColor=e,q.emissiveColor=BABYLON.Color3.FromHexString(e||B.lineColor)}function Io(e){B.eyeColor=e,G.emissiveColor=BABYLON.Color3.FromHexString(e||B.lineColor)}function Do(e){B.noseColor=e,Z.emissiveColor=BABYLON.Color3.FromHexString(e||B.lineColor)}function Vo(e){B.browColor=e,X.emissiveColor=BABYLON.Color3.FromHexString(e)}function Eo(){const e=(e,o)=>{e&&(e.isVisible=o)};e(je,!!B.minimalMouth),e(Ye,!!B.minimalMouth);for(const o of Ue)e(o.upper,!!B.minimalEyes),e(o.lower,!!B.minimalEyes);for(const o of Ve)e(o.mesh,!!B.minimalBrows);e(qe,!!B.minimalNose),e(Ge,!!B.minimalNose),e(Ze,!!B.minimalNose)}function qo(e){B.pupilColor=e,xe&&(xe.emissiveColor=BABYLON.Color3.FromHexString(e))}function Go(e){B.baseColor=e,he=m(e),me=!0,V.emissiveColor=new BABYLON.Color3(he[0],he[1],he[2]),oe&&oe._edgesRenderer&&(oe.edgesColor=new BABYLON.Color4(he[0],he[1],he[2],1))}function Zo(e){B.fadeColor=e,fe=m(e),me=!0}function Xo(e){B.irisColor=e,Ae&&(Ae.emissiveColor=BABYLON.Color3.FromHexString(e))}function Ko(e){if(!/^#[0-9a-f]{6}$/i.test(e||""))return;B.backgroundColor=e;const o=m(e);j.clearColor=new BABYLON.Color4(o[0],o[1],o[2],1)}const Jo={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let Wo=!1;function $o(e){if("orbit"===e)return void(Wo=!0);Wo=!1;const o=Jo[e];o&&(nt=!1,tt=null,rt=null,clearTimeout(it),it=null,st=null,F.target.y=0,F.alpha=o.alpha,F.beta=o.beta,F.radius=o.radius)}const Qo={};for(const e of Object.keys(c))Qo[e]=Object.assign({},c[e]);let et=.5,ot=.5,tt=null,nt=!1,rt=null,it=null,st=null,at=0,lt=0,ut=P;const ct=["yaw","pitch","zoom","dim","ty"],dt={yaw:0,pitch:0,zoom:1,dim:1,ty:0},ht={yaw:0,pitch:0,zoom:1,dim:1,ty:0},ft=(e,o,t)=>Math.max(o,Math.min(t,e)),mt=(e,o)=>"number"==typeof e&&isFinite(e)?e:o;function pt(e){if(r[e]){P=e;for(const o of i)N[o]=o===e?1:0}}let wt=null;function yt(){const e=-(F.alpha+Math.PI/2);dt.yaw=Math.atan2(Math.sin(e),Math.cos(e)),dt.pitch=Math.PI/2-F.beta,dt.zoom=3.3/Math.max(.01,F.radius),dt.ty=F.target.y}function gt(e){if(at&&(lt+=e,lt>1.2?(at=0,I.position.y=0):I.position.y=at*Math.abs(Math.sin(Math.PI*lt/.3))*Math.exp(-3.5*lt)),!nt)return;const o=1-Math.exp(-e/Math.max(.02,ot/3));let t=0;for(const e of ct){const n=ht[e]-dt[e];dt[e]+=n*o,t=Math.max(t,Math.abs(n))}if(t<.0015){for(const e of ct)dt[e]=ht[e];nt=!1}F.alpha=-Math.PI/2-dt.yaw,F.beta=Math.PI/2-dt.pitch,F.radius=3.3/dt.zoom,F.target.y=dt.ty,function(e){const o=1-ft(e,0,1);o<.004?wt&&(wt.isEnabled=!1):(wt||(wt=new BABYLON.Layer("wfDim",null,j,!1),wt.texture=BABYLON.RawTexture.CreateRGBATexture(new Uint8Array([255,255,255,255]),1,1,j,!1,!1,BABYLON.Texture.NEAREST_SAMPLINGMODE),wt.alphaBlendingMode=BABYLON.Engine.ALPHA_COMBINE),wt.isEnabled=!0,wt.color=new BABYLON.Color4(0,0,0,o))}(dt.dim)}function vt(){Y.intensity=B.glow?.85:0,Y.isEnabled=!!B.glow}ge(),Ne(),Ke(),Go(B.baseColor),Zo(B.fadeColor),Ho(B.lineColor),Vo(B.browColor),B.mouthColor&&Uo(B.mouthColor),B.eyeColor&&Io(B.eyeColor),B.noseColor&&Do(B.noseColor),qo(B.pupilColor),Xo(B.irisColor),Ko(B.backgroundColor),Eo(),vt(),$o(B.cameraView);let bt=performance.now(),_t=!1;T.runRenderLoop(()=>{if(_t)return;const e=performance.now(),n=Math.min(.25,(e-bt)/1e3);bt=e,function(e){eo+=e,eo>Qe&&!z.eyeBlinkLeft&&!z.eyeBlinkRight&&(k.eyeBlinkLeft=1,k.eyeBlinkRight=1,setTimeout(()=>{k.eyeBlinkLeft=S.sleep>.5?1:0,k.eyeBlinkRight=S.sleep>.5?1:0},110),eo=0,Qe=1.5+3.5*Math.random()),to+=e,to>oo&&!z.eyeLookH&&(no=.6*(Math.random()-.5),ro=.4*(Math.random()-.5),to=0,oo=.7+2.5*Math.random()),k.eyeLookH=no,k.eyeLookV=ro,io+=e,so.headRotateX=.04*Math.sin(.27*io),so.headRotateY=.06*Math.sin(.19*io),so.headRotateZ=.03*Math.sin(.11*io),k.headRotateX=so.headRotateX,k.headRotateY=so.headRotateY,k.headRotateZ=so.headRotateZ}(n),function(e){if(!Ro.active)return!1;const o=e+1e3*Ro.lead,t=Ro.frames;for(;Ro.head<t.length&&t[Ro.head].t<=o;)Ro.prev=t[Ro.head++];Ro.head>512&&(t.splice(0,Ro.head),Ro.head=0);const n=Ro.prev,r=t[Ro.head],i=n&&o-n.t<2.5*y;let s=Co;if(i&&(s=n.v,r&&r.t-n.t<2.5*y)){const e=(o-n.t)/(r.t-n.t);for(let o=0;o<9;o++)No[o]=n.v[o]+(r.v[o]-n.v[o])*e;s=No}if(i&&s[0]<.5&&Ro.release>0){const e=1e3*Ro.release;let r=1/0,i=n.t;for(let n=Ro.head;n<t.length;n++){const s=t[n];if(s.t-o>e||s.t-i>2.5*y){s.t-i>2.5*y&&(r=i+y-o),i=-1;break}if(s.v[0]>=.5){r=s.t-o,i=-1;break}i=s.t}if(i>=0&&Ro.ended&&n.run===Ro.run&&(r=i+y-o),r<e){const o=Math.max(0,r/e);s!==No&&(No.set(s),s=No);for(let e=1;e<9;e++)No[e]*=o}}if(Lo(s),i)return Ro.dry=0,Ro.spoke&&n.run!==Ro.spokeRun&&(Ro.spoke=!1,Oo("speechend",{run:Ro.spokeRun,reason:"end"})),!Ro.spoke&&s[0]<.5&&(Ro.spoke=!0,Ro.spokeRun=n.run,Oo("speechstart",{run:n.run})),!0;if(r)return!0;if(Ro.spoke){const o=Ro.ended&&Ro.spokeRun===Ro.run;if(o||Ro.dry||(Ro.dry=e,Oo("underrun",{run:Ro.spokeRun})),!(o||e-Ro.dry>250))return!0;Ro.spoke=!1,Oo("speechend",{run:Ro.spokeRun,reason:o?"end":"dry"})}return Ro.active=!1,Ro.prev=null,!1}(e)||!mo&&!go||function(){const e=go?go.an:mo?co:null;if(!e)return;const o=go?go.data:po;e.getByteFrequencyData(o),Lo(ko(o,e.context.sampleRate,zo))}(),function(e){const o=Math.max(.05,B.moodTransitionTime)/4,t=1-Math.pow(.5,e/o);for(const e of i)S[e]+=(N[e]-S[e])*t;for(const e of s){let o=0;for(const t of i)o+=(r[t][e]||0)*S[t];k[e]=o}let n=0;for(const e of i)n+=(r[e].jawOpen||0)*S[e];$e=Math.max(0,Math.min(1,n))}(n),function(e){const n=Ro.snapUntil>performance.now();for(const r of t){let t=k[r];if(z[r]){if(t=A[r],h[r]){const e=o[r].range;t=Math.max(e[0],Math.min(e[1],t+so[r]))}if(!O[r]){x[r]=t;continue}}else"jawOpen"===r&&$e>0&&(t=$e+t*(1-$e));let i=a[r]||a.default;n&&f[r]&&(i*=3);const s=1-Math.exp(-i*e*30);x[r]=x[r]+(t-x[r])*s}}(n),We(),gt(n),Wo&&(F.alpha+=.3*n),j.render()});const Mt=()=>T.resize();function Bt(e){if(!e)return;const o=e.renderConfig||{};let n=!1;void 0!==o.meshCols&&o.meshCols!==B.meshCols&&(n=!0),void 0!==o.meshRows&&o.meshRows!==B.meshRows&&(n=!0),void 0!==o.fragment&&o.fragment!==B.fragment&&(n=!0),void 0!==o.mouthHole&&o.mouthHole!==B.mouthHole&&(n=!0),void 0!==o.eyeHoles&&o.eyeHoles!==B.eyeHoles&&(n=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==B.mouthHoleSize&&(n=!0),void 0!==o.eyeHoleSize&&o.eyeHoleSize!==B.eyeHoleSize&&(n=!0),void 0!==o.eyeDepth&&o.eyeDepth!==B.eyeDepth&&(n=!0);const i=void 0!==o.lineThickness||void 0!==o.mouthLineThickness||void 0!==o.eyeLineThickness||void 0!==o.noseLineThickness||void 0!==o.browLineThickness,s=B.backgroundColor;if(Object.assign(B,o),void 0!==o.backgroundColor&&(B.backgroundColor=s,Ko(o.backgroundColor)),e.lineColor&&Ho(e.lineColor),e.pupilColor&&qo(e.pupilColor),o.baseColor&&Go(o.baseColor),o.fadeColor&&Zo(o.fadeColor),o.lineColor&&Ho(o.lineColor),o.pupilColor&&qo(o.pupilColor),o.irisColor&&Xo(o.irisColor),o.browColor&&Vo(o.browColor),void 0!==o.mouthColor&&Uo(o.mouthColor),void 0!==o.eyeColor&&Io(o.eyeColor),void 0!==o.noseColor&&Do(o.noseColor),n?(ge(),Ke(),Ne()):(Le(),Me(),Be(),Ce(),i&&Ke(),void 0===o.irisSize&&void 0===o.pupils||Ne(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||ve()),void 0===o.minimalMouth&&void 0===o.minimalEyes&&void 0===o.minimalNose&&void 0===o.minimalBrows||Eo(),void 0!==o.glow&&vt(),e.channelGains)for(const o of t)void 0!==e.channelGains[o]&&(R[o]=e.channelGains[o]);e.activeMood&&r[e.activeMood]&&(ut=e.activeMood,pt(e.activeMood))}return window.addEventListener("resize",Mt),{loadAudio:async function(e){vo();const o=await e.arrayBuffer();lo=await ao.decodeAudioData(o.slice(0)),fo=0},play(e){lo&&function(e){lo&&(vo(),uo=ao.createBufferSource(),uo.buffer=lo,uo.loop=!!B.loopAudio,co=ao.createAnalyser(),co.fftSize=1024,co.smoothingTimeConstant=.4,po=new Uint8Array(co.frequencyBinCount),wo=ao.createGain(),wo.gain.value=yo?0:1,uo.connect(co),co.connect(wo),wo.connect(ao.destination),ho=ao.currentTime-(e||0),uo.start(0,e||0),uo.onended=()=>{if(!B.loopAudio){mo=!1;for(const e of Object.keys(n))k["viseme_"+e]=0;k.viseme_sil=1,k.jawOpen=0}},mo=!0)}(void 0!==e?e:fo)},pause(){mo&&(fo=Fo(),bo())},stop(){fo=0,bo(),go||Ro.active||_o()},setLoop(e){B.loopAudio=!!e,uo&&(uo.loop=!!e)},setMuted(e){yo=!!e,wo&&(wo.gain.value=yo?0:1)},isMuted:()=>yo,attachAudio:function(e){Yo();let o=null,t=!1;if(e&&"function"==typeof e.connect&&e.context)o=e;else{if(!("undefined"!=typeof MediaStream&&e instanceof MediaStream))throw new Error("wireface.attachAudio: expected a MediaStream or an AudioNode");vo(),o=ao.createMediaStreamSource(e),t=!0}const n=o.context,r=n.createAnalyser();r.fftSize=1024,r.smoothingTimeConstant=.4;const i=n.createGain();i.gain.value=0,o.connect(r),r.connect(i),i.connect(n.destination),go={node:o,an:r,sink:i,owned:t,keep:Mo(n,r),data:new Uint8Array(r.frequencyBinCount)}},pushAudio:function(e,o,t){const n=(t=t||{}).run;if(void 0!==n&&Ro.cut.indexOf(n)>=0)return So();if(!e||!e.length&&!e.byteLength)return t.end&&n===Ro.run&&(Ro.ended=!0),So();let r=e;if(!(e instanceof Float32Array)){const o=e instanceof Int16Array?e:new Int16Array(e.buffer||e,e.byteOffset||0,Math.floor(e.byteLength/2));r=new Float32Array(o.length);for(let e=0;e<o.length;e++)r[e]=o[e]/32768}const i=o>0?o:p;"number"==typeof t.lead&&(Ro.lead=Math.max(0,Math.min(.5,t.lead))),"number"==typeof t.release&&(Ro.release=Math.max(0,Math.min(.5,t.release)));const s=performance.now();let a;a="number"==typeof t.at&&isFinite(t.at)?s+(t.at-Date.now()):Ro.end>s?Ro.end:s+1e3*Math.max(0,mt(t.delay,.05)),n===Ro.run&&i===Ro.inRate&&Ro.end>0&&Math.abs(a-Ro.end)<40?a=Ro.end:(a<Ro.end&&To(void 0,a),Ro.ring.fill(0),Ro.ringPos=0,Ro.sinceHop=0,Ro.mag.fill(0),Ro.phase=0,Ro.last=0,Ro.inRate=i,Ro.segT0=a,Ro.segN=0,n!==Ro.run&&(Ro.run=n,Ro.ended=!1));const l=i/p,u=Ro.ring,c=r.length;let d=Ro.phase;for(;d<c-1;){let e;if(d<0)e=Ro.last*-d+r[0]*(1+d);else{const o=0|d,t=d-o;e=r[o]*(1-t)+r[o+1]*t}u[Ro.ringPos]=e,Ro.ringPos=Ro.ringPos+1&1023,Ro.segN++,800===++Ro.sinceHop&&(Ro.sinceHop=0,Po(Ro.segT0+1e3*Ro.segN/p,n)),d+=l}Ro.phase=d-c,Ro.last=r[c-1];const h=c/i*1e3;return t.audible&&function(e,o,t,n){vo(),Ro.gain||(Ro.gain=ao.createGain(),Ro.gain.connect(ao.destination));const r=ao.createBuffer(1,e.length,o);r.getChannelData(0).set(e);const i=ao.createBufferSource();let s;i.buffer=r,i.connect(Ro.gain);const a=ao.getOutputTimestamp?ao.getOutputTimestamp():null;s=a&&a.performanceTime>0&&a.contextTime>0?a.contextTime+(t-a.performanceTime)/1e3:ao.currentTime+(t-performance.now())/1e3-((ao.outputLatency||0)+(ao.baseLatency||0));const l=ao.currentTime-s;if(l<=0)i.start(s);else{if(!(l<r.duration))return;i.start(0,l)}const u={src:i,run:n,startP:t};Ro.sources.push(u),i.onended=()=>{const e=Ro.sources.indexOf(u);e>=0&&Ro.sources.splice(e,1)}}(r,i,a,n),Ro.end=a+h,t.end&&(Ro.ended=!0),Ro.active=!0,Ro.dry=0,So()},cutAudio:jo,detachAudio:Yo,isSpeaking:()=>Ro.spoke,on:function(e,o){return"function"!=typeof o?()=>{}:((Ao[e]=Ao[e]||[]).push(o),()=>{const t=Ao[e],n=t?t.indexOf(o):-1;n>=0&&t.splice(n,1)})},setMood(e){r[e]&&(ut=e,pt(e))},setBehaviour:function e(o,t,n){t=t||{};const r=it?st:null;if(clearTimeout(it),it=null,st=null,null==o)return yt(),ht.yaw=dt.yaw,ht.pitch=dt.pitch,ht.zoom=dt.zoom,ht.dim=1,ht.ty=0,ot=mt(t.glide,et),tt=null,rt=null,nt=!0,n||Oo("behaviour",{name:null}),!0;const i="object"==typeof o?o:Qo[o];if(!i)return!1;const s="string"==typeof o?o:"(custom)",a=mt(t.for,mt(i.for,0));let l=rt||r;yt(),l||(l={recipe:{yaw:dt.yaw,pitch:dt.pitch,zoom:dt.zoom,dim:dt.dim,_ty:dt.ty,mood:P},opts:{}}),a>0||(rt={recipe:o,opts:{side:t.side,glide:t.glide}}),Wo=!1;const u=t.side<0?-1:1;ht.yaw=mt(i.yaw,0)*u,ht.pitch=mt(i.pitch,0),ht.zoom=ft(mt(i.zoom,1),.3,6),ht.dim=ft(mt(i.dim,1),0,1),ht.ty=mt(i._ty,mt(d[i.focus],0)),ot=mt(t.glide,mt(i.glide,et));const c=3.3/ht.zoom;return F.lowerRadiusLimit=Math.min(F.lowerRadiusLimit,c),F.upperRadiusLimit=Math.max(F.upperRadiusLimit,c),mt(i.hop,0)&&(at=i.hop,lt=0),i.mood&&pt("persona"===i.mood?ut:i.mood),tt=s,nt=!0,a>0&&(st=l,it=setTimeout(()=>{if(it=null,st=null,_t)return;const o=rt;e(l.recipe,l.opts,!0),rt=o,o||(tt=null),Oo("behaviour",{name:tt,returned:!0})},1e3*a)),n||Oo("behaviour",{name:tt}),!0},defineBehaviours:function(e){if(!e||"object"!=typeof e)return;const o=e.recipes&&"object"==typeof e.recipes?e.recipes:e;e.recipes&&"number"==typeof e.glide_s&&(et=Math.max(0,e.glide_s));for(const e of Object.keys(o)){const t=o[e];t&&"object"==typeof t&&(Qo[e]=Object.assign({},t))}},getBehaviour:()=>tt,getBehaviourNames:()=>Object.keys(Qo),getBehaviours(){const e={};for(const o of Object.keys(Qo))e[o]=Object.assign({},Qo[o]);return e},setChannel(e,t,n){if(!o[e])return;const r=o[e].range,i=Math.max(r[0],Math.min(r[1],t)),s=!(!n||!n.smooth);A[e]=i,O[e]=s,k[e]=i,s||(x[e]=i),z[e]=!0,clearTimeout(z["_t_"+e]),z["_t_"+e]=n&&n.hold?null:setTimeout(()=>{z[e]=!1},1200)},releaseChannel(e){o[e]&&(clearTimeout(z["_t_"+e]),z[e]=!1)},setView:$o,loadPreset:Bt,setRenderConfig(e){Bt({renderConfig:e})},getRenderConfig:()=>Object.assign({},B),getPreset(){const e={};for(const o of t)1!==R[o]&&(e[o]=R[o]);return{version:"wireface-v010",createdAt:(new Date).toISOString(),renderConfig:Object.assign({},B),channelGains:e,activeMood:ut}},getChannel:e=>void 0!==x[e]?x[e]:0,getChannelTarget:e=>void 0!==k[e]?k[e]:0,getChannelGain:e=>void 0!==R[e]?R[e]:1,setChannelGain(e,t){o[e]&&(R[e]=t)},getChannelNames:()=>t.slice(),getMoodNames:()=>i.slice(),isPlaying:()=>mo,getDuration:()=>lo?lo.duration:0,getPosition:()=>Fo(),getActiveMood:()=>P,dispose(){_t=!0,clearTimeout(it);for(const e of t)clearTimeout(z["_t_"+e]);try{Yo()}catch(e){}try{bo()}catch(e){}if(ao){try{ao.close()}catch(e){}ao=null}window.removeEventListener("resize",Mt);try{T.stopRenderLoop()}catch(e){}try{j.dispose()}catch(e){}try{T.dispose()}catch(e){}}}}e.createWireface=M,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:M})}("undefined"!=typeof window?window:globalThis);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<!--
|
|
3
|
+
wireface — behaviours + streamed speech (four faces)
|
|
4
|
+
|
|
5
|
+
What this page shows, in the order a page with several faces needs it:
|
|
6
|
+
1. DESIGNS each face starts from a bundled preset (presets/*.json), gets a
|
|
7
|
+
small variation and its own background, and getPreset() hands
|
|
8
|
+
the result back as JSON to store.
|
|
9
|
+
2. BEHAVIOURS the page only says what is going on (speak, listen, idle, busy,
|
|
10
|
+
jump …) with setBehaviour(name); the library glides the framing,
|
|
11
|
+
brightness and mood. No camera is touched from here.
|
|
12
|
+
3. STREAM speech arrives as PCM chunks, not as a file: pushAudio(chunk,
|
|
13
|
+
rate, { run, end }) analyses each chunk as it lands and puts
|
|
14
|
+
the lips on a clock — slightly ahead of the sound, closed as it
|
|
15
|
+
ends. A person cutting in is cutAudio().
|
|
16
|
+
4. EVENTS the page does not guess who is speaking: speechstart and
|
|
17
|
+
speechend come from what the lips actually do.
|
|
18
|
+
|
|
19
|
+
Serve the repo root (npm run demo) and open /examples/behaviours.html.
|
|
20
|
+
-->
|
|
21
|
+
<html lang="en">
|
|
22
|
+
<head>
|
|
23
|
+
<meta charset="UTF-8">
|
|
24
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
25
|
+
<title>wireface — behaviours + streamed speech</title>
|
|
26
|
+
<style>
|
|
27
|
+
:root { --fg:#e8e8e8; --dim:#777; --line:#262626; --accent:#ffeb3b; --mono:ui-monospace,SFMono-Regular,Menlo,monospace; }
|
|
28
|
+
* { box-sizing:border-box; }
|
|
29
|
+
html,body { margin:0; height:100%; background:#000; color:var(--fg); font:11px var(--mono); letter-spacing:.08em; }
|
|
30
|
+
body { display:flex; flex-direction:column; }
|
|
31
|
+
#faces { flex:1; display:grid; grid-template-columns:repeat(4,1fr); gap:1px; background:var(--line); min-height:0; }
|
|
32
|
+
.face { position:relative; background:#000; min-width:0; min-height:0; cursor:pointer; }
|
|
33
|
+
.face canvas { width:100%; height:100%; display:block; outline:none; touch-action:none; }
|
|
34
|
+
.face .tag { position:absolute; left:10px; top:8px; text-transform:uppercase; color:var(--dim); pointer-events:none; mix-blend-mode:difference; }
|
|
35
|
+
.face .tag b { color:var(--fg); font-weight:400; }
|
|
36
|
+
.face.floor .tag b { color:var(--accent); }
|
|
37
|
+
#bar { display:flex; flex-wrap:wrap; gap:6px; align-items:center; padding:10px; border-top:1px solid var(--line); }
|
|
38
|
+
#bar .sep { width:1px; height:18px; background:var(--line); margin:0 6px; }
|
|
39
|
+
#bar label { color:var(--dim); text-transform:uppercase; }
|
|
40
|
+
button { background:none; color:var(--fg); border:1px solid #3a3a3a; padding:5px 9px; font:inherit; letter-spacing:inherit; text-transform:uppercase; cursor:pointer; }
|
|
41
|
+
button:hover { background:var(--fg); color:#000; }
|
|
42
|
+
button.on { background:var(--accent); color:#000; border-color:var(--accent); }
|
|
43
|
+
#note { color:var(--dim); padding:0 10px 10px; }
|
|
44
|
+
</style>
|
|
45
|
+
</head>
|
|
46
|
+
<body>
|
|
47
|
+
<div id="faces"></div>
|
|
48
|
+
<div id="bar">
|
|
49
|
+
<label>stream</label>
|
|
50
|
+
<button id="stream">▶ stream speech</button>
|
|
51
|
+
<button id="silent" title="lips move, no sound from this page — for speech that is sounded elsewhere">silent: off</button>
|
|
52
|
+
<span class="sep"></span>
|
|
53
|
+
<label>floor face</label>
|
|
54
|
+
<span id="shots"></span>
|
|
55
|
+
<span class="sep"></span>
|
|
56
|
+
<button id="store" title="log every face's design (getPreset) to the console">store designs</button>
|
|
57
|
+
</div>
|
|
58
|
+
<div id="note">click a face to give it the floor · the others turn toward it · shots apply to the floor face</div>
|
|
59
|
+
|
|
60
|
+
<script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
|
|
61
|
+
<script src="../wireface.js"></script>
|
|
62
|
+
<script>
|
|
63
|
+
/* 1. DESIGNS — a bundled preset per face, each nudged a little so no two faces
|
|
64
|
+
are the same, each with its own backdrop. */
|
|
65
|
+
const DESIGNS = [
|
|
66
|
+
{ name: 'ember', preset: 'asset-8pgwi9', vary: { backgroundColor: '#0d0707' } },
|
|
67
|
+
{ name: 'block', preset: 'asset-kln33e', vary: { backgroundColor: '#070b12', baseColor: '#58a6ca', spread: 1.45 } },
|
|
68
|
+
{ name: 'rose', preset: 'asset-th5rha', vary: { backgroundColor: '#12060a', meshCols: 19, scaleEyes: 1.2 } },
|
|
69
|
+
{ name: 'slate', preset: 'asset-ydr7de', vary: { backgroundColor: '#0b0c16', meshRows: 11, lineColor: '#c8cdf0' } },
|
|
70
|
+
];
|
|
71
|
+
const SHOTS = ['point', 'closeup', 'closeup-eyes', 'closeup-mouth', 'work', 'distant', 'away', 'jump', 'asleep'];
|
|
72
|
+
|
|
73
|
+
const faces = [];
|
|
74
|
+
let floor = 0;
|
|
75
|
+
|
|
76
|
+
async function mount(design, i) {
|
|
77
|
+
const el = document.createElement('div');
|
|
78
|
+
el.className = 'face';
|
|
79
|
+
el.innerHTML = `<canvas></canvas><div class="tag"><b>${design.name}</b> · <span></span></div>`;
|
|
80
|
+
document.getElementById('faces').appendChild(el);
|
|
81
|
+
const wf = createWireface(el.querySelector('canvas'));
|
|
82
|
+
const data = await fetch(`presets/${design.preset}.json`).then(r => r.json());
|
|
83
|
+
wf.loadPreset(Array.isArray(data) ? data[0] : data); // pick the design
|
|
84
|
+
wf.setRenderConfig(design.vary); // …and make it this face's own
|
|
85
|
+
const face = { wf, el, label: el.querySelector('.tag span'), design };
|
|
86
|
+
el.addEventListener('click', () => { floor = i; arrange(); });
|
|
87
|
+
// 4. EVENTS — the stage follows the lips, not a timer
|
|
88
|
+
wf.on('speechstart', arrange);
|
|
89
|
+
wf.on('speechend', arrange);
|
|
90
|
+
return face;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* 2. BEHAVIOURS — one line per face says what is going on. The floor face
|
|
94
|
+
speaks or listens; the others idle, turned toward it (side). */
|
|
95
|
+
function arrange() {
|
|
96
|
+
const speaking = faces.some(f => f.wf.isSpeaking());
|
|
97
|
+
faces.forEach((f, i) => {
|
|
98
|
+
f.el.classList.toggle('floor', i === floor);
|
|
99
|
+
if (i === floor) f.wf.setBehaviour(speaking ? 'speak' : 'listen');
|
|
100
|
+
else f.wf.setBehaviour(speaking ? 'waiting' : 'idle', { side: Math.sign(i - floor) || 1 });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
setInterval(() => faces.forEach(f => { f.label.textContent = f.wf.getBehaviour() || '—'; }), 200);
|
|
104
|
+
|
|
105
|
+
/* 3. STREAM — speech as PCM chunks. Here the chunks are cut from the bundled
|
|
106
|
+
sample to stand in for a TTS stream: 50 ms of 22.05 kHz int16 at a time,
|
|
107
|
+
handed to the floor face as they "arrive". Each utterance is a run: its
|
|
108
|
+
id travels with every chunk, and its last chunk says so. */
|
|
109
|
+
const RATE = 22050, CHUNK = Math.round(RATE * 0.05);
|
|
110
|
+
let pcm = null, cursor = 0, timer = null, silent = false, run = 0;
|
|
111
|
+
const EMPTY = new Int16Array(0);
|
|
112
|
+
|
|
113
|
+
async function loadPcm() {
|
|
114
|
+
const bytes = await fetch('Wireface-001-kokoro-santa.mp3').then(r => r.arrayBuffer());
|
|
115
|
+
const off = new OfflineAudioContext(1, 1, RATE);
|
|
116
|
+
const buf = await off.decodeAudioData(bytes); // decoded at RATE
|
|
117
|
+
const x = buf.getChannelData(0);
|
|
118
|
+
pcm = new Int16Array(x.length);
|
|
119
|
+
for (let i = 0; i < x.length; i++) pcm[i] = Math.max(-1, Math.min(1, x[i])) * 32767;
|
|
120
|
+
}
|
|
121
|
+
function pump() {
|
|
122
|
+
// keep ~150 ms queued ahead, like a network sender would
|
|
123
|
+
let ahead = faces[floor].wf.pushAudio(EMPTY, RATE); // an empty chunk reports what is queued
|
|
124
|
+
while (ahead < 0.15 && cursor < pcm.length) {
|
|
125
|
+
const chunk = pcm.subarray(cursor, cursor + CHUNK);
|
|
126
|
+
cursor += CHUNK;
|
|
127
|
+
ahead = faces[floor].wf.pushAudio(chunk, RATE, { audible: !silent, run: 'utterance-' + run, end: cursor >= pcm.length });
|
|
128
|
+
}
|
|
129
|
+
if (cursor >= pcm.length) { clearInterval(timer); timer = null; cursor = 0; showStream(); } // it plays out, then speechend
|
|
130
|
+
}
|
|
131
|
+
const showStream = () => { document.getElementById('stream').textContent = timer ? '■ cut in' : '▶ stream speech'; };
|
|
132
|
+
async function startStream() {
|
|
133
|
+
if (!pcm) await loadPcm();
|
|
134
|
+
run++;
|
|
135
|
+
timer = setInterval(pump, 40); pump();
|
|
136
|
+
showStream();
|
|
137
|
+
}
|
|
138
|
+
function stopStream() { // a person cut in: drop what is queued, now
|
|
139
|
+
clearInterval(timer); timer = null; cursor = 0;
|
|
140
|
+
faces.forEach(f => f.wf.cutAudio());
|
|
141
|
+
showStream();
|
|
142
|
+
}
|
|
143
|
+
document.getElementById('stream').onclick = () => timer ? stopStream() : startStream();
|
|
144
|
+
document.getElementById('silent').onclick = e => { silent = !silent; e.target.textContent = 'silent: ' + (silent ? 'on' : 'off'); e.target.classList.toggle('on', silent); };
|
|
145
|
+
|
|
146
|
+
for (const name of SHOTS) {
|
|
147
|
+
const b = document.createElement('button');
|
|
148
|
+
b.textContent = name;
|
|
149
|
+
b.onclick = () => faces[floor].wf.setBehaviour(name);
|
|
150
|
+
document.getElementById('shots').appendChild(b);
|
|
151
|
+
}
|
|
152
|
+
document.getElementById('store').onclick = () => {
|
|
153
|
+
const designs = Object.fromEntries(faces.map(f => [f.design.name, f.wf.getPreset()]));
|
|
154
|
+
console.log('[wireface] designs', designs);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
(async () => {
|
|
158
|
+
for (let i = 0; i < DESIGNS.length; i++) faces.push(await mount(DESIGNS[i], i));
|
|
159
|
+
arrange();
|
|
160
|
+
window.faces = faces; // for console poking
|
|
161
|
+
})();
|
|
162
|
+
</script>
|
|
163
|
+
</body>
|
|
164
|
+
</html>
|
package/examples/editor.html
CHANGED
|
@@ -348,6 +348,7 @@
|
|
|
348
348
|
<h3>colours <span class="num">style</span></h3>
|
|
349
349
|
<div class="color-row"><div class="ctl-name">base</div><input type="color" id="color-base" value="#ffffff"><div class="ctl-val" id="color-base-val">FFF</div></div>
|
|
350
350
|
<div class="color-row"><div class="ctl-name">depth fade</div><input type="color" id="color-fade" value="#000000"><div class="ctl-val" id="color-fade-val">000</div></div>
|
|
351
|
+
<div class="color-row"><div class="ctl-name">background</div><input type="color" id="color-bg" value="#000000"><div class="ctl-val" id="color-bg-val">000</div></div>
|
|
351
352
|
<div class="ctl"><div class="ctl-name">fade ░░</div><div class="ctl-bar" data-rcfg="depthFade" data-min="0" data-max="1" data-step="0.02"><div class="fill"></div></div><div class="ctl-val" data-rcfg-val="depthFade">0.00</div></div>
|
|
352
353
|
<div class="ctl"><div class="ctl-name">fade curve</div><div class="ctl-bar" data-rcfg="depthFadeCurve" data-min="0.3" data-max="3" data-step="0.05"><div class="fill"></div></div><div class="ctl-val" data-rcfg-val="depthFadeCurve">1.00</div></div>
|
|
353
354
|
<div class="color-row"><div class="ctl-name">line (default)</div><input type="color" id="color-line" value="#ffffff"><div class="ctl-val" id="color-line-val">FFF</div></div>
|
|
@@ -659,6 +660,7 @@ const renderConfig = {
|
|
|
659
660
|
// v011:
|
|
660
661
|
baseColor: '#ffffff', // mesh wireframe / face emissive base color
|
|
661
662
|
fadeColor: '#000000', // back-of-mesh color to fade to (depth gradient)
|
|
663
|
+
backgroundColor: '#000000', // scene clear colour behind the face (v1.2) — saved with the preset
|
|
662
664
|
depthFade: 0.0, // 0 = no fade, 1 = full fade to fadeColor at deepest z [0, 1]
|
|
663
665
|
irisColor: '#000000', // iris ring color (visible behind pupil)
|
|
664
666
|
irisSize: 1.6, // iris radius multiplier on pupil radius [1, 4]
|
|
@@ -2640,6 +2642,14 @@ function applyFadeColor(hex) {
|
|
|
2640
2642
|
const lbl = document.getElementById('color-fade-val');
|
|
2641
2643
|
if (lbl) lbl.textContent = hex.replace('#', '').toUpperCase().slice(0, 3);
|
|
2642
2644
|
}
|
|
2645
|
+
function applyBackgroundColor(hex) {
|
|
2646
|
+
if (!/^#[0-9a-f]{6}$/i.test(hex || '')) return;
|
|
2647
|
+
renderConfig.backgroundColor = hex;
|
|
2648
|
+
const c = hex2rgb(hex);
|
|
2649
|
+
scene.clearColor = new BABYLON.Color4(c[0], c[1], c[2], 1);
|
|
2650
|
+
const lbl = document.getElementById('color-bg-val');
|
|
2651
|
+
if (lbl) lbl.textContent = hex.replace('#', '').toUpperCase().slice(0, 3);
|
|
2652
|
+
}
|
|
2643
2653
|
function applyIrisColor(hex) {
|
|
2644
2654
|
renderConfig.irisColor = hex;
|
|
2645
2655
|
if (typeof irisMat !== 'undefined' && irisMat) {
|
|
@@ -2662,6 +2672,7 @@ function applyBrowColor(hex) {
|
|
|
2662
2672
|
['color-pupil', 'pupilColor', applyPupilColor],
|
|
2663
2673
|
['color-base', 'baseColor', applyBaseColor],
|
|
2664
2674
|
['color-fade', 'fadeColor', applyFadeColor],
|
|
2675
|
+
['color-bg', 'backgroundColor', applyBackgroundColor],
|
|
2665
2676
|
['color-iris', 'irisColor', applyIrisColor],
|
|
2666
2677
|
['color-brow', 'browColor', applyBrowColor],
|
|
2667
2678
|
// v1.1: per-feature minimal-line colors. Default value seeded from
|
|
@@ -2837,6 +2848,10 @@ function applyPreset(p) {
|
|
|
2837
2848
|
const el = document.getElementById('color-fade'); if (el) el.value = p.renderConfig.fadeColor;
|
|
2838
2849
|
applyFadeColor(p.renderConfig.fadeColor);
|
|
2839
2850
|
}
|
|
2851
|
+
if (p.renderConfig && p.renderConfig.backgroundColor) {
|
|
2852
|
+
const el = document.getElementById('color-bg'); if (el) el.value = p.renderConfig.backgroundColor;
|
|
2853
|
+
applyBackgroundColor(p.renderConfig.backgroundColor);
|
|
2854
|
+
}
|
|
2840
2855
|
if (p.renderConfig && p.renderConfig.irisColor) {
|
|
2841
2856
|
const el = document.getElementById('color-iris'); if (el) el.value = p.renderConfig.irisColor;
|
|
2842
2857
|
applyIrisColor(p.renderConfig.irisColor);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// wireface — Babylon Playground snippet (v7 candidate)
|
|
2
|
+
// paste into https://playground.babylonjs.com/, hit Run (don't save until verified).
|
|
3
|
+
// minimal: face + audio + keyboard. NO DOM injection — that belongs in
|
|
4
|
+
// examples/playground.html (which we own). Keep this snippet polite.
|
|
5
|
+
|
|
6
|
+
export const createScene = function () {
|
|
7
|
+
// ── tear down previous instance (multiple Run presses) ───────────────────
|
|
8
|
+
if (window.wf && window.wf.dispose) { try { window.wf.dispose(); } catch (e) {} }
|
|
9
|
+
if (window._wfKey) { document.removeEventListener('keydown', window._wfKey); window._wfKey = null; }
|
|
10
|
+
if (window._wfPoll) { clearInterval(window._wfPoll); window._wfPoll = null; }
|
|
11
|
+
|
|
12
|
+
const canvas = engine.getRenderingCanvas();
|
|
13
|
+
const scene = new BABYLON.Scene(engine); // placeholder so the Playground is happy
|
|
14
|
+
|
|
15
|
+
// ── PRESETS (4) ──────────────────────────────────────────────────────────
|
|
16
|
+
const PRESETS = [
|
|
17
|
+
{"version":"wireface-v010","createdAt":"2026-05-01T14:17:22.023Z","renderConfig":{"meshCols":17,"meshRows":23,"scaleNose":0.7000000000000001,"scaleEyes":0.45,"scaleMouth":1.1,"reactivity":0.22,"spread":1,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":1.9500000000000002,"eyeHoles":true,"eyeDepth":0,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"8pgwi9","name":"Wireface-001_8pgwi9"},
|
|
18
|
+
{"version":"wireface-v010","createdAt":"2026-05-01T15:13:02.043Z","renderConfig":{"meshCols":9,"meshRows":9,"scaleNose":1.05,"scaleEyes":1.4,"scaleMouth":1.5500000000000003,"reactivity":0.3,"spread":1.6500000000000001,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":0.9,"eyeHoleSize":0.9500000000000001,"eyeHoles":true,"eyeDepth":3.1500000000000004,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":1,"lipVertAmp":0.5,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.6000000000000001,"lineColor":"#ffffff","pupilColor":"#3e0f0f","baseColor":"#ca5858","fadeColor":"#000000","depthFade":1,"irisColor":"#121212","irisSize":1.6,"browColor":"#ffffff","jawExtend":1.1500000000000001,"mouthGrow":0,"depthFadeCurve":3,"upperJawProtrude":1.4500000000000002,"lowerJawProtrude":2.45,"mouthColor":"#454a1c","eyeColor":"#2c2b2b","noseColor":"#ffffff","minimalMouth":true,"minimalEyes":true,"minimalNose":false,"minimalBrows":false,"mouthLineThickness":0.2,"eyeLineThickness":0.2,"noseLineThickness":0.2,"browLineThickness":4},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"kln33e","name":"Wireface-001_kln33e"},
|
|
19
|
+
{"version":"wireface-v010","createdAt":"2026-05-01T02:19:44.566Z","renderConfig":{"meshCols":21,"meshRows":21,"scaleNose":0.4,"scaleEyes":1.35,"scaleMouth":0.4,"reactivity":0.24,"spread":0.9,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":1.15,"eyeHoles":true,"eyeDepth":5,"mouthAnchor":true,"eyeAnchor":true,"lineThickness":0.4,"lipVertAmp":4,"lipPressForce":3,"overlayTracksMesh":true,"moodTransitionTime":0.05,"lineColor":"#541717","pupilColor":"#c4b0b0","baseColor":"#ff8585","fadeColor":"#f00000","depthFade":1,"irisColor":"#ff0000","irisSize":3.3,"browColor":"#616161","jawExtend":0,"mouthGrow":0},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"th5rha","name":"asset__post__th5rha"},
|
|
20
|
+
{"version":"wireface-v010","createdAt":"2026-05-01T02:00:12.074Z","renderConfig":{"meshCols":7,"meshRows":9,"scaleNose":1.15,"scaleEyes":2,"scaleMouth":2,"reactivity":0.26,"spread":0.8,"mode":"wire","pupils":true,"meshVisible":true,"minimal":true,"fragment":true,"glow":true,"flipFace":true,"loopAudio":true,"mouthHole":true,"mouthHoleSize":1.85,"eyeHoles":false,"eyeDepth":1,"mouthAnchor":true,"eyeAnchor":false,"lineThickness":1,"lipVertAmp":1.6,"lipPressForce":0,"overlayTracksMesh":true,"moodTransitionTime":0.05,"lineColor":"#181616","pupilColor":"#3a2727","baseColor":"#7a86c2","fadeColor":"#f00000","depthFade":0.4,"irisColor":"#170303","irisSize":2,"browColor":"#616161","jawExtend":0,"mouthGrow":0},"channelGains":{},"activeMood":"neutral","moodTargetWeights":{"neutral":1},"id":"ydr7de","name":"asset__post__ydr7de"},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// ── load wireface@1.1.5 from CDN, then init ──────────────────────────────
|
|
24
|
+
const init = () => {
|
|
25
|
+
// wireface creates its OWN engine on the canvas. Stop the Playground's
|
|
26
|
+
// render loop so the two engines don't fight for pointer input — that's
|
|
27
|
+
// what was causing inverted-drag in left-handed-vs-right-handed mode.
|
|
28
|
+
try { engine.stopRenderLoop(); } catch (e) {}
|
|
29
|
+
|
|
30
|
+
const wf = createWireface(canvas);
|
|
31
|
+
wf.setLoop(true);
|
|
32
|
+
|
|
33
|
+
let idx = 0;
|
|
34
|
+
const apply = () => wf.loadPreset(PRESETS[idx]);
|
|
35
|
+
apply();
|
|
36
|
+
|
|
37
|
+
window._wfKey = (e) => {
|
|
38
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
39
|
+
idx = (idx + 1) % PRESETS.length; apply();
|
|
40
|
+
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
41
|
+
idx = (idx - 1 + PRESETS.length) % PRESETS.length; apply();
|
|
42
|
+
} else if (e.key === ' ') {
|
|
43
|
+
wf.isPlaying() ? wf.pause() : wf.play();
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
document.addEventListener('keydown', window._wfKey);
|
|
48
|
+
|
|
49
|
+
fetch('https://cdn.jsdelivr.net/gh/styk-tv/wireface@main/examples/Wireface-001-kokoro-santa.mp3')
|
|
50
|
+
.then(r => r.blob())
|
|
51
|
+
.then(blob => wf.loadAudio(new File([blob], 'sample.mp3')))
|
|
52
|
+
.then(() => wf.play())
|
|
53
|
+
.catch(() => {});
|
|
54
|
+
|
|
55
|
+
window.wf = wf;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
if (window.createWireface) {
|
|
59
|
+
init();
|
|
60
|
+
} else {
|
|
61
|
+
const s = document.createElement('script');
|
|
62
|
+
s.src = 'https://cdn.jsdelivr.net/npm/wireface@1.1.5/dist/wireface.min.js';
|
|
63
|
+
s.onload = init;
|
|
64
|
+
document.head.appendChild(s);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return scene;
|
|
68
|
+
};
|
package/examples/playground.html
CHANGED
|
@@ -16,16 +16,53 @@
|
|
|
16
16
|
<style>
|
|
17
17
|
html,body { margin:0; height:100%; background:#000; overflow:hidden; }
|
|
18
18
|
canvas { width:100vw; height:100vh; display:block; outline:none; touch-action:none; }
|
|
19
|
-
/*
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
/* dim chrome, hover-brightens. mix-blend-mode keeps it readable on any face colour. */
|
|
20
|
+
.wf-chrome { position:fixed; color:rgba(255,255,255,.32); mix-blend-mode:difference;
|
|
21
|
+
font:11px ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
22
|
+
letter-spacing:.18em; text-transform:uppercase;
|
|
23
|
+
user-select:none; -webkit-user-select:none; }
|
|
24
|
+
.wf-chrome a, .wf-chrome button { color:inherit; text-decoration:none;
|
|
25
|
+
background:none; border:0; padding:0; margin:0; cursor:pointer;
|
|
26
|
+
font:inherit; letter-spacing:inherit; text-transform:inherit;
|
|
27
|
+
display:inline-flex; align-items:center; gap:8px; }
|
|
28
|
+
.wf-chrome a:hover, .wf-chrome button:hover { color:rgba(255,255,255,.95); }
|
|
29
|
+
.wf-chrome svg { width:14px; height:14px; fill:currentColor; display:block; }
|
|
30
|
+
#wf-brand { top:14px; right:16px; }
|
|
31
|
+
#wf-brand .name { letter-spacing:.32em; }
|
|
32
|
+
#wf-bar { left:50%; bottom:18px; transform:translateX(-50%);
|
|
33
|
+
display:flex; align-items:center; gap:22px; }
|
|
34
|
+
#wf-bar button svg { width:18px; height:18px; }
|
|
35
|
+
#wf-bar #wf-play svg { width:22px; height:22px; }
|
|
36
|
+
#wf-hint { left:50%; bottom:46px; transform:translateX(-50%);
|
|
37
|
+
font-size:9px; opacity:.55; white-space:nowrap; }
|
|
24
38
|
</style>
|
|
25
39
|
</head>
|
|
26
40
|
<body>
|
|
27
41
|
<canvas id="cv"></canvas>
|
|
28
|
-
|
|
42
|
+
|
|
43
|
+
<div id="wf-brand" class="wf-chrome">
|
|
44
|
+
<a href="https://github.com/styk-tv/wireface" target="_blank" aria-label="wireface on github">
|
|
45
|
+
<span class="name">wireface</span>
|
|
46
|
+
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
|
|
47
|
+
</a>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div id="wf-hint" class="wf-chrome">drag .mp3 · ←/→ swap · space play</div>
|
|
51
|
+
|
|
52
|
+
<div id="wf-bar" class="wf-chrome">
|
|
53
|
+
<a href="https://github.com/styk-tv/wireface" target="_blank" aria-label="github" title="github">
|
|
54
|
+
<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8a8 8 0 0 0 5.47 7.59c.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
|
|
55
|
+
</a>
|
|
56
|
+
<button id="wf-prev" aria-label="previous preset" title="previous preset (←)">
|
|
57
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 5h2v14H6V5zm14 0L8.5 12 20 19V5z"/></svg>
|
|
58
|
+
</button>
|
|
59
|
+
<button id="wf-play" aria-label="play/pause" title="play/pause (space)">
|
|
60
|
+
<svg id="wf-play-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>
|
|
61
|
+
</button>
|
|
62
|
+
<button id="wf-next" aria-label="next preset" title="next preset (→)">
|
|
63
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M16 5h2v14h-2V5zM4 5l11.5 7L4 19V5z"/></svg>
|
|
64
|
+
</button>
|
|
65
|
+
</div>
|
|
29
66
|
|
|
30
67
|
<script src="https://cdn.jsdelivr.net/npm/babylonjs@9/babylon.js"></script>
|
|
31
68
|
<script src="https://cdn.jsdelivr.net/npm/wireface@1/dist/wireface.min.js"></script>
|
|
@@ -48,15 +85,37 @@ wf.setLoop(true);
|
|
|
48
85
|
|
|
49
86
|
let idx = 0;
|
|
50
87
|
const apply = () => wf.loadPreset(PRESETS[idx]);
|
|
88
|
+
const next = () => { idx = (idx + 1) % PRESETS.length; apply(); };
|
|
89
|
+
const prev = () => { idx = (idx - 1 + PRESETS.length) % PRESETS.length; apply(); };
|
|
90
|
+
const toggle = () => { wf.isPlaying() ? wf.pause() : wf.play(); syncPlayIcon(); };
|
|
51
91
|
apply();
|
|
52
92
|
|
|
93
|
+
/* play/pause icon swap. poll because loop/autoplay can flip state without our input. */
|
|
94
|
+
const PLAY_PATH = 'M8 5v14l11-7z';
|
|
95
|
+
const PAUSE_PATH = 'M6 5h4v14H6V5zm8 0h4v14h-4V5z';
|
|
96
|
+
const playIcon = document.getElementById('wf-play-icon');
|
|
97
|
+
let lastPlaying = null;
|
|
98
|
+
function syncPlayIcon() {
|
|
99
|
+
const p = wf.isPlaying();
|
|
100
|
+
if (p === lastPlaying) return;
|
|
101
|
+
lastPlaying = p;
|
|
102
|
+
playIcon.firstElementChild
|
|
103
|
+
? playIcon.firstElementChild.setAttribute('d', p ? PAUSE_PATH : PLAY_PATH)
|
|
104
|
+
: playIcon.innerHTML = `<path d="${p ? PAUSE_PATH : PLAY_PATH}"/>`;
|
|
105
|
+
}
|
|
106
|
+
setInterval(syncPlayIcon, 200);
|
|
107
|
+
|
|
108
|
+
document.getElementById('wf-prev').addEventListener('click', prev);
|
|
109
|
+
document.getElementById('wf-next').addEventListener('click', next);
|
|
110
|
+
document.getElementById('wf-play').addEventListener('click', toggle);
|
|
111
|
+
|
|
53
112
|
document.addEventListener('keydown', e => {
|
|
54
113
|
if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
|
55
|
-
|
|
114
|
+
next();
|
|
56
115
|
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
|
57
|
-
|
|
116
|
+
prev();
|
|
58
117
|
} else if (e.key === ' ') {
|
|
59
|
-
|
|
118
|
+
toggle();
|
|
60
119
|
e.preventDefault();
|
|
61
120
|
}
|
|
62
121
|
});
|
|
@@ -70,6 +129,7 @@ fetch('https://cdn.jsdelivr.net/gh/styk-tv/wireface@main/examples/Wireface-001-k
|
|
|
70
129
|
.then(r => r.blob())
|
|
71
130
|
.then(blob => wf.loadAudio(new File([blob], 'sample.mp3')))
|
|
72
131
|
.then(() => wf.play())
|
|
132
|
+
.then(() => syncPlayIcon())
|
|
73
133
|
.catch(() => {});
|
|
74
134
|
|
|
75
135
|
/* drag-drop your own .mp3 to override the sample */
|
|
@@ -77,7 +137,7 @@ window.addEventListener('dragover', e => e.preventDefault());
|
|
|
77
137
|
window.addEventListener('drop', async e => {
|
|
78
138
|
e.preventDefault();
|
|
79
139
|
const f = e.dataTransfer.files && e.dataTransfer.files[0];
|
|
80
|
-
if (f) { await wf.loadAudio(f); wf.play(); }
|
|
140
|
+
if (f) { await wf.loadAudio(f); wf.play(); syncPlayIcon(); }
|
|
81
141
|
});
|
|
82
142
|
|
|
83
143
|
window.wf = wf;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wireface",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|
|
@@ -41,6 +41,8 @@
|
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "mkdir -p dist && cp wireface.js dist/wireface.js && terser wireface.js -c -m --comments=false -o dist/wireface.min.js",
|
|
43
43
|
"prepublishOnly": "npm run build",
|
|
44
|
+
"test": "node test/run.mjs",
|
|
45
|
+
"test:min": "npm run build && node test/run.mjs --min",
|
|
44
46
|
"demo": "npx --yes serve -l 5173 ."
|
|
45
47
|
},
|
|
46
48
|
"author": "Peter Styk",
|