@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/components.needle.json +1 -1
  3. package/dist/gltf-progressive.js +103 -102
  4. package/dist/gltf-progressive.light.js +103 -102
  5. package/dist/gltf-progressive.light.min.js +6 -6
  6. package/dist/gltf-progressive.light.umd.cjs +6 -6
  7. package/dist/gltf-progressive.min.js +6 -6
  8. package/dist/gltf-progressive.umd.cjs +6 -6
  9. package/dist/needle-engine.bundle.js +7820 -7561
  10. package/dist/needle-engine.bundle.light.js +7773 -7514
  11. package/dist/needle-engine.bundle.light.min.js +131 -132
  12. package/dist/needle-engine.bundle.light.umd.cjs +134 -135
  13. package/dist/needle-engine.bundle.min.js +131 -132
  14. package/dist/needle-engine.bundle.umd.cjs +134 -135
  15. package/dist/needle-engine.js +596 -590
  16. package/dist/needle-engine.light.js +596 -590
  17. package/dist/needle-engine.light.min.js +1 -1
  18. package/dist/needle-engine.light.umd.cjs +1 -1
  19. package/dist/needle-engine.min.js +1 -1
  20. package/dist/needle-engine.umd.cjs +1 -1
  21. package/dist/three-examples.js +26 -26
  22. package/dist/three-examples.light.js +26 -26
  23. package/dist/three-examples.light.min.js +1 -1
  24. package/dist/three-examples.light.umd.cjs +1 -1
  25. package/dist/three-examples.min.js +1 -1
  26. package/dist/three-examples.umd.cjs +1 -1
  27. package/dist/vendor.js +0 -2
  28. package/dist/vendor.light.js +0 -2
  29. package/dist/vendor.light.min.js +2 -2
  30. package/dist/vendor.light.umd.cjs +2 -2
  31. package/dist/vendor.min.js +2 -2
  32. package/dist/vendor.umd.cjs +2 -2
  33. package/lib/engine/engine.d.ts +4 -0
  34. package/lib/engine/engine.js +12 -0
  35. package/lib/engine/engine.js.map +1 -0
  36. package/lib/engine/engine_web_api.d.ts +12 -0
  37. package/lib/engine/engine_web_api.js +113 -0
  38. package/lib/engine/engine_web_api.js.map +1 -0
  39. package/lib/engine/xr/NeedleXRSession.js +3 -0
  40. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  41. package/lib/engine-components/FlyControls.d.ts +10 -0
  42. package/lib/engine-components/FlyControls.js +29 -0
  43. package/lib/engine-components/FlyControls.js.map +1 -0
  44. package/lib/engine-components/GroundProjection.d.ts +1 -1
  45. package/lib/engine-components/GroundProjection.js +39 -32
  46. package/lib/engine-components/GroundProjection.js.map +1 -1
  47. package/lib/engine-components/OrbitControls.js +8 -0
  48. package/lib/engine-components/OrbitControls.js.map +1 -1
  49. package/lib/engine-components/RigidBody.js +10 -4
  50. package/lib/engine-components/RigidBody.js.map +1 -1
  51. package/lib/engine-components/SpatialTrigger.d.ts +2 -2
  52. package/lib/engine-components/SpatialTrigger.js +4 -4
  53. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  54. package/lib/engine-components/TransformGizmo.d.ts +7 -1
  55. package/lib/engine-components/TransformGizmo.js +39 -32
  56. package/lib/engine-components/TransformGizmo.js.map +1 -1
  57. package/lib/engine-components/VideoPlayer.js +0 -1
  58. package/lib/engine-components/VideoPlayer.js.map +1 -1
  59. package/lib/engine-components/particlesystem/ParticleSystemModules.js +1 -1
  60. package/lib/engine-components/particlesystem/ParticleSystemModules.js.map +1 -1
  61. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +2 -0
  62. package/lib/engine-components/postprocessing/Effects/Sharpening.js +15 -6
  63. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  64. package/lib/engine-components/webxr/WebXRImageTracking.d.ts +4 -0
  65. package/lib/engine-components/webxr/WebXRImageTracking.js +14 -4
  66. package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
  67. package/lib/engine-components/webxr/WebXRRig.d.ts +11 -1
  68. package/lib/engine-components/webxr/WebXRRig.js +13 -1
  69. package/lib/engine-components/webxr/WebXRRig.js.map +1 -1
  70. package/lib/needle-engine.js +5 -5
  71. package/lib/needle-engine.js.map +1 -1
  72. package/package.json +3 -3
  73. package/src/engine/codegen/register_types.ts +2 -2
  74. package/src/engine/xr/NeedleXRSession.ts +3 -0
  75. package/src/engine-components/GroundProjection.ts +46 -38
  76. package/src/engine-components/OrbitControls.ts +8 -0
  77. package/src/engine-components/RigidBody.ts +11 -5
  78. package/src/engine-components/SpatialTrigger.ts +6 -6
  79. package/src/engine-components/TransformGizmo.ts +41 -33
  80. package/src/engine-components/VideoPlayer.ts +0 -1
  81. package/src/engine-components/particlesystem/ParticleSystemModules.ts +1 -1
  82. package/src/engine-components/postprocessing/Effects/Sharpening.ts +16 -7
  83. package/src/engine-components/webxr/WebXRImageTracking.ts +18 -4
  84. package/src/engine-components/webxr/WebXRRig.ts +15 -2
  85. package/src/needle-engine.ts +5 -5
@@ -1010,7 +1010,7 @@ void main() {
1010
1010
  #include <tile_vertex>
1011
1011
  #include <soft_vertex>
1012
1012
  }
