@needle-tools/engine 4.9.0 → 4.9.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 (37) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/{needle-engine.bundle-B1gr_nQ0.min.js → needle-engine.bundle-DwspSk2O.min.js} +95 -95
  3. package/dist/{needle-engine.bundle-DrlDKOar.umd.cjs → needle-engine.bundle-WLYWw5OF.umd.cjs} +89 -89
  4. package/dist/{needle-engine.bundle-BikYBC35.js → needle-engine.bundle-XBRfMDwo.js} +1992 -1952
  5. package/dist/needle-engine.js +2 -2
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/dist/{vendor-8le8g4MS.umd.cjs → vendor-BtJpSuCj.umd.cjs} +1 -1
  9. package/dist/{vendor-yDFiCnCw.min.js → vendor-XJ9xiwrv.min.js} +1 -1
  10. package/dist/{vendor-Msb9AgYE.js → vendor-k9i6CeGi.js} +871 -870
  11. package/lib/engine/engine_gameobject.d.ts +7 -7
  12. package/lib/engine/engine_gameobject.js +88 -27
  13. package/lib/engine/engine_gameobject.js.map +1 -1
  14. package/lib/engine/engine_networking_instantiate.js +23 -6
  15. package/lib/engine/engine_networking_instantiate.js.map +1 -1
  16. package/lib/engine/engine_serialization_core.d.ts +2 -2
  17. package/lib/engine/engine_serialization_core.js +7 -7
  18. package/lib/engine/engine_serialization_core.js.map +1 -1
  19. package/lib/engine/engine_serialization_decorator.js +2 -1
  20. package/lib/engine/engine_serialization_decorator.js.map +1 -1
  21. package/lib/engine-components/Animation.js +1 -1
  22. package/lib/engine-components/Animation.js.map +1 -1
  23. package/lib/engine-components/Renderer.d.ts +7 -6
  24. package/lib/engine-components/Renderer.js +3 -0
  25. package/lib/engine-components/Renderer.js.map +1 -1
  26. package/lib/engine-components/web/ScrollFollow.d.ts +19 -1
  27. package/lib/engine-components/web/ScrollFollow.js +20 -1
  28. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  29. package/package.json +2 -2
  30. package/plugins/vite/build.js +3 -0
  31. package/src/engine/engine_gameobject.ts +105 -38
  32. package/src/engine/engine_networking_instantiate.ts +21 -6
  33. package/src/engine/engine_serialization_core.ts +9 -9
  34. package/src/engine/engine_serialization_decorator.ts +2 -1
  35. package/src/engine-components/Animation.ts +1 -1
  36. package/src/engine-components/Renderer.ts +16 -10
  37. package/src/engine-components/web/ScrollFollow.ts +20 -1
