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