@idosgames/characters 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -2
  3. package/dist/PartsManager-CAVBKvp6.d.ts +589 -0
  4. package/dist/PartsManager-Cn3MU-VS.d.cts +589 -0
  5. package/dist/chunk-64D567CX.js +1 -0
  6. package/dist/chunk-BU66AZ2Z.js +1 -0
  7. package/dist/chunk-CGF2TQVK.js +1 -0
  8. package/dist/chunk-OF4BH3JZ.js +2 -0
  9. package/dist/chunk-WKHHFTK2.js +1 -0
  10. package/dist/chunk-Z5I76WRJ.js +1 -0
  11. package/dist/contract-DhZuKNIf.d.cts +24 -0
  12. package/dist/contract-DhZuKNIf.d.ts +24 -0
  13. package/dist/gltf/index.cjs +1 -0
  14. package/dist/gltf/index.d.cts +150 -0
  15. package/dist/gltf/index.d.ts +150 -0
  16. package/dist/gltf/index.js +1 -0
  17. package/dist/image-D5NaQeFz.d.cts +8 -0
  18. package/dist/image-D5NaQeFz.d.ts +8 -0
  19. package/dist/index.cjs +1 -0
  20. package/dist/index.d.cts +65 -0
  21. package/dist/index.d.ts +65 -0
  22. package/dist/index.js +1 -0
  23. package/dist/rig2d/editor/index.cjs +81 -0
  24. package/dist/rig2d/editor/index.d.cts +25 -0
  25. package/dist/rig2d/editor/index.d.ts +25 -0
  26. package/dist/rig2d/editor/index.js +81 -0
  27. package/dist/rig2d/index.cjs +17 -0
  28. package/dist/rig2d/index.d.cts +190 -0
  29. package/dist/rig2d/index.d.ts +190 -0
  30. package/dist/rig2d/index.js +17 -0
  31. package/dist/rig2d/phaser/index.cjs +2 -0
  32. package/dist/rig2d/phaser/index.d.cts +106 -0
  33. package/dist/rig2d/phaser/index.d.ts +106 -0
  34. package/dist/rig2d/phaser/index.js +1 -0
  35. package/dist/rig2d/three/index.cjs +2 -0
  36. package/dist/rig2d/three/index.d.cts +63 -0
  37. package/dist/rig2d/three/index.d.ts +63 -0
  38. package/dist/rig2d/three/index.js +1 -0
  39. package/dist/thumbnail-BhGEEXux.d.cts +49 -0
  40. package/dist/thumbnail-Bp-jK70T.d.ts +49 -0
  41. package/dist/voxel/index.cjs +54 -0
  42. package/dist/voxel/index.d.cts +972 -0
  43. package/dist/voxel/index.d.ts +972 -0
  44. package/dist/voxel/index.js +54 -0
  45. package/package.json +101 -4
