import{r as a,j as x}from"./chunk-CuuP8Xz2.js";import{$ as L,j as P,B as T,n}from"./chunk-ETf0-tW6.js";import{f as g,h as v,i as C}from"./chunk-CTGhZ228.js";import"./chunk-tuBEHo31.js";/* empty css              */import"./chunk-BXl3LOEh.js";function A(r){switch(r?.toLowerCase()){case"ply":return n.PLY;case"spz":return n.SPZ;case"splat":return n.SPLAT;case"ksplat":return n.KSPLAT;case"sog":return n.PCSOGSZIP;default:return}}function D(r){const{mapLocalFileToRemote:c}=C.getState();for(const[s,i]of Object.entries(c))if(i===r)return s;return r.split(/[?#]/)[0].split("/").pop()}function O({_ref:r,_key:c,src:s,render:i="inherit",minDepth:d=1,maxDepth:m=10,...u}){const[e,h]=a.useState(null),p=g(t=>t.invalidate),j=v(t=>t.mode),S=i==="inherit"?j||"rgb":i,f=a.useCallback(()=>{p();const t=[16,50,100,500,2e3].map(o=>setTimeout(p,o));return()=>t.forEach(clearTimeout)},[p]);return a.useEffect(()=>{if(!s)return;let t=!1,o=null;return(async()=>{try{const l=D(s),y=l?.split(".").pop(),b=A(y),k=new L;b&&(k.fileType=b);const E=await k.loadAsync(s);if(t)return;const w=new P({packedSplats:E});o=w,h(w)}catch(l){console.error("Failed to load splat:",l)}})(),()=>{t=!0,o?.dispose(),h(null)}},[s]),a.useEffect(()=>{if(e){switch(S){case"depth":T.setDepthColor(e,d,m,!0);break;case"normal":T.setWorldNormalColor(e);break;case"rgb":default:e.worldModifier=void 0,e.updateGenerator();break}return f()}},[e,S,d,m,f]),a.useEffect(()=>{if(e)return f()},[e,u.position,u.rotation,u.rotation]),e?x.jsx("primitive",{ref:r,object:e,...u},c):null}export{O as default};