1013
- `;function Fn(s){return s===0?"uv":`uv${s}`}class Da extends X.MeshStandardMaterial{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=co,t.fragmentShader=ro}}class _a extends X.MeshPhysicalMaterial{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=co,t.fragmentShader=ro}}new M(0,0,1);class Aa extends Rc{constructor(t){super(t),this.vector_=new M,this.vector2_=new M,this.vector3_=new M,this.quaternion_=new Q,this.quaternion2_=new Q,this.quaternion3_=new Q,this.rotationMat_=new Bt,this.rotationMat2_=new Bt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.StretchedBillBoard)&&(this.rotationBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new X.InstancedBufferGeometry,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(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={},e={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(t.map=new X.Uniform$1(this.settings.material.map)),this.settings.material.alphaTest&&(e.USE_ALPHATEST="",t.alphaTest=new X.Uniform$1(this.settings.material.alphaTest)),e.USE_UV="";const i=this.settings.uTileCount,n=this.settings.vTileCount;(i>1||n>1)&&(e.UV_TILE="",t.tileCount=new X.Uniform$1(new De(i,n))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(e.USE_NORMALMAP="",e.NORMALMAP_UV=Fn(this.settings.material.normalMap.channel),t.normalMapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(e.USE_MAP="",this.settings.blendTiles&&(e.TILE_BLEND=""),e.MAP_UV=Fn(this.settings.material.map.channel),t.mapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.map.matrix))),e.USE_COLOR_ALPHA="";let o;if(this.settings.softParticles){e.SOFT_PARTICLES="";const l=this.settings.softNearFade,c=1/(this.settings.softFarFade-this.settings.softNearFade);t.softParams=new X.Uniform$1(new De(l,c)),t.depthTexture=new X.Uniform$1(null);const a=t.projParams=new X.Uniform$1(new Lt);o=(d,h,u)=>{a.value.set(u.near,u.far,0,0)}}let r=!1;if(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.Mesh){let l,c;this.settings.renderMode===exports.RenderMode.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(e.USE_COLOR="",l=co,c=ro,r=!0):(l=ja,c=yn):(l=Ea,c=yn),this.settings.renderMode===exports.RenderMode.VerticalBillBoard?e.VERTICAL="":this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&(e.HORIZONTAL="");let a=!1;this.settings.renderMode===exports.RenderMode.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Da({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,a=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new _a({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,a=!0)),a||(this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:l,fragmentShader:c,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:r}))}else if(this.settings.renderMode===exports.RenderMode.StretchedBillBoard)t.speedFactor=new X.Uniform$1(1),this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:Oa,fragmentShader:yn,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 t=0,e=0;this.systems.forEach(i=>{e+=i.particleNum}),e>this.maxParticles&&this.expandBuffers(e),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const n=i.particles,o=i.particleNum,r=this.quaternion2_,l=this.vector2_,c=this.vector3_;i.emitter.matrixWorld.decompose(l,r,c),this.rotationMat_.setFromMatrix4(i.emitter.matrixWorld);for(let a=0;a<o;a++,t++){const d=n[a];if(this.settings.renderMode===exports.RenderMode.Mesh){let u;if(i.worldSpace)u=d.rotation;else{let p;d.parentMatrix?p=this.quaternion3_.setFromRotationMatrix(d.parentMatrix):p=r,u=this.quaternion_,u.copy(p).multiply(d.rotation)}this.rotationBuffer.setXYZW(t,u.x,u.y,u.z,u.w)}else(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&this.rotationBuffer.setX(t,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(t,h.x,h.y,h.z),this.colorBuffer.setXYZW(t,d.color.x,d.color.y,d.color.z,d.color.w),i.worldSpace?this.sizeBuffer.setXYZ(t,d.size.x,d.size.y,d.size.z):d.parentMatrix?this.sizeBuffer.setXYZ(t,d.size.x,d.size.y,d.size.z):this.sizeBuffer.setXYZ(t,d.size.x*Math.abs(c.x),d.size.y*Math.abs(c.y),d.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(t,d.uvTile),this.settings.renderMode===exports.RenderMode.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(t,m.x*u,m.y*u,m.z*u,p)}}}),this.geometry.instanceCount=t,t>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,t*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,t*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,t),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,t*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var qa=`
1013
+ `;function Fn(s){return s===0?"uv":`uv${s}`}class Da extends X.MeshStandardMaterial{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=co,t.fragmentShader=ro}}class _a extends X.MeshPhysicalMaterial{constructor(t){super(t)}onBeforeCompile(t,e){super.onBeforeCompile(t,e),t.vertexShader=co,t.fragmentShader=ro}}class Aa extends Rc{constructor(t){super(t),this.vector_=new M,this.vector2_=new M,this.vector3_=new M,this.quaternion_=new Q,this.quaternion2_=new Q,this.quaternion3_=new Q,this.rotationMat_=new Bt,this.rotationMat2_=new Bt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.StretchedBillBoard)&&(this.rotationBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new X.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new X.InstancedBufferGeometry,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(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={},e={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(t.map=new X.Uniform$1(this.settings.material.map)),this.settings.material.alphaTest&&(e.USE_ALPHATEST="",t.alphaTest=new X.Uniform$1(this.settings.material.alphaTest)),e.USE_UV="";const i=this.settings.uTileCount,n=this.settings.vTileCount;(i>1||n>1)&&(e.UV_TILE="",t.tileCount=new X.Uniform$1(new De(i,n))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(e.USE_NORMALMAP="",e.NORMALMAP_UV=Fn(this.settings.material.normalMap.channel),t.normalMapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(e.USE_MAP="",this.settings.blendTiles&&(e.TILE_BLEND=""),e.MAP_UV=Fn(this.settings.material.map.channel),t.mapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.map.matrix))),e.USE_COLOR_ALPHA="";let o;if(this.settings.softParticles){e.SOFT_PARTICLES="";const l=this.settings.softNearFade,c=1/(this.settings.softFarFade-this.settings.softNearFade);t.softParams=new X.Uniform$1(new De(l,c)),t.depthTexture=new X.Uniform$1(null);const a=t.projParams=new X.Uniform$1(new Lt);o=(d,h,u)=>{a.value.set(u.near,u.far,0,0)}}let r=!1;if(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.Mesh){let l,c;this.settings.renderMode===exports.RenderMode.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(e.USE_COLOR="",l=co,c=ro,r=!0):(l=ja,c=yn):(l=Ea,c=yn),this.settings.renderMode===exports.RenderMode.VerticalBillBoard?e.VERTICAL="":this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&(e.HORIZONTAL="");let a=!1;this.settings.renderMode===exports.RenderMode.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Da({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,a=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new _a({}),this.material.copy(this.settings.material),this.material.uniforms=t,this.material.defines=e,a=!0)),a||(this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:l,fragmentShader:c,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:r}))}else if(this.settings.renderMode===exports.RenderMode.StretchedBillBoard)t.speedFactor=new X.Uniform$1(1),this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:Oa,fragmentShader:yn,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 t=0,e=0;this.systems.forEach(i=>{e+=i.particleNum}),e>this.maxParticles&&this.expandBuffers(e),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const n=i.particles,o=i.particleNum,r=this.quaternion2_,l=this.vector2_,c=this.vector3_;i.emitter.matrixWorld.decompose(l,r,c),this.rotationMat_.setFromMatrix4(i.emitter.matrixWorld);for(let a=0;a<o;a++,t++){const d=n[a];if(this.settings.renderMode===exports.RenderMode.Mesh){let u;if(i.worldSpace)u=d.rotation;else{let p;d.parentMatrix?p=this.quaternion3_.setFromRotationMatrix(d.parentMatrix):p=r,u=this.quaternion_,u.copy(p).multiply(d.rotation)}this.rotationBuffer.setXYZW(t,u.x,u.y,u.z,u.w)}else(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&this.rotationBuffer.setX(t,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(t,h.x,h.y,h.z),this.colorBuffer.setXYZW(t,d.color.x,d.color.y,d.color.z,d.color.w),i.worldSpace?this.sizeBuffer.setXYZ(t,d.size.x,d.size.y,d.size.z):d.parentMatrix?this.sizeBuffer.setXYZ(t,d.size.x,d.size.y,d.size.z):this.sizeBuffer.setXYZ(t,d.size.x*Math.abs(c.x),d.size.y*Math.abs(c.y),d.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(t,d.uvTile),this.settings.renderMode===exports.RenderMode.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(t,m.x*u,m.y*u,m.z*u,p)}}}),this.geometry.instanceCount=t,t>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,t*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,t*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,t),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,t*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,t),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var qa=`
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 M(0,0,1);class td extends Rc{constructor(t){super(t),this.vector_=new M,this.vector2_=new M,this.vector3_=new M,this.quaternion_=new Q,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new X.BufferGeometry,this.indexBuffer=new X.BufferAttribute(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new De(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},e={};if(e.USE_UV="",e.USE_COLOR_ALPHA="",this.settings.material.map&&(e.USE_MAP="",e.MAP_UV=Fn(this.settings.material.map.channel),t.map=new X.Uniform$1(this.settings.material.map),t.mapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:$a,fragmentShader:qa,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||X.AdditiveBlending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let t=0,e=0,i=0;this.systems.forEach(n=>{for(let o=0;o<n.particleNum;o++)i+=n.particles[o].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(n=>{n.emitter.updateMatrixWorld&&(n.emitter.updateWorldMatrix(!0,!1),n.emitter.updateMatrixWorld(!0));const o=this.quaternion_,r=this.vector2_,l=this.vector3_;n.emitter.matrixWorld.decompose(r,o,l);const c=n.particles,a=n.particleNum,d=this.settings.uTileCount,h=this.settings.vTileCount,u=1/d,p=1/h;for(let m=0;m<a;m++){const b=c[m],G=b.uvTile%h,y=Math.floor(b.uvTile/h+.001),Z=b.previous.values();let V=Z.next(),R=V.value,f=R;V.done||(V=Z.next());let x;V.value!==void 0?x=V.value:x=f;for(let L=0;L<b.previous.length;L++,t+=2){if(this.positionBuffer.setXYZ(t,f.position.x,f.position.y,f.position.z),this.positionBuffer.setXYZ(t+1,f.position.x,f.position.y,f.position.z),n.worldSpace?(this.positionBuffer.setXYZ(t,f.position.x,f.position.y,f.position.z),this.positionBuffer.setXYZ(t+1,f.position.x,f.position.y,f.position.z)):(b.parentMatrix?this.vector_.copy(f.position).applyMatrix4(b.parentMatrix):this.vector_.copy(f.position).applyMatrix4(n.emitter.matrixWorld),this.positionBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.previousBuffer.setXYZ(t,R.position.x,R.position.y,R.position.z),this.previousBuffer.setXYZ(t+1,R.position.x,R.position.y,R.position.z)):(b.parentMatrix?this.vector_.copy(R.position).applyMatrix4(b.parentMatrix):this.vector_.copy(R.position).applyMatrix4(n.emitter.matrixWorld),this.previousBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.nextBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.nextBuffer.setXYZ(t+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(n.emitter.matrixWorld),this.nextBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(t,-1),this.sideBuffer.setX(t+1,1),n.worldSpace)this.widthBuffer.setX(t,f.size),this.widthBuffer.setX(t+1,f.size);else if(b.parentMatrix)this.widthBuffer.setX(t,f.size),this.widthBuffer.setX(t+1,f.size);else{const W=(Math.abs(l.x)+Math.abs(l.y)+Math.abs(l.z))/3;this.widthBuffer.setX(t,f.size*W),this.widthBuffer.setX(t+1,f.size*W)}this.uvBuffer.setXY(t,(L/b.previous.length+G)*u,(h-y-1)*p),this.uvBuffer.setXY(t+1,(L/b.previous.length+G)*u,(h-y)*p),this.colorBuffer.setXYZW(t,f.color.x,f.color.y,f.color.z,f.color.w),this.colorBuffer.setXYZW(t+1,f.color.x,f.color.y,f.color.z,f.color.w),L+1<b.previous.length&&(this.indexBuffer.setX(e*3,t),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+2),e++,this.indexBuffer.setX(e*3,t+2),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+3),e++),R=f,f=x,V.done||(V=Z.next(),V.value!==void 0&&(x=V.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,t*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,t*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,t*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,t),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,t),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,t*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,e*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,e*3)}dispose(){this.geometry.dispose()}}class rs{get geometry(){return this._geometry}set geometry(t){if(this._geometry=t,t===void 0||typeof t=="string")return;const e=new X.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!t.getIndex())return;const n=t.getIndex().array,o=n.length/3;this._triangleIndexToArea.push(0);for(let r=0;r<o;r++)e.setFromAttributeAndIndices(t.getAttribute("position"),n[r*3],n[r*3+1],n[r*3+2]),i+=e.getArea(),this._triangleIndexToArea.push(i);t.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(t){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new X.Vector3,this._tempB=new X.Vector3,this._tempC=new X.Vector3,t&&(this.geometry=t)}initialize(t){const e=this._geometry;if(!e||e.getIndex()===null){t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);return}const i=this._triangleIndexToArea.length-1;let n=0,o=i;const r=Math.random()*this._triangleIndexToArea[i];for(;n+1<o;){const p=Math.floor((n+o)/2);r<this._triangleIndexToArea[p]?o=p:n=p}let l=Math.random(),c=Math.random();l+c>1&&(l=1-l,c=1-c);const a=e.getIndex().array[n*3],d=e.getIndex().array[n*3+1],h=e.getIndex().array[n*3+2],u=e.getAttribute("position");this._tempA.fromBufferAttribute(u,a),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,l).addScaledVector(this._tempC,c),t.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),t.velocity.copy(this._tempA).normalize().multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(t,e){return new rs(e.geometries[t.geometry])}clone(){return new rs(this._geometry)}update(t,e){}}Ka({id:"three.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:rs,loadJSON:rs.fromJSON}],behaviors:[]});class lo extends X.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(t,e){return t.material.side===e.material.side&&t.material.blending===e.material.blending&&t.material.blendSrc===e.material.blendSrc&&t.material.blendDst===e.material.blendDst&&t.material.blendEquation===e.material.blendEquation&&t.material.premultipliedAlpha===e.material.premultipliedAlpha&&t.material.transparent===e.material.transparent&&t.material.depthTest===e.material.depthTest&&t.material.type===e.material.type&&t.material.alphaTest===e.material.alphaTest&&t.material.map===e.material.map&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layers.mask===e.layers.mask}addSystem(t){t._renderer=this;const e=t.getRendererSettings();for(let n=0;n<this.batches.length;n++)if(lo.equals(this.batches[n].settings,e)){this.batches[n].addSystem(t),this.systemToBatchIndex.set(t,n);return}let i;switch(e.renderMode){case exports.RenderMode.Trail:i=new td(e);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new Aa(e);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(t),this.batches.push(i),this.systemToBatchIndex.set(t,this.batches.length-1),this.add(i)}deleteSystem(t){const e=this.systemToBatchIndex.get(t);e!=null&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t))}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}updateSystem(t){this.deleteSystem(t),this.addSystem(t)}update(t){this.systemToBatchIndex.forEach((e,i)=>{i.update(t)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}}const ed=lo;Ua();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const xc=Math.sqrt(5),id=(xc-1)/4,ct=(5-xc)/20,Gs=s=>Math.floor(s)|0,Zs=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 sd(s=Math.random){const t=nd(s),e=new Float64Array(t).map(r=>Zs[r%32*4]),i=new Float64Array(t).map(r=>Zs[r%32*4+1]),n=new Float64Array(t).map(r=>Zs[r%32*4+2]),o=new Float64Array(t).map(r=>Zs[r%32*4+3]);return function(l,c,a,d){let h,u,p,m,b;const G=(l+c+a+d)*id,y=Gs(l+G),Z=Gs(c+G),V=Gs(a+G),R=Gs(d+G),f=(y+Z+V+R)*ct,x=y-f,L=Z-f,W=V-f,C=R-f,S=l-x,z=c-L,g=a-W,v=d-C;let K=0,Y=0,H=0,I=0;S>z?K++:Y++,S>g?K++:H++,S>v?K++:I++,z>g?Y++:H++,z>v?Y++:I++,g>v?H++:I++;const P=K>=3?1:0,D=Y>=3?1:0,it=H>=3?1:0,tt=I>=3?1:0,St=K>=2?1:0,Vt=Y>=2?1:0,st=H>=2?1:0,pt=I>=2?1:0,et=K>=1?1:0,j=Y>=1?1:0,oe=H>=1?1:0,_=I>=1?1:0,Ut=S-P+ct,jt=z-D+ct,ye=g-it+ct,Ge=v-tt+ct,Ze=S-St+2*ct,Xe=z-Vt+2*ct,fe=g-st+2*ct,Ve=v-pt+2*ct,Re=S-et+3*ct,xe=z-j+3*ct,Le=g-oe+3*ct,Ot=v-_+3*ct,Dt=S-1+4*ct,_t=z-1+4*ct,At=g-1+4*ct,qt=v-1+4*ct,Tt=y&255,Mt=Z&255,Yt=V&255,kt=R&255;let F=.6-S*S-z*z-g*g-v*v;if(F<0)h=0;else{const O=Tt+t[Mt+t[Yt+t[kt]]];F*=F,h=F*F*(e[O]*S+i[O]*z+n[O]*g+o[O]*v)}let ei=.6-Ut*Ut-jt*jt-ye*ye-Ge*Ge;if(ei<0)u=0;else{const O=Tt+P+t[Mt+D+t[Yt+it+t[kt+tt]]];ei*=ei,u=ei*ei*(e[O]*Ut+i[O]*jt+n[O]*ye+o[O]*Ge)}let ii=.6-Ze*Ze-Xe*Xe-fe*fe-Ve*Ve;if(ii<0)p=0;else{const O=Tt+St+t[Mt+Vt+t[Yt+st+t[kt+pt]]];ii*=ii,p=ii*ii*(e[O]*Ze+i[O]*Xe+n[O]*fe+o[O]*Ve)}let si=.6-Re*Re-xe*xe-Le*Le-Ot*Ot;if(si<0)m=0;else{const O=Tt+et+t[Mt+j+t[Yt+oe+t[kt+_]]];si*=si,m=si*si*(e[O]*Re+i[O]*xe+n[O]*Le+o[O]*Ot)}let ni=.6-Dt*Dt-_t*_t-At*At-qt*qt;if(ni<0)b=0;else{const O=Tt+1+t[Mt+1+t[Yt+1+t[kt+1]]];ni*=ni,b=ni*ni*(e[O]*Dt+i[O]*_t+n[O]*At+o[O]*qt)}return 27*(h+u+p+m+b)}}function nd(s){const e=new Uint8Array(512);for(let i=0;i<512/2;i++)e[i]=i;for(let i=0;i<512/2-1;i++){const n=i+~~(s()*(256-i)),o=e[i];e[i]=e[n],e[n]=o}for(let i=256;i<512;i++)e[i]=e[i-256];return e}class od{constructor(t){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Backoff must be a positive integer");this.backoff=t}get retries(){return this._retries}get current(){return this.backoff}next(){return this._retries++,this.backoff}reset(){this._retries=0}}class rd{constructor(t,e){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Base must be a positive integer or zero");if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=t,this.expMax=e,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}class cd{constructor(t,e,i){if(this.i=0,this._retries=0,t<0)throw new Error("Initial must be a positive number or zero");if(e<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<t)throw new Error("Max must be undefined or greater than or equal to initial");this.initial=t,this.increment=e,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 ld{constructor(){this.elements=[]}add(t){this.elements.push(t)}clear(){this.elements.length=0}forEach(t){this.elements.forEach(t)}length(){return this.elements.length}isEmpty(){return this.elements.length===0}peek(){return this.elements[0]}read(){return this.elements.shift()}}class ad{constructor(t){if(!Number.isInteger(t)||t<=0)throw new Error("Capacity must be a positive integer");this.elements=new Array(t+1),this.head=0,this.tail=0}add(t){this.elements[this.head]=t,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(t){for(let e=this.tail;e!==this.head;e=(e+1)%this.elements.length)t(this.elements[e])}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 t=this.peek();return t!==void 0&&(this.tail=(this.tail+1)%this.elements.length),t}}var w;(function(s){s.open="open",s.close="close",s.error="error",s.message="message",s.retry="retry",s.reconnect="reconnect"})(w||(w={}));class Lc{constructor(t,e,i){var n,o,r,l,c,a,d,h,u,p,m,b,G,y,Z;this._closedByUser=!1,this.handleOpenEvent=V=>this.handleEvent(w.open,V),this.handleErrorEvent=V=>this.handleEvent(w.error,V),this.handleCloseEvent=V=>this.handleEvent(w.close,V),this.handleMessageEvent=V=>this.handleEvent(w.message,V),this._url=t,this._protocols=e,this._options={buffer:i==null?void 0:i.buffer,retry:{maxRetries:(n=i==null?void 0:i.retry)===null||n===void 0?void 0:n.maxRetries,instantReconnect:(o=i==null?void 0:i.retry)===null||o===void 0?void 0:o.instantReconnect,backoff:(r=i==null?void 0:i.retry)===null||r===void 0?void 0:r.backoff},listeners:{open:[...(c=(l=i==null?void 0:i.listeners)===null||l===void 0?void 0:l.open)!==null&&c!==void 0?c:[]],close:[...(d=(a=i==null?void 0:i.listeners)===null||a===void 0?void 0:a.close)!==null&&d!==void 0?d:[]],error:[...(u=(h=i==null?void 0:i.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[]],message:[...(m=(p=i==null?void 0:i.listeners)===null||p===void 0?void 0:p.message)!==null&&m!==void 0?m:[]],retry:[...(G=(b=i==null?void 0:i.listeners)===null||b===void 0?void 0:b.retry)!==null&&G!==void 0?G:[]],reconnect:[...(Z=(y=i==null?void 0: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(t){this._underlyingWebsocket.binaryType=t}send(t){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(t):this.buffer!==void 0&&this.buffer.add(t))}close(t,e){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(t,e)}addEventListener(t,e,i){this._options.listeners[t].push({listener:e,options:i})}removeEventListener(t,e,i){const n=o=>o.listener!==e||o.options!==i;this._options.listeners[t]=this._options.listeners[t].filter(n)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(w.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(w.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(w.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(w.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(w.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(w.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(w.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(w.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(t,e){const i=this._options.listeners[t],n=[];i.forEach(({listener:o,options:r})=>{o(this,e),(r===void 0||r.once===void 0||!r.once)&&n.push({listener:o,options:r})}),this._options.listeners[t]=n}handleEvent(t,e){switch(t){case w.close:this.dispatchEvent(t,e),this.scheduleConnectionRetryIfNeeded();break;case w.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},n=new CustomEvent(w.reconnect,{detail:i});this.dispatchEvent(w.reconnect,n),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(t,e),this.sendBufferedData();break;case w.retry:this.dispatchEvent(t,e),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(t,e);break}}sendBufferedData(){if(this.buffer!==void 0)for(let t=this.buffer.read();t!==void 0;t=this.buffer.read())this.send(t)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const t=i=>{const n=new CustomEvent(w.retry,{detail:i});this.handleEvent(w.retry,n)},e={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||e.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>t(e),e.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class dd{constructor(t){this._url=t}get url(){return this._url}withProtocols(t){return this._protocols=t,this}get protocols(){return this._protocols}withMaxRetries(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{maxRetries:t})}),this}get maxRetries(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.maxRetries}withInstantReconnect(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{instantReconnect:t})}),this}get instantReconnect(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.instantReconnect}withBackoff(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{backoff:t})}),this}get backoff(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.backoff}withBuffer(t){return this._options=Object.assign(Object.assign({},this._options),{buffer:t}),this}get buffer(){var t;return(t=this._options)===null||t===void 0?void 0:t.buffer}onOpen(t,e){return this.addListener(w.open,t,e),this}onClose(t,e){return this.addListener(w.close,t,e),this}onError(t,e){return this.addListener(w.error,t,e),this}onMessage(t,e){return this.addListener(w.message,t,e),this}onRetry(t,e){return this.addListener(w.retry,t,e),this}onReconnect(t,e){return this.addListener(w.reconnect,t,e),this}build(){return new Lc(this._url,this._protocols,this._options)}addListener(t,e,i){var n,o,r,l,c,a,d,h,u,p,m,b,G,y,Z,V,R,f,x,L,W;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(r=(o=(n=this._options)===null||n===void 0?void 0:n.listeners)===null||o===void 0?void 0:o.open)!==null&&r!==void 0?r:[],close:(a=(c=(l=this._options)===null||l===void 0?void 0:l.listeners)===null||c===void 0?void 0:c.close)!==null&&a!==void 0?a:[],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:(f=(R=(V=this._options)===null||V===void 0?void 0:V.listeners)===null||R===void 0?void 0:R.reconnect)!==null&&f!==void 0?f:[],[t]:[...(W=(L=(x=this._options)===null||x===void 0?void 0:x.listeners)===null||L===void 0?void 0:L[t])!==null&&W!==void 0?W:[],{listener:e,options:i}]}}),this}}const hd=Object.freeze(Object.defineProperty({__proto__:null,ArrayQueue:ld,ConstantBackoff:od,ExponentialBackoff:rd,LinearBackoff:cd,RingQueue:ad,Websocket:Lc,WebsocketBuilder:dd,get WebsocketEvent(){return w}},Symbol.toStringTag,{value:"Module"})),ao=0,Sc=1,Wc=2,ud=0,pd=1,Qn=2,Us=1.25,wn=1,pe=6*4+4+4,en=65535,md=Math.pow(2,-24),Gn=Symbol("SKIP_GENERATION");function gc(s){return s.index?s.index.count:s.attributes.position.count}function ti(s){return gc(s)/3}function Cc(s,t=ArrayBuffer){return s>65535?new Uint32Array(new t(4*s)):new Uint16Array(new t(2*s))}function bd(s,t){if(!s.index){const e=s.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Cc(e,i);s.setIndex(new X.BufferAttribute(n,1));for(let o=0;o<e;o++)n[o]=o}}function zc(s,t){const e=ti(s),i=t||s.drawRange,n=i.start/3,o=(i.start+i.count)/3,r=Math.max(0,n),l=Math.min(e,o)-r;return[{offset:Math.floor(r),count:Math.floor(l)}]}function vc(s,t){if(!s.groups||!s.groups.length)return zc(s,t);const e=[],i=new Set,n=t||s.drawRange,o=n.start/3,r=(n.start+n.count)/3;for(const c of s.groups){const a=c.start/3,d=(c.start+c.count)/3;i.add(Math.max(o,a)),i.add(Math.min(r,d))}const l=Array.from(i.values()).sort((c,a)=>c-a);for(let c=0;c<l.length-1;c++){const a=l[c],d=l[c+1];e.push({offset:Math.floor(a),count:Math.floor(d-a)})}return e}function yd(s,t){const e=ti(s),i=vc(s,t).sort((r,l)=>r.offset-l.offset),n=i[i.length-1];n.count=Math.min(e-n.offset,n.count);let o=0;return i.forEach(({count:r})=>o+=r),e!==o}function Zn(s,t,e,i,n){let o=1/0,r=1/0,l=1/0,c=-1/0,a=-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=t*6,Z=(t+e)*6;y<Z;y+=6){const V=s[y+0],R=s[y+1],f=V-R,x=V+R;f<o&&(o=f),x>c&&(c=x),V<h&&(h=V),V>m&&(m=V);const L=s[y+2],W=s[y+3],C=L-W,S=L+W;C<r&&(r=C),S>a&&(a=S),L<u&&(u=L),L>b&&(b=L);const z=s[y+4],g=s[y+5],v=z-g,K=z+g;v<l&&(l=v),K>d&&(d=K),z<p&&(p=z),z>G&&(G=z)}i[0]=o,i[1]=r,i[2]=l,i[3]=c,i[4]=a,i[5]=d,n[0]=h,n[1]=u,n[2]=p,n[3]=m,n[4]=b,n[5]=G}function Gd(s,t=null,e=null,i=null){const n=s.attributes.position,o=s.index?s.index.array:null,r=ti(s),l=n.normalized;let c;t===null?(c=new Float32Array(r*6),e=0,i=r):(c=t,e=e||0,i=i||r);const a=n.array,d=n.offset||0;let h=3;n.isInterleavedBufferAttribute&&(h=n.data.stride);const u=["getX","getY","getZ"];for(let p=e;p<e+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]),l||(G=G*h+d,y=y*h+d,Z=Z*h+d);for(let V=0;V<3;V++){let R,f,x;l?(R=n[u[V]](G),f=n[u[V]](y),x=n[u[V]](Z)):(R=a[G+V],f=a[y+V],x=a[Z+V]);let L=R;f<L&&(L=f),x<L&&(L=x);let W=R;f>W&&(W=f),x>W&&(W=x);const C=(W-L)/2,S=V*2;c[b+S+0]=L+C,c[b+S+1]=C+(Math.abs(L)+C)*md}}return c}function B(s,t,e){return e.min.x=t[s],e.min.y=t[s+1],e.min.z=t[s+2],e.max.x=t[s+3],e.max.y=t[s+4],e.max.z=t[s+5],e}function Oo(s){let t=-1,e=-1/0;for(let i=0;i<3;i++){const n=s[i+3]-s[i];n>e&&(e=n,t=i)}return t}function Do(s,t){t.set(s)}function _o(s,t,e){let i,n;for(let o=0;o<3;o++){const r=o+3;i=s[o],n=t[o],e[o]=i<n?i:n,i=s[r],n=t[r],e[r]=i>n?i:n}}function Xs(s,t,e){for(let i=0;i<3;i++){const n=t[s+2*i],o=t[s+2*i+1],r=n-o,l=n+o;r<e[i]&&(e[i]=r),l>e[i+3]&&(e[i+3]=l)}}function li(s){const t=s[3]-s[0],e=s[4]-s[1],i=s[5]-s[2];return 2*(t*e+e*i+i*t)}const $t=32,Zd=(s,t)=>s.candidate-t.candidate,le=new Array($t).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),fs=new Float32Array(6);function Xd(s,t,e,i,n,o){let r=-1,l=0;if(o===ao)r=Oo(t),r!==-1&&(l=(t[r]+t[r+3])/2);else if(o===Sc)r=Oo(s),r!==-1&&(l=fd(e,i,n,r));else if(o===Wc){const c=li(s);let a=Us*n;const d=i*6,h=(i+n)*6;for(let u=0;u<3;u++){const p=t[u],G=(t[u+3]-p)/$t;if(n<$t/4){const y=[...le];y.length=n;let Z=0;for(let R=d;R<h;R+=6,Z++){const f=y[Z];f.candidate=e[R+2*u],f.count=0;const{bounds:x,leftCacheBounds:L,rightCacheBounds:W}=f;for(let C=0;C<3;C++)W[C]=1/0,W[C+3]=-1/0,L[C]=1/0,L[C+3]=-1/0,x[C]=1/0,x[C+3]=-1/0;Xs(R,e,x)}y.sort(Zd);let V=n;for(let R=0;R<V;R++){const f=y[R];for(;R+1<V&&y[R+1].candidate===f.candidate;)y.splice(R+1,1),V--}for(let R=d;R<h;R+=6){const f=e[R+2*u];for(let x=0;x<V;x++){const L=y[x];f>=L.candidate?Xs(R,e,L.rightCacheBounds):(Xs(R,e,L.leftCacheBounds),L.count++)}}for(let R=0;R<V;R++){const f=y[R],x=f.count,L=n-f.count,W=f.leftCacheBounds,C=f.rightCacheBounds;let S=0;x!==0&&(S=li(W)/c);let z=0;L!==0&&(z=li(C)/c);const g=wn+Us*(S*x+z*L);g<a&&(r=u,a=g,l=f.candidate)}}else{for(let V=0;V<$t;V++){const R=le[V];R.count=0,R.candidate=p+G+V*G;const f=R.bounds;for(let x=0;x<3;x++)f[x]=1/0,f[x+3]=-1/0}for(let V=d;V<h;V+=6){let x=~~((e[V+2*u]-p)/G);x>=$t&&(x=$t-1);const L=le[x];L.count++,Xs(V,e,L.bounds)}const y=le[$t-1];Do(y.bounds,y.rightCacheBounds);for(let V=$t-2;V>=0;V--){const R=le[V],f=le[V+1];_o(R.bounds,f.rightCacheBounds,R.rightCacheBounds)}let Z=0;for(let V=0;V<$t-1;V++){const R=le[V],f=R.count,x=R.bounds,W=le[V+1].rightCacheBounds;f!==0&&(Z===0?Do(x,fs):_o(x,fs,fs)),Z+=f;let C=0,S=0;Z!==0&&(C=li(fs)/c);const z=n-Z;z!==0&&(S=li(W)/c);const g=wn+Us*(C*Z+S*z);g<a&&(r=u,a=g,l=R.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:r,pos:l}}function fd(s,t,e,i){let n=0;for(let o=t,r=t+e;o<r;o++)n+=s[o*6+i*2];return n/e}class Xn{constructor(){this.boundingData=new Float32Array(6)}}function Vd(s,t,e,i,n,o){let r=i,l=i+n-1;const c=o.pos,a=o.axis*2;for(;;){for(;r<=l&&e[r*6+a]<c;)r++;for(;r<=l&&e[l*6+a]>=c;)l--;if(r<l){for(let d=0;d<3;d++){let h=t[r*3+d];t[r*3+d]=t[l*3+d],t[l*3+d]=h}for(let d=0;d<6;d++){let h=e[r*6+d];e[r*6+d]=e[l*6+d],e[l*6+d]=h}r++,l--}else return r}}function Rd(s,t,e,i,n,o){let r=i,l=i+n-1;const c=o.pos,a=o.axis*2;for(;;){for(;r<=l&&e[r*6+a]<c;)r++;for(;r<=l&&e[l*6+a]>=c;)l--;if(r<l){let d=s[r];s[r]=s[l],s[l]=d;for(let h=0;h<6;h++){let u=e[r*6+h];e[r*6+h]=e[l*6+h],e[l*6+h]=u}r++,l--}else return r}}function Zt(s,t){return t[s+15]===65535}function xt(s,t){return t[s+6]}function gt(s,t){return t[s+14]}function zt(s){return s+8}function Ct(s,t){return t[s+6]}function ho(s,t){return t[s+7]}let Kc,xi,Ps,Tc;const xd=Math.pow(2,32);function Bn(s){return"count"in s?1:1+Bn(s.left)+Bn(s.right)}function Ld(s,t,e){return Kc=new Float32Array(e),xi=new Uint32Array(e),Ps=new Uint16Array(e),Tc=new Uint8Array(e),En(s,t)}function En(s,t){const e=s/4,i=s/2,n="count"in t,o=t.boundingData;for(let r=0;r<6;r++)Kc[e+r]=o[r];if(n)if(t.buffer){const r=t.buffer;Tc.set(new Uint8Array(r),s);for(let l=s,c=s+r.byteLength;l<c;l+=pe){const a=l/2;Zt(a,Ps)||(xi[l/4+6]+=e)}return s+r.byteLength}else{const r=t.offset,l=t.count;return xi[e+6]=r,Ps[i+14]=l,Ps[i+15]=en,s+pe}else{const r=t.left,l=t.right,c=t.splitAxis;let a;if(a=En(s+pe,r),a/4>xd)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return xi[e+6]=a/4,a=En(a,l),xi[e+7]=c,a}}function Sd(s,t){const e=(s.index?s.index.count:s.attributes.position.count)/3,i=e>2**16,n=i?4:2,o=t?new SharedArrayBuffer(e*n):new ArrayBuffer(e*n),r=i?new Uint32Array(o):new Uint16Array(o);for(let l=0,c=r.length;l<c;l++)r[l]=l;return r}function Wd(s,t,e,i,n){const{maxDepth:o,verbose:r,maxLeafTris:l,strategy:c,onProgress:a,indirect:d}=n,h=s._indirectBuffer,u=s.geometry,p=u.index?u.index.array:null,m=d?Rd:Vd,b=ti(u),G=new Float32Array(6);let y=!1;const Z=new Xn;return Zn(t,e,i,Z.boundingData,G),R(Z,e,i,G),Z;function V(f){a&&a(f/b)}function R(f,x,L,W=null,C=0){if(!y&&C>=o&&(y=!0,r&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),L<=l||C>=o)return V(x+L),f.offset=x,f.count=L,f;const S=Xd(f.boundingData,W,t,x,L,c);if(S.axis===-1)return V(x+L),f.offset=x,f.count=L,f;const z=m(h,p,t,x,L,S);if(z===x||z===x+L)V(x+L),f.offset=x,f.count=L;else{f.splitAxis=S.axis;const g=new Xn,v=x,K=z-x;f.left=g,Zn(t,v,K,g.boundingData,G),R(g,v,K,G,C+1);const Y=new Xn,H=z,I=L-K;f.right=Y,Zn(t,H,I,Y.boundingData,G),R(Y,H,I,G,C+1)}return f}}function gd(s,t){const e=s.geometry;t.indirect&&(s._indirectBuffer=Sd(e,t.useSharedArrayBuffer),yd(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),s._indirectBuffer||bd(e,t);const i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Gd(e),o=t.indirect?zc(e,t.range):vc(e,t.range);s._roots=o.map(r=>{const l=Wd(s,n,r.offset,r.count,t),c=Bn(l),a=new i(pe*c);return Ld(0,l,a),a})}class ne{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,n=-1/0;for(let o=0,r=t.length;o<r;o++){const c=t[o][e];i=c<i?c:i,n=c>n?c:n}this.min=i,this.max=n}setFromPoints(t,e){let i=1/0,n=-1/0;for(let o=0,r=e.length;o<r;o++){const l=e[o],c=t.dot(l);i=c<i?c:i,n=c>n?c:n}this.min=i,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}ne.prototype.setFromBox=function(){const s=new X.Vector3;return function(e,i){const n=i.min,o=i.max;let r=1/0,l=-1/0;for(let c=0;c<=1;c++)for(let a=0;a<=1;a++)for(let d=0;d<=1;d++){s.x=n.x*c+o.x*(1-c),s.y=n.y*a+o.y*(1-a),s.z=n.z*d+o.z*(1-d);const h=e.dot(s);r=Math.min(h,r),l=Math.max(h,l)}this.min=r,this.max=l}}();const Cd=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Vector3;return function(n,o,r){const l=n.start,c=s,a=o.start,d=t;e.subVectors(l,a),s.subVectors(n.end,n.start),t.subVectors(o.end,o.start);const h=e.dot(d),u=d.dot(c),p=d.dot(d),m=e.dot(c),G=c.dot(c)*p-u*u;let y,Z;G!==0?y=(h*u-m*p)/G:y=0,Z=(h+y*u)/p,r.x=y,r.y=Z}}(),uo=function(){const s=new X.Vector2,t=new X.Vector3,e=new X.Vector3;return function(n,o,r,l){Cd(n,o,s);let c=s.x,a=s.y;if(c>=0&&c<=1&&a>=0&&a<=1){n.at(c,r),o.at(a,l);return}else if(c>=0&&c<=1){a<0?o.at(0,l):o.at(1,l),n.closestPointToPoint(l,!0,r);return}else if(a>=0&&a<=1){c<0?n.at(0,r):n.at(1,r),o.closestPointToPoint(r,!0,l);return}else{let d;c<0?d=n.start:d=n.end;let h;a<0?h=o.start:h=o.end;const u=t,p=e;if(n.closestPointToPoint(h,!0,t),o.closestPointToPoint(d,!0,e),u.distanceToSquared(h)<=p.distanceToSquared(d)){r.copy(u),l.copy(h);return}else{r.copy(d),l.copy(p);return}}}}(),zd=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Plane,i=new X.Line3;return function(o,r){const{radius:l,center:c}=o,{a,b:d,c:h}=r;if(i.start=a,i.end=d,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l||(i.start=a,i.end=h,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l)||(i.start=d,i.end=h,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l))return!0;const b=r.getPlane(e);if(Math.abs(b.distanceToPoint(c))<=l){const y=b.projectPoint(c,t);if(r.containsPoint(y))return!0}return!1}}(),vd=1e-15;function fn(s){return Math.abs(s)<vd}class Kt extends X.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new X.Vector3),this.satBounds=new Array(4).fill().map(()=>new ne),this.points=[this.a,this.b,this.c],this.sphere=new X.Sphere,this.plane=new X.Plane,this.needsUpdate=!0}intersectsSphere(t){return zd(t,this)}update(){const t=this.a,e=this.b,i=this.c,n=this.points,o=this.satAxes,r=this.satBounds,l=o[0],c=r[0];this.getNormal(l),c.setFromPoints(l,n);const a=o[1],d=r[1];a.subVectors(t,e),d.setFromPoints(a,n);const h=o[2],u=r[2];h.subVectors(e,i),u.setFromPoints(h,n);const p=o[3],m=r[3];p.subVectors(i,t),m.setFromPoints(p,n),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(l,t),this.needsUpdate=!1}}Kt.prototype.closestPointToSegment=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Line3;return function(n,o=null,r=null){const{start:l,end:c}=n,a=this.points;let d,h=1/0;for(let u=0;u<3;u++){const p=(u+1)%3;e.start.copy(a[u]),e.end.copy(a[p]),uo(e,n,s,t),d=s.distanceToSquared(t),d<h&&(h=d,o&&o.copy(s),r&&r.copy(t))}return this.closestPointToPoint(l,s),d=l.distanceToSquared(s),d<h&&(h=d,o&&o.copy(s),r&&r.copy(l)),this.closestPointToPoint(c,s),d=c.distanceToSquared(s),d<h&&(h=d,o&&o.copy(s),r&&r.copy(c)),Math.sqrt(h)}}();Kt.prototype.intersectsTriangle=function(){const s=new Kt,t=new Array(3),e=new Array(3),i=new ne,n=new ne,o=new X.Vector3,r=new X.Vector3,l=new X.Vector3,c=new X.Vector3,a=new X.Vector3,d=new X.Line3,h=new X.Line3,u=new X.Line3,p=new X.Vector3;function m(b,G,y){const Z=b.points;let V=0,R=-1;for(let f=0;f<3;f++){const{start:x,end:L}=d;x.copy(Z[f]),L.copy(Z[(f+1)%3]),d.delta(r);const W=fn(G.distanceToPoint(x));if(fn(G.normal.dot(r))&&W){y.copy(d),V=2;break}const C=G.intersectLine(d,p);if(!C&&W&&p.copy(x),(C||W)&&!fn(p.distanceTo(L))){if(V<=1)(V===1?y.start:y.end).copy(p),W&&(R=V);else if(V>=2){(R===1?y.start:y.end).copy(p),V=2;break}if(V++,V===2&&R===-1)break}}return V}return function(G,y=null,Z=!1){this.needsUpdate&&this.update(),G.isExtendedTriangle?G.needsUpdate&&G.update():(s.copy(G),s.update(),G=s);const V=this.plane,R=G.plane;if(Math.abs(V.normal.dot(R.normal))>1-1e-10){const f=this.satBounds,x=this.satAxes;e[0]=G.a,e[1]=G.b,e[2]=G.c;for(let C=0;C<4;C++){const S=f[C],z=x[C];if(i.setFromPoints(z,e),S.isSeparated(i))return!1}const L=G.satBounds,W=G.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let C=0;C<4;C++){const S=L[C],z=W[C];if(i.setFromPoints(z,t),S.isSeparated(i))return!1}for(let C=0;C<4;C++){const S=x[C];for(let z=0;z<4;z++){const g=W[z];if(o.crossVectors(S,g),i.setFromPoints(o,t),n.setFromPoints(o,e),i.isSeparated(n))return!1}}return y&&(Z||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),!0}else{const f=m(this,R,h);if(f===1&&G.containsPoint(h.end))return y&&(y.start.copy(h.end),y.end.copy(h.end)),!0;if(f!==2)return!1;const x=m(G,V,u);if(x===1&&this.containsPoint(u.end))return y&&(y.start.copy(u.end),y.end.copy(u.end)),!0;if(x!==2)return!1;if(h.delta(l),u.delta(c),l.dot(c)<0){let v=u.start;u.start=u.end,u.end=v}const L=h.start.dot(l),W=h.end.dot(l),C=u.start.dot(l),S=u.end.dot(l),z=W<C,g=L<S;return L!==S&&C!==W&&z===g?!1:(y&&(a.subVectors(h.start,u.start),a.dot(l)>0?y.start.copy(h.start):y.start.copy(u.start),a.subVectors(h.end,u.end),a.dot(l)<0?y.end.copy(h.end):y.end.copy(u.end)),!0)}}}();Kt.prototype.distanceToPoint=function(){const s=new X.Vector3;return function(e){return this.closestPointToPoint(e,s),e.distanceTo(s)}}();Kt.prototype.distanceToTriangle=function(){const s=new X.Vector3,t=new X.Vector3,e=["a","b","c"],i=new X.Line3,n=new X.Line3;return function(r,l=null,c=null){const a=l||c?i:null;if(this.intersectsTriangle(r,a))return(l||c)&&(l&&a.getCenter(l),c&&a.getCenter(c)),0;let d=1/0;for(let h=0;h<3;h++){let u;const p=e[h],m=r[p];this.closestPointToPoint(m,s),u=m.distanceToSquared(s),u<d&&(d=u,l&&l.copy(s),c&&c.copy(m));const b=this[p];r.closestPointToPoint(b,s),u=b.distanceToSquared(s),u<d&&(d=u,l&&l.copy(b),c&&c.copy(s))}for(let h=0;h<3;h++){const u=e[h],p=e[(h+1)%3];i.set(this[u],this[p]);for(let m=0;m<3;m++){const b=e[m],G=e[(m+1)%3];n.set(r[b],r[G]),uo(i,n,s,t);const y=s.distanceToSquared(t);y<d&&(d=y,l&&l.copy(s),c&&c.copy(t))}}return Math.sqrt(d)}}();class Gt{constructor(t,e,i){this.isOrientedBox=!0,this.min=new X.Vector3,this.max=new X.Vector3,this.matrix=new X.Matrix4,this.invMatrix=new X.Matrix4,this.points=new Array(8).fill().map(()=>new X.Vector3),this.satAxes=new Array(3).fill().map(()=>new X.Vector3),this.satBounds=new Array(3).fill().map(()=>new ne),this.alignedSatBounds=new Array(3).fill().map(()=>new ne),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Gt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,n=this.points;for(let a=0;a<=1;a++)for(let d=0;d<=1;d++)for(let h=0;h<=1;h++){const u=1*a|2*d|4*h,p=n[u];p.x=a?i.x:e.x,p.y=d?i.y:e.y,p.z=h?i.z:e.z,p.applyMatrix4(t)}const o=this.satBounds,r=this.satAxes,l=n[0];for(let a=0;a<3;a++){const d=r[a],h=o[a],u=1<<a,p=n[u];d.subVectors(l,p),h.setFromPoints(d,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();Gt.prototype.intersectsBox=function(){const s=new ne;return function(e){this.needsUpdate&&this.update();const i=e.min,n=e.max,o=this.satBounds,r=this.satAxes,l=this.alignedSatBounds;if(s.min=i.x,s.max=n.x,l[0].isSeparated(s)||(s.min=i.y,s.max=n.y,l[1].isSeparated(s))||(s.min=i.z,s.max=n.z,l[2].isSeparated(s)))return!1;for(let c=0;c<3;c++){const a=r[c],d=o[c];if(s.setFromBox(a,e),d.isSeparated(s))return!1}return!0}}();Gt.prototype.intersectsTriangle=function(){const s=new Kt,t=new Array(3),e=new ne,i=new ne,n=new X.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(s.copy(r),s.update(),r=s);const l=this.satBounds,c=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let u=0;u<3;u++){const p=l[u],m=c[u];if(e.setFromPoints(m,t),p.isSeparated(e))return!1}const a=r.satBounds,d=r.satAxes,h=this.points;for(let u=0;u<3;u++){const p=a[u],m=d[u];if(e.setFromPoints(m,h),p.isSeparated(e))return!1}for(let u=0;u<3;u++){const p=c[u];for(let m=0;m<4;m++){const b=d[m];if(n.crossVectors(p,b),e.setFromPoints(n,t),i.setFromPoints(n,h),e.isSeparated(i))return!1}}return!0}}();Gt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}();Gt.prototype.distanceToPoint=function(){const s=new X.Vector3;return function(e){return this.closestPointToPoint(e,s),e.distanceTo(s)}}();Gt.prototype.distanceToBox=function(){const s=["x","y","z"],t=new Array(12).fill().map(()=>new X.Line3),e=new Array(12).fill().map(()=>new X.Line3),i=new X.Vector3,n=new X.Vector3;return function(r,l=0,c=null,a=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(c||a)&&(r.getCenter(n),this.closestPointToPoint(n,i),r.closestPointToPoint(i,n),c&&c.copy(i),a&&a.copy(n)),0;const d=l*l,h=r.min,u=r.max,p=this.points;let m=1/0;for(let G=0;G<8;G++){const y=p[G];n.copy(y).clamp(h,u);const Z=y.distanceToSquared(n);if(Z<m&&(m=Z,c&&c.copy(y),a&&a.copy(n),Z<d))return Math.sqrt(Z)}let b=0;for(let G=0;G<3;G++)for(let y=0;y<=1;y++)for(let Z=0;Z<=1;Z++){const V=(G+1)%3,R=(G+2)%3,f=y<<V|Z<<R,x=1<<G|y<<V|Z<<R,L=p[f],W=p[x];t[b].set(L,W);const S=s[G],z=s[V],g=s[R],v=e[b],K=v.start,Y=v.end;K[S]=h[S],K[z]=y?h[z]:u[z],K[g]=Z?h[g]:u[z],Y[S]=u[S],Y[z]=y?h[z]:u[z],Y[g]=Z?h[g]:u[z],b++}for(let G=0;G<=1;G++)for(let y=0;y<=1;y++)for(let Z=0;Z<=1;Z++){n.x=G?u.x:h.x,n.y=y?u.y:h.y,n.z=Z?u.z:h.z,this.closestPointToPoint(n,i);const V=n.distanceToSquared(i);if(V<m&&(m=V,c&&c.copy(i),a&&a.copy(n),V<d))return Math.sqrt(V)}for(let G=0;G<12;G++){const y=t[G];for(let Z=0;Z<12;Z++){const V=e[Z];uo(y,V,i,n);const R=i.distanceToSquared(n);if(R<m&&(m=R,c&&c.copy(i),a&&a.copy(n),R<d))return Math.sqrt(R)}}return Math.sqrt(m)}}();class po{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Kd extends po{constructor(){super(()=>new Kt)}}const vt=new Kd;class Td{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const E=new Td;let ue,Oe;const Je=[],Vs=new po(()=>new X.Box3);function Md(s,t,e,i,n,o){ue=Vs.getPrimitive(),Oe=Vs.getPrimitive(),Je.push(ue,Oe),E.setBuffer(s._roots[t]);const r=jn(0,s.geometry,e,i,n,o);E.clearBuffer(),Vs.releasePrimitive(ue),Vs.releasePrimitive(Oe),Je.pop(),Je.pop();const l=Je.length;return l>0&&(Oe=Je[l-1],ue=Je[l-2]),r}function jn(s,t,e,i,n=null,o=0,r=0){const{float32Array:l,uint16Array:c,uint32Array:a}=E;let d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);return B(s,l,ue),i(u,p,!1,r,o+s,ue)}else{let S=function(g){const{uint16Array:v,uint32Array:K}=E;let Y=g*2;for(;!Zt(Y,v);)g=zt(g),Y=g*2;return xt(g,K)},z=function(g){const{uint16Array:v,uint32Array:K}=E;let Y=g*2;for(;!Zt(Y,v);)g=Ct(g,K),Y=g*2;return xt(g,K)+gt(Y,v)};const u=zt(s),p=Ct(s,a);let m=u,b=p,G,y,Z,V;if(n&&(Z=ue,V=Oe,B(m,l,Z),B(b,l,V),G=n(Z),y=n(V),y<G)){m=p,b=u;const g=G;G=y,y=g,Z=V}Z||(Z=ue,B(m,l,Z));const R=Zt(m*2,c),f=e(Z,R,G,r+1,o+m);let x;if(f===Qn){const g=S(m),K=z(m)-g;x=i(g,K,!0,r+1,o+m,Z)}else x=f&&jn(m,t,e,i,n,o,r+1);if(x)return!0;V=Oe,B(b,l,V);const L=Zt(b*2,c),W=e(V,L,y,r+1,o+b);let C;if(W===Qn){const g=S(b),K=z(b)-g;C=i(g,K,!0,r+1,o+b,V)}else C=W&&jn(b,t,e,i,n,o,r+1);return!!C}}const ai=new X.Vector3,Vn=new X.Vector3;function Yd(s,t,e={},i=0,n=1/0){const o=i*i,r=n*n;let l=1/0,c=null;if(s.shapecast({boundsTraverseOrder:d=>(ai.copy(t).clamp(d.min,d.max),ai.distanceToSquared(t)),intersectsBounds:(d,h,u)=>u<l&&u<r,intersectsTriangle:(d,h)=>{d.closestPointToPoint(t,ai);const u=t.distanceToSquared(ai);return u<l&&(Vn.copy(ai),l=u,c=h),u<o}}),l===1/0)return null;const a=Math.sqrt(l);return e.point?e.point.copy(Vn):e.point=Vn.clone(),e.distance=a,e.faceIndex=c,e}const kd=parseInt(X.REVISION)>=169,ge=new X.Vector3,Ce=new X.Vector3,ze=new X.Vector3,Rs=new X.Vector2,xs=new X.Vector2,Ls=new X.Vector2,Ao=new X.Vector3,qo=new X.Vector3,$o=new X.Vector3,di=new X.Vector3;function Hd(s,t,e,i,n,o,r,l){let c;if(o===X.BackSide?c=s.intersectTriangle(i,e,t,!0,n):c=s.intersectTriangle(t,e,i,o!==X.DoubleSide,n),c===null)return null;const a=s.origin.distanceTo(n);return a<r||a>l?null:{distance:a,point:n.clone()}}function Nd(s,t,e,i,n,o,r,l,c,a,d){ge.fromBufferAttribute(t,o),Ce.fromBufferAttribute(t,r),ze.fromBufferAttribute(t,l);const h=Hd(s,ge,Ce,ze,di,c,a,d);if(h){const u=new X.Vector3;X.Triangle.getBarycoord(di,ge,Ce,ze,u),i&&(Rs.fromBufferAttribute(i,o),xs.fromBufferAttribute(i,r),Ls.fromBufferAttribute(i,l),h.uv=X.Triangle.getInterpolation(di,ge,Ce,ze,Rs,xs,Ls,new X.Vector2)),n&&(Rs.fromBufferAttribute(n,o),xs.fromBufferAttribute(n,r),Ls.fromBufferAttribute(n,l),h.uv1=X.Triangle.getInterpolation(di,ge,Ce,ze,Rs,xs,Ls,new X.Vector2)),e&&(Ao.fromBufferAttribute(e,o),qo.fromBufferAttribute(e,r),$o.fromBufferAttribute(e,l),h.normal=X.Triangle.getInterpolation(di,ge,Ce,ze,Ao,qo,$o,new X.Vector3),h.normal.dot(s.direction)>0&&h.normal.multiplyScalar(-1));const p={a:o,b:r,c:l,normal:new X.Vector3,materialIndex:0};X.Triangle.getNormal(ge,Ce,ze,p.normal),h.face=p,h.faceIndex=o,kd&&(h.barycoord=u)}return h}function sn(s,t,e,i,n,o,r){const l=i*3;let c=l+0,a=l+1,d=l+2;const h=s.index;s.index&&(c=h.getX(c),a=h.getX(a),d=h.getX(d));const{position:u,normal:p,uv:m,uv1:b}=s.attributes,G=Nd(e,u,p,m,b,c,a,d,t,o,r);return G?(G.faceIndex=i,n&&n.push(G),G):null}function $(s,t,e,i){const n=s.a,o=s.b,r=s.c;let l=t,c=t+1,a=t+2;e&&(l=e.getX(l),c=e.getX(c),a=e.getX(a)),n.x=i.getX(l),n.y=i.getY(l),n.z=i.getZ(l),o.x=i.getX(c),o.y=i.getY(c),o.z=i.getZ(c),r.x=i.getX(a),r.y=i.getY(a),r.z=i.getZ(a)}const hi=new X.Vector3,ui=new X.Vector3,pi=new X.Vector3,tr=new X.Vector2,er=new X.Vector2,ir=new X.Vector2;function Id(s,t,e,i){const n=t.getIndex().array,o=t.getAttribute("position"),r=t.getAttribute("uv"),l=n[e*3],c=n[e*3+1],a=n[e*3+2];hi.fromBufferAttribute(o,l),ui.fromBufferAttribute(o,c),pi.fromBufferAttribute(o,a);let d=0;const h=t.groups,u=e*3;for(let b=0,G=h.length;b<G;b++){const y=h[b],{start:Z,count:V}=y;if(u>=Z&&u<Z+V){d=y.materialIndex;break}}const p=i&&i.barycoord?i.barycoord:new X.Vector3;X.Triangle.getBarycoord(s,hi,ui,pi,p);let m=null;return r&&(tr.fromBufferAttribute(r,l),er.fromBufferAttribute(r,c),ir.fromBufferAttribute(r,a),i&&i.uv?m=i.uv:m=new X.Vector2,X.Triangle.getInterpolation(s,hi,ui,pi,tr,er,ir,m)),i?(i.face||(i.face={}),i.face.a=l,i.face.b=c,i.face.c=a,i.face.materialIndex=d,i.face.normal||(i.face.normal=new X.Vector3),X.Triangle.getNormal(hi,ui,pi,i.face.normal),m&&(i.uv=m),i.barycoord=p,i):{face:{a:l,b:c,c:a,materialIndex:d,normal:X.Triangle.getNormal(hi,ui,pi,new X.Vector3)},uv:m,barycoord:p}}function Jd(s,t,e,i,n,o,r,l){const{geometry:c,_indirectBuffer:a}=s;for(let d=i,h=i+n;d<h;d++)sn(c,t,e,d,o,r,l)}function Ud(s,t,e,i,n,o,r){const{geometry:l,_indirectBuffer:c}=s;let a=1/0,d=null;for(let h=i,u=i+n;h<u;h++){let p;p=sn(l,t,e,h,null,o,r),p&&p.distance<a&&(d=p,a=p.distance)}return d}function Pd(s,t,e,i,n,o,r){const{geometry:l}=e,{index:c}=l,a=l.attributes.position;for(let d=s,h=t+s;d<h;d++){let u;if(u=d,$(r,u*3,c,a),r.needsUpdate=!0,i(r,u,n,o))return!0}return!1}function Fd(s,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=s.geometry,i=e.index?e.index.array:null,n=e.attributes.position;let o,r,l,c,a=0;const d=s._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],r=new Uint32Array(o),l=new Uint16Array(o),c=new Float32Array(o),h(0,a),a+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(l[b+15]===en){const y=r[u+6],Z=l[b+14];let V=1/0,R=1/0,f=1/0,x=-1/0,L=-1/0,W=-1/0;for(let C=3*y,S=3*(y+Z);C<S;C++){let z=i[C];const g=n.getX(z),v=n.getY(z),K=n.getZ(z);g<V&&(V=g),g>x&&(x=g),v<R&&(R=v),v>L&&(L=v),K<f&&(f=K),K>W&&(W=K)}return c[u+0]!==V||c[u+1]!==R||c[u+2]!==f||c[u+3]!==x||c[u+4]!==L||c[u+5]!==W?(c[u+0]=V,c[u+1]=R,c[u+2]=f,c[u+3]=x,c[u+4]=L,c[u+5]=W,!0):!1}else{const y=u+8,Z=r[u+6],V=y+p,R=Z+p;let f=m,x=!1,L=!1;t?f||(x=t.has(V),L=t.has(R),f=!x&&!L):(x=!0,L=!0);const W=f||x,C=f||L;let S=!1;W&&(S=h(y,p,f));let z=!1;C&&(z=h(Z,p,f));const g=S||z;if(g)for(let v=0;v<3;v++){const K=y+v,Y=Z+v,H=c[K],I=c[K+3],P=c[Y],D=c[Y+3];c[u+v]=H<P?H:P,c[u+v+3]=I>D?I:D}return g}}}function me(s,t,e,i,n){let o,r,l,c,a,d;const h=1/e.direction.x,u=1/e.direction.y,p=1/e.direction.z,m=e.origin.x,b=e.origin.y,G=e.origin.z;let y=t[s],Z=t[s+3],V=t[s+1],R=t[s+3+1],f=t[s+2],x=t[s+3+2];return h>=0?(o=(y-m)*h,r=(Z-m)*h):(o=(Z-m)*h,r=(y-m)*h),u>=0?(l=(V-b)*u,c=(R-b)*u):(l=(R-b)*u,c=(V-b)*u),o>c||l>r||((l>o||isNaN(o))&&(o=l),(c<r||isNaN(r))&&(r=c),p>=0?(a=(f-G)*p,d=(x-G)*p):(a=(x-G)*p,d=(f-G)*p),o>d||a>r)?!1:((a>o||o!==o)&&(o=a),(d<r||r!==r)&&(r=d),o<=n&&r>=i)}function Qd(s,t,e,i,n,o,r,l){const{geometry:c,_indirectBuffer:a}=s;for(let d=i,h=i+n;d<h;d++){let u=a?a[d]:d;sn(c,t,e,u,o,r,l)}}function wd(s,t,e,i,n,o,r){const{geometry:l,_indirectBuffer:c}=s;let a=1/0,d=null;for(let h=i,u=i+n;h<u;h++){let p;p=sn(l,t,e,c?c[h]:h,null,o,r),p&&p.distance<a&&(d=p,a=p.distance)}return d}function Bd(s,t,e,i,n,o,r){const{geometry:l}=e,{index:c}=l,a=l.attributes.position;for(let d=s,h=t+s;d<h;d++){let u;if(u=e.resolveTriangleIndex(d),$(r,u*3,c,a),r.needsUpdate=!0,i(r,u,n,o))return!0}return!1}function Ed(s,t,e,i,n,o,r){E.setBuffer(s._roots[t]),On(0,s,e,i,n,o,r),E.clearBuffer()}function On(s,t,e,i,n,o,r){const{float32Array:l,uint16Array:c,uint32Array:a}=E,d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);Jd(t,e,i,u,p,n,o,r)}else{const u=zt(s);me(u,l,i,o,r)&&On(u,t,e,i,n,o,r);const p=Ct(s,a);me(p,l,i,o,r)&&On(p,t,e,i,n,o,r)}}const jd=["x","y","z"];function Od(s,t,e,i,n,o){E.setBuffer(s._roots[t]);const r=Dn(0,s,e,i,n,o);return E.clearBuffer(),r}function Dn(s,t,e,i,n,o){const{float32Array:r,uint16Array:l,uint32Array:c}=E;let a=s*2;if(Zt(a,l)){const h=xt(s,c),u=gt(a,l);return Ud(t,e,i,h,u,n,o)}else{const h=ho(s,c),u=jd[h],m=i.direction[u]>=0;let b,G;m?(b=zt(s),G=Ct(s,c)):(b=Ct(s,c),G=zt(s));const Z=me(b,r,i,n,o)?Dn(b,t,e,i,n,o):null;if(Z){const f=Z.point[u];if(m?f<=r[G+h]:f>=r[G+h+3])return Z}const R=me(G,r,i,n,o)?Dn(G,t,e,i,n,o):null;return Z&&R?Z.distance<=R.distance?Z:R:Z||R||null}}const Ss=new X.Box3,Ue=new Kt,Pe=new Kt,mi=new X.Matrix4,sr=new Gt,Ws=new Gt;function Dd(s,t,e,i){E.setBuffer(s._roots[t]);const n=_n(0,s,e,i);return E.clearBuffer(),n}function _n(s,t,e,i,n=null){const{float32Array:o,uint16Array:r,uint32Array:l}=E;let c=s*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),sr.set(e.boundingBox.min,e.boundingBox.max,i),n=sr),Zt(c,r)){const d=t.geometry,h=d.index,u=d.attributes.position,p=e.index,m=e.attributes.position,b=xt(s,l),G=gt(c,r);if(mi.copy(i).invert(),e.boundsTree)return B(s,o,Ws),Ws.matrix.copy(mi),Ws.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:Z=>Ws.intersectsBox(Z),intersectsTriangle:Z=>{Z.a.applyMatrix4(i),Z.b.applyMatrix4(i),Z.c.applyMatrix4(i),Z.needsUpdate=!0;for(let V=b*3,R=(G+b)*3;V<R;V+=3)if($(Pe,V,h,u),Pe.needsUpdate=!0,Z.intersectsTriangle(Pe))return!0;return!1}});for(let y=b*3,Z=(G+b)*3;y<Z;y+=3){$(Ue,y,h,u),Ue.a.applyMatrix4(mi),Ue.b.applyMatrix4(mi),Ue.c.applyMatrix4(mi),Ue.needsUpdate=!0;for(let V=0,R=p.count;V<R;V+=3)if($(Pe,V,p,m),Pe.needsUpdate=!0,Ue.intersectsTriangle(Pe))return!0}}else{const d=s+8,h=l[s+6];return B(d,o,Ss),!!(n.intersectsBox(Ss)&&_n(d,t,e,i,n)||(B(h,o,Ss),n.intersectsBox(Ss)&&_n(h,t,e,i,n)))}}const gs=new X.Matrix4,Rn=new Gt,bi=new Gt,_d=new X.Vector3,Ad=new X.Vector3,qd=new X.Vector3,$d=new X.Vector3;function th(s,t,e,i={},n={},o=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Rn.set(t.boundingBox.min,t.boundingBox.max,e),Rn.needsUpdate=!0;const l=s.geometry,c=l.attributes.position,a=l.index,d=t.attributes.position,h=t.index,u=vt.getPrimitive(),p=vt.getPrimitive();let m=_d,b=Ad,G=null,y=null;n&&(G=qd,y=$d);let Z=1/0,V=null,R=null;return gs.copy(e).invert(),bi.matrix.copy(gs),s.shapecast({boundsTraverseOrder:f=>Rn.distanceToBox(f),intersectsBounds:(f,x,L)=>L<Z&&L<r?(x&&(bi.min.copy(f.min),bi.max.copy(f.max),bi.needsUpdate=!0),!0):!1,intersectsRange:(f,x)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:W=>bi.distanceToBox(W),intersectsBounds:(W,C,S)=>S<Z&&S<r,intersectsRange:(W,C)=>{for(let S=W,z=W+C;S<z;S++){$(p,3*S,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let g=f,v=f+x;g<v;g++){$(u,3*g,a,c),u.needsUpdate=!0;const K=u.distanceToTriangle(p,m,G);if(K<Z&&(b.copy(m),y&&y.copy(G),Z=K,V=g,R=S),K<o)return!0}}}});{const L=ti(t);for(let W=0,C=L;W<C;W++){$(p,3*W,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let S=f,z=f+x;S<z;S++){$(u,3*S,a,c),u.needsUpdate=!0;const g=u.distanceToTriangle(p,m,G);if(g<Z&&(b.copy(m),y&&y.copy(G),Z=g,V=S,R=W),g<o)return!0}}}}}),vt.releasePrimitive(u),vt.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=V,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(gs),b.applyMatrix4(gs),n.distance=b.sub(n.point).length(),n.faceIndex=R),i)}function eh(s,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=s.geometry,i=e.index?e.index.array:null,n=e.attributes.position;let o,r,l,c,a=0;const d=s._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],r=new Uint32Array(o),l=new Uint16Array(o),c=new Float32Array(o),h(0,a),a+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(l[b+15]===en){const y=r[u+6],Z=l[b+14];let V=1/0,R=1/0,f=1/0,x=-1/0,L=-1/0,W=-1/0;for(let C=y,S=y+Z;C<S;C++){const z=3*s.resolveTriangleIndex(C);for(let g=0;g<3;g++){let v=z+g;v=i?i[v]:v;const K=n.getX(v),Y=n.getY(v),H=n.getZ(v);K<V&&(V=K),K>x&&(x=K),Y<R&&(R=Y),Y>L&&(L=Y),H<f&&(f=H),H>W&&(W=H)}}return c[u+0]!==V||c[u+1]!==R||c[u+2]!==f||c[u+3]!==x||c[u+4]!==L||c[u+5]!==W?(c[u+0]=V,c[u+1]=R,c[u+2]=f,c[u+3]=x,c[u+4]=L,c[u+5]=W,!0):!1}else{const y=u+8,Z=r[u+6],V=y+p,R=Z+p;let f=m,x=!1,L=!1;t?f||(x=t.has(V),L=t.has(R),f=!x&&!L):(x=!0,L=!0);const W=f||x,C=f||L;let S=!1;W&&(S=h(y,p,f));let z=!1;C&&(z=h(Z,p,f));const g=S||z;if(g)for(let v=0;v<3;v++){const K=y+v,Y=Z+v,H=c[K],I=c[K+3],P=c[Y],D=c[Y+3];c[u+v]=H<P?H:P,c[u+v+3]=I>D?I:D}return g}}}function ih(s,t,e,i,n,o,r){E.setBuffer(s._roots[t]),An(0,s,e,i,n,o,r),E.clearBuffer()}function An(s,t,e,i,n,o,r){const{float32Array:l,uint16Array:c,uint32Array:a}=E,d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);Qd(t,e,i,u,p,n,o,r)}else{const u=zt(s);me(u,l,i,o,r)&&An(u,t,e,i,n,o,r);const p=Ct(s,a);me(p,l,i,o,r)&&An(p,t,e,i,n,o,r)}}const sh=["x","y","z"];function nh(s,t,e,i,n,o){E.setBuffer(s._roots[t]);const r=qn(0,s,e,i,n,o);return E.clearBuffer(),r}function qn(s,t,e,i,n,o){const{float32Array:r,uint16Array:l,uint32Array:c}=E;let a=s*2;if(Zt(a,l)){const h=xt(s,c),u=gt(a,l);return wd(t,e,i,h,u,n,o)}else{const h=ho(s,c),u=sh[h],m=i.direction[u]>=0;let b,G;m?(b=zt(s),G=Ct(s,c)):(b=Ct(s,c),G=zt(s));const Z=me(b,r,i,n,o)?qn(b,t,e,i,n,o):null;if(Z){const f=Z.point[u];if(m?f<=r[G+h]:f>=r[G+h+3])return Z}const R=me(G,r,i,n,o)?qn(G,t,e,i,n,o):null;return Z&&R?Z.distance<=R.distance?Z:R:Z||R||null}}const Cs=new X.Box3,Fe=new Kt,Qe=new Kt,yi=new X.Matrix4,nr=new Gt,zs=new Gt;function oh(s,t,e,i){E.setBuffer(s._roots[t]);const n=$n(0,s,e,i);return E.clearBuffer(),n}function $n(s,t,e,i,n=null){const{float32Array:o,uint16Array:r,uint32Array:l}=E;let c=s*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),nr.set(e.boundingBox.min,e.boundingBox.max,i),n=nr),Zt(c,r)){const d=t.geometry,h=d.index,u=d.attributes.position,p=e.index,m=e.attributes.position,b=xt(s,l),G=gt(c,r);if(yi.copy(i).invert(),e.boundsTree)return B(s,o,zs),zs.matrix.copy(yi),zs.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:Z=>zs.intersectsBox(Z),intersectsTriangle:Z=>{Z.a.applyMatrix4(i),Z.b.applyMatrix4(i),Z.c.applyMatrix4(i),Z.needsUpdate=!0;for(let V=b,R=G+b;V<R;V++)if($(Qe,3*t.resolveTriangleIndex(V),h,u),Qe.needsUpdate=!0,Z.intersectsTriangle(Qe))return!0;return!1}});for(let y=b,Z=G+b;y<Z;y++){const V=t.resolveTriangleIndex(y);$(Fe,3*V,h,u),Fe.a.applyMatrix4(yi),Fe.b.applyMatrix4(yi),Fe.c.applyMatrix4(yi),Fe.needsUpdate=!0;for(let R=0,f=p.count;R<f;R+=3)if($(Qe,R,p,m),Qe.needsUpdate=!0,Fe.intersectsTriangle(Qe))return!0}}else{const d=s+8,h=l[s+6];return B(d,o,Cs),!!(n.intersectsBox(Cs)&&$n(d,t,e,i,n)||(B(h,o,Cs),n.intersectsBox(Cs)&&$n(h,t,e,i,n)))}}const vs=new X.Matrix4,xn=new Gt,Gi=new Gt,rh=new X.Vector3,ch=new X.Vector3,lh=new X.Vector3,ah=new X.Vector3;function dh(s,t,e,i={},n={},o=0,r=1/0){t.boundingBox||t.computeBoundingBox(),xn.set(t.boundingBox.min,t.boundingBox.max,e),xn.needsUpdate=!0;const l=s.geometry,c=l.attributes.position,a=l.index,d=t.attributes.position,h=t.index,u=vt.getPrimitive(),p=vt.getPrimitive();let m=rh,b=ch,G=null,y=null;n&&(G=lh,y=ah);let Z=1/0,V=null,R=null;return vs.copy(e).invert(),Gi.matrix.copy(vs),s.shapecast({boundsTraverseOrder:f=>xn.distanceToBox(f),intersectsBounds:(f,x,L)=>L<Z&&L<r?(x&&(Gi.min.copy(f.min),Gi.max.copy(f.max),Gi.needsUpdate=!0),!0):!1,intersectsRange:(f,x)=>{if(t.boundsTree){const L=t.boundsTree;return L.shapecast({boundsTraverseOrder:W=>Gi.distanceToBox(W),intersectsBounds:(W,C,S)=>S<Z&&S<r,intersectsRange:(W,C)=>{for(let S=W,z=W+C;S<z;S++){const g=L.resolveTriangleIndex(S);$(p,3*g,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let v=f,K=f+x;v<K;v++){const Y=s.resolveTriangleIndex(v);$(u,3*Y,a,c),u.needsUpdate=!0;const H=u.distanceToTriangle(p,m,G);if(H<Z&&(b.copy(m),y&&y.copy(G),Z=H,V=v,R=S),H<o)return!0}}}})}else{const L=ti(t);for(let W=0,C=L;W<C;W++){$(p,3*W,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let S=f,z=f+x;S<z;S++){const g=s.resolveTriangleIndex(S);$(u,3*g,a,c),u.needsUpdate=!0;const v=u.distanceToTriangle(p,m,G);if(v<Z&&(b.copy(m),y&&y.copy(G),Z=v,V=S,R=W),v<o)return!0}}}}}),vt.releasePrimitive(u),vt.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=V,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(vs),b.applyMatrix4(vs),n.distance=b.sub(n.point).length(),n.faceIndex=R),i)}function Mc(){return typeof SharedArrayBuffer<"u"}const Wi=new E.constructor,_s=new E.constructor,de=new po(()=>new X.Box3),we=new X.Box3,Be=new X.Box3,Ln=new X.Box3,Sn=new X.Box3;let Wn=!1;function hh(s,t,e,i){if(Wn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Wn=!0;const n=s._roots,o=t._roots;let r,l=0,c=0;const a=new X.Matrix4().copy(e).invert();for(let d=0,h=n.length;d<h;d++){Wi.setBuffer(n[d]),c=0;const u=de.getPrimitive();B(0,Wi.float32Array,u),u.applyMatrix4(a);for(let p=0,m=o.length;p<m&&(_s.setBuffer(o[p]),r=Nt(0,0,e,a,i,l,c,0,0,u),_s.clearBuffer(),c+=o[p].length,!r);p++);if(de.releasePrimitive(u),Wi.clearBuffer(),l+=n[d].length,r)break}return Wn=!1,r}function Nt(s,t,e,i,n,o=0,r=0,l=0,c=0,a=null,d=!1){let h,u;d?(h=_s,u=Wi):(h=Wi,u=_s);const p=h.float32Array,m=h.uint32Array,b=h.uint16Array,G=u.float32Array,y=u.uint32Array,Z=u.uint16Array,V=s*2,R=t*2,f=Zt(V,b),x=Zt(R,Z);let L=!1;if(x&&f)d?L=n(xt(t,y),gt(t*2,Z),xt(s,m),gt(s*2,b),c,r+t,l,o+s):L=n(xt(s,m),gt(s*2,b),xt(t,y),gt(t*2,Z),l,o+s,c,r+t);else if(x){const W=de.getPrimitive();B(t,G,W),W.applyMatrix4(e);const C=zt(s),S=Ct(s,m);B(C,p,we),B(S,p,Be);const z=W.intersectsBox(we),g=W.intersectsBox(Be);L=z&&Nt(t,C,i,e,n,r,o,c,l+1,W,!d)||g&&Nt(t,S,i,e,n,r,o,c,l+1,W,!d),de.releasePrimitive(W)}else{const W=zt(t),C=Ct(t,y);B(W,G,Ln),B(C,G,Sn);const S=a.intersectsBox(Ln),z=a.intersectsBox(Sn);if(S&&z)L=Nt(s,W,e,i,n,o,r,l,c+1,a,d)||Nt(s,C,e,i,n,o,r,l,c+1,a,d);else if(S)if(f)L=Nt(s,W,e,i,n,o,r,l,c+1,a,d);else{const g=de.getPrimitive();g.copy(Ln).applyMatrix4(e);const v=zt(s),K=Ct(s,m);B(v,p,we),B(K,p,Be);const Y=g.intersectsBox(we),H=g.intersectsBox(Be);L=Y&&Nt(W,v,i,e,n,r,o,c,l+1,g,!d)||H&&Nt(W,K,i,e,n,r,o,c,l+1,g,!d),de.releasePrimitive(g)}else if(z)if(f)L=Nt(s,C,e,i,n,o,r,l,c+1,a,d);else{const g=de.getPrimitive();g.copy(Sn).applyMatrix4(e);const v=zt(s),K=Ct(s,m);B(v,p,we),B(K,p,Be);const Y=g.intersectsBox(we),H=g.intersectsBox(Be);L=Y&&Nt(C,v,i,e,n,r,o,c,l+1,g,!d)||H&&Nt(C,K,i,e,n,r,o,c,l+1,g,!d),de.releasePrimitive(g)}}return L}const Ks=new Gt,or=new X.Box3,uh={strategy:ao,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class be{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,n=t._roots,o=t._indirectBuffer,r=i.getIndex();let l;return e.cloneBuffers?l={roots:n.map(c=>c.slice()),index:r?r.array.slice():null,indirectBuffer:o?o.slice():null}:l={roots:n,index:r?r.array:null,indirectBuffer:o},l}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:n,roots:o,indirectBuffer:r}=t,l=new be(e,{...i,[Gn]:!0});if(l._roots=o,l._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const a=new X.BufferAttribute(t.index,1,!1);e.setIndex(a)}else c.array!==n&&(c.array.set(n),c.needsUpdate=!0)}return l}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...uh,[Gn]:!1},e),e.useSharedArrayBuffer&&!Mc())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Gn]||(gd(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new X.Box3))),this.resolveTriangleIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i}refit(t=null){return(this.indirect?eh:Fd)(this,t)}traverse(t,e=0){const i=this._roots[e],n=new Uint32Array(i),o=new Uint16Array(i);r(0);function r(l,c=0){const a=l*2,d=o[a+15]===en;if(d){const h=n[l+6],u=o[a+14];t(c,d,new Float32Array(i,l*4,6),h,u)}else{const h=l+pe/4,u=n[l+6],p=n[l+7];t(c,d,new Float32Array(i,l*4,6),p)||(r(h,c+1),r(u,c+1))}}}raycast(t,e=X.FrontSide,i=0,n=1/0){const o=this._roots,r=this.geometry,l=[],c=e.isMaterial,a=Array.isArray(e),d=r.groups,h=c?e.side:e,u=this.indirect?ih:Ed;for(let p=0,m=o.length;p<m;p++){const b=a?e[d[p].materialIndex].side:h,G=l.length;if(u(this,p,b,t,l,i,n),a){const y=d[p].materialIndex;for(let Z=G,V=l.length;Z<V;Z++)l[Z].face.materialIndex=y}}return l}raycastFirst(t,e=X.FrontSide,i=0,n=1/0){const o=this._roots,r=this.geometry,l=e.isMaterial,c=Array.isArray(e);let a=null;const d=r.groups,h=l?e.side:e,u=this.indirect?nh:Od;for(let p=0,m=o.length;p<m;p++){const b=c?e[d[p].materialIndex].side:h,G=u(this,p,b,t,i,n);G!=null&&(a==null||G.distance<a.distance)&&(a=G,c&&(G.face.materialIndex=d[p].materialIndex))}return a}intersectsGeometry(t,e){let i=!1;const n=this._roots,o=this.indirect?oh:Dd;for(let r=0,l=n.length;r<l&&(i=o(this,r,t,e),!i);r++);return i}shapecast(t){const e=vt.getPrimitive(),i=this.indirect?Bd:Pd;let{boundsTraverseOrder:n,intersectsBounds:o,intersectsRange:r,intersectsTriangle:l}=t;if(r&&l){const h=r;r=(u,p,m,b,G)=>h(u,p,m,b,G)?!0:i(u,p,this,l,m,b,e)}else r||(l?r=(h,u,p,m)=>i(h,u,this,l,p,m,e):r=(h,u,p)=>p);let c=!1,a=0;const d=this._roots;for(let h=0,u=d.length;h<u;h++){const p=d[h];if(c=Md(this,h,o,r,n,a),c)break;a+=p.byteLength}return vt.releasePrimitive(e),c}bvhcast(t,e,i){let{intersectsRanges:n,intersectsTriangles:o}=i;const r=vt.getPrimitive(),l=this.geometry.index,c=this.geometry.attributes.position,a=this.indirect?m=>{const b=this.resolveTriangleIndex(m);$(r,b*3,l,c)}:m=>{$(r,m*3,l,c)},d=vt.getPrimitive(),h=t.geometry.index,u=t.geometry.attributes.position,p=t.indirect?m=>{const b=t.resolveTriangleIndex(m);$(d,b*3,h,u)}:m=>{$(d,m*3,h,u)};if(o){const m=(b,G,y,Z,V,R,f,x)=>{for(let L=y,W=y+Z;L<W;L++){p(L),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let C=b,S=b+G;C<S;C++)if(a(C),r.needsUpdate=!0,o(r,d,C,L,V,R,f,x))return!0}return!1};if(n){const b=n;n=function(G,y,Z,V,R,f,x,L){return b(G,y,Z,V,R,f,x,L)?!0:m(G,y,Z,V,R,f,x,L)}}else n=m}return hh(this,t,e,n)}intersectsBox(t,e){return Ks.set(t.min,t.max,e),Ks.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Ks.intersectsBox(i),intersectsTriangle:i=>Ks.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},n={},o=0,r=1/0){return(this.indirect?dh:th)(this,t,e,i,n,o,r)}closestPointToPoint(t,e={},i=0,n=1/0){return Yd(this,t,e,i,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{B(0,new Float32Array(i),or),t.union(or)}),t}}const rr=new X.Box3,cr=new X.Matrix4;class ph extends X.Object3D{get isMesh(){return!this.displayEdges}get isLineSegments(){return this.displayEdges}get isLine(){return this.displayEdges}getVertexPosition(...t){return X.Mesh.prototype.getVertexPosition.call(this,...t)}constructor(t,e,i=10,n=0){super(),this.material=e,this.geometry=new X.BufferGeometry,this.name="MeshBVHRootHelper",this.depth=i,this.displayParents=!1,this.bvh=t,this.displayEdges=!0,this._group=n}raycast(){}update(){const t=this.geometry,e=this.bvh,i=this._group;if(t.dispose(),this.visible=!1,e){const n=this.depth-1,o=this.displayParents;let r=0;e.traverse((u,p)=>{if(u>=n||p)return r++,!0;o&&r++},i);let l=0;const c=new Float32Array(8*3*r);e.traverse((u,p,m)=>{const b=u>=n||p;if(b||o){B(0,m,rr);const{min:G,max:y}=rr;for(let Z=-1;Z<=1;Z+=2){const V=Z<0?G.x:y.x;for(let R=-1;R<=1;R+=2){const f=R<0?G.y:y.y;for(let x=-1;x<=1;x+=2){const L=x<0?G.z:y.z;c[l+0]=V,c[l+1]=f,c[l+2]=L,l+=3}}}return b}},i);let a,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]),c.length>65535?a=new Uint32Array(d.length*r):a=new Uint16Array(d.length*r);const h=d.length;for(let u=0;u<r;u++){const p=u*8,m=u*h;for(let b=0;b<h;b++)a[m+b]=p+d[b]}t.setIndex(new X.BufferAttribute(a,1,!1)),t.setAttribute("position",new X.BufferAttribute(c,3,!1)),this.visible=!0}}}class mo extends X.Group{get color(){return this.edgeMaterial.color}get opacity(){return this.edgeMaterial.opacity}set opacity(t){this.edgeMaterial.opacity=t,this.meshMaterial.opacity=t}constructor(t=null,e=null,i=10){t instanceof be&&(i=e||10,e=t,t=null),typeof e=="number"&&(i=e,e=null),super(),this.name="MeshBVHHelper",this.depth=i,this.mesh=t,this.bvh=e,this.displayParents=!1,this.displayEdges=!0,this.objectIndex=0,this._roots=[];const n=new X.LineBasicMaterial({color:65416,transparent:!0,opacity:.3,depthWrite:!1}),o=new X.MeshBasicMaterial({color:65416,transparent:!0,opacity:.3,depthWrite:!1});o.color=n.color,this.edgeMaterial=n,this.meshMaterial=o,this.update()}update(){const t=this.mesh;let e=this.bvh||t.geometry.boundsTree||null;if(t.isBatchedMesh&&t.boundsTrees&&!e){const n=t._drawInfo[this.objectIndex];n&&(e=t.boundsTrees[n.geometryIndex]||e)}const i=e?e._roots.length:0;for(;this._roots.length>i;){const n=this._roots.pop();n.geometry.dispose(),this.remove(n)}for(let n=0;n<i;n++){const{depth:o,edgeMaterial:r,meshMaterial:l,displayParents:c,displayEdges:a}=this;if(n>=this._roots.length){const h=new ph(e,r,o,n);this.add(h),this._roots.push(h)}const d=this._roots[n];d.bvh=e,d.depth=o,d.displayParents=c,d.displayEdges=a,d.material=a?r:l,d.update()}}updateMatrixWorld(...t){const e=this.mesh,i=this.parent;e!==null&&(e.updateWorldMatrix(!0,!1),i?this.matrix.copy(i.matrixWorld).invert().multiply(e.matrixWorld):this.matrix.copy(e.matrixWorld),(e.isInstancedMesh||e.isBatchedMesh)&&(e.getMatrixAt(this.objectIndex,cr),this.matrix.multiply(cr)),this.matrix.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(...t)}copy(t){this.depth=t.depth,this.mesh=t.mesh,this.bvh=t.bvh,this.opacity=t.opacity,this.color.copy(t.color)}clone(){return new mo(this.mesh,this.bvh,this.depth)}dispose(){this.edgeMaterial.dispose(),this.meshMaterial.dispose();const t=this.children;for(let e=0,i=t.length;e<i;e++)t[e].geometry.dispose()}}const Zi=new X.Box3,lr=new X.Box3,Ee=new X.Vector3;function ar(s){switch(typeof s){case"number":return 8;case"string":return s.length*2;case"boolean":return 4;default:return 0}}function mh(s){return/(Uint|Int|Float)(8|16|32)Array/.test(s.constructor.name)}function bh(s,t){const e={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 s.traverse((i,n,o,r,l)=>{const c=o[3]-o[0],a=o[1+3]-o[1],d=o[2+3]-o[2],h=2*(c*a+a*d+d*c);e.nodeCount++,n?(e.leafNodeCount++,e.depth.min=Math.min(i,e.depth.min),e.depth.max=Math.max(i,e.depth.max),e.tris.min=Math.min(l,e.tris.min),e.tris.max=Math.max(l,e.tris.max),e.surfaceAreaScore+=h*Us*l):(e.splits[r]++,e.surfaceAreaScore+=h*wn)},t),e.tris.min===1/0&&(e.tris.min=0,e.tris.max=0),e.depth.min===1/0&&(e.depth.min=0,e.depth.max=0),e}function yh(s){return s._roots.map((t,e)=>bh(s,e))}function Gh(s){const t=new Set,e=[s];let i=0;for(;e.length;){const n=e.pop();if(!t.has(n)){t.add(n);for(let o in n){if(!Object.hasOwn(n,o))continue;i+=ar(o);const r=n[o];r&&(typeof r=="object"||typeof r=="function")?mh(r)||Mc()&&r instanceof SharedArrayBuffer||r instanceof ArrayBuffer?i+=r.byteLength:e.push(r):i+=ar(r)}}}return i}function Zh(s){const t=s.geometry,e=[],i=t.index,n=t.getAttribute("position");let o=!0;return s.traverse((r,l,c,a,d)=>{const h={depth:r,isLeaf:l,boundingData:c,offset:a,count:d};e[r]=h,B(0,c,Zi);const u=e[r-1];if(l)for(let p=a,m=a+d;p<m;p++){const b=s.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 V;Ee.fromBufferAttribute(n,G),V=Zi.containsPoint(Ee),Ee.fromBufferAttribute(n,y),V=V&&Zi.containsPoint(Ee),Ee.fromBufferAttribute(n,Z),V=V&&Zi.containsPoint(Ee),console.assert(V,"Leaf bounds does not fully contain triangle."),o=o&&V}if(u){B(0,c,lr);const p=lr.containsBox(Zi);console.assert(p,"Parent bounds does not fully contain child."),o=o&&p}}),o}function Xh(s){const t=[];return s.traverse((e,i,n,o,r)=>{const l={bounds:B(0,n,new X.Box3)};i?(l.count=r,l.offset=o):(l.left=null,l.right=null),t[e]=l;const c=t[e-1];c&&(c.left===null?c.left=l:c.right=l)}),t[0]}function dr(s,t,e){return s===null?null:(s.point.applyMatrix4(t.matrixWorld),s.distance=s.point.distanceTo(e.ray.origin),s.object=t,s)}const fh=parseInt(X.REVISION)>=166,Ts=new X.Ray,hr=new X.Vector3,ur=new X.Matrix4,Vh=X.Mesh.prototype.raycast,Rh=X.BatchedMesh.prototype.raycast,pr=new X.Vector3,lt=new X.Mesh,Ms=[];function xh(s,t){this.isBatchedMesh?Lh.call(this,s,t):Sh.call(this,s,t)}function Lh(s,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,n=this._drawRanges||this._geometryInfo,o=this.matrixWorld;lt.material=this.material,lt.geometry=this.geometry;const r=lt.geometry.boundsTree,l=lt.geometry.drawRange;lt.geometry.boundingSphere===null&&(lt.geometry.boundingSphere=new X.Sphere);for(let c=0,a=i.length;c<a;c++){if(!this.getVisibleAt(c))continue;const d=i[c].geometryIndex;if(lt.geometry.boundsTree=e[d],this.getMatrixAt(c,lt.matrixWorld).premultiply(o),!lt.geometry.boundsTree){this.getBoundingBoxAt(d,lt.geometry.boundingBox),this.getBoundingSphereAt(d,lt.geometry.boundingSphere);const h=n[d];lt.geometry.setDrawRange(h.start,h.count)}lt.raycast(s,Ms);for(let h=0,u=Ms.length;h<u;h++){const p=Ms[h];p.object=this,p.batchId=c,t.push(p)}Ms.length=0}lt.geometry.boundsTree=r,lt.geometry.drawRange=l,lt.material=null,lt.geometry=null}else Rh.call(this,s,t)}function Sh(s,t){if(this.geometry.boundsTree){if(this.material===void 0)return;ur.copy(this.matrixWorld).invert(),Ts.copy(s.ray).applyMatrix4(ur),pr.setFromMatrixScale(this.matrixWorld),hr.copy(Ts.direction).multiply(pr);const e=hr.length(),i=s.near/e,n=s.far/e,o=this.geometry.boundsTree;if(s.firstHitOnly===!0){const r=dr(o.raycastFirst(Ts,this.material,i,n),this,s);r&&t.push(r)}else{const r=o.raycast(Ts,this.material,i,n);for(let l=0,c=r.length;l<c;l++){const a=dr(r[l],this,s);a&&t.push(a)}}}else Vh.call(this,s,t)}function Wh(s={}){return this.boundsTree=new be(this,s),this.boundsTree}function gh(){this.boundsTree=null}function Ch(s=-1,t={}){if(!fh)throw new Error("BatchedMesh: Three r166+ is required to compute bounds trees.");t.indirect&&console.warn('"Indirect" is set to false because it is not supported for BatchedMesh.'),t={...t,indirect:!1,range:null};const e=this._drawRanges||this._geometryInfo,i=this._geometryCount;this.boundsTrees||(this.boundsTrees=new Array(i).fill(null));const n=this.boundsTrees;for(;n.length<i;)n.push(null);if(s<0){for(let o=0;o<i;o++)t.range=e[o],n[o]=new be(this.geometry,t);return n}else return s<e.length&&(t.range=e[s],n[s]=new be(this.geometry,t)),n[s]||null}function zh(s=-1){s<0?this.boundsTrees.fill(null):s<this.boundsTree.length&&(this.boundsTrees[s]=null)}function vh(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Kh(s){switch(s){case 1:return X.RedFormat;case 2:return X.RGFormat;case 3:return X.RGBAFormat;case 4:return X.RGBAFormat}}function mr(s){switch(s){case 1:return X.RedIntegerFormat;case 2:return X.RGIntegerFormat;case 3:return X.RGBAIntegerFormat;case 4:return X.RGBAIntegerFormat}}class nn extends X.DataTexture{constructor(){super(),this.minFilter=X.NearestFilter,this.magFilter=X.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(t){const e=this.overrideItemSize,i=t.itemSize,n=t.count;if(e!==null){if(i*n%e!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");t.itemSize=e,t.count=n*i/e}const o=t.itemSize,r=t.count,l=t.normalized,c=t.array.constructor,a=c.BYTES_PER_ELEMENT;let d=this._forcedType,h=o;if(d===null)switch(c){case Float32Array:d=X.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=X.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=X.IntType;break}let u,p,m,b,G=vh(o);switch(d){case X.FloatType:m=1,p=Kh(o),l&&a===1?(b=c,G+="8",c===Uint8Array?u=X.UnsignedByteType:(u=X.ByteType,G+="_SNORM")):(b=Float32Array,G+="32F",u=X.FloatType);break;case X.IntType:G+=a*8+"I",m=l?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,p=mr(o),a===1?(b=Int8Array,u=X.ByteType):a===2?(b=Int16Array,u=X.ShortType):(b=Int32Array,u=X.IntType);break;case X.UnsignedIntType:G+=a*8+"UI",m=l?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,p=mr(o),a===1?(b=Uint8Array,u=X.UnsignedByteType):a===2?(b=Uint16Array,u=X.UnsignedShortType):(b=Uint32Array,u=X.UnsignedIntType);break}h===3&&(p===X.RGBAFormat||p===X.RGBAIntegerFormat)&&(h=4);const y=Math.ceil(Math.sqrt(r))||1,Z=h*y*y,V=new b(Z),R=t.normalized;t.normalized=!1;for(let f=0;f<r;f++){const x=h*f;V[x]=t.getX(f)/m,o>=2&&(V[x+1]=t.getY(f)/m),o>=3&&(V[x+2]=t.getZ(f)/m,h===4&&(V[x+3]=1)),o>=4&&(V[x+3]=t.getW(f)/m)}t.normalized=R,this.internalFormat=G,this.format=p,this.type=u,this.image.width=y,this.image.height=y,this.image.data=V,this.needsUpdate=!0,this.dispose(),t.itemSize=i,t.count=n}}class Yc extends nn{constructor(){super(),this._forcedType=X.UnsignedIntType}}class Th extends nn{constructor(){super(),this._forcedType=X.IntType}}class kc extends nn{constructor(){super(),this._forcedType=X.FloatType}}class Mh{constructor(){this.index=new Yc,this.position=new kc,this.bvhBounds=new X.DataTexture,this.bvhContents=new X.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){const{geometry:e}=t;if(kh(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(e.attributes.position),t.indirect){const i=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(e.index)this._cachedIndexAttr=e.index.clone();else{const n=Cc(gc(e));this._cachedIndexAttr=new X.BufferAttribute(n,1,!1)}Yh(e,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(e.index)}dispose(){const{index:t,position:e,bvhBounds:i,bvhContents:n}=this;t&&t.dispose(),e&&e.dispose(),i&&i.dispose(),n&&n.dispose()}}function Yh(s,t,e){const i=e.array,n=s.index?s.index.array:null;for(let o=0,r=t.length;o<r;o++){const l=3*o,c=3*t[o];for(let a=0;a<3;a++)i[l+a]=n?n[c+a]:c+a}}function kh(s,t,e){const i=s._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const n=i[0],o=new Uint16Array(n),r=new Uint32Array(n),l=new Float32Array(n),c=n.byteLength/pe,a=2*Math.ceil(Math.sqrt(c/2)),d=new Float32Array(4*a*a),h=Math.ceil(Math.sqrt(c)),u=new Uint32Array(2*h*h);for(let p=0;p<c;p++){const m=p*pe/4,b=m*2,G=m;for(let y=0;y<3;y++)d[8*p+0+y]=l[G+0+y],d[8*p+4+y]=l[G+3+y];if(Zt(b,o)){const y=gt(b,o),Z=xt(m,r),V=4294901760|y;u[p*2+0]=V,u[p*2+1]=Z}else{const y=4*Ct(m,r)/pe,Z=ho(m,r);u[p*2+0]=Z,u[p*2+1]=y}}t.image.data=d,t.image.width=a,t.image.height=a,t.format=X.RGBAFormat,t.type=X.FloatType,t.internalFormat="RGBA32F",t.minFilter=X.NearestFilter,t.magFilter=X.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose(),e.image.data=u,e.image.width=h,e.image.height=h,e.format=X.RGIntegerFormat,e.type=X.UnsignedIntType,e.internalFormat="RG32UI",e.minFilter=X.NearestFilter,e.magFilter=X.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose()}const ve=new X.Vector3,Ke=new X.Vector3,Te=new X.Vector3,br=new X.Vector4,Ys=new X.Vector3,gn=new X.Vector3,yr=new X.Vector4,Gr=new X.Vector4,ks=new X.Matrix4,Zr=new X.Matrix4;function Xi(s,t){if(!s&&!t)return;const e=s.count===t.count,i=s.normalized===t.normalized,n=s.array.constructor===t.array.constructor,o=s.itemSize===t.itemSize;if(!e||!i||!n||!o)throw new Error}function Li(s,t=null){const e=s.array.constructor,i=s.normalized,n=s.itemSize,o=t===null?s.count:t;return new X.BufferAttribute(new e(n*o),n,i)}function Hc(s,t,e=0){if(s.isInterleavedBufferAttribute){const i=s.itemSize;for(let n=0,o=s.count;n<o;n++){const r=n+e;t.setX(r,s.getX(n)),i>=2&&t.setY(r,s.getY(n)),i>=3&&t.setZ(r,s.getZ(n)),i>=4&&t.setW(r,s.getW(n))}}else{const i=t.array,n=i.constructor,o=i.BYTES_PER_ELEMENT*s.itemSize*e;new n(i.buffer,o,s.array.length).set(s.array)}}function Hh(s,t,e){const i=s.elements,n=t.elements;for(let o=0,r=n.length;o<r;o++)i[o]+=n[o]*e}function Xr(s,t,e){const i=s.skeleton,n=s.geometry,o=i.bones,r=i.boneInverses;yr.fromBufferAttribute(n.attributes.skinIndex,t),Gr.fromBufferAttribute(n.attributes.skinWeight,t),ks.elements.fill(0);for(let l=0;l<4;l++){const c=Gr.getComponent(l);if(c!==0){const a=yr.getComponent(l);Zr.multiplyMatrices(o[a].matrixWorld,r[a]),Hh(ks,Zr,c)}}return ks.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),e.transformDirection(ks),e}function Cn(s,t,e,i,n){Ys.set(0,0,0);for(let o=0,r=s.length;o<r;o++){const l=t[o],c=s[o];l!==0&&(gn.fromBufferAttribute(c,i),e?Ys.addScaledVector(gn,l):Ys.addScaledVector(gn.sub(n),l))}n.add(Ys)}function Nh(s,t={useGroups:!1,updateIndex:!1,skipAttributes:[]},e=new X.BufferGeometry){const i=s[0].index!==null,{useGroups:n=!1,updateIndex:o=!1,skipAttributes:r=[]}=t,l=new Set(Object.keys(s[0].attributes)),c={};let a=0;e.clearGroups();for(let d=0;d<s.length;++d){const h=s[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(!l.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.');c[p]===void 0&&(c[p]=[]),c[p].push(h.attributes[p]),u++}if(u!==l.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(n){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");e.addGroup(a,p,d),a+=p}}if(i){let d=!1;if(!e.index){let h=0;for(let u=0;u<s.length;++u)h+=s[u].index.count;e.setIndex(new X.BufferAttribute(new Uint32Array(h),1,!1)),d=!0}if(o||d){const h=e.index;let u=0,p=0;for(let m=0;m<s.length;++m){const b=s[m],G=b.index;if(r[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 c){const h=c[d];if(!(d in e.attributes)){let m=0;for(const b in h)m+=h[b].count;e.setAttribute(d,Li(c[d][0],m))}const u=e.attributes[d];let p=0;for(let m=0,b=h.length;m<b;m++){const G=h[m];r[m]!==!0&&Hc(G,u,p),p+=G.count}}return e}function Ih(s,t){if(s===null||t===null)return s===t;if(s.length!==t.length)return!1;for(let e=0,i=s.length;e<i;e++)if(s[e]!==t[e])return!1;return!0}function Jh(s){const{index:t,attributes:e}=s;if(t)for(let i=0,n=t.count;i<n;i+=3){const o=t.getX(i),r=t.getX(i+2);t.setX(i,r),t.setX(i+2,o)}else for(const i in e){const n=e[i],o=n.itemSize;for(let r=0,l=n.count;r<l;r+=3)for(let c=0;c<o;c++){const a=n.getComponent(r,c),d=n.getComponent(r+2,c);n.setComponent(r,c,d),n.setComponent(r+2,c,a)}}return s}class Uh{constructor(t){this.matrixWorld=new X.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=t,this.update()}update(){const t=this.mesh,e=t.geometry,i=t.skeleton,n=(e.index?e.index.count:e.attributes.position.count)/3;if(this.matrixWorld.copy(t.matrixWorld),this.geometryHash=e.attributes.position.version,this.primitiveCount=n,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 t=this.mesh,e=t.geometry,i=(e.index?e.index.count:e.attributes.position.count)/3;return!(this.matrixWorld.equals(t.matrixWorld)&&this.geometryHash===e.attributes.position.version&&Ih(t.skeleton&&t.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class Ph{constructor(t){Array.isArray(t)||(t=[t]);const e=[];t.forEach(i=>{i.traverseVisible(n=>{n.isMesh&&e.push(n)})}),this.meshes=e,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(e.length).fill().map(()=>new X.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const t=[];return this.meshes.forEach(e=>{Array.isArray(e.material)?t.push(...e.material):t.push(e.material)}),t}generate(t=new X.BufferGeometry){let e=[];const{meshes:i,useGroups:n,_intermediateGeometry:o,_diffMap:r}=this;for(let l=0,c=i.length;l<c;l++){const a=i[l],d=o[l],h=r.get(a);!h||h.didChange(a)?(this._convertToStaticGeometry(a,d),e.push(!1),h?h.update():r.set(a,new Uh(a))):e.push(!0)}if(o.length===0){t.setIndex(null);const l=t.attributes;for(const c in l)t.deleteAttribute(c);for(const c in this.attributes)t.setAttribute(this.attributes[c],new X.BufferAttribute(new Float32Array(0),4,!1))}else Nh(o,{useGroups:n,skipAttributes:e},t);for(const l in t.attributes)t.attributes[l].needsUpdate=!0;return t}_convertToStaticGeometry(t,e=new X.BufferGeometry){const i=t.geometry,n=this.applyWorldTransforms,o=this.attributes.includes("normal"),r=this.attributes.includes("tangent"),l=i.attributes,c=e.attributes;!e.index&&i.index&&(e.index=i.index.clone()),c.position||e.setAttribute("position",Li(l.position)),o&&!c.normal&&l.normal&&e.setAttribute("normal",Li(l.normal)),r&&!c.tangent&&l.tangent&&e.setAttribute("tangent",Li(l.tangent)),Xi(i.index,e.index),Xi(l.position,c.position),o&&Xi(l.normal,c.normal),r&&Xi(l.tangent,c.tangent);const a=l.position,d=o?l.normal:null,h=r?l.tangent:null,u=i.morphAttributes.position,p=i.morphAttributes.normal,m=i.morphAttributes.tangent,b=i.morphTargetsRelative,G=t.morphTargetInfluences,y=new X.Matrix3;y.getNormalMatrix(t.matrixWorld),i.index&&e.index.array.set(i.index.array);for(let Z=0,V=l.position.count;Z<V;Z++)ve.fromBufferAttribute(a,Z),d&&Ke.fromBufferAttribute(d,Z),h&&(br.fromBufferAttribute(h,Z),Te.fromBufferAttribute(h,Z)),G&&(u&&Cn(u,G,b,Z,ve),p&&Cn(p,G,b,Z,Ke),m&&Cn(m,G,b,Z,Te)),t.isSkinnedMesh&&(t.applyBoneTransform(Z,ve),d&&Xr(t,Z,Ke),h&&Xr(t,Z,Te)),n&&ve.applyMatrix4(t.matrixWorld),c.position.setXYZ(Z,ve.x,ve.y,ve.z),d&&(n&&Ke.applyNormalMatrix(y),c.normal.setXYZ(Z,Ke.x,Ke.y,Ke.z)),h&&(n&&Te.transformDirection(t.matrixWorld),c.tangent.setXYZW(Z,Te.x,Te.y,Te.z,br.w));for(const Z in this.attributes){const V=this.attributes[Z];V==="position"||V==="tangent"||V==="normal"||!(V in l)||(c[V]||e.setAttribute(V,Li(l[V])),Xi(l[V],c[V]),Hc(l[V],c[V]))}return t.matrixWorld.determinant()<0&&Jh(e),e}}const Nc=`
1121
+ }`;class td extends Rc{constructor(t){super(t),this.vector_=new M,this.vector2_=new M,this.vector3_=new M,this.quaternion_=new Q,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new X.BufferGeometry,this.indexBuffer=new X.BufferAttribute(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new X.BufferAttribute(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(X.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(t){for(;t>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const t={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new De(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},e={};if(e.USE_UV="",e.USE_COLOR_ALPHA="",this.settings.material.map&&(e.USE_MAP="",e.MAP_UV=Fn(this.settings.material.map.channel),t.map=new X.Uniform$1(this.settings.material.map),t.mapTransform=new X.Uniform$1(new Bt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(e.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===exports.RenderMode.Trail)this.material=new X.ShaderMaterial({uniforms:t,defines:e,vertexShader:$a,fragmentShader:qa,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||X.AdditiveBlending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let t=0,e=0,i=0;this.systems.forEach(n=>{for(let o=0;o<n.particleNum;o++)i+=n.particles[o].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(n=>{n.emitter.updateMatrixWorld&&(n.emitter.updateWorldMatrix(!0,!1),n.emitter.updateMatrixWorld(!0));const o=this.quaternion_,r=this.vector2_,l=this.vector3_;n.emitter.matrixWorld.decompose(r,o,l);const c=n.particles,a=n.particleNum,d=this.settings.uTileCount,h=this.settings.vTileCount,u=1/d,p=1/h;for(let m=0;m<a;m++){const b=c[m],G=b.uvTile%h,y=Math.floor(b.uvTile/h+.001),Z=b.previous.values();let V=Z.next(),R=V.value,f=R;V.done||(V=Z.next());let x;V.value!==void 0?x=V.value:x=f;for(let L=0;L<b.previous.length;L++,t+=2){if(this.positionBuffer.setXYZ(t,f.position.x,f.position.y,f.position.z),this.positionBuffer.setXYZ(t+1,f.position.x,f.position.y,f.position.z),n.worldSpace?(this.positionBuffer.setXYZ(t,f.position.x,f.position.y,f.position.z),this.positionBuffer.setXYZ(t+1,f.position.x,f.position.y,f.position.z)):(b.parentMatrix?this.vector_.copy(f.position).applyMatrix4(b.parentMatrix):this.vector_.copy(f.position).applyMatrix4(n.emitter.matrixWorld),this.positionBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.previousBuffer.setXYZ(t,R.position.x,R.position.y,R.position.z),this.previousBuffer.setXYZ(t+1,R.position.x,R.position.y,R.position.z)):(b.parentMatrix?this.vector_.copy(R.position).applyMatrix4(b.parentMatrix):this.vector_.copy(R.position).applyMatrix4(n.emitter.matrixWorld),this.previousBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),n.worldSpace?(this.nextBuffer.setXYZ(t,x.position.x,x.position.y,x.position.z),this.nextBuffer.setXYZ(t+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(n.emitter.matrixWorld),this.nextBuffer.setXYZ(t,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(t+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(t,-1),this.sideBuffer.setX(t+1,1),n.worldSpace)this.widthBuffer.setX(t,f.size),this.widthBuffer.setX(t+1,f.size);else if(b.parentMatrix)this.widthBuffer.setX(t,f.size),this.widthBuffer.setX(t+1,f.size);else{const W=(Math.abs(l.x)+Math.abs(l.y)+Math.abs(l.z))/3;this.widthBuffer.setX(t,f.size*W),this.widthBuffer.setX(t+1,f.size*W)}this.uvBuffer.setXY(t,(L/b.previous.length+G)*u,(h-y-1)*p),this.uvBuffer.setXY(t+1,(L/b.previous.length+G)*u,(h-y)*p),this.colorBuffer.setXYZW(t,f.color.x,f.color.y,f.color.z,f.color.w),this.colorBuffer.setXYZW(t+1,f.color.x,f.color.y,f.color.z,f.color.w),L+1<b.previous.length&&(this.indexBuffer.setX(e*3,t),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+2),e++,this.indexBuffer.setX(e*3,t+2),this.indexBuffer.setX(e*3+1,t+1),this.indexBuffer.setX(e*3+2,t+3),e++),R=f,f=x,V.done||(V=Z.next(),V.value!==void 0&&(x=V.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,t*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,t*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,t*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,t),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,t),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,t*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,t*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,e*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,e*3)}dispose(){this.geometry.dispose()}}class rs{get geometry(){return this._geometry}set geometry(t){if(this._geometry=t,t===void 0||typeof t=="string")return;const e=new X.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!t.getIndex())return;const n=t.getIndex().array,o=n.length/3;this._triangleIndexToArea.push(0);for(let r=0;r<o;r++)e.setFromAttributeAndIndices(t.getAttribute("position"),n[r*3],n[r*3+1],n[r*3+2]),i+=e.getArea(),this._triangleIndexToArea.push(i);t.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(t){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new X.Vector3,this._tempB=new X.Vector3,this._tempC=new X.Vector3,t&&(this.geometry=t)}initialize(t){const e=this._geometry;if(!e||e.getIndex()===null){t.position.set(0,0,0),t.velocity.set(0,0,1).multiplyScalar(t.startSpeed);return}const i=this._triangleIndexToArea.length-1;let n=0,o=i;const r=Math.random()*this._triangleIndexToArea[i];for(;n+1<o;){const p=Math.floor((n+o)/2);r<this._triangleIndexToArea[p]?o=p:n=p}let l=Math.random(),c=Math.random();l+c>1&&(l=1-l,c=1-c);const a=e.getIndex().array[n*3],d=e.getIndex().array[n*3+1],h=e.getIndex().array[n*3+2],u=e.getAttribute("position");this._tempA.fromBufferAttribute(u,a),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,l).addScaledVector(this._tempC,c),t.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),t.velocity.copy(this._tempA).normalize().multiplyScalar(t.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(t,e){return new rs(e.geometries[t.geometry])}clone(){return new rs(this._geometry)}update(t,e){}}Ka({id:"three.quarks",initialize:()=>{},emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:rs,loadJSON:rs.fromJSON}],behaviors:[]});class lo extends X.Object3D{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(t,e){return t.material.side===e.material.side&&t.material.blending===e.material.blending&&t.material.blendSrc===e.material.blendSrc&&t.material.blendDst===e.material.blendDst&&t.material.blendEquation===e.material.blendEquation&&t.material.premultipliedAlpha===e.material.premultipliedAlpha&&t.material.transparent===e.material.transparent&&t.material.depthTest===e.material.depthTest&&t.material.type===e.material.type&&t.material.alphaTest===e.material.alphaTest&&t.material.map===e.material.map&&t.renderMode===e.renderMode&&t.blendTiles===e.blendTiles&&t.softParticles===e.softParticles&&t.softFarFade===e.softFarFade&&t.softNearFade===e.softNearFade&&t.uTileCount===e.uTileCount&&t.vTileCount===e.vTileCount&&t.instancingGeometry===e.instancingGeometry&&t.renderOrder===e.renderOrder&&t.layers.mask===e.layers.mask}addSystem(t){t._renderer=this;const e=t.getRendererSettings();for(let n=0;n<this.batches.length;n++)if(lo.equals(this.batches[n].settings,e)){this.batches[n].addSystem(t),this.systemToBatchIndex.set(t,n);return}let i;switch(e.renderMode){case exports.RenderMode.Trail:i=new td(e);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new Aa(e);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(t),this.batches.push(i),this.systemToBatchIndex.set(t,this.batches.length-1),this.add(i)}deleteSystem(t){const e=this.systemToBatchIndex.get(t);e!=null&&(this.batches[e].removeSystem(t),this.systemToBatchIndex.delete(t))}setDepthTexture(t){this.depthTexture=t;for(const e of this.batches)e.applyDepthTexture(t)}updateSystem(t){this.deleteSystem(t),this.addSystem(t)}update(t){this.systemToBatchIndex.forEach((e,i)=>{i.update(t)});for(let e=0;e<this.batches.length;e++)this.batches[e].update()}}const ed=lo;Ua();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const xc=Math.sqrt(5),id=(xc-1)/4,ct=(5-xc)/20,Gs=s=>Math.floor(s)|0,Zs=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 sd(s=Math.random){const t=nd(s),e=new Float64Array(t).map(r=>Zs[r%32*4]),i=new Float64Array(t).map(r=>Zs[r%32*4+1]),n=new Float64Array(t).map(r=>Zs[r%32*4+2]),o=new Float64Array(t).map(r=>Zs[r%32*4+3]);return function(l,c,a,d){let h,u,p,m,b;const G=(l+c+a+d)*id,y=Gs(l+G),Z=Gs(c+G),V=Gs(a+G),R=Gs(d+G),f=(y+Z+V+R)*ct,x=y-f,L=Z-f,W=V-f,C=R-f,S=l-x,z=c-L,g=a-W,v=d-C;let K=0,Y=0,H=0,I=0;S>z?K++:Y++,S>g?K++:H++,S>v?K++:I++,z>g?Y++:H++,z>v?Y++:I++,g>v?H++:I++;const P=K>=3?1:0,D=Y>=3?1:0,it=H>=3?1:0,tt=I>=3?1:0,St=K>=2?1:0,Vt=Y>=2?1:0,st=H>=2?1:0,pt=I>=2?1:0,et=K>=1?1:0,j=Y>=1?1:0,oe=H>=1?1:0,_=I>=1?1:0,Ut=S-P+ct,jt=z-D+ct,ye=g-it+ct,Ge=v-tt+ct,Ze=S-St+2*ct,Xe=z-Vt+2*ct,fe=g-st+2*ct,Ve=v-pt+2*ct,Re=S-et+3*ct,xe=z-j+3*ct,Le=g-oe+3*ct,Ot=v-_+3*ct,Dt=S-1+4*ct,_t=z-1+4*ct,At=g-1+4*ct,qt=v-1+4*ct,Tt=y&255,Mt=Z&255,Yt=V&255,kt=R&255;let F=.6-S*S-z*z-g*g-v*v;if(F<0)h=0;else{const O=Tt+t[Mt+t[Yt+t[kt]]];F*=F,h=F*F*(e[O]*S+i[O]*z+n[O]*g+o[O]*v)}let ei=.6-Ut*Ut-jt*jt-ye*ye-Ge*Ge;if(ei<0)u=0;else{const O=Tt+P+t[Mt+D+t[Yt+it+t[kt+tt]]];ei*=ei,u=ei*ei*(e[O]*Ut+i[O]*jt+n[O]*ye+o[O]*Ge)}let ii=.6-Ze*Ze-Xe*Xe-fe*fe-Ve*Ve;if(ii<0)p=0;else{const O=Tt+St+t[Mt+Vt+t[Yt+st+t[kt+pt]]];ii*=ii,p=ii*ii*(e[O]*Ze+i[O]*Xe+n[O]*fe+o[O]*Ve)}let si=.6-Re*Re-xe*xe-Le*Le-Ot*Ot;if(si<0)m=0;else{const O=Tt+et+t[Mt+j+t[Yt+oe+t[kt+_]]];si*=si,m=si*si*(e[O]*Re+i[O]*xe+n[O]*Le+o[O]*Ot)}let ni=.6-Dt*Dt-_t*_t-At*At-qt*qt;if(ni<0)b=0;else{const O=Tt+1+t[Mt+1+t[Yt+1+t[kt+1]]];ni*=ni,b=ni*ni*(e[O]*Dt+i[O]*_t+n[O]*At+o[O]*qt)}return 27*(h+u+p+m+b)}}function nd(s){const e=new Uint8Array(512);for(let i=0;i<512/2;i++)e[i]=i;for(let i=0;i<512/2-1;i++){const n=i+~~(s()*(256-i)),o=e[i];e[i]=e[n],e[n]=o}for(let i=256;i<512;i++)e[i]=e[i-256];return e}class od{constructor(t){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Backoff must be a positive integer");this.backoff=t}get retries(){return this._retries}get current(){return this.backoff}next(){return this._retries++,this.backoff}reset(){this._retries=0}}class rd{constructor(t,e){if(this._retries=0,!Number.isInteger(t)||t<0)throw new Error("Base must be a positive integer or zero");if(e!==void 0&&(!Number.isInteger(e)||e<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=t,this.expMax=e,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}class cd{constructor(t,e,i){if(this.i=0,this._retries=0,t<0)throw new Error("Initial must be a positive number or zero");if(e<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<t)throw new Error("Max must be undefined or greater than or equal to initial");this.initial=t,this.increment=e,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 ld{constructor(){this.elements=[]}add(t){this.elements.push(t)}clear(){this.elements.length=0}forEach(t){this.elements.forEach(t)}length(){return this.elements.length}isEmpty(){return this.elements.length===0}peek(){return this.elements[0]}read(){return this.elements.shift()}}class ad{constructor(t){if(!Number.isInteger(t)||t<=0)throw new Error("Capacity must be a positive integer");this.elements=new Array(t+1),this.head=0,this.tail=0}add(t){this.elements[this.head]=t,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(t){for(let e=this.tail;e!==this.head;e=(e+1)%this.elements.length)t(this.elements[e])}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 t=this.peek();return t!==void 0&&(this.tail=(this.tail+1)%this.elements.length),t}}var w;(function(s){s.open="open",s.close="close",s.error="error",s.message="message",s.retry="retry",s.reconnect="reconnect"})(w||(w={}));class Lc{constructor(t,e,i){var n,o,r,l,c,a,d,h,u,p,m,b,G,y,Z;this._closedByUser=!1,this.handleOpenEvent=V=>this.handleEvent(w.open,V),this.handleErrorEvent=V=>this.handleEvent(w.error,V),this.handleCloseEvent=V=>this.handleEvent(w.close,V),this.handleMessageEvent=V=>this.handleEvent(w.message,V),this._url=t,this._protocols=e,this._options={buffer:i==null?void 0:i.buffer,retry:{maxRetries:(n=i==null?void 0:i.retry)===null||n===void 0?void 0:n.maxRetries,instantReconnect:(o=i==null?void 0:i.retry)===null||o===void 0?void 0:o.instantReconnect,backoff:(r=i==null?void 0:i.retry)===null||r===void 0?void 0:r.backoff},listeners:{open:[...(c=(l=i==null?void 0:i.listeners)===null||l===void 0?void 0:l.open)!==null&&c!==void 0?c:[]],close:[...(d=(a=i==null?void 0:i.listeners)===null||a===void 0?void 0:a.close)!==null&&d!==void 0?d:[]],error:[...(u=(h=i==null?void 0:i.listeners)===null||h===void 0?void 0:h.error)!==null&&u!==void 0?u:[]],message:[...(m=(p=i==null?void 0:i.listeners)===null||p===void 0?void 0:p.message)!==null&&m!==void 0?m:[]],retry:[...(G=(b=i==null?void 0:i.listeners)===null||b===void 0?void 0:b.retry)!==null&&G!==void 0?G:[]],reconnect:[...(Z=(y=i==null?void 0: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(t){this._underlyingWebsocket.binaryType=t}send(t){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(t):this.buffer!==void 0&&this.buffer.add(t))}close(t,e){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(t,e)}addEventListener(t,e,i){this._options.listeners[t].push({listener:e,options:i})}removeEventListener(t,e,i){const n=o=>o.listener!==e||o.options!==i;this._options.listeners[t]=this._options.listeners[t].filter(n)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(w.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(w.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(w.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(w.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(w.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(w.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(w.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(w.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(t,e){const i=this._options.listeners[t],n=[];i.forEach(({listener:o,options:r})=>{o(this,e),(r===void 0||r.once===void 0||!r.once)&&n.push({listener:o,options:r})}),this._options.listeners[t]=n}handleEvent(t,e){switch(t){case w.close:this.dispatchEvent(t,e),this.scheduleConnectionRetryIfNeeded();break;case w.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},n=new CustomEvent(w.reconnect,{detail:i});this.dispatchEvent(w.reconnect,n),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(t,e),this.sendBufferedData();break;case w.retry:this.dispatchEvent(t,e),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(t,e);break}}sendBufferedData(){if(this.buffer!==void 0)for(let t=this.buffer.read();t!==void 0;t=this.buffer.read())this.send(t)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const t=i=>{const n=new CustomEvent(w.retry,{detail:i});this.handleEvent(w.retry,n)},e={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||e.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>t(e),e.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class dd{constructor(t){this._url=t}get url(){return this._url}withProtocols(t){return this._protocols=t,this}get protocols(){return this._protocols}withMaxRetries(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{maxRetries:t})}),this}get maxRetries(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.maxRetries}withInstantReconnect(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{instantReconnect:t})}),this}get instantReconnect(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.instantReconnect}withBackoff(t){var e;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(e=this._options)===null||e===void 0?void 0:e.retry),{backoff:t})}),this}get backoff(){var t,e;return(e=(t=this._options)===null||t===void 0?void 0:t.retry)===null||e===void 0?void 0:e.backoff}withBuffer(t){return this._options=Object.assign(Object.assign({},this._options),{buffer:t}),this}get buffer(){var t;return(t=this._options)===null||t===void 0?void 0:t.buffer}onOpen(t,e){return this.addListener(w.open,t,e),this}onClose(t,e){return this.addListener(w.close,t,e),this}onError(t,e){return this.addListener(w.error,t,e),this}onMessage(t,e){return this.addListener(w.message,t,e),this}onRetry(t,e){return this.addListener(w.retry,t,e),this}onReconnect(t,e){return this.addListener(w.reconnect,t,e),this}build(){return new Lc(this._url,this._protocols,this._options)}addListener(t,e,i){var n,o,r,l,c,a,d,h,u,p,m,b,G,y,Z,V,R,f,x,L,W;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(r=(o=(n=this._options)===null||n===void 0?void 0:n.listeners)===null||o===void 0?void 0:o.open)!==null&&r!==void 0?r:[],close:(a=(c=(l=this._options)===null||l===void 0?void 0:l.listeners)===null||c===void 0?void 0:c.close)!==null&&a!==void 0?a:[],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:(f=(R=(V=this._options)===null||V===void 0?void 0:V.listeners)===null||R===void 0?void 0:R.reconnect)!==null&&f!==void 0?f:[],[t]:[...(W=(L=(x=this._options)===null||x===void 0?void 0:x.listeners)===null||L===void 0?void 0:L[t])!==null&&W!==void 0?W:[],{listener:e,options:i}]}}),this}}const hd=Object.freeze(Object.defineProperty({__proto__:null,ArrayQueue:ld,ConstantBackoff:od,ExponentialBackoff:rd,LinearBackoff:cd,RingQueue:ad,Websocket:Lc,WebsocketBuilder:dd,get WebsocketEvent(){return w}},Symbol.toStringTag,{value:"Module"})),ao=0,Sc=1,Wc=2,ud=0,pd=1,Qn=2,Us=1.25,wn=1,pe=6*4+4+4,en=65535,md=Math.pow(2,-24),Gn=Symbol("SKIP_GENERATION");function gc(s){return s.index?s.index.count:s.attributes.position.count}function ti(s){return gc(s)/3}function Cc(s,t=ArrayBuffer){return s>65535?new Uint32Array(new t(4*s)):new Uint16Array(new t(2*s))}function bd(s,t){if(!s.index){const e=s.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Cc(e,i);s.setIndex(new X.BufferAttribute(n,1));for(let o=0;o<e;o++)n[o]=o}}function zc(s,t){const e=ti(s),i=t||s.drawRange,n=i.start/3,o=(i.start+i.count)/3,r=Math.max(0,n),l=Math.min(e,o)-r;return[{offset:Math.floor(r),count:Math.floor(l)}]}function vc(s,t){if(!s.groups||!s.groups.length)return zc(s,t);const e=[],i=new Set,n=t||s.drawRange,o=n.start/3,r=(n.start+n.count)/3;for(const c of s.groups){const a=c.start/3,d=(c.start+c.count)/3;i.add(Math.max(o,a)),i.add(Math.min(r,d))}const l=Array.from(i.values()).sort((c,a)=>c-a);for(let c=0;c<l.length-1;c++){const a=l[c],d=l[c+1];e.push({offset:Math.floor(a),count:Math.floor(d-a)})}return e}function yd(s,t){const e=ti(s),i=vc(s,t).sort((r,l)=>r.offset-l.offset),n=i[i.length-1];n.count=Math.min(e-n.offset,n.count);let o=0;return i.forEach(({count:r})=>o+=r),e!==o}function Zn(s,t,e,i,n){let o=1/0,r=1/0,l=1/0,c=-1/0,a=-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=t*6,Z=(t+e)*6;y<Z;y+=6){const V=s[y+0],R=s[y+1],f=V-R,x=V+R;f<o&&(o=f),x>c&&(c=x),V<h&&(h=V),V>m&&(m=V);const L=s[y+2],W=s[y+3],C=L-W,S=L+W;C<r&&(r=C),S>a&&(a=S),L<u&&(u=L),L>b&&(b=L);const z=s[y+4],g=s[y+5],v=z-g,K=z+g;v<l&&(l=v),K>d&&(d=K),z<p&&(p=z),z>G&&(G=z)}i[0]=o,i[1]=r,i[2]=l,i[3]=c,i[4]=a,i[5]=d,n[0]=h,n[1]=u,n[2]=p,n[3]=m,n[4]=b,n[5]=G}function Gd(s,t=null,e=null,i=null){const n=s.attributes.position,o=s.index?s.index.array:null,r=ti(s),l=n.normalized;let c;t===null?(c=new Float32Array(r*6),e=0,i=r):(c=t,e=e||0,i=i||r);const a=n.array,d=n.offset||0;let h=3;n.isInterleavedBufferAttribute&&(h=n.data.stride);const u=["getX","getY","getZ"];for(let p=e;p<e+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]),l||(G=G*h+d,y=y*h+d,Z=Z*h+d);for(let V=0;V<3;V++){let R,f,x;l?(R=n[u[V]](G),f=n[u[V]](y),x=n[u[V]](Z)):(R=a[G+V],f=a[y+V],x=a[Z+V]);let L=R;f<L&&(L=f),x<L&&(L=x);let W=R;f>W&&(W=f),x>W&&(W=x);const C=(W-L)/2,S=V*2;c[b+S+0]=L+C,c[b+S+1]=C+(Math.abs(L)+C)*md}}return c}function B(s,t,e){return e.min.x=t[s],e.min.y=t[s+1],e.min.z=t[s+2],e.max.x=t[s+3],e.max.y=t[s+4],e.max.z=t[s+5],e}function Oo(s){let t=-1,e=-1/0;for(let i=0;i<3;i++){const n=s[i+3]-s[i];n>e&&(e=n,t=i)}return t}function Do(s,t){t.set(s)}function _o(s,t,e){let i,n;for(let o=0;o<3;o++){const r=o+3;i=s[o],n=t[o],e[o]=i<n?i:n,i=s[r],n=t[r],e[r]=i>n?i:n}}function Xs(s,t,e){for(let i=0;i<3;i++){const n=t[s+2*i],o=t[s+2*i+1],r=n-o,l=n+o;r<e[i]&&(e[i]=r),l>e[i+3]&&(e[i+3]=l)}}function li(s){const t=s[3]-s[0],e=s[4]-s[1],i=s[5]-s[2];return 2*(t*e+e*i+i*t)}const $t=32,Zd=(s,t)=>s.candidate-t.candidate,le=new Array($t).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),fs=new Float32Array(6);function Xd(s,t,e,i,n,o){let r=-1,l=0;if(o===ao)r=Oo(t),r!==-1&&(l=(t[r]+t[r+3])/2);else if(o===Sc)r=Oo(s),r!==-1&&(l=fd(e,i,n,r));else if(o===Wc){const c=li(s);let a=Us*n;const d=i*6,h=(i+n)*6;for(let u=0;u<3;u++){const p=t[u],G=(t[u+3]-p)/$t;if(n<$t/4){const y=[...le];y.length=n;let Z=0;for(let R=d;R<h;R+=6,Z++){const f=y[Z];f.candidate=e[R+2*u],f.count=0;const{bounds:x,leftCacheBounds:L,rightCacheBounds:W}=f;for(let C=0;C<3;C++)W[C]=1/0,W[C+3]=-1/0,L[C]=1/0,L[C+3]=-1/0,x[C]=1/0,x[C+3]=-1/0;Xs(R,e,x)}y.sort(Zd);let V=n;for(let R=0;R<V;R++){const f=y[R];for(;R+1<V&&y[R+1].candidate===f.candidate;)y.splice(R+1,1),V--}for(let R=d;R<h;R+=6){const f=e[R+2*u];for(let x=0;x<V;x++){const L=y[x];f>=L.candidate?Xs(R,e,L.rightCacheBounds):(Xs(R,e,L.leftCacheBounds),L.count++)}}for(let R=0;R<V;R++){const f=y[R],x=f.count,L=n-f.count,W=f.leftCacheBounds,C=f.rightCacheBounds;let S=0;x!==0&&(S=li(W)/c);let z=0;L!==0&&(z=li(C)/c);const g=wn+Us*(S*x+z*L);g<a&&(r=u,a=g,l=f.candidate)}}else{for(let V=0;V<$t;V++){const R=le[V];R.count=0,R.candidate=p+G+V*G;const f=R.bounds;for(let x=0;x<3;x++)f[x]=1/0,f[x+3]=-1/0}for(let V=d;V<h;V+=6){let x=~~((e[V+2*u]-p)/G);x>=$t&&(x=$t-1);const L=le[x];L.count++,Xs(V,e,L.bounds)}const y=le[$t-1];Do(y.bounds,y.rightCacheBounds);for(let V=$t-2;V>=0;V--){const R=le[V],f=le[V+1];_o(R.bounds,f.rightCacheBounds,R.rightCacheBounds)}let Z=0;for(let V=0;V<$t-1;V++){const R=le[V],f=R.count,x=R.bounds,W=le[V+1].rightCacheBounds;f!==0&&(Z===0?Do(x,fs):_o(x,fs,fs)),Z+=f;let C=0,S=0;Z!==0&&(C=li(fs)/c);const z=n-Z;z!==0&&(S=li(W)/c);const g=wn+Us*(C*Z+S*z);g<a&&(r=u,a=g,l=R.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${o} used.`);return{axis:r,pos:l}}function fd(s,t,e,i){let n=0;for(let o=t,r=t+e;o<r;o++)n+=s[o*6+i*2];return n/e}class Xn{constructor(){this.boundingData=new Float32Array(6)}}function Vd(s,t,e,i,n,o){let r=i,l=i+n-1;const c=o.pos,a=o.axis*2;for(;;){for(;r<=l&&e[r*6+a]<c;)r++;for(;r<=l&&e[l*6+a]>=c;)l--;if(r<l){for(let d=0;d<3;d++){let h=t[r*3+d];t[r*3+d]=t[l*3+d],t[l*3+d]=h}for(let d=0;d<6;d++){let h=e[r*6+d];e[r*6+d]=e[l*6+d],e[l*6+d]=h}r++,l--}else return r}}function Rd(s,t,e,i,n,o){let r=i,l=i+n-1;const c=o.pos,a=o.axis*2;for(;;){for(;r<=l&&e[r*6+a]<c;)r++;for(;r<=l&&e[l*6+a]>=c;)l--;if(r<l){let d=s[r];s[r]=s[l],s[l]=d;for(let h=0;h<6;h++){let u=e[r*6+h];e[r*6+h]=e[l*6+h],e[l*6+h]=u}r++,l--}else return r}}function Zt(s,t){return t[s+15]===65535}function xt(s,t){return t[s+6]}function gt(s,t){return t[s+14]}function zt(s){return s+8}function Ct(s,t){return t[s+6]}function ho(s,t){return t[s+7]}let Kc,xi,Ps,Tc;const xd=Math.pow(2,32);function Bn(s){return"count"in s?1:1+Bn(s.left)+Bn(s.right)}function Ld(s,t,e){return Kc=new Float32Array(e),xi=new Uint32Array(e),Ps=new Uint16Array(e),Tc=new Uint8Array(e),En(s,t)}function En(s,t){const e=s/4,i=s/2,n="count"in t,o=t.boundingData;for(let r=0;r<6;r++)Kc[e+r]=o[r];if(n)if(t.buffer){const r=t.buffer;Tc.set(new Uint8Array(r),s);for(let l=s,c=s+r.byteLength;l<c;l+=pe){const a=l/2;Zt(a,Ps)||(xi[l/4+6]+=e)}return s+r.byteLength}else{const r=t.offset,l=t.count;return xi[e+6]=r,Ps[i+14]=l,Ps[i+15]=en,s+pe}else{const r=t.left,l=t.right,c=t.splitAxis;let a;if(a=En(s+pe,r),a/4>xd)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return xi[e+6]=a/4,a=En(a,l),xi[e+7]=c,a}}function Sd(s,t){const e=(s.index?s.index.count:s.attributes.position.count)/3,i=e>2**16,n=i?4:2,o=t?new SharedArrayBuffer(e*n):new ArrayBuffer(e*n),r=i?new Uint32Array(o):new Uint16Array(o);for(let l=0,c=r.length;l<c;l++)r[l]=l;return r}function Wd(s,t,e,i,n){const{maxDepth:o,verbose:r,maxLeafTris:l,strategy:c,onProgress:a,indirect:d}=n,h=s._indirectBuffer,u=s.geometry,p=u.index?u.index.array:null,m=d?Rd:Vd,b=ti(u),G=new Float32Array(6);let y=!1;const Z=new Xn;return Zn(t,e,i,Z.boundingData,G),R(Z,e,i,G),Z;function V(f){a&&a(f/b)}function R(f,x,L,W=null,C=0){if(!y&&C>=o&&(y=!0,r&&(console.warn(`MeshBVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`),console.warn(u))),L<=l||C>=o)return V(x+L),f.offset=x,f.count=L,f;const S=Xd(f.boundingData,W,t,x,L,c);if(S.axis===-1)return V(x+L),f.offset=x,f.count=L,f;const z=m(h,p,t,x,L,S);if(z===x||z===x+L)V(x+L),f.offset=x,f.count=L;else{f.splitAxis=S.axis;const g=new Xn,v=x,K=z-x;f.left=g,Zn(t,v,K,g.boundingData,G),R(g,v,K,G,C+1);const Y=new Xn,H=z,I=L-K;f.right=Y,Zn(t,H,I,Y.boundingData,G),R(Y,H,I,G,C+1)}return f}}function gd(s,t){const e=s.geometry;t.indirect&&(s._indirectBuffer=Sd(e,t.useSharedArrayBuffer),yd(e,t.range)&&!t.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),s._indirectBuffer||bd(e,t);const i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=Gd(e),o=t.indirect?zc(e,t.range):vc(e,t.range);s._roots=o.map(r=>{const l=Wd(s,n,r.offset,r.count,t),c=Bn(l),a=new i(pe*c);return Ld(0,l,a),a})}class ne{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,n=-1/0;for(let o=0,r=t.length;o<r;o++){const c=t[o][e];i=c<i?c:i,n=c>n?c:n}this.min=i,this.max=n}setFromPoints(t,e){let i=1/0,n=-1/0;for(let o=0,r=e.length;o<r;o++){const l=e[o],c=t.dot(l);i=c<i?c:i,n=c>n?c:n}this.min=i,this.max=n}isSeparated(t){return this.min>t.max||t.min>this.max}}ne.prototype.setFromBox=function(){const s=new X.Vector3;return function(e,i){const n=i.min,o=i.max;let r=1/0,l=-1/0;for(let c=0;c<=1;c++)for(let a=0;a<=1;a++)for(let d=0;d<=1;d++){s.x=n.x*c+o.x*(1-c),s.y=n.y*a+o.y*(1-a),s.z=n.z*d+o.z*(1-d);const h=e.dot(s);r=Math.min(h,r),l=Math.max(h,l)}this.min=r,this.max=l}}();const Cd=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Vector3;return function(n,o,r){const l=n.start,c=s,a=o.start,d=t;e.subVectors(l,a),s.subVectors(n.end,n.start),t.subVectors(o.end,o.start);const h=e.dot(d),u=d.dot(c),p=d.dot(d),m=e.dot(c),G=c.dot(c)*p-u*u;let y,Z;G!==0?y=(h*u-m*p)/G:y=0,Z=(h+y*u)/p,r.x=y,r.y=Z}}(),uo=function(){const s=new X.Vector2,t=new X.Vector3,e=new X.Vector3;return function(n,o,r,l){Cd(n,o,s);let c=s.x,a=s.y;if(c>=0&&c<=1&&a>=0&&a<=1){n.at(c,r),o.at(a,l);return}else if(c>=0&&c<=1){a<0?o.at(0,l):o.at(1,l),n.closestPointToPoint(l,!0,r);return}else if(a>=0&&a<=1){c<0?n.at(0,r):n.at(1,r),o.closestPointToPoint(r,!0,l);return}else{let d;c<0?d=n.start:d=n.end;let h;a<0?h=o.start:h=o.end;const u=t,p=e;if(n.closestPointToPoint(h,!0,t),o.closestPointToPoint(d,!0,e),u.distanceToSquared(h)<=p.distanceToSquared(d)){r.copy(u),l.copy(h);return}else{r.copy(d),l.copy(p);return}}}}(),zd=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Plane,i=new X.Line3;return function(o,r){const{radius:l,center:c}=o,{a,b:d,c:h}=r;if(i.start=a,i.end=d,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l||(i.start=a,i.end=h,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l)||(i.start=d,i.end=h,i.closestPointToPoint(c,!0,s).distanceTo(c)<=l))return!0;const b=r.getPlane(e);if(Math.abs(b.distanceToPoint(c))<=l){const y=b.projectPoint(c,t);if(r.containsPoint(y))return!0}return!1}}(),vd=1e-15;function fn(s){return Math.abs(s)<vd}class Kt extends X.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new X.Vector3),this.satBounds=new Array(4).fill().map(()=>new ne),this.points=[this.a,this.b,this.c],this.sphere=new X.Sphere,this.plane=new X.Plane,this.needsUpdate=!0}intersectsSphere(t){return zd(t,this)}update(){const t=this.a,e=this.b,i=this.c,n=this.points,o=this.satAxes,r=this.satBounds,l=o[0],c=r[0];this.getNormal(l),c.setFromPoints(l,n);const a=o[1],d=r[1];a.subVectors(t,e),d.setFromPoints(a,n);const h=o[2],u=r[2];h.subVectors(e,i),u.setFromPoints(h,n);const p=o[3],m=r[3];p.subVectors(i,t),m.setFromPoints(p,n),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(l,t),this.needsUpdate=!1}}Kt.prototype.closestPointToSegment=function(){const s=new X.Vector3,t=new X.Vector3,e=new X.Line3;return function(n,o=null,r=null){const{start:l,end:c}=n,a=this.points;let d,h=1/0;for(let u=0;u<3;u++){const p=(u+1)%3;e.start.copy(a[u]),e.end.copy(a[p]),uo(e,n,s,t),d=s.distanceToSquared(t),d<h&&(h=d,o&&o.copy(s),r&&r.copy(t))}return this.closestPointToPoint(l,s),d=l.distanceToSquared(s),d<h&&(h=d,o&&o.copy(s),r&&r.copy(l)),this.closestPointToPoint(c,s),d=c.distanceToSquared(s),d<h&&(h=d,o&&o.copy(s),r&&r.copy(c)),Math.sqrt(h)}}();Kt.prototype.intersectsTriangle=function(){const s=new Kt,t=new Array(3),e=new Array(3),i=new ne,n=new ne,o=new X.Vector3,r=new X.Vector3,l=new X.Vector3,c=new X.Vector3,a=new X.Vector3,d=new X.Line3,h=new X.Line3,u=new X.Line3,p=new X.Vector3;function m(b,G,y){const Z=b.points;let V=0,R=-1;for(let f=0;f<3;f++){const{start:x,end:L}=d;x.copy(Z[f]),L.copy(Z[(f+1)%3]),d.delta(r);const W=fn(G.distanceToPoint(x));if(fn(G.normal.dot(r))&&W){y.copy(d),V=2;break}const C=G.intersectLine(d,p);if(!C&&W&&p.copy(x),(C||W)&&!fn(p.distanceTo(L))){if(V<=1)(V===1?y.start:y.end).copy(p),W&&(R=V);else if(V>=2){(R===1?y.start:y.end).copy(p),V=2;break}if(V++,V===2&&R===-1)break}}return V}return function(G,y=null,Z=!1){this.needsUpdate&&this.update(),G.isExtendedTriangle?G.needsUpdate&&G.update():(s.copy(G),s.update(),G=s);const V=this.plane,R=G.plane;if(Math.abs(V.normal.dot(R.normal))>1-1e-10){const f=this.satBounds,x=this.satAxes;e[0]=G.a,e[1]=G.b,e[2]=G.c;for(let C=0;C<4;C++){const S=f[C],z=x[C];if(i.setFromPoints(z,e),S.isSeparated(i))return!1}const L=G.satBounds,W=G.satAxes;t[0]=this.a,t[1]=this.b,t[2]=this.c;for(let C=0;C<4;C++){const S=L[C],z=W[C];if(i.setFromPoints(z,t),S.isSeparated(i))return!1}for(let C=0;C<4;C++){const S=x[C];for(let z=0;z<4;z++){const g=W[z];if(o.crossVectors(S,g),i.setFromPoints(o,t),n.setFromPoints(o,e),i.isSeparated(n))return!1}}return y&&(Z||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),y.start.set(0,0,0),y.end.set(0,0,0)),!0}else{const f=m(this,R,h);if(f===1&&G.containsPoint(h.end))return y&&(y.start.copy(h.end),y.end.copy(h.end)),!0;if(f!==2)return!1;const x=m(G,V,u);if(x===1&&this.containsPoint(u.end))return y&&(y.start.copy(u.end),y.end.copy(u.end)),!0;if(x!==2)return!1;if(h.delta(l),u.delta(c),l.dot(c)<0){let v=u.start;u.start=u.end,u.end=v}const L=h.start.dot(l),W=h.end.dot(l),C=u.start.dot(l),S=u.end.dot(l),z=W<C,g=L<S;return L!==S&&C!==W&&z===g?!1:(y&&(a.subVectors(h.start,u.start),a.dot(l)>0?y.start.copy(h.start):y.start.copy(u.start),a.subVectors(h.end,u.end),a.dot(l)<0?y.end.copy(h.end):y.end.copy(u.end)),!0)}}}();Kt.prototype.distanceToPoint=function(){const s=new X.Vector3;return function(e){return this.closestPointToPoint(e,s),e.distanceTo(s)}}();Kt.prototype.distanceToTriangle=function(){const s=new X.Vector3,t=new X.Vector3,e=["a","b","c"],i=new X.Line3,n=new X.Line3;return function(r,l=null,c=null){const a=l||c?i:null;if(this.intersectsTriangle(r,a))return(l||c)&&(l&&a.getCenter(l),c&&a.getCenter(c)),0;let d=1/0;for(let h=0;h<3;h++){let u;const p=e[h],m=r[p];this.closestPointToPoint(m,s),u=m.distanceToSquared(s),u<d&&(d=u,l&&l.copy(s),c&&c.copy(m));const b=this[p];r.closestPointToPoint(b,s),u=b.distanceToSquared(s),u<d&&(d=u,l&&l.copy(b),c&&c.copy(s))}for(let h=0;h<3;h++){const u=e[h],p=e[(h+1)%3];i.set(this[u],this[p]);for(let m=0;m<3;m++){const b=e[m],G=e[(m+1)%3];n.set(r[b],r[G]),uo(i,n,s,t);const y=s.distanceToSquared(t);y<d&&(d=y,l&&l.copy(s),c&&c.copy(t))}}return Math.sqrt(d)}}();class Gt{constructor(t,e,i){this.isOrientedBox=!0,this.min=new X.Vector3,this.max=new X.Vector3,this.matrix=new X.Matrix4,this.invMatrix=new X.Matrix4,this.points=new Array(8).fill().map(()=>new X.Vector3),this.satAxes=new Array(3).fill().map(()=>new X.Vector3),this.satBounds=new Array(3).fill().map(()=>new ne),this.alignedSatBounds=new Array(3).fill().map(()=>new ne),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Gt.prototype.update=function(){return function(){const t=this.matrix,e=this.min,i=this.max,n=this.points;for(let a=0;a<=1;a++)for(let d=0;d<=1;d++)for(let h=0;h<=1;h++){const u=1*a|2*d|4*h,p=n[u];p.x=a?i.x:e.x,p.y=d?i.y:e.y,p.z=h?i.z:e.z,p.applyMatrix4(t)}const o=this.satBounds,r=this.satAxes,l=n[0];for(let a=0;a<3;a++){const d=r[a],h=o[a],u=1<<a,p=n[u];d.subVectors(l,p),h.setFromPoints(d,n)}const c=this.alignedSatBounds;c[0].setFromPointsField(n,"x"),c[1].setFromPointsField(n,"y"),c[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}();Gt.prototype.intersectsBox=function(){const s=new ne;return function(e){this.needsUpdate&&this.update();const i=e.min,n=e.max,o=this.satBounds,r=this.satAxes,l=this.alignedSatBounds;if(s.min=i.x,s.max=n.x,l[0].isSeparated(s)||(s.min=i.y,s.max=n.y,l[1].isSeparated(s))||(s.min=i.z,s.max=n.z,l[2].isSeparated(s)))return!1;for(let c=0;c<3;c++){const a=r[c],d=o[c];if(s.setFromBox(a,e),d.isSeparated(s))return!1}return!0}}();Gt.prototype.intersectsTriangle=function(){const s=new Kt,t=new Array(3),e=new ne,i=new ne,n=new X.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(s.copy(r),s.update(),r=s);const l=this.satBounds,c=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let u=0;u<3;u++){const p=l[u],m=c[u];if(e.setFromPoints(m,t),p.isSeparated(e))return!1}const a=r.satBounds,d=r.satAxes,h=this.points;for(let u=0;u<3;u++){const p=a[u],m=d[u];if(e.setFromPoints(m,h),p.isSeparated(e))return!1}for(let u=0;u<3;u++){const p=c[u];for(let m=0;m<4;m++){const b=d[m];if(n.crossVectors(p,b),e.setFromPoints(n,t),i.setFromPoints(n,h),e.isSeparated(i))return!1}}return!0}}();Gt.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}();Gt.prototype.distanceToPoint=function(){const s=new X.Vector3;return function(e){return this.closestPointToPoint(e,s),e.distanceTo(s)}}();Gt.prototype.distanceToBox=function(){const s=["x","y","z"],t=new Array(12).fill().map(()=>new X.Line3),e=new Array(12).fill().map(()=>new X.Line3),i=new X.Vector3,n=new X.Vector3;return function(r,l=0,c=null,a=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(c||a)&&(r.getCenter(n),this.closestPointToPoint(n,i),r.closestPointToPoint(i,n),c&&c.copy(i),a&&a.copy(n)),0;const d=l*l,h=r.min,u=r.max,p=this.points;let m=1/0;for(let G=0;G<8;G++){const y=p[G];n.copy(y).clamp(h,u);const Z=y.distanceToSquared(n);if(Z<m&&(m=Z,c&&c.copy(y),a&&a.copy(n),Z<d))return Math.sqrt(Z)}let b=0;for(let G=0;G<3;G++)for(let y=0;y<=1;y++)for(let Z=0;Z<=1;Z++){const V=(G+1)%3,R=(G+2)%3,f=y<<V|Z<<R,x=1<<G|y<<V|Z<<R,L=p[f],W=p[x];t[b].set(L,W);const S=s[G],z=s[V],g=s[R],v=e[b],K=v.start,Y=v.end;K[S]=h[S],K[z]=y?h[z]:u[z],K[g]=Z?h[g]:u[z],Y[S]=u[S],Y[z]=y?h[z]:u[z],Y[g]=Z?h[g]:u[z],b++}for(let G=0;G<=1;G++)for(let y=0;y<=1;y++)for(let Z=0;Z<=1;Z++){n.x=G?u.x:h.x,n.y=y?u.y:h.y,n.z=Z?u.z:h.z,this.closestPointToPoint(n,i);const V=n.distanceToSquared(i);if(V<m&&(m=V,c&&c.copy(i),a&&a.copy(n),V<d))return Math.sqrt(V)}for(let G=0;G<12;G++){const y=t[G];for(let Z=0;Z<12;Z++){const V=e[Z];uo(y,V,i,n);const R=i.distanceToSquared(n);if(R<m&&(m=R,c&&c.copy(i),a&&a.copy(n),R<d))return Math.sqrt(R)}}return Math.sqrt(m)}}();class po{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Kd extends po{constructor(){super(()=>new Kt)}}const vt=new Kd;class Td{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const E=new Td;let ue,Oe;const Je=[],Vs=new po(()=>new X.Box3);function Md(s,t,e,i,n,o){ue=Vs.getPrimitive(),Oe=Vs.getPrimitive(),Je.push(ue,Oe),E.setBuffer(s._roots[t]);const r=jn(0,s.geometry,e,i,n,o);E.clearBuffer(),Vs.releasePrimitive(ue),Vs.releasePrimitive(Oe),Je.pop(),Je.pop();const l=Je.length;return l>0&&(Oe=Je[l-1],ue=Je[l-2]),r}function jn(s,t,e,i,n=null,o=0,r=0){const{float32Array:l,uint16Array:c,uint32Array:a}=E;let d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);return B(s,l,ue),i(u,p,!1,r,o+s,ue)}else{let S=function(g){const{uint16Array:v,uint32Array:K}=E;let Y=g*2;for(;!Zt(Y,v);)g=zt(g),Y=g*2;return xt(g,K)},z=function(g){const{uint16Array:v,uint32Array:K}=E;let Y=g*2;for(;!Zt(Y,v);)g=Ct(g,K),Y=g*2;return xt(g,K)+gt(Y,v)};const u=zt(s),p=Ct(s,a);let m=u,b=p,G,y,Z,V;if(n&&(Z=ue,V=Oe,B(m,l,Z),B(b,l,V),G=n(Z),y=n(V),y<G)){m=p,b=u;const g=G;G=y,y=g,Z=V}Z||(Z=ue,B(m,l,Z));const R=Zt(m*2,c),f=e(Z,R,G,r+1,o+m);let x;if(f===Qn){const g=S(m),K=z(m)-g;x=i(g,K,!0,r+1,o+m,Z)}else x=f&&jn(m,t,e,i,n,o,r+1);if(x)return!0;V=Oe,B(b,l,V);const L=Zt(b*2,c),W=e(V,L,y,r+1,o+b);let C;if(W===Qn){const g=S(b),K=z(b)-g;C=i(g,K,!0,r+1,o+b,V)}else C=W&&jn(b,t,e,i,n,o,r+1);return!!C}}const ai=new X.Vector3,Vn=new X.Vector3;function Yd(s,t,e={},i=0,n=1/0){const o=i*i,r=n*n;let l=1/0,c=null;if(s.shapecast({boundsTraverseOrder:d=>(ai.copy(t).clamp(d.min,d.max),ai.distanceToSquared(t)),intersectsBounds:(d,h,u)=>u<l&&u<r,intersectsTriangle:(d,h)=>{d.closestPointToPoint(t,ai);const u=t.distanceToSquared(ai);return u<l&&(Vn.copy(ai),l=u,c=h),u<o}}),l===1/0)return null;const a=Math.sqrt(l);return e.point?e.point.copy(Vn):e.point=Vn.clone(),e.distance=a,e.faceIndex=c,e}const kd=parseInt(X.REVISION)>=169,ge=new X.Vector3,Ce=new X.Vector3,ze=new X.Vector3,Rs=new X.Vector2,xs=new X.Vector2,Ls=new X.Vector2,Ao=new X.Vector3,qo=new X.Vector3,$o=new X.Vector3,di=new X.Vector3;function Hd(s,t,e,i,n,o,r,l){let c;if(o===X.BackSide?c=s.intersectTriangle(i,e,t,!0,n):c=s.intersectTriangle(t,e,i,o!==X.DoubleSide,n),c===null)return null;const a=s.origin.distanceTo(n);return a<r||a>l?null:{distance:a,point:n.clone()}}function Nd(s,t,e,i,n,o,r,l,c,a,d){ge.fromBufferAttribute(t,o),Ce.fromBufferAttribute(t,r),ze.fromBufferAttribute(t,l);const h=Hd(s,ge,Ce,ze,di,c,a,d);if(h){const u=new X.Vector3;X.Triangle.getBarycoord(di,ge,Ce,ze,u),i&&(Rs.fromBufferAttribute(i,o),xs.fromBufferAttribute(i,r),Ls.fromBufferAttribute(i,l),h.uv=X.Triangle.getInterpolation(di,ge,Ce,ze,Rs,xs,Ls,new X.Vector2)),n&&(Rs.fromBufferAttribute(n,o),xs.fromBufferAttribute(n,r),Ls.fromBufferAttribute(n,l),h.uv1=X.Triangle.getInterpolation(di,ge,Ce,ze,Rs,xs,Ls,new X.Vector2)),e&&(Ao.fromBufferAttribute(e,o),qo.fromBufferAttribute(e,r),$o.fromBufferAttribute(e,l),h.normal=X.Triangle.getInterpolation(di,ge,Ce,ze,Ao,qo,$o,new X.Vector3),h.normal.dot(s.direction)>0&&h.normal.multiplyScalar(-1));const p={a:o,b:r,c:l,normal:new X.Vector3,materialIndex:0};X.Triangle.getNormal(ge,Ce,ze,p.normal),h.face=p,h.faceIndex=o,kd&&(h.barycoord=u)}return h}function sn(s,t,e,i,n,o,r){const l=i*3;let c=l+0,a=l+1,d=l+2;const h=s.index;s.index&&(c=h.getX(c),a=h.getX(a),d=h.getX(d));const{position:u,normal:p,uv:m,uv1:b}=s.attributes,G=Nd(e,u,p,m,b,c,a,d,t,o,r);return G?(G.faceIndex=i,n&&n.push(G),G):null}function $(s,t,e,i){const n=s.a,o=s.b,r=s.c;let l=t,c=t+1,a=t+2;e&&(l=e.getX(l),c=e.getX(c),a=e.getX(a)),n.x=i.getX(l),n.y=i.getY(l),n.z=i.getZ(l),o.x=i.getX(c),o.y=i.getY(c),o.z=i.getZ(c),r.x=i.getX(a),r.y=i.getY(a),r.z=i.getZ(a)}const hi=new X.Vector3,ui=new X.Vector3,pi=new X.Vector3,tr=new X.Vector2,er=new X.Vector2,ir=new X.Vector2;function Id(s,t,e,i){const n=t.getIndex().array,o=t.getAttribute("position"),r=t.getAttribute("uv"),l=n[e*3],c=n[e*3+1],a=n[e*3+2];hi.fromBufferAttribute(o,l),ui.fromBufferAttribute(o,c),pi.fromBufferAttribute(o,a);let d=0;const h=t.groups,u=e*3;for(let b=0,G=h.length;b<G;b++){const y=h[b],{start:Z,count:V}=y;if(u>=Z&&u<Z+V){d=y.materialIndex;break}}const p=i&&i.barycoord?i.barycoord:new X.Vector3;X.Triangle.getBarycoord(s,hi,ui,pi,p);let m=null;return r&&(tr.fromBufferAttribute(r,l),er.fromBufferAttribute(r,c),ir.fromBufferAttribute(r,a),i&&i.uv?m=i.uv:m=new X.Vector2,X.Triangle.getInterpolation(s,hi,ui,pi,tr,er,ir,m)),i?(i.face||(i.face={}),i.face.a=l,i.face.b=c,i.face.c=a,i.face.materialIndex=d,i.face.normal||(i.face.normal=new X.Vector3),X.Triangle.getNormal(hi,ui,pi,i.face.normal),m&&(i.uv=m),i.barycoord=p,i):{face:{a:l,b:c,c:a,materialIndex:d,normal:X.Triangle.getNormal(hi,ui,pi,new X.Vector3)},uv:m,barycoord:p}}function Jd(s,t,e,i,n,o,r,l){const{geometry:c,_indirectBuffer:a}=s;for(let d=i,h=i+n;d<h;d++)sn(c,t,e,d,o,r,l)}function Ud(s,t,e,i,n,o,r){const{geometry:l,_indirectBuffer:c}=s;let a=1/0,d=null;for(let h=i,u=i+n;h<u;h++){let p;p=sn(l,t,e,h,null,o,r),p&&p.distance<a&&(d=p,a=p.distance)}return d}function Pd(s,t,e,i,n,o,r){const{geometry:l}=e,{index:c}=l,a=l.attributes.position;for(let d=s,h=t+s;d<h;d++){let u;if(u=d,$(r,u*3,c,a),r.needsUpdate=!0,i(r,u,n,o))return!0}return!1}function Fd(s,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=s.geometry,i=e.index?e.index.array:null,n=e.attributes.position;let o,r,l,c,a=0;const d=s._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],r=new Uint32Array(o),l=new Uint16Array(o),c=new Float32Array(o),h(0,a),a+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(l[b+15]===en){const y=r[u+6],Z=l[b+14];let V=1/0,R=1/0,f=1/0,x=-1/0,L=-1/0,W=-1/0;for(let C=3*y,S=3*(y+Z);C<S;C++){let z=i[C];const g=n.getX(z),v=n.getY(z),K=n.getZ(z);g<V&&(V=g),g>x&&(x=g),v<R&&(R=v),v>L&&(L=v),K<f&&(f=K),K>W&&(W=K)}return c[u+0]!==V||c[u+1]!==R||c[u+2]!==f||c[u+3]!==x||c[u+4]!==L||c[u+5]!==W?(c[u+0]=V,c[u+1]=R,c[u+2]=f,c[u+3]=x,c[u+4]=L,c[u+5]=W,!0):!1}else{const y=u+8,Z=r[u+6],V=y+p,R=Z+p;let f=m,x=!1,L=!1;t?f||(x=t.has(V),L=t.has(R),f=!x&&!L):(x=!0,L=!0);const W=f||x,C=f||L;let S=!1;W&&(S=h(y,p,f));let z=!1;C&&(z=h(Z,p,f));const g=S||z;if(g)for(let v=0;v<3;v++){const K=y+v,Y=Z+v,H=c[K],I=c[K+3],P=c[Y],D=c[Y+3];c[u+v]=H<P?H:P,c[u+v+3]=I>D?I:D}return g}}}function me(s,t,e,i,n){let o,r,l,c,a,d;const h=1/e.direction.x,u=1/e.direction.y,p=1/e.direction.z,m=e.origin.x,b=e.origin.y,G=e.origin.z;let y=t[s],Z=t[s+3],V=t[s+1],R=t[s+3+1],f=t[s+2],x=t[s+3+2];return h>=0?(o=(y-m)*h,r=(Z-m)*h):(o=(Z-m)*h,r=(y-m)*h),u>=0?(l=(V-b)*u,c=(R-b)*u):(l=(R-b)*u,c=(V-b)*u),o>c||l>r||((l>o||isNaN(o))&&(o=l),(c<r||isNaN(r))&&(r=c),p>=0?(a=(f-G)*p,d=(x-G)*p):(a=(x-G)*p,d=(f-G)*p),o>d||a>r)?!1:((a>o||o!==o)&&(o=a),(d<r||r!==r)&&(r=d),o<=n&&r>=i)}function Qd(s,t,e,i,n,o,r,l){const{geometry:c,_indirectBuffer:a}=s;for(let d=i,h=i+n;d<h;d++){let u=a?a[d]:d;sn(c,t,e,u,o,r,l)}}function wd(s,t,e,i,n,o,r){const{geometry:l,_indirectBuffer:c}=s;let a=1/0,d=null;for(let h=i,u=i+n;h<u;h++){let p;p=sn(l,t,e,c?c[h]:h,null,o,r),p&&p.distance<a&&(d=p,a=p.distance)}return d}function Bd(s,t,e,i,n,o,r){const{geometry:l}=e,{index:c}=l,a=l.attributes.position;for(let d=s,h=t+s;d<h;d++){let u;if(u=e.resolveTriangleIndex(d),$(r,u*3,c,a),r.needsUpdate=!0,i(r,u,n,o))return!0}return!1}function Ed(s,t,e,i,n,o,r){E.setBuffer(s._roots[t]),On(0,s,e,i,n,o,r),E.clearBuffer()}function On(s,t,e,i,n,o,r){const{float32Array:l,uint16Array:c,uint32Array:a}=E,d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);Jd(t,e,i,u,p,n,o,r)}else{const u=zt(s);me(u,l,i,o,r)&&On(u,t,e,i,n,o,r);const p=Ct(s,a);me(p,l,i,o,r)&&On(p,t,e,i,n,o,r)}}const jd=["x","y","z"];function Od(s,t,e,i,n,o){E.setBuffer(s._roots[t]);const r=Dn(0,s,e,i,n,o);return E.clearBuffer(),r}function Dn(s,t,e,i,n,o){const{float32Array:r,uint16Array:l,uint32Array:c}=E;let a=s*2;if(Zt(a,l)){const h=xt(s,c),u=gt(a,l);return Ud(t,e,i,h,u,n,o)}else{const h=ho(s,c),u=jd[h],m=i.direction[u]>=0;let b,G;m?(b=zt(s),G=Ct(s,c)):(b=Ct(s,c),G=zt(s));const Z=me(b,r,i,n,o)?Dn(b,t,e,i,n,o):null;if(Z){const f=Z.point[u];if(m?f<=r[G+h]:f>=r[G+h+3])return Z}const R=me(G,r,i,n,o)?Dn(G,t,e,i,n,o):null;return Z&&R?Z.distance<=R.distance?Z:R:Z||R||null}}const Ss=new X.Box3,Ue=new Kt,Pe=new Kt,mi=new X.Matrix4,sr=new Gt,Ws=new Gt;function Dd(s,t,e,i){E.setBuffer(s._roots[t]);const n=_n(0,s,e,i);return E.clearBuffer(),n}function _n(s,t,e,i,n=null){const{float32Array:o,uint16Array:r,uint32Array:l}=E;let c=s*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),sr.set(e.boundingBox.min,e.boundingBox.max,i),n=sr),Zt(c,r)){const d=t.geometry,h=d.index,u=d.attributes.position,p=e.index,m=e.attributes.position,b=xt(s,l),G=gt(c,r);if(mi.copy(i).invert(),e.boundsTree)return B(s,o,Ws),Ws.matrix.copy(mi),Ws.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:Z=>Ws.intersectsBox(Z),intersectsTriangle:Z=>{Z.a.applyMatrix4(i),Z.b.applyMatrix4(i),Z.c.applyMatrix4(i),Z.needsUpdate=!0;for(let V=b*3,R=(G+b)*3;V<R;V+=3)if($(Pe,V,h,u),Pe.needsUpdate=!0,Z.intersectsTriangle(Pe))return!0;return!1}});for(let y=b*3,Z=(G+b)*3;y<Z;y+=3){$(Ue,y,h,u),Ue.a.applyMatrix4(mi),Ue.b.applyMatrix4(mi),Ue.c.applyMatrix4(mi),Ue.needsUpdate=!0;for(let V=0,R=p.count;V<R;V+=3)if($(Pe,V,p,m),Pe.needsUpdate=!0,Ue.intersectsTriangle(Pe))return!0}}else{const d=s+8,h=l[s+6];return B(d,o,Ss),!!(n.intersectsBox(Ss)&&_n(d,t,e,i,n)||(B(h,o,Ss),n.intersectsBox(Ss)&&_n(h,t,e,i,n)))}}const gs=new X.Matrix4,Rn=new Gt,bi=new Gt,_d=new X.Vector3,Ad=new X.Vector3,qd=new X.Vector3,$d=new X.Vector3;function th(s,t,e,i={},n={},o=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Rn.set(t.boundingBox.min,t.boundingBox.max,e),Rn.needsUpdate=!0;const l=s.geometry,c=l.attributes.position,a=l.index,d=t.attributes.position,h=t.index,u=vt.getPrimitive(),p=vt.getPrimitive();let m=_d,b=Ad,G=null,y=null;n&&(G=qd,y=$d);let Z=1/0,V=null,R=null;return gs.copy(e).invert(),bi.matrix.copy(gs),s.shapecast({boundsTraverseOrder:f=>Rn.distanceToBox(f),intersectsBounds:(f,x,L)=>L<Z&&L<r?(x&&(bi.min.copy(f.min),bi.max.copy(f.max),bi.needsUpdate=!0),!0):!1,intersectsRange:(f,x)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:W=>bi.distanceToBox(W),intersectsBounds:(W,C,S)=>S<Z&&S<r,intersectsRange:(W,C)=>{for(let S=W,z=W+C;S<z;S++){$(p,3*S,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let g=f,v=f+x;g<v;g++){$(u,3*g,a,c),u.needsUpdate=!0;const K=u.distanceToTriangle(p,m,G);if(K<Z&&(b.copy(m),y&&y.copy(G),Z=K,V=g,R=S),K<o)return!0}}}});{const L=ti(t);for(let W=0,C=L;W<C;W++){$(p,3*W,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let S=f,z=f+x;S<z;S++){$(u,3*S,a,c),u.needsUpdate=!0;const g=u.distanceToTriangle(p,m,G);if(g<Z&&(b.copy(m),y&&y.copy(G),Z=g,V=S,R=W),g<o)return!0}}}}}),vt.releasePrimitive(u),vt.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=V,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(gs),b.applyMatrix4(gs),n.distance=b.sub(n.point).length(),n.faceIndex=R),i)}function eh(s,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=s.geometry,i=e.index?e.index.array:null,n=e.attributes.position;let o,r,l,c,a=0;const d=s._roots;for(let u=0,p=d.length;u<p;u++)o=d[u],r=new Uint32Array(o),l=new Uint16Array(o),c=new Float32Array(o),h(0,a),a+=o.byteLength;function h(u,p,m=!1){const b=u*2;if(l[b+15]===en){const y=r[u+6],Z=l[b+14];let V=1/0,R=1/0,f=1/0,x=-1/0,L=-1/0,W=-1/0;for(let C=y,S=y+Z;C<S;C++){const z=3*s.resolveTriangleIndex(C);for(let g=0;g<3;g++){let v=z+g;v=i?i[v]:v;const K=n.getX(v),Y=n.getY(v),H=n.getZ(v);K<V&&(V=K),K>x&&(x=K),Y<R&&(R=Y),Y>L&&(L=Y),H<f&&(f=H),H>W&&(W=H)}}return c[u+0]!==V||c[u+1]!==R||c[u+2]!==f||c[u+3]!==x||c[u+4]!==L||c[u+5]!==W?(c[u+0]=V,c[u+1]=R,c[u+2]=f,c[u+3]=x,c[u+4]=L,c[u+5]=W,!0):!1}else{const y=u+8,Z=r[u+6],V=y+p,R=Z+p;let f=m,x=!1,L=!1;t?f||(x=t.has(V),L=t.has(R),f=!x&&!L):(x=!0,L=!0);const W=f||x,C=f||L;let S=!1;W&&(S=h(y,p,f));let z=!1;C&&(z=h(Z,p,f));const g=S||z;if(g)for(let v=0;v<3;v++){const K=y+v,Y=Z+v,H=c[K],I=c[K+3],P=c[Y],D=c[Y+3];c[u+v]=H<P?H:P,c[u+v+3]=I>D?I:D}return g}}}function ih(s,t,e,i,n,o,r){E.setBuffer(s._roots[t]),An(0,s,e,i,n,o,r),E.clearBuffer()}function An(s,t,e,i,n,o,r){const{float32Array:l,uint16Array:c,uint32Array:a}=E,d=s*2;if(Zt(d,c)){const u=xt(s,a),p=gt(d,c);Qd(t,e,i,u,p,n,o,r)}else{const u=zt(s);me(u,l,i,o,r)&&An(u,t,e,i,n,o,r);const p=Ct(s,a);me(p,l,i,o,r)&&An(p,t,e,i,n,o,r)}}const sh=["x","y","z"];function nh(s,t,e,i,n,o){E.setBuffer(s._roots[t]);const r=qn(0,s,e,i,n,o);return E.clearBuffer(),r}function qn(s,t,e,i,n,o){const{float32Array:r,uint16Array:l,uint32Array:c}=E;let a=s*2;if(Zt(a,l)){const h=xt(s,c),u=gt(a,l);return wd(t,e,i,h,u,n,o)}else{const h=ho(s,c),u=sh[h],m=i.direction[u]>=0;let b,G;m?(b=zt(s),G=Ct(s,c)):(b=Ct(s,c),G=zt(s));const Z=me(b,r,i,n,o)?qn(b,t,e,i,n,o):null;if(Z){const f=Z.point[u];if(m?f<=r[G+h]:f>=r[G+h+3])return Z}const R=me(G,r,i,n,o)?qn(G,t,e,i,n,o):null;return Z&&R?Z.distance<=R.distance?Z:R:Z||R||null}}const Cs=new X.Box3,Fe=new Kt,Qe=new Kt,yi=new X.Matrix4,nr=new Gt,zs=new Gt;function oh(s,t,e,i){E.setBuffer(s._roots[t]);const n=$n(0,s,e,i);return E.clearBuffer(),n}function $n(s,t,e,i,n=null){const{float32Array:o,uint16Array:r,uint32Array:l}=E;let c=s*2;if(n===null&&(e.boundingBox||e.computeBoundingBox(),nr.set(e.boundingBox.min,e.boundingBox.max,i),n=nr),Zt(c,r)){const d=t.geometry,h=d.index,u=d.attributes.position,p=e.index,m=e.attributes.position,b=xt(s,l),G=gt(c,r);if(yi.copy(i).invert(),e.boundsTree)return B(s,o,zs),zs.matrix.copy(yi),zs.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:Z=>zs.intersectsBox(Z),intersectsTriangle:Z=>{Z.a.applyMatrix4(i),Z.b.applyMatrix4(i),Z.c.applyMatrix4(i),Z.needsUpdate=!0;for(let V=b,R=G+b;V<R;V++)if($(Qe,3*t.resolveTriangleIndex(V),h,u),Qe.needsUpdate=!0,Z.intersectsTriangle(Qe))return!0;return!1}});for(let y=b,Z=G+b;y<Z;y++){const V=t.resolveTriangleIndex(y);$(Fe,3*V,h,u),Fe.a.applyMatrix4(yi),Fe.b.applyMatrix4(yi),Fe.c.applyMatrix4(yi),Fe.needsUpdate=!0;for(let R=0,f=p.count;R<f;R+=3)if($(Qe,R,p,m),Qe.needsUpdate=!0,Fe.intersectsTriangle(Qe))return!0}}else{const d=s+8,h=l[s+6];return B(d,o,Cs),!!(n.intersectsBox(Cs)&&$n(d,t,e,i,n)||(B(h,o,Cs),n.intersectsBox(Cs)&&$n(h,t,e,i,n)))}}const vs=new X.Matrix4,xn=new Gt,Gi=new Gt,rh=new X.Vector3,ch=new X.Vector3,lh=new X.Vector3,ah=new X.Vector3;function dh(s,t,e,i={},n={},o=0,r=1/0){t.boundingBox||t.computeBoundingBox(),xn.set(t.boundingBox.min,t.boundingBox.max,e),xn.needsUpdate=!0;const l=s.geometry,c=l.attributes.position,a=l.index,d=t.attributes.position,h=t.index,u=vt.getPrimitive(),p=vt.getPrimitive();let m=rh,b=ch,G=null,y=null;n&&(G=lh,y=ah);let Z=1/0,V=null,R=null;return vs.copy(e).invert(),Gi.matrix.copy(vs),s.shapecast({boundsTraverseOrder:f=>xn.distanceToBox(f),intersectsBounds:(f,x,L)=>L<Z&&L<r?(x&&(Gi.min.copy(f.min),Gi.max.copy(f.max),Gi.needsUpdate=!0),!0):!1,intersectsRange:(f,x)=>{if(t.boundsTree){const L=t.boundsTree;return L.shapecast({boundsTraverseOrder:W=>Gi.distanceToBox(W),intersectsBounds:(W,C,S)=>S<Z&&S<r,intersectsRange:(W,C)=>{for(let S=W,z=W+C;S<z;S++){const g=L.resolveTriangleIndex(S);$(p,3*g,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let v=f,K=f+x;v<K;v++){const Y=s.resolveTriangleIndex(v);$(u,3*Y,a,c),u.needsUpdate=!0;const H=u.distanceToTriangle(p,m,G);if(H<Z&&(b.copy(m),y&&y.copy(G),Z=H,V=v,R=S),H<o)return!0}}}})}else{const L=ti(t);for(let W=0,C=L;W<C;W++){$(p,3*W,h,d),p.a.applyMatrix4(e),p.b.applyMatrix4(e),p.c.applyMatrix4(e),p.needsUpdate=!0;for(let S=f,z=f+x;S<z;S++){const g=s.resolveTriangleIndex(S);$(u,3*g,a,c),u.needsUpdate=!0;const v=u.distanceToTriangle(p,m,G);if(v<Z&&(b.copy(m),y&&y.copy(G),Z=v,V=S,R=W),v<o)return!0}}}}}),vt.releasePrimitive(u),vt.releasePrimitive(p),Z===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=Z,i.faceIndex=V,n&&(n.point?n.point.copy(y):n.point=y.clone(),n.point.applyMatrix4(vs),b.applyMatrix4(vs),n.distance=b.sub(n.point).length(),n.faceIndex=R),i)}function Mc(){return typeof SharedArrayBuffer<"u"}const Wi=new E.constructor,_s=new E.constructor,de=new po(()=>new X.Box3),we=new X.Box3,Be=new X.Box3,Ln=new X.Box3,Sn=new X.Box3;let Wn=!1;function hh(s,t,e,i){if(Wn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Wn=!0;const n=s._roots,o=t._roots;let r,l=0,c=0;const a=new X.Matrix4().copy(e).invert();for(let d=0,h=n.length;d<h;d++){Wi.setBuffer(n[d]),c=0;const u=de.getPrimitive();B(0,Wi.float32Array,u),u.applyMatrix4(a);for(let p=0,m=o.length;p<m&&(_s.setBuffer(o[p]),r=Nt(0,0,e,a,i,l,c,0,0,u),_s.clearBuffer(),c+=o[p].length,!r);p++);if(de.releasePrimitive(u),Wi.clearBuffer(),l+=n[d].length,r)break}return Wn=!1,r}function Nt(s,t,e,i,n,o=0,r=0,l=0,c=0,a=null,d=!1){let h,u;d?(h=_s,u=Wi):(h=Wi,u=_s);const p=h.float32Array,m=h.uint32Array,b=h.uint16Array,G=u.float32Array,y=u.uint32Array,Z=u.uint16Array,V=s*2,R=t*2,f=Zt(V,b),x=Zt(R,Z);let L=!1;if(x&&f)d?L=n(xt(t,y),gt(t*2,Z),xt(s,m),gt(s*2,b),c,r+t,l,o+s):L=n(xt(s,m),gt(s*2,b),xt(t,y),gt(t*2,Z),l,o+s,c,r+t);else if(x){const W=de.getPrimitive();B(t,G,W),W.applyMatrix4(e);const C=zt(s),S=Ct(s,m);B(C,p,we),B(S,p,Be);const z=W.intersectsBox(we),g=W.intersectsBox(Be);L=z&&Nt(t,C,i,e,n,r,o,c,l+1,W,!d)||g&&Nt(t,S,i,e,n,r,o,c,l+1,W,!d),de.releasePrimitive(W)}else{const W=zt(t),C=Ct(t,y);B(W,G,Ln),B(C,G,Sn);const S=a.intersectsBox(Ln),z=a.intersectsBox(Sn);if(S&&z)L=Nt(s,W,e,i,n,o,r,l,c+1,a,d)||Nt(s,C,e,i,n,o,r,l,c+1,a,d);else if(S)if(f)L=Nt(s,W,e,i,n,o,r,l,c+1,a,d);else{const g=de.getPrimitive();g.copy(Ln).applyMatrix4(e);const v=zt(s),K=Ct(s,m);B(v,p,we),B(K,p,Be);const Y=g.intersectsBox(we),H=g.intersectsBox(Be);L=Y&&Nt(W,v,i,e,n,r,o,c,l+1,g,!d)||H&&Nt(W,K,i,e,n,r,o,c,l+1,g,!d),de.releasePrimitive(g)}else if(z)if(f)L=Nt(s,C,e,i,n,o,r,l,c+1,a,d);else{const g=de.getPrimitive();g.copy(Sn).applyMatrix4(e);const v=zt(s),K=Ct(s,m);B(v,p,we),B(K,p,Be);const Y=g.intersectsBox(we),H=g.intersectsBox(Be);L=Y&&Nt(C,v,i,e,n,r,o,c,l+1,g,!d)||H&&Nt(C,K,i,e,n,r,o,c,l+1,g,!d),de.releasePrimitive(g)}}return L}const Ks=new Gt,or=new X.Box3,uh={strategy:ao,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class be{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,n=t._roots,o=t._indirectBuffer,r=i.getIndex();let l;return e.cloneBuffers?l={roots:n.map(c=>c.slice()),index:r?r.array.slice():null,indirectBuffer:o?o.slice():null}:l={roots:n,index:r?r.array:null,indirectBuffer:o},l}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:n,roots:o,indirectBuffer:r}=t,l=new be(e,{...i,[Gn]:!0});if(l._roots=o,l._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const a=new X.BufferAttribute(t.index,1,!1);e.setIndex(a)}else c.array!==n&&(c.array.set(n),c.needsUpdate=!0)}return l}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(e=Object.assign({...uh,[Gn]:!1},e),e.useSharedArrayBuffer&&!Mc())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Gn]||(gd(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new X.Box3))),this.resolveTriangleIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i}refit(t=null){return(this.indirect?eh:Fd)(this,t)}traverse(t,e=0){const i=this._roots[e],n=new Uint32Array(i),o=new Uint16Array(i);r(0);function r(l,c=0){const a=l*2,d=o[a+15]===en;if(d){const h=n[l+6],u=o[a+14];t(c,d,new Float32Array(i,l*4,6),h,u)}else{const h=l+pe/4,u=n[l+6],p=n[l+7];t(c,d,new Float32Array(i,l*4,6),p)||(r(h,c+1),r(u,c+1))}}}raycast(t,e=X.FrontSide,i=0,n=1/0){const o=this._roots,r=this.geometry,l=[],c=e.isMaterial,a=Array.isArray(e),d=r.groups,h=c?e.side:e,u=this.indirect?ih:Ed;for(let p=0,m=o.length;p<m;p++){const b=a?e[d[p].materialIndex].side:h,G=l.length;if(u(this,p,b,t,l,i,n),a){const y=d[p].materialIndex;for(let Z=G,V=l.length;Z<V;Z++)l[Z].face.materialIndex=y}}return l}raycastFirst(t,e=X.FrontSide,i=0,n=1/0){const o=this._roots,r=this.geometry,l=e.isMaterial,c=Array.isArray(e);let a=null;const d=r.groups,h=l?e.side:e,u=this.indirect?nh:Od;for(let p=0,m=o.length;p<m;p++){const b=c?e[d[p].materialIndex].side:h,G=u(this,p,b,t,i,n);G!=null&&(a==null||G.distance<a.distance)&&(a=G,c&&(G.face.materialIndex=d[p].materialIndex))}return a}intersectsGeometry(t,e){let i=!1;const n=this._roots,o=this.indirect?oh:Dd;for(let r=0,l=n.length;r<l&&(i=o(this,r,t,e),!i);r++);return i}shapecast(t){const e=vt.getPrimitive(),i=this.indirect?Bd:Pd;let{boundsTraverseOrder:n,intersectsBounds:o,intersectsRange:r,intersectsTriangle:l}=t;if(r&&l){const h=r;r=(u,p,m,b,G)=>h(u,p,m,b,G)?!0:i(u,p,this,l,m,b,e)}else r||(l?r=(h,u,p,m)=>i(h,u,this,l,p,m,e):r=(h,u,p)=>p);let c=!1,a=0;const d=this._roots;for(let h=0,u=d.length;h<u;h++){const p=d[h];if(c=Md(this,h,o,r,n,a),c)break;a+=p.byteLength}return vt.releasePrimitive(e),c}bvhcast(t,e,i){let{intersectsRanges:n,intersectsTriangles:o}=i;const r=vt.getPrimitive(),l=this.geometry.index,c=this.geometry.attributes.position,a=this.indirect?m=>{const b=this.resolveTriangleIndex(m);$(r,b*3,l,c)}:m=>{$(r,m*3,l,c)},d=vt.getPrimitive(),h=t.geometry.index,u=t.geometry.attributes.position,p=t.indirect?m=>{const b=t.resolveTriangleIndex(m);$(d,b*3,h,u)}:m=>{$(d,m*3,h,u)};if(o){const m=(b,G,y,Z,V,R,f,x)=>{for(let L=y,W=y+Z;L<W;L++){p(L),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let C=b,S=b+G;C<S;C++)if(a(C),r.needsUpdate=!0,o(r,d,C,L,V,R,f,x))return!0}return!1};if(n){const b=n;n=function(G,y,Z,V,R,f,x,L){return b(G,y,Z,V,R,f,x,L)?!0:m(G,y,Z,V,R,f,x,L)}}else n=m}return hh(this,t,e,n)}intersectsBox(t,e){return Ks.set(t.min,t.max,e),Ks.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Ks.intersectsBox(i),intersectsTriangle:i=>Ks.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},n={},o=0,r=1/0){return(this.indirect?dh:th)(this,t,e,i,n,o,r)}closestPointToPoint(t,e={},i=0,n=1/0){return Yd(this,t,e,i,n)}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{B(0,new Float32Array(i),or),t.union(or)}),t}}const rr=new X.Box3,cr=new X.Matrix4;class ph extends X.Object3D{get isMesh(){return!this.displayEdges}get isLineSegments(){return this.displayEdges}get isLine(){return this.displayEdges}getVertexPosition(...t){return X.Mesh.prototype.getVertexPosition.call(this,...t)}constructor(t,e,i=10,n=0){super(),this.material=e,this.geometry=new X.BufferGeometry,this.name="MeshBVHRootHelper",this.depth=i,this.displayParents=!1,this.bvh=t,this.displayEdges=!0,this._group=n}raycast(){}update(){const t=this.geometry,e=this.bvh,i=this._group;if(t.dispose(),this.visible=!1,e){const n=this.depth-1,o=this.displayParents;let r=0;e.traverse((u,p)=>{if(u>=n||p)return r++,!0;o&&r++},i);let l=0;const c=new Float32Array(8*3*r);e.traverse((u,p,m)=>{const b=u>=n||p;if(b||o){B(0,m,rr);const{min:G,max:y}=rr;for(let Z=-1;Z<=1;Z+=2){const V=Z<0?G.x:y.x;for(let R=-1;R<=1;R+=2){const f=R<0?G.y:y.y;for(let x=-1;x<=1;x+=2){const L=x<0?G.z:y.z;c[l+0]=V,c[l+1]=f,c[l+2]=L,l+=3}}}return b}},i);let a,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]),c.length>65535?a=new Uint32Array(d.length*r):a=new Uint16Array(d.length*r);const h=d.length;for(let u=0;u<r;u++){const p=u*8,m=u*h;for(let b=0;b<h;b++)a[m+b]=p+d[b]}t.setIndex(new X.BufferAttribute(a,1,!1)),t.setAttribute("position",new X.BufferAttribute(c,3,!1)),this.visible=!0}}}class mo extends X.Group{get color(){return this.edgeMaterial.color}get opacity(){return this.edgeMaterial.opacity}set opacity(t){this.edgeMaterial.opacity=t,this.meshMaterial.opacity=t}constructor(t=null,e=null,i=10){t instanceof be&&(i=e||10,e=t,t=null),typeof e=="number"&&(i=e,e=null),super(),this.name="MeshBVHHelper",this.depth=i,this.mesh=t,this.bvh=e,this.displayParents=!1,this.displayEdges=!0,this.objectIndex=0,this._roots=[];const n=new X.LineBasicMaterial({color:65416,transparent:!0,opacity:.3,depthWrite:!1}),o=new X.MeshBasicMaterial({color:65416,transparent:!0,opacity:.3,depthWrite:!1});o.color=n.color,this.edgeMaterial=n,this.meshMaterial=o,this.update()}update(){const t=this.mesh;let e=this.bvh||t.geometry.boundsTree||null;if(t.isBatchedMesh&&t.boundsTrees&&!e){const n=t._drawInfo[this.objectIndex];n&&(e=t.boundsTrees[n.geometryIndex]||e)}const i=e?e._roots.length:0;for(;this._roots.length>i;){const n=this._roots.pop();n.geometry.dispose(),this.remove(n)}for(let n=0;n<i;n++){const{depth:o,edgeMaterial:r,meshMaterial:l,displayParents:c,displayEdges:a}=this;if(n>=this._roots.length){const h=new ph(e,r,o,n);this.add(h),this._roots.push(h)}const d=this._roots[n];d.bvh=e,d.depth=o,d.displayParents=c,d.displayEdges=a,d.material=a?r:l,d.update()}}updateMatrixWorld(...t){const e=this.mesh,i=this.parent;e!==null&&(e.updateWorldMatrix(!0,!1),i?this.matrix.copy(i.matrixWorld).invert().multiply(e.matrixWorld):this.matrix.copy(e.matrixWorld),(e.isInstancedMesh||e.isBatchedMesh)&&(e.getMatrixAt(this.objectIndex,cr),this.matrix.multiply(cr)),this.matrix.decompose(this.position,this.quaternion,this.scale)),super.updateMatrixWorld(...t)}copy(t){this.depth=t.depth,this.mesh=t.mesh,this.bvh=t.bvh,this.opacity=t.opacity,this.color.copy(t.color)}clone(){return new mo(this.mesh,this.bvh,this.depth)}dispose(){this.edgeMaterial.dispose(),this.meshMaterial.dispose();const t=this.children;for(let e=0,i=t.length;e<i;e++)t[e].geometry.dispose()}}const Zi=new X.Box3,lr=new X.Box3,Ee=new X.Vector3;function ar(s){switch(typeof s){case"number":return 8;case"string":return s.length*2;case"boolean":return 4;default:return 0}}function mh(s){return/(Uint|Int|Float)(8|16|32)Array/.test(s.constructor.name)}function bh(s,t){const e={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 s.traverse((i,n,o,r,l)=>{const c=o[3]-o[0],a=o[1+3]-o[1],d=o[2+3]-o[2],h=2*(c*a+a*d+d*c);e.nodeCount++,n?(e.leafNodeCount++,e.depth.min=Math.min(i,e.depth.min),e.depth.max=Math.max(i,e.depth.max),e.tris.min=Math.min(l,e.tris.min),e.tris.max=Math.max(l,e.tris.max),e.surfaceAreaScore+=h*Us*l):(e.splits[r]++,e.surfaceAreaScore+=h*wn)},t),e.tris.min===1/0&&(e.tris.min=0,e.tris.max=0),e.depth.min===1/0&&(e.depth.min=0,e.depth.max=0),e}function yh(s){return s._roots.map((t,e)=>bh(s,e))}function Gh(s){const t=new Set,e=[s];let i=0;for(;e.length;){const n=e.pop();if(!t.has(n)){t.add(n);for(let o in n){if(!Object.hasOwn(n,o))continue;i+=ar(o);const r=n[o];r&&(typeof r=="object"||typeof r=="function")?mh(r)||Mc()&&r instanceof SharedArrayBuffer||r instanceof ArrayBuffer?i+=r.byteLength:e.push(r):i+=ar(r)}}}return i}function Zh(s){const t=s.geometry,e=[],i=t.index,n=t.getAttribute("position");let o=!0;return s.traverse((r,l,c,a,d)=>{const h={depth:r,isLeaf:l,boundingData:c,offset:a,count:d};e[r]=h,B(0,c,Zi);const u=e[r-1];if(l)for(let p=a,m=a+d;p<m;p++){const b=s.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 V;Ee.fromBufferAttribute(n,G),V=Zi.containsPoint(Ee),Ee.fromBufferAttribute(n,y),V=V&&Zi.containsPoint(Ee),Ee.fromBufferAttribute(n,Z),V=V&&Zi.containsPoint(Ee),console.assert(V,"Leaf bounds does not fully contain triangle."),o=o&&V}if(u){B(0,c,lr);const p=lr.containsBox(Zi);console.assert(p,"Parent bounds does not fully contain child."),o=o&&p}}),o}function Xh(s){const t=[];return s.traverse((e,i,n,o,r)=>{const l={bounds:B(0,n,new X.Box3)};i?(l.count=r,l.offset=o):(l.left=null,l.right=null),t[e]=l;const c=t[e-1];c&&(c.left===null?c.left=l:c.right=l)}),t[0]}function dr(s,t,e){return s===null?null:(s.point.applyMatrix4(t.matrixWorld),s.distance=s.point.distanceTo(e.ray.origin),s.object=t,s)}const fh=parseInt(X.REVISION)>=166,Ts=new X.Ray,hr=new X.Vector3,ur=new X.Matrix4,Vh=X.Mesh.prototype.raycast,Rh=X.BatchedMesh.prototype.raycast,pr=new X.Vector3,lt=new X.Mesh,Ms=[];function xh(s,t){this.isBatchedMesh?Lh.call(this,s,t):Sh.call(this,s,t)}function Lh(s,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,n=this._drawRanges||this._geometryInfo,o=this.matrixWorld;lt.material=this.material,lt.geometry=this.geometry;const r=lt.geometry.boundsTree,l=lt.geometry.drawRange;lt.geometry.boundingSphere===null&&(lt.geometry.boundingSphere=new X.Sphere);for(let c=0,a=i.length;c<a;c++){if(!this.getVisibleAt(c))continue;const d=i[c].geometryIndex;if(lt.geometry.boundsTree=e[d],this.getMatrixAt(c,lt.matrixWorld).premultiply(o),!lt.geometry.boundsTree){this.getBoundingBoxAt(d,lt.geometry.boundingBox),this.getBoundingSphereAt(d,lt.geometry.boundingSphere);const h=n[d];lt.geometry.setDrawRange(h.start,h.count)}lt.raycast(s,Ms);for(let h=0,u=Ms.length;h<u;h++){const p=Ms[h];p.object=this,p.batchId=c,t.push(p)}Ms.length=0}lt.geometry.boundsTree=r,lt.geometry.drawRange=l,lt.material=null,lt.geometry=null}else Rh.call(this,s,t)}function Sh(s,t){if(this.geometry.boundsTree){if(this.material===void 0)return;ur.copy(this.matrixWorld).invert(),Ts.copy(s.ray).applyMatrix4(ur),pr.setFromMatrixScale(this.matrixWorld),hr.copy(Ts.direction).multiply(pr);const e=hr.length(),i=s.near/e,n=s.far/e,o=this.geometry.boundsTree;if(s.firstHitOnly===!0){const r=dr(o.raycastFirst(Ts,this.material,i,n),this,s);r&&t.push(r)}else{const r=o.raycast(Ts,this.material,i,n);for(let l=0,c=r.length;l<c;l++){const a=dr(r[l],this,s);a&&t.push(a)}}}else Vh.call(this,s,t)}function Wh(s={}){return this.boundsTree=new be(this,s),this.boundsTree}function gh(){this.boundsTree=null}function Ch(s=-1,t={}){if(!fh)throw new Error("BatchedMesh: Three r166+ is required to compute bounds trees.");t.indirect&&console.warn('"Indirect" is set to false because it is not supported for BatchedMesh.'),t={...t,indirect:!1,range:null};const e=this._drawRanges||this._geometryInfo,i=this._geometryCount;this.boundsTrees||(this.boundsTrees=new Array(i).fill(null));const n=this.boundsTrees;for(;n.length<i;)n.push(null);if(s<0){for(let o=0;o<i;o++)t.range=e[o],n[o]=new be(this.geometry,t);return n}else return s<e.length&&(t.range=e[s],n[s]=new be(this.geometry,t)),n[s]||null}function zh(s=-1){s<0?this.boundsTrees.fill(null):s<this.boundsTree.length&&(this.boundsTrees[s]=null)}function vh(s){switch(s){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function Kh(s){switch(s){case 1:return X.RedFormat;case 2:return X.RGFormat;case 3:return X.RGBAFormat;case 4:return X.RGBAFormat}}function mr(s){switch(s){case 1:return X.RedIntegerFormat;case 2:return X.RGIntegerFormat;case 3:return X.RGBAIntegerFormat;case 4:return X.RGBAIntegerFormat}}class nn extends X.DataTexture{constructor(){super(),this.minFilter=X.NearestFilter,this.magFilter=X.NearestFilter,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(t){const e=this.overrideItemSize,i=t.itemSize,n=t.count;if(e!==null){if(i*n%e!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");t.itemSize=e,t.count=n*i/e}const o=t.itemSize,r=t.count,l=t.normalized,c=t.array.constructor,a=c.BYTES_PER_ELEMENT;let d=this._forcedType,h=o;if(d===null)switch(c){case Float32Array:d=X.FloatType;break;case Uint8Array:case Uint16Array:case Uint32Array:d=X.UnsignedIntType;break;case Int8Array:case Int16Array:case Int32Array:d=X.IntType;break}let u,p,m,b,G=vh(o);switch(d){case X.FloatType:m=1,p=Kh(o),l&&a===1?(b=c,G+="8",c===Uint8Array?u=X.UnsignedByteType:(u=X.ByteType,G+="_SNORM")):(b=Float32Array,G+="32F",u=X.FloatType);break;case X.IntType:G+=a*8+"I",m=l?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,p=mr(o),a===1?(b=Int8Array,u=X.ByteType):a===2?(b=Int16Array,u=X.ShortType):(b=Int32Array,u=X.IntType);break;case X.UnsignedIntType:G+=a*8+"UI",m=l?Math.pow(2,c.BYTES_PER_ELEMENT*8-1):1,p=mr(o),a===1?(b=Uint8Array,u=X.UnsignedByteType):a===2?(b=Uint16Array,u=X.UnsignedShortType):(b=Uint32Array,u=X.UnsignedIntType);break}h===3&&(p===X.RGBAFormat||p===X.RGBAIntegerFormat)&&(h=4);const y=Math.ceil(Math.sqrt(r))||1,Z=h*y*y,V=new b(Z),R=t.normalized;t.normalized=!1;for(let f=0;f<r;f++){const x=h*f;V[x]=t.getX(f)/m,o>=2&&(V[x+1]=t.getY(f)/m),o>=3&&(V[x+2]=t.getZ(f)/m,h===4&&(V[x+3]=1)),o>=4&&(V[x+3]=t.getW(f)/m)}t.normalized=R,this.internalFormat=G,this.format=p,this.type=u,this.image.width=y,this.image.height=y,this.image.data=V,this.needsUpdate=!0,this.dispose(),t.itemSize=i,t.count=n}}class Yc extends nn{constructor(){super(),this._forcedType=X.UnsignedIntType}}class Th extends nn{constructor(){super(),this._forcedType=X.IntType}}class kc extends nn{constructor(){super(),this._forcedType=X.FloatType}}class Mh{constructor(){this.index=new Yc,this.position=new kc,this.bvhBounds=new X.DataTexture,this.bvhContents=new X.DataTexture,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(t){const{geometry:e}=t;if(kh(t,this.bvhBounds,this.bvhContents),this.position.updateFrom(e.attributes.position),t.indirect){const i=t._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(e.index)this._cachedIndexAttr=e.index.clone();else{const n=Cc(gc(e));this._cachedIndexAttr=new X.BufferAttribute(n,1,!1)}Yh(e,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(e.index)}dispose(){const{index:t,position:e,bvhBounds:i,bvhContents:n}=this;t&&t.dispose(),e&&e.dispose(),i&&i.dispose(),n&&n.dispose()}}function Yh(s,t,e){const i=e.array,n=s.index?s.index.array:null;for(let o=0,r=t.length;o<r;o++){const l=3*o,c=3*t[o];for(let a=0;a<3;a++)i[l+a]=n?n[c+a]:c+a}}function kh(s,t,e){const i=s._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const n=i[0],o=new Uint16Array(n),r=new Uint32Array(n),l=new Float32Array(n),c=n.byteLength/pe,a=2*Math.ceil(Math.sqrt(c/2)),d=new Float32Array(4*a*a),h=Math.ceil(Math.sqrt(c)),u=new Uint32Array(2*h*h);for(let p=0;p<c;p++){const m=p*pe/4,b=m*2,G=m;for(let y=0;y<3;y++)d[8*p+0+y]=l[G+0+y],d[8*p+4+y]=l[G+3+y];if(Zt(b,o)){const y=gt(b,o),Z=xt(m,r),V=4294901760|y;u[p*2+0]=V,u[p*2+1]=Z}else{const y=4*Ct(m,r)/pe,Z=ho(m,r);u[p*2+0]=Z,u[p*2+1]=y}}t.image.data=d,t.image.width=a,t.image.height=a,t.format=X.RGBAFormat,t.type=X.FloatType,t.internalFormat="RGBA32F",t.minFilter=X.NearestFilter,t.magFilter=X.NearestFilter,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose(),e.image.data=u,e.image.width=h,e.image.height=h,e.format=X.RGIntegerFormat,e.type=X.UnsignedIntType,e.internalFormat="RG32UI",e.minFilter=X.NearestFilter,e.magFilter=X.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose()}const ve=new X.Vector3,Ke=new X.Vector3,Te=new X.Vector3,br=new X.Vector4,Ys=new X.Vector3,gn=new X.Vector3,yr=new X.Vector4,Gr=new X.Vector4,ks=new X.Matrix4,Zr=new X.Matrix4;function Xi(s,t){if(!s&&!t)return;const e=s.count===t.count,i=s.normalized===t.normalized,n=s.array.constructor===t.array.constructor,o=s.itemSize===t.itemSize;if(!e||!i||!n||!o)throw new Error}function Li(s,t=null){const e=s.array.constructor,i=s.normalized,n=s.itemSize,o=t===null?s.count:t;return new X.BufferAttribute(new e(n*o),n,i)}function Hc(s,t,e=0){if(s.isInterleavedBufferAttribute){const i=s.itemSize;for(let n=0,o=s.count;n<o;n++){const r=n+e;t.setX(r,s.getX(n)),i>=2&&t.setY(r,s.getY(n)),i>=3&&t.setZ(r,s.getZ(n)),i>=4&&t.setW(r,s.getW(n))}}else{const i=t.array,n=i.constructor,o=i.BYTES_PER_ELEMENT*s.itemSize*e;new n(i.buffer,o,s.array.length).set(s.array)}}function Hh(s,t,e){const i=s.elements,n=t.elements;for(let o=0,r=n.length;o<r;o++)i[o]+=n[o]*e}function Xr(s,t,e){const i=s.skeleton,n=s.geometry,o=i.bones,r=i.boneInverses;yr.fromBufferAttribute(n.attributes.skinIndex,t),Gr.fromBufferAttribute(n.attributes.skinWeight,t),ks.elements.fill(0);for(let l=0;l<4;l++){const c=Gr.getComponent(l);if(c!==0){const a=yr.getComponent(l);Zr.multiplyMatrices(o[a].matrixWorld,r[a]),Hh(ks,Zr,c)}}return ks.multiply(s.bindMatrix).premultiply(s.bindMatrixInverse),e.transformDirection(ks),e}function Cn(s,t,e,i,n){Ys.set(0,0,0);for(let o=0,r=s.length;o<r;o++){const l=t[o],c=s[o];l!==0&&(gn.fromBufferAttribute(c,i),e?Ys.addScaledVector(gn,l):Ys.addScaledVector(gn.sub(n),l))}n.add(Ys)}function Nh(s,t={useGroups:!1,updateIndex:!1,skipAttributes:[]},e=new X.BufferGeometry){const i=s[0].index!==null,{useGroups:n=!1,updateIndex:o=!1,skipAttributes:r=[]}=t,l=new Set(Object.keys(s[0].attributes)),c={};let a=0;e.clearGroups();for(let d=0;d<s.length;++d){const h=s[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(!l.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.');c[p]===void 0&&(c[p]=[]),c[p].push(h.attributes[p]),u++}if(u!==l.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(n){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");e.addGroup(a,p,d),a+=p}}if(i){let d=!1;if(!e.index){let h=0;for(let u=0;u<s.length;++u)h+=s[u].index.count;e.setIndex(new X.BufferAttribute(new Uint32Array(h),1,!1)),d=!0}if(o||d){const h=e.index;let u=0,p=0;for(let m=0;m<s.length;++m){const b=s[m],G=b.index;if(r[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 c){const h=c[d];if(!(d in e.attributes)){let m=0;for(const b in h)m+=h[b].count;e.setAttribute(d,Li(c[d][0],m))}const u=e.attributes[d];let p=0;for(let m=0,b=h.length;m<b;m++){const G=h[m];r[m]!==!0&&Hc(G,u,p),p+=G.count}}return e}function Ih(s,t){if(s===null||t===null)return s===t;if(s.length!==t.length)return!1;for(let e=0,i=s.length;e<i;e++)if(s[e]!==t[e])return!1;return!0}function Jh(s){const{index:t,attributes:e}=s;if(t)for(let i=0,n=t.count;i<n;i+=3){const o=t.getX(i),r=t.getX(i+2);t.setX(i,r),t.setX(i+2,o)}else for(const i in e){const n=e[i],o=n.itemSize;for(let r=0,l=n.count;r<l;r+=3)for(let c=0;c<o;c++){const a=n.getComponent(r,c),d=n.getComponent(r+2,c);n.setComponent(r,c,d),n.setComponent(r+2,c,a)}}return s}class Uh{constructor(t){this.matrixWorld=new X.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=t,this.update()}update(){const t=this.mesh,e=t.geometry,i=t.skeleton,n=(e.index?e.index.count:e.attributes.position.count)/3;if(this.matrixWorld.copy(t.matrixWorld),this.geometryHash=e.attributes.position.version,this.primitiveCount=n,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 t=this.mesh,e=t.geometry,i=(e.index?e.index.count:e.attributes.position.count)/3;return!(this.matrixWorld.equals(t.matrixWorld)&&this.geometryHash===e.attributes.position.version&&Ih(t.skeleton&&t.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===i)}}class Ph{constructor(t){Array.isArray(t)||(t=[t]);const e=[];t.forEach(i=>{i.traverseVisible(n=>{n.isMesh&&e.push(n)})}),this.meshes=e,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(e.length).fill().map(()=>new X.BufferGeometry),this._diffMap=new WeakMap}getMaterials(){const t=[];return this.meshes.forEach(e=>{Array.isArray(e.material)?t.push(...e.material):t.push(e.material)}),t}generate(t=new X.BufferGeometry){let e=[];const{meshes:i,useGroups:n,_intermediateGeometry:o,_diffMap:r}=this;for(let l=0,c=i.length;l<c;l++){const a=i[l],d=o[l],h=r.get(a);!h||h.didChange(a)?(this._convertToStaticGeometry(a,d),e.push(!1),h?h.update():r.set(a,new Uh(a))):e.push(!0)}if(o.length===0){t.setIndex(null);const l=t.attributes;for(const c in l)t.deleteAttribute(c);for(const c in this.attributes)t.setAttribute(this.attributes[c],new X.BufferAttribute(new Float32Array(0),4,!1))}else Nh(o,{useGroups:n,skipAttributes:e},t);for(const l in t.attributes)t.attributes[l].needsUpdate=!0;return t}_convertToStaticGeometry(t,e=new X.BufferGeometry){const i=t.geometry,n=this.applyWorldTransforms,o=this.attributes.includes("normal"),r=this.attributes.includes("tangent"),l=i.attributes,c=e.attributes;!e.index&&i.index&&(e.index=i.index.clone()),c.position||e.setAttribute("position",Li(l.position)),o&&!c.normal&&l.normal&&e.setAttribute("normal",Li(l.normal)),r&&!c.tangent&&l.tangent&&e.setAttribute("tangent",Li(l.tangent)),Xi(i.index,e.index),Xi(l.position,c.position),o&&Xi(l.normal,c.normal),r&&Xi(l.tangent,c.tangent);const a=l.position,d=o?l.normal:null,h=r?l.tangent:null,u=i.morphAttributes.position,p=i.morphAttributes.normal,m=i.morphAttributes.tangent,b=i.morphTargetsRelative,G=t.morphTargetInfluences,y=new X.Matrix3;y.getNormalMatrix(t.matrixWorld),i.index&&e.index.array.set(i.index.array);for(let Z=0,V=l.position.count;Z<V;Z++)ve.fromBufferAttribute(a,Z),d&&Ke.fromBufferAttribute(d,Z),h&&(br.fromBufferAttribute(h,Z),Te.fromBufferAttribute(h,Z)),G&&(u&&Cn(u,G,b,Z,ve),p&&Cn(p,G,b,Z,Ke),m&&Cn(m,G,b,Z,Te)),t.isSkinnedMesh&&(t.applyBoneTransform(Z,ve),d&&Xr(t,Z,Ke),h&&Xr(t,Z,Te)),n&&ve.applyMatrix4(t.matrixWorld),c.position.setXYZ(Z,ve.x,ve.y,ve.z),d&&(n&&Ke.applyNormalMatrix(y),c.normal.setXYZ(Z,Ke.x,Ke.y,Ke.z)),h&&(n&&Te.transformDirection(t.matrixWorld),c.tangent.setXYZW(Z,Te.x,Te.y,Te.z,br.w));for(const Z in this.attributes){const V=this.attributes[Z];V==="position"||V==="tangent"||V==="normal"||!(V in l)||(c[V]||e.setAttribute(V,Li(l[V])),Xi(l[V],c[V]),Hc(l[V],c[V]))}return t.matrixWorld.determinant()<0&&Jh(e),e}}const Nc=`
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