@needle-tools/engine 4.9.1 → 4.9.3-next.002c20b
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.
- package/CHANGELOG.md +4 -0
- package/dist/{needle-engine.bundle-O7rlGMn7.js → needle-engine.bundle-BR5JPeY6.js} +1991 -1946
- package/dist/{needle-engine.bundle-BuTUhZAc.umd.cjs → needle-engine.bundle-BcceMKjs.umd.cjs} +120 -98
- package/dist/{needle-engine.bundle-DoywABnJ.min.js → needle-engine.bundle-D3RtScQB.min.js} +128 -106
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-B_FzkwDz.min.js → postprocessing-BZOSD1ln.min.js} +53 -53
- package/dist/{postprocessing-DTX5VXrj.umd.cjs → postprocessing-Bb5StX0o.umd.cjs} +76 -76
- package/dist/{postprocessing-DP1U_BpT.js → postprocessing-BzFF7i-7.js} +212 -190
- package/dist/{vendor-8le8g4MS.umd.cjs → vendor-BtJpSuCj.umd.cjs} +1 -1
- package/dist/{vendor-yDFiCnCw.min.js → vendor-XJ9xiwrv.min.js} +1 -1
- package/dist/{vendor-Msb9AgYE.js → vendor-k9i6CeGi.js} +871 -870
- package/lib/engine/webcomponents/needle-engine.loading.js +59 -23
- package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.d.ts +1 -0
- package/lib/engine/xr/NeedleXRSession.js +25 -11
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/Animation.js +1 -1
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/Renderer.js +12 -5
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/SpriteRenderer.js +4 -1
- package/lib/engine-components/SpriteRenderer.js.map +1 -1
- package/package.json +3 -3
- package/plugins/vite/alias.js +5 -3
- package/plugins/vite/poster-client.js +22 -21
- package/src/engine/webcomponents/needle-engine.loading.ts +63 -24
- package/src/engine/xr/NeedleXRSession.ts +25 -10
- package/src/engine-components/Animation.ts +1 -1
- package/src/engine-components/Renderer.ts +12 -5
- package/src/engine-components/SpriteRenderer.ts +3 -1
|
@@ -1118,4 +1118,4 @@ void main() {
|
|
|
1118
1118
|
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
1119
1119
|
|
|
1120
1120
|
#include <fog_vertex>
|
|
1121
|
-
}`;class El extends la{constructor(e){super(e),this.vector_=new B,this.vector2_=new B,this.vector3_=new B,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(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new jt(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Dn(this.settings.material.map.channel),e.map=new M.Uniform$1(this.settings.material.map),e.mapTransform=new M.Uniform$1(new He().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new M.ShaderMaterial({uniforms:e,defines:t,vertexShader:wl,fragmentShader:Pl,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 e=0,t=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),v=_.previous.values();let g=v.next(),b=g.value,x=b;g.done||(g=v.next());let S;g.value!==void 0?S=g.value:S=x;for(let T=0;T<_.previous.length;T++,e+=2){if(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z),r.worldSpace?(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+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(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.previousBuffer.setXYZ(e,b.position.x,b.position.y,b.position.z),this.previousBuffer.setXYZ(e+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.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.nextBuffer.setXYZ(e,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+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.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,-1),this.sideBuffer.setX(e+1,1),r.worldSpace)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else if(_.parentMatrix)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else{const w=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,x.size*w),this.widthBuffer.setX(e+1,x.size*w)}this.uvBuffer.setXY(e,(T/_.previous.length+p)*f,(h-m-1)*d),this.uvBuffer.setXY(e+1,(T/_.previous.length+p)*f,(h-m)*d),this.colorBuffer.setXYZW(e,x.color.x,x.color.y,x.color.z,x.color.w),this.colorBuffer.setXYZW(e+1,x.color.x,x.color.y,x.color.z,x.color.w),T+1<_.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),b=x,x=S,g.done||(g=v.next(),g.value!==void 0&&(S=g.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class Ki{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new M.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const r=e.getIndex().array,s=r.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),r[a*3],r[a*3+1],r[a*3+2]),i+=t.getArea(),this._triangleIndexToArea.push(i);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new M.Vector3,this._tempB=new M.Vector3,this._tempC=new M.Vector3,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.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=t.getIndex().array[r*3],u=t.getIndex().array[r*3+1],h=t.getIndex().array[r*3+2],f=t.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),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new Ki(t.geometries[e.geometry])}clone(){return new Ki(this._geometry)}update(e,t){}}sl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Ki,loadJSON:Ki.fromJSON}],behaviors:[]});class ns extends M.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let r=0;r<this.batches.length;r++)if(ns.equals(this.batches[r].settings,t)){this.batches[r].addSystem(e),this.systemToBatchIndex.set(e,r);return}let i;switch(t.renderMode){case exports.RenderMode.Trail:i=new El(t);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new Cl(t);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(e),this.batches.push(i),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(i)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,i)=>{i.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const Rl=ns;pl();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const ua=Math.sqrt(5),kl=(ua-1)/4,ae=(5-ua)/20,lr=n=>Math.floor(n)|0,ur=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 Al(n=Math.random){const e=zl(n),t=new Float64Array(e).map(a=>ur[a%32*4]),i=new Float64Array(e).map(a=>ur[a%32*4+1]),r=new Float64Array(e).map(a=>ur[a%32*4+2]),s=new Float64Array(e).map(a=>ur[a%32*4+3]);return function(o,c,l,u){let h,f,d,y,_;const p=(o+c+l+u)*kl,m=lr(o+p),v=lr(c+p),g=lr(l+p),b=lr(u+p),x=(m+v+g+b)*ae,S=m-x,T=v-x,w=g-x,P=b-x,C=o-S,R=c-T,E=l-w,k=u-P;let A=0,z=0,N=0,L=0;C>R?A++:z++,C>E?A++:N++,C>k?A++:L++,R>E?z++:N++,R>k?z++:L++,E>k?N++:L++;const I=A>=3?1:0,X=z>=3?1:0,Z=N>=3?1:0,ie=L>=3?1:0,Q=A>=2?1:0,pe=z>=2?1:0,me=N>=2?1:0,re=L>=2?1:0,H=A>=1?1:0,j=z>=1?1:0,Ye=N>=1?1:0,Le=L>=1?1:0,Ve=C-I+ae,Je=R-X+ae,ve=E-Z+ae,Ae=k-ie+ae,_e=C-Q+2*ae,Ze=R-pe+2*ae,Ke=E-me+2*ae,W=k-re+2*ae,Ge=C-H+3*ae,Qe=R-j+3*ae,_t=E-Ye+3*ae,et=k-Le+3*ae,tt=C-1+4*ae,it=R-1+4*ae,rt=E-1+4*ae,nt=k-1+4*ae,ze=m&255,Oe=v&255,Be=g&255,Ie=b&255;let V=.6-C*C-R*R-E*E-k*k;if(V<0)h=0;else{const q=ze+e[Oe+e[Be+e[Ie]]];V*=V,h=V*V*(t[q]*C+i[q]*R+r[q]*E+s[q]*k)}let Yt=.6-Ve*Ve-Je*Je-ve*ve-Ae*Ae;if(Yt<0)f=0;else{const q=ze+I+e[Oe+X+e[Be+Z+e[Ie+ie]]];Yt*=Yt,f=Yt*Yt*(t[q]*Ve+i[q]*Je+r[q]*ve+s[q]*Ae)}let Zt=.6-_e*_e-Ze*Ze-Ke*Ke-W*W;if(Zt<0)d=0;else{const q=ze+Q+e[Oe+pe+e[Be+me+e[Ie+re]]];Zt*=Zt,d=Zt*Zt*(t[q]*_e+i[q]*Ze+r[q]*Ke+s[q]*W)}let Kt=.6-Ge*Ge-Qe*Qe-_t*_t-et*et;if(Kt<0)y=0;else{const q=ze+H+e[Oe+j+e[Be+Ye+e[Ie+Le]]];Kt*=Kt,y=Kt*Kt*(t[q]*Ge+i[q]*Qe+r[q]*_t+s[q]*et)}let Qt=.6-tt*tt-it*it-rt*rt-nt*nt;if(Qt<0)_=0;else{const q=ze+1+e[Oe+1+e[Be+1+e[Ie+1]]];Qt*=Qt,_=Qt*Qt*(t[q]*tt+i[q]*it+r[q]*rt+s[q]*nt)}return 27*(h+f+d+y+_)}}function zl(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const r=i+~~(n()*(256-i)),s=t[i];t[i]=t[r],t[r]=s}for(let i=256;i<512;i++)t[i]=t[i-256];return t}class Ol{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,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 ha{constructor(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v;this._closedByUser=!1,this.handleOpenEvent=g=>this.handleEvent(G.open,g),this.handleErrorEvent=g=>this.handleEvent(G.error,g),this.handleCloseEvent=g=>this.handleEvent(G.close,g),this.handleMessageEvent=g=>this.handleEvent(G.message,g),this._url=e,this._protocols=t,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:[...(v=(m=i?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&v!==void 0?v:[]]}},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(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,i){this._options.listeners[e].push({listener:t,options:i})}removeEventListener(e,t,i){const r=s=>s.listener!==t||s.options!==i;this._options.listeners[e]=this._options.listeners[e].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(e,t){const i=this._options.listeners[e],r=[];i.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&r.push({listener:s,options:a})}),this._options.listeners[e]=r}handleEvent(e,t){switch(e){case G.close:this.dispatchEvent(e,t),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(e,t),this.sendBufferedData();break;case G.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=i=>{const r=new CustomEvent(G.retry,{detail:i});this.handleEvent(G.retry,r)},t={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||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class Bl{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(G.open,e,t),this}onClose(e,t){return this.addListener(G.close,e,t),this}onError(e,t){return this.addListener(G.error,e,t),this}onMessage(e,t){return this.addListener(G.message,e,t),this}onRetry(e,t){return this.addListener(G.retry,e,t),this}onReconnect(e,t){return this.addListener(G.reconnect,e,t),this}build(){return new ha(this._url,this._protocols,this._options)}addListener(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v,g,b,x,S,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:(v=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.retry)!==null&&v!==void 0?v:[],reconnect:(x=(b=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||b===void 0?void 0:b.reconnect)!==null&&x!==void 0?x:[],[e]:[...(w=(T=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||T===void 0?void 0:T[e])!==null&&w!==void 0?w:[],{listener:t,options:i}]}}),this}}const Il=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Ol,Websocket:ha,WebsocketBuilder:Bl,get WebsocketEvent(){return G}},Symbol.toStringTag,{value:"Module"})),ss=0,fa=1,da=2,Ln=2,mn=1.25,Xs=1,gi=32,Xr=65535,Nl=Math.pow(2,-24),yn=Symbol("SKIP_GENERATION");function Ul(n){return n.index?n.index.count:n.attributes.position.count}function Wt(n){return Ul(n)/3}function Fl(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Dl(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Fl(t,i);n.setIndex(new M.BufferAttribute(r,1));for(let s=0;s<t;s++)r[s]=s}}function pa(n,e){const t=Wt(n),i=e||n.drawRange,r=i.start/3,s=(i.start+i.count)/3,a=Math.max(0,r),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function ma(n,e){if(!n.groups||!n.groups.length)return pa(n,e);const t=[],i=new Set,r=e||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];t.push({offset:Math.floor(l),count:Math.floor(u-l)})}return t}function Ll(n,e){const t=Wt(n),i=ma(n,e).sort((a,o)=>a.offset-o.offset),r=i[i.length-1];r.count=Math.min(t-r.offset,r.count);let s=0;return i.forEach(({count:a})=>s+=a),t!==s}function gn(n,e,t,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=e*6,v=(e+t)*6;m<v;m+=6){const g=n[m+0],b=n[m+1],x=g-b,S=g+b;x<s&&(s=x),S>c&&(c=S),g<h&&(h=g),g>y&&(y=g);const T=n[m+2],w=n[m+3],P=T-w,C=T+w;P<a&&(a=P),C>l&&(l=C),T<f&&(f=T),T>_&&(_=T);const R=n[m+4],E=n[m+5],k=R-E,A=R+E;k<o&&(o=k),A>u&&(u=A),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 Vl(n,e=null,t=null,i=null){const r=n.attributes.position,s=n.index?n.index.array:null,a=Wt(n),o=r.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,i=a):(c=e,t=t||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=t;d<t+i;d++){const y=d*3,_=d*6;let p=y+0,m=y+1,v=y+2;s&&(p=s[p],m=s[m],v=s[v]),o||(p=p*h+u,m=m*h+u,v=v*h+u);for(let g=0;g<3;g++){let b,x,S;o?(b=r[f[g]](p),x=r[f[g]](m),S=r[f[g]](v)):(b=l[p+g],x=l[m+g],S=l[v+g]);let T=b;x<T&&(T=x),S<T&&(T=S);let w=b;x>w&&(w=x),S>w&&(w=S);const P=(w-T)/2,C=g*2;c[_+C+0]=T+P,c[_+C+1]=P+(Math.abs(T)+P)*Nl}}return c}function Y(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function Hs(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const r=n[i+3]-n[i];r>t&&(t=r,e=i)}return e}function Ws(n,e){e.set(n)}function Ys(n,e,t){let i,r;for(let s=0;s<3;s++){const a=s+3;i=n[s],r=e[s],t[s]=i<r?i:r,i=n[a],r=e[a],t[a]=i>r?i:r}}function hr(n,e,t){for(let i=0;i<3;i++){const r=e[n+2*i],s=e[n+2*i+1],a=r-s,o=r+s;a<t[i]&&(t[i]=a),o>t[i+3]&&(t[i+3]=o)}}function ri(n){const e=n[3]-n[0],t=n[4]-n[1],i=n[5]-n[2];return 2*(e*t+t*i+i*e)}const st=32,Jl=(n,e)=>n.candidate-e.candidate,dt=new Array(st).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),fr=new Float32Array(6);function Gl(n,e,t,i,r,s){let a=-1,o=0;if(s===ss)a=Hs(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===fa)a=Hs(n),a!==-1&&(o=jl(t,i,r,a));else if(s===da){const c=ri(n);let l=mn*r;const u=i*6,h=(i+r)*6;for(let f=0;f<3;f++){const d=e[f],p=(e[f+3]-d)/st;if(r<st/4){const m=[...dt];m.length=r;let v=0;for(let b=u;b<h;b+=6,v++){const x=m[v];x.candidate=t[b+2*f],x.count=0;const{bounds:S,leftCacheBounds:T,rightCacheBounds:w}=x;for(let P=0;P<3;P++)w[P]=1/0,w[P+3]=-1/0,T[P]=1/0,T[P+3]=-1/0,S[P]=1/0,S[P+3]=-1/0;hr(b,t,S)}m.sort(Jl);let g=r;for(let b=0;b<g;b++){const x=m[b];for(;b+1<g&&m[b+1].candidate===x.candidate;)m.splice(b+1,1),g--}for(let b=u;b<h;b+=6){const x=t[b+2*f];for(let S=0;S<g;S++){const T=m[S];x>=T.candidate?hr(b,t,T.rightCacheBounds):(hr(b,t,T.leftCacheBounds),T.count++)}}for(let b=0;b<g;b++){const x=m[b],S=x.count,T=r-x.count,w=x.leftCacheBounds,P=x.rightCacheBounds;let C=0;S!==0&&(C=ri(w)/c);let R=0;T!==0&&(R=ri(P)/c);const E=Xs+mn*(C*S+R*T);E<l&&(a=f,l=E,o=x.candidate)}}else{for(let g=0;g<st;g++){const b=dt[g];b.count=0,b.candidate=d+p+g*p;const x=b.bounds;for(let S=0;S<3;S++)x[S]=1/0,x[S+3]=-1/0}for(let g=u;g<h;g+=6){let S=~~((t[g+2*f]-d)/p);S>=st&&(S=st-1);const T=dt[S];T.count++,hr(g,t,T.bounds)}const m=dt[st-1];Ws(m.bounds,m.rightCacheBounds);for(let g=st-2;g>=0;g--){const b=dt[g],x=dt[g+1];Ys(b.bounds,x.rightCacheBounds,b.rightCacheBounds)}let v=0;for(let g=0;g<st-1;g++){const b=dt[g],x=b.count,S=b.bounds,w=dt[g+1].rightCacheBounds;x!==0&&(v===0?Ws(S,fr):Ys(S,fr,fr)),v+=x;let P=0,C=0;v!==0&&(P=ri(fr)/c);const R=r-v;R!==0&&(C=ri(w)/c);const E=Xs+mn*(P*v+C*R);E<l&&(a=f,l=E,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function jl(n,e,t,i){let r=0;for(let s=e,a=e+t;s<a;s++)r+=n[s*6+i*2];return r/t}class vn{constructor(){this.boundingData=new Float32Array(6)}}function $l(n,e,t,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let u=0;u<3;u++){let h=e[a*3+u];e[a*3+u]=e[o*3+u],e[o*3+u]=h}for(let u=0;u<6;u++){let h=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=h}a++,o--}else return a}}function ql(n,e,t,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[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=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=f}a++,o--}else return a}}function be(n,e){return e[n+15]===65535}function Me(n,e){return e[n+6]}function Pe(n,e){return e[n+14]}function we(n){return n+8}function Ee(n,e){return e[n+6]}function ya(n,e){return e[n+7]}let ga,pi,zr,va;const Xl=Math.pow(2,32);function Vn(n){return"count"in n?1:1+Vn(n.left)+Vn(n.right)}function Hl(n,e,t){return ga=new Float32Array(t),pi=new Uint32Array(t),zr=new Uint16Array(t),va=new Uint8Array(t),Jn(n,e)}function Jn(n,e){const t=n/4,i=n/2,r="count"in e,s=e.boundingData;for(let a=0;a<6;a++)ga[t+a]=s[a];if(r)if(e.buffer){const a=e.buffer;va.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=gi){const l=o/2;be(l,zr)||(pi[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return pi[t+6]=a,zr[i+14]=o,zr[i+15]=Xr,n+gi}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Jn(n+gi,a),l/4>Xl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return pi[t+6]=l/4,l=Jn(l,o),pi[t+7]=c,l}}function Wl(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,i=t>2**16,r=i?4:2,s=e?new SharedArrayBuffer(t*r):new ArrayBuffer(t*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 Yl(n,e,t,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?ql:$l,_=Wt(f),p=new Float32Array(6);let m=!1;const v=new vn;return gn(e,t,i,v.boundingData,p),b(v,t,i,p),v;function g(x){l&&l(x/_)}function b(x,S,T,w=null,P=0){if(!m&&P>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(f))),T<=o||P>=s)return g(S+T),x.offset=S,x.count=T,x;const C=Gl(x.boundingData,w,e,S,T,c);if(C.axis===-1)return g(S+T),x.offset=S,x.count=T,x;const R=y(h,d,e,S,T,C);if(R===S||R===S+T)g(S+T),x.offset=S,x.count=T;else{x.splitAxis=C.axis;const E=new vn,k=S,A=R-S;x.left=E,gn(e,k,A,E.boundingData,p),b(E,k,A,p,P+1);const z=new vn,N=R,L=T-A;x.right=z,gn(e,N,L,z.boundingData,p),b(z,N,L,p,P+1)}return x}}function Zl(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Wl(t,e.useSharedArrayBuffer),Ll(t,e.range)&&!e.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||Dl(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Vl(t),s=e.indirect?pa(t,e.range):ma(t,e.range);n._roots=s.map(a=>{const o=Yl(n,r,a.offset,a.count,e),c=Vn(o),l=new i(gi*c);return Hl(0,o,l),l})}class ut{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,r=-1/0;for(let s=0,a=e.length;s<a;s++){const c=e[s][t];i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}setFromPoints(e,t){let i=1/0,r=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}}ut.prototype.setFromBox=(function(){const n=new M.Vector3;return function(t,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=t.dot(n);a=Math.min(h,a),o=Math.max(h,o)}this.min=a,this.max=o}})();const Kl=(function(){const n=new M.Vector3,e=new M.Vector3,t=new M.Vector3;return function(r,s,a){const o=r.start,c=n,l=s.start,u=e;t.subVectors(o,l),n.subVectors(r.end,r.start),e.subVectors(s.end,s.start);const h=t.dot(u),f=u.dot(c),d=u.dot(u),y=t.dot(c),p=c.dot(c)*d-f*f;let m,v;p!==0?m=(h*f-y*d)/p:m=0,v=(h+m*f)/d,a.x=m,a.y=v}})(),os=(function(){const n=new M.Vector2,e=new M.Vector3,t=new M.Vector3;return function(r,s,a,o){Kl(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=e,d=t;if(r.closestPointToPoint(h,!0,e),s.closestPointToPoint(u,!0,t),f.distanceToSquared(h)<=d.distanceToSquared(u)){a.copy(f),o.copy(h);return}else{a.copy(u),o.copy(d);return}}}})(),Ql=(function(){const n=new M.Vector3,e=new M.Vector3,t=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(t);if(Math.abs(_.distanceToPoint(c))<=o){const m=_.projectPoint(c,e);if(a.containsPoint(m))return!0}return!1}})(),eu=1e-15;function _n(n){return Math.abs(n)<eu}class ke extends M.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M.Vector3),this.satBounds=new Array(4).fill().map(()=>new ut),this.points=[this.a,this.b,this.c],this.sphere=new M.Sphere,this.plane=new M.Plane,this.needsUpdate=!0}intersectsSphere(e){return Ql(e,this)}update(){const e=this.a,t=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(e,t),u.setFromPoints(l,r);const h=s[2],f=a[2];h.subVectors(t,i),f.setFromPoints(h,r);const d=s[3],y=a[3];d.subVectors(i,e),y.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}ke.prototype.closestPointToSegment=(function(){const n=new M.Vector3,e=new M.Vector3,t=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;t.start.copy(l[f]),t.end.copy(l[d]),os(t,r,n,e),u=n.distanceToSquared(e),u<h&&(h=u,s&&s.copy(n),a&&a.copy(e))}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)}})();ke.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new Array(3),i=new ut,r=new ut,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 v=_.points;let g=0,b=-1;for(let x=0;x<3;x++){const{start:S,end:T}=u;S.copy(v[x]),T.copy(v[(x+1)%3]),u.delta(a);const w=_n(p.distanceToPoint(S));if(_n(p.normal.dot(a))&&w){m.copy(u),g=2;break}const P=p.intersectLine(u,d);if(!P&&w&&d.copy(S),(P||w)&&!_n(d.distanceTo(T))){if(g<=1)(g===1?m.start:m.end).copy(d),w&&(b=g);else if(g>=2){(b===1?m.start:m.end).copy(d),g=2;break}if(g++,g===2&&b===-1)break}}return g}return function(p,m=null,v=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(n.copy(p),n.update(),p=n);const g=this.plane,b=p.plane;if(Math.abs(g.normal.dot(b.normal))>1-1e-10){const x=this.satBounds,S=this.satAxes;t[0]=p.a,t[1]=p.b,t[2]=p.c;for(let P=0;P<4;P++){const C=x[P],R=S[P];if(i.setFromPoints(R,t),C.isSeparated(i))return!1}const T=p.satBounds,w=p.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let P=0;P<4;P++){const C=T[P],R=w[P];if(i.setFromPoints(R,e),C.isSeparated(i))return!1}for(let P=0;P<4;P++){const C=S[P];for(let R=0;R<4;R++){const E=w[R];if(s.crossVectors(C,E),i.setFromPoints(s,e),r.setFromPoints(s,t),i.isSeparated(r))return!1}}return m&&(v||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,b,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 S=y(p,g,f);if(S===1&&this.containsPoint(f.end))return m&&(m.start.copy(f.end),m.end.copy(f.end)),!0;if(S!==2)return!1;if(h.delta(o),f.delta(c),o.dot(c)<0){let k=f.start;f.start=f.end,f.end=k}const T=h.start.dot(o),w=h.end.dot(o),P=f.start.dot(o),C=f.end.dot(o),R=w<P,E=T<C;return T!==C&&P!==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)}}})();ke.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();ke.prototype.distanceToTriangle=(function(){const n=new M.Vector3,e=new M.Vector3,t=["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=t[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=t[h],d=t[(h+1)%3];i.set(this[f],this[d]);for(let y=0;y<3;y++){const _=t[y],p=t[(y+1)%3];r.set(a[_],a[p]),os(i,r,n,e);const m=n.distanceToSquared(e);m<u&&(u=m,o&&o.copy(n),c&&c.copy(e))}}return Math.sqrt(u)}})();class de{constructor(e,t,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 ut),this.alignedSatBounds=new Array(3).fill().map(()=>new ut),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}de.prototype.update=(function(){return function(){const e=this.matrix,t=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:t.x,d.y=u?i.y:t.y,d.z=h?i.z:t.z,d.applyMatrix4(e)}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}})();de.prototype.intersectsBox=(function(){const n=new ut;return function(t){this.needsUpdate&&this.update();const i=t.min,r=t.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,t),u.isSeparated(n))return!1}return!0}})();de.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new ut,i=new ut,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;e[0]=a.a,e[1]=a.b,e[2]=a.c;for(let f=0;f<3;f++){const d=o[f],y=c[f];if(t.setFromPoints(y,e),d.isSeparated(t))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(t.setFromPoints(y,h),d.isSeparated(t))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,_),t.setFromPoints(r,e),i.setFromPoints(r,h),t.isSeparated(i))return!1}}return!0}})();de.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();de.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();de.prototype.distanceToBox=(function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new M.Line3),t=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 v=m.distanceToSquared(r);if(v<y&&(y=v,c&&c.copy(m),l&&l.copy(r),v<u))return Math.sqrt(v)}let _=0;for(let p=0;p<3;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){const g=(p+1)%3,b=(p+2)%3,x=m<<g|v<<b,S=1<<p|m<<g|v<<b,T=d[x],w=d[S];e[_].set(T,w);const C=n[p],R=n[g],E=n[b],k=t[_],A=k.start,z=k.end;A[C]=h[C],A[R]=m?h[R]:f[R],A[E]=v?h[E]:f[R],z[C]=f[C],z[R]=m?h[R]:f[R],z[E]=v?h[E]:f[R],_++}for(let p=0;p<=1;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){r.x=p?f.x:h.x,r.y=m?f.y:h.y,r.z=v?f.z:h.z,this.closestPointToPoint(r,i);const g=r.distanceToSquared(i);if(g<y&&(y=g,c&&c.copy(i),l&&l.copy(r),g<u))return Math.sqrt(g)}for(let p=0;p<12;p++){const m=e[p];for(let v=0;v<12;v++){const g=t[v];os(m,g,i,r);const b=i.distanceToSquared(r);if(b<y&&(y=b,c&&c.copy(i),l&&l.copy(r),b<u))return Math.sqrt(b)}}return Math.sqrt(y)}})();class as{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class tu extends as{constructor(){super(()=>new ke)}}const Re=new tu;class iu{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const $=new iu;let gt,Gt;const It=[],dr=new as(()=>new M.Box3);function ru(n,e,t,i,r,s){gt=dr.getPrimitive(),Gt=dr.getPrimitive(),It.push(gt,Gt),$.setBuffer(n._roots[e]);const a=Gn(0,n.geometry,t,i,r,s);$.clearBuffer(),dr.releasePrimitive(gt),dr.releasePrimitive(Gt),It.pop(),It.pop();const o=It.length;return o>0&&(Gt=It[o-1],gt=It[o-2]),a}function Gn(n,e,t,i,r=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=$;let u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);return Y(n,o,gt),i(f,d,!1,a,s+n,gt)}else{let C=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=we(E),z=E*2;return Me(E,A)},R=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=Ee(E,A),z=E*2;return Me(E,A)+Pe(z,k)};const f=we(n),d=Ee(n,l);let y=f,_=d,p,m,v,g;if(r&&(v=gt,g=Gt,Y(y,o,v),Y(_,o,g),p=r(v),m=r(g),m<p)){y=d,_=f;const E=p;p=m,m=E,v=g}v||(v=gt,Y(y,o,v));const b=be(y*2,c),x=t(v,b,p,a+1,s+y);let S;if(x===Ln){const E=C(y),A=R(y)-E;S=i(E,A,!0,a+1,s+y,v)}else S=x&&Gn(y,e,t,i,r,s,a+1);if(S)return!0;g=Gt,Y(_,o,g);const T=be(_*2,c),w=t(g,T,m,a+1,s+_);let P;if(w===Ln){const E=C(_),A=R(_)-E;P=i(E,A,!0,a+1,s+_,g)}else P=w&&Gn(_,e,t,i,r,s,a+1);return!!P}}const ni=new M.Vector3,xn=new M.Vector3;function nu(n,e,t={},i=0,r=1/0){const s=i*i,a=r*r;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:u=>(ni.copy(e).clamp(u.min,u.max),ni.distanceToSquared(e)),intersectsBounds:(u,h,f)=>f<o&&f<a,intersectsTriangle:(u,h)=>{u.closestPointToPoint(e,ni);const f=e.distanceToSquared(ni);return f<o&&(xn.copy(ni),o=f,c=h),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(xn):t.point=xn.clone(),t.distance=l,t.faceIndex=c,t}const su=parseInt(M.REVISION)>=169,St=new M.Vector3,Tt=new M.Vector3,Mt=new M.Vector3,pr=new M.Vector2,mr=new M.Vector2,yr=new M.Vector2,Zs=new M.Vector3,Ks=new M.Vector3,Qs=new M.Vector3,si=new M.Vector3;function ou(n,e,t,i,r,s,a,o){let c;if(s===M.BackSide?c=n.intersectTriangle(i,t,e,!0,r):c=n.intersectTriangle(e,t,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 au(n,e,t,i,r,s,a,o,c,l,u){St.fromBufferAttribute(e,s),Tt.fromBufferAttribute(e,a),Mt.fromBufferAttribute(e,o);const h=ou(n,St,Tt,Mt,si,c,l,u);if(h){const f=new M.Vector3;M.Triangle.getBarycoord(si,St,Tt,Mt,f),i&&(pr.fromBufferAttribute(i,s),mr.fromBufferAttribute(i,a),yr.fromBufferAttribute(i,o),h.uv=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),r&&(pr.fromBufferAttribute(r,s),mr.fromBufferAttribute(r,a),yr.fromBufferAttribute(r,o),h.uv1=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),t&&(Zs.fromBufferAttribute(t,s),Ks.fromBufferAttribute(t,a),Qs.fromBufferAttribute(t,o),h.normal=M.Triangle.getInterpolation(si,St,Tt,Mt,Zs,Ks,Qs,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(St,Tt,Mt,d.normal),h.face=d,h.faceIndex=s,su&&(h.barycoord=f)}return h}function Hr(n,e,t,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=au(t,f,d,y,_,c,l,u,e,s,a);return p?(p.faceIndex=i,r&&r.push(p),p):null}function te(n,e,t,i){const r=n.a,s=n.b,a=n.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.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 cu(n,e,t,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++)Hr(c,e,t,u,s,a,o)}function lu(n,e,t,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=Hr(o,e,t,h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function uu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=u,te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.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]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=3*m,C=3*(m+v);P<C;P++){let R=i[P];const E=r.getX(R),k=r.getY(R),A=r.getZ(R);E<g&&(g=E),E>S&&(S=E),k<b&&(b=k),k>T&&(T=k),A<x&&(x=A),A>w&&(w=A)}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function vt(n,e,t,i,r){let s,a,o,c,l,u;const h=1/t.direction.x,f=1/t.direction.y,d=1/t.direction.z,y=t.origin.x,_=t.origin.y,p=t.origin.z;let m=e[n],v=e[n+3],g=e[n+1],b=e[n+3+1],x=e[n+2],S=e[n+3+2];return h>=0?(s=(m-y)*h,a=(v-y)*h):(s=(v-y)*h,a=(m-y)*h),f>=0?(o=(g-_)*f,c=(b-_)*f):(o=(b-_)*f,c=(g-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),d>=0?(l=(x-p)*d,u=(S-p)*d):(l=(S-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 fu(n,e,t,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;Hr(c,e,t,f,s,a,o)}}function du(n,e,t,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=Hr(o,e,t,c?c[h]:h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function pu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=t.resolveTriangleIndex(u),te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function mu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),jn(0,n,t,i,r,s,a),$.clearBuffer()}function jn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);cu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&jn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&jn(d,e,t,i,r,s,a)}}const yu=["x","y","z"];function gu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=$n(0,n,t,i,r,s);return $.clearBuffer(),a}function $n(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return lu(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=yu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?$n(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?$n(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const gr=new M.Box3,Nt=new ke,Ut=new ke,oi=new M.Matrix4,eo=new de,vr=new de;function vu(n,e,t,i){$.setBuffer(n._roots[e]);const r=qn(0,n,t,i);return $.clearBuffer(),r}function qn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),eo.set(t.boundingBox.min,t.boundingBox.max,i),r=eo),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(oi.copy(i).invert(),t.boundsTree)return Y(n,s,vr),vr.matrix.copy(oi),vr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>vr.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_*3,b=(p+_)*3;g<b;g+=3)if(te(Ut,g,h,f),Ut.needsUpdate=!0,v.intersectsTriangle(Ut))return!0;return!1}});for(let m=_*3,v=(p+_)*3;m<v;m+=3){te(Nt,m,h,f),Nt.a.applyMatrix4(oi),Nt.b.applyMatrix4(oi),Nt.c.applyMatrix4(oi),Nt.needsUpdate=!0;for(let g=0,b=d.count;g<b;g+=3)if(te(Ut,g,d,y),Ut.needsUpdate=!0,Nt.intersectsTriangle(Ut))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,gr),!!(r.intersectsBox(gr)&&qn(u,e,t,i,r)||(Y(h,s,gr),r.intersectsBox(gr)&&qn(h,e,t,i,r)))}}const _r=new M.Matrix4,bn=new de,ai=new de,_u=new M.Vector3,xu=new M.Vector3,bu=new M.Vector3,Su=new M.Vector3;function Tu(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),bn.set(e.boundingBox.min,e.boundingBox.max,t),bn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=_u,_=xu,p=null,m=null;r&&(p=bu,m=Su);let v=1/0,g=null,b=null;return _r.copy(t).invert(),ai.matrix.copy(_r),n.shapecast({boundsTraverseOrder:x=>bn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(ai.min.copy(x.min),ai.max.copy(x.max),ai.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>ai.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){te(d,3*C,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let E=x,k=x+S;E<k;E++){te(f,3*E,l,c),f.needsUpdate=!0;const A=f.distanceToTriangle(d,y,p);if(A<v&&(_.copy(y),m&&m.copy(p),v=A,g=E,b=C),A<s)return!0}}}});{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){te(f,3*C,l,c),f.needsUpdate=!0;const E=f.distanceToTriangle(d,y,p);if(E<v&&(_.copy(y),m&&m.copy(p),v=E,g=C,b=w),E<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(_r),_.applyMatrix4(_r),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Mu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.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]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=m,C=m+v;P<C;P++){const R=3*n.resolveTriangleIndex(P);for(let E=0;E<3;E++){let k=R+E;k=i?i[k]:k;const A=r.getX(k),z=r.getY(k),N=r.getZ(k);A<g&&(g=A),A>S&&(S=A),z<b&&(b=z),z>T&&(T=z),N<x&&(x=N),N>w&&(w=N)}}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function Cu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),Xn(0,n,t,i,r,s,a),$.clearBuffer()}function Xn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);fu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&Xn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&Xn(d,e,t,i,r,s,a)}}const Pu=["x","y","z"];function wu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=Hn(0,n,t,i,r,s);return $.clearBuffer(),a}function Hn(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return du(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=Pu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?Hn(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?Hn(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const xr=new M.Box3,Ft=new ke,Dt=new ke,ci=new M.Matrix4,to=new de,br=new de;function Eu(n,e,t,i){$.setBuffer(n._roots[e]);const r=Wn(0,n,t,i);return $.clearBuffer(),r}function Wn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),to.set(t.boundingBox.min,t.boundingBox.max,i),r=to),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(ci.copy(i).invert(),t.boundsTree)return Y(n,s,br),br.matrix.copy(ci),br.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>br.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_,b=p+_;g<b;g++)if(te(Dt,3*e.resolveTriangleIndex(g),h,f),Dt.needsUpdate=!0,v.intersectsTriangle(Dt))return!0;return!1}});for(let m=_,v=p+_;m<v;m++){const g=e.resolveTriangleIndex(m);te(Ft,3*g,h,f),Ft.a.applyMatrix4(ci),Ft.b.applyMatrix4(ci),Ft.c.applyMatrix4(ci),Ft.needsUpdate=!0;for(let b=0,x=d.count;b<x;b+=3)if(te(Dt,b,d,y),Dt.needsUpdate=!0,Ft.intersectsTriangle(Dt))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,xr),!!(r.intersectsBox(xr)&&Wn(u,e,t,i,r)||(Y(h,s,xr),r.intersectsBox(xr)&&Wn(h,e,t,i,r)))}}const Sr=new M.Matrix4,Sn=new de,li=new de,Ru=new M.Vector3,ku=new M.Vector3,Au=new M.Vector3,zu=new M.Vector3;function Ou(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Sn.set(e.boundingBox.min,e.boundingBox.max,t),Sn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=Ru,_=ku,p=null,m=null;r&&(p=Au,m=zu);let v=1/0,g=null,b=null;return Sr.copy(t).invert(),li.matrix.copy(Sr),n.shapecast({boundsTraverseOrder:x=>Sn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(li.min.copy(x.min),li.max.copy(x.max),li.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree){const T=e.boundsTree;return T.shapecast({boundsTraverseOrder:w=>li.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){const E=T.resolveTriangleIndex(C);te(d,3*E,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let k=x,A=x+S;k<A;k++){const z=n.resolveTriangleIndex(k);te(f,3*z,l,c),f.needsUpdate=!0;const N=f.distanceToTriangle(d,y,p);if(N<v&&(_.copy(y),m&&m.copy(p),v=N,g=k,b=C),N<s)return!0}}}})}else{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){const E=n.resolveTriangleIndex(C);te(f,3*E,l,c),f.needsUpdate=!0;const k=f.distanceToTriangle(d,y,p);if(k<v&&(_.copy(y),m&&m.copy(p),v=k,g=C,b=w),k<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(Sr),_.applyMatrix4(Sr),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Bu(){return typeof SharedArrayBuffer<"u"}const vi=new $.constructor,Jr=new $.constructor,mt=new as(()=>new M.Box3),Lt=new M.Box3,Vt=new M.Box3,Tn=new M.Box3,Mn=new M.Box3;let Cn=!1;function Iu(n,e,t,i){if(Cn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Cn=!0;const r=n._roots,s=e._roots;let a,o=0,c=0;const l=new M.Matrix4().copy(t).invert();for(let u=0,h=r.length;u<h;u++){vi.setBuffer(r[u]),c=0;const f=mt.getPrimitive();Y(0,vi.float32Array,f),f.applyMatrix4(l);for(let d=0,y=s.length;d<y&&(Jr.setBuffer(s[d]),a=Ue(0,0,t,l,i,o,c,0,0,f),Jr.clearBuffer(),c+=s[d].length,!a);d++);if(mt.releasePrimitive(f),vi.clearBuffer(),o+=r[u].length,a)break}return Cn=!1,a}function Ue(n,e,t,i,r,s=0,a=0,o=0,c=0,l=null,u=!1){let h,f;u?(h=Jr,f=vi):(h=vi,f=Jr);const d=h.float32Array,y=h.uint32Array,_=h.uint16Array,p=f.float32Array,m=f.uint32Array,v=f.uint16Array,g=n*2,b=e*2,x=be(g,_),S=be(b,v);let T=!1;if(S&&x)u?T=r(Me(e,m),Pe(e*2,v),Me(n,y),Pe(n*2,_),c,a+e,o,s+n):T=r(Me(n,y),Pe(n*2,_),Me(e,m),Pe(e*2,v),o,s+n,c,a+e);else if(S){const w=mt.getPrimitive();Y(e,p,w),w.applyMatrix4(t);const P=we(n),C=Ee(n,y);Y(P,d,Lt),Y(C,d,Vt);const R=w.intersectsBox(Lt),E=w.intersectsBox(Vt);T=R&&Ue(e,P,i,t,r,a,s,c,o+1,w,!u)||E&&Ue(e,C,i,t,r,a,s,c,o+1,w,!u),mt.releasePrimitive(w)}else{const w=we(e),P=Ee(e,m);Y(w,p,Tn),Y(P,p,Mn);const C=l.intersectsBox(Tn),R=l.intersectsBox(Mn);if(C&&R)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u)||Ue(n,P,t,i,r,s,a,o,c+1,l,u);else if(C)if(x)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Tn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(w,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(w,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}else if(R)if(x)T=Ue(n,P,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Mn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(P,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(P,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}}return T}const Tr=new de,io=new M.Box3,Nu={strategy:ss,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class tr{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,r=e._roots,s=e._indirectBuffer,a=i.getIndex();let o;return t.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(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:r,roots:s,indirectBuffer:a}=e,o=new tr(t,{...i,[yn]:!0});if(o._roots=s,o._indirectBuffer=a||null,i.setIndex){const c=t.getIndex();if(c===null){const l=new M.BufferAttribute(e.index,1,!1);t.setIndex(l)}else c.array!==r&&(c.array.set(r),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Nu,[yn]:!1},t),t.useSharedArrayBuffer&&!Bu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[yn]||(Zl(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new M.Box3))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Mu:hu)(this,e)}traverse(e,t=0){const i=this._roots[t],r=new Uint32Array(i),s=new Uint16Array(i);a(0);function a(o,c=0){const l=o*2,u=s[l+15]===Xr;if(u){const h=r[o+6],f=s[l+14];e(c,u,new Float32Array(i,o*4,6),h,f)}else{const h=o+gi/4,f=r[o+6],d=r[o+7];e(c,u,new Float32Array(i,o*4,6),d)||(a(h,c+1),a(f,c+1))}}}raycast(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),u=a.groups,h=c?t.side:t,f=this.indirect?Cu:mu;for(let d=0,y=s.length;d<y;d++){const _=l?t[u[d].materialIndex].side:h,p=o.length;if(f(this,d,_,e,o,i,r),l){const m=u[d].materialIndex;for(let v=p,g=o.length;v<g;v++)o[v].face.materialIndex=m}}return o}raycastFirst(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const u=a.groups,h=o?t.side:t,f=this.indirect?wu:gu;for(let d=0,y=s.length;d<y;d++){const _=c?t[u[d].materialIndex].side:h,p=f(this,d,_,e,i,r);p!=null&&(l==null||p.distance<l.distance)&&(l=p,c&&(p.face.materialIndex=u[d].materialIndex))}return l}intersectsGeometry(e,t){let i=!1;const r=this._roots,s=this.indirect?Eu:vu;for(let a=0,o=r.length;a<o&&(i=s(this,a,e,t),!i);a++);return i}shapecast(e){const t=Re.getPrimitive(),i=this.indirect?pu:uu;let{boundsTraverseOrder:r,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const h=a;a=(f,d,y,_,p)=>h(f,d,y,_,p)?!0:i(f,d,this,o,y,_,t)}else a||(o?a=(h,f,d,y)=>i(h,f,this,o,d,y,t):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=ru(this,h,s,a,r,l),c)break;l+=d.byteLength}return Re.releasePrimitive(t),c}bvhcast(e,t,i){let{intersectsRanges:r,intersectsTriangles:s}=i;const a=Re.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const _=this.resolveTriangleIndex(y);te(a,_*3,o,c)}:y=>{te(a,y*3,o,c)},u=Re.getPrimitive(),h=e.geometry.index,f=e.geometry.attributes.position,d=e.indirect?y=>{const _=e.resolveTriangleIndex(y);te(u,_*3,h,f)}:y=>{te(u,y*3,h,f)};if(s){const y=(_,p,m,v,g,b,x,S)=>{for(let T=m,w=m+v;T<w;T++){d(T),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let P=_,C=_+p;P<C;P++)if(l(P),a.needsUpdate=!0,s(a,u,P,T,g,b,x,S))return!0}return!1};if(r){const _=r;r=function(p,m,v,g,b,x,S,T){return _(p,m,v,g,b,x,S,T)?!0:y(p,m,v,g,b,x,S,T)}}else r=y}return Iu(this,e,t,r)}intersectsBox(e,t){return Tr.set(e.min,e.max,t),Tr.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Tr.intersectsBox(i),intersectsTriangle:i=>Tr.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},r={},s=0,a=1/0){return(this.indirect?Ou:Tu)(this,e,t,i,r,s,a)}closestPointToPoint(e,t={},i=0,r=1/0){return nu(this,e,t,i,r)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),io),e.union(io)}),e}}function ro(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Mr=new M.Ray,no=new M.Vector3,so=new M.Matrix4,Uu=M.Mesh.prototype.raycast,Fu=M.BatchedMesh.prototype.raycast,oo=new M.Vector3,ce=new M.Mesh,Cr=[];function Du(n,e){this.isBatchedMesh?Lu.call(this,n,e):Vu.call(this,n,e)}function Lu(n,e){if(this.boundsTrees){const t=this.boundsTrees,i=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ce.material=this.material,ce.geometry=this.geometry;const a=ce.geometry.boundsTree,o=ce.geometry.drawRange;ce.geometry.boundingSphere===null&&(ce.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(ce.geometry.boundsTree=t[u],this.getMatrixAt(c,ce.matrixWorld).premultiply(s),!ce.geometry.boundsTree){this.getBoundingBoxAt(u,ce.geometry.boundingBox),this.getBoundingSphereAt(u,ce.geometry.boundingSphere);const h=r[u];ce.geometry.setDrawRange(h.start,h.count)}ce.raycast(n,Cr);for(let h=0,f=Cr.length;h<f;h++){const d=Cr[h];d.object=this,d.batchId=c,e.push(d)}Cr.length=0}ce.geometry.boundsTree=a,ce.geometry.drawRange=o,ce.material=null,ce.geometry=null}else Fu.call(this,n,e)}function Vu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;so.copy(this.matrixWorld).invert(),Mr.copy(n.ray).applyMatrix4(so),oo.setFromMatrixScale(this.matrixWorld),no.copy(Mr.direction).multiply(oo);const t=no.length(),i=n.near/t,r=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=ro(s.raycastFirst(Mr,this.material,i,r),this,n);a&&e.push(a)}else{const a=s.raycast(Mr,this.material,i,r);for(let o=0,c=a.length;o<c;o++){const l=ro(a[o],this,n);l&&e.push(l)}}}else Uu.call(this,n,e)}function Ju(n={}){return this.boundsTree=new tr(this,n),this.boundsTree}const Ct=new M.Vector3,Pt=new M.Vector3,wt=new M.Vector3,ao=new M.Vector4,Pr=new M.Vector3,Pn=new M.Vector3,co=new M.Vector4,lo=new M.Vector4,wr=new M.Matrix4,uo=new M.Matrix4;function ui(n,e){if(!n&&!e)return;const t=n.count===e.count,i=n.normalized===e.normalized,r=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!i||!r||!s)throw new Error}function mi(n,e=null){const t=n.array.constructor,i=n.normalized,r=n.itemSize,s=e===null?n.count:e;return new M.BufferAttribute(new t(r*s),r,i)}function _a(n,e,t=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let r=0,s=n.count;r<s;r++){const a=r+t;e.setX(a,n.getX(r)),i>=2&&e.setY(a,n.getY(r)),i>=3&&e.setZ(a,n.getZ(r)),i>=4&&e.setW(a,n.getW(r))}}else{const i=e.array,r=i.constructor,s=i.BYTES_PER_ELEMENT*n.itemSize*t;new r(i.buffer,s,n.array.length).set(n.array)}}function Gu(n,e,t){const i=n.elements,r=e.elements;for(let s=0,a=r.length;s<a;s++)i[s]+=r[s]*t}function ho(n,e,t){const i=n.skeleton,r=n.geometry,s=i.bones,a=i.boneInverses;co.fromBufferAttribute(r.attributes.skinIndex,e),lo.fromBufferAttribute(r.attributes.skinWeight,e),wr.elements.fill(0);for(let o=0;o<4;o++){const c=lo.getComponent(o);if(c!==0){const l=co.getComponent(o);uo.multiplyMatrices(s[l].matrixWorld,a[l]),Gu(wr,uo,c)}}return wr.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(wr),t}function wn(n,e,t,i,r){Pr.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(Pn.fromBufferAttribute(c,i),t?Pr.addScaledVector(Pn,o):Pr.addScaledVector(Pn.sub(r),o))}r.add(Pr)}function ju(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new M.BufferGeometry){const i=n[0].index!==null,{useGroups:r=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.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");t.addGroup(l,d,u),l+=d}}if(i){let u=!1;if(!t.index){let h=0;for(let f=0;f<n.length;++f)h+=n[f].index.count;t.setIndex(new M.BufferAttribute(new Uint32Array(h),1,!1)),u=!0}if(s||u){const h=t.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 t.attributes)){let y=0;for(const _ in h)y+=h[_].count;t.setAttribute(u,mi(c[u][0],y))}const f=t.attributes[u];let d=0;for(let y=0,_=h.length;y<_;y++){const p=h[y];a[y]!==!0&&_a(p,f,d),d+=p.count}}return t}function $u(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,i=n.length;t<i;t++)if(n[t]!==e[t])return!1;return!0}function qu(n){const{index:e,attributes:t}=n;if(e)for(let i=0,r=e.count;i<r;i+=3){const s=e.getX(i),a=e.getX(i+2);e.setX(i,a),e.setX(i+2,s)}else for(const i in t){const r=t[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 Xu{constructor(e){this.matrixWorld=new M.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,i=e.skeleton,r=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.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 e=this.mesh,t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&$u(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class Hu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(i=>{i.traverseVisible(r=>{r.isMesh&&t.push(r)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new M.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new M.BufferGeometry){let t=[];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),t.push(!1),h?h.update():a.set(l,new Xu(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new M.BufferAttribute(new Float32Array(0),4,!1))}else ju(s,{useGroups:r,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new M.BufferGeometry){const i=e.geometry,r=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=i.attributes,c=t.attributes;!t.index&&i.index&&(t.index=i.index.clone()),c.position||t.setAttribute("position",mi(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",mi(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",mi(o.tangent)),ui(i.index,t.index),ui(o.position,c.position),s&&ui(o.normal,c.normal),a&&ui(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=e.morphTargetInfluences,m=new M.Matrix3;m.getNormalMatrix(e.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let v=0,g=o.position.count;v<g;v++)Ct.fromBufferAttribute(l,v),u&&Pt.fromBufferAttribute(u,v),h&&(ao.fromBufferAttribute(h,v),wt.fromBufferAttribute(h,v)),p&&(f&&wn(f,p,_,v,Ct),d&&wn(d,p,_,v,Pt),y&&wn(y,p,_,v,wt)),e.isSkinnedMesh&&(e.applyBoneTransform(v,Ct),u&&ho(e,v,Pt),h&&ho(e,v,wt)),r&&Ct.applyMatrix4(e.matrixWorld),c.position.setXYZ(v,Ct.x,Ct.y,Ct.z),u&&(r&&Pt.applyNormalMatrix(m),c.normal.setXYZ(v,Pt.x,Pt.y,Pt.z)),h&&(r&&wt.transformDirection(e.matrixWorld),c.tangent.setXYZW(v,wt.x,wt.y,wt.z,ao.w));for(const v in this.attributes){const g=this.attributes[v];g==="position"||g==="tangent"||g==="normal"||!(g in o)||(c[g]||t.setAttribute(g,mi(o[g])),ui(o[g],c[g]),_a(o[g],c[g]))}return e.matrixWorld.determinant()<0&&qu(t),t}}const Wu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:fa,CENTER:ss,CONTAINED:Ln,ExtendedTriangle:ke,MeshBVH:tr,OrientedBox:de,SAH:da,StaticGeometryGenerator:Hu,acceleratedRaycast:Du,computeBoundsTree:Ju},Symbol.toStringTag,{value:"Module"}));class Yu{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){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 t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const Ce={node:"node",material:"material",camera:"camera",light:"light"},Et="KHR_animation_pointer",Zu={CUBICSPLINE:void 0,LINEAR:M.InterpolateLinear,STEP:M.InterpolateDiscrete};class Ku{constructor(e){this.name=Et,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,i=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",i)}loadAnimationTargetFromChannelWithAnimationPointer(e){eh();const t=e.target,i=t.extensions&&t.extensions[Et]&&t.path&&t.path==="pointer";if(!i)return null;let r,s=Ce.node,a;if(i){const c=t.extensions[Et];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=Ce.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=Ce.light:l.startsWith("/cameras/")&&(s=Ce.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case Ce.material:const u=("/materials/"+a.toString()+"/").length,h=l.substring(0,u);switch(r=l.substring(u),r){case"pbrMetallicRoughness/baseColorFactor":r="color";break;case"pbrMetallicRoughness/roughnessFactor":r="roughness";break;case"pbrMetallicRoughness/metallicFactor":r="metalness";break;case"emissiveFactor":r="emissive";break;case"alphaCutoff":r="alphaTest";break;case"occlusionTexture/strength":r="aoMapIntensity";break;case"normalTexture/scale":r="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":r="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":r="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":r="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":r="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":r="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":r="transmission";break;case"extensions/KHR_materials_ior/ior":r="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":r="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":r="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":r="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":r="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":r="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":r="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":r="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":r="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":r="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":r="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":r="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":r="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":r="specularColor";break}l=h+r;break;case Ce.node:const f=("/nodes/"+a.toString()+"/").length,d=l.substring(0,f);switch(r=l.substring(f),r){case"translation":r="position";break;case"rotation":r="quaternion";break;case"scale":r="scale";break;case"weights":r="morphTargetInfluences";break}l=d+r;break;case Ce.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(r=l.substring(y),r){case"color":break;case"intensity":break;case"spot/innerConeAngle":r="penumbra";break;case"spot/outerConeAngle":r="angle";break;case"range":r="distance";break}l="/lights/"+a.toString()+"/"+r;break;case Ce.camera:const _=("/cameras/"+a.toString()+"/").length,p=l.substring(0,_);switch(r=l.substring(_),r){case"perspective/yfov":r="fov";break;case"perspective/znear":case"orthographic/znear":r="near";break;case"perspective/zfar":case"orthographic/zfar":r="far";break;case"perspective/aspect":r="aspect";break;case"orthographic/xmag":r="zoom";break;case"orthographic/ymag":r="zoom";break}l=p+r;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Et].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===Ce.node?o=this.parser.getDependency("node",a):s===Ce.material?o=this.parser.getDependency("material",a):s===Ce.light?o=this.parser.getDependency("light",a):s===Ce.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,i,r,s){if(!(s.extensions&&s.extensions[Et]&&s.path&&s.path==="pointer"))return null;let o=s.extensions[Et].pointer;if(!o)return null;const c=[];o=o.replaceAll("/",".");const l=o.split(".");var h=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(l[2]=h,l[3]==="morphTargetInfluences"&&e.type==="Group"){for(const d of e.children)d instanceof M.SkinnedMesh&&d.morphTargetInfluences&&(l[3]=d.name,l[4]="morphTargetInfluences",f(this.parser));return c}f(this.parser);function f(d){o=l.join(".");let y;switch(i.itemSize){case 1:y=M.NumberKeyframeTrack;break;case 2:case 3:y=M.VectorKeyframeTrack;break;case 4:o.endsWith(".quaternion")?y=M.QuaternionKeyframeTrack:y=M.ColorKeyframeTrack;break}if(!y){console.warn("Unsupported output accessor format",i);return}const _=r.interpolation!==void 0?Zu[r.interpolation]:M.InterpolateLinear;let p=d._getArrayFromAccessor(i);o.endsWith(".fov")&&(p=p.map(v=>v/Math.PI*180));const m=new y(o,t.array,p,_);if(_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(m),o&&i.itemSize===4&&o.startsWith(".materials.")&&o.endsWith(".color")){const v=new Float32Array(p.length/4);for(let b=0,x=p.length/4;b<x;b+=1)v[b]=p[b*4+3];const g=new y(o.replace(".color",".opacity"),t.array,v,_);_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(g)}}return c}_tryResolveTargetId(e,t){let i="";return t==="node"?i=e.substring(7):t==="material"?i=e.substring(11):t==="light"?i=e.substring(39):t==="camera"&&(i=e.substring(9)),i=i.substring(0,i.indexOf("/")),Number.parseInt(i)}loadAnimation(e){const t=this,i=this.parser.json,r=this.parser,s=i.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],h=[];for(let f=0,d=s.channels.length;f<d;f++){const y=s.channels[f],_=s.samplers[y.sampler],p=y.target,m=s.parameters!==void 0?s.parameters[_.input]:_.input,v=s.parameters!==void 0?s.parameters[_.output]:_.output;let g=t.loadAnimationTargetFromChannelWithAnimationPointer(y);g||(g=t.loadAnimationTargetFromChannel(y)),o.push(g),c.push(r.getDependency("accessor",m)),l.push(r.getDependency("accessor",v)),u.push(_),h.push(p)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(h)]).then(function(f){const d=f[0],y=f[1],_=f[2],p=f[3],m=f[4],v=[];for(let g=0,b=d.length;g<b;g++){const x=d[g],S=y[g],T=_[g],w=p[g],P=m[g];if(x===void 0)continue;x.updateMatrix&&(x.updateMatrix(),x.matrixAutoUpdate=!0);let C=t.createAnimationTracksWithAnimationPointer(x,S,T,w,P);if(C||(C=r._createAnimationTracks(x,S,T,w,P)),C)for(let R=0;R<C.length;R++)v.push(C[R])}return new M.AnimationClip(a,void 0,v)})}}let fo=!1,Qu=null;function eh(){if(fo)return;fo=!0;const n=Qu||=M.PropertyBinding.findNode;M.PropertyBinding.findNode=function(e,t){if(t.startsWith(".materials.")){const i=t.substring(11).substring(t.indexOf(".")),r=i.indexOf("."),s=r<0?i:i.substring(0,r);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(i.endsWith(".map")?a=a.map:i.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const i=t.split(".");let r;for(let s=1;s<i.length;s++){const a=i[s];if(a.length==36)r=e.getObjectByProperty("uuid",a);else if(r&&r[a]){const c=Number.parseInt(a);let l=a;c>=0&&(l=c),r=r[l]}else{const c=e.getObjectByName(a);c&&(r=c)}}if(!r){const s=n(e,i[2]);return s||console.warn(Et+": Property binding not found",t,e,e.name,i),s}return r}return n(e,t)}}const th=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Ku},Symbol.toStringTag,{value:"Module"}));exports.$70d766613f57b014$export$2e2bcd8739ae039=ia;exports.BatchedParticleRenderer=Rl;exports.Builder=Yn;exports.ByteBuffer=_i;exports.ConstantColor=At;exports.ConstantValue=F;exports.Matrix4=De;exports.MeshBVH=tr;exports.MotionController=Pa;exports.ParticleSystem=Vr;exports.SIZE_PREFIX_LENGTH=mo;exports.TrailParticle=Dr;exports.Vector4=Se;exports.WorkerBase=Yu;exports.bundler=nc;exports.createNoise4D=Al;exports.fetchProfile=ba;exports.index=Il;exports.index$1=Wu;exports.index$2=th;exports.md5=xc;exports.v5=mc;
|
|
1121
|
+
}`;class El extends la{constructor(e){super(e),this.vector_=new B,this.vector2_=new B,this.vector3_=new B,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(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new jt(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Dn(this.settings.material.map.channel),e.map=new M.Uniform$1(this.settings.material.map),e.mapTransform=new M.Uniform$1(new He().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new M.ShaderMaterial({uniforms:e,defines:t,vertexShader:wl,fragmentShader:Pl,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 e=0,t=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),v=_.previous.values();let g=v.next(),b=g.value,x=b;g.done||(g=v.next());let S;g.value!==void 0?S=g.value:S=x;for(let T=0;T<_.previous.length;T++,e+=2){if(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z),r.worldSpace?(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+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(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.previousBuffer.setXYZ(e,b.position.x,b.position.y,b.position.z),this.previousBuffer.setXYZ(e+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.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),r.worldSpace?(this.nextBuffer.setXYZ(e,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+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.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,-1),this.sideBuffer.setX(e+1,1),r.worldSpace)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else if(_.parentMatrix)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else{const w=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,x.size*w),this.widthBuffer.setX(e+1,x.size*w)}this.uvBuffer.setXY(e,(T/_.previous.length+p)*f,(h-m-1)*d),this.uvBuffer.setXY(e+1,(T/_.previous.length+p)*f,(h-m)*d),this.colorBuffer.setXYZW(e,x.color.x,x.color.y,x.color.z,x.color.w),this.colorBuffer.setXYZW(e+1,x.color.x,x.color.y,x.color.z,x.color.w),T+1<_.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),b=x,x=S,g.done||(g=v.next(),g.value!==void 0&&(S=g.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class Ki{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new M.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const r=e.getIndex().array,s=r.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),r[a*3],r[a*3+1],r[a*3+2]),i+=t.getArea(),this._triangleIndexToArea.push(i);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new M.Vector3,this._tempB=new M.Vector3,this._tempC=new M.Vector3,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.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=t.getIndex().array[r*3],u=t.getIndex().array[r*3+1],h=t.getIndex().array[r*3+2],f=t.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),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new Ki(t.geometries[e.geometry])}clone(){return new Ki(this._geometry)}update(e,t){}}sl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Ki,loadJSON:Ki.fromJSON}],behaviors:[]});class ns extends M.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let r=0;r<this.batches.length;r++)if(ns.equals(this.batches[r].settings,t)){this.batches[r].addSystem(e),this.systemToBatchIndex.set(e,r);return}let i;switch(t.renderMode){case exports.RenderMode.Trail:i=new El(t);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new Cl(t);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(e),this.batches.push(i),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(i)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,i)=>{i.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const Rl=ns;pl();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const ua=Math.sqrt(5),kl=(ua-1)/4,ae=(5-ua)/20,lr=n=>Math.floor(n)|0,ur=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 Al(n=Math.random){const e=zl(n),t=new Float64Array(e).map(a=>ur[a%32*4]),i=new Float64Array(e).map(a=>ur[a%32*4+1]),r=new Float64Array(e).map(a=>ur[a%32*4+2]),s=new Float64Array(e).map(a=>ur[a%32*4+3]);return function(o,c,l,u){let h,f,d,y,_;const p=(o+c+l+u)*kl,m=lr(o+p),v=lr(c+p),g=lr(l+p),b=lr(u+p),x=(m+v+g+b)*ae,S=m-x,T=v-x,w=g-x,P=b-x,C=o-S,R=c-T,E=l-w,k=u-P;let A=0,z=0,N=0,L=0;C>R?A++:z++,C>E?A++:N++,C>k?A++:L++,R>E?z++:N++,R>k?z++:L++,E>k?N++:L++;const I=A>=3?1:0,X=z>=3?1:0,Z=N>=3?1:0,ie=L>=3?1:0,Q=A>=2?1:0,pe=z>=2?1:0,me=N>=2?1:0,re=L>=2?1:0,H=A>=1?1:0,j=z>=1?1:0,Ye=N>=1?1:0,Le=L>=1?1:0,Ve=C-I+ae,Je=R-X+ae,ve=E-Z+ae,Ae=k-ie+ae,_e=C-Q+2*ae,Ze=R-pe+2*ae,Ke=E-me+2*ae,W=k-re+2*ae,Ge=C-H+3*ae,Qe=R-j+3*ae,_t=E-Ye+3*ae,et=k-Le+3*ae,tt=C-1+4*ae,it=R-1+4*ae,rt=E-1+4*ae,nt=k-1+4*ae,ze=m&255,Oe=v&255,Be=g&255,Ie=b&255;let V=.6-C*C-R*R-E*E-k*k;if(V<0)h=0;else{const q=ze+e[Oe+e[Be+e[Ie]]];V*=V,h=V*V*(t[q]*C+i[q]*R+r[q]*E+s[q]*k)}let Yt=.6-Ve*Ve-Je*Je-ve*ve-Ae*Ae;if(Yt<0)f=0;else{const q=ze+I+e[Oe+X+e[Be+Z+e[Ie+ie]]];Yt*=Yt,f=Yt*Yt*(t[q]*Ve+i[q]*Je+r[q]*ve+s[q]*Ae)}let Zt=.6-_e*_e-Ze*Ze-Ke*Ke-W*W;if(Zt<0)d=0;else{const q=ze+Q+e[Oe+pe+e[Be+me+e[Ie+re]]];Zt*=Zt,d=Zt*Zt*(t[q]*_e+i[q]*Ze+r[q]*Ke+s[q]*W)}let Kt=.6-Ge*Ge-Qe*Qe-_t*_t-et*et;if(Kt<0)y=0;else{const q=ze+H+e[Oe+j+e[Be+Ye+e[Ie+Le]]];Kt*=Kt,y=Kt*Kt*(t[q]*Ge+i[q]*Qe+r[q]*_t+s[q]*et)}let Qt=.6-tt*tt-it*it-rt*rt-nt*nt;if(Qt<0)_=0;else{const q=ze+1+e[Oe+1+e[Be+1+e[Ie+1]]];Qt*=Qt,_=Qt*Qt*(t[q]*tt+i[q]*it+r[q]*rt+s[q]*nt)}return 27*(h+f+d+y+_)}}function zl(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const r=i+~~(n()*(256-i)),s=t[i];t[i]=t[r],t[r]=s}for(let i=256;i<512;i++)t[i]=t[i-256];return t}class Ol{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,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 ha{constructor(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v;this._closedByUser=!1,this.handleOpenEvent=g=>this.handleEvent(G.open,g),this.handleErrorEvent=g=>this.handleEvent(G.error,g),this.handleCloseEvent=g=>this.handleEvent(G.close,g),this.handleMessageEvent=g=>this.handleEvent(G.message,g),this._url=e,this._protocols=t,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:[...(v=(m=i?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&v!==void 0?v:[]]}},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(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,i){this._options.listeners[e].push({listener:t,options:i})}removeEventListener(e,t,i){const r=s=>s.listener!==t||s.options!==i;this._options.listeners[e]=this._options.listeners[e].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(e,t){const i=this._options.listeners[e],r=[];i.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&r.push({listener:s,options:a})}),this._options.listeners[e]=r}handleEvent(e,t){switch(e){case G.close:this.dispatchEvent(e,t),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(e,t),this.sendBufferedData();break;case G.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=i=>{const r=new CustomEvent(G.retry,{detail:i});this.handleEvent(G.retry,r)},t={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||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class Bl{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(G.open,e,t),this}onClose(e,t){return this.addListener(G.close,e,t),this}onError(e,t){return this.addListener(G.error,e,t),this}onMessage(e,t){return this.addListener(G.message,e,t),this}onRetry(e,t){return this.addListener(G.retry,e,t),this}onReconnect(e,t){return this.addListener(G.reconnect,e,t),this}build(){return new ha(this._url,this._protocols,this._options)}addListener(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v,g,b,x,S,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:(v=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.retry)!==null&&v!==void 0?v:[],reconnect:(x=(b=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||b===void 0?void 0:b.reconnect)!==null&&x!==void 0?x:[],[e]:[...(w=(T=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||T===void 0?void 0:T[e])!==null&&w!==void 0?w:[],{listener:t,options:i}]}}),this}}const Il=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Ol,Websocket:ha,WebsocketBuilder:Bl,get WebsocketEvent(){return G}},Symbol.toStringTag,{value:"Module"})),ss=0,fa=1,da=2,Ln=2,mn=1.25,Xs=1,gi=32,Xr=65535,Nl=Math.pow(2,-24),yn=Symbol("SKIP_GENERATION");function Ul(n){return n.index?n.index.count:n.attributes.position.count}function Wt(n){return Ul(n)/3}function Fl(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Dl(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Fl(t,i);n.setIndex(new M.BufferAttribute(r,1));for(let s=0;s<t;s++)r[s]=s}}function pa(n,e){const t=Wt(n),i=e||n.drawRange,r=i.start/3,s=(i.start+i.count)/3,a=Math.max(0,r),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function ma(n,e){if(!n.groups||!n.groups.length)return pa(n,e);const t=[],i=new Set,r=e||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];t.push({offset:Math.floor(l),count:Math.floor(u-l)})}return t}function Ll(n,e){const t=Wt(n),i=ma(n,e).sort((a,o)=>a.offset-o.offset),r=i[i.length-1];r.count=Math.min(t-r.offset,r.count);let s=0;return i.forEach(({count:a})=>s+=a),t!==s}function gn(n,e,t,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=e*6,v=(e+t)*6;m<v;m+=6){const g=n[m+0],b=n[m+1],x=g-b,S=g+b;x<s&&(s=x),S>c&&(c=S),g<h&&(h=g),g>y&&(y=g);const T=n[m+2],w=n[m+3],P=T-w,C=T+w;P<a&&(a=P),C>l&&(l=C),T<f&&(f=T),T>_&&(_=T);const R=n[m+4],E=n[m+5],k=R-E,A=R+E;k<o&&(o=k),A>u&&(u=A),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 Vl(n,e=null,t=null,i=null){const r=n.attributes.position,s=n.index?n.index.array:null,a=Wt(n),o=r.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,i=a):(c=e,t=t||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=t;d<t+i;d++){const y=d*3,_=d*6;let p=y+0,m=y+1,v=y+2;s&&(p=s[p],m=s[m],v=s[v]),o||(p=p*h+u,m=m*h+u,v=v*h+u);for(let g=0;g<3;g++){let b,x,S;o?(b=r[f[g]](p),x=r[f[g]](m),S=r[f[g]](v)):(b=l[p+g],x=l[m+g],S=l[v+g]);let T=b;x<T&&(T=x),S<T&&(T=S);let w=b;x>w&&(w=x),S>w&&(w=S);const P=(w-T)/2,C=g*2;c[_+C+0]=T+P,c[_+C+1]=P+(Math.abs(T)+P)*Nl}}return c}function Y(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function Hs(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const r=n[i+3]-n[i];r>t&&(t=r,e=i)}return e}function Ws(n,e){e.set(n)}function Ys(n,e,t){let i,r;for(let s=0;s<3;s++){const a=s+3;i=n[s],r=e[s],t[s]=i<r?i:r,i=n[a],r=e[a],t[a]=i>r?i:r}}function hr(n,e,t){for(let i=0;i<3;i++){const r=e[n+2*i],s=e[n+2*i+1],a=r-s,o=r+s;a<t[i]&&(t[i]=a),o>t[i+3]&&(t[i+3]=o)}}function ri(n){const e=n[3]-n[0],t=n[4]-n[1],i=n[5]-n[2];return 2*(e*t+t*i+i*e)}const st=32,Jl=(n,e)=>n.candidate-e.candidate,dt=new Array(st).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),fr=new Float32Array(6);function Gl(n,e,t,i,r,s){let a=-1,o=0;if(s===ss)a=Hs(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===fa)a=Hs(n),a!==-1&&(o=jl(t,i,r,a));else if(s===da){const c=ri(n);let l=mn*r;const u=i*6,h=(i+r)*6;for(let f=0;f<3;f++){const d=e[f],p=(e[f+3]-d)/st;if(r<st/4){const m=[...dt];m.length=r;let v=0;for(let b=u;b<h;b+=6,v++){const x=m[v];x.candidate=t[b+2*f],x.count=0;const{bounds:S,leftCacheBounds:T,rightCacheBounds:w}=x;for(let P=0;P<3;P++)w[P]=1/0,w[P+3]=-1/0,T[P]=1/0,T[P+3]=-1/0,S[P]=1/0,S[P+3]=-1/0;hr(b,t,S)}m.sort(Jl);let g=r;for(let b=0;b<g;b++){const x=m[b];for(;b+1<g&&m[b+1].candidate===x.candidate;)m.splice(b+1,1),g--}for(let b=u;b<h;b+=6){const x=t[b+2*f];for(let S=0;S<g;S++){const T=m[S];x>=T.candidate?hr(b,t,T.rightCacheBounds):(hr(b,t,T.leftCacheBounds),T.count++)}}for(let b=0;b<g;b++){const x=m[b],S=x.count,T=r-x.count,w=x.leftCacheBounds,P=x.rightCacheBounds;let C=0;S!==0&&(C=ri(w)/c);let R=0;T!==0&&(R=ri(P)/c);const E=Xs+mn*(C*S+R*T);E<l&&(a=f,l=E,o=x.candidate)}}else{for(let g=0;g<st;g++){const b=dt[g];b.count=0,b.candidate=d+p+g*p;const x=b.bounds;for(let S=0;S<3;S++)x[S]=1/0,x[S+3]=-1/0}for(let g=u;g<h;g+=6){let S=~~((t[g+2*f]-d)/p);S>=st&&(S=st-1);const T=dt[S];T.count++,hr(g,t,T.bounds)}const m=dt[st-1];Ws(m.bounds,m.rightCacheBounds);for(let g=st-2;g>=0;g--){const b=dt[g],x=dt[g+1];Ys(b.bounds,x.rightCacheBounds,b.rightCacheBounds)}let v=0;for(let g=0;g<st-1;g++){const b=dt[g],x=b.count,S=b.bounds,w=dt[g+1].rightCacheBounds;x!==0&&(v===0?Ws(S,fr):Ys(S,fr,fr)),v+=x;let P=0,C=0;v!==0&&(P=ri(fr)/c);const R=r-v;R!==0&&(C=ri(w)/c);const E=Xs+mn*(P*v+C*R);E<l&&(a=f,l=E,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function jl(n,e,t,i){let r=0;for(let s=e,a=e+t;s<a;s++)r+=n[s*6+i*2];return r/t}class vn{constructor(){this.boundingData=new Float32Array(6)}}function $l(n,e,t,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let u=0;u<3;u++){let h=e[a*3+u];e[a*3+u]=e[o*3+u],e[o*3+u]=h}for(let u=0;u<6;u++){let h=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=h}a++,o--}else return a}}function ql(n,e,t,i,r,s){let a=i,o=i+r-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[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=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=f}a++,o--}else return a}}function be(n,e){return e[n+15]===65535}function Me(n,e){return e[n+6]}function Pe(n,e){return e[n+14]}function we(n){return n+8}function Ee(n,e){return e[n+6]}function ya(n,e){return e[n+7]}let ga,pi,zr,va;const Xl=Math.pow(2,32);function Vn(n){return"count"in n?1:1+Vn(n.left)+Vn(n.right)}function Hl(n,e,t){return ga=new Float32Array(t),pi=new Uint32Array(t),zr=new Uint16Array(t),va=new Uint8Array(t),Jn(n,e)}function Jn(n,e){const t=n/4,i=n/2,r="count"in e,s=e.boundingData;for(let a=0;a<6;a++)ga[t+a]=s[a];if(r)if(e.buffer){const a=e.buffer;va.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=gi){const l=o/2;be(l,zr)||(pi[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return pi[t+6]=a,zr[i+14]=o,zr[i+15]=Xr,n+gi}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Jn(n+gi,a),l/4>Xl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return pi[t+6]=l/4,l=Jn(l,o),pi[t+7]=c,l}}function Wl(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,i=t>2**16,r=i?4:2,s=e?new SharedArrayBuffer(t*r):new ArrayBuffer(t*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 Yl(n,e,t,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?ql:$l,_=Wt(f),p=new Float32Array(6);let m=!1;const v=new vn;return gn(e,t,i,v.boundingData,p),b(v,t,i,p),v;function g(x){l&&l(x/_)}function b(x,S,T,w=null,P=0){if(!m&&P>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(f))),T<=o||P>=s)return g(S+T),x.offset=S,x.count=T,x;const C=Gl(x.boundingData,w,e,S,T,c);if(C.axis===-1)return g(S+T),x.offset=S,x.count=T,x;const R=y(h,d,e,S,T,C);if(R===S||R===S+T)g(S+T),x.offset=S,x.count=T;else{x.splitAxis=C.axis;const E=new vn,k=S,A=R-S;x.left=E,gn(e,k,A,E.boundingData,p),b(E,k,A,p,P+1);const z=new vn,N=R,L=T-A;x.right=z,gn(e,N,L,z.boundingData,p),b(z,N,L,p,P+1)}return x}}function Zl(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Wl(t,e.useSharedArrayBuffer),Ll(t,e.range)&&!e.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||Dl(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Vl(t),s=e.indirect?pa(t,e.range):ma(t,e.range);n._roots=s.map(a=>{const o=Yl(n,r,a.offset,a.count,e),c=Vn(o),l=new i(gi*c);return Hl(0,o,l),l})}class ut{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,r=-1/0;for(let s=0,a=e.length;s<a;s++){const c=e[s][t];i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}setFromPoints(e,t){let i=1/0,r=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}}ut.prototype.setFromBox=(function(){const n=new M.Vector3;return function(t,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=t.dot(n);a=Math.min(h,a),o=Math.max(h,o)}this.min=a,this.max=o}})();const Kl=(function(){const n=new M.Vector3,e=new M.Vector3,t=new M.Vector3;return function(r,s,a){const o=r.start,c=n,l=s.start,u=e;t.subVectors(o,l),n.subVectors(r.end,r.start),e.subVectors(s.end,s.start);const h=t.dot(u),f=u.dot(c),d=u.dot(u),y=t.dot(c),p=c.dot(c)*d-f*f;let m,v;p!==0?m=(h*f-y*d)/p:m=0,v=(h+m*f)/d,a.x=m,a.y=v}})(),os=(function(){const n=new M.Vector2,e=new M.Vector3,t=new M.Vector3;return function(r,s,a,o){Kl(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=e,d=t;if(r.closestPointToPoint(h,!0,e),s.closestPointToPoint(u,!0,t),f.distanceToSquared(h)<=d.distanceToSquared(u)){a.copy(f),o.copy(h);return}else{a.copy(u),o.copy(d);return}}}})(),Ql=(function(){const n=new M.Vector3,e=new M.Vector3,t=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(t);if(Math.abs(_.distanceToPoint(c))<=o){const m=_.projectPoint(c,e);if(a.containsPoint(m))return!0}return!1}})(),eu=1e-15;function _n(n){return Math.abs(n)<eu}class ke extends M.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M.Vector3),this.satBounds=new Array(4).fill().map(()=>new ut),this.points=[this.a,this.b,this.c],this.sphere=new M.Sphere,this.plane=new M.Plane,this.needsUpdate=!0}intersectsSphere(e){return Ql(e,this)}update(){const e=this.a,t=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(e,t),u.setFromPoints(l,r);const h=s[2],f=a[2];h.subVectors(t,i),f.setFromPoints(h,r);const d=s[3],y=a[3];d.subVectors(i,e),y.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}ke.prototype.closestPointToSegment=(function(){const n=new M.Vector3,e=new M.Vector3,t=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;t.start.copy(l[f]),t.end.copy(l[d]),os(t,r,n,e),u=n.distanceToSquared(e),u<h&&(h=u,s&&s.copy(n),a&&a.copy(e))}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)}})();ke.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new Array(3),i=new ut,r=new ut,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 v=_.points;let g=0,b=-1;for(let x=0;x<3;x++){const{start:S,end:T}=u;S.copy(v[x]),T.copy(v[(x+1)%3]),u.delta(a);const w=_n(p.distanceToPoint(S));if(_n(p.normal.dot(a))&&w){m.copy(u),g=2;break}const P=p.intersectLine(u,d);if(!P&&w&&d.copy(S),(P||w)&&!_n(d.distanceTo(T))){if(g<=1)(g===1?m.start:m.end).copy(d),w&&(b=g);else if(g>=2){(b===1?m.start:m.end).copy(d),g=2;break}if(g++,g===2&&b===-1)break}}return g}return function(p,m=null,v=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(n.copy(p),n.update(),p=n);const g=this.plane,b=p.plane;if(Math.abs(g.normal.dot(b.normal))>1-1e-10){const x=this.satBounds,S=this.satAxes;t[0]=p.a,t[1]=p.b,t[2]=p.c;for(let P=0;P<4;P++){const C=x[P],R=S[P];if(i.setFromPoints(R,t),C.isSeparated(i))return!1}const T=p.satBounds,w=p.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let P=0;P<4;P++){const C=T[P],R=w[P];if(i.setFromPoints(R,e),C.isSeparated(i))return!1}for(let P=0;P<4;P++){const C=S[P];for(let R=0;R<4;R++){const E=w[R];if(s.crossVectors(C,E),i.setFromPoints(s,e),r.setFromPoints(s,t),i.isSeparated(r))return!1}}return m&&(v||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,b,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 S=y(p,g,f);if(S===1&&this.containsPoint(f.end))return m&&(m.start.copy(f.end),m.end.copy(f.end)),!0;if(S!==2)return!1;if(h.delta(o),f.delta(c),o.dot(c)<0){let k=f.start;f.start=f.end,f.end=k}const T=h.start.dot(o),w=h.end.dot(o),P=f.start.dot(o),C=f.end.dot(o),R=w<P,E=T<C;return T!==C&&P!==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)}}})();ke.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();ke.prototype.distanceToTriangle=(function(){const n=new M.Vector3,e=new M.Vector3,t=["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=t[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=t[h],d=t[(h+1)%3];i.set(this[f],this[d]);for(let y=0;y<3;y++){const _=t[y],p=t[(y+1)%3];r.set(a[_],a[p]),os(i,r,n,e);const m=n.distanceToSquared(e);m<u&&(u=m,o&&o.copy(n),c&&c.copy(e))}}return Math.sqrt(u)}})();class de{constructor(e,t,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 ut),this.alignedSatBounds=new Array(3).fill().map(()=>new ut),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}de.prototype.update=(function(){return function(){const e=this.matrix,t=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:t.x,d.y=u?i.y:t.y,d.z=h?i.z:t.z,d.applyMatrix4(e)}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}})();de.prototype.intersectsBox=(function(){const n=new ut;return function(t){this.needsUpdate&&this.update();const i=t.min,r=t.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,t),u.isSeparated(n))return!1}return!0}})();de.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new ut,i=new ut,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;e[0]=a.a,e[1]=a.b,e[2]=a.c;for(let f=0;f<3;f++){const d=o[f],y=c[f];if(t.setFromPoints(y,e),d.isSeparated(t))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(t.setFromPoints(y,h),d.isSeparated(t))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,_),t.setFromPoints(r,e),i.setFromPoints(r,h),t.isSeparated(i))return!1}}return!0}})();de.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();de.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();de.prototype.distanceToBox=(function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new M.Line3),t=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 v=m.distanceToSquared(r);if(v<y&&(y=v,c&&c.copy(m),l&&l.copy(r),v<u))return Math.sqrt(v)}let _=0;for(let p=0;p<3;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){const g=(p+1)%3,b=(p+2)%3,x=m<<g|v<<b,S=1<<p|m<<g|v<<b,T=d[x],w=d[S];e[_].set(T,w);const C=n[p],R=n[g],E=n[b],k=t[_],A=k.start,z=k.end;A[C]=h[C],A[R]=m?h[R]:f[R],A[E]=v?h[E]:f[R],z[C]=f[C],z[R]=m?h[R]:f[R],z[E]=v?h[E]:f[R],_++}for(let p=0;p<=1;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){r.x=p?f.x:h.x,r.y=m?f.y:h.y,r.z=v?f.z:h.z,this.closestPointToPoint(r,i);const g=r.distanceToSquared(i);if(g<y&&(y=g,c&&c.copy(i),l&&l.copy(r),g<u))return Math.sqrt(g)}for(let p=0;p<12;p++){const m=e[p];for(let v=0;v<12;v++){const g=t[v];os(m,g,i,r);const b=i.distanceToSquared(r);if(b<y&&(y=b,c&&c.copy(i),l&&l.copy(r),b<u))return Math.sqrt(b)}}return Math.sqrt(y)}})();class as{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class tu extends as{constructor(){super(()=>new ke)}}const Re=new tu;class iu{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const $=new iu;let gt,Gt;const It=[],dr=new as(()=>new M.Box3);function ru(n,e,t,i,r,s){gt=dr.getPrimitive(),Gt=dr.getPrimitive(),It.push(gt,Gt),$.setBuffer(n._roots[e]);const a=Gn(0,n.geometry,t,i,r,s);$.clearBuffer(),dr.releasePrimitive(gt),dr.releasePrimitive(Gt),It.pop(),It.pop();const o=It.length;return o>0&&(Gt=It[o-1],gt=It[o-2]),a}function Gn(n,e,t,i,r=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=$;let u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);return Y(n,o,gt),i(f,d,!1,a,s+n,gt)}else{let C=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=we(E),z=E*2;return Me(E,A)},R=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=Ee(E,A),z=E*2;return Me(E,A)+Pe(z,k)};const f=we(n),d=Ee(n,l);let y=f,_=d,p,m,v,g;if(r&&(v=gt,g=Gt,Y(y,o,v),Y(_,o,g),p=r(v),m=r(g),m<p)){y=d,_=f;const E=p;p=m,m=E,v=g}v||(v=gt,Y(y,o,v));const b=be(y*2,c),x=t(v,b,p,a+1,s+y);let S;if(x===Ln){const E=C(y),A=R(y)-E;S=i(E,A,!0,a+1,s+y,v)}else S=x&&Gn(y,e,t,i,r,s,a+1);if(S)return!0;g=Gt,Y(_,o,g);const T=be(_*2,c),w=t(g,T,m,a+1,s+_);let P;if(w===Ln){const E=C(_),A=R(_)-E;P=i(E,A,!0,a+1,s+_,g)}else P=w&&Gn(_,e,t,i,r,s,a+1);return!!P}}const ni=new M.Vector3,xn=new M.Vector3;function nu(n,e,t={},i=0,r=1/0){const s=i*i,a=r*r;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:u=>(ni.copy(e).clamp(u.min,u.max),ni.distanceToSquared(e)),intersectsBounds:(u,h,f)=>f<o&&f<a,intersectsTriangle:(u,h)=>{u.closestPointToPoint(e,ni);const f=e.distanceToSquared(ni);return f<o&&(xn.copy(ni),o=f,c=h),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(xn):t.point=xn.clone(),t.distance=l,t.faceIndex=c,t}const su=parseInt(M.REVISION)>=169,St=new M.Vector3,Tt=new M.Vector3,Mt=new M.Vector3,pr=new M.Vector2,mr=new M.Vector2,yr=new M.Vector2,Zs=new M.Vector3,Ks=new M.Vector3,Qs=new M.Vector3,si=new M.Vector3;function ou(n,e,t,i,r,s,a,o){let c;if(s===M.BackSide?c=n.intersectTriangle(i,t,e,!0,r):c=n.intersectTriangle(e,t,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 au(n,e,t,i,r,s,a,o,c,l,u){St.fromBufferAttribute(e,s),Tt.fromBufferAttribute(e,a),Mt.fromBufferAttribute(e,o);const h=ou(n,St,Tt,Mt,si,c,l,u);if(h){const f=new M.Vector3;M.Triangle.getBarycoord(si,St,Tt,Mt,f),i&&(pr.fromBufferAttribute(i,s),mr.fromBufferAttribute(i,a),yr.fromBufferAttribute(i,o),h.uv=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),r&&(pr.fromBufferAttribute(r,s),mr.fromBufferAttribute(r,a),yr.fromBufferAttribute(r,o),h.uv1=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),t&&(Zs.fromBufferAttribute(t,s),Ks.fromBufferAttribute(t,a),Qs.fromBufferAttribute(t,o),h.normal=M.Triangle.getInterpolation(si,St,Tt,Mt,Zs,Ks,Qs,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(St,Tt,Mt,d.normal),h.face=d,h.faceIndex=s,su&&(h.barycoord=f)}return h}function Hr(n,e,t,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=au(t,f,d,y,_,c,l,u,e,s,a);return p?(p.faceIndex=i,r&&r.push(p),p):null}function te(n,e,t,i){const r=n.a,s=n.b,a=n.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.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 cu(n,e,t,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++)Hr(c,e,t,u,s,a,o)}function lu(n,e,t,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=Hr(o,e,t,h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function uu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=u,te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.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]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=3*m,C=3*(m+v);P<C;P++){let R=i[P];const E=r.getX(R),k=r.getY(R),A=r.getZ(R);E<g&&(g=E),E>S&&(S=E),k<b&&(b=k),k>T&&(T=k),A<x&&(x=A),A>w&&(w=A)}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function vt(n,e,t,i,r){let s,a,o,c,l,u;const h=1/t.direction.x,f=1/t.direction.y,d=1/t.direction.z,y=t.origin.x,_=t.origin.y,p=t.origin.z;let m=e[n],v=e[n+3],g=e[n+1],b=e[n+3+1],x=e[n+2],S=e[n+3+2];return h>=0?(s=(m-y)*h,a=(v-y)*h):(s=(v-y)*h,a=(m-y)*h),f>=0?(o=(g-_)*f,c=(b-_)*f):(o=(b-_)*f,c=(g-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),d>=0?(l=(x-p)*d,u=(S-p)*d):(l=(S-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 fu(n,e,t,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;Hr(c,e,t,f,s,a,o)}}function du(n,e,t,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=Hr(o,e,t,c?c[h]:h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function pu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=t.resolveTriangleIndex(u),te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function mu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),jn(0,n,t,i,r,s,a),$.clearBuffer()}function jn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);cu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&jn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&jn(d,e,t,i,r,s,a)}}const yu=["x","y","z"];function gu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=$n(0,n,t,i,r,s);return $.clearBuffer(),a}function $n(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return lu(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=yu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?$n(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?$n(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const gr=new M.Box3,Nt=new ke,Ut=new ke,oi=new M.Matrix4,eo=new de,vr=new de;function vu(n,e,t,i){$.setBuffer(n._roots[e]);const r=qn(0,n,t,i);return $.clearBuffer(),r}function qn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),eo.set(t.boundingBox.min,t.boundingBox.max,i),r=eo),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(oi.copy(i).invert(),t.boundsTree)return Y(n,s,vr),vr.matrix.copy(oi),vr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>vr.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_*3,b=(p+_)*3;g<b;g+=3)if(te(Ut,g,h,f),Ut.needsUpdate=!0,v.intersectsTriangle(Ut))return!0;return!1}});for(let m=_*3,v=(p+_)*3;m<v;m+=3){te(Nt,m,h,f),Nt.a.applyMatrix4(oi),Nt.b.applyMatrix4(oi),Nt.c.applyMatrix4(oi),Nt.needsUpdate=!0;for(let g=0,b=d.count;g<b;g+=3)if(te(Ut,g,d,y),Ut.needsUpdate=!0,Nt.intersectsTriangle(Ut))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,gr),!!(r.intersectsBox(gr)&&qn(u,e,t,i,r)||(Y(h,s,gr),r.intersectsBox(gr)&&qn(h,e,t,i,r)))}}const _r=new M.Matrix4,bn=new de,ai=new de,_u=new M.Vector3,xu=new M.Vector3,bu=new M.Vector3,Su=new M.Vector3;function Tu(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),bn.set(e.boundingBox.min,e.boundingBox.max,t),bn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=_u,_=xu,p=null,m=null;r&&(p=bu,m=Su);let v=1/0,g=null,b=null;return _r.copy(t).invert(),ai.matrix.copy(_r),n.shapecast({boundsTraverseOrder:x=>bn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(ai.min.copy(x.min),ai.max.copy(x.max),ai.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>ai.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){te(d,3*C,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let E=x,k=x+S;E<k;E++){te(f,3*E,l,c),f.needsUpdate=!0;const A=f.distanceToTriangle(d,y,p);if(A<v&&(_.copy(y),m&&m.copy(p),v=A,g=E,b=C),A<s)return!0}}}});{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){te(f,3*C,l,c),f.needsUpdate=!0;const E=f.distanceToTriangle(d,y,p);if(E<v&&(_.copy(y),m&&m.copy(p),v=E,g=C,b=w),E<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(_r),_.applyMatrix4(_r),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Mu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.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]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=m,C=m+v;P<C;P++){const R=3*n.resolveTriangleIndex(P);for(let E=0;E<3;E++){let k=R+E;k=i?i[k]:k;const A=r.getX(k),z=r.getY(k),N=r.getZ(k);A<g&&(g=A),A>S&&(S=A),z<b&&(b=z),z>T&&(T=z),N<x&&(x=N),N>w&&(w=N)}}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function Cu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),Xn(0,n,t,i,r,s,a),$.clearBuffer()}function Xn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);fu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&Xn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&Xn(d,e,t,i,r,s,a)}}const Pu=["x","y","z"];function wu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=Hn(0,n,t,i,r,s);return $.clearBuffer(),a}function Hn(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return du(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=Pu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?Hn(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?Hn(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const xr=new M.Box3,Ft=new ke,Dt=new ke,ci=new M.Matrix4,to=new de,br=new de;function Eu(n,e,t,i){$.setBuffer(n._roots[e]);const r=Wn(0,n,t,i);return $.clearBuffer(),r}function Wn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),to.set(t.boundingBox.min,t.boundingBox.max,i),r=to),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(ci.copy(i).invert(),t.boundsTree)return Y(n,s,br),br.matrix.copy(ci),br.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>br.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_,b=p+_;g<b;g++)if(te(Dt,3*e.resolveTriangleIndex(g),h,f),Dt.needsUpdate=!0,v.intersectsTriangle(Dt))return!0;return!1}});for(let m=_,v=p+_;m<v;m++){const g=e.resolveTriangleIndex(m);te(Ft,3*g,h,f),Ft.a.applyMatrix4(ci),Ft.b.applyMatrix4(ci),Ft.c.applyMatrix4(ci),Ft.needsUpdate=!0;for(let b=0,x=d.count;b<x;b+=3)if(te(Dt,b,d,y),Dt.needsUpdate=!0,Ft.intersectsTriangle(Dt))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,xr),!!(r.intersectsBox(xr)&&Wn(u,e,t,i,r)||(Y(h,s,xr),r.intersectsBox(xr)&&Wn(h,e,t,i,r)))}}const Sr=new M.Matrix4,Sn=new de,li=new de,Ru=new M.Vector3,ku=new M.Vector3,Au=new M.Vector3,zu=new M.Vector3;function Ou(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Sn.set(e.boundingBox.min,e.boundingBox.max,t),Sn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=Ru,_=ku,p=null,m=null;r&&(p=Au,m=zu);let v=1/0,g=null,b=null;return Sr.copy(t).invert(),li.matrix.copy(Sr),n.shapecast({boundsTraverseOrder:x=>Sn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(li.min.copy(x.min),li.max.copy(x.max),li.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree){const T=e.boundsTree;return T.shapecast({boundsTraverseOrder:w=>li.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){const E=T.resolveTriangleIndex(C);te(d,3*E,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let k=x,A=x+S;k<A;k++){const z=n.resolveTriangleIndex(k);te(f,3*z,l,c),f.needsUpdate=!0;const N=f.distanceToTriangle(d,y,p);if(N<v&&(_.copy(y),m&&m.copy(p),v=N,g=k,b=C),N<s)return!0}}}})}else{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){const E=n.resolveTriangleIndex(C);te(f,3*E,l,c),f.needsUpdate=!0;const k=f.distanceToTriangle(d,y,p);if(k<v&&(_.copy(y),m&&m.copy(p),v=k,g=C,b=w),k<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(Sr),_.applyMatrix4(Sr),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Bu(){return typeof SharedArrayBuffer<"u"}const vi=new $.constructor,Jr=new $.constructor,mt=new as(()=>new M.Box3),Lt=new M.Box3,Vt=new M.Box3,Tn=new M.Box3,Mn=new M.Box3;let Cn=!1;function Iu(n,e,t,i){if(Cn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Cn=!0;const r=n._roots,s=e._roots;let a,o=0,c=0;const l=new M.Matrix4().copy(t).invert();for(let u=0,h=r.length;u<h;u++){vi.setBuffer(r[u]),c=0;const f=mt.getPrimitive();Y(0,vi.float32Array,f),f.applyMatrix4(l);for(let d=0,y=s.length;d<y&&(Jr.setBuffer(s[d]),a=Ue(0,0,t,l,i,o,c,0,0,f),Jr.clearBuffer(),c+=s[d].length,!a);d++);if(mt.releasePrimitive(f),vi.clearBuffer(),o+=r[u].length,a)break}return Cn=!1,a}function Ue(n,e,t,i,r,s=0,a=0,o=0,c=0,l=null,u=!1){let h,f;u?(h=Jr,f=vi):(h=vi,f=Jr);const d=h.float32Array,y=h.uint32Array,_=h.uint16Array,p=f.float32Array,m=f.uint32Array,v=f.uint16Array,g=n*2,b=e*2,x=be(g,_),S=be(b,v);let T=!1;if(S&&x)u?T=r(Me(e,m),Pe(e*2,v),Me(n,y),Pe(n*2,_),c,a+e,o,s+n):T=r(Me(n,y),Pe(n*2,_),Me(e,m),Pe(e*2,v),o,s+n,c,a+e);else if(S){const w=mt.getPrimitive();Y(e,p,w),w.applyMatrix4(t);const P=we(n),C=Ee(n,y);Y(P,d,Lt),Y(C,d,Vt);const R=w.intersectsBox(Lt),E=w.intersectsBox(Vt);T=R&&Ue(e,P,i,t,r,a,s,c,o+1,w,!u)||E&&Ue(e,C,i,t,r,a,s,c,o+1,w,!u),mt.releasePrimitive(w)}else{const w=we(e),P=Ee(e,m);Y(w,p,Tn),Y(P,p,Mn);const C=l.intersectsBox(Tn),R=l.intersectsBox(Mn);if(C&&R)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u)||Ue(n,P,t,i,r,s,a,o,c+1,l,u);else if(C)if(x)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Tn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(w,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(w,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}else if(R)if(x)T=Ue(n,P,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Mn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(P,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(P,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}}return T}const Tr=new de,io=new M.Box3,Nu={strategy:ss,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class tr{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,r=e._roots,s=e._indirectBuffer,a=i.getIndex();let o;return t.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(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:r,roots:s,indirectBuffer:a}=e,o=new tr(t,{...i,[yn]:!0});if(o._roots=s,o._indirectBuffer=a||null,i.setIndex){const c=t.getIndex();if(c===null){const l=new M.BufferAttribute(e.index,1,!1);t.setIndex(l)}else c.array!==r&&(c.array.set(r),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Nu,[yn]:!1},t),t.useSharedArrayBuffer&&!Bu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[yn]||(Zl(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new M.Box3))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Mu:hu)(this,e)}traverse(e,t=0){const i=this._roots[t],r=new Uint32Array(i),s=new Uint16Array(i);a(0);function a(o,c=0){const l=o*2,u=s[l+15]===Xr;if(u){const h=r[o+6],f=s[l+14];e(c,u,new Float32Array(i,o*4,6),h,f)}else{const h=o+gi/4,f=r[o+6],d=r[o+7];e(c,u,new Float32Array(i,o*4,6),d)||(a(h,c+1),a(f,c+1))}}}raycast(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),u=a.groups,h=c?t.side:t,f=this.indirect?Cu:mu;for(let d=0,y=s.length;d<y;d++){const _=l?t[u[d].materialIndex].side:h,p=o.length;if(f(this,d,_,e,o,i,r),l){const m=u[d].materialIndex;for(let v=p,g=o.length;v<g;v++)o[v].face.materialIndex=m}}return o}raycastFirst(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const u=a.groups,h=o?t.side:t,f=this.indirect?wu:gu;for(let d=0,y=s.length;d<y;d++){const _=c?t[u[d].materialIndex].side:h,p=f(this,d,_,e,i,r);p!=null&&(l==null||p.distance<l.distance)&&(l=p,c&&(p.face.materialIndex=u[d].materialIndex))}return l}intersectsGeometry(e,t){let i=!1;const r=this._roots,s=this.indirect?Eu:vu;for(let a=0,o=r.length;a<o&&(i=s(this,a,e,t),!i);a++);return i}shapecast(e){const t=Re.getPrimitive(),i=this.indirect?pu:uu;let{boundsTraverseOrder:r,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const h=a;a=(f,d,y,_,p)=>h(f,d,y,_,p)?!0:i(f,d,this,o,y,_,t)}else a||(o?a=(h,f,d,y)=>i(h,f,this,o,d,y,t):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=ru(this,h,s,a,r,l),c)break;l+=d.byteLength}return Re.releasePrimitive(t),c}bvhcast(e,t,i){let{intersectsRanges:r,intersectsTriangles:s}=i;const a=Re.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const _=this.resolveTriangleIndex(y);te(a,_*3,o,c)}:y=>{te(a,y*3,o,c)},u=Re.getPrimitive(),h=e.geometry.index,f=e.geometry.attributes.position,d=e.indirect?y=>{const _=e.resolveTriangleIndex(y);te(u,_*3,h,f)}:y=>{te(u,y*3,h,f)};if(s){const y=(_,p,m,v,g,b,x,S)=>{for(let T=m,w=m+v;T<w;T++){d(T),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let P=_,C=_+p;P<C;P++)if(l(P),a.needsUpdate=!0,s(a,u,P,T,g,b,x,S))return!0}return!1};if(r){const _=r;r=function(p,m,v,g,b,x,S,T){return _(p,m,v,g,b,x,S,T)?!0:y(p,m,v,g,b,x,S,T)}}else r=y}return Iu(this,e,t,r)}intersectsBox(e,t){return Tr.set(e.min,e.max,t),Tr.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Tr.intersectsBox(i),intersectsTriangle:i=>Tr.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},r={},s=0,a=1/0){return(this.indirect?Ou:Tu)(this,e,t,i,r,s,a)}closestPointToPoint(e,t={},i=0,r=1/0){return nu(this,e,t,i,r)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),io),e.union(io)}),e}}function ro(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Mr=new M.Ray,no=new M.Vector3,so=new M.Matrix4,Uu=M.Mesh.prototype.raycast,Fu=M.BatchedMesh.prototype.raycast,oo=new M.Vector3,ce=new M.Mesh,Cr=[];function Du(n,e){this.isBatchedMesh?Lu.call(this,n,e):Vu.call(this,n,e)}function Lu(n,e){if(this.boundsTrees){const t=this.boundsTrees,i=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ce.material=this.material,ce.geometry=this.geometry;const a=ce.geometry.boundsTree,o=ce.geometry.drawRange;ce.geometry.boundingSphere===null&&(ce.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(ce.geometry.boundsTree=t[u],this.getMatrixAt(c,ce.matrixWorld).premultiply(s),!ce.geometry.boundsTree){this.getBoundingBoxAt(u,ce.geometry.boundingBox),this.getBoundingSphereAt(u,ce.geometry.boundingSphere);const h=r[u];ce.geometry.setDrawRange(h.start,h.count)}ce.raycast(n,Cr);for(let h=0,f=Cr.length;h<f;h++){const d=Cr[h];d.object=this,d.batchId=c,e.push(d)}Cr.length=0}ce.geometry.boundsTree=a,ce.geometry.drawRange=o,ce.material=null,ce.geometry=null}else Fu.call(this,n,e)}function Vu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;so.copy(this.matrixWorld).invert(),Mr.copy(n.ray).applyMatrix4(so),oo.setFromMatrixScale(this.matrixWorld),no.copy(Mr.direction).multiply(oo);const t=no.length(),i=n.near/t,r=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=ro(s.raycastFirst(Mr,this.material,i,r),this,n);a&&e.push(a)}else{const a=s.raycast(Mr,this.material,i,r);for(let o=0,c=a.length;o<c;o++){const l=ro(a[o],this,n);l&&e.push(l)}}}else Uu.call(this,n,e)}function Ju(n={}){return this.boundsTree=new tr(this,n),this.boundsTree}const Ct=new M.Vector3,Pt=new M.Vector3,wt=new M.Vector3,ao=new M.Vector4,Pr=new M.Vector3,Pn=new M.Vector3,co=new M.Vector4,lo=new M.Vector4,wr=new M.Matrix4,uo=new M.Matrix4;function ui(n,e){if(!n&&!e)return;const t=n.count===e.count,i=n.normalized===e.normalized,r=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!i||!r||!s)throw new Error}function mi(n,e=null){const t=n.array.constructor,i=n.normalized,r=n.itemSize,s=e===null?n.count:e;return new M.BufferAttribute(new t(r*s),r,i)}function _a(n,e,t=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let r=0,s=n.count;r<s;r++){const a=r+t;e.setX(a,n.getX(r)),i>=2&&e.setY(a,n.getY(r)),i>=3&&e.setZ(a,n.getZ(r)),i>=4&&e.setW(a,n.getW(r))}}else{const i=e.array,r=i.constructor,s=i.BYTES_PER_ELEMENT*n.itemSize*t;new r(i.buffer,s,n.array.length).set(n.array)}}function Gu(n,e,t){const i=n.elements,r=e.elements;for(let s=0,a=r.length;s<a;s++)i[s]+=r[s]*t}function ho(n,e,t){const i=n.skeleton,r=n.geometry,s=i.bones,a=i.boneInverses;co.fromBufferAttribute(r.attributes.skinIndex,e),lo.fromBufferAttribute(r.attributes.skinWeight,e),wr.elements.fill(0);for(let o=0;o<4;o++){const c=lo.getComponent(o);if(c!==0){const l=co.getComponent(o);uo.multiplyMatrices(s[l].matrixWorld,a[l]),Gu(wr,uo,c)}}return wr.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(wr),t}function wn(n,e,t,i,r){Pr.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(Pn.fromBufferAttribute(c,i),t?Pr.addScaledVector(Pn,o):Pr.addScaledVector(Pn.sub(r),o))}r.add(Pr)}function ju(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new M.BufferGeometry){const i=n[0].index!==null,{useGroups:r=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.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");t.addGroup(l,d,u),l+=d}}if(i){let u=!1;if(!t.index){let h=0;for(let f=0;f<n.length;++f)h+=n[f].index.count;t.setIndex(new M.BufferAttribute(new Uint32Array(h),1,!1)),u=!0}if(s||u){const h=t.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 t.attributes)){let y=0;for(const _ in h)y+=h[_].count;t.setAttribute(u,mi(c[u][0],y))}const f=t.attributes[u];let d=0;for(let y=0,_=h.length;y<_;y++){const p=h[y];a[y]!==!0&&_a(p,f,d),d+=p.count}}return t}function $u(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,i=n.length;t<i;t++)if(n[t]!==e[t])return!1;return!0}function qu(n){const{index:e,attributes:t}=n;if(e)for(let i=0,r=e.count;i<r;i+=3){const s=e.getX(i),a=e.getX(i+2);e.setX(i,a),e.setX(i+2,s)}else for(const i in t){const r=t[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 Xu{constructor(e){this.matrixWorld=new M.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,i=e.skeleton,r=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.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 e=this.mesh,t=e.geometry,i=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&$u(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class Hu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(i=>{i.traverseVisible(r=>{r.isMesh&&t.push(r)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new M.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new M.BufferGeometry){let t=[];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),t.push(!1),h?h.update():a.set(l,new Xu(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new M.BufferAttribute(new Float32Array(0),4,!1))}else ju(s,{useGroups:r,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new M.BufferGeometry){const i=e.geometry,r=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=i.attributes,c=t.attributes;!t.index&&i.index&&(t.index=i.index.clone()),c.position||t.setAttribute("position",mi(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",mi(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",mi(o.tangent)),ui(i.index,t.index),ui(o.position,c.position),s&&ui(o.normal,c.normal),a&&ui(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=e.morphTargetInfluences,m=new M.Matrix3;m.getNormalMatrix(e.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let v=0,g=o.position.count;v<g;v++)Ct.fromBufferAttribute(l,v),u&&Pt.fromBufferAttribute(u,v),h&&(ao.fromBufferAttribute(h,v),wt.fromBufferAttribute(h,v)),p&&(f&&wn(f,p,_,v,Ct),d&&wn(d,p,_,v,Pt),y&&wn(y,p,_,v,wt)),e.isSkinnedMesh&&(e.applyBoneTransform(v,Ct),u&&ho(e,v,Pt),h&&ho(e,v,wt)),r&&Ct.applyMatrix4(e.matrixWorld),c.position.setXYZ(v,Ct.x,Ct.y,Ct.z),u&&(r&&Pt.applyNormalMatrix(m),c.normal.setXYZ(v,Pt.x,Pt.y,Pt.z)),h&&(r&&wt.transformDirection(e.matrixWorld),c.tangent.setXYZW(v,wt.x,wt.y,wt.z,ao.w));for(const v in this.attributes){const g=this.attributes[v];g==="position"||g==="tangent"||g==="normal"||!(g in o)||(c[g]||t.setAttribute(g,mi(o[g])),ui(o[g],c[g]),_a(o[g],c[g]))}return e.matrixWorld.determinant()<0&&qu(t),t}}const Wu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:fa,CENTER:ss,CONTAINED:Ln,ExtendedTriangle:ke,MeshBVH:tr,OrientedBox:de,SAH:da,StaticGeometryGenerator:Hu,acceleratedRaycast:Du,computeBoundsTree:Ju},Symbol.toStringTag,{value:"Module"}));class Yu{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){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 t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const Ce={node:"node",material:"material",camera:"camera",light:"light"},Et="KHR_animation_pointer",Zu={CUBICSPLINE:void 0,LINEAR:M.InterpolateLinear,STEP:M.InterpolateDiscrete};class Ku{constructor(e){this.name=Et,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,i=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",i)}loadAnimationTargetFromChannelWithAnimationPointer(e){eh();const t=e.target,i=t.extensions&&t.extensions[Et]&&t.path&&t.path==="pointer";if(!i)return null;let r,s=Ce.node,a;if(i){const c=t.extensions[Et];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=Ce.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=Ce.light:l.startsWith("/cameras/")&&(s=Ce.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case Ce.material:const u=("/materials/"+a.toString()+"/").length,h=l.substring(0,u);switch(r=l.substring(u),r){case"pbrMetallicRoughness/baseColorFactor":r="color";break;case"pbrMetallicRoughness/roughnessFactor":r="roughness";break;case"pbrMetallicRoughness/metallicFactor":r="metalness";break;case"emissiveFactor":r="emissive";break;case"alphaCutoff":r="alphaTest";break;case"occlusionTexture/strength":r="aoMapIntensity";break;case"normalTexture/scale":r="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":r="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":r="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":r="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":r="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":r="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":r="transmission";break;case"extensions/KHR_materials_ior/ior":r="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":r="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":r="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":r="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":r="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":r="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":r="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":r="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":r="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":r="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":r="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":r="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":r="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":r="specularColor";break}l=h+r;break;case Ce.node:const f=("/nodes/"+a.toString()+"/").length,d=l.substring(0,f);switch(r=l.substring(f),r){case"translation":r="position";break;case"rotation":r="quaternion";break;case"scale":r="scale";break;case"weights":r="morphTargetInfluences";break}l=d+r;break;case Ce.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(r=l.substring(y),r){case"color":break;case"intensity":break;case"spot/innerConeAngle":r="penumbra";break;case"spot/outerConeAngle":r="angle";break;case"range":r="distance";break}l="/lights/"+a.toString()+"/"+r;break;case Ce.camera:const _=("/cameras/"+a.toString()+"/").length,p=l.substring(0,_);switch(r=l.substring(_),r){case"perspective/yfov":r="fov";break;case"perspective/znear":case"orthographic/znear":r="near";break;case"perspective/zfar":case"orthographic/zfar":r="far";break;case"perspective/aspect":r="aspect";break;case"orthographic/xmag":r="zoom";break;case"orthographic/ymag":r="zoom";break}l=p+r;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Et].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===Ce.node?o=this.parser.getDependency("node",a):s===Ce.material?o=this.parser.getDependency("material",a):s===Ce.light?o=this.parser.getDependency("light",a):s===Ce.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,i,r,s){if(!(s.extensions&&s.extensions[Et]&&s.path&&s.path==="pointer"))return null;let o=s.extensions[Et].pointer;if(!o)return null;const c=[];o=o.replaceAll("/",".");const l=o.split(".");var h=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(l[2]=h,l[3]==="morphTargetInfluences"&&e.type==="Group"){for(const d of e.children)d instanceof M.SkinnedMesh&&d.morphTargetInfluences&&(l[3]=d.name,l[4]="morphTargetInfluences",f(this.parser));return c}f(this.parser);function f(d){o=l.join(".");let y;switch(i.itemSize){case 1:y=M.NumberKeyframeTrack;break;case 2:case 3:y=M.VectorKeyframeTrack;break;case 4:o.endsWith(".quaternion")?y=M.QuaternionKeyframeTrack:y=M.ColorKeyframeTrack;break}if(!y){console.warn("Unsupported output accessor format",i);return}const _=r.interpolation!==void 0?Zu[r.interpolation]:M.InterpolateLinear;let p=d._getArrayFromAccessor(i);o.endsWith(".fov")&&(p=p.map(v=>v/Math.PI*180));const m=new y(o,t.array,p,_);if(_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(m),o&&i.itemSize===4&&o.startsWith(".materials.")&&o.endsWith(".color")){const v=new Float32Array(p.length/4);for(let b=0,x=p.length/4;b<x;b+=1)v[b]=p[b*4+3];const g=new y(o.replace(".color",".opacity"),t.array,v,_);_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(g)}}return c}_tryResolveTargetId(e,t){let i="";return t==="node"?i=e.substring(7):t==="material"?i=e.substring(11):t==="light"?i=e.substring(39):t==="camera"&&(i=e.substring(9)),i=i.substring(0,i.indexOf("/")),Number.parseInt(i)}loadAnimation(e){const t=this,i=this.parser.json,r=this.parser,s=i.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],h=[];for(let f=0,d=s.channels.length;f<d;f++){const y=s.channels[f],_=s.samplers[y.sampler],p=y.target,m=s.parameters!==void 0?s.parameters[_.input]:_.input,v=s.parameters!==void 0?s.parameters[_.output]:_.output;let g=t.loadAnimationTargetFromChannelWithAnimationPointer(y);g||(g=t.loadAnimationTargetFromChannel(y)),o.push(g),c.push(r.getDependency("accessor",m)),l.push(r.getDependency("accessor",v)),u.push(_),h.push(p)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(h)]).then(function(f){const d=f[0],y=f[1],_=f[2],p=f[3],m=f[4],v=[];for(let g=0,b=d.length;g<b;g++){const x=d[g],S=y[g],T=_[g],w=p[g],P=m[g];if(x===void 0)continue;x.updateMatrix&&(x.updateMatrix(),x.matrixAutoUpdate=!0);let C=t.createAnimationTracksWithAnimationPointer(x,S,T,w,P);if(C||(C=r._createAnimationTracks(x,S,T,w,P)),C)for(let R=0;R<C.length;R++)v.push(C[R])}return new M.AnimationClip(a,void 0,v)})}}let fo=!1,Qu=null;function eh(){if(fo)return;fo=!0;const n=Qu||=M.PropertyBinding.findNode;M.PropertyBinding.findNode=function(e,t){if(!t)return n(e,t);if(t.startsWith(".materials.")){const i=t.substring(11).substring(t.indexOf(".")),r=i.indexOf("."),s=r<0?i:i.substring(0,r);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(i.endsWith(".map")?a=a.map:i.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const i=t.split(".");let r;for(let s=1;s<i.length;s++){const a=i[s];if(a.length==36)r=e.getObjectByProperty("uuid",a);else if(r&&r[a]){const c=Number.parseInt(a);let l=a;c>=0&&(l=c),r=r[l]}else{const c=e.getObjectByName(a);c&&(r=c)}}if(!r){const s=n(e,i[2]);return s||console.warn(Et+": Property binding not found",t,e,e.name,i),s}return r}return n(e,t)}}const th=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Ku},Symbol.toStringTag,{value:"Module"}));exports.$70d766613f57b014$export$2e2bcd8739ae039=ia;exports.BatchedParticleRenderer=Rl;exports.Builder=Yn;exports.ByteBuffer=_i;exports.ConstantColor=At;exports.ConstantValue=F;exports.Matrix4=De;exports.MeshBVH=tr;exports.MotionController=Pa;exports.ParticleSystem=Vr;exports.SIZE_PREFIX_LENGTH=mo;exports.TrailParticle=Dr;exports.Vector4=Se;exports.WorkerBase=Yu;exports.bundler=nc;exports.createNoise4D=Al;exports.fetchProfile=ba;exports.index=Il;exports.index$1=Wu;exports.index$2=th;exports.md5=xc;exports.v5=mc;
|