@@ -0,0 +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=J;exports.createCharacterStage=Jt;exports.vectorArt=mt;
@@ -0,0 +1,106 @@
1
+ import Phaser from 'phaser';
2
+ import { h 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-Cn3MU-VS.cjs';
3
+ import '../../contract-DhZuKNIf.cjs';
4
+
5
+ interface ArtSource {
6
+ /** Can this source draw the image. */
7
+ has(path: string): boolean;
8
+ /** The texture key for an image; null while it is being made (onReady runs once it exists).
9
+ * `style` — its painted part's colour and the light on it, for a source that draws them. */
10
+ texture(path: string, size: {
11
+ w: number;
12
+ h: number;
13
+ }, onReady: () => void, style?: ArtStyle): string | null;
14
+ }
15
+ /** Our SVG art from a catalog, rasterized at `resolution`× per image. */
16
+ declare function vectorArt(textures: Phaser.Textures.TextureManager, catalog: ArtCatalog, resolution?: number): ArtSource;
17
+
18
+ interface CharacterViewOptions {
19
+ rig: RigDef;
20
+ art: ArtSource;
21
+ look?: CharacterLook;
22
+ x?: number;
23
+ y?: number;
24
+ /** 1 = the rig's own px (the hero is ~188 px tall). */
25
+ scale?: number;
26
+ /** Follow the scene's update by itself (default true); false — call update(dt) yourself. */
27
+ autoUpdate?: boolean;
28
+ /** The animation to start with (default the rig's). */
29
+ animation?: string;
30
+ }
31
+ declare class CharacterView {
32
+ private readonly scene;
33
+ readonly root: Phaser.GameObjects.Container;
34
+ readonly skeleton: Skeleton;
35
+ readonly animator: Animator;
36
+ readonly parts: PartsManager;
37
+ private readonly slots;
38
+ private readonly sizes;
39
+ private readonly lights;
40
+ private skinsDirty;
41
+ private overlay;
42
+ private flashUntil;
43
+ private flashColor;
44
+ private facing;
45
+ private size;
46
+ private readonly offs;
47
+ /** The animation asked for (play) — what is played may be a stance of it (rig.stance). */
48
+ private asked;
49
+ readonly rig: RigDef;
50
+ private art;
51
+ constructor(scene: Phaser.Scene, options: CharacterViewOptions);
52
+ /** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
53
+ play(animation: string, options?: PlayOptions): boolean;
54
+ /** The animation last asked for (play), not its stance. */
55
+ animation(): string | null;
56
+ private stanceOf;
57
+ /** An animation event ("Attack", "Step", "Hit", "Die"), "end", or "*". Returns the unsubscribe. */
58
+ on(event: string, listener: (e: AnimationEvent) => void): () => void;
59
+ setLook(look: CharacterLook): void;
60
+ /** Another art source (the maker swaps to a reference atlas and back). */
61
+ setArt(art: ArtSource): void;
62
+ setPosition(x: number, y: number): this;
63
+ setScale(scale: number): this;
64
+ /** 1 — the rig's own facing, -1 — mirrored. */
65
+ setFacing(direction: 1 | -1): this;
66
+ setDepth(depth: number): this;
67
+ setVisible(visible: boolean): this;
68
+ setAlpha(alpha: number): this;
69
+ /** A colour multiplied over the whole character (a frenzy glow); null — off. */
70
+ setOverlay(color: number | null): this;
71
+ /** The whole character filled with a colour for a moment (a hit flash). */
72
+ flash(color?: number, ms?: number): void;
73
+ /** A bone's position in world space — by anchor role ("hand", "head") or bone name. */
74
+ worldPoint(boneOrRole: string): {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ /** The character's height on screen (the skeleton's height × scale). */
79
+ get displayHeight(): number;
80
+ destroy(): void;
81
+ update(dt: number): void;
82
+ private drawSlot;
83
+ private drawsSkin;
84
+ }
85
+
86
+ interface CharacterStageOptions {
87
+ rig: RigDef;
88
+ catalog: ArtCatalog;
89
+ look?: CharacterLook;
90
+ width: number;
91
+ height: number;
92
+ /** The character's scale; it stands centred, its feet on a line 88% down. */
93
+ scale?: number;
94
+ /** Background colour; omitted — transparent. */
95
+ background?: string;
96
+ }
97
+ interface CharacterStage {
98
+ view: CharacterView;
99
+ game: Phaser.Game;
100
+ /** Our vector art for this stage (to switch back to after another source). */
101
+ vector: ArtSource;
102
+ destroy(): void;
103
+ }
104
+ declare function createCharacterStage(parent: HTMLElement, options: CharacterStageOptions): Promise<CharacterStage>;
105
+
106
+ export { type ArtSource, type CharacterStage, type CharacterStageOptions, CharacterView, type CharacterViewOptions, createCharacterStage, vectorArt };
@@ -0,0 +1,106 @@
1
+ import Phaser from 'phaser';
2
+ import { h 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-CAVBKvp6.js';
3
+ import '../../contract-DhZuKNIf.js';
4
+
5
+ interface ArtSource {
6
+ /** Can this source draw the image. */
7
+ has(path: string): boolean;
8
+ /** The texture key for an image; null while it is being made (onReady runs once it exists).
9
+ * `style` — its painted part's colour and the light on it, for a source that draws them. */
10
+ texture(path: string, size: {
11
+ w: number;
12
+ h: number;
13
+ }, onReady: () => void, style?: ArtStyle): string | null;
14
+ }
15
+ /** Our SVG art from a catalog, rasterized at `resolution`× per image. */
16
+ declare function vectorArt(textures: Phaser.Textures.TextureManager, catalog: ArtCatalog, resolution?: number): ArtSource;
17
+
18
+ interface CharacterViewOptions {
19
+ rig: RigDef;
20
+ art: ArtSource;
21
+ look?: CharacterLook;
22
+ x?: number;
23
+ y?: number;
24
+ /** 1 = the rig's own px (the hero is ~188 px tall). */
25
+ scale?: number;
26
+ /** Follow the scene's update by itself (default true); false — call update(dt) yourself. */
27
+ autoUpdate?: boolean;
28
+ /** The animation to start with (default the rig's). */
29
+ animation?: string;
30
+ }
31
+ declare class CharacterView {
32
+ private readonly scene;
33
+ readonly root: Phaser.GameObjects.Container;
34
+ readonly skeleton: Skeleton;
35
+ readonly animator: Animator;
36
+ readonly parts: PartsManager;
37
+ private readonly slots;
38
+ private readonly sizes;
39
+ private readonly lights;
40
+ private skinsDirty;
41
+ private overlay;
42
+ private flashUntil;
43
+ private flashColor;
44
+ private facing;
45
+ private size;
46
+ private readonly offs;
47
+ /** The animation asked for (play) — what is played may be a stance of it (rig.stance). */
48
+ private asked;
49
+ readonly rig: RigDef;
50
+ private art;
51
+ constructor(scene: Phaser.Scene, options: CharacterViewOptions);
52
+ /** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
53
+ play(animation: string, options?: PlayOptions): boolean;
54
+ /** The animation last asked for (play), not its stance. */
55
+ animation(): string | null;
56
+ private stanceOf;
57
+ /** An animation event ("Attack", "Step", "Hit", "Die"), "end", or "*". Returns the unsubscribe. */
58
+ on(event: string, listener: (e: AnimationEvent) => void): () => void;
59
+ setLook(look: CharacterLook): void;
60
+ /** Another art source (the maker swaps to a reference atlas and back). */
61
+ setArt(art: ArtSource): void;
62
+ setPosition(x: number, y: number): this;
63
+ setScale(scale: number): this;
64
+ /** 1 — the rig's own facing, -1 — mirrored. */
65
+ setFacing(direction: 1 | -1): this;
66
+ setDepth(depth: number): this;
67
+ setVisible(visible: boolean): this;
68
+ setAlpha(alpha: number): this;
69
+ /** A colour multiplied over the whole character (a frenzy glow); null — off. */
70
+ setOverlay(color: number | null): this;
71
+ /** The whole character filled with a colour for a moment (a hit flash). */
72
+ flash(color?: number, ms?: number): void;
73
+ /** A bone's position in world space — by anchor role ("hand", "head") or bone name. */
74
+ worldPoint(boneOrRole: string): {
75
+ x: number;
76
+ y: number;
77
+ };
78
+ /** The character's height on screen (the skeleton's height × scale). */
79
+ get displayHeight(): number;
80
+ destroy(): void;
81
+ update(dt: number): void;
82
+ private drawSlot;
83
+ private drawsSkin;
84
+ }
85
+
86
+ interface CharacterStageOptions {
87
+ rig: RigDef;
88
+ catalog: ArtCatalog;
89
+ look?: CharacterLook;
90
+ width: number;
91
+ height: number;
92
+ /** The character's scale; it stands centred, its feet on a line 88% down. */
93
+ scale?: number;
94
+ /** Background colour; omitted — transparent. */
95
+ background?: string;
96
+ }
97
+ interface CharacterStage {
98
+ view: CharacterView;
99
+ game: Phaser.Game;
100
+ /** Our vector art for this stage (to switch back to after another source). */
101
+ vector: ArtSource;
102
+ destroy(): void;
103
+ }
104
+ declare function createCharacterStage(parent: HTMLElement, options: CharacterStageOptions): Promise<CharacterStage>;
105
+
106
+ export { type ArtSource, type CharacterStage, type CharacterStageOptions, CharacterView, type CharacterViewOptions, createCharacterStage, vectorArt };
@@ -0,0 +1 @@
1
+ export{a as CharacterView,c as createCharacterStage,b as vectorArt}from'../../chunk-BU66AZ2Z.js';import'../../chunk-OF4BH3JZ.js';
@@ -0,0 +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);}};
2
+ exports.Rig2dView=ut;
@@ -0,0 +1,63 @@
1
+ import * as THREE from 'three';
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-Cn3MU-VS.cjs';
4
+
5
+ interface Rig2dViewOptions {
6
+ rig: RigDef;
7
+ catalog: ArtCatalog;
8
+ look?: CharacterLook;
9
+ /** The animation to start with (default the rig's). */
10
+ animation?: string;
11
+ /** Scene units per rig px (default 0.01 — the ~188 px hero is ~1.9 units tall). */
12
+ unitsPerPx?: number;
13
+ /** Rasterization × per image (default 2). */
14
+ resolution?: number;
15
+ /** Seed of the blink's chance — the same seed, the same blinks on every render. */
16
+ seed?: number;
17
+ }
18
+ declare class Rig2dView {
19
+ readonly root: THREE.Group<THREE.Object3DEventMap>;
20
+ readonly skeleton: Skeleton;
21
+ readonly animator: Animator;
22
+ readonly parts: PartsManager;
23
+ readonly rig: RigDef;
24
+ private readonly catalog;
25
+ private readonly slots;
26
+ private readonly sizes;
27
+ private readonly lights;
28
+ private readonly resolution;
29
+ private readonly unitsPerPx;
30
+ private readonly offs;
31
+ private readonly pending;
32
+ private asked;
33
+ private skinsDirty;
34
+ private facing;
35
+ private size;
36
+ constructor(options: Rig2dViewOptions);
37
+ /** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
38
+ play(animation: string, options?: PlayOptions): boolean;
39
+ /** An animation event, "end", or "*". Returns the unsubscribe. */
40
+ on(event: string, listener: (e: AnimationEvent) => void): () => void;
41
+ setLook(look: CharacterLook): void;
42
+ setEmotion(emotion: Emotion): void;
43
+ setViseme(viseme: Viseme): void;
44
+ /** 1 — the rig's own facing (the hero faces −x), −1 — mirrored. */
45
+ setFacing(direction: 1 | -1): this;
46
+ /** × the rig's own size in scene units. */
47
+ setScale(scale: number): this;
48
+ /** All the order slots draw in starts at `base` (another actor in front gets a higher base). */
49
+ setRenderOrder(base: number): this;
50
+ /** A bone's point in the scene — by anchor role ("hand", "head") or bone name. */
51
+ worldPoint(boneOrRole: string, out?: THREE.Vector3): THREE.Vector3;
52
+ /** Height in scene units. */
53
+ get height(): number;
54
+ /** Resolves when every picture of what is worn now has its texture (await before recording). */
55
+ ready(): Promise<void>;
56
+ dispose(): void;
57
+ update(dt: number): void;
58
+ private drawSlot;
59
+ private stanceOf;
60
+ private applyScale;
61
+ }
62
+
63
+ export { Rig2dView, type Rig2dViewOptions };
@@ -0,0 +1,63 @@
1
+ import * as THREE from 'three';
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-CAVBKvp6.js';
4
+
5
+ interface Rig2dViewOptions {
6
+ rig: RigDef;
7
+ catalog: ArtCatalog;
8
+ look?: CharacterLook;
9
+ /** The animation to start with (default the rig's). */
10
+ animation?: string;
11
+ /** Scene units per rig px (default 0.01 — the ~188 px hero is ~1.9 units tall). */
12
+ unitsPerPx?: number;
13
+ /** Rasterization × per image (default 2). */
14
+ resolution?: number;
15
+ /** Seed of the blink's chance — the same seed, the same blinks on every render. */
16
+ seed?: number;
17
+ }
18
+ declare class Rig2dView {
19
+ readonly root: THREE.Group<THREE.Object3DEventMap>;
20
+ readonly skeleton: Skeleton;
21
+ readonly animator: Animator;
22
+ readonly parts: PartsManager;
23
+ readonly rig: RigDef;
24
+ private readonly catalog;
25
+ private readonly slots;
26
+ private readonly sizes;
27
+ private readonly lights;
28
+ private readonly resolution;
29
+ private readonly unitsPerPx;
30
+ private readonly offs;
31
+ private readonly pending;
32
+ private asked;
33
+ private skinsDirty;
34
+ private facing;
35
+ private size;
36
+ constructor(options: Rig2dViewOptions);
37
+ /** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
38
+ play(animation: string, options?: PlayOptions): boolean;
39
+ /** An animation event, "end", or "*". Returns the unsubscribe. */
40
+ on(event: string, listener: (e: AnimationEvent) => void): () => void;
41
+ setLook(look: CharacterLook): void;
42
+ setEmotion(emotion: Emotion): void;
43
+ setViseme(viseme: Viseme): void;
44
+ /** 1 — the rig's own facing (the hero faces −x), −1 — mirrored. */
45
+ setFacing(direction: 1 | -1): this;
46
+ /** × the rig's own size in scene units. */
47
+ setScale(scale: number): this;
48
+ /** All the order slots draw in starts at `base` (another actor in front gets a higher base). */
49
+ setRenderOrder(base: number): this;
50
+ /** A bone's point in the scene — by anchor role ("hand", "head") or bone name. */
51
+ worldPoint(boneOrRole: string, out?: THREE.Vector3): THREE.Vector3;
52
+ /** Height in scene units. */
53
+ get height(): number;
54
+ /** Resolves when every picture of what is worn now has its texture (await before recording). */
55
+ ready(): Promise<void>;
56
+ dispose(): void;
57
+ update(dt: number): void;
58
+ private drawSlot;
59
+ private stanceOf;
60
+ private applyScale;
61
+ }
62
+
63
+ export { Rig2dView, type Rig2dViewOptions };
@@ -0,0 +1 @@
1
+ import {w,s,D,C,t,x,n,y,c}from'../../chunk-OF4BH3JZ.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?D(e.data,e.shading):new Map,this.parts=new C(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};
@@ -0,0 +1,49 @@
1
+ import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-Cn3MU-VS.cjs';
2
+
3
+ interface LookPreset {
4
+ id: string;
5
+ label: string;
6
+ look: CharacterLook;
7
+ }
8
+ declare const HERO_PRESETS: readonly LookPreset[];
9
+
10
+ interface ThumbnailBackdrop {
11
+ /** What is drawn behind, as a flat silhouette (a head under the face parts). */
12
+ skins: readonly string[];
13
+ /** Only these slots of it (by name); omitted — all. */
14
+ slots?: readonly string[];
15
+ color: Hex;
16
+ }
17
+ interface ThumbnailRequest {
18
+ skins: readonly string[];
19
+ /** The paint of a slot (by index) over its own colour, null — its own (PartsManager.slotColor). */
20
+ slotColor?: (slotIndex: number) => Hex | null;
21
+ /** The colour drawn into a slot's art (an iris), null — the art's own (PartsManager.artColor). */
22
+ artColor?: (slotIndex: number) => Hex | null;
23
+ /** Only these slots are drawn (by name); omitted — all. */
24
+ slots?: readonly string[];
25
+ backdrop?: ThumbnailBackdrop;
26
+ /** What the picture is framed on: the backdrop (every face part on the same head) or what is drawn. */
27
+ frame?: "backdrop" | "content";
28
+ /** Free space round the framed box, as a share of the canvas (default 0.08). */
29
+ padding?: number;
30
+ /** The animation and time of the pose (default the rig's default animation at 0). */
31
+ pose?: {
32
+ animation: string;
33
+ time: number;
34
+ };
35
+ }
36
+ /** Where the pictures' images come from: our vector art (vectorPictures) or any other source. */
37
+ interface PictureArt {
38
+ /** `paint` — the colour of the image's painted part (an iris), when the source draws one. */
39
+ image(path: string, paint?: Hex | null): Promise<HTMLImageElement | HTMLCanvasElement | null>;
40
+ }
41
+ /** Our vector art, each image rasterized once at `resolution`× its size. */
42
+ declare function vectorPictures(rig: RigDef, catalog: ArtCatalog, resolution?: number): PictureArt;
43
+ interface Thumbnailer {
44
+ /** Draws onto the canvas (cleared first), at its own pixel size. */
45
+ draw(canvas: HTMLCanvasElement, request: ThumbnailRequest): Promise<void>;
46
+ }
47
+ declare function createThumbnailer(rig: RigDef, art: PictureArt): Thumbnailer;
48
+
49
+ export { HERO_PRESETS as H, type LookPreset as L, type PictureArt as P, type ThumbnailBackdrop as T, type ThumbnailRequest as a, type Thumbnailer as b, createThumbnailer as c, vectorPictures as v };
@@ -0,0 +1,49 @@
1
+ import { C as CharacterLook, H as Hex, R as RigDef, A as ArtCatalog } from './PartsManager-CAVBKvp6.js';
2
+
3
+ interface LookPreset {
4
+ id: string;
5
+ label: string;
6
+ look: CharacterLook;
7
+ }
8
+ declare const HERO_PRESETS: readonly LookPreset[];
9
+
10
+ interface ThumbnailBackdrop {
11
+ /** What is drawn behind, as a flat silhouette (a head under the face parts). */
12
+ skins: readonly string[];
13
+ /** Only these slots of it (by name); omitted — all. */
14
+ slots?: readonly string[];
15
+ color: Hex;
16
+ }
17
+ interface ThumbnailRequest {
18
+ skins: readonly string[];
19
+ /** The paint of a slot (by index) over its own colour, null — its own (PartsManager.slotColor). */
20
+ slotColor?: (slotIndex: number) => Hex | null;
21
+ /** The colour drawn into a slot's art (an iris), null — the art's own (PartsManager.artColor). */
22
+ artColor?: (slotIndex: number) => Hex | null;
23
+ /** Only these slots are drawn (by name); omitted — all. */
24
+ slots?: readonly string[];
25
+ backdrop?: ThumbnailBackdrop;
26
+ /** What the picture is framed on: the backdrop (every face part on the same head) or what is drawn. */
27
+ frame?: "backdrop" | "content";
28
+ /** Free space round the framed box, as a share of the canvas (default 0.08). */
29
+ padding?: number;
30
+ /** The animation and time of the pose (default the rig's default animation at 0). */
31
+ pose?: {
32
+ animation: string;
33
+ time: number;
34
+ };
35
+ }
36
+ /** Where the pictures' images come from: our vector art (vectorPictures) or any other source. */
37
+ interface PictureArt {
38
+ /** `paint` — the colour of the image's painted part (an iris), when the source draws one. */
39
+ image(path: string, paint?: Hex | null): Promise<HTMLImageElement | HTMLCanvasElement | null>;
40
+ }
41
+ /** Our vector art, each image rasterized once at `resolution`× its size. */
42
+ declare function vectorPictures(rig: RigDef, catalog: ArtCatalog, resolution?: number): PictureArt;
43
+ interface Thumbnailer {
44
+ /** Draws onto the canvas (cleared first), at its own pixel size. */
45
+ draw(canvas: HTMLCanvasElement, request: ThumbnailRequest): Promise<void>;
46
+ }
47
+ declare function createThumbnailer(rig: RigDef, art: PictureArt): Thumbnailer;
48
+
49
+ export { HERO_PRESETS as H, type LookPreset as L, type PictureArt as P, type ThumbnailBackdrop as T, type ThumbnailRequest as a, type Thumbnailer as b, createThumbnailer as c, vectorPictures as v };