t2-mapper/docs/_next/static/chunks/cb4089eec9313f48.js
2025-12-29 20:03:13 -08:00

1 line
2.6 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),i=e.i(73949),o=e.i(49774),n=e.i(90072),u=e.i(62395),c=e.i(12979),s=e.i(51434),a=e.i(79123),l=e.i(89887);let f=new Map,m=(0,r.memo)(function({object:e}){let{debugMode:m}=(0,a.useDebug)(),p=(0,u.getProperty)(e,"fileName")??"",d=(0,u.getFloat)(e,"volume")??1,h=(0,u.getFloat)(e,"minDistance")??1,g=(0,u.getFloat)(e,"maxDistance")??1,y=(0,u.getFloat)(e,"minLoopGap")??0,T=(0,u.getFloat)(e,"maxLoopGap")??0,x=(0,u.getInt)(e,"is3D")??0,[D,M,R]=(0,u.getPosition)(e),{scene:A,camera:F}=(0,i.useThree)(),{audioLoader:P,audioListener:b}=(0,s.useAudio)(),{audioEnabled:v}=(0,a.useSettings)(),j=(0,r.useRef)(null),w=(0,r.useRef)(null),B=(0,r.useRef)(null),E=(0,r.useRef)(!1),L=(0,r.useRef)(!1),_=(0,r.useRef)(new n.Vector3(D,M,R));(0,r.useEffect)(()=>{if(!P||!b)return;let e=new n.PositionalAudio(b);return e.position.copy(_.current),x?(e.setDistanceModel("exponential"),e.setRefDistance(h/20),e.setMaxDistance(g/25),e.setVolume(d)):(e.setDistanceModel("linear"),e.setRefDistance(1),e.setMaxDistance(2e6),e.setVolume(d/15)),j.current=e,A.add(e),()=>{w.current&&clearTimeout(w.current),B.current&&clearTimeout(B.current);try{e.stop()}catch(e){}e.disconnect(),A.remove(e),E.current=!1,L.current=!1}},[P,b,x,h,g,d,A]);let G=e=>{if(y>0||T>0){let t=Math.max(0,y),r=Math.max(t,T),i=t===r?t:Math.random()*(r-t)+t;e.loop=!1;let o=()=>{!1===e.isPlaying?w.current=setTimeout(()=>{try{e.play(),G(e)}catch(e){}},i):B.current=setTimeout(o,100)};B.current=setTimeout(o,100)}else e.setLoop(!0)};return(0,o.useFrame)(()=>{let e=j.current;if(!e||!v||!p)return;let t=F.position,r=_.current,i=t.distanceTo(r),o=L.current,n=i<=g;if(n&&!o)if(L.current=!0,E.current)try{e.isPlaying||(e.play(),G(e))}catch(e){}else{var u,s;u=(0,c.audioToUrl)(p),s=t=>{if(!e.buffer){e.setBuffer(t),E.current=!0;try{e.play(),G(e)}catch(e){}}},f.has(u)?s(f.get(u)):P.load(u,e=>{f.set(u,e),s(e)},void 0,e=>{console.error("AudioEmitter: Audio load error",u,e)})}else if(!n&&o){L.current=!1,w.current&&clearTimeout(w.current),B.current&&clearTimeout(B.current);try{e.stop()}catch(e){}}}),(0,r.useEffect)(()=>{let e=j.current;if(e&&!v){w.current&&clearTimeout(w.current),B.current&&clearTimeout(B.current);try{e.stop()}catch(e){}}},[v]),m?(0,t.jsxs)("mesh",{position:_.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:p})]}):null});e.s(["AudioEmitter",0,m])}]);