@needle-tools/engine 4.1.0-beta → 4.1.0-beta.2
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 +15 -0
- package/components.needle.json +1 -1
- package/dist/gltf-progressive.js +103 -102
- package/dist/gltf-progressive.light.js +103 -102
- package/dist/gltf-progressive.light.min.js +6 -6
- package/dist/gltf-progressive.light.umd.cjs +6 -6
- package/dist/gltf-progressive.min.js +6 -6
- package/dist/gltf-progressive.umd.cjs +6 -6
- package/dist/needle-engine.bundle.js +7820 -7561
- package/dist/needle-engine.bundle.light.js +7773 -7514
- package/dist/needle-engine.bundle.light.min.js +131 -132
- package/dist/needle-engine.bundle.light.umd.cjs +134 -135
- package/dist/needle-engine.bundle.min.js +131 -132
- package/dist/needle-engine.bundle.umd.cjs +134 -135
- package/dist/needle-engine.js +596 -590
- package/dist/needle-engine.light.js +596 -590
- package/dist/needle-engine.light.min.js +1 -1
- package/dist/needle-engine.light.umd.cjs +1 -1
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/three-examples.js +26 -26
- package/dist/three-examples.light.js +26 -26
- package/dist/three-examples.light.min.js +1 -1
- package/dist/three-examples.light.umd.cjs +1 -1
- package/dist/three-examples.min.js +1 -1
- package/dist/three-examples.umd.cjs +1 -1
- package/dist/vendor.js +0 -2
- package/dist/vendor.light.js +0 -2
- package/dist/vendor.light.min.js +2 -2
- package/dist/vendor.light.umd.cjs +2 -2
- package/dist/vendor.min.js +2 -2
- package/dist/vendor.umd.cjs +2 -2
- package/lib/engine/engine.d.ts +4 -0
- package/lib/engine/engine.js +12 -0
- package/lib/engine/engine.js.map +1 -0
- package/lib/engine/engine_web_api.d.ts +12 -0
- package/lib/engine/engine_web_api.js +113 -0
- package/lib/engine/engine_web_api.js.map +1 -0
- package/lib/engine/xr/NeedleXRSession.js +3 -0
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/lib/engine-components/FlyControls.d.ts +10 -0
- package/lib/engine-components/FlyControls.js +29 -0
- package/lib/engine-components/FlyControls.js.map +1 -0
- package/lib/engine-components/GroundProjection.d.ts +1 -1
- package/lib/engine-components/GroundProjection.js +39 -32
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +8 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/RigidBody.js +10 -4
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.d.ts +2 -2
- package/lib/engine-components/SpatialTrigger.js +4 -4
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/TransformGizmo.d.ts +7 -1
- package/lib/engine-components/TransformGizmo.js +39 -32
- package/lib/engine-components/TransformGizmo.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js +0 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/particlesystem/ParticleSystemModules.js +1 -1
- package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
- package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
- package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
- package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
- package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
- package/lib/engine-components/webxr/WebXRRig.js +13 -1
- package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
- package/lib/needle-engine.js +5 -5
- package/lib/needle-engine.js.map +1 -1
- package/package.json +3 -3
- package/src/engine/codegen/register_types.ts +2 -2
- package/src/engine/xr/NeedleXRSession.ts +3 -0
- package/src/engine-components/GroundProjection.ts +46 -38
- package/src/engine-components/OrbitControls.ts +8 -0
- package/src/engine-components/RigidBody.ts +11 -5
- package/src/engine-components/SpatialTrigger.ts +6 -6
- package/src/engine-components/TransformGizmo.ts +41 -33
- package/src/engine-components/VideoPlayer.ts +0 -1
- package/src/engine-components/particlesystem/ParticleSystemModules.ts +1 -1
- package/src/engine-components/postprocessing/Effects/Sharpening.ts +16 -7
- package/src/engine-components/webxr/WebXRImageTracking.ts +18 -4
- package/src/engine-components/webxr/WebXRRig.ts +15 -2
- package/src/needle-engine.ts +5 -5
package/dist/vendor.min.js
CHANGED
|
@@ -1010,7 +1010,7 @@ void main() {
|
|
|
1010
1010
|
#include <tile_vertex>
|
|
1011
1011
|
#include <soft_vertex>
|
|
1012
1012
|
}
|
|
1013
|
-
`;function ro(n){return n===0?"uv":`uv${n}`}class Fd extends xl{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=ao,e.fragmentShader=oo}}class Qd extends Sl{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=ao,e.fragmentShader=oo}}
|
|
1013
|
+
`;function ro(n){return n===0?"uv":`uv${n}`}class Fd extends xl{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=ao,e.fragmentShader=oo}}class Qd extends Sl{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=ao,e.fragmentShader=oo}}class Bd extends gr{constructor(e){super(e),this.vector_=new T,this.vector2_=new T,this.vector3_=new T,this.quaternion_=new F,this.quaternion2_=new F,this.quaternion3_=new F,this.rotationMat_=new tt,this.rotationMat2_=new tt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new Yt(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(Ve),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new Yt(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(Ve),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===v.Mesh?(this.rotationBuffer=new Yt(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(Ve),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===v.BillBoard||this.settings.renderMode===v.HorizontalBillBoard||this.settings.renderMode===v.VerticalBillBoard||this.settings.renderMode===v.StretchedBillBoard)&&(this.rotationBuffer=new Yt(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(Ve),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new Yt(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(Ve),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new Yt(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(Ve),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===v.StretchedBillBoard&&(this.velocityBuffer=new Yt(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(Ve),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Ll,this.geometry.setIndex(this.settings.instancingGeometry.getIndex()),this.settings.instancingGeometry.hasAttribute("normal")&&this.geometry.setAttribute("normal",this.settings.instancingGeometry.getAttribute("normal")),this.geometry.setAttribute("position",this.settings.instancingGeometry.getAttribute("position")),this.geometry.setAttribute("uv",this.settings.instancingGeometry.getAttribute("uv")),this.buildExpandableBuffers()}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={},t={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(e.map=new Fe(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new Fe(this.settings.material.alphaTest)),t.USE_UV="";const i=this.settings.uTileCount,s=this.settings.vTileCount;(i>1||s>1)&&(t.UV_TILE="",e.tileCount=new Fe(new di(i,s))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(t.USE_NORMALMAP="",t.NORMALMAP_UV=ro(this.settings.material.normalMap.channel),e.normalMapTransform=new Fe(new tt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=ro(this.settings.material.map.channel),e.mapTransform=new Fe(new tt().copy(this.settings.material.map.matrix))),t.USE_COLOR_ALPHA="";let o;if(this.settings.softParticles){t.SOFT_PARTICLES="";const c=this.settings.softNearFade,r=1/(this.settings.softFarFade-this.settings.softNearFade);e.softParams=new Fe(new di(c,r)),e.depthTexture=new Fe(null);const l=e.projParams=new Fe(new Ce);o=(d,h,u)=>{l.value.set(u.near,u.far,0,0)}}let a=!1;if(this.settings.renderMode===v.BillBoard||this.settings.renderMode===v.VerticalBillBoard||this.settings.renderMode===v.HorizontalBillBoard||this.settings.renderMode===v.Mesh){let c,r;this.settings.renderMode===v.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",c=ao,r=oo,a=!0):(c=Pd,r=so):(c=Ud,r=so),this.settings.renderMode===v.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===v.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===v.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Fd({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Qd({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new fs({uniforms:e,defines:t,vertexShader:c,fragmentShader:r,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest,lights:a}))}else if(this.settings.renderMode===v.StretchedBillBoard)e.speedFactor=new Fe(1),this.material=new fs({uniforms:e,defines:t,vertexShader:wd,fragmentShader:so,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest});else throw new Error("render mode unavailable");this.material&&o&&(this.material.onBeforeRender=o)}update(){let e=0,t=0;this.systems.forEach(i=>{t+=i.particleNum}),t>this.maxParticles&&this.expandBuffers(t),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const s=i.particles,o=i.particleNum,a=this.quaternion2_,c=this.vector2_,r=this.vector3_;i.emitter.matrixWorld.decompose(c,a,r),this.rotationMat_.setFromMatrix4(i.emitter.matrixWorld);for(let l=0;l<o;l++,e++){const d=s[l];if(this.settings.renderMode===v.Mesh){let u;if(i.worldSpace)u=d.rotation;else{let p;d.parentMatrix?p=this.quaternion3_.setFromRotationMatrix(d.parentMatrix):p=a,u=this.quaternion_,u.copy(p).multiply(d.rotation)}this.rotationBuffer.setXYZW(e,u.x,u.y,u.z,u.w)}else(this.settings.renderMode===v.StretchedBillBoard||this.settings.renderMode===v.VerticalBillBoard||this.settings.renderMode===v.HorizontalBillBoard||this.settings.renderMode===v.BillBoard)&&this.rotationBuffer.setX(e,d.rotation);let h;if(i.worldSpace?h=d.position:(h=this.vector_,d.parentMatrix?h.copy(d.position).applyMatrix4(d.parentMatrix):h.copy(d.position).applyMatrix4(i.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,h.x,h.y,h.z),this.colorBuffer.setXYZW(e,d.color.x,d.color.y,d.color.z,d.color.w),i.worldSpace?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):d.parentMatrix?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):this.sizeBuffer.setXYZ(e,d.size.x*Math.abs(r.x),d.size.y*Math.abs(r.y),d.size.z*Math.abs(r.z)),this.uvTileBuffer.setX(e,d.uvTile),this.settings.renderMode===v.StretchedBillBoard&&this.velocityBuffer){let u=i.rendererEmitterSettings.speedFactor;u===0&&(u=.001);const p=i.rendererEmitterSettings.lengthFactor;let m;i.worldSpace?m=d.velocity:(m=this.vector_,d.parentMatrix?(this.rotationMat2_.setFromMatrix4(d.parentMatrix),m.copy(d.velocity).applyMatrix3(this.rotationMat2_)):m.copy(d.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,m.x*u,m.y*u,m.z*u,p)}}}),this.geometry.instanceCount=e,e>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,e*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,e*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,e),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===v.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===v.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===v.StretchedBillBoard||this.settings.renderMode===v.HorizontalBillBoard||this.settings.renderMode===v.VerticalBillBoard||this.settings.renderMode===v.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Ed=`
|
|
1014
1014
|
|
|
1015
1015
|
#include <common>
|
|
1016
1016
|
#include <tile_pars_fragment>
|
|
@@ -1118,7 +1118,7 @@ void main() {
|
|
|
1118
1118
|
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
1119
1119
|
|
|
1120
1120
|
#include <fog_vertex>
|
|
1121
|
-
}`;new T(0,0,1);class Od extends gr{constructor(e){super(e),this.vector_=new T,this.vector2_=new T,this.vector3_=new T,this.quaternion_=new F,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Ot,this.indexBuffer=new be(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(Ve),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new be(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(Ve),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new be(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(Ve),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new be(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(Ve),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new be(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(Ve),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new be(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(Ve),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new be(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(Ve),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new be(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(Ve),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 di(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=ro(this.settings.material.map.channel),e.map=new Fe(this.settings.material.map),e.mapTransform=new Fe(new tt().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===v.Trail)this.material=new fs({uniforms:e,defines:t,vertexShader:jd,fragmentShader:Ed,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Uo,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(s=>{for(let o=0;o<s.particleNum;o++)i+=s.particles[o].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(s=>{s.emitter.updateMatrixWorld&&(s.emitter.updateWorldMatrix(!0,!1),s.emitter.updateMatrixWorld(!0));const o=this.quaternion_,a=this.vector2_,c=this.vector3_;s.emitter.matrixWorld.decompose(a,o,c);const r=s.particles,l=s.particleNum,d=this.settings.uTileCount,h=this.settings.vTileCount,u=1/d,p=1/h;for(let m=0;m<l;m++){const b=r[m],G=b.uvTile%h,y=Math.floor(b.uvTile/h+.001),Z=b.previous.values();let X=Z.next(),L=X.value,V=L;X.done||(X=Z.next());let x;X.value!==void 0?x=X.value:x=V;for(let R=0;R<b.previous.length;R++,e+=2){if(this.positionBuffer.setXYZ(e,V.position.x,V.position.y,V.position.z),this.positionBuffer.setXYZ(e+1,V.position.x,V.position.y,V.position.z),s.worldSpace?(this.positionBuffer.setXYZ(e,V.position.x,V.position.y,V.position.z),this.positionBuffer.setXYZ(e+1,V.position.x,V.position.y,V.position.z)):(b.parentMatrix?this.vector_.copy(V.position).applyMatrix4(b.parentMatrix):this.vector_.copy(V.position).applyMatrix4(s.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)),s.worldSpace?(this.previousBuffer.setXYZ(e,L.position.x,L.position.y,L.position.z),this.previousBuffer.setXYZ(e+1,L.position.x,L.position.y,L.position.z)):(b.parentMatrix?this.vector_.copy(L.position).applyMatrix4(b.parentMatrix):this.vector_.copy(L.position).applyMatrix4(s.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)),s.worldSpace?(this.nextBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.nextBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(b.parentMatrix?this.vector_.copy(x.position).applyMatrix4(b.parentMatrix):this.vector_.copy(x.position).applyMatrix4(s.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),s.worldSpace)this.widthBuffer.setX(e,V.size),this.widthBuffer.setX(e+1,V.size);else if(b.parentMatrix)this.widthBuffer.setX(e,V.size),this.widthBuffer.setX(e+1,V.size);else{const S=(Math.abs(c.x)+Math.abs(c.y)+Math.abs(c.z))/3;this.widthBuffer.setX(e,V.size*S),this.widthBuffer.setX(e+1,V.size*S)}this.uvBuffer.setXY(e,(R/b.previous.length+G)*u,(h-y-1)*p),this.uvBuffer.setXY(e+1,(R/b.previous.length+G)*u,(h-y)*p),this.colorBuffer.setXYZW(e,V.color.x,V.color.y,V.color.z,V.color.w),this.colorBuffer.setXYZW(e+1,V.color.x,V.color.y,V.color.z,V.color.w),R+1<b.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++),L=V,V=x,X.done||(X=Z.next(),X.value!==void 0&&(x=X.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 Ln{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new we;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const s=e.getIndex().array,o=s.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<o;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),s[a*3],s[a*3+1],s[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 K,this._tempB=new K,this._tempC=new K,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 s=0,o=i;const a=Math.random()*this._triangleIndexToArea[i];for(;s+1<o;){const p=Math.floor((s+o)/2);a<this._triangleIndexToArea[p]?o=p:s=p}let c=Math.random(),r=Math.random();c+r>1&&(c=1-c,r=1-r);const l=t.getIndex().array[s*3],d=t.getIndex().array[s*3+1],h=t.getIndex().array[s*3+2],u=t.getAttribute("position");this._tempA.fromBufferAttribute(u,l),this._tempB.fromBufferAttribute(u,d),this._tempC.fromBufferAttribute(u,h),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,c).addScaledVector(this._tempC,r),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 Ln(t.geometries[e.geometry])}clone(){return new Ln(this._geometry)}update(e,t){}}fd({id:"three.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Ln,loadJSON:Ln.fromJSON}],behaviors:[]});class No extends Ss{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 s=0;s<this.batches.length;s++)if(No.equals(this.batches[s].settings,t)){this.batches[s].addSystem(e),this.systemToBatchIndex.set(e,s);return}let i;switch(t.renderMode){case v.Trail:i=new Od(t);break;case v.Mesh:case v.BillBoard:case v.VerticalBillBoard:case v.HorizontalBillBoard:case v.StretchedBillBoard:i=new Bd(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 Dd=No;Yd(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const zr=Math.sqrt(5),_d=(zr-1)/4,ue=(5-zr)/20,jn=n=>Math.floor(n)|0,On=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 Ad(n=Math.random){const e=qd(n),t=new Float64Array(e).map(a=>On[a%32*4]),i=new Float64Array(e).map(a=>On[a%32*4+1]),s=new Float64Array(e).map(a=>On[a%32*4+2]),o=new Float64Array(e).map(a=>On[a%32*4+3]);return function(a,c,r,l){let d,h,u,p,m;const b=(a+c+r+l)*_d,G=jn(a+b),y=jn(c+b),Z=jn(r+b),X=jn(l+b),L=(G+y+Z+X)*ue,V=G-L,x=y-L,R=Z-L,S=X-L,W=a-V,f=c-x,C=r-R,g=l-S;let z=0,Y=0,k=0,N=0;W>f?z++:Y++,W>C?z++:k++,W>g?z++:N++,f>C?Y++:k++,f>g?Y++:N++,C>g?k++:N++;const Q=z>=3?1:0,P=Y>=3?1:0,ae=k>=3?1:0,ie=N>=3?1:0,ee=z>=2?1:0,ze=Y>=2?1:0,Se=k>=2?1:0,ne=N>=2?1:0,me=z>=1?1:0,te=Y>=1?1:0,O=k>=1?1:0,mt=N>=1?1:0,_=W-Q+ue,Oe=f-P+ue,it=C-ae+ue,ft=g-ie+ue,Wt=W-ee+2*ue,gt=f-ze+2*ue,Ct=C-Se+2*ue,zt=g-ne+2*ue,vt=W-me+3*ue,Kt=f-te+3*ue,Mt=C-O+3*ue,Tt=g-mt+3*ue,nt=W-1+4*ue,st=f-1+4*ue,ot=C-1+4*ue,at=g-1+4*ue,Ne=G&255,Ie=y&255,Je=Z&255,Ue=X&255;let Pe=.6-W*W-f*f-C*C-g*g;if(Pe<0)d=0;else{const D=Ne+e[Ie+e[Je+e[Ue]]];Pe*=Pe,d=Pe*Pe*(t[D]*W+i[D]*f+s[D]*C+o[D]*g)}let w=.6-_*_-Oe*Oe-it*it-ft*ft;if(w<0)h=0;else{const D=Ne+Q+e[Ie+P+e[Je+ae+e[Ue+ie]]];w*=w,h=w*w*(t[D]*_+i[D]*Oe+s[D]*it+o[D]*ft)}let pi=.6-Wt*Wt-gt*gt-Ct*Ct-zt*zt;if(pi<0)u=0;else{const D=Ne+ee+e[Ie+ze+e[Je+Se+e[Ue+ne]]];pi*=pi,u=pi*pi*(t[D]*Wt+i[D]*gt+s[D]*Ct+o[D]*zt)}let mi=.6-vt*vt-Kt*Kt-Mt*Mt-Tt*Tt;if(mi<0)p=0;else{const D=Ne+me+e[Ie+te+e[Je+O+e[Ue+mt]]];mi*=mi,p=mi*mi*(t[D]*vt+i[D]*Kt+s[D]*Mt+o[D]*Tt)}let bi=.6-nt*nt-st*st-ot*ot-at*at;if(bi<0)m=0;else{const D=Ne+1+e[Ie+1+e[Je+1+e[Ue+1]]];bi*=bi,m=bi*bi*(t[D]*nt+i[D]*st+s[D]*ot+o[D]*at)}return 27*(d+h+u+p+m)}}function qd(n){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const i=t+~~(n()*(256-t)),s=e[t];e[t]=e[i],e[i]=s}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class $d{constructor(e){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Backoff must be a positive integer");this.backoff=e}get retries(){return this._retries}get current(){return this.backoff}next(){return this._retries++,this.backoff}reset(){this._retries=0}}class eh{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}}class th{constructor(e,t,i){if(this.i=0,this._retries=0,e<0)throw new Error("Initial must be a positive number or zero");if(t<0)throw new Error("Increment must be a positive number or zero");if(i!==void 0&&i<0)throw new Error("Max must be undefined, a positive number or zero");if(i!==void 0&&i<e)throw new Error("Max must be undefined or greater than or equal to initial");this.initial=e,this.increment=t,this.max=i}get retries(){return this._retries}get current(){return this.max===void 0?this.initial+this.increment*this.i:Math.min(this.initial+this.increment*this.i,this.max)}next(){return this._retries++,this.i++,this.current}reset(){this._retries=0,this.i=0}}class ih{constructor(){this.elements=[]}add(e){this.elements.push(e)}clear(){this.elements.length=0}forEach(e){this.elements.forEach(e)}length(){return this.elements.length}isEmpty(){return this.elements.length===0}peek(){return this.elements[0]}read(){return this.elements.shift()}}class nh{constructor(e){if(!Number.isInteger(e)||e<=0)throw new Error("Capacity must be a positive integer");this.elements=new Array(e+1),this.head=0,this.tail=0}add(e){this.elements[this.head]=e,this.head=(this.head+1)%this.elements.length,this.head===this.tail&&(this.tail=(this.tail+1)%this.elements.length)}clear(){this.head=0,this.tail=0}forEach(e){for(let t=this.tail;t!==this.head;t=(t+1)%this.elements.length)e(this.elements[t])}length(){return this.tail===this.head?0:this.tail<this.head?this.head-this.tail:this.elements.length-this.tail+this.head}isEmpty(){return this.head===this.tail}peek(){return this.isEmpty()?void 0:this.elements[this.tail]}read(){const e=this.peek();return e!==void 0&&(this.tail=(this.tail+1)%this.elements.length),e}}var B;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(B||(B={}));class vr{constructor(e,t,i){var s,o,a,c,r,l,d,h,u,p,m,b,G,y,Z;this._closedByUser=!1,this.handleOpenEvent=X=>this.handleEvent(B.open,X),this.handleErrorEvent=X=>this.handleEvent(B.error,X),this.handleCloseEvent=X=>this.handleEvent(B.close,X),this.handleMessageEvent=X=>this.handleEvent(B.message,X),this._url=e,this._protocols=t,this._options={buffer:i?.buffer,retry:{maxRetries:(s=i?.retry)===null||s===void 0?void 0:s.maxRetries,instantReconnect:(o=i?.retry)===null||o===void 0?void 0:o.instantReconnect,backoff:(a=i?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(r=(c=i?.listeners)===null||c===void 0?void 0:c.open)!==null&&r!==void 0?r:[]],close:[...(d=(l=i?.listeners)===null||l===void 0?void 0:l.close)!==null&&d!==void 0?d:[]],error:[...(u=(h=i?.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[]],message:[...(m=(p=i?.listeners)===null||p===void 0?void 0:p.message)!==null&&m!==void 0?m:[]],retry:[...(G=(b=i?.listeners)===null||b===void 0?void 0:b.retry)!==null&&G!==void 0?G:[]],reconnect:[...(Z=(y=i?.listeners)===null||y===void 0?void 0:y.reconnect)!==null&&Z!==void 0?Z:[]]}},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 s=o=>o.listener!==t||o.options!==i;this._options.listeners[e]=this._options.listeners[e].filter(s)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(B.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(B.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(B.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(B.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(B.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(B.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(B.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(B.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const i=this._options.listeners[e],s=[];i.forEach(({listener:o,options:a})=>{o(this,t),(a===void 0||a.once===void 0||!a.once)&&s.push({listener:o,options:a})}),this._options.listeners[e]=s}handleEvent(e,t){switch(e){case B.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case B.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},s=new CustomEvent(B.reconnect,{detail:i});this.dispatchEvent(B.reconnect,s),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case B.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 s=new CustomEvent(B.retry,{detail:i});this.handleEvent(B.retry,s)},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 sh{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(B.open,e,t),this}onClose(e,t){return this.addListener(B.close,e,t),this}onError(e,t){return this.addListener(B.error,e,t),this}onMessage(e,t){return this.addListener(B.message,e,t),this}onRetry(e,t){return this.addListener(B.retry,e,t),this}onReconnect(e,t){return this.addListener(B.reconnect,e,t),this}build(){return new vr(this._url,this._protocols,this._options)}addListener(e,t,i){var s,o,a,c,r,l,d,h,u,p,m,b,G,y,Z,X,L,V,x,R,S;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(o=(s=this._options)===null||s===void 0?void 0:s.listeners)===null||o===void 0?void 0:o.open)!==null&&a!==void 0?a:[],close:(l=(r=(c=this._options)===null||c===void 0?void 0:c.listeners)===null||r===void 0?void 0:r.close)!==null&&l!==void 0?l:[],error:(u=(h=(d=this._options)===null||d===void 0?void 0:d.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[],message:(b=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.message)!==null&&b!==void 0?b:[],retry:(Z=(y=(G=this._options)===null||G===void 0?void 0:G.listeners)===null||y===void 0?void 0:y.retry)!==null&&Z!==void 0?Z:[],reconnect:(V=(L=(X=this._options)===null||X===void 0?void 0:X.listeners)===null||L===void 0?void 0:L.reconnect)!==null&&V!==void 0?V:[],[e]:[...(S=(R=(x=this._options)===null||x===void 0?void 0:x.listeners)===null||R===void 0?void 0:R[e])!==null&&S!==void 0?S:[],{listener:t,options:i}]}}),this}}const oh=Object.freeze(Object.defineProperty({__proto__:null,ArrayQueue:ih,ConstantBackoff:$d,ExponentialBackoff:eh,LinearBackoff:th,RingQueue:nh,Websocket:vr,WebsocketBuilder:sh,get WebsocketEvent(){return B}},Symbol.toStringTag,{value:"Module"})),lo=0,Kr=1,Mr=2,ah=0,rh=1,co=2,Dn=1.25,ho=1,Zt=6*4+4+4,_n=65535,lh=Math.pow(2,-24),uo=Symbol("SKIP_GENERATION");function Tr(n){return n.index?n.index.count:n.attributes.position.count}function ei(n){return Tr(n)/3}function Yr(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function ch(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Yr(t,i);n.setIndex(new be(s,1));for(let o=0;o<t;o++)s[o]=o}}function Hr(n,e){const t=ei(n),i=e||n.drawRange,s=i.start/3,o=(i.start+i.count)/3,a=Math.max(0,s),c=Math.min(t,o)-a;return[{offset:Math.floor(a),count:Math.floor(c)}]}function kr(n,e){if(!n.groups||!n.groups.length)return Hr(n,e);const t=[],i=new Set,s=e||n.drawRange,o=s.start/3,a=(s.start+s.count)/3;for(const r of n.groups){const l=r.start/3,d=(r.start+r.count)/3;i.add(Math.max(o,l)),i.add(Math.min(a,d))}const c=Array.from(i.values()).sort((r,l)=>r-l);for(let r=0;r<c.length-1;r++){const l=c[r],d=c[r+1];t.push({offset:Math.floor(l),count:Math.floor(d-l)})}return t}function dh(n,e){const t=ei(n),i=kr(n,e).sort((a,c)=>a.offset-c.offset),s=i[i.length-1];s.count=Math.min(t-s.offset,s.count);let o=0;return i.forEach(({count:a})=>o+=a),t!==o}function po(n,e,t,i,s){let o=1/0,a=1/0,c=1/0,r=-1/0,l=-1/0,d=-1/0,h=1/0,u=1/0,p=1/0,m=-1/0,b=-1/0,G=-1/0;for(let y=e*6,Z=(e+t)*6;y<Z;y+=6){const X=n[y+0],L=n[y+1],V=X-L,x=X+L;V<o&&(o=V),x>r&&(r=x),X<h&&(h=X),X>m&&(m=X);const R=n[y+2],S=n[y+3],W=R-S,f=R+S;W<a&&(a=W),f>l&&(l=f),R<u&&(u=R),R>b&&(b=R);const C=n[y+4],g=n[y+5],z=C-g,Y=C+g;z<c&&(c=z),Y>d&&(d=Y),C<p&&(p=C),C>G&&(G=C)}i[0]=o,i[1]=a,i[2]=c,i[3]=r,i[4]=l,i[5]=d,s[0]=h,s[1]=u,s[2]=p,s[3]=m,s[4]=b,s[5]=G}function hh(n,e=null,t=null,i=null){const s=n.attributes.position,o=n.index?n.index.array:null,a=ei(n),c=s.normalized;let r;e===null?(r=new Float32Array(a*6),t=0,i=a):(r=e,t=t||0,i=i||a);const l=s.array,d=s.offset||0;let h=3;s.isInterleavedBufferAttribute&&(h=s.data.stride);const u=["getX","getY","getZ"];for(let p=t;p<t+i;p++){const m=p*3,b=p*6;let G=m+0,y=m+1,Z=m+2;o&&(G=o[G],y=o[y],Z=o[Z]),c||(G=G*h+d,y=y*h+d,Z=Z*h+d);for(let X=0;X<3;X++){let L,V,x;c?(L=s[u[X]](G),V=s[u[X]](y),x=s[u[X]](Z)):(L=l[G+X],V=l[y+X],x=l[Z+X]);let R=L;V<R&&(R=V),x<R&&(R=x);let S=L;V>S&&(S=V),x>S&&(S=x);const W=(S-R)/2,f=X*2;r[b+f+0]=R+W,r[b+f+1]=W+(Math.abs(R)+W)*lh}}return r}function E(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 Nr(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=n[i+3]-n[i];s>t&&(t=s,e=i)}return e}function Ir(n,e){e.set(n)}function Jr(n,e,t){let i,s;for(let o=0;o<3;o++){const a=o+3;i=n[o],s=e[o],t[o]=i<s?i:s,i=n[a],s=e[a],t[a]=i>s?i:s}}function An(n,e,t){for(let i=0;i<3;i++){const s=e[n+2*i],o=e[n+2*i+1],a=s-o,c=s+o;a<t[i]&&(t[i]=a),c>t[i+3]&&(t[i+3]=c)}}function vi(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 ht=32,uh=(n,e)=>n.candidate-e.candidate,Xt=new Array(ht).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),qn=new Float32Array(6);function ph(n,e,t,i,s,o){let a=-1,c=0;if(o===lo)a=Nr(e),a!==-1&&(c=(e[a]+e[a+3])/2);else if(o===Kr)a=Nr(n),a!==-1&&(c=mh(t,i,s,a));else if(o===Mr){const r=vi(n);let l=Dn*s;const d=i*6,h=(i+s)*6;for(let u=0;u<3;u++){const p=e[u],m=(e[u+3]-p)/ht;if(s<ht/4){const b=[...Xt];b.length=s;let G=0;for(let Z=d;Z<h;Z+=6,G++){const X=b[G];X.candidate=t[Z+2*u],X.count=0;const{bounds:L,leftCacheBounds:V,rightCacheBounds:x}=X;for(let R=0;R<3;R++)x[R]=1/0,x[R+3]=-1/0,V[R]=1/0,V[R+3]=-1/0,L[R]=1/0,L[R+3]=-1/0;An(Z,t,L)}b.sort(uh);let y=s;for(let Z=0;Z<y;Z++){const X=b[Z];for(;Z+1<y&&b[Z+1].candidate===X.candidate;)b.splice(Z+1,1),y--}for(let Z=d;Z<h;Z+=6){const X=t[Z+2*u];for(let L=0;L<y;L++){const V=b[L];X>=V.candidate?An(Z,t,V.rightCacheBounds):(An(Z,t,V.leftCacheBounds),V.count++)}}for(let Z=0;Z<y;Z++){const X=b[Z],L=X.count,V=s-X.count,x=X.leftCacheBounds,R=X.rightCacheBounds;let S=0;L!==0&&(S=vi(x)/r);let W=0;V!==0&&(W=vi(R)/r);const f=ho+Dn*(S*L+W*V);f<l&&(a=u,l=f,c=X.candidate)}}else{for(let y=0;y<ht;y++){const Z=Xt[y];Z.count=0,Z.candidate=p+m+y*m;const X=Z.bounds;for(let L=0;L<3;L++)X[L]=1/0,X[L+3]=-1/0}for(let y=d;y<h;y+=6){let Z=~~((t[y+2*u]-p)/m);Z>=ht&&(Z=ht-1);const X=Xt[Z];X.count++,An(y,t,X.bounds)}const b=Xt[ht-1];Ir(b.bounds,b.rightCacheBounds);for(let y=ht-2;y>=0;y--){const Z=Xt[y],X=Xt[y+1];Jr(Z.bounds,X.rightCacheBounds,Z.rightCacheBounds)}let G=0;for(let y=0;y<ht-1;y++){const Z=Xt[y],X=Z.count,L=Z.bounds,V=Xt[y+1].rightCacheBounds;X!==0&&(G===0?Ir(L,qn):Jr(L,qn,qn)),G+=X;let x=0,R=0;G!==0&&(x=vi(qn)/r);const S=s-G;S!==0&&(R=vi(V)/r);const W=ho+Dn*(x*G+R*S);W<l&&(a=u,l=W,c=Z.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:a,pos:c}}function mh(n,e,t,i){let s=0;for(let o=e,a=e+t;o<a;o++)s+=n[o*6+i*2];return s/t}class mo{constructor(){this.boundingData=new Float32Array(6)}}function bh(n,e,t,i,s,o){let a=i,c=i+s-1;const r=o.pos,l=o.axis*2;for(;;){for(;a<=c&&t[a*6+l]<r;)a++;for(;a<=c&&t[c*6+l]>=r;)c--;if(a<c){for(let d=0;d<3;d++){let h=e[a*3+d];e[a*3+d]=e[c*3+d],e[c*3+d]=h}for(let d=0;d<6;d++){let h=t[a*6+d];t[a*6+d]=t[c*6+d],t[c*6+d]=h}a++,c--}else return a}}function yh(n,e,t,i,s,o){let a=i,c=i+s-1;const r=o.pos,l=o.axis*2;for(;;){for(;a<=c&&t[a*6+l]<r;)a++;for(;a<=c&&t[c*6+l]>=r;)c--;if(a<c){let d=n[a];n[a]=n[c],n[c]=d;for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[c*6+h],t[c*6+h]=u}a++,c--}else return a}}function xe(n,e){return e[n+15]===65535}function ge(n,e){return e[n+6]}function Ke(n,e){return e[n+14]}function Ye(n){return n+8}function Me(n,e){return e[n+6]}function bo(n,e){return e[n+7]}let Ur,Ki,$n,Pr;const Gh=Math.pow(2,32);function yo(n){return"count"in n?1:1+yo(n.left)+yo(n.right)}function Zh(n,e,t){return Ur=new Float32Array(t),Ki=new Uint32Array(t),$n=new Uint16Array(t),Pr=new Uint8Array(t),Go(n,e)}function Go(n,e){const t=n/4,i=n/2,s="count"in e,o=e.boundingData;for(let a=0;a<6;a++)Ur[t+a]=o[a];if(s)if(e.buffer){const a=e.buffer;Pr.set(new Uint8Array(a),n);for(let c=n,r=n+a.byteLength;c<r;c+=Zt){const l=c/2;xe(l,$n)||(Ki[c/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,c=e.count;return Ki[t+6]=a,$n[i+14]=c,$n[i+15]=_n,n+Zt}else{const a=e.left,c=e.right,r=e.splitAxis;let l;if(l=Go(n+Zt,a),l/4>Gh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Ki[t+6]=l/4,l=Go(l,c),Ki[t+7]=r,l}}function Xh(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,i=t>2**16,s=i?4:2,o=e?new SharedArrayBuffer(t*s):new ArrayBuffer(t*s),a=i?new Uint32Array(o):new Uint16Array(o);for(let c=0,r=a.length;c<r;c++)a[c]=c;return a}function Vh(n,e,t,i,s){const{maxDepth:o,verbose:a,maxLeafTris:c,strategy:r,onProgress:l,indirect:d}=s,h=n._indirectBuffer,u=n.geometry,p=u.index?u.index.array:null,m=d?yh:bh,b=ei(u),G=new Float32Array(6);let y=!1;const Z=new mo;return po(e,t,i,Z.boundingData,G),L(Z,t,i,G),Z;function X(V){l&&l(V/b)}function L(V,x,R,S=null,W=0){if(!y&&W>=o&&(y=!0,a&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),R<=c||W>=o)return X(x+R),V.offset=x,V.count=R,V;const f=ph(V.boundingData,S,e,x,R,r);if(f.axis===-1)return X(x+R),V.offset=x,V.count=R,V;const C=m(h,p,e,x,R,f);if(C===x||C===x+R)X(x+R),V.offset=x,V.count=R;else{V.splitAxis=f.axis;const g=new mo,z=x,Y=C-x;V.left=g,po(e,z,Y,g.boundingData,G),L(g,z,Y,G,W+1);const k=new mo,N=C,Q=R-Y;V.right=k,po(e,N,Q,k.boundingData,G),L(k,N,Q,G,W+1)}return V}}function Rh(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Xh(t,e.useSharedArrayBuffer),dh(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||ch(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=hh(t),o=e.indirect?Hr(t,e.range):kr(t,e.range);n._roots=o.map(a=>{const c=Vh(n,s,a.offset,a.count,e),r=yo(c),l=new i(Zt*r);return Zh(0,c,l),l})}class ut{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let o=0,a=e.length;o<a;o++){const c=e[o][t];i=c<i?c:i,s=c>s?c:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let o=0,a=t.length;o<a;o++){const c=t[o],r=e.dot(c);i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}ut.prototype.setFromBox=function(){const n=new K;return function(e,t){const i=t.min,s=t.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let r=0;r<=1;r++)for(let l=0;l<=1;l++){n.x=i.x*c+s.x*(1-c),n.y=i.y*r+s.y*(1-r),n.z=i.z*l+s.z*(1-l);const d=e.dot(n);o=Math.min(d,o),a=Math.max(d,a)}this.min=o,this.max=a}}();const Lh=function(){const n=new K,e=new K,t=new K;return function(i,s,o){const a=i.start,c=n,r=s.start,l=e;t.subVectors(a,r),n.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const d=t.dot(l),h=l.dot(c),u=l.dot(l),p=t.dot(c),m=c.dot(c)*u-h*h;let b,G;m!==0?b=(d*h-p*u)/m:b=0,G=(d+b*h)/u,o.x=b,o.y=G}}(),Zo=function(){const n=new De,e=new K,t=new K;return function(i,s,o,a){Lh(i,s,n);let c=n.x,r=n.y;if(c>=0&&c<=1&&r>=0&&r<=1){i.at(c,o),s.at(r,a);return}else if(c>=0&&c<=1){r<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,o);return}else if(r>=0&&r<=1){c<0?i.at(0,o):i.at(1,o),s.closestPointToPoint(o,!0,a);return}else{let l;c<0?l=i.start:l=i.end;let d;r<0?d=s.start:d=s.end;const h=e,u=t;if(i.closestPointToPoint(d,!0,e),s.closestPointToPoint(l,!0,t),h.distanceToSquared(d)<=u.distanceToSquared(l)){o.copy(h),a.copy(d);return}else{o.copy(l),a.copy(u);return}}}}(),xh=function(){const n=new K,e=new K,t=new Po,i=new rt;return function(s,o){const{radius:a,center:c}=s,{a:r,b:l,c:d}=o;if(i.start=r,i.end=l,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a||(i.start=r,i.end=d,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a)||(i.start=l,i.end=d,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a))return!0;const h=o.getPlane(t);if(Math.abs(h.distanceToPoint(c))<=a){const u=h.projectPoint(c,e);if(o.containsPoint(u))return!0}return!1}}(),Sh=1e-15;function Xo(n){return Math.abs(n)<Sh}class He extends we{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new K),this.satBounds=new Array(4).fill().map(()=>new ut),this.points=[this.a,this.b,this.c],this.sphere=new wo,this.plane=new Po,this.needsUpdate=!0}intersectsSphere(e){return xh(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,o=this.satAxes,a=this.satBounds,c=o[0],r=a[0];this.getNormal(c),r.setFromPoints(c,s);const l=o[1],d=a[1];l.subVectors(e,t),d.setFromPoints(l,s);const h=o[2],u=a[2];h.subVectors(t,i),u.setFromPoints(h,s);const p=o[3],m=a[3];p.subVectors(i,e),m.setFromPoints(p,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}He.prototype.closestPointToSegment=function(){const n=new K,e=new K,t=new rt;return function(i,s=null,o=null){const{start:a,end:c}=i,r=this.points;let l,d=1/0;for(let h=0;h<3;h++){const u=(h+1)%3;t.start.copy(r[h]),t.end.copy(r[u]),Zo(t,i,n,e),l=n.distanceToSquared(e),l<d&&(d=l,s&&s.copy(n),o&&o.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<d&&(d=l,s&&s.copy(n),o&&o.copy(a)),this.closestPointToPoint(c,n),l=c.distanceToSquared(n),l<d&&(d=l,s&&s.copy(n),o&&o.copy(c)),Math.sqrt(d)}}(),He.prototype.intersectsTriangle=function(){const n=new He,e=new Array(3),t=new Array(3),i=new ut,s=new ut,o=new K,a=new K,c=new K,r=new K,l=new K,d=new rt,h=new rt,u=new rt,p=new K;function m(b,G,y){const Z=b.points;let X=0,L=-1;for(let V=0;V<3;V++){const{start:x,end:R}=d;x.copy(Z[V]),R.copy(Z[(V+1)%3]),d.delta(a);const S=Xo(G.distanceToPoint(x));if(Xo(G.normal.dot(a))&&S){y.copy(d),X=2;break}const W=G.intersectLine(d,p);if(!W&&S&&p.copy(x),(W||S)&&!Xo(p.distanceTo(R))){if(X<=1)(X===1?y.start:y.end).copy(p),S&&(L=X);else if(X>=2){(L===1?y.start:y.end).copy(p),X=2;break}if(X++,X===2&&L===-1)break}}return X}return function(b,G=null,y=!1){this.needsUpdate&&this.update(),b.isExtendedTriangle?b.needsUpdate&&b.update():(n.copy(b),n.update(),b=n);const Z=this.plane,X=b.plane;if(Math.abs(Z.normal.dot(X.normal))>1-1e-10){const L=this.satBounds,V=this.satAxes;t[0]=b.a,t[1]=b.b,t[2]=b.c;for(let S=0;S<4;S++){const W=L[S],f=V[S];if(i.setFromPoints(f,t),W.isSeparated(i))return!1}const x=b.satBounds,R=b.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let S=0;S<4;S++){const W=x[S],f=R[S];if(i.setFromPoints(f,e),W.isSeparated(i))return!1}for(let S=0;S<4;S++){const W=V[S];for(let f=0;f<4;f++){const C=R[f];if(o.crossVectors(W,C),i.setFromPoints(o,e),s.setFromPoints(o,t),i.isSeparated(s))return!1}}return G&&(y||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),G.start.set(0,0,0),G.end.set(0,0,0)),!0}else{const L=m(this,X,h);if(L===1&&b.containsPoint(h.end))return G&&(G.start.copy(h.end),G.end.copy(h.end)),!0;if(L!==2)return!1;const V=m(b,Z,u);if(V===1&&this.containsPoint(u.end))return G&&(G.start.copy(u.end),G.end.copy(u.end)),!0;if(V!==2)return!1;if(h.delta(c),u.delta(r),c.dot(r)<0){let g=u.start;u.start=u.end,u.end=g}const x=h.start.dot(c),R=h.end.dot(c),S=u.start.dot(c),W=u.end.dot(c),f=R<S,C=x<W;return x!==W&&S!==R&&f===C?!1:(G&&(l.subVectors(h.start,u.start),l.dot(c)>0?G.start.copy(h.start):G.start.copy(u.start),l.subVectors(h.end,u.end),l.dot(c)<0?G.end.copy(h.end):G.end.copy(u.end)),!0)}}}(),He.prototype.distanceToPoint=function(){const n=new K;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),He.prototype.distanceToTriangle=function(){const n=new K,e=new K,t=["a","b","c"],i=new rt,s=new rt;return function(o,a=null,c=null){const r=a||c?i:null;if(this.intersectsTriangle(o,r))return(a||c)&&(a&&r.getCenter(a),c&&r.getCenter(c)),0;let l=1/0;for(let d=0;d<3;d++){let h;const u=t[d],p=o[u];this.closestPointToPoint(p,n),h=p.distanceToSquared(n),h<l&&(l=h,a&&a.copy(n),c&&c.copy(p));const m=this[u];o.closestPointToPoint(m,n),h=m.distanceToSquared(n),h<l&&(l=h,a&&a.copy(m),c&&c.copy(n))}for(let d=0;d<3;d++){const h=t[d],u=t[(d+1)%3];i.set(this[h],this[u]);for(let p=0;p<3;p++){const m=t[p],b=t[(p+1)%3];s.set(o[m],o[b]),Zo(i,s,n,e);const G=n.distanceToSquared(e);G<l&&(l=G,a&&a.copy(n),c&&c.copy(e))}}return Math.sqrt(l)}}();class Xe{constructor(e,t,i){this.isOrientedBox=!0,this.min=new K,this.max=new K,this.matrix=new Te,this.invMatrix=new Te,this.points=new Array(8).fill().map(()=>new K),this.satAxes=new Array(3).fill().map(()=>new K),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}}Xe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,i=this.points;for(let r=0;r<=1;r++)for(let l=0;l<=1;l++)for(let d=0;d<=1;d++){const h=1*r|2*l|4*d,u=i[h];u.x=r?t.x:e.x,u.y=l?t.y:e.y,u.z=d?t.z:e.z,u.applyMatrix4(n)}const s=this.satBounds,o=this.satAxes,a=i[0];for(let r=0;r<3;r++){const l=o[r],d=s[r],h=1<<r,u=i[h];l.subVectors(a,u),d.setFromPoints(l,i)}const c=this.alignedSatBounds;c[0].setFromPointsField(i,"x"),c[1].setFromPointsField(i,"y"),c[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Xe.prototype.intersectsBox=function(){const n=new ut;return function(e){this.needsUpdate&&this.update();const t=e.min,i=e.max,s=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=i.x,a[0].isSeparated(n)||(n.min=t.y,n.max=i.y,a[1].isSeparated(n))||(n.min=t.z,n.max=i.z,a[2].isSeparated(n)))return!1;for(let c=0;c<3;c++){const r=o[c],l=s[c];if(n.setFromBox(r,e),l.isSeparated(n))return!1}return!0}}(),Xe.prototype.intersectsTriangle=function(){const n=new He,e=new Array(3),t=new ut,i=new ut,s=new K;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(n.copy(o),n.update(),o=n);const a=this.satBounds,c=this.satAxes;e[0]=o.a,e[1]=o.b,e[2]=o.c;for(let h=0;h<3;h++){const u=a[h],p=c[h];if(t.setFromPoints(p,e),u.isSeparated(t))return!1}const r=o.satBounds,l=o.satAxes,d=this.points;for(let h=0;h<3;h++){const u=r[h],p=l[h];if(t.setFromPoints(p,d),u.isSeparated(t))return!1}for(let h=0;h<3;h++){const u=c[h];for(let p=0;p<4;p++){const m=l[p];if(s.crossVectors(u,m),t.setFromPoints(s,e),i.setFromPoints(s,d),t.isSeparated(i))return!1}}return!0}}(),Xe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Xe.prototype.distanceToPoint=function(){const n=new K;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Xe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new rt),t=new Array(12).fill().map(()=>new rt),i=new K,s=new K;return function(o,a=0,c=null,r=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||r)&&(o.getCenter(s),this.closestPointToPoint(s,i),o.closestPointToPoint(i,s),c&&c.copy(i),r&&r.copy(s)),0;const l=a*a,d=o.min,h=o.max,u=this.points;let p=1/0;for(let b=0;b<8;b++){const G=u[b];s.copy(G).clamp(d,h);const y=G.distanceToSquared(s);if(y<p&&(p=y,c&&c.copy(G),r&&r.copy(s),y<l))return Math.sqrt(y)}let m=0;for(let b=0;b<3;b++)for(let G=0;G<=1;G++)for(let y=0;y<=1;y++){const Z=(b+1)%3,X=(b+2)%3,L=G<<Z|y<<X,V=1<<b|G<<Z|y<<X,x=u[L],R=u[V];e[m].set(x,R);const S=n[b],W=n[Z],f=n[X],C=t[m],g=C.start,z=C.end;g[S]=d[S],g[W]=G?d[W]:h[W],g[f]=y?d[f]:h[W],z[S]=h[S],z[W]=G?d[W]:h[W],z[f]=y?d[f]:h[W],m++}for(let b=0;b<=1;b++)for(let G=0;G<=1;G++)for(let y=0;y<=1;y++){s.x=b?h.x:d.x,s.y=G?h.y:d.y,s.z=y?h.z:d.z,this.closestPointToPoint(s,i);const Z=s.distanceToSquared(i);if(Z<p&&(p=Z,c&&c.copy(i),r&&r.copy(s),Z<l))return Math.sqrt(Z)}for(let b=0;b<12;b++){const G=e[b];for(let y=0;y<12;y++){const Z=t[y];Zo(G,Z,i,s);const X=i.distanceToSquared(s);if(X<p&&(p=X,c&&c.copy(i),r&&r.copy(s),X<l))return Math.sqrt(X)}}return Math.sqrt(p)}}();class Vo{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 fh extends Vo{constructor(){super(()=>new He)}}const ke=new fh;class Wh{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 j=new Wh;let Vt,ti;const ii=[],es=new Vo(()=>new fe);function gh(n,e,t,i,s,o){Vt=es.getPrimitive(),ti=es.getPrimitive(),ii.push(Vt,ti),j.setBuffer(n._roots[e]);const a=Ro(0,n.geometry,t,i,s,o);j.clearBuffer(),es.releasePrimitive(Vt),es.releasePrimitive(ti),ii.pop(),ii.pop();const c=ii.length;return c>0&&(ti=ii[c-1],Vt=ii[c-2]),a}function Ro(n,e,t,i,s=null,o=0,a=0){const{float32Array:c,uint16Array:r,uint32Array:l}=j;let d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);return E(n,c,Vt),i(h,u,!1,a,o+n,Vt)}else{let h=function(C){const{uint16Array:g,uint32Array:z}=j;let Y=C*2;for(;!xe(Y,g);)C=Ye(C),Y=C*2;return ge(C,z)},u=function(C){const{uint16Array:g,uint32Array:z}=j;let Y=C*2;for(;!xe(Y,g);)C=Me(C,z),Y=C*2;return ge(C,z)+Ke(Y,g)};const p=Ye(n),m=Me(n,l);let b=p,G=m,y,Z,X,L;if(s&&(X=Vt,L=ti,E(b,c,X),E(G,c,L),y=s(X),Z=s(L),Z<y)){b=m,G=p;const C=y;y=Z,Z=C,X=L}X||(X=Vt,E(b,c,X));const V=xe(b*2,r),x=t(X,V,y,a+1,o+b);let R;if(x===co){const C=h(b),g=u(b)-C;R=i(C,g,!0,a+1,o+b,X)}else R=x&&Ro(b,e,t,i,s,o,a+1);if(R)return!0;L=ti,E(G,c,L);const S=xe(G*2,r),W=t(L,S,Z,a+1,o+G);let f;if(W===co){const C=h(G),g=u(G)-C;f=i(C,g,!0,a+1,o+G,L)}else f=W&&Ro(G,e,t,i,s,o,a+1);return!!f}}const Mi=new K,Lo=new K;function Ch(n,e,t={},i=0,s=1/0){const o=i*i,a=s*s;let c=1/0,r=null;if(n.shapecast({boundsTraverseOrder:d=>(Mi.copy(e).clamp(d.min,d.max),Mi.distanceToSquared(e)),intersectsBounds:(d,h,u)=>u<c&&u<a,intersectsTriangle:(d,h)=>{d.closestPointToPoint(e,Mi);const u=e.distanceToSquared(Mi);return u<c&&(Lo.copy(Mi),c=u,r=h),u<o}}),c===1/0)return null;const l=Math.sqrt(c);return t.point?t.point.copy(Lo):t.point=Lo.clone(),t.distance=l,t.faceIndex=r,t}const zh=parseInt(Fo)>=169,Nt=new K,It=new K,Jt=new K,ts=new De,is=new De,ns=new De,wr=new K,Fr=new K,Qr=new K,Ti=new K;function vh(n,e,t,i,s,o,a,c){let r;if(o===fl?r=n.intersectTriangle(i,t,e,!0,s):r=n.intersectTriangle(e,t,i,o!==xs,s),r===null)return null;const l=n.origin.distanceTo(s);return l<a||l>c?null:{distance:l,point:s.clone()}}function Kh(n,e,t,i,s,o,a,c,r,l,d){Nt.fromBufferAttribute(e,o),It.fromBufferAttribute(e,a),Jt.fromBufferAttribute(e,c);const h=vh(n,Nt,It,Jt,Ti,r,l,d);if(h){const u=new K;we.getBarycoord(Ti,Nt,It,Jt,u),i&&(ts.fromBufferAttribute(i,o),is.fromBufferAttribute(i,a),ns.fromBufferAttribute(i,c),h.uv=we.getInterpolation(Ti,Nt,It,Jt,ts,is,ns,new De)),s&&(ts.fromBufferAttribute(s,o),is.fromBufferAttribute(s,a),ns.fromBufferAttribute(s,c),h.uv1=we.getInterpolation(Ti,Nt,It,Jt,ts,is,ns,new De)),t&&(wr.fromBufferAttribute(t,o),Fr.fromBufferAttribute(t,a),Qr.fromBufferAttribute(t,c),h.normal=we.getInterpolation(Ti,Nt,It,Jt,wr,Fr,Qr,new K),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const p={a:o,b:a,c,normal:new K,materialIndex:0};we.getNormal(Nt,It,Jt,p.normal),h.face=p,h.faceIndex=o,zh&&(h.barycoord=u)}return h}function ss(n,e,t,i,s,o,a){const c=i*3;let r=c+0,l=c+1,d=c+2;const h=n.index;n.index&&(r=h.getX(r),l=h.getX(l),d=h.getX(d));const{position:u,normal:p,uv:m,uv1:b}=n.attributes,G=Kh(t,u,p,m,b,r,l,d,e,o,a);return G?(G.faceIndex=i,s&&s.push(G),G):null}function $(n,e,t,i){const s=n.a,o=n.b,a=n.c;let c=e,r=e+1,l=e+2;t&&(c=t.getX(c),r=t.getX(r),l=t.getX(l)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),o.x=i.getX(r),o.y=i.getY(r),o.z=i.getZ(r),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l)}const Yi=new K,Hi=new K,ki=new K,Br=new De,Er=new De,jr=new De;function Mh(n,e,t,i){const s=e.getIndex().array,o=e.getAttribute("position"),a=e.getAttribute("uv"),c=s[t*3],r=s[t*3+1],l=s[t*3+2];Yi.fromBufferAttribute(o,c),Hi.fromBufferAttribute(o,r),ki.fromBufferAttribute(o,l);let d=0;const h=e.groups,u=t*3;for(let b=0,G=h.length;b<G;b++){const y=h[b],{start:Z,count:X}=y;if(u>=Z&&u<Z+X){d=y.materialIndex;break}}const p=i&&i.barycoord?i.barycoord:new K;we.getBarycoord(n,Yi,Hi,ki,p);let m=null;return a&&(Br.fromBufferAttribute(a,c),Er.fromBufferAttribute(a,r),jr.fromBufferAttribute(a,l),i&&i.uv?m=i.uv:m=new De,we.getInterpolation(n,Yi,Hi,ki,Br,Er,jr,m)),i?(i.face||(i.face={}),i.face.a=c,i.face.b=r,i.face.c=l,i.face.materialIndex=d,i.face.normal||(i.face.normal=new K),we.getNormal(Yi,Hi,ki,i.face.normal),m&&(i.uv=m),i.barycoord=p,i):{face:{a:c,b:r,c:l,materialIndex:d,normal:we.getNormal(Yi,Hi,ki,new K)},uv:m,barycoord:p}}function Th(n,e,t,i,s,o,a,c){const{geometry:r,_indirectBuffer:l}=n;for(let d=i,h=i+s;d<h;d++)ss(r,e,t,d,o,a,c)}function Yh(n,e,t,i,s,o,a){const{geometry:c,_indirectBuffer:r}=n;let l=1/0,d=null;for(let h=i,u=i+s;h<u;h++){let p;p=ss(c,e,t,h,null,o,a),p&&p.distance<l&&(d=p,l=p.distance)}return d}function Hh(n,e,t,i,s,o,a){const{geometry:c}=t,{index:r}=c,l=c.attributes.position;for(let d=n,h=e+n;d<h;d++){let u;if(u=d,$(a,u*3,r,l),a.needsUpdate=!0,i(a,u,s,o))return!0}return!1}function kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let o,a,c,r,l=0;const d=n._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],a=new Uint32Array(o),c=new Uint16Array(o),r=new Float32Array(o),h(0,l),l+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(c[b+15]===_n){const G=a[u+6],y=c[b+14];let Z=1/0,X=1/0,L=1/0,V=-1/0,x=-1/0,R=-1/0;for(let S=3*G,W=3*(G+y);S<W;S++){let f=i[S];const C=s.getX(f),g=s.getY(f),z=s.getZ(f);C<Z&&(Z=C),C>V&&(V=C),g<X&&(X=g),g>x&&(x=g),z<L&&(L=z),z>R&&(R=z)}return r[u+0]!==Z||r[u+1]!==X||r[u+2]!==L||r[u+3]!==V||r[u+4]!==x||r[u+5]!==R?(r[u+0]=Z,r[u+1]=X,r[u+2]=L,r[u+3]=V,r[u+4]=x,r[u+5]=R,!0):!1}else{const G=u+8,y=a[u+6],Z=G+p,X=y+p;let L=m,V=!1,x=!1;e?L||(V=e.has(Z),x=e.has(X),L=!V&&!x):(V=!0,x=!0);const R=L||V,S=L||x;let W=!1;R&&(W=h(G,p,L));let f=!1;S&&(f=h(y,p,L));const C=W||f;if(C)for(let g=0;g<3;g++){const z=G+g,Y=y+g,k=r[z],N=r[z+3],Q=r[Y],P=r[Y+3];r[u+g]=k<Q?k:Q,r[u+g+3]=N>P?N:P}return C}}}function Rt(n,e,t,i,s){let o,a,c,r,l,d;const h=1/t.direction.x,u=1/t.direction.y,p=1/t.direction.z,m=t.origin.x,b=t.origin.y,G=t.origin.z;let y=e[n],Z=e[n+3],X=e[n+1],L=e[n+3+1],V=e[n+2],x=e[n+3+2];return h>=0?(o=(y-m)*h,a=(Z-m)*h):(o=(Z-m)*h,a=(y-m)*h),u>=0?(c=(X-b)*u,r=(L-b)*u):(c=(L-b)*u,r=(X-b)*u),o>r||c>a||((c>o||isNaN(o))&&(o=c),(r<a||isNaN(a))&&(a=r),p>=0?(l=(V-G)*p,d=(x-G)*p):(l=(x-G)*p,d=(V-G)*p),o>d||l>a)?!1:((l>o||o!==o)&&(o=l),(d<a||a!==a)&&(a=d),o<=s&&a>=i)}function Nh(n,e,t,i,s,o,a,c){const{geometry:r,_indirectBuffer:l}=n;for(let d=i,h=i+s;d<h;d++){let u=l?l[d]:d;ss(r,e,t,u,o,a,c)}}function Ih(n,e,t,i,s,o,a){const{geometry:c,_indirectBuffer:r}=n;let l=1/0,d=null;for(let h=i,u=i+s;h<u;h++){let p;p=ss(c,e,t,r?r[h]:h,null,o,a),p&&p.distance<l&&(d=p,l=p.distance)}return d}function Jh(n,e,t,i,s,o,a){const{geometry:c}=t,{index:r}=c,l=c.attributes.position;for(let d=n,h=e+n;d<h;d++){let u;if(u=t.resolveTriangleIndex(d),$(a,u*3,r,l),a.needsUpdate=!0,i(a,u,s,o))return!0}return!1}function Uh(n,e,t,i,s,o,a){j.setBuffer(n._roots[e]),xo(0,n,t,i,s,o,a),j.clearBuffer()}function xo(n,e,t,i,s,o,a){const{float32Array:c,uint16Array:r,uint32Array:l}=j,d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);Th(e,t,i,h,u,s,o,a)}else{const h=Ye(n);Rt(h,c,i,o,a)&&xo(h,e,t,i,s,o,a);const u=Me(n,l);Rt(u,c,i,o,a)&&xo(u,e,t,i,s,o,a)}}const Ph=["x","y","z"];function wh(n,e,t,i,s,o){j.setBuffer(n._roots[e]);const a=So(0,n,t,i,s,o);return j.clearBuffer(),a}function So(n,e,t,i,s,o){const{float32Array:a,uint16Array:c,uint32Array:r}=j;let l=n*2;if(xe(l,c)){const d=ge(n,r),h=Ke(l,c);return Yh(e,t,i,d,h,s,o)}else{const d=bo(n,r),h=Ph[d],u=i.direction[h]>=0;let p,m;u?(p=Ye(n),m=Me(n,r)):(p=Me(n,r),m=Ye(n));const b=Rt(p,a,i,s,o)?So(p,e,t,i,s,o):null;if(b){const y=b.point[h];if(u?y<=a[m+d]:y>=a[m+d+3])return b}const G=Rt(m,a,i,s,o)?So(m,e,t,i,s,o):null;return b&&G?b.distance<=G.distance?b:G:b||G||null}}const os=new fe,ni=new He,si=new He,Ni=new Te,Or=new Xe,as=new Xe;function Fh(n,e,t,i){j.setBuffer(n._roots[e]);const s=fo(0,n,t,i);return j.clearBuffer(),s}function fo(n,e,t,i,s=null){const{float32Array:o,uint16Array:a,uint32Array:c}=j;let r=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Or.set(t.boundingBox.min,t.boundingBox.max,i),s=Or),xe(r,a)){const l=e.geometry,d=l.index,h=l.attributes.position,u=t.index,p=t.attributes.position,m=ge(n,c),b=Ke(r,a);if(Ni.copy(i).invert(),t.boundsTree)return E(n,o,as),as.matrix.copy(Ni),as.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:G=>as.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(i),G.b.applyMatrix4(i),G.c.applyMatrix4(i),G.needsUpdate=!0;for(let y=m*3,Z=(b+m)*3;y<Z;y+=3)if($(si,y,d,h),si.needsUpdate=!0,G.intersectsTriangle(si))return!0;return!1}});for(let G=m*3,y=(b+m)*3;G<y;G+=3){$(ni,G,d,h),ni.a.applyMatrix4(Ni),ni.b.applyMatrix4(Ni),ni.c.applyMatrix4(Ni),ni.needsUpdate=!0;for(let Z=0,X=u.count;Z<X;Z+=3)if($(si,Z,u,p),si.needsUpdate=!0,ni.intersectsTriangle(si))return!0}}else{const l=n+8,d=c[n+6];return E(l,o,os),!!(s.intersectsBox(os)&&fo(l,e,t,i,s)||(E(d,o,os),s.intersectsBox(os)&&fo(d,e,t,i,s)))}}const rs=new Te,Wo=new Xe,Ii=new Xe,Qh=new K,Bh=new K,Eh=new K,jh=new K;function Oh(n,e,t,i={},s={},o=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Wo.set(e.boundingBox.min,e.boundingBox.max,t),Wo.needsUpdate=!0;const c=n.geometry,r=c.attributes.position,l=c.index,d=e.attributes.position,h=e.index,u=ke.getPrimitive(),p=ke.getPrimitive();let m=Qh,b=Bh,G=null,y=null;s&&(G=Eh,y=jh);let Z=1/0,X=null,L=null;return rs.copy(t).invert(),Ii.matrix.copy(rs),n.shapecast({boundsTraverseOrder:V=>Wo.distanceToBox(V),intersectsBounds:(V,x,R)=>R<Z&&R<a?(x&&(Ii.min.copy(V.min),Ii.max.copy(V.max),Ii.needsUpdate=!0),!0):!1,intersectsRange:(V,x)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:R=>Ii.distanceToBox(R),intersectsBounds:(R,S,W)=>W<Z&&W<a,intersectsRange:(R,S)=>{for(let W=R,f=R+S;W<f;W++){$(p,3*W,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=V,g=V+x;C<g;C++){$(u,3*C,l,r),u.needsUpdate=!0;const z=u.distanceToTriangle(p,m,G);if(z<Z&&(b.copy(m),y&&y.copy(G),Z=z,X=C,L=W),z<o)return!0}}}});{const R=ei(e);for(let S=0,W=R;S<W;S++){$(p,3*S,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let f=V,C=V+x;f<C;f++){$(u,3*f,l,r),u.needsUpdate=!0;const g=u.distanceToTriangle(p,m,G);if(g<Z&&(b.copy(m),y&&y.copy(G),Z=g,X=f,L=S),g<o)return!0}}}}}),ke.releasePrimitive(u),ke.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=X,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(rs),b.applyMatrix4(rs),s.distance=b.sub(s.point).length(),s.faceIndex=L),i)}function Dh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let o,a,c,r,l=0;const d=n._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],a=new Uint32Array(o),c=new Uint16Array(o),r=new Float32Array(o),h(0,l),l+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(c[b+15]===_n){const G=a[u+6],y=c[b+14];let Z=1/0,X=1/0,L=1/0,V=-1/0,x=-1/0,R=-1/0;for(let S=G,W=G+y;S<W;S++){const f=3*n.resolveTriangleIndex(S);for(let C=0;C<3;C++){let g=f+C;g=i?i[g]:g;const z=s.getX(g),Y=s.getY(g),k=s.getZ(g);z<Z&&(Z=z),z>V&&(V=z),Y<X&&(X=Y),Y>x&&(x=Y),k<L&&(L=k),k>R&&(R=k)}}return r[u+0]!==Z||r[u+1]!==X||r[u+2]!==L||r[u+3]!==V||r[u+4]!==x||r[u+5]!==R?(r[u+0]=Z,r[u+1]=X,r[u+2]=L,r[u+3]=V,r[u+4]=x,r[u+5]=R,!0):!1}else{const G=u+8,y=a[u+6],Z=G+p,X=y+p;let L=m,V=!1,x=!1;e?L||(V=e.has(Z),x=e.has(X),L=!V&&!x):(V=!0,x=!0);const R=L||V,S=L||x;let W=!1;R&&(W=h(G,p,L));let f=!1;S&&(f=h(y,p,L));const C=W||f;if(C)for(let g=0;g<3;g++){const z=G+g,Y=y+g,k=r[z],N=r[z+3],Q=r[Y],P=r[Y+3];r[u+g]=k<Q?k:Q,r[u+g+3]=N>P?N:P}return C}}}function _h(n,e,t,i,s,o,a){j.setBuffer(n._roots[e]),go(0,n,t,i,s,o,a),j.clearBuffer()}function go(n,e,t,i,s,o,a){const{float32Array:c,uint16Array:r,uint32Array:l}=j,d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);Nh(e,t,i,h,u,s,o,a)}else{const h=Ye(n);Rt(h,c,i,o,a)&&go(h,e,t,i,s,o,a);const u=Me(n,l);Rt(u,c,i,o,a)&&go(u,e,t,i,s,o,a)}}const Ah=["x","y","z"];function qh(n,e,t,i,s,o){j.setBuffer(n._roots[e]);const a=Co(0,n,t,i,s,o);return j.clearBuffer(),a}function Co(n,e,t,i,s,o){const{float32Array:a,uint16Array:c,uint32Array:r}=j;let l=n*2;if(xe(l,c)){const d=ge(n,r),h=Ke(l,c);return Ih(e,t,i,d,h,s,o)}else{const d=bo(n,r),h=Ah[d],u=i.direction[h]>=0;let p,m;u?(p=Ye(n),m=Me(n,r)):(p=Me(n,r),m=Ye(n));const b=Rt(p,a,i,s,o)?Co(p,e,t,i,s,o):null;if(b){const y=b.point[h];if(u?y<=a[m+d]:y>=a[m+d+3])return b}const G=Rt(m,a,i,s,o)?Co(m,e,t,i,s,o):null;return b&&G?b.distance<=G.distance?b:G:b||G||null}}const ls=new fe,oi=new He,ai=new He,Ji=new Te,Dr=new Xe,cs=new Xe;function $h(n,e,t,i){j.setBuffer(n._roots[e]);const s=zo(0,n,t,i);return j.clearBuffer(),s}function zo(n,e,t,i,s=null){const{float32Array:o,uint16Array:a,uint32Array:c}=j;let r=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Dr.set(t.boundingBox.min,t.boundingBox.max,i),s=Dr),xe(r,a)){const l=e.geometry,d=l.index,h=l.attributes.position,u=t.index,p=t.attributes.position,m=ge(n,c),b=Ke(r,a);if(Ji.copy(i).invert(),t.boundsTree)return E(n,o,cs),cs.matrix.copy(Ji),cs.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:G=>cs.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(i),G.b.applyMatrix4(i),G.c.applyMatrix4(i),G.needsUpdate=!0;for(let y=m,Z=b+m;y<Z;y++)if($(ai,3*e.resolveTriangleIndex(y),d,h),ai.needsUpdate=!0,G.intersectsTriangle(ai))return!0;return!1}});for(let G=m,y=b+m;G<y;G++){const Z=e.resolveTriangleIndex(G);$(oi,3*Z,d,h),oi.a.applyMatrix4(Ji),oi.b.applyMatrix4(Ji),oi.c.applyMatrix4(Ji),oi.needsUpdate=!0;for(let X=0,L=u.count;X<L;X+=3)if($(ai,X,u,p),ai.needsUpdate=!0,oi.intersectsTriangle(ai))return!0}}else{const l=n+8,d=c[n+6];return E(l,o,ls),!!(s.intersectsBox(ls)&&zo(l,e,t,i,s)||(E(d,o,ls),s.intersectsBox(ls)&&zo(d,e,t,i,s)))}}const ds=new Te,vo=new Xe,Ui=new Xe,eu=new K,tu=new K,iu=new K,nu=new K;function su(n,e,t,i={},s={},o=0,a=1/0){e.boundingBox||e.computeBoundingBox(),vo.set(e.boundingBox.min,e.boundingBox.max,t),vo.needsUpdate=!0;const c=n.geometry,r=c.attributes.position,l=c.index,d=e.attributes.position,h=e.index,u=ke.getPrimitive(),p=ke.getPrimitive();let m=eu,b=tu,G=null,y=null;s&&(G=iu,y=nu);let Z=1/0,X=null,L=null;return ds.copy(t).invert(),Ui.matrix.copy(ds),n.shapecast({boundsTraverseOrder:V=>vo.distanceToBox(V),intersectsBounds:(V,x,R)=>R<Z&&R<a?(x&&(Ui.min.copy(V.min),Ui.max.copy(V.max),Ui.needsUpdate=!0),!0):!1,intersectsRange:(V,x)=>{if(e.boundsTree){const R=e.boundsTree;return R.shapecast({boundsTraverseOrder:S=>Ui.distanceToBox(S),intersectsBounds:(S,W,f)=>f<Z&&f<a,intersectsRange:(S,W)=>{for(let f=S,C=S+W;f<C;f++){const g=R.resolveTriangleIndex(f);$(p,3*g,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let z=V,Y=V+x;z<Y;z++){const k=n.resolveTriangleIndex(z);$(u,3*k,l,r),u.needsUpdate=!0;const N=u.distanceToTriangle(p,m,G);if(N<Z&&(b.copy(m),y&&y.copy(G),Z=N,X=z,L=f),N<o)return!0}}}})}else{const R=ei(e);for(let S=0,W=R;S<W;S++){$(p,3*S,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let f=V,C=V+x;f<C;f++){const g=n.resolveTriangleIndex(f);$(u,3*g,l,r),u.needsUpdate=!0;const z=u.distanceToTriangle(p,m,G);if(z<Z&&(b.copy(m),y&&y.copy(G),Z=z,X=f,L=S),z<o)return!0}}}}}),ke.releasePrimitive(u),ke.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=X,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(ds),b.applyMatrix4(ds),s.distance=b.sub(s.point).length(),s.faceIndex=L),i)}function _r(){return typeof SharedArrayBuffer<"u"}const Pi=new j.constructor,hs=new j.constructor,Lt=new Vo(()=>new fe),ri=new fe,li=new fe,Ko=new fe,Mo=new fe;let To=!1;function ou(n,e,t,i){if(To)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");To=!0;const s=n._roots,o=e._roots;let a,c=0,r=0;const l=new Te().copy(t).invert();for(let d=0,h=s.length;d<h;d++){Pi.setBuffer(s[d]),r=0;const u=Lt.getPrimitive();E(0,Pi.float32Array,u),u.applyMatrix4(l);for(let p=0,m=o.length;p<m&&(hs.setBuffer(o[p]),a=Ee(0,0,t,l,i,c,r,0,0,u),hs.clearBuffer(),r+=o[p].length,!a);p++);if(Lt.releasePrimitive(u),Pi.clearBuffer(),c+=s[d].length,a)break}return To=!1,a}function Ee(n,e,t,i,s,o=0,a=0,c=0,r=0,l=null,d=!1){let h,u;d?(h=hs,u=Pi):(h=Pi,u=hs);const p=h.float32Array,m=h.uint32Array,b=h.uint16Array,G=u.float32Array,y=u.uint32Array,Z=u.uint16Array,X=n*2,L=e*2,V=xe(X,b),x=xe(L,Z);let R=!1;if(x&&V)d?R=s(ge(e,y),Ke(e*2,Z),ge(n,m),Ke(n*2,b),r,a+e,c,o+n):R=s(ge(n,m),Ke(n*2,b),ge(e,y),Ke(e*2,Z),c,o+n,r,a+e);else if(x){const S=Lt.getPrimitive();E(e,G,S),S.applyMatrix4(t);const W=Ye(n),f=Me(n,m);E(W,p,ri),E(f,p,li);const C=S.intersectsBox(ri),g=S.intersectsBox(li);R=C&&Ee(e,W,i,t,s,a,o,r,c+1,S,!d)||g&&Ee(e,f,i,t,s,a,o,r,c+1,S,!d),Lt.releasePrimitive(S)}else{const S=Ye(e),W=Me(e,y);E(S,G,Ko),E(W,G,Mo);const f=l.intersectsBox(Ko),C=l.intersectsBox(Mo);if(f&&C)R=Ee(n,S,t,i,s,o,a,c,r+1,l,d)||Ee(n,W,t,i,s,o,a,c,r+1,l,d);else if(f)if(V)R=Ee(n,S,t,i,s,o,a,c,r+1,l,d);else{const g=Lt.getPrimitive();g.copy(Ko).applyMatrix4(t);const z=Ye(n),Y=Me(n,m);E(z,p,ri),E(Y,p,li);const k=g.intersectsBox(ri),N=g.intersectsBox(li);R=k&&Ee(S,z,i,t,s,a,o,r,c+1,g,!d)||N&&Ee(S,Y,i,t,s,a,o,r,c+1,g,!d),Lt.releasePrimitive(g)}else if(C)if(V)R=Ee(n,W,t,i,s,o,a,c,r+1,l,d);else{const g=Lt.getPrimitive();g.copy(Mo).applyMatrix4(t);const z=Ye(n),Y=Me(n,m);E(z,p,ri),E(Y,p,li);const k=g.intersectsBox(ri),N=g.intersectsBox(li);R=k&&Ee(W,z,i,t,s,a,o,r,c+1,g,!d)||N&&Ee(W,Y,i,t,s,a,o,r,c+1,g,!d),Lt.releasePrimitive(g)}}return R}const us=new Xe,Ar=new fe,au={strategy:lo,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class xt{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,o=e._indirectBuffer,a=i.getIndex();let c;return t.cloneBuffers?c={roots:s.map(r=>r.slice()),index:a?a.array.slice():null,indirectBuffer:o?o.slice():null}:c={roots:s,index:a?a.array:null,indirectBuffer:o},c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:o,indirectBuffer:a}=e,c=new xt(t,{...i,[uo]:!0});if(c._roots=o,c._indirectBuffer=a||null,i.setIndex){const r=t.getIndex();if(r===null){const l=new be(e.index,1,!1);t.setIndex(l)}else r.array!==s&&(r.array.set(s),r.needsUpdate=!0)}return c}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({...au,[uo]:!1},t),t.useSharedArrayBuffer&&!_r())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[uo]||(Rh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new fe))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Dh:kh)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),o=new Uint16Array(i);a(0);function a(c,r=0){const l=c*2,d=o[l+15]===_n;if(d){const h=s[c+6],u=o[l+14];e(r,d,new Float32Array(i,c*4,6),h,u)}else{const h=c+Zt/4,u=s[c+6],p=s[c+7];e(r,d,new Float32Array(i,c*4,6),p)||(a(h,r+1),a(u,r+1))}}}raycast(e,t=Qo,i=0,s=1/0){const o=this._roots,a=this.geometry,c=[],r=t.isMaterial,l=Array.isArray(t),d=a.groups,h=r?t.side:t,u=this.indirect?_h:Uh;for(let p=0,m=o.length;p<m;p++){const b=l?t[d[p].materialIndex].side:h,G=c.length;if(u(this,p,b,e,c,i,s),l){const y=d[p].materialIndex;for(let Z=G,X=c.length;Z<X;Z++)c[Z].face.materialIndex=y}}return c}raycastFirst(e,t=Qo,i=0,s=1/0){const o=this._roots,a=this.geometry,c=t.isMaterial,r=Array.isArray(t);let l=null;const d=a.groups,h=c?t.side:t,u=this.indirect?qh:wh;for(let p=0,m=o.length;p<m;p++){const b=r?t[d[p].materialIndex].side:h,G=u(this,p,b,e,i,s);G!=null&&(l==null||G.distance<l.distance)&&(l=G,r&&(G.face.materialIndex=d[p].materialIndex))}return l}intersectsGeometry(e,t){let i=!1;const s=this._roots,o=this.indirect?$h:Fh;for(let a=0,c=s.length;a<c&&(i=o(this,a,e,t),!i);a++);return i}shapecast(e){const t=ke.getPrimitive(),i=this.indirect?Jh:Hh;let{boundsTraverseOrder:s,intersectsBounds:o,intersectsRange:a,intersectsTriangle:c}=e;if(a&&c){const h=a;a=(u,p,m,b,G)=>h(u,p,m,b,G)?!0:i(u,p,this,c,m,b,t)}else a||(c?a=(h,u,p,m)=>i(h,u,this,c,p,m,t):a=(h,u,p)=>p);let r=!1,l=0;const d=this._roots;for(let h=0,u=d.length;h<u;h++){const p=d[h];if(r=gh(this,h,o,a,s,l),r)break;l+=p.byteLength}return ke.releasePrimitive(t),r}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:o}=i;const a=ke.getPrimitive(),c=this.geometry.index,r=this.geometry.attributes.position,l=this.indirect?m=>{const b=this.resolveTriangleIndex(m);$(a,b*3,c,r)}:m=>{$(a,m*3,c,r)},d=ke.getPrimitive(),h=e.geometry.index,u=e.geometry.attributes.position,p=e.indirect?m=>{const b=e.resolveTriangleIndex(m);$(d,b*3,h,u)}:m=>{$(d,m*3,h,u)};if(o){const m=(b,G,y,Z,X,L,V,x)=>{for(let R=y,S=y+Z;R<S;R++){p(R),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let W=b,f=b+G;W<f;W++)if(l(W),a.needsUpdate=!0,o(a,d,W,R,X,L,V,x))return!0}return!1};if(s){const b=s;s=function(G,y,Z,X,L,V,x,R){return b(G,y,Z,X,L,V,x,R)?!0:m(G,y,Z,X,L,V,x,R)}}else s=m}return ou(this,e,t,s)}intersectsBox(e,t){return us.set(e.min,e.max,t),us.needsUpdate=!0,this.shapecast({intersectsBounds:i=>us.intersectsBox(i),intersectsTriangle:i=>us.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},o=0,a=1/0){return(this.indirect?su:Oh)(this,e,t,i,s,o,a)}closestPointToPoint(e,t={},i=0,s=1/0){return Ch(this,e,t,i,s)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{E(0,new Float32Array(t),Ar),e.union(Ar)}),e}}const qr=new fe,$r=new Te;class ru extends Ss{get isMesh(){return!this.displayEdges}get isLineSegments(){return this.displayEdges}get isLine(){return this.displayEdges}getVertexPosition(...e){return Sn.prototype.getVertexPosition.call(this,...e)}constructor(e,t,i=10,s=0){super(),this.material=t,this.geometry=new Ot,this.name="MeshBVHRootHelper",this.depth=i,this.displayParents=!1,this.bvh=e,this.displayEdges=!0,this._group=s}raycast(){}update(){const e=this.geometry,t=this.bvh,i=this._group;if(e.dispose(),this.visible=!1,t){const s=this.depth-1,o=this.displayParents;let a=0;t.traverse((u,p)=>{if(u>=s||p)return a++,!0;o&&a++},i);let c=0;const r=new Float32Array(8*3*a);t.traverse((u,p,m)=>{const b=u>=s||p;if(b||o){E(0,m,qr);const{min:G,max:y}=qr;for(let Z=-1;Z<=1;Z+=2){const X=Z<0?G.x:y.x;for(let L=-1;L<=1;L+=2){const V=L<0?G.y:y.y;for(let x=-1;x<=1;x+=2){const R=x<0?G.z:y.z;r[c+0]=X,r[c+1]=V,r[c+2]=R,c+=3}}}return b}},i);let l,d;this.displayEdges?d=new Uint8Array([0,4,1,5,2,6,3,7,0,2,1,3,4,6,5,7,0,1,2,3,4,5,6,7]):d=new Uint8Array([0,1,2,2,1,3,4,6,5,6,7,5,1,4,5,0,4,1,2,3,6,3,7,6,0,2,4,2,6,4,1,5,3,3,5,7]),r.length>65535?l=new Uint32Array(d.length*a):l=new Uint16Array(d.length*a);const h=d.length;for(let u=0;u<a;u++){const p=u*8,m=u*h;for(let b=0;b<h;b++)l[m+b]=p+d[b]}e.setIndex(new be(l,1,!1)),e.setAttribute("position",new be(r,3,!1)),this.visible=!0}}}class Io extends Wl{get color(){return this.edgeMaterial.color}get opacity(){return this.edgeMaterial.opacity}set opacity(e){this.edgeMaterial.opacity=e,this.meshMaterial.opacity=e}constructor(e=null,t=null,i=10){e instanceof xt&&(i=t||10,t=e,e=null),typeof t=="number"&&(i=t,t=null),super(),this.name="MeshBVHHelper",this.depth=i,this.mesh=e,this.bvh=t,this.displayParents=!1,this.displayEdges=!0,this.objectIndex=0,this._roots=[];const s=new gl({color:65416,transparent:!0,opacity:.3,depthWrite:!1}),o=new Ls({color:65416,transparent:!0,opacity:.3,depthWrite:!1});o.color=s.color,this.edgeMaterial=s,this.meshMaterial=o,this.update()}update(){const e=this.mesh;let t=this.bvh||e.geometry.boundsTree||null;if(e.isBatchedMesh&&e.boundsTrees&&!t){const s=e._drawInfo[this.objectIndex];s&&(t=e.boundsTrees[s.geometryIndex]||t)}const i=t?t._roots.length:0;for(;this._roots.length>i;){const s=this._roots.pop();s.geometry.dispose(),this.remove(s)}for(let s=0;s<i;s++){const{depth:o,edgeMaterial:a,meshMaterial:c,displayParents:r,displayEdges:l}=this;if(s>=this._roots.length){const h=new ru(t,a,o,s);this.add(h),this._roots.push(h)}const d=this._roots[s];d.bvh=t,d.depth=o,d.displayParents=r,d.displayEdges=l,d.material=l?a:c,d.update()}}updateMatrixWorld(...e){const t=this.mesh,i=this.parent;t!==null&&(t.updateWorldMatrix(!0,!1),i?this.matrix.copy(i.matrixWorld).invert().multiply(t.matrixWorld):this.matrix.copy(t.matrixWorld),(t.isInstancedMesh||t.isBatchedMesh)&&(t.getMatrixAt(this.objectIndex,$r),this.matrix.multiply($r)),this.matrix.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(...e)}copy(e){this.depth=e.depth,this.mesh=e.mesh,this.bvh=e.bvh,this.opacity=e.opacity,this.color.copy(e.color)}clone(){return new Io(this.mesh,this.bvh,this.depth)}dispose(){this.edgeMaterial.dispose(),this.meshMaterial.dispose();const e=this.children;for(let t=0,i=e.length;t<i;t++)e[t].geometry.dispose()}}const wi=new fe,el=new fe,ci=new K;function tl(n){switch(typeof n){case"number":return 8;case"string":return n.length*2;case"boolean":return 4;default:return 0}}function lu(n){return/(Uint|Int|Float)(8|16|32)Array/.test(n.constructor.name)}function cu(n,e){const t={nodeCount:0,leafNodeCount:0,depth:{min:1/0,max:-1/0},tris:{min:1/0,max:-1/0},splits:[0,0,0],surfaceAreaScore:0};return n.traverse((i,s,o,a,c)=>{const r=o[3]-o[0],l=o[1+3]-o[1],d=o[2+3]-o[2],h=2*(r*l+l*d+d*r);t.nodeCount++,s?(t.leafNodeCount++,t.depth.min=Math.min(i,t.depth.min),t.depth.max=Math.max(i,t.depth.max),t.tris.min=Math.min(c,t.tris.min),t.tris.max=Math.max(c,t.tris.max),t.surfaceAreaScore+=h*Dn*c):(t.splits[a]++,t.surfaceAreaScore+=h*ho)},e),t.tris.min===1/0&&(t.tris.min=0,t.tris.max=0),t.depth.min===1/0&&(t.depth.min=0,t.depth.max=0),t}function du(n){return n._roots.map((e,t)=>cu(n,t))}function hu(n){const e=new Set,t=[n];let i=0;for(;t.length;){const s=t.pop();if(!e.has(s)){e.add(s);for(let o in s){if(!Object.hasOwn(s,o))continue;i+=tl(o);const a=s[o];a&&(typeof a=="object"||typeof a=="function")?lu(a)||_r()&&a instanceof SharedArrayBuffer||a instanceof ArrayBuffer?i+=a.byteLength:t.push(a):i+=tl(a)}}}return i}function uu(n){const e=n.geometry,t=[],i=e.index,s=e.getAttribute("position");let o=!0;return n.traverse((a,c,r,l,d)=>{const h={depth:a,isLeaf:c,boundingData:r,offset:l,count:d};t[a]=h,E(0,r,wi);const u=t[a-1];if(c)for(let p=l,m=l+d;p<m;p++){const b=n.resolveTriangleIndex(p);let G=3*b,y=3*b+1,Z=3*b+2;i&&(G=i.getX(G),y=i.getX(y),Z=i.getX(Z));let X;ci.fromBufferAttribute(s,G),X=wi.containsPoint(ci),ci.fromBufferAttribute(s,y),X=X&&wi.containsPoint(ci),ci.fromBufferAttribute(s,Z),X=X&&wi.containsPoint(ci),console.assert(X,"Leaf bounds does not fully contain triangle."),o=o&&X}if(u){E(0,r,el);const p=el.containsBox(wi);console.assert(p,"Parent bounds does not fully contain child."),o=o&&p}}),o}function pu(n){const e=[];return n.traverse((t,i,s,o,a)=>{const c={bounds:E(0,s,new fe)};i?(c.count=a,c.offset=o):(c.left=null,c.right=null),e[t]=c;const r=e[t-1];r&&(r.left===null?r.left=c:r.right=c)}),e[0]}function il(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 mu=parseInt(Fo)>=166,ps=new zl,nl=new K,sl=new Te,bu=Sn.prototype.raycast,yu=Cl.prototype.raycast,ol=new K,pe=new Sn,ms=[];function Gu(n,e){this.isBatchedMesh?Zu.call(this,n,e):Xu.call(this,n,e)}function Zu(n,e){if(this.boundsTrees){const t=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,o=this.matrixWorld;pe.material=this.material,pe.geometry=this.geometry;const a=pe.geometry.boundsTree,c=pe.geometry.drawRange;pe.geometry.boundingSphere===null&&(pe.geometry.boundingSphere=new wo);for(let r=0,l=i.length;r<l;r++){if(!this.getVisibleAt(r))continue;const d=i[r].geometryIndex;if(pe.geometry.boundsTree=t[d],this.getMatrixAt(r,pe.matrixWorld).premultiply(o),!pe.geometry.boundsTree){this.getBoundingBoxAt(d,pe.geometry.boundingBox),this.getBoundingSphereAt(d,pe.geometry.boundingSphere);const h=s[d];pe.geometry.setDrawRange(h.start,h.count)}pe.raycast(n,ms);for(let h=0,u=ms.length;h<u;h++){const p=ms[h];p.object=this,p.batchId=r,e.push(p)}ms.length=0}pe.geometry.boundsTree=a,pe.geometry.drawRange=c,pe.material=null,pe.geometry=null}else yu.call(this,n,e)}function Xu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;sl.copy(this.matrixWorld).invert(),ps.copy(n.ray).applyMatrix4(sl),ol.setFromMatrixScale(this.matrixWorld),nl.copy(ps.direction).multiply(ol);const t=nl.length(),i=n.near/t,s=n.far/t,o=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=il(o.raycastFirst(ps,this.material,i,s),this,n);a&&e.push(a)}else{const a=o.raycast(ps,this.material,i,s);for(let c=0,r=a.length;c<r;c++){const l=il(a[c],this,n);l&&e.push(l)}}}else bu.call(this,n,e)}function Vu(n={}){return this.boundsTree=new xt(this,n),this.boundsTree}function Ru(){this.boundsTree=null}function Lu(n=-1,e={}){if(!mu)throw new Error("BatchedMesh: Three r166+ is required to compute bounds trees.");e.indirect&&console.warn('"Indirect" is set to false because it is not supported for BatchedMesh.'),e={...e,indirect:!1,range:null};const t=this._drawRanges||this._geometryInfo,i=this._geometryCount;this.boundsTrees||(this.boundsTrees=new Array(i).fill(null));const s=this.boundsTrees;for(;s.length<i;)s.push(null);if(n<0){for(let o=0;o<i;o++)e.range=t[o],s[o]=new xt(this.geometry,e);return s}else return n<t.length&&(e.range=t[n],s[n]=new xt(this.geometry,e)),s[n]||null}function xu(n=-1){n<0?this.boundsTrees.fill(null):n<this.boundsTree.length&&(this.boundsTrees[n]=null)}function Su(n){switch(n){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function fu(n){switch(n){case 1:return Tl;case 2:return Ml;case 3:return Wn;case 4:return Wn}}function al(n){switch(n){case 1:return Yl;case 2:return jo;case 3:return gs;case 4:return gs}}class bs extends Ws{constructor(){super(),this.minFilter=Dt,this.magFilter=Dt,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,i=e.itemSize,s=e.count;if(t!==null){if(i*s%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=s*i/t}const o=e.itemSize,a=e.count,c=e.normalized,r=e.array.constructor,l=r.BYTES_PER_ELEMENT;let d=this._forcedType,h=o;if(d===null)switch(r){case Float32Array:d=Gi;break;case Uint8Array:case Uint16Array:case Uint32Array:d=yi;break;case Int8Array:case Int16Array:case Int32Array:d=fn;break}let u,p,m,b,G=Su(o);switch(d){case Gi:m=1,p=fu(o),c&&l===1?(b=r,G+="8",r===Uint8Array?u=Bo:(u=Eo,G+="_SNORM")):(b=Float32Array,G+="32F",u=Gi);break;case fn:G+=l*8+"I",m=c?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,p=al(o),l===1?(b=Int8Array,u=Eo):l===2?(b=Int16Array,u=Kl):(b=Int32Array,u=fn);break;case yi:G+=l*8+"UI",m=c?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,p=al(o),l===1?(b=Uint8Array,u=Bo):l===2?(b=Uint16Array,u=vl):(b=Uint32Array,u=yi);break}h===3&&(p===Wn||p===gs)&&(h=4);const y=Math.ceil(Math.sqrt(a))||1,Z=h*y*y,X=new b(Z),L=e.normalized;e.normalized=!1;for(let V=0;V<a;V++){const x=h*V;X[x]=e.getX(V)/m,o>=2&&(X[x+1]=e.getY(V)/m),o>=3&&(X[x+2]=e.getZ(V)/m,h===4&&(X[x+3]=1)),o>=4&&(X[x+3]=e.getW(V)/m)}e.normalized=L,this.internalFormat=G,this.format=p,this.type=u,this.image.width=y,this.image.height=y,this.image.data=X,this.needsUpdate=!0,this.dispose(),e.itemSize=i,e.count=s}}class rl extends bs{constructor(){super(),this._forcedType=yi}}class Wu extends bs{constructor(){super(),this._forcedType=fn}}class ll extends bs{constructor(){super(),this._forcedType=Gi}}class gu{constructor(){this.index=new rl,this.position=new ll,this.bvhBounds=new Ws,this.bvhContents=new Ws,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(zu(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const i=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const s=Yr(Tr(t));this._cachedIndexAttr=new be(s,1,!1)}Cu(t,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:i,bvhContents:s}=this;e&&e.dispose(),t&&t.dispose(),i&&i.dispose(),s&&s.dispose()}}function Cu(n,e,t){const i=t.array,s=n.index?n.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,r=3*e[o];for(let l=0;l<3;l++)i[c+l]=s?s[r+l]:r+l}}function zu(n,e,t){const i=n._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const s=i[0],o=new Uint16Array(s),a=new Uint32Array(s),c=new Float32Array(s),r=s.byteLength/Zt,l=2*Math.ceil(Math.sqrt(r/2)),d=new Float32Array(4*l*l),h=Math.ceil(Math.sqrt(r)),u=new Uint32Array(2*h*h);for(let p=0;p<r;p++){const m=p*Zt/4,b=m*2,G=m;for(let y=0;y<3;y++)d[8*p+0+y]=c[G+0+y],d[8*p+4+y]=c[G+3+y];if(xe(b,o)){const y=Ke(b,o),Z=ge(m,a),X=4294901760|y;u[p*2+0]=X,u[p*2+1]=Z}else{const y=4*Me(m,a)/Zt,Z=bo(m,a);u[p*2+0]=Z,u[p*2+1]=y}}e.image.data=d,e.image.width=l,e.image.height=l,e.format=Wn,e.type=Gi,e.internalFormat="RGBA32F",e.minFilter=Dt,e.magFilter=Dt,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=u,t.image.width=h,t.image.height=h,t.format=jo,t.type=yi,t.internalFormat="RG32UI",t.minFilter=Dt,t.magFilter=Dt,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const Ut=new K,Pt=new K,wt=new K,cl=new Cs,ys=new K,Yo=new K,dl=new Cs,hl=new Cs,Gs=new Te,ul=new Te;function Fi(n,e){if(!n&&!e)return;const t=n.count===e.count,i=n.normalized===e.normalized,s=n.array.constructor===e.array.constructor,o=n.itemSize===e.itemSize;if(!t||!i||!s||!o)throw new Error}function Qi(n,e=null){const t=n.array.constructor,i=n.normalized,s=n.itemSize,o=e===null?n.count:e;return new be(new t(s*o),s,i)}function pl(n,e,t=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let s=0,o=n.count;s<o;s++){const a=s+t;e.setX(a,n.getX(s)),i>=2&&e.setY(a,n.getY(s)),i>=3&&e.setZ(a,n.getZ(s)),i>=4&&e.setW(a,n.getW(s))}}else{const i=e.array,s=i.constructor,o=i.BYTES_PER_ELEMENT*n.itemSize*t;new s(i.buffer,o,n.array.length).set(n.array)}}function vu(n,e,t){const i=n.elements,s=e.elements;for(let o=0,a=s.length;o<a;o++)i[o]+=s[o]*t}function ml(n,e,t){const i=n.skeleton,s=n.geometry,o=i.bones,a=i.boneInverses;dl.fromBufferAttribute(s.attributes.skinIndex,e),hl.fromBufferAttribute(s.attributes.skinWeight,e),Gs.elements.fill(0);for(let c=0;c<4;c++){const r=hl.getComponent(c);if(r!==0){const l=dl.getComponent(c);ul.multiplyMatrices(o[l].matrixWorld,a[l]),vu(Gs,ul,r)}}return Gs.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(Gs),t}function Ho(n,e,t,i,s){ys.set(0,0,0);for(let o=0,a=n.length;o<a;o++){const c=e[o],r=n[o];c!==0&&(Yo.fromBufferAttribute(r,i),t?ys.addScaledVector(Yo,c):ys.addScaledVector(Yo.sub(s),c))}s.add(ys)}function Ku(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new Ot){const i=n[0].index!==null,{useGroups:s=!1,updateIndex:o=!1,skipAttributes:a=[]}=e,c=new Set(Object.keys(n[0].attributes)),r={};let l=0;t.clearGroups();for(let d=0;d<n.length;++d){const h=n[d];let u=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 p in h.attributes){if(!c.has(p))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.');r[p]===void 0&&(r[p]=[]),r[p].push(h.attributes[p]),u++}if(u!==c.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(s){let p;if(i)p=h.index.count;else if(h.attributes.position!==void 0)p=h.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,d),l+=p}}if(i){let d=!1;if(!t.index){let h=0;for(let u=0;u<n.length;++u)h+=n[u].index.count;t.setIndex(new be(new Uint32Array(h),1,!1)),d=!0}if(o||d){const h=t.index;let u=0,p=0;for(let m=0;m<n.length;++m){const b=n[m],G=b.index;if(a[m]!==!0)for(let y=0;y<G.count;++y)h.setX(u,G.getX(y)+p),u++;p+=b.attributes.position.count}}}for(const d in r){const h=r[d];if(!(d in t.attributes)){let m=0;for(const b in h)m+=h[b].count;t.setAttribute(d,Qi(r[d][0],m))}const u=t.attributes[d];let p=0;for(let m=0,b=h.length;m<b;m++){const G=h[m];a[m]!==!0&&pl(G,u,p),p+=G.count}}return t}function Mu(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 Tu(n){const{index:e,attributes:t}=n;if(e)for(let i=0,s=e.count;i<s;i+=3){const o=e.getX(i),a=e.getX(i+2);e.setX(i,a),e.setX(i+2,o)}else for(const i in t){const s=t[i],o=s.itemSize;for(let a=0,c=s.count;a<c;a+=3)for(let r=0;r<o;r++){const l=s.getComponent(a,r),d=s.getComponent(a+2,r);s.setComponent(a,r,d),s.setComponent(a+2,r,l)}}return n}class Yu{constructor(e){this.matrixWorld=new Te,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,s=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=s,i){i.boneTexture||i.computeBoneTexture(),i.update();const o=i.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==o.length?this.boneMatrices=o.slice():this.boneMatrices.set(o)}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&&Mu(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(s=>{s.isMesh&&t.push(s)})}),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 Ot),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 Ot){let t=[];const{meshes:i,useGroups:s,_intermediateGeometry:o,_diffMap:a}=this;for(let c=0,r=i.length;c<r;c++){const l=i[c],d=o[c],h=a.get(l);!h||h.didChange(l)?(this._convertToStaticGeometry(l,d),t.push(!1),h?h.update():a.set(l,new Yu(l))):t.push(!0)}if(o.length===0){e.setIndex(null);const c=e.attributes;for(const r in c)e.deleteAttribute(r);for(const r in this.attributes)e.setAttribute(this.attributes[r],new be(new Float32Array(0),4,!1))}else Ku(o,{useGroups:s,skipAttributes:t},e);for(const c in e.attributes)e.attributes[c].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new Ot){const i=e.geometry,s=this.applyWorldTransforms,o=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),c=i.attributes,r=t.attributes;!t.index&&i.index&&(t.index=i.index.clone()),r.position||t.setAttribute("position",Qi(c.position)),o&&!r.normal&&c.normal&&t.setAttribute("normal",Qi(c.normal)),a&&!r.tangent&&c.tangent&&t.setAttribute("tangent",Qi(c.tangent)),Fi(i.index,t.index),Fi(c.position,r.position),o&&Fi(c.normal,r.normal),a&&Fi(c.tangent,r.tangent);const l=c.position,d=o?c.normal:null,h=a?c.tangent:null,u=i.morphAttributes.position,p=i.morphAttributes.normal,m=i.morphAttributes.tangent,b=i.morphTargetsRelative,G=e.morphTargetInfluences,y=new Hl;y.getNormalMatrix(e.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let Z=0,X=c.position.count;Z<X;Z++)Ut.fromBufferAttribute(l,Z),d&&Pt.fromBufferAttribute(d,Z),h&&(cl.fromBufferAttribute(h,Z),wt.fromBufferAttribute(h,Z)),G&&(u&&Ho(u,G,b,Z,Ut),p&&Ho(p,G,b,Z,Pt),m&&Ho(m,G,b,Z,wt)),e.isSkinnedMesh&&(e.applyBoneTransform(Z,Ut),d&&ml(e,Z,Pt),h&&ml(e,Z,wt)),s&&Ut.applyMatrix4(e.matrixWorld),r.position.setXYZ(Z,Ut.x,Ut.y,Ut.z),d&&(s&&Pt.applyNormalMatrix(y),r.normal.setXYZ(Z,Pt.x,Pt.y,Pt.z)),h&&(s&&wt.transformDirection(e.matrixWorld),r.tangent.setXYZW(Z,wt.x,wt.y,wt.z,cl.w));for(const Z in this.attributes){const X=this.attributes[Z];X==="position"||X==="tangent"||X==="normal"||!(X in c)||(r[X]||t.setAttribute(X,Qi(c[X])),Fi(c[X],r[X]),pl(c[X],r[X]))}return e.matrixWorld.determinant()<0&&Tu(t),t}}const bl=`
|
|
1121
|
+
}`;class Od extends gr{constructor(e){super(e),this.vector_=new T,this.vector2_=new T,this.vector3_=new T,this.quaternion_=new F,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Ot,this.indexBuffer=new be(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(Ve),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new be(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(Ve),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new be(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(Ve),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new be(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(Ve),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new be(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(Ve),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new be(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(Ve),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new be(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(Ve),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new be(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(Ve),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 di(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=ro(this.settings.material.map.channel),e.map=new Fe(this.settings.material.map),e.mapTransform=new Fe(new tt().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===v.Trail)this.material=new fs({uniforms:e,defines:t,vertexShader:jd,fragmentShader:Ed,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Uo,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(s=>{for(let o=0;o<s.particleNum;o++)i+=s.particles[o].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(s=>{s.emitter.updateMatrixWorld&&(s.emitter.updateWorldMatrix(!0,!1),s.emitter.updateMatrixWorld(!0));const o=this.quaternion_,a=this.vector2_,c=this.vector3_;s.emitter.matrixWorld.decompose(a,o,c);const r=s.particles,l=s.particleNum,d=this.settings.uTileCount,h=this.settings.vTileCount,u=1/d,p=1/h;for(let m=0;m<l;m++){const b=r[m],G=b.uvTile%h,y=Math.floor(b.uvTile/h+.001),Z=b.previous.values();let X=Z.next(),L=X.value,V=L;X.done||(X=Z.next());let x;X.value!==void 0?x=X.value:x=V;for(let R=0;R<b.previous.length;R++,e+=2){if(this.positionBuffer.setXYZ(e,V.position.x,V.position.y,V.position.z),this.positionBuffer.setXYZ(e+1,V.position.x,V.position.y,V.position.z),s.worldSpace?(this.positionBuffer.setXYZ(e,V.position.x,V.position.y,V.position.z),this.positionBuffer.setXYZ(e+1,V.position.x,V.position.y,V.position.z)):(b.parentMatrix?this.vector_.copy(V.position).applyMatrix4(b.parentMatrix):this.vector_.copy(V.position).applyMatrix4(s.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)),s.worldSpace?(this.previousBuffer.setXYZ(e,L.position.x,L.position.y,L.position.z),this.previousBuffer.setXYZ(e+1,L.position.x,L.position.y,L.position.z)):(b.parentMatrix?this.vector_.copy(L.position).applyMatrix4(b.parentMatrix):this.vector_.copy(L.position).applyMatrix4(s.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)),s.worldSpace?(this.nextBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.nextBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(b.parentMatrix?this.vector_.copy(x.position).applyMatrix4(b.parentMatrix):this.vector_.copy(x.position).applyMatrix4(s.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),s.worldSpace)this.widthBuffer.setX(e,V.size),this.widthBuffer.setX(e+1,V.size);else if(b.parentMatrix)this.widthBuffer.setX(e,V.size),this.widthBuffer.setX(e+1,V.size);else{const S=(Math.abs(c.x)+Math.abs(c.y)+Math.abs(c.z))/3;this.widthBuffer.setX(e,V.size*S),this.widthBuffer.setX(e+1,V.size*S)}this.uvBuffer.setXY(e,(R/b.previous.length+G)*u,(h-y-1)*p),this.uvBuffer.setXY(e+1,(R/b.previous.length+G)*u,(h-y)*p),this.colorBuffer.setXYZW(e,V.color.x,V.color.y,V.color.z,V.color.w),this.colorBuffer.setXYZW(e+1,V.color.x,V.color.y,V.color.z,V.color.w),R+1<b.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++),L=V,V=x,X.done||(X=Z.next(),X.value!==void 0&&(x=X.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 Ln{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new we;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const s=e.getIndex().array,o=s.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<o;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),s[a*3],s[a*3+1],s[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 K,this._tempB=new K,this._tempC=new K,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 s=0,o=i;const a=Math.random()*this._triangleIndexToArea[i];for(;s+1<o;){const p=Math.floor((s+o)/2);a<this._triangleIndexToArea[p]?o=p:s=p}let c=Math.random(),r=Math.random();c+r>1&&(c=1-c,r=1-r);const l=t.getIndex().array[s*3],d=t.getIndex().array[s*3+1],h=t.getIndex().array[s*3+2],u=t.getAttribute("position");this._tempA.fromBufferAttribute(u,l),this._tempB.fromBufferAttribute(u,d),this._tempC.fromBufferAttribute(u,h),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,c).addScaledVector(this._tempC,r),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 Ln(t.geometries[e.geometry])}clone(){return new Ln(this._geometry)}update(e,t){}}fd({id:"three.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Ln,loadJSON:Ln.fromJSON}],behaviors:[]});class No extends Ss{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 s=0;s<this.batches.length;s++)if(No.equals(this.batches[s].settings,t)){this.batches[s].addSystem(e),this.systemToBatchIndex.set(e,s);return}let i;switch(t.renderMode){case v.Trail:i=new Od(t);break;case v.Mesh:case v.BillBoard:case v.VerticalBillBoard:case v.HorizontalBillBoard:case v.StretchedBillBoard:i=new Bd(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 Dd=No;Yd(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const zr=Math.sqrt(5),_d=(zr-1)/4,ue=(5-zr)/20,jn=n=>Math.floor(n)|0,On=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 Ad(n=Math.random){const e=qd(n),t=new Float64Array(e).map(a=>On[a%32*4]),i=new Float64Array(e).map(a=>On[a%32*4+1]),s=new Float64Array(e).map(a=>On[a%32*4+2]),o=new Float64Array(e).map(a=>On[a%32*4+3]);return function(a,c,r,l){let d,h,u,p,m;const b=(a+c+r+l)*_d,G=jn(a+b),y=jn(c+b),Z=jn(r+b),X=jn(l+b),L=(G+y+Z+X)*ue,V=G-L,x=y-L,R=Z-L,S=X-L,W=a-V,f=c-x,C=r-R,g=l-S;let z=0,Y=0,k=0,N=0;W>f?z++:Y++,W>C?z++:k++,W>g?z++:N++,f>C?Y++:k++,f>g?Y++:N++,C>g?k++:N++;const Q=z>=3?1:0,P=Y>=3?1:0,ae=k>=3?1:0,ie=N>=3?1:0,ee=z>=2?1:0,ze=Y>=2?1:0,Se=k>=2?1:0,ne=N>=2?1:0,me=z>=1?1:0,te=Y>=1?1:0,O=k>=1?1:0,mt=N>=1?1:0,_=W-Q+ue,Oe=f-P+ue,it=C-ae+ue,ft=g-ie+ue,Wt=W-ee+2*ue,gt=f-ze+2*ue,Ct=C-Se+2*ue,zt=g-ne+2*ue,vt=W-me+3*ue,Kt=f-te+3*ue,Mt=C-O+3*ue,Tt=g-mt+3*ue,nt=W-1+4*ue,st=f-1+4*ue,ot=C-1+4*ue,at=g-1+4*ue,Ne=G&255,Ie=y&255,Je=Z&255,Ue=X&255;let Pe=.6-W*W-f*f-C*C-g*g;if(Pe<0)d=0;else{const D=Ne+e[Ie+e[Je+e[Ue]]];Pe*=Pe,d=Pe*Pe*(t[D]*W+i[D]*f+s[D]*C+o[D]*g)}let w=.6-_*_-Oe*Oe-it*it-ft*ft;if(w<0)h=0;else{const D=Ne+Q+e[Ie+P+e[Je+ae+e[Ue+ie]]];w*=w,h=w*w*(t[D]*_+i[D]*Oe+s[D]*it+o[D]*ft)}let pi=.6-Wt*Wt-gt*gt-Ct*Ct-zt*zt;if(pi<0)u=0;else{const D=Ne+ee+e[Ie+ze+e[Je+Se+e[Ue+ne]]];pi*=pi,u=pi*pi*(t[D]*Wt+i[D]*gt+s[D]*Ct+o[D]*zt)}let mi=.6-vt*vt-Kt*Kt-Mt*Mt-Tt*Tt;if(mi<0)p=0;else{const D=Ne+me+e[Ie+te+e[Je+O+e[Ue+mt]]];mi*=mi,p=mi*mi*(t[D]*vt+i[D]*Kt+s[D]*Mt+o[D]*Tt)}let bi=.6-nt*nt-st*st-ot*ot-at*at;if(bi<0)m=0;else{const D=Ne+1+e[Ie+1+e[Je+1+e[Ue+1]]];bi*=bi,m=bi*bi*(t[D]*nt+i[D]*st+s[D]*ot+o[D]*at)}return 27*(d+h+u+p+m)}}function qd(n){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const i=t+~~(n()*(256-t)),s=e[t];e[t]=e[i],e[i]=s}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class $d{constructor(e){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Backoff must be a positive integer");this.backoff=e}get retries(){return this._retries}get current(){return this.backoff}next(){return this._retries++,this.backoff}reset(){this._retries=0}}class eh{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}}class th{constructor(e,t,i){if(this.i=0,this._retries=0,e<0)throw new Error("Initial must be a positive number or zero");if(t<0)throw new Error("Increment must be a positive number or zero");if(i!==void 0&&i<0)throw new Error("Max must be undefined, a positive number or zero");if(i!==void 0&&i<e)throw new Error("Max must be undefined or greater than or equal to initial");this.initial=e,this.increment=t,this.max=i}get retries(){return this._retries}get current(){return this.max===void 0?this.initial+this.increment*this.i:Math.min(this.initial+this.increment*this.i,this.max)}next(){return this._retries++,this.i++,this.current}reset(){this._retries=0,this.i=0}}class ih{constructor(){this.elements=[]}add(e){this.elements.push(e)}clear(){this.elements.length=0}forEach(e){this.elements.forEach(e)}length(){return this.elements.length}isEmpty(){return this.elements.length===0}peek(){return this.elements[0]}read(){return this.elements.shift()}}class nh{constructor(e){if(!Number.isInteger(e)||e<=0)throw new Error("Capacity must be a positive integer");this.elements=new Array(e+1),this.head=0,this.tail=0}add(e){this.elements[this.head]=e,this.head=(this.head+1)%this.elements.length,this.head===this.tail&&(this.tail=(this.tail+1)%this.elements.length)}clear(){this.head=0,this.tail=0}forEach(e){for(let t=this.tail;t!==this.head;t=(t+1)%this.elements.length)e(this.elements[t])}length(){return this.tail===this.head?0:this.tail<this.head?this.head-this.tail:this.elements.length-this.tail+this.head}isEmpty(){return this.head===this.tail}peek(){return this.isEmpty()?void 0:this.elements[this.tail]}read(){const e=this.peek();return e!==void 0&&(this.tail=(this.tail+1)%this.elements.length),e}}var B;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(B||(B={}));class vr{constructor(e,t,i){var s,o,a,c,r,l,d,h,u,p,m,b,G,y,Z;this._closedByUser=!1,this.handleOpenEvent=X=>this.handleEvent(B.open,X),this.handleErrorEvent=X=>this.handleEvent(B.error,X),this.handleCloseEvent=X=>this.handleEvent(B.close,X),this.handleMessageEvent=X=>this.handleEvent(B.message,X),this._url=e,this._protocols=t,this._options={buffer:i?.buffer,retry:{maxRetries:(s=i?.retry)===null||s===void 0?void 0:s.maxRetries,instantReconnect:(o=i?.retry)===null||o===void 0?void 0:o.instantReconnect,backoff:(a=i?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(r=(c=i?.listeners)===null||c===void 0?void 0:c.open)!==null&&r!==void 0?r:[]],close:[...(d=(l=i?.listeners)===null||l===void 0?void 0:l.close)!==null&&d!==void 0?d:[]],error:[...(u=(h=i?.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[]],message:[...(m=(p=i?.listeners)===null||p===void 0?void 0:p.message)!==null&&m!==void 0?m:[]],retry:[...(G=(b=i?.listeners)===null||b===void 0?void 0:b.retry)!==null&&G!==void 0?G:[]],reconnect:[...(Z=(y=i?.listeners)===null||y===void 0?void 0:y.reconnect)!==null&&Z!==void 0?Z:[]]}},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 s=o=>o.listener!==t||o.options!==i;this._options.listeners[e]=this._options.listeners[e].filter(s)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(B.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(B.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(B.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(B.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(B.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(B.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(B.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(B.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const i=this._options.listeners[e],s=[];i.forEach(({listener:o,options:a})=>{o(this,t),(a===void 0||a.once===void 0||!a.once)&&s.push({listener:o,options:a})}),this._options.listeners[e]=s}handleEvent(e,t){switch(e){case B.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case B.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},s=new CustomEvent(B.reconnect,{detail:i});this.dispatchEvent(B.reconnect,s),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case B.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 s=new CustomEvent(B.retry,{detail:i});this.handleEvent(B.retry,s)},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 sh{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(B.open,e,t),this}onClose(e,t){return this.addListener(B.close,e,t),this}onError(e,t){return this.addListener(B.error,e,t),this}onMessage(e,t){return this.addListener(B.message,e,t),this}onRetry(e,t){return this.addListener(B.retry,e,t),this}onReconnect(e,t){return this.addListener(B.reconnect,e,t),this}build(){return new vr(this._url,this._protocols,this._options)}addListener(e,t,i){var s,o,a,c,r,l,d,h,u,p,m,b,G,y,Z,X,L,V,x,R,S;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(o=(s=this._options)===null||s===void 0?void 0:s.listeners)===null||o===void 0?void 0:o.open)!==null&&a!==void 0?a:[],close:(l=(r=(c=this._options)===null||c===void 0?void 0:c.listeners)===null||r===void 0?void 0:r.close)!==null&&l!==void 0?l:[],error:(u=(h=(d=this._options)===null||d===void 0?void 0:d.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[],message:(b=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.message)!==null&&b!==void 0?b:[],retry:(Z=(y=(G=this._options)===null||G===void 0?void 0:G.listeners)===null||y===void 0?void 0:y.retry)!==null&&Z!==void 0?Z:[],reconnect:(V=(L=(X=this._options)===null||X===void 0?void 0:X.listeners)===null||L===void 0?void 0:L.reconnect)!==null&&V!==void 0?V:[],[e]:[...(S=(R=(x=this._options)===null||x===void 0?void 0:x.listeners)===null||R===void 0?void 0:R[e])!==null&&S!==void 0?S:[],{listener:t,options:i}]}}),this}}const oh=Object.freeze(Object.defineProperty({__proto__:null,ArrayQueue:ih,ConstantBackoff:$d,ExponentialBackoff:eh,LinearBackoff:th,RingQueue:nh,Websocket:vr,WebsocketBuilder:sh,get WebsocketEvent(){return B}},Symbol.toStringTag,{value:"Module"})),lo=0,Kr=1,Mr=2,ah=0,rh=1,co=2,Dn=1.25,ho=1,Zt=6*4+4+4,_n=65535,lh=Math.pow(2,-24),uo=Symbol("SKIP_GENERATION");function Tr(n){return n.index?n.index.count:n.attributes.position.count}function ei(n){return Tr(n)/3}function Yr(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function ch(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Yr(t,i);n.setIndex(new be(s,1));for(let o=0;o<t;o++)s[o]=o}}function Hr(n,e){const t=ei(n),i=e||n.drawRange,s=i.start/3,o=(i.start+i.count)/3,a=Math.max(0,s),c=Math.min(t,o)-a;return[{offset:Math.floor(a),count:Math.floor(c)}]}function kr(n,e){if(!n.groups||!n.groups.length)return Hr(n,e);const t=[],i=new Set,s=e||n.drawRange,o=s.start/3,a=(s.start+s.count)/3;for(const r of n.groups){const l=r.start/3,d=(r.start+r.count)/3;i.add(Math.max(o,l)),i.add(Math.min(a,d))}const c=Array.from(i.values()).sort((r,l)=>r-l);for(let r=0;r<c.length-1;r++){const l=c[r],d=c[r+1];t.push({offset:Math.floor(l),count:Math.floor(d-l)})}return t}function dh(n,e){const t=ei(n),i=kr(n,e).sort((a,c)=>a.offset-c.offset),s=i[i.length-1];s.count=Math.min(t-s.offset,s.count);let o=0;return i.forEach(({count:a})=>o+=a),t!==o}function po(n,e,t,i,s){let o=1/0,a=1/0,c=1/0,r=-1/0,l=-1/0,d=-1/0,h=1/0,u=1/0,p=1/0,m=-1/0,b=-1/0,G=-1/0;for(let y=e*6,Z=(e+t)*6;y<Z;y+=6){const X=n[y+0],L=n[y+1],V=X-L,x=X+L;V<o&&(o=V),x>r&&(r=x),X<h&&(h=X),X>m&&(m=X);const R=n[y+2],S=n[y+3],W=R-S,f=R+S;W<a&&(a=W),f>l&&(l=f),R<u&&(u=R),R>b&&(b=R);const C=n[y+4],g=n[y+5],z=C-g,Y=C+g;z<c&&(c=z),Y>d&&(d=Y),C<p&&(p=C),C>G&&(G=C)}i[0]=o,i[1]=a,i[2]=c,i[3]=r,i[4]=l,i[5]=d,s[0]=h,s[1]=u,s[2]=p,s[3]=m,s[4]=b,s[5]=G}function hh(n,e=null,t=null,i=null){const s=n.attributes.position,o=n.index?n.index.array:null,a=ei(n),c=s.normalized;let r;e===null?(r=new Float32Array(a*6),t=0,i=a):(r=e,t=t||0,i=i||a);const l=s.array,d=s.offset||0;let h=3;s.isInterleavedBufferAttribute&&(h=s.data.stride);const u=["getX","getY","getZ"];for(let p=t;p<t+i;p++){const m=p*3,b=p*6;let G=m+0,y=m+1,Z=m+2;o&&(G=o[G],y=o[y],Z=o[Z]),c||(G=G*h+d,y=y*h+d,Z=Z*h+d);for(let X=0;X<3;X++){let L,V,x;c?(L=s[u[X]](G),V=s[u[X]](y),x=s[u[X]](Z)):(L=l[G+X],V=l[y+X],x=l[Z+X]);let R=L;V<R&&(R=V),x<R&&(R=x);let S=L;V>S&&(S=V),x>S&&(S=x);const W=(S-R)/2,f=X*2;r[b+f+0]=R+W,r[b+f+1]=W+(Math.abs(R)+W)*lh}}return r}function E(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 Nr(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=n[i+3]-n[i];s>t&&(t=s,e=i)}return e}function Ir(n,e){e.set(n)}function Jr(n,e,t){let i,s;for(let o=0;o<3;o++){const a=o+3;i=n[o],s=e[o],t[o]=i<s?i:s,i=n[a],s=e[a],t[a]=i>s?i:s}}function An(n,e,t){for(let i=0;i<3;i++){const s=e[n+2*i],o=e[n+2*i+1],a=s-o,c=s+o;a<t[i]&&(t[i]=a),c>t[i+3]&&(t[i+3]=c)}}function vi(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 ht=32,uh=(n,e)=>n.candidate-e.candidate,Xt=new Array(ht).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),qn=new Float32Array(6);function ph(n,e,t,i,s,o){let a=-1,c=0;if(o===lo)a=Nr(e),a!==-1&&(c=(e[a]+e[a+3])/2);else if(o===Kr)a=Nr(n),a!==-1&&(c=mh(t,i,s,a));else if(o===Mr){const r=vi(n);let l=Dn*s;const d=i*6,h=(i+s)*6;for(let u=0;u<3;u++){const p=e[u],m=(e[u+3]-p)/ht;if(s<ht/4){const b=[...Xt];b.length=s;let G=0;for(let Z=d;Z<h;Z+=6,G++){const X=b[G];X.candidate=t[Z+2*u],X.count=0;const{bounds:L,leftCacheBounds:V,rightCacheBounds:x}=X;for(let R=0;R<3;R++)x[R]=1/0,x[R+3]=-1/0,V[R]=1/0,V[R+3]=-1/0,L[R]=1/0,L[R+3]=-1/0;An(Z,t,L)}b.sort(uh);let y=s;for(let Z=0;Z<y;Z++){const X=b[Z];for(;Z+1<y&&b[Z+1].candidate===X.candidate;)b.splice(Z+1,1),y--}for(let Z=d;Z<h;Z+=6){const X=t[Z+2*u];for(let L=0;L<y;L++){const V=b[L];X>=V.candidate?An(Z,t,V.rightCacheBounds):(An(Z,t,V.leftCacheBounds),V.count++)}}for(let Z=0;Z<y;Z++){const X=b[Z],L=X.count,V=s-X.count,x=X.leftCacheBounds,R=X.rightCacheBounds;let S=0;L!==0&&(S=vi(x)/r);let W=0;V!==0&&(W=vi(R)/r);const f=ho+Dn*(S*L+W*V);f<l&&(a=u,l=f,c=X.candidate)}}else{for(let y=0;y<ht;y++){const Z=Xt[y];Z.count=0,Z.candidate=p+m+y*m;const X=Z.bounds;for(let L=0;L<3;L++)X[L]=1/0,X[L+3]=-1/0}for(let y=d;y<h;y+=6){let Z=~~((t[y+2*u]-p)/m);Z>=ht&&(Z=ht-1);const X=Xt[Z];X.count++,An(y,t,X.bounds)}const b=Xt[ht-1];Ir(b.bounds,b.rightCacheBounds);for(let y=ht-2;y>=0;y--){const Z=Xt[y],X=Xt[y+1];Jr(Z.bounds,X.rightCacheBounds,Z.rightCacheBounds)}let G=0;for(let y=0;y<ht-1;y++){const Z=Xt[y],X=Z.count,L=Z.bounds,V=Xt[y+1].rightCacheBounds;X!==0&&(G===0?Ir(L,qn):Jr(L,qn,qn)),G+=X;let x=0,R=0;G!==0&&(x=vi(qn)/r);const S=s-G;S!==0&&(R=vi(V)/r);const W=ho+Dn*(x*G+R*S);W<l&&(a=u,l=W,c=Z.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:a,pos:c}}function mh(n,e,t,i){let s=0;for(let o=e,a=e+t;o<a;o++)s+=n[o*6+i*2];return s/t}class mo{constructor(){this.boundingData=new Float32Array(6)}}function bh(n,e,t,i,s,o){let a=i,c=i+s-1;const r=o.pos,l=o.axis*2;for(;;){for(;a<=c&&t[a*6+l]<r;)a++;for(;a<=c&&t[c*6+l]>=r;)c--;if(a<c){for(let d=0;d<3;d++){let h=e[a*3+d];e[a*3+d]=e[c*3+d],e[c*3+d]=h}for(let d=0;d<6;d++){let h=t[a*6+d];t[a*6+d]=t[c*6+d],t[c*6+d]=h}a++,c--}else return a}}function yh(n,e,t,i,s,o){let a=i,c=i+s-1;const r=o.pos,l=o.axis*2;for(;;){for(;a<=c&&t[a*6+l]<r;)a++;for(;a<=c&&t[c*6+l]>=r;)c--;if(a<c){let d=n[a];n[a]=n[c],n[c]=d;for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[c*6+h],t[c*6+h]=u}a++,c--}else return a}}function xe(n,e){return e[n+15]===65535}function ge(n,e){return e[n+6]}function Ke(n,e){return e[n+14]}function Ye(n){return n+8}function Me(n,e){return e[n+6]}function bo(n,e){return e[n+7]}let Ur,Ki,$n,Pr;const Gh=Math.pow(2,32);function yo(n){return"count"in n?1:1+yo(n.left)+yo(n.right)}function Zh(n,e,t){return Ur=new Float32Array(t),Ki=new Uint32Array(t),$n=new Uint16Array(t),Pr=new Uint8Array(t),Go(n,e)}function Go(n,e){const t=n/4,i=n/2,s="count"in e,o=e.boundingData;for(let a=0;a<6;a++)Ur[t+a]=o[a];if(s)if(e.buffer){const a=e.buffer;Pr.set(new Uint8Array(a),n);for(let c=n,r=n+a.byteLength;c<r;c+=Zt){const l=c/2;xe(l,$n)||(Ki[c/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,c=e.count;return Ki[t+6]=a,$n[i+14]=c,$n[i+15]=_n,n+Zt}else{const a=e.left,c=e.right,r=e.splitAxis;let l;if(l=Go(n+Zt,a),l/4>Gh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Ki[t+6]=l/4,l=Go(l,c),Ki[t+7]=r,l}}function Xh(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,i=t>2**16,s=i?4:2,o=e?new SharedArrayBuffer(t*s):new ArrayBuffer(t*s),a=i?new Uint32Array(o):new Uint16Array(o);for(let c=0,r=a.length;c<r;c++)a[c]=c;return a}function Vh(n,e,t,i,s){const{maxDepth:o,verbose:a,maxLeafTris:c,strategy:r,onProgress:l,indirect:d}=s,h=n._indirectBuffer,u=n.geometry,p=u.index?u.index.array:null,m=d?yh:bh,b=ei(u),G=new Float32Array(6);let y=!1;const Z=new mo;return po(e,t,i,Z.boundingData,G),L(Z,t,i,G),Z;function X(V){l&&l(V/b)}function L(V,x,R,S=null,W=0){if(!y&&W>=o&&(y=!0,a&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),R<=c||W>=o)return X(x+R),V.offset=x,V.count=R,V;const f=ph(V.boundingData,S,e,x,R,r);if(f.axis===-1)return X(x+R),V.offset=x,V.count=R,V;const C=m(h,p,e,x,R,f);if(C===x||C===x+R)X(x+R),V.offset=x,V.count=R;else{V.splitAxis=f.axis;const g=new mo,z=x,Y=C-x;V.left=g,po(e,z,Y,g.boundingData,G),L(g,z,Y,G,W+1);const k=new mo,N=C,Q=R-Y;V.right=k,po(e,N,Q,k.boundingData,G),L(k,N,Q,G,W+1)}return V}}function Rh(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Xh(t,e.useSharedArrayBuffer),dh(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||ch(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=hh(t),o=e.indirect?Hr(t,e.range):kr(t,e.range);n._roots=o.map(a=>{const c=Vh(n,s,a.offset,a.count,e),r=yo(c),l=new i(Zt*r);return Zh(0,c,l),l})}class ut{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let o=0,a=e.length;o<a;o++){const c=e[o][t];i=c<i?c:i,s=c>s?c:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let o=0,a=t.length;o<a;o++){const c=t[o],r=e.dot(c);i=r<i?r:i,s=r>s?r:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}ut.prototype.setFromBox=function(){const n=new K;return function(e,t){const i=t.min,s=t.max;let o=1/0,a=-1/0;for(let c=0;c<=1;c++)for(let r=0;r<=1;r++)for(let l=0;l<=1;l++){n.x=i.x*c+s.x*(1-c),n.y=i.y*r+s.y*(1-r),n.z=i.z*l+s.z*(1-l);const d=e.dot(n);o=Math.min(d,o),a=Math.max(d,a)}this.min=o,this.max=a}}();const Lh=function(){const n=new K,e=new K,t=new K;return function(i,s,o){const a=i.start,c=n,r=s.start,l=e;t.subVectors(a,r),n.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const d=t.dot(l),h=l.dot(c),u=l.dot(l),p=t.dot(c),m=c.dot(c)*u-h*h;let b,G;m!==0?b=(d*h-p*u)/m:b=0,G=(d+b*h)/u,o.x=b,o.y=G}}(),Zo=function(){const n=new De,e=new K,t=new K;return function(i,s,o,a){Lh(i,s,n);let c=n.x,r=n.y;if(c>=0&&c<=1&&r>=0&&r<=1){i.at(c,o),s.at(r,a);return}else if(c>=0&&c<=1){r<0?s.at(0,a):s.at(1,a),i.closestPointToPoint(a,!0,o);return}else if(r>=0&&r<=1){c<0?i.at(0,o):i.at(1,o),s.closestPointToPoint(o,!0,a);return}else{let l;c<0?l=i.start:l=i.end;let d;r<0?d=s.start:d=s.end;const h=e,u=t;if(i.closestPointToPoint(d,!0,e),s.closestPointToPoint(l,!0,t),h.distanceToSquared(d)<=u.distanceToSquared(l)){o.copy(h),a.copy(d);return}else{o.copy(l),a.copy(u);return}}}}(),xh=function(){const n=new K,e=new K,t=new Po,i=new rt;return function(s,o){const{radius:a,center:c}=s,{a:r,b:l,c:d}=o;if(i.start=r,i.end=l,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a||(i.start=r,i.end=d,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a)||(i.start=l,i.end=d,i.closestPointToPoint(c,!0,n).distanceTo(c)<=a))return!0;const h=o.getPlane(t);if(Math.abs(h.distanceToPoint(c))<=a){const u=h.projectPoint(c,e);if(o.containsPoint(u))return!0}return!1}}(),Sh=1e-15;function Xo(n){return Math.abs(n)<Sh}class He extends we{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new K),this.satBounds=new Array(4).fill().map(()=>new ut),this.points=[this.a,this.b,this.c],this.sphere=new wo,this.plane=new Po,this.needsUpdate=!0}intersectsSphere(e){return xh(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,o=this.satAxes,a=this.satBounds,c=o[0],r=a[0];this.getNormal(c),r.setFromPoints(c,s);const l=o[1],d=a[1];l.subVectors(e,t),d.setFromPoints(l,s);const h=o[2],u=a[2];h.subVectors(t,i),u.setFromPoints(h,s);const p=o[3],m=a[3];p.subVectors(i,e),m.setFromPoints(p,s),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}He.prototype.closestPointToSegment=function(){const n=new K,e=new K,t=new rt;return function(i,s=null,o=null){const{start:a,end:c}=i,r=this.points;let l,d=1/0;for(let h=0;h<3;h++){const u=(h+1)%3;t.start.copy(r[h]),t.end.copy(r[u]),Zo(t,i,n,e),l=n.distanceToSquared(e),l<d&&(d=l,s&&s.copy(n),o&&o.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<d&&(d=l,s&&s.copy(n),o&&o.copy(a)),this.closestPointToPoint(c,n),l=c.distanceToSquared(n),l<d&&(d=l,s&&s.copy(n),o&&o.copy(c)),Math.sqrt(d)}}(),He.prototype.intersectsTriangle=function(){const n=new He,e=new Array(3),t=new Array(3),i=new ut,s=new ut,o=new K,a=new K,c=new K,r=new K,l=new K,d=new rt,h=new rt,u=new rt,p=new K;function m(b,G,y){const Z=b.points;let X=0,L=-1;for(let V=0;V<3;V++){const{start:x,end:R}=d;x.copy(Z[V]),R.copy(Z[(V+1)%3]),d.delta(a);const S=Xo(G.distanceToPoint(x));if(Xo(G.normal.dot(a))&&S){y.copy(d),X=2;break}const W=G.intersectLine(d,p);if(!W&&S&&p.copy(x),(W||S)&&!Xo(p.distanceTo(R))){if(X<=1)(X===1?y.start:y.end).copy(p),S&&(L=X);else if(X>=2){(L===1?y.start:y.end).copy(p),X=2;break}if(X++,X===2&&L===-1)break}}return X}return function(b,G=null,y=!1){this.needsUpdate&&this.update(),b.isExtendedTriangle?b.needsUpdate&&b.update():(n.copy(b),n.update(),b=n);const Z=this.plane,X=b.plane;if(Math.abs(Z.normal.dot(X.normal))>1-1e-10){const L=this.satBounds,V=this.satAxes;t[0]=b.a,t[1]=b.b,t[2]=b.c;for(let S=0;S<4;S++){const W=L[S],f=V[S];if(i.setFromPoints(f,t),W.isSeparated(i))return!1}const x=b.satBounds,R=b.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let S=0;S<4;S++){const W=x[S],f=R[S];if(i.setFromPoints(f,e),W.isSeparated(i))return!1}for(let S=0;S<4;S++){const W=V[S];for(let f=0;f<4;f++){const C=R[f];if(o.crossVectors(W,C),i.setFromPoints(o,e),s.setFromPoints(o,t),i.isSeparated(s))return!1}}return G&&(y||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),G.start.set(0,0,0),G.end.set(0,0,0)),!0}else{const L=m(this,X,h);if(L===1&&b.containsPoint(h.end))return G&&(G.start.copy(h.end),G.end.copy(h.end)),!0;if(L!==2)return!1;const V=m(b,Z,u);if(V===1&&this.containsPoint(u.end))return G&&(G.start.copy(u.end),G.end.copy(u.end)),!0;if(V!==2)return!1;if(h.delta(c),u.delta(r),c.dot(r)<0){let g=u.start;u.start=u.end,u.end=g}const x=h.start.dot(c),R=h.end.dot(c),S=u.start.dot(c),W=u.end.dot(c),f=R<S,C=x<W;return x!==W&&S!==R&&f===C?!1:(G&&(l.subVectors(h.start,u.start),l.dot(c)>0?G.start.copy(h.start):G.start.copy(u.start),l.subVectors(h.end,u.end),l.dot(c)<0?G.end.copy(h.end):G.end.copy(u.end)),!0)}}}(),He.prototype.distanceToPoint=function(){const n=new K;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),He.prototype.distanceToTriangle=function(){const n=new K,e=new K,t=["a","b","c"],i=new rt,s=new rt;return function(o,a=null,c=null){const r=a||c?i:null;if(this.intersectsTriangle(o,r))return(a||c)&&(a&&r.getCenter(a),c&&r.getCenter(c)),0;let l=1/0;for(let d=0;d<3;d++){let h;const u=t[d],p=o[u];this.closestPointToPoint(p,n),h=p.distanceToSquared(n),h<l&&(l=h,a&&a.copy(n),c&&c.copy(p));const m=this[u];o.closestPointToPoint(m,n),h=m.distanceToSquared(n),h<l&&(l=h,a&&a.copy(m),c&&c.copy(n))}for(let d=0;d<3;d++){const h=t[d],u=t[(d+1)%3];i.set(this[h],this[u]);for(let p=0;p<3;p++){const m=t[p],b=t[(p+1)%3];s.set(o[m],o[b]),Zo(i,s,n,e);const G=n.distanceToSquared(e);G<l&&(l=G,a&&a.copy(n),c&&c.copy(e))}}return Math.sqrt(l)}}();class Xe{constructor(e,t,i){this.isOrientedBox=!0,this.min=new K,this.max=new K,this.matrix=new Te,this.invMatrix=new Te,this.points=new Array(8).fill().map(()=>new K),this.satAxes=new Array(3).fill().map(()=>new K),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}}Xe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,i=this.points;for(let r=0;r<=1;r++)for(let l=0;l<=1;l++)for(let d=0;d<=1;d++){const h=1*r|2*l|4*d,u=i[h];u.x=r?t.x:e.x,u.y=l?t.y:e.y,u.z=d?t.z:e.z,u.applyMatrix4(n)}const s=this.satBounds,o=this.satAxes,a=i[0];for(let r=0;r<3;r++){const l=o[r],d=s[r],h=1<<r,u=i[h];l.subVectors(a,u),d.setFromPoints(l,i)}const c=this.alignedSatBounds;c[0].setFromPointsField(i,"x"),c[1].setFromPointsField(i,"y"),c[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Xe.prototype.intersectsBox=function(){const n=new ut;return function(e){this.needsUpdate&&this.update();const t=e.min,i=e.max,s=this.satBounds,o=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=i.x,a[0].isSeparated(n)||(n.min=t.y,n.max=i.y,a[1].isSeparated(n))||(n.min=t.z,n.max=i.z,a[2].isSeparated(n)))return!1;for(let c=0;c<3;c++){const r=o[c],l=s[c];if(n.setFromBox(r,e),l.isSeparated(n))return!1}return!0}}(),Xe.prototype.intersectsTriangle=function(){const n=new He,e=new Array(3),t=new ut,i=new ut,s=new K;return function(o){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(n.copy(o),n.update(),o=n);const a=this.satBounds,c=this.satAxes;e[0]=o.a,e[1]=o.b,e[2]=o.c;for(let h=0;h<3;h++){const u=a[h],p=c[h];if(t.setFromPoints(p,e),u.isSeparated(t))return!1}const r=o.satBounds,l=o.satAxes,d=this.points;for(let h=0;h<3;h++){const u=r[h],p=l[h];if(t.setFromPoints(p,d),u.isSeparated(t))return!1}for(let h=0;h<3;h++){const u=c[h];for(let p=0;p<4;p++){const m=l[p];if(s.crossVectors(u,m),t.setFromPoints(s,e),i.setFromPoints(s,d),t.isSeparated(i))return!1}}return!0}}(),Xe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Xe.prototype.distanceToPoint=function(){const n=new K;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Xe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new rt),t=new Array(12).fill().map(()=>new rt),i=new K,s=new K;return function(o,a=0,c=null,r=null){if(this.needsUpdate&&this.update(),this.intersectsBox(o))return(c||r)&&(o.getCenter(s),this.closestPointToPoint(s,i),o.closestPointToPoint(i,s),c&&c.copy(i),r&&r.copy(s)),0;const l=a*a,d=o.min,h=o.max,u=this.points;let p=1/0;for(let b=0;b<8;b++){const G=u[b];s.copy(G).clamp(d,h);const y=G.distanceToSquared(s);if(y<p&&(p=y,c&&c.copy(G),r&&r.copy(s),y<l))return Math.sqrt(y)}let m=0;for(let b=0;b<3;b++)for(let G=0;G<=1;G++)for(let y=0;y<=1;y++){const Z=(b+1)%3,X=(b+2)%3,L=G<<Z|y<<X,V=1<<b|G<<Z|y<<X,x=u[L],R=u[V];e[m].set(x,R);const S=n[b],W=n[Z],f=n[X],C=t[m],g=C.start,z=C.end;g[S]=d[S],g[W]=G?d[W]:h[W],g[f]=y?d[f]:h[W],z[S]=h[S],z[W]=G?d[W]:h[W],z[f]=y?d[f]:h[W],m++}for(let b=0;b<=1;b++)for(let G=0;G<=1;G++)for(let y=0;y<=1;y++){s.x=b?h.x:d.x,s.y=G?h.y:d.y,s.z=y?h.z:d.z,this.closestPointToPoint(s,i);const Z=s.distanceToSquared(i);if(Z<p&&(p=Z,c&&c.copy(i),r&&r.copy(s),Z<l))return Math.sqrt(Z)}for(let b=0;b<12;b++){const G=e[b];for(let y=0;y<12;y++){const Z=t[y];Zo(G,Z,i,s);const X=i.distanceToSquared(s);if(X<p&&(p=X,c&&c.copy(i),r&&r.copy(s),X<l))return Math.sqrt(X)}}return Math.sqrt(p)}}();class Vo{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 fh extends Vo{constructor(){super(()=>new He)}}const ke=new fh;class Wh{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 j=new Wh;let Vt,ti;const ii=[],es=new Vo(()=>new fe);function gh(n,e,t,i,s,o){Vt=es.getPrimitive(),ti=es.getPrimitive(),ii.push(Vt,ti),j.setBuffer(n._roots[e]);const a=Ro(0,n.geometry,t,i,s,o);j.clearBuffer(),es.releasePrimitive(Vt),es.releasePrimitive(ti),ii.pop(),ii.pop();const c=ii.length;return c>0&&(ti=ii[c-1],Vt=ii[c-2]),a}function Ro(n,e,t,i,s=null,o=0,a=0){const{float32Array:c,uint16Array:r,uint32Array:l}=j;let d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);return E(n,c,Vt),i(h,u,!1,a,o+n,Vt)}else{let h=function(C){const{uint16Array:g,uint32Array:z}=j;let Y=C*2;for(;!xe(Y,g);)C=Ye(C),Y=C*2;return ge(C,z)},u=function(C){const{uint16Array:g,uint32Array:z}=j;let Y=C*2;for(;!xe(Y,g);)C=Me(C,z),Y=C*2;return ge(C,z)+Ke(Y,g)};const p=Ye(n),m=Me(n,l);let b=p,G=m,y,Z,X,L;if(s&&(X=Vt,L=ti,E(b,c,X),E(G,c,L),y=s(X),Z=s(L),Z<y)){b=m,G=p;const C=y;y=Z,Z=C,X=L}X||(X=Vt,E(b,c,X));const V=xe(b*2,r),x=t(X,V,y,a+1,o+b);let R;if(x===co){const C=h(b),g=u(b)-C;R=i(C,g,!0,a+1,o+b,X)}else R=x&&Ro(b,e,t,i,s,o,a+1);if(R)return!0;L=ti,E(G,c,L);const S=xe(G*2,r),W=t(L,S,Z,a+1,o+G);let f;if(W===co){const C=h(G),g=u(G)-C;f=i(C,g,!0,a+1,o+G,L)}else f=W&&Ro(G,e,t,i,s,o,a+1);return!!f}}const Mi=new K,Lo=new K;function Ch(n,e,t={},i=0,s=1/0){const o=i*i,a=s*s;let c=1/0,r=null;if(n.shapecast({boundsTraverseOrder:d=>(Mi.copy(e).clamp(d.min,d.max),Mi.distanceToSquared(e)),intersectsBounds:(d,h,u)=>u<c&&u<a,intersectsTriangle:(d,h)=>{d.closestPointToPoint(e,Mi);const u=e.distanceToSquared(Mi);return u<c&&(Lo.copy(Mi),c=u,r=h),u<o}}),c===1/0)return null;const l=Math.sqrt(c);return t.point?t.point.copy(Lo):t.point=Lo.clone(),t.distance=l,t.faceIndex=r,t}const zh=parseInt(Fo)>=169,Nt=new K,It=new K,Jt=new K,ts=new De,is=new De,ns=new De,wr=new K,Fr=new K,Qr=new K,Ti=new K;function vh(n,e,t,i,s,o,a,c){let r;if(o===fl?r=n.intersectTriangle(i,t,e,!0,s):r=n.intersectTriangle(e,t,i,o!==xs,s),r===null)return null;const l=n.origin.distanceTo(s);return l<a||l>c?null:{distance:l,point:s.clone()}}function Kh(n,e,t,i,s,o,a,c,r,l,d){Nt.fromBufferAttribute(e,o),It.fromBufferAttribute(e,a),Jt.fromBufferAttribute(e,c);const h=vh(n,Nt,It,Jt,Ti,r,l,d);if(h){const u=new K;we.getBarycoord(Ti,Nt,It,Jt,u),i&&(ts.fromBufferAttribute(i,o),is.fromBufferAttribute(i,a),ns.fromBufferAttribute(i,c),h.uv=we.getInterpolation(Ti,Nt,It,Jt,ts,is,ns,new De)),s&&(ts.fromBufferAttribute(s,o),is.fromBufferAttribute(s,a),ns.fromBufferAttribute(s,c),h.uv1=we.getInterpolation(Ti,Nt,It,Jt,ts,is,ns,new De)),t&&(wr.fromBufferAttribute(t,o),Fr.fromBufferAttribute(t,a),Qr.fromBufferAttribute(t,c),h.normal=we.getInterpolation(Ti,Nt,It,Jt,wr,Fr,Qr,new K),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const p={a:o,b:a,c,normal:new K,materialIndex:0};we.getNormal(Nt,It,Jt,p.normal),h.face=p,h.faceIndex=o,zh&&(h.barycoord=u)}return h}function ss(n,e,t,i,s,o,a){const c=i*3;let r=c+0,l=c+1,d=c+2;const h=n.index;n.index&&(r=h.getX(r),l=h.getX(l),d=h.getX(d));const{position:u,normal:p,uv:m,uv1:b}=n.attributes,G=Kh(t,u,p,m,b,r,l,d,e,o,a);return G?(G.faceIndex=i,s&&s.push(G),G):null}function $(n,e,t,i){const s=n.a,o=n.b,a=n.c;let c=e,r=e+1,l=e+2;t&&(c=t.getX(c),r=t.getX(r),l=t.getX(l)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),o.x=i.getX(r),o.y=i.getY(r),o.z=i.getZ(r),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l)}const Yi=new K,Hi=new K,ki=new K,Br=new De,Er=new De,jr=new De;function Mh(n,e,t,i){const s=e.getIndex().array,o=e.getAttribute("position"),a=e.getAttribute("uv"),c=s[t*3],r=s[t*3+1],l=s[t*3+2];Yi.fromBufferAttribute(o,c),Hi.fromBufferAttribute(o,r),ki.fromBufferAttribute(o,l);let d=0;const h=e.groups,u=t*3;for(let b=0,G=h.length;b<G;b++){const y=h[b],{start:Z,count:X}=y;if(u>=Z&&u<Z+X){d=y.materialIndex;break}}const p=i&&i.barycoord?i.barycoord:new K;we.getBarycoord(n,Yi,Hi,ki,p);let m=null;return a&&(Br.fromBufferAttribute(a,c),Er.fromBufferAttribute(a,r),jr.fromBufferAttribute(a,l),i&&i.uv?m=i.uv:m=new De,we.getInterpolation(n,Yi,Hi,ki,Br,Er,jr,m)),i?(i.face||(i.face={}),i.face.a=c,i.face.b=r,i.face.c=l,i.face.materialIndex=d,i.face.normal||(i.face.normal=new K),we.getNormal(Yi,Hi,ki,i.face.normal),m&&(i.uv=m),i.barycoord=p,i):{face:{a:c,b:r,c:l,materialIndex:d,normal:we.getNormal(Yi,Hi,ki,new K)},uv:m,barycoord:p}}function Th(n,e,t,i,s,o,a,c){const{geometry:r,_indirectBuffer:l}=n;for(let d=i,h=i+s;d<h;d++)ss(r,e,t,d,o,a,c)}function Yh(n,e,t,i,s,o,a){const{geometry:c,_indirectBuffer:r}=n;let l=1/0,d=null;for(let h=i,u=i+s;h<u;h++){let p;p=ss(c,e,t,h,null,o,a),p&&p.distance<l&&(d=p,l=p.distance)}return d}function Hh(n,e,t,i,s,o,a){const{geometry:c}=t,{index:r}=c,l=c.attributes.position;for(let d=n,h=e+n;d<h;d++){let u;if(u=d,$(a,u*3,r,l),a.needsUpdate=!0,i(a,u,s,o))return!0}return!1}function kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let o,a,c,r,l=0;const d=n._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],a=new Uint32Array(o),c=new Uint16Array(o),r=new Float32Array(o),h(0,l),l+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(c[b+15]===_n){const G=a[u+6],y=c[b+14];let Z=1/0,X=1/0,L=1/0,V=-1/0,x=-1/0,R=-1/0;for(let S=3*G,W=3*(G+y);S<W;S++){let f=i[S];const C=s.getX(f),g=s.getY(f),z=s.getZ(f);C<Z&&(Z=C),C>V&&(V=C),g<X&&(X=g),g>x&&(x=g),z<L&&(L=z),z>R&&(R=z)}return r[u+0]!==Z||r[u+1]!==X||r[u+2]!==L||r[u+3]!==V||r[u+4]!==x||r[u+5]!==R?(r[u+0]=Z,r[u+1]=X,r[u+2]=L,r[u+3]=V,r[u+4]=x,r[u+5]=R,!0):!1}else{const G=u+8,y=a[u+6],Z=G+p,X=y+p;let L=m,V=!1,x=!1;e?L||(V=e.has(Z),x=e.has(X),L=!V&&!x):(V=!0,x=!0);const R=L||V,S=L||x;let W=!1;R&&(W=h(G,p,L));let f=!1;S&&(f=h(y,p,L));const C=W||f;if(C)for(let g=0;g<3;g++){const z=G+g,Y=y+g,k=r[z],N=r[z+3],Q=r[Y],P=r[Y+3];r[u+g]=k<Q?k:Q,r[u+g+3]=N>P?N:P}return C}}}function Rt(n,e,t,i,s){let o,a,c,r,l,d;const h=1/t.direction.x,u=1/t.direction.y,p=1/t.direction.z,m=t.origin.x,b=t.origin.y,G=t.origin.z;let y=e[n],Z=e[n+3],X=e[n+1],L=e[n+3+1],V=e[n+2],x=e[n+3+2];return h>=0?(o=(y-m)*h,a=(Z-m)*h):(o=(Z-m)*h,a=(y-m)*h),u>=0?(c=(X-b)*u,r=(L-b)*u):(c=(L-b)*u,r=(X-b)*u),o>r||c>a||((c>o||isNaN(o))&&(o=c),(r<a||isNaN(a))&&(a=r),p>=0?(l=(V-G)*p,d=(x-G)*p):(l=(x-G)*p,d=(V-G)*p),o>d||l>a)?!1:((l>o||o!==o)&&(o=l),(d<a||a!==a)&&(a=d),o<=s&&a>=i)}function Nh(n,e,t,i,s,o,a,c){const{geometry:r,_indirectBuffer:l}=n;for(let d=i,h=i+s;d<h;d++){let u=l?l[d]:d;ss(r,e,t,u,o,a,c)}}function Ih(n,e,t,i,s,o,a){const{geometry:c,_indirectBuffer:r}=n;let l=1/0,d=null;for(let h=i,u=i+s;h<u;h++){let p;p=ss(c,e,t,r?r[h]:h,null,o,a),p&&p.distance<l&&(d=p,l=p.distance)}return d}function Jh(n,e,t,i,s,o,a){const{geometry:c}=t,{index:r}=c,l=c.attributes.position;for(let d=n,h=e+n;d<h;d++){let u;if(u=t.resolveTriangleIndex(d),$(a,u*3,r,l),a.needsUpdate=!0,i(a,u,s,o))return!0}return!1}function Uh(n,e,t,i,s,o,a){j.setBuffer(n._roots[e]),xo(0,n,t,i,s,o,a),j.clearBuffer()}function xo(n,e,t,i,s,o,a){const{float32Array:c,uint16Array:r,uint32Array:l}=j,d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);Th(e,t,i,h,u,s,o,a)}else{const h=Ye(n);Rt(h,c,i,o,a)&&xo(h,e,t,i,s,o,a);const u=Me(n,l);Rt(u,c,i,o,a)&&xo(u,e,t,i,s,o,a)}}const Ph=["x","y","z"];function wh(n,e,t,i,s,o){j.setBuffer(n._roots[e]);const a=So(0,n,t,i,s,o);return j.clearBuffer(),a}function So(n,e,t,i,s,o){const{float32Array:a,uint16Array:c,uint32Array:r}=j;let l=n*2;if(xe(l,c)){const d=ge(n,r),h=Ke(l,c);return Yh(e,t,i,d,h,s,o)}else{const d=bo(n,r),h=Ph[d],u=i.direction[h]>=0;let p,m;u?(p=Ye(n),m=Me(n,r)):(p=Me(n,r),m=Ye(n));const b=Rt(p,a,i,s,o)?So(p,e,t,i,s,o):null;if(b){const y=b.point[h];if(u?y<=a[m+d]:y>=a[m+d+3])return b}const G=Rt(m,a,i,s,o)?So(m,e,t,i,s,o):null;return b&&G?b.distance<=G.distance?b:G:b||G||null}}const os=new fe,ni=new He,si=new He,Ni=new Te,Or=new Xe,as=new Xe;function Fh(n,e,t,i){j.setBuffer(n._roots[e]);const s=fo(0,n,t,i);return j.clearBuffer(),s}function fo(n,e,t,i,s=null){const{float32Array:o,uint16Array:a,uint32Array:c}=j;let r=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Or.set(t.boundingBox.min,t.boundingBox.max,i),s=Or),xe(r,a)){const l=e.geometry,d=l.index,h=l.attributes.position,u=t.index,p=t.attributes.position,m=ge(n,c),b=Ke(r,a);if(Ni.copy(i).invert(),t.boundsTree)return E(n,o,as),as.matrix.copy(Ni),as.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:G=>as.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(i),G.b.applyMatrix4(i),G.c.applyMatrix4(i),G.needsUpdate=!0;for(let y=m*3,Z=(b+m)*3;y<Z;y+=3)if($(si,y,d,h),si.needsUpdate=!0,G.intersectsTriangle(si))return!0;return!1}});for(let G=m*3,y=(b+m)*3;G<y;G+=3){$(ni,G,d,h),ni.a.applyMatrix4(Ni),ni.b.applyMatrix4(Ni),ni.c.applyMatrix4(Ni),ni.needsUpdate=!0;for(let Z=0,X=u.count;Z<X;Z+=3)if($(si,Z,u,p),si.needsUpdate=!0,ni.intersectsTriangle(si))return!0}}else{const l=n+8,d=c[n+6];return E(l,o,os),!!(s.intersectsBox(os)&&fo(l,e,t,i,s)||(E(d,o,os),s.intersectsBox(os)&&fo(d,e,t,i,s)))}}const rs=new Te,Wo=new Xe,Ii=new Xe,Qh=new K,Bh=new K,Eh=new K,jh=new K;function Oh(n,e,t,i={},s={},o=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Wo.set(e.boundingBox.min,e.boundingBox.max,t),Wo.needsUpdate=!0;const c=n.geometry,r=c.attributes.position,l=c.index,d=e.attributes.position,h=e.index,u=ke.getPrimitive(),p=ke.getPrimitive();let m=Qh,b=Bh,G=null,y=null;s&&(G=Eh,y=jh);let Z=1/0,X=null,L=null;return rs.copy(t).invert(),Ii.matrix.copy(rs),n.shapecast({boundsTraverseOrder:V=>Wo.distanceToBox(V),intersectsBounds:(V,x,R)=>R<Z&&R<a?(x&&(Ii.min.copy(V.min),Ii.max.copy(V.max),Ii.needsUpdate=!0),!0):!1,intersectsRange:(V,x)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:R=>Ii.distanceToBox(R),intersectsBounds:(R,S,W)=>W<Z&&W<a,intersectsRange:(R,S)=>{for(let W=R,f=R+S;W<f;W++){$(p,3*W,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let C=V,g=V+x;C<g;C++){$(u,3*C,l,r),u.needsUpdate=!0;const z=u.distanceToTriangle(p,m,G);if(z<Z&&(b.copy(m),y&&y.copy(G),Z=z,X=C,L=W),z<o)return!0}}}});{const R=ei(e);for(let S=0,W=R;S<W;S++){$(p,3*S,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let f=V,C=V+x;f<C;f++){$(u,3*f,l,r),u.needsUpdate=!0;const g=u.distanceToTriangle(p,m,G);if(g<Z&&(b.copy(m),y&&y.copy(G),Z=g,X=f,L=S),g<o)return!0}}}}}),ke.releasePrimitive(u),ke.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=X,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(rs),b.applyMatrix4(rs),s.distance=b.sub(s.point).length(),s.faceIndex=L),i)}function Dh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let o,a,c,r,l=0;const d=n._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],a=new Uint32Array(o),c=new Uint16Array(o),r=new Float32Array(o),h(0,l),l+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(c[b+15]===_n){const G=a[u+6],y=c[b+14];let Z=1/0,X=1/0,L=1/0,V=-1/0,x=-1/0,R=-1/0;for(let S=G,W=G+y;S<W;S++){const f=3*n.resolveTriangleIndex(S);for(let C=0;C<3;C++){let g=f+C;g=i?i[g]:g;const z=s.getX(g),Y=s.getY(g),k=s.getZ(g);z<Z&&(Z=z),z>V&&(V=z),Y<X&&(X=Y),Y>x&&(x=Y),k<L&&(L=k),k>R&&(R=k)}}return r[u+0]!==Z||r[u+1]!==X||r[u+2]!==L||r[u+3]!==V||r[u+4]!==x||r[u+5]!==R?(r[u+0]=Z,r[u+1]=X,r[u+2]=L,r[u+3]=V,r[u+4]=x,r[u+5]=R,!0):!1}else{const G=u+8,y=a[u+6],Z=G+p,X=y+p;let L=m,V=!1,x=!1;e?L||(V=e.has(Z),x=e.has(X),L=!V&&!x):(V=!0,x=!0);const R=L||V,S=L||x;let W=!1;R&&(W=h(G,p,L));let f=!1;S&&(f=h(y,p,L));const C=W||f;if(C)for(let g=0;g<3;g++){const z=G+g,Y=y+g,k=r[z],N=r[z+3],Q=r[Y],P=r[Y+3];r[u+g]=k<Q?k:Q,r[u+g+3]=N>P?N:P}return C}}}function _h(n,e,t,i,s,o,a){j.setBuffer(n._roots[e]),go(0,n,t,i,s,o,a),j.clearBuffer()}function go(n,e,t,i,s,o,a){const{float32Array:c,uint16Array:r,uint32Array:l}=j,d=n*2;if(xe(d,r)){const h=ge(n,l),u=Ke(d,r);Nh(e,t,i,h,u,s,o,a)}else{const h=Ye(n);Rt(h,c,i,o,a)&&go(h,e,t,i,s,o,a);const u=Me(n,l);Rt(u,c,i,o,a)&&go(u,e,t,i,s,o,a)}}const Ah=["x","y","z"];function qh(n,e,t,i,s,o){j.setBuffer(n._roots[e]);const a=Co(0,n,t,i,s,o);return j.clearBuffer(),a}function Co(n,e,t,i,s,o){const{float32Array:a,uint16Array:c,uint32Array:r}=j;let l=n*2;if(xe(l,c)){const d=ge(n,r),h=Ke(l,c);return Ih(e,t,i,d,h,s,o)}else{const d=bo(n,r),h=Ah[d],u=i.direction[h]>=0;let p,m;u?(p=Ye(n),m=Me(n,r)):(p=Me(n,r),m=Ye(n));const b=Rt(p,a,i,s,o)?Co(p,e,t,i,s,o):null;if(b){const y=b.point[h];if(u?y<=a[m+d]:y>=a[m+d+3])return b}const G=Rt(m,a,i,s,o)?Co(m,e,t,i,s,o):null;return b&&G?b.distance<=G.distance?b:G:b||G||null}}const ls=new fe,oi=new He,ai=new He,Ji=new Te,Dr=new Xe,cs=new Xe;function $h(n,e,t,i){j.setBuffer(n._roots[e]);const s=zo(0,n,t,i);return j.clearBuffer(),s}function zo(n,e,t,i,s=null){const{float32Array:o,uint16Array:a,uint32Array:c}=j;let r=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Dr.set(t.boundingBox.min,t.boundingBox.max,i),s=Dr),xe(r,a)){const l=e.geometry,d=l.index,h=l.attributes.position,u=t.index,p=t.attributes.position,m=ge(n,c),b=Ke(r,a);if(Ji.copy(i).invert(),t.boundsTree)return E(n,o,cs),cs.matrix.copy(Ji),cs.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:G=>cs.intersectsBox(G),intersectsTriangle:G=>{G.a.applyMatrix4(i),G.b.applyMatrix4(i),G.c.applyMatrix4(i),G.needsUpdate=!0;for(let y=m,Z=b+m;y<Z;y++)if($(ai,3*e.resolveTriangleIndex(y),d,h),ai.needsUpdate=!0,G.intersectsTriangle(ai))return!0;return!1}});for(let G=m,y=b+m;G<y;G++){const Z=e.resolveTriangleIndex(G);$(oi,3*Z,d,h),oi.a.applyMatrix4(Ji),oi.b.applyMatrix4(Ji),oi.c.applyMatrix4(Ji),oi.needsUpdate=!0;for(let X=0,L=u.count;X<L;X+=3)if($(ai,X,u,p),ai.needsUpdate=!0,oi.intersectsTriangle(ai))return!0}}else{const l=n+8,d=c[n+6];return E(l,o,ls),!!(s.intersectsBox(ls)&&zo(l,e,t,i,s)||(E(d,o,ls),s.intersectsBox(ls)&&zo(d,e,t,i,s)))}}const ds=new Te,vo=new Xe,Ui=new Xe,eu=new K,tu=new K,iu=new K,nu=new K;function su(n,e,t,i={},s={},o=0,a=1/0){e.boundingBox||e.computeBoundingBox(),vo.set(e.boundingBox.min,e.boundingBox.max,t),vo.needsUpdate=!0;const c=n.geometry,r=c.attributes.position,l=c.index,d=e.attributes.position,h=e.index,u=ke.getPrimitive(),p=ke.getPrimitive();let m=eu,b=tu,G=null,y=null;s&&(G=iu,y=nu);let Z=1/0,X=null,L=null;return ds.copy(t).invert(),Ui.matrix.copy(ds),n.shapecast({boundsTraverseOrder:V=>vo.distanceToBox(V),intersectsBounds:(V,x,R)=>R<Z&&R<a?(x&&(Ui.min.copy(V.min),Ui.max.copy(V.max),Ui.needsUpdate=!0),!0):!1,intersectsRange:(V,x)=>{if(e.boundsTree){const R=e.boundsTree;return R.shapecast({boundsTraverseOrder:S=>Ui.distanceToBox(S),intersectsBounds:(S,W,f)=>f<Z&&f<a,intersectsRange:(S,W)=>{for(let f=S,C=S+W;f<C;f++){const g=R.resolveTriangleIndex(f);$(p,3*g,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let z=V,Y=V+x;z<Y;z++){const k=n.resolveTriangleIndex(z);$(u,3*k,l,r),u.needsUpdate=!0;const N=u.distanceToTriangle(p,m,G);if(N<Z&&(b.copy(m),y&&y.copy(G),Z=N,X=z,L=f),N<o)return!0}}}})}else{const R=ei(e);for(let S=0,W=R;S<W;S++){$(p,3*S,h,d),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let f=V,C=V+x;f<C;f++){const g=n.resolveTriangleIndex(f);$(u,3*g,l,r),u.needsUpdate=!0;const z=u.distanceToTriangle(p,m,G);if(z<Z&&(b.copy(m),y&&y.copy(G),Z=z,X=f,L=S),z<o)return!0}}}}}),ke.releasePrimitive(u),ke.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=X,s&&(s.point?s.point.copy(y):s.point=y.clone(),s.point.applyMatrix4(ds),b.applyMatrix4(ds),s.distance=b.sub(s.point).length(),s.faceIndex=L),i)}function _r(){return typeof SharedArrayBuffer<"u"}const Pi=new j.constructor,hs=new j.constructor,Lt=new Vo(()=>new fe),ri=new fe,li=new fe,Ko=new fe,Mo=new fe;let To=!1;function ou(n,e,t,i){if(To)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");To=!0;const s=n._roots,o=e._roots;let a,c=0,r=0;const l=new Te().copy(t).invert();for(let d=0,h=s.length;d<h;d++){Pi.setBuffer(s[d]),r=0;const u=Lt.getPrimitive();E(0,Pi.float32Array,u),u.applyMatrix4(l);for(let p=0,m=o.length;p<m&&(hs.setBuffer(o[p]),a=Ee(0,0,t,l,i,c,r,0,0,u),hs.clearBuffer(),r+=o[p].length,!a);p++);if(Lt.releasePrimitive(u),Pi.clearBuffer(),c+=s[d].length,a)break}return To=!1,a}function Ee(n,e,t,i,s,o=0,a=0,c=0,r=0,l=null,d=!1){let h,u;d?(h=hs,u=Pi):(h=Pi,u=hs);const p=h.float32Array,m=h.uint32Array,b=h.uint16Array,G=u.float32Array,y=u.uint32Array,Z=u.uint16Array,X=n*2,L=e*2,V=xe(X,b),x=xe(L,Z);let R=!1;if(x&&V)d?R=s(ge(e,y),Ke(e*2,Z),ge(n,m),Ke(n*2,b),r,a+e,c,o+n):R=s(ge(n,m),Ke(n*2,b),ge(e,y),Ke(e*2,Z),c,o+n,r,a+e);else if(x){const S=Lt.getPrimitive();E(e,G,S),S.applyMatrix4(t);const W=Ye(n),f=Me(n,m);E(W,p,ri),E(f,p,li);const C=S.intersectsBox(ri),g=S.intersectsBox(li);R=C&&Ee(e,W,i,t,s,a,o,r,c+1,S,!d)||g&&Ee(e,f,i,t,s,a,o,r,c+1,S,!d),Lt.releasePrimitive(S)}else{const S=Ye(e),W=Me(e,y);E(S,G,Ko),E(W,G,Mo);const f=l.intersectsBox(Ko),C=l.intersectsBox(Mo);if(f&&C)R=Ee(n,S,t,i,s,o,a,c,r+1,l,d)||Ee(n,W,t,i,s,o,a,c,r+1,l,d);else if(f)if(V)R=Ee(n,S,t,i,s,o,a,c,r+1,l,d);else{const g=Lt.getPrimitive();g.copy(Ko).applyMatrix4(t);const z=Ye(n),Y=Me(n,m);E(z,p,ri),E(Y,p,li);const k=g.intersectsBox(ri),N=g.intersectsBox(li);R=k&&Ee(S,z,i,t,s,a,o,r,c+1,g,!d)||N&&Ee(S,Y,i,t,s,a,o,r,c+1,g,!d),Lt.releasePrimitive(g)}else if(C)if(V)R=Ee(n,W,t,i,s,o,a,c,r+1,l,d);else{const g=Lt.getPrimitive();g.copy(Mo).applyMatrix4(t);const z=Ye(n),Y=Me(n,m);E(z,p,ri),E(Y,p,li);const k=g.intersectsBox(ri),N=g.intersectsBox(li);R=k&&Ee(W,z,i,t,s,a,o,r,c+1,g,!d)||N&&Ee(W,Y,i,t,s,a,o,r,c+1,g,!d),Lt.releasePrimitive(g)}}return R}const us=new Xe,Ar=new fe,au={strategy:lo,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class xt{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,o=e._indirectBuffer,a=i.getIndex();let c;return t.cloneBuffers?c={roots:s.map(r=>r.slice()),index:a?a.array.slice():null,indirectBuffer:o?o.slice():null}:c={roots:s,index:a?a.array:null,indirectBuffer:o},c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:o,indirectBuffer:a}=e,c=new xt(t,{...i,[uo]:!0});if(c._roots=o,c._indirectBuffer=a||null,i.setIndex){const r=t.getIndex();if(r===null){const l=new be(e.index,1,!1);t.setIndex(l)}else r.array!==s&&(r.array.set(s),r.needsUpdate=!0)}return c}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({...au,[uo]:!1},t),t.useSharedArrayBuffer&&!_r())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[uo]||(Rh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new fe))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Dh:kh)(this,e)}traverse(e,t=0){const i=this._roots[t],s=new Uint32Array(i),o=new Uint16Array(i);a(0);function a(c,r=0){const l=c*2,d=o[l+15]===_n;if(d){const h=s[c+6],u=o[l+14];e(r,d,new Float32Array(i,c*4,6),h,u)}else{const h=c+Zt/4,u=s[c+6],p=s[c+7];e(r,d,new Float32Array(i,c*4,6),p)||(a(h,r+1),a(u,r+1))}}}raycast(e,t=Qo,i=0,s=1/0){const o=this._roots,a=this.geometry,c=[],r=t.isMaterial,l=Array.isArray(t),d=a.groups,h=r?t.side:t,u=this.indirect?_h:Uh;for(let p=0,m=o.length;p<m;p++){const b=l?t[d[p].materialIndex].side:h,G=c.length;if(u(this,p,b,e,c,i,s),l){const y=d[p].materialIndex;for(let Z=G,X=c.length;Z<X;Z++)c[Z].face.materialIndex=y}}return c}raycastFirst(e,t=Qo,i=0,s=1/0){const o=this._roots,a=this.geometry,c=t.isMaterial,r=Array.isArray(t);let l=null;const d=a.groups,h=c?t.side:t,u=this.indirect?qh:wh;for(let p=0,m=o.length;p<m;p++){const b=r?t[d[p].materialIndex].side:h,G=u(this,p,b,e,i,s);G!=null&&(l==null||G.distance<l.distance)&&(l=G,r&&(G.face.materialIndex=d[p].materialIndex))}return l}intersectsGeometry(e,t){let i=!1;const s=this._roots,o=this.indirect?$h:Fh;for(let a=0,c=s.length;a<c&&(i=o(this,a,e,t),!i);a++);return i}shapecast(e){const t=ke.getPrimitive(),i=this.indirect?Jh:Hh;let{boundsTraverseOrder:s,intersectsBounds:o,intersectsRange:a,intersectsTriangle:c}=e;if(a&&c){const h=a;a=(u,p,m,b,G)=>h(u,p,m,b,G)?!0:i(u,p,this,c,m,b,t)}else a||(c?a=(h,u,p,m)=>i(h,u,this,c,p,m,t):a=(h,u,p)=>p);let r=!1,l=0;const d=this._roots;for(let h=0,u=d.length;h<u;h++){const p=d[h];if(r=gh(this,h,o,a,s,l),r)break;l+=p.byteLength}return ke.releasePrimitive(t),r}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:o}=i;const a=ke.getPrimitive(),c=this.geometry.index,r=this.geometry.attributes.position,l=this.indirect?m=>{const b=this.resolveTriangleIndex(m);$(a,b*3,c,r)}:m=>{$(a,m*3,c,r)},d=ke.getPrimitive(),h=e.geometry.index,u=e.geometry.attributes.position,p=e.indirect?m=>{const b=e.resolveTriangleIndex(m);$(d,b*3,h,u)}:m=>{$(d,m*3,h,u)};if(o){const m=(b,G,y,Z,X,L,V,x)=>{for(let R=y,S=y+Z;R<S;R++){p(R),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let W=b,f=b+G;W<f;W++)if(l(W),a.needsUpdate=!0,o(a,d,W,R,X,L,V,x))return!0}return!1};if(s){const b=s;s=function(G,y,Z,X,L,V,x,R){return b(G,y,Z,X,L,V,x,R)?!0:m(G,y,Z,X,L,V,x,R)}}else s=m}return ou(this,e,t,s)}intersectsBox(e,t){return us.set(e.min,e.max,t),us.needsUpdate=!0,this.shapecast({intersectsBounds:i=>us.intersectsBox(i),intersectsTriangle:i=>us.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},o=0,a=1/0){return(this.indirect?su:Oh)(this,e,t,i,s,o,a)}closestPointToPoint(e,t={},i=0,s=1/0){return Ch(this,e,t,i,s)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{E(0,new Float32Array(t),Ar),e.union(Ar)}),e}}const qr=new fe,$r=new Te;class ru extends Ss{get isMesh(){return!this.displayEdges}get isLineSegments(){return this.displayEdges}get isLine(){return this.displayEdges}getVertexPosition(...e){return Sn.prototype.getVertexPosition.call(this,...e)}constructor(e,t,i=10,s=0){super(),this.material=t,this.geometry=new Ot,this.name="MeshBVHRootHelper",this.depth=i,this.displayParents=!1,this.bvh=e,this.displayEdges=!0,this._group=s}raycast(){}update(){const e=this.geometry,t=this.bvh,i=this._group;if(e.dispose(),this.visible=!1,t){const s=this.depth-1,o=this.displayParents;let a=0;t.traverse((u,p)=>{if(u>=s||p)return a++,!0;o&&a++},i);let c=0;const r=new Float32Array(8*3*a);t.traverse((u,p,m)=>{const b=u>=s||p;if(b||o){E(0,m,qr);const{min:G,max:y}=qr;for(let Z=-1;Z<=1;Z+=2){const X=Z<0?G.x:y.x;for(let L=-1;L<=1;L+=2){const V=L<0?G.y:y.y;for(let x=-1;x<=1;x+=2){const R=x<0?G.z:y.z;r[c+0]=X,r[c+1]=V,r[c+2]=R,c+=3}}}return b}},i);let l,d;this.displayEdges?d=new Uint8Array([0,4,1,5,2,6,3,7,0,2,1,3,4,6,5,7,0,1,2,3,4,5,6,7]):d=new Uint8Array([0,1,2,2,1,3,4,6,5,6,7,5,1,4,5,0,4,1,2,3,6,3,7,6,0,2,4,2,6,4,1,5,3,3,5,7]),r.length>65535?l=new Uint32Array(d.length*a):l=new Uint16Array(d.length*a);const h=d.length;for(let u=0;u<a;u++){const p=u*8,m=u*h;for(let b=0;b<h;b++)l[m+b]=p+d[b]}e.setIndex(new be(l,1,!1)),e.setAttribute("position",new be(r,3,!1)),this.visible=!0}}}class Io extends Wl{get color(){return this.edgeMaterial.color}get opacity(){return this.edgeMaterial.opacity}set opacity(e){this.edgeMaterial.opacity=e,this.meshMaterial.opacity=e}constructor(e=null,t=null,i=10){e instanceof xt&&(i=t||10,t=e,e=null),typeof t=="number"&&(i=t,t=null),super(),this.name="MeshBVHHelper",this.depth=i,this.mesh=e,this.bvh=t,this.displayParents=!1,this.displayEdges=!0,this.objectIndex=0,this._roots=[];const s=new gl({color:65416,transparent:!0,opacity:.3,depthWrite:!1}),o=new Ls({color:65416,transparent:!0,opacity:.3,depthWrite:!1});o.color=s.color,this.edgeMaterial=s,this.meshMaterial=o,this.update()}update(){const e=this.mesh;let t=this.bvh||e.geometry.boundsTree||null;if(e.isBatchedMesh&&e.boundsTrees&&!t){const s=e._drawInfo[this.objectIndex];s&&(t=e.boundsTrees[s.geometryIndex]||t)}const i=t?t._roots.length:0;for(;this._roots.length>i;){const s=this._roots.pop();s.geometry.dispose(),this.remove(s)}for(let s=0;s<i;s++){const{depth:o,edgeMaterial:a,meshMaterial:c,displayParents:r,displayEdges:l}=this;if(s>=this._roots.length){const h=new ru(t,a,o,s);this.add(h),this._roots.push(h)}const d=this._roots[s];d.bvh=t,d.depth=o,d.displayParents=r,d.displayEdges=l,d.material=l?a:c,d.update()}}updateMatrixWorld(...e){const t=this.mesh,i=this.parent;t!==null&&(t.updateWorldMatrix(!0,!1),i?this.matrix.copy(i.matrixWorld).invert().multiply(t.matrixWorld):this.matrix.copy(t.matrixWorld),(t.isInstancedMesh||t.isBatchedMesh)&&(t.getMatrixAt(this.objectIndex,$r),this.matrix.multiply($r)),this.matrix.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(...e)}copy(e){this.depth=e.depth,this.mesh=e.mesh,this.bvh=e.bvh,this.opacity=e.opacity,this.color.copy(e.color)}clone(){return new Io(this.mesh,this.bvh,this.depth)}dispose(){this.edgeMaterial.dispose(),this.meshMaterial.dispose();const e=this.children;for(let t=0,i=e.length;t<i;t++)e[t].geometry.dispose()}}const wi=new fe,el=new fe,ci=new K;function tl(n){switch(typeof n){case"number":return 8;case"string":return n.length*2;case"boolean":return 4;default:return 0}}function lu(n){return/(Uint|Int|Float)(8|16|32)Array/.test(n.constructor.name)}function cu(n,e){const t={nodeCount:0,leafNodeCount:0,depth:{min:1/0,max:-1/0},tris:{min:1/0,max:-1/0},splits:[0,0,0],surfaceAreaScore:0};return n.traverse((i,s,o,a,c)=>{const r=o[3]-o[0],l=o[1+3]-o[1],d=o[2+3]-o[2],h=2*(r*l+l*d+d*r);t.nodeCount++,s?(t.leafNodeCount++,t.depth.min=Math.min(i,t.depth.min),t.depth.max=Math.max(i,t.depth.max),t.tris.min=Math.min(c,t.tris.min),t.tris.max=Math.max(c,t.tris.max),t.surfaceAreaScore+=h*Dn*c):(t.splits[a]++,t.surfaceAreaScore+=h*ho)},e),t.tris.min===1/0&&(t.tris.min=0,t.tris.max=0),t.depth.min===1/0&&(t.depth.min=0,t.depth.max=0),t}function du(n){return n._roots.map((e,t)=>cu(n,t))}function hu(n){const e=new Set,t=[n];let i=0;for(;t.length;){const s=t.pop();if(!e.has(s)){e.add(s);for(let o in s){if(!Object.hasOwn(s,o))continue;i+=tl(o);const a=s[o];a&&(typeof a=="object"||typeof a=="function")?lu(a)||_r()&&a instanceof SharedArrayBuffer||a instanceof ArrayBuffer?i+=a.byteLength:t.push(a):i+=tl(a)}}}return i}function uu(n){const e=n.geometry,t=[],i=e.index,s=e.getAttribute("position");let o=!0;return n.traverse((a,c,r,l,d)=>{const h={depth:a,isLeaf:c,boundingData:r,offset:l,count:d};t[a]=h,E(0,r,wi);const u=t[a-1];if(c)for(let p=l,m=l+d;p<m;p++){const b=n.resolveTriangleIndex(p);let G=3*b,y=3*b+1,Z=3*b+2;i&&(G=i.getX(G),y=i.getX(y),Z=i.getX(Z));let X;ci.fromBufferAttribute(s,G),X=wi.containsPoint(ci),ci.fromBufferAttribute(s,y),X=X&&wi.containsPoint(ci),ci.fromBufferAttribute(s,Z),X=X&&wi.containsPoint(ci),console.assert(X,"Leaf bounds does not fully contain triangle."),o=o&&X}if(u){E(0,r,el);const p=el.containsBox(wi);console.assert(p,"Parent bounds does not fully contain child."),o=o&&p}}),o}function pu(n){const e=[];return n.traverse((t,i,s,o,a)=>{const c={bounds:E(0,s,new fe)};i?(c.count=a,c.offset=o):(c.left=null,c.right=null),e[t]=c;const r=e[t-1];r&&(r.left===null?r.left=c:r.right=c)}),e[0]}function il(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 mu=parseInt(Fo)>=166,ps=new zl,nl=new K,sl=new Te,bu=Sn.prototype.raycast,yu=Cl.prototype.raycast,ol=new K,pe=new Sn,ms=[];function Gu(n,e){this.isBatchedMesh?Zu.call(this,n,e):Xu.call(this,n,e)}function Zu(n,e){if(this.boundsTrees){const t=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,o=this.matrixWorld;pe.material=this.material,pe.geometry=this.geometry;const a=pe.geometry.boundsTree,c=pe.geometry.drawRange;pe.geometry.boundingSphere===null&&(pe.geometry.boundingSphere=new wo);for(let r=0,l=i.length;r<l;r++){if(!this.getVisibleAt(r))continue;const d=i[r].geometryIndex;if(pe.geometry.boundsTree=t[d],this.getMatrixAt(r,pe.matrixWorld).premultiply(o),!pe.geometry.boundsTree){this.getBoundingBoxAt(d,pe.geometry.boundingBox),this.getBoundingSphereAt(d,pe.geometry.boundingSphere);const h=s[d];pe.geometry.setDrawRange(h.start,h.count)}pe.raycast(n,ms);for(let h=0,u=ms.length;h<u;h++){const p=ms[h];p.object=this,p.batchId=r,e.push(p)}ms.length=0}pe.geometry.boundsTree=a,pe.geometry.drawRange=c,pe.material=null,pe.geometry=null}else yu.call(this,n,e)}function Xu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;sl.copy(this.matrixWorld).invert(),ps.copy(n.ray).applyMatrix4(sl),ol.setFromMatrixScale(this.matrixWorld),nl.copy(ps.direction).multiply(ol);const t=nl.length(),i=n.near/t,s=n.far/t,o=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=il(o.raycastFirst(ps,this.material,i,s),this,n);a&&e.push(a)}else{const a=o.raycast(ps,this.material,i,s);for(let c=0,r=a.length;c<r;c++){const l=il(a[c],this,n);l&&e.push(l)}}}else bu.call(this,n,e)}function Vu(n={}){return this.boundsTree=new xt(this,n),this.boundsTree}function Ru(){this.boundsTree=null}function Lu(n=-1,e={}){if(!mu)throw new Error("BatchedMesh: Three r166+ is required to compute bounds trees.");e.indirect&&console.warn('"Indirect" is set to false because it is not supported for BatchedMesh.'),e={...e,indirect:!1,range:null};const t=this._drawRanges||this._geometryInfo,i=this._geometryCount;this.boundsTrees||(this.boundsTrees=new Array(i).fill(null));const s=this.boundsTrees;for(;s.length<i;)s.push(null);if(n<0){for(let o=0;o<i;o++)e.range=t[o],s[o]=new xt(this.geometry,e);return s}else return n<t.length&&(e.range=t[n],s[n]=new xt(this.geometry,e)),s[n]||null}function xu(n=-1){n<0?this.boundsTrees.fill(null):n<this.boundsTree.length&&(this.boundsTrees[n]=null)}function Su(n){switch(n){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function fu(n){switch(n){case 1:return Tl;case 2:return Ml;case 3:return Wn;case 4:return Wn}}function al(n){switch(n){case 1:return Yl;case 2:return jo;case 3:return gs;case 4:return gs}}class bs extends Ws{constructor(){super(),this.minFilter=Dt,this.magFilter=Dt,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,i=e.itemSize,s=e.count;if(t!==null){if(i*s%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=s*i/t}const o=e.itemSize,a=e.count,c=e.normalized,r=e.array.constructor,l=r.BYTES_PER_ELEMENT;let d=this._forcedType,h=o;if(d===null)switch(r){case Float32Array:d=Gi;break;case Uint8Array:case Uint16Array:case Uint32Array:d=yi;break;case Int8Array:case Int16Array:case Int32Array:d=fn;break}let u,p,m,b,G=Su(o);switch(d){case Gi:m=1,p=fu(o),c&&l===1?(b=r,G+="8",r===Uint8Array?u=Bo:(u=Eo,G+="_SNORM")):(b=Float32Array,G+="32F",u=Gi);break;case fn:G+=l*8+"I",m=c?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,p=al(o),l===1?(b=Int8Array,u=Eo):l===2?(b=Int16Array,u=Kl):(b=Int32Array,u=fn);break;case yi:G+=l*8+"UI",m=c?Math.pow(2,r.BYTES_PER_ELEMENT*8-1):1,p=al(o),l===1?(b=Uint8Array,u=Bo):l===2?(b=Uint16Array,u=vl):(b=Uint32Array,u=yi);break}h===3&&(p===Wn||p===gs)&&(h=4);const y=Math.ceil(Math.sqrt(a))||1,Z=h*y*y,X=new b(Z),L=e.normalized;e.normalized=!1;for(let V=0;V<a;V++){const x=h*V;X[x]=e.getX(V)/m,o>=2&&(X[x+1]=e.getY(V)/m),o>=3&&(X[x+2]=e.getZ(V)/m,h===4&&(X[x+3]=1)),o>=4&&(X[x+3]=e.getW(V)/m)}e.normalized=L,this.internalFormat=G,this.format=p,this.type=u,this.image.width=y,this.image.height=y,this.image.data=X,this.needsUpdate=!0,this.dispose(),e.itemSize=i,e.count=s}}class rl extends bs{constructor(){super(),this._forcedType=yi}}class Wu extends bs{constructor(){super(),this._forcedType=fn}}class ll extends bs{constructor(){super(),this._forcedType=Gi}}class gu{constructor(){this.index=new rl,this.position=new ll,this.bvhBounds=new Ws,this.bvhContents=new Ws,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(zu(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const i=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const s=Yr(Tr(t));this._cachedIndexAttr=new be(s,1,!1)}Cu(t,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:i,bvhContents:s}=this;e&&e.dispose(),t&&t.dispose(),i&&i.dispose(),s&&s.dispose()}}function Cu(n,e,t){const i=t.array,s=n.index?n.index.array:null;for(let o=0,a=e.length;o<a;o++){const c=3*o,r=3*e[o];for(let l=0;l<3;l++)i[c+l]=s?s[r+l]:r+l}}function zu(n,e,t){const i=n._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const s=i[0],o=new Uint16Array(s),a=new Uint32Array(s),c=new Float32Array(s),r=s.byteLength/Zt,l=2*Math.ceil(Math.sqrt(r/2)),d=new Float32Array(4*l*l),h=Math.ceil(Math.sqrt(r)),u=new Uint32Array(2*h*h);for(let p=0;p<r;p++){const m=p*Zt/4,b=m*2,G=m;for(let y=0;y<3;y++)d[8*p+0+y]=c[G+0+y],d[8*p+4+y]=c[G+3+y];if(xe(b,o)){const y=Ke(b,o),Z=ge(m,a),X=4294901760|y;u[p*2+0]=X,u[p*2+1]=Z}else{const y=4*Me(m,a)/Zt,Z=bo(m,a);u[p*2+0]=Z,u[p*2+1]=y}}e.image.data=d,e.image.width=l,e.image.height=l,e.format=Wn,e.type=Gi,e.internalFormat="RGBA32F",e.minFilter=Dt,e.magFilter=Dt,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=u,t.image.width=h,t.image.height=h,t.format=jo,t.type=yi,t.internalFormat="RG32UI",t.minFilter=Dt,t.magFilter=Dt,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const Ut=new K,Pt=new K,wt=new K,cl=new Cs,ys=new K,Yo=new K,dl=new Cs,hl=new Cs,Gs=new Te,ul=new Te;function Fi(n,e){if(!n&&!e)return;const t=n.count===e.count,i=n.normalized===e.normalized,s=n.array.constructor===e.array.constructor,o=n.itemSize===e.itemSize;if(!t||!i||!s||!o)throw new Error}function Qi(n,e=null){const t=n.array.constructor,i=n.normalized,s=n.itemSize,o=e===null?n.count:e;return new be(new t(s*o),s,i)}function pl(n,e,t=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let s=0,o=n.count;s<o;s++){const a=s+t;e.setX(a,n.getX(s)),i>=2&&e.setY(a,n.getY(s)),i>=3&&e.setZ(a,n.getZ(s)),i>=4&&e.setW(a,n.getW(s))}}else{const i=e.array,s=i.constructor,o=i.BYTES_PER_ELEMENT*n.itemSize*t;new s(i.buffer,o,n.array.length).set(n.array)}}function vu(n,e,t){const i=n.elements,s=e.elements;for(let o=0,a=s.length;o<a;o++)i[o]+=s[o]*t}function ml(n,e,t){const i=n.skeleton,s=n.geometry,o=i.bones,a=i.boneInverses;dl.fromBufferAttribute(s.attributes.skinIndex,e),hl.fromBufferAttribute(s.attributes.skinWeight,e),Gs.elements.fill(0);for(let c=0;c<4;c++){const r=hl.getComponent(c);if(r!==0){const l=dl.getComponent(c);ul.multiplyMatrices(o[l].matrixWorld,a[l]),vu(Gs,ul,r)}}return Gs.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(Gs),t}function Ho(n,e,t,i,s){ys.set(0,0,0);for(let o=0,a=n.length;o<a;o++){const c=e[o],r=n[o];c!==0&&(Yo.fromBufferAttribute(r,i),t?ys.addScaledVector(Yo,c):ys.addScaledVector(Yo.sub(s),c))}s.add(ys)}function Ku(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new Ot){const i=n[0].index!==null,{useGroups:s=!1,updateIndex:o=!1,skipAttributes:a=[]}=e,c=new Set(Object.keys(n[0].attributes)),r={};let l=0;t.clearGroups();for(let d=0;d<n.length;++d){const h=n[d];let u=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 p in h.attributes){if(!c.has(p))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.');r[p]===void 0&&(r[p]=[]),r[p].push(h.attributes[p]),u++}if(u!==c.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(s){let p;if(i)p=h.index.count;else if(h.attributes.position!==void 0)p=h.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,d),l+=p}}if(i){let d=!1;if(!t.index){let h=0;for(let u=0;u<n.length;++u)h+=n[u].index.count;t.setIndex(new be(new Uint32Array(h),1,!1)),d=!0}if(o||d){const h=t.index;let u=0,p=0;for(let m=0;m<n.length;++m){const b=n[m],G=b.index;if(a[m]!==!0)for(let y=0;y<G.count;++y)h.setX(u,G.getX(y)+p),u++;p+=b.attributes.position.count}}}for(const d in r){const h=r[d];if(!(d in t.attributes)){let m=0;for(const b in h)m+=h[b].count;t.setAttribute(d,Qi(r[d][0],m))}const u=t.attributes[d];let p=0;for(let m=0,b=h.length;m<b;m++){const G=h[m];a[m]!==!0&&pl(G,u,p),p+=G.count}}return t}function Mu(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 Tu(n){const{index:e,attributes:t}=n;if(e)for(let i=0,s=e.count;i<s;i+=3){const o=e.getX(i),a=e.getX(i+2);e.setX(i,a),e.setX(i+2,o)}else for(const i in t){const s=t[i],o=s.itemSize;for(let a=0,c=s.count;a<c;a+=3)for(let r=0;r<o;r++){const l=s.getComponent(a,r),d=s.getComponent(a+2,r);s.setComponent(a,r,d),s.setComponent(a+2,r,l)}}return n}class Yu{constructor(e){this.matrixWorld=new Te,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,s=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=s,i){i.boneTexture||i.computeBoneTexture(),i.update();const o=i.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==o.length?this.boneMatrices=o.slice():this.boneMatrices.set(o)}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&&Mu(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(s=>{s.isMesh&&t.push(s)})}),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 Ot),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 Ot){let t=[];const{meshes:i,useGroups:s,_intermediateGeometry:o,_diffMap:a}=this;for(let c=0,r=i.length;c<r;c++){const l=i[c],d=o[c],h=a.get(l);!h||h.didChange(l)?(this._convertToStaticGeometry(l,d),t.push(!1),h?h.update():a.set(l,new Yu(l))):t.push(!0)}if(o.length===0){e.setIndex(null);const c=e.attributes;for(const r in c)e.deleteAttribute(r);for(const r in this.attributes)e.setAttribute(this.attributes[r],new be(new Float32Array(0),4,!1))}else Ku(o,{useGroups:s,skipAttributes:t},e);for(const c in e.attributes)e.attributes[c].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new Ot){const i=e.geometry,s=this.applyWorldTransforms,o=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),c=i.attributes,r=t.attributes;!t.index&&i.index&&(t.index=i.index.clone()),r.position||t.setAttribute("position",Qi(c.position)),o&&!r.normal&&c.normal&&t.setAttribute("normal",Qi(c.normal)),a&&!r.tangent&&c.tangent&&t.setAttribute("tangent",Qi(c.tangent)),Fi(i.index,t.index),Fi(c.position,r.position),o&&Fi(c.normal,r.normal),a&&Fi(c.tangent,r.tangent);const l=c.position,d=o?c.normal:null,h=a?c.tangent:null,u=i.morphAttributes.position,p=i.morphAttributes.normal,m=i.morphAttributes.tangent,b=i.morphTargetsRelative,G=e.morphTargetInfluences,y=new Hl;y.getNormalMatrix(e.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let Z=0,X=c.position.count;Z<X;Z++)Ut.fromBufferAttribute(l,Z),d&&Pt.fromBufferAttribute(d,Z),h&&(cl.fromBufferAttribute(h,Z),wt.fromBufferAttribute(h,Z)),G&&(u&&Ho(u,G,b,Z,Ut),p&&Ho(p,G,b,Z,Pt),m&&Ho(m,G,b,Z,wt)),e.isSkinnedMesh&&(e.applyBoneTransform(Z,Ut),d&&ml(e,Z,Pt),h&&ml(e,Z,wt)),s&&Ut.applyMatrix4(e.matrixWorld),r.position.setXYZ(Z,Ut.x,Ut.y,Ut.z),d&&(s&&Pt.applyNormalMatrix(y),r.normal.setXYZ(Z,Pt.x,Pt.y,Pt.z)),h&&(s&&wt.transformDirection(e.matrixWorld),r.tangent.setXYZW(Z,wt.x,wt.y,wt.z,cl.w));for(const Z in this.attributes){const X=this.attributes[Z];X==="position"||X==="tangent"||X==="normal"||!(X in c)||(r[X]||t.setAttribute(X,Qi(c[X])),Fi(c[X],r[X]),pl(c[X],r[X]))}return e.matrixWorld.determinant()<0&&Tu(t),t}}const bl=`
|
|
1122
1122
|
|
|
1123
1123
|
// A stack of uint32 indices can can store the indices for
|
|
1124
1124
|
// a perfectly balanced tree with a depth up to 31. Lower stack
|