const wasmUrl=new URL("./sorter_no_simd_non_shared.wasm",import.meta.url).href,DIST_MAP_RANGE=1<<20,HEADER_PAGES=1,PAGE_BYTES=65536;let uv,fv,sortFn=null,memBuf=null,pIndexes=0,pCenters=0,pMappedDist=0,pFrequencies=0,pMVP=0,pIndexesOut=0,N=0;const align16=e=>e+15&-16;async function init({positions:e,splatCount:s}){const t=new Float32Array(4*s),n=3*s;for(let s=0,a=0;s<n;)t[a++]=e[s++],t[a++]=e[s++],t[a++]=e[s++],t[a++]=1;N=s;let a=65536;pIndexes=a,a=align16(a+4*N),pCenters=a,a=align16(a+4*N*4),pMappedDist=a,a=align16(a+4*N),pFrequencies=a,a=align16(a+4194304),pMVP=a,a=align16(a+64),pIndexesOut=a,a=align16(a+4*N);const r=a,i=Math.ceil(r/65536)+2;let p;memBuf=new WebAssembly.Memory({initial:i,maximum:i+4});try{const e=await fetch(wasmUrl);({instance:p}=await WebAssembly.instantiateStreaming(e,{env:{memory:memBuf}}))}catch{const e=await(await fetch(wasmUrl)).arrayBuffer();({instance:p}=await WebAssembly.instantiate(e,{env:{memory:memBuf}}))}sortFn=p.exports.sortIndexes,"function"==typeof p.exports.__wasm_call_ctors&&p.exports.__wasm_call_ctors(),fv=new Float32Array(memBuf.buffer),fv.set(t.subarray(0,4*N),pCenters>>2),uv=new Uint32Array(memBuf.buffer),uv.set(Array.from({length:N},(e,s)=>s),pIndexes>>2),self.postMessage({type:"ready"})}function sort({viewMatrix:e}){uv.fill(0,pFrequencies>>2,1048576+(pFrequencies>>2));const s=pMVP>>2;fv.set(e,s),fv[s+2]=-fv[s+2],fv[s+6]=-fv[s+6],fv[s+10]=-fv[s+10],fv[s+14]=-fv[s+14],sortFn(pIndexes,pCenters,0,pMappedDist,pFrequencies,pMVP,pIndexesOut,0,0,1048576,N,N,N,0,0,0);const t=uv.subarray(pIndexesOut>>2,(pIndexesOut>>2)+N);self.postMessage({type:"sorted",indices:t})}self.onmessage=async e=>{try{switch(e.data.type){case"init":await init(e.data);break;case"sort":sort(e.data)}}catch(e){self.postMessage({type:"error",message:String(e)})}};