@needle-tools/engine 4.8.0-next.9de3f45 → 4.8.0-next.c98d4ee

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/gltf-progressive--2HtE1d8.umd.cjs +8 -0
  2. package/dist/gltf-progressive-CeuEsYpY.min.js +8 -0
  3. package/dist/gltf-progressive-DY5t1MFv.js +1370 -0
  4. package/dist/loader.worker-8olmVOL4.js +1 -0
  5. package/dist/needle-engine.bundle-BGWBaskf.min.js +1607 -0
  6. package/dist/needle-engine.bundle-By9CcUKE.js +42600 -0
  7. package/dist/needle-engine.bundle-Dc3rwg_0.umd.cjs +1607 -0
  8. package/dist/needle-engine.d.ts +15 -15
  9. package/dist/needle-engine.js +591 -592
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-BzY0H7ry.min.js → postprocessing-ChsrvDkI.min.js} +54 -54
  13. package/dist/{postprocessing-vKBVFpSz.js → postprocessing-DElbMQgB.js} +479 -483
  14. package/dist/{postprocessing-Dw2OCMp4.umd.cjs → postprocessing-DtxaELce.umd.cjs} +66 -66
  15. package/dist/{three-examples-DUcCNw9s.umd.cjs → three-examples-BhQvv1B9.umd.cjs} +11 -11
  16. package/dist/{three-examples-tvuhV8Ne.js → three-examples-CM6Iip03.js} +23 -27
  17. package/dist/{three-examples-BMOhDaYR.min.js → three-examples-D2zemuAM.min.js} +12 -12
  18. package/dist/{three-mesh-ui-CxuWt7m-.js → three-mesh-ui-D6Mz5Yl7.js} +799 -810
  19. package/dist/three-mesh-ui-DWcMuyQ_.min.js +406 -0
  20. package/dist/three-mesh-ui-tt0buEDC.umd.cjs +406 -0
  21. package/dist/{vendor-BmYIgaS1.js → vendor-ClB-U1Hn.js} +10 -10
  22. package/dist/{vendor-Cavtu3CP.umd.cjs → vendor-bOWOWClg.umd.cjs} +1 -1
  23. package/package.json +3 -3
  24. package/plugins/vite/dependencies.js +28 -19
  25. package/dist/gltf-progressive-Bz6FXMZ1.min.js +0 -8
  26. package/dist/gltf-progressive-DAdiYt1v.js +0 -1392
  27. package/dist/gltf-progressive-D_S7mZaT.umd.cjs +0 -8
  28. package/dist/loader.worker-qHzhYKEC.js +0 -1
  29. package/dist/needle-engine.bundle-C5vAAuK3.js +0 -43849
  30. package/dist/needle-engine.bundle-fg0LG9Pa.umd.cjs +0 -1607
  31. package/dist/needle-engine.bundle-tepIih-J.min.js +0 -1607
  32. package/dist/three-mesh-ui-B3p3gyUz.min.js +0 -406
  33. package/dist/three-mesh-ui-CQiIQIlA.umd.cjs +0 -406
