@mymosdk/avatar 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Avatar-DEkBZdcp.js +2583 -0
- package/dist/Avatar-DEkBZdcp.js.map +1 -0
- package/dist/Avatar-Ok6vAXs6.cjs +10 -0
- package/dist/Avatar-Ok6vAXs6.cjs.map +1 -0
- package/dist/Avatar.d.ts +77 -0
- package/dist/Avatar.d.ts.map +1 -0
- package/dist/animation/AnimationEngine.d.ts +58 -0
- package/dist/animation/AnimationEngine.d.ts.map +1 -0
- package/dist/audio/AudioEngine.d.ts +19 -0
- package/dist/audio/AudioEngine.d.ts.map +1 -0
- package/dist/audio/LipSync.d.ts +14 -0
- package/dist/audio/LipSync.d.ts.map +1 -0
- package/dist/events/EventEmitter.d.ts +9 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/loader/AssetLoader.d.ts +18 -0
- package/dist/loader/AssetLoader.d.ts.map +1 -0
- package/dist/mymo-avatar.cjs +2 -0
- package/dist/mymo-avatar.cjs.map +1 -0
- package/dist/mymo-avatar.js +5 -0
- package/dist/mymo-avatar.js.map +1 -0
- package/dist/mymo-avatar.umd.js +992 -0
- package/dist/mymo-avatar.umd.js.map +1 -0
- package/dist/plugins/PluginSystem.d.ts +7 -0
- package/dist/plugins/PluginSystem.d.ts.map +1 -0
- package/dist/react/AvatarWidget.d.ts +4 -0
- package/dist/react/AvatarWidget.d.ts.map +1 -0
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/useAvatar.d.ts +3 -0
- package/dist/react/useAvatar.d.ts.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.js +19 -0
- package/dist/react.js.map +1 -0
- package/dist/renderer/Renderer.d.ts +46 -0
- package/dist/renderer/Renderer.d.ts.map +1 -0
- package/dist/types/index.d.ts +69 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/vue/AvatarWidget.d.ts +4 -0
- package/dist/vue/AvatarWidget.d.ts.map +1 -0
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/useAvatar.d.ts +4 -0
- package/dist/vue/useAvatar.d.ts.map +1 -0
- package/dist/vue.cjs +2 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.js +41 -0
- package/dist/vue.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";const d=require("three"),f=require("@pixiv/three-vrm");function ae(l){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const e in l)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(l,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>l[e]})}}return t.default=l,Object.freeze(t)}const y=ae(d);class ce{constructor(){this.listeners=new Map}on(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),this}off(t,e){return this.listeners.get(t)?.delete(e),this}emit(t,e){this.listeners.get(t)?.forEach(s=>s(t,e))}removeAllListeners(t){t?this.listeners.delete(t):this.listeners.clear()}}const le={full:[0,1,.5],half:[.48,1,.5],bust:[.68,1,.46],face:[.8,1,.36]},he={full:{camY:0,camZ:2.8,lookY:0},half:{camY:.5,camZ:2,lookY:.4},bust:{camY:.8,camZ:1,lookY:.55},face:{camY:.8,camZ:.7,lookY:.7}},ue={"bottom-right":{bottom:"20px",right:"20px"},"bottom-left":{bottom:"20px",left:"20px"},"top-right":{top:"20px",right:"20px"},"top-left":{top:"20px",left:"20px"}};class de{constructor(){this.clock=new y.Clock,this.rafId=0,this.tickCallbacks=[],this.currentModel=null,this.currentFraming="full",this.currentTheme="light",this.modelFraming=null,this.userSliceConfig={},this.userThemeConfig={},this._skeletonHelper=null,this.scene=new y.Scene,this.camera=new y.PerspectiveCamera(45,1,.1,100)}setup(t){this.webgl=new y.WebGLRenderer({antialias:!0,alpha:!0}),this.webgl.setPixelRatio(Math.min(window.devicePixelRatio,2)),this.webgl.setSize(t.size,t.size),this.webgl.shadowMap.enabled=t.shadows,this.webgl.shadowMap.type=y.PCFSoftShadowMap,this.webgl.outputColorSpace=y.SRGBColorSpace,this.webgl.toneMapping=y.ACESFilmicToneMapping,this._setupLights(),t.themeConfig&&(this.userThemeConfig=t.themeConfig),this._createContainer(t),this.currentFraming=t.framing,t.framingConfig&&(this.userSliceConfig=t.framingConfig),this._applyFraming(t.framing),this._startLoop()}_setupLights(){const t=new y.AmbientLight(16777215,.8),e=new y.DirectionalLight(16777215,1.5);e.position.set(1.5,3,2.5);const s=new y.DirectionalLight(8947967,.5);s.position.set(-2,0,1),this.scene.add(t,e,s)}_createContainer(t){this.container=document.createElement("div");const e=this.container.style;e.position="fixed",e.width=`${t.size}px`,e.height=`${t.size}px`,e.zIndex=String(t.zIndex),e.overflow="hidden",e.borderRadius="50%",e.cursor="pointer",e.userSelect="none",e.boxSizing="border-box",this.currentTheme=t.theme,this._applyTheme(t.theme,t.size),this._applyPosition(t.position),this.container.appendChild(this.webgl.domElement),document.body.appendChild(this.container),t.draggable&&this._makeDraggable()}setTheme(t){this.currentTheme=t,this._applyTheme(t,0)}setThemeConfig(t){this.userThemeConfig={...this.userThemeConfig,...t},this._applyTheme(this.currentTheme,0)}_applyTheme(t,e){const s=this.container.style;if(t==="dark"?(s.background=this.userThemeConfig.dark?.background??"radial-gradient(circle at 40% 35%, #2a2a4a 0%, #0d0d1a 100%)",s.boxShadow=this.userThemeConfig.dark?.boxShadow??"0 8px 32px rgba(0,0,0,0.5), 0 0 0 2px rgba(255,255,255,0.08)"):t==="light"?(s.background=this.userThemeConfig.light?.background??"radial-gradient(circle at 40% 35%, #f8f8ff 0%, #e0e0f0 100%)",s.boxShadow=this.userThemeConfig.light?.boxShadow??"0 8px 32px rgba(0,0,0,0.15), 0 0 0 2px rgba(0,0,0,0.06)"):(s.background="transparent",s.boxShadow="none"),s.transition="box-shadow 0.3s ease",s.setProperty("--ring-color","transparent"),!document.getElementById("__mymo_styles__")){const n=document.createElement("style");n.id="__mymo_styles__",n.textContent=`
|
|
2
|
+
@keyframes mymo-ring {
|
|
3
|
+
0% { box-shadow: 0 0 0 0px var(--ring-color); }
|
|
4
|
+
70% { box-shadow: 0 0 0 10px transparent; }
|
|
5
|
+
100% { box-shadow: 0 0 0 0px transparent; }
|
|
6
|
+
}
|
|
7
|
+
[data-state] { animation: mymo-ring 1.2s ease-out infinite; }
|
|
8
|
+
[data-state=""] { animation: none; }
|
|
9
|
+
`,document.head.appendChild(n)}}_applyPosition(t){const e=this.container.style;e.top=e.bottom=e.left=e.right="";const s=ue[t];for(const[n,i]of Object.entries(s))i!==void 0&&(e[n]=i)}_startLoop(){const t=()=>{this.rafId=requestAnimationFrame(t);const e=this.clock.getDelta();for(const s of this.tickCallbacks)s(e);this.webgl.render(this.scene,this.camera)};t()}_makeDraggable(){let t=!1,e=0,s=0;this.container.addEventListener("pointerdown",n=>{t=!0;const i=this.container.getBoundingClientRect();e=n.clientX-i.left,s=n.clientY-i.top,this.container.style.transition="none",n.preventDefault()}),window.addEventListener("pointermove",n=>{if(!t)return;const i=this.container.style;i.top=i.bottom=i.left=i.right="",i.left=`${n.clientX-e}px`,i.top=`${n.clientY-s}px`}),window.addEventListener("pointerup",()=>{t=!1})}addTickCallback(t){this.tickCallbacks.push(t)}setModel(t){this.currentModel&&this.scene.remove(this.currentModel),this._skeletonHelper&&(this.scene.remove(this._skeletonHelper),this._skeletonHelper=null),this.currentModel=t,this._autoFit(t),this.scene.add(t),this.modelFraming=this._computeFraming(t),this._applyFraming(this.currentFraming)}debugBones(t){if(this.currentModel){if(t===!1){this._skeletonHelper&&(this.scene.remove(this._skeletonHelper),this._skeletonHelper=null);return}this._skeletonHelper?(this.scene.remove(this._skeletonHelper),this._skeletonHelper=null):(this._skeletonHelper=new y.SkeletonHelper(this.currentModel),this.scene.add(this._skeletonHelper))}}_computeFraming(t){const e=new y.Box3().setFromObject(t),s=e.max.y-e.min.y,n=Math.tan(this.camera.fov*Math.PI/180/2),i={};for(const[o,a]of Object.entries(le)){const r=this.userSliceConfig[o]??{},c=r.from??a[0],u=r.to??a[1],h=r.lookBias??a[2],m=e.min.y+s*c,g=e.min.y+s*u-m,T=m+g*h,A=g/2/n*1.15;i[o]={camY:T,camZ:A,lookY:T}}return i}_autoFit(t){const e=new y.Box3().setFromObject(t),s=e.getCenter(new y.Vector3),n=e.getSize(new y.Vector3),o=1.8/Math.max(n.x,n.y,n.z);t.scale.setScalar(o),t.position.set(-s.x*o,-s.y*o,-s.z*o)}_applyFraming(t){const{camY:e,camZ:s,lookY:n}=(this.modelFraming??he)[t];this.camera.position.set(0,e,s),this.camera.lookAt(0,n,0)}show(){this.container.style.display=""}hide(){this.container.style.display="none"}setFraming(t){this.currentFraming=t,this._applyFraming(t)}setFramingConfig(t){this.userSliceConfig={...this.userSliceConfig,...t},this.currentModel&&(this.modelFraming=this._computeFraming(this.currentModel),this._applyFraming(this.currentFraming))}setPosition(t){this._applyPosition(t)}setSize(t){this.container.style.width=`${t}px`,this.container.style.height=`${t}px`,this.webgl.setSize(t,t)}moveTo(t,e){const s=this.container.style;s.top=s.bottom=s.left=s.right="",s.left=`${t}px`,s.top=`${e}px`}getContainer(){return this.container}dispose(){cancelAnimationFrame(this.rafId),this.tickCallbacks=[],this.webgl.dispose(),this.container.remove()}}function N(l,t,e){return l+(t-l)*e}function b(l){return l*l*(3-2*l)}function q(l){return Math.max(0,Math.min(1,l))}const E=Math.PI/3.2,G=-.1,me=.1,V=-.15,fe={wave:{duration:3,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightShoulder),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightLowerArm),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightHand),a=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),r=b(q(l/.25)),c=l>.8?b((l-.8)/.2):0,u=r*(1-c);s&&(s.rotation.z=N(0,-.2,u),s.rotation.x=0,s.rotation.y=0),n&&(n.rotation.z=N(E,0,u),n.rotation.x=0,n.rotation.y=0),i&&(i.rotation.order="XYZ",i.rotation.z=N(G,-Math.PI/2,u),i.rotation.x=0,i.rotation.y=0);const h=l>=.25&&l<=.8?Math.sin((l-.25)/.55*Math.PI*4):0;o&&(o.rotation.x=N(V,-Math.PI/2,u),o.rotation.y=h*.4*u,o.rotation.z=0),a&&(a.rotation.z=-E)}},nod:{duration:1.8,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Neck),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),o=l>.85?(1-l)/.15:1;s&&(s.rotation.x=.32*Math.max(0,Math.sin(l*Math.PI*2))*o),n&&(n.rotation.z=E),i&&(i.rotation.z=-E)}},shakeHead:{duration:1.8,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Neck),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),o=l>.85?(1-l)/.15:1;s&&(s.rotation.y=.35*Math.sin(l*Math.PI*2.5)*o),n&&(n.rotation.z=E),i&&(i.rotation.z=-E)}},clap:{duration:2.2,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightLowerArm),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftLowerArm),a=b(q(l/.2)),r=l>.8?b((l-.8)/.2):0,c=a*(1-r),u=l>=.2&&l<=.8?Math.max(0,Math.sin((l-.2)/.6*Math.PI*10)):0,h=Math.PI/2-.08,m=Math.PI/2+.05,p=N(h,m,u);s&&(s.rotation.z=N(E,Math.PI/3,c),s.rotation.y=N(0,p,c),s.rotation.x=0),n&&(n.rotation.z=N(-E,-Math.PI/3,c),n.rotation.y=N(0,-p,c),n.rotation.x=0);const g=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightHand),T=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftHand);i&&(i.rotation.z=N(G,-Math.PI/2.5,c),i.rotation.y=N(0,Math.PI/2,c),i.rotation.x=0),o&&(o.rotation.z=N(me,Math.PI/2.5,c),o.rotation.y=N(0,-Math.PI/2,c),o.rotation.x=0),g&&(g.rotation.z=N(0,-Math.PI/11.25,c),g.rotation.y=0,g.rotation.x=N(V,0,c)),T&&(T.rotation.z=N(0,Math.PI/11.25,c),T.rotation.y=0,T.rotation.x=N(V,0,c))}},jump:{duration:1.5,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Hips),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.Spine),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.Chest),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),a=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),r=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperLeg),c=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperLeg),u=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightLowerLeg),h=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftLowerLeg),m=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightFoot),p=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftFoot);let g=0,T=0,A=0,R=0,x=0;if(l<.22){const M=b(l/.22);g=-.12*M,T=M,A=-M*.85,x=M*.06}else if(l<.55){const M=b((l-.22)/.33);g=N(-.12,.22,M),T=N(1,0,M),A=N(-.85,.6,M),R=M*.5,x=N(.06,-.05,M)}else if(l<.72){const M=b((l-.55)/.17);g=N(.22,-.07,M),T=M*.75,A=N(.6,-.6,M),R=N(.5,0,M),x=N(-.05,.07,M)}else{const M=b((l-.72)/.28);g=N(-.07,0,M),T=N(.75,0,M),A=N(-.6,0,M),x=N(.07,0,M)}const S=t.scene.userData.hipsRestY??0;s&&(s.position.y=S+g),r&&(r.rotation.x=-T*.35,r.rotation.z=0,r.rotation.y=0),c&&(c.rotation.x=-T*.35,c.rotation.z=0,c.rotation.y=0),u&&(u.rotation.x=T*1.2,u.rotation.z=0,u.rotation.y=0),h&&(h.rotation.x=T*1.2,h.rotation.z=0,h.rotation.y=0),m&&(m.rotation.x=A,m.rotation.z=0,m.rotation.y=0),p&&(p.rotation.x=A,p.rotation.z=0,p.rotation.y=0),n&&(n.rotation.x=x),i&&(i.rotation.x=x*.4),o&&(o.rotation.z=E-R),a&&(a.rotation.z=-E+R)}},no:{duration:1.8,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Neck),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.Head),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),a=l<.12?b(l/.12):l>.85?b((1-l)/.15):1,r=Math.sin(l*Math.PI*6)*a;s&&(s.rotation.y=r*.38),n&&(n.rotation.y=r*.12),i&&(i.rotation.z=E),o&&(o.rotation.z=-E)}},yes:{duration:2,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Neck),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.Head),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),a=l<.12?b(l/.12):l>.85?b((1-l)/.15):1,r=Math.max(0,Math.sin(l*Math.PI*6))*a;s&&(s.rotation.x=r*.3),n&&(n.rotation.x=r*.12),i&&(i.rotation.z=E),o&&(o.rotation.z=-E)}},thumbsUp:{duration:2.5,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightLowerArm),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightHand),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),a=l<.2?b(l/.2):l>.8?b(1-(l-.8)/.2):1;s&&(s.rotation.y=N(0,.9,a),s.rotation.z=E,s.rotation.x=0),n&&(n.rotation.order="XYZ",n.rotation.y=N(0,1.8,a),n.rotation.z=N(G,0,a),n.rotation.x=0),i&&(i.rotation.x=N(V,-.9,a),i.rotation.y=N(0,.05,a),i.rotation.z=N(0,.6,a));const r=[[f.VRMHumanBoneName.RightIndexProximal,f.VRMHumanBoneName.RightIndexIntermediate,f.VRMHumanBoneName.RightIndexDistal],[f.VRMHumanBoneName.RightMiddleProximal,f.VRMHumanBoneName.RightMiddleIntermediate,f.VRMHumanBoneName.RightMiddleDistal],[f.VRMHumanBoneName.RightRingProximal,f.VRMHumanBoneName.RightRingIntermediate,f.VRMHumanBoneName.RightRingDistal],[f.VRMHumanBoneName.RightLittleProximal,f.VRMHumanBoneName.RightLittleIntermediate,f.VRMHumanBoneName.RightLittleDistal]];for(const[m,p,g]of r){const T=N(.28,1.45,a),A=e.getNormalizedBoneNode(m),R=e.getNormalizedBoneNode(p),x=e.getNormalizedBoneNode(g);A&&(A.rotation.z=T,A.rotation.x=0),R&&(R.rotation.z=T*.9,R.rotation.x=0),x&&(x.rotation.z=T*.7,x.rotation.x=0)}const c=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightThumbMetacarpal),u=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightThumbProximal),h=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightThumbDistal);c&&(c.rotation.x=N(.2,.2,a),c.rotation.z=N(-.3,-.3,a),c.rotation.y=0),u&&(u.rotation.x=0,u.rotation.z=0,u.rotation.y=0),h&&(h.rotation.x=0,h.rotation.z=0,h.rotation.y=0),o&&(o.rotation.z=-E)}},dance:{duration:3,fn(l,t){const e=t.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Hips),n=e.getNormalizedBoneNode(f.VRMHumanBoneName.Spine),i=e.getNormalizedBoneNode(f.VRMHumanBoneName.Chest),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.Neck),a=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),r=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm),c=l<.1?l/.1:l>.9?(1-l)/.1:1,u=Math.sin(l*Math.PI*4)*c,h=Math.sin(l*Math.PI*4+Math.PI)*c,m=t.scene.userData.hipsRestY??0,p=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperLeg),g=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperLeg),T=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightFoot),A=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftFoot);s&&(s.position.y=m,s.rotation.z=h*.18,s.rotation.y=h*.06),p&&(p.rotation.z=-h*.18,p.rotation.x=0,p.rotation.y=0),g&&(g.rotation.z=-h*.18,g.rotation.x=0,g.rotation.y=0),T&&(T.rotation.x=0,T.rotation.z=0,T.rotation.y=0),A&&(A.rotation.x=0,A.rotation.z=0,A.rotation.y=0),n&&(n.rotation.z=u*.1),i&&(i.rotation.z=-u*.07),o&&(o.rotation.z=Math.sin(l*Math.PI*4+Math.PI/4)*.07*c),a&&(a.rotation.z=E-u*.5,a.rotation.x=Math.abs(u)*.1),r&&(r.rotation.z=-E+u*.5,r.rotation.x=Math.abs(u)*.1)}}},U={idle:[],smile:["Smile","smile","Happy","happy","mouthSmile","Joy"],sad:["Sad","sad","Frown","frown","mouthFrown"],happy:["Smile","smile","Happy","happy","Joy","joy"],angry:["Angry","angry","Frown","frown","Mad"],surprised:["Surprised","surprised","Awe","awe","Oh","Shock"],thinking:["Thinking","thinking","Sad","Awe"],confused:["Confused","confused","Awe","Surprised"],sleep:["Sleep","sleep","Blink","eyesClosed"]},Z={idle:null,smile:"happy",happy:"happy",sad:"sad",angry:"angry",surprised:"surprised",thinking:"relaxed",confused:"surprised",sleep:"blink"},$=["Blink","blink","EyesClosed","eyesClosed","eyeBlink_L","eyeBlink"],pe=["mouthOpen","MouthOpen","jawOpen","JawOpen","jaw_open","mouth_open","viseme_O","viseme_aa","A","open"],ge=["Head","head","mixamorigHead","Bip01_Head","Bip001 Head","head_joint","HeadBone"],Ae=[/^bip_head/i,/^head$/i,/head_0/i],F=class F{constructor(){this.mixer=null,this.clips=[],this.currentAction=null,this.idleAction=null,this.vrm=null,this.morphMeshes=[],this.headBone=null,this.headBoneRestWorldQ=new y.Quaternion,this.lookCurrentDelta=new y.Quaternion,this.lookTargetDelta=new y.Quaternion,this.lookSettled=!0,this._tmpParentWorldQInv=new y.Quaternion,this._tmpDesiredWorldQ=new y.Quaternion,this.blinkTimer=null,this.idleTimer=null,this.randomLookTimeout=null,this._vrmIdleTime=0,this._gestureActive=!1,this._gestureElapsed=0,this._gestureDuration=0,this._gestureUpdateFn=null,this._pendingGesture=null}init(t){if(this.dispose(),this.vrm=t.vrm??null,this.mixer=new y.AnimationMixer(t.scene),this.clips=t.animations,this.morphMeshes=[],this.headBone=null,this.vrm){const e=this.vrm.humanoid.getNormalizedBoneNode(f.VRMHumanBoneName.Head);e&&(this.headBone=e,t.scene.updateWorldMatrix(!0,!0),this.headBone.getWorldQuaternion(this.headBoneRestWorldQ)),this._initVRMRestPose()}else t.scene.traverse(e=>{if(e instanceof y.Bone&&!this.headBone){const s=ge.includes(e.name),n=!s&&Ae.some(i=>i.test(e.name));(s||n)&&(this.headBone=e,t.scene.updateWorldMatrix(!0,!0),e.getWorldQuaternion(this.headBoneRestWorldQ))}(e instanceof y.Mesh||e instanceof y.SkinnedMesh)&&e.morphTargetDictionary&&Object.keys(e.morphTargetDictionary).length>0&&this.morphMeshes.push(e)})}update(t){if(this.mixer?.update(t),this._vrmIdleTime+=t,this._gestureActive?this._tickProceduralGesture(t):this._updateVRMProceduralIdle(this._vrmIdleTime),this.vrm?.update(t),this.headBone){if(!this.lookSettled){const s=1-Math.pow(1e-4,t);this.lookCurrentDelta.slerp(this.lookTargetDelta,s),this.lookCurrentDelta.angleTo(this.lookTargetDelta)<.01&&(this.lookCurrentDelta.copy(this.lookTargetDelta),this.lookSettled=!0)}this._tmpDesiredWorldQ.multiplyQuaternions(this.headBoneRestWorldQ,this.lookCurrentDelta);const e=this.headBone.parent;e?(e.getWorldQuaternion(this._tmpParentWorldQInv),this._tmpParentWorldQInv.invert(),this.headBone.quaternion.multiplyQuaternions(this._tmpParentWorldQInv,this._tmpDesiredWorldQ)):this.headBone.quaternion.copy(this._tmpDesiredWorldQ)}}play(t){const e=y.AnimationClip.findByName(this.clips,t);!e||!this.mixer||this._transitionTo(this.mixer.clipAction(e))}stop(){this.currentAction&&(this.currentAction.fadeOut(.3),this.currentAction=null,this.idleAction&&this.idleAction.fadeIn(.3).play())}_transitionTo(t,e=.3){this.currentAction!==t&&(this.currentAction?.fadeOut(e),t.reset().fadeIn(e).play(),this.currentAction=t)}startIdle(t=8e3){const e=this._findClip(/idle|breathing|float/i)??this.clips[0];e&&this.mixer&&(this.idleAction=this.mixer.clipAction(e),this.idleAction.setLoop(y.LoopRepeat,1/0),this.idleAction.play()),this.idleTimer=setInterval(()=>{this._randomIdleExpression()},t)}stopIdle(){this.idleAction?.stop(),this.idleAction=null,this.idleTimer&&(clearInterval(this.idleTimer),this.idleTimer=null)}_randomIdleExpression(){const t=["idle","smile","thinking"],e=t[Math.floor(Math.random()*t.length)];e!=="idle"&&(this.setExpression(e,.3),setTimeout(()=>this.setExpression("idle",0),1200))}startBlink(t=3500){this.blinkTimer=setInterval(()=>{this._doBlink()},t+Math.random()*1e3-500)}stopBlink(){this.blinkTimer&&(clearInterval(this.blinkTimer),this.blinkTimer=null)}async _doBlink(){this.vrm?.expressionManager?(this.vrm.expressionManager.setValue("blink",1),await this._delay(120),this.vrm.expressionManager.setValue("blink",0)):(this._setMorphTarget($,1),await this._delay(120),this._setMorphTarget($,0))}setExpression(t,e=1){if(this.vrm?.expressionManager){const n=this.vrm.expressionManager;for(const o of Object.values(Z))o&&n.setValue(o,0);const i=Z[t];i&&n.setValue(i,e);return}if(t==="idle"){for(const n of Object.values(U))this._setMorphTarget(n,0);return}const s=U[t];if(s.length){for(const[n,i]of Object.entries(U))n!==t&&n!=="idle"&&this._setMorphTarget(i,0);this._setMorphTarget(s,e)}}setMouthMorph(t){const e=Math.max(0,Math.min(1,t));if(this.vrm?.expressionManager){const s=this.vrm.expressionManager;for(const n of F._VRM_VISEMES)s.setValue(n,0);if(e>.01){const n=Math.floor(performance.now()/250)%F._VRM_VISEME_CYCLE.length,i=F._VRM_VISEME_CYCLE[n]??"aa";s.setValue(i,e)}return}this._setMorphTarget(pe,e)}playGesture(t){if(this.vrm){this._playVRMProceduralGesture(t);return}const e=this._findClip(new RegExp(t,"i"));if(e&&this.mixer){const s=this.mixer.clipAction(e);s.setLoop(y.LoopOnce,1),s.clampWhenFinished=!0,this._transitionTo(s),this.mixer.addEventListener("finished",n=>{n.action===s&&(this.stop(),this.mixer?.removeEventListener("finished",()=>{}))})}}_playVRMProceduralGesture(t){if(this.vrm){if(this._gestureActive){const e=this._gestureDuration*.82;this._gestureElapsed<e&&(this._gestureElapsed=e),this._pendingGesture=t;return}this._startGesture(t)}}_startGesture(t){const e=fe[t];if(!e||!this.vrm)return;const s=this.vrm;this._gestureActive=!0,this._gestureElapsed=0,this._gestureDuration=e.duration,this._gestureUpdateFn=n=>e.fn(n,s),this._pendingGesture=null}_tickProceduralGesture(t){if(!this._gestureUpdateFn)return;this._gestureElapsed+=t;const e=Math.min(this._gestureElapsed/this._gestureDuration,1);this._gestureUpdateFn(e),e>=1&&(this._gestureActive=!1,this._gestureUpdateFn=null,this._gestureElapsed=0,this._pendingGesture&&this._startGesture(this._pendingGesture))}lookAt(t,e){const s=new y.Euler(e*.6,t*.75,0,"YXZ");this.lookTargetDelta.setFromEuler(s),this.lookSettled=!1}lookForward(){this.stopRandomLook(),this.lookTargetDelta.identity(),this.lookSettled=!1}startRandomLook(){this.stopRandomLook();const t=()=>{const e=(Math.random()-.5)*1.4,s=(Math.random()-.5)*.8;this.lookAt(e,s),this.randomLookTimeout=setTimeout(t,1500+Math.random()*2e3)};t()}stopRandomLook(){this.randomLookTimeout&&(clearTimeout(this.randomLookTimeout),this.randomLookTimeout=null)}stopLook(){this.stopRandomLook(),this.lookTargetDelta.identity(),this.lookCurrentDelta.identity()}hasHeadBone(){return this.headBone!==null}_setMorphTarget(t,e){for(const s of this.morphMeshes){const n=s.morphTargetDictionary;if(!(!n||!s.morphTargetInfluences))for(const i of t){const o=n[i];if(o!==void 0){s.morphTargetInfluences[o]=e;break}}}}_initVRMRestPose(){if(!this.vrm)return;const t=this.vrm.humanoid,e=t.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),s=t.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm);e&&(e.rotation.z=Math.PI/6),s&&(s.rotation.z=-Math.PI/6);const n=t.getNormalizedBoneNode(f.VRMHumanBoneName.Hips);n&&(this.vrm.scene.userData.hipsRestY=n.position.y)}_updateVRMProceduralIdle(t){if(!this.vrm)return;const e=this.vrm.humanoid,s=e.getNormalizedBoneNode(f.VRMHumanBoneName.Hips);s&&(s.position.y=this.vrm.scene.userData.hipsRestY??0);const n=Math.sin(t*1.8),i=Math.sin(t*.7),o=e.getNormalizedBoneNode(f.VRMHumanBoneName.Spine),a=e.getNormalizedBoneNode(f.VRMHumanBoneName.Chest);o&&(o.rotation.z=i*.008),a&&(a.rotation.x=n*.015);const r=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightUpperArm),c=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftUpperArm);r&&(r.rotation.z=Math.PI/3.2+n*.018,r.rotation.y=0,r.rotation.x=0),c&&(c.rotation.z=-(Math.PI/3.2+n*.018),c.rotation.y=0,c.rotation.x=0);const u=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightLowerArm),h=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftLowerArm);u&&(u.rotation.order="XYZ",u.rotation.z=-.1,u.rotation.y=0,u.rotation.x=0),h&&(h.rotation.z=.1,h.rotation.y=0,h.rotation.x=0);const m=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightHand),p=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftHand);m&&(m.rotation.x=-.15,m.rotation.y=0,m.rotation.z=0),p&&(p.rotation.x=-.15,p.rotation.y=0,p.rotation.z=0);const g=.28+n*.06,T=[[f.VRMHumanBoneName.RightIndexProximal,f.VRMHumanBoneName.RightIndexIntermediate,f.VRMHumanBoneName.RightIndexDistal],[f.VRMHumanBoneName.RightMiddleProximal,f.VRMHumanBoneName.RightMiddleIntermediate,f.VRMHumanBoneName.RightMiddleDistal],[f.VRMHumanBoneName.RightRingProximal,f.VRMHumanBoneName.RightRingIntermediate,f.VRMHumanBoneName.RightRingDistal],[f.VRMHumanBoneName.RightLittleProximal,f.VRMHumanBoneName.RightLittleIntermediate,f.VRMHumanBoneName.RightLittleDistal]];for(const[S,M,B]of T){const w=e.getNormalizedBoneNode(S),L=e.getNormalizedBoneNode(M),I=e.getNormalizedBoneNode(B);w&&(w.rotation.z=g,w.rotation.x=0),L&&(L.rotation.z=g*.8,L.rotation.x=0),I&&(I.rotation.z=g*.5,I.rotation.x=0)}const A=[[f.VRMHumanBoneName.LeftIndexProximal,f.VRMHumanBoneName.LeftIndexIntermediate,f.VRMHumanBoneName.LeftIndexDistal],[f.VRMHumanBoneName.LeftMiddleProximal,f.VRMHumanBoneName.LeftMiddleIntermediate,f.VRMHumanBoneName.LeftMiddleDistal],[f.VRMHumanBoneName.LeftRingProximal,f.VRMHumanBoneName.LeftRingIntermediate,f.VRMHumanBoneName.LeftRingDistal],[f.VRMHumanBoneName.LeftLittleProximal,f.VRMHumanBoneName.LeftLittleIntermediate,f.VRMHumanBoneName.LeftLittleDistal]];for(const[S,M,B]of A){const w=e.getNormalizedBoneNode(S),L=e.getNormalizedBoneNode(M),I=e.getNormalizedBoneNode(B);w&&(w.rotation.z=-g,w.rotation.x=0),L&&(L.rotation.z=-g*.8,L.rotation.x=0),I&&(I.rotation.z=-g*.5,I.rotation.x=0)}const R=e.getNormalizedBoneNode(f.VRMHumanBoneName.RightThumbProximal),x=e.getNormalizedBoneNode(f.VRMHumanBoneName.LeftThumbProximal);R&&(R.rotation.z=-.3,R.rotation.x=.2),x&&(x.rotation.z=.3,x.rotation.x=.2)}_findClip(t){return this.clips.find(e=>t.test(e.name))}_delay(t){return new Promise(e=>setTimeout(e,t))}dispose(){this.stopBlink(),this.stopIdle(),this.stopRandomLook(),this.stopLook(),this.mixer?.stopAllAction(),this.mixer=null,this.vrm=null,this.clips=[],this.morphMeshes=[],this.headBone=null,this.lookCurrentDelta.identity(),this.lookTargetDelta.identity(),this.lookSettled=!0,this.currentAction=null,this.idleAction=null,this._gestureActive=!1,this._gestureUpdateFn=null,this._gestureElapsed=0,this._pendingGesture=null}};F._VRM_VISEME_CYCLE=["aa","aa","oh","aa","ih","aa","ee","ou"],F._VRM_VISEMES=["aa","ih","ou","ee","oh"];let W=F;class Te{constructor(){this.context=null,this.source=null,this.analyser=null,this.gainNode=null,this.dataArray=new Float32Array(0),this._endedCallback=null}_ctx(){return(!this.context||this.context.state==="closed")&&(this.context=new AudioContext),this.context}async play(t){const e=this._ctx();e.state==="suspended"&&await e.resume(),this._stopSource();const s=await this._toBuffer(e,t);return this.analyser=e.createAnalyser(),this.analyser.fftSize=512,this.analyser.smoothingTimeConstant=.6,this.dataArray=new Float32Array(this.analyser.frequencyBinCount),this.gainNode=e.createGain(),this.source=e.createBufferSource(),this.source.buffer=s,this.source.connect(this.analyser),this.analyser.connect(this.gainNode),this.gainNode.connect(e.destination),new Promise(n=>{this.source.onended=()=>{this._endedCallback?.(),n()},this.source.start(0)})}pause(){this.context?.suspend()}async resume(){await this.context?.resume()}stop(){this._stopSource()}getAmplitude(){if(!this.analyser||this.dataArray.length===0)return 0;this.analyser.getFloatTimeDomainData(this.dataArray);let t=0;for(const e of this.dataArray)t+=e*e;return Math.sqrt(t/this.dataArray.length)}set onEnded(t){this._endedCallback=t}async _toBuffer(t,e){if(e instanceof AudioBuffer)return e;if(typeof e=="string"){const n=await(await fetch(e)).arrayBuffer();return t.decodeAudioData(n)}return t.decodeAudioData(e.slice(0))}_stopSource(){try{this.source?.stop()}catch{}this.source?.disconnect(),this.source=null}dispose(){this._stopSource(),this.context?.close(),this.context=null,this.analyser=null,this.gainNode=null}}const Me={sil:0,PP:.05,FF:.2,TH:.25,DD:.3,kk:.35,CH:.5,SS:.2,nn:.15,RR:.4,aa:1,E:.7,ih:.5,oh:.85,ou:.6};class Re{constructor(t,e){this.audioEngine=t,this.onMouth=e,this.rafId=0}setViseme(t){this.onMouth(Me[t]??0)}setMouth(t){this.onMouth(Math.max(0,Math.min(1,t)))}setVolume(t){this.onMouth(Math.max(0,Math.min(1,t)))}startAutoSync(){this.stopAutoSync();const t=()=>{const e=this.audioEngine.getAmplitude();this.onMouth(Math.min(1,e*10)),this.rafId=requestAnimationFrame(t)};this.rafId=requestAnimationFrame(t)}stopAutoSync(){cancelAnimationFrame(this.rafId),this.rafId=0,this.onMouth(0)}}function J(l,t){if(t===d.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),l;if(t===d.TriangleFanDrawMode||t===d.TriangleStripDrawMode){let e=l.getIndex();if(e===null){const o=[],a=l.getAttribute("position");if(a!==void 0){for(let r=0;r<a.count;r++)o.push(r);l.setIndex(o),e=l.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),l}const s=e.count-2,n=[];if(t===d.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(e.getX(0)),n.push(e.getX(o)),n.push(e.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(e.getX(o)),n.push(e.getX(o+1)),n.push(e.getX(o+2))):(n.push(e.getX(o+2)),n.push(e.getX(o+1)),n.push(e.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const i=l.clone();return i.setIndex(n),i.clearGroups(),i}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),l}class ee extends d.Loader{constructor(t){super(t),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new Se(e)}),this.register(function(e){return new Le(e)}),this.register(function(e){return new Pe(e)}),this.register(function(e){return new ve(e)}),this.register(function(e){return new Fe(e)}),this.register(function(e){return new we(e)}),this.register(function(e){return new Be(e)}),this.register(function(e){return new be(e)}),this.register(function(e){return new Ie(e)}),this.register(function(e){return new ye(e)}),this.register(function(e){return new ke(e)}),this.register(function(e){return new Ee(e)}),this.register(function(e){return new Ce(e)}),this.register(function(e){return new He(e)}),this.register(function(e){return new Ne(e)}),this.register(function(e){return new De(e)}),this.register(function(e){return new Oe(e)})}load(t,e,s,n){const i=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const c=d.LoaderUtils.extractUrlBase(t);o=d.LoaderUtils.resolveURL(c,this.path)}else o=d.LoaderUtils.extractUrlBase(t);this.manager.itemStart(t);const a=function(c){n?n(c):console.error(c),i.manager.itemError(t),i.manager.itemEnd(t)},r=new d.FileLoader(this.manager);r.setPath(this.path),r.setResponseType("arraybuffer"),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(c){try{i.parse(c,o,function(u){e(u),i.manager.itemEnd(t)},a)}catch(u){a(u)}},s,a)}setDRACOLoader(t){return this.dracoLoader=t,this}setDDSLoader(){throw new Error('THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".')}setKTX2Loader(t){return this.ktx2Loader=t,this}setMeshoptDecoder(t){return this.meshoptDecoder=t,this}register(t){return this.pluginCallbacks.indexOf(t)===-1&&this.pluginCallbacks.push(t),this}unregister(t){return this.pluginCallbacks.indexOf(t)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(t),1),this}parse(t,e,s,n){let i;const o={},a={},r=new TextDecoder;if(typeof t=="string")i=JSON.parse(t);else if(t instanceof ArrayBuffer)if(r.decode(new Uint8Array(t,0,4))===oe){try{o[_.KHR_BINARY_GLTF]=new Ve(t)}catch(h){n&&n(h);return}i=JSON.parse(o[_.KHR_BINARY_GLTF].content)}else i=JSON.parse(r.decode(t));else i=t;if(i.asset===void 0||i.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const c=new Je(i,{path:e||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const h=this.pluginCallbacks[u](c);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[h.name]=h,o[h.name]=!0}if(i.extensionsUsed)for(let u=0;u<i.extensionsUsed.length;++u){const h=i.extensionsUsed[u],m=i.extensionsRequired||[];switch(h){case _.KHR_MATERIALS_UNLIT:o[h]=new _e;break;case _.KHR_DRACO_MESH_COMPRESSION:o[h]=new ze(i,this.dracoLoader);break;case _.KHR_TEXTURE_TRANSFORM:o[h]=new Ge;break;case _.KHR_MESH_QUANTIZATION:o[h]=new Ue;break;default:m.indexOf(h)>=0&&a[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}c.setExtensions(o),c.setPlugins(a),c.parse(s,n)}parseAsync(t,e){const s=this;return new Promise(function(n,i){s.parse(t,e,n,i)})}}function xe(){let l={};return{get:function(t){return l[t]},add:function(t,e){l[t]=e},remove:function(t){delete l[t]},removeAll:function(){l={}}}}const _={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Ne{constructor(t){this.parser=t,this.name=_.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const t=this.parser,e=this.parser.json.nodes||[];for(let s=0,n=e.length;s<n;s++){const i=e[s];i.extensions&&i.extensions[this.name]&&i.extensions[this.name].light!==void 0&&t._addNodeRef(this.cache,i.extensions[this.name].light)}}_loadLight(t){const e=this.parser,s="light:"+t;let n=e.cache.get(s);if(n)return n;const i=e.json,r=((i.extensions&&i.extensions[this.name]||{}).lights||[])[t];let c;const u=new d.Color(16777215);r.color!==void 0&&u.setRGB(r.color[0],r.color[1],r.color[2],d.LinearSRGBColorSpace);const h=r.range!==void 0?r.range:0;switch(r.type){case"directional":c=new d.DirectionalLight(u),c.target.position.set(0,0,-1),c.add(c.target);break;case"point":c=new d.PointLight(u),c.distance=h;break;case"spot":c=new d.SpotLight(u),c.distance=h,r.spot=r.spot||{},r.spot.innerConeAngle=r.spot.innerConeAngle!==void 0?r.spot.innerConeAngle:0,r.spot.outerConeAngle=r.spot.outerConeAngle!==void 0?r.spot.outerConeAngle:Math.PI/4,c.angle=r.spot.outerConeAngle,c.penumbra=1-r.spot.innerConeAngle/r.spot.outerConeAngle,c.target.position.set(0,0,-1),c.add(c.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+r.type)}return c.position.set(0,0,0),c.decay=2,H(c,r),r.intensity!==void 0&&(c.intensity=r.intensity),c.name=e.createUniqueName(r.name||"light_"+t),n=Promise.resolve(c),e.cache.add(s,n),n}getDependency(t,e){if(t==="light")return this._loadLight(e)}createNodeAttachment(t){const e=this,s=this.parser,i=s.json.nodes[t],a=(i.extensions&&i.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(r){return s._getNodeRef(e.cache,a,r)})}}class _e{constructor(){this.name=_.KHR_MATERIALS_UNLIT}getMaterialType(){return d.MeshBasicMaterial}extendParams(t,e,s){const n=[];t.color=new d.Color(1,1,1),t.opacity=1;const i=e.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){const o=i.baseColorFactor;t.color.setRGB(o[0],o[1],o[2],d.LinearSRGBColorSpace),t.opacity=o[3]}i.baseColorTexture!==void 0&&n.push(s.assignTexture(t,"map",i.baseColorTexture,d.SRGBColorSpace))}return Promise.all(n)}}class ye{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(t,e){const n=this.parser.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name].emissiveStrength;return i!==void 0&&(e.emissiveIntensity=i),Promise.resolve()}}class Se{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_CLEARCOAT}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];if(o.clearcoatFactor!==void 0&&(e.clearcoat=o.clearcoatFactor),o.clearcoatTexture!==void 0&&i.push(s.assignTexture(e,"clearcoatMap",o.clearcoatTexture)),o.clearcoatRoughnessFactor!==void 0&&(e.clearcoatRoughness=o.clearcoatRoughnessFactor),o.clearcoatRoughnessTexture!==void 0&&i.push(s.assignTexture(e,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),o.clearcoatNormalTexture!==void 0&&(i.push(s.assignTexture(e,"clearcoatNormalMap",o.clearcoatNormalTexture)),o.clearcoatNormalTexture.scale!==void 0)){const a=o.clearcoatNormalTexture.scale;e.clearcoatNormalScale=new d.Vector2(a,a)}return Promise.all(i)}}class Le{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_DISPERSION}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const n=this.parser.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return e.dispersion=i.dispersion!==void 0?i.dispersion:0,Promise.resolve()}}class Ee{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_IRIDESCENCE}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.iridescenceFactor!==void 0&&(e.iridescence=o.iridescenceFactor),o.iridescenceTexture!==void 0&&i.push(s.assignTexture(e,"iridescenceMap",o.iridescenceTexture)),o.iridescenceIor!==void 0&&(e.iridescenceIOR=o.iridescenceIor),e.iridescenceThicknessRange===void 0&&(e.iridescenceThicknessRange=[100,400]),o.iridescenceThicknessMinimum!==void 0&&(e.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),o.iridescenceThicknessMaximum!==void 0&&(e.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),o.iridescenceThicknessTexture!==void 0&&i.push(s.assignTexture(e,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(i)}}class we{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_SHEEN}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[];e.sheenColor=new d.Color(0,0,0),e.sheenRoughness=0,e.sheen=1;const o=n.extensions[this.name];if(o.sheenColorFactor!==void 0){const a=o.sheenColorFactor;e.sheenColor.setRGB(a[0],a[1],a[2],d.LinearSRGBColorSpace)}return o.sheenRoughnessFactor!==void 0&&(e.sheenRoughness=o.sheenRoughnessFactor),o.sheenColorTexture!==void 0&&i.push(s.assignTexture(e,"sheenColorMap",o.sheenColorTexture,d.SRGBColorSpace)),o.sheenRoughnessTexture!==void 0&&i.push(s.assignTexture(e,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(i)}}class Be{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_TRANSMISSION}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.transmissionFactor!==void 0&&(e.transmission=o.transmissionFactor),o.transmissionTexture!==void 0&&i.push(s.assignTexture(e,"transmissionMap",o.transmissionTexture)),Promise.all(i)}}class be{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_VOLUME}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];e.thickness=o.thicknessFactor!==void 0?o.thicknessFactor:0,o.thicknessTexture!==void 0&&i.push(s.assignTexture(e,"thicknessMap",o.thicknessTexture)),e.attenuationDistance=o.attenuationDistance||1/0;const a=o.attenuationColor||[1,1,1];return e.attenuationColor=new d.Color().setRGB(a[0],a[1],a[2],d.LinearSRGBColorSpace),Promise.all(i)}}class Ie{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_IOR}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const n=this.parser.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=n.extensions[this.name];return e.ior=i.ior!==void 0?i.ior:1.5,Promise.resolve()}}class ke{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_SPECULAR}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];e.specularIntensity=o.specularFactor!==void 0?o.specularFactor:1,o.specularTexture!==void 0&&i.push(s.assignTexture(e,"specularIntensityMap",o.specularTexture));const a=o.specularColorFactor||[1,1,1];return e.specularColor=new d.Color().setRGB(a[0],a[1],a[2],d.LinearSRGBColorSpace),o.specularColorTexture!==void 0&&i.push(s.assignTexture(e,"specularColorMap",o.specularColorTexture,d.SRGBColorSpace)),Promise.all(i)}}class He{constructor(t){this.parser=t,this.name=_.EXT_MATERIALS_BUMP}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return e.bumpScale=o.bumpFactor!==void 0?o.bumpFactor:1,o.bumpTexture!==void 0&&i.push(s.assignTexture(e,"bumpMap",o.bumpTexture)),Promise.all(i)}}class Ce{constructor(t){this.parser=t,this.name=_.KHR_MATERIALS_ANISOTROPY}getMaterialType(t){const s=this.parser.json.materials[t];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(t,e){const s=this.parser,n=s.json.materials[t];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const i=[],o=n.extensions[this.name];return o.anisotropyStrength!==void 0&&(e.anisotropy=o.anisotropyStrength),o.anisotropyRotation!==void 0&&(e.anisotropyRotation=o.anisotropyRotation),o.anisotropyTexture!==void 0&&i.push(s.assignTexture(e,"anisotropyMap",o.anisotropyTexture)),Promise.all(i)}}class Pe{constructor(t){this.parser=t,this.name=_.KHR_TEXTURE_BASISU}loadTexture(t){const e=this.parser,s=e.json,n=s.textures[t];if(!n.extensions||!n.extensions[this.name])return null;const i=n.extensions[this.name],o=e.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return e.loadTextureImage(t,i.source,o)}}class ve{constructor(t){this.parser=t,this.name=_.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(t){const e=this.name,s=this.parser,n=s.json,i=n.textures[t];if(!i.extensions||!i.extensions[e])return null;const o=i.extensions[e],a=n.images[o.source];let r=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(r=c)}return this.detectSupport().then(function(c){if(c)return s.loadTextureImage(t,o.source,r);if(n.extensionsRequired&&n.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(t)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(t){const e=new Image;e.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",e.onload=e.onerror=function(){t(e.height===1)}})),this.isSupported}}class Fe{constructor(t){this.parser=t,this.name=_.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(t){const e=this.name,s=this.parser,n=s.json,i=n.textures[t];if(!i.extensions||!i.extensions[e])return null;const o=i.extensions[e],a=n.images[o.source];let r=s.textureLoader;if(a.uri){const c=s.options.manager.getHandler(a.uri);c!==null&&(r=c)}return this.detectSupport().then(function(c){if(c)return s.loadTextureImage(t,o.source,r);if(n.extensionsRequired&&n.extensionsRequired.indexOf(e)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return s.loadTexture(t)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(t){const e=new Image;e.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",e.onload=e.onerror=function(){t(e.height===1)}})),this.isSupported}}class De{constructor(t){this.name=_.EXT_MESHOPT_COMPRESSION,this.parser=t}loadBufferView(t){const e=this.parser.json,s=e.bufferViews[t];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],i=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(e.extensionsRequired&&e.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return i.then(function(a){const r=n.byteOffset||0,c=n.byteLength||0,u=n.count,h=n.byteStride,m=new Uint8Array(a,r,c);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,h,m,n.mode,n.filter).then(function(p){return p.buffer}):o.ready.then(function(){const p=new ArrayBuffer(u*h);return o.decodeGltfBuffer(new Uint8Array(p),u,h,m,n.mode,n.filter),p})})}else return null}}class Oe{constructor(t){this.name=_.EXT_MESH_GPU_INSTANCING,this.parser=t}createNodeMesh(t){const e=this.parser.json,s=e.nodes[t];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=e.meshes[s.mesh];for(const c of n.primitives)if(c.mode!==k.TRIANGLES&&c.mode!==k.TRIANGLE_STRIP&&c.mode!==k.TRIANGLE_FAN&&c.mode!==void 0)return null;const o=s.extensions[this.name].attributes,a=[],r={};for(const c in o)a.push(this.parser.getDependency("accessor",o[c]).then(u=>(r[c]=u,r[c])));return a.length<1?null:(a.push(this.parser.createNodeMesh(t)),Promise.all(a).then(c=>{const u=c.pop(),h=u.isGroup?u.children:[u],m=c[0].count,p=[];for(const g of h){const T=new d.Matrix4,A=new d.Vector3,R=new d.Quaternion,x=new d.Vector3(1,1,1),S=new d.InstancedMesh(g.geometry,g.material,m);for(let M=0;M<m;M++)r.TRANSLATION&&A.fromBufferAttribute(r.TRANSLATION,M),r.ROTATION&&R.fromBufferAttribute(r.ROTATION,M),r.SCALE&&x.fromBufferAttribute(r.SCALE,M),S.setMatrixAt(M,T.compose(A,R,x));for(const M in r)if(M==="_COLOR_0"){const B=r[M];S.instanceColor=new d.InstancedBufferAttribute(B.array,B.itemSize,B.normalized)}else M!=="TRANSLATION"&&M!=="ROTATION"&&M!=="SCALE"&&g.geometry.setAttribute(M,r[M]);d.Object3D.prototype.copy.call(S,g),this.parser.assignFinalMaterial(S),p.push(S)}return u.isGroup?(u.clear(),u.add(...p),u):p[0]}))}}const oe="glTF",O=12,te={JSON:1313821514,BIN:5130562};class Ve{constructor(t){this.name=_.KHR_BINARY_GLTF,this.content=null,this.body=null;const e=new DataView(t,0,O),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(t.slice(0,4))),version:e.getUint32(4,!0),length:e.getUint32(8,!0)},this.header.magic!==oe)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-O,i=new DataView(t,O);let o=0;for(;o<n;){const a=i.getUint32(o,!0);o+=4;const r=i.getUint32(o,!0);if(o+=4,r===te.JSON){const c=new Uint8Array(t,O+o,a);this.content=s.decode(c)}else if(r===te.BIN){const c=O+o;this.body=t.slice(c,c+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class ze{constructor(t,e){if(!e)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=_.KHR_DRACO_MESH_COMPRESSION,this.json=t,this.dracoLoader=e,this.dracoLoader.preload()}decodePrimitive(t,e){const s=this.json,n=this.dracoLoader,i=t.extensions[this.name].bufferView,o=t.extensions[this.name].attributes,a={},r={},c={};for(const u in o){const h=Y[u]||u.toLowerCase();a[h]=o[u]}for(const u in t.attributes){const h=Y[u]||u.toLowerCase();if(o[u]!==void 0){const m=s.accessors[t.attributes[u]],p=D[m.componentType];c[h]=p.name,r[h]=m.normalized===!0}}return e.getDependency("bufferView",i).then(function(u){return new Promise(function(h,m){n.decodeDracoFile(u,function(p){for(const g in p.attributes){const T=p.attributes[g],A=r[g];A!==void 0&&(T.normalized=A)}h(p)},a,c,d.LinearSRGBColorSpace,m)})})}}class Ge{constructor(){this.name=_.KHR_TEXTURE_TRANSFORM}extendTexture(t,e){return(e.texCoord===void 0||e.texCoord===t.channel)&&e.offset===void 0&&e.rotation===void 0&&e.scale===void 0||(t=t.clone(),e.texCoord!==void 0&&(t.channel=e.texCoord),e.offset!==void 0&&t.offset.fromArray(e.offset),e.rotation!==void 0&&(t.rotation=e.rotation),e.scale!==void 0&&t.repeat.fromArray(e.scale),t.needsUpdate=!0),t}}class Ue{constructor(){this.name=_.KHR_MESH_QUANTIZATION}}class re extends d.Interpolant{constructor(t,e,s,n){super(t,e,s,n)}copySampleValue_(t){const e=this.resultBuffer,s=this.sampleValues,n=this.valueSize,i=t*n*3+n;for(let o=0;o!==n;o++)e[o]=s[i+o];return e}interpolate_(t,e,s,n){const i=this.resultBuffer,o=this.sampleValues,a=this.valueSize,r=a*2,c=a*3,u=n-e,h=(s-e)/u,m=h*h,p=m*h,g=t*c,T=g-c,A=-2*p+3*m,R=p-m,x=1-A,S=R-m+h;for(let M=0;M!==a;M++){const B=o[T+M+a],w=o[T+M+r]*u,L=o[g+M+a],I=o[g+M]*u;i[M]=x*B+S*w+A*L+R*I}return i}}const je=new d.Quaternion;class Ke extends re{interpolate_(t,e,s,n){const i=super.interpolate_(t,e,s,n);return je.fromArray(i).normalize().toArray(i),i}}const k={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},D={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},ne={9728:d.NearestFilter,9729:d.LinearFilter,9984:d.NearestMipmapNearestFilter,9985:d.LinearMipmapNearestFilter,9986:d.NearestMipmapLinearFilter,9987:d.LinearMipmapLinearFilter},se={33071:d.ClampToEdgeWrapping,33648:d.MirroredRepeatWrapping,10497:d.RepeatWrapping},j={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Y={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},P={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Xe={CUBICSPLINE:void 0,LINEAR:d.InterpolateLinear,STEP:d.InterpolateDiscrete},K={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function We(l){return l.DefaultMaterial===void 0&&(l.DefaultMaterial=new d.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:d.FrontSide})),l.DefaultMaterial}function v(l,t,e){for(const s in e.extensions)l[s]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[s]=e.extensions[s])}function H(l,t){t.extras!==void 0&&(typeof t.extras=="object"?Object.assign(l.userData,t.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+t.extras))}function Ye(l,t,e){let s=!1,n=!1,i=!1;for(let c=0,u=t.length;c<u;c++){const h=t[c];if(h.POSITION!==void 0&&(s=!0),h.NORMAL!==void 0&&(n=!0),h.COLOR_0!==void 0&&(i=!0),s&&n&&i)break}if(!s&&!n&&!i)return Promise.resolve(l);const o=[],a=[],r=[];for(let c=0,u=t.length;c<u;c++){const h=t[c];if(s){const m=h.POSITION!==void 0?e.getDependency("accessor",h.POSITION):l.attributes.position;o.push(m)}if(n){const m=h.NORMAL!==void 0?e.getDependency("accessor",h.NORMAL):l.attributes.normal;a.push(m)}if(i){const m=h.COLOR_0!==void 0?e.getDependency("accessor",h.COLOR_0):l.attributes.color;r.push(m)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(r)]).then(function(c){const u=c[0],h=c[1],m=c[2];return s&&(l.morphAttributes.position=u),n&&(l.morphAttributes.normal=h),i&&(l.morphAttributes.color=m),l.morphTargetsRelative=!0,l})}function Qe(l,t){if(l.updateMorphTargets(),t.weights!==void 0)for(let e=0,s=t.weights.length;e<s;e++)l.morphTargetInfluences[e]=t.weights[e];if(t.extras&&Array.isArray(t.extras.targetNames)){const e=t.extras.targetNames;if(l.morphTargetInfluences.length===e.length){l.morphTargetDictionary={};for(let s=0,n=e.length;s<n;s++)l.morphTargetDictionary[e[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function qe(l){let t;const e=l.extensions&&l.extensions[_.KHR_DRACO_MESH_COMPRESSION];if(e?t="draco:"+e.bufferView+":"+e.indices+":"+X(e.attributes):t=l.indices+":"+X(l.attributes)+":"+l.mode,l.targets!==void 0)for(let s=0,n=l.targets.length;s<n;s++)t+=":"+X(l.targets[s]);return t}function X(l){let t="";const e=Object.keys(l).sort();for(let s=0,n=e.length;s<n;s++)t+=e[s]+":"+l[e[s]]+";";return t}function Q(l){switch(l){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function Ze(l){return l.search(/\.jpe?g($|\?)/i)>0||l.search(/^data\:image\/jpeg/)===0?"image/jpeg":l.search(/\.webp($|\?)/i)>0||l.search(/^data\:image\/webp/)===0?"image/webp":"image/png"}const $e=new d.Matrix4;class Je{constructor(t={},e={}){this.json=t,this.extensions={},this.plugins={},this.options=e,this.cache=new xe,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=!1,i=-1;typeof navigator<"u"&&(s=/^((?!chrome|android).)*safari/i.test(navigator.userAgent)===!0,n=navigator.userAgent.indexOf("Firefox")>-1,i=n?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),typeof createImageBitmap>"u"||s||n&&i<98?this.textureLoader=new d.TextureLoader(this.options.manager):this.textureLoader=new d.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(t){this.extensions=t}setPlugins(t){this.plugins=t}parse(t,e){const s=this,n=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const a={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return v(i,a,n),H(a,n),Promise.all(s._invokeAll(function(r){return r.afterRoot&&r.afterRoot(a)})).then(function(){for(const r of a.scenes)r.updateMatrixWorld();t(a)})}).catch(e)}_markDefs(){const t=this.json.nodes||[],e=this.json.skins||[],s=this.json.meshes||[];for(let n=0,i=e.length;n<i;n++){const o=e[n].joints;for(let a=0,r=o.length;a<r;a++)t[o[a]].isBone=!0}for(let n=0,i=t.length;n<i;n++){const o=t[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(t,e){e!==void 0&&(t.refs[e]===void 0&&(t.refs[e]=t.uses[e]=0),t.refs[e]++)}_getNodeRef(t,e,s){if(t.refs[e]<=1)return s;const n=s.clone(),i=(o,a)=>{const r=this.associations.get(o);r!=null&&this.associations.set(a,r);for(const[c,u]of o.children.entries())i(u,a.children[c])};return i(s,n),n.name+="_instance_"+t.uses[e]++,n}_invokeOne(t){const e=Object.values(this.plugins);e.push(this);for(let s=0;s<e.length;s++){const n=t(e[s]);if(n)return n}return null}_invokeAll(t){const e=Object.values(this.plugins);e.unshift(this);const s=[];for(let n=0;n<e.length;n++){const i=t(e[n]);i&&s.push(i)}return s}getDependency(t,e){const s=t+":"+e;let n=this.cache.get(s);if(!n){switch(t){case"scene":n=this.loadScene(e);break;case"node":n=this._invokeOne(function(i){return i.loadNode&&i.loadNode(e)});break;case"mesh":n=this._invokeOne(function(i){return i.loadMesh&&i.loadMesh(e)});break;case"accessor":n=this.loadAccessor(e);break;case"bufferView":n=this._invokeOne(function(i){return i.loadBufferView&&i.loadBufferView(e)});break;case"buffer":n=this.loadBuffer(e);break;case"material":n=this._invokeOne(function(i){return i.loadMaterial&&i.loadMaterial(e)});break;case"texture":n=this._invokeOne(function(i){return i.loadTexture&&i.loadTexture(e)});break;case"skin":n=this.loadSkin(e);break;case"animation":n=this._invokeOne(function(i){return i.loadAnimation&&i.loadAnimation(e)});break;case"camera":n=this.loadCamera(e);break;default:if(n=this._invokeOne(function(i){return i!=this&&i.getDependency&&i.getDependency(t,e)}),!n)throw new Error("Unknown type: "+t);break}this.cache.add(s,n)}return n}getDependencies(t){let e=this.cache.get(t);if(!e){const s=this,n=this.json[t+(t==="mesh"?"es":"s")]||[];e=Promise.all(n.map(function(i,o){return s.getDependency(t,o)})),this.cache.add(t,e)}return e}loadBuffer(t){const e=this.json.buffers[t],s=this.fileLoader;if(e.type&&e.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+e.type+" buffer type is not supported.");if(e.uri===void 0&&t===0)return Promise.resolve(this.extensions[_.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(i,o){s.load(d.LoaderUtils.resolveURL(e.uri,n.path),i,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+e.uri+'".'))})})}loadBufferView(t){const e=this.json.bufferViews[t];return this.getDependency("buffer",e.buffer).then(function(s){const n=e.byteLength||0,i=e.byteOffset||0;return s.slice(i,i+n)})}loadAccessor(t){const e=this,s=this.json,n=this.json.accessors[t];if(n.bufferView===void 0&&n.sparse===void 0){const o=j[n.type],a=D[n.componentType],r=n.normalized===!0,c=new a(n.count*o);return Promise.resolve(new d.BufferAttribute(c,o,r))}const i=[];return n.bufferView!==void 0?i.push(this.getDependency("bufferView",n.bufferView)):i.push(null),n.sparse!==void 0&&(i.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),i.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(i).then(function(o){const a=o[0],r=j[n.type],c=D[n.componentType],u=c.BYTES_PER_ELEMENT,h=u*r,m=n.byteOffset||0,p=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,g=n.normalized===!0;let T,A;if(p&&p!==h){const R=Math.floor(m/p),x="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+R+":"+n.count;let S=e.cache.get(x);S||(T=new c(a,R*p,n.count*p/u),S=new d.InterleavedBuffer(T,p/u),e.cache.add(x,S)),A=new d.InterleavedBufferAttribute(S,r,m%p/u,g)}else a===null?T=new c(n.count*r):T=new c(a,m,n.count*r),A=new d.BufferAttribute(T,r,g);if(n.sparse!==void 0){const R=j.SCALAR,x=D[n.sparse.indices.componentType],S=n.sparse.indices.byteOffset||0,M=n.sparse.values.byteOffset||0,B=new x(o[1],S,n.sparse.count*R),w=new c(o[2],M,n.sparse.count*r);a!==null&&(A=new d.BufferAttribute(A.array.slice(),A.itemSize,A.normalized));for(let L=0,I=B.length;L<I;L++){const C=B[L];if(A.setX(C,w[L*r]),r>=2&&A.setY(C,w[L*r+1]),r>=3&&A.setZ(C,w[L*r+2]),r>=4&&A.setW(C,w[L*r+3]),r>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return A})}loadTexture(t){const e=this.json,s=this.options,i=e.textures[t].source,o=e.images[i];let a=this.textureLoader;if(o.uri){const r=s.manager.getHandler(o.uri);r!==null&&(a=r)}return this.loadTextureImage(t,i,a)}loadTextureImage(t,e,s){const n=this,i=this.json,o=i.textures[t],a=i.images[e],r=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[r])return this.textureCache[r];const c=this.loadImageSource(e,s).then(function(u){u.flipY=!1,u.name=o.name||a.name||"",u.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(u.name=a.uri);const m=(i.samplers||{})[o.sampler]||{};return u.magFilter=ne[m.magFilter]||d.LinearFilter,u.minFilter=ne[m.minFilter]||d.LinearMipmapLinearFilter,u.wrapS=se[m.wrapS]||d.RepeatWrapping,u.wrapT=se[m.wrapT]||d.RepeatWrapping,n.associations.set(u,{textures:t}),u}).catch(function(){return null});return this.textureCache[r]=c,c}loadImageSource(t,e){const s=this,n=this.json,i=this.options;if(this.sourceCache[t]!==void 0)return this.sourceCache[t].then(h=>h.clone());const o=n.images[t],a=self.URL||self.webkitURL;let r=o.uri||"",c=!1;if(o.bufferView!==void 0)r=s.getDependency("bufferView",o.bufferView).then(function(h){c=!0;const m=new Blob([h],{type:o.mimeType});return r=a.createObjectURL(m),r});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+t+" is missing URI and bufferView");const u=Promise.resolve(r).then(function(h){return new Promise(function(m,p){let g=m;e.isImageBitmapLoader===!0&&(g=function(T){const A=new d.Texture(T);A.needsUpdate=!0,m(A)}),e.load(d.LoaderUtils.resolveURL(h,i.path),g,void 0,p)})}).then(function(h){return c===!0&&a.revokeObjectURL(r),H(h,o),h.userData.mimeType=o.mimeType||Ze(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",r),h});return this.sourceCache[t]=u,u}assignTexture(t,e,s,n){const i=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),i.extensions[_.KHR_TEXTURE_TRANSFORM]){const a=s.extensions!==void 0?s.extensions[_.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const r=i.associations.get(o);o=i.extensions[_.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),i.associations.set(o,r)}}return n!==void 0&&(o.colorSpace=n),t[e]=o,o})}assignFinalMaterial(t){const e=t.geometry;let s=t.material;const n=e.attributes.tangent===void 0,i=e.attributes.color!==void 0,o=e.attributes.normal===void 0;if(t.isPoints){const a="PointsMaterial:"+s.uuid;let r=this.cache.get(a);r||(r=new d.PointsMaterial,d.Material.prototype.copy.call(r,s),r.color.copy(s.color),r.map=s.map,r.sizeAttenuation=!1,this.cache.add(a,r)),s=r}else if(t.isLine){const a="LineBasicMaterial:"+s.uuid;let r=this.cache.get(a);r||(r=new d.LineBasicMaterial,d.Material.prototype.copy.call(r,s),r.color.copy(s.color),r.map=s.map,this.cache.add(a,r)),s=r}if(n||i||o){let a="ClonedMaterial:"+s.uuid+":";n&&(a+="derivative-tangents:"),i&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let r=this.cache.get(a);r||(r=s.clone(),i&&(r.vertexColors=!0),o&&(r.flatShading=!0),n&&(r.normalScale&&(r.normalScale.y*=-1),r.clearcoatNormalScale&&(r.clearcoatNormalScale.y*=-1)),this.cache.add(a,r),this.associations.set(r,this.associations.get(s))),s=r}t.material=s}getMaterialType(){return d.MeshStandardMaterial}loadMaterial(t){const e=this,s=this.json,n=this.extensions,i=s.materials[t];let o;const a={},r=i.extensions||{},c=[];if(r[_.KHR_MATERIALS_UNLIT]){const h=n[_.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),c.push(h.extendParams(a,i,e))}else{const h=i.pbrMetallicRoughness||{};if(a.color=new d.Color(1,1,1),a.opacity=1,Array.isArray(h.baseColorFactor)){const m=h.baseColorFactor;a.color.setRGB(m[0],m[1],m[2],d.LinearSRGBColorSpace),a.opacity=m[3]}h.baseColorTexture!==void 0&&c.push(e.assignTexture(a,"map",h.baseColorTexture,d.SRGBColorSpace)),a.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,a.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(c.push(e.assignTexture(a,"metalnessMap",h.metallicRoughnessTexture)),c.push(e.assignTexture(a,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(m){return m.getMaterialType&&m.getMaterialType(t)}),c.push(Promise.all(this._invokeAll(function(m){return m.extendMaterialParams&&m.extendMaterialParams(t,a)})))}i.doubleSided===!0&&(a.side=d.DoubleSide);const u=i.alphaMode||K.OPAQUE;if(u===K.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,u===K.MASK&&(a.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture!==void 0&&o!==d.MeshBasicMaterial&&(c.push(e.assignTexture(a,"normalMap",i.normalTexture)),a.normalScale=new d.Vector2(1,1),i.normalTexture.scale!==void 0)){const h=i.normalTexture.scale;a.normalScale.set(h,h)}if(i.occlusionTexture!==void 0&&o!==d.MeshBasicMaterial&&(c.push(e.assignTexture(a,"aoMap",i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==d.MeshBasicMaterial){const h=i.emissiveFactor;a.emissive=new d.Color().setRGB(h[0],h[1],h[2],d.LinearSRGBColorSpace)}return i.emissiveTexture!==void 0&&o!==d.MeshBasicMaterial&&c.push(e.assignTexture(a,"emissiveMap",i.emissiveTexture,d.SRGBColorSpace)),Promise.all(c).then(function(){const h=new o(a);return i.name&&(h.name=i.name),H(h,i),e.associations.set(h,{materials:t}),i.extensions&&v(n,h,i),h})}createUniqueName(t){const e=d.PropertyBinding.sanitizeNodeName(t||"");return e in this.nodeNamesUsed?e+"_"+ ++this.nodeNamesUsed[e]:(this.nodeNamesUsed[e]=0,e)}loadGeometries(t){const e=this,s=this.extensions,n=this.primitiveCache;function i(a){return s[_.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,e).then(function(r){return ie(r,a,e)})}const o=[];for(let a=0,r=t.length;a<r;a++){const c=t[a],u=qe(c),h=n[u];if(h)o.push(h.promise);else{let m;c.extensions&&c.extensions[_.KHR_DRACO_MESH_COMPRESSION]?m=i(c):m=ie(new d.BufferGeometry,c,e),n[u]={primitive:c,promise:m},o.push(m)}}return Promise.all(o)}loadMesh(t){const e=this,s=this.json,n=this.extensions,i=s.meshes[t],o=i.primitives,a=[];for(let r=0,c=o.length;r<c;r++){const u=o[r].material===void 0?We(this.cache):this.getDependency("material",o[r].material);a.push(u)}return a.push(e.loadGeometries(o)),Promise.all(a).then(function(r){const c=r.slice(0,r.length-1),u=r[r.length-1],h=[];for(let p=0,g=u.length;p<g;p++){const T=u[p],A=o[p];let R;const x=c[p];if(A.mode===k.TRIANGLES||A.mode===k.TRIANGLE_STRIP||A.mode===k.TRIANGLE_FAN||A.mode===void 0)R=i.isSkinnedMesh===!0?new d.SkinnedMesh(T,x):new d.Mesh(T,x),R.isSkinnedMesh===!0&&R.normalizeSkinWeights(),A.mode===k.TRIANGLE_STRIP?R.geometry=J(R.geometry,d.TriangleStripDrawMode):A.mode===k.TRIANGLE_FAN&&(R.geometry=J(R.geometry,d.TriangleFanDrawMode));else if(A.mode===k.LINES)R=new d.LineSegments(T,x);else if(A.mode===k.LINE_STRIP)R=new d.Line(T,x);else if(A.mode===k.LINE_LOOP)R=new d.LineLoop(T,x);else if(A.mode===k.POINTS)R=new d.Points(T,x);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+A.mode);Object.keys(R.geometry.morphAttributes).length>0&&Qe(R,i),R.name=e.createUniqueName(i.name||"mesh_"+t),H(R,i),A.extensions&&v(n,R,A),e.assignFinalMaterial(R),h.push(R)}for(let p=0,g=h.length;p<g;p++)e.associations.set(h[p],{meshes:t,primitives:p});if(h.length===1)return i.extensions&&v(n,h[0],i),h[0];const m=new d.Group;i.extensions&&v(n,m,i),e.associations.set(m,{meshes:t});for(let p=0,g=h.length;p<g;p++)m.add(h[p]);return m})}loadCamera(t){let e;const s=this.json.cameras[t],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?e=new d.PerspectiveCamera(d.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(e=new d.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(e.name=this.createUniqueName(s.name)),H(e,s),Promise.resolve(e)}loadSkin(t){const e=this.json.skins[t],s=[];for(let n=0,i=e.joints.length;n<i;n++)s.push(this._loadNodeShallow(e.joints[n]));return e.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",e.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const i=n.pop(),o=n,a=[],r=[];for(let c=0,u=o.length;c<u;c++){const h=o[c];if(h){a.push(h);const m=new d.Matrix4;i!==null&&m.fromArray(i.array,c*16),r.push(m)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',e.joints[c])}return new d.Skeleton(a,r)})}loadAnimation(t){const e=this.json,s=this,n=e.animations[t],i=n.name?n.name:"animation_"+t,o=[],a=[],r=[],c=[],u=[];for(let h=0,m=n.channels.length;h<m;h++){const p=n.channels[h],g=n.samplers[p.sampler],T=p.target,A=T.node,R=n.parameters!==void 0?n.parameters[g.input]:g.input,x=n.parameters!==void 0?n.parameters[g.output]:g.output;T.node!==void 0&&(o.push(this.getDependency("node",A)),a.push(this.getDependency("accessor",R)),r.push(this.getDependency("accessor",x)),c.push(g),u.push(T))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(r),Promise.all(c),Promise.all(u)]).then(function(h){const m=h[0],p=h[1],g=h[2],T=h[3],A=h[4],R=[];for(let x=0,S=m.length;x<S;x++){const M=m[x],B=p[x],w=g[x],L=T[x],I=A[x];if(M===void 0)continue;M.updateMatrix&&M.updateMatrix();const C=s._createAnimationTracks(M,B,w,L,I);if(C)for(let z=0;z<C.length;z++)R.push(C[z])}return new d.AnimationClip(i,void 0,R)})}createNodeMesh(t){const e=this.json,s=this,n=e.nodes[t];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(i){const o=s._getNodeRef(s.meshCache,n.mesh,i);return n.weights!==void 0&&o.traverse(function(a){if(a.isMesh)for(let r=0,c=n.weights.length;r<c;r++)a.morphTargetInfluences[r]=n.weights[r]}),o})}loadNode(t){const e=this.json,s=this,n=e.nodes[t],i=s._loadNodeShallow(t),o=[],a=n.children||[];for(let c=0,u=a.length;c<u;c++)o.push(s.getDependency("node",a[c]));const r=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([i,Promise.all(o),r]).then(function(c){const u=c[0],h=c[1],m=c[2];m!==null&&u.traverse(function(p){p.isSkinnedMesh&&p.bind(m,$e)});for(let p=0,g=h.length;p<g;p++)u.add(h[p]);return u})}_loadNodeShallow(t){const e=this.json,s=this.extensions,n=this;if(this.nodeCache[t]!==void 0)return this.nodeCache[t];const i=e.nodes[t],o=i.name?n.createUniqueName(i.name):"",a=[],r=n._invokeOne(function(c){return c.createNodeMesh&&c.createNodeMesh(t)});return r&&a.push(r),i.camera!==void 0&&a.push(n.getDependency("camera",i.camera).then(function(c){return n._getNodeRef(n.cameraCache,i.camera,c)})),n._invokeAll(function(c){return c.createNodeAttachment&&c.createNodeAttachment(t)}).forEach(function(c){a.push(c)}),this.nodeCache[t]=Promise.all(a).then(function(c){let u;if(i.isBone===!0?u=new d.Bone:c.length>1?u=new d.Group:c.length===1?u=c[0]:u=new d.Object3D,u!==c[0])for(let h=0,m=c.length;h<m;h++)u.add(c[h]);if(i.name&&(u.userData.name=i.name,u.name=o),H(u,i),i.extensions&&v(s,u,i),i.matrix!==void 0){const h=new d.Matrix4;h.fromArray(i.matrix),u.applyMatrix4(h)}else i.translation!==void 0&&u.position.fromArray(i.translation),i.rotation!==void 0&&u.quaternion.fromArray(i.rotation),i.scale!==void 0&&u.scale.fromArray(i.scale);return n.associations.has(u)||n.associations.set(u,{}),n.associations.get(u).nodes=t,u}),this.nodeCache[t]}loadScene(t){const e=this.extensions,s=this.json.scenes[t],n=this,i=new d.Group;s.name&&(i.name=n.createUniqueName(s.name)),H(i,s),s.extensions&&v(e,i,s);const o=s.nodes||[],a=[];for(let r=0,c=o.length;r<c;r++)a.push(n.getDependency("node",o[r]));return Promise.all(a).then(function(r){for(let u=0,h=r.length;u<h;u++)i.add(r[u]);const c=u=>{const h=new Map;for(const[m,p]of n.associations)(m instanceof d.Material||m instanceof d.Texture)&&h.set(m,p);return u.traverse(m=>{const p=n.associations.get(m);p!=null&&h.set(m,p)}),h};return n.associations=c(i),i})}_createAnimationTracks(t,e,s,n,i){const o=[],a=t.name?t.name:t.uuid,r=[];P[i.path]===P.weights?t.traverse(function(m){m.morphTargetInfluences&&r.push(m.name?m.name:m.uuid)}):r.push(a);let c;switch(P[i.path]){case P.weights:c=d.NumberKeyframeTrack;break;case P.rotation:c=d.QuaternionKeyframeTrack;break;case P.position:case P.scale:c=d.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:c=d.NumberKeyframeTrack;break;case 2:case 3:default:c=d.VectorKeyframeTrack;break}break}const u=n.interpolation!==void 0?Xe[n.interpolation]:d.InterpolateLinear,h=this._getArrayFromAccessor(s);for(let m=0,p=r.length;m<p;m++){const g=new c(r[m]+"."+P[i.path],e.array,h,u);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(g),o.push(g)}return o}_getArrayFromAccessor(t){let e=t.array;if(t.normalized){const s=Q(e.constructor),n=new Float32Array(e.length);for(let i=0,o=e.length;i<o;i++)n[i]=e[i]*s;e=n}return e}_createCubicSplineTrackInterpolant(t){t.createInterpolant=function(s){const n=this instanceof d.QuaternionKeyframeTrack?Ke:re;return new n(this.times,this.values,this.getValueSize()/3,s)},t.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function et(l,t,e){const s=t.attributes,n=new d.Box3;if(s.POSITION!==void 0){const a=e.json.accessors[s.POSITION],r=a.min,c=a.max;if(r!==void 0&&c!==void 0){if(n.set(new d.Vector3(r[0],r[1],r[2]),new d.Vector3(c[0],c[1],c[2])),a.normalized){const u=Q(D[a.componentType]);n.min.multiplyScalar(u),n.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const i=t.targets;if(i!==void 0){const a=new d.Vector3,r=new d.Vector3;for(let c=0,u=i.length;c<u;c++){const h=i[c];if(h.POSITION!==void 0){const m=e.json.accessors[h.POSITION],p=m.min,g=m.max;if(p!==void 0&&g!==void 0){if(r.setX(Math.max(Math.abs(p[0]),Math.abs(g[0]))),r.setY(Math.max(Math.abs(p[1]),Math.abs(g[1]))),r.setZ(Math.max(Math.abs(p[2]),Math.abs(g[2]))),m.normalized){const T=Q(D[m.componentType]);r.multiplyScalar(T)}a.max(r)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(a)}l.boundingBox=n;const o=new d.Sphere;n.getCenter(o.center),o.radius=n.min.distanceTo(n.max)/2,l.boundingSphere=o}function ie(l,t,e){const s=t.attributes,n=[];function i(o,a){return e.getDependency("accessor",o).then(function(r){l.setAttribute(a,r)})}for(const o in s){const a=Y[o]||o.toLowerCase();a in l.attributes||n.push(i(s[o],a))}if(t.indices!==void 0&&!l.index){const o=e.getDependency("accessor",t.indices).then(function(a){l.setIndex(a)});n.push(o)}return d.ColorManagement.workingColorSpace!==d.LinearSRGBColorSpace&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${d.ColorManagement.workingColorSpace}" not supported.`),H(l,t),et(l,t,e),Promise.all(n).then(function(){return t.targets!==void 0?Ye(l,t.targets,e):l})}const tt="https://cdn.jsdelivr.net/npm/@mymo";class nt{constructor(){this.cache=new Map}async load(t){const e=this._resolve(t),s=this.cache.get(e);if(s)return s;const i=e.endsWith(".vrm")?await this._loadVRM(e):await this._loadGLB(e);return this.cache.set(e,i),i}_resolve(t){return t.startsWith("http")||t.startsWith("/")||t.endsWith(".glb")||t.endsWith(".vrm")?t:`${tt}/model-${t}/latest/${t}.glb`}async _loadGLB(t){console.warn("[mymo-avatar] GLB support is best-effort. For guaranteed expressions, gestures, lip sync, and blink, use a VRM model.");const e=new ee,s=await this._load(e,t);return this._prepareMeshes(s.scene),{scene:s.scene,animations:s.animations}}async _loadVRM(t){const e=new ee;e.register(i=>new f.VRMLoaderPlugin(i));const s=await this._load(e,t),n=s.userData.vrm;return this._prepareMeshes(n.scene),{scene:n.scene,animations:s.animations,vrm:n}}_prepareMeshes(t){t.traverse(e=>{(e instanceof y.Mesh||e instanceof y.SkinnedMesh)&&(e.castShadow=!0,e.receiveShadow=!0,e.morphTargetInfluences&&e.morphTargetInfluences.fill(0))})}_load(t,e){return new Promise((s,n)=>{t.load(e,s,void 0,i=>n(new Error(`Failed to load model: ${e} — ${String(i)}`)))})}clearCache(){this.cache.clear()}}class st{constructor(){this.installed=new Map}use(t,e,s){this.installed.has(t.name)||(t.install(e,s),this.installed.set(t.name,t))}has(t){return this.installed.has(t)}}const it={"pulse-blue":"rgba(96,165,250,0.7)","pulse-green":"rgba(74,222,128,0.7)","pulse-red":"rgba(248,113,113,0.7)","pulse-orange":"rgba(251,146,60,0.7)"},ot={model:"maya",position:"bottom-right",size:180,theme:"light",framing:"full",draggable:!1,shadows:!1,idle:!0,idleInterval:8e3,blink:!0,blinkInterval:3500,lipSync:!0,followMouse:!1,autoHide:!1,zIndex:99999,framingConfig:{},themeConfig:{}};class rt{constructor(t={}){this._boundMouseLook=e=>{const s=e.clientX/window.innerWidth*2-1,n=e.clientY/window.innerHeight*2-1;this.animation.lookAt(s,n)},this.options={...ot,...t},this.events=new ce,this.renderer=new de,this.animation=new W,this.audio=new Te,this.lipSync=new Re(this.audio,e=>this.animation.setMouthMorph(e)),this.loader=new nt,this.plugins=new st,this.renderer.setup(this.options),this.renderer.addTickCallback(e=>this.animation.update(e)),this._bindContainerEvents(),this._initialize().catch(e=>console.error("[mymo-avatar]",e))}async _initialize(){try{const t=await this.loader.load(this.options.model);this.renderer.setModel(t.scene),this.animation.init(t),this.options.idle&&this.animation.startIdle(this.options.idleInterval),this.options.blink&&this.animation.startBlink(this.options.blinkInterval),this.options.followMouse&&this._bindMouseLook(),this.events.emit("loaded"),this.events.emit("modelLoaded",{model:this.options.model})}catch(t){console.error("[mymo-avatar] Failed to load model:",t)}}_bindContainerEvents(){this.renderer.getContainer().addEventListener("click",()=>{this.events.emit("click")})}_bindMouseLook(){window.addEventListener("mousemove",this._boundMouseLook)}debugBones(t){return this.renderer.debugBones(t),this}show(){return this.renderer.show(),this}hide(){return this.renderer.hide(),this}destroy(){window.removeEventListener("mousemove",this._boundMouseLook),this.animation.stopLook(),this.animation.dispose(),this.audio.dispose(),this.renderer.dispose(),this.events.removeAllListeners()}move(t,e){return this.renderer.moveTo(t,e),this}position(t){return this.renderer.setPosition(t),this}scale(t){const e=parseInt(this.renderer.getContainer().style.width,10)||this.options.size;return this.renderer.setSize(e*t),this}size(t){return this.renderer.setSize(t),this}frame(t){return this.renderer.setFraming(t),this}setFramingConfig(t){return this.renderer.setFramingConfig(t),this}setTheme(t){return this.renderer.setTheme(t),this}setThemeConfig(t){return this.renderer.setThemeConfig(t),this}expression(t,e=1){return this.animation.setExpression(t,e),this}smile(){return this.expression("smile")}sad(){return this.expression("sad")}happy(){return this.expression("happy")}angry(){return this.expression("angry")}surprised(){return this.expression("surprised")}thinking(){return this.expression("thinking")}confused(){return this.expression("confused")}sleep(){return this.expression("sleep")}idle(){return this.expression("idle")}wave(){return this._gesture("wave")}nod(){return this._gesture("nod")}shakeHead(){return this._gesture("shakeHead")}clap(){return this._gesture("clap")}jump(){return this._gesture("jump")}dance(){return this._gesture("dance")}yes(){return this._gesture("yes")}no(){return this._gesture("no")}thumbsUp(){return this._gesture("thumbsUp")}_gesture(t){return this.events.emit("animationStart",{gesture:t}),this.animation.playGesture(t),this}lookAtMouse(){return this._bindMouseLook(),this}lookAt(t,e){const s=t/window.innerWidth*2-1,n=e/window.innerHeight*2-1;return this.animation.lookAt(s,n),this}lookForward(){return window.removeEventListener("mousemove",this._boundMouseLook),this.animation.lookForward(),this}randomLook(){return this.animation.startRandomLook(),this}async talk(t){return this.events.emit("speechStart"),this.options.lipSync&&this.lipSync.startAutoSync(),await this.audio.play(t),this.options.lipSync&&this.lipSync.stopAutoSync(),this.events.emit("speechEnd"),this}startTalking(){return this.events.emit("speechStart"),this.options.lipSync&&this.lipSync.startAutoSync(),this}stopTalking(){return this.audio.stop(),this.lipSync.stopAutoSync(),this.events.emit("speechEnd"),this}pauseTalking(){return this.audio.pause(),this}setViseme(t){return this.lipSync.setViseme(t),this}setMouth(t){return this.lipSync.setMouth(t),this}setVolume(t){return this.lipSync.setVolume(t),this}setState(t){const e={loading:{expression:"thinking",animation:"Idle",ring:"pulse-blue"},success:{expression:"happy",animation:"Yes",ring:"pulse-green"},error:{expression:"sad",animation:"No",ring:"pulse-red"},warning:{expression:"surprised",animation:"Idle",ring:"pulse-orange"},typing:{expression:"thinking",animation:"Idle",ring:""},listening:{expression:"smile",animation:"Idle",ring:"pulse-blue"},processing:{expression:"thinking",animation:"Idle",ring:"pulse-blue"},complete:{expression:"happy",animation:"ThumbsUp",ring:"pulse-green"}},{expression:s,animation:n,ring:i}=e[t];this.animation.setExpression(s),this.animation.play(n);const o=this.renderer.getContainer();return o.dataset.state=t,o.style.setProperty("--ring-color",i?it[i]??"transparent":"transparent"),this.events.emit("animationStart",{state:t}),this}loading(){return this.setState("loading")}success(){return this.setState("success")}error(){return this.setState("error")}warning(){return this.setState("warning")}typing(){return this.setState("typing")}listening(){return this.setState("listening")}processing(){return this.setState("processing")}complete(){return this.setState("complete")}clearState(){this.animation.setExpression("idle"),this.animation.stop();const t=this.renderer.getContainer();return t.dataset.state="",t.style.setProperty("--ring-color","transparent"),this.events.emit("animationEnd"),this}play(t){return this.events.emit("animationStart",{name:t}),this.animation.play(t),this}stop(){return this.animation.stop(),this.events.emit("animationEnd"),this}async load(t){const e=await this.loader.load(t);return this.animation.dispose(),this.renderer.setModel(e.scene),this.animation.init(e),this.options.idle&&this.animation.startIdle(this.options.idleInterval),this.options.blink&&this.animation.startBlink(this.options.blinkInterval),this.events.emit("modelLoaded",{model:t}),this}on(t,e){return this.events.on(t,e),this}off(t,e){return this.events.off(t,e),this}use(t,e){return this.plugins.use(t,this,e),this}}exports.Avatar=rt;
|
|
10
|
+
//# sourceMappingURL=Avatar-Ok6vAXs6.cjs.map
|