mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-16 02:40:59 +00:00
1 line
No EOL
5.3 KiB
JavaScript
1 line
No EOL
5.3 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,29055,e=>{"use strict";var t=e.i(43476),r=e.i(71645),n=e.i(15080),o=e.i(71753),u=e.i(90072),i=e.i(25645),c=e.i(12979),a=e.i(51434),s=e.i(79123),l=e.i(89887),f=e.i(58647);let d=(0,i.createLogger)("AudioEmitter"),h=new Map,p=new Map;function y(e,t=1){p.set(e,t)}function m(e){p.delete(e)}let g=0;function S(){return g}function R(){for(let[e]of(g++,p)){try{e.stop()}catch{}try{e.disconnect()}catch{}}p.clear()}function b(e,t){let r=t(e),n=r?.filename;if(!n)return null;let o=n.endsWith(".wav")?n:`${n}.wav`,u=r.description,i=null!=u?t(u):void 0,c=i?.is3D??!0,a=i?.isLooping??!1,s=i?.referenceDistance??20;return{filename:o,is3D:c,isLooping:a,refDist:s,maxDist:i?.maxDistance??100,volume:i?.volume??1}}function M(e,t,r,n,o){let i;try{i=(0,c.audioToUrl)(e.filename)}catch{return}let a=f.engineStore.getState().playback.rate,s=g;v(i,r,r=>{if(s===g)try{if(e.is3D&&o){let i=new u.PositionalAudio(t);i.setBuffer(r),i.setDistanceModel("inverse"),i.setRefDistance(e.refDist),i.setMaxDistance(e.maxDist),i.setRolloffFactor(1),i.setVolume(e.volume),i.setPlaybackRate(a),n&&i.position.copy(n),o.add(i),p.set(i,1),i.play(),i.source.onended=()=>{p.delete(i);try{i.disconnect()}catch{}o.remove(i)}}else{let n=new u.Audio(t);n.setBuffer(r),n.setVolume(e.volume),n.setPlaybackRate(a),p.set(n,1),n.play(),n.source.onended=()=>{p.delete(n);try{n.disconnect()}catch{}}}}catch{}})}function v(e,t,r){h.has(e)?r(h.get(e)):t.load(e,t=>{h.set(e,t),r(t)},void 0,t=>{d.error("Audio load error %s: %o",e,t)})}f.engineStore.subscribe(e=>e.playback.rate,e=>{for(let[t,r]of p)try{t.setPlaybackRate(r*e)}catch{}});let D=(0,r.memo)(function({entity:e}){let{debugMode:i}=(0,s.useDebug)(),f=e.audioFileName??"",d=e.audioVolume??1,h=e.audioMinDistance??1,p=e.audioMaxDistance??1,y=e.audioMinLoopGap??0,m=e.audioMaxLoopGap??0,g=e.audioIs3D??!0?1:0,S=e.audioIsLooping??!0,[R,b,M]=e.position??[0,0,0],D=(0,n.useThree)(e=>e.scene),k=(0,n.useThree)(e=>e.camera),{audioLoader:A,audioListener:T}=(0,a.useAudio)(),{audioEnabled:P}=(0,s.useSettings)(),w=(0,r.useRef)(null),x=(0,r.useRef)(null),B=(0,r.useRef)(null),E=(0,r.useRef)(!1),L=(0,r.useRef)(!1),C=(0,r.useRef)(new u.Vector3(R,b,M)),G=(0,r.useRef)(0),V=()=>{null!=x.current&&(clearTimeout(x.current),x.current=null),null!=B.current&&(clearTimeout(B.current),B.current=null)},[j]=(0,r.useState)(()=>Math.random());(0,r.useEffect)(()=>{let e;if(A&&T){if(G.current++,g){let t=new u.PositionalAudio(T);t.position.copy(C.current),t.setDistanceModel("inverse"),t.setRefDistance(h),t.setMaxDistance(p),t.setRolloffFactor(1),t.setVolume(d),e=t,D.add(e)}else(e=new u.Audio(T)).setVolume(d);return w.current=e,()=>{V();try{e.stop()}catch{}try{e.disconnect()}catch{}g&&D.remove(e),w.current=null,E.current=!1,L.current=!1}}},[A,T,g,h,p,d,D]);let F=(e,t)=>{if(S)if(y>0||m>0){let r=Math.max(0,y),n=Math.max(r,m),o=r===n?r:j*(n-r)+r;e.loop=!1;let u=()=>{t===G.current&&(!1===e.isPlaying?x.current=setTimeout(()=>{if(t===G.current)try{e.play(),F(e,t)}catch{}},o):B.current=setTimeout(u,100))};B.current=setTimeout(u,100)}else e.setLoop(!0)},U=(0,r.useEffectEvent)(e=>{if(!A)return;let t=G.current;if(E.current)try{e.isPlaying||(e.play(),F(e,t))}catch{}else{let r;try{r=(0,c.audioToUrl)(f)}catch{return}v(r,A,r=>{if(t===G.current&&!e.buffer){e.setBuffer(r),E.current=!0;try{e.play(),F(e,t)}catch{}}})}});return(0,r.useEffect)(()=>{let e=w.current;e&&!g&&P&&f&&U(e)},[P,g,f,A,T]),(0,o.useFrame)(()=>{let e=w.current;if(!e||!g||!P||!f)return;let t=k.position.distanceTo(C.current),r=L.current,n=t<=p;if(n&&!r)L.current=!0,U(e);else if(!n&&r){L.current=!1,V();try{e.stop()}catch{}}}),(0,r.useEffect)(()=>{let e=w.current;if(e&&!P){V();try{e.stop()}catch{}L.current=!1}},[P]),i?(0,t.jsxs)("mesh",{position:C.current,children:[(0,t.jsx)("sphereGeometry",{args:[h,12,12]}),(0,t.jsx)("meshBasicMaterial",{color:"#00ff00",wireframe:!0,opacity:.05,transparent:!0,toneMapped:!1}),(0,t.jsx)(l.FloatingLabel,{color:"#00ff00",position:[0,h+1,0],children:f})]}):null});e.s(["AudioEmitter",0,D,"audioBufferCache",0,h,"getCachedAudioBuffer",()=>v,"getSoundGeneration",()=>S,"playOneShotSound",()=>M,"resolveAudioProfile",()=>b,"stopAllTrackedSounds",()=>R,"trackSound",()=>y,"untrackSound",()=>m])},9962,e=>{"use strict";var t=e.i(71645),r=e.i(90072),n=e.i(12979),o=e.i(51434),u=e.i(29055),i=e.i(79123),c=e.i(58647);function a(){let{audioLoader:e,audioListener:a}=(0,o.useAudio)(),{audioEnabled:s}=(0,i.useSettings)(),l=(0,c.useEngineSelector)(e=>e.playback.streamSnapshot?.chatMessages),f=(0,c.useEngineSelector)(e=>e.playback.streamSnapshot?.timeSec),d=(0,t.useRef)(new WeakSet),h=(0,t.useRef)(new Map);return(0,t.useEffect)(()=>{if(!s||!e||!a||!l?.length||null==f)return;let t=d.current,o=h.current;for(let i of l){if(!t.has(i)){if((t.add(i),i.soundPath)&&!(Math.abs(f-i.timeSec)>2))try{let t=(0,n.audioToUrl)(i.soundPath),s=i.soundPitch??1,l=c.engineStore.getState().playback.rate,f=i.sender,d=(0,u.getSoundGeneration)();(0,u.getCachedAudioBuffer)(t,e,e=>{if(d!==(0,u.getSoundGeneration)())return;if(f){let e=o.get(f);if(e){try{e.stop()}catch{}(0,u.untrackSound)(e);try{e.disconnect()}catch{}o.delete(f)}}let t=new r.Audio(a);t.setBuffer(e),t.setPlaybackRate(s*l),(0,u.trackSound)(t,s),f&&o.set(f,t),t.play(),t.source.onended=()=>{(0,u.untrackSound)(t);try{t.disconnect()}catch{}f&&o.get(f)===t&&o.delete(f)}})}catch{}}}},[s,e,a,l,f]),null}e.s(["ChatSoundPlayer",()=>a])}]); |