@@ -11533,19 +11533,19 @@ class ka {
11533
11533
  constructor(t, e, i) {
11534
11534
  var r, s, a, o, c, l, h, u, f, d, y, _, p, m, g;
11535
11535
  this._closedByUser = !1, this.handleOpenEvent = (v) => this.handleEvent(j.open, v), this.handleErrorEvent = (v) => this.handleEvent(j.error, v), this.handleCloseEvent = (v) => this.handleEvent(j.close, v), this.handleMessageEvent = (v) => this.handleEvent(j.message, v), this._url = t, this._protocols = e, this._options = {
11536
- buffer: i == null ? void 0 : i.buffer,
11536
+ buffer: i?.buffer,
11537
11537
  retry: {
11538
- maxRetries: (r = i == null ? void 0 : i.retry) === null || r === void 0 ? void 0 : r.maxRetries,
11539
- instantReconnect: (s = i == null ? void 0 : i.retry) === null || s === void 0 ? void 0 : s.instantReconnect,
11540
- backoff: (a = i == null ? void 0 : i.retry) === null || a === void 0 ? void 0 : a.backoff
11538
+ maxRetries: (r = i?.retry) === null || r === void 0 ? void 0 : r.maxRetries,
11539
+ instantReconnect: (s = i?.retry) === null || s === void 0 ? void 0 : s.instantReconnect,
11540
+ backoff: (a = i?.retry) === null || a === void 0 ? void 0 : a.backoff
11541
11541
  },
11542
11542
  listeners: {
11543
- open: [...(c = (o = i == null ? void 0 : i.listeners) === null || o === void 0 ? void 0 : o.open) !== null && c !== void 0 ? c : []],
11544
- close: [...(h = (l = i == null ? void 0 : i.listeners) === null || l === void 0 ? void 0 : l.close) !== null && h !== void 0 ? h : []],
11545
- error: [...(f = (u = i == null ? void 0 : i.listeners) === null || u === void 0 ? void 0 : u.error) !== null && f !== void 0 ? f : []],
11546
- message: [...(y = (d = i == null ? void 0 : i.listeners) === null || d === void 0 ? void 0 : d.message) !== null && y !== void 0 ? y : []],
11547
- retry: [...(p = (_ = i == null ? void 0 : i.listeners) === null || _ === void 0 ? void 0 : _.retry) !== null && p !== void 0 ? p : []],
11548
- reconnect: [...(g = (m = i == null ? void 0 : i.listeners) === null || m === void 0 ? void 0 : m.reconnect) !== null && g !== void 0 ? g : []]
11543
+ open: [...(c = (o = i?.listeners) === null || o === void 0 ? void 0 : o.open) !== null && c !== void 0 ? c : []],
11544
+ close: [...(h = (l = i?.listeners) === null || l === void 0 ? void 0 : l.close) !== null && h !== void 0 ? h : []],
11545
+ error: [...(f = (u = i?.listeners) === null || u === void 0 ? void 0 : u.error) !== null && f !== void 0 ? f : []],
11546
+ message: [...(y = (d = i?.listeners) === null || d === void 0 ? void 0 : d.message) !== null && y !== void 0 ? y : []],
11547
+ retry: [...(p = (_ = i?.listeners) === null || _ === void 0 ? void 0 : _.retry) !== null && p !== void 0 ? p : []],
11548
+ reconnect: [...(g = (m = i?.listeners) === null || m === void 0 ? void 0 : m.reconnect) !== null && g !== void 0 ? g : []]
11549
11549
  }
11550
11550
  }, this._underlyingWebsocket = this.tryConnect();
11551
11551
  }
@@ -1118,4 +1118,4 @@ void main() {
1118
1118
  vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
1119
1119
 
1120
1120
  #include <fog_vertex>
1121
- }`;class Cl extends oa{constructor(t){super(t),this.vector_=new O,this.vector2_=new O,this.vector3_=new O,this.quaternion_=new J,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new M.BufferGeometry,this.indexBuffer=new M.BufferAttribute(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new Je(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},e={};if(e.USE_UV="",e.USE_COLOR_ALPHA="",this.settings.material.map&&(e.USE_MAP="",e.MAP_UV=Nn(this.settings.material.map.channel),t.map=new M.Uniform$1(this.settings.material.map),t.mapTransform=new M.Uniform$1(new Xt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new M.ShaderMaterial({uniforms:t,defines:e,vertexShader:Ml,fragmentShader:Tl,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||M.AdditiveBlending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let t=0,e=0,i=0;this.systems.forEach(r=>{for(let s=0;s<r.particleNum;s++)i+=r.particles[s].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(r=>{r.emitter.updateMatrixWorld&&(r.emitter.updateWorldMatrix(!0,!1),r.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;r.emitter.matrixWorld.decompose(a,s,o);const c=r.particles,l=r.particleNum,u=this.settings.uTileCount,h=this.settings.vTileCount,f=1/u,d=1/h;for(let y=0;y<l;y++){const _=c[y],p=_.uvTile%h,m=Math.floor(_.uvTile/h+.001),g=_.previous.values();let v=g.next(),S=v.value,x=S;v.done||(v=g.next());let b;v.value!==void 0?b=v.value:b=x;for(let T=0;T<_.previous.length;T++,t+=2){if(this.positionBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(t+1,x.position.x,x.position.y,x.position.z),r.worldSpace?(this.positionBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(t+1,x.position.x,x.position.y,x.position.z)):(_.parentMatrix?this.vector_.copy(x.position).applyMatrix4(_.parentMatrix):this.vector_.copy(x.position).applyMatrix4(r.emitter.matrixWorld),this.positionBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.previousBuffer.setXYZ(t,S.position.x,S.position.y,S.position.z),this.previousBuffer.setXYZ(t+1,S.position.x,S.position.y,S.position.z)):(_.parentMatrix?this.vector_.copy(S.position).applyMatrix4(_.parentMatrix):this.vector_.copy(S.position).applyMatrix4(r.emitter.matrixWorld),this.previousBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.nextBuffer.setXYZ(t,b.position.x,b.position.y,b.position.z),this.nextBuffer.setXYZ(t+1,b.position.x,b.position.y,b.position.z)):(_.parentMatrix?this.vector_.copy(b.position).applyMatrix4(_.parentMatrix):this.vector_.copy(b.position).applyMatrix4(r.emitter.matrixWorld),this.nextBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(t,-1),this.sideBuffer.setX(t+1,1),r.worldSpace)this.widthBuffer.setX(t,x.size),this.widthBuffer.setX(t+1,x.size);else if(_.parentMatrix)this.widthBuffer.setX(t,x.size),this.widthBuffer.setX(t+1,x.size);else{const w=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(t,x.size*w),this.widthBuffer.setX(t+1,x.size*w)}this.uvBuffer.setXY(t,(T/_.previous.length+p)*f,(h-m-1)*d),this.uvBuffer.setXY(t+1,(T/_.previous.length+p)*f,(h-m)*d),this.colorBuffer.setXYZW(t,x.color.x,x.color.y,x.color.z,x.color.w),this.colorBuffer.setXYZW(t+1,x.color.x,x.color.y,x.color.z,x.color.w),T+1<_.previous.length&&(this.indexBuffer.setX(e*3,t),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+2),e++,this.indexBuffer.setX(e*3,t+2),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+3),e++),S=x,x=b,v.done||(v=g.next(),v.value!==void 0&&(b=v.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,t*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,t*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,t*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,t),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,t),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,t*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,e*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,e*3)}dispose(){this.geometry.dispose()}}class Yi{get geometry(){return this._geometry}set geometry(t){if(this._geometry=t,t===void 0||typeof t=="string")return;const e=new M.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!t.getIndex())return;const r=t.getIndex().array,s=r.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)e.setFromAttributeAndIndices(t.getAttribute("position"),r[a*3],r[a*3+1],r[a*3+2]),i+=e.getArea(),this._triangleIndexToArea.push(i);t.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(t){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new M.Vector3,this._tempB=new M.Vector3,this._tempC=new M.Vector3,t&&(this.geometry=t)}initialize(t){const e=this._geometry;if(!e||e.getIndex()===null){t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);return}const i=this._triangleIndexToArea.length-1;let r=0,s=i;const a=Math.random()*this._triangleIndexToArea[i];for(;r+1<s;){const d=Math.floor((r+s)/2);a<this._triangleIndexToArea[d]?s=d:r=d}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=e.getIndex().array[r*3],u=e.getIndex().array[r*3+1],h=e.getIndex().array[r*3+2],f=e.getAttribute("position");this._tempA.fromBufferAttribute(f,l),this._tempB.fromBufferAttribute(f,u),this._tempC.fromBufferAttribute(f,h),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),t.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),t.velocity.copy(this._tempA).normalize().multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(t,e){return new Yi(e.geometries[t.geometry])}clone(){return new Yi(this._geometry)}update(t,e){}}il({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Yi,loadJSON:Yi.fromJSON}],behaviors:[]});class is extends M.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(t,e){return t.material.side===e.material.side&&t.material.blending===e.material.blending&&t.material.blendSrc===e.material.blendSrc&&t.material.blendDst===e.material.blendDst&&t.material.blendEquation===e.material.blendEquation&&t.material.premultipliedAlpha===e.material.premultipliedAlpha&&t.material.transparent===e.material.transparent&&t.material.depthTest===e.material.depthTest&&t.material.type===e.material.type&&t.material.alphaTest===e.material.alphaTest&&t.material.map===e.material.map&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layers.mask===e.layers.mask}addSystem(t){t._renderer=this;const e=t.getRendererSettings();for(let r=0;r<this.batches.length;r++)if(is.equals(this.batches[r].settings,e)){this.batches[r].addSystem(t),this.systemToBatchIndex.set(t,r);return}let i;switch(e.renderMode){case exports.RenderMode.Trail:i=new Cl(e);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new bl(e);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(t),this.batches.push(i),this.systemToBatchIndex.set(t,this.batches.length-1),this.add(i)}deleteSystem(t){const e=this.systemToBatchIndex.get(t);e!=null&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t))}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}updateSystem(t){this.deleteSystem(t),this.addSystem(t)}update(t){this.systemToBatchIndex.forEach((e,i)=>{i.update(t)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}}const Pl=is;hl();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const aa=Math.sqrt(5),wl=(aa-1)/4,at=(5-aa)/20,ar=n=>Math.floor(n)|0,cr=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function El(n=Math.random){const t=Rl(n),e=new Float64Array(t).map(a=>cr[a%32*4]),i=new Float64Array(t).map(a=>cr[a%32*4+1]),r=new Float64Array(t).map(a=>cr[a%32*4+2]),s=new Float64Array(t).map(a=>cr[a%32*4+3]);return function(o,c,l,u){let h,f,d,y,_;const p=(o+c+l+u)*wl,m=ar(o+p),g=ar(c+p),v=ar(l+p),S=ar(u+p),x=(m+g+v+S)*at,b=m-x,T=g-x,w=v-x,C=S-x,P=o-b,R=c-T,E=l-w,A=u-C;let k=0,z=0,U=0,L=0;P>R?k++:z++,P>E?k++:U++,P>A?k++:L++,R>E?z++:U++,R>A?z++:L++,E>A?U++:L++;const I=k>=3?1:0,X=z>=3?1:0,Z=U>=3?1:0,it=L>=3?1:0,K=k>=2?1:0,pt=z>=2?1:0,mt=U>=2?1:0,rt=L>=2?1:0,W=k>=1?1:0,j=z>=1?1:0,Ht=U>=1?1:0,Dt=L>=1?1:0,Lt=P-I+at,Vt=R-X+at,vt=E-Z+at,At=A-it+at,_t=P-K+2*at,Yt=R-pt+2*at,Zt=E-mt+2*at,H=A-rt+2*at,Jt=P-W+3*at,Qt=R-j+3*at,ve=E-Ht+3*at,Kt=A-Dt+3*at,te=P-1+4*at,ee=R-1+4*at,ie=E-1+4*at,re=A-1+4*at,kt=m&255,zt=g&255,Bt=v&255,Ot=S&255;let V=.6-P*P-R*R-E*E-A*A;if(V<0)h=0;else{const q=kt+t[zt+t[Bt+t[Ot]]];V*=V,h=V*V*(e[q]*P+i[q]*R+r[q]*E+s[q]*A)}let We=.6-Lt*Lt-Vt*Vt-vt*vt-At*At;if(We<0)f=0;else{const q=kt+I+t[zt+X+t[Bt+Z+t[Ot+it]]];We*=We,f=We*We*(e[q]*Lt+i[q]*Vt+r[q]*vt+s[q]*At)}let He=.6-_t*_t-Yt*Yt-Zt*Zt-H*H;if(He<0)d=0;else{const q=kt+K+t[zt+pt+t[Bt+mt+t[Ot+rt]]];He*=He,d=He*He*(e[q]*_t+i[q]*Yt+r[q]*Zt+s[q]*H)}let Ye=.6-Jt*Jt-Qt*Qt-ve*ve-Kt*Kt;if(Ye<0)y=0;else{const q=kt+W+t[zt+j+t[Bt+Ht+t[Ot+Dt]]];Ye*=Ye,y=Ye*Ye*(e[q]*Jt+i[q]*Qt+r[q]*ve+s[q]*Kt)}let Ze=.6-te*te-ee*ee-ie*ie-re*re;if(Ze<0)_=0;else{const q=kt+1+t[zt+1+t[Bt+1+t[Ot+1]]];Ze*=Ze,_=Ze*Ze*(e[q]*te+i[q]*ee+r[q]*ie+s[q]*re)}return 27*(h+f+d+y+_)}}function Rl(n){const e=new Uint8Array(512);for(let i=0;i<512/2;i++)e[i]=i;for(let i=0;i<512/2-1;i++){const r=i+~~(n()*(256-i)),s=e[i];e[i]=e[r],e[r]=s}for(let i=256;i<512;i++)e[i]=e[i-256];return e}class Al{constructor(t,e){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Base must be a positive integer or zero");if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=t,this.expMax=e,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var G;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(G||(G={}));class ca{constructor(t,e,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,g;this._closedByUser=!1,this.handleOpenEvent=v=>this.handleEvent(G.open,v),this.handleErrorEvent=v=>this.handleEvent(G.error,v),this.handleCloseEvent=v=>this.handleEvent(G.close,v),this.handleMessageEvent=v=>this.handleEvent(G.message,v),this._url=t,this._protocols=e,this._options={buffer:i==null?void 0:i.buffer,retry:{maxRetries:(r=i==null?void 0:i.retry)===null||r===void 0?void 0:r.maxRetries,instantReconnect:(s=i==null?void 0:i.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=i==null?void 0:i.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=i==null?void 0:i.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=i==null?void 0:i.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(f=(h=i==null?void 0:i.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[]],message:[...(y=(d=i==null?void 0:i.listeners)===null||d===void 0?void 0:d.message)!==null&&y!==void 0?y:[]],retry:[...(p=(_=i==null?void 0:i.listeners)===null||_===void 0?void 0:_.retry)!==null&&p!==void 0?p:[]],reconnect:[...(g=(m=i==null?void 0:i.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&g!==void 0?g:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(t){this._underlyingWebsocket.binaryType=t}send(t){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(t):this.buffer!==void 0&&this.buffer.add(t))}close(t,e){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(t,e)}addEventListener(t,e,i){this._options.listeners[t].push({listener:e,options:i})}removeEventListener(t,e,i){const r=s=>s.listener!==e||s.options!==i;this._options.listeners[t]=this._options.listeners[t].filter(r)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(t,e){const i=this._options.listeners[t],r=[];i.forEach(({listener:s,options:a})=>{s(this,e),(a===void 0||a.once===void 0||!a.once)&&r.push({listener:s,options:a})}),this._options.listeners[t]=r}handleEvent(t,e){switch(t){case G.close:this.dispatchEvent(t,e),this.scheduleConnectionRetryIfNeeded();break;case G.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},r=new CustomEvent(G.reconnect,{detail:i});this.dispatchEvent(G.reconnect,r),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(t,e),this.sendBufferedData();break;case G.retry:this.dispatchEvent(t,e),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(t,e);break}}sendBufferedData(){if(this.buffer!==void 0)for(let t=this.buffer.read();t!==void 0;t=this.buffer.read())this.send(t)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const t=i=>{const r=new CustomEvent(G.retry,{detail:i});this.handleEvent(G.retry,r)},e={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||e.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>t(e),e.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class kl{constructor(t){this._url=t}get url(){return this._url}withProtocols(t){return this._protocols=t,this}get protocols(){return this._protocols}withMaxRetries(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{maxRetries:t})}),this}get maxRetries(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.maxRetries}withInstantReconnect(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{instantReconnect:t})}),this}get instantReconnect(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.instantReconnect}withBackoff(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{backoff:t})}),this}get backoff(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.backoff}withBuffer(t){return this._options=Object.assign(Object.assign({},this._options),{buffer:t}),this}get buffer(){var t;return(t=this._options)===null||t===void 0?void 0:t.buffer}onOpen(t,e){return this.addListener(G.open,t,e),this}onClose(t,e){return this.addListener(G.close,t,e),this}onError(t,e){return this.addListener(G.error,t,e),this}onMessage(t,e){return this.addListener(G.message,t,e),this}onRetry(t,e){return this.addListener(G.retry,t,e),this}onReconnect(t,e){return this.addListener(G.reconnect,t,e),this}build(){return new ca(this._url,this._protocols,this._options)}addListener(t,e,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,g,v,S,x,b,T,w;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(r=this._options)===null||r===void 0?void 0:r.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(f=(h=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[],message:(_=(y=(d=this._options)===null||d===void 0?void 0:d.listeners)===null||y===void 0?void 0:y.message)!==null&&_!==void 0?_:[],retry:(g=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.retry)!==null&&g!==void 0?g:[],reconnect:(x=(S=(v=this._options)===null||v===void 0?void 0:v.listeners)===null||S===void 0?void 0:S.reconnect)!==null&&x!==void 0?x:[],[t]:[...(w=(T=(b=this._options)===null||b===void 0?void 0:b.listeners)===null||T===void 0?void 0:T[t])!==null&&w!==void 0?w:[],{listener:e,options:i}]}}),this}}const zl=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Al,Websocket:ca,WebsocketBuilder:kl,get WebsocketEvent(){return G}},Symbol.toStringTag,{value:"Module"})),rs=0,la=1,ua=2,Fn=2,dn=1.25,$s=1,mi=32,$r=65535,Bl=Math.pow(2,-24),pn=Symbol("SKIP_GENERATION");function Ol(n){return n.index?n.index.count:n.attributes.position.count}function Xe(n){return Ol(n)/3}function Il(n,t=ArrayBuffer){return n>65535?new Uint32Array(new t(4*n)):new Uint16Array(new t(2*n))}function Ul(n,t){if(!n.index){const e=n.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Il(e,i);n.setIndex(new M.BufferAttribute(r,1));for(let s=0;s<e;s++)r[s]=s}}function ha(n,t){const e=Xe(n),i=t||n.drawRange,r=i.start/3,s=(i.start+i.count)/3,a=Math.max(0,r),o=Math.min(e,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function fa(n,t){if(!n.groups||!n.groups.length)return ha(n,t);const e=[],i=new Set,r=t||n.drawRange,s=r.start/3,a=(r.start+r.count)/3;for(const c of n.groups){const l=c.start/3,u=(c.start+c.count)/3;i.add(Math.max(s,l)),i.add(Math.min(a,u))}const o=Array.from(i.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],u=o[c+1];e.push({offset:Math.floor(l),count:Math.floor(u-l)})}return e}function Nl(n,t){const e=Xe(n),i=fa(n,t).sort((a,o)=>a.offset-o.offset),r=i[i.length-1];r.count=Math.min(e-r.offset,r.count);let s=0;return i.forEach(({count:a})=>s+=a),e!==s}function mn(n,t,e,i,r){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,h=1/0,f=1/0,d=1/0,y=-1/0,_=-1/0,p=-1/0;for(let m=t*6,g=(t+e)*6;m<g;m+=6){const v=n[m+0],S=n[m+1],x=v-S,b=v+S;x<s&&(s=x),b>c&&(c=b),v<h&&(h=v),v>y&&(y=v);const T=n[m+2],w=n[m+3],C=T-w,P=T+w;C<a&&(a=C),P>l&&(l=P),T<f&&(f=T),T>_&&(_=T);const R=n[m+4],E=n[m+5],A=R-E,k=R+E;A<o&&(o=A),k>u&&(u=k),R<d&&(d=R),R>p&&(p=R)}i[0]=s,i[1]=a,i[2]=o,i[3]=c,i[4]=l,i[5]=u,r[0]=h,r[1]=f,r[2]=d,r[3]=y,r[4]=_,r[5]=p}function Fl(n,t=null,e=null,i=null){const r=n.attributes.position,s=n.index?n.index.array:null,a=Xe(n),o=r.normalized;let c;t===null?(c=new Float32Array(a*6),e=0,i=a):(c=t,e=e||0,i=i||a);const l=r.array,u=r.offset||0;let h=3;r.isInterleavedBufferAttribute&&(h=r.data.stride);const f=["getX","getY","getZ"];for(let d=e;d<e+i;d++){const y=d*3,_=d*6;let p=y+0,m=y+1,g=y+2;s&&(p=s[p],m=s[m],g=s[g]),o||(p=p*h+u,m=m*h+u,g=g*h+u);for(let v=0;v<3;v++){let S,x,b;o?(S=r[f[v]](p),x=r[f[v]](m),b=r[f[v]](g)):(S=l[p+v],x=l[m+v],b=l[g+v]);let T=S;x<T&&(T=x),b<T&&(T=b);let w=S;x>w&&(w=x),b>w&&(w=b);const C=(w-T)/2,P=v*2;c[_+P+0]=T+C,c[_+P+1]=C+(Math.abs(T)+C)*Bl}}return c}function Y(n,t,e){return e.min.x=t[n],e.min.y=t[n+1],e.min.z=t[n+2],e.max.x=t[n+3],e.max.y=t[n+4],e.max.z=t[n+5],e}function qs(n){let t=-1,e=-1/0;for(let i=0;i<3;i++){const r=n[i+3]-n[i];r>e&&(e=r,t=i)}return t}function Xs(n,t){t.set(n)}function Ws(n,t,e){let i,r;for(let s=0;s<3;s++){const a=s+3;i=n[s],r=t[s],e[s]=i<r?i:r,i=n[a],r=t[a],e[a]=i>r?i:r}}function lr(n,t,e){for(let i=0;i<3;i++){const r=t[n+2*i],s=t[n+2*i+1],a=r-s,o=r+s;a<e[i]&&(e[i]=a),o>e[i+3]&&(e[i+3]=o)}}function ei(n){const t=n[3]-n[0],e=n[4]-n[1],i=n[5]-n[2];return 2*(t*e+e*i+i*t)}const ne=32,Dl=(n,t)=>n.candidate-t.candidate,fe=new Array(ne).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ur=new Float32Array(6);function Ll(n,t,e,i,r,s){let a=-1,o=0;if(s===rs)a=qs(t),a!==-1&&(o=(t[a]+t[a+3])/2);else if(s===la)a=qs(n),a!==-1&&(o=Vl(e,i,r,a));else if(s===ua){const c=ei(n);let l=dn*r;const u=i*6,h=(i+r)*6;for(let f=0;f<3;f++){const d=t[f],p=(t[f+3]-d)/ne;if(r<ne/4){const m=[...fe];m.length=r;let g=0;for(let S=u;S<h;S+=6,g++){const x=m[g];x.candidate=e[S+2*f],x.count=0;const{bounds:b,leftCacheBounds:T,rightCacheBounds:w}=x;for(let C=0;C<3;C++)w[C]=1/0,w[C+3]=-1/0,T[C]=1/0,T[C+3]=-1/0,b[C]=1/0,b[C+3]=-1/0;lr(S,e,b)}m.sort(Dl);let v=r;for(let S=0;S<v;S++){const x=m[S];for(;S+1<v&&m[S+1].candidate===x.candidate;)m.splice(S+1,1),v--}for(let S=u;S<h;S+=6){const x=e[S+2*f];for(let b=0;b<v;b++){const T=m[b];x>=T.candidate?lr(S,e,T.rightCacheBounds):(lr(S,e,T.leftCacheBounds),T.count++)}}for(let S=0;S<v;S++){const x=m[S],b=x.count,T=r-x.count,w=x.leftCacheBounds,C=x.rightCacheBounds;let P=0;b!==0&&(P=ei(w)/c);let R=0;T!==0&&(R=ei(C)/c);const E=$s+dn*(P*b+R*T);E<l&&(a=f,l=E,o=x.candidate)}}else{for(let v=0;v<ne;v++){const S=fe[v];S.count=0,S.candidate=d+p+v*p;const x=S.bounds;for(let b=0;b<3;b++)x[b]=1/0,x[b+3]=-1/0}for(let v=u;v<h;v+=6){let b=~~((e[v+2*f]-d)/p);b>=ne&&(b=ne-1);const T=fe[b];T.count++,lr(v,e,T.bounds)}const m=fe[ne-1];Xs(m.bounds,m.rightCacheBounds);for(let v=ne-2;v>=0;v--){const S=fe[v],x=fe[v+1];Ws(S.bounds,x.rightCacheBounds,S.rightCacheBounds)}let g=0;for(let v=0;v<ne-1;v++){const S=fe[v],x=S.count,b=S.bounds,w=fe[v+1].rightCacheBounds;x!==0&&(g===0?Xs(b,ur):Ws(b,ur,ur)),g+=x;let C=0,P=0;g!==0&&(C=ei(ur)/c);const R=r-g;R!==0&&(P=ei(w)/c);const E=$s+dn*(C*g+P*R);E<l&&(a=f,l=E,o=S.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Vl(n,t,e,i){let r=0;for(let s=t,a=t+e;s<a;s++)r+=n[s*6+i*2];return r/e}class yn{constructor(){this.boundingData=new Float32Array(6)}}function Jl(n,t,e,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&e[a*6+l]<c;)a++;for(;a<=o&&e[o*6+l]>=c;)o--;if(a<o){for(let u=0;u<3;u++){let h=t[a*3+u];t[a*3+u]=t[o*3+u],t[o*3+u]=h}for(let u=0;u<6;u++){let h=e[a*6+u];e[a*6+u]=e[o*6+u],e[o*6+u]=h}a++,o--}else return a}}function Gl(n,t,e,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&e[a*6+l]<c;)a++;for(;a<=o&&e[o*6+l]>=c;)o--;if(a<o){let u=n[a];n[a]=n[o],n[o]=u;for(let h=0;h<6;h++){let f=e[a*6+h];e[a*6+h]=e[o*6+h],e[o*6+h]=f}a++,o--}else return a}}function St(n,t){return t[n+15]===65535}function Mt(n,t){return t[n+6]}function Ct(n,t){return t[n+14]}function Pt(n){return n+8}function wt(n,t){return t[n+6]}function da(n,t){return t[n+7]}let pa,fi,Ar,ma;const jl=Math.pow(2,32);function Dn(n){return"count"in n?1:1+Dn(n.left)+Dn(n.right)}function $l(n,t,e){return pa=new Float32Array(e),fi=new Uint32Array(e),Ar=new Uint16Array(e),ma=new Uint8Array(e),Ln(n,t)}function Ln(n,t){const e=n/4,i=n/2,r="count"in t,s=t.boundingData;for(let a=0;a<6;a++)pa[e+a]=s[a];if(r)if(t.buffer){const a=t.buffer;ma.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=mi){const l=o/2;St(l,Ar)||(fi[o/4+6]+=e)}return n+a.byteLength}else{const a=t.offset,o=t.count;return fi[e+6]=a,Ar[i+14]=o,Ar[i+15]=$r,n+mi}else{const a=t.left,o=t.right,c=t.splitAxis;let l;if(l=Ln(n+mi,a),l/4>jl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return fi[e+6]=l/4,l=Ln(l,o),fi[e+7]=c,l}}function ql(n,t){const e=(n.index?n.index.count:n.attributes.position.count)/3,i=e>2**16,r=i?4:2,s=t?new SharedArrayBuffer(e*r):new ArrayBuffer(e*r),a=i?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Xl(n,t,e,i,r){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:u}=r,h=n._indirectBuffer,f=n.geometry,d=f.index?f.index.array:null,y=u?Gl:Jl,_=Xe(f),p=new Float32Array(6);let m=!1;const g=new yn;return mn(t,e,i,g.boundingData,p),S(g,e,i,p),g;function v(x){l&&l(x/_)}function S(x,b,T,w=null,C=0){if(!m&&C>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(f))),T<=o||C>=s)return v(b+T),x.offset=b,x.count=T,x;const P=Ll(x.boundingData,w,t,b,T,c);if(P.axis===-1)return v(b+T),x.offset=b,x.count=T,x;const R=y(h,d,t,b,T,P);if(R===b||R===b+T)v(b+T),x.offset=b,x.count=T;else{x.splitAxis=P.axis;const E=new yn,A=b,k=R-b;x.left=E,mn(t,A,k,E.boundingData,p),S(E,A,k,p,C+1);const z=new yn,U=R,L=T-k;x.right=z,mn(t,U,L,z.boundingData,p),S(z,U,L,p,C+1)}return x}}function Wl(n,t){const e=n.geometry;t.indirect&&(n._indirectBuffer=ql(e,t.useSharedArrayBuffer),Nl(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||Ul(e,t);const i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Fl(e),s=t.indirect?ha(e,t.range):fa(e,t.range);n._roots=s.map(a=>{const o=Xl(n,r,a.offset,a.count,t),c=Dn(o),l=new i(mi*c);return $l(0,o,l),l})}class le{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,r=-1/0;for(let s=0,a=t.length;s<a;s++){const c=t[s][e];i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}setFromPoints(t,e){let i=1/0,r=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s],c=t.dot(o);i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}isSeparated(t){return this.min>t.max||t.min>this.max}}le.prototype.setFromBox=function(){const n=new M.Vector3;return function(e,i){const r=i.min,s=i.max;let a=1/0,o=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){n.x=r.x*c+s.x*(1-c),n.y=r.y*l+s.y*(1-l),n.z=r.z*u+s.z*(1-u);const h=e.dot(n);a=Math.min(h,a),o=Math.max(h,o)}this.min=a,this.max=o}}();const Hl=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Vector3;return function(r,s,a){const o=r.start,c=n,l=s.start,u=t;e.subVectors(o,l),n.subVectors(r.end,r.start),t.subVectors(s.end,s.start);const h=e.dot(u),f=u.dot(c),d=u.dot(u),y=e.dot(c),p=c.dot(c)*d-f*f;let m,g;p!==0?m=(h*f-y*d)/p:m=0,g=(h+m*f)/d,a.x=m,a.y=g}}(),ns=function(){const n=new M.Vector2,t=new M.Vector3,e=new M.Vector3;return function(r,s,a,o){Hl(r,s,n);let c=n.x,l=n.y;if(c>=0&&c<=1&&l>=0&&l<=1){r.at(c,a),s.at(l,o);return}else if(c>=0&&c<=1){l<0?s.at(0,o):s.at(1,o),r.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?r.at(0,a):r.at(1,a),s.closestPointToPoint(a,!0,o);return}else{let u;c<0?u=r.start:u=r.end;let h;l<0?h=s.start:h=s.end;const f=t,d=e;if(r.closestPointToPoint(h,!0,t),s.closestPointToPoint(u,!0,e),f.distanceToSquared(h)<=d.distanceToSquared(u)){a.copy(f),o.copy(h);return}else{a.copy(u),o.copy(d);return}}}}(),Yl=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Plane,i=new M.Line3;return function(s,a){const{radius:o,center:c}=s,{a:l,b:u,c:h}=a;if(i.start=l,i.end=u,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o||(i.start=l,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o)||(i.start=u,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o))return!0;const _=a.getPlane(e);if(Math.abs(_.distanceToPoint(c))<=o){const m=_.projectPoint(c,t);if(a.containsPoint(m))return!0}return!1}}(),Zl=1e-15;function gn(n){return Math.abs(n)<Zl}class Rt extends M.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M.Vector3),this.satBounds=new Array(4).fill().map(()=>new le),this.points=[this.a,this.b,this.c],this.sphere=new M.Sphere,this.plane=new M.Plane,this.needsUpdate=!0}intersectsSphere(t){return Yl(t,this)}update(){const t=this.a,e=this.b,i=this.c,r=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,r);const l=s[1],u=a[1];l.subVectors(t,e),u.setFromPoints(l,r);const h=s[2],f=a[2];h.subVectors(e,i),f.setFromPoints(h,r);const d=s[3],y=a[3];d.subVectors(i,t),y.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Rt.prototype.closestPointToSegment=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Line3;return function(r,s=null,a=null){const{start:o,end:c}=r,l=this.points;let u,h=1/0;for(let f=0;f<3;f++){const d=(f+1)%3;e.start.copy(l[f]),e.end.copy(l[d]),ns(e,r,n,t),u=n.distanceToSquared(t),u<h&&(h=u,s&&s.copy(n),a&&a.copy(t))}return this.closestPointToPoint(o,n),u=o.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(o)),this.closestPointToPoint(c,n),u=c.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(c)),Math.sqrt(h)}}();Rt.prototype.intersectsTriangle=function(){const n=new Rt,t=new Array(3),e=new Array(3),i=new le,r=new le,s=new M.Vector3,a=new M.Vector3,o=new M.Vector3,c=new M.Vector3,l=new M.Vector3,u=new M.Line3,h=new M.Line3,f=new M.Line3,d=new M.Vector3;function y(_,p,m){const g=_.points;let v=0,S=-1;for(let x=0;x<3;x++){const{start:b,end:T}=u;b.copy(g[x]),T.copy(g[(x+1)%3]),u.delta(a);const w=gn(p.distanceToPoint(b));if(gn(p.normal.dot(a))&&w){m.copy(u),v=2;break}const C=p.intersectLine(u,d);if(!C&&w&&d.copy(b),(C||w)&&!gn(d.distanceTo(T))){if(v<=1)(v===1?m.start:m.end).copy(d),w&&(S=v);else if(v>=2){(S===1?m.start:m.end).copy(d),v=2;break}if(v++,v===2&&S===-1)break}}return v}return function(p,m=null,g=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(n.copy(p),n.update(),p=n);const v=this.plane,S=p.plane;if(Math.abs(v.normal.dot(S.normal))>1-1e-10){const x=this.satBounds,b=this.satAxes;e[0]=p.a,e[1]=p.b,e[2]=p.c;for(let C=0;C<4;C++){const P=x[C],R=b[C];if(i.setFromPoints(R,e),P.isSeparated(i))return!1}const T=p.satBounds,w=p.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let C=0;C<4;C++){const P=T[C],R=w[C];if(i.setFromPoints(R,t),P.isSeparated(i))return!1}for(let C=0;C<4;C++){const P=b[C];for(let R=0;R<4;R++){const E=w[R];if(s.crossVectors(P,E),i.setFromPoints(s,t),r.setFromPoints(s,e),i.isSeparated(r))return!1}}return m&&(g||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),m.start.set(0,0,0),m.end.set(0,0,0)),!0}else{const x=y(this,S,h);if(x===1&&p.containsPoint(h.end))return m&&(m.start.copy(h.end),m.end.copy(h.end)),!0;if(x!==2)return!1;const b=y(p,v,f);if(b===1&&this.containsPoint(f.end))return m&&(m.start.copy(f.end),m.end.copy(f.end)),!0;if(b!==2)return!1;if(h.delta(o),f.delta(c),o.dot(c)<0){let A=f.start;f.start=f.end,f.end=A}const T=h.start.dot(o),w=h.end.dot(o),C=f.start.dot(o),P=f.end.dot(o),R=w<C,E=T<P;return T!==P&&C!==w&&R===E?!1:(m&&(l.subVectors(h.start,f.start),l.dot(o)>0?m.start.copy(h.start):m.start.copy(f.start),l.subVectors(h.end,f.end),l.dot(o)<0?m.end.copy(h.end):m.end.copy(f.end)),!0)}}}();Rt.prototype.distanceToPoint=function(){const n=new M.Vector3;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}();Rt.prototype.distanceToTriangle=function(){const n=new M.Vector3,t=new M.Vector3,e=["a","b","c"],i=new M.Line3,r=new M.Line3;return function(a,o=null,c=null){const l=o||c?i:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let u=1/0;for(let h=0;h<3;h++){let f;const d=e[h],y=a[d];this.closestPointToPoint(y,n),f=y.distanceToSquared(n),f<u&&(u=f,o&&o.copy(n),c&&c.copy(y));const _=this[d];a.closestPointToPoint(_,n),f=_.distanceToSquared(n),f<u&&(u=f,o&&o.copy(_),c&&c.copy(n))}for(let h=0;h<3;h++){const f=e[h],d=e[(h+1)%3];i.set(this[f],this[d]);for(let y=0;y<3;y++){const _=e[y],p=e[(y+1)%3];r.set(a[_],a[p]),ns(i,r,n,t);const m=n.distanceToSquared(t);m<u&&(u=m,o&&o.copy(n),c&&c.copy(t))}}return Math.sqrt(u)}}();class dt{constructor(t,e,i){this.isOrientedBox=!0,this.min=new M.Vector3,this.max=new M.Vector3,this.matrix=new M.Matrix4,this.invMatrix=new M.Matrix4,this.points=new Array(8).fill().map(()=>new M.Vector3),this.satAxes=new Array(3).fill().map(()=>new M.Vector3),this.satBounds=new Array(3).fill().map(()=>new le),this.alignedSatBounds=new Array(3).fill().map(()=>new le),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}dt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,r=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){const f=1*l|2*u|4*h,d=r[f];d.x=l?i.x:e.x,d.y=u?i.y:e.y,d.z=h?i.z:e.z,d.applyMatrix4(t)}const s=this.satBounds,a=this.satAxes,o=r[0];for(let l=0;l<3;l++){const u=a[l],h=s[l],f=1<<l,d=r[f];u.subVectors(o,d),h.setFromPoints(u,r)}const c=this.alignedSatBounds;c[0].setFromPointsField(r,"x"),c[1].setFromPointsField(r,"y"),c[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();dt.prototype.intersectsBox=function(){const n=new le;return function(e){this.needsUpdate&&this.update();const i=e.min,r=e.max,s=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(n.min=i.x,n.max=r.x,o[0].isSeparated(n)||(n.min=i.y,n.max=r.y,o[1].isSeparated(n))||(n.min=i.z,n.max=r.z,o[2].isSeparated(n)))return!1;for(let c=0;c<3;c++){const l=a[c],u=s[c];if(n.setFromBox(l,e),u.isSeparated(n))return!1}return!0}}();dt.prototype.intersectsTriangle=function(){const n=new Rt,t=new Array(3),e=new le,i=new le,r=new M.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(n.copy(a),n.update(),a=n);const o=this.satBounds,c=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let f=0;f<3;f++){const d=o[f],y=c[f];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const l=a.satBounds,u=a.satAxes,h=this.points;for(let f=0;f<3;f++){const d=l[f],y=u[f];if(e.setFromPoints(y,h),d.isSeparated(e))return!1}for(let f=0;f<3;f++){const d=c[f];for(let y=0;y<4;y++){const _=u[y];if(r.crossVectors(d,_),e.setFromPoints(r,t),i.setFromPoints(r,h),e.isSeparated(i))return!1}}return!0}}();dt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}();dt.prototype.distanceToPoint=function(){const n=new M.Vector3;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}();dt.prototype.distanceToBox=function(){const n=["x","y","z"],t=new Array(12).fill().map(()=>new M.Line3),e=new Array(12).fill().map(()=>new M.Line3),i=new M.Vector3,r=new M.Vector3;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(r),this.closestPointToPoint(r,i),a.closestPointToPoint(i,r),c&&c.copy(i),l&&l.copy(r)),0;const u=o*o,h=a.min,f=a.max,d=this.points;let y=1/0;for(let p=0;p<8;p++){const m=d[p];r.copy(m).clamp(h,f);const g=m.distanceToSquared(r);if(g<y&&(y=g,c&&c.copy(m),l&&l.copy(r),g<u))return Math.sqrt(g)}let _=0;for(let p=0;p<3;p++)for(let m=0;m<=1;m++)for(let g=0;g<=1;g++){const v=(p+1)%3,S=(p+2)%3,x=m<<v|g<<S,b=1<<p|m<<v|g<<S,T=d[x],w=d[b];t[_].set(T,w);const P=n[p],R=n[v],E=n[S],A=e[_],k=A.start,z=A.end;k[P]=h[P],k[R]=m?h[R]:f[R],k[E]=g?h[E]:f[R],z[P]=f[P],z[R]=m?h[R]:f[R],z[E]=g?h[E]:f[R],_++}for(let p=0;p<=1;p++)for(let m=0;m<=1;m++)for(let g=0;g<=1;g++){r.x=p?f.x:h.x,r.y=m?f.y:h.y,r.z=g?f.z:h.z,this.closestPointToPoint(r,i);const v=r.distanceToSquared(i);if(v<y&&(y=v,c&&c.copy(i),l&&l.copy(r),v<u))return Math.sqrt(v)}for(let p=0;p<12;p++){const m=t[p];for(let g=0;g<12;g++){const v=e[g];ns(m,v,i,r);const S=i.distanceToSquared(r);if(S<y&&(y=S,c&&c.copy(i),l&&l.copy(r),S<u))return Math.sqrt(S)}}return Math.sqrt(y)}}();class ss{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Ql extends ss{constructor(){super(()=>new Rt)}}const Et=new Ql;class Kl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const $=new Kl;let ye,Ve;const Be=[],hr=new ss(()=>new M.Box3);function tu(n,t,e,i,r,s){ye=hr.getPrimitive(),Ve=hr.getPrimitive(),Be.push(ye,Ve),$.setBuffer(n._roots[t]);const a=Vn(0,n.geometry,e,i,r,s);$.clearBuffer(),hr.releasePrimitive(ye),hr.releasePrimitive(Ve),Be.pop(),Be.pop();const o=Be.length;return o>0&&(Ve=Be[o-1],ye=Be[o-2]),a}function Vn(n,t,e,i,r=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=$;let u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);return Y(n,o,ye),i(f,d,!1,a,s+n,ye)}else{let P=function(E){const{uint16Array:A,uint32Array:k}=$;let z=E*2;for(;!St(z,A);)E=Pt(E),z=E*2;return Mt(E,k)},R=function(E){const{uint16Array:A,uint32Array:k}=$;let z=E*2;for(;!St(z,A);)E=wt(E,k),z=E*2;return Mt(E,k)+Ct(z,A)};const f=Pt(n),d=wt(n,l);let y=f,_=d,p,m,g,v;if(r&&(g=ye,v=Ve,Y(y,o,g),Y(_,o,v),p=r(g),m=r(v),m<p)){y=d,_=f;const E=p;p=m,m=E,g=v}g||(g=ye,Y(y,o,g));const S=St(y*2,c),x=e(g,S,p,a+1,s+y);let b;if(x===Fn){const E=P(y),k=R(y)-E;b=i(E,k,!0,a+1,s+y,g)}else b=x&&Vn(y,t,e,i,r,s,a+1);if(b)return!0;v=Ve,Y(_,o,v);const T=St(_*2,c),w=e(v,T,m,a+1,s+_);let C;if(w===Fn){const E=P(_),k=R(_)-E;C=i(E,k,!0,a+1,s+_,v)}else C=w&&Vn(_,t,e,i,r,s,a+1);return!!C}}const ii=new M.Vector3,vn=new M.Vector3;function eu(n,t,e={},i=0,r=1/0){const s=i*i,a=r*r;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:u=>(ii.copy(t).clamp(u.min,u.max),ii.distanceToSquared(t)),intersectsBounds:(u,h,f)=>f<o&&f<a,intersectsTriangle:(u,h)=>{u.closestPointToPoint(t,ii);const f=t.distanceToSquared(ii);return f<o&&(vn.copy(ii),o=f,c=h),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return e.point?e.point.copy(vn):e.point=vn.clone(),e.distance=l,e.faceIndex=c,e}const iu=parseInt(M.REVISION)>=169,Se=new M.Vector3,be=new M.Vector3,Te=new M.Vector3,fr=new M.Vector2,dr=new M.Vector2,pr=new M.Vector2,Hs=new M.Vector3,Ys=new M.Vector3,Zs=new M.Vector3,ri=new M.Vector3;function ru(n,t,e,i,r,s,a,o){let c;if(s===M.BackSide?c=n.intersectTriangle(i,e,t,!0,r):c=n.intersectTriangle(t,e,i,s!==M.DoubleSide,r),c===null)return null;const l=n.origin.distanceTo(r);return l<a||l>o?null:{distance:l,point:r.clone()}}function nu(n,t,e,i,r,s,a,o,c,l,u){Se.fromBufferAttribute(t,s),be.fromBufferAttribute(t,a),Te.fromBufferAttribute(t,o);const h=ru(n,Se,be,Te,ri,c,l,u);if(h){const f=new M.Vector3;M.Triangle.getBarycoord(ri,Se,be,Te,f),i&&(fr.fromBufferAttribute(i,s),dr.fromBufferAttribute(i,a),pr.fromBufferAttribute(i,o),h.uv=M.Triangle.getInterpolation(ri,Se,be,Te,fr,dr,pr,new M.Vector2)),r&&(fr.fromBufferAttribute(r,s),dr.fromBufferAttribute(r,a),pr.fromBufferAttribute(r,o),h.uv1=M.Triangle.getInterpolation(ri,Se,be,Te,fr,dr,pr,new M.Vector2)),e&&(Hs.fromBufferAttribute(e,s),Ys.fromBufferAttribute(e,a),Zs.fromBufferAttribute(e,o),h.normal=M.Triangle.getInterpolation(ri,Se,be,Te,Hs,Ys,Zs,new M.Vector3),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:s,b:a,c:o,normal:new M.Vector3,materialIndex:0};M.Triangle.getNormal(Se,be,Te,d.normal),h.face=d,h.faceIndex=s,iu&&(h.barycoord=f)}return h}function qr(n,t,e,i,r,s,a){const o=i*3;let c=o+0,l=o+1,u=o+2;const h=n.index;n.index&&(c=h.getX(c),l=h.getX(l),u=h.getX(u));const{position:f,normal:d,uv:y,uv1:_}=n.attributes,p=nu(e,f,d,y,_,c,l,u,t,s,a);return p?(p.faceIndex=i,r&&r.push(p),p):null}function et(n,t,e,i){const r=n.a,s=n.b,a=n.c;let o=t,c=t+1,l=t+2;e&&(o=e.getX(o),c=e.getX(c),l=e.getX(l)),r.x=i.getX(o),r.y=i.getY(o),r.z=i.getZ(o),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l)}function su(n,t,e,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++)qr(c,t,e,u,s,a,o)}function ou(n,t,e,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=qr(o,t,e,h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function au(n,t,e,i,r,s,a){const{geometry:o}=e,{index:c}=o,l=o.attributes.position;for(let u=n,h=t+n;u<h;u++){let f;if(f=u,et(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function cu(n,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=n.geometry,i=e.index?e.index.array:null,r=e.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===$r){const m=a[f+6],g=o[_+14];let v=1/0,S=1/0,x=1/0,b=-1/0,T=-1/0,w=-1/0;for(let C=3*m,P=3*(m+g);C<P;C++){let R=i[C];const E=r.getX(R),A=r.getY(R),k=r.getZ(R);E<v&&(v=E),E>b&&(b=E),A<S&&(S=A),A>T&&(T=A),k<x&&(x=k),k>w&&(w=k)}return c[f+0]!==v||c[f+1]!==S||c[f+2]!==x||c[f+3]!==b||c[f+4]!==T||c[f+5]!==w?(c[f+0]=v,c[f+1]=S,c[f+2]=x,c[f+3]=b,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,g=a[f+6],v=m+d,S=g+d;let x=y,b=!1,T=!1;t?x||(b=t.has(v),T=t.has(S),x=!b&&!T):(b=!0,T=!0);const w=x||b,C=x||T;let P=!1;w&&(P=h(m,d,x));let R=!1;C&&(R=h(g,d,x));const E=P||R;if(E)for(let A=0;A<3;A++){const k=m+A,z=g+A,U=c[k],L=c[k+3],I=c[z],X=c[z+3];c[f+A]=U<I?U:I,c[f+A+3]=L>X?L:X}return E}}}function ge(n,t,e,i,r){let s,a,o,c,l,u;const h=1/e.direction.x,f=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,_=e.origin.y,p=e.origin.z;let m=t[n],g=t[n+3],v=t[n+1],S=t[n+3+1],x=t[n+2],b=t[n+3+2];return h>=0?(s=(m-y)*h,a=(g-y)*h):(s=(g-y)*h,a=(m-y)*h),f>=0?(o=(v-_)*f,c=(S-_)*f):(o=(S-_)*f,c=(v-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),d>=0?(l=(x-p)*d,u=(b-p)*d):(l=(b-p)*d,u=(x-p)*d),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=r&&a>=i)}function lu(n,t,e,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++){let f=l?l[u]:u;qr(c,t,e,f,s,a,o)}}function uu(n,t,e,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=qr(o,t,e,c?c[h]:h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function hu(n,t,e,i,r,s,a){const{geometry:o}=e,{index:c}=o,l=o.attributes.position;for(let u=n,h=t+n;u<h;u++){let f;if(f=e.resolveTriangleIndex(u),et(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function fu(n,t,e,i,r,s,a){$.setBuffer(n._roots[t]),Jn(0,n,e,i,r,s,a),$.clearBuffer()}function Jn(n,t,e,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);su(t,e,i,f,d,r,s,a)}else{const f=Pt(n);ge(f,o,i,s,a)&&Jn(f,t,e,i,r,s,a);const d=wt(n,l);ge(d,o,i,s,a)&&Jn(d,t,e,i,r,s,a)}}const du=["x","y","z"];function pu(n,t,e,i,r,s){$.setBuffer(n._roots[t]);const a=Gn(0,n,e,i,r,s);return $.clearBuffer(),a}function Gn(n,t,e,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(St(l,o)){const h=Mt(n,c),f=Ct(l,o);return ou(t,e,i,h,f,r,s)}else{const h=da(n,c),f=du[h],y=i.direction[f]>=0;let _,p;y?(_=Pt(n),p=wt(n,c)):(_=wt(n,c),p=Pt(n));const g=ge(_,a,i,r,s)?Gn(_,t,e,i,r,s):null;if(g){const x=g.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return g}const S=ge(p,a,i,r,s)?Gn(p,t,e,i,r,s):null;return g&&S?g.distance<=S.distance?g:S:g||S||null}}const mr=new M.Box3,Oe=new Rt,Ie=new Rt,ni=new M.Matrix4,Qs=new dt,yr=new dt;function mu(n,t,e,i){$.setBuffer(n._roots[t]);const r=jn(0,n,e,i);return $.clearBuffer(),r}function jn(n,t,e,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(e.boundingBox||e.computeBoundingBox(),Qs.set(e.boundingBox.min,e.boundingBox.max,i),r=Qs),St(c,a)){const u=t.geometry,h=u.index,f=u.attributes.position,d=e.index,y=e.attributes.position,_=Mt(n,o),p=Ct(c,a);if(ni.copy(i).invert(),e.boundsTree)return Y(n,s,yr),yr.matrix.copy(ni),yr.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>yr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(i),g.b.applyMatrix4(i),g.c.applyMatrix4(i),g.needsUpdate=!0;for(let v=_*3,S=(p+_)*3;v<S;v+=3)if(et(Ie,v,h,f),Ie.needsUpdate=!0,g.intersectsTriangle(Ie))return!0;return!1}});for(let m=_*3,g=(p+_)*3;m<g;m+=3){et(Oe,m,h,f),Oe.a.applyMatrix4(ni),Oe.b.applyMatrix4(ni),Oe.c.applyMatrix4(ni),Oe.needsUpdate=!0;for(let v=0,S=d.count;v<S;v+=3)if(et(Ie,v,d,y),Ie.needsUpdate=!0,Oe.intersectsTriangle(Ie))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,mr),!!(r.intersectsBox(mr)&&jn(u,t,e,i,r)||(Y(h,s,mr),r.intersectsBox(mr)&&jn(h,t,e,i,r)))}}const gr=new M.Matrix4,_n=new dt,si=new dt,yu=new M.Vector3,gu=new M.Vector3,vu=new M.Vector3,_u=new M.Vector3;function xu(n,t,e,i={},r={},s=0,a=1/0){t.boundingBox||t.computeBoundingBox(),_n.set(t.boundingBox.min,t.boundingBox.max,e),_n.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=t.attributes.position,h=t.index,f=Et.getPrimitive(),d=Et.getPrimitive();let y=yu,_=gu,p=null,m=null;r&&(p=vu,m=_u);let g=1/0,v=null,S=null;return gr.copy(e).invert(),si.matrix.copy(gr),n.shapecast({boundsTraverseOrder:x=>_n.distanceToBox(x),intersectsBounds:(x,b,T)=>T<g&&T<a?(b&&(si.min.copy(x.min),si.max.copy(x.max),si.needsUpdate=!0),!0):!1,intersectsRange:(x,b)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:w=>si.distanceToBox(w),intersectsBounds:(w,C,P)=>P<g&&P<a,intersectsRange:(w,C)=>{for(let P=w,R=w+C;P<R;P++){et(d,3*P,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=x,A=x+b;E<A;E++){et(f,3*E,l,c),f.needsUpdate=!0;const k=f.distanceToTriangle(d,y,p);if(k<g&&(_.copy(y),m&&m.copy(p),g=k,v=E,S=P),k<s)return!0}}}});{const T=Xe(t);for(let w=0,C=T;w<C;w++){et(d,3*w,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let P=x,R=x+b;P<R;P++){et(f,3*P,l,c),f.needsUpdate=!0;const E=f.distanceToTriangle(d,y,p);if(E<g&&(_.copy(y),m&&m.copy(p),g=E,v=P,S=w),E<s)return!0}}}}}),Et.releasePrimitive(f),Et.releasePrimitive(d),g===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=g,i.faceIndex=v,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(gr),_.applyMatrix4(gr),r.distance=_.sub(r.point).length(),r.faceIndex=S),i)}function Su(n,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=n.geometry,i=e.index?e.index.array:null,r=e.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===$r){const m=a[f+6],g=o[_+14];let v=1/0,S=1/0,x=1/0,b=-1/0,T=-1/0,w=-1/0;for(let C=m,P=m+g;C<P;C++){const R=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let A=R+E;A=i?i[A]:A;const k=r.getX(A),z=r.getY(A),U=r.getZ(A);k<v&&(v=k),k>b&&(b=k),z<S&&(S=z),z>T&&(T=z),U<x&&(x=U),U>w&&(w=U)}}return c[f+0]!==v||c[f+1]!==S||c[f+2]!==x||c[f+3]!==b||c[f+4]!==T||c[f+5]!==w?(c[f+0]=v,c[f+1]=S,c[f+2]=x,c[f+3]=b,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,g=a[f+6],v=m+d,S=g+d;let x=y,b=!1,T=!1;t?x||(b=t.has(v),T=t.has(S),x=!b&&!T):(b=!0,T=!0);const w=x||b,C=x||T;let P=!1;w&&(P=h(m,d,x));let R=!1;C&&(R=h(g,d,x));const E=P||R;if(E)for(let A=0;A<3;A++){const k=m+A,z=g+A,U=c[k],L=c[k+3],I=c[z],X=c[z+3];c[f+A]=U<I?U:I,c[f+A+3]=L>X?L:X}return E}}}function bu(n,t,e,i,r,s,a){$.setBuffer(n._roots[t]),$n(0,n,e,i,r,s,a),$.clearBuffer()}function $n(n,t,e,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);lu(t,e,i,f,d,r,s,a)}else{const f=Pt(n);ge(f,o,i,s,a)&&$n(f,t,e,i,r,s,a);const d=wt(n,l);ge(d,o,i,s,a)&&$n(d,t,e,i,r,s,a)}}const Tu=["x","y","z"];function Mu(n,t,e,i,r,s){$.setBuffer(n._roots[t]);const a=qn(0,n,e,i,r,s);return $.clearBuffer(),a}function qn(n,t,e,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(St(l,o)){const h=Mt(n,c),f=Ct(l,o);return uu(t,e,i,h,f,r,s)}else{const h=da(n,c),f=Tu[h],y=i.direction[f]>=0;let _,p;y?(_=Pt(n),p=wt(n,c)):(_=wt(n,c),p=Pt(n));const g=ge(_,a,i,r,s)?qn(_,t,e,i,r,s):null;if(g){const x=g.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return g}const S=ge(p,a,i,r,s)?qn(p,t,e,i,r,s):null;return g&&S?g.distance<=S.distance?g:S:g||S||null}}const vr=new M.Box3,Ue=new Rt,Ne=new Rt,oi=new M.Matrix4,Ks=new dt,_r=new dt;function Cu(n,t,e,i){$.setBuffer(n._roots[t]);const r=Xn(0,n,e,i);return $.clearBuffer(),r}function Xn(n,t,e,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(e.boundingBox||e.computeBoundingBox(),Ks.set(e.boundingBox.min,e.boundingBox.max,i),r=Ks),St(c,a)){const u=t.geometry,h=u.index,f=u.attributes.position,d=e.index,y=e.attributes.position,_=Mt(n,o),p=Ct(c,a);if(oi.copy(i).invert(),e.boundsTree)return Y(n,s,_r),_r.matrix.copy(oi),_r.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>_r.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(i),g.b.applyMatrix4(i),g.c.applyMatrix4(i),g.needsUpdate=!0;for(let v=_,S=p+_;v<S;v++)if(et(Ne,3*t.resolveTriangleIndex(v),h,f),Ne.needsUpdate=!0,g.intersectsTriangle(Ne))return!0;return!1}});for(let m=_,g=p+_;m<g;m++){const v=t.resolveTriangleIndex(m);et(Ue,3*v,h,f),Ue.a.applyMatrix4(oi),Ue.b.applyMatrix4(oi),Ue.c.applyMatrix4(oi),Ue.needsUpdate=!0;for(let S=0,x=d.count;S<x;S+=3)if(et(Ne,S,d,y),Ne.needsUpdate=!0,Ue.intersectsTriangle(Ne))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,vr),!!(r.intersectsBox(vr)&&Xn(u,t,e,i,r)||(Y(h,s,vr),r.intersectsBox(vr)&&Xn(h,t,e,i,r)))}}const xr=new M.Matrix4,xn=new dt,ai=new dt,Pu=new M.Vector3,wu=new M.Vector3,Eu=new M.Vector3,Ru=new M.Vector3;function Au(n,t,e,i={},r={},s=0,a=1/0){t.boundingBox||t.computeBoundingBox(),xn.set(t.boundingBox.min,t.boundingBox.max,e),xn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=t.attributes.position,h=t.index,f=Et.getPrimitive(),d=Et.getPrimitive();let y=Pu,_=wu,p=null,m=null;r&&(p=Eu,m=Ru);let g=1/0,v=null,S=null;return xr.copy(e).invert(),ai.matrix.copy(xr),n.shapecast({boundsTraverseOrder:x=>xn.distanceToBox(x),intersectsBounds:(x,b,T)=>T<g&&T<a?(b&&(ai.min.copy(x.min),ai.max.copy(x.max),ai.needsUpdate=!0),!0):!1,intersectsRange:(x,b)=>{if(t.boundsTree){const T=t.boundsTree;return T.shapecast({boundsTraverseOrder:w=>ai.distanceToBox(w),intersectsBounds:(w,C,P)=>P<g&&P<a,intersectsRange:(w,C)=>{for(let P=w,R=w+C;P<R;P++){const E=T.resolveTriangleIndex(P);et(d,3*E,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=x,k=x+b;A<k;A++){const z=n.resolveTriangleIndex(A);et(f,3*z,l,c),f.needsUpdate=!0;const U=f.distanceToTriangle(d,y,p);if(U<g&&(_.copy(y),m&&m.copy(p),g=U,v=A,S=P),U<s)return!0}}}})}else{const T=Xe(t);for(let w=0,C=T;w<C;w++){et(d,3*w,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let P=x,R=x+b;P<R;P++){const E=n.resolveTriangleIndex(P);et(f,3*E,l,c),f.needsUpdate=!0;const A=f.distanceToTriangle(d,y,p);if(A<g&&(_.copy(y),m&&m.copy(p),g=A,v=P,S=w),A<s)return!0}}}}}),Et.releasePrimitive(f),Et.releasePrimitive(d),g===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=g,i.faceIndex=v,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(xr),_.applyMatrix4(xr),r.distance=_.sub(r.point).length(),r.faceIndex=S),i)}function ku(){return typeof SharedArrayBuffer<"u"}const yi=new $.constructor,Lr=new $.constructor,pe=new ss(()=>new M.Box3),Fe=new M.Box3,De=new M.Box3,Sn=new M.Box3,bn=new M.Box3;let Tn=!1;function zu(n,t,e,i){if(Tn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Tn=!0;const r=n._roots,s=t._roots;let a,o=0,c=0;const l=new M.Matrix4().copy(e).invert();for(let u=0,h=r.length;u<h;u++){yi.setBuffer(r[u]),c=0;const f=pe.getPrimitive();Y(0,yi.float32Array,f),f.applyMatrix4(l);for(let d=0,y=s.length;d<y&&(Lr.setBuffer(s[d]),a=Ut(0,0,e,l,i,o,c,0,0,f),Lr.clearBuffer(),c+=s[d].length,!a);d++);if(pe.releasePrimitive(f),yi.clearBuffer(),o+=r[u].length,a)break}return Tn=!1,a}function Ut(n,t,e,i,r,s=0,a=0,o=0,c=0,l=null,u=!1){let h,f;u?(h=Lr,f=yi):(h=yi,f=Lr);const d=h.float32Array,y=h.uint32Array,_=h.uint16Array,p=f.float32Array,m=f.uint32Array,g=f.uint16Array,v=n*2,S=t*2,x=St(v,_),b=St(S,g);let T=!1;if(b&&x)u?T=r(Mt(t,m),Ct(t*2,g),Mt(n,y),Ct(n*2,_),c,a+t,o,s+n):T=r(Mt(n,y),Ct(n*2,_),Mt(t,m),Ct(t*2,g),o,s+n,c,a+t);else if(b){const w=pe.getPrimitive();Y(t,p,w),w.applyMatrix4(e);const C=Pt(n),P=wt(n,y);Y(C,d,Fe),Y(P,d,De);const R=w.intersectsBox(Fe),E=w.intersectsBox(De);T=R&&Ut(t,C,i,e,r,a,s,c,o+1,w,!u)||E&&Ut(t,P,i,e,r,a,s,c,o+1,w,!u),pe.releasePrimitive(w)}else{const w=Pt(t),C=wt(t,m);Y(w,p,Sn),Y(C,p,bn);const P=l.intersectsBox(Sn),R=l.intersectsBox(bn);if(P&&R)T=Ut(n,w,e,i,r,s,a,o,c+1,l,u)||Ut(n,C,e,i,r,s,a,o,c+1,l,u);else if(P)if(x)T=Ut(n,w,e,i,r,s,a,o,c+1,l,u);else{const E=pe.getPrimitive();E.copy(Sn).applyMatrix4(e);const A=Pt(n),k=wt(n,y);Y(A,d,Fe),Y(k,d,De);const z=E.intersectsBox(Fe),U=E.intersectsBox(De);T=z&&Ut(w,A,i,e,r,a,s,c,o+1,E,!u)||U&&Ut(w,k,i,e,r,a,s,c,o+1,E,!u),pe.releasePrimitive(E)}else if(R)if(x)T=Ut(n,C,e,i,r,s,a,o,c+1,l,u);else{const E=pe.getPrimitive();E.copy(bn).applyMatrix4(e);const A=Pt(n),k=wt(n,y);Y(A,d,Fe),Y(k,d,De);const z=E.intersectsBox(Fe),U=E.intersectsBox(De);T=z&&Ut(C,A,i,e,r,a,s,c,o+1,E,!u)||U&&Ut(C,k,i,e,r,a,s,c,o+1,E,!u),pe.releasePrimitive(E)}}return T}const Sr=new dt,to=new M.Box3,Bu={strategy:rs,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Ki{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,r=t._roots,s=t._indirectBuffer,a=i.getIndex();let o;return e.cloneBuffers?o={roots:r.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:r,index:a?a.array:null,indirectBuffer:s},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:r,roots:s,indirectBuffer:a}=t,o=new Ki(e,{...i,[pn]:!0});if(o._roots=s,o._indirectBuffer=a||null,i.setIndex){const c=e.getIndex();if(c===null){const l=new M.BufferAttribute(t.index,1,!1);e.setIndex(l)}else c.array!==r&&(c.array.set(r),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...Bu,[pn]:!1},e),e.useSharedArrayBuffer&&!ku())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[pn]||(Wl(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new M.Box3))),this.resolveTriangleIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i}refit(t=null){return(this.indirect?Su:cu)(this,t)}traverse(t,e=0){const i=this._roots[e],r=new Uint32Array(i),s=new Uint16Array(i);a(0);function a(o,c=0){const l=o*2,u=s[l+15]===$r;if(u){const h=r[o+6],f=s[l+14];t(c,u,new Float32Array(i,o*4,6),h,f)}else{const h=o+mi/4,f=r[o+6],d=r[o+7];t(c,u,new Float32Array(i,o*4,6),d)||(a(h,c+1),a(f,c+1))}}}raycast(t,e=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=[],c=e.isMaterial,l=Array.isArray(e),u=a.groups,h=c?e.side:e,f=this.indirect?bu:fu;for(let d=0,y=s.length;d<y;d++){const _=l?e[u[d].materialIndex].side:h,p=o.length;if(f(this,d,_,t,o,i,r),l){const m=u[d].materialIndex;for(let g=p,v=o.length;g<v;g++)o[g].face.materialIndex=m}}return o}raycastFirst(t,e=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=e.isMaterial,c=Array.isArray(e);let l=null;const u=a.groups,h=o?e.side:e,f=this.indirect?Mu:pu;for(let d=0,y=s.length;d<y;d++){const _=c?e[u[d].materialIndex].side:h,p=f(this,d,_,t,i,r);p!=null&&(l==null||p.distance<l.distance)&&(l=p,c&&(p.face.materialIndex=u[d].materialIndex))}return l}intersectsGeometry(t,e){let i=!1;const r=this._roots,s=this.indirect?Cu:mu;for(let a=0,o=r.length;a<o&&(i=s(this,a,t,e),!i);a++);return i}shapecast(t){const e=Et.getPrimitive(),i=this.indirect?hu:au;let{boundsTraverseOrder:r,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=t;if(a&&o){const h=a;a=(f,d,y,_,p)=>h(f,d,y,_,p)?!0:i(f,d,this,o,y,_,e)}else a||(o?a=(h,f,d,y)=>i(h,f,this,o,d,y,e):a=(h,f,d)=>d);let c=!1,l=0;const u=this._roots;for(let h=0,f=u.length;h<f;h++){const d=u[h];if(c=tu(this,h,s,a,r,l),c)break;l+=d.byteLength}return Et.releasePrimitive(e),c}bvhcast(t,e,i){let{intersectsRanges:r,intersectsTriangles:s}=i;const a=Et.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const _=this.resolveTriangleIndex(y);et(a,_*3,o,c)}:y=>{et(a,y*3,o,c)},u=Et.getPrimitive(),h=t.geometry.index,f=t.geometry.attributes.position,d=t.indirect?y=>{const _=t.resolveTriangleIndex(y);et(u,_*3,h,f)}:y=>{et(u,y*3,h,f)};if(s){const y=(_,p,m,g,v,S,x,b)=>{for(let T=m,w=m+g;T<w;T++){d(T),u.a.applyMatrix4(e),u.b.applyMatrix4(e),u.c.applyMatrix4(e),u.needsUpdate=!0;for(let C=_,P=_+p;C<P;C++)if(l(C),a.needsUpdate=!0,s(a,u,C,T,v,S,x,b))return!0}return!1};if(r){const _=r;r=function(p,m,g,v,S,x,b,T){return _(p,m,g,v,S,x,b,T)?!0:y(p,m,g,v,S,x,b,T)}}else r=y}return zu(this,t,e,r)}intersectsBox(t,e){return Sr.set(t.min,t.max,e),Sr.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Sr.intersectsBox(i),intersectsTriangle:i=>Sr.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},r={},s=0,a=1/0){return(this.indirect?Au:xu)(this,t,e,i,r,s,a)}closestPointToPoint(t,e={},i=0,r=1/0){return eu(this,t,e,i,r)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),to),t.union(to)}),t}}function eo(n,t,e){return n===null?null:(n.point.applyMatrix4(t.matrixWorld),n.distance=n.point.distanceTo(e.ray.origin),n.object=t,n)}const br=new M.Ray,io=new M.Vector3,ro=new M.Matrix4,Ou=M.Mesh.prototype.raycast,Iu=M.BatchedMesh.prototype.raycast,no=new M.Vector3,ct=new M.Mesh,Tr=[];function Uu(n,t){this.isBatchedMesh?Nu.call(this,n,t):Fu.call(this,n,t)}function Nu(n,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ct.material=this.material,ct.geometry=this.geometry;const a=ct.geometry.boundsTree,o=ct.geometry.drawRange;ct.geometry.boundingSphere===null&&(ct.geometry.boundingSphere=new M.Sphere);for(let c=0,l=i.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=i[c].geometryIndex;if(ct.geometry.boundsTree=e[u],this.getMatrixAt(c,ct.matrixWorld).premultiply(s),!ct.geometry.boundsTree){this.getBoundingBoxAt(u,ct.geometry.boundingBox),this.getBoundingSphereAt(u,ct.geometry.boundingSphere);const h=r[u];ct.geometry.setDrawRange(h.start,h.count)}ct.raycast(n,Tr);for(let h=0,f=Tr.length;h<f;h++){const d=Tr[h];d.object=this,d.batchId=c,t.push(d)}Tr.length=0}ct.geometry.boundsTree=a,ct.geometry.drawRange=o,ct.material=null,ct.geometry=null}else Iu.call(this,n,t)}function Fu(n,t){if(this.geometry.boundsTree){if(this.material===void 0)return;ro.copy(this.matrixWorld).invert(),br.copy(n.ray).applyMatrix4(ro),no.setFromMatrixScale(this.matrixWorld),io.copy(br.direction).multiply(no);const e=io.length(),i=n.near/e,r=n.far/e,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=eo(s.raycastFirst(br,this.material,i,r),this,n);a&&t.push(a)}else{const a=s.raycast(br,this.material,i,r);for(let o=0,c=a.length;o<c;o++){const l=eo(a[o],this,n);l&&t.push(l)}}}else Ou.call(this,n,t)}function Du(n={}){return this.boundsTree=new Ki(this,n),this.boundsTree}const Me=new M.Vector3,Ce=new M.Vector3,Pe=new M.Vector3,so=new M.Vector4,Mr=new M.Vector3,Mn=new M.Vector3,oo=new M.Vector4,ao=new M.Vector4,Cr=new M.Matrix4,co=new M.Matrix4;function ci(n,t){if(!n&&!t)return;const e=n.count===t.count,i=n.normalized===t.normalized,r=n.array.constructor===t.array.constructor,s=n.itemSize===t.itemSize;if(!e||!i||!r||!s)throw new Error}function di(n,t=null){const e=n.array.constructor,i=n.normalized,r=n.itemSize,s=t===null?n.count:t;return new M.BufferAttribute(new e(r*s),r,i)}function ya(n,t,e=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let r=0,s=n.count;r<s;r++){const a=r+e;t.setX(a,n.getX(r)),i>=2&&t.setY(a,n.getY(r)),i>=3&&t.setZ(a,n.getZ(r)),i>=4&&t.setW(a,n.getW(r))}}else{const i=t.array,r=i.constructor,s=i.BYTES_PER_ELEMENT*n.itemSize*e;new r(i.buffer,s,n.array.length).set(n.array)}}function Lu(n,t,e){const i=n.elements,r=t.elements;for(let s=0,a=r.length;s<a;s++)i[s]+=r[s]*e}function lo(n,t,e){const i=n.skeleton,r=n.geometry,s=i.bones,a=i.boneInverses;oo.fromBufferAttribute(r.attributes.skinIndex,t),ao.fromBufferAttribute(r.attributes.skinWeight,t),Cr.elements.fill(0);for(let o=0;o<4;o++){const c=ao.getComponent(o);if(c!==0){const l=oo.getComponent(o);co.multiplyMatrices(s[l].matrixWorld,a[l]),Lu(Cr,co,c)}}return Cr.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),e.transformDirection(Cr),e}function Cn(n,t,e,i,r){Mr.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=t[s],c=n[s];o!==0&&(Mn.fromBufferAttribute(c,i),e?Mr.addScaledVector(Mn,o):Mr.addScaledVector(Mn.sub(r),o))}r.add(Mr)}function Vu(n,t={useGroups:!1,updateIndex:!1,skipAttributes:[]},e=new M.BufferGeometry){const i=n[0].index!==null,{useGroups:r=!1,updateIndex:s=!1,skipAttributes:a=[]}=t,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;e.clearGroups();for(let u=0;u<n.length;++u){const h=n[u];let f=0;if(i!==(h.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const d in h.attributes){if(!o.has(d))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.');c[d]===void 0&&(c[d]=[]),c[d].push(h.attributes[d]),f++}if(f!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(r){let d;if(i)d=h.index.count;else if(h.attributes.position!==void 0)d=h.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");e.addGroup(l,d,u),l+=d}}if(i){let u=!1;if(!e.index){let h=0;for(let f=0;f<n.length;++f)h+=n[f].index.count;e.setIndex(new M.BufferAttribute(new Uint32Array(h),1,!1)),u=!0}if(s||u){const h=e.index;let f=0,d=0;for(let y=0;y<n.length;++y){const _=n[y],p=_.index;if(a[y]!==!0)for(let m=0;m<p.count;++m)h.setX(f,p.getX(m)+d),f++;d+=_.attributes.position.count}}}for(const u in c){const h=c[u];if(!(u in e.attributes)){let y=0;for(const _ in h)y+=h[_].count;e.setAttribute(u,di(c[u][0],y))}const f=e.attributes[u];let d=0;for(let y=0,_=h.length;y<_;y++){const p=h[y];a[y]!==!0&&ya(p,f,d),d+=p.count}}return e}function Ju(n,t){if(n===null||t===null)return n===t;if(n.length!==t.length)return!1;for(let e=0,i=n.length;e<i;e++)if(n[e]!==t[e])return!1;return!0}function Gu(n){const{index:t,attributes:e}=n;if(t)for(let i=0,r=t.count;i<r;i+=3){const s=t.getX(i),a=t.getX(i+2);t.setX(i,a),t.setX(i+2,s)}else for(const i in e){const r=e[i],s=r.itemSize;for(let a=0,o=r.count;a<o;a+=3)for(let c=0;c<s;c++){const l=r.getComponent(a,c),u=r.getComponent(a+2,c);r.setComponent(a,c,u),r.setComponent(a+2,c,l)}}return n}class ju{constructor(t){this.matrixWorld=new M.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=t,this.update()}update(){const t=this.mesh,e=t.geometry,i=t.skeleton,r=(e.index?e.index.count:e.attributes.position.count)/3;if(this.matrixWorld.copy(t.matrixWorld),this.geometryHash=e.attributes.position.version,this.primitiveCount=r,i){i.boneTexture||i.computeBoneTexture(),i.update();const s=i.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const t=this.mesh,e=t.geometry,i=(e.index?e.index.count:e.attributes.position.count)/3;return!(this.matrixWorld.equals(t.matrixWorld)&&this.geometryHash===e.attributes.position.version&&Ju(t.skeleton&&t.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class $u{constructor(t){Array.isArray(t)||(t=[t]);const e=[];t.forEach(i=>{i.traverseVisible(r=>{r.isMesh&&e.push(r)})}),this.meshes=e,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(e.length).fill().map(()=>new M.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const t=[];return this.meshes.forEach(e=>{Array.isArray(e.material)?t.push(...e.material):t.push(e.material)}),t}generate(t=new M.BufferGeometry){let e=[];const{meshes:i,useGroups:r,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=i.length;o<c;o++){const l=i[o],u=s[o],h=a.get(l);!h||h.didChange(l)?(this._convertToStaticGeometry(l,u),e.push(!1),h?h.update():a.set(l,new ju(l))):e.push(!0)}if(s.length===0){t.setIndex(null);const o=t.attributes;for(const c in o)t.deleteAttribute(c);for(const c in this.attributes)t.setAttribute(this.attributes[c],new M.BufferAttribute(new Float32Array(0),4,!1))}else Vu(s,{useGroups:r,skipAttributes:e},t);for(const o in t.attributes)t.attributes[o].needsUpdate=!0;return t}_convertToStaticGeometry(t,e=new M.BufferGeometry){const i=t.geometry,r=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=i.attributes,c=e.attributes;!e.index&&i.index&&(e.index=i.index.clone()),c.position||e.setAttribute("position",di(o.position)),s&&!c.normal&&o.normal&&e.setAttribute("normal",di(o.normal)),a&&!c.tangent&&o.tangent&&e.setAttribute("tangent",di(o.tangent)),ci(i.index,e.index),ci(o.position,c.position),s&&ci(o.normal,c.normal),a&&ci(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,h=a?o.tangent:null,f=i.morphAttributes.position,d=i.morphAttributes.normal,y=i.morphAttributes.tangent,_=i.morphTargetsRelative,p=t.morphTargetInfluences,m=new M.Matrix3;m.getNormalMatrix(t.matrixWorld),i.index&&e.index.array.set(i.index.array);for(let g=0,v=o.position.count;g<v;g++)Me.fromBufferAttribute(l,g),u&&Ce.fromBufferAttribute(u,g),h&&(so.fromBufferAttribute(h,g),Pe.fromBufferAttribute(h,g)),p&&(f&&Cn(f,p,_,g,Me),d&&Cn(d,p,_,g,Ce),y&&Cn(y,p,_,g,Pe)),t.isSkinnedMesh&&(t.applyBoneTransform(g,Me),u&&lo(t,g,Ce),h&&lo(t,g,Pe)),r&&Me.applyMatrix4(t.matrixWorld),c.position.setXYZ(g,Me.x,Me.y,Me.z),u&&(r&&Ce.applyNormalMatrix(m),c.normal.setXYZ(g,Ce.x,Ce.y,Ce.z)),h&&(r&&Pe.transformDirection(t.matrixWorld),c.tangent.setXYZW(g,Pe.x,Pe.y,Pe.z,so.w));for(const g in this.attributes){const v=this.attributes[g];v==="position"||v==="tangent"||v==="normal"||!(v in o)||(c[v]||e.setAttribute(v,di(o[v])),ci(o[v],c[v]),ya(o[v],c[v]))}return t.matrixWorld.determinant()<0&&Gu(e),e}}const qu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:la,CENTER:rs,CONTAINED:Fn,ExtendedTriangle:Rt,MeshBVH:Ki,OrientedBox:dt,SAH:ua,StaticGeometryGenerator:$u,acceleratedRaycast:Uu,computeBoundsTree:Du},Symbol.toStringTag,{value:"Module"}));class Xu{constructor(t){this.name="WorkerBase",this.running=!1,this.worker=t,this.worker.onerror=e=>{throw e.message?new Error(`${this.name}: Could not create Web Worker with error "${e.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...t){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const e=this.runTask(this.worker,...t);return e.finally(()=>{this.running=!1}),e}dispose(){this.worker.terminate(),this.worker=null}}exports.$70d766613f57b014$export$2e2bcd8739ae039=Ko;exports.BatchedParticleRenderer=Pl;exports.Builder=Wn;exports.ByteBuffer=gi;exports.ConstantColor=Re;exports.ConstantValue=F;exports.Matrix4=Ft;exports.MeshBVH=Ki;exports.MotionController=Ta;exports.ParticleSystem=Dr;exports.SIZE_PREFIX_LENGTH=ho;exports.TrailParticle=Nr;exports.Vector4=bt;exports.WorkerBase=Xu;exports.bundler=ec;exports.createNoise4D=El;exports.fetchProfile=va;exports.index=zl;exports.index$1=qu;exports.md5=gc;exports.v5=fc;
1121
+ }`;class Cl extends oa{constructor(t){super(t),this.vector_=new O,this.vector2_=new O,this.vector3_=new O,this.quaternion_=new J,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new M.BufferGeometry,this.indexBuffer=new M.BufferAttribute(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new Je(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},e={};if(e.USE_UV="",e.USE_COLOR_ALPHA="",this.settings.material.map&&(e.USE_MAP="",e.MAP_UV=Nn(this.settings.material.map.channel),t.map=new M.Uniform$1(this.settings.material.map),t.mapTransform=new M.Uniform$1(new Xt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new M.ShaderMaterial({uniforms:t,defines:e,vertexShader:Ml,fragmentShader:Tl,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||M.AdditiveBlending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let t=0,e=0,i=0;this.systems.forEach(r=>{for(let s=0;s<r.particleNum;s++)i+=r.particles[s].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(r=>{r.emitter.updateMatrixWorld&&(r.emitter.updateWorldMatrix(!0,!1),r.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;r.emitter.matrixWorld.decompose(a,s,o);const c=r.particles,l=r.particleNum,u=this.settings.uTileCount,h=this.settings.vTileCount,f=1/u,d=1/h;for(let y=0;y<l;y++){const _=c[y],p=_.uvTile%h,m=Math.floor(_.uvTile/h+.001),g=_.previous.values();let v=g.next(),S=v.value,x=S;v.done||(v=g.next());let b;v.value!==void 0?b=v.value:b=x;for(let T=0;T<_.previous.length;T++,t+=2){if(this.positionBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(t+1,x.position.x,x.position.y,x.position.z),r.worldSpace?(this.positionBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(t+1,x.position.x,x.position.y,x.position.z)):(_.parentMatrix?this.vector_.copy(x.position).applyMatrix4(_.parentMatrix):this.vector_.copy(x.position).applyMatrix4(r.emitter.matrixWorld),this.positionBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.previousBuffer.setXYZ(t,S.position.x,S.position.y,S.position.z),this.previousBuffer.setXYZ(t+1,S.position.x,S.position.y,S.position.z)):(_.parentMatrix?this.vector_.copy(S.position).applyMatrix4(_.parentMatrix):this.vector_.copy(S.position).applyMatrix4(r.emitter.matrixWorld),this.previousBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.nextBuffer.setXYZ(t,b.position.x,b.position.y,b.position.z),this.nextBuffer.setXYZ(t+1,b.position.x,b.position.y,b.position.z)):(_.parentMatrix?this.vector_.copy(b.position).applyMatrix4(_.parentMatrix):this.vector_.copy(b.position).applyMatrix4(r.emitter.matrixWorld),this.nextBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(t,-1),this.sideBuffer.setX(t+1,1),r.worldSpace)this.widthBuffer.setX(t,x.size),this.widthBuffer.setX(t+1,x.size);else if(_.parentMatrix)this.widthBuffer.setX(t,x.size),this.widthBuffer.setX(t+1,x.size);else{const w=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(t,x.size*w),this.widthBuffer.setX(t+1,x.size*w)}this.uvBuffer.setXY(t,(T/_.previous.length+p)*f,(h-m-1)*d),this.uvBuffer.setXY(t+1,(T/_.previous.length+p)*f,(h-m)*d),this.colorBuffer.setXYZW(t,x.color.x,x.color.y,x.color.z,x.color.w),this.colorBuffer.setXYZW(t+1,x.color.x,x.color.y,x.color.z,x.color.w),T+1<_.previous.length&&(this.indexBuffer.setX(e*3,t),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+2),e++,this.indexBuffer.setX(e*3,t+2),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+3),e++),S=x,x=b,v.done||(v=g.next(),v.value!==void 0&&(b=v.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,t*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,t*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,t*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,t),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,t),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,t*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,e*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,e*3)}dispose(){this.geometry.dispose()}}class Yi{get geometry(){return this._geometry}set geometry(t){if(this._geometry=t,t===void 0||typeof t=="string")return;const e=new M.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!t.getIndex())return;const r=t.getIndex().array,s=r.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)e.setFromAttributeAndIndices(t.getAttribute("position"),r[a*3],r[a*3+1],r[a*3+2]),i+=e.getArea(),this._triangleIndexToArea.push(i);t.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(t){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new M.Vector3,this._tempB=new M.Vector3,this._tempC=new M.Vector3,t&&(this.geometry=t)}initialize(t){const e=this._geometry;if(!e||e.getIndex()===null){t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);return}const i=this._triangleIndexToArea.length-1;let r=0,s=i;const a=Math.random()*this._triangleIndexToArea[i];for(;r+1<s;){const d=Math.floor((r+s)/2);a<this._triangleIndexToArea[d]?s=d:r=d}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=e.getIndex().array[r*3],u=e.getIndex().array[r*3+1],h=e.getIndex().array[r*3+2],f=e.getAttribute("position");this._tempA.fromBufferAttribute(f,l),this._tempB.fromBufferAttribute(f,u),this._tempC.fromBufferAttribute(f,h),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),t.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),t.velocity.copy(this._tempA).normalize().multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(t,e){return new Yi(e.geometries[t.geometry])}clone(){return new Yi(this._geometry)}update(t,e){}}il({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Yi,loadJSON:Yi.fromJSON}],behaviors:[]});class is extends M.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(t,e){return t.material.side===e.material.side&&t.material.blending===e.material.blending&&t.material.blendSrc===e.material.blendSrc&&t.material.blendDst===e.material.blendDst&&t.material.blendEquation===e.material.blendEquation&&t.material.premultipliedAlpha===e.material.premultipliedAlpha&&t.material.transparent===e.material.transparent&&t.material.depthTest===e.material.depthTest&&t.material.type===e.material.type&&t.material.alphaTest===e.material.alphaTest&&t.material.map===e.material.map&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layers.mask===e.layers.mask}addSystem(t){t._renderer=this;const e=t.getRendererSettings();for(let r=0;r<this.batches.length;r++)if(is.equals(this.batches[r].settings,e)){this.batches[r].addSystem(t),this.systemToBatchIndex.set(t,r);return}let i;switch(e.renderMode){case exports.RenderMode.Trail:i=new Cl(e);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new bl(e);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(t),this.batches.push(i),this.systemToBatchIndex.set(t,this.batches.length-1),this.add(i)}deleteSystem(t){const e=this.systemToBatchIndex.get(t);e!=null&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t))}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}updateSystem(t){this.deleteSystem(t),this.addSystem(t)}update(t){this.systemToBatchIndex.forEach((e,i)=>{i.update(t)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}}const Pl=is;hl();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const aa=Math.sqrt(5),wl=(aa-1)/4,at=(5-aa)/20,ar=n=>Math.floor(n)|0,cr=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function El(n=Math.random){const t=Rl(n),e=new Float64Array(t).map(a=>cr[a%32*4]),i=new Float64Array(t).map(a=>cr[a%32*4+1]),r=new Float64Array(t).map(a=>cr[a%32*4+2]),s=new Float64Array(t).map(a=>cr[a%32*4+3]);return function(o,c,l,u){let h,f,d,y,_;const p=(o+c+l+u)*wl,m=ar(o+p),g=ar(c+p),v=ar(l+p),S=ar(u+p),x=(m+g+v+S)*at,b=m-x,T=g-x,w=v-x,C=S-x,P=o-b,R=c-T,E=l-w,A=u-C;let k=0,z=0,U=0,L=0;P>R?k++:z++,P>E?k++:U++,P>A?k++:L++,R>E?z++:U++,R>A?z++:L++,E>A?U++:L++;const I=k>=3?1:0,X=z>=3?1:0,Z=U>=3?1:0,it=L>=3?1:0,K=k>=2?1:0,pt=z>=2?1:0,mt=U>=2?1:0,rt=L>=2?1:0,W=k>=1?1:0,j=z>=1?1:0,Ht=U>=1?1:0,Dt=L>=1?1:0,Lt=P-I+at,Vt=R-X+at,vt=E-Z+at,At=A-it+at,_t=P-K+2*at,Yt=R-pt+2*at,Zt=E-mt+2*at,H=A-rt+2*at,Jt=P-W+3*at,Qt=R-j+3*at,ve=E-Ht+3*at,Kt=A-Dt+3*at,te=P-1+4*at,ee=R-1+4*at,ie=E-1+4*at,re=A-1+4*at,kt=m&255,zt=g&255,Bt=v&255,Ot=S&255;let V=.6-P*P-R*R-E*E-A*A;if(V<0)h=0;else{const q=kt+t[zt+t[Bt+t[Ot]]];V*=V,h=V*V*(e[q]*P+i[q]*R+r[q]*E+s[q]*A)}let We=.6-Lt*Lt-Vt*Vt-vt*vt-At*At;if(We<0)f=0;else{const q=kt+I+t[zt+X+t[Bt+Z+t[Ot+it]]];We*=We,f=We*We*(e[q]*Lt+i[q]*Vt+r[q]*vt+s[q]*At)}let He=.6-_t*_t-Yt*Yt-Zt*Zt-H*H;if(He<0)d=0;else{const q=kt+K+t[zt+pt+t[Bt+mt+t[Ot+rt]]];He*=He,d=He*He*(e[q]*_t+i[q]*Yt+r[q]*Zt+s[q]*H)}let Ye=.6-Jt*Jt-Qt*Qt-ve*ve-Kt*Kt;if(Ye<0)y=0;else{const q=kt+W+t[zt+j+t[Bt+Ht+t[Ot+Dt]]];Ye*=Ye,y=Ye*Ye*(e[q]*Jt+i[q]*Qt+r[q]*ve+s[q]*Kt)}let Ze=.6-te*te-ee*ee-ie*ie-re*re;if(Ze<0)_=0;else{const q=kt+1+t[zt+1+t[Bt+1+t[Ot+1]]];Ze*=Ze,_=Ze*Ze*(e[q]*te+i[q]*ee+r[q]*ie+s[q]*re)}return 27*(h+f+d+y+_)}}function Rl(n){const e=new Uint8Array(512);for(let i=0;i<512/2;i++)e[i]=i;for(let i=0;i<512/2-1;i++){const r=i+~~(n()*(256-i)),s=e[i];e[i]=e[r],e[r]=s}for(let i=256;i<512;i++)e[i]=e[i-256];return e}class Al{constructor(t,e){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Base must be a positive integer or zero");if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=t,this.expMax=e,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var G;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(G||(G={}));class ca{constructor(t,e,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,g;this._closedByUser=!1,this.handleOpenEvent=v=>this.handleEvent(G.open,v),this.handleErrorEvent=v=>this.handleEvent(G.error,v),this.handleCloseEvent=v=>this.handleEvent(G.close,v),this.handleMessageEvent=v=>this.handleEvent(G.message,v),this._url=t,this._protocols=e,this._options={buffer:i?.buffer,retry:{maxRetries:(r=i?.retry)===null||r===void 0?void 0:r.maxRetries,instantReconnect:(s=i?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=i?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=i?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=i?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(f=(h=i?.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[]],message:[...(y=(d=i?.listeners)===null||d===void 0?void 0:d.message)!==null&&y!==void 0?y:[]],retry:[...(p=(_=i?.listeners)===null||_===void 0?void 0:_.retry)!==null&&p!==void 0?p:[]],reconnect:[...(g=(m=i?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&g!==void 0?g:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(t){this._underlyingWebsocket.binaryType=t}send(t){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(t):this.buffer!==void 0&&this.buffer.add(t))}close(t,e){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(t,e)}addEventListener(t,e,i){this._options.listeners[t].push({listener:e,options:i})}removeEventListener(t,e,i){const r=s=>s.listener!==e||s.options!==i;this._options.listeners[t]=this._options.listeners[t].filter(r)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(t,e){const i=this._options.listeners[t],r=[];i.forEach(({listener:s,options:a})=>{s(this,e),(a===void 0||a.once===void 0||!a.once)&&r.push({listener:s,options:a})}),this._options.listeners[t]=r}handleEvent(t,e){switch(t){case G.close:this.dispatchEvent(t,e),this.scheduleConnectionRetryIfNeeded();break;case G.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},r=new CustomEvent(G.reconnect,{detail:i});this.dispatchEvent(G.reconnect,r),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(t,e),this.sendBufferedData();break;case G.retry:this.dispatchEvent(t,e),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(t,e);break}}sendBufferedData(){if(this.buffer!==void 0)for(let t=this.buffer.read();t!==void 0;t=this.buffer.read())this.send(t)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const t=i=>{const r=new CustomEvent(G.retry,{detail:i});this.handleEvent(G.retry,r)},e={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||e.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>t(e),e.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class kl{constructor(t){this._url=t}get url(){return this._url}withProtocols(t){return this._protocols=t,this}get protocols(){return this._protocols}withMaxRetries(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{maxRetries:t})}),this}get maxRetries(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.maxRetries}withInstantReconnect(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{instantReconnect:t})}),this}get instantReconnect(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.instantReconnect}withBackoff(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{backoff:t})}),this}get backoff(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.backoff}withBuffer(t){return this._options=Object.assign(Object.assign({},this._options),{buffer:t}),this}get buffer(){var t;return(t=this._options)===null||t===void 0?void 0:t.buffer}onOpen(t,e){return this.addListener(G.open,t,e),this}onClose(t,e){return this.addListener(G.close,t,e),this}onError(t,e){return this.addListener(G.error,t,e),this}onMessage(t,e){return this.addListener(G.message,t,e),this}onRetry(t,e){return this.addListener(G.retry,t,e),this}onReconnect(t,e){return this.addListener(G.reconnect,t,e),this}build(){return new ca(this._url,this._protocols,this._options)}addListener(t,e,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,g,v,S,x,b,T,w;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(r=this._options)===null||r===void 0?void 0:r.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(f=(h=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[],message:(_=(y=(d=this._options)===null||d===void 0?void 0:d.listeners)===null||y===void 0?void 0:y.message)!==null&&_!==void 0?_:[],retry:(g=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.retry)!==null&&g!==void 0?g:[],reconnect:(x=(S=(v=this._options)===null||v===void 0?void 0:v.listeners)===null||S===void 0?void 0:S.reconnect)!==null&&x!==void 0?x:[],[t]:[...(w=(T=(b=this._options)===null||b===void 0?void 0:b.listeners)===null||T===void 0?void 0:T[t])!==null&&w!==void 0?w:[],{listener:e,options:i}]}}),this}}const zl=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Al,Websocket:ca,WebsocketBuilder:kl,get WebsocketEvent(){return G}},Symbol.toStringTag,{value:"Module"})),rs=0,la=1,ua=2,Fn=2,dn=1.25,$s=1,mi=32,$r=65535,Bl=Math.pow(2,-24),pn=Symbol("SKIP_GENERATION");function Ol(n){return n.index?n.index.count:n.attributes.position.count}function Xe(n){return Ol(n)/3}function Il(n,t=ArrayBuffer){return n>65535?new Uint32Array(new t(4*n)):new Uint16Array(new t(2*n))}function Ul(n,t){if(!n.index){const e=n.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Il(e,i);n.setIndex(new M.BufferAttribute(r,1));for(let s=0;s<e;s++)r[s]=s}}function ha(n,t){const e=Xe(n),i=t||n.drawRange,r=i.start/3,s=(i.start+i.count)/3,a=Math.max(0,r),o=Math.min(e,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function fa(n,t){if(!n.groups||!n.groups.length)return ha(n,t);const e=[],i=new Set,r=t||n.drawRange,s=r.start/3,a=(r.start+r.count)/3;for(const c of n.groups){const l=c.start/3,u=(c.start+c.count)/3;i.add(Math.max(s,l)),i.add(Math.min(a,u))}const o=Array.from(i.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],u=o[c+1];e.push({offset:Math.floor(l),count:Math.floor(u-l)})}return e}function Nl(n,t){const e=Xe(n),i=fa(n,t).sort((a,o)=>a.offset-o.offset),r=i[i.length-1];r.count=Math.min(e-r.offset,r.count);let s=0;return i.forEach(({count:a})=>s+=a),e!==s}function mn(n,t,e,i,r){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,h=1/0,f=1/0,d=1/0,y=-1/0,_=-1/0,p=-1/0;for(let m=t*6,g=(t+e)*6;m<g;m+=6){const v=n[m+0],S=n[m+1],x=v-S,b=v+S;x<s&&(s=x),b>c&&(c=b),v<h&&(h=v),v>y&&(y=v);const T=n[m+2],w=n[m+3],C=T-w,P=T+w;C<a&&(a=C),P>l&&(l=P),T<f&&(f=T),T>_&&(_=T);const R=n[m+4],E=n[m+5],A=R-E,k=R+E;A<o&&(o=A),k>u&&(u=k),R<d&&(d=R),R>p&&(p=R)}i[0]=s,i[1]=a,i[2]=o,i[3]=c,i[4]=l,i[5]=u,r[0]=h,r[1]=f,r[2]=d,r[3]=y,r[4]=_,r[5]=p}function Fl(n,t=null,e=null,i=null){const r=n.attributes.position,s=n.index?n.index.array:null,a=Xe(n),o=r.normalized;let c;t===null?(c=new Float32Array(a*6),e=0,i=a):(c=t,e=e||0,i=i||a);const l=r.array,u=r.offset||0;let h=3;r.isInterleavedBufferAttribute&&(h=r.data.stride);const f=["getX","getY","getZ"];for(let d=e;d<e+i;d++){const y=d*3,_=d*6;let p=y+0,m=y+1,g=y+2;s&&(p=s[p],m=s[m],g=s[g]),o||(p=p*h+u,m=m*h+u,g=g*h+u);for(let v=0;v<3;v++){let S,x,b;o?(S=r[f[v]](p),x=r[f[v]](m),b=r[f[v]](g)):(S=l[p+v],x=l[m+v],b=l[g+v]);let T=S;x<T&&(T=x),b<T&&(T=b);let w=S;x>w&&(w=x),b>w&&(w=b);const C=(w-T)/2,P=v*2;c[_+P+0]=T+C,c[_+P+1]=C+(Math.abs(T)+C)*Bl}}return c}function Y(n,t,e){return e.min.x=t[n],e.min.y=t[n+1],e.min.z=t[n+2],e.max.x=t[n+3],e.max.y=t[n+4],e.max.z=t[n+5],e}function qs(n){let t=-1,e=-1/0;for(let i=0;i<3;i++){const r=n[i+3]-n[i];r>e&&(e=r,t=i)}return t}function Xs(n,t){t.set(n)}function Ws(n,t,e){let i,r;for(let s=0;s<3;s++){const a=s+3;i=n[s],r=t[s],e[s]=i<r?i:r,i=n[a],r=t[a],e[a]=i>r?i:r}}function lr(n,t,e){for(let i=0;i<3;i++){const r=t[n+2*i],s=t[n+2*i+1],a=r-s,o=r+s;a<e[i]&&(e[i]=a),o>e[i+3]&&(e[i+3]=o)}}function ei(n){const t=n[3]-n[0],e=n[4]-n[1],i=n[5]-n[2];return 2*(t*e+e*i+i*t)}const ne=32,Dl=(n,t)=>n.candidate-t.candidate,fe=new Array(ne).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ur=new Float32Array(6);function Ll(n,t,e,i,r,s){let a=-1,o=0;if(s===rs)a=qs(t),a!==-1&&(o=(t[a]+t[a+3])/2);else if(s===la)a=qs(n),a!==-1&&(o=Vl(e,i,r,a));else if(s===ua){const c=ei(n);let l=dn*r;const u=i*6,h=(i+r)*6;for(let f=0;f<3;f++){const d=t[f],p=(t[f+3]-d)/ne;if(r<ne/4){const m=[...fe];m.length=r;let g=0;for(let S=u;S<h;S+=6,g++){const x=m[g];x.candidate=e[S+2*f],x.count=0;const{bounds:b,leftCacheBounds:T,rightCacheBounds:w}=x;for(let C=0;C<3;C++)w[C]=1/0,w[C+3]=-1/0,T[C]=1/0,T[C+3]=-1/0,b[C]=1/0,b[C+3]=-1/0;lr(S,e,b)}m.sort(Dl);let v=r;for(let S=0;S<v;S++){const x=m[S];for(;S+1<v&&m[S+1].candidate===x.candidate;)m.splice(S+1,1),v--}for(let S=u;S<h;S+=6){const x=e[S+2*f];for(let b=0;b<v;b++){const T=m[b];x>=T.candidate?lr(S,e,T.rightCacheBounds):(lr(S,e,T.leftCacheBounds),T.count++)}}for(let S=0;S<v;S++){const x=m[S],b=x.count,T=r-x.count,w=x.leftCacheBounds,C=x.rightCacheBounds;let P=0;b!==0&&(P=ei(w)/c);let R=0;T!==0&&(R=ei(C)/c);const E=$s+dn*(P*b+R*T);E<l&&(a=f,l=E,o=x.candidate)}}else{for(let v=0;v<ne;v++){const S=fe[v];S.count=0,S.candidate=d+p+v*p;const x=S.bounds;for(let b=0;b<3;b++)x[b]=1/0,x[b+3]=-1/0}for(let v=u;v<h;v+=6){let b=~~((e[v+2*f]-d)/p);b>=ne&&(b=ne-1);const T=fe[b];T.count++,lr(v,e,T.bounds)}const m=fe[ne-1];Xs(m.bounds,m.rightCacheBounds);for(let v=ne-2;v>=0;v--){const S=fe[v],x=fe[v+1];Ws(S.bounds,x.rightCacheBounds,S.rightCacheBounds)}let g=0;for(let v=0;v<ne-1;v++){const S=fe[v],x=S.count,b=S.bounds,w=fe[v+1].rightCacheBounds;x!==0&&(g===0?Xs(b,ur):Ws(b,ur,ur)),g+=x;let C=0,P=0;g!==0&&(C=ei(ur)/c);const R=r-g;R!==0&&(P=ei(w)/c);const E=$s+dn*(C*g+P*R);E<l&&(a=f,l=E,o=S.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Vl(n,t,e,i){let r=0;for(let s=t,a=t+e;s<a;s++)r+=n[s*6+i*2];return r/e}class yn{constructor(){this.boundingData=new Float32Array(6)}}function Jl(n,t,e,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&e[a*6+l]<c;)a++;for(;a<=o&&e[o*6+l]>=c;)o--;if(a<o){for(let u=0;u<3;u++){let h=t[a*3+u];t[a*3+u]=t[o*3+u],t[o*3+u]=h}for(let u=0;u<6;u++){let h=e[a*6+u];e[a*6+u]=e[o*6+u],e[o*6+u]=h}a++,o--}else return a}}function Gl(n,t,e,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&e[a*6+l]<c;)a++;for(;a<=o&&e[o*6+l]>=c;)o--;if(a<o){let u=n[a];n[a]=n[o],n[o]=u;for(let h=0;h<6;h++){let f=e[a*6+h];e[a*6+h]=e[o*6+h],e[o*6+h]=f}a++,o--}else return a}}function St(n,t){return t[n+15]===65535}function Mt(n,t){return t[n+6]}function Ct(n,t){return t[n+14]}function Pt(n){return n+8}function wt(n,t){return t[n+6]}function da(n,t){return t[n+7]}let pa,fi,Ar,ma;const jl=Math.pow(2,32);function Dn(n){return"count"in n?1:1+Dn(n.left)+Dn(n.right)}function $l(n,t,e){return pa=new Float32Array(e),fi=new Uint32Array(e),Ar=new Uint16Array(e),ma=new Uint8Array(e),Ln(n,t)}function Ln(n,t){const e=n/4,i=n/2,r="count"in t,s=t.boundingData;for(let a=0;a<6;a++)pa[e+a]=s[a];if(r)if(t.buffer){const a=t.buffer;ma.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=mi){const l=o/2;St(l,Ar)||(fi[o/4+6]+=e)}return n+a.byteLength}else{const a=t.offset,o=t.count;return fi[e+6]=a,Ar[i+14]=o,Ar[i+15]=$r,n+mi}else{const a=t.left,o=t.right,c=t.splitAxis;let l;if(l=Ln(n+mi,a),l/4>jl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return fi[e+6]=l/4,l=Ln(l,o),fi[e+7]=c,l}}function ql(n,t){const e=(n.index?n.index.count:n.attributes.position.count)/3,i=e>2**16,r=i?4:2,s=t?new SharedArrayBuffer(e*r):new ArrayBuffer(e*r),a=i?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Xl(n,t,e,i,r){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:u}=r,h=n._indirectBuffer,f=n.geometry,d=f.index?f.index.array:null,y=u?Gl:Jl,_=Xe(f),p=new Float32Array(6);let m=!1;const g=new yn;return mn(t,e,i,g.boundingData,p),S(g,e,i,p),g;function v(x){l&&l(x/_)}function S(x,b,T,w=null,C=0){if(!m&&C>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(f))),T<=o||C>=s)return v(b+T),x.offset=b,x.count=T,x;const P=Ll(x.boundingData,w,t,b,T,c);if(P.axis===-1)return v(b+T),x.offset=b,x.count=T,x;const R=y(h,d,t,b,T,P);if(R===b||R===b+T)v(b+T),x.offset=b,x.count=T;else{x.splitAxis=P.axis;const E=new yn,A=b,k=R-b;x.left=E,mn(t,A,k,E.boundingData,p),S(E,A,k,p,C+1);const z=new yn,U=R,L=T-k;x.right=z,mn(t,U,L,z.boundingData,p),S(z,U,L,p,C+1)}return x}}function Wl(n,t){const e=n.geometry;t.indirect&&(n._indirectBuffer=ql(e,t.useSharedArrayBuffer),Nl(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||Ul(e,t);const i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Fl(e),s=t.indirect?ha(e,t.range):fa(e,t.range);n._roots=s.map(a=>{const o=Xl(n,r,a.offset,a.count,t),c=Dn(o),l=new i(mi*c);return $l(0,o,l),l})}class le{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,r=-1/0;for(let s=0,a=t.length;s<a;s++){const c=t[s][e];i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}setFromPoints(t,e){let i=1/0,r=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s],c=t.dot(o);i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}isSeparated(t){return this.min>t.max||t.min>this.max}}le.prototype.setFromBox=function(){const n=new M.Vector3;return function(e,i){const r=i.min,s=i.max;let a=1/0,o=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){n.x=r.x*c+s.x*(1-c),n.y=r.y*l+s.y*(1-l),n.z=r.z*u+s.z*(1-u);const h=e.dot(n);a=Math.min(h,a),o=Math.max(h,o)}this.min=a,this.max=o}}();const Hl=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Vector3;return function(r,s,a){const o=r.start,c=n,l=s.start,u=t;e.subVectors(o,l),n.subVectors(r.end,r.start),t.subVectors(s.end,s.start);const h=e.dot(u),f=u.dot(c),d=u.dot(u),y=e.dot(c),p=c.dot(c)*d-f*f;let m,g;p!==0?m=(h*f-y*d)/p:m=0,g=(h+m*f)/d,a.x=m,a.y=g}}(),ns=function(){const n=new M.Vector2,t=new M.Vector3,e=new M.Vector3;return function(r,s,a,o){Hl(r,s,n);let c=n.x,l=n.y;if(c>=0&&c<=1&&l>=0&&l<=1){r.at(c,a),s.at(l,o);return}else if(c>=0&&c<=1){l<0?s.at(0,o):s.at(1,o),r.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?r.at(0,a):r.at(1,a),s.closestPointToPoint(a,!0,o);return}else{let u;c<0?u=r.start:u=r.end;let h;l<0?h=s.start:h=s.end;const f=t,d=e;if(r.closestPointToPoint(h,!0,t),s.closestPointToPoint(u,!0,e),f.distanceToSquared(h)<=d.distanceToSquared(u)){a.copy(f),o.copy(h);return}else{a.copy(u),o.copy(d);return}}}}(),Yl=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Plane,i=new M.Line3;return function(s,a){const{radius:o,center:c}=s,{a:l,b:u,c:h}=a;if(i.start=l,i.end=u,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o||(i.start=l,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o)||(i.start=u,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o))return!0;const _=a.getPlane(e);if(Math.abs(_.distanceToPoint(c))<=o){const m=_.projectPoint(c,t);if(a.containsPoint(m))return!0}return!1}}(),Zl=1e-15;function gn(n){return Math.abs(n)<Zl}class Rt extends M.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M.Vector3),this.satBounds=new Array(4).fill().map(()=>new le),this.points=[this.a,this.b,this.c],this.sphere=new M.Sphere,this.plane=new M.Plane,this.needsUpdate=!0}intersectsSphere(t){return Yl(t,this)}update(){const t=this.a,e=this.b,i=this.c,r=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,r);const l=s[1],u=a[1];l.subVectors(t,e),u.setFromPoints(l,r);const h=s[2],f=a[2];h.subVectors(e,i),f.setFromPoints(h,r);const d=s[3],y=a[3];d.subVectors(i,t),y.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Rt.prototype.closestPointToSegment=function(){const n=new M.Vector3,t=new M.Vector3,e=new M.Line3;return function(r,s=null,a=null){const{start:o,end:c}=r,l=this.points;let u,h=1/0;for(let f=0;f<3;f++){const d=(f+1)%3;e.start.copy(l[f]),e.end.copy(l[d]),ns(e,r,n,t),u=n.distanceToSquared(t),u<h&&(h=u,s&&s.copy(n),a&&a.copy(t))}return this.closestPointToPoint(o,n),u=o.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(o)),this.closestPointToPoint(c,n),u=c.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(c)),Math.sqrt(h)}}();Rt.prototype.intersectsTriangle=function(){const n=new Rt,t=new Array(3),e=new Array(3),i=new le,r=new le,s=new M.Vector3,a=new M.Vector3,o=new M.Vector3,c=new M.Vector3,l=new M.Vector3,u=new M.Line3,h=new M.Line3,f=new M.Line3,d=new M.Vector3;function y(_,p,m){const g=_.points;let v=0,S=-1;for(let x=0;x<3;x++){const{start:b,end:T}=u;b.copy(g[x]),T.copy(g[(x+1)%3]),u.delta(a);const w=gn(p.distanceToPoint(b));if(gn(p.normal.dot(a))&&w){m.copy(u),v=2;break}const C=p.intersectLine(u,d);if(!C&&w&&d.copy(b),(C||w)&&!gn(d.distanceTo(T))){if(v<=1)(v===1?m.start:m.end).copy(d),w&&(S=v);else if(v>=2){(S===1?m.start:m.end).copy(d),v=2;break}if(v++,v===2&&S===-1)break}}return v}return function(p,m=null,g=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(n.copy(p),n.update(),p=n);const v=this.plane,S=p.plane;if(Math.abs(v.normal.dot(S.normal))>1-1e-10){const x=this.satBounds,b=this.satAxes;e[0]=p.a,e[1]=p.b,e[2]=p.c;for(let C=0;C<4;C++){const P=x[C],R=b[C];if(i.setFromPoints(R,e),P.isSeparated(i))return!1}const T=p.satBounds,w=p.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let C=0;C<4;C++){const P=T[C],R=w[C];if(i.setFromPoints(R,t),P.isSeparated(i))return!1}for(let C=0;C<4;C++){const P=b[C];for(let R=0;R<4;R++){const E=w[R];if(s.crossVectors(P,E),i.setFromPoints(s,t),r.setFromPoints(s,e),i.isSeparated(r))return!1}}return m&&(g||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),m.start.set(0,0,0),m.end.set(0,0,0)),!0}else{const x=y(this,S,h);if(x===1&&p.containsPoint(h.end))return m&&(m.start.copy(h.end),m.end.copy(h.end)),!0;if(x!==2)return!1;const b=y(p,v,f);if(b===1&&this.containsPoint(f.end))return m&&(m.start.copy(f.end),m.end.copy(f.end)),!0;if(b!==2)return!1;if(h.delta(o),f.delta(c),o.dot(c)<0){let A=f.start;f.start=f.end,f.end=A}const T=h.start.dot(o),w=h.end.dot(o),C=f.start.dot(o),P=f.end.dot(o),R=w<C,E=T<P;return T!==P&&C!==w&&R===E?!1:(m&&(l.subVectors(h.start,f.start),l.dot(o)>0?m.start.copy(h.start):m.start.copy(f.start),l.subVectors(h.end,f.end),l.dot(o)<0?m.end.copy(h.end):m.end.copy(f.end)),!0)}}}();Rt.prototype.distanceToPoint=function(){const n=new M.Vector3;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}();Rt.prototype.distanceToTriangle=function(){const n=new M.Vector3,t=new M.Vector3,e=["a","b","c"],i=new M.Line3,r=new M.Line3;return function(a,o=null,c=null){const l=o||c?i:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let u=1/0;for(let h=0;h<3;h++){let f;const d=e[h],y=a[d];this.closestPointToPoint(y,n),f=y.distanceToSquared(n),f<u&&(u=f,o&&o.copy(n),c&&c.copy(y));const _=this[d];a.closestPointToPoint(_,n),f=_.distanceToSquared(n),f<u&&(u=f,o&&o.copy(_),c&&c.copy(n))}for(let h=0;h<3;h++){const f=e[h],d=e[(h+1)%3];i.set(this[f],this[d]);for(let y=0;y<3;y++){const _=e[y],p=e[(y+1)%3];r.set(a[_],a[p]),ns(i,r,n,t);const m=n.distanceToSquared(t);m<u&&(u=m,o&&o.copy(n),c&&c.copy(t))}}return Math.sqrt(u)}}();class dt{constructor(t,e,i){this.isOrientedBox=!0,this.min=new M.Vector3,this.max=new M.Vector3,this.matrix=new M.Matrix4,this.invMatrix=new M.Matrix4,this.points=new Array(8).fill().map(()=>new M.Vector3),this.satAxes=new Array(3).fill().map(()=>new M.Vector3),this.satBounds=new Array(3).fill().map(()=>new le),this.alignedSatBounds=new Array(3).fill().map(()=>new le),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}dt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,r=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){const f=1*l|2*u|4*h,d=r[f];d.x=l?i.x:e.x,d.y=u?i.y:e.y,d.z=h?i.z:e.z,d.applyMatrix4(t)}const s=this.satBounds,a=this.satAxes,o=r[0];for(let l=0;l<3;l++){const u=a[l],h=s[l],f=1<<l,d=r[f];u.subVectors(o,d),h.setFromPoints(u,r)}const c=this.alignedSatBounds;c[0].setFromPointsField(r,"x"),c[1].setFromPointsField(r,"y"),c[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();dt.prototype.intersectsBox=function(){const n=new le;return function(e){this.needsUpdate&&this.update();const i=e.min,r=e.max,s=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(n.min=i.x,n.max=r.x,o[0].isSeparated(n)||(n.min=i.y,n.max=r.y,o[1].isSeparated(n))||(n.min=i.z,n.max=r.z,o[2].isSeparated(n)))return!1;for(let c=0;c<3;c++){const l=a[c],u=s[c];if(n.setFromBox(l,e),u.isSeparated(n))return!1}return!0}}();dt.prototype.intersectsTriangle=function(){const n=new Rt,t=new Array(3),e=new le,i=new le,r=new M.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(n.copy(a),n.update(),a=n);const o=this.satBounds,c=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let f=0;f<3;f++){const d=o[f],y=c[f];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const l=a.satBounds,u=a.satAxes,h=this.points;for(let f=0;f<3;f++){const d=l[f],y=u[f];if(e.setFromPoints(y,h),d.isSeparated(e))return!1}for(let f=0;f<3;f++){const d=c[f];for(let y=0;y<4;y++){const _=u[y];if(r.crossVectors(d,_),e.setFromPoints(r,t),i.setFromPoints(r,h),e.isSeparated(i))return!1}}return!0}}();dt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}();dt.prototype.distanceToPoint=function(){const n=new M.Vector3;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}();dt.prototype.distanceToBox=function(){const n=["x","y","z"],t=new Array(12).fill().map(()=>new M.Line3),e=new Array(12).fill().map(()=>new M.Line3),i=new M.Vector3,r=new M.Vector3;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(r),this.closestPointToPoint(r,i),a.closestPointToPoint(i,r),c&&c.copy(i),l&&l.copy(r)),0;const u=o*o,h=a.min,f=a.max,d=this.points;let y=1/0;for(let p=0;p<8;p++){const m=d[p];r.copy(m).clamp(h,f);const g=m.distanceToSquared(r);if(g<y&&(y=g,c&&c.copy(m),l&&l.copy(r),g<u))return Math.sqrt(g)}let _=0;for(let p=0;p<3;p++)for(let m=0;m<=1;m++)for(let g=0;g<=1;g++){const v=(p+1)%3,S=(p+2)%3,x=m<<v|g<<S,b=1<<p|m<<v|g<<S,T=d[x],w=d[b];t[_].set(T,w);const P=n[p],R=n[v],E=n[S],A=e[_],k=A.start,z=A.end;k[P]=h[P],k[R]=m?h[R]:f[R],k[E]=g?h[E]:f[R],z[P]=f[P],z[R]=m?h[R]:f[R],z[E]=g?h[E]:f[R],_++}for(let p=0;p<=1;p++)for(let m=0;m<=1;m++)for(let g=0;g<=1;g++){r.x=p?f.x:h.x,r.y=m?f.y:h.y,r.z=g?f.z:h.z,this.closestPointToPoint(r,i);const v=r.distanceToSquared(i);if(v<y&&(y=v,c&&c.copy(i),l&&l.copy(r),v<u))return Math.sqrt(v)}for(let p=0;p<12;p++){const m=t[p];for(let g=0;g<12;g++){const v=e[g];ns(m,v,i,r);const S=i.distanceToSquared(r);if(S<y&&(y=S,c&&c.copy(i),l&&l.copy(r),S<u))return Math.sqrt(S)}}return Math.sqrt(y)}}();class ss{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Ql extends ss{constructor(){super(()=>new Rt)}}const Et=new Ql;class Kl{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const $=new Kl;let ye,Ve;const Be=[],hr=new ss(()=>new M.Box3);function tu(n,t,e,i,r,s){ye=hr.getPrimitive(),Ve=hr.getPrimitive(),Be.push(ye,Ve),$.setBuffer(n._roots[t]);const a=Vn(0,n.geometry,e,i,r,s);$.clearBuffer(),hr.releasePrimitive(ye),hr.releasePrimitive(Ve),Be.pop(),Be.pop();const o=Be.length;return o>0&&(Ve=Be[o-1],ye=Be[o-2]),a}function Vn(n,t,e,i,r=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=$;let u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);return Y(n,o,ye),i(f,d,!1,a,s+n,ye)}else{let P=function(E){const{uint16Array:A,uint32Array:k}=$;let z=E*2;for(;!St(z,A);)E=Pt(E),z=E*2;return Mt(E,k)},R=function(E){const{uint16Array:A,uint32Array:k}=$;let z=E*2;for(;!St(z,A);)E=wt(E,k),z=E*2;return Mt(E,k)+Ct(z,A)};const f=Pt(n),d=wt(n,l);let y=f,_=d,p,m,g,v;if(r&&(g=ye,v=Ve,Y(y,o,g),Y(_,o,v),p=r(g),m=r(v),m<p)){y=d,_=f;const E=p;p=m,m=E,g=v}g||(g=ye,Y(y,o,g));const S=St(y*2,c),x=e(g,S,p,a+1,s+y);let b;if(x===Fn){const E=P(y),k=R(y)-E;b=i(E,k,!0,a+1,s+y,g)}else b=x&&Vn(y,t,e,i,r,s,a+1);if(b)return!0;v=Ve,Y(_,o,v);const T=St(_*2,c),w=e(v,T,m,a+1,s+_);let C;if(w===Fn){const E=P(_),k=R(_)-E;C=i(E,k,!0,a+1,s+_,v)}else C=w&&Vn(_,t,e,i,r,s,a+1);return!!C}}const ii=new M.Vector3,vn=new M.Vector3;function eu(n,t,e={},i=0,r=1/0){const s=i*i,a=r*r;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:u=>(ii.copy(t).clamp(u.min,u.max),ii.distanceToSquared(t)),intersectsBounds:(u,h,f)=>f<o&&f<a,intersectsTriangle:(u,h)=>{u.closestPointToPoint(t,ii);const f=t.distanceToSquared(ii);return f<o&&(vn.copy(ii),o=f,c=h),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return e.point?e.point.copy(vn):e.point=vn.clone(),e.distance=l,e.faceIndex=c,e}const iu=parseInt(M.REVISION)>=169,Se=new M.Vector3,be=new M.Vector3,Te=new M.Vector3,fr=new M.Vector2,dr=new M.Vector2,pr=new M.Vector2,Hs=new M.Vector3,Ys=new M.Vector3,Zs=new M.Vector3,ri=new M.Vector3;function ru(n,t,e,i,r,s,a,o){let c;if(s===M.BackSide?c=n.intersectTriangle(i,e,t,!0,r):c=n.intersectTriangle(t,e,i,s!==M.DoubleSide,r),c===null)return null;const l=n.origin.distanceTo(r);return l<a||l>o?null:{distance:l,point:r.clone()}}function nu(n,t,e,i,r,s,a,o,c,l,u){Se.fromBufferAttribute(t,s),be.fromBufferAttribute(t,a),Te.fromBufferAttribute(t,o);const h=ru(n,Se,be,Te,ri,c,l,u);if(h){const f=new M.Vector3;M.Triangle.getBarycoord(ri,Se,be,Te,f),i&&(fr.fromBufferAttribute(i,s),dr.fromBufferAttribute(i,a),pr.fromBufferAttribute(i,o),h.uv=M.Triangle.getInterpolation(ri,Se,be,Te,fr,dr,pr,new M.Vector2)),r&&(fr.fromBufferAttribute(r,s),dr.fromBufferAttribute(r,a),pr.fromBufferAttribute(r,o),h.uv1=M.Triangle.getInterpolation(ri,Se,be,Te,fr,dr,pr,new M.Vector2)),e&&(Hs.fromBufferAttribute(e,s),Ys.fromBufferAttribute(e,a),Zs.fromBufferAttribute(e,o),h.normal=M.Triangle.getInterpolation(ri,Se,be,Te,Hs,Ys,Zs,new M.Vector3),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:s,b:a,c:o,normal:new M.Vector3,materialIndex:0};M.Triangle.getNormal(Se,be,Te,d.normal),h.face=d,h.faceIndex=s,iu&&(h.barycoord=f)}return h}function qr(n,t,e,i,r,s,a){const o=i*3;let c=o+0,l=o+1,u=o+2;const h=n.index;n.index&&(c=h.getX(c),l=h.getX(l),u=h.getX(u));const{position:f,normal:d,uv:y,uv1:_}=n.attributes,p=nu(e,f,d,y,_,c,l,u,t,s,a);return p?(p.faceIndex=i,r&&r.push(p),p):null}function et(n,t,e,i){const r=n.a,s=n.b,a=n.c;let o=t,c=t+1,l=t+2;e&&(o=e.getX(o),c=e.getX(c),l=e.getX(l)),r.x=i.getX(o),r.y=i.getY(o),r.z=i.getZ(o),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l)}function su(n,t,e,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++)qr(c,t,e,u,s,a,o)}function ou(n,t,e,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=qr(o,t,e,h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function au(n,t,e,i,r,s,a){const{geometry:o}=e,{index:c}=o,l=o.attributes.position;for(let u=n,h=t+n;u<h;u++){let f;if(f=u,et(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function cu(n,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=n.geometry,i=e.index?e.index.array:null,r=e.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===$r){const m=a[f+6],g=o[_+14];let v=1/0,S=1/0,x=1/0,b=-1/0,T=-1/0,w=-1/0;for(let C=3*m,P=3*(m+g);C<P;C++){let R=i[C];const E=r.getX(R),A=r.getY(R),k=r.getZ(R);E<v&&(v=E),E>b&&(b=E),A<S&&(S=A),A>T&&(T=A),k<x&&(x=k),k>w&&(w=k)}return c[f+0]!==v||c[f+1]!==S||c[f+2]!==x||c[f+3]!==b||c[f+4]!==T||c[f+5]!==w?(c[f+0]=v,c[f+1]=S,c[f+2]=x,c[f+3]=b,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,g=a[f+6],v=m+d,S=g+d;let x=y,b=!1,T=!1;t?x||(b=t.has(v),T=t.has(S),x=!b&&!T):(b=!0,T=!0);const w=x||b,C=x||T;let P=!1;w&&(P=h(m,d,x));let R=!1;C&&(R=h(g,d,x));const E=P||R;if(E)for(let A=0;A<3;A++){const k=m+A,z=g+A,U=c[k],L=c[k+3],I=c[z],X=c[z+3];c[f+A]=U<I?U:I,c[f+A+3]=L>X?L:X}return E}}}function ge(n,t,e,i,r){let s,a,o,c,l,u;const h=1/e.direction.x,f=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,_=e.origin.y,p=e.origin.z;let m=t[n],g=t[n+3],v=t[n+1],S=t[n+3+1],x=t[n+2],b=t[n+3+2];return h>=0?(s=(m-y)*h,a=(g-y)*h):(s=(g-y)*h,a=(m-y)*h),f>=0?(o=(v-_)*f,c=(S-_)*f):(o=(S-_)*f,c=(v-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),d>=0?(l=(x-p)*d,u=(b-p)*d):(l=(b-p)*d,u=(x-p)*d),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=r&&a>=i)}function lu(n,t,e,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++){let f=l?l[u]:u;qr(c,t,e,f,s,a,o)}}function uu(n,t,e,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=qr(o,t,e,c?c[h]:h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function hu(n,t,e,i,r,s,a){const{geometry:o}=e,{index:c}=o,l=o.attributes.position;for(let u=n,h=t+n;u<h;u++){let f;if(f=e.resolveTriangleIndex(u),et(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function fu(n,t,e,i,r,s,a){$.setBuffer(n._roots[t]),Jn(0,n,e,i,r,s,a),$.clearBuffer()}function Jn(n,t,e,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);su(t,e,i,f,d,r,s,a)}else{const f=Pt(n);ge(f,o,i,s,a)&&Jn(f,t,e,i,r,s,a);const d=wt(n,l);ge(d,o,i,s,a)&&Jn(d,t,e,i,r,s,a)}}const du=["x","y","z"];function pu(n,t,e,i,r,s){$.setBuffer(n._roots[t]);const a=Gn(0,n,e,i,r,s);return $.clearBuffer(),a}function Gn(n,t,e,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(St(l,o)){const h=Mt(n,c),f=Ct(l,o);return ou(t,e,i,h,f,r,s)}else{const h=da(n,c),f=du[h],y=i.direction[f]>=0;let _,p;y?(_=Pt(n),p=wt(n,c)):(_=wt(n,c),p=Pt(n));const g=ge(_,a,i,r,s)?Gn(_,t,e,i,r,s):null;if(g){const x=g.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return g}const S=ge(p,a,i,r,s)?Gn(p,t,e,i,r,s):null;return g&&S?g.distance<=S.distance?g:S:g||S||null}}const mr=new M.Box3,Oe=new Rt,Ie=new Rt,ni=new M.Matrix4,Qs=new dt,yr=new dt;function mu(n,t,e,i){$.setBuffer(n._roots[t]);const r=jn(0,n,e,i);return $.clearBuffer(),r}function jn(n,t,e,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(e.boundingBox||e.computeBoundingBox(),Qs.set(e.boundingBox.min,e.boundingBox.max,i),r=Qs),St(c,a)){const u=t.geometry,h=u.index,f=u.attributes.position,d=e.index,y=e.attributes.position,_=Mt(n,o),p=Ct(c,a);if(ni.copy(i).invert(),e.boundsTree)return Y(n,s,yr),yr.matrix.copy(ni),yr.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>yr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(i),g.b.applyMatrix4(i),g.c.applyMatrix4(i),g.needsUpdate=!0;for(let v=_*3,S=(p+_)*3;v<S;v+=3)if(et(Ie,v,h,f),Ie.needsUpdate=!0,g.intersectsTriangle(Ie))return!0;return!1}});for(let m=_*3,g=(p+_)*3;m<g;m+=3){et(Oe,m,h,f),Oe.a.applyMatrix4(ni),Oe.b.applyMatrix4(ni),Oe.c.applyMatrix4(ni),Oe.needsUpdate=!0;for(let v=0,S=d.count;v<S;v+=3)if(et(Ie,v,d,y),Ie.needsUpdate=!0,Oe.intersectsTriangle(Ie))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,mr),!!(r.intersectsBox(mr)&&jn(u,t,e,i,r)||(Y(h,s,mr),r.intersectsBox(mr)&&jn(h,t,e,i,r)))}}const gr=new M.Matrix4,_n=new dt,si=new dt,yu=new M.Vector3,gu=new M.Vector3,vu=new M.Vector3,_u=new M.Vector3;function xu(n,t,e,i={},r={},s=0,a=1/0){t.boundingBox||t.computeBoundingBox(),_n.set(t.boundingBox.min,t.boundingBox.max,e),_n.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=t.attributes.position,h=t.index,f=Et.getPrimitive(),d=Et.getPrimitive();let y=yu,_=gu,p=null,m=null;r&&(p=vu,m=_u);let g=1/0,v=null,S=null;return gr.copy(e).invert(),si.matrix.copy(gr),n.shapecast({boundsTraverseOrder:x=>_n.distanceToBox(x),intersectsBounds:(x,b,T)=>T<g&&T<a?(b&&(si.min.copy(x.min),si.max.copy(x.max),si.needsUpdate=!0),!0):!1,intersectsRange:(x,b)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:w=>si.distanceToBox(w),intersectsBounds:(w,C,P)=>P<g&&P<a,intersectsRange:(w,C)=>{for(let P=w,R=w+C;P<R;P++){et(d,3*P,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=x,A=x+b;E<A;E++){et(f,3*E,l,c),f.needsUpdate=!0;const k=f.distanceToTriangle(d,y,p);if(k<g&&(_.copy(y),m&&m.copy(p),g=k,v=E,S=P),k<s)return!0}}}});{const T=Xe(t);for(let w=0,C=T;w<C;w++){et(d,3*w,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let P=x,R=x+b;P<R;P++){et(f,3*P,l,c),f.needsUpdate=!0;const E=f.distanceToTriangle(d,y,p);if(E<g&&(_.copy(y),m&&m.copy(p),g=E,v=P,S=w),E<s)return!0}}}}}),Et.releasePrimitive(f),Et.releasePrimitive(d),g===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=g,i.faceIndex=v,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(gr),_.applyMatrix4(gr),r.distance=_.sub(r.point).length(),r.faceIndex=S),i)}function Su(n,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=n.geometry,i=e.index?e.index.array:null,r=e.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===$r){const m=a[f+6],g=o[_+14];let v=1/0,S=1/0,x=1/0,b=-1/0,T=-1/0,w=-1/0;for(let C=m,P=m+g;C<P;C++){const R=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let A=R+E;A=i?i[A]:A;const k=r.getX(A),z=r.getY(A),U=r.getZ(A);k<v&&(v=k),k>b&&(b=k),z<S&&(S=z),z>T&&(T=z),U<x&&(x=U),U>w&&(w=U)}}return c[f+0]!==v||c[f+1]!==S||c[f+2]!==x||c[f+3]!==b||c[f+4]!==T||c[f+5]!==w?(c[f+0]=v,c[f+1]=S,c[f+2]=x,c[f+3]=b,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,g=a[f+6],v=m+d,S=g+d;let x=y,b=!1,T=!1;t?x||(b=t.has(v),T=t.has(S),x=!b&&!T):(b=!0,T=!0);const w=x||b,C=x||T;let P=!1;w&&(P=h(m,d,x));let R=!1;C&&(R=h(g,d,x));const E=P||R;if(E)for(let A=0;A<3;A++){const k=m+A,z=g+A,U=c[k],L=c[k+3],I=c[z],X=c[z+3];c[f+A]=U<I?U:I,c[f+A+3]=L>X?L:X}return E}}}function bu(n,t,e,i,r,s,a){$.setBuffer(n._roots[t]),$n(0,n,e,i,r,s,a),$.clearBuffer()}function $n(n,t,e,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(St(u,c)){const f=Mt(n,l),d=Ct(u,c);lu(t,e,i,f,d,r,s,a)}else{const f=Pt(n);ge(f,o,i,s,a)&&$n(f,t,e,i,r,s,a);const d=wt(n,l);ge(d,o,i,s,a)&&$n(d,t,e,i,r,s,a)}}const Tu=["x","y","z"];function Mu(n,t,e,i,r,s){$.setBuffer(n._roots[t]);const a=qn(0,n,e,i,r,s);return $.clearBuffer(),a}function qn(n,t,e,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(St(l,o)){const h=Mt(n,c),f=Ct(l,o);return uu(t,e,i,h,f,r,s)}else{const h=da(n,c),f=Tu[h],y=i.direction[f]>=0;let _,p;y?(_=Pt(n),p=wt(n,c)):(_=wt(n,c),p=Pt(n));const g=ge(_,a,i,r,s)?qn(_,t,e,i,r,s):null;if(g){const x=g.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return g}const S=ge(p,a,i,r,s)?qn(p,t,e,i,r,s):null;return g&&S?g.distance<=S.distance?g:S:g||S||null}}const vr=new M.Box3,Ue=new Rt,Ne=new Rt,oi=new M.Matrix4,Ks=new dt,_r=new dt;function Cu(n,t,e,i){$.setBuffer(n._roots[t]);const r=Xn(0,n,e,i);return $.clearBuffer(),r}function Xn(n,t,e,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(e.boundingBox||e.computeBoundingBox(),Ks.set(e.boundingBox.min,e.boundingBox.max,i),r=Ks),St(c,a)){const u=t.geometry,h=u.index,f=u.attributes.position,d=e.index,y=e.attributes.position,_=Mt(n,o),p=Ct(c,a);if(oi.copy(i).invert(),e.boundsTree)return Y(n,s,_r),_r.matrix.copy(oi),_r.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:g=>_r.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(i),g.b.applyMatrix4(i),g.c.applyMatrix4(i),g.needsUpdate=!0;for(let v=_,S=p+_;v<S;v++)if(et(Ne,3*t.resolveTriangleIndex(v),h,f),Ne.needsUpdate=!0,g.intersectsTriangle(Ne))return!0;return!1}});for(let m=_,g=p+_;m<g;m++){const v=t.resolveTriangleIndex(m);et(Ue,3*v,h,f),Ue.a.applyMatrix4(oi),Ue.b.applyMatrix4(oi),Ue.c.applyMatrix4(oi),Ue.needsUpdate=!0;for(let S=0,x=d.count;S<x;S+=3)if(et(Ne,S,d,y),Ne.needsUpdate=!0,Ue.intersectsTriangle(Ne))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,vr),!!(r.intersectsBox(vr)&&Xn(u,t,e,i,r)||(Y(h,s,vr),r.intersectsBox(vr)&&Xn(h,t,e,i,r)))}}const xr=new M.Matrix4,xn=new dt,ai=new dt,Pu=new M.Vector3,wu=new M.Vector3,Eu=new M.Vector3,Ru=new M.Vector3;function Au(n,t,e,i={},r={},s=0,a=1/0){t.boundingBox||t.computeBoundingBox(),xn.set(t.boundingBox.min,t.boundingBox.max,e),xn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=t.attributes.position,h=t.index,f=Et.getPrimitive(),d=Et.getPrimitive();let y=Pu,_=wu,p=null,m=null;r&&(p=Eu,m=Ru);let g=1/0,v=null,S=null;return xr.copy(e).invert(),ai.matrix.copy(xr),n.shapecast({boundsTraverseOrder:x=>xn.distanceToBox(x),intersectsBounds:(x,b,T)=>T<g&&T<a?(b&&(ai.min.copy(x.min),ai.max.copy(x.max),ai.needsUpdate=!0),!0):!1,intersectsRange:(x,b)=>{if(t.boundsTree){const T=t.boundsTree;return T.shapecast({boundsTraverseOrder:w=>ai.distanceToBox(w),intersectsBounds:(w,C,P)=>P<g&&P<a,intersectsRange:(w,C)=>{for(let P=w,R=w+C;P<R;P++){const E=T.resolveTriangleIndex(P);et(d,3*E,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=x,k=x+b;A<k;A++){const z=n.resolveTriangleIndex(A);et(f,3*z,l,c),f.needsUpdate=!0;const U=f.distanceToTriangle(d,y,p);if(U<g&&(_.copy(y),m&&m.copy(p),g=U,v=A,S=P),U<s)return!0}}}})}else{const T=Xe(t);for(let w=0,C=T;w<C;w++){et(d,3*w,h,u),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let P=x,R=x+b;P<R;P++){const E=n.resolveTriangleIndex(P);et(f,3*E,l,c),f.needsUpdate=!0;const A=f.distanceToTriangle(d,y,p);if(A<g&&(_.copy(y),m&&m.copy(p),g=A,v=P,S=w),A<s)return!0}}}}}),Et.releasePrimitive(f),Et.releasePrimitive(d),g===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=g,i.faceIndex=v,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(xr),_.applyMatrix4(xr),r.distance=_.sub(r.point).length(),r.faceIndex=S),i)}function ku(){return typeof SharedArrayBuffer<"u"}const yi=new $.constructor,Lr=new $.constructor,pe=new ss(()=>new M.Box3),Fe=new M.Box3,De=new M.Box3,Sn=new M.Box3,bn=new M.Box3;let Tn=!1;function zu(n,t,e,i){if(Tn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Tn=!0;const r=n._roots,s=t._roots;let a,o=0,c=0;const l=new M.Matrix4().copy(e).invert();for(let u=0,h=r.length;u<h;u++){yi.setBuffer(r[u]),c=0;const f=pe.getPrimitive();Y(0,yi.float32Array,f),f.applyMatrix4(l);for(let d=0,y=s.length;d<y&&(Lr.setBuffer(s[d]),a=Ut(0,0,e,l,i,o,c,0,0,f),Lr.clearBuffer(),c+=s[d].length,!a);d++);if(pe.releasePrimitive(f),yi.clearBuffer(),o+=r[u].length,a)break}return Tn=!1,a}function Ut(n,t,e,i,r,s=0,a=0,o=0,c=0,l=null,u=!1){let h,f;u?(h=Lr,f=yi):(h=yi,f=Lr);const d=h.float32Array,y=h.uint32Array,_=h.uint16Array,p=f.float32Array,m=f.uint32Array,g=f.uint16Array,v=n*2,S=t*2,x=St(v,_),b=St(S,g);let T=!1;if(b&&x)u?T=r(Mt(t,m),Ct(t*2,g),Mt(n,y),Ct(n*2,_),c,a+t,o,s+n):T=r(Mt(n,y),Ct(n*2,_),Mt(t,m),Ct(t*2,g),o,s+n,c,a+t);else if(b){const w=pe.getPrimitive();Y(t,p,w),w.applyMatrix4(e);const C=Pt(n),P=wt(n,y);Y(C,d,Fe),Y(P,d,De);const R=w.intersectsBox(Fe),E=w.intersectsBox(De);T=R&&Ut(t,C,i,e,r,a,s,c,o+1,w,!u)||E&&Ut(t,P,i,e,r,a,s,c,o+1,w,!u),pe.releasePrimitive(w)}else{const w=Pt(t),C=wt(t,m);Y(w,p,Sn),Y(C,p,bn);const P=l.intersectsBox(Sn),R=l.intersectsBox(bn);if(P&&R)T=Ut(n,w,e,i,r,s,a,o,c+1,l,u)||Ut(n,C,e,i,r,s,a,o,c+1,l,u);else if(P)if(x)T=Ut(n,w,e,i,r,s,a,o,c+1,l,u);else{const E=pe.getPrimitive();E.copy(Sn).applyMatrix4(e);const A=Pt(n),k=wt(n,y);Y(A,d,Fe),Y(k,d,De);const z=E.intersectsBox(Fe),U=E.intersectsBox(De);T=z&&Ut(w,A,i,e,r,a,s,c,o+1,E,!u)||U&&Ut(w,k,i,e,r,a,s,c,o+1,E,!u),pe.releasePrimitive(E)}else if(R)if(x)T=Ut(n,C,e,i,r,s,a,o,c+1,l,u);else{const E=pe.getPrimitive();E.copy(bn).applyMatrix4(e);const A=Pt(n),k=wt(n,y);Y(A,d,Fe),Y(k,d,De);const z=E.intersectsBox(Fe),U=E.intersectsBox(De);T=z&&Ut(C,A,i,e,r,a,s,c,o+1,E,!u)||U&&Ut(C,k,i,e,r,a,s,c,o+1,E,!u),pe.releasePrimitive(E)}}return T}const Sr=new dt,to=new M.Box3,Bu={strategy:rs,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Ki{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,r=t._roots,s=t._indirectBuffer,a=i.getIndex();let o;return e.cloneBuffers?o={roots:r.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:r,index:a?a.array:null,indirectBuffer:s},o}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:r,roots:s,indirectBuffer:a}=t,o=new Ki(e,{...i,[pn]:!0});if(o._roots=s,o._indirectBuffer=a||null,i.setIndex){const c=e.getIndex();if(c===null){const l=new M.BufferAttribute(t.index,1,!1);e.setIndex(l)}else c.array!==r&&(c.array.set(r),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...Bu,[pn]:!1},e),e.useSharedArrayBuffer&&!ku())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[pn]||(Wl(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new M.Box3))),this.resolveTriangleIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i}refit(t=null){return(this.indirect?Su:cu)(this,t)}traverse(t,e=0){const i=this._roots[e],r=new Uint32Array(i),s=new Uint16Array(i);a(0);function a(o,c=0){const l=o*2,u=s[l+15]===$r;if(u){const h=r[o+6],f=s[l+14];t(c,u,new Float32Array(i,o*4,6),h,f)}else{const h=o+mi/4,f=r[o+6],d=r[o+7];t(c,u,new Float32Array(i,o*4,6),d)||(a(h,c+1),a(f,c+1))}}}raycast(t,e=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=[],c=e.isMaterial,l=Array.isArray(e),u=a.groups,h=c?e.side:e,f=this.indirect?bu:fu;for(let d=0,y=s.length;d<y;d++){const _=l?e[u[d].materialIndex].side:h,p=o.length;if(f(this,d,_,t,o,i,r),l){const m=u[d].materialIndex;for(let g=p,v=o.length;g<v;g++)o[g].face.materialIndex=m}}return o}raycastFirst(t,e=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=e.isMaterial,c=Array.isArray(e);let l=null;const u=a.groups,h=o?e.side:e,f=this.indirect?Mu:pu;for(let d=0,y=s.length;d<y;d++){const _=c?e[u[d].materialIndex].side:h,p=f(this,d,_,t,i,r);p!=null&&(l==null||p.distance<l.distance)&&(l=p,c&&(p.face.materialIndex=u[d].materialIndex))}return l}intersectsGeometry(t,e){let i=!1;const r=this._roots,s=this.indirect?Cu:mu;for(let a=0,o=r.length;a<o&&(i=s(this,a,t,e),!i);a++);return i}shapecast(t){const e=Et.getPrimitive(),i=this.indirect?hu:au;let{boundsTraverseOrder:r,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=t;if(a&&o){const h=a;a=(f,d,y,_,p)=>h(f,d,y,_,p)?!0:i(f,d,this,o,y,_,e)}else a||(o?a=(h,f,d,y)=>i(h,f,this,o,d,y,e):a=(h,f,d)=>d);let c=!1,l=0;const u=this._roots;for(let h=0,f=u.length;h<f;h++){const d=u[h];if(c=tu(this,h,s,a,r,l),c)break;l+=d.byteLength}return Et.releasePrimitive(e),c}bvhcast(t,e,i){let{intersectsRanges:r,intersectsTriangles:s}=i;const a=Et.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const _=this.resolveTriangleIndex(y);et(a,_*3,o,c)}:y=>{et(a,y*3,o,c)},u=Et.getPrimitive(),h=t.geometry.index,f=t.geometry.attributes.position,d=t.indirect?y=>{const _=t.resolveTriangleIndex(y);et(u,_*3,h,f)}:y=>{et(u,y*3,h,f)};if(s){const y=(_,p,m,g,v,S,x,b)=>{for(let T=m,w=m+g;T<w;T++){d(T),u.a.applyMatrix4(e),u.b.applyMatrix4(e),u.c.applyMatrix4(e),u.needsUpdate=!0;for(let C=_,P=_+p;C<P;C++)if(l(C),a.needsUpdate=!0,s(a,u,C,T,v,S,x,b))return!0}return!1};if(r){const _=r;r=function(p,m,g,v,S,x,b,T){return _(p,m,g,v,S,x,b,T)?!0:y(p,m,g,v,S,x,b,T)}}else r=y}return zu(this,t,e,r)}intersectsBox(t,e){return Sr.set(t.min,t.max,e),Sr.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Sr.intersectsBox(i),intersectsTriangle:i=>Sr.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},r={},s=0,a=1/0){return(this.indirect?Au:xu)(this,t,e,i,r,s,a)}closestPointToPoint(t,e={},i=0,r=1/0){return eu(this,t,e,i,r)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),to),t.union(to)}),t}}function eo(n,t,e){return n===null?null:(n.point.applyMatrix4(t.matrixWorld),n.distance=n.point.distanceTo(e.ray.origin),n.object=t,n)}const br=new M.Ray,io=new M.Vector3,ro=new M.Matrix4,Ou=M.Mesh.prototype.raycast,Iu=M.BatchedMesh.prototype.raycast,no=new M.Vector3,ct=new M.Mesh,Tr=[];function Uu(n,t){this.isBatchedMesh?Nu.call(this,n,t):Fu.call(this,n,t)}function Nu(n,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ct.material=this.material,ct.geometry=this.geometry;const a=ct.geometry.boundsTree,o=ct.geometry.drawRange;ct.geometry.boundingSphere===null&&(ct.geometry.boundingSphere=new M.Sphere);for(let c=0,l=i.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=i[c].geometryIndex;if(ct.geometry.boundsTree=e[u],this.getMatrixAt(c,ct.matrixWorld).premultiply(s),!ct.geometry.boundsTree){this.getBoundingBoxAt(u,ct.geometry.boundingBox),this.getBoundingSphereAt(u,ct.geometry.boundingSphere);const h=r[u];ct.geometry.setDrawRange(h.start,h.count)}ct.raycast(n,Tr);for(let h=0,f=Tr.length;h<f;h++){const d=Tr[h];d.object=this,d.batchId=c,t.push(d)}Tr.length=0}ct.geometry.boundsTree=a,ct.geometry.drawRange=o,ct.material=null,ct.geometry=null}else Iu.call(this,n,t)}function Fu(n,t){if(this.geometry.boundsTree){if(this.material===void 0)return;ro.copy(this.matrixWorld).invert(),br.copy(n.ray).applyMatrix4(ro),no.setFromMatrixScale(this.matrixWorld),io.copy(br.direction).multiply(no);const e=io.length(),i=n.near/e,r=n.far/e,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=eo(s.raycastFirst(br,this.material,i,r),this,n);a&&t.push(a)}else{const a=s.raycast(br,this.material,i,r);for(let o=0,c=a.length;o<c;o++){const l=eo(a[o],this,n);l&&t.push(l)}}}else Ou.call(this,n,t)}function Du(n={}){return this.boundsTree=new Ki(this,n),this.boundsTree}const Me=new M.Vector3,Ce=new M.Vector3,Pe=new M.Vector3,so=new M.Vector4,Mr=new M.Vector3,Mn=new M.Vector3,oo=new M.Vector4,ao=new M.Vector4,Cr=new M.Matrix4,co=new M.Matrix4;function ci(n,t){if(!n&&!t)return;const e=n.count===t.count,i=n.normalized===t.normalized,r=n.array.constructor===t.array.constructor,s=n.itemSize===t.itemSize;if(!e||!i||!r||!s)throw new Error}function di(n,t=null){const e=n.array.constructor,i=n.normalized,r=n.itemSize,s=t===null?n.count:t;return new M.BufferAttribute(new e(r*s),r,i)}function ya(n,t,e=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let r=0,s=n.count;r<s;r++){const a=r+e;t.setX(a,n.getX(r)),i>=2&&t.setY(a,n.getY(r)),i>=3&&t.setZ(a,n.getZ(r)),i>=4&&t.setW(a,n.getW(r))}}else{const i=t.array,r=i.constructor,s=i.BYTES_PER_ELEMENT*n.itemSize*e;new r(i.buffer,s,n.array.length).set(n.array)}}function Lu(n,t,e){const i=n.elements,r=t.elements;for(let s=0,a=r.length;s<a;s++)i[s]+=r[s]*e}function lo(n,t,e){const i=n.skeleton,r=n.geometry,s=i.bones,a=i.boneInverses;oo.fromBufferAttribute(r.attributes.skinIndex,t),ao.fromBufferAttribute(r.attributes.skinWeight,t),Cr.elements.fill(0);for(let o=0;o<4;o++){const c=ao.getComponent(o);if(c!==0){const l=oo.getComponent(o);co.multiplyMatrices(s[l].matrixWorld,a[l]),Lu(Cr,co,c)}}return Cr.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),e.transformDirection(Cr),e}function Cn(n,t,e,i,r){Mr.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=t[s],c=n[s];o!==0&&(Mn.fromBufferAttribute(c,i),e?Mr.addScaledVector(Mn,o):Mr.addScaledVector(Mn.sub(r),o))}r.add(Mr)}function Vu(n,t={useGroups:!1,updateIndex:!1,skipAttributes:[]},e=new M.BufferGeometry){const i=n[0].index!==null,{useGroups:r=!1,updateIndex:s=!1,skipAttributes:a=[]}=t,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;e.clearGroups();for(let u=0;u<n.length;++u){const h=n[u];let f=0;if(i!==(h.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const d in h.attributes){if(!o.has(d))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.');c[d]===void 0&&(c[d]=[]),c[d].push(h.attributes[d]),f++}if(f!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(r){let d;if(i)d=h.index.count;else if(h.attributes.position!==void 0)d=h.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");e.addGroup(l,d,u),l+=d}}if(i){let u=!1;if(!e.index){let h=0;for(let f=0;f<n.length;++f)h+=n[f].index.count;e.setIndex(new M.BufferAttribute(new Uint32Array(h),1,!1)),u=!0}if(s||u){const h=e.index;let f=0,d=0;for(let y=0;y<n.length;++y){const _=n[y],p=_.index;if(a[y]!==!0)for(let m=0;m<p.count;++m)h.setX(f,p.getX(m)+d),f++;d+=_.attributes.position.count}}}for(const u in c){const h=c[u];if(!(u in e.attributes)){let y=0;for(const _ in h)y+=h[_].count;e.setAttribute(u,di(c[u][0],y))}const f=e.attributes[u];let d=0;for(let y=0,_=h.length;y<_;y++){const p=h[y];a[y]!==!0&&ya(p,f,d),d+=p.count}}return e}function Ju(n,t){if(n===null||t===null)return n===t;if(n.length!==t.length)return!1;for(let e=0,i=n.length;e<i;e++)if(n[e]!==t[e])return!1;return!0}function Gu(n){const{index:t,attributes:e}=n;if(t)for(let i=0,r=t.count;i<r;i+=3){const s=t.getX(i),a=t.getX(i+2);t.setX(i,a),t.setX(i+2,s)}else for(const i in e){const r=e[i],s=r.itemSize;for(let a=0,o=r.count;a<o;a+=3)for(let c=0;c<s;c++){const l=r.getComponent(a,c),u=r.getComponent(a+2,c);r.setComponent(a,c,u),r.setComponent(a+2,c,l)}}return n}class ju{constructor(t){this.matrixWorld=new M.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=t,this.update()}update(){const t=this.mesh,e=t.geometry,i=t.skeleton,r=(e.index?e.index.count:e.attributes.position.count)/3;if(this.matrixWorld.copy(t.matrixWorld),this.geometryHash=e.attributes.position.version,this.primitiveCount=r,i){i.boneTexture||i.computeBoneTexture(),i.update();const s=i.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const t=this.mesh,e=t.geometry,i=(e.index?e.index.count:e.attributes.position.count)/3;return!(this.matrixWorld.equals(t.matrixWorld)&&this.geometryHash===e.attributes.position.version&&Ju(t.skeleton&&t.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class $u{constructor(t){Array.isArray(t)||(t=[t]);const e=[];t.forEach(i=>{i.traverseVisible(r=>{r.isMesh&&e.push(r)})}),this.meshes=e,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(e.length).fill().map(()=>new M.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const t=[];return this.meshes.forEach(e=>{Array.isArray(e.material)?t.push(...e.material):t.push(e.material)}),t}generate(t=new M.BufferGeometry){let e=[];const{meshes:i,useGroups:r,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=i.length;o<c;o++){const l=i[o],u=s[o],h=a.get(l);!h||h.didChange(l)?(this._convertToStaticGeometry(l,u),e.push(!1),h?h.update():a.set(l,new ju(l))):e.push(!0)}if(s.length===0){t.setIndex(null);const o=t.attributes;for(const c in o)t.deleteAttribute(c);for(const c in this.attributes)t.setAttribute(this.attributes[c],new M.BufferAttribute(new Float32Array(0),4,!1))}else Vu(s,{useGroups:r,skipAttributes:e},t);for(const o in t.attributes)t.attributes[o].needsUpdate=!0;return t}_convertToStaticGeometry(t,e=new M.BufferGeometry){const i=t.geometry,r=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=i.attributes,c=e.attributes;!e.index&&i.index&&(e.index=i.index.clone()),c.position||e.setAttribute("position",di(o.position)),s&&!c.normal&&o.normal&&e.setAttribute("normal",di(o.normal)),a&&!c.tangent&&o.tangent&&e.setAttribute("tangent",di(o.tangent)),ci(i.index,e.index),ci(o.position,c.position),s&&ci(o.normal,c.normal),a&&ci(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,h=a?o.tangent:null,f=i.morphAttributes.position,d=i.morphAttributes.normal,y=i.morphAttributes.tangent,_=i.morphTargetsRelative,p=t.morphTargetInfluences,m=new M.Matrix3;m.getNormalMatrix(t.matrixWorld),i.index&&e.index.array.set(i.index.array);for(let g=0,v=o.position.count;g<v;g++)Me.fromBufferAttribute(l,g),u&&Ce.fromBufferAttribute(u,g),h&&(so.fromBufferAttribute(h,g),Pe.fromBufferAttribute(h,g)),p&&(f&&Cn(f,p,_,g,Me),d&&Cn(d,p,_,g,Ce),y&&Cn(y,p,_,g,Pe)),t.isSkinnedMesh&&(t.applyBoneTransform(g,Me),u&&lo(t,g,Ce),h&&lo(t,g,Pe)),r&&Me.applyMatrix4(t.matrixWorld),c.position.setXYZ(g,Me.x,Me.y,Me.z),u&&(r&&Ce.applyNormalMatrix(m),c.normal.setXYZ(g,Ce.x,Ce.y,Ce.z)),h&&(r&&Pe.transformDirection(t.matrixWorld),c.tangent.setXYZW(g,Pe.x,Pe.y,Pe.z,so.w));for(const g in this.attributes){const v=this.attributes[g];v==="position"||v==="tangent"||v==="normal"||!(v in o)||(c[v]||e.setAttribute(v,di(o[v])),ci(o[v],c[v]),ya(o[v],c[v]))}return t.matrixWorld.determinant()<0&&Gu(e),e}}const qu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:la,CENTER:rs,CONTAINED:Fn,ExtendedTriangle:Rt,MeshBVH:Ki,OrientedBox:dt,SAH:ua,StaticGeometryGenerator:$u,acceleratedRaycast:Uu,computeBoundsTree:Du},Symbol.toStringTag,{value:"Module"}));class Xu{constructor(t){this.name="WorkerBase",this.running=!1,this.worker=t,this.worker.onerror=e=>{throw e.message?new Error(`${this.name}: Could not create Web Worker with error "${e.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...t){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const e=this.runTask(this.worker,...t);return e.finally(()=>{this.running=!1}),e}dispose(){this.worker.terminate(),this.worker=null}}exports.$70d766613f57b014$export$2e2bcd8739ae039=Ko;exports.BatchedParticleRenderer=Pl;exports.Builder=Wn;exports.ByteBuffer=gi;exports.ConstantColor=Re;exports.ConstantValue=F;exports.Matrix4=Ft;exports.MeshBVH=Ki;exports.MotionController=Ta;exports.ParticleSystem=Dr;exports.SIZE_PREFIX_LENGTH=ho;exports.TrailParticle=Nr;exports.Vector4=bt;exports.WorkerBase=Xu;exports.bundler=ec;exports.createNoise4D=El;exports.fetchProfile=va;exports.index=zl;exports.index$1=qu;exports.md5=gc;exports.v5=fc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "4.8.0-next.9de3f45",
3
+ "version": "4.8.0-next.c98d4ee",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
5
5
  "main": "dist/needle-engine.min.js",
