wireface 1.0.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/LICENSE +22 -0
- package/README.md +288 -0
- package/dist/wireface.js +1447 -0
- package/dist/wireface.min.js +1 -0
- package/docs/wireface.png +0 -0
- package/examples/demo.html +296 -0
- package/examples/editor.html +3023 -0
- package/examples/presets/asset-th5rha.json +121 -0
- package/examples/presets/asset-ydr7de.json +121 -0
- package/package.json +59 -0
- package/wireface.js +1447 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e){"use strict";const o={viseme_sil:{range:[0,1],def:1},viseme_PP:{range:[0,1],def:0},viseme_FF:{range:[0,1],def:0},viseme_TH:{range:[0,1],def:0},viseme_DD:{range:[0,1],def:0},viseme_kk:{range:[0,1],def:0},viseme_CH:{range:[0,1],def:0},viseme_SS:{range:[0,1],def:0},viseme_nn:{range:[0,1],def:0},viseme_RR:{range:[0,1],def:0},viseme_aa:{range:[0,1],def:0},viseme_E:{range:[0,1],def:0},viseme_I:{range:[0,1],def:0},viseme_O:{range:[0,1],def:0},viseme_U:{range:[0,1],def:0},jawOpen:{range:[0,1],def:0},mouthSmile:{range:[-1,1],def:0},mouthPucker:{range:[0,1],def:0},eyeBlinkLeft:{range:[0,1],def:0},eyeBlinkRight:{range:[0,1],def:0},eyeLookH:{range:[-1,1],def:0},eyeLookV:{range:[-1,1],def:0},eyeSquint:{range:[0,1],def:0},browInnerUp:{range:[0,1],def:0},browOuterUp:{range:[-1,1],def:0},browDown:{range:[0,1],def:0},noseSneer:{range:[0,1],def:0},headRotateX:{range:[-1,1],def:0},headRotateY:{range:[-1,1],def:0},headRotateZ:{range:[-1,1],def:0}},t=Object.keys(o),n={sil:{open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0},PP:{open:0,width:0,round:.2,smile:0,lipPress:.95,jaw:0},FF:{open:.1,width:.05,round:0,smile:.05,lipPress:.55,jaw:.1},TH:{open:.2,width:.15,round:0,smile:0,lipPress:.1,jaw:.18},DD:{open:.28,width:.25,round:0,smile:.05,lipPress:.05,jaw:.25},kk:{open:.32,width:.2,round:0,smile:0,lipPress:.05,jaw:.3},CH:{open:.32,width:0,round:.55,smile:0,lipPress:.1,jaw:.25},SS:{open:.18,width:.45,round:0,smile:.2,lipPress:.2,jaw:.1},nn:{open:.18,width:.18,round:0,smile:0,lipPress:.3,jaw:.18},RR:{open:.35,width:0,round:.5,smile:0,lipPress:.05,jaw:.25},aa:{open:.85,width:.45,round:0,smile:0,lipPress:0,jaw:.85},E:{open:.5,width:.65,round:0,smile:.2,lipPress:0,jaw:.45},I:{open:.28,width:.85,round:0,smile:.3,lipPress:0,jaw:.18},O:{open:.55,width:0,round:.75,smile:0,lipPress:0,jaw:.45},U:{open:.35,width:-.15,round:.95,smile:0,lipPress:.05,jaw:.25}},r={neutral:{browInnerUp:0,browOuterUp:0,browDown:0,mouthSmile:0,eyeSquint:0},happy:{browOuterUp:.4,mouthSmile:.7,eyeSquint:.25},sad:{browInnerUp:.7,browDown:.2,mouthSmile:-.5,eyeBlinkLeft:.15,eyeBlinkRight:.15},angry:{browInnerUp:0,browOuterUp:-.4,browDown:.7,mouthSmile:-.4,noseSneer:.5,eyeSquint:.4},fear:{browInnerUp:.7,browOuterUp:.5,mouthSmile:-.3,eyeBlinkLeft:-.2,eyeBlinkRight:-.2},surprise:{browInnerUp:.6,browOuterUp:.8,jawOpen:.5,mouthSmile:0},sleep:{eyeBlinkLeft:1,eyeBlinkRight:1,browDown:.3,mouthSmile:0}},i=Object.keys(r),s=["browInnerUp","browOuterUp","browDown","mouthSmile","eyeSquint","noseSneer","eyeBlinkLeft","eyeBlinkRight"],a={default:.35,eyeBlinkLeft:.55,eyeBlinkRight:.55,...Object.fromEntries(Object.keys(n).map(e=>["viseme_"+e,.45])),browInnerUp:.18,browOuterUp:.18,browDown:.18,headRotateX:.1,headRotateY:.1,headRotateZ:.1,eyeLookH:.25,eyeLookV:.25},l={mouth_jaw_drop:{uv:[.5,.78],d:[0,-.2,-.02],r:.28},mouth_open_lower:{uv:[.5,.71],d:[0,-.1,0],r:.16},mouth_open_upper:{uv:[.5,.66],d:[0,.04,0],r:.13},mouth_smile_L:{uv:[.32,.69],d:[-.06,.07,-.02],r:.13},mouth_smile_R:{uv:[.68,.69],d:[.06,.07,-.02],r:.13},mouth_frown_L:{uv:[.32,.69],d:[.02,-.07,0],r:.13},mouth_frown_R:{uv:[.68,.69],d:[-.02,-.07,0],r:.13},mouth_round_L:{uv:[.32,.69],d:[.07,0,.03],r:.13},mouth_round_R:{uv:[.68,.69],d:[-.07,0,.03],r:.13},mouth_round_top:{uv:[.5,.66],d:[0,-.02,.04],r:.12},mouth_round_bot:{uv:[.5,.71],d:[0,.02,.04],r:.12},mouth_press_top:{uv:[.5,.66],d:[0,-.025,0],r:.12},mouth_press_bot:{uv:[.5,.71],d:[0,.025,0],r:.12},mouth_width_L:{uv:[.32,.69],d:[-.05,0,0],r:.13},mouth_width_R:{uv:[.68,.69],d:[.05,0,0],r:.13},eye_blink_L_up:{uv:[.3,.36],d:[0,-.05,-.02],r:.08},eye_blink_L_lo:{uv:[.3,.45],d:[0,.03,0],r:.08},eye_blink_R_up:{uv:[.7,.36],d:[0,-.05,-.02],r:.08},eye_blink_R_lo:{uv:[.7,.45],d:[0,.03,0],r:.08},eye_squint_L:{uv:[.3,.42],d:[0,-.015,0],r:.1},eye_squint_R:{uv:[.7,.42],d:[0,-.015,0],r:.1},brow_inner_L:{uv:[.42,.25],d:[0,.06,.02],r:.1},brow_inner_R:{uv:[.58,.25],d:[0,.06,.02],r:.1},brow_outer_L:{uv:[.2,.27],d:[0,.05,0],r:.12},brow_outer_R:{uv:[.8,.27],d:[0,.05,0],r:.12},brow_down_L:{uv:[.3,.27],d:[0,-.05,0],r:.14},brow_down_R:{uv:[.7,.27],d:[0,-.05,0],r:.14},nose_sneer_L:{uv:[.42,.55],d:[0,.03,.02],r:.08},nose_sneer_R:{uv:[.58,.55],d:[0,.03,.02],r:.08}},u={mode:"wire",meshCols:17,meshRows:21,spread:1,reactivity:.25,scaleNose:1,scaleEyes:1,scaleMouth:1,flipFace:!0,glow:!1,pupils:!0,fragment:!0,minimal:!0,meshVisible:!0,loopAudio:!0,mouthHole:!0,mouthHoleSize:1,eyeHoles:!1,eyeDepth:1,mouthAnchor:!0,eyeAnchor:!1,lineThickness:1,lipVertAmp:1.6,lipPressForce:1,overlayTracksMesh:!0,moodTransitionTime:.6,lineColor:"#ffffff",pupilColor:"#ffffff",baseColor:"#ffffff",fadeColor:"#000000",depthFade:0,irisColor:"#000000",irisSize:1.6,browColor:"#ffffff",jawExtend:0,mouthGrow:0,cameraView:"three-q"};function d(e){const o=(e||"#ffffff").replace("#","");return[parseInt(o.slice(0,2),16)/255,parseInt(o.slice(2,4),16)/255,parseInt(o.slice(4,6),16)/255]}function h(e,h){if("undefined"==typeof BABYLON)throw new Error("wireface: BABYLON.js not loaded — include babylon.js before wireface.js");const c=Object.assign({},u,h||{}),f=(e,o,t)=>new BABYLON.Vector3(e,o,t),m={};for(const e of Object.keys(l)){const o=l[e];m[e]={uv:o.uv,dir:f(o.d[0],o.d[1],o.d[2]),radius:o.r}}const p={},w={},y={},_={};t.forEach(e=>{p[e]=o[e].def,w[e]=o[e].def,_[e]=1});const g={},v={};for(const e of i)g[e]=0,v[e]=0;g.neutral=1,v.neutral=1;let B="neutral";const b=new BABYLON.Engine(e,!0,{preserveDrawingBuffer:!1,stencil:!1,antialias:!0}),M=new BABYLON.Scene(b);M.clearColor=new BABYLON.Color4(0,0,0,1),M.skipPointerMovePicking=!0;const x=new BABYLON.GlowLayer("glow",M,{mainTextureFixedSize:1024,blurKernelSize:32});x.intensity=0;const L=new BABYLON.ArcRotateCamera("cam",-Math.PI/2-.6,Math.PI/2-.15,4,BABYLON.Vector3.Zero(),M);L.minZ=.1,L.maxZ=100,L.lowerRadiusLimit=1.5,L.upperRadiusLimit=12,L.wheelDeltaPercentage=.01;const C=navigator.getGamepads;try{navigator.getGamepads=()=>[]}catch(e){}L.attachControl(e,!0);try{navigator.getGamepads=C}catch(e){}const O=new BABYLON.HemisphericLight("h",new BABYLON.Vector3(0,1,0),M);O.intensity=.9,O.groundColor=new BABYLON.Color3(.1,.1,.14);const z=new BABYLON.TransformNode("faceRoot",M),R=new BABYLON.StandardMaterial("faceMat",M);R.diffuseColor=new BABYLON.Color3(.05,.05,.07),R.emissiveColor=new BABYLON.Color3(.012,.012,.02),R.specularColor=new BABYLON.Color3(.2,.22,.28),R.specularPower=48,R.backFaceCulling=!1,R.useVertexColor=!0;const A=new BABYLON.StandardMaterial("wireMat",M);A.emissiveColor=new BABYLON.Color3(1,1,1),A.disableLighting=!0,A.wireframe=!0,A.backFaceCulling=!1,A.alpha=1,A.useVertexColor=!0;const k=new BABYLON.StandardMaterial("minimalMat",M);k.emissiveColor=new BABYLON.Color3(1,1,1),k.disableLighting=!0,k.specularColor=new BABYLON.Color3(0,0,0);const N=new BABYLON.StandardMaterial("browMat",M);N.emissiveColor=new BABYLON.Color3(1,1,1),N.disableLighting=!0,N.specularColor=new BABYLON.Color3(0,0,0);const S=new BABYLON.TransformNode("minimal",M);function P(e,o){const t=2*(e-.5),n=2*(.5-o),r=.95*n,i=Math.max(0,1-r*r),s=t*Math.sqrt(i)*.8,a=.95*n;let l=Math.cos(t*Math.PI*.5)*Math.cos(n*Math.PI*.5)*.18;const u=Math.hypot(e-.5,o-.5)/.16;u<1.6&&(l+=.085*(1-Math.min(1,u)));const d=Math.hypot(e-.3,o-.27)/.1,h=Math.hypot(e-.7,o-.27)/.1;d<1.6&&(l+=.02*(1-Math.min(1,d))),h<1.6&&(l+=.02*(1-Math.min(1,h)));const m=Math.hypot((e-.3)/.085,(o-.4)/.045),p=Math.hypot((e-.7)/.085,(o-.4)/.045);m<1.5&&(l-=.03*(1-Math.min(1,m))*c.eyeDepth),p<1.5&&(l-=.03*(1-Math.min(1,p))*c.eyeDepth),o>.85&&(l+=.6*(o-.85)*.1*Math.max(0,1-1.2*Math.abs(t)));const w=Math.hypot((e-.22)/.1,(o-.62)/.08),y=Math.hypot((e-.78)/.1,(o-.62)/.08);return w<1.6&&(l+=.018*(1-Math.min(1,w))),y<1.6&&(l+=.018*(1-Math.min(1,y))),f(s,a,l)}S.parent=z;const Y=P(.5,.69);function j(e,o,t){const n=Y.x,r=Y.y,i=Y.z,s=.27*(1+.4*t.width)*(1-.4*t.round),a=c.lipVertAmp,l=c.lipPressForce,u=.16*t.open*a,d=.012*t.lipPress*a*l,h=.09*t.jaw*a,m=.05*t.smile,p=.07*t.round,w=.007*(1-.55*t.lipPress),y=.022*(1-.55*t.lipPress);let _;if(o){const e=r+u/2-d+.4*m;_=[[-1,r+m,.5*-p],[-.45,e+.012,.012],[0,e-w,.018+p],[.45,e+.012,.012],[1,r+m,.5*-p]]}else{const e=r-u/2+d-h;_=[[-1,r+m,.5*-p],[-.5,e-.005,.014],[0,e-y,.022+1.1*p],[.5,e-.005,.014],[1,r+m,.5*-p]]}e=Math.max(-1,Math.min(1,e));let g=0;for(;g<_.length-1&&e>_[g+1][0];)g++;g=Math.min(g,_.length-2);const v=(e-_[g][0])/(_[g+1][0]-_[g][0]),B=_[g][1]*(1-v)+_[g+1][1]*v,b=_[g][2]*(1-v)+_[g+1][2]*v;return f(n+e*s,B,i+b)}function V(e,o,t,n,r){const i=(e+1)/2*Math.PI,s=t.center.x+Math.cos(Math.PI-i)*t.hw,a=.012*r,l=(t.center.y+(o?1:-1)*Math.sin(i)*t.hh)*(1-n)+t.center.y*n+(o?-a:.5*a),u=t.center.z+.018+.012*Math.sin(i);return f(s,l,u)}function D(){let e=0;const o={open:0,width:0,round:0,smile:0,lipPress:0,jaw:0};for(const t of Object.keys(n)){const r=p["viseme_"+t]||0;if(r<=0)continue;e+=r;const i=n[t];o.open+=i.open*r,o.width+=i.width*r,o.round+=i.round*r,o.smile+=i.smile*r,o.lipPress+=i.lipPress*r,o.jaw+=i.jaw*r}if(e>1){const t=1/e;o.open*=t,o.width*=t,o.round*=t,o.smile*=t,o.lipPress*=t,o.jaw*=t}o.smile+=p.mouthSmile;const t=p.mouthPucker;return o.round+=.7*t,o.width+=.4*-t,o.open+=.6*p.jawOpen,o.jaw+=.7*p.jawOpen,o}let U=null,H=[],T=[],I=[],F=[],q=null,E=null,G=null,Z=null,K=0,X=0,W=[1,1,1],J=[0,0,0],Q=!1,$=[],ee=[];const oe={open:0,width:0,round:0,smile:0,lipPress:.3,jaw:0};function te(){U&&(U.dispose(),U=null);const e=c.meshCols,o=c.meshRows;H=[],T=[],I=[];for(let t=0;t<o;t++)for(let n=0;n<e;n++){const r=n/(e-1),i=t/(o-1);T.push({u:r,v:i}),H.push(P(r,i))}const t=e=>{if(!c.fragment)return!0;const o=2*(T[e].u-.5),t=2*(.5-T[e].v);return o*o*1.2+t*t*.95<1},n=(e,o,n)=>{((e,o,n)=>{if(!t(e)||!t(o)||!t(n))return!1;if(c.mouthHole){const t=.5,r=.69,i=.18*c.mouthHoleSize,s=.075*c.mouthHoleSize,a=((T[e].u+T[o].u+T[n].u)/3-t)/i,l=((T[e].v+T[o].v+T[n].v)/3-r)/s;if(a*a+l*l<1)return!1}if(c.eyeHoles){const t=(T[e].u+T[o].u+T[n].u)/3,r=(T[e].v+T[o].v+T[n].v)/3;if(((t-.3)/.085)**2+((r-.4)/.045)**2<1||((t-.7)/.085)**2+((r-.4)/.045)**2<1)return!1}return!0})(e,o,n)&&I.push(e,o,n)};for(let t=0;t<o-1;t++)for(let o=0;o<e-1;o++){const r=t*e+o,i=t*e+(o+1),s=(t+1)*e+o,a=(t+1)*e+(o+1);(t+o)%2==0?(n(r,i,a),n(r,a,s)):(n(r,i,s),n(i,a,s))}F=function(e,o){const t=Array.from({length:o},()=>new Set);for(let o=0;o<e.length;o+=3){const n=e[o],r=e[o+1],i=e[o+2];t[n].add(r),t[n].add(i),t[r].add(n),t[r].add(i),t[i].add(n),t[i].add(r)}return t.map(e=>Array.from(e))}(I,H.length),U=new BABYLON.Mesh("face",M),U.parent=z;const r=H.length;E=new Float32Array(3*r),G=new Float32Array(3*r),Z=new Float32Array(4*r),q=new Array(r),K=1/0,X=-1/0;for(let e=0;e<r;e++)E[3*e]=H[e].x,E[3*e+1]=H[e].y,E[3*e+2]=H[e].z,H[e].z<K&&(K=H[e].z),H[e].z>X&&(X=H[e].z),q[e]=f(0,0,0),Z[4*e]=1,Z[4*e+1]=1,Z[4*e+2]=1,Z[4*e+3]=1;BABYLON.VertexData.ComputeNormals(E,I,G);const i=new BABYLON.VertexData;i.positions=Array.from(E),i.indices=I,i.normals=Array.from(G),i.colors=Array.from(Z),i.applyToMesh(U,!0),ue(),se(),ae(),ne(),Q=!0}function ne(){$=[],ee=[];const e=.18*c.mouthHoleSize,o=.075*c.mouthHoleSize;for(let t=0;t<T.length;t++){const n=(T[t].u-.5)/e,r=(T[t].v-.69)/o,i=n*n+r*r;if(i<4){const e=T[t].v<.69,o=Math.max(-1,Math.min(1,n));let r=i<=1?i:(4-i)/3;r=Math.max(0,Math.min(1,r)),$.push({idx:t,isUpper:e,xRel:o,weight:r,baselineTarget:j(o,e,oe)})}}const t=[{side:"L",cu:.3,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04},{side:"R",cu:.7,cv:.4,ru:.085,rv:.045,hw:.1,hh:.04}];for(const e of t)for(let o=0;o<T.length;o++){const t=(T[o].u-e.cu)/e.ru,n=(T[o].v-e.cv)/e.rv,r=t*t+n*n;if(r<4){const n=T[o].v<e.cv,i=Math.max(-1,Math.min(1,t));let s=r<=1?r:(4-r)/3;s=Math.max(0,Math.min(1,s));const a=P(e.cu,e.cv);ee.push({idx:o,side:e.side,isUpper:n,xRel:i,weight:s,eyeDef:{center:a,hw:e.hw,hh:e.hh},baselineTarget:V(i,n,{center:a,hw:e.hw,hh:e.hh},0,0)})}}}function re(e,o,t,n){if(Math.abs(t)<.001)return;const r=o.uv[0],i=o.uv[1],s=o.radius*n,a=s*s,l=o.dir.x*t,u=o.dir.y*t,d=o.dir.z*t;for(let o=0;o<T.length;o++){const t=T[o].u-r,n=T[o].v-i,s=t*t+n*n;if(s>4*a)continue;const h=Math.exp(-s/a);e[o].x+=l*h,e[o].y+=u*h,e[o].z+=d*h}}const ie=[{name:"nose",uv:[.5,.5],radiusUV:.16,get scale(){return c.scaleNose}},{name:"eyeL",uv:[.3,.4],radiusUV:.11,get scale(){return c.scaleEyes}},{name:"eyeR",uv:[.7,.4],radiusUV:.11,get scale(){return c.scaleEyes}},{name:"mouth",uv:[.5,.7],radiusUV:.18,get scale(){return c.scaleMouth}}];function se(){z&&(z.rotation.y=c.flipFace?Math.PI:0)}function ae(){U&&(U.isVisible=!!c.meshVisible)}function le(){S&&S.getChildMeshes().forEach(e=>e.isVisible=!!c.minimal)}function ue(){if(!U)return;U._edgesRenderer&&U.disableEdgesRendering();const e=c.lineThickness;switch(c.mode){case"wire":U.material=A,A.wireframe=!0,A.alpha=1;break;case"edges":U.material=R,R.alpha=1,R.wireframe=!1,U.enableEdgesRendering(.9999),U.edgesWidth=4*e,U.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1);break;case"shaded":U.material=R,R.alpha=1,R.wireframe=!1}}let de=null,he=null,ce=null,fe=null,me=null,pe=null;function we(){if(he&&(he.dispose(),he=null),ce&&(ce.dispose(),ce=null),me&&(me.dispose(),me=null),pe&&(pe.dispose(),pe=null),!c.pupils)return;de||(de=new BABYLON.StandardMaterial("pupilMat",M),de.emissiveColor=BABYLON.Color3.FromHexString(c.pupilColor),de.disableLighting=!0,de.backFaceCulling=!1),fe||(fe=new BABYLON.StandardMaterial("irisMat",M),fe.emissiveColor=BABYLON.Color3.FromHexString(c.irisColor),fe.disableLighting=!0,fe.backFaceCulling=!1);const e=.035*c.irisSize;me=BABYLON.MeshBuilder.CreateDisc("irisL",{radius:e,tessellation:24},M),pe=BABYLON.MeshBuilder.CreateDisc("irisR",{radius:e,tessellation:24},M),me.material=pe.material=fe,me.parent=pe.parent=z,he=BABYLON.MeshBuilder.CreateDisc("pupilL",{radius:.035,tessellation:14},M),ce=BABYLON.MeshBuilder.CreateDisc("pupilR",{radius:.035,tessellation:14},M),he.material=ce.material=de,he.parent=ce.parent=z}function ye(e,o){const t=P(e,o);if(!c.overlayTracksMesh)return t;const n=function(e,o){if(!q)return f(0,0,0);const t=.0036;let n=0,r=0,i=0,s=0;for(let a=0;a<T.length;a++){const l=T[a].u-e,u=T[a].v-o,d=l*l+u*u;if(d<t){const e=1-Math.sqrt(d/t);n+=e,r+=q[a].x*e,i+=q[a].y*e,s+=q[a].z*e}}return 0===n?f(0,0,0):f(r/n,i/n,s/n)}(e,o);return f(t.x+n.x,t.y+n.y,t.z+n.z)}function _e(e,o=18){const t=[],n=e.length,r=o=>e[Math.max(0,Math.min(n-1,o))];for(let e=0;e<n-1;e++){const n=r(e-1),i=r(e),s=r(e+1),a=r(e+2);for(let e=0;e<o;e++){const r=e/o,l=r*r,u=r*l,d=.5*(2*i.x+(-n.x+s.x)*r+(2*n.x-5*i.x+4*s.x-a.x)*l+(-n.x+3*i.x-3*s.x+a.x)*u),h=.5*(2*i.y+(-n.y+s.y)*r+(2*n.y-5*i.y+4*s.y-a.y)*l+(-n.y+3*i.y-3*s.y+a.y)*u),c=.5*(2*i.z+(-n.z+s.z)*r+(2*n.z-5*i.z+4*s.z-a.z)*l+(-n.z+3*i.z-3*s.z+a.z)*u);t.push(f(d,h,c))}}return t.push(e[n-1]),t}function ge(e,o,t,n){const r={path:o,radius:n?t:t*c.lineThickness,tessellation:6,updatable:!0};n&&(r.instance=n);const i=BABYLON.MeshBuilder.CreateTube(e,r,M);return n||(i.material=k,i.parent=S),i}let ve=null,Be=null;function be(){const e=D();return{upper:_e([-1,-.45,0,.45,1].map(o=>j(o,!0,e)),18),lower:_e([-1,-.5,0,.5,1].map(o=>j(o,!1,e)),18)}}const Me=[{side:"L",uv:[.3,.4],hw:.1,hh:.04},{side:"R",uv:[.7,.4],hw:.1,hh:.04}];let xe=[];function Le(e,o){const t="L"===e.side?p.eyeBlinkLeft:p.eyeBlinkRight,n=p.eyeSquint,r=ye(e.uv[0],e.uv[1]),i=[],s=.012*n;for(let n=0;n<=12;n++){const a=n/12*Math.PI,l=r.x+Math.cos(Math.PI-a)*e.hw,u=(r.y+(o?1:-1)*Math.sin(a)*e.hh)*(1-t)+r.y*t+(o?-s:.5*s),d=r.z+.018+.012*Math.sin(a);i.push(f(l,u,d))}return i}const Ce=[{side:"L",uv:[.27,.27]},{side:"R",uv:[.73,.27]}];let Oe=[];function ze(e){const o=ye(e.uv[0],e.uv[1]),t="L"===e.side?-1:1,n=.085*p.browInnerUp-.05*p.browDown,r=.07*(p.browOuterUp>=0?p.browOuterUp:0)-.05*p.browDown,i=o.x+-.1*t,s=o.x,a=o.x+.1*t,l=o.y+n,u=o.y+.5*(n+r)+.005,d=o.y+r-.005,h=o.z+.018;return _e([f(i,l,h),f(s,u,h+.01),f(a,d,h)],12)}let Re=null,Ae=null,ke=null;function Ne(){const e=.025*p.noseSneer,o=ye(.5,.4),t=ye(.5,.55),n=_e([f(o.x,o.y-.02,o.z+.02),f(o.x-.005,.5*(o.y+t.y),.5*(o.z+t.z)+.05),f(t.x,t.y+.03,t.z+.05)],14),r=t.y+.01;return{bridge:n,leftN:_e([f(t.x,r,t.z+.05),f(t.x-.06-e,r-.03,t.z+.02),f(t.x-.04,r-.05,t.z+.005),f(t.x-.01,r-.02,t.z+.03)],10),rightN:_e([f(t.x,r,t.z+.05),f(t.x+.06+e,r-.03,t.z+.02),f(t.x+.04,r-.05,t.z+.005),f(t.x+.01,r-.02,t.z+.03)],10)}}function Se(){ve&&(ve.dispose(),ve=null),Be&&(Be.dispose(),Be=null);for(const e of xe)e.upper.dispose(),e.lower.dispose();xe=[];for(const e of Oe)e.mesh.dispose();Oe=[],Re&&(Re.dispose(),Re=null),Ae&&(Ae.dispose(),Ae=null),ke&&(ke.dispose(),ke=null);const{upper:e,lower:o}=be();ve=ge("mouth_u",e,.01),Be=ge("mouth_l",o,.01);for(const e of Me){const o=ge("eye_"+e.side+"_u",Le(e,!0),.0085),t=ge("eye_"+e.side+"_l",Le(e,!1),.0085);xe.push({eye:e,upper:o,lower:t})}for(const e of Ce){const o=ge("brow_"+e.side,ze(e),.011);o.material=N,Oe.push({brow:e,mesh:o})}const t=Ne();Re=ge("nose_b",t.bridge,.009),Ae=ge("nose_l",t.leftN,.0085),ke=ge("nose_r",t.rightN,.0085),le()}const Pe={};function Ye(){if(U){for(let e=0;e<t.length;e++){const o=t[e];Pe[o]=p[o],p[o]=p[o]*(_[o]||1)}for(let e=0;e<q.length;e++)q[e].x=q[e].y=q[e].z=0;!function(e){const o=c.spread,t=D();re(e,m.mouth_jaw_drop,t.jaw,o),re(e,m.mouth_open_lower,t.open,o),re(e,m.mouth_open_upper,t.open,o);const n=t.smile;n>0?(re(e,m.mouth_smile_L,n,o),re(e,m.mouth_smile_R,n,o)):n<0&&(re(e,m.mouth_frown_L,-n,o),re(e,m.mouth_frown_R,-n,o)),re(e,m.mouth_round_L,t.round,o),re(e,m.mouth_round_R,t.round,o),re(e,m.mouth_round_top,t.round,o),re(e,m.mouth_round_bot,t.round,o),re(e,m.mouth_press_top,t.lipPress,o),re(e,m.mouth_press_bot,t.lipPress,o),t.width>0&&(re(e,m.mouth_width_L,t.width,o),re(e,m.mouth_width_R,t.width,o)),re(e,m.eye_blink_L_up,p.eyeBlinkLeft,o),re(e,m.eye_blink_L_lo,p.eyeBlinkLeft,o),re(e,m.eye_blink_R_up,p.eyeBlinkRight,o),re(e,m.eye_blink_R_lo,p.eyeBlinkRight,o),re(e,m.eye_squint_L,p.eyeSquint,o),re(e,m.eye_squint_R,p.eyeSquint,o),re(e,m.brow_inner_L,p.browInnerUp,o),re(e,m.brow_inner_R,p.browInnerUp,o),re(e,m.brow_outer_L,Math.max(0,p.browOuterUp),o),re(e,m.brow_outer_R,Math.max(0,p.browOuterUp),o),re(e,m.brow_down_L,p.browDown+Math.max(0,-p.browOuterUp),o),re(e,m.brow_down_R,p.browDown+Math.max(0,-p.browOuterUp),o),re(e,m.nose_sneer_L,p.noseSneer,o),re(e,m.nose_sneer_R,p.noseSneer,o)}(q),c.reactivity>0&&function(e,o){if(o<=0)return;const t=e.length,n=new Array(t);for(let r=0;r<t;r++){const t=F[r];if(0===t.length){n[r]=f(e[r].x,e[r].y,e[r].z);continue}let i=0,s=0,a=0;for(const o of t)i+=e[o].x,s+=e[o].y,a+=e[o].z;i/=t.length,s/=t.length,a/=t.length,n[r]=f(e[r].x*(1-o)+i*o,e[r].y*(1-o)+s*o,e[r].z*(1-o)+a*o)}for(let o=0;o<t;o++)e[o].x=n[o].x,e[o].y=n[o].y,e[o].z=n[o].z}(q,c.reactivity),function(e){for(const o of ie){const t=o.scale;if(Math.abs(t-1)<.001)continue;const n=P(o.uv[0],o.uv[1]),r=o.radiusUV*o.radiusUV,i=4*r;for(let s=0;s<T.length;s++){const a=T[s].u-o.uv[0],l=T[s].v-o.uv[1],u=a*a+l*l;if(u>i)continue;const d=Math.exp(-u/r),h=H[s].x-n.x,c=H[s].y-n.y,f=H[s].z-n.z,m=(t-1)*d;e[s].x+=h*m,e[s].y+=c*m,e[s].z+=f*m}}}(q),function(e){const o=c.jawExtend;if(o<.001)return;const t=p.jawOpen||0;if(t<.001)return;const n=t*o*.1;for(let o=0;o<T.length;o++){const t=T[o].v;if(t<.55)continue;const r=Math.min(1,(t-.55)/.45);e[o].z+=n*r}}(q),function(e){const o=c.mouthGrow;if(o<.001)return;const t=D().open;if(t<.001)return;const n=t*o,r=.0625;for(let o=0;o<T.length;o++){const t=T[o].u-.5,i=T[o].v-.69,s=t*t+i*i;if(s>r)continue;const a=1-Math.sqrt(s/r),l=H[o];e[o].x+=(l.x-Y.x)*n*a*.4,e[o].y+=(l.y-Y.y)*n*a*.4,e[o].z+=n*a*.05}}(q),function(e){if(!c.mouthAnchor)return;const o=D();for(const t of $){const n=j(t.xRel,t.isUpper,o),r=n.x-t.baselineTarget.x,i=n.y-t.baselineTarget.y,s=n.z-t.baselineTarget.z,a=t.weight;e[t.idx].x=e[t.idx].x*(1-a)+r*a,e[t.idx].y=e[t.idx].y*(1-a)+i*a,e[t.idx].z=e[t.idx].z*(1-a)+s*a}}(q),function(e){if(!c.eyeAnchor)return;const o=p.eyeBlinkLeft,t=p.eyeBlinkRight,n=p.eyeSquint;for(const r of ee){const i="L"===r.side?o:t,s=V(r.xRel,r.isUpper,r.eyeDef,i,n),a=s.x-r.baselineTarget.x,l=s.y-r.baselineTarget.y,u=s.z-r.baselineTarget.z,d=r.weight;e[r.idx].x=e[r.idx].x*(1-d)+a*d,e[r.idx].y=e[r.idx].y*(1-d)+l*d,e[r.idx].z=e[r.idx].z*(1-d)+u*d}}(q);for(let e=0;e<H.length;e++)E[3*e]=H[e].x+q[e].x,E[3*e+1]=H[e].y+q[e].y,E[3*e+2]=H[e].z+q[e].z;if(U.updateVerticesData(BABYLON.VertexBuffer.PositionKind,E),c.depthFade>.001){const e=X-K||1,o=c.depthFade;for(let t=0;t<H.length;t++){const n=E[3*t+2],r=Math.max(0,Math.min(1,(X-n)/e))*o;Z[4*t]=W[0]*(1-r)+J[0]*r,Z[4*t+1]=W[1]*(1-r)+J[1]*r,Z[4*t+2]=W[2]*(1-r)+J[2]*r,Z[4*t+3]=1}U.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z)}else if(Q){for(let e=0;e<H.length;e++)Z[4*e]=W[0],Z[4*e+1]=W[1],Z[4*e+2]=W[2],Z[4*e+3]=1;U.updateVerticesData(BABYLON.VertexBuffer.ColorKind,Z),Q=!1}"edges"!==c.mode&&"shaded"!==c.mode||(BABYLON.VertexData.ComputeNormals(E,I,G),U.updateVerticesData(BABYLON.VertexBuffer.NormalKind,G)),function(){if(!he||!ce)return;const e=.05*p.eyeLookH,o=.035*p.eyeLookV,t=P(.3,.4),n=P(.7,.4);me&&pe&&(me.position.set(t.x+.6*e,t.y+.6*o,t.z+.045),pe.position.set(n.x+.6*e,n.y+.6*o,n.z+.045)),he.position.set(t.x+e,t.y+o,t.z+.05),ce.position.set(n.x+e,n.y+o,n.z+.05);const r=.5*(p.eyeBlinkLeft+p.eyeBlinkRight);he.isVisible=ce.isVisible=r<.85,me&&pe&&(me.isVisible=pe.isVisible=r<.85)}(),c.minimal&&function(){if(!ve)return;const e=be();ge("",e.upper,.01,ve),ge("",e.lower,.01,Be);for(const e of xe)ge("",Le(e.eye,!0),.0085,e.upper),ge("",Le(e.eye,!1),.0085,e.lower);for(const e of Oe)ge("",ze(e.brow),.011,e.mesh);const o=Ne();ge("",o.bridge,.009,Re),ge("",o.leftN,.0085,Ae),ge("",o.rightN,.0085,ke)}(),z.rotation.x=.35*p.headRotateX,z.rotation.y=.5*p.headRotateY,z.rotation.z=.3*p.headRotateZ;for(let e=0;e<t.length;e++)p[t[e]]=Pe[t[e]]}}let je=1.5+3*Math.random(),Ve=0,De=.8+2*Math.random(),Ue=0,He=0,Te=0,Ie=0;let Fe=null,qe=null,Ee=null,Ge=null,Ze=0,Ke=0,Xe=!1,We=null;function Je(){Fe||(Fe=new(window.AudioContext||window.webkitAudioContext)),"suspended"===Fe.state&&Fe.resume()}function Qe(){if(Ee){try{Ee.stop()}catch(e){}try{Ee.disconnect()}catch(e){}Ee=null}if(Ge){try{Ge.disconnect()}catch(e){}Ge=null}Xe=!1}function $e(){return Fe&&qe?Xe?Fe.currentTime-Ze:Ke||0:0}function eo(e,o){if(!We)return 0;const t=Fe.sampleRate/2/We.length,n=Math.max(0,Math.floor(e/t)),r=Math.min(We.length-1,Math.ceil(o/t));let i=0,s=0;for(let e=n;e<=r;e++)i+=We[e],s++;return s?i/s/255:0}function oo(e){c.lineColor=e,k.emissiveColor=BABYLON.Color3.FromHexString(e)}function to(e){c.pupilColor=e,de&&(de.emissiveColor=BABYLON.Color3.FromHexString(e))}function no(e){c.baseColor=e,W=d(e),Q=!0,A.emissiveColor=new BABYLON.Color3(W[0],W[1],W[2]),U&&U._edgesRenderer&&(U.edgesColor=new BABYLON.Color4(W[0],W[1],W[2],1))}function ro(e){c.fadeColor=e,J=d(e),Q=!0}function io(e){c.irisColor=e,fe&&(fe.emissiveColor=BABYLON.Color3.FromHexString(e))}function so(e){c.browColor=e,N.emissiveColor=BABYLON.Color3.FromHexString(e)}const ao={front:{alpha:-Math.PI/2,beta:Math.PI/2,radius:4.4},"three-q":{alpha:-Math.PI/2-.6,beta:Math.PI/2-.15,radius:4},profile:{alpha:0,beta:Math.PI/2,radius:4.6},orbit:null};let lo=!1;function uo(e){if("orbit"===e)return void(lo=!0);lo=!1;const o=ao[e];o&&(L.alpha=o.alpha,L.beta=o.beta,L.radius=o.radius)}function ho(){x.intensity=c.glow?.85:0}te(),we(),Se(),no(c.baseColor),ro(c.fadeColor),oo(c.lineColor),so(c.browColor),to(c.pupilColor),io(c.irisColor),ho(),uo(c.cameraView);let co=performance.now(),fo=!1;b.runRenderLoop(()=>{if(fo)return;const e=performance.now(),o=Math.min(.05,(e-co)/1e3);co=e,function(e){Ve+=e,Ve>je&&!y.eyeBlinkLeft&&!y.eyeBlinkRight&&(w.eyeBlinkLeft=1,w.eyeBlinkRight=1,setTimeout(()=>{w.eyeBlinkLeft=v.sleep>.5?1:0,w.eyeBlinkRight=v.sleep>.5?1:0},110),Ve=0,je=1.5+3.5*Math.random()),Ue+=e,Ue>De&&!y.eyeLookH&&(He=.6*(Math.random()-.5),Te=.4*(Math.random()-.5),Ue=0,De=.7+2.5*Math.random()),w.eyeLookH=He,w.eyeLookV=Te,Ie+=e,w.headRotateX=.04*Math.sin(.27*Ie),w.headRotateY=.06*Math.sin(.19*Ie),w.headRotateZ=.03*Math.sin(.11*Ie)}(o),Xe&&function(){if(!Ge)return;Ge.getByteFrequencyData(We);const e=eo(200,700),o=eo(700,2e3),t=eo(2e3,4e3),r=eo(4e3,8e3),i=eo(1500,5e3),s=Math.max(e,o,t,r);if(s<.08){for(const e of Object.keys(n))w["viseme_"+e]=0;return w.viseme_sil=1,void(w.jawOpen=0)}w.viseme_sil=0,w.jawOpen=.7*s;for(const e of Object.keys(n))"sil"!==e&&(w["viseme_"+e]=0);r>.35&&r>.8*o&&(w.viseme_SS=Math.min(1,1.3*r),w.viseme_FF=Math.min(.6,1.2*i)),e>o&&e>.18?t>.25?w.viseme_aa=Math.min(1,1.2*e):(w.viseme_O=Math.min(1,1.2*e),w.viseme_U=Math.min(.7,.9*e)):o>.2&&(t>.6*o?(w.viseme_I=Math.min(1,1.4*t),w.viseme_E=Math.min(.7,1.1*o)):(w.viseme_E=Math.min(1,1.3*o),w.viseme_aa=Math.min(.4,.9*e)))}(),function(e){const o=Math.max(.05,c.moodTransitionTime)/4,t=1-Math.pow(.5,e/o);for(const e of i)v[e]+=(g[e]-v[e])*t;for(const e of s){let o=0;for(const t of i)o+=(r[t][e]||0)*v[t];w[e]=o}}(o),function(e){for(const o of t){if(y[o]){p[o]=w[o];continue}const t=a[o]||a.default,n=1-Math.exp(-t*e*30);p[o]=p[o]+(w[o]-p[o])*n}}(o),Ye(),lo&&(L.alpha+=.3*o),M.render()});const mo=()=>b.resize();function po(e){if(!e)return;const o=e.renderConfig||{};let n=!1;if(void 0!==o.meshCols&&o.meshCols!==c.meshCols&&(n=!0),void 0!==o.meshRows&&o.meshRows!==c.meshRows&&(n=!0),void 0!==o.fragment&&o.fragment!==c.fragment&&(n=!0),void 0!==o.mouthHole&&o.mouthHole!==c.mouthHole&&(n=!0),void 0!==o.eyeHoles&&o.eyeHoles!==c.eyeHoles&&(n=!0),void 0!==o.mouthHoleSize&&o.mouthHoleSize!==c.mouthHoleSize&&(n=!0),void 0!==o.eyeDepth&&o.eyeDepth!==c.eyeDepth&&(n=!0),Object.assign(c,o),e.lineColor&&oo(e.lineColor),e.pupilColor&&to(e.pupilColor),o.baseColor&&no(o.baseColor),o.fadeColor&&ro(o.fadeColor),o.lineColor&&oo(o.lineColor),o.pupilColor&&to(o.pupilColor),o.irisColor&&io(o.irisColor),o.browColor&&so(o.browColor),n?(te(),Se(),we()):(ue(),se(),ae(),le(),void 0!==o.lineThickness&&Se(),void 0!==o.irisSize&&we(),void 0===o.lipVertAmp&&void 0===o.lipPressForce||ne()),void 0!==o.glow&&ho(),e.channelGains)for(const o of t)void 0!==e.channelGains[o]&&(_[o]=e.channelGains[o]);if(e.activeMood&&r[e.activeMood]){B=e.activeMood;for(const e of i)g[e]=e===B?1:0}}return window.addEventListener("resize",mo),{loadAudio:async function(e){Je();const o=await e.arrayBuffer();qe=await Fe.decodeAudioData(o.slice(0)),Ke=0},play(e){qe&&function(e){qe&&(Je(),Ee=Fe.createBufferSource(),Ee.buffer=qe,Ee.loop=!!c.loopAudio,Ge=Fe.createAnalyser(),Ge.fftSize=1024,Ge.smoothingTimeConstant=.4,We=new Uint8Array(Ge.frequencyBinCount),Ee.connect(Ge),Ge.connect(Fe.destination),Ze=Fe.currentTime-(e||0),Ee.start(0,e||0),Ee.onended=()=>{if(!c.loopAudio){Xe=!1;for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0}},Xe=!0)}(void 0!==e?e:Ke)},pause(){Xe&&(Ke=$e(),Qe())},stop(){Ke=0,Qe();for(const e of Object.keys(n))w["viseme_"+e]=0;w.viseme_sil=1,w.jawOpen=0},setLoop(e){c.loopAudio=!!e,Ee&&(Ee.loop=!!e)},setMood(e){if(r[e]){B=e;for(const o of i)g[o]=o===e?1:0}},setChannel(e,t){if(!o[e])return;const n=o[e].range,r=Math.max(n[0],Math.min(n[1],t));w[e]=r,p[e]=r,y[e]=!0,clearTimeout(y["_t_"+e]),y["_t_"+e]=setTimeout(()=>{y[e]=!1},1200)},setView:uo,loadPreset:po,setRenderConfig(e){po({renderConfig:e})},getRenderConfig:()=>Object.assign({},c),getChannel:e=>void 0!==p[e]?p[e]:0,getChannelTarget:e=>void 0!==w[e]?w[e]:0,getChannelGain:e=>void 0!==_[e]?_[e]:1,setChannelGain(e,t){o[e]&&(_[e]=t)},getChannelNames:()=>t.slice(),getMoodNames:()=>i.slice(),isPlaying:()=>Xe,getDuration:()=>qe?qe.duration:0,getPosition:()=>$e(),getActiveMood:()=>B,dispose(){fo=!0;try{Qe()}catch(e){}if(Fe){try{Fe.close()}catch(e){}Fe=null}window.removeEventListener("resize",mo);try{b.stopRenderLoop()}catch(e){}try{M.dispose()}catch(e){}try{b.dispose()}catch(e){}}}}e.createWireface=h,"undefined"!=typeof module&&module.exports&&(module.exports={createWireface:h})}("undefined"!=typeof window?window:globalThis);
|
|
Binary file
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<!--
|
|
3
|
+
wireface-demo.html — two-instance demo for wireface.js
|
|
4
|
+
Copyright (c) 2026 Peter Styk
|
|
5
|
+
Released under the MIT License — see LICENSE in the repository root.
|
|
6
|
+
-->
|
|
7
|
+
<html lang="en">
|
|
8
|
+
<head>
|
|
9
|
+
<meta charset="utf-8">
|
|
10
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
11
|
+
<title>WIREFACE — two-instance demo</title>
|
|
12
|
+
<style>
|
|
13
|
+
:root {
|
|
14
|
+
--bg: #0a0a0a;
|
|
15
|
+
--bg-soft: #141414;
|
|
16
|
+
--fg: #f4f4f0;
|
|
17
|
+
--dim: #888;
|
|
18
|
+
--border: rgba(255,255,255,0.10);
|
|
19
|
+
--border-bright: rgba(255,255,255,0.22);
|
|
20
|
+
--accent: #f5e663;
|
|
21
|
+
--mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', 'Monaco', 'Cascadia Code', monospace;
|
|
22
|
+
}
|
|
23
|
+
* { box-sizing: border-box; }
|
|
24
|
+
html, body { width: 100%; height: 100%; margin: 0; background: var(--bg); color: var(--fg); font-family: var(--mono); font-weight: 300; -webkit-font-smoothing: antialiased; }
|
|
25
|
+
|
|
26
|
+
header { display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
|
|
27
|
+
header .mark { font-size: 13px; letter-spacing: 0.3em; font-weight: 500; }
|
|
28
|
+
header .sub { font-size: 11px; color: var(--dim); letter-spacing: 0.18em; text-transform: uppercase; }
|
|
29
|
+
|
|
30
|
+
main { display: grid; grid-template-columns: 1fr 1fr; gap: 0; height: calc(100vh - 54px); }
|
|
31
|
+
|
|
32
|
+
.panel { position: relative; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
|
|
33
|
+
.panel:last-child { border-right: none; }
|
|
34
|
+
|
|
35
|
+
.pl-label { display: flex; justify-content: space-between; padding: 10px 16px; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); border-bottom: 1px solid var(--border); }
|
|
36
|
+
.pl-label .name { color: var(--fg); }
|
|
37
|
+
.pl-label .meta { font-variant-numeric: tabular-nums; }
|
|
38
|
+
|
|
39
|
+
.canvas-wrap { flex: 1; position: relative; min-height: 0; background: #000; }
|
|
40
|
+
canvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
|
|
41
|
+
|
|
42
|
+
/* drop zone — overlays the canvas, becomes visible during drag */
|
|
43
|
+
.drop-overlay {
|
|
44
|
+
position: absolute; inset: 0;
|
|
45
|
+
display: grid; place-items: center;
|
|
46
|
+
background: rgba(0,0,0,0.6);
|
|
47
|
+
border: 2px dashed var(--accent);
|
|
48
|
+
color: var(--accent);
|
|
49
|
+
font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase;
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
opacity: 0;
|
|
52
|
+
transition: opacity 0.15s;
|
|
53
|
+
}
|
|
54
|
+
.panel.drag-over .drop-overlay { opacity: 1; }
|
|
55
|
+
|
|
56
|
+
/* per-instance controls strip below canvas */
|
|
57
|
+
.controls {
|
|
58
|
+
display: grid;
|
|
59
|
+
grid-template-columns: auto auto 1fr auto;
|
|
60
|
+
gap: 10px;
|
|
61
|
+
align-items: center;
|
|
62
|
+
padding: 10px 16px;
|
|
63
|
+
border-top: 1px solid var(--border);
|
|
64
|
+
font-size: 11px;
|
|
65
|
+
}
|
|
66
|
+
.controls button {
|
|
67
|
+
font-family: var(--mono);
|
|
68
|
+
font-size: 10px;
|
|
69
|
+
letter-spacing: 0.16em;
|
|
70
|
+
text-transform: uppercase;
|
|
71
|
+
background: transparent;
|
|
72
|
+
color: var(--fg);
|
|
73
|
+
border: 1px solid var(--border-bright);
|
|
74
|
+
padding: 7px 12px;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
transition: all 0.12s;
|
|
77
|
+
}
|
|
78
|
+
.controls button:hover { background: var(--fg); color: var(--bg); border-color: var(--fg); }
|
|
79
|
+
.controls button:disabled { opacity: 0.3; cursor: not-allowed; }
|
|
80
|
+
.controls button:disabled:hover { background: transparent; color: var(--fg); border-color: var(--border-bright); }
|
|
81
|
+
|
|
82
|
+
.file-info {
|
|
83
|
+
font-size: 10px;
|
|
84
|
+
color: var(--dim);
|
|
85
|
+
white-space: nowrap;
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
text-overflow: ellipsis;
|
|
88
|
+
border-left: 2px solid var(--border-bright);
|
|
89
|
+
padding-left: 10px;
|
|
90
|
+
}
|
|
91
|
+
.file-info b { color: var(--fg); font-weight: 400; }
|
|
92
|
+
|
|
93
|
+
.moods {
|
|
94
|
+
display: flex;
|
|
95
|
+
gap: 4px;
|
|
96
|
+
padding: 8px 16px;
|
|
97
|
+
border-top: 1px solid var(--border);
|
|
98
|
+
flex-wrap: wrap;
|
|
99
|
+
}
|
|
100
|
+
.moods button {
|
|
101
|
+
font-family: var(--mono);
|
|
102
|
+
font-size: 9px;
|
|
103
|
+
letter-spacing: 0.14em;
|
|
104
|
+
text-transform: uppercase;
|
|
105
|
+
background: transparent;
|
|
106
|
+
color: var(--fg);
|
|
107
|
+
border: 1px solid var(--border);
|
|
108
|
+
padding: 5px 8px;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
flex: 1;
|
|
111
|
+
min-width: 0;
|
|
112
|
+
}
|
|
113
|
+
.moods button:hover { background: rgba(255,255,255,0.05); }
|
|
114
|
+
.moods button.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }
|
|
115
|
+
|
|
116
|
+
.hint {
|
|
117
|
+
position: absolute; left: 12px; bottom: 12px;
|
|
118
|
+
font-size: 9px; color: var(--dim);
|
|
119
|
+
letter-spacing: 0.1em; text-transform: uppercase;
|
|
120
|
+
pointer-events: none;
|
|
121
|
+
user-select: none;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@media (max-width: 880px) {
|
|
125
|
+
main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; height: calc(200vh - 54px); }
|
|
126
|
+
.panel { border-right: none; border-bottom: 1px solid var(--border); }
|
|
127
|
+
}
|
|
128
|
+
</style>
|
|
129
|
+
</head>
|
|
130
|
+
<body>
|
|
131
|
+
|
|
132
|
+
<header>
|
|
133
|
+
<div class="mark">WIREFACE</div>
|
|
134
|
+
<div class="sub">two-instance demo · drop a preset.json or audio file onto each panel</div>
|
|
135
|
+
</header>
|
|
136
|
+
|
|
137
|
+
<main>
|
|
138
|
+
<section class="panel" data-instance="left">
|
|
139
|
+
<div class="pl-label"><span class="name">left</span><span class="meta" data-meta>—</span></div>
|
|
140
|
+
<div class="canvas-wrap">
|
|
141
|
+
<canvas data-canvas></canvas>
|
|
142
|
+
<div class="drop-overlay">drop preset.json or audio file</div>
|
|
143
|
+
<div class="hint">drop here · click ▶ to play</div>
|
|
144
|
+
</div>
|
|
145
|
+
<div class="controls">
|
|
146
|
+
<button data-action="play">▶ play</button>
|
|
147
|
+
<button data-action="stop">■ stop</button>
|
|
148
|
+
<div class="file-info"><b data-audio-name>no audio loaded</b></div>
|
|
149
|
+
<button data-action="loop" data-on="1">⟲ loop</button>
|
|
150
|
+
</div>
|
|
151
|
+
<div class="moods">
|
|
152
|
+
<button data-mood="neutral" class="on">neutral</button>
|
|
153
|
+
<button data-mood="happy">happy</button>
|
|
154
|
+
<button data-mood="sad">sad</button>
|
|
155
|
+
<button data-mood="angry">angry</button>
|
|
156
|
+
<button data-mood="fear">fear</button>
|
|
157
|
+
<button data-mood="surprise">surpr</button>
|
|
158
|
+
<button data-mood="sleep">sleep</button>
|
|
159
|
+
</div>
|
|
160
|
+
</section>
|
|
161
|
+
|
|
162
|
+
<section class="panel" data-instance="right">
|
|
163
|
+
<div class="pl-label"><span class="name">right</span><span class="meta" data-meta>—</span></div>
|
|
164
|
+
<div class="canvas-wrap">
|
|
165
|
+
<canvas data-canvas></canvas>
|
|
166
|
+
<div class="drop-overlay">drop preset.json or audio file</div>
|
|
167
|
+
<div class="hint">drop here · click ▶ to play</div>
|
|
168
|
+
</div>
|
|
169
|
+
<div class="controls">
|
|
170
|
+
<button data-action="play">▶ play</button>
|
|
171
|
+
<button data-action="stop">■ stop</button>
|
|
172
|
+
<div class="file-info"><b data-audio-name>no audio loaded</b></div>
|
|
173
|
+
<button data-action="loop" data-on="1">⟲ loop</button>
|
|
174
|
+
</div>
|
|
175
|
+
<div class="moods">
|
|
176
|
+
<button data-mood="neutral" class="on">neutral</button>
|
|
177
|
+
<button data-mood="happy">happy</button>
|
|
178
|
+
<button data-mood="sad">sad</button>
|
|
179
|
+
<button data-mood="angry">angry</button>
|
|
180
|
+
<button data-mood="fear">fear</button>
|
|
181
|
+
<button data-mood="surprise">surpr</button>
|
|
182
|
+
<button data-mood="sleep">sleep</button>
|
|
183
|
+
</div>
|
|
184
|
+
</section>
|
|
185
|
+
</main>
|
|
186
|
+
|
|
187
|
+
<!-- Babylon (peer) + library -->
|
|
188
|
+
<script src="https://cdn.babylonjs.com/babylon.js"></script>
|
|
189
|
+
<script src="wireface.js"></script>
|
|
190
|
+
|
|
191
|
+
<script>
|
|
192
|
+
/* Mount one wireface instance per panel and wire per-instance drag-drop +
|
|
193
|
+
transport buttons + mood buttons + audio name display. Each panel is a
|
|
194
|
+
self-contained little widget that knows nothing about the other one. */
|
|
195
|
+
|
|
196
|
+
function mountPanel(panelEl) {
|
|
197
|
+
const canvas = panelEl.querySelector('[data-canvas]');
|
|
198
|
+
const meta = panelEl.querySelector('[data-meta]');
|
|
199
|
+
const audioName = panelEl.querySelector('[data-audio-name]');
|
|
200
|
+
const playBtn = panelEl.querySelector('[data-action="play"]');
|
|
201
|
+
const stopBtn = panelEl.querySelector('[data-action="stop"]');
|
|
202
|
+
const loopBtn = panelEl.querySelector('[data-action="loop"]');
|
|
203
|
+
const moodBtns = panelEl.querySelectorAll('[data-mood]');
|
|
204
|
+
|
|
205
|
+
const wf = createWireface(canvas);
|
|
206
|
+
let presetName = null;
|
|
207
|
+
|
|
208
|
+
/* --- transport --- */
|
|
209
|
+
function setPlayUI(playing) {
|
|
210
|
+
playBtn.textContent = playing ? '❚❚ pause' : '▶ play';
|
|
211
|
+
}
|
|
212
|
+
playBtn.addEventListener('click', () => {
|
|
213
|
+
if (wf.isPlaying()) {
|
|
214
|
+
wf.pause();
|
|
215
|
+
setPlayUI(false);
|
|
216
|
+
} else {
|
|
217
|
+
wf.play();
|
|
218
|
+
setPlayUI(true);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
stopBtn.addEventListener('click', () => {
|
|
222
|
+
wf.stop();
|
|
223
|
+
setPlayUI(false);
|
|
224
|
+
});
|
|
225
|
+
loopBtn.addEventListener('click', () => {
|
|
226
|
+
const isOn = loopBtn.dataset.on === '1';
|
|
227
|
+
const next = !isOn;
|
|
228
|
+
loopBtn.dataset.on = next ? '1' : '0';
|
|
229
|
+
loopBtn.style.color = next ? 'var(--accent)' : '';
|
|
230
|
+
wf.setLoop(next);
|
|
231
|
+
});
|
|
232
|
+
// initial loop state from button
|
|
233
|
+
wf.setLoop(loopBtn.dataset.on === '1');
|
|
234
|
+
loopBtn.style.color = 'var(--accent)';
|
|
235
|
+
|
|
236
|
+
/* --- mood pills --- */
|
|
237
|
+
for (const b of moodBtns) {
|
|
238
|
+
b.addEventListener('click', () => {
|
|
239
|
+
moodBtns.forEach(x => x.classList.remove('on'));
|
|
240
|
+
b.classList.add('on');
|
|
241
|
+
wf.setMood(b.dataset.mood);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* --- drag/drop: detect file type by extension/MIME, route accordingly --- */
|
|
246
|
+
panelEl.addEventListener('dragenter', e => { e.preventDefault(); panelEl.classList.add('drag-over'); });
|
|
247
|
+
panelEl.addEventListener('dragover', e => { e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; });
|
|
248
|
+
panelEl.addEventListener('dragleave', e => {
|
|
249
|
+
if (e.target === panelEl || !panelEl.contains(e.relatedTarget)) panelEl.classList.remove('drag-over');
|
|
250
|
+
});
|
|
251
|
+
panelEl.addEventListener('drop', async e => {
|
|
252
|
+
e.preventDefault();
|
|
253
|
+
panelEl.classList.remove('drag-over');
|
|
254
|
+
const file = e.dataTransfer.files && e.dataTransfer.files[0];
|
|
255
|
+
if (!file) return;
|
|
256
|
+
await ingestFile(file);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
async function ingestFile(file) {
|
|
260
|
+
const isJson = /\.json$/i.test(file.name) || file.type === 'application/json';
|
|
261
|
+
const isAudio = file.type.startsWith('audio/') || /\.(mp3|wav|ogg|m4a|flac|aac|opus)$/i.test(file.name);
|
|
262
|
+
if (isJson) {
|
|
263
|
+
try {
|
|
264
|
+
const text = await file.text();
|
|
265
|
+
const data = JSON.parse(text);
|
|
266
|
+
// Saved exports are either a single preset object or an array of them.
|
|
267
|
+
const preset = Array.isArray(data) ? data[0] : data;
|
|
268
|
+
wf.loadPreset(preset);
|
|
269
|
+
presetName = preset.name || file.name.replace(/\.json$/i, '');
|
|
270
|
+
meta.textContent = 'preset: ' + presetName;
|
|
271
|
+
} catch (err) {
|
|
272
|
+
console.warn('[wireface] preset parse failed', err);
|
|
273
|
+
meta.textContent = 'preset error';
|
|
274
|
+
}
|
|
275
|
+
} else if (isAudio) {
|
|
276
|
+
try {
|
|
277
|
+
await wf.loadAudio(file);
|
|
278
|
+
audioName.textContent = file.name;
|
|
279
|
+
} catch (err) {
|
|
280
|
+
console.warn('[wireface] audio decode failed', err);
|
|
281
|
+
audioName.textContent = 'decode failed';
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
console.warn('[wireface] unsupported file type', file.type, file.name);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/* --- expose for console poking --- */
|
|
289
|
+
return wf;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
window.wirefaceLeft = mountPanel(document.querySelector('[data-instance="left"]'));
|
|
293
|
+
window.wirefaceRight = mountPanel(document.querySelector('[data-instance="right"]'));
|
|
294
|
+
</script>
|
|
295
|
+
</body>
|
|
296
|
+
</html>
|