import{_ as e,b as t,h as n,n as r,r as i,v as a,x as o,y as s}from"./chunk/Field3dRendererImpl.js";import{t as c}from"./chunk/prepareTransfer.js";self.onmessage=l=>{self.onmessage=null;let{id:u,payload:d}=l.data;function f(e,t){self.postMessage({id:u,payload:e},t)}let p=d.fieldConfig,m=d.mode,h=new e().fromArray(d.materialSpecular),g=d.materialShininess,_=new s,v=new s,y={},b=new r;Promise.all([new Promise(e=>{b.load(p.path,e)}),...p.gamePieces.map((e,t)=>new Promise(e=>{b.load(p.path.slice(0,-4)+`_`+t.toString()+`.glb`,e)}))]).then(async e=>{let r=e.map(e=>e.scene);if(p===void 0)return;let s=0;r.forEach(async(e,l)=>{if(l===0){let r=new a;p.gamePieces.forEach(n=>{n.stagedObjects.forEach(n=>{let i=e.getObjectByName(n);if(i!==void 0){let e=i.getWorldQuaternion(new t),n=i.getWorldPosition(new o);i.removeFromParent(),i.rotation.setFromQuaternion(e),i.position.copy(n),r.add(i)}})}),r.rotation.setFromQuaternion(n(p.rotations)),r.position.set(...p.position);let s=await i(r,m,h,g,!1,p.isFTC);v=new a,s.normal.length>0&&v.add(s.normal[0]),s.transparent.length>0&&v.add(s.transparent[0]),s.carpet.length>0&&v.add(s.carpet[0]),e.rotation.setFromQuaternion(n(p.rotations)),e.position.set(...p.position);let c=await i(e,m,h,g,!0,p.isFTC,1);_=new a,c.carpet.forEach(e=>{e.name=`carpet`}),[...c.normal,...c.transparent,...c.carpet].forEach(e=>_.add(e))}else{let t=p.gamePieces[l-1];e.rotation.setFromQuaternion(n(t.rotations)),e.position.set(...t.position);let r=(await i(e,m,h,g,!1,p.isFTC)).normal;r.length>0&&(y[t.name]=r[0])}if(++s===r.length){let e=_.toJSON(),t=v.toJSON(),n={};Object.entries(y).forEach(e=>{let[t,r]=e;n[t]=r.toJSON()});let r={field:e,fieldStagedPieces:t,fieldPieces:n};f(r,c(r))}})})};