mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-01-19 20:25:01 +00:00
1 line
2.7 KiB
JavaScript
1 line
2.7 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,29055,e=>{"use strict";e.s(["AudioEmitter",()=>m]);var t=e.i(43476),r=e.i(71645),n=e.i(16096),u=e.i(5230),i=e.i(90072),o=e.i(62395),c=e.i(12979),l=e.i(51434),s=e.i(79123),a=e.i(89887);let f=new Map,m=(0,r.memo)(function(e){var m,p,d,h,g,y,T;let{object:x}=e,{debugMode:D}=(0,s.useDebug)(),M=null!=(m=(0,o.getProperty)(x,"fileName"))?m:"",R=null!=(p=(0,o.getFloat)(x,"volume"))?p:1,v=null!=(d=(0,o.getFloat)(x,"minDistance"))?d:1,A=null!=(h=(0,o.getFloat)(x,"maxDistance"))?h:1,F=null!=(g=(0,o.getFloat)(x,"minLoopGap"))?g:0,P=null!=(y=(0,o.getFloat)(x,"maxLoopGap"))?y:0,b=null!=(T=(0,o.getInt)(x,"is3D"))?T:0,[j,w,B]=(0,o.getPosition)(x),{scene:E,camera:L}=(0,n.useThree)(),{audioLoader:G,audioListener:U}=(0,l.useAudio)(),{audioEnabled:V}=(0,s.useSettings)(),C=(0,r.useRef)(null),K=(0,r.useRef)(null),O=(0,r.useRef)(null),S=(0,r.useRef)(!1),I=(0,r.useRef)(!1),N=(0,r.useRef)(new i.Vector3(j,w,B));(0,r.useEffect)(()=>{if(!G||!U)return;let e=new i.PositionalAudio(U);return e.position.copy(N.current),b?(e.setDistanceModel("exponential"),e.setRefDistance(v/20),e.setMaxDistance(A/25),e.setVolume(R)):(e.setDistanceModel("linear"),e.setRefDistance(1),e.setMaxDistance(2e6),e.setVolume(R/15)),C.current=e,E.add(e),()=>{K.current&&clearTimeout(K.current),O.current&&clearTimeout(O.current);try{e.stop()}catch(e){}e.disconnect(),E.remove(e),S.current=!1,I.current=!1}},[G,U,b,v,A,R,E]);let k=e=>{if(F>0||P>0){let t=Math.max(0,F),r=Math.max(t,P),n=t===r?t:Math.random()*(r-t)+t;e.loop=!1;let u=()=>{!1===e.isPlaying?K.current=setTimeout(()=>{try{e.play(),k(e)}catch(e){}},n):O.current=setTimeout(u,100)};O.current=setTimeout(u,100)}else e.setLoop(!0)};return(0,u.useFrame)(()=>{let e=C.current;if(!e||!V||!M)return;let t=L.position,r=N.current,n=t.distanceTo(r),u=I.current,i=n<=A;if(i&&!u)if(I.current=!0,S.current)try{e.isPlaying||(e.play(),k(e))}catch(e){}else{var o,l;o=(0,c.audioToUrl)(M),l=t=>{if(!e.buffer){e.setBuffer(t),S.current=!0;try{e.play(),k(e)}catch(e){}}},f.has(o)?l(f.get(o)):G.load(o,e=>{f.set(o,e),l(e)},void 0,e=>{console.error("AudioEmitter: Audio load error",o,e)})}else if(!i&&u){I.current=!1,K.current&&clearTimeout(K.current),O.current&&clearTimeout(O.current);try{e.stop()}catch(e){}}}),(0,r.useEffect)(()=>{let e=C.current;if(e&&!V){K.current&&clearTimeout(K.current),O.current&&clearTimeout(O.current);try{e.stop()}catch(e){}}},[V]),D?(0,t.jsxs)("mesh",{position:N.current,children:[(0,t.jsx)("sphereGeometry",{args:[v,12,12]}),(0,t.jsx)("meshBasicMaterial",{color:"#00ff00",wireframe:!0,opacity:.05,transparent:!0,toneMapped:!1}),(0,t.jsx)(a.FloatingLabel,{color:"#00ff00",position:[0,v+1,0],children:M})]}):null})}]); |