@mulmoclaude/shapescript-plugin 1.3.0 → 1.4.0

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 (40) hide show
  1. package/README.md +19 -0
  2. package/dist/core/dispatch.d.ts +8 -3
  3. package/dist/core/dispatch.d.ts.map +1 -1
  4. package/dist/core/index.d.ts +5 -2
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/core/paths.d.ts +5 -0
  7. package/dist/core/paths.d.ts.map +1 -1
  8. package/dist/core-CpVzK-0i.js +53 -0
  9. package/dist/core-bcFgqR_m.cjs +1 -0
  10. package/dist/core.cjs +1 -1
  11. package/dist/core.js +4 -3
  12. package/dist/export/tool.d.ts +45 -0
  13. package/dist/export/tool.d.ts.map +1 -0
  14. package/dist/export/usdz.d.ts +17 -0
  15. package/dist/export/usdz.d.ts.map +1 -0
  16. package/dist/index.cjs +1 -1
  17. package/dist/index.js +4 -4
  18. package/dist/lang/de.d.ts.map +1 -1
  19. package/dist/lang/en.d.ts.map +1 -1
  20. package/dist/lang/es.d.ts.map +1 -1
  21. package/dist/lang/fr.d.ts.map +1 -1
  22. package/dist/lang/ja.d.ts.map +1 -1
  23. package/dist/lang/ko.d.ts.map +1 -1
  24. package/dist/lang/messages.d.ts +2 -0
  25. package/dist/lang/messages.d.ts.map +1 -1
  26. package/dist/lang/ptBR.d.ts.map +1 -1
  27. package/dist/lang/zh.d.ts.map +1 -1
  28. package/dist/render.cjs +2 -2
  29. package/dist/render.js +9 -9
  30. package/dist/samples-DPOGWslc.js +1038 -0
  31. package/dist/samples-DZNAeuSZ.cjs +210 -0
  32. package/dist/style.css +1 -1
  33. package/dist/{toThreeJS-B5LiF110.js → toThreeJS-BX_aeGdA.js} +18 -18
  34. package/dist/{toThreeJS-BOBpx5Dc.cjs → toThreeJS-XGDoVISb.cjs} +1 -1
  35. package/dist/vue/View.vue.d.ts.map +1 -1
  36. package/dist/vue.cjs +16 -16
  37. package/dist/vue.js +1760 -1716
  38. package/package.json +1 -1
  39. package/dist/samples-DHEKUNs5.cjs +0 -186
  40. package/dist/samples-SaXsqbHJ.js +0 -180
@@ -7,4 +7,4 @@ function e(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function t(t){re
7
7
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
8
8
  }`,po=`void main() {
9
9
  gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
10
- }`,mo=class extends Lr{constructor(e){super(),this.isShaderMaterial=!0,this.type=`ShaderMaterial`,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=fo,this.fragmentShader=po,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=ao(e.uniforms),this.uniformsGroups=co(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let n in this.uniforms){let r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type:`t`,value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type:`c`,value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type:`v2`,value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type:`v3`,value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type:`v4`,value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type:`m3`,value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type:`m4`,value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let e in this.extensions)this.extensions[e]===!0&&(n[e]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(let n in e.uniforms){let r=e.uniforms[n];switch(this.uniforms[n]={},r.type){case`t`:this.uniforms[n].value=t[r.value]||null;break;case`c`:this.uniforms[n].value=new Bn().setHex(r.value);break;case`v2`:this.uniforms[n].value=new q().fromArray(r.value);break;case`v3`:this.uniforms[n].value=new J().fromArray(r.value);break;case`v4`:this.uniforms[n].value=new en().fromArray(r.value);break;case`m3`:this.uniforms[n].value=new Rt().fromArray(r.value);break;case`m4`:this.uniforms[n].value=new Y().fromArray(r.value);break;default:this.uniforms[n].value=r.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(let t in e.extensions)this.extensions[t]=e.extensions[t];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}},ho=class extends mo{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type=`RawShaderMaterial`}},go=class extends Lr{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type=`MeshStandardMaterial`,this.defines={STANDARD:``},this.color=new Bn(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Bn(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new hn,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:``},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},_o=class extends Lr{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type=`MeshDepthMaterial`,this.depthPacking=Ue,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}},vo=class extends Lr{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type=`MeshDistanceMaterial`,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}};function yo(e,t){return!e||e.constructor===t?e:typeof t.BYTES_PER_ELEMENT==`number`?new t(e):Array.prototype.slice.call(e)}var bo=class{constructor(e,t,n,r){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=r===void 0?new t.constructor(n):r,this.sampleValues=t,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,n=this._cachedIndex,r=t[n],i=t[n-1];validate_interval:{seek:{let a;linear_scan:{forward_scan:if(!(e<r)){for(let a=n+2;;){if(r===void 0){if(e<i)break forward_scan;return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}if(n===a)break;if(i=r,r=t[++n],e<r)break seek}a=t.length;break linear_scan}if(!(e>=i)){let o=t[1];e<o&&(n=2,i=o);for(let a=n-2;;){if(i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===a)break;if(r=i,i=t[--n-1],e>=i)break seek}a=n,n=0;break linear_scan}break validate_interval}for(;n<a;){let r=n+a>>>1;e<t[r]?a=r:n=r+1}if(r=t[n],i=t[n-1],i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(r===void 0)return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}this._cachedIndex=n,this.intervalChanged_(n,i,r)}return this.interpolate_(n,i,e,r)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r;for(let e=0;e!==r;++e)t[e]=n[i+e];return t}interpolate_(){throw Error(`THREE.Interpolant: Call to abstract method.`)}intervalChanged_(){}},xo=class extends bo{constructor(e,t,n,r){super(e,t,n,r),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Be,endingEnd:Be}}intervalChanged_(e,t,n){let r=this.parameterPositions,i=e-2,a=e+1,o=r[i],s=r[a];if(o===void 0)switch(this.getSettings_().endingStart){case Ve:i=e,o=2*t-n;break;case He:i=r.length-2,o=t+r[i]-r[i+1];break;default:i=e,o=n}if(s===void 0)switch(this.getSettings_().endingEnd){case Ve:a=e,s=2*n-t;break;case He:a=1,s=n+r[1]-r[0];break;default:a=e-1,s=t}let c=(n-t)*.5,l=this.valueSize;this._weightPrev=c/(t-o),this._weightNext=c/(s-n),this._offsetPrev=i*l,this._offsetNext=a*l}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(n-t)/(r-t),m=p*p,h=m*p,g=-d*h+2*d*m-d*p,_=(1+d)*h+(-1.5-2*d)*m+(-.5+d)*p+1,v=(-1-f)*h+(1.5+f)*m+.5*p,y=f*h-f*m;for(let e=0;e!==o;++e)i[e]=g*a[l+e]+_*a[c+e]+v*a[s+e]+y*a[u+e];return i}},So=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=(n-t)/(r-t),u=1-l;for(let e=0;e!==o;++e)i[e]=a[c+e]*u+a[s+e]*l;return i}},Co=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e){return this.copySampleValue_(e-1)}},wo=class extends bo{interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=this.inTangents,u=this.outTangents;if(!l||!u){let e=(n-t)/(r-t),l=1-e;for(let t=0;t!==o;++t)i[t]=a[c+t]*l+a[s+t]*e;return i}let d=o*2,f=e-1;for(let p=0;p!==o;++p){let o=a[c+p],m=a[s+p],h=f*d+p*2,g=u[h],_=u[h+1],v=e*d+p*2,y=l[v],b=l[v+1],x=(n-t)/(r-t),S,C,w,T,E;for(let e=0;e<8;e++){S=x*x,C=S*x,w=1-x,T=w*w,E=T*w;let e=E*t+3*T*x*g+3*w*S*y+C*r-n;if(Math.abs(e)<1e-10)break;let i=3*T*(g-t)+6*w*x*(y-g)+3*S*(r-y);if(Math.abs(i)<1e-10)break;x-=e/i,x=Math.max(0,Math.min(1,x))}i[p]=E*o+3*T*x*_+3*w*S*b+C*m}return i}},To=class{constructor(e,t,n,r){if(e===void 0)throw Error(`THREE.KeyframeTrack: track name is undefined`);if(t===void 0||t.length===0)throw Error(`THREE.KeyframeTrack: no keyframes in track named `+e);this.name=e,this.times=yo(t,this.TimeBufferType),this.values=yo(n,this.ValueBufferType),this.setInterpolation(r||this.DefaultInterpolation)}static toJSON(e){let t=e.constructor,n;if(t.toJSON!==this.toJSON)n=t.toJSON(e);else{n={name:e.name,times:yo(e.times,Array),values:yo(e.values,Array)};let t=e.getInterpolation();t!==e.DefaultInterpolation&&(n.interpolation=t)}return n.type=e.ValueTypeName,n}InterpolantFactoryMethodDiscrete(e){return new Co(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new So(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new xo(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){let t=new wo(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.inTangents=this.settings.inTangents,t.outTangents=this.settings.outTangents),t}setInterpolation(e){let t;switch(e){case Ie:t=this.InterpolantFactoryMethodDiscrete;break;case Le:t=this.InterpolantFactoryMethodLinear;break;case Re:t=this.InterpolantFactoryMethodSmooth;break;case ze:t=this.InterpolantFactoryMethodBezier}if(t===void 0){let t=`unsupported interpolation for `+this.ValueTypeName+` keyframe track named `+this.name;if(this.createInterpolant===void 0){if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw Error(t)}return W(`KeyframeTrack:`,t),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Ie;case this.InterpolantFactoryMethodLinear:return Le;case this.InterpolantFactoryMethodSmooth:return Re;case this.InterpolantFactoryMethodBezier:return ze}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]+=e}return this}scale(e){if(e!==1){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]*=e}return this}trim(e,t){let n=this.times,r=n.length,i=0,a=r-1;for(;i!==r&&n[i]<e;)++i;for(;a!==-1&&n[a]>t;)--a;if(++a,i!==0||a!==r){i>=a&&(a=Math.max(a,1),i=a-1);let e=this.getValueSize();this.times=n.slice(i,a),this.values=this.values.slice(i*e,a*e)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(G(`KeyframeTrack: Invalid value size in track.`,this),e=!1);let n=this.times,r=this.values,i=n.length;i===0&&(G(`KeyframeTrack: Track is empty.`,this),e=!1);let a=null;for(let t=0;t!==i;t++){let r=n[t];if(typeof r==`number`&&isNaN(r)){G(`KeyframeTrack: Time is not a valid number.`,this,t,r),e=!1;break}if(a!==null&&a>r){G(`KeyframeTrack: Out of order keys.`,this,t,r,a),e=!1;break}a=r}if(r!==void 0&&$e(r))for(let t=0,n=r.length;t!==n;++t){let n=r[t];if(isNaN(n)){G(`KeyframeTrack: Value is not a valid number.`,this,t,n),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),n=this.getValueSize(),r=this.getInterpolation()===Re,i=e.length-1,a=1;for(let o=1;o<i;++o){let i=!1,s=e[o];if(s!==e[o+1]&&(o!==1||s!==e[0])){if(r)i=!0;else{let e=o*n,r=e-n,a=e+n;for(let o=0;o!==n;++o){let n=t[e+o];if(n!==t[r+o]||n!==t[a+o]){i=!0;break}}}}if(i){if(o!==a){e[a]=e[o];let r=o*n,i=a*n;for(let e=0;e!==n;++e)t[i+e]=t[r+e]}++a}}if(i>0){e[a]=e[i];for(let e=i*n,r=a*n,o=0;o!==n;++o)t[r+o]=t[e+o];++a}return a===e.length?(this.times=e,this.values=t):(this.times=e.slice(0,a),this.values=t.slice(0,a*n)),this}clone(){let e=this.times.slice(),t=this.values.slice(),n=this.constructor,r=new n(this.name,e,t);return r.createInterpolant=this.createInterpolant,r}};To.prototype.ValueTypeName=``,To.prototype.TimeBufferType=Float32Array,To.prototype.ValueBufferType=Float32Array,To.prototype.DefaultInterpolation=Le;var Eo=class extends To{constructor(e,t,n){super(e,t,n)}};Eo.prototype.ValueTypeName=`bool`,Eo.prototype.ValueBufferType=Array,Eo.prototype.DefaultInterpolation=Ie,Eo.prototype.InterpolantFactoryMethodLinear=void 0,Eo.prototype.InterpolantFactoryMethodSmooth=void 0;var Do=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Do.prototype.ValueTypeName=`color`;var Oo=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Oo.prototype.ValueTypeName=`number`;var ko=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=(n-t)/(r-t),c=e*o;for(let e=c+o;c!==e;c+=4)Ft.slerpFlat(i,0,a,c-o,a,c,s);return i}},Ao=class extends To{constructor(e,t,n,r){super(e,t,n,r)}InterpolantFactoryMethodLinear(e){return new ko(this.times,this.values,this.getValueSize(),e)}};Ao.prototype.ValueTypeName=`quaternion`,Ao.prototype.InterpolantFactoryMethodSmooth=void 0;var jo=class extends To{constructor(e,t,n){super(e,t,n)}};jo.prototype.ValueTypeName=`string`,jo.prototype.ValueBufferType=Array,jo.prototype.DefaultInterpolation=Ie,jo.prototype.InterpolantFactoryMethodLinear=void 0,jo.prototype.InterpolantFactoryMethodSmooth=void 0;var Mo=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Mo.prototype.ValueTypeName=`vector`;var No=class extends Mn{constructor(e,t=1){super(),this.isLight=!0,this.type=`Light`,this.color=new Bn(e),this.intensity=t}dispose(){this.dispatchEvent({type:`dispose`})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){let t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}},Po=new Y,Fo=new J,Io=new J,Lo=class{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new q(512,512),this.mapType=x,this.map=null,this.mapPass=null,this.matrix=new Y,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new hi,this._frameExtents=new q(1,1),this._viewportCount=1,this._viewports=[new en(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera,n=this.matrix;Fo.setFromMatrixPosition(e.matrixWorld),t.position.copy(Fo),Io.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Io),t.updateMatrixWorld(),Po.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Po,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===2001||t.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Po)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){let e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}},Ro=new J,zo=new Ft,Bo=new J,Vo=class extends Mn{constructor(){super(),this.isCamera=!0,this.type=`Camera`,this.matrixWorldInverse=new Y,this.projectionMatrix=new Y,this.projectionMatrixInverse=new Y,this.coordinateSystem=Ze,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(Ro,zo,Bo),Bo.x===1&&Bo.y===1&&Bo.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ro,zo,Bo.set(1,1,1)).invert()}updateWorldMatrix(e,t,n=!1){super.updateWorldMatrix(e,t,n),this.matrixWorld.decompose(Ro,zo,Bo),Bo.x===1&&Bo.y===1&&Bo.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ro,zo,Bo.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}},Ho=new J,Uo=new q,Wo=new q,Go=class extends Vo{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type=`PerspectiveCamera`,this.fov=e,this.zoom=1,this.near=n,this.far=r,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=ft*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(dt*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return ft*2*Math.atan(Math.tan(dt*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){Ho.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Ho.x,Ho.y).multiplyScalar(-e/Ho.z),Ho.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Ho.x,Ho.y).multiplyScalar(-e/Ho.z)}getViewSize(e,t){return this.getViewBounds(e,Uo,Wo),t.subVectors(Wo,Uo)}setViewOffset(e,t,n,r,i,a){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(dt*.5*this.fov)/this.zoom,n=2*t,r=this.aspect*n,i=-.5*r,a=this.view;if(this.view!==null&&this.view.enabled){let e=a.fullWidth,o=a.fullHeight;i+=a.offsetX*r/e,t-=a.offsetY*n/o,r*=a.width/e,n*=a.height/o}let o=this.filmOffset;o!==0&&(i+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(i,i+r,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}},Ko=class extends Vo{constructor(e=-1,t=1,n=1,r=-1,i=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type=`OrthographicCamera`,this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=r,this.near=i,this.far=a,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,r,i,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,r=(this.top+this.bottom)/2,i=n-e,a=n+e,o=r+t,s=r-t;if(this.view!==null&&this.view.enabled){let e=(this.right-this.left)/this.view.fullWidth/this.zoom,t=(this.top-this.bottom)/this.view.fullHeight/this.zoom;i+=e*this.view.offsetX,a=i+e*this.view.width,o-=t*this.view.offsetY,s=o-t*this.view.height}this.projectionMatrix.makeOrthographic(i,a,o,s,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}},qo=class extends Lo{constructor(){super(new Ko(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}},Jo=class extends No{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type=`DirectionalLight`,this.position.copy(Mn.DEFAULT_UP),this.updateMatrix(),this.target=new Mn,this.shadow=new qo}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}},Yo=class extends No{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type=`AmbientLight`}},Xo=-90,Zo=1,Qo=class extends Mn{constructor(e,t,n){super(),this.type=`CubeCamera`,this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let r=new Go(Xo,Zo,e,t);r.layers=this.layers,this.add(r);let i=new Go(Xo,Zo,e,t);i.layers=this.layers,this.add(i);let a=new Go(Xo,Zo,e,t);a.layers=this.layers,this.add(a);let o=new Go(Xo,Zo,e,t);o.layers=this.layers,this.add(o);let s=new Go(Xo,Zo,e,t);s.layers=this.layers,this.add(s);let c=new Go(Xo,Zo,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,r,i,a,o,s]=t;for(let e of t)this.remove(e);if(e===2e3)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.lookAt(-1,0,0),i.up.set(0,0,-1),i.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),s.up.set(0,1,0),s.lookAt(0,0,-1);else if(e===2001)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.lookAt(1,0,0),i.up.set(0,0,1),i.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),s.up.set(0,-1,0),s.lookAt(0,0,-1);else throw Error(`THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: `+e);for(let e of t)this.add(e),e.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[i,a,o,s,c,l]=this.children,u=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;let m=n.texture.generateMipmaps;n.texture.generateMipmaps=!1;let h=!1;h=e.isWebGLRenderer===!0?e.state.buffers.depth.getReversed():e.reversedDepthBuffer,e.setRenderTarget(n,0,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,i),e.setRenderTarget(n,1,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,2,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,3,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,4,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.generateMipmaps=m,e.setRenderTarget(n,5,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(u,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},$o=class extends Go{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}},es=`\\[\\]\\.:\\/`,ts=RegExp(`[\\[\\]\\.:\\/]`,`g`),ns=`[^\\[\\]\\.:\\/]`,rs=`[^`+es.replace(`\\.`,``)+`]`,is=`((?:WC+[\\/:])*)`.replace(`WC`,ns),as=`(WCOD+)?`.replace(`WCOD`,rs),os=`(?:\\.(WC+)(?:\\[(.+)\\])?)?`.replace(`WC`,ns),ss=`\\.(WC+)(?:\\[(.+)\\])?`.replace(`WC`,ns),cs=RegExp(`^`+is+as+os+ss+`$`),ls=[`material`,`materials`,`bones`,`map`],us=class{constructor(e,t,n){let r=n||ds.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,r)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,r=this._bindings[n];r!==void 0&&r.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let r=this._targetGroup.nCachedObjects_,i=n.length;r!==i;++r)n[r].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].unbind()}},ds=class e{constructor(t,n,r){this.path=n,this.parsedPath=r||e.parseTrackName(n),this.node=e.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,n,r){return t&&t.isAnimationObjectGroup?new e.Composite(t,n,r):new e(t,n,r)}static sanitizeNodeName(e){return e.replace(/\s/g,`_`).replace(ts,``)}static parseTrackName(e){let t=cs.exec(e);if(t===null)throw Error(`THREE.PropertyBinding: Cannot parse trackName: `+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},r=n.nodeName&&n.nodeName.lastIndexOf(`.`);if(r!==void 0&&r!==-1){let e=n.nodeName.substring(r+1);ls.indexOf(e)!==-1&&(n.nodeName=n.nodeName.substring(0,r),n.objectName=e)}if(n.propertyName===null||n.propertyName.length===0)throw Error(`THREE.PropertyBinding: can not parse propertyName from trackName: `+e);return n}static findNode(e,t){if(t===void 0||t===``||t===`.`||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let n=e.skeleton.getBoneByName(t);if(n!==void 0)return n}if(e.children){let n=function(e){for(let r=0;r<e.length;r++){let i=e[r];if(i.name===t||i.uuid===t)return i;let a=n(i.children);if(a)return a}return null},r=n(e.children);if(r)return r}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)e[t++]=n[r]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++]}_setValue_array_setNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let t=this.node,n=this.parsedPath,r=n.objectName,i=n.propertyName,a=n.propertyIndex;if(t||(t=e.findNode(this.rootNode,n.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){W(`PropertyBinding: No target node found for track: `+this.path+`.`);return}if(r){let e=n.objectIndex;switch(r){case`materials`:if(!t.material){G(`PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.materials){G(`PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.`,this);return}t=t.material.materials;break;case`bones`:if(!t.skeleton){G(`PropertyBinding: Can not bind to bones as node does not have a skeleton.`,this);return}t=t.skeleton.bones;for(let n=0;n<t.length;n++)if(t[n].name===e){e=n;break}break;case`map`:if(`map`in t){t=t.map;break}if(!t.material){G(`PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.map){G(`PropertyBinding: Can not bind to material.map as node.material does not have a map.`,this);return}t=t.material.map;break;default:if(t[r]===void 0){G(`PropertyBinding: Can not bind to objectName of node undefined.`,this);return}t=t[r]}if(e!==void 0){if(t[e]===void 0){G(`PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.`,this,t);return}t=t[e]}}let o=t[i];if(o===void 0){let e=n.nodeName;G(`PropertyBinding: Trying to update property for track: `+e+`.`+i+` but it wasn't found.`,t);return}let s=this.Versioning.None;this.targetObject=t,t.isMaterial===!0?s=this.Versioning.NeedsUpdate:t.isObject3D===!0&&(s=this.Versioning.MatrixWorldNeedsUpdate);let c=this.BindingType.Direct;if(a!==void 0){if(i===`morphTargetInfluences`){if(!t.geometry){G(`PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.`,this);return}if(!t.geometry.morphAttributes){G(`PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.`,this);return}t.morphTargetDictionary[a]!==void 0&&(a=t.morphTargetDictionary[a])}c=this.BindingType.ArrayElement,this.resolvedProperty=o,this.propertyIndex=a}else o.fromArray!==void 0&&o.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=o):Array.isArray(o)?(c=this.BindingType.EntireArray,this.resolvedProperty=o):this.propertyName=i;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][s]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};ds.Composite=us,ds.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},ds.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},ds.prototype.GetterByBindingType=[ds.prototype._getValue_direct,ds.prototype._getValue_array,ds.prototype._getValue_arrayElement,ds.prototype._getValue_toArray],ds.prototype.SetterByBindingTypeAndVersioning=[[ds.prototype._setValue_direct,ds.prototype._setValue_direct_setNeedsUpdate,ds.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_array,ds.prototype._setValue_array_setNeedsUpdate,ds.prototype._setValue_array_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_arrayElement,ds.prototype._setValue_arrayElement_setNeedsUpdate,ds.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_fromArray,ds.prototype._setValue_fromArray_setNeedsUpdate,ds.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var fs=class{constructor(e=1,t=0,n=0){this.radius=e,this.phi=t,this.theta=n}set(e,t,n){return this.radius=e,this.phi=t,this.theta=n,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){let e=1e-6;return this.phi=K(this.phi,e,Math.PI-e),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,n){return this.radius=Math.sqrt(e*e+t*t+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,n),this.phi=Math.acos(K(t/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}};(class e{static{e.prototype.isMatrix2=!0}constructor(e,t,n,r){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,n,r)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let n=0;n<4;n++)this.elements[n]=e[n+t];return this}set(e,t,n,r){let i=this.elements;return i[0]=e,i[2]=t,i[1]=n,i[3]=r,this}});var ps=new J,ms=new J,hs=new J,gs=new J,_s=new J,vs=new J,ys=new J,bs=class{constructor(e=new J,t=new J){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){ps.subVectors(e,this.start),ms.subVectors(this.end,this.start);let n=ms.dot(ms);if(n===0)return 0;let r=ms.dot(ps)/n;return t&&(r=K(r,0,1)),r}closestPointToPoint(e,t,n){let r=this.closestPointToPointParameter(e,t);return this.delta(n).multiplyScalar(r).add(this.start)}distanceSqToLine3(e,t=vs,n=ys){let r=1e-8*1e-8,i,a,o=this.start,s=e.start,c=this.end,l=e.end;hs.subVectors(c,o),gs.subVectors(l,s),_s.subVectors(o,s);let u=hs.dot(hs),d=gs.dot(gs),f=gs.dot(_s);if(u<=r&&d<=r)return t.copy(o),n.copy(s),t.sub(n),t.dot(t);if(u<=r)i=0,a=f/d,a=K(a,0,1);else{let e=hs.dot(_s);if(d<=r)a=0,i=K(-e/u,0,1);else{let t=hs.dot(gs),n=u*d-t*t;i=n===0?0:K((t*f-e*d)/n,0,1),a=(t*i+f)/d,a<0?(a=0,i=K(-e/u,0,1)):a>1&&(a=1,i=K((t-e)/u,0,1))}}return t.copy(o).addScaledVector(hs,i),n.copy(s).addScaledVector(gs,a),t.distanceToSquared(n)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},xs=class extends Oi{constructor(e=10,t=10,n=4473924,r=8947848){n=new Bn(n),r=new Bn(r);let i=t/2,a=e/t,o=e/2,s=[],c=[];for(let e=0,l=0,u=-o;e<=t;e++,u+=a){s.push(-o,0,u,o,0,u),s.push(u,0,-o,u,0,o);let t=e===i?n:r;t.toArray(c,l),l+=3,t.toArray(c,l),l+=3,t.toArray(c,l),l+=3,t.toArray(c,l),l+=3}let l=new Fr;l.setAttribute(`position`,new X(s,3)),l.setAttribute(`color`,new X(c,3));let u=new gi({vertexColors:!0,toneMapped:!1});super(l,u),this.type=`GridHelper`}dispose(){this.geometry.dispose(),this.material.dispose()}},Ss=class extends ct{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(e){if(e===void 0){W(`Controls: connect() now requires an element.`);return}this.domElement!==null&&this.disconnect(),this.domElement=e}disconnect(){}dispose(){}update(){}};function Cs(e,t,n,r){let i=ws(r);switch(n){case ee:return e*t;case R:return e*t/i.components*i.byteLength;case te:return e*t/i.components*i.byteLength;case z:return e*t*2/i.components*i.byteLength;case B:return e*t*2/i.components*i.byteLength;case P:return e*t*3/i.components*i.byteLength;case F:return e*t*4/i.components*i.byteLength;case V:return e*t*4/i.components*i.byteLength;case H:case U:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case ne:case re:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case ae:case se:return Math.max(e,16)*Math.max(t,8)/4;case ie:case oe:return Math.max(e,8)*Math.max(t,8)/2;case ce:case le:case de:case fe:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case ue:case pe:case me:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case he:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case ge:return Math.floor((e+4)/5)*Math.floor((t+3)/4)*16;case _e:return Math.floor((e+4)/5)*Math.floor((t+4)/5)*16;case ve:return Math.floor((e+5)/6)*Math.floor((t+4)/5)*16;case ye:return Math.floor((e+5)/6)*Math.floor((t+5)/6)*16;case be:return Math.floor((e+7)/8)*Math.floor((t+4)/5)*16;case xe:return Math.floor((e+7)/8)*Math.floor((t+5)/6)*16;case Se:return Math.floor((e+7)/8)*Math.floor((t+7)/8)*16;case Ce:return Math.floor((e+9)/10)*Math.floor((t+4)/5)*16;case we:return Math.floor((e+9)/10)*Math.floor((t+5)/6)*16;case Te:return Math.floor((e+9)/10)*Math.floor((t+7)/8)*16;case Ee:return Math.floor((e+9)/10)*Math.floor((t+9)/10)*16;case De:return Math.floor((e+11)/12)*Math.floor((t+9)/10)*16;case Oe:return Math.floor((e+11)/12)*Math.floor((t+11)/12)*16;case ke:case Ae:case je:return Math.ceil(e/4)*Math.ceil(t/4)*16;case Me:case Ne:return Math.ceil(e/4)*Math.ceil(t/4)*8;case Pe:case Fe:return Math.ceil(e/4)*Math.ceil(t/4)*16}throw Error(`Unable to determine texture byte length for ${n} format.`)}function ws(e){switch(e){case x:case S:return{byteLength:1,components:1};case w:case C:case O:return{byteLength:2,components:1};case k:case A:return{byteLength:2,components:4};case E:case T:case D:return{byteLength:4,components:1};case M:case N:return{byteLength:4,components:3}}throw Error(`THREE.TextureUtils: Unknown texture type ${e}.`)}typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`register`,{detail:{revision:`185`}})),typeof window<`u`&&(window.__THREE__?W(`WARNING: Multiple instances of Three.js being imported.`):window.__THREE__=`185`);var Ts=0,Es=1,Ds=new J,Os=new bs,ks=new di,As=new J,js=new nr,Ms=class{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new Is,this.unassigned=new Is,this.vertices=[]}setFromPoints(e){if(e.length>=4){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.vertices.push(new Fs(e[t]));this._compute()}return this}setFromObject(e){let t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){let n=e.geometry;if(n!==void 0){let r=n.attributes.position;if(r!==void 0)for(let n=0,i=r.count;n<i;n++){let i=new J;i.fromBufferAttribute(r,n).applyMatrix4(e.matrixWorld),t.push(i)}}}),this.setFromPoints(t)}containsPoint(e){let t=this.faces;for(let n=0,r=t.length;n<r;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0}intersectRay(e,t){let n=this.faces,r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t],o=a.distanceToPoint(e.origin),s=a.normal.dot(e.direction);if(o>0&&s>=0)return null;let c=s===0?0:-o/s;if(!(c<=0)&&(s>0?i=Math.min(c,i):r=Math.max(c,r),r>i))return null}return r===-1/0?e.at(i,t):e.at(r,t),t}intersectsRay(e){return this.intersectRay(e,Ds)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}_addVertexToFace(e,t){return e.face=t,t.outside===null?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this}_removeVertexFromFace(e,t){return e===t.outside&&(t.outside=e.next!==null&&e.next.face===t?e.next:null),this.assigned.remove(e),this}_removeAllVerticesFromFace(e){if(e.outside!==null){let t=e.outside,n=e.outside;for(;n.next!==null&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}}_deleteFaceVertices(e,t){let n=this._removeAllVerticesFromFace(e);if(n!==void 0){if(t===void 0)this.unassigned.appendChain(n);else{let e=n;do{let n=e.next;t.distanceToPoint(e.point)>this.tolerance?this._addVertexToFace(e,t):this.unassigned.append(e),e=n}while(e!==null)}}return this}_resolveUnassignedPoints(e){if(this.unassigned.isEmpty()===!1){let t=this.unassigned.first();do{let n=t.next,r=this.tolerance,i=null;for(let n=0;n<e.length;n++){let a=e[n];if(a.mark===Ts){let e=a.distanceToPoint(t.point);if(e>r&&(r=e,i=a),r>1e3*this.tolerance)break}}i!==null&&this._addVertexToFace(t,i),t=n}while(t!==null)}return this}_computeExtremes(){let e=new J,t=new J,n=[],r=[];for(let e=0;e<3;e++)n[e]=r[e]=this.vertices[0];e.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let i=0,a=this.vertices.length;i<a;i++){let a=this.vertices[i],o=a.point;for(let t=0;t<3;t++)o.getComponent(t)<e.getComponent(t)&&(e.setComponent(t,o.getComponent(t)),n[t]=a);for(let e=0;e<3;e++)o.getComponent(e)>t.getComponent(e)&&(t.setComponent(e,o.getComponent(e)),r[e]=a)}return this.tolerance=3*2**-52*(Math.max(Math.abs(e.x),Math.abs(t.x))+Math.max(Math.abs(e.y),Math.abs(t.y))+Math.max(Math.abs(e.z),Math.abs(t.z))),{min:n,max:r}}_computeInitialHull(){let e=this.vertices,t=this._computeExtremes(),n=t.min,r=t.max,i=0,a=0;for(let e=0;e<3;e++){let t=r[e].point.getComponent(e)-n[e].point.getComponent(e);t>i&&(i=t,a=e)}let o=n[a],s=r[a],c,l;i=0,Os.set(o.point,s.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s){Os.closestPointToPoint(n.point,!0,As);let e=As.distanceToSquared(n.point);e>i&&(i=e,c=n)}}i=-1,ks.setFromCoplanarPoints(o.point,s.point,c.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c){let e=Math.abs(ks.distanceToPoint(n.point));e>i&&(i=e,l=n)}}let u=[];if(ks.distanceToPoint(l.point)<0){u.push(Ns.create(o,s,c),Ns.create(l,s,o),Ns.create(l,c,s),Ns.create(l,o,c));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge(t)),u[e+1].getEdge(1).setTwin(u[t+1].getEdge(0))}}else{u.push(Ns.create(o,c,s),Ns.create(l,o,s),Ns.create(l,s,c),Ns.create(l,c,o));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge((3-e)%3)),u[e+1].getEdge(0).setTwin(u[t+1].getEdge(1))}}for(let e=0;e<4;e++)this.faces.push(u[e]);for(let t=0,n=e.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c&&n!==l){i=this.tolerance;let e=null;for(let t=0;t<4;t++){let r=this.faces[t].distanceToPoint(n.point);r>i&&(i=r,e=this.faces[t])}e!==null&&this._addVertexToFace(n,e)}}return this}_reindexFaces(){let e=[];for(let t=0;t<this.faces.length;t++){let n=this.faces[t];n.mark===Ts&&e.push(n)}return this.faces=e,this}_nextVertexToAdd(){if(this.assigned.isEmpty()===!1){let e,t=0,n=this.assigned.first().face,r=n.outside;do{let i=n.distanceToPoint(r.point);i>t&&(t=i,e=r),r=r.next}while(r!==null&&r.face===n);return e}}_computeHorizon(e,t,n,r){this._deleteFaceVertices(n),n.mark=Es;let i;i=t===null?t=n.getEdge(0):t.next;do{let t=i.twin,n=t.face;n.mark===Ts&&(n.distanceToPoint(e)>this.tolerance?this._computeHorizon(e,t,n,r):r.push(i)),i=i.next}while(i!==t);return this}_addAdjoiningFace(e,t){let n=Ns.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)}_addNewFaces(e,t){this.newFaces=[];let n=null,r=null;for(let i=0;i<t.length;i++){let a=t[i],o=this._addAdjoiningFace(e,a);n===null?n=o:o.next.setTwin(r),this.newFaces.push(o.face),r=o}return n.next.setTwin(r),this}_addVertexToHull(e){let t=[];return this.unassigned.clear(),this._removeVertexFromFace(e,e.face),this._computeHorizon(e.point,null,e.face,t),this._addNewFaces(e,t),this._resolveUnassignedPoints(this.newFaces),this}_cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}_compute(){let e;for(this._computeInitialHull();(e=this._nextVertexToAdd())!==void 0;)this._addVertexToHull(e);return this._reindexFaces(),this._cleanup(),this}},Ns=class e{constructor(){this.normal=new J,this.midpoint=new J,this.area=0,this.constant=0,this.outside=null,this.mark=Ts,this.edge=null}static create(t,n,r){let i=new e,a=new Ps(t,i),o=new Ps(n,i),s=new Ps(r,i);return a.next=s.prev=o,o.next=a.prev=s,s.next=o.prev=a,i.edge=a,i.compute()}getEdge(e){let t=this.edge;for(;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t}compute(){let e=this.edge.tail(),t=this.edge.head(),n=this.edge.next.head();return js.set(e.point,t.point,n.point),js.getNormal(this.normal),js.getMidpoint(this.midpoint),this.area=js.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(e){return this.normal.dot(e)-this.constant}},Ps=class{constructor(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceTo(e.point)}lengthSquared(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceToSquared(e.point)}setTwin(e){return this.twin=e,e.twin=this,this}},Fs=class{constructor(e){this.point=e,this.prev=null,this.next=null,this.face=null}},Is=class{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(e,t){return t.prev=e.prev,t.next=e,t.prev===null?this.head=t:t.prev.next=t,e.prev=t,this}insertAfter(e,t){return t.prev=e,t.next=e.next,t.next===null?this.tail=t:t.next.prev=t,e.next=t,this}append(e){return this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this}appendChain(e){for(this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail;e.next!==null;)e=e.next;return this.tail=e,this}remove(e){return e.prev===null?this.head=e.next:e.prev.next=e.next,e.next===null?this.tail=e.prev:e.next.prev=e.prev,this}removeSubList(e,t){return e.prev===null?this.head=t.next:e.prev.next=t.next,t.next===null?this.tail=e.prev:t.next.prev=e.prev,this}isEmpty(){return this.head===null}},Ls=class extends Fr{constructor(e=[]){super();let t=[],n=[],r=new Ms().setFromPoints(e).faces;for(let e=0;e<r.length;e++){let i=r[e],a=i.edge;do{let e=a.head().point;t.push(e.x,e.y,e.z),n.push(i.normal.x,i.normal.y,i.normal.z),a=a.next}while(a!==i.edge)}this.setAttribute(`position`,new X(t,3)),this.setAttribute(`normal`,new X(n,3))}};function Rs(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new Fr,l=0;for(let u=0;u<e.length;++u){let d=e[u],f=0;if(n!==(d.index!==null))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`),null;for(let e in d.attributes){if(!r.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`),null;a[e]===void 0&&(a[e]=[]),a[e].push(d.attributes[e]),f++}if(f!==r.size)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. Make sure all geometries have the same number of attributes.`),null;if(s!==d.morphTargetsRelative)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. .morphTargetsRelative must be consistent throughout all geometries.`),null;for(let e in d.morphAttributes){if(!i.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. .morphAttributes must be consistent throughout all geometries.`),null;o[e]===void 0&&(o[e]=[]),o[e].push(d.morphAttributes[e])}if(t){let e;if(n)e=d.index.count;else if(d.attributes.position!==void 0)e=d.attributes.position.count;else return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. The geometry must have either an index or a position attribute`),null;c.addGroup(l,e,u),l+=e}}if(n){let t=0,n=[];for(let r=0;r<e.length;++r){let i=e[r].index;for(let e=0;e<i.count;++e)n.push(i.getX(e)+t);t+=e[r].attributes.position.count}c.setIndex(n)}for(let e in a){let t=zs(a[e]);if(!t)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` attribute.`),null;c.setAttribute(e,t)}for(let e in o){let t=o[e][0].length;if(t!==0){c.morphAttributes=c.morphAttributes||{},c.morphAttributes[e]=[];for(let n=0;n<t;++n){let t=[];for(let r=0;r<o[e].length;++r)t.push(o[e][r][n]);let r=zs(t);if(!r)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` morphAttribute.`),null;c.morphAttributes[e].push(r)}}}return c}function zs(e){let t,n,r,i=-1,a=0;for(let o=0;o<e.length;++o){let s=e[o];if(t===void 0&&(t=s.array.constructor),t!==s.array.constructor)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.`),null;if(n===void 0&&(n=s.itemSize),n!==s.itemSize)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.`),null;if(r===void 0&&(r=s.normalized),r!==s.normalized)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.`),null;if(i===-1&&(i=s.gpuType),i!==s.gpuType)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.`),null;a+=s.count*n}let o=new t(a),s=new xr(o,n,r),c=0;for(let t=0;t<e.length;++t){let r=e[t];if(r.isInterleavedBufferAttribute){let e=c/n;for(let t=0,i=r.count;t<i;t++)for(let i=0;i<n;i++){let n=r.getComponent(t,i);s.setComponent(t+e,i,n)}}else o.set(r.array,c);c+=r.count*n}return i!==void 0&&(s.gpuType=i),s}function Bs(e){e.updateWorldMatrix(!0,!1);let t=e.geometry.getAttribute(`position`),n=e.geometry.index,r=[],i=[],a=new Map;for(let n=0;n<t.count;n++){let o=new J().fromBufferAttribute(t,n).applyMatrix4(e.matrixWorld),s=o.toArray().map(e=>Math.round(e*1e6)).join(`,`),c=a.get(s);c===void 0&&(c=r.length,a.set(s,c),r.push(o)),i.push(c)}let o=new Map,s=n?.count??t.count;for(let e=0;e<s;e+=3){let t=[0,1,2].map(t=>i[n?n.getX(e+t):e+t]);for(let e=0;e<3;e++){let n=t[e],r=t[(e+1)%3];if(n===r)continue;let i=n<r?`${n},${r}`:`${r},${n}`,a=o.get(i);a?a.count++:o.set(i,{a:n,b:r,count:1})}}let c=[...o.values()].filter(e=>e.count===1);if(c.length<3)throw Error(`Loft/extrude/fill requires planar profiles with a closed perimeter`);let l=new Map(c.map(({a:e,b:t})=>[e,t])),u=c[0].a,d=u,f=[];do{f.push(r[d]);let e=l.get(d);if(e===void 0||f.length>c.length)throw Error(`Profile perimeter is not a simple closed loop`);d=e}while(d!==u);if(f.length!==c.length)throw Error(`Profiles with holes or multiple perimeters are not supported by this builder`);return f}function Vs(e,t){if(e.length===t)return e.map(e=>e.clone());let n=e.map((t,n)=>t.distanceTo(e[(n+1)%e.length])),r=n.reduce((e,t)=>e+t,0);if(r<1e-10)throw Error(`Loft profile has zero perimeter`);let i=0,a=0;return Array.from({length:t},(o,s)=>{let c=r*s/t;for(;i<n.length-1&&a+n[i]<c;)a+=n[i++];return e[i].clone().lerp(e[(i+1)%e.length],(c-a)/(n[i]||1))})}function Hs(e){let t=new J;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t.x+=(r.y-i.y)*(r.z+i.z),t.y+=(r.z-i.z)*(r.x+i.x),t.z+=(r.x-i.x)*(r.y+i.y)}return t}function Us(e){for(let t=1;t<e.length;t++)Hs(e[t]).dot(Hs(e[t-1]))<0&&e[t].reverse()}function Ws(e){if(e.length<2)throw Error(`Loft requires at least two cross-sections`);let t=Math.max(...e.map(e=>e.length)),n=e.map(e=>Vs(e,t));Us(n);let r=[];for(let e=0;e<n.length-1;e++)for(let n=0;n<t;n++){let i=e*t+n,a=e*t+(n+1)%t;r.push(i,a,a+t,i,a+t,i+t)}for(let e of[0,n.length-1]){let i=n[e],a=i[0],o=i[1].clone().sub(a).normalize(),s=new J;for(let e=2;e<t&&s.lengthSq()<1e-12;e++)s.crossVectors(o,i[e].clone().sub(a));if(s.lengthSq()<1e-12)throw Error(`Loft profile is degenerate`);s.normalize();let c=s.clone().cross(o),l=i.map(e=>{let t=e.clone().sub(a);if(Math.abs(t.dot(s))>1e-5)throw Error(`Loft cross-sections must be planar`);return new q(t.dot(o),t.dot(c))});for(let[n,i,a]of qa.triangulateShape(l,[])){let o=e*t;e===0?r.push(o+a,o+i,o+n):r.push(o+n,o+i,o+a)}}let i=new Fr;i.setAttribute(`position`,new X(n.flatMap(e=>e.flatMap(e=>e.toArray())),3)),i.setAttribute(`uv`,new X(n.flatMap((e,r)=>Array.from({length:t},(e,i)=>[i/t,r/(n.length-1)]).flat()),2)),i.setIndex(r);let a=i.getAttribute(`position`),o=0;for(let e=0;e<r.length;e+=3){let t=new J().fromBufferAttribute(a,r[e]),n=new J().fromBufferAttribute(a,r[e+1]),i=new J().fromBufferAttribute(a,r[e+2]);o+=t.dot(n.cross(i))}if(Math.abs(o)<1e-10)throw i.dispose(),Error(`Loft cross-sections enclose no volume`);if(o<0){for(let e=0;e<r.length;e+=3)[r[e+1],r[e+2]]=[r[e+2],r[e+1]];i.setIndex(r)}return i.computeVertexNormals(),i}var Gs=1.25,Ks=65535,qs=2**-24,Js=Symbol(`SKIP_GENERATION`),Ys={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Js]:!1};function Xs(e,t,n){return n.min.x=t[e],n.min.y=t[e+1],n.min.z=t[e+2],n.max.x=t[e+3],n.max.y=t[e+4],n.max.z=t[e+5],n}function Zs(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){let i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Qs(e,t){t.set(e)}function $s(e,t,n){let r,i;for(let a=0;a<3;a++){let o=a+3;r=e[a],i=t[a],n[a]=r<i?r:i,r=e[o],i=t[o],n[o]=r>i?r:i}}function ec(e,t,n){for(let r=0;r<3;r++){let i=t[e+2*r],a=t[e+2*r+1],o=i-a,s=i+a;o<n[r]&&(n[r]=o),s>n[r+3]&&(n[r+3]=s)}}function tc(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function nc(e,t){return t[e+15]===Ks}function rc(e,t){return t[e+6]}function ic(e,t){return t[e+14]}function ac(e){return e+8}function oc(e,t){return e+t[e+6]*8}function sc(e,t){return t[e+7]}function cc(e){return e}function lc(e,t,n,r,i){let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,g=-1/0,_=e.offset||0;for(let r=(t-_)*6,i=(t+n-_)*6;r<i;r+=6){let t=e[r+0],n=e[r+1],i=t-n,_=t+n;i<a&&(a=i),_>c&&(c=_),t<d&&(d=t),t>m&&(m=t);let v=e[r+2],y=e[r+3],b=v-y,x=v+y;b<o&&(o=b),x>l&&(l=x),v<f&&(f=v),v>h&&(h=v);let S=e[r+4],C=e[r+5],w=S-C,T=S+C;w<s&&(s=w),T>u&&(u=T),S<p&&(p=S),S>g&&(g=S)}r[0]=a,r[1]=o,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=d,i[1]=f,i[2]=p,i[3]=m,i[4]=h,i[5]=g}var uc=32,dc=(e,t)=>e.candidate-t.candidate,fc=Array(uc).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),pc=new Float32Array(6);function mc(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Zs(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Zs(e),o!==-1&&(s=hc(n,r,i,o));else if(a===2){let a=tc(e),c=Gs*i,l=n.offset||0,u=(r-l)*6,d=(r+i-l)*6;for(let e=0;e<3;e++){let r=t[e],l=(t[e+3]-r)/uc;if(i<uc/4){let t=[...fc];t.length=i;let r=0;for(let i=u;i<d;i+=6,r++){let a=t[r];a.candidate=n[i+2*e],a.count=0;let{bounds:o,leftCacheBounds:s,rightCacheBounds:c}=a;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,s[e]=1/0,s[e+3]=-1/0,o[e]=1/0,o[e+3]=-1/0;ec(i,n,o)}t.sort(dc);let l=i;for(let e=0;e<l;e++){let n=t[e];for(;e+1<l&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),l--}for(let r=u;r<d;r+=6){let i=n[r+2*e];for(let e=0;e<l;e++){let a=t[e];i>=a.candidate?ec(r,n,a.rightCacheBounds):(ec(r,n,a.leftCacheBounds),a.count++)}}for(let n=0;n<l;n++){let r=t[n],l=r.count,u=i-r.count,d=r.leftCacheBounds,f=r.rightCacheBounds,p=0;l!==0&&(p=tc(d)/a);let m=0;u!==0&&(m=tc(f)/a);let h=1+Gs*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<uc;e++){let t=fc[e];t.count=0,t.candidate=r+l+e*l;let n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=u;t<d;t+=6){let i=~~((n[t+2*e]-r)/l);i>=uc&&(i=31);let a=fc[i];a.count++,ec(t,n,a.bounds)}let t=fc[31];Qs(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=fc[e],n=fc[e+1];$s(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=fc[t],r=n.count,l=n.bounds,u=fc[t+1].rightCacheBounds;r!==0&&(f===0?Qs(l,pc):$s(l,pc,pc)),f+=r;let d=0,p=0;f!==0&&(d=tc(pc)/a);let m=i-f;m!==0&&(p=tc(u)/a);let h=1+Gs*(d*f+p*m);h<c&&(o=e,c=h,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function hc(e,t,n,r){let i=0,a=e.offset;for(let o=t,s=t+n;o<s;o++)i+=e[(o-a)*6+r*2];return i/n}var gc=class{constructor(){this.boundingData=new Float32Array(6)}};function _c(e,t,n,r,i,a){let o=r,s=r+i-1,c=a.pos,l=a.axis*2,u=n.offset||0;for(;;){for(;o<=s&&n[(o-u)*6+l]<c;)o++;for(;o<=s&&n[(s-u)*6+l]>=c;)s--;if(o<s){for(let n=0;n<t;n++){let r=e[o*t+n];e[o*t+n]=e[s*t+n],e[s*t+n]=r}for(let e=0;e<6;e++){let t=o-u,r=s-u,i=n[t*6+e];n[t*6+e]=n[r*6+e],n[r*6+e]=i}o++,s--}else return o}}var vc,yc,bc,xc,Sc=2**32;function Cc(e){return`count`in e?1:1+Cc(e.left)+Cc(e.right)}function wc(e,t,n){return vc=new Float32Array(n),yc=new Uint32Array(n),bc=new Uint16Array(n),xc=new Uint8Array(n),Tc(e,t)}function Tc(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)vc[n+e]=a[e];if(i)return t.buffer?(xc.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(yc[n+6]=t.offset,bc[r+14]=t.count,bc[r+15]=Ks,e+32);{let{left:r,right:i,splitAxis:a}=t,o=Tc(e+32,r),s=e/32,c=o/32-s;if(c>Sc)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return yc[n+6]=c,yc[n+7]=a,Tc(o,i)}}function Ec(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new gc;return lc(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=mc(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:_c(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,Zs(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new gc,x=n,S=y-n;e.left=b,lc(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new gc,w=y,T=r-S;return e.right=C,lc(t,w,T,C.boundingData,m),v(C,w,T,m,a+1),e}}function Dc(e,t){let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=e.getRootRanges(t.range),i=r[0],a=r[r.length-1],o={offset:i.offset,count:a.offset+a.count-i.offset},s=new Float32Array(6*o.count);s.offset=o.offset,e.computePrimitiveBounds(o.offset,o.count,s),e._roots=r.map(r=>{let i=Ec(e,s,r.offset,r.count,t,o),a=Cc(i),c=new n(32*a);return wc(0,i,c),c})}var Oc=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},Q=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}},kc,Ac,jc=[],Mc=new Oc(()=>new rr);function Nc(e,t,n,r,i,a){kc=Mc.getPrimitive(),Ac=Mc.getPrimitive(),jc.push(kc,Ac),Q.setBuffer(e._roots[t]);let o=Pc(0,e.geometry,n,r,i,a);Q.clearBuffer(),Mc.releasePrimitive(kc),Mc.releasePrimitive(Ac),jc.pop(),jc.pop();let s=jc.length;return s>0&&(Ac=jc[s-1],kc=jc[s-2]),o}function Pc(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c)){let t=rc(e,l),n=ic(u,c);return Xs(cc(e),s,kc),r(t,n,!1,o,a+e/8,kc)}{let u=ac(e),p=oc(e,l),m=u,h=p,g,_,v,y;if(i&&(v=kc,y=Ac,Xs(cc(m),s,v),Xs(cc(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=kc,Xs(cc(m),s,v));let b=nc(m*2,c),x=n(v,b,g,o+1,a+m/8),S;if(x===2){let e=d(m);S=r(e,f(m)-e,!0,o+1,a+m/8,v)}else S=x&&Pc(m,t,n,r,i,a,o+1);if(S)return!0;y=Ac,Xs(cc(h),s,y);let C=nc(h*2,c),w=n(y,C,_,o+1,a+h/8),T;if(w===2){let e=d(h);T=r(e,f(h)-e,!0,o+1,a+h/8,y)}else T=w&&Pc(h,t,n,r,i,a,o+1);if(T)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=Q,r=e*2;for(;!nc(r,t);)e=ac(e),r=e*2;return rc(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=Q,r=e*2;for(;!nc(r,t);)e=oc(e,n),r=e*2;return rc(e,n)+ic(r,t)}}}var Fc=new Q.constructor,Ic=new Q.constructor,Lc=new Oc(()=>new rr),Rc=new rr,zc=new rr,Bc=new rr,Vc=new rr,Hc=!1;function Uc(e,t,n,r){if(Hc)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Hc=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new Y().copy(n).invert();for(let e=0,t=i.length;e<t;e++){Fc.setBuffer(i[e]),c=0;let t=Lc.getPrimitive();Xs(cc(0),Fc.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(Ic.setBuffer(a[e]),o=Wc(0,0,n,l,r,s,c,0,0,t),Ic.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(Lc.releasePrimitive(t),Fc.clearBuffer(),s+=i[e].byteLength/32,o)break}return Hc=!1,o}function Wc(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=Ic,f=Fc):(d=Fc,f=Ic);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=nc(y,h),S=nc(b,v),C=!1;if(S&&x)C=u?i(rc(t,_),ic(t*2,v),rc(e,m),ic(e*2,h),c,o+t/8,s,a+e/8):i(rc(e,m),ic(e*2,h),rc(t,_),ic(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=Lc.getPrimitive();Xs(cc(t),g,l),l.applyMatrix4(n);let d=ac(e),f=oc(e,m);Xs(cc(d),p,Rc),Xs(cc(f),p,zc);let h=l.intersectsBox(Rc),_=l.intersectsBox(zc);C=h&&Wc(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&Wc(t,f,r,n,i,o,a,c,s+1,l,!u),Lc.releasePrimitive(l)}else{let d=ac(t),f=oc(t,_);Xs(cc(d),g,Bc),Xs(cc(f),g,Vc);let h=l.intersectsBox(Bc),v=l.intersectsBox(Vc);if(h&&v)C=Wc(e,d,n,r,i,a,o,s,c+1,l,u)||Wc(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=Wc(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=Lc.getPrimitive();t.copy(Bc).applyMatrix4(n);let l=ac(e),f=oc(e,m);Xs(cc(l),p,Rc),Xs(cc(f),p,zc);let h=t.intersectsBox(Rc),g=t.intersectsBox(zc);C=h&&Wc(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&Wc(d,f,r,n,i,o,a,c,s+1,t,!u),Lc.releasePrimitive(t)}}else if(v){if(x)C=Wc(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=Lc.getPrimitive();t.copy(Vc).applyMatrix4(n);let l=ac(e),d=oc(e,m);Xs(cc(l),p,Rc),Xs(cc(d),p,zc);let h=t.intersectsBox(Rc),g=t.intersectsBox(zc);C=h&&Wc(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&Wc(f,d,r,n,i,o,a,c,s+1,t,!u),Lc.releasePrimitive(t)}}}return C}var Gc=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!nc(r,n);)e=ac(e),r=e*2;return rc(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!nc(r,n);)e=oc(e,t),r=e*2;return rc(e,t)+ic(r,n)};let i=(e,r,a)=>{let o=nc(r*2,n);if(!e(a,o,r)&&!o){let n=ac(r),o=oc(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}{let n=sc(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Kc=new rr,qc=new Float32Array(6),Jc=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Ys,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),Dc(this,e)}getRootRanges(){throw Error(`BVH: getRootRanges() not implemented`)}writePrimitiveBounds(){throw Error(`BVH: writePrimitiveBounds() not implemented`)}writePrimitiveRangeBounds(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let n=e,r=e+t;n<r;n++){this.writePrimitiveBounds(n,qc,0);let[e,t,r,u,d,f]=qc;e<i&&(i=e),u>s&&(s=u),t<a&&(a=t),d>c&&(c=d),r<o&&(o=r),f>l&&(l=f)}return n[r+0]=i,n[r+1]=a,n[r+2]=o,n[r+3]=s,n[r+4]=c,n[r+5]=l,n}computePrimitiveBounds(e,t,n){let r=n.offset||0;for(let i=e,a=e+t;i<a;i++){this.writePrimitiveBounds(i,qc,0);let[e,t,a,o,s,c]=qc,l=(e+o)/2,u=(t+s)/2,d=(a+c)/2,f=(o-e)/2,p=(s-t)/2,m=(c-a)/2,h=(i-r)*6;n[h+0]=l,n[h+1]=f+(Math.abs(l)+f)*qs,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*qs,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*qs}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;nc(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Gc.setBVH(this,t),Gc.traverse(e),Gc.reset()}refit(){let e=this._roots;for(let t=0,n=e.length;t<n;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n),a=new Float32Array(n),o=n.byteLength/32;for(let e=o-1;e>=0;e--){let t=e*8,n=t*2;if(nc(n,i)){let e=rc(t,r),o=ic(n,i);this.writePrimitiveRangeBounds(e,o,qc,0),a.set(qc,t)}else{let e=ac(t),n=oc(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Xs(0,new Float32Array(t),Kc),e.union(Kc)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:r,intersectsPrimitive:i,scratchPrimitive:a,iterate:o}=e;if(r&&i){let e=r;r=(t,n,r,s,c)=>e(t,n,r,s,c)?!0:o(t,n,this,i,r,s,a)}else r||=i?(e,t,n,r)=>o(e,t,this,i,n,r,a):(e,t,n)=>n;let s=!1,c=0,l=this._roots;for(let e=0,i=l.length;e<i;e++){let i=l[e];if(s=Nc(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Uc(this,e,t,r)}};function Yc(){return typeof SharedArrayBuffer<`u`}function Xc(e){return e.index?e.index.count:e.attributes.position.count}function Zc(e){return Xc(e)/3}function Qc(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function $c(e,t){if(!e.index){let n=e.attributes.position.count,r=Qc(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new xr(r,1));for(let e=0;e<n;e++)r[e]=e}}function el(e,t,n){let r=Xc(e)/n,i=t||e.drawRange,a=i.start/n,o=(i.start+i.count)/n,s=Math.max(0,a),c=Math.min(r,o)-s;return{offset:Math.floor(s),count:Math.floor(c)}}function tl(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function nl(e,t,n){let r=el(e,t,n),i=tl(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Xc(e)/n,l=[];for(let e of i){let{offset:t,count:n}=e,r=t,i=t+(isFinite(n)?n:c-t);r<s&&i>o&&(l.push({pos:Math.max(o,r),isStart:!0}),l.push({pos:Math.min(s,i),isStart:!1}))}l.sort((e,t)=>e.pos===t.pos?e.type===`end`?-1:1:e.pos-t.pos);let u=0,d=null;for(let e of l){let t=e.pos;u!==0&&t!==d&&a.push({offset:d,count:t-d}),u+=e.isStart?1:-1,d=t}return a}function rl(e,t){let n=e[e.length-1],r=n.offset+n.count>2**16,i=e.reduce((e,t)=>e+t.count,0),a=r?4:2,o=t?new SharedArrayBuffer(i*a):new ArrayBuffer(i*a),s=r?new Uint32Array(o):new Uint16Array(o),c=0;for(let t=0;t<e.length;t++){let{offset:n,count:r}=e[t];for(let e=0;e<r;e++)s[c+e]=n+e;c+=r}return s}var il=class extends Jc{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(!e.isBufferGeometry)throw Error(`BVH: Only BufferGeometries are supported.`);if(e.index&&e.index.isInterleavedBufferAttribute)throw Error(`BVH: InterleavedBufferAttribute is not supported for the index attribute.`);if(t.useSharedArrayBuffer&&!Yc())throw Error(`BVH: SharedArrayBuffer is not available.`);super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Ys,...t},t[Js]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=rl(nl(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else $c(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new rr))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:nl(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},al=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,a=e.length;i<a;i++){let a=e[i][t];n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,a=t.length;i<a;i++){let a=t[i],o=e.dot(a);n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}};al.prototype.setFromBox=(function(){let e=new J;return function(t,n){let r=n.min,i=n.max,a=1/0,o=-1/0;for(let n=0;n<=1;n++)for(let s=0;s<=1;s++)for(let c=0;c<=1;c++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var ol=(function(){let e=new J,t=new J,n=new J;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.dot(s),m=s.dot(s)*f-d*d,h,g;h=m===0?0:(u*d-p*f)/m,g=(u+h*d)/f,a.x=h,a.y=g}})(),sl=(function(){let e=new q,t=new J,n=new J;return function(r,i,a,o){ol(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}a.copy(e),o.copy(d);return}}})(),cl=(function(){let e=new J,t=new J,n=new di,r=new bs;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),ll=[`x`,`y`,`z`],ul=1e-15,dl=ul*ul;function fl(e){return Math.abs(e)<ul}var pl=class extends nr{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new J),this.satBounds=[,,,,].fill().map(()=>new al),this.points=[this.a,this.b,this.c],this.plane=new di,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new bs,this.needsUpdate=!0}intersectsSphere(e){return cl(e,this)}update(){let e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,a=this.satBounds,o=i[0],s=a[0];this.getNormal(o),s.setFromPoints(o,r);let c=i[1],l=a[1];c.subVectors(e,t),l.setFromPoints(c,r);let u=i[2],d=a[2];u.subVectors(t,n),d.setFromPoints(u,r);let f=i[3],p=a[3];f.subVectors(n,e),p.setFromPoints(f,r);let m=c.length(),h=u.length(),g=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<ul?h<ul||g<ul?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<ul?g<ul?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<ul&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};pl.prototype.closestPointToSegment=(function(){let e=new J,t=new J,n=new bs;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),sl(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),pl.prototype.intersectsTriangle=(function(){let e=new pl,t=new al,n=new al,r=new J,i=new J,a=new J,o=new J,s=new bs,c=new bs,l=new J,u=new q,d=new q;function f(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function p(e,t,n,r,i,a,o,s,c,l,u){let d=o/(o-s);l.x=r+(i-r)*d,u.start.subVectors(t,e).multiplyScalar(d).add(e),d=o/(o-c),l.y=r+(a-r)*d,u.end.subVectors(n,e).multiplyScalar(d).add(e)}function m(e,t,n,r,i,a,o,s,c,l,u){if(i>0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)p(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function h(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return fl(o)?fl(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):fl(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function g(e,t,n){let r=t.a;return fl(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function _(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<dl&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}function v(e,t,n,o){if(e.isDegenerateIntoSegment){if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.start),d=c.x*l.y-c.y*l.x;if(fl(d))return!1;let f=(u.x*l.y-u.y*l.x)/d,p=-(c.x*u.y-c.y*u.x)/d;return f<0||f>1||p<0||p>1?!1:fl(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}return t.isDegenerateIntoPoint?_(e,t,n):h(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<dl&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?_(t,e,n):g(t,e,n);if(t.isDegenerateIntoPoint)return g(e,t,n);if(t.isDegenerateIntoSegment)return h(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=v(this,t,n,r);if(o!==void 0)return o;let p=this.plane,h=t.plane,g=h.distanceToPoint(this.a),_=h.distanceToPoint(this.b),y=h.distanceToPoint(this.c);fl(g)&&(g=0),fl(_)&&(_=0),fl(y)&&(y=0);let b=g*_,x=g*y;if(b>0&&x>0)return!1;let S=p.distanceToPoint(t.a),C=p.distanceToPoint(t.b),w=p.distanceToPoint(t.c);fl(S)&&(S=0),fl(C)&&(C=0),fl(w)&&(w=0);let T=S*C,E=S*w;if(T>0&&E>0)return!1;i.copy(p.normal),a.copy(h.normal);let D=i.cross(a),O=0,k=Math.abs(D.x),A=Math.abs(D.y);A>k&&(k=A,O=1),Math.abs(D.z)>k&&(O=2);let j=ll[O],M=this.a[j],N=this.b[j],ee=this.c[j],P=t.a[j],F=t.b[j],I=t.c[j];if(m(this,M,N,ee,b,x,g,_,y,u,s)||m(t,P,F,I,T,E,S,C,w,d,c))return f(this,t,n,r);if(u.y<u.x){let e=u.y;u.y=u.x,u.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(n&&(d.x>u.x?n.start.copy(c.start):n.start.copy(s.start),d.y<u.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),pl.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),pl.prototype.distanceToTriangle=(function(){let e=new J,t=new J,n=[`a`,`b`,`c`],r=new bs,i=new bs;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),sl(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var ml=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new J,this.max=new J,this.matrix=new Y,this.invMatrix=new Y,this.points=Array(8).fill().map(()=>new J),this.satAxes=[,,,].fill().map(()=>new J),this.satBounds=[,,,].fill().map(()=>new al),this.alignedSatBounds=[,,,].fill().map(()=>new al),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}};ml.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let s=r[1*i|2*a|4*o];s.x=i?n.x:t.x,s.y=a?n.y:t.y,s.z=o?n.z:t.z,s.applyMatrix4(e)}let i=this.satBounds,a=this.satAxes,o=r[0];for(let e=0;e<3;e++){let t=a[e],n=i[e],s=r[1<<e];t.subVectors(o,s),n.setFromPoints(t,r)}let s=this.alignedSatBounds;s[0].setFromPointsField(r,`x`),s[1].setFromPointsField(r,`y`),s[2].setFromPointsField(r,`z`),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),ml.prototype.intersectsBox=(function(){let e=new al;return function(t){this.needsUpdate&&this.update();let n=t.min,r=t.max,i=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,o[0].isSeparated(e)||(e.min=n.y,e.max=r.y,o[1].isSeparated(e))||(e.min=n.z,e.max=r.z,o[2].isSeparated(e)))return!1;for(let n=0;n<3;n++){let r=a[n],o=i[n];if(e.setFromBox(r,t),o.isSeparated(e))return!1}return!0}})(),ml.prototype.intersectsTriangle=(function(){let e=new pl,t=[,,,],n=new al,r=new al,i=new J;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}})(),ml.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),ml.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),ml.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new bs),n=Array(12).fill().map(()=>new bs),r=new J,i=new J;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[m],b=y.start,x=y.end;b[g]=u[g],b[_]=i?u[_]:d[_],b[v]=a?u[v]:d[_],x[g]=d[g],x[_]=i?u[_]:d[_],x[v]=a?u[v]:d[_],m++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];sl(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var hl=new class extends Oc{constructor(){super(()=>new pl)}},gl=new J,_l=new J;function vl(e,t,n={},r=0,i=1/0){let a=r*r,o=i*i,s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(gl.copy(t).clamp(e.min,e.max),gl.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,gl);let r=t.distanceToSquared(gl);return r<s&&(_l.copy(gl),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(_l):n.point=_l.clone(),n.distance=l,n.faceIndex=c,n}var yl=!0,bl=new J,xl=new J,Sl=new J,Cl=new q,wl=new q,Tl=new q,El=new J,Dl=new J,Ol=new J,kl=new J;function Al(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function jl(e,t,n,r,i,a,o,s,c,l,u){bl.fromBufferAttribute(t,a),xl.fromBufferAttribute(t,o),Sl.fromBufferAttribute(t,s);let d=Al(e,bl,xl,Sl,kl,c,l,u);if(d){if(r){Cl.fromBufferAttribute(r,a),wl.fromBufferAttribute(r,o),Tl.fromBufferAttribute(r,s),d.uv=new q;let e=nr.getInterpolation(kl,bl,xl,Sl,Cl,wl,Tl,d.uv);yl||(d.uv=e)}if(i){Cl.fromBufferAttribute(i,a),wl.fromBufferAttribute(i,o),Tl.fromBufferAttribute(i,s),d.uv1=new q;let e=nr.getInterpolation(kl,bl,xl,Sl,Cl,wl,Tl,d.uv1);yl||(d.uv1=e)}if(n){El.fromBufferAttribute(n,a),Dl.fromBufferAttribute(n,o),Ol.fromBufferAttribute(n,s),d.normal=new J;let t=nr.getInterpolation(kl,bl,xl,Sl,El,Dl,Ol,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),yl||(d.normal=t)}let t={a,b:o,c:s,normal:new J,materialIndex:0};if(nr.getNormal(bl,xl,Sl,t.normal),d.face=t,d.faceIndex=a,yl){let e=new J;nr.getBarycoord(kl,bl,xl,Sl,e),d.barycoord=e}}return d}function Ml(e){return e&&e.isMaterial?e.side:e}function Nl(e,t,n,r,i,a,o){let s=r*3,c=s+0,l=s+1,u=s+2,{index:d,groups:f}=e;e.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));let{position:p,normal:m,uv:h,uv1:g}=e.attributes;if(Array.isArray(t)){let e=r*3;for(let s=0,d=f.length;s<d;s++){let{start:d,count:_,materialIndex:v}=f[s];if(e>=d&&e<d+_){let e=Ml(t[v]),s=jl(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=v,i)i.push(s);else return s}}}}else{let e=Ml(t),s=jl(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=0,i)i.push(s);else return s}}return null}function Pl(e,t,n,r){let i=e.a,a=e.b,o=e.c,s=t,c=t+1,l=t+2;n&&(s=n.getX(s),c=n.getX(c),l=n.getX(l)),i.x=r.getX(s),i.y=r.getY(s),i.z=r.getZ(s),a.x=r.getX(c),a.y=r.getY(c),a.z=r.getZ(c),o.x=r.getX(l),o.y=r.getY(l),o.z=r.getZ(l)}function Fl(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Nl(c,t,n,e,a,o,s)}function Il(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=Nl(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Ll(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let n=e,s=t+e;n<s;n++){let e;if(e=n,Pl(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Rl(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(nc(l,s)){let t=rc(e,o),n=ic(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}{let r=ac(e),i=oc(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function zl(e,t,n,r,i){let a,o,s,c,l,u,d=1/n.direction.x,f=1/n.direction.y,p=1/n.direction.z,m=n.origin.x,h=n.origin.y,g=n.origin.z,_=t[e],v=t[e+3],y=t[e+1],b=t[e+3+1],x=t[e+2],S=t[e+3+2];return d>=0?(a=(_-m)*d,o=(v-m)*d):(a=(v-m)*d,o=(_-m)*d),f>=0?(s=(y-h)*f,c=(b-h)*f):(s=(b-h)*f,c=(y-h)*f),a>c||s>o||((s>a||isNaN(a))&&(a=s),(c<o||isNaN(o))&&(o=c),p>=0?(l=(x-g)*p,u=(S-g)*p):(l=(S-g)*p,u=(x-g)*p),a>u||l>o)?!1:((l>a||a!==a)&&(a=l),(u<o||o!==o)&&(o=u),a<=i&&o>=r)}function Bl(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Nl(c,t,n,l?l[e]:e,a,o,s)}function Vl(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=Nl(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Hl(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),Pl(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ul(e,t,n,r,i,a,o){Q.setBuffer(e._roots[t]),Wl(0,e,n,r,i,a,o),Q.clearBuffer()}function Wl(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c))Fl(t,n,r,rc(e,l),ic(u,c),i,a,o);else{let c=ac(e);zl(c,s,r,a,o)&&Wl(c,t,n,r,i,a,o);let u=oc(e,l);zl(u,s,r,a,o)&&Wl(u,t,n,r,i,a,o)}}var Gl=[`x`,`y`,`z`];function Kl(e,t,n,r,i,a){Q.setBuffer(e._roots[t]);let o=ql(0,e,n,r,i,a);return Q.clearBuffer(),o}function ql(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=Q,l=e*2;if(nc(l,s))return Il(t,n,r,rc(e,c),ic(l,s),i,a);{let s=sc(e,c),l=Gl[s],u=r.direction[l]>=0,d,f;u?(d=ac(e),f=oc(e,c)):(d=oc(e,c),f=ac(e));let p=zl(d,o,r,i,a)?ql(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=zl(f,o,r,i,a)?ql(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Jl=new rr,Yl=new pl,Xl=new pl,Zl=new Y,Ql=new ml,$l=new ml;function eu(e,t,n,r){Q.setBuffer(e._roots[t]);let i=tu(0,e,n,r);return Q.clearBuffer(),i}function tu(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=Q,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Ql.set(n.boundingBox.min,n.boundingBox.max,r),i=Ql),nc(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=rc(e,s),m=ic(c,o);if(Zl.copy(r).invert(),n.boundsTree)return Xs(cc(e),a,$l),$l.matrix.copy(Zl),$l.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>$l.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=p*3,n=(m+p)*3;t<n;t+=3)if(Pl(Xl,t,l,u),Xl.needsUpdate=!0,e.intersectsTriangle(Xl))return!0;return!1}});{let e=Zc(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){Pl(Yl,t,l,u),Yl.a.applyMatrix4(Zl),Yl.b.applyMatrix4(Zl),Yl.c.applyMatrix4(Zl),Yl.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Pl(Xl,t,d,f),Xl.needsUpdate=!0,Yl.intersectsTriangle(Xl))return!0}}}else{let o=ac(e),c=oc(e,s);return Xs(cc(o),a,Jl),!!(i.intersectsBox(Jl)&&tu(o,t,n,r,i)||(Xs(cc(c),a,Jl),i.intersectsBox(Jl)&&tu(c,t,n,r,i)))}}var nu=new Y,ru=new ml,iu=new ml,au=new J,ou=new J,su=new J,cu=new J;function lu(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),ru.set(t.boundingBox.min,t.boundingBox.max,n),ru.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=hl.getPrimitive(),p=hl.getPrimitive(),m=au,h=ou,g=null,_=null;i&&(g=su,_=cu);let v=1/0,y=null,b=null;return nu.copy(n).invert(),iu.matrix.copy(nu),e.shapecast({boundsTraverseOrder:e=>ru.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(iu.min.copy(e.min),iu.max.copy(e.max),iu.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>iu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){Pl(p,3*o,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Pl(f,3*t,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=t,b=o),e<a)return!0}}}});{let i=Zc(t);for(let t=0,o=i;t<o;t++){Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=e,i=e+r;n<i;n++){Pl(f,3*n,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=n,b=t),e<a)return!0}}}}}),hl.releasePrimitive(f),hl.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(nu),h.applyMatrix4(nu),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function uu(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(nc(u,s)){let t=rc(n,o),a=ic(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}{let e=ac(n),r=oc(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function du(e,t,n,r,i,a,o){Q.setBuffer(e._roots[t]),fu(0,e,n,r,i,a,o),Q.clearBuffer()}function fu(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c))Bl(t,n,r,rc(e,l),ic(u,c),i,a,o);else{let c=ac(e);zl(c,s,r,a,o)&&fu(c,t,n,r,i,a,o);let u=oc(e,l);zl(u,s,r,a,o)&&fu(u,t,n,r,i,a,o)}}var pu=[`x`,`y`,`z`];function mu(e,t,n,r,i,a){Q.setBuffer(e._roots[t]);let o=hu(0,e,n,r,i,a);return Q.clearBuffer(),o}function hu(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=Q,l=e*2;if(nc(l,s))return Vl(t,n,r,rc(e,c),ic(l,s),i,a);{let s=sc(e,c),l=pu[s],u=r.direction[l]>=0,d,f;u?(d=ac(e),f=oc(e,c)):(d=oc(e,c),f=ac(e));let p=zl(d,o,r,i,a)?hu(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=zl(f,o,r,i,a)?hu(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var gu=new rr,_u=new pl,vu=new pl,yu=new Y,bu=new ml,xu=new ml;function Su(e,t,n,r){Q.setBuffer(e._roots[t]);let i=Cu(0,e,n,r);return Q.clearBuffer(),i}function Cu(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=Q,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),bu.set(n.boundingBox.min,n.boundingBox.max,r),i=bu),nc(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=rc(e,s),m=ic(c,o);if(yu.copy(r).invert(),n.boundsTree)return Xs(cc(e),a,xu),xu.matrix.copy(yu),xu.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>xu.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=m+p;n<r;n++)if(Pl(vu,3*t.resolveTriangleIndex(n),l,u),vu.needsUpdate=!0,e.intersectsTriangle(vu))return!0;return!1}});{let e=Zc(n);for(let n=p,r=m+p;n<r;n++){Pl(_u,3*t.resolveTriangleIndex(n),l,u),_u.a.applyMatrix4(yu),_u.b.applyMatrix4(yu),_u.c.applyMatrix4(yu),_u.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Pl(vu,t,d,f),vu.needsUpdate=!0,_u.intersectsTriangle(vu))return!0}}}else{let o=ac(e),c=oc(e,s);return Xs(cc(o),a,gu),!!(i.intersectsBox(gu)&&Cu(o,t,n,r,i)||(Xs(cc(c),a,gu),i.intersectsBox(gu)&&Cu(c,t,n,r,i)))}}var wu=new Y,Tu=new ml,Eu=new ml,Du=new J,Ou=new J,ku=new J,Au=new J;function ju(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Tu.set(t.boundingBox.min,t.boundingBox.max,n),Tu.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=hl.getPrimitive(),p=hl.getPrimitive(),m=Du,h=Ou,g=null,_=null;i&&(g=ku,_=Au);let v=1/0,y=null,b=null;return wu.copy(n).invert(),Eu.matrix.copy(wu),e.shapecast({boundsTraverseOrder:e=>Tu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Eu.min.copy(e.min),Eu.max.copy(e.max),Eu.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>Eu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){let n=e.resolveTriangleIndex(t);Pl(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}{let o=Zc(t);for(let t=0,s=o;t<s;t++){Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=r,o=r+i;n<o;n++){let r=e.resolveTriangleIndex(n);Pl(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<a)return!0}}}}}),hl.releasePrimitive(f),hl.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(wu),h.applyMatrix4(wu),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Mu(e,t,n){return e===null?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}var Nu=new ml,Pu=new Gr,Fu=new J,Iu=new Y,Lu=new J,Ru=[`getX`,`getY`,`getZ`],zu=class e extends il{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[Js]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new xr(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;nc(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.`),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=(i?i[e]:e)*3,c=s+0,l=s+1,u=s+2;o&&(c=o[c],l=o[l],u=o[u]);for(let e=0;e<3;e++){let r=a[Ru[e]](c),i=a[Ru[e]](l),o=a[Ru[e]](u),s=r;i<s&&(s=i),o<s&&(s=o);let d=r;i>d&&(d=i),o>d&&(d=o),t[n+e]=s,t[n+e+3]=d}return t}computePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw Error(`MeshBVH: compute triangle bounds range is invalid.`);let c=a.array,l=a.offset||0,u=3;a.isInterleavedBufferAttribute&&(u=a.data.stride);let d=[`getX`,`getY`,`getZ`],f=n.offset;for(let r=e,p=e+t;r<p;r++){let e=(i?i[r]:r)*3,t=(r-f)*6,p=e+0,m=e+1,h=e+2;o&&(p=o[p],m=o[m],h=o[h]),s||(p=p*u+l,m=m*u+l,h=h*u+l);for(let e=0;e<3;e++){let r,i,o;s?(r=a[d[e]](p),i=a[d[e]](m),o=a[d[e]](h)):(r=c[p+e],i=c[m+e],o=c[h+e]);let l=r;i<l&&(l=i),o<l&&(l=o);let u=r;i>u&&(u=i),o>u&&(u=o);let f=(u-l)/2,g=e*2;n[t+g+0]=l+f,n[t+g+1]=f+(Math.abs(l)+f)*qs}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;Iu.copy(e.matrixWorld).invert(),Pu.copy(t.ray).applyMatrix4(Iu),Lu.setFromMatrixScale(e.matrixWorld),Fu.copy(Pu.direction).multiply(Lu);let i=Fu.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(Pu,r,a,o);i=Mu(i,e,t),i&&n.push(i)}else{let i=this.raycast(Pu,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=Mu(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?uu:Rl)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?du:Ul;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?mu:Kl;for(let s=0,c=i.length;s<c;s++){let i=o(this,s,t,e,n,r);i!=null&&(a==null||i.distance<a.distance)&&(a=i)}return a}intersectsGeometry(e,t){let n=!1,r=this._roots,i=this.indirect?Su:eu;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=hl.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Hl:Ll});return hl.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=hl.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);Pl(o,t*3,s,c)}:e=>{Pl(o,e*3,s,c)},u=hl.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);Pl(u,n*3,d,f)}:e=>{Pl(u,e*3,d,f)};if(a){if(!(t instanceof e))throw Error(`MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.`);let r=(e,t,r,i,s,c,d,f)=>{for(let m=r,h=r+i;m<h;m++){p(m),u.a.applyMatrix4(n),u.b.applyMatrix4(n),u.c.applyMatrix4(n),u.needsUpdate=!0;for(let n=e,r=e+t;n<r;n++)if(l(n),o.needsUpdate=!0,a(o,u,n,m,s,c,d,f))return!0}return!1};if(i){let e=i;i=function(t,n,i,a,o,s,c,l){return e(t,n,i,a,o,s,c,l)?!0:r(t,n,i,a,o,s,c,l)}}else i=r}return super.bvhcast(t,n,{intersectsRanges:i})}intersectsBox(e,t){return Nu.set(e.min,e.max,t),Nu.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Nu.intersectsBox(e),intersectsTriangle:e=>Nu.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,a=1/0){return(this.indirect?ju:lu)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return vl(this,e,t,n,r)}},Bu=1e-6,Vu=Bu*.5,Hu=10**-Math.log10(Bu),Uu=Vu*Hu;function Wu(e){return~~(e*Hu+Uu)}function Gu(e){return`${Wu(e.x)},${Wu(e.y)}`}function Ku(e){return`${Wu(e.x)},${Wu(e.y)},${Wu(e.z)}`}function qu(e){return`${Wu(e.x)},${Wu(e.y)},${Wu(e.z)},${Wu(e.w)}`}function Ju(e,t,n){n.direction.subVectors(t,e).normalize();let r=e.dot(n.direction);return n.origin.copy(e).addScaledVector(n.direction,-r),n}function Yu(){return typeof SharedArrayBuffer<`u`}function Xu(e){if(e.buffer instanceof SharedArrayBuffer)return e;let t=e.constructor,n=e.buffer,r=new SharedArrayBuffer(n.byteLength),i=new Uint8Array(n);return new Uint8Array(r).set(i,0),new t(r)}function Zu(e){return e.index?e.index.count:e.attributes.position.count}function Qu(e){return Zu(e)/3}var $u=1e-8,ed=new J;function td(e){return~~(e/3)}function nd(e){return e%3}function rd(e,t){return e.start-t.start}function id(e,t){return ed.subVectors(t,e.origin).dot(e.direction)}function ad(e,t,n,r=$u){e.sort(rd),t.sort(rd);for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<t.length;s++){let c=t[s];if(!(c.start>i.end)){if(i.end<c.start||c.end<i.start)continue;if(i.start<=c.start&&i.end>=c.end)a(c.end,i.end)||e.splice(r+1,0,{start:c.end,end:i.end,index:i.index}),i.end=c.start,c.start=0,c.end=0;else if(i.start>=c.start&&i.end<=c.end)a(i.end,c.end)||t.splice(s+1,0,{start:i.end,end:c.end,index:c.index}),c.end=i.start,i.start=0,i.end=0;else if(i.start<=c.start&&i.end<=c.end){let e=i.end;i.end=c.start,c.start=e}else if(i.start>=c.start&&i.end>=c.end){let e=c.end;c.end=i.start,i.start=e}else throw Error()}if(n.has(i.index)||n.set(i.index,[]),n.has(c.index)||n.set(c.index,[]),n.get(i.index).push(c.index),n.get(c.index).push(i.index),o(c)&&(t.splice(s,1),s--),o(i)){e.splice(r,1),r--;break}}}i(e),i(t);function i(e){for(let t=0;t<e.length;t++)o(e[t])&&(e.splice(t,1),t--)}function a(e,t){return Math.abs(t-e)<r}function o(e){return Math.abs(e.end-e.start)<r}}var od=1e-5,sd=1e-4,cd=class{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){let t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let r=1/0,i=null;for(let s=0,c=t.length;s<c;s++){let c=t[s];if(a(c,e)&&a(c,n))continue;let l=o(c,e),u=o(c,n),d=Math.min(l,u);d<r&&(r=d,i=c)}return i;function a(e,t){let n=e.origin.distanceTo(t.origin)>od;return e.direction.angleTo(t.direction)>sd||n}function o(e,t){let n=e.origin.distanceTo(t.origin),r=e.direction.angleTo(t.direction);return n/od+r/sd}}},ld=new J,ud=new J,dd=new Gr;function fd(e,t,n){let r=e.attributes,i=e.index,a=r.position,o=new Map,s=new Map,c=Array.from(t),l=new cd;for(let e=0,t=c.length;e<t;e++){let t=c[e],n=td(t),r=nd(t),o=3*n+r,u=3*n+(r+1)%3;i&&(o=i.getX(o),u=i.getX(u)),ld.fromBufferAttribute(a,o),ud.fromBufferAttribute(a,u),Ju(ld,ud,dd);let d,f=l.findClosestRay(dd);f===null&&(f=dd.clone(),l.addRay(f)),s.has(f)||s.set(f,{forward:[],reverse:[],ray:f}),d=s.get(f);let p=id(f,ld),m=id(f,ud);p>m&&([p,m]=[m,p]),dd.direction.dot(f.direction)<0?d.reverse.push({start:p,end:m,index:t}):d.forward.push({start:p,end:m,index:t})}return s.forEach(({forward:e,reverse:t},r)=>{ad(e,t,o,n),e.length===0&&t.length===0&&s.delete(r)}),{disjointConnectivityMap:o,fragmentMap:s}}var pd=new q,md=new J,hd=new en,gd=[``,``,``],_d=class{constructor(){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8}getSiblingTriangleIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>~~(e/3)):[]}getDisjointSiblingEdgeIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>e%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){let{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:r,degenerateEpsilon:i}=this,a=t?v:_,o=new Map,{attributes:s}=e,c=t?Object.keys(s):null,l=e.index,u=s.position,d=Qu(e),f=d,p=0;n&&(p=e.drawRange.start,e.drawRange.count!==1/0&&(d=~~(e.drawRange.count/3)));let m=this.data;(!m||m.length<3*f)&&(m=new Int32Array(3*f)),m.fill(-1);let h=0,g=new Set;for(let e=p,t=d*3+p;e<t;e+=3){let t=e;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),gd[e]=a(n)}for(let e=0;e<3;e++){let n=(e+1)%3,r=gd[e],i=gd[n],a=`${i}_${r}`;if(o.has(a)){let n=t+e,r=o.get(a);m[n]=r,m[r]=n,o.delete(a),h+=2,g.delete(r)}else{let n=`${r}_${i}`,a=t+e;o.set(n,a),g.add(a)}}}if(r){let{fragmentMap:t,disjointConnectivityMap:n}=fd(e,g,i);g.clear(),t.forEach(({forward:e,reverse:t})=>{e.forEach(({index:e})=>g.add(e)),t.forEach(({index:e})=>g.add(e))}),this.unmatchedDisjointEdges=t,this.disjointConnections=n,h=d*3-g.size}this.matchedEdges=h,this.unmatchedEdges=g.size,this.data=m;function _(e){return md.fromBufferAttribute(u,e),Ku(md)}function v(e){let t=``;for(let n=0,r=c.length;n<r;n++){let r=s[c[n]],i;switch(r.itemSize){case 1:i=Wu(r.getX(e));break;case 2:i=Gu(pd.fromBufferAttribute(r,e));break;case 3:i=Ku(md.fromBufferAttribute(r,e));break;case 4:i=qu(hd.fromBufferAttribute(r,e))}t!==``&&(t+=`|`),t+=i}return t}}},vd=class extends ii{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new Y,this._previousMatrix.elements.fill(0),this._halfEdges=null,this._boundsTree=null,this._groupIndices=null,this._hash=null}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){let{matrix:e,_previousMatrix:t}=this,n=e.elements,r=t.elements;for(let e=0;e<16;e++)if(n[e]!==r[e])return!0;return!1}prepareGeometry(){let e=this.geometry,t=e.attributes,n=Yu(),r=e.index,i=e.attributes.position,a=r?`${r.uuid}_${r.count}_${r.version}`:`-1_-1_-1`,o=`${i.uuid}_${i.count}_${i.version}`,s=`${e.uuid}_${a}_${o}`;if(this._hash===s)return;if(this._hash=s,n)for(let e in t){let n=t[e];if(n.isInterleavedBufferAttribute)throw Error(`Brush: InterleavedBufferAttributes are not supported.`);n.array=Xu(n.array)}e.boundsTree=new zu(e,{maxLeafSize:3,indirect:!0,useSharedArrayBuffer:n}),e.halfEdges||=new _d,e.halfEdges.updateFrom(e);let c=Qu(e);(!e.groupIndices||e.groupIndices.length!==c)&&(e.groupIndices=new Uint16Array(c));let l=e.groupIndices,u=e.groups;for(let e=0,t=u.length;e<t;e++){let{start:t,count:n}=u[e];for(let r=t/3,i=(t+n)/3;r<i;r++)l[r]=e}}disposeCacheData(){let{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}},yd=Object.getOwnPropertyNames,bd=(e,t)=>function(){return t||(0,e[yd(e)[0]])((t={exports:{}}).exports,t),t.exports},xd=bd({"node_modules/binary-search-bounds/search-bounds.js"(e,t){"use strict";function n(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>=0?(a=o,i=o-1):r=o+1}return a}function r(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>0?(a=o,i=o-1):r=o+1}return a}function i(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<0?(a=o,r=o+1):i=o-1}return a}function a(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<=0?(a=o,r=o+1):i=o-1}return a}function o(e,t,n,r,i){for(;r<=i;){var a=r+i>>>1,o=e[a],s=n===void 0?o-t:n(o,t);if(s===0)return a;s<=0?r=a+1:i=a-1}return-1}function s(e,t,n,r,i,a){return typeof n==`function`?a(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):a(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}t.exports={ge:function(e,t,r,i,a){return s(e,t,r,i,a,n)},gt:function(e,t,n,i,a){return s(e,t,n,i,a,r)},lt:function(e,t,n,r,a){return s(e,t,n,r,a,i)},le:function(e,t,n,r,i){return s(e,t,n,r,i,a)},eq:function(e,t,n,r,i){return s(e,t,n,r,i,o)}}}}),Sd=bd({"node_modules/two-product/two-product.js"(e,t){"use strict";t.exports=r;var n=+(2**27+1);function r(e,t,r){var i=e*t,a=n*e,o=a-(a-e),s=e-o,c=n*t,l=c-(c-t),u=t-l,d=i-o*l-s*l-o*u,f=s*u-d;return r?(r[0]=f,r[1]=i,r):[f,i]}}}),Cd=bd({"node_modules/robust-sum/robust-sum.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),wd=bd({"node_modules/two-sum/two-sum.js"(e,t){"use strict";t.exports=n;function n(e,t,n){var r=e+t,i=r-e,a=r-i,o=t-i,s=e-a;return n?(n[0]=s+o,n[1]=r,n):[s+o,r]}}}),Td=bd({"node_modules/robust-scale/robust-scale.js"(e,t){"use strict";var n=Sd(),r=wd();t.exports=i;function i(e,t){var i=e.length;if(i===1){var a=n(e[0],t);return a[0]?a:[a[1]]}var o=Array(2*i),s=[.1,.1],c=[.1,.1],l=0;n(e[0],t,s),s[0]&&(o[l++]=s[0]);for(var u=1;u<i;++u){n(e[u],t,c);var d=s[1];r(d,c[0],s),s[0]&&(o[l++]=s[0]);var f=c[1],p=s[1],m=f+p,h=p-(m-f);s[1]=m,h&&(o[l++]=h)}return s[1]&&(o[l++]=s[1]),l===0&&(o[l++]=0),o.length=l,o}}}),Ed=bd({"node_modules/robust-subtract/robust-diff.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],-t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=-t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=-t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=-t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),Dd=bd({"node_modules/robust-orientation/orientation.js"(e,t){"use strict";var n=Sd(),r=Cd(),i=Td(),a=Ed(),o=5,s=11102230246251565e-32,c=(3+16*s)*s,l=(7+56*s)*s;function u(e,t,n,r){return function(n,i,a){var o=r(e(e(t(i[1],a[0]),t(-a[1],i[0])),e(t(n[1],i[0]),t(-i[1],n[0]))),e(t(n[1],a[0]),t(-a[1],n[0])));return o[o.length-1]}}function d(e,t,n,r){return function(i,a,o,s){var c=r(e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2])))),e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2])))));return c[c.length-1]}}function f(e,t,n,r){return function(i,a,o,s,c){var l=r(e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),a[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),-o[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),s[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),-c[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-a[3])))),e(e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),s[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),-c[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),i[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-a[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-s[3]))))),e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-o[3])),e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),s[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-c[3]))),e(e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),i[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),-a[3])),e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-c[3])))));return l[l.length-1]}}function p(e){return(e===3?u:e===4?d:f)(r,n,i,a)}var m=p(3),h=p(4),g=[function(){return 0},function(){return 0},function(e,t){return t[0]-e[0]},function(e,t,n){var r=(e[1]-n[1])*(t[0]-n[0]),i=(e[0]-n[0])*(t[1]-n[1]),a=r-i,o;if(r>0){if(i<=0)return a;o=r+i}else if(r<0){if(i>=0)return a;o=-(r+i)}else return a;var s=c*o;return a>=s||a<=-s?a:m(e,t,n)},function(e,t,n,r){var i=e[0]-r[0],a=t[0]-r[0],o=n[0]-r[0],s=e[1]-r[1],c=t[1]-r[1],u=n[1]-r[1],d=e[2]-r[2],f=t[2]-r[2],p=n[2]-r[2],m=a*u,g=o*c,_=o*s,v=i*u,y=i*c,b=a*s,x=d*(m-g)+f*(_-v)+p*(y-b),S=l*((Math.abs(m)+Math.abs(g))*Math.abs(d)+(Math.abs(_)+Math.abs(v))*Math.abs(f)+(Math.abs(y)+Math.abs(b))*Math.abs(p));return x>S||-x>S?x:h(e,t,n,r)}];function _(e){var t=g[e.length];return t||=g[e.length]=p(e.length),t.apply(void 0,e)}function v(e,t,n,r,i,a,o){return function(t,n,s,c,l){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,s);case 4:return a(t,n,s,c);case 5:return o(t,n,s,c,l)}for(var u=Array(arguments.length),d=0;d<arguments.length;++d)u[d]=arguments[d];return e(u)}}function y(){for(;g.length<=o;)g.push(p(g.length));t.exports=v.apply(void 0,[_].concat(g));for(var e=0;e<=o;++e)t.exports[e]=g[e]}y()}}),Od=bd({"node_modules/cdt2d/lib/monotone.js"(e,t){"use strict";var n=xd(),r=Dd()[3],i=0,a=1,o=2;t.exports=h;function s(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function c(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function l(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==i&&(n=r(e.a,e.b,t.b),n)?n:e.idx-t.idx}function u(e,t){return r(e.a,e.b,t)}function d(e,t,i,a,o){for(var s=n.lt(t,a,u),c=n.gt(t,a,u),l=s;l<c;++l){for(var d=t[l],f=d.lowerIds,p=f.length;p>1&&r(i[f[p-2]],i[f[p-1]],a)>0;)e.push([f[p-1],f[p-2],o]),--p;f.length=p,f.push(o);for(var m=d.upperIds,p=m.length;p>1&&r(i[m[p-2]],i[m[p-1]],a)<0;)e.push([m[p-2],m[p-1],o]),--p;m.length=p,m.push(o)}}function f(e,t){var n=e.a[0]<t.a[0]?r(e.a,e.b,t.a):r(t.b,t.a,e.a);return n||(n=t.b[0]<e.b[0]?r(e.a,e.b,t.b):r(t.b,t.a,e.b),n||e.idx-t.idx)}function p(e,t,r){var i=n.le(e,r,f),a=e[i],o=a.upperIds,c=o[o.length-1];a.upperIds=[c],e.splice(i+1,0,new s(r.a,r.b,r.idx,[c],o))}function m(e,t,r){var i=r.a;r.a=r.b,r.b=i;var a=n.eq(e,r,f),o=e[a],s=e[a-1];s.upperIds=o.upperIds,e.splice(a,1)}function h(e,t){for(var n=e.length,r=t.length,u=[],f=0;f<n;++f)u.push(new c(e[f],null,i,f));for(var f=0;f<r;++f){var h=t[f],g=e[h[0]],_=e[h[1]];g[0]<_[0]?u.push(new c(g,_,o,f),new c(_,g,a,f)):g[0]>_[0]&&u.push(new c(_,g,o,f),new c(g,_,a,f))}u.sort(l);for(var v=u[0].a[0]-(1+Math.abs(u[0].a[0]))*2**-52,y=[new s([v,1],[v,0],-1,[],[],[],[])],b=[],f=0,x=u.length;f<x;++f){var S=u[f],C=S.type;C===i?d(b,y,e,S.a,S.idx):C===o?p(y,e,S):m(y,e,S)}return b}}}),kd=bd({"node_modules/cdt2d/lib/triangulation.js"(e,t){"use strict";var n=xd();t.exports=o;function r(e,t){this.stars=e,this.edges=t}var i=r.prototype;function a(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}i.isConstraint=(function(){var e=[0,0];function t(e,t){return e[0]-t[0]||e[1]-t[1]}return function(r,i){return e[0]=Math.min(r,i),e[1]=Math.max(r,i),n.eq(this.edges,e,t)>=0}})(),i.removeTriangle=function(e,t,n){var r=this.stars;a(r[e],t,n),a(r[t],n,e),a(r[n],e,t)},i.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)},i.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1},i.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)},i.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2)t.push([i[a],i[a+1]]);return t},i.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2){var s=i[a],c=i[a+1];n<Math.min(s,c)&&t.push([n,s,c])}return t};function o(e,t){for(var n=Array(e),i=0;i<e;++i)n[i]=[];return new r(n,t)}}}),Ad=bd({"node_modules/robust-in-sphere/in-sphere.js"(e,t){"use strict";var n=Sd(),r=Cd(),i=Ed(),a=Td(),o=6;function s(e){return(e===3?d:e===4?f:e===5?p:m)(r,i,n,a)}function c(){return 0}function l(){return 0}function u(){return 0}function d(e,t,n,r){function i(i,a,o){var s=n(i[0],i[0]),c=r(s,a[0]),l=r(s,o[0]),u=n(a[0],a[0]),d=r(u,i[0]),f=r(u,o[0]),p=n(o[0],o[0]),m=r(p,i[0]),h=t(e(t(r(p,a[0]),f),t(d,c)),t(m,l));return h[h.length-1]}return i}function f(e,t,n,r){function i(i,a,o,s){var c=e(n(i[0],i[0]),n(i[1],i[1])),l=r(c,a[0]),u=r(c,o[0]),d=r(c,s[0]),f=e(n(a[0],a[0]),n(a[1],a[1])),p=r(f,i[0]),m=r(f,o[0]),h=r(f,s[0]),g=e(n(o[0],o[0]),n(o[1],o[1])),_=r(g,i[0]),v=r(g,a[0]),y=r(g,s[0]),b=e(n(s[0],s[0]),n(s[1],s[1])),x=r(b,i[0]),S=r(b,a[0]),C=r(b,o[0]),w=t(e(e(r(t(C,y),a[1]),e(r(t(S,h),-o[1]),r(t(v,m),s[1]))),e(r(t(S,h),i[1]),e(r(t(x,d),-a[1]),r(t(p,l),s[1])))),e(e(r(t(C,y),i[1]),e(r(t(x,d),-o[1]),r(t(_,u),s[1]))),e(r(t(v,m),i[1]),e(r(t(_,u),-a[1]),r(t(p,l),o[1])))));return w[w.length-1]}return i}function p(e,t,n,r){function i(i,a,o,s,c){var l=e(n(i[0],i[0]),e(n(i[1],i[1]),n(i[2],i[2]))),u=r(l,a[0]),d=r(l,o[0]),f=r(l,s[0]),p=r(l,c[0]),m=e(n(a[0],a[0]),e(n(a[1],a[1]),n(a[2],a[2]))),h=r(m,i[0]),g=r(m,o[0]),_=r(m,s[0]),v=r(m,c[0]),y=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),b=r(y,i[0]),x=r(y,a[0]),S=r(y,s[0]),C=r(y,c[0]),w=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),T=r(w,i[0]),E=r(w,a[0]),D=r(w,o[0]),O=r(w,c[0]),k=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),A=r(k,i[0]),j=r(k,a[0]),M=r(k,o[0]),N=r(k,s[0]),ee=t(e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),a[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),-o[2]),r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),s[2]))),e(r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),-c[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-a[2])))),e(e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),s[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),-c[2]),r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),i[2]))),e(r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-a[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-s[2]))))),e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-o[2])),e(r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),s[2]),r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-c[2]))),e(e(r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),i[2]),r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),-a[2])),e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-c[2])))));return ee[ee.length-1]}return i}function m(e,t,n,r){function i(i,a,o,s,c,l){var u=e(e(n(i[0],i[0]),n(i[1],i[1])),e(n(i[2],i[2]),n(i[3],i[3]))),d=r(u,a[0]),f=r(u,o[0]),p=r(u,s[0]),m=r(u,c[0]),h=r(u,l[0]),g=e(e(n(a[0],a[0]),n(a[1],a[1])),e(n(a[2],a[2]),n(a[3],a[3]))),_=r(g,i[0]),v=r(g,o[0]),y=r(g,s[0]),b=r(g,c[0]),x=r(g,l[0]),S=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),C=r(S,i[0]),w=r(S,a[0]),T=r(S,s[0]),E=r(S,c[0]),D=r(S,l[0]),O=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),k=r(O,i[0]),A=r(O,a[0]),j=r(O,o[0]),M=r(O,c[0]),N=r(O,l[0]),ee=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),P=r(ee,i[0]),F=r(ee,a[0]),I=r(ee,o[0]),L=r(ee,s[0]),R=r(ee,l[0]),te=e(e(n(l[0],l[0]),n(l[1],l[1])),e(n(l[2],l[2]),n(l[3],l[3]))),z=r(te,i[0]),B=r(te,a[0]),V=r(te,o[0]),H=r(te,s[0]),U=r(te,c[0]),ne=t(e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),a[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),s[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),i[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-a[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),o[3])),e(r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),l[3]))))),e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),i[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),o[3]),r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),i[3]))),e(e(r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),-a[3]),r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),o[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),c[3]))))));return ne[ne.length-1]}return i}var h=[c,l,u];function g(e){var t=h[e.length];return t||=h[e.length]=s(e.length),t.apply(void 0,e)}function _(e,t,n,r,i,a,o,s){function c(t,n,c,l,u,d){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,c);case 4:return a(t,n,c,l);case 5:return o(t,n,c,l,u);case 6:return s(t,n,c,l,u,d)}for(var f=Array(arguments.length),p=0;p<arguments.length;++p)f[p]=arguments[p];return e(f)}return c}function v(){for(;h.length<=o;)h.push(s(h.length));t.exports=_.apply(void 0,[g].concat(h));for(var e=0;e<=o;++e)t.exports[e]=h[e]}v()}}),jd=bd({"node_modules/cdt2d/lib/delaunay.js"(e,t){"use strict";var n=Ad()[4];xd(),t.exports=i;function r(e,t,r,i,a,o){var s=t.opposite(i,a);if(!(s<0)){if(a<i){var c=i;i=a,a=c,c=o,o=s,s=c}t.isConstraint(i,a)||n(e[i],e[a],e[o],e[s])<0&&r.push(i,a)}}function i(e,t){for(var i=[],a=e.length,o=t.stars,s=0;s<a;++s)for(var c=o[s],l=1;l<c.length;l+=2){var u=c[l];if(!(u<s)&&!t.isConstraint(s,u)){for(var d=c[l-1],f=-1,p=1;p<c.length;p+=2)if(c[p-1]===u){f=c[p];break}f<0||n(e[s],e[u],e[d],e[f])<0&&i.push(s,u)}}for(;i.length>0;){for(var u=i.pop(),s=i.pop(),d=-1,f=-1,c=o[s],m=1;m<c.length;m+=2){var h=c[m-1],g=c[m];h===u?f=g:g===u&&(d=h)}d<0||f<0||n(e[s],e[u],e[d],e[f])>=0||(t.flip(s,u),r(e,t,i,d,s,f),r(e,t,i,s,f,d),r(e,t,i,f,u,d),r(e,t,i,u,d,f))}}}}),Md=bd({"node_modules/cdt2d/lib/filter.js"(e,t){"use strict";var n=xd();t.exports=c;function r(e,t,n,r,i,a,o){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=a,this.boundary=o}var i=r.prototype;function a(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}i.locate=(function(){var e=[0,0,0];return function(t,r,i){var o=t,s=r,c=i;return r<i?r<t&&(o=r,s=i,c=t):i<t&&(o=i,s=t,c=r),o<0?-1:(e[0]=o,e[1]=s,e[2]=c,n.eq(this.cells,e,a))}})();function o(e,t){for(var n=e.cells(),i=n.length,o=0;o<i;++o){var s=n[o],c=s[0],l=s[1],u=s[2];l<u?l<c&&(s[0]=l,s[1]=u,s[2]=c):u<c&&(s[0]=u,s[1]=c,s[2]=l)}n.sort(a);for(var d=Array(i),o=0;o<d.length;++o)d[o]=0;var f=[],p=[],m=Array(3*i),h=Array(3*i),g=null;t&&(g=[]);for(var _=new r(n,m,h,d,f,p,g),o=0;o<i;++o)for(var s=n[o],v=0;v<3;++v){var c=s[v],l=s[(v+1)%3],y=m[3*o+v]=_.locate(l,c,e.opposite(l,c)),b=h[3*o+v]=e.isConstraint(c,l);y<0&&(b?p.push(o):(f.push(o),d[o]=1),t&&g.push([l,c,-1]))}return _}function s(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function c(e,t,n){var r=o(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,a=r.active,c=r.next,l=r.flags,u=r.cells,d=r.constraint,f=r.neighbor;a.length>0||c.length>0;){for(;a.length>0;){var p=a.pop();if(l[p]!==-i){l[p]=i,u[p];for(var m=0;m<3;++m){var h=f[3*p+m];h>=0&&l[h]===0&&(d[3*p+m]?c.push(h):(a.push(h),l[h]=i))}}}var g=c;c=a,a=g,c.length=0,i=-i}var _=s(u,l,t);return n?_.concat(r.boundary):_}}}),Nd=bd({"node_modules/cdt2d/cdt2d.js"(e,t){var n=Od(),r=kd(),i=jd(),a=Md();t.exports=u;function o(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function s(e,t){return e[0]-t[0]||e[1]-t[1]}function c(e){return e.map(o).sort(s)}function l(e,t,n){return t in e?e[t]:n}function u(e,t,o){Array.isArray(t)?(o||={},t||=[]):(o=t||{},t=[]);var s=!!l(o,`delaunay`,!0),u=!!l(o,`interior`,!0),d=!!l(o,`exterior`,!0),f=!!l(o,`infinity`,!1);if(!u&&!d||e.length===0)return[];var p=n(e,t);if(s||u!==d||f){for(var m=r(e.length,c(t)),h=0;h<p.length;++h){var g=p[h];m.addTriangle(g[0],g[1],g[2])}return s&&i(e,m),d?u?f?a(m,0,f):m.cells():a(m,1,f):a(m,-1)}return p}}})(),Pd=class{constructor(e){this.createFn=e,this._pool=[],this._index=0}getInstance(){return this._index>=this._pool.length&&this._pool.push(this.createFn()),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}},Fd=1e-16,Id=1e-16,Ld=new J,Rd=new J,zd=new Pd(()=>({param:0,index:0})),Bd=new Pd(()=>new J);function Vd(e,t,n,r){zd.clear(),t.length=0,n.length=0;for(let t=0,n=e.length;t<n;t++){let n=e[t];c(n.start),c(n.end)}for(let t=0,n=e.length;t<n;t++){let i=e[t];for(let a=t+1;a<n;a++){let t=e[a];i.distanceSqToLine3(t,Ld,Rd)<Fd*r&&c(Rd)}}let i=[];for(let a=0,o=e.length;a<o;a++){i.length=0;let o=e[a];for(let e=0,n=t.length;e<n;e++){let n=t[e],a=o.closestPointToPointParameter(n,!0);if(o.at(a,Ld),n.distanceToSquared(Ld)<Fd*r){let t=zd.getInstance();t.param=a,t.index=e,i.push(t)}}i.sort(s);for(let e=0,t=i.length-1;e<t;e++){let t=i[e].index,r=i[e+1].index;t!==r&&n.push([t,r])}}let a=new Set,o=0;for(let e=0,t=n.length;e<t;e++){let t=n[e],r=Math.min(t[0],t[1]),i=Math.max(t[0],t[1]),s=r+`,`+i;a.has(s)||(a.add(s),n[o++]=t)}n.length=o;function s(e,t){return e.param-t.param}function c(e){for(let n=0;n<t.length;n++){let i=t[n];if(e===i||e.distanceToSquared(i)<Id*r)return n}return t.push(Bd.getInstance().copy(e)),t.length-1}}var Hd=class{constructor(){this.trianglePool=new Pd(()=>new pl),this.linePool=new Pd(()=>new bs),this.triangles=[],this.triangleIndices=[],this.constrainedEdges=[],this.triangleConnectivity=[],this.normal=new J,this.projOrigin=new J,this.projU=new J,this.projV=new J,this.baseTri=new pl,this.baseIndices=[,,,]}initialize(e,t=null,n=null,r=null){this.reset();let{normal:i,baseTri:a,projU:o,projV:s,projOrigin:c,constrainedEdges:l,linePool:u,baseIndices:d}=this;e.getNormal(i),a.copy(e),a.update(),d[0]=t,d[1]=n,d[2]=r,l.length=0;let f=u.getInstance();f.start.copy(a.a),f.end.copy(a.b);let p=u.getInstance();p.start.copy(a.b),p.end.copy(a.c);let m=u.getInstance();m.start.copy(a.c),m.end.copy(a.a),l.push(f,p,m),c.copy(a.a),o.subVectors(a.b,a.a).normalize(),s.crossVectors(i,o).normalize()}addConstraintEdge(e){let{constrainedEdges:t,linePool:n}=this,r=n.getInstance().copy(e);t.push(r)}_to2D(e,t){let{projOrigin:n,projU:r,projV:i}=this;return Ld.subVectors(e,n),t.set(Ld.dot(r),Ld.dot(i),0)}_from2D(e,t,n){let{projOrigin:r,projU:i,projV:a}=this;return n.copy(r).addScaledVector(i,e).addScaledVector(a,t),n}triangulate(){let{triangles:e,trianglePool:t,triangleConnectivity:n,triangleIndices:r,linePool:i,baseTri:a,constrainedEdges:o,baseIndices:s}=this;e.length=0,t.clear();let c=[];for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.getInstance();this._to2D(t.start,n.start),this._to2D(t.end,n.end),c.push(n)}let l=0;for(let e=0;e<3;e++){let t=this._to2D(a.points[e],Ld);l=Math.max(l,Math.abs(t.x),Math.abs(t.y))}let u=[],d=[];Vd(c,u,d,l);let f=[];for(let e=0,t=u.length;e<t;e++){let t=u[e];f.push([t.x,t.y])}let p=Nd(f,d,{exterior:!1}),m=new Map;for(let e=0,t=d.length;e<t;e++){let t=d[e];m.set(`${t[0]}_${t[1]}`,-1),m.set(`${t[1]}_${t[0]}`,-1)}let h=`${s[0]}_${s[1]}_${s[2]}_`;for(let i=0,a=p.length;i<a;i++){let a=p[i],[o,c,l]=a,u=t.getInstance();this._from2D(f[o][0],f[o][1],u.a),this._from2D(f[c][0],f[c][1],u.b),this._from2D(f[l][0],f[l][1],u.c),e.push(u);let d=[];n.push(d);let g=[];r.push(g);for(let e=0;e<3;e++){let t=a[e];g.push(t<3?s[t]:h+t);let r=a[(e+1)%3],o=`${t}_${r}`;if(m.has(o)){let e=m.get(o);e!==-1&&(d.push(e),n[e].push(i))}else{let e=`${r}_${t}`;m.set(e,i)}}}}reset(){this.trianglePool.clear(),this.linePool.clear(),this.triangles.length=0,this.triangleIndices.length=0,this.triangleConnectivity.length=0,this.constrainedEdges.length=0}},Ud=1e-14,Wd=new J,Gd=new J,Kd=new J;function qd(e,t=Ud){Wd.subVectors(e.b,e.a),Gd.subVectors(e.c,e.a),Kd.subVectors(e.b,e.c);let n=Wd.angleTo(Gd),r=Wd.angleTo(Kd),i=Math.PI-n-r;return Math.abs(n)<t||Math.abs(r)<t||Math.abs(i)<t||e.a.distanceToSquared(e.b)<t||e.a.distanceToSquared(e.c)<t||e.b.distanceToSquared(e.c)<t}var Jd=1e-10,Yd=1e-10,Xd=new bs,Zd=new bs,Qd=new J,$d=new J,ef=new J,tf=new di,nf=new pl,rf=class{constructor(){this.trianglePool=new Pd(()=>new nr),this.triangles=[],this.normal=new J}initialize(e){this.reset();let{triangles:t,trianglePool:n,normal:r}=this;if(Array.isArray(e))for(let i=0,a=e.length;i<a;i++){let a=e[i];if(i===0)a.getNormal(r);else if(Math.abs(1-a.getNormal(Qd).dot(r))>Jd)throw Error(`Triangle Splitter: Cannot initialize with triangles that have different normals.`);let o=n.getInstance();o.copy(a),t.push(o)}else{e.getNormal(r);let i=n.getInstance();i.copy(e),t.push(i)}}splitByTriangle(e,t){let{triangles:n}=this;if(t){for(let e=0,t=n.length;e<t;e++){let t=n[e];t.coplanarCount=0}let t=[e.a,e.b,e.c];for(let n=0;n<3;n++){let r=(n+1)%3,i=t[n],a=t[r];e.getNormal($d).normalize(),Qd.subVectors(a,i).normalize(),ef.crossVectors($d,Qd),tf.setFromNormalAndCoplanarPoint(ef,i),this.splitByPlane(tf,e)}}else e.getPlane(tf),this.splitByPlane(tf,e)}splitByPlane(e,t){let{triangles:n,trianglePool:r}=this;nf.copy(t),nf.needsUpdate=!0;for(let t=0,i=n.length;t<i;t++){let a=n[t];if(!nf.intersectsTriangle(a,Xd,!0))continue;let{a:o,b:s,c}=a,l=0,u=-1,d=!1,f=[],p=[],m=[o,s,c];for(let t=0;t<3;t++){let n=(t+1)%3;Xd.start.copy(m[t]),Xd.end.copy(m[n]);let r=e.distanceToPoint(Xd.start),i=e.distanceToPoint(Xd.end);if(Math.abs(r)<Yd&&Math.abs(i)<Yd){d=!0;break}if(r>0?f.push(t):p.push(t),Math.abs(r)<Yd)continue;let a=!!e.intersectLine(Xd,Qd);!a&&Math.abs(i)<Yd&&(Qd.copy(Xd.end),a=!0),a&&!(Qd.distanceTo(Xd.start)<Jd)&&(Qd.distanceTo(Xd.end)<Jd&&(u=t),l===0?Zd.start.copy(Qd):Zd.end.copy(Qd),l++)}if(!d&&l===2&&Zd.distance()>Yd){if(u!==-1){u=(u+1)%3;let e=0;e===u&&(e=(e+1)%3);let o=e+1;o===u&&(o=(o+1)%3);let s=r.getInstance();s.a.copy(m[o]),s.b.copy(Zd.end),s.c.copy(Zd.start),qd(s)||n.push(s),a.a.copy(m[e]),a.b.copy(Zd.start),a.c.copy(Zd.end),qd(a)&&(n.splice(t,1),t--,i--)}else{let e=f.length>=2?p[0]:f[0];if(e===0){let e=Zd.start;Zd.start=Zd.end,Zd.end=e}let o=(e+1)%3,s=(e+2)%3,c=r.getInstance(),l=r.getInstance();m[o].distanceToSquared(Zd.start)<m[s].distanceToSquared(Zd.end)?(c.a.copy(m[o]),c.b.copy(Zd.start),c.c.copy(Zd.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Zd.start)):(c.a.copy(m[s]),c.b.copy(Zd.start),c.c.copy(Zd.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Zd.end)),a.a.copy(m[e]),a.b.copy(Zd.end),a.c.copy(Zd.start),qd(c)||n.push(c),qd(l)||n.push(l),qd(a)&&(n.splice(t,1),t--,i--)}}else l===3&&console.warn(`TriangleClipper: Coplanar clip not handled`)}}reset(){this.triangles.length=0,this.trianglePool.clear()}},af=class{constructor(){this.coplanarSet=new Map,this.intersectionSet=new Map,this.edgeSet=new Map,this.ids=[]}add(e,t,n=!1){let{intersectionSet:r,coplanarSet:i,ids:a}=this;r.has(e)||(r.set(e,[]),a.push(e)),r.get(e).push(t),n&&(i.has(e)||i.set(e,new Set),i.get(e).add(t))}addIntersectionEdge(e,t){let{edgeSet:n}=this;n.has(e)||n.set(e,new Set),n.get(e).add(t)}getIntersectionEdges(e){return this.edgeSet.get(e)||null}},of=1e-10,sf=1e-15,cf=1e-10,lf=1e-10,uf=new bs,df=new bs,ff=new J,pf=new J,mf=new J,hf=new di,gf=new J,_f=new J;function vf(e,t){e.getNormal(gf),t.getNormal(_f);let n=gf.dot(_f);if(Math.abs(1-Math.abs(n))>=cf)return!1;let r=gf.dot(e.a),i=gf.dot(t.a);return Math.abs(r-i)<lf}function yf(e,t,n,r){let i=0,a=1;e.delta(ff);let o=[t.a,t.b,t.c];for(let t=0;t<3;t++){let r=o[t],s=o[(t+1)%3];pf.subVectors(s,r),mf.crossVectors(n,pf),hf.setFromNormalAndCoplanarPoint(mf,r);let c=hf.distanceToPoint(e.start),l=hf.normal.dot(ff);if(Math.abs(l)<sf){if(c<-1e-10)return null;continue}let u=-c/l;if(l>0?i=Math.max(i,u):a=Math.min(a,u),i>a+of)return null}return a-i<of?null:(e.at(i,r.start),e.at(a,r.end),r)}function bf(e,t,n){let r=0;e.getNormal(gf),t.getNormal(_f);let i=[t.a,t.b,t.c];for(let t=0;t<3;t++){df.start.copy(i[t]),df.end.copy(i[(t+1)%3]);let a=yf(df,e,gf,uf);a!==null&&(r>=n.length&&n.push(new bs),n[r].copy(a),r++)}let a=[e.a,e.b,e.c];for(let e=0;e<3;e++){df.start.copy(a[e]),df.end.copy(a[(e+1)%3]);let i=yf(df,t,_f,uf);i!==null&&(r>=n.length&&n.push(new bs),n[r].copy(i),r++)}return r}var xf=new Gr,Sf=new Y,Cf=new bs,wf=[],Tf=new Pd(()=>new bs),Ef=null;function Df(e){Ef=e}function Of(e,t,n=null){e.getMidpoint(xf.origin),e.getNormal(xf.direction),n&&(xf.origin.applyMatrix4(n),xf.direction.transformDirection(n));let r=t.raycastFirst(xf,2);return r&&xf.direction.dot(r.face.normal)>0?-1:1}function kf(e,t){let n=new af,r=new af;return Tf.clear(),Sf.copy(e.matrixWorld).invert().multiply(t.matrixWorld),e.geometry.boundsTree.bvhcast(t.geometry.boundsTree,Sf,{intersectsTriangles(i,a,o,s){if(!qd(i)&&!qd(a)){let c=(vf(i,a)?bf(i,a,wf):0)>2;if(c||i.intersectsTriangle(a,Cf,!0)){let l=e.geometry.boundsTree.resolveTriangleIndex(o),u=t.geometry.boundsTree.resolveTriangleIndex(s);if(n.add(l,u,c),r.add(u,l,c),c){let e=bf(i,a,wf);for(let t=0;t<e;t++){let e=Tf.getInstance().copy(wf[t]);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,e)}}else{let e=Tf.getInstance().copy(Cf),t=Tf.getInstance().copy(Cf);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,t)}Ef&&(Ef.addEdge(Cf),Ef.addIntersectingTriangles(o,i,s,a))}}return!1}}),{aIntersections:n,bIntersections:r}}function Af(e,t,n=!1){switch(e){case 0:if(t===1||t===2&&!n)return 1;break;case 1:if(n){if(t===-1)return 0}else if(t===1||t===-2)return 1;break;case 2:if(n){if(t===1||t===-2)return 1}else if(t===-1)return 0;break;case 4:if(t===-1)return 0;if(t===1)return 1;break;case 3:if(t===-1||t===2&&!n)return 1;break;case 5:if(!n&&(t===1||t===-2))return 1;break;case 6:if(!n&&(t===-1||t===2))return 1;break;default:throw Error(`Unrecognized CSG operation enum "${e}".`)}return 2}var jf=class{constructor(e){this.triangle=new nr().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new nr().copy(t)}getIntersectArray(){let e=[],{intersects:t}=this;for(let n in t)e.push(t[n]);return e}},Mf=class{constructor(){this.data={}}addTriangleIntersection(e,t,n,r){let{data:i}=this;i[e]||(i[e]=new jf(t)),i[e].addTriangle(n,r)}getTrianglesAsArray(e=null){let{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(let e in t)n.push(t[e].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){let{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(e=>parseInt(e)):[]}getIntersectionsAsArray(e=null,t=null){let{data:n}=this,r=new Set,i=[],a=e=>{if(n[e]){if(t!==null)n[e].intersects[t]&&i.push(n[e].intersects[t]);else{let t=n[e].intersects;for(let e in t)r.has(e)||(r.add(e),i.push(t[e]))}}};if(e!==null)a(e);else for(let e in n)a(e);return i}reset(){this.data={}}},Nf=class{constructor(){this.enabled=!1,this.triangleIntersectsA=new Mf,this.triangleIntersectsB=new Mf,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,r){let{triangleIntersectsA:i,triangleIntersectsB:a}=this;i.addTriangleIntersection(e,t,n,r),a.addTriangleIntersection(n,r,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),Df(this))}complete(){this.enabled&&Df(null)}},Pf=new Y,Ff=new Y,If=new Y,Lf=new Rt,Rf=new nr,zf=new nr,Bf=new nr,Vf=new nr,Hf=[],Uf=[],Wf=new Set,Gf=new J,Kf=new J,qf=new Pd(()=>new nr),Jf=new J,Yf=[];function Xf(e,t,n,r,i,a={}){let{useGroups:o=!0}=a,{aIntersections:s,bIntersections:c}=kf(e,t),l=[],u;return u=o?0:-1,Qf(e,t,s,n,!1,i,u),Zf(e,t,s,n,!1,r,i,u),n.findIndex(e=>e!==6&&e!==5)!==-1&&(i.forEach(e=>e.clearIndexMap()),u=o?e.geometry.groups.length||1:-1,Qf(t,e,c,n,!0,i,u),Zf(t,e,c,n,!0,r,i,u)),i.forEach(e=>e.clearIndexMap()),Hf.length=0,{groups:l,materials:null}}function Zf(e,t,n,r,i,a,o,s=0){Pf.copy(t.matrixWorld).invert().multiply(e.matrixWorld),Ff.copy(Pf).invert(),i?If.copy(Pf):If.identity();let c=If.determinant()<0;Lf.getNormalMatrix(If).multiplyScalar(c?-1:1);let l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=t.geometry.boundsTree,p=t.geometry.index,m=t.geometry.attributes.position,h=n.ids;for(let t=0,g=h.length;t<g;t++){let g=h[t],_=s===-1?0:l[g]+s,v=3*g,y=v+0,b=v+1,x=v+2;u&&(y=u.getX(y),b=u.getX(b),x=u.getX(x)),Rf.a.fromBufferAttribute(d,y),Rf.b.fromBufferAttribute(d,b),Rf.c.fromBufferAttribute(d,x),i&&(Rf.a.applyMatrix4(Pf),Rf.b.applyMatrix4(Pf),Rf.c.applyMatrix4(Pf)),a.reset(),a.initialize(Rf,y,b,x),Yf.length=0,qf.clear(),Rf.getNormal(Kf);let S=n.coplanarSet.get(g);if(S)for(let e of S){let t=3*e,n=t+0,r=t+1,a=t+2;p&&(n=p.getX(n),r=p.getX(r),a=p.getX(a));let o=qf.getInstance();o.a.fromBufferAttribute(m,n),o.b.fromBufferAttribute(m,r),o.c.fromBufferAttribute(m,a),i||(o.a.applyMatrix4(Ff),o.b.applyMatrix4(Ff),o.c.applyMatrix4(Ff)),Yf.push(o)}if(a.addConstraintEdge){let e=n.getIntersectionEdges(g);if(e)for(let t of e)a.addConstraintEdge(t);a.triangulate()}else{let e=n.intersectionSet.get(g);for(let t=0,n=e.length;t<n;t++){let n=e[t],r=S&&S.has(n),o=3*n,s=o+0,c=o+1,l=o+2;p&&(s=p.getX(s),c=p.getX(c),l=p.getX(l)),zf.a.fromBufferAttribute(m,s),zf.b.fromBufferAttribute(m,c),zf.c.fromBufferAttribute(m,l),i||(zf.a.applyMatrix4(Ff),zf.b.applyMatrix4(Ff),zf.c.applyMatrix4(Ff)),a.splitByTriangle(zf,r)}}let{triangles:C,triangleIndices:w=[],triangleConnectivity:T=[]}=a;for(let t=0,n=o.length;t<n;t++)o[t].initInterpolatedAttributeData(e.geometry,If,Lf,y,b,x);Wf.clear();for(let e=0,t=C.length;e<t;e++){if(Wf.has(e))continue;let t=C[e],n=i?null:Pf,a=null;t.getMidpoint(Gf);for(let e=0,t=Yf.length;e<t;e++){let t=Yf[e];if(t.containsPoint(Gf)){t.getNormal(Jf),a=Kf.dot(Jf)>0?2:-2;break}}a===null&&(a=Of(t,f,n)),Hf.length=0,Uf.length=0;for(let e=0,t=r.length;e<t;e++){let t=Af(r[e],a,i);t!==2&&(Hf.push(t),Uf.push(o[e]))}if(Uf.length!==0){let t=[e];for(;t.length>0;){let e=t.pop();if(Wf.has(e))continue;Wf.add(e);let n=w[e],r=null,i=null,a=null;n&&(r=n[0],i=n[1],a=n[2]);let o=C[e];Rf.getBarycoord(o.a,Vf.a),Rf.getBarycoord(o.b,Vf.b),Rf.getBarycoord(o.c,Vf.c);for(let e=0,t=Uf.length;e<t;e++){let t=Uf[e],n=c!==(Hf[e]===0);t.appendInterpolatedAttributeData(_,Vf.a,r,n),n?(t.appendInterpolatedAttributeData(_,Vf.c,a,n),t.appendInterpolatedAttributeData(_,Vf.b,i,n)):(t.appendInterpolatedAttributeData(_,Vf.b,i,n),t.appendInterpolatedAttributeData(_,Vf.c,a,n))}}}}}return h.length}function Qf(e,t,n,r,i,a,o=0){Pf.copy(t.matrixWorld).invert().multiply(e.matrixWorld),i?If.copy(Pf):If.identity();let s=If.determinant()<0;Lf.getNormalMatrix(If).multiplyScalar(s?-1:1);let c=t.geometry.boundsTree,l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=[],p=e.geometry.halfEdges,m=new Set(n.ids),h=Qu(e.geometry);for(let t=0;t<h&&m.size!==h;t++){if(m.has(t))continue;m.add(t),f.push(t);let n=3*t,h=n+0,g=n+1,_=n+2;u&&(h=u.getX(h),g=u.getX(g),_=u.getX(_)),Bf.a.fromBufferAttribute(d,h),Bf.b.fromBufferAttribute(d,g),Bf.c.fromBufferAttribute(d,_),i&&(Bf.a.applyMatrix4(Pf),Bf.b.applyMatrix4(Pf),Bf.c.applyMatrix4(Pf));let v=Of(Bf,c,i?null:Pf);Hf.length=0,Uf.length=0;for(let e=0,t=r.length;e<t;e++){let t=Af(r[e],v,i);t!==2&&(Hf.push(t),Uf.push(a[e]))}for(;f.length>0;){let t=f.pop();for(let e=0;e<3;e++){let n=p.getSiblingTriangleIndex(t,e);n!==-1&&!m.has(n)&&(f.push(n),m.add(n))}if(Uf.length!==0){let n=3*t,r=n+0,i=n+1,a=n+2;u&&(r=u.getX(r),i=u.getX(i),a=u.getX(a));let c=o===-1?0:l[t]+o;if(Bf.a.fromBufferAttribute(d,r),Bf.b.fromBufferAttribute(d,i),Bf.c.fromBufferAttribute(d,a),!qd(Bf))for(let t=0,n=Uf.length;t<n;t++){let n=Uf[t],o=Hf[t]===0!==s;n.appendIndexFromGeometry(e.geometry,If,Lf,c,r,o),o?(n.appendIndexFromGeometry(e.geometry,If,Lf,c,a,o),n.appendIndexFromGeometry(e.geometry,If,Lf,c,i,o)):(n.appendIndexFromGeometry(e.geometry,If,Lf,c,i,o),n.appendIndexFromGeometry(e.geometry,If,Lf,c,a,o))}}}}}function $f(e){return e=~~e,e+4-e%4}var ep=class{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(e===this.type)return;if(this.length!==0)throw Error(`TypeBackedArray: Cannot change the type while there is used data in the buffer.`);let t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;let t=this.type,n=new t(new(Yu()?SharedArrayBuffer:ArrayBuffer)($f(e*t.BYTES_PER_ELEMENT)));this.array&&n.set(this.array,0),this.array=n}expand(){let{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let r=0,i=e.length;r<i;r++)t[n+r]=e[r];this.length+=e.length}clear(){this.length=0}},tp=new J,np=new J,rp=new J,ip=new J,ap=new en,op=new en,sp=new en,cp=new en;function lp(e,t,n,r,i,a=!1,o=!1){return i.set(0,0,0,0).addScaledVector(e,r.x).addScaledVector(t,r.y).addScaledVector(n,r.z),a&&i.normalize(),o&&i.multiplyScalar(-1),i}function up(e,t,n){switch(t){case 1:n.push(e.x);break;case 2:n.push(e.x,e.y);break;case 3:n.push(e.x,e.y,e.z);break;case 4:n.push(e.x,e.y,e.z,e.w)}}var dp=class extends ep{get count(){return this.length/this.itemSize}constructor(...e){super(...e),this.itemSize=1,this.normalized=!1}},fp=class{constructor(){this.attributeData={},this.groupIndices=[],this.forwardIndexMap=new Map,this.invertedIndexMap=new Map,this.interpolatedFields={}}initFromGeometry(e,t){this.clear();let{attributeData:n}=this,r=e.attributes;for(let e=0,i=t.length;e<i;e++){let i=t[e],a=r[i],o=a.array.constructor;n[i]||(n[i]=new dp(o)),n[i].setType(o),n[i].itemSize=a.itemSize,n[i].normalized=a.normalized}for(let e in n.attributes)t.includes(e)||n.delete(e)}initInterpolatedAttributeData(e,t,n,r,i,a){let{attributeData:o,interpolatedFields:s}=this,{attributes:c}=e;for(let e in o){let o=c[e];if(!o)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l,u,d;if(e===`position`?(l=np.fromBufferAttribute(o,r).applyMatrix4(t),u=rp.fromBufferAttribute(o,i).applyMatrix4(t),d=ip.fromBufferAttribute(o,a).applyMatrix4(t)):e===`normal`?(l=np.fromBufferAttribute(o,r).applyNormalMatrix(n),u=rp.fromBufferAttribute(o,i).applyNormalMatrix(n),d=ip.fromBufferAttribute(o,a).applyNormalMatrix(n)):e===`tangent`?(l=np.fromBufferAttribute(o,r).transformDirection(t),u=rp.fromBufferAttribute(o,i).transformDirection(t),d=ip.fromBufferAttribute(o,a).transformDirection(t)):(l=op.fromBufferAttribute(o,r),u=sp.fromBufferAttribute(o,i),d=cp.fromBufferAttribute(o,a)),!s[e])s[e]=[l.clone(),u.clone(),d.clone()];else{let t=s[e];t[0].copy(l),t[1].copy(u),t[2].copy(d)}}}appendInterpolatedAttributeData(e,t,n=null,r=!1){let{groupIndices:i,attributeData:a,interpolatedFields:o,forwardIndexMap:s,invertedIndexMap:c}=this;for(;i.length<=e;)i.push(new dp(Uint32Array));let l=r?c:s,u=i[e];if(n!==null&&l.has(n))u.push(l.get(n));else{l.set(n,a.position.count),u.push(a.position.count);for(let e in o){let n=a[e],i=e===`normal`||e===`tangent`,s=r&&i,c=n.itemSize,[l,u,d]=o[e];lp(l,u,d,t,ap,i,s),up(ap,c,n)}}}appendIndexFromGeometry(e,t,n,r,i,a=!1){let{groupIndices:o,attributeData:s,forwardIndexMap:c,invertedIndexMap:l}=this;for(;o.length<=r;)o.push(new dp(Uint32Array));let u=a?l:c,d=o[r];if(i!==null&&u.has(i))d.push(u.get(i));else{u.set(i,s.position.count),d.push(s.position.count);let{attributes:r}=e;for(let e in s){let o=s[e],c=r[e];if(!c)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l=c.itemSize;e===`position`?(tp.fromBufferAttribute(c,i).applyMatrix4(t),o.push(tp.x,tp.y,tp.z)):e===`normal`?(tp.fromBufferAttribute(c,i).applyNormalMatrix(n),a&&tp.multiplyScalar(-1),o.push(tp.x,tp.y,tp.z)):e===`tangent`?(tp.fromBufferAttribute(c,i).transformDirection(t),a&&tp.multiplyScalar(-1),o.push(tp.x,tp.y,tp.z)):(ap.fromBufferAttribute(c,i),up(ap,l,o))}}}buildGeometry(e,t){let n=!1,{groupIndices:r,attributeData:i}=this,{attributes:a,index:o}=e;for(let t in i){let r=i[t],{type:o,itemSize:s,normalized:c,length:l,count:u}=r,d=r.array.buffer,f=a[t];(!f||f.count<u||f.array.type!==o)&&(f=new xr(new o(l),s,c),e.setAttribute(t,f),n=!0),f.array.set(new o(d,0,l),0),f.needsUpdate=!0}let s=r.reduce((e,t)=>t.count+e,0);(!e.index||o.count<s||o.array.type!==Uint32Array)&&(e.setIndex(new xr(new Uint32Array(s),1)),n=!0),e.clearGroups();let c=0;for(let n=0,i=Math.min(t.length,r.length);n<i;n++){let{index:i,materialIndex:a}=t[n],{count:o}=r[i],s=r[i].array.buffer;o!==0&&(e.index.array.set(new Uint32Array(s,0,o),c),e.addGroup(c,o,a),c+=o)}e.setDrawRange(0,c),e.boundsTree=null,e.boundingBox=null,e.boundingSphere=null,n&&e.dispose()}clearIndexMap(){this.forwardIndexMap.clear(),this.invertedIndexMap.clear()}clear(){let{groupIndices:e,attributeData:t}=this;this.interpolatedFields={};for(let e in t)t[e].clear();e.forEach(e=>{e.clear()}),this.clearIndexMap()}};function pp(e,t){for(let n in e.attributes)t.includes(n)||(e.deleteAttribute(n),e.dispose());return e}function mp(e,t){let n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=t[i.materialIndex];n.push({...i,materialIndex:t.indexOf(a)})}return n}function hp(e,t){let n=[],r=new Map;for(let i=0,a=e.length;i<a;i++){let a=e[i];r.has(a.materialIndex)||(r.set(a.materialIndex,n.length),n.push(t[a.materialIndex])),a.materialIndex=r.get(a.materialIndex)}return n}function gp(e){for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(n.materialIndex===r.materialIndex){let i=n.start,a=r.start+r.count;r.start=i,r.count=a-i,e.splice(t,1),t--}}}function _p(e,t){let n=t;return Array.isArray(t)||(n=[],e.forEach(e=>{n[e.materialIndex]=t})),n}var vp=class{get useCDTClipping(){return this.triangleSplitter instanceof Hd}set useCDTClipping(e){e!==this.useCDTClipping&&(this.triangleSplitter=e?new Hd:new rf)}constructor(){this.triangleSplitter=new rf,this.geometryBuilders=[],this.attributes=[`position`,`uv`,`normal`],this.useGroups=!0,this.consolidateGroups=!0,this.removeUnusedMaterials=!0,this.debug=new Nf}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(e=>({...e}))}evaluate(e,t,n,r=new vd){let i=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(r)||(r=[r],i=!1),r.length!==n.length)throw Error(`Evaluator: operations and target array passed as different sizes.`);e.prepareGeometry(),t.prepareGeometry();let{triangleSplitter:a,geometryBuilders:o,attributes:s,useGroups:c,consolidateGroups:l,removeUnusedMaterials:u,debug:d}=this;for(;o.length<r.length;)o.push(new fp);r.forEach((t,n)=>{o[n].initFromGeometry(e.geometry,s),pp(t.geometry,s)}),d.init(),Xf(e,t,n,a,o,{useGroups:c}),d.complete();let f=this.getGroupRanges(e.geometry),p=_p(f,e.material),m=this.getGroupRanges(t.geometry),h=_p(m,t.material);m.forEach(e=>e.materialIndex+=p.length);let g=[...p,...h],_=[...f,...m].map((e,t)=>({...e,index:t}));return c?c&&l&&(_=mp(_,g),_.sort((e,t)=>e.materialIndex-t.materialIndex)):_=[{start:0,count:1/0,index:0,materialIndex:0}],r.forEach((t,n)=>{let r=t.geometry;o[n].buildGeometry(r,_),e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrix(),t.matrixWorld.copy(e.matrixWorld),c?(t.material=g,l&&gp(r.groups),u&&(t.material=hp(r.groups,g))):t.material=g[0]}),i?r:r[0]}evaluateHierarchy(e,t=new vd){e.updateMatrixWorld(!0);let n=(e,t)=>{let r=e.children;for(let e=0,i=r.length;e<i;e++){let i=r[e];i.isOperationGroup?n(i,t):t(i)}},r=e=>{let t=e.children,i=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];i=r(n)||i}let a=e.isDirty();if(a&&e.markUpdated(),i&&!e.isOperationGroup){let t;return n(e,n=>{t=t?this.evaluate(t,n,n.operation):this.evaluate(e,n,n.operation)}),e._cachedGeometry=t.geometry,e._cachedMaterials=t.material,!0}return i||a};return r(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}},yp=class{scopes=[];constructor(){this.pushScope();for(let[e,t]of Object.entries({pi:Math.PI,tau:2*Math.PI,true:!0,false:!1}))this.set(e,t)}pushScope(){this.scopes.push(new Map)}popScope(){this.scopes.length>1&&this.scopes.pop()}set(e,t){let n=this.scopes[this.scopes.length-1];if(n===void 0)throw Error(`SymbolTable has no active scope`);n.set(e,t)}get(e){for(let t=this.scopes.length-1;t>=0;t--){let n=this.scopes[t];if(n?.has(e))return n.get(e)}}has(e){return this.get(e)!==void 0}};function bp(e){let t=0;for(let n of Cp(e)){let e=$(n);t+=e*e}return Math.sqrt(t)}var xp={x:0,y:1,z:2,w:3,r:0,g:1,b:2,a:3,red:0,green:1,blue:2,alpha:3},Sp={round:e=>Math.round($(e)),floor:e=>Math.floor($(e)),ceil:e=>Math.ceil($(e)),abs:e=>Math.abs($(e)),sign:e=>Math.sign($(e)),sqrt:e=>Math.sqrt($(e)),pow:(e,t)=>$(e)**+$(t),min:(...e)=>Math.min(...e.flat().map($)),max:(...e)=>Math.max(...e.flat().map($)),sin:e=>Math.sin($(e)),cos:e=>Math.cos($(e)),tan:e=>Math.tan($(e)),asin:e=>Math.asin($(e)),acos:e=>Math.acos($(e)),atan:e=>Math.atan($(e)),atan2:(e,t)=>Math.atan2($(e),$(t)),dot:(e,t)=>{let n=Cp(e),r=Cp(t),i=0;for(let e=0;e<Math.min(n.length,r.length);e++)i+=$(n[e])*$(r[e]);return i},cross:(e,t)=>{let n=Cp(e),r=Cp(t);if(n.length<3||r.length<3)throw Error(`cross product requires 3D vectors`);let i=$(n[0]),a=$(n[1]),o=$(n[2]),s=$(r[0]),c=$(r[1]),l=$(r[2]);return[a*l-o*c,o*s-i*l,i*c-a*s]},length:e=>bp(e),normalize:e=>{let t=Cp(e),n=bp(e);return n===0?t:t.map(e=>$(e)/n)},sum:e=>Cp(e).reduce((e,t)=>e+$(t),0),join:(...e)=>{let t=e.length>0&&typeof e[e.length-1]==`string`?e.pop():``;return e.flat().map(String).join(t)},trim:e=>String(e).trim(),rand:()=>0};function $(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e==`string`){let t=parseFloat(e);if(isNaN(t))throw Error(`Cannot convert "${e}" to number`);return t}if(Array.isArray(e)&&e.length>0)return $(e[0]);throw Error(`Cannot convert ${typeof e} to number`)}function Cp(e){return Array.isArray(e)?e:[e]}function wp(e){return typeof e==`boolean`?e:typeof e==`number`?e!==0:typeof e==`string`||Array.isArray(e)?e.length>0:!1}var Tp=2654435769;function Ep(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var Dp=class{symbols;random;constructor(e,t=Tp){this.symbols=e||new yp,this.random=Ep(t)}getSymbols(){return this.symbols}evaluate(e){if(typeof e==`number`||typeof e==`string`||Array.isArray(e))return e;switch(e.type){case`string`:case`number`:return e.value;case`identifier`:{if(e.name===`rnd`)return this.random();let t=this.symbols.get(e.name);if(t===void 0)throw Error(`Undefined variable: ${e.name}`);return t}case`binary`:{let t=this.evaluate(e.left);if(e.operator===`and`&&!wp(t))return!1;if(e.operator===`or`&&wp(t))return!0;let n=this.evaluate(e.right);switch(e.operator){case`+`:if(Array.isArray(t)&&Array.isArray(n)){let e=[...t];for(let t=0;t<e.length&&t<n.length;t++)e[t]=$(e[t])+$(n[t]);return e}return $(t)+$(n);case`-`:if(Array.isArray(t)&&Array.isArray(n)){let e=[...t];for(let t=0;t<e.length&&t<n.length;t++)e[t]=$(e[t])-$(n[t]);return e}return $(t)-$(n);case`*`:if(Array.isArray(t)&&Array.isArray(n)){let e=Math.min(t.length,n.length),r=[];for(let i=0;i<e;i++)r.push($(t[i])*$(n[i]));return r}return Array.isArray(t)?t.map(e=>$(e)*$(n)):Array.isArray(n)?n.map(e=>$(t)*$(e)):$(t)*$(n);case`/`:if(Array.isArray(t)&&Array.isArray(n)){let e=Math.min(t.length,n.length),r=[];for(let i=0;i<e;i++)r.push($(t[i])/$(n[i]));return r}return Array.isArray(t)?t.map(e=>$(e)/$(n)):$(t)/$(n);case`%`:return $(t)%$(n);case`=`:if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if($(t[e])!==$(n[e]))return!1;return!0}return t===n;case`<>`:if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!0;for(let e=0;e<t.length;e++)if($(t[e])!==$(n[e]))return!0;return!1}return t!==n;case`<`:return $(t)<$(n);case`<=`:return $(t)<=$(n);case`>`:return $(t)>$(n);case`>=`:return $(t)>=$(n);case`and`:return wp(t)&&wp(n);case`or`:return wp(t)||wp(n);default:throw Error(`Unknown binary operator: ${e.operator}`)}}case`unary`:{let t=this.evaluate(e.operand);switch(e.operator){case`+`:return Array.isArray(t)?t.map($):$(t);case`-`:return Array.isArray(t)?t.map(e=>-$(e)):-$(t);case`not`:return!wp(t);default:throw Error(`Unknown unary operator: ${e.operator}`)}}case`call`:{let t=e.name.toLowerCase();if(t===`rand`)return this.random();let n=Object.prototype.hasOwnProperty.call(Sp,t)?Sp[t]:void 0;if(!n)throw Error(`Unknown function: ${e.name}`);return n(...e.args.map(e=>this.evaluate(e)))}case`tuple`:return e.elements.map(e=>this.evaluate(e));case`member`:{let t=this.evaluate(e.object);if(e.member===`count`&&(Array.isArray(t)||typeof t==`string`))return t.length;let n=xp[e.member];if(Object.hasOwn(xp,e.member)&&n!==void 0&&Array.isArray(t)&&n<t.length)return t[n];throw Error(`Unknown member: ${e.member}`)}case`subscript`:{let t=this.evaluate(e.object),n=this.evaluate(e.index);if(!Array.isArray(t)&&typeof t!=`string`)throw Error(`Subscripting requires a tuple or string`);if(typeof n!=`number`||!Number.isInteger(n)||n<0||n>=t.length)throw Error(`Subscript out of range: ${String(n)}`);return t[n]}default:throw Error(`Unknown expression type: ${e.type}`)}}evaluateToNumber(e){return $(this.evaluate(e))}evaluateToBoolean(e){return wp(this.evaluate(e))}evaluateToVector3(e){if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluate(e);if(Array.isArray(t))return[t.length>0?$(t[0]):0,t.length>1?$(t[1]):0,t.length>2?$(t[2]):0];let n=$(t);return[n,n,n]}evaluateToColor(e){if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluate(e);if(Array.isArray(t))return[t.length>0?$(t[0]):0,t.length>1?$(t[1]):0,t.length>2?$(t[2]):0];let n=$(t);return[n,n,n]}};function Op(){return{geometries:new Set,materials:new Set,textures:new Set}}function kp(e){let{material:t}=e;return Array.isArray(t)?t:t?.isMaterial?[t]:[]}function Ap(e,t){return e.traverse(e=>{let n=e;n.geometry?.isBufferGeometry&&t.geometries.add(n.geometry);for(let e of kp(n)){t.materials.add(e);for(let n of Object.values(e))n&&n.isTexture&&t.textures.add(n)}}),t}function jp(e,t){for(let n of e.geometries)t.geometries.has(n)||n.dispose();for(let n of e.textures)t.textures.has(n)||n.dispose();for(let n of e.materials)t.materials.has(n)||n.dispose()}function Mp(e){jp(Ap(e,Op()),Op())}function Np(e,t){let n=Ap(t,Op()),r=Op();for(let n of e)n!==t&&Ap(n,r);jp(r,n)}function Pp(e,t){t&&(e?.remove(t),Mp(t))}var Fp=12,Ip=4,Lp=1e-9,Rp=class extends Error{constructor(e){super(e),this.name=`ShapeScriptLimitError`}},zp=class{options;evaluator;symbols;pathCommandCount=0;detailLevel=32;nodeCount=0;vertexCount=0;startedAt=Date.now();transformStack=[];constructor(e={}){this.options=e,this.symbols=new yp,this.evaluator=new Dp(this.symbols,e.randomSeed),this.pushTransform()}convert(e){let t=new Nn;try{this.addChildren(t,e)}catch(e){throw Mp(t),e}return t}get maxNodes(){return this.options.maxNodes??1e5}get maxLoopIterations(){return this.options.maxLoopIterations??1e5}get maxVertices(){return this.options.maxVertices??5e6}get maxDurationMs(){return this.options.maxDurationMs??3e4}chargePathEstimate(e,t,n=1){let r=Math.max(1,e.curves.length)*Math.max(1,t);this.chargeEstimate(r*n)}chargeEstimate(e){if(this.vertexCount+e>this.maxVertices)throw new Rp(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`)}makeMesh(e,t){if(this.vertexCount+=e.getAttribute(`position`)?.count??0,this.vertexCount>this.maxVertices)throw e.dispose(),t.dispose(),new Rp(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);return new ii(e,t)}rangeIterations(e,t,n){if(n===0||!Number.isFinite(n)||!Number.isFinite(e)||!Number.isFinite(t))throw Error(`Loop bounds and step must be finite, with a nonzero step`);let r=[];for(let i=e;n>0?i<=t:i>=t;i+=n){if(r.length>=this.maxLoopIterations)throw new Rp(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);r.push(i)}return r}convertNode(e){if(this.nodeCount+=1,this.nodeCount>this.maxNodes)throw new Rp(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);if(Date.now()-this.startedAt>this.maxDurationMs)throw new Rp(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);switch(e.type){case`shape`:return this.convertShape(e);case`csg`:return this.convertCSG(e);case`block`:return this.convertBlock(e);case`for`:return this.convertForLoop(e);case`if`:return this.convertIf(e);case`switch`:return this.convertSwitch(e);case`define`:return this.handleDefine(e),null;case`extrude`:return this.convertExtrude(e);case`loft`:return this.convertLoft(e);case`lathe`:return this.convertLathe(e);case`fill`:return this.convertFill(e);case`hull`:return this.convertHull(e);case`group`:return this.convertBlock(e);case`detail`:return this.handleDetail(e),null;case`color`:return this.handleColorCommand(e),null;case`rotate`:return this.handleRotateCommand(e),null;case`orientation`:return this.handleOrientationCommand(e),null;case`translate`:return this.handleTranslateCommand(e),null;case`scale`:return this.handleScaleCommand(e),null;case`customShape`:return this.convertCustomShape(e);case`path`:{let t=this.buildPath(e);this.chargePathEstimate(t,Fp),this.requireEnclosedArea(t,`path`);let n=this.makeMesh(new to(t),this.createMaterial({properties:{}}));return this.applyCurrentTransform(n),n}default:throw Error(`Unsupported command: ${e.type}`)}}inScope(e,t){return this.inFrame(()=>{try{t()}catch(t){throw Mp(e),t}return e})}inFrame(e){this.symbols.pushScope(),this.pushTransform();try{return e()}finally{this.popTransform(),this.symbols.popScope()}}addChildren(e,t){for(let n of t){let t=this.convertNode(n);t&&e.add(t)}}convertBlock(e){let t=new Nn;return this.inScope(t,()=>this.addChildren(t,e.children))}finishMesh(e,t){let n;try{return n=this.makeMesh(e,this.createMaterial(t)),this.applyExplicitTransforms(n,t.properties),this.applyCurrentTransform(n),n}catch(t){throw n?Mp(n):e.dispose(),t}}convertShape(e){return this.finishMesh(this.createGeometry(e),e)}requireExtent(e,t){if(t.some(e=>!e))throw Error(`\`${e}\` needs a nonzero size in every dimension — this one encloses nothing`)}createGeometry(e){let t=[1,1,1];switch(e.properties.size&&(t=this.evaluateVector3(e.properties.size)),t[1]===0&&t[2]===0&&t[0]!==0&&(t=[t[0],t[0],t[0]]),e.primitive){case`cube`:return this.requireExtent(`cube`,t),new Ni(t[0],t[1],t[2]);case`sphere`:return this.requireExtent(`sphere`,t),new ro(1,this.detailLevel,this.detailLevel).scale(...t);case`cylinder`:{let n=e.properties.radiusTop?this.evaluateNumber(e.properties.radiusTop):t[0],r=e.properties.radiusBottom?this.evaluateNumber(e.properties.radiusBottom):t[0],i=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cylinder`,[n||r,i]),new Fi(n,r,i,this.detailLevel)}case`cone`:{let n=t[0],r=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cone`,[n,r]),new Ii(n,r,this.detailLevel)}case`torus`:{let n=e.properties.outerRadius?this.evaluateNumber(e.properties.outerRadius):t[0],r=e.properties.innerRadius?this.evaluateNumber(e.properties.innerRadius):.4;return this.requireExtent(`torus`,[n,r]),new io(n,r,Math.max(3,Math.floor(this.detailLevel/2)),this.detailLevel)}case`circle`:return new Pi(t[0]||1,this.detailLevel);case`square`:{let e=t[0]||1;return new eo(e,t[1]||e)}case`polygon`:{let n=t[0]||1,r=e.properties.sides===void 0?6:this.evaluateNumber(e.properties.sides);if(!Number.isInteger(r)||r<3||r>256)throw Error(`Polygon sides must be an integer from 3 to 256`);return new Pi(n,r)}default:throw Error(`Unknown primitive: ${e.primitive}`)}}materialColor(e){if(e!==void 0){let[t=.8,n=.8,r=.8]=this.evaluateColor(e);return new Bn(t,n,r)}let t=this.currentTransform().color;return t===void 0?new Bn(.8,.8,.8):t.clone()}createMaterial(e){let t=this.materialColor(e.properties.color),n=e.properties.opacity?this.evaluateNumber(e.properties.opacity):1;return new go({color:t,opacity:n,transparent:n<1,wireframe:this.options.wireframe??!1})}convertCSG(e){if(e.children.length===0)return new Nn;let t=this.currentTransform().matrix.clone(),n=[];try{let r=new vp;this.symbols.pushScope(),this.pushTransform(),this.currentTransform().matrix.identity();let i=[];try{for(let t of e.children){if(t.type===`path`)throw Error("A `path` has no volume and cannot be a CSG operand — wrap it in `extrude`, `lathe` or `fill`");let e=this.convertNode(t);if(e){if(n.push(e),e.isMesh){let t=e.clone();t.updateMatrixWorld(!0),i.push(t)}else e.isGroup&&(e.updateMatrixWorld(!0),e.traverse(e=>{if(e.isMesh){let t=e.clone();e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),i.push(t)}}))}}}finally{this.popTransform(),this.symbols.popScope()}if(i.length===0)return new Nn;n.push(...i);let a=i.map(e=>{let t=new vd(e.geometry,e.material);return t.position.copy(e.position),t.rotation.copy(e.rotation),t.scale.copy(e.scale),t.updateMatrixWorld(!0),t});n.push(...a);let o=a[0];if(o===void 0)throw Error(`CSG operation needs at least one child shape`);let s=o;for(let t=1;t<a.length;t++){let i=a[t];if(i===void 0)continue;let o=(e,t,i)=>{n.push(e,t);let a=r.evaluate(e,t,i);return n.push(a),this.chargeEstimate(a.geometry.getAttribute(`position`)?.count??0),this.vertexCount+=a.geometry.getAttribute(`position`)?.count??0,a};switch(e.operation){case`union`:s=o(s,i,0);break;case`difference`:s=o(s,i,1);break;case`intersection`:s=o(s,i,3);break;case`xor`:s=o(o(s.clone(),i.clone(),1),o(i.clone(),s.clone(),1),0);break;case`stencil`:{let e=o(s,i,5),t=o(s,i,6);t.material=Array.isArray(i.material)?i.material[0]:i.material,t.geometry.clearGroups(),t.geometry.addGroup(0,t.geometry.index?.count??t.geometry.getAttribute(`position`).count,0);let r=[e,t],a=r.map(e=>e.geometry.clone().applyMatrix4(e.matrixWorld));try{let e=Rs(a);if(!e)throw Error(`Could not combine stencil surfaces`);let t=[],i=0;for(let n of r){for(let r of n.geometry.groups)e.addGroup(i+r.start,r.count,t.length+(r.materialIndex??0));t.push(...Array.isArray(n.material)?n.material:[n.material]),i+=n.geometry.index?.count??n.geometry.getAttribute(`position`).count}s=new vd(e,t),n.push(s),this.chargeEstimate(e.getAttribute(`position`).count),this.vertexCount+=e.getAttribute(`position`).count}finally{a.forEach(e=>e.dispose())}break}}}return s.material||(s.material=o.material),s.applyMatrix4(t),s.updateMatrixWorld(!0),Np(n,s),s}catch(e){throw Np(n,new Nn),e}}convertForLoop(e){let t=new Nn;return this.inScope(t,()=>{if(e.iterableValues){let n=this.evaluator.evaluate(e.iterableValues),r=Array.isArray(n)?n:[n];if(r.length>this.maxLoopIterations)throw new Rp(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);for(let n of r)this.symbols.set(e.variable,n),this.addChildren(t,e.body)}else{let n=this.evaluateNumber(e.from),r=this.evaluateNumber(e.to),i=e.step?this.evaluateNumber(e.step):1,a=this.rangeIterations(n,r,i);for(let n of a)this.symbols.set(e.variable,n),this.addChildren(t,e.body)}})}convertIf(e){let t=new Nn,n=this.evaluator.evaluateToBoolean(e.condition);return this.inScope(t,()=>this.addChildren(t,n?e.thenBody:e.elseBody??[]))}convertSwitch(e){let t=new Nn,n=this.evaluator.evaluate(e.value);return this.inScope(t,()=>{let r=e.cases.find(e=>e.values.some(e=>this.valuesEqual(n,this.evaluator.evaluate(e))));this.addChildren(t,r?r.body:e.defaultCase??[])})}handleDefine(e){if(e.value!==void 0){let t=this.evaluator.evaluate(e.value);this.symbols.set(e.name,t)}else(e.body!==void 0||e.options!==void 0)&&this.symbols.set(e.name,e)}convertCustomShape(e){let t=this.symbols.get(e.name);if(!t||typeof t!=`object`||!(`type`in t))throw Error(`Unknown shape: ${e.name}`);let n=t;if(!n.body)throw Error(`Custom shape '${e.name}' has no body`);let r=new Nn,i=n.body;return this.inScope(r,()=>{for(let e of n.options??[])this.symbols.set(e.name,this.evaluator.evaluate(e.defaultValue));for(let[t,n]of Object.entries(e.properties))this.symbols.set(t,this.evaluator.evaluate(n));this.addChildren(r,i)})}pushTransform(){let e=this.currentTransform();this.transformStack.push({matrix:e.matrix.clone(),color:e.color===void 0?void 0:e.color.clone()})}popTransform(){this.transformStack.length>1&&this.transformStack.pop()}currentTransform(){return this.transformStack[this.transformStack.length-1]??{matrix:new Y,color:void 0}}applyCurrentTransform(e){let t=this.currentTransform();e.applyMatrix4(t.matrix)}applyExplicitTransforms(e,t){if(t.position){let n=this.evaluateVector3(t.position);e.position.set(...n)}if(t.rotation){let n=this.evaluateVector3(t.rotation);e.rotation.set(...n)}if(t.orientation){let n=this.evaluateVector3(t.orientation);e.rotation.set(...n)}}handleDetail(e){let t=this.evaluateNumber(e.value);this.detailLevel=Number.isFinite(t)?Math.min(256,Math.max(3,Math.floor(t))):3,this.symbols.set(`detail`,this.detailLevel)}handleColorCommand(e){let t=this.evaluateVector3OrColor(e.value);this.currentTransform().color=new Bn(t[0],t[1],t[2])}handleRotateCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new Y,i=new hn(t[0]*Math.PI*2,t[1]*Math.PI*2,t[2]*Math.PI*2,`XYZ`);r.makeRotationFromEuler(i),n.matrix.multiply(r)}handleOrientationCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new J,i=new J;n.matrix.decompose(r,new Ft,i);let a=new hn(t[0]*Math.PI*2,t[1]*Math.PI*2,t[2]*Math.PI*2,`XYZ`);n.matrix.compose(r,new Ft().setFromEuler(a),i)}handleTranslateCommand(e){let t=this.currentTransform(),[n,r,i]=this.evaluateTranslateVector(e.value);if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite translation components`);let a=new Y().makeTranslation(n,r,i);t.matrix.multiply(a)}handleScaleCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new Y().makeScale(t[0],t[1],t[2]);n.matrix.multiply(r)}requireEnclosedArea(e,t){let n=e.getPoints(Fp),r=qa.area(n);if(!Number.isFinite(r))throw Error(`\`${t}\` needs finite path coordinates — these overflow`);if(n.length<3||Math.abs(r)<Lp)throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);return e}convertExtrude(e){if(!e.path)return this.buildFromChildren({children:e.children??[],properties:e.properties},t=>{let n=t.map(e=>this.planarShape(e));if(!n.length)throw Error(`Extrude requires a path or planar shape`);let r=e.properties.size?this.evaluateVector3(e.properties.size):[1,1,1];for(let e of n)this.chargePathEstimate(e,1,12);return new Xa(n,{depth:r[2]??1,bevelEnabled:!1,curveSegments:1})});let t=this.requireEnclosedArea(this.buildPath(e.path),`extrude`),n=(e.properties.size?this.evaluateVector3(e.properties.size):[1,1,1])[2]||1,r=Math.max(1,Math.floor(this.detailLevel/4));this.chargePathEstimate(t,r,Ip);let i=new Xa(t,{depth:n,bevelEnabled:!1,curveSegments:r}),a=this.createMaterial(e),o=this.makeMesh(i,a);return this.applyExplicitTransforms(o,e.properties),this.applyCurrentTransform(o),o}buildPath(e){let t=new pa,n=0,r=0,i=0,a=!1,o=(e,t)=>{if(n+=e,r+=t,!Number.isFinite(n)||!Number.isFinite(r))throw Error(`Path coordinates overflowed to a non-finite value — they accumulate, so each command adds to the previous one`)},s=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new Rp(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`detail`:this.handleDetail(e);break;case`point`:{let s=this.evaluateNumber(e.x),c=this.evaluateNumber(e.y),l=Math.cos(i),u=Math.sin(i),d=s*l-c*u,f=s*u+c*l;o(d,f),a?t.lineTo(n,r):(t.moveTo(n,r),a=!0);break}case`curve`:{let s=this.evaluateNumber(e.x),c=this.evaluateNumber(e.y),l=Math.cos(i),u=Math.sin(i),d=s*l-c*u,f=s*u+c*l;if(o(d,f),!a){t.moveTo(n,r),a=!0;break}if(e.controlX!==void 0&&e.controlY!==void 0){let i=this.evaluateNumber(e.controlX),a=this.evaluateNumber(e.controlY),o=i*l-a*u,s=i*u+a*l;if(!Number.isFinite(n+o)||!Number.isFinite(r+s))throw Error(`Curve control point overflowed to a non-finite value`);t.quadraticCurveTo(n+o,r+s,n,r)}else t.lineTo(n,r);break}case`rotate`:{let t=this.evaluateNumber(e.angle);if(i+=t*Math.PI*2,!Number.isFinite(i))throw Error(`Path rotation overflowed to a non-finite angle`);break}case`translate`:o(this.evaluateNumber(e.x),this.evaluateNumber(e.y));break;case`for`:{this.symbols.pushScope();let t=this.evaluateNumber(e.from),n=this.evaluateNumber(e.to),r=e.step?this.evaluateNumber(e.step):1,i=this.rangeIterations(t,n,r);for(let t of i){this.symbols.set(e.variable,t);for(let t of e.commands)s(t)}this.symbols.popScope();break}}};for(let t of e.commands)s(t);return t}convertLathe(e){return this.inFrame(()=>this.buildLathe(e))}requireLatheProfile(e){if(!e.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");let t=Math.max(...e.map(e=>Math.abs(e.x))),n=Math.max(...e.map(e=>e.y))-Math.min(...e.map(e=>e.y));if(t<Lp||n<Lp)throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing")}buildLathe(e){let t=null;for(let n of e.children)if(n.type===`path`){t=n;break}if(!t)throw Error(`Lathe requires a path child`);let n=this.buildPath(t);this.chargePathEstimate(n,this.detailLevel,this.detailLevel+1);let r=n.getPoints(this.detailLevel);if(r.length<2)throw Error(`Lathe path must have at least 2 points`);this.requireLatheProfile(r),this.chargeEstimate(r.length*(this.detailLevel+1));let i=new $a(r,this.detailLevel),a=this.createMaterial(e),o=this.makeMesh(i,a);return this.applyExplicitTransforms(o,e.properties),this.applyCurrentTransform(o),o}buildOperands(e,t){this.inScope(e,()=>{this.currentTransform().matrix.identity(),this.addChildren(e,t)}),e.updateMatrixWorld(!0);let n=[];return e.traverse(e=>{e.isMesh&&n.push(e)}),n}buildFromChildren(e,t){let n=new Nn,r=this.vertexCount,i;try{i=t(this.buildOperands(n,e.children))}finally{Mp(n),this.vertexCount=r}return this.finishMesh(i,e)}convertLoft(e){return this.buildFromChildren(e,e=>{let t=e.map(Bs),n=t.length*Math.max(0,...t.map(e=>e.length));return this.chargeEstimate(n),Ws(t)})}planarShape(e){let t=Bs(e);if(t.some(e=>Math.abs(e.z)>1e-5))throw Error(`Fill/extrude profiles must lie in the XY plane`);return new pa(t.map(e=>new q(e.x,e.y)))}convertFill(e){return this.inFrame(()=>{let t=e.children.find(e=>e.type===`path`);if(!t)return this.buildFromChildren(e,e=>{let t=e.map(e=>this.planarShape(e));if(!t.length)throw Error(`Fill requires a path or planar shape`);for(let e of t)this.chargePathEstimate(e,1,3);return new to(t,1)});let n=this.buildPath(t);this.chargePathEstimate(n,Fp),this.requireEnclosedArea(n,`fill`);let r=new to(n),i=this.makeMesh(r,this.createMaterial(e));return this.applyExplicitTransforms(i,e.properties),this.applyCurrentTransform(i),i})}convertHull(e){return this.buildFromChildren(e,e=>{let t=[];for(let n of e){let e=n.geometry.getAttribute(`position`);for(let r=0;r<e.count;r++)t.push(new J().fromBufferAttribute(e,r).applyMatrix4(n.matrixWorld))}if(t.length<4)throw Error(`Hull requires at least four non-coplanar points`);this.chargeEstimate(t.length*6);let n=new Ls(t);if(!n.getAttribute(`position`).count)throw n.dispose(),Error(`Hull points must enclose a volume`);return n.setAttribute(`uv`,new X(new Float32Array(n.getAttribute(`position`).count*2),2)),n})}evaluateNumber(e){if(e===void 0)return 0;if(typeof e==`number`)return e;let t=this.evaluator.evaluateToNumber(e);if(!Number.isFinite(t))throw Error(`Expected a finite number`);return t}evaluateVector3(e){if(e===void 0)return[0,0,0];if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluator.evaluateToVector3(e);if(!t.every(Number.isFinite))throw Error(`Expected finite vector components`);return t}evaluateTranslateVector(e){let t=this.evaluator.evaluate(e);return typeof t==`number`?[t,0,0]:Array.isArray(t)?[t.length>0&&typeof t[0]==`number`?t[0]:0,t.length>1&&typeof t[1]==`number`?t[1]:0,t.length>2&&typeof t[2]==`number`?t[2]:0]:[0,0,0]}evaluateColor(e){return e===void 0?[.8,.8,.8]:Array.isArray(e)&&typeof e[0]==`number`?e:this.requireFiniteColor(this.evaluator.evaluateToColor(e))}requireFiniteColor(e){if(!e.every(Number.isFinite))throw Error(`Expected finite color channels`);return e}evaluateVector3OrColor(e){let t=this.evaluator.evaluate(e),n=e=>{if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(Array.isArray(e)&&e.length>0)return n(e[0]);throw Error(`Expected numeric color channels`)};if(typeof t==`number`)return this.requireFiniteColor([t,t,t]);if(typeof t==`boolean`)return this.requireFiniteColor([n(t),n(t),n(t)]);if(Array.isArray(t)){if(t.length===1)return this.requireFiniteColor([n(t[0]),n(t[0]),n(t[0])]);if(t.length===2)return this.requireFiniteColor([n(t[0]),n(t[1]),0]);if(t.length>=3)return this.requireFiniteColor([n(t[0]),n(t[1]),n(t[2])])}throw Error(`Expected numeric color channels`)}valuesEqual(e,t){if(typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!this.valuesEqual(e[n],t[n]))return!1;return!0}return e===t}};function Bp(e,t={}){return new zp(t).convert(e)}Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return Ko}}),Object.defineProperty(exports,"$t",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return hi}}),Object.defineProperty(exports,"An",{enumerable:!0,get:function(){return oo}}),Object.defineProperty(exports,"At",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"Bt",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"Cn",{enumerable:!0,get:function(){return ao}}),Object.defineProperty(exports,"Ct",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Mi}}),Object.defineProperty(exports,"Dn",{enumerable:!0,get:function(){return Cs}}),Object.defineProperty(exports,"Dt",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return ct}}),Object.defineProperty(exports,"En",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"Et",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return gn}}),Object.defineProperty(exports,"Fn",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"Ft",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"Gt",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return Pt}}),Object.defineProperty(exports,"Ht",{enumerable:!0,get:function(){return ho}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"In",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"It",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return vo}}),Object.defineProperty(exports,"Jt",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"Kt",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"Ln",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"Lt",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return xs}}),Object.defineProperty(exports,"Mn",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"Mt",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"Nn",{enumerable:!0,get:function(){return at}}),Object.defineProperty(exports,"Nt",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"On",{enumerable:!0,get:function(){return lo}}),Object.defineProperty(exports,"Ot",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"Pn",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"Pt",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"Qt",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"Rn",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"Rt",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"Sn",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"St",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Jo}}),Object.defineProperty(exports,"Tn",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"Tt",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return Rt}}),Object.defineProperty(exports,"Ut",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"Vt",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"Wt",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"Xt",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"Yt",{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Zt",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return ji}}),Object.defineProperty(exports,"_n",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"_t",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"an",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return ft}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return rn}}),Object.defineProperty(exports,"bn",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"bt",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Ni}}),Object.defineProperty(exports,"cn",{enumerable:!0,get:function(){return uo}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"dn",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"en",{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return Go}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"fn",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Qo}}),Object.defineProperty(exports,"gn",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Ss}}),Object.defineProperty(exports,"hn",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Pp}}),Object.defineProperty(exports,"in",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Xe}}),Object.defineProperty(exports,"jn",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,"jt",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"kn",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"kt",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return xr}}),Object.defineProperty(exports,"ln",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Ut}}),Object.defineProperty(exports,"mn",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Bp}}),Object.defineProperty(exports,"nn",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return eo}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Yo}}),Object.defineProperty(exports,"on",{enumerable:!0,get:function(){return Sr}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Bn}}),Object.defineProperty(exports,"pn",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return _o}}),Object.defineProperty(exports,"qt",{enumerable:!0,get:function(){return st}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Mp}}),Object.defineProperty(exports,"rn",{enumerable:!0,get:function(){return fs}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return $o}}),Object.defineProperty(exports,"sn",{enumerable:!0,get:function(){return Cr}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Rp}}),Object.defineProperty(exports,"tn",{enumerable:!0,get:function(){return mo}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Fr}}),Object.defineProperty(exports,"un",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return ki}}),Object.defineProperty(exports,"vn",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"vt",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"wn",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"wt",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return si}}),Object.defineProperty(exports,"xn",{enumerable:!0,get:function(){return nn}}),Object.defineProperty(exports,"xt",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return an}}),Object.defineProperty(exports,"yn",{enumerable:!0,get:function(){return en}}),Object.defineProperty(exports,"yt",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(exports,"zn",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"zt",{enumerable:!0,get:function(){return H}});
10
+ }`,mo=class extends Lr{constructor(e){super(),this.isShaderMaterial=!0,this.type=`ShaderMaterial`,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=fo,this.fragmentShader=po,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=ao(e.uniforms),this.uniformsGroups=co(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this.defaultAttributeValues=Object.assign({},e.defaultAttributeValues),this.index0AttributeName=e.index0AttributeName,this.uniformsNeedUpdate=e.uniformsNeedUpdate,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let n in this.uniforms){let r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type:`t`,value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type:`c`,value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type:`v2`,value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type:`v3`,value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type:`v4`,value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type:`m3`,value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type:`m4`,value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let e in this.extensions)this.extensions[e]===!0&&(n[e]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}fromJSON(e,t){if(super.fromJSON(e,t),e.uniforms!==void 0)for(let n in e.uniforms){let r=e.uniforms[n];switch(this.uniforms[n]={},r.type){case`t`:this.uniforms[n].value=t[r.value]||null;break;case`c`:this.uniforms[n].value=new Bn().setHex(r.value);break;case`v2`:this.uniforms[n].value=new q().fromArray(r.value);break;case`v3`:this.uniforms[n].value=new J().fromArray(r.value);break;case`v4`:this.uniforms[n].value=new en().fromArray(r.value);break;case`m3`:this.uniforms[n].value=new Rt().fromArray(r.value);break;case`m4`:this.uniforms[n].value=new Y().fromArray(r.value);break;default:this.uniforms[n].value=r.value}}if(e.defines!==void 0&&(this.defines=e.defines),e.vertexShader!==void 0&&(this.vertexShader=e.vertexShader),e.fragmentShader!==void 0&&(this.fragmentShader=e.fragmentShader),e.glslVersion!==void 0&&(this.glslVersion=e.glslVersion),e.extensions!==void 0)for(let t in e.extensions)this.extensions[t]=e.extensions[t];return e.lights!==void 0&&(this.lights=e.lights),e.clipping!==void 0&&(this.clipping=e.clipping),this}},ho=class extends mo{constructor(e){super(e),this.isRawShaderMaterial=!0,this.type=`RawShaderMaterial`}},go=class extends Lr{constructor(e){super(),this.isMeshStandardMaterial=!0,this.type=`MeshStandardMaterial`,this.defines={STANDARD:``},this.color=new Bn(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Bn(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new q(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new hn,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap=`round`,this.wireframeLinejoin=`round`,this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:``},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}},_o=class extends Lr{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type=`MeshDepthMaterial`,this.depthPacking=Ue,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}},vo=class extends Lr{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type=`MeshDistanceMaterial`,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}};function yo(e,t){return!e||e.constructor===t?e:typeof t.BYTES_PER_ELEMENT==`number`?new t(e):Array.prototype.slice.call(e)}var bo=class{constructor(e,t,n,r){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=r===void 0?new t.constructor(n):r,this.sampleValues=t,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,n=this._cachedIndex,r=t[n],i=t[n-1];validate_interval:{seek:{let a;linear_scan:{forward_scan:if(!(e<r)){for(let a=n+2;;){if(r===void 0){if(e<i)break forward_scan;return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}if(n===a)break;if(i=r,r=t[++n],e<r)break seek}a=t.length;break linear_scan}if(!(e>=i)){let o=t[1];e<o&&(n=2,i=o);for(let a=n-2;;){if(i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===a)break;if(r=i,i=t[--n-1],e>=i)break seek}a=n,n=0;break linear_scan}break validate_interval}for(;n<a;){let r=n+a>>>1;e<t[r]?a=r:n=r+1}if(r=t[n],i=t[n-1],i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(r===void 0)return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}this._cachedIndex=n,this.intervalChanged_(n,i,r)}return this.interpolate_(n,i,e,r)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r;for(let e=0;e!==r;++e)t[e]=n[i+e];return t}interpolate_(){throw Error(`THREE.Interpolant: Call to abstract method.`)}intervalChanged_(){}},xo=class extends bo{constructor(e,t,n,r){super(e,t,n,r),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Be,endingEnd:Be}}intervalChanged_(e,t,n){let r=this.parameterPositions,i=e-2,a=e+1,o=r[i],s=r[a];if(o===void 0)switch(this.getSettings_().endingStart){case Ve:i=e,o=2*t-n;break;case He:i=r.length-2,o=t+r[i]-r[i+1];break;default:i=e,o=n}if(s===void 0)switch(this.getSettings_().endingEnd){case Ve:a=e,s=2*n-t;break;case He:a=1,s=n+r[1]-r[0];break;default:a=e-1,s=t}let c=(n-t)*.5,l=this.valueSize;this._weightPrev=c/(t-o),this._weightNext=c/(s-n),this._offsetPrev=i*l,this._offsetNext=a*l}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(n-t)/(r-t),m=p*p,h=m*p,g=-d*h+2*d*m-d*p,_=(1+d)*h+(-1.5-2*d)*m+(-.5+d)*p+1,v=(-1-f)*h+(1.5+f)*m+.5*p,y=f*h-f*m;for(let e=0;e!==o;++e)i[e]=g*a[l+e]+_*a[c+e]+v*a[s+e]+y*a[u+e];return i}},So=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=(n-t)/(r-t),u=1-l;for(let e=0;e!==o;++e)i[e]=a[c+e]*u+a[s+e]*l;return i}},Co=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e){return this.copySampleValue_(e-1)}},wo=class extends bo{interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=this.inTangents,u=this.outTangents;if(!l||!u){let e=(n-t)/(r-t),l=1-e;for(let t=0;t!==o;++t)i[t]=a[c+t]*l+a[s+t]*e;return i}let d=o*2,f=e-1;for(let p=0;p!==o;++p){let o=a[c+p],m=a[s+p],h=f*d+p*2,g=u[h],_=u[h+1],v=e*d+p*2,y=l[v],b=l[v+1],x=(n-t)/(r-t),S,C,w,T,E;for(let e=0;e<8;e++){S=x*x,C=S*x,w=1-x,T=w*w,E=T*w;let e=E*t+3*T*x*g+3*w*S*y+C*r-n;if(Math.abs(e)<1e-10)break;let i=3*T*(g-t)+6*w*x*(y-g)+3*S*(r-y);if(Math.abs(i)<1e-10)break;x-=e/i,x=Math.max(0,Math.min(1,x))}i[p]=E*o+3*T*x*_+3*w*S*b+C*m}return i}},To=class{constructor(e,t,n,r){if(e===void 0)throw Error(`THREE.KeyframeTrack: track name is undefined`);if(t===void 0||t.length===0)throw Error(`THREE.KeyframeTrack: no keyframes in track named `+e);this.name=e,this.times=yo(t,this.TimeBufferType),this.values=yo(n,this.ValueBufferType),this.setInterpolation(r||this.DefaultInterpolation)}static toJSON(e){let t=e.constructor,n;if(t.toJSON!==this.toJSON)n=t.toJSON(e);else{n={name:e.name,times:yo(e.times,Array),values:yo(e.values,Array)};let t=e.getInterpolation();t!==e.DefaultInterpolation&&(n.interpolation=t)}return n.type=e.ValueTypeName,n}InterpolantFactoryMethodDiscrete(e){return new Co(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new So(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new xo(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodBezier(e){let t=new wo(this.times,this.values,this.getValueSize(),e);return this.settings&&(t.inTangents=this.settings.inTangents,t.outTangents=this.settings.outTangents),t}setInterpolation(e){let t;switch(e){case Ie:t=this.InterpolantFactoryMethodDiscrete;break;case Le:t=this.InterpolantFactoryMethodLinear;break;case Re:t=this.InterpolantFactoryMethodSmooth;break;case ze:t=this.InterpolantFactoryMethodBezier}if(t===void 0){let t=`unsupported interpolation for `+this.ValueTypeName+` keyframe track named `+this.name;if(this.createInterpolant===void 0){if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw Error(t)}return W(`KeyframeTrack:`,t),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Ie;case this.InterpolantFactoryMethodLinear:return Le;case this.InterpolantFactoryMethodSmooth:return Re;case this.InterpolantFactoryMethodBezier:return ze}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]+=e}return this}scale(e){if(e!==1){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]*=e}return this}trim(e,t){let n=this.times,r=n.length,i=0,a=r-1;for(;i!==r&&n[i]<e;)++i;for(;a!==-1&&n[a]>t;)--a;if(++a,i!==0||a!==r){i>=a&&(a=Math.max(a,1),i=a-1);let e=this.getValueSize();this.times=n.slice(i,a),this.values=this.values.slice(i*e,a*e)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(G(`KeyframeTrack: Invalid value size in track.`,this),e=!1);let n=this.times,r=this.values,i=n.length;i===0&&(G(`KeyframeTrack: Track is empty.`,this),e=!1);let a=null;for(let t=0;t!==i;t++){let r=n[t];if(typeof r==`number`&&isNaN(r)){G(`KeyframeTrack: Time is not a valid number.`,this,t,r),e=!1;break}if(a!==null&&a>r){G(`KeyframeTrack: Out of order keys.`,this,t,r,a),e=!1;break}a=r}if(r!==void 0&&$e(r))for(let t=0,n=r.length;t!==n;++t){let n=r[t];if(isNaN(n)){G(`KeyframeTrack: Value is not a valid number.`,this,t,n),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),n=this.getValueSize(),r=this.getInterpolation()===Re,i=e.length-1,a=1;for(let o=1;o<i;++o){let i=!1,s=e[o];if(s!==e[o+1]&&(o!==1||s!==e[0])){if(r)i=!0;else{let e=o*n,r=e-n,a=e+n;for(let o=0;o!==n;++o){let n=t[e+o];if(n!==t[r+o]||n!==t[a+o]){i=!0;break}}}}if(i){if(o!==a){e[a]=e[o];let r=o*n,i=a*n;for(let e=0;e!==n;++e)t[i+e]=t[r+e]}++a}}if(i>0){e[a]=e[i];for(let e=i*n,r=a*n,o=0;o!==n;++o)t[r+o]=t[e+o];++a}return a===e.length?(this.times=e,this.values=t):(this.times=e.slice(0,a),this.values=t.slice(0,a*n)),this}clone(){let e=this.times.slice(),t=this.values.slice(),n=this.constructor,r=new n(this.name,e,t);return r.createInterpolant=this.createInterpolant,r}};To.prototype.ValueTypeName=``,To.prototype.TimeBufferType=Float32Array,To.prototype.ValueBufferType=Float32Array,To.prototype.DefaultInterpolation=Le;var Eo=class extends To{constructor(e,t,n){super(e,t,n)}};Eo.prototype.ValueTypeName=`bool`,Eo.prototype.ValueBufferType=Array,Eo.prototype.DefaultInterpolation=Ie,Eo.prototype.InterpolantFactoryMethodLinear=void 0,Eo.prototype.InterpolantFactoryMethodSmooth=void 0;var Do=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Do.prototype.ValueTypeName=`color`;var Oo=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Oo.prototype.ValueTypeName=`number`;var ko=class extends bo{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=(n-t)/(r-t),c=e*o;for(let e=c+o;c!==e;c+=4)Ft.slerpFlat(i,0,a,c-o,a,c,s);return i}},Ao=class extends To{constructor(e,t,n,r){super(e,t,n,r)}InterpolantFactoryMethodLinear(e){return new ko(this.times,this.values,this.getValueSize(),e)}};Ao.prototype.ValueTypeName=`quaternion`,Ao.prototype.InterpolantFactoryMethodSmooth=void 0;var jo=class extends To{constructor(e,t,n){super(e,t,n)}};jo.prototype.ValueTypeName=`string`,jo.prototype.ValueBufferType=Array,jo.prototype.DefaultInterpolation=Ie,jo.prototype.InterpolantFactoryMethodLinear=void 0,jo.prototype.InterpolantFactoryMethodSmooth=void 0;var Mo=class extends To{constructor(e,t,n,r){super(e,t,n,r)}};Mo.prototype.ValueTypeName=`vector`;var No=class extends Mn{constructor(e,t=1){super(),this.isLight=!0,this.type=`Light`,this.color=new Bn(e),this.intensity=t}dispose(){this.dispatchEvent({type:`dispose`})}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}toJSON(e){let t=super.toJSON(e);return t.object.color=this.color.getHex(),t.object.intensity=this.intensity,t}},Po=new Y,Fo=new J,Io=new J,Lo=class{constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.biasNode=null,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new q(512,512),this.mapType=x,this.map=null,this.mapPass=null,this.matrix=new Y,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new hi,this._frameExtents=new q(1,1),this._viewportCount=1,this._viewports=[new en(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera,n=this.matrix;Fo.setFromMatrixPosition(e.matrixWorld),t.position.copy(Fo),Io.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Io),t.updateMatrixWorld(),Po.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Po,t.coordinateSystem,t.reversedDepth),t.coordinateSystem===2001||t.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Po)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this.biasNode=e.biasNode,this}clone(){return new this.constructor().copy(this)}toJSON(){let e={};return this.intensity!==1&&(e.intensity=this.intensity),this.bias!==0&&(e.bias=this.bias),this.normalBias!==0&&(e.normalBias=this.normalBias),this.radius!==1&&(e.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(e.mapSize=this.mapSize.toArray()),e.camera=this.camera.toJSON(!1).object,delete e.camera.matrix,e}},Ro=new J,zo=new Ft,Bo=new J,Vo=class extends Mn{constructor(){super(),this.isCamera=!0,this.type=`Camera`,this.matrixWorldInverse=new Y,this.projectionMatrix=new Y,this.projectionMatrixInverse=new Y,this.coordinateSystem=Ze,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorld.decompose(Ro,zo,Bo),Bo.x===1&&Bo.y===1&&Bo.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ro,zo,Bo.set(1,1,1)).invert()}updateWorldMatrix(e,t,n=!1){super.updateWorldMatrix(e,t,n),this.matrixWorld.decompose(Ro,zo,Bo),Bo.x===1&&Bo.y===1&&Bo.z===1?this.matrixWorldInverse.copy(this.matrixWorld).invert():this.matrixWorldInverse.compose(Ro,zo,Bo.set(1,1,1)).invert()}clone(){return new this.constructor().copy(this)}},Ho=new J,Uo=new q,Wo=new q,Go=class extends Vo{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type=`PerspectiveCamera`,this.fov=e,this.zoom=1,this.near=n,this.far=r,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=ft*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(dt*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return ft*2*Math.atan(Math.tan(dt*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){Ho.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(Ho.x,Ho.y).multiplyScalar(-e/Ho.z),Ho.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(Ho.x,Ho.y).multiplyScalar(-e/Ho.z)}getViewSize(e,t){return this.getViewBounds(e,Uo,Wo),t.subVectors(Wo,Uo)}setViewOffset(e,t,n,r,i,a){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(dt*.5*this.fov)/this.zoom,n=2*t,r=this.aspect*n,i=-.5*r,a=this.view;if(this.view!==null&&this.view.enabled){let e=a.fullWidth,o=a.fullHeight;i+=a.offsetX*r/e,t-=a.offsetY*n/o,r*=a.width/e,n*=a.height/o}let o=this.filmOffset;o!==0&&(i+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(i,i+r,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}},Ko=class extends Vo{constructor(e=-1,t=1,n=1,r=-1,i=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type=`OrthographicCamera`,this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=r,this.near=i,this.far=a,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,r,i,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,r=(this.top+this.bottom)/2,i=n-e,a=n+e,o=r+t,s=r-t;if(this.view!==null&&this.view.enabled){let e=(this.right-this.left)/this.view.fullWidth/this.zoom,t=(this.top-this.bottom)/this.view.fullHeight/this.zoom;i+=e*this.view.offsetX,a=i+e*this.view.width,o-=t*this.view.offsetY,s=o-t*this.view.height}this.projectionMatrix.makeOrthographic(i,a,o,s,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}},qo=class extends Lo{constructor(){super(new Ko(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}},Jo=class extends No{constructor(e,t){super(e,t),this.isDirectionalLight=!0,this.type=`DirectionalLight`,this.position.copy(Mn.DEFAULT_UP),this.updateMatrix(),this.target=new Mn,this.shadow=new qo}dispose(){super.dispose(),this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}toJSON(e){let t=super.toJSON(e);return t.object.shadow=this.shadow.toJSON(),t.object.target=this.target.uuid,t}},Yo=class extends No{constructor(e,t){super(e,t),this.isAmbientLight=!0,this.type=`AmbientLight`}},Xo=-90,Zo=1,Qo=class extends Mn{constructor(e,t,n){super(),this.type=`CubeCamera`,this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let r=new Go(Xo,Zo,e,t);r.layers=this.layers,this.add(r);let i=new Go(Xo,Zo,e,t);i.layers=this.layers,this.add(i);let a=new Go(Xo,Zo,e,t);a.layers=this.layers,this.add(a);let o=new Go(Xo,Zo,e,t);o.layers=this.layers,this.add(o);let s=new Go(Xo,Zo,e,t);s.layers=this.layers,this.add(s);let c=new Go(Xo,Zo,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,r,i,a,o,s]=t;for(let e of t)this.remove(e);if(e===2e3)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.lookAt(-1,0,0),i.up.set(0,0,-1),i.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),s.up.set(0,1,0),s.lookAt(0,0,-1);else if(e===2001)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.lookAt(1,0,0),i.up.set(0,0,1),i.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),s.up.set(0,-1,0),s.lookAt(0,0,-1);else throw Error(`THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: `+e);for(let e of t)this.add(e),e.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[i,a,o,s,c,l]=this.children,u=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;let m=n.texture.generateMipmaps;n.texture.generateMipmaps=!1;let h=!1;h=e.isWebGLRenderer===!0?e.state.buffers.depth.getReversed():e.reversedDepthBuffer,e.setRenderTarget(n,0,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,i),e.setRenderTarget(n,1,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,a),e.setRenderTarget(n,2,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,o),e.setRenderTarget(n,3,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,s),e.setRenderTarget(n,4,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,c),n.texture.generateMipmaps=m,e.setRenderTarget(n,5,r),h&&e.autoClear===!1&&e.clearDepth(),e.render(t,l),e.setRenderTarget(u,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},$o=class extends Go{constructor(e=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=e}},es=`\\[\\]\\.:\\/`,ts=RegExp(`[\\[\\]\\.:\\/]`,`g`),ns=`[^\\[\\]\\.:\\/]`,rs=`[^`+es.replace(`\\.`,``)+`]`,is=`((?:WC+[\\/:])*)`.replace(`WC`,ns),as=`(WCOD+)?`.replace(`WCOD`,rs),os=`(?:\\.(WC+)(?:\\[(.+)\\])?)?`.replace(`WC`,ns),ss=`\\.(WC+)(?:\\[(.+)\\])?`.replace(`WC`,ns),cs=RegExp(`^`+is+as+os+ss+`$`),ls=[`material`,`materials`,`bones`,`map`],us=class{constructor(e,t,n){let r=n||ds.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,r)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,r=this._bindings[n];r!==void 0&&r.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let r=this._targetGroup.nCachedObjects_,i=n.length;r!==i;++r)n[r].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].unbind()}},ds=class e{constructor(t,n,r){this.path=n,this.parsedPath=r||e.parseTrackName(n),this.node=e.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,n,r){return t&&t.isAnimationObjectGroup?new e.Composite(t,n,r):new e(t,n,r)}static sanitizeNodeName(e){return e.replace(/\s/g,`_`).replace(ts,``)}static parseTrackName(e){let t=cs.exec(e);if(t===null)throw Error(`THREE.PropertyBinding: Cannot parse trackName: `+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},r=n.nodeName&&n.nodeName.lastIndexOf(`.`);if(r!==void 0&&r!==-1){let e=n.nodeName.substring(r+1);ls.indexOf(e)!==-1&&(n.nodeName=n.nodeName.substring(0,r),n.objectName=e)}if(n.propertyName===null||n.propertyName.length===0)throw Error(`THREE.PropertyBinding: can not parse propertyName from trackName: `+e);return n}static findNode(e,t){if(t===void 0||t===``||t===`.`||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let n=e.skeleton.getBoneByName(t);if(n!==void 0)return n}if(e.children){let n=function(e){for(let r=0;r<e.length;r++){let i=e[r];if(i.name===t||i.uuid===t)return i;let a=n(i.children);if(a)return a}return null},r=n(e.children);if(r)return r}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)e[t++]=n[r]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++]}_setValue_array_setNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let t=this.node,n=this.parsedPath,r=n.objectName,i=n.propertyName,a=n.propertyIndex;if(t||(t=e.findNode(this.rootNode,n.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){W(`PropertyBinding: No target node found for track: `+this.path+`.`);return}if(r){let e=n.objectIndex;switch(r){case`materials`:if(!t.material){G(`PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.materials){G(`PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.`,this);return}t=t.material.materials;break;case`bones`:if(!t.skeleton){G(`PropertyBinding: Can not bind to bones as node does not have a skeleton.`,this);return}t=t.skeleton.bones;for(let n=0;n<t.length;n++)if(t[n].name===e){e=n;break}break;case`map`:if(`map`in t){t=t.map;break}if(!t.material){G(`PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.map){G(`PropertyBinding: Can not bind to material.map as node.material does not have a map.`,this);return}t=t.material.map;break;default:if(t[r]===void 0){G(`PropertyBinding: Can not bind to objectName of node undefined.`,this);return}t=t[r]}if(e!==void 0){if(t[e]===void 0){G(`PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.`,this,t);return}t=t[e]}}let o=t[i];if(o===void 0){let e=n.nodeName;G(`PropertyBinding: Trying to update property for track: `+e+`.`+i+` but it wasn't found.`,t);return}let s=this.Versioning.None;this.targetObject=t,t.isMaterial===!0?s=this.Versioning.NeedsUpdate:t.isObject3D===!0&&(s=this.Versioning.MatrixWorldNeedsUpdate);let c=this.BindingType.Direct;if(a!==void 0){if(i===`morphTargetInfluences`){if(!t.geometry){G(`PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.`,this);return}if(!t.geometry.morphAttributes){G(`PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.`,this);return}t.morphTargetDictionary[a]!==void 0&&(a=t.morphTargetDictionary[a])}c=this.BindingType.ArrayElement,this.resolvedProperty=o,this.propertyIndex=a}else o.fromArray!==void 0&&o.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=o):Array.isArray(o)?(c=this.BindingType.EntireArray,this.resolvedProperty=o):this.propertyName=i;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][s]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};ds.Composite=us,ds.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},ds.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},ds.prototype.GetterByBindingType=[ds.prototype._getValue_direct,ds.prototype._getValue_array,ds.prototype._getValue_arrayElement,ds.prototype._getValue_toArray],ds.prototype.SetterByBindingTypeAndVersioning=[[ds.prototype._setValue_direct,ds.prototype._setValue_direct_setNeedsUpdate,ds.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_array,ds.prototype._setValue_array_setNeedsUpdate,ds.prototype._setValue_array_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_arrayElement,ds.prototype._setValue_arrayElement_setNeedsUpdate,ds.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[ds.prototype._setValue_fromArray,ds.prototype._setValue_fromArray_setNeedsUpdate,ds.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var fs=class{constructor(e=1,t=0,n=0){this.radius=e,this.phi=t,this.theta=n}set(e,t,n){return this.radius=e,this.phi=t,this.theta=n,this}copy(e){return this.radius=e.radius,this.phi=e.phi,this.theta=e.theta,this}makeSafe(){let e=1e-6;return this.phi=K(this.phi,e,Math.PI-e),this}setFromVector3(e){return this.setFromCartesianCoords(e.x,e.y,e.z)}setFromCartesianCoords(e,t,n){return this.radius=Math.sqrt(e*e+t*t+n*n),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(e,n),this.phi=Math.acos(K(t/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}};(class e{static{e.prototype.isMatrix2=!0}constructor(e,t,n,r){this.elements=[1,0,0,1],e!==void 0&&this.set(e,t,n,r)}identity(){return this.set(1,0,0,1),this}fromArray(e,t=0){for(let n=0;n<4;n++)this.elements[n]=e[n+t];return this}set(e,t,n,r){let i=this.elements;return i[0]=e,i[2]=t,i[1]=n,i[3]=r,this}});var ps=new J,ms=new J,hs=new J,gs=new J,_s=new J,vs=new J,ys=new J,bs=class{constructor(e=new J,t=new J){this.start=e,this.end=t}set(e,t){return this.start.copy(e),this.end.copy(t),this}copy(e){return this.start.copy(e.start),this.end.copy(e.end),this}getCenter(e){return e.addVectors(this.start,this.end).multiplyScalar(.5)}delta(e){return e.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(e,t){return this.delta(t).multiplyScalar(e).add(this.start)}closestPointToPointParameter(e,t){ps.subVectors(e,this.start),ms.subVectors(this.end,this.start);let n=ms.dot(ms);if(n===0)return 0;let r=ms.dot(ps)/n;return t&&(r=K(r,0,1)),r}closestPointToPoint(e,t,n){let r=this.closestPointToPointParameter(e,t);return this.delta(n).multiplyScalar(r).add(this.start)}distanceSqToLine3(e,t=vs,n=ys){let r=1e-8*1e-8,i,a,o=this.start,s=e.start,c=this.end,l=e.end;hs.subVectors(c,o),gs.subVectors(l,s),_s.subVectors(o,s);let u=hs.dot(hs),d=gs.dot(gs),f=gs.dot(_s);if(u<=r&&d<=r)return t.copy(o),n.copy(s),t.sub(n),t.dot(t);if(u<=r)i=0,a=f/d,a=K(a,0,1);else{let e=hs.dot(_s);if(d<=r)a=0,i=K(-e/u,0,1);else{let t=hs.dot(gs),n=u*d-t*t;i=n===0?0:K((t*f-e*d)/n,0,1),a=(t*i+f)/d,a<0?(a=0,i=K(-e/u,0,1)):a>1&&(a=1,i=K((t-e)/u,0,1))}}return t.copy(o).addScaledVector(hs,i),n.copy(s).addScaledVector(gs,a),t.distanceToSquared(n)}applyMatrix4(e){return this.start.applyMatrix4(e),this.end.applyMatrix4(e),this}equals(e){return e.start.equals(this.start)&&e.end.equals(this.end)}clone(){return new this.constructor().copy(this)}},xs=class extends Oi{constructor(e=10,t=10,n=4473924,r=8947848){n=new Bn(n),r=new Bn(r);let i=t/2,a=e/t,o=e/2,s=[],c=[];for(let e=0,l=0,u=-o;e<=t;e++,u+=a){s.push(-o,0,u,o,0,u),s.push(u,0,-o,u,0,o);let t=e===i?n:r;t.toArray(c,l),l+=3,t.toArray(c,l),l+=3,t.toArray(c,l),l+=3,t.toArray(c,l),l+=3}let l=new Fr;l.setAttribute(`position`,new X(s,3)),l.setAttribute(`color`,new X(c,3));let u=new gi({vertexColors:!0,toneMapped:!1});super(l,u),this.type=`GridHelper`}dispose(){this.geometry.dispose(),this.material.dispose()}},Ss=class extends ct{constructor(e,t=null){super(),this.object=e,this.domElement=t,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(e){if(e===void 0){W(`Controls: connect() now requires an element.`);return}this.domElement!==null&&this.disconnect(),this.domElement=e}disconnect(){}dispose(){}update(){}};function Cs(e,t,n,r){let i=ws(r);switch(n){case ee:return e*t;case R:return e*t/i.components*i.byteLength;case te:return e*t/i.components*i.byteLength;case z:return e*t*2/i.components*i.byteLength;case B:return e*t*2/i.components*i.byteLength;case P:return e*t*3/i.components*i.byteLength;case F:return e*t*4/i.components*i.byteLength;case V:return e*t*4/i.components*i.byteLength;case H:case U:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case ne:case re:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case ae:case se:return Math.max(e,16)*Math.max(t,8)/4;case ie:case oe:return Math.max(e,8)*Math.max(t,8)/2;case ce:case le:case de:case fe:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*8;case ue:case pe:case me:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case he:return Math.floor((e+3)/4)*Math.floor((t+3)/4)*16;case ge:return Math.floor((e+4)/5)*Math.floor((t+3)/4)*16;case _e:return Math.floor((e+4)/5)*Math.floor((t+4)/5)*16;case ve:return Math.floor((e+5)/6)*Math.floor((t+4)/5)*16;case ye:return Math.floor((e+5)/6)*Math.floor((t+5)/6)*16;case be:return Math.floor((e+7)/8)*Math.floor((t+4)/5)*16;case xe:return Math.floor((e+7)/8)*Math.floor((t+5)/6)*16;case Se:return Math.floor((e+7)/8)*Math.floor((t+7)/8)*16;case Ce:return Math.floor((e+9)/10)*Math.floor((t+4)/5)*16;case we:return Math.floor((e+9)/10)*Math.floor((t+5)/6)*16;case Te:return Math.floor((e+9)/10)*Math.floor((t+7)/8)*16;case Ee:return Math.floor((e+9)/10)*Math.floor((t+9)/10)*16;case De:return Math.floor((e+11)/12)*Math.floor((t+9)/10)*16;case Oe:return Math.floor((e+11)/12)*Math.floor((t+11)/12)*16;case ke:case Ae:case je:return Math.ceil(e/4)*Math.ceil(t/4)*16;case Me:case Ne:return Math.ceil(e/4)*Math.ceil(t/4)*8;case Pe:case Fe:return Math.ceil(e/4)*Math.ceil(t/4)*16}throw Error(`Unable to determine texture byte length for ${n} format.`)}function ws(e){switch(e){case x:case S:return{byteLength:1,components:1};case w:case C:case O:return{byteLength:2,components:1};case k:case A:return{byteLength:2,components:4};case E:case T:case D:return{byteLength:4,components:1};case M:case N:return{byteLength:4,components:3}}throw Error(`THREE.TextureUtils: Unknown texture type ${e}.`)}typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`register`,{detail:{revision:`185`}})),typeof window<`u`&&(window.__THREE__?W(`WARNING: Multiple instances of Three.js being imported.`):window.__THREE__=`185`);var Ts=0,Es=1,Ds=new J,Os=new bs,ks=new di,As=new J,js=new nr,Ms=class{constructor(){this.tolerance=-1,this.faces=[],this.newFaces=[],this.assigned=new Is,this.unassigned=new Is,this.vertices=[]}setFromPoints(e){if(e.length>=4){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.vertices.push(new Fs(e[t]));this._compute()}return this}setFromObject(e){let t=[];return e.updateMatrixWorld(!0),e.traverse(function(e){let n=e.geometry;if(n!==void 0){let r=n.attributes.position;if(r!==void 0)for(let n=0,i=r.count;n<i;n++){let i=new J;i.fromBufferAttribute(r,n).applyMatrix4(e.matrixWorld),t.push(i)}}}),this.setFromPoints(t)}containsPoint(e){let t=this.faces;for(let n=0,r=t.length;n<r;n++)if(t[n].distanceToPoint(e)>this.tolerance)return!1;return!0}intersectRay(e,t){let n=this.faces,r=-1/0,i=1/0;for(let t=0,a=n.length;t<a;t++){let a=n[t],o=a.distanceToPoint(e.origin),s=a.normal.dot(e.direction);if(o>0&&s>=0)return null;let c=s===0?0:-o/s;if(!(c<=0)&&(s>0?i=Math.min(c,i):r=Math.max(c,r),r>i))return null}return r===-1/0?e.at(i,t):e.at(r,t),t}intersectsRay(e){return this.intersectRay(e,Ds)!==null}makeEmpty(){return this.faces=[],this.vertices=[],this}_addVertexToFace(e,t){return e.face=t,t.outside===null?this.assigned.append(e):this.assigned.insertBefore(t.outside,e),t.outside=e,this}_removeVertexFromFace(e,t){return e===t.outside&&(t.outside=e.next!==null&&e.next.face===t?e.next:null),this.assigned.remove(e),this}_removeAllVerticesFromFace(e){if(e.outside!==null){let t=e.outside,n=e.outside;for(;n.next!==null&&n.next.face===e;)n=n.next;return this.assigned.removeSubList(t,n),t.prev=n.next=null,e.outside=null,t}}_deleteFaceVertices(e,t){let n=this._removeAllVerticesFromFace(e);if(n!==void 0){if(t===void 0)this.unassigned.appendChain(n);else{let e=n;do{let n=e.next;t.distanceToPoint(e.point)>this.tolerance?this._addVertexToFace(e,t):this.unassigned.append(e),e=n}while(e!==null)}}return this}_resolveUnassignedPoints(e){if(this.unassigned.isEmpty()===!1){let t=this.unassigned.first();do{let n=t.next,r=this.tolerance,i=null;for(let n=0;n<e.length;n++){let a=e[n];if(a.mark===Ts){let e=a.distanceToPoint(t.point);if(e>r&&(r=e,i=a),r>1e3*this.tolerance)break}}i!==null&&this._addVertexToFace(t,i),t=n}while(t!==null)}return this}_computeExtremes(){let e=new J,t=new J,n=[],r=[];for(let e=0;e<3;e++)n[e]=r[e]=this.vertices[0];e.copy(this.vertices[0].point),t.copy(this.vertices[0].point);for(let i=0,a=this.vertices.length;i<a;i++){let a=this.vertices[i],o=a.point;for(let t=0;t<3;t++)o.getComponent(t)<e.getComponent(t)&&(e.setComponent(t,o.getComponent(t)),n[t]=a);for(let e=0;e<3;e++)o.getComponent(e)>t.getComponent(e)&&(t.setComponent(e,o.getComponent(e)),r[e]=a)}return this.tolerance=3*2**-52*(Math.max(Math.abs(e.x),Math.abs(t.x))+Math.max(Math.abs(e.y),Math.abs(t.y))+Math.max(Math.abs(e.z),Math.abs(t.z))),{min:n,max:r}}_computeInitialHull(){let e=this.vertices,t=this._computeExtremes(),n=t.min,r=t.max,i=0,a=0;for(let e=0;e<3;e++){let t=r[e].point.getComponent(e)-n[e].point.getComponent(e);t>i&&(i=t,a=e)}let o=n[a],s=r[a],c,l;i=0,Os.set(o.point,s.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s){Os.closestPointToPoint(n.point,!0,As);let e=As.distanceToSquared(n.point);e>i&&(i=e,c=n)}}i=-1,ks.setFromCoplanarPoints(o.point,s.point,c.point);for(let t=0,n=this.vertices.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c){let e=Math.abs(ks.distanceToPoint(n.point));e>i&&(i=e,l=n)}}let u=[];if(ks.distanceToPoint(l.point)<0){u.push(Ns.create(o,s,c),Ns.create(l,s,o),Ns.create(l,c,s),Ns.create(l,o,c));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge(t)),u[e+1].getEdge(1).setTwin(u[t+1].getEdge(0))}}else{u.push(Ns.create(o,c,s),Ns.create(l,o,s),Ns.create(l,s,c),Ns.create(l,c,o));for(let e=0;e<3;e++){let t=(e+1)%3;u[e+1].getEdge(2).setTwin(u[0].getEdge((3-e)%3)),u[e+1].getEdge(0).setTwin(u[t+1].getEdge(1))}}for(let e=0;e<4;e++)this.faces.push(u[e]);for(let t=0,n=e.length;t<n;t++){let n=e[t];if(n!==o&&n!==s&&n!==c&&n!==l){i=this.tolerance;let e=null;for(let t=0;t<4;t++){let r=this.faces[t].distanceToPoint(n.point);r>i&&(i=r,e=this.faces[t])}e!==null&&this._addVertexToFace(n,e)}}return this}_reindexFaces(){let e=[];for(let t=0;t<this.faces.length;t++){let n=this.faces[t];n.mark===Ts&&e.push(n)}return this.faces=e,this}_nextVertexToAdd(){if(this.assigned.isEmpty()===!1){let e,t=0,n=this.assigned.first().face,r=n.outside;do{let i=n.distanceToPoint(r.point);i>t&&(t=i,e=r),r=r.next}while(r!==null&&r.face===n);return e}}_computeHorizon(e,t,n,r){this._deleteFaceVertices(n),n.mark=Es;let i;i=t===null?t=n.getEdge(0):t.next;do{let t=i.twin,n=t.face;n.mark===Ts&&(n.distanceToPoint(e)>this.tolerance?this._computeHorizon(e,t,n,r):r.push(i)),i=i.next}while(i!==t);return this}_addAdjoiningFace(e,t){let n=Ns.create(e,t.tail(),t.head());return this.faces.push(n),n.getEdge(-1).setTwin(t.twin),n.getEdge(0)}_addNewFaces(e,t){this.newFaces=[];let n=null,r=null;for(let i=0;i<t.length;i++){let a=t[i],o=this._addAdjoiningFace(e,a);n===null?n=o:o.next.setTwin(r),this.newFaces.push(o.face),r=o}return n.next.setTwin(r),this}_addVertexToHull(e){let t=[];return this.unassigned.clear(),this._removeVertexFromFace(e,e.face),this._computeHorizon(e.point,null,e.face,t),this._addNewFaces(e,t),this._resolveUnassignedPoints(this.newFaces),this}_cleanup(){return this.assigned.clear(),this.unassigned.clear(),this.newFaces=[],this}_compute(){let e;for(this._computeInitialHull();(e=this._nextVertexToAdd())!==void 0;)this._addVertexToHull(e);return this._reindexFaces(),this._cleanup(),this}},Ns=class e{constructor(){this.normal=new J,this.midpoint=new J,this.area=0,this.constant=0,this.outside=null,this.mark=Ts,this.edge=null}static create(t,n,r){let i=new e,a=new Ps(t,i),o=new Ps(n,i),s=new Ps(r,i);return a.next=s.prev=o,o.next=a.prev=s,s.next=o.prev=a,i.edge=a,i.compute()}getEdge(e){let t=this.edge;for(;e>0;)t=t.next,e--;for(;e<0;)t=t.prev,e++;return t}compute(){let e=this.edge.tail(),t=this.edge.head(),n=this.edge.next.head();return js.set(e.point,t.point,n.point),js.getNormal(this.normal),js.getMidpoint(this.midpoint),this.area=js.getArea(),this.constant=this.normal.dot(this.midpoint),this}distanceToPoint(e){return this.normal.dot(e)-this.constant}},Ps=class{constructor(e,t){this.vertex=e,this.prev=null,this.next=null,this.twin=null,this.face=t}head(){return this.vertex}tail(){return this.prev?this.prev.vertex:null}length(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceTo(e.point)}lengthSquared(){let e=this.head(),t=this.tail();return t===null?-1:t.point.distanceToSquared(e.point)}setTwin(e){return this.twin=e,e.twin=this,this}},Fs=class{constructor(e){this.point=e,this.prev=null,this.next=null,this.face=null}},Is=class{constructor(){this.head=null,this.tail=null}first(){return this.head}last(){return this.tail}clear(){return this.head=this.tail=null,this}insertBefore(e,t){return t.prev=e.prev,t.next=e,t.prev===null?this.head=t:t.prev.next=t,e.prev=t,this}insertAfter(e,t){return t.prev=e,t.next=e.next,t.next===null?this.tail=t:t.next.prev=t,e.next=t,this}append(e){return this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail,e.next=null,this.tail=e,this}appendChain(e){for(this.head===null?this.head=e:this.tail.next=e,e.prev=this.tail;e.next!==null;)e=e.next;return this.tail=e,this}remove(e){return e.prev===null?this.head=e.next:e.prev.next=e.next,e.next===null?this.tail=e.prev:e.next.prev=e.prev,this}removeSubList(e,t){return e.prev===null?this.head=t.next:e.prev.next=t.next,t.next===null?this.tail=e.prev:t.next.prev=e.prev,this}isEmpty(){return this.head===null}},Ls=class extends Fr{constructor(e=[]){super();let t=[],n=[],r=new Ms().setFromPoints(e).faces;for(let e=0;e<r.length;e++){let i=r[e],a=i.edge;do{let e=a.head().point;t.push(e.x,e.y,e.z),n.push(i.normal.x,i.normal.y,i.normal.z),a=a.next}while(a!==i.edge)}this.setAttribute(`position`,new X(t,3)),this.setAttribute(`normal`,new X(n,3))}};function Rs(e,t=!1){let n=e[0].index!==null,r=new Set(Object.keys(e[0].attributes)),i=new Set(Object.keys(e[0].morphAttributes)),a={},o={},s=e[0].morphTargetsRelative,c=new Fr,l=0;for(let u=0;u<e.length;++u){let d=e[u],f=0;if(n!==(d.index!==null))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`),null;for(let e in d.attributes){if(!r.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`),null;a[e]===void 0&&(a[e]=[]),a[e].push(d.attributes[e]),f++}if(f!==r.size)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. Make sure all geometries have the same number of attributes.`),null;if(s!==d.morphTargetsRelative)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. .morphTargetsRelative must be consistent throughout all geometries.`),null;for(let e in d.morphAttributes){if(!i.has(e))return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. .morphAttributes must be consistent throughout all geometries.`),null;o[e]===void 0&&(o[e]=[]),o[e].push(d.morphAttributes[e])}if(t){let e;if(n)e=d.index.count;else if(d.attributes.position!==void 0)e=d.attributes.position.count;else return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index `+u+`. The geometry must have either an index or a position attribute`),null;c.addGroup(l,e,u),l+=e}}if(n){let t=0,n=[];for(let r=0;r<e.length;++r){let i=e[r].index;for(let e=0;e<i.count;++e)n.push(i.getX(e)+t);t+=e[r].attributes.position.count}c.setIndex(n)}for(let e in a){let t=zs(a[e]);if(!t)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` attribute.`),null;c.setAttribute(e,t)}for(let e in o){let t=o[e][0].length;if(t!==0){c.morphAttributes=c.morphAttributes||{},c.morphAttributes[e]=[];for(let n=0;n<t;++n){let t=[];for(let r=0;r<o[e].length;++r)t.push(o[e][r][n]);let r=zs(t);if(!r)return console.error(`THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the `+e+` morphAttribute.`),null;c.morphAttributes[e].push(r)}}}return c}function zs(e){let t,n,r,i=-1,a=0;for(let o=0;o<e.length;++o){let s=e[o];if(t===void 0&&(t=s.array.constructor),t!==s.array.constructor)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes.`),null;if(n===void 0&&(n=s.itemSize),n!==s.itemSize)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes.`),null;if(r===void 0&&(r=s.normalized),r!==s.normalized)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes.`),null;if(i===-1&&(i=s.gpuType),i!==s.gpuType)return console.error(`THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes.`),null;a+=s.count*n}let o=new t(a),s=new xr(o,n,r),c=0;for(let t=0;t<e.length;++t){let r=e[t];if(r.isInterleavedBufferAttribute){let e=c/n;for(let t=0,i=r.count;t<i;t++)for(let i=0;i<n;i++){let n=r.getComponent(t,i);s.setComponent(t+e,i,n)}}else o.set(r.array,c);c+=r.count*n}return i!==void 0&&(s.gpuType=i),s}function Bs(e){e.updateWorldMatrix(!0,!1);let t=e.geometry.getAttribute(`position`),n=e.geometry.index,r=[],i=[],a=new Map;for(let n=0;n<t.count;n++){let o=new J().fromBufferAttribute(t,n).applyMatrix4(e.matrixWorld),s=o.toArray().map(e=>Math.round(e*1e6)).join(`,`),c=a.get(s);c===void 0&&(c=r.length,a.set(s,c),r.push(o)),i.push(c)}let o=new Map,s=n?.count??t.count;for(let e=0;e<s;e+=3){let t=[0,1,2].map(t=>i[n?n.getX(e+t):e+t]);for(let e=0;e<3;e++){let n=t[e],r=t[(e+1)%3];if(n===r)continue;let i=n<r?`${n},${r}`:`${r},${n}`,a=o.get(i);a?a.count++:o.set(i,{a:n,b:r,count:1})}}let c=[...o.values()].filter(e=>e.count===1);if(c.length<3)throw Error(`Loft/extrude/fill requires planar profiles with a closed perimeter`);let l=new Map(c.map(({a:e,b:t})=>[e,t])),u=c[0].a,d=u,f=[];do{f.push(r[d]);let e=l.get(d);if(e===void 0||f.length>c.length)throw Error(`Profile perimeter is not a simple closed loop`);d=e}while(d!==u);if(f.length!==c.length)throw Error(`Profiles with holes or multiple perimeters are not supported by this builder`);return f}function Vs(e,t){if(e.length===t)return e.map(e=>e.clone());let n=e.map((t,n)=>t.distanceTo(e[(n+1)%e.length])),r=n.reduce((e,t)=>e+t,0);if(r<1e-10)throw Error(`Loft profile has zero perimeter`);let i=0,a=0;return Array.from({length:t},(o,s)=>{let c=r*s/t;for(;i<n.length-1&&a+n[i]<c;)a+=n[i++];return e[i].clone().lerp(e[(i+1)%e.length],(c-a)/(n[i]||1))})}function Hs(e){let t=new J;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t.x+=(r.y-i.y)*(r.z+i.z),t.y+=(r.z-i.z)*(r.x+i.x),t.z+=(r.x-i.x)*(r.y+i.y)}return t}function Us(e){for(let t=1;t<e.length;t++)Hs(e[t]).dot(Hs(e[t-1]))<0&&e[t].reverse()}function Ws(e){if(e.length<2)throw Error(`Loft requires at least two cross-sections`);let t=Math.max(...e.map(e=>e.length)),n=e.map(e=>Vs(e,t));Us(n);let r=[];for(let e=0;e<n.length-1;e++)for(let n=0;n<t;n++){let i=e*t+n,a=e*t+(n+1)%t;r.push(i,a,a+t,i,a+t,i+t)}for(let e of[0,n.length-1]){let i=n[e],a=i[0],o=i[1].clone().sub(a).normalize(),s=new J;for(let e=2;e<t&&s.lengthSq()<1e-12;e++)s.crossVectors(o,i[e].clone().sub(a));if(s.lengthSq()<1e-12)throw Error(`Loft profile is degenerate`);s.normalize();let c=s.clone().cross(o),l=i.map(e=>{let t=e.clone().sub(a);if(Math.abs(t.dot(s))>1e-5)throw Error(`Loft cross-sections must be planar`);return new q(t.dot(o),t.dot(c))});for(let[n,i,a]of qa.triangulateShape(l,[])){let o=e*t;e===0?r.push(o+a,o+i,o+n):r.push(o+n,o+i,o+a)}}let i=new Fr;i.setAttribute(`position`,new X(n.flatMap(e=>e.flatMap(e=>e.toArray())),3)),i.setAttribute(`uv`,new X(n.flatMap((e,r)=>Array.from({length:t},(e,i)=>[i/t,r/(n.length-1)]).flat()),2)),i.setIndex(r);let a=i.getAttribute(`position`),o=0;for(let e=0;e<r.length;e+=3){let t=new J().fromBufferAttribute(a,r[e]),n=new J().fromBufferAttribute(a,r[e+1]),i=new J().fromBufferAttribute(a,r[e+2]);o+=t.dot(n.cross(i))}if(Math.abs(o)<1e-10)throw i.dispose(),Error(`Loft cross-sections enclose no volume`);if(o<0){for(let e=0;e<r.length;e+=3)[r[e+1],r[e+2]]=[r[e+2],r[e+1]];i.setIndex(r)}return i.computeVertexNormals(),i}var Gs=1.25,Ks=65535,qs=2**-24,Js=Symbol(`SKIP_GENERATION`),Ys={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Js]:!1};function Xs(e,t,n){return n.min.x=t[e],n.min.y=t[e+1],n.min.z=t[e+2],n.max.x=t[e+3],n.max.y=t[e+4],n.max.z=t[e+5],n}function Zs(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){let i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function Qs(e,t){t.set(e)}function $s(e,t,n){let r,i;for(let a=0;a<3;a++){let o=a+3;r=e[a],i=t[a],n[a]=r<i?r:i,r=e[o],i=t[o],n[o]=r>i?r:i}}function ec(e,t,n){for(let r=0;r<3;r++){let i=t[e+2*r],a=t[e+2*r+1],o=i-a,s=i+a;o<n[r]&&(n[r]=o),s>n[r+3]&&(n[r+3]=s)}}function tc(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function nc(e,t){return t[e+15]===Ks}function rc(e,t){return t[e+6]}function ic(e,t){return t[e+14]}function ac(e){return e+8}function oc(e,t){return e+t[e+6]*8}function sc(e,t){return t[e+7]}function cc(e){return e}function lc(e,t,n,r,i){let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,g=-1/0,_=e.offset||0;for(let r=(t-_)*6,i=(t+n-_)*6;r<i;r+=6){let t=e[r+0],n=e[r+1],i=t-n,_=t+n;i<a&&(a=i),_>c&&(c=_),t<d&&(d=t),t>m&&(m=t);let v=e[r+2],y=e[r+3],b=v-y,x=v+y;b<o&&(o=b),x>l&&(l=x),v<f&&(f=v),v>h&&(h=v);let S=e[r+4],C=e[r+5],w=S-C,T=S+C;w<s&&(s=w),T>u&&(u=T),S<p&&(p=S),S>g&&(g=S)}r[0]=a,r[1]=o,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=d,i[1]=f,i[2]=p,i[3]=m,i[4]=h,i[5]=g}var uc=32,dc=(e,t)=>e.candidate-t.candidate,fc=Array(uc).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),pc=new Float32Array(6);function mc(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Zs(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Zs(e),o!==-1&&(s=hc(n,r,i,o));else if(a===2){let a=tc(e),c=Gs*i,l=n.offset||0,u=(r-l)*6,d=(r+i-l)*6;for(let e=0;e<3;e++){let r=t[e],l=(t[e+3]-r)/uc;if(i<uc/4){let t=[...fc];t.length=i;let r=0;for(let i=u;i<d;i+=6,r++){let a=t[r];a.candidate=n[i+2*e],a.count=0;let{bounds:o,leftCacheBounds:s,rightCacheBounds:c}=a;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,s[e]=1/0,s[e+3]=-1/0,o[e]=1/0,o[e+3]=-1/0;ec(i,n,o)}t.sort(dc);let l=i;for(let e=0;e<l;e++){let n=t[e];for(;e+1<l&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),l--}for(let r=u;r<d;r+=6){let i=n[r+2*e];for(let e=0;e<l;e++){let a=t[e];i>=a.candidate?ec(r,n,a.rightCacheBounds):(ec(r,n,a.leftCacheBounds),a.count++)}}for(let n=0;n<l;n++){let r=t[n],l=r.count,u=i-r.count,d=r.leftCacheBounds,f=r.rightCacheBounds,p=0;l!==0&&(p=tc(d)/a);let m=0;u!==0&&(m=tc(f)/a);let h=1+Gs*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<uc;e++){let t=fc[e];t.count=0,t.candidate=r+l+e*l;let n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=u;t<d;t+=6){let i=~~((n[t+2*e]-r)/l);i>=uc&&(i=31);let a=fc[i];a.count++,ec(t,n,a.bounds)}let t=fc[31];Qs(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=fc[e],n=fc[e+1];$s(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=fc[t],r=n.count,l=n.bounds,u=fc[t+1].rightCacheBounds;r!==0&&(f===0?Qs(l,pc):$s(l,pc,pc)),f+=r;let d=0,p=0;f!==0&&(d=tc(pc)/a);let m=i-f;m!==0&&(p=tc(u)/a);let h=1+Gs*(d*f+p*m);h<c&&(o=e,c=h,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function hc(e,t,n,r){let i=0,a=e.offset;for(let o=t,s=t+n;o<s;o++)i+=e[(o-a)*6+r*2];return i/n}var gc=class{constructor(){this.boundingData=new Float32Array(6)}};function _c(e,t,n,r,i,a){let o=r,s=r+i-1,c=a.pos,l=a.axis*2,u=n.offset||0;for(;;){for(;o<=s&&n[(o-u)*6+l]<c;)o++;for(;o<=s&&n[(s-u)*6+l]>=c;)s--;if(o<s){for(let n=0;n<t;n++){let r=e[o*t+n];e[o*t+n]=e[s*t+n],e[s*t+n]=r}for(let e=0;e<6;e++){let t=o-u,r=s-u,i=n[t*6+e];n[t*6+e]=n[r*6+e],n[r*6+e]=i}o++,s--}else return o}}var vc,yc,bc,xc,Sc=2**32;function Cc(e){return`count`in e?1:1+Cc(e.left)+Cc(e.right)}function wc(e,t,n){return vc=new Float32Array(n),yc=new Uint32Array(n),bc=new Uint16Array(n),xc=new Uint8Array(n),Tc(e,t)}function Tc(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)vc[n+e]=a[e];if(i)return t.buffer?(xc.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(yc[n+6]=t.offset,bc[r+14]=t.count,bc[r+15]=Ks,e+32);{let{left:r,right:i,splitAxis:a}=t,o=Tc(e+32,r),s=e/32,c=o/32-s;if(c>Sc)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return yc[n+6]=c,yc[n+7]=a,Tc(o,i)}}function Ec(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new gc;return lc(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=mc(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:_c(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,Zs(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new gc,x=n,S=y-n;e.left=b,lc(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new gc,w=y,T=r-S;return e.right=C,lc(t,w,T,C.boundingData,m),v(C,w,T,m,a+1),e}}function Dc(e,t){let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=e.getRootRanges(t.range),i=r[0],a=r[r.length-1],o={offset:i.offset,count:a.offset+a.count-i.offset},s=new Float32Array(6*o.count);s.offset=o.offset,e.computePrimitiveBounds(o.offset,o.count,s),e._roots=r.map(r=>{let i=Ec(e,s,r.offset,r.count,t,o),a=Cc(i),c=new n(32*a);return wc(0,i,c),c})}var Oc=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},Q=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}},kc,Ac,jc=[],Mc=new Oc(()=>new rr);function Nc(e,t,n,r,i,a){kc=Mc.getPrimitive(),Ac=Mc.getPrimitive(),jc.push(kc,Ac),Q.setBuffer(e._roots[t]);let o=Pc(0,e.geometry,n,r,i,a);Q.clearBuffer(),Mc.releasePrimitive(kc),Mc.releasePrimitive(Ac),jc.pop(),jc.pop();let s=jc.length;return s>0&&(Ac=jc[s-1],kc=jc[s-2]),o}function Pc(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c)){let t=rc(e,l),n=ic(u,c);return Xs(cc(e),s,kc),r(t,n,!1,o,a+e/8,kc)}{let u=ac(e),p=oc(e,l),m=u,h=p,g,_,v,y;if(i&&(v=kc,y=Ac,Xs(cc(m),s,v),Xs(cc(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=kc,Xs(cc(m),s,v));let b=nc(m*2,c),x=n(v,b,g,o+1,a+m/8),S;if(x===2){let e=d(m);S=r(e,f(m)-e,!0,o+1,a+m/8,v)}else S=x&&Pc(m,t,n,r,i,a,o+1);if(S)return!0;y=Ac,Xs(cc(h),s,y);let C=nc(h*2,c),w=n(y,C,_,o+1,a+h/8),T;if(w===2){let e=d(h);T=r(e,f(h)-e,!0,o+1,a+h/8,y)}else T=w&&Pc(h,t,n,r,i,a,o+1);if(T)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=Q,r=e*2;for(;!nc(r,t);)e=ac(e),r=e*2;return rc(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=Q,r=e*2;for(;!nc(r,t);)e=oc(e,n),r=e*2;return rc(e,n)+ic(r,t)}}}var Fc=new Q.constructor,Ic=new Q.constructor,Lc=new Oc(()=>new rr),Rc=new rr,zc=new rr,Bc=new rr,Vc=new rr,Hc=!1;function Uc(e,t,n,r){if(Hc)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Hc=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new Y().copy(n).invert();for(let e=0,t=i.length;e<t;e++){Fc.setBuffer(i[e]),c=0;let t=Lc.getPrimitive();Xs(cc(0),Fc.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(Ic.setBuffer(a[e]),o=Wc(0,0,n,l,r,s,c,0,0,t),Ic.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(Lc.releasePrimitive(t),Fc.clearBuffer(),s+=i[e].byteLength/32,o)break}return Hc=!1,o}function Wc(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=Ic,f=Fc):(d=Fc,f=Ic);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=nc(y,h),S=nc(b,v),C=!1;if(S&&x)C=u?i(rc(t,_),ic(t*2,v),rc(e,m),ic(e*2,h),c,o+t/8,s,a+e/8):i(rc(e,m),ic(e*2,h),rc(t,_),ic(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=Lc.getPrimitive();Xs(cc(t),g,l),l.applyMatrix4(n);let d=ac(e),f=oc(e,m);Xs(cc(d),p,Rc),Xs(cc(f),p,zc);let h=l.intersectsBox(Rc),_=l.intersectsBox(zc);C=h&&Wc(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&Wc(t,f,r,n,i,o,a,c,s+1,l,!u),Lc.releasePrimitive(l)}else{let d=ac(t),f=oc(t,_);Xs(cc(d),g,Bc),Xs(cc(f),g,Vc);let h=l.intersectsBox(Bc),v=l.intersectsBox(Vc);if(h&&v)C=Wc(e,d,n,r,i,a,o,s,c+1,l,u)||Wc(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=Wc(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=Lc.getPrimitive();t.copy(Bc).applyMatrix4(n);let l=ac(e),f=oc(e,m);Xs(cc(l),p,Rc),Xs(cc(f),p,zc);let h=t.intersectsBox(Rc),g=t.intersectsBox(zc);C=h&&Wc(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&Wc(d,f,r,n,i,o,a,c,s+1,t,!u),Lc.releasePrimitive(t)}}else if(v){if(x)C=Wc(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=Lc.getPrimitive();t.copy(Vc).applyMatrix4(n);let l=ac(e),d=oc(e,m);Xs(cc(l),p,Rc),Xs(cc(d),p,zc);let h=t.intersectsBox(Rc),g=t.intersectsBox(zc);C=h&&Wc(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&Wc(f,d,r,n,i,o,a,c,s+1,t,!u),Lc.releasePrimitive(t)}}}return C}var Gc=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!nc(r,n);)e=ac(e),r=e*2;return rc(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!nc(r,n);)e=oc(e,t),r=e*2;return rc(e,t)+ic(r,n)};let i=(e,r,a)=>{let o=nc(r*2,n);if(!e(a,o,r)&&!o){let n=ac(r),o=oc(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}{let n=sc(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Kc=new rr,qc=new Float32Array(6),Jc=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Ys,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),Dc(this,e)}getRootRanges(){throw Error(`BVH: getRootRanges() not implemented`)}writePrimitiveBounds(){throw Error(`BVH: writePrimitiveBounds() not implemented`)}writePrimitiveRangeBounds(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let n=e,r=e+t;n<r;n++){this.writePrimitiveBounds(n,qc,0);let[e,t,r,u,d,f]=qc;e<i&&(i=e),u>s&&(s=u),t<a&&(a=t),d>c&&(c=d),r<o&&(o=r),f>l&&(l=f)}return n[r+0]=i,n[r+1]=a,n[r+2]=o,n[r+3]=s,n[r+4]=c,n[r+5]=l,n}computePrimitiveBounds(e,t,n){let r=n.offset||0;for(let i=e,a=e+t;i<a;i++){this.writePrimitiveBounds(i,qc,0);let[e,t,a,o,s,c]=qc,l=(e+o)/2,u=(t+s)/2,d=(a+c)/2,f=(o-e)/2,p=(s-t)/2,m=(c-a)/2,h=(i-r)*6;n[h+0]=l,n[h+1]=f+(Math.abs(l)+f)*qs,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*qs,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*qs}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;nc(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Gc.setBVH(this,t),Gc.traverse(e),Gc.reset()}refit(){let e=this._roots;for(let t=0,n=e.length;t<n;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n),a=new Float32Array(n),o=n.byteLength/32;for(let e=o-1;e>=0;e--){let t=e*8,n=t*2;if(nc(n,i)){let e=rc(t,r),o=ic(n,i);this.writePrimitiveRangeBounds(e,o,qc,0),a.set(qc,t)}else{let e=ac(t),n=oc(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Xs(0,new Float32Array(t),Kc),e.union(Kc)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:r,intersectsPrimitive:i,scratchPrimitive:a,iterate:o}=e;if(r&&i){let e=r;r=(t,n,r,s,c)=>e(t,n,r,s,c)?!0:o(t,n,this,i,r,s,a)}else r||=i?(e,t,n,r)=>o(e,t,this,i,n,r,a):(e,t,n)=>n;let s=!1,c=0,l=this._roots;for(let e=0,i=l.length;e<i;e++){let i=l[e];if(s=Nc(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Uc(this,e,t,r)}};function Yc(){return typeof SharedArrayBuffer<`u`}function Xc(e){return e.index?e.index.count:e.attributes.position.count}function Zc(e){return Xc(e)/3}function Qc(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function $c(e,t){if(!e.index){let n=e.attributes.position.count,r=Qc(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new xr(r,1));for(let e=0;e<n;e++)r[e]=e}}function el(e,t,n){let r=Xc(e)/n,i=t||e.drawRange,a=i.start/n,o=(i.start+i.count)/n,s=Math.max(0,a),c=Math.min(r,o)-s;return{offset:Math.floor(s),count:Math.floor(c)}}function tl(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function nl(e,t,n){let r=el(e,t,n),i=tl(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Xc(e)/n,l=[];for(let e of i){let{offset:t,count:n}=e,r=t,i=t+(isFinite(n)?n:c-t);r<s&&i>o&&(l.push({pos:Math.max(o,r),isStart:!0}),l.push({pos:Math.min(s,i),isStart:!1}))}l.sort((e,t)=>e.pos===t.pos?e.type===`end`?-1:1:e.pos-t.pos);let u=0,d=null;for(let e of l){let t=e.pos;u!==0&&t!==d&&a.push({offset:d,count:t-d}),u+=e.isStart?1:-1,d=t}return a}function rl(e,t){let n=e[e.length-1],r=n.offset+n.count>2**16,i=e.reduce((e,t)=>e+t.count,0),a=r?4:2,o=t?new SharedArrayBuffer(i*a):new ArrayBuffer(i*a),s=r?new Uint32Array(o):new Uint16Array(o),c=0;for(let t=0;t<e.length;t++){let{offset:n,count:r}=e[t];for(let e=0;e<r;e++)s[c+e]=n+e;c+=r}return s}var il=class extends Jc{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(!e.isBufferGeometry)throw Error(`BVH: Only BufferGeometries are supported.`);if(e.index&&e.index.isInterleavedBufferAttribute)throw Error(`BVH: InterleavedBufferAttribute is not supported for the index attribute.`);if(t.useSharedArrayBuffer&&!Yc())throw Error(`BVH: SharedArrayBuffer is not available.`);super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Ys,...t},t[Js]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=rl(nl(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else $c(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new rr))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:nl(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},al=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,a=e.length;i<a;i++){let a=e[i][t];n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,a=t.length;i<a;i++){let a=t[i],o=e.dot(a);n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}};al.prototype.setFromBox=(function(){let e=new J;return function(t,n){let r=n.min,i=n.max,a=1/0,o=-1/0;for(let n=0;n<=1;n++)for(let s=0;s<=1;s++)for(let c=0;c<=1;c++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var ol=(function(){let e=new J,t=new J,n=new J;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.dot(s),m=s.dot(s)*f-d*d,h,g;h=m===0?0:(u*d-p*f)/m,g=(u+h*d)/f,a.x=h,a.y=g}})(),sl=(function(){let e=new q,t=new J,n=new J;return function(r,i,a,o){ol(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}a.copy(e),o.copy(d);return}}})(),cl=(function(){let e=new J,t=new J,n=new di,r=new bs;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),ll=[`x`,`y`,`z`],ul=1e-15,dl=ul*ul;function fl(e){return Math.abs(e)<ul}var pl=class extends nr{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new J),this.satBounds=[,,,,].fill().map(()=>new al),this.points=[this.a,this.b,this.c],this.plane=new di,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new bs,this.needsUpdate=!0}intersectsSphere(e){return cl(e,this)}update(){let e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,a=this.satBounds,o=i[0],s=a[0];this.getNormal(o),s.setFromPoints(o,r);let c=i[1],l=a[1];c.subVectors(e,t),l.setFromPoints(c,r);let u=i[2],d=a[2];u.subVectors(t,n),d.setFromPoints(u,r);let f=i[3],p=a[3];f.subVectors(n,e),p.setFromPoints(f,r);let m=c.length(),h=u.length(),g=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<ul?h<ul||g<ul?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<ul?g<ul?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<ul&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};pl.prototype.closestPointToSegment=(function(){let e=new J,t=new J,n=new bs;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),sl(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),pl.prototype.intersectsTriangle=(function(){let e=new pl,t=new al,n=new al,r=new J,i=new J,a=new J,o=new J,s=new bs,c=new bs,l=new J,u=new q,d=new q;function f(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function p(e,t,n,r,i,a,o,s,c,l,u){let d=o/(o-s);l.x=r+(i-r)*d,u.start.subVectors(t,e).multiplyScalar(d).add(e),d=o/(o-c),l.y=r+(a-r)*d,u.end.subVectors(n,e).multiplyScalar(d).add(e)}function m(e,t,n,r,i,a,o,s,c,l,u){if(i>0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)p(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)p(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)p(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function h(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return fl(o)?fl(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):fl(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function g(e,t,n){let r=t.a;return fl(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function _(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<dl&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}function v(e,t,n,o){if(e.isDegenerateIntoSegment){if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.start),d=c.x*l.y-c.y*l.x;if(fl(d))return!1;let f=(u.x*l.y-u.y*l.x)/d,p=-(c.x*u.y-c.y*u.x)/d;return f<0||f>1||p<0||p>1?!1:fl(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}return t.isDegenerateIntoPoint?_(e,t,n):h(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<dl&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?_(t,e,n):g(t,e,n);if(t.isDegenerateIntoPoint)return g(e,t,n);if(t.isDegenerateIntoSegment)return h(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=v(this,t,n,r);if(o!==void 0)return o;let p=this.plane,h=t.plane,g=h.distanceToPoint(this.a),_=h.distanceToPoint(this.b),y=h.distanceToPoint(this.c);fl(g)&&(g=0),fl(_)&&(_=0),fl(y)&&(y=0);let b=g*_,x=g*y;if(b>0&&x>0)return!1;let S=p.distanceToPoint(t.a),C=p.distanceToPoint(t.b),w=p.distanceToPoint(t.c);fl(S)&&(S=0),fl(C)&&(C=0),fl(w)&&(w=0);let T=S*C,E=S*w;if(T>0&&E>0)return!1;i.copy(p.normal),a.copy(h.normal);let D=i.cross(a),O=0,k=Math.abs(D.x),A=Math.abs(D.y);A>k&&(k=A,O=1),Math.abs(D.z)>k&&(O=2);let j=ll[O],M=this.a[j],N=this.b[j],ee=this.c[j],P=t.a[j],F=t.b[j],I=t.c[j];if(m(this,M,N,ee,b,x,g,_,y,u,s)||m(t,P,F,I,T,E,S,C,w,d,c))return f(this,t,n,r);if(u.y<u.x){let e=u.y;u.y=u.x,u.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(n&&(d.x>u.x?n.start.copy(c.start):n.start.copy(s.start),d.y<u.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),pl.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),pl.prototype.distanceToTriangle=(function(){let e=new J,t=new J,n=[`a`,`b`,`c`],r=new bs,i=new bs;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),sl(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var ml=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new J,this.max=new J,this.matrix=new Y,this.invMatrix=new Y,this.points=Array(8).fill().map(()=>new J),this.satAxes=[,,,].fill().map(()=>new J),this.satBounds=[,,,].fill().map(()=>new al),this.alignedSatBounds=[,,,].fill().map(()=>new al),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}};ml.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let s=r[1*i|2*a|4*o];s.x=i?n.x:t.x,s.y=a?n.y:t.y,s.z=o?n.z:t.z,s.applyMatrix4(e)}let i=this.satBounds,a=this.satAxes,o=r[0];for(let e=0;e<3;e++){let t=a[e],n=i[e],s=r[1<<e];t.subVectors(o,s),n.setFromPoints(t,r)}let s=this.alignedSatBounds;s[0].setFromPointsField(r,`x`),s[1].setFromPointsField(r,`y`),s[2].setFromPointsField(r,`z`),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),ml.prototype.intersectsBox=(function(){let e=new al;return function(t){this.needsUpdate&&this.update();let n=t.min,r=t.max,i=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,o[0].isSeparated(e)||(e.min=n.y,e.max=r.y,o[1].isSeparated(e))||(e.min=n.z,e.max=r.z,o[2].isSeparated(e)))return!1;for(let n=0;n<3;n++){let r=a[n],o=i[n];if(e.setFromBox(r,t),o.isSeparated(e))return!1}return!0}})(),ml.prototype.intersectsTriangle=(function(){let e=new pl,t=[,,,],n=new al,r=new al,i=new J;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}})(),ml.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})(),ml.prototype.distanceToPoint=(function(){let e=new J;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),ml.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new bs),n=Array(12).fill().map(()=>new bs),r=new J,i=new J;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[m],b=y.start,x=y.end;b[g]=u[g],b[_]=i?u[_]:d[_],b[v]=a?u[v]:d[_],x[g]=d[g],x[_]=i?u[_]:d[_],x[v]=a?u[v]:d[_],m++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];sl(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var hl=new class extends Oc{constructor(){super(()=>new pl)}},gl=new J,_l=new J;function vl(e,t,n={},r=0,i=1/0){let a=r*r,o=i*i,s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>(gl.copy(t).clamp(e.min,e.max),gl.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,gl);let r=t.distanceToSquared(gl);return r<s&&(_l.copy(gl),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(_l):n.point=_l.clone(),n.distance=l,n.faceIndex=c,n}var yl=!0,bl=new J,xl=new J,Sl=new J,Cl=new q,wl=new q,Tl=new q,El=new J,Dl=new J,Ol=new J,kl=new J;function Al(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function jl(e,t,n,r,i,a,o,s,c,l,u){bl.fromBufferAttribute(t,a),xl.fromBufferAttribute(t,o),Sl.fromBufferAttribute(t,s);let d=Al(e,bl,xl,Sl,kl,c,l,u);if(d){if(r){Cl.fromBufferAttribute(r,a),wl.fromBufferAttribute(r,o),Tl.fromBufferAttribute(r,s),d.uv=new q;let e=nr.getInterpolation(kl,bl,xl,Sl,Cl,wl,Tl,d.uv);yl||(d.uv=e)}if(i){Cl.fromBufferAttribute(i,a),wl.fromBufferAttribute(i,o),Tl.fromBufferAttribute(i,s),d.uv1=new q;let e=nr.getInterpolation(kl,bl,xl,Sl,Cl,wl,Tl,d.uv1);yl||(d.uv1=e)}if(n){El.fromBufferAttribute(n,a),Dl.fromBufferAttribute(n,o),Ol.fromBufferAttribute(n,s),d.normal=new J;let t=nr.getInterpolation(kl,bl,xl,Sl,El,Dl,Ol,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),yl||(d.normal=t)}let t={a,b:o,c:s,normal:new J,materialIndex:0};if(nr.getNormal(bl,xl,Sl,t.normal),d.face=t,d.faceIndex=a,yl){let e=new J;nr.getBarycoord(kl,bl,xl,Sl,e),d.barycoord=e}}return d}function Ml(e){return e&&e.isMaterial?e.side:e}function Nl(e,t,n,r,i,a,o){let s=r*3,c=s+0,l=s+1,u=s+2,{index:d,groups:f}=e;e.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));let{position:p,normal:m,uv:h,uv1:g}=e.attributes;if(Array.isArray(t)){let e=r*3;for(let s=0,d=f.length;s<d;s++){let{start:d,count:_,materialIndex:v}=f[s];if(e>=d&&e<d+_){let e=Ml(t[v]),s=jl(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=v,i)i.push(s);else return s}}}}else{let e=Ml(t),s=jl(n,p,m,h,g,c,l,u,e,a,o);if(s){if(s.faceIndex=r,s.face.materialIndex=0,i)i.push(s);else return s}}return null}function Pl(e,t,n,r){let i=e.a,a=e.b,o=e.c,s=t,c=t+1,l=t+2;n&&(s=n.getX(s),c=n.getX(c),l=n.getX(l)),i.x=r.getX(s),i.y=r.getY(s),i.z=r.getZ(s),a.x=r.getX(c),a.y=r.getY(c),a.z=r.getZ(c),o.x=r.getX(l),o.y=r.getY(l),o.z=r.getZ(l)}function Fl(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Nl(c,t,n,e,a,o,s)}function Il(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=Nl(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Ll(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let n=e,s=t+e;n<s;n++){let e;if(e=n,Pl(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Rl(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(nc(l,s)){let t=rc(e,o),n=ic(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}{let r=ac(e),i=oc(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function zl(e,t,n,r,i){let a,o,s,c,l,u,d=1/n.direction.x,f=1/n.direction.y,p=1/n.direction.z,m=n.origin.x,h=n.origin.y,g=n.origin.z,_=t[e],v=t[e+3],y=t[e+1],b=t[e+3+1],x=t[e+2],S=t[e+3+2];return d>=0?(a=(_-m)*d,o=(v-m)*d):(a=(v-m)*d,o=(_-m)*d),f>=0?(s=(y-h)*f,c=(b-h)*f):(s=(b-h)*f,c=(y-h)*f),a>c||s>o||((s>a||isNaN(a))&&(a=s),(c<o||isNaN(o))&&(o=c),p>=0?(l=(x-g)*p,u=(S-g)*p):(l=(S-g)*p,u=(x-g)*p),a>u||l>o)?!1:((l>a||a!==a)&&(a=l),(u<o||o!==o)&&(o=u),a<=i&&o>=r)}function Bl(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Nl(c,t,n,l?l[e]:e,a,o,s)}function Vl(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=Nl(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Hl(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),Pl(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ul(e,t,n,r,i,a,o){Q.setBuffer(e._roots[t]),Wl(0,e,n,r,i,a,o),Q.clearBuffer()}function Wl(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c))Fl(t,n,r,rc(e,l),ic(u,c),i,a,o);else{let c=ac(e);zl(c,s,r,a,o)&&Wl(c,t,n,r,i,a,o);let u=oc(e,l);zl(u,s,r,a,o)&&Wl(u,t,n,r,i,a,o)}}var Gl=[`x`,`y`,`z`];function Kl(e,t,n,r,i,a){Q.setBuffer(e._roots[t]);let o=ql(0,e,n,r,i,a);return Q.clearBuffer(),o}function ql(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=Q,l=e*2;if(nc(l,s))return Il(t,n,r,rc(e,c),ic(l,s),i,a);{let s=sc(e,c),l=Gl[s],u=r.direction[l]>=0,d,f;u?(d=ac(e),f=oc(e,c)):(d=oc(e,c),f=ac(e));let p=zl(d,o,r,i,a)?ql(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=zl(f,o,r,i,a)?ql(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Jl=new rr,Yl=new pl,Xl=new pl,Zl=new Y,Ql=new ml,$l=new ml;function eu(e,t,n,r){Q.setBuffer(e._roots[t]);let i=tu(0,e,n,r);return Q.clearBuffer(),i}function tu(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=Q,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Ql.set(n.boundingBox.min,n.boundingBox.max,r),i=Ql),nc(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=rc(e,s),m=ic(c,o);if(Zl.copy(r).invert(),n.boundsTree)return Xs(cc(e),a,$l),$l.matrix.copy(Zl),$l.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>$l.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=p*3,n=(m+p)*3;t<n;t+=3)if(Pl(Xl,t,l,u),Xl.needsUpdate=!0,e.intersectsTriangle(Xl))return!0;return!1}});{let e=Zc(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){Pl(Yl,t,l,u),Yl.a.applyMatrix4(Zl),Yl.b.applyMatrix4(Zl),Yl.c.applyMatrix4(Zl),Yl.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Pl(Xl,t,d,f),Xl.needsUpdate=!0,Yl.intersectsTriangle(Xl))return!0}}}else{let o=ac(e),c=oc(e,s);return Xs(cc(o),a,Jl),!!(i.intersectsBox(Jl)&&tu(o,t,n,r,i)||(Xs(cc(c),a,Jl),i.intersectsBox(Jl)&&tu(c,t,n,r,i)))}}var nu=new Y,ru=new ml,iu=new ml,au=new J,ou=new J,su=new J,cu=new J;function lu(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),ru.set(t.boundingBox.min,t.boundingBox.max,n),ru.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=hl.getPrimitive(),p=hl.getPrimitive(),m=au,h=ou,g=null,_=null;i&&(g=su,_=cu);let v=1/0,y=null,b=null;return nu.copy(n).invert(),iu.matrix.copy(nu),e.shapecast({boundsTraverseOrder:e=>ru.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(iu.min.copy(e.min),iu.max.copy(e.max),iu.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>iu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){Pl(p,3*o,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Pl(f,3*t,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=t,b=o),e<a)return!0}}}});{let i=Zc(t);for(let t=0,o=i;t<o;t++){Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=e,i=e+r;n<i;n++){Pl(f,3*n,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=n,b=t),e<a)return!0}}}}}),hl.releasePrimitive(f),hl.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(nu),h.applyMatrix4(nu),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function uu(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(nc(u,s)){let t=rc(n,o),a=ic(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}{let e=ac(n),r=oc(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function du(e,t,n,r,i,a,o){Q.setBuffer(e._roots[t]),fu(0,e,n,r,i,a,o),Q.clearBuffer()}function fu(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=Q,u=e*2;if(nc(u,c))Bl(t,n,r,rc(e,l),ic(u,c),i,a,o);else{let c=ac(e);zl(c,s,r,a,o)&&fu(c,t,n,r,i,a,o);let u=oc(e,l);zl(u,s,r,a,o)&&fu(u,t,n,r,i,a,o)}}var pu=[`x`,`y`,`z`];function mu(e,t,n,r,i,a){Q.setBuffer(e._roots[t]);let o=hu(0,e,n,r,i,a);return Q.clearBuffer(),o}function hu(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=Q,l=e*2;if(nc(l,s))return Vl(t,n,r,rc(e,c),ic(l,s),i,a);{let s=sc(e,c),l=pu[s],u=r.direction[l]>=0,d,f;u?(d=ac(e),f=oc(e,c)):(d=oc(e,c),f=ac(e));let p=zl(d,o,r,i,a)?hu(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=zl(f,o,r,i,a)?hu(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var gu=new rr,_u=new pl,vu=new pl,yu=new Y,bu=new ml,xu=new ml;function Su(e,t,n,r){Q.setBuffer(e._roots[t]);let i=Cu(0,e,n,r);return Q.clearBuffer(),i}function Cu(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=Q,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),bu.set(n.boundingBox.min,n.boundingBox.max,r),i=bu),nc(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=rc(e,s),m=ic(c,o);if(yu.copy(r).invert(),n.boundsTree)return Xs(cc(e),a,xu),xu.matrix.copy(yu),xu.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>xu.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=m+p;n<r;n++)if(Pl(vu,3*t.resolveTriangleIndex(n),l,u),vu.needsUpdate=!0,e.intersectsTriangle(vu))return!0;return!1}});{let e=Zc(n);for(let n=p,r=m+p;n<r;n++){Pl(_u,3*t.resolveTriangleIndex(n),l,u),_u.a.applyMatrix4(yu),_u.b.applyMatrix4(yu),_u.c.applyMatrix4(yu),_u.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Pl(vu,t,d,f),vu.needsUpdate=!0,_u.intersectsTriangle(vu))return!0}}}else{let o=ac(e),c=oc(e,s);return Xs(cc(o),a,gu),!!(i.intersectsBox(gu)&&Cu(o,t,n,r,i)||(Xs(cc(c),a,gu),i.intersectsBox(gu)&&Cu(c,t,n,r,i)))}}var wu=new Y,Tu=new ml,Eu=new ml,Du=new J,Ou=new J,ku=new J,Au=new J;function ju(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Tu.set(t.boundingBox.min,t.boundingBox.max,n),Tu.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=hl.getPrimitive(),p=hl.getPrimitive(),m=Du,h=Ou,g=null,_=null;i&&(g=ku,_=Au);let v=1/0,y=null,b=null;return wu.copy(n).invert(),Eu.matrix.copy(wu),e.shapecast({boundsTraverseOrder:e=>Tu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Eu.min.copy(e.min),Eu.max.copy(e.max),Eu.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>Eu.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){let n=e.resolveTriangleIndex(t);Pl(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}{let o=Zc(t);for(let t=0,s=o;t<s;t++){Pl(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=r,o=r+i;n<o;n++){let r=e.resolveTriangleIndex(n);Pl(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<a)return!0}}}}}),hl.releasePrimitive(f),hl.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(wu),h.applyMatrix4(wu),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Mu(e,t,n){return e===null?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}var Nu=new ml,Pu=new Gr,Fu=new J,Iu=new Y,Lu=new J,Ru=[`getX`,`getY`,`getZ`],zu=class e extends il{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[Js]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new xr(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;nc(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.`),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=(i?i[e]:e)*3,c=s+0,l=s+1,u=s+2;o&&(c=o[c],l=o[l],u=o[u]);for(let e=0;e<3;e++){let r=a[Ru[e]](c),i=a[Ru[e]](l),o=a[Ru[e]](u),s=r;i<s&&(s=i),o<s&&(s=o);let d=r;i>d&&(d=i),o>d&&(d=o),t[n+e]=s,t[n+e+3]=d}return t}computePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw Error(`MeshBVH: compute triangle bounds range is invalid.`);let c=a.array,l=a.offset||0,u=3;a.isInterleavedBufferAttribute&&(u=a.data.stride);let d=[`getX`,`getY`,`getZ`],f=n.offset;for(let r=e,p=e+t;r<p;r++){let e=(i?i[r]:r)*3,t=(r-f)*6,p=e+0,m=e+1,h=e+2;o&&(p=o[p],m=o[m],h=o[h]),s||(p=p*u+l,m=m*u+l,h=h*u+l);for(let e=0;e<3;e++){let r,i,o;s?(r=a[d[e]](p),i=a[d[e]](m),o=a[d[e]](h)):(r=c[p+e],i=c[m+e],o=c[h+e]);let l=r;i<l&&(l=i),o<l&&(l=o);let u=r;i>u&&(u=i),o>u&&(u=o);let f=(u-l)/2,g=e*2;n[t+g+0]=l+f,n[t+g+1]=f+(Math.abs(l)+f)*qs}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;Iu.copy(e.matrixWorld).invert(),Pu.copy(t.ray).applyMatrix4(Iu),Lu.setFromMatrixScale(e.matrixWorld),Fu.copy(Pu.direction).multiply(Lu);let i=Fu.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(Pu,r,a,o);i=Mu(i,e,t),i&&n.push(i)}else{let i=this.raycast(Pu,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=Mu(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?uu:Rl)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?du:Ul;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?mu:Kl;for(let s=0,c=i.length;s<c;s++){let i=o(this,s,t,e,n,r);i!=null&&(a==null||i.distance<a.distance)&&(a=i)}return a}intersectsGeometry(e,t){let n=!1,r=this._roots,i=this.indirect?Su:eu;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=hl.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Hl:Ll});return hl.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=hl.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);Pl(o,t*3,s,c)}:e=>{Pl(o,e*3,s,c)},u=hl.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);Pl(u,n*3,d,f)}:e=>{Pl(u,e*3,d,f)};if(a){if(!(t instanceof e))throw Error(`MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.`);let r=(e,t,r,i,s,c,d,f)=>{for(let m=r,h=r+i;m<h;m++){p(m),u.a.applyMatrix4(n),u.b.applyMatrix4(n),u.c.applyMatrix4(n),u.needsUpdate=!0;for(let n=e,r=e+t;n<r;n++)if(l(n),o.needsUpdate=!0,a(o,u,n,m,s,c,d,f))return!0}return!1};if(i){let e=i;i=function(t,n,i,a,o,s,c,l){return e(t,n,i,a,o,s,c,l)?!0:r(t,n,i,a,o,s,c,l)}}else i=r}return super.bvhcast(t,n,{intersectsRanges:i})}intersectsBox(e,t){return Nu.set(e.min,e.max,t),Nu.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Nu.intersectsBox(e),intersectsTriangle:e=>Nu.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,a=1/0){return(this.indirect?ju:lu)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return vl(this,e,t,n,r)}},Bu=1e-6,Vu=Bu*.5,Hu=10**-Math.log10(Bu),Uu=Vu*Hu;function Wu(e){return~~(e*Hu+Uu)}function Gu(e){return`${Wu(e.x)},${Wu(e.y)}`}function Ku(e){return`${Wu(e.x)},${Wu(e.y)},${Wu(e.z)}`}function qu(e){return`${Wu(e.x)},${Wu(e.y)},${Wu(e.z)},${Wu(e.w)}`}function Ju(e,t,n){n.direction.subVectors(t,e).normalize();let r=e.dot(n.direction);return n.origin.copy(e).addScaledVector(n.direction,-r),n}function Yu(){return typeof SharedArrayBuffer<`u`}function Xu(e){if(e.buffer instanceof SharedArrayBuffer)return e;let t=e.constructor,n=e.buffer,r=new SharedArrayBuffer(n.byteLength),i=new Uint8Array(n);return new Uint8Array(r).set(i,0),new t(r)}function Zu(e){return e.index?e.index.count:e.attributes.position.count}function Qu(e){return Zu(e)/3}var $u=1e-8,ed=new J;function td(e){return~~(e/3)}function nd(e){return e%3}function rd(e,t){return e.start-t.start}function id(e,t){return ed.subVectors(t,e.origin).dot(e.direction)}function ad(e,t,n,r=$u){e.sort(rd),t.sort(rd);for(let r=0;r<e.length;r++){let i=e[r];for(let s=0;s<t.length;s++){let c=t[s];if(!(c.start>i.end)){if(i.end<c.start||c.end<i.start)continue;if(i.start<=c.start&&i.end>=c.end)a(c.end,i.end)||e.splice(r+1,0,{start:c.end,end:i.end,index:i.index}),i.end=c.start,c.start=0,c.end=0;else if(i.start>=c.start&&i.end<=c.end)a(i.end,c.end)||t.splice(s+1,0,{start:i.end,end:c.end,index:c.index}),c.end=i.start,i.start=0,i.end=0;else if(i.start<=c.start&&i.end<=c.end){let e=i.end;i.end=c.start,c.start=e}else if(i.start>=c.start&&i.end>=c.end){let e=c.end;c.end=i.start,i.start=e}else throw Error()}if(n.has(i.index)||n.set(i.index,[]),n.has(c.index)||n.set(c.index,[]),n.get(i.index).push(c.index),n.get(c.index).push(i.index),o(c)&&(t.splice(s,1),s--),o(i)){e.splice(r,1),r--;break}}}i(e),i(t);function i(e){for(let t=0;t<e.length;t++)o(e[t])&&(e.splice(t,1),t--)}function a(e,t){return Math.abs(t-e)<r}function o(e){return Math.abs(e.end-e.start)<r}}var od=1e-5,sd=1e-4,cd=class{constructor(){this._rays=[]}addRay(e){this._rays.push(e)}findClosestRay(e){let t=this._rays,n=e.clone();n.direction.multiplyScalar(-1);let r=1/0,i=null;for(let s=0,c=t.length;s<c;s++){let c=t[s];if(a(c,e)&&a(c,n))continue;let l=o(c,e),u=o(c,n),d=Math.min(l,u);d<r&&(r=d,i=c)}return i;function a(e,t){let n=e.origin.distanceTo(t.origin)>od;return e.direction.angleTo(t.direction)>sd||n}function o(e,t){let n=e.origin.distanceTo(t.origin),r=e.direction.angleTo(t.direction);return n/od+r/sd}}},ld=new J,ud=new J,dd=new Gr;function fd(e,t,n){let r=e.attributes,i=e.index,a=r.position,o=new Map,s=new Map,c=Array.from(t),l=new cd;for(let e=0,t=c.length;e<t;e++){let t=c[e],n=td(t),r=nd(t),o=3*n+r,u=3*n+(r+1)%3;i&&(o=i.getX(o),u=i.getX(u)),ld.fromBufferAttribute(a,o),ud.fromBufferAttribute(a,u),Ju(ld,ud,dd);let d,f=l.findClosestRay(dd);f===null&&(f=dd.clone(),l.addRay(f)),s.has(f)||s.set(f,{forward:[],reverse:[],ray:f}),d=s.get(f);let p=id(f,ld),m=id(f,ud);p>m&&([p,m]=[m,p]),dd.direction.dot(f.direction)<0?d.reverse.push({start:p,end:m,index:t}):d.forward.push({start:p,end:m,index:t})}return s.forEach(({forward:e,reverse:t},r)=>{ad(e,t,o,n),e.length===0&&t.length===0&&s.delete(r)}),{disjointConnectivityMap:o,fragmentMap:s}}var pd=new q,md=new J,hd=new en,gd=[``,``,``],_d=class{constructor(){this.data=null,this.disjointConnections=null,this.unmatchedDisjointEdges=null,this.unmatchedEdges=-1,this.matchedEdges=-1,this.useDrawRange=!0,this.useAllAttributes=!1,this.matchDisjointEdges=!1,this.degenerateEpsilon=1e-8}getSiblingTriangleIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:~~(n/3)}getSiblingEdgeIndex(e,t){let n=this.data[e*3+t];return n===-1?-1:n%3}getDisjointSiblingTriangleIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>~~(e/3)):[]}getDisjointSiblingEdgeIndices(e,t){let n=e*3+t,r=this.disjointConnections.get(n);return r?r.map(e=>e%3):[]}isFullyConnected(){return this.unmatchedEdges===0}updateFrom(e){let{useAllAttributes:t,useDrawRange:n,matchDisjointEdges:r,degenerateEpsilon:i}=this,a=t?v:_,o=new Map,{attributes:s}=e,c=t?Object.keys(s):null,l=e.index,u=s.position,d=Qu(e),f=d,p=0;n&&(p=e.drawRange.start,e.drawRange.count!==1/0&&(d=~~(e.drawRange.count/3)));let m=this.data;(!m||m.length<3*f)&&(m=new Int32Array(3*f)),m.fill(-1);let h=0,g=new Set;for(let e=p,t=d*3+p;e<t;e+=3){let t=e;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),gd[e]=a(n)}for(let e=0;e<3;e++){let n=(e+1)%3,r=gd[e],i=gd[n],a=`${i}_${r}`;if(o.has(a)){let n=t+e,r=o.get(a);m[n]=r,m[r]=n,o.delete(a),h+=2,g.delete(r)}else{let n=`${r}_${i}`,a=t+e;o.set(n,a),g.add(a)}}}if(r){let{fragmentMap:t,disjointConnectivityMap:n}=fd(e,g,i);g.clear(),t.forEach(({forward:e,reverse:t})=>{e.forEach(({index:e})=>g.add(e)),t.forEach(({index:e})=>g.add(e))}),this.unmatchedDisjointEdges=t,this.disjointConnections=n,h=d*3-g.size}this.matchedEdges=h,this.unmatchedEdges=g.size,this.data=m;function _(e){return md.fromBufferAttribute(u,e),Ku(md)}function v(e){let t=``;for(let n=0,r=c.length;n<r;n++){let r=s[c[n]],i;switch(r.itemSize){case 1:i=Wu(r.getX(e));break;case 2:i=Gu(pd.fromBufferAttribute(r,e));break;case 3:i=Ku(md.fromBufferAttribute(r,e));break;case 4:i=qu(hd.fromBufferAttribute(r,e))}t!==``&&(t+=`|`),t+=i}return t}}},vd=class extends ii{constructor(...e){super(...e),this.isBrush=!0,this._previousMatrix=new Y,this._previousMatrix.elements.fill(0),this._halfEdges=null,this._boundsTree=null,this._groupIndices=null,this._hash=null}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){let{matrix:e,_previousMatrix:t}=this,n=e.elements,r=t.elements;for(let e=0;e<16;e++)if(n[e]!==r[e])return!0;return!1}prepareGeometry(){let e=this.geometry,t=e.attributes,n=Yu(),r=e.index,i=e.attributes.position,a=r?`${r.uuid}_${r.count}_${r.version}`:`-1_-1_-1`,o=`${i.uuid}_${i.count}_${i.version}`,s=`${e.uuid}_${a}_${o}`;if(this._hash===s)return;if(this._hash=s,n)for(let e in t){let n=t[e];if(n.isInterleavedBufferAttribute)throw Error(`Brush: InterleavedBufferAttributes are not supported.`);n.array=Xu(n.array)}e.boundsTree=new zu(e,{maxLeafSize:3,indirect:!0,useSharedArrayBuffer:n}),e.halfEdges||=new _d,e.halfEdges.updateFrom(e);let c=Qu(e);(!e.groupIndices||e.groupIndices.length!==c)&&(e.groupIndices=new Uint16Array(c));let l=e.groupIndices,u=e.groups;for(let e=0,t=u.length;e<t;e++){let{start:t,count:n}=u[e];for(let r=t/3,i=(t+n)/3;r<i;r++)l[r]=e}}disposeCacheData(){let{geometry:e}=this;e.halfEdges=null,e.boundsTree=null,e.groupIndices=null}},yd=Object.getOwnPropertyNames,bd=(e,t)=>function(){return t||(0,e[yd(e)[0]])((t={exports:{}}).exports,t),t.exports},xd=bd({"node_modules/binary-search-bounds/search-bounds.js"(e,t){"use strict";function n(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>=0?(a=o,i=o-1):r=o+1}return a}function r(e,t,n,r,i){for(var a=i+1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))>0?(a=o,i=o-1):r=o+1}return a}function i(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<0?(a=o,r=o+1):i=o-1}return a}function a(e,t,n,r,i){for(var a=r-1;r<=i;){var o=r+i>>>1,s=e[o];(n===void 0?s-t:n(s,t))<=0?(a=o,r=o+1):i=o-1}return a}function o(e,t,n,r,i){for(;r<=i;){var a=r+i>>>1,o=e[a],s=n===void 0?o-t:n(o,t);if(s===0)return a;s<=0?r=a+1:i=a-1}return-1}function s(e,t,n,r,i,a){return typeof n==`function`?a(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):a(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}t.exports={ge:function(e,t,r,i,a){return s(e,t,r,i,a,n)},gt:function(e,t,n,i,a){return s(e,t,n,i,a,r)},lt:function(e,t,n,r,a){return s(e,t,n,r,a,i)},le:function(e,t,n,r,i){return s(e,t,n,r,i,a)},eq:function(e,t,n,r,i){return s(e,t,n,r,i,o)}}}}),Sd=bd({"node_modules/two-product/two-product.js"(e,t){"use strict";t.exports=r;var n=+(2**27+1);function r(e,t,r){var i=e*t,a=n*e,o=a-(a-e),s=e-o,c=n*t,l=c-(c-t),u=t-l,d=i-o*l-s*l-o*u,f=s*u-d;return r?(r[0]=f,r[1]=i,r):[f,i]}}}),Cd=bd({"node_modules/robust-sum/robust-sum.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),wd=bd({"node_modules/two-sum/two-sum.js"(e,t){"use strict";t.exports=n;function n(e,t,n){var r=e+t,i=r-e,a=r-i,o=t-i,s=e-a;return n?(n[0]=s+o,n[1]=r,n):[s+o,r]}}}),Td=bd({"node_modules/robust-scale/robust-scale.js"(e,t){"use strict";var n=Sd(),r=wd();t.exports=i;function i(e,t){var i=e.length;if(i===1){var a=n(e[0],t);return a[0]?a:[a[1]]}var o=Array(2*i),s=[.1,.1],c=[.1,.1],l=0;n(e[0],t,s),s[0]&&(o[l++]=s[0]);for(var u=1;u<i;++u){n(e[u],t,c);var d=s[1];r(d,c[0],s),s[0]&&(o[l++]=s[0]);var f=c[1],p=s[1],m=f+p,h=p-(m-f);s[1]=m,h&&(o[l++]=h)}return s[1]&&(o[l++]=s[1]),l===0&&(o[l++]=0),o.length=l,o}}}),Ed=bd({"node_modules/robust-subtract/robust-diff.js"(e,t){"use strict";t.exports=r;function n(e,t){var n=e+t,r=n-e,i=n-r,a=t-r,o=e-i+a;return o?[o,n]:[n]}function r(e,t){var r=e.length|0,i=t.length|0;if(r===1&&i===1)return n(e[0],-t[0]);var a=r+i,o=Array(a),s=0,c=0,l=0,u=Math.abs,d=e[c],f=u(d),p=-t[l],m=u(p),h,g;f<m?(g=d,c+=1,c<r&&(d=e[c],f=u(d))):(g=p,l+=1,l<i&&(p=-t[l],m=u(p))),c<r&&f<m||l>=i?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p)));for(var _=h+g,v=_-h,y=g-v,b=y,x=_,S,C,w,T,E;c<r&&l<i;)f<m?(h=d,c+=1,c<r&&(d=e[c],f=u(d))):(h=p,l+=1,l<i&&(p=-t[l],m=u(p))),g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S;for(;c<r;)h=d,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,c+=1,c<r&&(d=e[c]);for(;l<i;)h=p,g=b,_=h+g,v=_-h,y=g-v,y&&(o[s++]=y),S=x+_,C=S-x,w=S-C,T=_-C,E=x-w,b=E+T,x=S,l+=1,l<i&&(p=-t[l]);return b&&(o[s++]=b),x&&(o[s++]=x),s||(o[s++]=0),o.length=s,o}}}),Dd=bd({"node_modules/robust-orientation/orientation.js"(e,t){"use strict";var n=Sd(),r=Cd(),i=Td(),a=Ed(),o=5,s=11102230246251565e-32,c=(3+16*s)*s,l=(7+56*s)*s;function u(e,t,n,r){return function(n,i,a){var o=r(e(e(t(i[1],a[0]),t(-a[1],i[0])),e(t(n[1],i[0]),t(-i[1],n[0]))),e(t(n[1],a[0]),t(-a[1],n[0])));return o[o.length-1]}}function d(e,t,n,r){return function(i,a,o,s){var c=r(e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2])))),e(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2])))));return c[c.length-1]}}function f(e,t,n,r){return function(i,a,o,s,c){var l=r(e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),a[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),-o[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),s[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),-c[3]),e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-s[2]),n(e(t(a[1],s[0]),t(-s[1],a[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-a[3])))),e(e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),s[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),-c[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),a[2]),e(n(e(t(a[1],s[0]),t(-s[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),s[2]))),i[3]))),e(n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-a[3]),e(n(e(n(e(t(a[1],s[0]),t(-s[1],a[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-s[3]))))),e(e(e(n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),i[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-s[2]),n(e(t(i[1],s[0]),t(-s[1],i[0])),c[2]))),-o[3])),e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),s[3]),n(e(n(e(t(o[1],s[0]),t(-s[1],o[0])),i[2]),e(n(e(t(i[1],s[0]),t(-s[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),s[2]))),-c[3]))),e(e(n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),a[2]),e(n(e(t(a[1],c[0]),t(-c[1],a[0])),-o[2]),n(e(t(a[1],o[0]),t(-o[1],a[0])),c[2]))),i[3]),n(e(n(e(t(o[1],c[0]),t(-c[1],o[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-o[2]),n(e(t(i[1],o[0]),t(-o[1],i[0])),c[2]))),-a[3])),e(n(e(n(e(t(a[1],c[0]),t(-c[1],a[0])),i[2]),e(n(e(t(i[1],c[0]),t(-c[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),c[2]))),o[3]),n(e(n(e(t(a[1],o[0]),t(-o[1],a[0])),i[2]),e(n(e(t(i[1],o[0]),t(-o[1],i[0])),-a[2]),n(e(t(i[1],a[0]),t(-a[1],i[0])),o[2]))),-c[3])))));return l[l.length-1]}}function p(e){return(e===3?u:e===4?d:f)(r,n,i,a)}var m=p(3),h=p(4),g=[function(){return 0},function(){return 0},function(e,t){return t[0]-e[0]},function(e,t,n){var r=(e[1]-n[1])*(t[0]-n[0]),i=(e[0]-n[0])*(t[1]-n[1]),a=r-i,o;if(r>0){if(i<=0)return a;o=r+i}else if(r<0){if(i>=0)return a;o=-(r+i)}else return a;var s=c*o;return a>=s||a<=-s?a:m(e,t,n)},function(e,t,n,r){var i=e[0]-r[0],a=t[0]-r[0],o=n[0]-r[0],s=e[1]-r[1],c=t[1]-r[1],u=n[1]-r[1],d=e[2]-r[2],f=t[2]-r[2],p=n[2]-r[2],m=a*u,g=o*c,_=o*s,v=i*u,y=i*c,b=a*s,x=d*(m-g)+f*(_-v)+p*(y-b),S=l*((Math.abs(m)+Math.abs(g))*Math.abs(d)+(Math.abs(_)+Math.abs(v))*Math.abs(f)+(Math.abs(y)+Math.abs(b))*Math.abs(p));return x>S||-x>S?x:h(e,t,n,r)}];function _(e){var t=g[e.length];return t||=g[e.length]=p(e.length),t.apply(void 0,e)}function v(e,t,n,r,i,a,o){return function(t,n,s,c,l){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,s);case 4:return a(t,n,s,c);case 5:return o(t,n,s,c,l)}for(var u=Array(arguments.length),d=0;d<arguments.length;++d)u[d]=arguments[d];return e(u)}}function y(){for(;g.length<=o;)g.push(p(g.length));t.exports=v.apply(void 0,[_].concat(g));for(var e=0;e<=o;++e)t.exports[e]=g[e]}y()}}),Od=bd({"node_modules/cdt2d/lib/monotone.js"(e,t){"use strict";var n=xd(),r=Dd()[3],i=0,a=1,o=2;t.exports=h;function s(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function c(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function l(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==i&&(n=r(e.a,e.b,t.b),n)?n:e.idx-t.idx}function u(e,t){return r(e.a,e.b,t)}function d(e,t,i,a,o){for(var s=n.lt(t,a,u),c=n.gt(t,a,u),l=s;l<c;++l){for(var d=t[l],f=d.lowerIds,p=f.length;p>1&&r(i[f[p-2]],i[f[p-1]],a)>0;)e.push([f[p-1],f[p-2],o]),--p;f.length=p,f.push(o);for(var m=d.upperIds,p=m.length;p>1&&r(i[m[p-2]],i[m[p-1]],a)<0;)e.push([m[p-2],m[p-1],o]),--p;m.length=p,m.push(o)}}function f(e,t){var n=e.a[0]<t.a[0]?r(e.a,e.b,t.a):r(t.b,t.a,e.a);return n||(n=t.b[0]<e.b[0]?r(e.a,e.b,t.b):r(t.b,t.a,e.b),n||e.idx-t.idx)}function p(e,t,r){var i=n.le(e,r,f),a=e[i],o=a.upperIds,c=o[o.length-1];a.upperIds=[c],e.splice(i+1,0,new s(r.a,r.b,r.idx,[c],o))}function m(e,t,r){var i=r.a;r.a=r.b,r.b=i;var a=n.eq(e,r,f),o=e[a],s=e[a-1];s.upperIds=o.upperIds,e.splice(a,1)}function h(e,t){for(var n=e.length,r=t.length,u=[],f=0;f<n;++f)u.push(new c(e[f],null,i,f));for(var f=0;f<r;++f){var h=t[f],g=e[h[0]],_=e[h[1]];g[0]<_[0]?u.push(new c(g,_,o,f),new c(_,g,a,f)):g[0]>_[0]&&u.push(new c(_,g,o,f),new c(g,_,a,f))}u.sort(l);for(var v=u[0].a[0]-(1+Math.abs(u[0].a[0]))*2**-52,y=[new s([v,1],[v,0],-1,[],[],[],[])],b=[],f=0,x=u.length;f<x;++f){var S=u[f],C=S.type;C===i?d(b,y,e,S.a,S.idx):C===o?p(y,e,S):m(y,e,S)}return b}}}),kd=bd({"node_modules/cdt2d/lib/triangulation.js"(e,t){"use strict";var n=xd();t.exports=o;function r(e,t){this.stars=e,this.edges=t}var i=r.prototype;function a(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}i.isConstraint=(function(){var e=[0,0];function t(e,t){return e[0]-t[0]||e[1]-t[1]}return function(r,i){return e[0]=Math.min(r,i),e[1]=Math.max(r,i),n.eq(this.edges,e,t)>=0}})(),i.removeTriangle=function(e,t,n){var r=this.stars;a(r[e],t,n),a(r[t],n,e),a(r[n],e,t)},i.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)},i.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1},i.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)},i.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2)t.push([i[a],i[a+1]]);return t},i.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],a=0,o=i.length;a<o;a+=2){var s=i[a],c=i[a+1];n<Math.min(s,c)&&t.push([n,s,c])}return t};function o(e,t){for(var n=Array(e),i=0;i<e;++i)n[i]=[];return new r(n,t)}}}),Ad=bd({"node_modules/robust-in-sphere/in-sphere.js"(e,t){"use strict";var n=Sd(),r=Cd(),i=Ed(),a=Td(),o=6;function s(e){return(e===3?d:e===4?f:e===5?p:m)(r,i,n,a)}function c(){return 0}function l(){return 0}function u(){return 0}function d(e,t,n,r){function i(i,a,o){var s=n(i[0],i[0]),c=r(s,a[0]),l=r(s,o[0]),u=n(a[0],a[0]),d=r(u,i[0]),f=r(u,o[0]),p=n(o[0],o[0]),m=r(p,i[0]),h=t(e(t(r(p,a[0]),f),t(d,c)),t(m,l));return h[h.length-1]}return i}function f(e,t,n,r){function i(i,a,o,s){var c=e(n(i[0],i[0]),n(i[1],i[1])),l=r(c,a[0]),u=r(c,o[0]),d=r(c,s[0]),f=e(n(a[0],a[0]),n(a[1],a[1])),p=r(f,i[0]),m=r(f,o[0]),h=r(f,s[0]),g=e(n(o[0],o[0]),n(o[1],o[1])),_=r(g,i[0]),v=r(g,a[0]),y=r(g,s[0]),b=e(n(s[0],s[0]),n(s[1],s[1])),x=r(b,i[0]),S=r(b,a[0]),C=r(b,o[0]),w=t(e(e(r(t(C,y),a[1]),e(r(t(S,h),-o[1]),r(t(v,m),s[1]))),e(r(t(S,h),i[1]),e(r(t(x,d),-a[1]),r(t(p,l),s[1])))),e(e(r(t(C,y),i[1]),e(r(t(x,d),-o[1]),r(t(_,u),s[1]))),e(r(t(v,m),i[1]),e(r(t(_,u),-a[1]),r(t(p,l),o[1])))));return w[w.length-1]}return i}function p(e,t,n,r){function i(i,a,o,s,c){var l=e(n(i[0],i[0]),e(n(i[1],i[1]),n(i[2],i[2]))),u=r(l,a[0]),d=r(l,o[0]),f=r(l,s[0]),p=r(l,c[0]),m=e(n(a[0],a[0]),e(n(a[1],a[1]),n(a[2],a[2]))),h=r(m,i[0]),g=r(m,o[0]),_=r(m,s[0]),v=r(m,c[0]),y=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),b=r(y,i[0]),x=r(y,a[0]),S=r(y,s[0]),C=r(y,c[0]),w=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),T=r(w,i[0]),E=r(w,a[0]),D=r(w,o[0]),O=r(w,c[0]),k=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),A=r(k,i[0]),j=r(k,a[0]),M=r(k,o[0]),N=r(k,s[0]),ee=t(e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),a[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),-o[2]),r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),s[2]))),e(r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),-c[2]),e(r(e(r(t(N,O),a[1]),e(r(t(j,v),-s[1]),r(t(E,_),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-a[2])))),e(e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),s[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),-c[2]),r(e(r(t(D,S),a[1]),e(r(t(E,_),-o[1]),r(t(x,g),s[1]))),i[2]))),e(r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-a[2]),e(r(e(r(t(E,_),i[1]),e(r(t(T,f),-a[1]),r(t(h,u),s[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-s[2]))))),e(e(e(r(e(r(t(N,O),o[1]),e(r(t(M,C),-s[1]),r(t(D,S),c[1]))),i[2]),r(e(r(t(N,O),i[1]),e(r(t(A,p),-s[1]),r(t(T,f),c[1]))),-o[2])),e(r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),s[2]),r(e(r(t(D,S),i[1]),e(r(t(T,f),-o[1]),r(t(b,d),s[1]))),-c[2]))),e(e(r(e(r(t(M,C),a[1]),e(r(t(j,v),-o[1]),r(t(x,g),c[1]))),i[2]),r(e(r(t(M,C),i[1]),e(r(t(A,p),-o[1]),r(t(b,d),c[1]))),-a[2])),e(r(e(r(t(j,v),i[1]),e(r(t(A,p),-a[1]),r(t(h,u),c[1]))),o[2]),r(e(r(t(x,g),i[1]),e(r(t(b,d),-a[1]),r(t(h,u),o[1]))),-c[2])))));return ee[ee.length-1]}return i}function m(e,t,n,r){function i(i,a,o,s,c,l){var u=e(e(n(i[0],i[0]),n(i[1],i[1])),e(n(i[2],i[2]),n(i[3],i[3]))),d=r(u,a[0]),f=r(u,o[0]),p=r(u,s[0]),m=r(u,c[0]),h=r(u,l[0]),g=e(e(n(a[0],a[0]),n(a[1],a[1])),e(n(a[2],a[2]),n(a[3],a[3]))),_=r(g,i[0]),v=r(g,o[0]),y=r(g,s[0]),b=r(g,c[0]),x=r(g,l[0]),S=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),C=r(S,i[0]),w=r(S,a[0]),T=r(S,s[0]),E=r(S,c[0]),D=r(S,l[0]),O=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),k=r(O,i[0]),A=r(O,a[0]),j=r(O,o[0]),M=r(O,c[0]),N=r(O,l[0]),ee=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),P=r(ee,i[0]),F=r(ee,a[0]),I=r(ee,o[0]),L=r(ee,s[0]),R=r(ee,l[0]),te=e(e(n(l[0],l[0]),n(l[1],l[1])),e(n(l[2],l[2]),n(l[3],l[3]))),z=r(te,i[0]),B=r(te,a[0]),V=r(te,o[0]),H=r(te,s[0]),U=r(te,c[0]),ne=t(e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),a[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-s[2])),e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),c[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),s[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),a[2]),r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-l[2]))),i[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-a[3]),r(e(e(r(e(r(t(H,N),a[1]),e(r(t(B,x),-s[1]),r(t(A,y),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-l[2]))),o[3])),e(r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),l[3]))))),e(e(e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),o[2]),r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),-s[2])),e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),c[2]),r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),-l[2]))),i[3]),e(r(e(e(r(e(r(t(U,R),s[1]),e(r(t(H,N),-c[1]),r(t(L,M),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-s[2])),e(r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),c[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-l[2]))),-o[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),s[3]))),e(e(r(e(e(r(e(r(t(H,N),o[1]),e(r(t(V,D),-s[1]),r(t(j,T),l[1]))),i[2]),r(e(r(t(H,N),i[1]),e(r(t(z,h),-s[1]),r(t(k,p),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-l[2]))),-c[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),l[3])),e(r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),a[2]),r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),-o[2])),e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),c[2]),r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),-l[2]))),i[3]),r(e(e(r(e(r(t(U,R),o[1]),e(r(t(V,D),-c[1]),r(t(I,E),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-o[2])),e(r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),c[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-l[2]))),-a[3])))),e(e(e(r(e(e(r(e(r(t(U,R),a[1]),e(r(t(B,x),-c[1]),r(t(F,b),l[1]))),i[2]),r(e(r(t(U,R),i[1]),e(r(t(z,h),-c[1]),r(t(P,m),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),c[2]),r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),-l[2]))),o[3]),r(e(e(r(e(r(t(V,D),a[1]),e(r(t(B,x),-o[1]),r(t(w,v),l[1]))),i[2]),r(e(r(t(V,D),i[1]),e(r(t(z,h),-o[1]),r(t(C,f),l[1]))),-a[2])),e(r(e(r(t(B,x),i[1]),e(r(t(z,h),-a[1]),r(t(_,d),l[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-l[2]))),-c[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),l[3]),r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),a[2]),r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),-o[2])),e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),s[2]),r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),-c[2]))),i[3]))),e(e(r(e(e(r(e(r(t(L,M),o[1]),e(r(t(I,E),-s[1]),r(t(j,T),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-o[2])),e(r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),s[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-c[2]))),-a[3]),r(e(e(r(e(r(t(L,M),a[1]),e(r(t(F,b),-s[1]),r(t(A,y),c[1]))),i[2]),r(e(r(t(L,M),i[1]),e(r(t(P,m),-s[1]),r(t(k,p),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),s[2]),r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),-c[2]))),o[3])),e(r(e(e(r(e(r(t(I,E),a[1]),e(r(t(F,b),-o[1]),r(t(w,v),c[1]))),i[2]),r(e(r(t(I,E),i[1]),e(r(t(P,m),-o[1]),r(t(C,f),c[1]))),-a[2])),e(r(e(r(t(F,b),i[1]),e(r(t(P,m),-a[1]),r(t(_,d),c[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-c[2]))),-s[3]),r(e(e(r(e(r(t(j,T),a[1]),e(r(t(A,y),-o[1]),r(t(w,v),s[1]))),i[2]),r(e(r(t(j,T),i[1]),e(r(t(k,p),-o[1]),r(t(C,f),s[1]))),-a[2])),e(r(e(r(t(A,y),i[1]),e(r(t(k,p),-a[1]),r(t(_,d),s[1]))),o[2]),r(e(r(t(w,v),i[1]),e(r(t(C,f),-a[1]),r(t(_,d),o[1]))),-s[2]))),c[3]))))));return ne[ne.length-1]}return i}var h=[c,l,u];function g(e){var t=h[e.length];return t||=h[e.length]=s(e.length),t.apply(void 0,e)}function _(e,t,n,r,i,a,o,s){function c(t,n,c,l,u,d){switch(arguments.length){case 0:case 1:return 0;case 2:return r(t,n);case 3:return i(t,n,c);case 4:return a(t,n,c,l);case 5:return o(t,n,c,l,u);case 6:return s(t,n,c,l,u,d)}for(var f=Array(arguments.length),p=0;p<arguments.length;++p)f[p]=arguments[p];return e(f)}return c}function v(){for(;h.length<=o;)h.push(s(h.length));t.exports=_.apply(void 0,[g].concat(h));for(var e=0;e<=o;++e)t.exports[e]=h[e]}v()}}),jd=bd({"node_modules/cdt2d/lib/delaunay.js"(e,t){"use strict";var n=Ad()[4];xd(),t.exports=i;function r(e,t,r,i,a,o){var s=t.opposite(i,a);if(!(s<0)){if(a<i){var c=i;i=a,a=c,c=o,o=s,s=c}t.isConstraint(i,a)||n(e[i],e[a],e[o],e[s])<0&&r.push(i,a)}}function i(e,t){for(var i=[],a=e.length,o=t.stars,s=0;s<a;++s)for(var c=o[s],l=1;l<c.length;l+=2){var u=c[l];if(!(u<s)&&!t.isConstraint(s,u)){for(var d=c[l-1],f=-1,p=1;p<c.length;p+=2)if(c[p-1]===u){f=c[p];break}f<0||n(e[s],e[u],e[d],e[f])<0&&i.push(s,u)}}for(;i.length>0;){for(var u=i.pop(),s=i.pop(),d=-1,f=-1,c=o[s],m=1;m<c.length;m+=2){var h=c[m-1],g=c[m];h===u?f=g:g===u&&(d=h)}d<0||f<0||n(e[s],e[u],e[d],e[f])>=0||(t.flip(s,u),r(e,t,i,d,s,f),r(e,t,i,s,f,d),r(e,t,i,f,u,d),r(e,t,i,u,d,f))}}}}),Md=bd({"node_modules/cdt2d/lib/filter.js"(e,t){"use strict";var n=xd();t.exports=c;function r(e,t,n,r,i,a,o){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=a,this.boundary=o}var i=r.prototype;function a(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}i.locate=(function(){var e=[0,0,0];return function(t,r,i){var o=t,s=r,c=i;return r<i?r<t&&(o=r,s=i,c=t):i<t&&(o=i,s=t,c=r),o<0?-1:(e[0]=o,e[1]=s,e[2]=c,n.eq(this.cells,e,a))}})();function o(e,t){for(var n=e.cells(),i=n.length,o=0;o<i;++o){var s=n[o],c=s[0],l=s[1],u=s[2];l<u?l<c&&(s[0]=l,s[1]=u,s[2]=c):u<c&&(s[0]=u,s[1]=c,s[2]=l)}n.sort(a);for(var d=Array(i),o=0;o<d.length;++o)d[o]=0;var f=[],p=[],m=Array(3*i),h=Array(3*i),g=null;t&&(g=[]);for(var _=new r(n,m,h,d,f,p,g),o=0;o<i;++o)for(var s=n[o],v=0;v<3;++v){var c=s[v],l=s[(v+1)%3],y=m[3*o+v]=_.locate(l,c,e.opposite(l,c)),b=h[3*o+v]=e.isConstraint(c,l);y<0&&(b?p.push(o):(f.push(o),d[o]=1),t&&g.push([l,c,-1]))}return _}function s(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function c(e,t,n){var r=o(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,a=r.active,c=r.next,l=r.flags,u=r.cells,d=r.constraint,f=r.neighbor;a.length>0||c.length>0;){for(;a.length>0;){var p=a.pop();if(l[p]!==-i){l[p]=i,u[p];for(var m=0;m<3;++m){var h=f[3*p+m];h>=0&&l[h]===0&&(d[3*p+m]?c.push(h):(a.push(h),l[h]=i))}}}var g=c;c=a,a=g,c.length=0,i=-i}var _=s(u,l,t);return n?_.concat(r.boundary):_}}}),Nd=bd({"node_modules/cdt2d/cdt2d.js"(e,t){var n=Od(),r=kd(),i=jd(),a=Md();t.exports=u;function o(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function s(e,t){return e[0]-t[0]||e[1]-t[1]}function c(e){return e.map(o).sort(s)}function l(e,t,n){return t in e?e[t]:n}function u(e,t,o){Array.isArray(t)?(o||={},t||=[]):(o=t||{},t=[]);var s=!!l(o,`delaunay`,!0),u=!!l(o,`interior`,!0),d=!!l(o,`exterior`,!0),f=!!l(o,`infinity`,!1);if(!u&&!d||e.length===0)return[];var p=n(e,t);if(s||u!==d||f){for(var m=r(e.length,c(t)),h=0;h<p.length;++h){var g=p[h];m.addTriangle(g[0],g[1],g[2])}return s&&i(e,m),d?u?f?a(m,0,f):m.cells():a(m,1,f):a(m,-1)}return p}}})(),Pd=class{constructor(e){this.createFn=e,this._pool=[],this._index=0}getInstance(){return this._index>=this._pool.length&&this._pool.push(this.createFn()),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}},Fd=1e-16,Id=1e-16,Ld=new J,Rd=new J,zd=new Pd(()=>({param:0,index:0})),Bd=new Pd(()=>new J);function Vd(e,t,n,r){zd.clear(),t.length=0,n.length=0;for(let t=0,n=e.length;t<n;t++){let n=e[t];c(n.start),c(n.end)}for(let t=0,n=e.length;t<n;t++){let i=e[t];for(let a=t+1;a<n;a++){let t=e[a];i.distanceSqToLine3(t,Ld,Rd)<Fd*r&&c(Rd)}}let i=[];for(let a=0,o=e.length;a<o;a++){i.length=0;let o=e[a];for(let e=0,n=t.length;e<n;e++){let n=t[e],a=o.closestPointToPointParameter(n,!0);if(o.at(a,Ld),n.distanceToSquared(Ld)<Fd*r){let t=zd.getInstance();t.param=a,t.index=e,i.push(t)}}i.sort(s);for(let e=0,t=i.length-1;e<t;e++){let t=i[e].index,r=i[e+1].index;t!==r&&n.push([t,r])}}let a=new Set,o=0;for(let e=0,t=n.length;e<t;e++){let t=n[e],r=Math.min(t[0],t[1]),i=Math.max(t[0],t[1]),s=r+`,`+i;a.has(s)||(a.add(s),n[o++]=t)}n.length=o;function s(e,t){return e.param-t.param}function c(e){for(let n=0;n<t.length;n++){let i=t[n];if(e===i||e.distanceToSquared(i)<Id*r)return n}return t.push(Bd.getInstance().copy(e)),t.length-1}}var Hd=class{constructor(){this.trianglePool=new Pd(()=>new pl),this.linePool=new Pd(()=>new bs),this.triangles=[],this.triangleIndices=[],this.constrainedEdges=[],this.triangleConnectivity=[],this.normal=new J,this.projOrigin=new J,this.projU=new J,this.projV=new J,this.baseTri=new pl,this.baseIndices=[,,,]}initialize(e,t=null,n=null,r=null){this.reset();let{normal:i,baseTri:a,projU:o,projV:s,projOrigin:c,constrainedEdges:l,linePool:u,baseIndices:d}=this;e.getNormal(i),a.copy(e),a.update(),d[0]=t,d[1]=n,d[2]=r,l.length=0;let f=u.getInstance();f.start.copy(a.a),f.end.copy(a.b);let p=u.getInstance();p.start.copy(a.b),p.end.copy(a.c);let m=u.getInstance();m.start.copy(a.c),m.end.copy(a.a),l.push(f,p,m),c.copy(a.a),o.subVectors(a.b,a.a).normalize(),s.crossVectors(i,o).normalize()}addConstraintEdge(e){let{constrainedEdges:t,linePool:n}=this,r=n.getInstance().copy(e);t.push(r)}_to2D(e,t){let{projOrigin:n,projU:r,projV:i}=this;return Ld.subVectors(e,n),t.set(Ld.dot(r),Ld.dot(i),0)}_from2D(e,t,n){let{projOrigin:r,projU:i,projV:a}=this;return n.copy(r).addScaledVector(i,e).addScaledVector(a,t),n}triangulate(){let{triangles:e,trianglePool:t,triangleConnectivity:n,triangleIndices:r,linePool:i,baseTri:a,constrainedEdges:o,baseIndices:s}=this;e.length=0,t.clear();let c=[];for(let e=0,t=o.length;e<t;e++){let t=o[e],n=i.getInstance();this._to2D(t.start,n.start),this._to2D(t.end,n.end),c.push(n)}let l=0;for(let e=0;e<3;e++){let t=this._to2D(a.points[e],Ld);l=Math.max(l,Math.abs(t.x),Math.abs(t.y))}let u=[],d=[];Vd(c,u,d,l);let f=[];for(let e=0,t=u.length;e<t;e++){let t=u[e];f.push([t.x,t.y])}let p=Nd(f,d,{exterior:!1}),m=new Map;for(let e=0,t=d.length;e<t;e++){let t=d[e];m.set(`${t[0]}_${t[1]}`,-1),m.set(`${t[1]}_${t[0]}`,-1)}let h=`${s[0]}_${s[1]}_${s[2]}_`;for(let i=0,a=p.length;i<a;i++){let a=p[i],[o,c,l]=a,u=t.getInstance();this._from2D(f[o][0],f[o][1],u.a),this._from2D(f[c][0],f[c][1],u.b),this._from2D(f[l][0],f[l][1],u.c),e.push(u);let d=[];n.push(d);let g=[];r.push(g);for(let e=0;e<3;e++){let t=a[e];g.push(t<3?s[t]:h+t);let r=a[(e+1)%3],o=`${t}_${r}`;if(m.has(o)){let e=m.get(o);e!==-1&&(d.push(e),n[e].push(i))}else{let e=`${r}_${t}`;m.set(e,i)}}}}reset(){this.trianglePool.clear(),this.linePool.clear(),this.triangles.length=0,this.triangleIndices.length=0,this.triangleConnectivity.length=0,this.constrainedEdges.length=0}},Ud=1e-14,Wd=new J,Gd=new J,Kd=new J;function qd(e,t=Ud){Wd.subVectors(e.b,e.a),Gd.subVectors(e.c,e.a),Kd.subVectors(e.b,e.c);let n=Wd.angleTo(Gd),r=Wd.angleTo(Kd),i=Math.PI-n-r;return Math.abs(n)<t||Math.abs(r)<t||Math.abs(i)<t||e.a.distanceToSquared(e.b)<t||e.a.distanceToSquared(e.c)<t||e.b.distanceToSquared(e.c)<t}var Jd=1e-10,Yd=1e-10,Xd=new bs,Zd=new bs,Qd=new J,$d=new J,ef=new J,tf=new di,nf=new pl,rf=class{constructor(){this.trianglePool=new Pd(()=>new nr),this.triangles=[],this.normal=new J}initialize(e){this.reset();let{triangles:t,trianglePool:n,normal:r}=this;if(Array.isArray(e))for(let i=0,a=e.length;i<a;i++){let a=e[i];if(i===0)a.getNormal(r);else if(Math.abs(1-a.getNormal(Qd).dot(r))>Jd)throw Error(`Triangle Splitter: Cannot initialize with triangles that have different normals.`);let o=n.getInstance();o.copy(a),t.push(o)}else{e.getNormal(r);let i=n.getInstance();i.copy(e),t.push(i)}}splitByTriangle(e,t){let{triangles:n}=this;if(t){for(let e=0,t=n.length;e<t;e++){let t=n[e];t.coplanarCount=0}let t=[e.a,e.b,e.c];for(let n=0;n<3;n++){let r=(n+1)%3,i=t[n],a=t[r];e.getNormal($d).normalize(),Qd.subVectors(a,i).normalize(),ef.crossVectors($d,Qd),tf.setFromNormalAndCoplanarPoint(ef,i),this.splitByPlane(tf,e)}}else e.getPlane(tf),this.splitByPlane(tf,e)}splitByPlane(e,t){let{triangles:n,trianglePool:r}=this;nf.copy(t),nf.needsUpdate=!0;for(let t=0,i=n.length;t<i;t++){let a=n[t];if(!nf.intersectsTriangle(a,Xd,!0))continue;let{a:o,b:s,c}=a,l=0,u=-1,d=!1,f=[],p=[],m=[o,s,c];for(let t=0;t<3;t++){let n=(t+1)%3;Xd.start.copy(m[t]),Xd.end.copy(m[n]);let r=e.distanceToPoint(Xd.start),i=e.distanceToPoint(Xd.end);if(Math.abs(r)<Yd&&Math.abs(i)<Yd){d=!0;break}if(r>0?f.push(t):p.push(t),Math.abs(r)<Yd)continue;let a=!!e.intersectLine(Xd,Qd);!a&&Math.abs(i)<Yd&&(Qd.copy(Xd.end),a=!0),a&&!(Qd.distanceTo(Xd.start)<Jd)&&(Qd.distanceTo(Xd.end)<Jd&&(u=t),l===0?Zd.start.copy(Qd):Zd.end.copy(Qd),l++)}if(!d&&l===2&&Zd.distance()>Yd){if(u!==-1){u=(u+1)%3;let e=0;e===u&&(e=(e+1)%3);let o=e+1;o===u&&(o=(o+1)%3);let s=r.getInstance();s.a.copy(m[o]),s.b.copy(Zd.end),s.c.copy(Zd.start),qd(s)||n.push(s),a.a.copy(m[e]),a.b.copy(Zd.start),a.c.copy(Zd.end),qd(a)&&(n.splice(t,1),t--,i--)}else{let e=f.length>=2?p[0]:f[0];if(e===0){let e=Zd.start;Zd.start=Zd.end,Zd.end=e}let o=(e+1)%3,s=(e+2)%3,c=r.getInstance(),l=r.getInstance();m[o].distanceToSquared(Zd.start)<m[s].distanceToSquared(Zd.end)?(c.a.copy(m[o]),c.b.copy(Zd.start),c.c.copy(Zd.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Zd.start)):(c.a.copy(m[s]),c.b.copy(Zd.start),c.c.copy(Zd.end),l.a.copy(m[o]),l.b.copy(m[s]),l.c.copy(Zd.end)),a.a.copy(m[e]),a.b.copy(Zd.end),a.c.copy(Zd.start),qd(c)||n.push(c),qd(l)||n.push(l),qd(a)&&(n.splice(t,1),t--,i--)}}else l===3&&console.warn(`TriangleClipper: Coplanar clip not handled`)}}reset(){this.triangles.length=0,this.trianglePool.clear()}},af=class{constructor(){this.coplanarSet=new Map,this.intersectionSet=new Map,this.edgeSet=new Map,this.ids=[]}add(e,t,n=!1){let{intersectionSet:r,coplanarSet:i,ids:a}=this;r.has(e)||(r.set(e,[]),a.push(e)),r.get(e).push(t),n&&(i.has(e)||i.set(e,new Set),i.get(e).add(t))}addIntersectionEdge(e,t){let{edgeSet:n}=this;n.has(e)||n.set(e,new Set),n.get(e).add(t)}getIntersectionEdges(e){return this.edgeSet.get(e)||null}},of=1e-10,sf=1e-15,cf=1e-10,lf=1e-10,uf=new bs,df=new bs,ff=new J,pf=new J,mf=new J,hf=new di,gf=new J,_f=new J;function vf(e,t){e.getNormal(gf),t.getNormal(_f);let n=gf.dot(_f);if(Math.abs(1-Math.abs(n))>=cf)return!1;let r=gf.dot(e.a),i=gf.dot(t.a);return Math.abs(r-i)<lf}function yf(e,t,n,r){let i=0,a=1;e.delta(ff);let o=[t.a,t.b,t.c];for(let t=0;t<3;t++){let r=o[t],s=o[(t+1)%3];pf.subVectors(s,r),mf.crossVectors(n,pf),hf.setFromNormalAndCoplanarPoint(mf,r);let c=hf.distanceToPoint(e.start),l=hf.normal.dot(ff);if(Math.abs(l)<sf){if(c<-1e-10)return null;continue}let u=-c/l;if(l>0?i=Math.max(i,u):a=Math.min(a,u),i>a+of)return null}return a-i<of?null:(e.at(i,r.start),e.at(a,r.end),r)}function bf(e,t,n){let r=0;e.getNormal(gf),t.getNormal(_f);let i=[t.a,t.b,t.c];for(let t=0;t<3;t++){df.start.copy(i[t]),df.end.copy(i[(t+1)%3]);let a=yf(df,e,gf,uf);a!==null&&(r>=n.length&&n.push(new bs),n[r].copy(a),r++)}let a=[e.a,e.b,e.c];for(let e=0;e<3;e++){df.start.copy(a[e]),df.end.copy(a[(e+1)%3]);let i=yf(df,t,_f,uf);i!==null&&(r>=n.length&&n.push(new bs),n[r].copy(i),r++)}return r}var xf=new Gr,Sf=new Y,Cf=new bs,wf=[],Tf=new Pd(()=>new bs),Ef=null;function Df(e){Ef=e}function Of(e,t,n=null){e.getMidpoint(xf.origin),e.getNormal(xf.direction),n&&(xf.origin.applyMatrix4(n),xf.direction.transformDirection(n));let r=t.raycastFirst(xf,2);return r&&xf.direction.dot(r.face.normal)>0?-1:1}function kf(e,t){let n=new af,r=new af;return Tf.clear(),Sf.copy(e.matrixWorld).invert().multiply(t.matrixWorld),e.geometry.boundsTree.bvhcast(t.geometry.boundsTree,Sf,{intersectsTriangles(i,a,o,s){if(!qd(i)&&!qd(a)){let c=(vf(i,a)?bf(i,a,wf):0)>2;if(c||i.intersectsTriangle(a,Cf,!0)){let l=e.geometry.boundsTree.resolveTriangleIndex(o),u=t.geometry.boundsTree.resolveTriangleIndex(s);if(n.add(l,u,c),r.add(u,l,c),c){let e=bf(i,a,wf);for(let t=0;t<e;t++){let e=Tf.getInstance().copy(wf[t]);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,e)}}else{let e=Tf.getInstance().copy(Cf),t=Tf.getInstance().copy(Cf);n.addIntersectionEdge(l,e),r.addIntersectionEdge(u,t)}Ef&&(Ef.addEdge(Cf),Ef.addIntersectingTriangles(o,i,s,a))}}return!1}}),{aIntersections:n,bIntersections:r}}function Af(e,t,n=!1){switch(e){case 0:if(t===1||t===2&&!n)return 1;break;case 1:if(n){if(t===-1)return 0}else if(t===1||t===-2)return 1;break;case 2:if(n){if(t===1||t===-2)return 1}else if(t===-1)return 0;break;case 4:if(t===-1)return 0;if(t===1)return 1;break;case 3:if(t===-1||t===2&&!n)return 1;break;case 5:if(!n&&(t===1||t===-2))return 1;break;case 6:if(!n&&(t===-1||t===2))return 1;break;default:throw Error(`Unrecognized CSG operation enum "${e}".`)}return 2}var jf=class{constructor(e){this.triangle=new nr().copy(e),this.intersects={}}addTriangle(e,t){this.intersects[e]=new nr().copy(t)}getIntersectArray(){let e=[],{intersects:t}=this;for(let n in t)e.push(t[n]);return e}},Mf=class{constructor(){this.data={}}addTriangleIntersection(e,t,n,r){let{data:i}=this;i[e]||(i[e]=new jf(t)),i[e].addTriangle(n,r)}getTrianglesAsArray(e=null){let{data:t}=this,n=[];if(e!==null)e in t&&n.push(t[e].triangle);else for(let e in t)n.push(t[e].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(e=>parseInt(e))}getIntersectionIndices(e){let{data:t}=this;return t[e]?Object.keys(t[e].intersects).map(e=>parseInt(e)):[]}getIntersectionsAsArray(e=null,t=null){let{data:n}=this,r=new Set,i=[],a=e=>{if(n[e]){if(t!==null)n[e].intersects[t]&&i.push(n[e].intersects[t]);else{let t=n[e].intersects;for(let e in t)r.has(e)||(r.add(e),i.push(t[e]))}}};if(e!==null)a(e);else for(let e in n)a(e);return i}reset(){this.data={}}},Nf=class{constructor(){this.enabled=!1,this.triangleIntersectsA=new Mf,this.triangleIntersectsB=new Mf,this.intersectionEdges=[]}addIntersectingTriangles(e,t,n,r){let{triangleIntersectsA:i,triangleIntersectsB:a}=this;i.addTriangleIntersection(e,t,n,r),a.addTriangleIntersection(n,r,e,t)}addEdge(e){this.intersectionEdges.push(e.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),Df(this))}complete(){this.enabled&&Df(null)}},Pf=new Y,Ff=new Y,If=new Y,Lf=new Rt,Rf=new nr,zf=new nr,Bf=new nr,Vf=new nr,Hf=[],Uf=[],Wf=new Set,Gf=new J,Kf=new J,qf=new Pd(()=>new nr),Jf=new J,Yf=[];function Xf(e,t,n,r,i,a={}){let{useGroups:o=!0}=a,{aIntersections:s,bIntersections:c}=kf(e,t),l=[],u;return u=o?0:-1,Qf(e,t,s,n,!1,i,u),Zf(e,t,s,n,!1,r,i,u),n.findIndex(e=>e!==6&&e!==5)!==-1&&(i.forEach(e=>e.clearIndexMap()),u=o?e.geometry.groups.length||1:-1,Qf(t,e,c,n,!0,i,u),Zf(t,e,c,n,!0,r,i,u)),i.forEach(e=>e.clearIndexMap()),Hf.length=0,{groups:l,materials:null}}function Zf(e,t,n,r,i,a,o,s=0){Pf.copy(t.matrixWorld).invert().multiply(e.matrixWorld),Ff.copy(Pf).invert(),i?If.copy(Pf):If.identity();let c=If.determinant()<0;Lf.getNormalMatrix(If).multiplyScalar(c?-1:1);let l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=t.geometry.boundsTree,p=t.geometry.index,m=t.geometry.attributes.position,h=n.ids;for(let t=0,g=h.length;t<g;t++){let g=h[t],_=s===-1?0:l[g]+s,v=3*g,y=v+0,b=v+1,x=v+2;u&&(y=u.getX(y),b=u.getX(b),x=u.getX(x)),Rf.a.fromBufferAttribute(d,y),Rf.b.fromBufferAttribute(d,b),Rf.c.fromBufferAttribute(d,x),i&&(Rf.a.applyMatrix4(Pf),Rf.b.applyMatrix4(Pf),Rf.c.applyMatrix4(Pf)),a.reset(),a.initialize(Rf,y,b,x),Yf.length=0,qf.clear(),Rf.getNormal(Kf);let S=n.coplanarSet.get(g);if(S)for(let e of S){let t=3*e,n=t+0,r=t+1,a=t+2;p&&(n=p.getX(n),r=p.getX(r),a=p.getX(a));let o=qf.getInstance();o.a.fromBufferAttribute(m,n),o.b.fromBufferAttribute(m,r),o.c.fromBufferAttribute(m,a),i||(o.a.applyMatrix4(Ff),o.b.applyMatrix4(Ff),o.c.applyMatrix4(Ff)),Yf.push(o)}if(a.addConstraintEdge){let e=n.getIntersectionEdges(g);if(e)for(let t of e)a.addConstraintEdge(t);a.triangulate()}else{let e=n.intersectionSet.get(g);for(let t=0,n=e.length;t<n;t++){let n=e[t],r=S&&S.has(n),o=3*n,s=o+0,c=o+1,l=o+2;p&&(s=p.getX(s),c=p.getX(c),l=p.getX(l)),zf.a.fromBufferAttribute(m,s),zf.b.fromBufferAttribute(m,c),zf.c.fromBufferAttribute(m,l),i||(zf.a.applyMatrix4(Ff),zf.b.applyMatrix4(Ff),zf.c.applyMatrix4(Ff)),a.splitByTriangle(zf,r)}}let{triangles:C,triangleIndices:w=[],triangleConnectivity:T=[]}=a;for(let t=0,n=o.length;t<n;t++)o[t].initInterpolatedAttributeData(e.geometry,If,Lf,y,b,x);Wf.clear();for(let e=0,t=C.length;e<t;e++){if(Wf.has(e))continue;let t=C[e],n=i?null:Pf,a=null;t.getMidpoint(Gf);for(let e=0,t=Yf.length;e<t;e++){let t=Yf[e];if(t.containsPoint(Gf)){t.getNormal(Jf),a=Kf.dot(Jf)>0?2:-2;break}}a===null&&(a=Of(t,f,n)),Hf.length=0,Uf.length=0;for(let e=0,t=r.length;e<t;e++){let t=Af(r[e],a,i);t!==2&&(Hf.push(t),Uf.push(o[e]))}if(Uf.length!==0){let t=[e];for(;t.length>0;){let e=t.pop();if(Wf.has(e))continue;Wf.add(e);let n=w[e],r=null,i=null,a=null;n&&(r=n[0],i=n[1],a=n[2]);let o=C[e];Rf.getBarycoord(o.a,Vf.a),Rf.getBarycoord(o.b,Vf.b),Rf.getBarycoord(o.c,Vf.c);for(let e=0,t=Uf.length;e<t;e++){let t=Uf[e],n=c!==(Hf[e]===0);t.appendInterpolatedAttributeData(_,Vf.a,r,n),n?(t.appendInterpolatedAttributeData(_,Vf.c,a,n),t.appendInterpolatedAttributeData(_,Vf.b,i,n)):(t.appendInterpolatedAttributeData(_,Vf.b,i,n),t.appendInterpolatedAttributeData(_,Vf.c,a,n))}}}}}return h.length}function Qf(e,t,n,r,i,a,o=0){Pf.copy(t.matrixWorld).invert().multiply(e.matrixWorld),i?If.copy(Pf):If.identity();let s=If.determinant()<0;Lf.getNormalMatrix(If).multiplyScalar(s?-1:1);let c=t.geometry.boundsTree,l=e.geometry.groupIndices,u=e.geometry.index,d=e.geometry.attributes.position,f=[],p=e.geometry.halfEdges,m=new Set(n.ids),h=Qu(e.geometry);for(let t=0;t<h&&m.size!==h;t++){if(m.has(t))continue;m.add(t),f.push(t);let n=3*t,h=n+0,g=n+1,_=n+2;u&&(h=u.getX(h),g=u.getX(g),_=u.getX(_)),Bf.a.fromBufferAttribute(d,h),Bf.b.fromBufferAttribute(d,g),Bf.c.fromBufferAttribute(d,_),i&&(Bf.a.applyMatrix4(Pf),Bf.b.applyMatrix4(Pf),Bf.c.applyMatrix4(Pf));let v=Of(Bf,c,i?null:Pf);Hf.length=0,Uf.length=0;for(let e=0,t=r.length;e<t;e++){let t=Af(r[e],v,i);t!==2&&(Hf.push(t),Uf.push(a[e]))}for(;f.length>0;){let t=f.pop();for(let e=0;e<3;e++){let n=p.getSiblingTriangleIndex(t,e);n!==-1&&!m.has(n)&&(f.push(n),m.add(n))}if(Uf.length!==0){let n=3*t,r=n+0,i=n+1,a=n+2;u&&(r=u.getX(r),i=u.getX(i),a=u.getX(a));let c=o===-1?0:l[t]+o;if(Bf.a.fromBufferAttribute(d,r),Bf.b.fromBufferAttribute(d,i),Bf.c.fromBufferAttribute(d,a),!qd(Bf))for(let t=0,n=Uf.length;t<n;t++){let n=Uf[t],o=Hf[t]===0!==s;n.appendIndexFromGeometry(e.geometry,If,Lf,c,r,o),o?(n.appendIndexFromGeometry(e.geometry,If,Lf,c,a,o),n.appendIndexFromGeometry(e.geometry,If,Lf,c,i,o)):(n.appendIndexFromGeometry(e.geometry,If,Lf,c,i,o),n.appendIndexFromGeometry(e.geometry,If,Lf,c,a,o))}}}}}function $f(e){return e=~~e,e+4-e%4}var ep=class{constructor(e,t=500){this.expansionFactor=1.5,this.type=e,this.length=0,this.array=null,this.setSize(t)}setType(e){if(e===this.type)return;if(this.length!==0)throw Error(`TypeBackedArray: Cannot change the type while there is used data in the buffer.`);let t=this.array.buffer;this.array=new e(t),this.type=e}setSize(e){if(this.array&&e===this.array.length)return;let t=this.type,n=new t(new(Yu()?SharedArrayBuffer:ArrayBuffer)($f(e*t.BYTES_PER_ELEMENT)));this.array&&n.set(this.array,0),this.array=n}expand(){let{array:e,expansionFactor:t}=this;this.setSize(e.length*t)}push(...e){let{array:t,length:n}=this;n+e.length>t.length&&(this.expand(),t=this.array);for(let r=0,i=e.length;r<i;r++)t[n+r]=e[r];this.length+=e.length}clear(){this.length=0}},tp=new J,np=new J,rp=new J,ip=new J,ap=new en,op=new en,sp=new en,cp=new en;function lp(e,t,n,r,i,a=!1,o=!1){return i.set(0,0,0,0).addScaledVector(e,r.x).addScaledVector(t,r.y).addScaledVector(n,r.z),a&&i.normalize(),o&&i.multiplyScalar(-1),i}function up(e,t,n){switch(t){case 1:n.push(e.x);break;case 2:n.push(e.x,e.y);break;case 3:n.push(e.x,e.y,e.z);break;case 4:n.push(e.x,e.y,e.z,e.w)}}var dp=class extends ep{get count(){return this.length/this.itemSize}constructor(...e){super(...e),this.itemSize=1,this.normalized=!1}},fp=class{constructor(){this.attributeData={},this.groupIndices=[],this.forwardIndexMap=new Map,this.invertedIndexMap=new Map,this.interpolatedFields={}}initFromGeometry(e,t){this.clear();let{attributeData:n}=this,r=e.attributes;for(let e=0,i=t.length;e<i;e++){let i=t[e],a=r[i],o=a.array.constructor;n[i]||(n[i]=new dp(o)),n[i].setType(o),n[i].itemSize=a.itemSize,n[i].normalized=a.normalized}for(let e in n.attributes)t.includes(e)||n.delete(e)}initInterpolatedAttributeData(e,t,n,r,i,a){let{attributeData:o,interpolatedFields:s}=this,{attributes:c}=e;for(let e in o){let o=c[e];if(!o)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l,u,d;if(e===`position`?(l=np.fromBufferAttribute(o,r).applyMatrix4(t),u=rp.fromBufferAttribute(o,i).applyMatrix4(t),d=ip.fromBufferAttribute(o,a).applyMatrix4(t)):e===`normal`?(l=np.fromBufferAttribute(o,r).applyNormalMatrix(n),u=rp.fromBufferAttribute(o,i).applyNormalMatrix(n),d=ip.fromBufferAttribute(o,a).applyNormalMatrix(n)):e===`tangent`?(l=np.fromBufferAttribute(o,r).transformDirection(t),u=rp.fromBufferAttribute(o,i).transformDirection(t),d=ip.fromBufferAttribute(o,a).transformDirection(t)):(l=op.fromBufferAttribute(o,r),u=sp.fromBufferAttribute(o,i),d=cp.fromBufferAttribute(o,a)),!s[e])s[e]=[l.clone(),u.clone(),d.clone()];else{let t=s[e];t[0].copy(l),t[1].copy(u),t[2].copy(d)}}}appendInterpolatedAttributeData(e,t,n=null,r=!1){let{groupIndices:i,attributeData:a,interpolatedFields:o,forwardIndexMap:s,invertedIndexMap:c}=this;for(;i.length<=e;)i.push(new dp(Uint32Array));let l=r?c:s,u=i[e];if(n!==null&&l.has(n))u.push(l.get(n));else{l.set(n,a.position.count),u.push(a.position.count);for(let e in o){let n=a[e],i=e===`normal`||e===`tangent`,s=r&&i,c=n.itemSize,[l,u,d]=o[e];lp(l,u,d,t,ap,i,s),up(ap,c,n)}}}appendIndexFromGeometry(e,t,n,r,i,a=!1){let{groupIndices:o,attributeData:s,forwardIndexMap:c,invertedIndexMap:l}=this;for(;o.length<=r;)o.push(new dp(Uint32Array));let u=a?l:c,d=o[r];if(i!==null&&u.has(i))d.push(u.get(i));else{u.set(i,s.position.count),d.push(s.position.count);let{attributes:r}=e;for(let e in s){let o=s[e],c=r[e];if(!c)throw Error(`CSG Operations: Attribute ${e} not available on geometry.`);let l=c.itemSize;e===`position`?(tp.fromBufferAttribute(c,i).applyMatrix4(t),o.push(tp.x,tp.y,tp.z)):e===`normal`?(tp.fromBufferAttribute(c,i).applyNormalMatrix(n),a&&tp.multiplyScalar(-1),o.push(tp.x,tp.y,tp.z)):e===`tangent`?(tp.fromBufferAttribute(c,i).transformDirection(t),a&&tp.multiplyScalar(-1),o.push(tp.x,tp.y,tp.z)):(ap.fromBufferAttribute(c,i),up(ap,l,o))}}}buildGeometry(e,t){let n=!1,{groupIndices:r,attributeData:i}=this,{attributes:a,index:o}=e;for(let t in i){let r=i[t],{type:o,itemSize:s,normalized:c,length:l,count:u}=r,d=r.array.buffer,f=a[t];(!f||f.count<u||f.array.type!==o)&&(f=new xr(new o(l),s,c),e.setAttribute(t,f),n=!0),f.array.set(new o(d,0,l),0),f.needsUpdate=!0}let s=r.reduce((e,t)=>t.count+e,0);(!e.index||o.count<s||o.array.type!==Uint32Array)&&(e.setIndex(new xr(new Uint32Array(s),1)),n=!0),e.clearGroups();let c=0;for(let n=0,i=Math.min(t.length,r.length);n<i;n++){let{index:i,materialIndex:a}=t[n],{count:o}=r[i],s=r[i].array.buffer;o!==0&&(e.index.array.set(new Uint32Array(s,0,o),c),e.addGroup(c,o,a),c+=o)}e.setDrawRange(0,c),e.boundsTree=null,e.boundingBox=null,e.boundingSphere=null,n&&e.dispose()}clearIndexMap(){this.forwardIndexMap.clear(),this.invertedIndexMap.clear()}clear(){let{groupIndices:e,attributeData:t}=this;this.interpolatedFields={};for(let e in t)t[e].clear();e.forEach(e=>{e.clear()}),this.clearIndexMap()}};function pp(e,t){for(let n in e.attributes)t.includes(n)||(e.deleteAttribute(n),e.dispose());return e}function mp(e,t){let n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=t[i.materialIndex];n.push({...i,materialIndex:t.indexOf(a)})}return n}function hp(e,t){let n=[],r=new Map;for(let i=0,a=e.length;i<a;i++){let a=e[i];r.has(a.materialIndex)||(r.set(a.materialIndex,n.length),n.push(t[a.materialIndex])),a.materialIndex=r.get(a.materialIndex)}return n}function gp(e){for(let t=0;t<e.length-1;t++){let n=e[t],r=e[t+1];if(n.materialIndex===r.materialIndex){let i=n.start,a=r.start+r.count;r.start=i,r.count=a-i,e.splice(t,1),t--}}}function _p(e,t){let n=t;return Array.isArray(t)||(n=[],e.forEach(e=>{n[e.materialIndex]=t})),n}var vp=class{get useCDTClipping(){return this.triangleSplitter instanceof Hd}set useCDTClipping(e){e!==this.useCDTClipping&&(this.triangleSplitter=e?new Hd:new rf)}constructor(){this.triangleSplitter=new rf,this.geometryBuilders=[],this.attributes=[`position`,`uv`,`normal`],this.useGroups=!0,this.consolidateGroups=!0,this.removeUnusedMaterials=!0,this.debug=new Nf}getGroupRanges(e){return!this.useGroups||e.groups.length===0?[{start:0,count:1/0,materialIndex:0}]:e.groups.map(e=>({...e}))}evaluate(e,t,n,r=new vd){let i=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(r)||(r=[r],i=!1),r.length!==n.length)throw Error(`Evaluator: operations and target array passed as different sizes.`);e.prepareGeometry(),t.prepareGeometry();let{triangleSplitter:a,geometryBuilders:o,attributes:s,useGroups:c,consolidateGroups:l,removeUnusedMaterials:u,debug:d}=this;for(;o.length<r.length;)o.push(new fp);r.forEach((t,n)=>{o[n].initFromGeometry(e.geometry,s),pp(t.geometry,s)}),d.init(),Xf(e,t,n,a,o,{useGroups:c}),d.complete();let f=this.getGroupRanges(e.geometry),p=_p(f,e.material),m=this.getGroupRanges(t.geometry),h=_p(m,t.material);m.forEach(e=>e.materialIndex+=p.length);let g=[...p,...h],_=[...f,...m].map((e,t)=>({...e,index:t}));return c?c&&l&&(_=mp(_,g),_.sort((e,t)=>e.materialIndex-t.materialIndex)):_=[{start:0,count:1/0,index:0,materialIndex:0}],r.forEach((t,n)=>{let r=t.geometry;o[n].buildGeometry(r,_),e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrix(),t.matrixWorld.copy(e.matrixWorld),c?(t.material=g,l&&gp(r.groups),u&&(t.material=hp(r.groups,g))):t.material=g[0]}),i?r:r[0]}evaluateHierarchy(e,t=new vd){e.updateMatrixWorld(!0);let n=(e,t)=>{let r=e.children;for(let e=0,i=r.length;e<i;e++){let i=r[e];i.isOperationGroup?n(i,t):t(i)}},r=e=>{let t=e.children,i=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];i=r(n)||i}let a=e.isDirty();if(a&&e.markUpdated(),i&&!e.isOperationGroup){let t;return n(e,n=>{t=t?this.evaluate(t,n,n.operation):this.evaluate(e,n,n.operation)}),e._cachedGeometry=t.geometry,e._cachedMaterials=t.material,!0}return i||a};return r(e),t.geometry=e._cachedGeometry,t.material=e._cachedMaterials,t}reset(){this.triangleSplitter.reset()}},yp=class{scopes=[];constructor(){this.pushScope();for(let[e,t]of Object.entries({pi:Math.PI,tau:2*Math.PI,true:!0,false:!1}))this.set(e,t)}pushScope(){this.scopes.push(new Map)}popScope(){this.scopes.length>1&&this.scopes.pop()}set(e,t){let n=this.scopes[this.scopes.length-1];if(n===void 0)throw Error(`SymbolTable has no active scope`);n.set(e,t)}get(e){for(let t=this.scopes.length-1;t>=0;t--){let n=this.scopes[t];if(n?.has(e))return n.get(e)}}has(e){return this.get(e)!==void 0}};function bp(e){let t=0;for(let n of Cp(e)){let e=$(n);t+=e*e}return Math.sqrt(t)}var xp={x:0,y:1,z:2,w:3,r:0,g:1,b:2,a:3,red:0,green:1,blue:2,alpha:3},Sp={round:e=>Math.round($(e)),floor:e=>Math.floor($(e)),ceil:e=>Math.ceil($(e)),abs:e=>Math.abs($(e)),sign:e=>Math.sign($(e)),sqrt:e=>Math.sqrt($(e)),pow:(e,t)=>$(e)**+$(t),min:(...e)=>Math.min(...e.flat().map($)),max:(...e)=>Math.max(...e.flat().map($)),sin:e=>Math.sin($(e)),cos:e=>Math.cos($(e)),tan:e=>Math.tan($(e)),asin:e=>Math.asin($(e)),acos:e=>Math.acos($(e)),atan:e=>Math.atan($(e)),atan2:(e,t)=>Math.atan2($(e),$(t)),dot:(e,t)=>{let n=Cp(e),r=Cp(t),i=0;for(let e=0;e<Math.min(n.length,r.length);e++)i+=$(n[e])*$(r[e]);return i},cross:(e,t)=>{let n=Cp(e),r=Cp(t);if(n.length<3||r.length<3)throw Error(`cross product requires 3D vectors`);let i=$(n[0]),a=$(n[1]),o=$(n[2]),s=$(r[0]),c=$(r[1]),l=$(r[2]);return[a*l-o*c,o*s-i*l,i*c-a*s]},length:e=>bp(e),normalize:e=>{let t=Cp(e),n=bp(e);return n===0?t:t.map(e=>$(e)/n)},sum:e=>Cp(e).reduce((e,t)=>e+$(t),0),join:(...e)=>{let t=e.length>0&&typeof e[e.length-1]==`string`?e.pop():``;return e.flat().map(String).join(t)},trim:e=>String(e).trim(),rand:()=>0};function $(e){if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(typeof e==`string`){let t=parseFloat(e);if(isNaN(t))throw Error(`Cannot convert "${e}" to number`);return t}if(Array.isArray(e)&&e.length>0)return $(e[0]);throw Error(`Cannot convert ${typeof e} to number`)}function Cp(e){return Array.isArray(e)?e:[e]}function wp(e){return typeof e==`boolean`?e:typeof e==`number`?e!==0:typeof e==`string`||Array.isArray(e)?e.length>0:!1}var Tp=2654435769;function Ep(e){let t=e>>>0;return()=>{t=t+1831565813>>>0;let e=t;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}var Dp=class{symbols;random;constructor(e,t=Tp){this.symbols=e||new yp,this.random=Ep(t)}getSymbols(){return this.symbols}evaluate(e){if(typeof e==`number`||typeof e==`string`||Array.isArray(e))return e;switch(e.type){case`string`:case`number`:return e.value;case`identifier`:{if(e.name===`rnd`)return this.random();let t=this.symbols.get(e.name);if(t===void 0)throw Error(`Undefined variable: ${e.name}`);return t}case`binary`:{let t=this.evaluate(e.left);if(e.operator===`and`&&!wp(t))return!1;if(e.operator===`or`&&wp(t))return!0;let n=this.evaluate(e.right);switch(e.operator){case`+`:if(Array.isArray(t)&&Array.isArray(n)){let e=[...t];for(let t=0;t<e.length&&t<n.length;t++)e[t]=$(e[t])+$(n[t]);return e}return $(t)+$(n);case`-`:if(Array.isArray(t)&&Array.isArray(n)){let e=[...t];for(let t=0;t<e.length&&t<n.length;t++)e[t]=$(e[t])-$(n[t]);return e}return $(t)-$(n);case`*`:if(Array.isArray(t)&&Array.isArray(n)){let e=Math.min(t.length,n.length),r=[];for(let i=0;i<e;i++)r.push($(t[i])*$(n[i]));return r}return Array.isArray(t)?t.map(e=>$(e)*$(n)):Array.isArray(n)?n.map(e=>$(t)*$(e)):$(t)*$(n);case`/`:if(Array.isArray(t)&&Array.isArray(n)){let e=Math.min(t.length,n.length),r=[];for(let i=0;i<e;i++)r.push($(t[i])/$(n[i]));return r}return Array.isArray(t)?t.map(e=>$(e)/$(n)):$(t)/$(n);case`%`:return $(t)%$(n);case`=`:if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if($(t[e])!==$(n[e]))return!1;return!0}return t===n;case`<>`:if(Array.isArray(t)&&Array.isArray(n)){if(t.length!==n.length)return!0;for(let e=0;e<t.length;e++)if($(t[e])!==$(n[e]))return!0;return!1}return t!==n;case`<`:return $(t)<$(n);case`<=`:return $(t)<=$(n);case`>`:return $(t)>$(n);case`>=`:return $(t)>=$(n);case`and`:return wp(t)&&wp(n);case`or`:return wp(t)||wp(n);default:throw Error(`Unknown binary operator: ${e.operator}`)}}case`unary`:{let t=this.evaluate(e.operand);switch(e.operator){case`+`:return Array.isArray(t)?t.map($):$(t);case`-`:return Array.isArray(t)?t.map(e=>-$(e)):-$(t);case`not`:return!wp(t);default:throw Error(`Unknown unary operator: ${e.operator}`)}}case`call`:{let t=e.name.toLowerCase();if(t===`rand`)return this.random();let n=Object.prototype.hasOwnProperty.call(Sp,t)?Sp[t]:void 0;if(!n)throw Error(`Unknown function: ${e.name}`);return n(...e.args.map(e=>this.evaluate(e)))}case`tuple`:return e.elements.map(e=>this.evaluate(e));case`member`:{let t=this.evaluate(e.object);if(e.member===`count`&&(Array.isArray(t)||typeof t==`string`))return t.length;let n=xp[e.member];if(Object.hasOwn(xp,e.member)&&n!==void 0&&Array.isArray(t)&&n<t.length)return t[n];throw Error(`Unknown member: ${e.member}`)}case`subscript`:{let t=this.evaluate(e.object),n=this.evaluate(e.index);if(!Array.isArray(t)&&typeof t!=`string`)throw Error(`Subscripting requires a tuple or string`);if(typeof n!=`number`||!Number.isInteger(n)||n<0||n>=t.length)throw Error(`Subscript out of range: ${String(n)}`);return t[n]}default:throw Error(`Unknown expression type: ${e.type}`)}}evaluateToNumber(e){return $(this.evaluate(e))}evaluateToBoolean(e){return wp(this.evaluate(e))}evaluateToVector3(e){if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluate(e);if(Array.isArray(t))return[t.length>0?$(t[0]):0,t.length>1?$(t[1]):0,t.length>2?$(t[2]):0];let n=$(t);return[n,n,n]}evaluateToColor(e){if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluate(e);if(Array.isArray(t))return[t.length>0?$(t[0]):0,t.length>1?$(t[1]):0,t.length>2?$(t[2]):0];let n=$(t);return[n,n,n]}};function Op(){return{geometries:new Set,materials:new Set,textures:new Set}}function kp(e){let{material:t}=e;return Array.isArray(t)?t:t?.isMaterial?[t]:[]}function Ap(e,t){return e.traverse(e=>{let n=e;n.geometry?.isBufferGeometry&&t.geometries.add(n.geometry);for(let e of kp(n)){t.materials.add(e);for(let n of Object.values(e))n&&n.isTexture&&t.textures.add(n)}}),t}function jp(e,t){for(let n of e.geometries)t.geometries.has(n)||n.dispose();for(let n of e.textures)t.textures.has(n)||n.dispose();for(let n of e.materials)t.materials.has(n)||n.dispose()}function Mp(e){jp(Ap(e,Op()),Op())}function Np(e,t){let n=Ap(t,Op()),r=Op();for(let n of e)n!==t&&Ap(n,r);jp(r,n)}function Pp(e,t){t&&(e?.remove(t),Mp(t))}var Fp=3e4,Ip=12,Lp=4,Rp=1e-9,zp=class extends Error{constructor(e){super(e),this.name=`ShapeScriptLimitError`}},Bp=class{options;evaluator;symbols;pathCommandCount=0;detailLevel=32;nodeCount=0;vertexCount=0;startedAt=Date.now();transformStack=[];constructor(e={}){this.options=e,this.symbols=new yp,this.evaluator=new Dp(this.symbols,e.randomSeed),this.pushTransform()}convert(e){let t=new Nn;try{this.addChildren(t,e)}catch(e){throw Mp(t),e}return t}get maxNodes(){return this.options.maxNodes??1e5}get maxLoopIterations(){return this.options.maxLoopIterations??1e5}get maxVertices(){return this.options.maxVertices??5e6}get maxDurationMs(){return this.options.maxDurationMs??3e4}chargePathEstimate(e,t,n=1){let r=Math.max(1,e.curves.length)*Math.max(1,t);this.chargeEstimate(r*n)}chargeEstimate(e){if(this.vertexCount+e>this.maxVertices)throw new zp(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or simplify the path`)}makeMesh(e,t){if(this.vertexCount+=e.getAttribute(`position`)?.count??0,this.vertexCount>this.maxVertices)throw e.dispose(),t.dispose(),new zp(`ShapeScript exceeds ${this.maxVertices} vertices — lower \`detail\` or use fewer shapes`);return new ii(e,t)}rangeIterations(e,t,n){if(n===0||!Number.isFinite(n)||!Number.isFinite(e)||!Number.isFinite(t))throw Error(`Loop bounds and step must be finite, with a nonzero step`);let r=[];for(let i=e;n>0?i<=t:i>=t;i+=n){if(r.length>=this.maxLoopIterations)throw new zp(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);r.push(i)}return r}convertNode(e){if(this.nodeCount+=1,this.nodeCount>this.maxNodes)throw new zp(`ShapeScript produced more than ${this.maxNodes} objects — reduce the loop counts or the nesting`);if(Date.now()-this.startedAt>this.maxDurationMs)throw new zp(`ShapeScript took longer than ${this.maxDurationMs}ms to build — simplify the model or use fewer boolean operations`);switch(e.type){case`shape`:return this.convertShape(e);case`csg`:return this.convertCSG(e);case`block`:return this.convertBlock(e);case`for`:return this.convertForLoop(e);case`if`:return this.convertIf(e);case`switch`:return this.convertSwitch(e);case`define`:return this.handleDefine(e),null;case`extrude`:return this.convertExtrude(e);case`loft`:return this.convertLoft(e);case`lathe`:return this.convertLathe(e);case`fill`:return this.convertFill(e);case`hull`:return this.convertHull(e);case`group`:return this.convertBlock(e);case`detail`:return this.handleDetail(e),null;case`color`:return this.handleColorCommand(e),null;case`rotate`:return this.handleRotateCommand(e),null;case`orientation`:return this.handleOrientationCommand(e),null;case`translate`:return this.handleTranslateCommand(e),null;case`scale`:return this.handleScaleCommand(e),null;case`customShape`:return this.convertCustomShape(e);case`path`:{let t=this.buildPath(e);this.chargePathEstimate(t,Ip),this.requireEnclosedArea(t,`path`);let n=this.makeMesh(new to(t),this.createMaterial({properties:{}}));return this.applyCurrentTransform(n),n}default:throw Error(`Unsupported command: ${e.type}`)}}inScope(e,t){return this.inFrame(()=>{try{t()}catch(t){throw Mp(e),t}return e})}inFrame(e){this.symbols.pushScope(),this.pushTransform();try{return e()}finally{this.popTransform(),this.symbols.popScope()}}addChildren(e,t){for(let n of t){let t=this.convertNode(n);t&&e.add(t)}}convertBlock(e){let t=new Nn;return this.inScope(t,()=>this.addChildren(t,e.children))}finishMesh(e,t){let n;try{return n=this.makeMesh(e,this.createMaterial(t)),this.applyExplicitTransforms(n,t.properties),this.applyCurrentTransform(n),n}catch(t){throw n?Mp(n):e.dispose(),t}}convertShape(e){return this.finishMesh(this.createGeometry(e),e)}requireExtent(e,t){if(t.some(e=>!e))throw Error(`\`${e}\` needs a nonzero size in every dimension — this one encloses nothing`)}createGeometry(e){let t=[1,1,1];switch(e.properties.size&&(t=this.evaluateVector3(e.properties.size)),t[1]===0&&t[2]===0&&t[0]!==0&&(t=[t[0],t[0],t[0]]),e.primitive){case`cube`:return this.requireExtent(`cube`,t),new Ni(t[0],t[1],t[2]);case`sphere`:return this.requireExtent(`sphere`,t),new ro(1,this.detailLevel,this.detailLevel).scale(...t);case`cylinder`:{let n=e.properties.radiusTop?this.evaluateNumber(e.properties.radiusTop):t[0],r=e.properties.radiusBottom?this.evaluateNumber(e.properties.radiusBottom):t[0],i=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cylinder`,[n||r,i]),new Fi(n,r,i,this.detailLevel)}case`cone`:{let n=t[0],r=e.properties.height?this.evaluateNumber(e.properties.height):t[1];return this.requireExtent(`cone`,[n,r]),new Ii(n,r,this.detailLevel)}case`torus`:{let n=e.properties.outerRadius?this.evaluateNumber(e.properties.outerRadius):t[0],r=e.properties.innerRadius?this.evaluateNumber(e.properties.innerRadius):.4;return this.requireExtent(`torus`,[n,r]),new io(n,r,Math.max(3,Math.floor(this.detailLevel/2)),this.detailLevel)}case`circle`:return new Pi(t[0]||1,this.detailLevel);case`square`:{let e=t[0]||1;return new eo(e,t[1]||e)}case`polygon`:{let n=t[0]||1,r=e.properties.sides===void 0?6:this.evaluateNumber(e.properties.sides);if(!Number.isInteger(r)||r<3||r>256)throw Error(`Polygon sides must be an integer from 3 to 256`);return new Pi(n,r)}default:throw Error(`Unknown primitive: ${e.primitive}`)}}materialColor(e){if(e!==void 0){let[t=.8,n=.8,r=.8]=this.evaluateColor(e);return new Bn(t,n,r)}let t=this.currentTransform().color;return t===void 0?new Bn(.8,.8,.8):t.clone()}createMaterial(e){let t=this.materialColor(e.properties.color),n=e.properties.opacity?this.evaluateNumber(e.properties.opacity):1;return new go({color:t,opacity:n,transparent:n<1,wireframe:this.options.wireframe??!1})}convertCSG(e){if(e.children.length===0)return new Nn;let t=this.currentTransform().matrix.clone(),n=[];try{let r=new vp;this.symbols.pushScope(),this.pushTransform(),this.currentTransform().matrix.identity();let i=[];try{for(let t of e.children){if(t.type===`path`)throw Error("A `path` has no volume and cannot be a CSG operand — wrap it in `extrude`, `lathe` or `fill`");let e=this.convertNode(t);if(e){if(n.push(e),e.isMesh){let t=e.clone();t.updateMatrixWorld(!0),i.push(t)}else e.isGroup&&(e.updateMatrixWorld(!0),e.traverse(e=>{if(e.isMesh){let t=e.clone();e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),i.push(t)}}))}}}finally{this.popTransform(),this.symbols.popScope()}if(i.length===0)return new Nn;n.push(...i);let a=i.map(e=>{let t=new vd(e.geometry,e.material);return t.position.copy(e.position),t.rotation.copy(e.rotation),t.scale.copy(e.scale),t.updateMatrixWorld(!0),t});n.push(...a);let o=a[0];if(o===void 0)throw Error(`CSG operation needs at least one child shape`);let s=o;for(let t=1;t<a.length;t++){let i=a[t];if(i===void 0)continue;let o=(e,t,i)=>{n.push(e,t);let a=r.evaluate(e,t,i);return n.push(a),this.chargeEstimate(a.geometry.getAttribute(`position`)?.count??0),this.vertexCount+=a.geometry.getAttribute(`position`)?.count??0,a};switch(e.operation){case`union`:s=o(s,i,0);break;case`difference`:s=o(s,i,1);break;case`intersection`:s=o(s,i,3);break;case`xor`:s=o(o(s.clone(),i.clone(),1),o(i.clone(),s.clone(),1),0);break;case`stencil`:{let e=o(s,i,5),t=o(s,i,6);t.material=Array.isArray(i.material)?i.material[0]:i.material,t.geometry.clearGroups(),t.geometry.addGroup(0,t.geometry.index?.count??t.geometry.getAttribute(`position`).count,0);let r=[e,t],a=r.map(e=>e.geometry.clone().applyMatrix4(e.matrixWorld));try{let e=Rs(a);if(!e)throw Error(`Could not combine stencil surfaces`);let t=[],i=0;for(let n of r){for(let r of n.geometry.groups)e.addGroup(i+r.start,r.count,t.length+(r.materialIndex??0));t.push(...Array.isArray(n.material)?n.material:[n.material]),i+=n.geometry.index?.count??n.geometry.getAttribute(`position`).count}s=new vd(e,t),n.push(s),this.chargeEstimate(e.getAttribute(`position`).count),this.vertexCount+=e.getAttribute(`position`).count}finally{a.forEach(e=>e.dispose())}break}}}return s.material||(s.material=o.material),s.applyMatrix4(t),s.updateMatrixWorld(!0),Np(n,s),s}catch(e){throw Np(n,new Nn),e}}convertForLoop(e){let t=new Nn;return this.inScope(t,()=>{if(e.iterableValues){let n=this.evaluator.evaluate(e.iterableValues),r=Array.isArray(n)?n:[n];if(r.length>this.maxLoopIterations)throw new zp(`ShapeScript loop exceeds ${this.maxLoopIterations} iterations — narrow the range or increase the step`);for(let n of r)this.symbols.set(e.variable,n),this.addChildren(t,e.body)}else{let n=this.evaluateNumber(e.from),r=this.evaluateNumber(e.to),i=e.step?this.evaluateNumber(e.step):1,a=this.rangeIterations(n,r,i);for(let n of a)this.symbols.set(e.variable,n),this.addChildren(t,e.body)}})}convertIf(e){let t=new Nn,n=this.evaluator.evaluateToBoolean(e.condition);return this.inScope(t,()=>this.addChildren(t,n?e.thenBody:e.elseBody??[]))}convertSwitch(e){let t=new Nn,n=this.evaluator.evaluate(e.value);return this.inScope(t,()=>{let r=e.cases.find(e=>e.values.some(e=>this.valuesEqual(n,this.evaluator.evaluate(e))));this.addChildren(t,r?r.body:e.defaultCase??[])})}handleDefine(e){if(e.value!==void 0){let t=this.evaluator.evaluate(e.value);this.symbols.set(e.name,t)}else(e.body!==void 0||e.options!==void 0)&&this.symbols.set(e.name,e)}convertCustomShape(e){let t=this.symbols.get(e.name);if(!t||typeof t!=`object`||!(`type`in t))throw Error(`Unknown shape: ${e.name}`);let n=t;if(!n.body)throw Error(`Custom shape '${e.name}' has no body`);let r=new Nn,i=n.body;return this.inScope(r,()=>{for(let e of n.options??[])this.symbols.set(e.name,this.evaluator.evaluate(e.defaultValue));for(let[t,n]of Object.entries(e.properties))this.symbols.set(t,this.evaluator.evaluate(n));this.addChildren(r,i)})}pushTransform(){let e=this.currentTransform();this.transformStack.push({matrix:e.matrix.clone(),color:e.color===void 0?void 0:e.color.clone()})}popTransform(){this.transformStack.length>1&&this.transformStack.pop()}currentTransform(){return this.transformStack[this.transformStack.length-1]??{matrix:new Y,color:void 0}}applyCurrentTransform(e){let t=this.currentTransform();e.applyMatrix4(t.matrix)}applyExplicitTransforms(e,t){if(t.position){let n=this.evaluateVector3(t.position);e.position.set(...n)}if(t.rotation){let n=this.evaluateVector3(t.rotation);e.rotation.set(...n)}if(t.orientation){let n=this.evaluateVector3(t.orientation);e.rotation.set(...n)}}handleDetail(e){let t=this.evaluateNumber(e.value);this.detailLevel=Number.isFinite(t)?Math.min(256,Math.max(3,Math.floor(t))):3,this.symbols.set(`detail`,this.detailLevel)}handleColorCommand(e){let t=this.evaluateVector3OrColor(e.value);this.currentTransform().color=new Bn(t[0],t[1],t[2])}handleRotateCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new Y,i=new hn(t[0]*Math.PI*2,t[1]*Math.PI*2,t[2]*Math.PI*2,`XYZ`);r.makeRotationFromEuler(i),n.matrix.multiply(r)}handleOrientationCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new J,i=new J;n.matrix.decompose(r,new Ft,i);let a=new hn(t[0]*Math.PI*2,t[1]*Math.PI*2,t[2]*Math.PI*2,`XYZ`);n.matrix.compose(r,new Ft().setFromEuler(a),i)}handleTranslateCommand(e){let t=this.currentTransform(),[n,r,i]=this.evaluateTranslateVector(e.value);if(![n,r,i].every(Number.isFinite))throw Error(`Expected finite translation components`);let a=new Y().makeTranslation(n,r,i);t.matrix.multiply(a)}handleScaleCommand(e){let t=this.evaluateVector3(e.value),n=this.currentTransform(),r=new Y().makeScale(t[0],t[1],t[2]);n.matrix.multiply(r)}requireEnclosedArea(e,t){let n=e.getPoints(Ip),r=qa.area(n);if(!Number.isFinite(r))throw Error(`\`${t}\` needs finite path coordinates — these overflow`);if(n.length<3||Math.abs(r)<Rp)throw Error(`\`${t}\` needs a path that encloses an area — this one has fewer than three distinct points, or they are collinear`);return e}convertExtrude(e){if(!e.path)return this.buildFromChildren({children:e.children??[],properties:e.properties},t=>{let n=t.map(e=>this.planarShape(e));if(!n.length)throw Error(`Extrude requires a path or planar shape`);let r=e.properties.size?this.evaluateVector3(e.properties.size):[1,1,1];for(let e of n)this.chargePathEstimate(e,1,12);return new Xa(n,{depth:r[2]??1,bevelEnabled:!1,curveSegments:1})});let t=this.requireEnclosedArea(this.buildPath(e.path),`extrude`),n=(e.properties.size?this.evaluateVector3(e.properties.size):[1,1,1])[2]||1,r=Math.max(1,Math.floor(this.detailLevel/4));this.chargePathEstimate(t,r,Lp);let i=new Xa(t,{depth:n,bevelEnabled:!1,curveSegments:r}),a=this.createMaterial(e),o=this.makeMesh(i,a);return this.applyExplicitTransforms(o,e.properties),this.applyCurrentTransform(o),o}buildPath(e){let t=new pa,n=0,r=0,i=0,a=!1,o=(e,t)=>{if(n+=e,r+=t,!Number.isFinite(n)||!Number.isFinite(r))throw Error(`Path coordinates overflowed to a non-finite value — they accumulate, so each command adds to the previous one`)},s=e=>{if(++this.pathCommandCount>this.maxLoopIterations)throw new zp(`ShapeScript path exceeds ${this.maxLoopIterations} commands`);switch(e.type){case`define`:this.handleDefine(e);break;case`detail`:this.handleDetail(e);break;case`point`:{let s=this.evaluateNumber(e.x),c=this.evaluateNumber(e.y),l=Math.cos(i),u=Math.sin(i),d=s*l-c*u,f=s*u+c*l;o(d,f),a?t.lineTo(n,r):(t.moveTo(n,r),a=!0);break}case`curve`:{let s=this.evaluateNumber(e.x),c=this.evaluateNumber(e.y),l=Math.cos(i),u=Math.sin(i),d=s*l-c*u,f=s*u+c*l;if(o(d,f),!a){t.moveTo(n,r),a=!0;break}if(e.controlX!==void 0&&e.controlY!==void 0){let i=this.evaluateNumber(e.controlX),a=this.evaluateNumber(e.controlY),o=i*l-a*u,s=i*u+a*l;if(!Number.isFinite(n+o)||!Number.isFinite(r+s))throw Error(`Curve control point overflowed to a non-finite value`);t.quadraticCurveTo(n+o,r+s,n,r)}else t.lineTo(n,r);break}case`rotate`:{let t=this.evaluateNumber(e.angle);if(i+=t*Math.PI*2,!Number.isFinite(i))throw Error(`Path rotation overflowed to a non-finite angle`);break}case`translate`:o(this.evaluateNumber(e.x),this.evaluateNumber(e.y));break;case`for`:{this.symbols.pushScope();let t=this.evaluateNumber(e.from),n=this.evaluateNumber(e.to),r=e.step?this.evaluateNumber(e.step):1,i=this.rangeIterations(t,n,r);for(let t of i){this.symbols.set(e.variable,t);for(let t of e.commands)s(t)}this.symbols.popScope();break}}};for(let t of e.commands)s(t);return t}convertLathe(e){return this.inFrame(()=>this.buildLathe(e))}requireLatheProfile(e){if(!e.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))throw Error("`lathe` profile has non-finite coordinates — a curve control point or a path command overflowed");let t=Math.max(...e.map(e=>Math.abs(e.x))),n=Math.max(...e.map(e=>e.y))-Math.min(...e.map(e=>e.y));if(t<Rp||n<Rp)throw Error("`lathe` needs a profile with both radius and height — one on the axis of rotation sweeps nothing")}buildLathe(e){let t=null;for(let n of e.children)if(n.type===`path`){t=n;break}if(!t)throw Error(`Lathe requires a path child`);let n=this.buildPath(t);this.chargePathEstimate(n,this.detailLevel,this.detailLevel+1);let r=n.getPoints(this.detailLevel);if(r.length<2)throw Error(`Lathe path must have at least 2 points`);this.requireLatheProfile(r),this.chargeEstimate(r.length*(this.detailLevel+1));let i=new $a(r,this.detailLevel),a=this.createMaterial(e),o=this.makeMesh(i,a);return this.applyExplicitTransforms(o,e.properties),this.applyCurrentTransform(o),o}buildOperands(e,t){this.inScope(e,()=>{this.currentTransform().matrix.identity(),this.addChildren(e,t)}),e.updateMatrixWorld(!0);let n=[];return e.traverse(e=>{e.isMesh&&n.push(e)}),n}buildFromChildren(e,t){let n=new Nn,r=this.vertexCount,i;try{i=t(this.buildOperands(n,e.children))}finally{Mp(n),this.vertexCount=r}return this.finishMesh(i,e)}convertLoft(e){return this.buildFromChildren(e,e=>{let t=e.map(Bs),n=t.length*Math.max(0,...t.map(e=>e.length));return this.chargeEstimate(n),Ws(t)})}planarShape(e){let t=Bs(e);if(t.some(e=>Math.abs(e.z)>1e-5))throw Error(`Fill/extrude profiles must lie in the XY plane`);return new pa(t.map(e=>new q(e.x,e.y)))}convertFill(e){return this.inFrame(()=>{let t=e.children.find(e=>e.type===`path`);if(!t)return this.buildFromChildren(e,e=>{let t=e.map(e=>this.planarShape(e));if(!t.length)throw Error(`Fill requires a path or planar shape`);for(let e of t)this.chargePathEstimate(e,1,3);return new to(t,1)});let n=this.buildPath(t);this.chargePathEstimate(n,Ip),this.requireEnclosedArea(n,`fill`);let r=new to(n),i=this.makeMesh(r,this.createMaterial(e));return this.applyExplicitTransforms(i,e.properties),this.applyCurrentTransform(i),i})}convertHull(e){return this.buildFromChildren(e,e=>{let t=[];for(let n of e){let e=n.geometry.getAttribute(`position`);for(let r=0;r<e.count;r++)t.push(new J().fromBufferAttribute(e,r).applyMatrix4(n.matrixWorld))}if(t.length<4)throw Error(`Hull requires at least four non-coplanar points`);this.chargeEstimate(t.length*6);let n=new Ls(t);if(!n.getAttribute(`position`).count)throw n.dispose(),Error(`Hull points must enclose a volume`);return n.setAttribute(`uv`,new X(new Float32Array(n.getAttribute(`position`).count*2),2)),n})}evaluateNumber(e){if(e===void 0)return 0;if(typeof e==`number`)return e;let t=this.evaluator.evaluateToNumber(e);if(!Number.isFinite(t))throw Error(`Expected a finite number`);return t}evaluateVector3(e){if(e===void 0)return[0,0,0];if(Array.isArray(e)&&typeof e[0]==`number`)return e;let t=this.evaluator.evaluateToVector3(e);if(!t.every(Number.isFinite))throw Error(`Expected finite vector components`);return t}evaluateTranslateVector(e){let t=this.evaluator.evaluate(e);return typeof t==`number`?[t,0,0]:Array.isArray(t)?[t.length>0&&typeof t[0]==`number`?t[0]:0,t.length>1&&typeof t[1]==`number`?t[1]:0,t.length>2&&typeof t[2]==`number`?t[2]:0]:[0,0,0]}evaluateColor(e){return e===void 0?[.8,.8,.8]:Array.isArray(e)&&typeof e[0]==`number`?e:this.requireFiniteColor(this.evaluator.evaluateToColor(e))}requireFiniteColor(e){if(!e.every(Number.isFinite))throw Error(`Expected finite color channels`);return e}evaluateVector3OrColor(e){let t=this.evaluator.evaluate(e),n=e=>{if(typeof e==`number`)return e;if(typeof e==`boolean`)return+!!e;if(Array.isArray(e)&&e.length>0)return n(e[0]);throw Error(`Expected numeric color channels`)};if(typeof t==`number`)return this.requireFiniteColor([t,t,t]);if(typeof t==`boolean`)return this.requireFiniteColor([n(t),n(t),n(t)]);if(Array.isArray(t)){if(t.length===1)return this.requireFiniteColor([n(t[0]),n(t[0]),n(t[0])]);if(t.length===2)return this.requireFiniteColor([n(t[0]),n(t[1]),0]);if(t.length>=3)return this.requireFiniteColor([n(t[0]),n(t[1]),n(t[2])])}throw Error(`Expected numeric color channels`)}valuesEqual(e,t){if(typeof e!=typeof t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!this.valuesEqual(e[n],t[n]))return!1;return!0}return e===t}};function Vp(e,t={}){return new Bp(t).convert(e)}Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"$t",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"An",{enumerable:!0,get:function(){return lo}}),Object.defineProperty(exports,"At",{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return Ge}}),Object.defineProperty(exports,"Bn",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"Bt",{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"Cn",{enumerable:!0,get:function(){return nn}}),Object.defineProperty(exports,"Ct",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return ct}}),Object.defineProperty(exports,"Dn",{enumerable:!0,get:function(){return et}}),Object.defineProperty(exports,"Dt",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return Jo}}),Object.defineProperty(exports,"En",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"Et",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"Fn",{enumerable:!0,get:function(){return at}}),Object.defineProperty(exports,"Ft",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"Gt",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"Ht",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return gn}}),Object.defineProperty(exports,"In",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"It",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return _o}}),Object.defineProperty(exports,"Jt",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"Kt",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"Ln",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"Lt",{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Xe}}),Object.defineProperty(exports,"Mn",{enumerable:!0,get:function(){return oo}}),Object.defineProperty(exports,"Mt",{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return xs}}),Object.defineProperty(exports,"Nn",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,"Nt",{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Mi}}),Object.defineProperty(exports,"On",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"Ot",{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"Pn",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"Pt",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Qt",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"Rn",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"Rt",{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return si}}),Object.defineProperty(exports,"Sn",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"St",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Ai}}),Object.defineProperty(exports,"Tn",{enumerable:!0,get:function(){return ao}}),Object.defineProperty(exports,"Tt",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return Pt}}),Object.defineProperty(exports,"Ut",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return Ke}}),Object.defineProperty(exports,"Vn",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"Vt",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return Rt}}),Object.defineProperty(exports,"Wt",{enumerable:!0,get:function(){return ho}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"Xt",{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return vo}}),Object.defineProperty(exports,"Yt",{enumerable:!0,get:function(){return st}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"Zt",{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Qo}}),Object.defineProperty(exports,"_n",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"_t",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Pp}}),Object.defineProperty(exports,"an",{enumerable:!0,get:function(){return fs}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return Ft}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return an}}),Object.defineProperty(exports,"bn",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"bt",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return $o}}),Object.defineProperty(exports,"cn",{enumerable:!0,get:function(){return Sr}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Fr}}),Object.defineProperty(exports,"dn",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"en",{enumerable:!0,get:function(){return We}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return Ko}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"fn",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Ss}}),Object.defineProperty(exports,"gn",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"gt",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Ut}}),Object.defineProperty(exports,"hn",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"ht",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Mp}}),Object.defineProperty(exports,"in",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return ds}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return hi}}),Object.defineProperty(exports,"jn",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"jt",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"kn",{enumerable:!0,get:function(){return Cs}}),Object.defineProperty(exports,"kt",{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Ni}}),Object.defineProperty(exports,"ln",{enumerable:!0,get:function(){return Cr}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Bn}}),Object.defineProperty(exports,"mn",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return zp}}),Object.defineProperty(exports,"nn",{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"on",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"pn",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"qt",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Vp}}),Object.defineProperty(exports,"rn",{enumerable:!0,get:function(){return mo}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return eo}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Yo}}),Object.defineProperty(exports,"sn",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return ft}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Fp}}),Object.defineProperty(exports,"tn",{enumerable:!0,get:function(){return qe}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return Go}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return xr}}),Object.defineProperty(exports,"un",{enumerable:!0,get:function(){return uo}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return ji}}),Object.defineProperty(exports,"vn",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"vt",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"wn",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"wt",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return rn}}),Object.defineProperty(exports,"xn",{enumerable:!0,get:function(){return en}}),Object.defineProperty(exports,"xt",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return ki}}),Object.defineProperty(exports,"yn",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"yt",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"zn",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"zt",{enumerable:!0,get:function(){return ae}});