gl-draw 0.17.0 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=Math.pow,a=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,h=(t,e)=>{for(var n in e||(e={}))s.call(e,n)&&a(t,n,e[n]);if(i)for(var n of i(e))r.call(e,n)&&a(t,n,e[n]);return t},l=(t,i)=>e(t,n(i)),c=(t,e)=>{var n={};for(var o in t)s.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&i)for(var o of i(t))e.indexOf(o)<0&&r.call(t,o)&&(n[o]=t[o]);return n},u=(t,e,n)=>a(t,"symbol"!=typeof e?e+"":e,n),d=(t,e,n)=>new Promise((i,s)=>{var r=t=>{try{a(n.next(t))}catch(e){s(e)}},o=t=>{try{a(n.throw(t))}catch(e){s(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(r,o);a((n=n.apply(t,e)).next())});import{EventEmitter as p}from"events";import f from"deepmerge";import m from"stats-gl";import{Vector3 as y,Matrix4 as g,PerspectiveCamera as x,Material as b,Object3D as v,Texture as w,Sphere as _,Ray as M,BufferGeometry as S,Float32BufferAttribute as A,PointsMaterial as T,Points as C,SRGBColorSpace as z,NoColorSpace as E,LinearSRGBColorSpace as O,MathUtils as P,Vector2 as N,Box3 as B,InstancedMesh as k,Quaternion as L,Group as R,Mesh as U,Sprite as j,BufferAttribute as D,MeshStandardMaterial as F,Shape as I,ShapeUtils as V,SplineCurve as W,QuadraticBezierCurve3 as H,QuadraticBezierCurve as q,LineCurve3 as Z,LineCurve as Y,EllipseCurve as G,CubicBezierCurve3 as X,CubicBezierCurve as $,CatmullRomCurve3 as J,ArcCurve as K,PlaneGeometry as Q,CanvasTexture as tt,AmbientLight as et,DirectionalLight as nt,PointLight as it,SpotLight as st,HemisphereLight as rt,RectAreaLight as ot,ShaderMaterial as at,Color as ht,LineSegments as lt,Vector4 as ct,Line3 as ut,InstancedInterleavedBuffer as dt,InterleavedBufferAttribute as pt,MeshBasicMaterial as ft,UniformsUtils as mt,RawShaderMaterial as yt,SpriteMaterial as gt,WebGLRenderTarget as xt,HalfFloatType as bt,Layers as vt,Raycaster as wt,Spherical as _t,AxesHelper as Mt,CameraHelper as St,PointLightHelper as At,DirectionalLightHelper as Tt,SpotLightHelper as Ct,HemisphereLightHelper as zt,Box3Helper as Et,Scene as Ot,Camera as Pt,FileLoader as Nt,Loader as Bt,VideoTexture as kt,LoadingManager as Lt,TextureLoader as Rt,DataTexture as Ut,WebGLRenderer as jt,REVISION as Dt,Timer as Ft,BufferGeometryLoader as It}from"three";import Vt from"three/examples/jsm/libs/tween.module.js";import{EffectComposer as Wt}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as Ht}from"three/examples/jsm/postprocessing/RenderPass.js";import{SSAOPass as qt}from"three/examples/jsm/postprocessing/SSAOPass.js";import{UnrealBloomPass as Zt}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";import{LineMaterial as Yt}from"three/examples/jsm/lines/LineMaterial.js";import{LineMaterial as Gt}from"three/examples/jsm/lines/LineMaterial.js";import{LineSegmentsGeometry as Xt}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{LineSegmentsGeometry as $t}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{CSS2DObject as Jt,CSS2DRenderer as Kt}from"three/examples/jsm/renderers/CSS2DRenderer.js";import{CSS3DObject as Qt,CSS3DSprite as te,CSS3DRenderer as ee}from"three/examples/jsm/renderers/CSS3DRenderer.js";import{createStore as ne,getMany as ie,setMany as se,keys as re,delMany as oe,get as ae,clear as he}from"idb-keyval";import{geoProjection as le,geoEquirectangular as ce,geoMercator as ue,geoBounds as de,geoContains as pe,geoDistance as fe,geoInterpolate as me}from"d3-geo";import{mergeAttributes as ye,mergeGroups as ge}from"three/examples/jsm/utils/BufferGeometryUtils";import xe from"@turf/boolean-clockwise";import{merge as be,mean as ve,extent as we}from"d3-array";import _e,{flatten as Me}from"earcut";import Se from"delaunator";import Ae from"@turf/boolean-point-in-polygon";import{geoVoronoi as Te}from"d3-geo-voronoi";import{scaleLinear as Ce}from"d3-scale";import{Brush as ze,Evaluator as Ee,INTERSECTION as Oe}from"three-bvh-csg";import{RectAreaLightUniformsLib as Pe}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{LineSegments2 as Ne}from"three/examples/jsm/lines/LineSegments2.js";import{LineSegmentsGeometry as Be}from"three/examples/jsm/lines/LineSegmentsGeometry";import{ShaderPass as ke}from"three/examples/jsm/postprocessing/ShaderPass.js";import{OutputPass as Le}from"three/examples/jsm/postprocessing/OutputPass.js";import{FullScreenQuad as Re}from"three/examples/jsm/postprocessing/Pass.js";import{RectAreaLightHelper as Ue}from"three/examples/jsm/helpers/RectAreaLightHelper.js";import{ViewHelper as je}from"three/examples/jsm/helpers/ViewHelper.js";import{generateUUID as De,makePromiseCreator as Fe,WorkerPool as Ie}from"esus-lite";import{DRACOLoader as Ve}from"three/examples/jsm/loaders/DRACOLoader.js";import{EXRLoader as We}from"three/examples/jsm/loaders/EXRLoader.js";import{GLTFLoader as He}from"three/examples/jsm/loaders/GLTFLoader.js";import{LottieLoader as qe}from"three/examples/jsm/loaders/LottieLoader.js";import{TransformControls as Ze}from"three/examples/jsm/controls/TransformControls.js";const Ye=!1;class Ge{constructor(){u(this,"mask"),this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}isEnabled(t){return!!(this.mask&1<<t)}getMinDisabledLayer(){const t=~this.mask;if(!(4294967295&t))return null;const e=t&-t;return 31-Math.clz32(e>>>0)}}class Xe{constructor(){u(this,"event",new p),u(this,"controllerMap",/* @__PURE__ */new Map),u(this,"activeIndex",-1),u(this,"controller"),u(this,"activeControllerSet",/* @__PURE__ */new Set)}addController(t,e){const n=new Ge;return n.disableAll(),void 0!==e&&n.set(e),this.controllerMap.set(t,n),e===this.activeIndex&&this.activeControllerSet.add(t),t}removePage(t,e){this.controllerMap.forEach((n,i)=>{n.isEnabled(t)&&(n.disable(t),0===n.mask&&(null==e||e(i),this.controllerMap.delete(i),this.activeControllerSet.delete(i)))})}setPageActive(t,e){this.activeIndex=t,this.activeControllerSet.clear();const n=Array.from(this.controllerMap.entries()).map(([n,i])=>{const s=i.isEnabled(t);if(null==e||e(n,s),s)return this.activeControllerSet.add(n),n}).filter(Boolean);this.controller=n[0],this.event.emit("pageChange",this.controller)}update(t,e){this.activeControllerSet.forEach(n=>{var i;null==(i=n.update)||i.call(n,t,e)})}dispose(){this.controllerMap.forEach((t,e)=>{t.set(0)}),this.removePage(0),this.controllerMap.clear(),this.event.removeAllListeners(),this.activeControllerSet.clear()}}const $e={fov:45,near:1,far:1e3,up:new y(0,1,0)};class Je extends Xe{constructor(t){super(),u(this,"width",0),u(this,"height",0),u(this,"_cachedMatrixWorld",new g),u(this,"_cachedMatrixWorldInverse",new g),u(this,"_lastFov",-1),u(this,"_lastAspect",-1),this.width=t.width,this.height=t.height}get camera(){return this.controller}addPerspectiveCamera(t=$e,e){const{fov:n,far:i,near:s,up:r,aspect:o}=t,a=null!=o?o:this.width/this.height,h=new x(n,a,s,i);return h.up=r,this.addController(h,e)}setPageActive(t){super.setPageActive(t,(t,e)=>{e&&this.setAspect(this.width/this.height,t)})}setSize(t,e){this.width=t,this.height=e,this.setAspect(t/e)}setAspect(t,e){const n=e||this.camera;n.aspect!==t&&(n.aspect=t,n.updateProjectionMatrix())}cloneCamera(t){const e=this.addPerspectiveCamera({fov:this.camera.fov,aspect:this.camera.aspect,near:this.camera.near,far:this.camera.far,up:this.camera.up},t);return e.position.copy(this.camera.position),e}sync(t){const e=this.camera;if("PerspectiveCamera"===t.type){const n=t,i=!e.position.equals(n.position),s=e.quaternion.x!==n.quaternion.x||e.quaternion.y!==n.quaternion.y||e.quaternion.z!==n.quaternion.z||e.quaternion.w!==n.quaternion.w;(i||s||e.far!==n.far||e.near!==n.near||e.fov!==n.fov||e.aspect!==n.aspect)&&e.copy(n)}else{const n=t,i=n.viewMatrix,s=n.inverseViewMatrix,{width:r,height:o}=this,a=r/o,h=this._lastFov!==n.fov,l=this._lastAspect!==a;(h||l)&&(e.fov=n.fov,e.aspect=a,e.updateProjectionMatrix(),this._lastFov=n.fov,this._lastAspect=a),this._cachedMatrixWorld.set(s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]),this._cachedMatrixWorldInverse.set(i[0],i[4],i[8],i[12],i[1],i[5],i[9],i[13],i[2],i[6],i[10],i[14],i[3],i[7],i[11],i[15]);const c=!e.matrixWorld.equals(this._cachedMatrixWorld),u=!e.matrixWorldInverse.equals(this._cachedMatrixWorldInverse);(c||u)&&(e.matrixAutoUpdate=!1,c&&e.matrixWorld.copy(this._cachedMatrixWorld),u&&e.matrixWorldInverse.copy(this._cachedMatrixWorldInverse))}}}class Ke{constructor(){u(this,"resources",/* @__PURE__ */new Set),u(this,"disposeMaterial",!0),u(this,"disposeVideo",!0)}track(t){if(!t)return t;if(Array.isArray(t))return t.forEach(t=>{this.track(t)}),t;if(!this.disposeMaterial&&t instanceof b)return t;if(t instanceof Ln?(t.disposeTrack&&t.object3d?this.track(t.object3d):this.resources.add(t),Object.values(t.materialList).map(t=>this.track(t))):(t instanceof v||Reflect.has(t,"dispose"))&&this.resources.add(t),t instanceof Ln)t.children.forEach(t=>{t.disposeTrack=!1}),this.track(t.children);else if(t instanceof v){const e=t;this.track(e.geometry),this.track(e.material),this.track(e.children)}else if(t instanceof b){for(const n of Object.values(t))n instanceof w&&this.track(n);const e=t;if(e.uniforms)for(const t of Object.values(e.uniforms))if(t){const e=t.value;(e instanceof w||Array.isArray(e))&&this.track(e)}}else this.disposeVideo&&t.isVideoTexture&&t.source.data&&this.resources.add(t.source.data);return t}dispose(){const t=[];for(const e of this.resources)e instanceof v?t.push(e):e instanceof HTMLVideoElement&&e.pause(),Reflect.has(e,"dispose")&&e.dispose();t.forEach(t=>{t.removeFromParent()}),t.length=0,this.resources.clear()}}const Qe=/* @__PURE__ */new g,tn=/* @__PURE__ */new M,en=/* @__PURE__ */new _,nn=/* @__PURE__ */new y;function sn(t,e){const n=this.geometry,i=this.matrixWorld,s=t.params.Points.threshold,r=n.drawRange;null===n.boundingSphere&&n.computeBoundingSphere(),en.copy(n.boundingSphere),en.applyMatrix4(i),en.radius+=s,Qe.copy(i).invert(),tn.copy(t.ray).applyMatrix4(Qe);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),a=n.index,h=n.attributes.position;if(null!==a){for(let n=Math.max(0,r.start),s=Math.min(a.count,r.start+r.count);n<s;n++){const s=a.getX(n);nn.fromBufferAttribute(h,s),rn(nn,s,o,i,t,e,this)}}else{for(let n=Math.max(0,r.start),s=Math.min(h.count,r.start+r.count);n<s;n++)nn.fromBufferAttribute(h,n),rn(nn,n,o,i,t,e,this)}}function rn(t,e,n,i,s,r,o){const a=new y;tn.closestPointToPoint(t,a),a.applyMatrix4(i);const h=s.ray.origin.distanceTo(t),l=a.distanceTo(t),c=Math.asin(l/h);if(c<n){if(h<s.near||h>s.far)return;r.push({distance:h,distanceToRay:l,angleToRay:c,point:a,index:e,face:null,object:o})}}const on={linearSRGB:O,sRGB:z,none:E},an={map:on.sRGB,emissiveMap:on.sRGB,sheenColorMap:on.sRGB,specularColorMap:on.sRGB,normalMap:on.none,bumpMap:on.none,displacementMap:on.none,roughnessMap:on.none,metalnessMap:on.none,aoMap:on.none,lightMap:on.none,alphaMap:on.none,specularIntensityMap:on.none,clearcoatMap:on.none,clearcoatNormalMap:on.none,clearcoatRoughnessMap:on.none,iridescenceMap:on.none,iridescenceThicknessMap:on.none,sheenRoughnessMap:on.none,specularMap:on.none,thicknessMap:on.none,transmissionMap:on.none},hn=[".hdr",".exr",".rgbe"];function ln(t){return function(t){if(t.userData&&"boolean"==typeof t.userData.isHDR)return t.userData.isHDR;if(t.colorSpace===O)return!0;if(!t.image||!t.image.src)return!1;const e="string"==typeof t.image.src?t.image.src:"";return hn.some(t=>e.toLowerCase().includes(t))}(t)?on.linearSRGB:on.sRGB}function cn({node:t,material:e,texture:n}){const i=function({node:t,material:e,texture:n}){if(n)return[{map:n}];if(e)return Array.isArray(e)?e:[e];if(null==t?void 0:t.material)return Array.isArray(t.material)?t.material:[t.material];return[]}({node:t,material:e,texture:n});i.forEach(t=>function(t){Object.keys(an).forEach(e=>{const n=t;n[e]&&(n[e].colorSpace=an[e])});const e=t;e.envMap&&(e.envMap.colorSpace=ln(e.envMap))}(t))}class un{constructor(t){u(this,"store"),u(this,"metadataStore"),u(this,"pendingMetadataUpdates",/* @__PURE__ */new Map),u(this,"cacheObj",{}),u(this,"options"),this.options=t,this.store=ne(t.dbName,"keyval"),this.metadataStore=ne(`${t.dbName}_metadata`,"keyval")}addToCache(t,e,n){this.cacheObj[t]||(this.cacheObj[t]={[e]:[]}),this.cacheObj[t][e]||(this.cacheObj[t][e]=[]),this.cacheObj[t][e].push(n)}recordMetadataUpdate(t,e){this.pendingMetadataUpdates.set(t,{size:e,timestamp:Date.now()})}flushMetadata(){return d(this,null,function*(){if(0===this.pendingMetadataUpdates.size)return;const t=Array.from(this.pendingMetadataUpdates.keys()),e=yield ie(t,this.metadataStore),n=[];for(let i=0;i<t.length;i++){const s=t[i],r=this.pendingMetadataUpdates.get(s);if(!r)continue;const o=e[i],a={lastAccessed:r.timestamp,accessCount:o?o.accessCount+1:1,size:r.size};n.push([s,a])}yield se(n,this.metadataStore),this.pendingMetadataUpdates.clear()})}evictLRUCache(){return d(this,null,function*(){const t=yield re(this.store);if(t.length>=this.options.maxCacheSize){const e=yield ie(t,this.metadataStore),n=[];for(let r=0;r<t.length;r++){const i=e[r];i&&n.push({key:t[r],metadata:i})}n.sort((t,e)=>t.metadata.accessCount!==e.metadata.accessCount?t.metadata.accessCount-e.metadata.accessCount:t.metadata.lastAccessed-e.metadata.lastAccessed);const i=Math.max(1,Math.floor(.1*this.options.maxCacheSize)),s=n.slice(0,i).map(t=>t.key);yield oe(s,this.store),yield oe(s,this.metadataStore)}})}get(t,e){return d(this,null,function*(){const n=yield ae(t,this.store),i=e||this.options.cacheVersion;return null==n?void 0:n[i]})}saveCache(){return d(this,null,function*(){var t,e;try{yield this.flushMetadata(),yield this.evictLRUCache();const e=Object.entries(this.cacheObj);if(0===e.length)return;yield se(e,this.store);const n=this.options.cacheVersion,i=e.map(([t])=>t),s=yield ie(i,this.metadataStore),r=[];for(let o=0;o<e.length;o++){const[i,a]=e[o],h=(null==(t=a[n])?void 0:t.length)||0,l=s[o],c={lastAccessed:Date.now(),accessCount:l?l.accessCount+1:1,size:h};r.push([i,c])}yield se(r,this.metadataStore),this.cacheObj={}}catch(n){if("QuotaExceededError"!==n.name&&!(null==(e=n.message)?void 0:e.includes("NO_SPACE")))throw n;console.error("存储空间不足,尝试清理旧缓存..."),yield this.clearCache()}})}getCacheStats(){return d(this,null,function*(){const t=yield re(this.store),e={total:t.length,maxSize:this.options.maxCacheSize,usage:t.length/this.options.maxCacheSize*100,items:[]},n=yield ie(t,this.metadataStore);for(let i=0;i<t.length;i++){const s=n[i];s&&e.items.push({key:t[i],metadata:s})}return e})}clearCache(){return d(this,null,function*(){yield he(this.store),yield he(this.metadataStore),this.cacheObj={}})}checkStorageQuota(){return d(this,null,function*(){var t;if(null==(t=navigator.storage)?void 0:t.estimate){const t=yield navigator.storage.estimate(),e=t.usage||0,n=t.quota||0,i=e/n*100;return console.log(`存储使用: ${(e/1024/1024).toFixed(2)}MB / ${(n/1024/1024).toFixed(2)}MB (${i.toFixed(2)}%)`),i>80&&console.warn("存储空间不足,建议清理缓存"),{usage:e,quota:n,percentUsed:i}}return null})}dispose(){this.cacheObj={},this.pendingMetadataUpdates.clear()}}const dn={a:6378137,b:6356752.314245179,f:1/298.257223563};function pn(t,e,n=0,i=1/dn.a,s=!1){const r=P.degToRad(t),o=P.degToRad(e),a=Math.cos(o),h=Math.sin(o),l=Math.cos(r),c=Math.sin(r);let u,d,p;if(s){const t=(dn.a+n)*i;u=t*a*c,d=t*h,p=t*a*l}else{const t=dn.a,e=dn.b,s=t*t,r=(s-e*e)/s,o=t/Math.sqrt(1-r*h*h);u=(o+n)*a*c*i,d=(o*(1-r)+n)*h*i,p=(o+n)*a*l*i}return new y(u,d,p)}var fn=Math.abs,mn=Math.cos,yn=Math.sin,gn=1e-6,xn=Math.PI,bn=xn/2;function vn(t){return t>1?0:t<-1?xn:Math.acos(t)}function wn(t){return t>0?Math.sqrt(t):0}function _n(t,e){var n=mn(e),i=function(t){return t?t/Math.sin(t):1}(vn(n*mn(t/=2)));return[2*n*yn(t)*i,yn(e)*i]}function Mn(t,e){var n=_n(t,e);return[(n[0]+t/bn)/2,(n[1]+e)/2]}Mn.invert=(t,e)=>{var n=t,i=e,s=25;do{var r,o=mn(i),a=yn(i),h=yn(2*i),l=a*a,c=o*o,u=yn(n),d=mn(n/2),p=yn(n/2),f=p*p,m=1-c*d*d,y=m?vn(o*d)*wn(r=1/m):r=0,g=.5*(2*y*o*p+n/bn)-t,x=.5*(y*a+i)-e,b=.5*r*(c*f+y*o*d*l)+.5/bn,v=r*(u*h/4-y*a*p),w=.125*r*(h*p-y*a*c*u),_=.5*r*(l*d+y*f*o)+.5,M=v*w-_*b,S=(x*v-g*_)/M,A=(g*w-x*b)/M;n-=S,i-=A}while((fn(S)>gn||fn(A)>gn)&&--s>0);return[n,i]};const Sn={mercator:ue,equirectangular:ce,winkel3:function(){return le(Mn).scale(158.837)}},An={};function Tn(t){return"[object Object]"===Object.prototype.toString.call(t)}function Cn(t){if(!1===Tn(t))return!1;const e=t.constructor;if(void 0===e)return!0;const n=e.prototype;return!1!==Tn(n)&&!1!==n.hasOwnProperty("isPrototypeOf")}const zn=t=>t instanceof y?t:new y(...t);const En=/* @__PURE__ */new Map,On=(t={})=>({generateTopUV(e,n,i,s,r){const o=n[3*i],a=n[3*i+1],h=n[3*s],l=n[3*s+1],c=n[3*r],u=n[3*r+1];let d;if(En.has(e))d=En.get(e);else{let n=t.box3;if(!n){n=new B;const t=e.parameters.shapes.getPoints().flatMap(t=>[t.x,t.y,0]);n.setFromArray(t)}const i=n.getSize(new y);t.split&&(i.y/=t.split),d={box:n,size:i},En.set(e,d)}const{box:p,size:f}=d,m=t.split?1-t.split:0;return[new N((o-p.min.x)/f.x,(a-p.min.y)/f.y+m),new N((h-p.min.x)/f.x,(l-p.min.y)/f.y+m),new N((c-p.min.x)/f.x,(u-p.min.y)/f.y+m)]},generateSideWallUV(e,n,i,s,r,o){const a=n[3*i],h=n[3*i+1],l=n[3*i+2],c=n[3*s],u=n[3*s+1],d=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],x=n[3*o+1],b=n[3*o+2];let v;if(En.has(n))v=En.get(n);else{const e=new B;e.setFromArray(n);const i=e.getSize(new y);t.split&&(i.z/=1-t.split),t.sideRepeat&&(i.z/=t.sideRepeat),v={box:e,size:i},En.set(n,v)}const{box:w,size:_}=v;return Math.abs(h-u)<Math.abs(a-c)?[new N((a-w.min.x)/_.x,(l-w.min.z)/_.z),new N((c-w.min.x)/_.x,(d-w.min.z)/_.z),new N((p-w.min.x)/_.x,(m-w.min.z)/_.z),new N((g-w.min.x)/_.x,(b-w.min.z)/_.z)]:[new N((h-w.min.y)/_.y,(l-w.min.z)/_.z),new N((u-w.min.y)/_.y,(d-w.min.z)/_.z),new N((f-w.min.y)/_.y,(m-w.min.z)/_.z),new N((x-w.min.y)/_.y,(b-w.min.z)/_.z)]}}),Pn=()=>{En.clear()},Nn={applyTextureColorSpace:cn,CacheManager:un,cartographicToCartesian:pn,WGS84:dn,getProjection:t=>{var e,n,i;const s=JSON.stringify(t);if(An[s])return An[s];const r=Sn[null!=(e=t.projectionType)?e:"mercator"]().center(t.center).scale(t.scale).translate(null!=(n=t.translate)?n:[0,0]).precision(null!=(i=t.precision)?i:.1);return t.rotate&&r.rotate(t.rotate),An[s]=r,r},isPlainObject:Cn,parseVector2:t=>t instanceof N?t:new N(...t),parseVector3:zn,claerUVGenerator:Pn,getUVGenerator:On,enableMultiLevelRTC:function(t,e){return e?"MeshLineMaterial"===t.type?(t.uniforms.globalRTCCenter={value:new y(e.x,e.y,e.z)},t.uniforms.uRTCMode.value=2,t):(t.onBeforeCompile=t=>{t.uniforms.globalRTCCenter={value:new y(e.x,e.y,e.z)},t.vertexShader=t.vertexShader.replace("#include <common>","\n #include <common>\n uniform vec3 globalRTCCenter;\n attribute vec3 localCenter;\n "),t.vertexShader=t.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n // 多级 RTC: position 相对于 localCenter,localCenter 相对于 globalRTCCenter\n transformed = transformed + localCenter + globalRTCCenter;\n ")},t):t}};let Bn=class{constructor(){u(this,"lead"),u(this,"onPointerIndex",[])}onPointerEvent(t,e){const n=this.lead.handlePick([this],t,e);this.onPointerIndex.push(n)}onClick(t){this.onPointerEvent("click",t)}onPointerEnter(t){this.onPointerEvent("enter",t)}onPointerEnterOnStop(t){this.onPointerEvent("enterOnStop",t)}onPointerLeave(t){this.onPointerEvent("leave",t)}onPointerMove(t){this.onPointerEvent("move",t)}onPointerDown(t){this.onPointerEvent("down",t)}dispose(){this.onPointerIndex.forEach(t=>{this.lead.removePick(t)})}};class kn extends Bn{constructor(){super(...arguments),u(this,"userData",{}),u(this,"materialList",{}),u(this,"useMaterialType","origin"),u(this,"disposeMaterialIfNotUsed",!0)}cloneMaterial(){const t=this.object3d;if(!t||!t.material)return;const e=t.material;if(Array.isArray(e))return e.map(t=>{const e=t.userData;t.userData={};const n=t.clone();return t.userData=e,n});{const t=e.userData;e.userData={};const n=e.clone();return e.userData=t,n}}setMaterialList(t,e){const n=this.object3d;if(!n||!n.material)return;this.materialList.origin||(this.materialList.origin=n.material);const i="clone"===e?this.cloneMaterial():Array.isArray(e)?e.slice():e;return this.materialList[t]=i,i}useMaterial(t){const e=this.object3d;e&&e.material&&this.useMaterialType!==t&&this.materialList[t]&&(this.useMaterialType=t,e.material=this.materialList[t])}useMListById(t,e){if(!this.mList)return;const n=this.mList.get(t);if(!n)return;const i=this.object3d;Array.isArray(i.material)&&void 0!==e?i.material[e]=n:i.material=n}useMListByName(t,e){if(!this.mList)return;const n=this.mList.getKeyByName(t);n&&this.useMListById(n,e)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Ln extends kn{constructor(){super(...arguments),u(this,"key",""),u(this,"keyType"),u(this,"keyUId"),u(this,"keyName"),u(this,"objectType","BaseObject"),u(this,"objectOptions"),u(this,"userData",{}),u(this,"isPrefab",!1),u(this,"isInstantiate",!1),u(this,"isBloom",!1),u(this,"isBaseObject",!0),u(this,"disposeTrack",!0),u(this,"isDispose",!1)}get parent(){const t=this.object3d.parent;return t&&this.lead.objMap.get(t)||null}get children(){return this.object3d.children.map(t=>this.lead.objMap.get(t)).filter(t=>!!t)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}lookAt(t){const e=t instanceof y?t:new y(...t);this.object3d.lookAt(e)}add(...t){[...t].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...t){[...t].forEach(t=>{var e;this.lead.objMap.get(t)?null==(e=this.lead.objMap.get(t))||e.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}isActuallyVisible(){if(!this.object3d.visible)return!1;const t=this.parent;return!t||t.isActuallyVisible()}create(){this.createGroup()}render(){}update(t,e){}resize(t,e){}show(){return this.object3d.visible=!0,this.isActuallyVisible()&&this._enableLayersRecursive(),this}hide(){return this.object3d.visible=!1,this._disableLayersRecursive(),this}_disableLayersRecursive(){var t;null==(t=this.object3d)||t.layers.disable(0),this.children.forEach(t=>{t._disableLayersRecursive()})}_enableLayersRecursive(){var t;this.object3d.visible&&(null==(t=this.object3d)||t.layers.enable(0),this.children.forEach(t=>{t._enableLayersRecursive()}))}createGroup(){return this.object3d=new R,this}createMesh(...t){return this.object3d=new U(...t),this}createPoints(...t){return this.object3d=new C(...t),this}createCSS2DObject(t){return this.object3d=new Jt(t),this}createCSS3DObject(t){return this.object3d=new Qt(t),this}createCSS3DSprite(t){return this.object3d=new te(t),this}createSprite(t){return this.object3d=new j(t),this}attach(...t){return[...t].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const t=(new B).setFromObject(this.object3d);return{min:t.min,max:t.max,size:t.getSize(new y),center:t.getCenter(new y)}}setTop(t){this.object3d&&(this.object3d.renderOrder=t)}traverse(t){t(this),this.children.forEach(e=>{e.traverse(t)})}instantiate(t){return d(this,null,function*(){var e,n;const i=null==(e=null==t?void 0:t.recursive)||e,s=null!=(n=null==t?void 0:t.cloneMaterial)&&n,{objectType:r,objectOptions:o}=this;let a,c=null==t?void 0:t.create,u=(null==t?void 0:t.target)||this.parent;return u===this.lead.prefabGroup&&(u=this.lead.group),"BaseObject"===this.objectType?a=this.lead.createBaseObject(this.object3d.clone(!1),{target:u}):(void 0===c&&(c=e=>{var n;if(this.object3d){if(null==(n=null==t?void 0:t.instancedAttr)?void 0:n.length){const n=t.instancedAttr.length;if(this.object3d instanceof j)e.object3d=((t,e=1)=>{const n=new S;n.setAttribute("position",new A(new Array(3*e).fill(0),3)),n.setAttribute("scaleAtt",new A(new Array(e).fill(1),1));const i=t.material,s=new T({size:10,map:i.map,alphaMap:i.alphaMap,color:i.color,blending:i.blending,depthTest:i.depthTest,depthWrite:!1,opacity:i.opacity,transparent:!0,alphaTest:i.alphaTest,sizeAttenuation:!1});s.onBeforeCompile=t=>{t.vertexShader=`\n attribute float scaleAtt;\n ${t.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}\n `};const r=new C(n,s);return r.raycast=sn,r})(this.object3d,n);else{const t=this.object3d,i=s?this.cloneMaterial():t.material;e.object3d=new k(t.geometry,i,n)}((t,e)=>{const n=new v;e.forEach((e,i)=>{const s=zn(e.position),r=zn(e.scale||[1,1,1]);n.position.copy(s),n.scale.copy(r),n.updateMatrix();const o=n.matrix.clone();if(t instanceof k||t.isInstantiate)t.setMatrixAt(i,o);else if(t instanceof C||"Points"===t.type){const e=t.geometry,n=e.attributes.position.array,s=e.attributes.scaleAtt.array,r=new y,a=new y,h=new L,l=3*i,c=1*i;o.decompose(r,h,a),n[l]=r.x,n[l+1]=r.y,n[l+2]=r.z,s[c]=Math.max(a.x,a.y,a.z),e.attributes.position.needsUpdate=!0,e.attributes.scaleAtt.needsUpdate=!0}})})(e.object3d,null==t?void 0:t.instancedAttr)}else e.object3d=this.object3d.clone(!1),s&&e.object3d.material&&(e.object3d.material=this.cloneMaterial());e.object3d.userData.prefab&&delete e.object3d.userData.prefab}}),a=yield this.lead.draw(r,l(h({},o||{}),{create:c,prefab:!1,keyType:this.keyType,key:(null==t?void 0:t.key)||this.keyName,uId:(null==t?void 0:t.uId)||this.keyUId,target:u}))),this.isBloom&&a.enableBloom(),i&&(yield Promise.all(this.children.map(e=>e.instantiate({key:e.keyUId&&e.keyName?`${e.keyName}-${e.keyUId}`:e.keyName,uId:null==t?void 0:t.uId,cloneMaterial:s,target:a})))),a.isInstantiate=!0,a})}erase(){this.lead.erase(this)}handleMaterialChange(t){}enableBloom(t=!0){var e,n,i;(null==(e=this.pencil.composerController)?void 0:e.bloomComposer)?t?this.traverse(t=>{t.enableBloom(!1)}):(this.object3d&&(null==(n=this.pencil.composerController)||n.bloomSelection.add(this),this.object3d.layers.enable(1)),null==(i=this.pencil.composerController)||i.checkBloomComposerActive(),this.isBloom=!0):console.warn("err:pencil.options.bloom")}disableBloom(t=!0){var e,n,i;(null==(e=this.pencil.composerController)?void 0:e.bloomComposer)?t?this.traverse(t=>{t.disableBloom(!1)}):(this.object3d&&(null==(n=this.pencil.composerController)||n.bloomSelection.delete(this),this.object3d.layers.disable(1)),null==(i=this.pencil.composerController)||i.checkBloomComposerActive(),this.isBloom=!1):console.warn("err:pencil.options.bloom")}dispose(){var t,e;if(!this.isDispose&&(this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),null==(t=this.pencil.composerController)||t.checkBloomComposerActive()),null==(e=this.lead)||e.disableCursor(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack)){const t=new Ke;t.disposeMaterial=!1,t.track(this),t.dispose()}}}function Rn(t,e=0){const n=null!==t[0].index,i=new Set(Object.keys(t[0].attributes)),s=new Set(Object.keys(t[0].morphAttributes)),r={},o={},a=t[0].morphTargetsRelative,h=new S;let l=0;for(let c=0;c<t.length;++c){const u=t[c];let d=0;if(n!==(null!==u.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const t in u.attributes){if(!i.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+'. All geometries must have compatible attributes; make sure "'+t+'" attribute exists among all geometries, or in none of them.'),null;void 0===r[t]&&(r[t]=[]),r[t].push(u.attributes[t]),d++}if(d!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". Make sure all geometries have the same number of attributes."),null;if(a!==u.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const t in u.morphAttributes){if(!s.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". .morphAttributes must be consistent throughout all geometries."),null;void 0===o[t]&&(o[t]=[]),o[t].push(u.morphAttributes[t])}if(e){let t;if(n)t=u.index.count;else{if(void 0===u.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". The geometry must have either an index or a position attribute"),null;t=u.attributes.position.count}if(1===e)h.addGroup(l,t,c);else if(2===e&&u.groups.length>0)for(let e of u.groups){let n=e.materialIndex;h.addGroup(l+e.start,Math.min(e.count,t),n)}l+=t}}if(n){let e=0;const n=[];for(let i=0;i<t.length;++i){const s=t[i].index;for(let t=0;t<s.count;++t)n.push(s.getX(t)+e);e+=t[i].attributes.position.count}h.setIndex(n)}for(const c in r){const t=ye(r[c]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+c+" attribute."),null;h.setAttribute(c,t)}for(const c in o){const t=o[c][0].length;if(0===t)break;h.morphAttributes=h.morphAttributes||{},h.morphAttributes[c]=[];for(let e=0;e<t;++e){const t=[];for(let i=0;i<o[c].length;++i)t.push(o[c][i][e]);const n=ye(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+c+" morphAttribute."),null;h.morphAttributes[c].push(n)}}return 2===e?ge(h):h}function Un(t,e,n=!1){return n?pe(e,t):Ae(t,e)}function jn(t,e){const n={type:"Polygon",coordinates:t},[[i,s],[r,a]]=de(n);if(Math.min(Math.abs(r-i),Math.abs(a-s))<e)return[];const h=i>r||a>=89||s<=-89;return function(t,{minLng:e,maxLng:n,minLat:i,maxLat:s}={}){const r=Math.round(o(360/t,2)/Math.PI),a=(1+Math.sqrt(5))/2,h=t=>t/a*360%360-180,l=t=>Math.acos(2*t/r-1)/Math.PI*180-90,c=t=>r*(Math.cos((t+90)*Math.PI/180)+1)/2,u=[void 0!==s?Math.ceil(c(s)):0,void 0!==i?Math.floor(c(i)):r-1],d=void 0===e&&void 0===n?()=>!0:void 0===e?t=>t<=n:void 0===n?t=>t>=e:n>=e?t=>t>=e&&t<=n:t=>t>=e||t<=n,p=[];for(let o=u[0];o<=u[1];o++){const t=h(o);d(t)&&p.push([t,l(o)])}return p}(e,{minLng:i,maxLng:r,minLat:s,maxLat:a}).filter(t=>Un(t,n,h))}function Dn(t,{resolution:e=1/0,bbox:n,projection:i}={}){const s=function(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const s=180*fe(t,i)/Math.PI;if(s>e){const r=me(i,t),o=1/Math.ceil(s/e);let a=o;for(;a<1;)n.push(r(a)),a+=o}}n.push(i=t)}),n})}(t,e),r=be(s),o=jn(t,e),a=[...r,...o],h={type:"Polygon",coordinates:t},[[l,c],[u,d]]=de(h),p=l>u||d>=89||c<=-89;let f=[];if(p){const t=Te(a).triangles(),e=new Map(a.map(([t,e],n)=>[`${t}-${e}`,n]));t.features.forEach(t=>{const n=t.geometry.coordinates[0].slice(0,3).reverse(),i=[];if(n.forEach(([t,n])=>{const s=`${t}-${n}`;e.has(s)&&i.push(e.get(s))}),3===i.length){if(i.some(t=>t<r.length)){if(!Un(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=Se.from(a);for(let e=0,n=t.triangles.length;e<n;e+=3){const n=[2,1,0].map(n=>t.triangles[e+n]),i=n.map(t=>a[t]);if(n.some(t=>t<r.length)){if(!Un([0,1].map(t=>ve(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=Me(s);f=_e(t,e,2)}let m=n?[n[0],n[2]]:we(a,t=>t[0]),y=n?[n[1],n[3]]:we(a,t=>t[1]);if(i){const[t,e]=i([m[0],y[0]]),[n,s]=i([m[1],y[1]]);m=[t,n],y=[-e,-s]}const g=Ce(m,[0,1]),x=Ce(y,[0,1]),b=a.map(([t,e])=>{if(i){const[n,s]=i([t,e]);return[g(n),x(-s)]}return[g(t),x(e)]});return{contour:s,triangles:{points:a,indices:f,uvs:b}}}const Fn=(new S).setAttribute?"setAttribute":"addAttribute";function In(t,e,n){const i=t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=pn(t,i,0,e/dn.a,!1);return[n.x,n.y,n.z]}if("sphere"===n){const n=pn(t,i,e-dn.a,1,!0);return[n.x,n.y,n.z]}if("function"==typeof n){const[s,r]=n([t,i]);return[s,-r,e]}return[t,i,e]}));return Me(i)}function Vn(t,e,n,i,s){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:In([t.points],e,s).vertices,uvs:n}}const Wn=({polygonGeoJson:t,startHeight:e,endHeight:n,curvatureResolution:i=1,hasSide:s=!0,hasBottom:r=!1,hasTop:o=!1,projection:a="sphere",bbox:h})=>{t.forEach(t=>{xe(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:c,triangles:u}=Dn(t,{resolution:i,bbox:h,projection:l});let d,p={};s&&(p=function(t,e,n,i){const{vertices:s,holes:r}=In(t,e,i),{vertices:o}=In(t,n,i),a=be([o,s]),h=Math.round(o.length/3),l=new Set(r);let c=0;const u=[];for(let p=0;p<h;p++){let t=p+1;if(t===h)t=c;else if(l.has(t)){const e=t;t=c,c=e}u.push(p,p+h,t+h),u.push(t+h,t,p)}const d=[];for(let p=1;p>=0;p--)for(let t=0;t<h;t+=1)d.push(t/(h-1),p);return{indices:u,vertices:a,uvs:d,topVerts:o}}(c,null!=e?e:n,null!=n?n:e,a),d=p.topVerts);let f=[];(r||o)&&(f=be(u.uvs));let m={};r&&(m=Vn(u,e,f,!1,a));let y={};return o&&(y=Vn(u,n,f,!0,a)),{contour:c,triangles:u,sideTorso:p,bottomCap:m,topCap:y,topVerts:d}};class Hn extends S{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=h(h({},{polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,projection:"sphere",resetCenter:!1}),e);const{hasTop:n,topFirst:i,hasBottom:s,hasSide:r}=this.parameters,{sideTorso:o,bottomCap:a,topCap:l}=Wn(h({},this.parameters));let c=[],u=[],d=[],p=0;const f=t=>{const e=Math.round(c.length/3),n=d.length;c=c.concat(t.vertices),u=u.concat(t.uvs),d=d.concat(e?t.indices.map(t=>t+e):t.indices),this.addGroup(n,d.length-n,p++)};n&&i&&f(l),r&&f(o),s&&f(a),n&&!i&&f(l),this.parameters.resetCenter&&c.length>0&&(this.userData.rtcPositionsVertices=new D(new Float64Array(c),3)),this.setIndex(d),this[Fn]("position",new A(c,3)),this[Fn]("uv",new A(u,2)),this.computeVertexNormals()}}const qn=t=>{const e=t,{coordinate:n,startHeight:i,height:s}=e,r=c(e,["coordinate","startHeight","height"]);let o=i||0;void 0!==i&&void 0!==s&&(o=i+s);return new Hn([n],l(h({},r),{startHeight:i,endHeight:o}))};class Zn extends Ln{constructor(t){super(),u(this,"options"),this.options=h({},t)}create(){const t=this.options,{geometry:e,coordinateArr:n,coordinate:i,material:s,useGroups:r}=t,o=c(t,["geometry","coordinateArr","coordinate","material","useGroups"]);let a=e;if(!a&&i)a=qn(h({coordinate:i},o));else if(!a&&n){a=Rn(n.map(t=>qn(h({coordinate:t},o))),null!=r?r:0)}this.createMesh(a,s)}}class Yn extends Ln{constructor(t={}){super(),u(this,"options"),this.options=t}create(){const t=function(t={}){const{a:e=dn.a,b:n=dn.b,scaleFactor:i=1/dn.a,widthSegments:s=64,heightSegments:r=32}=t,o=new S,a=[],h=[],l=[],c=[],u=e*e,d=(u-n*n)/u;let p=0;const f=[];for(let m=0;m<=r;m++){const t=[],o=m/r,a=180*(.5-o)*Math.PI/180,u=Math.sin(a),y=Math.cos(a),g=e/Math.sqrt(1-d*u*u);for(let r=0;r<=s;r++){const a=r/s,f=360*(a-.5)*Math.PI/180,m=Math.sin(f),x=Math.cos(f),b=g*y*m*i,v=g*(1-d)*u*i,w=g*y*x*i;h.push(b,v,w);const _=y*m/e,M=u*(1-d)/n,S=y*x/e,A=Math.sqrt(_*_+M*M+S*S);l.push(_/A,M/A,S/A),c.push(a,1-o),t.push(p++)}f.push(t)}for(let m=0;m<r;m++)for(let t=0;t<s;t++){const e=f[m][t+1],n=f[m][t],i=f[m+1][t],s=f[m+1][t+1];a.push(e,n,s),a.push(n,i,s)}return o.setIndex(a),o.setAttribute("position",new A(h,3)),o.setAttribute("normal",new A(l,3)),o.setAttribute("uv",new A(c,2)),o}(this.options),e=this.options.material||new F({color:2200782,metalness:.1,roughness:.7,wireframe:!1}),n=new U(t,e);return n.name="Ellipsoid",this.object3d=n,n}}const Gn={ArcCurve:K,CatmullRomCurve3:J,CubicBezierCurve:$,CubicBezierCurve3:X,EllipseCurve:G,LineCurve:Y,LineCurve3:Z,QuadraticBezierCurve:q,QuadraticBezierCurve3:H,SplineCurve:W};class Xn extends S{constructor(t=new I([new N(.5,.5),new N(-.5,.5),new N(-.5,-.5),new N(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const n=this,i=[],s=[];for(let o=0,a=t.length;o<a;o++){r(t[o])}function r(t){var r,o,a;const h=[],l=void 0!==e.curveSegments?e.curveSegments:12,c=void 0!==e.steps?e.steps:1,u=void 0!==e.depth?e.depth:1;let d=void 0===e.bevelEnabled||e.bevelEnabled,p=void 0!==e.bevelThickness?e.bevelThickness:.2,f=void 0!==e.bevelSize?e.bevelSize:p-.1,m=void 0!==e.bevelOffset?e.bevelOffset:0,g=void 0!==e.bevelSegments?e.bevelSegments:3;const x=e.extrudePath,b=void 0!==e.UVGenerator?e.UVGenerator:$n,v=null==(r=e.hasTop)||r,w=null==(o=e.hasBottom)||o,_=null==(a=e.hasSide)||a;let M,S,A,T,C,z=!1;x&&(M=x.getSpacedPoints(c),z=!0,d=!1,S=x.computeFrenetFrames(c,!1),A=new y,T=new y,C=new y),d||(g=0,p=0,f=0,m=0);const E=t.extractPoints(l);let O=E.shape;const P=E.holes;if(!V.isClockWise(O)){O=O.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];V.isClockWise(e)&&(P[t]=e.reverse())}}function B(t){const e=1e-10*1e-10;let n=t[0];for(let i=1;i<=t.length;i++){const s=i%t.length,r=t[s],o=r.x-n.x,a=r.y-n.y,h=o*o+a*a,l=Math.max(Math.abs(r.x),Math.abs(r.y),Math.abs(n.x),Math.abs(n.y));h<=e*l*l?(t.splice(s,1),i--):n=r}}B(O),P.forEach(B);const k=P.length,L=O;for(let e=0;e<k;e++){const t=P[e];O=O.concat(t)}function R(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const U=O.length;function j(t,e,n){let i,s,r;const o=t.x-e.x,a=t.y-e.y,h=n.x-t.x,l=n.y-t.y,c=o*o+a*a,u=o*l-a*h;if(Math.abs(u)>Number.EPSILON){const u=Math.sqrt(c),d=Math.sqrt(h*h+l*l),p=e.x-a/u,f=e.y+o/u,m=((n.x-l/d-p)*l-(n.y+h/d-f)*h)/(o*l-a*h);i=p+o*m-t.x,s=f+a*m-t.y;const y=i*i+s*s;if(y<=2)return new N(i,s);r=Math.sqrt(y/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(l)&&(t=!0),t?(i=-a,s=o,r=Math.sqrt(c)):(i=o,s=a,r=Math.sqrt(c/2))}return new N(i/r,s/r)}const D=[];for(let e=0,n=L.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),D[e]=j(L[e],L[i],L[s]);const F=[];let I,W,H=D.concat();for(let e=0,n=k;e<n;e++){const t=P[e];I=[];for(let e=0,n=t.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),I[e]=j(t[e],t[i],t[s]);F.push(I),H=H.concat(I)}if(0===g)W=V.triangulateShape(L,P);else{const t=[],e=[];for(let n=0;n<g;n++){const i=n/g,s=p*Math.cos(i*Math.PI/2),r=f*Math.sin(i*Math.PI/2)+m;for(let e=0,n=L.length;e<n;e++){const n=R(L[e],D[e],r);G(n.x,n.y,-s),0===i&&t.push(n)}for(let t=0,n=k;t<n;t++){const n=P[t];I=F[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=R(n[t],I[t],r);G(e.x,e.y,-s),0===i&&o.push(e)}0===i&&e.push(o)}}W=V.triangulateShape(t,e)}const q=W.length,Z=f+m;for(let e=0;e<U;e++){const t=d?R(O[e],H[e],Z):O[e];z?(T.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),C.copy(M[0]).add(T).add(A),G(C.x,C.y,C.z)):G(t.x,t.y,0)}for(let e=1;e<=c;e++)for(let t=0;t<U;t++){const n=d?R(O[t],H[t],Z):O[t];z?(T.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),C.copy(M[e]).add(T).add(A),G(C.x,C.y,C.z)):G(n.x,n.y,u/c*e)}for(let e=g-1;e>=0;e--){const t=e/g,n=p*Math.cos(t*Math.PI/2),i=f*Math.sin(t*Math.PI/2)+m;for(let e=0,s=L.length;e<s;e++){const t=R(L[e],D[e],i);G(t.x,t.y,u+n)}for(let e=0,s=P.length;e<s;e++){const t=P[e];I=F[e];for(let e=0,s=t.length;e<s;e++){const s=R(t[e],I[e],i);z?G(s.x,s.y+M[c-1].y,M[c-1].x+n):G(s.x,s.y,u+n)}}}function Y(t,e){let n=t.length;for(;--n>=0;){const i=n;let s=n-1;s<0&&(s=t.length-1);for(let t=0,n=c+2*g;t<n;t++){const n=U*t,r=U*(t+1);$(e+i+n,e+s+n,e+s+r,e+i+r)}}}function G(t,e,n){h.push(t),h.push(e),h.push(n)}function X(t,e,s){J(t),J(e),J(s);const r=i.length/3,o=b.generateTopUV(n,i,r-3,r-2,r-1);K(o[0]),K(o[1]),K(o[2])}function $(t,e,s,r){J(t),J(e),J(r),J(e),J(s),J(r);const o=i.length/3,a=b.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);K(a[0]),K(a[1]),K(a[3]),K(a[1]),K(a[2]),K(a[3])}function J(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function K(t){s.push(t.x),s.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=U*t;if(w)for(let n=0;n<q;n++){const t=W[n];X(t[2]+e,t[1]+e,t[0]+e)}if(t=c+2*g,e=U*t,v)for(let n=0;n<q;n++){const t=W[n];X(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<q;t++){const e=W[t];X(e[2],e[1],e[0])}if(v)for(let t=0;t<q;t++){const e=W[t];X(e[0]+U*c,e[1]+U*c,e[2]+U*c)}}n.addGroup(t,i.length/3-t,0)}(),_&&function(){const t=i.length/3;let e=0;Y(L,e),e+=L.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];Y(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new A(i,3)),this.setAttribute("uv",new A(s,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,n){if(n.shapes=[],Array.isArray(t))for(let i=0,s=t.length;i<s;i++){const e=t[i];n.shapes.push(e.uuid)}else n.shapes.push(t.uuid);n.options=Object.assign({},e),void 0!==e.extrudePath&&(n.options.extrudePath=e.extrudePath.toJSON());return n}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const n=[];for(let s=0,r=t.shapes.length;s<r;s++){const i=e[t.shapes[s]];n.push(i)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new Gn[i.type]).fromJSON(i)),new Xn(n,t.options)}}const $n={generateTopUV:function(t,e,n,i,s){const r=e[3*n],o=e[3*n+1],a=e[3*i],h=e[3*i+1],l=e[3*s],c=e[3*s+1];return[new N(r,o),new N(a,h),new N(l,c)]},generateSideWallUV:function(t,e,n,i,s,r){const o=e[3*n],a=e[3*n+1],h=e[3*n+2],l=e[3*i],c=e[3*i+1],u=e[3*i+2],d=e[3*s],p=e[3*s+1],f=e[3*s+2],m=e[3*r],y=e[3*r+1],g=e[3*r+2];return Math.abs(a-c)<Math.abs(o-l)?[new N(o,1-h),new N(l,1-u),new N(d,1-f),new N(m,1-g)]:[new N(a,1-h),new N(c,1-u),new N(p,1-f),new N(y,1-g)]}};class Jn extends Xn{constructor(t,e){super(t,e);const n=new ze(new Xn(t,l(h({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new B).setFromObject(n),s=new y;i.getSize(s);const r=new y(i.min.x+s.x/2,i.min.y+s.y/2,0);let o=e.topSegments,a=e.box3;if(a){a=a.union(i);const t=new y;a.getSize(t);const n=Math.max(s.x/t.x,s.y/t.y);o=Math.ceil(e.topSegments*n)}if(o<4)return this;const c=new Q(s.x,s.y,o,o),u=new ze(c);u.position.set(r.x,r.y,r.z),u.updateMatrixWorld();const d=(new Ee).evaluate(u,n,Oe),p=d.geometry.getAttribute("position"),f=new A(2*p.count,2);for(let h=0;h<p.count;h++){const t=p.getZ(h);p.setZ(h,e.depth+t)}if(a){const t=a.min,e=a.max,n=(new y).subVectors(e,t);for(let i=0;i<p.count;i++){const e=p.getX(i),s=p.getY(i),r=(e-t.x)/n.x,o=(s-t.y)/n.y;f.setXY(i,r,o)}d.geometry.setAttribute("uv",f)}p.needsUpdate=!0;const m=new Xn(t,l(h({},e),{hasTop:!1})),g=Rn([d.geometry,m],2);this.copy(g.toNonIndexed())}}const Kn=t=>{const{split:e,depth:n,points:i,box3:s,hasTop:r,hasBottom:o,hasSide:a,sideRepeat:h,topSegments:l}=t,c=new(l?Jn:Xn)(new I(i),{depth:n,bevelEnabled:!1,box3:s,UVGenerator:On({split:e,box3:s,sideRepeat:h}),hasTop:r,hasBottom:o,hasSide:a,topSegments:l});return Pn(),c};class Qn extends Ln{constructor(t){super(),u(this,"options"),this.options=h({depth:1},t)}create(){return d(this,null,function*(){const{points:t,pointsArr:e,useGroups:n,depth:i,geometry:s,geometryArr:r,material:o,box3:a,split:h,hasTop:l,hasBottom:c,hasSide:u}=this.options,d=Array.isArray(i)?i:[i],p=Array.isArray(a)?a:[a],f=o;let m=s;f||console.log("material is null"),!m&&t?m=Kn({points:t,depth:d[0],box3:p[0],split:h,hasTop:l,hasBottom:c,hasSide:u}):!m&&e?m=Rn(e.map((t,e)=>{var n,i;return Kn({points:t,depth:null!=(n=d[e])?n:d[0],box3:null!=(i=p[e])?i:p[0],split:h,hasTop:l,hasBottom:c,hasSide:u})}),null!=n?n:0):!m&&r&&r.length>1?m=Rn(r,null!=n?n:0):!m&&r&&1===r.length&&([m]=r),this.createMesh(m,f)})}addGeometries(t){const e=this.object3d,n=Rn([e.geometry,...t]);e.geometry=n}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const ti=t=>{const{topColor:e,sideColor:n,sideMap:i,createCanvasObjectURL:s,split:r,maxAnisotropy:o}=t;return new Promise(t=>{const o=i?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};o.onload=()=>{const a=r,h=document.createElement("canvas"),l=h.getContext("2d");h.height=o.height/(1-a),h.width=o.width,a&&e&&(l.fillStyle=e,l.fillRect(0,0,o.width,h.height*a)),i&&o instanceof HTMLImageElement?l.drawImage(o,0,h.height*a,o.width,o.height):n&&(l.fillStyle=n,l.fillRect(0,h.height*a,o.width,o.height)),s&&h.toBlob(t=>{console.log(URL.createObjectURL(t))});const c=new tt(h);t(c)},i?o.src=i:o instanceof HTMLImageElement||o.onload()})};class ei extends Ln{create(){this.createGroup()}render(){this.object3d.raycast=(t,e)=>t.intersectObjects(this.object3d.children,!0,e)}}class ni extends Ln{constructor(t){super(),u(this,"options"),u(this,"directionalLight"),u(this,"spotLight"),u(this,"pointLight"),u(this,"hemisphereLight"),u(this,"rectAreaLight"),u(this,"rectAreaLightUniformsLibInit",!1),this.options=t}create(){var t,e,n,i,s,r,o,a,h,l,c,u,d,p,f,m,y;const g=this.options;if("AmbientLight"===g.type){const t=new et(g.color);t.name="环境光",this.object3d=t}else if("DirectionalLight"===g.type){const t=new nt(g.color,g.intensity);t.name="平行光",t.target.position.set(0,0,0),this.object3d=t,t.target.name="平行光目标",t.shadow.camera.name="平行光阴影相机",t.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=t}else if("PointLight"===g.type){const s=new it(null!=(t=g.color)?t:16777215,null!=(e=g.intensity)?e:1,null!=(n=g.distance)?n:0,null!=(i=g.decay)?i:2);s.name="点光源",this.object3d=s,this.pointLight=s}else if("SpotLight"===g.type){const t=new st(null!=(s=g.color)?s:16777215,null!=(r=g.intensity)?r:1,null!=(o=g.distance)?o:0,null!=(a=g.angle)?a:Math.PI/3,null!=(h=g.penumbra)?h:1,null!=(l=g.decay)?l:2);t.name="聚光灯",this.object3d=t,this.spotLight=t,t.target.name="聚光灯目标"}else if("HemisphereLight"===g.type){const t=new rt(null!=(c=g.color)?c:16777215,null!=(u=g.groundColor)?u:16777215,null!=(d=g.intensity)?d:1);t.name="半球光",this.object3d=t,this.hemisphereLight=t}else if("RectAreaLight"===g.type){this.rectAreaLightUniformsLibInit||(Pe.init(),this.rectAreaLightUniformsLibInit=!0);const t=new ot(null!=(p=g.color)?p:16777215,null!=(f=g.intensity)?f:1,null!=(m=g.width)?m:10,null!=(y=g.height)?y:10);t.name="矩形区域光",this.object3d=t,this.rectAreaLight=t}}render(){const t=this.object3d;t.target&&this.pencil.scene.add(t.target);const e=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const t=this.spotLight||this.directionalLight;t.position.copy(e),t.target.position.copy(e)}else if(this.pointLight){this.pointLight.position.copy(e)}}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}class ii extends S{constructor(t=[],e="none",n){super(),u(this,"type","MeshLineGeometry"),u(this,"pointCount",0),u(this,"_points",[]),u(this,"shape","none"),u(this,"shapeFunction",t=>1),u(this,"matrixWorld",new g),this.shape=e,n&&(this.shapeFunction=n),t.length>0&&this.setPoints(t)}convertToVector3Array(t){if("number"==typeof t[0]){const e=[],n=t;for(let t=0;t<n.length;t+=3)e.push(new y(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof N?new y(t.x,t.y,0):t instanceof y?t:Array.isArray(t)&&2===t.length?new y(t[0],t[1],0):Array.isArray(t)&&3===t.length?new y(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n=!1){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry(n))}initializeGeometry(){const t=new D(new Float32Array(6*this.pointCount),3),e=new D(new Float32Array(6*this.pointCount),3),n=new D(new Float32Array(6*this.pointCount),3),i=new D(new Float32Array(2*this.pointCount),1),s=new D(new Float32Array(2*this.pointCount),1),r=new D(new Float32Array(2*this.pointCount),1),a=new D(new Float32Array(4*this.pointCount),2),h=new D(new Uint16Array(6*(this.pointCount-1)),1);"taper"===this.shape&&(this.shapeFunction=t=>1*o(4*t*(1-t),1));for(let o=0,l=0,c=0;o<this.pointCount;o+=1,l+=2,c+=6){i.setX(l,o/this.pointCount),i.setX(l+1,o/this.pointCount),s.setX(l,1),s.setX(l+1,-1);const t="none"===this.shape?1:this.shapeFunction(o/(this.pointCount-1));r.setX(l,t),r.setX(l+1,t);const e=o/(this.pointCount-1);if(a.setXY(l,e,0),a.setXY(l+1,e,1),o<this.pointCount-1){const t=2*o;h.setX(c+0,t+0),h.setX(c+1,t+1),h.setX(c+2,t+2),h.setX(c+3,t+2),h.setX(c+4,t+1),h.setX(c+5,t+3)}}this.setAttribute("position",t),this.setAttribute("previous",e),this.setAttribute("next",n),this.setAttribute("counters",i),this.setAttribute("side",s),this.setAttribute("width",r),this.setAttribute("uv",a),this.setIndex(h)}updateGeometry(t=!1){var e,n,i,s,r,o,a,h,l,c;if(!this._points[0])return;const u=this.getAttribute("position"),d=this.getAttribute("previous"),p=this.getAttribute("next");t&&(this.userData.rtcPositionsVertices=new D(new Float64Array(3*u.count),3),this.userData.rtcPreviousVertices=new D(new Float64Array(3*d.count),3),this.userData.rtcNextVertices=new D(new Float64Array(3*p.count),3));let f=0,m=0,y=0;const g=this._points[0];d.setXYZ(m,g.x,g.y,g.z),null==(e=this.userData.rtcPreviousVertices)||e.setXYZ(m,g.x,g.y,g.z),m+=1,d.setXYZ(m,g.x,g.y,g.z),null==(n=this.userData.rtcPreviousVertices)||n.setXYZ(m,g.x,g.y,g.z),m+=1;for(let b=0;b<this.pointCount;b++){const t=this._points[b];u.setXYZ(f,t.x,t.y,t.z),null==(i=this.userData.rtcPositionsVertices)||i.setXYZ(f,t.x,t.y,t.z),f+=1,u.setXYZ(f,t.x,t.y,t.z),null==(s=this.userData.rtcPositionsVertices)||s.setXYZ(f,t.x,t.y,t.z),f+=1,b<this.pointCount-1&&(d.setXYZ(m,t.x,t.y,t.z),null==(r=this.userData.rtcPreviousVertices)||r.setXYZ(m,t.x,t.y,t.z),m+=1,d.setXYZ(m,t.x,t.y,t.z),null==(o=this.userData.rtcPreviousVertices)||o.setXYZ(m,t.x,t.y,t.z),m+=1),b>0&&b+1<=this.pointCount&&(p.setXYZ(y,t.x,t.y,t.z),null==(a=this.userData.rtcNextVertices)||a.setXYZ(y,t.x,t.y,t.z),y+=1,p.setXYZ(y,t.x,t.y,t.z),null==(h=this.userData.rtcNextVertices)||h.setXYZ(y,t.x,t.y,t.z),y+=1)}const x=this._points[this.pointCount-1];p.setXYZ(y,x.x,x.y,x.z),null==(l=this.userData.rtcNextVertices)||l.setXYZ(y,x.x,x.y,x.z),y+=1,p.setXYZ(y,x.x,x.y,x.z),null==(c=this.userData.rtcNextVertices)||c.setXYZ(y,x.x,x.y,x.z),y+=1,u.needsUpdate=!0,d.needsUpdate=!0,p.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(t){this.setPoints(t)}updatePoints(t,e){const n=this.convertToVector3Array(t);n.length===this.pointCount?(this._points=n,e&&(this.shapeFunction=e,this.shape="custom",this.initializeGeometry()),this.updateGeometry()):console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.")}setShape(t,e){this.shape=t,e&&(this.shapeFunction=e),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function si(t=!1){return(t?"#define USE_RTC\n":"")+"\n #include <common>\n #include <logdepthbuf_pars_vertex>\n #include <fog_pars_vertex>\n\n attribute vec3 previous;\n attribute vec3 next;\n attribute float side;\n attribute float width;\n attribute float counters;\n\n // RTC 相关定义 \n #ifdef USE_RTC\n attribute vec3 localCenter;\n uniform vec3 globalRTCCenter;\n uniform vec3 rtcCenter;\n uniform float uRTCMode; // 0.0: None, 1.0: Simple, 2.0: Multi-Level\n #endif\n\n uniform vec2 resolution;\n uniform float lineWidth;\n uniform vec3 color;\n uniform float opacity;\n uniform float sizeAttenuation;\n uniform float scaleDown;\n uniform vec2 offset;\n\n varying vec2 vUV;\n varying vec4 vColor;\n varying float vCounters;\n\n vec2 intoScreen(vec4 i) {\n return resolution * (0.5 * i.xy / i.w + 0.5);\n }\n\n void main() {\n float aspect = resolution.y / resolution.x;\n\n vec3 worldPosition = position;\n vec3 worldPrevious = previous;\n vec3 worldNext = next;\n\n #ifdef USE_RTC\n if (uRTCMode == 1.0) {\n // Simple RTC\n worldPosition += rtcCenter;\n worldPrevious += rtcCenter;\n worldNext += rtcCenter;\n } else if (uRTCMode == 2.0) {\n // Multi-Level RTC\n worldPosition += localCenter + globalRTCCenter;\n worldPrevious += localCenter + globalRTCCenter;\n worldNext += localCenter + globalRTCCenter;\n }\n #endif\n\n mat4 m = projectionMatrix * modelViewMatrix;\n\n vec4 currentClip = m * vec4( worldPosition, 1.0 );\n vec4 prevClip = m * vec4( worldPrevious, 1.0 );\n vec4 nextClip = m * vec4( worldNext, 1.0 );\n\n vec4 currentNormed = currentClip / currentClip.w;\n vec4 prevNormed = prevClip / prevClip.w;\n vec4 nextNormed = nextClip / nextClip.w;\n\n vec2 currentScreen = intoScreen(currentNormed);\n vec2 prevScreen = intoScreen(prevNormed);\n vec2 nextScreen = intoScreen(nextNormed);\n\n float actualWidth = lineWidth * width;\n\n vec2 dir;\n if(nextScreen == currentScreen) {\n dir = normalize( currentScreen - prevScreen );\n } else if(prevScreen == currentScreen) {\n dir = normalize( nextScreen - currentScreen );\n } else {\n vec2 inDir = currentScreen - prevScreen;\n vec2 outDir = nextScreen - currentScreen;\n vec2 fullDir = nextScreen - prevScreen;\n\n if(length(fullDir) > 0.0) {\n dir = normalize(fullDir);\n } else if(length(inDir) > 0.0){\n dir = normalize(inDir);\n } else {\n dir = normalize(outDir);\n }\n }\n\n vec2 normal = vec2(-dir.y, dir.x);\n\n if(sizeAttenuation != 0.0) {\n normal /= currentClip.w;\n normal *= min(resolution.x, resolution.y);\n }\n\n if (scaleDown > 0.0) {\n float dist = length(nextNormed - prevNormed);\n normal *= smoothstep(0.0, scaleDown, dist);\n }\n\n vec2 offsetInScreen = actualWidth * normal * side * 0.5;\n\n vec2 withOffsetScreen = currentScreen + offsetInScreen;\n vec3 withOffsetNormed = vec3((2.0 * withOffsetScreen/resolution - 1.0), currentNormed.z);\n\n vCounters = counters;\n vColor = vec4( color, opacity );\n vUV = uv;\n vUV=uv+offset;\n\n gl_Position = currentClip.w * vec4(withOffsetNormed, 1.0);\n\n #include <logdepthbuf_vertex>\n #include <fog_vertex>\n }\n"}class ri extends at{constructor(t={}){const e=t,{lineWidth:n=1,color:i="#ffffff",opacity:s=1,map:r=null,dashOffset:o=0,dashArray:a=0,dashRatio:d=.5,sizeAttenuation:p=!0,offsetLoop:f=!0,offset:m=new N(0,0),scaleDown:g=0,alphaMap:x,alphaTest:b=0,repeat:v=new N(1,1),resolution:w=new N(1,1),useRTC:_=!1}=e,M=c(e,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution","useRTC"]);super(l(h({},M),{uniforms:{lineWidth:{value:n},color:{value:new ht(i)},opacity:{value:s},map:{value:r},useMap:{value:r?1:0},resolution:{value:w},sizeAttenuation:{value:p?1:0},offset:{value:m},offsetLoop:{value:f?1:0},dashArray:{value:a},dashOffset:{value:o},dashRatio:{value:d},useDash:{value:a>0?1:0},scaleDown:{value:g/10},alphaTest:{value:b},alphaMap:{value:x},useAlphaMap:{value:x?1:0},repeat:{value:v},uRTCMode:{value:0},globalRTCCenter:{value:new y(0,0,0)}},vertexShader:si(_),fragmentShader:"\n #include <fog_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n\nuniform float useDash;\nuniform float dashArray;\nuniform float dashOffset;\nuniform float dashRatio;\nuniform sampler2D alphaMap;\nuniform float useAlphaMap;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying float vCounters;\n\nuniform sampler2D map;\nuniform float useMap;\nuniform vec2 repeat;\nuniform float offsetLoop;\nuniform float alphaTest;\n\n\n\nvoid main()\t{\n\t#include <logdepthbuf_fragment>\n\n\tvec4 c = vColor;\n\n\tif( useMap == 1. ) c *= texture2D( map, vUV * repeat );\n\tif( useAlphaMap == 1. ) c.a *= texture2D( alphaMap, vUV * repeat ).r;\n\tif(offsetLoop!=1.0){\n if(vUV.x>1.0 || vUV.x<0.0){\n c.a = 0.0;\n }\n }\n if (c.a < alphaTest) discard;\n\tif( useDash == 1. ){\n\t\t\tc.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));\n\t}\n\tgl_FragColor = c;\n \t#include <fog_fragment>\n #include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}\n"})),u(this,"type","MeshLineMaterial")}get color(){return this.uniforms.color.value}set color(t){this.uniforms.color.value=new ht(t)}get opacity(){var t;return(null==(t=this.uniforms)?void 0:t.opacity.value)||1}set opacity(t){this.uniforms&&(this.uniforms.opacity.value=t)}get alphaTest(){return this.uniforms.alphaTest.value}set alphaTest(t){this.uniforms&&(this.uniforms.alphaTest.value=t)}get map(){return this.uniforms.map.value}set map(t){this.uniforms.map.value=t,this.uniforms.useMap.value=t?1:0}get repeat(){return this.uniforms.repeat.value}set repeat(t){this.uniforms.repeat.value.copy(t)}get lineWidth(){return this.uniforms.lineWidth.value}set lineWidth(t){this.uniforms.lineWidth.value=t}get sizeAttenuation(){return 1===this.uniforms.sizeAttenuation.value}set sizeAttenuation(t){this.uniforms.sizeAttenuation.value=t?1:0}}function oi(t,e){const n=new g,i=new M,s=new _,r=new y,o=this.geometry;if(s.copy(o.boundingSphere),s.applyMatrix4(this.matrixWorld),!t.ray.intersectSphere(s,r))return;n.copy(this.matrixWorld).invert(),i.copy(t.ray).applyMatrix4(n);const a=new y,h=new y,l=new y,c=this instanceof lt?2:1,u=o.index,d=o.attributes;if(null!==u){const n=u.array,s=d.position.array,o=d.width.array;for(let u=0,d=n.length-1;u<d;u+=c){const c=n[u],p=n[u+1];a.fromArray(s,3*c),h.fromArray(s,3*p);const f=void 0!==o[Math.floor(u/3)]?o[Math.floor(u/3)]:1,m=t.params.Line.threshold+this.material.lineWidth*f/2,y=m*m;if(i.distanceSqToSegment(a,h,r,l)>y)continue;r.applyMatrix4(this.matrixWorld);const g=t.ray.origin.distanceTo(r);g<t.near||g>t.far||(e.push({distance:g,point:l.clone().applyMatrix4(this.matrixWorld),index:u,face:null,faceIndex:void 0,object:this}),u=d)}}}const ai=t=>{var e;const{setPointWidth:n,nodes:i}=t,s=new ii;return s.setPoints(i,n,null!=(e=t.resetCenter)&&e),s},hi=/* @__PURE__ */new WeakMap,li=/* @__PURE__ */new Map;let ci=class extends Ln{constructor(t={}){super(),u(this,"options"),this.options=h({},t)}get material(){var t;return null==(t=this.object3d)?void 0:t.material}create(){return d(this,null,function*(){const{nodes:t,nodesArr:e,geometry:n,geometryArr:i,material:s,useGroups:r,setPointWidth:o,lineWidthArr:a,materialParameters:h}=this.options;let l=s,c=n;!l&&h&&(l=this.getMaterial(h)),!c&&t?c=ai({nodes:t,setPointWidth:o}):!c&&e?c=Rn(e.map((t,e)=>{let n=o;return!n&&a&&(n=()=>{var t;return null!=(t=a[e])?t:a[0]}),ai({nodes:t,setPointWidth:n})}),null!=r?r:0):!c&&i&&i.length>1?c=Rn(i,null!=r?r:0):!c&&i&&1===i.length&&([c]=i),this.createMesh(c,l)})}setGeometry(t,e){const n=ai({nodes:t,setPointWidth:e}),i=this.object3d,s=i.geometry;i.geometry=n,s.dispose()}getMaterial(t){const{width:e,height:n}=this.pencil.getSize(),i=new ri(h({color:new ht("#ffffff")},t));return i.uniforms.resolution.value.set(e,n),i}addGeometries(t){const e=this.object3d,n=Rn([e.geometry,...t]);e.geometry=n}resize(t,e){var n,i;null==(i=null==(n=this.material)?void 0:n.uniforms)||i.resolution.value.set(t,e)}handleMaterialChange(t){if(t){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}}animate({duration:t=1e3,delay:e=0,repeat:n=0,lineLoop:i,onRepeat:s,onUpdate:r,onComplete:o,startShow:a}={}){const{offset:h,offsetLoop:l}=this.material.uniforms,c=this.pencil.userData.debugLine?li:hi;if(c.get(this.material)&&this.stopAnimation(),0===t)return;const u=null==i||i;h.value.x=1,l.value=u&&a?1:0;let d=0;const p=new Vt.Tween(h.value).to({x:-1},t).delay(e).repeat(n).onUpdate(({x:t})=>{u&&t<=0&&0===l.value&&(l.value=1),null==r||r(t)}).onRepeat(()=>{d+=1,null==s||s(d)}).onComplete(()=>{null==o||o()}).start();c.set(this.material,p),this.material.addEventListener("dispose",()=>{this.stopAnimation()}),this.pencil.userData.debugLine&&console.log("animate",li.size)}stopAnimation(){const t=this.pencil.userData.debugLine?li:hi,e=t.get(this.material);e&&(e.stop(),Vt.remove(e),t.delete(this.material),this.material.uniforms.offset.value.x=0,this.material.uniforms.offsetLoop.value=1),this.pencil.userData.debugLine&&console.log("stopAnimation",li.size)}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}};const ui=t=>{const{points:e}=t,n=e.reduce((t,n,i)=>(i<e.length-1&&t.push(n,e[i+1]),t),[]);return(new S).setFromPoints(n)},di=new ct,pi=new y,fi=new y,mi=new ct,yi=new ct,gi=new ct,xi=new y,bi=new g,vi=new ut,wi=new y,_i=new B,Mi=new _,Si=new ct;let Ai,Ti;function Ci(t,e,n){return Si.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),Si.multiplyScalar(1/Si.w),Si.x=Ti/n.width,Si.y=Ti/n.height,Si.applyMatrix4(t.projectionMatrixInverse),Si.multiplyScalar(1/Si.w),Math.abs(Math.max(Si.x,Si.y))}class zi extends U{constructor(t=new Be,e){super(t,e),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const t=this.geometry,e=t.attributes.instanceStart,n=t.attributes.instanceEnd,i=new Float32Array(2*e.count);for(let r=0,o=0,a=e.count;r<a;r++,o+=2)pi.fromBufferAttribute(e,r),fi.fromBufferAttribute(n,r),i[o]=0===o?0:i[o-1],i[o+1]=i[o]+pi.distanceTo(fi);const s=new dt(i,2,1);return t.setAttribute("instanceDistanceStart",new pt(s,1,0)),t.setAttribute("instanceDistanceEnd",new pt(s,1,1)),this}raycast(t,e){const n=this.material.worldUnits,i=t.camera;null!==i||n||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const s=void 0!==t.params.Line2&&t.params.Line2.threshold||0;Ai=t.ray;const r=this.matrixWorld,o=this.geometry,a=this.material;let h,l;if(Ti=a.linewidth+s,null===o.boundingSphere&&o.computeBoundingSphere(),Mi.copy(o.boundingSphere).applyMatrix4(r),n)h=.5*Ti;else{h=Ci(i,Math.max(i.near,Mi.distanceToPoint(Ai.origin)),a.resolution)}if(Mi.radius+=h,!1!==Ai.intersectsSphere(Mi)){if(null===o.boundingBox&&o.computeBoundingBox(),_i.copy(o.boundingBox).applyMatrix4(r),n)l=.5*Ti;else{l=Ci(i,Math.max(i.near,_i.distanceToPoint(Ai.origin)),a.resolution)}_i.expandByScalar(l),!1!==Ai.intersectsBox(_i)&&(n?function(t,e){const n=t.matrixWorld,i=t.geometry,s=i.attributes.instanceStart,r=i.attributes.instanceEnd;for(let o=0,a=Math.min(i.instanceCount,s.count);o<a;o++){vi.start.fromBufferAttribute(s,o),vi.end.fromBufferAttribute(r,o),vi.applyMatrix4(n);const i=new y,a=new y;Ai.distanceSqToSegment(vi.start,vi.end,a,i),a.distanceTo(i)<.5*Ti&&e.push({point:a,pointOnLine:i,distance:Ai.origin.distanceTo(a),object:t,face:null,faceIndex:o,uv:null,uv1:null})}}(this,e):function(t,e,n){const i=e.projectionMatrix,s=t.material.resolution,r=t.matrixWorld,o=t.geometry,a=o.attributes.instanceStart,h=o.attributes.instanceEnd,l=Math.min(o.instanceCount,a.count),c=-e.near;Ai.at(1,gi),gi.w=1,gi.applyMatrix4(e.matrixWorldInverse),gi.applyMatrix4(i),gi.multiplyScalar(1/gi.w),gi.x*=s.x/2,gi.y*=s.y/2,gi.z=0,xi.copy(gi),bi.multiplyMatrices(e.matrixWorldInverse,r);for(let u=0,d=l;u<d;u++){if(mi.fromBufferAttribute(a,u),yi.fromBufferAttribute(h,u),mi.w=1,yi.w=1,mi.applyMatrix4(bi),yi.applyMatrix4(bi),mi.z>c&&yi.z>c)continue;if(mi.z>c){const t=mi.z-yi.z,e=(mi.z-c)/t;mi.lerp(yi,e)}else if(yi.z>c){const t=yi.z-mi.z,e=(yi.z-c)/t;yi.lerp(mi,e)}mi.applyMatrix4(i),yi.applyMatrix4(i),mi.multiplyScalar(1/mi.w),yi.multiplyScalar(1/yi.w),mi.x*=s.x/2,mi.y*=s.y/2,yi.x*=s.x/2,yi.y*=s.y/2,vi.start.copy(mi),vi.start.z=0,vi.end.copy(yi),vi.end.z=0;const e=vi.closestPointToPointParameter(xi,!0);vi.at(e,wi);const o=P.lerp(mi.z,yi.z,e),l=o>=-1&&o<=1,d=xi.distanceTo(wi)<.5*Ti;if(l&&d){vi.start.fromBufferAttribute(a,u),vi.end.fromBufferAttribute(h,u),vi.start.applyMatrix4(r),vi.end.applyMatrix4(r);const e=new y,i=new y;Ai.distanceSqToSegment(vi.start,vi.end,i,e),n.push({point:i,pointOnLine:e,distance:Ai.origin.distanceTo(i),object:t,face:null,faceIndex:u,uv:null,uv1:null})}}}(this,i,e))}}onBeforeRender(t){const e=this.material.uniforms;e&&e.resolution&&(t.getViewport(di),this.material.uniforms.resolution.value.set(di.z,di.w))}}class Ei extends Ln{constructor(t={}){super(),u(this,"options"),this.options=h({},t)}get material(){var t;return null==(t=this.object3d)?void 0:t.material}create(){return d(this,null,function*(){const{points:t,pointsArr:e,geometry:n,geometryArr:i,material:s,useGroups:r,setPointWidth:o,lineWidthArr:a,materialParameters:h,instanceCount:l}=this.options;let c=s,u=n;!c&&h&&(c=this.getMaterial(h)),!u&&t?u=ui({points:t}):!u&&e?u=Rn(e.map(t=>ui({points:t})),null!=r?r:0):!u&&i&&i.length>1?u=Rn(i,null!=r?r:0):!u&&i&&1===i.length&&([u]=i);const d=(new Xt).fromLineSegments(new lt(u));if(this.pencil.options.WebGPUTHREE){l&&(d.instanceCount=l);const t=new zi(d,c);t.computeLineDistances(),this.object3d=t}else{const t=new Ne(d,c);t.computeLineDistances(),this.object3d=t}})}getMaterial(t){return new Yt(h({color:new ht("#ffffff")},t))}}const Oi=class t extends Ln{constructor(t){super(),u(this,"objectType","Node"),u(this,"options"),u(this,"pickObject"),u(this,"element"),u(this,"onNodePointerIndex",[]),this.options=h(h({},{type:"2d"}),t)}create(){const{position:t,children:e}=this.options,n=document.createElement("div");this.element=n,e&&n.appendChild(e),"3d"===this.options.type?this.createCSS3DObject(n):"3dSprite"===this.options.type?this.createCSS3DSprite(n):this.createCSS2DObject(n),t&&this.object3d.position.copy(t)}trackCollision(t=0){var e;null==(e=this.pencil.cssRendererController)||e.collisionManager.add(this,{priority:t})}untrackCollision(){var t;null==(t=this.pencil.cssRendererController)||t.collisionManager.remove(this)}setChildren(t){this.options.children=t,this.element.innerHTML="",this.element.appendChild(t)}showAndEnsureVisible(){const t=this.options.children;t&&(t.style.visibility="hidden",this.show(),setTimeout(()=>{t.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const t=this.options.children;if(!t)return;const e=t.getBoundingClientRect(),n=window.innerWidth,i=window.innerHeight,s=e.width,r=e.height;let o=0,a=0;s>n?e.left>0&&(o=-e.left):e.left<0?o=-e.left:e.right>n&&(o=n-e.right,e.left+o<0&&(o=-e.left)),r>i?e.top>0&&(a=-e.top):e.top<0?a=-e.top:e.bottom>i&&(a=i-e.bottom,e.top+a<0&&(a=-e.top)),0===o&&0===a||(t.style.transform=`translate(${o}px, ${a}px)`)}ensureVisible(){const e=this.options.children;e&&(e.style.transform&&(e.style.transform=""),t.observerMap.has(e)||(t.sharedObserver||(t.sharedObserver=new IntersectionObserver(e=>{e.forEach(e=>{const n=e.target,i=t.observerMap.get(n);i&&e.isIntersecting&&(i.moveElementToViewport(),t.observerMap.delete(n),t.sharedObserver&&(t.sharedObserver.unobserve(n),0===t.observerMap.size&&(t.sharedObserver.disconnect(),t.sharedObserver=void 0)))})})),t.observerMap.set(e,this),t.sharedObserver.observe(e)))}onPointerEvent(t,e){const n=this.lead.handlePickNode([this],t,e);this.onNodePointerIndex.push(n)}dispose(){this.untrackCollision();const e=this.options.children;e&&t.sharedObserver&&(t.observerMap.delete(e),t.sharedObserver.unobserve(e),0===t.observerMap.size&&(t.sharedObserver.disconnect(),t.sharedObserver=void 0)),this.onNodePointerIndex.forEach(t=>{this.lead.removePickNode(t)}),super.dispose()}};u(Oi,"sharedObserver"),u(Oi,"observerMap",/* @__PURE__ */new Map);let Pi=Oi;class Ni extends Ln{constructor(t){super(),u(this,"options"),this.options=h({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return d(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:n,material:i,percentDepth:s,activeIndex:r}=this.options,o=Math.max(...t),a=t.reduce((t,e)=>t+e,0);let h=Math.PI/2;t.forEach((t,r)=>{if(0===t)return;const l=2*Math.PI*(t/a),c=n[r],u=s?e*(t/o):e,d=this.createGeometry(u,l),p=i?i.clone():new ft({color:c});i&&p.color.set(c);const f=new U(d,p);f.userData.depth=u,f.userData.index=r,f.rotateZ(h),h+=l,this.add(f)}),-1!==r&&this.setActive(r)})}createGeometry(t,e){const{outRadius:n,innerRadius:i}=this.options,s=new I;s.moveTo(n,0),s.lineTo(i,0),s.absarc(0,0,i,0,e,!1),s.absarc(0,0,n,e,0,!0);return new Xn(s,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:n}=this.pencil.pick(t,this.object3d.children)||{},i=n?this.object3d.children.findIndex(t=>t===n):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const n=this.object3d.children[t];if(this.object3d.children.forEach(t=>{if((!n||n!==t)&&1!==t.scale.z){if(t.userData.levTween)return;t.userData.enTween&&(t.userData.enTween.stop(),t.userData.enTween=null);const e=new Vt.Tween(t.scale).to({z:1},100);t.userData.levTween=e,e.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const t=new Vt.Tween(n.scale).to({z:e},100);return n.userData.enTween=t,t.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new Vt.Tween(this.object3d.scale).to({z:1},1e3).easing(Vt.Easing.Sinusoidal.InOut).start()}}const Bi={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:"\n\t\tprecision highp float;\n\n\t\tuniform mat4 modelViewMatrix;\n\t\tuniform mat4 projectionMatrix;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\t\n\t\tprecision highp float;\n\n\t\tuniform sampler2D tDiffuse;\n uniform float premultiplieAlpha;\n\n\t\t#include <tonemapping_pars_fragment>\n\t\t#include <colorspace_pars_fragment>\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tgl_FragColor = texture2D( tDiffuse, vUv );\n\n if (premultiplieAlpha == 1.0) {\n gl_FragColor.rgb *= gl_FragColor.a;\n } \n\n\t\t\t// tone mapping\n\n\t\t\t#ifdef LINEAR_TONE_MAPPING\n\n\t\t\t\tgl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( REINHARD_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( CINEON_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( ACES_FILMIC_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( AGX_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( NEUTRAL_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( CUSTOM_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );\n\n\t\t\t#endif\n\n\t\t\t// color space\n\n\t\t\t#ifdef SRGB_TRANSFER\n\n\t\t\t\tgl_FragColor = sRGBTransferOETF( gl_FragColor );\n\n\t\t\t#endif\n\n\t\t}"};class ki extends Le{constructor(){super();const t=Bi;this.uniforms=mt.clone(t.uniforms),this.material=new yt({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad?this.fsQuad=new Re(this.material):this._fsQuad&&(this._fsQuad=new Re(this.material))}}const Li=new ft({color:"black"}),Ri=new T({color:"black",sizeAttenuation:!1}),Ui=new T({color:"black",sizeAttenuation:!0}),ji=new gt({color:"black",sizeAttenuation:!0}),Di=new gt({color:"black",sizeAttenuation:!1}),Fi=new ri({color:"black",sizeAttenuation:!1,lineWidth:0}),Ii=new ht(0);class Vi{constructor(t){u(this,"renderer"),u(this,"scene"),u(this,"camera"),u(this,"finalComposer"),u(this,"bloomComposer"),u(this,"bloomComposerActive",!1),u(this,"renderPass"),u(this,"outputPass"),u(this,"bloomPass"),u(this,"ssaoPass"),u(this,"mixPass"),u(this,"options"),u(this,"active",!0),u(this,"bloomSelection",/* @__PURE__ */new Set),u(this,"bloomLayer",new vt),u(this,"bloomMaterials",{}),u(this,"bloomVisible",{}),u(this,"bloomComposerRenderIng",!1),u(this,"pipViewportState",null),this.options=t;const{rendererController:e,sceneController:n,cameraController:i,composerParams:s}=t,{renderer:r}=e;this.renderer=r;const{multisampling:o}=s,{maxSamples:a}=r.capabilities,h=r.getDrawingBufferSize(new N),l=new xt(h.width,h.height,{samples:Math.min(o,a),type:bt}),c=new Wt(r,l),d=this.getSize();c.setSize(d.width,d.height);const p=new Ht(n.scene,i.camera);c.addPass(p),this.scene=n.scene,this.camera=i.camera,this.finalComposer=c,this.renderPass=p,i.event.on("pageChange",t=>{this.changeCamera(t)}),n.event.on("pageChange",t=>{this.changeScene(t)})}changeCamera(t){this.renderPass.camera=t,this.camera=t}changeScene(t){this.renderPass.scene=t,this.ssaoPass&&(this.ssaoPass.scene=t),this.scene=t}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new ki;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addSSAOPass(t){const{scene:e,camera:n,renderer:i}=this,s=i.getSize(new N),r=s.width,o=s.height,a=new qt(e,n,r,o);a.kernelRadius=t.kernelRadius,a.minDistance=t.minDistance,a.maxDistance=t.maxDistance,this.ssaoPass=a,this.finalComposer.addPass(a)}addBloomPass(t){const{renderer:e}=this,{threshold:n,strength:i,radius:s,bloomAlphaType:r}=t,o=new Zt(new N(window.innerWidth,window.innerHeight),i,s,n);this.bloomPass=o;const a=new Wt(e);a.renderToScreen=!1,a.addPass(this.renderPass),a.addPass(o),this.bloomComposer=a;const h=(t=>{const e=new ke(new at({uniforms:{baseTexture:{value:null},bloomTexture:{value:t.renderTarget2.texture},bloomAlphaType:{value:0}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n uniform float bloomAlphaType;\n varying vec2 vUv;\n void main() {\n vec4 base_color = texture2D(baseTexture, vUv);\n vec4 bloom_color = texture2D(bloomTexture, vUv);\n if (bloomAlphaType == 0.0){\n float lum = 0.21 * bloom_color.r + 0.71 * bloom_color.g + 0.07 * bloom_color.b;\n gl_FragColor = vec4(base_color.rgb + bloom_color.rgb, max(base_color.a, lum));\n }else{\n gl_FragColor = ( base_color + vec4( 1.0 ) * bloom_color );\n }\n }\n ",defines:{}}),"baseTexture");return e.needsSwap=!0,e})(a);h.uniforms.bloomAlphaType.value=r,this.bloomComposer=a,this.finalComposer.addPass(h),this.mixPass=h,this.bloomLayer.set(1)}checkBloomComposerActive(){0===this.bloomSelection.size?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var n;null==(n=this.bloomComposer)||n.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;null==(e=this.bloomComposer)||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=[],e=[];this.scene.children.forEach(n=>{n.isTransformControls||n.isTransformControlsRoot||"RectAreaLightHelper"===n.type?t.push(n):e.push(n)}),e.forEach(e=>{e.traverse(e=>{var n;const i=e,s=e,r=e;if(null==(n=i.material)?void 0:n.isShadowMaterial)t.push(i);else if(i.material&&!1===this.bloomLayer.test(i.layers)){if(!0===i.material.transparent&&(1!==i.material.opacity||i.material.alphaMap))return void t.push(i);this.bloomMaterials[i.uuid]=i.material,s.isSprite?s.material.sizeAttenuation?s.material=ji:s.material=Di:i.material instanceof ri?i.material=Fi:r.isPoints?r.material.sizeAttenuation?r.material=Ui:r.material=Ri:i.material=Li}})}),t.forEach(t=>{this.bloomVisible[t.uuid]=t.visible,t.visible=!1});const n=this.scene.background;n&&(this.scene.userData._backgroundOriginal=n,this.scene.background=Ii)}restoreNonBloomed(){if(this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]?(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid]):void 0!==this.bloomVisible[e.uuid]&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])}),this.scene.background===Ii){const t=this.scene.userData._backgroundOriginal;t&&(this.scene.background=t,delete this.scene.userData._backgroundOriginal)}}finalComposerRender(){this.bloomComposerActive&&this.bloomComposer?(this.bloomComposerRenderIng=!0,this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed(),this.bloomComposerRenderIng=!1):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render()}getSize(){return this.renderer.getSize(new N)}render(){if(!this.active)return;const{cameraController:t,rendererController:e,sceneController:n}=this.options;if(this.finalComposerRender(),this.pipViewportState){t.setPageActive(31),t.setAspect(this.pipViewportState.width/this.pipViewportState.height),e.setViewport(l(h({},this.pipViewportState),{scissor:!0,scissorTest:!0})),this.finalComposerRender(),t.setPageActive(n.activeIndex);const i=this.getSize();e.setViewport({x:0,y:0,width:i.width,height:i.height,scissor:!0,scissorTest:!1})}}dispose(){var t;this.bloomMaterials={},this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),null==(t=this.bloomComposer)||t.dispose()}}const Wi=1,Hi=2,qi=4,Zi=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768,SCREEN_PAN:65536,TOUCH_SCREEN_PAN:131072,TOUCH_DOLLY_SCREEN_PAN:262144,TOUCH_ZOOM_SCREEN_PAN:524288}),Yi=0,Gi=1,Xi=-1;function $i(t){return t.isPerspectiveCamera}function Ji(t){return t.isOrthographicCamera}const Ki=2*Math.PI,Qi=Math.PI/2,ts=Math.PI/180;function es(t,e,n){return Math.max(e,Math.min(n,t))}function ns(t,e=1e-5){return Math.abs(t)<e}function is(t,e,n=1e-5){return ns(t-e,n)}function ss(t,e){return Math.round(t/e)*e}function rs(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function os(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function as(t,e,n,i,s=1/0,r){const o=2/(i=Math.max(1e-4,i)),a=o*r,h=1/(1+a+.48*a*a+.235*a*a*a);let l=t-e;const c=e,u=s*i;l=es(l,-u,u),e=t-l;const d=(n.value+o*l)*r;n.value=(n.value-o*d)*h;let p=e+(l+d)*h;return c-t>0==p>c&&(p=c,n.value=(p-c)/r),p}function hs(t,e,n,i,s=1/0,r,o){const a=2/(i=Math.max(1e-4,i)),h=a*r,l=1/(1+h+.48*h*h+.235*h*h*h);let c=e.x,u=e.y,d=e.z,p=t.x-c,f=t.y-u,m=t.z-d;const y=c,g=u,x=d,b=s*i,v=p*p+f*f+m*m;if(v>b*b){const t=Math.sqrt(v);p=p/t*b,f=f/t*b,m=m/t*b}c=t.x-p,u=t.y-f,d=t.z-m;const w=(n.x+a*p)*r,_=(n.y+a*f)*r,M=(n.z+a*m)*r;n.x=(n.x-a*w)*l,n.y=(n.y-a*_)*l,n.z=(n.z-a*M)*l,o.x=c+(p+w)*l,o.y=u+(f+_)*l,o.z=d+(m+M)*l;const S=y-t.x,A=g-t.y,T=x-t.z;return S*(o.x-y)+A*(o.y-g)+T*(o.z-x)>0&&(o.x=y,o.y=g,o.z=x,n.x=(o.x-y)/r,n.y=(o.y-g)/r,n.z=(o.z-x)/r),o}function ls(t,e){e.set(0,0),t.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=t.length,e.y/=t.length}function cs(t,e){return!!Ji(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class us{constructor(){this._listeners={}}addEventListener(t,e){const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}removeAllEventListeners(t){t?Array.isArray(this._listeners[t])&&(this._listeners[t].length=0):this._listeners={}}dispatchEvent(t){const e=this._listeners[t.type];if(void 0!==e){t.target=this;const n=e.slice(0);for(let e=0,i=n.length;e<i;e++)n[e].call(this,t)}}}const ds=1/8,ps=/Mac/.test(navigator.platform);let fs,ms,ys,gs,xs,bs,vs,ws,_s,Ms,Ss,As,Ts,Cs,zs,Es,Os,Ps,Ns,Bs,ks,Ls,Rs;class Us extends us{static install(t){fs=t.THREE,ms=Object.freeze(new fs.Vector3(0,0,0)),ys=Object.freeze(new fs.Vector3(0,1,0)),gs=Object.freeze(new fs.Vector3(0,0,1)),xs=new fs.Vector2,bs=new fs.Vector3,vs=new fs.Vector3,ws=new fs.Vector3,_s=new fs.Vector3,Ms=new fs.Vector3,Ss=new fs.Vector3,As=new fs.Vector3,Ts=new fs.Vector3,Cs=new fs.Vector3,zs=new fs.Spherical,Es=new fs.Spherical,Os=new fs.Box3,Ps=new fs.Box3,Ns=new fs.Sphere,Bs=new fs.Quaternion,ks=new fs.Quaternion,Ls=new fs.Matrix4,Rs=new fs.Raycaster}static get ACTION(){return Zi}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=Zi.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Yi,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new fs.Vector3,this._focalOffsetVelocity=new fs.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,n,i)=>{let s,r;if($i(this._camera)){const n=bs.copy(this._camera.position).sub(this._target),i=this._camera.getEffectiveFOV()*ts,o=n.length()*Math.tan(.5*i);s=this.truckSpeed*t*o/this._elementRect.height,r=this.truckSpeed*e*o/this._elementRect.height}else{if(!Ji(this._camera))return;{const n=this._camera;s=this.truckSpeed*t*(n.right-n.left)/n.zoom/this._elementRect.width,r=this.truckSpeed*e*(n.top-n.bottom)/n.zoom/this._elementRect.height}}i?(n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(s,0,!0),this.forward(-r,!0)):n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(s,r,!0)},this._rotateInternal=(t,e)=>{const n=Ki*this.azimuthRotateSpeed*t/this._elementRect.height,i=Ki*this.polarRotateSpeed*e/this._elementRect.height;this.rotate(n,i,!0)},this._dollyInternal=(t,e,n)=>{const i=Math.pow(.95,-t*this.dollySpeed),s=this._sphericalEnd.radius,r=this._sphericalEnd.radius*i,o=es(r,this.minDistance,this.maxDistance),a=o-r;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(r,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?r:o)-s,this._dollyControlCoord.set(e,n)),this._lastDollyDirection=Math.sign(-t)},this._zoomInternal=(t,e,n)=>{const i=Math.pow(.95,t*this.dollySpeed),s=this._zoom,r=this._zoom*i;this.zoomTo(r,!0),this.dollyToCursor&&(this._changedZoom+=r-s,this._dollyControlCoord.set(e,n))},void 0===fs&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=(new fs.Quaternion).setFromUnitVectors(this._camera.up,ys),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=Zi.NONE,this._target=new fs.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new fs.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new fs.Spherical).setFromVector3(bs.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new fs.Vector3,new fs.Vector3,new fs.Vector3,new fs.Vector3],this._updateNearPlaneCorners(),this._boundary=new fs.Box3(new fs.Vector3(-1/0,-1/0,-1/0),new fs.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new fs.Vector2,this.mouseButtons={left:Zi.ROTATE,middle:Zi.DOLLY,right:Zi.TRUCK,wheel:$i(this._camera)?Zi.DOLLY:Ji(this._camera)?Zi.ZOOM:Zi.NONE},this.touches={one:Zi.TOUCH_ROTATE,two:$i(this._camera)?Zi.TOUCH_DOLLY_TRUCK:Ji(this._camera)?Zi.TOUCH_ZOOM_TRUCK:Zi.NONE,three:Zi.TOUCH_TRUCK};const n=new fs.Vector2,i=new fs.Vector2,s=new fs.Vector2,r=t=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),n=(t.clientX-e.left)/(e.right-e.left),i=(t.clientY-e.top)/(e.bottom-e.top);if(n<this._interactiveArea.left||n>this._interactiveArea.right||i<this._interactiveArea.top||i>this._interactiveArea.bottom)return}const e="mouse"!==t.pointerType?null:(t.buttons&Wi)===Wi?Wi:(t.buttons&qi)===qi?qi:(t.buttons&Hi)===Hi?Hi:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&Wi)===Wi&&this._lockedPointer)return;const n={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,deltaX:0,deltaY:0,mouseButton:e};this._activePointers.push(n),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),this._isDragging=!0,u(t)},o=t=>{t.cancelable&&t.preventDefault();const e=t.pointerId,n=this._lockedPointer||this._findPointerById(e);if(n){if(n.clientX=t.clientX,n.clientY=t.clientY,n.deltaX=t.movementX,n.deltaY=t.movementY,this._state=0,"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(t.buttons&Wi)===Wi)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&qi)===qi&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Hi)===Hi&&(this._state=this._state|this.mouseButtons.right);d()}},a=t=>{const e=this._findPointerById(t.pointerId);if(!e||e!==this._lockedPointer){if(e&&this._disposePointer(e),"touch"===t.pointerType)switch(this._activePointers.length){case 0:this._state=Zi.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._state=Zi.NONE;p()}};let h=-1;const l=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===Zi.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),n=(t.clientX-e.left)/(e.right-e.left),i=(t.clientY-e.top)/(e.bottom-e.top);if(n<this._interactiveArea.left||n>this._interactiveArea.right||i<this._interactiveArea.top||i>this._interactiveArea.bottom)return}if(t.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===Zi.ROTATE||this.mouseButtons.wheel===Zi.TRUCK){const t=performance.now();h-t<1e3&&this._getClientRect(this._elementRect),h=t}const e=ps?-1:-3,n=1===t.deltaMode||t.ctrlKey?t.deltaY/e:t.deltaY/(10*e),i=this.dollyToCursor?(t.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,s=this.dollyToCursor?(t.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case Zi.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case Zi.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case Zi.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case Zi.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case Zi.DOLLY:this._dollyInternal(-n,i,s),this._isUserControllingDolly=!0;break;case Zi.ZOOM:this._zoomInternal(-n,i,s),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Us.ACTION.NONE){const e=t instanceof PointerEvent?t.pointerId:0,n=this._findPointerById(e);return n&&this._disposePointer(n),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}t.preventDefault()}},u=t=>{if(!this._enabled)return;ls(this._activePointers,xs),this._getClientRect(this._elementRect),n.copy(xs),i.copy(xs);if(this._activePointers.length>=2){const t=xs.x-this._activePointers[1].clientX,e=xs.y-this._activePointers[1].clientY,n=Math.sqrt(t*t+e*e);s.set(0,n);const r=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);i.set(r,o)}if(this._state=0,t)if("pointerType"in t&&"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._lockedPointer||(t.buttons&Wi)!==Wi||(this._state=this._state|this.mouseButtons.left),(t.buttons&qi)===qi&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Hi)===Hi&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&Zi.ROTATE)!==Zi.ROTATE&&(this._state&Zi.TOUCH_ROTATE)!==Zi.TOUCH_ROTATE&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),(this._state&Zi.TRUCK)!==Zi.TRUCK&&(this._state&Zi.SCREEN_PAN)!==Zi.SCREEN_PAN&&(this._state&Zi.TOUCH_TRUCK)!==Zi.TOUCH_TRUCK&&(this._state&Zi.TOUCH_SCREEN_PAN)!==Zi.TOUCH_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&Zi.DOLLY)!==Zi.DOLLY&&(this._state&Zi.TOUCH_DOLLY)!==Zi.TOUCH_DOLLY&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&Zi.ZOOM)!==Zi.ZOOM&&(this._state&Zi.TOUCH_ZOOM)!==Zi.TOUCH_ZOOM&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_ZOOM_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&Zi.OFFSET)!==Zi.OFFSET&&(this._state&Zi.TOUCH_OFFSET)!==Zi.TOUCH_OFFSET&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},d=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ls(this._activePointers,xs);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:i.x-xs.x,r=t?-t.deltaY:i.y-xs.y;if(i.copy(xs),(this._state&Zi.ROTATE)!==Zi.ROTATE&&(this._state&Zi.TOUCH_ROTATE)!==Zi.TOUCH_ROTATE&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&Zi.DOLLY)===Zi.DOLLY||(this._state&Zi.ZOOM)===Zi.ZOOM){const t=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,e=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0,i=this.dollyDragInverted?-1:1;(this._state&Zi.DOLLY)===Zi.DOLLY?(this._dollyInternal(i*r*ds,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(i*r*ds,t,e),this._isUserControllingZoom=!0)}if((this._state&Zi.TOUCH_DOLLY)===Zi.TOUCH_DOLLY||(this._state&Zi.TOUCH_ZOOM)===Zi.TOUCH_ZOOM||(this._state&Zi.TOUCH_DOLLY_TRUCK)===Zi.TOUCH_DOLLY_TRUCK||(this._state&Zi.TOUCH_ZOOM_TRUCK)===Zi.TOUCH_ZOOM_TRUCK||(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)===Zi.TOUCH_DOLLY_SCREEN_PAN||(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)===Zi.TOUCH_ZOOM_SCREEN_PAN||(this._state&Zi.TOUCH_DOLLY_OFFSET)===Zi.TOUCH_DOLLY_OFFSET||(this._state&Zi.TOUCH_ZOOM_OFFSET)===Zi.TOUCH_ZOOM_OFFSET||(this._state&Zi.TOUCH_DOLLY_ROTATE)===Zi.TOUCH_DOLLY_ROTATE||(this._state&Zi.TOUCH_ZOOM_ROTATE)===Zi.TOUCH_ZOOM_ROTATE){const t=xs.x-this._activePointers[1].clientX,e=xs.y-this._activePointers[1].clientY,n=Math.sqrt(t*t+e*e),r=s.y-n;s.set(0,n);const o=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,a=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&Zi.TOUCH_DOLLY)===Zi.TOUCH_DOLLY||(this._state&Zi.TOUCH_DOLLY_ROTATE)===Zi.TOUCH_DOLLY_ROTATE||(this._state&Zi.TOUCH_DOLLY_TRUCK)===Zi.TOUCH_DOLLY_TRUCK||(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)===Zi.TOUCH_DOLLY_SCREEN_PAN||(this._state&Zi.TOUCH_DOLLY_OFFSET)===Zi.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*ds,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*ds,o,a),this._isUserControllingZoom=!0)}(this._state&Zi.TRUCK)!==Zi.TRUCK&&(this._state&Zi.TOUCH_TRUCK)!==Zi.TOUCH_TRUCK&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&Zi.SCREEN_PAN)!==Zi.SCREEN_PAN&&(this._state&Zi.TOUCH_SCREEN_PAN)!==Zi.TOUCH_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&Zi.OFFSET)!==Zi.OFFSET&&(this._state&Zi.TOUCH_OFFSET)!==Zi.TOUCH_OFFSET&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{ls(this._activePointers,xs),i.copy(xs),this._dragNeedsUpdate=!1,(0===this._activePointers.length||1===this._activePointers.length&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),0===this._activePointers.length&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{this._enabled&&this._domElement&&(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",m),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),u())},this.unlockPointer=()=>{var t,e,n;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(t=this._domElement)||void 0===t||t.ownerDocument.exitPointerLock(),null===(e=this._domElement)||void 0===e||e.ownerDocument.removeEventListener("pointerlockchange",f),null===(n=this._domElement)||void 0===n||n.ownerDocument.removeEventListener("pointerlockerror",m),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},m=()=>{this.unlockPointer()};this._addAllEventListeners=t=>{this._domElement=t,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",l,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",l,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",m))},this.cancel=()=>{this._state!==Zi.NONE&&(this._state=Zi.NONE,this._activePointers.length=0,p())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=es(t.width,0,1),this._interactiveArea.height=es(t.height,0,1),this._interactiveArea.x=es(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=es(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,n=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,n)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,n=!1){this._isUserControllingRotate=!1;const i=es(t,this.minAzimuthAngle,this.maxAzimuthAngle),s=es(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=s,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,n||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!n||is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Yi,this._changedDolly=0,this._dollyToNoClamp(es(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const n=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const e=this._collisionTest(),i=is(e,this._spherical.radius);if(!(n>t)&&i)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,e)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const i=!e||is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(_s).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const n=!e||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=es(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const n=!e||is(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(n)}pan(t,e,n=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,n)}truck(t,e,n=!1){this._camera.updateMatrix(),Ms.setFromMatrixColumn(this._camera.matrix,0),Ss.setFromMatrixColumn(this._camera.matrix,1),Ms.multiplyScalar(t),Ss.multiplyScalar(-e);const i=bs.copy(Ms).add(Ss),s=vs.copy(this._targetEnd).add(i);return this.moveTo(s.x,s.y,s.z,n)}forward(t,e=!1){bs.setFromMatrixColumn(this._camera.matrix,0),bs.crossVectors(this._camera.up,bs),bs.multiplyScalar(t);const n=vs.copy(this._targetEnd).add(bs);return this.moveTo(n.x,n.y,n.z,e)}elevate(t,e=!1){return bs.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+bs.x,this._targetEnd.y+bs.y,this._targetEnd.z+bs.z,e)}moveTo(t,e,n,i=!1){this._isUserControllingTruck=!1;const s=bs.set(t,e,n).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,s,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,n,i=!1){const s=bs.set(t,e,n).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(s.x,s.y,s.z,i)}fitToBox(t,e,{cover:n=!1,paddingLeft:i=0,paddingRight:s=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],h=t.isBox3?Os.copy(t):Os.setFromObject(t);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const l=ss(this._sphericalEnd.theta,Qi),c=ss(this._sphericalEnd.phi,Qi);a.push(this.rotateTo(l,c,e));const u=bs.setFromSpherical(this._sphericalEnd).normalize(),d=Bs.setFromUnitVectors(u,gs),p=is(Math.abs(u.y),1);p&&d.multiply(ks.setFromAxisAngle(ys,l)),d.multiply(this._yAxisUpSpaceInverse);const f=Ps.makeEmpty();vs.copy(h.min).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setX(h.max.x).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setY(h.max.y).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setZ(h.min.z).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setZ(h.max.z).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setY(h.min.y).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setX(h.min.x).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).applyQuaternion(d),f.expandByPoint(vs),f.min.x-=i,f.min.y-=r,f.max.x+=s,f.max.y+=o,d.setFromUnitVectors(gs,u),p&&d.premultiply(ks.invert()),d.premultiply(this._yAxisUpSpace);const m=f.getSize(bs),y=f.getCenter(vs).applyQuaternion(d);if($i(this._camera)){const t=this.getDistanceToFitBox(m.x,m.y,m.z,n);a.push(this.moveTo(y.x,y.y,y.z,e)),a.push(this.dollyTo(t,e)),a.push(this.setFocalOffset(0,0,0,e))}else if(Ji(this._camera)){const t=this._camera,i=t.right-t.left,s=t.top-t.bottom,r=n?Math.max(i/m.x,s/m.y):Math.min(i/m.x,s/m.y);a.push(this.moveTo(y.x,y.y,y.z,e)),a.push(this.zoomTo(r,e)),a.push(this.setFocalOffset(0,0,0,e))}return Promise.all(a)}fitToSphere(t,e){const n=[],i="isObject3D"in t?Us.createBoundingSphere(t,Ns):Ns.copy(t);if(n.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),$i(this._camera)){const t=this.getDistanceToFitSphere(i.radius);n.push(this.dollyTo(t,e))}else if(Ji(this._camera)){const t=this._camera.right-this._camera.left,s=this._camera.top-this._camera.bottom,r=2*i.radius,o=Math.min(t/r,s/r);n.push(this.zoomTo(o,e))}return n.push(this.setFocalOffset(0,0,0,e)),Promise.all(n)}setLookAt(t,e,n,i,s,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Yi,this._changedDolly=0;const a=vs.set(i,s,r),h=bs.set(t,e,n);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(h.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const l=!o||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold)&&is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(l)}lerpLookAt(t,e,n,i,s,r,o,a,h,l,c,u,d,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Yi,this._changedDolly=0;const f=bs.set(i,s,r),m=vs.set(t,e,n);zs.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const y=ws.set(l,c,u),g=vs.set(o,a,h);Es.setFromVector3(g.sub(y).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(y,d));const x=Es.theta-zs.theta,b=Es.phi-zs.phi,v=Es.radius-zs.radius;this._sphericalEnd.set(zs.radius+v*d,zs.phi+b*d,zs.theta+x*d),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!p||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold)&&is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(w)}setPosition(t,e,n,i=!1){return this.setLookAt(t,e,n,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,n,i=!1){const s=this.getPosition(bs),r=this.setLookAt(s.x,s.y,s.z,t,e,n,i);return this._sphericalEnd.phi=es(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,n,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,n),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const s=!i||is(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&is(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&is(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}setOrbitPoint(t,e,n){this._camera.updateMatrixWorld(),Ms.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Ss.setFromMatrixColumn(this._camera.matrixWorldInverse,1),As.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=bs.set(t,e,n),s=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);Ms.multiplyScalar(r.x),Ss.multiplyScalar(r.y),As.multiplyScalar(r.z),bs.copy(Ms).add(Ss).add(As),bs.z=bs.z+s,this.dollyTo(s,!1),this.setFocalOffset(-bs.x,bs.y,-bs.z,!1),this.moveTo(t,e,n,!1)}setBoundary(t){if(!t)return this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),void(this._needsUpdate=!0);this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,n,i){null!==t?(this._viewport=this._viewport||new fs.Vector4,"number"==typeof t?this._viewport.set(t,e,n,i):this._viewport.copy(t)):this._viewport=null}getDistanceToFitBox(t,e,n,i=!1){if(cs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const s=t/e,r=this._camera.getEffectiveFOV()*ts,o=this._camera.aspect;return.5*((i?s>o:s<o)?e:t/o)/Math.tan(.5*r)+.5*n}getDistanceToFitSphere(t){if(cs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*ts,n=2*Math.atan(Math.tan(.5*e)*this._camera.aspect),i=1<this._camera.aspect?e:n;return t/Math.sin(.5*i)}getTarget(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new fs.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Ki,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Ki),this._spherical.theta+=Ki*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Ki)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!is(this._camera.up.x,this._cameraUp0.x)||!is(this._camera.up.y,this._cameraUp0.y)||!is(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(bs);this.updateCameraUp(),this.setPosition(t.x,t.y,t.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,ys),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=bs.subVectors(this._target,this._camera.position).normalize(),e=vs.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const n=this.getPosition(bs);this.updateCameraUp(),this.setPosition(n.x,n.y,n.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,n=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,s=Ts.subVectors(this._targetEnd,this._target),r=Cs.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ns(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=as(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(ns(n))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=as(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(ns(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=as(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(ns(s.x)&&ns(s.y)&&ns(s.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;hs(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(ns(r.x)&&ns(r.y)&&ns(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;hs(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(ns(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=as(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if($i(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,n=this._getCameraDirection(_s),i=bs.copy(n).cross(e.up).normalize();0===i.lengthSq()&&(i.x=1);const s=vs.crossVectors(i,n),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*ts*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=ws.copy(this._targetEnd).add(i.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(s.multiplyScalar(this._dollyControlCoord.y*r)),h=bs.copy(this._targetEnd).lerp(a,o),l=this._lastDollyDirection===Gi&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===Xi&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(l||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=vs.copy(n).multiplyScalar(-t);h.add(e)}this._boundary.clampPoint(h,h);const u=vs.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedDolly-=t,ns(this._changedDolly)&&(this._changedDolly=0)}else if(Ji(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,n=bs.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),i=vs.set(0,0,-1).applyQuaternion(e.quaternion),s=ws.copy(n).add(i.multiplyScalar(-n.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(_s),a=this._targetEnd.dot(o),h=bs.copy(this._targetEnd).lerp(s,r),l=h.dot(o),c=o.multiplyScalar(l-a);h.sub(c),this._boundary.clampPoint(h,h);const u=vs.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedZoom-=t,ns(this._changedZoom)&&(this._changedZoom=0)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target);(!ns(this._focalOffset.x)||!ns(this._focalOffset.y)||!ns(this._focalOffset.z))&&(Ms.setFromMatrixColumn(this._camera.matrix,0),Ss.setFromMatrixColumn(this._camera.matrix,1),As.setFromMatrixColumn(this._camera.matrix,2),Ms.multiplyScalar(this._focalOffset.x),Ss.multiplyScalar(-this._focalOffset.y),As.multiplyScalar(this._focalOffset.z),bs.copy(Ms).add(Ss).add(As),this._camera.position.add(bs),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),bs.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),ns(e,this.restThreshold)&&ns(n,this.restThreshold)&&ns(i,this.restThreshold)&&ns(s.x,this.restThreshold)&&ns(s.y,this.restThreshold)&&ns(s.z,this.restThreshold)&&ns(r.x,this.restThreshold)&&ns(r.y,this.restThreshold)&&ns(r.z,this.restThreshold)&&ns(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&(this._hasRested||(this._hasRested=!0,this.dispatchEvent({type:"rest"})),this.dispatchEvent({type:"sleep"})),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:rs(this.maxDistance),minZoom:this.minZoom,maxZoom:rs(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:rs(this.maxPolarAngle),minAzimuthAngle:rs(this.minAzimuthAngle),maxAzimuthAngle:rs(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:bs.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const n=JSON.parse(t);this.enabled=n.enabled,this.minDistance=n.minDistance,this.maxDistance=os(n.maxDistance),this.minZoom=n.minZoom,this.maxZoom=os(n.maxZoom),this.minPolarAngle=n.minPolarAngle,this.maxPolarAngle=os(n.maxPolarAngle),this.minAzimuthAngle=os(n.minAzimuthAngle),this.maxAzimuthAngle=os(n.maxAzimuthAngle),this.smoothTime=n.smoothTime,this.draggingSmoothTime=n.draggingSmoothTime,this.dollySpeed=n.dollySpeed,this.truckSpeed=n.truckSpeed,this.dollyToCursor=n.dollyToCursor,this._target0.fromArray(n.target0),this._position0.fromArray(n.position0),this._zoom0=n.zoom0,this._focalOffset0.fromArray(n.focalOffset0),this.moveTo(n.target[0],n.target[1],n.target[2],e),zs.setFromVector3(bs.fromArray(n.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(zs.theta,zs.phi,e),this.dollyTo(zs.radius,e),this.zoomTo(n.zoom,e),this.setFocalOffset(n.focalOffset[0],n.focalOffset[1],n.focalOffset[2],e),this._needsUpdate=!0}connect(t){this._domElement?console.warn("camera-controls is already connected."):(this._addAllEventListeners(t),this._getClientRect(this._elementRect))}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,n){const i=e.lengthSq();if(0===i)return t;const s=vs.copy(e).add(t),r=this._boundary.clampPoint(s,ws).sub(s),o=r.lengthSq();if(0===o)return t.add(e);if(o===i)return t;if(0===n)return t.add(e).add(r);{const i=1+n*o/e.dot(r);return t.add(vs.copy(e).multiplyScalar(i)).add(r.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if($i(this._camera)){const t=this._camera,e=t.near,n=t.getEffectiveFOV()*ts,i=Math.tan(.5*n)*e,s=i*t.aspect;this._nearPlaneCorners[0].set(-s,-i,0),this._nearPlaneCorners[1].set(s,-i,0),this._nearPlaneCorners[2].set(s,i,0),this._nearPlaneCorners[3].set(-s,i,0)}else if(Ji(this._camera)){const t=this._camera,e=1/t.zoom,n=t.left*e,i=t.right*e,s=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(n,s,0),this._nearPlaneCorners[1].set(i,s,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(n,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1))return t;if(cs(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(_s);Ls.lookAt(ms,e,this._camera.up);for(let n=0;n<4;n++){const i=vs.copy(this._nearPlaneCorners[n]);i.applyMatrix4(Ls);const s=ws.addVectors(this._target,i);Rs.set(s,e),Rs.far=this._spherical.radius+1;const r=Rs.intersectObjects(this.colliderMeshes);0!==r.length&&r[0].distance<t&&(t=r[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new fs.Sphere){const n=e,i=n.center;Os.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&Os.expandByObject(t)}),Os.getCenter(i);let s=0;return t.traverseVisible(t=>{if(!t.isMesh)return;const e=t;if(!e.geometry)return;const n=e.geometry.clone();n.applyMatrix4(e.matrixWorld);const r=n.attributes.position;for(let o=0,a=r.count;o<a;o++)bs.fromBufferAttribute(r,o),s=Math.max(s,i.distanceToSquared(bs))}),n.radius=Math.sqrt(s),n}}class js extends Xe{constructor(t){super(),u(this,"options"),u(this,"autoRotateSpeed",0),this.options=t;const e={Vector2:N,Vector3:y,Vector4:ct,Quaternion:L,Matrix4:g,Spherical:_t,Box3:B,Sphere:_,Raycaster:wt};Us.install({THREE:e})}get cameraControls(){return this.controller}addCameraControls(t,e){const{domElement:n}=this.options.controlsParams,i=new Us(t,n);return i.setLookAt(0,0,400,0,0,0,!1),this.addController(i,e)}setPageActive(t){super.setPageActive(t,(t,e)=>{t.enabled=e})}removePage(t){super.removePage(t,t=>{t.dispose()})}enable(){this.activeControllerSet.forEach(t=>{t.enabled=!0})}disable(){this.activeControllerSet.forEach(t=>{t.enabled=!1})}update(t,e){super.update(t,e),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*P.DEG2RAD)}}class Ds{constructor(t={}){u(this,"labels",/* @__PURE__ */new Map),u(this,"options"),u(this,"lastUpdateTime",0),u(this,"camera"),u(this,"animationFrameId"),u(this,"isUpdating",!1),this.options=h({padding:2,enabled:!1,throttleTime:16,viewportMargin:50,stabilityBonus:50,fadeTime:200},t)}add(t,e={}){var n;this.options.enabled||console.warn("collision.enabled is false, please enable it before adding nodes."),this.labels.set(t,{node:t,priority:null!=(n=e.priority)?n:0,visible:!0})}remove(t){this.labels.delete(t)}setPriority(t,e){const n=this.labels.get(t);n&&(n.priority=e)}addBatch(t,e){t.forEach((t,n)=>{this.add(t,{priority:e?e(t,n):0})})}setEnabled(t){this.options.enabled=t,t||this.labels.forEach(t=>{this.setNodeVisibility(t.node,!0),t.visible=!0})}update(t){if(!this.options.enabled)return;const e=performance.now();e-this.lastUpdateTime<this.options.throttleTime||(this.lastUpdateTime=e,this.camera=t,this.isUpdating||(this.isUpdating=!0,this.animationFrameId=requestAnimationFrame(()=>{this.performCollisionDetection(),this.isUpdating=!1})))}forceUpdate(){this.camera&&this.performCollisionDetection()}performCollisionDetection(){const{padding:t,viewportMargin:e}=this.options,n=window.innerWidth,i=window.innerHeight,s=[];this.labels.forEach(t=>{const r=t.node.element;if(!r)return;const o=r.firstElementChild;if(!o)return;const a="0"===o.style.opacity;a&&(o.style.visibility="hidden",o.style.opacity="1");const h=o.getBoundingClientRect();if(a&&(o.style.opacity="0",o.style.visibility=""),0===h.width||0===h.height)return;h.right>=-e&&h.left<=n+e&&h.bottom>=-e&&h.top<=i+e?(t.bounds=h,s.push(t)):(this.setNodeVisibility(t.node,!1),t.visible=!1)});const{stabilityBonus:r}=this.options;s.sort((t,e)=>{const n=t.priority+(t.visible?r:0);return e.priority+(e.visible?r:0)-n});const o=[];for(const a of s){if(!a.bounds)continue;this.checkCollision(a.bounds,o,t)?(this.setNodeVisibility(a.node,!1),a.visible=!1):(this.setNodeVisibility(a.node,!0),a.visible=!0,o.push(a.bounds))}}checkCollision(t,e,n){for(const i of e)if(this.rectsIntersect(t,i,n))return!0;return!1}rectsIntersect(t,e,n){return!(t.right+n<e.left||t.left-n>e.right||t.bottom+n<e.top||t.top-n>e.bottom)}setNodeVisibility(t,e){const n=t.element;if(!n)return;const i=n.firstElementChild;if(!i)return;const{fadeTime:s}=this.options;s>0&&!i.style.transition&&(i.style.transition=`opacity ${s}ms ease-out`),i.style.opacity=e?"1":"0"}getVisibleCount(){let t=0;return this.labels.forEach(e=>{e.visible&&t++}),t}getTotalCount(){return this.labels.size}debugRun(){const{padding:t,viewportMargin:e}=this.options,n=window.innerWidth,i=window.innerHeight;console.log("=== CollisionManager debugRun ==="),console.log("padding:",t,"viewportMargin:",e);const s=[];this.labels.forEach(t=>{const r=t.node.element;if(!r)return void console.log("Skipping: wrapper is null");const o=r.firstElementChild;if(!o)return void console.log("Skipping: child element is null");const a="0"===o.style.opacity;a&&(o.style.visibility="hidden",o.style.opacity="1");const h=o.getBoundingClientRect();if(a&&(o.style.opacity="0",o.style.visibility=""),0===h.width||0===h.height)return void console.log("Skipping: rect is 0",h);const l=h.right>=-e&&h.left<=n+e&&h.bottom>=-e&&h.top<=i+e;console.log(`Entry priority=${t.priority}, inViewport=${l}`),l?(t.bounds=h,s.push(t)):(this.setNodeVisibility(t.node,!1),t.visible=!1)}),console.log("Entries in viewport:",s.length),s.sort((t,e)=>e.priority-t.priority),console.log("Sorted entries:",s.map(t=>t.priority));const r=[];for(const o of s){if(!o.bounds)continue;const e=this.checkCollision(o.bounds,r,t);console.log(`Processing priority=${o.priority}, hasCollision=${e}, occupiedRects.length=${r.length}`),e?(this.setNodeVisibility(o.node,!1),o.visible=!1):(this.setNodeVisibility(o.node,!0),o.visible=!0,r.push(o.bounds))}console.log("Final visible count:",this.getVisibleCount())}clear(){this.labels.clear()}dispose(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.labels.clear()}}const Fs={zIndex:"auto"};class Is{constructor(t,e){u(this,"css2Drenderer"),u(this,"css3Drenderer"),u(this,"container"),u(this,"collisionManager"),this.container=t,this.collisionManager=new Ds(null==e?void 0:e.collision)}addRenderer(t,e){const n=h(h({},Fs),e),i=n.container||this.container,s=i.offsetWidth,r=i.offsetHeight,o="css2d"===t?new Kt:new ee;o.domElement.style.position="absolute",o.domElement.style.top="0",o.domElement.style.pointerEvents="none",o.domElement.style.zIndex=n.zIndex,o.setSize(s,r),i.appendChild(o.domElement),"css2d"===t?this.css2Drenderer=o:"css3d"===t&&(this.css3Drenderer=o)}setSize(t,e){var n,i;null==(n=this.css2Drenderer)||n.setSize(t,e),null==(i=this.css3Drenderer)||i.setSize(t,e)}render(t,e){var n,i;null==(n=this.css2Drenderer)||n.render(t,e),null==(i=this.css3Drenderer)||i.render(t,e),this.collisionManager.update(e)}dispose(){var t,e;null==(t=this.css2Drenderer)||t.domElement.remove(),null==(e=this.css3Drenderer)||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0,this.collisionManager.dispose()}}class Vs{constructor(t){u(this,"helpers",{}),u(this,"viewHelper"),u(this,"options"),this.options=t}add(t){const e=t.uuid,{sceneController:n}=this.options;let i=this.helpers[e];if(void 0===i){if(t.isScene)i=new Mt(100);else if(t.isCamera)i=new St(t);else if(t.isPointLight)i=new At(t,1);else if(t.isDirectionalLight)i=new Tt(t,1);else if(t.isSpotLight)i=new Ct(t);else if(t.isHemisphereLight)i=new zt(t,10);else if(t.isRectAreaLight)i=new Ue(t);else{const e=new B;if(e.setFromObject(t,!0),!1!==e.isEmpty())return;{i=new Et(e);const n=i.material;n.userData.object=t,n.userData.lastMatrixWorld=t.matrixWorld.clone(),n.depthTest=!1,n.transparent=!0}}n.scene.add(i),this.helpers[e]=i}}addViewHelper(){const{cameraController:t,container:e}=this.options,n=new je(t.camera,e);e.addEventListener("pointerdown",t=>{t.preventDefault(),n.handleClick(t)}),this.viewHelper=n}remove(t){var e;const n=t.uuid,{sceneController:i}=this.options;if(void 0!==this.helpers[n]){const t=this.helpers[n];i.scene.remove(t),delete this.helpers[n],null==(e=t.dispose)||e.call(t)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof Mt||this.remove({uuid:t})})}update(t,e,n){var i,s;const{cameraController:r}=this.options;Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof Et){const e=t.material,{object:n,lastMatrixWorld:i}=e.userData;if(n){!n.matrixWorld.equals(i||n.matrixWorld)&&(t.box.setFromObject(n,!0),e.userData.lastMatrixWorld=n.matrixWorld.clone())}}}),!0===(null==(i=this.viewHelper)?void 0:i.animating)&&(this.viewHelper.update(t),null==(s=e.cameraControls)||s.setPosition(...r.camera.position.toArray()),this.viewHelper.center.copy(n))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},null==(t=this.viewHelper)||t.dispose()}}function Ws(t){let e=!1,n=[];return(...i)=>{n=i,e||(e=!0,requestAnimationFrame(()=>{e=!1,t(...n)}))}}class Hs{constructor(t){var e;u(this,"pencil"),u(this,"enabled",!0),u(this,"pickFunctionsMap",/* @__PURE__ */new Map),u(this,"pickNodeFunctionsMap",/* @__PURE__ */new Map),u(this,"pickFunctionsMapIndex",-1),u(this,"pickNodeFunctionsMapIndex",-1),u(this,"activeObjects",/* @__PURE__ */new Set),u(this,"activeObject",null),u(this,"prevActiveObjects",/* @__PURE__ */new Set),u(this,"objCallbackMap",/* @__PURE__ */new Map),u(this,"pickListener",{move:!1,down:!1}),u(this,"hasEnterOnStopEvent",!1),u(this,"cursorObjects",/* @__PURE__ */new Map),u(this,"cursorListenerAdded",!1),u(this,"moveStopTimer",null),u(this,"moveStopDelay",150),u(this,"lastMoveEvent",null),u(this,"lastMoveActiveObjects",/* @__PURE__ */new Set),u(this,"lastMoveRealActiveObject",null),u(this,"triggeredEnterOnStopObjects",/* @__PURE__ */new Set),u(this,"domElement"),this.pencil=t,this.domElement=(null==(e=t.options.controls)?void 0:e.domElement)||t.options.container}addPickListener(t){const e=/* @__PURE__ */new Set(["move","enter","leave","enterOnStop"]),n=/* @__PURE__ */new Set(["down","downOutside","click"]);this.domElement.addEventListener(`pointer${t}`,Ws(i=>{var s;if(!this.enabled)return;i.preventDefault();const r="move"===t?e:n,o=[];if(this.pickFunctionsMap.forEach(t=>{r.has(t.type)&&o.push(l(h({},t),{objArr:t.objArr instanceof Function?t.objArr():t.objArr}))}),0===o.length)return;this.activeObjects.clear(),this.objCallbackMap.clear(),this.activeObject=null;const a=this.objCallbackMap;for(const t of o)for(const e of t.objArr){if(!e.object3d)continue;a.has(e)||a.set(e,/* @__PURE__ */new Map);const n=a.get(e);n.has(t.type)||n.set(t.type,[]),n.get(t.type).push(t.cb)}if(0===a.size)return;const c=[...a.keys()].map(t=>t.object3d),u=null==(s=this.pencil.pick(i,c,!1))?void 0:s.intersects;if(u&&0!==u.length){const e=u[0];this.processIntersection(e,i,t)}else"down"===t?this.handleDownOutside(i):"move"===t&&this.handleLeaveEvents(i);"move"===t&&this.hasEnterOnStopEvent&&(this.handleMoveStop(i),this.triggeredEnterOnStopObjects.forEach(t=>{this.activeObjects.has(t)||this.triggeredEnterOnStopObjects.delete(t)}));const d=this.prevActiveObjects;this.prevActiveObjects=this.activeObjects,this.activeObjects=d,this.activeObjects.clear()}),{passive:!1})}processIntersection(t,e,n){var i;const s=this.objCallbackMap,r=null!=(i=t.index)?i:-1;let o=t.object;for(;o;){const t=this.pencil.lead.objMap.get(o);t&&t.visible&&(this.activeObject||(this.activeObject=t),s.has(t)&&this.activeObjects.add(t)),o=o.parent}"move"===n?this.handleLeaveEvents(e):"down"===n&&this.handleDownOutside(e),this.processObjectHierarchy(e,n,r)}processObjectHierarchy(t,e,n){const i=this.objCallbackMap;let s=!1;const r=()=>{s=!0};for(const o of this.activeObjects){if(s)break;const a=i.get(o);if(a)if("move"===e){const e=a.get("enter");if(e&&!this.prevActiveObjects.has(o))for(const s of e)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});const i=a.get("move");if(i)for(const s of i)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n})}else{const e=a.get("down");if(e)for(const s of e)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});const i=a.get("click");if(i){const e=a=>{a.preventDefault();if(!s&&Math.abs(a.clientX-t.clientX)<=5&&Math.abs(a.clientY-t.clientY)<=5)for(const e of i)e({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});this.domElement.removeEventListener("pointerup",e)};this.domElement.addEventListener("pointerup",e)}}}}handleLeaveEvents(t){this.objCallbackMap.forEach((e,n)=>{const i=e.get("leave");if(i&&this.prevActiveObjects.has(n)&&!this.activeObjects.has(n))for(const s of i)s({baseObject:n,mouseEvent:t})})}handleDownOutside(t){this.objCallbackMap.forEach((e,n)=>{const i=e.get("downOutside");if(i&&!this.activeObjects.has(n))for(const s of i)s({baseObject:n,mouseEvent:t})})}handleMoveStop(t){null!==this.moveStopTimer&&clearTimeout(this.moveStopTimer),this.lastMoveEvent=t,this.lastMoveActiveObjects.clear(),this.activeObjects.forEach(t=>{this.lastMoveActiveObjects.add(t)}),this.lastMoveRealActiveObject=this.activeObject,this.moveStopTimer=window.setTimeout(()=>{this.triggerEnterOnStop()},this.moveStopDelay)}triggerEnterOnStop(){if(!this.lastMoveEvent||0===this.lastMoveActiveObjects.size)return;const t=this.lastMoveEvent,e=this.objCallbackMap;let n=!1;const i=()=>{n=!0};for(const s of this.lastMoveActiveObjects){if(n)break;const r=e.get(s);if(!r)continue;const o=r.get("enterOnStop");if(o&&!this.triggeredEnterOnStopObjects.has(s)){this.triggeredEnterOnStopObjects.add(s);for(const e of o)e({baseObject:s,realBaseObject:this.lastMoveRealActiveObject,mouseEvent:t,sp:i})}}this.moveStopTimer=null}resetCursor(){this.domElement.style.cursor=""}addCursorListener(){if(this.cursorListenerAdded)return;this.cursorListenerAdded=!0;this.domElement.addEventListener("pointermove",Ws(t=>{var e;if(!this.enabled)return;0===this.cursorObjects.size&&this.resetCursor();const n=[...this.cursorObjects.keys()].filter(t=>t.object3d).map(t=>t.object3d);if(0===n.length)return void this.resetCursor();const i=this.pencil.pick(t,n,!1);if(!(null==(e=null==i?void 0:i.intersects)?void 0:e.length))return void this.resetCursor();let s=i.intersects[0].object;for(;s;){const t=this.pencil.lead.objMap.get(s);if(t&&this.cursorObjects.has(t))return void(this.domElement.style.cursor=this.cursorObjects.get(t));s=s.parent}this.resetCursor()}),{passive:!0})}enableCursor(t,e="pointer"){this.cursorObjects.set(t,e),this.addCursorListener()}disableCursor(t){this.cursorObjects.delete(t)}handlePick(t,e,n){let i=e;"mousemove"===i?i="move":"mouseenter"===i?i="enter":"mouseleave"===i&&(i="leave"),this.pickFunctionsMapIndex+=1;const s=this.pickFunctionsMapIndex;if(this.pickFunctionsMap.set(s,{objArr:t,type:i,cb:n}),"enterOnStop"===i&&(this.hasEnterOnStopEvent=!0),!this.pickListener.move){Array.from(this.pickFunctionsMap.values()).some(t=>["move","enter","leave","enterOnStop"].includes(t.type))&&(this.pickListener.move=!0,this.addPickListener("move"))}if(!this.pickListener.down){Array.from(this.pickFunctionsMap.values()).some(t=>["down","downOutside","click"].includes(t.type))&&(this.pickListener.down=!0,this.addPickListener("down"))}return s}removePick(t){this.pickFunctionsMap.delete(t),this.hasEnterOnStopEvent=Array.from(this.pickFunctionsMap.values()).some(t=>"enterOnStop"===t.type)}handlePickNode(t,e,n){if("downOutside"===e)return console.warn("handlePickNode:err:不支持 downOutside"),-1;this.pickNodeFunctionsMapIndex+=1;const i=this.pickNodeFunctionsMapIndex,s=t instanceof Function?t():t,r=[];for(const o of s){const t=o;t.element.style.pointerEvents="auto";const i=e=>{this.enabled&&(e.preventDefault(),n({baseObject:t,mouseEvent:e}))},s=`pointer${e}`;t.element.addEventListener(s,Ws(i),!1),r.push({arr:t,type:s,listener:i})}return this.pickNodeFunctionsMap.set(i,r),i}removePickNode(t){const e=this.pickNodeFunctionsMap.get(t);if(e){for(const t of e)t.arr.element.style.pointerEvents="none",t.arr.element.removeEventListener(t.type,t.listener,!1);this.pickNodeFunctionsMap.delete(t)}}dispose(){null!==this.moveStopTimer&&(clearTimeout(this.moveStopTimer),this.moveStopTimer=null),this.pickFunctionsMap.clear(),this.pickNodeFunctionsMap.clear(),this.activeObjects.clear(),this.prevActiveObjects.clear(),this.lastMoveActiveObjects.clear(),this.triggeredEnterOnStopObjects.clear(),this.objCallbackMap.clear(),this.cursorObjects.clear()}}class qs extends Hs{constructor(t,e){super(t),u(this,"objMap",/* @__PURE__ */new Map),u(this,"objects",/* @__PURE__ */new Map),u(this,"objectsPm",/* @__PURE__ */new Map),u(this,"objectWrapChindIdMap",/* @__PURE__ */new Map),u(this,"scene"),u(this,"mList"),u(this,"group"),u(this,"prefabGroup"),u(this,"objectNamesToFactories",/* @__PURE__ */new Map),this.mList=e.mList,this.scene=this.createBaseObject(e.scene||new Ot,{key:"@Scene",name:"场景",mList:!1}),this.group=this.createBaseObject(new R,{key:"@Group",name:"物体组",target:this.scene,mList:!1}),this.prefabGroup=this.createBaseObject(new R,{key:"@PrefabGroup",name:"预制组",target:this.scene,mList:!1})}get objectsPromise(){return this.objectsPm.values()}createBaseObject(t,e={}){const n=h({mList:!0},e);t instanceof R&&(t.raycast=(e,n)=>e.intersectObjects(t.children,!0,n));const i=new Ln;if(i.object3d=t,i.pencil=this.pencil,i.lead=this,i.mList=this.mList,n.key&&(i.key=n.key),!n.key&&n.target){if("@Scene"===n.target.key&&t instanceof Pt)i.key="@Camera";else{const t=this.objectWrapChindIdMap.get(n.target),e=void 0!==t?t+1:0;this.objectWrapChindIdMap.set(n.target,e),this.setBaseObjectKey(i,{type:`$p:__c__${e}`,uId:"$p:",key:"$p:"},n.target)}}return n.name&&(t.name=n.name),n.target&&!n.target.object3d.getObjectById(t.id)&&n.target.object3d.add(t),this.objects.set(i.key,i),this.objMap.set(i.object3d,i),n.mList&&(this.mList.proxyBaseObject(i),this.mList.addBaseObjectMap(i)),t.children&&t.children.forEach(t=>{this.createBaseObject(t,{target:i,mList:n.mList})}),this.pencil.event.emit("lead.draw",{baseObject:i}),i}init(t){return Object.keys(t).forEach(e=>{this.objectNamesToFactories.set(String(e),class{create(n={}){return new t[e](n)}})}),this}getObject(t,e){t.includes("#")&&console.warn("getObject:err:不支持 #",t);const{key:n}=e||{},i=`${t}${n?`#${n}`:""}`;return this.objects.get(i)}getAllObject(t,e){t.includes("#")&&console.warn("getAllObject:err:不支持 #",t);const{key:n}=e||{},i=`${t}${n?`#${n}`:""}`,s=[];return this.objects.forEach((t,e)=>{(e.startsWith(n?i:`${i}#`)||e===i)&&s.push(t)}),s}draw(t,e,n){return d(this,null,function*(){var i,s,r;const o=this.objectNamesToFactories.get(String(t));if(!o)throw new Error(`Unrecognized factory: ${String(t)}`);e||(e={}),void 0===e.target&&(e.target=n);const a=e.target,h=null!=(i=e.onTop)?i:0,l=null!=(s=e.prefab)&&s,c=null==(r=e.create)||r,u=(new o).create(e);let d;if(null===a)d=null;else if("string"==typeof a){const t=this.objects.get(a);if(!t)throw new Error(`Object with key "${a}" not found`);d=t}else d=(null==a?void 0:a.isBaseObject)?a:a||(l?this.prefabGroup:this.group);return!1===c?u.create=()=>{}:!0!==c&&(u.create=()=>{c(u)}),u.pencil=this.pencil,u.lead=this,u.mList=this.mList,u.isPrefab=l,u.objectType=`${t}`,u.objectOptions=e,this.setBaseObjectKey(u,{type:e.keyType,key:e.key,uId:e.uId},d),this.objectsPm.set(u,this.addBaseObject(u,d,h)),yield this.objectsPm.get(u),this.objectsPm.delete(u),u})}setBaseObjectKey(t,e,n){let i="",s=e.key,r=e.type||t.keyType||t.objectType,o=e.uId;return n&&((null==s?void 0:s.includes("$p:"))&&(s=s.replace("$p:",n.keyName||"")),(null==r?void 0:r.includes("$p:"))&&(r=r.replace("$p:",n.keyType||"")),(null==o?void 0:o.includes("$p:"))&&(o=o.replace("$p:",n.keyUId||""))),i=`${r}`,s&&o?i+=`#${s}-${o}`:(s||o)&&(i+=`#${s||o}`),this.objects.has(i)?this.setBaseObjectKey(t,{type:e.type,key:e.key,uId:De()},n):(t.key=i,t.keyType=r,t.keyUId=o,t.keyName=s,this.objects.set(i,t),i)}updateBaseObjectKey(t,e){const n=t.key;this.objects.delete(n);const i=t.parent,s=this.setBaseObjectKey(t,e,i);return this.pencil.event.emit("lead.updateKey",{baseObject:t,key:s,oldKey:n}),t.children.forEach(t=>{var e;if(t.key.includes("__c__")){const n=null==(e=/__c__(\d+)/.exec(t.key))?void 0:e[1];void 0!==n&&this.updateBaseObjectKey(t,{type:`$p:__c__${n}`,key:"$p:",uId:"$p:"})}}),s}addBaseObject(t,e,n){return d(this,null,function*(){if(yield t.create(),t.object3d){const i=t.object3d;i.material&&Array.isArray(i.material)&&(i.material=i.material.slice()),this.mList.proxyBaseObject(t),this.mList.addBaseObjectMap(t),n&&t.setTop(n),null!==e&&e.object3d.add(t.object3d),this.objMap.set(t.object3d,t),i.children.forEach(e=>{this.objMap.get(e)||this.createBaseObject(e,{target:t})})}t.render(),this.pencil.event.emit("lead.draw",{baseObject:t})})}erase(...t){this.handleErase(!0,...t)}eraseWithoutMaterial(...t){this.handleErase(!1,...t)}handleErase(t,...e){[...e].forEach(e=>{const n=[];if("string"==typeof e){const[t,i]=e.split("#");n.push(...this.getAllObject(t,{key:i}))}else n.push(e);n.forEach(e=>{e.disposeMaterialIfNotUsed=t,e.dispose()})}),this.pencil.event.emit("lead.erase")}update(t,e){this.objects.forEach(n=>{n.update(t,e)})}setSize(t,e){this.objects.forEach(n=>{n.resize(t,e)})}eraseAll(){this.group&&(this.objects.forEach(t=>{t.key.startsWith("Node")&&this.erase(t)}),this.erase(this.group))}dispose(){super.dispose(),this.scene.erase(),this.objects.forEach(t=>{t.erase()}),this.objects.clear(),this.objectsPm.clear(),this.objMap.clear(),this.objectWrapChindIdMap.clear(),this.objectNamesToFactories.clear()}}class Zs extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get lead(){return this.controller}addLead(t,e,n){const{pencil:i}=this.options,s=new qs(i,{scene:t,mList:e});return this.addController(s,n)}removePage(t){super.removePage(t,t=>{t.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.enabled=e})}setSize(t,e){this.controllerMap.forEach((n,i)=>{i.setSize(t,e)})}}class Ys extends Nt{constructor(t){super(t),u(this,"customResponseType"),this.customResponseType="json",super.setResponseType("blob")}setResponseType(t){return"json"===t||"arraybuffer"===t?this.customResponseType=t:super.setResponseType(t),this}load(t,e,n,i){return super.load(t,t=>{const n=t,s=new DecompressionStream("gzip"),r=n.stream().pipeThrough(s),o=new Response(r);"arraybuffer"===this.customResponseType?o.arrayBuffer().then(t=>{null==e||e(t)}).catch(t=>{i&&i(t)}):o.json().then(t=>{null==e||e(t)}).catch(t=>{i&&i(t)})},n,i)}}class Gs extends Bt{load(t,e,n,i){const s=document.createElement("video");s.preload="auto",s.autoplay=!1,s.loop=!1,s.muted=!0,s.setAttribute("webkit-playsinline","webkit-playsinline"),s.setAttribute("playsinline","");const r=new kt(s),o=()=>{s.removeEventListener("loadeddata",o,!1),s.removeEventListener("error",a,!1),r.needsUpdate=!0,e&&e(r),this.manager.itemEnd(t)},a=e=>{s.removeEventListener("loadeddata",o,!1),s.removeEventListener("error",a,!1),i&&i(e),this.manager.itemError(t),this.manager.itemEnd(t)};return s.addEventListener("loadeddata",o,!1),s.addEventListener("error",a,!1),s.src=this.path+t,this.manager.itemStart(t),r}}const Xs={images:["png","jpg","jpeg","ico","webp","avif"],media:["mp4","webm","ogg"],gltf:["gltf","glb"],json:["json","geojson"],gzipJson:["json.gzip","json.gz"],exr:["exr"],lottie:["lottie.json"]};class $s{constructor(t){u(this,"loadingManager"),u(this,"loaders",/* @__PURE__ */new Map),u(this,"loaderConfigs",/* @__PURE__ */new Map),u(this,"loadObj",[]),u(this,"delLoadArr",[]),u(this,"assets",/* @__PURE__ */new Map),u(this,"event",new p),u(this,"options"),u(this,"scene"),this.options=h({simpleTexture4deleted:!1,prefix:""},t),this.loadingManager=new Lt(()=>{},(t,e,n)=>{this.emit("progress",e,n)},t=>{console.warn(`Failed to load ${t}`)}),this.initLoaderConfigs()}initLoaderConfigs(){this.loaderConfigs.set("images",{create:t=>new Rt(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("media",{create:t=>new Gs(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gltf",{create:t=>new He(t),setPath:(t,e)=>t.setPath(e),requiresDraco:!0}),this.loaderConfigs.set("lottie",{create:t=>new qe(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gzipJson",{create:t=>new Ys(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("json",{create:t=>new Nt(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("exr",{create:t=>new We(t),setPath:(t,e)=>t.setPath(e)})}emit(t,...e){this.event.emit(t,...e)}on(t,e){this.event.on(t,e)}getAsset(t){const e=this.getAssetType(t);if(!e)return;const n=this.assets.get(t);if(!n){if(("images"===e||"media"===e||"exr"===e)&&this.options.simpleTexture4deleted&&this.delLoadArr.includes(t))return new w;console.warn(`Asset ${t} not found`)}return n}getAssetType(t){var e;const n=null==(e=t.split(".").pop())?void 0:e.toLowerCase();if(n){if(t.endsWith("lottie.json"))return"lottie";if(t.endsWith("json.gzip")||t.endsWith("json.gz"))return"gzipJson";for(const[t,e]of Object.entries(Xs))if(e.includes(n))return t}}getLoader(t,e){let n=t;if("gltf"===t&&(null==e?void 0:e.dracoPath)?n="dracoGltf":"json"!==t&&"gzipJson"!==t||"arraybuffer"!==(null==e?void 0:e.responseType)||(n=`${t}Buffer`),this.loaders.has(n))return this.loaders.get(n);const i="dracoGltf"===n?"gltf":"json"===n.replace("Buffer","")||"gzipJson"===n.replace("Buffer","")?n.replace("Buffer",""):n,s=this.loaderConfigs.get(i);if(!s)return null;let r;if("dracoGltf"===n){r=new He(this.loadingManager);const t=new Ve;t.setDecoderPath((null==e?void 0:e.dracoPath)||""),r.setDRACOLoader(t)}else r=s.create(this.loadingManager,e);return s.setPath&&this.options.prefix&&s.setPath(r,this.options.prefix),s.setResponseType&&(null==e?void 0:e.responseType)&&"dracoGltf"!==n&&s.setResponseType(r,e.responseType),this.loaders.set(n,r),r}add(t,e){"string"==typeof t&&(t=[t]),t.forEach(t=>{const n=h({src:t},e);this.loadObj.push(n)})}getSrcByAsset(t,e=this.assets){let n;return e.forEach((e,i)=>{e===t&&(n=i)}),n}get textureAssets(){const t=/* @__PURE__ */new Map;return this.assets.forEach((e,n)=>{(e instanceof w||e instanceof Ut||e.isVideoTexture)&&t.set(n,e)}),t}loadAll(){return d(this,null,function*(){const t=this.loadObj.filter(t=>!this.delLoadArr.includes(t.src));return yield Promise.all(t.map(t=>this.load(t.src,t)))})}load(t,e){return d(this,null,function*(){var n,i;const s=null!=(n=null==e?void 0:e.type)?n:this.getAssetType(t);if(!s)return;const r=!1!==(null==e?void 0:e.cache),o=Fe();if(r){if(this.assets.has(t))return this.assets.get(t);this.assets.set(t,o.promise)}const a=this.getLoader(s,e);try{const n=yield a.loadAsync(t);if(this.assets.set(t,n),o.resolve(n),"images"===s||"media"===s||"exr"===s||"lottie"===s){const t=null!=(i=null==e?void 0:e.anisotropy)?i:this.options.anisotropy;n.anisotropy=t}return n}catch(h){return o.reject(`Failed to load ${t}`),void this.assets.delete(t)}})}getUnusedAssets(){const{scene:t}=this.options;if(!t)return[...this.delLoadArr];const e=/* @__PURE__ */new Set,n=this.textureAssets;t.traverse(t=>{const i=t;if(i.material){(Array.isArray(i.material)?i.material:[i.material]).forEach(t=>{[t.map,t.emissiveMap,t.normalMap,t.roughnessMap,t.metalnessMap,t.aoMap].forEach(t=>{if(t){const i=this.getSrcByAsset(t,n);i&&e.add(i)}})})}});const i=new Set(this.textureAssets.keys());return e.forEach(t=>{i.delete(t)}),[...i,...this.delLoadArr]}dispose(){this.assets.forEach(t=>{t&&"function"==typeof t.dispose&&t.dispose()}),this.assets.clear(),this.loaders.forEach((t,e)=>{if("dracoGltf"===e&&t){const e=t.dracoLoader;e&&"function"==typeof e.dispose&&e.dispose()}t&&"function"==typeof t.dispose&&t.dispose()}),this.loaders.clear(),this.loaderConfigs.clear(),this.event.removeAllListeners(),this.delLoadArr.length=0,this.loadObj.length=0}}class Js extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get loader(){return this.controller}addLoader(t,e){const{loaderParams:n}=this.options,i=new $s(l(h({},n),{scene:t}));return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}class Ks{constructor(t){u(this,"pencil"),u(this,"materials",/* @__PURE__ */new Map),u(this,"fixBaseObjects",/* @__PURE__ */new Map),u(this,"materialBaseObjectMap",/* @__PURE__ */new Map),this.pencil=t}add(t,e){this.materials.set(t,e);const n={object3d:new Proxy({material:e},{set:(e,n,i)=>{var s;if("material"===n&&!(null==(s=this.pencil.composerController)?void 0:s.bloomComposerRenderIng)){const n=e.material;return e.material=i,this.materials.set(t,i),this.disposeMaterial(n),this.syncChangeMaterial(n,i),!0}return e[n]=i,!0}})};this.fixBaseObjects.set(t,n),this.pencil.event.emit("mList.add",{key:t,material:e,baseObject:n})}get(t){const e=this.materials.get(t);return e||console.warn(`Material with key "${t}" not found.`),e}getByName(t){for(const[,e]of this.materials.entries())if(e.name===t)return e;console.warn(`Material with name "${t}" not found.`)}getKey(t){for(const[e,n]of this.materials.entries())if(n===t)return e}getKeyByName(t){for(const[e,n]of this.materials.entries())if(n.name===t)return e;console.warn(`Material key with name "${t}" not found.`)}addMultiple(t,e){for(const[n,i]of Object.entries(e)){const e=`${t}#${n}`;i&&this.add(e,i)}}getMultiple(t){const e={},n=`${t}#`;let i=!1;for(const[s,r]of this.materials.entries())if(s.startsWith(n)){e[s.substring(n.length)]=r,i=!0}return i?e:null}copy(t,e,n={}){const i=this.get(t);if(!i)return console.warn(`Material with key "${t}" not found.`),null;const s=i.clone();return n.name&&(s.name=n.name),this.add(e,s),s}copyMultiple(t,e){const n={},i=`${t}#`;for(const[s,r]of this.materials.entries())if(s.startsWith(i)){const t=s.substring(i.length),o=r.clone();n[t]=o;const a=`${e}#${t}`;this.add(a,o)}return n}disposeMaterial(t){if(!t)return;const e=new Ke;e.track(Array.isArray(t)?t:[t]),e.dispose()}remove(t){const e=this.materials.get(t);e&&this.disposeMaterial(e),this.materials.delete(t),this.fixBaseObjects.delete(t),this.pencil.event.emit("mList.remove",{key:t,material:e})}removeByMaterial(t){[...this.materials.entries()].some(([e,n])=>n===t&&(this.remove(e),!0))}proxyBaseObject(t){const e=t.object3d;if(!e.material)return;this.applyColorSpaceToMaterials(e.material);const n=e=>{if("__isProxy"in e)return e;const n=new Proxy(e,{set:(e,n,i)=>{if("string"==typeof n&&!Number.isNaN(Number(n))){const s=Number(n);if(s>=0&&s<e.length){const n=e[s];return this.rmBaseObjectMap(t,n),e[s]=i,i&&(this.applyColorSpaceToMaterials(i),this.addBaseObjectMap(t)),!0}}return e[n]=i,!0}});return Object.defineProperty(n,"__isProxy",{value:!0,enumerable:!1}),n};t.materialList&&(Object.values(t.materialList).forEach(t=>{t&&this.applyColorSpaceToMaterials(t)}),t.materialList=new Proxy(t.materialList,{set:(e,n,i)=>{if("string"==typeof n){const s=e[n];return this.rmBaseObjectMap(t,s),e[n]=i,i&&(this.applyColorSpaceToMaterials(i),this.addBaseObjectMap(t)),!0}return e[n]=i,!0},get:(t,e)=>{if("string"==typeof e&&t[e]){const i=t[e];if(Array.isArray(i)){const s=n(i);return s!==i&&(t[e]=s),s}return i}return t[e]},deleteProperty:(e,n)=>{if("string"==typeof n&&e[n]){const i=e[n];this.rmBaseObjectMap(t,i)}return delete e[n],!0}}));const i=e.material,s="_enhancedMaterial";e[s]=i,Object.defineProperty(e,"material",{get:()=>{var t;const i=e[s];if(!(null==(t=this.pencil.composerController)?void 0:t.bloomComposerRenderIng)&&Array.isArray(i)){const t=n(i);return t!==i&&(e[s]=t),t}return i},set:n=>{var i;if(null==(i=this.pencil.composerController)?void 0:i.bloomComposerRenderIng)e[s]=n;else{if(t.materialList&&Object.values(t.materialList).includes(n))return e[s]=n,void t.handleMaterialChange(n);this.rmBaseObjectMap(t),e[s]=n,n&&this.applyColorSpaceToMaterials(n),this.addBaseObjectMap(t)}t.handleMaterialChange(n)},enumerable:!0,configurable:!0})}applyColorSpaceToMaterials(t){cn({material:t})}material2array(t){return Array.isArray(t)?t:[t]}addBaseObjectMap(t){const e=t.object3d;e.material&&([...Object.values(t.materialList),e.material].forEach(e=>{if(e){this.material2array(e).forEach(e=>{const n=this.materialBaseObjectMap.get(e);n?n.add(t):this.materialBaseObjectMap.set(e,/* @__PURE__ */new Set([t]))})}}),this.pencil.event.emit("mList.addBaseObjectMap"))}rmBaseObjectMap(t,e,n=!0){const i=e&&this.material2array(e);this.materialBaseObjectMap.forEach((e,s)=>{i&&!i.includes(s)||e.has(t)&&(e.delete(t),0===e.size&&n&&(this.materialBaseObjectMap.delete(s),this.disposeMaterial(s)))}),this.pencil.event.emit("mList.rmBaseObjectMap")}getBaseObjectMap(t){return this.materialBaseObjectMap.get(t)||/* @__PURE__ */new Set}syncChangeMaterial(t,e){const n=this.materialBaseObjectMap.get(t);n&&n.forEach(n=>{const i=n.object3d,s=i.material;if(Array.isArray(s)){const n=s.indexOf(t);-1!==n&&(s[n]=e)}else s===t&&(i.material=e);n.materialList&&Object.keys(n.materialList).forEach(i=>{var s;const r=null==(s=n.materialList)?void 0:s[i];if(Array.isArray(r)){const n=r.indexOf(t);-1!==n&&(r[n]=e)}else r===t&&n.materialList&&(n.materialList[i]=e)})})}dispose(){const t=new Ke;t.track([...this.materials.values()]),t.dispose(),this.materials.clear(),this.fixBaseObjects.clear(),this.materialBaseObjectMap.clear()}}class Qs extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get mList(){return this.controller}addMList(t,e){const{pencil:n}=this.options,i=new Ks(n);return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const tr={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:on.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1};class er{constructor(t){u(this,"renderer"),u(this,"options"),this.options=t;const{width:e,height:n,rendererParams:i}=t,{alpha:s,devicePixelRatio:r,antialias:o,powerPreference:a,toneMappingExposure:h,outputColorSpace:l,logarithmicDepthBuffer:c,preserveDrawingBuffer:d,stencil:p,depth:f}=i,m=new jt({alpha:s,antialias:o,powerPreference:a,logarithmicDepthBuffer:c,preserveDrawingBuffer:d,stencil:p,depth:f});m.setSize(e,n),m.setPixelRatio(r),m.toneMappingExposure=h,m.outputColorSpace=l,this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t,e){this.renderer.render(t,e)}setViewport(t){var e,n;const{x:i,y:s,width:r,height:o}=t,a=null!=(e=t.scissor)&&e,h=null!=(n=t.scissorTest)&&n;this.renderer.setViewport(i,s,r,o),a&&(this.renderer.setScissor(i,s,r,o),this.renderer.setScissorTest(h))}dispose(){var t,e,n;this.setSize(0,0),null==(t=this.renderer)||t.clear(),null==(e=this.renderer)||e.dispose(),null==(n=this.renderer)||n.forceContextLoss()}}class nr extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get scene(){return this.controller}addScene(t,e){const n=new Ot;return(null==t?void 0:t.background)&&(n.background=t.background),this.addController(n,e)}removePage(t){super.removePage(t,t=>{const e=new Ke;e.track(t),e.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.visible=e})}}class ir{constructor(t){u(this,"controls"),u(this,"event",new p);const{renderer:e,scene:n,camera:i}=t,s=new Ze(i,e.domElement);if(s.getHelper){const t=s.getHelper();if(n.add(t),+Dt<170){const t=s._root;t.dispose=()=>{t.traverse(t=>{t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})},s.dispose=()=>{s.disconnect(),t.dispose()}}}else s instanceof v&&n.add(s);this.controls=s,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,n=null;const i=this.controls;i.addEventListener("change",()=>{const t=i.object;void 0!==t&&this.event.emit("change",t)}),i.addEventListener("mouseDown",()=>{const s=i.object;t=s.position.clone(),e=s.rotation.clone(),n=s.scale.clone(),this.event.emit("mouseDown",s)}),i.addEventListener("mouseUp",()=>{const s=i.object;if(void 0!==s)switch(i.getMode()){case"translate":t.equals(s.position)||this.event.emit("translate",s,s.position,t);break;case"rotate":e.equals(s.rotation)||this.event.emit("rotate",s,s.rotation,e);break;case"scale":n.equals(s.scale)||this.event.emit("scale",s,s.scale,n)}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),null==(t=this.controls)||t.dispose()}}const sr={antialias:!0,devicePixelRatio:window.devicePixelRatio};class rr{constructor(t){u(this,"renderer"),u(this,"options"),this.options=t;const{width:e,height:n,rendererParams:i,renderer:s}=t,{devicePixelRatio:r,antialias:o}=i,a=new s({antialias:o});a.setSize(e,n),a.setPixelRatio(r),this.renderer=a}setSize(t,e){this.renderer.setSize(t,e)}render(t,e){this.renderer.render(t,e)}dispose(){var t,e;this.setSize(1,1),null==(t=this.renderer)||t.clear(),null==(e=this.renderer)||e.dispose()}}const or=class t{constructor(e){var n,i;u(this,"options"),u(this,"composerController"),u(this,"rendererController"),u(this,"cssRendererController"),u(this,"cameraController"),u(this,"controlsController"),u(this,"transformController"),u(this,"sceneController"),u(this,"helperController"),u(this,"loaderController"),u(this,"leadController"),u(this,"mListController"),u(this,"stats"),u(this,"resizeObserver"),u(this,"raycaster",new wt),u(this,"maxBackufferArea",33177600),u(this,"installPlugins",/* @__PURE__ */new Map),u(this,"_cameraPositon",new y),u(this,"_cameraTarget",new y),u(this,"event",new p),u(this,"timer",new Ft),u(this,"userData",{}),u(this,"TweenRaf"),u(this,"pageActiveIndex",0),u(this,"pages",new Ge),u(this,"userSetDprCache",1),u(this,"viewPadding",[0,0,0,0]),u(this,"pipCameraControls"),u(this,"_isDispose",!1),this.event.setMaxListeners(1/0),null==(i=(n=this.timer).connect)||i.call(n,document),this.options=f(t.options,e,{isMergeableObject:Cn}),this.userSetDprCache=this.options.renderer.devicePixelRatio;const{container:s,stats:r,transformControls:o}=this.options;if(this.init(),this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),o&&this.initTransformControls(),r){const t=new m({horizontal:!1});t.dom.style.position="absolute",t.init(this.renderer),s.appendChild(t.dom),this.stats=t}this.initResizeObserver(),this.tweenUpdateRaf()}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?2:this.renderer.capabilities.getMaxAnisotropy()}get controls(){return this.controlsController.cameraControls}get cameraPositon(){return this.controls.getPosition(this._cameraPositon,!1)}get cameraTarget(){return this.controls.getTarget(this._cameraTarget,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}get loader(){return this.loaderController.loader}get lead(){return this.leadController.lead}get mList(){return this.mListController.mList}tweenUpdateRaf(){Vt.update(),this.TweenRaf=requestAnimationFrame(this.tweenUpdateRaf.bind(this))}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):"function"==typeof t.install&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}addPage({sceneOptions:t,cameraOptions:e}={}){const n=this.pages.getMinDisabledLayer(),i=this.cameraController.addPerspectiveCamera(e,n),s=this.sceneController.addScene(t,n);s.add(i),this.controlsController.addCameraControls(i,n),this.loaderController.addLoader(s,n);const r=this.mListController.addMList(null,n);return this.leadController.addLead(s,r,n),this.pages.enable(n),n}removePage(t){this.controlsController.removePage(t),this.loaderController.removePage(t),this.leadController.removePage(t),this.cameraController.removePage(t),this.sceneController.removePage(t),this.mListController.removePage(t),this.pages.disable(t),this.pageActiveIndex===t&&(this.render(),this.showPage(0))}showPage(t){var e;if(t===this.pageActiveIndex)return;const n=this.scene;this.sceneController.setPageActive(t),n&&(null==(e=this.cssRendererController)||e.render(n,this.camera)),this.cameraController.setPageActive(t),this.controlsController.setPageActive(t),this.loaderController.setPageActive(t),this.mListController.setPageActive(t),this.leadController.setPageActive(t),this.pageActiveIndex=t}init(){var t;const{container:e,WebGPUTHREE:n,helper:i,viewHelper:s,renderer:r,controls:o,loader:a}=this.options,{width:c,height:u}=this.getSize(),d=n?new rr({width:c,height:u,renderer:this.options.WebGPURenderer,rendererParams:sr}):new er({width:c,height:u,rendererParams:l(h({},r),{antialias:!1})});this.rendererController=d;const p=new Je({width:c,height:u}),f=new nr({}),m=new js({controlsParams:{domElement:null!=(t=null==o?void 0:o.domElement)?t:d.renderer.domElement}}),y=new Js({loaderParams:h({anisotropy:this.maxAnisotropy},a)}),g=new Qs({pencil:this}),x=new Zs({pencil:this});this.sceneController=f,this.cameraController=p,this.controlsController=m,this.loaderController=y,this.mListController=g,this.leadController=x;const b=this.addPage({sceneOptions:this.options.scene,cameraOptions:this.options.camera});if(this.showPage(b),i){const t=new Vs({container:e,sceneController:f,cameraController:p});t.add(f.scene),this.helperController=t,s&&t.addViewHelper()}e.appendChild(d.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,ssao:n,ssaoParams:i,composer:s}=this.options,r=new Vi({rendererController:this.rendererController,sceneController:this.sceneController,cameraController:this.cameraController,composerParams:s});this.composerController=r,t&&r.addBloomPass(h({},e)),n&&r.addSSAOPass(h({},i)),r.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:n,css2DRendererParams:i,css3DRendererParams:s}=this.options;if(e||n){const r=new Is(t,i);e&&r.addRenderer("css2d",i),n&&r.addRenderer("css3d",s),this.cssRendererController=r}}initTransformControls(){const t=new ir({camera:this.camera,renderer:this.renderer,scene:this.scene});t.event.on("mouseDown",()=>{var t;null==(t=this.controlsController)||t.disable()}),t.event.on("mouseUp",()=>{var t;null==(t=this.controlsController)||t.enable()}),this.transformController=t}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=new ResizeObserver(t=>{for(const e of t){const t=e.contentRect;this.handeleResize(t.width,t.height),this.setDevicePixelRatio(this.userSetDprCache)}});e.observe(t),this.resizeObserver=e}handeleResize(t,e,n=!0){const{rendererController:i,cameraController:s,composerController:r,cssRendererController:o,leadController:a}=this,h=this.renderer.getSize(new N);h.x===t&&h.y===e||(s.setSize(t,e),i.setSize(t,e),null==r||r.setSize(t,e),null==o||o.setSize(t,e),a.setSize(t,e),this.installPlugins.forEach(n=>{var i;null==(i=n.setSize)||i.call(n,t,e)}),this.viewPadding.some(t=>0!==t)&&this.setViewPadding(...this.viewPadding),this.render(),n&&this.event.emit("resize",{width:t,height:e}))}setDevicePixelRatio(t){var e;this.userSetDprCache=t;const{width:n,height:i}=this.getSize();let s=Math.sqrt(this.maxBackufferArea/(n*i));s=(100*s|0)/100;const r=Math.min(t,s);r!==t&&console.warn("maxBackufferArea:",this.maxBackufferArea," the pixel ratio is set to",r);r!==this.renderer.getPixelRatio()&&(this.rendererController.setPixelRatio(r),null==(e=this.composerController)||e.setPixelRatio(r),this.viewPadding.some(t=>0!==t)&&this.setViewPadding(...this.viewPadding))}setViewPadding(t=0,e=0,n=0,i=0){const{width:s,height:r}=this.renderer.getSize(new N),o={x:i,y:n,width:s-i-e,height:r-t-n};this.rendererController.setViewport(o),this.cameraController.setAspect(o.width/o.height),this.viewPadding=[t,e,n,i]}pick(t,e,n=!0){const{raycaster:i,options:s}=this,{container:r}=s,o=new N,a=r.getBoundingClientRect();if(o.x=(t.clientX-a.left)/(a.right-a.left)*2-1,o.y=-(t.clientY-a.top)/(a.bottom-a.top)*2+1,this.camera&&this.scene){i.setFromCamera(o,this.camera);const t=i.intersectObjects(e||this.scene.children,n);if(t.length)return{object:t[0].object,index:t[0].index,intersects:t}}}render(){var t,e,n,i,s,r;if(!this.camera||!this.scene)return;this.event.emit("beforeRender"),this.timer.update(),Vt.update();const o=this.timer.getDelta(),a=this.timer.getElapsed();this.controlsController.update(o,a),this.leadController.update(o,a),this.installPlugins.forEach(t=>{var e;null==(e=t.update)||e.call(t,o,a)}),null==(t=this.helperController)||t.update(o,this.controlsController,this.cameraTarget),(null==(e=this.composerController)?void 0:e.active)?this.composerController.render():null==(n=this.rendererController)||n.render(this.scene,this.camera),null==(i=this.helperController)||i.renderViewHelper(this.renderer),null==(s=this.cssRendererController)||s.render(this.scene,this.camera),null==(r=this.stats)||r.update(),this.event.emit("render",{delta:o,elapsed:a})}start(){var t;window.cancelAnimationFrame(this.TweenRaf),null==(t=this.renderer)||t.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){var t;this.tweenUpdateRaf(),null==(t=this.renderer)||t.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){this.composerController.pipViewportState=t;let e=this.pipCameraControls;if(t){const{width:n,height:i}=this.getSize(),s=new DOMRect(t.x/n,(i-t.y-t.height)/i,t.width/n,t.height/i);if(e)e.enabled=!0,e.camera.position.copy(this.camera.position);else{const n=this.cameraController.cloneCamera(31);n.aspect=t.width/t.height,n.updateProjectionMatrix(),e=this.controlsController.addCameraControls(n,this.sceneController.activeIndex),e.addEventListener("update",()=>{this.controls.enabled=!1}),e.addEventListener("sleep",()=>{this.controls.enabled=!0}),this.pipCameraControls=e}e.interactiveArea=s}}dispose(){var t,e,n,i,s,r,o,a,h,l,c,u,d,p;this.handeleResize(1,1,!1),this.stop(),this.timer.dispose(),Vt.removeAll(),this.event.removeAllListeners(),null==(t=this.resizeObserver)||t.unobserve(this.options.container),this.installPlugins.forEach(t=>{var e;null==(e=t.dispose)||e.call(t)}),null==(e=this.controlsController)||e.dispose(),null==(n=this.transformController)||n.dispose(),null==(i=this.cssRendererController)||i.dispose(),null==(s=this.sceneController)||s.dispose(),null==(r=this.cameraController)||r.dispose(),null==(o=this.helperController)||o.dispose(),null==(a=this.composerController)||a.dispose(),null==(h=this.rendererController)||h.dispose(),null==(l=this.loaderController)||l.dispose(),null==(c=this.leadController)||c.dispose(),null==(u=this.mListController)||u.dispose(),this.cssRendererController=void 0,this.installPlugins.clear(),null==(d=this.stats)||d.dom.remove(),null==(p=this.renderer)||p.domElement.remove(),this._isDispose=!0}};u(or,"options",{stats:Ye,helper:Ye,viewHelper:Ye,controls:!0,transformControls:Ye,renderer:tr,composer:{multisampling:4,premultiplieAlpha:!1},scene:{background:null},camera:$e,bloom:!1,bloomParams:{threshold:0,strength:.4,radius:.1,bloomAlphaType:0},ssao:!1,loader:{prefix:""},ssaoParams:{kernelRadius:8,minDistance:.005,maxDistance:.1},css2DRenderer:!1,css2DRendererParams:h({},Fs),css3DRenderer:!1,css3DRendererParams:h({},Fs)});let ar=or;const hr={Scan:class{constructor(t,e={}){u(this,"options"),u(this,"object"),u(this,"uniforms"),u(this,"tween"),this.object=t,this.options=h(h({},{color:16777215,opacity:1,lineNum:10,lineWidth:1,lineHieght:10,fade:!1,fadeType:2,radius:0,range:new N(0,1),vertical:!1,step:0,pos:"bottom",duration:5e3,yoyo:!1,repeat:0}),e)}initMaterial(){const{color:t,lineNum:e,lineWidth:n,lineHieght:i,fade:s,fadeType:r,radius:o,range:a,vertical:h,step:l,opacity:c,exclude:u}=this.options,d={field:{value:new ct(0,0,0,0)},color:{value:new ht(t)},opacity:{value:c},lineNum:{value:e},lineWidth:{value:n},lineHieght:{value:i},sizeNum:{value:new y(o,o,o)},objPos:{value:new y(0,0,0)},fade:{value:s},fadeType:{value:r},range:{value:a},angle:{value:0},stepNum:{value:l}};if(!o){const{size:t}=this.object.getSize();d.sizeNum.value.copy(t)}this.uniforms=d,this.object.object3d.traverse(t=>{const e=t;!e.material||u&&u.includes(e)||(e.userData.materialO?e.material=e.userData.materialO.clone():e.userData.materialO=Array.isArray(e.material)?e.material.map(t=>t.clone()):e.material.clone(),Array.isArray(e.material)?e.material.forEach(t=>{h?this.setVerticalMaterial(t):this.setMaterial(t)}):h?this.setVerticalMaterial(e.material):this.setMaterial(e.material))})}setMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineNum=e.lineNum,t.uniforms.lineWidth=e.lineWidth,t.uniforms.sizeNum=e.sizeNum,t.uniforms.fade=e.fade,t.uniforms.fadeType=e.fadeType,t.uniforms.range=e.range,t.uniforms.stepNum=e.stepNum,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform int lineNum;\n uniform vec3 sizeNum;\n uniform float lineWidth;\n uniform float fade;\n uniform int fadeType;\n uniform vec2 range;\n uniform int stepNum;\n varying vec4 vWorldPos;\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n float height = sizeNum.y;\n bool isTop = field.y > vWorldPos.y;\n float worldDist = distance(field.y, vWorldPos.y);\n // bool isMix = isTop?\n // worldDist >= sizeNum.y * (1.0 -range):\n // worldDist <= sizeNum.y * range;\n float wMin = range.x * height;\n float wMax = range.y * height;\n bool isMix = worldDist >= wMin && worldDist <= wMax && field.w > 0.0;\n\n if(isMix){\n float stepf = sizeNum.y / float(lineNum);\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n for(int i=0; i<lineNum; i++){\n float fw = field.w- stepf * float(i) + (stepNum > 0? lineWidth : 0.0);\n float fadeout = smoothstep(fw -lineWidth, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n if(fade ==1.0 && fadeType == 2){\n fadeout = float(lineNum-i) * fadeout/ float(lineNum);\n }\n if (fade ==1.0 && fadeType == 1) {\n fadeout -= smoothstep(wMin, wMax, worldDist);\n }\n if(fadeout != 0.0){\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n break;\n }\n }\n }\n ")},t.needsUpdate=!0}setVerticalMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineNum=e.lineNum,t.uniforms.lineWidth=e.lineWidth,t.uniforms.lineHieght=e.lineHieght,t.uniforms.sizeNum=e.sizeNum,t.uniforms.fade=e.fade,t.uniforms.range=e.range,t.uniforms.angle=e.angle,t.uniforms.objPos=e.objPos,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform int lineNum;\n uniform vec3 sizeNum;\n uniform float lineWidth;\n uniform float lineHieght;\n uniform float fade;\n uniform vec2 range;\n uniform float angle;\n uniform vec3 objPos;\n varying vec4 vWorldPos;\n\n float aa(float x, float z,float a) {\n return(x - objPos.x)*cos(a) - (z - objPos.z)*sin(a) + objPos.x ;\n }\n\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n\n float worldDist = distance(field.y, vWorldPos.y);\n bool isTop = field.x > vWorldPos.x;\n float height = sizeNum.y;\n // bool isMix = isTop?\n // worldDist >= sizeNum.y * (1.0 -range):\n // worldDist <= sizeNum.y * range;\n float wMin = range.x * height;\n float wMax = range.y * height;\n bool isMix = worldDist >= wMin && worldDist <= wMax;\n\n\n if(isMix){\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n float gap =0.0;\n float sx= sqrt(pow(sizeNum.x,2.0)+pow(sizeNum.z,2.0));\n float worldDistx = distance(field.x, aa(vWorldPos.x,vWorldPos.z,angle));\n float stepf = sx / float(lineNum);\n float gapWidth = stepf-lineWidth;\n for(int i=0; i<lineNum; i++){\n float fw = sx - stepf * float(i);\n gap = smoothstep(fw - gapWidth, fw, worldDistx);\n gap -= smoothstep(fw, fw + f, worldDistx);\n gap = gap != 0.0 ? 1.0 : 0.0;\n if(gap != 0.0){\n // gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, gap);\n break;\n\n }\n }\n if(gap == 0.0){\n float fw = field.w;\n float fadeout = smoothstep(fw - lineHieght, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n }\n }\n\n ")},t.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(t=>{const e=t;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(t={}){this.stop();const e=Fe(!0),{object:n,uniforms:i}=this,{lineNum:s,step:r,lineWidth:a,pos:l,duration:c}=h(h({},this.options),t),{min:u,max:d,size:p}=n.getSize();let f=s,m=a;r>0&&(f=1,m=p.y/r);const g=i.sizeNum.value.y*(f>1?2:1);return this.tween=new Vt.Tween({latest:0}).to({latest:1},c).onStart(()=>{const t=new y;"bottom"===l?t.set(u.x-.001,u.y-.001,u.z-.001):"top"===l&&t.set(d.x+.001,d.y+.001,d.z+.001);const e=n.pencil.controls.azimuthAngle||0,s=this.object.object3d.position.clone();if(e){const n=Math.sqrt(o(p.x,2)+o(p.z,2))/2;t.x=s.x+n,t.z=s.z+n;const i=(new y).subVectors(t,s),r=new y(0,1,0);i.applyAxisAngle(r,e),t.addVectors(s,i)}i.objPos.value.copy(s),i.field.value.set(t.x,t.y,t.z,0),i.angle.value=e,i.lineNum.value=f,i.lineWidth.value=m}).onUpdate(({latest:t})=>{i.field.value.w=r>0?Math.floor(t*r)/r*g:t*g}).onStop(()=>{i.field.value.w=0,e.reject("stop")}).onComplete(()=>{e.resolve()}).start(),e.promise}checkRepeat(){return d(this,arguments,function*(t={}){const{yoyo:e,repeat:n,pos:i}=h(h({},this.options),t);n===this.options.repeat&&this.initMaterial();const{err:s}=yield this.play(t);if(s)this.resetMaterial();else if(n){let t=i;e&&(t="bottom"===t?"top":"bottom"),yield this.checkRepeat({pos:t,repeat:n===1/0?-1:n-1})}else this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}},Scan2:class{constructor(t,e={}){u(this,"options"),u(this,"object"),u(this,"uniforms"),u(this,"tween"),this.object=t,this.options=h(h({},{color:16777215,lineWidth:2,opacity:.5,fade:!1,position:new y(0,0,0),duration:5e3,repeat:0}),e)}initMaterial(){const{exclude:t}=this.options,e={field:{value:new ct(0,0,0,1e-4)},color:{value:new ht(this.options.color)},opacity:{value:this.options.opacity},lineWidth:{value:this.options.lineWidth}};this.uniforms=e,this.object.object3d.traverse(e=>{const n=e;!n.material||t&&t.includes(n)||(n.userData.materialO?n.material=n.userData.materialO:n.userData.materialO=Array.isArray(n.material)?n.material.map(t=>t.clone()):n.material.clone(),Array.isArray(n.material)?n.material.forEach(t=>{this.setMaterial(t)}):this.setMaterial(n.material))})}setMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineWidth=e.lineWidth,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform float lineWidth;\n \n varying vec4 vWorldPos;\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n \n float worldDist = distance(field.xyz, vWorldPos.xyz);\n float fadeoutWidth = lineWidth;\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n\n float fw = field.w;\n float fadeout = smoothstep(fw - fadeoutWidth, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n \n ")},t.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(t=>{const e=t;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(){this.stop();const t=Fe(!0),{object:e,uniforms:n}=this,{position:i,duration:s}=this.options;let{radius:r}=this.options;if(!r){const{size:t}=e.getSize();r=Math.max(t.x,t.y,t.z)}return this.tween=new Vt.Tween({a:1e-4}).to({a:1},s).onStart(()=>{n.field.value.set(i.x,i.y,i.z,1e-4),this.options.fade&&(n.opacity.value=this.options.opacity)}).onUpdate(({a:t})=>{n.field.value.w=t*r,this.options.fade&&(n.opacity.value=(1-t)*this.options.opacity)}).onStop(()=>{n.field.value.w=0,t.reject("stop")}).onComplete(()=>{t.resolve()}).start(),t.promise}checkRepeat(){return d(this,arguments,function*(t={}){const{repeat:e}=h(h({},this.options),t);e===this.options.repeat&&this.initMaterial();const{err:n}=yield this.play();n?this.resetMaterial():e?yield this.checkRepeat({repeat:e===1/0?-1:e-1}):this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}}},lr=t=>{const e=new S;return Object.keys(t).forEach(n=>{"groups"===n?t[n].forEach(t=>{e.addGroup(t.start,t.count,t.materialIndex)}):"index"===n?e.setIndex(new D(t[n].array,t[n].itemSize)):"globalCenter"===n?e.userData.globalCenter=t.globalCenter:e.setAttribute(n,new D(t[n].array,t[n].itemSize))}),e},cr='var t=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,o=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),a=t=>{throw TypeError(t)},h=Math.pow,l=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,u=(t,e)=>{for(var n in e||(e={}))r.call(e,n)&&l(t,n,e[n]);if(i)for(var n of i(e))s.call(e,n)&&l(t,n,e[n]);return t},c=(t,i)=>e(t,n(i)),d=(t,e)=>{var n={};for(var o in t)r.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&i)for(var o of i(t))e.indexOf(o)<0&&s.call(t,o)&&(n[o]=t[o]);return n},p=(t,e,n)=>l(t,"symbol"!=typeof e?e+"":e,n),f=function(t,e){this[0]=t,this[1]=e},y=t=>{var e,n=t[o("asyncIterator")],i=!1,r={};return null==n?(n=t[o("iterator")](),e=t=>r[t]=e=>n[t](e)):(n=n.call(t),e=t=>r[t]=e=>{if(i){if(i=!1,"throw"===t)throw e;return e}return i=!0,{done:!1,value:new f(new Promise(i=>{var r=n[t](e);r instanceof Object||a("Object expected"),i(r)}),1)}}),r[o("iterator")]=()=>r,e("next"),"throw"in n?e("throw"):r.throw=t=>{throw t},"return"in n&&e("return"),r};!function(){"use strict";const t="182",e=1001,n="srgb",i="srgb-linear",r="linear",s="srgb",o=7680,a=2e3;function l(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const f={};function m(...t){const e="THREE."+t.shift();console.warn(e,...t)}function g(...t){const e="THREE."+t.shift();console.error(e,...t)}function x(...t){const e=t.join(" ");e in f||(f[e]=!0,m(...t))}class b{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return void 0!==n&&(void 0!==n[t]&&-1!==n[t].indexOf(e))}removeEventListener(t,e){const n=this._listeners;if(void 0===n)return;const i=n[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}dispatchEvent(t){const e=this._listeners;if(void 0===e)return;const n=e[t.type];if(void 0!==n){t.target=this;const e=n.slice(0);for(let n=0,i=e.length;n<i;n++)e[n].call(this,t);t.target=null}}}const w=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let v=1234567;const M=Math.PI/180,S=180/Math.PI;function A(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(w[255&t]+w[t>>8&255]+w[t>>16&255]+w[t>>24&255]+"-"+w[255&e]+w[e>>8&255]+"-"+w[e>>16&15|64]+w[e>>24&255]+"-"+w[63&n|128]+w[n>>8&255]+"-"+w[n>>16&255]+w[n>>24&255]+w[255&i]+w[i>>8&255]+w[i>>16&255]+w[i>>24&255]).toLowerCase()}function z(t,e,n){return Math.max(e,Math.min(n,t))}function _(t,e){return(t%e+e)%e}function T(t,e,n){return(1-n)*t+n*e}function B(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function P(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const C={DEG2RAD:M,RAD2DEG:S,generateUUID:A,clamp:z,euclideanModulo:_,mapLinear:function(t,e,n,i,r){return i+(t-e)*(r-i)/(n-e)},inverseLerp:function(t,e,n){return t!==e?(n-t)/(e-t):0},lerp:T,damp:function(t,e,n,i){return T(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(_(t,2*e)-e)},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(v=t);let e=v+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*M},radToDeg:function(t){return t*S},isPowerOfTwo:function(t){return!(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,n,i,r){const s=Math.cos,o=Math.sin,a=s(n/2),h=o(n/2),l=s((e+i)/2),u=o((e+i)/2),c=s((e-i)/2),d=o((e-i)/2),p=s((i-e)/2),f=o((i-e)/2);switch(r){case"XYX":t.set(a*u,h*c,h*d,a*l);break;case"YZY":t.set(h*d,a*u,h*c,a*l);break;case"ZXZ":t.set(h*c,h*d,a*u,a*l);break;case"XZX":t.set(a*u,h*f,h*p,a*l);break;case"YXY":t.set(h*p,a*u,h*f,a*l);break;case"ZYZ":t.set(h*f,h*p,a*u,a*l);break;default:m("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:P,denormalize:B};class E{constructor(t=0,e=0){E.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(z(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,s=this.y-t.y;return this.x=r*n-s*i+t.x,this.y=r*i+s*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class k{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,r,s,o){let a=n[i+0],h=n[i+1],l=n[i+2],u=n[i+3],c=r[s+0],d=r[s+1],p=r[s+2],f=r[s+3];if(o<=0)return t[e+0]=a,t[e+1]=h,t[e+2]=l,void(t[e+3]=u);if(o>=1)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(u!==f||a!==c||h!==d||l!==p){let t=a*c+h*d+l*p+u*f;t<0&&(c=-c,d=-d,p=-p,f=-f,t=-t);let e=1-o;if(t<.9995){const n=Math.acos(t),i=Math.sin(n);e=Math.sin(e*n)/i,a=a*e+c*(o=Math.sin(o*n)/i),h=h*e+d*o,l=l*e+p*o,u=u*e+f*o}else{a=a*e+c*o,h=h*e+d*o,l=l*e+p*o,u=u*e+f*o;const t=1/Math.sqrt(a*a+h*h+l*l+u*u);a*=t,h*=t,l*=t,u*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,s){const o=n[i],a=n[i+1],h=n[i+2],l=n[i+3],u=r[s],c=r[s+1],d=r[s+2],p=r[s+3];return t[e]=o*p+l*u+a*d-h*c,t[e+1]=a*p+l*c+h*u-o*d,t[e+2]=h*p+l*d+o*c-a*u,t[e+3]=l*p-o*u-a*c-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,i=t._y,r=t._z,s=t._order,o=Math.cos,a=Math.sin,h=o(n/2),l=o(i/2),u=o(r/2),c=a(n/2),d=a(i/2),p=a(r/2);switch(s){case"XYZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"YXZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"ZXY":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"ZYX":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"YZX":this._x=c*l*u+h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u-c*d*p;break;case"XZY":this._x=c*l*u-h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u+c*d*p;break;default:m("Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],s=e[1],o=e[5],a=e[9],h=e[2],l=e[6],u=e[10],c=n+o+u;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(s-i)*t}else if(n>o&&n>u){const t=2*Math.sqrt(1+n-o-u);this._w=(l-a)/t,this._x=.25*t,this._y=(i+s)/t,this._z=(r+h)/t}else if(o>u){const t=2*Math.sqrt(1+o-n-u);this._w=(r-h)/t,this._x=(i+s)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+u-n-o);this._w=(s-i)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<1e-8?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(z(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,i=t._y,r=t._z,s=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=n*l+s*o+i*h-r*a,this._y=i*l+s*a+r*o-n*h,this._z=r*l+s*h+n*a-i*o,this._w=s*l-n*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(e<=0)return this;if(e>=1)return this.copy(t);let n=t._x,i=t._y,r=t._z,s=t._w,o=this.dot(t);o<0&&(n=-n,i=-i,r=-r,s=-s,o=-o);let a=1-e;if(o<.9995){const t=Math.acos(o),h=Math.sin(t);a=Math.sin(a*t)/h,e=Math.sin(e*t)/h,this._x=this._x*a+n*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+s*e,this._onChangeCallback()}else this._x=this._x*a+n*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+s*e,this.normalize();return this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class N{constructor(t=0,e=0,n=0){N.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(O.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(O.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,s=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*s,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*s,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*s,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z,a=t.w,h=2*(s*i-o*n),l=2*(o*e-r*i),u=2*(r*n-s*e);return this.x=e+a*h+s*u-o*l,this.y=n+a*l+o*h-r*u,this.z=i+a*u+r*l-s*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this.z=z(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this.z=z(this.z,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,s=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*s-n*a,this.z=n*o-i*s,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return I.copy(this).projectOnVector(t),this.sub(I)}reflect(t){return this.sub(I.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(z(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const I=new N,O=new k;class F{constructor(t,e,n,i,r,s,o,a,h){F.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,o,a,h)}set(t,e,n,i,r,s,o,a,h){const l=this.elements;return l[0]=t,l[1]=i,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=n,l[7]=s,l[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],o=n[3],a=n[6],h=n[1],l=n[4],u=n[7],c=n[2],d=n[5],p=n[8],f=i[0],y=i[3],m=i[6],g=i[1],x=i[4],b=i[7],w=i[2],v=i[5],M=i[8];return r[0]=s*f+o*g+a*w,r[3]=s*y+o*x+a*v,r[6]=s*m+o*b+a*M,r[1]=h*f+l*g+u*w,r[4]=h*y+l*x+u*v,r[7]=h*m+l*b+u*M,r[2]=c*f+d*g+p*w,r[5]=c*y+d*x+p*v,r[8]=c*m+d*b+p*M,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*s*l-e*o*h-n*r*l+n*o*a+i*r*h-i*s*a}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8],u=l*s-o*h,c=o*a-l*r,d=h*r-s*a,p=e*u+n*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=u*f,t[1]=(i*h-l*n)*f,t[2]=(o*n-i*s)*f,t[3]=c*f,t[4]=(l*e-i*a)*f,t[5]=(i*r-o*e)*f,t[6]=d*f,t[7]=(n*a-h*e)*f,t[8]=(s*e-n*r)*f,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,r,s,o){const a=Math.cos(r),h=Math.sin(r);return this.set(n*a,n*h,-n*(a*s+h*o)+s+t,-i*h,i*a,-i*(-h*s+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(R.makeScale(t,e)),this}rotate(t){return this.premultiply(R.makeRotation(-t)),this}translate(t,e){return this.premultiply(R.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const R=new F,V=(new F).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),U=(new F).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function L(){const t={enabled:!0,workingColorSpace:i,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===s&&(t.r=D(t.r),t.g=D(t.g),t.b=D(t.b)),this.spaces[e].primaries!==this.spaces[n].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===s&&(t.r=X(t.r),t.g=X(t.g),t.b=X(t.b)),t):t},workingToColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},colorSpaceToWorking:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return""===t?r:this.spaces[t].transfer},getToneMappingMode:function(t){return this.spaces[t].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,n){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(e,n){return x("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(e,n)},toWorkingColorSpace:function(e,n){return x("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(e,n)}},e=[.64,.33,.3,.6,.15,.06],o=[.2126,.7152,.0722],a=[.3127,.329];return t.define({[i]:{primaries:e,whitePoint:a,transfer:r,toXYZ:V,fromXYZ:U,luminanceCoefficients:o,workingColorSpaceConfig:{unpackColorSpace:n},outputColorSpaceConfig:{drawingBufferColorSpace:n}},[n]:{primaries:e,whitePoint:a,transfer:s,toXYZ:V,fromXYZ:U,luminanceCoefficients:o,outputColorSpaceConfig:{drawingBufferColorSpace:n}}}),t}const q=L();function D(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function X(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let Z;class j{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let n;if(t instanceof HTMLCanvasElement)n=t;else{void 0===Z&&(Z=l("canvas")),Z.width=t.width,Z.height=t.height;const e=Z.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),n=Z}return n.toDataURL(e)}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=l("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*D(r[t]/255);return n.putImageData(i,0,0),e}if(t.data){const e=t.data.slice(0);for(let t=0;t<e.length;t++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[t]=Math.floor(255*D(e[t]/255)):e[t]=D(e[t]);return{data:e,width:t.width,height:t.height}}return m("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let G=0;class J{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:G++}),this.uuid=A(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return"undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):"undefined"!=typeof VideoFrame&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):null!==e?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){!0===t&&this.version++}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.images[this.uuid])return t.images[this.uuid];const n={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,n=i.length;e<n;e++)i[e].isDataTexture?t.push(W(i[e].image)):t.push(W(i[e]))}else t=W(i);n.url=t}return e||(t.images[this.uuid]=n),n}}function W(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?j.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(m("Texture: Unable to serialize Texture."),{})}let Y=0;const $=new N;class H extends b{constructor(t=H.DEFAULT_IMAGE,e=H.DEFAULT_MAPPING,n=1001,i=1001,r=1006,s=1008,o=1023,a=1009,h=H.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Y++}),this.uuid=A(),this.name="",this.source=new J(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=r,this.minFilter=s,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new E(0,0),this.repeat=new E(1,1),this.center=new E(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new F,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=l,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize($).x}get height(){return this.source.getSize($).y}get depth(){return this.source.getSize($).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const n=t[e];if(void 0===n){m(`Texture.setValues(): parameter \'${e}\' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[e]=n:m(`Texture.setValues(): property \'${e}\' does not exist.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case e:t.x=t.x<0?0:1;break;case 1002:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case e:t.y=t.y<0?0:1;break;case 1002:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}H.DEFAULT_IMAGE=null,H.DEFAULT_MAPPING=300,H.DEFAULT_ANISOTROPY=1;class Q{constructor(t=0,e=0,n=0,i=1){Q.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=this.w,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i+s[12]*r,this.y=s[1]*e+s[5]*n+s[9]*i+s[13]*r,this.z=s[2]*e+s[6]*n+s[10]*i+s[14]*r,this.w=s[3]*e+s[7]*n+s[11]*i+s[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const s=.01,o=.1,a=t.elements,h=a[0],l=a[4],u=a[8],c=a[1],d=a[5],p=a[9],f=a[2],y=a[6],m=a[10];if(Math.abs(l-c)<s&&Math.abs(u-f)<s&&Math.abs(p-y)<s){if(Math.abs(l+c)<o&&Math.abs(u+f)<o&&Math.abs(p+y)<o&&Math.abs(h+d+m-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,g=(m+1)/2,x=(l+c)/4,b=(u+f)/4,w=(p+y)/4;return t>a&&t>g?t<s?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(t),i=x/n,r=b/n):a>g?a<s?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),n=x/i,r=w/i):g<s?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(g),n=b/r,i=w/r),this.set(n,i,r,e),this}let g=Math.sqrt((y-p)*(y-p)+(u-f)*(u-f)+(c-l)*(c-l));return Math.abs(g)<.001&&(g=1),this.x=(y-p)/g,this.y=(u-f)/g,this.z=(c-l)/g,this.w=Math.acos((h+d+m-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this.z=z(this.z,t.z,e.z),this.w=z(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this.z=z(this.z,t,e),this.w=z(this.w,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class K{constructor(t=new N(1/0,1/0,1/0),e=new N(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e+=3)this.expandByPoint(et.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(et.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=et.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const n=t.geometry;if(void 0!==n){const i=n.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,n=i.count;e<n;e++)!0===t.isMesh?t.getVertexPosition(e,et):et.fromBufferAttribute(i,e),et.applyMatrix4(t.matrixWorld),this.expandByPoint(et);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),nt.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),nt.copy(n.boundingBox)),nt.applyMatrix4(t.matrixWorld),this.union(nt)}const i=t.children;for(let r=0,s=i.length;r<s;r++)this.expandByObject(i[r],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,et),et.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(lt),ut.subVectors(this.max,lt),it.subVectors(t.a,lt),rt.subVectors(t.b,lt),st.subVectors(t.c,lt),ot.subVectors(rt,it),at.subVectors(st,rt),ht.subVectors(it,st);let e=[0,-ot.z,ot.y,0,-at.z,at.y,0,-ht.z,ht.y,ot.z,0,-ot.x,at.z,0,-at.x,ht.z,0,-ht.x,-ot.y,ot.x,0,-at.y,at.x,0,-ht.y,ht.x,0];return!!pt(e,it,rt,st,ut)&&(e=[1,0,0,0,1,0,0,0,1],!!pt(e,it,rt,st,ut)&&(ct.crossVectors(ot,at),e=[ct.x,ct.y,ct.z],pt(e,it,rt,st,ut)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,et).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(et).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(tt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),tt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),tt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),tt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),tt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),tt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),tt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),tt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(tt)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const tt=[new N,new N,new N,new N,new N,new N,new N,new N],et=new N,nt=new K,it=new N,rt=new N,st=new N,ot=new N,at=new N,ht=new N,lt=new N,ut=new N,ct=new N,dt=new N;function pt(t,e,n,i,r){for(let s=0,o=t.length-3;s<=o;s+=3){dt.fromArray(t,s);const o=r.x*Math.abs(dt.x)+r.y*Math.abs(dt.y)+r.z*Math.abs(dt.z),a=e.dot(dt),h=n.dot(dt),l=i.dot(dt);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const ft=new K,yt=new N,mt=new N;class gt{constructor(t=new N,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;void 0!==e?n.copy(e):ft.setFromPoints(t).getCenter(n);let i=0;for(let r=0,s=t.length;r<s;r++)i=Math.max(i,n.distanceToSquared(t[r]));return this.radius=Math.sqrt(i),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const n=this.center.distanceToSquared(t);return e.copy(t),n>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;yt.subVectors(t,this.center);const e=yt.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(yt,n/t),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(mt.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(yt.copy(t.center).add(mt)),this.expandByPoint(yt.copy(t.center).sub(mt))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}const xt=new N,bt=new N,wt=new N,vt=new N,Mt=new N,St=new N,At=new N;class zt{constructor(t=new N,e=new N(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,xt)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=xt.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(xt.copy(this.origin).addScaledVector(this.direction,e),xt.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){bt.copy(t).add(e).multiplyScalar(.5),wt.copy(e).sub(t).normalize(),vt.copy(this.origin).sub(bt);const r=.5*t.distanceTo(e),s=-this.direction.dot(wt),o=vt.dot(this.direction),a=-vt.dot(wt),h=vt.lengthSq(),l=Math.abs(1-s*s);let u,c,d,p;if(l>0)if(u=s*a-o,c=s*o-a,p=r*l,u>=0)if(c>=-p)if(c<=p){const t=1/l;u*=t,c*=t,d=u*(u+s*c+2*o)+c*(s*u+c+2*a)+h}else c=r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;else c=-r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;else c<=-p?(u=Math.max(0,-(-s*r+o)),c=u>0?-r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h):c<=p?(u=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(u=Math.max(0,-(s*r+o)),c=u>0?r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h);else c=s>0?-r:r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(bt).addScaledVector(wt,c),d}intersectSphere(t,e){xt.subVectors(t.center,this.origin);const n=xt.dot(this.direction),i=xt.dot(xt)-n*n,r=t.radius*t.radius;if(i>r)return null;const s=Math.sqrt(r-i),o=n-s,a=n+s;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return!(t.radius<0)&&this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,r,s,o,a;const h=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,c=this.origin;return h>=0?(n=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(n=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),l>=0?(r=(t.min.y-c.y)*l,s=(t.max.y-c.y)*l):(r=(t.max.y-c.y)*l,s=(t.min.y-c.y)*l),n>s||r>i?null:((r>n||isNaN(n))&&(n=r),(s<i||isNaN(i))&&(i=s),u>=0?(o=(t.min.z-c.z)*u,a=(t.max.z-c.z)*u):(o=(t.max.z-c.z)*u,a=(t.min.z-c.z)*u),n>a||o>i?null:((o>n||n!=n)&&(n=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(n>=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,xt)}intersectTriangle(t,e,n,i,r){Mt.subVectors(e,t),St.subVectors(n,t),At.crossVectors(Mt,St);let s,o=this.direction.dot(At);if(o>0){if(i)return null;s=1}else{if(!(o<0))return null;s=-1,o=-o}vt.subVectors(this.origin,t);const a=s*this.direction.dot(St.crossVectors(vt,St));if(a<0)return null;const h=s*this.direction.dot(Mt.cross(vt));if(h<0)return null;if(a+h>o)return null;const l=-s*vt.dot(At);return l<0?null:this.at(l/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class _t{constructor(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){_t.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y)}set(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){const m=this.elements;return m[0]=t,m[4]=e,m[8]=n,m[12]=i,m[1]=r,m[5]=s,m[9]=o,m[13]=a,m[2]=h,m[6]=l,m[10]=u,m[14]=c,m[3]=d,m[7]=p,m[11]=f,m[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new _t).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),n.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this)}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,n=t.elements,i=1/Tt.setFromMatrixColumn(t,0).length(),r=1/Tt.setFromMatrixColumn(t,1).length(),s=1/Tt.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*s,e[9]=n[9]*s,e[10]=n[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,s=Math.cos(n),o=Math.sin(n),a=Math.cos(i),h=Math.sin(i),l=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=s*l,n=s*u,i=o*l,r=o*u;e[0]=a*l,e[4]=-a*u,e[8]=h,e[1]=n+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+n*h,e[10]=s*a}else if("YXZ"===t.order){const t=a*l,n=a*u,i=h*l,r=h*u;e[0]=t+r*o,e[4]=i*o-n,e[8]=s*h,e[1]=s*u,e[5]=s*l,e[9]=-o,e[2]=n*o-i,e[6]=r+t*o,e[10]=s*a}else if("ZXY"===t.order){const t=a*l,n=a*u,i=h*l,r=h*u;e[0]=t-r*o,e[4]=-s*u,e[8]=i+n*o,e[1]=n+i*o,e[5]=s*l,e[9]=r-t*o,e[2]=-s*h,e[6]=o,e[10]=s*a}else if("ZYX"===t.order){const t=s*l,n=s*u,i=o*l,r=o*u;e[0]=a*l,e[4]=i*h-n,e[8]=t*h+r,e[1]=a*u,e[5]=r*h+t,e[9]=n*h-i,e[2]=-h,e[6]=o*a,e[10]=s*a}else if("YZX"===t.order){const t=s*a,n=s*h,i=o*a,r=o*h;e[0]=a*l,e[4]=r-t*u,e[8]=i*u+n,e[1]=u,e[5]=s*l,e[9]=-o*l,e[2]=-h*l,e[6]=n*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=s*a,n=s*h,i=o*a,r=o*h;e[0]=a*l,e[4]=-u,e[8]=h*l,e[1]=t*u+r,e[5]=s*l,e[9]=n*u-i,e[2]=i*u-n,e[6]=o*l,e[10]=r*u+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Pt,t,Ct)}lookAt(t,e,n){const i=this.elements;return Nt.subVectors(t,e),0===Nt.lengthSq()&&(Nt.z=1),Nt.normalize(),Et.crossVectors(n,Nt),0===Et.lengthSq()&&(1===Math.abs(n.z)?Nt.x+=1e-4:Nt.z+=1e-4,Nt.normalize(),Et.crossVectors(n,Nt)),Et.normalize(),kt.crossVectors(Nt,Et),i[0]=Et.x,i[4]=kt.x,i[8]=Nt.x,i[1]=Et.y,i[5]=kt.y,i[9]=Nt.y,i[2]=Et.z,i[6]=kt.z,i[10]=Nt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],o=n[4],a=n[8],h=n[12],l=n[1],u=n[5],c=n[9],d=n[13],p=n[2],f=n[6],y=n[10],m=n[14],g=n[3],x=n[7],b=n[11],w=n[15],v=i[0],M=i[4],S=i[8],A=i[12],z=i[1],_=i[5],T=i[9],B=i[13],P=i[2],C=i[6],E=i[10],k=i[14],N=i[3],I=i[7],O=i[11],F=i[15];return r[0]=s*v+o*z+a*P+h*N,r[4]=s*M+o*_+a*C+h*I,r[8]=s*S+o*T+a*E+h*O,r[12]=s*A+o*B+a*k+h*F,r[1]=l*v+u*z+c*P+d*N,r[5]=l*M+u*_+c*C+d*I,r[9]=l*S+u*T+c*E+d*O,r[13]=l*A+u*B+c*k+d*F,r[2]=p*v+f*z+y*P+m*N,r[6]=p*M+f*_+y*C+m*I,r[10]=p*S+f*T+y*E+m*O,r[14]=p*A+f*B+y*k+m*F,r[3]=g*v+x*z+b*P+w*N,r[7]=g*M+x*_+b*C+w*I,r[11]=g*S+x*T+b*E+w*O,r[15]=g*A+x*B+b*k+w*F,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],i=t[8],r=t[12],s=t[1],o=t[5],a=t[9],h=t[13],l=t[2],u=t[6],c=t[10],d=t[14],p=t[3],f=t[7],y=t[11],m=t[15],g=a*d-h*c,x=o*d-h*u,b=o*c-a*u,w=s*d-h*l,v=s*c-a*l,M=s*u-o*l;return e*(f*g-y*x+m*b)-n*(p*g-y*w+m*v)+i*(p*x-f*w+m*M)-r*(p*b-f*v+y*M)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8],u=t[9],c=t[10],d=t[11],p=t[12],f=t[13],y=t[14],m=t[15],g=u*y*h-f*c*h+f*a*d-o*y*d-u*a*m+o*c*m,x=p*c*h-l*y*h-p*a*d+s*y*d+l*a*m-s*c*m,b=l*f*h-p*u*h+p*o*d-s*f*d-l*o*m+s*u*m,w=p*u*a-l*f*a-p*o*c+s*f*c+l*o*y-s*u*y,v=e*g+n*x+i*b+r*w;if(0===v)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const M=1/v;return t[0]=g*M,t[1]=(f*c*r-u*y*r-f*i*d+n*y*d+u*i*m-n*c*m)*M,t[2]=(o*y*r-f*a*r+f*i*h-n*y*h-o*i*m+n*a*m)*M,t[3]=(u*a*r-o*c*r-u*i*h+n*c*h+o*i*d-n*a*d)*M,t[4]=x*M,t[5]=(l*y*r-p*c*r+p*i*d-e*y*d-l*i*m+e*c*m)*M,t[6]=(p*a*r-s*y*r-p*i*h+e*y*h+s*i*m-e*a*m)*M,t[7]=(s*c*r-l*a*r+l*i*h-e*c*h-s*i*d+e*a*d)*M,t[8]=b*M,t[9]=(p*u*r-l*f*r-p*n*d+e*f*d+l*n*m-e*u*m)*M,t[10]=(s*f*r-p*o*r+p*n*h-e*f*h-s*n*m+e*o*m)*M,t[11]=(l*o*r-s*u*r-l*n*h+e*u*h+s*n*d-e*o*d)*M,t[12]=w*M,t[13]=(l*f*i-p*u*i+p*n*c-e*f*c-l*n*y+e*u*y)*M,t[14]=(p*o*i-s*f*i-p*n*a+e*f*a+s*n*y-e*o*y)*M,t[15]=(s*u*i-l*o*i+l*n*a-e*u*a-s*n*c+e*o*c)*M,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,s=t.x,o=t.y,a=t.z,h=r*s,l=r*o;return this.set(h*s+n,h*o-i*a,h*a+i*o,0,h*o+i*a,l*o+n,l*a-i*s,0,h*a-i*o,l*a+i*s,r*a*a+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,s){return this.set(1,n,r,0,t,1,s,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,s=e._y,o=e._z,a=e._w,h=r+r,l=s+s,u=o+o,c=r*h,d=r*l,p=r*u,f=s*l,y=s*u,m=o*u,g=a*h,x=a*l,b=a*u,w=n.x,v=n.y,M=n.z;return i[0]=(1-(f+m))*w,i[1]=(d+b)*w,i[2]=(p-x)*w,i[3]=0,i[4]=(d-b)*v,i[5]=(1-(c+m))*v,i[6]=(y+g)*v,i[7]=0,i[8]=(p+x)*M,i[9]=(y-g)*M,i[10]=(1-(c+f))*M,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;if(t.x=i[12],t.y=i[13],t.z=i[14],0===this.determinant())return n.set(1,1,1),e.identity(),this;let r=Tt.set(i[0],i[1],i[2]).length();const s=Tt.set(i[4],i[5],i[6]).length(),o=Tt.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),Bt.copy(this);const a=1/r,h=1/s,l=1/o;return Bt.elements[0]*=a,Bt.elements[1]*=a,Bt.elements[2]*=a,Bt.elements[4]*=h,Bt.elements[5]*=h,Bt.elements[6]*=h,Bt.elements[8]*=l,Bt.elements[9]*=l,Bt.elements[10]*=l,e.setFromRotationMatrix(Bt),n.x=r,n.y=s,n.z=o,this}makePerspective(t,e,n,i,r,s,o=2e3,h=!1){const l=this.elements,u=2*r/(e-t),c=2*r/(n-i),d=(e+t)/(e-t),p=(n+i)/(n-i);let f,y;if(h)f=r/(s-r),y=s*r/(s-r);else if(o===a)f=-(s+r)/(s-r),y=-2*s*r/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);f=-s/(s-r),y=-s*r/(s-r)}return l[0]=u,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=c,l[9]=p,l[13]=0,l[2]=0,l[6]=0,l[10]=f,l[14]=y,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,i,r,s,o=2e3,h=!1){const l=this.elements,u=2/(e-t),c=2/(n-i),d=-(e+t)/(e-t),p=-(n+i)/(n-i);let f,y;if(h)f=1/(s-r),y=s/(s-r);else if(o===a)f=-2/(s-r),y=-(s+r)/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);f=-1/(s-r),y=-r/(s-r)}return l[0]=u,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=c,l[9]=0,l[13]=p,l[2]=0,l[6]=0,l[10]=f,l[14]=y,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const Tt=new N,Bt=new _t,Pt=new N(0,0,0),Ct=new N(1,1,1),Et=new N,kt=new N,Nt=new N,It=new _t,Ot=new k;class Ft{constructor(t=0,e=0,n=0,i=Ft.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const i=t.elements,r=i[0],s=i[4],o=i[8],a=i[1],h=i[5],l=i[9],u=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(z(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-z(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(z(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-z(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-s,h));break;case"YZX":this._z=Math.asin(z(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-z(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:m("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return It.makeRotationFromQuaternion(t),this.setFromRotationMatrix(It,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Ot.setFromEuler(this),this.setFromQuaternion(Ot,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ft.DEFAULT_ORDER="XYZ";class Rt{constructor(){this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}test(t){return 0!==(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let Vt=0;const Ut=new N,Lt=new k,qt=new _t,Dt=new N,Xt=new N,Zt=new N,jt=new k,Gt=new N(1,0,0),Jt=new N(0,1,0),Wt=new N(0,0,1),Yt={type:"added"},$t={type:"removed"},Ht={type:"childadded",child:null},Qt={type:"childremoved",child:null};class Kt extends b{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Vt++}),this.uuid=A(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Kt.DEFAULT_UP.clone();const t=new N,e=new Ft,n=new k,i=new N(1,1,1);e._onChange(function(){n.setFromEuler(e,!1)}),n._onChange(function(){e.setFromQuaternion(n,void 0,!1)}),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new _t},normalMatrix:{value:new F}}),this.matrix=new _t,this.matrixWorld=new _t,this.matrixAutoUpdate=Kt.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Kt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Rt,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Lt.setFromAxisAngle(t,e),this.quaternion.multiply(Lt),this}rotateOnWorldAxis(t,e){return Lt.setFromAxisAngle(t,e),this.quaternion.premultiply(Lt),this}rotateX(t){return this.rotateOnAxis(Gt,t)}rotateY(t){return this.rotateOnAxis(Jt,t)}rotateZ(t){return this.rotateOnAxis(Wt,t)}translateOnAxis(t,e){return Ut.copy(t).applyQuaternion(this.quaternion),this.position.add(Ut.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Gt,t)}translateY(t){return this.translateOnAxis(Jt,t)}translateZ(t){return this.translateOnAxis(Wt,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(qt.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?Dt.copy(t):Dt.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),Xt.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?qt.lookAt(Xt,Dt,this.up):qt.lookAt(Dt,Xt,this.up),this.quaternion.setFromRotationMatrix(qt),i&&(qt.extractRotation(i.matrixWorld),Lt.setFromRotationMatrix(qt),this.quaternion.premultiply(Lt.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(g("Object3D.add: object can\'t be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Yt),Ht.child=t,this.dispatchEvent(Ht),Ht.child=null):g("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent($t),Qt.child=t,this.dispatchEvent(Qt),Qt.child=null),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),qt.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),qt.multiply(t.parent.matrixWorld)),t.applyMatrix4(qt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Yt),Ht.child=t,this.dispatchEvent(Ht),Ht.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let n=0,i=this.children.length;n<i;n++){const i=this.children[n].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const i=this.children;for(let r=0,s=i.length;r<s;r++)i[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xt,t,Zt),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xt,jt,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let n=0,i=e.length;n<i;n++){e[n].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const n=this.parent;if(!0===t&&null!==n&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),!0===e){const t=this.children;for(let e=0,n=t.length;e<n;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,n){return void 0===e[n.uuid]&&(e[n.uuid]=n.toJSON(t)),n.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(t=>c(u({},t),{boundingBox:t.boundingBox?t.boundingBox.toJSON():void 0,boundingSphere:t.boundingSphere?t.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(t=>u({},t)),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere=this.boundingSphere.toJSON()),null!==this.boundingBox&&(i.boundingBox=this.boundingBox.toJSON())),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e<i;e++){const i=n[e];r(t.shapes,i)}else r(t.shapes,n)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(r(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let n=0,i=this.material.length;n<i;n++)e.push(r(t.materials,this.material[n]));i.material=e}else i.material=r(t.materials,this.material);if(this.children.length>0){i.children=[];for(let e=0;e<this.children.length;e++)i.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let e=0;e<this.animations.length;e++){const n=this.animations[e];i.animations.push(r(t.animations,n))}}if(e){const e=s(t.geometries),i=s(t.materials),r=s(t.textures),o=s(t.images),a=s(t.shapes),h=s(t.skeletons),l=s(t.animations),u=s(t.nodes);e.length>0&&(n.geometries=e),i.length>0&&(n.materials=i),r.length>0&&(n.textures=r),o.length>0&&(n.images=o),a.length>0&&(n.shapes=a),h.length>0&&(n.skeletons=h),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=i,n;function s(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let n=0;n<t.children.length;n++){const e=t.children[n];this.add(e.clone())}return this}}Kt.DEFAULT_UP=new N(0,1,0),Kt.DEFAULT_MATRIX_AUTO_UPDATE=!0,Kt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const te=new N,ee=new N,ne=new N,ie=new N,re=new N,se=new N,oe=new N,ae=new N,he=new N,le=new N,ue=new Q,ce=new Q,de=new Q;class pe{constructor(t=new N,e=new N,n=new N){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),te.subVectors(t,e),i.cross(te);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){te.subVectors(i,e),ee.subVectors(n,e),ne.subVectors(t,e);const s=te.dot(te),o=te.dot(ee),a=te.dot(ne),h=ee.dot(ee),l=ee.dot(ne),u=s*h-o*o;if(0===u)return r.set(0,0,0),null;const c=1/u,d=(h*a-o*l)*c,p=(s*l-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,ie)&&(ie.x>=0&&ie.y>=0&&ie.x+ie.y<=1)}static getInterpolation(t,e,n,i,r,s,o,a){return null===this.getBarycoord(t,e,n,i,ie)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,ie.x),a.addScaledVector(s,ie.y),a.addScaledVector(o,ie.z),a)}static getInterpolatedAttribute(t,e,n,i,r,s){return ue.setScalar(0),ce.setScalar(0),de.setScalar(0),ue.fromBufferAttribute(t,e),ce.fromBufferAttribute(t,n),de.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(ue,r.x),s.addScaledVector(ce,r.y),s.addScaledVector(de,r.z),s}static isFrontFacing(t,e,n,i){return te.subVectors(n,e),ee.subVectors(t,e),te.cross(ee).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return te.subVectors(this.c,this.b),ee.subVectors(this.a,this.b),.5*te.cross(ee).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return pe.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return pe.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return pe.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return pe.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return pe.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let s,o;re.subVectors(i,n),se.subVectors(r,n),ae.subVectors(t,n);const a=re.dot(ae),h=se.dot(ae);if(a<=0&&h<=0)return e.copy(n);he.subVectors(t,i);const l=re.dot(he),u=se.dot(he);if(l>=0&&u<=l)return e.copy(i);const c=a*u-l*h;if(c<=0&&a>=0&&l<=0)return s=a/(a-l),e.copy(n).addScaledVector(re,s);le.subVectors(t,r);const d=re.dot(le),p=se.dot(le);if(p>=0&&d<=p)return e.copy(r);const f=d*h-a*p;if(f<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(n).addScaledVector(se,o);const y=l*p-d*u;if(y<=0&&u-l>=0&&d-p>=0)return oe.subVectors(r,i),o=(u-l)/(u-l+(d-p)),e.copy(i).addScaledVector(oe,o);const m=1/(y+f+c);return s=f*m,o=c*m,e.copy(n).addScaledVector(re,s).addScaledVector(se,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const fe={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},ye={h:0,s:0,l:0},me={h:0,s:0,l:0};function ge(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}let xe=class{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=n){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,q.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=q.workingColorSpace){return this.r=t,this.g=e,this.b=n,q.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=q.workingColorSpace){if(t=_(t,1),e=z(e,0,1),n=z(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=ge(r,i,t+1/3),this.g=ge(r,i,t),this.b=ge(r,i,t-1/3)}return q.colorSpaceToWorking(this,i),this}setStyle(t,e=n){function i(e){void 0!==e&&parseFloat(e)<1&&m("Color: Alpha component of "+t+" will be ignored.")}let r;if(r=/^(\\w+)\\(([^\\)]*)\\)/.exec(t)){let n;const s=r[1],o=r[2];switch(s){case"rgb":case"rgba":if(n=/^\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,e);if(n=/^\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,e);break;case"hsl":case"hsla":if(n=/^\\s*(\\d*\\.?\\d+)\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,e);break;default:m("Color: Unknown color model "+t)}}else if(r=/^\\#([A-Fa-f\\d]+)$/.exec(t)){const n=r[1],i=n.length;if(3===i)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===i)return this.setHex(parseInt(n,16),e);m("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=n){const i=fe[t.toLowerCase()];return void 0!==i?this.setHex(i,e):m("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=D(t.r),this.g=D(t.g),this.b=D(t.b),this}copyLinearToSRGB(t){return this.r=X(t.r),this.g=X(t.g),this.b=X(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=n){return q.workingToColorSpace(be.copy(this),t),65536*Math.round(z(255*be.r,0,255))+256*Math.round(z(255*be.g,0,255))+Math.round(z(255*be.b,0,255))}getHexString(t=n){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=q.workingColorSpace){q.workingToColorSpace(be.copy(this),e);const n=be.r,i=be.g,r=be.b,s=Math.max(n,i,r),o=Math.min(n,i,r);let a,h;const l=(o+s)/2;if(o===s)a=0,h=0;else{const t=s-o;switch(h=l<=.5?t/(s+o):t/(2-s-o),s){case n:a=(i-r)/t+(i<r?6:0);break;case i:a=(r-n)/t+2;break;case r:a=(n-i)/t+4}a/=6}return t.h=a,t.s=h,t.l=l,t}getRGB(t,e=q.workingColorSpace){return q.workingToColorSpace(be.copy(this),e),t.r=be.r,t.g=be.g,t.b=be.b,t}getStyle(t=n){q.workingToColorSpace(be.copy(this),t);const e=be.r,i=be.g,r=be.b;return t!==n?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${r.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*i)},${Math.round(255*r)})`}offsetHSL(t,e,n){return this.getHSL(ye),this.setHSL(ye.h+t,ye.s+e,ye.l+n)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(ye),t.getHSL(me);const n=T(ye.h,me.h,e),i=T(ye.s,me.s,e),r=T(ye.l,me.l,e);return this.setHSL(n,i,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,n=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*i,this.g=r[1]*e+r[4]*n+r[7]*i,this.b=r[2]*e+r[5]*n+r[8]*i,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}};const be=new xe;xe.NAMES=fe;let we=0;class ve extends b{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:we++}),this.uuid=A(),this.name="",this.type="Material",this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=204,this.blendDst=205,this.blendEquation=100,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new xe(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=o,this.stencilZFail=o,this.stencilZPass=o,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){m(`Material: parameter \'${e}\' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n:m(`Material: \'${e}\' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),204!==this.blendSrc&&(n.blendSrc=this.blendSrc),205!==this.blendDst&&(n.blendDst=this.blendDst),100!==this.blendEquation&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==o&&(n.stencilFail=this.stencilFail),this.stencilZFail!==o&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==o&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!1===this.allowOverride&&(n.allowOverride=!1),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(n.textures=e),r.length>0&&(n.images=r)}return n}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.allowOverride=t.allowOverride,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}class Me extends ve{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new xe(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Ft,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Se=new N,Ae=new E;let ze=0;class _e{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:ze++}),this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=n,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[n+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,n=this.count;e<n;e++)Ae.fromBufferAttribute(this,e),Ae.applyMatrix3(t),this.setXY(e,Ae.x,Ae.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyMatrix3(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyMatrix4(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyNormalMatrix(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.transformDirection(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=B(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=P(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=B(e,this.array)),e}setX(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=B(e,this.array)),e}setY(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=B(e,this.array)),e}setZ(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=B(e,this.array)),e}setW(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array),i=P(i,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this}setXYZW(t,e,n,i,r){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array),i=P(i,this.array),r=P(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),35044!==this.usage&&(t.usage=this.usage),t}}class Te extends _e{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class Be extends _e{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class Pe extends _e{constructor(t,e,n){super(new Float32Array(t),e,n)}}let Ce=0;const Ee=new _t,ke=new Kt,Ne=new N,Ie=new K,Oe=new K,Fe=new N;class Re extends b{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Ce++}),this.uuid=A(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(t)?Be:Te)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const n=this.attributes.normal;if(void 0!==n){const e=(new F).getNormalMatrix(t);n.applyNormalMatrix(e),n.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return Ee.makeRotationFromQuaternion(t),this.applyMatrix4(Ee),this}rotateX(t){return Ee.makeRotationX(t),this.applyMatrix4(Ee),this}rotateY(t){return Ee.makeRotationY(t),this.applyMatrix4(Ee),this}rotateZ(t){return Ee.makeRotationZ(t),this.applyMatrix4(Ee),this}translate(t,e,n){return Ee.makeTranslation(t,e,n),this.applyMatrix4(Ee),this}scale(t,e,n){return Ee.makeScale(t,e,n),this.applyMatrix4(Ee),this}lookAt(t){return ke.lookAt(t),ke.updateMatrix(),this.applyMatrix4(ke.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ne).negate(),this.translate(Ne.x,Ne.y,Ne.z),this}setFromPoints(t){const e=this.getAttribute("position");if(void 0===e){const e=[];for(let n=0,i=t.length;n<i;n++){const i=t[n];e.push(i.x,i.y,i.z||0)}this.setAttribute("position",new Pe(e,3))}else{const n=Math.min(t.length,e.count);for(let i=0;i<n;i++){const n=t[i];e.setXYZ(i,n.x,n.y,n.z||0)}t.length>e.count&&m("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new K);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return g("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new N(-1/0,-1/0,-1/0),new N(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,i=e.length;n<i;n++){const t=e[n];Ie.setFromBufferAttribute(t),this.morphTargetsRelative?(Fe.addVectors(this.boundingBox.min,Ie.min),this.boundingBox.expandByPoint(Fe),Fe.addVectors(this.boundingBox.max,Ie.max),this.boundingBox.expandByPoint(Fe)):(this.boundingBox.expandByPoint(Ie.min),this.boundingBox.expandByPoint(Ie.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&g(\'BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.\',this)}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new gt);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return g("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new N,1/0);if(t){const n=this.boundingSphere.center;if(Ie.setFromBufferAttribute(t),e)for(let t=0,r=e.length;t<r;t++){const n=e[t];Oe.setFromBufferAttribute(n),this.morphTargetsRelative?(Fe.addVectors(Ie.min,Oe.min),Ie.expandByPoint(Fe),Fe.addVectors(Ie.max,Oe.max),Ie.expandByPoint(Fe)):(Ie.expandByPoint(Oe.min),Ie.expandByPoint(Oe.max))}Ie.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)Fe.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(Fe));if(e)for(let r=0,s=e.length;r<s;r++){const s=e[r],o=this.morphTargetsRelative;for(let e=0,r=s.count;e<r;e++)Fe.fromBufferAttribute(s,e),o&&(Ne.fromBufferAttribute(t,e),Fe.add(Ne)),i=Math.max(i,n.distanceToSquared(Fe))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&g(\'BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.\',this)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return void g("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const n=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new _e(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),o=[],a=[];for(let g=0;g<n.count;g++)o[g]=new N,a[g]=new N;const h=new N,l=new N,u=new N,c=new E,d=new E,p=new E,f=new N,y=new N;function m(t,e,i){h.fromBufferAttribute(n,t),l.fromBufferAttribute(n,e),u.fromBufferAttribute(n,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),l.sub(h),u.sub(h),d.sub(c),p.sub(c);const s=1/(d.x*p.y-p.x*d.y);isFinite(s)&&(f.copy(l).multiplyScalar(p.y).addScaledVector(u,-d.y).multiplyScalar(s),y.copy(u).multiplyScalar(d.x).addScaledVector(l,-p.x).multiplyScalar(s),o[t].add(f),o[e].add(f),o[i].add(f),a[t].add(y),a[e].add(y),a[i].add(y))}let x=this.groups;0===x.length&&(x=[{start:0,count:t.count}]);for(let g=0,A=x.length;g<A;++g){const e=x[g],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)m(t.getX(i+0),t.getX(i+1),t.getX(i+2))}const b=new N,w=new N,v=new N,M=new N;function S(t){v.fromBufferAttribute(i,t),M.copy(v);const e=o[t];b.copy(e),b.sub(v.multiplyScalar(v.dot(e))).normalize(),w.crossVectors(M,e);const n=w.dot(a[t])<0?-1:1;s.setXYZW(t,b.x,b.y,b.z,n)}for(let g=0,A=x.length;g<A;++g){const e=x[g],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)S(t.getX(i+0)),S(t.getX(i+1)),S(t.getX(i+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let n=this.getAttribute("normal");if(void 0===n)n=new _e(new Float32Array(3*e.count),3),this.setAttribute("normal",n);else for(let t=0,e=n.count;t<e;t++)n.setXYZ(t,0,0,0);const i=new N,r=new N,s=new N,o=new N,a=new N,h=new N,l=new N,u=new N;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),f=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),s.fromBufferAttribute(e,f),l.subVectors(s,r),u.subVectors(i,r),l.cross(u),o.fromBufferAttribute(n,d),a.fromBufferAttribute(n,p),h.fromBufferAttribute(n,f),o.add(l),a.add(l),h.add(l),n.setXYZ(d,o.x,o.y,o.z),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(f,h.x,h.y,h.z)}else for(let t=0,c=e.count;t<c;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),s.fromBufferAttribute(e,t+2),l.subVectors(s,r),u.subVectors(i,r),l.cross(u),n.setXYZ(t+0,l.x,l.y,l.z),n.setXYZ(t+1,l.x,l.y,l.z),n.setXYZ(t+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Fe.fromBufferAttribute(t,e),Fe.normalize(),t.setXYZ(e,Fe.x,Fe.y,Fe.z)}toNonIndexed(){function t(t,e){const n=t.array,i=t.itemSize,r=t.normalized,s=new n.constructor(e.length*i);let o=0,a=0;for(let h=0,l=e.length;h<l;h++){o=t.isInterleavedBufferAttribute?e[h]*t.data.stride+t.offset:e[h]*i;for(let t=0;t<i;t++)s[a++]=n[o++]}return new _e(s,i,r)}if(null===this.index)return m("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Re,n=this.index.array,i=this.attributes;for(const o in i){const r=t(i[o],n);e.setAttribute(o,r)}const r=this.morphAttributes;for(const o in r){const i=[],s=r[o];for(let e=0,r=s.length;e<r;e++){const r=t(s[e],n);i.push(r)}e.morphAttributes[o]=i}e.morphTargetsRelative=this.morphTargetsRelative;const s=this.groups;for(let o=0,a=s.length;o<a;o++){const t=s[o];e.addGroup(t.start,t.count,t.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,""!==this.name&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const n in e)void 0!==e[n]&&(t[n]=e[n]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const a in n){const e=n[a];t.data.attributes[a]=e.toJSON(t.data)}const i={};let r=!1;for(const a in this.morphAttributes){const e=this.morphAttributes[a],n=[];for(let i=0,r=e.length;i<r;i++){const r=e[i];n.push(r.toJSON(t.data))}n.length>0&&(i[a]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(t.data.groups=JSON.parse(JSON.stringify(s)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere=o.toJSON()),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone());const i=t.attributes;for(const h in i){const t=i[h];this.setAttribute(h,t.clone(e))}const r=t.morphAttributes;for(const h in r){const t=[],n=r[h];for(let i=0,r=n.length;i<r;i++)t.push(n[i].clone(e));this.morphAttributes[h]=t}this.morphTargetsRelative=t.morphTargetsRelative;const s=t.groups;for(let h=0,l=s.length;h<l;h++){const t=s[h];this.addGroup(t.start,t.count,t.materialIndex)}const o=t.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=t.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Ve=new _t,Ue=new zt,Le=new gt,qe=new N,De=new N,Xe=new N,Ze=new N,je=new N,Ge=new N,Je=new N,We=new N;class Ye extends Kt{constructor(t=new Re,e=new Me){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t<e;t++){const e=n[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const n=this.geometry,i=n.attributes.position,r=n.morphAttributes.position,s=n.morphTargetsRelative;e.fromBufferAttribute(i,t);const o=this.morphTargetInfluences;if(r&&o){Ge.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=o[n],a=r[n];0!==i&&(je.fromBufferAttribute(a,t),s?Ge.addScaledVector(je,i):Ge.addScaledVector(je.sub(e),i))}e.add(Ge)}return e}raycast(t,e){const n=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===n.boundingSphere&&n.computeBoundingSphere(),Le.copy(n.boundingSphere),Le.applyMatrix4(r),Ue.copy(t.ray).recast(t.near),!1===Le.containsPoint(Ue.origin)){if(null===Ue.intersectSphere(Le,qe))return;if(Ue.origin.distanceToSquared(qe)>h(t.far-t.near,2))return}Ve.copy(r).invert(),Ue.copy(t.ray).applyMatrix4(Ve),null!==n.boundingBox&&!1===Ue.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Ue)}}_computeIntersections(t,e,n){let i;const r=this.geometry,s=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,l=r.attributes.uv1,u=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(s))for(let p=0,f=c.length;p<f;p++){const r=c[p],a=s[r.materialIndex];for(let s=Math.max(r.start,d.start),c=Math.min(o.count,Math.min(r.start+r.count,d.start+d.count));s<c;s+=3){i=$e(this,a,t,n,h,l,u,o.getX(s),o.getX(s+1),o.getX(s+2)),i&&(i.faceIndex=Math.floor(s/3),i.face.materialIndex=r.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),a=Math.min(o.count,d.start+d.count);r<a;r+=3){i=$e(this,s,t,n,h,l,u,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==a)if(Array.isArray(s))for(let p=0,f=c.length;p<f;p++){const r=c[p],o=s[r.materialIndex];for(let s=Math.max(r.start,d.start),c=Math.min(a.count,Math.min(r.start+r.count,d.start+d.count));s<c;s+=3){i=$e(this,o,t,n,h,l,u,s,s+1,s+2),i&&(i.faceIndex=Math.floor(s/3),i.face.materialIndex=r.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),o=Math.min(a.count,d.start+d.count);r<o;r+=3){i=$e(this,s,t,n,h,l,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function $e(t,e,n,i,r,s,o,a,h,l){t.getVertexPosition(a,De),t.getVertexPosition(h,Xe),t.getVertexPosition(l,Ze);const u=function(t,e,n,i,r,s,o,a){let h;if(h=1===e.side?i.intersectTriangle(o,s,r,!0,a):i.intersectTriangle(r,s,o,0===e.side,a),null===h)return null;We.copy(a),We.applyMatrix4(t.matrixWorld);const l=n.ray.origin.distanceTo(We);return l<n.near||l>n.far?null:{distance:l,point:We.clone(),object:t}}(t,e,n,i,De,Xe,Ze,Je);if(u){const t=new N;pe.getBarycoord(Je,De,Xe,Ze,t),r&&(u.uv=pe.getInterpolatedAttribute(r,a,h,l,t,new E)),s&&(u.uv1=pe.getInterpolatedAttribute(s,a,h,l,t,new E)),o&&(u.normal=pe.getInterpolatedAttribute(o,a,h,l,t,new N),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new N,materialIndex:0};pe.getNormal(De,Xe,Ze,e.normal),u.face=e,u.barycoord=t}return u}const He=new N,Qe=new N,Ke=new F;class tn{constructor(t=new N(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=He.subVectors(n,e).cross(Qe.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(He),i=this.normal.dot(n);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||Ke.getNormalMatrix(t),i=this.coplanarPoint(He).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}class en{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){m("Curve: .getPoint() not implemented.")}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let n,i=this.getPoint(0),r=0;e.push(0);for(let s=1;s<=t;s++)n=this.getPoint(s/t),r+=n.distanceTo(i),e.push(r),i=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e=null){const n=this.getLengths();let i=0;const r=n.length;let s;s=e||t*n[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=n[i]-s,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,n[i]===s)return i/(r-1);const l=n[i];return(i+(s-l)/(n[i+1]-l))/(r-1)}getTangent(t,e){const n=1e-4;let i=t-n,r=t+n;i<0&&(i=0),r>1&&(r=1);const s=this.getPoint(i),o=this.getPoint(r),a=e||(s.isVector2?new E:new N);return a.copy(o).sub(s).normalize(),a}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e=!1){const n=new N,i=[],r=[],s=[],o=new N,a=new _t;for(let d=0;d<=t;d++){const e=d/t;i[d]=this.getTangentAt(e,new N)}r[0]=new N,s[0]=new N;let h=Number.MAX_VALUE;const l=Math.abs(i[0].x),u=Math.abs(i[0].y),c=Math.abs(i[0].z);l<=h&&(h=l,n.set(1,0,0)),u<=h&&(h=u,n.set(0,1,0)),c<=h&&n.set(0,0,1),o.crossVectors(i[0],n).normalize(),r[0].crossVectors(i[0],o),s[0].crossVectors(i[0],r[0]);for(let d=1;d<=t;d++){if(r[d]=r[d-1].clone(),s[d]=s[d-1].clone(),o.crossVectors(i[d-1],i[d]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos(z(i[d-1].dot(i[d]),-1,1));r[d].applyMatrix4(a.makeRotationAxis(o,t))}s[d].crossVectors(i[d],r[d])}if(!0===e){let e=Math.acos(z(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let n=1;n<=t;n++)r[n].applyMatrix4(a.makeRotationAxis(i[n],e*n)),s[n].crossVectors(i[n],r[n])}return{tangents:i,normals:r,binormals:s}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class nn extends en{constructor(t=0,e=0,n=1,i=1,r=0,s=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=s,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new E){const n=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const s=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=s?0:i),!0!==this.aClockwise||s||(r===i?r=-i:r-=i);const o=this.aStartAngle+t*r;let a=this.aX+this.xRadius*Math.cos(o),h=this.aY+this.yRadius*Math.sin(o);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),n=a-this.aX,i=h-this.aY;a=n*t-i*e+this.aX,h=n*e+i*t+this.aY}return n.set(a,h)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class rn extends nn{constructor(t,e,n,i,r,s){super(t,e,n,n,i,r,s),this.isArcCurve=!0,this.type="ArcCurve"}}function sn(){let t=0,e=0,n=0,i=0;function r(r,s,o,a){t=r,e=o,n=-3*r+3*s-2*o-a,i=2*r-2*s+o+a}return{initCatmullRom:function(t,e,n,i,s){r(e,n,s*(n-t),s*(i-e))},initNonuniformCatmullRom:function(t,e,n,i,s,o,a){let h=(e-t)/s-(n-t)/(s+o)+(n-e)/o,l=(n-e)/o-(i-e)/(o+a)+(i-n)/a;h*=o,l*=o,r(e,n,h,l)},calc:function(r){const s=r*r;return t+e*r+n*s+i*(s*r)}}}const on=new N,an=new sn,hn=new sn,ln=new sn;class un extends en{constructor(t=[],e=!1,n="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=n,this.tension=i}getPoint(t,e=new N){const n=e,i=this.points,r=i.length,s=(r-(this.closed?0:1))*t;let o,a,h=Math.floor(s),l=s-h;this.closed?h+=h>0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===l&&h===r-1&&(h=r-2,l=1),this.closed||h>0?o=i[(h-1)%r]:(on.subVectors(i[0],i[1]).add(i[0]),o=on);const u=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(on.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=on),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(o.distanceToSquared(u),t),n=Math.pow(u.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(a),t);n<1e-4&&(n=1),e<1e-4&&(e=n),i<1e-4&&(i=n),an.initNonuniformCatmullRom(o.x,u.x,c.x,a.x,e,n,i),hn.initNonuniformCatmullRom(o.y,u.y,c.y,a.y,e,n,i),ln.initNonuniformCatmullRom(o.z,u.z,c.z,a.z,e,n,i)}else"catmullrom"===this.curveType&&(an.initCatmullRom(o.x,u.x,c.x,a.x,this.tension),hn.initCatmullRom(o.y,u.y,c.y,a.y,this.tension),ln.initCatmullRom(o.z,u.z,c.z,a.z,this.tension));return n.set(an.calc(l),hn.calc(l),ln.calc(l)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new N).fromArray(n))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function cn(t,e,n,i,r){const s=.5*(i-e),o=.5*(r-n),a=t*t;return(2*n-2*i+s+o)*(t*a)+(-3*n+3*i-2*s-o)*a+s*t+n}function dn(t,e,n,i){return function(t,e){const n=1-t;return n*n*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,n)+function(t,e){return t*t*e}(t,i)}function pn(t,e,n,i,r){return function(t,e){const n=1-t;return n*n*n*e}(t,e)+function(t,e){const n=1-t;return 3*n*n*t*e}(t,n)+function(t,e){return 3*(1-t)*t*t*e}(t,i)+function(t,e){return t*t*t*e}(t,r)}class fn extends en{constructor(t=new E,e=new E,n=new E,i=new E){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new E){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(pn(t,i.x,r.x,s.x,o.x),pn(t,i.y,r.y,s.y,o.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class yn extends en{constructor(t=new N,e=new N,n=new N,i=new N){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new N){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(pn(t,i.x,r.x,s.x,o.x),pn(t,i.y,r.y,s.y,o.y),pn(t,i.z,r.z,s.z,o.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class mn extends en{constructor(t=new E,e=new E){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new E){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new E){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class gn extends en{constructor(t=new N,e=new N){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new N){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new N){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class xn extends en{constructor(t=new E,e=new E,n=new E){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new E){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(dn(t,i.x,r.x,s.x),dn(t,i.y,r.y,s.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class bn extends en{constructor(t=new N,e=new N,n=new N){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new N){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(dn(t,i.x,r.x,s.x),dn(t,i.y,r.y,s.y),dn(t,i.z,r.z,s.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class wn extends en{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new E){const n=e,i=this.points,r=(i.length-1)*t,s=Math.floor(r),o=r-s,a=i[0===s?s:s-1],h=i[s],l=i[s>i.length-2?i.length-1:s+1],u=i[s>i.length-3?i.length-1:s+2];return n.set(cn(o,a.x,h.x,l.x,u.x),cn(o,a.y,h.y,l.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new E).fromArray(n))}return this}}var vn=Object.freeze({__proto__:null,ArcCurve:rn,CatmullRomCurve3:un,CubicBezierCurve:fn,CubicBezierCurve3:yn,EllipseCurve:nn,LineCurve:mn,LineCurve3:gn,QuadraticBezierCurve:xn,QuadraticBezierCurve3:bn,SplineCurve:wn});class Mn extends en{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const n=!0===t.isVector2?"LineCurve":"LineCurve3";this.curves.push(new vn[n](e,t))}return this}getPoint(t,e){const n=t*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=n){const t=i[r]-n,s=this.curves[r],o=s.getLength(),a=0===o?0:1-t/o;return s.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let n=0,i=this.curves.length;n<i;n++)e+=this.curves[n].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let n;for(let i=0,r=this.curves;i<r.length;i++){const s=r[i],o=s.isEllipseCurve?2*t:s.isLineCurve||s.isLineCurve3?1:s.isSplineCurve?t*s.points.length:t,a=s.getPoints(o);for(let t=0;t<a.length;t++){const i=a[t];n&&n.equals(i)||(e.push(i),n=i)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const n=t.curves[e];this.curves.push(n.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,n=this.curves.length;e<n;e++){const n=this.curves[e];t.curves.push(n.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const n=t.curves[e];this.curves.push((new vn[n.type]).fromJSON(n))}return this}}let Sn=class extends Mn{constructor(t){super(),this.type="Path",this.currentPoint=new E,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,n=t.length;e<n;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const n=new mn(this.currentPoint.clone(),new E(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,i){const r=new xn(this.currentPoint.clone(),new E(t,e),new E(n,i));return this.curves.push(r),this.currentPoint.set(n,i),this}bezierCurveTo(t,e,n,i,r,s){const o=new fn(this.currentPoint.clone(),new E(t,e),new E(n,i),new E(r,s));return this.curves.push(o),this.currentPoint.set(r,s),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new wn(e);return this.curves.push(n),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,n,i,r,s){const o=this.currentPoint.x,a=this.currentPoint.y;return this.absarc(t+o,e+a,n,i,r,s),this}absarc(t,e,n,i,r,s){return this.absellipse(t,e,n,n,i,r,s),this}ellipse(t,e,n,i,r,s,o,a){const h=this.currentPoint.x,l=this.currentPoint.y;return this.absellipse(t+h,e+l,n,i,r,s,o,a),this}absellipse(t,e,n,i,r,s,o,a){const h=new nn(t,e,n,i,r,s,o,a);if(this.curves.length>0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const l=h.getPoint(1);return this.currentPoint.copy(l),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}};class An extends Sn{constructor(t){super(t),this.uuid=A(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let n=0,i=this.holes.length;n<i;n++)e[n]=this.holes[n].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,n=t.holes.length;e<n;e++){const n=t.holes[e];this.holes.push(n.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,n=this.holes.length;e<n;e++){const n=this.holes[e];t.holes.push(n.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,n=t.holes.length;e<n;e++){const n=t.holes[e];this.holes.push((new Sn).fromJSON(n))}return this}}function zn(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=_n(t,0,r,n,!0);const o=[];if(!s||s.next===s.prev)return o;let a,h,l;if(i&&(s=function(t,e,n,i){const r=[];for(let s=0,o=e.length;s<o;s++){const n=_n(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Rn(n))}r.sort(Nn);for(let s=0;s<r.length;s++)n=In(r[s],n);return n}(t,e,s,n)),t.length>80*n){a=t[0],h=t[1];let e=a,i=h;for(let s=n;s<r;s+=n){const n=t[s],r=t[s+1];n<a&&(a=n),r<h&&(h=r),n>e&&(e=n),r>i&&(i=r)}l=Math.max(e-a,i-h),l=0!==l?32767/l:0}return Bn(s,o,n,a,h,l,0),o}function _n(t,e,n,i,r){let s;if(r===function(t,e,n,i){let r=0;for(let s=e,o=n-i;s<n;s+=i)r+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return r}(t,e,n,i)>0)for(let o=e;o<n;o+=i)s=Wn(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Wn(o/i|0,t[o],t[o+1],s);return s&&Dn(s,s.next)&&(Yn(s),s=s.next),s}function Tn(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Dn(i,i.next)&&0!==qn(i.prev,i,i.next))i=i.next;else{if(Yn(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function Bn(t,e,n,i,r,s,o){if(!t)return;!o&&s&&function(t,e,n,i){let r=t;do{0===r.z&&(r.z=Fn(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,n=1;do{let i,r=t;t=null;let s=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<n&&(a++,o=o.nextZ,o);t++);let h=n;for(;a>0||h>0&&o;)0!==a&&(0===h||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,h--),s?s.nextZ=i:t=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(e>1)}(r)}(t,i,r,s);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(s?Cn(t,i,r,s):Pn(t))e.push(h.i,t.i,l.i),Yn(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?Bn(t=En(Tn(t),e),e,n,i,r,s,2):2===o&&kn(t,e,n,i,r,s):Bn(Tn(t),e,n,i,r,s,1);break}}}function Pn(t){const e=t.prev,n=t,i=t.next;if(qn(e,n,i)>=0)return!1;const r=e.x,s=n.x,o=i.x,a=e.y,h=n.y,l=i.y,u=Math.min(r,s,o),c=Math.min(a,h,l),d=Math.max(r,s,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&Un(r,a,s,h,o,l,f.x,f.y)&&qn(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Cn(t,e,n,i){const r=t.prev,s=t,o=t.next;if(qn(r,s,o)>=0)return!1;const a=r.x,h=s.x,l=o.x,u=r.y,c=s.y,d=o.y,p=Math.min(a,h,l),f=Math.min(u,c,d),y=Math.max(a,h,l),m=Math.max(u,c,d),g=Fn(p,f,e,n,i),x=Fn(y,m,e,n,i);let b=t.prevZ,w=t.nextZ;for(;b&&b.z>=g&&w&&w.z<=x;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&Un(a,u,h,c,l,d,b.x,b.y)&&qn(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&Un(a,u,h,c,l,d,w.x,w.y)&&qn(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;b&&b.z>=g;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&Un(a,u,h,c,l,d,b.x,b.y)&&qn(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;w&&w.z<=x;){if(w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&Un(a,u,h,c,l,d,w.x,w.y)&&qn(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function En(t,e){let n=t;do{const i=n.prev,r=n.next.next;!Dn(i,r)&&Xn(i,n,n.next,r)&&Gn(i,r)&&Gn(r,i)&&(e.push(i.i,n.i,r.i),Yn(n),Yn(n.next),n=t=r),n=n.next}while(n!==t);return Tn(n)}function kn(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Ln(o,t)){let a=Jn(o,t);return o=Tn(o,o.next),a=Tn(a,a.next),Bn(o,e,n,i,r,s,0),void Bn(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function Nn(t,e){let n=t.x-e.x;if(0===n&&(n=t.y-e.y,0===n)){n=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}return n}function In(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(Dn(t,n))return n;do{if(Dn(t,n.next))return n.next;if(r<=n.y&&r>=n.next.y&&n.next.y!==n.y){const t=n.x+(r-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(t<=i&&t>o&&(o=t,s=n.x<n.next.x?n:n.next,t===i))return s}n=n.next}while(n!==e);if(!s)return null;const a=s,h=s.x,l=s.y;let u=1/0;n=s;do{if(i>=n.x&&n.x>=h&&i!==n.x&&Vn(r<l?i:o,r,h,l,r<l?o:i,r,n.x,n.y)){const e=Math.abs(r-n.y)/(i-n.x);Gn(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&On(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Jn(n,t);return Tn(i,i.next),Tn(n,n.next)}function On(t,e){return qn(t.prev,t,e.prev)<0&&qn(e.next,t,t.next)<0}function Fn(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Rn(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function Vn(t,e,n,i,r,s,o,a){return(r-o)*(e-a)>=(t-o)*(s-a)&&(t-o)*(i-a)>=(n-o)*(e-a)&&(n-o)*(s-a)>=(r-o)*(i-a)}function Un(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&Vn(t,e,n,i,r,s,o,a)}function Ln(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Xn(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Gn(t,e)&&Gn(e,t)&&function(t,e){let n=t,i=!1;const r=(t.x+e.x)/2,s=(t.y+e.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&r<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(qn(t.prev,t,e.prev)||qn(t,e.prev,e))||Dn(t,e)&&qn(t.prev,t,t.next)>0&&qn(e.prev,e,e.next)>0)}function qn(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Dn(t,e){return t.x===e.x&&t.y===e.y}function Xn(t,e,n,i){const r=jn(qn(t,e,n)),s=jn(qn(t,e,i)),o=jn(qn(n,i,t)),a=jn(qn(n,i,e));return r!==s&&o!==a||(!(0!==r||!Zn(t,n,e))||(!(0!==s||!Zn(t,i,e))||(!(0!==o||!Zn(n,t,i))||!(0!==a||!Zn(n,e,i)))))}function Zn(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function jn(t){return t>0?1:t<0?-1:0}function Gn(t,e){return qn(t.prev,t,t.next)<0?qn(t,e,t.next)>=0&&qn(t,t.prev,e)>=0:qn(t,e,t.prev)<0||qn(t,t.next,e)<0}function Jn(t,e){const n=$n(t.i,t.x,t.y),i=$n(e.i,e.x,e.y),r=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,s.next=i,i.prev=s,i}function Wn(t,e,n,i){const r=$n(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Yn(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function $n(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}class Hn{static triangulate(t,e,n=2){return zn(t,e,n)}}class Qn{static area(t){const e=t.length;let n=0;for(let i=e-1,r=0;r<e;i=r++)n+=t[i].x*t[r].y-t[r].x*t[i].y;return.5*n}static isClockWise(t){return Qn.area(t)<0}static triangulateShape(t,e){const n=[],i=[],r=[];Kn(t),ti(n,t);let s=t.length;e.forEach(Kn);for(let a=0;a<e.length;a++)i.push(s),s+=e[a].length,ti(n,e[a]);const o=Hn.triangulate(n,i);for(let a=0;a<o.length;a+=3)r.push(o.slice(a,a+3));return r}}function Kn(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function ti(t,e){for(let n=0;n<e.length;n++)t.push(e[n].x),t.push(e[n].y)}class ei extends Re{constructor(t=1,e=1,n=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:n,heightSegments:i};const r=t/2,s=e/2,o=Math.floor(n),a=Math.floor(i),h=o+1,l=a+1,u=t/o,c=e/a,d=[],p=[],f=[],y=[];for(let m=0;m<l;m++){const t=m*c-s;for(let e=0;e<h;e++){const n=e*u-r;p.push(n,-t,0),f.push(0,0,1),y.push(e/o),y.push(1-m/a)}}for(let m=0;m<a;m++)for(let t=0;t<o;t++){const e=t+h*m,n=t+h*(m+1),i=t+1+h*(m+1),r=t+1+h*m;d.push(e,n,r),d.push(n,i,r)}this.setIndex(d),this.setAttribute("position",new Pe(p,3)),this.setAttribute("normal",new Pe(f,3)),this.setAttribute("uv",new Pe(y,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ei(t.width,t.height,t.widthSegments,t.heightSegments)}}const ni=new N,ii=new N,ri=new N,si=new N,oi=new N,ai=new N,hi=new N;class li{constructor(t=new N,e=new N){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){ni.subVectors(t,this.start),ii.subVectors(this.end,this.start);const n=ii.dot(ii);let i=ii.dot(ni)/n;return e&&(i=z(i,0,1)),i}closestPointToPoint(t,e,n){const i=this.closestPointToPointParameter(t,e);return this.delta(n).multiplyScalar(i).add(this.start)}distanceSqToLine3(t,e=ai,n=hi){const i=1e-8*1e-8;let r,s;const o=this.start,a=t.start,h=this.end,l=t.end;ri.subVectors(h,o),si.subVectors(l,a),oi.subVectors(o,a);const u=ri.dot(ri),c=si.dot(si),d=si.dot(oi);if(u<=i&&c<=i)return e.copy(o),n.copy(a),e.sub(n),e.dot(e);if(u<=i)r=0,s=d/c,s=z(s,0,1);else{const t=ri.dot(oi);if(c<=i)s=0,r=z(-t/u,0,1);else{const e=ri.dot(si),n=u*c-e*e;r=0!==n?z((e*d-t*c)/n,0,1):0,s=(e*r+d)/c,s<0?(s=0,r=z(-t/u,0,1)):s>1&&(s=1,r=z((e-t)/u,0,1))}}return e.copy(o).add(ri.multiplyScalar(r)),n.copy(a).add(si.multiplyScalar(s)),e.sub(n),e.dot(e)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:t}})),"undefined"!=typeof window&&(window.__THREE__?m("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=t);const ui=new Map,ci=(t={})=>({generateTopUV(e,n,i,r,s){const o=n[3*i],a=n[3*i+1],h=n[3*r],l=n[3*r+1],u=n[3*s],c=n[3*s+1];let d;if(ui.has(e))d=ui.get(e);else{let n=t.box3;if(!n){n=new K;const t=e.parameters.shapes.getPoints().flatMap(t=>[t.x,t.y,0]);n.setFromArray(t)}const i=n.getSize(new N);t.split&&(i.y/=t.split),d={box:n,size:i},ui.set(e,d)}const{box:p,size:f}=d,y=t.split?1-t.split:0;return[new E((o-p.min.x)/f.x,(a-p.min.y)/f.y+y),new E((h-p.min.x)/f.x,(l-p.min.y)/f.y+y),new E((u-p.min.x)/f.x,(c-p.min.y)/f.y+y)]},generateSideWallUV(e,n,i,r,s,o){const a=n[3*i],h=n[3*i+1],l=n[3*i+2],u=n[3*r],c=n[3*r+1],d=n[3*r+2],p=n[3*s],f=n[3*s+1],y=n[3*s+2],m=n[3*o],g=n[3*o+1],x=n[3*o+2];let b;if(ui.has(n))b=ui.get(n);else{const e=new K;e.setFromArray(n);const i=e.getSize(new N);t.split&&(i.z/=1-t.split),t.sideRepeat&&(i.z/=t.sideRepeat),b={box:e,size:i},ui.set(n,b)}const{box:w,size:v}=b;return Math.abs(h-c)<Math.abs(a-u)?[new E((a-w.min.x)/v.x,(l-w.min.z)/v.z),new E((u-w.min.x)/v.x,(d-w.min.z)/v.z),new E((p-w.min.x)/v.x,(y-w.min.z)/v.z),new E((m-w.min.x)/v.x,(x-w.min.z)/v.z)]:[new E((h-w.min.y)/v.y,(l-w.min.z)/v.z),new E((c-w.min.y)/v.y,(d-w.min.z)/v.z),new E((f-w.min.y)/v.y,(y-w.min.z)/v.z),new E((g-w.min.y)/v.y,(x-w.min.z)/v.z)]}}),di={ArcCurve:rn,CatmullRomCurve3:un,CubicBezierCurve:fn,CubicBezierCurve3:yn,EllipseCurve:nn,LineCurve:mn,LineCurve3:gn,QuadraticBezierCurve:xn,QuadraticBezierCurve3:bn,SplineCurve:wn};class pi extends Re{constructor(t=new An([new E(.5,.5),new E(-.5,.5),new E(-.5,-.5),new E(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const n=this,i=[],r=[];for(let o=0,a=t.length;o<a;o++){s(t[o])}function s(t){var s,o,a;const h=[],l=void 0!==e.curveSegments?e.curveSegments:12,u=void 0!==e.steps?e.steps:1,c=void 0!==e.depth?e.depth:1;let d=void 0===e.bevelEnabled||e.bevelEnabled,p=void 0!==e.bevelThickness?e.bevelThickness:.2,f=void 0!==e.bevelSize?e.bevelSize:p-.1,y=void 0!==e.bevelOffset?e.bevelOffset:0,m=void 0!==e.bevelSegments?e.bevelSegments:3;const g=e.extrudePath,x=void 0!==e.UVGenerator?e.UVGenerator:fi,b=null==(s=e.hasTop)||s,w=null==(o=e.hasBottom)||o,v=null==(a=e.hasSide)||a;let M,S,A,z,_,T=!1;g&&(M=g.getSpacedPoints(u),T=!0,d=!1,S=g.computeFrenetFrames(u,!1),A=new N,z=new N,_=new N),d||(m=0,p=0,f=0,y=0);const B=t.extractPoints(l);let P=B.shape;const C=B.holes;if(!Qn.isClockWise(P)){P=P.reverse();for(let t=0,e=C.length;t<e;t++){const e=C[t];Qn.isClockWise(e)&&(C[t]=e.reverse())}}function k(t){const e=1e-10*1e-10;let n=t[0];for(let i=1;i<=t.length;i++){const r=i%t.length,s=t[r],o=s.x-n.x,a=s.y-n.y,h=o*o+a*a,l=Math.max(Math.abs(s.x),Math.abs(s.y),Math.abs(n.x),Math.abs(n.y));h<=e*l*l?(t.splice(r,1),i--):n=s}}k(P),C.forEach(k);const I=C.length,O=P;for(let e=0;e<I;e++){const t=C[e];P=P.concat(t)}function F(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const R=P.length;function V(t,e,n){let i,r,s;const o=t.x-e.x,a=t.y-e.y,h=n.x-t.x,l=n.y-t.y,u=o*o+a*a,c=o*l-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(u),d=Math.sqrt(h*h+l*l),p=e.x-a/c,f=e.y+o/c,y=((n.x-l/d-p)*l-(n.y+h/d-f)*h)/(o*l-a*h);i=p+o*y-t.x,r=f+a*y-t.y;const m=i*i+r*r;if(m<=2)return new E(i,r);s=Math.sqrt(m/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(l)&&(t=!0),t?(i=-a,r=o,s=Math.sqrt(u)):(i=o,r=a,s=Math.sqrt(u/2))}return new E(i/s,r/s)}const U=[];for(let e=0,n=O.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),U[e]=V(O[e],O[i],O[r]);const L=[];let q,D,X=U.concat();for(let e=0,n=I;e<n;e++){const t=C[e];q=[];for(let e=0,n=t.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),q[e]=V(t[e],t[i],t[r]);L.push(q),X=X.concat(q)}if(0===m)D=Qn.triangulateShape(O,C);else{const t=[],e=[];for(let n=0;n<m;n++){const i=n/m,r=p*Math.cos(i*Math.PI/2),s=f*Math.sin(i*Math.PI/2)+y;for(let e=0,n=O.length;e<n;e++){const n=F(O[e],U[e],s);J(n.x,n.y,-r),0===i&&t.push(n)}for(let t=0,n=I;t<n;t++){const n=C[t];q=L[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=F(n[t],q[t],s);J(e.x,e.y,-r),0===i&&o.push(e)}0===i&&e.push(o)}}D=Qn.triangulateShape(t,e)}const Z=D.length,j=f+y;for(let e=0;e<R;e++){const t=d?F(P[e],X[e],j):P[e];T?(z.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),_.copy(M[0]).add(z).add(A),J(_.x,_.y,_.z)):J(t.x,t.y,0)}for(let e=1;e<=u;e++)for(let t=0;t<R;t++){const n=d?F(P[t],X[t],j):P[t];T?(z.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),_.copy(M[e]).add(z).add(A),J(_.x,_.y,_.z)):J(n.x,n.y,c/u*e)}for(let e=m-1;e>=0;e--){const t=e/m,n=p*Math.cos(t*Math.PI/2),i=f*Math.sin(t*Math.PI/2)+y;for(let e=0,r=O.length;e<r;e++){const t=F(O[e],U[e],i);J(t.x,t.y,c+n)}for(let e=0,r=C.length;e<r;e++){const t=C[e];q=L[e];for(let e=0,r=t.length;e<r;e++){const r=F(t[e],q[e],i);T?J(r.x,r.y+M[u-1].y,M[u-1].x+n):J(r.x,r.y,c+n)}}}function G(t,e){let n=t.length;for(;--n>=0;){const i=n;let r=n-1;r<0&&(r=t.length-1);for(let t=0,n=u+2*m;t<n;t++){const n=R*t,s=R*(t+1);Y(e+i+n,e+r+n,e+r+s,e+i+s)}}}function J(t,e,n){h.push(t),h.push(e),h.push(n)}function W(t,e,r){$(t),$(e),$(r);const s=i.length/3,o=x.generateTopUV(n,i,s-3,s-2,s-1);H(o[0]),H(o[1]),H(o[2])}function Y(t,e,r,s){$(t),$(e),$(s),$(e),$(r),$(s);const o=i.length/3,a=x.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);H(a[0]),H(a[1]),H(a[3]),H(a[1]),H(a[2]),H(a[3])}function $(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function H(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=R*t;if(w)for(let n=0;n<Z;n++){const t=D[n];W(t[2]+e,t[1]+e,t[0]+e)}if(t=u+2*m,e=R*t,b)for(let n=0;n<Z;n++){const t=D[n];W(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<Z;t++){const e=D[t];W(e[2],e[1],e[0])}if(b)for(let t=0;t<Z;t++){const e=D[t];W(e[0]+R*u,e[1]+R*u,e[2]+R*u)}}n.addGroup(t,i.length/3-t,0)}(),v&&function(){const t=i.length/3;let e=0;G(O,e),e+=O.length;for(let n=0,i=C.length;n<i;n++){const t=C[n];G(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new Pe(i,3)),this.setAttribute("uv",new Pe(r,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,n){if(n.shapes=[],Array.isArray(t))for(let i=0,r=t.length;i<r;i++){const e=t[i];n.shapes.push(e.uuid)}else n.shapes.push(t.uuid);n.options=Object.assign({},e),void 0!==e.extrudePath&&(n.options.extrudePath=e.extrudePath.toJSON());return n}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const n=[];for(let r=0,s=t.shapes.length;r<s;r++){const i=e[t.shapes[r]];n.push(i)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new di[i.type]).fromJSON(i)),new pi(n,t.options)}}const fi={generateTopUV:function(t,e,n,i,r){const s=e[3*n],o=e[3*n+1],a=e[3*i],h=e[3*i+1],l=e[3*r],u=e[3*r+1];return[new E(s,o),new E(a,h),new E(l,u)]},generateSideWallUV:function(t,e,n,i,r,s){const o=e[3*n],a=e[3*n+1],h=e[3*n+2],l=e[3*i],u=e[3*i+1],c=e[3*i+2],d=e[3*r],p=e[3*r+1],f=e[3*r+2],y=e[3*s],m=e[3*s+1],g=e[3*s+2];return Math.abs(a-u)<Math.abs(o-l)?[new E(o,1-h),new E(l,1-c),new E(d,1-f),new E(y,1-g)]:[new E(a,1-h),new E(u,1-c),new E(p,1-f),new E(m,1-g)]}};const yi=1.25,mi=32,gi=Math.pow(2,-24),xi=Symbol("SKIP_GENERATION");function bi(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function wi(t,e){if(!t.index){const n=t.attributes.position.count,i=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(n,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new _e(i,1));for(let t=0;t<n;t++)i[t]=t}}function vi(t,e){const n=bi(t),i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=Math.max(0,r),a=Math.min(n,s)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function Mi(t,e){if(!t.groups||!t.groups.length)return vi(t,e);const n=[],i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=bi(t),a=[];for(const u of t.groups){const{start:t,count:e}=u,n=t/3,i=(t+(isFinite(e)?e:3*o-t))/3;n<s&&i>r&&(a.push({pos:Math.max(r,n),isStart:!0}),a.push({pos:Math.min(s,i),isStart:!1}))}a.sort((t,e)=>t.pos!==e.pos?t.pos-e.pos:"end"===t.type?-1:1);let h=0,l=null;for(const u of a){const t=u.pos;0!==h&&t!==l&&n.push({offset:l,count:t-l}),h+=u.isStart?1:-1,l=t}return n}function Si(t,e,n,i,r){let s=1/0,o=1/0,a=1/0,h=-1/0,l=-1/0,u=-1/0,c=1/0,d=1/0,p=1/0,f=-1/0,y=-1/0,m=-1/0;const g=t.offset||0;for(let x=6*(e-g),b=6*(e+n-g);x<b;x+=6){const e=t[x+0],n=t[x+1],i=e-n,r=e+n;i<s&&(s=i),r>h&&(h=r),e<c&&(c=e),e>f&&(f=e);const g=t[x+2],b=t[x+3],w=g-b,v=g+b;w<o&&(o=w),v>l&&(l=v),g<d&&(d=g),g>y&&(y=g);const M=t[x+4],S=t[x+5],A=M-S,z=M+S;A<a&&(a=A),z>u&&(u=z),M<p&&(p=M),M>m&&(m=M)}i[0]=s,i[1]=o,i[2]=a,i[3]=h,i[4]=l,i[5]=u,r[0]=c,r[1]=d,r[2]=p,r[3]=f,r[4]=y,r[5]=m}function Ai(t,e,n=null,i=null,r=null){const s=t.attributes.position,o=t.index?t.index.array:null,a=s.normalized;if(null===r)(r=new Float32Array(6*n)).offset=e;else if(e<0||n+e>r.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const h=s.array,l=s.offset||0;let u=3;s.isInterleavedBufferAttribute&&(u=s.data.stride);const c=["getX","getY","getZ"],d=r.offset;for(let p=e,f=e+n;p<f;p++){const t=3*(i?i[p]:p),e=6*(p-d);let n=t+0,f=t+1,y=t+2;o&&(n=o[n],f=o[f],y=o[y]),a||(n=n*u+l,f=f*u+l,y=y*u+l);for(let i=0;i<3;i++){let t,o,l;a?(t=s[c[i]](n),o=s[c[i]](f),l=s[c[i]](y)):(t=h[n+i],o=h[f+i],l=h[y+i]);let u=t;o<u&&(u=o),l<u&&(u=l);let d=t;o>d&&(d=o),l>d&&(d=l);const p=(d-u)/2,m=2*i;r[e+m+0]=u+p,r[e+m+1]=p+(Math.abs(u)+p)*gi}}return r}function zi(t,e,n){return n.min.x=e[t],n.min.y=e[t+1],n.min.z=e[t+2],n.max.x=e[t+3],n.max.y=e[t+4],n.max.z=e[t+5],n}function _i(t){let e=-1,n=-1/0;for(let i=0;i<3;i++){const r=t[i+3]-t[i];r>n&&(n=r,e=i)}return e}function Ti(t,e){e.set(t)}function Bi(t,e,n){let i,r;for(let s=0;s<3;s++){const o=s+3;i=t[s],r=e[s],n[s]=i<r?i:r,i=t[o],r=e[o],n[o]=i>r?i:r}}function Pi(t,e,n){for(let i=0;i<3;i++){const r=e[t+2*i],s=e[t+2*i+1],o=r-s,a=r+s;o<n[i]&&(n[i]=o),a>n[i+3]&&(n[i+3]=a)}}function Ci(t){const e=t[3]-t[0],n=t[4]-t[1],i=t[5]-t[2];return 2*(e*n+n*i+i*e)}const Ei=32,ki=(t,e)=>t.candidate-e.candidate,Ni=new Array(Ei).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ii=new Float32Array(6);class Oi{constructor(){this.boundingData=new Float32Array(6)}}function Fi(t,e,n,i,r,s){let o=i,a=i+r-1;const h=s.pos,l=2*s.axis,u=n.offset||0;for(;;){for(;o<=a&&n[6*(o-u)+l]<h;)o++;for(;o<=a&&n[6*(a-u)+l]>=h;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let n=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=n}for(let t=0;t<6;t++){const e=o-u,i=a-u,r=n[6*e+t];n[6*e+t]=n[6*i+t],n[6*i+t]=r}o++,a--}}function Ri(t,e,n,i,r,s){let o=i,a=i+r-1;const h=s.pos,l=2*s.axis,u=n.offset||0;for(;;){for(;o<=a&&n[6*(o-u)+l]<h;)o++;for(;o<=a&&n[6*(a-u)+l]>=h;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){const e=o-u,i=a-u,r=n[6*e+t];n[6*e+t]=n[6*i+t],n[6*i+t]=r}o++,a--}}}let Vi,Ui,Li,qi;const Di=Math.pow(2,32);function Xi(t){return"count"in t?1:1+Xi(t.left)+Xi(t.right)}function Zi(t,e,n){return Vi=new Float32Array(n),Ui=new Uint32Array(n),Li=new Uint16Array(n),qi=new Uint8Array(n),ji(t,e)}function ji(t,e){const n=t/4,i=t/2,r="count"in e,s=e.boundingData;for(let o=0;o<6;o++)Vi[n+o]=s[o];if(r)return e.buffer?(qi.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(Ui[n+6]=e.offset,Li[i+14]=e.count,Li[i+15]=65535,t+mi);{const{left:i,right:r,splitAxis:s}=e;let o=ji(t+mi,i);const a=o/mi-t/mi;if(a>Di)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ui[n+6]=a,Ui[n+7]=s,ji(o,r)}}function Gi(t,e,n,i,r){const{maxDepth:s,verbose:o,maxLeafTris:a,strategy:h,onProgress:l,indirect:u}=r,c=t._indirectBuffer,d=t.geometry,p=d.index?d.index.array:null,f=u?Ri:Fi,y=bi(d),m=new Float32Array(6);let g=!1;const x=new Oi;return Si(e,n,i,x.boundingData,m),function t(n,i,r,l=null,u=0){!g&&u>=s&&(g=!0,o&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d)));if(r<=a||u>=s)return b(i+r),n.offset=i,n.count=r,n;const y=function(t,e,n,i,r,s){let o=-1,a=0;if(0===s)o=_i(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===s)o=_i(t),-1!==o&&(a=function(t,e,n,i){let r=0;const s=t.offset;for(let o=e,a=e+n;o<a;o++)r+=t[6*(o-s)+2*i];return r/n}(n,i,r,o));else if(2===s){const s=Ci(t);let h=yi*r;const l=n.offset||0,u=6*(i-l),c=6*(i+r-l);for(let t=0;t<3;t++){const i=e[t],l=(e[t+3]-i)/Ei;if(r<8){const e=[...Ni];e.length=r;let i=0;for(let r=u;r<c;r+=6,i++){const s=e[i];s.candidate=n[r+2*t],s.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:h}=s;for(let t=0;t<3;t++)h[t]=1/0,h[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Pi(r,n,o)}e.sort(ki);let l=r;for(let t=0;t<l;t++){const n=e[t];for(;t+1<l&&e[t+1].candidate===n.candidate;)e.splice(t+1,1),l--}for(let r=u;r<c;r+=6){const i=n[r+2*t];for(let t=0;t<l;t++){const s=e[t];i>=s.candidate?Pi(r,n,s.rightCacheBounds):(Pi(r,n,s.leftCacheBounds),s.count++)}}for(let n=0;n<l;n++){const i=e[n],l=i.count,u=r-i.count,c=i.leftCacheBounds,d=i.rightCacheBounds;let p=0;0!==l&&(p=Ci(c)/s);let f=0;0!==u&&(f=Ci(d)/s);const y=1+yi*(p*l+f*u);y<h&&(o=t,h=y,a=i.candidate)}}else{for(let t=0;t<Ei;t++){const e=Ni[t];e.count=0,e.candidate=i+l+t*l;const n=e.bounds;for(let t=0;t<3;t++)n[t]=1/0,n[t+3]=-1/0}for(let r=u;r<c;r+=6){let e=~~((n[r+2*t]-i)/l);e>=Ei&&(e=31);const s=Ni[e];s.count++,Pi(r,n,s.bounds)}const e=Ni[31];Ti(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Ni[t],n=Ni[t+1];Bi(e.bounds,n.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let n=0;n<31;n++){const e=Ni[n],i=e.count,l=e.bounds,u=Ni[n+1].rightCacheBounds;0!==i&&(0===d?Ti(l,Ii):Bi(l,Ii,Ii)),d+=i;let c=0,p=0;0!==d&&(c=Ci(Ii)/s);const f=r-d;0!==f&&(p=Ci(u)/s);const y=1+yi*(c*d+p*f);y<h&&(o=t,h=y,a=e.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:o,pos:a}}(n.boundingData,l,e,i,r,h);if(-1===y.axis)return b(i+r),n.offset=i,n.count=r,n;const x=f(c,p,e,i,r,y);if(x===i||x===i+r)b(i+r),n.offset=i,n.count=r;else{n.splitAxis=y.axis;const s=new Oi,o=i,a=x-i;n.left=s,Si(e,o,a,s.boundingData,m),t(s,o,a,m,u+1);const h=new Oi,l=x,c=r-a;n.right=h,Si(e,l,c,h.boundingData,m),t(h,l,c,m,u+1)}return n}(x,n,i,m),x;function b(t){l&&l(t/y)}}function Ji(t,e){const n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=t.geometry;let r,s;if(e.indirect){const n=Mi(i,e.range),o=function(t,e,n){const i=(t.index?t.index.count:t.attributes.position.count)/3>h(2,16),r=n.reduce((t,e)=>t+e.count,0),s=i?4:2,o=e?new SharedArrayBuffer(r*s):new ArrayBuffer(r*s),a=i?new Uint32Array(o):new Uint16Array(o);let l=0;for(let h=0;h<n.length;h++){const{offset:t,count:e}=n[h];for(let n=0;n<e;n++)a[l+n]=t+n;l+=e}return a}(i,e.useSharedArrayBuffer,n);t._indirectBuffer=o,r=Ai(i,0,o.length,o),s=[{offset:0,count:o.length}]}else{wi(i,e);const t=vi(i,e.range)[0];r=Ai(i,t.offset,t.count),s=Mi(i,e.range)}t._roots=s.map(i=>{const s=Gi(t,r,i.offset,i.count,e),o=Xi(s),a=new n(mi*o);return Zi(0,s,a),a})}class Wi{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let n=1/0,i=-1/0;for(let r=0,s=t.length;r<s;r++){const s=t[r][e];n=s<n?s:n,i=s>i?s:i}this.min=n,this.max=i}setFromPoints(t,e){let n=1/0,i=-1/0;for(let r=0,s=e.length;r<s;r++){const s=e[r],o=t.dot(s);n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}}Wi.prototype.setFromBox=function(){const t=new N;return function(e,n){const i=n.min,r=n.max;let s=1/0,o=-1/0;for(let a=0;a<=1;a++)for(let n=0;n<=1;n++)for(let h=0;h<=1;h++){t.x=i.x*a+r.x*(1-a),t.y=i.y*n+r.y*(1-n),t.z=i.z*h+r.z*(1-h);const l=e.dot(t);s=Math.min(l,s),o=Math.max(l,o)}this.min=s,this.max=o}}();const Yi=function(){const t=new N,e=new N,n=new N;return function(i,r,s){const o=i.start,a=t,h=r.start,l=e;n.subVectors(o,h),t.subVectors(i.end,i.start),e.subVectors(r.end,r.start);const u=n.dot(l),c=l.dot(a),d=l.dot(l),p=n.dot(a),f=a.dot(a)*d-c*c;let y,m;y=0!==f?(u*c-p*d)/f:0,m=(u+y*c)/d,s.x=y,s.y=m}}(),$i=function(){const t=new E,e=new N,n=new N;return function(i,r,s,o){Yi(i,r,t);let a=t.x,h=t.y;if(a>=0&&a<=1&&h>=0&&h<=1)return i.at(a,s),void r.at(h,o);if(a>=0&&a<=1)return h<0?r.at(0,o):r.at(1,o),void i.closestPointToPoint(o,!0,s);if(h>=0&&h<=1)return a<0?i.at(0,s):i.at(1,s),void r.closestPointToPoint(s,!0,o);{let t,l;t=a<0?i.start:i.end,l=h<0?r.start:r.end;const u=e,c=n;return i.closestPointToPoint(l,!0,e),r.closestPointToPoint(t,!0,n),u.distanceToSquared(l)<=c.distanceToSquared(t)?(s.copy(u),void o.copy(l)):(s.copy(t),void o.copy(c))}}}(),Hi=function(){const t=new N,e=new N,n=new tn,i=new li;return function(r,s){const{radius:o,center:a}=r,{a:h,b:l,c:u}=s;i.start=h,i.end=l;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=h,i.end=u;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=l,i.end=u;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const c=s.getPlane(n);if(Math.abs(c.distanceToPoint(a))<=o){const t=c.projectPoint(a,e);if(s.containsPoint(t))return!0}return!1}}(),Qi=["x","y","z"],Ki=1e-15;function tr(t){return Math.abs(t)<Ki}class er extends pe{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new N),this.satBounds=new Array(4).fill().map(()=>new Wi),this.points=[this.a,this.b,this.c],this.plane=new tn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new li,this.needsUpdate=!0}intersectsSphere(t){return Hi(t,this)}update(){const t=this.a,e=this.b,n=this.c,i=this.points,r=this.satAxes,s=this.satBounds,o=r[0],a=s[0];this.getNormal(o),a.setFromPoints(o,i);const h=r[1],l=s[1];h.subVectors(t,e),l.setFromPoints(h,i);const u=r[2],c=s[2];u.subVectors(e,n),c.setFromPoints(u,i);const d=r[3],p=s[3];d.subVectors(n,t),p.setFromPoints(d,i);const f=h.length(),y=u.length(),m=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,f<Ki?y<Ki||m<Ki?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(n)):y<Ki?m<Ki?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):m<Ki&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}er.prototype.closestPointToSegment=function(){const t=new N,e=new N,n=new li;return function(i,r=null,s=null){const{start:o,end:a}=i,h=this.points;let l,u=1/0;for(let c=0;c<3;c++){const o=(c+1)%3;n.start.copy(h[c]),n.end.copy(h[o]),$i(n,i,t,e),l=t.distanceToSquared(e),l<u&&(u=l,r&&r.copy(t),s&&s.copy(e))}return this.closestPointToPoint(o,t),l=o.distanceToSquared(t),l<u&&(u=l,r&&r.copy(t),s&&s.copy(o)),this.closestPointToPoint(a,t),l=a.distanceToSquared(t),l<u&&(u=l,r&&r.copy(t),s&&s.copy(a)),Math.sqrt(u)}}(),er.prototype.intersectsTriangle=function(){const t=new er,e=new Wi,n=new Wi,i=new N,r=new N,s=new N,o=new N,a=new li,h=new li,l=new N,u=new E,c=new E;function d(t,r,s,a){const h=i;t.isDegenerateIntoPoint||t.isDegenerateIntoSegment?h.copy(r.plane.normal):h.copy(t.plane.normal);const l=t.satBounds,u=t.satAxes;for(let i=1;i<4;i++){const s=l[i],a=u[i];if(e.setFromPoints(a,r.points),s.isSeparated(e))return!1;if(o.copy(h).cross(a),e.setFromPoints(o,t.points),n.setFromPoints(o,r.points),e.isSeparated(n))return!1}const c=r.satBounds,d=r.satAxes;for(let i=1;i<4;i++){const s=c[i],a=d[i];if(e.setFromPoints(a,t.points),s.isSeparated(e))return!1;if(o.crossVectors(h,a),e.setFromPoints(o,t.points),n.setFromPoints(o,r.points),e.isSeparated(n))return!1}return s&&(a||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),s.start.set(0,0,0),s.end.set(0,0,0)),!0}function p(t,e,n,i,r,s,o,a,h,l,u){let c=o/(o-a);l.x=i+(r-i)*c,u.start.subVectors(e,t).multiplyScalar(c).add(t),c=o/(o-h),l.y=i+(s-i)*c,u.end.subVectors(n,t).multiplyScalar(c).add(t)}function f(t,e,n,i,r,s,o,a,h,l,u){if(r>0)p(t.c,t.a,t.b,i,e,n,h,o,a,l,u);else if(s>0)p(t.b,t.a,t.c,n,e,i,a,o,h,l,u);else if(a*h>0||0!=o)p(t.a,t.b,t.c,e,n,i,o,a,h,l,u);else if(0!=a)p(t.b,t.a,t.c,n,e,i,a,o,h,l,u);else{if(0==h)return!0;p(t.c,t.a,t.b,i,e,n,h,o,a,l,u)}return!1}function y(t,e,n,r){const s=e.degenerateSegment,o=t.plane.distanceToPoint(s.start),a=t.plane.distanceToPoint(s.end);return tr(o)?tr(a)?d(t,e,n,r):(n&&(n.start.copy(s.start),n.end.copy(s.start)),t.containsPoint(s.start)):tr(a)?(n&&(n.start.copy(s.end),n.end.copy(s.end)),t.containsPoint(s.end)):null!=t.plane.intersectLine(s,i)&&(n&&(n.start.copy(i),n.end.copy(i)),t.containsPoint(i))}function m(t,e,n){const i=e.a;return!(!tr(t.plane.distanceToPoint(i))||!t.containsPoint(i))&&(n&&(n.start.copy(i),n.end.copy(i)),!0)}function g(t,e,n){const r=t.degenerateSegment,s=e.a;return r.closestPointToPoint(s,!0,i),s.distanceToSquared(i)<1e-30&&(n&&(n.start.copy(s),n.end.copy(s)),!0)}return function(e,n=null,o=!1){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);const p=function(t,e,n,o){if(t.isDegenerateIntoSegment){if(e.isDegenerateIntoSegment){const o=t.degenerateSegment,a=e.degenerateSegment,h=r,l=s;o.delta(h),a.delta(l);const u=i.subVectors(a.start,o.start),c=h.x*l.y-h.y*l.x;if(tr(c))return!1;const d=(u.x*l.y-u.y*l.x)/c,p=-(h.x*u.y-h.y*u.x)/c;return!(d<0||d>1||p<0||p>1)&&(!!tr(o.start.z+h.z*d-(a.start.z+l.z*p))&&(n&&(n.start.copy(o.start).addScaledVector(h,d),n.end.copy(o.start).addScaledVector(h,d)),!0))}return e.isDegenerateIntoPoint?g(t,e,n):y(e,t,n,o)}return t.isDegenerateIntoPoint?e.isDegenerateIntoPoint?e.a.distanceToSquared(t.a)<1e-30&&(n&&(n.start.copy(t.a),n.end.copy(t.a)),!0):e.isDegenerateIntoSegment?g(e,t,n):m(e,t,n):e.isDegenerateIntoPoint?m(t,e,n):e.isDegenerateIntoSegment?y(t,e,n,o):void 0}(this,e,n,o);if(void 0!==p)return p;const x=this.plane,b=e.plane;let w=b.distanceToPoint(this.a),v=b.distanceToPoint(this.b),M=b.distanceToPoint(this.c);tr(w)&&(w=0),tr(v)&&(v=0),tr(M)&&(M=0);const S=w*v,A=w*M;if(S>0&&A>0)return!1;let z=x.distanceToPoint(e.a),_=x.distanceToPoint(e.b),T=x.distanceToPoint(e.c);tr(z)&&(z=0),tr(_)&&(_=0),tr(T)&&(T=0);const B=z*_,P=z*T;if(B>0&&P>0)return!1;r.copy(x.normal),s.copy(b.normal);const C=r.cross(s);let E=0,k=Math.abs(C.x);const N=Math.abs(C.y);N>k&&(k=N,E=1);Math.abs(C.z)>k&&(E=2);const I=Qi[E],O=this.a[I],F=this.b[I],R=this.c[I],V=e.a[I],U=e.b[I],L=e.c[I];if(f(this,O,F,R,S,A,w,v,M,u,a))return d(this,e,n,o);if(f(e,V,U,L,B,P,z,_,T,c,h))return d(this,e,n,o);if(u.y<u.x){const t=u.y;u.y=u.x,u.x=t,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(c.y<c.x){const t=c.y;c.y=c.x,c.x=t,l.copy(h.start),h.start.copy(h.end),h.end.copy(l)}return!(u.y<c.x||c.y<u.x)&&(n&&(c.x>u.x?n.start.copy(h.start):n.start.copy(a.start),c.y<u.y?n.end.copy(h.end):n.end.copy(a.end)),!0)}}(),er.prototype.distanceToPoint=function(){const t=new N;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),er.prototype.distanceToTriangle=function(){const t=new N,e=new N,n=["a","b","c"],i=new li,r=new li;return function(s,o=null,a=null){const h=o||a?i:null;if(this.intersectsTriangle(s,h))return(o||a)&&(o&&h.getCenter(o),a&&h.getCenter(a)),0;let l=1/0;for(let e=0;e<3;e++){let i;const r=n[e],h=s[r];this.closestPointToPoint(h,t),i=h.distanceToSquared(t),i<l&&(l=i,o&&o.copy(t),a&&a.copy(h));const u=this[r];s.closestPointToPoint(u,t),i=u.distanceToSquared(t),i<l&&(l=i,o&&o.copy(u),a&&a.copy(t))}for(let u=0;u<3;u++){const h=n[u],c=n[(u+1)%3];i.set(this[h],this[c]);for(let u=0;u<3;u++){const h=n[u],c=n[(u+1)%3];r.set(s[h],s[c]),$i(i,r,t,e);const d=t.distanceToSquared(e);d<l&&(l=d,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(l)}}();class nr{constructor(t,e,n){this.isOrientedBox=!0,this.min=new N,this.max=new N,this.matrix=new _t,this.invMatrix=new _t,this.points=new Array(8).fill().map(()=>new N),this.satAxes=new Array(3).fill().map(()=>new N),this.satBounds=new Array(3).fill().map(()=>new Wi),this.alignedSatBounds=new Array(3).fill().map(()=>new Wi),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n)}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}nr.prototype.update=function(){return function(){const t=this.matrix,e=this.min,n=this.max,i=this.points;for(let h=0;h<=1;h++)for(let r=0;r<=1;r++)for(let s=0;s<=1;s++){const o=i[1*h|2*r|4*s];o.x=h?n.x:e.x,o.y=r?n.y:e.y,o.z=s?n.z:e.z,o.applyMatrix4(t)}const r=this.satBounds,s=this.satAxes,o=i[0];for(let h=0;h<3;h++){const t=s[h],e=r[h],n=i[1<<h];t.subVectors(o,n),e.setFromPoints(t,i)}const a=this.alignedSatBounds;a[0].setFromPointsField(i,"x"),a[1].setFromPointsField(i,"y"),a[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),nr.prototype.intersectsBox=function(){const t=new Wi;return function(e){this.needsUpdate&&this.update();const n=e.min,i=e.max,r=this.satBounds,s=this.satAxes,o=this.alignedSatBounds;if(t.min=n.x,t.max=i.x,o[0].isSeparated(t))return!1;if(t.min=n.y,t.max=i.y,o[1].isSeparated(t))return!1;if(t.min=n.z,t.max=i.z,o[2].isSeparated(t))return!1;for(let a=0;a<3;a++){const n=s[a],i=r[a];if(t.setFromBox(n,e),i.isSeparated(t))return!1}return!0}}(),nr.prototype.intersectsTriangle=function(){const t=new er,e=new Array(3),n=new Wi,i=new Wi,r=new N;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(t.copy(s),t.update(),s=t);const o=this.satBounds,a=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let t=0;t<3;t++){const i=o[t],r=a[t];if(n.setFromPoints(r,e),i.isSeparated(n))return!1}const h=s.satBounds,l=s.satAxes,u=this.points;for(let t=0;t<3;t++){const e=h[t],i=l[t];if(n.setFromPoints(i,u),e.isSeparated(n))return!1}for(let t=0;t<3;t++){const s=a[t];for(let t=0;t<4;t++){const o=l[t];if(r.crossVectors(s,o),n.setFromPoints(r,e),i.setFromPoints(r,u),n.isSeparated(i))return!1}}return!0}}(),nr.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),nr.prototype.distanceToPoint=function(){const t=new N;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),nr.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new li),n=new Array(12).fill().map(()=>new li),i=new N,r=new N;return function(s,o=0,a=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(a||h)&&(s.getCenter(r),this.closestPointToPoint(r,i),s.closestPointToPoint(i,r),a&&a.copy(i),h&&h.copy(r)),0;const l=o*o,u=s.min,c=s.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(u,c);const n=e.distanceToSquared(r);if(n<p&&(p=n,a&&a.copy(e),h&&h.copy(r),n<l))return Math.sqrt(n)}let f=0;for(let i=0;i<3;i++)for(let r=0;r<=1;r++)for(let s=0;s<=1;s++){const o=(i+1)%3,a=(i+2)%3,h=1<<i|r<<o|s<<a,l=d[r<<o|s<<a],p=d[h];e[f].set(l,p);const y=t[i],m=t[o],g=t[a],x=n[f],b=x.start,w=x.end;b[y]=u[y],b[m]=r?u[m]:c[m],b[g]=s?u[g]:c[m],w[y]=c[y],w[m]=r?u[m]:c[m],w[g]=s?u[g]:c[m],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let n=0;n<=1;n++){r.x=t?c.x:u.x,r.y=e?c.y:u.y,r.z=n?c.z:u.z,this.closestPointToPoint(r,i);const s=r.distanceToSquared(i);if(s<p&&(p=s,a&&a.copy(i),h&&h.copy(r),s<l))return Math.sqrt(s)}for(let t=0;t<12;t++){const s=e[t];for(let t=0;t<12;t++){const e=n[t];$i(s,e,i,r);const o=i.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(i),h&&h.copy(r),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}}();class ir{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class rr extends ir{constructor(){super(()=>new er)}}const sr=new rr;function or(t,e){return 65535===e[t+15]}function ar(t,e){return e[t+6]}function hr(t,e){return e[t+14]}function lr(t){return t+8}function ur(t,e){return t+8*e[t+6]}function cr(t,e){return e[t+7]}function dr(t){return t}class pr{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}}const fr=new pr;let yr,mr;const gr=[],xr=new ir(()=>new K);function br(t,e,n,i,r,s){yr=xr.getPrimitive(),mr=xr.getPrimitive(),gr.push(yr,mr),fr.setBuffer(t._roots[e]);const o=wr(0,t.geometry,n,i,r,s);fr.clearBuffer(),xr.releasePrimitive(yr),xr.releasePrimitive(mr),gr.pop(),gr.pop();const a=gr.length;return a>0&&(mr=gr[a-1],yr=gr[a-2]),o}function wr(t,e,n,i,r=null,s=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=fr;let u=2*t;if(or(u,h)){const e=ar(t,l),n=hr(u,h);return zi(t,a,yr),i(e,n,!1,o,s+t/8,yr)}{let u=function(t){const{uint16Array:e,uint32Array:n}=fr;let i=2*t;for(;!or(i,e);)i=2*(t=lr(t));return ar(t,n)},c=function(t){const{uint16Array:e,uint32Array:n}=fr;let i=2*t;for(;!or(i,e);)i=2*(t=ur(t,n));return ar(t,n)+hr(i,e)};const d=lr(t),p=ur(t,l);let f,y,m,g,x=d,b=p;if(r&&(m=yr,g=mr,zi(x,a,m),zi(b,a,g),f=r(m),y=r(g),y<f)){x=p,b=d;const t=f;f=y,y=t,m=g}m||(m=yr,zi(x,a,m));const w=n(m,or(2*x,h),f,o+1,s+x/8);let v;if(2===w){const t=u(x);v=i(t,c(x)-t,!0,o+1,s+x/8,m)}else v=w&&wr(x,e,n,i,r,s,o+1);if(v)return!0;g=mr,zi(b,a,g);const M=n(g,or(2*b,h),y,o+1,s+b/8);let S;if(2===M){const t=u(b);S=i(t,c(b)-t,!0,o+1,s+b/8,g)}else S=M&&wr(b,e,n,i,r,s,o+1);return!!S}}const vr=new N,Mr=new N;const Sr=parseInt(t)>=169,Ar=parseInt(t)<=161,zr=new N,_r=new N,Tr=new N,Br=new E,Pr=new E,Cr=new E,Er=new N,kr=new N,Nr=new N,Ir=new N;function Or(t,e,n,i,r,s,o,a,h,l,u){zr.fromBufferAttribute(e,s),_r.fromBufferAttribute(e,o),Tr.fromBufferAttribute(e,a);const c=function(t,e,n,i,r,s,o,a){let h;if(h=1===s?t.intersectTriangle(i,n,e,!0,r):t.intersectTriangle(e,n,i,2!==s,r),null===h)return null;const l=t.origin.distanceTo(r);return l<o||l>a?null:{distance:l,point:r.clone()}}(t,zr,_r,Tr,Ir,h,l,u);if(c){if(i){Br.fromBufferAttribute(i,s),Pr.fromBufferAttribute(i,o),Cr.fromBufferAttribute(i,a),c.uv=new E;const t=pe.getInterpolation(Ir,zr,_r,Tr,Br,Pr,Cr,c.uv);Sr||(c.uv=t)}if(r){Br.fromBufferAttribute(r,s),Pr.fromBufferAttribute(r,o),Cr.fromBufferAttribute(r,a),c.uv1=new E;const t=pe.getInterpolation(Ir,zr,_r,Tr,Br,Pr,Cr,c.uv1);Sr||(c.uv1=t),Ar&&(c.uv2=c.uv1)}if(n){Er.fromBufferAttribute(n,s),kr.fromBufferAttribute(n,o),Nr.fromBufferAttribute(n,a),c.normal=new N;const e=pe.getInterpolation(Ir,zr,_r,Tr,Er,kr,Nr,c.normal);c.normal.dot(t.direction)>0&&c.normal.multiplyScalar(-1),Sr||(c.normal=e)}const e={a:s,b:o,c:a,normal:new N,materialIndex:0};if(pe.getNormal(zr,_r,Tr,e.normal),c.face=e,c.faceIndex=s,Sr){const t=new N;pe.getBarycoord(Ir,zr,_r,Tr,t),c.barycoord=t}}return c}function Fr(t){return t&&t.isMaterial?t.side:t}function Rr(t,e,n,i,r,s,o){const a=3*i;let h=a+0,l=a+1,u=a+2;const{index:c,groups:d}=t;t.index&&(h=c.getX(h),l=c.getX(l),u=c.getX(u));const{position:p,normal:f,uv:y,uv1:m}=t.attributes;if(Array.isArray(e)){const t=3*i;for(let a=0,c=d.length;a<c;a++){const{start:c,count:g,materialIndex:x}=d[a];if(t>=c&&t<c+g){const t=Or(n,p,f,y,m,h,l,u,Fr(e[x]),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=x,!r)return t;r.push(t)}}}}else{const t=Or(n,p,f,y,m,h,l,u,Fr(e),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=0,!r)return t;r.push(t)}}return null}function Vr(t,e,n,i){const r=t.a,s=t.b,o=t.c;let a=e,h=e+1,l=e+2;n&&(a=n.getX(a),h=n.getX(h),l=n.getX(l)),r.x=i.getX(a),r.y=i.getY(a),r.z=i.getZ(a),s.x=i.getX(h),s.y=i.getY(h),s.z=i.getZ(h),o.x=i.getX(l),o.y=i.getY(l),o.z=i.getZ(l)}function Ur(t,e,n,i,r,s,o){const{geometry:a}=n,{index:h}=a,l=a.attributes.position;for(let u=t,c=e+t;u<c;u++){let t;if(t=u,Vr(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function Lr(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const n=t.geometry,i=n.index?n.index.array:null,r=n.attributes.position;let s,o,a,h,l=0;const u=t._roots;for(let d=0,p=u.length;d<p;d++)s=u[d],o=new Uint32Array(s),a=new Uint16Array(s),h=new Float32Array(s),c(0,l),l+=s.byteLength;function c(t,n,s=!1){const l=2*t;if(or(l,a)){const e=o[t+6];let n=1/0,s=1/0,u=1/0,c=-1/0,d=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[l+14]);t<o;t++){let e=i[t];const o=r.getX(e),a=r.getY(e),h=r.getZ(e);o<n&&(n=o),o>c&&(c=o),a<s&&(s=a),a>d&&(d=a),h<u&&(u=h),h>p&&(p=h)}return(h[t+0]!==n||h[t+1]!==s||h[t+2]!==u||h[t+3]!==c||h[t+4]!==d||h[t+5]!==p)&&(h[t+0]=n,h[t+1]=s,h[t+2]=u,h[t+3]=c,h[t+4]=d,h[t+5]=p,!0)}{const i=lr(t),r=ur(t,o);let a=s,l=!1,u=!1;if(e){if(!a){const t=i/8+n/mi,s=r/8+n/mi;l=e.has(t),u=e.has(s),a=!l&&!u}}else l=!0,u=!0;const d=a||u;let p=!1;(a||l)&&(p=c(i,n,a));let f=!1;d&&(f=c(r,n,a));const y=p||f;if(y)for(let e=0;e<3;e++){const n=i+e,s=r+e,o=h[n],a=h[n+3],l=h[s],u=h[s+3];h[t+e]=o<l?o:l,h[t+e+3]=a>u?a:u}return y}}}function qr(t,e,n,i,r){let s,o,a,h,l,u;const c=1/n.direction.x,d=1/n.direction.y,p=1/n.direction.z,f=n.origin.x,y=n.origin.y,m=n.origin.z;let g=e[t],x=e[t+3],b=e[t+1],w=e[t+3+1],v=e[t+2],M=e[t+3+2];return c>=0?(s=(g-f)*c,o=(x-f)*c):(s=(x-f)*c,o=(g-f)*c),d>=0?(a=(b-y)*d,h=(w-y)*d):(a=(w-y)*d,h=(b-y)*d),!(s>h||a>o)&&((a>s||isNaN(s))&&(s=a),(h<o||isNaN(o))&&(o=h),p>=0?(l=(v-m)*p,u=(M-m)*p):(l=(M-m)*p,u=(v-m)*p),!(s>u||l>o)&&((l>s||s!=s)&&(s=l),(u<o||o!=o)&&(o=u),s<=r&&o>=i))}function Dr(t,e,n,i,r,s,o){const{geometry:a}=n,{index:h}=a,l=a.attributes.position;for(let u=t,c=e+t;u<c;u++){let t;if(t=n.resolveTriangleIndex(u),Vr(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function Xr(t,e,n,i,r,s,o){fr.setBuffer(t._roots[e]),Zr(0,t,n,i,r,s,o),fr.clearBuffer()}function Zr(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=fr,u=2*t;if(or(u,h)){!function(t,e,n,i,r,s,o,a){const{geometry:h,_indirectBuffer:l}=t;for(let u=i,c=i+r;u<c;u++)Rr(h,e,n,u,s,o,a)}(e,n,i,ar(t,l),hr(u,h),r,s,o)}else{const h=lr(t);qr(h,a,i,s,o)&&Zr(h,e,n,i,r,s,o);const u=ur(t,l);qr(u,a,i,s,o)&&Zr(u,e,n,i,r,s,o)}}const jr=["x","y","z"];function Gr(t,e,n,i,r,s){fr.setBuffer(t._roots[e]);const o=Jr(0,t,n,i,r,s);return fr.clearBuffer(),o}function Jr(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=fr;let l=2*t;if(or(l,a)){return function(t,e,n,i,r,s,o){const{geometry:a,_indirectBuffer:h}=t;let l=1/0,u=null;for(let c=i,d=i+r;c<d;c++){let t;t=Rr(a,e,n,c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,ar(t,h),hr(l,a),r,s)}{const a=cr(t,h),l=jr[a],u=i.direction[l]>=0;let c,d;u?(c=lr(t),d=ur(t,h)):(c=ur(t,h),d=lr(t));const p=qr(c,o,i,r,s)?Jr(c,e,n,i,r,s):null;if(p){const t=p.point[l];if(u?t<=o[d+a]:t>=o[d+a+3])return p}const f=qr(d,o,i,r,s)?Jr(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Wr=new K,Yr=new er,$r=new er,Hr=new _t,Qr=new nr,Kr=new nr;function ts(t,e,n,i){fr.setBuffer(t._roots[e]);const r=es(0,t,n,i);return fr.clearBuffer(),r}function es(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=fr;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),Qr.set(n.boundingBox.min,n.boundingBox.max,i),r=Qr);if(!or(h,o)){const o=lr(t),h=ur(t,a);zi(o,s,Wr);if(r.intersectsBox(Wr)&&es(o,e,n,i,r))return!0;zi(h,s,Wr);return!!(r.intersectsBox(Wr)&&es(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=ar(t,a),f=hr(h,o);if(Hr.copy(i).invert(),n.boundsTree){zi(t,s,Kr),Kr.matrix.copy(Hr),Kr.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Kr.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let e=3*p,n=3*(f+p);e<n;e+=3)if(Vr($r,e,l,u),$r.needsUpdate=!0,t.intersectsTriangle($r))return!0;return!1}})}{const t=bi(n);for(let e=3*p,n=3*(f+p);e<n;e+=3){Vr(Yr,e,l,u),Yr.a.applyMatrix4(Hr),Yr.b.applyMatrix4(Hr),Yr.c.applyMatrix4(Hr),Yr.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(Vr($r,e,c,d),$r.needsUpdate=!0,Yr.intersectsTriangle($r))return!0}}}}const ns=new _t,is=new nr,rs=new nr,ss=new N,os=new N,as=new N,hs=new N;function ls(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),is.set(e.boundingBox.min,e.boundingBox.max,n),is.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=sr.getPrimitive(),p=sr.getPrimitive();let f=ss,y=os,m=null,g=null;r&&(m=as,g=hs);let x=1/0,b=null,w=null;return ns.copy(n).invert(),rs.matrix.copy(ns),t.shapecast({boundsTraverseOrder:t=>is.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(rs.min.copy(t.min),rs.max.copy(t.max),rs.needsUpdate=!0),!0),intersectsRange:(t,i)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>rs.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,r)=>{for(let o=e,a=e+r;o<a;o++){Vr(p,3*o,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++){Vr(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,m);if(t<x&&(y.copy(f),g&&g.copy(m),x=t,b=e,w=o),t<s)return!0}}}})}for(let r=0,o=bi(e);r<o;r++){Vr(p,3*r,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++){Vr(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,m);if(t<x&&(y.copy(f),g&&g.copy(m),x=t,b=e,w=r),t<s)return!0}}}}),sr.releasePrimitive(d),sr.releasePrimitive(p),x===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=x,i.faceIndex=b,r&&(r.point?r.point.copy(g):r.point=g.clone(),r.point.applyMatrix4(ns),y.applyMatrix4(ns),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}function us(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const n=t.geometry,i=n.index?n.index.array:null,r=n.attributes.position;let s,o,a,h,l=0;const u=t._roots;for(let d=0,p=u.length;d<p;d++)s=u[d],o=new Uint32Array(s),a=new Uint16Array(s),h=new Float32Array(s),c(0,l),l+=s.byteLength;function c(n,s,l=!1){const u=2*n;if(or(u,a)){const e=o[n+6];let s=1/0,l=1/0,c=1/0,d=-1/0,p=-1/0,f=-1/0;for(let n=e,o=e+a[u+14];n<o;n++){const e=3*t.resolveTriangleIndex(n);for(let t=0;t<3;t++){let n=e+t;n=i?i[n]:n;const o=r.getX(n),a=r.getY(n),h=r.getZ(n);o<s&&(s=o),o>d&&(d=o),a<l&&(l=a),a>p&&(p=a),h<c&&(c=h),h>f&&(f=h)}}return(h[n+0]!==s||h[n+1]!==l||h[n+2]!==c||h[n+3]!==d||h[n+4]!==p||h[n+5]!==f)&&(h[n+0]=s,h[n+1]=l,h[n+2]=c,h[n+3]=d,h[n+4]=p,h[n+5]=f,!0)}{const t=lr(n),i=ur(n,o);let r=l,a=!1,u=!1;if(e){if(!r){const n=t/8+s/mi,o=i/8+s/mi;a=e.has(n),u=e.has(o),r=!a&&!u}}else a=!0,u=!0;const d=r||u;let p=!1;(r||a)&&(p=c(t,s,r));let f=!1;d&&(f=c(i,s,r));const y=p||f;if(y)for(let e=0;e<3;e++){const r=t+e,s=i+e,o=h[r],a=h[r+3],l=h[s],u=h[s+3];h[n+e]=o<l?o:l,h[n+e+3]=a>u?a:u}return y}}}function cs(t,e,n,i,r,s,o){fr.setBuffer(t._roots[e]),ds(0,t,n,i,r,s,o),fr.clearBuffer()}function ds(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=fr,u=2*t;if(or(u,h)){!function(t,e,n,i,r,s,o,a){const{geometry:h,_indirectBuffer:l}=t;for(let u=i,c=i+r;u<c;u++)Rr(h,e,n,l?l[u]:u,s,o,a)}(e,n,i,ar(t,l),hr(u,h),r,s,o)}else{const h=lr(t);qr(h,a,i,s,o)&&ds(h,e,n,i,r,s,o);const u=ur(t,l);qr(u,a,i,s,o)&&ds(u,e,n,i,r,s,o)}}const ps=["x","y","z"];function fs(t,e,n,i,r,s){fr.setBuffer(t._roots[e]);const o=ys(0,t,n,i,r,s);return fr.clearBuffer(),o}function ys(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=fr;let l=2*t;if(or(l,a)){return function(t,e,n,i,r,s,o){const{geometry:a,_indirectBuffer:h}=t;let l=1/0,u=null;for(let c=i,d=i+r;c<d;c++){let t;t=Rr(a,e,n,h?h[c]:c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,ar(t,h),hr(l,a),r,s)}{const a=cr(t,h),l=ps[a],u=i.direction[l]>=0;let c,d;u?(c=lr(t),d=ur(t,h)):(c=ur(t,h),d=lr(t));const p=qr(c,o,i,r,s)?ys(c,e,n,i,r,s):null;if(p){const t=p.point[l];if(u?t<=o[d+a]:t>=o[d+a+3])return p}const f=qr(d,o,i,r,s)?ys(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const ms=new K,gs=new er,xs=new er,bs=new _t,ws=new nr,vs=new nr;function Ms(t,e,n,i){fr.setBuffer(t._roots[e]);const r=Ss(0,t,n,i);return fr.clearBuffer(),r}function Ss(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=fr;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),ws.set(n.boundingBox.min,n.boundingBox.max,i),r=ws);if(!or(h,o)){const o=lr(t),h=ur(t,a);zi(o,s,ms);if(r.intersectsBox(ms)&&Ss(o,e,n,i,r))return!0;zi(h,s,ms);return!!(r.intersectsBox(ms)&&Ss(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=ar(t,a),f=hr(h,o);if(bs.copy(i).invert(),n.boundsTree){zi(t,s,vs),vs.matrix.copy(bs),vs.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>vs.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let n=p,i=f+p;n<i;n++)if(Vr(xs,3*e.resolveTriangleIndex(n),l,u),xs.needsUpdate=!0,t.intersectsTriangle(xs))return!0;return!1}})}{const t=bi(n);for(let n=p,i=f+p;n<i;n++){const i=e.resolveTriangleIndex(n);Vr(gs,3*i,l,u),gs.a.applyMatrix4(bs),gs.b.applyMatrix4(bs),gs.c.applyMatrix4(bs),gs.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(Vr(xs,e,c,d),xs.needsUpdate=!0,gs.intersectsTriangle(xs))return!0}}}}const As=new _t,zs=new nr,_s=new nr,Ts=new N,Bs=new N,Ps=new N,Cs=new N;function Es(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),zs.set(e.boundingBox.min,e.boundingBox.max,n),zs.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=sr.getPrimitive(),p=sr.getPrimitive();let f=Ts,y=Bs,m=null,g=null;r&&(m=Ps,g=Cs);let x=1/0,b=null,w=null;return As.copy(n).invert(),_s.matrix.copy(As),t.shapecast({boundsTraverseOrder:t=>zs.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(_s.min.copy(t.min),_s.max.copy(t.max),_s.needsUpdate=!0),!0),intersectsRange:(i,r)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>_s.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,o)=>{for(let v=e,M=e+o;v<M;v++){const e=a.resolveTriangleIndex(v);Vr(p,3*e,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=i,o=i+r;n<o;n++){const e=t.resolveTriangleIndex(n);Vr(d,3*e,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,m);if(i<x&&(y.copy(f),g&&g.copy(m),x=i,b=n,w=v),i<s)return!0}}}})}for(let o=0,a=bi(e);o<a;o++){Vr(p,3*o,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=i,n=i+r;e<n;e++){const n=t.resolveTriangleIndex(e);Vr(d,3*n,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,m);if(i<x&&(y.copy(f),g&&g.copy(m),x=i,b=e,w=o),i<s)return!0}}}}),sr.releasePrimitive(d),sr.releasePrimitive(p),x===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=x,i.faceIndex=b,r&&(r.point?r.point.copy(g):r.point=g.clone(),r.point.applyMatrix4(As),y.applyMatrix4(As),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}const ks=new fr.constructor,Ns=new fr.constructor,Is=new ir(()=>new K),Os=new K,Fs=new K,Rs=new K,Vs=new K;let Us=!1;function Ls(t,e,n,i,r,s=0,o=0,a=0,h=0,l=null,u=!1){let c,d;u?(c=Ns,d=ks):(c=ks,d=Ns);const p=c.float32Array,f=c.uint32Array,y=c.uint16Array,m=d.float32Array,g=d.uint32Array,x=d.uint16Array,b=2*e,w=or(2*t,y),v=or(b,x);let M=!1;if(v&&w)M=u?r(ar(e,g),hr(2*e,x),ar(t,f),hr(2*t,y),h,o+e/8,a,s+t/8):r(ar(t,f),hr(2*t,y),ar(e,g),hr(2*e,x),a,s+t/8,h,o+e/8);else if(v){const l=Is.getPrimitive();zi(e,m,l),l.applyMatrix4(n);const c=lr(t),d=ur(t,f);zi(c,p,Os),zi(d,p,Fs);const y=l.intersectsBox(Os),g=l.intersectsBox(Fs);M=y&&Ls(e,c,i,n,r,o,s,h,a+1,l,!u)||g&&Ls(e,d,i,n,r,o,s,h,a+1,l,!u),Is.releasePrimitive(l)}else{const c=lr(e),d=ur(e,g);zi(c,m,Rs),zi(d,m,Vs);const y=l.intersectsBox(Rs),x=l.intersectsBox(Vs);if(y&&x)M=Ls(t,c,n,i,r,s,o,a,h+1,l,u)||Ls(t,d,n,i,r,s,o,a,h+1,l,u);else if(y)if(w)M=Ls(t,c,n,i,r,s,o,a,h+1,l,u);else{const e=Is.getPrimitive();e.copy(Rs).applyMatrix4(n);const l=lr(t),d=ur(t,f);zi(l,p,Os),zi(d,p,Fs);const y=e.intersectsBox(Os),m=e.intersectsBox(Fs);M=y&&Ls(c,l,i,n,r,o,s,h,a+1,e,!u)||m&&Ls(c,d,i,n,r,o,s,h,a+1,e,!u),Is.releasePrimitive(e)}else if(x)if(w)M=Ls(t,d,n,i,r,s,o,a,h+1,l,u);else{const e=Is.getPrimitive();e.copy(Vs).applyMatrix4(n);const l=lr(t),c=ur(t,f);zi(l,p,Os),zi(c,p,Fs);const y=e.intersectsBox(Os),m=e.intersectsBox(Fs);M=y&&Ls(d,l,i,n,r,o,s,h,a+1,e,!u)||m&&Ls(d,c,i,n,r,o,s,h,a+1,e,!u),Is.releasePrimitive(e)}}return M}const qs=new nr,Ds=new K,Xs={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Zs{static serialize(t,e={}){e=u({cloneBuffers:!0},e);const n=t.geometry,i=t._roots,r=t._indirectBuffer,s=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(o.roots=i.map(t=>t.slice()),o.index=s?s.array.slice():null,o.indirectBuffer=r?r.slice():null):(o.roots=i,o.index=s?s.array:null,o.indirectBuffer=r),o}static deserialize(t,e,n={}){n=u({setIndex:!0,indirect:Boolean(t.indirectBuffer)},n);const{index:i,roots:r,indirectBuffer:s}=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."),function(t){for(let e=0;e<t.length;e++){const n=t[e],i=new Uint32Array(n),r=new Uint16Array(n);for(let t=0,e=n.byteLength/mi;t<e;t++){const e=8*t;or(2*e,r)||(i[e+6]=i[e+6]/8-t)}}}(r));const o=new Zs(e,c(u({},n),{[xi]:!0}));if(o._roots=r,o._indirectBuffer=s||null,n.setIndex){const n=e.getIndex();if(null===n){const n=new _e(t.index,1,!1);e.setIndex(n)}else n.array!==i&&(n.array.set(i),n.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign(c(u({},Xs),{[xi]:!1}),e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[xi]||(Ji(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new K))),this.resolveTriangleIndex=e.indirect?t=>this._indirectBuffer[t]:t=>t}shiftTriangleOffsets(t){const e=this._indirectBuffer;if(e)for(let n=0,i=e.length;n<i;n++)e[n]+=t;else{const e=this._roots;for(let n=0;n<e.length;n++){const i=e[n],r=new Uint32Array(i),s=new Uint16Array(i),o=i.byteLength/mi;for(let e=0;e<o;e++){const n=8*e;or(2*n,s)&&(r[n+6]+=t)}}}}refit(t=null){return(this.indirect?us:Lr)(this,t)}traverse(t,e=0){const n=this._roots[e],i=new Uint32Array(n),r=new Uint16Array(n);!function e(s,o=0){const a=2*s,h=or(a,r);if(h){const e=i[s+6],l=r[a+14];t(o,h,new Float32Array(n,4*s,6),e,l)}else{const r=lr(s),a=ur(s,i),l=cr(s,i);t(o,h,new Float32Array(n,4*s,6),l)||(e(r,o+1),e(a,o+1))}}(0)}raycast(t,e=0,n=0,i=1/0){const r=this._roots,s=[],o=this.indirect?cs:Xr;for(let a=0,h=r.length;a<h;a++)o(this,a,e,t,s,n,i);return s}raycastFirst(t,e=0,n=0,i=1/0){const r=this._roots;let s=null;const o=this.indirect?fs:Gr;for(let a=0,h=r.length;a<h;a++){const r=o(this,a,e,t,n,i);null!=r&&(null==s||r.distance<s.distance)&&(s=r)}return s}intersectsGeometry(t,e){let n=!1;const i=this._roots,r=this.indirect?Ms:ts;for(let s=0,o=i.length;s<o&&(n=r(this,s,t,e),!n);s++);return n}shapecast(t){const e=sr.getPrimitive(),n=this.indirect?Dr:Ur;let{boundsTraverseOrder:i,intersectsBounds:r,intersectsRange:s,intersectsTriangle:o}=t;if(s&&o){const t=s;s=(i,r,s,a,h)=>!!t(i,r,s,a,h)||n(i,r,this,o,s,a,e)}else s||(s=o?(t,i,r,s)=>n(t,i,this,o,r,s,e):(t,e,n)=>n);let a=!1,h=0;const l=this._roots;for(let u=0,c=l.length;u<c;u++){const t=l[u];if(a=br(this,u,r,s,i,h),a)break;h+=t.byteLength/mi}return sr.releasePrimitive(e),a}bvhcast(t,e,n){let{intersectsRanges:i,intersectsTriangles:r}=n;const s=sr.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);Vr(s,3*e,o,a)}:t=>{Vr(s,3*t,o,a)},l=sr.getPrimitive(),u=t.geometry.index,c=t.geometry.attributes.position,d=t.indirect?e=>{const n=t.resolveTriangleIndex(e);Vr(l,3*n,u,c)}:t=>{Vr(l,3*t,u,c)};if(r){const t=(t,n,i,o,a,u,c,p)=>{for(let f=i,y=i+o;f<y;f++){d(f),l.a.applyMatrix4(e),l.b.applyMatrix4(e),l.c.applyMatrix4(e),l.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++)if(h(e),s.needsUpdate=!0,r(s,l,e,f,a,u,c,p))return!0}return!1};if(i){const e=i;i=function(n,i,r,s,o,a,h,l){return!!e(n,i,r,s,o,a,h,l)||t(n,i,r,s,o,a,h,l)}}else i=t}return function(t,e,n,i){if(Us)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Us=!0;const r=t._roots,s=e._roots;let o,a=0,h=0;const l=(new _t).copy(n).invert();for(let u=0,c=r.length;u<c;u++){ks.setBuffer(r[u]),h=0;const t=Is.getPrimitive();zi(dr(0),ks.float32Array,t),t.applyMatrix4(l);for(let e=0,r=s.length;e<r&&(Ns.setBuffer(s[e]),o=Ls(0,0,n,l,i,a,h,0,0,t),Ns.clearBuffer(),h+=s[e].byteLength/mi,!o);e++);if(Is.releasePrimitive(t),ks.clearBuffer(),a+=r[u].byteLength/mi,o)break}return Us=!1,o}(this,t,e,i)}intersectsBox(t,e){return qs.set(t.min,t.max,e),qs.needsUpdate=!0,this.shapecast({intersectsBounds:t=>qs.intersectsBox(t),intersectsTriangle:t=>qs.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,n={},i={},r=0,s=1/0){return(this.indirect?Es:ls)(this,t,e,n,i,r,s)}closestPointToPoint(t,e={},n=0,i=1/0){return function(t,e,n={},i=0,r=1/0){const s=i*i,o=r*r;let a=1/0,h=null;if(t.shapecast({boundsTraverseOrder:t=>(vr.copy(e).clamp(t.min,t.max),vr.distanceToSquared(e)),intersectsBounds:(t,e,n)=>n<a&&n<o,intersectsTriangle:(t,n)=>{t.closestPointToPoint(e,vr);const i=e.distanceToSquared(vr);return i<a&&(Mr.copy(vr),a=i,h=n),i<s}}),a===1/0)return null;const l=Math.sqrt(a);return n.point?n.point.copy(Mr):n.point=Mr.clone(),n.distance=l,n.faceIndex=h,n}(this,t,e,n,i)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{zi(0,new Float32Array(e),Ds),t.union(Ds)}),t}}const js=1e-6,Gs=Math.pow(10,-Math.log10(js)),Js=5e-7*Gs;function Ws(t){return~~(t*Gs+Js)}function Ys(t){return`${Ws(t.x)},${Ws(t.y)}`}function $s(t){return`${Ws(t.x)},${Ws(t.y)},${Ws(t.z)}`}function Hs(t){return`${Ws(t.x)},${Ws(t.y)},${Ws(t.z)},${Ws(t.w)}`}function Qs(t,e,n){n.direction.subVectors(e,t).normalize();const i=t.dot(n.direction);return n.origin.copy(t).addScaledVector(n.direction,-i),n}function Ks(){return"undefined"!=typeof SharedArrayBuffer}function to(t){if(t.buffer instanceof SharedArrayBuffer)return t;const e=t.constructor,n=t.buffer,i=new SharedArrayBuffer(n.byteLength),r=new Uint8Array(n);return new Uint8Array(i).set(r,0),new e(i)}function eo(t,e){if(!t.index){const n=t.attributes.position.count,i=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(n,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new _e(i,1));for(let t=0;t<n;t++)i[t]=t}}function no(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}const io=new N;function ro(t){return~~(t/3)}function so(t){return t%3}function oo(t,e){return t.start-e.start}function ao(t,e){return io.subVectors(e,t.origin).dot(t.direction)}const ho=1e-5,lo=1e-4;class uo{constructor(){this._rays=[]}addRay(t){this._rays.push(t)}findClosestRay(t){const e=this._rays,n=t.clone();n.direction.multiplyScalar(-1);let i=1/0,r=null;for(let a=0,h=e.length;a<h;a++){const h=e[a];if(s(h,t)&&s(h,n))continue;const l=o(h,t),u=o(h,n),c=Math.min(l,u);c<i&&(i=c,r=h)}return r;function s(t,e){const n=t.origin.distanceTo(e.origin)>ho;return t.direction.angleTo(e.direction)>lo||n}function o(t,e){const n=t.origin.distanceTo(e.origin),i=t.direction.angleTo(e.direction);return n/ho+i/lo}}}const co=new N,po=new N,fo=new zt;function yo(t,e,n){const i=t.attributes,r=t.index,s=i.position,o=new Map,a=new Map,h=Array.from(e),l=new uo;for(let u=0,c=h.length;u<c;u++){const t=h[u],e=ro(t),n=so(t);let i,o=3*e+n,c=3*e+(n+1)%3;r&&(o=r.getX(o),c=r.getX(c)),co.fromBufferAttribute(s,o),po.fromBufferAttribute(s,c),Qs(co,po,fo);let d=l.findClosestRay(fo);null===d&&(d=fo.clone(),l.addRay(d)),a.has(d)||a.set(d,{forward:[],reverse:[],ray:d}),i=a.get(d);let p=ao(d,co),f=ao(d,po);p>f&&([p,f]=[f,p]),fo.direction.dot(d.direction)<0?i.reverse.push({start:p,end:f,index:t}):i.forward.push({start:p,end:f,index:t})}return a.forEach(({forward:t,reverse:e},i)=>{!function(t,e,n,i=1e-8){t.sort(oo),e.sort(oo);for(let a=0;a<t.length;a++){const i=t[a];for(let r=0;r<e.length;r++){const h=e[r];if(h.start>i.end);else{if(i.end<h.start||h.end<i.start)continue;if(i.start<=h.start&&i.end>=h.end)s(h.end,i.end)||t.splice(a+1,0,{start:h.end,end:i.end,index:i.index}),i.end=h.start,h.start=0,h.end=0;else if(i.start>=h.start&&i.end<=h.end)s(i.end,h.end)||e.splice(r+1,0,{start:i.end,end:h.end,index:h.index}),h.end=i.start,i.start=0,i.end=0;else if(i.start<=h.start&&i.end<=h.end){const t=i.end;i.end=h.start,h.start=t}else{if(!(i.start>=h.start&&i.end>=h.end))throw new Error;{const t=h.end;h.end=i.start,i.start=t}}}if(n.has(i.index)||n.set(i.index,[]),n.has(h.index)||n.set(h.index,[]),n.get(i.index).push(h.index),n.get(h.index).push(i.index),o(h)&&(e.splice(r,1),r--),o(i)){t.splice(a,1),a--;break}}}function r(t){for(let e=0;e<t.length;e++)o(t[e])&&(t.splice(e,1),e--)}function s(t,e){return Math.abs(e-t)<i}function o(t){return Math.abs(t.end-t.start)<i}r(t),r(e)}(t,e,o,n),0===t.length&&0===e.length&&a.delete(i)}),{disjointConnectivityMap:o,fragmentMap:a}}const mo=new E,go=new N,xo=new Q,bo=["","",""];class wo{constructor(t=null){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,t&&this.updateFrom(t)}getSiblingTriangleIndex(t,e){const n=this.data[3*t+e];return-1===n?-1:~~(n/3)}getSiblingEdgeIndex(t,e){const n=this.data[3*t+e];return-1===n?-1:n%3}getDisjointSiblingTriangleIndices(t,e){const n=3*t+e,i=this.disjointConnections.get(n);return i?i.map(t=>~~(t/3)):[]}getDisjointSiblingEdgeIndices(t,e){const n=3*t+e,i=this.disjointConnections.get(n);return i?i.map(t=>t%3):[]}isFullyConnected(){return 0===this.unmatchedEdges}updateFrom(t){const{useAllAttributes:e,useDrawRange:n,matchDisjointEdges:i,degenerateEpsilon:r}=this,s=e?function(t){let e="";for(let n=0,i=h.length;n<i;n++){const i=a[h[n]];let r;switch(i.itemSize){case 1:r=Ws(i.getX(t));break;case 2:r=Ys(mo.fromBufferAttribute(i,t));break;case 3:r=$s(go.fromBufferAttribute(i,t));break;case 4:r=Hs(xo.fromBufferAttribute(i,t))}""!==e&&(e+="|"),e+=r}return e}:function(t){return go.fromBufferAttribute(u,t),$s(go)},o=new Map,{attributes:a}=t,h=e?Object.keys(a):null,l=t.index,u=a.position;let c=no(t);const d=c;let p=0;n&&(p=t.drawRange.start,t.drawRange.count!==1/0&&(c=~~(t.drawRange.count/3)));let f=this.data;(!f||f.length<3*d)&&(f=new Int32Array(3*d)),f.fill(-1);let y=0,m=new Set;for(let g=p,x=3*c+p;g<x;g+=3){const t=g;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),bo[e]=s(n)}for(let e=0;e<3;e++){const n=(e+1)%3,i=bo[e],r=bo[n],s=`${r}_${i}`;if(o.has(s)){const n=t+e,i=o.get(s);f[n]=i,f[i]=n,o.delete(s),y+=2,m.delete(i)}else{const n=`${i}_${r}`,s=t+e;o.set(n,s),m.add(s)}}}if(i){const{fragmentMap:e,disjointConnectivityMap:n}=yo(t,m,r);m.clear(),e.forEach(({forward:t,reverse:e})=>{t.forEach(({index:t})=>m.add(t)),e.forEach(({index:t})=>m.add(t))}),this.unmatchedDisjointEdges=e,this.disjointConnections=n,y=3*c-m.size}this.matchedEdges=y,this.unmatchedEdges=m.size,this.data=f}}class vo extends Ye{constructor(...t){super(...t),this.isBrush=!0,this._previousMatrix=new _t,this._previousMatrix.elements.fill(0)}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){const{matrix:t,_previousMatrix:e}=this,n=t.elements,i=e.elements;for(let r=0;r<16;r++)if(n[r]!==i[r])return!0;return!1}prepareGeometry(){const t=this.geometry,e=t.attributes,n=Ks();if(n)for(const i in e){const t=e[i];if(t.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");t.array=to(t.array)}if(t.boundsTree||(eo(t,{useSharedArrayBuffer:n}),t.boundsTree=new Zs(t,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),t.halfEdges||(t.halfEdges=new wo(t)),!t.groupIndices){const e=no(t),n=new Uint16Array(e),i=t.groups;for(let t=0,r=i.length;t<r;t++){const{start:e,count:r}=i[t];for(let i=e/3,s=(e+r)/3;i<s;i++)n[i]=t}t.groupIndices=n}}disposeCacheData(){const{geometry:t}=this;t.halfEdges=null,t.boundsTree=null,t.groupIndices=null}}const Mo=new N,So=new N,Ao=new N;function zo(t,e=1e-14){Mo.subVectors(t.b,t.a),So.subVectors(t.c,t.a),Ao.subVectors(t.b,t.c);const n=Mo.angleTo(So),i=Mo.angleTo(Ao),r=Math.PI-n-i;return Math.abs(n)<e||Math.abs(i)<e||Math.abs(r)<e||t.a.distanceToSquared(t.b)<e||t.a.distanceToSquared(t.c)<e||t.b.distanceToSquared(t.c)<e}const _o=1e-10,To=1e-10,Bo=new li,Po=new li,Co=new N,Eo=new N,ko=new N,No=new tn,Io=new er;class Oo{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new pe),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class Fo{constructor(){this.trianglePool=new Oo,this.triangles=[],this.normal=new N,this.coplanarTriangleUsed=!1}initialize(t){this.reset();const{triangles:e,trianglePool:n,normal:i}=this;if(Array.isArray(t))for(let r=0,s=t.length;r<s;r++){const s=t[r];if(0===r)s.getNormal(i);else if(Math.abs(1-s.getNormal(Co).dot(i))>_o)throw new Error("Triangle Splitter: Cannot initialize with triangles that have different normals.");const o=n.getTriangle();o.copy(s),e.push(o)}else{t.getNormal(i);const r=n.getTriangle();r.copy(t),e.push(r)}}splitByTriangle(t){const{normal:e,triangles:n}=this;if(t.getNormal(Eo).normalize(),Math.abs(1-Math.abs(Eo.dot(e)))<1e-10){this.coplanarTriangleUsed=!0;for(let t=0,i=n.length;t<i;t++){n[t].coplanarCount=0}const e=[t.a,t.b,t.c];for(let n=0;n<3;n++){const i=(n+1)%3,r=e[n],s=e[i];Co.subVectors(s,r).normalize(),ko.crossVectors(Eo,Co),No.setFromNormalAndCoplanarPoint(ko,r),this.splitByPlane(No,t)}}else t.getPlane(No),this.splitByPlane(No,t)}splitByPlane(t,e){const{triangles:n,trianglePool:i}=this;Io.copy(e),Io.needsUpdate=!0;for(let r=0,s=n.length;r<s;r++){const e=n[r];if(!Io.intersectsTriangle(e,Bo,!0))continue;const{a:o,b:a,c:h}=e;let l=0,u=-1,c=!1,d=[],p=[];const f=[o,a,h];for(let n=0;n<3;n++){const e=(n+1)%3;Bo.start.copy(f[n]),Bo.end.copy(f[e]);const i=t.distanceToPoint(Bo.start),r=t.distanceToPoint(Bo.end);if(Math.abs(i)<To&&Math.abs(r)<To){c=!0;break}if(i>0?d.push(n):p.push(n),Math.abs(i)<To)continue;let s=!!t.intersectLine(Bo,Co);!s&&Math.abs(r)<To&&(Co.copy(Bo.end),s=!0),!s||Co.distanceTo(Bo.start)<_o||(Co.distanceTo(Bo.end)<_o&&(u=n),0===l?Po.start.copy(Co):Po.end.copy(Co),l++)}if(!c&&2===l&&Po.distance()>To)if(-1!==u){u=(u+1)%3;let t=0;t===u&&(t=(t+1)%3);let o=t+1;o===u&&(o=(o+1)%3);const a=i.getTriangle();a.a.copy(f[o]),a.b.copy(Po.end),a.c.copy(Po.start),zo(a)||n.push(a),e.a.copy(f[t]),e.b.copy(Po.start),e.c.copy(Po.end),zo(e)&&(n.splice(r,1),r--,s--)}else{const t=d.length>=2?p[0]:d[0];if(0===t){let t=Po.start;Po.start=Po.end,Po.end=t}const o=(t+1)%3,a=(t+2)%3,h=i.getTriangle(),l=i.getTriangle();f[o].distanceToSquared(Po.start)<f[a].distanceToSquared(Po.end)?(h.a.copy(f[o]),h.b.copy(Po.start),h.c.copy(Po.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Po.start)):(h.a.copy(f[a]),h.b.copy(Po.start),h.c.copy(Po.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Po.end)),e.a.copy(f[t]),e.b.copy(Po.end),e.c.copy(Po.start),zo(h)||n.push(h),zo(l)||n.push(l),zo(e)&&(n.splice(r,1),r--,s--)}else 3===l&&console.warn("TriangleClipper: Coplanar clip not handled")}}reset(){this.triangles.length=0,this.trianglePool.clear(),this.coplanarTriangleUsed=!1}}class Ro{constructor(t,e=500){this.expansionFactor=1.5,this.type=t,this.length=0,this.array=null,this.setSize(e)}setType(t){if(0!==this.length)throw new Error("TypeBackedArray: Cannot change the type while there is used data in the buffer.");const e=this.array.buffer;this.array=new t(e),this.type=t}setSize(t){if(this.array&&t===this.array.length)return;const e=this.type,n=new e(new(Ks()?SharedArrayBuffer:ArrayBuffer)(4+(i=~~(i=t*e.BYTES_PER_ELEMENT))-i%4));var i;this.array&&n.set(this.array,0),this.array=n}expand(){const{array:t,expansionFactor:e}=this;this.setSize(t.length*e)}push(...t){let{array:e,length:n}=this;n+t.length>e.length&&(this.expand(),e=this.array);for(let i=0,r=t.length;i<r;i++)e[n+i]=t[i];this.length+=t.length}clear(){this.length=0}}class Vo{constructor(){this.groupAttributes=[{}],this.groupCount=0}getType(t){return this.groupAttributes[0][t].type}getItemSize(t){return this.groupAttributes[0][t].itemSize}getNormalized(t){return this.groupAttributes[0][t].normalized}getCount(t){if(this.groupCount<=t)return 0;const e=this.getGroupAttrArray("position",t);return e.length/e.itemSize}getTotalLength(t){const{groupCount:e,groupAttributes:n}=this;let i=0;for(let r=0;r<e;r++){i+=n[r][t].length}return i}getGroupAttrSet(t=0){const{groupAttributes:e}=this;if(e[t])return this.groupCount=Math.max(this.groupCount,t+1),e[t];const n=e[0];for(this.groupCount=Math.max(this.groupCount,t+1);t>=e.length;){const t={};e.push(t);for(const e in n){const i=n[e],r=new Ro(i.type);r.itemSize=i.itemSize,r.normalized=i.normalized,t[e]=r}}return e[t]}getGroupAttrArray(t,e=0){const{groupAttributes:n}=this;if(!n[0][t])throw new Error(`TypedAttributeData: Attribute with "${t}" has not been initialized`);return this.getGroupAttrSet(e)[t]}initializeArray(t,e,n,i){const{groupAttributes:r}=this,s=r[0][t];if(s){if(s.type!==e)for(let o=0,a=r.length;o<a;o++){const s=r[o][t];s.setType(e),s.itemSize=n,s.normalized=i}}else for(let o=0,a=r.length;o<a;o++){const s=new Ro(e);s.itemSize=n,s.normalized=i,r[o][t]=s}}clear(){this.groupCount=0;const{groupAttributes:t}=this;t.forEach(t=>{for(const e in t)t[e].clear()})}delete(t){this.groupAttributes.forEach(e=>{delete e[t]})}reset(){this.groupAttributes=[],this.groupCount=0}}class Uo{constructor(){this.intersectionSet={},this.ids=[]}add(t,e){const{intersectionSet:n,ids:i}=this;n[t]||(n[t]=[],i.push(t)),n[t].push(e)}}const Lo=new zt,qo=new _t,Do=new pe,Xo=new N,Zo=new Q,jo=new Q,Go=new Q,Jo=new Q,Wo=new Q,Yo=new Q,$o=new li,Ho=new N,Qo=1e-8,Ko=-1;let ta=null;function ea(t){ta=t}function na(t,e){t.getMidpoint(Lo.origin),t.getNormal(Lo.direction);const n=e.raycastFirst(Lo,2);return Boolean(n&&Lo.direction.dot(n.face.normal)>0)?Ko:1}function ia(t,e){function n(){return Math.random()-.5}t.getNormal(Ho),Lo.direction.copy(Ho),t.getMidpoint(Lo.origin);let i=0,r=1/0;for(let s=0;s<3;s++){Lo.direction.x+=n()*Qo,Lo.direction.y+=n()*Qo,Lo.direction.z+=n()*Qo,Lo.direction.multiplyScalar(-1);const t=e.raycastFirst(Lo,2);if(Boolean(t&&Lo.direction.dot(t.face.normal)>0)&&i++,null!==t&&(r=Math.min(r,t.distance)),r<=1e-15)return t.face.normal.dot(Ho)>0?2:-2;if(i/3>.5||(s-i+1)/3>.5)break}return i/3>.5?Ko:1}function ra(t,e,n,i,r,s,o=!1){const a=n.attributes,h=n.index,l=3*t,u=h.getX(l+0),c=h.getX(l+1),d=h.getX(l+2);for(const p in s){const t=a[p],n=s[p];if(!(p in a))throw new Error(`CSG Operations: Attribute ${p} not available on geometry.`);const h=t.itemSize;"position"===p?(Do.a.fromBufferAttribute(t,u).applyMatrix4(i),Do.b.fromBufferAttribute(t,c).applyMatrix4(i),Do.c.fromBufferAttribute(t,d).applyMatrix4(i),aa(Do.a,Do.b,Do.c,e,3,n,o)):"normal"===p?(Do.a.fromBufferAttribute(t,u).applyNormalMatrix(r),Do.b.fromBufferAttribute(t,c).applyNormalMatrix(r),Do.c.fromBufferAttribute(t,d).applyNormalMatrix(r),o&&(Do.a.multiplyScalar(-1),Do.b.multiplyScalar(-1),Do.c.multiplyScalar(-1)),aa(Do.a,Do.b,Do.c,e,3,n,o,!0)):(Zo.fromBufferAttribute(t,u),jo.fromBufferAttribute(t,c),Go.fromBufferAttribute(t,d),aa(Zo,jo,Go,e,h,n,o))}}function sa(t,e,n,i,r,s,o,a=!1){ha(t,i,r,s,o,a),ha(a?n:e,i,r,s,o,a),ha(a?e:n,i,r,s,o,a)}function oa(t,e,n=!1){switch(t){case 0:if(1===e||2===e&&!n)return 1;break;case 1:if(n){if(e===Ko)return 0}else if(1===e||-2===e)return 1;break;case 2:if(n){if(1===e||-2===e)return 1}else if(e===Ko)return 0;break;case 4:if(e===Ko)return 0;if(1===e)return 1;break;case 3:if(e===Ko||2===e&&!n)return 1;break;case 5:if(!n&&(1===e||-2===e))return 1;break;case 6:if(!n&&(e===Ko||2===e))return 1;break;default:throw new Error(`Unrecognized CSG operation enum "${t}".`)}return 2}function aa(t,e,n,i,r,s,o=!1,a=!1){const h=t=>{s.push(t.x),r>1&&s.push(t.y),r>2&&s.push(t.z),r>3&&s.push(t.w)};Jo.set(0,0,0,0).addScaledVector(t,i.a.x).addScaledVector(e,i.a.y).addScaledVector(n,i.a.z),Wo.set(0,0,0,0).addScaledVector(t,i.b.x).addScaledVector(e,i.b.y).addScaledVector(n,i.b.z),Yo.set(0,0,0,0).addScaledVector(t,i.c.x).addScaledVector(e,i.c.y).addScaledVector(n,i.c.z),a&&(Jo.normalize(),Wo.normalize(),Yo.normalize()),h(Jo),o?(h(Yo),h(Wo)):(h(Wo),h(Yo))}function ha(t,e,n,i,r,s=!1){for(const o in r){const a=e[o],h=r[o];if(!(o in e))throw new Error(`CSG Operations: Attribute ${o} no available on geometry.`);const l=a.itemSize;"position"===o?(Xo.fromBufferAttribute(a,t).applyMatrix4(n),h.push(Xo.x,Xo.y,Xo.z)):"normal"===o?(Xo.fromBufferAttribute(a,t).applyNormalMatrix(i),s&&Xo.multiplyScalar(-1),h.push(Xo.x,Xo.y,Xo.z)):(h.push(a.getX(t)),l>1&&h.push(a.getY(t)),l>2&&h.push(a.getZ(t)),l>3&&h.push(a.getW(t)))}}class la{constructor(t){this.triangle=(new pe).copy(t),this.intersects={}}addTriangle(t,e){this.intersects[t]=(new pe).copy(e)}getIntersectArray(){const t=[],{intersects:e}=this;for(const n in e)t.push(e[n]);return t}}class ua{constructor(){this.data={}}addTriangleIntersection(t,e,n,i){const{data:r}=this;r[t]||(r[t]=new la(e)),r[t].addTriangle(n,i)}getTrianglesAsArray(t=null){const{data:e}=this,n=[];if(null!==t)t in e&&n.push(e[t].triangle);else for(const i in e)n.push(e[i].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(t=>parseInt(t))}getIntersectionIndices(t){const{data:e}=this;return e[t]?Object.keys(e[t].intersects).map(t=>parseInt(t)):[]}getIntersectionsAsArray(t=null,e=null){const{data:n}=this,i=new Set,r=[],s=t=>{if(n[t])if(null!==e)n[t].intersects[e]&&r.push(n[t].intersects[e]);else{const e=n[t].intersects;for(const t in e)i.has(t)||(i.add(t),r.push(e[t]))}};if(null!==t)s(t);else for(const o in n)s(o);return r}reset(){this.data={}}}class ca{constructor(){this.enabled=!1,this.triangleIntersectsA=new ua,this.triangleIntersectsB=new ua,this.intersectionEdges=[]}addIntersectingTriangles(t,e,n,i){const{triangleIntersectsA:r,triangleIntersectsB:s}=this;r.addTriangleIntersection(t,e,n,i),s.addTriangleIntersection(n,i,t,e)}addEdge(t){this.intersectionEdges.push(t.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),ea(this))}complete(){this.enabled&&ea(null)}}const da=new _t,pa=new F,fa=new pe,ya=new pe,ma=new pe,ga=new pe,xa=[],ba=[];function wa(t){for(const e of t)return e}function va(t,e,n,i,r,s={}){const{useGroups:o=!0}=s,{aIntersections:a,bIntersections:h}=function(t,e){const n=new Uo,i=new Uo;return qo.copy(t.matrixWorld).invert().multiply(e.matrixWorld),t.geometry.boundsTree.bvhcast(e.geometry.boundsTree,qo,{intersectsTriangles(r,s,o,a){if(!zo(r)&&!zo(s)){let h=r.intersectsTriangle(s,$o,!0);if(!h){const t=r.plane,e=s.plane,n=t.normal,i=e.normal;1===n.dot(i)&&Math.abs(t.constant-e.constant)<1e-14&&(h=!0)}if(h){let h=t.geometry.boundsTree.resolveTriangleIndex(o),l=e.geometry.boundsTree.resolveTriangleIndex(a);n.add(h,l),i.add(l,h),ta&&(ta.addEdge($o),ta.addIntersectingTriangles(o,r,a,s))}}return!1}}),{aIntersections:n,bIntersections:i}}(t,e);let l;l=o?0:-1,Ma(t,e,a,n,!1,i,r,l),Sa(t,e,a,n,!1,r,l);return-1!==n.findIndex(t=>6!==t&&5!==t)&&(l=o?t.geometry.groups.length||1:-1,Ma(e,t,h,n,!0,i,r,l),Sa(e,t,h,n,!0,r,l)),xa.length=0,ba.length=0,{groups:[],materials:null}}function Ma(t,e,n,i,r,s,o,a=0){const h=t.matrixWorld.determinant()<0;da.copy(e.matrixWorld).invert().multiply(t.matrixWorld),pa.getNormalMatrix(t.matrixWorld).multiplyScalar(h?-1:1);const l=t.geometry.groupIndices,u=t.geometry.index,c=t.geometry.attributes.position,d=e.geometry.boundsTree,p=e.geometry.index,f=e.geometry.attributes.position,y=n.ids,m=n.intersectionSet;for(let g=0,x=y.length;g<x;g++){const e=y[g],n=-1===a?0:l[e]+a,x=3*e,b=u.getX(x+0),w=u.getX(x+1),v=u.getX(x+2);fa.a.fromBufferAttribute(c,b).applyMatrix4(da),fa.b.fromBufferAttribute(c,w).applyMatrix4(da),fa.c.fromBufferAttribute(c,v).applyMatrix4(da),s.reset(),s.initialize(fa);const M=m[e];for(let t=0,i=M.length;t<i;t++){const e=3*M[t],n=p.getX(e+0),i=p.getX(e+1),r=p.getX(e+2);ya.a.fromBufferAttribute(f,n),ya.b.fromBufferAttribute(f,i),ya.c.fromBufferAttribute(f,r),s.splitByTriangle(ya)}const S=s.triangles;for(let a=0,l=S.length;a<l;a++){const l=S[a],u=s.coplanarTriangleUsed?ia(l,d):na(l,d);xa.length=0,ba.length=0;for(let t=0,e=i.length;t<e;t++){const e=oa(i[t],u,r);2!==e&&(ba.push(e),xa.push(o[t].getGroupAttrSet(n)))}if(0!==xa.length){fa.getBarycoord(l.a,ga.a),fa.getBarycoord(l.b,ga.b),fa.getBarycoord(l.c,ga.c);for(let n=0,i=xa.length;n<i;n++){const i=xa[n],r=0===ba[n];ra(e,ga,t.geometry,t.matrixWorld,pa,i,h!==r)}}}}return y.length}function Sa(t,e,n,i,r,s,o=0){const a=t.matrixWorld.determinant()<0;da.copy(e.matrixWorld).invert().multiply(t.matrixWorld),pa.getNormalMatrix(t.matrixWorld).multiplyScalar(a?-1:1);const h=e.geometry.boundsTree,l=t.geometry.groupIndices,u=t.geometry.index,c=t.geometry.attributes,d=c.position,p=[],f=t.geometry.halfEdges,y=new Set;for(let m=0,g=no(t.geometry);m<g;m++)m in n.intersectionSet||y.add(m);for(;y.size>0;){const e=wa(y);y.delete(e),p.push(e);const n=3*e,m=u.getX(n+0),g=u.getX(n+1),x=u.getX(n+2);ma.a.fromBufferAttribute(d,m).applyMatrix4(da),ma.b.fromBufferAttribute(d,g).applyMatrix4(da),ma.c.fromBufferAttribute(d,x).applyMatrix4(da);const b=na(ma,h);ba.length=0,xa.length=0;for(let t=0,o=i.length;t<o;t++){const e=oa(i[t],b,r);2!==e&&(ba.push(e),xa.push(s[t]))}for(;p.length>0;){const e=p.pop();for(let t=0;t<3;t++){const n=f.getSiblingTriangleIndex(e,t);-1!==n&&y.has(n)&&(p.push(n),y.delete(n))}if(0!==xa.length){const n=3*e,i=u.getX(n+0),r=u.getX(n+1),s=u.getX(n+2),h=-1===o?0:l[e]+o;if(ma.a.fromBufferAttribute(d,i),ma.b.fromBufferAttribute(d,r),ma.c.fromBufferAttribute(d,s),!zo(ma))for(let e=0,o=xa.length;e<o;e++){const n=ba[e],o=xa[e].getGroupAttrSet(h),l=0===n;sa(i,r,s,c,t.matrixWorld,pa,o,l!==a)}}}}}function Aa(t,e){let n=e;return Array.isArray(e)||(n=[],t.forEach(t=>{n[t.materialIndex]=e})),n}class za{constructor(){this.triangleSplitter=new Fo,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new ca}getGroupRanges(t){return this.useGroups&&0!==t.groups.length?t.groups.map(t=>u({},t)):[{start:0,count:1/0,materialIndex:0}]}evaluate(t,e,n,i=new vo){let r=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(i)||(i=[i],r=!1),i.length!==n.length)throw new Error("Evaluator: operations and target array passed as different sizes.");t.prepareGeometry(),e.prepareGeometry();const{triangleSplitter:s,attributeData:o,attributes:a,useGroups:h,consolidateGroups:l,debug:d}=this;for(;o.length<i.length;)o.push(new Vo);i.forEach((e,n)=>{!function(t,e,n,i){n.clear();const r=t.attributes;for(let s=0,o=i.length;s<o;s++){const t=i[s],e=r[t];n.initializeArray(t,e.array.constructor,e.itemSize,e.normalized)}for(const s in n.attributes)i.includes(s)||n.delete(s);for(const s in e.attributes)i.includes(s)||(e.deleteAttribute(s),e.dispose())}(t.geometry,e.geometry,o[n],a)}),d.init(),va(t,e,n,s,o,{useGroups:h}),d.complete();const p=this.getGroupRanges(t.geometry),f=Aa(p,t.material),y=this.getGroupRanges(e.geometry),m=Aa(y,e.material);y.forEach(t=>t.materialIndex+=f.length);let g=[...p,...y].map((t,e)=>c(u({},t),{index:e}));if(h){const t=[...f,...m];l&&(g=g.map(e=>{const n=t[e.materialIndex];return e.materialIndex=t.indexOf(n),e}).sort((t,e)=>t.materialIndex-e.materialIndex));const e=[];for(let n=0,i=t.length;n<i;n++){let i=!1;for(let t=0,r=g.length;t<r;t++){const r=g[t];r.materialIndex===n&&(i=!0,r.materialIndex=e.length)}i&&e.push(t[n])}i.forEach(t=>{t.material=e})}else g=[{start:0,count:1/0,index:0,materialIndex:0}],i.forEach(t=>{t.material=f[0]});return i.forEach((t,e)=>{const n=t.geometry;!function(t,e,n){let i=!1,r=-1;const s=t.attributes,o=e.groupAttributes[0];for(const h in o){const o=e.getTotalLength(h),a=e.getType(h),l=e.getItemSize(h),u=e.getNormalized(h);let c=s[h];(!c||c.array.length<o)&&(c=new _e(new a(o),l,u),t.setAttribute(h,c),i=!0);let d=0;for(let t=0,i=Math.min(n.length,e.groupCount);t<i;t++){const i=n[t].index,{array:r,type:s,length:o}=e.groupAttributes[i][h],a=new s(r.buffer,0,o);c.array.set(a,d),d+=a.length}c.needsUpdate=!0,r=o/c.itemSize}if(t.index){const e=t.index.array;if(e.length<r)t.index=null,i=!0;else for(let t=0,n=e.length;t<n;t++)e[t]=t}let a=0;t.clearGroups();for(let h=0,l=Math.min(n.length,e.groupCount);h<l;h++){const{index:i,materialIndex:r}=n[h],s=e.getCount(i);0!==s&&(t.addGroup(a,s,r),a+=s)}t.setDrawRange(0,r),t.boundsTree=null,i&&t.dispose()}(n,o[e],g),l&&function(t){for(let e=0;e<t.length-1;e++){const n=t[e],i=t[e+1];if(n.materialIndex===i.materialIndex){const r=n.start,s=i.start+i.count;i.start=r,i.count=s-r,t.splice(e,1),e--}}}(n.groups)}),r?i:i[0]}evaluateHierarchy(t,e=new vo){t.updateMatrixWorld(!0);const n=(t,e)=>{const i=t.children;for(let r=0,s=i.length;r<s;r++){const t=i[r];t.isOperationGroup?n(t,e):e(t)}},i=t=>{const e=t.children;let r=!1;for(let n=0,o=e.length;n<o;n++){const t=e[n];r=i(t)||r}const s=t.isDirty();if(s&&t.markUpdated(),r&&!t.isOperationGroup){let e;return n(t,n=>{e=e?this.evaluate(e,n,n.operation):this.evaluate(t,n,n.operation)}),t._cachedGeometry=e.geometry,t._cachedMaterials=e.material,!0}return r||s};return i(t),e.geometry=t._cachedGeometry,e.material=t._cachedMaterials,e}reset(){this.triangleSplitter.reset()}}function _a(t){let e,n,i,r=-1,s=0;for(let l=0;l<t.length;++l){const o=t[l];if(void 0===e&&(e=o.array.constructor),e!==o.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(void 0===n&&(n=o.itemSize),n!==o.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(void 0===i&&(i=o.normalized),i!==o.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(-1===r&&(r=o.gpuType),r!==o.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;s+=o.count*n}const o=new e(s),a=new _e(o,n,i);let h=0;for(let l=0;l<t.length;++l){const e=t[l];if(e.isInterleavedBufferAttribute){const t=h/n;for(let i=0,r=e.count;i<r;i++)for(let s=0;s<n;s++){const n=e.getComponent(i,s);a.setComponent(i+t,s,n)}}else o.set(e.array,h);h+=e.count*n}return void 0!==r&&(a.gpuType=r),a}function Ta(t,e=0){const n=null!==t[0].index,i=new Set(Object.keys(t[0].attributes)),r=new Set(Object.keys(t[0].morphAttributes)),s={},o={},a=t[0].morphTargetsRelative,h=new Re;let l=0;for(let u=0;u<t.length;++u){const c=t[u];let d=0;if(n!==(null!==c.index))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(const t in c.attributes){if(!i.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+\'. All geometries must have compatible attributes; make sure "\'+t+\'" attribute exists among all geometries, or in none of them.\'),null;void 0===s[t]&&(s[t]=[]),s[t].push(c.attributes[t]),d++}if(d!==i.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(a!==c.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const t in c.morphAttributes){if(!r.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;void 0===o[t]&&(o[t]=[]),o[t].push(c.morphAttributes[t])}if(e){let t;if(n)t=c.index.count;else{if(void 0===c.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;t=c.attributes.position.count}if(1===e)h.addGroup(l,t,u);else if(2===e&&c.groups.length>0)for(let e of c.groups){let n=e.materialIndex;h.addGroup(l+e.start,Math.min(e.count,t),n)}l+=t}}if(n){let e=0;const n=[];for(let i=0;i<t.length;++i){const r=t[i].index;for(let t=0;t<r.count;++t)n.push(r.getX(t)+e);e+=t[i].attributes.position.count}h.setIndex(n)}for(const u in s){const t=_a(s[u]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" attribute."),null;h.setAttribute(u,t)}for(const u in o){const t=o[u][0].length;if(0===t)break;h.morphAttributes=h.morphAttributes||{},h.morphAttributes[u]=[];for(let e=0;e<t;++e){const t=[];for(let i=0;i<o[u].length;++i)t.push(o[u][i][e]);const n=_a(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;h.morphAttributes[u].push(n)}}return 2===e?function(t){if(0===t.groups.length)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),t;let e=t.groups;if(e=e.sort((t,e)=>t.materialIndex!==e.materialIndex?t.materialIndex-e.materialIndex:t.start-e.start),null===t.getIndex()){const e=t.getAttribute("position"),n=[];for(let t=0;t<e.count;t+=3)n.push(t,t+1,t+2);t.setIndex(n)}const n=t.getIndex(),i=[];for(let o=0;o<e.length;o++){const t=e[o],r=t.start,s=r+t.count;for(let e=r;e<s;e++)i.push(n.getX(e))}t.dispose(),t.setIndex(i);let r=0;for(let o=0;o<e.length;o++){const t=e[o];t.start=r,r+=t.count}let s=e[0];t.groups=[s];for(let o=1;o<e.length;o++){const n=e[o];s.materialIndex===n.materialIndex?s.count+=n.count:(s=n,t.groups.push(s))}return t}(h):h}class Ba extends pi{constructor(t,e){super(t,e);const n=new vo(new pi(t,c(u({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new K).setFromObject(n),r=new N;i.getSize(r);const s=new N(i.min.x+r.x/2,i.min.y+r.y/2,0);let o=e.topSegments,a=e.box3;if(a){a=a.union(i);const t=new N;a.getSize(t);const n=Math.max(r.x/t.x,r.y/t.y);o=Math.ceil(e.topSegments*n)}if(o<4)return this;const h=new ei(r.x,r.y,o,o),l=new vo(h);l.position.set(s.x,s.y,s.z),l.updateMatrixWorld();const d=(new za).evaluate(l,n,3),p=d.geometry.getAttribute("position"),f=new Pe(2*p.count,2);for(let u=0;u<p.count;u++){const t=p.getZ(u);p.setZ(u,e.depth+t)}if(a){const t=a.min,e=a.max,n=(new N).subVectors(e,t);for(let i=0;i<p.count;i++){const e=p.getX(i),r=p.getY(i),s=(e-t.x)/n.x,o=(r-t.y)/n.y;f.setXY(i,s,o)}d.geometry.setAttribute("uv",f)}p.needsUpdate=!0;const y=new pi(t,c(u({},e),{hasTop:!1})),m=Ta([d.geometry,y],2);this.copy(m.toNonIndexed())}}var Pa=t=>{const{split:e,depth:n,points:i,box3:r,hasTop:s,hasBottom:o,hasSide:a,sideRepeat:h,topSegments:l}=t,u=new(l?Ba:pi)(new An(i),{depth:n,bevelEnabled:!1,box3:r,UVGenerator:ci({split:e,box3:r,sideRepeat:h}),hasTop:s,hasBottom:o,hasSide:a,topSegments:l});return ui.clear(),u};const Ca=6378137,Ea=6356752.314245179;function ka(t,e,n=0,i=1/Ca,r=!1){const s=C.degToRad(t),o=C.degToRad(e),a=Math.cos(o),h=Math.sin(o),l=Math.cos(s),u=Math.sin(s);let c,d,p;if(r){const t=(Ca+n)*i;c=t*a*u,d=t*h,p=t*a*l}else{const t=Ca*Ca,e=(t-Ea*Ea)/t,r=Ca/Math.sqrt(1-e*h*h);c=(r+n)*a*u*i,d=(r*(1-e)+n)*h*i,p=(r+n)*a*l*i}return new N(c,d,p)}function Na(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Ia(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Oa(t){let e,n,i;function r(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<0?r=e+1:s=e}while(r<s)}return r}return 2!==t.length?(e=Na,n=(e,n)=>Na(t(e),n),i=(e,n)=>t(e)-n):(e=t===Na||t===Ia?t:Fa,n=t,i=t),{left:r,center:function(t,e,n=0,s=t.length){const o=r(t,e,n,s-1);return o>n&&i(t[o-1],e)>-i(t[o],e)?o-1:o},right:function(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<=0?r=e+1:s=e}while(r<s)}return r}}}function Fa(){return 0}const Ra=Oa(Na).right;function Va(t,e){let n,i;if(void 0===e)for(const r of t)null!=r&&(void 0===n?r>=r&&(n=i=r):(n>r&&(n=r),i<r&&(i=r)));else{let r=-1;for(let s of t)null!=(s=e(s,++r,t))&&(void 0===n?s>=s&&(n=i=s):(n>s&&(n=s),i<s&&(i=s)))}return[n,i]}Oa(function(t){return null===t?NaN:+t}).center;class Ua{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const e=this._partials;let n=0;for(let i=0;i<this._n&&i<32;i++){const r=e[i],s=t+r,o=Math.abs(t)<Math.abs(r)?t-(s-r):r-(s-t);o&&(e[n++]=o),t=s}return e[n]=t,this._n=n+1,this}valueOf(){const t=this._partials;let e,n,i,r=this._n,s=0;if(r>0){for(s=t[--r];r>0&&(e=s,n=t[--r],s=e+n,i=n-(s-e),!i););r>0&&(i<0&&t[r-1]<0||i>0&&t[r-1]>0)&&(n=2*i,e=s+n,n==e-s&&(s=e))}return s}}const La=Math.sqrt(50),qa=Math.sqrt(10),Da=Math.sqrt(2);function Xa(t,e,n){const i=(e-t)/Math.max(0,n),r=Math.floor(Math.log10(i)),s=i/Math.pow(10,r),o=s>=La?10:s>=qa?5:s>=Da?2:1;let a,h,l;return r<0?(l=Math.pow(10,-r)/o,a=Math.round(t*l),h=Math.round(e*l),a/l<t&&++a,h/l>e&&--h,l=-l):(l=Math.pow(10,r)*o,a=Math.round(t/l),h=Math.round(e/l),a*l<t&&++a,h*l>e&&--h),h<a&&.5<=n&&n<2?Xa(t,e,2*n):[a,h,l]}function Za(t,e,n){return Xa(t=+t,e=+e,n=+n)[2]}function ja(t,e){let n=0,i=0;if(void 0===e)for(let r of t)null!=r&&(r=+r)>=r&&(++n,i+=r);else{let r=-1;for(let s of t)null!=(s=e(s,++r,t))&&(s=+s)>=s&&(++n,i+=s)}if(n)return i/n}function Ga(t){return Array.from(function*(t){for(const e of t)yield*y(e)}(t))}var Ja=1e-6,Wa=1e-12,Ya=Math.PI,$a=Ya/2,Ha=Ya/4,Qa=2*Ya,Ka=180/Ya,th=Ya/180,eh=Math.abs,nh=Math.atan,ih=Math.atan2,rh=Math.cos,sh=Math.exp,oh=Math.hypot,ah=Math.log,hh=Math.sin,lh=Math.sign||function(t){return t>0?1:t<0?-1:0},uh=Math.sqrt,ch=Math.tan;function dh(t){return t>1?$a:t<-1?-$a:Math.asin(t)}function ph(t){return(t=hh(t/2))*t}function fh(){}function yh(t,e){t&&gh.hasOwnProperty(t.type)&&gh[t.type](t,e)}var mh={Feature:function(t,e){yh(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)yh(n[i].geometry,e)}},gh={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)t=n[i],e.point(t[0],t[1],t[2])},LineString:function(t,e){xh(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)xh(n[i],e,0)},Polygon:function(t,e){bh(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)bh(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)yh(n[i],e)}};function xh(t,e,n){var i,r=-1,s=t.length-n;for(e.lineStart();++r<s;)i=t[r],e.point(i[0],i[1],i[2]);e.lineEnd()}function bh(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)xh(t[n],e,1);e.polygonEnd()}function wh(t,e){t&&mh.hasOwnProperty(t.type)?mh[t.type](t,e):yh(t,e)}var vh,Mh,Sh,Ah,zh,_h,Th,Bh,Ph,Ch,Eh,kh,Nh,Ih,Oh,Fh,Rh=new Ua,Vh=new Ua,Uh={point:fh,lineStart:fh,lineEnd:fh,polygonStart:function(){Rh=new Ua,Uh.lineStart=Lh,Uh.lineEnd=qh},polygonEnd:function(){var t=+Rh;Vh.add(t<0?Qa+t:t),this.lineStart=this.lineEnd=this.point=fh},sphere:function(){Vh.add(Qa)}};function Lh(){Uh.point=Dh}function qh(){Xh(vh,Mh)}function Dh(t,e){Uh.point=Xh,vh=t,Mh=e,Sh=t*=th,Ah=rh(e=(e*=th)/2+Ha),zh=hh(e)}function Xh(t,e){var n=(t*=th)-Sh,i=n>=0?1:-1,r=i*n,s=rh(e=(e*=th)/2+Ha),o=hh(e),a=zh*o,h=Ah*s+a*rh(r),l=a*i*hh(r);Rh.add(ih(l,h)),Sh=t,Ah=s,zh=o}function Zh(t){return[ih(t[1],t[0]),dh(t[2])]}function jh(t){var e=t[0],n=t[1],i=rh(n);return[i*rh(e),i*hh(e),hh(n)]}function Gh(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Jh(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Wh(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Yh(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function $h(t){var e=uh(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var Hh,Qh,Kh,tl,el,nl,il,rl,sl,ol,al,hl,ll,ul,cl,dl,pl={point:fl,lineStart:ml,lineEnd:gl,polygonStart:function(){pl.point=xl,pl.lineStart=bl,pl.lineEnd=wl,Ih=new Ua,Uh.polygonStart()},polygonEnd:function(){Uh.polygonEnd(),pl.point=fl,pl.lineStart=ml,pl.lineEnd=gl,Rh<0?(_h=-(Bh=180),Th=-(Ph=90)):Ih>Ja?Ph=90:Ih<-1e-6&&(Th=-90),Fh[0]=_h,Fh[1]=Bh},sphere:function(){_h=-(Bh=180),Th=-(Ph=90)}};function fl(t,e){Oh.push(Fh=[_h=t,Bh=t]),e<Th&&(Th=e),e>Ph&&(Ph=e)}function yl(t,e){var n=jh([t*th,e*th]);if(Nh){var i=Jh(Nh,n),r=Jh([i[1],-i[0],0],i);$h(r),r=Zh(r);var s,o=t-Ch,a=o>0?1:-1,h=r[0]*Ka*a,l=eh(o)>180;l^(a*Ch<h&&h<a*t)?(s=r[1]*Ka)>Ph&&(Ph=s):l^(a*Ch<(h=(h+360)%360-180)&&h<a*t)?(s=-r[1]*Ka)<Th&&(Th=s):(e<Th&&(Th=e),e>Ph&&(Ph=e)),l?t<Ch?vl(_h,t)>vl(_h,Bh)&&(Bh=t):vl(t,Bh)>vl(_h,Bh)&&(_h=t):Bh>=_h?(t<_h&&(_h=t),t>Bh&&(Bh=t)):t>Ch?vl(_h,t)>vl(_h,Bh)&&(Bh=t):vl(t,Bh)>vl(_h,Bh)&&(_h=t)}else Oh.push(Fh=[_h=t,Bh=t]);e<Th&&(Th=e),e>Ph&&(Ph=e),Nh=n,Ch=t}function ml(){pl.point=yl}function gl(){Fh[0]=_h,Fh[1]=Bh,pl.point=fl,Nh=null}function xl(t,e){if(Nh){var n=t-Ch;Ih.add(eh(n)>180?n+(n>0?360:-360):n)}else Eh=t,kh=e;Uh.point(t,e),yl(t,e)}function bl(){Uh.lineStart()}function wl(){xl(Eh,kh),Uh.lineEnd(),eh(Ih)>Ja&&(_h=-(Bh=180)),Fh[0]=_h,Fh[1]=Bh,Nh=null}function vl(t,e){return(e-=t)<0?e+360:e}function Ml(t,e){return t[0]-e[0]}function Sl(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function Al(t){var e,n,i,r,s,o,a;if(Ph=Bh=-(_h=Th=1/0),Oh=[],wh(t,pl),n=Oh.length){for(Oh.sort(Ml),e=1,s=[i=Oh[0]];e<n;++e)Sl(i,(r=Oh[e])[0])||Sl(i,r[1])?(vl(i[0],r[1])>vl(i[0],i[1])&&(i[1]=r[1]),vl(r[0],i[1])>vl(i[0],i[1])&&(i[0]=r[0])):s.push(i=r);for(o=-1/0,e=0,i=s[n=s.length-1];e<=n;i=r,++e)r=s[e],(a=vl(i[1],r[0]))>o&&(o=a,_h=r[0],Bh=i[1])}return Oh=Fh=null,_h===1/0||Th===1/0?[[NaN,NaN],[NaN,NaN]]:[[_h,Th],[Bh,Ph]]}var zl={sphere:fh,point:_l,lineStart:Bl,lineEnd:El,polygonStart:function(){zl.lineStart=kl,zl.lineEnd=Nl},polygonEnd:function(){zl.lineStart=Bl,zl.lineEnd=El}};function _l(t,e){t*=th;var n=rh(e*=th);Tl(n*rh(t),n*hh(t),hh(e))}function Tl(t,e,n){++Hh,Kh+=(t-Kh)/Hh,tl+=(e-tl)/Hh,el+=(n-el)/Hh}function Bl(){zl.point=Pl}function Pl(t,e){t*=th;var n=rh(e*=th);ul=n*rh(t),cl=n*hh(t),dl=hh(e),zl.point=Cl,Tl(ul,cl,dl)}function Cl(t,e){t*=th;var n=rh(e*=th),i=n*rh(t),r=n*hh(t),s=hh(e),o=ih(uh((o=cl*s-dl*r)*o+(o=dl*i-ul*s)*o+(o=ul*r-cl*i)*o),ul*i+cl*r+dl*s);Qh+=o,nl+=o*(ul+(ul=i)),il+=o*(cl+(cl=r)),rl+=o*(dl+(dl=s)),Tl(ul,cl,dl)}function El(){zl.point=_l}function kl(){zl.point=Il}function Nl(){Ol(hl,ll),zl.point=_l}function Il(t,e){hl=t,ll=e,t*=th,e*=th,zl.point=Ol;var n=rh(e);ul=n*rh(t),cl=n*hh(t),dl=hh(e),Tl(ul,cl,dl)}function Ol(t,e){t*=th;var n=rh(e*=th),i=n*rh(t),r=n*hh(t),s=hh(e),o=cl*s-dl*r,a=dl*i-ul*s,h=ul*r-cl*i,l=oh(o,a,h),u=dh(l),c=l&&-u/l;sl.add(c*o),ol.add(c*a),al.add(c*h),Qh+=u,nl+=u*(ul+(ul=i)),il+=u*(cl+(cl=r)),rl+=u*(dl+(dl=s)),Tl(ul,cl,dl)}function Fl(t){Hh=Qh=Kh=tl=el=nl=il=rl=0,sl=new Ua,ol=new Ua,al=new Ua,wh(t,zl);var e=+sl,n=+ol,i=+al,r=oh(e,n,i);return r<Wa&&(e=nl,n=il,i=rl,Qh<Ja&&(e=Kh,n=tl,i=el),(r=oh(e,n,i))<Wa)?[NaN,NaN]:[ih(n,e)*Ka,dh(i/r)*Ka]}function Rl(t,e){function n(n,i){return n=t(n,i),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,i){return(n=e.invert(n,i))&&t.invert(n[0],n[1])}),n}function Vl(t,e){return eh(t)>Ya&&(t-=Math.round(t/Qa)*Qa),[t,e]}function Ul(t,e,n){return(t%=Qa)?e||n?Rl(ql(t),Dl(e,n)):ql(t):e||n?Dl(e,n):Vl}function Ll(t){return function(e,n){return eh(e+=t)>Ya&&(e-=Math.round(e/Qa)*Qa),[e,n]}}function ql(t){var e=Ll(t);return e.invert=Ll(-t),e}function Dl(t,e){var n=rh(t),i=hh(t),r=rh(e),s=hh(e);function o(t,e){var o=rh(e),a=rh(t)*o,h=hh(t)*o,l=hh(e),u=l*n+a*i;return[ih(h*r-u*s,a*n-l*i),dh(u*r+h*s)]}return o.invert=function(t,e){var o=rh(e),a=rh(t)*o,h=hh(t)*o,l=hh(e),u=l*r-h*s;return[ih(h*r+l*s,a*n+u*i),dh(u*n-a*i)]},o}function Xl(t){function e(e){return(e=t(e[0]*th,e[1]*th))[0]*=Ka,e[1]*=Ka,e}return t=Ul(t[0]*th,t[1]*th,t.length>2?t[2]*th:0),e.invert=function(e){return(e=t.invert(e[0]*th,e[1]*th))[0]*=Ka,e[1]*=Ka,e},e}function Zl(t,e){(e=jh(e))[0]-=t,$h(e);var n,i=(n=-e[1])>1?0:n<-1?Ya:Math.acos(n);return((-e[2]<0?-i:i)+Qa-Ja)%Qa}function jl(){var t,e=[];return{point:function(e,n,i){t.push([e,n,i])},lineStart:function(){e.push(t=[])},lineEnd:fh,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Gl(t,e){return eh(t[0]-e[0])<Ja&&eh(t[1]-e[1])<Ja}function Jl(t,e,n,i){this.x=t,this.z=e,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Wl(t,e,n,i,r){var s,o,a=[],h=[];if(t.forEach(function(t){if(!((e=t.length-1)<=0)){var e,n,i=t[0],o=t[e];if(Gl(i,o)){if(!i[2]&&!o[2]){for(r.lineStart(),s=0;s<e;++s)r.point((i=t[s])[0],i[1]);return void r.lineEnd()}o[0]+=2e-6}a.push(n=new Jl(i,t,null,!0)),h.push(n.o=new Jl(i,null,n,!1)),a.push(n=new Jl(o,t,null,!1)),h.push(n.o=new Jl(o,null,n,!0))}}),a.length){for(h.sort(e),Yl(a),Yl(h),s=0,o=h.length;s<o;++s)h[s].e=n=!n;for(var l,u,c=a[0];;){for(var d=c,p=!0;d.v;)if((d=d.n)===c)return;l=d.z,r.lineStart();do{if(d.v=d.o.v=!0,d.e){if(p)for(s=0,o=l.length;s<o;++s)r.point((u=l[s])[0],u[1]);else i(d.x,d.n.x,1,r);d=d.n}else{if(p)for(l=d.p.z,s=l.length-1;s>=0;--s)r.point((u=l[s])[0],u[1]);else i(d.x,d.p.x,-1,r);d=d.p}l=(d=d.o).z,p=!p}while(!d.v);r.lineEnd()}}}function Yl(t){if(e=t.length){for(var e,n,i=0,r=t[0];++i<e;)r.n=n=t[i],n.p=r,r=n;r.n=n=t[0],n.p=r}}function $l(t){return eh(t[0])<=Ya?t[0]:lh(t[0])*((eh(t[0])+Ya)%Qa-Ya)}function Hl(t,e){var n=$l(e),i=e[1],r=hh(i),s=[hh(n),-rh(n),0],o=0,a=0,h=new Ua;1===r?i=$a+Ja:-1===r&&(i=-$a-Ja);for(var l=0,u=t.length;l<u;++l)if(d=(c=t[l]).length)for(var c,d,p=c[d-1],f=$l(p),y=p[1]/2+Ha,m=hh(y),g=rh(y),x=0;x<d;++x,f=w,m=M,g=S,p=b){var b=c[x],w=$l(b),v=b[1]/2+Ha,M=hh(v),S=rh(v),A=w-f,z=A>=0?1:-1,_=z*A,T=_>Ya,B=m*M;if(h.add(ih(B*z*hh(_),g*S+B*rh(_))),o+=T?A+z*Qa:A,T^f>=n^w>=n){var P=Jh(jh(p),jh(b));$h(P);var C=Jh(s,P);$h(C);var E=(T^A>=0?-1:1)*dh(C[2]);(i>E||i===E&&(P[0]||P[1]))&&(a+=T^A>=0?1:-1)}}return(o<-1e-6||o<Ja&&h<-1e-12)^1&a}function Ql(t,e,n,i){return function(r){var s,o,a,h=e(r),l=jl(),u=e(l),c=!1,d={point:p,lineStart:y,lineEnd:m,polygonStart:function(){d.point=g,d.lineStart=x,d.lineEnd=b,o=[],s=[]},polygonEnd:function(){d.point=p,d.lineStart=y,d.lineEnd=m,o=Ga(o);var t=Hl(s,i);o.length?(c||(r.polygonStart(),c=!0),Wl(o,tu,t,n,r)):t&&(c||(r.polygonStart(),c=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),c&&(r.polygonEnd(),c=!1),o=s=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function p(e,n){t(e,n)&&r.point(e,n)}function f(t,e){h.point(t,e)}function y(){d.point=f,h.lineStart()}function m(){d.point=p,h.lineEnd()}function g(t,e){a.push([t,e]),u.point(t,e)}function x(){u.lineStart(),a=[]}function b(){g(a[0][0],a[0][1]),u.lineEnd();var t,e,n,i,h=u.clean(),d=l.result(),p=d.length;if(a.pop(),s.push(a),a=null,p)if(1&h){if((e=(n=d[0]).length-1)>0){for(c||(r.polygonStart(),c=!0),r.lineStart(),t=0;t<e;++t)r.point((i=n[t])[0],i[1]);r.lineEnd()}}else p>1&&2&h&&d.push(d.pop().concat(d.shift())),o.push(d.filter(Kl))}return d}}function Kl(t){return t.length>1}function tu(t,e){return((t=t.x)[0]<0?t[1]-$a-Ja:$a-t[1])-((e=e.x)[0]<0?e[1]-$a-Ja:$a-e[1])}Vl.invert=Vl;var eu=Ql(function(){return!0},function(t){var e,n=NaN,i=NaN,r=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(s,o){var a=s>0?Ya:-Ya,h=eh(s-n);eh(h-Ya)<Ja?(t.point(n,i=(i+o)/2>0?$a:-$a),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(s,i),e=0):r!==a&&h>=Ya&&(eh(n-r)<Ja&&(n-=r*Ja),eh(s-a)<Ja&&(s-=a*Ja),i=function(t,e,n,i){var r,s,o=hh(t-n);return eh(o)>Ja?nh((hh(e)*(s=rh(i))*hh(n)-hh(i)*(r=rh(e))*hh(t))/(r*s*o)):(e+i)/2}(n,i,s,o),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),e=0),t.point(n=s,i=o),r=a},lineEnd:function(){t.lineEnd(),n=i=NaN},clean:function(){return 2-e}}},function(t,e,n,i){var r;if(null==t)r=n*$a,i.point(-Ya,r),i.point(0,r),i.point(Ya,r),i.point(Ya,0),i.point(Ya,-r),i.point(0,-r),i.point(-Ya,-r),i.point(-Ya,0),i.point(-Ya,r);else if(eh(t[0]-e[0])>Ja){var s=t[0]<e[0]?Ya:-Ya;r=n*s/2,i.point(-s,r),i.point(0,r),i.point(s,r)}else i.point(e[0],e[1])},[-Ya,-$a]);function nu(t){var e=rh(t),n=2*th,i=e>0,r=eh(e)>Ja;function s(t,n){return rh(t)*rh(n)>e}function o(t,n,i){var r=[1,0,0],s=Jh(jh(t),jh(n)),o=Gh(s,s),a=s[0],h=o-a*a;if(!h)return!i&&t;var l=e*o/h,u=-e*a/h,c=Jh(r,s),d=Yh(r,l);Wh(d,Yh(s,u));var p=c,f=Gh(d,p),y=Gh(p,p),m=f*f-y*(Gh(d,d)-1);if(!(m<0)){var g=uh(m),x=Yh(p,(-f-g)/y);if(Wh(x,d),x=Zh(x),!i)return x;var b,w=t[0],v=n[0],M=t[1],S=n[1];v<w&&(b=w,w=v,v=b);var A=v-w,z=eh(A-Ya)<Ja;if(!z&&S<M&&(b=M,M=S,S=b),z||A<Ja?z?M+S>0^x[1]<(eh(x[0]-w)<Ja?M:S):M<=x[1]&&x[1]<=S:A>Ya^(w<=x[0]&&x[0]<=v)){var _=Yh(p,(-f+g)/y);return Wh(_,d),[x,Zh(_)]}}}function a(e,n){var r=i?t:Ya-t,s=0;return e<-r?s|=1:e>r&&(s|=2),n<-r?s|=4:n>r&&(s|=8),s}return Ql(s,function(t){var e,n,h,l,u;return{lineStart:function(){l=h=!1,u=1},point:function(c,d){var p,f=[c,d],y=s(c,d),m=i?y?0:a(c,d):y?a(c+(c<0?Ya:-Ya),d):0;if(!e&&(l=h=y)&&t.lineStart(),y!==h&&(!(p=o(e,f))||Gl(e,p)||Gl(f,p))&&(f[2]=1),y!==h)u=0,y?(t.lineStart(),p=o(f,e),t.point(p[0],p[1])):(p=o(e,f),t.point(p[0],p[1],2),t.lineEnd()),e=p;else if(r&&e&&i^y){var g;m&n||!(g=o(f,e,!0))||(u=0,i?(t.lineStart(),t.point(g[0][0],g[0][1]),t.point(g[1][0],g[1][1]),t.lineEnd()):(t.point(g[1][0],g[1][1]),t.lineEnd(),t.lineStart(),t.point(g[0][0],g[0][1],3)))}!y||e&&Gl(e,f)||t.point(f[0],f[1]),e=f,h=y,n=m},lineEnd:function(){h&&t.lineEnd(),e=null},clean:function(){return u|(l&&h)<<1}}},function(e,i,r,s){!function(t,e,n,i,r,s){if(n){var o=rh(e),a=hh(e),h=i*n;null==r?(r=e+i*Qa,s=e-h/2):(r=Zl(o,r),s=Zl(o,s),(i>0?r<s:r>s)&&(r+=i*Qa));for(var l,u=r;i>0?u>s:u<s;u-=h)l=Zh([o,-a*rh(u),-a*hh(u)]),t.point(l[0],l[1])}}(s,t,n,r,e,i)},i?[0,-t]:[-Ya,t-Ya])}var iu,ru,su,ou,au=1e9,hu=-au;function lu(t,e,n,i){function r(r,s){return t<=r&&r<=n&&e<=s&&s<=i}function s(r,s,a,l){var u=0,c=0;if(null==r||(u=o(r,a))!==(c=o(s,a))||h(r,s)<0^a>0)do{l.point(0===u||3===u?t:n,u>1?i:e)}while((u=(u+a+4)%4)!==c);else l.point(s[0],s[1])}function o(i,r){return eh(i[0]-t)<Ja?r>0?0:3:eh(i[0]-n)<Ja?r>0?2:1:eh(i[1]-e)<Ja?r>0?1:0:r>0?3:2}function a(t,e){return h(t.x,e.x)}function h(t,e){var n=o(t,1),i=o(e,1);return n!==i?n-i:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(o){var h,l,u,c,d,p,f,y,m,g,x,b=o,w=jl(),v={point:M,lineStart:function(){v.point=S,l&&l.push(u=[]);g=!0,m=!1,f=y=NaN},lineEnd:function(){h&&(S(c,d),p&&m&&w.rejoin(),h.push(w.result()));v.point=M,m&&b.lineEnd()},polygonStart:function(){b=w,h=[],l=[],x=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,r=l.length;n<r;++n)for(var s,o,a=l[n],h=1,u=a.length,c=a[0],d=c[0],p=c[1];h<u;++h)s=d,o=p,d=(c=a[h])[0],p=c[1],o<=i?p>i&&(d-s)*(i-o)>(p-o)*(t-s)&&++e:p<=i&&(d-s)*(i-o)<(p-o)*(t-s)&&--e;return e}(),n=x&&e,r=(h=Ga(h)).length;(n||r)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),r&&Wl(h,a,e,s,o),o.polygonEnd());b=o,h=l=u=null}};function M(t,e){r(t,e)&&b.point(t,e)}function S(s,o){var a=r(s,o);if(l&&u.push([s,o]),g)c=s,d=o,p=a,g=!1,a&&(b.lineStart(),b.point(s,o));else if(a&&m)b.point(s,o);else{var h=[f=Math.max(hu,Math.min(au,f)),y=Math.max(hu,Math.min(au,y))],w=[s=Math.max(hu,Math.min(au,s)),o=Math.max(hu,Math.min(au,o))];!function(t,e,n,i,r,s){var o,a=t[0],h=t[1],l=0,u=1,c=e[0]-a,d=e[1]-h;if(o=n-a,c||!(o>0)){if(o/=c,c<0){if(o<l)return;o<u&&(u=o)}else if(c>0){if(o>u)return;o>l&&(l=o)}if(o=r-a,c||!(o<0)){if(o/=c,c<0){if(o>u)return;o>l&&(l=o)}else if(c>0){if(o<l)return;o<u&&(u=o)}if(o=i-h,d||!(o>0)){if(o/=d,d<0){if(o<l)return;o<u&&(u=o)}else if(d>0){if(o>u)return;o>l&&(l=o)}if(o=s-h,d||!(o<0)){if(o/=d,d<0){if(o>u)return;o>l&&(l=o)}else if(d>0){if(o<l)return;o<u&&(u=o)}return l>0&&(t[0]=a+l*c,t[1]=h+l*d),u<1&&(e[0]=a+u*c,e[1]=h+u*d),!0}}}}}(h,w,t,e,n,i)?a&&(b.lineStart(),b.point(s,o),x=!1):(m||(b.lineStart(),b.point(h[0],h[1])),b.point(w[0],w[1]),a||b.lineEnd(),x=!1)}f=s,y=o,m=a}return v}}var uu={sphere:fh,point:fh,lineStart:function(){uu.point=du,uu.lineEnd=cu},lineEnd:fh,polygonStart:fh,polygonEnd:fh};function cu(){uu.point=uu.lineEnd=fh}function du(t,e){ru=t*=th,su=hh(e*=th),ou=rh(e),uu.point=pu}function pu(t,e){t*=th;var n=hh(e*=th),i=rh(e),r=eh(t-ru),s=rh(r),o=i*hh(r),a=ou*n-su*i*s,h=su*n+ou*i*s;iu.add(ih(uh(o*o+a*a),h)),ru=t,su=n,ou=i}var fu=[null,null],yu={type:"LineString",coordinates:fu};function mu(t,e){return fu[0]=t,fu[1]=e,n=yu,iu=new Ua,wh(n,uu),+iu;var n}var gu={Feature:function(t,e){return bu(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)if(bu(n[i].geometry,e))return!0;return!1}},xu={Sphere:function(){return!0},Point:function(t,e){return wu(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(wu(n[i],e))return!0;return!1},LineString:function(t,e){return vu(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(vu(n[i],e))return!0;return!1},Polygon:function(t,e){return Mu(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Mu(n[i],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)if(bu(n[i],e))return!0;return!1}};function bu(t,e){return!(!t||!xu.hasOwnProperty(t.type))&&xu[t.type](t,e)}function wu(t,e){return 0===mu(t,e)}function vu(t,e){for(var n,i,r,s=0,o=t.length;s<o;s++){if(0===(i=mu(t[s],e)))return!0;if(s>0&&(r=mu(t[s],t[s-1]))>0&&n<=r&&i<=r&&(n+i-r)*(1-Math.pow((n-i)/r,2))<Wa*r)return!0;n=i}return!1}function Mu(t,e){return!!Hl(t.map(Su),Au(e))}function Su(t){return(t=t.map(Au)).pop(),t}function Au(t){return[t[0]*th,t[1]*th]}var zu=t=>t,_u=1/0,Tu=_u,Bu=-_u,Pu=Bu,Cu={point:function(t,e){t<_u&&(_u=t);t>Bu&&(Bu=t);e<Tu&&(Tu=e);e>Pu&&(Pu=e)},lineStart:fh,lineEnd:fh,polygonStart:fh,polygonEnd:fh,result:function(){var t=[[_u,Tu],[Bu,Pu]];return Bu=Pu=-(Tu=_u=1/0),t}};function Eu(t){return function(e){var n=new ku;for(var i in t)n[i]=t[i];return n.stream=e,n}}function ku(){}function Nu(t,e,n){var i=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=i&&t.clipExtent(null),wh(n,t.stream(Cu)),e(Cu.result()),null!=i&&t.clipExtent(i),t}function Iu(t,e,n){return Nu(t,function(n){var i=e[1][0]-e[0][0],r=e[1][1]-e[0][1],s=Math.min(i/(n[1][0]-n[0][0]),r/(n[1][1]-n[0][1])),o=+e[0][0]+(i-s*(n[1][0]+n[0][0]))/2,a=+e[0][1]+(r-s*(n[1][1]+n[0][1]))/2;t.scale(150*s).translate([o,a])},n)}ku.prototype={constructor:ku,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Ou=rh(30*th);function Fu(t,e){return+e?function(t,e){function n(i,r,s,o,a,h,l,u,c,d,p,f,y,m){var g=l-i,x=u-r,b=g*g+x*x;if(b>4*e&&y--){var w=o+d,v=a+p,M=h+f,S=uh(w*w+v*v+M*M),A=dh(M/=S),z=eh(eh(M)-1)<Ja||eh(s-c)<Ja?(s+c)/2:ih(v,w),_=t(z,A),T=_[0],B=_[1],P=T-i,C=B-r,E=x*P-g*C;(E*E/b>e||eh((g*P+x*C)/b-.5)>.3||o*d+a*p+h*f<Ou)&&(n(i,r,s,o,a,h,T,B,z,w/=S,v/=S,M,y,m),m.point(T,B),n(T,B,z,w,v,M,l,u,c,d,p,f,y,m))}}return function(e){var i,r,s,o,a,h,l,u,c,d,p,f,y={point:m,lineStart:g,lineEnd:b,polygonStart:function(){e.polygonStart(),y.lineStart=w},polygonEnd:function(){e.polygonEnd(),y.lineStart=g}};function m(n,i){n=t(n,i),e.point(n[0],n[1])}function g(){u=NaN,y.point=x,e.lineStart()}function x(i,r){var s=jh([i,r]),o=t(i,r);n(u,c,l,d,p,f,u=o[0],c=o[1],l=i,d=s[0],p=s[1],f=s[2],16,e),e.point(u,c)}function b(){y.point=m,e.lineEnd()}function w(){g(),y.point=v,y.lineEnd=M}function v(t,e){x(i=t,e),r=u,s=c,o=d,a=p,h=f,y.point=x}function M(){n(u,c,l,d,p,f,r,s,i,o,a,h,16,e),y.lineEnd=b,b()}return y}}(t,e):function(t){return Eu({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var Ru,Vu=Eu({point:function(t,e){this.stream.point(t*th,e*th)}});function Uu(t,e,n,i,r,s){if(!s)return function(t,e,n,i,r){function s(s,o){return[e+t*(s*=i),n-t*(o*=r)]}return s.invert=function(s,o){return[(s-e)/t*i,(n-o)/t*r]},s}(t,e,n,i,r);var o=rh(s),a=hh(s),h=o*t,l=a*t,u=o/t,c=a/t,d=(a*n-o*e)/t,p=(a*e+o*n)/t;function f(t,s){return[h*(t*=i)-l*(s*=r)+e,n-l*t-h*s]}return f.invert=function(t,e){return[i*(u*t-c*e+d),r*(p-c*t-u*e)]},f}function Lu(t){return function(t){var e,n,i,r,s,o,a,h,l,u,c=150,d=480,p=250,f=0,y=0,m=0,g=0,x=0,b=0,w=1,v=1,M=null,S=eu,A=null,z=zu,_=.5;function T(t){return h(t[0]*th,t[1]*th)}function B(t){return(t=h.invert(t[0],t[1]))&&[t[0]*Ka,t[1]*Ka]}function P(){var t=Uu(c,0,0,w,v,b).apply(null,e(f,y)),i=Uu(c,d-t[0],p-t[1],w,v,b);return n=Ul(m,g,x),a=Rl(e,i),h=Rl(n,a),o=Fu(a,_),C()}function C(){return l=u=null,T}return T.stream=function(t){return l&&u===t?l:l=Vu(function(t){return Eu({point:function(e,n){var i=t(e,n);return this.stream.point(i[0],i[1])}})}(n)(S(o(z(u=t)))))},T.preclip=function(t){return arguments.length?(S=t,M=void 0,C()):S},T.postclip=function(t){return arguments.length?(z=t,A=i=r=s=null,C()):z},T.clipAngle=function(t){return arguments.length?(S=+t?nu(M=t*th):(M=null,eu),C()):M*Ka},T.clipExtent=function(t){return arguments.length?(z=null==t?(A=i=r=s=null,zu):lu(A=+t[0][0],i=+t[0][1],r=+t[1][0],s=+t[1][1]),C()):null==A?null:[[A,i],[r,s]]},T.scale=function(t){return arguments.length?(c=+t,P()):c},T.translate=function(t){return arguments.length?(d=+t[0],p=+t[1],P()):[d,p]},T.center=function(t){return arguments.length?(f=t[0]%360*th,y=t[1]%360*th,P()):[f*Ka,y*Ka]},T.rotate=function(t){return arguments.length?(m=t[0]%360*th,g=t[1]%360*th,x=t.length>2?t[2]%360*th:0,P()):[m*Ka,g*Ka,x*Ka]},T.angle=function(t){return arguments.length?(b=t%360*th,P()):b*Ka},T.reflectX=function(t){return arguments.length?(w=t?-1:1,P()):w<0},T.reflectY=function(t){return arguments.length?(v=t?-1:1,P()):v<0},T.precision=function(t){return arguments.length?(o=Fu(a,_=t*t),C()):uh(_)},T.fitExtent=function(t,e){return Iu(T,t,e)},T.fitSize=function(t,e){return function(t,e,n){return Iu(t,[[0,0],e],n)}(T,t,e)},T.fitWidth=function(t,e){return function(t,e,n){return Nu(t,function(n){var i=+e,r=i/(n[1][0]-n[0][0]),s=(i-r*(n[1][0]+n[0][0]))/2,o=-r*n[0][1];t.scale(150*r).translate([s,o])},n)}(T,t,e)},T.fitHeight=function(t,e){return function(t,e,n){return Nu(t,function(n){var i=+e,r=i/(n[1][1]-n[0][1]),s=-r*n[0][0],o=(i-r*(n[1][1]+n[0][1]))/2;t.scale(150*r).translate([s,o])},n)}(T,t,e)},function(){return e=t.apply(this,arguments),T.invert=e.invert&&B,P()}}(function(){return t})()}function qu(t,e){return[t,ah(ch(($a+e)/2))]}function Du(t,e){return[t,e]}function Xu(t,e){var n=rh(e),i=1+rh(t)*n;return[n*hh(t)/i,hh(e)/i]}qu.invert=function(t,e){return[t,2*nh(sh(e))-$a]},Du.invert=Du,Xu.invert=(Ru=function(t){return 2*nh(t)},function(t,e){var n=uh(t*t+e*e),i=Ru(n),r=hh(i),s=rh(i);return[ih(t*r,n*s),dh(n&&e*r/n)]});var Zu=Math.abs,ju=Math.cos,Gu=Math.sin,Ju=1e-6,Wu=Math.PI,Yu=Wu/2;function $u(t){return t>1?0:t<-1?Wu:Math.acos(t)}function Hu(t){return t>0?Math.sqrt(t):0}function Qu(t,e){var n=ju(e),i=function(t){return t?t/Math.sin(t):1}($u(n*ju(t/=2)));return[2*n*Gu(t)*i,Gu(e)*i]}function Ku(t,e){var n=Qu(t,e);return[(n[0]+t/Yu)/2,(n[1]+e)/2]}Ku.invert=(t,e)=>{var n=t,i=e,r=25;do{var s,o=ju(i),a=Gu(i),h=Gu(2*i),l=a*a,u=o*o,c=Gu(n),d=ju(n/2),p=Gu(n/2),f=p*p,y=1-u*d*d,m=y?$u(o*d)*Hu(s=1/y):s=0,g=.5*(2*m*o*p+n/Yu)-t,x=.5*(m*a+i)-e,b=.5*s*(u*f+m*o*d*l)+.5/Yu,w=s*(c*h/4-m*a*p),v=.125*s*(h*p-m*a*u*c),M=.5*s*(l*d+m*f*o)+.5,S=w*v-M*b,A=(x*w-g*M)/S,z=(g*v-x*b)/S;n-=A,i-=z}while((Zu(A)>Ju||Zu(z)>Ju)&&--r>0);return[n,i]};const tc={mercator:function(){return function(t){var e,n,i,r=Lu(t),s=r.center,o=r.scale,a=r.translate,h=r.clipExtent,l=null;function u(){var s=Ya*o(),a=r(Xl(r.rotate()).invert([0,0]));return h(null==l?[[a[0]-s,a[1]-s],[a[0]+s,a[1]+s]]:t===qu?[[Math.max(a[0]-s,l),e],[Math.min(a[0]+s,n),i]]:[[l,Math.max(a[1]-s,e)],[n,Math.min(a[1]+s,i)]])}return r.scale=function(t){return arguments.length?(o(t),u()):o()},r.translate=function(t){return arguments.length?(a(t),u()):a()},r.center=function(t){return arguments.length?(s(t),u()):s()},r.clipExtent=function(t){return arguments.length?(null==t?l=e=n=i=null:(l=+t[0][0],e=+t[0][1],n=+t[1][0],i=+t[1][1]),u()):null==l?null:[[l,e],[n,i]]},u()}(qu).scale(961/Qa)},equirectangular:function(){return Lu(Du).scale(152.63)},winkel3:function(){return Lu(Ku).scale(158.837)}},ec={},nc=t=>{var e,n,i;const r=JSON.stringify(t);if(ec[r])return ec[r];const s=tc[null!=(e=t.projectionType)?e:"mercator"]().center(t.center).scale(t.scale).translate(null!=(n=t.translate)?n:[0,0]).precision(null!=(i=t.precision)?i:.1);return t.rotate&&s.rotate(t.rotate),ec[r]=s,s};function ic(t){var e;const n=null!=(e=t.userData.rtcPositionsVertices)?e:t.attributes.position;if(!n)throw new Error("Geometry has no position attribute");return{x:n.getX(0),y:n.getY(0),z:n.getZ(0)}}function rc(t){t.forEach(t=>{t.userData.rtcCenter||function(t,e=null){var n,i,r;e||(e=ic(t)),t.userData.rtcCenter=e;const s=t.attributes.position,o=null!=(n=t.userData.rtcPositionsVertices)?n:t.attributes.position;for(let l=0;l<s.count;l++)s.setX(l,o.getX(l)-e.x),s.setY(l,o.getY(l)-e.y),s.setZ(l,o.getZ(l)-e.z);s.needsUpdate=!0;const a=t.attributes.next,h=null!=(i=t.userData.rtcNextVertices)?i:t.attributes.next;if("MeshLineGeometry"===t.type&&a){for(let t=0;t<a.count;t++)a.setX(t,h.getX(t)-e.x),a.setY(t,h.getY(t)-e.y),a.setZ(t,h.getZ(t)-e.z);a.needsUpdate=!0}if("MeshLineGeometry"===t.type&&t.attributes.previous){const n=t.attributes.previous,i=null!=(r=t.userData.rtcPreviousVertices)?r:t.attributes.previous;for(let t=0;t<n.count;t++)n.setX(t,i.getX(t)-e.x),n.setY(t,i.getY(t)-e.y),n.setZ(t,i.getZ(t)-e.z);n.needsUpdate=!0}}(t)});const e=function(t){if(!t||0===t.length)return{x:0,y:0,z:0};let e=0,n=0,i=0;return t.forEach(t=>{if(t.userData&&t.userData.rtcCenter){const r=t.userData.rtcCenter;e+=r.x,n+=r.y,i+=r.z}else{const r=ic(t);e+=r.x,n+=r.y,i+=r.z}}),{x:e/t.length,y:n/t.length,z:i/t.length}}(t);return t.forEach(t=>{!function(t,e){const n=t.userData.rtcCenter;if(!n)throw new Error("Geometry must have rtcCenter in userData. Call applyRTC first.");const i=n.x-e.x,r=n.y-e.y,s=n.z-e.z,o=t.attributes.position.count,a=new Float32Array(3*o);for(let h=0;h<o;h++)a[3*h]=i,a[3*h+1]=r,a[3*h+2]=s;t.setAttribute("localCenter",new _e(a,3)),t.attributes.center&&t.deleteAttribute("center")}(t,e)}),{geometries:t,globalCenter:e}}const sc=(t,e)=>t.map(([t,n])=>{let i;if(e){const[r,s]=e([t,n]);i=new E(r,-s)}else i=new E(t,n);return i}),oc=({coordinates:t,lengths:e,metaLength:n,dimension:i=2})=>{const r=[],s=[];if(t&&e&&(t instanceof Float64Array||t instanceof Float32Array)){let o=0;r.length=e.length;for(let n=0;n<e.length;n++){const s=e[n],a=new Array(s);for(let e=0;e<s;e++)a[e]=Array.from(t.subarray(o,o+i)),o+=i;r[n]=a}if(n){const e=(t.length-o)/n;s.length=e;for(let i=0;i<e;i++)s[i]=Array.from(t.subarray(o,o+n)),o+=n}}return{coordinatesArr:r,metaArray:s}};var ac=(t,e,n)=>{const i={};if(n){const{globalCenter:e}=rc(t);i.globalCenter=e}const r=Ta(t,null!=e?e:0),s=[],o=Object.keys(r.attributes);return r.index&&o.push("index"),o.forEach(t=>{const e="index"===t?r.index:r.attributes[t];i[t]={array:e.array,itemSize:e.itemSize},s.push(e.array.buffer)}),e&&(i.groups=r.groups),r.dispose(),t.forEach(t=>{t.dispose()}),{message:i,transfer:s}},hc=(t,e=300,n)=>{const i=[],r=[];return t.forEach((t,s)=>{let o=!1;for(let n=1;n<t.length;n++)if(Math.abs(t[n].x-t[n-1].x)>e){o=!0;break}if(o){const e=[],o=[];t.forEach(t=>{t.x<0?e.push(t):o.push(t)}),i.push(e,o),n&&r.push(n[s],n[s])}else i.push(t),n&&r.push(n[s])}),{splitPolygons:i,splitMeta:r}};class lc extends Re{constructor(t=[],e="none",n){super(),p(this,"type","MeshLineGeometry"),p(this,"pointCount",0),p(this,"_points",[]),p(this,"shape","none"),p(this,"shapeFunction",t=>1),p(this,"matrixWorld",new _t),this.shape=e,n&&(this.shapeFunction=n),t.length>0&&this.setPoints(t)}convertToVector3Array(t){if("number"==typeof t[0]){const e=[],n=t;for(let t=0;t<n.length;t+=3)e.push(new N(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof E?new N(t.x,t.y,0):t instanceof N?t:Array.isArray(t)&&2===t.length?new N(t[0],t[1],0):Array.isArray(t)&&3===t.length?new N(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n=!1){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry(n))}initializeGeometry(){const t=new _e(new Float32Array(6*this.pointCount),3),e=new _e(new Float32Array(6*this.pointCount),3),n=new _e(new Float32Array(6*this.pointCount),3),i=new _e(new Float32Array(2*this.pointCount),1),r=new _e(new Float32Array(2*this.pointCount),1),s=new _e(new Float32Array(2*this.pointCount),1),o=new _e(new Float32Array(4*this.pointCount),2),a=new _e(new Uint16Array(6*(this.pointCount-1)),1);"taper"===this.shape&&(this.shapeFunction=t=>1*h(4*t*(1-t),1));for(let h=0,l=0,u=0;h<this.pointCount;h+=1,l+=2,u+=6){i.setX(l,h/this.pointCount),i.setX(l+1,h/this.pointCount),r.setX(l,1),r.setX(l+1,-1);const t="none"===this.shape?1:this.shapeFunction(h/(this.pointCount-1));s.setX(l,t),s.setX(l+1,t);const e=h/(this.pointCount-1);if(o.setXY(l,e,0),o.setXY(l+1,e,1),h<this.pointCount-1){const t=2*h;a.setX(u+0,t+0),a.setX(u+1,t+1),a.setX(u+2,t+2),a.setX(u+3,t+2),a.setX(u+4,t+1),a.setX(u+5,t+3)}}this.setAttribute("position",t),this.setAttribute("previous",e),this.setAttribute("next",n),this.setAttribute("counters",i),this.setAttribute("side",r),this.setAttribute("width",s),this.setAttribute("uv",o),this.setIndex(a)}updateGeometry(t=!1){var e,n,i,r,s,o,a,h,l,u;if(!this._points[0])return;const c=this.getAttribute("position"),d=this.getAttribute("previous"),p=this.getAttribute("next");t&&(this.userData.rtcPositionsVertices=new _e(new Float64Array(3*c.count),3),this.userData.rtcPreviousVertices=new _e(new Float64Array(3*d.count),3),this.userData.rtcNextVertices=new _e(new Float64Array(3*p.count),3));let f=0,y=0,m=0;const g=this._points[0];d.setXYZ(y,g.x,g.y,g.z),null==(e=this.userData.rtcPreviousVertices)||e.setXYZ(y,g.x,g.y,g.z),y+=1,d.setXYZ(y,g.x,g.y,g.z),null==(n=this.userData.rtcPreviousVertices)||n.setXYZ(y,g.x,g.y,g.z),y+=1;for(let b=0;b<this.pointCount;b++){const t=this._points[b];c.setXYZ(f,t.x,t.y,t.z),null==(i=this.userData.rtcPositionsVertices)||i.setXYZ(f,t.x,t.y,t.z),f+=1,c.setXYZ(f,t.x,t.y,t.z),null==(r=this.userData.rtcPositionsVertices)||r.setXYZ(f,t.x,t.y,t.z),f+=1,b<this.pointCount-1&&(d.setXYZ(y,t.x,t.y,t.z),null==(s=this.userData.rtcPreviousVertices)||s.setXYZ(y,t.x,t.y,t.z),y+=1,d.setXYZ(y,t.x,t.y,t.z),null==(o=this.userData.rtcPreviousVertices)||o.setXYZ(y,t.x,t.y,t.z),y+=1),b>0&&b+1<=this.pointCount&&(p.setXYZ(m,t.x,t.y,t.z),null==(a=this.userData.rtcNextVertices)||a.setXYZ(m,t.x,t.y,t.z),m+=1,p.setXYZ(m,t.x,t.y,t.z),null==(h=this.userData.rtcNextVertices)||h.setXYZ(m,t.x,t.y,t.z),m+=1)}const x=this._points[this.pointCount-1];p.setXYZ(m,x.x,x.y,x.z),null==(l=this.userData.rtcNextVertices)||l.setXYZ(m,x.x,x.y,x.z),m+=1,p.setXYZ(m,x.x,x.y,x.z),null==(u=this.userData.rtcNextVertices)||u.setXYZ(m,x.x,x.y,x.z),m+=1,c.needsUpdate=!0,d.needsUpdate=!0,p.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(t){this.setPoints(t)}updatePoints(t,e){const n=this.convertToVector3Array(t);n.length===this.pointCount?(this._points=n,e&&(this.shapeFunction=e,this.shape="custom",this.initializeGeometry()),this.updateGeometry()):console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.")}setShape(t,e){this.shape=t,e&&(this.shapeFunction=e),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}var uc=t=>{var e;const{setPointWidth:n,nodes:i}=t,r=new lc;return r.setPoints(i,n,null!=(e=t.resetCenter)&&e),r};var cc=function(t){const e=function(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(t);let n,i,r=0,s=1;for(;s<e.length;)n=i||e[0],i=e[s],r+=(i[0]-n[0])*(i[1]+n[1]),s++;return r>0};function dc(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=pc(t,0,r,n,!0);const o=[];if(!s||s.next===s.prev)return o;let a,h,l;if(i&&(s=function(t,e,n,i){const r=[];for(let s=0,o=e.length;s<o;s++){const n=pc(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Ac(n))}r.sort(wc);for(let s=0;s<r.length;s++)n=vc(r[s],n);return n}(t,e,s,n)),t.length>80*n){a=t[0],h=t[1];let e=a,i=h;for(let s=n;s<r;s+=n){const n=t[s],r=t[s+1];n<a&&(a=n),r<h&&(h=r),n>e&&(e=n),r>i&&(i=r)}l=Math.max(e-a,i-h),l=0!==l?32767/l:0}return yc(s,o,n,a,h,l,0),o}function pc(t,e,n,i,r){let s;if(r===function(t,e,n,i){let r=0;for(let s=e,o=n-i;s<n;s+=i)r+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return r}(t,e,n,i)>0)for(let o=e;o<n;o+=i)s=Oc(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Oc(o/i|0,t[o],t[o+1],s);return s&&Pc(s,s.next)&&(Fc(s),s=s.next),s}function fc(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Pc(i,i.next)&&0!==Bc(i.prev,i,i.next))i=i.next;else{if(Fc(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function yc(t,e,n,i,r,s,o){if(!t)return;!o&&s&&function(t,e,n,i){let r=t;do{0===r.z&&(r.z=Sc(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,n=1;do{let i,r=t;t=null;let s=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<n&&(a++,o=o.nextZ,o);t++);let h=n;for(;a>0||h>0&&o;)0!==a&&(0===h||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,h--),s?s.nextZ=i:t=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(e>1)}(r)}(t,i,r,s);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(s?gc(t,i,r,s):mc(t))e.push(h.i,t.i,l.i),Fc(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?yc(t=xc(fc(t),e),e,n,i,r,s,2):2===o&&bc(t,e,n,i,r,s):yc(fc(t),e,n,i,r,s,1);break}}}function mc(t){const e=t.prev,n=t,i=t.next;if(Bc(e,n,i)>=0)return!1;const r=e.x,s=n.x,o=i.x,a=e.y,h=n.y,l=i.y,u=Math.min(r,s,o),c=Math.min(a,h,l),d=Math.max(r,s,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&_c(r,a,s,h,o,l,f.x,f.y)&&Bc(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function gc(t,e,n,i){const r=t.prev,s=t,o=t.next;if(Bc(r,s,o)>=0)return!1;const a=r.x,h=s.x,l=o.x,u=r.y,c=s.y,d=o.y,p=Math.min(a,h,l),f=Math.min(u,c,d),y=Math.max(a,h,l),m=Math.max(u,c,d),g=Sc(p,f,e,n,i),x=Sc(y,m,e,n,i);let b=t.prevZ,w=t.nextZ;for(;b&&b.z>=g&&w&&w.z<=x;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&_c(a,u,h,c,l,d,b.x,b.y)&&Bc(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&_c(a,u,h,c,l,d,w.x,w.y)&&Bc(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;b&&b.z>=g;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&_c(a,u,h,c,l,d,b.x,b.y)&&Bc(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;w&&w.z<=x;){if(w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&_c(a,u,h,c,l,d,w.x,w.y)&&Bc(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function xc(t,e){let n=t;do{const i=n.prev,r=n.next.next;!Pc(i,r)&&Cc(i,n,n.next,r)&&Nc(i,r)&&Nc(r,i)&&(e.push(i.i,n.i,r.i),Fc(n),Fc(n.next),n=t=r),n=n.next}while(n!==t);return fc(n)}function bc(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Tc(o,t)){let a=Ic(o,t);return o=fc(o,o.next),a=fc(a,a.next),yc(o,e,n,i,r,s,0),void yc(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function wc(t,e){let n=t.x-e.x;if(0===n&&(n=t.y-e.y,0===n)){n=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}return n}function vc(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(Pc(t,n))return n;do{if(Pc(t,n.next))return n.next;if(r<=n.y&&r>=n.next.y&&n.next.y!==n.y){const t=n.x+(r-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(t<=i&&t>o&&(o=t,s=n.x<n.next.x?n:n.next,t===i))return s}n=n.next}while(n!==e);if(!s)return null;const a=s,h=s.x,l=s.y;let u=1/0;n=s;do{if(i>=n.x&&n.x>=h&&i!==n.x&&zc(r<l?i:o,r,h,l,r<l?o:i,r,n.x,n.y)){const e=Math.abs(r-n.y)/(i-n.x);Nc(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&Mc(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Ic(n,t);return fc(i,i.next),fc(n,n.next)}function Mc(t,e){return Bc(t.prev,t,e.prev)<0&&Bc(e.next,t,t.next)<0}function Sc(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Ac(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function zc(t,e,n,i,r,s,o,a){return(r-o)*(e-a)>=(t-o)*(s-a)&&(t-o)*(i-a)>=(n-o)*(e-a)&&(n-o)*(s-a)>=(r-o)*(i-a)}function _c(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&zc(t,e,n,i,r,s,o,a)}function Tc(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Cc(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Nc(t,e)&&Nc(e,t)&&function(t,e){let n=t,i=!1;const r=(t.x+e.x)/2,s=(t.y+e.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&r<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(Bc(t.prev,t,e.prev)||Bc(t,e.prev,e))||Pc(t,e)&&Bc(t.prev,t,t.next)>0&&Bc(e.prev,e,e.next)>0)}function Bc(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Pc(t,e){return t.x===e.x&&t.y===e.y}function Cc(t,e,n,i){const r=kc(Bc(t,e,n)),s=kc(Bc(t,e,i)),o=kc(Bc(n,i,t)),a=kc(Bc(n,i,e));return r!==s&&o!==a||(!(0!==r||!Ec(t,n,e))||(!(0!==s||!Ec(t,i,e))||(!(0!==o||!Ec(n,t,i))||!(0!==a||!Ec(n,e,i)))))}function Ec(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function kc(t){return t>0?1:t<0?-1:0}function Nc(t,e){return Bc(t.prev,t,t.next)<0?Bc(t,e,t.next)>=0&&Bc(t,t.prev,e)>=0:Bc(t,e,t.prev)<0||Bc(t,t.next,e)<0}function Ic(t,e){const n=Rc(t.i,t.x,t.y),i=Rc(e.i,e.x,e.y),r=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,s.next=i,i.prev=s,i}function Oc(t,e,n,i){const r=Rc(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Fc(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Rc(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Vc(t){const e=[],n=[],i=t[0][0].length;let r=0,s=0;for(const o of t){for(const t of o)for(let n=0;n<i;n++)e.push(t[n]);s&&(r+=s,n.push(r)),s=o.length}return{vertices:e,holes:n,dimensions:i}}const Uc=134217729;function Lc(t,e,n,i,r){let s,o,a,h,l=e[0],u=i[0],c=0,d=0;u>l==u>-l?(s=l,l=e[++c]):(s=u,u=i[++d]);let p=0;if(c<t&&d<n)for(u>l==u>-l?(o=l+s,a=s-(o-l),l=e[++c]):(o=u+s,a=s-(o-u),u=i[++d]),s=o,0!==a&&(r[p++]=a);c<t&&d<n;)u>l==u>-l?(o=s+l,h=o-s,a=s-(o-h)+(l-h),l=e[++c]):(o=s+u,h=o-s,a=s-(o-h)+(u-h),u=i[++d]),s=o,0!==a&&(r[p++]=a);for(;c<t;)o=s+l,h=o-s,a=s-(o-h)+(l-h),l=e[++c],s=o,0!==a&&(r[p++]=a);for(;d<n;)o=s+u,h=o-s,a=s-(o-h)+(u-h),u=i[++d],s=o,0!==a&&(r[p++]=a);return 0===s&&0!==p||(r[p++]=s),p}function qc(t){return new Float64Array(t)}const Dc=qc(4),Xc=qc(8),Zc=qc(12),jc=qc(16),Gc=qc(4);function Jc(t,e,n,i,r,s){const o=(e-s)*(n-r),a=(t-r)*(i-s),h=o-a,l=Math.abs(o+a);return Math.abs(h)>=33306690738754716e-32*l?h:-function(t,e,n,i,r,s,o){let a,h,l,u,c,d,p,f,y,m,g,x,b,w,v,M,S,A;const z=t-r,_=n-r,T=e-s,B=i-s;w=z*B,d=Uc*z,p=d-(d-z),f=z-p,d=Uc*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=T*_,d=Uc*T,p=d-(d-T),f=T-p,d=Uc*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Dc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Dc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Dc[2]=x-(A-c)+(g-c),Dc[3]=A;let P=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,Dc),C=22204460492503146e-32*o;if(P>=C||-P>=C)return P;if(c=t-z,a=t-(z+c)+(c-r),c=n-_,l=n-(_+c)+(c-r),c=e-T,h=e-(T+c)+(c-s),c=i-B,u=i-(B+c)+(c-s),0===a&&0===h&&0===l&&0===u)return P;if(C=11093356479670487e-47*o+33306690738754706e-32*Math.abs(P),P+=z*u+B*a-(T*l+_*h),P>=C||-P>=C)return P;w=a*B,d=Uc*a,p=d-(d-a),f=a-p,d=Uc*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=h*_,d=Uc*h,p=d-(d-h),f=h-p,d=Uc*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const E=Lc(4,Dc,4,Gc,Xc);w=z*u,d=Uc*z,p=d-(d-z),f=z-p,d=Uc*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=T*l,d=Uc*T,p=d-(d-T),f=T-p,d=Uc*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const k=Lc(E,Xc,4,Gc,Zc);w=a*u,d=Uc*a,p=d-(d-a),f=a-p,d=Uc*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=h*l,d=Uc*h,p=d-(d-h),f=h-p,d=Uc*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const N=Lc(k,Zc,4,Gc,jc);return jc[N-1]}(t,e,n,i,r,s,l)}const Wc=Math.pow(2,-52),Yc=new Uint32Array(512);class $c{static from(t,e=nd,n=id){const i=t.length,r=new Float64Array(2*i);for(let s=0;s<i;s++){const i=t[s];r[2*s]=e(i),r[2*s+1]=n(i)}return new $c(r)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const n=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*n),this._halfedges=new Int32Array(3*n),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let o=1/0,a=1/0,h=-1/0,l=-1/0;for(let A=0;A<s;A++){const e=t[2*A],n=t[2*A+1];e<o&&(o=e),n<a&&(a=n),e>h&&(h=e),n>l&&(l=n),this._ids[A]=A}const u=(o+h)/2,c=(a+l)/2;let d,p,f;for(let A=0,z=1/0;A<s;A++){const e=Hc(u,c,t[2*A],t[2*A+1]);e<z&&(d=A,z=e)}const y=t[2*d],m=t[2*d+1];for(let A=0,z=1/0;A<s;A++){if(A===d)continue;const e=Hc(y,m,t[2*A],t[2*A+1]);e<z&&e>0&&(p=A,z=e)}let g=t[2*p],x=t[2*p+1],b=1/0;for(let A=0;A<s;A++){if(A===d||A===p)continue;const e=Kc(y,m,g,x,t[2*A],t[2*A+1]);e<b&&(f=A,b=e)}let w=t[2*f],v=t[2*f+1];if(b===1/0){for(let i=0;i<s;i++)this._dists[i]=t[2*i]-t[0]||t[2*i+1]-t[1];td(this._ids,this._dists,0,s-1);const e=new Uint32Array(s);let n=0;for(let t=0,i=-1/0;t<s;t++){const r=this._ids[t],s=this._dists[r];s>i&&(e[n++]=r,i=s)}return this.hull=e.subarray(0,n),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(Jc(y,m,g,x,w,v)<0){const t=p,e=g,n=x;p=f,g=w,x=v,f=t,w=e,v=n}const M=function(t,e,n,i,r,s){const o=n-t,a=i-e,h=r-t,l=s-e,u=o*o+a*a,c=h*h+l*l,d=.5/(o*l-a*h);return{x:t+(l*u-a*c)*d,y:e+(o*c-h*u)*d}}(y,m,g,x,w,v);this._cx=M.x,this._cy=M.y;for(let A=0;A<s;A++)this._dists[A]=Hc(t[2*A],t[2*A+1],M.x,M.y);td(this._ids,this._dists,0,s-1),this._hullStart=d;let S=3;n[d]=e[f]=p,n[p]=e[d]=f,n[f]=e[p]=d,i[d]=0,i[p]=1,i[f]=2,r.fill(-1),r[this._hashKey(y,m)]=d,r[this._hashKey(g,x)]=p,r[this._hashKey(w,v)]=f,this.trianglesLen=0,this._addTriangle(d,p,f,-1,-1,-1);for(let A,z,_=0;_<this._ids.length;_++){const s=this._ids[_],o=t[2*s],a=t[2*s+1];if(_>0&&Math.abs(o-A)<=Wc&&Math.abs(a-z)<=Wc)continue;if(A=o,z=a,s===d||s===p||s===f)continue;let h=0;for(let t=0,e=this._hashKey(o,a);t<this._hashSize&&(h=r[(e+t)%this._hashSize],-1===h||h===n[h]);t++);h=e[h];let l,u=h;for(;l=n[u],Jc(o,a,t[2*u],t[2*u+1],t[2*l],t[2*l+1])>=0;)if(u=l,u===h){u=-1;break}if(-1===u)continue;let c=this._addTriangle(u,s,n[u],-1,-1,i[u]);i[s]=this._legalize(c+2),i[u]=c,S++;let y=n[u];for(;l=n[y],Jc(o,a,t[2*y],t[2*y+1],t[2*l],t[2*l+1])<0;)c=this._addTriangle(y,s,l,i[s],-1,i[y]),i[s]=this._legalize(c+2),n[y]=y,S--,y=l;if(u===h)for(;l=e[u],Jc(o,a,t[2*l],t[2*l+1],t[2*u],t[2*u+1])<0;)c=this._addTriangle(l,s,u,-1,i[u],i[l]),this._legalize(c+2),i[l]=c,n[u]=u,S--,u=l;this._hullStart=e[s]=u,n[u]=e[y]=s,n[s]=y,r[this._hashKey(o,a)]=s,r[this._hashKey(t[2*u],t[2*u+1])]=u}this.hull=new Uint32Array(S);for(let A=0,z=this._hullStart;A<S;A++)this.hull[A]=z,z=n[z];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:n,coords:i}=this;let r=0,s=0;for(;;){const o=n[t],a=t-t%3;if(s=a+(t+2)%3,-1===o){if(0===r)break;t=Yc[--r];continue}const h=o-o%3,l=a+(t+1)%3,u=h+(o+2)%3,c=e[s],d=e[t],p=e[l],f=e[u];if(Qc(i[2*c],i[2*c+1],i[2*d],i[2*d+1],i[2*p],i[2*p+1],i[2*f],i[2*f+1])){e[t]=f,e[o]=c;const i=n[u];if(-1===i){let e=this._hullStart;do{if(this._hullTri[e]===u){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,i),this._link(o,n[s]),this._link(s,u);const a=h+(o+1)%3;r<Yc.length&&(Yc[r++]=a)}else{if(0===r)break;t=Yc[--r]}}return s}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,n,i,r,s){const o=this.trianglesLen;return this._triangles[o]=t,this._triangles[o+1]=e,this._triangles[o+2]=n,this._link(o,i),this._link(o+1,r),this._link(o+2,s),this.trianglesLen+=3,o}}function Hc(t,e,n,i){const r=t-n,s=e-i;return r*r+s*s}function Qc(t,e,n,i,r,s,o,a){const h=t-o,l=e-a,u=n-o,c=i-a,d=r-o,p=s-a,f=u*u+c*c,y=d*d+p*p;return h*(c*y-f*p)-l*(u*y-f*d)+(h*h+l*l)*(u*p-c*d)<0}function Kc(t,e,n,i,r,s){const o=n-t,a=i-e,h=r-t,l=s-e,u=o*o+a*a,c=h*h+l*l,d=.5/(o*l-a*h),p=(l*u-a*c)*d,f=(o*c-h*u)*d;return p*p+f*f}function td(t,e,n,i){if(i-n<=20)for(let r=n+1;r<=i;r++){const i=t[r],s=e[i];let o=r-1;for(;o>=n&&e[t[o]]>s;)t[o+1]=t[o--];t[o+1]=i}else{let r=n+1,s=i;ed(t,n+i>>1,r),e[t[n]]>e[t[i]]&&ed(t,n,i),e[t[r]]>e[t[i]]&&ed(t,r,i),e[t[n]]>e[t[r]]&&ed(t,n,r);const o=t[r],a=e[o];for(;;){do{r++}while(e[t[r]]<a);do{s--}while(e[t[s]]>a);if(s<r)break;ed(t,r,s)}t[n+1]=t[s],t[s]=o,i-r+1>=s-n?(td(t,e,r,i),td(t,e,n,s-1)):(td(t,e,n,s-1),td(t,e,r,i))}}function ed(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function nd(t){return t[0]}function id(t){return t[1]}function rd(t,e){for(var n=0,i=0,r=0,s=0,o=0,a=0,h=0,l=0,u=null,c=null,d=t[0],p=t[1],f=e.length;n<f;n++){i=0;var y=e[n].length-1,m=e[n];if((u=m[0])[0]!==m[y][0]&&u[1]!==m[y][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-d,a=u[1]-p;i<y;i++)if(l=(c=m[i+1])[1]-p,a<0&&l<0||a>0&&l>0)a=l,o=(u=c)[0]-d;else{if(h=c[0]-t[0],l>0&&a<=0){if((s=o*l-h*a)>0)r+=1;else if(0===s)return 0}else if(a>0&&l<=0){if((s=o*l-h*a)<0)r+=1;else if(0===s)return 0}else if(0===l&&a<0){if(0===(s=o*l-h*a))return 0}else if(0===a&&l<0){if(0===(s=o*l-h*a))return 0}else if(0===a&&0===l){if(h<=0&&o>=0)return 0;if(o<=0&&h>=0)return 0}u=c,a=l,o=h}}return r%2!=0}var sd=function(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const i=function(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(t),r="Feature"===(s=e).type?s.geometry:s;var s;const o=r.type,a=e.bbox;let h=r.coordinates;if(a&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(i,a))return!1;"Polygon"===o&&(h=[h]);let l=!1;for(var u=0;u<h.length;++u){const t=rd(i,h[u]);if(0===t)return!n.ignoreBoundary;t&&(l=!0)}return l};const od=1e-6;class ad{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,n){const i=(t=+t)+(n=+n),r=e=+e;if(n<0)throw new Error("negative radius");null===this._x1?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>od||Math.abs(this._y1-r)>od)&&(this._+="L"+i+","+r),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,n,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+i}h${-n}Z`}value(){return this._||null}}class hd{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class ld{constructor(t,[e,n,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e)&&(r=+r)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:i}=this,r=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let d,p,f=0,y=0,m=n.length;f<m;f+=3,y+=2){const e=2*n[f],i=2*n[f+1],s=2*n[f+2],o=t[e],a=t[e+1],h=t[i],l=t[i+1],u=t[s],c=t[s+1],m=h-o,g=l-a,x=u-o,b=c-a,w=2*(m*b-g*x);if(Math.abs(w)<1e-9){let e=1e9;const i=2*n[0];e*=Math.sign((t[i]-o)*b-(t[i+1]-a)*x),d=(o+u)/2-e*b,p=(a+c)/2+e*x}else{const t=1/w,e=m*m+g*g,n=x*x+b*b;d=o+(b*e-g*n)*t,p=a+(m*n-x*e)*t}r[y]=d,r[y+1]=p}let s,o,a,h=e[e.length-1],l=4*h,u=t[2*h],c=t[2*h+1];i.fill(0);for(let d=0;d<e.length;++d)h=e[d],s=l,o=u,a=c,l=4*h,u=t[2*h],c=t[2*h+1],i[s+2]=i[l]=a-c,i[s+3]=i[l+1]=u-o}render(t){const e=null==t?t=new ad:void 0,{delaunay:{halfedges:n,inedges:i,hull:r},circumcenters:s,vectors:o}=this;if(r.length<=1)return null;for(let l=0,u=n.length;l<u;++l){const e=n[l];if(e<l)continue;const i=2*Math.floor(l/3),r=2*Math.floor(e/3),o=s[i],a=s[i+1],h=s[r],u=s[r+1];this._renderSegment(o,a,h,u,t)}let a,h=r[r.length-1];for(let l=0;l<r.length;++l){a=h,h=r[l];const e=2*Math.floor(i[h]/3),n=s[e],u=s[e+1],c=4*a,d=this._project(n,u,o[c+2],o[c+3]);d&&this._renderSegment(n,u,d[0],d[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new ad:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=null==e?e=new ad:void 0,i=this._clip(t);if(null===i||!i.length)return;e.moveTo(i[0],i[1]);let r=i.length;for(;i[0]===i[r-2]&&i[1]===i[r-1]&&r>1;)r-=2;for(let s=2;s<r;s+=2)i[s]===i[s-2]&&i[s+1]===i[s-1]||e.lineTo(i[s],i[s+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const t=this.cellPolygon(e);t&&(t.index=e,yield t)}}cellPolygon(t){const e=new hd;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,i,r){let s;const o=this._regioncode(t,e),a=this._regioncode(n,i);0===o&&0===a?(r.moveTo(t,e),r.lineTo(n,i)):(s=this._clipSegment(t,e,n,i,o,a))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,n){return(e=+e)==e&&(n=+n)==n&&this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const t=this._clip(n);if(t)t:for(let i=0,r=e.length;i<r;i+=2)for(let s=0,o=t.length;s<o;s+=2)if(e[i]==t[s]&&e[i+1]==t[s+1]&&e[(i+2)%r]==t[(s+o-2)%o]&&e[(i+3)%r]==t[(s+o-1)%o]){yield n;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:i,triangles:r}}=this,s=n[t];if(-1===s)return null;const o=[];let a=s;do{const n=Math.floor(a/3);if(o.push(e[2*n],e[2*n+1]),a=a%3==2?a-2:a+1,r[a]!==t)break;a=i[a]}while(a!==s&&-1!==a);return o}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:n}=this,i=4*t;return n[i]||n[i+1]?this._clipInfinite(t,e,n[i],n[i+1],n[i+2],n[i+3]):this._clipFinite(t,e)}_clipFinite(t,e){const n=e.length;let i,r,s,o,a=null,h=e[n-2],l=e[n-1],u=this._regioncode(h,l),c=0;for(let d=0;d<n;d+=2)if(i=h,r=l,h=e[d],l=e[d+1],s=u,u=this._regioncode(h,l),0===s&&0===u)o=c,c=0,a?a.push(h,l):a=[h,l];else{let e,n,d,p,f;if(0===s){if(null===(e=this._clipSegment(i,r,h,l,s,u)))continue;[n,d,p,f]=e}else{if(null===(e=this._clipSegment(h,l,i,r,u,s)))continue;[p,f,n,d]=e,o=c,c=this._edgecode(n,d),o&&c&&this._edge(t,o,c,a,a.length),a?a.push(n,d):a=[n,d]}o=c,c=this._edgecode(p,f),o&&c&&this._edge(t,o,c,a,a.length),a?a.push(p,f):a=[p,f]}if(a)o=c,c=this._edgecode(a[0],a[1]),o&&c&&this._edge(t,o,c,a,a.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return a}_clipSegment(t,e,n,i,r,s){for(;;){if(0===r&&0===s)return[t,e,n,i];if(r&s)return null;let o,a,h=r||s;8&h?(o=t+(n-t)*(this.ymax-e)/(i-e),a=this.ymax):4&h?(o=t+(n-t)*(this.ymin-e)/(i-e),a=this.ymin):2&h?(a=e+(i-e)*(this.xmax-t)/(n-t),o=this.xmax):(a=e+(i-e)*(this.xmin-t)/(n-t),o=this.xmin),r?(t=o,e=a,r=this._regioncode(t,e)):(n=o,i=a,s=this._regioncode(n,i))}}_clipInfinite(t,e,n,i,r,s){let o,a=Array.from(e);if((o=this._project(a[0],a[1],n,i))&&a.unshift(o[0],o[1]),(o=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(o[0],o[1]),a=this._clipFinite(t,a))for(let h,l=0,u=a.length,c=this._edgecode(a[u-2],a[u-1]);l<u;l+=2)h=c,c=this._edgecode(a[l],a[l+1]),h&&c&&(l=this._edge(t,h,c,a,l),u=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,n,i,r){for(;e!==n;){let n,s;switch(e){case 5:e=4;continue;case 4:e=6,n=this.xmax,s=this.ymin;break;case 6:e=2;continue;case 2:e=10,n=this.xmax,s=this.ymax;break;case 10:e=8;continue;case 8:e=9,n=this.xmin,s=this.ymax;break;case 9:e=1;continue;case 1:e=5,n=this.xmin,s=this.ymin}i[r]===n&&i[r+1]===s||!this.contains(t,n,s)||(i.splice(r,0,n,s),r+=2)}if(i.length>4)for(let s=0;s<i.length;s+=2){const t=(s+2)%i.length,e=(s+4)%i.length;(i[s]===i[t]&&i[t]===i[e]||i[s+1]===i[t+1]&&i[t+1]===i[e+1])&&(i.splice(t,2),s-=2)}return r}_project(t,e,n,i){let r,s,o,a=1/0;if(i<0){if(e<=this.ymin)return null;(r=(this.ymin-e)/i)<a&&(o=this.ymin,s=t+(a=r)*n)}else if(i>0){if(e>=this.ymax)return null;(r=(this.ymax-e)/i)<a&&(o=this.ymax,s=t+(a=r)*n)}if(n>0){if(t>=this.xmax)return null;(r=(this.xmax-t)/n)<a&&(s=this.xmax,o=e+(a=r)*i)}else if(n<0){if(t<=this.xmin)return null;(r=(this.xmin-t)/n)<a&&(s=this.xmin,o=e+(a=r)*i)}return[s,o]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const ud=2*Math.PI,cd=Math.pow;function dd(t){return t[0]}function pd(t){return t[1]}function fd(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class yd{static from(t,e=dd,n=pd,i){return new yd("length"in t?function(t,e,n,i){const r=t.length,s=new Float64Array(2*r);for(let o=0;o<r;++o){const r=t[o];s[2*o]=e.call(i,r,o,t),s[2*o+1]=n.call(i,r,o,t)}return s}(t,e,n,i):Float64Array.from(function*(t,e,n,i){let r=0;for(const s of t)yield e.call(i,s,r,t),yield n.call(i,s,r,t),++r}(t,e,n,i)))}constructor(t){this._delaunator=new $c(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:n}=t;for(let i=0;i<e.length;i+=3){const t=2*e[i],r=2*e[i+1],s=2*e[i+2];if((n[s]-n[t])*(n[r+1]-n[t+1])-(n[r]-n[t])*(n[s+1]-n[t+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},(t,e)=>e).sort((t,n)=>e[2*t]-e[2*n]||e[2*t+1]-e[2*n+1]);const t=this.collinear[0],n=this.collinear[this.collinear.length-1],i=[e[2*t],e[2*t+1],e[2*n],e[2*n+1]],r=1e-8*Math.hypot(i[3]-i[1],i[2]-i[0]);for(let s=0,o=e.length/2;s<o;++s){const t=fd(e[2*s],e[2*s+1],r);e[2*s]=t[0],e[2*s+1]=t[1]}this._delaunator=new $c(e)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),o=this._hullIndex.fill(-1);for(let a=0,h=n.length;a<h;++a){const t=r[a%3==2?a-2:a+1];-1!==n[a]&&-1!==s[t]||(s[t]=a)}for(let a=0,h=i.length;a<h;++a)o[i[a]]=a;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,2===i.length&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new ld(this,t)}*neighbors(t){const{inedges:e,hull:n,_hullIndex:i,halfedges:r,triangles:s,collinear:o}=this;if(o){const e=o.indexOf(t);return e>0&&(yield o[e-1]),void(e<o.length-1&&(yield o[e+1]))}const a=e[t];if(-1===a)return;let h=a,l=-1;do{if(yield l=s[h],h=h%3==2?h-2:h+1,s[h]!==t)return;if(h=r[h],-1===h){const e=n[(i[t]+1)%n.length];return void(e!==l&&(yield e))}}while(h!==a)}find(t,e,n=0){if((t=+t)!=t||(e=+e)!=e)return-1;const i=n;let r;for(;(r=this._step(n,t,e))>=0&&r!==n&&r!==i;)n=r;return r}_step(t,e,n){const{inedges:i,hull:r,_hullIndex:s,halfedges:o,triangles:a,points:h}=this;if(-1===i[t]||!h.length)return(t+1)%(h.length>>1);let l=t,u=cd(e-h[2*t],2)+cd(n-h[2*t+1],2);const c=i[t];let d=c;do{let i=a[d];const c=cd(e-h[2*i],2)+cd(n-h[2*i+1],2);if(c<u&&(u=c,l=i),d=d%3==2?d-2:d+1,a[d]!==t)break;if(d=o[d],-1===d){if(d=r[(s[t]+1)%r.length],d!==i&&cd(e-h[2*d],2)+cd(n-h[2*d+1],2)<u)return d;break}}while(d!==c);return l}render(t){const e=null==t?t=new ad:void 0,{points:n,halfedges:i,triangles:r}=this;for(let s=0,o=i.length;s<o;++s){const e=i[s];if(e<s)continue;const o=2*r[s],a=2*r[e];t.moveTo(n[o],n[o+1]),t.lineTo(n[a],n[a+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){void 0!==e||t&&"function"==typeof t.moveTo||(e=t,t=null),e=null==e?2:+e;const n=null==t?t=new ad:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const n=i[r],s=i[r+1];t.moveTo(n+e,s),t.arc(n,s,e,0,ud)}return n&&n.value()}renderHull(t){const e=null==t?t=new ad:void 0,{hull:n,points:i}=this,r=2*n[0],s=n.length;t.moveTo(i[r],i[r+1]);for(let o=1;o<s;++o){const e=2*n[o];t.lineTo(i[e],i[e+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new hd;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new ad:void 0,{points:i,triangles:r}=this,s=2*r[t*=3],o=2*r[t+1],a=2*r[t+2];return e.moveTo(i[s],i[s+1]),e.lineTo(i[o],i[o+1]),e.lineTo(i[a],i[a+1]),e.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,n=t.length/3;e<n;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new hd;return this.renderTriangle(t,e),e.value()}}const md=Math.PI,gd=md/2,xd=180/md,bd=md/180,wd=Math.atan2,vd=Math.cos,Md=Math.max,Sd=Math.min,Ad=Math.sin,zd=Math.sign||function(t){return t>0?1:t<0?-1:0},_d=Math.sqrt;function Td(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Bd(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Pd(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Cd(t){var e=_d(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return[t[0]/e,t[1]/e,t[2]/e]}function Ed(t){return[wd(t[1],t[0])*xd,(e=Md(-1,Sd(1,t[2])),(e>1?gd:e<-1?-gd:Math.asin(e))*xd)];var e}function kd(t){const e=t[0]*bd,n=t[1]*bd,i=vd(n);return[i*vd(e),i*Ad(e),Ad(n)]}function Nd(t){return Td((t=t.map(t=>kd(t)))[0],Bd(t[2],t[1]))}function Id(t){const e=function(t){if(t.length<2)return{};let e=0;for(;isNaN(t[e][0]+t[e][1])&&e++<t.length;);const n=Xl(t[e]),i=Lu(Xu).scale(250).clipAngle(142).translate([0,0]).scale(1).rotate(n.invert([180,0]));t=t.map(i);const r=[];let s=1;for(let d=0,p=t.length;d<p;d++){let e=h(t[d][0],2)+h(t[d][1],2);!isFinite(e)||e>1e32?r.push(d):e>s&&(s=e)}const o=1e6*_d(s);r.forEach(e=>t[e]=[o,0]),t.push([0,o]),t.push([-o,0]),t.push([0,-o]);const a=yd.from(t);a.projection=i;const{triangles:l,halfedges:u,inedges:c}=a;for(let h=0,d=u.length;h<d;h++)if(u[h]<0){const t=h%3==2?h-2:h+1,n=h%3==0?h+2:h-1,i=u[t],r=u[n];u[i]=r,u[r]=i,u[t]=u[n]=-1,l[h]=l[t]=l[n]=e,c[l[i]]=i%3==0?i+2:i-1,c[l[r]]=r%3==0?r+2:r-1,h+=2-h%3}else l[h]>t.length-3-1&&(l[h]=e);return a}(t),n=function(t){const{triangles:e}=t;if(!e)return[];const n=[];for(let i=0,r=e.length/3;i<r;i++){const t=e[3*i],r=e[3*i+1],s=e[3*i+2];t!==r&&r!==s&&n.push([t,s,r])}return n}(e),i=function(t,e){const n=new Set;return 2===e.length?[[0,1]]:(t.forEach(t=>{if(t[0]!==t[1]&&!(Nd(t.map(t=>e[t]))<0))for(let e,i=0;i<3;i++)e=(i+1)%3,n.add(Va([t[i],t[e]]).join("-"))}),Array.from(n,t=>t.split("-").map(Number)))}(n,t),r=function(t,e){const n=[];t.forEach(t=>{for(let e=0;e<3;e++){const i=t[e],r=t[(e+1)%3];n[i]=n[i]||[],n[i].push(r)}}),0===t.length&&(2===e?(n[0]=[1],n[1]=[0]):1===e&&(n[0]=[]));return n}(n,t.length),s=function(t,e){function n(t,e){let n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2];return n*n+i*i+r*r}return function(i,r,s){void 0===s&&(s=0);let o,a,h=s;const l=kd([i,r]);do{o=s,s=null,a=n(l,kd(e[o])),t[o].forEach(t=>{let i=n(l,kd(e[t]));if(i<a)return a=i,s=t,void(h=t)})}while(null!==s);return h}}(r,t),o=function(t,e){return t.map(t=>{const n=t.map(t=>e[t]).map(kd);return Ed(Cd(Pd(Pd(Bd(n[1],n[0]),Bd(n[2],n[1])),Bd(n[0],n[2]))))})}(n,t),{polygons:a,centers:l}=function(t,e,n){const i=[],r=t.slice();if(0===e.length){if(n.length<2)return{polygons:i,centers:r};if(2===n.length){const t=kd(n[0]),e=kd(n[1]),s=Cd(Pd(t,e)),a=Cd(Bd(t,e)),h=Bd(s,a),l=[s,Bd(s,h),Bd(Bd(s,h),h),Bd(Bd(Bd(s,h),h),h)].map(Ed).map(o);return i.push(l),i.push(l.slice().reverse()),{polygons:i,centers:r}}}e.forEach((t,e)=>{for(let n=0;n<3;n++){const r=t[n],s=t[(n+1)%3],o=t[(n+2)%3];i[r]=i[r]||[],i[r].push([s,o,e,[r,s,o]])}});const s=i.map(t=>{const e=[t[0][2]];let i=t[0][1];for(let n=1;n<t.length;n++)for(let r=0;r<t.length;r++)if(t[r][0]==i){i=t[r][1],e.push(t[r][2]);break}if(e.length>2)return e;if(2==e.length){const i=Od(n[t[0][3][0]],n[t[0][3][1]],r[e[0]]),s=Od(n[t[0][3][2]],n[t[0][3][0]],r[e[0]]),a=o(i),h=o(s);return[e[0],h,e[1],a]}});function o(t){let n=-1;return r.slice(e.length,1/0).forEach((i,r)=>{i[0]===t[0]&&i[1]===t[1]&&(n=r+e.length)}),n<0&&(n=r.length,r.push(t)),n}return{polygons:s,centers:r}}(o,n,t),u=function(t){const e=[];return t.forEach(t=>{if(!t)return;let n=t[t.length-1];for(let i of t)i>n&&e.push([n,i]),n=i}),e}(a),c=function(t,e){const n=new Set,i=[];t.map(t=>{if(!(Nd(t.map(t=>e[t>e.length?0:t]))>1e-12))for(let e=0;e<3;e++){let i=[t[e],t[(e+1)%3]],r=`${i[0]}-${i[1]}`;n.has(r)?n.delete(r):n.add(`${i[1]}-${i[0]}`)}});const r=new Map;let s;if(n.forEach(t=>{t=t.split("-").map(Number),r.set(t[0],t[1]),s=t[0]}),void 0===s)return i;let o=s;do{i.push(o);let t=r.get(o);r.set(o,-1),o=t}while(o>-1&&o!==s);return i}(n,t),d=function(t,e){return function(n){const i=new Map,r=new Map;return t.forEach((t,e)=>{const s=t.join("-");i.set(s,n[e]),r.set(s,!0)}),e.forEach(t=>{let e=0,n=-1;for(let r=0;r<3;r++){let s=Va([t[r],t[(r+1)%3]]).join("-");i.get(s)>e&&(e=i.get(s),n=s)}r.set(n,!1)}),t.map(t=>r.get(t.join("-")))}}(i,n);return{delaunay:e,edges:i,triangles:n,centers:l,neighbors:r,polygons:a,mesh:u,hull:c,urquhart:d,find:s}}function Od(t,e,n){t=kd(t),e=kd(e),n=kd(n);const i=zd(Td(Bd(e,t),n));return Ed(Cd(Pd(t,e)).map(t=>i*t))}function Fd(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Rd(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Vd(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Ud(){}var Ld=.7,qd=1/Ld,Dd="\\\\s*([+-]?\\\\d+)\\\\s*",Xd="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*",Zd="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*",jd=/^#([0-9a-f]{3,8})$/,Gd=new RegExp(`^rgb\\\\(${Dd},${Dd},${Dd}\\\\)$`),Jd=new RegExp(`^rgb\\\\(${Zd},${Zd},${Zd}\\\\)$`),Wd=new RegExp(`^rgba\\\\(${Dd},${Dd},${Dd},${Xd}\\\\)$`),Yd=new RegExp(`^rgba\\\\(${Zd},${Zd},${Zd},${Xd}\\\\)$`),$d=new RegExp(`^hsl\\\\(${Xd},${Zd},${Zd}\\\\)$`),Hd=new RegExp(`^hsla\\\\(${Xd},${Zd},${Zd},${Xd}\\\\)$`),Qd={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function Kd(){return this.rgb().formatHex()}function tp(){return this.rgb().formatRgb()}function ep(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=jd.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?np(e):3===n?new sp(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?ip(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?ip(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Gd.exec(t))?new sp(e[1],e[2],e[3],1):(e=Jd.exec(t))?new sp(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Wd.exec(t))?ip(e[1],e[2],e[3],e[4]):(e=Yd.exec(t))?ip(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=$d.exec(t))?cp(e[1],e[2]/100,e[3]/100,1):(e=Hd.exec(t))?cp(e[1],e[2]/100,e[3]/100,e[4]):Qd.hasOwnProperty(t)?np(Qd[t]):"transparent"===t?new sp(NaN,NaN,NaN,0):null}function np(t){return new sp(t>>16&255,t>>8&255,255&t,1)}function ip(t,e,n,i){return i<=0&&(t=e=n=NaN),new sp(t,e,n,i)}function rp(t,e,n,i){return 1===arguments.length?((r=t)instanceof Ud||(r=ep(r)),r?new sp((r=r.rgb()).r,r.g,r.b,r.opacity):new sp):new sp(t,e,n,null==i?1:i);var r}function sp(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function op(){return`#${up(this.r)}${up(this.g)}${up(this.b)}`}function ap(){const t=hp(this.opacity);return`${1===t?"rgb(":"rgba("}${lp(this.r)}, ${lp(this.g)}, ${lp(this.b)}${1===t?")":`, ${t})`}`}function hp(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function lp(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function up(t){return((t=lp(t))<16?"0":"")+t.toString(16)}function cp(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new pp(t,e,n,i)}function dp(t){if(t instanceof pp)return new pp(t.h,t.s,t.l,t.opacity);if(t instanceof Ud||(t=ep(t)),!t)return new pp;if(t instanceof pp)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),s=Math.max(e,n,i),o=NaN,a=s-r,h=(s+r)/2;return a?(o=e===s?(n-i)/a+6*(n<i):n===s?(i-e)/a+2:(e-n)/a+4,a/=h<.5?s+r:2-s-r,o*=60):a=h>0&&h<1?0:o,new pp(o,a,h,t.opacity)}function pp(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function fp(t){return(t=(t||0)%360)<0?t+360:t}function yp(t){return Math.max(0,Math.min(1,t||0))}function mp(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Rd(Ud,ep,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Kd,formatHex:Kd,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return dp(this).formatHsl()},formatRgb:tp,toString:tp}),Rd(sp,rp,Vd(Ud,{brighter(t){return t=null==t?qd:Math.pow(qd,t),new sp(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Ld:Math.pow(Ld,t),new sp(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new sp(lp(this.r),lp(this.g),lp(this.b),hp(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:op,formatHex:op,formatHex8:function(){return`#${up(this.r)}${up(this.g)}${up(this.b)}${up(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ap,toString:ap})),Rd(pp,function(t,e,n,i){return 1===arguments.length?dp(t):new pp(t,e,n,null==i?1:i)},Vd(Ud,{brighter(t){return t=null==t?qd:Math.pow(qd,t),new pp(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Ld:Math.pow(Ld,t),new pp(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new sp(mp(t>=240?t-240:t+120,r,i),mp(t,r,i),mp(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new pp(fp(this.h),yp(this.s),yp(this.l),hp(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=hp(this.opacity);return`${1===t?"hsl(":"hsla("}${fp(this.h)}, ${100*yp(this.s)}%, ${100*yp(this.l)}%${1===t?")":`, ${t})`}`}}));var gp=t=>()=>t;function xp(t){return 1===(t=+t)?bp:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):gp(isNaN(e)?n:e)}}function bp(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):gp(isNaN(t)?e:t)}var wp=function t(e){var n=xp(e);function i(t,e){var i=n((t=rp(t)).r,(e=rp(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=bp(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=s(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function vp(t,e){e||(e=[]);var n,i=t?Math.min(e.length,t.length):0,r=e.slice();return function(s){for(n=0;n<i;++n)r[n]=t[n]*(1-s)+e[n]*s;return r}}function Mp(t,e){var n,i=e?e.length:0,r=t?Math.min(i,t.length):0,s=new Array(r),o=new Array(i);for(n=0;n<r;++n)s[n]=Pp(t[n],e[n]);for(;n<i;++n)o[n]=e[n];return function(t){for(n=0;n<r;++n)o[n]=s[n](t);return o}}function Sp(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function Ap(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function zp(t,e){var n,i={},r={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?i[n]=Pp(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var _p=/[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,Tp=new RegExp(_p.source,"g");function Bp(t,e){var n,i,r,s=_p.lastIndex=Tp.lastIndex=0,o=-1,a=[],h=[];for(t+="",e+="";(n=_p.exec(t))&&(i=Tp.exec(e));)(r=i.index)>s&&(r=e.slice(s,r),a[o]?a[o]+=r:a[++o]=r),(n=n[0])===(i=i[0])?a[o]?a[o]+=i:a[++o]=i:(a[++o]=null,h.push({i:o,x:Ap(n,i)})),s=Tp.lastIndex;return s<e.length&&(r=e.slice(s),a[o]?a[o]+=r:a[++o]=r),a.length<2?h[0]?function(t){return function(e){return t(e)+""}}(h[0].x):function(t){return function(){return t}}(e):(e=h.length,function(t){for(var n,i=0;i<e;++i)a[(n=h[i]).i]=n.x(t);return a.join("")})}function Pp(t,e){var n,i,r=typeof e;return null==e||"boolean"===r?gp(e):("number"===r?Ap:"string"===r?(n=ep(e))?(e=n,wp):Bp:e instanceof ep?wp:e instanceof Date?Sp:(i=e,!ArrayBuffer.isView(i)||i instanceof DataView?Array.isArray(e)?Mp:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?zp:Ap:vp))(t,e)}function Cp(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function Ep(t){return+t}var kp=[0,1];function Np(t){return t}function Ip(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function Op(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Ip(r,i),s=n(o,s)):(i=Ip(i,r),s=n(s,o)),function(t){return s(i(t))}}function Fp(t,e,n){var i=Math.min(t.length,e.length)-1,r=new Array(i),s=new Array(i),o=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<i;)r[o]=Ip(t[o],t[o+1]),s[o]=n(e[o],e[o+1]);return function(e){var n=Ra(t,e,1,i)-1;return s[n](r[n](e))}}function Rp(){var t,e,n,i,r,s,o=kp,a=kp,h=Pp,l=Np;function u(){var t,e,n,h=Math.min(o.length,a.length);return l!==Np&&(t=o[0],e=o[h-1],t>e&&(n=t,t=e,e=n),l=function(n){return Math.max(t,Math.min(e,n))}),i=h>2?Fp:Op,r=s=null,c}function c(e){return null==e||isNaN(e=+e)?n:(r||(r=i(o.map(t),a,h)))(t(l(e)))}return c.invert=function(n){return l(e((s||(s=i(a,o.map(t),Ap)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,Ep),u()):o.slice()},c.range=function(t){return arguments.length?(a=Array.from(t),u()):a.slice()},c.rangeRound=function(t){return a=Array.from(t),h=Cp,u()},c.clamp=function(t){return arguments.length?(l=!!t||Np,u()):l!==Np},c.interpolate=function(t){return arguments.length?(h=t,u()):h},c.unknown=function(t){return arguments.length?(n=t,c):n},function(n,i){return t=n,e=i,u()}}function Vp(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,i=t.slice(0,n);return[i.length>1?i[0]+i.slice(2):i,+t.slice(n+1)]}function Up(t){return(t=Vp(Math.abs(t)))?t[1]:NaN}var Lp,qp=/^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;function Dp(t){if(!(e=qp.exec(t)))throw new Error("invalid format: "+t);var e;return new Xp({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Xp(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Zp(t,e){var n=Vp(t,e);if(!n)return t+"";var i=n[0],r=n[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}Dp.prototype=Xp.prototype,Xp.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var jp={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Zp(100*t,e),r:Zp,s:function(t,e){var n=Vp(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(Lp=3*Math.max(-8,Math.min(8,Math.floor(r/3))))+1,o=i.length;return s===o?i:s>o?i+new Array(s-o+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+Vp(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Gp(t){return t}var Jp,Wp,Yp,$p=Array.prototype.map,Hp=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Qp(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?Gp:(e=$p.call(t.grouping,Number),n=t.thousands+"",function(t,i){for(var r=t.length,s=[],o=0,a=e[0],h=0;r>0&&a>0&&(h+a+1>i&&(a=Math.max(1,i-h)),s.push(t.substring(r-=a,r+a)),!((h+=a+1)>i));)a=e[o=(o+1)%e.length];return s.reverse().join(n)}),r=void 0===t.currency?"":t.currency[0]+"",s=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?Gp:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}($p.call(t.numerals,String)),h=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var e=(t=Dp(t)).fill,n=t.align,c=t.sign,d=t.symbol,p=t.zero,f=t.width,y=t.comma,m=t.precision,g=t.trim,x=t.type;"n"===x?(y=!0,x="g"):jp[x]||(void 0===m&&(m=12),g=!0,x="g"),(p||"0"===e&&"="===n)&&(p=!0,e="0",n="=");var b="$"===d?r:"#"===d&&/[boxX]/.test(x)?"0"+x.toLowerCase():"",w="$"===d?s:/[%p]/.test(x)?h:"",v=jp[x],M=/[defgprs%]/.test(x);function S(t){var r,s,h,d=b,S=w;if("c"===x)S=v(t)+S,t="";else{var A=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:v(Math.abs(t),m),g&&(t=function(t){t:for(var e,n=t.length,i=1,r=-1;i<n;++i)switch(t[i]){case".":r=e=i;break;case"0":0===r&&(r=i),e=i;break;default:if(!+t[i])break t;r>0&&(r=0)}return r>0?t.slice(0,r)+t.slice(e+1):t}(t)),A&&0===+t&&"+"!==c&&(A=!1),d=(A?"("===c?c:l:"-"===c||"("===c?"":c)+d,S=("s"===x?Hp[8+Lp/3]:"")+S+(A&&"("===c?")":""),M)for(r=-1,s=t.length;++r<s;)if(48>(h=t.charCodeAt(r))||h>57){S=(46===h?o+t.slice(r+1):t.slice(r))+S,t=t.slice(0,r);break}}y&&!p&&(t=i(t,1/0));var z=d.length+t.length+S.length,_=z<f?new Array(f-z+1).join(e):"";switch(y&&p&&(t=i(_+t,_.length?f-S.length:1/0),_=""),n){case"<":t=d+t+S+_;break;case"=":t=d+_+t+S;break;case"^":t=_.slice(0,z=_.length>>1)+d+t+S+_.slice(z);break;default:t=_+d+t+S}return a(t)}return m=void 0===m?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),S.toString=function(){return t+""},S}return{format:c,formatPrefix:function(t,e){var n=c(((t=Dp(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Up(e)/3))),r=Math.pow(10,-i),s=Hp[8+i/3];return function(t){return n(r*t)+s}}}}function Kp(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?Za(e,t,n):Za(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=Dp(null==i?",f":i)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=i.precision||isNaN(r=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Up(e)/3)))-Up(Math.abs(t)))}(s,o))||(i.precision=r),Yp(i,o);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(r=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Up(e)-Up(t))+1}(s,Math.max(Math.abs(t),Math.abs(e))))||(i.precision=r-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(r=function(t){return Math.max(0,-Up(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return Wp(i)}function tf(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const i=e<t,[r,s,o]=i?Xa(e,t,n):Xa(t,e,n);if(!(s>=r))return[];const a=s-r+1,h=new Array(a);if(i)if(o<0)for(let l=0;l<a;++l)h[l]=(s-l)/-o;else for(let l=0;l<a;++l)h[l]=(s-l)*o;else if(o<0)for(let l=0;l<a;++l)h[l]=(r+l)/-o;else for(let l=0;l<a;++l)h[l]=(r+l)*o;return h}(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var i=e();return Kp(i[0],i[i.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var i,r,s=e(),o=0,a=s.length-1,h=s[o],l=s[a],u=10;for(l<h&&(r=h,h=l,l=r,r=o,o=a,a=r);u-- >0;){if((r=Za(h,l,n))===i)return s[o]=h,s[a]=l,e(s);if(r>0)h=Math.floor(h/r)*r,l=Math.ceil(l/r)*r;else{if(!(r<0))break;h=Math.ceil(h*r)/r,l=Math.floor(l*r)/r}i=r}return t},t}function ef(){var t=Rp()(Np,Np);return t.copy=function(){return e=t,ef().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Fd.apply(t,arguments),tf(t)}function nf(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const v=180*mu(t,i)/Math.PI;if(v>e){const M=(s=t,o=(r=i)[0]*th,a=r[1]*th,h=s[0]*th,l=s[1]*th,u=rh(a),c=hh(a),d=rh(l),p=hh(l),f=u*rh(o),y=u*hh(o),m=d*rh(h),g=d*hh(h),x=2*dh(uh(ph(l-a)+u*d*ph(h-o))),b=hh(x),w=x?function(t){var e=hh(t*=x)/b,n=hh(x-t)/b,i=n*f+e*m,r=n*y+e*g,s=n*c+e*p;return[ih(r,i)*Ka,ih(s,uh(i*i+r*r))*Ka]}:function(){return[o*Ka,a*Ka]},w.distance=x,w),S=1/Math.ceil(v/e);let A=S;for(;A<1;)n.push(M(A)),A+=S}}var r,s,o,a,h,l,u,c,d,p,f,y,m,g,x,b,w;n.push(i=t)}),n})}function rf(t,e,n=!1){return n?(r=t,((i=e)&&gu.hasOwnProperty(i.type)?gu[i.type]:bu)(i,r)):sd(t,e);var i,r}function sf(t,e){const n={type:"Polygon",coordinates:t},[[i,r],[s,o]]=Al(n);if(Math.min(Math.abs(s-i),Math.abs(o-r))<e)return[];const a=i>s||o>=89||r<=-89;return function(t,{minLng:e,maxLng:n,minLat:i,maxLat:r}={}){const s=Math.round(h(360/t,2)/Math.PI),o=(1+Math.sqrt(5))/2,a=t=>t/o*360%360-180,l=t=>Math.acos(2*t/s-1)/Math.PI*180-90,u=t=>s*(Math.cos((t+90)*Math.PI/180)+1)/2,c=[void 0!==r?Math.ceil(u(r)):0,void 0!==i?Math.floor(u(i)):s-1],d=void 0===e&&void 0===n?()=>!0:void 0===e?t=>t<=n:void 0===n?t=>t>=e:n>=e?t=>t>=e&&t<=n:t=>t>=e||t<=n,p=[];for(let h=c[0];h<=c[1];h++){const t=a(h);d(t)&&p.push([t,l(h)])}return p}(e,{minLng:i,maxLng:s,minLat:r,maxLat:o}).filter(t=>rf(t,n,a))}function of(t,{resolution:e=1/0,bbox:n,projection:i}={}){const r=nf(t,e),s=Ga(r),o=sf(t,e),a=[...s,...o],h={type:"Polygon",coordinates:t},[[l,u],[c,d]]=Al(h),p=l>c||d>=89||u<=-89;let f=[];if(p){const t=function(t){const e=function(t){if(e.delaunay=null,e._data=t,"object"==typeof e._data&&"FeatureCollection"===e._data.type&&(e._data=e._data.features),"object"==typeof e._data){const t=e._data.map(t=>[e._vx(t),e._vy(t),t]).filter(t=>isFinite(t[0]+t[1]));e.points=t.map(t=>[t[0],t[1]]),e.valid=t.map(t=>t[2]),e.delaunay=Id(e.points)}return e};return e._vx=function(t){return"object"==typeof t&&"type"in t?Fl(t)[0]:0 in t?t[0]:void 0},e._vy=function(t){return"object"==typeof t&&"type"in t?Fl(t)[1]:1 in t?t[1]:void 0},e.x=function(t){return t?(e._vx=t,e):e._vx},e.y=function(t){return t?(e._vy=t,e):e._vy},e.polygons=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const n={type:"FeatureCollection",features:[]};return 0===e.valid.length||(e.delaunay.polygons.forEach((t,i)=>n.features.push({type:"Feature",geometry:t?{type:"Polygon",coordinates:[[...t,t[0]].map(t=>e.delaunay.centers[t])]}:null,properties:{site:e.valid[i],sitecoordinates:e.points[i],neighbours:e.delaunay.neighbors[i]}})),1===e.valid.length&&n.features.push({type:"Feature",geometry:{type:"Sphere"},properties:{site:e.valid[0],sitecoordinates:e.points[0],neighbours:[]}})),n},e.triangles=function(t){return void 0!==t&&e(t),!!e.delaunay&&{type:"FeatureCollection",features:e.delaunay.triangles.map((t,n)=>((t=t.map(t=>e.points[t])).center=e.delaunay.centers[n],t)).filter(t=>Nd(t)>0).map(t=>({type:"Feature",properties:{circumcenter:t.center},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}}))}},e.links=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const n=e.delaunay.edges.map(t=>mu(e.points[t[0]],e.points[t[1]])),i=e.delaunay.urquhart(n);return{type:"FeatureCollection",features:e.delaunay.edges.map((t,r)=>({type:"Feature",properties:{source:e.valid[t[0]],target:e.valid[t[1]],length:n[r],urquhart:!!i[r]},geometry:{type:"LineString",coordinates:[e.points[t[0]],e.points[t[1]]]}}))}},e.mesh=function(t){return void 0!==t&&e(t),!!e.delaunay&&{type:"MultiLineString",coordinates:e.delaunay.edges.map(t=>[e.points[t[0]],e.points[t[1]]])}},e.cellMesh=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const{centers:n,polygons:i}=e.delaunay,r=[];for(const e of i)if(e)for(let t=e.length,i=e[t-1],s=e[0],o=0;o<t;i=s,s=e[++o])s>i&&r.push([n[i],n[s]]);return{type:"MultiLineString",coordinates:r}},e._found=void 0,e.find=function(t,n,i){if(e._found=e.delaunay.find(t,n,e._found),!i||mu([t,n],e.points[e._found])<i)return e._found},e.hull=function(t){void 0!==t&&e(t);const n=e.delaunay.hull,i=e.points;return 0===n.length?null:{type:"Polygon",coordinates:[[...n.map(t=>i[t]),i[n[0]]]]}},t?e(t):e}(a).triangles(),e=new Map(a.map(([t,e],n)=>[`${t}-${e}`,n]));t.features.forEach(t=>{const n=t.geometry.coordinates[0].slice(0,3).reverse(),i=[];if(n.forEach(([t,n])=>{const r=`${t}-${n}`;e.has(r)&&i.push(e.get(r))}),3===i.length){if(i.some(t=>t<s.length)){if(!rf(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=$c.from(a);for(let e=0,n=t.triangles.length;e<n;e+=3){const n=[2,1,0].map(n=>t.triangles[e+n]),i=n.map(t=>a[t]);if(n.some(t=>t<s.length)){if(!rf([0,1].map(t=>ja(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=Vc(r);f=dc(t,e,2)}let y=n?[n[0],n[2]]:Va(a,t=>t[0]),m=n?[n[1],n[3]]:Va(a,t=>t[1]);if(i){const[t,e]=i([y[0],m[0]]),[n,r]=i([y[1],m[1]]);y=[t,n],m=[-e,-r]}const g=ef(y,[0,1]),x=ef(m,[0,1]),b=a.map(([t,e])=>{if(i){const[n,r]=i([t,e]);return[g(n),x(-r)]}return[g(t),x(e)]});return{contour:r,triangles:{points:a,indices:f,uvs:b}}}Jp=Qp({thousands:",",grouping:[3],currency:["$",""]}),Wp=Jp.format,Yp=Jp.formatPrefix;const af=(new Re).setAttribute?"setAttribute":"addAttribute";function hf(t,e,n){return Vc(t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=ka(t,i,0,e/Ca,!1);return[n.x,n.y,n.z]}if("sphere"===n){const n=ka(t,i,e-Ca,1,!0);return[n.x,n.y,n.z]}if("function"==typeof n){const[r,s]=n([t,i]);return[r,-s,e]}return[t,i,e]})))}function lf(t,e,n,i,r){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:hf([t.points],e,r).vertices,uvs:n}}const uf=({polygonGeoJson:t,startHeight:e,endHeight:n,curvatureResolution:i=1,hasSide:r=!0,hasBottom:s=!1,hasTop:o=!1,projection:a="sphere",bbox:h})=>{t.forEach(t=>{cc(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:u,triangles:c}=of(t,{resolution:i,bbox:h,projection:l});let d,p={};r&&(p=function(t,e,n,i){const{vertices:r,holes:s}=hf(t,e,i),{vertices:o}=hf(t,n,i),a=Ga([o,r]),h=Math.round(o.length/3),l=new Set(s);let u=0;const c=[];for(let p=0;p<h;p++){let t=p+1;if(t===h)t=u;else if(l.has(t)){const e=t;t=u,u=e}c.push(p,p+h,t+h),c.push(t+h,t,p)}const d=[];for(let p=1;p>=0;p--)for(let t=0;t<h;t+=1)d.push(t/(h-1),p);return{indices:c,vertices:a,uvs:d,topVerts:o}}(u,null!=e?e:n,null!=n?n:e,a),d=p.topVerts);let f=[];(s||o)&&(f=Ga(c.uvs));let y={};s&&(y=lf(c,e,f,!1,a));let m={};return o&&(m=lf(c,n,f,!0,a)),{contour:u,triangles:c,sideTorso:p,bottomCap:y,topCap:m,topVerts:d}};class cf extends Re{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=u(u({},{polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,projection:"sphere",resetCenter:!1}),e);const{hasTop:n,topFirst:i,hasBottom:r,hasSide:s}=this.parameters,{sideTorso:o,bottomCap:a,topCap:h}=uf(u({},this.parameters));let l=[],c=[],d=[],p=0;const f=t=>{const e=Math.round(l.length/3),n=d.length;l=l.concat(t.vertices),c=c.concat(t.uvs),d=d.concat(e?t.indices.map(t=>t+e):t.indices),this.addGroup(n,d.length-n,p++)};n&&i&&f(h),s&&f(o),r&&f(a),n&&!i&&f(h),this.parameters.resetCenter&&l.length>0&&(this.userData.rtcPositionsVertices=new _e(new Float64Array(l),3)),this.setIndex(d),this[af]("position",new Pe(l,3)),this[af]("uv",new Pe(c,2)),this.computeVertexNormals()}}function df(t){return Object.getOwnPropertyNames(t).reduce(function(e,n){return Object.defineProperty(e,n,{value:t[n],enumerable:!0})},{})}(t=>{const e={run(t,e){const n=new Function("return ("+t+").apply(null, arguments);");return n.apply(n,e)},methods:()=>Object.keys(e)};addEventListener("message",t=>((t,e,n)=>new Promise((i,r)=>{var s=t=>{try{a(n.next(t))}catch(e){r(e)}},o=t=>{try{a(n.throw(t))}catch(e){r(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(s,o);a((n=n.apply(t,e)).next())}))(void 0,[t],function*({data:t}){try{const n=e[t.method];if(!n)throw new Error(\'Unknown method "\'+t.method+\'"\');{const e=yield n.apply(n,t.params);e.transfer&&e.message?postMessage({id:t.id,result:e.message,error:null},e.transfer):postMessage({id:t.id,result:e,error:null})}}catch(n){postMessage({id:t.id,result:null,error:df(n)})}})),Object.keys(t).forEach(n=>{e[n]=t[n]}),postMessage("ready")})({extrudePolygon:({coordinates:t,lengths:e,metaLength:n,split:i,bbox:r,projection:s,useGroups:o,hasTop:a,hasBottom:h,hasSide:l,splitPolygons:d,topSegments:p})=>{const f=s&&nc(s),{coordinatesArr:y,metaArray:m}=oc({coordinates:t,lengths:e,metaLength:n});let g,x=y.map(t=>sc(t,f)),b=m;if(d){const t=hc(x,d,m);x=t.splitPolygons,b=t.splitMeta}if(r){const t=-180===r[0]&&180===r[2]&&(null==s?void 0:s.rotate),[e,n]=function(t,e,n=0){const[i,r,s,o]=t;let a=1/0,h=1/0,l=-1/0,u=-1/0;for(let c=0;c<=n;c++){const t=n&&c/n;sc([[i+t*(s-i),r],[i+t*(s-i),o],[i,r+t*(o-r)],[s,r+t*(o-r)]],e).forEach(t=>{a=Math.min(a,t.x),h=Math.min(h,t.y),l=Math.max(l,t.x),u=Math.max(u,t.y)})}return[[a,h],[l,u]]}(r,t?nc(c(u({},s),{rotate:void 0})):f,"winkel3"===(null==s?void 0:s.projectionType)?10:0);g=new K(new N(e[0],e[1],0),new N(n[0],n[1],0))}const w=x.map((t,e)=>{const n=b[e][0],r=b[e][1]||0,s=b[e][2]||1,o=Pa({points:t,split:i,sideRepeat:s,depth:n,hasTop:a,hasBottom:h,hasSide:l,box3:g,topSegments:p});if(r){const t=o.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+r);t.needsUpdate=!0}return o});return ac(w,o)},line:({coordinates:t,lengths:e,metaLength:n,projection:i,useGroups:r,splitPolygons:s})=>{const o=i&&nc(i),{coordinatesArr:a,metaArray:h}=oc({coordinates:t,lengths:e,metaLength:n});let l=a.map(t=>sc(t,o)),u=h;if(s){const t=hc(l,s,u);l=t.splitPolygons,u=t.splitMeta}const c=l.map((t,e)=>{const n=u[e][0]||1;return uc({nodes:t,setPointWidth:()=>n})});return ac(c,r)},line2:({coordinates:t,lengths:e,metaLength:n,projection:i,useGroups:r,splitPolygons:s})=>{const o=i&&nc(i),{coordinatesArr:a,metaArray:h}=oc({coordinates:t,lengths:e,metaLength:n});let l=a.map(t=>sc(t,o));if(s){l=hc(l,s,h).splitPolygons}const u=l.map((t,e)=>(t=>{const{points:e}=t,n=e.reduce((t,n,i)=>(i<e.length-1&&t.push(n,e[i+1]),t),[]);return(new Re).setFromPoints(n)})({points:t.map(t=>new N(t.x,t.y,0))}));return ac(u,r)},conicPolygon:({coordinates:t,lengths:e,metaLength:n,useGroups:i,hasTop:r,topFirst:s,hasBottom:o,hasSide:a,rtc:h,projection:l,curvatureResolution:p,bbox:f})=>{let y;y=l&&"object"==typeof l?nc(l):l||"sphere";const{coordinatesArr:m,metaArray:g}=oc({coordinates:t,lengths:e,metaLength:n}),x=m.map((t,e)=>{const n=g[e][0],i=g[e][1]||0;return(t=>{const e=t,{coordinate:n,startHeight:i,height:r}=e,s=d(e,["coordinate","startHeight","height"]);let o=i||0;return void 0!==i&&void 0!==r&&(o=i+r),new cf([n],c(u({},s),{startHeight:i,endHeight:o}))})({coordinate:t,projection:y,startHeight:i,height:n,hasTop:null==r||r,topFirst:null!=s&&s,hasBottom:null==o||o,hasSide:null==a||a,curvatureResolution:null!=p?p:1,bbox:f,resetCenter:null!=h&&h})});return ac(x,i,null!=h&&h)},conicLine:({coordinates:t,lengths:e,metaLength:n,useGroups:i,projection:r="sphere",rtc:s})=>{const{coordinatesArr:o,metaArray:a}=oc({coordinates:t,lengths:e,metaLength:n}),h=o.map((t,e)=>{const n=a[e][1]||0;return uf({polygonGeoJson:[t],startHeight:n,projection:r}).topVerts}).map((t,e)=>{const n=a[e][0];return uc({nodes:t,setPointWidth:()=>n,resetCenter:null!=s&&s})});return ac(h,i,null!=s&&s)}})}();\n',ur="undefined"!=typeof self&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",cr],{type:"text/javascript;charset=utf-8"});function dr(t){let e;try{if(e=ur&&(self.URL||self.webkitURL).createObjectURL(ur),!e)throw"";const n=new Worker(e,{name:null==t?void 0:t.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch(n){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(cr),{name:null==t?void 0:t.name})}}class pr{constructor(t){u(this,"pluginName","worker"),u(this,"options"),u(this,"pencil"),u(this,"pool"),u(this,"bufferGeometryLoader",new It),u(this,"cacheManager"),this.options=h({dbName:"pencil_cache",cacheVersion:"1",maxCacheSize:100},t),this.cacheManager=new un({dbName:this.options.dbName,maxCacheSize:this.options.maxCacheSize,cacheVersion:this.options.cacheVersion})}install(t){this.pencil=t;const e=new Ie(dr,{maxWorkers:this.options.maxWorkers});this.pool=e}geoGeometry(t,e){return d(this,null,function*(){const{mesaage:n,coordinatesArr:i,metaArray:s,cacheKey:r,userData:o,cacheVersion:a,cb:l,useFloat64Array:c}=h(h({},this.options),e),u=this.pool,{flat:d,lengths:p}=this.flattenCoordinates(i,s,c),{err:f,res:m}=yield u.exec(t,[h({coordinates:d,lengths:p,metaLength:s?s[0].length:0},n)],{on:()=>{},transfer:[d.buffer]},!0);if(f)throw f;const y=lr(m);return Object.assign(y.userData,h({},o)),l&&(yield l(y)),r&&this.cacheManager.addToCache(r,a,h({attributes:m},o)),y})}getCachedGeometry(t){return d(this,null,function*(){const{cacheKey:e,cacheVersion:n}=t;if(e){const t=yield this.cacheManager.get(e,n);return t&&Array.isArray(t)?(this.cacheManager.recordMetadataUpdate(e,t.length),t.map(t=>{const e=t,{attributes:n}=e,i=c(e,["attributes"]),s=lr(n);return Object.assign(s.userData,h({},i)),s})):[]}return[]})}saveCache(){return d(this,null,function*(){return yield this.cacheManager.saveCache()})}flushMetadata(){return d(this,null,function*(){return yield this.cacheManager.flushMetadata()})}getCacheStats(){return d(this,null,function*(){return yield this.cacheManager.getCacheStats()})}clearCache(){return d(this,null,function*(){return yield this.cacheManager.clearCache()})}checkStorageQuota(){return d(this,null,function*(){return yield this.cacheManager.checkStorageQuota()})}flattenCoordinates(t,e,n=!1){const i=[];let s=0;for(const h of t){const t=h.length;i.push(t),s+=t}const r=e?e.reduce((t,e)=>t+e.length,0):0,o=n?new Float64Array(2*s+r):new Float32Array(2*s+r);let a=0;for(const h of t)for(const[t,e]of h)o[a++]=t,o[a++]=e;if(e)for(const h of e)for(const t of h)o[a++]=t;return{flat:o,lengths:i}}dispose(){this.cacheManager.dispose(),this.pool.dispose(),this.pool.workers.length=0}}const fr=Us.ACTION;export{Ln as BaseObject,Zn as ConicPolygon,Yn as Ellipsoid,Qn as ExtrudePolygon,ei as Group,ni as Light,ci as Line,Ei as Line2,Gt as Line2Material,$t as LineSegmentsGeometry,ii as MeshLineGeometry,ri as MeshLineMaterial,oi as MeshLineRaycast,Pi as Node,ar as Pencil,Ni as Pie,Ke as ResourceTracker,pr as Wk,fr as cameraControlsAction,ar as default,hr as effect,ti as getSplitTexture,Nn as utils};
|
|
1
|
+
var t=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,s=Object.prototype.hasOwnProperty,r=Object.prototype.propertyIsEnumerable,o=Math.pow,a=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,h=(t,e)=>{for(var n in e||(e={}))s.call(e,n)&&a(t,n,e[n]);if(i)for(var n of i(e))r.call(e,n)&&a(t,n,e[n]);return t},l=(t,i)=>e(t,n(i)),c=(t,e)=>{var n={};for(var o in t)s.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&i)for(var o of i(t))e.indexOf(o)<0&&r.call(t,o)&&(n[o]=t[o]);return n},u=(t,e,n)=>a(t,"symbol"!=typeof e?e+"":e,n),d=(t,e,n)=>new Promise((i,s)=>{var r=t=>{try{a(n.next(t))}catch(e){s(e)}},o=t=>{try{a(n.throw(t))}catch(e){s(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(r,o);a((n=n.apply(t,e)).next())});import{EventEmitter as p}from"events";import f from"deepmerge";import m from"stats-gl";import{Vector3 as y,Matrix4 as g,PerspectiveCamera as x,Material as b,Object3D as v,Texture as w,Sphere as _,Ray as M,BufferGeometry as S,Float32BufferAttribute as A,PointsMaterial as T,Points as C,SRGBColorSpace as z,NoColorSpace as E,LinearSRGBColorSpace as O,MathUtils as P,Vector2 as N,Box3 as B,InstancedMesh as k,Quaternion as L,Group as R,Mesh as U,Sprite as j,BufferAttribute as D,MeshStandardMaterial as F,Shape as I,ShapeUtils as V,SplineCurve as W,QuadraticBezierCurve3 as H,QuadraticBezierCurve as q,LineCurve3 as Z,LineCurve as Y,EllipseCurve as G,CubicBezierCurve3 as X,CubicBezierCurve as $,CatmullRomCurve3 as J,ArcCurve as K,PlaneGeometry as Q,CanvasTexture as tt,AmbientLight as et,DirectionalLight as nt,PointLight as it,SpotLight as st,HemisphereLight as rt,RectAreaLight as ot,ShaderMaterial as at,Color as ht,LineSegments as lt,Vector4 as ct,Line3 as ut,InstancedInterleavedBuffer as dt,InterleavedBufferAttribute as pt,MeshBasicMaterial as ft,UniformsUtils as mt,RawShaderMaterial as yt,SpriteMaterial as gt,WebGLRenderTarget as xt,HalfFloatType as bt,Layers as vt,Raycaster as wt,Spherical as _t,AxesHelper as Mt,CameraHelper as St,PointLightHelper as At,DirectionalLightHelper as Tt,SpotLightHelper as Ct,HemisphereLightHelper as zt,Box3Helper as Et,Scene as Ot,Camera as Pt,FileLoader as Nt,Loader as Bt,VideoTexture as kt,LoadingManager as Lt,TextureLoader as Rt,DataTexture as Ut,WebGLRenderer as jt,REVISION as Dt,Timer as Ft,BufferGeometryLoader as It}from"three";import Vt from"three/examples/jsm/libs/tween.module.js";import{EffectComposer as Wt}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as Ht}from"three/examples/jsm/postprocessing/RenderPass.js";import{SSAOPass as qt}from"three/examples/jsm/postprocessing/SSAOPass.js";import{UnrealBloomPass as Zt}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";import{LineMaterial as Yt}from"three/examples/jsm/lines/LineMaterial.js";import{LineMaterial as Gt}from"three/examples/jsm/lines/LineMaterial.js";import{LineSegmentsGeometry as Xt}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{LineSegmentsGeometry as $t}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{CSS2DObject as Jt,CSS2DRenderer as Kt}from"three/examples/jsm/renderers/CSS2DRenderer.js";import{CSS3DObject as Qt,CSS3DSprite as te,CSS3DRenderer as ee}from"three/examples/jsm/renderers/CSS3DRenderer.js";import{createStore as ne,getMany as ie,setMany as se,keys as re,delMany as oe,get as ae,clear as he}from"idb-keyval";import{geoProjection as le,geoEquirectangular as ce,geoMercator as ue,geoBounds as de,geoContains as pe,geoDistance as fe,geoInterpolate as me}from"d3-geo";import{mergeAttributes as ye,mergeGroups as ge}from"three/examples/jsm/utils/BufferGeometryUtils";import xe from"@turf/boolean-clockwise";import{merge as be,mean as ve,extent as we}from"d3-array";import _e,{flatten as Me}from"earcut";import Se from"delaunator";import Ae from"@turf/boolean-point-in-polygon";import{geoVoronoi as Te}from"d3-geo-voronoi";import{scaleLinear as Ce}from"d3-scale";import{Brush as ze,Evaluator as Ee,INTERSECTION as Oe}from"three-bvh-csg";import{RectAreaLightUniformsLib as Pe}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{LineSegments2 as Ne}from"three/examples/jsm/lines/LineSegments2.js";import{LineSegmentsGeometry as Be}from"three/examples/jsm/lines/LineSegmentsGeometry";import{ShaderPass as ke}from"three/examples/jsm/postprocessing/ShaderPass.js";import{OutputPass as Le}from"three/examples/jsm/postprocessing/OutputPass.js";import{FullScreenQuad as Re}from"three/examples/jsm/postprocessing/Pass.js";import{RectAreaLightHelper as Ue}from"three/examples/jsm/helpers/RectAreaLightHelper.js";import{ViewHelper as je}from"three/examples/jsm/helpers/ViewHelper.js";import{generateUUID as De,makePromiseCreator as Fe,WorkerPool as Ie}from"esus-lite";import{DRACOLoader as Ve}from"three/examples/jsm/loaders/DRACOLoader.js";import{EXRLoader as We}from"three/examples/jsm/loaders/EXRLoader.js";import{GLTFLoader as He}from"three/examples/jsm/loaders/GLTFLoader.js";import{LottieLoader as qe}from"three/examples/jsm/loaders/LottieLoader.js";import{TransformControls as Ze}from"three/examples/jsm/controls/TransformControls.js";const Ye=!1;class Ge{constructor(){u(this,"mask"),this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}isEnabled(t){return!!(this.mask&1<<t)}getMinDisabledLayer(){const t=~this.mask;if(!(4294967295&t))return null;const e=t&-t;return 31-Math.clz32(e>>>0)}}class Xe{constructor(){u(this,"event",new p),u(this,"controllerMap",/* @__PURE__ */new Map),u(this,"activeIndex",-1),u(this,"controller"),u(this,"activeControllerSet",/* @__PURE__ */new Set)}addController(t,e){const n=new Ge;return n.disableAll(),void 0!==e&&n.set(e),this.controllerMap.set(t,n),e===this.activeIndex&&this.activeControllerSet.add(t),t}removePage(t,e){this.controllerMap.forEach((n,i)=>{n.isEnabled(t)&&(n.disable(t),0===n.mask&&(null==e||e(i),this.controllerMap.delete(i),this.activeControllerSet.delete(i)))})}setPageActive(t,e){this.activeIndex=t,this.activeControllerSet.clear();const n=Array.from(this.controllerMap.entries()).map(([n,i])=>{const s=i.isEnabled(t);if(null==e||e(n,s),s)return this.activeControllerSet.add(n),n}).filter(Boolean);this.controller=n[0],this.event.emit("pageChange",this.controller)}update(t,e){this.activeControllerSet.forEach(n=>{var i;null==(i=n.update)||i.call(n,t,e)})}dispose(){this.controllerMap.forEach((t,e)=>{t.set(0)}),this.removePage(0),this.controllerMap.clear(),this.event.removeAllListeners(),this.activeControllerSet.clear()}}const $e={fov:45,near:1,far:1e3,up:new y(0,1,0)};class Je extends Xe{constructor(t){super(),u(this,"width",0),u(this,"height",0),u(this,"_cachedMatrixWorld",new g),u(this,"_cachedMatrixWorldInverse",new g),u(this,"_lastFov",-1),u(this,"_lastAspect",-1),this.width=t.width,this.height=t.height}get camera(){return this.controller}addPerspectiveCamera(t=$e,e){const{fov:n,far:i,near:s,up:r,aspect:o}=t,a=null!=o?o:this.width/this.height,h=new x(n,a,s,i);return h.up=r,this.addController(h,e)}setPageActive(t){super.setPageActive(t,(t,e)=>{e&&this.setAspect(this.width/this.height,t)})}setSize(t,e){this.width=t,this.height=e,this.setAspect(t/e)}setAspect(t,e){const n=e||this.camera;n.aspect!==t&&(n.aspect=t,n.updateProjectionMatrix())}cloneCamera(t){const e=this.addPerspectiveCamera({fov:this.camera.fov,aspect:this.camera.aspect,near:this.camera.near,far:this.camera.far,up:this.camera.up},t);return e.position.copy(this.camera.position),e}sync(t){const e=this.camera;if("PerspectiveCamera"===t.type){const n=t,i=!e.position.equals(n.position),s=e.quaternion.x!==n.quaternion.x||e.quaternion.y!==n.quaternion.y||e.quaternion.z!==n.quaternion.z||e.quaternion.w!==n.quaternion.w;(i||s||e.far!==n.far||e.near!==n.near||e.fov!==n.fov||e.aspect!==n.aspect)&&e.copy(n)}else{const n=t,i=n.viewMatrix,s=n.inverseViewMatrix,{width:r,height:o}=this,a=r/o,h=this._lastFov!==n.fov,l=this._lastAspect!==a;(h||l)&&(e.fov=n.fov,e.aspect=a,e.updateProjectionMatrix(),this._lastFov=n.fov,this._lastAspect=a),this._cachedMatrixWorld.set(s[0],s[4],s[8],s[12],s[1],s[5],s[9],s[13],s[2],s[6],s[10],s[14],s[3],s[7],s[11],s[15]),this._cachedMatrixWorldInverse.set(i[0],i[4],i[8],i[12],i[1],i[5],i[9],i[13],i[2],i[6],i[10],i[14],i[3],i[7],i[11],i[15]);const c=!e.matrixWorld.equals(this._cachedMatrixWorld),u=!e.matrixWorldInverse.equals(this._cachedMatrixWorldInverse);(c||u)&&(e.matrixAutoUpdate=!1,c&&e.matrixWorld.copy(this._cachedMatrixWorld),u&&e.matrixWorldInverse.copy(this._cachedMatrixWorldInverse))}}}class Ke{constructor(){u(this,"resources",/* @__PURE__ */new Set),u(this,"disposeMaterial",!0),u(this,"disposeVideo",!0)}track(t){if(!t)return t;if(Array.isArray(t))return t.forEach(t=>{this.track(t)}),t;if(!this.disposeMaterial&&t instanceof b)return t;if(t instanceof Ln?(t.disposeTrack&&t.object3d?this.track(t.object3d):this.resources.add(t),Object.values(t.materialList).map(t=>this.track(t))):(t instanceof v||Reflect.has(t,"dispose"))&&this.resources.add(t),t instanceof Ln)t.children.forEach(t=>{t.disposeTrack=!1}),this.track(t.children);else if(t instanceof v){const e=t;this.track(e.geometry),this.track(e.material),this.track(e.children)}else if(t instanceof b){for(const n of Object.values(t))n instanceof w&&this.track(n);const e=t;if(e.uniforms)for(const t of Object.values(e.uniforms))if(t){const e=t.value;(e instanceof w||Array.isArray(e))&&this.track(e)}}else this.disposeVideo&&t.isVideoTexture&&t.source.data&&this.resources.add(t.source.data);return t}dispose(){const t=[];for(const e of this.resources)e instanceof v?t.push(e):e instanceof HTMLVideoElement&&e.pause(),Reflect.has(e,"dispose")&&e.dispose();t.forEach(t=>{t.removeFromParent()}),t.length=0,this.resources.clear()}}const Qe=/* @__PURE__ */new g,tn=/* @__PURE__ */new M,en=/* @__PURE__ */new _,nn=/* @__PURE__ */new y;function sn(t,e){const n=this.geometry,i=this.matrixWorld,s=t.params.Points.threshold,r=n.drawRange;null===n.boundingSphere&&n.computeBoundingSphere(),en.copy(n.boundingSphere),en.applyMatrix4(i),en.radius+=s,Qe.copy(i).invert(),tn.copy(t.ray).applyMatrix4(Qe);const o=s/((this.scale.x+this.scale.y+this.scale.z)/3),a=n.index,h=n.attributes.position;if(null!==a){for(let n=Math.max(0,r.start),s=Math.min(a.count,r.start+r.count);n<s;n++){const s=a.getX(n);nn.fromBufferAttribute(h,s),rn(nn,s,o,i,t,e,this)}}else{for(let n=Math.max(0,r.start),s=Math.min(h.count,r.start+r.count);n<s;n++)nn.fromBufferAttribute(h,n),rn(nn,n,o,i,t,e,this)}}function rn(t,e,n,i,s,r,o){const a=new y;tn.closestPointToPoint(t,a),a.applyMatrix4(i);const h=s.ray.origin.distanceTo(t),l=a.distanceTo(t),c=Math.asin(l/h);if(c<n){if(h<s.near||h>s.far)return;r.push({distance:h,distanceToRay:l,angleToRay:c,point:a,index:e,face:null,object:o})}}const on={linearSRGB:O,sRGB:z,none:E},an={map:on.sRGB,emissiveMap:on.sRGB,sheenColorMap:on.sRGB,specularColorMap:on.sRGB,normalMap:on.none,bumpMap:on.none,displacementMap:on.none,roughnessMap:on.none,metalnessMap:on.none,aoMap:on.none,lightMap:on.none,alphaMap:on.none,specularIntensityMap:on.none,clearcoatMap:on.none,clearcoatNormalMap:on.none,clearcoatRoughnessMap:on.none,iridescenceMap:on.none,iridescenceThicknessMap:on.none,sheenRoughnessMap:on.none,specularMap:on.none,thicknessMap:on.none,transmissionMap:on.none},hn=[".hdr",".exr",".rgbe"];function ln(t){return function(t){var e;if(t.userData&&"boolean"==typeof t.userData.isHDR)return t.userData.isHDR;if(t.colorSpace===O)return!0;if(null==(e=t.image)?void 0:e.data)return!0;if(!t.image||!t.image.src)return!1;const n="string"==typeof t.image.src?t.image.src:"";return hn.some(t=>n.toLowerCase().includes(t))}(t)?on.linearSRGB:on.sRGB}function cn({node:t,material:e,texture:n}){const i=function({node:t,material:e,texture:n}){if(n)return[{map:n}];if(e)return Array.isArray(e)?e:[e];if(null==t?void 0:t.material)return Array.isArray(t.material)?t.material:[t.material];return[]}({node:t,material:e,texture:n});i.forEach(t=>function(t){Object.keys(an).forEach(e=>{const n=t;n[e]&&(n[e].colorSpace=an[e])});const e=t;e.envMap&&(e.envMap.colorSpace=ln(e.envMap))}(t))}class un{constructor(t){u(this,"store"),u(this,"metadataStore"),u(this,"pendingMetadataUpdates",/* @__PURE__ */new Map),u(this,"cacheObj",{}),u(this,"options"),this.options=t,this.store=ne(t.dbName,"keyval"),this.metadataStore=ne(`${t.dbName}_metadata`,"keyval")}addToCache(t,e,n){this.cacheObj[t]||(this.cacheObj[t]={[e]:[]}),this.cacheObj[t][e]||(this.cacheObj[t][e]=[]),this.cacheObj[t][e].push(n)}recordMetadataUpdate(t,e){this.pendingMetadataUpdates.set(t,{size:e,timestamp:Date.now()})}flushMetadata(){return d(this,null,function*(){if(0===this.pendingMetadataUpdates.size)return;const t=Array.from(this.pendingMetadataUpdates.keys()),e=yield ie(t,this.metadataStore),n=[];for(let i=0;i<t.length;i++){const s=t[i],r=this.pendingMetadataUpdates.get(s);if(!r)continue;const o=e[i],a={lastAccessed:r.timestamp,accessCount:o?o.accessCount+1:1,size:r.size};n.push([s,a])}yield se(n,this.metadataStore),this.pendingMetadataUpdates.clear()})}evictLRUCache(){return d(this,null,function*(){const t=yield re(this.store);if(t.length>=this.options.maxCacheSize){const e=yield ie(t,this.metadataStore),n=[];for(let r=0;r<t.length;r++){const i=e[r];i&&n.push({key:t[r],metadata:i})}n.sort((t,e)=>t.metadata.accessCount!==e.metadata.accessCount?t.metadata.accessCount-e.metadata.accessCount:t.metadata.lastAccessed-e.metadata.lastAccessed);const i=Math.max(1,Math.floor(.1*this.options.maxCacheSize)),s=n.slice(0,i).map(t=>t.key);yield oe(s,this.store),yield oe(s,this.metadataStore)}})}get(t,e){return d(this,null,function*(){const n=yield ae(t,this.store),i=e||this.options.cacheVersion;return null==n?void 0:n[i]})}saveCache(){return d(this,null,function*(){var t,e;try{yield this.flushMetadata(),yield this.evictLRUCache();const e=Object.entries(this.cacheObj);if(0===e.length)return;yield se(e,this.store);const n=this.options.cacheVersion,i=e.map(([t])=>t),s=yield ie(i,this.metadataStore),r=[];for(let o=0;o<e.length;o++){const[i,a]=e[o],h=(null==(t=a[n])?void 0:t.length)||0,l=s[o],c={lastAccessed:Date.now(),accessCount:l?l.accessCount+1:1,size:h};r.push([i,c])}yield se(r,this.metadataStore),this.cacheObj={}}catch(n){if("QuotaExceededError"!==n.name&&!(null==(e=n.message)?void 0:e.includes("NO_SPACE")))throw n;console.error("存储空间不足,尝试清理旧缓存..."),yield this.clearCache()}})}getCacheStats(){return d(this,null,function*(){const t=yield re(this.store),e={total:t.length,maxSize:this.options.maxCacheSize,usage:t.length/this.options.maxCacheSize*100,items:[]},n=yield ie(t,this.metadataStore);for(let i=0;i<t.length;i++){const s=n[i];s&&e.items.push({key:t[i],metadata:s})}return e})}clearCache(){return d(this,null,function*(){yield he(this.store),yield he(this.metadataStore),this.cacheObj={}})}checkStorageQuota(){return d(this,null,function*(){var t;if(null==(t=navigator.storage)?void 0:t.estimate){const t=yield navigator.storage.estimate(),e=t.usage||0,n=t.quota||0,i=e/n*100;return console.log(`存储使用: ${(e/1024/1024).toFixed(2)}MB / ${(n/1024/1024).toFixed(2)}MB (${i.toFixed(2)}%)`),i>80&&console.warn("存储空间不足,建议清理缓存"),{usage:e,quota:n,percentUsed:i}}return null})}dispose(){this.cacheObj={},this.pendingMetadataUpdates.clear()}}const dn={a:6378137,b:6356752.314245179,f:1/298.257223563};function pn(t,e,n=0,i=1,s=!1){const r=P.degToRad(t),o=P.degToRad(e),a=Math.cos(o),h=Math.sin(o),l=Math.cos(r),c=Math.sin(r);let u,d,p;if(s){const t=(dn.a+n)*i;u=t*a*c,d=t*h,p=t*a*l}else{const t=dn.a,e=dn.b,s=t*t,r=(s-e*e)/s,o=t/Math.sqrt(1-r*h*h);u=(o+n)*a*c*i,d=(o*(1-r)+n)*h*i,p=(o+n)*a*l*i}return new y(u,d,p)}var fn=Math.abs,mn=Math.cos,yn=Math.sin,gn=1e-6,xn=Math.PI,bn=xn/2;function vn(t){return t>1?0:t<-1?xn:Math.acos(t)}function wn(t){return t>0?Math.sqrt(t):0}function _n(t,e){var n=mn(e),i=function(t){return t?t/Math.sin(t):1}(vn(n*mn(t/=2)));return[2*n*yn(t)*i,yn(e)*i]}function Mn(t,e){var n=_n(t,e);return[(n[0]+t/bn)/2,(n[1]+e)/2]}Mn.invert=(t,e)=>{var n=t,i=e,s=25;do{var r,o=mn(i),a=yn(i),h=yn(2*i),l=a*a,c=o*o,u=yn(n),d=mn(n/2),p=yn(n/2),f=p*p,m=1-c*d*d,y=m?vn(o*d)*wn(r=1/m):r=0,g=.5*(2*y*o*p+n/bn)-t,x=.5*(y*a+i)-e,b=.5*r*(c*f+y*o*d*l)+.5/bn,v=r*(u*h/4-y*a*p),w=.125*r*(h*p-y*a*c*u),_=.5*r*(l*d+y*f*o)+.5,M=v*w-_*b,S=(x*v-g*_)/M,A=(g*w-x*b)/M;n-=S,i-=A}while((fn(S)>gn||fn(A)>gn)&&--s>0);return[n,i]};const Sn={mercator:ue,equirectangular:ce,winkel3:function(){return le(Mn).scale(158.837)}},An={};function Tn(t){return"[object Object]"===Object.prototype.toString.call(t)}function Cn(t){if(!1===Tn(t))return!1;const e=t.constructor;if(void 0===e)return!0;const n=e.prototype;return!1!==Tn(n)&&!1!==n.hasOwnProperty("isPrototypeOf")}const zn=t=>t instanceof y?t:new y(...t);const En=/* @__PURE__ */new Map,On=(t={})=>({generateTopUV(e,n,i,s,r){const o=n[3*i],a=n[3*i+1],h=n[3*s],l=n[3*s+1],c=n[3*r],u=n[3*r+1];let d;if(En.has(e))d=En.get(e);else{let n=t.box3;if(!n){n=new B;const t=e.parameters.shapes.getPoints().flatMap(t=>[t.x,t.y,0]);n.setFromArray(t)}const i=n.getSize(new y);t.split&&(i.y/=t.split),d={box:n,size:i},En.set(e,d)}const{box:p,size:f}=d,m=t.split?1-t.split:0;return[new N((o-p.min.x)/f.x,(a-p.min.y)/f.y+m),new N((h-p.min.x)/f.x,(l-p.min.y)/f.y+m),new N((c-p.min.x)/f.x,(u-p.min.y)/f.y+m)]},generateSideWallUV(e,n,i,s,r,o){const a=n[3*i],h=n[3*i+1],l=n[3*i+2],c=n[3*s],u=n[3*s+1],d=n[3*s+2],p=n[3*r],f=n[3*r+1],m=n[3*r+2],g=n[3*o],x=n[3*o+1],b=n[3*o+2];let v;if(En.has(n))v=En.get(n);else{const e=new B;e.setFromArray(n);const i=e.getSize(new y);t.split&&(i.z/=1-t.split),t.sideRepeat&&(i.z/=t.sideRepeat),v={box:e,size:i},En.set(n,v)}const{box:w,size:_}=v;return Math.abs(h-u)<Math.abs(a-c)?[new N((a-w.min.x)/_.x,(l-w.min.z)/_.z),new N((c-w.min.x)/_.x,(d-w.min.z)/_.z),new N((p-w.min.x)/_.x,(m-w.min.z)/_.z),new N((g-w.min.x)/_.x,(b-w.min.z)/_.z)]:[new N((h-w.min.y)/_.y,(l-w.min.z)/_.z),new N((u-w.min.y)/_.y,(d-w.min.z)/_.z),new N((f-w.min.y)/_.y,(m-w.min.z)/_.z),new N((x-w.min.y)/_.y,(b-w.min.z)/_.z)]}}),Pn=()=>{En.clear()},Nn={applyTextureColorSpace:cn,CacheManager:un,cartographicToCartesian:pn,WGS84:dn,getProjection:t=>{var e,n,i;const s=JSON.stringify(t);if(An[s])return An[s];const r=Sn[null!=(e=t.projectionType)?e:"mercator"]().center(t.center).scale(t.scale).translate(null!=(n=t.translate)?n:[0,0]).precision(null!=(i=t.precision)?i:.1);return t.rotate&&r.rotate(t.rotate),An[s]=r,r},isPlainObject:Cn,parseVector2:t=>t instanceof N?t:new N(...t),parseVector3:zn,claerUVGenerator:Pn,getUVGenerator:On,enableMultiLevelRTC:function(t,e){return e?"MeshLineMaterial"===t.type?(t.uniforms.globalRTCCenter={value:new y(e.x,e.y,e.z)},t.uniforms.uRTCMode.value=2,t):(t.onBeforeCompile=t=>{t.uniforms.globalRTCCenter={value:new y(e.x,e.y,e.z)},t.vertexShader=t.vertexShader.replace("#include <common>","\n #include <common>\n uniform vec3 globalRTCCenter;\n attribute vec3 localCenter;\n "),t.vertexShader=t.vertexShader.replace("#include <begin_vertex>","\n #include <begin_vertex>\n // 多级 RTC: position 相对于 localCenter,localCenter 相对于 globalRTCCenter\n transformed = transformed + localCenter + globalRTCCenter;\n ")},t):t}};let Bn=class{constructor(){u(this,"lead"),u(this,"onPointerIndex",[])}onPointerEvent(t,e){const n=this.lead.handlePick([this],t,e);this.onPointerIndex.push(n)}onClick(t){this.onPointerEvent("click",t)}onPointerEnter(t){this.onPointerEvent("enter",t)}onPointerEnterOnStop(t){this.onPointerEvent("enterOnStop",t)}onPointerLeave(t){this.onPointerEvent("leave",t)}onPointerMove(t){this.onPointerEvent("move",t)}onPointerDown(t){this.onPointerEvent("down",t)}dispose(){this.onPointerIndex.forEach(t=>{this.lead.removePick(t)})}};class kn extends Bn{constructor(){super(...arguments),u(this,"userData",{}),u(this,"materialList",{}),u(this,"useMaterialType","origin"),u(this,"disposeMaterialIfNotUsed",!0)}cloneMaterial(){const t=this.object3d;if(!t||!t.material)return;const e=t.material;if(Array.isArray(e))return e.map(t=>{const e=t.userData;t.userData={};const n=t.clone();return t.userData=e,n});{const t=e.userData;e.userData={};const n=e.clone();return e.userData=t,n}}setMaterialList(t,e){const n=this.object3d;if(!n||!n.material)return;this.materialList.origin||(this.materialList.origin=n.material);const i="clone"===e?this.cloneMaterial():Array.isArray(e)?e.slice():e;return this.materialList[t]=i,i}useMaterial(t){const e=this.object3d;e&&e.material&&this.useMaterialType!==t&&this.materialList[t]&&(this.useMaterialType=t,e.material=this.materialList[t])}useMListById(t,e){if(!this.mList)return;const n=this.mList.get(t);if(!n)return;const i=this.object3d;Array.isArray(i.material)&&void 0!==e?i.material[e]=n:i.material=n}useMListByName(t,e){if(!this.mList)return;const n=this.mList.getKeyByName(t);n&&this.useMListById(n,e)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Ln extends kn{constructor(){super(...arguments),u(this,"key",""),u(this,"keyType"),u(this,"keyUId"),u(this,"keyName"),u(this,"objectType","BaseObject"),u(this,"objectOptions"),u(this,"userData",{}),u(this,"isPrefab",!1),u(this,"isInstantiate",!1),u(this,"isBloom",!1),u(this,"isBaseObject",!0),u(this,"disposeTrack",!0),u(this,"isDispose",!1)}get parent(){const t=this.object3d.parent;return t&&this.lead.objMap.get(t)||null}get children(){return this.object3d.children.map(t=>this.lead.objMap.get(t)).filter(t=>!!t)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}lookAt(t){const e=t instanceof y?t:new y(...t);this.object3d.lookAt(e)}add(...t){[...t].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...t){[...t].forEach(t=>{var e;this.lead.objMap.get(t)?null==(e=this.lead.objMap.get(t))||e.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}isActuallyVisible(){if(!this.object3d.visible)return!1;const t=this.parent;return!t||t.isActuallyVisible()}create(){this.createGroup()}render(){}update(t,e){}resize(t,e){}show(){return this.object3d.visible=!0,this.isActuallyVisible()&&this._enableLayersRecursive(),this}hide(){return this.object3d.visible=!1,this._disableLayersRecursive(),this}_disableLayersRecursive(){var t;null==(t=this.object3d)||t.layers.disable(0),this.children.forEach(t=>{t._disableLayersRecursive()})}_enableLayersRecursive(){var t;this.object3d.visible&&(null==(t=this.object3d)||t.layers.enable(0),this.children.forEach(t=>{t._enableLayersRecursive()}))}createGroup(){return this.object3d=new R,this}createMesh(...t){return this.object3d=new U(...t),this}createPoints(...t){return this.object3d=new C(...t),this}createCSS2DObject(t){return this.object3d=new Jt(t),this}createCSS3DObject(t){return this.object3d=new Qt(t),this}createCSS3DSprite(t){return this.object3d=new te(t),this}createSprite(t){return this.object3d=new j(t),this}attach(...t){return[...t].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const t=(new B).setFromObject(this.object3d);return{min:t.min,max:t.max,size:t.getSize(new y),center:t.getCenter(new y)}}setTop(t){this.object3d&&(this.object3d.renderOrder=t)}traverse(t){t(this),this.children.forEach(e=>{e.traverse(t)})}instantiate(t){return d(this,null,function*(){var e,n;const i=null==(e=null==t?void 0:t.recursive)||e,s=null!=(n=null==t?void 0:t.cloneMaterial)&&n,{objectType:r,objectOptions:o}=this;let a,c=null==t?void 0:t.create,u=(null==t?void 0:t.target)||this.parent;return u===this.lead.prefabGroup&&(u=this.lead.group),"BaseObject"===this.objectType?a=this.lead.createBaseObject(this.object3d.clone(!1),{target:u}):(void 0===c&&(c=e=>{var n;if(this.object3d){if(null==(n=null==t?void 0:t.instancedAttr)?void 0:n.length){const n=t.instancedAttr.length;if(this.object3d instanceof j)e.object3d=((t,e=1)=>{const n=new S;n.setAttribute("position",new A(new Array(3*e).fill(0),3)),n.setAttribute("scaleAtt",new A(new Array(e).fill(1),1));const i=t.material,s=new T({size:10,map:i.map,alphaMap:i.alphaMap,color:i.color,blending:i.blending,depthTest:i.depthTest,depthWrite:!1,opacity:i.opacity,transparent:!0,alphaTest:i.alphaTest,sizeAttenuation:!1});s.onBeforeCompile=t=>{t.vertexShader=`\n attribute float scaleAtt;\n ${t.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}\n `};const r=new C(n,s);return r.raycast=sn,r})(this.object3d,n);else{const t=this.object3d,i=s?this.cloneMaterial():t.material;e.object3d=new k(t.geometry,i,n)}((t,e)=>{const n=new v;e.forEach((e,i)=>{const s=zn(e.position),r=zn(e.scale||[1,1,1]);n.position.copy(s),n.scale.copy(r),n.updateMatrix();const o=n.matrix.clone();if(t instanceof k||t.isInstantiate)t.setMatrixAt(i,o);else if(t instanceof C||"Points"===t.type){const e=t.geometry,n=e.attributes.position.array,s=e.attributes.scaleAtt.array,r=new y,a=new y,h=new L,l=3*i,c=1*i;o.decompose(r,h,a),n[l]=r.x,n[l+1]=r.y,n[l+2]=r.z,s[c]=Math.max(a.x,a.y,a.z),e.attributes.position.needsUpdate=!0,e.attributes.scaleAtt.needsUpdate=!0}})})(e.object3d,null==t?void 0:t.instancedAttr)}else e.object3d=this.object3d.clone(!1),s&&e.object3d.material&&(e.object3d.material=this.cloneMaterial());e.object3d.userData.prefab&&delete e.object3d.userData.prefab}}),a=yield this.lead.draw(r,l(h({},o||{}),{create:c,prefab:!1,keyType:this.keyType,key:(null==t?void 0:t.key)||this.keyName,uId:(null==t?void 0:t.uId)||this.keyUId,target:u}))),this.isBloom&&a.enableBloom(),i&&(yield Promise.all(this.children.map(e=>e.instantiate({key:e.keyUId&&e.keyName?`${e.keyName}-${e.keyUId}`:e.keyName,uId:null==t?void 0:t.uId,cloneMaterial:s,target:a})))),a.isInstantiate=!0,a})}erase(){this.lead.erase(this)}handleMaterialChange(t){}enableBloom(t=!0){var e,n,i;(null==(e=this.pencil.composerController)?void 0:e.bloomComposer)?t?this.traverse(t=>{t.enableBloom(!1)}):(this.object3d&&(null==(n=this.pencil.composerController)||n.bloomSelection.add(this),this.object3d.layers.enable(1)),null==(i=this.pencil.composerController)||i.checkBloomComposerActive(),this.isBloom=!0):console.warn("err:pencil.options.bloom")}disableBloom(t=!0){var e,n,i;(null==(e=this.pencil.composerController)?void 0:e.bloomComposer)?t?this.traverse(t=>{t.disableBloom(!1)}):(this.object3d&&(null==(n=this.pencil.composerController)||n.bloomSelection.delete(this),this.object3d.layers.disable(1)),null==(i=this.pencil.composerController)||i.checkBloomComposerActive(),this.isBloom=!1):console.warn("err:pencil.options.bloom")}dispose(){var t,e;if(!this.isDispose&&(this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),null==(t=this.pencil.composerController)||t.checkBloomComposerActive()),null==(e=this.lead)||e.disableCursor(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack)){const t=new Ke;t.disposeMaterial=!1,t.track(this),t.dispose()}}}function Rn(t,e=0){const n=null!==t[0].index,i=new Set(Object.keys(t[0].attributes)),s=new Set(Object.keys(t[0].morphAttributes)),r={},o={},a=t[0].morphTargetsRelative,h=new S;let l=0;for(let c=0;c<t.length;++c){const u=t[c];let d=0;if(n!==(null!==u.index))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const t in u.attributes){if(!i.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+'. All geometries must have compatible attributes; make sure "'+t+'" attribute exists among all geometries, or in none of them.'),null;void 0===r[t]&&(r[t]=[]),r[t].push(u.attributes[t]),d++}if(d!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". Make sure all geometries have the same number of attributes."),null;if(a!==u.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const t in u.morphAttributes){if(!s.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". .morphAttributes must be consistent throughout all geometries."),null;void 0===o[t]&&(o[t]=[]),o[t].push(u.morphAttributes[t])}if(e){let t;if(n)t=u.index.count;else{if(void 0===u.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+c+". The geometry must have either an index or a position attribute"),null;t=u.attributes.position.count}if(1===e)h.addGroup(l,t,c);else if(2===e&&u.groups.length>0)for(let e of u.groups){let n=e.materialIndex;h.addGroup(l+e.start,Math.min(e.count,t),n)}l+=t}}if(n){let e=0;const n=[];for(let i=0;i<t.length;++i){const s=t[i].index;for(let t=0;t<s.count;++t)n.push(s.getX(t)+e);e+=t[i].attributes.position.count}h.setIndex(n)}for(const c in r){const t=ye(r[c]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+c+" attribute."),null;h.setAttribute(c,t)}for(const c in o){const t=o[c][0].length;if(0===t)break;h.morphAttributes=h.morphAttributes||{},h.morphAttributes[c]=[];for(let e=0;e<t;++e){const t=[];for(let i=0;i<o[c].length;++i)t.push(o[c][i][e]);const n=ye(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+c+" morphAttribute."),null;h.morphAttributes[c].push(n)}}return 2===e?ge(h):h}function Un(t,e,n=!1){return n?pe(e,t):Ae(t,e)}function jn(t,e){const n={type:"Polygon",coordinates:t},[[i,s],[r,a]]=de(n);if(Math.min(Math.abs(r-i),Math.abs(a-s))<e)return[];const h=i>r||a>=89||s<=-89;return function(t,{minLng:e,maxLng:n,minLat:i,maxLat:s}={}){const r=Math.round(o(360/t,2)/Math.PI),a=(1+Math.sqrt(5))/2,h=t=>t/a*360%360-180,l=t=>Math.acos(2*t/r-1)/Math.PI*180-90,c=t=>r*(Math.cos((t+90)*Math.PI/180)+1)/2,u=[void 0!==s?Math.ceil(c(s)):0,void 0!==i?Math.floor(c(i)):r-1],d=void 0===e&&void 0===n?()=>!0:void 0===e?t=>t<=n:void 0===n?t=>t>=e:n>=e?t=>t>=e&&t<=n:t=>t>=e||t<=n,p=[];for(let o=u[0];o<=u[1];o++){const t=h(o);d(t)&&p.push([t,l(o)])}return p}(e,{minLng:i,maxLng:r,minLat:s,maxLat:a}).filter(t=>Un(t,n,h))}function Dn(t,{resolution:e=1/0,bbox:n,projection:i}={}){const s=function(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const s=180*fe(t,i)/Math.PI;if(s>e){const r=me(i,t),o=1/Math.ceil(s/e);let a=o;for(;a<1;)n.push(r(a)),a+=o}}n.push(i=t)}),n})}(t,e),r=be(s),o=jn(t,e),a=[...r,...o],h={type:"Polygon",coordinates:t},[[l,c],[u,d]]=de(h),p=l>u||d>=89||c<=-89;let f=[];if(p){const t=Te(a).triangles(),e=new Map(a.map(([t,e],n)=>[`${t}-${e}`,n]));t.features.forEach(t=>{const n=t.geometry.coordinates[0].slice(0,3).reverse(),i=[];if(n.forEach(([t,n])=>{const s=`${t}-${n}`;e.has(s)&&i.push(e.get(s))}),3===i.length){if(i.some(t=>t<r.length)){if(!Un(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=Se.from(a);for(let e=0,n=t.triangles.length;e<n;e+=3){const n=[2,1,0].map(n=>t.triangles[e+n]),i=n.map(t=>a[t]);if(n.some(t=>t<r.length)){if(!Un([0,1].map(t=>ve(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=Me(s);f=_e(t,e,2)}let m=n?[n[0],n[2]]:we(a,t=>t[0]),y=n?[n[1],n[3]]:we(a,t=>t[1]);if(i){const[t,e]=i([m[0],y[0]]),[n,s]=i([m[1],y[1]]);m=[t,n],y=[-e,-s]}const g=Ce(m,[0,1]),x=Ce(y,[0,1]),b=a.map(([t,e])=>{if(i){const[n,s]=i([t,e]);return[g(n),x(-s)]}return[g(t),x(e)]});return{contour:s,triangles:{points:a,indices:f,uvs:b}}}const Fn=(new S).setAttribute?"setAttribute":"addAttribute";function In(t,e,n){const i=t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=pn(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=pn(t,i,e,1/dn.a,!0);return[n.x,n.y,n.z]}if("function"==typeof n){const[s,r]=n([t,i]);return[s,-r,e]}return[t,i,e]}));return Me(i)}function Vn(t,e,n,i,s){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:In([t.points],e,s).vertices,uvs:n}}const Wn=({polygonGeoJson:t,startHeight:e,endHeight:n,curvatureResolution:i=1,hasSide:s=!0,hasBottom:r=!1,hasTop:o=!1,projection:a="sphere",bbox:h})=>{t.forEach(t=>{xe(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:c,triangles:u}=Dn(t,{resolution:i,bbox:h,projection:l});let d,p={};s&&(p=function(t,e,n,i){const{vertices:s,holes:r}=In(t,e,i),{vertices:o}=In(t,n,i),a=be([o,s]),h=Math.round(o.length/3),l=new Set(r);let c=0;const u=[];for(let p=0;p<h;p++){let t=p+1;if(t===h)t=c;else if(l.has(t)){const e=t;t=c,c=e}u.push(p,p+h,t+h),u.push(t+h,t,p)}const d=[];for(let p=1;p>=0;p--)for(let t=0;t<h;t+=1)d.push(t/(h-1),p);return{indices:u,vertices:a,uvs:d,topVerts:o}}(c,null!=e?e:n,null!=n?n:e,a),d=p.topVerts);let f=[];(r||o)&&(f=be(u.uvs));let m={};r&&(m=Vn(u,e,f,!1,a));let y={};return o&&(y=Vn(u,n,f,!0,a)),{contour:c,triangles:u,sideTorso:p,bottomCap:m,topCap:y,topVerts:d}};class Hn extends S{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=h(h({},{polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,projection:"sphere",resetCenter:!1}),e);const{hasTop:n,topFirst:i,hasBottom:s,hasSide:r}=this.parameters,{sideTorso:o,bottomCap:a,topCap:l}=Wn(h({},this.parameters));let c=[],u=[],d=[],p=0;const f=t=>{const e=Math.round(c.length/3),n=d.length;c=c.concat(t.vertices),u=u.concat(t.uvs),d=d.concat(e?t.indices.map(t=>t+e):t.indices),this.addGroup(n,d.length-n,p++)};n&&i&&f(l),r&&f(o),s&&f(a),n&&!i&&f(l),this.parameters.resetCenter&&c.length>0&&(this.userData.rtcPositionsVertices=new D(new Float64Array(c),3)),this.setIndex(d),this[Fn]("position",new A(c,3)),this[Fn]("uv",new A(u,2)),this.computeVertexNormals()}}const qn=t=>{const e=t,{coordinate:n,startHeight:i,height:s}=e,r=c(e,["coordinate","startHeight","height"]);let o=i||0;void 0!==i&&void 0!==s&&(o=i+s);return new Hn([n],l(h({},r),{startHeight:i,endHeight:o}))};class Zn extends Ln{constructor(t){super(),u(this,"options"),this.options=h({},t)}create(){const t=this.options,{geometry:e,coordinateArr:n,coordinate:i,material:s,useGroups:r}=t,o=c(t,["geometry","coordinateArr","coordinate","material","useGroups"]);let a=e;if(!a&&i)a=qn(h({coordinate:i},o));else if(!a&&n){a=Rn(n.map(t=>qn(h({coordinate:t},o))),null!=r?r:0)}this.createMesh(a,s)}}class Yn extends Ln{constructor(t={}){super(),u(this,"options"),this.options=t}create(){const t=function(t={}){const{a:e=dn.a,b:n=dn.b,scaleFactor:i=1/dn.a,widthSegments:s=64,heightSegments:r=32}=t,o=new S,a=[],h=[],l=[],c=[],u=e*e,d=(u-n*n)/u;let p=0;const f=[];for(let m=0;m<=r;m++){const t=[],o=m/r,a=180*(.5-o)*Math.PI/180,u=Math.sin(a),y=Math.cos(a),g=e/Math.sqrt(1-d*u*u);for(let r=0;r<=s;r++){const a=r/s,f=360*(a-.5)*Math.PI/180,m=Math.sin(f),x=Math.cos(f),b=g*y*m*i,v=g*(1-d)*u*i,w=g*y*x*i;h.push(b,v,w);const _=y*m/e,M=u*(1-d)/n,S=y*x/e,A=Math.sqrt(_*_+M*M+S*S);l.push(_/A,M/A,S/A),c.push(a,1-o),t.push(p++)}f.push(t)}for(let m=0;m<r;m++)for(let t=0;t<s;t++){const e=f[m][t+1],n=f[m][t],i=f[m+1][t],s=f[m+1][t+1];a.push(e,n,s),a.push(n,i,s)}return o.setIndex(a),o.setAttribute("position",new A(h,3)),o.setAttribute("normal",new A(l,3)),o.setAttribute("uv",new A(c,2)),o}(this.options),e=this.options.material||new F({color:2200782,metalness:.1,roughness:.7,wireframe:!1}),n=new U(t,e);return n.name="Ellipsoid",this.object3d=n,n}}const Gn={ArcCurve:K,CatmullRomCurve3:J,CubicBezierCurve:$,CubicBezierCurve3:X,EllipseCurve:G,LineCurve:Y,LineCurve3:Z,QuadraticBezierCurve:q,QuadraticBezierCurve3:H,SplineCurve:W};class Xn extends S{constructor(t=new I([new N(.5,.5),new N(-.5,.5),new N(-.5,-.5),new N(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const n=this,i=[],s=[];for(let o=0,a=t.length;o<a;o++){r(t[o])}function r(t){var r,o,a;const h=[],l=void 0!==e.curveSegments?e.curveSegments:12,c=void 0!==e.steps?e.steps:1,u=void 0!==e.depth?e.depth:1;let d=void 0===e.bevelEnabled||e.bevelEnabled,p=void 0!==e.bevelThickness?e.bevelThickness:.2,f=void 0!==e.bevelSize?e.bevelSize:p-.1,m=void 0!==e.bevelOffset?e.bevelOffset:0,g=void 0!==e.bevelSegments?e.bevelSegments:3;const x=e.extrudePath,b=void 0!==e.UVGenerator?e.UVGenerator:$n,v=null==(r=e.hasTop)||r,w=null==(o=e.hasBottom)||o,_=null==(a=e.hasSide)||a;let M,S,A,T,C,z=!1;x&&(M=x.getSpacedPoints(c),z=!0,d=!1,S=x.computeFrenetFrames(c,!1),A=new y,T=new y,C=new y),d||(g=0,p=0,f=0,m=0);const E=t.extractPoints(l);let O=E.shape;const P=E.holes;if(!V.isClockWise(O)){O=O.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];V.isClockWise(e)&&(P[t]=e.reverse())}}function B(t){const e=1e-10*1e-10;let n=t[0];for(let i=1;i<=t.length;i++){const s=i%t.length,r=t[s],o=r.x-n.x,a=r.y-n.y,h=o*o+a*a,l=Math.max(Math.abs(r.x),Math.abs(r.y),Math.abs(n.x),Math.abs(n.y));h<=e*l*l?(t.splice(s,1),i--):n=r}}B(O),P.forEach(B);const k=P.length,L=O;for(let e=0;e<k;e++){const t=P[e];O=O.concat(t)}function R(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const U=O.length;function j(t,e,n){let i,s,r;const o=t.x-e.x,a=t.y-e.y,h=n.x-t.x,l=n.y-t.y,c=o*o+a*a,u=o*l-a*h;if(Math.abs(u)>Number.EPSILON){const u=Math.sqrt(c),d=Math.sqrt(h*h+l*l),p=e.x-a/u,f=e.y+o/u,m=((n.x-l/d-p)*l-(n.y+h/d-f)*h)/(o*l-a*h);i=p+o*m-t.x,s=f+a*m-t.y;const y=i*i+s*s;if(y<=2)return new N(i,s);r=Math.sqrt(y/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(l)&&(t=!0),t?(i=-a,s=o,r=Math.sqrt(c)):(i=o,s=a,r=Math.sqrt(c/2))}return new N(i/r,s/r)}const D=[];for(let e=0,n=L.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),D[e]=j(L[e],L[i],L[s]);const F=[];let I,W,H=D.concat();for(let e=0,n=k;e<n;e++){const t=P[e];I=[];for(let e=0,n=t.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),I[e]=j(t[e],t[i],t[s]);F.push(I),H=H.concat(I)}if(0===g)W=V.triangulateShape(L,P);else{const t=[],e=[];for(let n=0;n<g;n++){const i=n/g,s=p*Math.cos(i*Math.PI/2),r=f*Math.sin(i*Math.PI/2)+m;for(let e=0,n=L.length;e<n;e++){const n=R(L[e],D[e],r);G(n.x,n.y,-s),0===i&&t.push(n)}for(let t=0,n=k;t<n;t++){const n=P[t];I=F[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=R(n[t],I[t],r);G(e.x,e.y,-s),0===i&&o.push(e)}0===i&&e.push(o)}}W=V.triangulateShape(t,e)}const q=W.length,Z=f+m;for(let e=0;e<U;e++){const t=d?R(O[e],H[e],Z):O[e];z?(T.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),C.copy(M[0]).add(T).add(A),G(C.x,C.y,C.z)):G(t.x,t.y,0)}for(let e=1;e<=c;e++)for(let t=0;t<U;t++){const n=d?R(O[t],H[t],Z):O[t];z?(T.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),C.copy(M[e]).add(T).add(A),G(C.x,C.y,C.z)):G(n.x,n.y,u/c*e)}for(let e=g-1;e>=0;e--){const t=e/g,n=p*Math.cos(t*Math.PI/2),i=f*Math.sin(t*Math.PI/2)+m;for(let e=0,s=L.length;e<s;e++){const t=R(L[e],D[e],i);G(t.x,t.y,u+n)}for(let e=0,s=P.length;e<s;e++){const t=P[e];I=F[e];for(let e=0,s=t.length;e<s;e++){const s=R(t[e],I[e],i);z?G(s.x,s.y+M[c-1].y,M[c-1].x+n):G(s.x,s.y,u+n)}}}function Y(t,e){let n=t.length;for(;--n>=0;){const i=n;let s=n-1;s<0&&(s=t.length-1);for(let t=0,n=c+2*g;t<n;t++){const n=U*t,r=U*(t+1);$(e+i+n,e+s+n,e+s+r,e+i+r)}}}function G(t,e,n){h.push(t),h.push(e),h.push(n)}function X(t,e,s){J(t),J(e),J(s);const r=i.length/3,o=b.generateTopUV(n,i,r-3,r-2,r-1);K(o[0]),K(o[1]),K(o[2])}function $(t,e,s,r){J(t),J(e),J(r),J(e),J(s),J(r);const o=i.length/3,a=b.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);K(a[0]),K(a[1]),K(a[3]),K(a[1]),K(a[2]),K(a[3])}function J(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function K(t){s.push(t.x),s.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=U*t;if(w)for(let n=0;n<q;n++){const t=W[n];X(t[2]+e,t[1]+e,t[0]+e)}if(t=c+2*g,e=U*t,v)for(let n=0;n<q;n++){const t=W[n];X(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<q;t++){const e=W[t];X(e[2],e[1],e[0])}if(v)for(let t=0;t<q;t++){const e=W[t];X(e[0]+U*c,e[1]+U*c,e[2]+U*c)}}n.addGroup(t,i.length/3-t,0)}(),_&&function(){const t=i.length/3;let e=0;Y(L,e),e+=L.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];Y(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new A(i,3)),this.setAttribute("uv",new A(s,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,n){if(n.shapes=[],Array.isArray(t))for(let i=0,s=t.length;i<s;i++){const e=t[i];n.shapes.push(e.uuid)}else n.shapes.push(t.uuid);n.options=Object.assign({},e),void 0!==e.extrudePath&&(n.options.extrudePath=e.extrudePath.toJSON());return n}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const n=[];for(let s=0,r=t.shapes.length;s<r;s++){const i=e[t.shapes[s]];n.push(i)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new Gn[i.type]).fromJSON(i)),new Xn(n,t.options)}}const $n={generateTopUV:function(t,e,n,i,s){const r=e[3*n],o=e[3*n+1],a=e[3*i],h=e[3*i+1],l=e[3*s],c=e[3*s+1];return[new N(r,o),new N(a,h),new N(l,c)]},generateSideWallUV:function(t,e,n,i,s,r){const o=e[3*n],a=e[3*n+1],h=e[3*n+2],l=e[3*i],c=e[3*i+1],u=e[3*i+2],d=e[3*s],p=e[3*s+1],f=e[3*s+2],m=e[3*r],y=e[3*r+1],g=e[3*r+2];return Math.abs(a-c)<Math.abs(o-l)?[new N(o,1-h),new N(l,1-u),new N(d,1-f),new N(m,1-g)]:[new N(a,1-h),new N(c,1-u),new N(p,1-f),new N(y,1-g)]}};class Jn extends Xn{constructor(t,e){super(t,e);const n=new ze(new Xn(t,l(h({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new B).setFromObject(n),s=new y;i.getSize(s);const r=new y(i.min.x+s.x/2,i.min.y+s.y/2,0);let o=e.topSegments,a=e.box3;if(a){a=a.union(i);const t=new y;a.getSize(t);const n=Math.max(s.x/t.x,s.y/t.y);o=Math.ceil(e.topSegments*n)}if(o<4)return this;const c=new Q(s.x,s.y,o,o),u=new ze(c);u.position.set(r.x,r.y,r.z),u.updateMatrixWorld();const d=(new Ee).evaluate(u,n,Oe),p=d.geometry.getAttribute("position"),f=new A(2*p.count,2);for(let h=0;h<p.count;h++){const t=p.getZ(h);p.setZ(h,e.depth+t)}if(a){const t=a.min,e=a.max,n=(new y).subVectors(e,t);for(let i=0;i<p.count;i++){const e=p.getX(i),s=p.getY(i),r=(e-t.x)/n.x,o=(s-t.y)/n.y;f.setXY(i,r,o)}d.geometry.setAttribute("uv",f)}p.needsUpdate=!0;const m=new Xn(t,l(h({},e),{hasTop:!1})),g=Rn([d.geometry,m],2);this.copy(g.toNonIndexed())}}const Kn=t=>{const{split:e,depth:n,points:i,box3:s,hasTop:r,hasBottom:o,hasSide:a,sideRepeat:h,topSegments:l}=t,c=new(l?Jn:Xn)(new I(i),{depth:n,bevelEnabled:!1,box3:s,UVGenerator:On({split:e,box3:s,sideRepeat:h}),hasTop:r,hasBottom:o,hasSide:a,topSegments:l});return Pn(),c};class Qn extends Ln{constructor(t){super(),u(this,"options"),this.options=h({depth:1},t)}create(){return d(this,null,function*(){const{points:t,pointsArr:e,useGroups:n,depth:i,geometry:s,geometryArr:r,material:o,box3:a,split:h,hasTop:l,hasBottom:c,hasSide:u}=this.options,d=Array.isArray(i)?i:[i],p=Array.isArray(a)?a:[a],f=o;let m=s;f||console.log("material is null"),!m&&t?m=Kn({points:t,depth:d[0],box3:p[0],split:h,hasTop:l,hasBottom:c,hasSide:u}):!m&&e?m=Rn(e.map((t,e)=>{var n,i;return Kn({points:t,depth:null!=(n=d[e])?n:d[0],box3:null!=(i=p[e])?i:p[0],split:h,hasTop:l,hasBottom:c,hasSide:u})}),null!=n?n:0):!m&&r&&r.length>1?m=Rn(r,null!=n?n:0):!m&&r&&1===r.length&&([m]=r),this.createMesh(m,f)})}addGeometries(t){const e=this.object3d,n=Rn([e.geometry,...t]);e.geometry=n}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const ti=t=>{const{topColor:e,sideColor:n,sideMap:i,createCanvasObjectURL:s,split:r,maxAnisotropy:o}=t;return new Promise(t=>{const o=i?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};o.onload=()=>{const a=r,h=document.createElement("canvas"),l=h.getContext("2d");h.height=o.height/(1-a),h.width=o.width,a&&e&&(l.fillStyle=e,l.fillRect(0,0,o.width,h.height*a)),i&&o instanceof HTMLImageElement?l.drawImage(o,0,h.height*a,o.width,o.height):n&&(l.fillStyle=n,l.fillRect(0,h.height*a,o.width,o.height)),s&&h.toBlob(t=>{console.log(URL.createObjectURL(t))});const c=new tt(h);t(c)},i?o.src=i:o instanceof HTMLImageElement||o.onload()})};class ei extends Ln{create(){this.createGroup()}render(){this.object3d.raycast=(t,e)=>t.intersectObjects(this.object3d.children,!0,e)}}class ni extends Ln{constructor(t){super(),u(this,"options"),u(this,"directionalLight"),u(this,"spotLight"),u(this,"pointLight"),u(this,"hemisphereLight"),u(this,"rectAreaLight"),u(this,"rectAreaLightUniformsLibInit",!1),this.options=t}create(){var t,e,n,i,s,r,o,a,h,l,c,u,d,p,f,m,y;const g=this.options;if("AmbientLight"===g.type){const t=new et(g.color);t.name="环境光",this.object3d=t}else if("DirectionalLight"===g.type){const t=new nt(g.color,g.intensity);t.name="平行光",t.target.position.set(0,0,0),this.object3d=t,t.target.name="平行光目标",t.shadow.camera.name="平行光阴影相机",t.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=t}else if("PointLight"===g.type){const s=new it(null!=(t=g.color)?t:16777215,null!=(e=g.intensity)?e:1,null!=(n=g.distance)?n:0,null!=(i=g.decay)?i:2);s.name="点光源",this.object3d=s,this.pointLight=s}else if("SpotLight"===g.type){const t=new st(null!=(s=g.color)?s:16777215,null!=(r=g.intensity)?r:1,null!=(o=g.distance)?o:0,null!=(a=g.angle)?a:Math.PI/3,null!=(h=g.penumbra)?h:1,null!=(l=g.decay)?l:2);t.name="聚光灯",this.object3d=t,this.spotLight=t,t.target.name="聚光灯目标"}else if("HemisphereLight"===g.type){const t=new rt(null!=(c=g.color)?c:16777215,null!=(u=g.groundColor)?u:16777215,null!=(d=g.intensity)?d:1);t.name="半球光",this.object3d=t,this.hemisphereLight=t}else if("RectAreaLight"===g.type){this.rectAreaLightUniformsLibInit||(Pe.init(),this.rectAreaLightUniformsLibInit=!0);const t=new ot(null!=(p=g.color)?p:16777215,null!=(f=g.intensity)?f:1,null!=(m=g.width)?m:10,null!=(y=g.height)?y:10);t.name="矩形区域光",this.object3d=t,this.rectAreaLight=t}}render(){const t=this.object3d;t.target&&this.pencil.scene.add(t.target);const e=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const t=this.spotLight||this.directionalLight;t.position.copy(e),t.target.position.copy(e)}else if(this.pointLight){this.pointLight.position.copy(e)}}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}class ii extends S{constructor(t=[],e="none",n){super(),u(this,"type","MeshLineGeometry"),u(this,"pointCount",0),u(this,"_points",[]),u(this,"shape","none"),u(this,"shapeFunction",t=>1),u(this,"matrixWorld",new g),this.shape=e,n&&(this.shapeFunction=n),t.length>0&&this.setPoints(t)}convertToVector3Array(t){if("number"==typeof t[0]){const e=[],n=t;for(let t=0;t<n.length;t+=3)e.push(new y(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof N?new y(t.x,t.y,0):t instanceof y?t:Array.isArray(t)&&2===t.length?new y(t[0],t[1],0):Array.isArray(t)&&3===t.length?new y(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n=!1){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry(n))}initializeGeometry(){const t=new D(new Float32Array(6*this.pointCount),3),e=new D(new Float32Array(6*this.pointCount),3),n=new D(new Float32Array(6*this.pointCount),3),i=new D(new Float32Array(2*this.pointCount),1),s=new D(new Float32Array(2*this.pointCount),1),r=new D(new Float32Array(2*this.pointCount),1),a=new D(new Float32Array(4*this.pointCount),2),h=new D(new Uint16Array(6*(this.pointCount-1)),1);"taper"===this.shape&&(this.shapeFunction=t=>1*o(4*t*(1-t),1));for(let o=0,l=0,c=0;o<this.pointCount;o+=1,l+=2,c+=6){i.setX(l,o/this.pointCount),i.setX(l+1,o/this.pointCount),s.setX(l,1),s.setX(l+1,-1);const t="none"===this.shape?1:this.shapeFunction(o/(this.pointCount-1));r.setX(l,t),r.setX(l+1,t);const e=o/(this.pointCount-1);if(a.setXY(l,e,0),a.setXY(l+1,e,1),o<this.pointCount-1){const t=2*o;h.setX(c+0,t+0),h.setX(c+1,t+1),h.setX(c+2,t+2),h.setX(c+3,t+2),h.setX(c+4,t+1),h.setX(c+5,t+3)}}this.setAttribute("position",t),this.setAttribute("previous",e),this.setAttribute("next",n),this.setAttribute("counters",i),this.setAttribute("side",s),this.setAttribute("width",r),this.setAttribute("uv",a),this.setIndex(h)}updateGeometry(t=!1){var e,n,i,s,r,o,a,h,l,c;if(!this._points[0])return;const u=this.getAttribute("position"),d=this.getAttribute("previous"),p=this.getAttribute("next");t&&(this.userData.rtcPositionsVertices=new D(new Float64Array(3*u.count),3),this.userData.rtcPreviousVertices=new D(new Float64Array(3*d.count),3),this.userData.rtcNextVertices=new D(new Float64Array(3*p.count),3));let f=0,m=0,y=0;const g=this._points[0];d.setXYZ(m,g.x,g.y,g.z),null==(e=this.userData.rtcPreviousVertices)||e.setXYZ(m,g.x,g.y,g.z),m+=1,d.setXYZ(m,g.x,g.y,g.z),null==(n=this.userData.rtcPreviousVertices)||n.setXYZ(m,g.x,g.y,g.z),m+=1;for(let b=0;b<this.pointCount;b++){const t=this._points[b];u.setXYZ(f,t.x,t.y,t.z),null==(i=this.userData.rtcPositionsVertices)||i.setXYZ(f,t.x,t.y,t.z),f+=1,u.setXYZ(f,t.x,t.y,t.z),null==(s=this.userData.rtcPositionsVertices)||s.setXYZ(f,t.x,t.y,t.z),f+=1,b<this.pointCount-1&&(d.setXYZ(m,t.x,t.y,t.z),null==(r=this.userData.rtcPreviousVertices)||r.setXYZ(m,t.x,t.y,t.z),m+=1,d.setXYZ(m,t.x,t.y,t.z),null==(o=this.userData.rtcPreviousVertices)||o.setXYZ(m,t.x,t.y,t.z),m+=1),b>0&&b+1<=this.pointCount&&(p.setXYZ(y,t.x,t.y,t.z),null==(a=this.userData.rtcNextVertices)||a.setXYZ(y,t.x,t.y,t.z),y+=1,p.setXYZ(y,t.x,t.y,t.z),null==(h=this.userData.rtcNextVertices)||h.setXYZ(y,t.x,t.y,t.z),y+=1)}const x=this._points[this.pointCount-1];p.setXYZ(y,x.x,x.y,x.z),null==(l=this.userData.rtcNextVertices)||l.setXYZ(y,x.x,x.y,x.z),y+=1,p.setXYZ(y,x.x,x.y,x.z),null==(c=this.userData.rtcNextVertices)||c.setXYZ(y,x.x,x.y,x.z),y+=1,u.needsUpdate=!0,d.needsUpdate=!0,p.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(t){this.setPoints(t)}updatePoints(t,e){const n=this.convertToVector3Array(t);n.length===this.pointCount?(this._points=n,e&&(this.shapeFunction=e,this.shape="custom",this.initializeGeometry()),this.updateGeometry()):console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.")}setShape(t,e){this.shape=t,e&&(this.shapeFunction=e),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}function si(t=!1){return(t?"#define USE_RTC\n":"")+"\n #include <common>\n #include <logdepthbuf_pars_vertex>\n #include <fog_pars_vertex>\n\n attribute vec3 previous;\n attribute vec3 next;\n attribute float side;\n attribute float width;\n attribute float counters;\n\n // RTC 相关定义 \n #ifdef USE_RTC\n attribute vec3 localCenter;\n uniform vec3 globalRTCCenter;\n uniform vec3 rtcCenter;\n uniform float uRTCMode; // 0.0: None, 1.0: Simple, 2.0: Multi-Level\n #endif\n\n uniform vec2 resolution;\n uniform float lineWidth;\n uniform vec3 color;\n uniform float opacity;\n uniform float sizeAttenuation;\n uniform float scaleDown;\n uniform vec2 offset;\n\n varying vec2 vUV;\n varying vec4 vColor;\n varying float vCounters;\n\n vec2 intoScreen(vec4 i) {\n return resolution * (0.5 * i.xy / i.w + 0.5);\n }\n\n void main() {\n float aspect = resolution.y / resolution.x;\n\n vec3 worldPosition = position;\n vec3 worldPrevious = previous;\n vec3 worldNext = next;\n\n #ifdef USE_RTC\n if (uRTCMode == 1.0) {\n // Simple RTC\n worldPosition += rtcCenter;\n worldPrevious += rtcCenter;\n worldNext += rtcCenter;\n } else if (uRTCMode == 2.0) {\n // Multi-Level RTC\n worldPosition += localCenter + globalRTCCenter;\n worldPrevious += localCenter + globalRTCCenter;\n worldNext += localCenter + globalRTCCenter;\n }\n #endif\n\n mat4 m = projectionMatrix * modelViewMatrix;\n\n vec4 currentClip = m * vec4( worldPosition, 1.0 );\n vec4 prevClip = m * vec4( worldPrevious, 1.0 );\n vec4 nextClip = m * vec4( worldNext, 1.0 );\n\n vec4 currentNormed = currentClip / currentClip.w;\n vec4 prevNormed = prevClip / prevClip.w;\n vec4 nextNormed = nextClip / nextClip.w;\n\n vec2 currentScreen = intoScreen(currentNormed);\n vec2 prevScreen = intoScreen(prevNormed);\n vec2 nextScreen = intoScreen(nextNormed);\n\n float actualWidth = lineWidth * width;\n\n vec2 dir;\n if(nextScreen == currentScreen) {\n dir = normalize( currentScreen - prevScreen );\n } else if(prevScreen == currentScreen) {\n dir = normalize( nextScreen - currentScreen );\n } else {\n vec2 inDir = currentScreen - prevScreen;\n vec2 outDir = nextScreen - currentScreen;\n vec2 fullDir = nextScreen - prevScreen;\n\n if(length(fullDir) > 0.0) {\n dir = normalize(fullDir);\n } else if(length(inDir) > 0.0){\n dir = normalize(inDir);\n } else {\n dir = normalize(outDir);\n }\n }\n\n vec2 normal = vec2(-dir.y, dir.x);\n\n if(sizeAttenuation != 0.0) {\n normal /= currentClip.w;\n normal *= min(resolution.x, resolution.y);\n }\n\n if (scaleDown > 0.0) {\n float dist = length(nextNormed - prevNormed);\n normal *= smoothstep(0.0, scaleDown, dist);\n }\n\n vec2 offsetInScreen = actualWidth * normal * side * 0.5;\n\n vec2 withOffsetScreen = currentScreen + offsetInScreen;\n vec3 withOffsetNormed = vec3((2.0 * withOffsetScreen/resolution - 1.0), currentNormed.z);\n\n vCounters = counters;\n vColor = vec4( color, opacity );\n vUV = uv;\n vUV=uv+offset;\n\n gl_Position = currentClip.w * vec4(withOffsetNormed, 1.0);\n\n #include <logdepthbuf_vertex>\n #include <fog_vertex>\n }\n"}class ri extends at{constructor(t={}){const e=t,{lineWidth:n=1,color:i="#ffffff",opacity:s=1,map:r=null,dashOffset:o=0,dashArray:a=0,dashRatio:d=.5,sizeAttenuation:p=!0,offsetLoop:f=!0,offset:m=new N(0,0),scaleDown:g=0,alphaMap:x,alphaTest:b=0,repeat:v=new N(1,1),resolution:w=new N(1,1),useRTC:_=!1}=e,M=c(e,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution","useRTC"]);super(l(h({},M),{uniforms:{lineWidth:{value:n},color:{value:new ht(i)},opacity:{value:s},map:{value:r},useMap:{value:r?1:0},resolution:{value:w},sizeAttenuation:{value:p?1:0},offset:{value:m},offsetLoop:{value:f?1:0},dashArray:{value:a},dashOffset:{value:o},dashRatio:{value:d},useDash:{value:a>0?1:0},scaleDown:{value:g/10},alphaTest:{value:b},alphaMap:{value:x},useAlphaMap:{value:x?1:0},repeat:{value:v},uRTCMode:{value:0},globalRTCCenter:{value:new y(0,0,0)}},vertexShader:si(_),fragmentShader:"\n #include <fog_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n\nuniform float useDash;\nuniform float dashArray;\nuniform float dashOffset;\nuniform float dashRatio;\nuniform sampler2D alphaMap;\nuniform float useAlphaMap;\n\nvarying vec2 vUV;\nvarying vec4 vColor;\nvarying float vCounters;\n\nuniform sampler2D map;\nuniform float useMap;\nuniform vec2 repeat;\nuniform float offsetLoop;\nuniform float alphaTest;\n\n\n\nvoid main()\t{\n\t#include <logdepthbuf_fragment>\n\n\tvec4 c = vColor;\n\n\tif( useMap == 1. ) c *= texture2D( map, vUV * repeat );\n\tif( useAlphaMap == 1. ) c.a *= texture2D( alphaMap, vUV * repeat ).r;\n\tif(offsetLoop!=1.0){\n if(vUV.x>1.0 || vUV.x<0.0){\n c.a = 0.0;\n }\n }\n if (c.a < alphaTest) discard;\n\tif( useDash == 1. ){\n\t\t\tc.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));\n\t}\n\tgl_FragColor = c;\n \t#include <fog_fragment>\n #include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}\n"})),u(this,"type","MeshLineMaterial")}get color(){return this.uniforms.color.value}set color(t){this.uniforms.color.value=new ht(t)}get opacity(){var t;return(null==(t=this.uniforms)?void 0:t.opacity.value)||1}set opacity(t){this.uniforms&&(this.uniforms.opacity.value=t)}get alphaTest(){return this.uniforms.alphaTest.value}set alphaTest(t){this.uniforms&&(this.uniforms.alphaTest.value=t)}get map(){return this.uniforms.map.value}set map(t){this.uniforms.map.value=t,this.uniforms.useMap.value=t?1:0}get repeat(){return this.uniforms.repeat.value}set repeat(t){this.uniforms.repeat.value.copy(t)}get lineWidth(){return this.uniforms.lineWidth.value}set lineWidth(t){this.uniforms.lineWidth.value=t}get sizeAttenuation(){return 1===this.uniforms.sizeAttenuation.value}set sizeAttenuation(t){this.uniforms.sizeAttenuation.value=t?1:0}}function oi(t,e){const n=new g,i=new M,s=new _,r=new y,o=this.geometry;if(s.copy(o.boundingSphere),s.applyMatrix4(this.matrixWorld),!t.ray.intersectSphere(s,r))return;n.copy(this.matrixWorld).invert(),i.copy(t.ray).applyMatrix4(n);const a=new y,h=new y,l=new y,c=this instanceof lt?2:1,u=o.index,d=o.attributes;if(null!==u){const n=u.array,s=d.position.array,o=d.width.array;for(let u=0,d=n.length-1;u<d;u+=c){const c=n[u],p=n[u+1];a.fromArray(s,3*c),h.fromArray(s,3*p);const f=void 0!==o[Math.floor(u/3)]?o[Math.floor(u/3)]:1,m=t.params.Line.threshold+this.material.lineWidth*f/2,y=m*m;if(i.distanceSqToSegment(a,h,r,l)>y)continue;r.applyMatrix4(this.matrixWorld);const g=t.ray.origin.distanceTo(r);g<t.near||g>t.far||(e.push({distance:g,point:l.clone().applyMatrix4(this.matrixWorld),index:u,face:null,faceIndex:void 0,object:this}),u=d)}}}const ai=t=>{var e;const{setPointWidth:n,nodes:i}=t,s=new ii;return s.setPoints(i,n,null!=(e=t.resetCenter)&&e),s},hi=/* @__PURE__ */new WeakMap,li=/* @__PURE__ */new Map;let ci=class extends Ln{constructor(t={}){super(),u(this,"options"),this.options=h({},t)}get material(){var t;return null==(t=this.object3d)?void 0:t.material}create(){return d(this,null,function*(){const{nodes:t,nodesArr:e,geometry:n,geometryArr:i,material:s,useGroups:r,setPointWidth:o,lineWidthArr:a,materialParameters:h}=this.options;let l=s,c=n;!l&&h&&(l=this.getMaterial(h)),!c&&t?c=ai({nodes:t,setPointWidth:o}):!c&&e?c=Rn(e.map((t,e)=>{let n=o;return!n&&a&&(n=()=>{var t;return null!=(t=a[e])?t:a[0]}),ai({nodes:t,setPointWidth:n})}),null!=r?r:0):!c&&i&&i.length>1?c=Rn(i,null!=r?r:0):!c&&i&&1===i.length&&([c]=i),this.createMesh(c,l)})}setGeometry(t,e){const n=ai({nodes:t,setPointWidth:e}),i=this.object3d,s=i.geometry;i.geometry=n,s.dispose()}getMaterial(t){const{width:e,height:n}=this.pencil.getSize(),i=new ri(h({color:new ht("#ffffff")},t));return i.uniforms.resolution.value.set(e,n),i}addGeometries(t){const e=this.object3d,n=Rn([e.geometry,...t]);e.geometry=n}resize(t,e){var n,i;null==(i=null==(n=this.material)?void 0:n.uniforms)||i.resolution.value.set(t,e)}handleMaterialChange(t){if(t){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}}animate({duration:t=1e3,delay:e=0,repeat:n=0,lineLoop:i,onRepeat:s,onUpdate:r,onComplete:o,startShow:a}={}){const{offset:h,offsetLoop:l}=this.material.uniforms,c=this.pencil.userData.debugLine?li:hi;if(c.get(this.material)&&this.stopAnimation(),0===t)return;const u=null==i||i;h.value.x=1,l.value=u&&a?1:0;let d=0;const p=new Vt.Tween(h.value).to({x:-1},t).delay(e).repeat(n).onUpdate(({x:t})=>{u&&t<=0&&0===l.value&&(l.value=1),null==r||r(t)}).onRepeat(()=>{d+=1,null==s||s(d)}).onComplete(()=>{null==o||o()}).start();c.set(this.material,p),this.material.addEventListener("dispose",()=>{this.stopAnimation()}),this.pencil.userData.debugLine&&console.log("animate",li.size)}stopAnimation(){const t=this.pencil.userData.debugLine?li:hi,e=t.get(this.material);e&&(e.stop(),Vt.remove(e),t.delete(this.material),this.material.uniforms.offset.value.x=0,this.material.uniforms.offsetLoop.value=1),this.pencil.userData.debugLine&&console.log("stopAnimation",li.size)}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}};const ui=t=>{const{points:e}=t,n=e.reduce((t,n,i)=>(i<e.length-1&&t.push(n,e[i+1]),t),[]);return(new S).setFromPoints(n)},di=new ct,pi=new y,fi=new y,mi=new ct,yi=new ct,gi=new ct,xi=new y,bi=new g,vi=new ut,wi=new y,_i=new B,Mi=new _,Si=new ct;let Ai,Ti;function Ci(t,e,n){return Si.set(0,0,-e,1).applyMatrix4(t.projectionMatrix),Si.multiplyScalar(1/Si.w),Si.x=Ti/n.width,Si.y=Ti/n.height,Si.applyMatrix4(t.projectionMatrixInverse),Si.multiplyScalar(1/Si.w),Math.abs(Math.max(Si.x,Si.y))}class zi extends U{constructor(t=new Be,e){super(t,e),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const t=this.geometry,e=t.attributes.instanceStart,n=t.attributes.instanceEnd,i=new Float32Array(2*e.count);for(let r=0,o=0,a=e.count;r<a;r++,o+=2)pi.fromBufferAttribute(e,r),fi.fromBufferAttribute(n,r),i[o]=0===o?0:i[o-1],i[o+1]=i[o]+pi.distanceTo(fi);const s=new dt(i,2,1);return t.setAttribute("instanceDistanceStart",new pt(s,1,0)),t.setAttribute("instanceDistanceEnd",new pt(s,1,1)),this}raycast(t,e){const n=this.material.worldUnits,i=t.camera;null!==i||n||console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const s=void 0!==t.params.Line2&&t.params.Line2.threshold||0;Ai=t.ray;const r=this.matrixWorld,o=this.geometry,a=this.material;let h,l;if(Ti=a.linewidth+s,null===o.boundingSphere&&o.computeBoundingSphere(),Mi.copy(o.boundingSphere).applyMatrix4(r),n)h=.5*Ti;else{h=Ci(i,Math.max(i.near,Mi.distanceToPoint(Ai.origin)),a.resolution)}if(Mi.radius+=h,!1!==Ai.intersectsSphere(Mi)){if(null===o.boundingBox&&o.computeBoundingBox(),_i.copy(o.boundingBox).applyMatrix4(r),n)l=.5*Ti;else{l=Ci(i,Math.max(i.near,_i.distanceToPoint(Ai.origin)),a.resolution)}_i.expandByScalar(l),!1!==Ai.intersectsBox(_i)&&(n?function(t,e){const n=t.matrixWorld,i=t.geometry,s=i.attributes.instanceStart,r=i.attributes.instanceEnd;for(let o=0,a=Math.min(i.instanceCount,s.count);o<a;o++){vi.start.fromBufferAttribute(s,o),vi.end.fromBufferAttribute(r,o),vi.applyMatrix4(n);const i=new y,a=new y;Ai.distanceSqToSegment(vi.start,vi.end,a,i),a.distanceTo(i)<.5*Ti&&e.push({point:a,pointOnLine:i,distance:Ai.origin.distanceTo(a),object:t,face:null,faceIndex:o,uv:null,uv1:null})}}(this,e):function(t,e,n){const i=e.projectionMatrix,s=t.material.resolution,r=t.matrixWorld,o=t.geometry,a=o.attributes.instanceStart,h=o.attributes.instanceEnd,l=Math.min(o.instanceCount,a.count),c=-e.near;Ai.at(1,gi),gi.w=1,gi.applyMatrix4(e.matrixWorldInverse),gi.applyMatrix4(i),gi.multiplyScalar(1/gi.w),gi.x*=s.x/2,gi.y*=s.y/2,gi.z=0,xi.copy(gi),bi.multiplyMatrices(e.matrixWorldInverse,r);for(let u=0,d=l;u<d;u++){if(mi.fromBufferAttribute(a,u),yi.fromBufferAttribute(h,u),mi.w=1,yi.w=1,mi.applyMatrix4(bi),yi.applyMatrix4(bi),mi.z>c&&yi.z>c)continue;if(mi.z>c){const t=mi.z-yi.z,e=(mi.z-c)/t;mi.lerp(yi,e)}else if(yi.z>c){const t=yi.z-mi.z,e=(yi.z-c)/t;yi.lerp(mi,e)}mi.applyMatrix4(i),yi.applyMatrix4(i),mi.multiplyScalar(1/mi.w),yi.multiplyScalar(1/yi.w),mi.x*=s.x/2,mi.y*=s.y/2,yi.x*=s.x/2,yi.y*=s.y/2,vi.start.copy(mi),vi.start.z=0,vi.end.copy(yi),vi.end.z=0;const e=vi.closestPointToPointParameter(xi,!0);vi.at(e,wi);const o=P.lerp(mi.z,yi.z,e),l=o>=-1&&o<=1,d=xi.distanceTo(wi)<.5*Ti;if(l&&d){vi.start.fromBufferAttribute(a,u),vi.end.fromBufferAttribute(h,u),vi.start.applyMatrix4(r),vi.end.applyMatrix4(r);const e=new y,i=new y;Ai.distanceSqToSegment(vi.start,vi.end,i,e),n.push({point:i,pointOnLine:e,distance:Ai.origin.distanceTo(i),object:t,face:null,faceIndex:u,uv:null,uv1:null})}}}(this,i,e))}}onBeforeRender(t){const e=this.material.uniforms;e&&e.resolution&&(t.getViewport(di),this.material.uniforms.resolution.value.set(di.z,di.w))}}class Ei extends Ln{constructor(t={}){super(),u(this,"options"),this.options=h({},t)}get material(){var t;return null==(t=this.object3d)?void 0:t.material}create(){return d(this,null,function*(){const{points:t,pointsArr:e,geometry:n,geometryArr:i,material:s,useGroups:r,setPointWidth:o,lineWidthArr:a,materialParameters:h,instanceCount:l}=this.options;let c=s,u=n;!c&&h&&(c=this.getMaterial(h)),!u&&t?u=ui({points:t}):!u&&e?u=Rn(e.map(t=>ui({points:t})),null!=r?r:0):!u&&i&&i.length>1?u=Rn(i,null!=r?r:0):!u&&i&&1===i.length&&([u]=i);const d=(new Xt).fromLineSegments(new lt(u));if(this.pencil.options.WebGPUTHREE){l&&(d.instanceCount=l);const t=new zi(d,c);t.computeLineDistances(),this.object3d=t}else{const t=new Ne(d,c);t.computeLineDistances(),this.object3d=t}})}getMaterial(t){return new Yt(h({color:new ht("#ffffff")},t))}}const Oi=class t extends Ln{constructor(t){super(),u(this,"objectType","Node"),u(this,"options"),u(this,"pickObject"),u(this,"element"),u(this,"onNodePointerIndex",[]),this.options=h(h({},{type:"2d"}),t)}create(){const{position:t,children:e}=this.options,n=document.createElement("div");this.element=n,e&&n.appendChild(e),"3d"===this.options.type?this.createCSS3DObject(n):"3dSprite"===this.options.type?this.createCSS3DSprite(n):this.createCSS2DObject(n),t&&this.object3d.position.copy(t)}trackCollision(t=0){var e;null==(e=this.pencil.cssRendererController)||e.collisionManager.add(this,{priority:t})}untrackCollision(){var t;null==(t=this.pencil.cssRendererController)||t.collisionManager.remove(this)}setChildren(t){this.options.children=t,this.element.innerHTML="",this.element.appendChild(t)}showAndEnsureVisible(){const t=this.options.children;t&&(t.style.visibility="hidden",this.show(),setTimeout(()=>{t.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const t=this.options.children;if(!t)return;const e=t.getBoundingClientRect(),n=window.innerWidth,i=window.innerHeight,s=e.width,r=e.height;let o=0,a=0;s>n?e.left>0&&(o=-e.left):e.left<0?o=-e.left:e.right>n&&(o=n-e.right,e.left+o<0&&(o=-e.left)),r>i?e.top>0&&(a=-e.top):e.top<0?a=-e.top:e.bottom>i&&(a=i-e.bottom,e.top+a<0&&(a=-e.top)),0===o&&0===a||(t.style.transform=`translate(${o}px, ${a}px)`)}ensureVisible(){const e=this.options.children;e&&(e.style.transform&&(e.style.transform=""),t.observerMap.has(e)||(t.sharedObserver||(t.sharedObserver=new IntersectionObserver(e=>{e.forEach(e=>{const n=e.target,i=t.observerMap.get(n);i&&e.isIntersecting&&(i.moveElementToViewport(),t.observerMap.delete(n),t.sharedObserver&&(t.sharedObserver.unobserve(n),0===t.observerMap.size&&(t.sharedObserver.disconnect(),t.sharedObserver=void 0)))})})),t.observerMap.set(e,this),t.sharedObserver.observe(e)))}onPointerEvent(t,e){const n=this.lead.handlePickNode([this],t,e);this.onNodePointerIndex.push(n)}dispose(){this.untrackCollision();const e=this.options.children;e&&t.sharedObserver&&(t.observerMap.delete(e),t.sharedObserver.unobserve(e),0===t.observerMap.size&&(t.sharedObserver.disconnect(),t.sharedObserver=void 0)),this.onNodePointerIndex.forEach(t=>{this.lead.removePickNode(t)}),super.dispose()}};u(Oi,"sharedObserver"),u(Oi,"observerMap",/* @__PURE__ */new Map);let Pi=Oi;class Ni extends Ln{constructor(t){super(),u(this,"options"),this.options=h({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return d(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:n,material:i,percentDepth:s,activeIndex:r}=this.options,o=Math.max(...t),a=t.reduce((t,e)=>t+e,0);let h=Math.PI/2;t.forEach((t,r)=>{if(0===t)return;const l=2*Math.PI*(t/a),c=n[r],u=s?e*(t/o):e,d=this.createGeometry(u,l),p=i?i.clone():new ft({color:c});i&&p.color.set(c);const f=new U(d,p);f.userData.depth=u,f.userData.index=r,f.rotateZ(h),h+=l,this.add(f)}),-1!==r&&this.setActive(r)})}createGeometry(t,e){const{outRadius:n,innerRadius:i}=this.options,s=new I;s.moveTo(n,0),s.lineTo(i,0),s.absarc(0,0,i,0,e,!1),s.absarc(0,0,n,e,0,!0);return new Xn(s,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:n}=this.pencil.pick(t,this.object3d.children)||{},i=n?this.object3d.children.findIndex(t=>t===n):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const n=this.object3d.children[t];if(this.object3d.children.forEach(t=>{if((!n||n!==t)&&1!==t.scale.z){if(t.userData.levTween)return;t.userData.enTween&&(t.userData.enTween.stop(),t.userData.enTween=null);const e=new Vt.Tween(t.scale).to({z:1},100);t.userData.levTween=e,e.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const t=new Vt.Tween(n.scale).to({z:e},100);return n.userData.enTween=t,t.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new Vt.Tween(this.object3d.scale).to({z:1},1e3).easing(Vt.Easing.Sinusoidal.InOut).start()}}const Bi={name:"OutputShader",uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1},premultiplieAlpha:{value:0}},vertexShader:"\n\t\tprecision highp float;\n\n\t\tuniform mat4 modelViewMatrix;\n\t\tuniform mat4 projectionMatrix;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\t\n\t\tprecision highp float;\n\n\t\tuniform sampler2D tDiffuse;\n uniform float premultiplieAlpha;\n\n\t\t#include <tonemapping_pars_fragment>\n\t\t#include <colorspace_pars_fragment>\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tgl_FragColor = texture2D( tDiffuse, vUv );\n\n if (premultiplieAlpha == 1.0) {\n gl_FragColor.rgb *= gl_FragColor.a;\n } \n\n\t\t\t// tone mapping\n\n\t\t\t#ifdef LINEAR_TONE_MAPPING\n\n\t\t\t\tgl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( REINHARD_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( CINEON_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( ACES_FILMIC_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( AGX_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( NEUTRAL_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );\n\n\t\t\t#elif defined( CUSTOM_TONE_MAPPING )\n\n\t\t\t\tgl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );\n\n\t\t\t#endif\n\n\t\t\t// color space\n\n\t\t\t#ifdef SRGB_TRANSFER\n\n\t\t\t\tgl_FragColor = sRGBTransferOETF( gl_FragColor );\n\n\t\t\t#endif\n\n\t\t}"};class ki extends Le{constructor(){super();const t=Bi;this.uniforms=mt.clone(t.uniforms),this.material=new yt({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad?this.fsQuad=new Re(this.material):this._fsQuad&&(this._fsQuad=new Re(this.material))}}const Li=new ft({color:"black"}),Ri=new T({color:"black",sizeAttenuation:!1}),Ui=new T({color:"black",sizeAttenuation:!0}),ji=new gt({color:"black",sizeAttenuation:!0}),Di=new gt({color:"black",sizeAttenuation:!1}),Fi=new ri({color:"black",sizeAttenuation:!1,lineWidth:0}),Ii=new ht(0);class Vi{constructor(t){u(this,"renderer"),u(this,"scene"),u(this,"camera"),u(this,"finalComposer"),u(this,"bloomComposer"),u(this,"bloomComposerActive",!1),u(this,"renderPass"),u(this,"outputPass"),u(this,"bloomPass"),u(this,"ssaoPass"),u(this,"mixPass"),u(this,"options"),u(this,"active",!0),u(this,"bloomSelection",/* @__PURE__ */new Set),u(this,"bloomLayer",new vt),u(this,"bloomMaterials",{}),u(this,"bloomVisible",{}),u(this,"bloomComposerRenderIng",!1),u(this,"pipViewportState",null),this.options=t;const{rendererController:e,sceneController:n,cameraController:i,composerParams:s}=t,{renderer:r}=e;this.renderer=r;const{multisampling:o}=s,{maxSamples:a}=r.capabilities,h=r.getDrawingBufferSize(new N),l=new xt(h.width,h.height,{samples:Math.min(o,a),type:bt}),c=new Wt(r,l),d=this.getSize();c.setSize(d.width,d.height);const p=new Ht(n.scene,i.camera);c.addPass(p),this.scene=n.scene,this.camera=i.camera,this.finalComposer=c,this.renderPass=p,i.event.on("pageChange",t=>{this.changeCamera(t)}),n.event.on("pageChange",t=>{this.changeScene(t)})}changeCamera(t){this.renderPass.camera=t,this.camera=t}changeScene(t){this.renderPass.scene=t,this.ssaoPass&&(this.ssaoPass.scene=t),this.scene=t}addOutputPass(){const{premultiplieAlpha:t}=this.options.composerParams,e=new ki;this.outputPass=e,this.setPremultiplieAlpha(t),this.finalComposer.addPass(e)}setPremultiplieAlpha(t){this.outputPass&&(this.outputPass.uniforms.premultiplieAlpha.value=t?1:0)}addSSAOPass(t){const{scene:e,camera:n,renderer:i}=this,s=i.getSize(new N),r=s.width,o=s.height,a=new qt(e,n,r,o);a.kernelRadius=t.kernelRadius,a.minDistance=t.minDistance,a.maxDistance=t.maxDistance,this.ssaoPass=a,this.finalComposer.addPass(a)}addBloomPass(t){const{renderer:e}=this,{threshold:n,strength:i,radius:s,bloomAlphaType:r}=t,o=new Zt(new N(window.innerWidth,window.innerHeight),i,s,n);this.bloomPass=o;const a=new Wt(e);a.renderToScreen=!1,a.addPass(this.renderPass),a.addPass(o),this.bloomComposer=a;const h=(t=>{const e=new ke(new at({uniforms:{baseTexture:{value:null},bloomTexture:{value:t.renderTarget2.texture},bloomAlphaType:{value:0}},vertexShader:"\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",fragmentShader:"\n uniform sampler2D baseTexture;\n uniform sampler2D bloomTexture;\n uniform float bloomAlphaType;\n varying vec2 vUv;\n void main() {\n vec4 base_color = texture2D(baseTexture, vUv);\n vec4 bloom_color = texture2D(bloomTexture, vUv);\n if (bloomAlphaType == 0.0){\n float lum = 0.21 * bloom_color.r + 0.71 * bloom_color.g + 0.07 * bloom_color.b;\n gl_FragColor = vec4(base_color.rgb + bloom_color.rgb, max(base_color.a, lum));\n }else{\n gl_FragColor = ( base_color + vec4( 1.0 ) * bloom_color );\n }\n }\n ",defines:{}}),"baseTexture");return e.needsSwap=!0,e})(a);h.uniforms.bloomAlphaType.value=r,this.bloomComposer=a,this.finalComposer.addPass(h),this.mixPass=h,this.bloomLayer.set(1)}checkBloomComposerActive(){0===this.bloomSelection.size?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var n;null==(n=this.bloomComposer)||n.setSize(t,e),this.finalComposer.setSize(t,e)}setPixelRatio(t){var e;null==(e=this.bloomComposer)||e.setPixelRatio(t),this.finalComposer.setPixelRatio(t)}darkenNonBloomed(){const t=[],e=[];this.scene.children.forEach(n=>{n.isTransformControls||n.isTransformControlsRoot||"RectAreaLightHelper"===n.type?t.push(n):e.push(n)}),e.forEach(e=>{e.traverse(e=>{var n;const i=e,s=e,r=e;if(null==(n=i.material)?void 0:n.isShadowMaterial)t.push(i);else if(i.material&&!1===this.bloomLayer.test(i.layers)){if(!0===i.material.transparent&&(1!==i.material.opacity||i.material.alphaMap))return void t.push(i);this.bloomMaterials[i.uuid]=i.material,s.isSprite?s.material.sizeAttenuation?s.material=ji:s.material=Di:i.material instanceof ri?i.material=Fi:r.isPoints?r.material.sizeAttenuation?r.material=Ui:r.material=Ri:i.material=Li}})}),t.forEach(t=>{this.bloomVisible[t.uuid]=t.visible,t.visible=!1});const n=this.scene.background;n&&(this.scene.userData._backgroundOriginal=n,this.scene.background=Ii)}restoreNonBloomed(){if(this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]?(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid]):void 0!==this.bloomVisible[e.uuid]&&(e.visible=this.bloomVisible[e.uuid],delete this.bloomVisible[e.uuid])}),this.scene.background===Ii){const t=this.scene.userData._backgroundOriginal;t&&(this.scene.background=t,delete this.scene.userData._backgroundOriginal)}}finalComposerRender(){this.bloomComposerActive&&this.bloomComposer?(this.bloomComposerRenderIng=!0,this.mixPass.enabled=!0,this.darkenNonBloomed(),this.bloomComposer.render(),this.restoreNonBloomed(),this.bloomComposerRenderIng=!1):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render()}getSize(){return this.renderer.getSize(new N)}render(){if(!this.active)return;const{cameraController:t,rendererController:e,sceneController:n}=this.options;if(this.finalComposerRender(),this.pipViewportState){t.setPageActive(31),t.setAspect(this.pipViewportState.width/this.pipViewportState.height),e.setViewport(l(h({},this.pipViewportState),{scissor:!0,scissorTest:!0})),this.finalComposerRender(),t.setPageActive(n.activeIndex);const i=this.getSize();e.setViewport({x:0,y:0,width:i.width,height:i.height,scissor:!0,scissorTest:!1})}}dispose(){var t;this.bloomMaterials={},this.bloomVisible={},this.bloomSelection.clear(),this.finalComposer.dispose(),null==(t=this.bloomComposer)||t.dispose()}}const Wi=1,Hi=2,qi=4,Zi=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768,SCREEN_PAN:65536,TOUCH_SCREEN_PAN:131072,TOUCH_DOLLY_SCREEN_PAN:262144,TOUCH_ZOOM_SCREEN_PAN:524288}),Yi=0,Gi=1,Xi=-1;function $i(t){return t.isPerspectiveCamera}function Ji(t){return t.isOrthographicCamera}const Ki=2*Math.PI,Qi=Math.PI/2,ts=Math.PI/180;function es(t,e,n){return Math.max(e,Math.min(n,t))}function ns(t,e=1e-5){return Math.abs(t)<e}function is(t,e,n=1e-5){return ns(t-e,n)}function ss(t,e){return Math.round(t/e)*e}function rs(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function os(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function as(t,e,n,i,s=1/0,r){const o=2/(i=Math.max(1e-4,i)),a=o*r,h=1/(1+a+.48*a*a+.235*a*a*a);let l=t-e;const c=e,u=s*i;l=es(l,-u,u),e=t-l;const d=(n.value+o*l)*r;n.value=(n.value-o*d)*h;let p=e+(l+d)*h;return c-t>0==p>c&&(p=c,n.value=(p-c)/r),p}function hs(t,e,n,i,s=1/0,r,o){const a=2/(i=Math.max(1e-4,i)),h=a*r,l=1/(1+h+.48*h*h+.235*h*h*h);let c=e.x,u=e.y,d=e.z,p=t.x-c,f=t.y-u,m=t.z-d;const y=c,g=u,x=d,b=s*i,v=p*p+f*f+m*m;if(v>b*b){const t=Math.sqrt(v);p=p/t*b,f=f/t*b,m=m/t*b}c=t.x-p,u=t.y-f,d=t.z-m;const w=(n.x+a*p)*r,_=(n.y+a*f)*r,M=(n.z+a*m)*r;n.x=(n.x-a*w)*l,n.y=(n.y-a*_)*l,n.z=(n.z-a*M)*l,o.x=c+(p+w)*l,o.y=u+(f+_)*l,o.z=d+(m+M)*l;const S=y-t.x,A=g-t.y,T=x-t.z;return S*(o.x-y)+A*(o.y-g)+T*(o.z-x)>0&&(o.x=y,o.y=g,o.z=x,n.x=(o.x-y)/r,n.y=(o.y-g)/r,n.z=(o.z-x)/r),o}function ls(t,e){e.set(0,0),t.forEach(t=>{e.x+=t.clientX,e.y+=t.clientY}),e.x/=t.length,e.y/=t.length}function cs(t,e){return!!Ji(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class us{constructor(){this._listeners={}}addEventListener(t,e){const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}removeAllEventListeners(t){t?Array.isArray(this._listeners[t])&&(this._listeners[t].length=0):this._listeners={}}dispatchEvent(t){const e=this._listeners[t.type];if(void 0!==e){t.target=this;const n=e.slice(0);for(let e=0,i=n.length;e<i;e++)n[e].call(this,t)}}}const ds=1/8,ps=/Mac/.test(navigator.platform);let fs,ms,ys,gs,xs,bs,vs,ws,_s,Ms,Ss,As,Ts,Cs,zs,Es,Os,Ps,Ns,Bs,ks,Ls,Rs;class Us extends us{static install(t){fs=t.THREE,ms=Object.freeze(new fs.Vector3(0,0,0)),ys=Object.freeze(new fs.Vector3(0,1,0)),gs=Object.freeze(new fs.Vector3(0,0,1)),xs=new fs.Vector2,bs=new fs.Vector3,vs=new fs.Vector3,ws=new fs.Vector3,_s=new fs.Vector3,Ms=new fs.Vector3,Ss=new fs.Vector3,As=new fs.Vector3,Ts=new fs.Vector3,Cs=new fs.Vector3,zs=new fs.Spherical,Es=new fs.Spherical,Os=new fs.Box3,Ps=new fs.Box3,Ns=new fs.Sphere,Bs=new fs.Quaternion,ks=new fs.Quaternion,Ls=new fs.Matrix4,Rs=new fs.Raycaster}static get ACTION(){return Zi}constructor(t,e){super(),this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=Number.EPSILON,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.dollyDragInverted=!1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=Zi.NONE,this._viewport=null,this._changedDolly=0,this._changedZoom=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=new DOMRect,this._isDragging=!1,this._dragNeedsUpdate=!0,this._activePointers=[],this._lockedPointer=null,this._interactiveArea=new DOMRect(0,0,1,1),this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._lastDollyDirection=Yi,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new fs.Vector3,this._focalOffsetVelocity=new fs.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,n,i)=>{let s,r;if($i(this._camera)){const n=bs.copy(this._camera.position).sub(this._target),i=this._camera.getEffectiveFOV()*ts,o=n.length()*Math.tan(.5*i);s=this.truckSpeed*t*o/this._elementRect.height,r=this.truckSpeed*e*o/this._elementRect.height}else{if(!Ji(this._camera))return;{const n=this._camera;s=this.truckSpeed*t*(n.right-n.left)/n.zoom/this._elementRect.width,r=this.truckSpeed*e*(n.top-n.bottom)/n.zoom/this._elementRect.height}}i?(n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(s,0,!0),this.forward(-r,!0)):n?this.setFocalOffset(this._focalOffsetEnd.x+s,this._focalOffsetEnd.y+r,this._focalOffsetEnd.z,!0):this.truck(s,r,!0)},this._rotateInternal=(t,e)=>{const n=Ki*this.azimuthRotateSpeed*t/this._elementRect.height,i=Ki*this.polarRotateSpeed*e/this._elementRect.height;this.rotate(n,i,!0)},this._dollyInternal=(t,e,n)=>{const i=Math.pow(.95,-t*this.dollySpeed),s=this._sphericalEnd.radius,r=this._sphericalEnd.radius*i,o=es(r,this.minDistance,this.maxDistance),a=o-r;this.infinityDolly&&this.dollyToCursor?this._dollyToNoClamp(r,!0):this.infinityDolly&&!this.dollyToCursor?(this.dollyInFixed(a,!0),this._dollyToNoClamp(o,!0)):this._dollyToNoClamp(o,!0),this.dollyToCursor&&(this._changedDolly+=(this.infinityDolly?r:o)-s,this._dollyControlCoord.set(e,n)),this._lastDollyDirection=Math.sign(-t)},this._zoomInternal=(t,e,n)=>{const i=Math.pow(.95,t*this.dollySpeed),s=this._zoom,r=this._zoom*i;this.zoomTo(r,!0),this.dollyToCursor&&(this._changedZoom+=r-s,this._dollyControlCoord.set(e,n))},void 0===fs&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=t,this._yAxisUpSpace=(new fs.Quaternion).setFromUnitVectors(this._camera.up,ys),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=Zi.NONE,this._target=new fs.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new fs.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new fs.Spherical).setFromVector3(bs.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._lastDistance=this._spherical.radius,this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._lastZoom=this._zoom,this._nearPlaneCorners=[new fs.Vector3,new fs.Vector3,new fs.Vector3,new fs.Vector3],this._updateNearPlaneCorners(),this._boundary=new fs.Box3(new fs.Vector3(-1/0,-1/0,-1/0),new fs.Vector3(1/0,1/0,1/0)),this._cameraUp0=this._camera.up.clone(),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlCoord=new fs.Vector2,this.mouseButtons={left:Zi.ROTATE,middle:Zi.DOLLY,right:Zi.TRUCK,wheel:$i(this._camera)?Zi.DOLLY:Ji(this._camera)?Zi.ZOOM:Zi.NONE},this.touches={one:Zi.TOUCH_ROTATE,two:$i(this._camera)?Zi.TOUCH_DOLLY_TRUCK:Ji(this._camera)?Zi.TOUCH_ZOOM_TRUCK:Zi.NONE,three:Zi.TOUCH_TRUCK};const n=new fs.Vector2,i=new fs.Vector2,s=new fs.Vector2,r=t=>{if(!this._enabled||!this._domElement)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),n=(t.clientX-e.left)/(e.right-e.left),i=(t.clientY-e.top)/(e.bottom-e.top);if(n<this._interactiveArea.left||n>this._interactiveArea.right||i<this._interactiveArea.top||i>this._interactiveArea.bottom)return}const e="mouse"!==t.pointerType?null:(t.buttons&Wi)===Wi?Wi:(t.buttons&qi)===qi?qi:(t.buttons&Hi)===Hi?Hi:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&Wi)===Wi&&this._lockedPointer)return;const n={pointerId:t.pointerId,clientX:t.clientX,clientY:t.clientY,deltaX:0,deltaY:0,mouseButton:e};this._activePointers.push(n),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),this._isDragging=!0,u(t)},o=t=>{t.cancelable&&t.preventDefault();const e=t.pointerId,n=this._lockedPointer||this._findPointerById(e);if(n){if(n.clientX=t.clientX,n.clientY=t.clientY,n.deltaX=t.movementX,n.deltaY=t.movementY,this._state=0,"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else(!this._isDragging&&this._lockedPointer||this._isDragging&&(t.buttons&Wi)===Wi)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&qi)===qi&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Hi)===Hi&&(this._state=this._state|this.mouseButtons.right);d()}},a=t=>{const e=this._findPointerById(t.pointerId);if(!e||e!==this._lockedPointer){if(e&&this._disposePointer(e),"touch"===t.pointerType)switch(this._activePointers.length){case 0:this._state=Zi.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._state=Zi.NONE;p()}};let h=-1;const l=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===Zi.NONE)return;if(0!==this._interactiveArea.left||0!==this._interactiveArea.top||1!==this._interactiveArea.width||1!==this._interactiveArea.height){const e=this._domElement.getBoundingClientRect(),n=(t.clientX-e.left)/(e.right-e.left),i=(t.clientY-e.top)/(e.bottom-e.top);if(n<this._interactiveArea.left||n>this._interactiveArea.right||i<this._interactiveArea.top||i>this._interactiveArea.bottom)return}if(t.preventDefault(),this.dollyToCursor||this.mouseButtons.wheel===Zi.ROTATE||this.mouseButtons.wheel===Zi.TRUCK){const t=performance.now();h-t<1e3&&this._getClientRect(this._elementRect),h=t}const e=ps?-1:-3,n=1===t.deltaMode||t.ctrlKey?t.deltaY/e:t.deltaY/(10*e),i=this.dollyToCursor?(t.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,s=this.dollyToCursor?(t.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case Zi.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case Zi.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case Zi.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case Zi.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case Zi.DOLLY:this._dollyInternal(-n,i,s),this._isUserControllingDolly=!0;break;case Zi.ZOOM:this._zoomInternal(-n,i,s),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Us.ACTION.NONE){const e=t instanceof PointerEvent?t.pointerId:0,n=this._findPointerById(e);return n&&this._disposePointer(n),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),void this._domElement.ownerDocument.removeEventListener("pointerup",a)}t.preventDefault()}},u=t=>{if(!this._enabled)return;ls(this._activePointers,xs),this._getClientRect(this._elementRect),n.copy(xs),i.copy(xs);if(this._activePointers.length>=2){const t=xs.x-this._activePointers[1].clientX,e=xs.y-this._activePointers[1].clientY,n=Math.sqrt(t*t+e*e);s.set(0,n);const r=.5*(this._activePointers[0].clientX+this._activePointers[1].clientX),o=.5*(this._activePointers[0].clientY+this._activePointers[1].clientY);i.set(r,o)}if(this._state=0,t)if("pointerType"in t&&"touch"===t.pointerType)switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three}else this._lockedPointer||(t.buttons&Wi)!==Wi||(this._state=this._state|this.mouseButtons.left),(t.buttons&qi)===qi&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Hi)===Hi&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&Zi.ROTATE)!==Zi.ROTATE&&(this._state&Zi.TOUCH_ROTATE)!==Zi.TOUCH_ROTATE&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),(this._state&Zi.TRUCK)!==Zi.TRUCK&&(this._state&Zi.SCREEN_PAN)!==Zi.SCREEN_PAN&&(this._state&Zi.TOUCH_TRUCK)!==Zi.TOUCH_TRUCK&&(this._state&Zi.TOUCH_SCREEN_PAN)!==Zi.TOUCH_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&Zi.DOLLY)!==Zi.DOLLY&&(this._state&Zi.TOUCH_DOLLY)!==Zi.TOUCH_DOLLY&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&Zi.ZOOM)!==Zi.ZOOM&&(this._state&Zi.TOUCH_ZOOM)!==Zi.TOUCH_ZOOM&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_ZOOM_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&Zi.OFFSET)!==Zi.OFFSET&&(this._state&Zi.TOUCH_OFFSET)!==Zi.TOUCH_OFFSET&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET||(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},d=()=>{if(!this._enabled||!this._dragNeedsUpdate)return;this._dragNeedsUpdate=!1,ls(this._activePointers,xs);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:i.x-xs.x,r=t?-t.deltaY:i.y-xs.y;if(i.copy(xs),(this._state&Zi.ROTATE)!==Zi.ROTATE&&(this._state&Zi.TOUCH_ROTATE)!==Zi.TOUCH_ROTATE&&(this._state&Zi.TOUCH_DOLLY_ROTATE)!==Zi.TOUCH_DOLLY_ROTATE&&(this._state&Zi.TOUCH_ZOOM_ROTATE)!==Zi.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&Zi.DOLLY)===Zi.DOLLY||(this._state&Zi.ZOOM)===Zi.ZOOM){const t=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,e=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0,i=this.dollyDragInverted?-1:1;(this._state&Zi.DOLLY)===Zi.DOLLY?(this._dollyInternal(i*r*ds,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(i*r*ds,t,e),this._isUserControllingZoom=!0)}if((this._state&Zi.TOUCH_DOLLY)===Zi.TOUCH_DOLLY||(this._state&Zi.TOUCH_ZOOM)===Zi.TOUCH_ZOOM||(this._state&Zi.TOUCH_DOLLY_TRUCK)===Zi.TOUCH_DOLLY_TRUCK||(this._state&Zi.TOUCH_ZOOM_TRUCK)===Zi.TOUCH_ZOOM_TRUCK||(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)===Zi.TOUCH_DOLLY_SCREEN_PAN||(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)===Zi.TOUCH_ZOOM_SCREEN_PAN||(this._state&Zi.TOUCH_DOLLY_OFFSET)===Zi.TOUCH_DOLLY_OFFSET||(this._state&Zi.TOUCH_ZOOM_OFFSET)===Zi.TOUCH_ZOOM_OFFSET||(this._state&Zi.TOUCH_DOLLY_ROTATE)===Zi.TOUCH_DOLLY_ROTATE||(this._state&Zi.TOUCH_ZOOM_ROTATE)===Zi.TOUCH_ZOOM_ROTATE){const t=xs.x-this._activePointers[1].clientX,e=xs.y-this._activePointers[1].clientY,n=Math.sqrt(t*t+e*e),r=s.y-n;s.set(0,n);const o=this.dollyToCursor?(i.x-this._elementRect.x)/this._elementRect.width*2-1:0,a=this.dollyToCursor?(i.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&Zi.TOUCH_DOLLY)===Zi.TOUCH_DOLLY||(this._state&Zi.TOUCH_DOLLY_ROTATE)===Zi.TOUCH_DOLLY_ROTATE||(this._state&Zi.TOUCH_DOLLY_TRUCK)===Zi.TOUCH_DOLLY_TRUCK||(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)===Zi.TOUCH_DOLLY_SCREEN_PAN||(this._state&Zi.TOUCH_DOLLY_OFFSET)===Zi.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*ds,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*ds,o,a),this._isUserControllingZoom=!0)}(this._state&Zi.TRUCK)!==Zi.TRUCK&&(this._state&Zi.TOUCH_TRUCK)!==Zi.TOUCH_TRUCK&&(this._state&Zi.TOUCH_DOLLY_TRUCK)!==Zi.TOUCH_DOLLY_TRUCK&&(this._state&Zi.TOUCH_ZOOM_TRUCK)!==Zi.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&Zi.SCREEN_PAN)!==Zi.SCREEN_PAN&&(this._state&Zi.TOUCH_SCREEN_PAN)!==Zi.TOUCH_SCREEN_PAN&&(this._state&Zi.TOUCH_DOLLY_SCREEN_PAN)!==Zi.TOUCH_DOLLY_SCREEN_PAN&&(this._state&Zi.TOUCH_ZOOM_SCREEN_PAN)!==Zi.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&Zi.OFFSET)!==Zi.OFFSET&&(this._state&Zi.TOUCH_OFFSET)!==Zi.TOUCH_OFFSET&&(this._state&Zi.TOUCH_DOLLY_OFFSET)!==Zi.TOUCH_DOLLY_OFFSET&&(this._state&Zi.TOUCH_ZOOM_OFFSET)!==Zi.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{ls(this._activePointers,xs),i.copy(xs),this._dragNeedsUpdate=!1,(0===this._activePointers.length||1===this._activePointers.length&&this._activePointers[0]===this._lockedPointer)&&(this._isDragging=!1),0===this._activePointers.length&&this._domElement&&(this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this.dispatchEvent({type:"controlend"}))};this.lockPointer=()=>{this._enabled&&this._domElement&&(this.cancel(),this._lockedPointer={pointerId:-1,clientX:0,clientY:0,deltaX:0,deltaY:0,mouseButton:null},this._activePointers.push(this._lockedPointer),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.requestPointerLock(),this._domElement.ownerDocument.addEventListener("pointerlockchange",f),this._domElement.ownerDocument.addEventListener("pointerlockerror",m),this._domElement.ownerDocument.addEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.addEventListener("pointerup",a),u())},this.unlockPointer=()=>{var t,e,n;null!==this._lockedPointer&&(this._disposePointer(this._lockedPointer),this._lockedPointer=null),null===(t=this._domElement)||void 0===t||t.ownerDocument.exitPointerLock(),null===(e=this._domElement)||void 0===e||e.ownerDocument.removeEventListener("pointerlockchange",f),null===(n=this._domElement)||void 0===n||n.ownerDocument.removeEventListener("pointerlockerror",m),this.cancel()};const f=()=>{this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement||this.unlockPointer()},m=()=>{this.unlockPointer()};this._addAllEventListeners=t=>{this._domElement=t,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",r),this._domElement.addEventListener("pointercancel",a),this._domElement.addEventListener("wheel",l,{passive:!1}),this._domElement.addEventListener("contextmenu",c)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",r),this._domElement.removeEventListener("pointercancel",a),this._domElement.removeEventListener("wheel",l,{passive:!1}),this._domElement.removeEventListener("contextmenu",c),this._domElement.ownerDocument.removeEventListener("pointermove",o,{passive:!1}),this._domElement.ownerDocument.removeEventListener("pointerup",a),this._domElement.ownerDocument.removeEventListener("pointerlockchange",f),this._domElement.ownerDocument.removeEventListener("pointerlockerror",m))},this.cancel=()=>{this._state!==Zi.NONE&&(this._state=Zi.NONE,this._activePointers.length=0,p())},e&&this.connect(e),this.update(0)}get camera(){return this._camera}set camera(t){this._camera=t,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(t){this._enabled=t,this._domElement&&(t?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(t){this._spherical.radius===t&&this._sphericalEnd.radius===t||(this._spherical.radius=t,this._sphericalEnd.radius=t,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(t){this._spherical.theta===t&&this._sphericalEnd.theta===t||(this._spherical.theta=t,this._sphericalEnd.theta=t,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(t){this._spherical.phi===t&&this._sphericalEnd.phi===t||(this._spherical.phi=t,this._sphericalEnd.phi=t,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(t){this._boundaryEnclosesCamera=t,this._needsUpdate=!0}set interactiveArea(t){this._interactiveArea.width=es(t.width,0,1),this._interactiveArea.height=es(t.height,0,1),this._interactiveArea.x=es(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=es(t.y,0,1-this._interactiveArea.height)}addEventListener(t,e){super.addEventListener(t,e)}removeEventListener(t,e){super.removeEventListener(t,e)}rotate(t,e,n=!1){return this.rotateTo(this._sphericalEnd.theta+t,this._sphericalEnd.phi+e,n)}rotateAzimuthTo(t,e=!1){return this.rotateTo(t,this._sphericalEnd.phi,e)}rotatePolarTo(t,e=!1){return this.rotateTo(this._sphericalEnd.theta,t,e)}rotateTo(t,e,n=!1){this._isUserControllingRotate=!1;const i=es(t,this.minAzimuthAngle,this.maxAzimuthAngle),s=es(e,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=i,this._sphericalEnd.phi=s,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,n||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const r=!n||is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(r)}dolly(t,e=!1){return this.dollyTo(this._sphericalEnd.radius-t,e)}dollyTo(t,e=!1){return this._isUserControllingDolly=!1,this._lastDollyDirection=Yi,this._changedDolly=0,this._dollyToNoClamp(es(t,this.minDistance,this.maxDistance),e)}_dollyToNoClamp(t,e=!1){const n=this._sphericalEnd.radius;if(this.colliderMeshes.length>=1){const e=this._collisionTest(),i=is(e,this._spherical.radius);if(!(n>t)&&i)return Promise.resolve();this._sphericalEnd.radius=Math.min(t,e)}else this._sphericalEnd.radius=t;this._needsUpdate=!0,e||(this._spherical.radius=this._sphericalEnd.radius);const i=!e||is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(_s).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const n=!e||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}zoom(t,e=!1){return this.zoomTo(this._zoomEnd+t,e)}zoomTo(t,e=!1){this._isUserControllingZoom=!1,this._zoomEnd=es(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const n=!e||is(this._zoom,this._zoomEnd,this.restThreshold);return this._changedZoom=0,this._createOnRestPromise(n)}pan(t,e,n=!1){return console.warn("`pan` has been renamed to `truck`"),this.truck(t,e,n)}truck(t,e,n=!1){this._camera.updateMatrix(),Ms.setFromMatrixColumn(this._camera.matrix,0),Ss.setFromMatrixColumn(this._camera.matrix,1),Ms.multiplyScalar(t),Ss.multiplyScalar(-e);const i=bs.copy(Ms).add(Ss),s=vs.copy(this._targetEnd).add(i);return this.moveTo(s.x,s.y,s.z,n)}forward(t,e=!1){bs.setFromMatrixColumn(this._camera.matrix,0),bs.crossVectors(this._camera.up,bs),bs.multiplyScalar(t);const n=vs.copy(this._targetEnd).add(bs);return this.moveTo(n.x,n.y,n.z,e)}elevate(t,e=!1){return bs.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+bs.x,this._targetEnd.y+bs.y,this._targetEnd.z+bs.z,e)}moveTo(t,e,n,i=!1){this._isUserControllingTruck=!1;const s=bs.set(t,e,n).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,s,this.boundaryFriction),this._needsUpdate=!0,i||this._target.copy(this._targetEnd);const r=!i||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,n,i=!1){const s=bs.set(t,e,n).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius).add(this._targetEnd);return this.setPosition(s.x,s.y,s.z,i)}fitToBox(t,e,{cover:n=!1,paddingLeft:i=0,paddingRight:s=0,paddingBottom:r=0,paddingTop:o=0}={}){const a=[],h=t.isBox3?Os.copy(t):Os.setFromObject(t);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const l=ss(this._sphericalEnd.theta,Qi),c=ss(this._sphericalEnd.phi,Qi);a.push(this.rotateTo(l,c,e));const u=bs.setFromSpherical(this._sphericalEnd).normalize(),d=Bs.setFromUnitVectors(u,gs),p=is(Math.abs(u.y),1);p&&d.multiply(ks.setFromAxisAngle(ys,l)),d.multiply(this._yAxisUpSpaceInverse);const f=Ps.makeEmpty();vs.copy(h.min).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setX(h.max.x).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setY(h.max.y).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setZ(h.min.z).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.min).setZ(h.max.z).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setY(h.min.y).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).setX(h.min.x).applyQuaternion(d),f.expandByPoint(vs),vs.copy(h.max).applyQuaternion(d),f.expandByPoint(vs),f.min.x-=i,f.min.y-=r,f.max.x+=s,f.max.y+=o,d.setFromUnitVectors(gs,u),p&&d.premultiply(ks.invert()),d.premultiply(this._yAxisUpSpace);const m=f.getSize(bs),y=f.getCenter(vs).applyQuaternion(d);if($i(this._camera)){const t=this.getDistanceToFitBox(m.x,m.y,m.z,n);a.push(this.moveTo(y.x,y.y,y.z,e)),a.push(this.dollyTo(t,e)),a.push(this.setFocalOffset(0,0,0,e))}else if(Ji(this._camera)){const t=this._camera,i=t.right-t.left,s=t.top-t.bottom,r=n?Math.max(i/m.x,s/m.y):Math.min(i/m.x,s/m.y);a.push(this.moveTo(y.x,y.y,y.z,e)),a.push(this.zoomTo(r,e)),a.push(this.setFocalOffset(0,0,0,e))}return Promise.all(a)}fitToSphere(t,e){const n=[],i="isObject3D"in t?Us.createBoundingSphere(t,Ns):Ns.copy(t);if(n.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),$i(this._camera)){const t=this.getDistanceToFitSphere(i.radius);n.push(this.dollyTo(t,e))}else if(Ji(this._camera)){const t=this._camera.right-this._camera.left,s=this._camera.top-this._camera.bottom,r=2*i.radius,o=Math.min(t/r,s/r);n.push(this.zoomTo(o,e))}return n.push(this.setFocalOffset(0,0,0,e)),Promise.all(n)}setLookAt(t,e,n,i,s,r,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Yi,this._changedDolly=0;const a=vs.set(i,s,r),h=bs.set(t,e,n);this._targetEnd.copy(a),this._sphericalEnd.setFromVector3(h.sub(a).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const l=!o||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold)&&is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(l)}lerpLookAt(t,e,n,i,s,r,o,a,h,l,c,u,d,p=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._lastDollyDirection=Yi,this._changedDolly=0;const f=bs.set(i,s,r),m=vs.set(t,e,n);zs.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const y=ws.set(l,c,u),g=vs.set(o,a,h);Es.setFromVector3(g.sub(y).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(y,d));const x=Es.theta-zs.theta,b=Es.phi-zs.phi,v=Es.radius-zs.radius;this._sphericalEnd.set(zs.radius+v*d,zs.phi+b*d,zs.theta+x*d),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!p||is(this._target.x,this._targetEnd.x,this.restThreshold)&&is(this._target.y,this._targetEnd.y,this.restThreshold)&&is(this._target.z,this._targetEnd.z,this.restThreshold)&&is(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&is(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&is(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(w)}setPosition(t,e,n,i=!1){return this.setLookAt(t,e,n,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,i)}setTarget(t,e,n,i=!1){const s=this.getPosition(bs),r=this.setLookAt(s.x,s.y,s.z,t,e,n,i);return this._sphericalEnd.phi=es(this._sphericalEnd.phi,this.minPolarAngle,this.maxPolarAngle),r}setFocalOffset(t,e,n,i=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(t,e,n),this._needsUpdate=!0,i||this._focalOffset.copy(this._focalOffsetEnd);const s=!i||is(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&is(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&is(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}setOrbitPoint(t,e,n){this._camera.updateMatrixWorld(),Ms.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Ss.setFromMatrixColumn(this._camera.matrixWorldInverse,1),As.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=bs.set(t,e,n),s=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);Ms.multiplyScalar(r.x),Ss.multiplyScalar(r.y),As.multiplyScalar(r.z),bs.copy(Ms).add(Ss).add(As),bs.z=bs.z+s,this.dollyTo(s,!1),this.setFocalOffset(-bs.x,bs.y,-bs.z,!1),this.moveTo(t,e,n,!1)}setBoundary(t){if(!t)return this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),void(this._needsUpdate=!0);this._boundary.copy(t),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(t,e,n,i){null!==t?(this._viewport=this._viewport||new fs.Vector4,"number"==typeof t?this._viewport.set(t,e,n,i):this._viewport.copy(t)):this._viewport=null}getDistanceToFitBox(t,e,n,i=!1){if(cs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const s=t/e,r=this._camera.getEffectiveFOV()*ts,o=this._camera.aspect;return.5*((i?s>o:s<o)?e:t/o)/Math.tan(.5*r)+.5*n}getDistanceToFitSphere(t){if(cs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*ts,n=2*Math.atan(Math.tan(.5*e)*this._camera.aspect),i=1<this._camera.aspect?e:n;return t/Math.sin(.5*i)}getTarget(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new fs.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new fs.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Ki,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Ki),this._spherical.theta+=Ki*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Ki)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!is(this._camera.up.x,this._cameraUp0.x)||!is(this._camera.up.y,this._cameraUp0.y)||!is(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(bs);this.updateCameraUp(),this.setPosition(t.x,t.y,t.z)}const e=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,t),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,t),this.zoomTo(this._zoom0,t)];return Promise.all(e)}saveState(){this._cameraUp0.copy(this._camera.up),this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,ys),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=bs.subVectors(this._target,this._camera.position).normalize(),e=vs.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const n=this.getPosition(bs);this.updateCameraUp(),this.setPosition(n.x,n.y,n.z)}update(t){const e=this._sphericalEnd.theta-this._spherical.theta,n=this._sphericalEnd.phi-this._spherical.phi,i=this._sphericalEnd.radius-this._spherical.radius,s=Ts.subVectors(this._targetEnd,this._target),r=Cs.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ns(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=as(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(ns(n))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=as(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(ns(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=as(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(ns(s.x)&&ns(s.y)&&ns(s.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;hs(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(ns(r.x)&&ns(r.y)&&ns(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;hs(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(ns(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=as(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if($i(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,n=this._getCameraDirection(_s),i=bs.copy(n).cross(e.up).normalize();0===i.lengthSq()&&(i.x=1);const s=vs.crossVectors(i,n),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*ts*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=ws.copy(this._targetEnd).add(i.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(s.multiplyScalar(this._dollyControlCoord.y*r)),h=bs.copy(this._targetEnd).lerp(a,o),l=this._lastDollyDirection===Gi&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===Xi&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(l||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=vs.copy(n).multiplyScalar(-t);h.add(e)}this._boundary.clampPoint(h,h);const u=vs.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedDolly-=t,ns(this._changedDolly)&&(this._changedDolly=0)}else if(Ji(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,n=bs.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),i=vs.set(0,0,-1).applyQuaternion(e.quaternion),s=ws.copy(n).add(i.multiplyScalar(-n.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(_s),a=this._targetEnd.dot(o),h=bs.copy(this._targetEnd).lerp(s,r),l=h.dot(o),c=o.multiplyScalar(l-a);h.sub(c),this._boundary.clampPoint(h,h);const u=vs.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedZoom-=t,ns(this._changedZoom)&&(this._changedZoom=0)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0),this._dragNeedsUpdate=!0;const a=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,a),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target);(!ns(this._focalOffset.x)||!ns(this._focalOffset.y)||!ns(this._focalOffset.z))&&(Ms.setFromMatrixColumn(this._camera.matrix,0),Ss.setFromMatrixColumn(this._camera.matrix,1),As.setFromMatrixColumn(this._camera.matrix,2),Ms.multiplyScalar(this._focalOffset.x),Ss.multiplyScalar(-this._focalOffset.y),As.multiplyScalar(this._focalOffset.z),bs.copy(Ms).add(Ss).add(As),this._camera.position.add(bs),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),bs.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const h=this._needsUpdate;return h&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):h?(this.dispatchEvent({type:"update"}),ns(e,this.restThreshold)&&ns(n,this.restThreshold)&&ns(i,this.restThreshold)&&ns(s.x,this.restThreshold)&&ns(s.y,this.restThreshold)&&ns(s.z,this.restThreshold)&&ns(r.x,this.restThreshold)&&ns(r.y,this.restThreshold)&&ns(r.z,this.restThreshold)&&ns(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!h&&this._updatedLastTime&&(this._hasRested||(this._hasRested=!0,this.dispatchEvent({type:"rest"})),this.dispatchEvent({type:"sleep"})),this._lastDistance=this._spherical.radius,this._lastZoom=this._zoom,this._updatedLastTime=h,this._needsUpdate=!1,h}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:rs(this.maxDistance),minZoom:this.minZoom,maxZoom:rs(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:rs(this.maxPolarAngle),minAzimuthAngle:rs(this.minAzimuthAngle),maxAzimuthAngle:rs(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:bs.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(t,e=!1){const n=JSON.parse(t);this.enabled=n.enabled,this.minDistance=n.minDistance,this.maxDistance=os(n.maxDistance),this.minZoom=n.minZoom,this.maxZoom=os(n.maxZoom),this.minPolarAngle=n.minPolarAngle,this.maxPolarAngle=os(n.maxPolarAngle),this.minAzimuthAngle=os(n.minAzimuthAngle),this.maxAzimuthAngle=os(n.maxAzimuthAngle),this.smoothTime=n.smoothTime,this.draggingSmoothTime=n.draggingSmoothTime,this.dollySpeed=n.dollySpeed,this.truckSpeed=n.truckSpeed,this.dollyToCursor=n.dollyToCursor,this._target0.fromArray(n.target0),this._position0.fromArray(n.position0),this._zoom0=n.zoom0,this._focalOffset0.fromArray(n.focalOffset0),this.moveTo(n.target[0],n.target[1],n.target[2],e),zs.setFromVector3(bs.fromArray(n.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(zs.theta,zs.phi,e),this.dollyTo(zs.radius,e),this.zoomTo(n.zoom,e),this.setFocalOffset(n.focalOffset[0],n.focalOffset[1],n.focalOffset[2],e),this._needsUpdate=!0}connect(t){this._domElement?console.warn("camera-controls is already connected."):(this._addAllEventListeners(t),this._getClientRect(this._elementRect))}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_getTargetDirection(t){return t.setFromSpherical(this._spherical).divideScalar(this._spherical.radius).applyQuaternion(this._yAxisUpSpaceInverse)}_getCameraDirection(t){return this._getTargetDirection(t).negate()}_findPointerById(t){return this._activePointers.find(e=>e.pointerId===t)}_findPointerByMouseButton(t){return this._activePointers.find(e=>e.mouseButton===t)}_disposePointer(t){this._activePointers.splice(this._activePointers.indexOf(t),1)}_encloseToBoundary(t,e,n){const i=e.lengthSq();if(0===i)return t;const s=vs.copy(e).add(t),r=this._boundary.clampPoint(s,ws).sub(s),o=r.lengthSq();if(0===o)return t.add(e);if(o===i)return t;if(0===n)return t.add(e).add(r);{const i=1+n*o/e.dot(r);return t.add(vs.copy(e).multiplyScalar(i)).add(r.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if($i(this._camera)){const t=this._camera,e=t.near,n=t.getEffectiveFOV()*ts,i=Math.tan(.5*n)*e,s=i*t.aspect;this._nearPlaneCorners[0].set(-s,-i,0),this._nearPlaneCorners[1].set(s,-i,0),this._nearPlaneCorners[2].set(s,i,0),this._nearPlaneCorners[3].set(-s,i,0)}else if(Ji(this._camera)){const t=this._camera,e=1/t.zoom,n=t.left*e,i=t.right*e,s=t.top*e,r=t.bottom*e;this._nearPlaneCorners[0].set(n,s,0),this._nearPlaneCorners[1].set(i,s,0),this._nearPlaneCorners[2].set(i,r,0),this._nearPlaneCorners[3].set(n,r,0)}}_collisionTest(){let t=1/0;if(!(this.colliderMeshes.length>=1))return t;if(cs(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(_s);Ls.lookAt(ms,e,this._camera.up);for(let n=0;n<4;n++){const i=vs.copy(this._nearPlaneCorners[n]);i.applyMatrix4(Ls);const s=ws.addVectors(this._target,i);Rs.set(s,e),Rs.far=this._spherical.radius+1;const r=Rs.intersectObjects(this.colliderMeshes);0!==r.length&&r[0].distance<t&&(t=r[0].distance)}return t}_getClientRect(t){if(!this._domElement)return;const e=this._domElement.getBoundingClientRect();return t.x=e.left,t.y=e.top,this._viewport?(t.x+=this._viewport.x,t.y+=e.height-this._viewport.w-this._viewport.y,t.width=this._viewport.z,t.height=this._viewport.w):(t.width=e.width,t.height=e.height),t}_createOnRestPromise(t){return t?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(t=>{const e=()=>{this.removeEventListener("rest",e),t()};this.addEventListener("rest",e)}))}_addAllEventListeners(t){}_removeAllEventListeners(){}get dampingFactor(){return console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead."),0}set dampingFactor(t){console.warn(".dampingFactor has been deprecated. use smoothTime (in seconds) instead.")}get draggingDampingFactor(){return console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead."),0}set draggingDampingFactor(t){console.warn(".draggingDampingFactor has been deprecated. use draggingSmoothTime (in seconds) instead.")}static createBoundingSphere(t,e=new fs.Sphere){const n=e,i=n.center;Os.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&Os.expandByObject(t)}),Os.getCenter(i);let s=0;return t.traverseVisible(t=>{if(!t.isMesh)return;const e=t;if(!e.geometry)return;const n=e.geometry.clone();n.applyMatrix4(e.matrixWorld);const r=n.attributes.position;for(let o=0,a=r.count;o<a;o++)bs.fromBufferAttribute(r,o),s=Math.max(s,i.distanceToSquared(bs))}),n.radius=Math.sqrt(s),n}}class js extends Xe{constructor(t){super(),u(this,"options"),u(this,"autoRotateSpeed",0),this.options=t;const e={Vector2:N,Vector3:y,Vector4:ct,Quaternion:L,Matrix4:g,Spherical:_t,Box3:B,Sphere:_,Raycaster:wt};Us.install({THREE:e})}get cameraControls(){return this.controller}addCameraControls(t,e){const{domElement:n}=this.options.controlsParams,i=new Us(t,n);return i.setLookAt(0,0,400,0,0,0,!1),this.addController(i,e)}setPageActive(t){super.setPageActive(t,(t,e)=>{t.enabled=e})}removePage(t){super.removePage(t,t=>{t.dispose()})}enable(){this.activeControllerSet.forEach(t=>{t.enabled=!0})}disable(){this.activeControllerSet.forEach(t=>{t.enabled=!1})}update(t,e){super.update(t,e),this.autoRotateSpeed&&this.cameraControls&&(this.cameraControls.azimuthAngle+=this.autoRotateSpeed*t*P.DEG2RAD)}}class Ds{constructor(t={}){u(this,"labels",/* @__PURE__ */new Map),u(this,"options"),u(this,"lastUpdateTime",0),u(this,"camera"),u(this,"animationFrameId"),u(this,"isUpdating",!1),this.options=h({padding:2,enabled:!1,throttleTime:16,viewportMargin:50,stabilityBonus:50,fadeTime:200},t)}add(t,e={}){var n;this.options.enabled||console.warn("collision.enabled is false, please enable it before adding nodes."),this.labels.set(t,{node:t,priority:null!=(n=e.priority)?n:0,visible:!0})}remove(t){this.labels.delete(t)}setPriority(t,e){const n=this.labels.get(t);n&&(n.priority=e)}addBatch(t,e){t.forEach((t,n)=>{this.add(t,{priority:e?e(t,n):0})})}setEnabled(t){this.options.enabled=t,t||this.labels.forEach(t=>{this.setNodeVisibility(t.node,!0),t.visible=!0})}update(t){if(!this.options.enabled)return;const e=performance.now();e-this.lastUpdateTime<this.options.throttleTime||(this.lastUpdateTime=e,this.camera=t,this.isUpdating||(this.isUpdating=!0,this.animationFrameId=requestAnimationFrame(()=>{this.performCollisionDetection(),this.isUpdating=!1})))}forceUpdate(){this.camera&&this.performCollisionDetection()}performCollisionDetection(){const{padding:t,viewportMargin:e}=this.options,n=window.innerWidth,i=window.innerHeight,s=[];this.labels.forEach(t=>{const r=t.node.element;if(!r)return;const o=r.firstElementChild;if(!o)return;const a="0"===o.style.opacity;a&&(o.style.visibility="hidden",o.style.opacity="1");const h=o.getBoundingClientRect();if(a&&(o.style.opacity="0",o.style.visibility=""),0===h.width||0===h.height)return;h.right>=-e&&h.left<=n+e&&h.bottom>=-e&&h.top<=i+e?(t.bounds=h,s.push(t)):(this.setNodeVisibility(t.node,!1),t.visible=!1)});const{stabilityBonus:r}=this.options;s.sort((t,e)=>{const n=t.priority+(t.visible?r:0);return e.priority+(e.visible?r:0)-n});const o=[];for(const a of s){if(!a.bounds)continue;this.checkCollision(a.bounds,o,t)?(this.setNodeVisibility(a.node,!1),a.visible=!1):(this.setNodeVisibility(a.node,!0),a.visible=!0,o.push(a.bounds))}}checkCollision(t,e,n){for(const i of e)if(this.rectsIntersect(t,i,n))return!0;return!1}rectsIntersect(t,e,n){return!(t.right+n<e.left||t.left-n>e.right||t.bottom+n<e.top||t.top-n>e.bottom)}setNodeVisibility(t,e){const n=t.element;if(!n)return;const i=n.firstElementChild;if(!i)return;const{fadeTime:s}=this.options;s>0&&!i.style.transition&&(i.style.transition=`opacity ${s}ms ease-out`),i.style.opacity=e?"1":"0"}getVisibleCount(){let t=0;return this.labels.forEach(e=>{e.visible&&t++}),t}getTotalCount(){return this.labels.size}debugRun(){const{padding:t,viewportMargin:e}=this.options,n=window.innerWidth,i=window.innerHeight;console.log("=== CollisionManager debugRun ==="),console.log("padding:",t,"viewportMargin:",e);const s=[];this.labels.forEach(t=>{const r=t.node.element;if(!r)return void console.log("Skipping: wrapper is null");const o=r.firstElementChild;if(!o)return void console.log("Skipping: child element is null");const a="0"===o.style.opacity;a&&(o.style.visibility="hidden",o.style.opacity="1");const h=o.getBoundingClientRect();if(a&&(o.style.opacity="0",o.style.visibility=""),0===h.width||0===h.height)return void console.log("Skipping: rect is 0",h);const l=h.right>=-e&&h.left<=n+e&&h.bottom>=-e&&h.top<=i+e;console.log(`Entry priority=${t.priority}, inViewport=${l}`),l?(t.bounds=h,s.push(t)):(this.setNodeVisibility(t.node,!1),t.visible=!1)}),console.log("Entries in viewport:",s.length),s.sort((t,e)=>e.priority-t.priority),console.log("Sorted entries:",s.map(t=>t.priority));const r=[];for(const o of s){if(!o.bounds)continue;const e=this.checkCollision(o.bounds,r,t);console.log(`Processing priority=${o.priority}, hasCollision=${e}, occupiedRects.length=${r.length}`),e?(this.setNodeVisibility(o.node,!1),o.visible=!1):(this.setNodeVisibility(o.node,!0),o.visible=!0,r.push(o.bounds))}console.log("Final visible count:",this.getVisibleCount())}clear(){this.labels.clear()}dispose(){this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.labels.clear()}}const Fs={zIndex:"auto"};class Is{constructor(t,e){u(this,"css2Drenderer"),u(this,"css3Drenderer"),u(this,"container"),u(this,"collisionManager"),this.container=t,this.collisionManager=new Ds(null==e?void 0:e.collision)}addRenderer(t,e){const n=h(h({},Fs),e),i=n.container||this.container,s=i.offsetWidth,r=i.offsetHeight,o="css2d"===t?new Kt:new ee;o.domElement.style.position="absolute",o.domElement.style.top="0",o.domElement.style.pointerEvents="none",o.domElement.style.zIndex=n.zIndex,o.setSize(s,r),i.appendChild(o.domElement),"css2d"===t?this.css2Drenderer=o:"css3d"===t&&(this.css3Drenderer=o)}setSize(t,e){var n,i;null==(n=this.css2Drenderer)||n.setSize(t,e),null==(i=this.css3Drenderer)||i.setSize(t,e)}render(t,e){var n,i;null==(n=this.css2Drenderer)||n.render(t,e),null==(i=this.css3Drenderer)||i.render(t,e),this.collisionManager.update(e)}dispose(){var t,e;null==(t=this.css2Drenderer)||t.domElement.remove(),null==(e=this.css3Drenderer)||e.domElement.remove(),this.css2Drenderer=void 0,this.css3Drenderer=void 0,this.collisionManager.dispose()}}class Vs{constructor(t){u(this,"helpers",{}),u(this,"viewHelper"),u(this,"options"),this.options=t}add(t){const e=t.uuid,{sceneController:n}=this.options;let i=this.helpers[e];if(void 0===i){if(t.isScene)i=new Mt(100);else if(t.isCamera)i=new St(t);else if(t.isPointLight)i=new At(t,1);else if(t.isDirectionalLight)i=new Tt(t,1);else if(t.isSpotLight)i=new Ct(t);else if(t.isHemisphereLight)i=new zt(t,10);else if(t.isRectAreaLight)i=new Ue(t);else{const e=new B;if(e.setFromObject(t,!0),!1!==e.isEmpty())return;{i=new Et(e);const n=i.material;n.userData.object=t,n.userData.lastMatrixWorld=t.matrixWorld.clone(),n.depthTest=!1,n.transparent=!0}}n.scene.add(i),this.helpers[e]=i}}addViewHelper(){const{cameraController:t,container:e}=this.options,n=new je(t.camera,e);e.addEventListener("pointerdown",t=>{t.preventDefault(),n.handleClick(t)}),this.viewHelper=n}remove(t){var e;const n=t.uuid,{sceneController:i}=this.options;if(void 0!==this.helpers[n]){const t=this.helpers[n];i.scene.remove(t),delete this.helpers[n],null==(e=t.dispose)||e.call(t)}}removeAll(){Object.keys(this.helpers).forEach(t=>{this.remove({uuid:t})}),this.helpers={}}removeAllExcludeScene(){Object.keys(this.helpers).forEach(t=>{this.helpers[t]instanceof Mt||this.remove({uuid:t})})}update(t,e,n){var i,s;const{cameraController:r}=this.options;Object.values(this.helpers).forEach(t=>{if(t.update&&t.update(),t instanceof Et){const e=t.material,{object:n,lastMatrixWorld:i}=e.userData;if(n){!n.matrixWorld.equals(i||n.matrixWorld)&&(t.box.setFromObject(n,!0),e.userData.lastMatrixWorld=n.matrixWorld.clone())}}}),!0===(null==(i=this.viewHelper)?void 0:i.animating)&&(this.viewHelper.update(t),null==(s=e.cameraControls)||s.setPosition(...r.camera.position.toArray()),this.viewHelper.center.copy(n))}renderViewHelper(t){if(!this.viewHelper)return;const e=t.autoClear;t.autoClear=!1,this.viewHelper.render(t),t.autoClear=e}dispose(){var t;this.helpers={},null==(t=this.viewHelper)||t.dispose()}}function Ws(t){let e=!1,n=[];return(...i)=>{n=i,e||(e=!0,requestAnimationFrame(()=>{e=!1,t(...n)}))}}class Hs{constructor(t){var e;u(this,"pencil"),u(this,"enabled",!0),u(this,"pickFunctionsMap",/* @__PURE__ */new Map),u(this,"pickNodeFunctionsMap",/* @__PURE__ */new Map),u(this,"pickFunctionsMapIndex",-1),u(this,"pickNodeFunctionsMapIndex",-1),u(this,"activeObjects",/* @__PURE__ */new Set),u(this,"activeObject",null),u(this,"prevActiveObjects",/* @__PURE__ */new Set),u(this,"objCallbackMap",/* @__PURE__ */new Map),u(this,"pickListener",{move:!1,down:!1}),u(this,"hasEnterOnStopEvent",!1),u(this,"cursorObjects",/* @__PURE__ */new Map),u(this,"cursorListenerAdded",!1),u(this,"moveStopTimer",null),u(this,"moveStopDelay",150),u(this,"lastMoveEvent",null),u(this,"lastMoveActiveObjects",/* @__PURE__ */new Set),u(this,"lastMoveRealActiveObject",null),u(this,"triggeredEnterOnStopObjects",/* @__PURE__ */new Set),u(this,"domElement"),this.pencil=t,this.domElement=(null==(e=t.options.controls)?void 0:e.domElement)||t.options.container}addPickListener(t){const e=/* @__PURE__ */new Set(["move","enter","leave","enterOnStop"]),n=/* @__PURE__ */new Set(["down","downOutside","click"]);this.domElement.addEventListener(`pointer${t}`,Ws(i=>{var s;if(!this.enabled)return;i.preventDefault();const r="move"===t?e:n,o=[];if(this.pickFunctionsMap.forEach(t=>{r.has(t.type)&&o.push(l(h({},t),{objArr:t.objArr instanceof Function?t.objArr():t.objArr}))}),0===o.length)return;this.activeObjects.clear(),this.objCallbackMap.clear(),this.activeObject=null;const a=this.objCallbackMap;for(const t of o)for(const e of t.objArr){if(!e.object3d)continue;a.has(e)||a.set(e,/* @__PURE__ */new Map);const n=a.get(e);n.has(t.type)||n.set(t.type,[]),n.get(t.type).push(t.cb)}if(0===a.size)return;const c=[...a.keys()].map(t=>t.object3d),u=null==(s=this.pencil.pick(i,c,!1))?void 0:s.intersects;if(u&&0!==u.length){const e=u[0];this.processIntersection(e,i,t)}else"down"===t?this.handleDownOutside(i):"move"===t&&this.handleLeaveEvents(i);"move"===t&&this.hasEnterOnStopEvent&&(this.handleMoveStop(i),this.triggeredEnterOnStopObjects.forEach(t=>{this.activeObjects.has(t)||this.triggeredEnterOnStopObjects.delete(t)}));const d=this.prevActiveObjects;this.prevActiveObjects=this.activeObjects,this.activeObjects=d,this.activeObjects.clear()}),{passive:!1})}processIntersection(t,e,n){var i;const s=this.objCallbackMap,r=null!=(i=t.index)?i:-1;let o=t.object;for(;o;){const t=this.pencil.lead.objMap.get(o);t&&t.visible&&(this.activeObject||(this.activeObject=t),s.has(t)&&this.activeObjects.add(t)),o=o.parent}"move"===n?this.handleLeaveEvents(e):"down"===n&&this.handleDownOutside(e),this.processObjectHierarchy(e,n,r)}processObjectHierarchy(t,e,n){const i=this.objCallbackMap;let s=!1;const r=()=>{s=!0};for(const o of this.activeObjects){if(s)break;const a=i.get(o);if(a)if("move"===e){const e=a.get("enter");if(e&&!this.prevActiveObjects.has(o))for(const s of e)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});const i=a.get("move");if(i)for(const s of i)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n})}else{const e=a.get("down");if(e)for(const s of e)s({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});const i=a.get("click");if(i){const e=a=>{a.preventDefault();if(!s&&Math.abs(a.clientX-t.clientX)<=5&&Math.abs(a.clientY-t.clientY)<=5)for(const e of i)e({baseObject:o,realBaseObject:this.activeObject,mouseEvent:t,sp:r,intersectionIndex:n});this.domElement.removeEventListener("pointerup",e)};this.domElement.addEventListener("pointerup",e)}}}}handleLeaveEvents(t){this.objCallbackMap.forEach((e,n)=>{const i=e.get("leave");if(i&&this.prevActiveObjects.has(n)&&!this.activeObjects.has(n))for(const s of i)s({baseObject:n,mouseEvent:t})})}handleDownOutside(t){this.objCallbackMap.forEach((e,n)=>{const i=e.get("downOutside");if(i&&!this.activeObjects.has(n))for(const s of i)s({baseObject:n,mouseEvent:t})})}handleMoveStop(t){null!==this.moveStopTimer&&clearTimeout(this.moveStopTimer),this.lastMoveEvent=t,this.lastMoveActiveObjects.clear(),this.activeObjects.forEach(t=>{this.lastMoveActiveObjects.add(t)}),this.lastMoveRealActiveObject=this.activeObject,this.moveStopTimer=window.setTimeout(()=>{this.triggerEnterOnStop()},this.moveStopDelay)}triggerEnterOnStop(){if(!this.lastMoveEvent||0===this.lastMoveActiveObjects.size)return;const t=this.lastMoveEvent,e=this.objCallbackMap;let n=!1;const i=()=>{n=!0};for(const s of this.lastMoveActiveObjects){if(n)break;const r=e.get(s);if(!r)continue;const o=r.get("enterOnStop");if(o&&!this.triggeredEnterOnStopObjects.has(s)){this.triggeredEnterOnStopObjects.add(s);for(const e of o)e({baseObject:s,realBaseObject:this.lastMoveRealActiveObject,mouseEvent:t,sp:i})}}this.moveStopTimer=null}resetCursor(){this.domElement.style.cursor=""}addCursorListener(){if(this.cursorListenerAdded)return;this.cursorListenerAdded=!0;this.domElement.addEventListener("pointermove",Ws(t=>{var e;if(!this.enabled)return;0===this.cursorObjects.size&&this.resetCursor();const n=[...this.cursorObjects.keys()].filter(t=>t.object3d).map(t=>t.object3d);if(0===n.length)return void this.resetCursor();const i=this.pencil.pick(t,n,!1);if(!(null==(e=null==i?void 0:i.intersects)?void 0:e.length))return void this.resetCursor();let s=i.intersects[0].object;for(;s;){const t=this.pencil.lead.objMap.get(s);if(t&&this.cursorObjects.has(t))return void(this.domElement.style.cursor=this.cursorObjects.get(t));s=s.parent}this.resetCursor()}),{passive:!0})}enableCursor(t,e="pointer"){this.cursorObjects.set(t,e),this.addCursorListener()}disableCursor(t){this.cursorObjects.delete(t)}handlePick(t,e,n){let i=e;"mousemove"===i?i="move":"mouseenter"===i?i="enter":"mouseleave"===i&&(i="leave"),this.pickFunctionsMapIndex+=1;const s=this.pickFunctionsMapIndex;if(this.pickFunctionsMap.set(s,{objArr:t,type:i,cb:n}),"enterOnStop"===i&&(this.hasEnterOnStopEvent=!0),!this.pickListener.move){Array.from(this.pickFunctionsMap.values()).some(t=>["move","enter","leave","enterOnStop"].includes(t.type))&&(this.pickListener.move=!0,this.addPickListener("move"))}if(!this.pickListener.down){Array.from(this.pickFunctionsMap.values()).some(t=>["down","downOutside","click"].includes(t.type))&&(this.pickListener.down=!0,this.addPickListener("down"))}return s}removePick(t){this.pickFunctionsMap.delete(t),this.hasEnterOnStopEvent=Array.from(this.pickFunctionsMap.values()).some(t=>"enterOnStop"===t.type)}handlePickNode(t,e,n){if("downOutside"===e)return console.warn("handlePickNode:err:不支持 downOutside"),-1;this.pickNodeFunctionsMapIndex+=1;const i=this.pickNodeFunctionsMapIndex,s=t instanceof Function?t():t,r=[];for(const o of s){const t=o;t.element.style.pointerEvents="auto";const i=e=>{this.enabled&&(e.preventDefault(),n({baseObject:t,mouseEvent:e}))},s=`pointer${e}`;t.element.addEventListener(s,Ws(i),!1),r.push({arr:t,type:s,listener:i})}return this.pickNodeFunctionsMap.set(i,r),i}removePickNode(t){const e=this.pickNodeFunctionsMap.get(t);if(e){for(const t of e)t.arr.element.style.pointerEvents="none",t.arr.element.removeEventListener(t.type,t.listener,!1);this.pickNodeFunctionsMap.delete(t)}}dispose(){null!==this.moveStopTimer&&(clearTimeout(this.moveStopTimer),this.moveStopTimer=null),this.pickFunctionsMap.clear(),this.pickNodeFunctionsMap.clear(),this.activeObjects.clear(),this.prevActiveObjects.clear(),this.lastMoveActiveObjects.clear(),this.triggeredEnterOnStopObjects.clear(),this.objCallbackMap.clear(),this.cursorObjects.clear()}}class qs extends Hs{constructor(t,e){super(t),u(this,"objMap",/* @__PURE__ */new Map),u(this,"objects",/* @__PURE__ */new Map),u(this,"objectsPm",/* @__PURE__ */new Map),u(this,"objectWrapChindIdMap",/* @__PURE__ */new Map),u(this,"scene"),u(this,"mList"),u(this,"group"),u(this,"prefabGroup"),u(this,"objectNamesToFactories",/* @__PURE__ */new Map),this.mList=e.mList,this.scene=this.createBaseObject(e.scene||new Ot,{key:"@Scene",name:"场景",mList:!1}),this.group=this.createBaseObject(new R,{key:"@Group",name:"物体组",target:this.scene,mList:!1}),this.prefabGroup=this.createBaseObject(new R,{key:"@PrefabGroup",name:"预制组",target:this.scene,mList:!1})}get objectsPromise(){return this.objectsPm.values()}createBaseObject(t,e={}){const n=h({mList:!0},e);t instanceof R&&(t.raycast=(e,n)=>e.intersectObjects(t.children,!0,n));const i=new Ln;if(i.object3d=t,i.pencil=this.pencil,i.lead=this,i.mList=this.mList,n.key&&(i.key=n.key),!n.key&&n.target){if("@Scene"===n.target.key&&t instanceof Pt)i.key="@Camera";else{const t=this.objectWrapChindIdMap.get(n.target),e=void 0!==t?t+1:0;this.objectWrapChindIdMap.set(n.target,e),this.setBaseObjectKey(i,{type:`$p:__c__${e}`,uId:"$p:",key:"$p:"},n.target)}}return n.name&&(t.name=n.name),n.target&&!n.target.object3d.getObjectById(t.id)&&n.target.object3d.add(t),this.objects.set(i.key,i),this.objMap.set(i.object3d,i),n.mList&&(this.mList.proxyBaseObject(i),this.mList.addBaseObjectMap(i)),t.children&&t.children.forEach(t=>{this.createBaseObject(t,{target:i,mList:n.mList})}),this.pencil.event.emit("lead.draw",{baseObject:i}),i}init(t){return Object.keys(t).forEach(e=>{this.objectNamesToFactories.set(String(e),class{create(n={}){return new t[e](n)}})}),this}getObject(t,e){t.includes("#")&&console.warn("getObject:err:不支持 #",t);const{key:n}=e||{},i=`${t}${n?`#${n}`:""}`;return this.objects.get(i)}getAllObject(t,e){t.includes("#")&&console.warn("getAllObject:err:不支持 #",t);const{key:n}=e||{},i=`${t}${n?`#${n}`:""}`,s=[];return this.objects.forEach((t,e)=>{(e.startsWith(n?i:`${i}#`)||e===i)&&s.push(t)}),s}draw(t,e,n){return d(this,null,function*(){var i,s,r;const o=this.objectNamesToFactories.get(String(t));if(!o)throw new Error(`Unrecognized factory: ${String(t)}`);e||(e={}),void 0===e.target&&(e.target=n);const a=e.target,h=null!=(i=e.onTop)?i:0,l=null!=(s=e.prefab)&&s,c=null==(r=e.create)||r,u=(new o).create(e);let d;if(null===a)d=null;else if("string"==typeof a){const t=this.objects.get(a);if(!t)throw new Error(`Object with key "${a}" not found`);d=t}else d=(null==a?void 0:a.isBaseObject)?a:a||(l?this.prefabGroup:this.group);return!1===c?u.create=()=>{}:!0!==c&&(u.create=()=>{c(u)}),u.pencil=this.pencil,u.lead=this,u.mList=this.mList,u.isPrefab=l,u.objectType=`${t}`,u.objectOptions=e,this.setBaseObjectKey(u,{type:e.keyType,key:e.key,uId:e.uId},d),this.objectsPm.set(u,this.addBaseObject(u,d,h)),yield this.objectsPm.get(u),this.objectsPm.delete(u),u})}setBaseObjectKey(t,e,n){let i="",s=e.key,r=e.type||t.keyType||t.objectType,o=e.uId;return n&&((null==s?void 0:s.includes("$p:"))&&(s=s.replace("$p:",n.keyName||"")),(null==r?void 0:r.includes("$p:"))&&(r=r.replace("$p:",n.keyType||"")),(null==o?void 0:o.includes("$p:"))&&(o=o.replace("$p:",n.keyUId||""))),i=`${r}`,s&&o?i+=`#${s}-${o}`:(s||o)&&(i+=`#${s||o}`),this.objects.has(i)?this.setBaseObjectKey(t,{type:e.type,key:e.key,uId:De()},n):(t.key=i,t.keyType=r,t.keyUId=o,t.keyName=s,this.objects.set(i,t),i)}updateBaseObjectKey(t,e){const n=t.key;this.objects.delete(n);const i=t.parent,s=this.setBaseObjectKey(t,e,i);return this.pencil.event.emit("lead.updateKey",{baseObject:t,key:s,oldKey:n}),t.children.forEach(t=>{var e;if(t.key.includes("__c__")){const n=null==(e=/__c__(\d+)/.exec(t.key))?void 0:e[1];void 0!==n&&this.updateBaseObjectKey(t,{type:`$p:__c__${n}`,key:"$p:",uId:"$p:"})}}),s}addBaseObject(t,e,n){return d(this,null,function*(){if(yield t.create(),t.object3d){const i=t.object3d;i.material&&Array.isArray(i.material)&&(i.material=i.material.slice()),this.mList.proxyBaseObject(t),this.mList.addBaseObjectMap(t),n&&t.setTop(n),null!==e&&e.object3d.add(t.object3d),this.objMap.set(t.object3d,t),i.children.forEach(e=>{this.objMap.get(e)||this.createBaseObject(e,{target:t})})}t.render(),this.pencil.event.emit("lead.draw",{baseObject:t})})}erase(...t){this.handleErase(!0,...t)}eraseWithoutMaterial(...t){this.handleErase(!1,...t)}handleErase(t,...e){[...e].forEach(e=>{const n=[];if("string"==typeof e){const[t,i]=e.split("#");n.push(...this.getAllObject(t,{key:i}))}else n.push(e);n.forEach(e=>{e.disposeMaterialIfNotUsed=t,e.dispose()})}),this.pencil.event.emit("lead.erase")}update(t,e){this.objects.forEach(n=>{n.update(t,e)})}setSize(t,e){this.objects.forEach(n=>{n.resize(t,e)})}eraseAll(){this.group&&(this.objects.forEach(t=>{t.key.startsWith("Node")&&this.erase(t)}),this.erase(this.group))}dispose(){super.dispose(),this.scene.erase(),this.objects.forEach(t=>{t.erase()}),this.objects.clear(),this.objectsPm.clear(),this.objMap.clear(),this.objectWrapChindIdMap.clear(),this.objectNamesToFactories.clear()}}class Zs extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get lead(){return this.controller}addLead(t,e,n){const{pencil:i}=this.options,s=new qs(i,{scene:t,mList:e});return this.addController(s,n)}removePage(t){super.removePage(t,t=>{t.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.enabled=e})}setSize(t,e){this.controllerMap.forEach((n,i)=>{i.setSize(t,e)})}}class Ys extends Nt{constructor(t){super(t),u(this,"customResponseType"),this.customResponseType="json",super.setResponseType("blob")}setResponseType(t){return"json"===t||"arraybuffer"===t?this.customResponseType=t:super.setResponseType(t),this}load(t,e,n,i){return super.load(t,t=>{const n=t,s=new DecompressionStream("gzip"),r=n.stream().pipeThrough(s),o=new Response(r);"arraybuffer"===this.customResponseType?o.arrayBuffer().then(t=>{null==e||e(t)}).catch(t=>{i&&i(t)}):o.json().then(t=>{null==e||e(t)}).catch(t=>{i&&i(t)})},n,i)}}class Gs extends Bt{load(t,e,n,i){const s=document.createElement("video");s.preload="auto",s.autoplay=!1,s.loop=!1,s.muted=!0,s.setAttribute("webkit-playsinline","webkit-playsinline"),s.setAttribute("playsinline","");const r=new kt(s),o=()=>{s.removeEventListener("loadeddata",o,!1),s.removeEventListener("error",a,!1),r.needsUpdate=!0,e&&e(r),this.manager.itemEnd(t)},a=e=>{s.removeEventListener("loadeddata",o,!1),s.removeEventListener("error",a,!1),i&&i(e),this.manager.itemError(t),this.manager.itemEnd(t)};return s.addEventListener("loadeddata",o,!1),s.addEventListener("error",a,!1),s.src=this.path+t,this.manager.itemStart(t),r}}const Xs={images:["png","jpg","jpeg","ico","webp","avif"],media:["mp4","webm","ogg"],gltf:["gltf","glb"],json:["json","geojson"],gzipJson:["json.gzip","json.gz"],exr:["exr"],lottie:["lottie.json"]};class $s{constructor(t){u(this,"loadingManager"),u(this,"loaders",/* @__PURE__ */new Map),u(this,"loaderConfigs",/* @__PURE__ */new Map),u(this,"loadObj",[]),u(this,"delLoadArr",[]),u(this,"assets",/* @__PURE__ */new Map),u(this,"event",new p),u(this,"options"),u(this,"scene"),this.options=h({simpleTexture4deleted:!1,prefix:""},t),this.loadingManager=new Lt(()=>{},(t,e,n)=>{this.emit("progress",e,n)},t=>{console.warn(`Failed to load ${t}`)}),this.initLoaderConfigs()}initLoaderConfigs(){this.loaderConfigs.set("images",{create:t=>new Rt(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("media",{create:t=>new Gs(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gltf",{create:t=>new He(t),setPath:(t,e)=>t.setPath(e),requiresDraco:!0}),this.loaderConfigs.set("lottie",{create:t=>new qe(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gzipJson",{create:t=>new Ys(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("json",{create:t=>new Nt(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("exr",{create:t=>new We(t),setPath:(t,e)=>t.setPath(e)})}emit(t,...e){this.event.emit(t,...e)}on(t,e){this.event.on(t,e)}getAsset(t){const e=this.getAssetType(t);if(!e)return;const n=this.assets.get(t);if(!n){if(("images"===e||"media"===e||"exr"===e)&&this.options.simpleTexture4deleted&&this.delLoadArr.includes(t))return new w;console.warn(`Asset ${t} not found`)}return n}getAssetType(t){var e;const n=null==(e=t.split(".").pop())?void 0:e.toLowerCase();if(n){if(t.endsWith("lottie.json"))return"lottie";if(t.endsWith("json.gzip")||t.endsWith("json.gz"))return"gzipJson";for(const[t,e]of Object.entries(Xs))if(e.includes(n))return t}}getLoader(t,e){let n=t;if("gltf"===t&&(null==e?void 0:e.dracoPath)?n="dracoGltf":"json"!==t&&"gzipJson"!==t||"arraybuffer"!==(null==e?void 0:e.responseType)||(n=`${t}Buffer`),this.loaders.has(n))return this.loaders.get(n);const i="dracoGltf"===n?"gltf":"json"===n.replace("Buffer","")||"gzipJson"===n.replace("Buffer","")?n.replace("Buffer",""):n,s=this.loaderConfigs.get(i);if(!s)return null;let r;if("dracoGltf"===n){r=new He(this.loadingManager);const t=new Ve;t.setDecoderPath((null==e?void 0:e.dracoPath)||""),r.setDRACOLoader(t)}else r=s.create(this.loadingManager,e);return s.setPath&&this.options.prefix&&s.setPath(r,this.options.prefix),s.setResponseType&&(null==e?void 0:e.responseType)&&"dracoGltf"!==n&&s.setResponseType(r,e.responseType),this.loaders.set(n,r),r}add(t,e){"string"==typeof t&&(t=[t]),t.forEach(t=>{const n=h({src:t},e);this.loadObj.push(n)})}getSrcByAsset(t,e=this.assets){let n;return e.forEach((e,i)=>{e===t&&(n=i)}),n}get textureAssets(){const t=/* @__PURE__ */new Map;return this.assets.forEach((e,n)=>{(e instanceof w||e instanceof Ut||e.isVideoTexture)&&t.set(n,e)}),t}loadAll(){return d(this,null,function*(){const t=this.loadObj.filter(t=>!this.delLoadArr.includes(t.src));return yield Promise.all(t.map(t=>this.load(t.src,t)))})}load(t,e){return d(this,null,function*(){var n,i;const s=null!=(n=null==e?void 0:e.type)?n:this.getAssetType(t);if(!s)return;const r=!1!==(null==e?void 0:e.cache),o=Fe();if(r){if(this.assets.has(t))return this.assets.get(t);this.assets.set(t,o.promise)}const a=this.getLoader(s,e);try{const n=yield a.loadAsync(t);if(this.assets.set(t,n),o.resolve(n),"images"===s||"media"===s||"exr"===s||"lottie"===s){const t=null!=(i=null==e?void 0:e.anisotropy)?i:this.options.anisotropy;n.anisotropy=t}return n}catch(h){return o.reject(`Failed to load ${t}`),void this.assets.delete(t)}})}getUnusedAssets(){const{scene:t}=this.options;if(!t)return[...this.delLoadArr];const e=/* @__PURE__ */new Set,n=this.textureAssets;t.traverse(t=>{const i=t;if(i.material){(Array.isArray(i.material)?i.material:[i.material]).forEach(t=>{[t.map,t.emissiveMap,t.normalMap,t.roughnessMap,t.metalnessMap,t.aoMap].forEach(t=>{if(t){const i=this.getSrcByAsset(t,n);i&&e.add(i)}})})}});const i=new Set(this.textureAssets.keys());return e.forEach(t=>{i.delete(t)}),[...i,...this.delLoadArr]}dispose(){this.assets.forEach(t=>{t&&"function"==typeof t.dispose&&t.dispose()}),this.assets.clear(),this.loaders.forEach((t,e)=>{if("dracoGltf"===e&&t){const e=t.dracoLoader;e&&"function"==typeof e.dispose&&e.dispose()}t&&"function"==typeof t.dispose&&t.dispose()}),this.loaders.clear(),this.loaderConfigs.clear(),this.event.removeAllListeners(),this.delLoadArr.length=0,this.loadObj.length=0}}class Js extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get loader(){return this.controller}addLoader(t,e){const{loaderParams:n}=this.options,i=new $s(l(h({},n),{scene:t}));return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}class Ks{constructor(t){u(this,"pencil"),u(this,"materials",/* @__PURE__ */new Map),u(this,"fixBaseObjects",/* @__PURE__ */new Map),u(this,"materialBaseObjectMap",/* @__PURE__ */new Map),this.pencil=t}add(t,e){this.materials.set(t,e);const n={object3d:new Proxy({material:e},{set:(e,n,i)=>{var s;if("material"===n&&!(null==(s=this.pencil.composerController)?void 0:s.bloomComposerRenderIng)){const n=e.material;return e.material=i,this.materials.set(t,i),this.disposeMaterial(n),this.syncChangeMaterial(n,i),!0}return e[n]=i,!0}})};this.fixBaseObjects.set(t,n),this.pencil.event.emit("mList.add",{key:t,material:e,baseObject:n})}get(t){const e=this.materials.get(t);return e||console.warn(`Material with key "${t}" not found.`),e}getByName(t){for(const[,e]of this.materials.entries())if(e.name===t)return e;console.warn(`Material with name "${t}" not found.`)}getKey(t){for(const[e,n]of this.materials.entries())if(n===t)return e}getKeyByName(t){for(const[e,n]of this.materials.entries())if(n.name===t)return e;console.warn(`Material key with name "${t}" not found.`)}addMultiple(t,e){for(const[n,i]of Object.entries(e)){const e=`${t}#${n}`;i&&this.add(e,i)}}getMultiple(t){const e={},n=`${t}#`;let i=!1;for(const[s,r]of this.materials.entries())if(s.startsWith(n)){e[s.substring(n.length)]=r,i=!0}return i?e:null}copy(t,e,n={}){const i=this.get(t);if(!i)return console.warn(`Material with key "${t}" not found.`),null;const s=i.clone();return n.name&&(s.name=n.name),this.add(e,s),s}copyMultiple(t,e){const n={},i=`${t}#`;for(const[s,r]of this.materials.entries())if(s.startsWith(i)){const t=s.substring(i.length),o=r.clone();n[t]=o;const a=`${e}#${t}`;this.add(a,o)}return n}disposeMaterial(t){if(!t)return;const e=new Ke;e.track(Array.isArray(t)?t:[t]),e.dispose()}remove(t){const e=this.materials.get(t);e&&this.disposeMaterial(e),this.materials.delete(t),this.fixBaseObjects.delete(t),this.pencil.event.emit("mList.remove",{key:t,material:e})}removeByMaterial(t){[...this.materials.entries()].some(([e,n])=>n===t&&(this.remove(e),!0))}proxyBaseObject(t){const e=t.object3d;if(!e.material)return;this.applyColorSpaceToMaterials(e.material);const n=e=>{if("__isProxy"in e)return e;const n=new Proxy(e,{set:(e,n,i)=>{if("string"==typeof n&&!Number.isNaN(Number(n))){const s=Number(n);if(s>=0&&s<e.length){const n=e[s];return this.rmBaseObjectMap(t,n),e[s]=i,i&&(this.applyColorSpaceToMaterials(i),this.addBaseObjectMap(t)),!0}}return e[n]=i,!0}});return Object.defineProperty(n,"__isProxy",{value:!0,enumerable:!1}),n};t.materialList&&(Object.values(t.materialList).forEach(t=>{t&&this.applyColorSpaceToMaterials(t)}),t.materialList=new Proxy(t.materialList,{set:(e,n,i)=>{if("string"==typeof n){const s=e[n];return this.rmBaseObjectMap(t,s),e[n]=i,i&&(this.applyColorSpaceToMaterials(i),this.addBaseObjectMap(t)),!0}return e[n]=i,!0},get:(t,e)=>{if("string"==typeof e&&t[e]){const i=t[e];if(Array.isArray(i)){const s=n(i);return s!==i&&(t[e]=s),s}return i}return t[e]},deleteProperty:(e,n)=>{if("string"==typeof n&&e[n]){const i=e[n];this.rmBaseObjectMap(t,i)}return delete e[n],!0}}));const i=e.material,s="_enhancedMaterial";e[s]=i,Object.defineProperty(e,"material",{get:()=>{var t;const i=e[s];if(!(null==(t=this.pencil.composerController)?void 0:t.bloomComposerRenderIng)&&Array.isArray(i)){const t=n(i);return t!==i&&(e[s]=t),t}return i},set:n=>{var i;if(null==(i=this.pencil.composerController)?void 0:i.bloomComposerRenderIng)e[s]=n;else{if(t.materialList&&Object.values(t.materialList).includes(n))return e[s]=n,void t.handleMaterialChange(n);this.rmBaseObjectMap(t),e[s]=n,n&&this.applyColorSpaceToMaterials(n),this.addBaseObjectMap(t)}t.handleMaterialChange(n)},enumerable:!0,configurable:!0})}applyColorSpaceToMaterials(t){cn({material:t})}material2array(t){return Array.isArray(t)?t:[t]}addBaseObjectMap(t){const e=t.object3d;e.material&&([...Object.values(t.materialList),e.material].forEach(e=>{if(e){this.material2array(e).forEach(e=>{const n=this.materialBaseObjectMap.get(e);n?n.add(t):this.materialBaseObjectMap.set(e,/* @__PURE__ */new Set([t]))})}}),this.pencil.event.emit("mList.addBaseObjectMap"))}rmBaseObjectMap(t,e,n=!0){const i=e&&this.material2array(e);this.materialBaseObjectMap.forEach((e,s)=>{i&&!i.includes(s)||e.has(t)&&(e.delete(t),0===e.size&&n&&(this.materialBaseObjectMap.delete(s),this.disposeMaterial(s)))}),this.pencil.event.emit("mList.rmBaseObjectMap")}getBaseObjectMap(t){return this.materialBaseObjectMap.get(t)||/* @__PURE__ */new Set}syncChangeMaterial(t,e){const n=this.materialBaseObjectMap.get(t);n&&n.forEach(n=>{const i=n.object3d,s=i.material;if(Array.isArray(s)){const n=s.indexOf(t);-1!==n&&(s[n]=e)}else s===t&&(i.material=e);n.materialList&&Object.keys(n.materialList).forEach(i=>{var s;const r=null==(s=n.materialList)?void 0:s[i];if(Array.isArray(r)){const n=r.indexOf(t);-1!==n&&(r[n]=e)}else r===t&&n.materialList&&(n.materialList[i]=e)})})}dispose(){const t=new Ke;t.track([...this.materials.values()]),t.dispose(),this.materials.clear(),this.fixBaseObjects.clear(),this.materialBaseObjectMap.clear()}}class Qs extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get mList(){return this.controller}addMList(t,e){const{pencil:n}=this.options,i=new Ks(n);return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const tr={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:on.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1};class er{constructor(t){u(this,"renderer"),u(this,"options"),this.options=t;const{width:e,height:n,rendererParams:i}=t,{alpha:s,devicePixelRatio:r,antialias:o,powerPreference:a,toneMappingExposure:h,outputColorSpace:l,logarithmicDepthBuffer:c,preserveDrawingBuffer:d,stencil:p,depth:f}=i,m=new jt({alpha:s,antialias:o,powerPreference:a,logarithmicDepthBuffer:c,preserveDrawingBuffer:d,stencil:p,depth:f});m.setSize(e,n),m.setPixelRatio(r),m.toneMappingExposure=h,m.outputColorSpace=l,this.renderer=m}setSize(t,e){this.renderer.setSize(t,e)}setPixelRatio(t){this.renderer.setPixelRatio(t)}render(t,e){this.renderer.render(t,e)}setViewport(t){var e,n;const{x:i,y:s,width:r,height:o}=t,a=null!=(e=t.scissor)&&e,h=null!=(n=t.scissorTest)&&n;this.renderer.setViewport(i,s,r,o),a&&(this.renderer.setScissor(i,s,r,o),this.renderer.setScissorTest(h))}dispose(){var t,e,n;this.setSize(0,0),null==(t=this.renderer)||t.clear(),null==(e=this.renderer)||e.dispose(),null==(n=this.renderer)||n.forceContextLoss()}}class nr extends Xe{constructor(t){super(),u(this,"options"),this.options=t}get scene(){return this.controller}addScene(t,e){const n=new Ot;return(null==t?void 0:t.background)&&(n.background=t.background),this.addController(n,e)}removePage(t){super.removePage(t,t=>{const e=new Ke;e.track(t),e.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.visible=e})}}class ir{constructor(t){u(this,"controls"),u(this,"event",new p);const{renderer:e,scene:n,camera:i}=t,s=new Ze(i,e.domElement);if(s.getHelper){const t=s.getHelper();if(n.add(t),+Dt<170){const t=s._root;t.dispose=()=>{t.traverse(t=>{t.geometry&&t.geometry.dispose(),t.material&&t.material.dispose()})},s.dispose=()=>{s.disconnect(),t.dispose()}}}else s instanceof v&&n.add(s);this.controls=s,this.addEvent()}get detach(){return this.controls.detach.bind(this.controls)}get attach(){return this.controls.attach.bind(this.controls)}addEvent(){let t=null,e=null,n=null;const i=this.controls;i.addEventListener("change",()=>{const t=i.object;void 0!==t&&this.event.emit("change",t)}),i.addEventListener("mouseDown",()=>{const s=i.object;t=s.position.clone(),e=s.rotation.clone(),n=s.scale.clone(),this.event.emit("mouseDown",s)}),i.addEventListener("mouseUp",()=>{const s=i.object;if(void 0!==s)switch(i.getMode()){case"translate":t.equals(s.position)||this.event.emit("translate",s,s.position,t);break;case"rotate":e.equals(s.rotation)||this.event.emit("rotate",s,s.rotation,e);break;case"scale":n.equals(s.scale)||this.event.emit("scale",s,s.scale,n)}this.event.emit("mouseUp")})}dispose(){var t;this.event.removeAllListeners(),null==(t=this.controls)||t.dispose()}}const sr={antialias:!0,devicePixelRatio:window.devicePixelRatio};class rr{constructor(t){u(this,"renderer"),u(this,"options"),this.options=t;const{width:e,height:n,rendererParams:i,renderer:s}=t,{devicePixelRatio:r,antialias:o}=i,a=new s({antialias:o});a.setSize(e,n),a.setPixelRatio(r),this.renderer=a}setSize(t,e){this.renderer.setSize(t,e)}render(t,e){this.renderer.render(t,e)}dispose(){var t,e;this.setSize(1,1),null==(t=this.renderer)||t.clear(),null==(e=this.renderer)||e.dispose()}}const or=class t{constructor(e){var n,i;u(this,"options"),u(this,"composerController"),u(this,"rendererController"),u(this,"cssRendererController"),u(this,"cameraController"),u(this,"controlsController"),u(this,"transformController"),u(this,"sceneController"),u(this,"helperController"),u(this,"loaderController"),u(this,"leadController"),u(this,"mListController"),u(this,"stats"),u(this,"resizeObserver"),u(this,"raycaster",new wt),u(this,"maxBackufferArea",33177600),u(this,"installPlugins",/* @__PURE__ */new Map),u(this,"_cameraPositon",new y),u(this,"_cameraTarget",new y),u(this,"event",new p),u(this,"timer",new Ft),u(this,"userData",{}),u(this,"TweenRaf"),u(this,"pageActiveIndex",0),u(this,"pages",new Ge),u(this,"userSetDprCache",1),u(this,"viewPadding",[0,0,0,0]),u(this,"pipCameraControls"),u(this,"_isDispose",!1),this.event.setMaxListeners(1/0),null==(i=(n=this.timer).connect)||i.call(n,document),this.options=f(t.options,e,{isMergeableObject:Cn}),this.userSetDprCache=this.options.renderer.devicePixelRatio;const{container:s,stats:r,transformControls:o}=this.options;if(this.init(),this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),o&&this.initTransformControls(),r){const t=new m({horizontal:!1});t.dom.style.position="absolute",t.init(this.renderer),s.appendChild(t.dom),this.stats=t}this.initResizeObserver(),this.tweenUpdateRaf()}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?2:this.renderer.capabilities.getMaxAnisotropy()}get controls(){return this.controlsController.cameraControls}get cameraPositon(){return this.controls.getPosition(this._cameraPositon,!1)}get cameraTarget(){return this.controls.getTarget(this._cameraTarget,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}get loader(){return this.loaderController.loader}get lead(){return this.leadController.lead}get mList(){return this.mListController.mList}tweenUpdateRaf(){Vt.update(),this.TweenRaf=requestAnimationFrame(this.tweenUpdateRaf.bind(this))}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):"function"==typeof t.install&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}addPage({sceneOptions:t,cameraOptions:e}={}){const n=this.pages.getMinDisabledLayer(),i=this.cameraController.addPerspectiveCamera(e,n),s=this.sceneController.addScene(t,n);s.add(i),this.controlsController.addCameraControls(i,n),this.loaderController.addLoader(s,n);const r=this.mListController.addMList(null,n);return this.leadController.addLead(s,r,n),this.pages.enable(n),n}removePage(t){this.controlsController.removePage(t),this.loaderController.removePage(t),this.leadController.removePage(t),this.cameraController.removePage(t),this.sceneController.removePage(t),this.mListController.removePage(t),this.pages.disable(t),this.pageActiveIndex===t&&(this.render(),this.showPage(0))}showPage(t){var e;if(t===this.pageActiveIndex)return;const n=this.scene;this.sceneController.setPageActive(t),n&&(null==(e=this.cssRendererController)||e.render(n,this.camera)),this.cameraController.setPageActive(t),this.controlsController.setPageActive(t),this.loaderController.setPageActive(t),this.mListController.setPageActive(t),this.leadController.setPageActive(t),this.pageActiveIndex=t}init(){var t;const{container:e,WebGPUTHREE:n,helper:i,viewHelper:s,renderer:r,controls:o,loader:a}=this.options,{width:c,height:u}=this.getSize(),d=n?new rr({width:c,height:u,renderer:this.options.WebGPURenderer,rendererParams:sr}):new er({width:c,height:u,rendererParams:l(h({},r),{antialias:!1})});this.rendererController=d;const p=new Je({width:c,height:u}),f=new nr({}),m=new js({controlsParams:{domElement:null!=(t=null==o?void 0:o.domElement)?t:d.renderer.domElement}}),y=new Js({loaderParams:h({anisotropy:this.maxAnisotropy},a)}),g=new Qs({pencil:this}),x=new Zs({pencil:this});this.sceneController=f,this.cameraController=p,this.controlsController=m,this.loaderController=y,this.mListController=g,this.leadController=x;const b=this.addPage({sceneOptions:this.options.scene,cameraOptions:this.options.camera});if(this.showPage(b),i){const t=new Vs({container:e,sceneController:f,cameraController:p});t.add(f.scene),this.helperController=t,s&&t.addViewHelper()}e.appendChild(d.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,ssao:n,ssaoParams:i,composer:s}=this.options,r=new Vi({rendererController:this.rendererController,sceneController:this.sceneController,cameraController:this.cameraController,composerParams:s});this.composerController=r,t&&r.addBloomPass(h({},e)),n&&r.addSSAOPass(h({},i)),r.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:n,css2DRendererParams:i,css3DRendererParams:s}=this.options;if(e||n){const r=new Is(t,i);e&&r.addRenderer("css2d",i),n&&r.addRenderer("css3d",s),this.cssRendererController=r}}initTransformControls(){const t=new ir({camera:this.camera,renderer:this.renderer,scene:this.scene});t.event.on("mouseDown",()=>{var t;null==(t=this.controlsController)||t.disable()}),t.event.on("mouseUp",()=>{var t;null==(t=this.controlsController)||t.enable()}),this.transformController=t}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=new ResizeObserver(t=>{for(const e of t){const t=e.contentRect;this.handeleResize(t.width,t.height),this.setDevicePixelRatio(this.userSetDprCache)}});e.observe(t),this.resizeObserver=e}handeleResize(t,e,n=!0){const{rendererController:i,cameraController:s,composerController:r,cssRendererController:o,leadController:a}=this,h=this.renderer.getSize(new N);h.x===t&&h.y===e||(s.setSize(t,e),i.setSize(t,e),null==r||r.setSize(t,e),null==o||o.setSize(t,e),a.setSize(t,e),this.installPlugins.forEach(n=>{var i;null==(i=n.setSize)||i.call(n,t,e)}),this.viewPadding.some(t=>0!==t)&&this.setViewPadding(...this.viewPadding),this.render(),n&&this.event.emit("resize",{width:t,height:e}))}setDevicePixelRatio(t){var e;this.userSetDprCache=t;const{width:n,height:i}=this.getSize();let s=Math.sqrt(this.maxBackufferArea/(n*i));s=(100*s|0)/100;const r=Math.min(t,s);r!==t&&console.warn("maxBackufferArea:",this.maxBackufferArea," the pixel ratio is set to",r);r!==this.renderer.getPixelRatio()&&(this.rendererController.setPixelRatio(r),null==(e=this.composerController)||e.setPixelRatio(r),this.viewPadding.some(t=>0!==t)&&this.setViewPadding(...this.viewPadding))}setViewPadding(t=0,e=0,n=0,i=0){const{width:s,height:r}=this.renderer.getSize(new N),o={x:i,y:n,width:s-i-e,height:r-t-n};this.rendererController.setViewport(o),this.cameraController.setAspect(o.width/o.height),this.viewPadding=[t,e,n,i]}pick(t,e,n=!0){const{raycaster:i,options:s}=this,{container:r}=s,o=new N,a=r.getBoundingClientRect();if(o.x=(t.clientX-a.left)/(a.right-a.left)*2-1,o.y=-(t.clientY-a.top)/(a.bottom-a.top)*2+1,this.camera&&this.scene){i.setFromCamera(o,this.camera);const t=i.intersectObjects(e||this.scene.children,n);if(t.length)return{object:t[0].object,index:t[0].index,intersects:t}}}render(){var t,e,n,i,s,r;if(!this.camera||!this.scene)return;this.event.emit("beforeRender"),this.timer.update(),Vt.update();const o=this.timer.getDelta(),a=this.timer.getElapsed();this.controlsController.update(o,a),this.leadController.update(o,a),this.installPlugins.forEach(t=>{var e;null==(e=t.update)||e.call(t,o,a)}),null==(t=this.helperController)||t.update(o,this.controlsController,this.cameraTarget),(null==(e=this.composerController)?void 0:e.active)?this.composerController.render():null==(n=this.rendererController)||n.render(this.scene,this.camera),null==(i=this.helperController)||i.renderViewHelper(this.renderer),null==(s=this.cssRendererController)||s.render(this.scene,this.camera),null==(r=this.stats)||r.update(),this.event.emit("render",{delta:o,elapsed:a})}start(){var t;window.cancelAnimationFrame(this.TweenRaf),null==(t=this.renderer)||t.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){var t;this.tweenUpdateRaf(),null==(t=this.renderer)||t.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){this.composerController.pipViewportState=t;let e=this.pipCameraControls;if(t){const{width:n,height:i}=this.getSize(),s=new DOMRect(t.x/n,(i-t.y-t.height)/i,t.width/n,t.height/i);if(e)e.enabled=!0,e.camera.position.copy(this.camera.position);else{const n=this.cameraController.cloneCamera(31);n.aspect=t.width/t.height,n.updateProjectionMatrix(),e=this.controlsController.addCameraControls(n,this.sceneController.activeIndex),e.addEventListener("update",()=>{this.controls.enabled=!1}),e.addEventListener("sleep",()=>{this.controls.enabled=!0}),this.pipCameraControls=e}e.interactiveArea=s}}dispose(){var t,e,n,i,s,r,o,a,h,l,c,u,d,p;this.handeleResize(1,1,!1),this.stop(),this.timer.dispose(),Vt.removeAll(),this.event.removeAllListeners(),null==(t=this.resizeObserver)||t.unobserve(this.options.container),this.installPlugins.forEach(t=>{var e;null==(e=t.dispose)||e.call(t)}),null==(e=this.controlsController)||e.dispose(),null==(n=this.transformController)||n.dispose(),null==(i=this.cssRendererController)||i.dispose(),null==(s=this.sceneController)||s.dispose(),null==(r=this.cameraController)||r.dispose(),null==(o=this.helperController)||o.dispose(),null==(a=this.composerController)||a.dispose(),null==(h=this.rendererController)||h.dispose(),null==(l=this.loaderController)||l.dispose(),null==(c=this.leadController)||c.dispose(),null==(u=this.mListController)||u.dispose(),this.cssRendererController=void 0,this.installPlugins.clear(),null==(d=this.stats)||d.dom.remove(),null==(p=this.renderer)||p.domElement.remove(),this._isDispose=!0}};u(or,"options",{stats:Ye,helper:Ye,viewHelper:Ye,controls:!0,transformControls:Ye,renderer:tr,composer:{multisampling:4,premultiplieAlpha:!1},scene:{background:null},camera:$e,bloom:!1,bloomParams:{threshold:0,strength:.4,radius:.1,bloomAlphaType:0},ssao:!1,loader:{prefix:""},ssaoParams:{kernelRadius:8,minDistance:.005,maxDistance:.1},css2DRenderer:!1,css2DRendererParams:h({},Fs),css3DRenderer:!1,css3DRendererParams:h({},Fs)});let ar=or;const hr={Scan:class{constructor(t,e={}){u(this,"options"),u(this,"object"),u(this,"uniforms"),u(this,"tween"),this.object=t,this.options=h(h({},{color:16777215,opacity:1,lineNum:10,lineWidth:1,lineHieght:10,fade:!1,fadeType:2,radius:0,range:new N(0,1),vertical:!1,step:0,pos:"bottom",duration:5e3,yoyo:!1,repeat:0}),e)}initMaterial(){const{color:t,lineNum:e,lineWidth:n,lineHieght:i,fade:s,fadeType:r,radius:o,range:a,vertical:h,step:l,opacity:c,exclude:u}=this.options,d={field:{value:new ct(0,0,0,0)},color:{value:new ht(t)},opacity:{value:c},lineNum:{value:e},lineWidth:{value:n},lineHieght:{value:i},sizeNum:{value:new y(o,o,o)},objPos:{value:new y(0,0,0)},fade:{value:s},fadeType:{value:r},range:{value:a},angle:{value:0},stepNum:{value:l}};if(!o){const{size:t}=this.object.getSize();d.sizeNum.value.copy(t)}this.uniforms=d,this.object.object3d.traverse(t=>{const e=t;!e.material||u&&u.includes(e)||(e.userData.materialO?e.material=e.userData.materialO.clone():e.userData.materialO=Array.isArray(e.material)?e.material.map(t=>t.clone()):e.material.clone(),Array.isArray(e.material)?e.material.forEach(t=>{h?this.setVerticalMaterial(t):this.setMaterial(t)}):h?this.setVerticalMaterial(e.material):this.setMaterial(e.material))})}setMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineNum=e.lineNum,t.uniforms.lineWidth=e.lineWidth,t.uniforms.sizeNum=e.sizeNum,t.uniforms.fade=e.fade,t.uniforms.fadeType=e.fadeType,t.uniforms.range=e.range,t.uniforms.stepNum=e.stepNum,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform int lineNum;\n uniform vec3 sizeNum;\n uniform float lineWidth;\n uniform float fade;\n uniform int fadeType;\n uniform vec2 range;\n uniform int stepNum;\n varying vec4 vWorldPos;\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n float height = sizeNum.y;\n bool isTop = field.y > vWorldPos.y;\n float worldDist = distance(field.y, vWorldPos.y);\n // bool isMix = isTop?\n // worldDist >= sizeNum.y * (1.0 -range):\n // worldDist <= sizeNum.y * range;\n float wMin = range.x * height;\n float wMax = range.y * height;\n bool isMix = worldDist >= wMin && worldDist <= wMax && field.w > 0.0;\n\n if(isMix){\n float stepf = sizeNum.y / float(lineNum);\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n for(int i=0; i<lineNum; i++){\n float fw = field.w- stepf * float(i) + (stepNum > 0? lineWidth : 0.0);\n float fadeout = smoothstep(fw -lineWidth, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n if(fade ==1.0 && fadeType == 2){\n fadeout = float(lineNum-i) * fadeout/ float(lineNum);\n }\n if (fade ==1.0 && fadeType == 1) {\n fadeout -= smoothstep(wMin, wMax, worldDist);\n }\n if(fadeout != 0.0){\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n break;\n }\n }\n }\n ")},t.needsUpdate=!0}setVerticalMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineNum=e.lineNum,t.uniforms.lineWidth=e.lineWidth,t.uniforms.lineHieght=e.lineHieght,t.uniforms.sizeNum=e.sizeNum,t.uniforms.fade=e.fade,t.uniforms.range=e.range,t.uniforms.angle=e.angle,t.uniforms.objPos=e.objPos,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform int lineNum;\n uniform vec3 sizeNum;\n uniform float lineWidth;\n uniform float lineHieght;\n uniform float fade;\n uniform vec2 range;\n uniform float angle;\n uniform vec3 objPos;\n varying vec4 vWorldPos;\n\n float aa(float x, float z,float a) {\n return(x - objPos.x)*cos(a) - (z - objPos.z)*sin(a) + objPos.x ;\n }\n\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n\n float worldDist = distance(field.y, vWorldPos.y);\n bool isTop = field.x > vWorldPos.x;\n float height = sizeNum.y;\n // bool isMix = isTop?\n // worldDist >= sizeNum.y * (1.0 -range):\n // worldDist <= sizeNum.y * range;\n float wMin = range.x * height;\n float wMax = range.y * height;\n bool isMix = worldDist >= wMin && worldDist <= wMax;\n\n\n if(isMix){\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n float gap =0.0;\n float sx= sqrt(pow(sizeNum.x,2.0)+pow(sizeNum.z,2.0));\n float worldDistx = distance(field.x, aa(vWorldPos.x,vWorldPos.z,angle));\n float stepf = sx / float(lineNum);\n float gapWidth = stepf-lineWidth;\n for(int i=0; i<lineNum; i++){\n float fw = sx - stepf * float(i);\n gap = smoothstep(fw - gapWidth, fw, worldDistx);\n gap -= smoothstep(fw, fw + f, worldDistx);\n gap = gap != 0.0 ? 1.0 : 0.0;\n if(gap != 0.0){\n // gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, gap);\n break;\n\n }\n }\n if(gap == 0.0){\n float fw = field.w;\n float fadeout = smoothstep(fw - lineHieght, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n }\n }\n\n ")},t.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(t=>{const e=t;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(t={}){this.stop();const e=Fe(!0),{object:n,uniforms:i}=this,{lineNum:s,step:r,lineWidth:a,pos:l,duration:c}=h(h({},this.options),t),{min:u,max:d,size:p}=n.getSize();let f=s,m=a;r>0&&(f=1,m=p.y/r);const g=i.sizeNum.value.y*(f>1?2:1);return this.tween=new Vt.Tween({latest:0}).to({latest:1},c).onStart(()=>{const t=new y;"bottom"===l?t.set(u.x-.001,u.y-.001,u.z-.001):"top"===l&&t.set(d.x+.001,d.y+.001,d.z+.001);const e=n.pencil.controls.azimuthAngle||0,s=this.object.object3d.position.clone();if(e){const n=Math.sqrt(o(p.x,2)+o(p.z,2))/2;t.x=s.x+n,t.z=s.z+n;const i=(new y).subVectors(t,s),r=new y(0,1,0);i.applyAxisAngle(r,e),t.addVectors(s,i)}i.objPos.value.copy(s),i.field.value.set(t.x,t.y,t.z,0),i.angle.value=e,i.lineNum.value=f,i.lineWidth.value=m}).onUpdate(({latest:t})=>{i.field.value.w=r>0?Math.floor(t*r)/r*g:t*g}).onStop(()=>{i.field.value.w=0,e.reject("stop")}).onComplete(()=>{e.resolve()}).start(),e.promise}checkRepeat(){return d(this,arguments,function*(t={}){const{yoyo:e,repeat:n,pos:i}=h(h({},this.options),t);n===this.options.repeat&&this.initMaterial();const{err:s}=yield this.play(t);if(s)this.resetMaterial();else if(n){let t=i;e&&(t="bottom"===t?"top":"bottom"),yield this.checkRepeat({pos:t,repeat:n===1/0?-1:n-1})}else this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}},Scan2:class{constructor(t,e={}){u(this,"options"),u(this,"object"),u(this,"uniforms"),u(this,"tween"),this.object=t,this.options=h(h({},{color:16777215,lineWidth:2,opacity:.5,fade:!1,position:new y(0,0,0),duration:5e3,repeat:0}),e)}initMaterial(){const{exclude:t}=this.options,e={field:{value:new ct(0,0,0,1e-4)},color:{value:new ht(this.options.color)},opacity:{value:this.options.opacity},lineWidth:{value:this.options.lineWidth}};this.uniforms=e,this.object.object3d.traverse(e=>{const n=e;!n.material||t&&t.includes(n)||(n.userData.materialO?n.material=n.userData.materialO:n.userData.materialO=Array.isArray(n.material)?n.material.map(t=>t.clone()):n.material.clone(),Array.isArray(n.material)?n.material.forEach(t=>{this.setMaterial(t)}):this.setMaterial(n.material))})}setMaterial(t){const{uniforms:e}=this;t.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineWidth=e.lineWidth,t.vertexShader=`\n varying vec4 vWorldPos;\n ${t.vertexShader}\n `.replace("#include <worldpos_vertex>","#include <worldpos_vertex>\n vWorldPos = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n vWorldPos = instanceMatrix * vWorldPos;\n #endif\n vWorldPos = modelMatrix * vWorldPos;\n "),t.fragmentShader=`\n uniform vec4 field;\n uniform vec3 fieldColor;\n uniform float fieldOpacity;\n uniform float lineWidth;\n \n varying vec4 vWorldPos;\n ${t.fragmentShader}\n `.replace("#include <dithering_fragment>","#include <dithering_fragment>\n \n float worldDist = distance(field.xyz, vWorldPos.xyz);\n float fadeoutWidth = lineWidth;\n vec3 posf = fwidth(vWorldPos.xyz);\n float f = length(posf);\n\n float fw = field.w;\n float fadeout = smoothstep(fw - fadeoutWidth, fw, worldDist);\n fadeout -= smoothstep(fw, fw + f, worldDist);\n if(fadeout!=0.0 && fieldOpacity!=-1.0) {\n fadeout = fieldOpacity;\n }\n gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);\n \n ")},t.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(t=>{const e=t;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(){this.stop();const t=Fe(!0),{object:e,uniforms:n}=this,{position:i,duration:s}=this.options;let{radius:r}=this.options;if(!r){const{size:t}=e.getSize();r=Math.max(t.x,t.y,t.z)}return this.tween=new Vt.Tween({a:1e-4}).to({a:1},s).onStart(()=>{n.field.value.set(i.x,i.y,i.z,1e-4),this.options.fade&&(n.opacity.value=this.options.opacity)}).onUpdate(({a:t})=>{n.field.value.w=t*r,this.options.fade&&(n.opacity.value=(1-t)*this.options.opacity)}).onStop(()=>{n.field.value.w=0,t.reject("stop")}).onComplete(()=>{t.resolve()}).start(),t.promise}checkRepeat(){return d(this,arguments,function*(t={}){const{repeat:e}=h(h({},this.options),t);e===this.options.repeat&&this.initMaterial();const{err:n}=yield this.play();n?this.resetMaterial():e?yield this.checkRepeat({repeat:e===1/0?-1:e-1}):this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}}},lr=t=>{const e=new S;return Object.keys(t).forEach(n=>{"groups"===n?t[n].forEach(t=>{e.addGroup(t.start,t.count,t.materialIndex)}):"index"===n?e.setIndex(new D(t[n].array,t[n].itemSize)):"globalCenter"===n?e.userData.globalCenter=t.globalCenter:e.setAttribute(n,new D(t[n].array,t[n].itemSize))}),e},cr='var t=Object.defineProperty,e=Object.defineProperties,n=Object.getOwnPropertyDescriptors,i=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,o=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),a=t=>{throw TypeError(t)},h=Math.pow,l=(e,n,i)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,u=(t,e)=>{for(var n in e||(e={}))r.call(e,n)&&l(t,n,e[n]);if(i)for(var n of i(e))s.call(e,n)&&l(t,n,e[n]);return t},c=(t,i)=>e(t,n(i)),d=(t,e)=>{var n={};for(var o in t)r.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(null!=t&&i)for(var o of i(t))e.indexOf(o)<0&&s.call(t,o)&&(n[o]=t[o]);return n},p=(t,e,n)=>l(t,"symbol"!=typeof e?e+"":e,n),f=function(t,e){this[0]=t,this[1]=e},y=t=>{var e,n=t[o("asyncIterator")],i=!1,r={};return null==n?(n=t[o("iterator")](),e=t=>r[t]=e=>n[t](e)):(n=n.call(t),e=t=>r[t]=e=>{if(i){if(i=!1,"throw"===t)throw e;return e}return i=!0,{done:!1,value:new f(new Promise(i=>{var r=n[t](e);r instanceof Object||a("Object expected"),i(r)}),1)}}),r[o("iterator")]=()=>r,e("next"),"throw"in n?e("throw"):r.throw=t=>{throw t},"return"in n&&e("return"),r};!function(){"use strict";const t="182",e=1001,n="srgb",i="srgb-linear",r="linear",s="srgb",o=7680,a=2e3;function l(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const f={};function m(...t){const e="THREE."+t.shift();console.warn(e,...t)}function g(...t){const e="THREE."+t.shift();console.error(e,...t)}function x(...t){const e=t.join(" ");e in f||(f[e]=!0,m(...t))}class b{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return void 0!==n&&(void 0!==n[t]&&-1!==n[t].indexOf(e))}removeEventListener(t,e){const n=this._listeners;if(void 0===n)return;const i=n[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}dispatchEvent(t){const e=this._listeners;if(void 0===e)return;const n=e[t.type];if(void 0!==n){t.target=this;const e=n.slice(0);for(let n=0,i=e.length;n<i;n++)e[n].call(this,t);t.target=null}}}const w=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let v=1234567;const M=Math.PI/180,S=180/Math.PI;function A(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(w[255&t]+w[t>>8&255]+w[t>>16&255]+w[t>>24&255]+"-"+w[255&e]+w[e>>8&255]+"-"+w[e>>16&15|64]+w[e>>24&255]+"-"+w[63&n|128]+w[n>>8&255]+"-"+w[n>>16&255]+w[n>>24&255]+w[255&i]+w[i>>8&255]+w[i>>16&255]+w[i>>24&255]).toLowerCase()}function z(t,e,n){return Math.max(e,Math.min(n,t))}function _(t,e){return(t%e+e)%e}function T(t,e,n){return(1-n)*t+n*e}function B(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function P(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const C={DEG2RAD:M,RAD2DEG:S,generateUUID:A,clamp:z,euclideanModulo:_,mapLinear:function(t,e,n,i,r){return i+(t-e)*(r-i)/(n-e)},inverseLerp:function(t,e,n){return t!==e?(n-t)/(e-t):0},lerp:T,damp:function(t,e,n,i){return T(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(_(t,2*e)-e)},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(v=t);let e=v+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*M},radToDeg:function(t){return t*S},isPowerOfTwo:function(t){return!(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,n,i,r){const s=Math.cos,o=Math.sin,a=s(n/2),h=o(n/2),l=s((e+i)/2),u=o((e+i)/2),c=s((e-i)/2),d=o((e-i)/2),p=s((i-e)/2),f=o((i-e)/2);switch(r){case"XYX":t.set(a*u,h*c,h*d,a*l);break;case"YZY":t.set(h*d,a*u,h*c,a*l);break;case"ZXZ":t.set(h*c,h*d,a*u,a*l);break;case"XZX":t.set(a*u,h*f,h*p,a*l);break;case"YXY":t.set(h*p,a*u,h*f,a*l);break;case"ZYZ":t.set(h*f,h*p,a*u,a*l);break;default:m("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:P,denormalize:B};class E{constructor(t=0,e=0){E.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(z(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,s=this.y-t.y;return this.x=r*n-s*i+t.x,this.y=r*i+s*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class k{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,r,s,o){let a=n[i+0],h=n[i+1],l=n[i+2],u=n[i+3],c=r[s+0],d=r[s+1],p=r[s+2],f=r[s+3];if(o<=0)return t[e+0]=a,t[e+1]=h,t[e+2]=l,void(t[e+3]=u);if(o>=1)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(u!==f||a!==c||h!==d||l!==p){let t=a*c+h*d+l*p+u*f;t<0&&(c=-c,d=-d,p=-p,f=-f,t=-t);let e=1-o;if(t<.9995){const n=Math.acos(t),i=Math.sin(n);e=Math.sin(e*n)/i,a=a*e+c*(o=Math.sin(o*n)/i),h=h*e+d*o,l=l*e+p*o,u=u*e+f*o}else{a=a*e+c*o,h=h*e+d*o,l=l*e+p*o,u=u*e+f*o;const t=1/Math.sqrt(a*a+h*h+l*l+u*u);a*=t,h*=t,l*=t,u*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,s){const o=n[i],a=n[i+1],h=n[i+2],l=n[i+3],u=r[s],c=r[s+1],d=r[s+2],p=r[s+3];return t[e]=o*p+l*u+a*d-h*c,t[e+1]=a*p+l*c+h*u-o*d,t[e+2]=h*p+l*d+o*c-a*u,t[e+3]=l*p-o*u-a*c-h*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,i=t._y,r=t._z,s=t._order,o=Math.cos,a=Math.sin,h=o(n/2),l=o(i/2),u=o(r/2),c=a(n/2),d=a(i/2),p=a(r/2);switch(s){case"XYZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"YXZ":this._x=c*l*u+h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"ZXY":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u-c*d*p;break;case"ZYX":this._x=c*l*u-h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u+c*d*p;break;case"YZX":this._x=c*l*u+h*d*p,this._y=h*d*u+c*l*p,this._z=h*l*p-c*d*u,this._w=h*l*u-c*d*p;break;case"XZY":this._x=c*l*u-h*d*p,this._y=h*d*u-c*l*p,this._z=h*l*p+c*d*u,this._w=h*l*u+c*d*p;break;default:m("Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],s=e[1],o=e[5],a=e[9],h=e[2],l=e[6],u=e[10],c=n+o+u;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(s-i)*t}else if(n>o&&n>u){const t=2*Math.sqrt(1+n-o-u);this._w=(l-a)/t,this._x=.25*t,this._y=(i+s)/t,this._z=(r+h)/t}else if(o>u){const t=2*Math.sqrt(1+o-n-u);this._w=(r-h)/t,this._x=(i+s)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+u-n-o);this._w=(s-i)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<1e-8?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(z(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,i=t._y,r=t._z,s=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=n*l+s*o+i*h-r*a,this._y=i*l+s*a+r*o-n*h,this._z=r*l+s*h+n*a-i*o,this._w=s*l-n*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(e<=0)return this;if(e>=1)return this.copy(t);let n=t._x,i=t._y,r=t._z,s=t._w,o=this.dot(t);o<0&&(n=-n,i=-i,r=-r,s=-s,o=-o);let a=1-e;if(o<.9995){const t=Math.acos(o),h=Math.sin(t);a=Math.sin(a*t)/h,e=Math.sin(e*t)/h,this._x=this._x*a+n*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+s*e,this._onChangeCallback()}else this._x=this._x*a+n*e,this._y=this._y*a+i*e,this._z=this._z*a+r*e,this._w=this._w*a+s*e,this.normalize();return this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class N{constructor(t=0,e=0,n=0){N.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(O.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(O.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,s=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*s,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*s,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*s,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,o=t.z,a=t.w,h=2*(s*i-o*n),l=2*(o*e-r*i),u=2*(r*n-s*e);return this.x=e+a*h+s*u-o*l,this.y=n+a*l+o*h-r*u,this.z=i+a*u+r*l-s*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this.z=z(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this.z=z(this.z,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,s=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*s-n*a,this.z=n*o-i*s,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return I.copy(this).projectOnVector(t),this.sub(I)}reflect(t){return this.sub(I.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(z(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const I=new N,O=new k;class F{constructor(t,e,n,i,r,s,o,a,h){F.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,o,a,h)}set(t,e,n,i,r,s,o,a,h){const l=this.elements;return l[0]=t,l[1]=i,l[2]=o,l[3]=e,l[4]=r,l[5]=a,l[6]=n,l[7]=s,l[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],o=n[3],a=n[6],h=n[1],l=n[4],u=n[7],c=n[2],d=n[5],p=n[8],f=i[0],y=i[3],m=i[6],g=i[1],x=i[4],b=i[7],w=i[2],v=i[5],M=i[8];return r[0]=s*f+o*g+a*w,r[3]=s*y+o*x+a*v,r[6]=s*m+o*b+a*M,r[1]=h*f+l*g+u*w,r[4]=h*y+l*x+u*v,r[7]=h*m+l*b+u*M,r[2]=c*f+d*g+p*w,r[5]=c*y+d*x+p*v,r[8]=c*m+d*b+p*M,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*s*l-e*o*h-n*r*l+n*o*a+i*r*h-i*s*a}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8],u=l*s-o*h,c=o*a-l*r,d=h*r-s*a,p=e*u+n*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=u*f,t[1]=(i*h-l*n)*f,t[2]=(o*n-i*s)*f,t[3]=c*f,t[4]=(l*e-i*a)*f,t[5]=(i*r-o*e)*f,t[6]=d*f,t[7]=(n*a-h*e)*f,t[8]=(s*e-n*r)*f,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,r,s,o){const a=Math.cos(r),h=Math.sin(r);return this.set(n*a,n*h,-n*(a*s+h*o)+s+t,-i*h,i*a,-i*(-h*s+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(R.makeScale(t,e)),this}rotate(t){return this.premultiply(R.makeRotation(-t)),this}translate(t,e){return this.premultiply(R.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const R=new F,V=(new F).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),U=(new F).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function L(){const t={enabled:!0,workingColorSpace:i,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===s&&(t.r=D(t.r),t.g=D(t.g),t.b=D(t.b)),this.spaces[e].primaries!==this.spaces[n].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===s&&(t.r=X(t.r),t.g=X(t.g),t.b=X(t.b)),t):t},workingToColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},colorSpaceToWorking:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return""===t?r:this.spaces[t].transfer},getToneMappingMode:function(t){return this.spaces[t].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,n){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(e,n){return x("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(e,n)},toWorkingColorSpace:function(e,n){return x("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(e,n)}},e=[.64,.33,.3,.6,.15,.06],o=[.2126,.7152,.0722],a=[.3127,.329];return t.define({[i]:{primaries:e,whitePoint:a,transfer:r,toXYZ:V,fromXYZ:U,luminanceCoefficients:o,workingColorSpaceConfig:{unpackColorSpace:n},outputColorSpaceConfig:{drawingBufferColorSpace:n}},[n]:{primaries:e,whitePoint:a,transfer:s,toXYZ:V,fromXYZ:U,luminanceCoefficients:o,outputColorSpaceConfig:{drawingBufferColorSpace:n}}}),t}const q=L();function D(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function X(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let Z;class j{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let n;if(t instanceof HTMLCanvasElement)n=t;else{void 0===Z&&(Z=l("canvas")),Z.width=t.width,Z.height=t.height;const e=Z.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),n=Z}return n.toDataURL(e)}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=l("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*D(r[t]/255);return n.putImageData(i,0,0),e}if(t.data){const e=t.data.slice(0);for(let t=0;t<e.length;t++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[t]=Math.floor(255*D(e[t]/255)):e[t]=D(e[t]);return{data:e,width:t.width,height:t.height}}return m("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let G=0;class J{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:G++}),this.uuid=A(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return"undefined"!=typeof HTMLVideoElement&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):"undefined"!=typeof VideoFrame&&e instanceof VideoFrame?t.set(e.displayHeight,e.displayWidth,0):null!==e?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){!0===t&&this.version++}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.images[this.uuid])return t.images[this.uuid];const n={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,n=i.length;e<n;e++)i[e].isDataTexture?t.push(W(i[e].image)):t.push(W(i[e]))}else t=W(i);n.url=t}return e||(t.images[this.uuid]=n),n}}function W(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?j.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(m("Texture: Unable to serialize Texture."),{})}let Y=0;const $=new N;class H extends b{constructor(t=H.DEFAULT_IMAGE,e=H.DEFAULT_MAPPING,n=1001,i=1001,r=1006,s=1008,o=1023,a=1009,h=H.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Y++}),this.uuid=A(),this.name="",this.source=new J(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=r,this.minFilter=s,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new E(0,0),this.repeat=new E(1,1),this.center=new E(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new F,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=l,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0}get width(){return this.source.getSize($).x}get height(){return this.source.getSize($).y}get depth(){return this.source.getSize($).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const n=t[e];if(void 0===n){m(`Texture.setValues(): parameter \'${e}\' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[e]=n:m(`Texture.setValues(): property \'${e}\' does not exist.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case 1e3:t.x=t.x-Math.floor(t.x);break;case e:t.x=t.x<0?0:1;break;case 1002:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case e:t.y=t.y<0?0:1;break;case 1002:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}H.DEFAULT_IMAGE=null,H.DEFAULT_MAPPING=300,H.DEFAULT_ANISOTROPY=1;class Q{constructor(t=0,e=0,n=0,i=1){Q.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=this.w,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i+s[12]*r,this.y=s[1]*e+s[5]*n+s[9]*i+s[13]*r,this.z=s[2]*e+s[6]*n+s[10]*i+s[14]*r,this.w=s[3]*e+s[7]*n+s[11]*i+s[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const s=.01,o=.1,a=t.elements,h=a[0],l=a[4],u=a[8],c=a[1],d=a[5],p=a[9],f=a[2],y=a[6],m=a[10];if(Math.abs(l-c)<s&&Math.abs(u-f)<s&&Math.abs(p-y)<s){if(Math.abs(l+c)<o&&Math.abs(u+f)<o&&Math.abs(p+y)<o&&Math.abs(h+d+m-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,g=(m+1)/2,x=(l+c)/4,b=(u+f)/4,w=(p+y)/4;return t>a&&t>g?t<s?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(t),i=x/n,r=b/n):a>g?a<s?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),n=x/i,r=w/i):g<s?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(g),n=b/r,i=w/r),this.set(n,i,r,e),this}let g=Math.sqrt((y-p)*(y-p)+(u-f)*(u-f)+(c-l)*(c-l));return Math.abs(g)<.001&&(g=1),this.x=(y-p)/g,this.y=(u-f)/g,this.z=(c-l)/g,this.w=Math.acos((h+d+m-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=z(this.x,t.x,e.x),this.y=z(this.y,t.y,e.y),this.z=z(this.z,t.z,e.z),this.w=z(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=z(this.x,t,e),this.y=z(this.y,t,e),this.z=z(this.z,t,e),this.w=z(this.w,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(z(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class K{constructor(t=new N(1/0,1/0,1/0),e=new N(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e+=3)this.expandByPoint(et.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(et.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=et.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const n=t.geometry;if(void 0!==n){const i=n.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,n=i.count;e<n;e++)!0===t.isMesh?t.getVertexPosition(e,et):et.fromBufferAttribute(i,e),et.applyMatrix4(t.matrixWorld),this.expandByPoint(et);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),nt.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),nt.copy(n.boundingBox)),nt.applyMatrix4(t.matrixWorld),this.union(nt)}const i=t.children;for(let r=0,s=i.length;r<s;r++)this.expandByObject(i[r],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,et),et.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(lt),ut.subVectors(this.max,lt),it.subVectors(t.a,lt),rt.subVectors(t.b,lt),st.subVectors(t.c,lt),ot.subVectors(rt,it),at.subVectors(st,rt),ht.subVectors(it,st);let e=[0,-ot.z,ot.y,0,-at.z,at.y,0,-ht.z,ht.y,ot.z,0,-ot.x,at.z,0,-at.x,ht.z,0,-ht.x,-ot.y,ot.x,0,-at.y,at.x,0,-ht.y,ht.x,0];return!!pt(e,it,rt,st,ut)&&(e=[1,0,0,0,1,0,0,0,1],!!pt(e,it,rt,st,ut)&&(ct.crossVectors(ot,at),e=[ct.x,ct.y,ct.z],pt(e,it,rt,st,ut)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,et).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(et).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(tt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),tt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),tt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),tt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),tt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),tt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),tt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),tt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(tt)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const tt=[new N,new N,new N,new N,new N,new N,new N,new N],et=new N,nt=new K,it=new N,rt=new N,st=new N,ot=new N,at=new N,ht=new N,lt=new N,ut=new N,ct=new N,dt=new N;function pt(t,e,n,i,r){for(let s=0,o=t.length-3;s<=o;s+=3){dt.fromArray(t,s);const o=r.x*Math.abs(dt.x)+r.y*Math.abs(dt.y)+r.z*Math.abs(dt.z),a=e.dot(dt),h=n.dot(dt),l=i.dot(dt);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const ft=new K,yt=new N,mt=new N;class gt{constructor(t=new N,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;void 0!==e?n.copy(e):ft.setFromPoints(t).getCenter(n);let i=0;for(let r=0,s=t.length;r<s;r++)i=Math.max(i,n.distanceToSquared(t[r]));return this.radius=Math.sqrt(i),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const n=this.center.distanceToSquared(t);return e.copy(t),n>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;yt.subVectors(t,this.center);const e=yt.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(yt,n/t),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(mt.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(yt.copy(t.center).add(mt)),this.expandByPoint(yt.copy(t.center).sub(mt))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}const xt=new N,bt=new N,wt=new N,vt=new N,Mt=new N,St=new N,At=new N;class zt{constructor(t=new N,e=new N(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,xt)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=xt.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(xt.copy(this.origin).addScaledVector(this.direction,e),xt.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){bt.copy(t).add(e).multiplyScalar(.5),wt.copy(e).sub(t).normalize(),vt.copy(this.origin).sub(bt);const r=.5*t.distanceTo(e),s=-this.direction.dot(wt),o=vt.dot(this.direction),a=-vt.dot(wt),h=vt.lengthSq(),l=Math.abs(1-s*s);let u,c,d,p;if(l>0)if(u=s*a-o,c=s*o-a,p=r*l,u>=0)if(c>=-p)if(c<=p){const t=1/l;u*=t,c*=t,d=u*(u+s*c+2*o)+c*(s*u+c+2*a)+h}else c=r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;else c=-r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;else c<=-p?(u=Math.max(0,-(-s*r+o)),c=u>0?-r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h):c<=p?(u=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(u=Math.max(0,-(s*r+o)),c=u>0?r:Math.min(Math.max(-r,-a),r),d=-u*u+c*(c+2*a)+h);else c=s>0?-r:r,u=Math.max(0,-(s*c+o)),d=-u*u+c*(c+2*a)+h;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(bt).addScaledVector(wt,c),d}intersectSphere(t,e){xt.subVectors(t.center,this.origin);const n=xt.dot(this.direction),i=xt.dot(xt)-n*n,r=t.radius*t.radius;if(i>r)return null;const s=Math.sqrt(r-i),o=n-s,a=n+s;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return!(t.radius<0)&&this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,r,s,o,a;const h=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,c=this.origin;return h>=0?(n=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(n=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),l>=0?(r=(t.min.y-c.y)*l,s=(t.max.y-c.y)*l):(r=(t.max.y-c.y)*l,s=(t.min.y-c.y)*l),n>s||r>i?null:((r>n||isNaN(n))&&(n=r),(s<i||isNaN(i))&&(i=s),u>=0?(o=(t.min.z-c.z)*u,a=(t.max.z-c.z)*u):(o=(t.max.z-c.z)*u,a=(t.min.z-c.z)*u),n>a||o>i?null:((o>n||n!=n)&&(n=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(n>=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,xt)}intersectTriangle(t,e,n,i,r){Mt.subVectors(e,t),St.subVectors(n,t),At.crossVectors(Mt,St);let s,o=this.direction.dot(At);if(o>0){if(i)return null;s=1}else{if(!(o<0))return null;s=-1,o=-o}vt.subVectors(this.origin,t);const a=s*this.direction.dot(St.crossVectors(vt,St));if(a<0)return null;const h=s*this.direction.dot(Mt.cross(vt));if(h<0)return null;if(a+h>o)return null;const l=-s*vt.dot(At);return l<0?null:this.at(l/o,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class _t{constructor(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){_t.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y)}set(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){const m=this.elements;return m[0]=t,m[4]=e,m[8]=n,m[12]=i,m[1]=r,m[5]=s,m[9]=o,m[13]=a,m[2]=h,m[6]=l,m[10]=u,m[14]=c,m[3]=d,m[7]=p,m[11]=f,m[15]=y,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new _t).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return 0===this.determinant()?(t.set(1,0,0),e.set(0,1,0),n.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this)}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){if(0===t.determinant())return this.identity();const e=this.elements,n=t.elements,i=1/Tt.setFromMatrixColumn(t,0).length(),r=1/Tt.setFromMatrixColumn(t,1).length(),s=1/Tt.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*s,e[9]=n[9]*s,e[10]=n[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,s=Math.cos(n),o=Math.sin(n),a=Math.cos(i),h=Math.sin(i),l=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=s*l,n=s*u,i=o*l,r=o*u;e[0]=a*l,e[4]=-a*u,e[8]=h,e[1]=n+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+n*h,e[10]=s*a}else if("YXZ"===t.order){const t=a*l,n=a*u,i=h*l,r=h*u;e[0]=t+r*o,e[4]=i*o-n,e[8]=s*h,e[1]=s*u,e[5]=s*l,e[9]=-o,e[2]=n*o-i,e[6]=r+t*o,e[10]=s*a}else if("ZXY"===t.order){const t=a*l,n=a*u,i=h*l,r=h*u;e[0]=t-r*o,e[4]=-s*u,e[8]=i+n*o,e[1]=n+i*o,e[5]=s*l,e[9]=r-t*o,e[2]=-s*h,e[6]=o,e[10]=s*a}else if("ZYX"===t.order){const t=s*l,n=s*u,i=o*l,r=o*u;e[0]=a*l,e[4]=i*h-n,e[8]=t*h+r,e[1]=a*u,e[5]=r*h+t,e[9]=n*h-i,e[2]=-h,e[6]=o*a,e[10]=s*a}else if("YZX"===t.order){const t=s*a,n=s*h,i=o*a,r=o*h;e[0]=a*l,e[4]=r-t*u,e[8]=i*u+n,e[1]=u,e[5]=s*l,e[9]=-o*l,e[2]=-h*l,e[6]=n*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=s*a,n=s*h,i=o*a,r=o*h;e[0]=a*l,e[4]=-u,e[8]=h*l,e[1]=t*u+r,e[5]=s*l,e[9]=n*u-i,e[2]=i*u-n,e[6]=o*l,e[10]=r*u+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Pt,t,Ct)}lookAt(t,e,n){const i=this.elements;return Nt.subVectors(t,e),0===Nt.lengthSq()&&(Nt.z=1),Nt.normalize(),Et.crossVectors(n,Nt),0===Et.lengthSq()&&(1===Math.abs(n.z)?Nt.x+=1e-4:Nt.z+=1e-4,Nt.normalize(),Et.crossVectors(n,Nt)),Et.normalize(),kt.crossVectors(Nt,Et),i[0]=Et.x,i[4]=kt.x,i[8]=Nt.x,i[1]=Et.y,i[5]=kt.y,i[9]=Nt.y,i[2]=Et.z,i[6]=kt.z,i[10]=Nt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],o=n[4],a=n[8],h=n[12],l=n[1],u=n[5],c=n[9],d=n[13],p=n[2],f=n[6],y=n[10],m=n[14],g=n[3],x=n[7],b=n[11],w=n[15],v=i[0],M=i[4],S=i[8],A=i[12],z=i[1],_=i[5],T=i[9],B=i[13],P=i[2],C=i[6],E=i[10],k=i[14],N=i[3],I=i[7],O=i[11],F=i[15];return r[0]=s*v+o*z+a*P+h*N,r[4]=s*M+o*_+a*C+h*I,r[8]=s*S+o*T+a*E+h*O,r[12]=s*A+o*B+a*k+h*F,r[1]=l*v+u*z+c*P+d*N,r[5]=l*M+u*_+c*C+d*I,r[9]=l*S+u*T+c*E+d*O,r[13]=l*A+u*B+c*k+d*F,r[2]=p*v+f*z+y*P+m*N,r[6]=p*M+f*_+y*C+m*I,r[10]=p*S+f*T+y*E+m*O,r[14]=p*A+f*B+y*k+m*F,r[3]=g*v+x*z+b*P+w*N,r[7]=g*M+x*_+b*C+w*I,r[11]=g*S+x*T+b*E+w*O,r[15]=g*A+x*B+b*k+w*F,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],i=t[8],r=t[12],s=t[1],o=t[5],a=t[9],h=t[13],l=t[2],u=t[6],c=t[10],d=t[14],p=t[3],f=t[7],y=t[11],m=t[15],g=a*d-h*c,x=o*d-h*u,b=o*c-a*u,w=s*d-h*l,v=s*c-a*l,M=s*u-o*l;return e*(f*g-y*x+m*b)-n*(p*g-y*w+m*v)+i*(p*x-f*w+m*M)-r*(p*b-f*v+y*M)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],o=t[5],a=t[6],h=t[7],l=t[8],u=t[9],c=t[10],d=t[11],p=t[12],f=t[13],y=t[14],m=t[15],g=u*y*h-f*c*h+f*a*d-o*y*d-u*a*m+o*c*m,x=p*c*h-l*y*h-p*a*d+s*y*d+l*a*m-s*c*m,b=l*f*h-p*u*h+p*o*d-s*f*d-l*o*m+s*u*m,w=p*u*a-l*f*a-p*o*c+s*f*c+l*o*y-s*u*y,v=e*g+n*x+i*b+r*w;if(0===v)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const M=1/v;return t[0]=g*M,t[1]=(f*c*r-u*y*r-f*i*d+n*y*d+u*i*m-n*c*m)*M,t[2]=(o*y*r-f*a*r+f*i*h-n*y*h-o*i*m+n*a*m)*M,t[3]=(u*a*r-o*c*r-u*i*h+n*c*h+o*i*d-n*a*d)*M,t[4]=x*M,t[5]=(l*y*r-p*c*r+p*i*d-e*y*d-l*i*m+e*c*m)*M,t[6]=(p*a*r-s*y*r-p*i*h+e*y*h+s*i*m-e*a*m)*M,t[7]=(s*c*r-l*a*r+l*i*h-e*c*h-s*i*d+e*a*d)*M,t[8]=b*M,t[9]=(p*u*r-l*f*r-p*n*d+e*f*d+l*n*m-e*u*m)*M,t[10]=(s*f*r-p*o*r+p*n*h-e*f*h-s*n*m+e*o*m)*M,t[11]=(l*o*r-s*u*r-l*n*h+e*u*h+s*n*d-e*o*d)*M,t[12]=w*M,t[13]=(l*f*i-p*u*i+p*n*c-e*f*c-l*n*y+e*u*y)*M,t[14]=(p*o*i-s*f*i-p*n*a+e*f*a+s*n*y-e*o*y)*M,t[15]=(s*u*i-l*o*i+l*n*a-e*u*a-s*n*c+e*o*c)*M,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,s=t.x,o=t.y,a=t.z,h=r*s,l=r*o;return this.set(h*s+n,h*o-i*a,h*a+i*o,0,h*o+i*a,l*o+n,l*a-i*s,0,h*a-i*o,l*a+i*s,r*a*a+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,s){return this.set(1,n,r,0,t,1,s,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,s=e._y,o=e._z,a=e._w,h=r+r,l=s+s,u=o+o,c=r*h,d=r*l,p=r*u,f=s*l,y=s*u,m=o*u,g=a*h,x=a*l,b=a*u,w=n.x,v=n.y,M=n.z;return i[0]=(1-(f+m))*w,i[1]=(d+b)*w,i[2]=(p-x)*w,i[3]=0,i[4]=(d-b)*v,i[5]=(1-(c+m))*v,i[6]=(y+g)*v,i[7]=0,i[8]=(p+x)*M,i[9]=(y-g)*M,i[10]=(1-(c+f))*M,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;if(t.x=i[12],t.y=i[13],t.z=i[14],0===this.determinant())return n.set(1,1,1),e.identity(),this;let r=Tt.set(i[0],i[1],i[2]).length();const s=Tt.set(i[4],i[5],i[6]).length(),o=Tt.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),Bt.copy(this);const a=1/r,h=1/s,l=1/o;return Bt.elements[0]*=a,Bt.elements[1]*=a,Bt.elements[2]*=a,Bt.elements[4]*=h,Bt.elements[5]*=h,Bt.elements[6]*=h,Bt.elements[8]*=l,Bt.elements[9]*=l,Bt.elements[10]*=l,e.setFromRotationMatrix(Bt),n.x=r,n.y=s,n.z=o,this}makePerspective(t,e,n,i,r,s,o=2e3,h=!1){const l=this.elements,u=2*r/(e-t),c=2*r/(n-i),d=(e+t)/(e-t),p=(n+i)/(n-i);let f,y;if(h)f=r/(s-r),y=s*r/(s-r);else if(o===a)f=-(s+r)/(s-r),y=-2*s*r/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);f=-s/(s-r),y=-s*r/(s-r)}return l[0]=u,l[4]=0,l[8]=d,l[12]=0,l[1]=0,l[5]=c,l[9]=p,l[13]=0,l[2]=0,l[6]=0,l[10]=f,l[14]=y,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,i,r,s,o=2e3,h=!1){const l=this.elements,u=2/(e-t),c=2/(n-i),d=-(e+t)/(e-t),p=-(n+i)/(n-i);let f,y;if(h)f=1/(s-r),y=s/(s-r);else if(o===a)f=-2/(s-r),y=-(s+r)/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);f=-1/(s-r),y=-r/(s-r)}return l[0]=u,l[4]=0,l[8]=0,l[12]=d,l[1]=0,l[5]=c,l[9]=0,l[13]=p,l[2]=0,l[6]=0,l[10]=f,l[14]=y,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const Tt=new N,Bt=new _t,Pt=new N(0,0,0),Ct=new N(1,1,1),Et=new N,kt=new N,Nt=new N,It=new _t,Ot=new k;class Ft{constructor(t=0,e=0,n=0,i=Ft.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const i=t.elements,r=i[0],s=i[4],o=i[8],a=i[1],h=i[5],l=i[9],u=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(z(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-z(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(z(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-z(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-s,h));break;case"YZX":this._z=Math.asin(z(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-z(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:m("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return It.makeRotationFromQuaternion(t),this.setFromRotationMatrix(It,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Ot.setFromEuler(this),this.setFromQuaternion(Ot,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ft.DEFAULT_ORDER="XYZ";class Rt{constructor(){this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}test(t){return 0!==(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let Vt=0;const Ut=new N,Lt=new k,qt=new _t,Dt=new N,Xt=new N,Zt=new N,jt=new k,Gt=new N(1,0,0),Jt=new N(0,1,0),Wt=new N(0,0,1),Yt={type:"added"},$t={type:"removed"},Ht={type:"childadded",child:null},Qt={type:"childremoved",child:null};class Kt extends b{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Vt++}),this.uuid=A(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Kt.DEFAULT_UP.clone();const t=new N,e=new Ft,n=new k,i=new N(1,1,1);e._onChange(function(){n.setFromEuler(e,!1)}),n._onChange(function(){e.setFromQuaternion(n,void 0,!1)}),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new _t},normalMatrix:{value:new F}}),this.matrix=new _t,this.matrixWorld=new _t,this.matrixAutoUpdate=Kt.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Kt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Rt,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Lt.setFromAxisAngle(t,e),this.quaternion.multiply(Lt),this}rotateOnWorldAxis(t,e){return Lt.setFromAxisAngle(t,e),this.quaternion.premultiply(Lt),this}rotateX(t){return this.rotateOnAxis(Gt,t)}rotateY(t){return this.rotateOnAxis(Jt,t)}rotateZ(t){return this.rotateOnAxis(Wt,t)}translateOnAxis(t,e){return Ut.copy(t).applyQuaternion(this.quaternion),this.position.add(Ut.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Gt,t)}translateY(t){return this.translateOnAxis(Jt,t)}translateZ(t){return this.translateOnAxis(Wt,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(qt.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?Dt.copy(t):Dt.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),Xt.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?qt.lookAt(Xt,Dt,this.up):qt.lookAt(Dt,Xt,this.up),this.quaternion.setFromRotationMatrix(qt),i&&(qt.extractRotation(i.matrixWorld),Lt.setFromRotationMatrix(qt),this.quaternion.premultiply(Lt.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(g("Object3D.add: object can\'t be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(Yt),Ht.child=t,this.dispatchEvent(Ht),Ht.child=null):g("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent($t),Qt.child=t,this.dispatchEvent(Qt),Qt.child=null),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),qt.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),qt.multiply(t.parent.matrixWorld)),t.applyMatrix4(qt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Yt),Ht.child=t,this.dispatchEvent(Ht),Ht.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let n=0,i=this.children.length;n<i;n++){const i=this.children[n].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const i=this.children;for(let r=0,s=i.length;r<s;r++)i[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xt,t,Zt),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xt,jt,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let n=0,i=e.length;n<i;n++){e[n].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const n=this.parent;if(!0===t&&null!==n&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),!0===e){const t=this.children;for(let e=0,n=t.length;e<n;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,n){return void 0===e[n.uuid]&&(e[n.uuid]=n.toJSON(t)),n.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(t=>c(u({},t),{boundingBox:t.boundingBox?t.boundingBox.toJSON():void 0,boundingSphere:t.boundingSphere?t.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(t=>u({},t)),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere=this.boundingSphere.toJSON()),null!==this.boundingBox&&(i.boundingBox=this.boundingBox.toJSON())),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e<i;e++){const i=n[e];r(t.shapes,i)}else r(t.shapes,n)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(r(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let n=0,i=this.material.length;n<i;n++)e.push(r(t.materials,this.material[n]));i.material=e}else i.material=r(t.materials,this.material);if(this.children.length>0){i.children=[];for(let e=0;e<this.children.length;e++)i.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let e=0;e<this.animations.length;e++){const n=this.animations[e];i.animations.push(r(t.animations,n))}}if(e){const e=s(t.geometries),i=s(t.materials),r=s(t.textures),o=s(t.images),a=s(t.shapes),h=s(t.skeletons),l=s(t.animations),u=s(t.nodes);e.length>0&&(n.geometries=e),i.length>0&&(n.materials=i),r.length>0&&(n.textures=r),o.length>0&&(n.images=o),a.length>0&&(n.shapes=a),h.length>0&&(n.skeletons=h),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=i,n;function s(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let n=0;n<t.children.length;n++){const e=t.children[n];this.add(e.clone())}return this}}Kt.DEFAULT_UP=new N(0,1,0),Kt.DEFAULT_MATRIX_AUTO_UPDATE=!0,Kt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const te=new N,ee=new N,ne=new N,ie=new N,re=new N,se=new N,oe=new N,ae=new N,he=new N,le=new N,ue=new Q,ce=new Q,de=new Q;class pe{constructor(t=new N,e=new N,n=new N){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),te.subVectors(t,e),i.cross(te);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){te.subVectors(i,e),ee.subVectors(n,e),ne.subVectors(t,e);const s=te.dot(te),o=te.dot(ee),a=te.dot(ne),h=ee.dot(ee),l=ee.dot(ne),u=s*h-o*o;if(0===u)return r.set(0,0,0),null;const c=1/u,d=(h*a-o*l)*c,p=(s*l-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,ie)&&(ie.x>=0&&ie.y>=0&&ie.x+ie.y<=1)}static getInterpolation(t,e,n,i,r,s,o,a){return null===this.getBarycoord(t,e,n,i,ie)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,ie.x),a.addScaledVector(s,ie.y),a.addScaledVector(o,ie.z),a)}static getInterpolatedAttribute(t,e,n,i,r,s){return ue.setScalar(0),ce.setScalar(0),de.setScalar(0),ue.fromBufferAttribute(t,e),ce.fromBufferAttribute(t,n),de.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(ue,r.x),s.addScaledVector(ce,r.y),s.addScaledVector(de,r.z),s}static isFrontFacing(t,e,n,i){return te.subVectors(n,e),ee.subVectors(t,e),te.cross(ee).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return te.subVectors(this.c,this.b),ee.subVectors(this.a,this.b),.5*te.cross(ee).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return pe.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return pe.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return pe.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return pe.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return pe.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let s,o;re.subVectors(i,n),se.subVectors(r,n),ae.subVectors(t,n);const a=re.dot(ae),h=se.dot(ae);if(a<=0&&h<=0)return e.copy(n);he.subVectors(t,i);const l=re.dot(he),u=se.dot(he);if(l>=0&&u<=l)return e.copy(i);const c=a*u-l*h;if(c<=0&&a>=0&&l<=0)return s=a/(a-l),e.copy(n).addScaledVector(re,s);le.subVectors(t,r);const d=re.dot(le),p=se.dot(le);if(p>=0&&d<=p)return e.copy(r);const f=d*h-a*p;if(f<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(n).addScaledVector(se,o);const y=l*p-d*u;if(y<=0&&u-l>=0&&d-p>=0)return oe.subVectors(r,i),o=(u-l)/(u-l+(d-p)),e.copy(i).addScaledVector(oe,o);const m=1/(y+f+c);return s=f*m,o=c*m,e.copy(n).addScaledVector(re,s).addScaledVector(se,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const fe={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},ye={h:0,s:0,l:0},me={h:0,s:0,l:0};function ge(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}let xe=class{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=n){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,q.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=q.workingColorSpace){return this.r=t,this.g=e,this.b=n,q.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=q.workingColorSpace){if(t=_(t,1),e=z(e,0,1),n=z(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=ge(r,i,t+1/3),this.g=ge(r,i,t),this.b=ge(r,i,t-1/3)}return q.colorSpaceToWorking(this,i),this}setStyle(t,e=n){function i(e){void 0!==e&&parseFloat(e)<1&&m("Color: Alpha component of "+t+" will be ignored.")}let r;if(r=/^(\\w+)\\(([^\\)]*)\\)/.exec(t)){let n;const s=r[1],o=r[2];switch(s){case"rgb":case"rgba":if(n=/^\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,e);if(n=/^\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,e);break;case"hsl":case"hsla":if(n=/^\\s*(\\d*\\.?\\d+)\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return i(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,e);break;default:m("Color: Unknown color model "+t)}}else if(r=/^\\#([A-Fa-f\\d]+)$/.exec(t)){const n=r[1],i=n.length;if(3===i)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===i)return this.setHex(parseInt(n,16),e);m("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=n){const i=fe[t.toLowerCase()];return void 0!==i?this.setHex(i,e):m("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=D(t.r),this.g=D(t.g),this.b=D(t.b),this}copyLinearToSRGB(t){return this.r=X(t.r),this.g=X(t.g),this.b=X(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=n){return q.workingToColorSpace(be.copy(this),t),65536*Math.round(z(255*be.r,0,255))+256*Math.round(z(255*be.g,0,255))+Math.round(z(255*be.b,0,255))}getHexString(t=n){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=q.workingColorSpace){q.workingToColorSpace(be.copy(this),e);const n=be.r,i=be.g,r=be.b,s=Math.max(n,i,r),o=Math.min(n,i,r);let a,h;const l=(o+s)/2;if(o===s)a=0,h=0;else{const t=s-o;switch(h=l<=.5?t/(s+o):t/(2-s-o),s){case n:a=(i-r)/t+(i<r?6:0);break;case i:a=(r-n)/t+2;break;case r:a=(n-i)/t+4}a/=6}return t.h=a,t.s=h,t.l=l,t}getRGB(t,e=q.workingColorSpace){return q.workingToColorSpace(be.copy(this),e),t.r=be.r,t.g=be.g,t.b=be.b,t}getStyle(t=n){q.workingToColorSpace(be.copy(this),t);const e=be.r,i=be.g,r=be.b;return t!==n?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${r.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*i)},${Math.round(255*r)})`}offsetHSL(t,e,n){return this.getHSL(ye),this.setHSL(ye.h+t,ye.s+e,ye.l+n)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(ye),t.getHSL(me);const n=T(ye.h,me.h,e),i=T(ye.s,me.s,e),r=T(ye.l,me.l,e);return this.setHSL(n,i,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,n=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*i,this.g=r[1]*e+r[4]*n+r[7]*i,this.b=r[2]*e+r[5]*n+r[8]*i,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}};const be=new xe;xe.NAMES=fe;let we=0;class ve extends b{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:we++}),this.uuid=A(),this.name="",this.type="Material",this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=204,this.blendDst=205,this.blendEquation=100,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new xe(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=o,this.stencilZFail=o,this.stencilZPass=o,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){m(`Material: parameter \'${e}\' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n:m(`Material: \'${e}\' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),204!==this.blendSrc&&(n.blendSrc=this.blendSrc),205!==this.blendDst&&(n.blendDst=this.blendDst),100!==this.blendEquation&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==o&&(n.stencilFail=this.stencilFail),this.stencilZFail!==o&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==o&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!1===this.allowOverride&&(n.allowOverride=!1),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(n.textures=e),r.length>0&&(n.images=r)}return n}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.allowOverride=t.allowOverride,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}class Me extends ve{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new xe(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Ft,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Se=new N,Ae=new E;let ze=0;class _e{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:ze++}),this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=n,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[n+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,n=this.count;e<n;e++)Ae.fromBufferAttribute(this,e),Ae.applyMatrix3(t),this.setXY(e,Ae.x,Ae.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyMatrix3(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyMatrix4(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.applyNormalMatrix(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Se.fromBufferAttribute(this,e),Se.transformDirection(t),this.setXYZ(e,Se.x,Se.y,Se.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=B(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=P(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=B(e,this.array)),e}setX(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=B(e,this.array)),e}setY(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=B(e,this.array)),e}setZ(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=B(e,this.array)),e}setW(t,e){return this.normalized&&(e=P(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array),i=P(i,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this}setXYZW(t,e,n,i,r){return t*=this.itemSize,this.normalized&&(e=P(e,this.array),n=P(n,this.array),i=P(i,this.array),r=P(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this.array[t+3]=r,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),35044!==this.usage&&(t.usage=this.usage),t}}class Te extends _e{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class Be extends _e{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class Pe extends _e{constructor(t,e,n){super(new Float32Array(t),e,n)}}let Ce=0;const Ee=new _t,ke=new Kt,Ne=new N,Ie=new K,Oe=new K,Fe=new N;class Re extends b{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Ce++}),this.uuid=A(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(t)?Be:Te)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const n=this.attributes.normal;if(void 0!==n){const e=(new F).getNormalMatrix(t);n.applyNormalMatrix(e),n.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return Ee.makeRotationFromQuaternion(t),this.applyMatrix4(Ee),this}rotateX(t){return Ee.makeRotationX(t),this.applyMatrix4(Ee),this}rotateY(t){return Ee.makeRotationY(t),this.applyMatrix4(Ee),this}rotateZ(t){return Ee.makeRotationZ(t),this.applyMatrix4(Ee),this}translate(t,e,n){return Ee.makeTranslation(t,e,n),this.applyMatrix4(Ee),this}scale(t,e,n){return Ee.makeScale(t,e,n),this.applyMatrix4(Ee),this}lookAt(t){return ke.lookAt(t),ke.updateMatrix(),this.applyMatrix4(ke.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ne).negate(),this.translate(Ne.x,Ne.y,Ne.z),this}setFromPoints(t){const e=this.getAttribute("position");if(void 0===e){const e=[];for(let n=0,i=t.length;n<i;n++){const i=t[n];e.push(i.x,i.y,i.z||0)}this.setAttribute("position",new Pe(e,3))}else{const n=Math.min(t.length,e.count);for(let i=0;i<n;i++){const n=t[i];e.setXYZ(i,n.x,n.y,n.z||0)}t.length>e.count&&m("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new K);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return g("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new N(-1/0,-1/0,-1/0),new N(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let n=0,i=e.length;n<i;n++){const t=e[n];Ie.setFromBufferAttribute(t),this.morphTargetsRelative?(Fe.addVectors(this.boundingBox.min,Ie.min),this.boundingBox.expandByPoint(Fe),Fe.addVectors(this.boundingBox.max,Ie.max),this.boundingBox.expandByPoint(Fe)):(this.boundingBox.expandByPoint(Ie.min),this.boundingBox.expandByPoint(Ie.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&g(\'BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.\',this)}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new gt);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return g("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new N,1/0);if(t){const n=this.boundingSphere.center;if(Ie.setFromBufferAttribute(t),e)for(let t=0,r=e.length;t<r;t++){const n=e[t];Oe.setFromBufferAttribute(n),this.morphTargetsRelative?(Fe.addVectors(Ie.min,Oe.min),Ie.expandByPoint(Fe),Fe.addVectors(Ie.max,Oe.max),Ie.expandByPoint(Fe)):(Ie.expandByPoint(Oe.min),Ie.expandByPoint(Oe.max))}Ie.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)Fe.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(Fe));if(e)for(let r=0,s=e.length;r<s;r++){const s=e[r],o=this.morphTargetsRelative;for(let e=0,r=s.count;e<r;e++)Fe.fromBufferAttribute(s,e),o&&(Ne.fromBufferAttribute(t,e),Fe.add(Ne)),i=Math.max(i,n.distanceToSquared(Fe))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&g(\'BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.\',this)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return void g("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const n=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new _e(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),o=[],a=[];for(let g=0;g<n.count;g++)o[g]=new N,a[g]=new N;const h=new N,l=new N,u=new N,c=new E,d=new E,p=new E,f=new N,y=new N;function m(t,e,i){h.fromBufferAttribute(n,t),l.fromBufferAttribute(n,e),u.fromBufferAttribute(n,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),l.sub(h),u.sub(h),d.sub(c),p.sub(c);const s=1/(d.x*p.y-p.x*d.y);isFinite(s)&&(f.copy(l).multiplyScalar(p.y).addScaledVector(u,-d.y).multiplyScalar(s),y.copy(u).multiplyScalar(d.x).addScaledVector(l,-p.x).multiplyScalar(s),o[t].add(f),o[e].add(f),o[i].add(f),a[t].add(y),a[e].add(y),a[i].add(y))}let x=this.groups;0===x.length&&(x=[{start:0,count:t.count}]);for(let g=0,A=x.length;g<A;++g){const e=x[g],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)m(t.getX(i+0),t.getX(i+1),t.getX(i+2))}const b=new N,w=new N,v=new N,M=new N;function S(t){v.fromBufferAttribute(i,t),M.copy(v);const e=o[t];b.copy(e),b.sub(v.multiplyScalar(v.dot(e))).normalize(),w.crossVectors(M,e);const n=w.dot(a[t])<0?-1:1;s.setXYZW(t,b.x,b.y,b.z,n)}for(let g=0,A=x.length;g<A;++g){const e=x[g],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)S(t.getX(i+0)),S(t.getX(i+1)),S(t.getX(i+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let n=this.getAttribute("normal");if(void 0===n)n=new _e(new Float32Array(3*e.count),3),this.setAttribute("normal",n);else for(let t=0,e=n.count;t<e;t++)n.setXYZ(t,0,0,0);const i=new N,r=new N,s=new N,o=new N,a=new N,h=new N,l=new N,u=new N;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),f=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),s.fromBufferAttribute(e,f),l.subVectors(s,r),u.subVectors(i,r),l.cross(u),o.fromBufferAttribute(n,d),a.fromBufferAttribute(n,p),h.fromBufferAttribute(n,f),o.add(l),a.add(l),h.add(l),n.setXYZ(d,o.x,o.y,o.z),n.setXYZ(p,a.x,a.y,a.z),n.setXYZ(f,h.x,h.y,h.z)}else for(let t=0,c=e.count;t<c;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),s.fromBufferAttribute(e,t+2),l.subVectors(s,r),u.subVectors(i,r),l.cross(u),n.setXYZ(t+0,l.x,l.y,l.z),n.setXYZ(t+1,l.x,l.y,l.z),n.setXYZ(t+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Fe.fromBufferAttribute(t,e),Fe.normalize(),t.setXYZ(e,Fe.x,Fe.y,Fe.z)}toNonIndexed(){function t(t,e){const n=t.array,i=t.itemSize,r=t.normalized,s=new n.constructor(e.length*i);let o=0,a=0;for(let h=0,l=e.length;h<l;h++){o=t.isInterleavedBufferAttribute?e[h]*t.data.stride+t.offset:e[h]*i;for(let t=0;t<i;t++)s[a++]=n[o++]}return new _e(s,i,r)}if(null===this.index)return m("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Re,n=this.index.array,i=this.attributes;for(const o in i){const r=t(i[o],n);e.setAttribute(o,r)}const r=this.morphAttributes;for(const o in r){const i=[],s=r[o];for(let e=0,r=s.length;e<r;e++){const r=t(s[e],n);i.push(r)}e.morphAttributes[o]=i}e.morphTargetsRelative=this.morphTargetsRelative;const s=this.groups;for(let o=0,a=s.length;o<a;o++){const t=s[o];e.addGroup(t.start,t.count,t.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,""!==this.name&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const n in e)void 0!==e[n]&&(t[n]=e[n]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const a in n){const e=n[a];t.data.attributes[a]=e.toJSON(t.data)}const i={};let r=!1;for(const a in this.morphAttributes){const e=this.morphAttributes[a],n=[];for(let i=0,r=e.length;i<r;i++){const r=e[i];n.push(r.toJSON(t.data))}n.length>0&&(i[a]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(t.data.groups=JSON.parse(JSON.stringify(s)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere=o.toJSON()),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone());const i=t.attributes;for(const h in i){const t=i[h];this.setAttribute(h,t.clone(e))}const r=t.morphAttributes;for(const h in r){const t=[],n=r[h];for(let i=0,r=n.length;i<r;i++)t.push(n[i].clone(e));this.morphAttributes[h]=t}this.morphTargetsRelative=t.morphTargetsRelative;const s=t.groups;for(let h=0,l=s.length;h<l;h++){const t=s[h];this.addGroup(t.start,t.count,t.materialIndex)}const o=t.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=t.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Ve=new _t,Ue=new zt,Le=new gt,qe=new N,De=new N,Xe=new N,Ze=new N,je=new N,Ge=new N,Je=new N,We=new N;class Ye extends Kt{constructor(t=new Re,e=new Me){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t<e;t++){const e=n[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const n=this.geometry,i=n.attributes.position,r=n.morphAttributes.position,s=n.morphTargetsRelative;e.fromBufferAttribute(i,t);const o=this.morphTargetInfluences;if(r&&o){Ge.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=o[n],a=r[n];0!==i&&(je.fromBufferAttribute(a,t),s?Ge.addScaledVector(je,i):Ge.addScaledVector(je.sub(e),i))}e.add(Ge)}return e}raycast(t,e){const n=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===n.boundingSphere&&n.computeBoundingSphere(),Le.copy(n.boundingSphere),Le.applyMatrix4(r),Ue.copy(t.ray).recast(t.near),!1===Le.containsPoint(Ue.origin)){if(null===Ue.intersectSphere(Le,qe))return;if(Ue.origin.distanceToSquared(qe)>h(t.far-t.near,2))return}Ve.copy(r).invert(),Ue.copy(t.ray).applyMatrix4(Ve),null!==n.boundingBox&&!1===Ue.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Ue)}}_computeIntersections(t,e,n){let i;const r=this.geometry,s=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,l=r.attributes.uv1,u=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(s))for(let p=0,f=c.length;p<f;p++){const r=c[p],a=s[r.materialIndex];for(let s=Math.max(r.start,d.start),c=Math.min(o.count,Math.min(r.start+r.count,d.start+d.count));s<c;s+=3){i=$e(this,a,t,n,h,l,u,o.getX(s),o.getX(s+1),o.getX(s+2)),i&&(i.faceIndex=Math.floor(s/3),i.face.materialIndex=r.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),a=Math.min(o.count,d.start+d.count);r<a;r+=3){i=$e(this,s,t,n,h,l,u,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==a)if(Array.isArray(s))for(let p=0,f=c.length;p<f;p++){const r=c[p],o=s[r.materialIndex];for(let s=Math.max(r.start,d.start),c=Math.min(a.count,Math.min(r.start+r.count,d.start+d.count));s<c;s+=3){i=$e(this,o,t,n,h,l,u,s,s+1,s+2),i&&(i.faceIndex=Math.floor(s/3),i.face.materialIndex=r.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),o=Math.min(a.count,d.start+d.count);r<o;r+=3){i=$e(this,s,t,n,h,l,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function $e(t,e,n,i,r,s,o,a,h,l){t.getVertexPosition(a,De),t.getVertexPosition(h,Xe),t.getVertexPosition(l,Ze);const u=function(t,e,n,i,r,s,o,a){let h;if(h=1===e.side?i.intersectTriangle(o,s,r,!0,a):i.intersectTriangle(r,s,o,0===e.side,a),null===h)return null;We.copy(a),We.applyMatrix4(t.matrixWorld);const l=n.ray.origin.distanceTo(We);return l<n.near||l>n.far?null:{distance:l,point:We.clone(),object:t}}(t,e,n,i,De,Xe,Ze,Je);if(u){const t=new N;pe.getBarycoord(Je,De,Xe,Ze,t),r&&(u.uv=pe.getInterpolatedAttribute(r,a,h,l,t,new E)),s&&(u.uv1=pe.getInterpolatedAttribute(s,a,h,l,t,new E)),o&&(u.normal=pe.getInterpolatedAttribute(o,a,h,l,t,new N),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new N,materialIndex:0};pe.getNormal(De,Xe,Ze,e.normal),u.face=e,u.barycoord=t}return u}const He=new N,Qe=new N,Ke=new F;class tn{constructor(t=new N(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=He.subVectors(n,e).cross(Qe.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(He),i=this.normal.dot(n);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||Ke.getNormalMatrix(t),i=this.coplanarPoint(He).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}class en{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){m("Curve: .getPoint() not implemented.")}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let n,i=this.getPoint(0),r=0;e.push(0);for(let s=1;s<=t;s++)n=this.getPoint(s/t),r+=n.distanceTo(i),e.push(r),i=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e=null){const n=this.getLengths();let i=0;const r=n.length;let s;s=e||t*n[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=n[i]-s,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,n[i]===s)return i/(r-1);const l=n[i];return(i+(s-l)/(n[i+1]-l))/(r-1)}getTangent(t,e){const n=1e-4;let i=t-n,r=t+n;i<0&&(i=0),r>1&&(r=1);const s=this.getPoint(i),o=this.getPoint(r),a=e||(s.isVector2?new E:new N);return a.copy(o).sub(s).normalize(),a}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e=!1){const n=new N,i=[],r=[],s=[],o=new N,a=new _t;for(let d=0;d<=t;d++){const e=d/t;i[d]=this.getTangentAt(e,new N)}r[0]=new N,s[0]=new N;let h=Number.MAX_VALUE;const l=Math.abs(i[0].x),u=Math.abs(i[0].y),c=Math.abs(i[0].z);l<=h&&(h=l,n.set(1,0,0)),u<=h&&(h=u,n.set(0,1,0)),c<=h&&n.set(0,0,1),o.crossVectors(i[0],n).normalize(),r[0].crossVectors(i[0],o),s[0].crossVectors(i[0],r[0]);for(let d=1;d<=t;d++){if(r[d]=r[d-1].clone(),s[d]=s[d-1].clone(),o.crossVectors(i[d-1],i[d]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos(z(i[d-1].dot(i[d]),-1,1));r[d].applyMatrix4(a.makeRotationAxis(o,t))}s[d].crossVectors(i[d],r[d])}if(!0===e){let e=Math.acos(z(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let n=1;n<=t;n++)r[n].applyMatrix4(a.makeRotationAxis(i[n],e*n)),s[n].crossVectors(i[n],r[n])}return{tangents:i,normals:r,binormals:s}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.7,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class nn extends en{constructor(t=0,e=0,n=1,i=1,r=0,s=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=s,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new E){const n=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const s=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=s?0:i),!0!==this.aClockwise||s||(r===i?r=-i:r-=i);const o=this.aStartAngle+t*r;let a=this.aX+this.xRadius*Math.cos(o),h=this.aY+this.yRadius*Math.sin(o);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),n=a-this.aX,i=h-this.aY;a=n*t-i*e+this.aX,h=n*e+i*t+this.aY}return n.set(a,h)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class rn extends nn{constructor(t,e,n,i,r,s){super(t,e,n,n,i,r,s),this.isArcCurve=!0,this.type="ArcCurve"}}function sn(){let t=0,e=0,n=0,i=0;function r(r,s,o,a){t=r,e=o,n=-3*r+3*s-2*o-a,i=2*r-2*s+o+a}return{initCatmullRom:function(t,e,n,i,s){r(e,n,s*(n-t),s*(i-e))},initNonuniformCatmullRom:function(t,e,n,i,s,o,a){let h=(e-t)/s-(n-t)/(s+o)+(n-e)/o,l=(n-e)/o-(i-e)/(o+a)+(i-n)/a;h*=o,l*=o,r(e,n,h,l)},calc:function(r){const s=r*r;return t+e*r+n*s+i*(s*r)}}}const on=new N,an=new sn,hn=new sn,ln=new sn;class un extends en{constructor(t=[],e=!1,n="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=n,this.tension=i}getPoint(t,e=new N){const n=e,i=this.points,r=i.length,s=(r-(this.closed?0:1))*t;let o,a,h=Math.floor(s),l=s-h;this.closed?h+=h>0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===l&&h===r-1&&(h=r-2,l=1),this.closed||h>0?o=i[(h-1)%r]:(on.subVectors(i[0],i[1]).add(i[0]),o=on);const u=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(on.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=on),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(o.distanceToSquared(u),t),n=Math.pow(u.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(a),t);n<1e-4&&(n=1),e<1e-4&&(e=n),i<1e-4&&(i=n),an.initNonuniformCatmullRom(o.x,u.x,c.x,a.x,e,n,i),hn.initNonuniformCatmullRom(o.y,u.y,c.y,a.y,e,n,i),ln.initNonuniformCatmullRom(o.z,u.z,c.z,a.z,e,n,i)}else"catmullrom"===this.curveType&&(an.initCatmullRom(o.x,u.x,c.x,a.x,this.tension),hn.initCatmullRom(o.y,u.y,c.y,a.y,this.tension),ln.initCatmullRom(o.z,u.z,c.z,a.z,this.tension));return n.set(an.calc(l),hn.calc(l),ln.calc(l)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new N).fromArray(n))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function cn(t,e,n,i,r){const s=.5*(i-e),o=.5*(r-n),a=t*t;return(2*n-2*i+s+o)*(t*a)+(-3*n+3*i-2*s-o)*a+s*t+n}function dn(t,e,n,i){return function(t,e){const n=1-t;return n*n*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,n)+function(t,e){return t*t*e}(t,i)}function pn(t,e,n,i,r){return function(t,e){const n=1-t;return n*n*n*e}(t,e)+function(t,e){const n=1-t;return 3*n*n*t*e}(t,n)+function(t,e){return 3*(1-t)*t*t*e}(t,i)+function(t,e){return t*t*t*e}(t,r)}class fn extends en{constructor(t=new E,e=new E,n=new E,i=new E){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new E){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(pn(t,i.x,r.x,s.x,o.x),pn(t,i.y,r.y,s.y,o.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class yn extends en{constructor(t=new N,e=new N,n=new N,i=new N){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new N){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(pn(t,i.x,r.x,s.x,o.x),pn(t,i.y,r.y,s.y,o.y),pn(t,i.z,r.z,s.z,o.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class mn extends en{constructor(t=new E,e=new E){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new E){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new E){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class gn extends en{constructor(t=new N,e=new N){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new N){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new N){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class xn extends en{constructor(t=new E,e=new E,n=new E){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new E){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(dn(t,i.x,r.x,s.x),dn(t,i.y,r.y,s.y)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class bn extends en{constructor(t=new N,e=new N,n=new N){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new N){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(dn(t,i.x,r.x,s.x),dn(t,i.y,r.y,s.y),dn(t,i.z,r.z,s.z)),n}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class wn extends en{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new E){const n=e,i=this.points,r=(i.length-1)*t,s=Math.floor(r),o=r-s,a=i[0===s?s:s-1],h=i[s],l=i[s>i.length-2?i.length-1:s+1],u=i[s>i.length-3?i.length-1:s+2];return n.set(cn(o,a.x,h.x,l.x,u.x),cn(o,a.y,h.y,l.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new E).fromArray(n))}return this}}var vn=Object.freeze({__proto__:null,ArcCurve:rn,CatmullRomCurve3:un,CubicBezierCurve:fn,CubicBezierCurve3:yn,EllipseCurve:nn,LineCurve:mn,LineCurve3:gn,QuadraticBezierCurve:xn,QuadraticBezierCurve3:bn,SplineCurve:wn});class Mn extends en{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const n=!0===t.isVector2?"LineCurve":"LineCurve3";this.curves.push(new vn[n](e,t))}return this}getPoint(t,e){const n=t*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=n){const t=i[r]-n,s=this.curves[r],o=s.getLength(),a=0===o?0:1-t/o;return s.getPointAt(a,e)}r++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let n=0,i=this.curves.length;n<i;n++)e+=this.curves[n].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let n;for(let i=0,r=this.curves;i<r.length;i++){const s=r[i],o=s.isEllipseCurve?2*t:s.isLineCurve||s.isLineCurve3?1:s.isSplineCurve?t*s.points.length:t,a=s.getPoints(o);for(let t=0;t<a.length;t++){const i=a[t];n&&n.equals(i)||(e.push(i),n=i)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const n=t.curves[e];this.curves.push(n.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,n=this.curves.length;e<n;e++){const n=this.curves[e];t.curves.push(n.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,n=t.curves.length;e<n;e++){const n=t.curves[e];this.curves.push((new vn[n.type]).fromJSON(n))}return this}}let Sn=class extends Mn{constructor(t){super(),this.type="Path",this.currentPoint=new E,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,n=t.length;e<n;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const n=new mn(this.currentPoint.clone(),new E(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,i){const r=new xn(this.currentPoint.clone(),new E(t,e),new E(n,i));return this.curves.push(r),this.currentPoint.set(n,i),this}bezierCurveTo(t,e,n,i,r,s){const o=new fn(this.currentPoint.clone(),new E(t,e),new E(n,i),new E(r,s));return this.curves.push(o),this.currentPoint.set(r,s),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new wn(e);return this.curves.push(n),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,n,i,r,s){const o=this.currentPoint.x,a=this.currentPoint.y;return this.absarc(t+o,e+a,n,i,r,s),this}absarc(t,e,n,i,r,s){return this.absellipse(t,e,n,n,i,r,s),this}ellipse(t,e,n,i,r,s,o,a){const h=this.currentPoint.x,l=this.currentPoint.y;return this.absellipse(t+h,e+l,n,i,r,s,o,a),this}absellipse(t,e,n,i,r,s,o,a){const h=new nn(t,e,n,i,r,s,o,a);if(this.curves.length>0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const l=h.getPoint(1);return this.currentPoint.copy(l),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}};class An extends Sn{constructor(t){super(t),this.uuid=A(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let n=0,i=this.holes.length;n<i;n++)e[n]=this.holes[n].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,n=t.holes.length;e<n;e++){const n=t.holes[e];this.holes.push(n.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,n=this.holes.length;e<n;e++){const n=this.holes[e];t.holes.push(n.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,n=t.holes.length;e<n;e++){const n=t.holes[e];this.holes.push((new Sn).fromJSON(n))}return this}}function zn(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=_n(t,0,r,n,!0);const o=[];if(!s||s.next===s.prev)return o;let a,h,l;if(i&&(s=function(t,e,n,i){const r=[];for(let s=0,o=e.length;s<o;s++){const n=_n(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Rn(n))}r.sort(Nn);for(let s=0;s<r.length;s++)n=In(r[s],n);return n}(t,e,s,n)),t.length>80*n){a=t[0],h=t[1];let e=a,i=h;for(let s=n;s<r;s+=n){const n=t[s],r=t[s+1];n<a&&(a=n),r<h&&(h=r),n>e&&(e=n),r>i&&(i=r)}l=Math.max(e-a,i-h),l=0!==l?32767/l:0}return Bn(s,o,n,a,h,l,0),o}function _n(t,e,n,i,r){let s;if(r===function(t,e,n,i){let r=0;for(let s=e,o=n-i;s<n;s+=i)r+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return r}(t,e,n,i)>0)for(let o=e;o<n;o+=i)s=Wn(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Wn(o/i|0,t[o],t[o+1],s);return s&&Dn(s,s.next)&&(Yn(s),s=s.next),s}function Tn(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Dn(i,i.next)&&0!==qn(i.prev,i,i.next))i=i.next;else{if(Yn(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function Bn(t,e,n,i,r,s,o){if(!t)return;!o&&s&&function(t,e,n,i){let r=t;do{0===r.z&&(r.z=Fn(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,n=1;do{let i,r=t;t=null;let s=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<n&&(a++,o=o.nextZ,o);t++);let h=n;for(;a>0||h>0&&o;)0!==a&&(0===h||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,h--),s?s.nextZ=i:t=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(e>1)}(r)}(t,i,r,s);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(s?Cn(t,i,r,s):Pn(t))e.push(h.i,t.i,l.i),Yn(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?Bn(t=En(Tn(t),e),e,n,i,r,s,2):2===o&&kn(t,e,n,i,r,s):Bn(Tn(t),e,n,i,r,s,1);break}}}function Pn(t){const e=t.prev,n=t,i=t.next;if(qn(e,n,i)>=0)return!1;const r=e.x,s=n.x,o=i.x,a=e.y,h=n.y,l=i.y,u=Math.min(r,s,o),c=Math.min(a,h,l),d=Math.max(r,s,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&Un(r,a,s,h,o,l,f.x,f.y)&&qn(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Cn(t,e,n,i){const r=t.prev,s=t,o=t.next;if(qn(r,s,o)>=0)return!1;const a=r.x,h=s.x,l=o.x,u=r.y,c=s.y,d=o.y,p=Math.min(a,h,l),f=Math.min(u,c,d),y=Math.max(a,h,l),m=Math.max(u,c,d),g=Fn(p,f,e,n,i),x=Fn(y,m,e,n,i);let b=t.prevZ,w=t.nextZ;for(;b&&b.z>=g&&w&&w.z<=x;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&Un(a,u,h,c,l,d,b.x,b.y)&&qn(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&Un(a,u,h,c,l,d,w.x,w.y)&&qn(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;b&&b.z>=g;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&Un(a,u,h,c,l,d,b.x,b.y)&&qn(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;w&&w.z<=x;){if(w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&Un(a,u,h,c,l,d,w.x,w.y)&&qn(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function En(t,e){let n=t;do{const i=n.prev,r=n.next.next;!Dn(i,r)&&Xn(i,n,n.next,r)&&Gn(i,r)&&Gn(r,i)&&(e.push(i.i,n.i,r.i),Yn(n),Yn(n.next),n=t=r),n=n.next}while(n!==t);return Tn(n)}function kn(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Ln(o,t)){let a=Jn(o,t);return o=Tn(o,o.next),a=Tn(a,a.next),Bn(o,e,n,i,r,s,0),void Bn(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function Nn(t,e){let n=t.x-e.x;if(0===n&&(n=t.y-e.y,0===n)){n=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}return n}function In(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(Dn(t,n))return n;do{if(Dn(t,n.next))return n.next;if(r<=n.y&&r>=n.next.y&&n.next.y!==n.y){const t=n.x+(r-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(t<=i&&t>o&&(o=t,s=n.x<n.next.x?n:n.next,t===i))return s}n=n.next}while(n!==e);if(!s)return null;const a=s,h=s.x,l=s.y;let u=1/0;n=s;do{if(i>=n.x&&n.x>=h&&i!==n.x&&Vn(r<l?i:o,r,h,l,r<l?o:i,r,n.x,n.y)){const e=Math.abs(r-n.y)/(i-n.x);Gn(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&On(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Jn(n,t);return Tn(i,i.next),Tn(n,n.next)}function On(t,e){return qn(t.prev,t,e.prev)<0&&qn(e.next,t,t.next)<0}function Fn(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Rn(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function Vn(t,e,n,i,r,s,o,a){return(r-o)*(e-a)>=(t-o)*(s-a)&&(t-o)*(i-a)>=(n-o)*(e-a)&&(n-o)*(s-a)>=(r-o)*(i-a)}function Un(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&Vn(t,e,n,i,r,s,o,a)}function Ln(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Xn(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Gn(t,e)&&Gn(e,t)&&function(t,e){let n=t,i=!1;const r=(t.x+e.x)/2,s=(t.y+e.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&r<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(qn(t.prev,t,e.prev)||qn(t,e.prev,e))||Dn(t,e)&&qn(t.prev,t,t.next)>0&&qn(e.prev,e,e.next)>0)}function qn(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Dn(t,e){return t.x===e.x&&t.y===e.y}function Xn(t,e,n,i){const r=jn(qn(t,e,n)),s=jn(qn(t,e,i)),o=jn(qn(n,i,t)),a=jn(qn(n,i,e));return r!==s&&o!==a||(!(0!==r||!Zn(t,n,e))||(!(0!==s||!Zn(t,i,e))||(!(0!==o||!Zn(n,t,i))||!(0!==a||!Zn(n,e,i)))))}function Zn(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function jn(t){return t>0?1:t<0?-1:0}function Gn(t,e){return qn(t.prev,t,t.next)<0?qn(t,e,t.next)>=0&&qn(t,t.prev,e)>=0:qn(t,e,t.prev)<0||qn(t,t.next,e)<0}function Jn(t,e){const n=$n(t.i,t.x,t.y),i=$n(e.i,e.x,e.y),r=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,s.next=i,i.prev=s,i}function Wn(t,e,n,i){const r=$n(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Yn(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function $n(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}class Hn{static triangulate(t,e,n=2){return zn(t,e,n)}}class Qn{static area(t){const e=t.length;let n=0;for(let i=e-1,r=0;r<e;i=r++)n+=t[i].x*t[r].y-t[r].x*t[i].y;return.5*n}static isClockWise(t){return Qn.area(t)<0}static triangulateShape(t,e){const n=[],i=[],r=[];Kn(t),ti(n,t);let s=t.length;e.forEach(Kn);for(let a=0;a<e.length;a++)i.push(s),s+=e[a].length,ti(n,e[a]);const o=Hn.triangulate(n,i);for(let a=0;a<o.length;a+=3)r.push(o.slice(a,a+3));return r}}function Kn(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function ti(t,e){for(let n=0;n<e.length;n++)t.push(e[n].x),t.push(e[n].y)}class ei extends Re{constructor(t=1,e=1,n=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:n,heightSegments:i};const r=t/2,s=e/2,o=Math.floor(n),a=Math.floor(i),h=o+1,l=a+1,u=t/o,c=e/a,d=[],p=[],f=[],y=[];for(let m=0;m<l;m++){const t=m*c-s;for(let e=0;e<h;e++){const n=e*u-r;p.push(n,-t,0),f.push(0,0,1),y.push(e/o),y.push(1-m/a)}}for(let m=0;m<a;m++)for(let t=0;t<o;t++){const e=t+h*m,n=t+h*(m+1),i=t+1+h*(m+1),r=t+1+h*m;d.push(e,n,r),d.push(n,i,r)}this.setIndex(d),this.setAttribute("position",new Pe(p,3)),this.setAttribute("normal",new Pe(f,3)),this.setAttribute("uv",new Pe(y,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ei(t.width,t.height,t.widthSegments,t.heightSegments)}}const ni=new N,ii=new N,ri=new N,si=new N,oi=new N,ai=new N,hi=new N;class li{constructor(t=new N,e=new N){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){ni.subVectors(t,this.start),ii.subVectors(this.end,this.start);const n=ii.dot(ii);let i=ii.dot(ni)/n;return e&&(i=z(i,0,1)),i}closestPointToPoint(t,e,n){const i=this.closestPointToPointParameter(t,e);return this.delta(n).multiplyScalar(i).add(this.start)}distanceSqToLine3(t,e=ai,n=hi){const i=1e-8*1e-8;let r,s;const o=this.start,a=t.start,h=this.end,l=t.end;ri.subVectors(h,o),si.subVectors(l,a),oi.subVectors(o,a);const u=ri.dot(ri),c=si.dot(si),d=si.dot(oi);if(u<=i&&c<=i)return e.copy(o),n.copy(a),e.sub(n),e.dot(e);if(u<=i)r=0,s=d/c,s=z(s,0,1);else{const t=ri.dot(oi);if(c<=i)s=0,r=z(-t/u,0,1);else{const e=ri.dot(si),n=u*c-e*e;r=0!==n?z((e*d-t*c)/n,0,1):0,s=(e*r+d)/c,s<0?(s=0,r=z(-t/u,0,1)):s>1&&(s=1,r=z((e-t)/u,0,1))}}return e.copy(o).add(ri.multiplyScalar(r)),n.copy(a).add(si.multiplyScalar(s)),e.sub(n),e.dot(e)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return(new this.constructor).copy(this)}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:t}})),"undefined"!=typeof window&&(window.__THREE__?m("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=t);const ui=new Map,ci=(t={})=>({generateTopUV(e,n,i,r,s){const o=n[3*i],a=n[3*i+1],h=n[3*r],l=n[3*r+1],u=n[3*s],c=n[3*s+1];let d;if(ui.has(e))d=ui.get(e);else{let n=t.box3;if(!n){n=new K;const t=e.parameters.shapes.getPoints().flatMap(t=>[t.x,t.y,0]);n.setFromArray(t)}const i=n.getSize(new N);t.split&&(i.y/=t.split),d={box:n,size:i},ui.set(e,d)}const{box:p,size:f}=d,y=t.split?1-t.split:0;return[new E((o-p.min.x)/f.x,(a-p.min.y)/f.y+y),new E((h-p.min.x)/f.x,(l-p.min.y)/f.y+y),new E((u-p.min.x)/f.x,(c-p.min.y)/f.y+y)]},generateSideWallUV(e,n,i,r,s,o){const a=n[3*i],h=n[3*i+1],l=n[3*i+2],u=n[3*r],c=n[3*r+1],d=n[3*r+2],p=n[3*s],f=n[3*s+1],y=n[3*s+2],m=n[3*o],g=n[3*o+1],x=n[3*o+2];let b;if(ui.has(n))b=ui.get(n);else{const e=new K;e.setFromArray(n);const i=e.getSize(new N);t.split&&(i.z/=1-t.split),t.sideRepeat&&(i.z/=t.sideRepeat),b={box:e,size:i},ui.set(n,b)}const{box:w,size:v}=b;return Math.abs(h-c)<Math.abs(a-u)?[new E((a-w.min.x)/v.x,(l-w.min.z)/v.z),new E((u-w.min.x)/v.x,(d-w.min.z)/v.z),new E((p-w.min.x)/v.x,(y-w.min.z)/v.z),new E((m-w.min.x)/v.x,(x-w.min.z)/v.z)]:[new E((h-w.min.y)/v.y,(l-w.min.z)/v.z),new E((c-w.min.y)/v.y,(d-w.min.z)/v.z),new E((f-w.min.y)/v.y,(y-w.min.z)/v.z),new E((g-w.min.y)/v.y,(x-w.min.z)/v.z)]}}),di={ArcCurve:rn,CatmullRomCurve3:un,CubicBezierCurve:fn,CubicBezierCurve3:yn,EllipseCurve:nn,LineCurve:mn,LineCurve3:gn,QuadraticBezierCurve:xn,QuadraticBezierCurve3:bn,SplineCurve:wn};class pi extends Re{constructor(t=new An([new E(.5,.5),new E(-.5,.5),new E(-.5,-.5),new E(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const n=this,i=[],r=[];for(let o=0,a=t.length;o<a;o++){s(t[o])}function s(t){var s,o,a;const h=[],l=void 0!==e.curveSegments?e.curveSegments:12,u=void 0!==e.steps?e.steps:1,c=void 0!==e.depth?e.depth:1;let d=void 0===e.bevelEnabled||e.bevelEnabled,p=void 0!==e.bevelThickness?e.bevelThickness:.2,f=void 0!==e.bevelSize?e.bevelSize:p-.1,y=void 0!==e.bevelOffset?e.bevelOffset:0,m=void 0!==e.bevelSegments?e.bevelSegments:3;const g=e.extrudePath,x=void 0!==e.UVGenerator?e.UVGenerator:fi,b=null==(s=e.hasTop)||s,w=null==(o=e.hasBottom)||o,v=null==(a=e.hasSide)||a;let M,S,A,z,_,T=!1;g&&(M=g.getSpacedPoints(u),T=!0,d=!1,S=g.computeFrenetFrames(u,!1),A=new N,z=new N,_=new N),d||(m=0,p=0,f=0,y=0);const B=t.extractPoints(l);let P=B.shape;const C=B.holes;if(!Qn.isClockWise(P)){P=P.reverse();for(let t=0,e=C.length;t<e;t++){const e=C[t];Qn.isClockWise(e)&&(C[t]=e.reverse())}}function k(t){const e=1e-10*1e-10;let n=t[0];for(let i=1;i<=t.length;i++){const r=i%t.length,s=t[r],o=s.x-n.x,a=s.y-n.y,h=o*o+a*a,l=Math.max(Math.abs(s.x),Math.abs(s.y),Math.abs(n.x),Math.abs(n.y));h<=e*l*l?(t.splice(r,1),i--):n=s}}k(P),C.forEach(k);const I=C.length,O=P;for(let e=0;e<I;e++){const t=C[e];P=P.concat(t)}function F(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const R=P.length;function V(t,e,n){let i,r,s;const o=t.x-e.x,a=t.y-e.y,h=n.x-t.x,l=n.y-t.y,u=o*o+a*a,c=o*l-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(u),d=Math.sqrt(h*h+l*l),p=e.x-a/c,f=e.y+o/c,y=((n.x-l/d-p)*l-(n.y+h/d-f)*h)/(o*l-a*h);i=p+o*y-t.x,r=f+a*y-t.y;const m=i*i+r*r;if(m<=2)return new E(i,r);s=Math.sqrt(m/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(l)&&(t=!0),t?(i=-a,r=o,s=Math.sqrt(u)):(i=o,r=a,s=Math.sqrt(u/2))}return new E(i/s,r/s)}const U=[];for(let e=0,n=O.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),U[e]=V(O[e],O[i],O[r]);const L=[];let q,D,X=U.concat();for(let e=0,n=I;e<n;e++){const t=C[e];q=[];for(let e=0,n=t.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),q[e]=V(t[e],t[i],t[r]);L.push(q),X=X.concat(q)}if(0===m)D=Qn.triangulateShape(O,C);else{const t=[],e=[];for(let n=0;n<m;n++){const i=n/m,r=p*Math.cos(i*Math.PI/2),s=f*Math.sin(i*Math.PI/2)+y;for(let e=0,n=O.length;e<n;e++){const n=F(O[e],U[e],s);J(n.x,n.y,-r),0===i&&t.push(n)}for(let t=0,n=I;t<n;t++){const n=C[t];q=L[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=F(n[t],q[t],s);J(e.x,e.y,-r),0===i&&o.push(e)}0===i&&e.push(o)}}D=Qn.triangulateShape(t,e)}const Z=D.length,j=f+y;for(let e=0;e<R;e++){const t=d?F(P[e],X[e],j):P[e];T?(z.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),_.copy(M[0]).add(z).add(A),J(_.x,_.y,_.z)):J(t.x,t.y,0)}for(let e=1;e<=u;e++)for(let t=0;t<R;t++){const n=d?F(P[t],X[t],j):P[t];T?(z.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),_.copy(M[e]).add(z).add(A),J(_.x,_.y,_.z)):J(n.x,n.y,c/u*e)}for(let e=m-1;e>=0;e--){const t=e/m,n=p*Math.cos(t*Math.PI/2),i=f*Math.sin(t*Math.PI/2)+y;for(let e=0,r=O.length;e<r;e++){const t=F(O[e],U[e],i);J(t.x,t.y,c+n)}for(let e=0,r=C.length;e<r;e++){const t=C[e];q=L[e];for(let e=0,r=t.length;e<r;e++){const r=F(t[e],q[e],i);T?J(r.x,r.y+M[u-1].y,M[u-1].x+n):J(r.x,r.y,c+n)}}}function G(t,e){let n=t.length;for(;--n>=0;){const i=n;let r=n-1;r<0&&(r=t.length-1);for(let t=0,n=u+2*m;t<n;t++){const n=R*t,s=R*(t+1);Y(e+i+n,e+r+n,e+r+s,e+i+s)}}}function J(t,e,n){h.push(t),h.push(e),h.push(n)}function W(t,e,r){$(t),$(e),$(r);const s=i.length/3,o=x.generateTopUV(n,i,s-3,s-2,s-1);H(o[0]),H(o[1]),H(o[2])}function Y(t,e,r,s){$(t),$(e),$(s),$(e),$(r),$(s);const o=i.length/3,a=x.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);H(a[0]),H(a[1]),H(a[3]),H(a[1]),H(a[2]),H(a[3])}function $(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function H(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=R*t;if(w)for(let n=0;n<Z;n++){const t=D[n];W(t[2]+e,t[1]+e,t[0]+e)}if(t=u+2*m,e=R*t,b)for(let n=0;n<Z;n++){const t=D[n];W(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<Z;t++){const e=D[t];W(e[2],e[1],e[0])}if(b)for(let t=0;t<Z;t++){const e=D[t];W(e[0]+R*u,e[1]+R*u,e[2]+R*u)}}n.addGroup(t,i.length/3-t,0)}(),v&&function(){const t=i.length/3;let e=0;G(O,e),e+=O.length;for(let n=0,i=C.length;n<i;n++){const t=C[n];G(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new Pe(i,3)),this.setAttribute("uv",new Pe(r,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,n){if(n.shapes=[],Array.isArray(t))for(let i=0,r=t.length;i<r;i++){const e=t[i];n.shapes.push(e.uuid)}else n.shapes.push(t.uuid);n.options=Object.assign({},e),void 0!==e.extrudePath&&(n.options.extrudePath=e.extrudePath.toJSON());return n}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const n=[];for(let r=0,s=t.shapes.length;r<s;r++){const i=e[t.shapes[r]];n.push(i)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new di[i.type]).fromJSON(i)),new pi(n,t.options)}}const fi={generateTopUV:function(t,e,n,i,r){const s=e[3*n],o=e[3*n+1],a=e[3*i],h=e[3*i+1],l=e[3*r],u=e[3*r+1];return[new E(s,o),new E(a,h),new E(l,u)]},generateSideWallUV:function(t,e,n,i,r,s){const o=e[3*n],a=e[3*n+1],h=e[3*n+2],l=e[3*i],u=e[3*i+1],c=e[3*i+2],d=e[3*r],p=e[3*r+1],f=e[3*r+2],y=e[3*s],m=e[3*s+1],g=e[3*s+2];return Math.abs(a-u)<Math.abs(o-l)?[new E(o,1-h),new E(l,1-c),new E(d,1-f),new E(y,1-g)]:[new E(a,1-h),new E(u,1-c),new E(p,1-f),new E(m,1-g)]}};const yi=1.25,mi=32,gi=Math.pow(2,-24),xi=Symbol("SKIP_GENERATION");function bi(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function wi(t,e){if(!t.index){const n=t.attributes.position.count,i=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(n,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new _e(i,1));for(let t=0;t<n;t++)i[t]=t}}function vi(t,e){const n=bi(t),i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=Math.max(0,r),a=Math.min(n,s)-o;return[{offset:Math.floor(o),count:Math.floor(a)}]}function Mi(t,e){if(!t.groups||!t.groups.length)return vi(t,e);const n=[],i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=bi(t),a=[];for(const u of t.groups){const{start:t,count:e}=u,n=t/3,i=(t+(isFinite(e)?e:3*o-t))/3;n<s&&i>r&&(a.push({pos:Math.max(r,n),isStart:!0}),a.push({pos:Math.min(s,i),isStart:!1}))}a.sort((t,e)=>t.pos!==e.pos?t.pos-e.pos:"end"===t.type?-1:1);let h=0,l=null;for(const u of a){const t=u.pos;0!==h&&t!==l&&n.push({offset:l,count:t-l}),h+=u.isStart?1:-1,l=t}return n}function Si(t,e,n,i,r){let s=1/0,o=1/0,a=1/0,h=-1/0,l=-1/0,u=-1/0,c=1/0,d=1/0,p=1/0,f=-1/0,y=-1/0,m=-1/0;const g=t.offset||0;for(let x=6*(e-g),b=6*(e+n-g);x<b;x+=6){const e=t[x+0],n=t[x+1],i=e-n,r=e+n;i<s&&(s=i),r>h&&(h=r),e<c&&(c=e),e>f&&(f=e);const g=t[x+2],b=t[x+3],w=g-b,v=g+b;w<o&&(o=w),v>l&&(l=v),g<d&&(d=g),g>y&&(y=g);const M=t[x+4],S=t[x+5],A=M-S,z=M+S;A<a&&(a=A),z>u&&(u=z),M<p&&(p=M),M>m&&(m=M)}i[0]=s,i[1]=o,i[2]=a,i[3]=h,i[4]=l,i[5]=u,r[0]=c,r[1]=d,r[2]=p,r[3]=f,r[4]=y,r[5]=m}function Ai(t,e,n=null,i=null,r=null){const s=t.attributes.position,o=t.index?t.index.array:null,a=s.normalized;if(null===r)(r=new Float32Array(6*n)).offset=e;else if(e<0||n+e>r.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const h=s.array,l=s.offset||0;let u=3;s.isInterleavedBufferAttribute&&(u=s.data.stride);const c=["getX","getY","getZ"],d=r.offset;for(let p=e,f=e+n;p<f;p++){const t=3*(i?i[p]:p),e=6*(p-d);let n=t+0,f=t+1,y=t+2;o&&(n=o[n],f=o[f],y=o[y]),a||(n=n*u+l,f=f*u+l,y=y*u+l);for(let i=0;i<3;i++){let t,o,l;a?(t=s[c[i]](n),o=s[c[i]](f),l=s[c[i]](y)):(t=h[n+i],o=h[f+i],l=h[y+i]);let u=t;o<u&&(u=o),l<u&&(u=l);let d=t;o>d&&(d=o),l>d&&(d=l);const p=(d-u)/2,m=2*i;r[e+m+0]=u+p,r[e+m+1]=p+(Math.abs(u)+p)*gi}}return r}function zi(t,e,n){return n.min.x=e[t],n.min.y=e[t+1],n.min.z=e[t+2],n.max.x=e[t+3],n.max.y=e[t+4],n.max.z=e[t+5],n}function _i(t){let e=-1,n=-1/0;for(let i=0;i<3;i++){const r=t[i+3]-t[i];r>n&&(n=r,e=i)}return e}function Ti(t,e){e.set(t)}function Bi(t,e,n){let i,r;for(let s=0;s<3;s++){const o=s+3;i=t[s],r=e[s],n[s]=i<r?i:r,i=t[o],r=e[o],n[o]=i>r?i:r}}function Pi(t,e,n){for(let i=0;i<3;i++){const r=e[t+2*i],s=e[t+2*i+1],o=r-s,a=r+s;o<n[i]&&(n[i]=o),a>n[i+3]&&(n[i+3]=a)}}function Ci(t){const e=t[3]-t[0],n=t[4]-t[1],i=t[5]-t[2];return 2*(e*n+n*i+i*e)}const Ei=32,ki=(t,e)=>t.candidate-e.candidate,Ni=new Array(Ei).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ii=new Float32Array(6);class Oi{constructor(){this.boundingData=new Float32Array(6)}}function Fi(t,e,n,i,r,s){let o=i,a=i+r-1;const h=s.pos,l=2*s.axis,u=n.offset||0;for(;;){for(;o<=a&&n[6*(o-u)+l]<h;)o++;for(;o<=a&&n[6*(a-u)+l]>=h;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let n=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=n}for(let t=0;t<6;t++){const e=o-u,i=a-u,r=n[6*e+t];n[6*e+t]=n[6*i+t],n[6*i+t]=r}o++,a--}}function Ri(t,e,n,i,r,s){let o=i,a=i+r-1;const h=s.pos,l=2*s.axis,u=n.offset||0;for(;;){for(;o<=a&&n[6*(o-u)+l]<h;)o++;for(;o<=a&&n[6*(a-u)+l]>=h;)a--;if(!(o<a))return o;{let e=t[o];t[o]=t[a],t[a]=e;for(let t=0;t<6;t++){const e=o-u,i=a-u,r=n[6*e+t];n[6*e+t]=n[6*i+t],n[6*i+t]=r}o++,a--}}}let Vi,Ui,Li,qi;const Di=Math.pow(2,32);function Xi(t){return"count"in t?1:1+Xi(t.left)+Xi(t.right)}function Zi(t,e,n){return Vi=new Float32Array(n),Ui=new Uint32Array(n),Li=new Uint16Array(n),qi=new Uint8Array(n),ji(t,e)}function ji(t,e){const n=t/4,i=t/2,r="count"in e,s=e.boundingData;for(let o=0;o<6;o++)Vi[n+o]=s[o];if(r)return e.buffer?(qi.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(Ui[n+6]=e.offset,Li[i+14]=e.count,Li[i+15]=65535,t+mi);{const{left:i,right:r,splitAxis:s}=e;let o=ji(t+mi,i);const a=o/mi-t/mi;if(a>Di)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ui[n+6]=a,Ui[n+7]=s,ji(o,r)}}function Gi(t,e,n,i,r){const{maxDepth:s,verbose:o,maxLeafTris:a,strategy:h,onProgress:l,indirect:u}=r,c=t._indirectBuffer,d=t.geometry,p=d.index?d.index.array:null,f=u?Ri:Fi,y=bi(d),m=new Float32Array(6);let g=!1;const x=new Oi;return Si(e,n,i,x.boundingData,m),function t(n,i,r,l=null,u=0){!g&&u>=s&&(g=!0,o&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d)));if(r<=a||u>=s)return b(i+r),n.offset=i,n.count=r,n;const y=function(t,e,n,i,r,s){let o=-1,a=0;if(0===s)o=_i(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===s)o=_i(t),-1!==o&&(a=function(t,e,n,i){let r=0;const s=t.offset;for(let o=e,a=e+n;o<a;o++)r+=t[6*(o-s)+2*i];return r/n}(n,i,r,o));else if(2===s){const s=Ci(t);let h=yi*r;const l=n.offset||0,u=6*(i-l),c=6*(i+r-l);for(let t=0;t<3;t++){const i=e[t],l=(e[t+3]-i)/Ei;if(r<8){const e=[...Ni];e.length=r;let i=0;for(let r=u;r<c;r+=6,i++){const s=e[i];s.candidate=n[r+2*t],s.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:h}=s;for(let t=0;t<3;t++)h[t]=1/0,h[t+3]=-1/0,a[t]=1/0,a[t+3]=-1/0,o[t]=1/0,o[t+3]=-1/0;Pi(r,n,o)}e.sort(ki);let l=r;for(let t=0;t<l;t++){const n=e[t];for(;t+1<l&&e[t+1].candidate===n.candidate;)e.splice(t+1,1),l--}for(let r=u;r<c;r+=6){const i=n[r+2*t];for(let t=0;t<l;t++){const s=e[t];i>=s.candidate?Pi(r,n,s.rightCacheBounds):(Pi(r,n,s.leftCacheBounds),s.count++)}}for(let n=0;n<l;n++){const i=e[n],l=i.count,u=r-i.count,c=i.leftCacheBounds,d=i.rightCacheBounds;let p=0;0!==l&&(p=Ci(c)/s);let f=0;0!==u&&(f=Ci(d)/s);const y=1+yi*(p*l+f*u);y<h&&(o=t,h=y,a=i.candidate)}}else{for(let t=0;t<Ei;t++){const e=Ni[t];e.count=0,e.candidate=i+l+t*l;const n=e.bounds;for(let t=0;t<3;t++)n[t]=1/0,n[t+3]=-1/0}for(let r=u;r<c;r+=6){let e=~~((n[r+2*t]-i)/l);e>=Ei&&(e=31);const s=Ni[e];s.count++,Pi(r,n,s.bounds)}const e=Ni[31];Ti(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=Ni[t],n=Ni[t+1];Bi(e.bounds,n.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let n=0;n<31;n++){const e=Ni[n],i=e.count,l=e.bounds,u=Ni[n+1].rightCacheBounds;0!==i&&(0===d?Ti(l,Ii):Bi(l,Ii,Ii)),d+=i;let c=0,p=0;0!==d&&(c=Ci(Ii)/s);const f=r-d;0!==f&&(p=Ci(u)/s);const y=1+yi*(c*d+p*f);y<h&&(o=t,h=y,a=e.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:o,pos:a}}(n.boundingData,l,e,i,r,h);if(-1===y.axis)return b(i+r),n.offset=i,n.count=r,n;const x=f(c,p,e,i,r,y);if(x===i||x===i+r)b(i+r),n.offset=i,n.count=r;else{n.splitAxis=y.axis;const s=new Oi,o=i,a=x-i;n.left=s,Si(e,o,a,s.boundingData,m),t(s,o,a,m,u+1);const h=new Oi,l=x,c=r-a;n.right=h,Si(e,l,c,h.boundingData,m),t(h,l,c,m,u+1)}return n}(x,n,i,m),x;function b(t){l&&l(t/y)}}function Ji(t,e){const n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=t.geometry;let r,s;if(e.indirect){const n=Mi(i,e.range),o=function(t,e,n){const i=(t.index?t.index.count:t.attributes.position.count)/3>h(2,16),r=n.reduce((t,e)=>t+e.count,0),s=i?4:2,o=e?new SharedArrayBuffer(r*s):new ArrayBuffer(r*s),a=i?new Uint32Array(o):new Uint16Array(o);let l=0;for(let h=0;h<n.length;h++){const{offset:t,count:e}=n[h];for(let n=0;n<e;n++)a[l+n]=t+n;l+=e}return a}(i,e.useSharedArrayBuffer,n);t._indirectBuffer=o,r=Ai(i,0,o.length,o),s=[{offset:0,count:o.length}]}else{wi(i,e);const t=vi(i,e.range)[0];r=Ai(i,t.offset,t.count),s=Mi(i,e.range)}t._roots=s.map(i=>{const s=Gi(t,r,i.offset,i.count,e),o=Xi(s),a=new n(mi*o);return Zi(0,s,a),a})}class Wi{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let n=1/0,i=-1/0;for(let r=0,s=t.length;r<s;r++){const s=t[r][e];n=s<n?s:n,i=s>i?s:i}this.min=n,this.max=i}setFromPoints(t,e){let n=1/0,i=-1/0;for(let r=0,s=e.length;r<s;r++){const s=e[r],o=t.dot(s);n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}}Wi.prototype.setFromBox=function(){const t=new N;return function(e,n){const i=n.min,r=n.max;let s=1/0,o=-1/0;for(let a=0;a<=1;a++)for(let n=0;n<=1;n++)for(let h=0;h<=1;h++){t.x=i.x*a+r.x*(1-a),t.y=i.y*n+r.y*(1-n),t.z=i.z*h+r.z*(1-h);const l=e.dot(t);s=Math.min(l,s),o=Math.max(l,o)}this.min=s,this.max=o}}();const Yi=function(){const t=new N,e=new N,n=new N;return function(i,r,s){const o=i.start,a=t,h=r.start,l=e;n.subVectors(o,h),t.subVectors(i.end,i.start),e.subVectors(r.end,r.start);const u=n.dot(l),c=l.dot(a),d=l.dot(l),p=n.dot(a),f=a.dot(a)*d-c*c;let y,m;y=0!==f?(u*c-p*d)/f:0,m=(u+y*c)/d,s.x=y,s.y=m}}(),$i=function(){const t=new E,e=new N,n=new N;return function(i,r,s,o){Yi(i,r,t);let a=t.x,h=t.y;if(a>=0&&a<=1&&h>=0&&h<=1)return i.at(a,s),void r.at(h,o);if(a>=0&&a<=1)return h<0?r.at(0,o):r.at(1,o),void i.closestPointToPoint(o,!0,s);if(h>=0&&h<=1)return a<0?i.at(0,s):i.at(1,s),void r.closestPointToPoint(s,!0,o);{let t,l;t=a<0?i.start:i.end,l=h<0?r.start:r.end;const u=e,c=n;return i.closestPointToPoint(l,!0,e),r.closestPointToPoint(t,!0,n),u.distanceToSquared(l)<=c.distanceToSquared(t)?(s.copy(u),void o.copy(l)):(s.copy(t),void o.copy(c))}}}(),Hi=function(){const t=new N,e=new N,n=new tn,i=new li;return function(r,s){const{radius:o,center:a}=r,{a:h,b:l,c:u}=s;i.start=h,i.end=l;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=h,i.end=u;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=l,i.end=u;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const c=s.getPlane(n);if(Math.abs(c.distanceToPoint(a))<=o){const t=c.projectPoint(a,e);if(s.containsPoint(t))return!0}return!1}}(),Qi=["x","y","z"],Ki=1e-15;function tr(t){return Math.abs(t)<Ki}class er extends pe{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new N),this.satBounds=new Array(4).fill().map(()=>new Wi),this.points=[this.a,this.b,this.c],this.plane=new tn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new li,this.needsUpdate=!0}intersectsSphere(t){return Hi(t,this)}update(){const t=this.a,e=this.b,n=this.c,i=this.points,r=this.satAxes,s=this.satBounds,o=r[0],a=s[0];this.getNormal(o),a.setFromPoints(o,i);const h=r[1],l=s[1];h.subVectors(t,e),l.setFromPoints(h,i);const u=r[2],c=s[2];u.subVectors(e,n),c.setFromPoints(u,i);const d=r[3],p=s[3];d.subVectors(n,t),p.setFromPoints(d,i);const f=h.length(),y=u.length(),m=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,f<Ki?y<Ki||m<Ki?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(n)):y<Ki?m<Ki?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):m<Ki&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}er.prototype.closestPointToSegment=function(){const t=new N,e=new N,n=new li;return function(i,r=null,s=null){const{start:o,end:a}=i,h=this.points;let l,u=1/0;for(let c=0;c<3;c++){const o=(c+1)%3;n.start.copy(h[c]),n.end.copy(h[o]),$i(n,i,t,e),l=t.distanceToSquared(e),l<u&&(u=l,r&&r.copy(t),s&&s.copy(e))}return this.closestPointToPoint(o,t),l=o.distanceToSquared(t),l<u&&(u=l,r&&r.copy(t),s&&s.copy(o)),this.closestPointToPoint(a,t),l=a.distanceToSquared(t),l<u&&(u=l,r&&r.copy(t),s&&s.copy(a)),Math.sqrt(u)}}(),er.prototype.intersectsTriangle=function(){const t=new er,e=new Wi,n=new Wi,i=new N,r=new N,s=new N,o=new N,a=new li,h=new li,l=new N,u=new E,c=new E;function d(t,r,s,a){const h=i;t.isDegenerateIntoPoint||t.isDegenerateIntoSegment?h.copy(r.plane.normal):h.copy(t.plane.normal);const l=t.satBounds,u=t.satAxes;for(let i=1;i<4;i++){const s=l[i],a=u[i];if(e.setFromPoints(a,r.points),s.isSeparated(e))return!1;if(o.copy(h).cross(a),e.setFromPoints(o,t.points),n.setFromPoints(o,r.points),e.isSeparated(n))return!1}const c=r.satBounds,d=r.satAxes;for(let i=1;i<4;i++){const s=c[i],a=d[i];if(e.setFromPoints(a,t.points),s.isSeparated(e))return!1;if(o.crossVectors(h,a),e.setFromPoints(o,t.points),n.setFromPoints(o,r.points),e.isSeparated(n))return!1}return s&&(a||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),s.start.set(0,0,0),s.end.set(0,0,0)),!0}function p(t,e,n,i,r,s,o,a,h,l,u){let c=o/(o-a);l.x=i+(r-i)*c,u.start.subVectors(e,t).multiplyScalar(c).add(t),c=o/(o-h),l.y=i+(s-i)*c,u.end.subVectors(n,t).multiplyScalar(c).add(t)}function f(t,e,n,i,r,s,o,a,h,l,u){if(r>0)p(t.c,t.a,t.b,i,e,n,h,o,a,l,u);else if(s>0)p(t.b,t.a,t.c,n,e,i,a,o,h,l,u);else if(a*h>0||0!=o)p(t.a,t.b,t.c,e,n,i,o,a,h,l,u);else if(0!=a)p(t.b,t.a,t.c,n,e,i,a,o,h,l,u);else{if(0==h)return!0;p(t.c,t.a,t.b,i,e,n,h,o,a,l,u)}return!1}function y(t,e,n,r){const s=e.degenerateSegment,o=t.plane.distanceToPoint(s.start),a=t.plane.distanceToPoint(s.end);return tr(o)?tr(a)?d(t,e,n,r):(n&&(n.start.copy(s.start),n.end.copy(s.start)),t.containsPoint(s.start)):tr(a)?(n&&(n.start.copy(s.end),n.end.copy(s.end)),t.containsPoint(s.end)):null!=t.plane.intersectLine(s,i)&&(n&&(n.start.copy(i),n.end.copy(i)),t.containsPoint(i))}function m(t,e,n){const i=e.a;return!(!tr(t.plane.distanceToPoint(i))||!t.containsPoint(i))&&(n&&(n.start.copy(i),n.end.copy(i)),!0)}function g(t,e,n){const r=t.degenerateSegment,s=e.a;return r.closestPointToPoint(s,!0,i),s.distanceToSquared(i)<1e-30&&(n&&(n.start.copy(s),n.end.copy(s)),!0)}return function(e,n=null,o=!1){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);const p=function(t,e,n,o){if(t.isDegenerateIntoSegment){if(e.isDegenerateIntoSegment){const o=t.degenerateSegment,a=e.degenerateSegment,h=r,l=s;o.delta(h),a.delta(l);const u=i.subVectors(a.start,o.start),c=h.x*l.y-h.y*l.x;if(tr(c))return!1;const d=(u.x*l.y-u.y*l.x)/c,p=-(h.x*u.y-h.y*u.x)/c;return!(d<0||d>1||p<0||p>1)&&(!!tr(o.start.z+h.z*d-(a.start.z+l.z*p))&&(n&&(n.start.copy(o.start).addScaledVector(h,d),n.end.copy(o.start).addScaledVector(h,d)),!0))}return e.isDegenerateIntoPoint?g(t,e,n):y(e,t,n,o)}return t.isDegenerateIntoPoint?e.isDegenerateIntoPoint?e.a.distanceToSquared(t.a)<1e-30&&(n&&(n.start.copy(t.a),n.end.copy(t.a)),!0):e.isDegenerateIntoSegment?g(e,t,n):m(e,t,n):e.isDegenerateIntoPoint?m(t,e,n):e.isDegenerateIntoSegment?y(t,e,n,o):void 0}(this,e,n,o);if(void 0!==p)return p;const x=this.plane,b=e.plane;let w=b.distanceToPoint(this.a),v=b.distanceToPoint(this.b),M=b.distanceToPoint(this.c);tr(w)&&(w=0),tr(v)&&(v=0),tr(M)&&(M=0);const S=w*v,A=w*M;if(S>0&&A>0)return!1;let z=x.distanceToPoint(e.a),_=x.distanceToPoint(e.b),T=x.distanceToPoint(e.c);tr(z)&&(z=0),tr(_)&&(_=0),tr(T)&&(T=0);const B=z*_,P=z*T;if(B>0&&P>0)return!1;r.copy(x.normal),s.copy(b.normal);const C=r.cross(s);let E=0,k=Math.abs(C.x);const N=Math.abs(C.y);N>k&&(k=N,E=1);Math.abs(C.z)>k&&(E=2);const I=Qi[E],O=this.a[I],F=this.b[I],R=this.c[I],V=e.a[I],U=e.b[I],L=e.c[I];if(f(this,O,F,R,S,A,w,v,M,u,a))return d(this,e,n,o);if(f(e,V,U,L,B,P,z,_,T,c,h))return d(this,e,n,o);if(u.y<u.x){const t=u.y;u.y=u.x,u.x=t,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(c.y<c.x){const t=c.y;c.y=c.x,c.x=t,l.copy(h.start),h.start.copy(h.end),h.end.copy(l)}return!(u.y<c.x||c.y<u.x)&&(n&&(c.x>u.x?n.start.copy(h.start):n.start.copy(a.start),c.y<u.y?n.end.copy(h.end):n.end.copy(a.end)),!0)}}(),er.prototype.distanceToPoint=function(){const t=new N;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),er.prototype.distanceToTriangle=function(){const t=new N,e=new N,n=["a","b","c"],i=new li,r=new li;return function(s,o=null,a=null){const h=o||a?i:null;if(this.intersectsTriangle(s,h))return(o||a)&&(o&&h.getCenter(o),a&&h.getCenter(a)),0;let l=1/0;for(let e=0;e<3;e++){let i;const r=n[e],h=s[r];this.closestPointToPoint(h,t),i=h.distanceToSquared(t),i<l&&(l=i,o&&o.copy(t),a&&a.copy(h));const u=this[r];s.closestPointToPoint(u,t),i=u.distanceToSquared(t),i<l&&(l=i,o&&o.copy(u),a&&a.copy(t))}for(let u=0;u<3;u++){const h=n[u],c=n[(u+1)%3];i.set(this[h],this[c]);for(let u=0;u<3;u++){const h=n[u],c=n[(u+1)%3];r.set(s[h],s[c]),$i(i,r,t,e);const d=t.distanceToSquared(e);d<l&&(l=d,o&&o.copy(t),a&&a.copy(e))}}return Math.sqrt(l)}}();class nr{constructor(t,e,n){this.isOrientedBox=!0,this.min=new N,this.max=new N,this.matrix=new _t,this.invMatrix=new _t,this.points=new Array(8).fill().map(()=>new N),this.satAxes=new Array(3).fill().map(()=>new N),this.satBounds=new Array(3).fill().map(()=>new Wi),this.alignedSatBounds=new Array(3).fill().map(()=>new Wi),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),n&&this.matrix.copy(n)}set(t,e,n){this.min.copy(t),this.max.copy(e),this.matrix.copy(n),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}nr.prototype.update=function(){return function(){const t=this.matrix,e=this.min,n=this.max,i=this.points;for(let h=0;h<=1;h++)for(let r=0;r<=1;r++)for(let s=0;s<=1;s++){const o=i[1*h|2*r|4*s];o.x=h?n.x:e.x,o.y=r?n.y:e.y,o.z=s?n.z:e.z,o.applyMatrix4(t)}const r=this.satBounds,s=this.satAxes,o=i[0];for(let h=0;h<3;h++){const t=s[h],e=r[h],n=i[1<<h];t.subVectors(o,n),e.setFromPoints(t,i)}const a=this.alignedSatBounds;a[0].setFromPointsField(i,"x"),a[1].setFromPointsField(i,"y"),a[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),nr.prototype.intersectsBox=function(){const t=new Wi;return function(e){this.needsUpdate&&this.update();const n=e.min,i=e.max,r=this.satBounds,s=this.satAxes,o=this.alignedSatBounds;if(t.min=n.x,t.max=i.x,o[0].isSeparated(t))return!1;if(t.min=n.y,t.max=i.y,o[1].isSeparated(t))return!1;if(t.min=n.z,t.max=i.z,o[2].isSeparated(t))return!1;for(let a=0;a<3;a++){const n=s[a],i=r[a];if(t.setFromBox(n,e),i.isSeparated(t))return!1}return!0}}(),nr.prototype.intersectsTriangle=function(){const t=new er,e=new Array(3),n=new Wi,i=new Wi,r=new N;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(t.copy(s),t.update(),s=t);const o=this.satBounds,a=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let t=0;t<3;t++){const i=o[t],r=a[t];if(n.setFromPoints(r,e),i.isSeparated(n))return!1}const h=s.satBounds,l=s.satAxes,u=this.points;for(let t=0;t<3;t++){const e=h[t],i=l[t];if(n.setFromPoints(i,u),e.isSeparated(n))return!1}for(let t=0;t<3;t++){const s=a[t];for(let t=0;t<4;t++){const o=l[t];if(r.crossVectors(s,o),n.setFromPoints(r,e),i.setFromPoints(r,u),n.isSeparated(i))return!1}}return!0}}(),nr.prototype.closestPointToPoint=function(){return function(t,e){return this.needsUpdate&&this.update(),e.copy(t).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),nr.prototype.distanceToPoint=function(){const t=new N;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),nr.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new li),n=new Array(12).fill().map(()=>new li),i=new N,r=new N;return function(s,o=0,a=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(a||h)&&(s.getCenter(r),this.closestPointToPoint(r,i),s.closestPointToPoint(i,r),a&&a.copy(i),h&&h.copy(r)),0;const l=o*o,u=s.min,c=s.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(u,c);const n=e.distanceToSquared(r);if(n<p&&(p=n,a&&a.copy(e),h&&h.copy(r),n<l))return Math.sqrt(n)}let f=0;for(let i=0;i<3;i++)for(let r=0;r<=1;r++)for(let s=0;s<=1;s++){const o=(i+1)%3,a=(i+2)%3,h=1<<i|r<<o|s<<a,l=d[r<<o|s<<a],p=d[h];e[f].set(l,p);const y=t[i],m=t[o],g=t[a],x=n[f],b=x.start,w=x.end;b[y]=u[y],b[m]=r?u[m]:c[m],b[g]=s?u[g]:c[m],w[y]=c[y],w[m]=r?u[m]:c[m],w[g]=s?u[g]:c[m],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let n=0;n<=1;n++){r.x=t?c.x:u.x,r.y=e?c.y:u.y,r.z=n?c.z:u.z,this.closestPointToPoint(r,i);const s=r.distanceToSquared(i);if(s<p&&(p=s,a&&a.copy(i),h&&h.copy(r),s<l))return Math.sqrt(s)}for(let t=0;t<12;t++){const s=e[t];for(let t=0;t<12;t++){const e=n[t];$i(s,e,i,r);const o=i.distanceToSquared(r);if(o<p&&(p=o,a&&a.copy(i),h&&h.copy(r),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}}();class ir{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return 0===t.length?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class rr extends ir{constructor(){super(()=>new er)}}const sr=new rr;function or(t,e){return 65535===e[t+15]}function ar(t,e){return e[t+6]}function hr(t,e){return e[t+14]}function lr(t){return t+8}function ur(t,e){return t+8*e[t+6]}function cr(t,e){return e[t+7]}function dr(t){return t}class pr{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=n=>{e&&t.push(e),e=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}}const fr=new pr;let yr,mr;const gr=[],xr=new ir(()=>new K);function br(t,e,n,i,r,s){yr=xr.getPrimitive(),mr=xr.getPrimitive(),gr.push(yr,mr),fr.setBuffer(t._roots[e]);const o=wr(0,t.geometry,n,i,r,s);fr.clearBuffer(),xr.releasePrimitive(yr),xr.releasePrimitive(mr),gr.pop(),gr.pop();const a=gr.length;return a>0&&(mr=gr[a-1],yr=gr[a-2]),o}function wr(t,e,n,i,r=null,s=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=fr;let u=2*t;if(or(u,h)){const e=ar(t,l),n=hr(u,h);return zi(t,a,yr),i(e,n,!1,o,s+t/8,yr)}{let u=function(t){const{uint16Array:e,uint32Array:n}=fr;let i=2*t;for(;!or(i,e);)i=2*(t=lr(t));return ar(t,n)},c=function(t){const{uint16Array:e,uint32Array:n}=fr;let i=2*t;for(;!or(i,e);)i=2*(t=ur(t,n));return ar(t,n)+hr(i,e)};const d=lr(t),p=ur(t,l);let f,y,m,g,x=d,b=p;if(r&&(m=yr,g=mr,zi(x,a,m),zi(b,a,g),f=r(m),y=r(g),y<f)){x=p,b=d;const t=f;f=y,y=t,m=g}m||(m=yr,zi(x,a,m));const w=n(m,or(2*x,h),f,o+1,s+x/8);let v;if(2===w){const t=u(x);v=i(t,c(x)-t,!0,o+1,s+x/8,m)}else v=w&&wr(x,e,n,i,r,s,o+1);if(v)return!0;g=mr,zi(b,a,g);const M=n(g,or(2*b,h),y,o+1,s+b/8);let S;if(2===M){const t=u(b);S=i(t,c(b)-t,!0,o+1,s+b/8,g)}else S=M&&wr(b,e,n,i,r,s,o+1);return!!S}}const vr=new N,Mr=new N;const Sr=parseInt(t)>=169,Ar=parseInt(t)<=161,zr=new N,_r=new N,Tr=new N,Br=new E,Pr=new E,Cr=new E,Er=new N,kr=new N,Nr=new N,Ir=new N;function Or(t,e,n,i,r,s,o,a,h,l,u){zr.fromBufferAttribute(e,s),_r.fromBufferAttribute(e,o),Tr.fromBufferAttribute(e,a);const c=function(t,e,n,i,r,s,o,a){let h;if(h=1===s?t.intersectTriangle(i,n,e,!0,r):t.intersectTriangle(e,n,i,2!==s,r),null===h)return null;const l=t.origin.distanceTo(r);return l<o||l>a?null:{distance:l,point:r.clone()}}(t,zr,_r,Tr,Ir,h,l,u);if(c){if(i){Br.fromBufferAttribute(i,s),Pr.fromBufferAttribute(i,o),Cr.fromBufferAttribute(i,a),c.uv=new E;const t=pe.getInterpolation(Ir,zr,_r,Tr,Br,Pr,Cr,c.uv);Sr||(c.uv=t)}if(r){Br.fromBufferAttribute(r,s),Pr.fromBufferAttribute(r,o),Cr.fromBufferAttribute(r,a),c.uv1=new E;const t=pe.getInterpolation(Ir,zr,_r,Tr,Br,Pr,Cr,c.uv1);Sr||(c.uv1=t),Ar&&(c.uv2=c.uv1)}if(n){Er.fromBufferAttribute(n,s),kr.fromBufferAttribute(n,o),Nr.fromBufferAttribute(n,a),c.normal=new N;const e=pe.getInterpolation(Ir,zr,_r,Tr,Er,kr,Nr,c.normal);c.normal.dot(t.direction)>0&&c.normal.multiplyScalar(-1),Sr||(c.normal=e)}const e={a:s,b:o,c:a,normal:new N,materialIndex:0};if(pe.getNormal(zr,_r,Tr,e.normal),c.face=e,c.faceIndex=s,Sr){const t=new N;pe.getBarycoord(Ir,zr,_r,Tr,t),c.barycoord=t}}return c}function Fr(t){return t&&t.isMaterial?t.side:t}function Rr(t,e,n,i,r,s,o){const a=3*i;let h=a+0,l=a+1,u=a+2;const{index:c,groups:d}=t;t.index&&(h=c.getX(h),l=c.getX(l),u=c.getX(u));const{position:p,normal:f,uv:y,uv1:m}=t.attributes;if(Array.isArray(e)){const t=3*i;for(let a=0,c=d.length;a<c;a++){const{start:c,count:g,materialIndex:x}=d[a];if(t>=c&&t<c+g){const t=Or(n,p,f,y,m,h,l,u,Fr(e[x]),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=x,!r)return t;r.push(t)}}}}else{const t=Or(n,p,f,y,m,h,l,u,Fr(e),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=0,!r)return t;r.push(t)}}return null}function Vr(t,e,n,i){const r=t.a,s=t.b,o=t.c;let a=e,h=e+1,l=e+2;n&&(a=n.getX(a),h=n.getX(h),l=n.getX(l)),r.x=i.getX(a),r.y=i.getY(a),r.z=i.getZ(a),s.x=i.getX(h),s.y=i.getY(h),s.z=i.getZ(h),o.x=i.getX(l),o.y=i.getY(l),o.z=i.getZ(l)}function Ur(t,e,n,i,r,s,o){const{geometry:a}=n,{index:h}=a,l=a.attributes.position;for(let u=t,c=e+t;u<c;u++){let t;if(t=u,Vr(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function Lr(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const n=t.geometry,i=n.index?n.index.array:null,r=n.attributes.position;let s,o,a,h,l=0;const u=t._roots;for(let d=0,p=u.length;d<p;d++)s=u[d],o=new Uint32Array(s),a=new Uint16Array(s),h=new Float32Array(s),c(0,l),l+=s.byteLength;function c(t,n,s=!1){const l=2*t;if(or(l,a)){const e=o[t+6];let n=1/0,s=1/0,u=1/0,c=-1/0,d=-1/0,p=-1/0;for(let t=3*e,o=3*(e+a[l+14]);t<o;t++){let e=i[t];const o=r.getX(e),a=r.getY(e),h=r.getZ(e);o<n&&(n=o),o>c&&(c=o),a<s&&(s=a),a>d&&(d=a),h<u&&(u=h),h>p&&(p=h)}return(h[t+0]!==n||h[t+1]!==s||h[t+2]!==u||h[t+3]!==c||h[t+4]!==d||h[t+5]!==p)&&(h[t+0]=n,h[t+1]=s,h[t+2]=u,h[t+3]=c,h[t+4]=d,h[t+5]=p,!0)}{const i=lr(t),r=ur(t,o);let a=s,l=!1,u=!1;if(e){if(!a){const t=i/8+n/mi,s=r/8+n/mi;l=e.has(t),u=e.has(s),a=!l&&!u}}else l=!0,u=!0;const d=a||u;let p=!1;(a||l)&&(p=c(i,n,a));let f=!1;d&&(f=c(r,n,a));const y=p||f;if(y)for(let e=0;e<3;e++){const n=i+e,s=r+e,o=h[n],a=h[n+3],l=h[s],u=h[s+3];h[t+e]=o<l?o:l,h[t+e+3]=a>u?a:u}return y}}}function qr(t,e,n,i,r){let s,o,a,h,l,u;const c=1/n.direction.x,d=1/n.direction.y,p=1/n.direction.z,f=n.origin.x,y=n.origin.y,m=n.origin.z;let g=e[t],x=e[t+3],b=e[t+1],w=e[t+3+1],v=e[t+2],M=e[t+3+2];return c>=0?(s=(g-f)*c,o=(x-f)*c):(s=(x-f)*c,o=(g-f)*c),d>=0?(a=(b-y)*d,h=(w-y)*d):(a=(w-y)*d,h=(b-y)*d),!(s>h||a>o)&&((a>s||isNaN(s))&&(s=a),(h<o||isNaN(o))&&(o=h),p>=0?(l=(v-m)*p,u=(M-m)*p):(l=(M-m)*p,u=(v-m)*p),!(s>u||l>o)&&((l>s||s!=s)&&(s=l),(u<o||o!=o)&&(o=u),s<=r&&o>=i))}function Dr(t,e,n,i,r,s,o){const{geometry:a}=n,{index:h}=a,l=a.attributes.position;for(let u=t,c=e+t;u<c;u++){let t;if(t=n.resolveTriangleIndex(u),Vr(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function Xr(t,e,n,i,r,s,o){fr.setBuffer(t._roots[e]),Zr(0,t,n,i,r,s,o),fr.clearBuffer()}function Zr(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=fr,u=2*t;if(or(u,h)){!function(t,e,n,i,r,s,o,a){const{geometry:h,_indirectBuffer:l}=t;for(let u=i,c=i+r;u<c;u++)Rr(h,e,n,u,s,o,a)}(e,n,i,ar(t,l),hr(u,h),r,s,o)}else{const h=lr(t);qr(h,a,i,s,o)&&Zr(h,e,n,i,r,s,o);const u=ur(t,l);qr(u,a,i,s,o)&&Zr(u,e,n,i,r,s,o)}}const jr=["x","y","z"];function Gr(t,e,n,i,r,s){fr.setBuffer(t._roots[e]);const o=Jr(0,t,n,i,r,s);return fr.clearBuffer(),o}function Jr(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=fr;let l=2*t;if(or(l,a)){return function(t,e,n,i,r,s,o){const{geometry:a,_indirectBuffer:h}=t;let l=1/0,u=null;for(let c=i,d=i+r;c<d;c++){let t;t=Rr(a,e,n,c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,ar(t,h),hr(l,a),r,s)}{const a=cr(t,h),l=jr[a],u=i.direction[l]>=0;let c,d;u?(c=lr(t),d=ur(t,h)):(c=ur(t,h),d=lr(t));const p=qr(c,o,i,r,s)?Jr(c,e,n,i,r,s):null;if(p){const t=p.point[l];if(u?t<=o[d+a]:t>=o[d+a+3])return p}const f=qr(d,o,i,r,s)?Jr(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Wr=new K,Yr=new er,$r=new er,Hr=new _t,Qr=new nr,Kr=new nr;function ts(t,e,n,i){fr.setBuffer(t._roots[e]);const r=es(0,t,n,i);return fr.clearBuffer(),r}function es(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=fr;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),Qr.set(n.boundingBox.min,n.boundingBox.max,i),r=Qr);if(!or(h,o)){const o=lr(t),h=ur(t,a);zi(o,s,Wr);if(r.intersectsBox(Wr)&&es(o,e,n,i,r))return!0;zi(h,s,Wr);return!!(r.intersectsBox(Wr)&&es(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=ar(t,a),f=hr(h,o);if(Hr.copy(i).invert(),n.boundsTree){zi(t,s,Kr),Kr.matrix.copy(Hr),Kr.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Kr.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let e=3*p,n=3*(f+p);e<n;e+=3)if(Vr($r,e,l,u),$r.needsUpdate=!0,t.intersectsTriangle($r))return!0;return!1}})}{const t=bi(n);for(let e=3*p,n=3*(f+p);e<n;e+=3){Vr(Yr,e,l,u),Yr.a.applyMatrix4(Hr),Yr.b.applyMatrix4(Hr),Yr.c.applyMatrix4(Hr),Yr.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(Vr($r,e,c,d),$r.needsUpdate=!0,Yr.intersectsTriangle($r))return!0}}}}const ns=new _t,is=new nr,rs=new nr,ss=new N,os=new N,as=new N,hs=new N;function ls(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),is.set(e.boundingBox.min,e.boundingBox.max,n),is.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=sr.getPrimitive(),p=sr.getPrimitive();let f=ss,y=os,m=null,g=null;r&&(m=as,g=hs);let x=1/0,b=null,w=null;return ns.copy(n).invert(),rs.matrix.copy(ns),t.shapecast({boundsTraverseOrder:t=>is.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(rs.min.copy(t.min),rs.max.copy(t.max),rs.needsUpdate=!0),!0),intersectsRange:(t,i)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>rs.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,r)=>{for(let o=e,a=e+r;o<a;o++){Vr(p,3*o,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++){Vr(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,m);if(t<x&&(y.copy(f),g&&g.copy(m),x=t,b=e,w=o),t<s)return!0}}}})}for(let r=0,o=bi(e);r<o;r++){Vr(p,3*r,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=t,n=t+i;e<n;e++){Vr(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,m);if(t<x&&(y.copy(f),g&&g.copy(m),x=t,b=e,w=r),t<s)return!0}}}}),sr.releasePrimitive(d),sr.releasePrimitive(p),x===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=x,i.faceIndex=b,r&&(r.point?r.point.copy(g):r.point=g.clone(),r.point.applyMatrix4(ns),y.applyMatrix4(ns),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}function us(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const n=t.geometry,i=n.index?n.index.array:null,r=n.attributes.position;let s,o,a,h,l=0;const u=t._roots;for(let d=0,p=u.length;d<p;d++)s=u[d],o=new Uint32Array(s),a=new Uint16Array(s),h=new Float32Array(s),c(0,l),l+=s.byteLength;function c(n,s,l=!1){const u=2*n;if(or(u,a)){const e=o[n+6];let s=1/0,l=1/0,c=1/0,d=-1/0,p=-1/0,f=-1/0;for(let n=e,o=e+a[u+14];n<o;n++){const e=3*t.resolveTriangleIndex(n);for(let t=0;t<3;t++){let n=e+t;n=i?i[n]:n;const o=r.getX(n),a=r.getY(n),h=r.getZ(n);o<s&&(s=o),o>d&&(d=o),a<l&&(l=a),a>p&&(p=a),h<c&&(c=h),h>f&&(f=h)}}return(h[n+0]!==s||h[n+1]!==l||h[n+2]!==c||h[n+3]!==d||h[n+4]!==p||h[n+5]!==f)&&(h[n+0]=s,h[n+1]=l,h[n+2]=c,h[n+3]=d,h[n+4]=p,h[n+5]=f,!0)}{const t=lr(n),i=ur(n,o);let r=l,a=!1,u=!1;if(e){if(!r){const n=t/8+s/mi,o=i/8+s/mi;a=e.has(n),u=e.has(o),r=!a&&!u}}else a=!0,u=!0;const d=r||u;let p=!1;(r||a)&&(p=c(t,s,r));let f=!1;d&&(f=c(i,s,r));const y=p||f;if(y)for(let e=0;e<3;e++){const r=t+e,s=i+e,o=h[r],a=h[r+3],l=h[s],u=h[s+3];h[n+e]=o<l?o:l,h[n+e+3]=a>u?a:u}return y}}}function cs(t,e,n,i,r,s,o){fr.setBuffer(t._roots[e]),ds(0,t,n,i,r,s,o),fr.clearBuffer()}function ds(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=fr,u=2*t;if(or(u,h)){!function(t,e,n,i,r,s,o,a){const{geometry:h,_indirectBuffer:l}=t;for(let u=i,c=i+r;u<c;u++)Rr(h,e,n,l?l[u]:u,s,o,a)}(e,n,i,ar(t,l),hr(u,h),r,s,o)}else{const h=lr(t);qr(h,a,i,s,o)&&ds(h,e,n,i,r,s,o);const u=ur(t,l);qr(u,a,i,s,o)&&ds(u,e,n,i,r,s,o)}}const ps=["x","y","z"];function fs(t,e,n,i,r,s){fr.setBuffer(t._roots[e]);const o=ys(0,t,n,i,r,s);return fr.clearBuffer(),o}function ys(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=fr;let l=2*t;if(or(l,a)){return function(t,e,n,i,r,s,o){const{geometry:a,_indirectBuffer:h}=t;let l=1/0,u=null;for(let c=i,d=i+r;c<d;c++){let t;t=Rr(a,e,n,h?h[c]:c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,ar(t,h),hr(l,a),r,s)}{const a=cr(t,h),l=ps[a],u=i.direction[l]>=0;let c,d;u?(c=lr(t),d=ur(t,h)):(c=ur(t,h),d=lr(t));const p=qr(c,o,i,r,s)?ys(c,e,n,i,r,s):null;if(p){const t=p.point[l];if(u?t<=o[d+a]:t>=o[d+a+3])return p}const f=qr(d,o,i,r,s)?ys(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const ms=new K,gs=new er,xs=new er,bs=new _t,ws=new nr,vs=new nr;function Ms(t,e,n,i){fr.setBuffer(t._roots[e]);const r=Ss(0,t,n,i);return fr.clearBuffer(),r}function Ss(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=fr;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),ws.set(n.boundingBox.min,n.boundingBox.max,i),r=ws);if(!or(h,o)){const o=lr(t),h=ur(t,a);zi(o,s,ms);if(r.intersectsBox(ms)&&Ss(o,e,n,i,r))return!0;zi(h,s,ms);return!!(r.intersectsBox(ms)&&Ss(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=ar(t,a),f=hr(h,o);if(bs.copy(i).invert(),n.boundsTree){zi(t,s,vs),vs.matrix.copy(bs),vs.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>vs.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let n=p,i=f+p;n<i;n++)if(Vr(xs,3*e.resolveTriangleIndex(n),l,u),xs.needsUpdate=!0,t.intersectsTriangle(xs))return!0;return!1}})}{const t=bi(n);for(let n=p,i=f+p;n<i;n++){const i=e.resolveTriangleIndex(n);Vr(gs,3*i,l,u),gs.a.applyMatrix4(bs),gs.b.applyMatrix4(bs),gs.c.applyMatrix4(bs),gs.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(Vr(xs,e,c,d),xs.needsUpdate=!0,gs.intersectsTriangle(xs))return!0}}}}const As=new _t,zs=new nr,_s=new nr,Ts=new N,Bs=new N,Ps=new N,Cs=new N;function Es(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),zs.set(e.boundingBox.min,e.boundingBox.max,n),zs.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=sr.getPrimitive(),p=sr.getPrimitive();let f=Ts,y=Bs,m=null,g=null;r&&(m=Ps,g=Cs);let x=1/0,b=null,w=null;return As.copy(n).invert(),_s.matrix.copy(As),t.shapecast({boundsTraverseOrder:t=>zs.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(_s.min.copy(t.min),_s.max.copy(t.max),_s.needsUpdate=!0),!0),intersectsRange:(i,r)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>_s.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,o)=>{for(let v=e,M=e+o;v<M;v++){const e=a.resolveTriangleIndex(v);Vr(p,3*e,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=i,o=i+r;n<o;n++){const e=t.resolveTriangleIndex(n);Vr(d,3*e,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,m);if(i<x&&(y.copy(f),g&&g.copy(m),x=i,b=n,w=v),i<s)return!0}}}})}for(let o=0,a=bi(e);o<a;o++){Vr(p,3*o,c,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let e=i,n=i+r;e<n;e++){const n=t.resolveTriangleIndex(e);Vr(d,3*n,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,m);if(i<x&&(y.copy(f),g&&g.copy(m),x=i,b=e,w=o),i<s)return!0}}}}),sr.releasePrimitive(d),sr.releasePrimitive(p),x===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=x,i.faceIndex=b,r&&(r.point?r.point.copy(g):r.point=g.clone(),r.point.applyMatrix4(As),y.applyMatrix4(As),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}const ks=new fr.constructor,Ns=new fr.constructor,Is=new ir(()=>new K),Os=new K,Fs=new K,Rs=new K,Vs=new K;let Us=!1;function Ls(t,e,n,i,r,s=0,o=0,a=0,h=0,l=null,u=!1){let c,d;u?(c=Ns,d=ks):(c=ks,d=Ns);const p=c.float32Array,f=c.uint32Array,y=c.uint16Array,m=d.float32Array,g=d.uint32Array,x=d.uint16Array,b=2*e,w=or(2*t,y),v=or(b,x);let M=!1;if(v&&w)M=u?r(ar(e,g),hr(2*e,x),ar(t,f),hr(2*t,y),h,o+e/8,a,s+t/8):r(ar(t,f),hr(2*t,y),ar(e,g),hr(2*e,x),a,s+t/8,h,o+e/8);else if(v){const l=Is.getPrimitive();zi(e,m,l),l.applyMatrix4(n);const c=lr(t),d=ur(t,f);zi(c,p,Os),zi(d,p,Fs);const y=l.intersectsBox(Os),g=l.intersectsBox(Fs);M=y&&Ls(e,c,i,n,r,o,s,h,a+1,l,!u)||g&&Ls(e,d,i,n,r,o,s,h,a+1,l,!u),Is.releasePrimitive(l)}else{const c=lr(e),d=ur(e,g);zi(c,m,Rs),zi(d,m,Vs);const y=l.intersectsBox(Rs),x=l.intersectsBox(Vs);if(y&&x)M=Ls(t,c,n,i,r,s,o,a,h+1,l,u)||Ls(t,d,n,i,r,s,o,a,h+1,l,u);else if(y)if(w)M=Ls(t,c,n,i,r,s,o,a,h+1,l,u);else{const e=Is.getPrimitive();e.copy(Rs).applyMatrix4(n);const l=lr(t),d=ur(t,f);zi(l,p,Os),zi(d,p,Fs);const y=e.intersectsBox(Os),m=e.intersectsBox(Fs);M=y&&Ls(c,l,i,n,r,o,s,h,a+1,e,!u)||m&&Ls(c,d,i,n,r,o,s,h,a+1,e,!u),Is.releasePrimitive(e)}else if(x)if(w)M=Ls(t,d,n,i,r,s,o,a,h+1,l,u);else{const e=Is.getPrimitive();e.copy(Vs).applyMatrix4(n);const l=lr(t),c=ur(t,f);zi(l,p,Os),zi(c,p,Fs);const y=e.intersectsBox(Os),m=e.intersectsBox(Fs);M=y&&Ls(d,l,i,n,r,o,s,h,a+1,e,!u)||m&&Ls(d,c,i,n,r,o,s,h,a+1,e,!u),Is.releasePrimitive(e)}}return M}const qs=new nr,Ds=new K,Xs={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Zs{static serialize(t,e={}){e=u({cloneBuffers:!0},e);const n=t.geometry,i=t._roots,r=t._indirectBuffer,s=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(o.roots=i.map(t=>t.slice()),o.index=s?s.array.slice():null,o.indirectBuffer=r?r.slice():null):(o.roots=i,o.index=s?s.array:null,o.indirectBuffer=r),o}static deserialize(t,e,n={}){n=u({setIndex:!0,indirect:Boolean(t.indirectBuffer)},n);const{index:i,roots:r,indirectBuffer:s}=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."),function(t){for(let e=0;e<t.length;e++){const n=t[e],i=new Uint32Array(n),r=new Uint16Array(n);for(let t=0,e=n.byteLength/mi;t<e;t++){const e=8*t;or(2*e,r)||(i[e+6]=i[e+6]/8-t)}}}(r));const o=new Zs(e,c(u({},n),{[xi]:!0}));if(o._roots=r,o._indirectBuffer=s||null,n.setIndex){const n=e.getIndex();if(null===n){const n=new _e(t.index,1,!1);e.setIndex(n)}else n.array!==i&&(n.array.set(i),n.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(t,e={}){if(!t.isBufferGeometry)throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.");if((e=Object.assign(c(u({},Xs),{[xi]:!1}),e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[xi]||(Ji(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new K))),this.resolveTriangleIndex=e.indirect?t=>this._indirectBuffer[t]:t=>t}shiftTriangleOffsets(t){const e=this._indirectBuffer;if(e)for(let n=0,i=e.length;n<i;n++)e[n]+=t;else{const e=this._roots;for(let n=0;n<e.length;n++){const i=e[n],r=new Uint32Array(i),s=new Uint16Array(i),o=i.byteLength/mi;for(let e=0;e<o;e++){const n=8*e;or(2*n,s)&&(r[n+6]+=t)}}}}refit(t=null){return(this.indirect?us:Lr)(this,t)}traverse(t,e=0){const n=this._roots[e],i=new Uint32Array(n),r=new Uint16Array(n);!function e(s,o=0){const a=2*s,h=or(a,r);if(h){const e=i[s+6],l=r[a+14];t(o,h,new Float32Array(n,4*s,6),e,l)}else{const r=lr(s),a=ur(s,i),l=cr(s,i);t(o,h,new Float32Array(n,4*s,6),l)||(e(r,o+1),e(a,o+1))}}(0)}raycast(t,e=0,n=0,i=1/0){const r=this._roots,s=[],o=this.indirect?cs:Xr;for(let a=0,h=r.length;a<h;a++)o(this,a,e,t,s,n,i);return s}raycastFirst(t,e=0,n=0,i=1/0){const r=this._roots;let s=null;const o=this.indirect?fs:Gr;for(let a=0,h=r.length;a<h;a++){const r=o(this,a,e,t,n,i);null!=r&&(null==s||r.distance<s.distance)&&(s=r)}return s}intersectsGeometry(t,e){let n=!1;const i=this._roots,r=this.indirect?Ms:ts;for(let s=0,o=i.length;s<o&&(n=r(this,s,t,e),!n);s++);return n}shapecast(t){const e=sr.getPrimitive(),n=this.indirect?Dr:Ur;let{boundsTraverseOrder:i,intersectsBounds:r,intersectsRange:s,intersectsTriangle:o}=t;if(s&&o){const t=s;s=(i,r,s,a,h)=>!!t(i,r,s,a,h)||n(i,r,this,o,s,a,e)}else s||(s=o?(t,i,r,s)=>n(t,i,this,o,r,s,e):(t,e,n)=>n);let a=!1,h=0;const l=this._roots;for(let u=0,c=l.length;u<c;u++){const t=l[u];if(a=br(this,u,r,s,i,h),a)break;h+=t.byteLength/mi}return sr.releasePrimitive(e),a}bvhcast(t,e,n){let{intersectsRanges:i,intersectsTriangles:r}=n;const s=sr.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);Vr(s,3*e,o,a)}:t=>{Vr(s,3*t,o,a)},l=sr.getPrimitive(),u=t.geometry.index,c=t.geometry.attributes.position,d=t.indirect?e=>{const n=t.resolveTriangleIndex(e);Vr(l,3*n,u,c)}:t=>{Vr(l,3*t,u,c)};if(r){const t=(t,n,i,o,a,u,c,p)=>{for(let f=i,y=i+o;f<y;f++){d(f),l.a.applyMatrix4(e),l.b.applyMatrix4(e),l.c.applyMatrix4(e),l.needsUpdate=!0;for(let e=t,i=t+n;e<i;e++)if(h(e),s.needsUpdate=!0,r(s,l,e,f,a,u,c,p))return!0}return!1};if(i){const e=i;i=function(n,i,r,s,o,a,h,l){return!!e(n,i,r,s,o,a,h,l)||t(n,i,r,s,o,a,h,l)}}else i=t}return function(t,e,n,i){if(Us)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Us=!0;const r=t._roots,s=e._roots;let o,a=0,h=0;const l=(new _t).copy(n).invert();for(let u=0,c=r.length;u<c;u++){ks.setBuffer(r[u]),h=0;const t=Is.getPrimitive();zi(dr(0),ks.float32Array,t),t.applyMatrix4(l);for(let e=0,r=s.length;e<r&&(Ns.setBuffer(s[e]),o=Ls(0,0,n,l,i,a,h,0,0,t),Ns.clearBuffer(),h+=s[e].byteLength/mi,!o);e++);if(Is.releasePrimitive(t),ks.clearBuffer(),a+=r[u].byteLength/mi,o)break}return Us=!1,o}(this,t,e,i)}intersectsBox(t,e){return qs.set(t.min,t.max,e),qs.needsUpdate=!0,this.shapecast({intersectsBounds:t=>qs.intersectsBox(t),intersectsTriangle:t=>qs.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,n={},i={},r=0,s=1/0){return(this.indirect?Es:ls)(this,t,e,n,i,r,s)}closestPointToPoint(t,e={},n=0,i=1/0){return function(t,e,n={},i=0,r=1/0){const s=i*i,o=r*r;let a=1/0,h=null;if(t.shapecast({boundsTraverseOrder:t=>(vr.copy(e).clamp(t.min,t.max),vr.distanceToSquared(e)),intersectsBounds:(t,e,n)=>n<a&&n<o,intersectsTriangle:(t,n)=>{t.closestPointToPoint(e,vr);const i=e.distanceToSquared(vr);return i<a&&(Mr.copy(vr),a=i,h=n),i<s}}),a===1/0)return null;const l=Math.sqrt(a);return n.point?n.point.copy(Mr):n.point=Mr.clone(),n.distance=l,n.faceIndex=h,n}(this,t,e,n,i)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{zi(0,new Float32Array(e),Ds),t.union(Ds)}),t}}const js=1e-6,Gs=Math.pow(10,-Math.log10(js)),Js=5e-7*Gs;function Ws(t){return~~(t*Gs+Js)}function Ys(t){return`${Ws(t.x)},${Ws(t.y)}`}function $s(t){return`${Ws(t.x)},${Ws(t.y)},${Ws(t.z)}`}function Hs(t){return`${Ws(t.x)},${Ws(t.y)},${Ws(t.z)},${Ws(t.w)}`}function Qs(t,e,n){n.direction.subVectors(e,t).normalize();const i=t.dot(n.direction);return n.origin.copy(t).addScaledVector(n.direction,-i),n}function Ks(){return"undefined"!=typeof SharedArrayBuffer}function to(t){if(t.buffer instanceof SharedArrayBuffer)return t;const e=t.constructor,n=t.buffer,i=new SharedArrayBuffer(n.byteLength),r=new Uint8Array(n);return new Uint8Array(i).set(r,0),new e(i)}function eo(t,e){if(!t.index){const n=t.attributes.position.count,i=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(n,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new _e(i,1));for(let t=0;t<n;t++)i[t]=t}}function no(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}const io=new N;function ro(t){return~~(t/3)}function so(t){return t%3}function oo(t,e){return t.start-e.start}function ao(t,e){return io.subVectors(e,t.origin).dot(t.direction)}const ho=1e-5,lo=1e-4;class uo{constructor(){this._rays=[]}addRay(t){this._rays.push(t)}findClosestRay(t){const e=this._rays,n=t.clone();n.direction.multiplyScalar(-1);let i=1/0,r=null;for(let a=0,h=e.length;a<h;a++){const h=e[a];if(s(h,t)&&s(h,n))continue;const l=o(h,t),u=o(h,n),c=Math.min(l,u);c<i&&(i=c,r=h)}return r;function s(t,e){const n=t.origin.distanceTo(e.origin)>ho;return t.direction.angleTo(e.direction)>lo||n}function o(t,e){const n=t.origin.distanceTo(e.origin),i=t.direction.angleTo(e.direction);return n/ho+i/lo}}}const co=new N,po=new N,fo=new zt;function yo(t,e,n){const i=t.attributes,r=t.index,s=i.position,o=new Map,a=new Map,h=Array.from(e),l=new uo;for(let u=0,c=h.length;u<c;u++){const t=h[u],e=ro(t),n=so(t);let i,o=3*e+n,c=3*e+(n+1)%3;r&&(o=r.getX(o),c=r.getX(c)),co.fromBufferAttribute(s,o),po.fromBufferAttribute(s,c),Qs(co,po,fo);let d=l.findClosestRay(fo);null===d&&(d=fo.clone(),l.addRay(d)),a.has(d)||a.set(d,{forward:[],reverse:[],ray:d}),i=a.get(d);let p=ao(d,co),f=ao(d,po);p>f&&([p,f]=[f,p]),fo.direction.dot(d.direction)<0?i.reverse.push({start:p,end:f,index:t}):i.forward.push({start:p,end:f,index:t})}return a.forEach(({forward:t,reverse:e},i)=>{!function(t,e,n,i=1e-8){t.sort(oo),e.sort(oo);for(let a=0;a<t.length;a++){const i=t[a];for(let r=0;r<e.length;r++){const h=e[r];if(h.start>i.end);else{if(i.end<h.start||h.end<i.start)continue;if(i.start<=h.start&&i.end>=h.end)s(h.end,i.end)||t.splice(a+1,0,{start:h.end,end:i.end,index:i.index}),i.end=h.start,h.start=0,h.end=0;else if(i.start>=h.start&&i.end<=h.end)s(i.end,h.end)||e.splice(r+1,0,{start:i.end,end:h.end,index:h.index}),h.end=i.start,i.start=0,i.end=0;else if(i.start<=h.start&&i.end<=h.end){const t=i.end;i.end=h.start,h.start=t}else{if(!(i.start>=h.start&&i.end>=h.end))throw new Error;{const t=h.end;h.end=i.start,i.start=t}}}if(n.has(i.index)||n.set(i.index,[]),n.has(h.index)||n.set(h.index,[]),n.get(i.index).push(h.index),n.get(h.index).push(i.index),o(h)&&(e.splice(r,1),r--),o(i)){t.splice(a,1),a--;break}}}function r(t){for(let e=0;e<t.length;e++)o(t[e])&&(t.splice(e,1),e--)}function s(t,e){return Math.abs(e-t)<i}function o(t){return Math.abs(t.end-t.start)<i}r(t),r(e)}(t,e,o,n),0===t.length&&0===e.length&&a.delete(i)}),{disjointConnectivityMap:o,fragmentMap:a}}const mo=new E,go=new N,xo=new Q,bo=["","",""];class wo{constructor(t=null){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,t&&this.updateFrom(t)}getSiblingTriangleIndex(t,e){const n=this.data[3*t+e];return-1===n?-1:~~(n/3)}getSiblingEdgeIndex(t,e){const n=this.data[3*t+e];return-1===n?-1:n%3}getDisjointSiblingTriangleIndices(t,e){const n=3*t+e,i=this.disjointConnections.get(n);return i?i.map(t=>~~(t/3)):[]}getDisjointSiblingEdgeIndices(t,e){const n=3*t+e,i=this.disjointConnections.get(n);return i?i.map(t=>t%3):[]}isFullyConnected(){return 0===this.unmatchedEdges}updateFrom(t){const{useAllAttributes:e,useDrawRange:n,matchDisjointEdges:i,degenerateEpsilon:r}=this,s=e?function(t){let e="";for(let n=0,i=h.length;n<i;n++){const i=a[h[n]];let r;switch(i.itemSize){case 1:r=Ws(i.getX(t));break;case 2:r=Ys(mo.fromBufferAttribute(i,t));break;case 3:r=$s(go.fromBufferAttribute(i,t));break;case 4:r=Hs(xo.fromBufferAttribute(i,t))}""!==e&&(e+="|"),e+=r}return e}:function(t){return go.fromBufferAttribute(u,t),$s(go)},o=new Map,{attributes:a}=t,h=e?Object.keys(a):null,l=t.index,u=a.position;let c=no(t);const d=c;let p=0;n&&(p=t.drawRange.start,t.drawRange.count!==1/0&&(c=~~(t.drawRange.count/3)));let f=this.data;(!f||f.length<3*d)&&(f=new Int32Array(3*d)),f.fill(-1);let y=0,m=new Set;for(let g=p,x=3*c+p;g<x;g+=3){const t=g;for(let e=0;e<3;e++){let n=t+e;l&&(n=l.getX(n)),bo[e]=s(n)}for(let e=0;e<3;e++){const n=(e+1)%3,i=bo[e],r=bo[n],s=`${r}_${i}`;if(o.has(s)){const n=t+e,i=o.get(s);f[n]=i,f[i]=n,o.delete(s),y+=2,m.delete(i)}else{const n=`${i}_${r}`,s=t+e;o.set(n,s),m.add(s)}}}if(i){const{fragmentMap:e,disjointConnectivityMap:n}=yo(t,m,r);m.clear(),e.forEach(({forward:t,reverse:e})=>{t.forEach(({index:t})=>m.add(t)),e.forEach(({index:t})=>m.add(t))}),this.unmatchedDisjointEdges=e,this.disjointConnections=n,y=3*c-m.size}this.matchedEdges=y,this.unmatchedEdges=m.size,this.data=f}}class vo extends Ye{constructor(...t){super(...t),this.isBrush=!0,this._previousMatrix=new _t,this._previousMatrix.elements.fill(0)}markUpdated(){this._previousMatrix.copy(this.matrix)}isDirty(){const{matrix:t,_previousMatrix:e}=this,n=t.elements,i=e.elements;for(let r=0;r<16;r++)if(n[r]!==i[r])return!0;return!1}prepareGeometry(){const t=this.geometry,e=t.attributes,n=Ks();if(n)for(const i in e){const t=e[i];if(t.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");t.array=to(t.array)}if(t.boundsTree||(eo(t,{useSharedArrayBuffer:n}),t.boundsTree=new Zs(t,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),t.halfEdges||(t.halfEdges=new wo(t)),!t.groupIndices){const e=no(t),n=new Uint16Array(e),i=t.groups;for(let t=0,r=i.length;t<r;t++){const{start:e,count:r}=i[t];for(let i=e/3,s=(e+r)/3;i<s;i++)n[i]=t}t.groupIndices=n}}disposeCacheData(){const{geometry:t}=this;t.halfEdges=null,t.boundsTree=null,t.groupIndices=null}}const Mo=new N,So=new N,Ao=new N;function zo(t,e=1e-14){Mo.subVectors(t.b,t.a),So.subVectors(t.c,t.a),Ao.subVectors(t.b,t.c);const n=Mo.angleTo(So),i=Mo.angleTo(Ao),r=Math.PI-n-i;return Math.abs(n)<e||Math.abs(i)<e||Math.abs(r)<e||t.a.distanceToSquared(t.b)<e||t.a.distanceToSquared(t.c)<e||t.b.distanceToSquared(t.c)<e}const _o=1e-10,To=1e-10,Bo=new li,Po=new li,Co=new N,Eo=new N,ko=new N,No=new tn,Io=new er;class Oo{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new pe),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class Fo{constructor(){this.trianglePool=new Oo,this.triangles=[],this.normal=new N,this.coplanarTriangleUsed=!1}initialize(t){this.reset();const{triangles:e,trianglePool:n,normal:i}=this;if(Array.isArray(t))for(let r=0,s=t.length;r<s;r++){const s=t[r];if(0===r)s.getNormal(i);else if(Math.abs(1-s.getNormal(Co).dot(i))>_o)throw new Error("Triangle Splitter: Cannot initialize with triangles that have different normals.");const o=n.getTriangle();o.copy(s),e.push(o)}else{t.getNormal(i);const r=n.getTriangle();r.copy(t),e.push(r)}}splitByTriangle(t){const{normal:e,triangles:n}=this;if(t.getNormal(Eo).normalize(),Math.abs(1-Math.abs(Eo.dot(e)))<1e-10){this.coplanarTriangleUsed=!0;for(let t=0,i=n.length;t<i;t++){n[t].coplanarCount=0}const e=[t.a,t.b,t.c];for(let n=0;n<3;n++){const i=(n+1)%3,r=e[n],s=e[i];Co.subVectors(s,r).normalize(),ko.crossVectors(Eo,Co),No.setFromNormalAndCoplanarPoint(ko,r),this.splitByPlane(No,t)}}else t.getPlane(No),this.splitByPlane(No,t)}splitByPlane(t,e){const{triangles:n,trianglePool:i}=this;Io.copy(e),Io.needsUpdate=!0;for(let r=0,s=n.length;r<s;r++){const e=n[r];if(!Io.intersectsTriangle(e,Bo,!0))continue;const{a:o,b:a,c:h}=e;let l=0,u=-1,c=!1,d=[],p=[];const f=[o,a,h];for(let n=0;n<3;n++){const e=(n+1)%3;Bo.start.copy(f[n]),Bo.end.copy(f[e]);const i=t.distanceToPoint(Bo.start),r=t.distanceToPoint(Bo.end);if(Math.abs(i)<To&&Math.abs(r)<To){c=!0;break}if(i>0?d.push(n):p.push(n),Math.abs(i)<To)continue;let s=!!t.intersectLine(Bo,Co);!s&&Math.abs(r)<To&&(Co.copy(Bo.end),s=!0),!s||Co.distanceTo(Bo.start)<_o||(Co.distanceTo(Bo.end)<_o&&(u=n),0===l?Po.start.copy(Co):Po.end.copy(Co),l++)}if(!c&&2===l&&Po.distance()>To)if(-1!==u){u=(u+1)%3;let t=0;t===u&&(t=(t+1)%3);let o=t+1;o===u&&(o=(o+1)%3);const a=i.getTriangle();a.a.copy(f[o]),a.b.copy(Po.end),a.c.copy(Po.start),zo(a)||n.push(a),e.a.copy(f[t]),e.b.copy(Po.start),e.c.copy(Po.end),zo(e)&&(n.splice(r,1),r--,s--)}else{const t=d.length>=2?p[0]:d[0];if(0===t){let t=Po.start;Po.start=Po.end,Po.end=t}const o=(t+1)%3,a=(t+2)%3,h=i.getTriangle(),l=i.getTriangle();f[o].distanceToSquared(Po.start)<f[a].distanceToSquared(Po.end)?(h.a.copy(f[o]),h.b.copy(Po.start),h.c.copy(Po.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Po.start)):(h.a.copy(f[a]),h.b.copy(Po.start),h.c.copy(Po.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Po.end)),e.a.copy(f[t]),e.b.copy(Po.end),e.c.copy(Po.start),zo(h)||n.push(h),zo(l)||n.push(l),zo(e)&&(n.splice(r,1),r--,s--)}else 3===l&&console.warn("TriangleClipper: Coplanar clip not handled")}}reset(){this.triangles.length=0,this.trianglePool.clear(),this.coplanarTriangleUsed=!1}}class Ro{constructor(t,e=500){this.expansionFactor=1.5,this.type=t,this.length=0,this.array=null,this.setSize(e)}setType(t){if(0!==this.length)throw new Error("TypeBackedArray: Cannot change the type while there is used data in the buffer.");const e=this.array.buffer;this.array=new t(e),this.type=t}setSize(t){if(this.array&&t===this.array.length)return;const e=this.type,n=new e(new(Ks()?SharedArrayBuffer:ArrayBuffer)(4+(i=~~(i=t*e.BYTES_PER_ELEMENT))-i%4));var i;this.array&&n.set(this.array,0),this.array=n}expand(){const{array:t,expansionFactor:e}=this;this.setSize(t.length*e)}push(...t){let{array:e,length:n}=this;n+t.length>e.length&&(this.expand(),e=this.array);for(let i=0,r=t.length;i<r;i++)e[n+i]=t[i];this.length+=t.length}clear(){this.length=0}}class Vo{constructor(){this.groupAttributes=[{}],this.groupCount=0}getType(t){return this.groupAttributes[0][t].type}getItemSize(t){return this.groupAttributes[0][t].itemSize}getNormalized(t){return this.groupAttributes[0][t].normalized}getCount(t){if(this.groupCount<=t)return 0;const e=this.getGroupAttrArray("position",t);return e.length/e.itemSize}getTotalLength(t){const{groupCount:e,groupAttributes:n}=this;let i=0;for(let r=0;r<e;r++){i+=n[r][t].length}return i}getGroupAttrSet(t=0){const{groupAttributes:e}=this;if(e[t])return this.groupCount=Math.max(this.groupCount,t+1),e[t];const n=e[0];for(this.groupCount=Math.max(this.groupCount,t+1);t>=e.length;){const t={};e.push(t);for(const e in n){const i=n[e],r=new Ro(i.type);r.itemSize=i.itemSize,r.normalized=i.normalized,t[e]=r}}return e[t]}getGroupAttrArray(t,e=0){const{groupAttributes:n}=this;if(!n[0][t])throw new Error(`TypedAttributeData: Attribute with "${t}" has not been initialized`);return this.getGroupAttrSet(e)[t]}initializeArray(t,e,n,i){const{groupAttributes:r}=this,s=r[0][t];if(s){if(s.type!==e)for(let o=0,a=r.length;o<a;o++){const s=r[o][t];s.setType(e),s.itemSize=n,s.normalized=i}}else for(let o=0,a=r.length;o<a;o++){const s=new Ro(e);s.itemSize=n,s.normalized=i,r[o][t]=s}}clear(){this.groupCount=0;const{groupAttributes:t}=this;t.forEach(t=>{for(const e in t)t[e].clear()})}delete(t){this.groupAttributes.forEach(e=>{delete e[t]})}reset(){this.groupAttributes=[],this.groupCount=0}}class Uo{constructor(){this.intersectionSet={},this.ids=[]}add(t,e){const{intersectionSet:n,ids:i}=this;n[t]||(n[t]=[],i.push(t)),n[t].push(e)}}const Lo=new zt,qo=new _t,Do=new pe,Xo=new N,Zo=new Q,jo=new Q,Go=new Q,Jo=new Q,Wo=new Q,Yo=new Q,$o=new li,Ho=new N,Qo=1e-8,Ko=-1;let ta=null;function ea(t){ta=t}function na(t,e){t.getMidpoint(Lo.origin),t.getNormal(Lo.direction);const n=e.raycastFirst(Lo,2);return Boolean(n&&Lo.direction.dot(n.face.normal)>0)?Ko:1}function ia(t,e){function n(){return Math.random()-.5}t.getNormal(Ho),Lo.direction.copy(Ho),t.getMidpoint(Lo.origin);let i=0,r=1/0;for(let s=0;s<3;s++){Lo.direction.x+=n()*Qo,Lo.direction.y+=n()*Qo,Lo.direction.z+=n()*Qo,Lo.direction.multiplyScalar(-1);const t=e.raycastFirst(Lo,2);if(Boolean(t&&Lo.direction.dot(t.face.normal)>0)&&i++,null!==t&&(r=Math.min(r,t.distance)),r<=1e-15)return t.face.normal.dot(Ho)>0?2:-2;if(i/3>.5||(s-i+1)/3>.5)break}return i/3>.5?Ko:1}function ra(t,e,n,i,r,s,o=!1){const a=n.attributes,h=n.index,l=3*t,u=h.getX(l+0),c=h.getX(l+1),d=h.getX(l+2);for(const p in s){const t=a[p],n=s[p];if(!(p in a))throw new Error(`CSG Operations: Attribute ${p} not available on geometry.`);const h=t.itemSize;"position"===p?(Do.a.fromBufferAttribute(t,u).applyMatrix4(i),Do.b.fromBufferAttribute(t,c).applyMatrix4(i),Do.c.fromBufferAttribute(t,d).applyMatrix4(i),aa(Do.a,Do.b,Do.c,e,3,n,o)):"normal"===p?(Do.a.fromBufferAttribute(t,u).applyNormalMatrix(r),Do.b.fromBufferAttribute(t,c).applyNormalMatrix(r),Do.c.fromBufferAttribute(t,d).applyNormalMatrix(r),o&&(Do.a.multiplyScalar(-1),Do.b.multiplyScalar(-1),Do.c.multiplyScalar(-1)),aa(Do.a,Do.b,Do.c,e,3,n,o,!0)):(Zo.fromBufferAttribute(t,u),jo.fromBufferAttribute(t,c),Go.fromBufferAttribute(t,d),aa(Zo,jo,Go,e,h,n,o))}}function sa(t,e,n,i,r,s,o,a=!1){ha(t,i,r,s,o,a),ha(a?n:e,i,r,s,o,a),ha(a?e:n,i,r,s,o,a)}function oa(t,e,n=!1){switch(t){case 0:if(1===e||2===e&&!n)return 1;break;case 1:if(n){if(e===Ko)return 0}else if(1===e||-2===e)return 1;break;case 2:if(n){if(1===e||-2===e)return 1}else if(e===Ko)return 0;break;case 4:if(e===Ko)return 0;if(1===e)return 1;break;case 3:if(e===Ko||2===e&&!n)return 1;break;case 5:if(!n&&(1===e||-2===e))return 1;break;case 6:if(!n&&(e===Ko||2===e))return 1;break;default:throw new Error(`Unrecognized CSG operation enum "${t}".`)}return 2}function aa(t,e,n,i,r,s,o=!1,a=!1){const h=t=>{s.push(t.x),r>1&&s.push(t.y),r>2&&s.push(t.z),r>3&&s.push(t.w)};Jo.set(0,0,0,0).addScaledVector(t,i.a.x).addScaledVector(e,i.a.y).addScaledVector(n,i.a.z),Wo.set(0,0,0,0).addScaledVector(t,i.b.x).addScaledVector(e,i.b.y).addScaledVector(n,i.b.z),Yo.set(0,0,0,0).addScaledVector(t,i.c.x).addScaledVector(e,i.c.y).addScaledVector(n,i.c.z),a&&(Jo.normalize(),Wo.normalize(),Yo.normalize()),h(Jo),o?(h(Yo),h(Wo)):(h(Wo),h(Yo))}function ha(t,e,n,i,r,s=!1){for(const o in r){const a=e[o],h=r[o];if(!(o in e))throw new Error(`CSG Operations: Attribute ${o} no available on geometry.`);const l=a.itemSize;"position"===o?(Xo.fromBufferAttribute(a,t).applyMatrix4(n),h.push(Xo.x,Xo.y,Xo.z)):"normal"===o?(Xo.fromBufferAttribute(a,t).applyNormalMatrix(i),s&&Xo.multiplyScalar(-1),h.push(Xo.x,Xo.y,Xo.z)):(h.push(a.getX(t)),l>1&&h.push(a.getY(t)),l>2&&h.push(a.getZ(t)),l>3&&h.push(a.getW(t)))}}class la{constructor(t){this.triangle=(new pe).copy(t),this.intersects={}}addTriangle(t,e){this.intersects[t]=(new pe).copy(e)}getIntersectArray(){const t=[],{intersects:e}=this;for(const n in e)t.push(e[n]);return t}}class ua{constructor(){this.data={}}addTriangleIntersection(t,e,n,i){const{data:r}=this;r[t]||(r[t]=new la(e)),r[t].addTriangle(n,i)}getTrianglesAsArray(t=null){const{data:e}=this,n=[];if(null!==t)t in e&&n.push(e[t].triangle);else for(const i in e)n.push(e[i].triangle);return n}getTriangleIndices(){return Object.keys(this.data).map(t=>parseInt(t))}getIntersectionIndices(t){const{data:e}=this;return e[t]?Object.keys(e[t].intersects).map(t=>parseInt(t)):[]}getIntersectionsAsArray(t=null,e=null){const{data:n}=this,i=new Set,r=[],s=t=>{if(n[t])if(null!==e)n[t].intersects[e]&&r.push(n[t].intersects[e]);else{const e=n[t].intersects;for(const t in e)i.has(t)||(i.add(t),r.push(e[t]))}};if(null!==t)s(t);else for(const o in n)s(o);return r}reset(){this.data={}}}class ca{constructor(){this.enabled=!1,this.triangleIntersectsA=new ua,this.triangleIntersectsB=new ua,this.intersectionEdges=[]}addIntersectingTriangles(t,e,n,i){const{triangleIntersectsA:r,triangleIntersectsB:s}=this;r.addTriangleIntersection(t,e,n,i),s.addTriangleIntersection(n,i,t,e)}addEdge(t){this.intersectionEdges.push(t.clone())}reset(){this.triangleIntersectsA.reset(),this.triangleIntersectsB.reset(),this.intersectionEdges=[]}init(){this.enabled&&(this.reset(),ea(this))}complete(){this.enabled&&ea(null)}}const da=new _t,pa=new F,fa=new pe,ya=new pe,ma=new pe,ga=new pe,xa=[],ba=[];function wa(t){for(const e of t)return e}function va(t,e,n,i,r,s={}){const{useGroups:o=!0}=s,{aIntersections:a,bIntersections:h}=function(t,e){const n=new Uo,i=new Uo;return qo.copy(t.matrixWorld).invert().multiply(e.matrixWorld),t.geometry.boundsTree.bvhcast(e.geometry.boundsTree,qo,{intersectsTriangles(r,s,o,a){if(!zo(r)&&!zo(s)){let h=r.intersectsTriangle(s,$o,!0);if(!h){const t=r.plane,e=s.plane,n=t.normal,i=e.normal;1===n.dot(i)&&Math.abs(t.constant-e.constant)<1e-14&&(h=!0)}if(h){let h=t.geometry.boundsTree.resolveTriangleIndex(o),l=e.geometry.boundsTree.resolveTriangleIndex(a);n.add(h,l),i.add(l,h),ta&&(ta.addEdge($o),ta.addIntersectingTriangles(o,r,a,s))}}return!1}}),{aIntersections:n,bIntersections:i}}(t,e);let l;l=o?0:-1,Ma(t,e,a,n,!1,i,r,l),Sa(t,e,a,n,!1,r,l);return-1!==n.findIndex(t=>6!==t&&5!==t)&&(l=o?t.geometry.groups.length||1:-1,Ma(e,t,h,n,!0,i,r,l),Sa(e,t,h,n,!0,r,l)),xa.length=0,ba.length=0,{groups:[],materials:null}}function Ma(t,e,n,i,r,s,o,a=0){const h=t.matrixWorld.determinant()<0;da.copy(e.matrixWorld).invert().multiply(t.matrixWorld),pa.getNormalMatrix(t.matrixWorld).multiplyScalar(h?-1:1);const l=t.geometry.groupIndices,u=t.geometry.index,c=t.geometry.attributes.position,d=e.geometry.boundsTree,p=e.geometry.index,f=e.geometry.attributes.position,y=n.ids,m=n.intersectionSet;for(let g=0,x=y.length;g<x;g++){const e=y[g],n=-1===a?0:l[e]+a,x=3*e,b=u.getX(x+0),w=u.getX(x+1),v=u.getX(x+2);fa.a.fromBufferAttribute(c,b).applyMatrix4(da),fa.b.fromBufferAttribute(c,w).applyMatrix4(da),fa.c.fromBufferAttribute(c,v).applyMatrix4(da),s.reset(),s.initialize(fa);const M=m[e];for(let t=0,i=M.length;t<i;t++){const e=3*M[t],n=p.getX(e+0),i=p.getX(e+1),r=p.getX(e+2);ya.a.fromBufferAttribute(f,n),ya.b.fromBufferAttribute(f,i),ya.c.fromBufferAttribute(f,r),s.splitByTriangle(ya)}const S=s.triangles;for(let a=0,l=S.length;a<l;a++){const l=S[a],u=s.coplanarTriangleUsed?ia(l,d):na(l,d);xa.length=0,ba.length=0;for(let t=0,e=i.length;t<e;t++){const e=oa(i[t],u,r);2!==e&&(ba.push(e),xa.push(o[t].getGroupAttrSet(n)))}if(0!==xa.length){fa.getBarycoord(l.a,ga.a),fa.getBarycoord(l.b,ga.b),fa.getBarycoord(l.c,ga.c);for(let n=0,i=xa.length;n<i;n++){const i=xa[n],r=0===ba[n];ra(e,ga,t.geometry,t.matrixWorld,pa,i,h!==r)}}}}return y.length}function Sa(t,e,n,i,r,s,o=0){const a=t.matrixWorld.determinant()<0;da.copy(e.matrixWorld).invert().multiply(t.matrixWorld),pa.getNormalMatrix(t.matrixWorld).multiplyScalar(a?-1:1);const h=e.geometry.boundsTree,l=t.geometry.groupIndices,u=t.geometry.index,c=t.geometry.attributes,d=c.position,p=[],f=t.geometry.halfEdges,y=new Set;for(let m=0,g=no(t.geometry);m<g;m++)m in n.intersectionSet||y.add(m);for(;y.size>0;){const e=wa(y);y.delete(e),p.push(e);const n=3*e,m=u.getX(n+0),g=u.getX(n+1),x=u.getX(n+2);ma.a.fromBufferAttribute(d,m).applyMatrix4(da),ma.b.fromBufferAttribute(d,g).applyMatrix4(da),ma.c.fromBufferAttribute(d,x).applyMatrix4(da);const b=na(ma,h);ba.length=0,xa.length=0;for(let t=0,o=i.length;t<o;t++){const e=oa(i[t],b,r);2!==e&&(ba.push(e),xa.push(s[t]))}for(;p.length>0;){const e=p.pop();for(let t=0;t<3;t++){const n=f.getSiblingTriangleIndex(e,t);-1!==n&&y.has(n)&&(p.push(n),y.delete(n))}if(0!==xa.length){const n=3*e,i=u.getX(n+0),r=u.getX(n+1),s=u.getX(n+2),h=-1===o?0:l[e]+o;if(ma.a.fromBufferAttribute(d,i),ma.b.fromBufferAttribute(d,r),ma.c.fromBufferAttribute(d,s),!zo(ma))for(let e=0,o=xa.length;e<o;e++){const n=ba[e],o=xa[e].getGroupAttrSet(h),l=0===n;sa(i,r,s,c,t.matrixWorld,pa,o,l!==a)}}}}}function Aa(t,e){let n=e;return Array.isArray(e)||(n=[],t.forEach(t=>{n[t.materialIndex]=e})),n}class za{constructor(){this.triangleSplitter=new Fo,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new ca}getGroupRanges(t){return this.useGroups&&0!==t.groups.length?t.groups.map(t=>u({},t)):[{start:0,count:1/0,materialIndex:0}]}evaluate(t,e,n,i=new vo){let r=!0;if(Array.isArray(n)||(n=[n]),Array.isArray(i)||(i=[i],r=!1),i.length!==n.length)throw new Error("Evaluator: operations and target array passed as different sizes.");t.prepareGeometry(),e.prepareGeometry();const{triangleSplitter:s,attributeData:o,attributes:a,useGroups:h,consolidateGroups:l,debug:d}=this;for(;o.length<i.length;)o.push(new Vo);i.forEach((e,n)=>{!function(t,e,n,i){n.clear();const r=t.attributes;for(let s=0,o=i.length;s<o;s++){const t=i[s],e=r[t];n.initializeArray(t,e.array.constructor,e.itemSize,e.normalized)}for(const s in n.attributes)i.includes(s)||n.delete(s);for(const s in e.attributes)i.includes(s)||(e.deleteAttribute(s),e.dispose())}(t.geometry,e.geometry,o[n],a)}),d.init(),va(t,e,n,s,o,{useGroups:h}),d.complete();const p=this.getGroupRanges(t.geometry),f=Aa(p,t.material),y=this.getGroupRanges(e.geometry),m=Aa(y,e.material);y.forEach(t=>t.materialIndex+=f.length);let g=[...p,...y].map((t,e)=>c(u({},t),{index:e}));if(h){const t=[...f,...m];l&&(g=g.map(e=>{const n=t[e.materialIndex];return e.materialIndex=t.indexOf(n),e}).sort((t,e)=>t.materialIndex-e.materialIndex));const e=[];for(let n=0,i=t.length;n<i;n++){let i=!1;for(let t=0,r=g.length;t<r;t++){const r=g[t];r.materialIndex===n&&(i=!0,r.materialIndex=e.length)}i&&e.push(t[n])}i.forEach(t=>{t.material=e})}else g=[{start:0,count:1/0,index:0,materialIndex:0}],i.forEach(t=>{t.material=f[0]});return i.forEach((t,e)=>{const n=t.geometry;!function(t,e,n){let i=!1,r=-1;const s=t.attributes,o=e.groupAttributes[0];for(const h in o){const o=e.getTotalLength(h),a=e.getType(h),l=e.getItemSize(h),u=e.getNormalized(h);let c=s[h];(!c||c.array.length<o)&&(c=new _e(new a(o),l,u),t.setAttribute(h,c),i=!0);let d=0;for(let t=0,i=Math.min(n.length,e.groupCount);t<i;t++){const i=n[t].index,{array:r,type:s,length:o}=e.groupAttributes[i][h],a=new s(r.buffer,0,o);c.array.set(a,d),d+=a.length}c.needsUpdate=!0,r=o/c.itemSize}if(t.index){const e=t.index.array;if(e.length<r)t.index=null,i=!0;else for(let t=0,n=e.length;t<n;t++)e[t]=t}let a=0;t.clearGroups();for(let h=0,l=Math.min(n.length,e.groupCount);h<l;h++){const{index:i,materialIndex:r}=n[h],s=e.getCount(i);0!==s&&(t.addGroup(a,s,r),a+=s)}t.setDrawRange(0,r),t.boundsTree=null,i&&t.dispose()}(n,o[e],g),l&&function(t){for(let e=0;e<t.length-1;e++){const n=t[e],i=t[e+1];if(n.materialIndex===i.materialIndex){const r=n.start,s=i.start+i.count;i.start=r,i.count=s-r,t.splice(e,1),e--}}}(n.groups)}),r?i:i[0]}evaluateHierarchy(t,e=new vo){t.updateMatrixWorld(!0);const n=(t,e)=>{const i=t.children;for(let r=0,s=i.length;r<s;r++){const t=i[r];t.isOperationGroup?n(t,e):e(t)}},i=t=>{const e=t.children;let r=!1;for(let n=0,o=e.length;n<o;n++){const t=e[n];r=i(t)||r}const s=t.isDirty();if(s&&t.markUpdated(),r&&!t.isOperationGroup){let e;return n(t,n=>{e=e?this.evaluate(e,n,n.operation):this.evaluate(t,n,n.operation)}),t._cachedGeometry=e.geometry,t._cachedMaterials=e.material,!0}return r||s};return i(t),e.geometry=t._cachedGeometry,e.material=t._cachedMaterials,e}reset(){this.triangleSplitter.reset()}}function _a(t){let e,n,i,r=-1,s=0;for(let l=0;l<t.length;++l){const o=t[l];if(void 0===e&&(e=o.array.constructor),e!==o.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(void 0===n&&(n=o.itemSize),n!==o.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(void 0===i&&(i=o.normalized),i!==o.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(-1===r&&(r=o.gpuType),r!==o.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;s+=o.count*n}const o=new e(s),a=new _e(o,n,i);let h=0;for(let l=0;l<t.length;++l){const e=t[l];if(e.isInterleavedBufferAttribute){const t=h/n;for(let i=0,r=e.count;i<r;i++)for(let s=0;s<n;s++){const n=e.getComponent(i,s);a.setComponent(i+t,s,n)}}else o.set(e.array,h);h+=e.count*n}return void 0!==r&&(a.gpuType=r),a}function Ta(t,e=0){const n=null!==t[0].index,i=new Set(Object.keys(t[0].attributes)),r=new Set(Object.keys(t[0].morphAttributes)),s={},o={},a=t[0].morphTargetsRelative,h=new Re;let l=0;for(let u=0;u<t.length;++u){const c=t[u];let d=0;if(n!==(null!==c.index))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(const t in c.attributes){if(!i.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+\'. All geometries must have compatible attributes; make sure "\'+t+\'" attribute exists among all geometries, or in none of them.\'),null;void 0===s[t]&&(s[t]=[]),s[t].push(c.attributes[t]),d++}if(d!==i.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(a!==c.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const t in c.morphAttributes){if(!r.has(t))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". .morphAttributes must be consistent throughout all geometries."),null;void 0===o[t]&&(o[t]=[]),o[t].push(c.morphAttributes[t])}if(e){let t;if(n)t=c.index.count;else{if(void 0===c.attributes.position)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+u+". The geometry must have either an index or a position attribute"),null;t=c.attributes.position.count}if(1===e)h.addGroup(l,t,u);else if(2===e&&c.groups.length>0)for(let e of c.groups){let n=e.materialIndex;h.addGroup(l+e.start,Math.min(e.count,t),n)}l+=t}}if(n){let e=0;const n=[];for(let i=0;i<t.length;++i){const r=t[i].index;for(let t=0;t<r.count;++t)n.push(r.getX(t)+e);e+=t[i].attributes.position.count}h.setIndex(n)}for(const u in s){const t=_a(s[u]);if(!t)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" attribute."),null;h.setAttribute(u,t)}for(const u in o){const t=o[u][0].length;if(0===t)break;h.morphAttributes=h.morphAttributes||{},h.morphAttributes[u]=[];for(let e=0;e<t;++e){const t=[];for(let i=0;i<o[u].length;++i)t.push(o[u][i][e]);const n=_a(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;h.morphAttributes[u].push(n)}}return 2===e?function(t){if(0===t.groups.length)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),t;let e=t.groups;if(e=e.sort((t,e)=>t.materialIndex!==e.materialIndex?t.materialIndex-e.materialIndex:t.start-e.start),null===t.getIndex()){const e=t.getAttribute("position"),n=[];for(let t=0;t<e.count;t+=3)n.push(t,t+1,t+2);t.setIndex(n)}const n=t.getIndex(),i=[];for(let o=0;o<e.length;o++){const t=e[o],r=t.start,s=r+t.count;for(let e=r;e<s;e++)i.push(n.getX(e))}t.dispose(),t.setIndex(i);let r=0;for(let o=0;o<e.length;o++){const t=e[o];t.start=r,r+=t.count}let s=e[0];t.groups=[s];for(let o=1;o<e.length;o++){const n=e[o];s.materialIndex===n.materialIndex?s.count+=n.count:(s=n,t.groups.push(s))}return t}(h):h}class Ba extends pi{constructor(t,e){super(t,e);const n=new vo(new pi(t,c(u({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new K).setFromObject(n),r=new N;i.getSize(r);const s=new N(i.min.x+r.x/2,i.min.y+r.y/2,0);let o=e.topSegments,a=e.box3;if(a){a=a.union(i);const t=new N;a.getSize(t);const n=Math.max(r.x/t.x,r.y/t.y);o=Math.ceil(e.topSegments*n)}if(o<4)return this;const h=new ei(r.x,r.y,o,o),l=new vo(h);l.position.set(s.x,s.y,s.z),l.updateMatrixWorld();const d=(new za).evaluate(l,n,3),p=d.geometry.getAttribute("position"),f=new Pe(2*p.count,2);for(let u=0;u<p.count;u++){const t=p.getZ(u);p.setZ(u,e.depth+t)}if(a){const t=a.min,e=a.max,n=(new N).subVectors(e,t);for(let i=0;i<p.count;i++){const e=p.getX(i),r=p.getY(i),s=(e-t.x)/n.x,o=(r-t.y)/n.y;f.setXY(i,s,o)}d.geometry.setAttribute("uv",f)}p.needsUpdate=!0;const y=new pi(t,c(u({},e),{hasTop:!1})),m=Ta([d.geometry,y],2);this.copy(m.toNonIndexed())}}var Pa=t=>{const{split:e,depth:n,points:i,box3:r,hasTop:s,hasBottom:o,hasSide:a,sideRepeat:h,topSegments:l}=t,u=new(l?Ba:pi)(new An(i),{depth:n,bevelEnabled:!1,box3:r,UVGenerator:ci({split:e,box3:r,sideRepeat:h}),hasTop:s,hasBottom:o,hasSide:a,topSegments:l});return ui.clear(),u};const Ca=6378137,Ea=6356752.314245179;function ka(t,e,n=0,i=1,r=!1){const s=C.degToRad(t),o=C.degToRad(e),a=Math.cos(o),h=Math.sin(o),l=Math.cos(s),u=Math.sin(s);let c,d,p;if(r){const t=(Ca+n)*i;c=t*a*u,d=t*h,p=t*a*l}else{const t=Ca*Ca,e=(t-Ea*Ea)/t,r=Ca/Math.sqrt(1-e*h*h);c=(r+n)*a*u*i,d=(r*(1-e)+n)*h*i,p=(r+n)*a*l*i}return new N(c,d,p)}function Na(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Ia(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Oa(t){let e,n,i;function r(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<0?r=e+1:s=e}while(r<s)}return r}return 2!==t.length?(e=Na,n=(e,n)=>Na(t(e),n),i=(e,n)=>t(e)-n):(e=t===Na||t===Ia?t:Fa,n=t,i=t),{left:r,center:function(t,e,n=0,s=t.length){const o=r(t,e,n,s-1);return o>n&&i(t[o-1],e)>-i(t[o],e)?o-1:o},right:function(t,i,r=0,s=t.length){if(r<s){if(0!==e(i,i))return s;do{const e=r+s>>>1;n(t[e],i)<=0?r=e+1:s=e}while(r<s)}return r}}}function Fa(){return 0}const Ra=Oa(Na).right;function Va(t,e){let n,i;if(void 0===e)for(const r of t)null!=r&&(void 0===n?r>=r&&(n=i=r):(n>r&&(n=r),i<r&&(i=r)));else{let r=-1;for(let s of t)null!=(s=e(s,++r,t))&&(void 0===n?s>=s&&(n=i=s):(n>s&&(n=s),i<s&&(i=s)))}return[n,i]}Oa(function(t){return null===t?NaN:+t}).center;class Ua{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const e=this._partials;let n=0;for(let i=0;i<this._n&&i<32;i++){const r=e[i],s=t+r,o=Math.abs(t)<Math.abs(r)?t-(s-r):r-(s-t);o&&(e[n++]=o),t=s}return e[n]=t,this._n=n+1,this}valueOf(){const t=this._partials;let e,n,i,r=this._n,s=0;if(r>0){for(s=t[--r];r>0&&(e=s,n=t[--r],s=e+n,i=n-(s-e),!i););r>0&&(i<0&&t[r-1]<0||i>0&&t[r-1]>0)&&(n=2*i,e=s+n,n==e-s&&(s=e))}return s}}const La=Math.sqrt(50),qa=Math.sqrt(10),Da=Math.sqrt(2);function Xa(t,e,n){const i=(e-t)/Math.max(0,n),r=Math.floor(Math.log10(i)),s=i/Math.pow(10,r),o=s>=La?10:s>=qa?5:s>=Da?2:1;let a,h,l;return r<0?(l=Math.pow(10,-r)/o,a=Math.round(t*l),h=Math.round(e*l),a/l<t&&++a,h/l>e&&--h,l=-l):(l=Math.pow(10,r)*o,a=Math.round(t/l),h=Math.round(e/l),a*l<t&&++a,h*l>e&&--h),h<a&&.5<=n&&n<2?Xa(t,e,2*n):[a,h,l]}function Za(t,e,n){return Xa(t=+t,e=+e,n=+n)[2]}function ja(t,e){let n=0,i=0;if(void 0===e)for(let r of t)null!=r&&(r=+r)>=r&&(++n,i+=r);else{let r=-1;for(let s of t)null!=(s=e(s,++r,t))&&(s=+s)>=s&&(++n,i+=s)}if(n)return i/n}function Ga(t){return Array.from(function*(t){for(const e of t)yield*y(e)}(t))}var Ja=1e-6,Wa=1e-12,Ya=Math.PI,$a=Ya/2,Ha=Ya/4,Qa=2*Ya,Ka=180/Ya,th=Ya/180,eh=Math.abs,nh=Math.atan,ih=Math.atan2,rh=Math.cos,sh=Math.exp,oh=Math.hypot,ah=Math.log,hh=Math.sin,lh=Math.sign||function(t){return t>0?1:t<0?-1:0},uh=Math.sqrt,ch=Math.tan;function dh(t){return t>1?$a:t<-1?-$a:Math.asin(t)}function ph(t){return(t=hh(t/2))*t}function fh(){}function yh(t,e){t&&gh.hasOwnProperty(t.type)&&gh[t.type](t,e)}var mh={Feature:function(t,e){yh(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)yh(n[i].geometry,e)}},gh={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)t=n[i],e.point(t[0],t[1],t[2])},LineString:function(t,e){xh(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)xh(n[i],e,0)},Polygon:function(t,e){bh(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)bh(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)yh(n[i],e)}};function xh(t,e,n){var i,r=-1,s=t.length-n;for(e.lineStart();++r<s;)i=t[r],e.point(i[0],i[1],i[2]);e.lineEnd()}function bh(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)xh(t[n],e,1);e.polygonEnd()}function wh(t,e){t&&mh.hasOwnProperty(t.type)?mh[t.type](t,e):yh(t,e)}var vh,Mh,Sh,Ah,zh,_h,Th,Bh,Ph,Ch,Eh,kh,Nh,Ih,Oh,Fh,Rh=new Ua,Vh=new Ua,Uh={point:fh,lineStart:fh,lineEnd:fh,polygonStart:function(){Rh=new Ua,Uh.lineStart=Lh,Uh.lineEnd=qh},polygonEnd:function(){var t=+Rh;Vh.add(t<0?Qa+t:t),this.lineStart=this.lineEnd=this.point=fh},sphere:function(){Vh.add(Qa)}};function Lh(){Uh.point=Dh}function qh(){Xh(vh,Mh)}function Dh(t,e){Uh.point=Xh,vh=t,Mh=e,Sh=t*=th,Ah=rh(e=(e*=th)/2+Ha),zh=hh(e)}function Xh(t,e){var n=(t*=th)-Sh,i=n>=0?1:-1,r=i*n,s=rh(e=(e*=th)/2+Ha),o=hh(e),a=zh*o,h=Ah*s+a*rh(r),l=a*i*hh(r);Rh.add(ih(l,h)),Sh=t,Ah=s,zh=o}function Zh(t){return[ih(t[1],t[0]),dh(t[2])]}function jh(t){var e=t[0],n=t[1],i=rh(n);return[i*rh(e),i*hh(e),hh(n)]}function Gh(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Jh(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Wh(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Yh(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function $h(t){var e=uh(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var Hh,Qh,Kh,tl,el,nl,il,rl,sl,ol,al,hl,ll,ul,cl,dl,pl={point:fl,lineStart:ml,lineEnd:gl,polygonStart:function(){pl.point=xl,pl.lineStart=bl,pl.lineEnd=wl,Ih=new Ua,Uh.polygonStart()},polygonEnd:function(){Uh.polygonEnd(),pl.point=fl,pl.lineStart=ml,pl.lineEnd=gl,Rh<0?(_h=-(Bh=180),Th=-(Ph=90)):Ih>Ja?Ph=90:Ih<-1e-6&&(Th=-90),Fh[0]=_h,Fh[1]=Bh},sphere:function(){_h=-(Bh=180),Th=-(Ph=90)}};function fl(t,e){Oh.push(Fh=[_h=t,Bh=t]),e<Th&&(Th=e),e>Ph&&(Ph=e)}function yl(t,e){var n=jh([t*th,e*th]);if(Nh){var i=Jh(Nh,n),r=Jh([i[1],-i[0],0],i);$h(r),r=Zh(r);var s,o=t-Ch,a=o>0?1:-1,h=r[0]*Ka*a,l=eh(o)>180;l^(a*Ch<h&&h<a*t)?(s=r[1]*Ka)>Ph&&(Ph=s):l^(a*Ch<(h=(h+360)%360-180)&&h<a*t)?(s=-r[1]*Ka)<Th&&(Th=s):(e<Th&&(Th=e),e>Ph&&(Ph=e)),l?t<Ch?vl(_h,t)>vl(_h,Bh)&&(Bh=t):vl(t,Bh)>vl(_h,Bh)&&(_h=t):Bh>=_h?(t<_h&&(_h=t),t>Bh&&(Bh=t)):t>Ch?vl(_h,t)>vl(_h,Bh)&&(Bh=t):vl(t,Bh)>vl(_h,Bh)&&(_h=t)}else Oh.push(Fh=[_h=t,Bh=t]);e<Th&&(Th=e),e>Ph&&(Ph=e),Nh=n,Ch=t}function ml(){pl.point=yl}function gl(){Fh[0]=_h,Fh[1]=Bh,pl.point=fl,Nh=null}function xl(t,e){if(Nh){var n=t-Ch;Ih.add(eh(n)>180?n+(n>0?360:-360):n)}else Eh=t,kh=e;Uh.point(t,e),yl(t,e)}function bl(){Uh.lineStart()}function wl(){xl(Eh,kh),Uh.lineEnd(),eh(Ih)>Ja&&(_h=-(Bh=180)),Fh[0]=_h,Fh[1]=Bh,Nh=null}function vl(t,e){return(e-=t)<0?e+360:e}function Ml(t,e){return t[0]-e[0]}function Sl(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function Al(t){var e,n,i,r,s,o,a;if(Ph=Bh=-(_h=Th=1/0),Oh=[],wh(t,pl),n=Oh.length){for(Oh.sort(Ml),e=1,s=[i=Oh[0]];e<n;++e)Sl(i,(r=Oh[e])[0])||Sl(i,r[1])?(vl(i[0],r[1])>vl(i[0],i[1])&&(i[1]=r[1]),vl(r[0],i[1])>vl(i[0],i[1])&&(i[0]=r[0])):s.push(i=r);for(o=-1/0,e=0,i=s[n=s.length-1];e<=n;i=r,++e)r=s[e],(a=vl(i[1],r[0]))>o&&(o=a,_h=r[0],Bh=i[1])}return Oh=Fh=null,_h===1/0||Th===1/0?[[NaN,NaN],[NaN,NaN]]:[[_h,Th],[Bh,Ph]]}var zl={sphere:fh,point:_l,lineStart:Bl,lineEnd:El,polygonStart:function(){zl.lineStart=kl,zl.lineEnd=Nl},polygonEnd:function(){zl.lineStart=Bl,zl.lineEnd=El}};function _l(t,e){t*=th;var n=rh(e*=th);Tl(n*rh(t),n*hh(t),hh(e))}function Tl(t,e,n){++Hh,Kh+=(t-Kh)/Hh,tl+=(e-tl)/Hh,el+=(n-el)/Hh}function Bl(){zl.point=Pl}function Pl(t,e){t*=th;var n=rh(e*=th);ul=n*rh(t),cl=n*hh(t),dl=hh(e),zl.point=Cl,Tl(ul,cl,dl)}function Cl(t,e){t*=th;var n=rh(e*=th),i=n*rh(t),r=n*hh(t),s=hh(e),o=ih(uh((o=cl*s-dl*r)*o+(o=dl*i-ul*s)*o+(o=ul*r-cl*i)*o),ul*i+cl*r+dl*s);Qh+=o,nl+=o*(ul+(ul=i)),il+=o*(cl+(cl=r)),rl+=o*(dl+(dl=s)),Tl(ul,cl,dl)}function El(){zl.point=_l}function kl(){zl.point=Il}function Nl(){Ol(hl,ll),zl.point=_l}function Il(t,e){hl=t,ll=e,t*=th,e*=th,zl.point=Ol;var n=rh(e);ul=n*rh(t),cl=n*hh(t),dl=hh(e),Tl(ul,cl,dl)}function Ol(t,e){t*=th;var n=rh(e*=th),i=n*rh(t),r=n*hh(t),s=hh(e),o=cl*s-dl*r,a=dl*i-ul*s,h=ul*r-cl*i,l=oh(o,a,h),u=dh(l),c=l&&-u/l;sl.add(c*o),ol.add(c*a),al.add(c*h),Qh+=u,nl+=u*(ul+(ul=i)),il+=u*(cl+(cl=r)),rl+=u*(dl+(dl=s)),Tl(ul,cl,dl)}function Fl(t){Hh=Qh=Kh=tl=el=nl=il=rl=0,sl=new Ua,ol=new Ua,al=new Ua,wh(t,zl);var e=+sl,n=+ol,i=+al,r=oh(e,n,i);return r<Wa&&(e=nl,n=il,i=rl,Qh<Ja&&(e=Kh,n=tl,i=el),(r=oh(e,n,i))<Wa)?[NaN,NaN]:[ih(n,e)*Ka,dh(i/r)*Ka]}function Rl(t,e){function n(n,i){return n=t(n,i),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,i){return(n=e.invert(n,i))&&t.invert(n[0],n[1])}),n}function Vl(t,e){return eh(t)>Ya&&(t-=Math.round(t/Qa)*Qa),[t,e]}function Ul(t,e,n){return(t%=Qa)?e||n?Rl(ql(t),Dl(e,n)):ql(t):e||n?Dl(e,n):Vl}function Ll(t){return function(e,n){return eh(e+=t)>Ya&&(e-=Math.round(e/Qa)*Qa),[e,n]}}function ql(t){var e=Ll(t);return e.invert=Ll(-t),e}function Dl(t,e){var n=rh(t),i=hh(t),r=rh(e),s=hh(e);function o(t,e){var o=rh(e),a=rh(t)*o,h=hh(t)*o,l=hh(e),u=l*n+a*i;return[ih(h*r-u*s,a*n-l*i),dh(u*r+h*s)]}return o.invert=function(t,e){var o=rh(e),a=rh(t)*o,h=hh(t)*o,l=hh(e),u=l*r-h*s;return[ih(h*r+l*s,a*n+u*i),dh(u*n-a*i)]},o}function Xl(t){function e(e){return(e=t(e[0]*th,e[1]*th))[0]*=Ka,e[1]*=Ka,e}return t=Ul(t[0]*th,t[1]*th,t.length>2?t[2]*th:0),e.invert=function(e){return(e=t.invert(e[0]*th,e[1]*th))[0]*=Ka,e[1]*=Ka,e},e}function Zl(t,e){(e=jh(e))[0]-=t,$h(e);var n,i=(n=-e[1])>1?0:n<-1?Ya:Math.acos(n);return((-e[2]<0?-i:i)+Qa-Ja)%Qa}function jl(){var t,e=[];return{point:function(e,n,i){t.push([e,n,i])},lineStart:function(){e.push(t=[])},lineEnd:fh,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Gl(t,e){return eh(t[0]-e[0])<Ja&&eh(t[1]-e[1])<Ja}function Jl(t,e,n,i){this.x=t,this.z=e,this.o=n,this.e=i,this.v=!1,this.n=this.p=null}function Wl(t,e,n,i,r){var s,o,a=[],h=[];if(t.forEach(function(t){if(!((e=t.length-1)<=0)){var e,n,i=t[0],o=t[e];if(Gl(i,o)){if(!i[2]&&!o[2]){for(r.lineStart(),s=0;s<e;++s)r.point((i=t[s])[0],i[1]);return void r.lineEnd()}o[0]+=2e-6}a.push(n=new Jl(i,t,null,!0)),h.push(n.o=new Jl(i,null,n,!1)),a.push(n=new Jl(o,t,null,!1)),h.push(n.o=new Jl(o,null,n,!0))}}),a.length){for(h.sort(e),Yl(a),Yl(h),s=0,o=h.length;s<o;++s)h[s].e=n=!n;for(var l,u,c=a[0];;){for(var d=c,p=!0;d.v;)if((d=d.n)===c)return;l=d.z,r.lineStart();do{if(d.v=d.o.v=!0,d.e){if(p)for(s=0,o=l.length;s<o;++s)r.point((u=l[s])[0],u[1]);else i(d.x,d.n.x,1,r);d=d.n}else{if(p)for(l=d.p.z,s=l.length-1;s>=0;--s)r.point((u=l[s])[0],u[1]);else i(d.x,d.p.x,-1,r);d=d.p}l=(d=d.o).z,p=!p}while(!d.v);r.lineEnd()}}}function Yl(t){if(e=t.length){for(var e,n,i=0,r=t[0];++i<e;)r.n=n=t[i],n.p=r,r=n;r.n=n=t[0],n.p=r}}function $l(t){return eh(t[0])<=Ya?t[0]:lh(t[0])*((eh(t[0])+Ya)%Qa-Ya)}function Hl(t,e){var n=$l(e),i=e[1],r=hh(i),s=[hh(n),-rh(n),0],o=0,a=0,h=new Ua;1===r?i=$a+Ja:-1===r&&(i=-$a-Ja);for(var l=0,u=t.length;l<u;++l)if(d=(c=t[l]).length)for(var c,d,p=c[d-1],f=$l(p),y=p[1]/2+Ha,m=hh(y),g=rh(y),x=0;x<d;++x,f=w,m=M,g=S,p=b){var b=c[x],w=$l(b),v=b[1]/2+Ha,M=hh(v),S=rh(v),A=w-f,z=A>=0?1:-1,_=z*A,T=_>Ya,B=m*M;if(h.add(ih(B*z*hh(_),g*S+B*rh(_))),o+=T?A+z*Qa:A,T^f>=n^w>=n){var P=Jh(jh(p),jh(b));$h(P);var C=Jh(s,P);$h(C);var E=(T^A>=0?-1:1)*dh(C[2]);(i>E||i===E&&(P[0]||P[1]))&&(a+=T^A>=0?1:-1)}}return(o<-1e-6||o<Ja&&h<-1e-12)^1&a}function Ql(t,e,n,i){return function(r){var s,o,a,h=e(r),l=jl(),u=e(l),c=!1,d={point:p,lineStart:y,lineEnd:m,polygonStart:function(){d.point=g,d.lineStart=x,d.lineEnd=b,o=[],s=[]},polygonEnd:function(){d.point=p,d.lineStart=y,d.lineEnd=m,o=Ga(o);var t=Hl(s,i);o.length?(c||(r.polygonStart(),c=!0),Wl(o,tu,t,n,r)):t&&(c||(r.polygonStart(),c=!0),r.lineStart(),n(null,null,1,r),r.lineEnd()),c&&(r.polygonEnd(),c=!1),o=s=null},sphere:function(){r.polygonStart(),r.lineStart(),n(null,null,1,r),r.lineEnd(),r.polygonEnd()}};function p(e,n){t(e,n)&&r.point(e,n)}function f(t,e){h.point(t,e)}function y(){d.point=f,h.lineStart()}function m(){d.point=p,h.lineEnd()}function g(t,e){a.push([t,e]),u.point(t,e)}function x(){u.lineStart(),a=[]}function b(){g(a[0][0],a[0][1]),u.lineEnd();var t,e,n,i,h=u.clean(),d=l.result(),p=d.length;if(a.pop(),s.push(a),a=null,p)if(1&h){if((e=(n=d[0]).length-1)>0){for(c||(r.polygonStart(),c=!0),r.lineStart(),t=0;t<e;++t)r.point((i=n[t])[0],i[1]);r.lineEnd()}}else p>1&&2&h&&d.push(d.pop().concat(d.shift())),o.push(d.filter(Kl))}return d}}function Kl(t){return t.length>1}function tu(t,e){return((t=t.x)[0]<0?t[1]-$a-Ja:$a-t[1])-((e=e.x)[0]<0?e[1]-$a-Ja:$a-e[1])}Vl.invert=Vl;var eu=Ql(function(){return!0},function(t){var e,n=NaN,i=NaN,r=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(s,o){var a=s>0?Ya:-Ya,h=eh(s-n);eh(h-Ya)<Ja?(t.point(n,i=(i+o)/2>0?$a:-$a),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(s,i),e=0):r!==a&&h>=Ya&&(eh(n-r)<Ja&&(n-=r*Ja),eh(s-a)<Ja&&(s-=a*Ja),i=function(t,e,n,i){var r,s,o=hh(t-n);return eh(o)>Ja?nh((hh(e)*(s=rh(i))*hh(n)-hh(i)*(r=rh(e))*hh(t))/(r*s*o)):(e+i)/2}(n,i,s,o),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),e=0),t.point(n=s,i=o),r=a},lineEnd:function(){t.lineEnd(),n=i=NaN},clean:function(){return 2-e}}},function(t,e,n,i){var r;if(null==t)r=n*$a,i.point(-Ya,r),i.point(0,r),i.point(Ya,r),i.point(Ya,0),i.point(Ya,-r),i.point(0,-r),i.point(-Ya,-r),i.point(-Ya,0),i.point(-Ya,r);else if(eh(t[0]-e[0])>Ja){var s=t[0]<e[0]?Ya:-Ya;r=n*s/2,i.point(-s,r),i.point(0,r),i.point(s,r)}else i.point(e[0],e[1])},[-Ya,-$a]);function nu(t){var e=rh(t),n=2*th,i=e>0,r=eh(e)>Ja;function s(t,n){return rh(t)*rh(n)>e}function o(t,n,i){var r=[1,0,0],s=Jh(jh(t),jh(n)),o=Gh(s,s),a=s[0],h=o-a*a;if(!h)return!i&&t;var l=e*o/h,u=-e*a/h,c=Jh(r,s),d=Yh(r,l);Wh(d,Yh(s,u));var p=c,f=Gh(d,p),y=Gh(p,p),m=f*f-y*(Gh(d,d)-1);if(!(m<0)){var g=uh(m),x=Yh(p,(-f-g)/y);if(Wh(x,d),x=Zh(x),!i)return x;var b,w=t[0],v=n[0],M=t[1],S=n[1];v<w&&(b=w,w=v,v=b);var A=v-w,z=eh(A-Ya)<Ja;if(!z&&S<M&&(b=M,M=S,S=b),z||A<Ja?z?M+S>0^x[1]<(eh(x[0]-w)<Ja?M:S):M<=x[1]&&x[1]<=S:A>Ya^(w<=x[0]&&x[0]<=v)){var _=Yh(p,(-f+g)/y);return Wh(_,d),[x,Zh(_)]}}}function a(e,n){var r=i?t:Ya-t,s=0;return e<-r?s|=1:e>r&&(s|=2),n<-r?s|=4:n>r&&(s|=8),s}return Ql(s,function(t){var e,n,h,l,u;return{lineStart:function(){l=h=!1,u=1},point:function(c,d){var p,f=[c,d],y=s(c,d),m=i?y?0:a(c,d):y?a(c+(c<0?Ya:-Ya),d):0;if(!e&&(l=h=y)&&t.lineStart(),y!==h&&(!(p=o(e,f))||Gl(e,p)||Gl(f,p))&&(f[2]=1),y!==h)u=0,y?(t.lineStart(),p=o(f,e),t.point(p[0],p[1])):(p=o(e,f),t.point(p[0],p[1],2),t.lineEnd()),e=p;else if(r&&e&&i^y){var g;m&n||!(g=o(f,e,!0))||(u=0,i?(t.lineStart(),t.point(g[0][0],g[0][1]),t.point(g[1][0],g[1][1]),t.lineEnd()):(t.point(g[1][0],g[1][1]),t.lineEnd(),t.lineStart(),t.point(g[0][0],g[0][1],3)))}!y||e&&Gl(e,f)||t.point(f[0],f[1]),e=f,h=y,n=m},lineEnd:function(){h&&t.lineEnd(),e=null},clean:function(){return u|(l&&h)<<1}}},function(e,i,r,s){!function(t,e,n,i,r,s){if(n){var o=rh(e),a=hh(e),h=i*n;null==r?(r=e+i*Qa,s=e-h/2):(r=Zl(o,r),s=Zl(o,s),(i>0?r<s:r>s)&&(r+=i*Qa));for(var l,u=r;i>0?u>s:u<s;u-=h)l=Zh([o,-a*rh(u),-a*hh(u)]),t.point(l[0],l[1])}}(s,t,n,r,e,i)},i?[0,-t]:[-Ya,t-Ya])}var iu,ru,su,ou,au=1e9,hu=-au;function lu(t,e,n,i){function r(r,s){return t<=r&&r<=n&&e<=s&&s<=i}function s(r,s,a,l){var u=0,c=0;if(null==r||(u=o(r,a))!==(c=o(s,a))||h(r,s)<0^a>0)do{l.point(0===u||3===u?t:n,u>1?i:e)}while((u=(u+a+4)%4)!==c);else l.point(s[0],s[1])}function o(i,r){return eh(i[0]-t)<Ja?r>0?0:3:eh(i[0]-n)<Ja?r>0?2:1:eh(i[1]-e)<Ja?r>0?1:0:r>0?3:2}function a(t,e){return h(t.x,e.x)}function h(t,e){var n=o(t,1),i=o(e,1);return n!==i?n-i:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(o){var h,l,u,c,d,p,f,y,m,g,x,b=o,w=jl(),v={point:M,lineStart:function(){v.point=S,l&&l.push(u=[]);g=!0,m=!1,f=y=NaN},lineEnd:function(){h&&(S(c,d),p&&m&&w.rejoin(),h.push(w.result()));v.point=M,m&&b.lineEnd()},polygonStart:function(){b=w,h=[],l=[],x=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,r=l.length;n<r;++n)for(var s,o,a=l[n],h=1,u=a.length,c=a[0],d=c[0],p=c[1];h<u;++h)s=d,o=p,d=(c=a[h])[0],p=c[1],o<=i?p>i&&(d-s)*(i-o)>(p-o)*(t-s)&&++e:p<=i&&(d-s)*(i-o)<(p-o)*(t-s)&&--e;return e}(),n=x&&e,r=(h=Ga(h)).length;(n||r)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),r&&Wl(h,a,e,s,o),o.polygonEnd());b=o,h=l=u=null}};function M(t,e){r(t,e)&&b.point(t,e)}function S(s,o){var a=r(s,o);if(l&&u.push([s,o]),g)c=s,d=o,p=a,g=!1,a&&(b.lineStart(),b.point(s,o));else if(a&&m)b.point(s,o);else{var h=[f=Math.max(hu,Math.min(au,f)),y=Math.max(hu,Math.min(au,y))],w=[s=Math.max(hu,Math.min(au,s)),o=Math.max(hu,Math.min(au,o))];!function(t,e,n,i,r,s){var o,a=t[0],h=t[1],l=0,u=1,c=e[0]-a,d=e[1]-h;if(o=n-a,c||!(o>0)){if(o/=c,c<0){if(o<l)return;o<u&&(u=o)}else if(c>0){if(o>u)return;o>l&&(l=o)}if(o=r-a,c||!(o<0)){if(o/=c,c<0){if(o>u)return;o>l&&(l=o)}else if(c>0){if(o<l)return;o<u&&(u=o)}if(o=i-h,d||!(o>0)){if(o/=d,d<0){if(o<l)return;o<u&&(u=o)}else if(d>0){if(o>u)return;o>l&&(l=o)}if(o=s-h,d||!(o<0)){if(o/=d,d<0){if(o>u)return;o>l&&(l=o)}else if(d>0){if(o<l)return;o<u&&(u=o)}return l>0&&(t[0]=a+l*c,t[1]=h+l*d),u<1&&(e[0]=a+u*c,e[1]=h+u*d),!0}}}}}(h,w,t,e,n,i)?a&&(b.lineStart(),b.point(s,o),x=!1):(m||(b.lineStart(),b.point(h[0],h[1])),b.point(w[0],w[1]),a||b.lineEnd(),x=!1)}f=s,y=o,m=a}return v}}var uu={sphere:fh,point:fh,lineStart:function(){uu.point=du,uu.lineEnd=cu},lineEnd:fh,polygonStart:fh,polygonEnd:fh};function cu(){uu.point=uu.lineEnd=fh}function du(t,e){ru=t*=th,su=hh(e*=th),ou=rh(e),uu.point=pu}function pu(t,e){t*=th;var n=hh(e*=th),i=rh(e),r=eh(t-ru),s=rh(r),o=i*hh(r),a=ou*n-su*i*s,h=su*n+ou*i*s;iu.add(ih(uh(o*o+a*a),h)),ru=t,su=n,ou=i}var fu=[null,null],yu={type:"LineString",coordinates:fu};function mu(t,e){return fu[0]=t,fu[1]=e,n=yu,iu=new Ua,wh(n,uu),+iu;var n}var gu={Feature:function(t,e){return bu(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)if(bu(n[i].geometry,e))return!0;return!1}},xu={Sphere:function(){return!0},Point:function(t,e){return wu(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(wu(n[i],e))return!0;return!1},LineString:function(t,e){return vu(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(vu(n[i],e))return!0;return!1},Polygon:function(t,e){return Mu(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Mu(n[i],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)if(bu(n[i],e))return!0;return!1}};function bu(t,e){return!(!t||!xu.hasOwnProperty(t.type))&&xu[t.type](t,e)}function wu(t,e){return 0===mu(t,e)}function vu(t,e){for(var n,i,r,s=0,o=t.length;s<o;s++){if(0===(i=mu(t[s],e)))return!0;if(s>0&&(r=mu(t[s],t[s-1]))>0&&n<=r&&i<=r&&(n+i-r)*(1-Math.pow((n-i)/r,2))<Wa*r)return!0;n=i}return!1}function Mu(t,e){return!!Hl(t.map(Su),Au(e))}function Su(t){return(t=t.map(Au)).pop(),t}function Au(t){return[t[0]*th,t[1]*th]}var zu=t=>t,_u=1/0,Tu=_u,Bu=-_u,Pu=Bu,Cu={point:function(t,e){t<_u&&(_u=t);t>Bu&&(Bu=t);e<Tu&&(Tu=e);e>Pu&&(Pu=e)},lineStart:fh,lineEnd:fh,polygonStart:fh,polygonEnd:fh,result:function(){var t=[[_u,Tu],[Bu,Pu]];return Bu=Pu=-(Tu=_u=1/0),t}};function Eu(t){return function(e){var n=new ku;for(var i in t)n[i]=t[i];return n.stream=e,n}}function ku(){}function Nu(t,e,n){var i=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=i&&t.clipExtent(null),wh(n,t.stream(Cu)),e(Cu.result()),null!=i&&t.clipExtent(i),t}function Iu(t,e,n){return Nu(t,function(n){var i=e[1][0]-e[0][0],r=e[1][1]-e[0][1],s=Math.min(i/(n[1][0]-n[0][0]),r/(n[1][1]-n[0][1])),o=+e[0][0]+(i-s*(n[1][0]+n[0][0]))/2,a=+e[0][1]+(r-s*(n[1][1]+n[0][1]))/2;t.scale(150*s).translate([o,a])},n)}ku.prototype={constructor:ku,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var Ou=rh(30*th);function Fu(t,e){return+e?function(t,e){function n(i,r,s,o,a,h,l,u,c,d,p,f,y,m){var g=l-i,x=u-r,b=g*g+x*x;if(b>4*e&&y--){var w=o+d,v=a+p,M=h+f,S=uh(w*w+v*v+M*M),A=dh(M/=S),z=eh(eh(M)-1)<Ja||eh(s-c)<Ja?(s+c)/2:ih(v,w),_=t(z,A),T=_[0],B=_[1],P=T-i,C=B-r,E=x*P-g*C;(E*E/b>e||eh((g*P+x*C)/b-.5)>.3||o*d+a*p+h*f<Ou)&&(n(i,r,s,o,a,h,T,B,z,w/=S,v/=S,M,y,m),m.point(T,B),n(T,B,z,w,v,M,l,u,c,d,p,f,y,m))}}return function(e){var i,r,s,o,a,h,l,u,c,d,p,f,y={point:m,lineStart:g,lineEnd:b,polygonStart:function(){e.polygonStart(),y.lineStart=w},polygonEnd:function(){e.polygonEnd(),y.lineStart=g}};function m(n,i){n=t(n,i),e.point(n[0],n[1])}function g(){u=NaN,y.point=x,e.lineStart()}function x(i,r){var s=jh([i,r]),o=t(i,r);n(u,c,l,d,p,f,u=o[0],c=o[1],l=i,d=s[0],p=s[1],f=s[2],16,e),e.point(u,c)}function b(){y.point=m,e.lineEnd()}function w(){g(),y.point=v,y.lineEnd=M}function v(t,e){x(i=t,e),r=u,s=c,o=d,a=p,h=f,y.point=x}function M(){n(u,c,l,d,p,f,r,s,i,o,a,h,16,e),y.lineEnd=b,b()}return y}}(t,e):function(t){return Eu({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var Ru,Vu=Eu({point:function(t,e){this.stream.point(t*th,e*th)}});function Uu(t,e,n,i,r,s){if(!s)return function(t,e,n,i,r){function s(s,o){return[e+t*(s*=i),n-t*(o*=r)]}return s.invert=function(s,o){return[(s-e)/t*i,(n-o)/t*r]},s}(t,e,n,i,r);var o=rh(s),a=hh(s),h=o*t,l=a*t,u=o/t,c=a/t,d=(a*n-o*e)/t,p=(a*e+o*n)/t;function f(t,s){return[h*(t*=i)-l*(s*=r)+e,n-l*t-h*s]}return f.invert=function(t,e){return[i*(u*t-c*e+d),r*(p-c*t-u*e)]},f}function Lu(t){return function(t){var e,n,i,r,s,o,a,h,l,u,c=150,d=480,p=250,f=0,y=0,m=0,g=0,x=0,b=0,w=1,v=1,M=null,S=eu,A=null,z=zu,_=.5;function T(t){return h(t[0]*th,t[1]*th)}function B(t){return(t=h.invert(t[0],t[1]))&&[t[0]*Ka,t[1]*Ka]}function P(){var t=Uu(c,0,0,w,v,b).apply(null,e(f,y)),i=Uu(c,d-t[0],p-t[1],w,v,b);return n=Ul(m,g,x),a=Rl(e,i),h=Rl(n,a),o=Fu(a,_),C()}function C(){return l=u=null,T}return T.stream=function(t){return l&&u===t?l:l=Vu(function(t){return Eu({point:function(e,n){var i=t(e,n);return this.stream.point(i[0],i[1])}})}(n)(S(o(z(u=t)))))},T.preclip=function(t){return arguments.length?(S=t,M=void 0,C()):S},T.postclip=function(t){return arguments.length?(z=t,A=i=r=s=null,C()):z},T.clipAngle=function(t){return arguments.length?(S=+t?nu(M=t*th):(M=null,eu),C()):M*Ka},T.clipExtent=function(t){return arguments.length?(z=null==t?(A=i=r=s=null,zu):lu(A=+t[0][0],i=+t[0][1],r=+t[1][0],s=+t[1][1]),C()):null==A?null:[[A,i],[r,s]]},T.scale=function(t){return arguments.length?(c=+t,P()):c},T.translate=function(t){return arguments.length?(d=+t[0],p=+t[1],P()):[d,p]},T.center=function(t){return arguments.length?(f=t[0]%360*th,y=t[1]%360*th,P()):[f*Ka,y*Ka]},T.rotate=function(t){return arguments.length?(m=t[0]%360*th,g=t[1]%360*th,x=t.length>2?t[2]%360*th:0,P()):[m*Ka,g*Ka,x*Ka]},T.angle=function(t){return arguments.length?(b=t%360*th,P()):b*Ka},T.reflectX=function(t){return arguments.length?(w=t?-1:1,P()):w<0},T.reflectY=function(t){return arguments.length?(v=t?-1:1,P()):v<0},T.precision=function(t){return arguments.length?(o=Fu(a,_=t*t),C()):uh(_)},T.fitExtent=function(t,e){return Iu(T,t,e)},T.fitSize=function(t,e){return function(t,e,n){return Iu(t,[[0,0],e],n)}(T,t,e)},T.fitWidth=function(t,e){return function(t,e,n){return Nu(t,function(n){var i=+e,r=i/(n[1][0]-n[0][0]),s=(i-r*(n[1][0]+n[0][0]))/2,o=-r*n[0][1];t.scale(150*r).translate([s,o])},n)}(T,t,e)},T.fitHeight=function(t,e){return function(t,e,n){return Nu(t,function(n){var i=+e,r=i/(n[1][1]-n[0][1]),s=-r*n[0][0],o=(i-r*(n[1][1]+n[0][1]))/2;t.scale(150*r).translate([s,o])},n)}(T,t,e)},function(){return e=t.apply(this,arguments),T.invert=e.invert&&B,P()}}(function(){return t})()}function qu(t,e){return[t,ah(ch(($a+e)/2))]}function Du(t,e){return[t,e]}function Xu(t,e){var n=rh(e),i=1+rh(t)*n;return[n*hh(t)/i,hh(e)/i]}qu.invert=function(t,e){return[t,2*nh(sh(e))-$a]},Du.invert=Du,Xu.invert=(Ru=function(t){return 2*nh(t)},function(t,e){var n=uh(t*t+e*e),i=Ru(n),r=hh(i),s=rh(i);return[ih(t*r,n*s),dh(n&&e*r/n)]});var Zu=Math.abs,ju=Math.cos,Gu=Math.sin,Ju=1e-6,Wu=Math.PI,Yu=Wu/2;function $u(t){return t>1?0:t<-1?Wu:Math.acos(t)}function Hu(t){return t>0?Math.sqrt(t):0}function Qu(t,e){var n=ju(e),i=function(t){return t?t/Math.sin(t):1}($u(n*ju(t/=2)));return[2*n*Gu(t)*i,Gu(e)*i]}function Ku(t,e){var n=Qu(t,e);return[(n[0]+t/Yu)/2,(n[1]+e)/2]}Ku.invert=(t,e)=>{var n=t,i=e,r=25;do{var s,o=ju(i),a=Gu(i),h=Gu(2*i),l=a*a,u=o*o,c=Gu(n),d=ju(n/2),p=Gu(n/2),f=p*p,y=1-u*d*d,m=y?$u(o*d)*Hu(s=1/y):s=0,g=.5*(2*m*o*p+n/Yu)-t,x=.5*(m*a+i)-e,b=.5*s*(u*f+m*o*d*l)+.5/Yu,w=s*(c*h/4-m*a*p),v=.125*s*(h*p-m*a*u*c),M=.5*s*(l*d+m*f*o)+.5,S=w*v-M*b,A=(x*w-g*M)/S,z=(g*v-x*b)/S;n-=A,i-=z}while((Zu(A)>Ju||Zu(z)>Ju)&&--r>0);return[n,i]};const tc={mercator:function(){return function(t){var e,n,i,r=Lu(t),s=r.center,o=r.scale,a=r.translate,h=r.clipExtent,l=null;function u(){var s=Ya*o(),a=r(Xl(r.rotate()).invert([0,0]));return h(null==l?[[a[0]-s,a[1]-s],[a[0]+s,a[1]+s]]:t===qu?[[Math.max(a[0]-s,l),e],[Math.min(a[0]+s,n),i]]:[[l,Math.max(a[1]-s,e)],[n,Math.min(a[1]+s,i)]])}return r.scale=function(t){return arguments.length?(o(t),u()):o()},r.translate=function(t){return arguments.length?(a(t),u()):a()},r.center=function(t){return arguments.length?(s(t),u()):s()},r.clipExtent=function(t){return arguments.length?(null==t?l=e=n=i=null:(l=+t[0][0],e=+t[0][1],n=+t[1][0],i=+t[1][1]),u()):null==l?null:[[l,e],[n,i]]},u()}(qu).scale(961/Qa)},equirectangular:function(){return Lu(Du).scale(152.63)},winkel3:function(){return Lu(Ku).scale(158.837)}},ec={},nc=t=>{var e,n,i;const r=JSON.stringify(t);if(ec[r])return ec[r];const s=tc[null!=(e=t.projectionType)?e:"mercator"]().center(t.center).scale(t.scale).translate(null!=(n=t.translate)?n:[0,0]).precision(null!=(i=t.precision)?i:.1);return t.rotate&&s.rotate(t.rotate),ec[r]=s,s};function ic(t){var e;const n=null!=(e=t.userData.rtcPositionsVertices)?e:t.attributes.position;if(!n)throw new Error("Geometry has no position attribute");return{x:n.getX(0),y:n.getY(0),z:n.getZ(0)}}function rc(t){t.forEach(t=>{t.userData.rtcCenter||function(t,e=null){var n,i,r;e||(e=ic(t)),t.userData.rtcCenter=e;const s=t.attributes.position,o=null!=(n=t.userData.rtcPositionsVertices)?n:t.attributes.position;for(let l=0;l<s.count;l++)s.setX(l,o.getX(l)-e.x),s.setY(l,o.getY(l)-e.y),s.setZ(l,o.getZ(l)-e.z);s.needsUpdate=!0;const a=t.attributes.next,h=null!=(i=t.userData.rtcNextVertices)?i:t.attributes.next;if("MeshLineGeometry"===t.type&&a){for(let t=0;t<a.count;t++)a.setX(t,h.getX(t)-e.x),a.setY(t,h.getY(t)-e.y),a.setZ(t,h.getZ(t)-e.z);a.needsUpdate=!0}if("MeshLineGeometry"===t.type&&t.attributes.previous){const n=t.attributes.previous,i=null!=(r=t.userData.rtcPreviousVertices)?r:t.attributes.previous;for(let t=0;t<n.count;t++)n.setX(t,i.getX(t)-e.x),n.setY(t,i.getY(t)-e.y),n.setZ(t,i.getZ(t)-e.z);n.needsUpdate=!0}}(t)});const e=function(t){if(!t||0===t.length)return{x:0,y:0,z:0};let e=0,n=0,i=0;return t.forEach(t=>{if(t.userData&&t.userData.rtcCenter){const r=t.userData.rtcCenter;e+=r.x,n+=r.y,i+=r.z}else{const r=ic(t);e+=r.x,n+=r.y,i+=r.z}}),{x:e/t.length,y:n/t.length,z:i/t.length}}(t);return t.forEach(t=>{!function(t,e){const n=t.userData.rtcCenter;if(!n)throw new Error("Geometry must have rtcCenter in userData. Call applyRTC first.");const i=n.x-e.x,r=n.y-e.y,s=n.z-e.z,o=t.attributes.position.count,a=new Float32Array(3*o);for(let h=0;h<o;h++)a[3*h]=i,a[3*h+1]=r,a[3*h+2]=s;t.setAttribute("localCenter",new _e(a,3)),t.attributes.center&&t.deleteAttribute("center")}(t,e)}),{geometries:t,globalCenter:e}}const sc=(t,e)=>t.map(([t,n])=>{let i;if(e){const[r,s]=e([t,n]);i=new E(r,-s)}else i=new E(t,n);return i}),oc=({coordinates:t,lengths:e,metaLength:n,dimension:i=2})=>{const r=[],s=[];if(t&&e&&(t instanceof Float64Array||t instanceof Float32Array)){let o=0;r.length=e.length;for(let n=0;n<e.length;n++){const s=e[n],a=new Array(s);for(let e=0;e<s;e++)a[e]=Array.from(t.subarray(o,o+i)),o+=i;r[n]=a}if(n){const e=(t.length-o)/n;s.length=e;for(let i=0;i<e;i++)s[i]=Array.from(t.subarray(o,o+n)),o+=n}}return{coordinatesArr:r,metaArray:s}};var ac=(t,e,n)=>{const i={};if(n){const{globalCenter:e}=rc(t);i.globalCenter=e}const r=Ta(t,null!=e?e:0),s=[],o=Object.keys(r.attributes);return r.index&&o.push("index"),o.forEach(t=>{const e="index"===t?r.index:r.attributes[t];i[t]={array:e.array,itemSize:e.itemSize},s.push(e.array.buffer)}),e&&(i.groups=r.groups),r.dispose(),t.forEach(t=>{t.dispose()}),{message:i,transfer:s}},hc=(t,e=300,n)=>{const i=[],r=[];return t.forEach((t,s)=>{let o=!1;for(let n=1;n<t.length;n++)if(Math.abs(t[n].x-t[n-1].x)>e){o=!0;break}if(o){const e=[],o=[];t.forEach(t=>{t.x<0?e.push(t):o.push(t)}),i.push(e,o),n&&r.push(n[s],n[s])}else i.push(t),n&&r.push(n[s])}),{splitPolygons:i,splitMeta:r}};class lc extends Re{constructor(t=[],e="none",n){super(),p(this,"type","MeshLineGeometry"),p(this,"pointCount",0),p(this,"_points",[]),p(this,"shape","none"),p(this,"shapeFunction",t=>1),p(this,"matrixWorld",new _t),this.shape=e,n&&(this.shapeFunction=n),t.length>0&&this.setPoints(t)}convertToVector3Array(t){if("number"==typeof t[0]){const e=[],n=t;for(let t=0;t<n.length;t+=3)e.push(new N(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof E?new N(t.x,t.y,0):t instanceof N?t:Array.isArray(t)&&2===t.length?new N(t[0],t[1],0):Array.isArray(t)&&3===t.length?new N(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n=!1){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry(n))}initializeGeometry(){const t=new _e(new Float32Array(6*this.pointCount),3),e=new _e(new Float32Array(6*this.pointCount),3),n=new _e(new Float32Array(6*this.pointCount),3),i=new _e(new Float32Array(2*this.pointCount),1),r=new _e(new Float32Array(2*this.pointCount),1),s=new _e(new Float32Array(2*this.pointCount),1),o=new _e(new Float32Array(4*this.pointCount),2),a=new _e(new Uint16Array(6*(this.pointCount-1)),1);"taper"===this.shape&&(this.shapeFunction=t=>1*h(4*t*(1-t),1));for(let h=0,l=0,u=0;h<this.pointCount;h+=1,l+=2,u+=6){i.setX(l,h/this.pointCount),i.setX(l+1,h/this.pointCount),r.setX(l,1),r.setX(l+1,-1);const t="none"===this.shape?1:this.shapeFunction(h/(this.pointCount-1));s.setX(l,t),s.setX(l+1,t);const e=h/(this.pointCount-1);if(o.setXY(l,e,0),o.setXY(l+1,e,1),h<this.pointCount-1){const t=2*h;a.setX(u+0,t+0),a.setX(u+1,t+1),a.setX(u+2,t+2),a.setX(u+3,t+2),a.setX(u+4,t+1),a.setX(u+5,t+3)}}this.setAttribute("position",t),this.setAttribute("previous",e),this.setAttribute("next",n),this.setAttribute("counters",i),this.setAttribute("side",r),this.setAttribute("width",s),this.setAttribute("uv",o),this.setIndex(a)}updateGeometry(t=!1){var e,n,i,r,s,o,a,h,l,u;if(!this._points[0])return;const c=this.getAttribute("position"),d=this.getAttribute("previous"),p=this.getAttribute("next");t&&(this.userData.rtcPositionsVertices=new _e(new Float64Array(3*c.count),3),this.userData.rtcPreviousVertices=new _e(new Float64Array(3*d.count),3),this.userData.rtcNextVertices=new _e(new Float64Array(3*p.count),3));let f=0,y=0,m=0;const g=this._points[0];d.setXYZ(y,g.x,g.y,g.z),null==(e=this.userData.rtcPreviousVertices)||e.setXYZ(y,g.x,g.y,g.z),y+=1,d.setXYZ(y,g.x,g.y,g.z),null==(n=this.userData.rtcPreviousVertices)||n.setXYZ(y,g.x,g.y,g.z),y+=1;for(let b=0;b<this.pointCount;b++){const t=this._points[b];c.setXYZ(f,t.x,t.y,t.z),null==(i=this.userData.rtcPositionsVertices)||i.setXYZ(f,t.x,t.y,t.z),f+=1,c.setXYZ(f,t.x,t.y,t.z),null==(r=this.userData.rtcPositionsVertices)||r.setXYZ(f,t.x,t.y,t.z),f+=1,b<this.pointCount-1&&(d.setXYZ(y,t.x,t.y,t.z),null==(s=this.userData.rtcPreviousVertices)||s.setXYZ(y,t.x,t.y,t.z),y+=1,d.setXYZ(y,t.x,t.y,t.z),null==(o=this.userData.rtcPreviousVertices)||o.setXYZ(y,t.x,t.y,t.z),y+=1),b>0&&b+1<=this.pointCount&&(p.setXYZ(m,t.x,t.y,t.z),null==(a=this.userData.rtcNextVertices)||a.setXYZ(m,t.x,t.y,t.z),m+=1,p.setXYZ(m,t.x,t.y,t.z),null==(h=this.userData.rtcNextVertices)||h.setXYZ(m,t.x,t.y,t.z),m+=1)}const x=this._points[this.pointCount-1];p.setXYZ(m,x.x,x.y,x.z),null==(l=this.userData.rtcNextVertices)||l.setXYZ(m,x.x,x.y,x.z),m+=1,p.setXYZ(m,x.x,x.y,x.z),null==(u=this.userData.rtcNextVertices)||u.setXYZ(m,x.x,x.y,x.z),m+=1,c.needsUpdate=!0,d.needsUpdate=!0,p.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(t){this.setPoints(t)}updatePoints(t,e){const n=this.convertToVector3Array(t);n.length===this.pointCount?(this._points=n,e&&(this.shapeFunction=e,this.shape="custom",this.initializeGeometry()),this.updateGeometry()):console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.")}setShape(t,e){this.shape=t,e&&(this.shapeFunction=e),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}var uc=t=>{var e;const{setPointWidth:n,nodes:i}=t,r=new lc;return r.setPoints(i,n,null!=(e=t.resetCenter)&&e),r};var cc=function(t){const e=function(t){if(Array.isArray(t))return t;if("Feature"===t.type){if(null!==t.geometry)return t.geometry.coordinates}else if(t.coordinates)return t.coordinates;throw new Error("coords must be GeoJSON Feature, Geometry Object or an Array")}(t);let n,i,r=0,s=1;for(;s<e.length;)n=i||e[0],i=e[s],r+=(i[0]-n[0])*(i[1]+n[1]),s++;return r>0};function dc(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=pc(t,0,r,n,!0);const o=[];if(!s||s.next===s.prev)return o;let a,h,l;if(i&&(s=function(t,e,n,i){const r=[];for(let s=0,o=e.length;s<o;s++){const n=pc(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Ac(n))}r.sort(wc);for(let s=0;s<r.length;s++)n=vc(r[s],n);return n}(t,e,s,n)),t.length>80*n){a=t[0],h=t[1];let e=a,i=h;for(let s=n;s<r;s+=n){const n=t[s],r=t[s+1];n<a&&(a=n),r<h&&(h=r),n>e&&(e=n),r>i&&(i=r)}l=Math.max(e-a,i-h),l=0!==l?32767/l:0}return yc(s,o,n,a,h,l,0),o}function pc(t,e,n,i,r){let s;if(r===function(t,e,n,i){let r=0;for(let s=e,o=n-i;s<n;s+=i)r+=(t[o]-t[s])*(t[s+1]+t[o+1]),o=s;return r}(t,e,n,i)>0)for(let o=e;o<n;o+=i)s=Oc(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Oc(o/i|0,t[o],t[o+1],s);return s&&Pc(s,s.next)&&(Fc(s),s=s.next),s}function fc(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!Pc(i,i.next)&&0!==Bc(i.prev,i,i.next))i=i.next;else{if(Fc(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function yc(t,e,n,i,r,s,o){if(!t)return;!o&&s&&function(t,e,n,i){let r=t;do{0===r.z&&(r.z=Sc(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,n=1;do{let i,r=t;t=null;let s=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<n&&(a++,o=o.nextZ,o);t++);let h=n;for(;a>0||h>0&&o;)0!==a&&(0===h||!o||r.z<=o.z)?(i=r,r=r.nextZ,a--):(i=o,o=o.nextZ,h--),s?s.nextZ=i:t=i,i.prevZ=s,s=i;r=o}s.nextZ=null,n*=2}while(e>1)}(r)}(t,i,r,s);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(s?gc(t,i,r,s):mc(t))e.push(h.i,t.i,l.i),Fc(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?yc(t=xc(fc(t),e),e,n,i,r,s,2):2===o&&bc(t,e,n,i,r,s):yc(fc(t),e,n,i,r,s,1);break}}}function mc(t){const e=t.prev,n=t,i=t.next;if(Bc(e,n,i)>=0)return!1;const r=e.x,s=n.x,o=i.x,a=e.y,h=n.y,l=i.y,u=Math.min(r,s,o),c=Math.min(a,h,l),d=Math.max(r,s,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&_c(r,a,s,h,o,l,f.x,f.y)&&Bc(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function gc(t,e,n,i){const r=t.prev,s=t,o=t.next;if(Bc(r,s,o)>=0)return!1;const a=r.x,h=s.x,l=o.x,u=r.y,c=s.y,d=o.y,p=Math.min(a,h,l),f=Math.min(u,c,d),y=Math.max(a,h,l),m=Math.max(u,c,d),g=Sc(p,f,e,n,i),x=Sc(y,m,e,n,i);let b=t.prevZ,w=t.nextZ;for(;b&&b.z>=g&&w&&w.z<=x;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&_c(a,u,h,c,l,d,b.x,b.y)&&Bc(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&_c(a,u,h,c,l,d,w.x,w.y)&&Bc(w.prev,w,w.next)>=0)return!1;w=w.nextZ}for(;b&&b.z>=g;){if(b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==r&&b!==o&&_c(a,u,h,c,l,d,b.x,b.y)&&Bc(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;w&&w.z<=x;){if(w.x>=p&&w.x<=y&&w.y>=f&&w.y<=m&&w!==r&&w!==o&&_c(a,u,h,c,l,d,w.x,w.y)&&Bc(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function xc(t,e){let n=t;do{const i=n.prev,r=n.next.next;!Pc(i,r)&&Cc(i,n,n.next,r)&&Nc(i,r)&&Nc(r,i)&&(e.push(i.i,n.i,r.i),Fc(n),Fc(n.next),n=t=r),n=n.next}while(n!==t);return fc(n)}function bc(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Tc(o,t)){let a=Ic(o,t);return o=fc(o,o.next),a=fc(a,a.next),yc(o,e,n,i,r,s,0),void yc(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function wc(t,e){let n=t.x-e.x;if(0===n&&(n=t.y-e.y,0===n)){n=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}return n}function vc(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(Pc(t,n))return n;do{if(Pc(t,n.next))return n.next;if(r<=n.y&&r>=n.next.y&&n.next.y!==n.y){const t=n.x+(r-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(t<=i&&t>o&&(o=t,s=n.x<n.next.x?n:n.next,t===i))return s}n=n.next}while(n!==e);if(!s)return null;const a=s,h=s.x,l=s.y;let u=1/0;n=s;do{if(i>=n.x&&n.x>=h&&i!==n.x&&zc(r<l?i:o,r,h,l,r<l?o:i,r,n.x,n.y)){const e=Math.abs(r-n.y)/(i-n.x);Nc(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&Mc(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Ic(n,t);return fc(i,i.next),fc(n,n.next)}function Mc(t,e){return Bc(t.prev,t,e.prev)<0&&Bc(e.next,t,t.next)<0}function Sc(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-n)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Ac(t){let e=t,n=t;do{(e.x<n.x||e.x===n.x&&e.y<n.y)&&(n=e),e=e.next}while(e!==t);return n}function zc(t,e,n,i,r,s,o,a){return(r-o)*(e-a)>=(t-o)*(s-a)&&(t-o)*(i-a)>=(n-o)*(e-a)&&(n-o)*(s-a)>=(r-o)*(i-a)}function _c(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&zc(t,e,n,i,r,s,o,a)}function Tc(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Cc(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Nc(t,e)&&Nc(e,t)&&function(t,e){let n=t,i=!1;const r=(t.x+e.x)/2,s=(t.y+e.y)/2;do{n.y>s!=n.next.y>s&&n.next.y!==n.y&&r<(n.next.x-n.x)*(s-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(Bc(t.prev,t,e.prev)||Bc(t,e.prev,e))||Pc(t,e)&&Bc(t.prev,t,t.next)>0&&Bc(e.prev,e,e.next)>0)}function Bc(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function Pc(t,e){return t.x===e.x&&t.y===e.y}function Cc(t,e,n,i){const r=kc(Bc(t,e,n)),s=kc(Bc(t,e,i)),o=kc(Bc(n,i,t)),a=kc(Bc(n,i,e));return r!==s&&o!==a||(!(0!==r||!Ec(t,n,e))||(!(0!==s||!Ec(t,i,e))||(!(0!==o||!Ec(n,t,i))||!(0!==a||!Ec(n,e,i)))))}function Ec(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function kc(t){return t>0?1:t<0?-1:0}function Nc(t,e){return Bc(t.prev,t,t.next)<0?Bc(t,e,t.next)>=0&&Bc(t,t.prev,e)>=0:Bc(t,e,t.prev)<0||Bc(t,t.next,e)<0}function Ic(t,e){const n=Rc(t.i,t.x,t.y),i=Rc(e.i,e.x,e.y),r=t.next,s=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,s.next=i,i.prev=s,i}function Oc(t,e,n,i){const r=Rc(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Fc(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Rc(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Vc(t){const e=[],n=[],i=t[0][0].length;let r=0,s=0;for(const o of t){for(const t of o)for(let n=0;n<i;n++)e.push(t[n]);s&&(r+=s,n.push(r)),s=o.length}return{vertices:e,holes:n,dimensions:i}}const Uc=134217729;function Lc(t,e,n,i,r){let s,o,a,h,l=e[0],u=i[0],c=0,d=0;u>l==u>-l?(s=l,l=e[++c]):(s=u,u=i[++d]);let p=0;if(c<t&&d<n)for(u>l==u>-l?(o=l+s,a=s-(o-l),l=e[++c]):(o=u+s,a=s-(o-u),u=i[++d]),s=o,0!==a&&(r[p++]=a);c<t&&d<n;)u>l==u>-l?(o=s+l,h=o-s,a=s-(o-h)+(l-h),l=e[++c]):(o=s+u,h=o-s,a=s-(o-h)+(u-h),u=i[++d]),s=o,0!==a&&(r[p++]=a);for(;c<t;)o=s+l,h=o-s,a=s-(o-h)+(l-h),l=e[++c],s=o,0!==a&&(r[p++]=a);for(;d<n;)o=s+u,h=o-s,a=s-(o-h)+(u-h),u=i[++d],s=o,0!==a&&(r[p++]=a);return 0===s&&0!==p||(r[p++]=s),p}function qc(t){return new Float64Array(t)}const Dc=qc(4),Xc=qc(8),Zc=qc(12),jc=qc(16),Gc=qc(4);function Jc(t,e,n,i,r,s){const o=(e-s)*(n-r),a=(t-r)*(i-s),h=o-a,l=Math.abs(o+a);return Math.abs(h)>=33306690738754716e-32*l?h:-function(t,e,n,i,r,s,o){let a,h,l,u,c,d,p,f,y,m,g,x,b,w,v,M,S,A;const z=t-r,_=n-r,T=e-s,B=i-s;w=z*B,d=Uc*z,p=d-(d-z),f=z-p,d=Uc*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=T*_,d=Uc*T,p=d-(d-T),f=T-p,d=Uc*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Dc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Dc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Dc[2]=x-(A-c)+(g-c),Dc[3]=A;let P=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,Dc),C=22204460492503146e-32*o;if(P>=C||-P>=C)return P;if(c=t-z,a=t-(z+c)+(c-r),c=n-_,l=n-(_+c)+(c-r),c=e-T,h=e-(T+c)+(c-s),c=i-B,u=i-(B+c)+(c-s),0===a&&0===h&&0===l&&0===u)return P;if(C=11093356479670487e-47*o+33306690738754706e-32*Math.abs(P),P+=z*u+B*a-(T*l+_*h),P>=C||-P>=C)return P;w=a*B,d=Uc*a,p=d-(d-a),f=a-p,d=Uc*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=h*_,d=Uc*h,p=d-(d-h),f=h-p,d=Uc*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const E=Lc(4,Dc,4,Gc,Xc);w=z*u,d=Uc*z,p=d-(d-z),f=z-p,d=Uc*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=T*l,d=Uc*T,p=d-(d-T),f=T-p,d=Uc*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const k=Lc(E,Xc,4,Gc,Zc);w=a*u,d=Uc*a,p=d-(d-a),f=a-p,d=Uc*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=h*l,d=Uc*h,p=d-(d-h),f=h-p,d=Uc*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,Gc[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,Gc[1]=b-(g+c)+(c-M),A=x+g,c=A-x,Gc[2]=x-(A-c)+(g-c),Gc[3]=A;const N=Lc(k,Zc,4,Gc,jc);return jc[N-1]}(t,e,n,i,r,s,l)}const Wc=Math.pow(2,-52),Yc=new Uint32Array(512);class $c{static from(t,e=nd,n=id){const i=t.length,r=new Float64Array(2*i);for(let s=0;s<i;s++){const i=t[s];r[2*s]=e(i),r[2*s+1]=n(i)}return new $c(r)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const n=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*n),this._halfedges=new Int32Array(3*n),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:i,_hullHash:r}=this,s=t.length>>1;let o=1/0,a=1/0,h=-1/0,l=-1/0;for(let A=0;A<s;A++){const e=t[2*A],n=t[2*A+1];e<o&&(o=e),n<a&&(a=n),e>h&&(h=e),n>l&&(l=n),this._ids[A]=A}const u=(o+h)/2,c=(a+l)/2;let d,p,f;for(let A=0,z=1/0;A<s;A++){const e=Hc(u,c,t[2*A],t[2*A+1]);e<z&&(d=A,z=e)}const y=t[2*d],m=t[2*d+1];for(let A=0,z=1/0;A<s;A++){if(A===d)continue;const e=Hc(y,m,t[2*A],t[2*A+1]);e<z&&e>0&&(p=A,z=e)}let g=t[2*p],x=t[2*p+1],b=1/0;for(let A=0;A<s;A++){if(A===d||A===p)continue;const e=Kc(y,m,g,x,t[2*A],t[2*A+1]);e<b&&(f=A,b=e)}let w=t[2*f],v=t[2*f+1];if(b===1/0){for(let i=0;i<s;i++)this._dists[i]=t[2*i]-t[0]||t[2*i+1]-t[1];td(this._ids,this._dists,0,s-1);const e=new Uint32Array(s);let n=0;for(let t=0,i=-1/0;t<s;t++){const r=this._ids[t],s=this._dists[r];s>i&&(e[n++]=r,i=s)}return this.hull=e.subarray(0,n),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(Jc(y,m,g,x,w,v)<0){const t=p,e=g,n=x;p=f,g=w,x=v,f=t,w=e,v=n}const M=function(t,e,n,i,r,s){const o=n-t,a=i-e,h=r-t,l=s-e,u=o*o+a*a,c=h*h+l*l,d=.5/(o*l-a*h);return{x:t+(l*u-a*c)*d,y:e+(o*c-h*u)*d}}(y,m,g,x,w,v);this._cx=M.x,this._cy=M.y;for(let A=0;A<s;A++)this._dists[A]=Hc(t[2*A],t[2*A+1],M.x,M.y);td(this._ids,this._dists,0,s-1),this._hullStart=d;let S=3;n[d]=e[f]=p,n[p]=e[d]=f,n[f]=e[p]=d,i[d]=0,i[p]=1,i[f]=2,r.fill(-1),r[this._hashKey(y,m)]=d,r[this._hashKey(g,x)]=p,r[this._hashKey(w,v)]=f,this.trianglesLen=0,this._addTriangle(d,p,f,-1,-1,-1);for(let A,z,_=0;_<this._ids.length;_++){const s=this._ids[_],o=t[2*s],a=t[2*s+1];if(_>0&&Math.abs(o-A)<=Wc&&Math.abs(a-z)<=Wc)continue;if(A=o,z=a,s===d||s===p||s===f)continue;let h=0;for(let t=0,e=this._hashKey(o,a);t<this._hashSize&&(h=r[(e+t)%this._hashSize],-1===h||h===n[h]);t++);h=e[h];let l,u=h;for(;l=n[u],Jc(o,a,t[2*u],t[2*u+1],t[2*l],t[2*l+1])>=0;)if(u=l,u===h){u=-1;break}if(-1===u)continue;let c=this._addTriangle(u,s,n[u],-1,-1,i[u]);i[s]=this._legalize(c+2),i[u]=c,S++;let y=n[u];for(;l=n[y],Jc(o,a,t[2*y],t[2*y+1],t[2*l],t[2*l+1])<0;)c=this._addTriangle(y,s,l,i[s],-1,i[y]),i[s]=this._legalize(c+2),n[y]=y,S--,y=l;if(u===h)for(;l=e[u],Jc(o,a,t[2*l],t[2*l+1],t[2*u],t[2*u+1])<0;)c=this._addTriangle(l,s,u,-1,i[u],i[l]),this._legalize(c+2),i[l]=c,n[u]=u,S--,u=l;this._hullStart=e[s]=u,n[u]=e[y]=s,n[s]=y,r[this._hashKey(o,a)]=s,r[this._hashKey(t[2*u],t[2*u+1])]=u}this.hull=new Uint32Array(S);for(let A=0,z=this._hullStart;A<S;A++)this.hull[A]=z,z=n[z];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:n,coords:i}=this;let r=0,s=0;for(;;){const o=n[t],a=t-t%3;if(s=a+(t+2)%3,-1===o){if(0===r)break;t=Yc[--r];continue}const h=o-o%3,l=a+(t+1)%3,u=h+(o+2)%3,c=e[s],d=e[t],p=e[l],f=e[u];if(Qc(i[2*c],i[2*c+1],i[2*d],i[2*d+1],i[2*p],i[2*p+1],i[2*f],i[2*f+1])){e[t]=f,e[o]=c;const i=n[u];if(-1===i){let e=this._hullStart;do{if(this._hullTri[e]===u){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,i),this._link(o,n[s]),this._link(s,u);const a=h+(o+1)%3;r<Yc.length&&(Yc[r++]=a)}else{if(0===r)break;t=Yc[--r]}}return s}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,n,i,r,s){const o=this.trianglesLen;return this._triangles[o]=t,this._triangles[o+1]=e,this._triangles[o+2]=n,this._link(o,i),this._link(o+1,r),this._link(o+2,s),this.trianglesLen+=3,o}}function Hc(t,e,n,i){const r=t-n,s=e-i;return r*r+s*s}function Qc(t,e,n,i,r,s,o,a){const h=t-o,l=e-a,u=n-o,c=i-a,d=r-o,p=s-a,f=u*u+c*c,y=d*d+p*p;return h*(c*y-f*p)-l*(u*y-f*d)+(h*h+l*l)*(u*p-c*d)<0}function Kc(t,e,n,i,r,s){const o=n-t,a=i-e,h=r-t,l=s-e,u=o*o+a*a,c=h*h+l*l,d=.5/(o*l-a*h),p=(l*u-a*c)*d,f=(o*c-h*u)*d;return p*p+f*f}function td(t,e,n,i){if(i-n<=20)for(let r=n+1;r<=i;r++){const i=t[r],s=e[i];let o=r-1;for(;o>=n&&e[t[o]]>s;)t[o+1]=t[o--];t[o+1]=i}else{let r=n+1,s=i;ed(t,n+i>>1,r),e[t[n]]>e[t[i]]&&ed(t,n,i),e[t[r]]>e[t[i]]&&ed(t,r,i),e[t[n]]>e[t[r]]&&ed(t,n,r);const o=t[r],a=e[o];for(;;){do{r++}while(e[t[r]]<a);do{s--}while(e[t[s]]>a);if(s<r)break;ed(t,r,s)}t[n+1]=t[s],t[s]=o,i-r+1>=s-n?(td(t,e,r,i),td(t,e,n,s-1)):(td(t,e,n,s-1),td(t,e,r,i))}}function ed(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function nd(t){return t[0]}function id(t){return t[1]}function rd(t,e){for(var n=0,i=0,r=0,s=0,o=0,a=0,h=0,l=0,u=null,c=null,d=t[0],p=t[1],f=e.length;n<f;n++){i=0;var y=e[n].length-1,m=e[n];if((u=m[0])[0]!==m[y][0]&&u[1]!==m[y][1])throw new Error("First and last coordinates in a ring must be the same");for(o=u[0]-d,a=u[1]-p;i<y;i++)if(l=(c=m[i+1])[1]-p,a<0&&l<0||a>0&&l>0)a=l,o=(u=c)[0]-d;else{if(h=c[0]-t[0],l>0&&a<=0){if((s=o*l-h*a)>0)r+=1;else if(0===s)return 0}else if(a>0&&l<=0){if((s=o*l-h*a)<0)r+=1;else if(0===s)return 0}else if(0===l&&a<0){if(0===(s=o*l-h*a))return 0}else if(0===a&&l<0){if(0===(s=o*l-h*a))return 0}else if(0===a&&0===l){if(h<=0&&o>=0)return 0;if(o<=0&&h>=0)return 0}u=c,a=l,o=h}}return r%2!=0}var sd=function(t,e,n={}){if(!t)throw new Error("point is required");if(!e)throw new Error("polygon is required");const i=function(t){if(!t)throw new Error("coord is required");if(!Array.isArray(t)){if("Feature"===t.type&&null!==t.geometry&&"Point"===t.geometry.type)return[...t.geometry.coordinates];if("Point"===t.type)return[...t.coordinates]}if(Array.isArray(t)&&t.length>=2&&!Array.isArray(t[0])&&!Array.isArray(t[1]))return[...t];throw new Error("coord must be GeoJSON Point or an Array of numbers")}(t),r="Feature"===(s=e).type?s.geometry:s;var s;const o=r.type,a=e.bbox;let h=r.coordinates;if(a&&!1===function(t,e){return e[0]<=t[0]&&e[1]<=t[1]&&e[2]>=t[0]&&e[3]>=t[1]}(i,a))return!1;"Polygon"===o&&(h=[h]);let l=!1;for(var u=0;u<h.length;++u){const t=rd(i,h[u]);if(0===t)return!n.ignoreBoundary;t&&(l=!0)}return l};const od=1e-6;class ad{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,n){const i=(t=+t)+(n=+n),r=e=+e;if(n<0)throw new Error("negative radius");null===this._x1?this._+=`M${i},${r}`:(Math.abs(this._x1-i)>od||Math.abs(this._y1-r)>od)&&(this._+="L"+i+","+r),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=i},${this._y1=r}`)}rect(t,e,n,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+i}h${-n}Z`}value(){return this._||null}}class hd{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class ld{constructor(t,[e,n,i,r]=[0,0,960,500]){if(!((i=+i)>=(e=+e)&&(r=+r)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=i,this.xmin=e,this.ymax=r,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:i}=this,r=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let d,p,f=0,y=0,m=n.length;f<m;f+=3,y+=2){const e=2*n[f],i=2*n[f+1],s=2*n[f+2],o=t[e],a=t[e+1],h=t[i],l=t[i+1],u=t[s],c=t[s+1],m=h-o,g=l-a,x=u-o,b=c-a,w=2*(m*b-g*x);if(Math.abs(w)<1e-9){let e=1e9;const i=2*n[0];e*=Math.sign((t[i]-o)*b-(t[i+1]-a)*x),d=(o+u)/2-e*b,p=(a+c)/2+e*x}else{const t=1/w,e=m*m+g*g,n=x*x+b*b;d=o+(b*e-g*n)*t,p=a+(m*n-x*e)*t}r[y]=d,r[y+1]=p}let s,o,a,h=e[e.length-1],l=4*h,u=t[2*h],c=t[2*h+1];i.fill(0);for(let d=0;d<e.length;++d)h=e[d],s=l,o=u,a=c,l=4*h,u=t[2*h],c=t[2*h+1],i[s+2]=i[l]=a-c,i[s+3]=i[l+1]=u-o}render(t){const e=null==t?t=new ad:void 0,{delaunay:{halfedges:n,inedges:i,hull:r},circumcenters:s,vectors:o}=this;if(r.length<=1)return null;for(let l=0,u=n.length;l<u;++l){const e=n[l];if(e<l)continue;const i=2*Math.floor(l/3),r=2*Math.floor(e/3),o=s[i],a=s[i+1],h=s[r],u=s[r+1];this._renderSegment(o,a,h,u,t)}let a,h=r[r.length-1];for(let l=0;l<r.length;++l){a=h,h=r[l];const e=2*Math.floor(i[h]/3),n=s[e],u=s[e+1],c=4*a,d=this._project(n,u,o[c+2],o[c+3]);d&&this._renderSegment(n,u,d[0],d[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new ad:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=null==e?e=new ad:void 0,i=this._clip(t);if(null===i||!i.length)return;e.moveTo(i[0],i[1]);let r=i.length;for(;i[0]===i[r-2]&&i[1]===i[r-1]&&r>1;)r-=2;for(let s=2;s<r;s+=2)i[s]===i[s-2]&&i[s+1]===i[s-1]||e.lineTo(i[s],i[s+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const t=this.cellPolygon(e);t&&(t.index=e,yield t)}}cellPolygon(t){const e=new hd;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,i,r){let s;const o=this._regioncode(t,e),a=this._regioncode(n,i);0===o&&0===a?(r.moveTo(t,e),r.lineTo(n,i)):(s=this._clipSegment(t,e,n,i,o,a))&&(r.moveTo(s[0],s[1]),r.lineTo(s[2],s[3]))}contains(t,e,n){return(e=+e)==e&&(n=+n)==n&&this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const t=this._clip(n);if(t)t:for(let i=0,r=e.length;i<r;i+=2)for(let s=0,o=t.length;s<o;s+=2)if(e[i]==t[s]&&e[i+1]==t[s+1]&&e[(i+2)%r]==t[(s+o-2)%o]&&e[(i+3)%r]==t[(s+o-1)%o]){yield n;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:i,triangles:r}}=this,s=n[t];if(-1===s)return null;const o=[];let a=s;do{const n=Math.floor(a/3);if(o.push(e[2*n],e[2*n+1]),a=a%3==2?a-2:a+1,r[a]!==t)break;a=i[a]}while(a!==s&&-1!==a);return o}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:n}=this,i=4*t;return n[i]||n[i+1]?this._clipInfinite(t,e,n[i],n[i+1],n[i+2],n[i+3]):this._clipFinite(t,e)}_clipFinite(t,e){const n=e.length;let i,r,s,o,a=null,h=e[n-2],l=e[n-1],u=this._regioncode(h,l),c=0;for(let d=0;d<n;d+=2)if(i=h,r=l,h=e[d],l=e[d+1],s=u,u=this._regioncode(h,l),0===s&&0===u)o=c,c=0,a?a.push(h,l):a=[h,l];else{let e,n,d,p,f;if(0===s){if(null===(e=this._clipSegment(i,r,h,l,s,u)))continue;[n,d,p,f]=e}else{if(null===(e=this._clipSegment(h,l,i,r,u,s)))continue;[p,f,n,d]=e,o=c,c=this._edgecode(n,d),o&&c&&this._edge(t,o,c,a,a.length),a?a.push(n,d):a=[n,d]}o=c,c=this._edgecode(p,f),o&&c&&this._edge(t,o,c,a,a.length),a?a.push(p,f):a=[p,f]}if(a)o=c,c=this._edgecode(a[0],a[1]),o&&c&&this._edge(t,o,c,a,a.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return a}_clipSegment(t,e,n,i,r,s){for(;;){if(0===r&&0===s)return[t,e,n,i];if(r&s)return null;let o,a,h=r||s;8&h?(o=t+(n-t)*(this.ymax-e)/(i-e),a=this.ymax):4&h?(o=t+(n-t)*(this.ymin-e)/(i-e),a=this.ymin):2&h?(a=e+(i-e)*(this.xmax-t)/(n-t),o=this.xmax):(a=e+(i-e)*(this.xmin-t)/(n-t),o=this.xmin),r?(t=o,e=a,r=this._regioncode(t,e)):(n=o,i=a,s=this._regioncode(n,i))}}_clipInfinite(t,e,n,i,r,s){let o,a=Array.from(e);if((o=this._project(a[0],a[1],n,i))&&a.unshift(o[0],o[1]),(o=this._project(a[a.length-2],a[a.length-1],r,s))&&a.push(o[0],o[1]),a=this._clipFinite(t,a))for(let h,l=0,u=a.length,c=this._edgecode(a[u-2],a[u-1]);l<u;l+=2)h=c,c=this._edgecode(a[l],a[l+1]),h&&c&&(l=this._edge(t,h,c,a,l),u=a.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(a=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return a}_edge(t,e,n,i,r){for(;e!==n;){let n,s;switch(e){case 5:e=4;continue;case 4:e=6,n=this.xmax,s=this.ymin;break;case 6:e=2;continue;case 2:e=10,n=this.xmax,s=this.ymax;break;case 10:e=8;continue;case 8:e=9,n=this.xmin,s=this.ymax;break;case 9:e=1;continue;case 1:e=5,n=this.xmin,s=this.ymin}i[r]===n&&i[r+1]===s||!this.contains(t,n,s)||(i.splice(r,0,n,s),r+=2)}if(i.length>4)for(let s=0;s<i.length;s+=2){const t=(s+2)%i.length,e=(s+4)%i.length;(i[s]===i[t]&&i[t]===i[e]||i[s+1]===i[t+1]&&i[t+1]===i[e+1])&&(i.splice(t,2),s-=2)}return r}_project(t,e,n,i){let r,s,o,a=1/0;if(i<0){if(e<=this.ymin)return null;(r=(this.ymin-e)/i)<a&&(o=this.ymin,s=t+(a=r)*n)}else if(i>0){if(e>=this.ymax)return null;(r=(this.ymax-e)/i)<a&&(o=this.ymax,s=t+(a=r)*n)}if(n>0){if(t>=this.xmax)return null;(r=(this.xmax-t)/n)<a&&(s=this.xmax,o=e+(a=r)*i)}else if(n<0){if(t<=this.xmin)return null;(r=(this.xmin-t)/n)<a&&(s=this.xmin,o=e+(a=r)*i)}return[s,o]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const ud=2*Math.PI,cd=Math.pow;function dd(t){return t[0]}function pd(t){return t[1]}function fd(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class yd{static from(t,e=dd,n=pd,i){return new yd("length"in t?function(t,e,n,i){const r=t.length,s=new Float64Array(2*r);for(let o=0;o<r;++o){const r=t[o];s[2*o]=e.call(i,r,o,t),s[2*o+1]=n.call(i,r,o,t)}return s}(t,e,n,i):Float64Array.from(function*(t,e,n,i){let r=0;for(const s of t)yield e.call(i,s,r,t),yield n.call(i,s,r,t),++r}(t,e,n,i)))}constructor(t){this._delaunator=new $c(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:n}=t;for(let i=0;i<e.length;i+=3){const t=2*e[i],r=2*e[i+1],s=2*e[i+2];if((n[s]-n[t])*(n[r+1]-n[t+1])-(n[r]-n[t])*(n[s+1]-n[t+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},(t,e)=>e).sort((t,n)=>e[2*t]-e[2*n]||e[2*t+1]-e[2*n+1]);const t=this.collinear[0],n=this.collinear[this.collinear.length-1],i=[e[2*t],e[2*t+1],e[2*n],e[2*n+1]],r=1e-8*Math.hypot(i[3]-i[1],i[2]-i[0]);for(let s=0,o=e.length/2;s<o;++s){const t=fd(e[2*s],e[2*s+1],r);e[2*s]=t[0],e[2*s+1]=t[1]}this._delaunator=new $c(e)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,i=this.hull=this._delaunator.hull,r=this.triangles=this._delaunator.triangles,s=this.inedges.fill(-1),o=this._hullIndex.fill(-1);for(let a=0,h=n.length;a<h;++a){const t=r[a%3==2?a-2:a+1];-1!==n[a]&&-1!==s[t]||(s[t]=a)}for(let a=0,h=i.length;a<h;++a)o[i[a]]=a;i.length<=2&&i.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],s[i[0]]=1,2===i.length&&(s[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new ld(this,t)}*neighbors(t){const{inedges:e,hull:n,_hullIndex:i,halfedges:r,triangles:s,collinear:o}=this;if(o){const e=o.indexOf(t);return e>0&&(yield o[e-1]),void(e<o.length-1&&(yield o[e+1]))}const a=e[t];if(-1===a)return;let h=a,l=-1;do{if(yield l=s[h],h=h%3==2?h-2:h+1,s[h]!==t)return;if(h=r[h],-1===h){const e=n[(i[t]+1)%n.length];return void(e!==l&&(yield e))}}while(h!==a)}find(t,e,n=0){if((t=+t)!=t||(e=+e)!=e)return-1;const i=n;let r;for(;(r=this._step(n,t,e))>=0&&r!==n&&r!==i;)n=r;return r}_step(t,e,n){const{inedges:i,hull:r,_hullIndex:s,halfedges:o,triangles:a,points:h}=this;if(-1===i[t]||!h.length)return(t+1)%(h.length>>1);let l=t,u=cd(e-h[2*t],2)+cd(n-h[2*t+1],2);const c=i[t];let d=c;do{let i=a[d];const c=cd(e-h[2*i],2)+cd(n-h[2*i+1],2);if(c<u&&(u=c,l=i),d=d%3==2?d-2:d+1,a[d]!==t)break;if(d=o[d],-1===d){if(d=r[(s[t]+1)%r.length],d!==i&&cd(e-h[2*d],2)+cd(n-h[2*d+1],2)<u)return d;break}}while(d!==c);return l}render(t){const e=null==t?t=new ad:void 0,{points:n,halfedges:i,triangles:r}=this;for(let s=0,o=i.length;s<o;++s){const e=i[s];if(e<s)continue;const o=2*r[s],a=2*r[e];t.moveTo(n[o],n[o+1]),t.lineTo(n[a],n[a+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e){void 0!==e||t&&"function"==typeof t.moveTo||(e=t,t=null),e=null==e?2:+e;const n=null==t?t=new ad:void 0,{points:i}=this;for(let r=0,s=i.length;r<s;r+=2){const n=i[r],s=i[r+1];t.moveTo(n+e,s),t.arc(n,s,e,0,ud)}return n&&n.value()}renderHull(t){const e=null==t?t=new ad:void 0,{hull:n,points:i}=this,r=2*n[0],s=n.length;t.moveTo(i[r],i[r+1]);for(let o=1;o<s;++o){const e=2*n[o];t.lineTo(i[e],i[e+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new hd;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new ad:void 0,{points:i,triangles:r}=this,s=2*r[t*=3],o=2*r[t+1],a=2*r[t+2];return e.moveTo(i[s],i[s+1]),e.lineTo(i[o],i[o+1]),e.lineTo(i[a],i[a+1]),e.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,n=t.length/3;e<n;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new hd;return this.renderTriangle(t,e),e.value()}}const md=Math.PI,gd=md/2,xd=180/md,bd=md/180,wd=Math.atan2,vd=Math.cos,Md=Math.max,Sd=Math.min,Ad=Math.sin,zd=Math.sign||function(t){return t>0?1:t<0?-1:0},_d=Math.sqrt;function Td(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Bd(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Pd(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Cd(t){var e=_d(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return[t[0]/e,t[1]/e,t[2]/e]}function Ed(t){return[wd(t[1],t[0])*xd,(e=Md(-1,Sd(1,t[2])),(e>1?gd:e<-1?-gd:Math.asin(e))*xd)];var e}function kd(t){const e=t[0]*bd,n=t[1]*bd,i=vd(n);return[i*vd(e),i*Ad(e),Ad(n)]}function Nd(t){return Td((t=t.map(t=>kd(t)))[0],Bd(t[2],t[1]))}function Id(t){const e=function(t){if(t.length<2)return{};let e=0;for(;isNaN(t[e][0]+t[e][1])&&e++<t.length;);const n=Xl(t[e]),i=Lu(Xu).scale(250).clipAngle(142).translate([0,0]).scale(1).rotate(n.invert([180,0]));t=t.map(i);const r=[];let s=1;for(let d=0,p=t.length;d<p;d++){let e=h(t[d][0],2)+h(t[d][1],2);!isFinite(e)||e>1e32?r.push(d):e>s&&(s=e)}const o=1e6*_d(s);r.forEach(e=>t[e]=[o,0]),t.push([0,o]),t.push([-o,0]),t.push([0,-o]);const a=yd.from(t);a.projection=i;const{triangles:l,halfedges:u,inedges:c}=a;for(let h=0,d=u.length;h<d;h++)if(u[h]<0){const t=h%3==2?h-2:h+1,n=h%3==0?h+2:h-1,i=u[t],r=u[n];u[i]=r,u[r]=i,u[t]=u[n]=-1,l[h]=l[t]=l[n]=e,c[l[i]]=i%3==0?i+2:i-1,c[l[r]]=r%3==0?r+2:r-1,h+=2-h%3}else l[h]>t.length-3-1&&(l[h]=e);return a}(t),n=function(t){const{triangles:e}=t;if(!e)return[];const n=[];for(let i=0,r=e.length/3;i<r;i++){const t=e[3*i],r=e[3*i+1],s=e[3*i+2];t!==r&&r!==s&&n.push([t,s,r])}return n}(e),i=function(t,e){const n=new Set;return 2===e.length?[[0,1]]:(t.forEach(t=>{if(t[0]!==t[1]&&!(Nd(t.map(t=>e[t]))<0))for(let e,i=0;i<3;i++)e=(i+1)%3,n.add(Va([t[i],t[e]]).join("-"))}),Array.from(n,t=>t.split("-").map(Number)))}(n,t),r=function(t,e){const n=[];t.forEach(t=>{for(let e=0;e<3;e++){const i=t[e],r=t[(e+1)%3];n[i]=n[i]||[],n[i].push(r)}}),0===t.length&&(2===e?(n[0]=[1],n[1]=[0]):1===e&&(n[0]=[]));return n}(n,t.length),s=function(t,e){function n(t,e){let n=t[0]-e[0],i=t[1]-e[1],r=t[2]-e[2];return n*n+i*i+r*r}return function(i,r,s){void 0===s&&(s=0);let o,a,h=s;const l=kd([i,r]);do{o=s,s=null,a=n(l,kd(e[o])),t[o].forEach(t=>{let i=n(l,kd(e[t]));if(i<a)return a=i,s=t,void(h=t)})}while(null!==s);return h}}(r,t),o=function(t,e){return t.map(t=>{const n=t.map(t=>e[t]).map(kd);return Ed(Cd(Pd(Pd(Bd(n[1],n[0]),Bd(n[2],n[1])),Bd(n[0],n[2]))))})}(n,t),{polygons:a,centers:l}=function(t,e,n){const i=[],r=t.slice();if(0===e.length){if(n.length<2)return{polygons:i,centers:r};if(2===n.length){const t=kd(n[0]),e=kd(n[1]),s=Cd(Pd(t,e)),a=Cd(Bd(t,e)),h=Bd(s,a),l=[s,Bd(s,h),Bd(Bd(s,h),h),Bd(Bd(Bd(s,h),h),h)].map(Ed).map(o);return i.push(l),i.push(l.slice().reverse()),{polygons:i,centers:r}}}e.forEach((t,e)=>{for(let n=0;n<3;n++){const r=t[n],s=t[(n+1)%3],o=t[(n+2)%3];i[r]=i[r]||[],i[r].push([s,o,e,[r,s,o]])}});const s=i.map(t=>{const e=[t[0][2]];let i=t[0][1];for(let n=1;n<t.length;n++)for(let r=0;r<t.length;r++)if(t[r][0]==i){i=t[r][1],e.push(t[r][2]);break}if(e.length>2)return e;if(2==e.length){const i=Od(n[t[0][3][0]],n[t[0][3][1]],r[e[0]]),s=Od(n[t[0][3][2]],n[t[0][3][0]],r[e[0]]),a=o(i),h=o(s);return[e[0],h,e[1],a]}});function o(t){let n=-1;return r.slice(e.length,1/0).forEach((i,r)=>{i[0]===t[0]&&i[1]===t[1]&&(n=r+e.length)}),n<0&&(n=r.length,r.push(t)),n}return{polygons:s,centers:r}}(o,n,t),u=function(t){const e=[];return t.forEach(t=>{if(!t)return;let n=t[t.length-1];for(let i of t)i>n&&e.push([n,i]),n=i}),e}(a),c=function(t,e){const n=new Set,i=[];t.map(t=>{if(!(Nd(t.map(t=>e[t>e.length?0:t]))>1e-12))for(let e=0;e<3;e++){let i=[t[e],t[(e+1)%3]],r=`${i[0]}-${i[1]}`;n.has(r)?n.delete(r):n.add(`${i[1]}-${i[0]}`)}});const r=new Map;let s;if(n.forEach(t=>{t=t.split("-").map(Number),r.set(t[0],t[1]),s=t[0]}),void 0===s)return i;let o=s;do{i.push(o);let t=r.get(o);r.set(o,-1),o=t}while(o>-1&&o!==s);return i}(n,t),d=function(t,e){return function(n){const i=new Map,r=new Map;return t.forEach((t,e)=>{const s=t.join("-");i.set(s,n[e]),r.set(s,!0)}),e.forEach(t=>{let e=0,n=-1;for(let r=0;r<3;r++){let s=Va([t[r],t[(r+1)%3]]).join("-");i.get(s)>e&&(e=i.get(s),n=s)}r.set(n,!1)}),t.map(t=>r.get(t.join("-")))}}(i,n);return{delaunay:e,edges:i,triangles:n,centers:l,neighbors:r,polygons:a,mesh:u,hull:c,urquhart:d,find:s}}function Od(t,e,n){t=kd(t),e=kd(e),n=kd(n);const i=zd(Td(Bd(e,t),n));return Ed(Cd(Pd(t,e)).map(t=>i*t))}function Fd(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Rd(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function Vd(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function Ud(){}var Ld=.7,qd=1/Ld,Dd="\\\\s*([+-]?\\\\d+)\\\\s*",Xd="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*",Zd="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*",jd=/^#([0-9a-f]{3,8})$/,Gd=new RegExp(`^rgb\\\\(${Dd},${Dd},${Dd}\\\\)$`),Jd=new RegExp(`^rgb\\\\(${Zd},${Zd},${Zd}\\\\)$`),Wd=new RegExp(`^rgba\\\\(${Dd},${Dd},${Dd},${Xd}\\\\)$`),Yd=new RegExp(`^rgba\\\\(${Zd},${Zd},${Zd},${Xd}\\\\)$`),$d=new RegExp(`^hsl\\\\(${Xd},${Zd},${Zd}\\\\)$`),Hd=new RegExp(`^hsla\\\\(${Xd},${Zd},${Zd},${Xd}\\\\)$`),Qd={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function Kd(){return this.rgb().formatHex()}function tp(){return this.rgb().formatRgb()}function ep(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=jd.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?np(e):3===n?new sp(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?ip(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?ip(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Gd.exec(t))?new sp(e[1],e[2],e[3],1):(e=Jd.exec(t))?new sp(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Wd.exec(t))?ip(e[1],e[2],e[3],e[4]):(e=Yd.exec(t))?ip(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=$d.exec(t))?cp(e[1],e[2]/100,e[3]/100,1):(e=Hd.exec(t))?cp(e[1],e[2]/100,e[3]/100,e[4]):Qd.hasOwnProperty(t)?np(Qd[t]):"transparent"===t?new sp(NaN,NaN,NaN,0):null}function np(t){return new sp(t>>16&255,t>>8&255,255&t,1)}function ip(t,e,n,i){return i<=0&&(t=e=n=NaN),new sp(t,e,n,i)}function rp(t,e,n,i){return 1===arguments.length?((r=t)instanceof Ud||(r=ep(r)),r?new sp((r=r.rgb()).r,r.g,r.b,r.opacity):new sp):new sp(t,e,n,null==i?1:i);var r}function sp(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function op(){return`#${up(this.r)}${up(this.g)}${up(this.b)}`}function ap(){const t=hp(this.opacity);return`${1===t?"rgb(":"rgba("}${lp(this.r)}, ${lp(this.g)}, ${lp(this.b)}${1===t?")":`, ${t})`}`}function hp(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function lp(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function up(t){return((t=lp(t))<16?"0":"")+t.toString(16)}function cp(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new pp(t,e,n,i)}function dp(t){if(t instanceof pp)return new pp(t.h,t.s,t.l,t.opacity);if(t instanceof Ud||(t=ep(t)),!t)return new pp;if(t instanceof pp)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),s=Math.max(e,n,i),o=NaN,a=s-r,h=(s+r)/2;return a?(o=e===s?(n-i)/a+6*(n<i):n===s?(i-e)/a+2:(e-n)/a+4,a/=h<.5?s+r:2-s-r,o*=60):a=h>0&&h<1?0:o,new pp(o,a,h,t.opacity)}function pp(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function fp(t){return(t=(t||0)%360)<0?t+360:t}function yp(t){return Math.max(0,Math.min(1,t||0))}function mp(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Rd(Ud,ep,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Kd,formatHex:Kd,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return dp(this).formatHsl()},formatRgb:tp,toString:tp}),Rd(sp,rp,Vd(Ud,{brighter(t){return t=null==t?qd:Math.pow(qd,t),new sp(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Ld:Math.pow(Ld,t),new sp(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new sp(lp(this.r),lp(this.g),lp(this.b),hp(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:op,formatHex:op,formatHex8:function(){return`#${up(this.r)}${up(this.g)}${up(this.b)}${up(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:ap,toString:ap})),Rd(pp,function(t,e,n,i){return 1===arguments.length?dp(t):new pp(t,e,n,null==i?1:i)},Vd(Ud,{brighter(t){return t=null==t?qd:Math.pow(qd,t),new pp(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Ld:Math.pow(Ld,t),new pp(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new sp(mp(t>=240?t-240:t+120,r,i),mp(t,r,i),mp(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new pp(fp(this.h),yp(this.s),yp(this.l),hp(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=hp(this.opacity);return`${1===t?"hsl(":"hsla("}${fp(this.h)}, ${100*yp(this.s)}%, ${100*yp(this.l)}%${1===t?")":`, ${t})`}`}}));var gp=t=>()=>t;function xp(t){return 1===(t=+t)?bp:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):gp(isNaN(e)?n:e)}}function bp(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):gp(isNaN(t)?e:t)}var wp=function t(e){var n=xp(e);function i(t,e){var i=n((t=rp(t)).r,(e=rp(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=bp(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=s(e),t.opacity=o(e),t+""}}return i.gamma=t,i}(1);function vp(t,e){e||(e=[]);var n,i=t?Math.min(e.length,t.length):0,r=e.slice();return function(s){for(n=0;n<i;++n)r[n]=t[n]*(1-s)+e[n]*s;return r}}function Mp(t,e){var n,i=e?e.length:0,r=t?Math.min(i,t.length):0,s=new Array(r),o=new Array(i);for(n=0;n<r;++n)s[n]=Pp(t[n],e[n]);for(;n<i;++n)o[n]=e[n];return function(t){for(n=0;n<r;++n)o[n]=s[n](t);return o}}function Sp(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function Ap(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function zp(t,e){var n,i={},r={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?i[n]=Pp(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var _p=/[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,Tp=new RegExp(_p.source,"g");function Bp(t,e){var n,i,r,s=_p.lastIndex=Tp.lastIndex=0,o=-1,a=[],h=[];for(t+="",e+="";(n=_p.exec(t))&&(i=Tp.exec(e));)(r=i.index)>s&&(r=e.slice(s,r),a[o]?a[o]+=r:a[++o]=r),(n=n[0])===(i=i[0])?a[o]?a[o]+=i:a[++o]=i:(a[++o]=null,h.push({i:o,x:Ap(n,i)})),s=Tp.lastIndex;return s<e.length&&(r=e.slice(s),a[o]?a[o]+=r:a[++o]=r),a.length<2?h[0]?function(t){return function(e){return t(e)+""}}(h[0].x):function(t){return function(){return t}}(e):(e=h.length,function(t){for(var n,i=0;i<e;++i)a[(n=h[i]).i]=n.x(t);return a.join("")})}function Pp(t,e){var n,i,r=typeof e;return null==e||"boolean"===r?gp(e):("number"===r?Ap:"string"===r?(n=ep(e))?(e=n,wp):Bp:e instanceof ep?wp:e instanceof Date?Sp:(i=e,!ArrayBuffer.isView(i)||i instanceof DataView?Array.isArray(e)?Mp:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?zp:Ap:vp))(t,e)}function Cp(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function Ep(t){return+t}var kp=[0,1];function Np(t){return t}function Ip(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function Op(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Ip(r,i),s=n(o,s)):(i=Ip(i,r),s=n(s,o)),function(t){return s(i(t))}}function Fp(t,e,n){var i=Math.min(t.length,e.length)-1,r=new Array(i),s=new Array(i),o=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<i;)r[o]=Ip(t[o],t[o+1]),s[o]=n(e[o],e[o+1]);return function(e){var n=Ra(t,e,1,i)-1;return s[n](r[n](e))}}function Rp(){var t,e,n,i,r,s,o=kp,a=kp,h=Pp,l=Np;function u(){var t,e,n,h=Math.min(o.length,a.length);return l!==Np&&(t=o[0],e=o[h-1],t>e&&(n=t,t=e,e=n),l=function(n){return Math.max(t,Math.min(e,n))}),i=h>2?Fp:Op,r=s=null,c}function c(e){return null==e||isNaN(e=+e)?n:(r||(r=i(o.map(t),a,h)))(t(l(e)))}return c.invert=function(n){return l(e((s||(s=i(a,o.map(t),Ap)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,Ep),u()):o.slice()},c.range=function(t){return arguments.length?(a=Array.from(t),u()):a.slice()},c.rangeRound=function(t){return a=Array.from(t),h=Cp,u()},c.clamp=function(t){return arguments.length?(l=!!t||Np,u()):l!==Np},c.interpolate=function(t){return arguments.length?(h=t,u()):h},c.unknown=function(t){return arguments.length?(n=t,c):n},function(n,i){return t=n,e=i,u()}}function Vp(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,i=t.slice(0,n);return[i.length>1?i[0]+i.slice(2):i,+t.slice(n+1)]}function Up(t){return(t=Vp(Math.abs(t)))?t[1]:NaN}var Lp,qp=/^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;function Dp(t){if(!(e=qp.exec(t)))throw new Error("invalid format: "+t);var e;return new Xp({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Xp(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Zp(t,e){var n=Vp(t,e);if(!n)return t+"";var i=n[0],r=n[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}Dp.prototype=Xp.prototype,Xp.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var jp={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Zp(100*t,e),r:Zp,s:function(t,e){var n=Vp(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(Lp=3*Math.max(-8,Math.min(8,Math.floor(r/3))))+1,o=i.length;return s===o?i:s>o?i+new Array(s-o+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+Vp(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Gp(t){return t}var Jp,Wp,Yp,$p=Array.prototype.map,Hp=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Qp(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?Gp:(e=$p.call(t.grouping,Number),n=t.thousands+"",function(t,i){for(var r=t.length,s=[],o=0,a=e[0],h=0;r>0&&a>0&&(h+a+1>i&&(a=Math.max(1,i-h)),s.push(t.substring(r-=a,r+a)),!((h+=a+1)>i));)a=e[o=(o+1)%e.length];return s.reverse().join(n)}),r=void 0===t.currency?"":t.currency[0]+"",s=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?Gp:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}($p.call(t.numerals,String)),h=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var e=(t=Dp(t)).fill,n=t.align,c=t.sign,d=t.symbol,p=t.zero,f=t.width,y=t.comma,m=t.precision,g=t.trim,x=t.type;"n"===x?(y=!0,x="g"):jp[x]||(void 0===m&&(m=12),g=!0,x="g"),(p||"0"===e&&"="===n)&&(p=!0,e="0",n="=");var b="$"===d?r:"#"===d&&/[boxX]/.test(x)?"0"+x.toLowerCase():"",w="$"===d?s:/[%p]/.test(x)?h:"",v=jp[x],M=/[defgprs%]/.test(x);function S(t){var r,s,h,d=b,S=w;if("c"===x)S=v(t)+S,t="";else{var A=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:v(Math.abs(t),m),g&&(t=function(t){t:for(var e,n=t.length,i=1,r=-1;i<n;++i)switch(t[i]){case".":r=e=i;break;case"0":0===r&&(r=i),e=i;break;default:if(!+t[i])break t;r>0&&(r=0)}return r>0?t.slice(0,r)+t.slice(e+1):t}(t)),A&&0===+t&&"+"!==c&&(A=!1),d=(A?"("===c?c:l:"-"===c||"("===c?"":c)+d,S=("s"===x?Hp[8+Lp/3]:"")+S+(A&&"("===c?")":""),M)for(r=-1,s=t.length;++r<s;)if(48>(h=t.charCodeAt(r))||h>57){S=(46===h?o+t.slice(r+1):t.slice(r))+S,t=t.slice(0,r);break}}y&&!p&&(t=i(t,1/0));var z=d.length+t.length+S.length,_=z<f?new Array(f-z+1).join(e):"";switch(y&&p&&(t=i(_+t,_.length?f-S.length:1/0),_=""),n){case"<":t=d+t+S+_;break;case"=":t=d+_+t+S;break;case"^":t=_.slice(0,z=_.length>>1)+d+t+S+_.slice(z);break;default:t=_+d+t+S}return a(t)}return m=void 0===m?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,m)):Math.max(0,Math.min(20,m)),S.toString=function(){return t+""},S}return{format:c,formatPrefix:function(t,e){var n=c(((t=Dp(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(Up(e)/3))),r=Math.pow(10,-i),s=Hp[8+i/3];return function(t){return n(r*t)+s}}}}function Kp(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?Za(e,t,n):Za(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=Dp(null==i?",f":i)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=i.precision||isNaN(r=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Up(e)/3)))-Up(Math.abs(t)))}(s,o))||(i.precision=r),Yp(i,o);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(r=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Up(e)-Up(t))+1}(s,Math.max(Math.abs(t),Math.abs(e))))||(i.precision=r-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(r=function(t){return Math.max(0,-Up(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return Wp(i)}function tf(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const i=e<t,[r,s,o]=i?Xa(e,t,n):Xa(t,e,n);if(!(s>=r))return[];const a=s-r+1,h=new Array(a);if(i)if(o<0)for(let l=0;l<a;++l)h[l]=(s-l)/-o;else for(let l=0;l<a;++l)h[l]=(s-l)*o;else if(o<0)for(let l=0;l<a;++l)h[l]=(r+l)/-o;else for(let l=0;l<a;++l)h[l]=(r+l)*o;return h}(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var i=e();return Kp(i[0],i[i.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var i,r,s=e(),o=0,a=s.length-1,h=s[o],l=s[a],u=10;for(l<h&&(r=h,h=l,l=r,r=o,o=a,a=r);u-- >0;){if((r=Za(h,l,n))===i)return s[o]=h,s[a]=l,e(s);if(r>0)h=Math.floor(h/r)*r,l=Math.ceil(l/r)*r;else{if(!(r<0))break;h=Math.ceil(h*r)/r,l=Math.floor(l*r)/r}i=r}return t},t}function ef(){var t=Rp()(Np,Np);return t.copy=function(){return e=t,ef().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Fd.apply(t,arguments),tf(t)}function nf(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const v=180*mu(t,i)/Math.PI;if(v>e){const M=(s=t,o=(r=i)[0]*th,a=r[1]*th,h=s[0]*th,l=s[1]*th,u=rh(a),c=hh(a),d=rh(l),p=hh(l),f=u*rh(o),y=u*hh(o),m=d*rh(h),g=d*hh(h),x=2*dh(uh(ph(l-a)+u*d*ph(h-o))),b=hh(x),w=x?function(t){var e=hh(t*=x)/b,n=hh(x-t)/b,i=n*f+e*m,r=n*y+e*g,s=n*c+e*p;return[ih(r,i)*Ka,ih(s,uh(i*i+r*r))*Ka]}:function(){return[o*Ka,a*Ka]},w.distance=x,w),S=1/Math.ceil(v/e);let A=S;for(;A<1;)n.push(M(A)),A+=S}}var r,s,o,a,h,l,u,c,d,p,f,y,m,g,x,b,w;n.push(i=t)}),n})}function rf(t,e,n=!1){return n?(r=t,((i=e)&&gu.hasOwnProperty(i.type)?gu[i.type]:bu)(i,r)):sd(t,e);var i,r}function sf(t,e){const n={type:"Polygon",coordinates:t},[[i,r],[s,o]]=Al(n);if(Math.min(Math.abs(s-i),Math.abs(o-r))<e)return[];const a=i>s||o>=89||r<=-89;return function(t,{minLng:e,maxLng:n,minLat:i,maxLat:r}={}){const s=Math.round(h(360/t,2)/Math.PI),o=(1+Math.sqrt(5))/2,a=t=>t/o*360%360-180,l=t=>Math.acos(2*t/s-1)/Math.PI*180-90,u=t=>s*(Math.cos((t+90)*Math.PI/180)+1)/2,c=[void 0!==r?Math.ceil(u(r)):0,void 0!==i?Math.floor(u(i)):s-1],d=void 0===e&&void 0===n?()=>!0:void 0===e?t=>t<=n:void 0===n?t=>t>=e:n>=e?t=>t>=e&&t<=n:t=>t>=e||t<=n,p=[];for(let h=c[0];h<=c[1];h++){const t=a(h);d(t)&&p.push([t,l(h)])}return p}(e,{minLng:i,maxLng:s,minLat:r,maxLat:o}).filter(t=>rf(t,n,a))}function of(t,{resolution:e=1/0,bbox:n,projection:i}={}){const r=nf(t,e),s=Ga(r),o=sf(t,e),a=[...s,...o],h={type:"Polygon",coordinates:t},[[l,u],[c,d]]=Al(h),p=l>c||d>=89||u<=-89;let f=[];if(p){const t=function(t){const e=function(t){if(e.delaunay=null,e._data=t,"object"==typeof e._data&&"FeatureCollection"===e._data.type&&(e._data=e._data.features),"object"==typeof e._data){const t=e._data.map(t=>[e._vx(t),e._vy(t),t]).filter(t=>isFinite(t[0]+t[1]));e.points=t.map(t=>[t[0],t[1]]),e.valid=t.map(t=>t[2]),e.delaunay=Id(e.points)}return e};return e._vx=function(t){return"object"==typeof t&&"type"in t?Fl(t)[0]:0 in t?t[0]:void 0},e._vy=function(t){return"object"==typeof t&&"type"in t?Fl(t)[1]:1 in t?t[1]:void 0},e.x=function(t){return t?(e._vx=t,e):e._vx},e.y=function(t){return t?(e._vy=t,e):e._vy},e.polygons=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const n={type:"FeatureCollection",features:[]};return 0===e.valid.length||(e.delaunay.polygons.forEach((t,i)=>n.features.push({type:"Feature",geometry:t?{type:"Polygon",coordinates:[[...t,t[0]].map(t=>e.delaunay.centers[t])]}:null,properties:{site:e.valid[i],sitecoordinates:e.points[i],neighbours:e.delaunay.neighbors[i]}})),1===e.valid.length&&n.features.push({type:"Feature",geometry:{type:"Sphere"},properties:{site:e.valid[0],sitecoordinates:e.points[0],neighbours:[]}})),n},e.triangles=function(t){return void 0!==t&&e(t),!!e.delaunay&&{type:"FeatureCollection",features:e.delaunay.triangles.map((t,n)=>((t=t.map(t=>e.points[t])).center=e.delaunay.centers[n],t)).filter(t=>Nd(t)>0).map(t=>({type:"Feature",properties:{circumcenter:t.center},geometry:{type:"Polygon",coordinates:[[...t,t[0]]]}}))}},e.links=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const n=e.delaunay.edges.map(t=>mu(e.points[t[0]],e.points[t[1]])),i=e.delaunay.urquhart(n);return{type:"FeatureCollection",features:e.delaunay.edges.map((t,r)=>({type:"Feature",properties:{source:e.valid[t[0]],target:e.valid[t[1]],length:n[r],urquhart:!!i[r]},geometry:{type:"LineString",coordinates:[e.points[t[0]],e.points[t[1]]]}}))}},e.mesh=function(t){return void 0!==t&&e(t),!!e.delaunay&&{type:"MultiLineString",coordinates:e.delaunay.edges.map(t=>[e.points[t[0]],e.points[t[1]]])}},e.cellMesh=function(t){if(void 0!==t&&e(t),!e.delaunay)return!1;const{centers:n,polygons:i}=e.delaunay,r=[];for(const e of i)if(e)for(let t=e.length,i=e[t-1],s=e[0],o=0;o<t;i=s,s=e[++o])s>i&&r.push([n[i],n[s]]);return{type:"MultiLineString",coordinates:r}},e._found=void 0,e.find=function(t,n,i){if(e._found=e.delaunay.find(t,n,e._found),!i||mu([t,n],e.points[e._found])<i)return e._found},e.hull=function(t){void 0!==t&&e(t);const n=e.delaunay.hull,i=e.points;return 0===n.length?null:{type:"Polygon",coordinates:[[...n.map(t=>i[t]),i[n[0]]]]}},t?e(t):e}(a).triangles(),e=new Map(a.map(([t,e],n)=>[`${t}-${e}`,n]));t.features.forEach(t=>{const n=t.geometry.coordinates[0].slice(0,3).reverse(),i=[];if(n.forEach(([t,n])=>{const r=`${t}-${n}`;e.has(r)&&i.push(e.get(r))}),3===i.length){if(i.some(t=>t<s.length)){if(!rf(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=$c.from(a);for(let e=0,n=t.triangles.length;e<n;e+=3){const n=[2,1,0].map(n=>t.triangles[e+n]),i=n.map(t=>a[t]);if(n.some(t=>t<s.length)){if(!rf([0,1].map(t=>ja(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=Vc(r);f=dc(t,e,2)}let y=n?[n[0],n[2]]:Va(a,t=>t[0]),m=n?[n[1],n[3]]:Va(a,t=>t[1]);if(i){const[t,e]=i([y[0],m[0]]),[n,r]=i([y[1],m[1]]);y=[t,n],m=[-e,-r]}const g=ef(y,[0,1]),x=ef(m,[0,1]),b=a.map(([t,e])=>{if(i){const[n,r]=i([t,e]);return[g(n),x(-r)]}return[g(t),x(e)]});return{contour:r,triangles:{points:a,indices:f,uvs:b}}}Jp=Qp({thousands:",",grouping:[3],currency:["$",""]}),Wp=Jp.format,Yp=Jp.formatPrefix;const af=(new Re).setAttribute?"setAttribute":"addAttribute";function hf(t,e,n){return Vc(t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=ka(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=ka(t,i,e,1/Ca,!0);return[n.x,n.y,n.z]}if("function"==typeof n){const[r,s]=n([t,i]);return[r,-s,e]}return[t,i,e]})))}function lf(t,e,n,i,r){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:hf([t.points],e,r).vertices,uvs:n}}const uf=({polygonGeoJson:t,startHeight:e,endHeight:n,curvatureResolution:i=1,hasSide:r=!0,hasBottom:s=!1,hasTop:o=!1,projection:a="sphere",bbox:h})=>{t.forEach(t=>{cc(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:u,triangles:c}=of(t,{resolution:i,bbox:h,projection:l});let d,p={};r&&(p=function(t,e,n,i){const{vertices:r,holes:s}=hf(t,e,i),{vertices:o}=hf(t,n,i),a=Ga([o,r]),h=Math.round(o.length/3),l=new Set(s);let u=0;const c=[];for(let p=0;p<h;p++){let t=p+1;if(t===h)t=u;else if(l.has(t)){const e=t;t=u,u=e}c.push(p,p+h,t+h),c.push(t+h,t,p)}const d=[];for(let p=1;p>=0;p--)for(let t=0;t<h;t+=1)d.push(t/(h-1),p);return{indices:c,vertices:a,uvs:d,topVerts:o}}(u,null!=e?e:n,null!=n?n:e,a),d=p.topVerts);let f=[];(s||o)&&(f=Ga(c.uvs));let y={};s&&(y=lf(c,e,f,!1,a));let m={};return o&&(m=lf(c,n,f,!0,a)),{contour:u,triangles:c,sideTorso:p,bottomCap:y,topCap:m,topVerts:d}};class cf extends Re{constructor(t,e={}){super(),this.type="PolygonBufferGeometry",this.parameters=u(u({},{polygonGeoJson:t,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,projection:"sphere",resetCenter:!1}),e);const{hasTop:n,topFirst:i,hasBottom:r,hasSide:s}=this.parameters,{sideTorso:o,bottomCap:a,topCap:h}=uf(u({},this.parameters));let l=[],c=[],d=[],p=0;const f=t=>{const e=Math.round(l.length/3),n=d.length;l=l.concat(t.vertices),c=c.concat(t.uvs),d=d.concat(e?t.indices.map(t=>t+e):t.indices),this.addGroup(n,d.length-n,p++)};n&&i&&f(h),s&&f(o),r&&f(a),n&&!i&&f(h),this.parameters.resetCenter&&l.length>0&&(this.userData.rtcPositionsVertices=new _e(new Float64Array(l),3)),this.setIndex(d),this[af]("position",new Pe(l,3)),this[af]("uv",new Pe(c,2)),this.computeVertexNormals()}}function df(t){return Object.getOwnPropertyNames(t).reduce(function(e,n){return Object.defineProperty(e,n,{value:t[n],enumerable:!0})},{})}(t=>{const e={run(t,e){const n=new Function("return ("+t+").apply(null, arguments);");return n.apply(n,e)},methods:()=>Object.keys(e)};addEventListener("message",t=>((t,e,n)=>new Promise((i,r)=>{var s=t=>{try{a(n.next(t))}catch(e){r(e)}},o=t=>{try{a(n.throw(t))}catch(e){r(e)}},a=t=>t.done?i(t.value):Promise.resolve(t.value).then(s,o);a((n=n.apply(t,e)).next())}))(void 0,[t],function*({data:t}){try{const n=e[t.method];if(!n)throw new Error(\'Unknown method "\'+t.method+\'"\');{const e=yield n.apply(n,t.params);e.transfer&&e.message?postMessage({id:t.id,result:e.message,error:null},e.transfer):postMessage({id:t.id,result:e,error:null})}}catch(n){postMessage({id:t.id,result:null,error:df(n)})}})),Object.keys(t).forEach(n=>{e[n]=t[n]}),postMessage("ready")})({extrudePolygon:({coordinates:t,lengths:e,metaLength:n,split:i,bbox:r,projection:s,useGroups:o,hasTop:a,hasBottom:h,hasSide:l,splitPolygons:d,topSegments:p})=>{const f=s&&nc(s),{coordinatesArr:y,metaArray:m}=oc({coordinates:t,lengths:e,metaLength:n});let g,x=y.map(t=>sc(t,f)),b=m;if(d){const t=hc(x,d,m);x=t.splitPolygons,b=t.splitMeta}if(r){const t=-180===r[0]&&180===r[2]&&(null==s?void 0:s.rotate),[e,n]=function(t,e,n=0){const[i,r,s,o]=t;let a=1/0,h=1/0,l=-1/0,u=-1/0;for(let c=0;c<=n;c++){const t=n&&c/n;sc([[i+t*(s-i),r],[i+t*(s-i),o],[i,r+t*(o-r)],[s,r+t*(o-r)]],e).forEach(t=>{a=Math.min(a,t.x),h=Math.min(h,t.y),l=Math.max(l,t.x),u=Math.max(u,t.y)})}return[[a,h],[l,u]]}(r,t?nc(c(u({},s),{rotate:void 0})):f,"winkel3"===(null==s?void 0:s.projectionType)?10:0);g=new K(new N(e[0],e[1],0),new N(n[0],n[1],0))}const w=x.map((t,e)=>{const n=b[e][0],r=b[e][1]||0,s=b[e][2]||1,o=Pa({points:t,split:i,sideRepeat:s,depth:n,hasTop:a,hasBottom:h,hasSide:l,box3:g,topSegments:p});if(r){const t=o.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+r);t.needsUpdate=!0}return o});return ac(w,o)},line:({coordinates:t,lengths:e,metaLength:n,projection:i,useGroups:r,splitPolygons:s})=>{const o=i&&nc(i),{coordinatesArr:a,metaArray:h}=oc({coordinates:t,lengths:e,metaLength:n});let l=a.map(t=>sc(t,o)),u=h;if(s){const t=hc(l,s,u);l=t.splitPolygons,u=t.splitMeta}const c=l.map((t,e)=>{const n=u[e][0]||1;return uc({nodes:t,setPointWidth:()=>n})});return ac(c,r)},line2:({coordinates:t,lengths:e,metaLength:n,projection:i,useGroups:r,splitPolygons:s})=>{const o=i&&nc(i),{coordinatesArr:a,metaArray:h}=oc({coordinates:t,lengths:e,metaLength:n});let l=a.map(t=>sc(t,o));if(s){l=hc(l,s,h).splitPolygons}const u=l.map((t,e)=>(t=>{const{points:e}=t,n=e.reduce((t,n,i)=>(i<e.length-1&&t.push(n,e[i+1]),t),[]);return(new Re).setFromPoints(n)})({points:t.map(t=>new N(t.x,t.y,0))}));return ac(u,r)},conicPolygon:({coordinates:t,lengths:e,metaLength:n,useGroups:i,hasTop:r,topFirst:s,hasBottom:o,hasSide:a,rtc:h,projection:l,curvatureResolution:p,bbox:f})=>{let y;y=l&&"object"==typeof l?nc(l):l||"sphere";const{coordinatesArr:m,metaArray:g}=oc({coordinates:t,lengths:e,metaLength:n}),x=m.map((t,e)=>{const n=g[e][0],i=g[e][1]||0;return(t=>{const e=t,{coordinate:n,startHeight:i,height:r}=e,s=d(e,["coordinate","startHeight","height"]);let o=i||0;return void 0!==i&&void 0!==r&&(o=i+r),new cf([n],c(u({},s),{startHeight:i,endHeight:o}))})({coordinate:t,projection:y,startHeight:i,height:n,hasTop:null==r||r,topFirst:null!=s&&s,hasBottom:null==o||o,hasSide:null==a||a,curvatureResolution:null!=p?p:1,bbox:f,resetCenter:null!=h&&h})});return ac(x,i,null!=h&&h)},conicLine:({coordinates:t,lengths:e,metaLength:n,useGroups:i,projection:r="sphere",rtc:s})=>{const{coordinatesArr:o,metaArray:a}=oc({coordinates:t,lengths:e,metaLength:n}),h=o.map((t,e)=>{const n=a[e][1]||0;return uf({polygonGeoJson:[t],startHeight:n,projection:r}).topVerts}).map((t,e)=>{const n=a[e][0];return uc({nodes:t,setPointWidth:()=>n,resetCenter:null!=s&&s})});return ac(h,i,null!=s&&s)}})}();\n',ur="undefined"!=typeof self&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",cr],{type:"text/javascript;charset=utf-8"});function dr(t){let e;try{if(e=ur&&(self.URL||self.webkitURL).createObjectURL(ur),!e)throw"";const n=new Worker(e,{name:null==t?void 0:t.name});return n.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),n}catch(n){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(cr),{name:null==t?void 0:t.name})}}class pr{constructor(t){u(this,"pluginName","worker"),u(this,"options"),u(this,"pencil"),u(this,"pool"),u(this,"bufferGeometryLoader",new It),u(this,"cacheManager"),this.options=h({dbName:"pencil_cache",cacheVersion:"1",maxCacheSize:100},t),this.cacheManager=new un({dbName:this.options.dbName,maxCacheSize:this.options.maxCacheSize,cacheVersion:this.options.cacheVersion})}install(t){this.pencil=t;const e=new Ie(dr,{maxWorkers:this.options.maxWorkers});this.pool=e}geoGeometry(t,e){return d(this,null,function*(){const{mesaage:n,coordinatesArr:i,metaArray:s,cacheKey:r,userData:o,cacheVersion:a,cb:l,useFloat64Array:c}=h(h({},this.options),e),u=this.pool,{flat:d,lengths:p}=this.flattenCoordinates(i,s,c),{err:f,res:m}=yield u.exec(t,[h({coordinates:d,lengths:p,metaLength:s?s[0].length:0},n)],{on:()=>{},transfer:[d.buffer]},!0);if(f)throw f;const y=lr(m);return Object.assign(y.userData,h({},o)),l&&(yield l(y)),r&&this.cacheManager.addToCache(r,a,h({attributes:m},o)),y})}getCachedGeometry(t){return d(this,null,function*(){const{cacheKey:e,cacheVersion:n}=t;if(e){const t=yield this.cacheManager.get(e,n);return t&&Array.isArray(t)?(this.cacheManager.recordMetadataUpdate(e,t.length),t.map(t=>{const e=t,{attributes:n}=e,i=c(e,["attributes"]),s=lr(n);return Object.assign(s.userData,h({},i)),s})):[]}return[]})}saveCache(){return d(this,null,function*(){return yield this.cacheManager.saveCache()})}flushMetadata(){return d(this,null,function*(){return yield this.cacheManager.flushMetadata()})}getCacheStats(){return d(this,null,function*(){return yield this.cacheManager.getCacheStats()})}clearCache(){return d(this,null,function*(){return yield this.cacheManager.clearCache()})}checkStorageQuota(){return d(this,null,function*(){return yield this.cacheManager.checkStorageQuota()})}flattenCoordinates(t,e,n=!1){const i=[];let s=0;for(const h of t){const t=h.length;i.push(t),s+=t}const r=e?e.reduce((t,e)=>t+e.length,0):0,o=n?new Float64Array(2*s+r):new Float32Array(2*s+r);let a=0;for(const h of t)for(const[t,e]of h)o[a++]=t,o[a++]=e;if(e)for(const h of e)for(const t of h)o[a++]=t;return{flat:o,lengths:i}}dispose(){this.cacheManager.dispose(),this.pool.dispose(),this.pool.workers.length=0}}const fr=Us.ACTION;export{Ln as BaseObject,Zn as ConicPolygon,Yn as Ellipsoid,Qn as ExtrudePolygon,ei as Group,ni as Light,ci as Line,Ei as Line2,Gt as Line2Material,$t as LineSegmentsGeometry,ii as MeshLineGeometry,ri as MeshLineMaterial,oi as MeshLineRaycast,Pi as Node,ar as Pencil,Ni as Pie,Ke as ResourceTracker,pr as Wk,fr as cameraControlsAction,ar as default,hr as effect,ti as getSplitTexture,Nn as utils};
|