6
6
  "exports": {
@@ -93,7 +93,7 @@
93
93
  ],
94
94
  "dependencies": {
95
95
  "@dimforge/rapier3d-compat": "^0.14.0",
96
- "@needle-tools/gltf-progressive": "3.1.1-next.1039397",
96
+ "@needle-tools/gltf-progressive": "3.1.1-next.fd37564",
97
97
  "@webxr-input-profiles/motion-controllers": "^1.0.0",
98
98
  "flatbuffers": "2.0.4",
99
99
  "md5": "^2.3.0",
@@ -138,7 +138,7 @@
138
138
  "madge": "^5.0.1",
139
139
  "npm-watch": "^0.11.0",
140
140
  "typescript": "^4.5.5",
141
- "vite": "6.3.5",
141
+ "vite": "7",
142
142
  "vite-plugin-dts": "^4.5.0"
143
143
  },
144
144
  "peerDependencies": {
@@ -27,32 +27,41 @@ export const needleDependencies = (command, config, userSettings) => {
27
27
  }
28
28
  }
29
29
 
30
+ const excludeDependencies = [
31
+ "three-mesh-bvh",
32
+ "@needle-tools/gltf-progressive"
33
+ ]
34
+
30
35
  /**
31
36
  * @param {import('vite').UserConfig} config
32
37
  */
