@idosgames/characters 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{PartsManager-CAVBKvp6.d.ts → PartsManager-BpAUMQXw.d.ts} +100 -10
- package/dist/{PartsManager-Cn3MU-VS.d.cts → PartsManager-CmrzoyJR.d.cts} +100 -10
- package/dist/{chunk-Z5I76WRJ.js → chunk-BMZA5JIA.js} +1 -1
- package/dist/chunk-SDZXML7V.js +1 -0
- package/dist/chunk-UUX4NEC2.js +2 -0
- package/dist/rig2d/editor/index.cjs +8 -4
- package/dist/rig2d/editor/index.d.cts +4 -2
- package/dist/rig2d/editor/index.d.ts +4 -2
- package/dist/rig2d/editor/index.js +8 -4
- package/dist/rig2d/index.cjs +4 -4
- package/dist/rig2d/index.d.cts +14 -4
- package/dist/rig2d/index.d.ts +14 -4
- package/dist/rig2d/index.js +4 -4
- package/dist/rig2d/phaser/index.cjs +2 -2
- package/dist/rig2d/phaser/index.d.cts +1 -1
- package/dist/rig2d/phaser/index.d.ts +1 -1
- package/dist/rig2d/phaser/index.js +1 -1
- package/dist/rig2d/three/index.cjs +1 -1
- package/dist/rig2d/three/index.d.cts +1 -1
- package/dist/rig2d/three/index.d.ts +1 -1
- package/dist/rig2d/three/index.js +1 -1
- package/dist/{thumbnail-BhGEEXux.d.cts → thumbnail-B1WjbWcW.d.cts} +1 -1
- package/dist/{thumbnail-Bp-jK70T.d.ts → thumbnail-B7wrQe1B.d.ts} +1 -1
- package/dist/voxel/index.cjs +1 -1
- package/dist/voxel/index.d.cts +5 -0
- package/dist/voxel/index.d.ts +5 -0
- package/dist/voxel/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-BU66AZ2Z.js +0 -1
- package/dist/chunk-OF4BH3JZ.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var R=require('phaser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var R__default=/*#__PURE__*/_interopDefault(R);var X=Math.PI/180,ct=1e-5;function St(l,t){return l.type==="ik"?new E(l,t):new pt(l,t)}var ht=l=>l>180?l-360:l<=-180?l+360:l,E=class{constructor(t,e){this.data=t;this.bones=t.bones.map(n=>e.bones[n.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Mt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Mt(l,t,e,n,o){let s=t.bone.parent;if(!s)return;t.modifyLocal(l);let r=s.applied,i=r.a,c=r.b,a=r.c,h=r.d,p=-t.shearX-t.rotation,u=i*h-c*a,m=e-r.worldX,f=n-r.worldY,y=(m*h-f*c)/u-t.x,d=(f*i-m*a)/u-t.y;p+=Math.atan2(d,y)/X,t.scaleX<0&&(p+=180),t.rotation+=ht(p)*o;}function Ot(l,t,e,n,o,s,r){t.modifyLocal(l),e.modifyLocal(l);let i=t.x,c=t.y,a=t.scaleX,h=t.scaleY,p=e.scaleX,u,m,f;a<0?(a=-a,u=180,f=-1):(u=0,f=1),h<0&&(h=-h,f=-f),p<0?(p=-p,m=180):m=0;let y=Math.abs(a-h)<=ct,d,g;y?(d=t.a*e.x+t.b*e.y+t.worldX,g=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,d=t.a*e.x+t.worldX,g=t.c*e.x+t.worldY);let v=t.bone.parent;if(!v)return;let b=v.applied,B=b.a,$=b.b,rt=b.c,it=b.d,A=B*it-$*rt,H=d-b.worldX,W=g-b.worldY;A=Math.abs(A)<=ct?0:1/A;let gt=(H*it-W*$)*A-i,yt=(W*B-H*rt)*A-c,x=Math.sqrt(gt*gt+yt*yt),T=e.bone.data.length*p;if(x<ct){Mt(l,t,n,o,r),e.rotation=0;return}H=n-b.worldX,W=o-b.worldY;let q=(H*it-W*$)*A-i,N=(W*B-H*rt)*A-c,K=q*q+N*N,P=0,S=0;if(y){T*=a;let k=(K-x*x-T*T)/(2*x*T);k<-1?(k=-1,S=Math.PI*s):k>1?(k=1,S=0):S=Math.acos(k)*s;let L=x+T*k,D=T*Math.sin(S);P=Math.atan2(N*L-q*D,q*L+N*D);}else {let k=a*T,L=h*T,D=k*k,G=L*L,at=Math.atan2(N,q),w=G*x*x+D*K-D*G,z=-2*G*x,xt=G-D,kt=z*z-4*xt*w,vt=false;if(kt>=0){let M=Math.sqrt(kt);z<0&&(M=-M),M=-(z+M)*.5;let I=M/xt,O=w/M,Y=Math.abs(I)<Math.abs(O)?I:O,V=K-Y*Y;if(V>=0){let C=Math.sqrt(V)*s;P=at-Math.atan2(C,Y),S=Math.atan2(C/h,(Y-x)/a),vt=true;}}if(!vt){let M=Math.PI,I=x-k,O=I*I,Y=0,V=0,C=x+k,lt=C*C,wt=0;if(w=-k*x/(D-G),w>=-1&&w<=1){w=Math.acos(w);let _=k*Math.cos(w)+x,Q=L*Math.sin(w),Z=_*_+Q*Q;Z<O&&(M=w,O=Z,I=_,Y=Q),Z>lt&&(V=w,lt=Z,C=_,wt=Q);}K<=(O+lt)*.5?(P=at-Math.atan2(Y*s,I),S=M*s):(P=at-Math.atan2(wt*s,C),S=V*s);}}let bt=Math.atan2(e.y,e.x)*f;P=ht((P-bt)/X+u-t.rotation),S=ht(((S+bt)/X-e.shearX)*f+m-e.rotation),t.rotation+=P*r,e.rotation+=S*r;}var pt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(n=>e.bones[n.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let n=this.source.applied,o=this.data.offsets;for(let s of this.bones){let r=s.applied;r.modifyWorld(t);for(let i of this.data.properties){let c=Et(t,n,i.prop,o)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Ft(t,r,a.prop,a.offset+c*a.scale,h);}}}}};function Et(l,t,e,n){let o=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let r=(t.a*t.d-t.b*t.c)*o*s>0?1:-1,i=Math.atan2(t.c/s,t.a/o)/X+r*n.rotate;return i<0&&(i+=360),i}case "x":return (n.x*t.a+n.y*t.b+t.worldX)/o;case "y":return (n.x*t.c+n.y*t.d+t.worldY)/s;case "scaleX":return Math.hypot(t.a/o,t.c/s)+n.scaleX;case "scaleY":return Math.hypot(t.b/o,t.d/s)+n.scaleY;case "shearY":return (Math.atan2(t.d/s,t.b/o)-Math.atan2(t.c/s,t.a/o))/X-90+n.shearY}}function Ft(l,t,e,n,o){let s=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let i=t.a/s,c=t.b/s,a=t.c/r,h=t.d/r,p=n*X-Math.atan2(a,i);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=o;let u=Math.cos(p),m=Math.sin(p);t.a=(u*i-m*a)*s,t.b=(u*c-m*h)*s,t.c=(m*i+u*a)*r,t.d=(m*c+u*h)*r;return}case "x":t.worldX+=(n-t.worldX/s)*o*s;return;case "y":t.worldY+=(n-t.worldY/r)*o*r;return;case "scaleX":{let i=Math.hypot(t.a/s,t.c/r);i!==0&&(i=1+(n-i)*o/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/s,t.d/r);i!==0&&(i=1+(n-i)*o/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/s,c=t.d/r,a=Math.atan2(c,i),h=(n+90)*X;h-=a-Math.atan2(t.c/r,t.a/s),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*o;let p=Math.hypot(i,c);t.b=Math.cos(h)*p*s,t.d=Math.sin(h)*p*r;return}}}var tt=class{constructor(t,e,n=.2){this.skeleton=t;this.data=e;this.defaultMix=n;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let n={bones:new Set(t.bones.map(o=>this.data.bone(o).index)),slots:new Set(t.slots.map(o=>this.data.slot(o).index))};this.blink={source:e,filter:n,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let n=this.data.animations.get(t);if(!n)return false;let o=e.mix??this.defaultMix;return this.previous=this.track&&o>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?o:0,this.track={animation:n,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let n=this.listeners.get(t)??new Set;return n.add(e),this.listeners.set(t,n),()=>n.delete(e)}update(t){let e=[],n=this.track;if(n&&!n.done){let o=n.time;n.time+=Math.max(0,t)*n.speed,this.collect(n,o,n.time,e),!n.loop&&n.time>=n.animation.duration&&(n.time=n.animation.duration,n.done=true,e.push({name:"end",animation:n.animation.name}));}if(this.previous){let o=this.previous;o.time+=Math.max(0,t)*o.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let o of e){for(let s of this.listeners.get(o.name)??[])s(o);for(let s of this.listeners.get("*")??[])s(o);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let n=this.blink;n&&n.at>=0&&n.source.applyOnly(t,n.options.from+n.at,n.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,n,o){let s=t.animation.duration;if(s<=0||n<=e)return;let r=Math.floor(e/s),i=t.loop?Math.floor(n/s):0;for(let c=r;c<=i;c++)for(let a of t.animation.events){let h=c*s+a.time;h>=e&&(h<n||!t.loop&&h<=n)&&o.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,n)=>{let o=e.pose;this.snapshot.set([o.x,o.y,o.rotation,o.scaleX,o.scaleY],n*5);}),t.slots.forEach((e,n)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],n*4)),t.constraints.forEach((e,n)=>{e instanceof E&&(this.ikSnapshot[n]=e.mix);});}blendFromSaved(t){let e=this.skeleton,n=(o,s)=>o+(s-o)*t;e.bones.forEach((o,s)=>{let r=this.snapshot,i=o.pose,c=s*5;i.x=n(r[c],i.x),i.y=n(r[c+1],i.y);let a=i.rotation-r[c+2];a-=Math.round(a/360)*360,i.rotation=r[c+2]+a*t,i.scaleX=n(r[c+3],i.scaleX),i.scaleY=n(r[c+4],i.scaleY);}),e.slots.forEach((o,s)=>{let r=this.slotSnapshot;o.color.r=n(r[s*4],o.color.r),o.color.g=n(r[s*4+1],o.color.g),o.color.b=n(r[s*4+2],o.color.b),o.color.a=n(r[s*4+3],o.color.a);}),e.constraints.forEach((o,s)=>{o instanceof E&&(o.mix=n(this.ikSnapshot[s],o.mix));});}};var Tt=Math.PI/180,Rt=new Float32Array([0,1,0,0,1,0,1,1]),Ht=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function Wt(l){let t=At.get(l);if(t)return t;let e=-l.width/2*l.scaleX,n=-l.height/2*l.scaleY,o=l.width/2*l.scaleX,s=l.height/2*l.scaleY,r=Math.cos(l.rotation*Tt),i=Math.sin(l.rotation*Tt),c=(a,h)=>[a*r-h*i+l.x,a*i+h*r+l.y];return t=Float32Array.from([...c(e,n),...c(e,s),...c(o,s),...c(o,n)]),At.set(l,t),t}function et(l,t,e,n){if(e.type==="region"){let o=n&&n.length===8?n:new Float32Array(8),s=Wt(e),r=t.bone.applied;for(let i=0;i<8;i+=2){let c=s[i],a=s[i+1];o[i]=c*r.a+a*r.b+r.worldX,o[i+1]=c*r.c+a*r.d+r.worldY;}return {positions:o,uvs:Rt,triangles:Ht}}return qt(l,t,e,n)}function qt(l,t,e,n){let o=e.vertexCount*2,s=n&&n.length===o?n:new Float32Array(o),r=e.vertices;if(e.weighted){let i=0;for(let c=0;c<o;c+=2){let a=r[i++],h=0,p=0;for(let u=0;u<a;u++,i+=4){let m=l.bones[r[i]].applied,f=r[i+1],y=r[i+2],d=r[i+3];h+=(f*m.a+y*m.b+m.worldX)*d,p+=(f*m.c+y*m.d+m.worldY)*d;}s[c]=h,s[c+1]=p;}}else {let i=t.bone.applied;for(let c=0;c<o;c+=2){let a=r[c],h=r[c+1];s[c]=a*i.a+h*i.b+i.worldX,s[c+1]=a*i.c+h*i.d+i.worldY;}}return {positions:s,uvs:e.uvs,triangles:e.triangles}}function Pt(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function It(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let n of e.attachments.values())for(let o of n.values())t.has(o.path)||t.set(o.path,{w:o.width,h:o.height});return Dt.set(l,t),t}function Yt(l,t){let e=l.skins.get(t);if(!e)return [];let n=new Set;for(let o of e.attachments.values())for(let s of o.values())n.add(s.path);return [...n]}var nt=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let n=(o,s)=>t.colorTargets.find(r=>(r.into??"tint")===s&&r.slotPrefixes.some(i=>o.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(o=>n(o.name,"tint")),this.slotArt=t.data.slots.map(o=>n(o.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";setDrawable(t){let e=new Set(this.rig.partTypes.filter(n=>!this.count(n.id)).map(n=>n.id));this.drawable=t,this.rebuildLists();for(let n of this.rig.partTypes){if(n.auto)continue;let o=this.chosen.get(n.id);(o&&!this.lists.get(n.id).includes(o)||!o&&e.has(n.id))&&this.chosen.set(n.id,this.first(n));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a)};for(let a of this.rig.rules)a.apply(e);let n=this.rig.expressions,o=this.face??this.emotionFace,s=o?n?.faces[o]:void 0;for(let[a,h]of Object.entries(s??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let r=this.speech!=="rest"?n?.speech:void 0,i=r?.visemes[this.speech];r&&i&&t.get(r.type)&&e.exists(i)&&t.set(r.type,i);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}expression(){return this.face}equip(t,e){let n=this.lists.get(t);if(!n)return;let o;if(e===null||e===-1)o=null;else if(typeof e=="number")o=n[Math.max(0,Math.min(n.length-1,e))]??null;else if(n.includes(e))o=e;else return;o===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,o),this.emit({kind:"part",type:t,skin:o}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n>=e-1?-1:n+1):this.equip(t,(n+1)%e);}prev(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n<=-1?e-1:n-1):this.equip(t,(n-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,n=e&&this.rig.expressions?.faces[e]?e:null;n!==this.emotionFace&&(this.emotionFace=n,this.emit({kind:"expression",name:this.face??n}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let n=this.count(e.id);n&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*n));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,o]of this.colors)o&&(e[n]=o);return {v:1,parts:t,colors:e}}applyLook(t){for(let[e,n]of Object.entries(t.parts??{}))n===void 0||this.typeDef(e)?.auto||(this.equip(e,n),n!==null&&this.part(e)===n&&this.hidden.set(e,false));for(let[e,n]of Object.entries(t.colors??{}))n&&this.setColor(e,n);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var U=Math.PI/180,dt=1e-5,ot=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*U,n=(this.rotation+90+this.shearY)*U,o=Math.cos(e)*this.scaleX,s=Math.cos(n)*this.scaleY,r=Math.sin(e)*this.scaleX,i=Math.sin(n)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,p=t.scaleY;this.a=o*h,this.b=s*h,this.c=r*p,this.d=i*p,this.worldX=this.x*h+t.x,this.worldY=this.y*p+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*o+a.b*r,this.b=a.a*s+a.b*i,this.c=a.c*o+a.d*r,this.d=a.c*s+a.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let n=e.applied,o=1/(n.a*n.d-n.b*n.c),s=n.d*o,r=n.b*o,i=n.c*o,c=n.a*o,a=this.worldX-n.worldX,h=this.worldY-n.worldY;this.x=a*s-h*r,this.y=h*c-a*i,this.set5(s*this.a-r*this.c,s*this.b-r*this.d,c*this.c-i*this.a,c*this.d-i*this.b);}set5(t,e,n,o){this.shearX=0;let s=t*t+n*n,r=e*e+o*o;if(s>dt){let i=Math.atan2(n,t)/U;this.rotation=i,this.scaleX=Math.sqrt(s),this.scaleY=Math.sqrt(r),r>dt?(this.shearY=Math.atan2(o,e)/U,t*o-e*n<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(r),this.shearY=0,this.rotation=r>dt?Math.atan2(o,e)/U-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let n=e.applied;n.world===t.updateId&&(n.local===t.updateId&&n.updateLocalTransform(t),n.world=0,n.resetWorld(t));}}},st=class{constructor(t){this.data=t;this.pose=new ot(this),this.applied=new ot(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},ut=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},F=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new st(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new ut(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>St(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let n=this.skins.length-1;n>=0;n--){let o=this.skins[n].attachments.get(t)?.get(e);if(o)return o}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof st?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Ct=new WeakMap;function Xt(l,t){let e=Ct.get(l);if(e)return e;e=new Map;let n=new F(l);n.setupPose(),n.updateWorldTransform();let[o,s]=t.light;for(let r of l.skins.values())for(let[i,c]of r.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(d=>a.path.startsWith(d)))continue;let h=et(n,n.slots[i],a,null),p=Nt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let u=p.a*p.d-p.b*p.c;if(Math.abs(u)<1e-9)continue;let m=(p.d*o-p.b*s)/u,f=(-p.c*o+p.a*s)/u,y=Math.hypot(m,f)||1;e.set(a.path,{x:m/y,y:f/y});}return Ct.set(l,e),e}function Nt(l,t,e,n){let o=t.length/2;if(o<3)return null;let s=0,r=0,i=0,c=0;for(let g=0;g<o;g++)s+=t[g*2]*e,r+=t[g*2+1]*n,i+=l[g*2],c+=l[g*2+1];s/=o,r/=o,i/=o,c/=o;let a=0,h=0,p=0,u=0,m=0,f=0,y=0;for(let g=0;g<o;g++){let v=t[g*2]*e-s,b=t[g*2+1]*n-r,B=l[g*2]-i,$=l[g*2+1]-c;a+=v*v,h+=v*b,p+=b*b,u+=B*v,m+=B*b,f+=$*v,y+=$*b;}let d=a*p-h*h;return Math.abs(d)<1e-9?null:{a:(u*p-m*h)/d,b:(m*a-u*h)/d,c:(f*p-y*h)/d,d:(y*a-f*h)/d}}var J=class{constructor(t,e){this.scene=t;let n=this.rig=e.rig;this.art=e.art,this.skeleton=new F(n.data),this.sizes=It(n.data),this.lights=n.shading?Xt(n.data,n.shading):new Map,this.parts=new nt(n,o=>this.drawsSkin(o)),e.look&&this.parts.applyLook(e.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new tt(this.skeleton,n.data,n.mix),this.animator.setBlink(n.blink??null),this.play(e.animation??n.defaultAnimation,{mix:0}),this.root=t.add.container(e.x??0,e.y??0);for(let o=0;o<this.skeleton.slots.length;o++){let s=new R__default.default.GameObjects.Mesh2D(t,0,0,"__DEFAULT",[],[],true);s.setRenderAsTriangles(true),s.setVisible(false),this.root.add(s),this.slots.push({mesh:s,positions:null,vertices:[],indices:[],path:null,key:null,paint:null,waiting:false});}if(this.setScale(e.scale??1),e.autoUpdate!==false){let o=(s,r)=>this.update(r/1e3);t.events.on(R__default.default.Scenes.Events.UPDATE,o),this.offs.push(()=>t.events.off(R__default.default.Scenes.Events.UPDATE,o));}this.root.once(R__default.default.GameObjects.Events.DESTROY,()=>{for(let o of this.offs.splice(0))o();}),this.update(0);}scene;root;skeleton;animator;parts;slots=[];sizes;lights;skinsDirty=true;overlay=null;flashUntil=0;flashColor=16777215;facing=1;size=1;offs=[];asked=null;rig;art;play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}animation(){return this.asked?.name??null}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,n=>e.isWorn(n)?e.part(n):null)??t}on(t,e){let n=this.animator.on(t,e);return this.offs.push(n),n}setLook(t){this.parts.applyLook(t);}setArt(t){this.art=t;for(let e of this.slots)e.key=e.path=null,e.waiting=false;this.parts.setDrawable(e=>this.drawsSkin(e));}setPosition(t,e){return this.root.setPosition(t,e),this}setScale(t){return this.size=t,this.root.setScale(t*this.facing,t),this}setFacing(t){return this.facing=t,this.setScale(this.size)}setDepth(t){return this.root.setDepth(t),this}setVisible(t){return this.root.setVisible(t),this}setAlpha(t){return this.root.setAlpha(t),this}setOverlay(t){return this.overlay=t,this}flash(t=16777215,e=90){this.flashColor=t,this.flashUntil=this.scene.time.now+e;}worldPoint(t){let e=this.rig.anchors[t]??t,n=this.skeleton.bone(e).applied,o=this.root.getWorldTransformMatrix();return {x:o.tx+o.a*n.worldX+o.c*-n.worldY,y:o.ty+o.b*n.worldX+o.d*-n.worldY}}get displayHeight(){return this.rig.data.height*this.size}destroy(){this.root.destroy();}update(t){let e=this.skeleton,n=this.rig.expressions;if(n&&this.parts.setExpression(n.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let i=this.rig.data.skins.get(r);return i?[i]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),e.slots.forEach((s,r)=>{let i=this.parts.slotColor(r);if(!i)return;let c=Pt(i);s.color.r=(c>>16&255)/255,s.color.g=(c>>8&255)/255,s.color.b=(c&255)/255,s.color.a=1;}),e.updateWorldTransform();let o=this.flashUntil>this.scene.time.now;e.slots.forEach((s,r)=>this.drawSlot(r,o));}drawSlot(t,e){let n=this.slots[t],o=this.skeleton.slots[t],s=o.attachment,r=n.mesh;if(!s||o.color.a<=0){r.setVisible(false);return}let i=this.parts.artColor(t);if((n.path!==s.path||n.paint!==i)&&(n.path=s.path,n.paint=i,n.key=null,n.waiting=false),!n.key&&!n.waiting){let d=this.sizes.get(s.path)??{w:s.width,h:s.height},g=s.path,v=this.art.texture(g,d,()=>{n.path===g&&(n.waiting=false);},{paint:i,light:this.lights.get(g)??null});v?(n.key=v,r.setTexture(v)):n.waiting=true;}if(!n.key){r.setVisible(false);return}let c=et(this.skeleton,o,s,n.positions);n.positions=c.positions;let a=c.uvs.length/2,h=n.vertices;h.length=a*4;for(let d=0;d<a;d++)h[d*4]=c.positions[d*2],h[d*4+1]=-c.positions[d*2+1],h[d*4+2]=c.uvs[d*2],h[d*4+3]=c.uvs[d*2+1];let p=c.triangles,u=n.indices;if(u.length!==p.length/3*4){u.length=0;for(let d=0;d<p.length;d+=3)u.push(p[d],p[d+1],p[d+2],0);}else for(let d=0,g=0;d<p.length;d+=3,g+=4)u[g]=p[d],u[g+1]=p[d+1],u[g+2]=p[d+2];r.vertices=h,r.indices=u;let m=o.color,f=s.color,y=Math.round(m.r*f.r*255)<<16|Math.round(m.g*f.g*255)<<8|Math.round(m.b*f.b*255);this.overlay!==null&&(y=Gt(y,this.overlay)),e?r.setTint(this.flashColor).setTintMode(R__default.default.TintModes.FILL):r.setTint(y).setTintMode(R__default.default.TintModes.MULTIPLY),r.setAlpha(m.a*f.a),r.setVisible(true);}drawsSkin(t){return Yt(this.rig.data,t).every(e=>this.art.has(e))}};function Gt(l,t){let e=n=>Math.round((l>>n&255)*(t>>n&255)/255)<<n;return e(16)|e(8)|e(0)}function Bt(l,t,e=1,n={}){let o=Math.max(1,Math.ceil(t.w*e)),s=Math.max(1,Math.ceil(t.h*e)),r=n.paint??l.paint,i=n.light?Vt(t,n.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${s}" viewBox="0 0 ${t.w} ${t.h}"${r?` color="${r}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var j={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Vt(l,t){let e=Math.max(j.min,Math.min(j.max,Math.min(l.w,l.h)*j.depth)),n=o=>+o.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*.7)}" result="body"/><feOffset in="body" dx="${n(t.x*e)}" dy="${n(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${j.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${n(-t.x*e*.42)}" dy="${n(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${j.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var $t=new WeakMap;function Ut(l,t,e){return `chr:${l}@${t}${e||""}`}function Lt(l,t,e,n,o,s,r={}){let i=e.paint?r.paint??null:null,c=Ut(t,o,i);if(l.exists(c))return c;let a=$t.get(l);a||$t.set(l,a=new Map);let h=a.get(c);if(h)return h.push(s),null;let p=[s];a.set(c,p);let u=new Image,m=()=>{a.delete(c);for(let f of p)f();};return u.onload=()=>{l.exists(c)||l.addImage(c,u),m();},u.onerror=()=>{console.warn(`[character] art ${t} did not render`),m();},u.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(Bt(e,n,o,{paint:i,light:r.light??null})),null}function mt(l,t,e=2){return {has:n=>t.has(n),texture(n,o,s,r){let i=t.get(n);return i?Lt(l,n,i,o,e,s,r):null}}}function Jt(l,t){return new Promise(e=>{let{width:n,height:o}=t;class s extends R__default.default.Scene{create(){let c=t.scale??1,a=mt(this.textures,t.catalog,Math.max(2,Math.ceil(c*1.5))),h=new J(this,{rig:t.rig,art:a,...t.look?{look:t.look}:{},x:n/2,y:Math.round(o*.88),scale:c});e({view:h,game:r,vector:a,destroy:()=>r.destroy(true)});}}let r=new R__default.default.Game({type:R__default.default.WEBGL,parent:l,width:n,height:o,transparent:!t.background,...t.background?{backgroundColor:t.background}:{},scene:s,banner:false,audio:{noAudio:true}});})}
|
|
2
|
-
exports.CharacterView=
|
|
1
|
+
'use strict';var F=require('phaser');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var F__default=/*#__PURE__*/_interopDefault(F);var R=Math.PI/180,ht=1e-5;function St(l,t){return l.type==="ik"?new O(l,t):new pt(l,t)}var dt=l=>l>180?l-360:l<=-180?l+360:l,O=class{constructor(t,e){this.data=t;this.bones=t.bones.map(o=>e.bones[o.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Mt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Mt(l,t,e,o,n){let r=t.bone.parent;if(!r)return;t.modifyLocal(l);let s=r.applied,i=s.a,c=s.b,a=s.c,h=s.d,d=-t.shearX-t.rotation,u=i*h-c*a,f=e-s.worldX,m=o-s.worldY,y=(f*h-m*c)/u-t.x,p=(m*i-f*a)/u-t.y;d+=Math.atan2(p,y)/R,t.scaleX<0&&(d+=180),t.rotation+=dt(d)*n;}function Ot(l,t,e,o,n,r,s){t.modifyLocal(l),e.modifyLocal(l);let i=t.x,c=t.y,a=t.scaleX,h=t.scaleY,d=e.scaleX,u,f,m;a<0?(a=-a,u=180,m=-1):(u=0,m=1),h<0&&(h=-h,m=-m),d<0?(d=-d,f=180):f=0;let y=Math.abs(a-h)<=ht,p,g;y?(p=t.a*e.x+t.b*e.y+t.worldX,g=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,p=t.a*e.x+t.worldX,g=t.c*e.x+t.worldY);let v=t.bone.parent;if(!v)return;let b=v.applied,X=b.a,L=b.b,it=b.c,at=b.d,A=X*at-L*it,H=p-b.worldX,W=g-b.worldY;A=Math.abs(A)<=ht?0:1/A;let gt=(H*at-W*L)*A-i,yt=(W*X-H*it)*A-c,x=Math.sqrt(gt*gt+yt*yt),T=e.bone.data.length*d;if(x<ht){Mt(l,t,o,n,s),e.rotation=0;return}H=o-b.worldX,W=n-b.worldY;let G=(H*at-W*L)*A-i,N=(W*X-H*it)*A-c,K=G*G+N*N,P=0,S=0;if(y){T*=a;let k=(K-x*x-T*T)/(2*x*T);k<-1?(k=-1,S=Math.PI*r):k>1?(k=1,S=0):S=Math.acos(k)*r;let B=x+T*k,D=T*Math.sin(S);P=Math.atan2(N*B-G*D,G*B+N*D);}else {let k=a*T,B=h*T,D=k*k,q=B*B,lt=Math.atan2(N,G),w=q*x*x+D*K-D*q,z=-2*q*x,xt=q-D,kt=z*z-4*xt*w,vt=false;if(kt>=0){let M=Math.sqrt(kt);z<0&&(M=-M),M=-(z+M)*.5;let C=M/xt,$=w/M,I=Math.abs(C)<Math.abs($)?C:$,V=K-I*I;if(V>=0){let Y=Math.sqrt(V)*r;P=lt-Math.atan2(Y,I),S=Math.atan2(Y/h,(I-x)/a),vt=true;}}if(!vt){let M=Math.PI,C=x-k,$=C*C,I=0,V=0,Y=x+k,ct=Y*Y,wt=0;if(w=-k*x/(D-q),w>=-1&&w<=1){w=Math.acos(w);let _=k*Math.cos(w)+x,Z=B*Math.sin(w),Q=_*_+Z*Z;Q<$&&(M=w,$=Q,C=_,I=Z),Q>ct&&(V=w,ct=Q,Y=_,wt=Z);}K<=($+ct)*.5?(P=lt-Math.atan2(I*r,C),S=M*r):(P=lt-Math.atan2(wt*r,Y),S=V*r);}}let bt=Math.atan2(e.y,e.x)*m;P=dt((P-bt)/R+u-t.rotation),S=dt(((S+bt)/R-e.shearX)*m+f-e.rotation),t.rotation+=P*s,e.rotation+=S*s;}var pt=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(o=>e.bones[o.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let o=this.source.applied,n=this.data.offsets;for(let r of this.bones){let s=r.applied;s.modifyWorld(t);for(let i of this.data.properties){let c=Et(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Ft(t,s,a.prop,a.offset+c*a.scale,h);}}}}};function Et(l,t,e,o){let n=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let s=(t.a*t.d-t.b*t.c)*n*r>0?1:-1,i=Math.atan2(t.c/r,t.a/n)/R+s*o.rotate;return i<0&&(i+=360),i}case "x":return (o.x*t.a+o.y*t.b+t.worldX)/n;case "y":return (o.x*t.c+o.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/n,t.c/r)+o.scaleX;case "scaleY":return Math.hypot(t.b/n,t.d/r)+o.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/n)-Math.atan2(t.c/r,t.a/n))/R-90+o.shearY}}function Ft(l,t,e,o,n){let r=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let i=t.a/r,c=t.b/r,a=t.c/s,h=t.d/s,d=o*R-Math.atan2(a,i);d>Math.PI?d-=2*Math.PI:d<-Math.PI&&(d+=2*Math.PI),d*=n;let u=Math.cos(d),f=Math.sin(d);t.a=(u*i-f*a)*r,t.b=(u*c-f*h)*r,t.c=(f*i+u*a)*s,t.d=(f*c+u*h)*s;return}case "x":t.worldX+=(o-t.worldX/r)*n*r;return;case "y":t.worldY+=(o-t.worldY/s)*n*s;return;case "scaleX":{let i=Math.hypot(t.a/r,t.c/s);i!==0&&(i=1+(o-i)*n/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/r,t.d/s);i!==0&&(i=1+(o-i)*n/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/r,c=t.d/s,a=Math.atan2(c,i),h=(o+90)*R;h-=a-Math.atan2(t.c/s,t.a/r),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*n;let d=Math.hypot(i,c);t.b=Math.cos(h)*d*r,t.d=Math.sin(h)*d*s;return}}}var tt=class{constructor(t,e,o=.2){this.skeleton=t;this.data=e;this.defaultMix=o;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let o={bones:new Set(t.bones.map(n=>this.data.bone(n).index)),slots:new Set(t.slots.map(n=>this.data.slot(n).index))};this.blink={source:e,filter:o,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let o=this.data.animations.get(t);if(!o)return false;let n=e.mix??this.defaultMix;return this.previous=this.track&&n>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?n:0,this.track={animation:o,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let o=this.listeners.get(t)??new Set;return o.add(e),this.listeners.set(t,o),()=>o.delete(e)}update(t){let e=[],o=this.track;if(o&&!o.done){let n=o.time;o.time+=Math.max(0,t)*o.speed,this.collect(o,n,o.time,e),!o.loop&&o.time>=o.animation.duration&&(o.time=o.animation.duration,o.done=true,e.push({name:"end",animation:o.animation.name}));}if(this.previous){let n=this.previous;n.time+=Math.max(0,t)*n.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let n of e){for(let r of this.listeners.get(n.name)??[])r(n);for(let r of this.listeners.get("*")??[])r(n);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let o=this.blink;o&&o.at>=0&&o.source.applyOnly(t,o.options.from+o.at,o.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,o,n){let r=t.animation.duration;if(r<=0||o<=e)return;let s=Math.floor(e/r),i=t.loop?Math.floor(o/r):0;for(let c=s;c<=i;c++)for(let a of t.animation.events){let h=c*r+a.time;h>=e&&(h<o||!t.loop&&h<=o)&&n.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,o)=>{let n=e.pose;this.snapshot.set([n.x,n.y,n.rotation,n.scaleX,n.scaleY],o*5);}),t.slots.forEach((e,o)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],o*4)),t.constraints.forEach((e,o)=>{e instanceof O&&(this.ikSnapshot[o]=e.mix);});}blendFromSaved(t){let e=this.skeleton,o=(n,r)=>n+(r-n)*t;e.bones.forEach((n,r)=>{let s=this.snapshot,i=n.pose,c=r*5;i.x=o(s[c],i.x),i.y=o(s[c+1],i.y);let a=i.rotation-s[c+2];a-=Math.round(a/360)*360,i.rotation=s[c+2]+a*t,i.scaleX=o(s[c+3],i.scaleX),i.scaleY=o(s[c+4],i.scaleY);}),e.slots.forEach((n,r)=>{let s=this.slotSnapshot;n.color.r=o(s[r*4],n.color.r),n.color.g=o(s[r*4+1],n.color.g),n.color.b=o(s[r*4+2],n.color.b),n.color.a=o(s[r*4+3],n.color.a);}),e.constraints.forEach((n,r)=>{n instanceof O&&(n.mix=o(this.ikSnapshot[r],n.mix));});}};var Tt=Math.PI/180,Ht=new Float32Array([0,1,0,0,1,0,1,1]),Wt=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function Gt(l){let t=At.get(l);if(t)return t;let e=-l.width/2*l.scaleX,o=-l.height/2*l.scaleY,n=l.width/2*l.scaleX,r=l.height/2*l.scaleY,s=Math.cos(l.rotation*Tt),i=Math.sin(l.rotation*Tt),c=(a,h)=>[a*s-h*i+l.x,a*i+h*s+l.y];return t=Float32Array.from([...c(e,o),...c(e,r),...c(n,r),...c(n,o)]),At.set(l,t),t}function et(l,t,e,o){if(e.type==="region"){let n=o&&o.length===8?o:new Float32Array(8),r=Gt(e),s=t.bone.applied;for(let i=0;i<8;i+=2){let c=r[i],a=r[i+1];n[i]=c*s.a+a*s.b+s.worldX,n[i+1]=c*s.c+a*s.d+s.worldY;}return {positions:n,uvs:Ht,triangles:Wt}}return Nt(l,t,e,o)}function Nt(l,t,e,o){let n=e.vertexCount*2,r=o&&o.length===n?o:new Float32Array(n),s=e.vertices;if(e.weighted){let i=0;for(let c=0;c<n;c+=2){let a=s[i++],h=0,d=0;for(let u=0;u<a;u++,i+=4){let f=l.bones[s[i]].applied,m=s[i+1],y=s[i+2],p=s[i+3];h+=(m*f.a+y*f.b+f.worldX)*p,d+=(m*f.c+y*f.d+f.worldY)*p;}r[c]=h,r[c+1]=d;}}else {let i=t.bone.applied;for(let c=0;c<n;c+=2){let a=s[c],h=s[c+1];r[c]=a*i.a+h*i.b+i.worldX,r[c+1]=a*i.c+h*i.d+i.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}function Pt(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function Ct(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let o of e.attachments.values())for(let n of o.values())t.has(n.path)||t.set(n.path,{w:n.width,h:n.height});return Dt.set(l,t),t}function It(l,t){let e=l.skins.get(t);if(!e)return [];let o=new Set;for(let n of e.attachments.values())for(let r of n.values())o.add(r.path);return [...o]}function Yt(l,t){return !l.skin?.length||l.skin.some(e=>e.toLowerCase()===t.toLowerCase())}var ot=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let o=(n,r)=>t.colorTargets.find(s=>(s.into??"tint")===r&&s.slotPrefixes.some(i=>n.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(n=>o(n.name,"tint")),this.slotArt=t.data.slots.map(n=>o(n.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";body={};raceSaved=new Map;raceGiven=new Map;setDrawable(t){let e=new Set(this.rig.partTypes.filter(o=>!this.count(o.id)).map(o=>o.id));this.drawable=t,this.rebuildLists();for(let o of this.rig.partTypes){if(o.auto)continue;let n=this.chosen.get(o.id);(n&&!this.lists.get(o.id).includes(n)||!n&&e.has(o.id))&&this.chosen.set(o.id,this.first(o));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a),race:()=>this.race(),types:()=>this.rig.partTypes.map(a=>a.id)};for(let a of this.rig.rules)a.apply(e);let o=this.rig.expressions,n=this.face??this.emotionFace,r=n?o?.faces[n]:void 0;for(let[a,h]of Object.entries(r??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let s=this.speech!=="rest"?o?.speech:void 0,i=s?.visemes[this.speech];s&&i&&t.get(s.type)&&e.exists(i)&&t.set(s.type,i);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}bodyLook(){return {...this.body}}race(){return this.rig.races?.get(this.body.race)??null}expression(){return this.face}equip(t,e){let o=this.lists.get(t);if(!o)return;let n;if(e===null||e===-1)n=null;else if(typeof e=="number")n=o[Math.max(0,Math.min(o.length-1,e))]??null;else if(o.includes(e))n=e;else return;n===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,n),this.emit({kind:"part",type:t,skin:n}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o>=e-1?-1:o+1):this.equip(t,(o+1)%e);}prev(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o<=-1?e-1:o-1):this.equip(t,(o-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,o=e&&this.rig.expressions?.faces[e]?e:null;o!==this.emotionFace&&(this.emotionFace=o,this.emit({kind:"expression",name:this.face??o}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}setBody(t){let e=this.race();if(this.body={...t},this.body.race!==e?.id){this.dropRaceColors();let o=new Map(this.colors);this.fitRaceColors(false),this.rememberRaceColors(o);}this.emit({kind:"body",body:this.bodyLook()});}setRace(t){let e={...this.body};t?e.race=t:delete e.race,this.setBody(e);}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let o=this.count(e.id);o&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*o));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,r]of this.colors)r&&(e[n]=r);let o=this.bodyLook();return {v:2,parts:t,colors:e,...Object.keys(o).length?{body:o}:{}}}applyLook(t){let e=this.race(),o=!!t.body&&t.body.race!==e?.id;o&&this.dropRaceColors();let n=new Map(this.colors);for(let[r,s]of Object.entries(t.parts??{}))s===void 0||this.typeDef(r)?.auto||(this.equip(r,s),s!==null&&this.part(r)===s&&this.hidden.set(r,false));for(let[r,s]of Object.entries(t.colors??{}))s&&this.setColor(r,s);t.body&&(this.body={...this.body,...t.body},o&&(this.fitRaceColors(true,t),this.rememberRaceColors(n)),this.emit({kind:"body",body:this.bodyLook()}));}dropRaceColors(){for(let[t,e]of this.raceGiven)this.color(t)?.toLowerCase()===e.toLowerCase()&&this.setColor(t,this.raceSaved.get(t)??null);this.raceGiven.clear(),this.raceSaved.clear();}rememberRaceColors(t){let e=this.race();if(!e)return;let o=new Set(Object.keys(e.colors??{}));e.skin?.length&&o.add(this.rig.skinColor??"Skin");for(let n of o){let r=this.color(n);!r||r===(t.get(n)??null)||(this.raceSaved.set(n,t.get(n)??null),this.raceGiven.set(n,r));}}fitRaceColors(t,e){let o=this.race();if(!o)return;for(let[i,c]of Object.entries(o.colors??{}))(t?e?.colors?.[i]:this.color(i))||this.setColor(i,c);let n=this.rig.skinColor??"Skin",r=this.color(n),s=t?e?.colors?.[n]??r:r;o.skin?.length&&(!s||!Yt(o,s))&&this.setColor(n,o.skin[0]);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear(),this.body={},this.raceSaved.clear(),this.raceGiven.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var U=Math.PI/180,ut=1e-5,nt=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*U,o=(this.rotation+90+this.shearY)*U,n=Math.cos(e)*this.scaleX,r=Math.cos(o)*this.scaleY,s=Math.sin(e)*this.scaleX,i=Math.sin(o)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,d=t.scaleY;this.a=n*h,this.b=r*h,this.c=s*d,this.d=i*d,this.worldX=this.x*h+t.x,this.worldY=this.y*d+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*n+a.b*s,this.b=a.a*r+a.b*i,this.c=a.c*n+a.d*s,this.d=a.c*r+a.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let o=e.applied,n=1/(o.a*o.d-o.b*o.c),r=o.d*n,s=o.b*n,i=o.c*n,c=o.a*n,a=this.worldX-o.worldX,h=this.worldY-o.worldY;this.x=a*r-h*s,this.y=h*c-a*i,this.set5(r*this.a-s*this.c,r*this.b-s*this.d,c*this.c-i*this.a,c*this.d-i*this.b);}set5(t,e,o,n){this.shearX=0;let r=t*t+o*o,s=e*e+n*n;if(r>ut){let i=Math.atan2(o,t)/U;this.rotation=i,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(s),s>ut?(this.shearY=Math.atan2(n,e)/U,t*n-e*o<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(s),this.shearY=0,this.rotation=s>ut?Math.atan2(n,e)/U-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let o=e.applied;o.world===t.updateId&&(o.local===t.updateId&&o.updateLocalTransform(t),o.world=0,o.resetWorld(t));}}},rt=class{constructor(t){this.data=t;this.pose=new nt(this),this.applied=new nt(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},ft=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},E=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new rt(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new ft(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>St(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let o=this.skins.length-1;o>=0;o--){let n=this.skins[o].attachments.get(t)?.get(e);if(n)return n}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof rt?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Rt=new WeakMap;function Xt(l,t){let e=Rt.get(l);if(e)return e;e=new Map;let o=new E(l);o.setupPose(),o.updateWorldTransform();let[n,r]=t.light;for(let s of l.skins.values())for(let[i,c]of s.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(p=>a.path.startsWith(p)))continue;let h=et(o,o.slots[i],a,null),d=qt(h.positions,h.uvs,a.width,a.height);if(!d)continue;let u=d.a*d.d-d.b*d.c;if(Math.abs(u)<1e-9)continue;let f=(d.d*n-d.b*r)/u,m=(-d.c*n+d.a*r)/u,y=Math.hypot(f,m)||1;e.set(a.path,{x:f/y,y:m/y});}return Rt.set(l,e),e}function qt(l,t,e,o){let n=t.length/2;if(n<3)return null;let r=0,s=0,i=0,c=0;for(let g=0;g<n;g++)r+=t[g*2]*e,s+=t[g*2+1]*o,i+=l[g*2],c+=l[g*2+1];r/=n,s/=n,i/=n,c/=n;let a=0,h=0,d=0,u=0,f=0,m=0,y=0;for(let g=0;g<n;g++){let v=t[g*2]*e-r,b=t[g*2+1]*o-s,X=l[g*2]-i,L=l[g*2+1]-c;a+=v*v,h+=v*b,d+=b*b,u+=X*v,f+=X*b,m+=L*v,y+=L*b;}let p=a*d-h*h;return Math.abs(p)<1e-9?null:{a:(u*d-f*h)/p,b:(f*a-u*h)/p,c:(m*d-y*h)/p,d:(y*a-m*h)/p}}var j=class{constructor(t,e){this.scene=t;let o=this.rig=e.rig;this.art=e.art,this.skeleton=new E(o.data),this.sizes=Ct(o.data),this.lights=o.shading?Xt(o.data,o.shading):new Map,this.parts=new ot(o,n=>this.drawsSkin(n)),e.look&&this.parts.applyLook(e.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new tt(this.skeleton,o.data,o.mix),this.animator.setBlink(o.blink??null),this.play(e.animation??o.defaultAnimation,{mix:0}),this.root=t.add.container(e.x??0,e.y??0);for(let n=0;n<this.skeleton.slots.length;n++){let r=new F__default.default.GameObjects.Mesh2D(t,0,0,"__DEFAULT",[],[],true);r.setRenderAsTriangles(true),r.setVisible(false),this.root.add(r),this.slots.push({mesh:r,positions:null,vertices:[],indices:[],path:null,key:null,paint:null,waiting:false});}if(this.setScale(e.scale??1),e.autoUpdate!==false){let n=(r,s)=>this.update(s/1e3);t.events.on(F__default.default.Scenes.Events.UPDATE,n),this.offs.push(()=>t.events.off(F__default.default.Scenes.Events.UPDATE,n));}this.root.once(F__default.default.GameObjects.Events.DESTROY,()=>{for(let n of this.offs.splice(0))n();}),this.update(0);}scene;root;skeleton;animator;parts;slots=[];sizes;lights;skinsDirty=true;overlay=null;flashUntil=0;flashColor=16777215;facing=1;size=1;offs=[];asked=null;rig;art;play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}animation(){return this.asked?.name??null}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,o=>e.isWorn(o)?e.part(o):null)??t}on(t,e){let o=this.animator.on(t,e);return this.offs.push(o),o}setLook(t){this.parts.applyLook(t);}setArt(t){this.art=t;for(let e of this.slots)e.key=e.path=null,e.waiting=false;this.parts.setDrawable(e=>this.drawsSkin(e));}setPosition(t,e){return this.root.setPosition(t,e),this}setScale(t){return this.size=t,this.root.setScale(t*this.facing,t),this}setFacing(t){return this.facing=t,this.setScale(this.size)}setDepth(t){return this.root.setDepth(t),this}setVisible(t){return this.root.setVisible(t),this}setAlpha(t){return this.root.setAlpha(t),this}setOverlay(t){return this.overlay=t,this}flash(t=16777215,e=90){this.flashColor=t,this.flashUntil=this.scene.time.now+e;}worldPoint(t){let e=this.rig.anchors[t]??t,o=this.skeleton.bone(e).applied,n=this.root.getWorldTransformMatrix();return {x:n.tx+n.a*o.worldX+n.c*-o.worldY,y:n.ty+n.b*o.worldX+n.d*-o.worldY}}get displayHeight(){return this.rig.data.height*this.size}destroy(){this.root.destroy();}update(t){let e=this.skeleton,o=this.rig.expressions;if(o&&this.parts.setExpression(o.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(s=>{let i=this.rig.data.skins.get(s);return i?[i]:[]}));let r=this.asked;r&&this.stanceOf(r.name)!==this.animator.current()&&this.animator.play(this.stanceOf(r.name),{...r.options,mix:.15});}this.animator.update(t),e.slots.forEach((r,s)=>{let i=this.parts.slotColor(s);if(!i)return;let c=Pt(i);r.color.r=(c>>16&255)/255,r.color.g=(c>>8&255)/255,r.color.b=(c&255)/255,r.color.a=1;}),e.updateWorldTransform();let n=this.flashUntil>this.scene.time.now;e.slots.forEach((r,s)=>this.drawSlot(s,n));}drawSlot(t,e){let o=this.slots[t],n=this.skeleton.slots[t],r=n.attachment,s=o.mesh;if(!r||n.color.a<=0){s.setVisible(false);return}let i=this.parts.artColor(t);if((o.path!==r.path||o.paint!==i)&&(o.path=r.path,o.paint=i,o.key=null,o.waiting=false),!o.key&&!o.waiting){let p=this.sizes.get(r.path)??{w:r.width,h:r.height},g=r.path,v=this.art.texture(g,p,()=>{o.path===g&&(o.waiting=false);},{paint:i,light:this.lights.get(g)??null});v?(o.key=v,s.setTexture(v)):o.waiting=true;}if(!o.key){s.setVisible(false);return}let c=et(this.skeleton,n,r,o.positions);o.positions=c.positions;let a=c.uvs.length/2,h=o.vertices;h.length=a*4;for(let p=0;p<a;p++)h[p*4]=c.positions[p*2],h[p*4+1]=-c.positions[p*2+1],h[p*4+2]=c.uvs[p*2],h[p*4+3]=c.uvs[p*2+1];let d=c.triangles,u=o.indices;if(u.length!==d.length/3*4){u.length=0;for(let p=0;p<d.length;p+=3)u.push(d[p],d[p+1],d[p+2],0);}else for(let p=0,g=0;p<d.length;p+=3,g+=4)u[g]=d[p],u[g+1]=d[p+1],u[g+2]=d[p+2];s.vertices=h,s.indices=u;let f=n.color,m=r.color,y=Math.round(f.r*m.r*255)<<16|Math.round(f.g*m.g*255)<<8|Math.round(f.b*m.b*255);this.overlay!==null&&(y=Vt(y,this.overlay)),e?s.setTint(this.flashColor).setTintMode(F__default.default.TintModes.FILL):s.setTint(y).setTintMode(F__default.default.TintModes.MULTIPLY),s.setAlpha(f.a*m.a),s.setVisible(true);}drawsSkin(t){return It(this.rig.data,t).every(e=>this.art.has(e))}};function Vt(l,t){let e=o=>Math.round((l>>o&255)*(t>>o&255)/255)<<o;return e(16)|e(8)|e(0)}function Lt(l,t,e=1,o={}){let n=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),s=o.paint??l.paint,i=o.light?Ut(t,o.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${s?` color="${s}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var J={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Ut(l,t){let e=Math.max(J.min,Math.min(J.max,Math.min(l.w,l.h)*J.depth)),o=n=>+n.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*.7)}" result="body"/><feOffset in="body" dx="${o(t.x*e)}" dy="${o(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${J.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${o(-t.x*e*.42)}" dy="${o(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${J.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var Bt=new WeakMap;function jt(l,t,e){return `chr:${l}@${t}${e||""}`}function $t(l,t,e,o,n,r,s={}){let i=e.paint?s.paint??null:null,c=jt(t,n,i);if(l.exists(c))return c;let a=Bt.get(l);a||Bt.set(l,a=new Map);let h=a.get(c);if(h)return h.push(r),null;let d=[r];a.set(c,d);let u=new Image,f=()=>{a.delete(c);for(let m of d)m();};return u.onload=()=>{l.exists(c)||l.addImage(c,u),f();},u.onerror=()=>{console.warn(`[character] art ${t} did not render`),f();},u.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(Lt(e,o,n,{paint:i,light:s.light??null})),null}function mt(l,t,e=2){return {has:o=>t.has(o),texture(o,n,r,s){let i=t.get(o);return i?$t(l,o,i,n,e,r,s):null}}}function Jt(l,t){return new Promise(e=>{let{width:o,height:n}=t,r=Math.min(2,Math.max(1,typeof devicePixelRatio=="number"&&devicePixelRatio||1));class s extends F__default.default.Scene{create(){this.cameras.main.setOrigin(0,0).setZoom(r);let a=t.scale??1,h=mt(this.textures,t.catalog,Math.max(2,Math.ceil(a*r*1.5))),d=new j(this,{rig:t.rig,art:h,...t.look?{look:t.look}:{},x:o/2,y:Math.round(n*.88),scale:a});e({view:d,game:i,vector:h,destroy:()=>i.destroy(true)});}}let i=new F__default.default.Game({type:F__default.default.WEBGL,parent:l,width:Math.ceil(o*r),height:Math.ceil(n*r),scale:{mode:F__default.default.Scale.NONE,zoom:1/r},render:{autoMobileTextures:false},transparent:!t.background,...t.background?{backgroundColor:t.background}:{},scene:s,banner:false,audio:{noAudio:true}});})}
|
|
2
|
+
exports.CharacterView=j;exports.createCharacterStage=Jt;exports.vectorArt=mt;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Phaser from 'phaser';
|
|
2
|
-
import {
|
|
2
|
+
import { i as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CmrzoyJR.cjs';
|
|
3
3
|
import '../../contract-DhZuKNIf.cjs';
|
|
4
4
|
|
|
5
5
|
interface ArtSource {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Phaser from 'phaser';
|
|
2
|
-
import {
|
|
2
|
+
import { i as ArtStyle, A as ArtCatalog, S as Skeleton, a as Animator, P as PartsManager, R as RigDef, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-BpAUMQXw.js';
|
|
3
3
|
import '../../contract-DhZuKNIf.js';
|
|
4
4
|
|
|
5
5
|
interface ArtSource {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{a as CharacterView,c as createCharacterStage,b as vectorArt}from'../../chunk-
|
|
1
|
+
export{a as CharacterView,c as createCharacterStage,b as vectorArt}from'../../chunk-SDZXML7V.js';import'../../chunk-UUX4NEC2.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var y=require('three');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var y__namespace=/*#__PURE__*/_interopNamespace(y);function vt(l){let t=l>>>0;return function(){t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function wt(l,t,e=1,n={}){let o=Math.max(1,Math.ceil(t.w*e)),r=Math.max(1,Math.ceil(t.h*e)),i=n.paint??l.paint,s=n.light?$t(t,n.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${r}" viewBox="0 0 ${t.w} ${t.h}"${i?` color="${i}"`:""}>${s}<g stroke-linejoin="round" stroke-linecap="round"${s?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var V={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function $t(l,t){let e=Math.max(V.min,Math.min(V.max,Math.min(l.w,l.h)*V.depth)),n=o=>+o.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*.7)}" result="body"/><feOffset in="body" dx="${n(t.x*e)}" dy="${n(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${V.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${n(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${n(-t.x*e*.42)}" dy="${n(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${V.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var R=Math.PI/180,lt=1e-5;function Mt(l,t){return l.type==="ik"?new L(l,t):new ht(l,t)}var ct=l=>l>180?l-360:l<=-180?l+360:l,L=class{constructor(t,e){this.data=t;this.bones=t.bones.map(n=>e.bones[n.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?St(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ht(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function St(l,t,e,n,o){let r=t.bone.parent;if(!r)return;t.modifyLocal(l);let i=r.applied,s=i.a,c=i.b,a=i.c,h=i.d,p=-t.shearX-t.rotation,m=s*h-c*a,u=e-i.worldX,f=n-i.worldY,b=(u*h-f*c)/m-t.x,g=(f*s-u*a)/m-t.y;p+=Math.atan2(g,b)/R,t.scaleX<0&&(p+=180),t.rotation+=ct(p)*o;}function Ht(l,t,e,n,o,r,i){t.modifyLocal(l),e.modifyLocal(l);let s=t.x,c=t.y,a=t.scaleX,h=t.scaleY,p=e.scaleX,m,u,f;a<0?(a=-a,m=180,f=-1):(m=0,f=1),h<0&&(h=-h,f=-f),p<0?(p=-p,u=180):u=0;let b=Math.abs(a-h)<=lt,g,d;b?(g=t.a*e.x+t.b*e.y+t.worldX,d=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,g=t.a*e.x+t.worldX,d=t.c*e.x+t.worldY);let k=t.bone.parent;if(!k)return;let x=k.applied,P=x.a,S=x.b,st=x.c,rt=x.d,I=P*rt-S*st,F=g-x.worldX,W=d-x.worldY;I=Math.abs(I)<=lt?0:1/I;let mt=(F*rt-W*S)*I-s,ft=(W*P-F*st)*I-c,v=Math.sqrt(mt*mt+ft*ft),D=e.bone.data.length*p;if(v<lt){St(l,t,n,o,i),e.rotation=0;return}F=n-x.worldX,W=o-x.worldY;let N=(F*rt-W*S)*I-s,q=(W*P-F*st)*I-c,K=N*N+q*q,Y=0,T=0;if(b){D*=a;let w=(K-v*v-D*D)/(2*v*D);w<-1?(w=-1,T=Math.PI*r):w>1?(w=1,T=0):T=Math.acos(w)*r;let $=v+D*w,E=D*Math.sin(T);Y=Math.atan2(q*$-N*E,N*$+q*E);}else {let w=a*D,$=h*D,E=w*w,G=$*$,it=Math.atan2(q,N),M=G*v*v+E*K-E*G,z=-2*G*v,yt=G-E,bt=z*z-4*yt*M,xt=false;if(bt>=0){let A=Math.sqrt(bt);z<0&&(A=-A),A=-(z+A)*.5;let X=A/yt,H=M/A,B=Math.abs(X)<Math.abs(H)?X:H,U=K-B*B;if(U>=0){let C=Math.sqrt(U)*r;Y=it-Math.atan2(C,B),T=Math.atan2(C/h,(B-v)/a),xt=true;}}if(!xt){let A=Math.PI,X=v-w,H=X*X,B=0,U=0,C=v+w,at=C*C,kt=0;if(M=-w*v/(E-G),M>=-1&&M<=1){M=Math.acos(M);let j=w*Math.cos(M)+v,_=$*Math.sin(M),Q=j*j+_*_;Q<H&&(A=M,H=Q,X=j,B=_),Q>at&&(U=M,at=Q,C=j,kt=_);}K<=(H+at)*.5?(Y=it-Math.atan2(B*r,X),T=A*r):(Y=it-Math.atan2(kt*r,C),T=U*r);}}let gt=Math.atan2(e.y,e.x)*f;Y=ct((Y-gt)/R+m-t.rotation),T=ct(((T+gt)/R-e.shearX)*f+u-e.rotation),t.rotation+=Y*i,e.rotation+=T*i;}var ht=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(n=>e.bones[n.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let n=this.source.applied,o=this.data.offsets;for(let r of this.bones){let i=r.applied;i.modifyWorld(t);for(let s of this.data.properties){let c=Lt(t,n,s.prop,o)-s.offset;for(let a of s.to){let h=e[a.prop];h!==0&&Ot(t,i,a.prop,a.offset+c*a.scale,h);}}}}};function Lt(l,t,e,n){let o=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let i=(t.a*t.d-t.b*t.c)*o*r>0?1:-1,s=Math.atan2(t.c/r,t.a/o)/R+i*n.rotate;return s<0&&(s+=360),s}case "x":return (n.x*t.a+n.y*t.b+t.worldX)/o;case "y":return (n.x*t.c+n.y*t.d+t.worldY)/r;case "scaleX":return Math.hypot(t.a/o,t.c/r)+n.scaleX;case "scaleY":return Math.hypot(t.b/o,t.d/r)+n.scaleY;case "shearY":return (Math.atan2(t.d/r,t.b/o)-Math.atan2(t.c/r,t.a/o))/R-90+n.shearY}}function Ot(l,t,e,n,o){let r=l.scaleX,i=l.scaleY;switch(e){case "rotate":{let s=t.a/r,c=t.b/r,a=t.c/i,h=t.d/i,p=n*R-Math.atan2(a,s);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=o;let m=Math.cos(p),u=Math.sin(p);t.a=(m*s-u*a)*r,t.b=(m*c-u*h)*r,t.c=(u*s+m*a)*i,t.d=(u*c+m*h)*i;return}case "x":t.worldX+=(n-t.worldX/r)*o*r;return;case "y":t.worldY+=(n-t.worldY/i)*o*i;return;case "scaleX":{let s=Math.hypot(t.a/r,t.c/i);s!==0&&(s=1+(n-s)*o/s,t.a*=s,t.c*=s);return}case "scaleY":{let s=Math.hypot(t.b/r,t.d/i);s!==0&&(s=1+(n-s)*o/s,t.b*=s,t.d*=s);return}case "shearY":{let s=t.b/r,c=t.d/i,a=Math.atan2(c,s),h=(n+90)*R;h-=a-Math.atan2(t.c/i,t.a/r),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*o;let p=Math.hypot(s,c);t.b=Math.cos(h)*p*r,t.d=Math.sin(h)*p*i;return}}}var Z=class{constructor(t,e,n=.2){this.skeleton=t;this.data=e;this.defaultMix=n;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let n={bones:new Set(t.bones.map(o=>this.data.bone(o).index)),slots:new Set(t.slots.map(o=>this.data.slot(o).index))};this.blink={source:e,filter:n,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let n=this.data.animations.get(t);if(!n)return false;let o=e.mix??this.defaultMix;return this.previous=this.track&&o>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?o:0,this.track={animation:n,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let n=this.listeners.get(t)??new Set;return n.add(e),this.listeners.set(t,n),()=>n.delete(e)}update(t){let e=[],n=this.track;if(n&&!n.done){let o=n.time;n.time+=Math.max(0,t)*n.speed,this.collect(n,o,n.time,e),!n.loop&&n.time>=n.animation.duration&&(n.time=n.animation.duration,n.done=true,e.push({name:"end",animation:n.animation.name}));}if(this.previous){let o=this.previous;o.time+=Math.max(0,t)*o.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let o of e){for(let r of this.listeners.get(o.name)??[])r(o);for(let r of this.listeners.get("*")??[])r(o);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let n=this.blink;n&&n.at>=0&&n.source.applyOnly(t,n.options.from+n.at,n.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,n,o){let r=t.animation.duration;if(r<=0||n<=e)return;let i=Math.floor(e/r),s=t.loop?Math.floor(n/r):0;for(let c=i;c<=s;c++)for(let a of t.animation.events){let h=c*r+a.time;h>=e&&(h<n||!t.loop&&h<=n)&&o.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,n)=>{let o=e.pose;this.snapshot.set([o.x,o.y,o.rotation,o.scaleX,o.scaleY],n*5);}),t.slots.forEach((e,n)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],n*4)),t.constraints.forEach((e,n)=>{e instanceof L&&(this.ikSnapshot[n]=e.mix);});}blendFromSaved(t){let e=this.skeleton,n=(o,r)=>o+(r-o)*t;e.bones.forEach((o,r)=>{let i=this.snapshot,s=o.pose,c=r*5;s.x=n(i[c],s.x),s.y=n(i[c+1],s.y);let a=s.rotation-i[c+2];a-=Math.round(a/360)*360,s.rotation=i[c+2]+a*t,s.scaleX=n(i[c+3],s.scaleX),s.scaleY=n(i[c+4],s.scaleY);}),e.slots.forEach((o,r)=>{let i=this.slotSnapshot;o.color.r=n(i[r*4],o.color.r),o.color.g=n(i[r*4+1],o.color.g),o.color.b=n(i[r*4+2],o.color.b),o.color.a=n(i[r*4+3],o.color.a);}),e.constraints.forEach((o,r)=>{o instanceof L&&(o.mix=n(this.ikSnapshot[r],o.mix));});}};var Tt=Math.PI/180,Ft=new Float32Array([0,1,0,0,1,0,1,1]),Wt=new Uint16Array([0,1,2,2,3,0]),Pt=new WeakMap;function Nt(l){let t=Pt.get(l);if(t)return t;let e=-l.width/2*l.scaleX,n=-l.height/2*l.scaleY,o=l.width/2*l.scaleX,r=l.height/2*l.scaleY,i=Math.cos(l.rotation*Tt),s=Math.sin(l.rotation*Tt),c=(a,h)=>[a*i-h*s+l.x,a*s+h*i+l.y];return t=Float32Array.from([...c(e,n),...c(e,r),...c(o,r),...c(o,n)]),Pt.set(l,t),t}function tt(l,t,e,n){if(e.type==="region"){let o=n&&n.length===8?n:new Float32Array(8),r=Nt(e),i=t.bone.applied;for(let s=0;s<8;s+=2){let c=r[s],a=r[s+1];o[s]=c*i.a+a*i.b+i.worldX,o[s+1]=c*i.c+a*i.d+i.worldY;}return {positions:o,uvs:Ft,triangles:Wt}}return qt(l,t,e,n)}function qt(l,t,e,n){let o=e.vertexCount*2,r=n&&n.length===o?n:new Float32Array(o),i=e.vertices;if(e.weighted){let s=0;for(let c=0;c<o;c+=2){let a=i[s++],h=0,p=0;for(let m=0;m<a;m++,s+=4){let u=l.bones[i[s]].applied,f=i[s+1],b=i[s+2],g=i[s+3];h+=(f*u.a+b*u.b+u.worldX)*g,p+=(f*u.c+b*u.d+u.worldY)*g;}r[c]=h,r[c+1]=p;}}else {let s=t.bone.applied;for(let c=0;c<o;c+=2){let a=i[c],h=i[c+1];r[c]=a*s.a+h*s.b+s.worldX,r[c+1]=a*s.c+h*s.d+s.worldY;}}return {positions:r,uvs:e.uvs,triangles:e.triangles}}function At(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Dt=new WeakMap;function It(l){let t=Dt.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let n of e.attachments.values())for(let o of n.values())t.has(o.path)||t.set(o.path,{w:o.width,h:o.height});return Dt.set(l,t),t}function Yt(l,t){let e=l.skins.get(t);if(!e)return [];let n=new Set;for(let o of e.attachments.values())for(let r of o.values())n.add(r.path);return [...n]}var et=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let n=(o,r)=>t.colorTargets.find(i=>(i.into??"tint")===r&&i.slotPrefixes.some(s=>o.startsWith(s)))?.id??null;this.slotTarget=t.data.slots.map(o=>n(o.name,"tint")),this.slotArt=t.data.slots.map(o=>n(o.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";setDrawable(t){let e=new Set(this.rig.partTypes.filter(n=>!this.count(n.id)).map(n=>n.id));this.drawable=t,this.rebuildLists();for(let n of this.rig.partTypes){if(n.auto)continue;let o=this.chosen.get(n.id);(o&&!this.lists.get(n.id).includes(o)||!o&&e.has(n.id))&&this.chosen.set(n.id,this.first(n));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a)};for(let a of this.rig.rules)a.apply(e);let n=this.rig.expressions,o=this.face??this.emotionFace,r=o?n?.faces[o]:void 0;for(let[a,h]of Object.entries(r??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let i=this.speech!=="rest"?n?.speech:void 0,s=i?.visemes[this.speech];i&&s&&t.get(i.type)&&e.exists(s)&&t.set(i.type,s);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}expression(){return this.face}equip(t,e){let n=this.lists.get(t);if(!n)return;let o;if(e===null||e===-1)o=null;else if(typeof e=="number")o=n[Math.max(0,Math.min(n.length-1,e))]??null;else if(n.includes(e))o=e;else return;o===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,o),this.emit({kind:"part",type:t,skin:o}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n>=e-1?-1:n+1):this.equip(t,(n+1)%e);}prev(t){let e=this.count(t);if(!e)return;let n=this.index(t);this.typeDef(t)?.canHide?this.equip(t,n<=-1?e-1:n-1):this.equip(t,(n-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,n=e&&this.rig.expressions?.faces[e]?e:null;n!==this.emotionFace&&(this.emotionFace=n,this.emit({kind:"expression",name:this.face??n}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let n=this.count(e.id);n&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*n));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,o]of this.colors)o&&(e[n]=o);return {v:1,parts:t,colors:e}}applyLook(t){for(let[e,n]of Object.entries(t.parts??{}))n===void 0||this.typeDef(e)?.auto||(this.equip(e,n),n!==null&&this.part(e)===n&&this.hidden.set(e,false));for(let[e,n]of Object.entries(t.colors??{}))n&&this.setColor(e,n);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var J=Math.PI/180,pt=1e-5,nt=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*J,n=(this.rotation+90+this.shearY)*J,o=Math.cos(e)*this.scaleX,r=Math.cos(n)*this.scaleY,i=Math.sin(e)*this.scaleX,s=Math.sin(n)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,p=t.scaleY;this.a=o*h,this.b=r*h,this.c=i*p,this.d=s*p,this.worldX=this.x*h+t.x,this.worldY=this.y*p+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*o+a.b*i,this.b=a.a*r+a.b*s,this.c=a.c*o+a.d*i,this.d=a.c*r+a.d*s;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let n=e.applied,o=1/(n.a*n.d-n.b*n.c),r=n.d*o,i=n.b*o,s=n.c*o,c=n.a*o,a=this.worldX-n.worldX,h=this.worldY-n.worldY;this.x=a*r-h*i,this.y=h*c-a*s,this.set5(r*this.a-i*this.c,r*this.b-i*this.d,c*this.c-s*this.a,c*this.d-s*this.b);}set5(t,e,n,o){this.shearX=0;let r=t*t+n*n,i=e*e+o*o;if(r>pt){let s=Math.atan2(n,t)/J;this.rotation=s,this.scaleX=Math.sqrt(r),this.scaleY=Math.sqrt(i),i>pt?(this.shearY=Math.atan2(o,e)/J,t*o-e*n<0?(this.scaleY=-this.scaleY,this.shearY+=90-s):this.shearY-=90+s,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(i),this.shearY=0,this.rotation=i>pt?Math.atan2(o,e)/J-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let n=e.applied;n.world===t.updateId&&(n.local===t.updateId&&n.updateLocalTransform(t),n.world=0,n.resetWorld(t));}}},ot=class{constructor(t){this.data=t;this.pose=new nt(this),this.applied=new nt(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},dt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},O=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new ot(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new dt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>Mt(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let n=this.skins.length-1;n>=0;n--){let o=this.skins[n].attachments.get(t)?.get(e);if(o)return o}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof ot?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Et=new WeakMap;function Xt(l,t){let e=Et.get(l);if(e)return e;e=new Map;let n=new O(l);n.setupPose(),n.updateWorldTransform();let[o,r]=t.light;for(let i of l.skins.values())for(let[s,c]of i.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(g=>a.path.startsWith(g)))continue;let h=tt(n,n.slots[s],a,null),p=Gt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let m=p.a*p.d-p.b*p.c;if(Math.abs(m)<1e-9)continue;let u=(p.d*o-p.b*r)/m,f=(-p.c*o+p.a*r)/m,b=Math.hypot(u,f)||1;e.set(a.path,{x:u/b,y:f/b});}return Et.set(l,e),e}function Gt(l,t,e,n){let o=t.length/2;if(o<3)return null;let r=0,i=0,s=0,c=0;for(let d=0;d<o;d++)r+=t[d*2]*e,i+=t[d*2+1]*n,s+=l[d*2],c+=l[d*2+1];r/=o,i/=o,s/=o,c/=o;let a=0,h=0,p=0,m=0,u=0,f=0,b=0;for(let d=0;d<o;d++){let k=t[d*2]*e-r,x=t[d*2+1]*n-i,P=l[d*2]-s,S=l[d*2+1]-c;a+=k*k,h+=k*x,p+=x*x,m+=P*k,u+=P*x,f+=S*k,b+=S*x;}let g=a*p-h*h;return Math.abs(g)<1e-9?null:{a:(m*p-u*h)/g,b:(u*a-m*h)/g,c:(f*p-b*h)/g,d:(b*a-f*h)/g}}var Bt=new Map,Rt=new Map,Ct=new WeakMap,Ut=1;function Vt(l,t,e){let n=Ct.get(l);return n===void 0&&Ct.set(l,n=Ut++),`${n}@${t}${e??""}`}function Jt(l,t,e,n,o){let r=Bt.get(l);return r||(r=new Promise(i=>{let s=new Image;s.onload=()=>{let c=new y__namespace.Texture(s);c.flipY=false,c.colorSpace=y__namespace.SRGBColorSpace,c.needsUpdate=true,Rt.set(l,c),i(c);},s.onerror=()=>i(null),s.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(wt(t,e,n,{paint:o.paint??null,light:o.light??null}));}),Bt.set(l,r),r)}var ut=class{root=new y__namespace.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t){let e=this.rig=t.rig;this.catalog=t.catalog,this.resolution=t.resolution??2,this.unitsPerPx=t.unitsPerPx??.01,this.skeleton=new O(e.data),this.sizes=It(e.data),this.lights=e.shading?Xt(e.data,e.shading):new Map,this.parts=new et(e,n=>Yt(e.data,n).every(o=>this.catalog.has(o))),t.look&&this.parts.applyLook(t.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new Z(this.skeleton,e.data,e.mix),this.animator.setRandom(vt(t.seed??1)),this.animator.setBlink(e.blink??null),this.play(t.animation??e.defaultAnimation,{mix:0});for(let n=0;n<this.skeleton.slots.length;n++){let o=new y__namespace.BufferGeometry,r=new y__namespace.MeshBasicMaterial({transparent:true,depthWrite:false,side:y__namespace.DoubleSide}),i=new y__namespace.Mesh(o,r);i.renderOrder=n,i.visible=false,i.frustumCulled=false,this.root.add(i),this.slots.push({mesh:i,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let n=this.animator.on(t,e);return this.offs.push(n),n}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,n)=>e.mesh.renderOrder=t+n),this}worldPoint(t,e=new y__namespace.Vector3){let n=this.rig.anchors[t]??t,o=this.skeleton.bone(n).applied;return e.set(o.worldX*this.unitsPerPx,o.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,n=this.rig.expressions;if(n&&this.parts.setExpression(n.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let i=this.rig.data.skins.get(r);return i?[i]:[]}));let o=this.asked;o&&this.stanceOf(o.name)!==this.animator.current()&&this.animator.play(this.stanceOf(o.name),{...o.options,mix:.15});}this.animator.update(t),e.slots.forEach((o,r)=>{let i=this.parts.slotColor(r);if(!i)return;let s=At(i);o.color.r=(s>>16&255)/255,o.color.g=(s>>8&255)/255,o.color.b=(s&255)/255,o.color.a=1;}),e.updateWorldTransform();for(let o=0;o<e.slots.length;o++)this.drawSlot(o);}drawSlot(t){let e=this.slots[t],n=this.skeleton.slots[t],o=n.attachment,r=e.mesh;if(!o||n.color.a*o.color.a<=0){r.visible=false;return}let i=this.parts.artColor(t);if((e.path!==o.path||e.paint!==i)&&(e.path=o.path,e.paint=i,e.key=null),!e.key){let d=this.catalog.get(o.path);if(!d){r.visible=false;return}let k=d.paint?i:null,x=Vt(d,this.resolution,k),P=Rt.get(x);if(!P){let S=Jt(x,d,this.sizes.get(o.path)??{w:o.width,h:o.height},this.resolution,{paint:k,light:this.lights.get(o.path)??null});this.pending.add(S),S.then(()=>this.pending.delete(S)),r.visible=false;return}e.key=x,r.material.map=P,r.material.needsUpdate=true;}let s=tt(this.skeleton,n,o,e.positions);e.positions=s.positions;let c=r.geometry,a=s.uvs.length/2,h=c.getAttribute("position");(!h||h.count!==a)&&(h=new y__namespace.BufferAttribute(new Float32Array(a*3),3),c.setAttribute("position",h),c.setAttribute("uv",new y__namespace.BufferAttribute(new Float32Array(a*2),2)));let p=h.array,m=c.getAttribute("uv").array;for(let d=0;d<a;d++)p[d*3]=s.positions[d*2]*this.unitsPerPx,p[d*3+1]=s.positions[d*2+1]*this.unitsPerPx,p[d*3+2]=0,m[d*2]=s.uvs[d*2],m[d*2+1]=s.uvs[d*2+1];h.needsUpdate=true,c.getAttribute("uv").needsUpdate=true;let u=s.triangles,f=c.getIndex();if(!f||f.count!==u.length)c.setIndex(Array.from(u));else {let d=f.array;for(let k=0;k<u.length;k++)d[k]=u[k];f.needsUpdate=true;}let b=n.color,g=o.color;r.material.color.setRGB(b.r*g.r,b.g*g.g,b.b*g.b,y__namespace.SRGBColorSpace),r.material.opacity=b.a*g.a,r.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,n=>e.isWorn(n)?e.part(n):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};
|
|
1
|
+
'use strict';var y=require('three');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var y__namespace=/*#__PURE__*/_interopNamespace(y);function wt(l){let t=l>>>0;return function(){t|=0,t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}function vt(l,t,e=1,o={}){let n=Math.max(1,Math.ceil(t.w*e)),s=Math.max(1,Math.ceil(t.h*e)),r=o.paint??l.paint,i=o.light?Lt(t,o.light):"";return `<svg xmlns="http://www.w3.org/2000/svg" width="${n}" height="${s}" viewBox="0 0 ${t.w} ${t.h}"${r?` color="${r}"`:""}>${i}<g stroke-linejoin="round" stroke-linecap="round"${i?' filter="url(#cel)"':""}>${l.svg}</g></svg>`}var U={depth:.18,min:2.6,max:11,dark:.3,shine:.36};function Lt(l,t){let e=Math.max(U.min,Math.min(U.max,Math.min(l.w,l.h)*U.depth)),o=n=>+n.toFixed(2);return `<defs><filter id="cel" filterUnits="userSpaceOnUse" x="0" y="0" width="${l.w}" height="${l.h}" color-interpolation-filters="sRGB"><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*.7)}" result="body"/><feOffset in="body" dx="${o(t.x*e)}" dy="${o(t.y*e)}" result="moved"/><feComposite in="body" in2="moved" operator="out" result="far"/><feFlood flood-color="#000000" flood-opacity="${U.dark}"/><feComposite in2="far" operator="in" result="dark"/><feMorphology in="SourceAlpha" operator="erode" radius="${o(3.6*1.05)}" result="inner"/><feOffset in="inner" dx="${o(-t.x*e*.42)}" dy="${o(-t.y*e*.42)}" result="back"/><feComposite in="inner" in2="back" operator="out" result="near"/><feFlood flood-color="#ffffff" flood-opacity="${U.shine}"/><feComposite in2="near" operator="in" result="shine"/><feMerge><feMergeNode in="SourceGraphic"/><feMergeNode in="dark"/><feMergeNode in="shine"/></feMerge></filter></defs>`}var X=Math.PI/180,lt=1e-5;function St(l,t){return l.type==="ik"?new O(l,t):new ht(l,t)}var ct=l=>l>180?l-360:l<=-180?l+360:l,O=class{constructor(t,e){this.data=t;this.bones=t.bones.map(o=>e.bones[o.index]),this.target=e.bones[t.target.index],this.mix=t.mix,this.bendDirection=t.bendDirection;}data;mix;bendDirection;bones;target;setupPose(){this.mix=this.data.mix,this.bendDirection=this.data.bendDirection;}sort(t){t.sortBone(this.target);let e=this.bones[0];t.sortBone(e),t.pushConstraint(this),e.sorted=false,t.sortReset(e.children);}update(t){if(this.mix===0)return;let e=this.target.applied;this.bones.length===1?Mt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ot(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Mt(l,t,e,o,n){let s=t.bone.parent;if(!s)return;t.modifyLocal(l);let r=s.applied,i=r.a,c=r.b,a=r.c,h=r.d,d=-t.shearX-t.rotation,f=i*h-c*a,u=e-r.worldX,m=o-r.worldY,b=(u*h-m*c)/f-t.x,g=(m*i-u*a)/f-t.y;d+=Math.atan2(g,b)/X,t.scaleX<0&&(d+=180),t.rotation+=ct(d)*n;}function Ot(l,t,e,o,n,s,r){t.modifyLocal(l),e.modifyLocal(l);let i=t.x,c=t.y,a=t.scaleX,h=t.scaleY,d=e.scaleX,f,u,m;a<0?(a=-a,f=180,m=-1):(f=0,m=1),h<0&&(h=-h,m=-m),d<0?(d=-d,u=180):u=0;let b=Math.abs(a-h)<=lt,g,p;b?(g=t.a*e.x+t.b*e.y+t.worldX,p=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,g=t.a*e.x+t.worldX,p=t.c*e.x+t.worldY);let k=t.bone.parent;if(!k)return;let x=k.applied,P=x.a,M=x.b,st=x.c,rt=x.d,D=P*rt-M*st,F=g-x.worldX,W=p-x.worldY;D=Math.abs(D)<=lt?0:1/D;let ft=(F*rt-W*M)*D-i,mt=(W*P-F*st)*D-c,w=Math.sqrt(ft*ft+mt*mt),I=e.bone.data.length*d;if(w<lt){Mt(l,t,o,n,r),e.rotation=0;return}F=o-x.worldX,W=n-x.worldY;let G=(F*rt-W*M)*D-i,N=(W*P-F*st)*D-c,j=G*G+N*N,R=0,T=0;if(b){I*=a;let v=(j-w*w-I*I)/(2*w*I);v<-1?(v=-1,T=Math.PI*s):v>1?(v=1,T=0):T=Math.acos(v)*s;let $=w+I*v,C=I*Math.sin(T);R=Math.atan2(N*$-G*C,G*$+N*C);}else {let v=a*I,$=h*I,C=v*v,q=$*$,it=Math.atan2(N,G),S=q*w*w+C*j-C*q,K=-2*q*w,yt=q-C,bt=K*K-4*yt*S,xt=false;if(bt>=0){let A=Math.sqrt(bt);K<0&&(A=-A),A=-(K+A)*.5;let E=A/yt,L=S/A,Y=Math.abs(E)<Math.abs(L)?E:L,V=j-Y*Y;if(V>=0){let B=Math.sqrt(V)*s;R=it-Math.atan2(B,Y),T=Math.atan2(B/h,(Y-w)/a),xt=true;}}if(!xt){let A=Math.PI,E=w-v,L=E*E,Y=0,V=0,B=w+v,at=B*B,kt=0;if(S=-v*w/(C-q),S>=-1&&S<=1){S=Math.acos(S);let z=v*Math.cos(S)+w,_=$*Math.sin(S),Q=z*z+_*_;Q<L&&(A=S,L=Q,E=z,Y=_),Q>at&&(V=S,at=Q,B=z,kt=_);}j<=(L+at)*.5?(R=it-Math.atan2(Y*s,E),T=A*s):(R=it-Math.atan2(kt*s,B),T=V*s);}}let gt=Math.atan2(e.y,e.x)*m;R=ct((R-gt)/X+f-t.rotation),T=ct(((T+gt)/X-e.shearX)*m+u-e.rotation),t.rotation+=R*r,e.rotation+=T*r;}var ht=class{constructor(t,e){this.data=t;this.source=e.bones[t.source.index],this.bones=t.bones.map(o=>e.bones[o.index]),this.mix={...t.mix};}data;mix;source;bones;setupPose(){Object.assign(this.mix,this.data.mix);}sort(t){t.sortBone(this.source);for(let e of this.bones)t.sortBone(e);t.pushConstraint(this);for(let e of this.bones)t.sortReset(e.children);for(let e of this.bones)e.sorted=true;}update(t){let e=this.mix;if(!e.rotate&&!e.x&&!e.y&&!e.scaleX&&!e.scaleY&&!e.shearY)return;let o=this.source.applied,n=this.data.offsets;for(let s of this.bones){let r=s.applied;r.modifyWorld(t);for(let i of this.data.properties){let c=Ht(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Ft(t,r,a.prop,a.offset+c*a.scale,h);}}}}};function Ht(l,t,e,o){let n=l.scaleX,s=l.scaleY;switch(e){case "rotate":{let r=(t.a*t.d-t.b*t.c)*n*s>0?1:-1,i=Math.atan2(t.c/s,t.a/n)/X+r*o.rotate;return i<0&&(i+=360),i}case "x":return (o.x*t.a+o.y*t.b+t.worldX)/n;case "y":return (o.x*t.c+o.y*t.d+t.worldY)/s;case "scaleX":return Math.hypot(t.a/n,t.c/s)+o.scaleX;case "scaleY":return Math.hypot(t.b/n,t.d/s)+o.scaleY;case "shearY":return (Math.atan2(t.d/s,t.b/n)-Math.atan2(t.c/s,t.a/n))/X-90+o.shearY}}function Ft(l,t,e,o,n){let s=l.scaleX,r=l.scaleY;switch(e){case "rotate":{let i=t.a/s,c=t.b/s,a=t.c/r,h=t.d/r,d=o*X-Math.atan2(a,i);d>Math.PI?d-=2*Math.PI:d<-Math.PI&&(d+=2*Math.PI),d*=n;let f=Math.cos(d),u=Math.sin(d);t.a=(f*i-u*a)*s,t.b=(f*c-u*h)*s,t.c=(u*i+f*a)*r,t.d=(u*c+f*h)*r;return}case "x":t.worldX+=(o-t.worldX/s)*n*s;return;case "y":t.worldY+=(o-t.worldY/r)*n*r;return;case "scaleX":{let i=Math.hypot(t.a/s,t.c/r);i!==0&&(i=1+(o-i)*n/i,t.a*=i,t.c*=i);return}case "scaleY":{let i=Math.hypot(t.b/s,t.d/r);i!==0&&(i=1+(o-i)*n/i,t.b*=i,t.d*=i);return}case "shearY":{let i=t.b/s,c=t.d/r,a=Math.atan2(c,i),h=(o+90)*X;h-=a-Math.atan2(t.c/r,t.a/s),h>Math.PI?h-=2*Math.PI:h<-Math.PI&&(h+=2*Math.PI),h=a+h*n;let d=Math.hypot(i,c);t.b=Math.cos(h)*d*s,t.d=Math.sin(h)*d*r;return}}}var Z=class{constructor(t,e,o=.2){this.skeleton=t;this.data=e;this.defaultMix=o;this.snapshot=new Float32Array(t.bones.length*5),this.slotSnapshot=new Float32Array(t.slots.length*4),this.ikSnapshot=new Float32Array(t.constraints.length);}skeleton;data;defaultMix;track=null;previous=null;mixTime=0;mixDuration=0;listeners=new Map;snapshot;slotSnapshot;ikSnapshot;blink=null;setBlink(t){let e=t?this.data.animations.get(t.animation):void 0;if(!t||!e){this.blink=null;return}let o={bones:new Set(t.bones.map(n=>this.data.bone(n).index)),slots:new Set(t.slots.map(n=>this.data.slot(n).index))};this.blink={source:e,filter:o,options:t,wait:this.nextBlink(t),at:-1};}blinkNow(){this.blink&&(this.blink.at=0);}blinking(){return (this.blink?.at??-1)>=0}setRandom(t){this.random=t;}random=Math.random;nextBlink(t){return t.every[0]+this.random()*(t.every[1]-t.every[0])}names(){return [...this.data.animations.keys()]}has(t){return this.data.animations.has(t)}play(t,e={}){let o=this.data.animations.get(t);if(!o)return false;let n=e.mix??this.defaultMix;return this.previous=this.track&&n>0?this.track:null,this.mixTime=0,this.mixDuration=this.previous?n:0,this.track={animation:o,time:Math.max(0,e.from??0),speed:e.speed??1,loop:e.loop??true,done:false},true}current(){return this.track?.animation.name??null}time(){return this.track?this.local(this.track):0}duration(){return this.track?.animation.duration??0}finished(){return this.track?.done??false}setSpeed(t){this.track&&(this.track.speed=t);}on(t,e){let o=this.listeners.get(t)??new Set;return o.add(e),this.listeners.set(t,o),()=>o.delete(e)}update(t){let e=[],o=this.track;if(o&&!o.done){let n=o.time;o.time+=Math.max(0,t)*o.speed,this.collect(o,n,o.time,e),!o.loop&&o.time>=o.animation.duration&&(o.time=o.animation.duration,o.done=true,e.push({name:"end",animation:o.animation.name}));}if(this.previous){let n=this.previous;n.time+=Math.max(0,t)*n.speed,this.mixTime+=Math.max(0,t),this.mixTime>=this.mixDuration&&(this.previous=null);}this.advanceBlink(Math.max(0,t)),this.pose();for(let n of e){for(let s of this.listeners.get(n.name)??[])s(n);for(let s of this.listeners.get("*")??[])s(n);}}pose(){let t=this.skeleton,e=this.previous;e&&this.mixDuration>0&&(t.setupPose(),e.animation.apply(t,this.local(e)),this.save()),t.setupPose(),this.track&&this.track.animation.apply(t,this.local(this.track)),e&&this.mixDuration>0&&this.blendFromSaved(Math.min(1,this.mixTime/this.mixDuration));let o=this.blink;o&&o.at>=0&&o.source.applyOnly(t,o.options.from+o.at,o.filter),t.resolveAttachments();}advanceBlink(t){let e=this.blink;if(e){if(this.track?.animation.touches(e.filter)){e.at=-1;return}if(e.at>=0){e.at+=t,e.at>=e.options.to-e.options.from&&(e.at=-1,e.wait=this.nextBlink(e.options));return}e.wait-=t,e.wait<=0&&(e.at=0);}}local(t){let e=t.animation.duration;return e<=0?0:t.loop?t.time%e:Math.min(t.time,e)}collect(t,e,o,n){let s=t.animation.duration;if(s<=0||o<=e)return;let r=Math.floor(e/s),i=t.loop?Math.floor(o/s):0;for(let c=r;c<=i;c++)for(let a of t.animation.events){let h=c*s+a.time;h>=e&&(h<o||!t.loop&&h<=o)&&n.push({name:a.name,animation:t.animation.name});}}save(){let t=this.skeleton;t.bones.forEach((e,o)=>{let n=e.pose;this.snapshot.set([n.x,n.y,n.rotation,n.scaleX,n.scaleY],o*5);}),t.slots.forEach((e,o)=>this.slotSnapshot.set([e.color.r,e.color.g,e.color.b,e.color.a],o*4)),t.constraints.forEach((e,o)=>{e instanceof O&&(this.ikSnapshot[o]=e.mix);});}blendFromSaved(t){let e=this.skeleton,o=(n,s)=>n+(s-n)*t;e.bones.forEach((n,s)=>{let r=this.snapshot,i=n.pose,c=s*5;i.x=o(r[c],i.x),i.y=o(r[c+1],i.y);let a=i.rotation-r[c+2];a-=Math.round(a/360)*360,i.rotation=r[c+2]+a*t,i.scaleX=o(r[c+3],i.scaleX),i.scaleY=o(r[c+4],i.scaleY);}),e.slots.forEach((n,s)=>{let r=this.slotSnapshot;n.color.r=o(r[s*4],n.color.r),n.color.g=o(r[s*4+1],n.color.g),n.color.b=o(r[s*4+2],n.color.b),n.color.a=o(r[s*4+3],n.color.a);}),e.constraints.forEach((n,s)=>{n instanceof O&&(n.mix=o(this.ikSnapshot[s],n.mix));});}};var Tt=Math.PI/180,Wt=new Float32Array([0,1,0,0,1,0,1,1]),Gt=new Uint16Array([0,1,2,2,3,0]),Pt=new WeakMap;function Nt(l){let t=Pt.get(l);if(t)return t;let e=-l.width/2*l.scaleX,o=-l.height/2*l.scaleY,n=l.width/2*l.scaleX,s=l.height/2*l.scaleY,r=Math.cos(l.rotation*Tt),i=Math.sin(l.rotation*Tt),c=(a,h)=>[a*r-h*i+l.x,a*i+h*r+l.y];return t=Float32Array.from([...c(e,o),...c(e,s),...c(n,s),...c(n,o)]),Pt.set(l,t),t}function tt(l,t,e,o){if(e.type==="region"){let n=o&&o.length===8?o:new Float32Array(8),s=Nt(e),r=t.bone.applied;for(let i=0;i<8;i+=2){let c=s[i],a=s[i+1];n[i]=c*r.a+a*r.b+r.worldX,n[i+1]=c*r.c+a*r.d+r.worldY;}return {positions:n,uvs:Wt,triangles:Gt}}return qt(l,t,e,o)}function qt(l,t,e,o){let n=e.vertexCount*2,s=o&&o.length===n?o:new Float32Array(n),r=e.vertices;if(e.weighted){let i=0;for(let c=0;c<n;c+=2){let a=r[i++],h=0,d=0;for(let f=0;f<a;f++,i+=4){let u=l.bones[r[i]].applied,m=r[i+1],b=r[i+2],g=r[i+3];h+=(m*u.a+b*u.b+u.worldX)*g,d+=(m*u.c+b*u.d+u.worldY)*g;}s[c]=h,s[c+1]=d;}}else {let i=t.bone.applied;for(let c=0;c<n;c+=2){let a=r[c],h=r[c+1];s[c]=a*i.a+h*i.b+i.worldX,s[c+1]=a*i.c+h*i.d+i.worldY;}}return {positions:s,uvs:e.uvs,triangles:e.triangles}}function At(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var It=new WeakMap;function Dt(l){let t=It.get(l);if(t)return t;t=new Map;for(let e of l.skins.values())for(let o of e.attachments.values())for(let n of o.values())t.has(n.path)||t.set(n.path,{w:n.width,h:n.height});return It.set(l,t),t}function Rt(l,t){let e=l.skins.get(t);if(!e)return [];let o=new Set;for(let n of e.attachments.values())for(let s of n.values())o.add(s.path);return [...o]}function Ct(l,t){return !l.skin?.length||l.skin.some(e=>e.toLowerCase()===t.toLowerCase())}var et=class{constructor(t,e=()=>true){this.rig=t;this.drawable=e;let o=(n,s)=>t.colorTargets.find(r=>(r.into??"tint")===s&&r.slotPrefixes.some(i=>n.startsWith(i)))?.id??null;this.slotTarget=t.data.slots.map(n=>o(n.name,"tint")),this.slotArt=t.data.slots.map(n=>o(n.name,"art")),this.rebuildLists(),this.init();}rig;drawable;chosen=new Map;hidden=new Map;colors=new Map;lists=new Map;listeners=new Set;slotTarget;slotArt;face=null;emotionFace=null;speech="rest";body={};raceSaved=new Map;raceGiven=new Map;setDrawable(t){let e=new Set(this.rig.partTypes.filter(o=>!this.count(o.id)).map(o=>o.id));this.drawable=t,this.rebuildLists();for(let o of this.rig.partTypes){if(o.auto)continue;let n=this.chosen.get(o.id);(n&&!this.lists.get(o.id).includes(n)||!n&&e.has(o.id))&&this.chosen.set(o.id,this.first(o));}this.emit({kind:"part",type:"*",skin:null});}on(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let e of [...this.listeners])e(t);}typeDef(t){return this.rig.partTypes.find(e=>e.id===t)}list(t){return this.lists.get(t)??[]}count(t){return this.list(t).length}part(t){return this.chosen.get(t)??null}index(t){let e=this.part(t);return e?this.list(t).indexOf(e):-1}isHidden(t){return this.hidden.get(t)??false}isWorn(t){return this.part(t)!==null&&!this.isHidden(t)}color(t){return this.colors.get(t)??null}wornSkins(){let t=new Map;for(let a of this.rig.partTypes)t.set(a.id,!a.auto&&this.isWorn(a.id)?this.part(a.id):null);let e={worn:a=>t.get(a)??null,setWorn:(a,h)=>t.set(a,h),exists:a=>this.rig.data.skins.has(a)&&this.drawable(a),race:()=>this.race(),types:()=>this.rig.partTypes.map(a=>a.id)};for(let a of this.rig.rules)a.apply(e);let o=this.rig.expressions,n=this.face??this.emotionFace,s=n?o?.faces[n]:void 0;for(let[a,h]of Object.entries(s??{}))t.get(a)&&e.exists(h)&&t.set(a,h);let r=this.speech!=="rest"?o?.speech:void 0,i=r?.visemes[this.speech];r&&i&&t.get(r.type)&&e.exists(i)&&t.set(r.type,i);let c=[];for(let a of this.rig.partTypes){let h=t.get(a.id);h&&c.push(h);}return c}slotColor(t){let e=this.slotTarget[t];return e?this.color(e):null}artColor(t){let e=this.slotArt[t];return e?this.color(e):null}bodyLook(){return {...this.body}}race(){return this.rig.races?.get(this.body.race)??null}expression(){return this.face}equip(t,e){let o=this.lists.get(t);if(!o)return;let n;if(e===null||e===-1)n=null;else if(typeof e=="number")n=o[Math.max(0,Math.min(o.length-1,e))]??null;else if(o.includes(e))n=e;else return;n===null&&!this.typeDef(t)?.canHide||(this.chosen.set(t,n),this.emit({kind:"part",type:t,skin:n}));}unequip(t){this.equip(t,null);}setHidden(t,e){this.typeDef(t)?.canHide&&(this.hidden.set(t,e),this.emit({kind:"hidden",type:t,hidden:e}));}next(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o>=e-1?-1:o+1):this.equip(t,(o+1)%e);}prev(t){let e=this.count(t);if(!e)return;let o=this.index(t);this.typeDef(t)?.canHide?this.equip(t,o<=-1?e-1:o-1):this.equip(t,(o-1+e)%e);}setColor(t,e){this.colors.set(t,e),this.emit({kind:"color",target:t,color:e});}setExpression(t){let e=t&&this.rig.expressions?.faces[t]?t:null;e!==this.face&&(this.face=e,this.emit({kind:"expression",name:e}));}setEmotion(t){let e=this.rig.expressions?.emotions?.[t]??null,o=e&&this.rig.expressions?.faces[e]?e:null;o!==this.emotionFace&&(this.emotionFace=o,this.emit({kind:"expression",name:this.face??o}));}setSpeech(t){t!==this.speech&&(this.speech=t,this.emit({kind:"speech",viseme:t}));}setBody(t){let e=this.race();if(this.body={...t},this.body.race!==e?.id){this.dropRaceColors();let o=new Map(this.colors);this.fitRaceColors(false),this.rememberRaceColors(o);}this.emit({kind:"body",body:this.bodyLook()});}setRace(t){let e={...this.body};t?e.race=t:delete e.race,this.setBody(e);}randomize(t=Math.random){for(let e of this.rig.partTypes){if(e.auto)continue;let o=this.count(e.id);o&&this.equip(e.id,e.canHide&&t()<.3?-1:Math.floor(t()*o));}}reset(){this.init();for(let t of this.rig.partTypes)this.emit({kind:"part",type:t.id,skin:this.part(t.id)});}toLook(){let t={};for(let n of this.rig.partTypes)n.auto||(t[n.id]=this.isWorn(n.id)?this.part(n.id):null);let e={};for(let[n,s]of this.colors)s&&(e[n]=s);let o=this.bodyLook();return {v:2,parts:t,colors:e,...Object.keys(o).length?{body:o}:{}}}applyLook(t){let e=this.race(),o=!!t.body&&t.body.race!==e?.id;o&&this.dropRaceColors();let n=new Map(this.colors);for(let[s,r]of Object.entries(t.parts??{}))r===void 0||this.typeDef(s)?.auto||(this.equip(s,r),r!==null&&this.part(s)===r&&this.hidden.set(s,false));for(let[s,r]of Object.entries(t.colors??{}))r&&this.setColor(s,r);t.body&&(this.body={...this.body,...t.body},o&&(this.fitRaceColors(true,t),this.rememberRaceColors(n)),this.emit({kind:"body",body:this.bodyLook()}));}dropRaceColors(){for(let[t,e]of this.raceGiven)this.color(t)?.toLowerCase()===e.toLowerCase()&&this.setColor(t,this.raceSaved.get(t)??null);this.raceGiven.clear(),this.raceSaved.clear();}rememberRaceColors(t){let e=this.race();if(!e)return;let o=new Set(Object.keys(e.colors??{}));e.skin?.length&&o.add(this.rig.skinColor??"Skin");for(let n of o){let s=this.color(n);!s||s===(t.get(n)??null)||(this.raceSaved.set(n,t.get(n)??null),this.raceGiven.set(n,s));}}fitRaceColors(t,e){let o=this.race();if(!o)return;for(let[i,c]of Object.entries(o.colors??{}))(t?e?.colors?.[i]:this.color(i))||this.setColor(i,c);let n=this.rig.skinColor??"Skin",s=this.color(n),r=t?e?.colors?.[n]??s:s;o.skin?.length&&(!r||!Ct(o,r))&&this.setColor(n,o.skin[0]);}rebuildLists(){for(let t of this.rig.partTypes)this.lists.set(t.id,this.rig.data.skinOrder.filter(e=>e.startsWith(t.skinPrefix)&&this.drawable(e)));}first(t){return this.lists.get(t.id)?.[0]??null}init(){this.chosen.clear(),this.hidden.clear(),this.colors.clear(),this.body={},this.raceSaved.clear(),this.raceGiven.clear();for(let t of this.rig.partTypes)this.chosen.set(t.id,t.auto?null:this.first(t));}};var J=Math.PI/180,dt=1e-5,ot=class{constructor(t){this.bone=t;}bone;x=0;y=0;rotation=0;scaleX=1;scaleY=1;shearX=0;shearY=0;a=1;b=0;c=0;d=1;worldX=0;worldY=0;world=0;local=0;copyLocal(t){this.x=t.x,this.y=t.y,this.rotation=t.rotation,this.scaleX=t.scaleX,this.scaleY=t.scaleY,this.shearX=t.shearX,this.shearY=t.shearY;}update(t){this.world!==t.updateId&&this.updateWorldTransform(t);}updateWorldTransform(t){this.local===t.updateId?this.updateLocalTransform(t):this.world=t.updateId;let e=(this.rotation+this.shearX)*J,o=(this.rotation+90+this.shearY)*J,n=Math.cos(e)*this.scaleX,s=Math.cos(o)*this.scaleY,r=Math.sin(e)*this.scaleX,i=Math.sin(o)*this.scaleY,c=this.bone.parent;if(!c){let h=t.scaleX,d=t.scaleY;this.a=n*h,this.b=s*h,this.c=r*d,this.d=i*d,this.worldX=this.x*h+t.x,this.worldY=this.y*d+t.y;return}let a=c.applied;this.worldX=a.a*this.x+a.b*this.y+a.worldX,this.worldY=a.c*this.x+a.d*this.y+a.worldY,this.a=a.a*n+a.b*r,this.b=a.a*s+a.b*i,this.c=a.c*n+a.d*r,this.d=a.c*s+a.d*i;}updateLocalTransform(t){this.local=0,this.world=t.updateId;let e=this.bone.parent;if(!e){this.x=(this.worldX-t.x)/t.scaleX,this.y=(this.worldY-t.y)/t.scaleY,this.set5(this.a/t.scaleX,this.b/t.scaleX,this.c/t.scaleY,this.d/t.scaleY);return}let o=e.applied,n=1/(o.a*o.d-o.b*o.c),s=o.d*n,r=o.b*n,i=o.c*n,c=o.a*n,a=this.worldX-o.worldX,h=this.worldY-o.worldY;this.x=a*s-h*r,this.y=h*c-a*i,this.set5(s*this.a-r*this.c,s*this.b-r*this.d,c*this.c-i*this.a,c*this.d-i*this.b);}set5(t,e,o,n){this.shearX=0;let s=t*t+o*o,r=e*e+n*n;if(s>dt){let i=Math.atan2(o,t)/J;this.rotation=i,this.scaleX=Math.sqrt(s),this.scaleY=Math.sqrt(r),r>dt?(this.shearY=Math.atan2(n,e)/J,t*n-e*o<0?(this.scaleY=-this.scaleY,this.shearY+=90-i):this.shearY-=90+i,this.shearY>180?this.shearY-=360:this.shearY<=-180&&(this.shearY+=360)):this.shearY=0;}else this.scaleX=0,this.scaleY=Math.sqrt(r),this.shearY=0,this.rotation=r>dt?Math.atan2(n,e)/J-90:0;}modifyLocal(t){this.local===t.updateId&&this.updateLocalTransform(t),this.world=0,this.resetWorld(t);}modifyWorld(t){this.local=t.updateId,this.world=t.updateId,this.resetWorld(t);}resetWorld(t){for(let e of this.bone.children){let o=e.applied;o.world===t.updateId&&(o.local===t.updateId&&o.updateLocalTransform(t),o.world=0,o.resetWorld(t));}}},nt=class{constructor(t){this.data=t;this.pose=new ot(this),this.applied=new ot(this),this.setupPose();}data;pose;applied;parent=null;children=[];sorted=false;setupPose(){let t=this.data,e=this.pose;e.x=t.x,e.y=t.y,e.rotation=t.rotation,e.scaleX=t.scaleX,e.scaleY=t.scaleY,e.shearX=0,e.shearY=0;}},pt=class{constructor(t,e){this.data=t;this.bone=e;this.color={...t.color},this.attachmentKey=t.attachment;}data;bone;color;attachmentKey;attachment=null},H=class{constructor(t){this.data=t;this.bones=t.bones.map(e=>new nt(e));for(let e of this.bones)e.data.parent&&(e.parent=this.bones[e.data.parent.index],e.parent.children.push(e));this.slots=t.slots.map(e=>new pt(e,this.bones[e.bone.index])),this.constraints=t.constraints.map(e=>St(e,this)),this.updateCache();}data;bones;slots;constraints;skins=[];scaleX=1;scaleY=1;x=0;y=0;updateId=0;cache=[];bone(t){return this.bones[this.data.bone(t).index]}slot(t){return this.slots[this.data.slot(t).index]}setSkins(t){this.skins=[...t],this.resolveAttachments();}getAttachment(t,e){for(let o=this.skins.length-1;o>=0;o--){let n=this.skins[o].attachments.get(t)?.get(e);if(n)return n}return null}resolveAttachments(){for(let t of this.slots)t.attachment=t.attachmentKey?this.getAttachment(t.data.index,t.attachmentKey):null;}setupPose(){for(let t of this.bones)t.setupPose();for(let t of this.constraints)t.setupPose();for(let t of this.slots)Object.assign(t.color,t.data.color),t.attachmentKey=t.data.attachment;}updateWorldTransform(){this.updateId++;for(let t of this.bones)t.applied.copyLocal(t.pose),t.applied.world=0,t.applied.local=0;for(let t of this.cache)t instanceof nt?t.applied.update(this):t.update(this);}updateCache(){this.cache=[];for(let t of this.bones)t.sorted=false;for(let t of this.constraints)t.sort(this);for(let t of this.bones)this.sortBone(t);}sortBone(t){t.sorted||(t.parent&&this.sortBone(t.parent),t.sorted=true,this.cache.push(t));}sortReset(t){for(let e of t)e.sorted&&this.sortReset(e.children),e.sorted=false;}pushConstraint(t){this.cache.push(t);}};var Et=new WeakMap;function Yt(l,t){let e=Et.get(l);if(e)return e;e=new Map;let o=new H(l);o.setupPose(),o.updateWorldTransform();let[n,s]=t.light;for(let r of l.skins.values())for(let[i,c]of r.attachments)for(let a of c.values()){if(e.has(a.path)||t.skip?.some(g=>a.path.startsWith(g)))continue;let h=tt(o,o.slots[i],a,null),d=Vt(h.positions,h.uvs,a.width,a.height);if(!d)continue;let f=d.a*d.d-d.b*d.c;if(Math.abs(f)<1e-9)continue;let u=(d.d*n-d.b*s)/f,m=(-d.c*n+d.a*s)/f,b=Math.hypot(u,m)||1;e.set(a.path,{x:u/b,y:m/b});}return Et.set(l,e),e}function Vt(l,t,e,o){let n=t.length/2;if(n<3)return null;let s=0,r=0,i=0,c=0;for(let p=0;p<n;p++)s+=t[p*2]*e,r+=t[p*2+1]*o,i+=l[p*2],c+=l[p*2+1];s/=n,r/=n,i/=n,c/=n;let a=0,h=0,d=0,f=0,u=0,m=0,b=0;for(let p=0;p<n;p++){let k=t[p*2]*e-s,x=t[p*2+1]*o-r,P=l[p*2]-i,M=l[p*2+1]-c;a+=k*k,h+=k*x,d+=x*x,f+=P*k,u+=P*x,m+=M*k,b+=M*x;}let g=a*d-h*h;return Math.abs(g)<1e-9?null:{a:(f*d-u*h)/g,b:(u*a-f*h)/g,c:(m*d-b*h)/g,d:(b*a-m*h)/g}}var Bt=new Map,$t=new Map,Xt=new WeakMap,Ut=1;function Jt(l,t,e){let o=Xt.get(l);return o===void 0&&Xt.set(l,o=Ut++),`${o}@${t}${e??""}`}function jt(l,t,e,o,n){let s=Bt.get(l);return s||(s=new Promise(r=>{let i=new Image;i.onload=()=>{let c=new y__namespace.Texture(i);c.flipY=false,c.colorSpace=y__namespace.SRGBColorSpace,c.needsUpdate=true,$t.set(l,c),r(c);},i.onerror=()=>r(null),i.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(vt(t,e,o,{paint:n.paint??null,light:n.light??null}));}),Bt.set(l,s),s)}var ut=class{root=new y__namespace.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t){let e=this.rig=t.rig;this.catalog=t.catalog,this.resolution=t.resolution??2,this.unitsPerPx=t.unitsPerPx??.01,this.skeleton=new H(e.data),this.sizes=Dt(e.data),this.lights=e.shading?Yt(e.data,e.shading):new Map,this.parts=new et(e,o=>Rt(e.data,o).every(n=>this.catalog.has(n))),t.look&&this.parts.applyLook(t.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new Z(this.skeleton,e.data,e.mix),this.animator.setRandom(wt(t.seed??1)),this.animator.setBlink(e.blink??null),this.play(t.animation??e.defaultAnimation,{mix:0});for(let o=0;o<this.skeleton.slots.length;o++){let n=new y__namespace.BufferGeometry,s=new y__namespace.MeshBasicMaterial({transparent:true,depthWrite:false,side:y__namespace.DoubleSide}),r=new y__namespace.Mesh(n,s);r.renderOrder=o,r.visible=false,r.frustumCulled=false,this.root.add(r),this.slots.push({mesh:r,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let o=this.animator.on(t,e);return this.offs.push(o),o}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,o)=>e.mesh.renderOrder=t+o),this}worldPoint(t,e=new y__namespace.Vector3){let o=this.rig.anchors[t]??t,n=this.skeleton.bone(o).applied;return e.set(n.worldX*this.unitsPerPx,n.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,o=this.rig.expressions;if(o&&this.parts.setExpression(o.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(s=>{let r=this.rig.data.skins.get(s);return r?[r]:[]}));let n=this.asked;n&&this.stanceOf(n.name)!==this.animator.current()&&this.animator.play(this.stanceOf(n.name),{...n.options,mix:.15});}this.animator.update(t),e.slots.forEach((n,s)=>{let r=this.parts.slotColor(s);if(!r)return;let i=At(r);n.color.r=(i>>16&255)/255,n.color.g=(i>>8&255)/255,n.color.b=(i&255)/255,n.color.a=1;}),e.updateWorldTransform();for(let n=0;n<e.slots.length;n++)this.drawSlot(n);}drawSlot(t){let e=this.slots[t],o=this.skeleton.slots[t],n=o.attachment,s=e.mesh;if(!n||o.color.a*n.color.a<=0){s.visible=false;return}let r=this.parts.artColor(t);if((e.path!==n.path||e.paint!==r)&&(e.path=n.path,e.paint=r,e.key=null),!e.key){let p=this.catalog.get(n.path);if(!p){s.visible=false;return}let k=p.paint?r:null,x=Jt(p,this.resolution,k),P=$t.get(x);if(!P){let M=jt(x,p,this.sizes.get(n.path)??{w:n.width,h:n.height},this.resolution,{paint:k,light:this.lights.get(n.path)??null});this.pending.add(M),M.then(()=>this.pending.delete(M)),s.visible=false;return}e.key=x,s.material.map=P,s.material.needsUpdate=true;}let i=tt(this.skeleton,o,n,e.positions);e.positions=i.positions;let c=s.geometry,a=i.uvs.length/2,h=c.getAttribute("position");(!h||h.count!==a)&&(h=new y__namespace.BufferAttribute(new Float32Array(a*3),3),c.setAttribute("position",h),c.setAttribute("uv",new y__namespace.BufferAttribute(new Float32Array(a*2),2)));let d=h.array,f=c.getAttribute("uv").array;for(let p=0;p<a;p++)d[p*3]=i.positions[p*2]*this.unitsPerPx,d[p*3+1]=i.positions[p*2+1]*this.unitsPerPx,d[p*3+2]=0,f[p*2]=i.uvs[p*2],f[p*2+1]=i.uvs[p*2+1];h.needsUpdate=true,c.getAttribute("uv").needsUpdate=true;let u=i.triangles,m=c.getIndex();if(!m||m.count!==u.length)c.setIndex(Array.from(u));else {let p=m.array;for(let k=0;k<u.length;k++)p[k]=u[k];m.needsUpdate=true;}let b=o.color,g=n.color;s.material.color.setRGB(b.r*g.r,b.g*g.g,b.b*g.b,y__namespace.SRGBColorSpace),s.material.opacity=b.a*g.a,s.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,o=>e.isWorn(o)?e.part(o):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};
|
|
2
2
|
exports.Rig2dView=ut;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { E as Emotion, V as Viseme } from '../../contract-DhZuKNIf.cjs';
|
|
3
|
-
import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-
|
|
3
|
+
import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-CmrzoyJR.cjs';
|
|
4
4
|
|
|
5
5
|
interface Rig2dViewOptions {
|
|
6
6
|
rig: RigDef;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import { E as Emotion, V as Viseme } from '../../contract-DhZuKNIf.js';
|
|
3
|
-
import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-
|
|
3
|
+
import { S as Skeleton, a as Animator, P as PartsManager, R as RigDef, A as ArtCatalog, C as CharacterLook, b as PlayOptions, c as AnimationEvent } from '../../PartsManager-BpAUMQXw.js';
|
|
4
4
|
|
|
5
5
|
interface Rig2dViewOptions {
|
|
6
6
|
rig: RigDef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {w,s,
|
|
1
|
+
import {w,s,M,L as L$1,t,x,n,y,c}from'../../chunk-UUX4NEC2.js';import {a}from'../../chunk-CGF2TQVK.js';import*as o from'three';var O=new Map,I=new Map,z=new WeakMap,L=1;function U(p,t,e){let i=z.get(p);return i===void 0&&z.set(p,i=L++),`${i}@${t}${e??""}`}function V(p,t,e,i,s){let r=O.get(p);return r||(r=new Promise(n=>{let l=new Image;l.onload=()=>{let h=new o.Texture(l);h.flipY=false,h.colorSpace=o.SRGBColorSpace,h.needsUpdate=true,I.set(p,h),n(h);},l.onerror=()=>n(null),l.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(c(t,e,i,{paint:s.paint??null,light:s.light??null}));}),O.set(p,r),r)}var b=class{root=new o.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;constructor(t$1){let e=this.rig=t$1.rig;this.catalog=t$1.catalog,this.resolution=t$1.resolution??2,this.unitsPerPx=t$1.unitsPerPx??.01,this.skeleton=new w(e.data),this.sizes=s(e.data),this.lights=e.shading?M(e.data,e.shading):new Map,this.parts=new L$1(e,i=>t(e.data,i).every(s=>this.catalog.has(s))),t$1.look&&this.parts.applyLook(t$1.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new x(this.skeleton,e.data,e.mix),this.animator.setRandom(a(t$1.seed??1)),this.animator.setBlink(e.blink??null),this.play(t$1.animation??e.defaultAnimation,{mix:0});for(let i=0;i<this.skeleton.slots.length;i++){let s=new o.BufferGeometry,r=new o.MeshBasicMaterial({transparent:true,depthWrite:false,side:o.DoubleSide}),n=new o.Mesh(s,r);n.renderOrder=i,n.visible=false,n.frustumCulled=false,this.root.add(n),this.slots.push({mesh:n,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(t,e){return this.asked={name:t,...e?{options:e}:{}},this.animator.play(this.stanceOf(t),e)}on(t,e){let i=this.animator.on(t,e);return this.offs.push(i),i}setLook(t){this.parts.reset(),this.parts.applyLook(t);}setEmotion(t){this.parts.setEmotion(t);}setViseme(t){this.parts.setSpeech(t);}setFacing(t){return this.facing=t,this.applyScale(),this}setScale(t){return this.size=t,this.applyScale(),this}setRenderOrder(t){return this.slots.forEach((e,i)=>e.mesh.renderOrder=t+i),this}worldPoint(t,e=new o.Vector3){let i=this.rig.anchors[t]??t,s=this.skeleton.bone(i).applied;return e.set(s.worldX*this.unitsPerPx,s.worldY*this.unitsPerPx,0),this.root.localToWorld(e)}get height(){return this.rig.data.height*this.unitsPerPx*this.size}async ready(){for(this.update(0);this.pending.size>0;)await Promise.all([...this.pending]),this.update(0);}dispose(){for(let t of this.offs.splice(0))t();for(let t of this.slots)t.mesh.geometry.dispose(),t.mesh.material.dispose();this.root.removeFromParent();}update(t){let e=this.skeleton,i=this.rig.expressions;if(i&&this.parts.setExpression(i.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,e.setSkins(this.parts.wornSkins().flatMap(r=>{let n=this.rig.data.skins.get(r);return n?[n]:[]}));let s=this.asked;s&&this.stanceOf(s.name)!==this.animator.current()&&this.animator.play(this.stanceOf(s.name),{...s.options,mix:.15});}this.animator.update(t),e.slots.forEach((s,r)=>{let n$1=this.parts.slotColor(r);if(!n$1)return;let l=n(n$1);s.color.r=(l>>16&255)/255,s.color.g=(l>>8&255)/255,s.color.b=(l&255)/255,s.color.a=1;}),e.updateWorldTransform();for(let s=0;s<e.slots.length;s++)this.drawSlot(s);}drawSlot(t){let e=this.slots[t],i=this.skeleton.slots[t],s=i.attachment,r=e.mesh;if(!s||i.color.a*s.color.a<=0){r.visible=false;return}let n=this.parts.artColor(t);if((e.path!==s.path||e.paint!==n)&&(e.path=s.path,e.paint=n,e.key=null),!e.key){let a=this.catalog.get(s.path);if(!a){r.visible=false;return}let u=a.paint?n:null,v=U(a,this.resolution,u),A=I.get(v);if(!A){let k=V(v,a,this.sizes.get(s.path)??{w:s.width,h:s.height},this.resolution,{paint:u,light:this.lights.get(s.path)??null});this.pending.add(k),k.then(()=>this.pending.delete(k)),r.visible=false;return}e.key=v,r.material.map=A,r.material.needsUpdate=true;}let l=y(this.skeleton,i,s,e.positions);e.positions=l.positions;let h=r.geometry,c=l.uvs.length/2,m=h.getAttribute("position");(!m||m.count!==c)&&(m=new o.BufferAttribute(new Float32Array(c*3),3),h.setAttribute("position",m),h.setAttribute("uv",new o.BufferAttribute(new Float32Array(c*2),2)));let E=m.array,w=h.getAttribute("uv").array;for(let a=0;a<c;a++)E[a*3]=l.positions[a*2]*this.unitsPerPx,E[a*3+1]=l.positions[a*2+1]*this.unitsPerPx,E[a*3+2]=0,w[a*2]=l.uvs[a*2],w[a*2+1]=l.uvs[a*2+1];m.needsUpdate=true,h.getAttribute("uv").needsUpdate=true;let d=l.triangles,g=h.getIndex();if(!g||g.count!==d.length)h.setIndex(Array.from(d));else {let a=g.array;for(let u=0;u<d.length;u++)a[u]=d[u];g.needsUpdate=true;}let f=i.color,y$1=s.color;r.material.color.setRGB(f.r*y$1.r,f.g*y$1.g,f.b*y$1.b,o.SRGBColorSpace),r.material.opacity=f.a*y$1.a,r.visible=true;}stanceOf(t){let e=this.parts;return this.rig.stance?.(t,i=>e.isWorn(i)?e.part(i):null)??t}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};export{b as Rig2dView};
|