@@ -1118,4 +1118,4 @@ void main() {
1118
1118
  vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
1119
1119
 
1120
1120
  #include <fog_vertex>
1121
- }`;class fh extends da{constructor(e){super(e),this.vector_=new z,this.vector2_=new z,this.vector3_=new z,this.quaternion_=new j,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new lr,this.indexBuffer=new Te(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(ge),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(ge),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(ge),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(ge),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(ge),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(ge),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new Te(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(ge),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new Te(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(ge),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new ir(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Gn(this.settings.material.map.channel),e.map=new Ve(this.settings.material.map),e.mapTransform=new Ve(new rt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===R.Trail)this.material=new cn({uniforms:e,defines:t,vertexShader:ph,fragmentShader:dh,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Ss,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let e=0,t=0,r=0;this.systems.forEach(i=>{for(let s=0;s<i.particleNum;s++)r+=i.particles[s].previous.length*2}),r>this.maxParticles&&this.expandBuffers(r),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;i.emitter.matrixWorld.decompose(a,s,o);const c=i.particles,l=i.particleNum,h=this.settings.uTileCount,u=this.settings.vTileCount,d=1/h,p=1/u;for(let y=0;y<l;y++){const g=c[y],f=g.uvTile%u,m=Math.floor(g.uvTile/u+.001),b=g.previous.values();let v=b.next(),x=v.value,_=x;v.done||(v=b.next());let S;v.value!==void 0?S=v.value:S=_;for(let w=0;w<g.previous.length;w++,e+=2){if(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z),i.worldSpace?(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z)):(g.parentMatrix?this.vector_.copy(_.position).applyMatrix4(g.parentMatrix):this.vector_.copy(_.position).applyMatrix4(i.emitter.matrixWorld),this.positionBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.previousBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.previousBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(g.parentMatrix?this.vector_.copy(x.position).applyMatrix4(g.parentMatrix):this.vector_.copy(x.position).applyMatrix4(i.emitter.matrixWorld),this.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.nextBuffer.setXYZ(e,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+1,S.position.x,S.position.y,S.position.z)):(g.parentMatrix?this.vector_.copy(S.position).applyMatrix4(g.parentMatrix):this.vector_.copy(S.position).applyMatrix4(i.emitter.matrixWorld),this.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,-1),this.sideBuffer.setX(e+1,1),i.worldSpace)this.widthBuffer.setX(e,_.size),this.widthBuffer.setX(e+1,_.size);else if(g.parentMatrix)this.widthBuffer.setX(e,_.size),this.widthBuffer.setX(e+1,_.size);else{const C=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,_.size*C),this.widthBuffer.setX(e+1,_.size*C)}this.uvBuffer.setXY(e,(w/g.previous.length+f)*d,(u-m-1)*p),this.uvBuffer.setXY(e+1,(w/g.previous.length+f)*d,(u-m)*p),this.colorBuffer.setXYZW(e,_.color.x,_.color.y,_.color.z,_.color.w),this.colorBuffer.setXYZW(e+1,_.color.x,_.color.y,_.color.z,_.color.w),w+1<g.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),x=_,_=S,v.done||(v=b.next(),v.value!==void 0&&(S=v.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class ui{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new Et;this._triangleIndexToArea.length=0;let r=0;if(!e.getIndex())return;const i=e.getIndex().array,s=i.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),i[a*3],i[a*3+1],i[a*3+2]),r+=t.getArea(),this._triangleIndexToArea.push(r);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new I,this._tempB=new I,this._tempC=new I,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);return}const r=this._triangleIndexToArea.length-1;let i=0,s=r;const a=Math.random()*this._triangleIndexToArea[r];for(;i+1<s;){const p=Math.floor((i+s)/2);a<this._triangleIndexToArea[p]?s=p:i=p}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],h=t.getIndex().array[i*3+1],u=t.getIndex().array[i*3+2],d=t.getAttribute("position");this._tempA.fromBufferAttribute(d,l),this._tempB.fromBufferAttribute(d,h),this._tempC.fromBufferAttribute(d,u),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new ui(t.geometries[e.geometry])}clone(){return new ui(this._geometry)}update(e,t){}}Wl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:ui,loadJSON:ui.fromJSON}],behaviors:[]});class vs extends _s{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let i=0;i<this.batches.length;i++)if(vs.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let r;switch(t.renderMode){case R.Trail:r=new fh(t);break;case R.Mesh:case R.BillBoard:case R.VerticalBillBoard:case R.HorizontalBillBoard:case R.StretchedBillBoard:r=new uh(t);break}this.depthTexture&&r.applyDepthTexture(this.depthTexture),r.addSystem(e),this.batches.push(r),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(r)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,r)=>{r.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const mh=vs;eh(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const fa=Math.sqrt(5),yh=(fa-1)/4,he=(5-fa)/20,zi=n=>Math.floor(n)|0,Bi=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 gh(n=Math.random){const e=vh(n),t=new Float64Array(e).map(a=>Bi[a%32*4]),r=new Float64Array(e).map(a=>Bi[a%32*4+1]),i=new Float64Array(e).map(a=>Bi[a%32*4+2]),s=new Float64Array(e).map(a=>Bi[a%32*4+3]);return function(a,o,c,l){let h,u,d,p,y;const g=(a+o+c+l)*yh,f=zi(a+g),m=zi(o+g),b=zi(c+g),v=zi(l+g),x=(f+m+b+v)*he,_=f-x,S=m-x,w=b-x,C=v-x,M=a-_,T=o-S,E=c-w,P=l-C;let k=0,A=0,N=0,U=0;M>T?k++:A++,M>E?k++:N++,M>P?k++:U++,T>E?A++:N++,T>P?A++:U++,E>P?N++:U++;const G=k>=3?1:0,B=A>=3?1:0,oe=N>=3?1:0,K=U>=3?1:0,re=k>=2?1:0,$=A>=2?1:0,me=N>=2?1:0,ye=U>=2?1:0,ie=k>=1?1:0,q=A>=1?1:0,W=N>=1?1:0,it=U>=1?1:0,Be=M-G+he,Xe=T-B+he,qe=E-oe+he,_e=P-K+he,Ie=M-re+2*he,xe=T-$+2*he,nt=E-me+2*he,st=P-ye+2*he,Y=M-ie+3*he,Ye=T-q+3*he,ot=E-W+3*he,Ct=P-it+3*he,at=M-1+4*he,ct=T-1+4*he,lt=E-1+4*he,ht=P-1+4*he,Ne=f&255,Ue=m&255,De=b&255,Fe=v&255;let Le=.6-M*M-T*T-E*E-P*P;if(Le<0)h=0;else{const X=Ne+e[Ue+e[De+e[Fe]]];Le*=Le,h=Le*Le*(t[X]*M+r[X]*T+i[X]*E+s[X]*P)}let V=.6-Be*Be-Xe*Xe-qe*qe-_e*_e;if(V<0)u=0;else{const X=Ne+G+e[Ue+B+e[De+oe+e[Fe+K]]];V*=V,u=V*V*(t[X]*Be+r[X]*Xe+i[X]*qe+s[X]*_e)}let or=.6-Ie*Ie-xe*xe-nt*nt-st*st;if(or<0)d=0;else{const X=Ne+re+e[Ue+$+e[De+me+e[Fe+ye]]];or*=or,d=or*or*(t[X]*Ie+r[X]*xe+i[X]*nt+s[X]*st)}let ar=.6-Y*Y-Ye*Ye-ot*ot-Ct*Ct;if(ar<0)p=0;else{const X=Ne+ie+e[Ue+q+e[De+W+e[Fe+it]]];ar*=ar,p=ar*ar*(t[X]*Y+r[X]*Ye+i[X]*ot+s[X]*Ct)}let cr=.6-at*at-ct*ct-lt*lt-ht*ht;if(cr<0)y=0;else{const X=Ne+1+e[Ue+1+e[De+1+e[Fe+1]]];cr*=cr,y=cr*cr*(t[X]*at+r[X]*ct+i[X]*lt+s[X]*ht)}return 27*(h+u+d+p+y)}}function vh(n){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class bh{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var J;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(J||(J={}));class ma{constructor(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b;this._closedByUser=!1,this.handleOpenEvent=v=>this.handleEvent(J.open,v),this.handleErrorEvent=v=>this.handleEvent(J.error,v),this.handleCloseEvent=v=>this.handleEvent(J.close,v),this.handleMessageEvent=v=>this.handleEvent(J.message,v),this._url=e,this._protocols=t,this._options={buffer:r?.buffer,retry:{maxRetries:(i=r?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=r?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=r?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=r?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(h=(l=r?.listeners)===null||l===void 0?void 0:l.close)!==null&&h!==void 0?h:[]],error:[...(d=(u=r?.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[]],message:[...(y=(p=r?.listeners)===null||p===void 0?void 0:p.message)!==null&&y!==void 0?y:[]],retry:[...(f=(g=r?.listeners)===null||g===void 0?void 0:g.retry)!==null&&f!==void 0?f:[]],reconnect:[...(b=(m=r?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&b!==void 0?b:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,r){this._options.listeners[e].push({listener:t,options:r})}removeEventListener(e,t,r){const i=s=>s.listener!==t||s.options!==r;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const r=this._options.listeners[e],i=[];r.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case J.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case J.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const r={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(J.reconnect,{detail:r});this.dispatchEvent(J.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case J.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=r=>{const i=new CustomEvent(J.retry,{detail:r});this.handleEvent(J.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class _h{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(J.open,e,t),this}onClose(e,t){return this.addListener(J.close,e,t),this}onError(e,t){return this.addListener(J.error,e,t),this}onMessage(e,t){return this.addListener(J.message,e,t),this}onRetry(e,t){return this.addListener(J.retry,e,t),this}onReconnect(e,t){return this.addListener(J.reconnect,e,t),this}build(){return new ma(this._url,this._protocols,this._options)}addListener(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b,v,x,_,S,w,C;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(d=(u=(h=this._options)===null||h===void 0?void 0:h.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[],message:(g=(y=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||y===void 0?void 0:y.message)!==null&&g!==void 0?g:[],retry:(b=(m=(f=this._options)===null||f===void 0?void 0:f.listeners)===null||m===void 0?void 0:m.retry)!==null&&b!==void 0?b:[],reconnect:(_=(x=(v=this._options)===null||v===void 0?void 0:v.listeners)===null||x===void 0?void 0:x.reconnect)!==null&&_!==void 0?_:[],[e]:[...(C=(w=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||w===void 0?void 0:w[e])!==null&&C!==void 0?C:[],{listener:t,options:r}]}}),this}}const xh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:bh,Websocket:ma,WebsocketBuilder:_h,get WebsocketEvent(){return J}},Symbol.toStringTag,{value:"Module"})),Wn=0,ya=1,ga=2,Hn=2,Xn=1.25,va=1,Sr=32,Ii=65535,Sh=Math.pow(2,-24),qn=Symbol("SKIP_GENERATION");function wh(n){return n.index?n.index.count:n.attributes.position.count}function qt(n){return wh(n)/3}function Mh(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Th(n,e){if(!n.index){const t=n.attributes.position.count,r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Mh(t,r);n.setIndex(new Te(i,1));for(let s=0;s<t;s++)i[s]=s}}function ba(n,e){const t=qt(n),r=e||n.drawRange,i=r.start/3,s=(r.start+r.count)/3,a=Math.max(0,i),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function _a(n,e){if(!n.groups||!n.groups.length)return ba(n,e);const t=[],r=new Set,i=e||n.drawRange,s=i.start/3,a=(i.start+i.count)/3;for(const c of n.groups){const l=c.start/3,h=(c.start+c.count)/3;r.add(Math.max(s,l)),r.add(Math.min(a,h))}const o=Array.from(r.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],h=o[c+1];t.push({offset:Math.floor(l),count:Math.floor(h-l)})}return t}function Ch(n,e){const t=qt(n),r=_a(n,e).sort((a,o)=>a.offset-o.offset),i=r[r.length-1];i.count=Math.min(t-i.offset,i.count);let s=0;return r.forEach(({count:a})=>s+=a),t!==s}function Yn(n,e,t,r,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,y=-1/0,g=-1/0,f=-1/0;for(let m=e*6,b=(e+t)*6;m<b;m+=6){const v=n[m+0],x=n[m+1],_=v-x,S=v+x;_<s&&(s=_),S>c&&(c=S),v<u&&(u=v),v>y&&(y=v);const w=n[m+2],C=n[m+3],M=w-C,T=w+C;M<a&&(a=M),T>l&&(l=T),w<d&&(d=w),w>g&&(g=w);const E=n[m+4],P=n[m+5],k=E-P,A=E+P;k<o&&(o=k),A>h&&(h=A),E<p&&(p=E),E>f&&(f=E)}r[0]=s,r[1]=a,r[2]=o,r[3]=c,r[4]=l,r[5]=h,i[0]=u,i[1]=d,i[2]=p,i[3]=y,i[4]=g,i[5]=f}function Ph(n,e=null,t=null,r=null){const i=n.attributes.position,s=n.index?n.index.array:null,a=qt(n),o=i.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,r=a):(c=e,t=t||0,r=r||a);const l=i.array,h=i.offset||0;let u=3;i.isInterleavedBufferAttribute&&(u=i.data.stride);const d=["getX","getY","getZ"];for(let p=t;p<t+r;p++){const y=p*3,g=p*6;let f=y+0,m=y+1,b=y+2;s&&(f=s[f],m=s[m],b=s[b]),o||(f=f*u+h,m=m*u+h,b=b*u+h);for(let v=0;v<3;v++){let x,_,S;o?(x=i[d[v]](f),_=i[d[v]](m),S=i[d[v]](b)):(x=l[f+v],_=l[m+v],S=l[b+v]);let w=x;_<w&&(w=_),S<w&&(w=S);let C=x;_>C&&(C=_),S>C&&(C=S);const M=(C-w)/2,T=v*2;c[g+T+0]=w+M,c[g+T+1]=M+(Math.abs(w)+M)*Sh}}return c}function Z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function xa(n){let e=-1,t=-1/0;for(let r=0;r<3;r++){const i=n[r+3]-n[r];i>t&&(t=i,e=r)}return e}function Sa(n,e){e.set(n)}function wa(n,e,t){let r,i;for(let s=0;s<3;s++){const a=s+3;r=n[s],i=e[s],t[s]=r<i?r:i,r=n[a],i=e[a],t[a]=r>i?r:i}}function Ni(n,e,t){for(let r=0;r<3;r++){const i=e[n+2*r],s=e[n+2*r+1],a=i-s,o=i+s;a<t[r]&&(t[r]=a),o>t[r+3]&&(t[r+3]=o)}}function wr(n){const e=n[3]-n[0],t=n[4]-n[1],r=n[5]-n[2];return 2*(e*t+t*r+r*e)}const mt=32,Eh=(n,e)=>n.candidate-e.candidate,xt=new Array(mt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ui=new Float32Array(6);function kh(n,e,t,r,i,s){let a=-1,o=0;if(s===Wn)a=xa(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===ya)a=xa(n),a!==-1&&(o=Rh(t,r,i,a));else if(s===ga){const c=wr(n);let l=Xn*i;const h=r*6,u=(r+i)*6;for(let d=0;d<3;d++){const p=e[d],y=(e[d+3]-p)/mt;if(i<mt/4){const g=[...xt];g.length=i;let f=0;for(let b=h;b<u;b+=6,f++){const v=g[f];v.candidate=t[b+2*d],v.count=0;const{bounds:x,leftCacheBounds:_,rightCacheBounds:S}=v;for(let w=0;w<3;w++)S[w]=1/0,S[w+3]=-1/0,_[w]=1/0,_[w+3]=-1/0,x[w]=1/0,x[w+3]=-1/0;Ni(b,t,x)}g.sort(Eh);let m=i;for(let b=0;b<m;b++){const v=g[b];for(;b+1<m&&g[b+1].candidate===v.candidate;)g.splice(b+1,1),m--}for(let b=h;b<u;b+=6){const v=t[b+2*d];for(let x=0;x<m;x++){const _=g[x];v>=_.candidate?Ni(b,t,_.rightCacheBounds):(Ni(b,t,_.leftCacheBounds),_.count++)}}for(let b=0;b<m;b++){const v=g[b],x=v.count,_=i-v.count,S=v.leftCacheBounds,w=v.rightCacheBounds;let C=0;x!==0&&(C=wr(S)/c);let M=0;_!==0&&(M=wr(w)/c);const T=va+Xn*(C*x+M*_);T<l&&(a=d,l=T,o=v.candidate)}}else{for(let m=0;m<mt;m++){const b=xt[m];b.count=0,b.candidate=p+y+m*y;const v=b.bounds;for(let x=0;x<3;x++)v[x]=1/0,v[x+3]=-1/0}for(let m=h;m<u;m+=6){let b=~~((t[m+2*d]-p)/y);b>=mt&&(b=mt-1);const v=xt[b];v.count++,Ni(m,t,v.bounds)}const g=xt[mt-1];Sa(g.bounds,g.rightCacheBounds);for(let m=mt-2;m>=0;m--){const b=xt[m],v=xt[m+1];wa(b.bounds,v.rightCacheBounds,b.rightCacheBounds)}let f=0;for(let m=0;m<mt-1;m++){const b=xt[m],v=b.count,x=b.bounds,_=xt[m+1].rightCacheBounds;v!==0&&(f===0?Sa(x,Ui):wa(x,Ui,Ui)),f+=v;let S=0,w=0;f!==0&&(S=wr(Ui)/c);const C=i-f;C!==0&&(w=wr(_)/c);const M=va+Xn*(S*f+w*C);M<l&&(a=d,l=M,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Rh(n,e,t,r){let i=0;for(let s=e,a=e+t;s<a;s++)i+=n[s*6+r*2];return i/t}class Zn{constructor(){this.boundingData=new Float32Array(6)}}function Ah(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let h=0;h<3;h++){let u=e[a*3+h];e[a*3+h]=e[o*3+h],e[o*3+h]=u}for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=u}a++,o--}else return a}}function Oh(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){let h=n[a];n[a]=n[o],n[o]=h;for(let u=0;u<6;u++){let d=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=d}a++,o--}else return a}}function we(n,e){return e[n+15]===65535}function Pe(n,e){return e[n+6]}function Ee(n,e){return e[n+14]}function ke(n){return n+8}function Re(n,e){return e[n+6]}function Ma(n,e){return e[n+7]}let Ta,Mr,Di,Ca;const zh=Math.pow(2,32);function Kn(n){return"count"in n?1:1+Kn(n.left)+Kn(n.right)}function Bh(n,e,t){return Ta=new Float32Array(t),Mr=new Uint32Array(t),Di=new Uint16Array(t),Ca=new Uint8Array(t),Qn(n,e)}function Qn(n,e){const t=n/4,r=n/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)Ta[t+a]=s[a];if(i)if(e.buffer){const a=e.buffer;Ca.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=Sr){const l=o/2;we(l,Di)||(Mr[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return Mr[t+6]=a,Di[r+14]=o,Di[r+15]=Ii,n+Sr}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Qn(n+Sr,a),l/4>zh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Mr[t+6]=l/4,l=Qn(l,o),Mr[t+7]=c,l}}function Ih(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,r=t>2**16,i=r?4:2,s=e?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),a=r?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Nh(n,e,t,r,i){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:h}=i,u=n._indirectBuffer,d=n.geometry,p=d.index?d.index.array:null,y=h?Oh:Ah,g=qt(d),f=new Float32Array(6);let m=!1;const b=new Zn;return Yn(e,t,r,b.boundingData,f),x(b,t,r,f),b;function v(_){l&&l(_/g)}function x(_,S,w,C=null,M=0){if(!m&&M>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),w<=o||M>=s)return v(S+w),_.offset=S,_.count=w,_;const T=kh(_.boundingData,C,e,S,w,c);if(T.axis===-1)return v(S+w),_.offset=S,_.count=w,_;const E=y(u,p,e,S,w,T);if(E===S||E===S+w)v(S+w),_.offset=S,_.count=w;else{_.splitAxis=T.axis;const P=new Zn,k=S,A=E-S;_.left=P,Yn(e,k,A,P.boundingData,f),x(P,k,A,f,M+1);const N=new Zn,U=E,G=w-A;_.right=N,Yn(e,U,G,N.boundingData,f),x(N,U,G,f,M+1)}return _}}function Uh(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Ih(t,e.useSharedArrayBuffer),Ch(t,e.range)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||Th(t,e);const r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Ph(t),s=e.indirect?ba(t,e.range):_a(t,e.range);n._roots=s.map(a=>{const o=Nh(n,i,a.offset,a.count,e),c=Kn(o),l=new r(Sr*c);return Bh(0,o,l),l})}class yt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let r=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];r=o<r?o:r,i=o>i?o:i}this.min=r,this.max=i}setFromPoints(e,t){let r=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);r=c<r?c:r,i=c>i?c:i}this.min=r,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}yt.prototype.setFromBox=function(){const n=new I;return function(e,t){const r=t.min,i=t.max;let s=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let l=0;l<=1;l++){n.x=r.x*o+i.x*(1-o),n.y=r.y*c+i.y*(1-c),n.z=r.z*l+i.z*(1-l);const h=e.dot(n);s=Math.min(h,s),a=Math.max(h,a)}this.min=s,this.max=a}}();const Dh=function(){const n=new I,e=new I,t=new I;return function(r,i,s){const a=r.start,o=n,c=i.start,l=e;t.subVectors(a,c),n.subVectors(r.end,r.start),e.subVectors(i.end,i.start);const h=t.dot(l),u=l.dot(o),d=l.dot(l),p=t.dot(o),y=o.dot(o)*d-u*u;let g,f;y!==0?g=(h*u-p*d)/y:g=0,f=(h+g*u)/d,s.x=g,s.y=f}}(),$n=function(){const n=new Jt,e=new I,t=new I;return function(r,i,s,a){Dh(r,i,n);let o=n.x,c=n.y;if(o>=0&&o<=1&&c>=0&&c<=1){r.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),r.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?r.at(0,s):r.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=r.start:l=r.end;let h;c<0?h=i.start:h=i.end;const u=e,d=t;if(r.closestPointToPoint(h,!0,e),i.closestPointToPoint(l,!0,t),u.distanceToSquared(h)<=d.distanceToSquared(l)){s.copy(u),a.copy(h);return}else{s.copy(l),a.copy(d);return}}}}(),Fh=function(){const n=new I,e=new I,t=new ws,r=new ut;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:h}=s;if(r.start=c,r.end=l,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a||(r.start=c,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a)||(r.start=l,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a))return!0;const u=s.getPlane(t);if(Math.abs(u.distanceToPoint(o))<=a){const d=u.projectPoint(o,e);if(s.containsPoint(d))return!0}return!1}}(),Lh=1e-15;function es(n){return Math.abs(n)<Lh}class Ae extends Et{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new I),this.satBounds=new Array(4).fill().map(()=>new yt),this.points=[this.a,this.b,this.c],this.sphere=new Ms,this.plane=new ws,this.needsUpdate=!0}intersectsSphere(e){return Fh(e,this)}update(){const e=this.a,t=this.b,r=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],h=a[1];l.subVectors(e,t),h.setFromPoints(l,i);const u=s[2],d=a[2];u.subVectors(t,r),d.setFromPoints(u,i);const p=s[3],y=a[3];p.subVectors(r,e),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}Ae.prototype.closestPointToSegment=function(){const n=new I,e=new I,t=new ut;return function(r,i=null,s=null){const{start:a,end:o}=r,c=this.points;let l,h=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;t.start.copy(c[u]),t.end.copy(c[d]),$n(t,r,n,e),l=n.distanceToSquared(e),l<h&&(h=l,i&&i.copy(n),s&&s.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(a)),this.closestPointToPoint(o,n),l=o.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(o)),Math.sqrt(h)}}(),Ae.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new Array(3),r=new yt,i=new yt,s=new I,a=new I,o=new I,c=new I,l=new I,h=new ut,u=new ut,d=new ut,p=new I;function y(g,f,m){const b=g.points;let v=0,x=-1;for(let _=0;_<3;_++){const{start:S,end:w}=h;S.copy(b[_]),w.copy(b[(_+1)%3]),h.delta(a);const C=es(f.distanceToPoint(S));if(es(f.normal.dot(a))&&C){m.copy(h),v=2;break}const M=f.intersectLine(h,p);if(!M&&C&&p.copy(S),(M||C)&&!es(p.distanceTo(w))){if(v<=1)(v===1?m.start:m.end).copy(p),C&&(x=v);else if(v>=2){(x===1?m.start:m.end).copy(p),v=2;break}if(v++,v===2&&x===-1)break}}return v}return function(g,f=null,m=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(n.copy(g),n.update(),g=n);const b=this.plane,v=g.plane;if(Math.abs(b.normal.dot(v.normal))>1-1e-10){const x=this.satBounds,_=this.satAxes;t[0]=g.a,t[1]=g.b,t[2]=g.c;for(let C=0;C<4;C++){const M=x[C],T=_[C];if(r.setFromPoints(T,t),M.isSeparated(r))return!1}const S=g.satBounds,w=g.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const M=S[C],T=w[C];if(r.setFromPoints(T,e),M.isSeparated(r))return!1}for(let C=0;C<4;C++){const M=_[C];for(let T=0;T<4;T++){const E=w[T];if(s.crossVectors(M,E),r.setFromPoints(s,e),i.setFromPoints(s,t),r.isSeparated(i))return!1}}return f&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const x=y(this,v,u);if(x===1&&g.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(x!==2)return!1;const _=y(g,b,d);if(_===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(_!==2)return!1;if(u.delta(o),d.delta(c),o.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=u.start.dot(o),w=u.end.dot(o),C=d.start.dot(o),M=d.end.dot(o),T=w<C,E=S<M;return S!==M&&C!==w&&T===E?!1:(f&&(l.subVectors(u.start,d.start),l.dot(o)>0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(o)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}(),Ae.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Ae.prototype.distanceToTriangle=function(){const n=new I,e=new I,t=["a","b","c"],r=new ut,i=new ut;return function(s,a=null,o=null){const c=a||o?r:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let h=0;h<3;h++){let u;const d=t[h],p=s[d];this.closestPointToPoint(p,n),u=p.distanceToSquared(n),u<l&&(l=u,a&&a.copy(n),o&&o.copy(p));const y=this[d];s.closestPointToPoint(y,n),u=y.distanceToSquared(n),u<l&&(l=u,a&&a.copy(y),o&&o.copy(n))}for(let h=0;h<3;h++){const u=t[h],d=t[(h+1)%3];r.set(this[u],this[d]);for(let p=0;p<3;p++){const y=t[p],g=t[(p+1)%3];i.set(s[y],s[g]),$n(r,i,n,e);const f=n.distanceToSquared(e);f<l&&(l=f,a&&a.copy(n),o&&o.copy(e))}}return Math.sqrt(l)}}();class fe{constructor(e,t,r){this.isOrientedBox=!0,this.min=new I,this.max=new I,this.matrix=new je,this.invMatrix=new je,this.points=new Array(8).fill().map(()=>new I),this.satAxes=new Array(3).fill().map(()=>new I),this.satBounds=new Array(3).fill().map(()=>new yt),this.alignedSatBounds=new Array(3).fill().map(()=>new yt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),r&&this.matrix.copy(r)}set(e,t,r){this.min.copy(e),this.max.copy(t),this.matrix.copy(r),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,r=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){const u=1*c|2*l|4*h,d=r[u];d.x=c?t.x:e.x,d.y=l?t.y:e.y,d.z=h?t.z:e.z,d.applyMatrix4(n)}const i=this.satBounds,s=this.satAxes,a=r[0];for(let c=0;c<3;c++){const l=s[c],h=i[c],u=1<<c,d=r[u];l.subVectors(a,d),h.setFromPoints(l,r)}const o=this.alignedSatBounds;o[0].setFromPointsField(r,"x"),o[1].setFromPointsField(r,"y"),o[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),fe.prototype.intersectsBox=function(){const n=new yt;return function(e){this.needsUpdate&&this.update();const t=e.min,r=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=r.x,a[0].isSeparated(n)||(n.min=t.y,n.max=r.y,a[1].isSeparated(n))||(n.min=t.z,n.max=r.z,a[2].isSeparated(n)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(n.setFromBox(c,e),l.isSeparated(n))return!1}return!0}}(),fe.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new yt,r=new yt,i=new I;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(n.copy(s),n.update(),s=n);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let u=0;u<3;u++){const d=a[u],p=o[u];if(t.setFromPoints(p,e),d.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,h=this.points;for(let u=0;u<3;u++){const d=c[u],p=l[u];if(t.setFromPoints(p,h),d.isSeparated(t))return!1}for(let u=0;u<3;u++){const d=o[u];for(let p=0;p<4;p++){const y=l[p];if(i.crossVectors(d,y),t.setFromPoints(i,e),r.setFromPoints(i,h),t.isSeparated(r))return!1}}return!0}}(),fe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),fe.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),fe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ut),t=new Array(12).fill().map(()=>new ut),r=new I,i=new I;return function(s,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(o||c)&&(s.getCenter(i),this.closestPointToPoint(i,r),s.closestPointToPoint(r,i),o&&o.copy(r),c&&c.copy(i)),0;const l=a*a,h=s.min,u=s.max,d=this.points;let p=1/0;for(let g=0;g<8;g++){const f=d[g];i.copy(f).clamp(h,u);const m=f.distanceToSquared(i);if(m<p&&(p=m,o&&o.copy(f),c&&c.copy(i),m<l))return Math.sqrt(m)}let y=0;for(let g=0;g<3;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){const b=(g+1)%3,v=(g+2)%3,x=f<<b|m<<v,_=1<<g|f<<b|m<<v,S=d[x],w=d[_];e[y].set(S,w);const C=n[g],M=n[b],T=n[v],E=t[y],P=E.start,k=E.end;P[C]=h[C],P[M]=f?h[M]:u[M],P[T]=m?h[T]:u[M],k[C]=u[C],k[M]=f?h[M]:u[M],k[T]=m?h[T]:u[M],y++}for(let g=0;g<=1;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){i.x=g?u.x:h.x,i.y=f?u.y:h.y,i.z=m?u.z:h.z,this.closestPointToPoint(i,r);const b=i.distanceToSquared(r);if(b<p&&(p=b,o&&o.copy(r),c&&c.copy(i),b<l))return Math.sqrt(b)}for(let g=0;g<12;g++){const f=e[g];for(let m=0;m<12;m++){const b=t[m];$n(f,b,r,i);const v=r.distanceToSquared(i);if(v<p&&(p=v,o&&o.copy(r),c&&c.copy(i),v<l))return Math.sqrt(v)}}return Math.sqrt(p)}}();class ts{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Vh extends ts{constructor(){super(()=>new Ae)}}const Oe=new Vh;class jh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=r=>{t&&e.push(t),t=r,this.float32Array=new Float32Array(r),this.uint16Array=new Uint16Array(r),this.uint32Array=new Uint32Array(r)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const H=new jh;let St,Yt;const Zt=[],Fi=new ts(()=>new Ze);function Jh(n,e,t,r,i,s){St=Fi.getPrimitive(),Yt=Fi.getPrimitive(),Zt.push(St,Yt),H.setBuffer(n._roots[e]);const a=rs(0,n.geometry,t,r,i,s);H.clearBuffer(),Fi.releasePrimitive(St),Fi.releasePrimitive(Yt),Zt.pop(),Zt.pop();const o=Zt.length;return o>0&&(Yt=Zt[o-1],St=Zt[o-2]),a}function rs(n,e,t,r,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=H;let h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);return Z(n,o,St),r(u,d,!1,a,s+n,St)}else{let u=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=ke(E),A=E*2;return Pe(E,k)},d=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=Re(E,k),A=E*2;return Pe(E,k)+Ee(A,P)};const p=ke(n),y=Re(n,l);let g=p,f=y,m,b,v,x;if(i&&(v=St,x=Yt,Z(g,o,v),Z(f,o,x),m=i(v),b=i(x),b<m)){g=y,f=p;const E=m;m=b,b=E,v=x}v||(v=St,Z(g,o,v));const _=we(g*2,c),S=t(v,_,m,a+1,s+g);let w;if(S===Hn){const E=u(g),P=d(g)-E;w=r(E,P,!0,a+1,s+g,v)}else w=S&&rs(g,e,t,r,i,s,a+1);if(w)return!0;x=Yt,Z(f,o,x);const C=we(f*2,c),M=t(x,C,b,a+1,s+f);let T;if(M===Hn){const E=u(f),P=d(f)-E;T=r(E,P,!0,a+1,s+f,x)}else T=M&&rs(f,e,t,r,i,s,a+1);return!!T}}const Tr=new I,is=new I;function Gh(n,e,t={},r=0,i=1/0){const s=r*r,a=i*i;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:h=>(Tr.copy(e).clamp(h.min,h.max),Tr.distanceToSquared(e)),intersectsBounds:(h,u,d)=>d<o&&d<a,intersectsTriangle:(h,u)=>{h.closestPointToPoint(e,Tr);const d=e.distanceToSquared(Tr);return d<o&&(is.copy(Tr),o=d,c=u),d<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(is):t.point=is.clone(),t.distance=l,t.faceIndex=c,t}const Wh=parseInt(Ya)>=169,At=new I,Ot=new I,zt=new I,Li=new Jt,Vi=new Jt,ji=new Jt,Pa=new I,Ea=new I,ka=new I,Cr=new I;function Hh(n,e,t,r,i,s,a,o){let c;if(s===qa?c=n.intersectTriangle(r,t,e,!0,i):c=n.intersectTriangle(e,t,r,s!==an,i),c===null)return null;const l=n.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Xh(n,e,t,r,i,s,a,o,c,l,h){At.fromBufferAttribute(e,s),Ot.fromBufferAttribute(e,a),zt.fromBufferAttribute(e,o);const u=Hh(n,At,Ot,zt,Cr,c,l,h);if(u){const d=new I;Et.getBarycoord(Cr,At,Ot,zt,d),r&&(Li.fromBufferAttribute(r,s),Vi.fromBufferAttribute(r,a),ji.fromBufferAttribute(r,o),u.uv=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),i&&(Li.fromBufferAttribute(i,s),Vi.fromBufferAttribute(i,a),ji.fromBufferAttribute(i,o),u.uv1=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),t&&(Pa.fromBufferAttribute(t,s),Ea.fromBufferAttribute(t,a),ka.fromBufferAttribute(t,o),u.normal=Et.getInterpolation(Cr,At,Ot,zt,Pa,Ea,ka,new I),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const p={a:s,b:a,c:o,normal:new I,materialIndex:0};Et.getNormal(At,Ot,zt,p.normal),u.face=p,u.faceIndex=s,Wh&&(u.barycoord=d)}return u}function Ji(n,e,t,r,i,s,a){const o=r*3;let c=o+0,l=o+1,h=o+2;const u=n.index;n.index&&(c=u.getX(c),l=u.getX(l),h=u.getX(h));const{position:d,normal:p,uv:y,uv1:g}=n.attributes,f=Xh(t,d,p,y,g,c,l,h,e,s,a);return f?(f.faceIndex=r,i&&i.push(f),f):null}function te(n,e,t,r){const i=n.a,s=n.b,a=n.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=r.getX(o),i.y=r.getY(o),i.z=r.getZ(o),s.x=r.getX(c),s.y=r.getY(c),s.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++)Ji(c,e,t,h,s,a,o)}function Yh(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function Zh(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=h,te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function Kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=3*f,M=3*(f+m);C<M;C++){let T=r[C];const E=i.getX(T),P=i.getY(T),k=i.getZ(T);E<b&&(b=E),E>_&&(_=E),P<v&&(v=P),P>S&&(S=P),k<x&&(x=k),k>w&&(w=k)}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function wt(n,e,t,r,i){let s,a,o,c,l,h;const u=1/t.direction.x,d=1/t.direction.y,p=1/t.direction.z,y=t.origin.x,g=t.origin.y,f=t.origin.z;let m=e[n],b=e[n+3],v=e[n+1],x=e[n+3+1],_=e[n+2],S=e[n+3+2];return u>=0?(s=(m-y)*u,a=(b-y)*u):(s=(b-y)*u,a=(m-y)*u),d>=0?(o=(v-g)*d,c=(x-g)*d):(o=(x-g)*d,c=(v-g)*d),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),p>=0?(l=(_-f)*p,h=(S-f)*p):(l=(S-f)*p,h=(_-f)*p),s>h||l>a)?!1:((l>s||s!==s)&&(s=l),(h<a||a!==a)&&(a=h),s<=i&&a>=r)}function Qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++){let d=l?l[h]:h;Ji(c,e,t,d,s,a,o)}}function $h(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,c?c[u]:u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function eu(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=t.resolveTriangleIndex(h),te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function tu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),ns(0,n,t,r,i,s,a),H.clearBuffer()}function ns(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&ns(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&ns(d,e,t,r,i,s,a)}}const ru=["x","y","z"];function iu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ss(0,n,t,r,i,s);return H.clearBuffer(),a}function ss(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return Yh(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=ru[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ss(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ss(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Gi=new Ze,Kt=new Ae,Qt=new Ae,Pr=new je,Ra=new fe,Wi=new fe;function nu(n,e,t,r){H.setBuffer(n._roots[e]);const i=os(0,n,t,r);return H.clearBuffer(),i}function os(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ra.set(t.boundingBox.min,t.boundingBox.max,r),i=Ra),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(Pr.copy(r).invert(),t.boundsTree)return Z(n,s,Wi),Wi.matrix.copy(Pr),Wi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>Wi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y*3,b=(g+y)*3;m<b;m+=3)if(te(Qt,m,h,u),Qt.needsUpdate=!0,f.intersectsTriangle(Qt))return!0;return!1}});for(let f=y*3,m=(g+y)*3;f<m;f+=3){te(Kt,f,h,u),Kt.a.applyMatrix4(Pr),Kt.b.applyMatrix4(Pr),Kt.c.applyMatrix4(Pr),Kt.needsUpdate=!0;for(let b=0,v=d.count;b<v;b+=3)if(te(Qt,b,d,p),Qt.needsUpdate=!0,Kt.intersectsTriangle(Qt))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Gi),!!(i.intersectsBox(Gi)&&os(l,e,t,r,i)||(Z(h,s,Gi),i.intersectsBox(Gi)&&os(h,e,t,r,i)))}}const Hi=new je,as=new fe,Er=new fe,su=new I,ou=new I,au=new I,cu=new I;function lu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),as.set(e.boundingBox.min,e.boundingBox.max,t),as.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=su,g=ou,f=null,m=null;i&&(f=au,m=cu);let b=1/0,v=null,x=null;return Hi.copy(t).invert(),Er.matrix.copy(Hi),n.shapecast({boundsTraverseOrder:_=>as.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Er.min.copy(_.min),Er.max.copy(_.max),Er.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>Er.distanceToBox(w),intersectsBounds:(w,C,M)=>M<b&&M<a,intersectsRange:(w,C)=>{for(let M=w,T=w+C;M<T;M++){te(p,3*M,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=_,P=_+S;E<P;E++){te(d,3*E,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=E,x=M),k<s)return!0}}}});{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){te(d,3*T,l,c),d.needsUpdate=!0;const P=d.distanceToTriangle(p,y,f);if(P<b&&(g.copy(y),m&&m.copy(f),b=P,v=T,x=C),P<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Hi),g.applyMatrix4(Hi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=f,M=f+m;C<M;C++){const T=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let P=T+E;P=r?r[P]:P;const k=i.getX(P),A=i.getY(P),N=i.getZ(P);k<b&&(b=k),k>_&&(_=k),A<v&&(v=A),A>S&&(S=A),N<x&&(x=N),N>w&&(w=N)}}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function uu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),cs(0,n,t,r,i,s,a),H.clearBuffer()}function cs(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);Qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&cs(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&cs(d,e,t,r,i,s,a)}}const du=["x","y","z"];function pu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ls(0,n,t,r,i,s);return H.clearBuffer(),a}function ls(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return $h(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=du[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ls(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ls(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Xi=new Ze,$t=new Ae,er=new Ae,kr=new je,Aa=new fe,qi=new fe;function fu(n,e,t,r){H.setBuffer(n._roots[e]);const i=hs(0,n,t,r);return H.clearBuffer(),i}function hs(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Aa.set(t.boundingBox.min,t.boundingBox.max,r),i=Aa),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(kr.copy(r).invert(),t.boundsTree)return Z(n,s,qi),qi.matrix.copy(kr),qi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>qi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y,b=g+y;m<b;m++)if(te(er,3*e.resolveTriangleIndex(m),h,u),er.needsUpdate=!0,f.intersectsTriangle(er))return!0;return!1}});for(let f=y,m=g+y;f<m;f++){const b=e.resolveTriangleIndex(f);te($t,3*b,h,u),$t.a.applyMatrix4(kr),$t.b.applyMatrix4(kr),$t.c.applyMatrix4(kr),$t.needsUpdate=!0;for(let v=0,x=d.count;v<x;v+=3)if(te(er,v,d,p),er.needsUpdate=!0,$t.intersectsTriangle(er))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Xi),!!(i.intersectsBox(Xi)&&hs(l,e,t,r,i)||(Z(h,s,Xi),i.intersectsBox(Xi)&&hs(h,e,t,r,i)))}}const Yi=new je,us=new fe,Rr=new fe,mu=new I,yu=new I,gu=new I,vu=new I;function bu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),us.set(e.boundingBox.min,e.boundingBox.max,t),us.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=mu,g=yu,f=null,m=null;i&&(f=gu,m=vu);let b=1/0,v=null,x=null;return Yi.copy(t).invert(),Rr.matrix.copy(Yi),n.shapecast({boundsTraverseOrder:_=>us.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Rr.min.copy(_.min),Rr.max.copy(_.max),Rr.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:C=>Rr.distanceToBox(C),intersectsBounds:(C,M,T)=>T<b&&T<a,intersectsRange:(C,M)=>{for(let T=C,E=C+M;T<E;T++){const P=w.resolveTriangleIndex(T);te(p,3*P,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let k=_,A=_+S;k<A;k++){const N=n.resolveTriangleIndex(k);te(d,3*N,l,c),d.needsUpdate=!0;const U=d.distanceToTriangle(p,y,f);if(U<b&&(g.copy(y),m&&m.copy(f),b=U,v=k,x=T),U<s)return!0}}}})}else{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){const P=n.resolveTriangleIndex(T);te(d,3*P,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=T,x=C),k<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Yi),g.applyMatrix4(Yi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function _u(){return typeof SharedArrayBuffer<"u"}const Ar=new H.constructor,Zi=new H.constructor,Mt=new ts(()=>new Ze),tr=new Ze,rr=new Ze,ds=new Ze,ps=new Ze;let fs=!1;function xu(n,e,t,r){if(fs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");fs=!0;const i=n._roots,s=e._roots;let a,o=0,c=0;const l=new je().copy(t).invert();for(let h=0,u=i.length;h<u;h++){Ar.setBuffer(i[h]),c=0;const d=Mt.getPrimitive();Z(0,Ar.float32Array,d),d.applyMatrix4(l);for(let p=0,y=s.length;p<y&&(Zi.setBuffer(s[p]),a=We(0,0,t,l,r,o,c,0,0,d),Zi.clearBuffer(),c+=s[p].length,!a);p++);if(Mt.releasePrimitive(d),Ar.clearBuffer(),o+=i[h].length,a)break}return fs=!1,a}function We(n,e,t,r,i,s=0,a=0,o=0,c=0,l=null,h=!1){let u,d;h?(u=Zi,d=Ar):(u=Ar,d=Zi);const p=u.float32Array,y=u.uint32Array,g=u.uint16Array,f=d.float32Array,m=d.uint32Array,b=d.uint16Array,v=n*2,x=e*2,_=we(v,g),S=we(x,b);let w=!1;if(S&&_)h?w=i(Pe(e,m),Ee(e*2,b),Pe(n,y),Ee(n*2,g),c,a+e,o,s+n):w=i(Pe(n,y),Ee(n*2,g),Pe(e,m),Ee(e*2,b),o,s+n,c,a+e);else if(S){const C=Mt.getPrimitive();Z(e,f,C),C.applyMatrix4(t);const M=ke(n),T=Re(n,y);Z(M,p,tr),Z(T,p,rr);const E=C.intersectsBox(tr),P=C.intersectsBox(rr);w=E&&We(e,M,r,t,i,a,s,c,o+1,C,!h)||P&&We(e,T,r,t,i,a,s,c,o+1,C,!h),Mt.releasePrimitive(C)}else{const C=ke(e),M=Re(e,m);Z(C,f,ds),Z(M,f,ps);const T=l.intersectsBox(ds),E=l.intersectsBox(ps);if(T&&E)w=We(n,C,t,r,i,s,a,o,c+1,l,h)||We(n,M,t,r,i,s,a,o,c+1,l,h);else if(T)if(_)w=We(n,C,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ds).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(C,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(C,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}else if(E)if(_)w=We(n,M,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ps).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(M,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(M,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}}return w}const Ki=new fe,Oa=new Ze,Su={strategy:Wn,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Ir{static serialize(e,t={}){t={cloneBuffers:!0,...t};const r=e.geometry,i=e._roots,s=e._indirectBuffer,a=r.getIndex();let o;return t.cloneBuffers?o={roots:i.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:i,index:a?a.array:null,indirectBuffer:s},o}static deserialize(e,t,r={}){r={setIndex:!0,indirect:!!e.indirectBuffer,...r};const{index:i,roots:s,indirectBuffer:a}=e,o=new Ir(t,{...r,[qn]:!0});if(o._roots=s,o._indirectBuffer=a||null,r.setIndex){const c=t.getIndex();if(c===null){const l=new Te(e.index,1,!1);t.setIndex(l)}else c.array!==i&&(c.array.set(i),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Su,[qn]:!1},t),t.useSharedArrayBuffer&&!_u())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[qn]||(Uh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Ze))),this.resolveTriangleIndex=t.indirect?r=>this._indirectBuffer[r]:r=>r}refit(e=null){return(this.indirect?hu:Kh)(this,e)}traverse(e,t=0){const r=this._roots[t],i=new Uint32Array(r),s=new Uint16Array(r);a(0);function a(o,c=0){const l=o*2,h=s[l+15]===Ii;if(h){const u=i[o+6],d=s[l+14];e(c,h,new Float32Array(r,o*4,6),u,d)}else{const u=o+Sr/4,d=i[o+6],p=i[o+7];e(c,h,new Float32Array(r,o*4,6),p)||(a(u,c+1),a(d,c+1))}}}raycast(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),h=a.groups,u=c?t.side:t,d=this.indirect?uu:tu;for(let p=0,y=s.length;p<y;p++){const g=l?t[h[p].materialIndex].side:u,f=o.length;if(d(this,p,g,e,o,r,i),l){const m=h[p].materialIndex;for(let b=f,v=o.length;b<v;b++)o[b].face.materialIndex=m}}return o}raycastFirst(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const h=a.groups,u=o?t.side:t,d=this.indirect?pu:iu;for(let p=0,y=s.length;p<y;p++){const g=c?t[h[p].materialIndex].side:u,f=d(this,p,g,e,r,i);f!=null&&(l==null||f.distance<l.distance)&&(l=f,c&&(f.face.materialIndex=h[p].materialIndex))}return l}intersectsGeometry(e,t){let r=!1;const i=this._roots,s=this.indirect?fu:nu;for(let a=0,o=i.length;a<o&&(r=s(this,a,e,t),!r);a++);return r}shapecast(e){const t=Oe.getPrimitive(),r=this.indirect?eu:Zh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const u=a;a=(d,p,y,g,f)=>u(d,p,y,g,f)?!0:r(d,p,this,o,y,g,t)}else a||(o?a=(u,d,p,y)=>r(u,d,this,o,p,y,t):a=(u,d,p)=>p);let c=!1,l=0;const h=this._roots;for(let u=0,d=h.length;u<d;u++){const p=h[u];if(c=Jh(this,u,s,a,i,l),c)break;l+=p.byteLength}return Oe.releasePrimitive(t),c}bvhcast(e,t,r){let{intersectsRanges:i,intersectsTriangles:s}=r;const a=Oe.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const g=this.resolveTriangleIndex(y);te(a,g*3,o,c)}:y=>{te(a,y*3,o,c)},h=Oe.getPrimitive(),u=e.geometry.index,d=e.geometry.attributes.position,p=e.indirect?y=>{const g=e.resolveTriangleIndex(y);te(h,g*3,u,d)}:y=>{te(h,y*3,u,d)};if(s){const y=(g,f,m,b,v,x,_,S)=>{for(let w=m,C=m+b;w<C;w++){p(w),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let M=g,T=g+f;M<T;M++)if(l(M),a.needsUpdate=!0,s(a,h,M,w,v,x,_,S))return!0}return!1};if(i){const g=i;i=function(f,m,b,v,x,_,S,w){return g(f,m,b,v,x,_,S,w)?!0:y(f,m,b,v,x,_,S,w)}}else i=y}return xu(this,e,t,i)}intersectsBox(e,t){return Ki.set(e.min,e.max,t),Ki.needsUpdate=!0,this.shapecast({intersectsBounds:r=>Ki.intersectsBox(r),intersectsTriangle:r=>Ki.intersectsTriangle(r)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,r={},i={},s=0,a=1/0){return(this.indirect?bu:lu)(this,e,t,r,i,s,a)}closestPointToPoint(e,t={},r=0,i=1/0){return Gh(this,e,t,r,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Z(0,new Float32Array(t),Oa),e.union(Oa)}),e}}function za(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Qi=new Ka,Ba=new I,Ia=new je,wu=ln.prototype.raycast,Mu=Za.prototype.raycast,Na=new I,ue=new ln,$i=[];function Tu(n,e){this.isBatchedMesh?Cu.call(this,n,e):Pu.call(this,n,e)}function Cu(n,e){if(this.boundsTrees){const t=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ue.material=this.material,ue.geometry=this.geometry;const a=ue.geometry.boundsTree,o=ue.geometry.drawRange;ue.geometry.boundingSphere===null&&(ue.geometry.boundingSphere=new Ms);for(let c=0,l=r.length;c<l;c++){if(!this.getVisibleAt(c))continue;const h=r[c].geometryIndex;if(ue.geometry.boundsTree=t[h],this.getMatrixAt(c,ue.matrixWorld).premultiply(s),!ue.geometry.boundsTree){this.getBoundingBoxAt(h,ue.geometry.boundingBox),this.getBoundingSphereAt(h,ue.geometry.boundingSphere);const u=i[h];ue.geometry.setDrawRange(u.start,u.count)}ue.raycast(n,$i);for(let u=0,d=$i.length;u<d;u++){const p=$i[u];p.object=this,p.batchId=c,e.push(p)}$i.length=0}ue.geometry.boundsTree=a,ue.geometry.drawRange=o,ue.material=null,ue.geometry=null}else Mu.call(this,n,e)}function Pu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;Ia.copy(this.matrixWorld).invert(),Qi.copy(n.ray).applyMatrix4(Ia),Na.setFromMatrixScale(this.matrixWorld),Ba.copy(Qi.direction).multiply(Na);const t=Ba.length(),r=n.near/t,i=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=za(s.raycastFirst(Qi,this.material,r,i),this,n);a&&e.push(a)}else{const a=s.raycast(Qi,this.material,r,i);for(let o=0,c=a.length;o<c;o++){const l=za(a[o],this,n);l&&e.push(l)}}}else wu.call(this,n,e)}function Eu(n={}){return this.boundsTree=new Ir(this,n),this.boundsTree}const Bt=new I,It=new I,Nt=new I,Ua=new hn,en=new I,ms=new I,Da=new hn,Fa=new hn,tn=new je,La=new je;function Or(n,e){if(!n&&!e)return;const t=n.count===e.count,r=n.normalized===e.normalized,i=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!r||!i||!s)throw new Error}function zr(n,e=null){const t=n.array.constructor,r=n.normalized,i=n.itemSize,s=e===null?n.count:e;return new Te(new t(i*s),i,r)}function Va(n,e,t=0){if(n.isInterleavedBufferAttribute){const r=n.itemSize;for(let i=0,s=n.count;i<s;i++){const a=i+t;e.setX(a,n.getX(i)),r>=2&&e.setY(a,n.getY(i)),r>=3&&e.setZ(a,n.getZ(i)),r>=4&&e.setW(a,n.getW(i))}}else{const r=e.array,i=r.constructor,s=r.BYTES_PER_ELEMENT*n.itemSize*t;new i(r.buffer,s,n.array.length).set(n.array)}}function ku(n,e,t){const r=n.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)r[s]+=i[s]*t}function ja(n,e,t){const r=n.skeleton,i=n.geometry,s=r.bones,a=r.boneInverses;Da.fromBufferAttribute(i.attributes.skinIndex,e),Fa.fromBufferAttribute(i.attributes.skinWeight,e),tn.elements.fill(0);for(let o=0;o<4;o++){const c=Fa.getComponent(o);if(c!==0){const l=Da.getComponent(o);La.multiplyMatrices(s[l].matrixWorld,a[l]),ku(tn,La,c)}}return tn.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(tn),t}function ys(n,e,t,r,i){en.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(ms.fromBufferAttribute(c,r),t?en.addScaledVector(ms,o):en.addScaledVector(ms.sub(i),o))}i.add(en)}function Ru(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new lr){const r=n[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.clearGroups();for(let h=0;h<n.length;++h){const u=n[h];let d=0;if(r!==(u.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 u.attributes){if(!o.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(u.attributes[p]),d++}if(d!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let p;if(r)p=u.index.count;else if(u.attributes.position!==void 0)p=u.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,h),l+=p}}if(r){let h=!1;if(!t.index){let u=0;for(let d=0;d<n.length;++d)u+=n[d].index.count;t.setIndex(new Te(new Uint32Array(u),1,!1)),h=!0}if(s||h){const u=t.index;let d=0,p=0;for(let y=0;y<n.length;++y){const g=n[y],f=g.index;if(a[y]!==!0)for(let m=0;m<f.count;++m)u.setX(d,f.getX(m)+p),d++;p+=g.attributes.position.count}}}for(const h in c){const u=c[h];if(!(h in t.attributes)){let y=0;for(const g in u)y+=u[g].count;t.setAttribute(h,zr(c[h][0],y))}const d=t.attributes[h];let p=0;for(let y=0,g=u.length;y<g;y++){const f=u[y];a[y]!==!0&&Va(f,d,p),p+=f.count}}return t}function Au(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,r=n.length;t<r;t++)if(n[t]!==e[t])return!1;return!0}function Ou(n){const{index:e,attributes:t}=n;if(e)for(let r=0,i=e.count;r<i;r+=3){const s=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,s)}else for(const r in t){const i=t[r],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),h=i.getComponent(a+2,c);i.setComponent(a,c,h),i.setComponent(a+2,c,l)}}return n}class zu{constructor(e){this.matrixWorld=new je,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,r=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,r){r.boneTexture||r.computeBoneTexture(),r.update();const s=r.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Au(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===r)}}class Bu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(r=>{r.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new lr),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new lr){let t=[];const{meshes:r,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=r.length;o<c;o++){const l=r[o],h=s[o],u=a.get(l);!u||u.didChange(l)?(this._convertToStaticGeometry(l,h),t.push(!1),u?u.update():a.set(l,new zu(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new Te(new Float32Array(0),4,!1))}else Ru(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new lr){const r=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=r.attributes,c=t.attributes;!t.index&&r.index&&(t.index=r.index.clone()),c.position||t.setAttribute("position",zr(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",zr(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",zr(o.tangent)),Or(r.index,t.index),Or(o.position,c.position),s&&Or(o.normal,c.normal),a&&Or(o.tangent,c.tangent);const l=o.position,h=s?o.normal:null,u=a?o.tangent:null,d=r.morphAttributes.position,p=r.morphAttributes.normal,y=r.morphAttributes.tangent,g=r.morphTargetsRelative,f=e.morphTargetInfluences,m=new Qa;m.getNormalMatrix(e.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let b=0,v=o.position.count;b<v;b++)Bt.fromBufferAttribute(l,b),h&&It.fromBufferAttribute(h,b),u&&(Ua.fromBufferAttribute(u,b),Nt.fromBufferAttribute(u,b)),f&&(d&&ys(d,f,g,b,Bt),p&&ys(p,f,g,b,It),y&&ys(y,f,g,b,Nt)),e.isSkinnedMesh&&(e.applyBoneTransform(b,Bt),h&&ja(e,b,It),u&&ja(e,b,Nt)),i&&Bt.applyMatrix4(e.matrixWorld),c.position.setXYZ(b,Bt.x,Bt.y,Bt.z),h&&(i&&It.applyNormalMatrix(m),c.normal.setXYZ(b,It.x,It.y,It.z)),u&&(i&&Nt.transformDirection(e.matrixWorld),c.tangent.setXYZW(b,Nt.x,Nt.y,Nt.z,Ua.w));for(const b in this.attributes){const v=this.attributes[b];v==="position"||v==="tangent"||v==="normal"||!(v in o)||(c[v]||t.setAttribute(v,zr(o[v])),Or(o[v],c[v]),Va(o[v],c[v]))}return e.matrixWorld.determinant()<0&&Ou(t),t}}const Iu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:ya,CENTER:Wn,CONTAINED:Hn,ExtendedTriangle:Ae,MeshBVH:Ir,OrientedBox:fe,SAH:ga,StaticGeometryGenerator:Bu,acceleratedRaycast:Tu,computeBoundsTree:Eu},Symbol.toStringTag,{value:"Module"}));class Nu{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const ze={node:"node",material:"material",camera:"camera",light:"light"},Ut="KHR_animation_pointer",Uu={CUBICSPLINE:void 0,LINEAR:Cs,STEP:ec};class Du{constructor(e){this.name=Ut,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,r=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",r)}loadAnimationTargetFromChannelWithAnimationPointer(e){Lu();const t=e.target,r=t.extensions&&t.extensions[Ut]&&t.path&&t.path==="pointer";if(!r)return null;let i,s=ze.node,a;if(r){const c=t.extensions[Ut];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=ze.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=ze.light:l.startsWith("/cameras/")&&(s=ze.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case ze.material:const h=("/materials/"+a.toString()+"/").length,u=l.substring(0,h);switch(i=l.substring(h),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=u+i;break;case ze.node:const d=("/nodes/"+a.toString()+"/").length,p=l.substring(0,d);switch(i=l.substring(d),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break}l=p+i;break;case ze.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(y),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case ze.camera:const g=("/cameras/"+a.toString()+"/").length,f=l.substring(0,g);switch(i=l.substring(g),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=f+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Ut].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===ze.node?o=this.parser.getDependency("node",a):s===ze.material?o=this.parser.getDependency("material",a):s===ze.light?o=this.parser.getDependency("light",a):s===ze.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,r,i,s){if(!(s.extensions&&s.extensions[Ut]&&s.path&&s.path==="pointer"))return null;let a=s.extensions[Ut].pointer;if(!a)return null;const o=[];a=a.replaceAll("/",".");const c=a.split(".");var l=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(c[2]=l,c[3]==="morphTargetInfluences"&&e.type==="Group"){for(const u of e.children)u instanceof $a&&u.morphTargetInfluences&&(c[3]=u.name,c[4]="morphTargetInfluences",h(this.parser));return o}h(this.parser);function h(u){a=c.join(".");let d;switch(r.itemSize){case 1:d=sc;break;case 2:case 3:d=nc;break;case 4:a.endsWith(".quaternion")?d=rc:d=ic;break}if(!d){console.warn("Unsupported output accessor format",r);return}const p=i.interpolation!==void 0?Uu[i.interpolation]:Cs;let y=u._getArrayFromAccessor(r);a.endsWith(".fov")&&(y=y.map(f=>f/Math.PI*180));const g=new d(a,t.array,y,p);if(p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(g),a&&r.itemSize===4&&a.startsWith(".materials.")&&a.endsWith(".color")){const f=new Float32Array(y.length/4);for(let b=0,v=y.length/4;b<v;b+=1)f[b]=y[b*4+3];const m=new d(a.replace(".color",".opacity"),t.array,f,p);p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(m)}}return o}_tryResolveTargetId(e,t){let r="";return t==="node"?r=e.substring(7):t==="material"?r=e.substring(11):t==="light"?r=e.substring(39):t==="camera"&&(r=e.substring(9)),r=r.substring(0,r.indexOf("/")),Number.parseInt(r)}loadAnimation(e){const t=this,r=this.parser.json,i=this.parser,s=r.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],h=[],u=[];for(let d=0,p=s.channels.length;d<p;d++){const y=s.channels[d],g=s.samplers[y.sampler],f=y.target,m=s.parameters!==void 0?s.parameters[g.input]:g.input,b=s.parameters!==void 0?s.parameters[g.output]:g.output;let v=t.loadAnimationTargetFromChannelWithAnimationPointer(y);v||(v=t.loadAnimationTargetFromChannel(y)),o.push(v),c.push(i.getDependency("accessor",m)),l.push(i.getDependency("accessor",b)),h.push(g),u.push(f)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(h),Promise.all(u)]).then(function(d){const p=d[0],y=d[1],g=d[2],f=d[3],m=d[4],b=[];for(let v=0,x=p.length;v<x;v++){const _=p[v],S=y[v],w=g[v],C=f[v],M=m[v];if(_===void 0)continue;_.updateMatrix&&(_.updateMatrix(),_.matrixAutoUpdate=!0);let T=t.createAnimationTracksWithAnimationPointer(_,S,w,C,M);if(T||(T=i._createAnimationTracks(_,S,w,C,M)),T)for(let E=0;E<T.length;E++)b.push(T[E])}return new tc(a,void 0,b)})}}let Ja=!1,Fu=null;function Lu(){if(Ja)return;Ja=!0;const n=Fu||=Ps.findNode;Ps.findNode=function(e,t){if(t.startsWith(".materials.")){const r=t.substring(11).substring(t.indexOf(".")),i=r.indexOf("."),s=i<0?r:r.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(r.endsWith(".map")?a=a.map:r.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const r=t.split(".");let i;for(let s=1;s<r.length;s++){const a=r[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const o=Number.parseInt(a);let c=a;o>=0&&(c=o),i=i[c]}else{const o=e.getObjectByName(a);o&&(i=o)}}if(!i){const s=n(e,r[2]);return s||console.warn(Ut+": Property binding not found",t,e,e.name,r),s}return i}return n(e,t)}}const Vu=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Du},Symbol.toStringTag,{value:"Module"}));export{Ho as $70d766613f57b014$export$2e2bcd8739ae039,mh as BatchedParticleRenderer,gs as Builder,Br as ByteBuffer,Ft as ConstantColor,L as ConstantValue,He as Matrix4,Ir as MeshBVH,dc as MotionController,on as ParticleSystem,R as RenderMode,ks as SIZE_PREFIX_LENGTH,Ai as TrailParticle,Me as Vector4,Nu as WorkerBase,Gc as bundler,gh as createNoise4D,ac as fetchProfile,xh as index,Iu as index$1,Vu as index$2,ol as md5,tl as v5};
1121
+ }`;class fh extends da{constructor(e){super(e),this.vector_=new z,this.vector2_=new z,this.vector3_=new z,this.quaternion_=new j,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new lr,this.indexBuffer=new Te(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(ge),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(ge),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(ge),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(ge),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(ge),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(ge),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new Te(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(ge),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new Te(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(ge),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new ir(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Gn(this.settings.material.map.channel),e.map=new Ve(this.settings.material.map),e.mapTransform=new Ve(new rt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===R.Trail)this.material=new cn({uniforms:e,defines:t,vertexShader:ph,fragmentShader:dh,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Ss,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let e=0,t=0,r=0;this.systems.forEach(i=>{for(let s=0;s<i.particleNum;s++)r+=i.particles[s].previous.length*2}),r>this.maxParticles&&this.expandBuffers(r),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;i.emitter.matrixWorld.decompose(a,s,o);const c=i.particles,l=i.particleNum,h=this.settings.uTileCount,u=this.settings.vTileCount,d=1/h,p=1/u;for(let y=0;y<l;y++){const g=c[y],f=g.uvTile%u,m=Math.floor(g.uvTile/u+.001),b=g.previous.values();let v=b.next(),x=v.value,_=x;v.done||(v=b.next());let S;v.value!==void 0?S=v.value:S=_;for(let w=0;w<g.previous.length;w++,e+=2){if(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z),i.worldSpace?(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z)):(g.parentMatrix?this.vector_.copy(_.position).applyMatrix4(g.parentMatrix):this.vector_.copy(_.position).applyMatrix4(i.emitter.matrixWorld),this.positionBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.previousBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.previousBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(g.parentMatrix?this.vector_.copy(x.position).applyMatrix4(g.parentMatrix):this.vector_.copy(x.position).applyMatrix4(i.emitter.matrixWorld),this.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.nextBuffer.setXYZ(e,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+1,S.position.x,S.position.y,S.position.z)):(g.parentMatrix?this.vector_.copy(S.position).applyMatrix4(g.parentMatrix):this.vector_.copy(S.position).applyMatrix4(i.emitter.matrixWorld),this.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,-1),this.sideBuffer.setX(e+1,1),i.worldSpace)this.widthBuffer.setX(e,_.size),this.widthBuffer.setX(e+1,_.size);else if(g.parentMatrix)this.widthBuffer.setX(e,_.size),this.widthBuffer.setX(e+1,_.size);else{const C=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,_.size*C),this.widthBuffer.setX(e+1,_.size*C)}this.uvBuffer.setXY(e,(w/g.previous.length+f)*d,(u-m-1)*p),this.uvBuffer.setXY(e+1,(w/g.previous.length+f)*d,(u-m)*p),this.colorBuffer.setXYZW(e,_.color.x,_.color.y,_.color.z,_.color.w),this.colorBuffer.setXYZW(e+1,_.color.x,_.color.y,_.color.z,_.color.w),w+1<g.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),x=_,_=S,v.done||(v=b.next(),v.value!==void 0&&(S=v.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class ui{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new Et;this._triangleIndexToArea.length=0;let r=0;if(!e.getIndex())return;const i=e.getIndex().array,s=i.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),i[a*3],i[a*3+1],i[a*3+2]),r+=t.getArea(),this._triangleIndexToArea.push(r);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new I,this._tempB=new I,this._tempC=new I,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);return}const r=this._triangleIndexToArea.length-1;let i=0,s=r;const a=Math.random()*this._triangleIndexToArea[r];for(;i+1<s;){const p=Math.floor((i+s)/2);a<this._triangleIndexToArea[p]?s=p:i=p}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],h=t.getIndex().array[i*3+1],u=t.getIndex().array[i*3+2],d=t.getAttribute("position");this._tempA.fromBufferAttribute(d,l),this._tempB.fromBufferAttribute(d,h),this._tempC.fromBufferAttribute(d,u),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new ui(t.geometries[e.geometry])}clone(){return new ui(this._geometry)}update(e,t){}}Wl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:ui,loadJSON:ui.fromJSON}],behaviors:[]});class vs extends _s{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let i=0;i<this.batches.length;i++)if(vs.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let r;switch(t.renderMode){case R.Trail:r=new fh(t);break;case R.Mesh:case R.BillBoard:case R.VerticalBillBoard:case R.HorizontalBillBoard:case R.StretchedBillBoard:r=new uh(t);break}this.depthTexture&&r.applyDepthTexture(this.depthTexture),r.addSystem(e),this.batches.push(r),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(r)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,r)=>{r.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const mh=vs;eh(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const fa=Math.sqrt(5),yh=(fa-1)/4,he=(5-fa)/20,zi=n=>Math.floor(n)|0,Bi=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 gh(n=Math.random){const e=vh(n),t=new Float64Array(e).map(a=>Bi[a%32*4]),r=new Float64Array(e).map(a=>Bi[a%32*4+1]),i=new Float64Array(e).map(a=>Bi[a%32*4+2]),s=new Float64Array(e).map(a=>Bi[a%32*4+3]);return function(a,o,c,l){let h,u,d,p,y;const g=(a+o+c+l)*yh,f=zi(a+g),m=zi(o+g),b=zi(c+g),v=zi(l+g),x=(f+m+b+v)*he,_=f-x,S=m-x,w=b-x,C=v-x,M=a-_,T=o-S,E=c-w,P=l-C;let k=0,A=0,N=0,U=0;M>T?k++:A++,M>E?k++:N++,M>P?k++:U++,T>E?A++:N++,T>P?A++:U++,E>P?N++:U++;const G=k>=3?1:0,B=A>=3?1:0,oe=N>=3?1:0,K=U>=3?1:0,re=k>=2?1:0,$=A>=2?1:0,me=N>=2?1:0,ye=U>=2?1:0,ie=k>=1?1:0,q=A>=1?1:0,W=N>=1?1:0,it=U>=1?1:0,Be=M-G+he,Xe=T-B+he,qe=E-oe+he,_e=P-K+he,Ie=M-re+2*he,xe=T-$+2*he,nt=E-me+2*he,st=P-ye+2*he,Y=M-ie+3*he,Ye=T-q+3*he,ot=E-W+3*he,Ct=P-it+3*he,at=M-1+4*he,ct=T-1+4*he,lt=E-1+4*he,ht=P-1+4*he,Ne=f&255,Ue=m&255,De=b&255,Fe=v&255;let Le=.6-M*M-T*T-E*E-P*P;if(Le<0)h=0;else{const X=Ne+e[Ue+e[De+e[Fe]]];Le*=Le,h=Le*Le*(t[X]*M+r[X]*T+i[X]*E+s[X]*P)}let V=.6-Be*Be-Xe*Xe-qe*qe-_e*_e;if(V<0)u=0;else{const X=Ne+G+e[Ue+B+e[De+oe+e[Fe+K]]];V*=V,u=V*V*(t[X]*Be+r[X]*Xe+i[X]*qe+s[X]*_e)}let or=.6-Ie*Ie-xe*xe-nt*nt-st*st;if(or<0)d=0;else{const X=Ne+re+e[Ue+$+e[De+me+e[Fe+ye]]];or*=or,d=or*or*(t[X]*Ie+r[X]*xe+i[X]*nt+s[X]*st)}let ar=.6-Y*Y-Ye*Ye-ot*ot-Ct*Ct;if(ar<0)p=0;else{const X=Ne+ie+e[Ue+q+e[De+W+e[Fe+it]]];ar*=ar,p=ar*ar*(t[X]*Y+r[X]*Ye+i[X]*ot+s[X]*Ct)}let cr=.6-at*at-ct*ct-lt*lt-ht*ht;if(cr<0)y=0;else{const X=Ne+1+e[Ue+1+e[De+1+e[Fe+1]]];cr*=cr,y=cr*cr*(t[X]*at+r[X]*ct+i[X]*lt+s[X]*ht)}return 27*(h+u+d+p+y)}}function vh(n){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class bh{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var J;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(J||(J={}));class ma{constructor(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b;this._closedByUser=!1,this.handleOpenEvent=v=>this.handleEvent(J.open,v),this.handleErrorEvent=v=>this.handleEvent(J.error,v),this.handleCloseEvent=v=>this.handleEvent(J.close,v),this.handleMessageEvent=v=>this.handleEvent(J.message,v),this._url=e,this._protocols=t,this._options={buffer:r?.buffer,retry:{maxRetries:(i=r?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=r?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=r?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=r?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(h=(l=r?.listeners)===null||l===void 0?void 0:l.close)!==null&&h!==void 0?h:[]],error:[...(d=(u=r?.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[]],message:[...(y=(p=r?.listeners)===null||p===void 0?void 0:p.message)!==null&&y!==void 0?y:[]],retry:[...(f=(g=r?.listeners)===null||g===void 0?void 0:g.retry)!==null&&f!==void 0?f:[]],reconnect:[...(b=(m=r?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&b!==void 0?b:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,r){this._options.listeners[e].push({listener:t,options:r})}removeEventListener(e,t,r){const i=s=>s.listener!==t||s.options!==r;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const r=this._options.listeners[e],i=[];r.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case J.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case J.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const r={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(J.reconnect,{detail:r});this.dispatchEvent(J.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case J.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=r=>{const i=new CustomEvent(J.retry,{detail:r});this.handleEvent(J.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class _h{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(J.open,e,t),this}onClose(e,t){return this.addListener(J.close,e,t),this}onError(e,t){return this.addListener(J.error,e,t),this}onMessage(e,t){return this.addListener(J.message,e,t),this}onRetry(e,t){return this.addListener(J.retry,e,t),this}onReconnect(e,t){return this.addListener(J.reconnect,e,t),this}build(){return new ma(this._url,this._protocols,this._options)}addListener(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b,v,x,_,S,w,C;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(d=(u=(h=this._options)===null||h===void 0?void 0:h.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[],message:(g=(y=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||y===void 0?void 0:y.message)!==null&&g!==void 0?g:[],retry:(b=(m=(f=this._options)===null||f===void 0?void 0:f.listeners)===null||m===void 0?void 0:m.retry)!==null&&b!==void 0?b:[],reconnect:(_=(x=(v=this._options)===null||v===void 0?void 0:v.listeners)===null||x===void 0?void 0:x.reconnect)!==null&&_!==void 0?_:[],[e]:[...(C=(w=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||w===void 0?void 0:w[e])!==null&&C!==void 0?C:[],{listener:t,options:r}]}}),this}}const xh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:bh,Websocket:ma,WebsocketBuilder:_h,get WebsocketEvent(){return J}},Symbol.toStringTag,{value:"Module"})),Wn=0,ya=1,ga=2,Hn=2,Xn=1.25,va=1,Sr=32,Ii=65535,Sh=Math.pow(2,-24),qn=Symbol("SKIP_GENERATION");function wh(n){return n.index?n.index.count:n.attributes.position.count}function qt(n){return wh(n)/3}function Mh(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Th(n,e){if(!n.index){const t=n.attributes.position.count,r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Mh(t,r);n.setIndex(new Te(i,1));for(let s=0;s<t;s++)i[s]=s}}function ba(n,e){const t=qt(n),r=e||n.drawRange,i=r.start/3,s=(r.start+r.count)/3,a=Math.max(0,i),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function _a(n,e){if(!n.groups||!n.groups.length)return ba(n,e);const t=[],r=new Set,i=e||n.drawRange,s=i.start/3,a=(i.start+i.count)/3;for(const c of n.groups){const l=c.start/3,h=(c.start+c.count)/3;r.add(Math.max(s,l)),r.add(Math.min(a,h))}const o=Array.from(r.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],h=o[c+1];t.push({offset:Math.floor(l),count:Math.floor(h-l)})}return t}function Ch(n,e){const t=qt(n),r=_a(n,e).sort((a,o)=>a.offset-o.offset),i=r[r.length-1];i.count=Math.min(t-i.offset,i.count);let s=0;return r.forEach(({count:a})=>s+=a),t!==s}function Yn(n,e,t,r,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,y=-1/0,g=-1/0,f=-1/0;for(let m=e*6,b=(e+t)*6;m<b;m+=6){const v=n[m+0],x=n[m+1],_=v-x,S=v+x;_<s&&(s=_),S>c&&(c=S),v<u&&(u=v),v>y&&(y=v);const w=n[m+2],C=n[m+3],M=w-C,T=w+C;M<a&&(a=M),T>l&&(l=T),w<d&&(d=w),w>g&&(g=w);const E=n[m+4],P=n[m+5],k=E-P,A=E+P;k<o&&(o=k),A>h&&(h=A),E<p&&(p=E),E>f&&(f=E)}r[0]=s,r[1]=a,r[2]=o,r[3]=c,r[4]=l,r[5]=h,i[0]=u,i[1]=d,i[2]=p,i[3]=y,i[4]=g,i[5]=f}function Ph(n,e=null,t=null,r=null){const i=n.attributes.position,s=n.index?n.index.array:null,a=qt(n),o=i.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,r=a):(c=e,t=t||0,r=r||a);const l=i.array,h=i.offset||0;let u=3;i.isInterleavedBufferAttribute&&(u=i.data.stride);const d=["getX","getY","getZ"];for(let p=t;p<t+r;p++){const y=p*3,g=p*6;let f=y+0,m=y+1,b=y+2;s&&(f=s[f],m=s[m],b=s[b]),o||(f=f*u+h,m=m*u+h,b=b*u+h);for(let v=0;v<3;v++){let x,_,S;o?(x=i[d[v]](f),_=i[d[v]](m),S=i[d[v]](b)):(x=l[f+v],_=l[m+v],S=l[b+v]);let w=x;_<w&&(w=_),S<w&&(w=S);let C=x;_>C&&(C=_),S>C&&(C=S);const M=(C-w)/2,T=v*2;c[g+T+0]=w+M,c[g+T+1]=M+(Math.abs(w)+M)*Sh}}return c}function Z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function xa(n){let e=-1,t=-1/0;for(let r=0;r<3;r++){const i=n[r+3]-n[r];i>t&&(t=i,e=r)}return e}function Sa(n,e){e.set(n)}function wa(n,e,t){let r,i;for(let s=0;s<3;s++){const a=s+3;r=n[s],i=e[s],t[s]=r<i?r:i,r=n[a],i=e[a],t[a]=r>i?r:i}}function Ni(n,e,t){for(let r=0;r<3;r++){const i=e[n+2*r],s=e[n+2*r+1],a=i-s,o=i+s;a<t[r]&&(t[r]=a),o>t[r+3]&&(t[r+3]=o)}}function wr(n){const e=n[3]-n[0],t=n[4]-n[1],r=n[5]-n[2];return 2*(e*t+t*r+r*e)}const mt=32,Eh=(n,e)=>n.candidate-e.candidate,xt=new Array(mt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ui=new Float32Array(6);function kh(n,e,t,r,i,s){let a=-1,o=0;if(s===Wn)a=xa(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===ya)a=xa(n),a!==-1&&(o=Rh(t,r,i,a));else if(s===ga){const c=wr(n);let l=Xn*i;const h=r*6,u=(r+i)*6;for(let d=0;d<3;d++){const p=e[d],y=(e[d+3]-p)/mt;if(i<mt/4){const g=[...xt];g.length=i;let f=0;for(let b=h;b<u;b+=6,f++){const v=g[f];v.candidate=t[b+2*d],v.count=0;const{bounds:x,leftCacheBounds:_,rightCacheBounds:S}=v;for(let w=0;w<3;w++)S[w]=1/0,S[w+3]=-1/0,_[w]=1/0,_[w+3]=-1/0,x[w]=1/0,x[w+3]=-1/0;Ni(b,t,x)}g.sort(Eh);let m=i;for(let b=0;b<m;b++){const v=g[b];for(;b+1<m&&g[b+1].candidate===v.candidate;)g.splice(b+1,1),m--}for(let b=h;b<u;b+=6){const v=t[b+2*d];for(let x=0;x<m;x++){const _=g[x];v>=_.candidate?Ni(b,t,_.rightCacheBounds):(Ni(b,t,_.leftCacheBounds),_.count++)}}for(let b=0;b<m;b++){const v=g[b],x=v.count,_=i-v.count,S=v.leftCacheBounds,w=v.rightCacheBounds;let C=0;x!==0&&(C=wr(S)/c);let M=0;_!==0&&(M=wr(w)/c);const T=va+Xn*(C*x+M*_);T<l&&(a=d,l=T,o=v.candidate)}}else{for(let m=0;m<mt;m++){const b=xt[m];b.count=0,b.candidate=p+y+m*y;const v=b.bounds;for(let x=0;x<3;x++)v[x]=1/0,v[x+3]=-1/0}for(let m=h;m<u;m+=6){let b=~~((t[m+2*d]-p)/y);b>=mt&&(b=mt-1);const v=xt[b];v.count++,Ni(m,t,v.bounds)}const g=xt[mt-1];Sa(g.bounds,g.rightCacheBounds);for(let m=mt-2;m>=0;m--){const b=xt[m],v=xt[m+1];wa(b.bounds,v.rightCacheBounds,b.rightCacheBounds)}let f=0;for(let m=0;m<mt-1;m++){const b=xt[m],v=b.count,x=b.bounds,_=xt[m+1].rightCacheBounds;v!==0&&(f===0?Sa(x,Ui):wa(x,Ui,Ui)),f+=v;let S=0,w=0;f!==0&&(S=wr(Ui)/c);const C=i-f;C!==0&&(w=wr(_)/c);const M=va+Xn*(S*f+w*C);M<l&&(a=d,l=M,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Rh(n,e,t,r){let i=0;for(let s=e,a=e+t;s<a;s++)i+=n[s*6+r*2];return i/t}class Zn{constructor(){this.boundingData=new Float32Array(6)}}function Ah(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let h=0;h<3;h++){let u=e[a*3+h];e[a*3+h]=e[o*3+h],e[o*3+h]=u}for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=u}a++,o--}else return a}}function Oh(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){let h=n[a];n[a]=n[o],n[o]=h;for(let u=0;u<6;u++){let d=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=d}a++,o--}else return a}}function we(n,e){return e[n+15]===65535}function Pe(n,e){return e[n+6]}function Ee(n,e){return e[n+14]}function ke(n){return n+8}function Re(n,e){return e[n+6]}function Ma(n,e){return e[n+7]}let Ta,Mr,Di,Ca;const zh=Math.pow(2,32);function Kn(n){return"count"in n?1:1+Kn(n.left)+Kn(n.right)}function Bh(n,e,t){return Ta=new Float32Array(t),Mr=new Uint32Array(t),Di=new Uint16Array(t),Ca=new Uint8Array(t),Qn(n,e)}function Qn(n,e){const t=n/4,r=n/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)Ta[t+a]=s[a];if(i)if(e.buffer){const a=e.buffer;Ca.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=Sr){const l=o/2;we(l,Di)||(Mr[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return Mr[t+6]=a,Di[r+14]=o,Di[r+15]=Ii,n+Sr}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Qn(n+Sr,a),l/4>zh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Mr[t+6]=l/4,l=Qn(l,o),Mr[t+7]=c,l}}function Ih(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,r=t>2**16,i=r?4:2,s=e?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),a=r?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Nh(n,e,t,r,i){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:h}=i,u=n._indirectBuffer,d=n.geometry,p=d.index?d.index.array:null,y=h?Oh:Ah,g=qt(d),f=new Float32Array(6);let m=!1;const b=new Zn;return Yn(e,t,r,b.boundingData,f),x(b,t,r,f),b;function v(_){l&&l(_/g)}function x(_,S,w,C=null,M=0){if(!m&&M>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),w<=o||M>=s)return v(S+w),_.offset=S,_.count=w,_;const T=kh(_.boundingData,C,e,S,w,c);if(T.axis===-1)return v(S+w),_.offset=S,_.count=w,_;const E=y(u,p,e,S,w,T);if(E===S||E===S+w)v(S+w),_.offset=S,_.count=w;else{_.splitAxis=T.axis;const P=new Zn,k=S,A=E-S;_.left=P,Yn(e,k,A,P.boundingData,f),x(P,k,A,f,M+1);const N=new Zn,U=E,G=w-A;_.right=N,Yn(e,U,G,N.boundingData,f),x(N,U,G,f,M+1)}return _}}function Uh(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Ih(t,e.useSharedArrayBuffer),Ch(t,e.range)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||Th(t,e);const r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Ph(t),s=e.indirect?ba(t,e.range):_a(t,e.range);n._roots=s.map(a=>{const o=Nh(n,i,a.offset,a.count,e),c=Kn(o),l=new r(Sr*c);return Bh(0,o,l),l})}class yt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let r=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];r=o<r?o:r,i=o>i?o:i}this.min=r,this.max=i}setFromPoints(e,t){let r=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);r=c<r?c:r,i=c>i?c:i}this.min=r,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}yt.prototype.setFromBox=function(){const n=new I;return function(e,t){const r=t.min,i=t.max;let s=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let l=0;l<=1;l++){n.x=r.x*o+i.x*(1-o),n.y=r.y*c+i.y*(1-c),n.z=r.z*l+i.z*(1-l);const h=e.dot(n);s=Math.min(h,s),a=Math.max(h,a)}this.min=s,this.max=a}}();const Dh=function(){const n=new I,e=new I,t=new I;return function(r,i,s){const a=r.start,o=n,c=i.start,l=e;t.subVectors(a,c),n.subVectors(r.end,r.start),e.subVectors(i.end,i.start);const h=t.dot(l),u=l.dot(o),d=l.dot(l),p=t.dot(o),y=o.dot(o)*d-u*u;let g,f;y!==0?g=(h*u-p*d)/y:g=0,f=(h+g*u)/d,s.x=g,s.y=f}}(),$n=function(){const n=new Jt,e=new I,t=new I;return function(r,i,s,a){Dh(r,i,n);let o=n.x,c=n.y;if(o>=0&&o<=1&&c>=0&&c<=1){r.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),r.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?r.at(0,s):r.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=r.start:l=r.end;let h;c<0?h=i.start:h=i.end;const u=e,d=t;if(r.closestPointToPoint(h,!0,e),i.closestPointToPoint(l,!0,t),u.distanceToSquared(h)<=d.distanceToSquared(l)){s.copy(u),a.copy(h);return}else{s.copy(l),a.copy(d);return}}}}(),Fh=function(){const n=new I,e=new I,t=new ws,r=new ut;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:h}=s;if(r.start=c,r.end=l,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a||(r.start=c,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a)||(r.start=l,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a))return!0;const u=s.getPlane(t);if(Math.abs(u.distanceToPoint(o))<=a){const d=u.projectPoint(o,e);if(s.containsPoint(d))return!0}return!1}}(),Lh=1e-15;function es(n){return Math.abs(n)<Lh}class Ae extends Et{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new I),this.satBounds=new Array(4).fill().map(()=>new yt),this.points=[this.a,this.b,this.c],this.sphere=new Ms,this.plane=new ws,this.needsUpdate=!0}intersectsSphere(e){return Fh(e,this)}update(){const e=this.a,t=this.b,r=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],h=a[1];l.subVectors(e,t),h.setFromPoints(l,i);const u=s[2],d=a[2];u.subVectors(t,r),d.setFromPoints(u,i);const p=s[3],y=a[3];p.subVectors(r,e),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}Ae.prototype.closestPointToSegment=function(){const n=new I,e=new I,t=new ut;return function(r,i=null,s=null){const{start:a,end:o}=r,c=this.points;let l,h=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;t.start.copy(c[u]),t.end.copy(c[d]),$n(t,r,n,e),l=n.distanceToSquared(e),l<h&&(h=l,i&&i.copy(n),s&&s.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(a)),this.closestPointToPoint(o,n),l=o.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(o)),Math.sqrt(h)}}(),Ae.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new Array(3),r=new yt,i=new yt,s=new I,a=new I,o=new I,c=new I,l=new I,h=new ut,u=new ut,d=new ut,p=new I;function y(g,f,m){const b=g.points;let v=0,x=-1;for(let _=0;_<3;_++){const{start:S,end:w}=h;S.copy(b[_]),w.copy(b[(_+1)%3]),h.delta(a);const C=es(f.distanceToPoint(S));if(es(f.normal.dot(a))&&C){m.copy(h),v=2;break}const M=f.intersectLine(h,p);if(!M&&C&&p.copy(S),(M||C)&&!es(p.distanceTo(w))){if(v<=1)(v===1?m.start:m.end).copy(p),C&&(x=v);else if(v>=2){(x===1?m.start:m.end).copy(p),v=2;break}if(v++,v===2&&x===-1)break}}return v}return function(g,f=null,m=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(n.copy(g),n.update(),g=n);const b=this.plane,v=g.plane;if(Math.abs(b.normal.dot(v.normal))>1-1e-10){const x=this.satBounds,_=this.satAxes;t[0]=g.a,t[1]=g.b,t[2]=g.c;for(let C=0;C<4;C++){const M=x[C],T=_[C];if(r.setFromPoints(T,t),M.isSeparated(r))return!1}const S=g.satBounds,w=g.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const M=S[C],T=w[C];if(r.setFromPoints(T,e),M.isSeparated(r))return!1}for(let C=0;C<4;C++){const M=_[C];for(let T=0;T<4;T++){const E=w[T];if(s.crossVectors(M,E),r.setFromPoints(s,e),i.setFromPoints(s,t),r.isSeparated(i))return!1}}return f&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const x=y(this,v,u);if(x===1&&g.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(x!==2)return!1;const _=y(g,b,d);if(_===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(_!==2)return!1;if(u.delta(o),d.delta(c),o.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=u.start.dot(o),w=u.end.dot(o),C=d.start.dot(o),M=d.end.dot(o),T=w<C,E=S<M;return S!==M&&C!==w&&T===E?!1:(f&&(l.subVectors(u.start,d.start),l.dot(o)>0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(o)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}(),Ae.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Ae.prototype.distanceToTriangle=function(){const n=new I,e=new I,t=["a","b","c"],r=new ut,i=new ut;return function(s,a=null,o=null){const c=a||o?r:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let h=0;h<3;h++){let u;const d=t[h],p=s[d];this.closestPointToPoint(p,n),u=p.distanceToSquared(n),u<l&&(l=u,a&&a.copy(n),o&&o.copy(p));const y=this[d];s.closestPointToPoint(y,n),u=y.distanceToSquared(n),u<l&&(l=u,a&&a.copy(y),o&&o.copy(n))}for(let h=0;h<3;h++){const u=t[h],d=t[(h+1)%3];r.set(this[u],this[d]);for(let p=0;p<3;p++){const y=t[p],g=t[(p+1)%3];i.set(s[y],s[g]),$n(r,i,n,e);const f=n.distanceToSquared(e);f<l&&(l=f,a&&a.copy(n),o&&o.copy(e))}}return Math.sqrt(l)}}();class fe{constructor(e,t,r){this.isOrientedBox=!0,this.min=new I,this.max=new I,this.matrix=new je,this.invMatrix=new je,this.points=new Array(8).fill().map(()=>new I),this.satAxes=new Array(3).fill().map(()=>new I),this.satBounds=new Array(3).fill().map(()=>new yt),this.alignedSatBounds=new Array(3).fill().map(()=>new yt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),r&&this.matrix.copy(r)}set(e,t,r){this.min.copy(e),this.max.copy(t),this.matrix.copy(r),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,r=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){const u=1*c|2*l|4*h,d=r[u];d.x=c?t.x:e.x,d.y=l?t.y:e.y,d.z=h?t.z:e.z,d.applyMatrix4(n)}const i=this.satBounds,s=this.satAxes,a=r[0];for(let c=0;c<3;c++){const l=s[c],h=i[c],u=1<<c,d=r[u];l.subVectors(a,d),h.setFromPoints(l,r)}const o=this.alignedSatBounds;o[0].setFromPointsField(r,"x"),o[1].setFromPointsField(r,"y"),o[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),fe.prototype.intersectsBox=function(){const n=new yt;return function(e){this.needsUpdate&&this.update();const t=e.min,r=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=r.x,a[0].isSeparated(n)||(n.min=t.y,n.max=r.y,a[1].isSeparated(n))||(n.min=t.z,n.max=r.z,a[2].isSeparated(n)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(n.setFromBox(c,e),l.isSeparated(n))return!1}return!0}}(),fe.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new yt,r=new yt,i=new I;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(n.copy(s),n.update(),s=n);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let u=0;u<3;u++){const d=a[u],p=o[u];if(t.setFromPoints(p,e),d.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,h=this.points;for(let u=0;u<3;u++){const d=c[u],p=l[u];if(t.setFromPoints(p,h),d.isSeparated(t))return!1}for(let u=0;u<3;u++){const d=o[u];for(let p=0;p<4;p++){const y=l[p];if(i.crossVectors(d,y),t.setFromPoints(i,e),r.setFromPoints(i,h),t.isSeparated(r))return!1}}return!0}}(),fe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),fe.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),fe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ut),t=new Array(12).fill().map(()=>new ut),r=new I,i=new I;return function(s,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(o||c)&&(s.getCenter(i),this.closestPointToPoint(i,r),s.closestPointToPoint(r,i),o&&o.copy(r),c&&c.copy(i)),0;const l=a*a,h=s.min,u=s.max,d=this.points;let p=1/0;for(let g=0;g<8;g++){const f=d[g];i.copy(f).clamp(h,u);const m=f.distanceToSquared(i);if(m<p&&(p=m,o&&o.copy(f),c&&c.copy(i),m<l))return Math.sqrt(m)}let y=0;for(let g=0;g<3;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){const b=(g+1)%3,v=(g+2)%3,x=f<<b|m<<v,_=1<<g|f<<b|m<<v,S=d[x],w=d[_];e[y].set(S,w);const C=n[g],M=n[b],T=n[v],E=t[y],P=E.start,k=E.end;P[C]=h[C],P[M]=f?h[M]:u[M],P[T]=m?h[T]:u[M],k[C]=u[C],k[M]=f?h[M]:u[M],k[T]=m?h[T]:u[M],y++}for(let g=0;g<=1;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){i.x=g?u.x:h.x,i.y=f?u.y:h.y,i.z=m?u.z:h.z,this.closestPointToPoint(i,r);const b=i.distanceToSquared(r);if(b<p&&(p=b,o&&o.copy(r),c&&c.copy(i),b<l))return Math.sqrt(b)}for(let g=0;g<12;g++){const f=e[g];for(let m=0;m<12;m++){const b=t[m];$n(f,b,r,i);const v=r.distanceToSquared(i);if(v<p&&(p=v,o&&o.copy(r),c&&c.copy(i),v<l))return Math.sqrt(v)}}return Math.sqrt(p)}}();class ts{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Vh extends ts{constructor(){super(()=>new Ae)}}const Oe=new Vh;class jh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=r=>{t&&e.push(t),t=r,this.float32Array=new Float32Array(r),this.uint16Array=new Uint16Array(r),this.uint32Array=new Uint32Array(r)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const H=new jh;let St,Yt;const Zt=[],Fi=new ts(()=>new Ze);function Jh(n,e,t,r,i,s){St=Fi.getPrimitive(),Yt=Fi.getPrimitive(),Zt.push(St,Yt),H.setBuffer(n._roots[e]);const a=rs(0,n.geometry,t,r,i,s);H.clearBuffer(),Fi.releasePrimitive(St),Fi.releasePrimitive(Yt),Zt.pop(),Zt.pop();const o=Zt.length;return o>0&&(Yt=Zt[o-1],St=Zt[o-2]),a}function rs(n,e,t,r,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=H;let h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);return Z(n,o,St),r(u,d,!1,a,s+n,St)}else{let u=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=ke(E),A=E*2;return Pe(E,k)},d=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=Re(E,k),A=E*2;return Pe(E,k)+Ee(A,P)};const p=ke(n),y=Re(n,l);let g=p,f=y,m,b,v,x;if(i&&(v=St,x=Yt,Z(g,o,v),Z(f,o,x),m=i(v),b=i(x),b<m)){g=y,f=p;const E=m;m=b,b=E,v=x}v||(v=St,Z(g,o,v));const _=we(g*2,c),S=t(v,_,m,a+1,s+g);let w;if(S===Hn){const E=u(g),P=d(g)-E;w=r(E,P,!0,a+1,s+g,v)}else w=S&&rs(g,e,t,r,i,s,a+1);if(w)return!0;x=Yt,Z(f,o,x);const C=we(f*2,c),M=t(x,C,b,a+1,s+f);let T;if(M===Hn){const E=u(f),P=d(f)-E;T=r(E,P,!0,a+1,s+f,x)}else T=M&&rs(f,e,t,r,i,s,a+1);return!!T}}const Tr=new I,is=new I;function Gh(n,e,t={},r=0,i=1/0){const s=r*r,a=i*i;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:h=>(Tr.copy(e).clamp(h.min,h.max),Tr.distanceToSquared(e)),intersectsBounds:(h,u,d)=>d<o&&d<a,intersectsTriangle:(h,u)=>{h.closestPointToPoint(e,Tr);const d=e.distanceToSquared(Tr);return d<o&&(is.copy(Tr),o=d,c=u),d<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(is):t.point=is.clone(),t.distance=l,t.faceIndex=c,t}const Wh=parseInt(Ya)>=169,At=new I,Ot=new I,zt=new I,Li=new Jt,Vi=new Jt,ji=new Jt,Pa=new I,Ea=new I,ka=new I,Cr=new I;function Hh(n,e,t,r,i,s,a,o){let c;if(s===qa?c=n.intersectTriangle(r,t,e,!0,i):c=n.intersectTriangle(e,t,r,s!==an,i),c===null)return null;const l=n.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Xh(n,e,t,r,i,s,a,o,c,l,h){At.fromBufferAttribute(e,s),Ot.fromBufferAttribute(e,a),zt.fromBufferAttribute(e,o);const u=Hh(n,At,Ot,zt,Cr,c,l,h);if(u){const d=new I;Et.getBarycoord(Cr,At,Ot,zt,d),r&&(Li.fromBufferAttribute(r,s),Vi.fromBufferAttribute(r,a),ji.fromBufferAttribute(r,o),u.uv=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),i&&(Li.fromBufferAttribute(i,s),Vi.fromBufferAttribute(i,a),ji.fromBufferAttribute(i,o),u.uv1=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),t&&(Pa.fromBufferAttribute(t,s),Ea.fromBufferAttribute(t,a),ka.fromBufferAttribute(t,o),u.normal=Et.getInterpolation(Cr,At,Ot,zt,Pa,Ea,ka,new I),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const p={a:s,b:a,c:o,normal:new I,materialIndex:0};Et.getNormal(At,Ot,zt,p.normal),u.face=p,u.faceIndex=s,Wh&&(u.barycoord=d)}return u}function Ji(n,e,t,r,i,s,a){const o=r*3;let c=o+0,l=o+1,h=o+2;const u=n.index;n.index&&(c=u.getX(c),l=u.getX(l),h=u.getX(h));const{position:d,normal:p,uv:y,uv1:g}=n.attributes,f=Xh(t,d,p,y,g,c,l,h,e,s,a);return f?(f.faceIndex=r,i&&i.push(f),f):null}function te(n,e,t,r){const i=n.a,s=n.b,a=n.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=r.getX(o),i.y=r.getY(o),i.z=r.getZ(o),s.x=r.getX(c),s.y=r.getY(c),s.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++)Ji(c,e,t,h,s,a,o)}function Yh(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function Zh(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=h,te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function Kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=3*f,M=3*(f+m);C<M;C++){let T=r[C];const E=i.getX(T),P=i.getY(T),k=i.getZ(T);E<b&&(b=E),E>_&&(_=E),P<v&&(v=P),P>S&&(S=P),k<x&&(x=k),k>w&&(w=k)}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function wt(n,e,t,r,i){let s,a,o,c,l,h;const u=1/t.direction.x,d=1/t.direction.y,p=1/t.direction.z,y=t.origin.x,g=t.origin.y,f=t.origin.z;let m=e[n],b=e[n+3],v=e[n+1],x=e[n+3+1],_=e[n+2],S=e[n+3+2];return u>=0?(s=(m-y)*u,a=(b-y)*u):(s=(b-y)*u,a=(m-y)*u),d>=0?(o=(v-g)*d,c=(x-g)*d):(o=(x-g)*d,c=(v-g)*d),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),p>=0?(l=(_-f)*p,h=(S-f)*p):(l=(S-f)*p,h=(_-f)*p),s>h||l>a)?!1:((l>s||s!==s)&&(s=l),(h<a||a!==a)&&(a=h),s<=i&&a>=r)}function Qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++){let d=l?l[h]:h;Ji(c,e,t,d,s,a,o)}}function $h(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,c?c[u]:u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function eu(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=t.resolveTriangleIndex(h),te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function tu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),ns(0,n,t,r,i,s,a),H.clearBuffer()}function ns(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&ns(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&ns(d,e,t,r,i,s,a)}}const ru=["x","y","z"];function iu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ss(0,n,t,r,i,s);return H.clearBuffer(),a}function ss(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return Yh(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=ru[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ss(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ss(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Gi=new Ze,Kt=new Ae,Qt=new Ae,Pr=new je,Ra=new fe,Wi=new fe;function nu(n,e,t,r){H.setBuffer(n._roots[e]);const i=os(0,n,t,r);return H.clearBuffer(),i}function os(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ra.set(t.boundingBox.min,t.boundingBox.max,r),i=Ra),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(Pr.copy(r).invert(),t.boundsTree)return Z(n,s,Wi),Wi.matrix.copy(Pr),Wi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>Wi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y*3,b=(g+y)*3;m<b;m+=3)if(te(Qt,m,h,u),Qt.needsUpdate=!0,f.intersectsTriangle(Qt))return!0;return!1}});for(let f=y*3,m=(g+y)*3;f<m;f+=3){te(Kt,f,h,u),Kt.a.applyMatrix4(Pr),Kt.b.applyMatrix4(Pr),Kt.c.applyMatrix4(Pr),Kt.needsUpdate=!0;for(let b=0,v=d.count;b<v;b+=3)if(te(Qt,b,d,p),Qt.needsUpdate=!0,Kt.intersectsTriangle(Qt))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Gi),!!(i.intersectsBox(Gi)&&os(l,e,t,r,i)||(Z(h,s,Gi),i.intersectsBox(Gi)&&os(h,e,t,r,i)))}}const Hi=new je,as=new fe,Er=new fe,su=new I,ou=new I,au=new I,cu=new I;function lu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),as.set(e.boundingBox.min,e.boundingBox.max,t),as.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=su,g=ou,f=null,m=null;i&&(f=au,m=cu);let b=1/0,v=null,x=null;return Hi.copy(t).invert(),Er.matrix.copy(Hi),n.shapecast({boundsTraverseOrder:_=>as.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Er.min.copy(_.min),Er.max.copy(_.max),Er.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>Er.distanceToBox(w),intersectsBounds:(w,C,M)=>M<b&&M<a,intersectsRange:(w,C)=>{for(let M=w,T=w+C;M<T;M++){te(p,3*M,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=_,P=_+S;E<P;E++){te(d,3*E,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=E,x=M),k<s)return!0}}}});{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){te(d,3*T,l,c),d.needsUpdate=!0;const P=d.distanceToTriangle(p,y,f);if(P<b&&(g.copy(y),m&&m.copy(f),b=P,v=T,x=C),P<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Hi),g.applyMatrix4(Hi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=f,M=f+m;C<M;C++){const T=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let P=T+E;P=r?r[P]:P;const k=i.getX(P),A=i.getY(P),N=i.getZ(P);k<b&&(b=k),k>_&&(_=k),A<v&&(v=A),A>S&&(S=A),N<x&&(x=N),N>w&&(w=N)}}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function uu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),cs(0,n,t,r,i,s,a),H.clearBuffer()}function cs(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);Qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&cs(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&cs(d,e,t,r,i,s,a)}}const du=["x","y","z"];function pu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ls(0,n,t,r,i,s);return H.clearBuffer(),a}function ls(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return $h(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=du[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ls(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ls(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Xi=new Ze,$t=new Ae,er=new Ae,kr=new je,Aa=new fe,qi=new fe;function fu(n,e,t,r){H.setBuffer(n._roots[e]);const i=hs(0,n,t,r);return H.clearBuffer(),i}function hs(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Aa.set(t.boundingBox.min,t.boundingBox.max,r),i=Aa),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(kr.copy(r).invert(),t.boundsTree)return Z(n,s,qi),qi.matrix.copy(kr),qi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>qi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y,b=g+y;m<b;m++)if(te(er,3*e.resolveTriangleIndex(m),h,u),er.needsUpdate=!0,f.intersectsTriangle(er))return!0;return!1}});for(let f=y,m=g+y;f<m;f++){const b=e.resolveTriangleIndex(f);te($t,3*b,h,u),$t.a.applyMatrix4(kr),$t.b.applyMatrix4(kr),$t.c.applyMatrix4(kr),$t.needsUpdate=!0;for(let v=0,x=d.count;v<x;v+=3)if(te(er,v,d,p),er.needsUpdate=!0,$t.intersectsTriangle(er))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Xi),!!(i.intersectsBox(Xi)&&hs(l,e,t,r,i)||(Z(h,s,Xi),i.intersectsBox(Xi)&&hs(h,e,t,r,i)))}}const Yi=new je,us=new fe,Rr=new fe,mu=new I,yu=new I,gu=new I,vu=new I;function bu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),us.set(e.boundingBox.min,e.boundingBox.max,t),us.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=mu,g=yu,f=null,m=null;i&&(f=gu,m=vu);let b=1/0,v=null,x=null;return Yi.copy(t).invert(),Rr.matrix.copy(Yi),n.shapecast({boundsTraverseOrder:_=>us.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Rr.min.copy(_.min),Rr.max.copy(_.max),Rr.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:C=>Rr.distanceToBox(C),intersectsBounds:(C,M,T)=>T<b&&T<a,intersectsRange:(C,M)=>{for(let T=C,E=C+M;T<E;T++){const P=w.resolveTriangleIndex(T);te(p,3*P,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let k=_,A=_+S;k<A;k++){const N=n.resolveTriangleIndex(k);te(d,3*N,l,c),d.needsUpdate=!0;const U=d.distanceToTriangle(p,y,f);if(U<b&&(g.copy(y),m&&m.copy(f),b=U,v=k,x=T),U<s)return!0}}}})}else{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){const P=n.resolveTriangleIndex(T);te(d,3*P,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=T,x=C),k<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Yi),g.applyMatrix4(Yi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function _u(){return typeof SharedArrayBuffer<"u"}const Ar=new H.constructor,Zi=new H.constructor,Mt=new ts(()=>new Ze),tr=new Ze,rr=new Ze,ds=new Ze,ps=new Ze;let fs=!1;function xu(n,e,t,r){if(fs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");fs=!0;const i=n._roots,s=e._roots;let a,o=0,c=0;const l=new je().copy(t).invert();for(let h=0,u=i.length;h<u;h++){Ar.setBuffer(i[h]),c=0;const d=Mt.getPrimitive();Z(0,Ar.float32Array,d),d.applyMatrix4(l);for(let p=0,y=s.length;p<y&&(Zi.setBuffer(s[p]),a=We(0,0,t,l,r,o,c,0,0,d),Zi.clearBuffer(),c+=s[p].length,!a);p++);if(Mt.releasePrimitive(d),Ar.clearBuffer(),o+=i[h].length,a)break}return fs=!1,a}function We(n,e,t,r,i,s=0,a=0,o=0,c=0,l=null,h=!1){let u,d;h?(u=Zi,d=Ar):(u=Ar,d=Zi);const p=u.float32Array,y=u.uint32Array,g=u.uint16Array,f=d.float32Array,m=d.uint32Array,b=d.uint16Array,v=n*2,x=e*2,_=we(v,g),S=we(x,b);let w=!1;if(S&&_)h?w=i(Pe(e,m),Ee(e*2,b),Pe(n,y),Ee(n*2,g),c,a+e,o,s+n):w=i(Pe(n,y),Ee(n*2,g),Pe(e,m),Ee(e*2,b),o,s+n,c,a+e);else if(S){const C=Mt.getPrimitive();Z(e,f,C),C.applyMatrix4(t);const M=ke(n),T=Re(n,y);Z(M,p,tr),Z(T,p,rr);const E=C.intersectsBox(tr),P=C.intersectsBox(rr);w=E&&We(e,M,r,t,i,a,s,c,o+1,C,!h)||P&&We(e,T,r,t,i,a,s,c,o+1,C,!h),Mt.releasePrimitive(C)}else{const C=ke(e),M=Re(e,m);Z(C,f,ds),Z(M,f,ps);const T=l.intersectsBox(ds),E=l.intersectsBox(ps);if(T&&E)w=We(n,C,t,r,i,s,a,o,c+1,l,h)||We(n,M,t,r,i,s,a,o,c+1,l,h);else if(T)if(_)w=We(n,C,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ds).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(C,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(C,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}else if(E)if(_)w=We(n,M,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ps).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(M,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(M,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}}return w}const Ki=new fe,Oa=new Ze,Su={strategy:Wn,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Ir{static serialize(e,t={}){t={cloneBuffers:!0,...t};const r=e.geometry,i=e._roots,s=e._indirectBuffer,a=r.getIndex();let o;return t.cloneBuffers?o={roots:i.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:i,index:a?a.array:null,indirectBuffer:s},o}static deserialize(e,t,r={}){r={setIndex:!0,indirect:!!e.indirectBuffer,...r};const{index:i,roots:s,indirectBuffer:a}=e,o=new Ir(t,{...r,[qn]:!0});if(o._roots=s,o._indirectBuffer=a||null,r.setIndex){const c=t.getIndex();if(c===null){const l=new Te(e.index,1,!1);t.setIndex(l)}else c.array!==i&&(c.array.set(i),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Su,[qn]:!1},t),t.useSharedArrayBuffer&&!_u())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[qn]||(Uh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Ze))),this.resolveTriangleIndex=t.indirect?r=>this._indirectBuffer[r]:r=>r}refit(e=null){return(this.indirect?hu:Kh)(this,e)}traverse(e,t=0){const r=this._roots[t],i=new Uint32Array(r),s=new Uint16Array(r);a(0);function a(o,c=0){const l=o*2,h=s[l+15]===Ii;if(h){const u=i[o+6],d=s[l+14];e(c,h,new Float32Array(r,o*4,6),u,d)}else{const u=o+Sr/4,d=i[o+6],p=i[o+7];e(c,h,new Float32Array(r,o*4,6),p)||(a(u,c+1),a(d,c+1))}}}raycast(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),h=a.groups,u=c?t.side:t,d=this.indirect?uu:tu;for(let p=0,y=s.length;p<y;p++){const g=l?t[h[p].materialIndex].side:u,f=o.length;if(d(this,p,g,e,o,r,i),l){const m=h[p].materialIndex;for(let b=f,v=o.length;b<v;b++)o[b].face.materialIndex=m}}return o}raycastFirst(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const h=a.groups,u=o?t.side:t,d=this.indirect?pu:iu;for(let p=0,y=s.length;p<y;p++){const g=c?t[h[p].materialIndex].side:u,f=d(this,p,g,e,r,i);f!=null&&(l==null||f.distance<l.distance)&&(l=f,c&&(f.face.materialIndex=h[p].materialIndex))}return l}intersectsGeometry(e,t){let r=!1;const i=this._roots,s=this.indirect?fu:nu;for(let a=0,o=i.length;a<o&&(r=s(this,a,e,t),!r);a++);return r}shapecast(e){const t=Oe.getPrimitive(),r=this.indirect?eu:Zh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const u=a;a=(d,p,y,g,f)=>u(d,p,y,g,f)?!0:r(d,p,this,o,y,g,t)}else a||(o?a=(u,d,p,y)=>r(u,d,this,o,p,y,t):a=(u,d,p)=>p);let c=!1,l=0;const h=this._roots;for(let u=0,d=h.length;u<d;u++){const p=h[u];if(c=Jh(this,u,s,a,i,l),c)break;l+=p.byteLength}return Oe.releasePrimitive(t),c}bvhcast(e,t,r){let{intersectsRanges:i,intersectsTriangles:s}=r;const a=Oe.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const g=this.resolveTriangleIndex(y);te(a,g*3,o,c)}:y=>{te(a,y*3,o,c)},h=Oe.getPrimitive(),u=e.geometry.index,d=e.geometry.attributes.position,p=e.indirect?y=>{const g=e.resolveTriangleIndex(y);te(h,g*3,u,d)}:y=>{te(h,y*3,u,d)};if(s){const y=(g,f,m,b,v,x,_,S)=>{for(let w=m,C=m+b;w<C;w++){p(w),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let M=g,T=g+f;M<T;M++)if(l(M),a.needsUpdate=!0,s(a,h,M,w,v,x,_,S))return!0}return!1};if(i){const g=i;i=function(f,m,b,v,x,_,S,w){return g(f,m,b,v,x,_,S,w)?!0:y(f,m,b,v,x,_,S,w)}}else i=y}return xu(this,e,t,i)}intersectsBox(e,t){return Ki.set(e.min,e.max,t),Ki.needsUpdate=!0,this.shapecast({intersectsBounds:r=>Ki.intersectsBox(r),intersectsTriangle:r=>Ki.intersectsTriangle(r)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,r={},i={},s=0,a=1/0){return(this.indirect?bu:lu)(this,e,t,r,i,s,a)}closestPointToPoint(e,t={},r=0,i=1/0){return Gh(this,e,t,r,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Z(0,new Float32Array(t),Oa),e.union(Oa)}),e}}function za(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Qi=new Ka,Ba=new I,Ia=new je,wu=ln.prototype.raycast,Mu=Za.prototype.raycast,Na=new I,ue=new ln,$i=[];function Tu(n,e){this.isBatchedMesh?Cu.call(this,n,e):Pu.call(this,n,e)}function Cu(n,e){if(this.boundsTrees){const t=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ue.material=this.material,ue.geometry=this.geometry;const a=ue.geometry.boundsTree,o=ue.geometry.drawRange;ue.geometry.boundingSphere===null&&(ue.geometry.boundingSphere=new Ms);for(let c=0,l=r.length;c<l;c++){if(!this.getVisibleAt(c))continue;const h=r[c].geometryIndex;if(ue.geometry.boundsTree=t[h],this.getMatrixAt(c,ue.matrixWorld).premultiply(s),!ue.geometry.boundsTree){this.getBoundingBoxAt(h,ue.geometry.boundingBox),this.getBoundingSphereAt(h,ue.geometry.boundingSphere);const u=i[h];ue.geometry.setDrawRange(u.start,u.count)}ue.raycast(n,$i);for(let u=0,d=$i.length;u<d;u++){const p=$i[u];p.object=this,p.batchId=c,e.push(p)}$i.length=0}ue.geometry.boundsTree=a,ue.geometry.drawRange=o,ue.material=null,ue.geometry=null}else Mu.call(this,n,e)}function Pu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;Ia.copy(this.matrixWorld).invert(),Qi.copy(n.ray).applyMatrix4(Ia),Na.setFromMatrixScale(this.matrixWorld),Ba.copy(Qi.direction).multiply(Na);const t=Ba.length(),r=n.near/t,i=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=za(s.raycastFirst(Qi,this.material,r,i),this,n);a&&e.push(a)}else{const a=s.raycast(Qi,this.material,r,i);for(let o=0,c=a.length;o<c;o++){const l=za(a[o],this,n);l&&e.push(l)}}}else wu.call(this,n,e)}function Eu(n={}){return this.boundsTree=new Ir(this,n),this.boundsTree}const Bt=new I,It=new I,Nt=new I,Ua=new hn,en=new I,ms=new I,Da=new hn,Fa=new hn,tn=new je,La=new je;function Or(n,e){if(!n&&!e)return;const t=n.count===e.count,r=n.normalized===e.normalized,i=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!r||!i||!s)throw new Error}function zr(n,e=null){const t=n.array.constructor,r=n.normalized,i=n.itemSize,s=e===null?n.count:e;return new Te(new t(i*s),i,r)}function Va(n,e,t=0){if(n.isInterleavedBufferAttribute){const r=n.itemSize;for(let i=0,s=n.count;i<s;i++){const a=i+t;e.setX(a,n.getX(i)),r>=2&&e.setY(a,n.getY(i)),r>=3&&e.setZ(a,n.getZ(i)),r>=4&&e.setW(a,n.getW(i))}}else{const r=e.array,i=r.constructor,s=r.BYTES_PER_ELEMENT*n.itemSize*t;new i(r.buffer,s,n.array.length).set(n.array)}}function ku(n,e,t){const r=n.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)r[s]+=i[s]*t}function ja(n,e,t){const r=n.skeleton,i=n.geometry,s=r.bones,a=r.boneInverses;Da.fromBufferAttribute(i.attributes.skinIndex,e),Fa.fromBufferAttribute(i.attributes.skinWeight,e),tn.elements.fill(0);for(let o=0;o<4;o++){const c=Fa.getComponent(o);if(c!==0){const l=Da.getComponent(o);La.multiplyMatrices(s[l].matrixWorld,a[l]),ku(tn,La,c)}}return tn.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(tn),t}function ys(n,e,t,r,i){en.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(ms.fromBufferAttribute(c,r),t?en.addScaledVector(ms,o):en.addScaledVector(ms.sub(i),o))}i.add(en)}function Ru(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new lr){const r=n[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.clearGroups();for(let h=0;h<n.length;++h){const u=n[h];let d=0;if(r!==(u.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 u.attributes){if(!o.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(u.attributes[p]),d++}if(d!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let p;if(r)p=u.index.count;else if(u.attributes.position!==void 0)p=u.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,h),l+=p}}if(r){let h=!1;if(!t.index){let u=0;for(let d=0;d<n.length;++d)u+=n[d].index.count;t.setIndex(new Te(new Uint32Array(u),1,!1)),h=!0}if(s||h){const u=t.index;let d=0,p=0;for(let y=0;y<n.length;++y){const g=n[y],f=g.index;if(a[y]!==!0)for(let m=0;m<f.count;++m)u.setX(d,f.getX(m)+p),d++;p+=g.attributes.position.count}}}for(const h in c){const u=c[h];if(!(h in t.attributes)){let y=0;for(const g in u)y+=u[g].count;t.setAttribute(h,zr(c[h][0],y))}const d=t.attributes[h];let p=0;for(let y=0,g=u.length;y<g;y++){const f=u[y];a[y]!==!0&&Va(f,d,p),p+=f.count}}return t}function Au(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,r=n.length;t<r;t++)if(n[t]!==e[t])return!1;return!0}function Ou(n){const{index:e,attributes:t}=n;if(e)for(let r=0,i=e.count;r<i;r+=3){const s=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,s)}else for(const r in t){const i=t[r],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),h=i.getComponent(a+2,c);i.setComponent(a,c,h),i.setComponent(a+2,c,l)}}return n}class zu{constructor(e){this.matrixWorld=new je,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,r=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,r){r.boneTexture||r.computeBoneTexture(),r.update();const s=r.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Au(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===r)}}class Bu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(r=>{r.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new lr),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new lr){let t=[];const{meshes:r,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=r.length;o<c;o++){const l=r[o],h=s[o],u=a.get(l);!u||u.didChange(l)?(this._convertToStaticGeometry(l,h),t.push(!1),u?u.update():a.set(l,new zu(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new Te(new Float32Array(0),4,!1))}else Ru(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new lr){const r=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=r.attributes,c=t.attributes;!t.index&&r.index&&(t.index=r.index.clone()),c.position||t.setAttribute("position",zr(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",zr(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",zr(o.tangent)),Or(r.index,t.index),Or(o.position,c.position),s&&Or(o.normal,c.normal),a&&Or(o.tangent,c.tangent);const l=o.position,h=s?o.normal:null,u=a?o.tangent:null,d=r.morphAttributes.position,p=r.morphAttributes.normal,y=r.morphAttributes.tangent,g=r.morphTargetsRelative,f=e.morphTargetInfluences,m=new Qa;m.getNormalMatrix(e.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let b=0,v=o.position.count;b<v;b++)Bt.fromBufferAttribute(l,b),h&&It.fromBufferAttribute(h,b),u&&(Ua.fromBufferAttribute(u,b),Nt.fromBufferAttribute(u,b)),f&&(d&&ys(d,f,g,b,Bt),p&&ys(p,f,g,b,It),y&&ys(y,f,g,b,Nt)),e.isSkinnedMesh&&(e.applyBoneTransform(b,Bt),h&&ja(e,b,It),u&&ja(e,b,Nt)),i&&Bt.applyMatrix4(e.matrixWorld),c.position.setXYZ(b,Bt.x,Bt.y,Bt.z),h&&(i&&It.applyNormalMatrix(m),c.normal.setXYZ(b,It.x,It.y,It.z)),u&&(i&&Nt.transformDirection(e.matrixWorld),c.tangent.setXYZW(b,Nt.x,Nt.y,Nt.z,Ua.w));for(const b in this.attributes){const v=this.attributes[b];v==="position"||v==="tangent"||v==="normal"||!(v in o)||(c[v]||t.setAttribute(v,zr(o[v])),Or(o[v],c[v]),Va(o[v],c[v]))}return e.matrixWorld.determinant()<0&&Ou(t),t}}const Iu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:ya,CENTER:Wn,CONTAINED:Hn,ExtendedTriangle:Ae,MeshBVH:Ir,OrientedBox:fe,SAH:ga,StaticGeometryGenerator:Bu,acceleratedRaycast:Tu,computeBoundsTree:Eu},Symbol.toStringTag,{value:"Module"}));class Nu{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const ze={node:"node",material:"material",camera:"camera",light:"light"},Ut="KHR_animation_pointer",Uu={CUBICSPLINE:void 0,LINEAR:Cs,STEP:ec};class Du{constructor(e){this.name=Ut,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,r=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",r)}loadAnimationTargetFromChannelWithAnimationPointer(e){Lu();const t=e.target,r=t.extensions&&t.extensions[Ut]&&t.path&&t.path==="pointer";if(!r)return null;let i,s=ze.node,a;if(r){const c=t.extensions[Ut];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=ze.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=ze.light:l.startsWith("/cameras/")&&(s=ze.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case ze.material:const h=("/materials/"+a.toString()+"/").length,u=l.substring(0,h);switch(i=l.substring(h),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=u+i;break;case ze.node:const d=("/nodes/"+a.toString()+"/").length,p=l.substring(0,d);switch(i=l.substring(d),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break}l=p+i;break;case ze.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(y),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case ze.camera:const g=("/cameras/"+a.toString()+"/").length,f=l.substring(0,g);switch(i=l.substring(g),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=f+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Ut].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===ze.node?o=this.parser.getDependency("node",a):s===ze.material?o=this.parser.getDependency("material",a):s===ze.light?o=this.parser.getDependency("light",a):s===ze.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,r,i,s){if(!(s.extensions&&s.extensions[Ut]&&s.path&&s.path==="pointer"))return null;let a=s.extensions[Ut].pointer;if(!a)return null;const o=[];a=a.replaceAll("/",".");const c=a.split(".");var l=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(c[2]=l,c[3]==="morphTargetInfluences"&&e.type==="Group"){for(const u of e.children)u instanceof $a&&u.morphTargetInfluences&&(c[3]=u.name,c[4]="morphTargetInfluences",h(this.parser));return o}h(this.parser);function h(u){a=c.join(".");let d;switch(r.itemSize){case 1:d=sc;break;case 2:case 3:d=nc;break;case 4:a.endsWith(".quaternion")?d=rc:d=ic;break}if(!d){console.warn("Unsupported output accessor format",r);return}const p=i.interpolation!==void 0?Uu[i.interpolation]:Cs;let y=u._getArrayFromAccessor(r);a.endsWith(".fov")&&(y=y.map(f=>f/Math.PI*180));const g=new d(a,t.array,y,p);if(p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(g),a&&r.itemSize===4&&a.startsWith(".materials.")&&a.endsWith(".color")){const f=new Float32Array(y.length/4);for(let b=0,v=y.length/4;b<v;b+=1)f[b]=y[b*4+3];const m=new d(a.replace(".color",".opacity"),t.array,f,p);p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(m)}}return o}_tryResolveTargetId(e,t){let r="";return t==="node"?r=e.substring(7):t==="material"?r=e.substring(11):t==="light"?r=e.substring(39):t==="camera"&&(r=e.substring(9)),r=r.substring(0,r.indexOf("/")),Number.parseInt(r)}loadAnimation(e){const t=this,r=this.parser.json,i=this.parser,s=r.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],h=[],u=[];for(let d=0,p=s.channels.length;d<p;d++){const y=s.channels[d],g=s.samplers[y.sampler],f=y.target,m=s.parameters!==void 0?s.parameters[g.input]:g.input,b=s.parameters!==void 0?s.parameters[g.output]:g.output;let v=t.loadAnimationTargetFromChannelWithAnimationPointer(y);v||(v=t.loadAnimationTargetFromChannel(y)),o.push(v),c.push(i.getDependency("accessor",m)),l.push(i.getDependency("accessor",b)),h.push(g),u.push(f)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(h),Promise.all(u)]).then(function(d){const p=d[0],y=d[1],g=d[2],f=d[3],m=d[4],b=[];for(let v=0,x=p.length;v<x;v++){const _=p[v],S=y[v],w=g[v],C=f[v],M=m[v];if(_===void 0)continue;_.updateMatrix&&(_.updateMatrix(),_.matrixAutoUpdate=!0);let T=t.createAnimationTracksWithAnimationPointer(_,S,w,C,M);if(T||(T=i._createAnimationTracks(_,S,w,C,M)),T)for(let E=0;E<T.length;E++)b.push(T[E])}return new tc(a,void 0,b)})}}let Ja=!1,Fu=null;function Lu(){if(Ja)return;Ja=!0;const n=Fu||=Ps.findNode;Ps.findNode=function(e,t){if(!t)return n(e,t);if(t.startsWith(".materials.")){const r=t.substring(11).substring(t.indexOf(".")),i=r.indexOf("."),s=i<0?r:r.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(r.endsWith(".map")?a=a.map:r.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const r=t.split(".");let i;for(let s=1;s<r.length;s++){const a=r[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const o=Number.parseInt(a);let c=a;o>=0&&(c=o),i=i[c]}else{const o=e.getObjectByName(a);o&&(i=o)}}if(!i){const s=n(e,r[2]);return s||console.warn(Ut+": Property binding not found",t,e,e.name,r),s}return i}return n(e,t)}}const Vu=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Du},Symbol.toStringTag,{value:"Module"}));export{Ho as $70d766613f57b014$export$2e2bcd8739ae039,mh as BatchedParticleRenderer,gs as Builder,Br as ByteBuffer,Ft as ConstantColor,L as ConstantValue,He as Matrix4,Ir as MeshBVH,dc as MotionController,on as ParticleSystem,R as RenderMode,ks as SIZE_PREFIX_LENGTH,Ai as TrailParticle,Me as Vector4,Nu as WorkerBase,Gc as bundler,gh as createNoise4D,ac as fetchProfile,xh as index,Iu as index$1,Vu as index$2,ol as md5,tl as v5};