33
38
  function handleOptimizeDeps(config) {
34
- if (config.optimizeDeps?.include?.includes("three-mesh-bvh")) {
35
- console.log("[needle-dependencies] three-mesh-bvh is included in the optimizeDeps.include array. This may cause issues with the worker import.");
36
- }
37
- else {
38
- if (!config.optimizeDeps) {
39
- config.optimizeDeps = {};
39
+ excludeDependencies.forEach(dep => {
40
+ if (config.optimizeDeps?.include?.includes(dep)) {
41
+ console.log(`[needle-dependencies] ${dep} is included in the optimizeDeps.include array. This may cause issues with the worker import.`);
40
42
  }
41
- if (!config.optimizeDeps.exclude) {
42
- config.optimizeDeps.exclude = [];
43
- }
44
- console.log("[needle-dependencies] Adding three-mesh-bvh to the optimizeDeps.exclude array.");
45
- // This needs to be excluded from optimization because otherwise the worker import fails
46
- // three-mesh-bvh/src/workers/generateMeshBVH.worker.js?worker
47
- config.optimizeDeps.exclude.push("three-mesh-bvh");
43
+ else {
44
+ if (!config.optimizeDeps) {
45
+ config.optimizeDeps = {};
46
+ }
47
+ if (!config.optimizeDeps.exclude) {
48
+ config.optimizeDeps.exclude = [];
49
+ }
48
50
 
49
- if (!config.server) config.server = {};
50
- if (!config.server.fs) config.server.fs = {};
51
- if (config.server.fs.strict === undefined) {
52
- // we need to disable strictness to allow importing the worker from three-mesh-bvh node_modules in our GenerateMeshBVHWorker.js file
53
- config.server.fs.strict = false;
51
+ // This needs to be excluded from optimization because otherwise the worker import fails
52
+ // three-mesh-bvh/src/workers/generateMeshBVH.worker.js?worker
53
+ // same for gltf-progressive
54
+ console.log(`[needle-dependencies] Adding ${dep} to the optimizeDeps.exclude array to support workers.`);
55
+ config.optimizeDeps.exclude.push(dep);
56
+
57
+ if (!config.server) config.server = {};
58
+ if (!config.server.fs) config.server.fs = {};
59
+ if (config.server.fs.strict === undefined) {
60
+ // we need to disable strictness to allow importing the worker from three-mesh-bvh node_modules in our GenerateMeshBVHWorker.js file
61
+ config.server.fs.strict = false;
62
+ }
54
63
  }
55
- }
64
+ });
56
65
  }
57
66
 
58
67
  /**
@@ -1,8 +0,0 @@
1
- var rt=Object.defineProperty,$e=r=>{throw TypeError(r)},st=(r,e,t)=>e in r?rt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,c=(r,e,t)=>st(r,typeof e!="symbol"?e+"":e,t),Re=(r,e,t)=>e.has(r)||$e("Cannot "+t),b=(r,e,t)=>(Re(r,e,"read from private field"),t?t.call(r):e.get(r)),J=(r,e,t)=>e.has(r)?$e("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),U=(r,e,t,n)=>(Re(r,e,"write to private field"),n?n.call(r,t):e.set(r,t),t);import{BufferGeometry as oe,Mesh as Z,Box3 as be,Vector3 as G,Sphere as Ge,CompressedTexture as nt,Texture as ee,Matrix3 as ot,InterleavedBuffer as it,InterleavedBufferAttribute as at,BufferAttribute as lt,TextureLoader as ut,Matrix4 as je,Clock as dt,MeshStandardMaterial as ct}from"./three-DuDKwKB8.min.js";import{DRACOLoader as ht,KTX2Loader as gt,MeshoptDecoder as ft,GLTFLoader as Me}from"./three-examples-BMOhDaYR.min.js";const Ne="3.1.1";globalThis.GLTF_PROGRESSIVE_VERSION=Ne,console.debug(`[gltf-progressive] version ${Ne}`);let j="https://www.gstatic.com/draco/versioned/decoders/1.5.7/",te="https://www.gstatic.com/basis-universal/versioned/2021-04-15-ba1c3e4/";const mt=j,pt=te,We=new URL(j+"draco_decoder.js");We.searchParams.append("range","true"),fetch(We,{method:"GET",headers:{Range:"bytes=0-1"}}).catch(r=>{console.debug(`Failed to fetch remote Draco decoder from ${j} (offline: ${typeof navigator<"u"?navigator.onLine:"unknown"})`),j===mt&&Fe("./include/draco/"),te===pt&&Ue("./include/ktx2/")}).finally(()=>{ze()});const vt=()=>({dracoDecoderPath:j,ktx2TranscoderPath:te});function Fe(r){j=r,$&&$[Oe]!=j?(console.debug("Updating Draco decoder path to "+r),$[Oe]=j,$.setDecoderPath(j),$.preload()):console.debug("Setting Draco decoder path to "+r)}function Ue(r){te=r,N&&N.transcoderPath!=te?(console.debug("Updating KTX2 transcoder path to "+r),N.setTranscoderPath(te),N.init()):console.debug("Setting KTX2 transcoder path to "+r)}function ge(r){return ze(),r?N.detectSupport(r):r!==null&&console.warn("No renderer provided to detect ktx2 support - loading KTX2 textures might fail"),{dracoLoader:$,ktx2Loader:N,meshoptDecoder:fe}}function De(r){r.dracoLoader||r.setDRACOLoader($),r.ktx2Loader||r.setKTX2Loader(N),r.meshoptDecoder||r.setMeshoptDecoder(fe)}const Oe=Symbol("dracoDecoderPath");let $,fe,N;function ze(){$||($=new ht,$[Oe]=j,$.setDecoderPath(j),$.setDecoderConfig({type:"js"}),$.preload()),N||(N=new gt,N.setTranscoderPath(te),N.init()),fe||(fe=ft)}const Se=new WeakMap;function Pe(r,e){let t=Se.get(r);t?t=Object.assign(t,e):t=e,Se.set(r,t)}const qe=Me.prototype.load;function xt(...r){const e=Se.get(this);let t=r[0];const n=new URL(t,window.location.href);if(n.hostname.endsWith("needle.tools")){const s=e?.progressive!==void 0?e.progressive:!0,i=e!=null&&e.usecase?e.usecase:"default";s?this.requestHeader.Accept=`*/*;progressive=allowed;usecase=${i}`:this.requestHeader.Accept=`*/*;usecase=${i}`,t=n.toString()}return r[0]=t,qe?.call(this,...r)}Me.prototype.load=xt,re("debugprogressive");function re(r){if(typeof window>"u")return!1;const e=new URL(window.location.href).searchParams.get(r);return e==null||e==="0"||e==="false"?!1:e===""?!0:e}function yt(r,e){if(e===void 0||e.startsWith("./")||e.startsWith("http")||r===void 0)return e;const t=r.lastIndexOf("/");if(t>=0){const n=r.substring(0,t+1);for(;n.endsWith("/")&&e.startsWith("/");)e=e.substring(1);return n+e}return e}let me;function Ve(){return me!==void 0||(me=/iPhone|iPad|iPod|Android|IEMobile/i.test(navigator.userAgent),re("debugprogressive")&&console.log("[glTF Progressive]: isMobileDevice",me)),me}function Xe(){if(typeof window>"u")return!1;const r=new URL(window.location.href),e=r.hostname==="localhost"||/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(r.hostname);return r.hostname==="127.0.0.1"||e}class wt{constructor(e=100,t={}){c(this,"maxConcurrent"),c(this,"_running",new Map),c(this,"_queue",[]),c(this,"debug",!1),c(this,"tick",()=>{this.internalUpdate(),setTimeout(this.tick,10)}),this.maxConcurrent=e,this.debug=t.debug??!1,window.requestAnimationFrame(this.tick)}slot(e){return this.debug&&console.debug(`[PromiseQueue]: Requesting slot for key ${e}, running: ${this._running.size}, waiting: ${this._queue.length}`),new Promise(t=>{this._queue.push({key:e,resolve:t})})}add(e,t){this._running.has(e)||(this._running.set(e,t),t.finally(()=>{this._running.delete(e),this.debug&&console.debug(`[PromiseQueue]: Promise finished now running: ${this._running.size}, waiting: ${this._queue.length}. (finished ${e})`)}),this.debug&&console.debug(`[PromiseQueue]: Added new promise, now running: ${this._running.size}, waiting: ${this._queue.length}. (added ${e})`))}internalUpdate(){const e=this.maxConcurrent-this._running.size;for(let t=0;t<e&&this._queue.length>0;t++){this.debug&&console.debug(`[PromiseQueue]: Running ${this._running.size} promises, waiting for ${this._queue.length} more.`);const{key:n,resolve:s}=this._queue.shift();s({use:i=>this.add(n,i)})}}}const Lt=typeof window>"u"&&typeof document>"u",Te=Symbol("needle:raycast-mesh");function ne(r){return r?.[Te]instanceof oe?r[Te]:null}function _t(r,e){if((r.type==="Mesh"||r.type==="SkinnedMesh")&&!ne(r)){const t=Mt(e);t.userData={isRaycastMesh:!0},r[Te]=t}}function bt(r=!0){if(r){if(ie)return;const e=ie=Z.prototype.raycast;Z.prototype.raycast=function(t,n){const s=this,i=ne(s);let o;i&&s.isMesh&&(o=s.geometry,s.geometry=i),e.call(this,t,n),o&&(s.geometry=o)}}else{if(!ie)return;Z.prototype.raycast=ie,ie=null}}let ie=null;function Mt(r){const e=new oe;for(const t in r.attributes)e.setAttribute(t,r.getAttribute(t));return e.setIndex(r.getIndex()),e}const X=new Array,w=re("debugprogressive");let pe,se=-1;if(w){let r=function(){se+=1,se>=e&&(se=-1),console.log(`Toggle LOD level [${se}]`)},e=6;window.addEventListener("keyup",t=>{t.key==="p"&&r(),t.key==="w"&&(pe=!pe,console.log(`Toggle wireframe [${pe}]`));const n=parseInt(t.key);!isNaN(n)&&n>=0&&(se=n,console.log(`Set LOD level to [${se}]`))})}function He(r){if(w)if(Array.isArray(r))for(const e of r)He(e);else r&&"wireframe"in r&&(r.wireframe=pe===!0)}const ae=new Array;let Dt=0;const Ot=Ve()?2:10;function St(r){if(ae.length<Ot){const t=ae.length;w&&console.warn(`[Worker] Creating new worker #${t}`);const n=Be.createWorker(r||{});return ae.push(n),n}const e=Dt++%ae.length;return ae[e]}class Be{constructor(e,t){c(this,"worker"),c(this,"_running",[]),c(this,"_webglRenderer",null),c(this,"_debug",!1),this.worker=e,this._debug=t.debug??!1,e.onmessage=n=>{const s=n.data;switch(this._debug&&console.log("[Worker] EVENT",s),s.type){case"loaded-gltf":for(const i of this._running)if(i.url===s.result.url){Pt(s.result),i.resolve(s.result);const o=i.url;o.startsWith("blob:")&&URL.revokeObjectURL(o)}}},e.onerror=n=>{console.error("[Worker] Error in gltf-progressive worker:",n)},e.postMessage({type:"init"})}static async createWorker(e){const t=new Worker(new URL("/loader.worker-qHzhYKEC.js",import.meta.url),{type:"module"});return new Be(t,e)}async load(e,t){const n=vt();let s=t?.renderer;s||(this._webglRenderer??(this._webglRenderer=(async()=>{const{WebGLRenderer:a}=await import("./three-DuDKwKB8.min.js").then(u=>u.THREE);return new a})()),s=await this._webglRenderer);const i=ge(s).ktx2Loader.workerConfig;e instanceof URL?e=e.toString():e.startsWith("file:")?e=URL.createObjectURL(new Blob([e])):!e.startsWith("blob:")&&!e.startsWith("http:")&&!e.startsWith("https:")&&(e=new URL(e,window.location.href).toString());const o={type:"load",url:e,dracoDecoderPath:n.dracoDecoderPath,ktx2TranscoderPath:n.ktx2TranscoderPath,ktx2LoaderConfig:i};return this._debug&&console.debug("[Worker] Sending load request",o),this.worker.postMessage(o),new Promise(a=>{this._running.push({url:e.toString(),resolve:a})})}}function Pt(r){var e,t,n,s,i,o,a,u,d,h,v,x,y,O,I,M;for(const S of r.geometries){const l=S.geometry,f=new oe;if(f.name=l.name||"",l.index){const L=l.index;f.setIndex(Ae(L))}for(const L in l.attributes){const P=l.attributes[L],D=Ae(P);f.setAttribute(L,D)}if(l.morphAttributes)for(const L in l.morphAttributes){const P=l.morphAttributes[L].map(D=>Ae(D));f.morphAttributes[L]=P}if(f.morphTargetsRelative=l.morphTargetsRelative??!1,f.boundingBox=new be,f.boundingBox.min=new G((e=l.boundingBox)==null?void 0:e.min.x,(t=l.boundingBox)==null?void 0:t.min.y,(n=l.boundingBox)==null?void 0:n.min.z),f.boundingBox.max=new G((s=l.boundingBox)==null?void 0:s.max.x,(i=l.boundingBox)==null?void 0:i.max.y,(o=l.boundingBox)==null?void 0:o.max.z),f.boundingSphere=new Ge(new G((a=l.boundingSphere)==null?void 0:a.center.x,(u=l.boundingSphere)==null?void 0:u.center.y,(d=l.boundingSphere)==null?void 0:d.center.z),(h=l.boundingSphere)==null?void 0:h.radius),l.groups)for(const L of l.groups)f.addGroup(L.start,L.count,L.materialIndex);l.userData&&(f.userData=l.userData),S.geometry=f}for(const S of r.textures){const l=S.texture;let f=null;if(l.isCompressedTexture){const L=l.mipmaps,P=((v=l.image)==null?void 0:v.width)||((y=(x=l.source)==null?void 0:x.data)==null?void 0:y.width)||-1,D=((O=l.image)==null?void 0:O.height)||((M=(I=l.source)==null?void 0:I.data)==null?void 0:M.height)||-1;f=new nt(L,P,D,l.format,l.type,l.mapping,l.wrapS,l.wrapT,l.magFilter,l.minFilter,l.anisotropy,l.colorSpace)}else f=new ee(l.image,l.mapping,l.wrapS,l.wrapT,l.magFilter,l.minFilter,l.format,l.type,l.anisotropy,l.colorSpace),f.mipmaps=l.mipmaps,f.channel=l.channel,f.source.data=l.source.data,f.flipY=l.flipY,f.premultiplyAlpha=l.premultiplyAlpha,f.unpackAlignment=l.unpackAlignment,f.matrix=new ot(...l.matrix.elements);if(!f){console.error("[Worker] Failed to create new texture from received data. Texture is not a CompressedTexture or Texture.");continue}S.texture=f}return r}function Ae(r){let e=r;if("isInterleavedBufferAttribute"in r&&r.isInterleavedBufferAttribute){const t=r.data,n=t.array,s=new it(n,t.stride);e=new at(s,r.itemSize,n.byteOffset,r.normalized),e.offset=r.offset}else"isBufferAttribute"in r&&r.isBufferAttribute&&(e=new lt(r.array,r.itemSize,r.normalized),e.usage=r.usage,e.gpuType=r.gpuType,e.updateRanges=r.updateRanges);return e}const Tt=re("gltf-progressive-worker"),At=re("gltf-progressive-reduce-mipmaps"),ke=Symbol("needle-progressive-texture"),z="NEEDLE_progressive",A=class R{constructor(e,t){c(this,"parser"),c(this,"url"),c(this,"_isLoadingMesh"),c(this,"loadMesh",n=>{var s,i;if(this._isLoadingMesh)return null;const o=(i=(s=this.parser.json.meshes[n])==null?void 0:s.extensions)==null?void 0:i[z];return o?(this._isLoadingMesh=!0,this.parser.getDependency("mesh",n).then(a=>{var u;return this._isLoadingMesh=!1,a&&R.registerMesh(this.url,o.guid,a,(u=o.lods)==null?void 0:u.length,0,o),a})):null}),w&&console.log("Progressive extension registered for",t),this.parser=e,this.url=t}get name(){return z}static getMeshLODExtension(e){const t=this.getAssignedLODInformation(e);return t!=null&&t.key?this.lodInfos.get(t.key):null}static getPrimitiveIndex(e){var t;return((t=this.getAssignedLODInformation(e))==null?void 0:t.index)??-1}static getMaterialMinMaxLODsCount(e,t){const n=this,s="LODS:minmax",i=e[s];if(i!=null)return i;if(t||(t={min_count:1/0,max_count:0,lods:[]}),Array.isArray(e)){for(const a of e)this.getMaterialMinMaxLODsCount(a,t);return e[s]=t,t}if(w==="verbose"&&console.log("getMaterialMinMaxLODsCount",e),e.type==="ShaderMaterial"||e.type==="RawShaderMaterial"){const a=e;for(const u of Object.keys(a.uniforms)){const d=a.uniforms[u].value;d?.isTexture===!0&&o(d,t)}}else if(e.isMaterial)for(const a of Object.keys(e)){const u=e[a];u?.isTexture===!0&&o(u,t)}else w&&console.warn(`[getMaterialMinMaxLODsCount] Unsupported material type: ${e.type}`);return e[s]=t,t;function o(a,u){const d=n.getAssignedLODInformation(a);if(d){const h=n.lodInfos.get(d.key);if(h&&h.lods){u.min_count=Math.min(u.min_count,h.lods.length),u.max_count=Math.max(u.max_count,h.lods.length);for(let v=0;v<h.lods.length;v++){const x=h.lods[v];x.width&&(u.lods[v]=u.lods[v]||{min_height:1/0,max_height:0},u.lods[v].min_height=Math.min(u.lods[v].min_height,x.height),u.lods[v].max_height=Math.max(u.lods[v].max_height,x.height))}}}}}static hasLODLevelAvailable(e,t){var n;if(Array.isArray(e)){for(const o of e)if(this.hasLODLevelAvailable(o,t))return!0;return!1}if(e.isMaterial===!0){for(const o of Object.keys(e)){const a=e[o];if(a&&a.isTexture&&this.hasLODLevelAvailable(a,t))return!0}return!1}else if(e.isGroup===!0){for(const o of e.children)if(o.isMesh===!0&&this.hasLODLevelAvailable(o,t))return!0}let s,i;if(e.isMesh?s=e.geometry:(e.isBufferGeometry||e.isTexture)&&(s=e),s&&(n=s?.userData)!=null&&n.LODS){const o=s.userData.LODS;if(i=this.lodInfos.get(o.key),t===void 0)return i!=null;if(i)return Array.isArray(i.lods)?t<i.lods.length:t===0}return!1}static assignMeshLOD(e,t){var n;if(!e)return Promise.resolve(null);if(e instanceof Z||e.isMesh===!0){const s=e.geometry,i=this.getAssignedLODInformation(s);if(!i)return Promise.resolve(null);for(const o of X)(n=o.onBeforeGetLODMesh)==null||n.call(o,e,t);return e["LOD:requested level"]=t,R.getOrLoadLOD(s,t).then(o=>{if(Array.isArray(o)){const a=i.index||0;o=o[a]}return e["LOD:requested level"]===t&&(delete e["LOD:requested level"],o&&s!=o&&(o?.isBufferGeometry?e.geometry=o:w&&console.error("Invalid LOD geometry",o))),o}).catch(o=>(console.error("Error loading mesh LOD",e,o),null))}else w&&console.error("Invalid call to assignMeshLOD: Request mesh LOD but the object is not a mesh",e);return Promise.resolve(null)}static assignTextureLOD(e,t=0){if(!e)return Promise.resolve(null);if(e.isMesh===!0){const n=e;if(Array.isArray(n.material)){const s=new Array;for(const i of n.material){const o=this.assignTextureLOD(i,t);s.push(o)}return Promise.all(s).then(i=>{const o=new Array;for(const a of i)Array.isArray(a)&&o.push(...a);return o})}else return this.assignTextureLOD(n.material,t)}if(e.isMaterial===!0){const n=e,s=[],i=new Array;if(n.uniforms&&(n.isRawShaderMaterial||n.isShaderMaterial===!0)){const o=n;for(const a of Object.keys(o.uniforms)){const u=o.uniforms[a].value;if(u?.isTexture===!0){const d=this.assignTextureLODForSlot(u,t,n,a).then(h=>(h&&o.uniforms[a].value!=h&&(o.uniforms[a].value=h,o.uniformsNeedUpdate=!0),h));s.push(d),i.push(a)}}}else for(const o of Object.keys(n)){const a=n[o];if(a?.isTexture===!0){const u=this.assignTextureLODForSlot(a,t,n,o);s.push(u),i.push(o)}}return Promise.all(s).then(o=>{const a=new Array;for(let u=0;u<o.length;u++){const d=o[u],h=i[u];d&&d.isTexture===!0?a.push({material:n,slot:h,texture:d,level:t}):a.push({material:n,slot:h,texture:null,level:t})}return a})}if(e instanceof ee||e.isTexture===!0){const n=e;return this.assignTextureLODForSlot(n,t,null,null)}return Promise.resolve(null)}static assignTextureLODForSlot(e,t,n,s){return e?.isTexture!==!0?Promise.resolve(null):s==="glyphMap"?Promise.resolve(e):R.getOrLoadLOD(e,t).then(i=>{var o,a;if(Array.isArray(i))return console.warn("Progressive: Got an array of textures for a texture slot, this should not happen..."),null;if(i?.isTexture===!0){if(i!=e&&n&&s){const u=n[s];if(u&&!w){const d=this.getAssignedLODInformation(u);if(d&&d?.level<t)return w==="verbose"&&console.warn("Assigned texture level is already higher: ",d.level,t,n,u,i),null}if(At&&i.mipmaps){const d=i.mipmaps.length;i.mipmaps.length=Math.min(i.mipmaps.length,3),d!==i.mipmaps.length&&w&&console.debug(`Reduced mipmap count from ${d} to ${i.mipmaps.length} for ${i.uuid}: ${(o=i.image)==null?void 0:o.width}x${(a=i.image)==null?void 0:a.height}.`)}n[s]=i}return i}else w=="verbose"&&console.warn("No LOD found for",e,t);return null}).catch(i=>(console.error("Error loading LOD",e,i),null))}afterRoot(e){var t,n;return w&&console.log("AFTER",this.url,e),(t=this.parser.json.textures)==null||t.forEach((s,i)=>{var o;if(s!=null&&s.extensions){const a=s?.extensions[z];if(a){if(!a.lods){w&&console.warn("Texture has no LODs",a);return}let u=!1;for(const d of this.parser.associations.keys())if(d.isTexture===!0){const h=this.parser.associations.get(d);h?.textures===i&&(u=!0,R.registerTexture(this.url,d,(o=a.lods)==null?void 0:o.length,i,a))}u||this.parser.getDependency("texture",i).then(d=>{var h;d&&R.registerTexture(this.url,d,(h=a.lods)==null?void 0:h.length,i,a)})}}}),(n=this.parser.json.meshes)==null||n.forEach((s,i)=>{if(s!=null&&s.extensions){const o=s?.extensions[z];if(o&&o.lods){for(const a of this.parser.associations.keys())if(a.isMesh){const u=this.parser.associations.get(a);u?.meshes===i&&R.registerMesh(this.url,o.guid,a,o.lods.length,u.primitives,o)}}}}),null}static async getOrLoadLOD(e,t){var n,s,i,o;const a=w=="verbose",u=this.getAssignedLODInformation(e);if(!u)return w&&console.warn(`[gltf-progressive] No LOD information found: ${e.name}, uuid: ${e.uuid}, type: ${e.type}`,e),null;const d=u?.key;let h;if(e.isTexture===!0){const v=e;v.source&&v.source[ke]&&(h=v.source[ke])}if(h||(h=R.lodInfos.get(d)),h){if(t>0){let y=!1;const O=Array.isArray(h.lods);if(O&&t>=h.lods.length?y=!0:O||(y=!0),y)return this.lowresCache.get(d)}const v=Array.isArray(h.lods)?(n=h.lods[t])==null?void 0:n.path:h.lods;if(!v)return w&&!h["missing:uri"]&&(h["missing:uri"]=!0,console.warn("Missing uri for progressive asset for LOD "+t,h)),null;const x=yt(u.url,v);if(x.endsWith(".glb")||x.endsWith(".gltf")){if(!h.guid)return console.warn("missing pointer for glb/gltf texture",h),null;const y=x+"_"+h.guid,O=await this.queue.slot(x),I=this.previouslyLoaded.get(y);if(I!==void 0){a&&console.log(`LOD ${t} was already loading/loaded: ${y}`);let l=await I.catch(L=>(console.error(`Error loading LOD ${t} from ${x}
2
- `,L),null)),f=!1;if(l==null||(l instanceof ee&&e instanceof ee?(s=l.image)!=null&&s.data||(i=l.source)!=null&&i.data?l=this.copySettings(e,l):(f=!0,this.previouslyLoaded.delete(y)):l instanceof oe&&e instanceof oe&&((o=l.attributes.position)!=null&&o.array||(f=!0,this.previouslyLoaded.delete(y)))),!f)return l}if(!O.use)return w&&console.log(`LOD ${t} was aborted: ${x}`),null;const M=h,S=new Promise(async(l,f)=>{if(Tt){const m=await(await St({})).load(x);if(m.textures.length>0)for(const g of m.textures){let p=g.texture;return R.assignLODInformation(u.url,p,d,t,void 0),e instanceof ee&&(p=this.copySettings(e,p)),p&&(p.guid=M.guid),l(p)}if(m.geometries.length>0){const g=new Array;for(const p of m.geometries){const T=p.geometry;R.assignLODInformation(u.url,T,d,t,p.primitiveIndex),g.push(T)}return l(g)}return l(null)}const L=new Me;De(L),w&&(await new Promise(m=>setTimeout(m,1e3)),a&&console.warn("Start loading (delayed) "+x,M.guid));let P=x;if(M&&Array.isArray(M.lods)){const m=M.lods[t];m.hash&&(P+="?v="+m.hash)}const D=await L.loadAsync(P).catch(m=>(console.error(`Error loading LOD ${t} from ${x}
3
- `,m),l(null)));if(!D)return l(null);const F=D.parser;a&&console.log("Loading finished "+x,M.guid);let k=0;if(D.parser.json.textures){let m=!1;for(const g of D.parser.json.textures){if(g!=null&&g.extensions){const p=g?.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){m=!0;break}}k++}if(m){let g=await F.getDependency("texture",k);return g&&R.assignLODInformation(u.url,g,d,t,void 0),a&&console.log('change "'+e.name+'" \u2192 "'+g.name+'"',x,k,g,y),e instanceof ee&&(g=this.copySettings(e,g)),g&&(g.guid=M.guid),l(g)}else w&&console.warn("Could not find texture with guid",M.guid,D.parser.json)}if(k=0,D.parser.json.meshes){let m=!1;for(const g of D.parser.json.meshes){if(g!=null&&g.extensions){const p=g?.extensions[z];if(p!=null&&p.guid&&p.guid===M.guid){m=!0;break}}k++}if(m){const g=await F.getDependency("mesh",k);if(a&&console.log(`Loaded Mesh "${g.name}"`,x,k,g,y),g.isMesh===!0){const p=g.geometry;return R.assignLODInformation(u.url,p,d,t,0),l(p)}else{const p=new Array;for(let T=0;T<g.children.length;T++){const B=g.children[T];if(B.isMesh===!0){const V=B.geometry;R.assignLODInformation(u.url,V,d,t,T),p.push(V)}}return l(p)}}else w&&console.warn("Could not find mesh with guid",M.guid,D.parser.json)}return l(null)});return this.previouslyLoaded.set(y,S),O.use(S),await S}else if(e instanceof ee){a&&console.log("Load texture from uri: "+x);const y=await new ut().loadAsync(x);return y?(y.guid=h.guid,y.flipY=!1,y.needsUpdate=!0,y.colorSpace=e.colorSpace,a&&console.log(h,y)):w&&console.warn("failed loading",x),y}}else w&&console.warn(`Can not load LOD ${t}: no LOD info found for "${d}" ${e.name}`,e.type);return null}static assignLODInformation(e,t,n,s,i){if(!t)return;t.userData||(t.userData={});const o=new kt(e,n,s,i);t.userData.LODS=o,"source"in t&&typeof t.source=="object"&&(t.source.LODS=o)}static getAssignedLODInformation(e){var t,n;return e?(t=e.userData)!=null&&t.LODS?e.userData.LODS:"source"in e&&(n=e.source)!=null&&n.LODS?e.source.LODS:null:null}static copySettings(e,t){return t?(w==="verbose"&&console.debug(`Copy texture settings
4
- `,e.uuid,`
5
- `,t.uuid),t=t.clone(),t.offset=e.offset,t.repeat=e.repeat,t.colorSpace=e.colorSpace,t.magFilter=e.magFilter,t.minFilter=e.minFilter,t.wrapS=e.wrapS,t.wrapT=e.wrapT,t.flipY=e.flipY,t.anisotropy=e.anisotropy,t.mipmaps||(t.generateMipmaps=e.generateMipmaps),t):e}};c(A,"registerTexture",(r,e,t,n,s)=>{var i,o,a,u,d,h,v,x;if(!e){w&&console.error("gltf-progressive: Called register texture without texture");return}if(w){const O=((i=e.image)==null?void 0:i.width)||((a=(o=e.source)==null?void 0:o.data)==null?void 0:a.width)||0,I=((u=e.image)==null?void 0:u.height)||((h=(d=e.source)==null?void 0:d.data)==null?void 0:h.height)||0;console.log(`> Progressive: register texture[${n}] "${e.name||e.uuid}", Current: ${O}x${I}, Max: ${(v=s.lods[0])==null?void 0:v.width}x${(x=s.lods[0])==null?void 0:x.height}, uuid: ${e.uuid}`,s,e)}e.source&&(e.source[ke]=s);const y=s.guid;A.assignLODInformation(r,e,y,t,n),A.lodInfos.set(y,s),A.lowresCache.set(y,e)}),c(A,"registerMesh",(r,e,t,n,s,i)=>{var o;const a=t.geometry;if(!a){w&&console.warn("gltf-progressive: Register mesh without geometry");return}a.userData||(a.userData={}),w&&console.log("> Progressive: register mesh "+t.name,{index:s,uuid:t.uuid},i,t),A.assignLODInformation(r,a,e,n,s),A.lodInfos.set(e,i);let u=A.lowresCache.get(e);u?u.push(t.geometry):u=[t.geometry],A.lowresCache.set(e,u),n>0&&!ne(t)&&_t(t,a);for(const d of X)(o=d.onRegisteredNewMesh)==null||o.call(d,t,i)}),c(A,"lodInfos",new Map),c(A,"previouslyLoaded",new Map),c(A,"lowresCache",new Map),c(A,"workers",[]),c(A,"_workersIndex",0),c(A,"maxConcurrent",50),c(A,"queue",new wt(A.maxConcurrent,{debug:w!=!1}));let q=A;class kt{constructor(e,t,n,s){c(this,"url"),c(this,"key"),c(this,"level"),c(this,"index"),this.url=e,this.key=t,this.level=n,s!=null&&(this.index=s)}}class ve{constructor(e,t){c(this,"frame_start"),c(this,"frame_capture_end"),c(this,"ready"),c(this,"_resolve"),c(this,"_signal"),c(this,"_resolved",!1),c(this,"_addedCount",0),c(this,"_resolvedCount",0),c(this,"_awaiting",[]),c(this,"_maxPromisesPerObject",1),c(this,"_currentFrame",0),c(this,"_seen",new WeakMap);var n;const s=Math.max(t.frames??2,2);this.frame_start=e,this.frame_capture_end=e+s,this.ready=new Promise(i=>{this._resolve=i}),this.ready.finally(()=>{this._resolved=!0,this._awaiting.length=0}),this._signal=t.signal,(n=this._signal)==null||n.addEventListener("abort",()=>{this.resolveNow()}),this._maxPromisesPerObject=Math.max(1,t.maxPromisesPerObject??1)}get awaitedCount(){return this._addedCount}get resolvedCount(){return this._resolvedCount}get currentlyAwaiting(){return this._awaiting.length}update(e){var t;this._currentFrame=e,((t=this._signal)!=null&&t.aborted||this._currentFrame>this.frame_capture_end&&this._awaiting.length===0)&&this.resolveNow()}add(e,t,n){if(this._resolved){w&&console.warn("PromiseGroup: Trying to add a promise to a resolved group, ignoring.");return}if(!(this._currentFrame>this.frame_capture_end)){if(this._maxPromisesPerObject>=1)if(this._seen.has(t)){let s=this._seen.get(t);if(s>=this._maxPromisesPerObject){w&&console.warn("PromiseGroup: Already awaiting object ignoring new promise for it.");return}this._seen.set(t,s+1)}else this._seen.set(t,1);this._awaiting.push(n),this._addedCount++,n.finally(()=>{this._resolvedCount++,this._awaiting.splice(this._awaiting.indexOf(n),1)})}}resolveNow(){var e,t;this._resolved||(t=this._resolve)==null||t.call(this,{awaited_count:this._addedCount,resolved_count:this._resolvedCount,cancelled:((e=this._signal)==null?void 0:e.aborted)??!1})}}c(ve,"addPromise",(r,e,t,n)=>{n.forEach(s=>{s.add(r,e,t)})});const W=re("debugprogressive"),It=re("noprogressive"),Ie=Symbol("Needle:LODSManager"),Ee=Symbol("Needle:LODState"),H=Symbol("Needle:CurrentLOD"),E={mesh_lod:-1,texture_lod:-1};var _,C,K,Ce,Y,le,xe,Q;let ue=(_=class{constructor(r,e){c(this,"renderer"),c(this,"context"),c(this,"projectionScreenMatrix",new je),c(this,"targetTriangleDensity",2e5),c(this,"skinnedMeshAutoUpdateBoundsInterval",30),c(this,"updateInterval","auto"),J(this,C,1),c(this,"pause",!1),c(this,"manual",!1),c(this,"_newPromiseGroups",[]),c(this,"_promiseGroupIds",0),c(this,"_lodchangedlisteners",[]),J(this,K),J(this,Ce,new dt),J(this,Y,0),J(this,le,0),J(this,xe,0),J(this,Q,0),c(this,"_fpsBuffer",[60,60,60,60,60]),c(this,"_sphere",new Ge),c(this,"_tempBox",new be),c(this,"_tempBox2",new be),c(this,"tempMatrix",new je),c(this,"_tempWorldPosition",new G),c(this,"_tempBoxSize",new G),c(this,"_tempBox2Size",new G),this.renderer=r,this.context={...e}}static getObjectLODState(r){return r[Ee]}static addPlugin(r){X.push(r)}static removePlugin(r){const e=X.indexOf(r);e>=0&&X.splice(e,1)}static get(r,e){if(r[Ie])return console.debug("[gltf-progressive] LODsManager already exists for this renderer"),r[Ie];const t=new _(r,{engine:"unknown",...e});return r[Ie]=t,t}get plugins(){return X}awaitLoading(r){const e=this._promiseGroupIds++,t=new ve(b(this,Y),{...r});this._newPromiseGroups.push(t);const n=performance.now();return t.ready.finally(()=>{const s=this._newPromiseGroups.indexOf(t);s>=0&&(this._newPromiseGroups.splice(s,1),Xe()&&performance.measure("LODsManager:awaitLoading",{start:n,detail:{id:e,name:r?.name,awaited:t.awaitedCount,resolved:t.resolvedCount}}))}),t.ready}_postprocessPromiseGroups(){if(this._newPromiseGroups.length!==0)for(let r=this._newPromiseGroups.length-1;r>=0;r--)this._newPromiseGroups[r].update(b(this,Y))}addEventListener(r,e){r==="changed"&&this._lodchangedlisteners.push(e)}removeEventListener(r,e){if(r==="changed"){const t=this._lodchangedlisteners.indexOf(e);t>=0&&this._lodchangedlisteners.splice(t,1)}}enable(){if(b(this,K))return;console.debug("[gltf-progressive] Enabling LODsManager for renderer");let r=0;U(this,K,this.renderer.render);const e=this;ge(this.renderer),this.renderer.render=function(t,n){const s=e.renderer.getRenderTarget();(s==null||"isXRRenderTarget"in s&&s.isXRRenderTarget)&&(r=0,U(e,Y,b(e,Y)+1),U(e,le,b(e,Ce).getDelta()),U(e,xe,b(e,xe)+b(e,le)),e._fpsBuffer.shift(),e._fpsBuffer.push(1/b(e,le)),U(e,Q,e._fpsBuffer.reduce((o,a)=>o+a)/e._fpsBuffer.length),W&&b(e,Y)%200===0&&console.log("FPS",Math.round(b(e,Q)),"Interval:",b(e,C)));const i=r++;b(e,K).call(this,t,n),e.onAfterRender(t,n,i)}}disable(){b(this,K)&&(console.debug("[gltf-progressive] Disabling LODsManager for renderer"),this.renderer.render=b(this,K),U(this,K,void 0))}update(r,e){this.internalUpdate(r,e)}onAfterRender(r,e,t){if(this.pause)return;const n=this.renderer.renderLists.get(r,0).opaque;let s=!0;if(n.length===1){const i=n[0].material;(i.name==="EffectMaterial"||i.name==="CopyShader")&&(s=!1)}if((e.parent&&e.parent.type==="CubeCamera"||t>=1&&e.type==="OrthographicCamera")&&(s=!1),s){if(It||(this.updateInterval==="auto"?b(this,Q)<40&&b(this,C)<10?(U(this,C,b(this,C)+1),W&&console.warn("\u2193 Reducing LOD updates",b(this,C),b(this,Q).toFixed(0))):b(this,Q)>=60&&b(this,C)>1&&(U(this,C,b(this,C)-1),W&&console.warn("\u2191 Increasing LOD updates",b(this,C),b(this,Q).toFixed(0))):U(this,C,this.updateInterval),b(this,C)>0&&b(this,Y)%b(this,C)!=0))return;this.internalUpdate(r,e),this._postprocessPromiseGroups()}}internalUpdate(r,e){var t,n;const s=this.renderer.renderLists.get(r,0),i=s.opaque;this.projectionScreenMatrix.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse);const o=this.targetTriangleDensity;for(const d of i){if(d.material&&(((t=d.geometry)==null?void 0:t.type)==="BoxGeometry"||((n=d.geometry)==null?void 0:n.type)==="BufferGeometry")&&(d.material.name==="SphericalGaussianBlur"||d.material.name=="BackgroundCubeMaterial"||d.material.name==="CubemapFromEquirect"||d.material.name==="EquirectangularToCubeUV")){W&&(d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]||(d.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]=!0,console.warn("Ignoring skybox or BLIT object",d,d.material.name,d.material.type)));continue}switch(d.material.type){case"LineBasicMaterial":case"LineDashedMaterial":case"PointsMaterial":case"ShadowMaterial":case"MeshDistanceMaterial":case"MeshDepthMaterial":continue}if(W==="color"&&d.material&&!d.object.progressive_debug_color){d.object.progressive_debug_color=!0;const v=Math.random()*16777215,x=new ct({color:v});d.object.material=x}const h=d.object;(h instanceof Z||h.isMesh)&&this.updateLODs(r,e,h,o)}const a=s.transparent;for(const d of a){const h=d.object;(h instanceof Z||h.isMesh)&&this.updateLODs(r,e,h,o)}const u=s.transmissive;for(const d of u){const h=d.object;(h instanceof Z||h.isMesh)&&this.updateLODs(r,e,h,o)}}updateLODs(r,e,t,n){var s,i;t.userData||(t.userData={});let o=t[Ee];if(o||(o=new Et,t[Ee]=o),o.frames++<2)return;for(const u of X)(s=u.onBeforeUpdateLOD)==null||s.call(u,this.renderer,r,e,t);const a=_.overrideGlobalLodLevel!==void 0?_.overrideGlobalLodLevel:se;a>=0?(E.mesh_lod=a,E.texture_lod=a):(this.calculateLodLevel(e,t,o,n,E),E.mesh_lod=Math.round(E.mesh_lod),E.texture_lod=Math.round(E.texture_lod)),E.mesh_lod>=0&&this.loadProgressiveMeshes(t,E.mesh_lod),t.material&&E.texture_lod>=0&&this.loadProgressiveTextures(t.material,E.texture_lod,a),w&&t.material&&!t.isGizmo&&He(t.material);for(const u of X)(i=u.onAfterUpdatedLOD)==null||i.call(u,this.renderer,r,e,t,E);o.lastLodLevel_Mesh=E.mesh_lod,o.lastLodLevel_Texture=E.texture_lod}loadProgressiveTextures(r,e,t){if(!r)return;if(Array.isArray(r)){for(const s of r)this.loadProgressiveTextures(s,e);return}let n=!1;if((r[H]===void 0||e<r[H])&&(n=!0),t!==void 0&&t>=0&&(n=r[H]!=t,e=t),n){r[H]=e;const s=q.assignTextureLOD(r,e).then(i=>{this._lodchangedlisteners.forEach(o=>o({type:"texture",level:e,object:r}))});ve.addPromise("texture",r,s,this._newPromiseGroups)}}loadProgressiveMeshes(r,e){if(!r)return Promise.resolve(null);let t=r[H]!==e;const n=r["DEBUG:LOD"];if(n!=null&&(t=r[H]!=n,e=n),t){r[H]=e;const s=r.geometry,i=q.assignMeshLOD(r,e).then(o=>(o&&r[H]==e&&s!=r.geometry&&this._lodchangedlisteners.forEach(a=>a({type:"mesh",level:e,object:r})),o));return ve.addPromise("mesh",r,i,this._newPromiseGroups),i}return Promise.resolve(null)}static isInside(r,e){const t=r.min,n=r.max,s=(t.x+n.x)*.5,i=(t.y+n.y)*.5;return this._tempPtInside.set(s,i,t.z).applyMatrix4(e).z<0}calculateLodLevel(r,e,t,n,s){var i,o,a,u;if(!e){s.mesh_lod=-1,s.texture_lod=-1;return}if(!r){s.mesh_lod=-1,s.texture_lod=-1;return}let d=10+1,h=!1;if(W&&e["DEBUG:LOD"]!=null)return e["DEBUG:LOD"];const v=(i=q.getMeshLODExtension(e.geometry))==null?void 0:i.lods,x=q.getPrimitiveIndex(e.geometry),y=v&&v.length>0,O=q.getMaterialMinMaxLODsCount(e.material),I=O.min_count!==1/0&&O.min_count>=0&&O.max_count>=0;if(!y&&!I){s.mesh_lod=0,s.texture_lod=0;return}y||(h=!0,d=0);const M=this.renderer.domElement.clientHeight||this.renderer.domElement.height;let S=e.geometry.boundingBox;if(e.type==="SkinnedMesh"){const l=e;if(!l.boundingBox)l.computeBoundingBox();else if(this.skinnedMeshAutoUpdateBoundsInterval>0){if(!l[_.$skinnedMeshBoundsOffset]){const L=_.skinnedMeshBoundsFrameOffsetCounter++;l[_.$skinnedMeshBoundsOffset]=L}const f=l[_.$skinnedMeshBoundsOffset];if((t.frames+f)%this.skinnedMeshAutoUpdateBoundsInterval===0){const L=ne(l),P=l.geometry;L&&(l.geometry=L),l.computeBoundingBox(),l.geometry=P}}S=l.boundingBox}if(S){const l=r;if(e.geometry.attributes.color&&e.geometry.attributes.color.count<100&&e.geometry.boundingSphere){this._sphere.copy(e.geometry.boundingSphere),this._sphere.applyMatrix4(e.matrixWorld);const m=r.getWorldPosition(this._tempWorldPosition);if(this._sphere.containsPoint(m)){s.mesh_lod=0,s.texture_lod=0;return}}if(this._tempBox.copy(S),this._tempBox.applyMatrix4(e.matrixWorld),l.isPerspectiveCamera&&_.isInside(this._tempBox,this.projectionScreenMatrix)){s.mesh_lod=0,s.texture_lod=0;return}if(this._tempBox.applyMatrix4(this.projectionScreenMatrix),this.renderer.xr.enabled&&l.isPerspectiveCamera&&l.fov>70){const m=this._tempBox.min,g=this._tempBox.max;let p=m.x,T=m.y,B=g.x,V=g.y;const de=2,Le=1.5,ce=(m.x+g.x)*.5,he=(m.y+g.y)*.5;p=(p-ce)*de+ce,T=(T-he)*de+he,B=(B-ce)*de+ce,V=(V-he)*de+he;const et=p<0&&B>0?0:Math.min(Math.abs(m.x),Math.abs(g.x)),tt=T<0&&V>0?0:Math.min(Math.abs(m.y),Math.abs(g.y)),_e=Math.max(et,tt);t.lastCentrality=(Le-_e)*(Le-_e)*(Le-_e)}else t.lastCentrality=1;const f=this._tempBox.getSize(this._tempBoxSize);f.multiplyScalar(.5),screen.availHeight>0&&M>0&&f.multiplyScalar(M/screen.availHeight),r.isPerspectiveCamera?f.x*=r.aspect:r.isOrthographicCamera;const L=r.matrixWorldInverse,P=this._tempBox2;P.copy(S),P.applyMatrix4(e.matrixWorld),P.applyMatrix4(L);const D=P.getSize(this._tempBox2Size),F=Math.max(D.x,D.y);if(Math.max(f.x,f.y)!=0&&F!=0&&(f.z=D.z/Math.max(D.x,D.y)*Math.max(f.x,f.y)),t.lastScreenCoverage=Math.max(f.x,f.y,f.z),t.lastScreenspaceVolume.copy(f),t.lastScreenCoverage*=t.lastCentrality,W&&_.debugDrawLine){const m=this.tempMatrix.copy(this.projectionScreenMatrix);m.invert();const g=_.corner0,p=_.corner1,T=_.corner2,B=_.corner3;g.copy(this._tempBox.min),p.copy(this._tempBox.max),p.x=g.x,T.copy(this._tempBox.max),T.y=g.y,B.copy(this._tempBox.max);const V=(g.z+B.z)*.5;g.z=p.z=T.z=B.z=V,g.applyMatrix4(m),p.applyMatrix4(m),T.applyMatrix4(m),B.applyMatrix4(m),_.debugDrawLine(g,p,255),_.debugDrawLine(g,T,255),_.debugDrawLine(p,B,255),_.debugDrawLine(T,B,255)}let k=999;if(v&&t.lastScreenCoverage>0)for(let m=0;m<v.length;m++){const g=v[m],p=(((o=g.densities)==null?void 0:o[x])||g.density||1e-5)/t.lastScreenCoverage;if(x>0&&Xe()&&!g.densities&&!globalThis["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]&&(window["NEEDLE:MISSING_LOD_PRIMITIVE_DENSITIES"]=!0,console.warn("[Needle Progressive] Detected usage of mesh without primitive densities. This might cause incorrect LOD level selection: Consider re-optimizing your model by updating your Needle Integration, Needle glTF Pipeline or running optimization again on Needle Cloud.")),p<n){k=m;break}}k<d&&(d=k,h=!0)}if(h?s.mesh_lod=d:s.mesh_lod=t.lastLodLevel_Mesh,W&&s.mesh_lod!=t.lastLodLevel_Mesh){const l=v?.[s.mesh_lod];l&&console.debug(`Mesh LOD changed: ${t.lastLodLevel_Mesh} \u2192 ${s.mesh_lod} (density: ${(a=l.densities)==null?void 0:a[x].toFixed(0)}) | ${e.name}`)}if(I){const l="saveData"in globalThis.navigator&&globalThis.navigator.saveData===!0;if(t.lastLodLevel_Texture<0){if(s.texture_lod=O.max_count-1,W){const f=O.lods[O.max_count-1];W&&console.log(`First Texture LOD ${s.texture_lod} (${f.max_height}px) - ${e.name}`)}}else{const f=t.lastScreenspaceVolume.x+t.lastScreenspaceVolume.y+t.lastScreenspaceVolume.z;let L=t.lastScreenCoverage*4;((u=this.context)==null?void 0:u.engine)==="model-viewer"&&(L*=1.5);const P=M/window.devicePixelRatio*L;let D=!1;for(let F=O.lods.length-1;F>=0;F--){const k=O.lods[F];if(!(l&&k.max_height>=2048)&&!(Ve()&&k.max_height>4096)&&(k.max_height>P||!D&&F===0)){if(D=!0,s.texture_lod=F,W&&s.texture_lod<t.lastLodLevel_Texture){const m=k.max_height;console.log(`Texture LOD changed: ${t.lastLodLevel_Texture} \u2192 ${s.texture_lod} = ${m}px
6
- Screensize: ${P.toFixed(0)}px, Coverage: ${(100*t.lastScreenCoverage).toFixed(2)}%, Volume ${f.toFixed(1)}
7
- ${e.name}`)}break}}}}else s.texture_lod=0}},C=new WeakMap,K=new WeakMap,Ce=new WeakMap,Y=new WeakMap,le=new WeakMap,xe=new WeakMap,Q=new WeakMap,c(_,"debugDrawLine"),c(_,"overrideGlobalLodLevel"),c(_,"corner0",new G),c(_,"corner1",new G),c(_,"corner2",new G),c(_,"corner3",new G),c(_,"_tempPtInside",new G),c(_,"skinnedMeshBoundsFrameOffsetCounter",0),c(_,"$skinnedMeshBoundsOffset",Symbol("gltf-progressive-skinnedMeshBoundsOffset")),_);class Et{constructor(){c(this,"frames",0),c(this,"lastLodLevel_Mesh",-1),c(this,"lastLodLevel_Texture",-1),c(this,"lastScreenCoverage",0),c(this,"lastScreenspaceVolume",new G),c(this,"lastCentrality",0)}}const Ke=Symbol("NEEDLE_mesh_lod"),ye=Symbol("NEEDLE_texture_lod");let we=null;function Ye(){const r=Ct();r&&(r.mapURLs(function(e){return Qe(),e}),Qe(),we?.disconnect(),we=new MutationObserver(e=>{e.forEach(t=>{t.addedNodes.forEach(n=>{n instanceof HTMLElement&&n.tagName.toLowerCase()==="model-viewer"&&Ze(n)})})}),we.observe(document,{childList:!0,subtree:!0}))}function Ct(){return typeof customElements>"u"?null:customElements.get("model-viewer")||(customElements.whenDefined("model-viewer").then(()=>{console.debug("[gltf-progressive] model-viewer defined"),Ye()}),null)}function Qe(){typeof document>"u"||document.querySelectorAll("model-viewer").forEach(r=>{Ze(r)})}const Je=new WeakSet;let Bt=0;function Ze(r){if(!r||Je.has(r))return null;Je.add(r),console.debug("[gltf-progressive] found new model-viewer..."+ ++Bt+`
8
- `,r.getAttribute("src"));let e=null,t=null,n=null;for(let s=r;s!=null;s=Object.getPrototypeOf(s)){const i=Object.getOwnPropertySymbols(s),o=i.find(d=>d.toString()=="Symbol(renderer)"),a=i.find(d=>d.toString()=="Symbol(scene)"),u=i.find(d=>d.toString()=="Symbol(needsRender)");!e&&o!=null&&(e=r[o].threeRenderer),!t&&a!=null&&(t=r[a]),!n&&u!=null&&(n=r[u])}if(e&&t){let s=function(){if(n){let o=0,a=setInterval(()=>{if(o++>5){clearInterval(a);return}n?.call(r)},300)}};console.debug("[gltf-progressive] setup model-viewer");const i=ue.get(e,{engine:"model-viewer"});return ue.addPlugin(new $t),i.enable(),i.addEventListener("changed",()=>{n?.call(r)}),r.addEventListener("model-visibility",o=>{o.detail.visible&&n?.call(r)}),r.addEventListener("load",()=>{s()}),()=>{i.disable()}}return null}class $t{constructor(){c(this,"_didWarnAboutMissingUrl",!1)}onBeforeUpdateLOD(e,t,n,s){this.tryParseMeshLOD(t,s),this.tryParseTextureLOD(t,s)}getUrl(e){if(!e)return null;let t=e.getAttribute("src");return t||(t=e.src),t||(this._didWarnAboutMissingUrl||console.warn("No url found in modelviewer",e),this._didWarnAboutMissingUrl=!0),t}tryGetCurrentGLTF(e){return e._currentGLTF}tryGetCurrentModelViewer(e){return e.element}tryParseTextureLOD(e,t){if(t[ye]==!0)return;t[ye]=!0;const n=this.tryGetCurrentGLTF(e),s=this.tryGetCurrentModelViewer(e),i=this.getUrl(s);if(i&&n&&t.material){let o=function(u){var d,h,v;if(u[ye]==!0)return;u[ye]=!0,u.userData&&(u.userData.LOD=-1);const x=Object.keys(u);for(let y=0;y<x.length;y++){const O=x[y],I=u[O];if(I?.isTexture===!0){const M=(h=(d=I.userData)==null?void 0:d.associations)==null?void 0:h.textures;if(M==null)continue;const S=n.parser.json.textures[M];if(!S){console.warn("Texture data not found for texture index "+M);continue}if((v=S?.extensions)!=null&&v[z]){const l=S.extensions[z];l&&i&&q.registerTexture(i,I,l.lods.length,M,l)}}}};const a=t.material;if(Array.isArray(a))for(const u of a)o(u);else o(a)}}tryParseMeshLOD(e,t){var n,s;if(t[Ke]==!0)return;t[Ke]=!0;const i=this.tryGetCurrentModelViewer(e),o=this.getUrl(i);if(!o)return;const a=(s=(n=t.userData)==null?void 0:n.gltfExtensions)==null?void 0:s[z];if(a&&o){const u=t.uuid;q.registerMesh(o,u,t,0,a.lods.length,a)}}}function Rt(r,e,t,n){ge(e),De(t),Pe(t,{progressive:!0,...n?.hints}),t.register(i=>new q(i,r));const s=ue.get(e);return n?.enableLODsManager!==!1&&s.enable(),s}if(Ye(),!Lt){const r={gltfProgressive:{useNeedleProgressive:Rt,LODsManager:ue,configureLoader:Pe,getRaycastMesh:ne,useRaycastMeshes:bt}};if(!globalThis.Needle)globalThis.Needle=r;else for(const e in r)globalThis.Needle[e]=r[e]}export{ue as LODsManager,q as NEEDLE_progressive,De as addDracoAndKTX2Loaders,Pe as configureLoader,ge as createLoaders,ne as getRaycastMesh,Fe as setDracoDecoderLocation,Ue as setKTX2TranscoderLocation};