@idosgames/characters 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gltf/index.cjs +1 -1
- package/dist/gltf/index.d.cts +8 -1
- package/dist/gltf/index.d.ts +8 -1
- package/dist/gltf/index.js +1 -1
- package/dist/rig2d/three/index.cjs +1 -1
- package/dist/rig2d/three/index.d.cts +14 -0
- package/dist/rig2d/three/index.d.ts +14 -0
- package/dist/rig2d/three/index.js +1 -1
- package/dist/voxel/index.cjs +15 -15
- package/dist/voxel/index.d.cts +385 -4
- package/dist/voxel/index.d.ts +385 -4
- package/dist/voxel/index.js +15 -15
- package/package.json +1 -1
package/dist/gltf/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var d=require('three'),GLTFLoader_js=require('three/examples/jsm/loaders/GLTFLoader.js'),KTX2Loader_js=require('three/examples/jsm/loaders/KTX2Loader.js'),meshopt_decoder_module_js=require('three/examples/jsm/libs/meshopt_decoder.module.js'),SkeletonUtils_js=require('three/examples/jsm/utils/SkeletonUtils.js');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 d__namespace=/*#__PURE__*/_interopNamespace(d);var W="humanoid-v1",Y=["hips","spine","chest","upperChest","neck","head","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes"],H=["hips","spine","chest","neck","head","leftUpperArm","leftLowerArm","leftHand","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","rightUpperLeg","rightLowerLeg","rightFoot"],U={hips:"hips",pelvis:"hips",spine:"spine",spine1:"chest",chest:"chest",spine2:"upperChest",upperchest:"upperChest",neck:"neck",head:"head",leftshoulder:"leftShoulder",shoulderl:"leftShoulder",leftarm:"leftUpperArm",leftupperarm:"leftUpperArm",upperarml:"leftUpperArm",leftforearm:"leftLowerArm",leftlowerarm:"leftLowerArm",forearml:"leftLowerArm",lefthand:"leftHand",handl:"leftHand",rightshoulder:"rightShoulder",shoulderr:"rightShoulder",rightarm:"rightUpperArm",rightupperarm:"rightUpperArm",upperarmr:"rightUpperArm",rightforearm:"rightLowerArm",rightlowerarm:"rightLowerArm",forearmr:"rightLowerArm",righthand:"rightHand",handr:"rightHand",leftupleg:"leftUpperLeg",leftupperleg:"leftUpperLeg",thighl:"leftUpperLeg",leftleg:"leftLowerLeg",leftlowerleg:"leftLowerLeg",shinl:"leftLowerLeg",leftfoot:"leftFoot",footl:"leftFoot",lefttoebase:"leftToes",lefttoes:"leftToes",toel:"leftToes",rightupleg:"rightUpperLeg",rightupperleg:"rightUpperLeg",thighr:"rightUpperLeg",rightleg:"rightLowerLeg",rightlowerleg:"rightLowerLeg",shinr:"rightLowerLeg",rightfoot:"rightFoot",footr:"rightFoot",righttoebase:"rightToes",righttoes:"rightToes",toer:"rightToes"};function x(o){let e=o.replace(/^mixamorig\d*[:_]?/i,"").replace(/^(DEF|ORG|MCH)[-_.]/i,"").replace(/[\s._:-]/g,"").toLowerCase();return U[e]??null}var v={A:["v_A","aa","vrc.v_aa","mouth_a"],E:["v_E","ee","ih","vrc.v_e","vrc.v_ih","mouth_e"],O:["v_O","oh","ou","vrc.v_oh","vrc.v_ou","mouth_o"],MBP:["v_MBP","vrc.v_pp","mouth_m"],FV:["v_FV","vrc.v_ff","mouth_f"]},M={happy:["e_happy","happy","joy"],sad:["e_sad","sad","sorrow"],angry:["e_angry","angry"],surprised:["e_surprised","surprised"],scared:["e_scared","scared","fear"],tired:["e_tired","tired"],hurt:["e_hurt","hurt","pain"]},L=["blink","e_blink","eyes_closed"],I={handR:["socket_handR","rightHand"],handL:["socket_handL","leftHand"],head:["socket_head","head"]},g={maxTriangles:15e3,maxMaterials:2,maxTextureSize:2048,maxFileBytes:6*1024*1024};function F(o){let e=[],t=(a,f)=>e.push({level:"error",code:a,message:f}),r=(a,f)=>e.push({level:"warning",code:a,message:f}),s={};for(let a of o.bones){let f=x(a);f&&!s[f]&&(s[f]=a);}let i=H.filter(a=>!s[a]);o.bones.length===0?t("NO_SKELETON","the model has no skeleton (skin)"):i.length>0&&t("BONES_MISSING",`humanoid-v1 bones missing: ${i.join(", ")}`);let h=new Set(o.morphTargets.map(a=>a.toLowerCase())),n=a=>a.some(f=>h.has(f.toLowerCase())),l=Object.entries(v).filter(([,a])=>n(a)).map(([a])=>a),c=Object.entries(M).filter(([,a])=>n(a)).map(([a])=>a),p=n(L);l.length===0?r("NO_VISEMES","no mouth shape keys (v_A, v_E, v_O, v_MBP, v_FV): the mouth will not move"):l.length<5&&r("VISEMES_PARTIAL",`mouth shape keys: ${l.join(", ")} of A, E, O, MBP, FV`),c.length<6&&r("EMOTIONS_PARTIAL",`emotion shape keys: ${c.join(", ")||"none"} (the standard asks for happy, sad, angry, surprised, scared + neutral)`),p||r("NO_BLINK","no blink shape key"),o.triangles>g.maxTriangles&&t("TRIANGLES",`${o.triangles} triangles, budget ${g.maxTriangles}`),o.materials>g.maxMaterials&&t("MATERIALS",`${o.materials} materials, budget ${g.maxMaterials}`);let u=o.textureSizes.filter(a=>a>g.maxTextureSize);u.length>0&&t("TEXTURES",`textures over ${g.maxTextureSize}px: ${u.join(", ")}`),o.fileBytes>g.maxFileBytes&&t("FILE_SIZE",`${(o.fileBytes/1048576).toFixed(1)} MB, budget ${g.maxFileBytes/1048576} MB`);let[m,E,S]=o.bounds.min,[y,P,N]=o.bounds.max,b=P-E;return (b<.3||b>4)&&t("SCALE",`height ${b.toFixed(2)} m \u2014 units must be metres (a person is ~1.7 m)`),Math.abs(E)>.05*Math.max(b,1)&&r("PIVOT",`feet at y=${E.toFixed(2)}: the pivot must be between the feet (y = 0)`),(Math.abs((m+y)/2)>.25||Math.abs((S+N)/2)>.25)&&r("CENTER","the model is off the origin: the pivot must be between the feet"),y-m>b*1.5&&b>0&&r("AXES","wider than tall \u2014 is +Y up?"),o.animations>0&&r("EMBEDDED_CLIPS",`${o.animations} clips inside the character: clips belong to the shared library`),{ok:!e.some(a=>a.level==="error"),issues:e,boneMap:s,visemes:l,emotions:c,blink:p}}var G={neutral:"neutral",happy:"happy",sad:"sad",angry:"angry",surprised:"surprised",scared:"scared",tired:"tired",hurt:"hurt",love:"happy",excited:"happy",smug:"happy",confused:"surprised",embarrassed:"happy",silly:"happy",cool:"neutral",disgusted:"angry",determined:"angry",crying:"sad",dizzy:"hurt",sleepy:"tired",wink:"happy"};function C(o){let e=o>>>0;return function(){e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}var w=null;function O(o){let e=new GLTFLoader_js.GLTFLoader;return e.setMeshoptDecoder(meshopt_decoder_module_js.MeshoptDecoder),o.renderer&&o.ktx2TranscoderPath&&(w||(w=new KTX2Loader_js.KTX2Loader().setTranscoderPath(o.ktx2TranscoderPath),w.detectSupport(o.renderer)),e.setKTX2Loader(w)),e}var _=class o{constructor(e,t){this.gltf=e;this.report=F(t);}gltf;report;static async load(e,t={}){let r=await O(t).loadAsync(e);return new o(r,R(r,t.fileBytes??0))}static async parse(e,t={}){let r=await O(t).parseAsync(e,"");return new o(r,R(r,e.byteLength))}instance(e=1){return new k(SkeletonUtils_js.clone(this.gltf.scene),this.report,e)}};function R(o,e){let t=new Set,r=new Set,s=new Set,i=[],h=0;o.scene.updateMatrixWorld(true);let n=new d__namespace.Box3().setFromObject(o.scene);return o.scene.traverse(l=>{let c=l;if(l.isSkinnedMesh)for(let m of l.skeleton.bones)t.add(m.name);if(!c.isMesh)return;let p=c.geometry;h+=(p.index?p.index.count:p.attributes.position.count)/3;for(let m of Object.keys(c.morphTargetDictionary??{}))r.add(m);let u=Array.isArray(c.material)?c.material:[c.material];for(let m of u){s.add(m.uuid);for(let E of Object.values(m)){let S=E,y=S?.isTexture?S.image:null;y?.width&&y.height&&i.push(Math.max(y.width,y.height));}}}),{bones:[...t],morphTargets:[...r],triangles:Math.round(h),materials:s.size,textureSizes:i,fileBytes:e,bounds:{min:[n.min.x,n.min.y,n.min.z],max:[n.max.x,n.max.y,n.max.z]},animations:o.animations.length}}var k=class{constructor(e,t,r=1){this.report=t;this.rnd=C(r),this.blinkIn=2+this.rnd()*3,this.root=new d__namespace.Group,this.root.add(e),this.mixer=new d__namespace.AnimationMixer(e);let s=new Map;e.traverse(i=>{s.set(i.name,i);let h=x(i.name);h&&!this.bones[h]&&i.isBone&&(this.bones[h]=i);let n=i;if(!n.isMesh||!n.morphTargetDictionary)return;let l=z(n.morphTargetDictionary),c=p=>p.flatMap(u=>{let m=l.get(u.toLowerCase());return m===void 0?[]:[{mesh:n,index:m}]});for(let[p,u]of Object.entries(v))this.visemeMorphs.set(p,[...this.visemeMorphs.get(p)??[],...c(u)]);for(let[p,u]of Object.entries(M))this.emotionMorphs.set(p,[...this.emotionMorphs.get(p)??[],...c(u)]);this.blinkMorphs.push(...c(L));});for(let[i,h]of Object.entries(I)){let n=h.map(l=>s.get(l)??this.bones[l]).find(Boolean);n&&this.sockets.set(i,n);}}report;root;mixer;bones={};visemeMorphs=new Map;emotionMorphs=new Map;blinkMorphs=[];sockets=new Map;current=null;viseme="rest";visemeWeights=new Map;emotion="neutral";emotionWeight=0;blinkIn;blinkT=-1;rnd;play(e,t={}){let r=this.mixer.clipAction(e);r.reset(),r.setLoop(t.loop===false?d__namespace.LoopOnce:d__namespace.LoopRepeat,1/0),r.clampWhenFinished=t.loop===false,r.timeScale=t.timeScale??1;let s=t.fade??.2;this.current&&this.current!==r&&r.crossFadeFrom(this.current,s,false),r.play(),this.current=r;}setEmotion(e){this.emotion=this.emotionMorphs.get(e)?.length?e:G[e];}setViseme(e){this.viseme=e;}attach(e,t){let r=this.sockets.get(e);return r?(r.add(t),true):false}update(e){this.mixer.update(e);let t=1-Math.exp(-e/.06);for(let[s,i]of this.visemeMorphs){let h=s===this.viseme?1:0,n=(this.visemeWeights.get(s)??0)+(h-(this.visemeWeights.get(s)??0))*t;this.visemeWeights.set(s,n);for(let l of i)A(l,n);}let r=1-Math.exp(-e/.15);this.emotionWeight+=((this.emotion==="neutral"?0:1)-this.emotionWeight)*r;for(let[s,i]of this.emotionMorphs)for(let h of i)A(h,s===this.emotion?this.emotionWeight:0);if(this.blinkT>=0){this.blinkT+=e;let s=this.blinkT/.15,i=s<.5?s*2:Math.max(0,2-s*2);for(let h of this.blinkMorphs)A(h,i);s>=1&&(this.blinkT=-1,this.blinkIn=2+this.rnd()*3);}else (this.blinkIn-=e)<=0&&(this.blinkT=0);}dispose(){this.mixer.stopAllAction(),this.root.removeFromParent(),this.root.traverse(e=>{let t=e;t.isMesh&&t.geometry.dispose();});}};function A(o,e){let t=o.mesh.morphTargetInfluences;t&&(t[o.index]=e);}function z(o){return new Map(Object.entries(o).map(([e,t])=>[e.toLowerCase(),t]))}var B=class{clips=new Map;perTarget=new WeakMap;add(e,t){this.clips.set(e,t);}async load(e,t,r={}){let i=(await O(r).loadAsync(t)).animations[0];if(!i)throw new Error(`${t}: no animation`);this.add(e,i);}has(e){return this.clips.has(e)}names(){return [...this.clips.keys()]}clipFor(e,t){let r=this.perTarget.get(e);r||this.perTarget.set(e,r=new Map);let s=r.get(t);if(s)return s;let i=this.clips.get(t);if(!i)return null;let h=[];for(let l of i.tracks){let c=l.name.lastIndexOf("."),p=x(l.name.slice(0,c)),u=l.name.slice(c+1);if(!p)continue;let m=e.bones[p];if(!m||u==="position"&&p!=="hips"||u==="scale")continue;let E=l.clone();E.name=`${m.name}.${u}`,h.push(E);}let n=new d__namespace.AnimationClip(`${t}`,i.duration,h);return r.set(t,n),n}};exports.BLINK_KEYS=L;exports.EMOTION_KEYS=M;exports.GLTF_BUDGET=g;exports.GltfCharacter=k;exports.GltfCharacterAsset=_;exports.GltfClipLibrary=B;exports.HUMANOID_BONES=Y;exports.HUMANOID_V1=W;exports.REQUIRED_BONES=H;exports.SOCKET_NODES=I;exports.VISEME_KEYS=v;exports.canonicalBone=x;exports.gltfFacts=R;exports.validateGltfCharacter=F;
|
|
1
|
+
'use strict';var E=require('three'),GLTFLoader_js=require('three/examples/jsm/loaders/GLTFLoader.js'),KTX2Loader_js=require('three/examples/jsm/loaders/KTX2Loader.js'),meshopt_decoder_module_js=require('three/examples/jsm/libs/meshopt_decoder.module.js'),SkeletonUtils_js=require('three/examples/jsm/utils/SkeletonUtils.js');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 E__namespace=/*#__PURE__*/_interopNamespace(E);var he="humanoid-v1",pe=["hips","spine","chest","upperChest","neck","head","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes"],U=["hips","spine","chest","neck","head","leftUpperArm","leftLowerArm","leftHand","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","rightUpperLeg","rightLowerLeg","rightFoot"],te={hips:"hips",pelvis:"hips",spine:"spine",spine1:"chest",chest:"chest",spine2:"upperChest",upperchest:"upperChest",neck:"neck",head:"head",leftshoulder:"leftShoulder",shoulderl:"leftShoulder",leftarm:"leftUpperArm",leftupperarm:"leftUpperArm",upperarml:"leftUpperArm",leftforearm:"leftLowerArm",leftlowerarm:"leftLowerArm",forearml:"leftLowerArm",lefthand:"leftHand",handl:"leftHand",rightshoulder:"rightShoulder",shoulderr:"rightShoulder",rightarm:"rightUpperArm",rightupperarm:"rightUpperArm",upperarmr:"rightUpperArm",rightforearm:"rightLowerArm",rightlowerarm:"rightLowerArm",forearmr:"rightLowerArm",righthand:"rightHand",handr:"rightHand",leftupleg:"leftUpperLeg",leftupperleg:"leftUpperLeg",thighl:"leftUpperLeg",leftleg:"leftLowerLeg",leftlowerleg:"leftLowerLeg",shinl:"leftLowerLeg",leftfoot:"leftFoot",footl:"leftFoot",lefttoebase:"leftToes",lefttoes:"leftToes",toel:"leftToes",rightupleg:"rightUpperLeg",rightupperleg:"rightUpperLeg",thighr:"rightUpperLeg",rightleg:"rightLowerLeg",rightlowerleg:"rightLowerLeg",shinr:"rightLowerLeg",rightfoot:"rightFoot",footr:"rightFoot",righttoebase:"rightToes",righttoes:"rightToes",toer:"rightToes"};function M(o){let e=o.replace(/^mixamorig\d*[:_]?/i,"").replace(/^(DEF|ORG|MCH)[-_.]/i,"").replace(/[\s._:-]/g,"").toLowerCase();return te[e]??null}var L={A:["v_A","aa","vrc.v_aa","mouth_a"],E:["v_E","ee","ih","vrc.v_e","vrc.v_ih","mouth_e"],O:["v_O","oh","ou","vrc.v_oh","vrc.v_ou","mouth_o"],MBP:["v_MBP","vrc.v_pp","mouth_m"],FV:["v_FV","vrc.v_ff","mouth_f"]},A={happy:["e_happy","happy","joy"],sad:["e_sad","sad","sorrow"],angry:["e_angry","angry"],surprised:["e_surprised","surprised"],scared:["e_scared","scared","fear"],tired:["e_tired","tired"],hurt:["e_hurt","hurt","pain"]},O=["blink","e_blink","eyes_closed"],W={handR:["socket_handR","rightHand"],handL:["socket_handL","leftHand"],head:["socket_head","head"]},y={maxTriangles:15e3,maxMaterials:2,maxTextureSize:2048,maxFileBytes:6*1024*1024};function N(o){let e=[],t=(d,b)=>e.push({level:"error",code:d,message:b}),r=(d,b)=>e.push({level:"warning",code:d,message:b}),a={};for(let d of o.bones){let b=M(d);b&&!a[b]&&(a[b]=d);}let s=U.filter(d=>!a[d]);o.bones.length===0?t("NO_SKELETON","the model has no skeleton (skin)"):s.length>0&&t("BONES_MISSING",`humanoid-v1 bones missing: ${s.join(", ")}`);let c=new Set(o.morphTargets.map(d=>d.toLowerCase())),n=d=>d.some(b=>c.has(b.toLowerCase())),h=Object.entries(L).filter(([,d])=>n(d)).map(([d])=>d),l=Object.entries(A).filter(([,d])=>n(d)).map(([d])=>d),i=n(O);h.length===0?r("NO_VISEMES","no mouth shape keys (v_A, v_E, v_O, v_MBP, v_FV): the mouth will not move"):h.length<5&&r("VISEMES_PARTIAL",`mouth shape keys: ${h.join(", ")} of A, E, O, MBP, FV`),l.length<6&&r("EMOTIONS_PARTIAL",`emotion shape keys: ${l.join(", ")||"none"} (the standard asks for happy, sad, angry, surprised, scared + neutral)`),i||r("NO_BLINK","no blink shape key"),o.triangles>y.maxTriangles&&t("TRIANGLES",`${o.triangles} triangles, budget ${y.maxTriangles}`),o.materials>y.maxMaterials&&t("MATERIALS",`${o.materials} materials, budget ${y.maxMaterials}`);let m=o.textureSizes.filter(d=>d>y.maxTextureSize);m.length>0&&t("TEXTURES",`textures over ${y.maxTextureSize}px: ${m.join(", ")}`),o.fileBytes>y.maxFileBytes&&t("FILE_SIZE",`${(o.fileBytes/1048576).toFixed(1)} MB, budget ${y.maxFileBytes/1048576} MB`);let[p,f,g]=o.bounds.min,[T,J,ee]=o.bounds.max,w=J-f;return (w<.3||w>4)&&t("SCALE",`height ${w.toFixed(2)} m \u2014 units must be metres (a person is ~1.7 m)`),Math.abs(f)>.05*Math.max(w,1)&&r("PIVOT",`feet at y=${f.toFixed(2)}: the pivot must be between the feet (y = 0)`),(Math.abs((p+T)/2)>.25||Math.abs((g+ee)/2)>.25)&&r("CENTER","the model is off the origin: the pivot must be between the feet"),T-p>w*1.5&&w>0&&r("AXES","wider than tall \u2014 is +Y up?"),o.animations>0&&r("EMBEDDED_CLIPS",`${o.animations} clips inside the character: clips belong to the shared library`),{ok:!e.some(d=>d.level==="error"),issues:e,boneMap:a,visemes:h,emotions:l,blink:i}}var K={neutral:"neutral",happy:"happy",sad:"sad",angry:"angry",surprised:"surprised",scared:"scared",tired:"tired",hurt:"hurt",love:"happy",excited:"happy",smug:"happy",confused:"surprised",embarrassed:"happy",silly:"happy",cool:"neutral",disgusted:"angry",determined:"angry",crying:"sad",dizzy:"hurt",sleepy:"tired",wink:"happy"};function z(o){let e=o>>>0;return function(){e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}var re=.25,$=1.1,Q=.7,R=new E__namespace.Vector3,v=new E__namespace.Vector3,H=new E__namespace.Vector3,I=new E__namespace.Vector3,x=new E__namespace.Vector3,ne=new E__namespace.Quaternion,B=new E__namespace.Quaternion,Y=new E__namespace.Quaternion;function S(o,e){o.getWorldQuaternion(Y);let t=o.parent;t?t.getWorldQuaternion(B):B.identity(),o.quaternion.copy(B.invert().multiply(ne.copy(e).multiply(Y))),o.updateWorldMatrix(false,true);}function q(o,e,t,r,a){o.updateWorldMatrix(true,true),o.getWorldPosition(R),e.getWorldPosition(v),t.getWorldPosition(H);let s=R.distanceTo(v),c=v.distanceTo(H);if(s<1e-6||c<1e-6)return;let n=new E__namespace.Vector3().subVectors(R,v),h=new E__namespace.Vector3().subVectors(H,v),l=R.distanceTo(H),i=R.distanceTo(r),m=(s+c)*.999,p=(s+c)*.04;if(i>l&&i>m-p&&(i=Math.max(l,m-p+p*(1-Math.exp(-(i-(m-p))/p)))),i=Math.max(Math.abs(s-c)+1e-4,Math.min(i,m)),x.crossVectors(n,h),x.lengthSq()<1e-10&&x.crossVectors(n,a),x.lengthSq()<1e-10)return;x.normalize();let f=Math.acos(E__namespace.MathUtils.clamp((s*s+c*c-i*i)/(2*s*c),-1,1)),g=Math.atan2(I.crossVectors(n,h).dot(x),n.dot(h));S(e,new E__namespace.Quaternion().setFromAxisAngle(x,f-g)),t.getWorldPosition(H);let T=new E__namespace.Quaternion().setFromUnitVectors(I.subVectors(H,R).normalize(),new E__namespace.Vector3().subVectors(r,R).normalize());S(o,T);}function X(o,e,t,r,a,s){o.updateWorldMatrix(true,false),o.getWorldPosition(R);let c=I.subVectors(t,R),n=new E__namespace.Vector3().crossVectors(r,a).normalize(),h=c.dot(n),l=c.dot(a),i=c.dot(r),m=E__namespace.MathUtils.clamp(Math.atan2(-h,i),-$,$)*s,p=E__namespace.MathUtils.clamp(Math.atan2(l,Math.hypot(h,i)),-Q,Q)*s,f=g=>new E__namespace.Quaternion().setFromAxisAngle(a,m*g).multiply(new E__namespace.Quaternion().setFromAxisAngle(n,p*g));e?(S(e,f(.4)),S(o,f(.6))):S(o,f(1));}function Z(o,e,t){return Math.max(0,Math.min(1,o+(e?1:-1)*t/re))}var F=o=>o*o*(3-2*o);var _=null;function C(o){let e=new GLTFLoader_js.GLTFLoader;return e.setMeshoptDecoder(meshopt_decoder_module_js.MeshoptDecoder),o.renderer&&o.ktx2TranscoderPath&&(_||(_=new KTX2Loader_js.KTX2Loader().setTranscoderPath(o.ktx2TranscoderPath),_.detectSupport(o.renderer)),e.setKTX2Loader(_)),e}var D=class o{constructor(e,t){this.gltf=e;this.report=N(t);}gltf;report;static async load(e,t={}){let r=await C(t).loadAsync(e);return new o(r,G(r,t.fileBytes??0))}static async parse(e,t={}){let r=await C(t).parseAsync(e,"");return new o(r,G(r,e.byteLength))}instance(e=1){return new V(SkeletonUtils_js.clone(this.gltf.scene),this.report,e)}};function G(o,e){let t=new Set,r=new Set,a=new Set,s=[],c=0;o.scene.updateMatrixWorld(true);let n=new E__namespace.Box3().setFromObject(o.scene);return o.scene.traverse(h=>{let l=h;if(h.isSkinnedMesh)for(let p of h.skeleton.bones)t.add(p.name);if(!l.isMesh)return;let i=l.geometry;c+=(i.index?i.index.count:i.attributes.position.count)/3;for(let p of Object.keys(l.morphTargetDictionary??{}))r.add(p);let m=Array.isArray(l.material)?l.material:[l.material];for(let p of m){a.add(p.uuid);for(let f of Object.values(p)){let g=f,T=g?.isTexture?g.image:null;T?.width&&T.height&&s.push(Math.max(T.width,T.height));}}}),{bones:[...t],morphTargets:[...r],triangles:Math.round(c),materials:a.size,textureSizes:s,fileBytes:e,bounds:{min:[n.min.x,n.min.y,n.min.z],max:[n.max.x,n.max.y,n.max.z]},animations:o.animations.length}}var V=class{constructor(e,t,r=1){this.report=t;this.rnd=z(r),this.blinkIn=2+this.rnd()*3,this.root=new E__namespace.Group,this.root.add(e),this.mixer=new E__namespace.AnimationMixer(e);let a=new Map;e.traverse(s=>{a.set(s.name,s);let c=M(s.name);c&&!this.bones[c]&&s.isBone&&(this.bones[c]=s);let n=s;if(!n.isMesh||!n.morphTargetDictionary)return;let h=ce(n.morphTargetDictionary),l=i=>i.flatMap(m=>{let p=h.get(m.toLowerCase());return p===void 0?[]:[{mesh:n,index:p}]});for(let[i,m]of Object.entries(L))this.visemeMorphs.set(i,[...this.visemeMorphs.get(i)??[],...l(m)]);for(let[i,m]of Object.entries(A))this.emotionMorphs.set(i,[...this.emotionMorphs.get(i)??[],...l(m)]);this.blinkMorphs.push(...l(O));});for(let[s,c]of Object.entries(W)){let n=c.map(h=>a.get(h)??this.bones[h]).find(Boolean);n&&this.sockets.set(s,n);}}report;root;mixer;bones={};visemeMorphs=new Map;emotionMorphs=new Map;blinkMorphs=[];sockets=new Map;current=null;ik={look:null,handR:null,handL:null,w:{look:0,handR:0,handL:0},last:{look:new E__namespace.Vector3,handR:new E__namespace.Vector3,handL:new E__namespace.Vector3}};viseme="rest";visemeWeights=new Map;emotion="neutral";emotionWeight=0;blinkIn;blinkT=-1;rnd;play(e,t={}){let r=this.mixer.clipAction(e);r.reset(),r.setLoop(t.loop===false?E__namespace.LoopOnce:E__namespace.LoopRepeat,1/0),r.clampWhenFinished=t.loop===false,r.timeScale=t.timeScale??1;let a=t.fade??.2;this.current&&this.current!==r&&r.crossFadeFrom(this.current,a,false),r.play(),this.current=r;}setEmotion(e){this.emotion=this.emotionMorphs.get(e)?.length?e:K[e];}setViseme(e){this.viseme=e;}attach(e,t){let r=this.sockets.get(e);return r?(r.add(t),true):false}lookAt(e){this.ik.look=e;}reach(e,t){this.ik[e]=t;}update(e){this.mixer.update(e),this.solveIK(e);let t=1-Math.exp(-e/.06);for(let[a,s]of this.visemeMorphs){let c=a===this.viseme?1:0,n=(this.visemeWeights.get(a)??0)+(c-(this.visemeWeights.get(a)??0))*t;this.visemeWeights.set(a,n);for(let h of s)P(h,n);}let r=1-Math.exp(-e/.15);this.emotionWeight+=((this.emotion==="neutral"?0:1)-this.emotionWeight)*r;for(let[a,s]of this.emotionMorphs)for(let c of s)P(c,a===this.emotion?this.emotionWeight:0);if(this.blinkT>=0){this.blinkT+=e;let a=this.blinkT/.15,s=a<.5?a*2:Math.max(0,2-a*2);for(let c of this.blinkMorphs)P(c,s);a>=1&&(this.blinkT=-1,this.blinkIn=2+this.rnd()*3);}else (this.blinkIn-=e)<=0&&(this.blinkT=0);}solveIK(e){let t=this.ik,r=(l,i)=>l instanceof E__namespace.Object3D?l.getWorldPosition(i):i.copy(l);for(let l of ["look","handR","handL"]){t.w[l]=Z(t.w[l],!!t[l],e);let i=t[l];i&&r(i,t.last[l]);}if(t.w.look+t.w.handR+t.w.handL===0)return;this.root.updateWorldMatrix(true,true);let a=this.root.getWorldQuaternion(new E__namespace.Quaternion),s=new E__namespace.Vector3(0,0,-1).applyQuaternion(a),c=new E__namespace.Vector3(0,1,0).applyQuaternion(a),n=this.bones;t.w.look>0&&n.head&&X(n.head,n.neck,t.last.look,s,c,F(t.w.look));let h={handR:[n.rightUpperArm,n.rightLowerArm,n.rightHand],handL:[n.leftUpperArm,n.leftLowerArm,n.leftHand]};for(let l of ["handR","handL"]){let[i,m,p]=h[l],f=F(t.w[l]);if(f===0||!i||!m||!p)continue;let g=p.getWorldPosition(new E__namespace.Vector3);q(i,m,p,g.lerp(t.last[l],f),new E__namespace.Vector3().copy(s).negate());}}dispose(){this.mixer.stopAllAction(),this.root.removeFromParent(),this.root.traverse(e=>{let t=e;t.isMesh&&t.geometry.dispose();});}};function P(o,e){let t=o.mesh.morphTargetInfluences;t&&(t[o.index]=e);}function ce(o){return new Map(Object.entries(o).map(([e,t])=>[e.toLowerCase(),t]))}var j=class{clips=new Map;perTarget=new WeakMap;add(e,t){this.clips.set(e,t);}async load(e,t,r={}){let s=(await C(r).loadAsync(t)).animations[0];if(!s)throw new Error(`${t}: no animation`);this.add(e,s);}has(e){return this.clips.has(e)}names(){return [...this.clips.keys()]}clipFor(e,t){let r=this.perTarget.get(e);r||this.perTarget.set(e,r=new Map);let a=r.get(t);if(a)return a;let s=this.clips.get(t);if(!s)return null;let c=[];for(let h of s.tracks){let l=h.name.lastIndexOf("."),i=M(h.name.slice(0,l)),m=h.name.slice(l+1);if(!i)continue;let p=e.bones[i];if(!p||m==="position"&&i!=="hips"||m==="scale")continue;let f=h.clone();f.name=`${p.name}.${m}`,c.push(f);}let n=new E__namespace.AnimationClip(`${t}`,s.duration,c);return r.set(t,n),n}};exports.BLINK_KEYS=O;exports.EMOTION_KEYS=A;exports.GLTF_BUDGET=y;exports.GltfCharacter=V;exports.GltfCharacterAsset=D;exports.GltfClipLibrary=j;exports.HUMANOID_BONES=pe;exports.HUMANOID_V1=he;exports.REQUIRED_BONES=U;exports.SOCKET_NODES=W;exports.VISEME_KEYS=L;exports.canonicalBone=M;exports.gltfFacts=G;exports.validateGltfCharacter=N;
|
package/dist/gltf/index.d.cts
CHANGED
|
@@ -109,6 +109,8 @@ declare class GltfCharacter {
|
|
|
109
109
|
private readonly blinkMorphs;
|
|
110
110
|
private readonly sockets;
|
|
111
111
|
private current;
|
|
112
|
+
/** Обратная кинематика поверх клипа: куда смотреть, куда тянуть кисти (мир) и веса целей. */
|
|
113
|
+
private readonly ik;
|
|
112
114
|
private viseme;
|
|
113
115
|
private visemeWeights;
|
|
114
116
|
private emotion;
|
|
@@ -127,8 +129,13 @@ declare class GltfCharacter {
|
|
|
127
129
|
setViseme(v: Viseme): void;
|
|
128
130
|
/** Повесить пропс на сокет (правая/левая рука, голова). false — сокета у модели нет. */
|
|
129
131
|
attach(socket: ActorSocket, object: THREE.Object3D): boolean;
|
|
130
|
-
/**
|
|
132
|
+
/** Смотреть на цель (точка мира или объект сцены). null: снова за клипом (плавно). */
|
|
133
|
+
lookAt(target: THREE.Vector3 | THREE.Object3D | null): void;
|
|
134
|
+
/** Кисть к цели. null: снова за клипом (плавно). */
|
|
135
|
+
reach(hand: "handR" | "handL", target: THREE.Vector3 | THREE.Object3D | null): void;
|
|
136
|
+
/** Шаг времени: клипы, взгляд и руки к целям, лицо, моргание. */
|
|
131
137
|
update(dt: number): void;
|
|
138
|
+
private solveIK;
|
|
132
139
|
dispose(): void;
|
|
133
140
|
}
|
|
134
141
|
/**
|
package/dist/gltf/index.d.ts
CHANGED
|
@@ -109,6 +109,8 @@ declare class GltfCharacter {
|
|
|
109
109
|
private readonly blinkMorphs;
|
|
110
110
|
private readonly sockets;
|
|
111
111
|
private current;
|
|
112
|
+
/** Обратная кинематика поверх клипа: куда смотреть, куда тянуть кисти (мир) и веса целей. */
|
|
113
|
+
private readonly ik;
|
|
112
114
|
private viseme;
|
|
113
115
|
private visemeWeights;
|
|
114
116
|
private emotion;
|
|
@@ -127,8 +129,13 @@ declare class GltfCharacter {
|
|
|
127
129
|
setViseme(v: Viseme): void;
|
|
128
130
|
/** Повесить пропс на сокет (правая/левая рука, голова). false — сокета у модели нет. */
|
|
129
131
|
attach(socket: ActorSocket, object: THREE.Object3D): boolean;
|
|
130
|
-
/**
|
|
132
|
+
/** Смотреть на цель (точка мира или объект сцены). null: снова за клипом (плавно). */
|
|
133
|
+
lookAt(target: THREE.Vector3 | THREE.Object3D | null): void;
|
|
134
|
+
/** Кисть к цели. null: снова за клипом (плавно). */
|
|
135
|
+
reach(hand: "handR" | "handL", target: THREE.Vector3 | THREE.Object3D | null): void;
|
|
136
|
+
/** Шаг времени: клипы, взгляд и руки к целям, лицо, моргание. */
|
|
131
137
|
update(dt: number): void;
|
|
138
|
+
private solveIK;
|
|
132
139
|
dispose(): void;
|
|
133
140
|
}
|
|
134
141
|
/**
|
package/dist/gltf/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {a}from'../chunk-CGF2TQVK.js';import {d as d$1}from'../chunk-MNDPJKUD.js';import*as d from'three';import {GLTFLoader}from'three/examples/jsm/loaders/GLTFLoader.js';import {KTX2Loader}from'three/examples/jsm/loaders/KTX2Loader.js';import {MeshoptDecoder}from'three/examples/jsm/libs/meshopt_decoder.module.js';import {clone}from'three/examples/jsm/utils/SkeletonUtils.js';var $="humanoid-v1",W=["hips","spine","chest","upperChest","neck","head","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes"],I=["hips","spine","chest","neck","head","leftUpperArm","leftLowerArm","leftHand","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","rightUpperLeg","rightLowerLeg","rightFoot"],N={hips:"hips",pelvis:"hips",spine:"spine",spine1:"chest",chest:"chest",spine2:"upperChest",upperchest:"upperChest",neck:"neck",head:"head",leftshoulder:"leftShoulder",shoulderl:"leftShoulder",leftarm:"leftUpperArm",leftupperarm:"leftUpperArm",upperarml:"leftUpperArm",leftforearm:"leftLowerArm",leftlowerarm:"leftLowerArm",forearml:"leftLowerArm",lefthand:"leftHand",handl:"leftHand",rightshoulder:"rightShoulder",shoulderr:"rightShoulder",rightarm:"rightUpperArm",rightupperarm:"rightUpperArm",upperarmr:"rightUpperArm",rightforearm:"rightLowerArm",rightlowerarm:"rightLowerArm",forearmr:"rightLowerArm",righthand:"rightHand",handr:"rightHand",leftupleg:"leftUpperLeg",leftupperleg:"leftUpperLeg",thighl:"leftUpperLeg",leftleg:"leftLowerLeg",leftlowerleg:"leftLowerLeg",shinl:"leftLowerLeg",leftfoot:"leftFoot",footl:"leftFoot",lefttoebase:"leftToes",lefttoes:"leftToes",toel:"leftToes",rightupleg:"rightUpperLeg",rightupperleg:"rightUpperLeg",thighr:"rightUpperLeg",rightleg:"rightLowerLeg",rightlowerleg:"rightLowerLeg",shinr:"rightLowerLeg",rightfoot:"rightFoot",footr:"rightFoot",righttoebase:"rightToes",righttoes:"rightToes",toer:"rightToes"};function x(o){let e=o.replace(/^mixamorig\d*[:_]?/i,"").replace(/^(DEF|ORG|MCH)[-_.]/i,"").replace(/[\s._:-]/g,"").toLowerCase();return N[e]??null}var v={A:["v_A","aa","vrc.v_aa","mouth_a"],E:["v_E","ee","ih","vrc.v_e","vrc.v_ih","mouth_e"],O:["v_O","oh","ou","vrc.v_oh","vrc.v_ou","mouth_o"],MBP:["v_MBP","vrc.v_pp","mouth_m"],FV:["v_FV","vrc.v_ff","mouth_f"]},y={happy:["e_happy","happy","joy"],sad:["e_sad","sad","sorrow"],angry:["e_angry","angry"],surprised:["e_surprised","surprised"],scared:["e_scared","scared","fear"],tired:["e_tired","tired"],hurt:["e_hurt","hurt","pain"]},M=["blink","e_blink","eyes_closed"],F={handR:["socket_handR","rightHand"],handL:["socket_handL","leftHand"],head:["socket_head","head"]},u={maxTriangles:15e3,maxMaterials:2,maxTextureSize:2048,maxFileBytes:6*1024*1024};function G(o){let e=[],t=(a,g)=>e.push({level:"error",code:a,message:g}),r=(a,g)=>e.push({level:"warning",code:a,message:g}),i={};for(let a of o.bones){let g=x(a);g&&!i[g]&&(i[g]=a);}let n=I.filter(a=>!i[a]);o.bones.length===0?t("NO_SKELETON","the model has no skeleton (skin)"):n.length>0&&t("BONES_MISSING",`humanoid-v1 bones missing: ${n.join(", ")}`);let h=new Set(o.morphTargets.map(a=>a.toLowerCase())),s=a=>a.some(g=>h.has(g.toLowerCase())),l=Object.entries(v).filter(([,a])=>s(a)).map(([a])=>a),p=Object.entries(y).filter(([,a])=>s(a)).map(([a])=>a),m=s(M);l.length===0?r("NO_VISEMES","no mouth shape keys (v_A, v_E, v_O, v_MBP, v_FV): the mouth will not move"):l.length<5&&r("VISEMES_PARTIAL",`mouth shape keys: ${l.join(", ")} of A, E, O, MBP, FV`),p.length<6&&r("EMOTIONS_PARTIAL",`emotion shape keys: ${p.join(", ")||"none"} (the standard asks for happy, sad, angry, surprised, scared + neutral)`),m||r("NO_BLINK","no blink shape key"),o.triangles>u.maxTriangles&&t("TRIANGLES",`${o.triangles} triangles, budget ${u.maxTriangles}`),o.materials>u.maxMaterials&&t("MATERIALS",`${o.materials} materials, budget ${u.maxMaterials}`);let f=o.textureSizes.filter(a=>a>u.maxTextureSize);f.length>0&&t("TEXTURES",`textures over ${u.maxTextureSize}px: ${f.join(", ")}`),o.fileBytes>u.maxFileBytes&&t("FILE_SIZE",`${(o.fileBytes/1048576).toFixed(1)} MB, budget ${u.maxFileBytes/1048576} MB`);let[c,E,L]=o.bounds.min,[b,U,C]=o.bounds.max,T=U-E;return (T<.3||T>4)&&t("SCALE",`height ${T.toFixed(2)} m \u2014 units must be metres (a person is ~1.7 m)`),Math.abs(E)>.05*Math.max(T,1)&&r("PIVOT",`feet at y=${E.toFixed(2)}: the pivot must be between the feet (y = 0)`),(Math.abs((c+b)/2)>.25||Math.abs((L+C)/2)>.25)&&r("CENTER","the model is off the origin: the pivot must be between the feet"),b-c>T*1.5&&T>0&&r("AXES","wider than tall \u2014 is +Y up?"),o.animations>0&&r("EMBEDDED_CLIPS",`${o.animations} clips inside the character: clips belong to the shared library`),{ok:!e.some(a=>a.level==="error"),issues:e,boneMap:i,visemes:l,emotions:p,blink:m}}var w=null;function _(o){let e=new GLTFLoader;return e.setMeshoptDecoder(MeshoptDecoder),o.renderer&&o.ktx2TranscoderPath&&(w||(w=new KTX2Loader().setTranscoderPath(o.ktx2TranscoderPath),w.detectSupport(o.renderer)),e.setKTX2Loader(w)),e}var R=class o{constructor(e,t){this.gltf=e;this.report=G(t);}gltf;report;static async load(e,t={}){let r=await _(t).loadAsync(e);return new o(r,k(r,t.fileBytes??0))}static async parse(e,t={}){let r=await _(t).parseAsync(e,"");return new o(r,k(r,e.byteLength))}instance(e=1){return new S(clone(this.gltf.scene),this.report,e)}};function k(o,e){let t=new Set,r=new Set,i=new Set,n=[],h=0;o.scene.updateMatrixWorld(true);let s=new d.Box3().setFromObject(o.scene);return o.scene.traverse(l=>{let p=l;if(l.isSkinnedMesh)for(let c of l.skeleton.bones)t.add(c.name);if(!p.isMesh)return;let m=p.geometry;h+=(m.index?m.index.count:m.attributes.position.count)/3;for(let c of Object.keys(p.morphTargetDictionary??{}))r.add(c);let f=Array.isArray(p.material)?p.material:[p.material];for(let c of f){i.add(c.uuid);for(let E of Object.values(c)){let L=E,b=L?.isTexture?L.image:null;b?.width&&b.height&&n.push(Math.max(b.width,b.height));}}}),{bones:[...t],morphTargets:[...r],triangles:Math.round(h),materials:i.size,textureSizes:n,fileBytes:e,bounds:{min:[s.min.x,s.min.y,s.min.z],max:[s.max.x,s.max.y,s.max.z]},animations:o.animations.length}}var S=class{constructor(e,t,r=1){this.report=t;this.rnd=a(r),this.blinkIn=2+this.rnd()*3,this.root=new d.Group,this.root.add(e),this.mixer=new d.AnimationMixer(e);let i=new Map;e.traverse(n=>{i.set(n.name,n);let h=x(n.name);h&&!this.bones[h]&&n.isBone&&(this.bones[h]=n);let s=n;if(!s.isMesh||!s.morphTargetDictionary)return;let l=P(s.morphTargetDictionary),p=m=>m.flatMap(f=>{let c=l.get(f.toLowerCase());return c===void 0?[]:[{mesh:s,index:c}]});for(let[m,f]of Object.entries(v))this.visemeMorphs.set(m,[...this.visemeMorphs.get(m)??[],...p(f)]);for(let[m,f]of Object.entries(y))this.emotionMorphs.set(m,[...this.emotionMorphs.get(m)??[],...p(f)]);this.blinkMorphs.push(...p(M));});for(let[n,h]of Object.entries(F)){let s=h.map(l=>i.get(l)??this.bones[l]).find(Boolean);s&&this.sockets.set(n,s);}}report;root;mixer;bones={};visemeMorphs=new Map;emotionMorphs=new Map;blinkMorphs=[];sockets=new Map;current=null;viseme="rest";visemeWeights=new Map;emotion="neutral";emotionWeight=0;blinkIn;blinkT=-1;rnd;play(e,t={}){let r=this.mixer.clipAction(e);r.reset(),r.setLoop(t.loop===false?d.LoopOnce:d.LoopRepeat,1/0),r.clampWhenFinished=t.loop===false,r.timeScale=t.timeScale??1;let i=t.fade??.2;this.current&&this.current!==r&&r.crossFadeFrom(this.current,i,false),r.play(),this.current=r;}setEmotion(e){this.emotion=this.emotionMorphs.get(e)?.length?e:d$1[e];}setViseme(e){this.viseme=e;}attach(e,t){let r=this.sockets.get(e);return r?(r.add(t),true):false}update(e){this.mixer.update(e);let t=1-Math.exp(-e/.06);for(let[i,n]of this.visemeMorphs){let h=i===this.viseme?1:0,s=(this.visemeWeights.get(i)??0)+(h-(this.visemeWeights.get(i)??0))*t;this.visemeWeights.set(i,s);for(let l of n)A(l,s);}let r=1-Math.exp(-e/.15);this.emotionWeight+=((this.emotion==="neutral"?0:1)-this.emotionWeight)*r;for(let[i,n]of this.emotionMorphs)for(let h of n)A(h,i===this.emotion?this.emotionWeight:0);if(this.blinkT>=0){this.blinkT+=e;let i=this.blinkT/.15,n=i<.5?i*2:Math.max(0,2-i*2);for(let h of this.blinkMorphs)A(h,n);i>=1&&(this.blinkT=-1,this.blinkIn=2+this.rnd()*3);}else (this.blinkIn-=e)<=0&&(this.blinkT=0);}dispose(){this.mixer.stopAllAction(),this.root.removeFromParent(),this.root.traverse(e=>{let t=e;t.isMesh&&t.geometry.dispose();});}};function A(o,e){let t=o.mesh.morphTargetInfluences;t&&(t[o.index]=e);}function P(o){return new Map(Object.entries(o).map(([e,t])=>[e.toLowerCase(),t]))}var H=class{clips=new Map;perTarget=new WeakMap;add(e,t){this.clips.set(e,t);}async load(e,t,r={}){let n=(await _(r).loadAsync(t)).animations[0];if(!n)throw new Error(`${t}: no animation`);this.add(e,n);}has(e){return this.clips.has(e)}names(){return [...this.clips.keys()]}clipFor(e,t){let r=this.perTarget.get(e);r||this.perTarget.set(e,r=new Map);let i=r.get(t);if(i)return i;let n=this.clips.get(t);if(!n)return null;let h=[];for(let l of n.tracks){let p=l.name.lastIndexOf("."),m=x(l.name.slice(0,p)),f=l.name.slice(p+1);if(!m)continue;let c=e.bones[m];if(!c||f==="position"&&m!=="hips"||f==="scale")continue;let E=l.clone();E.name=`${c.name}.${f}`,h.push(E);}let s=new d.AnimationClip(`${t}`,n.duration,h);return r.set(t,s),s}};export{M as BLINK_KEYS,y as EMOTION_KEYS,u as GLTF_BUDGET,S as GltfCharacter,R as GltfCharacterAsset,H as GltfClipLibrary,W as HUMANOID_BONES,$ as HUMANOID_V1,I as REQUIRED_BONES,F as SOCKET_NODES,v as VISEME_KEYS,x as canonicalBone,k as gltfFacts,G as validateGltfCharacter};
|
|
1
|
+
import {a}from'../chunk-CGF2TQVK.js';import {d}from'../chunk-MNDPJKUD.js';import*as u from'three';import {GLTFLoader}from'three/examples/jsm/loaders/GLTFLoader.js';import {KTX2Loader}from'three/examples/jsm/loaders/KTX2Loader.js';import {MeshoptDecoder}from'three/examples/jsm/libs/meshopt_decoder.module.js';import {clone}from'three/examples/jsm/utils/SkeletonUtils.js';var le="humanoid-v1",ce=["hips","spine","chest","upperChest","neck","head","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes"],N=["hips","spine","chest","neck","head","leftUpperArm","leftLowerArm","leftHand","rightUpperArm","rightLowerArm","rightHand","leftUpperLeg","leftLowerLeg","leftFoot","rightUpperLeg","rightLowerLeg","rightFoot"],ee={hips:"hips",pelvis:"hips",spine:"spine",spine1:"chest",chest:"chest",spine2:"upperChest",upperchest:"upperChest",neck:"neck",head:"head",leftshoulder:"leftShoulder",shoulderl:"leftShoulder",leftarm:"leftUpperArm",leftupperarm:"leftUpperArm",upperarml:"leftUpperArm",leftforearm:"leftLowerArm",leftlowerarm:"leftLowerArm",forearml:"leftLowerArm",lefthand:"leftHand",handl:"leftHand",rightshoulder:"rightShoulder",shoulderr:"rightShoulder",rightarm:"rightUpperArm",rightupperarm:"rightUpperArm",upperarmr:"rightUpperArm",rightforearm:"rightLowerArm",rightlowerarm:"rightLowerArm",forearmr:"rightLowerArm",righthand:"rightHand",handr:"rightHand",leftupleg:"leftUpperLeg",leftupperleg:"leftUpperLeg",thighl:"leftUpperLeg",leftleg:"leftLowerLeg",leftlowerleg:"leftLowerLeg",shinl:"leftLowerLeg",leftfoot:"leftFoot",footl:"leftFoot",lefttoebase:"leftToes",lefttoes:"leftToes",toel:"leftToes",rightupleg:"rightUpperLeg",rightupperleg:"rightUpperLeg",thighr:"rightUpperLeg",rightleg:"rightLowerLeg",rightlowerleg:"rightLowerLeg",shinr:"rightLowerLeg",rightfoot:"rightFoot",footr:"rightFoot",righttoebase:"rightToes",righttoes:"rightToes",toer:"rightToes"};function y(o){let e=o.replace(/^mixamorig\d*[:_]?/i,"").replace(/^(DEF|ORG|MCH)[-_.]/i,"").replace(/[\s._:-]/g,"").toLowerCase();return ee[e]??null}var k={A:["v_A","aa","vrc.v_aa","mouth_a"],E:["v_E","ee","ih","vrc.v_e","vrc.v_ih","mouth_e"],O:["v_O","oh","ou","vrc.v_oh","vrc.v_ou","mouth_o"],MBP:["v_MBP","vrc.v_pp","mouth_m"],FV:["v_FV","vrc.v_ff","mouth_f"]},A={happy:["e_happy","happy","joy"],sad:["e_sad","sad","sorrow"],angry:["e_angry","angry"],surprised:["e_surprised","surprised"],scared:["e_scared","scared","fear"],tired:["e_tired","tired"],hurt:["e_hurt","hurt","pain"]},_=["blink","e_blink","eyes_closed"],P={handR:["socket_handR","rightHand"],handL:["socket_handL","leftHand"],head:["socket_head","head"]},R={maxTriangles:15e3,maxMaterials:2,maxTextureSize:2048,maxFileBytes:6*1024*1024};function K(o){let e=[],t=(d,b)=>e.push({level:"error",code:d,message:b}),r=(d,b)=>e.push({level:"warning",code:d,message:b}),a={};for(let d of o.bones){let b=y(d);b&&!a[b]&&(a[b]=d);}let s=N.filter(d=>!a[d]);o.bones.length===0?t("NO_SKELETON","the model has no skeleton (skin)"):s.length>0&&t("BONES_MISSING",`humanoid-v1 bones missing: ${s.join(", ")}`);let c=new Set(o.morphTargets.map(d=>d.toLowerCase())),n=d=>d.some(b=>c.has(b.toLowerCase())),h=Object.entries(k).filter(([,d])=>n(d)).map(([d])=>d),l=Object.entries(A).filter(([,d])=>n(d)).map(([d])=>d),i=n(_);h.length===0?r("NO_VISEMES","no mouth shape keys (v_A, v_E, v_O, v_MBP, v_FV): the mouth will not move"):h.length<5&&r("VISEMES_PARTIAL",`mouth shape keys: ${h.join(", ")} of A, E, O, MBP, FV`),l.length<6&&r("EMOTIONS_PARTIAL",`emotion shape keys: ${l.join(", ")||"none"} (the standard asks for happy, sad, angry, surprised, scared + neutral)`),i||r("NO_BLINK","no blink shape key"),o.triangles>R.maxTriangles&&t("TRIANGLES",`${o.triangles} triangles, budget ${R.maxTriangles}`),o.materials>R.maxMaterials&&t("MATERIALS",`${o.materials} materials, budget ${R.maxMaterials}`);let p=o.textureSizes.filter(d=>d>R.maxTextureSize);p.length>0&&t("TEXTURES",`textures over ${R.maxTextureSize}px: ${p.join(", ")}`),o.fileBytes>R.maxFileBytes&&t("FILE_SIZE",`${(o.fileBytes/1048576).toFixed(1)} MB, budget ${R.maxFileBytes/1048576} MB`);let[m,f,g]=o.bounds.min,[T,Z,J]=o.bounds.max,x=Z-f;return (x<.3||x>4)&&t("SCALE",`height ${x.toFixed(2)} m \u2014 units must be metres (a person is ~1.7 m)`),Math.abs(f)>.05*Math.max(x,1)&&r("PIVOT",`feet at y=${f.toFixed(2)}: the pivot must be between the feet (y = 0)`),(Math.abs((m+T)/2)>.25||Math.abs((g+J)/2)>.25)&&r("CENTER","the model is off the origin: the pivot must be between the feet"),T-m>x*1.5&&x>0&&r("AXES","wider than tall \u2014 is +Y up?"),o.animations>0&&r("EMBEDDED_CLIPS",`${o.animations} clips inside the character: clips belong to the shared library`),{ok:!e.some(d=>d.level==="error"),issues:e,boneMap:a,visemes:h,emotions:l,blink:i}}var te=.25,$=1.1,Q=.7,H=new u.Vector3,L=new u.Vector3,M=new u.Vector3,B=new u.Vector3,w=new u.Vector3,oe=new u.Quaternion,V=new u.Quaternion,z=new u.Quaternion;function v(o,e){o.getWorldQuaternion(z);let t=o.parent;t?t.getWorldQuaternion(V):V.identity(),o.quaternion.copy(V.invert().multiply(oe.copy(e).multiply(z))),o.updateWorldMatrix(false,true);}function Y(o,e,t,r,a){o.updateWorldMatrix(true,true),o.getWorldPosition(H),e.getWorldPosition(L),t.getWorldPosition(M);let s=H.distanceTo(L),c=L.distanceTo(M);if(s<1e-6||c<1e-6)return;let n=new u.Vector3().subVectors(H,L),h=new u.Vector3().subVectors(M,L),l=H.distanceTo(M),i=H.distanceTo(r),p=(s+c)*.999,m=(s+c)*.04;if(i>l&&i>p-m&&(i=Math.max(l,p-m+m*(1-Math.exp(-(i-(p-m))/m)))),i=Math.max(Math.abs(s-c)+1e-4,Math.min(i,p)),w.crossVectors(n,h),w.lengthSq()<1e-10&&w.crossVectors(n,a),w.lengthSq()<1e-10)return;w.normalize();let f=Math.acos(u.MathUtils.clamp((s*s+c*c-i*i)/(2*s*c),-1,1)),g=Math.atan2(B.crossVectors(n,h).dot(w),n.dot(h));v(e,new u.Quaternion().setFromAxisAngle(w,f-g)),t.getWorldPosition(M);let T=new u.Quaternion().setFromUnitVectors(B.subVectors(M,H).normalize(),new u.Vector3().subVectors(r,H).normalize());v(o,T);}function q(o,e,t,r,a,s){o.updateWorldMatrix(true,false),o.getWorldPosition(H);let c=B.subVectors(t,H),n=new u.Vector3().crossVectors(r,a).normalize(),h=c.dot(n),l=c.dot(a),i=c.dot(r),p=u.MathUtils.clamp(Math.atan2(-h,i),-$,$)*s,m=u.MathUtils.clamp(Math.atan2(l,Math.hypot(h,i)),-Q,Q)*s,f=g=>new u.Quaternion().setFromAxisAngle(a,p*g).multiply(new u.Quaternion().setFromAxisAngle(n,m*g));e?(v(e,f(.4)),v(o,f(.6))):v(o,f(1));}function X(o,e,t){return Math.max(0,Math.min(1,o+(e?1:-1)*t/te))}var F=o=>o*o*(3-2*o);var S=null;function G(o){let e=new GLTFLoader;return e.setMeshoptDecoder(MeshoptDecoder),o.renderer&&o.ktx2TranscoderPath&&(S||(S=new KTX2Loader().setTranscoderPath(o.ktx2TranscoderPath),S.detectSupport(o.renderer)),e.setKTX2Loader(S)),e}var D=class o{constructor(e,t){this.gltf=e;this.report=K(t);}gltf;report;static async load(e,t={}){let r=await G(t).loadAsync(e);return new o(r,U(r,t.fileBytes??0))}static async parse(e,t={}){let r=await G(t).parseAsync(e,"");return new o(r,U(r,e.byteLength))}instance(e=1){return new O(clone(this.gltf.scene),this.report,e)}};function U(o,e){let t=new Set,r=new Set,a=new Set,s=[],c=0;o.scene.updateMatrixWorld(true);let n=new u.Box3().setFromObject(o.scene);return o.scene.traverse(h=>{let l=h;if(h.isSkinnedMesh)for(let m of h.skeleton.bones)t.add(m.name);if(!l.isMesh)return;let i=l.geometry;c+=(i.index?i.index.count:i.attributes.position.count)/3;for(let m of Object.keys(l.morphTargetDictionary??{}))r.add(m);let p=Array.isArray(l.material)?l.material:[l.material];for(let m of p){a.add(m.uuid);for(let f of Object.values(m)){let g=f,T=g?.isTexture?g.image:null;T?.width&&T.height&&s.push(Math.max(T.width,T.height));}}}),{bones:[...t],morphTargets:[...r],triangles:Math.round(c),materials:a.size,textureSizes:s,fileBytes:e,bounds:{min:[n.min.x,n.min.y,n.min.z],max:[n.max.x,n.max.y,n.max.z]},animations:o.animations.length}}var O=class{constructor(e,t,r=1){this.report=t;this.rnd=a(r),this.blinkIn=2+this.rnd()*3,this.root=new u.Group,this.root.add(e),this.mixer=new u.AnimationMixer(e);let a$1=new Map;e.traverse(s=>{a$1.set(s.name,s);let c=y(s.name);c&&!this.bones[c]&&s.isBone&&(this.bones[c]=s);let n=s;if(!n.isMesh||!n.morphTargetDictionary)return;let h=ae(n.morphTargetDictionary),l=i=>i.flatMap(p=>{let m=h.get(p.toLowerCase());return m===void 0?[]:[{mesh:n,index:m}]});for(let[i,p]of Object.entries(k))this.visemeMorphs.set(i,[...this.visemeMorphs.get(i)??[],...l(p)]);for(let[i,p]of Object.entries(A))this.emotionMorphs.set(i,[...this.emotionMorphs.get(i)??[],...l(p)]);this.blinkMorphs.push(...l(_));});for(let[s,c]of Object.entries(P)){let n=c.map(h=>a$1.get(h)??this.bones[h]).find(Boolean);n&&this.sockets.set(s,n);}}report;root;mixer;bones={};visemeMorphs=new Map;emotionMorphs=new Map;blinkMorphs=[];sockets=new Map;current=null;ik={look:null,handR:null,handL:null,w:{look:0,handR:0,handL:0},last:{look:new u.Vector3,handR:new u.Vector3,handL:new u.Vector3}};viseme="rest";visemeWeights=new Map;emotion="neutral";emotionWeight=0;blinkIn;blinkT=-1;rnd;play(e,t={}){let r=this.mixer.clipAction(e);r.reset(),r.setLoop(t.loop===false?u.LoopOnce:u.LoopRepeat,1/0),r.clampWhenFinished=t.loop===false,r.timeScale=t.timeScale??1;let a=t.fade??.2;this.current&&this.current!==r&&r.crossFadeFrom(this.current,a,false),r.play(),this.current=r;}setEmotion(e){this.emotion=this.emotionMorphs.get(e)?.length?e:d[e];}setViseme(e){this.viseme=e;}attach(e,t){let r=this.sockets.get(e);return r?(r.add(t),true):false}lookAt(e){this.ik.look=e;}reach(e,t){this.ik[e]=t;}update(e){this.mixer.update(e),this.solveIK(e);let t=1-Math.exp(-e/.06);for(let[a,s]of this.visemeMorphs){let c=a===this.viseme?1:0,n=(this.visemeWeights.get(a)??0)+(c-(this.visemeWeights.get(a)??0))*t;this.visemeWeights.set(a,n);for(let h of s)I(h,n);}let r=1-Math.exp(-e/.15);this.emotionWeight+=((this.emotion==="neutral"?0:1)-this.emotionWeight)*r;for(let[a,s]of this.emotionMorphs)for(let c of s)I(c,a===this.emotion?this.emotionWeight:0);if(this.blinkT>=0){this.blinkT+=e;let a=this.blinkT/.15,s=a<.5?a*2:Math.max(0,2-a*2);for(let c of this.blinkMorphs)I(c,s);a>=1&&(this.blinkT=-1,this.blinkIn=2+this.rnd()*3);}else (this.blinkIn-=e)<=0&&(this.blinkT=0);}solveIK(e){let t=this.ik,r=(l,i)=>l instanceof u.Object3D?l.getWorldPosition(i):i.copy(l);for(let l of ["look","handR","handL"]){t.w[l]=X(t.w[l],!!t[l],e);let i=t[l];i&&r(i,t.last[l]);}if(t.w.look+t.w.handR+t.w.handL===0)return;this.root.updateWorldMatrix(true,true);let a=this.root.getWorldQuaternion(new u.Quaternion),s=new u.Vector3(0,0,-1).applyQuaternion(a),c=new u.Vector3(0,1,0).applyQuaternion(a),n=this.bones;t.w.look>0&&n.head&&q(n.head,n.neck,t.last.look,s,c,F(t.w.look));let h={handR:[n.rightUpperArm,n.rightLowerArm,n.rightHand],handL:[n.leftUpperArm,n.leftLowerArm,n.leftHand]};for(let l of ["handR","handL"]){let[i,p,m]=h[l],f=F(t.w[l]);if(f===0||!i||!p||!m)continue;let g=m.getWorldPosition(new u.Vector3);Y(i,p,m,g.lerp(t.last[l],f),new u.Vector3().copy(s).negate());}}dispose(){this.mixer.stopAllAction(),this.root.removeFromParent(),this.root.traverse(e=>{let t=e;t.isMesh&&t.geometry.dispose();});}};function I(o,e){let t=o.mesh.morphTargetInfluences;t&&(t[o.index]=e);}function ae(o){return new Map(Object.entries(o).map(([e,t])=>[e.toLowerCase(),t]))}var W=class{clips=new Map;perTarget=new WeakMap;add(e,t){this.clips.set(e,t);}async load(e,t,r={}){let s=(await G(r).loadAsync(t)).animations[0];if(!s)throw new Error(`${t}: no animation`);this.add(e,s);}has(e){return this.clips.has(e)}names(){return [...this.clips.keys()]}clipFor(e,t){let r=this.perTarget.get(e);r||this.perTarget.set(e,r=new Map);let a=r.get(t);if(a)return a;let s=this.clips.get(t);if(!s)return null;let c=[];for(let h of s.tracks){let l=h.name.lastIndexOf("."),i=y(h.name.slice(0,l)),p=h.name.slice(l+1);if(!i)continue;let m=e.bones[i];if(!m||p==="position"&&i!=="hips"||p==="scale")continue;let f=h.clone();f.name=`${m.name}.${p}`,c.push(f);}let n=new u.AnimationClip(`${t}`,s.duration,c);return r.set(t,n),n}};export{_ as BLINK_KEYS,A as EMOTION_KEYS,R as GLTF_BUDGET,O as GltfCharacter,D as GltfCharacterAsset,W as GltfClipLibrary,ce as HUMANOID_BONES,le as HUMANOID_V1,N as REQUIRED_BONES,P as SOCKET_NODES,k as VISEME_KEYS,y as canonicalBone,U as gltfFacts,K as validateGltfCharacter};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var g=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 g__namespace=/*#__PURE__*/_interopNamespace(g);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 St(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?Ht(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 Ht(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 O=Math.PI/180,ct=1e-5;function Mt(l,t){return l.type==="ik"?new $(l,t):new pt(l,t)}var ht=l=>l>180?l-360:l<=-180?l+360:l,$=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?Tt(t,this.bones[0].applied,e.worldX,e.worldY,this.mix):Ft(t,this.bones[0].applied,this.bones[1].applied,e.worldX,e.worldY,this.bendDirection,this.mix);}};function Tt(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,p=-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,y=(m*i-u*a)/f-t.y;p+=Math.atan2(y,b)/O,t.scaleX<0&&(p+=180),t.rotation+=ht(p)*n;}function Ft(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,p=e.scaleX,f,u,m;a<0?(a=-a,f=180,m=-1):(f=0,m=1),h<0&&(h=-h,m=-m),p<0?(p=-p,u=180):u=0;let b=Math.abs(a-h)<=ct,y,d;b?(y=t.a*e.x+t.b*e.y+t.worldX,d=t.c*e.x+t.d*e.y+t.worldY):(e.y=0,y=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,M=x.b,rt=x.c,it=x.d,I=P*it-M*rt,F=y-x.worldX,W=d-x.worldY;I=Math.abs(I)<=ct?0:1/I;let mt=(F*it-W*M)*I-i,yt=(W*P-F*rt)*I-c,w=Math.sqrt(mt*mt+yt*yt),E=e.bone.data.length*p;if(w<ct){Tt(l,t,o,n,r),e.rotation=0;return}F=o-x.worldX,W=n-x.worldY;let N=(F*it-W*M)*I-i,G=(W*P-F*rt)*I-c,z=N*N+G*G,R=0,T=0;if(b){E*=a;let v=(z-w*w-E*E)/(2*w*E);v<-1?(v=-1,T=Math.PI*s):v>1?(v=1,T=0):T=Math.acos(v)*s;let X=w+E*v,D=E*Math.sin(T);R=Math.atan2(G*X-N*D,N*X+G*D);}else {let v=a*E,X=h*E,D=v*v,q=X*X,at=Math.atan2(G,N),S=q*w*w+D*z-D*q,K=-2*q*w,bt=q-D,xt=K*K-4*bt*S,kt=false;if(xt>=0){let A=Math.sqrt(xt);K<0&&(A=-A),A=-(K+A)*.5;let C=A/bt,L=S/A,B=Math.abs(C)<Math.abs(L)?C:L,V=z-B*B;if(V>=0){let Y=Math.sqrt(V)*s;R=at-Math.atan2(Y,B),T=Math.atan2(Y/h,(B-w)/a),kt=true;}}if(!kt){let A=Math.PI,C=w-v,L=C*C,B=0,V=0,Y=w+v,lt=Y*Y,wt=0;if(S=-v*w/(D-q),S>=-1&&S<=1){S=Math.acos(S);let J=v*Math.cos(S)+w,Q=X*Math.sin(S),Z=J*J+Q*Q;Z<L&&(A=S,L=Z,C=J,B=Q),Z>lt&&(V=S,lt=Z,Y=J,wt=Q);}z<=(L+lt)*.5?(R=at-Math.atan2(B*s,C),T=A*s):(R=at-Math.atan2(wt*s,Y),T=V*s);}}let gt=Math.atan2(e.y,e.x)*m;R=ht((R-gt)/O+f-t.rotation),T=ht(((T+gt)/O-e.shearX)*m+u-e.rotation),t.rotation+=R*r,e.rotation+=T*r;}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 s of this.bones){let r=s.applied;r.modifyWorld(t);for(let i of this.data.properties){let c=Wt(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Nt(t,r,a.prop,a.offset+c*a.scale,h);}}}}};function Wt(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)/O+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))/O-90+o.shearY}}function Nt(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,p=o*O-Math.atan2(a,i);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=n;let f=Math.cos(p),u=Math.sin(p);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)*O;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 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,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 $&&(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 $&&(n.mix=o(this.ikSnapshot[s],n.mix));});}};var Pt=Math.PI/180,Gt=new Float32Array([0,1,0,0,1,0,1,1]),qt=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function Vt(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,s=l.height/2*l.scaleY,r=Math.cos(l.rotation*Pt),i=Math.sin(l.rotation*Pt),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)]),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),s=Vt(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:Gt,triangles:qt}}return Ut(l,t,e,o)}function Ut(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,p=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],y=r[i+3];h+=(m*u.a+b*u.b+u.worldX)*y,p+=(m*u.c+b*u.d+u.worldY)*y;}s[c]=h,s[c+1]=p;}}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 Et(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var It=new WeakMap;function Rt(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 Dt(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]}var Ct={neutral:"neutral",happy:"happy",sad:"sad",angry:"angry",surprised:"surprised",scared:"scared",tired:"tired",hurt:"hurt",love:"happy",excited:"happy",smug:"happy",confused:"surprised",embarrassed:"happy",silly:"happy",cool:"neutral",disgusted:"angry",determined:"angry",crying:"sad",dizzy:"hurt",sleepy:"tired",wink:"happy"};function Bt(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,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,o=e?.[t]??e?.[Ct[t]]??null,n=o&&this.rig.expressions?.faces[o]?o: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}));}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||!Bt(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,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,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,p=t.scaleY;this.a=n*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*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));}}},st=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;}},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},H=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=>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 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 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 Yt=new WeakMap;function Ot(l,t){let e=Yt.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(y=>a.path.startsWith(y)))continue;let h=et(o,o.slots[i],a,null),p=jt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let f=p.a*p.d-p.b*p.c;if(Math.abs(f)<1e-9)continue;let u=(p.d*n-p.b*s)/f,m=(-p.c*n+p.a*s)/f,b=Math.hypot(u,m)||1;e.set(a.path,{x:u/b,y:m/b});}return Yt.set(l,e),e}function jt(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 d=0;d<n;d++)s+=t[d*2]*e,r+=t[d*2+1]*o,i+=l[d*2],c+=l[d*2+1];s/=n,r/=n,i/=n,c/=n;let a=0,h=0,p=0,f=0,u=0,m=0,b=0;for(let d=0;d<n;d++){let k=t[d*2]*e-s,x=t[d*2+1]*o-r,P=l[d*2]-i,M=l[d*2+1]-c;a+=k*k,h+=k*x,p+=x*x,f+=P*k,u+=P*x,m+=M*k,b+=M*x;}let y=a*p-h*h;return Math.abs(y)<1e-9?null:{a:(f*p-u*h)/y,b:(u*a-f*h)/y,c:(m*p-b*h)/y,d:(b*a-m*h)/y}}var Xt=new Map,$t=new Map,Lt=new WeakMap,zt=1;function Kt(l,t,e){let o=Lt.get(l);return o===void 0&&Lt.set(l,o=zt++),`${o}@${t}${e??""}`}function Jt(l,t,e,o,n){let s=Xt.get(l);return s||(s=new Promise(r=>{let i=new Image;i.onload=()=>{let c=new g__namespace.Texture(i);c.flipY=false,c.colorSpace=g__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(St(t,e,o,{paint:n.paint??null,light:n.light??null}));}),Xt.set(l,s),s)}var ft=class{root=new g__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=Rt(e.data),this.lights=e.shading?Ot(e.data,e.shading):new Map,this.parts=new ot(e,o=>Dt(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 tt(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 o=0;o<this.skeleton.slots.length;o++){let n=new g__namespace.BufferGeometry,s=new g__namespace.MeshBasicMaterial({transparent:true,depthWrite:false,side:g__namespace.DoubleSide}),r=new g__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 g__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=Et(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 d=this.catalog.get(n.path);if(!d){s.visible=false;return}let k=d.paint?r:null,x=Kt(d,this.resolution,k),P=$t.get(x);if(!P){let M=Jt(x,d,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=et(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 g__namespace.BufferAttribute(new Float32Array(a*3),3),c.setAttribute("position",h),c.setAttribute("uv",new g__namespace.BufferAttribute(new Float32Array(a*2),2)));let p=h.array,f=c.getAttribute("uv").array;for(let d=0;d<a;d++)p[d*3]=i.positions[d*2]*this.unitsPerPx,p[d*3+1]=i.positions[d*2+1]*this.unitsPerPx,p[d*3+2]=0,f[d*2]=i.uvs[d*2],f[d*2+1]=i.uvs[d*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 d=m.array;for(let k=0;k<u.length;k++)d[k]=u[k];m.needsUpdate=true;}let b=o.color,y=n.color;s.material.color.setRGB(b.r*y.r,b.g*y.g,b.b*y.b,g__namespace.SRGBColorSpace),s.material.opacity=b.a*y.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);}};
|
|
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 St(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?Ht(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 Ht(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 O=Math.PI/180,ct=1e-5;function Tt(l,t){return l.type==="ik"?new $(l,t):new pt(l,t)}var ht=l=>l>180?l-360:l<=-180?l+360:l,$=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):Ft(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,p=-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;p+=Math.atan2(g,b)/O,t.scaleX<0&&(p+=180),t.rotation+=ht(p)*n;}function Ft(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,p=e.scaleX,f,u,m;a<0?(a=-a,f=180,m=-1):(f=0,m=1),h<0&&(h=-h,m=-m),p<0?(p=-p,u=180):u=0;let b=Math.abs(a-h)<=ct,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,T=x.b,rt=x.c,it=x.d,R=P*it-T*rt,F=g-x.worldX,W=d-x.worldY;R=Math.abs(R)<=ct?0:1/R;let mt=(F*it-W*T)*R-i,yt=(W*P-F*rt)*R-c,w=Math.sqrt(mt*mt+yt*yt),E=e.bone.data.length*p;if(w<ct){Mt(l,t,o,n,r),e.rotation=0;return}F=o-x.worldX,W=n-x.worldY;let N=(F*it-W*T)*R-i,G=(W*P-F*rt)*R-c,z=N*N+G*G,I=0,M=0;if(b){E*=a;let v=(z-w*w-E*E)/(2*w*E);v<-1?(v=-1,M=Math.PI*s):v>1?(v=1,M=0):M=Math.acos(v)*s;let X=w+E*v,D=E*Math.sin(M);I=Math.atan2(G*X-N*D,N*X+G*D);}else {let v=a*E,X=h*E,D=v*v,V=X*X,at=Math.atan2(G,N),S=V*w*w+D*z-D*V,K=-2*V*w,bt=V-D,xt=K*K-4*bt*S,kt=false;if(xt>=0){let A=Math.sqrt(xt);K<0&&(A=-A),A=-(K+A)*.5;let C=A/bt,L=S/A,B=Math.abs(C)<Math.abs(L)?C:L,q=z-B*B;if(q>=0){let Y=Math.sqrt(q)*s;I=at-Math.atan2(Y,B),M=Math.atan2(Y/h,(B-w)/a),kt=true;}}if(!kt){let A=Math.PI,C=w-v,L=C*C,B=0,q=0,Y=w+v,lt=Y*Y,wt=0;if(S=-v*w/(D-V),S>=-1&&S<=1){S=Math.acos(S);let J=v*Math.cos(S)+w,Q=X*Math.sin(S),Z=J*J+Q*Q;Z<L&&(A=S,L=Z,C=J,B=Q),Z>lt&&(q=S,lt=Z,Y=J,wt=Q);}z<=(L+lt)*.5?(I=at-Math.atan2(B*s,C),M=A*s):(I=at-Math.atan2(wt*s,Y),M=q*s);}}let gt=Math.atan2(e.y,e.x)*m;I=ht((I-gt)/O+f-t.rotation),M=ht(((M+gt)/O-e.shearX)*m+u-e.rotation),t.rotation+=I*r,e.rotation+=M*r;}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 s of this.bones){let r=s.applied;r.modifyWorld(t);for(let i of this.data.properties){let c=Wt(t,o,i.prop,n)-i.offset;for(let a of i.to){let h=e[a.prop];h!==0&&Nt(t,r,a.prop,a.offset+c*a.scale,h);}}}}};function Wt(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)/O+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))/O-90+o.shearY}}function Nt(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,p=o*O-Math.atan2(a,i);p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),p*=n;let f=Math.cos(p),u=Math.sin(p);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)*O;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 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,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 $&&(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 $&&(n.mix=o(this.ikSnapshot[s],n.mix));});}};var Pt=Math.PI/180,Gt=new Float32Array([0,1,0,0,1,0,1,1]),Vt=new Uint16Array([0,1,2,2,3,0]),At=new WeakMap;function qt(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,s=l.height/2*l.scaleY,r=Math.cos(l.rotation*Pt),i=Math.sin(l.rotation*Pt),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)]),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),s=qt(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:Gt,triangles:Vt}}return Ut(l,t,e,o)}function Ut(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,p=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,p+=(m*u.c+b*u.d+u.worldY)*g;}s[c]=h,s[c+1]=p;}}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 Et(l){let t=/^#?([0-9a-f]{6})$/i.exec(l.trim());return t?parseInt(t[1],16):16777215}var Rt=new WeakMap;function It(l){let t=Rt.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 Rt.set(l,t),t}function Dt(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]}var Ct={neutral:"neutral",happy:"happy",sad:"sad",angry:"angry",surprised:"surprised",scared:"scared",tired:"tired",hurt:"hurt",love:"happy",excited:"happy",smug:"happy",confused:"surprised",embarrassed:"happy",silly:"happy",cool:"neutral",disgusted:"angry",determined:"angry",crying:"sad",dizzy:"hurt",sleepy:"tired",wink:"happy"};function Bt(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,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,o=e?.[t]??e?.[Ct[t]]??null,n=o&&this.rig.expressions?.faces[o]?o: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}));}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||!Bt(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,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,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,p=t.scaleY;this.a=n*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*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));}}},st=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;}},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},H=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=>Tt(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 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 Yt=new WeakMap;function Ot(l,t){let e=Yt.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=et(o,o.slots[i],a,null),p=jt(h.positions,h.uvs,a.width,a.height);if(!p)continue;let f=p.a*p.d-p.b*p.c;if(Math.abs(f)<1e-9)continue;let u=(p.d*n-p.b*s)/f,m=(-p.c*n+p.a*s)/f,b=Math.hypot(u,m)||1;e.set(a.path,{x:u/b,y:m/b});}return Yt.set(l,e),e}function jt(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 d=0;d<n;d++)s+=t[d*2]*e,r+=t[d*2+1]*o,i+=l[d*2],c+=l[d*2+1];s/=n,r/=n,i/=n,c/=n;let a=0,h=0,p=0,f=0,u=0,m=0,b=0;for(let d=0;d<n;d++){let k=t[d*2]*e-s,x=t[d*2+1]*o-r,P=l[d*2]-i,T=l[d*2+1]-c;a+=k*k,h+=k*x,p+=x*x,f+=P*k,u+=P*x,m+=T*k,b+=T*x;}let g=a*p-h*h;return Math.abs(g)<1e-9?null:{a:(f*p-u*h)/g,b:(u*a-f*h)/g,c:(m*p-b*h)/g,d:(b*a-m*h)/g}}var Xt=new Map,$t=new Map,Lt=new WeakMap,zt=1;function Kt(l,t,e){let o=Lt.get(l);return o===void 0&&Lt.set(l,o=zt++),`${o}@${t}${e??""}`}function Jt(l,t,e,o,n){let s=Xt.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(St(t,e,o,{paint:n.paint??null,light:n.light??null}));}),Xt.set(l,s),s)}var ft=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;reaches=new Map;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=It(e.data),this.lights=e.shading?Ot(e.data,e.shading):new Map,this.parts=new ot(e,o=>Dt(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 tt(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 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}reach(t,e){let o=this.reaches.get(t)??{at:null,w:0,last:new y__namespace.Vector3};o.at=e,e&&o.last.copy(e),this.reaches.set(t,o);}reachTarget(t){let e=this.rig.anchors[t];if(!e)return null;let o=this.rig.data.bone(e),n=this.rig.data.constraints.find(r=>r.type==="ik"&&r.bones[r.bones.length-1]===o.parent);if(!n||n.type!=="ik")return null;let s=this.skeleton.bone(n.target.name);return s.parent?{target:s,parent:s.parent}:null}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(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);let n=this.applyReach(t);e.slots.forEach((s,r)=>{let i=this.parts.slotColor(r);if(!i)return;let c=Et(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(),n?.();for(let s=0;s<e.slots.length;s++)this.drawSlot(s);}applyReach(t){if(this.reaches.size===0)return null;let e=[];for(let[s,r]of this.reaches){r.w=Math.max(0,Math.min(1,r.w+(r.at?1:-1)*t/.25));let i=r.w>0?this.reachTarget(s):null;i&&e.push({target:i.target,x:i.target.pose.x,y:i.target.pose.y,w:r.w*r.w*(3-2*r.w),at:r.last});}if(!e.length)return null;this.skeleton.updateWorldTransform();let n=new y__namespace.Vector3;for(let s of e){this.root.updateWorldMatrix(true,false),this.root.worldToLocal(n.copy(s.at)).divideScalar(this.unitsPerPx);let r=s.target.parent.applied,i=r.a*r.d-r.b*r.c;if(Math.abs(i)<1e-9)continue;let c=n.x-r.worldX,a=n.y-r.worldY,h=(r.d*c-r.b*a)/i,p=(r.a*a-r.c*c)/i;s.target.pose.x=s.x+(h-s.x)*s.w,s.target.pose.y=s.y+(p-s.y)*s.w;}return ()=>{for(let s of e)s.target.pose.x=s.x,s.target.pose.y=s.y;}}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 d=this.catalog.get(n.path);if(!d){s.visible=false;return}let k=d.paint?r:null,x=Kt(d,this.resolution,k),P=$t.get(x);if(!P){let T=Jt(x,d,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(T),T.then(()=>this.pending.delete(T)),s.visible=false;return}e.key=x,s.material.map=P,s.material.needsUpdate=true;}let i=et(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 p=h.array,f=c.getAttribute("uv").array;for(let d=0;d<a;d++)p[d*3]=i.positions[d*2]*this.unitsPerPx,p[d*3+1]=i.positions[d*2+1]*this.unitsPerPx,p[d*3+2]=0,f[d*2]=i.uvs[d*2],f[d*2+1]=i.uvs[d*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 d=m.array;for(let k=0;k<u.length;k++)d[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=ft;
|
|
@@ -33,6 +33,8 @@ declare class Rig2dView {
|
|
|
33
33
|
private skinsDirty;
|
|
34
34
|
private facing;
|
|
35
35
|
private size;
|
|
36
|
+
/** Кисти к точкам сцены поверх анимации (`reach`): точка, вес и последняя точка, пока вес гаснет. */
|
|
37
|
+
private readonly reaches;
|
|
36
38
|
constructor(options: Rig2dViewOptions);
|
|
37
39
|
/** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
|
|
38
40
|
play(animation: string, options?: PlayOptions): boolean;
|
|
@@ -47,6 +49,13 @@ declare class Rig2dView {
|
|
|
47
49
|
setScale(scale: number): this;
|
|
48
50
|
/** All the order slots draw in starts at `base` (another actor in front gets a higher base). */
|
|
49
51
|
setRenderOrder(base: number): this;
|
|
52
|
+
/**
|
|
53
|
+
* Кисть к точке сцены (рукопожатие, объятие, дверная ручка): цель IK руки встаёт в эту точку поверх
|
|
54
|
+
* анимации, локоть гнёт сам риг. null: снова за анимацией (плавно за 0.25 с).
|
|
55
|
+
*/
|
|
56
|
+
reach(hand: "hand" | "offHand", at: THREE.Vector3 | null): void;
|
|
57
|
+
/** Цель IK руки (кость, к которой тянется цепочка с этой кистью) и её родитель. */
|
|
58
|
+
private reachTarget;
|
|
50
59
|
/** A bone's point in the scene — by anchor role ("hand", "head") or bone name. */
|
|
51
60
|
worldPoint(boneOrRole: string, out?: THREE.Vector3): THREE.Vector3;
|
|
52
61
|
/** Height in scene units. */
|
|
@@ -55,6 +64,11 @@ declare class Rig2dView {
|
|
|
55
64
|
ready(): Promise<void>;
|
|
56
65
|
dispose(): void;
|
|
57
66
|
update(dt: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Цели рук к точкам сцены: поза анимации сдвигается на этот кадр; возвращённая функция ставит её
|
|
69
|
+
* обратно после расчёта мира (у цели может не быть ключей: правка иначе копилась бы).
|
|
70
|
+
*/
|
|
71
|
+
private applyReach;
|
|
58
72
|
private drawSlot;
|
|
59
73
|
private stanceOf;
|
|
60
74
|
private applyScale;
|
|
@@ -33,6 +33,8 @@ declare class Rig2dView {
|
|
|
33
33
|
private skinsDirty;
|
|
34
34
|
private facing;
|
|
35
35
|
private size;
|
|
36
|
+
/** Кисти к точкам сцены поверх анимации (`reach`): точка, вес и последняя точка, пока вес гаснет. */
|
|
37
|
+
private readonly reaches;
|
|
36
38
|
constructor(options: Rig2dViewOptions);
|
|
37
39
|
/** Plays an animation — or the rig's stance of it for what is worn (a walk with a rifle). */
|
|
38
40
|
play(animation: string, options?: PlayOptions): boolean;
|
|
@@ -47,6 +49,13 @@ declare class Rig2dView {
|
|
|
47
49
|
setScale(scale: number): this;
|
|
48
50
|
/** All the order slots draw in starts at `base` (another actor in front gets a higher base). */
|
|
49
51
|
setRenderOrder(base: number): this;
|
|
52
|
+
/**
|
|
53
|
+
* Кисть к точке сцены (рукопожатие, объятие, дверная ручка): цель IK руки встаёт в эту точку поверх
|
|
54
|
+
* анимации, локоть гнёт сам риг. null: снова за анимацией (плавно за 0.25 с).
|
|
55
|
+
*/
|
|
56
|
+
reach(hand: "hand" | "offHand", at: THREE.Vector3 | null): void;
|
|
57
|
+
/** Цель IK руки (кость, к которой тянется цепочка с этой кистью) и её родитель. */
|
|
58
|
+
private reachTarget;
|
|
50
59
|
/** A bone's point in the scene — by anchor role ("hand", "head") or bone name. */
|
|
51
60
|
worldPoint(boneOrRole: string, out?: THREE.Vector3): THREE.Vector3;
|
|
52
61
|
/** Height in scene units. */
|
|
@@ -55,6 +64,11 @@ declare class Rig2dView {
|
|
|
55
64
|
ready(): Promise<void>;
|
|
56
65
|
dispose(): void;
|
|
57
66
|
update(dt: number): void;
|
|
67
|
+
/**
|
|
68
|
+
* Цели рук к точкам сцены: поза анимации сдвигается на этот кадр; возвращённая функция ставит её
|
|
69
|
+
* обратно после расчёта мира (у цели может не быть ключей: правка иначе копилась бы).
|
|
70
|
+
*/
|
|
71
|
+
private applyReach;
|
|
58
72
|
private drawSlot;
|
|
59
73
|
private stanceOf;
|
|
60
74
|
private applyScale;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import {w,s,M,L as L$1,t,x,n,y,c}from'../../chunk-UFZRW76X.js';import {a}from'../../chunk-CGF2TQVK.js';import'../../chunk-MNDPJKUD.js';import*as
|
|
1
|
+
import {w,s,M,L as L$1,t,x,n,y,c}from'../../chunk-UFZRW76X.js';import {a as a$1}from'../../chunk-CGF2TQVK.js';import'../../chunk-MNDPJKUD.js';import*as a from'three';var z=new Map,O=new Map,C=new WeakMap,L=1;function I(u,e,t){let i=C.get(u);return i===void 0&&C.set(u,i=L++),`${i}@${e}${t??""}`}function U(u,e,t,i,n){let r=z.get(u);return r||(r=new Promise(s=>{let o=new Image;o.onload=()=>{let l=new a.Texture(o);l.flipY=false,l.colorSpace=a.SRGBColorSpace,l.needsUpdate=true,O.set(u,l),s(l);},o.onerror=()=>s(null),o.src="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(c(e,t,i,{paint:n.paint??null,light:n.light??null}));}),z.set(u,r),r)}var v=class{root=new a.Group;skeleton;animator;parts;rig;catalog;slots=[];sizes;lights;resolution;unitsPerPx;offs=[];pending=new Set;asked=null;skinsDirty=true;facing=1;size=1;reaches=new Map;constructor(e){let t$1=this.rig=e.rig;this.catalog=e.catalog,this.resolution=e.resolution??2,this.unitsPerPx=e.unitsPerPx??.01,this.skeleton=new w(t$1.data),this.sizes=s(t$1.data),this.lights=t$1.shading?M(t$1.data,t$1.shading):new Map,this.parts=new L$1(t$1,i=>t(t$1.data,i).every(n=>this.catalog.has(n))),e.look&&this.parts.applyLook(e.look),this.offs.push(this.parts.on(()=>this.skinsDirty=true)),this.animator=new x(this.skeleton,t$1.data,t$1.mix),this.animator.setRandom(a$1(e.seed??1)),this.animator.setBlink(t$1.blink??null),this.play(e.animation??t$1.defaultAnimation,{mix:0});for(let i=0;i<this.skeleton.slots.length;i++){let n=new a.BufferGeometry,r=new a.MeshBasicMaterial({transparent:true,depthWrite:false,side:a.DoubleSide}),s=new a.Mesh(n,r);s.renderOrder=i,s.visible=false,s.frustumCulled=false,this.root.add(s),this.slots.push({mesh:s,positions:null,path:null,paint:null,key:null});}this.applyScale(),this.update(0);}play(e,t){return this.asked={name:e,...t?{options:t}:{}},this.animator.play(this.stanceOf(e),t)}on(e,t){let i=this.animator.on(e,t);return this.offs.push(i),i}setLook(e){this.parts.reset(),this.parts.applyLook(e);}setEmotion(e){this.parts.setEmotion(e);}setViseme(e){this.parts.setSpeech(e);}setFacing(e){return this.facing=e,this.applyScale(),this}setScale(e){return this.size=e,this.applyScale(),this}setRenderOrder(e){return this.slots.forEach((t,i)=>t.mesh.renderOrder=e+i),this}reach(e,t){let i=this.reaches.get(e)??{at:null,w:0,last:new a.Vector3};i.at=t,t&&i.last.copy(t),this.reaches.set(e,i);}reachTarget(e){let t=this.rig.anchors[e];if(!t)return null;let i=this.rig.data.bone(t),n=this.rig.data.constraints.find(s=>s.type==="ik"&&s.bones[s.bones.length-1]===i.parent);if(!n||n.type!=="ik")return null;let r=this.skeleton.bone(n.target.name);return r.parent?{target:r,parent:r.parent}:null}worldPoint(e,t=new a.Vector3){let i=this.rig.anchors[e]??e,n=this.skeleton.bone(i).applied;return t.set(n.worldX*this.unitsPerPx,n.worldY*this.unitsPerPx,0),this.root.localToWorld(t)}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 e of this.offs.splice(0))e();for(let e of this.slots)e.mesh.geometry.dispose(),e.mesh.material.dispose();this.root.removeFromParent();}update(e){let t=this.skeleton,i=this.rig.expressions;if(i&&this.parts.setExpression(i.byAnimation[this.animator.current()??""]??null),this.skinsDirty){this.skinsDirty=false,t.setSkins(this.parts.wornSkins().flatMap(s=>{let o=this.rig.data.skins.get(s);return o?[o]:[]}));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(e);let n$1=this.applyReach(e);t.slots.forEach((r,s)=>{let o=this.parts.slotColor(s);if(!o)return;let l=n(o);r.color.r=(l>>16&255)/255,r.color.g=(l>>8&255)/255,r.color.b=(l&255)/255,r.color.a=1;}),t.updateWorldTransform(),n$1?.();for(let r=0;r<t.slots.length;r++)this.drawSlot(r);}applyReach(e){if(this.reaches.size===0)return null;let t=[];for(let[r,s]of this.reaches){s.w=Math.max(0,Math.min(1,s.w+(s.at?1:-1)*e/.25));let o=s.w>0?this.reachTarget(r):null;o&&t.push({target:o.target,x:o.target.pose.x,y:o.target.pose.y,w:s.w*s.w*(3-2*s.w),at:s.last});}if(!t.length)return null;this.skeleton.updateWorldTransform();let n=new a.Vector3;for(let r of t){this.root.updateWorldMatrix(true,false),this.root.worldToLocal(n.copy(r.at)).divideScalar(this.unitsPerPx);let s=r.target.parent.applied,o=s.a*s.d-s.b*s.c;if(Math.abs(o)<1e-9)continue;let l=n.x-s.worldX,c=n.y-s.worldY,p=(s.d*l-s.b*c)/o,m=(s.a*c-s.c*l)/o;r.target.pose.x=r.x+(p-r.x)*r.w,r.target.pose.y=r.y+(m-r.y)*r.w;}return ()=>{for(let r of t)r.target.pose.x=r.x,r.target.pose.y=r.y;}}drawSlot(e){let t=this.slots[e],i=this.skeleton.slots[e],n=i.attachment,r=t.mesh;if(!n||i.color.a*n.color.a<=0){r.visible=false;return}let s=this.parts.artColor(e);if((t.path!==n.path||t.paint!==s)&&(t.path=n.path,t.paint=s,t.key=null),!t.key){let h=this.catalog.get(n.path);if(!h){r.visible=false;return}let d=h.paint?s:null,w=I(h,this.resolution,d),x=O.get(w);if(!x){let b=U(w,h,this.sizes.get(n.path)??{w:n.width,h:n.height},this.resolution,{paint:d,light:this.lights.get(n.path)??null});this.pending.add(b),b.then(()=>this.pending.delete(b)),r.visible=false;return}t.key=w,r.material.map=x,r.material.needsUpdate=true;}let o=y(this.skeleton,i,n,t.positions);t.positions=o.positions;let l=r.geometry,c=o.uvs.length/2,p=l.getAttribute("position");(!p||p.count!==c)&&(p=new a.BufferAttribute(new Float32Array(c*3),3),l.setAttribute("position",p),l.setAttribute("uv",new a.BufferAttribute(new Float32Array(c*2),2)));let m=p.array,k=l.getAttribute("uv").array;for(let h=0;h<c;h++)m[h*3]=o.positions[h*2]*this.unitsPerPx,m[h*3+1]=o.positions[h*2+1]*this.unitsPerPx,m[h*3+2]=0,k[h*2]=o.uvs[h*2],k[h*2+1]=o.uvs[h*2+1];p.needsUpdate=true,l.getAttribute("uv").needsUpdate=true;let g=o.triangles,f=l.getIndex();if(!f||f.count!==g.length)l.setIndex(Array.from(g));else {let h=f.array;for(let d=0;d<g.length;d++)h[d]=g[d];f.needsUpdate=true;}let y$1=i.color,E=n.color;r.material.color.setRGB(y$1.r*E.r,y$1.g*E.g,y$1.b*E.b,a.SRGBColorSpace),r.material.opacity=y$1.a*E.a,r.visible=true;}stanceOf(e){let t=this.parts;return this.rig.stance?.(e,i=>t.isWorn(i)?t.part(i):null)??e}applyScale(){this.root.scale.set(this.size*this.facing,this.size,this.size);}};export{v as Rig2dView};
|