t2-mapper/docs/assets/PlayerModel-C8bjGZ0F.js
2026-03-30 22:50:52 -07:00

1 line
No EOL
20 KiB
JavaScript

import{r as e}from"./chunk-DECur_0Z.js";import{n as t,r as n,t as r}from"./jsx-runtime-BpGWiA-R.js";import{o as i,t as a}from"./Html-DrHEhPVE.js";import{a as o,b as s,c,d as l,f as u,g as d,h as f,l as p,u as m,v as h}from"./SettingsProvider-DVIFsPwe.js";import{C as g,a as _,f as ee,i as v,l as y,m as b,p as x,r as S,t as C,u as w}from"./GenericShape-D0Move-Z.js";import{p as T,r as E}from"./loaders-BhaVxgpz.js";import{$ as D,Q as O,a as k,bt as te,f as A,i as j,o as M,s as N}from"./three.module-DRRYkRPO.js";import{a as ne,i as re,o as P}from"./engineStore-DeZJbWme.js";import{t as F}from"./DebugSuspense-CNky_EQQ.js";import{n as I}from"./streamPlaybackStore-D-tkUWut.js";import{t as ie}from"./useAnisotropy-nhH7jNtm.js";import{t as ae}from"./ShapeErrorBoundary-75cvF0LI.js";var L=e(n(),1),R=t(),z=.1,B=20;function V(e){return-2*Math.atan2(e[1],e[3])}function oe(e,t,n,r){if(n)return{animation:`fall`,timeScale:1};if(!e)return{animation:`root`,timeScale:1};let[i,a,o]=e,s=i*i+a*a;if(Math.abs(o)>2||s>B*B)return r?{animation:`jet`,timeScale:1}:{animation:`root`,timeScale:1};let c=V(t),l=Math.cos(c),u=Math.sin(c),d=i*l+a*u,f=-i*u+a*l,p=f,m=-f,h=-d,g=Math.max(p,m,h,d);return g<z?{animation:`root`,timeScale:1}:g===p?{animation:`run`,timeScale:1}:g===m?{animation:`back`,timeScale:1}:g===h?{animation:`side`,timeScale:1}:{animation:`side`,timeScale:-1}}var H=-1,U=32,W=1,G=2,K=3,se=4,ce=class{states;seqIndexToName;currentStateIndex=0;delayTime=0;lastFireCount=-1;spinTimeScale=0;constructor(e,t){this.states=e,this.seqIndexToName=t,e.length>0&&(this.delayTime=e[0].timeoutValue??0)}get stateIndex(){return this.currentStateIndex}reset(){this.currentStateIndex=0,this.delayTime=this.states.length>0?this.states[0].timeoutValue??0:0,this.lastFireCount=-1}tick(e,t){if(this.states.length===0)return{sequenceName:null,isFiring:!1,spinTimeScale:0,reverse:!1,scaleAnimation:!1,timeoutValue:0,transitioned:!1,soundDataBlockIds:[],stateIndex:-1};let n=this.lastFireCount>=0&&t.fireCount!==this.lastFireCount;this.lastFireCount=t.fireCount;let r=[];if(n){let e=this.states.findIndex(e=>e.fire);if(e>=0&&e!==this.currentStateIndex){this.currentStateIndex=e,this.delayTime=this.states[e].timeoutValue??0;let t=this.states[e].soundDataBlockId;t>=0&&r.push(t)}}this.delayTime-=e;let i=n,a=this.evaluateTickTransitions(t),o=0;for(;a>=0&&o<U;){if(o++,i=!0,a===this.currentStateIndex){this.delayTime=this.states[a].timeoutValue??0;break}let e=this.states[this.currentStateIndex].spin,n=this.delayTime;this.currentStateIndex=a;let s=this.states[a].timeoutValue??0;this.delayTime=s;let c=this.states[a].soundDataBlockId;switch(c>=0&&r.push(c),this.states[a].spin){case W:this.spinTimeScale=0;break;case se:this.spinTimeScale=1;break;case G:e===K&&s>0&&(this.delayTime*=1-n/s);break;case K:e===G&&s>0&&(this.delayTime*=1-n/s);break}a=this.evaluateEntryTransitions(t)}let s=this.states[this.currentStateIndex],c=s.timeoutValue??0;switch(s.spin){case W:this.spinTimeScale=0;break;case G:this.spinTimeScale=c>0?Math.max(0,1-this.delayTime/c):1;break;case se:this.spinTimeScale=1;break;case K:this.spinTimeScale=c>0?Math.max(0,this.delayTime/c):0;break}return{sequenceName:this.resolveSequenceName(s),isFiring:s.fire,spinTimeScale:this.spinTimeScale,reverse:!s.direction,scaleAnimation:s.scaleAnimation,timeoutValue:s.timeoutValue??0,transitioned:i,soundDataBlockIds:r,stateIndex:this.currentStateIndex}}evaluateTickTransitions(e){let t=this.states[this.currentStateIndex],n=this.delayTime<=0;if(!(n||!t.waitForTimeout))return-1;let r=this.evaluateConditions(t,e);if(r!==-1)return r;if(n){let e=t.transitionOnTimeout;if(e!==H)return e}return-1}evaluateEntryTransitions(e){let t=this.states[this.currentStateIndex];return this.evaluateConditions(t,e)}evaluateConditions(e,t){let n=t.loaded?e.transitionOnLoaded:e.transitionOnNotLoaded;if(n!==H)return n;let r=t.ammo?e.transitionOnAmmo:e.transitionOnNoAmmo;if(r!==H)return r;let i=t.target?e.transitionOnTarget:e.transitionOnNoTarget;if(i!==H)return i;let a=t.wet?e.transitionOnWet:e.transitionOnNotWet;if(a!==H)return a;let o=t.triggerDown?e.transitionOnTriggerDown:e.transitionOnTriggerUp;return o===H?-1:o}resolveSequenceName(e){return e.sequence==null||e.sequence<0?null:this.seqIndexToName[e.sequence]??null}},q={Root:`_Root_1i0cm_1`,Top:`_Top_1i0cm_10 _Root_1i0cm_1`,Bottom:`_Bottom_1i0cm_15 _Root_1i0cm_1`,IffArrow:`_IffArrow_1i0cm_20`,Name:`_Name_1i0cm_27`,HealthBar:`_HealthBar_1i0cm_35`,HealthFill:`_HealthFill_1i0cm_44`},J=r(),le=150,ue=.1,Y=-.2,de=T(`gui/hud_alliedtriangle`),fe=T(`gui/hud_enemytriangle`),X=[];function pe(e){let t=(0,R.c)(23),{entity:n}=e,r=S(n.shapeName),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o={fadeDistance:le},t[0]=o):o=t[0];let{groupRef:s,isVisible:c,opacityRef:l}=h(o),u=(0,L.useRef)(null),d=(0,L.useRef)(null),f=(0,L.useRef)(null),p=(0,L.useRef)(null),m=(0,L.useRef)(null),g;t[1]===r.scene?g=t[2]:(g=new A().setFromObject(r.scene),t[1]=r.scene,t[2]=g);let _=g.max.y+ue,v=n.keyframes??X,y;t[3]===v?y=t[4]:(y=v.some(me),t[3]=v,t[4]=y);let b=y,x;t[5]!==n.id||t[6]!==n.iffColor||t[7]!==n.playerName||t[8]!==b||t[9]!==c||t[10]!==v||t[11]!==l?(x=()=>{if(!c)return;let e=ee(v,I.getState().time),t=e?.health??1;if(e?.damageState!=null&&e.damageState>=1){u.current&&(u.current.style.opacity=`0`),d.current&&(d.current.style.opacity=`0`);return}let r=l.current;if(u.current&&(u.current.style.opacity=r),d.current&&(d.current.style.opacity=r),m.current){let e=n.playerName??n.id;m.current.textContent!==e&&(m.current.textContent=e)}if(p.current&&n.iffColor){let e=n.iffColor.r>n.iffColor.g?fe:de;p.current.getAttribute(`src`)!==e&&(p.current.src=e)}f.current&&b&&(f.current.style.width=`${Math.max(0,Math.min(100,t*100))}%`,f.current.style.background=n.iffColor?`rgb(${n.iffColor.r}, ${n.iffColor.g}, ${n.iffColor.b})`:``)},t[5]=n.id,t[6]=n.iffColor,t[7]=n.playerName,t[8]=b,t[9]=c,t[10]=v,t[11]=l,t[12]=x):x=t[12],i(x);let C=n.iffColor&&n.iffColor.r>n.iffColor.g?fe:de,w;t[13]!==n.id||t[14]!==n.playerName||t[15]!==b||t[16]!==_||t[17]!==C||t[18]!==c?(w=c&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(a,{position:[0,_,0],center:!0,children:(0,J.jsx)(`div`,{ref:u,className:q.Top,children:(0,J.jsx)(`img`,{ref:p,className:q.IffArrow,src:C,alt:``})})}),(0,J.jsx)(a,{position:[0,Y,0],center:!0,children:(0,J.jsxs)(`div`,{ref:d,className:q.Bottom,children:[(0,J.jsx)(`div`,{ref:m,className:q.Name,children:n.playerName??n.id}),b&&(0,J.jsx)(`div`,{className:q.HealthBar,children:(0,J.jsx)(`div`,{ref:f,className:q.HealthFill})})]})})]}),t[13]=n.id,t[14]=n.playerName,t[15]=b,t[16]=_,t[17]=C,t[18]=c,t[19]=w):w=t[19];let T;return t[20]!==s||t[21]!==w?(T=(0,J.jsx)(`group`,{ref:s,children:w}),t[20]=s,t[21]=w,t[22]=T):T=t[22],T}function me(e){return e.health!=null}var Z=8,Q=[`root`,`run`,`back`,`side`,`fall`,`jet`,`jump`,`land`];function he(e,t,n=0){let r=new Map,i=[];for(let n of e){let e=n.indexOf(` `);if(e===-1)continue;let r=n.slice(0,e).toLowerCase(),a=n.slice(e+1).trim().toLowerCase();if(!a||!r.startsWith(t)||!r.endsWith(`.dsq`))continue;let o=r.slice(t.length,-4);o&&i.push({clipName:o,alias:a})}let a=new Set;for(let e=0;e<Q.length;e++){let t=Q[e];for(let n=0;n<i.length;n++)if(i[n].alias===t){a.add(n),r.set(e,i[n]);break}}let o=Z+n;for(let e=0;e<i.length;e++)a.has(e)||(r.set(o,i[e]),o++);return r}var ge=new Set(Q);function _e(e,t,n){let r=e.userData?.dts_sequence_names;if(typeof r!=`string`)return 0;let i;try{i=JSON.parse(r)}catch{return 0}if(!Array.isArray(i)||i.length===0)return 0;let a=new Set;for(let e of t){let t=e.indexOf(` `);if(t===-1)continue;let r=e.slice(0,t).toLowerCase();if(!r.startsWith(n)||!r.endsWith(`.dsq`))continue;let i=r.slice(n.length,-4);i&&a.add(i)}let o=0;for(let e of i){if(a.has(e.toLowerCase()))break;ge.has(e.toLowerCase())||o++}return o}function ve(e,t,n){let r=e.current;if(r){d(r);try{r.stop()}catch{}try{r.disconnect()}catch{}n?.remove(r),e.current=null,t.current=-1}}function $({entity:e}){let t=ne(),n=e.shapeName,r=S(n),a=re(e=>{let t=n?.toLowerCase();return t?e.runtime.sequenceAliases.get(t):void 0}),l=ie(),m=re(e=>e.playback.streamSnapshot?.controlPlayerGhostId),{clonedScene:h,mixer:_,mount0:x,mount1:T,mount2:A,iflInitializers:R}=(0,L.useMemo)(()=>{let t=g(r.scene),n=b(t,void 0,{anisotropy:l,emap:e.emap});t.traverse(e=>{if(e.isMesh&&e.material){let t=Array.isArray(e.material)?e.material:[e.material];for(let e of t)e.side=0}});let i=new M(t),a=null,o=null,s=null;return t.traverse(e=>{!a&&e.name===`Mount0`&&(a=e),!o&&e.name===`Mount1`&&(o=e),!s&&e.name===`Mount2`&&(s=e)}),{clonedScene:t,mixer:i,mount0:a,mount1:o,mount2:s,iflInitializers:n}},[r.scene,l,e.emap]);(0,L.useEffect)(()=>()=>{w(h),_.uncacheRoot(h)},[h,_]);let z=(0,L.useRef)(new Map),B=(0,L.useRef)({head:null,headside:null}),V=(0,L.useRef)(new Map),H=(0,L.useRef)(null),U=(0,L.useRef)({name:`root`,timeScale:1}),W=(0,L.useRef)(!1),G=(0,L.useRef)(void 0),K=(0,L.useMemo)(()=>{let e=t.getState().playback.recording?.streamingPlayback,i=n?.toLowerCase();if(!e||!i)return new Map;let a=e.getShapeConstructorSequences(i);if(!a)return new Map;let o=i.replace(/\.dts$/i,``)+`_`;return he(a,o,_e(r.scene,a,o))},[t,n,r.scene]),se=(0,L.useMemo)(()=>{let e=new Map,t=r.scene.userData?.dts_sequence_names,n=r.scene.userData?.dts_sequence_cyclic;if(typeof t==`string`&&typeof n==`string`)try{let r=JSON.parse(t),i=JSON.parse(n),o=new Map;for(let e=0;e<r.length;e++)o.set(r[e].toLowerCase(),i[e]??!0);if(a)for(let[t,n]of a){let r=o.get(n);r!=null&&e.set(t,r)}for(let[t,n]of o)e.has(t)||e.set(t,n)}catch{}return e},[r.scene,a]);(0,L.useEffect)(()=>{let e=P(r.animations,_,a);z.current=e;let t=e.get(`root`);t&&t.play(),U.current={name:`root`,timeScale:1};let n={head:null,headside:null};for(let{key:e,names:t}of[{key:`head`,names:[`head`]},{key:`headside`,names:[`headside`]}]){let i=r.animations.find(e=>t.includes(e.name.toLowerCase()));if(!i)continue;let a=i.clone(),o=Math.round(i.duration*30/2);N.makeClipAdditive(a,o,i,30);let s=_.clipAction(a);s.blendMode=j,s.timeScale=0,s.weight=1,s.play(),n[e]=s}B.current=n;let i=r.animations.find(e=>e.name.toLowerCase()===`root`);if(i){let e=new Set;for(let t of r.animations){let n=t.name.toLowerCase();if([`forward`,`back`,`side`,`fall`].includes(n))for(let n of t.tracks)e.add(n.name.slice(0,n.name.lastIndexOf(`.`)))}let t=i.tracks.filter(t=>{let n=t.name.slice(0,t.name.lastIndexOf(`.`));return!e.has(n)});if(t.length>0){let e=new k(`root_arms`,i.duration,t);_.clipAction(e).play()}}let o=new Map,s=r.scene.userData?.dts_sequence_names,c=r.scene.userData?.dts_sequence_blend;if(typeof s==`string`&&typeof c==`string`)try{let e=JSON.parse(s),t=JSON.parse(c);for(let n=0;n<e.length;n++){if(!t[n])continue;let i=e[n].toLowerCase();if(i===`head`||i===`headside`)continue;let a=r.animations.find(e=>e.name.toLowerCase()===i);if(!a)continue;let s=a.clone(),c=y(r.scene,s);N.makeClipAdditive(s,0,c,30);let l=_.clipAction(s);l.blendMode=j,l.timeScale=0,l.weight=0,l.play(),o.set(i,l)}}catch{}V.current=o;let l=o.get(`lookde`);return l&&(l.weight=1,H.current=`lookde`),_.update(0),()=>{_.stopAllAction(),z.current=new Map,B.current={head:null,headside:null},V.current=new Map,H.current=null}},[_,r.animations,a]),(0,L.useEffect)(()=>{let e=[];for(let{mesh:t,initialize:n}of R)n(t,()=>I.getState().time).then(t=>e.push(t)).catch(()=>{});return()=>e.forEach(e=>e())},[R]);let ce=(0,L.useRef)(e.weaponShape),[q,le]=(0,L.useState)(e.weaponShape),ue=(0,L.useRef)(e.packShape),[Y,de]=(0,L.useState)(e.packShape),fe=(0,L.useRef)(e.flagShape),[X,me]=(0,L.useState)(e.flagShape),{audioLoader:Q,audioListener:ge}=s(),ve=o()?.audioEnabled??!1,$=(0,L.useRef)(null),ye=(0,L.useRef)(null),xe=(0,L.useRef)(null);return(0,L.useEffect)(()=>{if(!Q)return;let n=t.getState().playback.recording?.streamingPlayback;if(!n||!e.dataBlockId)return;let r=n.getDataBlockData.bind(n),i=r(e.dataBlockId)?.sounds?.[0];if(i==null)return;let a=u(i,r);if(a){xe.current=a;try{c(E(a.filename),Q,e=>{ye.current=e})}catch{}}},[Q,t,e.dataBlockId]),(0,L.useEffect)(()=>()=>{let e=$.current;if(e){d(e);try{e.stop()}catch{}try{e.disconnect()}catch{}e.parent?.remove(e),$.current=null}},[]),i((n,r)=>{e.weaponShape!==ce.current&&(ce.current=e.weaponShape,le(e.weaponShape)),e.packShape!==ue.current&&(ue.current=e.packShape,de(e.packShape)),e.flagShape!==fe.current&&(fe.current=e.flagShape,me(e.flagShape));let i=t.getState().playback,a=i.status===`playing`,o=I.getState().time,s=ee(e.keyframes??[],o),c=s?.damageState!=null&&s.damageState>=1,l=z.current;if(c&&!W.current){W.current=!0;let e=s.actionAnim==null?void 0:K.get(s.actionAnim);if(e){let t=l.get(e.clipName);if(t){let n=l.get(U.current.name.toLowerCase());n&&n.fadeOut(v),t.setLoop(O,1),t.clampWhenFinished=!0,t.reset().fadeIn(v).play(),U.current={name:e.clipName,timeScale:1},G.current=s.actionAnim}}}if(!c&&W.current){W.current=!1,G.current=void 0;let e=l.get(U.current.name.toLowerCase());e&&(e.stop(),e.setLoop(D,1/0),e.clampWhenFinished=!1),U.current={name:`root`,timeScale:1};let t=l.get(`root`);t&&t.reset().play()}let u=s?.actionAnim,m=G.current;if(!W.current&&u!==m){G.current=u;let e=u!=null&&u>=Z,t=m!=null&&m>=Z;if(e){let e=K.get(u);if(e){let t=l.get(e.clipName);if(t){let n=l.get(U.current.name.toLowerCase());n&&n.fadeOut(v),t.setLoop(O,1),t.clampWhenFinished=!0,t.reset().fadeIn(v).play(),U.current={name:e.clipName,timeScale:1}}}}else if(t){let e=K.get(m);if(e){let t=l.get(e.clipName);t&&(t.fadeOut(v),t.setLoop(D,1/0),t.clampWhenFinished=!1)}U.current={name:`root`,timeScale:1};let t=l.get(`root`);t&&t.reset().fadeIn(v).play()}}if(u!=null&&u>=Z&&s?.actionAtEnd){let e=K.get(u);if(e){let t=l.get(e.clipName);t&&(t.paused=!0)}}let g=G.current!=null&&G.current>=Z;if(!W.current&&!g){let t=oe(s?.velocity,s?.rotation??[0,0,0,1],e.falling,e.jetting),n=U.current;if(t.animation!==n.name||t.timeScale!==n.timeScale){let e=l.get(n.name.toLowerCase()),r=l.get(t.animation.toLowerCase());r&&(se.get(t.animation)??!0?(r.setLoop(D,1/0),r.clampWhenFinished=!1):(r.setLoop(O,1),r.clampWhenFinished=!0),a&&e&&e!==r?(e.fadeOut(v),r.reset().fadeIn(v).play()):(e&&e!==r&&e.stop(),r.reset().play()),r.timeScale=t.timeScale,U.current={name:t.animation,timeScale:t.timeScale})}}let y=(e.armAction==null?void 0:K.get(e.armAction))?.clipName??`lookde`;if(y!==H.current){let e=V.current,t=H.current?e.get(H.current):null,n=e.get(y);n&&(t&&(t.weight=0),n.weight=c?0:1,H.current=y)}let{head:b,headside:x}=B.current,S=H.current?V.current.get(H.current):null,C=c?0:1,w=e.headPitch??0,T=e.headYaw??0,E=(w+1)/2,k=(T+1)/2;S&&(S.time=E*S.getClip().duration,S.weight=C),b&&(b.time=E*b.getClip().duration,b.weight=C),x&&(x.time=k*x.getClip().duration,x.weight=C);let A=!!e.jetting&&!c,j=xe.current,M=$.current,N=M?.isPlaying??!1;if(A&&!N){if(ve&&ge&&ye.current&&j){let e=M;e||(e=new te(ge),e.setDistanceModel(`inverse`),e.setRefDistance(j.refDist),e.setMaxDistance(j.maxDist),e.setRolloffFactor(1),e.setVolume(j.volume),h.add(e),$.current=e);try{e.setBuffer(ye.current),e.setLoop(!0),e.setPlaybackRate(p()),e.play(),f(e,1)}catch{}}}else if(!A&&N&&M){d(M);try{M.stop()}catch{}}a?_.update(r*i.rate):_.update(0)}),(0,J.jsxs)(J.Fragment,{children:[e.id!==m&&(0,J.jsx)(pe,{entity:e}),(0,J.jsx)(`group`,{rotation:[0,Math.PI/2,0],children:(0,J.jsx)(`primitive`,{object:h})}),q&&x&&(0,J.jsx)(ae,{fallback:(0,J.jsx)(C,{color:`red`,label:q}),children:(0,J.jsx)(F,{name:`Weapon:${e.id}/${q}`,fallback:(0,J.jsx)(C,{color:`cyan`,label:q}),children:(0,J.jsx)(be,{entity:e,weaponShape:q,mount0:x})})},q),Y&&T&&(0,J.jsx)(ae,{fallback:(0,J.jsx)(C,{color:`red`,label:Y}),children:(0,J.jsx)(F,{name:`Pack:${e.id}/${Y}`,fallback:(0,J.jsx)(C,{color:`cyan`,label:Y}),children:(0,J.jsx)(Se,{packShape:Y,mountBone:T,emap:e.emap})})},Y),X&&A&&(0,J.jsx)(ae,{fallback:(0,J.jsx)(C,{color:`red`,label:X}),children:(0,J.jsx)(F,{name:`Flag:${e.id}/${X}`,fallback:(0,J.jsx)(C,{color:`cyan`,label:X}),children:(0,J.jsx)(Se,{packShape:X,mountBone:A,emap:e.emap})})},X)]})}function ye(e,t){let n=e.userData?.dts_sequence_names;if(typeof n==`string`)try{return JSON.parse(n).map(e=>e.toLowerCase())}catch{}return t.map(e=>e.name.toLowerCase())}function be({entity:e,weaponShape:t,mount0:n}){let r=ne(),a=S(t),d=ie(),{weaponClone:h,weaponMixer:_,seqIndexToName:ee,visNodesBySequence:v,weaponIflInitializers:y}=(0,L.useMemo)(()=>{let t=g(a.scene),n=b(t,void 0,{anisotropy:d,emap:e.emap}),r=x(a.scene,a.animations,`Mountpoint`);if(r){let e=r.quaternion.clone().invert(),n=r.position.clone().negate().applyQuaternion(e);t.position.copy(n),t.quaternion.copy(e)}let i=new Map;return t.traverse(e=>{if(!e.isMesh)return;let t=(e.userData?.vis_sequence??``).toLowerCase();if(!t)return;let n=i.get(t);n||(n=[],i.set(t,n)),n.push(e)}),{weaponClone:t,weaponMixer:new M(t),seqIndexToName:ye(a.scene,a.animations),visNodesBySequence:i,weaponIflInitializers:n}},[a,d]);(0,L.useEffect)(()=>()=>{w(h),_.uncacheRoot(h)},[h,_]);let C=(0,L.useRef)(new Map),T=(0,L.useRef)(null);(0,L.useEffect)(()=>{let e=new Map;for(let t of a.animations)e.set(t.name.toLowerCase(),_.clipAction(t));C.current=e;let t=e.get(`spin`);return t&&(t.setLoop(D,1/0),t.timeScale=0,t.play()),T.current=t??null,_.update(0),()=>{_.stopAllAction(),C.current=new Map,T.current=null,ve(P,F)}},[_,a.animations]),(0,L.useEffect)(()=>{let e=[];for(let{mesh:t,initialize:n}of y)n(t,()=>I.getState().time).then(t=>e.push(t)).catch(()=>{});return()=>e.forEach(e=>e())},[y]);let{audioLoader:O,audioListener:k}=s(),A=o()?.audioEnabled??!1,j=(0,L.useRef)(null),N=(0,L.useRef)(null),re=(0,L.useRef)(e.weaponImageStates),P=(0,L.useRef)(null),F=(0,L.useRef)(-1);return(0,L.useEffect)(()=>(n.add(h),()=>{n.remove(h)}),[h,n]),i((t,n)=>{let i=r.getState().playback,a=i.status===`playing`,o=C.current,s=e.weaponImageState,d=e.weaponImageStates;d!==re.current&&(re.current=d,d&&d.length>0?j.current=new ce(d,ee):j.current=null,N.current=null,ve(P,F,h)),!j.current&&d&&d.length>0&&(j.current=new ce(d,ee));let g=j.current;if(g&&s&&a){let e=n*i.rate,t=g.tick(e,s);if(xe(t,o,N,v),P.current&&t.stateIndex!==F.current&&ve(P,F,h),A&&O&&k&&t.soundDataBlockIds.length>0){let e=i.recording?.streamingPlayback.getDataBlockData.bind(i.recording.streamingPlayback);if(e)for(let n of t.soundDataBlockIds){let t=u(n,e);if(t)if(t.isLooping){if(!P.current)try{let e=E(t.filename),n=m();c(e,O,e=>{if(n!==m()||P.current)return;let r=g.stateIndex,i=new te(k);i.setBuffer(e),i.setDistanceModel(`inverse`),i.setRefDistance(t.refDist),i.setMaxDistance(t.maxDist),i.setRolloffFactor(1),i.setVolume(t.volume),i.setPlaybackRate(p()),i.setLoop(!0),h.add(i),f(i),i.play(),P.current=i,F.current=r})}catch{}}else l(t,k,O,void 0,h)}}T.current&&(T.current.timeScale=t.spinTimeScale)}a?_.update(n*i.rate):_.update(0)}),null}function xe(e,t,n,r){let i=e.sequenceName,a=n.current;if(i===a&&!e.transitioned)return;if(i!==a){if(a){let e=r.get(a);if(e)for(let t of e)t.visible=!1}if(i){let e=r.get(i);if(e)for(let t of e)t.visible=!0}}if(!i){if(a){let e=t.get(a);e&&e.fadeOut(v),n.current=null}return}let o=t.get(i);if(o&&(e.transitioned||i!==a)){let r=a?t.get(a):null;if(e.isFiring||e.timeoutValue>0?(o.setLoop(O,1),o.clampWhenFinished=!0):(o.setLoop(D,1/0),o.clampWhenFinished=!1),e.scaleAnimation&&e.timeoutValue>0){let t=o.getClip().duration;o.timeScale=t>0?t/e.timeoutValue:1}else o.timeScale=e.reverse?-1:1;r&&r!==o?(r.fadeOut(v),o.reset().fadeIn(v).play()):o.reset().play(),n.current=i}}function Se({packShape:e,mountBone:t,emap:n}){let r=S(e),i=ie(),{packClone:a,packIflInitializers:o}=(0,L.useMemo)(()=>{let e=g(r.scene),t=b(e,void 0,{anisotropy:i,emap:n}),a=x(r.scene,r.animations,`Mountpoint`);if(a){let t=a.quaternion.clone().invert(),n=a.position.clone().negate().applyQuaternion(t);e.position.copy(n),e.quaternion.copy(t)}return{packClone:e,packIflInitializers:t}},[r,i]);return(0,L.useEffect)(()=>(t.add(a),()=>{t.remove(a),w(a)}),[a,t]),(0,L.useEffect)(()=>{let e=[];for(let{mesh:t,initialize:n}of o)n(t,()=>I.getState().time).then(t=>e.push(t)).catch(()=>{});return()=>e.forEach(e=>e())},[o]),null}function Ce(e){let t=(0,R.c)(7),{shapeName:n,eyeOffsetRef:r}=e,i=S(n),a;t[0]!==r||t[1]!==i.animations||t[2]!==i.scene?(a=()=>{let e=x(i.scene,i.animations,`Eye`);e?r.current.set(e.position.z,e.position.y,-e.position.x):r.current.set(0,_,0)},t[0]=r,t[1]=i.animations,t[2]=i.scene,t[3]=a):a=t[3];let o;return t[4]!==r||t[5]!==i?(o=[i,r],t[4]=r,t[5]=i,t[6]=o):o=t[6],(0,L.useEffect)(a,o),null}export{Ce as PlayerEyeOffset,$ as PlayerModel};