gl-draw 0.18.1 → 0.18.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 v,Object3D as b,Texture as w,Sphere as _,Ray as M,BufferGeometry as S,Float32BufferAttribute as A,PointsMaterial as T,Points as C,NoColorSpace as O,SRGBColorSpace as z,LinearSRGBColorSpace as E,MathUtils as P,Vector2 as j,InstancedMesh as k,Quaternion as R,Box3 as B,Sprite as L,Group as U,Mesh as D,AmbientLight as N,DirectionalLight as F,PointLight as I,SpotLight as V,HemisphereLight as W,RectAreaLight as H,MeshStandardMaterial as q,BufferAttribute as G,Shape as Z,ShapeUtils as X,SplineCurve as $,QuadraticBezierCurve3 as Y,QuadraticBezierCurve as J,LineCurve3 as K,LineCurve as Q,EllipseCurve as tt,CubicBezierCurve3 as et,CubicBezierCurve as nt,CatmullRomCurve3 as it,ArcCurve as st,PlaneGeometry as rt,ShaderMaterial as ot,Color as at,LineSegments as ht,MeshBasicMaterial as lt,UniformsUtils as ct,RawShaderMaterial as ut,SpriteMaterial as dt,WebGLRenderTarget as pt,HalfFloatType as ft,Layers as mt,Raycaster as yt,Spherical as gt,Vector4 as xt,AxesHelper as vt,CameraHelper as bt,PointLightHelper as wt,DirectionalLightHelper as _t,SpotLightHelper as Mt,HemisphereLightHelper as St,Box3Helper as At,ImageUtils as Tt,ObjectLoader as Ct,VideoTexture as Ot,DataTexture as zt,Scene as Et,Camera as Pt,FileLoader as jt,Loader as kt,LoadingManager as Rt,TextureLoader as Bt,WebGLRenderer as Lt,REVISION as Ut,Timer as Dt}from"three";import Nt from"three/examples/jsm/libs/tween.module.js";import{EffectComposer as Ft}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as It}from"three/examples/jsm/postprocessing/RenderPass.js";import{SSAOPass as Vt}from"three/examples/jsm/postprocessing/SSAOPass.js";import{UnrealBloomPass as Wt}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";import{LineMaterial as Ht}from"three/examples/jsm/lines/LineMaterial.js";import{LineSegmentsGeometry as qt}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{RectAreaLightUniformsLib as Gt}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{CSS2DObject as Zt,CSS2DRenderer as Xt}from"three/examples/jsm/renderers/CSS2DRenderer.js";import{CSS3DObject as $t,CSS3DSprite as Yt,CSS3DRenderer as Jt}from"three/examples/jsm/renderers/CSS3DRenderer.js";import{createStore as Kt,getMany as Qt,setMany as te,keys as ee,delMany as ne,get as ie,clear as se}from"idb-keyval";import{geoProjection as re,geoEquirectangular as oe,geoMercator as ae,geoBounds as he,geoContains as le,geoDistance as ce,geoInterpolate as ue}from"d3-geo";import de from"@turf/boolean-clockwise";import{merge as pe,mean as fe,extent as me}from"d3-array";import ye,{flatten as ge}from"earcut";import xe from"delaunator";import ve from"@turf/boolean-point-in-polygon";import{geoVoronoi as be}from"d3-geo-voronoi";import{scaleLinear as we}from"d3-scale";import{mergeGeometries as _e,mergeGroups as Me}from"three/examples/jsm/utils/BufferGeometryUtils.js";import{Brush as Se,Evaluator as Ae,INTERSECTION as Te}from"three-bvh-csg";import{ShaderPass as Ce}from"three/examples/jsm/postprocessing/ShaderPass.js";import{OutputPass as Oe}from"three/examples/jsm/postprocessing/OutputPass.js";import{FullScreenQuad as ze}from"three/examples/jsm/postprocessing/Pass.js";import{RectAreaLightHelper as Ee}from"three/examples/jsm/helpers/RectAreaLightHelper.js";import{ViewHelper as Pe}from"three/examples/jsm/helpers/ViewHelper.js";import{generateUUID as je,makePromiseCreator as ke,WorkerPool as Re}from"esus-lite";import{DRACOLoader as Be}from"three/examples/jsm/loaders/DRACOLoader.js";import{EXRLoader as Le}from"three/examples/jsm/loaders/EXRLoader.js";import{GLTFLoader as Ue}from"three/examples/jsm/loaders/GLTFLoader.js";import{LottieLoader as De}from"three/examples/jsm/loaders/LottieLoader.js";import{TransformControls as Ne}from"three/examples/jsm/controls/TransformControls.js";const Fe=!1;class Ie{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 Ve{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 Ie;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 We={fov:45,near:1,far:1e3,up:new y(0,1,0)};class He extends Ve{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=We,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),e.matrixWorld.decompose(e.position,e.quaternion,e.scale))}}update(t,e){-1===this._lastFov&&this.camera.updateMatrixWorld()}}class qe{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 v)return t;if(t instanceof Cn?(t.object3d&&this.track(t.object3d),Object.values(t.materialList).map(t=>this.track(t))):(t instanceof b||Reflect.has(t,"dispose"))&&this.resources.add(t),t instanceof b){const e=t;this.track(e.geometry),this.track(e.material)}else if(t instanceof v){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(){for(const t of this.resources)t instanceof HTMLVideoElement&&t.pause(),Reflect.has(t,"dispose")&&t.dispose();this.resources.clear()}}const Ge=/* @__PURE__ */new g,Ze=/* @__PURE__ */new M,Xe=/* @__PURE__ */new _,$e=/* @__PURE__ */new y;function Ye(t,e){const n=this.geometry,i=this.matrixWorld,s=t.params.Points.threshold,r=n.drawRange;null===n.boundingSphere&&n.computeBoundingSphere(),Xe.copy(n.boundingSphere),Xe.applyMatrix4(i),Xe.radius+=s,Ge.copy(i).invert(),Ze.copy(t.ray).applyMatrix4(Ge);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);$e.fromBufferAttribute(h,s),Je($e,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++)$e.fromBufferAttribute(h,n),Je($e,n,o,i,t,e,this)}}function Je(t,e,n,i,s,r,o){const a=new y;Ze.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 Ke=class t{constructor(t){u(this,"uuidToObject",/* @__PURE__ */new Map),u(this,"uuidToMaterial",/* @__PURE__ */new Map),u(this,"uuidToTexture",/* @__PURE__ */new Map),u(this,"uuidToImage",/* @__PURE__ */new Map),this._traceObjects(t.object),this._traceMaterials(t.materials),this._traceTextures(t.textures)}resolve(t){var e,n,i,s;return null!=(s=null!=(i=null!=(n=null!=(e=this.uuidToObject.get(t))?e:this.uuidToMaterial.get(t))?n:this.uuidToTexture.get(t))?i:this.uuidToImage.get(t))?s:t}formatRemap(t){const e=[];for(const[n,i]of t)e.push(` ${this.resolve(n)} => ${this.resolve(i)}`);return e}_traceObjects(t,e=""){var n,i,s,r;if(!t)return;let o="";o=(null==(n=t.userData)?void 0:n._mListFixKey)?`mlist(${t.userData._mListFixKey})`:(null==(i=t.userData)?void 0:i._baseObjectKey)?t.userData._baseObjectKey:t.name?t.name:t.type||"Object3D";const a=e?`${e} -> ${o}`:o;if(this.uuidToObject.set(t.uuid,a),t.geometry){const e=void 0!==(null==(s=t.userData)?void 0:s._mListFixKey),n=`Geometry in [${a}]`,i=this.uuidToObject.get(t.geometry);(!i||e&&!i.includes("mlist("))&&this.uuidToObject.set(t.geometry,n)}if(t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const n of e){const e=void 0!==(null==(r=t.userData)?void 0:r._mListFixKey),i=`Material in [${a}]`,s=this.uuidToMaterial.get(n);(!s||e&&!s.includes("mlist("))&&this.uuidToMaterial.set(n,i)}}if(t.children)for(const h of t.children)this._traceObjects(h,a)}_traceMaterials(e){if(e)for(const n of e){const e=n.name?`"${n.name}"`:n.type,i=this.uuidToMaterial.get(n.uuid)||`Unused Material ${e}`;for(const s of t._mapTypes)n[s]&&this.uuidToTexture.set(n[s],`Texture(${s}) in ${i}`)}}_traceTextures(t){if(t)for(const e of t){const t=e.name?`"${e.name}"`:"Tex",n=this.uuidToTexture.get(e.uuid)||`Unused Texture ${t}`;e.image&&this.uuidToImage.set(e.image,`Image for ${n}`)}}};u(Ke,"_mapTypes",["map","normalMap","bumpMap","roughnessMap","metalnessMap","emissiveMap","envMap","lightMap","aoMap","alphaMap","displacementMap"]);let Qe=Ke;const tn={linearSRGB:E,sRGB:z,none:O},en={map:tn.sRGB,emissiveMap:tn.sRGB,sheenColorMap:tn.sRGB,specularColorMap:tn.sRGB,normalMap:tn.none,bumpMap:tn.none,displacementMap:tn.none,roughnessMap:tn.none,metalnessMap:tn.none,aoMap:tn.none,lightMap:tn.none,alphaMap:tn.none,specularIntensityMap:tn.none,clearcoatMap:tn.none,clearcoatNormalMap:tn.none,clearcoatRoughnessMap:tn.none,iridescenceMap:tn.none,iridescenceThicknessMap:tn.none,sheenRoughnessMap:tn.none,specularMap:tn.none,thicknessMap:tn.none,transmissionMap:tn.none},nn=[".hdr",".exr",".rgbe"];function sn(t){return function(t){var e;if(t.userData&&"boolean"==typeof t.userData.isHDR)return t.userData.isHDR;if(t.colorSpace===E)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 nn.some(t=>n.toLowerCase().includes(t))}(t)?tn.linearSRGB:tn.sRGB}function rn({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(en).forEach(e=>{const n=t;n[e]&&(n[e].colorSpace=en[e])});const e=t;e.envMap&&(e.envMap.colorSpace=sn(e.envMap))}(t))}class on{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=Kt(t.dbName,"keyval"),this.metadataStore=Kt(`${t.dbName}_metadata`,"keyval")}addToCache(t,e){const n=this.options.cacheVersion;this.cacheObj[t]||(this.cacheObj[t]={}),this.cacheObj[t][n]||(this.cacheObj[t][n]=e)}recordMetadataUpdate(t,e=1){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 Qt(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};n.push([s,a])}yield te(n,this.metadataStore),this.pendingMetadataUpdates.clear()})}evictLRUCache(){return d(this,null,function*(){const t=yield ee(this.store);if(t.length>=this.options.maxCacheSize){const e=yield Qt(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 ne(s,this.store),yield ne(s,this.metadataStore)}})}get(t){return d(this,null,function*(){const e=yield ie(t,this.store),n=this.options.cacheVersion;return null==e?void 0:e[n]})}saveCache(){return d(this,null,function*(){var t;try{yield this.flushMetadata(),yield this.evictLRUCache();const t=Object.entries(this.cacheObj);if(0===t.length)return;yield te(t,this.store);const e=t.map(([t])=>t),n=yield Qt(e,this.metadataStore),i=[];for(let s=0;s<t.length;s++){const[e]=t[s],r=n[s],o={lastAccessed:Date.now(),accessCount:r?r.accessCount+1:1};i.push([e,o])}yield te(i,this.metadataStore),this.cacheObj={}}catch(e){if("QuotaExceededError"!==e.name&&!(null==(t=e.message)?void 0:t.includes("NO_SPACE")))throw e;console.error("存储空间不足,尝试清理旧缓存..."),yield this.clearCache()}})}getCacheStats(){return d(this,null,function*(){const t=yield ee(this.store),e={total:t.length,maxSize:this.options.maxCacheSize,usage:t.length/this.options.maxCacheSize*100,items:[]},n=yield Qt(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 se(this.store),yield se(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 an={a:6378137,b:6356752.314245179,f:1/298.257223563};function hn(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=n*i;u=t*a*c,d=t*h,p=t*a*l}else{const t=an.a,e=an.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 ln=Math.abs,cn=Math.cos,un=Math.sin,dn=1e-6,pn=Math.PI,fn=pn/2;function mn(t){return t>1?0:t<-1?pn:Math.acos(t)}function yn(t){return t>0?Math.sqrt(t):0}function gn(t,e){var n=cn(e),i=function(t){return t?t/Math.sin(t):1}(mn(n*cn(t/=2)));return[2*n*un(t)*i,un(e)*i]}function xn(t,e){var n=gn(t,e);return[(n[0]+t/fn)/2,(n[1]+e)/2]}xn.invert=(t,e)=>{var n=t,i=e,s=25;do{var r,o=cn(i),a=un(i),h=un(2*i),l=a*a,c=o*o,u=un(n),d=cn(n/2),p=un(n/2),f=p*p,m=1-c*d*d,y=m?mn(o*d)*yn(r=1/m):r=0,g=.5*(2*y*o*p+n/fn)-t,x=.5*(y*a+i)-e,v=.5*r*(c*f+y*o*d*l)+.5/fn,b=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=b*w-_*v,S=(x*b-g*_)/M,A=(g*w-x*v)/M;n-=S,i-=A}while((ln(S)>dn||ln(A)>dn)&&--s>0);return[n,i]};const vn={mercator:ae,equirectangular:oe,winkel3:function(){return re(xn).scale(158.837)}},bn=t=>{var e,n,i;const s=vn[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),s};function wn(t){return"[object Object]"===Object.prototype.toString.call(t)}function _n(t){if(!1===wn(t))return!1;const e=t.constructor;if(void 0===e)return!0;const n=e.prototype;return!1!==wn(n)&&!1!==n.hasOwnProperty("isPrototypeOf")}const Mn=t=>(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 j?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)})([t])[0],Sn={applyTextureColorSpace:rn,analyzeSceneJsonSize:function(t){const e=t=>{const e=new Blob([JSON.stringify(t)]).size;return{bytes:e,mbStr:(e/1024/1024).toFixed(3)+" MB"}};console.groupCollapsed("🔍 Scene JSON Size Analysis");const n=e(t);console.log("Total Size:",n.mbStr);const i=new Qe(t),{uuidToObject:s,uuidToMaterial:r,uuidToTexture:o,uuidToImage:a}=i;if(t.images){const e=t.images.filter(t=>!t.url||""===t.url);e.length>0&&(console.warn(`⚠️ Found ${e.length} image(s) with empty url:`),e.forEach((t,e)=>{const n=a.get(t.uuid)||"Unknown (unused image)";console.warn(` ${e+1}. uuid: ${t.uuid}`),console.warn(` ← ${n}`)}))}if(["geometries","materials","textures","images"].forEach(n=>{const i=t[n];if(i&&i.length>0){const t=e(i);if(console.log(`📦 ${n} (${i.length} items):`,t.mbStr),t.bytes>102400){const t=i.map(t=>{let i="Unknown";return"geometries"===n?i=s.get(t.uuid)||"Unknown":"materials"===n?i=r.get(t.uuid)||"Unknown":"textures"===n?i=o.get(t.uuid)||"Unknown":"images"===n&&(i=a.get(t.uuid)||"Unknown"),{uuid:t.uuid,type:t.type,name:t.name,usedBy:i,size:e(t)}}).sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10);console.log(` Top 10 largest ${n}:`),t.forEach((t,e)=>{console.log(` ${e+1}. [${t.type||"Item"}] ${t.name||t.uuid.substring(0,8)}...: ${t.size.mbStr} (Used by: ${t.usedBy})`)})}}}),t._sharedOptionsPool){const n=t._sharedOptionsPool,i=e(n);if(console.log(`🔗 _sharedOptionsPool (${n.length} entries):`,i.mbStr),i.bytes>102400){const t=n.map((t,n)=>({index:n,size:e(t)})).sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10);console.log(" Top 10 largest pool entries:"),t.forEach((t,e)=>{console.log(` ${e+1}. pool[${t.index}]: ${t.size.mbStr}`)})}const s=/* @__PURE__ */new Map,r=t=>{var e;const n=null==(e=null==t?void 0:t.userData)?void 0:e._baseObjectOptions;if(n)for(const i of Object.keys(n)){const t=n[i];t&&"object"==typeof t&&"_sharedRef"in t&&s.set(t._sharedRef,(s.get(t._sharedRef)||0)+1)}(null==t?void 0:t.children)&&t.children.forEach(r)};if(r(t.object),s.size>0){const t=[...s.values()].reduce((t,e)=>t+e,0),e=t-s.size;console.log(` ${n.length} unique entries, ${t} total references, ${e} duplicates eliminated`)}}if(t.object){console.log("🌳 object graph (structure):",e(t.object).mbStr);const n=[];let i=0,s=0;const r=t=>{if(t.userData&&t.userData._baseObjectOptions){const r=t.userData._baseObjectOptions,o=e(r);i+=o.bytes;for(const t of Object.keys(r)){const e=r[t];e&&"object"==typeof e&&"_sharedRef"in e&&s++}o.bytes>1024&&n.push({key:t.userData._baseObjectKey||t.name||t.uuid,type:t.userData._baseObjectObjectType||t.type,size:o})}t.children&&t.children.forEach(r)};if(r(t.object),i>0&&(console.log("⚙️ userData._baseObjectOptions total size:",(i/1024/1024).toFixed(3)+" MB",s>0?`(${s} fields extracted to shared pool)`:""),i>102400&&n.length>0)){console.log(" Top 10 largest options:");n.sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10).forEach((t,e)=>{console.log(` ${e+1}. [${t.type}] ${t.key}: ${t.size.mbStr}`)})}}console.groupEnd()},CacheManager:on,cartographicToCartesian:hn,WGS84:an,getProjection:bn,isPlainObject:_n,parseVector2:t=>t instanceof j?t:new j(...t),parseVector3:Mn,SceneJsonRefTracer:Qe};let An=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 Tn extends An{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 Cn extends Tn{constructor(t){super(),u(this,"key",""),u(this,"objectType","BaseObject"),u(this,"options"),u(this,"_keyType",""),u(this,"uuid",""),u(this,"object3d"),u(this,"userData",{}),u(this,"isPrefab",!1),u(this,"isInstantiate",!1),u(this,"isBloom",!1),u(this,"isBaseObject",!0),u(this,"isDispose",!1),this.object3d=t}get name(){return this.object3d.name}set name(t){this.object3d.name=t}get keyType(){return this._keyType||this.objectType}set keyType(t){this._keyType=t}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[0]instanceof y?t[0]:new y(...t);this.object3d.lookAt(e)}draw(t,...e){return this.lead.draw({target:this},t,...e)}drawPrefab(t,...e){return this.lead.draw({target:this,prefab:!0},t,...e)}add(...t){t.forEach(t=>{const e=t instanceof Cn?t:this.lead.wrap(t);this.object3d.add(e.object3d)})}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(){}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()}))}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,i;const s=null==(e=null==t?void 0:t.recursive)||e,r=null!=(n=null==t?void 0:t.cloneMaterial)&&n;let o;if(null==(i=null==t?void 0:t.instancedAttr)?void 0:i.length){const e=t.instancedAttr.length;if(this.object3d instanceof L)o=((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=Ye,r})(this.object3d,e);else{const t=this.object3d,n=r?this.cloneMaterial():t.material;o=new k(t.geometry,n,e)}((t,e)=>{const n=new b;e.forEach((e,i)=>{const s=Mn(e.position),r=Mn(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 R,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}})})(o,null==t?void 0:t.instancedAttr)}else{o=this.object3d.clone(!1);const t=o;r&&t.material&&(Array.isArray(t.material)?t.material=t.material.map(t=>t.clone()):t.material=t.material.clone())}o.userData.prefab&&delete o.userData.prefab;const a=this.constructor;let h;try{h=this.options?new a(this.options):new a(o),h.object3d!==o&&(h.object3d=o)}catch(c){console.warn(`[BaseObject] Instantiate failed for ${this.objectType}, fallback to BaseObject wrapper.`),h=new Cn(o)}h.objectType=this.objectType,h.keyType=this._keyType;let l=(null==t?void 0:t.target)||this.parent||this.lead.group;return l===this.lead.prefabGroup&&(l=this.lead.group),h.isInstantiate=!0,yield this.lead.add(h,l),this.isBloom&&h.enableBloom(),s&&(yield Promise.all(this.children.map(t=>d(this,null,function*(){(yield t.instantiate({cloneMaterial:r,target:h,recursive:!0})).setKey({uuid:h.uuid,syncParentUuid:!0})})))),h})}erase(){this.lead.erase(this)}setKey(t){t.syncParentUuid&&(this.userData.syncParentUuid=!0),this.lead.updateBaseObjectKey(this,t)}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)return;this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),null==(t=this.pencil.composerController)||t.checkBloomComposerActive()),null==(e=this.lead)||e.disableCursor(this);const n=new qe;n.disposeMaterial=!1,n.track(this),n.dispose()}}class On extends Cn{constructor(t=new U){super(t),u(this,"objectType","Group")}render(){this.object3d.raycast=(t,e)=>t.intersectObjects(this.object3d.children,!0,e)}}class zn extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","Mesh"),this);n(t instanceof D?t:new D(t,e))}}class En extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","Points"),this);n(t instanceof C?t:new C(t,e))}}class Pn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","Sprite"),this);e(t instanceof L?t:new L(t))}}class jn extends Cn{constructor(t,e,n){var i=(...t)=>(super(...t),u(this,"objectType","InstancedMesh"),this);i(t instanceof k?t:new k(t,e,n))}}class kn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS2DObject"),this);e(t instanceof Zt?t:new Zt(null!=t?t:document.createElement("div")))}}class Rn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS3DObject"),this);e(t instanceof $t?t:new $t(null!=t?t:document.createElement("div")))}}class Bn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS3DSprite"),this);e(t instanceof Yt?t:new Yt(null!=t?t:document.createElement("div")))}}class Ln extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","AmbientLight"),this);if(t instanceof N)n(t);else{const i=new N(t,e);i.name="环境光",n(i)}}}class Un extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","DirectionalLight"),this);if(t instanceof F)n(t);else{const i=new F(t,e);i.name="平行光",i.target.position.set(0,0,0),i.target.name="平行光目标",i.shadow.camera.name="平行光阴影相机",i.shadow.camera.userData.directionalLightShadow=!0,n(i)}}render(){if(!this.object3d.target.parent){this.parent.add(this.object3d.target);this.lead.objMap.get(this.object3d.target).userData.isLightTarget=!0}}dispose(){const t=this.lead.objMap.get(this.object3d.target);null==t||t.erase(),super.dispose()}}class Dn extends Cn{constructor(t,e,n,i){var s=(...t)=>(super(...t),u(this,"objectType","PointLight"),this);if(t instanceof I)s(t);else{const r=new I(t,e,n,i);r.name="点光源",s(r)}}}class Nn extends Cn{constructor(t,e,n,i,s,r){var o=(...t)=>(super(...t),u(this,"objectType","SpotLight"),this);if(t instanceof V)o(t);else{const a=new V(t,e,n,null!=i?i:Math.PI/3,null!=s?s:1,null!=r?r:2);a.name="聚光灯",a.target.name="聚光灯目标",o(a)}}render(){if(!this.object3d.target.parent){this.parent.add(this.object3d.target);this.lead.objMap.get(this.object3d.target).userData.isLightTarget=!0}}dispose(){const t=this.lead.objMap.get(this.object3d.target);null==t||t.erase(),super.dispose()}}class Fn extends Cn{constructor(t,e,n){var i=(...t)=>(super(...t),u(this,"objectType","HemisphereLight"),this);if(t instanceof W)i(t);else{const s=new W(t,e,n);s.name="半球光",i(s)}}}const In=class t extends Cn{constructor(e,n,i,s){var r=(...t)=>(super(...t),u(this,"objectType","RectAreaLight"),this);if(t.rectAreaLightUniformsLibInit||(Gt.init(),t.rectAreaLightUniformsLibInit=!0),e instanceof H)r(e);else{const t=new H(e,n,i,s);t.name="矩形区域光",r(t)}}};u(In,"rectAreaLightUniformsLibInit",!1);let Vn=In;class Wn extends zn{constructor(t={}){super(),u(this,"objectType","Ellipsoid"),u(this,"options"),this.options=t}create(){const t=function(t={}){const{a:e=an.a,b:n=an.b,scaleFactor:i=1/an.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),v=g*y*m*i,b=g*(1-d)*u*i,w=g*y*x*i;h.push(v,b,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 q({color:2200782,metalness:.1,roughness:.7,wireframe:!1});this.object3d.geometry=t,this.object3d.material=e}}function Hn(t,e,n=!1){return n?le(e,t):ve(t,e)}function qn(t,e){const n={type:"Polygon",coordinates:t},[[i,s],[r,a]]=he(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=>Hn(t,n,h))}function Gn(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*ce(t,i)/Math.PI;if(s>e){const r=ue(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=pe(s),o=qn(t,e),a=[...r,...o],h={type:"Polygon",coordinates:t},[[l,c],[u,d]]=he(h),p=l>u||d>=89||c<=-89;let f=[];if(p){const t=be(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(!Hn(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=xe.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(!Hn([0,1].map(t=>fe(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=ge(s);f=ye(t,e,2)}let m=n?[n[0],n[2]]:me(a,t=>t[0]),y=n?[n[1],n[3]]:me(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=we(m,[0,1]),x=we(y,[0,1]),v=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:v}}}const Zn=(new S).setAttribute?"setAttribute":"addAttribute";function Xn(t,e,n){const i=t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=hn(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=hn(t,i,e,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 ge(i)}function $n(t,e,n,i,s){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:Xn([t.points],e,s).vertices,uvs:n}}const Yn=({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=>{de(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:c,triangles:u}=Gn(t,{resolution:i,bbox:h,projection:l});let d,p={};s&&(p=function(t,e,n,i){const{vertices:s,holes:r}=Xn(t,e,i),{vertices:o}=Xn(t,n,i),a=pe([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=pe(u.uvs));let m={};r&&(m=$n(u,e,f,!1,a));let y={};return o&&(y=$n(u,n,f,!0,a)),{contour:c,triangles:u,sideTorso:p,bottomCap:m,topCap:y,topVerts:d}};class Jn 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}=Yn(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 G(new Float64Array(c),3)),this.setIndex(d),this[Zn]("position",new A(c,3)),this[Zn]("uv",new A(u,2)),this.computeVertexNormals()}}function Kn(t,e=0){const n=_e(t,!1);if(!n)return null;if(e){const i=null!==t[0].index;let s=0;for(let r=0;r<t.length;r++){const o=t[r];let a;if(i)a=o.index.count;else{if(void 0===o.attributes.position)return null;a=o.attributes.position.count}if(1===e)n.addGroup(s,a,r);else if(2===e&&o.groups.length>0)for(const t of o.groups)n.addGroup(s+t.start,Math.min(t.count,a),t.materialIndex);s+=a}if(2===e)return Me(n)}return n}function Qn({coordinatesArr:t,metaArray:e,globalMeta:n,hasTop:i,topFirst:s,hasBottom:r,hasSide:o,projection:a="sphere",curvatureResolution:u,bbox:d}){return t.map((t,p)=>{var f,m;const y=e&&e[p]||n||[],g=null!=(f=y[0])?f:0,x=null!=(m=y[1])?m:0;return(t=>{const e=t,{coordinate:n,startHeight:i,height:s}=e,r=c(e,["coordinate","startHeight","height"]);let o=i||0;return void 0!==i&&void 0!==s&&(o=i+s),new Jn([n],l(h({},r),{startHeight:i,endHeight:o}))})({coordinate:t,projection:a,startHeight:x,height:g,hasTop:null==i||i,topFirst:null!=s&&s,hasBottom:null==r||r,hasSide:null==o||o,curvatureResolution:null!=u?u:1,bbox:d})})}const ti={ArcCurve:st,CatmullRomCurve3:it,CubicBezierCurve:nt,CubicBezierCurve3:et,EllipseCurve:tt,LineCurve:Q,LineCurve3:K,QuadraticBezierCurve:J,QuadraticBezierCurve3:Y,SplineCurve:$};class ei extends S{constructor(t=new Z([new j(.5,.5),new j(-.5,.5),new j(-.5,-.5),new j(.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,v=void 0!==e.UVGenerator?e.UVGenerator:ni,b=null==(r=e.hasTop)||r,w=null==(o=e.hasBottom)||o,_=null==(a=e.hasSide)||a;let M,S,A,T,C,O=!1;x&&(M=x.getSpacedPoints(c),O=!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 z=t.extractPoints(l);let E=z.shape;const P=z.holes;if(!X.isClockWise(E)){E=E.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];X.isClockWise(e)&&(P[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 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}}k(E),P.forEach(k);const R=P.length,B=E;for(let e=0;e<R;e++){const t=P[e];E=E.concat(t)}function L(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const U=E.length;function D(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 j(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 j(i/r,s/r)}const N=[];for(let e=0,n=B.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),N[e]=D(B[e],B[i],B[s]);const F=[];let I,V,W=N.concat();for(let e=0,n=R;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]=D(t[e],t[i],t[s]);F.push(I),W=W.concat(I)}if(0===g)V=X.triangulateShape(B,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=B.length;e<n;e++){const n=L(B[e],N[e],r);Z(n.x,n.y,-s),0===i&&t.push(n)}for(let t=0,n=R;t<n;t++){const n=P[t];I=F[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=L(n[t],I[t],r);Z(e.x,e.y,-s),0===i&&o.push(e)}0===i&&e.push(o)}}V=X.triangulateShape(t,e)}const H=V.length,q=f+m;for(let e=0;e<U;e++){const t=d?L(E[e],W[e],q):E[e];O?(T.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),C.copy(M[0]).add(T).add(A),Z(C.x,C.y,C.z)):Z(t.x,t.y,0)}for(let e=1;e<=c;e++)for(let t=0;t<U;t++){const n=d?L(E[t],W[t],q):E[t];O?(T.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),C.copy(M[e]).add(T).add(A),Z(C.x,C.y,C.z)):Z(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=B.length;e<s;e++){const t=L(B[e],N[e],i);Z(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=L(t[e],I[e],i);O?Z(s.x,s.y+M[c-1].y,M[c-1].x+n):Z(s.x,s.y,u+n)}}}function G(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);Y(e+i+n,e+s+n,e+s+r,e+i+r)}}}function Z(t,e,n){h.push(t),h.push(e),h.push(n)}function $(t,e,s){J(t),J(e),J(s);const r=i.length/3,o=v.generateTopUV(n,i,r-3,r-2,r-1);K(o[0]),K(o[1]),K(o[2])}function Y(t,e,s,r){J(t),J(e),J(r),J(e),J(s),J(r);const o=i.length/3,a=v.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<H;n++){const t=V[n];$(t[2]+e,t[1]+e,t[0]+e)}if(t=c+2*g,e=U*t,b)for(let n=0;n<H;n++){const t=V[n];$(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<H;t++){const e=V[t];$(e[2],e[1],e[0])}if(b)for(let t=0;t<H;t++){const e=V[t];$(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;G(B,e),e+=B.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];G(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 ti[i.type]).fromJSON(i)),new ei(n,t.options)}}const ni={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 j(r,o),new j(a,h),new j(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 j(o,1-h),new j(l,1-u),new j(d,1-f),new j(m,1-g)]:[new j(a,1-h),new j(c,1-u),new j(p,1-f),new j(y,1-g)]}};class ii extends ei{constructor(t,e){super(t,e);const n=new Se(new ei(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;const c=new rt(s.x,s.y,o,o),u=new Se(c);u.position.set(r.x,r.y,r.z),u.updateMatrixWorld();const d=(new Ae).evaluate(u,n,Te),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 ei(t,l(h({},e),{hasTop:!1})),g=Kn([d.geometry,m],2);this.copy(g.toNonIndexed())}}const si=t=>{const{box3:e,sideBox:n}=t,i=e.getSize(new y),s=n.getSize(new y);return t.sideRepeat&&(s.z/=t.sideRepeat),{generateTopUV(t,n,s,r,o){const a=n[3*s],h=n[3*s+1],l=n[3*r],c=n[3*r+1],u=n[3*o],d=n[3*o+1];return[new j((a-e.min.x)/i.x,(h-e.min.y)/i.y),new j((l-e.min.x)/i.x,(c-e.min.y)/i.y),new j((u-e.min.x)/i.x,(d-e.min.y)/i.y)]},generateSideWallUV(t,e,i,r,o,a){const h=e[3*i],l=e[3*i+1],c=e[3*i+2],u=e[3*r],d=e[3*r+1],p=e[3*r+2],f=e[3*o],m=e[3*o+1],y=e[3*o+2],g=e[3*a],x=e[3*a+1],v=e[3*a+2];return Math.abs(l-d)<Math.abs(h-u)?[new j((h-n.min.x)/s.x,(c-n.min.z)/s.z),new j((u-n.min.x)/s.x,(p-n.min.z)/s.z),new j((f-n.min.x)/s.x,(y-n.min.z)/s.z),new j((g-n.min.x)/s.x,(v-n.min.z)/s.z)]:[new j((l-n.min.y)/s.y,(c-n.min.z)/s.z),new j((d-n.min.y)/s.y,(p-n.min.z)/s.z),new j((m-n.min.y)/s.y,(y-n.min.z)/s.z),new j((x-n.min.y)/s.y,(v-n.min.z)/s.z)]}}},ri=(t,e)=>t.map(t=>{let n;if(e){const[i,s]=e([...t]);n=new j(i,-s)}else n=new j(...t);return n});function oi(t,e=300,n){const i=[],s=[];return t.forEach((t,r)=>{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&&n[r]&&s.push(n[r],n[r])}else i.push(t),n&&n[r]&&s.push(n[r])}),{splitPolygons:i,splitMeta:s}}function ai({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,bbox:s,projection:r,hasTop:o,hasBottom:a,hasSide:c,splitPolygons:u,topSegments:d}){const p=r&&bn(r);let f,m=e||(t?t.map(t=>ri(t,p)):[]),g=n;if(u){const t=oi(m,u,n);m=t.splitPolygons,g=t.splitMeta}if(s){const t=-180===s[0]&&180===s[2]&&(null==r?void 0:r.rotate),[e,n]=function(t,e,n=0){const[i,s,r,o]=t;let a=1/0,h=1/0,l=-1/0,c=-1/0;for(let u=0;u<=n;u++){const t=n&&u/n;ri([[i+t*(r-i),s],[i+t*(r-i),o],[i,s+t*(o-s)],[r,s+t*(o-s)]],e).forEach(t=>{a=Math.min(a,t.x),h=Math.min(h,t.y),l=Math.max(l,t.x),c=Math.max(c,t.y)})}return[[a,h],[l,c]]}(s,t?bn(l(h({},r),{rotate:void 0})):p,"winkel3"===(null==r?void 0:r.projectionType)?10:0);f=new B(new y(e[0],e[1],0),new y(n[0],n[1],0))}return m.map((t,e)=>{var n,s,r;const h=(null==g?void 0:g[e])||i||[],l=null!=(n=h[0])?n:0,u=null!=(s=h[1])?s:0,p=(t=>{const{depth:e,points:n,box3:i,hasTop:s,hasBottom:r,hasSide:o,sideRepeat:a,topSegments:h}=t,l=h?ii:ei;let c=i;if(!c){c=new B;const t=n.flatMap(t=>[t.x,t.y,0]);c.setFromArray(t)}const u=c.clone();return u.min.z=0,u.max.z=e,new l(new Z(n),{depth:e,bevelEnabled:!1,box3:c,UVGenerator:si({box3:c,sideBox:u,sideRepeat:a}),hasTop:s,hasBottom:r,hasSide:o,topSegments:h})})({points:t,sideRepeat:null!=(r=h[2])?r:1,depth:l,hasTop:o,hasBottom:a,hasSide:c,box3:f,topSegments:d});if(u){const t=p.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+u);t.needsUpdate=!0}return p})}class hi extends zn{constructor(t){super(),u(this,"objectType","ExtrudePolygon"),u(this,"options"),this.options=t}create(){return d(this,null,function*(){const{geometry:t,material:e,useWorker:n=!1}=this.options;let i=t;const s=e;i||(i=n?yield this.createWithWorker():yield this.createLocal()),i&&(this.object3d.geometry=i),s&&(this.object3d.material=s)})}createWithWorker(){return d(this,null,function*(){const{cacheKey:t,onCacheMiss:e}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(e){const t=yield e(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:n,metaArray:i,globalMeta:s,useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,splitPolygons:d,topSegments:p,userData:f,curvatureResolution:m,topFirst:y,useFloat64Array:g}=this.options;if(n&&0!==n.length)return"cesium"===c||"sphere"===c?this.pencil.attributesWorker.geoGeometry("conicPolygon",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:f,useFloat64Array:g,mesaage:{useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,curvatureResolution:m,topFirst:y}}):this.pencil.attributesWorker.geoGeometry("extrudePolygon",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:f,useFloat64Array:g,mesaage:{useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,splitPolygons:d,topSegments:p}})})}createLocal(){return d(this,null,function*(){const{onCacheMiss:t}=this.options;if(t){const e=yield t(this.options);this.options=h(h({},this.options),e)}const{coordinatesArr:e,metaArray:n,globalMeta:i,useGroups:s,hasTop:r,hasBottom:o,hasSide:a,projection:l,splitPolygons:c,topSegments:u,bbox:d,curvatureResolution:p,topFirst:f}=this.options;if(!e||0===e.length)return;return Kn("cesium"===l||"sphere"===l?Qn({coordinatesArr:e,metaArray:n,globalMeta:i,bbox:d,projection:l,hasTop:r,hasBottom:o,hasSide:a,curvatureResolution:p,topFirst:f}):ai({coordinatesArr:e,metaArray:n,globalMeta:i,bbox:d,projection:l,hasTop:r,hasBottom:o,hasSide:a,splitPolygons:c,topSegments:u}),null!=s?s:0)})}}class li extends S{constructor(t=[],e="none",n,i=!1,s){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),u(this,"useRTC",!1),u(this,"rtcCenter",new y(0,0,0)),this.shape=e,this.useRTC=i,n&&(this.shapeFunction=n),s&&this.rtcCenter.copy(s),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 j?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,i){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,void 0!==n&&(this.useRTC=n),i?this.rtcCenter.copy(i):this.useRTC&&this._points.length>0&&this.rtcCenter.copy(this._points[0]),e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const t=new G(new Float32Array(6*this.pointCount),3),e=new G(new Float32Array(6*this.pointCount),3),n=new G(new Float32Array(6*this.pointCount),3),i=new G(new Float32Array(2*this.pointCount),1),s=new G(new Float32Array(2*this.pointCount),1),r=new G(new Float32Array(2*this.pointCount),1),a=new G(new Float32Array(4*this.pointCount),2),h=new G(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(){if(!this._points[0])return;const t=this.getAttribute("position"),e=this.getAttribute("previous"),n=this.getAttribute("next");let i=0,s=0,r=0;const o=this._points[0],a=this.useRTC?this.getRelativePosition(o):o;e.setXYZ(s,a.x,a.y,a.z),s+=1,e.setXYZ(s,a.x,a.y,a.z),s+=1;for(let c=0;c<this.pointCount;c++){const o=this._points[c],a=this.useRTC?this.getRelativePosition(o):o;t.setXYZ(i,a.x,a.y,a.z),i+=1,t.setXYZ(i,a.x,a.y,a.z),i+=1,c<this.pointCount-1&&(e.setXYZ(s,a.x,a.y,a.z),s+=1,e.setXYZ(s,a.x,a.y,a.z),s+=1),c>0&&c+1<=this.pointCount&&(n.setXYZ(r,a.x,a.y,a.z),r+=1,n.setXYZ(r,a.x,a.y,a.z),r+=1)}const h=this._points[this.pointCount-1],l=this.useRTC?this.getRelativePosition(h):h;n.setXYZ(r,l.x,l.y,l.z),r+=1,n.setXYZ(r,l.x,l.y,l.z),r+=1,t.needsUpdate=!0,e.needsUpdate=!0,n.needsUpdate=!0,this.useRTC?(this.boundingSphere=new _(new y,1/0),this.boundingBox=new B(new y(-1/0,-1/0,-1/0),new y(1/0,1/0,1/0))):(this.computeBoundingSphere(),this.computeBoundingBox())}getRelativePosition(t){return new y(t.x-this.rtcCenter.x,t.y-this.rtcCenter.y,t.z-this.rtcCenter.z)}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())}getRTCCenter(){return this.rtcCenter.clone()}setUseRTC(t){this.useRTC!==t&&(this.useRTC=t,this._points.length>0&&(this.useRTC&&this.rtcCenter.copy(this._points[0]),this.updateGeometry()))}getUseRTC(){return this.useRTC}setRTCCenter(t){this.rtcCenter.copy(t),this._points.length>0&&this.updateGeometry()}}class ci extends ot{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 j(0,0),scaleDown:x=0,alphaMap:v,alphaTest:b=0,repeat:w=new j(1,1),resolution:_=new j(1,1)}=e,M=c(e,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super(l(h({},M),{uniforms:{lineWidth:{value:n},color:{value:new at(i)},opacity:{value:s},map:{value:r},useMap:{value:r?1:0},resolution:{value:_},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:x/10},alphaTest:{value:b},alphaMap:{value:v},useAlphaMap:{value:v?1:0},repeat:{value:w},useRTC:{value:0},uRtcOffset:{value:new y(0,0,0)},uViewRotation:{value:new g},uModelMatrix:{value:new g}},vertexShader:"\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 相关 uniforms (始终定义,通过 useRTC 控制是否启用)\n uniform float useRTC; // 0.0 = 禁用, 1.0 = 启用\n uniform vec3 uRtcOffset; // (TransformedCenter - Camera)\n uniform mat4 uViewRotation; // 只有旋转的 View 矩阵\n uniform mat4 uModelMatrix; // 物体的模型矩阵 (包含缩放和旋转,不包含平移)\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 vec4 currentClip;\n vec4 prevClip;\n vec4 nextClip;\n\n if (useRTC > 0.5) {\n // RTC 模式\n // position, previous, next 已经是相对于 rtcCenter 的坐标\n // 先应用模型矩阵的缩放和旋转,然后处理 RTC 偏移和视图变换\n \n // 应用模型矩阵的缩放和旋转 (不包含平移)\n vec3 modelPosition = (uModelMatrix * vec4(position, 1.0)).xyz;\n vec3 modelPrevious = (uModelMatrix * vec4(previous, 1.0)).xyz;\n vec3 modelNext = (uModelMatrix * vec4(next, 1.0)).xyz;\n \n // 加上 RTC 偏移 (TransformedCenter - Camera)\n vec3 worldPosition = modelPosition + uRtcOffset;\n vec3 worldPrevious = modelPrevious + uRtcOffset;\n vec3 worldNext = modelNext + uRtcOffset;\n \n // 应用视图旋转 (因为我们手动计算了 Translation,所以这里只做 Rotation)\n worldPosition = (uViewRotation * vec4(worldPosition, 1.0)).xyz;\n worldPrevious = (uViewRotation * vec4(worldPrevious, 1.0)).xyz;\n worldNext = (uViewRotation * vec4(worldNext, 1.0)).xyz;\n \n // 投影\n currentClip = projectionMatrix * vec4(worldPosition, 1.0);\n prevClip = projectionMatrix * vec4(worldPrevious, 1.0);\n nextClip = projectionMatrix * vec4(worldNext, 1.0);\n } else {\n // 非 RTC 模式,使用原始逻辑\n mat4 m = projectionMatrix * modelViewMatrix;\n currentClip = m * vec4(position, 1.0);\n prevClip = m * vec4(previous, 1.0);\n nextClip = m * vec4(next, 1.0);\n }\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",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 at(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}get rtcOffset(){return this.uniforms.uRtcOffset.value}set rtcOffset(t){this.uniforms.uRtcOffset.value.copy(t)}get viewRotation(){return this.uniforms.uViewRotation.value}set viewRotation(t){this.uniforms.uViewRotation.value.copy(t)}get modelMatrix(){return this.uniforms.uModelMatrix.value}set modelMatrix(t){this.uniforms.uModelMatrix.value.copy(t)}get useRTC(){return this.uniforms.useRTC.value>.5}set useRTC(t){this.uniforms.useRTC.value=t?1:0}updateRTC(t,e,n){const i=e.elements,s=i[12],r=i[13],o=i[14],a=t.clone();if(n&&a.applyMatrix4(n),this.uniforms.useRTC.value=1,this.uniforms.uRtcOffset.value.set(a.x-s,a.y-r,a.z-o),this.uniforms.uViewRotation.value.extractRotation(e).invert(),n){const t=this.uniforms.uModelMatrix.value;t.copy(n),t.elements[12]=0,t.elements[13]=0,t.elements[14]=0}else this.uniforms.uModelMatrix.value.identity()}static fromParsedShaderMaterial(t){const e=t.uniforms,n={};e.color&&(n.color=e.color.value),e.lineWidth&&(n.lineWidth=e.lineWidth.value),e.opacity&&(n.opacity=e.opacity.value),e.sizeAttenuation&&(n.sizeAttenuation=e.sizeAttenuation.value>.5),e.map&&(n.map=e.map.value),e.alphaMap&&(n.alphaMap=e.alphaMap.value),e.dashArray&&(n.dashArray=e.dashArray.value),e.dashOffset&&(n.dashOffset=e.dashOffset.value),e.dashRatio&&(n.dashRatio=e.dashRatio.value),e.scaleDown&&(n.scaleDown=10*e.scaleDown.value),e.alphaTest&&(n.alphaTest=e.alphaTest.value),e.repeat&&(n.repeat=e.repeat.value),e.resolution&&(n.resolution=e.resolution.value),e.offset&&(n.offset=e.offset.value),e.offsetLoop&&(n.offsetLoop=e.offsetLoop.value>.5);const i=new ci(n);return i.uuid=t.uuid,i.name=t.name,i.transparent=t.transparent,i.depthTest=t.depthTest,i.depthWrite=t.depthWrite,i.blending=t.blending,i.side=t.side,i.visible=t.visible,i.colorWrite=t.colorWrite,t.userData&&(i.userData=t.userData),i}}function ui(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 ht?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 di=t=>{const{setPointWidth:e,nodes:n,useRTC:i=!1,rtcCenter:s}=t,r=new li(void 0,void 0,void 0,i,s);return r.setPoints(n,e,i,s),r};function pi({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,projection:s,splitPolygons:r}){const o=s&&bn(s);let a=e||(t?t.map(t=>((t,e)=>t.map(t=>{let n;if(e){const[i,s]=e([...t]);n=new y(i,-s,0)}else n=new y(...t);return n}))(t,o)):[]),h=n;if(r){const t=oi(a,r,h);a=t.splitPolygons,h=t.splitMeta}return a.map((t,e)=>{var n;const s=null!=(n=((null==h?void 0:h[e])||i||[])[0])?n:1;return di({nodes:t,setPointWidth:()=>s})})}const fi=/* @__PURE__ */new WeakMap,mi=/* @__PURE__ */new Map;class yi extends zn{constructor(t={}){super(),u(this,"objectType","Line"),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{geometry:t,material:e,useWorker:n=!1}=this.options,i=e;let s=t;s||(s=n?yield this.createWithWorker():yield this.createLocal()),s&&(this.object3d.geometry=s),i&&(this.object3d.material=i)})}createWithWorker(){return d(this,null,function*(){const{cacheKey:t,onCacheMiss:e}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(e){const t=yield e(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:n,metaArray:i,globalMeta:s,useGroups:r,projection:o,splitPolygons:a,userData:l,useFloat64Array:c,useRTC:u}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(n&&0!==n.length)return"cesium"===o||"sphere"===o?this.pencil.attributesWorker.geoGeometry("conicLine",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:l,useFloat64Array:c,mesaage:{useGroups:r,projection:o,useRTC:u}}):this.pencil.attributesWorker.geoGeometry("line",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:l,useFloat64Array:c,mesaage:{useGroups:r,projection:o,splitPolygons:a}})})}createLocal(){return d(this,null,function*(){var t,e;const{onCacheMiss:n}=this.options;if(n){const t=yield n(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:i,metaArray:s,globalMeta:r,useGroups:o,projection:a,splitPolygons:l,useRTC:c}=this.options;if(!i||0===i.length)return;const u="cesium"===a||"sphere"===a?function({coordinatesArr:t,metaArray:e,globalMeta:n,projection:i="sphere",useRTC:s=!1}){let r;return t.map((t,s)=>{var r;const o=null!=(r=(e&&e[s]||n||[])[1])?r:0;return Yn({polygonGeoJson:[t],startHeight:o,projection:i}).topVerts}).map((t,i)=>{var o;const a=null!=(o=(e&&e[i]||n||[])[0])?o:1,h=di({nodes:t,setPointWidth:()=>a,useRTC:s,rtcCenter:r});return 0===i&&(r=h.getRTCCenter()),h})}({coordinatesArr:i,metaArray:s,globalMeta:r,projection:a,useRTC:c}):pi({coordinatesArr:i,metaArray:s,globalMeta:r,projection:a,splitPolygons:l}),d=u[0],p=(null==(t=d.getUseRTC)?void 0:t.call(d))&&(null==(e=d.getRTCCenter)?void 0:e.call(d)),f=Kn(u,null!=o?o:0);return p&&(f.userData.rtcCenter=p),f})}setGeometry(t,e,n,i){const s=di({nodes:t,setPointWidth:e,useRTC:n,rtcCenter:i}),r=this.object3d,o=r.geometry;r.geometry=s,null==o||o.dispose()}createMaterial(t){const{width:e,height:n}=this.pencil.getSize(),i=new ci(h({color:new at("#ffffff")},t));return i.uniforms.resolution.value.set(e,n),i}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?mi:fi;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 Nt.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",mi.size)}stopAnimation(){const t=this.pencil.userData.debugLine?mi:fi,e=t.get(this.material);e&&(e.stop(),Nt.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",mi.size)}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}update(){const t=this.object3d,e=t.geometry,n=this.material,i=null==e?void 0:e.userData.rtcCenter;i&&this.material&&n.updateRTC(i,this.pencil.camera.matrixWorld,t.matrixWorld)}}const gi=class t extends Cn{constructor(t){const e=document.createElement("div");let n;t.children&&t.children instanceof HTMLElement&&e.appendChild(t.children);const i=t.type||"2d";n="3d"===i?new $t(e):"3dSprite"===i?new Yt(e):new Zt(e),super(n),u(this,"objectType","Node"),u(this,"options"),u(this,"pickObject"),u(this,"element"),u(this,"onNodePointerIndex",[]),this.element=e,this.options=h({type:"2d"},t),t.position&&this.object3d.position.copy(t.position)}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(gi,"sharedObserver"),u(gi,"observerMap",/* @__PURE__ */new Map);let xi=gi;class vi extends On{constructor(t){super(),u(this,"objectType","Pie"),u(this,"options"),this.options=h({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return d(this,null,function*(){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 lt({color:c});i&&p.color.set(c);const f=new D(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 Z;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 ei(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 Nt.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 Nt.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 Nt.Tween(this.object3d.scale).to({z:1},1e3).easing(Nt.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 wi extends Oe{constructor(){super();const t=bi;this.uniforms=ct.clone(t.uniforms),this.material=new ut({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad?this.fsQuad=new ze(this.material):this._fsQuad&&(this._fsQuad=new ze(this.material))}}const _i=new lt({color:"black"}),Mi=new T({color:"black",sizeAttenuation:!1}),Si=new T({color:"black",sizeAttenuation:!0}),Ai=new dt({color:"black",sizeAttenuation:!0}),Ti=new dt({color:"black",sizeAttenuation:!1}),Ci=new ci({color:"black",sizeAttenuation:!1,lineWidth:0}),Oi=new at(0);class zi{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 mt),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 j),l=new pt(h.width,h.height,{samples:Math.min(o,a),type:ft}),c=new Ft(r,l),d=this.getSize();c.setSize(d.width,d.height);const p=new It(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 wi;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 j),r=s.width,o=s.height,a=new Vt(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 Wt(new j(window.innerWidth,window.innerHeight),i,s,n);this.bloomPass=o;const a=new Ft(e);a.renderToScreen=!1,a.addPass(this.renderPass),a.addPass(o),this.bloomComposer=a;const h=(t=>{const e=new Ce(new ot({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=Ai:s.material=Ti:i.material instanceof ci?i.material=Ci:r.isPoints?r.material.sizeAttenuation?r.material=Si:r.material=Mi:i.material=_i}})}),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=Oi)}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===Oi){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 j)}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 Ei=1,Pi=2,ji=4,ki=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}),Ri=0,Bi=1,Li=-1;function Ui(t){return t.isPerspectiveCamera}function Di(t){return t.isOrthographicCamera}const Ni=2*Math.PI,Fi=Math.PI/2,Ii=Math.PI/180;function Vi(t,e,n){return Math.max(e,Math.min(n,t))}function Wi(t,e=1e-5){return Math.abs(t)<e}function Hi(t,e,n=1e-5){return Wi(t-e,n)}function qi(t,e){return Math.round(t/e)*e}function Gi(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Zi(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function Xi(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=Vi(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 $i(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,v=s*i,b=p*p+f*f+m*m;if(b>v*v){const t=Math.sqrt(b);p=p/t*v,f=f/t*v,m=m/t*v}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 Yi(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 Ji(t,e){return!!Di(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class Ki{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 Qi=1/8,ts=/Mac/.test(navigator.platform);let es,ns,is,ss,rs,os,as,hs,ls,cs,us,ds,ps,fs,ms,ys,gs,xs,vs,bs,ws,_s,Ms;class Ss extends Ki{static install(t){es=t.THREE,ns=Object.freeze(new es.Vector3(0,0,0)),is=Object.freeze(new es.Vector3(0,1,0)),ss=Object.freeze(new es.Vector3(0,0,1)),rs=new es.Vector2,os=new es.Vector3,as=new es.Vector3,hs=new es.Vector3,ls=new es.Vector3,cs=new es.Vector3,us=new es.Vector3,ds=new es.Vector3,ps=new es.Vector3,fs=new es.Vector3,ms=new es.Spherical,ys=new es.Spherical,gs=new es.Box3,xs=new es.Box3,vs=new es.Sphere,bs=new es.Quaternion,ws=new es.Quaternion,_s=new es.Matrix4,Ms=new es.Raycaster}static get ACTION(){return ki}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=ki.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=Ri,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new es.Vector3,this._focalOffsetVelocity=new es.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,n,i)=>{let s,r;if(Ui(this._camera)){const n=os.copy(this._camera.position).sub(this._target),i=this._camera.getEffectiveFOV()*Ii,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(!Di(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=Ni*this.azimuthRotateSpeed*t/this._elementRect.height,i=Ni*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=Vi(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===es&&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 es.Quaternion).setFromUnitVectors(this._camera.up,is),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=ki.NONE,this._target=new es.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new es.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new es.Spherical).setFromVector3(os.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 es.Vector3,new es.Vector3,new es.Vector3,new es.Vector3],this._updateNearPlaneCorners(),this._boundary=new es.Box3(new es.Vector3(-1/0,-1/0,-1/0),new es.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 es.Vector2,this.mouseButtons={left:ki.ROTATE,middle:ki.DOLLY,right:ki.TRUCK,wheel:Ui(this._camera)?ki.DOLLY:Di(this._camera)?ki.ZOOM:ki.NONE},this.touches={one:ki.TOUCH_ROTATE,two:Ui(this._camera)?ki.TOUCH_DOLLY_TRUCK:Di(this._camera)?ki.TOUCH_ZOOM_TRUCK:ki.NONE,three:ki.TOUCH_TRUCK};const n=new es.Vector2,i=new es.Vector2,s=new es.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&Ei)===Ei?Ei:(t.buttons&ji)===ji?ji:(t.buttons&Pi)===Pi?Pi:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&Ei)===Ei&&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&Ei)===Ei)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&ji)===ji&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Pi)===Pi&&(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=ki.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=ki.NONE;p()}};let h=-1;const l=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===ki.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===ki.ROTATE||this.mouseButtons.wheel===ki.TRUCK){const t=performance.now();h-t<1e3&&this._getClientRect(this._elementRect),h=t}const e=ts?-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 ki.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case ki.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case ki.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case ki.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case ki.DOLLY:this._dollyInternal(-n,i,s),this._isUserControllingDolly=!0;break;case ki.ZOOM:this._zoomInternal(-n,i,s),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Ss.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;Yi(this._activePointers,rs),this._getClientRect(this._elementRect),n.copy(rs),i.copy(rs);if(this._activePointers.length>=2){const t=rs.x-this._activePointers[1].clientX,e=rs.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&Ei)!==Ei||(this._state=this._state|this.mouseButtons.left),(t.buttons&ji)===ji&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Pi)===Pi&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&ki.ROTATE)!==ki.ROTATE&&(this._state&ki.TOUCH_ROTATE)!==ki.TOUCH_ROTATE&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.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&ki.TRUCK)!==ki.TRUCK&&(this._state&ki.SCREEN_PAN)!==ki.SCREEN_PAN&&(this._state&ki.TOUCH_TRUCK)!==ki.TOUCH_TRUCK&&(this._state&ki.TOUCH_SCREEN_PAN)!==ki.TOUCH_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&ki.DOLLY)!==ki.DOLLY&&(this._state&ki.TOUCH_DOLLY)!==ki.TOUCH_DOLLY&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&ki.ZOOM)!==ki.ZOOM&&(this._state&ki.TOUCH_ZOOM)!==ki.TOUCH_ZOOM&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_ZOOM_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.TOUCH_ZOOM_OFFSET&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&ki.OFFSET)!==ki.OFFSET&&(this._state&ki.TOUCH_OFFSET)!==ki.TOUCH_OFFSET&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.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,Yi(this._activePointers,rs);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:i.x-rs.x,r=t?-t.deltaY:i.y-rs.y;if(i.copy(rs),(this._state&ki.ROTATE)!==ki.ROTATE&&(this._state&ki.TOUCH_ROTATE)!==ki.TOUCH_ROTATE&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&ki.DOLLY)===ki.DOLLY||(this._state&ki.ZOOM)===ki.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&ki.DOLLY)===ki.DOLLY?(this._dollyInternal(i*r*Qi,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(i*r*Qi,t,e),this._isUserControllingZoom=!0)}if((this._state&ki.TOUCH_DOLLY)===ki.TOUCH_DOLLY||(this._state&ki.TOUCH_ZOOM)===ki.TOUCH_ZOOM||(this._state&ki.TOUCH_DOLLY_TRUCK)===ki.TOUCH_DOLLY_TRUCK||(this._state&ki.TOUCH_ZOOM_TRUCK)===ki.TOUCH_ZOOM_TRUCK||(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)===ki.TOUCH_DOLLY_SCREEN_PAN||(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)===ki.TOUCH_ZOOM_SCREEN_PAN||(this._state&ki.TOUCH_DOLLY_OFFSET)===ki.TOUCH_DOLLY_OFFSET||(this._state&ki.TOUCH_ZOOM_OFFSET)===ki.TOUCH_ZOOM_OFFSET||(this._state&ki.TOUCH_DOLLY_ROTATE)===ki.TOUCH_DOLLY_ROTATE||(this._state&ki.TOUCH_ZOOM_ROTATE)===ki.TOUCH_ZOOM_ROTATE){const t=rs.x-this._activePointers[1].clientX,e=rs.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&ki.TOUCH_DOLLY)===ki.TOUCH_DOLLY||(this._state&ki.TOUCH_DOLLY_ROTATE)===ki.TOUCH_DOLLY_ROTATE||(this._state&ki.TOUCH_DOLLY_TRUCK)===ki.TOUCH_DOLLY_TRUCK||(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)===ki.TOUCH_DOLLY_SCREEN_PAN||(this._state&ki.TOUCH_DOLLY_OFFSET)===ki.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*Qi,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*Qi,o,a),this._isUserControllingZoom=!0)}(this._state&ki.TRUCK)!==ki.TRUCK&&(this._state&ki.TOUCH_TRUCK)!==ki.TOUCH_TRUCK&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&ki.SCREEN_PAN)!==ki.SCREEN_PAN&&(this._state&ki.TOUCH_SCREEN_PAN)!==ki.TOUCH_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&ki.OFFSET)!==ki.OFFSET&&(this._state&ki.TOUCH_OFFSET)!==ki.TOUCH_OFFSET&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{Yi(this._activePointers,rs),i.copy(rs),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!==ki.NONE&&(this._state=ki.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=Vi(t.width,0,1),this._interactiveArea.height=Vi(t.height,0,1),this._interactiveArea.x=Vi(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=Vi(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=Vi(t,this.minAzimuthAngle,this.maxAzimuthAngle),s=Vi(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||Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(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=Ri,this._changedDolly=0,this._dollyToNoClamp(Vi(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=Hi(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||Hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(ls).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const n=!e||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(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=Vi(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const n=!e||Hi(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(),cs.setFromMatrixColumn(this._camera.matrix,0),us.setFromMatrixColumn(this._camera.matrix,1),cs.multiplyScalar(t),us.multiplyScalar(-e);const i=os.copy(cs).add(us),s=as.copy(this._targetEnd).add(i);return this.moveTo(s.x,s.y,s.z,n)}forward(t,e=!1){os.setFromMatrixColumn(this._camera.matrix,0),os.crossVectors(this._camera.up,os),os.multiplyScalar(t);const n=as.copy(this._targetEnd).add(os);return this.moveTo(n.x,n.y,n.z,e)}elevate(t,e=!1){return os.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+os.x,this._targetEnd.y+os.y,this._targetEnd.z+os.z,e)}moveTo(t,e,n,i=!1){this._isUserControllingTruck=!1;const s=os.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||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,n,i=!1){const s=os.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?gs.copy(t):gs.setFromObject(t);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const l=qi(this._sphericalEnd.theta,Fi),c=qi(this._sphericalEnd.phi,Fi);a.push(this.rotateTo(l,c,e));const u=os.setFromSpherical(this._sphericalEnd).normalize(),d=bs.setFromUnitVectors(u,ss),p=Hi(Math.abs(u.y),1);p&&d.multiply(ws.setFromAxisAngle(is,l)),d.multiply(this._yAxisUpSpaceInverse);const f=xs.makeEmpty();as.copy(h.min).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setX(h.max.x).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setY(h.max.y).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setZ(h.min.z).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setZ(h.max.z).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setY(h.min.y).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setX(h.min.x).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).applyQuaternion(d),f.expandByPoint(as),f.min.x-=i,f.min.y-=r,f.max.x+=s,f.max.y+=o,d.setFromUnitVectors(ss,u),p&&d.premultiply(ws.invert()),d.premultiply(this._yAxisUpSpace);const m=f.getSize(os),y=f.getCenter(as).applyQuaternion(d);if(Ui(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(Di(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?Ss.createBoundingSphere(t,vs):vs.copy(t);if(n.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),Ui(this._camera)){const t=this.getDistanceToFitSphere(i.radius);n.push(this.dollyTo(t,e))}else if(Di(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=Ri,this._changedDolly=0;const a=as.set(i,s,r),h=os.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||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold)&&Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Hi(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=Ri,this._changedDolly=0;const f=os.set(i,s,r),m=as.set(t,e,n);ms.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const y=hs.set(l,c,u),g=as.set(o,a,h);ys.setFromVector3(g.sub(y).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(y,d));const x=ys.theta-ms.theta,v=ys.phi-ms.phi,b=ys.radius-ms.radius;this._sphericalEnd.set(ms.radius+b*d,ms.phi+v*d,ms.theta+x*d),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!p||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold)&&Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Hi(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(os),r=this.setLookAt(s.x,s.y,s.z,t,e,n,i);return this._sphericalEnd.phi=Vi(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||Hi(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Hi(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Hi(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}setOrbitPoint(t,e,n){this._camera.updateMatrixWorld(),cs.setFromMatrixColumn(this._camera.matrixWorldInverse,0),us.setFromMatrixColumn(this._camera.matrixWorldInverse,1),ds.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=os.set(t,e,n),s=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);cs.multiplyScalar(r.x),us.multiplyScalar(r.y),ds.multiplyScalar(r.z),os.copy(cs).add(us).add(ds),os.z=os.z+s,this.dollyTo(s,!1),this.setFocalOffset(-os.x,os.y,-os.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 es.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(Ji(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const s=t/e,r=this._camera.getEffectiveFOV()*Ii,o=this._camera.aspect;return.5*((i?s>o:s<o)?e:t/o)/Math.tan(.5*r)+.5*n}getDistanceToFitSphere(t){if(Ji(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Ii,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 es.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new es.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new es.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new es.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Ni,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Ni),this._spherical.theta+=Ni*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Ni)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!Hi(this._camera.up.x,this._cameraUp0.x)||!Hi(this._camera.up.y,this._cameraUp0.y)||!Hi(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(os);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,is),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=os.subVectors(this._target,this._camera.position).normalize(),e=as.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const n=this.getPosition(os);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=ps.subVectors(this._targetEnd,this._target),r=fs.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(Wi(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Xi(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(Wi(n))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Xi(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(Wi(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Xi(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(Wi(s.x)&&Wi(s.y)&&Wi(s.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;$i(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(Wi(r.x)&&Wi(r.y)&&Wi(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;$i(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(Wi(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Xi(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if(Ui(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,n=this._getCameraDirection(ls),i=os.copy(n).cross(e.up).normalize();0===i.lengthSq()&&(i.x=1);const s=as.crossVectors(i,n),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*Ii*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=hs.copy(this._targetEnd).add(i.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(s.multiplyScalar(this._dollyControlCoord.y*r)),h=os.copy(this._targetEnd).lerp(a,o),l=this._lastDollyDirection===Bi&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===Li&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(l||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=as.copy(n).multiplyScalar(-t);h.add(e)}this._boundary.clampPoint(h,h);const u=as.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedDolly-=t,Wi(this._changedDolly)&&(this._changedDolly=0)}else if(Di(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,n=os.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),i=as.set(0,0,-1).applyQuaternion(e.quaternion),s=hs.copy(n).add(i.multiplyScalar(-n.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(ls),a=this._targetEnd.dot(o),h=os.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=as.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedZoom-=t,Wi(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);(!Wi(this._focalOffset.x)||!Wi(this._focalOffset.y)||!Wi(this._focalOffset.z))&&(cs.setFromMatrixColumn(this._camera.matrix,0),us.setFromMatrixColumn(this._camera.matrix,1),ds.setFromMatrixColumn(this._camera.matrix,2),cs.multiplyScalar(this._focalOffset.x),us.multiplyScalar(-this._focalOffset.y),ds.multiplyScalar(this._focalOffset.z),os.copy(cs).add(us).add(ds),this._camera.position.add(os),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),os.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"}),Wi(e,this.restThreshold)&&Wi(n,this.restThreshold)&&Wi(i,this.restThreshold)&&Wi(s.x,this.restThreshold)&&Wi(s.y,this.restThreshold)&&Wi(s.z,this.restThreshold)&&Wi(r.x,this.restThreshold)&&Wi(r.y,this.restThreshold)&&Wi(r.z,this.restThreshold)&&Wi(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:Gi(this.maxDistance),minZoom:this.minZoom,maxZoom:Gi(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Gi(this.maxPolarAngle),minAzimuthAngle:Gi(this.minAzimuthAngle),maxAzimuthAngle:Gi(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:os.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=Zi(n.maxDistance),this.minZoom=n.minZoom,this.maxZoom=Zi(n.maxZoom),this.minPolarAngle=n.minPolarAngle,this.maxPolarAngle=Zi(n.maxPolarAngle),this.minAzimuthAngle=Zi(n.minAzimuthAngle),this.maxAzimuthAngle=Zi(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),ms.setFromVector3(os.fromArray(n.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ms.theta,ms.phi,e),this.dollyTo(ms.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=as.copy(e).add(t),r=this._boundary.clampPoint(s,hs).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(as.copy(e).multiplyScalar(i)).add(r.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if(Ui(this._camera)){const t=this._camera,e=t.near,n=t.getEffectiveFOV()*Ii,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(Di(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(Ji(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(ls);_s.lookAt(ns,e,this._camera.up);for(let n=0;n<4;n++){const i=as.copy(this._nearPlaneCorners[n]);i.applyMatrix4(_s);const s=hs.addVectors(this._target,i);Ms.set(s,e),Ms.far=this._spherical.radius+1;const r=Ms.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 es.Sphere){const n=e,i=n.center;gs.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&gs.expandByObject(t)}),gs.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++)os.fromBufferAttribute(r,o),s=Math.max(s,i.distanceToSquared(os))}),n.radius=Math.sqrt(s),n}}class As extends Ve{constructor(t){super(),u(this,"options"),u(this,"autoRotateSpeed",0),this.options=t;const e={Vector2:j,Vector3:y,Vector4:xt,Quaternion:R,Matrix4:g,Spherical:gt,Box3:B,Sphere:_,Raycaster:yt};Ss.install({THREE:e})}get cameraControls(){return this.controller}addCameraControls(t,e){const{domElement:n}=this.options.controlsParams,i=new Ss(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 Ts{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 Cs={zIndex:"auto"};class Os{constructor(t,e){u(this,"css2Drenderer"),u(this,"css3Drenderer"),u(this,"container"),u(this,"collisionManager"),this.container=t,this.collisionManager=new Ts(null==e?void 0:e.collision)}addRenderer(t,e){const n=h(h({},Cs),e),i=n.container||this.container,s=i.offsetWidth,r=i.offsetHeight,o="css2d"===t?new Xt:new Jt;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 zs{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 vt(100);else if(t.isCamera)i=new bt(t);else if(t.isPointLight)i=new wt(t,1);else if(t.isDirectionalLight)i=new _t(t,1);else if(t.isSpotLight)i=new Mt(t);else if(t.isHemisphereLight)i=new St(t,10);else if(t.isRectAreaLight)i=new Ee(t);else{const e=new B;if(e.setFromObject(t,!0),!1!==e.isEmpty())return;{i=new At(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 Pe(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 vt||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 At){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 Es(t){let e=!1,n=[];return(...i)=>{n=i,e||(e=!0,requestAnimationFrame(()=>{e=!1,t(...n)}))}}class Ps{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}`,Es(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",Es(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,Es(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()}}const js=new S,ks=["_baseObjectObjectType","_baseObjectKeyType","_baseObjectUuid","_baseObjectKey","_baseObjectOptions","_baseObjectNeedsCreate","_baseObjectUserData"],Rs=class t{constructor(t){u(this,"lead"),this.lead=t}get scene(){return this.lead.scene}get group(){return this.lead.group}get prefabGroup(){return this.lead.prefabGroup}get mList(){return this.lead.mList}get objects(){return this.lead.objects}exportCompressScene(){const t=this.exportScene();return this._compressGzip(JSON.stringify(t))}exportScene({checkTextures:t=!1}={}){var e,n,i;const s=[],r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Set,a=/* @__PURE__ */new Map,h=[],l=[],c=[],u=[],d=Tt.getDataURL,p=t=>t&&"PMREM.cubeUv"===t.name,f=t=>null==t?void 0:t.isVideoTexture,m=t=>{var e,n;if(!(null==t?void 0:t.isDataTexture))return!1;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image;return(null==i?void 0:i.data)instanceof ArrayBuffer||ArrayBuffer.isView(null==i?void 0:i.data)},y={isTexture:!0,uuid:"PMREM_PLACEHOLDER",toJSON:()=>({uuid:"PMREM_PLACEHOLDER"})};try{this.mList.fixBaseObjects.forEach(t=>{s.push(t.object3d),this.scene.object3d.add(t.object3d),this.lead.objMap.set(t.object3d,t)}),this.scene.traverse(t=>{var e;if("Node"===t.objectType||t.userData.selectHide)return void o.add(t.object3d);t.object3d.userData._baseObjectObjectType=t.objectType,t.object3d.userData._baseObjectKeyType=t.keyType,t.object3d.userData._baseObjectUuid=t.uuid,t.object3d.userData._baseObjectKey=t.key,t.object3d.userData._baseObjectUserData=this._cloneObjectOptions(t.userData);const n=t.options;if(n){t.object3d.userData._baseObjectOptions=this._cloneObjectOptions(n);const i=t.object3d;(null==(e=i.geometry)?void 0:e.isBufferGeometry)&&(r.set(t.object3d,i.geometry),i.geometry=js,t.object3d.userData._baseObjectNeedsCreate=!0)}const i=t.object3d;if(i.material){const t=Array.isArray(i.material)?i.material:[i.material];for(const e of t)p(e.envMap)&&(l.push({target:e,key:"envMap",texture:e.envMap}),e.envMap=y);for(const e of t)for(const t of Object.keys(e)){const n=e[t];f(n)?(c.push({target:e,key:t,texture:n}),e[t]=this._videoTexToPlaceholder(n)):m(n)&&(u.push({target:e,key:t,texture:n}),e[t]=this._dataTexToPlaceholder(n))}}});for(const t of o)t.parent&&(a.set(t,t.parent),t.removeFromParent());const g=[...this.scene.object3d.children];for(const t of g){const s=null==(e=t.userData)?void 0:e._baseObjectKey,r=void 0!==(null==(n=t.userData)?void 0:n._mListFixKey),o=null==(i=t.userData)?void 0:i.light;"@Scene"===s||"@Camera"===s||"@Group"===s||"@PrefabGroup"===s||r||o||(h.push(t),this.scene.object3d.remove(t))}if(p(this.scene.object3d.environment)&&(l.push({target:this.scene.object3d,key:"environment",texture:this.scene.object3d.environment}),this.scene.object3d.environment=y),p(this.scene.object3d.background)&&(l.push({target:this.scene.object3d,key:"background",texture:this.scene.object3d.background}),this.scene.object3d.background=y),t){const t=["map","envMap","lightMap","aoMap","emissiveMap","bumpMap","normalMap","displacementMap","specularMap","alphaMap","metalnessMap","roughnessMap","gradientMap","sheenColorMap","sheenRoughnessMap","transmissionMap","thicknessMap","specularIntensityMap","specularColorMap","iridescenceMap","iridescenceThicknessMap","anisotropyMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap"],e=(t,e)=>{var n,i;if(!t||!t.isTexture)return;const s=null!=(i=null==(n=t.source)?void 0:n.data)?i:t.image;!s||s instanceof HTMLCanvasElement||s instanceof HTMLImageElement||s instanceof ImageBitmap||(null==s?void 0:s.data)&&s.width||console.warn("[SceneSerializer] Unable to serialize texture:",e,{texture:t,textureName:t.name,textureUuid:t.uuid,sourceData:s})};this.scene.object3d.traverse(n=>{var i;if(!n.material)return;const s=Array.isArray(n.material)?n.material:[n.material];for(const r of s){const s=`${n.name||n.uuid} / ${r.name||r.type}`;for(const n of t)e(r[n],`${s}.${n}`);if(r.uniforms)for(const t in r.uniforms){const n=null==(i=r.uniforms[t])?void 0:i.value;e(n,`${s}.uniforms.${t}`)}}})}Tt.getDataURL=(t,e="image/webp")=>d(t,e);const x=this.scene.object3d.toJSON();return this._deduplicateSceneJson(x),this._extractSharedOptionsPool(x),JSON.stringify(x)}finally{Tt.getDataURL=d;for(const t of l)t.target[t.key]=t.texture;for(const t of c)t.target[t.key]=t.texture;for(const t of u)t.target[t.key]=t.texture;this.scene.traverse(t=>{this._cleanUserData(t.object3d);const e=r.get(t.object3d);e&&(t.object3d.geometry=e)});for(const t of s)t.removeFromParent(),this.lead.objMap.delete(t);for(const[t,e]of a)e.add(t);for(const t of h)this.scene.object3d.add(t)}}restoreScene(t){return d(this,arguments,function*(t,e={},n){const i=t instanceof ArrayBuffer?yield this._decompressGzip(t):t,s="string"==typeof i?JSON.parse(i):i;this._restoreSharedOptionsPool(s);const r=new Ct,o=r.parseTextures.bind(r);r.parseTextures=(t,e)=>{const i=[],s=[],r=t?t.filter(t=>{var e,n;return"PMREM_PLACEHOLDER"!==t.uuid&&((null==(e=t.userData)?void 0:e._videoSrc)?(i.push(t),!1):!(null==(n=t.userData)?void 0:n._dataTexBase64)||(s.push(t),!1))}):t,a=o(r,e);n&&(a.PMREM_PLACEHOLDER=n);for(const n of i)a[n.uuid]=this._createVideoTextureFromJson(n);for(const n of s)a[n.uuid]=this._createDataTextureFromJson(n);return a};const a=r.parseMaterials.bind(r);r.parseMaterials=(t,e)=>{if(!t)return{};const n=/* @__PURE__ */new Map;for(const s of t)"MeshLineMaterial"===s.type&&(n.set(s.uuid,s.type),s.type="ShaderMaterial");const i=a(t,e);for(const s in i){"MeshLineMaterial"===n.get(s)&&(i[s]=ci.fromParsedShaderMaterial(i[s]))}return i};const h=yield r.parseAsync(s),l=h.children.filter(t=>void 0!==t.userData._mListFixKey);for(const d of l){const t=d.userData._mListFixKey,e=d.material;this.mList.add(t,e),d.removeFromParent()}this._graftParsedScene(h);const c=/* @__PURE__ */new Set([this.scene.object3d,this.group.object3d,this.prefabGroup.object3d]);this.objects.has("@Camera")&&c.add(this.objects.get("@Camera").object3d);const u=[];this.scene.object3d.traverse(t=>{if(c.has(t))return void this._cleanUserData(t);const n=t.userData._baseObjectObjectType||"BaseObject",i=!0===t.userData._baseObjectNeedsCreate,s=this._createInstance(t,n,e);if(t.userData._baseObjectObjectType&&(s.objectType=t.userData._baseObjectObjectType),t.userData._baseObjectKeyType&&(s.keyType=t.userData._baseObjectKeyType),t.userData._baseObjectUuid&&(s.uuid=t.userData._baseObjectUuid),t.userData._baseObjectKey&&(s.key=t.userData._baseObjectKey),t.userData._baseObjectUserData&&(s.userData=t.userData._baseObjectUserData),this._cleanUserData(t),this.lead.register(s),i){const e=t.material,n=Promise.resolve(s.create()).then(()=>{e&&(s.object3d.material=e),s.render(),this.mList&&(this.mList.proxyBaseObject(s),this.mList.addBaseObjectMap(s))});u.push(n)}else s.render(),this.mList&&(this.mList.proxyBaseObject(s),this.mList.addBaseObjectMap(s))}),yield Promise.all(u)})}_createInstance(t,e,n){const i=n[e];if(i){const e=t.userData._baseObjectOptions,n=new i(e||t);return n.object3d!==t&&(n.object3d=t),n}return"Group"===e?new On(t):new Cn(t)}_cloneObjectOptions(t){if(!t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>this._cloneObjectOptions(t)).filter(t=>void 0!==t);if(_n(t)){const e={};for(const n in t){const i=t[n];i&&(i.isBufferGeometry||i.isMaterial||i.isTexture||i.isObject3D||"function"==typeof i||"object"==typeof i&&i.constructor&&"HTMLImageElement"===i.constructor.name)||(e[n]=this._cloneObjectOptions(i))}return e}}_graftParsedScene(t){var e;this._syncObject3dProps(t,this.scene.object3d);for(const n of[...this.scene.object3d.children])n.removeFromParent();for(const n of[...t.children]){const t=null==(e=n.userData)?void 0:e._baseObjectKey;"@Group"===t?(this._graftObject3d(n,this.group.object3d),this.scene.object3d.add(this.group.object3d)):"@PrefabGroup"===t?(this._graftObject3d(n,this.prefabGroup.object3d),this.scene.object3d.add(this.prefabGroup.object3d)):"@Camera"===t&&this.objects.has("@Camera")?(this._graftObject3d(n,this.objects.get("@Camera").object3d),this.scene.object3d.add(this.objects.get("@Camera").object3d),this.lead.pencil.controls.updateCameraUp()):this.scene.object3d.add(n)}}_graftObject3d(t,e){this._syncObject3dProps(t,e);for(const n of[...e.children])n.removeFromParent();for(const n of[...t.children])e.add(n)}_syncObject3dProps(t,e){const n=t.userData;t.userData={},e.copy(t),t.userData=n}_cleanUserData(t){for(const e of ks)delete t.userData[e]}_deduplicateSceneJson(t){var e,n,i,s;const r=new Qe(t);if((null==(e=t.images)?void 0:e.length)>1){const e=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map;for(const i of t.images){const t=e.get(i.url);t?n.set(i.uuid,t):e.set(i.url,i.uuid)}if(n.size>0){if(t.textures)for(const e of t.textures){const t=n.get(e.image);t&&(e.image=t)}t.images=t.images.filter(t=>!n.has(t.uuid))}}if((null==(n=t.textures)?void 0:n.length)>1){const e=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;for(const r of t.textures){const t=null==(i=r.userData)?void 0:i._videoSrc,a=null==(s=r.userData)?void 0:s._dataTexBase64;if(void 0!==t){const n=e.get(t);n?o.set(r.uuid,n):e.set(t,r.uuid)}else if(void 0!==a){const t=n.get(a);t?o.set(r.uuid,t):n.set(a,r.uuid)}}if(o.size>0){if(t.materials)for(const e of t.materials)for(const t of Object.keys(e)){const n=o.get(e[t]);n&&(e[t]=n)}t.textures=t.textures.filter(t=>!o.has(t.uuid)),console.warn(`[SceneSerializer] Deduplicated ${o.size} textures:\n${r.formatRemap(o).join("\n")}`)}}}_extractSharedOptionsPool(e){const n=[],i=/* @__PURE__ */new Map;this._traverseObjectJson(e.object,e=>{var s;const r=null==(s=e.userData)?void 0:s._baseObjectOptions;if(r)for(const o of t._sharedOptionsKeys){const t=r[o];if(void 0===t)continue;const e=JSON.stringify(t);let s=i.get(e);void 0===s&&(s=n.length,n.push(t),i.set(e,s)),r[o]={_sharedRef:s}}}),n.length>0&&(e._sharedOptionsPool=n)}_restoreSharedOptionsPool(e){const n=e._sharedOptionsPool;n&&(delete e._sharedOptionsPool,this._traverseObjectJson(e.object,e=>{var i;const s=null==(i=e.userData)?void 0:i._baseObjectOptions;if(s)for(const r of t._sharedOptionsKeys){const t=s[r];t&&"object"==typeof t&&"_sharedRef"in t&&(s[r]=n[t._sharedRef])}}))}_traverseObjectJson(t,e){if(t&&(e(t),t.children))for(const n of t.children)this._traverseObjectJson(n,e)}_compressGzip(t){return d(this,null,function*(){const e=new Blob([t]),n=new CompressionStream("gzip"),i=e.stream().pipeThrough(n);return new Response(i).arrayBuffer()})}_decompressGzip(t){return d(this,null,function*(){const e=new Blob([t]),n=new DecompressionStream("gzip"),i=e.stream().pipeThrough(n);return new Response(i).text()})}_serializeTexProps(t){var e,n,i,s,r,o,a,h,l,c,u,d,p,f;return{uuid:t.uuid,name:t.name||"",mapping:t.mapping,channel:null!=(e=t.channel)?e:0,repeat:[null!=(i=null==(n=t.repeat)?void 0:n.x)?i:1,null!=(r=null==(s=t.repeat)?void 0:s.y)?r:1],offset:[null!=(a=null==(o=t.offset)?void 0:o.x)?a:0,null!=(l=null==(h=t.offset)?void 0:h.y)?l:0],center:[null!=(u=null==(c=t.center)?void 0:c.x)?u:0,null!=(p=null==(d=t.center)?void 0:d.y)?p:0],rotation:null!=(f=t.rotation)?f:0,wrap:[t.wrapS,t.wrapT],format:t.format,internalFormat:t.internalFormat,type:t.type,colorSpace:t.colorSpace,minFilter:t.minFilter,magFilter:t.magFilter,anisotropy:t.anisotropy,flipY:t.flipY,generateMipmaps:t.generateMipmaps,premultiplyAlpha:t.premultiplyAlpha,unpackAlignment:t.unpackAlignment}}_applyTexProps(t,e){t.uuid=e.uuid,e.name&&(t.name=e.name),void 0!==e.mapping&&(t.mapping=e.mapping),void 0!==e.channel&&(t.channel=e.channel),e.repeat&&t.repeat.set(e.repeat[0],e.repeat[1]),e.offset&&t.offset.set(e.offset[0],e.offset[1]),e.center&&t.center.set(e.center[0],e.center[1]),void 0!==e.rotation&&(t.rotation=e.rotation),e.wrap&&(t.wrapS=e.wrap[0],t.wrapT=e.wrap[1]),void 0!==e.format&&(t.format=e.format),void 0!==e.internalFormat&&(t.internalFormat=e.internalFormat),void 0!==e.type&&(t.type=e.type),void 0!==e.colorSpace&&(t.colorSpace=e.colorSpace),void 0!==e.minFilter&&(t.minFilter=e.minFilter),void 0!==e.magFilter&&(t.magFilter=e.magFilter),void 0!==e.anisotropy&&(t.anisotropy=e.anisotropy),void 0!==e.flipY&&(t.flipY=e.flipY),void 0!==e.generateMipmaps&&(t.generateMipmaps=e.generateMipmaps),void 0!==e.premultiplyAlpha&&(t.premultiplyAlpha=e.premultiplyAlpha),void 0!==e.unpackAlignment&&(t.unpackAlignment=e.unpackAlignment)}_createPlaceholder(t,e,n){return{isTexture:!0,uuid:t,toJSON(i){const s=l(h({},e),{userData:n});return(null==i?void 0:i.textures)&&(i.textures[t]=s),s}}}_videoTexToPlaceholder(t){var e,n;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image;return this._createPlaceholder(t.uuid,this._serializeTexProps(t),{_videoSrc:(null==i?void 0:i.src)||""})}_createVideoTextureFromJson(t){var e;const n=document.createElement("video");n.preload="auto",n.autoplay=!0,n.loop=!0,n.muted=!0,n.setAttribute("webkit-playsinline","webkit-playsinline"),n.setAttribute("playsinline",""),n.src=(null==(e=t.userData)?void 0:e._videoSrc)||"",n.play();const i=new Ot(n);return this._applyTexProps(i,t),i}_dataTexToPlaceholder(t){var e,n;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image,s=i.data;return this._createPlaceholder(t.uuid,this._serializeTexProps(t),{_dataTexBase64:this._typedArrayToBase64(s),_dataTexArrayType:s.constructor.name,_dataTexWidth:i.width,_dataTexHeight:i.height})}_createDataTextureFromJson(e){var n;const i=e.userData,s=null!=(n=t._typedArrayCtors[i._dataTexArrayType])?n:Uint16Array,r=this._base64ToTypedArray(i._dataTexBase64,s),o=new zt(r,i._dataTexWidth,i._dataTexHeight);return this._applyTexProps(o,e),o.needsUpdate=!0,o}_typedArrayToBase64(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let i=0;i<e.length;i+=8192)n+=String.fromCharCode(...e.subarray(i,Math.min(i+8192,e.length)));return btoa(n)}_base64ToTypedArray(t,e){const n=atob(t),i=new Uint8Array(n.length);for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s);return new e(i.buffer)}};u(Rs,"_sharedOptionsKeys",["coordinatesArr","src"]),u(Rs,"_typedArrayCtors",{Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Float32Array:Float32Array,Float64Array:Float64Array});let Bs=Rs;new S;class Ls extends Ps{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,"_serializer",new Bs(this)),this.mList=e.mList,this.scene=new Cn(e.scene||new Et),this.scene.key="@Scene",this.scene.object3d.name="场景",this._initCoreObject(this.scene),this.group=new On,this.group.key="@Group",this.group.object3d.name="物体组",this.scene.add(this.group),this._initCoreObject(this.group),this.prefabGroup=new On,this.prefabGroup.key="@PrefabGroup",this.prefabGroup.object3d.name="预制组",this.scene.add(this.prefabGroup),this._initCoreObject(this.prefabGroup)}get objectsPromise(){return this.objectsPm.values()}register(t){if(t.pencil=this.pencil,t.lead=this,t.mList=this.mList,t.object3d&&this.objMap.set(t.object3d,t),!t.key)if(!t.key&&t.parent&&"@Scene"===t.parent.key&&t.object3d instanceof Pt)t.key="@Camera";else if(!t.key&&t.parent){const e=this.objectWrapChindIdMap.get(t.parent),n=void 0!==e?e+1:0;this.objectWrapChindIdMap.set(t.parent,n);const i=`${t.parent.keyType}__c__${n}`,s=t.parent.uuid;this.updateBaseObjectKey(t,{keyType:i,uuid:s})}else this.updateBaseObjectKey(t);return this.objects.has(t.key)||this.objects.set(t.key,t),t}_initCoreObject(t){this.register(t),t.render(),t.object3d.children.forEach(t=>{t instanceof Pt&&this.wrap(t)})}draw(t,...e){let n,i,s,r=!1;"function"==typeof t?(n=t,i=e):(s=t.target,t.prefab&&(r=!0),n=e[0],i=e.slice(1));const o=new n(...i);return r&&(o.isPrefab=!0),this.add(o,s)}wrap(t){const e=this.objMap.get(t);if(e)return e;const n=t instanceof U?new On(t):new Cn(t);return this.register(n),this.mList&&(this.mList.proxyBaseObject(n),this.mList.addBaseObjectMap(n)),t.children.forEach(t=>{this.wrap(t)}),n}add(t,e){return d(this,null,function*(){let n=this.group;if(null===e)n=null;else if("string"==typeof e){const t=this.objects.get(e);t&&(n=t)}else e instanceof Cn?n=e:t.isPrefab&&(n=this.prefabGroup);this.register(t),n&&t.object3d&&n.object3d.add(t.object3d);const i=this._addLogic(t,n);return this.objectsPm.set(t,i),yield i,this.objectsPm.delete(t),t})}_addLogic(t,e){return d(this,null,function*(){t.isInstantiate||(yield t.create());const e=t.object3d;e.material&&Array.isArray(e.material)&&(e.material=e.material.slice()),t.render(),this.mList&&(this.mList.proxyBaseObject(t),this.mList.addBaseObjectMap(t)),e.children.forEach(t=>{this.objMap.get(t)||this.wrap(t)}),this.pencil.event.emit("lead.draw",{baseObject:t})})}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}updateBaseObjectKey(t,e={}){const n=t.key,i=t.keyType;this.objects.delete(n);const s=e.keyType||t.keyType,r=e.uuid,o=r?`${s}#${r}`:`${s}`;if(!this.objects.has(o))return t.keyType=s,t.uuid=r||"",t.key=o,this.objects.set(o,t),this.pencil.event.emit("lead.updateKey",{baseObject:t,key:o,oldKey:n}),t.children.forEach(t=>{if(t.keyType.includes("__c__")){const e=t.keyType.replace(i,s);this.updateBaseObjectKey(t,{keyType:e,uuid:r})}else t.userData.syncParentUuid&&this.updateBaseObjectKey(t,{uuid:r})}),o;this.updateBaseObjectKey(t,{keyType:s,uuid:je()})}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=>{const n=[...e.children];n.length>0&&this.handleErase(t,...n),this.objects.delete(e.key),this.objectWrapChindIdMap.delete(e),e.object3d&&(this.objMap.delete(e.object3d),e.object3d.removeFromParent()),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))}exportScene(...t){return this._serializer.exportScene(...t)}restoreScene(...t){return d(this,null,function*(){return this._serializer.restoreScene(...t)})}dispose(){super.dispose(),this.scene.erase(),this.objects.forEach(t=>{t.erase()}),this.objects.clear(),this.objectsPm.clear(),this.objMap.clear(),this.objectWrapChindIdMap.clear()}}class Us extends Ve{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 Ls(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 Ds extends jt{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 Ns extends kt{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 Ot(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 Fs={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 Is{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 Rt(()=>{},(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 Bt(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("media",{create:t=>new Ns(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gltf",{create:t=>new Ue(t),setPath:(t,e)=>t.setPath(e),requiresDraco:!0}),this.loaderConfigs.set("lottie",{create:t=>new De(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gzipJson",{create:t=>new Ds(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("json",{create:t=>new jt(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("exr",{create:t=>new Le(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(Fs))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 Ue(this.loadingManager);const t=new Be;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 zt||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=ke();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 Vs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get loader(){return this.controller}addLoader(t,e){const{loaderParams:n}=this.options,i=new Is(l(h({},n),{scene:t}));return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const Ws=class t{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(e,n){this.materials.set(e,n);const i=new D(t._emptyGeometry,n);i.visible=!1,i.userData._mListFixKey=e;const s=new Cn(i),r={value:n};Object.defineProperty(i,"material",{get:()=>r.value,set:t=>{var n;if(null==(n=this.pencil.composerController)?void 0:n.bloomComposerRenderIng)r.value=t;else{const n=r.value;r.value=t,this.materials.set(e,t),this.disposeMaterial(n),this.syncChangeMaterial(n,t)}},enumerable:!0,configurable:!0}),this.fixBaseObjects.set(e,s),this.pencil.event.emit("mList.add",{key:e,material:n,baseObject:s})}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 qe;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){rn({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 qe;t.track([...this.materials.values()]),t.dispose(),this.materials.clear(),this.fixBaseObjects.clear(),this.materialBaseObjectMap.clear()}};u(Ws,"_emptyGeometry",new S);let Hs=Ws;class qs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get mList(){return this.controller}addMList(t,e){const{pencil:n}=this.options,i=new Hs(n);return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const Gs={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:tn.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1};class Zs{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 Lt({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 Xs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get scene(){return this.controller}addScene(t,e){const n=new Et;return(null==t?void 0:t.background)&&(n.background=t.background),this.addController(n,e)}removePage(t){super.removePage(t,t=>{const e=new qe;e.track(t),e.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.visible=e})}}class $s{constructor(t){u(this,"controls"),u(this,"event",new p);const{renderer:e,scene:n,camera:i}=t,s=new Ne(i,e.domElement);if(s.getHelper){const t=s.getHelper();if(n.add(t),+Ut<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 b&&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 Ys={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Js{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 Ks=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 G(t[n].array,t[n].itemSize)):"rtcCenter"===n?e.userData.rtcCenter=new y(t.rtcCenter.x,t.rtcCenter.y,t.rtcCenter.z):e.setAttribute(n,new G(t[n].array,t[n].itemSize))}),e},Qs='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";function t(t){return Object.getOwnPropertyNames(t).reduce(function(e,n){return Object.defineProperty(e,n,{value:t[n],enumerable:!0})},{})}var e=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 n(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function i(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function r(t){let e,r,o;function a(t,n,i=0,s=t.length){if(i<s){if(0!==e(n,n))return s;do{const e=i+s>>>1;r(t[e],n)<0?i=e+1:s=e}while(i<s)}return i}return 2!==t.length?(e=n,r=(e,i)=>n(t(e),i),o=(e,n)=>t(e)-n):(e=t===n||t===i?t:s,r=t,o=t),{left:a,center:function(t,e,n=0,i=t.length){const r=a(t,e,n,i-1);return r>n&&o(t[r-1],e)>-o(t[r],e)?r-1:r},right:function(t,n,i=0,s=t.length){if(i<s){if(0!==e(n,n))return s;do{const e=i+s>>>1;r(t[e],n)<=0?i=e+1:s=e}while(i<s)}return i}}}function s(){return 0}const o=r(n).right;function a(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]}r(function(t){return null===t?NaN:+t}).center;class l{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 f=Math.sqrt(50),m=Math.sqrt(10),g=Math.sqrt(2);function x(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>=f?10:s>=m?5:s>=g?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?x(t,e,2*n):[a,h,l]}function b(t,e,n){return x(t=+t,e=+e,n=+n)[2]}function w(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 v(t){return Array.from(function*(t){for(const e of t)yield*y(e)}(t))}function M(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=S(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=S(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(I(n))}r.sort(P);for(let s=0;s<r.length;s++)n=E(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 z(s,o,n,a,h,l,0),o}function S(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=j(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=j(o/i|0,t[o],t[o+1],s);return s&&V(s,s.next)&&(G(s),s=s.next),s}function A(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!V(i,i.next)&&0!==U(i.prev,i,i.next))i=i.next;else{if(G(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function z(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=N(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?T(t,i,r,s):_(t))e.push(h.i,t.i,l.i),G(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?z(t=B(A(t),e),e,n,i,r,s,2):2===o&&C(t,e,n,i,r,s):z(A(t),e,n,i,r,s,1);break}}}function _(t){const e=t.prev,n=t,i=t.next;if(U(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&&F(r,a,s,h,o,l,f.x,f.y)&&U(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function T(t,e,n,i){const r=t.prev,s=t,o=t.next;if(U(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=N(p,f,e,n,i),x=N(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&&F(a,u,h,c,l,d,b.x,b.y)&&U(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&&F(a,u,h,c,l,d,w.x,w.y)&&U(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&&F(a,u,h,c,l,d,b.x,b.y)&&U(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&&F(a,u,h,c,l,d,w.x,w.y)&&U(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function B(t,e){let n=t;do{const i=n.prev,r=n.next.next;!V(i,r)&&L(i,n,n.next,r)&&X(i,r)&&X(r,i)&&(e.push(i.i,n.i,r.i),G(n),G(n.next),n=t=r),n=n.next}while(n!==t);return A(n)}function C(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&R(o,t)){let a=Z(o,t);return o=A(o,o.next),a=A(a,a.next),z(o,e,n,i,r,s,0),void z(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function P(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 E(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(V(t,n))return n;do{if(V(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&&O(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);X(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&k(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Z(n,t);return A(i,i.next),A(n,n.next)}function k(t,e){return U(t.prev,t,e.prev)<0&&U(e.next,t,t.next)<0}function N(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 I(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 O(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 F(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&O(t,e,n,i,r,s,o,a)}function R(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&&L(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(X(t,e)&&X(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)&&(U(t.prev,t,e.prev)||U(t,e.prev,e))||V(t,e)&&U(t.prev,t,t.next)>0&&U(e.prev,e,e.next)>0)}function U(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function V(t,e){return t.x===e.x&&t.y===e.y}function L(t,e,n,i){const r=D(U(t,e,n)),s=D(U(t,e,i)),o=D(U(n,i,t)),a=D(U(n,i,e));return r!==s&&o!==a||(!(0!==r||!q(t,n,e))||(!(0!==s||!q(t,i,e))||(!(0!==o||!q(n,t,i))||!(0!==a||!q(n,e,i)))))}function q(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 D(t){return t>0?1:t<0?-1:0}function X(t,e){return U(t.prev,t,t.next)<0?U(t,e,t.next)>=0&&U(t,t.prev,e)>=0:U(t,e,t.prev)<0||U(t,t.next,e)<0}function Z(t,e){const n=J(t.i,t.x,t.y),i=J(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 j(t,e,n,i){const r=J(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 G(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 J(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function W(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 $="183",Y=1001,H="srgb",Q="srgb-linear",K="linear",tt="srgb",et=7680,nt=2e3;function it(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const rt={};function st(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]=\'Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.\'}return t}function ot(...t){const e="THREE."+(t=st(t)).shift();{const n=t[0];n&&n.isStackTrace?console.warn(n.getError(e)):console.warn(e,...t)}}function at(...t){const e="THREE."+(t=st(t)).shift();{const n=t[0];n&&n.isStackTrace?console.error(n.getError(e)):console.error(e,...t)}}function ht(...t){const e=t.join(" ");e in rt||(rt[e]=!0,ot(...t))}class lt{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 ut=["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 ct=1234567;const dt=Math.PI/180,pt=180/Math.PI;function ft(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(ut[255&t]+ut[t>>8&255]+ut[t>>16&255]+ut[t>>24&255]+"-"+ut[255&e]+ut[e>>8&255]+"-"+ut[e>>16&15|64]+ut[e>>24&255]+"-"+ut[63&n|128]+ut[n>>8&255]+"-"+ut[n>>16&255]+ut[n>>24&255]+ut[255&i]+ut[i>>8&255]+ut[i>>16&255]+ut[i>>24&255]).toLowerCase()}function yt(t,e,n){return Math.max(e,Math.min(n,t))}function mt(t,e){return(t%e+e)%e}function gt(t,e,n){return(1-n)*t+n*e}function xt(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 bt(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 wt={DEG2RAD:dt,RAD2DEG:pt,generateUUID:ft,clamp:yt,euclideanModulo:mt,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:gt,damp:function(t,e,n,i){return gt(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(mt(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&&(ct=t);let e=ct+=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*dt},radToDeg:function(t){return t*pt},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:ot("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:bt,denormalize:xt};class vt{constructor(t=0,e=0){vt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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(yt(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 Mt{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(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:ot("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(yt(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){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 St{constructor(t=0,e=0,n=0){St.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(zt.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(zt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this.z=yt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this.z=yt(this.z,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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 At.copy(this).projectOnVector(t),this.sub(At)}reflect(t){return this.sub(At.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(yt(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 At=new St,zt=new Mt;class _t{constructor(t,e,n,i,r,s,o,a,h){_t.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(Tt.makeScale(t,e)),this}rotate(t){return this.premultiply(Tt.makeRotation(-t)),this}translate(t,e){return this.premultiply(Tt.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 Tt=new _t,Bt=(new _t).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ct=(new _t).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Pt(){const t={enabled:!0,workingColorSpace:Q,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===tt&&(t.r=kt(t.r),t.g=kt(t.g),t.b=kt(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===tt&&(t.r=Nt(t.r),t.g=Nt(t.g),t.b=Nt(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?K: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 ht("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(e,n)},toWorkingColorSpace:function(e,n){return ht("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(e,n)}},e=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],i=[.3127,.329];return t.define({[Q]:{primaries:e,whitePoint:i,transfer:K,toXYZ:Bt,fromXYZ:Ct,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:H},outputColorSpaceConfig:{drawingBufferColorSpace:H}},[H]:{primaries:e,whitePoint:i,transfer:tt,toXYZ:Bt,fromXYZ:Ct,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:H}}}),t}const Et=Pt();function kt(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function Nt(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let It;class Ot{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===It&&(It=it("canvas")),It.width=t.width,It.height=t.height;const e=It.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),n=It}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=it("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*kt(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*kt(e[t]/255)):e[t]=kt(e[t]);return{data:e,width:t.width,height:t.height}}return ot("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Ft=0;class Rt{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Ft++}),this.uuid=ft(),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(Ut(i[e].image)):t.push(Ut(i[e]))}else t=Ut(i);n.url=t}return e||(t.images[this.uuid]=n),n}}function Ut(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Ot.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(ot("Texture: Unable to serialize Texture."),{})}let Vt=0;const Lt=new St;class qt extends lt{constructor(t=qt.DEFAULT_IMAGE,e=qt.DEFAULT_MAPPING,n=1001,i=1001,r=1006,s=1008,o=1023,a=1009,h=qt.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Vt++}),this.uuid=ft(),this.name="",this.source=new Rt(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 vt(0,0),this.repeat=new vt(1,1),this.center=new vt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new _t,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(Lt).x}get height(){return this.source.getSize(Lt).y}get depth(){return this.source.getSize(Lt).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){ot(`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:ot(`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 Y: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 Y: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++}}qt.DEFAULT_IMAGE=null,qt.DEFAULT_MAPPING=300,qt.DEFAULT_ANISOTROPY=1;class Dt{constructor(t=0,e=0,n=0,i=1){Dt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this.z=yt(this.z,t.z,e.z),this.w=yt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this.z=yt(this.z,t,e),this.w=yt(this.w,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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 Xt{constructor(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){Xt.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 Xt).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/Zt.setFromMatrixColumn(t,0).length(),r=1/Zt.setFromMatrixColumn(t,1).length(),s=1/Zt.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(Gt,t,Jt)}lookAt(t,e,n){const i=this.elements;return Yt.subVectors(t,e),0===Yt.lengthSq()&&(Yt.z=1),Yt.normalize(),Wt.crossVectors(n,Yt),0===Wt.lengthSq()&&(1===Math.abs(n.z)?Yt.x+=1e-4:Yt.z+=1e-4,Yt.normalize(),Wt.crossVectors(n,Yt)),Wt.normalize(),$t.crossVectors(Yt,Wt),i[0]=Wt.x,i[4]=$t.x,i[8]=Yt.x,i[1]=Wt.y,i[5]=$t.y,i[9]=Yt.y,i[2]=Wt.z,i[6]=$t.z,i[10]=Yt.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],C=i[2],P=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*C+h*N,r[4]=s*M+o*_+a*P+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*C+d*N,r[5]=l*M+u*_+c*P+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*C+m*N,r[6]=p*M+f*_+y*P+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*C+w*N,r[7]=g*M+x*_+b*P+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=e*o-n*s,x=e*a-i*s,b=e*h-r*s,w=n*a-i*o,v=n*h-r*o,M=i*h-r*a,S=l*f-u*p,A=l*y-c*p,z=l*m-d*p,_=u*y-c*f,T=u*m-d*f,B=c*m-d*y,C=g*B-x*T+b*_+w*z-v*A+M*S;if(0===C)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const P=1/C;return t[0]=(o*B-a*T+h*_)*P,t[1]=(i*T-n*B-r*_)*P,t[2]=(f*M-y*v+m*w)*P,t[3]=(c*v-u*M-d*w)*P,t[4]=(a*z-s*B-h*A)*P,t[5]=(e*B-i*z+r*A)*P,t[6]=(y*b-p*M-m*x)*P,t[7]=(l*M-c*b+d*x)*P,t[8]=(s*T-o*z+h*S)*P,t[9]=(n*z-e*T-r*S)*P,t[10]=(p*v-f*b+m*g)*P,t[11]=(u*b-l*v-d*g)*P,t[12]=(o*A-s*_-a*S)*P,t[13]=(e*_-n*A+i*S)*P,t[14]=(f*x-p*w-y*g)*P,t[15]=(l*w-u*x+c*g)*P,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;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return n.set(1,1,1),e.identity(),this;let s=Zt.set(i[0],i[1],i[2]).length();const o=Zt.set(i[4],i[5],i[6]).length(),a=Zt.set(i[8],i[9],i[10]).length();r<0&&(s=-s),jt.copy(this);const h=1/s,l=1/o,u=1/a;return jt.elements[0]*=h,jt.elements[1]*=h,jt.elements[2]*=h,jt.elements[4]*=l,jt.elements[5]*=l,jt.elements[6]*=l,jt.elements[8]*=u,jt.elements[9]*=u,jt.elements[10]*=u,e.setFromRotationMatrix(jt),n.x=s,n.y=o,n.z=a,this}makePerspective(t,e,n,i,r,s,o=2e3,a=!1){const h=this.elements,l=2*r/(e-t),u=2*r/(n-i),c=(e+t)/(e-t),d=(n+i)/(n-i);let p,f;if(a)p=r/(s-r),f=s*r/(s-r);else if(o===nt)p=-(s+r)/(s-r),f=-2*s*r/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);p=-s/(s-r),f=-s*r/(s-r)}return h[0]=l,h[4]=0,h[8]=c,h[12]=0,h[1]=0,h[5]=u,h[9]=d,h[13]=0,h[2]=0,h[6]=0,h[10]=p,h[14]=f,h[3]=0,h[7]=0,h[11]=-1,h[15]=0,this}makeOrthographic(t,e,n,i,r,s,o=2e3,a=!1){const h=this.elements,l=2/(e-t),u=2/(n-i),c=-(e+t)/(e-t),d=-(n+i)/(n-i);let p,f;if(a)p=1/(s-r),f=s/(s-r);else if(o===nt)p=-2/(s-r),f=-(s+r)/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=-1/(s-r),f=-r/(s-r)}return h[0]=l,h[4]=0,h[8]=0,h[12]=c,h[1]=0,h[5]=u,h[9]=0,h[13]=d,h[2]=0,h[6]=0,h[10]=p,h[14]=f,h[3]=0,h[7]=0,h[11]=0,h[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 Zt=new St,jt=new Xt,Gt=new St(0,0,0),Jt=new St(1,1,1),Wt=new St,$t=new St,Yt=new St,Ht=new Xt,Qt=new Mt;class Kt{constructor(t=0,e=0,n=0,i=Kt.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(yt(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(-yt(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(yt(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(-yt(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(yt(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(-yt(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:ot("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return Ht.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Ht,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Qt.setFromEuler(this),this.setFromQuaternion(Qt,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}}Kt.DEFAULT_ORDER="XYZ";class te{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 ee=0;const ne=new St,ie=new Mt,re=new Xt,se=new St,oe=new St,ae=new St,he=new Mt,le=new St(1,0,0),ue=new St(0,1,0),ce=new St(0,0,1),de={type:"added"},pe={type:"removed"},fe={type:"childadded",child:null},ye={type:"childremoved",child:null};class me extends lt{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:ee++}),this.uuid=ft(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=me.DEFAULT_UP.clone();const t=new St,e=new Kt,n=new Mt,i=new St(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 Xt},normalMatrix:{value:new _t}}),this.matrix=new Xt,this.matrixWorld=new Xt,this.matrixAutoUpdate=me.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=me.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new te,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.static=!1,this.userData={},this.pivot=null}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 ie.setFromAxisAngle(t,e),this.quaternion.multiply(ie),this}rotateOnWorldAxis(t,e){return ie.setFromAxisAngle(t,e),this.quaternion.premultiply(ie),this}rotateX(t){return this.rotateOnAxis(le,t)}rotateY(t){return this.rotateOnAxis(ue,t)}rotateZ(t){return this.rotateOnAxis(ce,t)}translateOnAxis(t,e){return ne.copy(t).applyQuaternion(this.quaternion),this.position.add(ne.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(le,t)}translateY(t){return this.translateOnAxis(ue,t)}translateZ(t){return this.translateOnAxis(ce,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(re.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?se.copy(t):se.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),oe.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?re.lookAt(oe,se,this.up):re.lookAt(se,oe,this.up),this.quaternion.setFromRotationMatrix(re),i&&(re.extractRotation(i.matrixWorld),ie.setFromRotationMatrix(re),this.quaternion.premultiply(ie.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(at("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(de),fe.child=t,this.dispatchEvent(fe),fe.child=null):at("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(pe),ye.child=t,this.dispatchEvent(ye),ye.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),re.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),re.multiply(t.parent.matrixWorld)),t.applyMatrix4(re),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(de),fe.child=t,this.dispatchEvent(fe),fe.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(oe,t,ae),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(oe,he,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);const t=this.pivot;if(null!==t){const e=t.x,n=t.y,i=t.z,r=this.matrix.elements;r[12]+=e-r[0]*e-r[4]*n-r[8]*i,r[13]+=n-r[1]*e-r[5]*n-r[9]*i,r[14]+=i-r[2]*e-r[6]*n-r[10]*i}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),!1!==this.static&&(i.static=this.static),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(),null!==this.pivot&&(i.pivot=this.pivot.toArray()),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),void 0!==this.morphTargetDictionary&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),void 0!==this.morphTargetInfluences&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),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),null!==t.pivot&&(this.pivot=t.pivot.clone()),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.static=t.static,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}}me.DEFAULT_UP=new St(0,1,0),me.DEFAULT_MATRIX_AUTO_UPDATE=!0,me.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ge={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},xe={h:0,s:0,l:0},be={h:0,s:0,l:0};function we(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 ve=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=H){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,Et.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=Et.workingColorSpace){return this.r=t,this.g=e,this.b=n,Et.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=Et.workingColorSpace){if(t=mt(t,1),e=yt(e,0,1),n=yt(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=we(r,i,t+1/3),this.g=we(r,i,t),this.b=we(r,i,t-1/3)}return Et.colorSpaceToWorking(this,i),this}setStyle(t,e=H){function n(e){void 0!==e&&parseFloat(e)<1&&ot("Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\\w+)\\(([^\\)]*)\\)/.exec(t)){let r;const s=i[1],o=i[2];switch(s){case"rgb":case"rgba":if(r=/^\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\\s*(\\d*\\.?\\d+)\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:ot("Color: Unknown color model "+t)}}else if(i=/^\\#([A-Fa-f\\d]+)$/.exec(t)){const n=i[1],r=n.length;if(3===r)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(n,16),e);ot("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=H){const n=ge[t.toLowerCase()];return void 0!==n?this.setHex(n,e):ot("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=kt(t.r),this.g=kt(t.g),this.b=kt(t.b),this}copyLinearToSRGB(t){return this.r=Nt(t.r),this.g=Nt(t.g),this.b=Nt(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=H){return Et.workingToColorSpace(Me.copy(this),t),65536*Math.round(yt(255*Me.r,0,255))+256*Math.round(yt(255*Me.g,0,255))+Math.round(yt(255*Me.b,0,255))}getHexString(t=H){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Et.workingColorSpace){Et.workingToColorSpace(Me.copy(this),e);const n=Me.r,i=Me.g,r=Me.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=Et.workingColorSpace){return Et.workingToColorSpace(Me.copy(this),e),t.r=Me.r,t.g=Me.g,t.b=Me.b,t}getStyle(t=H){Et.workingToColorSpace(Me.copy(this),t);const e=Me.r,n=Me.g,i=Me.b;return t!==H?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*n)},${Math.round(255*i)})`}offsetHSL(t,e,n){return this.getHSL(xe),this.setHSL(xe.h+t,xe.s+e,xe.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(xe),t.getHSL(be);const n=gt(xe.h,be.h,e),i=gt(xe.s,be.s,e),r=gt(xe.l,be.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 Me=new ve;ve.NAMES=ge;const Se=new St,Ae=new St,ze=new St,_e=new St,Te=new St,Be=new St,Ce=new St,Pe=new St,Ee=new St,ke=new St,Ne=new Dt,Ie=new Dt,Oe=new Dt;class Fe{constructor(t=new St,e=new St,n=new St){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),Se.subVectors(t,e),i.cross(Se);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){Se.subVectors(i,e),Ae.subVectors(n,e),ze.subVectors(t,e);const s=Se.dot(Se),o=Se.dot(Ae),a=Se.dot(ze),h=Ae.dot(Ae),l=Ae.dot(ze),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,_e)&&(_e.x>=0&&_e.y>=0&&_e.x+_e.y<=1)}static getInterpolation(t,e,n,i,r,s,o,a){return null===this.getBarycoord(t,e,n,i,_e)?(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,_e.x),a.addScaledVector(s,_e.y),a.addScaledVector(o,_e.z),a)}static getInterpolatedAttribute(t,e,n,i,r,s){return Ne.setScalar(0),Ie.setScalar(0),Oe.setScalar(0),Ne.fromBufferAttribute(t,e),Ie.fromBufferAttribute(t,n),Oe.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(Ne,r.x),s.addScaledVector(Ie,r.y),s.addScaledVector(Oe,r.z),s}static isFrontFacing(t,e,n,i){return Se.subVectors(n,e),Ae.subVectors(t,e),Se.cross(Ae).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 Se.subVectors(this.c,this.b),Ae.subVectors(this.a,this.b),.5*Se.cross(Ae).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Fe.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Fe.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return Fe.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return Fe.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Fe.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;Te.subVectors(i,n),Be.subVectors(r,n),Pe.subVectors(t,n);const a=Te.dot(Pe),h=Be.dot(Pe);if(a<=0&&h<=0)return e.copy(n);Ee.subVectors(t,i);const l=Te.dot(Ee),u=Be.dot(Ee);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(Te,s);ke.subVectors(t,r);const d=Te.dot(ke),p=Be.dot(ke);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(Be,o);const y=l*p-d*u;if(y<=0&&u-l>=0&&d-p>=0)return Ce.subVectors(r,i),o=(u-l)/(u-l+(d-p)),e.copy(i).addScaledVector(Ce,o);const m=1/(y+f+c);return s=f*m,o=c*m,e.copy(n).addScaledVector(Te,s).addScaledVector(Be,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Re{constructor(t=new St(1/0,1/0,1/0),e=new St(-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(Ve.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(Ve.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=Ve.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,Ve):Ve.fromBufferAttribute(i,e),Ve.applyMatrix4(t.matrixWorld),this.expandByPoint(Ve);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),Le.copy(n.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}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,Ve),Ve.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(Je),We.subVectors(this.max,Je),qe.subVectors(t.a,Je),De.subVectors(t.b,Je),Xe.subVectors(t.c,Je),Ze.subVectors(De,qe),je.subVectors(Xe,De),Ge.subVectors(qe,Xe);let e=[0,-Ze.z,Ze.y,0,-je.z,je.y,0,-Ge.z,Ge.y,Ze.z,0,-Ze.x,je.z,0,-je.x,Ge.z,0,-Ge.x,-Ze.y,Ze.x,0,-je.y,je.x,0,-Ge.y,Ge.x,0];return!!He(e,qe,De,Xe,We)&&(e=[1,0,0,0,1,0,0,0,1],!!He(e,qe,De,Xe,We)&&($e.crossVectors(Ze,je),e=[$e.x,$e.y,$e.z],He(e,qe,De,Xe,We)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ve).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Ve).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()||(Ue[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ue[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ue[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ue[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ue[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ue[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ue[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ue[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ue)),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 Ue=[new St,new St,new St,new St,new St,new St,new St,new St],Ve=new St,Le=new Re,qe=new St,De=new St,Xe=new St,Ze=new St,je=new St,Ge=new St,Je=new St,We=new St,$e=new St,Ye=new St;function He(t,e,n,i,r){for(let s=0,o=t.length-3;s<=o;s+=3){Ye.fromArray(t,s);const o=r.x*Math.abs(Ye.x)+r.y*Math.abs(Ye.y)+r.z*Math.abs(Ye.z),a=e.dot(Ye),h=n.dot(Ye),l=i.dot(Ye);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const Qe=new St,Ke=new vt;let tn=0;class en{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:tn++}),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++)Ke.fromBufferAttribute(this,e),Ke.applyMatrix3(t),this.setXY(e,Ke.x,Ke.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyMatrix3(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyMatrix4(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyNormalMatrix(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.transformDirection(t),this.setXYZ(e,Qe.x,Qe.y,Qe.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=xt(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=bt(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=xt(e,this.array)),e}setX(t,e){return this.normalized&&(e=bt(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=xt(e,this.array)),e}setY(t,e){return this.normalized&&(e=bt(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=xt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=bt(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=xt(e,this.array)),e}setW(t,e){return this.normalized&&(e=bt(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=bt(e,this.array),n=bt(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=bt(e,this.array),n=bt(n,this.array),i=bt(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=bt(e,this.array),n=bt(n,this.array),i=bt(i,this.array),r=bt(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 nn extends en{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class rn extends en{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class sn extends en{constructor(t,e,n){super(new Float32Array(t),e,n)}}const on=new Re,an=new St,hn=new St;class ln{constructor(t=new St,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):on.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;an.subVectors(t,this.center);const e=an.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(an,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):(hn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(an.copy(t.center).add(hn)),this.expandByPoint(an.copy(t.center).sub(hn))),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}}let un=0;const cn=new Xt,dn=new me,pn=new St,fn=new Re,yn=new Re,mn=new St;class gn extends lt{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:un++}),this.uuid=ft(),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)?rn:nn)(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 _t).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 cn.makeRotationFromQuaternion(t),this.applyMatrix4(cn),this}rotateX(t){return cn.makeRotationX(t),this.applyMatrix4(cn),this}rotateY(t){return cn.makeRotationY(t),this.applyMatrix4(cn),this}rotateZ(t){return cn.makeRotationZ(t),this.applyMatrix4(cn),this}translate(t,e,n){return cn.makeTranslation(t,e,n),this.applyMatrix4(cn),this}scale(t,e,n){return cn.makeScale(t,e,n),this.applyMatrix4(cn),this}lookAt(t){return dn.lookAt(t),dn.updateMatrix(),this.applyMatrix4(dn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(pn).negate(),this.translate(pn.x,pn.y,pn.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 sn(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&&ot("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 Re);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return at("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new St(-1/0,-1/0,-1/0),new St(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];fn.setFromBufferAttribute(t),this.morphTargetsRelative?(mn.addVectors(this.boundingBox.min,fn.min),this.boundingBox.expandByPoint(mn),mn.addVectors(this.boundingBox.max,fn.max),this.boundingBox.expandByPoint(mn)):(this.boundingBox.expandByPoint(fn.min),this.boundingBox.expandByPoint(fn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&at(\'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 ln);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return at("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new St,1/0);if(t){const n=this.boundingSphere.center;if(fn.setFromBufferAttribute(t),e)for(let t=0,r=e.length;t<r;t++){const n=e[t];yn.setFromBufferAttribute(n),this.morphTargetsRelative?(mn.addVectors(fn.min,yn.min),fn.expandByPoint(mn),mn.addVectors(fn.max,yn.max),fn.expandByPoint(mn)):(fn.expandByPoint(yn.min),fn.expandByPoint(yn.max))}fn.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)mn.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(mn));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++)mn.fromBufferAttribute(s,e),o&&(pn.fromBufferAttribute(t,e),mn.add(pn)),i=Math.max(i,n.distanceToSquared(mn))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&at(\'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 at("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 en(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),o=[],a=[];for(let S=0;S<n.count;S++)o[S]=new St,a[S]=new St;const h=new St,l=new St,u=new St,c=new vt,d=new vt,p=new vt,f=new St,y=new St;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 g=this.groups;0===g.length&&(g=[{start:0,count:t.count}]);for(let S=0,A=g.length;S<A;++S){const e=g[S],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 x=new St,b=new St,w=new St,v=new St;function M(t){w.fromBufferAttribute(i,t),v.copy(w);const e=o[t];x.copy(e),x.sub(w.multiplyScalar(w.dot(e))).normalize(),b.crossVectors(v,e);const n=b.dot(a[t])<0?-1:1;s.setXYZW(t,x.x,x.y,x.z,n)}for(let S=0,A=g.length;S<A;++S){const e=g[S],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)M(t.getX(i+0)),M(t.getX(i+1)),M(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 en(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 St,r=new St,s=new St,o=new St,a=new St,h=new St,l=new St,u=new St;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++)mn.fromBufferAttribute(t,e),mn.normalize(),t.setXYZ(e,mn.x,mn.y,mn.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 en(s,i,r)}if(null===this.index)return ot("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new gn,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"})}}let xn=0;class bn extends lt{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:xn++}),this.uuid=ft(),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 ve(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=et,this.stencilZFail=et,this.stencilZPass=et,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){ot(`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:ot(`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!==et&&(n.stencilFail=this.stencilFail),this.stencilZFail!==et&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==et&&(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++}}const wn=new St,vn=new St,Mn=new St,Sn=new St,An=new St,zn=new St,_n=new St;class Tn{constructor(t=new St,e=new St(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,wn)),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=wn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(wn.copy(this.origin).addScaledVector(this.direction,e),wn.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){vn.copy(t).add(e).multiplyScalar(.5),Mn.copy(e).sub(t).normalize(),Sn.copy(this.origin).sub(vn);const r=.5*t.distanceTo(e),s=-this.direction.dot(Mn),o=Sn.dot(this.direction),a=-Sn.dot(Mn),h=Sn.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(vn).addScaledVector(Mn,c),d}intersectSphere(t,e){wn.subVectors(t.center,this.origin);const n=wn.dot(this.direction),i=wn.dot(wn)-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,wn)}intersectTriangle(t,e,n,i,r){An.subVectors(e,t),zn.subVectors(n,t),_n.crossVectors(An,zn);let s,o=this.direction.dot(_n);if(o>0){if(i)return null;s=1}else{if(!(o<0))return null;s=-1,o=-o}Sn.subVectors(this.origin,t);const a=s*this.direction.dot(zn.crossVectors(Sn,zn));if(a<0)return null;const h=s*this.direction.dot(An.cross(Sn));if(h<0)return null;if(a+h>o)return null;const l=-s*Sn.dot(_n);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 Bn extends bn{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ve(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 Kt,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 Cn=new Xt,Pn=new Tn,En=new ln,kn=new St,Nn=new St,In=new St,On=new St,Fn=new St,Rn=new St,Un=new St,Vn=new St;class Ln extends me{constructor(t=new gn,e=new Bn){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){Rn.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=o[n],a=r[n];0!==i&&(Fn.fromBufferAttribute(a,t),s?Rn.addScaledVector(Fn,i):Rn.addScaledVector(Fn.sub(e),i))}e.add(Rn)}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(),En.copy(n.boundingSphere),En.applyMatrix4(r),Pn.copy(t.ray).recast(t.near),!1===En.containsPoint(Pn.origin)){if(null===Pn.intersectSphere(En,kn))return;if(Pn.origin.distanceToSquared(kn)>h(t.far-t.near,2))return}Cn.copy(r).invert(),Pn.copy(t.ray).applyMatrix4(Cn),null!==n.boundingBox&&!1===Pn.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Pn)}}_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=qn(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=qn(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=qn(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=qn(this,s,t,n,h,l,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function qn(t,e,n,i,r,s,o,a,h,l){t.getVertexPosition(a,Nn),t.getVertexPosition(h,In),t.getVertexPosition(l,On);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;Vn.copy(a),Vn.applyMatrix4(t.matrixWorld);const l=n.ray.origin.distanceTo(Vn);return l<n.near||l>n.far?null:{distance:l,point:Vn.clone(),object:t}}(t,e,n,i,Nn,In,On,Un);if(u){const t=new St;Fe.getBarycoord(Un,Nn,In,On,t),r&&(u.uv=Fe.getInterpolatedAttribute(r,a,h,l,t,new vt)),s&&(u.uv1=Fe.getInterpolatedAttribute(s,a,h,l,t,new vt)),o&&(u.normal=Fe.getInterpolatedAttribute(o,a,h,l,t,new St),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new St,materialIndex:0};Fe.getNormal(Nn,In,On,e.normal),u.face=e,u.barycoord=t}return u}const Dn=new St,Xn=new St,Zn=new _t;class jn{constructor(t=new St(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=Dn.subVectors(n,e).cross(Xn.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(Dn),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||Zn.getNormalMatrix(t),i=this.coplanarPoint(Dn).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 Gn{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){ot("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 vt:new St);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 St,i=[],r=[],s=[],o=new St,a=new Xt;for(let d=0;d<=t;d++){const e=d/t;i[d]=this.getTangentAt(e,new St)}r[0]=new St,s[0]=new St;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(yt(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(yt(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 Jn extends Gn{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 vt){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 Wn extends Jn{constructor(t,e,n,i,r,s){super(t,e,n,n,i,r,s),this.isArcCurve=!0,this.type="ArcCurve"}}function $n(){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 Yn=new St,Hn=new $n,Qn=new $n,Kn=new $n;class ti extends Gn{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 St){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]:(Yn.subVectors(i[0],i[1]).add(i[0]),o=Yn);const u=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(Yn.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=Yn),"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),Hn.initNonuniformCatmullRom(o.x,u.x,c.x,a.x,e,n,i),Qn.initNonuniformCatmullRom(o.y,u.y,c.y,a.y,e,n,i),Kn.initNonuniformCatmullRom(o.z,u.z,c.z,a.z,e,n,i)}else"catmullrom"===this.curveType&&(Hn.initCatmullRom(o.x,u.x,c.x,a.x,this.tension),Qn.initCatmullRom(o.y,u.y,c.y,a.y,this.tension),Kn.initCatmullRom(o.z,u.z,c.z,a.z,this.tension));return n.set(Hn.calc(l),Qn.calc(l),Kn.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 St).fromArray(n))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function ei(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 ni(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 ii(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 ri extends Gn{constructor(t=new vt,e=new vt,n=new vt,i=new vt){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new vt){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(ii(t,i.x,r.x,s.x,o.x),ii(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 si extends Gn{constructor(t=new St,e=new St,n=new St,i=new St){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new St){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(ii(t,i.x,r.x,s.x,o.x),ii(t,i.y,r.y,s.y,o.y),ii(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 oi extends Gn{constructor(t=new vt,e=new vt){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new vt){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 vt){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 ai extends Gn{constructor(t=new St,e=new St){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new St){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 St){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 hi extends Gn{constructor(t=new vt,e=new vt,n=new vt){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new vt){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(ni(t,i.x,r.x,s.x),ni(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 li extends Gn{constructor(t=new St,e=new St,n=new St){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new St){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(ni(t,i.x,r.x,s.x),ni(t,i.y,r.y,s.y),ni(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 ui extends Gn{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new vt){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(ei(o,a.x,h.x,l.x,u.x),ei(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 vt).fromArray(n))}return this}}var ci=Object.freeze({__proto__:null,ArcCurve:Wn,CatmullRomCurve3:ti,CubicBezierCurve:ri,CubicBezierCurve3:si,EllipseCurve:Jn,LineCurve:oi,LineCurve3:ai,QuadraticBezierCurve:hi,QuadraticBezierCurve3:li,SplineCurve:ui});class di extends Gn{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 ci[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 ci[n.type]).fromJSON(n))}return this}}let pi=class extends di{constructor(t){super(),this.type="Path",this.currentPoint=new vt,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 oi(this.currentPoint.clone(),new vt(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,i){const r=new hi(this.currentPoint.clone(),new vt(t,e),new vt(n,i));return this.curves.push(r),this.currentPoint.set(n,i),this}bezierCurveTo(t,e,n,i,r,s){const o=new ri(this.currentPoint.clone(),new vt(t,e),new vt(n,i),new vt(r,s));return this.curves.push(o),this.currentPoint.set(r,s),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new ui(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 Jn(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 fi extends pi{constructor(t){super(t),this.uuid=ft(),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 pi).fromJSON(n))}return this}}function yi(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=mi(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=mi(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Ti(n))}r.sort(Si);for(let s=0;s<r.length;s++)n=Ai(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 xi(s,o,n,a,h,l,0),o}function mi(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=Ui(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Ui(o/i|0,t[o],t[o+1],s);return s&&ki(s,s.next)&&(Vi(s),s=s.next),s}function gi(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!ki(i,i.next)&&0!==Ei(i.prev,i,i.next))i=i.next;else{if(Vi(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function xi(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=_i(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?wi(t,i,r,s):bi(t))e.push(h.i,t.i,l.i),Vi(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?xi(t=vi(gi(t),e),e,n,i,r,s,2):2===o&&Mi(t,e,n,i,r,s):xi(gi(t),e,n,i,r,s,1);break}}}function bi(t){const e=t.prev,n=t,i=t.next;if(Ei(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&&Ci(r,a,s,h,o,l,f.x,f.y)&&Ei(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function wi(t,e,n,i){const r=t.prev,s=t,o=t.next;if(Ei(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=_i(p,f,e,n,i),x=_i(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&&Ci(a,u,h,c,l,d,b.x,b.y)&&Ei(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&&Ci(a,u,h,c,l,d,w.x,w.y)&&Ei(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&&Ci(a,u,h,c,l,d,b.x,b.y)&&Ei(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&&Ci(a,u,h,c,l,d,w.x,w.y)&&Ei(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function vi(t,e){let n=t;do{const i=n.prev,r=n.next.next;!ki(i,r)&&Ni(i,n,n.next,r)&&Fi(i,r)&&Fi(r,i)&&(e.push(i.i,n.i,r.i),Vi(n),Vi(n.next),n=t=r),n=n.next}while(n!==t);return gi(n)}function Mi(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Pi(o,t)){let a=Ri(o,t);return o=gi(o,o.next),a=gi(a,a.next),xi(o,e,n,i,r,s,0),void xi(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function Si(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 Ai(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(ki(t,n))return n;do{if(ki(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&&Bi(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);Fi(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&zi(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Ri(n,t);return gi(i,i.next),gi(n,n.next)}function zi(t,e){return Ei(t.prev,t,e.prev)<0&&Ei(e.next,t,t.next)<0}function _i(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 Ti(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 Bi(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 Ci(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&Bi(t,e,n,i,r,s,o,a)}function Pi(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&&Ni(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Fi(t,e)&&Fi(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)&&(Ei(t.prev,t,e.prev)||Ei(t,e.prev,e))||ki(t,e)&&Ei(t.prev,t,t.next)>0&&Ei(e.prev,e,e.next)>0)}function Ei(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function ki(t,e){return t.x===e.x&&t.y===e.y}function Ni(t,e,n,i){const r=Oi(Ei(t,e,n)),s=Oi(Ei(t,e,i)),o=Oi(Ei(n,i,t)),a=Oi(Ei(n,i,e));return r!==s&&o!==a||(!(0!==r||!Ii(t,n,e))||(!(0!==s||!Ii(t,i,e))||(!(0!==o||!Ii(n,t,i))||!(0!==a||!Ii(n,e,i)))))}function Ii(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 Oi(t){return t>0?1:t<0?-1:0}function Fi(t,e){return Ei(t.prev,t,t.next)<0?Ei(t,e,t.next)>=0&&Ei(t,t.prev,e)>=0:Ei(t,e,t.prev)<0||Ei(t,t.next,e)<0}function Ri(t,e){const n=Li(t.i,t.x,t.y),i=Li(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 Ui(t,e,n,i){const r=Li(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 Vi(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 Li(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}class qi{static triangulate(t,e,n=2){return yi(t,e,n)}}class Di{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 Di.area(t)<0}static triangulateShape(t,e){const n=[],i=[],r=[];Xi(t),Zi(n,t);let s=t.length;e.forEach(Xi);for(let a=0;a<e.length;a++)i.push(s),s+=e[a].length,Zi(n,e[a]);const o=qi.triangulate(n,i);for(let a=0;a<o.length;a+=3)r.push(o.slice(a,a+3));return r}}function Xi(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function Zi(t,e){for(let n=0;n<e.length;n++)t.push(e[n].x),t.push(e[n].y)}class ji extends gn{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 sn(p,3)),this.setAttribute("normal",new sn(f,3)),this.setAttribute("uv",new sn(y,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ji(t.width,t.height,t.widthSegments,t.heightSegments)}}const Gi=new St,Ji=new St,Wi=new St,$i=new St,Yi=new St,Hi=new St,Qi=new St;class Ki{constructor(t=new St,e=new St){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){Gi.subVectors(t,this.start),Ji.subVectors(this.end,this.start);const n=Ji.dot(Ji);let i=Ji.dot(Gi)/n;return e&&(i=yt(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=Hi,n=Qi){const i=1e-8*1e-8;let r,s;const o=this.start,a=t.start,h=this.end,l=t.end;Wi.subVectors(h,o),$i.subVectors(l,a),Yi.subVectors(o,a);const u=Wi.dot(Wi),c=$i.dot($i),d=$i.dot(Yi);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=yt(s,0,1);else{const t=Wi.dot(Yi);if(c<=i)s=0,r=yt(-t/u,0,1);else{const e=Wi.dot($i),n=u*c-e*e;r=0!==n?yt((e*d-t*c)/n,0,1):0,s=(e*r+d)/c,s<0?(s=0,r=yt(-t/u,0,1)):s>1&&(s=1,r=yt((e-t)/u,0,1))}}return e.copy(o).addScaledVector(Wi,r),n.copy(a).addScaledVector($i,s),e.distanceToSquared(n)}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:$}})),"undefined"!=typeof window&&(window.__THREE__?ot("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=$);const tr=6378137,er=6356752.314245179;function nr(t,e,n=0,i=1,r=!1){const s=wt.degToRad(t),o=wt.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=n*i;c=t*a*u,d=t*h,p=t*a*l}else{const t=tr*tr,e=(t-er*er)/t,r=tr/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 St(c,d,p)}const ir=134217729;function rr(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 sr(t){return new Float64Array(t)}const or=sr(4),ar=sr(8),hr=sr(12),lr=sr(16),ur=sr(4);function cr(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=ir*z,p=d-(d-z),f=z-p,d=ir*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=T*_,d=ir*T,p=d-(d-T),f=T-p,d=ir*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,or[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,or[1]=b-(g+c)+(c-M),A=x+g,c=A-x,or[2]=x-(A-c)+(g-c),or[3]=A;let C=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,or),P=22204460492503146e-32*o;if(C>=P||-C>=P)return C;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 C;if(P=11093356479670487e-47*o+33306690738754706e-32*Math.abs(C),C+=z*u+B*a-(T*l+_*h),C>=P||-C>=P)return C;w=a*B,d=ir*a,p=d-(d-a),f=a-p,d=ir*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=h*_,d=ir*h,p=d-(d-h),f=h-p,d=ir*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const E=rr(4,or,4,ur,ar);w=z*u,d=ir*z,p=d-(d-z),f=z-p,d=ir*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=T*l,d=ir*T,p=d-(d-T),f=T-p,d=ir*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const k=rr(E,ar,4,ur,hr);w=a*u,d=ir*a,p=d-(d-a),f=a-p,d=ir*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=h*l,d=ir*h,p=d-(d-h),f=h-p,d=ir*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const N=rr(k,hr,4,ur,lr);return lr[N-1]}(t,e,n,i,r,s,l)}const dr=Math.pow(2,-52),pr=new Uint32Array(512);class fr{static from(t,e=wr,n=vr){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 fr(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=yr(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=yr(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=gr(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];xr(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(cr(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]=yr(t[2*A],t[2*A+1],M.x,M.y);xr(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)<=dr&&Math.abs(a-z)<=dr)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],cr(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],cr(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],cr(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=pr[--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(mr(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<pr.length&&(pr[r++]=a)}else{if(0===r)break;t=pr[--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 yr(t,e,n,i){const r=t-n,s=e-i;return r*r+s*s}function mr(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 gr(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 xr(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;br(t,n+i>>1,r),e[t[n]]>e[t[i]]&&br(t,n,i),e[t[r]]>e[t[i]]&&br(t,r,i),e[t[n]]>e[t[r]]&&br(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;br(t,r,s)}t[n+1]=t[s],t[s]=o,i-r+1>=s-n?(xr(t,e,r,i),xr(t,e,n,s-1)):(xr(t,e,n,s-1),xr(t,e,r,i))}}function br(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function wr(t){return t[0]}function vr(t){return t[1]}function Mr(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 Sr=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=Mr(i,h[u]);if(0===t)return!n.ignoreBoundary;t&&(l=!0)}return l},Ar=1e-6,zr=1e-12,_r=Math.PI,Tr=_r/2,Br=_r/4,Cr=2*_r,Pr=180/_r,Er=_r/180,kr=Math.abs,Nr=Math.atan,Ir=Math.atan2,Or=Math.cos,Fr=Math.exp,Rr=Math.hypot,Ur=Math.log,Vr=Math.sin,Lr=Math.sign||function(t){return t>0?1:t<0?-1:0},qr=Math.sqrt,Dr=Math.tan;function Xr(t){return t>1?Tr:t<-1?-Tr:Math.asin(t)}function Zr(t){return(t=Vr(t/2))*t}function jr(){}function Gr(t,e){t&&Wr.hasOwnProperty(t.type)&&Wr[t.type](t,e)}var Jr={Feature:function(t,e){Gr(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)Gr(n[i].geometry,e)}},Wr={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){$r(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)$r(n[i],e,0)},Polygon:function(t,e){Yr(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)Yr(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)Gr(n[i],e)}};function $r(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 Yr(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)$r(t[n],e,1);e.polygonEnd()}function Hr(t,e){t&&Jr.hasOwnProperty(t.type)?Jr[t.type](t,e):Gr(t,e)}var Qr,Kr,ts,es,ns,is,rs,ss,os,as,hs,ls,us,cs,ds,ps,fs=new l,ys=new l,ms={point:jr,lineStart:jr,lineEnd:jr,polygonStart:function(){fs=new l,ms.lineStart=gs,ms.lineEnd=xs},polygonEnd:function(){var t=+fs;ys.add(t<0?Cr+t:t),this.lineStart=this.lineEnd=this.point=jr},sphere:function(){ys.add(Cr)}};function gs(){ms.point=bs}function xs(){ws(Qr,Kr)}function bs(t,e){ms.point=ws,Qr=t,Kr=e,ts=t*=Er,es=Or(e=(e*=Er)/2+Br),ns=Vr(e)}function ws(t,e){var n=(t*=Er)-ts,i=n>=0?1:-1,r=i*n,s=Or(e=(e*=Er)/2+Br),o=Vr(e),a=ns*o,h=es*s+a*Or(r),l=a*i*Vr(r);fs.add(Ir(l,h)),ts=t,es=s,ns=o}function vs(t){return[Ir(t[1],t[0]),Xr(t[2])]}function Ms(t){var e=t[0],n=t[1],i=Or(n);return[i*Or(e),i*Vr(e),Vr(n)]}function Ss(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function As(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 zs(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function _s(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Ts(t){var e=qr(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var Bs,Cs,Ps,Es,ks,Ns,Is,Os,Fs,Rs,Us,Vs,Ls,qs,Ds,Xs,Zs={point:js,lineStart:Js,lineEnd:Ws,polygonStart:function(){Zs.point=$s,Zs.lineStart=Ys,Zs.lineEnd=Hs,cs=new l,ms.polygonStart()},polygonEnd:function(){ms.polygonEnd(),Zs.point=js,Zs.lineStart=Js,Zs.lineEnd=Ws,fs<0?(is=-(ss=180),rs=-(os=90)):cs>Ar?os=90:cs<-1e-6&&(rs=-90),ps[0]=is,ps[1]=ss},sphere:function(){is=-(ss=180),rs=-(os=90)}};function js(t,e){ds.push(ps=[is=t,ss=t]),e<rs&&(rs=e),e>os&&(os=e)}function Gs(t,e){var n=Ms([t*Er,e*Er]);if(us){var i=As(us,n),r=As([i[1],-i[0],0],i);Ts(r),r=vs(r);var s,o=t-as,a=o>0?1:-1,h=r[0]*Pr*a,l=kr(o)>180;l^(a*as<h&&h<a*t)?(s=r[1]*Pr)>os&&(os=s):l^(a*as<(h=(h+360)%360-180)&&h<a*t)?(s=-r[1]*Pr)<rs&&(rs=s):(e<rs&&(rs=e),e>os&&(os=e)),l?t<as?Qs(is,t)>Qs(is,ss)&&(ss=t):Qs(t,ss)>Qs(is,ss)&&(is=t):ss>=is?(t<is&&(is=t),t>ss&&(ss=t)):t>as?Qs(is,t)>Qs(is,ss)&&(ss=t):Qs(t,ss)>Qs(is,ss)&&(is=t)}else ds.push(ps=[is=t,ss=t]);e<rs&&(rs=e),e>os&&(os=e),us=n,as=t}function Js(){Zs.point=Gs}function Ws(){ps[0]=is,ps[1]=ss,Zs.point=js,us=null}function $s(t,e){if(us){var n=t-as;cs.add(kr(n)>180?n+(n>0?360:-360):n)}else hs=t,ls=e;ms.point(t,e),Gs(t,e)}function Ys(){ms.lineStart()}function Hs(){$s(hs,ls),ms.lineEnd(),kr(cs)>Ar&&(is=-(ss=180)),ps[0]=is,ps[1]=ss,us=null}function Qs(t,e){return(e-=t)<0?e+360:e}function Ks(t,e){return t[0]-e[0]}function to(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function eo(t){var e,n,i,r,s,o,a;if(os=ss=-(is=rs=1/0),ds=[],Hr(t,Zs),n=ds.length){for(ds.sort(Ks),e=1,s=[i=ds[0]];e<n;++e)to(i,(r=ds[e])[0])||to(i,r[1])?(Qs(i[0],r[1])>Qs(i[0],i[1])&&(i[1]=r[1]),Qs(r[0],i[1])>Qs(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=Qs(i[1],r[0]))>o&&(o=a,is=r[0],ss=i[1])}return ds=ps=null,is===1/0||rs===1/0?[[NaN,NaN],[NaN,NaN]]:[[is,rs],[ss,os]]}var no={sphere:jr,point:io,lineStart:so,lineEnd:ho,polygonStart:function(){no.lineStart=lo,no.lineEnd=uo},polygonEnd:function(){no.lineStart=so,no.lineEnd=ho}};function io(t,e){t*=Er;var n=Or(e*=Er);ro(n*Or(t),n*Vr(t),Vr(e))}function ro(t,e,n){++Bs,Ps+=(t-Ps)/Bs,Es+=(e-Es)/Bs,ks+=(n-ks)/Bs}function so(){no.point=oo}function oo(t,e){t*=Er;var n=Or(e*=Er);qs=n*Or(t),Ds=n*Vr(t),Xs=Vr(e),no.point=ao,ro(qs,Ds,Xs)}function ao(t,e){t*=Er;var n=Or(e*=Er),i=n*Or(t),r=n*Vr(t),s=Vr(e),o=Ir(qr((o=Ds*s-Xs*r)*o+(o=Xs*i-qs*s)*o+(o=qs*r-Ds*i)*o),qs*i+Ds*r+Xs*s);Cs+=o,Ns+=o*(qs+(qs=i)),Is+=o*(Ds+(Ds=r)),Os+=o*(Xs+(Xs=s)),ro(qs,Ds,Xs)}function ho(){no.point=io}function lo(){no.point=co}function uo(){po(Vs,Ls),no.point=io}function co(t,e){Vs=t,Ls=e,t*=Er,e*=Er,no.point=po;var n=Or(e);qs=n*Or(t),Ds=n*Vr(t),Xs=Vr(e),ro(qs,Ds,Xs)}function po(t,e){t*=Er;var n=Or(e*=Er),i=n*Or(t),r=n*Vr(t),s=Vr(e),o=Ds*s-Xs*r,a=Xs*i-qs*s,h=qs*r-Ds*i,l=Rr(o,a,h),u=Xr(l),c=l&&-u/l;Fs.add(c*o),Rs.add(c*a),Us.add(c*h),Cs+=u,Ns+=u*(qs+(qs=i)),Is+=u*(Ds+(Ds=r)),Os+=u*(Xs+(Xs=s)),ro(qs,Ds,Xs)}function fo(t){Bs=Cs=Ps=Es=ks=Ns=Is=Os=0,Fs=new l,Rs=new l,Us=new l,Hr(t,no);var e=+Fs,n=+Rs,i=+Us,r=Rr(e,n,i);return r<zr&&(e=Ns,n=Is,i=Os,Cs<Ar&&(e=Ps,n=Es,i=ks),(r=Rr(e,n,i))<zr)?[NaN,NaN]:[Ir(n,e)*Pr,Xr(i/r)*Pr]}function yo(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 mo(t,e){return kr(t)>_r&&(t-=Math.round(t/Cr)*Cr),[t,e]}function go(t,e,n){return(t%=Cr)?e||n?yo(bo(t),wo(e,n)):bo(t):e||n?wo(e,n):mo}function xo(t){return function(e,n){return kr(e+=t)>_r&&(e-=Math.round(e/Cr)*Cr),[e,n]}}function bo(t){var e=xo(t);return e.invert=xo(-t),e}function wo(t,e){var n=Or(t),i=Vr(t),r=Or(e),s=Vr(e);function o(t,e){var o=Or(e),a=Or(t)*o,h=Vr(t)*o,l=Vr(e),u=l*n+a*i;return[Ir(h*r-u*s,a*n-l*i),Xr(u*r+h*s)]}return o.invert=function(t,e){var o=Or(e),a=Or(t)*o,h=Vr(t)*o,l=Vr(e),u=l*r-h*s;return[Ir(h*r+l*s,a*n+u*i),Xr(u*n-a*i)]},o}function vo(t){function e(e){return(e=t(e[0]*Er,e[1]*Er))[0]*=Pr,e[1]*=Pr,e}return t=go(t[0]*Er,t[1]*Er,t.length>2?t[2]*Er:0),e.invert=function(e){return(e=t.invert(e[0]*Er,e[1]*Er))[0]*=Pr,e[1]*=Pr,e},e}function Mo(t,e){(e=Ms(e))[0]-=t,Ts(e);var n,i=(n=-e[1])>1?0:n<-1?_r:Math.acos(n);return((-e[2]<0?-i:i)+Cr-Ar)%Cr}function So(){var t,e=[];return{point:function(e,n,i){t.push([e,n,i])},lineStart:function(){e.push(t=[])},lineEnd:jr,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Ao(t,e){return kr(t[0]-e[0])<Ar&&kr(t[1]-e[1])<Ar}function zo(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 _o(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(Ao(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 zo(i,t,null,!0)),h.push(n.o=new zo(i,null,n,!1)),a.push(n=new zo(o,t,null,!1)),h.push(n.o=new zo(o,null,n,!0))}}),a.length){for(h.sort(e),To(a),To(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 To(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 Bo(t){return kr(t[0])<=_r?t[0]:Lr(t[0])*((kr(t[0])+_r)%Cr-_r)}function Co(t,e){var n=Bo(e),i=e[1],r=Vr(i),s=[Vr(n),-Or(n),0],o=0,a=0,h=new l;1===r?i=Tr+Ar:-1===r&&(i=-Tr-Ar);for(var u=0,c=t.length;u<c;++u)if(p=(d=t[u]).length)for(var d,p,f=d[p-1],y=Bo(f),m=f[1]/2+Br,g=Vr(m),x=Or(m),b=0;b<p;++b,y=v,g=S,x=A,f=w){var w=d[b],v=Bo(w),M=w[1]/2+Br,S=Vr(M),A=Or(M),z=v-y,_=z>=0?1:-1,T=_*z,B=T>_r,C=g*S;if(h.add(Ir(C*_*Vr(T),x*A+C*Or(T))),o+=B?z+_*Cr:z,B^y>=n^v>=n){var P=As(Ms(f),Ms(w));Ts(P);var E=As(s,P);Ts(E);var k=(B^z>=0?-1:1)*Xr(E[2]);(i>k||i===k&&(P[0]||P[1]))&&(a+=B^z>=0?1:-1)}}return(o<-1e-6||o<Ar&&h<-1e-12)^1&a}function Po(t,e,n,i){return function(r){var s,o,a,h=e(r),l=So(),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=v(o);var t=Co(s,i);o.length?(c||(r.polygonStart(),c=!0),_o(o,ko,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(Eo))}return d}}function Eo(t){return t.length>1}function ko(t,e){return((t=t.x)[0]<0?t[1]-Tr-Ar:Tr-t[1])-((e=e.x)[0]<0?e[1]-Tr-Ar:Tr-e[1])}mo.invert=mo;var No=Po(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?_r:-_r,h=kr(s-n);kr(h-_r)<Ar?(t.point(n,i=(i+o)/2>0?Tr:-Tr),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(s,i),e=0):r!==a&&h>=_r&&(kr(n-r)<Ar&&(n-=r*Ar),kr(s-a)<Ar&&(s-=a*Ar),i=function(t,e,n,i){var r,s,o=Vr(t-n);return kr(o)>Ar?Nr((Vr(e)*(s=Or(i))*Vr(n)-Vr(i)*(r=Or(e))*Vr(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*Tr,i.point(-_r,r),i.point(0,r),i.point(_r,r),i.point(_r,0),i.point(_r,-r),i.point(0,-r),i.point(-_r,-r),i.point(-_r,0),i.point(-_r,r);else if(kr(t[0]-e[0])>Ar){var s=t[0]<e[0]?_r:-_r;r=n*s/2,i.point(-s,r),i.point(0,r),i.point(s,r)}else i.point(e[0],e[1])},[-_r,-Tr]);function Io(t){var e=Or(t),n=2*Er,i=e>0,r=kr(e)>Ar;function s(t,n){return Or(t)*Or(n)>e}function o(t,n,i){var r=[1,0,0],s=As(Ms(t),Ms(n)),o=Ss(s,s),a=s[0],h=o-a*a;if(!h)return!i&&t;var l=e*o/h,u=-e*a/h,c=As(r,s),d=_s(r,l);zs(d,_s(s,u));var p=c,f=Ss(d,p),y=Ss(p,p),m=f*f-y*(Ss(d,d)-1);if(!(m<0)){var g=qr(m),x=_s(p,(-f-g)/y);if(zs(x,d),x=vs(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=kr(A-_r)<Ar;if(!z&&S<M&&(b=M,M=S,S=b),z||A<Ar?z?M+S>0^x[1]<(kr(x[0]-w)<Ar?M:S):M<=x[1]&&x[1]<=S:A>_r^(w<=x[0]&&x[0]<=v)){var _=_s(p,(-f+g)/y);return zs(_,d),[x,vs(_)]}}}function a(e,n){var r=i?t:_r-t,s=0;return e<-r?s|=1:e>r&&(s|=2),n<-r?s|=4:n>r&&(s|=8),s}return Po(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?_r:-_r),d):0;if(!e&&(l=h=y)&&t.lineStart(),y!==h&&(!(p=o(e,f))||Ao(e,p)||Ao(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&&Ao(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=Or(e),a=Vr(e),h=i*n;null==r?(r=e+i*Cr,s=e-h/2):(r=Mo(o,r),s=Mo(o,s),(i>0?r<s:r>s)&&(r+=i*Cr));for(var l,u=r;i>0?u>s:u<s;u-=h)l=vs([o,-a*Or(u),-a*Vr(u)]),t.point(l[0],l[1])}}(s,t,n,r,e,i)},i?[0,-t]:[-_r,t-_r])}var Oo,Fo,Ro,Uo,Vo=1e9,Lo=-Vo;function qo(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 kr(i[0]-t)<Ar?r>0?0:3:kr(i[0]-n)<Ar?r>0?2:1:kr(i[1]-e)<Ar?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=So(),M={point:S,lineStart:function(){M.point=A,l&&l.push(u=[]);g=!0,m=!1,f=y=NaN},lineEnd:function(){h&&(A(c,d),p&&m&&w.rejoin(),h.push(w.result()));M.point=S,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=v(h)).length;(n||r)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),r&&_o(h,a,e,s,o),o.polygonEnd());b=o,h=l=u=null}};function S(t,e){r(t,e)&&b.point(t,e)}function A(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(Lo,Math.min(Vo,f)),y=Math.max(Lo,Math.min(Vo,y))],w=[s=Math.max(Lo,Math.min(Vo,s)),o=Math.max(Lo,Math.min(Vo,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 M}}var Do={sphere:jr,point:jr,lineStart:function(){Do.point=Zo,Do.lineEnd=Xo},lineEnd:jr,polygonStart:jr,polygonEnd:jr};function Xo(){Do.point=Do.lineEnd=jr}function Zo(t,e){Fo=t*=Er,Ro=Vr(e*=Er),Uo=Or(e),Do.point=jo}function jo(t,e){t*=Er;var n=Vr(e*=Er),i=Or(e),r=kr(t-Fo),s=Or(r),o=i*Vr(r),a=Uo*n-Ro*i*s,h=Ro*n+Uo*i*s;Oo.add(Ir(qr(o*o+a*a),h)),Fo=t,Ro=n,Uo=i}var Go=[null,null],Jo={type:"LineString",coordinates:Go};function Wo(t,e){return Go[0]=t,Go[1]=e,n=Jo,Oo=new l,Hr(n,Do),+Oo;var n}var $o={Feature:function(t,e){return Ho(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)if(Ho(n[i].geometry,e))return!0;return!1}},Yo={Sphere:function(){return!0},Point:function(t,e){return Qo(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Qo(n[i],e))return!0;return!1},LineString:function(t,e){return Ko(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Ko(n[i],e))return!0;return!1},Polygon:function(t,e){return ta(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(ta(n[i],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)if(Ho(n[i],e))return!0;return!1}};function Ho(t,e){return!(!t||!Yo.hasOwnProperty(t.type))&&Yo[t.type](t,e)}function Qo(t,e){return 0===Wo(t,e)}function Ko(t,e){for(var n,i,r,s=0,o=t.length;s<o;s++){if(0===(i=Wo(t[s],e)))return!0;if(s>0&&(r=Wo(t[s],t[s-1]))>0&&n<=r&&i<=r&&(n+i-r)*(1-Math.pow((n-i)/r,2))<zr*r)return!0;n=i}return!1}function ta(t,e){return!!Co(t.map(ea),na(e))}function ea(t){return(t=t.map(na)).pop(),t}function na(t){return[t[0]*Er,t[1]*Er]}var ia=t=>t,ra=1/0,sa=ra,oa=-ra,aa=oa,ha={point:function(t,e){t<ra&&(ra=t);t>oa&&(oa=t);e<sa&&(sa=e);e>aa&&(aa=e)},lineStart:jr,lineEnd:jr,polygonStart:jr,polygonEnd:jr,result:function(){var t=[[ra,sa],[oa,aa]];return oa=aa=-(sa=ra=1/0),t}};function la(t){return function(e){var n=new ua;for(var i in t)n[i]=t[i];return n.stream=e,n}}function ua(){}function ca(t,e,n){var i=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=i&&t.clipExtent(null),Hr(n,t.stream(ha)),e(ha.result()),null!=i&&t.clipExtent(i),t}function da(t,e,n){return ca(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)}ua.prototype={constructor:ua,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 pa=Or(30*Er);function fa(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=qr(w*w+v*v+M*M),A=Xr(M/=S),z=kr(kr(M)-1)<Ar||kr(s-c)<Ar?(s+c)/2:Ir(v,w),_=t(z,A),T=_[0],B=_[1],C=T-i,P=B-r,E=x*C-g*P;(E*E/b>e||kr((g*C+x*P)/b-.5)>.3||o*d+a*p+h*f<pa)&&(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=Ms([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 la({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var ya,ma=la({point:function(t,e){this.stream.point(t*Er,e*Er)}});function ga(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=Or(s),a=Vr(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 xa(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=No,A=null,z=ia,_=.5;function T(t){return h(t[0]*Er,t[1]*Er)}function B(t){return(t=h.invert(t[0],t[1]))&&[t[0]*Pr,t[1]*Pr]}function C(){var t=ga(c,0,0,w,v,b).apply(null,e(f,y)),i=ga(c,d-t[0],p-t[1],w,v,b);return n=go(m,g,x),a=yo(e,i),h=yo(n,a),o=fa(a,_),P()}function P(){return l=u=null,T}return T.stream=function(t){return l&&u===t?l:l=ma(function(t){return la({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,P()):S},T.postclip=function(t){return arguments.length?(z=t,A=i=r=s=null,P()):z},T.clipAngle=function(t){return arguments.length?(S=+t?Io(M=t*Er):(M=null,No),P()):M*Pr},T.clipExtent=function(t){return arguments.length?(z=null==t?(A=i=r=s=null,ia):qo(A=+t[0][0],i=+t[0][1],r=+t[1][0],s=+t[1][1]),P()):null==A?null:[[A,i],[r,s]]},T.scale=function(t){return arguments.length?(c=+t,C()):c},T.translate=function(t){return arguments.length?(d=+t[0],p=+t[1],C()):[d,p]},T.center=function(t){return arguments.length?(f=t[0]%360*Er,y=t[1]%360*Er,C()):[f*Pr,y*Pr]},T.rotate=function(t){return arguments.length?(m=t[0]%360*Er,g=t[1]%360*Er,x=t.length>2?t[2]%360*Er:0,C()):[m*Pr,g*Pr,x*Pr]},T.angle=function(t){return arguments.length?(b=t%360*Er,C()):b*Pr},T.reflectX=function(t){return arguments.length?(w=t?-1:1,C()):w<0},T.reflectY=function(t){return arguments.length?(v=t?-1:1,C()):v<0},T.precision=function(t){return arguments.length?(o=fa(a,_=t*t),P()):qr(_)},T.fitExtent=function(t,e){return da(T,t,e)},T.fitSize=function(t,e){return function(t,e,n){return da(t,[[0,0],e],n)}(T,t,e)},T.fitWidth=function(t,e){return function(t,e,n){return ca(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 ca(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,C()}}(function(){return t})()}function ba(t,e){return[t,Ur(Dr((Tr+e)/2))]}function wa(t,e){return[t,e]}function va(t,e){var n=Or(e),i=1+Or(t)*n;return[n*Vr(t)/i,Vr(e)/i]}ba.invert=function(t,e){return[t,2*Nr(Fr(e))-Tr]},wa.invert=wa,va.invert=(ya=function(t){return 2*Nr(t)},function(t,e){var n=qr(t*t+e*e),i=ya(n),r=Vr(i),s=Or(i);return[Ir(t*r,n*s),Xr(n&&e*r/n)]});const Ma=1e-6;class Sa{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)>Ma||Math.abs(this._y1-r)>Ma)&&(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 Aa{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 za{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 Sa: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 Sa: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 Sa: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 Aa;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 _a=2*Math.PI,Ta=Math.pow;function Ba(t){return t[0]}function Ca(t){return t[1]}function Pa(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class Ea{static from(t,e=Ba,n=Ca,i){return new Ea("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 fr(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=Pa(e[2*s],e[2*s+1],r);e[2*s]=t[0],e[2*s+1]=t[1]}this._delaunator=new fr(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 za(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=Ta(e-h[2*t],2)+Ta(n-h[2*t+1],2);const c=i[t];let d=c;do{let i=a[d];const c=Ta(e-h[2*i],2)+Ta(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&&Ta(e-h[2*d],2)+Ta(n-h[2*d+1],2)<u)return d;break}}while(d!==c);return l}render(t){const e=null==t?t=new Sa: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 Sa: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,_a)}return n&&n.value()}renderHull(t){const e=null==t?t=new Sa: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 Aa;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new Sa: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 Aa;return this.renderTriangle(t,e),e.value()}}const ka=Math.PI,Na=ka/2,Ia=180/ka,Oa=ka/180,Fa=Math.atan2,Ra=Math.cos,Ua=Math.max,Va=Math.min,La=Math.sin,qa=Math.sign||function(t){return t>0?1:t<0?-1:0},Da=Math.sqrt;function Xa(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Za(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 ja(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Ga(t){var e=Da(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return[t[0]/e,t[1]/e,t[2]/e]}function Ja(t){return[Fa(t[1],t[0])*Ia,(e=Ua(-1,Va(1,t[2])),(e>1?Na:e<-1?-Na:Math.asin(e))*Ia)];var e}function Wa(t){const e=t[0]*Oa,n=t[1]*Oa,i=Ra(n);return[i*Ra(e),i*La(e),La(n)]}function $a(t){return Xa((t=t.map(t=>Wa(t)))[0],Za(t[2],t[1]))}function Ya(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=vo(t[e]),i=xa(va).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*Da(s);r.forEach(e=>t[e]=[o,0]),t.push([0,o]),t.push([-o,0]),t.push([0,-o]);const a=Ea.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]&&!($a(t.map(t=>e[t]))<0))for(let e,i=0;i<3;i++)e=(i+1)%3,n.add(a([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=Wa([i,r]);do{o=s,s=null,a=n(l,Wa(e[o])),t[o].forEach(t=>{let i=n(l,Wa(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(Wa);return Ja(Ga(ja(ja(Za(n[1],n[0]),Za(n[2],n[1])),Za(n[0],n[2]))))})}(n,t),{polygons:l,centers:u}=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=Wa(n[0]),e=Wa(n[1]),s=Ga(ja(t,e)),a=Ga(Za(t,e)),h=Za(s,a),l=[s,Za(s,h),Za(Za(s,h),h),Za(Za(Za(s,h),h),h)].map(Ja).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=Ha(n[t[0][3][0]],n[t[0][3][1]],r[e[0]]),s=Ha(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),c=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}(l),d=function(t,e){const n=new Set,i=[];t.map(t=>{if(!($a(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),p=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=a([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:u,neighbors:r,polygons:l,mesh:c,hull:d,urquhart:p,find:s}}function Ha(t,e,n){t=Wa(t),e=Wa(e),n=Wa(n);const i=qa(Xa(Za(e,t),n));return Ja(Ga(ja(t,e)).map(t=>i*t))}function Qa(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Ka(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function th(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function eh(){}var nh=.7,ih=1/nh,rh="\\\\s*([+-]?\\\\d+)\\\\s*",sh="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*",oh="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*",ah=/^#([0-9a-f]{3,8})$/,hh=new RegExp(`^rgb\\\\(${rh},${rh},${rh}\\\\)$`),lh=new RegExp(`^rgb\\\\(${oh},${oh},${oh}\\\\)$`),uh=new RegExp(`^rgba\\\\(${rh},${rh},${rh},${sh}\\\\)$`),ch=new RegExp(`^rgba\\\\(${oh},${oh},${oh},${sh}\\\\)$`),dh=new RegExp(`^hsl\\\\(${sh},${oh},${oh}\\\\)$`),ph=new RegExp(`^hsla\\\\(${sh},${oh},${oh},${sh}\\\\)$`),fh={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 yh(){return this.rgb().formatHex()}function mh(){return this.rgb().formatRgb()}function gh(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=ah.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?xh(e):3===n?new vh(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?bh(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?bh(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=hh.exec(t))?new vh(e[1],e[2],e[3],1):(e=lh.exec(t))?new vh(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=uh.exec(t))?bh(e[1],e[2],e[3],e[4]):(e=ch.exec(t))?bh(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=dh.exec(t))?Th(e[1],e[2]/100,e[3]/100,1):(e=ph.exec(t))?Th(e[1],e[2]/100,e[3]/100,e[4]):fh.hasOwnProperty(t)?xh(fh[t]):"transparent"===t?new vh(NaN,NaN,NaN,0):null}function xh(t){return new vh(t>>16&255,t>>8&255,255&t,1)}function bh(t,e,n,i){return i<=0&&(t=e=n=NaN),new vh(t,e,n,i)}function wh(t,e,n,i){return 1===arguments.length?((r=t)instanceof eh||(r=gh(r)),r?new vh((r=r.rgb()).r,r.g,r.b,r.opacity):new vh):new vh(t,e,n,null==i?1:i);var r}function vh(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function Mh(){return`#${_h(this.r)}${_h(this.g)}${_h(this.b)}`}function Sh(){const t=Ah(this.opacity);return`${1===t?"rgb(":"rgba("}${zh(this.r)}, ${zh(this.g)}, ${zh(this.b)}${1===t?")":`, ${t})`}`}function Ah(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function zh(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function _h(t){return((t=zh(t))<16?"0":"")+t.toString(16)}function Th(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ch(t,e,n,i)}function Bh(t){if(t instanceof Ch)return new Ch(t.h,t.s,t.l,t.opacity);if(t instanceof eh||(t=gh(t)),!t)return new Ch;if(t instanceof Ch)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 Ch(o,a,h,t.opacity)}function Ch(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Ph(t){return(t=(t||0)%360)<0?t+360:t}function Eh(t){return Math.max(0,Math.min(1,t||0))}function kh(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Ka(eh,gh,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:yh,formatHex:yh,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Bh(this).formatHsl()},formatRgb:mh,toString:mh}),Ka(vh,wh,th(eh,{brighter(t){return t=null==t?ih:Math.pow(ih,t),new vh(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?nh:Math.pow(nh,t),new vh(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new vh(zh(this.r),zh(this.g),zh(this.b),Ah(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:Mh,formatHex:Mh,formatHex8:function(){return`#${_h(this.r)}${_h(this.g)}${_h(this.b)}${_h(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Sh,toString:Sh})),Ka(Ch,function(t,e,n,i){return 1===arguments.length?Bh(t):new Ch(t,e,n,null==i?1:i)},th(eh,{brighter(t){return t=null==t?ih:Math.pow(ih,t),new Ch(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?nh:Math.pow(nh,t),new Ch(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 vh(kh(t>=240?t-240:t+120,r,i),kh(t,r,i),kh(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new Ch(Ph(this.h),Eh(this.s),Eh(this.l),Ah(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=Ah(this.opacity);return`${1===t?"hsl(":"hsla("}${Ph(this.h)}, ${100*Eh(this.s)}%, ${100*Eh(this.l)}%${1===t?")":`, ${t})`}`}}));var Nh=t=>()=>t;function Ih(t){return 1===(t=+t)?Oh: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):Nh(isNaN(e)?n:e)}}function Oh(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Nh(isNaN(t)?e:t)}var Fh=function t(e){var n=Ih(e);function i(t,e){var i=n((t=wh(t)).r,(e=wh(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=Oh(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 Rh(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 Uh(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]=jh(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 Vh(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function Lh(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function qh(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]=jh(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var Dh=/[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,Xh=new RegExp(Dh.source,"g");function Zh(t,e){var n,i,r,s=Dh.lastIndex=Xh.lastIndex=0,o=-1,a=[],h=[];for(t+="",e+="";(n=Dh.exec(t))&&(i=Xh.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:Lh(n,i)})),s=Xh.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 jh(t,e){var n,i,r=typeof e;return null==e||"boolean"===r?Nh(e):("number"===r?Lh:"string"===r?(n=gh(e))?(e=n,Fh):Zh:e instanceof gh?Fh:e instanceof Date?Vh:(i=e,!ArrayBuffer.isView(i)||i instanceof DataView?Array.isArray(e)?Uh:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?qh:Lh:Rh))(t,e)}function Gh(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function Jh(t){return+t}var Wh=[0,1];function $h(t){return t}function Yh(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function Hh(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Yh(r,i),s=n(o,s)):(i=Yh(i,r),s=n(s,o)),function(t){return s(i(t))}}function Qh(t,e,n){var i=Math.min(t.length,e.length)-1,r=new Array(i),s=new Array(i),a=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++a<i;)r[a]=Yh(t[a],t[a+1]),s[a]=n(e[a],e[a+1]);return function(e){var n=o(t,e,1,i)-1;return s[n](r[n](e))}}function Kh(){var t,e,n,i,r,s,o=Wh,a=Wh,h=jh,l=$h;function u(){var t,e,n,h=Math.min(o.length,a.length);return l!==$h&&(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?Qh:Hh,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),Lh)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,Jh),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=Gh,u()},c.clamp=function(t){return arguments.length?(l=!!t||$h,u()):l!==$h},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 tl(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 el(t){return(t=tl(Math.abs(t)))?t[1]:NaN}var nl,il=/^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;function rl(t){if(!(e=il.exec(t)))throw new Error("invalid format: "+t);var e;return new sl({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 sl(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 ol(t,e){var n=tl(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")}rl.prototype=sl.prototype,sl.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 al={"%":(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)=>ol(100*t,e),r:ol,s:function(t,e){var n=tl(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(nl=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")+tl(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function hl(t){return t}var ll,ul,cl,dl=Array.prototype.map,pl=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function fl(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?hl:(e=dl.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?hl:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(dl.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=rl(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"):al[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=al[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?pl[8+nl/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=rl(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(el(e)/3))),r=Math.pow(10,-i),s=pl[8+i/3];return function(t){return n(r*t)+s}}}}function yl(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?b(e,t,n):b(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=rl(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(el(e)/3)))-el(Math.abs(t)))}(s,o))||(i.precision=r),cl(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,el(e)-el(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,-el(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return ul(i)}function ml(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?x(e,t,n):x(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 yl(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=b(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 gl(){var t=Kh()($h,$h);return t.copy=function(){return e=t,gl().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Qa.apply(t,arguments),ml(t)}function xl(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const v=180*Wo(t,i)/Math.PI;if(v>e){const M=(s=t,o=(r=i)[0]*Er,a=r[1]*Er,h=s[0]*Er,l=s[1]*Er,u=Or(a),c=Vr(a),d=Or(l),p=Vr(l),f=u*Or(o),y=u*Vr(o),m=d*Or(h),g=d*Vr(h),x=2*Xr(qr(Zr(l-a)+u*d*Zr(h-o))),b=Vr(x),w=x?function(t){var e=Vr(t*=x)/b,n=Vr(x-t)/b,i=n*f+e*m,r=n*y+e*g,s=n*c+e*p;return[Ir(r,i)*Pr,Ir(s,qr(i*i+r*r))*Pr]}:function(){return[o*Pr,a*Pr]},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 bl(t,e,n=!1){return n?(r=t,((i=e)&&$o.hasOwnProperty(i.type)?$o[i.type]:Ho)(i,r)):Sr(t,e);var i,r}function wl(t,e){const n={type:"Polygon",coordinates:t},[[i,r],[s,o]]=eo(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=>bl(t,n,a))}function vl(t,{resolution:e=1/0,bbox:n,projection:i}={}){const r=xl(t,e),s=v(r),o=wl(t,e),h=[...s,...o],l={type:"Polygon",coordinates:t},[[u,c],[d,p]]=eo(l),f=u>d||p>=89||c<=-89;let y=[];if(f){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=Ya(e.points)}return e};return e._vx=function(t){return"object"==typeof t&&"type"in t?fo(t)[0]:0 in t?t[0]:void 0},e._vy=function(t){return"object"==typeof t&&"type"in t?fo(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=>$a(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=>Wo(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||Wo([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}(h).triangles(),e=new Map(h.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(!bl(t.properties.circumcenter,l,f))return}y.push(...i)}})}else if(o.length){const t=fr.from(h);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=>h[t]);if(n.some(t=>t<s.length)){if(!bl([0,1].map(t=>w(i,e=>e[t])),l,f))continue}y.push(...n)}}else{const{vertices:t,holes:e=[]}=W(r);y=M(t,e,2)}let m=n?[n[0],n[2]]:a(h,t=>t[0]),g=n?[n[1],n[3]]:a(h,t=>t[1]);if(i){const[t,e]=i([m[0],g[0]]),[n,r]=i([m[1],g[1]]);m=[t,n],g=[-e,-r]}const x=gl(m,[0,1]),b=gl(g,[0,1]),S=h.map(([t,e])=>{if(i){const[n,r]=i([t,e]);return[x(n),b(-r)]}return[x(t),b(e)]});return{contour:r,triangles:{points:h,indices:y,uvs:S}}}ll=fl({thousands:",",grouping:[3],currency:["$",""]}),ul=ll.format,cl=ll.formatPrefix;const Ml=(new gn).setAttribute?"setAttribute":"addAttribute";function Sl(t,e,n){return W(t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=nr(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=nr(t,i,e,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 Al(t,e,n,i,r){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:Sl([t.points],e,r).vertices,uvs:n}}const zl=({polygonGeoJson:t,startHeight:n,endHeight:i,curvatureResolution:r=1,hasSide:s=!0,hasBottom:o=!1,hasTop:a=!1,projection:h="sphere",bbox:l})=>{t.forEach(t=>{e(t)||t.reverse()});const u="function"==typeof h?h:void 0,{contour:c,triangles:d}=vl(t,{resolution:r,bbox:l,projection:u});let p,f={};s&&(f=function(t,e,n,i){const{vertices:r,holes:s}=Sl(t,e,i),{vertices:o}=Sl(t,n,i),a=v([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}}(c,null!=n?n:i,null!=i?i:n,h),p=f.topVerts);let y=[];(o||a)&&(y=v(d.uvs));let m={};o&&(m=Al(d,n,y,!1,h));let g={};return a&&(g=Al(d,i,y,!0,h)),{contour:c,triangles:d,sideTorso:f,bottomCap:m,topCap:g,topVerts:p}};class _l extends gn{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}=zl(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 en(new Float64Array(l),3)),this.setIndex(d),this[Ml]("position",new sn(l,3)),this[Ml]("uv",new sn(c,2)),this.computeVertexNormals()}}class Tl extends gn{constructor(t=[],e="none",n,i=!1,r){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 Xt),p(this,"useRTC",!1),p(this,"rtcCenter",new St(0,0,0)),this.shape=e,this.useRTC=i,n&&(this.shapeFunction=n),r&&this.rtcCenter.copy(r),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 St(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof vt?new St(t.x,t.y,0):t instanceof St?t:Array.isArray(t)&&2===t.length?new St(t[0],t[1],0):Array.isArray(t)&&3===t.length?new St(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n,i){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,void 0!==n&&(this.useRTC=n),i?this.rtcCenter.copy(i):this.useRTC&&this._points.length>0&&this.rtcCenter.copy(this._points[0]),e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const t=new en(new Float32Array(6*this.pointCount),3),e=new en(new Float32Array(6*this.pointCount),3),n=new en(new Float32Array(6*this.pointCount),3),i=new en(new Float32Array(2*this.pointCount),1),r=new en(new Float32Array(2*this.pointCount),1),s=new en(new Float32Array(2*this.pointCount),1),o=new en(new Float32Array(4*this.pointCount),2),a=new en(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(){if(!this._points[0])return;const t=this.getAttribute("position"),e=this.getAttribute("previous"),n=this.getAttribute("next");let i=0,r=0,s=0;const o=this._points[0],a=this.useRTC?this.getRelativePosition(o):o;e.setXYZ(r,a.x,a.y,a.z),r+=1,e.setXYZ(r,a.x,a.y,a.z),r+=1;for(let u=0;u<this.pointCount;u++){const o=this._points[u],a=this.useRTC?this.getRelativePosition(o):o;t.setXYZ(i,a.x,a.y,a.z),i+=1,t.setXYZ(i,a.x,a.y,a.z),i+=1,u<this.pointCount-1&&(e.setXYZ(r,a.x,a.y,a.z),r+=1,e.setXYZ(r,a.x,a.y,a.z),r+=1),u>0&&u+1<=this.pointCount&&(n.setXYZ(s,a.x,a.y,a.z),s+=1,n.setXYZ(s,a.x,a.y,a.z),s+=1)}const h=this._points[this.pointCount-1],l=this.useRTC?this.getRelativePosition(h):h;n.setXYZ(s,l.x,l.y,l.z),s+=1,n.setXYZ(s,l.x,l.y,l.z),s+=1,t.needsUpdate=!0,e.needsUpdate=!0,n.needsUpdate=!0,this.useRTC?(this.boundingSphere=new ln(new St,1/0),this.boundingBox=new Re(new St(-1/0,-1/0,-1/0),new St(1/0,1/0,1/0))):(this.computeBoundingSphere(),this.computeBoundingBox())}getRelativePosition(t){return new St(t.x-this.rtcCenter.x,t.y-this.rtcCenter.y,t.z-this.rtcCenter.z)}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())}getRTCCenter(){return this.rtcCenter.clone()}setUseRTC(t){this.useRTC!==t&&(this.useRTC=t,this._points.length>0&&(this.useRTC&&this.rtcCenter.copy(this._points[0]),this.updateGeometry()))}getUseRTC(){return this.useRTC}setRTCCenter(t){this.rtcCenter.copy(t),this._points.length>0&&this.updateGeometry()}}var Bl=t=>{const{setPointWidth:e,nodes:n,useRTC:i=!1,rtcCenter:r}=t,s=new Tl(void 0,void 0,void 0,i,r);return s.setPoints(n,e,i,r),s};const Cl=(t,e,n,i=2)=>{const r=[];if(!t||!e||!n)return r;let s=0;for(let a=0;a<e.length;a++)s+=e[a]*i;const o=(t.length-s)/n;r.length=o;for(let a=0;a<o;a++){const e=new Array(n);for(let i=0;i<n;i++)e[i]=t[s+a*n+i];r[a]=e}return r},Pl=({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);if(2===i)for(let e=0;e<s;e++)a[e]=[t[o],t[o+1]],o+=2;else if(3===i)for(let e=0;e<s;e++)a[e]=[t[o],t[o+1],t[o+2]],o+=3;else for(let e=0;e<s;e++){const n=new Array(i);for(let e=0;e<i;e++)n[e]=t[o+e];a[e]=n,o+=i}r[n]=a}if(n){const e=(t.length-o)/n;s.length=e;for(let i=0;i<e;i++){const e=new Array(n);for(let i=0;i<n;i++)e[i]=t[o+i];s[i]=e,o+=n}}}return{coordinatesArr:r,metaArray:s}};function El(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 en(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 kl(t,e=0){const n=function(t,e=!1){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 gn;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}h.addGroup(l,t,u),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=El(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=El(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;h.morphAttributes[u].push(n)}}return h}(t,!1);if(!n)return null;if(e){const i=null!==t[0].index;let r=0;for(let s=0;s<t.length;s++){const o=t[s];let a;if(i)a=o.index.count;else{if(void 0===o.attributes.position)return null;a=o.attributes.position.count}if(1===e)n.addGroup(r,a,s);else if(2===e&&o.groups.length>0)for(const t of o.groups)n.addGroup(r+t.start,Math.min(t.count,a),t.materialIndex);r+=a}if(2===e)return 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}(n)}return n}var Nl=(t,e)=>{var n,i;const r={},s=t[0],o=(null==(n=s.getUseRTC)?void 0:n.call(s))&&(null==(i=s.getRTCCenter)?void 0:i.call(s)),a=kl(t,null!=e?e:0),h=[],l=Object.keys(a.attributes);return a.index&&l.push("index"),l.forEach(t=>{const e="index"===t?a.index:a.attributes[t];r[t]={array:e.array,itemSize:e.itemSize},h.push(e.array.buffer)}),e&&(r.groups=a.groups),o&&(r.rtcCenter={x:o.x,y:o.y,z:o.z}),a.dispose(),t.forEach(t=>{t.dispose()}),{message:r,transfer:h}};function Il({coordinatesArr:t,metaArray:e,globalMeta:n,hasTop:i,topFirst:r,hasBottom:s,hasSide:o,projection:a="sphere",curvatureResolution:h,bbox:l}){return t.map((t,p)=>{var f,y;const m=e&&e[p]||n||[],g=null!=(f=m[0])?f:0,x=null!=(y=m[1])?y: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 _l([n],c(u({},s),{startHeight:i,endHeight:o}))})({coordinate:t,projection:a,startHeight:x,height:g,hasTop:null==i||i,topFirst:null!=r&&r,hasBottom:null==s||s,hasSide:null==o||o,curvatureResolution:null!=h?h:1,bbox:l})})}const Ol={ArcCurve:Wn,CatmullRomCurve3:ti,CubicBezierCurve:ri,CubicBezierCurve3:si,EllipseCurve:Jn,LineCurve:oi,LineCurve3:ai,QuadraticBezierCurve:hi,QuadraticBezierCurve3:li,SplineCurve:ui};class Fl extends gn{constructor(t=new fi([new vt(.5,.5),new vt(-.5,.5),new vt(-.5,-.5),new vt(.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:Rl,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 St,z=new St,_=new St),d||(m=0,p=0,f=0,y=0);const B=t.extractPoints(l);let C=B.shape;const P=B.holes;if(!Di.isClockWise(C)){C=C.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];Di.isClockWise(e)&&(P[t]=e.reverse())}}function E(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}}E(C),P.forEach(E);const k=P.length,N=C;for(let e=0;e<k;e++){const t=P[e];C=C.concat(t)}function I(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const O=C.length;function F(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 vt(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 vt(i/s,r/s)}const R=[];for(let e=0,n=N.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),R[e]=F(N[e],N[i],N[r]);const U=[];let V,L,q=R.concat();for(let e=0,n=k;e<n;e++){const t=P[e];V=[];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),V[e]=F(t[e],t[i],t[r]);U.push(V),q=q.concat(V)}if(0===m)L=Di.triangulateShape(N,P);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=N.length;e<n;e++){const n=I(N[e],R[e],s);j(n.x,n.y,-r),0===i&&t.push(n)}for(let t=0,n=k;t<n;t++){const n=P[t];V=U[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=I(n[t],V[t],s);j(e.x,e.y,-r),0===i&&o.push(e)}0===i&&e.push(o)}}L=Di.triangulateShape(t,e)}const D=L.length,X=f+y;for(let e=0;e<O;e++){const t=d?I(C[e],q[e],X):C[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<O;t++){const n=d?I(C[t],q[t],X):C[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=N.length;e<r;e++){const t=I(N[e],R[e],i);j(t.x,t.y,c+n)}for(let e=0,r=P.length;e<r;e++){const t=P[e];V=U[e];for(let e=0,r=t.length;e<r;e++){const r=I(t[e],V[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 Z(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=O*t,s=O*(t+1);J(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 G(t,e,r){W(t),W(e),W(r);const s=i.length/3,o=x.generateTopUV(n,i,s-3,s-2,s-1);$(o[0]),$(o[1]),$(o[2])}function J(t,e,r,s){W(t),W(e),W(s),W(e),W(r),W(s);const o=i.length/3,a=x.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);$(a[0]),$(a[1]),$(a[3]),$(a[1]),$(a[2]),$(a[3])}function W(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function $(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=O*t;if(w)for(let n=0;n<D;n++){const t=L[n];G(t[2]+e,t[1]+e,t[0]+e)}if(t=u+2*m,e=O*t,b)for(let n=0;n<D;n++){const t=L[n];G(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<D;t++){const e=L[t];G(e[2],e[1],e[0])}if(b)for(let t=0;t<D;t++){const e=L[t];G(e[0]+O*u,e[1]+O*u,e[2]+O*u)}}n.addGroup(t,i.length/3-t,0)}(),v&&function(){const t=i.length/3;let e=0;Z(N,e),e+=N.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];Z(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new sn(i,3)),this.setAttribute("uv",new sn(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 Ol[i.type]).fromJSON(i)),new Fl(n,t.options)}}const Rl={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 vt(s,o),new vt(a,h),new vt(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 vt(o,1-h),new vt(l,1-c),new vt(d,1-f),new vt(y,1-g)]:[new vt(a,1-h),new vt(u,1-c),new vt(p,1-f),new vt(m,1-g)]}};const Ul=1.25,Vl=32,Ll=Math.pow(2,-24),ql=Symbol("SKIP_GENERATION");function Dl(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function Xl(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 en(i,1));for(let t=0;t<n;t++)i[t]=t}}function Zl(t,e){const n=Dl(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 jl(t,e){if(!t.groups||!t.groups.length)return Zl(t,e);const n=[],i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=Dl(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 Gl(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 Jl(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)*Ll}}return r}function Wl(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 $l(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 Yl(t,e){e.set(t)}function Hl(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 Ql(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 Kl(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 tu=32,eu=(t,e)=>t.candidate-e.candidate,nu=new Array(tu).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),iu=new Float32Array(6);class ru{constructor(){this.boundingData=new Float32Array(6)}}function su(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 ou(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 au,hu,lu,uu;const cu=Math.pow(2,32);function du(t){return"count"in t?1:1+du(t.left)+du(t.right)}function pu(t,e,n){return au=new Float32Array(n),hu=new Uint32Array(n),lu=new Uint16Array(n),uu=new Uint8Array(n),fu(t,e)}function fu(t,e){const n=t/4,i=t/2,r="count"in e,s=e.boundingData;for(let o=0;o<6;o++)au[n+o]=s[o];if(r)return e.buffer?(uu.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(hu[n+6]=e.offset,lu[i+14]=e.count,lu[i+15]=65535,t+Vl);{const{left:i,right:r,splitAxis:s}=e;let o=fu(t+Vl,i);const a=o/Vl-t/Vl;if(a>cu)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return hu[n+6]=a,hu[n+7]=s,fu(o,r)}}function yu(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?ou:su,y=Dl(d),m=new Float32Array(6);let g=!1;const x=new ru;return Gl(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=$l(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===s)o=$l(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=Kl(t);let h=Ul*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)/tu;if(r<8){const e=[...nu];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;Ql(r,n,o)}e.sort(eu);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?Ql(r,n,s.rightCacheBounds):(Ql(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=Kl(c)/s);let f=0;0!==u&&(f=Kl(d)/s);const y=1+Ul*(p*l+f*u);y<h&&(o=t,h=y,a=i.candidate)}}else{for(let t=0;t<tu;t++){const e=nu[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>=tu&&(e=31);const s=nu[e];s.count++,Ql(r,n,s.bounds)}const e=nu[31];Yl(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=nu[t],n=nu[t+1];Hl(e.bounds,n.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let n=0;n<31;n++){const e=nu[n],i=e.count,l=e.bounds,u=nu[n+1].rightCacheBounds;0!==i&&(0===d?Yl(l,iu):Hl(l,iu,iu)),d+=i;let c=0,p=0;0!==d&&(c=Kl(iu)/s);const f=r-d;0!==f&&(p=Kl(u)/s);const y=1+Ul*(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 ru,o=i,a=x-i;n.left=s,Gl(e,o,a,s.boundingData,m),t(s,o,a,m,u+1);const h=new ru,l=x,c=r-a;n.right=h,Gl(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 mu(t,e){const n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=t.geometry;let r,s;if(e.indirect){const n=jl(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=Jl(i,0,o.length,o),s=[{offset:0,count:o.length}]}else{Xl(i,e);const t=Zl(i,e.range)[0];r=Jl(i,t.offset,t.count),s=jl(i,e.range)}t._roots=s.map(i=>{const s=yu(t,r,i.offset,i.count,e),o=du(s),a=new n(Vl*o);return pu(0,s,a),a})}class gu{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}}gu.prototype.setFromBox=function(){const t=new St;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 xu=function(){const t=new St,e=new St,n=new St;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}}(),bu=function(){const t=new vt,e=new St,n=new St;return function(i,r,s,o){xu(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))}}}(),wu=function(){const t=new St,e=new St,n=new jn,i=new Ki;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}}(),vu=["x","y","z"],Mu=1e-15;function Su(t){return Math.abs(t)<Mu}class Au extends Fe{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new St),this.satBounds=new Array(4).fill().map(()=>new gu),this.points=[this.a,this.b,this.c],this.plane=new jn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Ki,this.needsUpdate=!0}intersectsSphere(t){return wu(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<Mu?y<Mu||m<Mu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(n)):y<Mu?m<Mu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):m<Mu&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Au.prototype.closestPointToSegment=function(){const t=new St,e=new St,n=new Ki;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]),bu(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)}}(),Au.prototype.intersectsTriangle=function(){const t=new Au,e=new gu,n=new gu,i=new St,r=new St,s=new St,o=new St,a=new Ki,h=new Ki,l=new St,u=new vt,c=new vt;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 Su(o)?Su(a)?d(t,e,n,r):(n&&(n.start.copy(s.start),n.end.copy(s.start)),t.containsPoint(s.start)):Su(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!(!Su(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(Su(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)&&(!!Su(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);Su(w)&&(w=0),Su(v)&&(v=0),Su(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);Su(z)&&(z=0),Su(_)&&(_=0),Su(T)&&(T=0);const B=z*_,C=z*T;if(B>0&&C>0)return!1;r.copy(x.normal),s.copy(b.normal);const P=r.cross(s);let E=0,k=Math.abs(P.x);const N=Math.abs(P.y);N>k&&(k=N,E=1);Math.abs(P.z)>k&&(E=2);const I=vu[E],O=this.a[I],F=this.b[I],R=this.c[I],U=e.a[I],V=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,U,V,L,B,C,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)}}(),Au.prototype.distanceToPoint=function(){const t=new St;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Au.prototype.distanceToTriangle=function(){const t=new St,e=new St,n=["a","b","c"],i=new Ki,r=new Ki;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]),bu(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 zu{constructor(t,e,n){this.isOrientedBox=!0,this.min=new St,this.max=new St,this.matrix=new Xt,this.invMatrix=new Xt,this.points=new Array(8).fill().map(()=>new St),this.satAxes=new Array(3).fill().map(()=>new St),this.satBounds=new Array(3).fill().map(()=>new gu),this.alignedSatBounds=new Array(3).fill().map(()=>new gu),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}}zu.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}}(),zu.prototype.intersectsBox=function(){const t=new gu;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}}(),zu.prototype.intersectsTriangle=function(){const t=new Au,e=new Array(3),n=new gu,i=new gu,r=new St;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}}(),zu.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}}(),zu.prototype.distanceToPoint=function(){const t=new St;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),zu.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new Ki),n=new Array(12).fill().map(()=>new Ki),i=new St,r=new St;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];bu(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 _u{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 Tu extends _u{constructor(){super(()=>new Au)}}const Bu=new Tu;function Cu(t,e){return 65535===e[t+15]}function Pu(t,e){return e[t+6]}function Eu(t,e){return e[t+14]}function ku(t){return t+8}function Nu(t,e){return t+8*e[t+6]}function Iu(t,e){return e[t+7]}function Ou(t){return t}class Fu{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 Ru=new Fu;let Uu,Vu;const Lu=[],qu=new _u(()=>new Re);function Du(t,e,n,i,r,s){Uu=qu.getPrimitive(),Vu=qu.getPrimitive(),Lu.push(Uu,Vu),Ru.setBuffer(t._roots[e]);const o=Xu(0,t.geometry,n,i,r,s);Ru.clearBuffer(),qu.releasePrimitive(Uu),qu.releasePrimitive(Vu),Lu.pop(),Lu.pop();const a=Lu.length;return a>0&&(Vu=Lu[a-1],Uu=Lu[a-2]),o}function Xu(t,e,n,i,r=null,s=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru;let u=2*t;if(Cu(u,h)){const e=Pu(t,l),n=Eu(u,h);return Wl(t,a,Uu),i(e,n,!1,o,s+t/8,Uu)}{let u=function(t){const{uint16Array:e,uint32Array:n}=Ru;let i=2*t;for(;!Cu(i,e);)i=2*(t=ku(t));return Pu(t,n)},c=function(t){const{uint16Array:e,uint32Array:n}=Ru;let i=2*t;for(;!Cu(i,e);)i=2*(t=Nu(t,n));return Pu(t,n)+Eu(i,e)};const d=ku(t),p=Nu(t,l);let f,y,m,g,x=d,b=p;if(r&&(m=Uu,g=Vu,Wl(x,a,m),Wl(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=Uu,Wl(x,a,m));const w=n(m,Cu(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&&Xu(x,e,n,i,r,s,o+1);if(v)return!0;g=Vu,Wl(b,a,g);const M=n(g,Cu(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&&Xu(b,e,n,i,r,s,o+1);return!!S}}const Zu=new St,ju=new St;const Gu=parseInt($)>=169,Ju=parseInt($)<=161,Wu=new St,$u=new St,Yu=new St,Hu=new vt,Qu=new vt,Ku=new vt,tc=new St,ec=new St,nc=new St,ic=new St;function rc(t,e,n,i,r,s,o,a,h,l,u){Wu.fromBufferAttribute(e,s),$u.fromBufferAttribute(e,o),Yu.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,Wu,$u,Yu,ic,h,l,u);if(c){if(i){Hu.fromBufferAttribute(i,s),Qu.fromBufferAttribute(i,o),Ku.fromBufferAttribute(i,a),c.uv=new vt;const t=Fe.getInterpolation(ic,Wu,$u,Yu,Hu,Qu,Ku,c.uv);Gu||(c.uv=t)}if(r){Hu.fromBufferAttribute(r,s),Qu.fromBufferAttribute(r,o),Ku.fromBufferAttribute(r,a),c.uv1=new vt;const t=Fe.getInterpolation(ic,Wu,$u,Yu,Hu,Qu,Ku,c.uv1);Gu||(c.uv1=t),Ju&&(c.uv2=c.uv1)}if(n){tc.fromBufferAttribute(n,s),ec.fromBufferAttribute(n,o),nc.fromBufferAttribute(n,a),c.normal=new St;const e=Fe.getInterpolation(ic,Wu,$u,Yu,tc,ec,nc,c.normal);c.normal.dot(t.direction)>0&&c.normal.multiplyScalar(-1),Gu||(c.normal=e)}const e={a:s,b:o,c:a,normal:new St,materialIndex:0};if(Fe.getNormal(Wu,$u,Yu,e.normal),c.face=e,c.faceIndex=s,Gu){const t=new St;Fe.getBarycoord(ic,Wu,$u,Yu,t),c.barycoord=t}}return c}function sc(t){return t&&t.isMaterial?t.side:t}function oc(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=rc(n,p,f,y,m,h,l,u,sc(e[x]),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=x,!r)return t;r.push(t)}}}}else{const t=rc(n,p,f,y,m,h,l,u,sc(e),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=0,!r)return t;r.push(t)}}return null}function ac(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 hc(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,ac(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function lc(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(Cu(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=ku(t),r=Nu(t,o);let a=s,l=!1,u=!1;if(e){if(!a){const t=i/8+n/Vl,s=r/8+n/Vl;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 uc(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 cc(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),ac(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function dc(t,e,n,i,r,s,o){Ru.setBuffer(t._roots[e]),pc(0,t,n,i,r,s,o),Ru.clearBuffer()}function pc(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru,u=2*t;if(Cu(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++)oc(h,e,n,u,s,o,a)}(e,n,i,Pu(t,l),Eu(u,h),r,s,o)}else{const h=ku(t);uc(h,a,i,s,o)&&pc(h,e,n,i,r,s,o);const u=Nu(t,l);uc(u,a,i,s,o)&&pc(u,e,n,i,r,s,o)}}const fc=["x","y","z"];function yc(t,e,n,i,r,s){Ru.setBuffer(t._roots[e]);const o=mc(0,t,n,i,r,s);return Ru.clearBuffer(),o}function mc(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=Ru;let l=2*t;if(Cu(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=oc(a,e,n,c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,Pu(t,h),Eu(l,a),r,s)}{const a=Iu(t,h),l=fc[a],u=i.direction[l]>=0;let c,d;u?(c=ku(t),d=Nu(t,h)):(c=Nu(t,h),d=ku(t));const p=uc(c,o,i,r,s)?mc(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=uc(d,o,i,r,s)?mc(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const gc=new Re,xc=new Au,bc=new Au,wc=new Xt,vc=new zu,Mc=new zu;function Sc(t,e,n,i){Ru.setBuffer(t._roots[e]);const r=Ac(0,t,n,i);return Ru.clearBuffer(),r}function Ac(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=Ru;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),vc.set(n.boundingBox.min,n.boundingBox.max,i),r=vc);if(!Cu(h,o)){const o=ku(t),h=Nu(t,a);Wl(o,s,gc);if(r.intersectsBox(gc)&&Ac(o,e,n,i,r))return!0;Wl(h,s,gc);return!!(r.intersectsBox(gc)&&Ac(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=Pu(t,a),f=Eu(h,o);if(wc.copy(i).invert(),n.boundsTree){Wl(t,s,Mc),Mc.matrix.copy(wc),Mc.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Mc.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(ac(bc,e,l,u),bc.needsUpdate=!0,t.intersectsTriangle(bc))return!0;return!1}})}{const t=Dl(n);for(let e=3*p,n=3*(f+p);e<n;e+=3){ac(xc,e,l,u),xc.a.applyMatrix4(wc),xc.b.applyMatrix4(wc),xc.c.applyMatrix4(wc),xc.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(ac(bc,e,c,d),bc.needsUpdate=!0,xc.intersectsTriangle(bc))return!0}}}}const zc=new Xt,_c=new zu,Tc=new zu,Bc=new St,Cc=new St,Pc=new St,Ec=new St;function kc(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),_c.set(e.boundingBox.min,e.boundingBox.max,n),_c.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=Bu.getPrimitive(),p=Bu.getPrimitive();let f=Bc,y=Cc,m=null,g=null;r&&(m=Pc,g=Ec);let x=1/0,b=null,w=null;return zc.copy(n).invert(),Tc.matrix.copy(zc),t.shapecast({boundsTraverseOrder:t=>_c.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(Tc.min.copy(t.min),Tc.max.copy(t.max),Tc.needsUpdate=!0),!0),intersectsRange:(t,i)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>Tc.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,r)=>{for(let o=e,a=e+r;o<a;o++){ac(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++){ac(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=Dl(e);r<o;r++){ac(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++){ac(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}}}}),Bu.releasePrimitive(d),Bu.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(zc),y.applyMatrix4(zc),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}function Nc(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(Cu(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=ku(n),i=Nu(n,o);let r=l,a=!1,u=!1;if(e){if(!r){const n=t/8+s/Vl,o=i/8+s/Vl;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 Ic(t,e,n,i,r,s,o){Ru.setBuffer(t._roots[e]),Oc(0,t,n,i,r,s,o),Ru.clearBuffer()}function Oc(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru,u=2*t;if(Cu(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++)oc(h,e,n,l?l[u]:u,s,o,a)}(e,n,i,Pu(t,l),Eu(u,h),r,s,o)}else{const h=ku(t);uc(h,a,i,s,o)&&Oc(h,e,n,i,r,s,o);const u=Nu(t,l);uc(u,a,i,s,o)&&Oc(u,e,n,i,r,s,o)}}const Fc=["x","y","z"];function Rc(t,e,n,i,r,s){Ru.setBuffer(t._roots[e]);const o=Uc(0,t,n,i,r,s);return Ru.clearBuffer(),o}function Uc(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=Ru;let l=2*t;if(Cu(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=oc(a,e,n,h?h[c]:c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,Pu(t,h),Eu(l,a),r,s)}{const a=Iu(t,h),l=Fc[a],u=i.direction[l]>=0;let c,d;u?(c=ku(t),d=Nu(t,h)):(c=Nu(t,h),d=ku(t));const p=uc(c,o,i,r,s)?Uc(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=uc(d,o,i,r,s)?Uc(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Vc=new Re,Lc=new Au,qc=new Au,Dc=new Xt,Xc=new zu,Zc=new zu;function jc(t,e,n,i){Ru.setBuffer(t._roots[e]);const r=Gc(0,t,n,i);return Ru.clearBuffer(),r}function Gc(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=Ru;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),Xc.set(n.boundingBox.min,n.boundingBox.max,i),r=Xc);if(!Cu(h,o)){const o=ku(t),h=Nu(t,a);Wl(o,s,Vc);if(r.intersectsBox(Vc)&&Gc(o,e,n,i,r))return!0;Wl(h,s,Vc);return!!(r.intersectsBox(Vc)&&Gc(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=Pu(t,a),f=Eu(h,o);if(Dc.copy(i).invert(),n.boundsTree){Wl(t,s,Zc),Zc.matrix.copy(Dc),Zc.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Zc.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(ac(qc,3*e.resolveTriangleIndex(n),l,u),qc.needsUpdate=!0,t.intersectsTriangle(qc))return!0;return!1}})}{const t=Dl(n);for(let n=p,i=f+p;n<i;n++){const i=e.resolveTriangleIndex(n);ac(Lc,3*i,l,u),Lc.a.applyMatrix4(Dc),Lc.b.applyMatrix4(Dc),Lc.c.applyMatrix4(Dc),Lc.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(ac(qc,e,c,d),qc.needsUpdate=!0,Lc.intersectsTriangle(qc))return!0}}}}const Jc=new Xt,Wc=new zu,$c=new zu,Yc=new St,Hc=new St,Qc=new St,Kc=new St;function td(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Wc.set(e.boundingBox.min,e.boundingBox.max,n),Wc.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=Bu.getPrimitive(),p=Bu.getPrimitive();let f=Yc,y=Hc,m=null,g=null;r&&(m=Qc,g=Kc);let x=1/0,b=null,w=null;return Jc.copy(n).invert(),$c.matrix.copy(Jc),t.shapecast({boundsTraverseOrder:t=>Wc.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&($c.min.copy(t.min),$c.max.copy(t.max),$c.needsUpdate=!0),!0),intersectsRange:(i,r)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>$c.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);ac(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);ac(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=Dl(e);o<a;o++){ac(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);ac(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}}}}),Bu.releasePrimitive(d),Bu.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(Jc),y.applyMatrix4(Jc),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}const ed=new Ru.constructor,nd=new Ru.constructor,id=new _u(()=>new Re),rd=new Re,sd=new Re,od=new Re,ad=new Re;let hd=!1;function ld(t,e,n,i,r,s=0,o=0,a=0,h=0,l=null,u=!1){let c,d;u?(c=nd,d=ed):(c=ed,d=nd);const p=c.float32Array,f=c.uint32Array,y=c.uint16Array,m=d.float32Array,g=d.uint32Array,x=d.uint16Array,b=2*e,w=Cu(2*t,y),v=Cu(b,x);let M=!1;if(v&&w)M=u?r(Pu(e,g),Eu(2*e,x),Pu(t,f),Eu(2*t,y),h,o+e/8,a,s+t/8):r(Pu(t,f),Eu(2*t,y),Pu(e,g),Eu(2*e,x),a,s+t/8,h,o+e/8);else if(v){const l=id.getPrimitive();Wl(e,m,l),l.applyMatrix4(n);const c=ku(t),d=Nu(t,f);Wl(c,p,rd),Wl(d,p,sd);const y=l.intersectsBox(rd),g=l.intersectsBox(sd);M=y&&ld(e,c,i,n,r,o,s,h,a+1,l,!u)||g&&ld(e,d,i,n,r,o,s,h,a+1,l,!u),id.releasePrimitive(l)}else{const c=ku(e),d=Nu(e,g);Wl(c,m,od),Wl(d,m,ad);const y=l.intersectsBox(od),x=l.intersectsBox(ad);if(y&&x)M=ld(t,c,n,i,r,s,o,a,h+1,l,u)||ld(t,d,n,i,r,s,o,a,h+1,l,u);else if(y)if(w)M=ld(t,c,n,i,r,s,o,a,h+1,l,u);else{const e=id.getPrimitive();e.copy(od).applyMatrix4(n);const l=ku(t),d=Nu(t,f);Wl(l,p,rd),Wl(d,p,sd);const y=e.intersectsBox(rd),m=e.intersectsBox(sd);M=y&&ld(c,l,i,n,r,o,s,h,a+1,e,!u)||m&&ld(c,d,i,n,r,o,s,h,a+1,e,!u),id.releasePrimitive(e)}else if(x)if(w)M=ld(t,d,n,i,r,s,o,a,h+1,l,u);else{const e=id.getPrimitive();e.copy(ad).applyMatrix4(n);const l=ku(t),c=Nu(t,f);Wl(l,p,rd),Wl(c,p,sd);const y=e.intersectsBox(rd),m=e.intersectsBox(sd);M=y&&ld(d,l,i,n,r,o,s,h,a+1,e,!u)||m&&ld(d,c,i,n,r,o,s,h,a+1,e,!u),id.releasePrimitive(e)}}return M}const ud=new zu,cd=new Re,dd={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class pd{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/Vl;t<e;t++){const e=8*t;Cu(2*e,r)||(i[e+6]=i[e+6]/8-t)}}}(r));const o=new pd(e,c(u({},n),{[ql]:!0}));if(o._roots=r,o._indirectBuffer=s||null,n.setIndex){const n=e.getIndex();if(null===n){const n=new en(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({},dd),{[ql]:!1}),e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[ql]||(mu(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Re))),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/Vl;for(let e=0;e<o;e++){const n=8*e;Cu(2*n,s)&&(r[n+6]+=t)}}}}refit(t=null){return(this.indirect?Nc:lc)(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=Cu(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=ku(s),a=Nu(s,i),l=Iu(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?Ic:dc;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?Rc:yc;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?jc:Sc;for(let s=0,o=i.length;s<o&&(n=r(this,s,t,e),!n);s++);return n}shapecast(t){const e=Bu.getPrimitive(),n=this.indirect?cc:hc;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=Du(this,u,r,s,i,h),a)break;h+=t.byteLength/Vl}return Bu.releasePrimitive(e),a}bvhcast(t,e,n){let{intersectsRanges:i,intersectsTriangles:r}=n;const s=Bu.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);ac(s,3*e,o,a)}:t=>{ac(s,3*t,o,a)},l=Bu.getPrimitive(),u=t.geometry.index,c=t.geometry.attributes.position,d=t.indirect?e=>{const n=t.resolveTriangleIndex(e);ac(l,3*n,u,c)}:t=>{ac(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(hd)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");hd=!0;const r=t._roots,s=e._roots;let o,a=0,h=0;const l=(new Xt).copy(n).invert();for(let u=0,c=r.length;u<c;u++){ed.setBuffer(r[u]),h=0;const t=id.getPrimitive();Wl(Ou(0),ed.float32Array,t),t.applyMatrix4(l);for(let e=0,r=s.length;e<r&&(nd.setBuffer(s[e]),o=ld(0,0,n,l,i,a,h,0,0,t),nd.clearBuffer(),h+=s[e].byteLength/Vl,!o);e++);if(id.releasePrimitive(t),ed.clearBuffer(),a+=r[u].byteLength/Vl,o)break}return hd=!1,o}(this,t,e,i)}intersectsBox(t,e){return ud.set(t.min,t.max,e),ud.needsUpdate=!0,this.shapecast({intersectsBounds:t=>ud.intersectsBox(t),intersectsTriangle:t=>ud.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?td:kc)(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=>(Zu.copy(e).clamp(t.min,t.max),Zu.distanceToSquared(e)),intersectsBounds:(t,e,n)=>n<a&&n<o,intersectsTriangle:(t,n)=>{t.closestPointToPoint(e,Zu);const i=e.distanceToSquared(Zu);return i<a&&(ju.copy(Zu),a=i,h=n),i<s}}),a===1/0)return null;const l=Math.sqrt(a);return n.point?n.point.copy(ju):n.point=ju.clone(),n.distance=l,n.faceIndex=h,n}(this,t,e,n,i)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{Wl(0,new Float32Array(e),cd),t.union(cd)}),t}}const fd=1e-6,yd=Math.pow(10,-Math.log10(fd)),md=5e-7*yd;function gd(t){return~~(t*yd+md)}function xd(t){return`${gd(t.x)},${gd(t.y)}`}function bd(t){return`${gd(t.x)},${gd(t.y)},${gd(t.z)}`}function wd(t){return`${gd(t.x)},${gd(t.y)},${gd(t.z)},${gd(t.w)}`}function vd(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 Md(){return"undefined"!=typeof SharedArrayBuffer}function Sd(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 Ad(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 en(i,1));for(let t=0;t<n;t++)i[t]=t}}function zd(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}const _d=new St;function Td(t){return~~(t/3)}function Bd(t){return t%3}function Cd(t,e){return t.start-e.start}function Pd(t,e){return _d.subVectors(e,t.origin).dot(t.direction)}const Ed=1e-5,kd=1e-4;class Nd{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)>Ed;return t.direction.angleTo(e.direction)>kd||n}function o(t,e){const n=t.origin.distanceTo(e.origin),i=t.direction.angleTo(e.direction);return n/Ed+i/kd}}}const Id=new St,Od=new St,Fd=new Tn;function Rd(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 Nd;for(let u=0,c=h.length;u<c;u++){const t=h[u],e=Td(t),n=Bd(t);let i,o=3*e+n,c=3*e+(n+1)%3;r&&(o=r.getX(o),c=r.getX(c)),Id.fromBufferAttribute(s,o),Od.fromBufferAttribute(s,c),vd(Id,Od,Fd);let d=l.findClosestRay(Fd);null===d&&(d=Fd.clone(),l.addRay(d)),a.has(d)||a.set(d,{forward:[],reverse:[],ray:d}),i=a.get(d);let p=Pd(d,Id),f=Pd(d,Od);p>f&&([p,f]=[f,p]),Fd.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(Cd),e.sort(Cd);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 Ud=new vt,Vd=new St,Ld=new Dt,qd=["","",""];class Dd{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=gd(i.getX(t));break;case 2:r=xd(Ud.fromBufferAttribute(i,t));break;case 3:r=bd(Vd.fromBufferAttribute(i,t));break;case 4:r=wd(Ld.fromBufferAttribute(i,t))}""!==e&&(e+="|"),e+=r}return e}:function(t){return Vd.fromBufferAttribute(u,t),bd(Vd)},o=new Map,{attributes:a}=t,h=e?Object.keys(a):null,l=t.index,u=a.position;let c=zd(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)),qd[e]=s(n)}for(let e=0;e<3;e++){const n=(e+1)%3,i=qd[e],r=qd[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}=Rd(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 Xd extends Ln{constructor(...t){super(...t),this.isBrush=!0,this._previousMatrix=new Xt,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=Md();if(n)for(const i in e){const t=e[i];if(t.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");t.array=Sd(t.array)}if(t.boundsTree||(Ad(t,{useSharedArrayBuffer:n}),t.boundsTree=new pd(t,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),t.halfEdges||(t.halfEdges=new Dd(t)),!t.groupIndices){const e=zd(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 Zd=new St,jd=new St,Gd=new St;function Jd(t,e=1e-14){Zd.subVectors(t.b,t.a),jd.subVectors(t.c,t.a),Gd.subVectors(t.b,t.c);const n=Zd.angleTo(jd),i=Zd.angleTo(Gd),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 Wd=1e-10,$d=1e-10,Yd=new Ki,Hd=new Ki,Qd=new St,Kd=new St,tp=new St,ep=new jn,np=new Au;class ip{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new Fe),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class rp{constructor(){this.trianglePool=new ip,this.triangles=[],this.normal=new St,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(Qd).dot(i))>Wd)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(Kd).normalize(),Math.abs(1-Math.abs(Kd.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];Qd.subVectors(s,r).normalize(),tp.crossVectors(Kd,Qd),ep.setFromNormalAndCoplanarPoint(tp,r),this.splitByPlane(ep,t)}}else t.getPlane(ep),this.splitByPlane(ep,t)}splitByPlane(t,e){const{triangles:n,trianglePool:i}=this;np.copy(e),np.needsUpdate=!0;for(let r=0,s=n.length;r<s;r++){const e=n[r];if(!np.intersectsTriangle(e,Yd,!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;Yd.start.copy(f[n]),Yd.end.copy(f[e]);const i=t.distanceToPoint(Yd.start),r=t.distanceToPoint(Yd.end);if(Math.abs(i)<$d&&Math.abs(r)<$d){c=!0;break}if(i>0?d.push(n):p.push(n),Math.abs(i)<$d)continue;let s=!!t.intersectLine(Yd,Qd);!s&&Math.abs(r)<$d&&(Qd.copy(Yd.end),s=!0),!s||Qd.distanceTo(Yd.start)<Wd||(Qd.distanceTo(Yd.end)<Wd&&(u=n),0===l?Hd.start.copy(Qd):Hd.end.copy(Qd),l++)}if(!c&&2===l&&Hd.distance()>$d)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(Hd.end),a.c.copy(Hd.start),Jd(a)||n.push(a),e.a.copy(f[t]),e.b.copy(Hd.start),e.c.copy(Hd.end),Jd(e)&&(n.splice(r,1),r--,s--)}else{const t=d.length>=2?p[0]:d[0];if(0===t){let t=Hd.start;Hd.start=Hd.end,Hd.end=t}const o=(t+1)%3,a=(t+2)%3,h=i.getTriangle(),l=i.getTriangle();f[o].distanceToSquared(Hd.start)<f[a].distanceToSquared(Hd.end)?(h.a.copy(f[o]),h.b.copy(Hd.start),h.c.copy(Hd.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Hd.start)):(h.a.copy(f[a]),h.b.copy(Hd.start),h.c.copy(Hd.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Hd.end)),e.a.copy(f[t]),e.b.copy(Hd.end),e.c.copy(Hd.start),Jd(h)||n.push(h),Jd(l)||n.push(l),Jd(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 sp{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(Md()?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 op{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 sp(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 sp(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 ap{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 hp=new Tn,lp=new Xt,up=new Fe,cp=new St,dp=new Dt,pp=new Dt,fp=new Dt,yp=new Dt,mp=new Dt,gp=new Dt,xp=new Ki,bp=new St,wp=1e-8,vp=-1;let Mp=null;function Sp(t){Mp=t}function Ap(t,e){t.getMidpoint(hp.origin),t.getNormal(hp.direction);const n=e.raycastFirst(hp,2);return Boolean(n&&hp.direction.dot(n.face.normal)>0)?vp:1}function zp(t,e){function n(){return Math.random()-.5}t.getNormal(bp),hp.direction.copy(bp),t.getMidpoint(hp.origin);let i=0,r=1/0;for(let s=0;s<3;s++){hp.direction.x+=n()*wp,hp.direction.y+=n()*wp,hp.direction.z+=n()*wp,hp.direction.multiplyScalar(-1);const t=e.raycastFirst(hp,2);if(Boolean(t&&hp.direction.dot(t.face.normal)>0)&&i++,null!==t&&(r=Math.min(r,t.distance)),r<=1e-15)return t.face.normal.dot(bp)>0?2:-2;if(i/3>.5||(s-i+1)/3>.5)break}return i/3>.5?vp:1}function _p(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?(up.a.fromBufferAttribute(t,u).applyMatrix4(i),up.b.fromBufferAttribute(t,c).applyMatrix4(i),up.c.fromBufferAttribute(t,d).applyMatrix4(i),Cp(up.a,up.b,up.c,e,3,n,o)):"normal"===p?(up.a.fromBufferAttribute(t,u).applyNormalMatrix(r),up.b.fromBufferAttribute(t,c).applyNormalMatrix(r),up.c.fromBufferAttribute(t,d).applyNormalMatrix(r),o&&(up.a.multiplyScalar(-1),up.b.multiplyScalar(-1),up.c.multiplyScalar(-1)),Cp(up.a,up.b,up.c,e,3,n,o,!0)):(dp.fromBufferAttribute(t,u),pp.fromBufferAttribute(t,c),fp.fromBufferAttribute(t,d),Cp(dp,pp,fp,e,h,n,o))}}function Tp(t,e,n,i,r,s,o,a=!1){Pp(t,i,r,s,o,a),Pp(a?n:e,i,r,s,o,a),Pp(a?e:n,i,r,s,o,a)}function Bp(t,e,n=!1){switch(t){case 0:if(1===e||2===e&&!n)return 1;break;case 1:if(n){if(e===vp)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===vp)return 0;break;case 4:if(e===vp)return 0;if(1===e)return 1;break;case 3:if(e===vp||2===e&&!n)return 1;break;case 5:if(!n&&(1===e||-2===e))return 1;break;case 6:if(!n&&(e===vp||2===e))return 1;break;default:throw new Error(`Unrecognized CSG operation enum "${t}".`)}return 2}function Cp(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)};yp.set(0,0,0,0).addScaledVector(t,i.a.x).addScaledVector(e,i.a.y).addScaledVector(n,i.a.z),mp.set(0,0,0,0).addScaledVector(t,i.b.x).addScaledVector(e,i.b.y).addScaledVector(n,i.b.z),gp.set(0,0,0,0).addScaledVector(t,i.c.x).addScaledVector(e,i.c.y).addScaledVector(n,i.c.z),a&&(yp.normalize(),mp.normalize(),gp.normalize()),h(yp),o?(h(gp),h(mp)):(h(mp),h(gp))}function Pp(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?(cp.fromBufferAttribute(a,t).applyMatrix4(n),h.push(cp.x,cp.y,cp.z)):"normal"===o?(cp.fromBufferAttribute(a,t).applyNormalMatrix(i),s&&cp.multiplyScalar(-1),h.push(cp.x,cp.y,cp.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 Ep{constructor(t){this.triangle=(new Fe).copy(t),this.intersects={}}addTriangle(t,e){this.intersects[t]=(new Fe).copy(e)}getIntersectArray(){const t=[],{intersects:e}=this;for(const n in e)t.push(e[n]);return t}}class kp{constructor(){this.data={}}addTriangleIntersection(t,e,n,i){const{data:r}=this;r[t]||(r[t]=new Ep(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 Np{constructor(){this.enabled=!1,this.triangleIntersectsA=new kp,this.triangleIntersectsB=new kp,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(),Sp(this))}complete(){this.enabled&&Sp(null)}}const Ip=new Xt,Op=new _t,Fp=new Fe,Rp=new Fe,Up=new Fe,Vp=new Fe,Lp=[],qp=[];function Dp(t){for(const e of t)return e}function Xp(t,e,n,i,r,s={}){const{useGroups:o=!0}=s,{aIntersections:a,bIntersections:h}=function(t,e){const n=new ap,i=new ap;return lp.copy(t.matrixWorld).invert().multiply(e.matrixWorld),t.geometry.boundsTree.bvhcast(e.geometry.boundsTree,lp,{intersectsTriangles(r,s,o,a){if(!Jd(r)&&!Jd(s)){let h=r.intersectsTriangle(s,xp,!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),Mp&&(Mp.addEdge(xp),Mp.addIntersectingTriangles(o,r,a,s))}}return!1}}),{aIntersections:n,bIntersections:i}}(t,e);let l;l=o?0:-1,Zp(t,e,a,n,!1,i,r,l),jp(t,e,a,n,!1,r,l);return-1!==n.findIndex(t=>6!==t&&5!==t)&&(l=o?t.geometry.groups.length||1:-1,Zp(e,t,h,n,!0,i,r,l),jp(e,t,h,n,!0,r,l)),Lp.length=0,qp.length=0,{groups:[],materials:null}}function Zp(t,e,n,i,r,s,o,a=0){const h=t.matrixWorld.determinant()<0;Ip.copy(e.matrixWorld).invert().multiply(t.matrixWorld),Op.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);Fp.a.fromBufferAttribute(c,b).applyMatrix4(Ip),Fp.b.fromBufferAttribute(c,w).applyMatrix4(Ip),Fp.c.fromBufferAttribute(c,v).applyMatrix4(Ip),s.reset(),s.initialize(Fp);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);Rp.a.fromBufferAttribute(f,n),Rp.b.fromBufferAttribute(f,i),Rp.c.fromBufferAttribute(f,r),s.splitByTriangle(Rp)}const S=s.triangles;for(let a=0,l=S.length;a<l;a++){const l=S[a],u=s.coplanarTriangleUsed?zp(l,d):Ap(l,d);Lp.length=0,qp.length=0;for(let t=0,e=i.length;t<e;t++){const e=Bp(i[t],u,r);2!==e&&(qp.push(e),Lp.push(o[t].getGroupAttrSet(n)))}if(0!==Lp.length){Fp.getBarycoord(l.a,Vp.a),Fp.getBarycoord(l.b,Vp.b),Fp.getBarycoord(l.c,Vp.c);for(let n=0,i=Lp.length;n<i;n++){const i=Lp[n],r=0===qp[n];_p(e,Vp,t.geometry,t.matrixWorld,Op,i,h!==r)}}}}return y.length}function jp(t,e,n,i,r,s,o=0){const a=t.matrixWorld.determinant()<0;Ip.copy(e.matrixWorld).invert().multiply(t.matrixWorld),Op.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=zd(t.geometry);m<g;m++)m in n.intersectionSet||y.add(m);for(;y.size>0;){const e=Dp(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);Up.a.fromBufferAttribute(d,m).applyMatrix4(Ip),Up.b.fromBufferAttribute(d,g).applyMatrix4(Ip),Up.c.fromBufferAttribute(d,x).applyMatrix4(Ip);const b=Ap(Up,h);qp.length=0,Lp.length=0;for(let t=0,o=i.length;t<o;t++){const e=Bp(i[t],b,r);2!==e&&(qp.push(e),Lp.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!==Lp.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(Up.a.fromBufferAttribute(d,i),Up.b.fromBufferAttribute(d,r),Up.c.fromBufferAttribute(d,s),!Jd(Up))for(let e=0,o=Lp.length;e<o;e++){const n=qp[e],o=Lp[e].getGroupAttrSet(h),l=0===n;Tp(i,r,s,c,t.matrixWorld,Op,o,l!==a)}}}}}function Gp(t,e){let n=e;return Array.isArray(e)||(n=[],t.forEach(t=>{n[t.materialIndex]=e})),n}class Jp{constructor(){this.triangleSplitter=new rp,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new Np}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 Xd){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 op);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(),Xp(t,e,n,s,o,{useGroups:h}),d.complete();const p=this.getGroupRanges(t.geometry),f=Gp(p,t.material),y=this.getGroupRanges(e.geometry),m=Gp(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 en(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 Xd){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()}}class Wp extends Fl{constructor(t,e){super(t,e);const n=new Xd(new Fl(t,c(u({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new Re).setFromObject(n),r=new St;i.getSize(r);const s=new St(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 St;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;const h=new ji(r.x,r.y,o,o),l=new Xd(h);l.position.set(s.x,s.y,s.z),l.updateMatrixWorld();const d=(new Jp).evaluate(l,n,3),p=d.geometry.getAttribute("position"),f=new sn(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 St).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 Fl(t,c(u({},e),{hasTop:!1})),m=kl([d.geometry,y],2);this.copy(m.toNonIndexed())}}const $p=t=>{const{box3:e,sideBox:n}=t,i=e.getSize(new St),r=n.getSize(new St);return t.sideRepeat&&(r.z/=t.sideRepeat),{generateTopUV(t,n,r,s,o){const a=n[3*r],h=n[3*r+1],l=n[3*s],u=n[3*s+1],c=n[3*o],d=n[3*o+1];return[new vt((a-e.min.x)/i.x,(h-e.min.y)/i.y),new vt((l-e.min.x)/i.x,(u-e.min.y)/i.y),new vt((c-e.min.x)/i.x,(d-e.min.y)/i.y)]},generateSideWallUV(t,e,i,s,o,a){const h=e[3*i],l=e[3*i+1],u=e[3*i+2],c=e[3*s],d=e[3*s+1],p=e[3*s+2],f=e[3*o],y=e[3*o+1],m=e[3*o+2],g=e[3*a],x=e[3*a+1],b=e[3*a+2];return Math.abs(l-d)<Math.abs(h-c)?[new vt((h-n.min.x)/r.x,(u-n.min.z)/r.z),new vt((c-n.min.x)/r.x,(p-n.min.z)/r.z),new vt((f-n.min.x)/r.x,(m-n.min.z)/r.z),new vt((g-n.min.x)/r.x,(b-n.min.z)/r.z)]:[new vt((l-n.min.y)/r.y,(u-n.min.z)/r.z),new vt((d-n.min.y)/r.y,(p-n.min.z)/r.z),new vt((y-n.min.y)/r.y,(m-n.min.z)/r.z),new vt((x-n.min.y)/r.y,(b-n.min.z)/r.z)]}}};var Yp=Math.abs,Hp=Math.cos,Qp=Math.sin,Kp=1e-6,tf=Math.PI,ef=tf/2;function nf(t){return t>1?0:t<-1?tf:Math.acos(t)}function rf(t){return t>0?Math.sqrt(t):0}function sf(t,e){var n=Hp(e),i=function(t){return t?t/Math.sin(t):1}(nf(n*Hp(t/=2)));return[2*n*Qp(t)*i,Qp(e)*i]}function of(t,e){var n=sf(t,e);return[(n[0]+t/ef)/2,(n[1]+e)/2]}of.invert=(t,e)=>{var n=t,i=e,r=25;do{var s,o=Hp(i),a=Qp(i),h=Qp(2*i),l=a*a,u=o*o,c=Qp(n),d=Hp(n/2),p=Qp(n/2),f=p*p,y=1-u*d*d,m=y?nf(o*d)*rf(s=1/y):s=0,g=.5*(2*m*o*p+n/ef)-t,x=.5*(m*a+i)-e,b=.5*s*(u*f+m*o*d*l)+.5/ef,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((Yp(A)>Kp||Yp(z)>Kp)&&--r>0);return[n,i]};const af={mercator:function(){return function(t){var e,n,i,r=xa(t),s=r.center,o=r.scale,a=r.translate,h=r.clipExtent,l=null;function u(){var s=_r*o(),a=r(vo(r.rotate()).invert([0,0]));return h(null==l?[[a[0]-s,a[1]-s],[a[0]+s,a[1]+s]]:t===ba?[[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()}(ba).scale(961/Cr)},equirectangular:function(){return xa(wa).scale(152.63)},winkel3:function(){return xa(of).scale(158.837)}},hf=t=>{var e,n,i;const r=af[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),r},lf=(t,e)=>t.map(t=>{let n;if(e){const[i,r]=e([...t]);n=new vt(i,-r)}else n=new vt(...t);return n});function uf(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&&n[s]&&r.push(n[s],n[s])}else i.push(t),n&&n[s]&&r.push(n[s])}),{splitPolygons:i,splitMeta:r}}function cf({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,bbox:r,projection:s,hasTop:o,hasBottom:a,hasSide:h,splitPolygons:l,topSegments:d}){const p=s&&hf(s);let f,y=e||(t?t.map(t=>lf(t,p)):[]),m=n;if(l){const t=uf(y,l,n);y=t.splitPolygons,m=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;lf([[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?hf(c(u({},s),{rotate:void 0})):p,"winkel3"===(null==s?void 0:s.projectionType)?10:0);f=new Re(new St(e[0],e[1],0),new St(n[0],n[1],0))}return y.map((t,e)=>{var n,r,s;const l=(null==m?void 0:m[e])||i||[],u=null!=(n=l[0])?n:0,c=null!=(r=l[1])?r:0,p=(t=>{const{depth:e,points:n,box3:i,hasTop:r,hasBottom:s,hasSide:o,sideRepeat:a,topSegments:h}=t,l=h?Wp:Fl;let u=i;if(!u){u=new Re;const t=n.flatMap(t=>[t.x,t.y,0]);u.setFromArray(t)}const c=u.clone();return c.min.z=0,c.max.z=e,new l(new fi(n),{depth:e,bevelEnabled:!1,box3:u,UVGenerator:$p({box3:u,sideBox:c,sideRepeat:a}),hasTop:r,hasBottom:s,hasSide:o,topSegments:h})})({points:t,sideRepeat:null!=(s=l[2])?s:1,depth:u,hasTop:o,hasBottom:a,hasSide:h,box3:f,topSegments:d});if(c){const t=p.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+c);t.needsUpdate=!0}return p})}function df({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,projection:r,splitPolygons:s}){const o=r&&hf(r);let a=e||(t?t.map(t=>((t,e)=>t.map(t=>{let n;if(e){const[i,r]=e([...t]);n=new St(i,-r,0)}else n=new St(...t);return n}))(t,o)):[]),h=n;if(s){const t=uf(a,s,h);a=t.splitPolygons,h=t.splitMeta}return a.map((t,e)=>{var n;const r=null!=(n=((null==h?void 0:h[e])||i||[])[0])?n:1;return Bl({nodes:t,setPointWidth:()=>r})})}(e=>{const n={run(t,e){const n=new Function("return ("+t+").apply(null, arguments);");return n.apply(n,e)},methods:()=>Object.keys(n)};addEventListener("message",e=>((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,[e],function*({data:e}){try{const t=n[e.method];if(!t)throw new Error(\'Unknown method "\'+e.method+\'"\');{const n=yield t.apply(t,e.params);n.transfer&&n.message?postMessage({id:e.id,result:n.message,error:null},n.transfer):postMessage({id:e.id,result:n,error:null})}}catch(i){postMessage({id:e.id,result:null,error:t(i)})}})),Object.keys(e).forEach(t=>{n[t]=e[t]}),postMessage("ready")})({extrudePolygon:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,dimension:s=2,useGroups:o,projection:a}=e,h=d(e,["coordinates","lengths","metaLength","dimension","useGroups","projection"]);const l=((t,e,n=2,i)=>{const r=new Array(e.length);let s=0;const o=[0,0];for(let a=0;a<e.length;a++){const h=e[a],l=new Array(h);for(let e=0;e<h;e++){let r=t[s],a=t[s+1];if(i){o[0]=r,o[1]=a;const t=i(o);t&&(r=t[0],a=t[1]),l[e]=new vt(r,-a)}else l[e]=new vt(r,a);s+=n}r[a]=l}return r})(n,i,s,a?hf(a):void 0),c=Cl(n,i,r,s),p=cf(u({pointsArr:l,metaArray:c,projection:a},h));return Nl(p,o)},line:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,dimension:s=2,useGroups:o,projection:a}=e,h=d(e,["coordinates","lengths","metaLength","dimension","useGroups","projection"]);const l=((t,e,n=2,i)=>{const r=new Array(e.length);let s=0;const o=[0,0];for(let a=0;a<e.length;a++){const h=e[a],l=new Array(h);for(let e=0;e<h;e++){let r=t[s],a=t[s+1];if(i){o[0]=r,o[1]=a;const t=i(o);t&&(r=t[0],a=t[1]),l[e]=new St(r,-a,0)}else{const i=3===n?t[s+2]:0;l[e]=new St(r,a,i)}s+=n}r[a]=l}return r})(n,i,s,a?hf(a):void 0),c=Cl(n,i,r,s),p=df(u({pointsArr:l,metaArray:c,projection:a},h));return Nl(p,o)},conicPolygon:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,useGroups:s}=e,o=d(e,["coordinates","lengths","metaLength","useGroups"]);const{coordinatesArr:a,metaArray:h}=Pl({coordinates:n,lengths:i,metaLength:r}),l=Il(u({coordinatesArr:a,metaArray:h},o));return Nl(l,s)},conicLine:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,useGroups:s}=e,o=d(e,["coordinates","lengths","metaLength","useGroups"]);const{coordinatesArr:a,metaArray:h}=Pl({coordinates:n,lengths:i,metaLength:r}),l=function({coordinatesArr:t,metaArray:e,globalMeta:n,projection:i="sphere",useRTC:r=!1}){let s;return t.map((t,r)=>{var s;const o=null!=(s=(e&&e[r]||n||[])[1])?s:0;return zl({polygonGeoJson:[t],startHeight:o,projection:i}).topVerts}).map((t,i)=>{var o;const a=null!=(o=(e&&e[i]||n||[])[0])?o:1,h=Bl({nodes:t,setPointWidth:()=>a,useRTC:r,rtcCenter:s});return 0===i&&(s=h.getRTCCenter()),h})}(u({coordinatesArr:a,metaArray:h},o));return Nl(l,s)}})}();\n',tr="undefined"!=typeof self&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Qs],{type:"text/javascript;charset=utf-8"});function er(t){let e;try{if(e=tr&&(self.URL||self.webkitURL).createObjectURL(tr),!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(Qs),{name:null==t?void 0:t.name})}}class nr{constructor(t){u(this,"options"),u(this,"pool"),u(this,"cacheManager"),this.options=h({dbName:"pencil_cache",cacheVersion:"1",maxCacheSize:100},t),this.cacheManager=new on({dbName:this.options.dbName,maxCacheSize:this.options.maxCacheSize,cacheVersion:this.options.cacheVersion});const e=new Re(er,{maxWorkers:this.options.maxWorkers});this.pool=e}geoGeometry(t,e){return d(this,null,function*(){const{mesaage:n,coordinatesArr:i,metaArray:s,globalMeta:r,cacheKey:o,userData:a,cb:l,useFloat64Array:c}=h(h({},this.options),e),u=this.pool,{flat:d,lengths:p,metaLength:f}=this.flattenCoordinates(i,s,r,c),{err:m,res:y}=yield u.exec(t,[h(h({coordinates:d,lengths:p,metaLength:f},n),r?{globalMeta:r}:{})],{on:()=>{},transfer:[d.buffer]},!0);if(m)throw m;const g=Ks(y);return Object.assign(g.userData,h({},a)),l&&(yield l(g)),o&&this.cacheManager.addToCache(o,h({attributes:y},a)),g})}getCachedGeometry(t){return d(this,null,function*(){const{cacheKey:e}=t;if(e){const t=yield this.cacheManager.get(e);if(t){this.cacheManager.recordMetadataUpdate(e);const n=t,{attributes:i}=n,s=c(n,["attributes"]),r=Ks(i);return Object.assign(r.userData,h({},s)),r}return null}return null})}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,i=!1){const s=t.length,r=new Array(s);let o=0;for(let d=0;d<s;d++){const e=t[d].length;r[d]=e,o+=e}let a=0;const h=e&&e.length>0;let l=0;h&&(a=e[0].length,l=e.length*a);const c=i?new Float64Array(2*o+l):new Float32Array(2*o+l);let u=0;for(let d=0;d<s;d++){const e=t[d];for(let t=0;t<e.length;t++){const n=e[t];c[u++]=n[0],c[u++]=n[1]}}if(h)for(let d=0;d<e.length;d++){const t=e[d];for(let e=0;e<t.length;e++)c[u++]=t[e]}return{flat:c,lengths:r,metaLength:a}}dispose(){this.cacheManager.dispose(),this.pool.dispose(),this.pool.workers.length=0}}const ir=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 yt),u(this,"maxBackufferArea",33177600),u(this,"installPlugins",/* @__PURE__ */new Map),u(this,"attributesWorker"),u(this,"_cameraPositon",new y),u(this,"_cameraTarget",new y),u(this,"event",new p),u(this,"timer",new Dt),u(this,"userData",{}),u(this,"TweenRaf"),u(this,"pageActiveIndex",0),u(this,"pages",new Ie),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:_n}),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(),this.attributesWorker=new nr({cacheVersion:this.options.attributesWorkerVersion})}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(){Nt.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 Js({width:c,height:u,renderer:this.options.WebGPURenderer,rendererParams:Ys}):new Zs({width:c,height:u,rendererParams:l(h({},r),{antialias:!1})});this.rendererController=d;const p=new He({width:c,height:u}),f=new Xs({}),m=new As({controlsParams:{domElement:null!=(t=null==o?void 0:o.domElement)?t:d.renderer.domElement}}),y=new Vs({loaderParams:h({anisotropy:this.maxAnisotropy},a)}),g=new qs({pencil:this}),x=new Us({pencil:this});this.sceneController=f,this.cameraController=p,this.controlsController=m,this.loaderController=y,this.mListController=g,this.leadController=x;const v=this.addPage({sceneOptions:this.options.scene,cameraOptions:this.options.camera});if(this.showPage(v),i){const t=new zs({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 zi({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 Os(t,i);e&&r.addRenderer("css2d",i),n&&r.addRenderer("css3d",s),this.cssRendererController=r}}initTransformControls(){const t=new $s({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 j);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 j),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 j,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(),Nt.update();const o=this.timer.getDelta(),a=this.timer.getElapsed();this.controlsController.update(o,a),this.cameraController.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),this.leadController.update(o,a),(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(),Nt.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.attributesWorker.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(ir,"options",{stats:Fe,helper:Fe,viewHelper:Fe,controls:!0,transformControls:Fe,renderer:Gs,composer:{multisampling:4,premultiplieAlpha:!1},scene:{background:null},camera:We,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({},Cs),css3DRenderer:!1,css3DRendererParams:h({},Cs),attributesWorkerVersion:"1"});let sr=ir;const rr={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 j(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 xt(0,0,0,0)},color:{value:new at(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=ke(!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 Nt.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 xt(0,0,0,1e-4)},color:{value:new at(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=ke(!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 Nt.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()}}},or=Ss.ACTION;export{Ln as AmbientLightObject,Cn as BaseObject,kn as CSS2DObjectObject,Rn as CSS3DObjectObject,Bn as CSS3DSpriteObject,Un as DirectionalLightObject,Wn as EllipsoidObject,hi as ExtrudePolygonObject,On as GroupObject,Fn as HemisphereLightObject,jn as InstancedMeshObject,Ht as Line2Material,yi as LineObject,qt as LineSegmentsGeometry,li as MeshLineGeometry,ci as MeshLineMaterial,ui as MeshLineRaycast,zn as MeshObject,xi as NodeObject,sr as Pencil,vi as PieObject,Dn as PointLightObject,En as PointsObject,Vn as RectAreaLightObject,qe as ResourceTracker,Nn as SpotLightObject,Pn as SpriteObject,or as cameraControlsAction,sr as default,rr as effect,Sn 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 v,Object3D as b,Texture as w,Sphere as _,Ray as M,BufferGeometry as S,Float32BufferAttribute as A,PointsMaterial as T,Points as C,NoColorSpace as O,SRGBColorSpace as z,LinearSRGBColorSpace as E,MathUtils as P,Vector2 as j,InstancedMesh as k,Quaternion as R,Box3 as B,Sprite as L,Group as D,Mesh as U,AmbientLight as N,DirectionalLight as F,PointLight as I,SpotLight as V,HemisphereLight as W,RectAreaLight as H,MeshStandardMaterial as q,BufferAttribute as G,Shape as Z,ShapeUtils as X,SplineCurve as $,QuadraticBezierCurve3 as Y,QuadraticBezierCurve as J,LineCurve3 as K,LineCurve as Q,EllipseCurve as tt,CubicBezierCurve3 as et,CubicBezierCurve as nt,CatmullRomCurve3 as it,ArcCurve as st,PlaneGeometry as rt,ShaderMaterial as ot,Color as at,LineSegments as ht,MeshBasicMaterial as lt,UniformsUtils as ct,RawShaderMaterial as ut,SpriteMaterial as dt,WebGLRenderTarget as pt,HalfFloatType as ft,Layers as mt,Raycaster as yt,Spherical as gt,Vector4 as xt,AxesHelper as vt,CameraHelper as bt,PointLightHelper as wt,DirectionalLightHelper as _t,SpotLightHelper as Mt,HemisphereLightHelper as St,Box3Helper as At,ImageUtils as Tt,ObjectLoader as Ct,VideoTexture as Ot,DataTexture as zt,Scene as Et,Camera as Pt,FileLoader as jt,Loader as kt,LoadingManager as Rt,TextureLoader as Bt,WebGLRenderer as Lt,REVISION as Dt,Timer as Ut}from"three";import Nt from"three/examples/jsm/libs/tween.module.js";import{EffectComposer as Ft}from"three/examples/jsm/postprocessing/EffectComposer.js";import{RenderPass as It}from"three/examples/jsm/postprocessing/RenderPass.js";import{SSAOPass as Vt}from"three/examples/jsm/postprocessing/SSAOPass.js";import{UnrealBloomPass as Wt}from"three/examples/jsm/postprocessing/UnrealBloomPass.js";import{LineMaterial as Ht}from"three/examples/jsm/lines/LineMaterial.js";import{LineSegmentsGeometry as qt}from"three/examples/jsm/lines/LineSegmentsGeometry.js";import{RectAreaLightUniformsLib as Gt}from"three/examples/jsm/lights/RectAreaLightUniformsLib.js";import{CSS2DObject as Zt,CSS2DRenderer as Xt}from"three/examples/jsm/renderers/CSS2DRenderer.js";import{CSS3DObject as $t,CSS3DSprite as Yt,CSS3DRenderer as Jt}from"three/examples/jsm/renderers/CSS3DRenderer.js";import{createStore as Kt,getMany as Qt,setMany as te,keys as ee,delMany as ne,get as ie,clear as se}from"idb-keyval";import{geoProjection as re,geoEquirectangular as oe,geoMercator as ae,geoBounds as he,geoContains as le,geoDistance as ce,geoInterpolate as ue}from"d3-geo";import de from"@turf/boolean-clockwise";import{merge as pe,mean as fe,extent as me}from"d3-array";import ye,{flatten as ge}from"earcut";import xe from"delaunator";import ve from"@turf/boolean-point-in-polygon";import{geoVoronoi as be}from"d3-geo-voronoi";import{scaleLinear as we}from"d3-scale";import{mergeGeometries as _e,mergeGroups as Me}from"three/examples/jsm/utils/BufferGeometryUtils.js";import{Brush as Se,Evaluator as Ae,INTERSECTION as Te}from"three-bvh-csg";import{ShaderPass as Ce}from"three/examples/jsm/postprocessing/ShaderPass.js";import{OutputPass as Oe}from"three/examples/jsm/postprocessing/OutputPass.js";import{FullScreenQuad as ze}from"three/examples/jsm/postprocessing/Pass.js";import{RectAreaLightHelper as Ee}from"three/examples/jsm/helpers/RectAreaLightHelper.js";import{ViewHelper as Pe}from"three/examples/jsm/helpers/ViewHelper.js";import{generateUUID as je,makePromiseCreator as ke,WorkerPool as Re}from"esus-lite";import{DRACOLoader as Be}from"three/examples/jsm/loaders/DRACOLoader.js";import{EXRLoader as Le}from"three/examples/jsm/loaders/EXRLoader.js";import{GLTFLoader as De}from"three/examples/jsm/loaders/GLTFLoader.js";import{LottieLoader as Ue}from"three/examples/jsm/loaders/LottieLoader.js";import{TransformControls as Ne}from"three/examples/jsm/controls/TransformControls.js";const Fe=!1;class Ie{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 Ve{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 Ie;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 We={fov:45,near:1,far:1e3,up:new y(0,1,0)};class He extends Ve{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=We,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),e.matrixWorld.decompose(e.position,e.quaternion,e.scale))}}update(t,e){-1===this._lastFov&&this.camera.updateMatrixWorld()}}class qe{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 v)return t;if(t instanceof Cn?(t.object3d&&this.track(t.object3d),Object.values(t.materialList).map(t=>this.track(t))):(t instanceof b||Reflect.has(t,"dispose"))&&this.resources.add(t),t instanceof b){const e=t;this.track(e.geometry),this.track(e.material)}else if(t instanceof v){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(){for(const t of this.resources)t instanceof HTMLVideoElement&&t.pause(),Reflect.has(t,"dispose")&&t.dispose();this.resources.clear()}}const Ge=/* @__PURE__ */new g,Ze=/* @__PURE__ */new M,Xe=/* @__PURE__ */new _,$e=/* @__PURE__ */new y;function Ye(t,e){const n=this.geometry,i=this.matrixWorld,s=t.params.Points.threshold,r=n.drawRange;null===n.boundingSphere&&n.computeBoundingSphere(),Xe.copy(n.boundingSphere),Xe.applyMatrix4(i),Xe.radius+=s,Ge.copy(i).invert(),Ze.copy(t.ray).applyMatrix4(Ge);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);$e.fromBufferAttribute(h,s),Je($e,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++)$e.fromBufferAttribute(h,n),Je($e,n,o,i,t,e,this)}}function Je(t,e,n,i,s,r,o){const a=new y;Ze.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 Ke=class t{constructor(t){u(this,"uuidToObject",/* @__PURE__ */new Map),u(this,"uuidToMaterial",/* @__PURE__ */new Map),u(this,"uuidToTexture",/* @__PURE__ */new Map),u(this,"uuidToImage",/* @__PURE__ */new Map),this._traceObjects(t.object),this._traceMaterials(t.materials),this._traceTextures(t.textures)}resolve(t){var e,n,i,s;return null!=(s=null!=(i=null!=(n=null!=(e=this.uuidToObject.get(t))?e:this.uuidToMaterial.get(t))?n:this.uuidToTexture.get(t))?i:this.uuidToImage.get(t))?s:t}formatRemap(t){const e=[];for(const[n,i]of t)e.push(` ${this.resolve(n)} => ${this.resolve(i)}`);return e}_traceObjects(t,e=""){var n,i,s,r;if(!t)return;let o="";o=(null==(n=t.userData)?void 0:n._mListFixKey)?`mlist(${t.userData._mListFixKey})`:(null==(i=t.userData)?void 0:i._baseObjectKey)?t.userData._baseObjectKey:t.name?t.name:t.type||"Object3D";const a=e?`${e} -> ${o}`:o;if(this.uuidToObject.set(t.uuid,a),t.geometry){const e=void 0!==(null==(s=t.userData)?void 0:s._mListFixKey),n=`Geometry in [${a}]`,i=this.uuidToObject.get(t.geometry);(!i||e&&!i.includes("mlist("))&&this.uuidToObject.set(t.geometry,n)}if(t.material){const e=Array.isArray(t.material)?t.material:[t.material];for(const n of e){const e=void 0!==(null==(r=t.userData)?void 0:r._mListFixKey),i=`Material in [${a}]`,s=this.uuidToMaterial.get(n);(!s||e&&!s.includes("mlist("))&&this.uuidToMaterial.set(n,i)}}if(t.children)for(const h of t.children)this._traceObjects(h,a)}_traceMaterials(e){if(e)for(const n of e){const e=n.name?`"${n.name}"`:n.type,i=this.uuidToMaterial.get(n.uuid)||`Unused Material ${e}`;for(const s of t._mapTypes)n[s]&&this.uuidToTexture.set(n[s],`Texture(${s}) in ${i}`)}}_traceTextures(t){if(t)for(const e of t){const t=e.name?`"${e.name}"`:"Tex",n=this.uuidToTexture.get(e.uuid)||`Unused Texture ${t}`;e.image&&this.uuidToImage.set(e.image,`Image for ${n}`)}}};u(Ke,"_mapTypes",["map","normalMap","bumpMap","roughnessMap","metalnessMap","emissiveMap","envMap","lightMap","aoMap","alphaMap","displacementMap"]);let Qe=Ke;const tn={linearSRGB:E,sRGB:z,none:O},en={map:tn.sRGB,emissiveMap:tn.sRGB,sheenColorMap:tn.sRGB,specularColorMap:tn.sRGB,normalMap:tn.none,bumpMap:tn.none,displacementMap:tn.none,roughnessMap:tn.none,metalnessMap:tn.none,aoMap:tn.none,lightMap:tn.none,alphaMap:tn.none,specularIntensityMap:tn.none,clearcoatMap:tn.none,clearcoatNormalMap:tn.none,clearcoatRoughnessMap:tn.none,iridescenceMap:tn.none,iridescenceThicknessMap:tn.none,sheenRoughnessMap:tn.none,specularMap:tn.none,thicknessMap:tn.none,transmissionMap:tn.none},nn=[".hdr",".exr",".rgbe"];function sn(t){return function(t){var e;if(t.userData&&"boolean"==typeof t.userData.isHDR)return t.userData.isHDR;if(t.colorSpace===E)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 nn.some(t=>n.toLowerCase().includes(t))}(t)?tn.linearSRGB:tn.sRGB}function rn({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(en).forEach(e=>{const n=t;n[e]&&(n[e].colorSpace=en[e])});const e=t;e.envMap&&(e.envMap.colorSpace=sn(e.envMap))}(t))}class on{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=Kt(t.dbName,"keyval"),this.metadataStore=Kt(`${t.dbName}_metadata`,"keyval")}addToCache(t,e){const n=this.options.cacheVersion;this.cacheObj[t]||(this.cacheObj[t]={}),this.cacheObj[t][n]||(this.cacheObj[t][n]=e)}recordMetadataUpdate(t,e=1){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 Qt(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};n.push([s,a])}yield te(n,this.metadataStore),this.pendingMetadataUpdates.clear()})}evictLRUCache(){return d(this,null,function*(){const t=yield ee(this.store);if(t.length>=this.options.maxCacheSize){const e=yield Qt(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 ne(s,this.store),yield ne(s,this.metadataStore)}})}get(t){return d(this,null,function*(){const e=yield ie(t,this.store),n=this.options.cacheVersion;return null==e?void 0:e[n]})}saveCache(){return d(this,null,function*(){var t;try{yield this.flushMetadata(),yield this.evictLRUCache();const t=Object.entries(this.cacheObj);if(0===t.length)return;yield te(t,this.store);const e=t.map(([t])=>t),n=yield Qt(e,this.metadataStore),i=[];for(let s=0;s<t.length;s++){const[e]=t[s],r=n[s],o={lastAccessed:Date.now(),accessCount:r?r.accessCount+1:1};i.push([e,o])}yield te(i,this.metadataStore),this.cacheObj={}}catch(e){if("QuotaExceededError"!==e.name&&!(null==(t=e.message)?void 0:t.includes("NO_SPACE")))throw e;console.error("存储空间不足,尝试清理旧缓存..."),yield this.clearCache()}})}getCacheStats(){return d(this,null,function*(){const t=yield ee(this.store),e={total:t.length,maxSize:this.options.maxCacheSize,usage:t.length/this.options.maxCacheSize*100,items:[]},n=yield Qt(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 se(this.store),yield se(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 an={a:6378137,b:6356752.314245179,f:1/298.257223563};function hn(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=n*i;u=t*a*c,d=t*h,p=t*a*l}else{const t=an.a,e=an.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 ln=Math.abs,cn=Math.cos,un=Math.sin,dn=1e-6,pn=Math.PI,fn=pn/2;function mn(t){return t>1?0:t<-1?pn:Math.acos(t)}function yn(t){return t>0?Math.sqrt(t):0}function gn(t,e){var n=cn(e),i=function(t){return t?t/Math.sin(t):1}(mn(n*cn(t/=2)));return[2*n*un(t)*i,un(e)*i]}function xn(t,e){var n=gn(t,e);return[(n[0]+t/fn)/2,(n[1]+e)/2]}xn.invert=(t,e)=>{var n=t,i=e,s=25;do{var r,o=cn(i),a=un(i),h=un(2*i),l=a*a,c=o*o,u=un(n),d=cn(n/2),p=un(n/2),f=p*p,m=1-c*d*d,y=m?mn(o*d)*yn(r=1/m):r=0,g=.5*(2*y*o*p+n/fn)-t,x=.5*(y*a+i)-e,v=.5*r*(c*f+y*o*d*l)+.5/fn,b=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=b*w-_*v,S=(x*b-g*_)/M,A=(g*w-x*v)/M;n-=S,i-=A}while((ln(S)>dn||ln(A)>dn)&&--s>0);return[n,i]};const vn={mercator:ae,equirectangular:oe,winkel3:function(){return re(xn).scale(158.837)}},bn=t=>{var e,n,i;const s=vn[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),s};function wn(t){return"[object Object]"===Object.prototype.toString.call(t)}function _n(t){if(!1===wn(t))return!1;const e=t.constructor;if(void 0===e)return!0;const n=e.prototype;return!1!==wn(n)&&!1!==n.hasOwnProperty("isPrototypeOf")}const Mn=t=>(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 j?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)})([t])[0],Sn={applyTextureColorSpace:rn,analyzeSceneJsonSize:function(t){const e=t=>{const e=new Blob([JSON.stringify(t)]).size;return{bytes:e,mbStr:(e/1024/1024).toFixed(3)+" MB"}};console.groupCollapsed("🔍 Scene JSON Size Analysis");const n=e(t);console.log("Total Size:",n.mbStr);const i=new Qe(t),{uuidToObject:s,uuidToMaterial:r,uuidToTexture:o,uuidToImage:a}=i;if(t.images){const e=t.images.filter(t=>!t.url||""===t.url);e.length>0&&(console.warn(`⚠️ Found ${e.length} image(s) with empty url:`),e.forEach((t,e)=>{const n=a.get(t.uuid)||"Unknown (unused image)";console.warn(` ${e+1}. uuid: ${t.uuid}`),console.warn(` ← ${n}`)}))}if(["geometries","materials","textures","images"].forEach(n=>{const i=t[n];if(i&&i.length>0){const t=e(i);if(console.log(`📦 ${n} (${i.length} items):`,t.mbStr),t.bytes>102400){const t=i.map(t=>{let i="Unknown";return"geometries"===n?i=s.get(t.uuid)||"Unknown":"materials"===n?i=r.get(t.uuid)||"Unknown":"textures"===n?i=o.get(t.uuid)||"Unknown":"images"===n&&(i=a.get(t.uuid)||"Unknown"),{uuid:t.uuid,type:t.type,name:t.name,usedBy:i,size:e(t)}}).sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10);console.log(` Top 10 largest ${n}:`),t.forEach((t,e)=>{console.log(` ${e+1}. [${t.type||"Item"}] ${t.name||t.uuid.substring(0,8)}...: ${t.size.mbStr} (Used by: ${t.usedBy})`)})}}}),t._sharedOptionsPool){const n=t._sharedOptionsPool,i=e(n);if(console.log(`🔗 _sharedOptionsPool (${n.length} entries):`,i.mbStr),i.bytes>102400){const t=n.map((t,n)=>({index:n,size:e(t)})).sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10);console.log(" Top 10 largest pool entries:"),t.forEach((t,e)=>{console.log(` ${e+1}. pool[${t.index}]: ${t.size.mbStr}`)})}const s=/* @__PURE__ */new Map,r=t=>{var e;const n=null==(e=null==t?void 0:t.userData)?void 0:e._baseObjectOptions;if(n)for(const i of Object.keys(n)){const t=n[i];t&&"object"==typeof t&&"_sharedRef"in t&&s.set(t._sharedRef,(s.get(t._sharedRef)||0)+1)}(null==t?void 0:t.children)&&t.children.forEach(r)};if(r(t.object),s.size>0){const t=[...s.values()].reduce((t,e)=>t+e,0),e=t-s.size;console.log(` ${n.length} unique entries, ${t} total references, ${e} duplicates eliminated`)}}if(t.object){console.log("🌳 object graph (structure):",e(t.object).mbStr);const n=[];let i=0,s=0;const r=t=>{if(t.userData&&t.userData._baseObjectOptions){const r=t.userData._baseObjectOptions,o=e(r);i+=o.bytes;for(const t of Object.keys(r)){const e=r[t];e&&"object"==typeof e&&"_sharedRef"in e&&s++}o.bytes>1024&&n.push({key:t.userData._baseObjectKey||t.name||t.uuid,type:t.userData._baseObjectObjectType||t.type,size:o})}t.children&&t.children.forEach(r)};if(r(t.object),i>0&&(console.log("⚙️ userData._baseObjectOptions total size:",(i/1024/1024).toFixed(3)+" MB",s>0?`(${s} fields extracted to shared pool)`:""),i>102400&&n.length>0)){console.log(" Top 10 largest options:");n.sort((t,e)=>e.size.bytes-t.size.bytes).slice(0,10).forEach((t,e)=>{console.log(` ${e+1}. [${t.type}] ${t.key}: ${t.size.mbStr}`)})}}console.groupEnd()},CacheManager:on,cartographicToCartesian:hn,WGS84:an,getProjection:bn,isPlainObject:_n,parseVector2:t=>t instanceof j?t:new j(...t),parseVector3:Mn,SceneJsonRefTracer:Qe};let An=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 Tn extends An{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 Cn extends Tn{constructor(t){super(),u(this,"key",""),u(this,"objectType","BaseObject"),u(this,"options"),u(this,"_keyType",""),u(this,"uuid",""),u(this,"object3d"),u(this,"userData",{}),u(this,"isPrefab",!1),u(this,"isInstantiate",!1),u(this,"isBloom",!1),u(this,"isBaseObject",!0),u(this,"isDispose",!1),this.object3d=t}get name(){return this.object3d.name}set name(t){this.object3d.name=t}get keyType(){return this._keyType||this.objectType}set keyType(t){this._keyType=t}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[0]instanceof y?t[0]:new y(...t);this.object3d.lookAt(e)}draw(t,...e){return this.lead.draw({target:this},t,...e)}drawPrefab(t,...e){return this.lead.draw({target:this,prefab:!0},t,...e)}add(...t){t.forEach(t=>{const e=t instanceof Cn?t:this.lead.wrap(t);this.object3d.add(e.object3d)})}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(){}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()}))}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,i;const s=null==(e=null==t?void 0:t.recursive)||e,r=null!=(n=null==t?void 0:t.cloneMaterial)&&n;let o;if(null==(i=null==t?void 0:t.instancedAttr)?void 0:i.length){const e=t.instancedAttr.length;if(this.object3d instanceof L)o=((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=Ye,r})(this.object3d,e);else{const t=this.object3d,n=r?this.cloneMaterial():t.material;o=new k(t.geometry,n,e)}((t,e)=>{const n=new b;e.forEach((e,i)=>{const s=Mn(e.position),r=Mn(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 R,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}})})(o,null==t?void 0:t.instancedAttr)}else{o=this.object3d.clone(!1);const t=o;r&&t.material&&(Array.isArray(t.material)?t.material=t.material.map(t=>t.clone()):t.material=t.material.clone())}o.userData.prefab&&delete o.userData.prefab;const a=this.constructor;let h;try{h=this.options?new a(this.options):new a(o),h.object3d!==o&&(h.object3d=o)}catch(c){console.warn(`[BaseObject] Instantiate failed for ${this.objectType}, fallback to BaseObject wrapper.`),h=new Cn(o)}h.objectType=this.objectType,h.keyType=this._keyType;let l=(null==t?void 0:t.target)||this.parent||this.lead.group;return l===this.lead.prefabGroup&&(l=this.lead.group),h.isInstantiate=!0,yield this.lead.add(h,l),this.isBloom&&h.enableBloom(),s&&(yield Promise.all(this.children.map(t=>d(this,null,function*(){(yield t.instantiate({cloneMaterial:r,target:h,recursive:!0})).setKey({uuid:h.uuid,syncParentUuid:!0})})))),h})}erase(){this.lead.erase(this)}setKey(t){t.syncParentUuid&&(this.userData.syncParentUuid=!0),this.lead.updateBaseObjectKey(this,t)}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)return;this.isDispose=!0,super.dispose(),this.isBloom&&(this.disableBloom(!1),null==(t=this.pencil.composerController)||t.checkBloomComposerActive()),null==(e=this.lead)||e.disableCursor(this);const n=new qe;n.disposeMaterial=!1,n.track(this),n.dispose()}}class On extends Cn{constructor(t=new D){super(t),u(this,"objectType","Group")}render(){this.object3d.raycast=(t,e)=>t.intersectObjects(this.object3d.children,!0,e)}}class zn extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","Mesh"),this);n(t instanceof U?t:new U(t,e))}}class En extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","Points"),this);n(t instanceof C?t:new C(t,e))}}class Pn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","Sprite"),this);e(t instanceof L?t:new L(t))}}class jn extends Cn{constructor(t,e,n){var i=(...t)=>(super(...t),u(this,"objectType","InstancedMesh"),this);i(t instanceof k?t:new k(t,e,n))}}class kn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS2DObject"),this);e(t instanceof Zt?t:new Zt(null!=t?t:document.createElement("div")))}}class Rn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS3DObject"),this);e(t instanceof $t?t:new $t(null!=t?t:document.createElement("div")))}}class Bn extends Cn{constructor(t){var e=(...t)=>(super(...t),u(this,"objectType","CSS3DSprite"),this);e(t instanceof Yt?t:new Yt(null!=t?t:document.createElement("div")))}}class Ln extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","AmbientLight"),this);if(t instanceof N)n(t);else{const i=new N(t,e);i.name="环境光",n(i)}}}class Dn extends Cn{constructor(t,e){var n=(...t)=>(super(...t),u(this,"objectType","DirectionalLight"),this);if(t instanceof F)n(t);else{const i=new F(t,e);i.name="平行光",i.target.position.set(0,0,0),i.target.name="平行光目标",i.shadow.camera.name="平行光阴影相机",i.shadow.camera.userData.directionalLightShadow=!0,n(i)}}render(){if(!this.object3d.target.parent){this.parent.add(this.object3d.target);this.lead.objMap.get(this.object3d.target).userData.isLightTarget=!0}}dispose(){const t=this.lead.objMap.get(this.object3d.target);null==t||t.erase(),super.dispose()}}class Un extends Cn{constructor(t,e,n,i){var s=(...t)=>(super(...t),u(this,"objectType","PointLight"),this);if(t instanceof I)s(t);else{const r=new I(t,e,n,i);r.name="点光源",s(r)}}}class Nn extends Cn{constructor(t,e,n,i,s,r){var o=(...t)=>(super(...t),u(this,"objectType","SpotLight"),this);if(t instanceof V)o(t);else{const a=new V(t,e,n,null!=i?i:Math.PI/3,null!=s?s:1,null!=r?r:2);a.name="聚光灯",a.target.name="聚光灯目标",o(a)}}render(){if(!this.object3d.target.parent){this.parent.add(this.object3d.target);this.lead.objMap.get(this.object3d.target).userData.isLightTarget=!0}}dispose(){const t=this.lead.objMap.get(this.object3d.target);null==t||t.erase(),super.dispose()}}class Fn extends Cn{constructor(t,e,n){var i=(...t)=>(super(...t),u(this,"objectType","HemisphereLight"),this);if(t instanceof W)i(t);else{const s=new W(t,e,n);s.name="半球光",i(s)}}}const In=class t extends Cn{constructor(e,n,i,s){var r=(...t)=>(super(...t),u(this,"objectType","RectAreaLight"),this);if(t.rectAreaLightUniformsLibInit||(Gt.init(),t.rectAreaLightUniformsLibInit=!0),e instanceof H)r(e);else{const t=new H(e,n,i,s);t.name="矩形区域光",r(t)}}};u(In,"rectAreaLightUniformsLibInit",!1);let Vn=In;class Wn extends zn{constructor(t={}){super(),u(this,"objectType","Ellipsoid"),u(this,"options"),this.options=t}create(){const t=function(t={}){const{a:e=an.a,b:n=an.b,scaleFactor:i=1/an.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),v=g*y*m*i,b=g*(1-d)*u*i,w=g*y*x*i;h.push(v,b,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 q({color:2200782,metalness:.1,roughness:.7,wireframe:!1});this.object3d.geometry=t,this.object3d.material=e}}function Hn(t,e,n=!1){return n?le(e,t):ve(t,e)}function qn(t,e){const n={type:"Polygon",coordinates:t},[[i,s],[r,a]]=he(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=>Hn(t,n,h))}function Gn(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*ce(t,i)/Math.PI;if(s>e){const r=ue(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=pe(s),o=qn(t,e),a=[...r,...o],h={type:"Polygon",coordinates:t},[[l,c],[u,d]]=he(h),p=l>u||d>=89||c<=-89;let f=[];if(p){const t=be(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(!Hn(t.properties.circumcenter,h,p))return}f.push(...i)}})}else if(o.length){const t=xe.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(!Hn([0,1].map(t=>fe(i,e=>e[t])),h,p))continue}f.push(...n)}}else{const{vertices:t,holes:e=[]}=ge(s);f=ye(t,e,2)}let m=n?[n[0],n[2]]:me(a,t=>t[0]),y=n?[n[1],n[3]]:me(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=we(m,[0,1]),x=we(y,[0,1]),v=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:v}}}const Zn=(new S).setAttribute?"setAttribute":"addAttribute";function Xn(t,e,n){const i=t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=hn(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=hn(t,i,e,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 ge(i)}function $n(t,e,n,i,s){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:Xn([t.points],e,s).vertices,uvs:n}}const Yn=({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=>{de(t)||t.reverse()});const l="function"==typeof a?a:void 0,{contour:c,triangles:u}=Gn(t,{resolution:i,bbox:h,projection:l});let d,p={};s&&(p=function(t,e,n,i){const{vertices:s,holes:r}=Xn(t,e,i),{vertices:o}=Xn(t,n,i),a=pe([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=pe(u.uvs));let m={};r&&(m=$n(u,e,f,!1,a));let y={};return o&&(y=$n(u,n,f,!0,a)),{contour:c,triangles:u,sideTorso:p,bottomCap:m,topCap:y,topVerts:d}};class Jn 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}=Yn(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 G(new Float64Array(c),3)),this.setIndex(d),this[Zn]("position",new A(c,3)),this[Zn]("uv",new A(u,2)),this.computeVertexNormals()}}function Kn(t,e=0){const n=_e(t,!1);if(!n)return null;if(e){const i=null!==t[0].index;let s=0;for(let r=0;r<t.length;r++){const o=t[r];let a;if(i)a=o.index.count;else{if(void 0===o.attributes.position)return null;a=o.attributes.position.count}if(1===e)n.addGroup(s,a,r);else if(2===e&&o.groups.length>0)for(const t of o.groups)n.addGroup(s+t.start,Math.min(t.count,a),t.materialIndex);s+=a}if(2===e)return Me(n)}return n}function Qn({coordinatesArr:t,metaArray:e,globalMeta:n,hasTop:i,topFirst:s,hasBottom:r,hasSide:o,projection:a="sphere",curvatureResolution:u,bbox:d}){return t.map((t,p)=>{var f,m;const y=e&&e[p]||n||[],g=null!=(f=y[0])?f:0,x=null!=(m=y[1])?m:0;return(t=>{const e=t,{coordinate:n,startHeight:i,height:s}=e,r=c(e,["coordinate","startHeight","height"]);let o=i||0;return void 0!==i&&void 0!==s&&(o=i+s),new Jn([n],l(h({},r),{startHeight:i,endHeight:o}))})({coordinate:t,projection:a,startHeight:x,height:g,hasTop:null==i||i,topFirst:null!=s&&s,hasBottom:null==r||r,hasSide:null==o||o,curvatureResolution:null!=u?u:1,bbox:d})})}const ti={ArcCurve:st,CatmullRomCurve3:it,CubicBezierCurve:nt,CubicBezierCurve3:et,EllipseCurve:tt,LineCurve:Q,LineCurve3:K,QuadraticBezierCurve:J,QuadraticBezierCurve3:Y,SplineCurve:$};class ei extends S{constructor(t=new Z([new j(.5,.5),new j(-.5,.5),new j(-.5,-.5),new j(.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,v=void 0!==e.UVGenerator?e.UVGenerator:ni,b=null==(r=e.hasTop)||r,w=null==(o=e.hasBottom)||o,_=null==(a=e.hasSide)||a;let M,S,A,T,C,O=!1;x&&(M=x.getSpacedPoints(c),O=!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 z=t.extractPoints(l);let E=z.shape;const P=z.holes;if(!X.isClockWise(E)){E=E.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];X.isClockWise(e)&&(P[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 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}}k(E),P.forEach(k);const R=P.length,B=E;for(let e=0;e<R;e++){const t=P[e];E=E.concat(t)}function L(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const D=E.length;function U(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 j(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 j(i/r,s/r)}const N=[];for(let e=0,n=B.length,i=n-1,s=e+1;e<n;e++,i++,s++)i===n&&(i=0),s===n&&(s=0),N[e]=U(B[e],B[i],B[s]);const F=[];let I,V,W=N.concat();for(let e=0,n=R;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]=U(t[e],t[i],t[s]);F.push(I),W=W.concat(I)}if(0===g)V=X.triangulateShape(B,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=B.length;e<n;e++){const n=L(B[e],N[e],r);Z(n.x,n.y,-s),0===i&&t.push(n)}for(let t=0,n=R;t<n;t++){const n=P[t];I=F[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=L(n[t],I[t],r);Z(e.x,e.y,-s),0===i&&o.push(e)}0===i&&e.push(o)}}V=X.triangulateShape(t,e)}const H=V.length,q=f+m;for(let e=0;e<D;e++){const t=d?L(E[e],W[e],q):E[e];O?(T.copy(S.normals[0]).multiplyScalar(t.x),A.copy(S.binormals[0]).multiplyScalar(t.y),C.copy(M[0]).add(T).add(A),Z(C.x,C.y,C.z)):Z(t.x,t.y,0)}for(let e=1;e<=c;e++)for(let t=0;t<D;t++){const n=d?L(E[t],W[t],q):E[t];O?(T.copy(S.normals[e]).multiplyScalar(n.x),A.copy(S.binormals[e]).multiplyScalar(n.y),C.copy(M[e]).add(T).add(A),Z(C.x,C.y,C.z)):Z(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=B.length;e<s;e++){const t=L(B[e],N[e],i);Z(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=L(t[e],I[e],i);O?Z(s.x,s.y+M[c-1].y,M[c-1].x+n):Z(s.x,s.y,u+n)}}}function G(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=D*t,r=D*(t+1);Y(e+i+n,e+s+n,e+s+r,e+i+r)}}}function Z(t,e,n){h.push(t),h.push(e),h.push(n)}function $(t,e,s){J(t),J(e),J(s);const r=i.length/3,o=v.generateTopUV(n,i,r-3,r-2,r-1);K(o[0]),K(o[1]),K(o[2])}function Y(t,e,s,r){J(t),J(e),J(r),J(e),J(s),J(r);const o=i.length/3,a=v.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=D*t;if(w)for(let n=0;n<H;n++){const t=V[n];$(t[2]+e,t[1]+e,t[0]+e)}if(t=c+2*g,e=D*t,b)for(let n=0;n<H;n++){const t=V[n];$(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<H;t++){const e=V[t];$(e[2],e[1],e[0])}if(b)for(let t=0;t<H;t++){const e=V[t];$(e[0]+D*c,e[1]+D*c,e[2]+D*c)}}n.addGroup(t,i.length/3-t,0)}(),_&&function(){const t=i.length/3;let e=0;G(B,e),e+=B.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];G(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 ti[i.type]).fromJSON(i)),new ei(n,t.options)}}const ni={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 j(r,o),new j(a,h),new j(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 j(o,1-h),new j(l,1-u),new j(d,1-f),new j(m,1-g)]:[new j(a,1-h),new j(c,1-u),new j(p,1-f),new j(y,1-g)]}};class ii extends ei{constructor(t,e){super(t,e);const n=new Se(new ei(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;const c=new rt(s.x,s.y,o,o),u=new Se(c);u.position.set(r.x,r.y,r.z),u.updateMatrixWorld();const d=(new Ae).evaluate(u,n,Te),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 ei(t,l(h({},e),{hasTop:!1})),g=Kn([d.geometry,m],2);this.copy(g.toNonIndexed())}}const si=t=>{const{box3:e,sideBox:n}=t,i=e.getSize(new y),s=n.getSize(new y);return t.sideRepeat&&(s.z/=t.sideRepeat),{generateTopUV(t,n,s,r,o){const a=n[3*s],h=n[3*s+1],l=n[3*r],c=n[3*r+1],u=n[3*o],d=n[3*o+1];return[new j((a-e.min.x)/i.x,(h-e.min.y)/i.y),new j((l-e.min.x)/i.x,(c-e.min.y)/i.y),new j((u-e.min.x)/i.x,(d-e.min.y)/i.y)]},generateSideWallUV(t,e,i,r,o,a){const h=e[3*i],l=e[3*i+1],c=e[3*i+2],u=e[3*r],d=e[3*r+1],p=e[3*r+2],f=e[3*o],m=e[3*o+1],y=e[3*o+2],g=e[3*a],x=e[3*a+1],v=e[3*a+2];return Math.abs(l-d)<Math.abs(h-u)?[new j((h-n.min.x)/s.x,(c-n.min.z)/s.z),new j((u-n.min.x)/s.x,(p-n.min.z)/s.z),new j((f-n.min.x)/s.x,(y-n.min.z)/s.z),new j((g-n.min.x)/s.x,(v-n.min.z)/s.z)]:[new j((l-n.min.y)/s.y,(c-n.min.z)/s.z),new j((d-n.min.y)/s.y,(p-n.min.z)/s.z),new j((m-n.min.y)/s.y,(y-n.min.z)/s.z),new j((x-n.min.y)/s.y,(v-n.min.z)/s.z)]}}},ri=(t,e)=>t.map(t=>{let n;if(e){const[i,s]=e([...t]);n=new j(i,-s)}else n=new j(...t);return n});function oi(t,e=300,n){const i=[],s=[];return t.forEach((t,r)=>{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&&n[r]&&s.push(n[r],n[r])}else i.push(t),n&&n[r]&&s.push(n[r])}),{splitPolygons:i,splitMeta:s}}function ai({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,bbox:s,projection:r,hasTop:o,hasBottom:a,hasSide:c,splitPolygons:u,topSegments:d}){const p=r&&bn(r);let f,m=e||(t?t.map(t=>ri(t,p)):[]),g=n;if(u){const t=oi(m,u,n);m=t.splitPolygons,g=t.splitMeta}if(s){const t=-180===s[0]&&180===s[2]&&(null==r?void 0:r.rotate),[e,n]=function(t,e,n=0){const[i,s,r,o]=t;let a=1/0,h=1/0,l=-1/0,c=-1/0;for(let u=0;u<=n;u++){const t=n&&u/n;ri([[i+t*(r-i),s],[i+t*(r-i),o],[i,s+t*(o-s)],[r,s+t*(o-s)]],e).forEach(t=>{a=Math.min(a,t.x),h=Math.min(h,t.y),l=Math.max(l,t.x),c=Math.max(c,t.y)})}return[[a,h],[l,c]]}(s,t?bn(l(h({},r),{rotate:void 0})):p,"winkel3"===(null==r?void 0:r.projectionType)?10:0);f=new B(new y(e[0],e[1],0),new y(n[0],n[1],0))}return m.map((t,e)=>{var n,s,r;const h=(null==g?void 0:g[e])||i||[],l=null!=(n=h[0])?n:0,u=null!=(s=h[1])?s:0,p=(t=>{const{depth:e,points:n,box3:i,hasTop:s,hasBottom:r,hasSide:o,sideRepeat:a,topSegments:h}=t,l=h?ii:ei;let c=i;if(!c){c=new B;const t=n.flatMap(t=>[t.x,t.y,0]);c.setFromArray(t)}const u=c.clone();return u.min.z=0,u.max.z=e,new l(new Z(n),{depth:e,bevelEnabled:!1,box3:c,UVGenerator:si({box3:c,sideBox:u,sideRepeat:a}),hasTop:s,hasBottom:r,hasSide:o,topSegments:h})})({points:t,sideRepeat:null!=(r=h[2])?r:1,depth:l,hasTop:o,hasBottom:a,hasSide:c,box3:f,topSegments:d});if(u){const t=p.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+u);t.needsUpdate=!0}return p})}class hi extends zn{constructor(t){super(),u(this,"objectType","ExtrudePolygon"),u(this,"options"),this.options=t}create(){return d(this,null,function*(){const{geometry:t,material:e,useWorker:n=!1}=this.options;let i=t;const s=e;i||(i=n?yield this.createWithWorker():yield this.createLocal()),i&&(this.object3d.geometry=i),s&&(this.object3d.material=s)})}createWithWorker(){return d(this,null,function*(){const{cacheKey:t,onCacheMiss:e}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(e){const t=yield e(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:n,metaArray:i,globalMeta:s,useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,splitPolygons:d,topSegments:p,userData:f,curvatureResolution:m,topFirst:y,useFloat64Array:g}=this.options;if(n&&0!==n.length)return"cesium"===c||"sphere"===c?this.pencil.attributesWorker.geoGeometry("conicPolygon",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:f,useFloat64Array:g,mesaage:{useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,curvatureResolution:m,topFirst:y}}):this.pencil.attributesWorker.geoGeometry("extrudePolygon",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:f,useFloat64Array:g,mesaage:{useGroups:r,hasTop:o,hasBottom:a,hasSide:l,projection:c,bbox:u,splitPolygons:d,topSegments:p}})})}createLocal(){return d(this,null,function*(){const{onCacheMiss:t}=this.options;if(t){const e=yield t(this.options);this.options=h(h({},this.options),e)}const{coordinatesArr:e,metaArray:n,globalMeta:i,useGroups:s,hasTop:r,hasBottom:o,hasSide:a,projection:l,splitPolygons:c,topSegments:u,bbox:d,curvatureResolution:p,topFirst:f}=this.options;if(!e||0===e.length)return;return Kn("cesium"===l||"sphere"===l?Qn({coordinatesArr:e,metaArray:n,globalMeta:i,bbox:d,projection:l,hasTop:r,hasBottom:o,hasSide:a,curvatureResolution:p,topFirst:f}):ai({coordinatesArr:e,metaArray:n,globalMeta:i,bbox:d,projection:l,hasTop:r,hasBottom:o,hasSide:a,splitPolygons:c,topSegments:u}),null!=s?s:0)})}}class li extends S{constructor(t=[],e="none",n,i=!1,s){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),u(this,"useRTC",!1),u(this,"rtcCenter",new y(0,0,0)),this.shape=e,this.useRTC=i,n&&(this.shapeFunction=n),s&&this.rtcCenter.copy(s),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 j?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,i){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,void 0!==n&&(this.useRTC=n),i?this.rtcCenter.copy(i):this.useRTC&&this._points.length>0&&this.rtcCenter.copy(this._points[0]),e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const t=new G(new Float32Array(6*this.pointCount),3),e=new G(new Float32Array(6*this.pointCount),3),n=new G(new Float32Array(6*this.pointCount),3),i=new G(new Float32Array(2*this.pointCount),1),s=new G(new Float32Array(2*this.pointCount),1),r=new G(new Float32Array(2*this.pointCount),1),a=new G(new Float32Array(4*this.pointCount),2),h=new G(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(){if(!this._points[0])return;const t=this.getAttribute("position"),e=this.getAttribute("previous"),n=this.getAttribute("next");let i=0,s=0,r=0;const o=this._points[0],a=this.useRTC?this.getRelativePosition(o):o;e.setXYZ(s,a.x,a.y,a.z),s+=1,e.setXYZ(s,a.x,a.y,a.z),s+=1;for(let c=0;c<this.pointCount;c++){const o=this._points[c],a=this.useRTC?this.getRelativePosition(o):o;t.setXYZ(i,a.x,a.y,a.z),i+=1,t.setXYZ(i,a.x,a.y,a.z),i+=1,c<this.pointCount-1&&(e.setXYZ(s,a.x,a.y,a.z),s+=1,e.setXYZ(s,a.x,a.y,a.z),s+=1),c>0&&c+1<=this.pointCount&&(n.setXYZ(r,a.x,a.y,a.z),r+=1,n.setXYZ(r,a.x,a.y,a.z),r+=1)}const h=this._points[this.pointCount-1],l=this.useRTC?this.getRelativePosition(h):h;n.setXYZ(r,l.x,l.y,l.z),r+=1,n.setXYZ(r,l.x,l.y,l.z),r+=1,t.needsUpdate=!0,e.needsUpdate=!0,n.needsUpdate=!0,this.useRTC?(this.boundingSphere=new _(new y,1/0),this.boundingBox=new B(new y(-1/0,-1/0,-1/0),new y(1/0,1/0,1/0))):(this.computeBoundingSphere(),this.computeBoundingBox())}getRelativePosition(t){return new y(t.x-this.rtcCenter.x,t.y-this.rtcCenter.y,t.z-this.rtcCenter.z)}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())}getRTCCenter(){return this.rtcCenter.clone()}setUseRTC(t){this.useRTC!==t&&(this.useRTC=t,this._points.length>0&&(this.useRTC&&this.rtcCenter.copy(this._points[0]),this.updateGeometry()))}getUseRTC(){return this.useRTC}setRTCCenter(t){this.rtcCenter.copy(t),this._points.length>0&&this.updateGeometry()}}class ci extends ot{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 j(0,0),scaleDown:x=0,alphaMap:v,alphaTest:b=0,repeat:w=new j(1,1),resolution:_=new j(1,1)}=e,M=c(e,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super(l(h({},M),{uniforms:{lineWidth:{value:n},color:{value:new at(i)},opacity:{value:s},map:{value:r},useMap:{value:r?1:0},resolution:{value:_},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:x/10},alphaTest:{value:b},alphaMap:{value:v},useAlphaMap:{value:v?1:0},repeat:{value:w},useRTC:{value:0},uRtcOffset:{value:new y(0,0,0)},uViewRotation:{value:new g},uModelMatrix:{value:new g}},vertexShader:"\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 相关 uniforms (始终定义,通过 useRTC 控制是否启用)\n uniform float useRTC; // 0.0 = 禁用, 1.0 = 启用\n uniform vec3 uRtcOffset; // (TransformedCenter - Camera)\n uniform mat4 uViewRotation; // 只有旋转的 View 矩阵\n uniform mat4 uModelMatrix; // 物体的模型矩阵 (包含缩放和旋转,不包含平移)\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 vec4 currentClip;\n vec4 prevClip;\n vec4 nextClip;\n\n if (useRTC > 0.5) {\n // RTC 模式\n // position, previous, next 已经是相对于 rtcCenter 的坐标\n // 先应用模型矩阵的缩放和旋转,然后处理 RTC 偏移和视图变换\n \n // 应用模型矩阵的缩放和旋转 (不包含平移)\n vec3 modelPosition = (uModelMatrix * vec4(position, 1.0)).xyz;\n vec3 modelPrevious = (uModelMatrix * vec4(previous, 1.0)).xyz;\n vec3 modelNext = (uModelMatrix * vec4(next, 1.0)).xyz;\n \n // 加上 RTC 偏移 (TransformedCenter - Camera)\n vec3 worldPosition = modelPosition + uRtcOffset;\n vec3 worldPrevious = modelPrevious + uRtcOffset;\n vec3 worldNext = modelNext + uRtcOffset;\n \n // 应用视图旋转 (因为我们手动计算了 Translation,所以这里只做 Rotation)\n worldPosition = (uViewRotation * vec4(worldPosition, 1.0)).xyz;\n worldPrevious = (uViewRotation * vec4(worldPrevious, 1.0)).xyz;\n worldNext = (uViewRotation * vec4(worldNext, 1.0)).xyz;\n \n // 投影\n currentClip = projectionMatrix * vec4(worldPosition, 1.0);\n prevClip = projectionMatrix * vec4(worldPrevious, 1.0);\n nextClip = projectionMatrix * vec4(worldNext, 1.0);\n } else {\n // 非 RTC 模式,使用原始逻辑\n mat4 m = projectionMatrix * modelViewMatrix;\n currentClip = m * vec4(position, 1.0);\n prevClip = m * vec4(previous, 1.0);\n nextClip = m * vec4(next, 1.0);\n }\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",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 at(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}get rtcOffset(){return this.uniforms.uRtcOffset.value}set rtcOffset(t){this.uniforms.uRtcOffset.value.copy(t)}get viewRotation(){return this.uniforms.uViewRotation.value}set viewRotation(t){this.uniforms.uViewRotation.value.copy(t)}get modelMatrix(){return this.uniforms.uModelMatrix.value}set modelMatrix(t){this.uniforms.uModelMatrix.value.copy(t)}get useRTC(){return this.uniforms.useRTC.value>.5}set useRTC(t){this.uniforms.useRTC.value=t?1:0}updateRTC(t,e,n){const i=e.elements,s=i[12],r=i[13],o=i[14],a=t.clone();if(n&&a.applyMatrix4(n),this.uniforms.useRTC.value=1,this.uniforms.uRtcOffset.value.set(a.x-s,a.y-r,a.z-o),this.uniforms.uViewRotation.value.extractRotation(e).invert(),n){const t=this.uniforms.uModelMatrix.value;t.copy(n),t.elements[12]=0,t.elements[13]=0,t.elements[14]=0}else this.uniforms.uModelMatrix.value.identity()}static fromParsedShaderMaterial(t){const e=t.uniforms,n={};e.color&&(n.color=e.color.value),e.lineWidth&&(n.lineWidth=e.lineWidth.value),e.opacity&&(n.opacity=e.opacity.value),e.sizeAttenuation&&(n.sizeAttenuation=e.sizeAttenuation.value>.5),e.map&&(n.map=e.map.value),e.alphaMap&&(n.alphaMap=e.alphaMap.value),e.dashArray&&(n.dashArray=e.dashArray.value),e.dashOffset&&(n.dashOffset=e.dashOffset.value),e.dashRatio&&(n.dashRatio=e.dashRatio.value),e.scaleDown&&(n.scaleDown=10*e.scaleDown.value),e.alphaTest&&(n.alphaTest=e.alphaTest.value),e.repeat&&(n.repeat=e.repeat.value),e.resolution&&(n.resolution=e.resolution.value),e.offset&&(n.offset=e.offset.value),e.offsetLoop&&(n.offsetLoop=e.offsetLoop.value>.5);const i=new ci(n);return i.uuid=t.uuid,i.name=t.name,i.transparent=t.transparent,i.depthTest=t.depthTest,i.depthWrite=t.depthWrite,i.blending=t.blending,i.side=t.side,i.visible=t.visible,i.colorWrite=t.colorWrite,t.userData&&(i.userData=t.userData),i}}function ui(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 ht?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 di=t=>{const{setPointWidth:e,nodes:n,useRTC:i=!1,rtcCenter:s}=t,r=new li(void 0,void 0,void 0,i,s);return r.setPoints(n,e,i,s),r};function pi({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,projection:s,splitPolygons:r}){const o=s&&bn(s);let a=e||(t?t.map(t=>((t,e)=>t.map(t=>{let n;if(e){const[i,s]=e([...t]);n=new y(i,-s,0)}else n=new y(...t);return n}))(t,o)):[]),h=n;if(r){const t=oi(a,r,h);a=t.splitPolygons,h=t.splitMeta}return a.map((t,e)=>{var n;const s=null!=(n=((null==h?void 0:h[e])||i||[])[0])?n:1;return di({nodes:t,setPointWidth:()=>s})})}const fi=/* @__PURE__ */new WeakMap,mi=/* @__PURE__ */new Map;class yi extends zn{constructor(t={}){super(),u(this,"objectType","Line"),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{geometry:t,material:e,useWorker:n=!1}=this.options,i=e;let s=t;s||(s=n?yield this.createWithWorker():yield this.createLocal()),s&&(this.object3d.geometry=s),i&&(this.object3d.material=i)})}createWithWorker(){return d(this,null,function*(){const{cacheKey:t,onCacheMiss:e}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(e){const t=yield e(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:n,metaArray:i,globalMeta:s,useGroups:r,projection:o,splitPolygons:a,userData:l,useFloat64Array:c,useRTC:u}=this.options;if(t){const e=yield this.pencil.attributesWorker.getCachedGeometry({cacheKey:t});if(e)return e}if(n&&0!==n.length)return"cesium"===o||"sphere"===o?this.pencil.attributesWorker.geoGeometry("conicLine",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:l,useFloat64Array:c,mesaage:{useGroups:r,projection:o,useRTC:u}}):this.pencil.attributesWorker.geoGeometry("line",{coordinatesArr:n,metaArray:i,globalMeta:s,cacheKey:t,userData:l,useFloat64Array:c,mesaage:{useGroups:r,projection:o,splitPolygons:a}})})}createLocal(){return d(this,null,function*(){var t,e;const{onCacheMiss:n}=this.options;if(n){const t=yield n(this.options);this.options=h(h({},this.options),t)}const{coordinatesArr:i,metaArray:s,globalMeta:r,useGroups:o,projection:a,splitPolygons:l,useRTC:c}=this.options;if(!i||0===i.length)return;const u="cesium"===a||"sphere"===a?function({coordinatesArr:t,metaArray:e,globalMeta:n,projection:i="sphere",useRTC:s=!1}){let r;return t.map((t,s)=>{var r;const o=null!=(r=(e&&e[s]||n||[])[1])?r:0;return Yn({polygonGeoJson:[t],startHeight:o,projection:i}).topVerts}).map((t,i)=>{var o;const a=null!=(o=(e&&e[i]||n||[])[0])?o:1,h=di({nodes:t,setPointWidth:()=>a,useRTC:s,rtcCenter:r});return 0===i&&(r=h.getRTCCenter()),h})}({coordinatesArr:i,metaArray:s,globalMeta:r,projection:a,useRTC:c}):pi({coordinatesArr:i,metaArray:s,globalMeta:r,projection:a,splitPolygons:l}),d=u[0],p=(null==(t=d.getUseRTC)?void 0:t.call(d))&&(null==(e=d.getRTCCenter)?void 0:e.call(d)),f=Kn(u,null!=o?o:0);return p&&(f.userData.rtcCenter=p),f})}setGeometry(t,e,n,i){const s=di({nodes:t,setPointWidth:e,useRTC:n,rtcCenter:i}),r=this.object3d,o=r.geometry;r.geometry=s,null==o||o.dispose()}createMaterial(t){const{width:e,height:n}=this.pencil.getSize(),i=new ci(h({color:new at("#ffffff")},t));return i.uniforms.resolution.value.set(e,n),i}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?mi:fi;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 Nt.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",mi.size)}stopAnimation(){const t=this.pencil.userData.debugLine?mi:fi,e=t.get(this.material);e&&(e.stop(),Nt.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",mi.size)}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}update(){const t=this.object3d,e=t.geometry,n=this.material,i=null==e?void 0:e.userData.rtcCenter;i&&this.material&&n.updateRTC(i,this.pencil.camera.matrixWorld,t.matrixWorld)}}const gi=class t extends Cn{constructor(t){const e=document.createElement("div");let n;t.children&&t.children instanceof HTMLElement&&e.appendChild(t.children);const i=t.type||"2d";n="3d"===i?new $t(e):"3dSprite"===i?new Yt(e):new Zt(e),super(n),u(this,"objectType","Node"),u(this,"options"),u(this,"pickObject"),u(this,"element"),u(this,"onNodePointerIndex",[]),this.element=e,this.options=h({type:"2d"},t),t.position&&this.object3d.position.copy(t.position)}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(gi,"sharedObserver"),u(gi,"observerMap",/* @__PURE__ */new Map);let xi=gi;class vi extends On{constructor(t){super(),u(this,"objectType","Pie"),u(this,"options"),this.options=h({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return d(this,null,function*(){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 lt({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 Z;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 ei(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 Nt.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 Nt.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 Nt.Tween(this.object3d.scale).to({z:1},1e3).easing(Nt.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 wi extends Oe{constructor(){super();const t=bi;this.uniforms=ct.clone(t.uniforms),this.material=new ut({name:t.name,uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),this.fsQuad?this.fsQuad=new ze(this.material):this._fsQuad&&(this._fsQuad=new ze(this.material))}}const _i=new lt({color:"black"}),Mi=new T({color:"black",sizeAttenuation:!1}),Si=new T({color:"black",sizeAttenuation:!0}),Ai=new dt({color:"black",sizeAttenuation:!0}),Ti=new dt({color:"black",sizeAttenuation:!1}),Ci=new ci({color:"black",sizeAttenuation:!1,lineWidth:0}),Oi=new at(0);class zi{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 mt),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 j),l=new pt(h.width,h.height,{samples:Math.min(o,a),type:ft}),c=new Ft(r,l),d=this.getSize();c.setSize(d.width,d.height);const p=new It(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 wi;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 j),r=s.width,o=s.height,a=new Vt(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 Wt(new j(window.innerWidth,window.innerHeight),i,s,n);this.bloomPass=o;const a=new Ft(e);a.renderToScreen=!1,a.addPass(this.renderPass),a.addPass(o),this.bloomComposer=a;const h=(t=>{const e=new Ce(new ot({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=Ai:s.material=Ti:i.material instanceof ci?i.material=Ci:r.isPoints?r.material.sizeAttenuation?r.material=Si:r.material=Mi:i.material=_i}})}),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=Oi)}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===Oi){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 j)}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 Ei=1,Pi=2,ji=4,ki=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}),Ri=0,Bi=1,Li=-1;function Di(t){return t.isPerspectiveCamera}function Ui(t){return t.isOrthographicCamera}const Ni=2*Math.PI,Fi=Math.PI/2,Ii=Math.PI/180;function Vi(t,e,n){return Math.max(e,Math.min(n,t))}function Wi(t,e=1e-5){return Math.abs(t)<e}function Hi(t,e,n=1e-5){return Wi(t-e,n)}function qi(t,e){return Math.round(t/e)*e}function Gi(t){return isFinite(t)?t:t<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Zi(t){return Math.abs(t)<Number.MAX_VALUE?t:t*(1/0)}function Xi(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=Vi(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 $i(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,v=s*i,b=p*p+f*f+m*m;if(b>v*v){const t=Math.sqrt(b);p=p/t*v,f=f/t*v,m=m/t*v}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 Yi(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 Ji(t,e){return!!Ui(t)&&(console.warn(`${e} is not supported in OrthographicCamera`),!0)}class Ki{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 Qi=1/8,ts=/Mac/.test(navigator.platform);let es,ns,is,ss,rs,os,as,hs,ls,cs,us,ds,ps,fs,ms,ys,gs,xs,vs,bs,ws,_s,Ms;class Ss extends Ki{static install(t){es=t.THREE,ns=Object.freeze(new es.Vector3(0,0,0)),is=Object.freeze(new es.Vector3(0,1,0)),ss=Object.freeze(new es.Vector3(0,0,1)),rs=new es.Vector2,os=new es.Vector3,as=new es.Vector3,hs=new es.Vector3,ls=new es.Vector3,cs=new es.Vector3,us=new es.Vector3,ds=new es.Vector3,ps=new es.Vector3,fs=new es.Vector3,ms=new es.Spherical,ys=new es.Spherical,gs=new es.Box3,xs=new es.Box3,vs=new es.Sphere,bs=new es.Quaternion,ws=new es.Quaternion,_s=new es.Matrix4,Ms=new es.Raycaster}static get ACTION(){return ki}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=ki.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=Ri,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new es.Vector3,this._focalOffsetVelocity=new es.Vector3,this._zoomVelocity={value:0},this._truckInternal=(t,e,n,i)=>{let s,r;if(Di(this._camera)){const n=os.copy(this._camera.position).sub(this._target),i=this._camera.getEffectiveFOV()*Ii,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(!Ui(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=Ni*this.azimuthRotateSpeed*t/this._elementRect.height,i=Ni*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=Vi(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===es&&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 es.Quaternion).setFromUnitVectors(this._camera.up,is),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=ki.NONE,this._target=new es.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new es.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=(new es.Spherical).setFromVector3(os.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 es.Vector3,new es.Vector3,new es.Vector3,new es.Vector3],this._updateNearPlaneCorners(),this._boundary=new es.Box3(new es.Vector3(-1/0,-1/0,-1/0),new es.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 es.Vector2,this.mouseButtons={left:ki.ROTATE,middle:ki.DOLLY,right:ki.TRUCK,wheel:Di(this._camera)?ki.DOLLY:Ui(this._camera)?ki.ZOOM:ki.NONE},this.touches={one:ki.TOUCH_ROTATE,two:Di(this._camera)?ki.TOUCH_DOLLY_TRUCK:Ui(this._camera)?ki.TOUCH_ZOOM_TRUCK:ki.NONE,three:ki.TOUCH_TRUCK};const n=new es.Vector2,i=new es.Vector2,s=new es.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&Ei)===Ei?Ei:(t.buttons&ji)===ji?ji:(t.buttons&Pi)===Pi?Pi:null;if(null!==e){const t=this._findPointerByMouseButton(e);t&&this._disposePointer(t)}if((t.buttons&Ei)===Ei&&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&Ei)===Ei)&&(this._state=this._state|this.mouseButtons.left),this._isDragging&&(t.buttons&ji)===ji&&(this._state=this._state|this.mouseButtons.middle),this._isDragging&&(t.buttons&Pi)===Pi&&(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=ki.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=ki.NONE;p()}};let h=-1;const l=t=>{if(!this._domElement)return;if(!this._enabled||this.mouseButtons.wheel===ki.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===ki.ROTATE||this.mouseButtons.wheel===ki.TRUCK){const t=performance.now();h-t<1e3&&this._getClientRect(this._elementRect),h=t}const e=ts?-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 ki.ROTATE:this._rotateInternal(t.deltaX,t.deltaY),this._isUserControllingRotate=!0;break;case ki.TRUCK:this._truckInternal(t.deltaX,t.deltaY,!1,!1),this._isUserControllingTruck=!0;break;case ki.SCREEN_PAN:this._truckInternal(t.deltaX,t.deltaY,!1,!0),this._isUserControllingTruck=!0;break;case ki.OFFSET:this._truckInternal(t.deltaX,t.deltaY,!0,!1),this._isUserControllingOffset=!0;break;case ki.DOLLY:this._dollyInternal(-n,i,s),this._isUserControllingDolly=!0;break;case ki.ZOOM:this._zoomInternal(-n,i,s),this._isUserControllingZoom=!0}this.dispatchEvent({type:"control"})},c=t=>{if(this._domElement&&this._enabled){if(this.mouseButtons.right===Ss.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;Yi(this._activePointers,rs),this._getClientRect(this._elementRect),n.copy(rs),i.copy(rs);if(this._activePointers.length>=2){const t=rs.x-this._activePointers[1].clientX,e=rs.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&Ei)!==Ei||(this._state=this._state|this.mouseButtons.left),(t.buttons&ji)===ji&&(this._state=this._state|this.mouseButtons.middle),(t.buttons&Pi)===Pi&&(this._state=this._state|this.mouseButtons.right);else this._lockedPointer&&(this._state=this._state|this.mouseButtons.left);(this._state&ki.ROTATE)!==ki.ROTATE&&(this._state&ki.TOUCH_ROTATE)!==ki.TOUCH_ROTATE&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.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&ki.TRUCK)!==ki.TRUCK&&(this._state&ki.SCREEN_PAN)!==ki.SCREEN_PAN&&(this._state&ki.TOUCH_TRUCK)!==ki.TOUCH_TRUCK&&(this._state&ki.TOUCH_SCREEN_PAN)!==ki.TOUCH_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN||(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),(this._state&ki.DOLLY)!==ki.DOLLY&&(this._state&ki.TOUCH_DOLLY)!==ki.TOUCH_DOLLY&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE||(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),(this._state&ki.ZOOM)!==ki.ZOOM&&(this._state&ki.TOUCH_ZOOM)!==ki.TOUCH_ZOOM&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_ZOOM_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.TOUCH_ZOOM_OFFSET&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.TOUCH_ZOOM_ROTATE||(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),(this._state&ki.OFFSET)!==ki.OFFSET&&(this._state&ki.TOUCH_OFFSET)!==ki.TOUCH_OFFSET&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.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,Yi(this._activePointers,rs);const t=this._domElement&&this._domElement.ownerDocument.pointerLockElement===this._domElement?this._lockedPointer||this._activePointers[0]:null,e=t?-t.deltaX:i.x-rs.x,r=t?-t.deltaY:i.y-rs.y;if(i.copy(rs),(this._state&ki.ROTATE)!==ki.ROTATE&&(this._state&ki.TOUCH_ROTATE)!==ki.TOUCH_ROTATE&&(this._state&ki.TOUCH_DOLLY_ROTATE)!==ki.TOUCH_DOLLY_ROTATE&&(this._state&ki.TOUCH_ZOOM_ROTATE)!==ki.TOUCH_ZOOM_ROTATE||(this._rotateInternal(e,r),this._isUserControllingRotate=!0),(this._state&ki.DOLLY)===ki.DOLLY||(this._state&ki.ZOOM)===ki.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&ki.DOLLY)===ki.DOLLY?(this._dollyInternal(i*r*Qi,t,e),this._isUserControllingDolly=!0):(this._zoomInternal(i*r*Qi,t,e),this._isUserControllingZoom=!0)}if((this._state&ki.TOUCH_DOLLY)===ki.TOUCH_DOLLY||(this._state&ki.TOUCH_ZOOM)===ki.TOUCH_ZOOM||(this._state&ki.TOUCH_DOLLY_TRUCK)===ki.TOUCH_DOLLY_TRUCK||(this._state&ki.TOUCH_ZOOM_TRUCK)===ki.TOUCH_ZOOM_TRUCK||(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)===ki.TOUCH_DOLLY_SCREEN_PAN||(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)===ki.TOUCH_ZOOM_SCREEN_PAN||(this._state&ki.TOUCH_DOLLY_OFFSET)===ki.TOUCH_DOLLY_OFFSET||(this._state&ki.TOUCH_ZOOM_OFFSET)===ki.TOUCH_ZOOM_OFFSET||(this._state&ki.TOUCH_DOLLY_ROTATE)===ki.TOUCH_DOLLY_ROTATE||(this._state&ki.TOUCH_ZOOM_ROTATE)===ki.TOUCH_ZOOM_ROTATE){const t=rs.x-this._activePointers[1].clientX,e=rs.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&ki.TOUCH_DOLLY)===ki.TOUCH_DOLLY||(this._state&ki.TOUCH_DOLLY_ROTATE)===ki.TOUCH_DOLLY_ROTATE||(this._state&ki.TOUCH_DOLLY_TRUCK)===ki.TOUCH_DOLLY_TRUCK||(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)===ki.TOUCH_DOLLY_SCREEN_PAN||(this._state&ki.TOUCH_DOLLY_OFFSET)===ki.TOUCH_DOLLY_OFFSET?(this._dollyInternal(r*Qi,o,a),this._isUserControllingDolly=!0):(this._zoomInternal(r*Qi,o,a),this._isUserControllingZoom=!0)}(this._state&ki.TRUCK)!==ki.TRUCK&&(this._state&ki.TOUCH_TRUCK)!==ki.TOUCH_TRUCK&&(this._state&ki.TOUCH_DOLLY_TRUCK)!==ki.TOUCH_DOLLY_TRUCK&&(this._state&ki.TOUCH_ZOOM_TRUCK)!==ki.TOUCH_ZOOM_TRUCK||(this._truckInternal(e,r,!1,!1),this._isUserControllingTruck=!0),(this._state&ki.SCREEN_PAN)!==ki.SCREEN_PAN&&(this._state&ki.TOUCH_SCREEN_PAN)!==ki.TOUCH_SCREEN_PAN&&(this._state&ki.TOUCH_DOLLY_SCREEN_PAN)!==ki.TOUCH_DOLLY_SCREEN_PAN&&(this._state&ki.TOUCH_ZOOM_SCREEN_PAN)!==ki.TOUCH_ZOOM_SCREEN_PAN||(this._truckInternal(e,r,!1,!0),this._isUserControllingTruck=!0),(this._state&ki.OFFSET)!==ki.OFFSET&&(this._state&ki.TOUCH_OFFSET)!==ki.TOUCH_OFFSET&&(this._state&ki.TOUCH_DOLLY_OFFSET)!==ki.TOUCH_DOLLY_OFFSET&&(this._state&ki.TOUCH_ZOOM_OFFSET)!==ki.TOUCH_ZOOM_OFFSET||(this._truckInternal(e,r,!0,!1),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},p=()=>{Yi(this._activePointers,rs),i.copy(rs),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!==ki.NONE&&(this._state=ki.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=Vi(t.width,0,1),this._interactiveArea.height=Vi(t.height,0,1),this._interactiveArea.x=Vi(t.x,0,1-this._interactiveArea.width),this._interactiveArea.y=Vi(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=Vi(t,this.minAzimuthAngle,this.maxAzimuthAngle),s=Vi(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||Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(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=Ri,this._changedDolly=0,this._dollyToNoClamp(Vi(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=Hi(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||Hi(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(i)}dollyInFixed(t,e=!1){this._targetEnd.add(this._getCameraDirection(ls).multiplyScalar(t)),e||this._target.copy(this._targetEnd);const n=!e||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(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=Vi(t,this.minZoom,this.maxZoom),this._needsUpdate=!0,e||(this._zoom=this._zoomEnd);const n=!e||Hi(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(),cs.setFromMatrixColumn(this._camera.matrix,0),us.setFromMatrixColumn(this._camera.matrix,1),cs.multiplyScalar(t),us.multiplyScalar(-e);const i=os.copy(cs).add(us),s=as.copy(this._targetEnd).add(i);return this.moveTo(s.x,s.y,s.z,n)}forward(t,e=!1){os.setFromMatrixColumn(this._camera.matrix,0),os.crossVectors(this._camera.up,os),os.multiplyScalar(t);const n=as.copy(this._targetEnd).add(os);return this.moveTo(n.x,n.y,n.z,e)}elevate(t,e=!1){return os.copy(this._camera.up).multiplyScalar(t),this.moveTo(this._targetEnd.x+os.x,this._targetEnd.y+os.y,this._targetEnd.z+os.z,e)}moveTo(t,e,n,i=!1){this._isUserControllingTruck=!1;const s=os.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||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}lookInDirectionOf(t,e,n,i=!1){const s=os.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?gs.copy(t):gs.setFromObject(t);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const l=qi(this._sphericalEnd.theta,Fi),c=qi(this._sphericalEnd.phi,Fi);a.push(this.rotateTo(l,c,e));const u=os.setFromSpherical(this._sphericalEnd).normalize(),d=bs.setFromUnitVectors(u,ss),p=Hi(Math.abs(u.y),1);p&&d.multiply(ws.setFromAxisAngle(is,l)),d.multiply(this._yAxisUpSpaceInverse);const f=xs.makeEmpty();as.copy(h.min).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setX(h.max.x).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setY(h.max.y).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setZ(h.min.z).applyQuaternion(d),f.expandByPoint(as),as.copy(h.min).setZ(h.max.z).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setY(h.min.y).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).setX(h.min.x).applyQuaternion(d),f.expandByPoint(as),as.copy(h.max).applyQuaternion(d),f.expandByPoint(as),f.min.x-=i,f.min.y-=r,f.max.x+=s,f.max.y+=o,d.setFromUnitVectors(ss,u),p&&d.premultiply(ws.invert()),d.premultiply(this._yAxisUpSpace);const m=f.getSize(os),y=f.getCenter(as).applyQuaternion(d);if(Di(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(Ui(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?Ss.createBoundingSphere(t,vs):vs.copy(t);if(n.push(this.moveTo(i.center.x,i.center.y,i.center.z,e)),Di(this._camera)){const t=this.getDistanceToFitSphere(i.radius);n.push(this.dollyTo(t,e))}else if(Ui(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=Ri,this._changedDolly=0;const a=as.set(i,s,r),h=os.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||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold)&&Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Hi(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=Ri,this._changedDolly=0;const f=os.set(i,s,r),m=as.set(t,e,n);ms.setFromVector3(m.sub(f).applyQuaternion(this._yAxisUpSpace));const y=hs.set(l,c,u),g=as.set(o,a,h);ys.setFromVector3(g.sub(y).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(f.lerp(y,d));const x=ys.theta-ms.theta,v=ys.phi-ms.phi,b=ys.radius-ms.radius;this._sphericalEnd.set(ms.radius+b*d,ms.phi+v*d,ms.theta+x*d),this.normalizeRotations(),this._needsUpdate=!0,p||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const w=!p||Hi(this._target.x,this._targetEnd.x,this.restThreshold)&&Hi(this._target.y,this._targetEnd.y,this.restThreshold)&&Hi(this._target.z,this._targetEnd.z,this.restThreshold)&&Hi(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&Hi(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&Hi(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(os),r=this.setLookAt(s.x,s.y,s.z,t,e,n,i);return this._sphericalEnd.phi=Vi(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||Hi(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&Hi(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&Hi(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(s)}setOrbitPoint(t,e,n){this._camera.updateMatrixWorld(),cs.setFromMatrixColumn(this._camera.matrixWorldInverse,0),us.setFromMatrixColumn(this._camera.matrixWorldInverse,1),ds.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const i=os.set(t,e,n),s=i.distanceTo(this._camera.position),r=i.sub(this._camera.position);cs.multiplyScalar(r.x),us.multiplyScalar(r.y),ds.multiplyScalar(r.z),os.copy(cs).add(us).add(ds),os.z=os.z+s,this.dollyTo(s,!1),this.setFocalOffset(-os.x,os.y,-os.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 es.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(Ji(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const s=t/e,r=this._camera.getEffectiveFOV()*Ii,o=this._camera.aspect;return.5*((i?s>o:s<o)?e:t/o)/Math.tan(.5*r)+.5*n}getDistanceToFitSphere(t){if(Ji(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const e=this._camera.getEffectiveFOV()*Ii,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 es.Vector3).copy(e?this._targetEnd:this._target)}getPosition(t,e=!0){return(t&&t.isVector3?t:new es.Vector3).setFromSpherical(e?this._sphericalEnd:this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(e?this._targetEnd:this._target)}getSpherical(t,e=!0){return(t||new es.Spherical).copy(e?this._sphericalEnd:this._spherical)}getFocalOffset(t,e=!0){return(t&&t.isVector3?t:new es.Vector3).copy(e?this._focalOffsetEnd:this._focalOffset)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%Ni,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=Ni),this._spherical.theta+=Ni*Math.round((this._sphericalEnd.theta-this._spherical.theta)/Ni)}stop(){this._focalOffset.copy(this._focalOffsetEnd),this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd),this._zoom=this._zoomEnd}reset(t=!1){if(!Hi(this._camera.up.x,this._cameraUp0.x)||!Hi(this._camera.up.y,this._cameraUp0.y)||!Hi(this._camera.up.z,this._cameraUp0.z)){this._camera.up.copy(this._cameraUp0);const t=this.getPosition(os);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,is),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert()}applyCameraUp(){const t=os.subVectors(this._target,this._camera.position).normalize(),e=as.crossVectors(t,this._camera.up);this._camera.up.crossVectors(e,t).normalize(),this._camera.updateMatrixWorld();const n=this.getPosition(os);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=ps.subVectors(this._targetEnd,this._target),r=fs.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(Wi(e))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Xi(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,e,1/0,t),this._needsUpdate=!0}if(Wi(n))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const e=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Xi(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,e,1/0,t),this._needsUpdate=!0}if(Wi(i))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const e=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Xi(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,e,this.maxSpeed,t),this._needsUpdate=!0}if(Wi(s.x)&&Wi(s.y)&&Wi(s.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const e=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;$i(this._target,this._targetEnd,this._targetVelocity,e,this.maxSpeed,t,this._target),this._needsUpdate=!0}if(Wi(r.x)&&Wi(r.y)&&Wi(r.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const e=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;$i(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,e,this.maxSpeed,t,this._focalOffset),this._needsUpdate=!0}if(Wi(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const e=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Xi(this._zoom,this._zoomEnd,this._zoomVelocity,e,1/0,t)}if(this.dollyToCursor)if(Di(this._camera)&&0!==this._changedDolly){const t=this._spherical.radius-this._lastDistance,e=this._camera,n=this._getCameraDirection(ls),i=os.copy(n).cross(e.up).normalize();0===i.lengthSq()&&(i.x=1);const s=as.crossVectors(i,n),r=this._sphericalEnd.radius*Math.tan(e.getEffectiveFOV()*Ii*.5),o=(this._sphericalEnd.radius-t-this._sphericalEnd.radius)/this._sphericalEnd.radius,a=hs.copy(this._targetEnd).add(i.multiplyScalar(this._dollyControlCoord.x*r*e.aspect)).add(s.multiplyScalar(this._dollyControlCoord.y*r)),h=os.copy(this._targetEnd).lerp(a,o),l=this._lastDollyDirection===Bi&&this._spherical.radius<=this.minDistance,c=this._lastDollyDirection===Li&&this.maxDistance<=this._spherical.radius;if(this.infinityDolly&&(l||c)){this._sphericalEnd.radius-=t,this._spherical.radius-=t;const e=as.copy(n).multiplyScalar(-t);h.add(e)}this._boundary.clampPoint(h,h);const u=as.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedDolly-=t,Wi(this._changedDolly)&&(this._changedDolly=0)}else if(Ui(this._camera)&&0!==this._changedZoom){const t=this._zoom-this._lastZoom,e=this._camera,n=os.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(e.near+e.far)/(e.near-e.far)).unproject(e),i=as.set(0,0,-1).applyQuaternion(e.quaternion),s=hs.copy(n).add(i.multiplyScalar(-n.dot(e.up))),r=-(this._zoom-t-this._zoom)/this._zoom,o=this._getCameraDirection(ls),a=this._targetEnd.dot(o),h=os.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=as.subVectors(h,this._targetEnd);this._targetEnd.copy(h),this._target.add(u),this._changedZoom-=t,Wi(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);(!Wi(this._focalOffset.x)||!Wi(this._focalOffset.y)||!Wi(this._focalOffset.z))&&(cs.setFromMatrixColumn(this._camera.matrix,0),us.setFromMatrixColumn(this._camera.matrix,1),ds.setFromMatrixColumn(this._camera.matrix,2),cs.multiplyScalar(this._focalOffset.x),us.multiplyScalar(-this._focalOffset.y),ds.multiplyScalar(this._focalOffset.z),os.copy(cs).add(us).add(ds),this._camera.position.add(os),this._camera.updateMatrixWorld()),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),os.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"}),Wi(e,this.restThreshold)&&Wi(n,this.restThreshold)&&Wi(i,this.restThreshold)&&Wi(s.x,this.restThreshold)&&Wi(s.y,this.restThreshold)&&Wi(s.z,this.restThreshold)&&Wi(r.x,this.restThreshold)&&Wi(r.y,this.restThreshold)&&Wi(r.z,this.restThreshold)&&Wi(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:Gi(this.maxDistance),minZoom:this.minZoom,maxZoom:Gi(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Gi(this.maxPolarAngle),minAzimuthAngle:Gi(this.minAzimuthAngle),maxAzimuthAngle:Gi(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,target:this._targetEnd.toArray(),position:os.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=Zi(n.maxDistance),this.minZoom=n.minZoom,this.maxZoom=Zi(n.maxZoom),this.minPolarAngle=n.minPolarAngle,this.maxPolarAngle=Zi(n.maxPolarAngle),this.minAzimuthAngle=Zi(n.minAzimuthAngle),this.maxAzimuthAngle=Zi(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),ms.setFromVector3(os.fromArray(n.position).sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ms.theta,ms.phi,e),this.dollyTo(ms.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=as.copy(e).add(t),r=this._boundary.clampPoint(s,hs).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(as.copy(e).multiplyScalar(i)).add(r.multiplyScalar(1-n))}}_updateNearPlaneCorners(){if(Di(this._camera)){const t=this._camera,e=t.near,n=t.getEffectiveFOV()*Ii,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(Ui(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(Ji(this._camera,"_collisionTest"))return t;const e=this._getTargetDirection(ls);_s.lookAt(ns,e,this._camera.up);for(let n=0;n<4;n++){const i=as.copy(this._nearPlaneCorners[n]);i.applyMatrix4(_s);const s=hs.addVectors(this._target,i);Ms.set(s,e),Ms.far=this._spherical.radius+1;const r=Ms.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 es.Sphere){const n=e,i=n.center;gs.makeEmpty(),t.traverseVisible(t=>{t.isMesh&&gs.expandByObject(t)}),gs.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++)os.fromBufferAttribute(r,o),s=Math.max(s,i.distanceToSquared(os))}),n.radius=Math.sqrt(s),n}}class As extends Ve{constructor(t){super(),u(this,"options"),u(this,"autoRotateSpeed",0),this.options=t;const e={Vector2:j,Vector3:y,Vector4:xt,Quaternion:R,Matrix4:g,Spherical:gt,Box3:B,Sphere:_,Raycaster:yt};Ss.install({THREE:e})}get cameraControls(){return this.controller}addCameraControls(t,e){const{domElement:n}=this.options.controlsParams,i=new Ss(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 Ts{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 Cs={zIndex:"auto"};class Os{constructor(t,e){u(this,"css2Drenderer"),u(this,"css3Drenderer"),u(this,"container"),u(this,"collisionManager"),this.container=t,this.collisionManager=new Ts(null==e?void 0:e.collision)}addRenderer(t,e){const n=h(h({},Cs),e),i=n.container||this.container,s=i.offsetWidth,r=i.offsetHeight,o="css2d"===t?new Xt:new Jt;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 zs{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 vt(100);else if(t.isCamera)i=new bt(t);else if(t.isPointLight)i=new wt(t,1);else if(t.isDirectionalLight)i=new _t(t,1);else if(t.isSpotLight)i=new Mt(t);else if(t.isHemisphereLight)i=new St(t,10);else if(t.isRectAreaLight)i=new Ee(t);else{const e=new B;if(e.setFromObject(t,!0),!1!==e.isEmpty())return;{i=new At(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 Pe(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 vt||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 At){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 Es(t){let e=!1,n=[];return(...i)=>{n=i,e||(e=!0,requestAnimationFrame(()=>{e=!1,t(...n)}))}}class Ps{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}`,Es(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",Es(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,Es(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()}}const js=new S,ks=["_baseObjectObjectType","_baseObjectKeyType","_baseObjectUuid","_baseObjectKey","_baseObjectOptions","_baseObjectNeedsCreate","_baseObjectUserData"],Rs=class t{constructor(t){u(this,"lead"),this.lead=t}get scene(){return this.lead.scene}get group(){return this.lead.group}get prefabGroup(){return this.lead.prefabGroup}get mList(){return this.lead.mList}get objects(){return this.lead.objects}exportCompressScene(){const t=this.exportScene();return this._compressGzip(JSON.stringify(t))}exportScene({checkTextures:t=!1}={}){var e,n,i;const s=[],r=/* @__PURE__ */new Map,o=/* @__PURE__ */new Set,a=/* @__PURE__ */new Map,h=[],l=[],c=[],u=[],d=Tt.getDataURL,p=t=>t&&"PMREM.cubeUv"===t.name,f=t=>null==t?void 0:t.isVideoTexture,m=t=>{var e,n;if(!(null==t?void 0:t.isDataTexture))return!1;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image;return(null==i?void 0:i.data)instanceof ArrayBuffer||ArrayBuffer.isView(null==i?void 0:i.data)},y={isTexture:!0,uuid:"PMREM_PLACEHOLDER",toJSON:()=>({uuid:"PMREM_PLACEHOLDER"})};try{this.mList.fixBaseObjects.forEach(t=>{s.push(t.object3d),this.scene.object3d.add(t.object3d),this.lead.objMap.set(t.object3d,t)}),this.scene.traverse(t=>{var e;if("Node"===t.objectType||t.userData.selectHide)return void o.add(t.object3d);t.object3d.userData._baseObjectObjectType=t.objectType,t.object3d.userData._baseObjectKeyType=t.keyType,t.object3d.userData._baseObjectUuid=t.uuid,t.object3d.userData._baseObjectKey=t.key,t.object3d.userData._baseObjectUserData=this._cloneObjectOptions(t.userData);const n=t.options;if(n){t.object3d.userData._baseObjectOptions=this._cloneObjectOptions(n);const i=t.object3d;(null==(e=i.geometry)?void 0:e.isBufferGeometry)&&(r.set(t.object3d,i.geometry),i.geometry=js,t.object3d.userData._baseObjectNeedsCreate=!0)}const i=t.object3d;if(i.material){const t=Array.isArray(i.material)?i.material:[i.material];for(const e of t)p(e.envMap)&&(l.push({target:e,key:"envMap",texture:e.envMap}),e.envMap=y);for(const e of t)for(const t of Object.keys(e)){const n=e[t];f(n)?(c.push({target:e,key:t,texture:n}),e[t]=this._videoTexToPlaceholder(n)):m(n)&&(u.push({target:e,key:t,texture:n}),e[t]=this._dataTexToPlaceholder(n))}}});for(const t of o)t.parent&&(a.set(t,t.parent),t.removeFromParent());const g=[...this.scene.object3d.children];for(const t of g){const s=null==(e=t.userData)?void 0:e._baseObjectKey,r=void 0!==(null==(n=t.userData)?void 0:n._mListFixKey),o=null==(i=t.userData)?void 0:i.light;"@Scene"===s||"@Camera"===s||"@Group"===s||"@PrefabGroup"===s||r||o||(h.push(t),this.scene.object3d.remove(t))}if(p(this.scene.object3d.environment)&&(l.push({target:this.scene.object3d,key:"environment",texture:this.scene.object3d.environment}),this.scene.object3d.environment=y),p(this.scene.object3d.background)&&(l.push({target:this.scene.object3d,key:"background",texture:this.scene.object3d.background}),this.scene.object3d.background=y),t){const t=["map","envMap","lightMap","aoMap","emissiveMap","bumpMap","normalMap","displacementMap","specularMap","alphaMap","metalnessMap","roughnessMap","gradientMap","sheenColorMap","sheenRoughnessMap","transmissionMap","thicknessMap","specularIntensityMap","specularColorMap","iridescenceMap","iridescenceThicknessMap","anisotropyMap","clearcoatMap","clearcoatNormalMap","clearcoatRoughnessMap"],e=(t,e)=>{var n,i;if(!t||!t.isTexture)return;const s=null!=(i=null==(n=t.source)?void 0:n.data)?i:t.image;!s||s instanceof HTMLCanvasElement||s instanceof HTMLImageElement||s instanceof ImageBitmap||(null==s?void 0:s.data)&&s.width||console.warn("[SceneSerializer] Unable to serialize texture:",e,{texture:t,textureName:t.name,textureUuid:t.uuid,sourceData:s})};this.scene.object3d.traverse(n=>{var i;if(!n.material)return;const s=Array.isArray(n.material)?n.material:[n.material];for(const r of s){const s=`${n.name||n.uuid} / ${r.name||r.type}`;for(const n of t)e(r[n],`${s}.${n}`);if(r.uniforms)for(const t in r.uniforms){const n=null==(i=r.uniforms[t])?void 0:i.value;e(n,`${s}.uniforms.${t}`)}}})}Tt.getDataURL=(t,e="image/webp")=>d(t,e);const x=this.scene.object3d.toJSON();return this._deduplicateSceneJson(x),this._extractSharedOptionsPool(x),JSON.stringify(x)}finally{Tt.getDataURL=d;for(const t of l)t.target[t.key]=t.texture;for(const t of c)t.target[t.key]=t.texture;for(const t of u)t.target[t.key]=t.texture;this.scene.traverse(t=>{this._cleanUserData(t.object3d);const e=r.get(t.object3d);e&&(t.object3d.geometry=e)});for(const t of s)t.removeFromParent(),this.lead.objMap.delete(t);for(const[t,e]of a)e.add(t);for(const t of h)this.scene.object3d.add(t)}}restoreScene(t){return d(this,arguments,function*(t,e={},n){const i=t instanceof ArrayBuffer?yield this._decompressGzip(t):t,s="string"==typeof i?JSON.parse(i):i;this._restoreSharedOptionsPool(s);const r=new Ct,o=r.parseTextures.bind(r);r.parseTextures=(t,e)=>{const i=[],s=[],r=t?t.filter(t=>{var e,n;return"PMREM_PLACEHOLDER"!==t.uuid&&((null==(e=t.userData)?void 0:e._videoSrc)?(i.push(t),!1):!(null==(n=t.userData)?void 0:n._dataTexBase64)||(s.push(t),!1))}):t,a=o(r,e);n&&(a.PMREM_PLACEHOLDER=n);for(const n of i)a[n.uuid]=this._createVideoTextureFromJson(n);for(const n of s)a[n.uuid]=this._createDataTextureFromJson(n);return a};const a=r.parseMaterials.bind(r);r.parseMaterials=(t,e)=>{if(!t)return{};const n=/* @__PURE__ */new Map;for(const s of t)"MeshLineMaterial"===s.type&&(n.set(s.uuid,s.type),s.type="ShaderMaterial");const i=a(t,e);for(const s in i){"MeshLineMaterial"===n.get(s)&&(i[s]=ci.fromParsedShaderMaterial(i[s]))}return i};const h=yield r.parseAsync(s),l=h.children.filter(t=>void 0!==t.userData._mListFixKey);for(const d of l){const t=d.userData._mListFixKey,e=d.material;this.mList.add(t,e),d.removeFromParent()}this._graftParsedScene(h);const c=/* @__PURE__ */new Set([this.scene.object3d,this.group.object3d,this.prefabGroup.object3d]);this.objects.has("@Camera")&&c.add(this.objects.get("@Camera").object3d);const u=[];this.scene.object3d.traverse(t=>{if(c.has(t))return void this._cleanUserData(t);const n=t.userData._baseObjectObjectType||"BaseObject",i=!0===t.userData._baseObjectNeedsCreate,s=this._createInstance(t,n,e);if(t.userData._baseObjectObjectType&&(s.objectType=t.userData._baseObjectObjectType),t.userData._baseObjectKeyType&&(s.keyType=t.userData._baseObjectKeyType),t.userData._baseObjectUuid&&(s.uuid=t.userData._baseObjectUuid),t.userData._baseObjectKey&&(s.key=t.userData._baseObjectKey),t.userData._baseObjectUserData&&(s.userData=t.userData._baseObjectUserData),this._cleanUserData(t),this.lead.register(s),i){const e=t.material,n=Promise.resolve(s.create()).then(()=>{e&&(s.object3d.material=e),s.render(),this.mList&&(this.mList.proxyBaseObject(s),this.mList.addBaseObjectMap(s))});u.push(n)}else s.render(),this.mList&&(this.mList.proxyBaseObject(s),this.mList.addBaseObjectMap(s))}),yield Promise.all(u)})}_createInstance(t,e,n){const i=n[e];if(i){const e=t.userData._baseObjectOptions,n=new i(e||t);return n.object3d!==t&&(n.object3d=t),n}return"Group"===e?new On(t):new Cn(t)}_cloneObjectOptions(t){if(!t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>this._cloneObjectOptions(t)).filter(t=>void 0!==t);if(_n(t)){const e={};for(const n in t){const i=t[n];i&&(i.isBufferGeometry||i.isMaterial||i.isTexture||i.isObject3D||"function"==typeof i||"object"==typeof i&&i.constructor&&"HTMLImageElement"===i.constructor.name)||(e[n]=this._cloneObjectOptions(i))}return e}}_graftParsedScene(t){var e;this._syncObject3dProps(t,this.scene.object3d);for(const n of[...this.scene.object3d.children])n.removeFromParent();for(const n of[...t.children]){const t=null==(e=n.userData)?void 0:e._baseObjectKey;"@Group"===t?(this._graftObject3d(n,this.group.object3d),this.scene.object3d.add(this.group.object3d)):"@PrefabGroup"===t?(this._graftObject3d(n,this.prefabGroup.object3d),this.scene.object3d.add(this.prefabGroup.object3d)):"@Camera"===t&&this.objects.has("@Camera")?(this._graftObject3d(n,this.objects.get("@Camera").object3d),this.scene.object3d.add(this.objects.get("@Camera").object3d)):this.scene.object3d.add(n)}}_graftObject3d(t,e){this._syncObject3dProps(t,e);for(const n of[...e.children])n.removeFromParent();for(const n of[...t.children])e.add(n)}_syncObject3dProps(t,e){const n=t.userData,i=e.userData;t.userData={},e.copy(t),t.userData=n,e.userData=i;for(const s in this._cloneObjectOptions(n))s.startsWith("background")&&e.isScene||s.startsWith("_baseObject")||(e.userData[s]=n[s])}_cleanUserData(t){for(const e of ks)delete t.userData[e]}_deduplicateSceneJson(t){var e,n,i,s;const r=new Qe(t);if((null==(e=t.images)?void 0:e.length)>1){const e=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map;for(const i of t.images){const t=e.get(i.url);t?n.set(i.uuid,t):e.set(i.url,i.uuid)}if(n.size>0){if(t.textures)for(const e of t.textures){const t=n.get(e.image);t&&(e.image=t)}t.images=t.images.filter(t=>!n.has(t.uuid))}}if((null==(n=t.textures)?void 0:n.length)>1){const e=/* @__PURE__ */new Map,n=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map;for(const r of t.textures){const t=null==(i=r.userData)?void 0:i._videoSrc,a=null==(s=r.userData)?void 0:s._dataTexBase64;if(void 0!==t){const n=e.get(t);n?o.set(r.uuid,n):e.set(t,r.uuid)}else if(void 0!==a){const t=n.get(a);t?o.set(r.uuid,t):n.set(a,r.uuid)}}if(o.size>0){if(t.materials)for(const e of t.materials)for(const t of Object.keys(e)){const n=o.get(e[t]);n&&(e[t]=n)}t.textures=t.textures.filter(t=>!o.has(t.uuid)),console.warn(`[SceneSerializer] Deduplicated ${o.size} textures:\n${r.formatRemap(o).join("\n")}`)}}}_extractSharedOptionsPool(e){const n=[],i=/* @__PURE__ */new Map;this._traverseObjectJson(e.object,e=>{var s;const r=null==(s=e.userData)?void 0:s._baseObjectOptions;if(r)for(const o of t._sharedOptionsKeys){const t=r[o];if(void 0===t)continue;const e=JSON.stringify(t);let s=i.get(e);void 0===s&&(s=n.length,n.push(t),i.set(e,s)),r[o]={_sharedRef:s}}}),n.length>0&&(e._sharedOptionsPool=n)}_restoreSharedOptionsPool(e){const n=e._sharedOptionsPool;n&&(delete e._sharedOptionsPool,this._traverseObjectJson(e.object,e=>{var i;const s=null==(i=e.userData)?void 0:i._baseObjectOptions;if(s)for(const r of t._sharedOptionsKeys){const t=s[r];t&&"object"==typeof t&&"_sharedRef"in t&&(s[r]=n[t._sharedRef])}}))}_traverseObjectJson(t,e){if(t&&(e(t),t.children))for(const n of t.children)this._traverseObjectJson(n,e)}_compressGzip(t){return d(this,null,function*(){const e=new Blob([t]),n=new CompressionStream("gzip"),i=e.stream().pipeThrough(n);return new Response(i).arrayBuffer()})}_decompressGzip(t){return d(this,null,function*(){const e=new Blob([t]),n=new DecompressionStream("gzip"),i=e.stream().pipeThrough(n);return new Response(i).text()})}_serializeTexProps(t){var e,n,i,s,r,o,a,h,l,c,u,d,p,f;return{uuid:t.uuid,name:t.name||"",mapping:t.mapping,channel:null!=(e=t.channel)?e:0,repeat:[null!=(i=null==(n=t.repeat)?void 0:n.x)?i:1,null!=(r=null==(s=t.repeat)?void 0:s.y)?r:1],offset:[null!=(a=null==(o=t.offset)?void 0:o.x)?a:0,null!=(l=null==(h=t.offset)?void 0:h.y)?l:0],center:[null!=(u=null==(c=t.center)?void 0:c.x)?u:0,null!=(p=null==(d=t.center)?void 0:d.y)?p:0],rotation:null!=(f=t.rotation)?f:0,wrap:[t.wrapS,t.wrapT],format:t.format,internalFormat:t.internalFormat,type:t.type,colorSpace:t.colorSpace,minFilter:t.minFilter,magFilter:t.magFilter,anisotropy:t.anisotropy,flipY:t.flipY,generateMipmaps:t.generateMipmaps,premultiplyAlpha:t.premultiplyAlpha,unpackAlignment:t.unpackAlignment}}_applyTexProps(t,e){t.uuid=e.uuid,e.name&&(t.name=e.name),void 0!==e.mapping&&(t.mapping=e.mapping),void 0!==e.channel&&(t.channel=e.channel),e.repeat&&t.repeat.set(e.repeat[0],e.repeat[1]),e.offset&&t.offset.set(e.offset[0],e.offset[1]),e.center&&t.center.set(e.center[0],e.center[1]),void 0!==e.rotation&&(t.rotation=e.rotation),e.wrap&&(t.wrapS=e.wrap[0],t.wrapT=e.wrap[1]),void 0!==e.format&&(t.format=e.format),void 0!==e.internalFormat&&(t.internalFormat=e.internalFormat),void 0!==e.type&&(t.type=e.type),void 0!==e.colorSpace&&(t.colorSpace=e.colorSpace),void 0!==e.minFilter&&(t.minFilter=e.minFilter),void 0!==e.magFilter&&(t.magFilter=e.magFilter),void 0!==e.anisotropy&&(t.anisotropy=e.anisotropy),void 0!==e.flipY&&(t.flipY=e.flipY),void 0!==e.generateMipmaps&&(t.generateMipmaps=e.generateMipmaps),void 0!==e.premultiplyAlpha&&(t.premultiplyAlpha=e.premultiplyAlpha),void 0!==e.unpackAlignment&&(t.unpackAlignment=e.unpackAlignment)}_createPlaceholder(t,e,n){return{isTexture:!0,uuid:t,toJSON(i){const s=l(h({},e),{userData:n});return(null==i?void 0:i.textures)&&(i.textures[t]=s),s}}}_videoTexToPlaceholder(t){var e,n;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image;return this._createPlaceholder(t.uuid,this._serializeTexProps(t),{_videoSrc:(null==i?void 0:i.src)||""})}_createVideoTextureFromJson(t){var e;const n=document.createElement("video");n.preload="auto",n.autoplay=!0,n.loop=!0,n.muted=!0,n.setAttribute("webkit-playsinline","webkit-playsinline"),n.setAttribute("playsinline",""),n.src=(null==(e=t.userData)?void 0:e._videoSrc)||"",n.play();const i=new Ot(n);return this._applyTexProps(i,t),i}_dataTexToPlaceholder(t){var e,n;const i=null!=(n=null==(e=t.source)?void 0:e.data)?n:t.image,s=i.data;return this._createPlaceholder(t.uuid,this._serializeTexProps(t),{_dataTexBase64:this._typedArrayToBase64(s),_dataTexArrayType:s.constructor.name,_dataTexWidth:i.width,_dataTexHeight:i.height})}_createDataTextureFromJson(e){var n;const i=e.userData,s=null!=(n=t._typedArrayCtors[i._dataTexArrayType])?n:Uint16Array,r=this._base64ToTypedArray(i._dataTexBase64,s),o=new zt(r,i._dataTexWidth,i._dataTexHeight);return this._applyTexProps(o,e),o.needsUpdate=!0,o}_typedArrayToBase64(t){const e=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let n="";for(let i=0;i<e.length;i+=8192)n+=String.fromCharCode(...e.subarray(i,Math.min(i+8192,e.length)));return btoa(n)}_base64ToTypedArray(t,e){const n=atob(t),i=new Uint8Array(n.length);for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s);return new e(i.buffer)}};u(Rs,"_sharedOptionsKeys",["coordinatesArr","src"]),u(Rs,"_typedArrayCtors",{Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Float32Array:Float32Array,Float64Array:Float64Array});let Bs=Rs;new S;class Ls extends Ps{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,"_serializer",new Bs(this)),this.mList=e.mList,this.scene=new Cn(e.scene||new Et),this.scene.key="@Scene",this.scene.object3d.name="场景",this._initCoreObject(this.scene),this.group=new On,this.group.key="@Group",this.group.object3d.name="物体组",this.scene.add(this.group),this._initCoreObject(this.group),this.prefabGroup=new On,this.prefabGroup.key="@PrefabGroup",this.prefabGroup.object3d.name="预制组",this.scene.add(this.prefabGroup),this._initCoreObject(this.prefabGroup)}get objectsPromise(){return this.objectsPm.values()}register(t){if(t.pencil=this.pencil,t.lead=this,t.mList=this.mList,t.object3d&&this.objMap.set(t.object3d,t),!t.key)if(!t.key&&t.parent&&"@Scene"===t.parent.key&&t.object3d instanceof Pt)t.key="@Camera";else if(!t.key&&t.parent){const e=this.objectWrapChindIdMap.get(t.parent),n=void 0!==e?e+1:0;this.objectWrapChindIdMap.set(t.parent,n);const i=`${t.parent.keyType}__c__${n}`,s=t.parent.uuid;this.updateBaseObjectKey(t,{keyType:i,uuid:s})}else this.updateBaseObjectKey(t);return this.objects.has(t.key)||this.objects.set(t.key,t),t}_initCoreObject(t){this.register(t),t.render(),t.object3d.children.forEach(t=>{t instanceof Pt&&this.wrap(t)})}draw(t,...e){let n,i,s,r=!1;"function"==typeof t?(n=t,i=e):(s=t.target,t.prefab&&(r=!0),n=e[0],i=e.slice(1));const o=new n(...i);return r&&(o.isPrefab=!0),this.add(o,s)}wrap(t){const e=this.objMap.get(t);if(e)return e;const n=t instanceof D?new On(t):new Cn(t);return this.register(n),this.mList&&(this.mList.proxyBaseObject(n),this.mList.addBaseObjectMap(n)),t.children.forEach(t=>{this.wrap(t)}),n}add(t,e){return d(this,null,function*(){let n=this.group;if(null===e)n=null;else if("string"==typeof e){const t=this.objects.get(e);t&&(n=t)}else e instanceof Cn?n=e:t.isPrefab&&(n=this.prefabGroup);this.register(t),n&&t.object3d&&n.object3d.add(t.object3d);const i=this._addLogic(t,n);return this.objectsPm.set(t,i),yield i,this.objectsPm.delete(t),t})}_addLogic(t,e){return d(this,null,function*(){t.isInstantiate||(yield t.create());const e=t.object3d;e.material&&Array.isArray(e.material)&&(e.material=e.material.slice()),t.render(),this.mList&&(this.mList.proxyBaseObject(t),this.mList.addBaseObjectMap(t)),e.children.forEach(t=>{this.objMap.get(t)||this.wrap(t)}),this.pencil.event.emit("lead.draw",{baseObject:t})})}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}updateBaseObjectKey(t,e={}){const n=t.key,i=t.keyType;this.objects.delete(n);const s=e.keyType||t.keyType,r=e.uuid,o=r?`${s}#${r}`:`${s}`;if(!this.objects.has(o))return t.keyType=s,t.uuid=r||"",t.key=o,this.objects.set(o,t),this.pencil.event.emit("lead.updateKey",{baseObject:t,key:o,oldKey:n}),t.children.forEach(t=>{if(t.keyType.includes("__c__")){const e=t.keyType.replace(i,s);this.updateBaseObjectKey(t,{keyType:e,uuid:r})}else t.userData.syncParentUuid&&this.updateBaseObjectKey(t,{uuid:r})}),o;this.updateBaseObjectKey(t,{keyType:s,uuid:je()})}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=>{const n=[...e.children];n.length>0&&this.handleErase(t,...n),this.objects.delete(e.key),this.objectWrapChindIdMap.delete(e),e.object3d&&(this.objMap.delete(e.object3d),e.object3d.removeFromParent()),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))}exportScene(...t){return this._serializer.exportScene(...t)}restoreScene(...t){return d(this,null,function*(){return this._serializer.restoreScene(...t)})}dispose(){super.dispose(),this.scene.erase(),this.objects.forEach(t=>{t.erase()}),this.objects.clear(),this.objectsPm.clear(),this.objMap.clear(),this.objectWrapChindIdMap.clear()}}class Ds extends Ve{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 Ls(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 Us extends jt{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 Ns extends kt{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 Ot(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 Fs={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 Is{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 Rt(()=>{},(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 Bt(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("media",{create:t=>new Ns(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gltf",{create:t=>new De(t),setPath:(t,e)=>t.setPath(e),requiresDraco:!0}),this.loaderConfigs.set("lottie",{create:t=>new Ue(t),setPath:(t,e)=>t.setPath(e)}),this.loaderConfigs.set("gzipJson",{create:t=>new Us(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("json",{create:t=>new jt(t),setPath:(t,e)=>t.setPath(e),setResponseType:(t,e)=>t.setResponseType(e)}),this.loaderConfigs.set("exr",{create:t=>new Le(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(Fs))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 De(this.loadingManager);const t=new Be;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 zt||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=ke();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 Vs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get loader(){return this.controller}addLoader(t,e){const{loaderParams:n}=this.options,i=new Is(l(h({},n),{scene:t}));return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const Ws=class t{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(e,n){this.materials.set(e,n);const i=new U(t._emptyGeometry,n);i.visible=!1,i.userData._mListFixKey=e;const s=new Cn(i),r={value:n};Object.defineProperty(i,"material",{get:()=>r.value,set:t=>{var n;if(null==(n=this.pencil.composerController)?void 0:n.bloomComposerRenderIng)r.value=t;else{const n=r.value;r.value=t,this.materials.set(e,t),this.disposeMaterial(n),this.syncChangeMaterial(n,t)}},enumerable:!0,configurable:!0}),this.fixBaseObjects.set(e,s),this.pencil.event.emit("mList.add",{key:e,material:n,baseObject:s})}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 qe;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){rn({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 qe;t.track([...this.materials.values()]),t.dispose(),this.materials.clear(),this.fixBaseObjects.clear(),this.materialBaseObjectMap.clear()}};u(Ws,"_emptyGeometry",new S);let Hs=Ws;class qs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get mList(){return this.controller}addMList(t,e){const{pencil:n}=this.options,i=new Hs(n);return this.addController(i,e)}removePage(t){super.removePage(t,t=>{t.dispose()})}}const Gs={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMappingExposure:1,alpha:!1,outputColorSpace:tn.sRGB,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1};class Zs{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 Lt({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 Xs extends Ve{constructor(t){super(),u(this,"options"),this.options=t}get scene(){return this.controller}addScene(t,e){const n=new Et;return(null==t?void 0:t.background)&&(n.background=t.background),this.addController(n,e)}removePage(t){super.removePage(t,t=>{const e=new qe;e.track(t),e.dispose()})}setPageActive(t){super.setPageActive(t,(t,e)=>{t.visible=e})}}class $s{constructor(t){u(this,"controls"),u(this,"event",new p);const{renderer:e,scene:n,camera:i}=t,s=new Ne(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 b&&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 Ys={antialias:!0,devicePixelRatio:window.devicePixelRatio};class Js{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 Ks=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 G(t[n].array,t[n].itemSize)):"rtcCenter"===n?e.userData.rtcCenter=new y(t.rtcCenter.x,t.rtcCenter.y,t.rtcCenter.z):e.setAttribute(n,new G(t[n].array,t[n].itemSize))}),e},Qs='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";function t(t){return Object.getOwnPropertyNames(t).reduce(function(e,n){return Object.defineProperty(e,n,{value:t[n],enumerable:!0})},{})}var e=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 n(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function i(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function r(t){let e,r,o;function a(t,n,i=0,s=t.length){if(i<s){if(0!==e(n,n))return s;do{const e=i+s>>>1;r(t[e],n)<0?i=e+1:s=e}while(i<s)}return i}return 2!==t.length?(e=n,r=(e,i)=>n(t(e),i),o=(e,n)=>t(e)-n):(e=t===n||t===i?t:s,r=t,o=t),{left:a,center:function(t,e,n=0,i=t.length){const r=a(t,e,n,i-1);return r>n&&o(t[r-1],e)>-o(t[r],e)?r-1:r},right:function(t,n,i=0,s=t.length){if(i<s){if(0!==e(n,n))return s;do{const e=i+s>>>1;r(t[e],n)<=0?i=e+1:s=e}while(i<s)}return i}}}function s(){return 0}const o=r(n).right;function a(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]}r(function(t){return null===t?NaN:+t}).center;class l{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 f=Math.sqrt(50),m=Math.sqrt(10),g=Math.sqrt(2);function x(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>=f?10:s>=m?5:s>=g?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?x(t,e,2*n):[a,h,l]}function b(t,e,n){return x(t=+t,e=+e,n=+n)[2]}function w(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 v(t){return Array.from(function*(t){for(const e of t)yield*y(e)}(t))}function M(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=S(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=S(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(I(n))}r.sort(P);for(let s=0;s<r.length;s++)n=E(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 z(s,o,n,a,h,l,0),o}function S(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=j(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=j(o/i|0,t[o],t[o+1],s);return s&&V(s,s.next)&&(G(s),s=s.next),s}function A(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!V(i,i.next)&&0!==U(i.prev,i,i.next))i=i.next;else{if(G(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function z(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=N(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?T(t,i,r,s):_(t))e.push(h.i,t.i,l.i),G(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?z(t=B(A(t),e),e,n,i,r,s,2):2===o&&C(t,e,n,i,r,s):z(A(t),e,n,i,r,s,1);break}}}function _(t){const e=t.prev,n=t,i=t.next;if(U(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&&F(r,a,s,h,o,l,f.x,f.y)&&U(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function T(t,e,n,i){const r=t.prev,s=t,o=t.next;if(U(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=N(p,f,e,n,i),x=N(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&&F(a,u,h,c,l,d,b.x,b.y)&&U(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&&F(a,u,h,c,l,d,w.x,w.y)&&U(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&&F(a,u,h,c,l,d,b.x,b.y)&&U(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&&F(a,u,h,c,l,d,w.x,w.y)&&U(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function B(t,e){let n=t;do{const i=n.prev,r=n.next.next;!V(i,r)&&L(i,n,n.next,r)&&X(i,r)&&X(r,i)&&(e.push(i.i,n.i,r.i),G(n),G(n.next),n=t=r),n=n.next}while(n!==t);return A(n)}function C(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&R(o,t)){let a=Z(o,t);return o=A(o,o.next),a=A(a,a.next),z(o,e,n,i,r,s,0),void z(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function P(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 E(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(V(t,n))return n;do{if(V(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&&O(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);X(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&k(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Z(n,t);return A(i,i.next),A(n,n.next)}function k(t,e){return U(t.prev,t,e.prev)<0&&U(e.next,t,t.next)<0}function N(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 I(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 O(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 F(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&O(t,e,n,i,r,s,o,a)}function R(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&&L(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(X(t,e)&&X(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)&&(U(t.prev,t,e.prev)||U(t,e.prev,e))||V(t,e)&&U(t.prev,t,t.next)>0&&U(e.prev,e,e.next)>0)}function U(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function V(t,e){return t.x===e.x&&t.y===e.y}function L(t,e,n,i){const r=D(U(t,e,n)),s=D(U(t,e,i)),o=D(U(n,i,t)),a=D(U(n,i,e));return r!==s&&o!==a||(!(0!==r||!q(t,n,e))||(!(0!==s||!q(t,i,e))||(!(0!==o||!q(n,t,i))||!(0!==a||!q(n,e,i)))))}function q(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 D(t){return t>0?1:t<0?-1:0}function X(t,e){return U(t.prev,t,t.next)<0?U(t,e,t.next)>=0&&U(t,t.prev,e)>=0:U(t,e,t.prev)<0||U(t,t.next,e)<0}function Z(t,e){const n=J(t.i,t.x,t.y),i=J(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 j(t,e,n,i){const r=J(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 G(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 J(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function W(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 $="183",Y=1001,H="srgb",Q="srgb-linear",K="linear",tt="srgb",et=7680,nt=2e3;function it(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const rt={};function st(t){const e=t[0];if("string"==typeof e&&e.startsWith("TSL:")){const e=t[1];e&&e.isStackTrace?t[0]+=" "+e.getLocation():t[1]=\'Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.\'}return t}function ot(...t){const e="THREE."+(t=st(t)).shift();{const n=t[0];n&&n.isStackTrace?console.warn(n.getError(e)):console.warn(e,...t)}}function at(...t){const e="THREE."+(t=st(t)).shift();{const n=t[0];n&&n.isStackTrace?console.error(n.getError(e)):console.error(e,...t)}}function ht(...t){const e=t.join(" ");e in rt||(rt[e]=!0,ot(...t))}class lt{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 ut=["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 ct=1234567;const dt=Math.PI/180,pt=180/Math.PI;function ft(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(ut[255&t]+ut[t>>8&255]+ut[t>>16&255]+ut[t>>24&255]+"-"+ut[255&e]+ut[e>>8&255]+"-"+ut[e>>16&15|64]+ut[e>>24&255]+"-"+ut[63&n|128]+ut[n>>8&255]+"-"+ut[n>>16&255]+ut[n>>24&255]+ut[255&i]+ut[i>>8&255]+ut[i>>16&255]+ut[i>>24&255]).toLowerCase()}function yt(t,e,n){return Math.max(e,Math.min(n,t))}function mt(t,e){return(t%e+e)%e}function gt(t,e,n){return(1-n)*t+n*e}function xt(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 bt(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 wt={DEG2RAD:dt,RAD2DEG:pt,generateUUID:ft,clamp:yt,euclideanModulo:mt,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:gt,damp:function(t,e,n,i){return gt(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(mt(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&&(ct=t);let e=ct+=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*dt},radToDeg:function(t){return t*pt},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:ot("MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:bt,denormalize:xt};class vt{constructor(t=0,e=0){vt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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(yt(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 Mt{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(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:ot("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(yt(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){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 St{constructor(t=0,e=0,n=0){St.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(zt.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(zt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this.z=yt(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this.z=yt(this.z,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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 At.copy(this).projectOnVector(t),this.sub(At)}reflect(t){return this.sub(At.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(yt(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 At=new St,zt=new Mt;class _t{constructor(t,e,n,i,r,s,o,a,h){_t.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(Tt.makeScale(t,e)),this}rotate(t){return this.premultiply(Tt.makeRotation(-t)),this}translate(t,e){return this.premultiply(Tt.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 Tt=new _t,Bt=(new _t).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ct=(new _t).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Pt(){const t={enabled:!0,workingColorSpace:Q,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===tt&&(t.r=kt(t.r),t.g=kt(t.g),t.b=kt(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===tt&&(t.r=Nt(t.r),t.g=Nt(t.g),t.b=Nt(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?K: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 ht("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(e,n)},toWorkingColorSpace:function(e,n){return ht("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(e,n)}},e=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],i=[.3127,.329];return t.define({[Q]:{primaries:e,whitePoint:i,transfer:K,toXYZ:Bt,fromXYZ:Ct,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:H},outputColorSpaceConfig:{drawingBufferColorSpace:H}},[H]:{primaries:e,whitePoint:i,transfer:tt,toXYZ:Bt,fromXYZ:Ct,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:H}}}),t}const Et=Pt();function kt(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function Nt(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let It;class Ot{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===It&&(It=it("canvas")),It.width=t.width,It.height=t.height;const e=It.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),n=It}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=it("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*kt(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*kt(e[t]/255)):e[t]=kt(e[t]);return{data:e,width:t.width,height:t.height}}return ot("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Ft=0;class Rt{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Ft++}),this.uuid=ft(),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(Ut(i[e].image)):t.push(Ut(i[e]))}else t=Ut(i);n.url=t}return e||(t.images[this.uuid]=n),n}}function Ut(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Ot.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(ot("Texture: Unable to serialize Texture."),{})}let Vt=0;const Lt=new St;class qt extends lt{constructor(t=qt.DEFAULT_IMAGE,e=qt.DEFAULT_MAPPING,n=1001,i=1001,r=1006,s=1008,o=1023,a=1009,h=qt.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Vt++}),this.uuid=ft(),this.name="",this.source=new Rt(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 vt(0,0),this.repeat=new vt(1,1),this.center=new vt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new _t,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(Lt).x}get height(){return this.source.getSize(Lt).y}get depth(){return this.source.getSize(Lt).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){ot(`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:ot(`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 Y: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 Y: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++}}qt.DEFAULT_IMAGE=null,qt.DEFAULT_MAPPING=300,qt.DEFAULT_ANISOTROPY=1;class Dt{constructor(t=0,e=0,n=0,i=1){Dt.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=yt(this.x,t.x,e.x),this.y=yt(this.y,t.y,e.y),this.z=yt(this.z,t.z,e.z),this.w=yt(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=yt(this.x,t,e),this.y=yt(this.y,t,e),this.z=yt(this.z,t,e),this.w=yt(this.w,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(yt(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 Xt{constructor(t,e,n,i,r,s,o,a,h,l,u,c,d,p,f,y){Xt.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 Xt).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/Zt.setFromMatrixColumn(t,0).length(),r=1/Zt.setFromMatrixColumn(t,1).length(),s=1/Zt.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(Gt,t,Jt)}lookAt(t,e,n){const i=this.elements;return Yt.subVectors(t,e),0===Yt.lengthSq()&&(Yt.z=1),Yt.normalize(),Wt.crossVectors(n,Yt),0===Wt.lengthSq()&&(1===Math.abs(n.z)?Yt.x+=1e-4:Yt.z+=1e-4,Yt.normalize(),Wt.crossVectors(n,Yt)),Wt.normalize(),$t.crossVectors(Yt,Wt),i[0]=Wt.x,i[4]=$t.x,i[8]=Yt.x,i[1]=Wt.y,i[5]=$t.y,i[9]=Yt.y,i[2]=Wt.z,i[6]=$t.z,i[10]=Yt.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],C=i[2],P=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*C+h*N,r[4]=s*M+o*_+a*P+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*C+d*N,r[5]=l*M+u*_+c*P+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*C+m*N,r[6]=p*M+f*_+y*P+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*C+w*N,r[7]=g*M+x*_+b*P+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=e*o-n*s,x=e*a-i*s,b=e*h-r*s,w=n*a-i*o,v=n*h-r*o,M=i*h-r*a,S=l*f-u*p,A=l*y-c*p,z=l*m-d*p,_=u*y-c*f,T=u*m-d*f,B=c*m-d*y,C=g*B-x*T+b*_+w*z-v*A+M*S;if(0===C)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const P=1/C;return t[0]=(o*B-a*T+h*_)*P,t[1]=(i*T-n*B-r*_)*P,t[2]=(f*M-y*v+m*w)*P,t[3]=(c*v-u*M-d*w)*P,t[4]=(a*z-s*B-h*A)*P,t[5]=(e*B-i*z+r*A)*P,t[6]=(y*b-p*M-m*x)*P,t[7]=(l*M-c*b+d*x)*P,t[8]=(s*T-o*z+h*S)*P,t[9]=(n*z-e*T-r*S)*P,t[10]=(p*v-f*b+m*g)*P,t[11]=(u*b-l*v-d*g)*P,t[12]=(o*A-s*_-a*S)*P,t[13]=(e*_-n*A+i*S)*P,t[14]=(f*x-p*w-y*g)*P,t[15]=(l*w-u*x+c*g)*P,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;t.x=i[12],t.y=i[13],t.z=i[14];const r=this.determinant();if(0===r)return n.set(1,1,1),e.identity(),this;let s=Zt.set(i[0],i[1],i[2]).length();const o=Zt.set(i[4],i[5],i[6]).length(),a=Zt.set(i[8],i[9],i[10]).length();r<0&&(s=-s),jt.copy(this);const h=1/s,l=1/o,u=1/a;return jt.elements[0]*=h,jt.elements[1]*=h,jt.elements[2]*=h,jt.elements[4]*=l,jt.elements[5]*=l,jt.elements[6]*=l,jt.elements[8]*=u,jt.elements[9]*=u,jt.elements[10]*=u,e.setFromRotationMatrix(jt),n.x=s,n.y=o,n.z=a,this}makePerspective(t,e,n,i,r,s,o=2e3,a=!1){const h=this.elements,l=2*r/(e-t),u=2*r/(n-i),c=(e+t)/(e-t),d=(n+i)/(n-i);let p,f;if(a)p=r/(s-r),f=s*r/(s-r);else if(o===nt)p=-(s+r)/(s-r),f=-2*s*r/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);p=-s/(s-r),f=-s*r/(s-r)}return h[0]=l,h[4]=0,h[8]=c,h[12]=0,h[1]=0,h[5]=u,h[9]=d,h[13]=0,h[2]=0,h[6]=0,h[10]=p,h[14]=f,h[3]=0,h[7]=0,h[11]=-1,h[15]=0,this}makeOrthographic(t,e,n,i,r,s,o=2e3,a=!1){const h=this.elements,l=2/(e-t),u=2/(n-i),c=-(e+t)/(e-t),d=-(n+i)/(n-i);let p,f;if(a)p=1/(s-r),f=s/(s-r);else if(o===nt)p=-2/(s-r),f=-(s+r)/(s-r);else{if(2001!==o)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=-1/(s-r),f=-r/(s-r)}return h[0]=l,h[4]=0,h[8]=0,h[12]=c,h[1]=0,h[5]=u,h[9]=0,h[13]=d,h[2]=0,h[6]=0,h[10]=p,h[14]=f,h[3]=0,h[7]=0,h[11]=0,h[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 Zt=new St,jt=new Xt,Gt=new St(0,0,0),Jt=new St(1,1,1),Wt=new St,$t=new St,Yt=new St,Ht=new Xt,Qt=new Mt;class Kt{constructor(t=0,e=0,n=0,i=Kt.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(yt(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(-yt(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(yt(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(-yt(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(yt(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(-yt(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:ot("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return Ht.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Ht,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Qt.setFromEuler(this),this.setFromQuaternion(Qt,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}}Kt.DEFAULT_ORDER="XYZ";class te{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 ee=0;const ne=new St,ie=new Mt,re=new Xt,se=new St,oe=new St,ae=new St,he=new Mt,le=new St(1,0,0),ue=new St(0,1,0),ce=new St(0,0,1),de={type:"added"},pe={type:"removed"},fe={type:"childadded",child:null},ye={type:"childremoved",child:null};class me extends lt{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:ee++}),this.uuid=ft(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=me.DEFAULT_UP.clone();const t=new St,e=new Kt,n=new Mt,i=new St(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 Xt},normalMatrix:{value:new _t}}),this.matrix=new Xt,this.matrixWorld=new Xt,this.matrixAutoUpdate=me.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=me.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new te,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.static=!1,this.userData={},this.pivot=null}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 ie.setFromAxisAngle(t,e),this.quaternion.multiply(ie),this}rotateOnWorldAxis(t,e){return ie.setFromAxisAngle(t,e),this.quaternion.premultiply(ie),this}rotateX(t){return this.rotateOnAxis(le,t)}rotateY(t){return this.rotateOnAxis(ue,t)}rotateZ(t){return this.rotateOnAxis(ce,t)}translateOnAxis(t,e){return ne.copy(t).applyQuaternion(this.quaternion),this.position.add(ne.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(le,t)}translateY(t){return this.translateOnAxis(ue,t)}translateZ(t){return this.translateOnAxis(ce,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(re.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?se.copy(t):se.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),oe.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?re.lookAt(oe,se,this.up):re.lookAt(se,oe,this.up),this.quaternion.setFromRotationMatrix(re),i&&(re.extractRotation(i.matrixWorld),ie.setFromRotationMatrix(re),this.quaternion.premultiply(ie.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(at("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(de),fe.child=t,this.dispatchEvent(fe),fe.child=null):at("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(pe),ye.child=t,this.dispatchEvent(ye),ye.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),re.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),re.multiply(t.parent.matrixWorld)),t.applyMatrix4(re),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(de),fe.child=t,this.dispatchEvent(fe),fe.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(oe,t,ae),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(oe,he,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);const t=this.pivot;if(null!==t){const e=t.x,n=t.y,i=t.z,r=this.matrix.elements;r[12]+=e-r[0]*e-r[4]*n-r[8]*i,r[13]+=n-r[1]*e-r[5]*n-r[9]*i,r[14]+=i-r[2]*e-r[6]*n-r[10]*i}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),!1!==this.static&&(i.static=this.static),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(),null!==this.pivot&&(i.pivot=this.pivot.toArray()),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),void 0!==this.morphTargetDictionary&&(i.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),void 0!==this.morphTargetInfluences&&(i.morphTargetInfluences=this.morphTargetInfluences.slice()),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),null!==t.pivot&&(this.pivot=t.pivot.clone()),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.static=t.static,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}}me.DEFAULT_UP=new St(0,1,0),me.DEFAULT_MATRIX_AUTO_UPDATE=!0,me.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ge={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},xe={h:0,s:0,l:0},be={h:0,s:0,l:0};function we(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 ve=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=H){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,Et.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=Et.workingColorSpace){return this.r=t,this.g=e,this.b=n,Et.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=Et.workingColorSpace){if(t=mt(t,1),e=yt(e,0,1),n=yt(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=we(r,i,t+1/3),this.g=we(r,i,t),this.b=we(r,i,t-1/3)}return Et.colorSpaceToWorking(this,i),this}setStyle(t,e=H){function n(e){void 0!==e&&parseFloat(e)<1&&ot("Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\\w+)\\(([^\\)]*)\\)/.exec(t)){let r;const s=i[1],o=i[2];switch(s){case"rgb":case"rgba":if(r=/^\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\\s*(\\d*\\.?\\d+)\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec(o))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:ot("Color: Unknown color model "+t)}}else if(i=/^\\#([A-Fa-f\\d]+)$/.exec(t)){const n=i[1],r=n.length;if(3===r)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(n,16),e);ot("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=H){const n=ge[t.toLowerCase()];return void 0!==n?this.setHex(n,e):ot("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=kt(t.r),this.g=kt(t.g),this.b=kt(t.b),this}copyLinearToSRGB(t){return this.r=Nt(t.r),this.g=Nt(t.g),this.b=Nt(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=H){return Et.workingToColorSpace(Me.copy(this),t),65536*Math.round(yt(255*Me.r,0,255))+256*Math.round(yt(255*Me.g,0,255))+Math.round(yt(255*Me.b,0,255))}getHexString(t=H){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Et.workingColorSpace){Et.workingToColorSpace(Me.copy(this),e);const n=Me.r,i=Me.g,r=Me.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=Et.workingColorSpace){return Et.workingToColorSpace(Me.copy(this),e),t.r=Me.r,t.g=Me.g,t.b=Me.b,t}getStyle(t=H){Et.workingToColorSpace(Me.copy(this),t);const e=Me.r,n=Me.g,i=Me.b;return t!==H?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*n)},${Math.round(255*i)})`}offsetHSL(t,e,n){return this.getHSL(xe),this.setHSL(xe.h+t,xe.s+e,xe.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(xe),t.getHSL(be);const n=gt(xe.h,be.h,e),i=gt(xe.s,be.s,e),r=gt(xe.l,be.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 Me=new ve;ve.NAMES=ge;const Se=new St,Ae=new St,ze=new St,_e=new St,Te=new St,Be=new St,Ce=new St,Pe=new St,Ee=new St,ke=new St,Ne=new Dt,Ie=new Dt,Oe=new Dt;class Fe{constructor(t=new St,e=new St,n=new St){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),Se.subVectors(t,e),i.cross(Se);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){Se.subVectors(i,e),Ae.subVectors(n,e),ze.subVectors(t,e);const s=Se.dot(Se),o=Se.dot(Ae),a=Se.dot(ze),h=Ae.dot(Ae),l=Ae.dot(ze),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,_e)&&(_e.x>=0&&_e.y>=0&&_e.x+_e.y<=1)}static getInterpolation(t,e,n,i,r,s,o,a){return null===this.getBarycoord(t,e,n,i,_e)?(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,_e.x),a.addScaledVector(s,_e.y),a.addScaledVector(o,_e.z),a)}static getInterpolatedAttribute(t,e,n,i,r,s){return Ne.setScalar(0),Ie.setScalar(0),Oe.setScalar(0),Ne.fromBufferAttribute(t,e),Ie.fromBufferAttribute(t,n),Oe.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(Ne,r.x),s.addScaledVector(Ie,r.y),s.addScaledVector(Oe,r.z),s}static isFrontFacing(t,e,n,i){return Se.subVectors(n,e),Ae.subVectors(t,e),Se.cross(Ae).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 Se.subVectors(this.c,this.b),Ae.subVectors(this.a,this.b),.5*Se.cross(Ae).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Fe.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Fe.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return Fe.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return Fe.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Fe.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;Te.subVectors(i,n),Be.subVectors(r,n),Pe.subVectors(t,n);const a=Te.dot(Pe),h=Be.dot(Pe);if(a<=0&&h<=0)return e.copy(n);Ee.subVectors(t,i);const l=Te.dot(Ee),u=Be.dot(Ee);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(Te,s);ke.subVectors(t,r);const d=Te.dot(ke),p=Be.dot(ke);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(Be,o);const y=l*p-d*u;if(y<=0&&u-l>=0&&d-p>=0)return Ce.subVectors(r,i),o=(u-l)/(u-l+(d-p)),e.copy(i).addScaledVector(Ce,o);const m=1/(y+f+c);return s=f*m,o=c*m,e.copy(n).addScaledVector(Te,s).addScaledVector(Be,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Re{constructor(t=new St(1/0,1/0,1/0),e=new St(-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(Ve.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(Ve.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=Ve.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,Ve):Ve.fromBufferAttribute(i,e),Ve.applyMatrix4(t.matrixWorld),this.expandByPoint(Ve);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),Le.copy(n.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}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,Ve),Ve.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(Je),We.subVectors(this.max,Je),qe.subVectors(t.a,Je),De.subVectors(t.b,Je),Xe.subVectors(t.c,Je),Ze.subVectors(De,qe),je.subVectors(Xe,De),Ge.subVectors(qe,Xe);let e=[0,-Ze.z,Ze.y,0,-je.z,je.y,0,-Ge.z,Ge.y,Ze.z,0,-Ze.x,je.z,0,-je.x,Ge.z,0,-Ge.x,-Ze.y,Ze.x,0,-je.y,je.x,0,-Ge.y,Ge.x,0];return!!He(e,qe,De,Xe,We)&&(e=[1,0,0,0,1,0,0,0,1],!!He(e,qe,De,Xe,We)&&($e.crossVectors(Ze,je),e=[$e.x,$e.y,$e.z],He(e,qe,De,Xe,We)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ve).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Ve).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()||(Ue[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ue[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ue[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ue[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ue[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ue[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ue[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ue[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ue)),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 Ue=[new St,new St,new St,new St,new St,new St,new St,new St],Ve=new St,Le=new Re,qe=new St,De=new St,Xe=new St,Ze=new St,je=new St,Ge=new St,Je=new St,We=new St,$e=new St,Ye=new St;function He(t,e,n,i,r){for(let s=0,o=t.length-3;s<=o;s+=3){Ye.fromArray(t,s);const o=r.x*Math.abs(Ye.x)+r.y*Math.abs(Ye.y)+r.z*Math.abs(Ye.z),a=e.dot(Ye),h=n.dot(Ye),l=i.dot(Ye);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const Qe=new St,Ke=new vt;let tn=0;class en{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:tn++}),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++)Ke.fromBufferAttribute(this,e),Ke.applyMatrix3(t),this.setXY(e,Ke.x,Ke.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyMatrix3(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyMatrix4(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.applyNormalMatrix(t),this.setXYZ(e,Qe.x,Qe.y,Qe.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)Qe.fromBufferAttribute(this,e),Qe.transformDirection(t),this.setXYZ(e,Qe.x,Qe.y,Qe.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=xt(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=bt(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=xt(e,this.array)),e}setX(t,e){return this.normalized&&(e=bt(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=xt(e,this.array)),e}setY(t,e){return this.normalized&&(e=bt(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=xt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=bt(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=xt(e,this.array)),e}setW(t,e){return this.normalized&&(e=bt(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=bt(e,this.array),n=bt(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=bt(e,this.array),n=bt(n,this.array),i=bt(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=bt(e,this.array),n=bt(n,this.array),i=bt(i,this.array),r=bt(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 nn extends en{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class rn extends en{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class sn extends en{constructor(t,e,n){super(new Float32Array(t),e,n)}}const on=new Re,an=new St,hn=new St;class ln{constructor(t=new St,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):on.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;an.subVectors(t,this.center);const e=an.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(an,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):(hn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(an.copy(t.center).add(hn)),this.expandByPoint(an.copy(t.center).sub(hn))),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}}let un=0;const cn=new Xt,dn=new me,pn=new St,fn=new Re,yn=new Re,mn=new St;class gn extends lt{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:un++}),this.uuid=ft(),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)?rn:nn)(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 _t).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 cn.makeRotationFromQuaternion(t),this.applyMatrix4(cn),this}rotateX(t){return cn.makeRotationX(t),this.applyMatrix4(cn),this}rotateY(t){return cn.makeRotationY(t),this.applyMatrix4(cn),this}rotateZ(t){return cn.makeRotationZ(t),this.applyMatrix4(cn),this}translate(t,e,n){return cn.makeTranslation(t,e,n),this.applyMatrix4(cn),this}scale(t,e,n){return cn.makeScale(t,e,n),this.applyMatrix4(cn),this}lookAt(t){return dn.lookAt(t),dn.updateMatrix(),this.applyMatrix4(dn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(pn).negate(),this.translate(pn.x,pn.y,pn.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 sn(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&&ot("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 Re);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return at("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new St(-1/0,-1/0,-1/0),new St(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];fn.setFromBufferAttribute(t),this.morphTargetsRelative?(mn.addVectors(this.boundingBox.min,fn.min),this.boundingBox.expandByPoint(mn),mn.addVectors(this.boundingBox.max,fn.max),this.boundingBox.expandByPoint(mn)):(this.boundingBox.expandByPoint(fn.min),this.boundingBox.expandByPoint(fn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&at(\'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 ln);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return at("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new St,1/0);if(t){const n=this.boundingSphere.center;if(fn.setFromBufferAttribute(t),e)for(let t=0,r=e.length;t<r;t++){const n=e[t];yn.setFromBufferAttribute(n),this.morphTargetsRelative?(mn.addVectors(fn.min,yn.min),fn.expandByPoint(mn),mn.addVectors(fn.max,yn.max),fn.expandByPoint(mn)):(fn.expandByPoint(yn.min),fn.expandByPoint(yn.max))}fn.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)mn.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(mn));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++)mn.fromBufferAttribute(s,e),o&&(pn.fromBufferAttribute(t,e),mn.add(pn)),i=Math.max(i,n.distanceToSquared(mn))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&at(\'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 at("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 en(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),o=[],a=[];for(let S=0;S<n.count;S++)o[S]=new St,a[S]=new St;const h=new St,l=new St,u=new St,c=new vt,d=new vt,p=new vt,f=new St,y=new St;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 g=this.groups;0===g.length&&(g=[{start:0,count:t.count}]);for(let S=0,A=g.length;S<A;++S){const e=g[S],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 x=new St,b=new St,w=new St,v=new St;function M(t){w.fromBufferAttribute(i,t),v.copy(w);const e=o[t];x.copy(e),x.sub(w.multiplyScalar(w.dot(e))).normalize(),b.crossVectors(v,e);const n=b.dot(a[t])<0?-1:1;s.setXYZW(t,x.x,x.y,x.z,n)}for(let S=0,A=g.length;S<A;++S){const e=g[S],n=e.start;for(let i=n,r=n+e.count;i<r;i+=3)M(t.getX(i+0)),M(t.getX(i+1)),M(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 en(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 St,r=new St,s=new St,o=new St,a=new St,h=new St,l=new St,u=new St;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++)mn.fromBufferAttribute(t,e),mn.normalize(),t.setXYZ(e,mn.x,mn.y,mn.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 en(s,i,r)}if(null===this.index)return ot("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new gn,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"})}}let xn=0;class bn extends lt{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:xn++}),this.uuid=ft(),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 ve(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=et,this.stencilZFail=et,this.stencilZPass=et,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){ot(`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:ot(`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!==et&&(n.stencilFail=this.stencilFail),this.stencilZFail!==et&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==et&&(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++}}const wn=new St,vn=new St,Mn=new St,Sn=new St,An=new St,zn=new St,_n=new St;class Tn{constructor(t=new St,e=new St(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,wn)),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=wn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(wn.copy(this.origin).addScaledVector(this.direction,e),wn.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){vn.copy(t).add(e).multiplyScalar(.5),Mn.copy(e).sub(t).normalize(),Sn.copy(this.origin).sub(vn);const r=.5*t.distanceTo(e),s=-this.direction.dot(Mn),o=Sn.dot(this.direction),a=-Sn.dot(Mn),h=Sn.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(vn).addScaledVector(Mn,c),d}intersectSphere(t,e){wn.subVectors(t.center,this.origin);const n=wn.dot(this.direction),i=wn.dot(wn)-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,wn)}intersectTriangle(t,e,n,i,r){An.subVectors(e,t),zn.subVectors(n,t),_n.crossVectors(An,zn);let s,o=this.direction.dot(_n);if(o>0){if(i)return null;s=1}else{if(!(o<0))return null;s=-1,o=-o}Sn.subVectors(this.origin,t);const a=s*this.direction.dot(zn.crossVectors(Sn,zn));if(a<0)return null;const h=s*this.direction.dot(An.cross(Sn));if(h<0)return null;if(a+h>o)return null;const l=-s*Sn.dot(_n);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 Bn extends bn{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new ve(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 Kt,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 Cn=new Xt,Pn=new Tn,En=new ln,kn=new St,Nn=new St,In=new St,On=new St,Fn=new St,Rn=new St,Un=new St,Vn=new St;class Ln extends me{constructor(t=new gn,e=new Bn){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){Rn.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=o[n],a=r[n];0!==i&&(Fn.fromBufferAttribute(a,t),s?Rn.addScaledVector(Fn,i):Rn.addScaledVector(Fn.sub(e),i))}e.add(Rn)}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(),En.copy(n.boundingSphere),En.applyMatrix4(r),Pn.copy(t.ray).recast(t.near),!1===En.containsPoint(Pn.origin)){if(null===Pn.intersectSphere(En,kn))return;if(Pn.origin.distanceToSquared(kn)>h(t.far-t.near,2))return}Cn.copy(r).invert(),Pn.copy(t.ray).applyMatrix4(Cn),null!==n.boundingBox&&!1===Pn.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Pn)}}_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=qn(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=qn(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=qn(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=qn(this,s,t,n,h,l,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function qn(t,e,n,i,r,s,o,a,h,l){t.getVertexPosition(a,Nn),t.getVertexPosition(h,In),t.getVertexPosition(l,On);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;Vn.copy(a),Vn.applyMatrix4(t.matrixWorld);const l=n.ray.origin.distanceTo(Vn);return l<n.near||l>n.far?null:{distance:l,point:Vn.clone(),object:t}}(t,e,n,i,Nn,In,On,Un);if(u){const t=new St;Fe.getBarycoord(Un,Nn,In,On,t),r&&(u.uv=Fe.getInterpolatedAttribute(r,a,h,l,t,new vt)),s&&(u.uv1=Fe.getInterpolatedAttribute(s,a,h,l,t,new vt)),o&&(u.normal=Fe.getInterpolatedAttribute(o,a,h,l,t,new St),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new St,materialIndex:0};Fe.getNormal(Nn,In,On,e.normal),u.face=e,u.barycoord=t}return u}const Dn=new St,Xn=new St,Zn=new _t;class jn{constructor(t=new St(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=Dn.subVectors(n,e).cross(Xn.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(Dn),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||Zn.getNormalMatrix(t),i=this.coplanarPoint(Dn).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 Gn{constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPoint(){ot("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 vt:new St);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 St,i=[],r=[],s=[],o=new St,a=new Xt;for(let d=0;d<=t;d++){const e=d/t;i[d]=this.getTangentAt(e,new St)}r[0]=new St,s[0]=new St;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(yt(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(yt(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 Jn extends Gn{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 vt){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 Wn extends Jn{constructor(t,e,n,i,r,s){super(t,e,n,n,i,r,s),this.isArcCurve=!0,this.type="ArcCurve"}}function $n(){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 Yn=new St,Hn=new $n,Qn=new $n,Kn=new $n;class ti extends Gn{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 St){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]:(Yn.subVectors(i[0],i[1]).add(i[0]),o=Yn);const u=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(Yn.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=Yn),"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),Hn.initNonuniformCatmullRom(o.x,u.x,c.x,a.x,e,n,i),Qn.initNonuniformCatmullRom(o.y,u.y,c.y,a.y,e,n,i),Kn.initNonuniformCatmullRom(o.z,u.z,c.z,a.z,e,n,i)}else"catmullrom"===this.curveType&&(Hn.initCatmullRom(o.x,u.x,c.x,a.x,this.tension),Qn.initCatmullRom(o.y,u.y,c.y,a.y,this.tension),Kn.initCatmullRom(o.z,u.z,c.z,a.z,this.tension));return n.set(Hn.calc(l),Qn.calc(l),Kn.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 St).fromArray(n))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function ei(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 ni(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 ii(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 ri extends Gn{constructor(t=new vt,e=new vt,n=new vt,i=new vt){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new vt){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(ii(t,i.x,r.x,s.x,o.x),ii(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 si extends Gn{constructor(t=new St,e=new St,n=new St,i=new St){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new St){const n=e,i=this.v0,r=this.v1,s=this.v2,o=this.v3;return n.set(ii(t,i.x,r.x,s.x,o.x),ii(t,i.y,r.y,s.y,o.y),ii(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 oi extends Gn{constructor(t=new vt,e=new vt){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new vt){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 vt){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 ai extends Gn{constructor(t=new St,e=new St){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new St){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 St){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 hi extends Gn{constructor(t=new vt,e=new vt,n=new vt){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new vt){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(ni(t,i.x,r.x,s.x),ni(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 li extends Gn{constructor(t=new St,e=new St,n=new St){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new St){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(ni(t,i.x,r.x,s.x),ni(t,i.y,r.y,s.y),ni(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 ui extends Gn{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new vt){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(ei(o,a.x,h.x,l.x,u.x),ei(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 vt).fromArray(n))}return this}}var ci=Object.freeze({__proto__:null,ArcCurve:Wn,CatmullRomCurve3:ti,CubicBezierCurve:ri,CubicBezierCurve3:si,EllipseCurve:Jn,LineCurve:oi,LineCurve3:ai,QuadraticBezierCurve:hi,QuadraticBezierCurve3:li,SplineCurve:ui});class di extends Gn{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 ci[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 ci[n.type]).fromJSON(n))}return this}}let pi=class extends di{constructor(t){super(),this.type="Path",this.currentPoint=new vt,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 oi(this.currentPoint.clone(),new vt(t,e));return this.curves.push(n),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,n,i){const r=new hi(this.currentPoint.clone(),new vt(t,e),new vt(n,i));return this.curves.push(r),this.currentPoint.set(n,i),this}bezierCurveTo(t,e,n,i,r,s){const o=new ri(this.currentPoint.clone(),new vt(t,e),new vt(n,i),new vt(r,s));return this.curves.push(o),this.currentPoint.set(r,s),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),n=new ui(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 Jn(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 fi extends pi{constructor(t){super(t),this.uuid=ft(),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 pi).fromJSON(n))}return this}}function yi(t,e,n=2){const i=e&&e.length,r=i?e[0]*n:t.length;let s=mi(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=mi(t,e[s]*i,s<o-1?e[s+1]*i:t.length,i,!1);n===n.next&&(n.steiner=!0),r.push(Ti(n))}r.sort(Si);for(let s=0;s<r.length;s++)n=Ai(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 xi(s,o,n,a,h,l,0),o}function mi(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=Ui(o/i|0,t[o],t[o+1],s);else for(let o=n-i;o>=e;o-=i)s=Ui(o/i|0,t[o],t[o+1],s);return s&&ki(s,s.next)&&(Vi(s),s=s.next),s}function gi(t,e){if(!t)return t;e||(e=t);let n,i=t;do{if(n=!1,i.steiner||!ki(i,i.next)&&0!==Ei(i.prev,i,i.next))i=i.next;else{if(Vi(i),i=e=i.prev,i===i.next)break;n=!0}}while(n||i!==e);return e}function xi(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=_i(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?wi(t,i,r,s):bi(t))e.push(h.i,t.i,l.i),Vi(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?xi(t=vi(gi(t),e),e,n,i,r,s,2):2===o&&Mi(t,e,n,i,r,s):xi(gi(t),e,n,i,r,s,1);break}}}function bi(t){const e=t.prev,n=t,i=t.next;if(Ei(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&&Ci(r,a,s,h,o,l,f.x,f.y)&&Ei(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function wi(t,e,n,i){const r=t.prev,s=t,o=t.next;if(Ei(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=_i(p,f,e,n,i),x=_i(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&&Ci(a,u,h,c,l,d,b.x,b.y)&&Ei(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&&Ci(a,u,h,c,l,d,w.x,w.y)&&Ei(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&&Ci(a,u,h,c,l,d,b.x,b.y)&&Ei(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&&Ci(a,u,h,c,l,d,w.x,w.y)&&Ei(w.prev,w,w.next)>=0)return!1;w=w.nextZ}return!0}function vi(t,e){let n=t;do{const i=n.prev,r=n.next.next;!ki(i,r)&&Ni(i,n,n.next,r)&&Fi(i,r)&&Fi(r,i)&&(e.push(i.i,n.i,r.i),Vi(n),Vi(n.next),n=t=r),n=n.next}while(n!==t);return gi(n)}function Mi(t,e,n,i,r,s){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Pi(o,t)){let a=Ri(o,t);return o=gi(o,o.next),a=gi(a,a.next),xi(o,e,n,i,r,s,0),void xi(a,e,n,i,r,s,0)}t=t.next}o=o.next}while(o!==t)}function Si(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 Ai(t,e){const n=function(t,e){let n=e;const i=t.x,r=t.y;let s,o=-1/0;if(ki(t,n))return n;do{if(ki(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&&Bi(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);Fi(n,t)&&(e<u||e===u&&(n.x>s.x||n.x===s.x&&zi(s,n)))&&(s=n,u=e)}n=n.next}while(n!==a);return s}(t,e);if(!n)return e;const i=Ri(n,t);return gi(i,i.next),gi(n,n.next)}function zi(t,e){return Ei(t.prev,t,e.prev)<0&&Ei(e.next,t,t.next)<0}function _i(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 Ti(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 Bi(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 Ci(t,e,n,i,r,s,o,a){return!(t===o&&e===a)&&Bi(t,e,n,i,r,s,o,a)}function Pi(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&&Ni(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Fi(t,e)&&Fi(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)&&(Ei(t.prev,t,e.prev)||Ei(t,e.prev,e))||ki(t,e)&&Ei(t.prev,t,t.next)>0&&Ei(e.prev,e,e.next)>0)}function Ei(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function ki(t,e){return t.x===e.x&&t.y===e.y}function Ni(t,e,n,i){const r=Oi(Ei(t,e,n)),s=Oi(Ei(t,e,i)),o=Oi(Ei(n,i,t)),a=Oi(Ei(n,i,e));return r!==s&&o!==a||(!(0!==r||!Ii(t,n,e))||(!(0!==s||!Ii(t,i,e))||(!(0!==o||!Ii(n,t,i))||!(0!==a||!Ii(n,e,i)))))}function Ii(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 Oi(t){return t>0?1:t<0?-1:0}function Fi(t,e){return Ei(t.prev,t,t.next)<0?Ei(t,e,t.next)>=0&&Ei(t,t.prev,e)>=0:Ei(t,e,t.prev)<0||Ei(t,t.next,e)<0}function Ri(t,e){const n=Li(t.i,t.x,t.y),i=Li(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 Ui(t,e,n,i){const r=Li(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 Vi(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 Li(t,e,n){return{i:t,x:e,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}class qi{static triangulate(t,e,n=2){return yi(t,e,n)}}class Di{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 Di.area(t)<0}static triangulateShape(t,e){const n=[],i=[],r=[];Xi(t),Zi(n,t);let s=t.length;e.forEach(Xi);for(let a=0;a<e.length;a++)i.push(s),s+=e[a].length,Zi(n,e[a]);const o=qi.triangulate(n,i);for(let a=0;a<o.length;a+=3)r.push(o.slice(a,a+3));return r}}function Xi(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function Zi(t,e){for(let n=0;n<e.length;n++)t.push(e[n].x),t.push(e[n].y)}class ji extends gn{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 sn(p,3)),this.setAttribute("normal",new sn(f,3)),this.setAttribute("uv",new sn(y,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ji(t.width,t.height,t.widthSegments,t.heightSegments)}}const Gi=new St,Ji=new St,Wi=new St,$i=new St,Yi=new St,Hi=new St,Qi=new St;class Ki{constructor(t=new St,e=new St){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){Gi.subVectors(t,this.start),Ji.subVectors(this.end,this.start);const n=Ji.dot(Ji);let i=Ji.dot(Gi)/n;return e&&(i=yt(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=Hi,n=Qi){const i=1e-8*1e-8;let r,s;const o=this.start,a=t.start,h=this.end,l=t.end;Wi.subVectors(h,o),$i.subVectors(l,a),Yi.subVectors(o,a);const u=Wi.dot(Wi),c=$i.dot($i),d=$i.dot(Yi);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=yt(s,0,1);else{const t=Wi.dot(Yi);if(c<=i)s=0,r=yt(-t/u,0,1);else{const e=Wi.dot($i),n=u*c-e*e;r=0!==n?yt((e*d-t*c)/n,0,1):0,s=(e*r+d)/c,s<0?(s=0,r=yt(-t/u,0,1)):s>1&&(s=1,r=yt((e-t)/u,0,1))}}return e.copy(o).addScaledVector(Wi,r),n.copy(a).addScaledVector($i,s),e.distanceToSquared(n)}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:$}})),"undefined"!=typeof window&&(window.__THREE__?ot("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=$);const tr=6378137,er=6356752.314245179;function nr(t,e,n=0,i=1,r=!1){const s=wt.degToRad(t),o=wt.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=n*i;c=t*a*u,d=t*h,p=t*a*l}else{const t=tr*tr,e=(t-er*er)/t,r=tr/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 St(c,d,p)}const ir=134217729;function rr(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 sr(t){return new Float64Array(t)}const or=sr(4),ar=sr(8),hr=sr(12),lr=sr(16),ur=sr(4);function cr(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=ir*z,p=d-(d-z),f=z-p,d=ir*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=T*_,d=ir*T,p=d-(d-T),f=T-p,d=ir*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,or[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,or[1]=b-(g+c)+(c-M),A=x+g,c=A-x,or[2]=x-(A-c)+(g-c),or[3]=A;let C=function(t,e){let n=e[0];for(let i=1;i<t;i++)n+=e[i];return n}(4,or),P=22204460492503146e-32*o;if(C>=P||-C>=P)return C;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 C;if(P=11093356479670487e-47*o+33306690738754706e-32*Math.abs(C),C+=z*u+B*a-(T*l+_*h),C>=P||-C>=P)return C;w=a*B,d=ir*a,p=d-(d-a),f=a-p,d=ir*B,y=d-(d-B),m=B-y,v=f*m-(w-p*y-f*y-p*m),M=h*_,d=ir*h,p=d-(d-h),f=h-p,d=ir*_,y=d-(d-_),m=_-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const E=rr(4,or,4,ur,ar);w=z*u,d=ir*z,p=d-(d-z),f=z-p,d=ir*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=T*l,d=ir*T,p=d-(d-T),f=T-p,d=ir*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const k=rr(E,ar,4,ur,hr);w=a*u,d=ir*a,p=d-(d-a),f=a-p,d=ir*u,y=d-(d-u),m=u-y,v=f*m-(w-p*y-f*y-p*m),M=h*l,d=ir*h,p=d-(d-h),f=h-p,d=ir*l,y=d-(d-l),m=l-y,S=f*m-(M-p*y-f*y-p*m),g=v-S,c=v-g,ur[0]=v-(g+c)+(c-S),x=w+g,c=x-w,b=w-(x-c)+(g-c),g=b-M,c=b-g,ur[1]=b-(g+c)+(c-M),A=x+g,c=A-x,ur[2]=x-(A-c)+(g-c),ur[3]=A;const N=rr(k,hr,4,ur,lr);return lr[N-1]}(t,e,n,i,r,s,l)}const dr=Math.pow(2,-52),pr=new Uint32Array(512);class fr{static from(t,e=wr,n=vr){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 fr(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=yr(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=yr(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=gr(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];xr(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(cr(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]=yr(t[2*A],t[2*A+1],M.x,M.y);xr(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)<=dr&&Math.abs(a-z)<=dr)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],cr(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],cr(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],cr(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=pr[--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(mr(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<pr.length&&(pr[r++]=a)}else{if(0===r)break;t=pr[--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 yr(t,e,n,i){const r=t-n,s=e-i;return r*r+s*s}function mr(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 gr(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 xr(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;br(t,n+i>>1,r),e[t[n]]>e[t[i]]&&br(t,n,i),e[t[r]]>e[t[i]]&&br(t,r,i),e[t[n]]>e[t[r]]&&br(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;br(t,r,s)}t[n+1]=t[s],t[s]=o,i-r+1>=s-n?(xr(t,e,r,i),xr(t,e,n,s-1)):(xr(t,e,n,s-1),xr(t,e,r,i))}}function br(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function wr(t){return t[0]}function vr(t){return t[1]}function Mr(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 Sr=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=Mr(i,h[u]);if(0===t)return!n.ignoreBoundary;t&&(l=!0)}return l},Ar=1e-6,zr=1e-12,_r=Math.PI,Tr=_r/2,Br=_r/4,Cr=2*_r,Pr=180/_r,Er=_r/180,kr=Math.abs,Nr=Math.atan,Ir=Math.atan2,Or=Math.cos,Fr=Math.exp,Rr=Math.hypot,Ur=Math.log,Vr=Math.sin,Lr=Math.sign||function(t){return t>0?1:t<0?-1:0},qr=Math.sqrt,Dr=Math.tan;function Xr(t){return t>1?Tr:t<-1?-Tr:Math.asin(t)}function Zr(t){return(t=Vr(t/2))*t}function jr(){}function Gr(t,e){t&&Wr.hasOwnProperty(t.type)&&Wr[t.type](t,e)}var Jr={Feature:function(t,e){Gr(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)Gr(n[i].geometry,e)}},Wr={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){$r(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)$r(n[i],e,0)},Polygon:function(t,e){Yr(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)Yr(n[i],e)},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)Gr(n[i],e)}};function $r(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 Yr(t,e){var n=-1,i=t.length;for(e.polygonStart();++n<i;)$r(t[n],e,1);e.polygonEnd()}function Hr(t,e){t&&Jr.hasOwnProperty(t.type)?Jr[t.type](t,e):Gr(t,e)}var Qr,Kr,ts,es,ns,is,rs,ss,os,as,hs,ls,us,cs,ds,ps,fs=new l,ys=new l,ms={point:jr,lineStart:jr,lineEnd:jr,polygonStart:function(){fs=new l,ms.lineStart=gs,ms.lineEnd=xs},polygonEnd:function(){var t=+fs;ys.add(t<0?Cr+t:t),this.lineStart=this.lineEnd=this.point=jr},sphere:function(){ys.add(Cr)}};function gs(){ms.point=bs}function xs(){ws(Qr,Kr)}function bs(t,e){ms.point=ws,Qr=t,Kr=e,ts=t*=Er,es=Or(e=(e*=Er)/2+Br),ns=Vr(e)}function ws(t,e){var n=(t*=Er)-ts,i=n>=0?1:-1,r=i*n,s=Or(e=(e*=Er)/2+Br),o=Vr(e),a=ns*o,h=es*s+a*Or(r),l=a*i*Vr(r);fs.add(Ir(l,h)),ts=t,es=s,ns=o}function vs(t){return[Ir(t[1],t[0]),Xr(t[2])]}function Ms(t){var e=t[0],n=t[1],i=Or(n);return[i*Or(e),i*Vr(e),Vr(n)]}function Ss(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function As(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 zs(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function _s(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Ts(t){var e=qr(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var Bs,Cs,Ps,Es,ks,Ns,Is,Os,Fs,Rs,Us,Vs,Ls,qs,Ds,Xs,Zs={point:js,lineStart:Js,lineEnd:Ws,polygonStart:function(){Zs.point=$s,Zs.lineStart=Ys,Zs.lineEnd=Hs,cs=new l,ms.polygonStart()},polygonEnd:function(){ms.polygonEnd(),Zs.point=js,Zs.lineStart=Js,Zs.lineEnd=Ws,fs<0?(is=-(ss=180),rs=-(os=90)):cs>Ar?os=90:cs<-1e-6&&(rs=-90),ps[0]=is,ps[1]=ss},sphere:function(){is=-(ss=180),rs=-(os=90)}};function js(t,e){ds.push(ps=[is=t,ss=t]),e<rs&&(rs=e),e>os&&(os=e)}function Gs(t,e){var n=Ms([t*Er,e*Er]);if(us){var i=As(us,n),r=As([i[1],-i[0],0],i);Ts(r),r=vs(r);var s,o=t-as,a=o>0?1:-1,h=r[0]*Pr*a,l=kr(o)>180;l^(a*as<h&&h<a*t)?(s=r[1]*Pr)>os&&(os=s):l^(a*as<(h=(h+360)%360-180)&&h<a*t)?(s=-r[1]*Pr)<rs&&(rs=s):(e<rs&&(rs=e),e>os&&(os=e)),l?t<as?Qs(is,t)>Qs(is,ss)&&(ss=t):Qs(t,ss)>Qs(is,ss)&&(is=t):ss>=is?(t<is&&(is=t),t>ss&&(ss=t)):t>as?Qs(is,t)>Qs(is,ss)&&(ss=t):Qs(t,ss)>Qs(is,ss)&&(is=t)}else ds.push(ps=[is=t,ss=t]);e<rs&&(rs=e),e>os&&(os=e),us=n,as=t}function Js(){Zs.point=Gs}function Ws(){ps[0]=is,ps[1]=ss,Zs.point=js,us=null}function $s(t,e){if(us){var n=t-as;cs.add(kr(n)>180?n+(n>0?360:-360):n)}else hs=t,ls=e;ms.point(t,e),Gs(t,e)}function Ys(){ms.lineStart()}function Hs(){$s(hs,ls),ms.lineEnd(),kr(cs)>Ar&&(is=-(ss=180)),ps[0]=is,ps[1]=ss,us=null}function Qs(t,e){return(e-=t)<0?e+360:e}function Ks(t,e){return t[0]-e[0]}function to(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}function eo(t){var e,n,i,r,s,o,a;if(os=ss=-(is=rs=1/0),ds=[],Hr(t,Zs),n=ds.length){for(ds.sort(Ks),e=1,s=[i=ds[0]];e<n;++e)to(i,(r=ds[e])[0])||to(i,r[1])?(Qs(i[0],r[1])>Qs(i[0],i[1])&&(i[1]=r[1]),Qs(r[0],i[1])>Qs(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=Qs(i[1],r[0]))>o&&(o=a,is=r[0],ss=i[1])}return ds=ps=null,is===1/0||rs===1/0?[[NaN,NaN],[NaN,NaN]]:[[is,rs],[ss,os]]}var no={sphere:jr,point:io,lineStart:so,lineEnd:ho,polygonStart:function(){no.lineStart=lo,no.lineEnd=uo},polygonEnd:function(){no.lineStart=so,no.lineEnd=ho}};function io(t,e){t*=Er;var n=Or(e*=Er);ro(n*Or(t),n*Vr(t),Vr(e))}function ro(t,e,n){++Bs,Ps+=(t-Ps)/Bs,Es+=(e-Es)/Bs,ks+=(n-ks)/Bs}function so(){no.point=oo}function oo(t,e){t*=Er;var n=Or(e*=Er);qs=n*Or(t),Ds=n*Vr(t),Xs=Vr(e),no.point=ao,ro(qs,Ds,Xs)}function ao(t,e){t*=Er;var n=Or(e*=Er),i=n*Or(t),r=n*Vr(t),s=Vr(e),o=Ir(qr((o=Ds*s-Xs*r)*o+(o=Xs*i-qs*s)*o+(o=qs*r-Ds*i)*o),qs*i+Ds*r+Xs*s);Cs+=o,Ns+=o*(qs+(qs=i)),Is+=o*(Ds+(Ds=r)),Os+=o*(Xs+(Xs=s)),ro(qs,Ds,Xs)}function ho(){no.point=io}function lo(){no.point=co}function uo(){po(Vs,Ls),no.point=io}function co(t,e){Vs=t,Ls=e,t*=Er,e*=Er,no.point=po;var n=Or(e);qs=n*Or(t),Ds=n*Vr(t),Xs=Vr(e),ro(qs,Ds,Xs)}function po(t,e){t*=Er;var n=Or(e*=Er),i=n*Or(t),r=n*Vr(t),s=Vr(e),o=Ds*s-Xs*r,a=Xs*i-qs*s,h=qs*r-Ds*i,l=Rr(o,a,h),u=Xr(l),c=l&&-u/l;Fs.add(c*o),Rs.add(c*a),Us.add(c*h),Cs+=u,Ns+=u*(qs+(qs=i)),Is+=u*(Ds+(Ds=r)),Os+=u*(Xs+(Xs=s)),ro(qs,Ds,Xs)}function fo(t){Bs=Cs=Ps=Es=ks=Ns=Is=Os=0,Fs=new l,Rs=new l,Us=new l,Hr(t,no);var e=+Fs,n=+Rs,i=+Us,r=Rr(e,n,i);return r<zr&&(e=Ns,n=Is,i=Os,Cs<Ar&&(e=Ps,n=Es,i=ks),(r=Rr(e,n,i))<zr)?[NaN,NaN]:[Ir(n,e)*Pr,Xr(i/r)*Pr]}function yo(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 mo(t,e){return kr(t)>_r&&(t-=Math.round(t/Cr)*Cr),[t,e]}function go(t,e,n){return(t%=Cr)?e||n?yo(bo(t),wo(e,n)):bo(t):e||n?wo(e,n):mo}function xo(t){return function(e,n){return kr(e+=t)>_r&&(e-=Math.round(e/Cr)*Cr),[e,n]}}function bo(t){var e=xo(t);return e.invert=xo(-t),e}function wo(t,e){var n=Or(t),i=Vr(t),r=Or(e),s=Vr(e);function o(t,e){var o=Or(e),a=Or(t)*o,h=Vr(t)*o,l=Vr(e),u=l*n+a*i;return[Ir(h*r-u*s,a*n-l*i),Xr(u*r+h*s)]}return o.invert=function(t,e){var o=Or(e),a=Or(t)*o,h=Vr(t)*o,l=Vr(e),u=l*r-h*s;return[Ir(h*r+l*s,a*n+u*i),Xr(u*n-a*i)]},o}function vo(t){function e(e){return(e=t(e[0]*Er,e[1]*Er))[0]*=Pr,e[1]*=Pr,e}return t=go(t[0]*Er,t[1]*Er,t.length>2?t[2]*Er:0),e.invert=function(e){return(e=t.invert(e[0]*Er,e[1]*Er))[0]*=Pr,e[1]*=Pr,e},e}function Mo(t,e){(e=Ms(e))[0]-=t,Ts(e);var n,i=(n=-e[1])>1?0:n<-1?_r:Math.acos(n);return((-e[2]<0?-i:i)+Cr-Ar)%Cr}function So(){var t,e=[];return{point:function(e,n,i){t.push([e,n,i])},lineStart:function(){e.push(t=[])},lineEnd:jr,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function Ao(t,e){return kr(t[0]-e[0])<Ar&&kr(t[1]-e[1])<Ar}function zo(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 _o(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(Ao(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 zo(i,t,null,!0)),h.push(n.o=new zo(i,null,n,!1)),a.push(n=new zo(o,t,null,!1)),h.push(n.o=new zo(o,null,n,!0))}}),a.length){for(h.sort(e),To(a),To(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 To(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 Bo(t){return kr(t[0])<=_r?t[0]:Lr(t[0])*((kr(t[0])+_r)%Cr-_r)}function Co(t,e){var n=Bo(e),i=e[1],r=Vr(i),s=[Vr(n),-Or(n),0],o=0,a=0,h=new l;1===r?i=Tr+Ar:-1===r&&(i=-Tr-Ar);for(var u=0,c=t.length;u<c;++u)if(p=(d=t[u]).length)for(var d,p,f=d[p-1],y=Bo(f),m=f[1]/2+Br,g=Vr(m),x=Or(m),b=0;b<p;++b,y=v,g=S,x=A,f=w){var w=d[b],v=Bo(w),M=w[1]/2+Br,S=Vr(M),A=Or(M),z=v-y,_=z>=0?1:-1,T=_*z,B=T>_r,C=g*S;if(h.add(Ir(C*_*Vr(T),x*A+C*Or(T))),o+=B?z+_*Cr:z,B^y>=n^v>=n){var P=As(Ms(f),Ms(w));Ts(P);var E=As(s,P);Ts(E);var k=(B^z>=0?-1:1)*Xr(E[2]);(i>k||i===k&&(P[0]||P[1]))&&(a+=B^z>=0?1:-1)}}return(o<-1e-6||o<Ar&&h<-1e-12)^1&a}function Po(t,e,n,i){return function(r){var s,o,a,h=e(r),l=So(),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=v(o);var t=Co(s,i);o.length?(c||(r.polygonStart(),c=!0),_o(o,ko,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(Eo))}return d}}function Eo(t){return t.length>1}function ko(t,e){return((t=t.x)[0]<0?t[1]-Tr-Ar:Tr-t[1])-((e=e.x)[0]<0?e[1]-Tr-Ar:Tr-e[1])}mo.invert=mo;var No=Po(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?_r:-_r,h=kr(s-n);kr(h-_r)<Ar?(t.point(n,i=(i+o)/2>0?Tr:-Tr),t.point(r,i),t.lineEnd(),t.lineStart(),t.point(a,i),t.point(s,i),e=0):r!==a&&h>=_r&&(kr(n-r)<Ar&&(n-=r*Ar),kr(s-a)<Ar&&(s-=a*Ar),i=function(t,e,n,i){var r,s,o=Vr(t-n);return kr(o)>Ar?Nr((Vr(e)*(s=Or(i))*Vr(n)-Vr(i)*(r=Or(e))*Vr(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*Tr,i.point(-_r,r),i.point(0,r),i.point(_r,r),i.point(_r,0),i.point(_r,-r),i.point(0,-r),i.point(-_r,-r),i.point(-_r,0),i.point(-_r,r);else if(kr(t[0]-e[0])>Ar){var s=t[0]<e[0]?_r:-_r;r=n*s/2,i.point(-s,r),i.point(0,r),i.point(s,r)}else i.point(e[0],e[1])},[-_r,-Tr]);function Io(t){var e=Or(t),n=2*Er,i=e>0,r=kr(e)>Ar;function s(t,n){return Or(t)*Or(n)>e}function o(t,n,i){var r=[1,0,0],s=As(Ms(t),Ms(n)),o=Ss(s,s),a=s[0],h=o-a*a;if(!h)return!i&&t;var l=e*o/h,u=-e*a/h,c=As(r,s),d=_s(r,l);zs(d,_s(s,u));var p=c,f=Ss(d,p),y=Ss(p,p),m=f*f-y*(Ss(d,d)-1);if(!(m<0)){var g=qr(m),x=_s(p,(-f-g)/y);if(zs(x,d),x=vs(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=kr(A-_r)<Ar;if(!z&&S<M&&(b=M,M=S,S=b),z||A<Ar?z?M+S>0^x[1]<(kr(x[0]-w)<Ar?M:S):M<=x[1]&&x[1]<=S:A>_r^(w<=x[0]&&x[0]<=v)){var _=_s(p,(-f+g)/y);return zs(_,d),[x,vs(_)]}}}function a(e,n){var r=i?t:_r-t,s=0;return e<-r?s|=1:e>r&&(s|=2),n<-r?s|=4:n>r&&(s|=8),s}return Po(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?_r:-_r),d):0;if(!e&&(l=h=y)&&t.lineStart(),y!==h&&(!(p=o(e,f))||Ao(e,p)||Ao(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&&Ao(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=Or(e),a=Vr(e),h=i*n;null==r?(r=e+i*Cr,s=e-h/2):(r=Mo(o,r),s=Mo(o,s),(i>0?r<s:r>s)&&(r+=i*Cr));for(var l,u=r;i>0?u>s:u<s;u-=h)l=vs([o,-a*Or(u),-a*Vr(u)]),t.point(l[0],l[1])}}(s,t,n,r,e,i)},i?[0,-t]:[-_r,t-_r])}var Oo,Fo,Ro,Uo,Vo=1e9,Lo=-Vo;function qo(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 kr(i[0]-t)<Ar?r>0?0:3:kr(i[0]-n)<Ar?r>0?2:1:kr(i[1]-e)<Ar?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=So(),M={point:S,lineStart:function(){M.point=A,l&&l.push(u=[]);g=!0,m=!1,f=y=NaN},lineEnd:function(){h&&(A(c,d),p&&m&&w.rejoin(),h.push(w.result()));M.point=S,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=v(h)).length;(n||r)&&(o.polygonStart(),n&&(o.lineStart(),s(null,null,1,o),o.lineEnd()),r&&_o(h,a,e,s,o),o.polygonEnd());b=o,h=l=u=null}};function S(t,e){r(t,e)&&b.point(t,e)}function A(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(Lo,Math.min(Vo,f)),y=Math.max(Lo,Math.min(Vo,y))],w=[s=Math.max(Lo,Math.min(Vo,s)),o=Math.max(Lo,Math.min(Vo,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 M}}var Do={sphere:jr,point:jr,lineStart:function(){Do.point=Zo,Do.lineEnd=Xo},lineEnd:jr,polygonStart:jr,polygonEnd:jr};function Xo(){Do.point=Do.lineEnd=jr}function Zo(t,e){Fo=t*=Er,Ro=Vr(e*=Er),Uo=Or(e),Do.point=jo}function jo(t,e){t*=Er;var n=Vr(e*=Er),i=Or(e),r=kr(t-Fo),s=Or(r),o=i*Vr(r),a=Uo*n-Ro*i*s,h=Ro*n+Uo*i*s;Oo.add(Ir(qr(o*o+a*a),h)),Fo=t,Ro=n,Uo=i}var Go=[null,null],Jo={type:"LineString",coordinates:Go};function Wo(t,e){return Go[0]=t,Go[1]=e,n=Jo,Oo=new l,Hr(n,Do),+Oo;var n}var $o={Feature:function(t,e){return Ho(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,i=-1,r=n.length;++i<r;)if(Ho(n[i].geometry,e))return!0;return!1}},Yo={Sphere:function(){return!0},Point:function(t,e){return Qo(t.coordinates,e)},MultiPoint:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Qo(n[i],e))return!0;return!1},LineString:function(t,e){return Ko(t.coordinates,e)},MultiLineString:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(Ko(n[i],e))return!0;return!1},Polygon:function(t,e){return ta(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,i=-1,r=n.length;++i<r;)if(ta(n[i],e))return!0;return!1},GeometryCollection:function(t,e){for(var n=t.geometries,i=-1,r=n.length;++i<r;)if(Ho(n[i],e))return!0;return!1}};function Ho(t,e){return!(!t||!Yo.hasOwnProperty(t.type))&&Yo[t.type](t,e)}function Qo(t,e){return 0===Wo(t,e)}function Ko(t,e){for(var n,i,r,s=0,o=t.length;s<o;s++){if(0===(i=Wo(t[s],e)))return!0;if(s>0&&(r=Wo(t[s],t[s-1]))>0&&n<=r&&i<=r&&(n+i-r)*(1-Math.pow((n-i)/r,2))<zr*r)return!0;n=i}return!1}function ta(t,e){return!!Co(t.map(ea),na(e))}function ea(t){return(t=t.map(na)).pop(),t}function na(t){return[t[0]*Er,t[1]*Er]}var ia=t=>t,ra=1/0,sa=ra,oa=-ra,aa=oa,ha={point:function(t,e){t<ra&&(ra=t);t>oa&&(oa=t);e<sa&&(sa=e);e>aa&&(aa=e)},lineStart:jr,lineEnd:jr,polygonStart:jr,polygonEnd:jr,result:function(){var t=[[ra,sa],[oa,aa]];return oa=aa=-(sa=ra=1/0),t}};function la(t){return function(e){var n=new ua;for(var i in t)n[i]=t[i];return n.stream=e,n}}function ua(){}function ca(t,e,n){var i=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=i&&t.clipExtent(null),Hr(n,t.stream(ha)),e(ha.result()),null!=i&&t.clipExtent(i),t}function da(t,e,n){return ca(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)}ua.prototype={constructor:ua,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 pa=Or(30*Er);function fa(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=qr(w*w+v*v+M*M),A=Xr(M/=S),z=kr(kr(M)-1)<Ar||kr(s-c)<Ar?(s+c)/2:Ir(v,w),_=t(z,A),T=_[0],B=_[1],C=T-i,P=B-r,E=x*C-g*P;(E*E/b>e||kr((g*C+x*P)/b-.5)>.3||o*d+a*p+h*f<pa)&&(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=Ms([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 la({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)}var ya,ma=la({point:function(t,e){this.stream.point(t*Er,e*Er)}});function ga(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=Or(s),a=Vr(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 xa(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=No,A=null,z=ia,_=.5;function T(t){return h(t[0]*Er,t[1]*Er)}function B(t){return(t=h.invert(t[0],t[1]))&&[t[0]*Pr,t[1]*Pr]}function C(){var t=ga(c,0,0,w,v,b).apply(null,e(f,y)),i=ga(c,d-t[0],p-t[1],w,v,b);return n=go(m,g,x),a=yo(e,i),h=yo(n,a),o=fa(a,_),P()}function P(){return l=u=null,T}return T.stream=function(t){return l&&u===t?l:l=ma(function(t){return la({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,P()):S},T.postclip=function(t){return arguments.length?(z=t,A=i=r=s=null,P()):z},T.clipAngle=function(t){return arguments.length?(S=+t?Io(M=t*Er):(M=null,No),P()):M*Pr},T.clipExtent=function(t){return arguments.length?(z=null==t?(A=i=r=s=null,ia):qo(A=+t[0][0],i=+t[0][1],r=+t[1][0],s=+t[1][1]),P()):null==A?null:[[A,i],[r,s]]},T.scale=function(t){return arguments.length?(c=+t,C()):c},T.translate=function(t){return arguments.length?(d=+t[0],p=+t[1],C()):[d,p]},T.center=function(t){return arguments.length?(f=t[0]%360*Er,y=t[1]%360*Er,C()):[f*Pr,y*Pr]},T.rotate=function(t){return arguments.length?(m=t[0]%360*Er,g=t[1]%360*Er,x=t.length>2?t[2]%360*Er:0,C()):[m*Pr,g*Pr,x*Pr]},T.angle=function(t){return arguments.length?(b=t%360*Er,C()):b*Pr},T.reflectX=function(t){return arguments.length?(w=t?-1:1,C()):w<0},T.reflectY=function(t){return arguments.length?(v=t?-1:1,C()):v<0},T.precision=function(t){return arguments.length?(o=fa(a,_=t*t),P()):qr(_)},T.fitExtent=function(t,e){return da(T,t,e)},T.fitSize=function(t,e){return function(t,e,n){return da(t,[[0,0],e],n)}(T,t,e)},T.fitWidth=function(t,e){return function(t,e,n){return ca(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 ca(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,C()}}(function(){return t})()}function ba(t,e){return[t,Ur(Dr((Tr+e)/2))]}function wa(t,e){return[t,e]}function va(t,e){var n=Or(e),i=1+Or(t)*n;return[n*Vr(t)/i,Vr(e)/i]}ba.invert=function(t,e){return[t,2*Nr(Fr(e))-Tr]},wa.invert=wa,va.invert=(ya=function(t){return 2*Nr(t)},function(t,e){var n=qr(t*t+e*e),i=ya(n),r=Vr(i),s=Or(i);return[Ir(t*r,n*s),Xr(n&&e*r/n)]});const Ma=1e-6;class Sa{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)>Ma||Math.abs(this._y1-r)>Ma)&&(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 Aa{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 za{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 Sa: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 Sa: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 Sa: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 Aa;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 _a=2*Math.PI,Ta=Math.pow;function Ba(t){return t[0]}function Ca(t){return t[1]}function Pa(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class Ea{static from(t,e=Ba,n=Ca,i){return new Ea("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 fr(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=Pa(e[2*s],e[2*s+1],r);e[2*s]=t[0],e[2*s+1]=t[1]}this._delaunator=new fr(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 za(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=Ta(e-h[2*t],2)+Ta(n-h[2*t+1],2);const c=i[t];let d=c;do{let i=a[d];const c=Ta(e-h[2*i],2)+Ta(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&&Ta(e-h[2*d],2)+Ta(n-h[2*d+1],2)<u)return d;break}}while(d!==c);return l}render(t){const e=null==t?t=new Sa: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 Sa: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,_a)}return n&&n.value()}renderHull(t){const e=null==t?t=new Sa: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 Aa;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new Sa: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 Aa;return this.renderTriangle(t,e),e.value()}}const ka=Math.PI,Na=ka/2,Ia=180/ka,Oa=ka/180,Fa=Math.atan2,Ra=Math.cos,Ua=Math.max,Va=Math.min,La=Math.sin,qa=Math.sign||function(t){return t>0?1:t<0?-1:0},Da=Math.sqrt;function Xa(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Za(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 ja(t,e){return[t[0]+e[0],t[1]+e[1],t[2]+e[2]]}function Ga(t){var e=Da(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);return[t[0]/e,t[1]/e,t[2]/e]}function Ja(t){return[Fa(t[1],t[0])*Ia,(e=Ua(-1,Va(1,t[2])),(e>1?Na:e<-1?-Na:Math.asin(e))*Ia)];var e}function Wa(t){const e=t[0]*Oa,n=t[1]*Oa,i=Ra(n);return[i*Ra(e),i*La(e),La(n)]}function $a(t){return Xa((t=t.map(t=>Wa(t)))[0],Za(t[2],t[1]))}function Ya(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=vo(t[e]),i=xa(va).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*Da(s);r.forEach(e=>t[e]=[o,0]),t.push([0,o]),t.push([-o,0]),t.push([0,-o]);const a=Ea.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]&&!($a(t.map(t=>e[t]))<0))for(let e,i=0;i<3;i++)e=(i+1)%3,n.add(a([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=Wa([i,r]);do{o=s,s=null,a=n(l,Wa(e[o])),t[o].forEach(t=>{let i=n(l,Wa(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(Wa);return Ja(Ga(ja(ja(Za(n[1],n[0]),Za(n[2],n[1])),Za(n[0],n[2]))))})}(n,t),{polygons:l,centers:u}=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=Wa(n[0]),e=Wa(n[1]),s=Ga(ja(t,e)),a=Ga(Za(t,e)),h=Za(s,a),l=[s,Za(s,h),Za(Za(s,h),h),Za(Za(Za(s,h),h),h)].map(Ja).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=Ha(n[t[0][3][0]],n[t[0][3][1]],r[e[0]]),s=Ha(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),c=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}(l),d=function(t,e){const n=new Set,i=[];t.map(t=>{if(!($a(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),p=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=a([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:u,neighbors:r,polygons:l,mesh:c,hull:d,urquhart:p,find:s}}function Ha(t,e,n){t=Wa(t),e=Wa(e),n=Wa(n);const i=qa(Xa(Za(e,t),n));return Ja(Ga(ja(t,e)).map(t=>i*t))}function Qa(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function Ka(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function th(t,e){var n=Object.create(t.prototype);for(var i in e)n[i]=e[i];return n}function eh(){}var nh=.7,ih=1/nh,rh="\\\\s*([+-]?\\\\d+)\\\\s*",sh="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)\\\\s*",oh="\\\\s*([+-]?(?:\\\\d*\\\\.)?\\\\d+(?:[eE][+-]?\\\\d+)?)%\\\\s*",ah=/^#([0-9a-f]{3,8})$/,hh=new RegExp(`^rgb\\\\(${rh},${rh},${rh}\\\\)$`),lh=new RegExp(`^rgb\\\\(${oh},${oh},${oh}\\\\)$`),uh=new RegExp(`^rgba\\\\(${rh},${rh},${rh},${sh}\\\\)$`),ch=new RegExp(`^rgba\\\\(${oh},${oh},${oh},${sh}\\\\)$`),dh=new RegExp(`^hsl\\\\(${sh},${oh},${oh}\\\\)$`),ph=new RegExp(`^hsla\\\\(${sh},${oh},${oh},${sh}\\\\)$`),fh={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 yh(){return this.rgb().formatHex()}function mh(){return this.rgb().formatRgb()}function gh(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=ah.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?xh(e):3===n?new vh(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?bh(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?bh(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=hh.exec(t))?new vh(e[1],e[2],e[3],1):(e=lh.exec(t))?new vh(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=uh.exec(t))?bh(e[1],e[2],e[3],e[4]):(e=ch.exec(t))?bh(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=dh.exec(t))?Th(e[1],e[2]/100,e[3]/100,1):(e=ph.exec(t))?Th(e[1],e[2]/100,e[3]/100,e[4]):fh.hasOwnProperty(t)?xh(fh[t]):"transparent"===t?new vh(NaN,NaN,NaN,0):null}function xh(t){return new vh(t>>16&255,t>>8&255,255&t,1)}function bh(t,e,n,i){return i<=0&&(t=e=n=NaN),new vh(t,e,n,i)}function wh(t,e,n,i){return 1===arguments.length?((r=t)instanceof eh||(r=gh(r)),r?new vh((r=r.rgb()).r,r.g,r.b,r.opacity):new vh):new vh(t,e,n,null==i?1:i);var r}function vh(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function Mh(){return`#${_h(this.r)}${_h(this.g)}${_h(this.b)}`}function Sh(){const t=Ah(this.opacity);return`${1===t?"rgb(":"rgba("}${zh(this.r)}, ${zh(this.g)}, ${zh(this.b)}${1===t?")":`, ${t})`}`}function Ah(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function zh(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function _h(t){return((t=zh(t))<16?"0":"")+t.toString(16)}function Th(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Ch(t,e,n,i)}function Bh(t){if(t instanceof Ch)return new Ch(t.h,t.s,t.l,t.opacity);if(t instanceof eh||(t=gh(t)),!t)return new Ch;if(t instanceof Ch)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 Ch(o,a,h,t.opacity)}function Ch(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Ph(t){return(t=(t||0)%360)<0?t+360:t}function Eh(t){return Math.max(0,Math.min(1,t||0))}function kh(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Ka(eh,gh,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:yh,formatHex:yh,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Bh(this).formatHsl()},formatRgb:mh,toString:mh}),Ka(vh,wh,th(eh,{brighter(t){return t=null==t?ih:Math.pow(ih,t),new vh(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?nh:Math.pow(nh,t),new vh(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new vh(zh(this.r),zh(this.g),zh(this.b),Ah(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:Mh,formatHex:Mh,formatHex8:function(){return`#${_h(this.r)}${_h(this.g)}${_h(this.b)}${_h(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Sh,toString:Sh})),Ka(Ch,function(t,e,n,i){return 1===arguments.length?Bh(t):new Ch(t,e,n,null==i?1:i)},th(eh,{brighter(t){return t=null==t?ih:Math.pow(ih,t),new Ch(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?nh:Math.pow(nh,t),new Ch(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 vh(kh(t>=240?t-240:t+120,r,i),kh(t,r,i),kh(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new Ch(Ph(this.h),Eh(this.s),Eh(this.l),Ah(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=Ah(this.opacity);return`${1===t?"hsl(":"hsla("}${Ph(this.h)}, ${100*Eh(this.s)}%, ${100*Eh(this.l)}%${1===t?")":`, ${t})`}`}}));var Nh=t=>()=>t;function Ih(t){return 1===(t=+t)?Oh: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):Nh(isNaN(e)?n:e)}}function Oh(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Nh(isNaN(t)?e:t)}var Fh=function t(e){var n=Ih(e);function i(t,e){var i=n((t=wh(t)).r,(e=wh(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),o=Oh(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 Rh(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 Uh(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]=jh(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 Vh(t,e){var n=new Date;return t=+t,e=+e,function(i){return n.setTime(t*(1-i)+e*i),n}}function Lh(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function qh(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]=jh(t[n],e[n]):r[n]=e[n];return function(t){for(n in i)r[n]=i[n](t);return r}}var Dh=/[-+]?(?:\\d+\\.?\\d*|\\.?\\d+)(?:[eE][-+]?\\d+)?/g,Xh=new RegExp(Dh.source,"g");function Zh(t,e){var n,i,r,s=Dh.lastIndex=Xh.lastIndex=0,o=-1,a=[],h=[];for(t+="",e+="";(n=Dh.exec(t))&&(i=Xh.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:Lh(n,i)})),s=Xh.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 jh(t,e){var n,i,r=typeof e;return null==e||"boolean"===r?Nh(e):("number"===r?Lh:"string"===r?(n=gh(e))?(e=n,Fh):Zh:e instanceof gh?Fh:e instanceof Date?Vh:(i=e,!ArrayBuffer.isView(i)||i instanceof DataView?Array.isArray(e)?Uh:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?qh:Lh:Rh))(t,e)}function Gh(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function Jh(t){return+t}var Wh=[0,1];function $h(t){return t}function Yh(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:(n=isNaN(e)?NaN:.5,function(){return n});var n}function Hh(t,e,n){var i=t[0],r=t[1],s=e[0],o=e[1];return r<i?(i=Yh(r,i),s=n(o,s)):(i=Yh(i,r),s=n(s,o)),function(t){return s(i(t))}}function Qh(t,e,n){var i=Math.min(t.length,e.length)-1,r=new Array(i),s=new Array(i),a=-1;for(t[i]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++a<i;)r[a]=Yh(t[a],t[a+1]),s[a]=n(e[a],e[a+1]);return function(e){var n=o(t,e,1,i)-1;return s[n](r[n](e))}}function Kh(){var t,e,n,i,r,s,o=Wh,a=Wh,h=jh,l=$h;function u(){var t,e,n,h=Math.min(o.length,a.length);return l!==$h&&(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?Qh:Hh,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),Lh)))(n)))},c.domain=function(t){return arguments.length?(o=Array.from(t,Jh),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=Gh,u()},c.clamp=function(t){return arguments.length?(l=!!t||$h,u()):l!==$h},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 tl(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 el(t){return(t=tl(Math.abs(t)))?t[1]:NaN}var nl,il=/^(?:(.)?([<>=^]))?([+\\-( ])?([$#])?(0)?(\\d+)?(,)?(\\.\\d+)?(~)?([a-z%])?$/i;function rl(t){if(!(e=il.exec(t)))throw new Error("invalid format: "+t);var e;return new sl({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 sl(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 ol(t,e){var n=tl(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")}rl.prototype=sl.prototype,sl.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 al={"%":(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)=>ol(100*t,e),r:ol,s:function(t,e){var n=tl(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(nl=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")+tl(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function hl(t){return t}var ll,ul,cl,dl=Array.prototype.map,pl=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function fl(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?hl:(e=dl.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?hl:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(dl.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=rl(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"):al[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=al[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?pl[8+nl/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=rl(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(el(e)/3))),r=Math.pow(10,-i),s=pl[8+i/3];return function(t){return n(r*t)+s}}}}function yl(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?b(e,t,n):b(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=rl(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(el(e)/3)))-el(Math.abs(t)))}(s,o))||(i.precision=r),cl(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,el(e)-el(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,-el(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return ul(i)}function ml(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?x(e,t,n):x(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 yl(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=b(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 gl(){var t=Kh()($h,$h);return t.copy=function(){return e=t,gl().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},Qa.apply(t,arguments),ml(t)}function xl(t,e){return t.map(t=>{const n=[];let i;return t.forEach(t=>{if(i){const v=180*Wo(t,i)/Math.PI;if(v>e){const M=(s=t,o=(r=i)[0]*Er,a=r[1]*Er,h=s[0]*Er,l=s[1]*Er,u=Or(a),c=Vr(a),d=Or(l),p=Vr(l),f=u*Or(o),y=u*Vr(o),m=d*Or(h),g=d*Vr(h),x=2*Xr(qr(Zr(l-a)+u*d*Zr(h-o))),b=Vr(x),w=x?function(t){var e=Vr(t*=x)/b,n=Vr(x-t)/b,i=n*f+e*m,r=n*y+e*g,s=n*c+e*p;return[Ir(r,i)*Pr,Ir(s,qr(i*i+r*r))*Pr]}:function(){return[o*Pr,a*Pr]},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 bl(t,e,n=!1){return n?(r=t,((i=e)&&$o.hasOwnProperty(i.type)?$o[i.type]:Ho)(i,r)):Sr(t,e);var i,r}function wl(t,e){const n={type:"Polygon",coordinates:t},[[i,r],[s,o]]=eo(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=>bl(t,n,a))}function vl(t,{resolution:e=1/0,bbox:n,projection:i}={}){const r=xl(t,e),s=v(r),o=wl(t,e),h=[...s,...o],l={type:"Polygon",coordinates:t},[[u,c],[d,p]]=eo(l),f=u>d||p>=89||c<=-89;let y=[];if(f){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=Ya(e.points)}return e};return e._vx=function(t){return"object"==typeof t&&"type"in t?fo(t)[0]:0 in t?t[0]:void 0},e._vy=function(t){return"object"==typeof t&&"type"in t?fo(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=>$a(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=>Wo(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||Wo([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}(h).triangles(),e=new Map(h.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(!bl(t.properties.circumcenter,l,f))return}y.push(...i)}})}else if(o.length){const t=fr.from(h);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=>h[t]);if(n.some(t=>t<s.length)){if(!bl([0,1].map(t=>w(i,e=>e[t])),l,f))continue}y.push(...n)}}else{const{vertices:t,holes:e=[]}=W(r);y=M(t,e,2)}let m=n?[n[0],n[2]]:a(h,t=>t[0]),g=n?[n[1],n[3]]:a(h,t=>t[1]);if(i){const[t,e]=i([m[0],g[0]]),[n,r]=i([m[1],g[1]]);m=[t,n],g=[-e,-r]}const x=gl(m,[0,1]),b=gl(g,[0,1]),S=h.map(([t,e])=>{if(i){const[n,r]=i([t,e]);return[x(n),b(-r)]}return[x(t),b(e)]});return{contour:r,triangles:{points:h,indices:y,uvs:S}}}ll=fl({thousands:",",grouping:[3],currency:["$",""]}),ul=ll.format,cl=ll.formatPrefix;const Ml=(new gn).setAttribute?"setAttribute":"addAttribute";function Sl(t,e,n){return W(t.map(t=>t.map(([t,i])=>{if("cesium"===n){const n=nr(t,i,e);return[n.x,n.y,n.z]}if("sphere"===n){const n=nr(t,i,e,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 Al(t,e,n,i,r){return{indices:i?t.indices:t.indices.slice().reverse(),vertices:Sl([t.points],e,r).vertices,uvs:n}}const zl=({polygonGeoJson:t,startHeight:n,endHeight:i,curvatureResolution:r=1,hasSide:s=!0,hasBottom:o=!1,hasTop:a=!1,projection:h="sphere",bbox:l})=>{t.forEach(t=>{e(t)||t.reverse()});const u="function"==typeof h?h:void 0,{contour:c,triangles:d}=vl(t,{resolution:r,bbox:l,projection:u});let p,f={};s&&(f=function(t,e,n,i){const{vertices:r,holes:s}=Sl(t,e,i),{vertices:o}=Sl(t,n,i),a=v([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}}(c,null!=n?n:i,null!=i?i:n,h),p=f.topVerts);let y=[];(o||a)&&(y=v(d.uvs));let m={};o&&(m=Al(d,n,y,!1,h));let g={};return a&&(g=Al(d,i,y,!0,h)),{contour:c,triangles:d,sideTorso:f,bottomCap:m,topCap:g,topVerts:p}};class _l extends gn{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}=zl(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 en(new Float64Array(l),3)),this.setIndex(d),this[Ml]("position",new sn(l,3)),this[Ml]("uv",new sn(c,2)),this.computeVertexNormals()}}class Tl extends gn{constructor(t=[],e="none",n,i=!1,r){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 Xt),p(this,"useRTC",!1),p(this,"rtcCenter",new St(0,0,0)),this.shape=e,this.useRTC=i,n&&(this.shapeFunction=n),r&&this.rtcCenter.copy(r),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 St(n[t],n[t+1],n[t+2]));return e}return t.map(t=>t instanceof vt?new St(t.x,t.y,0):t instanceof St?t:Array.isArray(t)&&2===t.length?new St(t[0],t[1],0):Array.isArray(t)&&3===t.length?new St(t[0],t[1],t[2]):null).filter(Boolean)}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e,n,i){t&&0!==t.length&&(this._points=this.convertToVector3Array(t),this.pointCount=this._points.length,void 0!==n&&(this.useRTC=n),i?this.rtcCenter.copy(i):this.useRTC&&this._points.length>0&&this.rtcCenter.copy(this._points[0]),e&&(this.shapeFunction=e,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const t=new en(new Float32Array(6*this.pointCount),3),e=new en(new Float32Array(6*this.pointCount),3),n=new en(new Float32Array(6*this.pointCount),3),i=new en(new Float32Array(2*this.pointCount),1),r=new en(new Float32Array(2*this.pointCount),1),s=new en(new Float32Array(2*this.pointCount),1),o=new en(new Float32Array(4*this.pointCount),2),a=new en(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(){if(!this._points[0])return;const t=this.getAttribute("position"),e=this.getAttribute("previous"),n=this.getAttribute("next");let i=0,r=0,s=0;const o=this._points[0],a=this.useRTC?this.getRelativePosition(o):o;e.setXYZ(r,a.x,a.y,a.z),r+=1,e.setXYZ(r,a.x,a.y,a.z),r+=1;for(let u=0;u<this.pointCount;u++){const o=this._points[u],a=this.useRTC?this.getRelativePosition(o):o;t.setXYZ(i,a.x,a.y,a.z),i+=1,t.setXYZ(i,a.x,a.y,a.z),i+=1,u<this.pointCount-1&&(e.setXYZ(r,a.x,a.y,a.z),r+=1,e.setXYZ(r,a.x,a.y,a.z),r+=1),u>0&&u+1<=this.pointCount&&(n.setXYZ(s,a.x,a.y,a.z),s+=1,n.setXYZ(s,a.x,a.y,a.z),s+=1)}const h=this._points[this.pointCount-1],l=this.useRTC?this.getRelativePosition(h):h;n.setXYZ(s,l.x,l.y,l.z),s+=1,n.setXYZ(s,l.x,l.y,l.z),s+=1,t.needsUpdate=!0,e.needsUpdate=!0,n.needsUpdate=!0,this.useRTC?(this.boundingSphere=new ln(new St,1/0),this.boundingBox=new Re(new St(-1/0,-1/0,-1/0),new St(1/0,1/0,1/0))):(this.computeBoundingSphere(),this.computeBoundingBox())}getRelativePosition(t){return new St(t.x-this.rtcCenter.x,t.y-this.rtcCenter.y,t.z-this.rtcCenter.z)}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())}getRTCCenter(){return this.rtcCenter.clone()}setUseRTC(t){this.useRTC!==t&&(this.useRTC=t,this._points.length>0&&(this.useRTC&&this.rtcCenter.copy(this._points[0]),this.updateGeometry()))}getUseRTC(){return this.useRTC}setRTCCenter(t){this.rtcCenter.copy(t),this._points.length>0&&this.updateGeometry()}}var Bl=t=>{const{setPointWidth:e,nodes:n,useRTC:i=!1,rtcCenter:r}=t,s=new Tl(void 0,void 0,void 0,i,r);return s.setPoints(n,e,i,r),s};const Cl=(t,e,n,i=2)=>{const r=[];if(!t||!e||!n)return r;let s=0;for(let a=0;a<e.length;a++)s+=e[a]*i;const o=(t.length-s)/n;r.length=o;for(let a=0;a<o;a++){const e=new Array(n);for(let i=0;i<n;i++)e[i]=t[s+a*n+i];r[a]=e}return r},Pl=({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);if(2===i)for(let e=0;e<s;e++)a[e]=[t[o],t[o+1]],o+=2;else if(3===i)for(let e=0;e<s;e++)a[e]=[t[o],t[o+1],t[o+2]],o+=3;else for(let e=0;e<s;e++){const n=new Array(i);for(let e=0;e<i;e++)n[e]=t[o+e];a[e]=n,o+=i}r[n]=a}if(n){const e=(t.length-o)/n;s.length=e;for(let i=0;i<e;i++){const e=new Array(n);for(let i=0;i<n;i++)e[i]=t[o+i];s[i]=e,o+=n}}}return{coordinatesArr:r,metaArray:s}};function El(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 en(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 kl(t,e=0){const n=function(t,e=!1){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 gn;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}h.addGroup(l,t,u),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=El(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=El(t);if(!n)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+u+" morphAttribute."),null;h.morphAttributes[u].push(n)}}return h}(t,!1);if(!n)return null;if(e){const i=null!==t[0].index;let r=0;for(let s=0;s<t.length;s++){const o=t[s];let a;if(i)a=o.index.count;else{if(void 0===o.attributes.position)return null;a=o.attributes.position.count}if(1===e)n.addGroup(r,a,s);else if(2===e&&o.groups.length>0)for(const t of o.groups)n.addGroup(r+t.start,Math.min(t.count,a),t.materialIndex);r+=a}if(2===e)return 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}(n)}return n}var Nl=(t,e)=>{var n,i;const r={},s=t[0],o=(null==(n=s.getUseRTC)?void 0:n.call(s))&&(null==(i=s.getRTCCenter)?void 0:i.call(s)),a=kl(t,null!=e?e:0),h=[],l=Object.keys(a.attributes);return a.index&&l.push("index"),l.forEach(t=>{const e="index"===t?a.index:a.attributes[t];r[t]={array:e.array,itemSize:e.itemSize},h.push(e.array.buffer)}),e&&(r.groups=a.groups),o&&(r.rtcCenter={x:o.x,y:o.y,z:o.z}),a.dispose(),t.forEach(t=>{t.dispose()}),{message:r,transfer:h}};function Il({coordinatesArr:t,metaArray:e,globalMeta:n,hasTop:i,topFirst:r,hasBottom:s,hasSide:o,projection:a="sphere",curvatureResolution:h,bbox:l}){return t.map((t,p)=>{var f,y;const m=e&&e[p]||n||[],g=null!=(f=m[0])?f:0,x=null!=(y=m[1])?y: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 _l([n],c(u({},s),{startHeight:i,endHeight:o}))})({coordinate:t,projection:a,startHeight:x,height:g,hasTop:null==i||i,topFirst:null!=r&&r,hasBottom:null==s||s,hasSide:null==o||o,curvatureResolution:null!=h?h:1,bbox:l})})}const Ol={ArcCurve:Wn,CatmullRomCurve3:ti,CubicBezierCurve:ri,CubicBezierCurve3:si,EllipseCurve:Jn,LineCurve:oi,LineCurve3:ai,QuadraticBezierCurve:hi,QuadraticBezierCurve3:li,SplineCurve:ui};class Fl extends gn{constructor(t=new fi([new vt(.5,.5),new vt(-.5,.5),new vt(-.5,-.5),new vt(.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:Rl,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 St,z=new St,_=new St),d||(m=0,p=0,f=0,y=0);const B=t.extractPoints(l);let C=B.shape;const P=B.holes;if(!Di.isClockWise(C)){C=C.reverse();for(let t=0,e=P.length;t<e;t++){const e=P[t];Di.isClockWise(e)&&(P[t]=e.reverse())}}function E(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}}E(C),P.forEach(E);const k=P.length,N=C;for(let e=0;e<k;e++){const t=P[e];C=C.concat(t)}function I(t,e,n){return e||error("ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,n)}const O=C.length;function F(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 vt(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 vt(i/s,r/s)}const R=[];for(let e=0,n=N.length,i=n-1,r=e+1;e<n;e++,i++,r++)i===n&&(i=0),r===n&&(r=0),R[e]=F(N[e],N[i],N[r]);const U=[];let V,L,q=R.concat();for(let e=0,n=k;e<n;e++){const t=P[e];V=[];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),V[e]=F(t[e],t[i],t[r]);U.push(V),q=q.concat(V)}if(0===m)L=Di.triangulateShape(N,P);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=N.length;e<n;e++){const n=I(N[e],R[e],s);j(n.x,n.y,-r),0===i&&t.push(n)}for(let t=0,n=k;t<n;t++){const n=P[t];V=U[t];const o=[];for(let t=0,e=n.length;t<e;t++){const e=I(n[t],V[t],s);j(e.x,e.y,-r),0===i&&o.push(e)}0===i&&e.push(o)}}L=Di.triangulateShape(t,e)}const D=L.length,X=f+y;for(let e=0;e<O;e++){const t=d?I(C[e],q[e],X):C[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<O;t++){const n=d?I(C[t],q[t],X):C[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=N.length;e<r;e++){const t=I(N[e],R[e],i);j(t.x,t.y,c+n)}for(let e=0,r=P.length;e<r;e++){const t=P[e];V=U[e];for(let e=0,r=t.length;e<r;e++){const r=I(t[e],V[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 Z(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=O*t,s=O*(t+1);J(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 G(t,e,r){W(t),W(e),W(r);const s=i.length/3,o=x.generateTopUV(n,i,s-3,s-2,s-1);$(o[0]),$(o[1]),$(o[2])}function J(t,e,r,s){W(t),W(e),W(s),W(e),W(r),W(s);const o=i.length/3,a=x.generateSideWallUV(n,i,o-6,o-3,o-2,o-1);$(a[0]),$(a[1]),$(a[3]),$(a[1]),$(a[2]),$(a[3])}function W(t){i.push(h[3*t+0]),i.push(h[3*t+1]),i.push(h[3*t+2])}function $(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(d){let t=0,e=O*t;if(w)for(let n=0;n<D;n++){const t=L[n];G(t[2]+e,t[1]+e,t[0]+e)}if(t=u+2*m,e=O*t,b)for(let n=0;n<D;n++){const t=L[n];G(t[0]+e,t[1]+e,t[2]+e)}}else{if(w)for(let t=0;t<D;t++){const e=L[t];G(e[2],e[1],e[0])}if(b)for(let t=0;t<D;t++){const e=L[t];G(e[0]+O*u,e[1]+O*u,e[2]+O*u)}}n.addGroup(t,i.length/3-t,0)}(),v&&function(){const t=i.length/3;let e=0;Z(N,e),e+=N.length;for(let n=0,i=P.length;n<i;n++){const t=P[n];Z(t,e),e+=t.length}n.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new sn(i,3)),this.setAttribute("uv",new sn(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 Ol[i.type]).fromJSON(i)),new Fl(n,t.options)}}const Rl={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 vt(s,o),new vt(a,h),new vt(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 vt(o,1-h),new vt(l,1-c),new vt(d,1-f),new vt(y,1-g)]:[new vt(a,1-h),new vt(u,1-c),new vt(p,1-f),new vt(m,1-g)]}};const Ul=1.25,Vl=32,Ll=Math.pow(2,-24),ql=Symbol("SKIP_GENERATION");function Dl(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function Xl(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 en(i,1));for(let t=0;t<n;t++)i[t]=t}}function Zl(t,e){const n=Dl(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 jl(t,e){if(!t.groups||!t.groups.length)return Zl(t,e);const n=[],i=e||t.drawRange,r=i.start/3,s=(i.start+i.count)/3,o=Dl(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 Gl(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 Jl(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)*Ll}}return r}function Wl(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 $l(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 Yl(t,e){e.set(t)}function Hl(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 Ql(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 Kl(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 tu=32,eu=(t,e)=>t.candidate-e.candidate,nu=new Array(tu).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),iu=new Float32Array(6);class ru{constructor(){this.boundingData=new Float32Array(6)}}function su(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 ou(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 au,hu,lu,uu;const cu=Math.pow(2,32);function du(t){return"count"in t?1:1+du(t.left)+du(t.right)}function pu(t,e,n){return au=new Float32Array(n),hu=new Uint32Array(n),lu=new Uint16Array(n),uu=new Uint8Array(n),fu(t,e)}function fu(t,e){const n=t/4,i=t/2,r="count"in e,s=e.boundingData;for(let o=0;o<6;o++)au[n+o]=s[o];if(r)return e.buffer?(uu.set(new Uint8Array(e.buffer),t),t+e.buffer.byteLength):(hu[n+6]=e.offset,lu[i+14]=e.count,lu[i+15]=65535,t+Vl);{const{left:i,right:r,splitAxis:s}=e;let o=fu(t+Vl,i);const a=o/Vl-t/Vl;if(a>cu)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return hu[n+6]=a,hu[n+7]=s,fu(o,r)}}function yu(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?ou:su,y=Dl(d),m=new Float32Array(6);let g=!1;const x=new ru;return Gl(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=$l(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===s)o=$l(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=Kl(t);let h=Ul*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)/tu;if(r<8){const e=[...nu];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;Ql(r,n,o)}e.sort(eu);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?Ql(r,n,s.rightCacheBounds):(Ql(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=Kl(c)/s);let f=0;0!==u&&(f=Kl(d)/s);const y=1+Ul*(p*l+f*u);y<h&&(o=t,h=y,a=i.candidate)}}else{for(let t=0;t<tu;t++){const e=nu[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>=tu&&(e=31);const s=nu[e];s.count++,Ql(r,n,s.bounds)}const e=nu[31];Yl(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=nu[t],n=nu[t+1];Hl(e.bounds,n.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let n=0;n<31;n++){const e=nu[n],i=e.count,l=e.bounds,u=nu[n+1].rightCacheBounds;0!==i&&(0===d?Yl(l,iu):Hl(l,iu,iu)),d+=i;let c=0,p=0;0!==d&&(c=Kl(iu)/s);const f=r-d;0!==f&&(p=Kl(u)/s);const y=1+Ul*(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 ru,o=i,a=x-i;n.left=s,Gl(e,o,a,s.boundingData,m),t(s,o,a,m,u+1);const h=new ru,l=x,c=r-a;n.right=h,Gl(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 mu(t,e){const n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=t.geometry;let r,s;if(e.indirect){const n=jl(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=Jl(i,0,o.length,o),s=[{offset:0,count:o.length}]}else{Xl(i,e);const t=Zl(i,e.range)[0];r=Jl(i,t.offset,t.count),s=jl(i,e.range)}t._roots=s.map(i=>{const s=yu(t,r,i.offset,i.count,e),o=du(s),a=new n(Vl*o);return pu(0,s,a),a})}class gu{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}}gu.prototype.setFromBox=function(){const t=new St;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 xu=function(){const t=new St,e=new St,n=new St;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}}(),bu=function(){const t=new vt,e=new St,n=new St;return function(i,r,s,o){xu(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))}}}(),wu=function(){const t=new St,e=new St,n=new jn,i=new Ki;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}}(),vu=["x","y","z"],Mu=1e-15;function Su(t){return Math.abs(t)<Mu}class Au extends Fe{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new St),this.satBounds=new Array(4).fill().map(()=>new gu),this.points=[this.a,this.b,this.c],this.plane=new jn,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Ki,this.needsUpdate=!0}intersectsSphere(t){return wu(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<Mu?y<Mu||m<Mu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(n)):y<Mu?m<Mu?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):m<Mu&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Au.prototype.closestPointToSegment=function(){const t=new St,e=new St,n=new Ki;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]),bu(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)}}(),Au.prototype.intersectsTriangle=function(){const t=new Au,e=new gu,n=new gu,i=new St,r=new St,s=new St,o=new St,a=new Ki,h=new Ki,l=new St,u=new vt,c=new vt;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 Su(o)?Su(a)?d(t,e,n,r):(n&&(n.start.copy(s.start),n.end.copy(s.start)),t.containsPoint(s.start)):Su(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!(!Su(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(Su(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)&&(!!Su(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);Su(w)&&(w=0),Su(v)&&(v=0),Su(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);Su(z)&&(z=0),Su(_)&&(_=0),Su(T)&&(T=0);const B=z*_,C=z*T;if(B>0&&C>0)return!1;r.copy(x.normal),s.copy(b.normal);const P=r.cross(s);let E=0,k=Math.abs(P.x);const N=Math.abs(P.y);N>k&&(k=N,E=1);Math.abs(P.z)>k&&(E=2);const I=vu[E],O=this.a[I],F=this.b[I],R=this.c[I],U=e.a[I],V=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,U,V,L,B,C,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)}}(),Au.prototype.distanceToPoint=function(){const t=new St;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Au.prototype.distanceToTriangle=function(){const t=new St,e=new St,n=["a","b","c"],i=new Ki,r=new Ki;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]),bu(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 zu{constructor(t,e,n){this.isOrientedBox=!0,this.min=new St,this.max=new St,this.matrix=new Xt,this.invMatrix=new Xt,this.points=new Array(8).fill().map(()=>new St),this.satAxes=new Array(3).fill().map(()=>new St),this.satBounds=new Array(3).fill().map(()=>new gu),this.alignedSatBounds=new Array(3).fill().map(()=>new gu),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}}zu.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}}(),zu.prototype.intersectsBox=function(){const t=new gu;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}}(),zu.prototype.intersectsTriangle=function(){const t=new Au,e=new Array(3),n=new gu,i=new gu,r=new St;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}}(),zu.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}}(),zu.prototype.distanceToPoint=function(){const t=new St;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),zu.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map(()=>new Ki),n=new Array(12).fill().map(()=>new Ki),i=new St,r=new St;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];bu(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 _u{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 Tu extends _u{constructor(){super(()=>new Au)}}const Bu=new Tu;function Cu(t,e){return 65535===e[t+15]}function Pu(t,e){return e[t+6]}function Eu(t,e){return e[t+14]}function ku(t){return t+8}function Nu(t,e){return t+8*e[t+6]}function Iu(t,e){return e[t+7]}function Ou(t){return t}class Fu{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 Ru=new Fu;let Uu,Vu;const Lu=[],qu=new _u(()=>new Re);function Du(t,e,n,i,r,s){Uu=qu.getPrimitive(),Vu=qu.getPrimitive(),Lu.push(Uu,Vu),Ru.setBuffer(t._roots[e]);const o=Xu(0,t.geometry,n,i,r,s);Ru.clearBuffer(),qu.releasePrimitive(Uu),qu.releasePrimitive(Vu),Lu.pop(),Lu.pop();const a=Lu.length;return a>0&&(Vu=Lu[a-1],Uu=Lu[a-2]),o}function Xu(t,e,n,i,r=null,s=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru;let u=2*t;if(Cu(u,h)){const e=Pu(t,l),n=Eu(u,h);return Wl(t,a,Uu),i(e,n,!1,o,s+t/8,Uu)}{let u=function(t){const{uint16Array:e,uint32Array:n}=Ru;let i=2*t;for(;!Cu(i,e);)i=2*(t=ku(t));return Pu(t,n)},c=function(t){const{uint16Array:e,uint32Array:n}=Ru;let i=2*t;for(;!Cu(i,e);)i=2*(t=Nu(t,n));return Pu(t,n)+Eu(i,e)};const d=ku(t),p=Nu(t,l);let f,y,m,g,x=d,b=p;if(r&&(m=Uu,g=Vu,Wl(x,a,m),Wl(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=Uu,Wl(x,a,m));const w=n(m,Cu(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&&Xu(x,e,n,i,r,s,o+1);if(v)return!0;g=Vu,Wl(b,a,g);const M=n(g,Cu(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&&Xu(b,e,n,i,r,s,o+1);return!!S}}const Zu=new St,ju=new St;const Gu=parseInt($)>=169,Ju=parseInt($)<=161,Wu=new St,$u=new St,Yu=new St,Hu=new vt,Qu=new vt,Ku=new vt,tc=new St,ec=new St,nc=new St,ic=new St;function rc(t,e,n,i,r,s,o,a,h,l,u){Wu.fromBufferAttribute(e,s),$u.fromBufferAttribute(e,o),Yu.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,Wu,$u,Yu,ic,h,l,u);if(c){if(i){Hu.fromBufferAttribute(i,s),Qu.fromBufferAttribute(i,o),Ku.fromBufferAttribute(i,a),c.uv=new vt;const t=Fe.getInterpolation(ic,Wu,$u,Yu,Hu,Qu,Ku,c.uv);Gu||(c.uv=t)}if(r){Hu.fromBufferAttribute(r,s),Qu.fromBufferAttribute(r,o),Ku.fromBufferAttribute(r,a),c.uv1=new vt;const t=Fe.getInterpolation(ic,Wu,$u,Yu,Hu,Qu,Ku,c.uv1);Gu||(c.uv1=t),Ju&&(c.uv2=c.uv1)}if(n){tc.fromBufferAttribute(n,s),ec.fromBufferAttribute(n,o),nc.fromBufferAttribute(n,a),c.normal=new St;const e=Fe.getInterpolation(ic,Wu,$u,Yu,tc,ec,nc,c.normal);c.normal.dot(t.direction)>0&&c.normal.multiplyScalar(-1),Gu||(c.normal=e)}const e={a:s,b:o,c:a,normal:new St,materialIndex:0};if(Fe.getNormal(Wu,$u,Yu,e.normal),c.face=e,c.faceIndex=s,Gu){const t=new St;Fe.getBarycoord(ic,Wu,$u,Yu,t),c.barycoord=t}}return c}function sc(t){return t&&t.isMaterial?t.side:t}function oc(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=rc(n,p,f,y,m,h,l,u,sc(e[x]),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=x,!r)return t;r.push(t)}}}}else{const t=rc(n,p,f,y,m,h,l,u,sc(e),s,o);if(t){if(t.faceIndex=i,t.face.materialIndex=0,!r)return t;r.push(t)}}return null}function ac(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 hc(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,ac(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function lc(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(Cu(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=ku(t),r=Nu(t,o);let a=s,l=!1,u=!1;if(e){if(!a){const t=i/8+n/Vl,s=r/8+n/Vl;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 uc(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 cc(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),ac(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,s))return!0}return!1}function dc(t,e,n,i,r,s,o){Ru.setBuffer(t._roots[e]),pc(0,t,n,i,r,s,o),Ru.clearBuffer()}function pc(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru,u=2*t;if(Cu(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++)oc(h,e,n,u,s,o,a)}(e,n,i,Pu(t,l),Eu(u,h),r,s,o)}else{const h=ku(t);uc(h,a,i,s,o)&&pc(h,e,n,i,r,s,o);const u=Nu(t,l);uc(u,a,i,s,o)&&pc(u,e,n,i,r,s,o)}}const fc=["x","y","z"];function yc(t,e,n,i,r,s){Ru.setBuffer(t._roots[e]);const o=mc(0,t,n,i,r,s);return Ru.clearBuffer(),o}function mc(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=Ru;let l=2*t;if(Cu(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=oc(a,e,n,c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,Pu(t,h),Eu(l,a),r,s)}{const a=Iu(t,h),l=fc[a],u=i.direction[l]>=0;let c,d;u?(c=ku(t),d=Nu(t,h)):(c=Nu(t,h),d=ku(t));const p=uc(c,o,i,r,s)?mc(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=uc(d,o,i,r,s)?mc(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const gc=new Re,xc=new Au,bc=new Au,wc=new Xt,vc=new zu,Mc=new zu;function Sc(t,e,n,i){Ru.setBuffer(t._roots[e]);const r=Ac(0,t,n,i);return Ru.clearBuffer(),r}function Ac(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=Ru;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),vc.set(n.boundingBox.min,n.boundingBox.max,i),r=vc);if(!Cu(h,o)){const o=ku(t),h=Nu(t,a);Wl(o,s,gc);if(r.intersectsBox(gc)&&Ac(o,e,n,i,r))return!0;Wl(h,s,gc);return!!(r.intersectsBox(gc)&&Ac(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=Pu(t,a),f=Eu(h,o);if(wc.copy(i).invert(),n.boundsTree){Wl(t,s,Mc),Mc.matrix.copy(wc),Mc.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Mc.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(ac(bc,e,l,u),bc.needsUpdate=!0,t.intersectsTriangle(bc))return!0;return!1}})}{const t=Dl(n);for(let e=3*p,n=3*(f+p);e<n;e+=3){ac(xc,e,l,u),xc.a.applyMatrix4(wc),xc.b.applyMatrix4(wc),xc.c.applyMatrix4(wc),xc.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(ac(bc,e,c,d),bc.needsUpdate=!0,xc.intersectsTriangle(bc))return!0}}}}const zc=new Xt,_c=new zu,Tc=new zu,Bc=new St,Cc=new St,Pc=new St,Ec=new St;function kc(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),_c.set(e.boundingBox.min,e.boundingBox.max,n),_c.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=Bu.getPrimitive(),p=Bu.getPrimitive();let f=Bc,y=Cc,m=null,g=null;r&&(m=Pc,g=Ec);let x=1/0,b=null,w=null;return zc.copy(n).invert(),Tc.matrix.copy(zc),t.shapecast({boundsTraverseOrder:t=>_c.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&(Tc.min.copy(t.min),Tc.max.copy(t.max),Tc.needsUpdate=!0),!0),intersectsRange:(t,i)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>Tc.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o,intersectsRange:(e,r)=>{for(let o=e,a=e+r;o<a;o++){ac(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++){ac(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=Dl(e);r<o;r++){ac(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++){ac(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}}}}),Bu.releasePrimitive(d),Bu.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(zc),y.applyMatrix4(zc),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}function Nc(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(Cu(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=ku(n),i=Nu(n,o);let r=l,a=!1,u=!1;if(e){if(!r){const n=t/8+s/Vl,o=i/8+s/Vl;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 Ic(t,e,n,i,r,s,o){Ru.setBuffer(t._roots[e]),Oc(0,t,n,i,r,s,o),Ru.clearBuffer()}function Oc(t,e,n,i,r,s,o){const{float32Array:a,uint16Array:h,uint32Array:l}=Ru,u=2*t;if(Cu(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++)oc(h,e,n,l?l[u]:u,s,o,a)}(e,n,i,Pu(t,l),Eu(u,h),r,s,o)}else{const h=ku(t);uc(h,a,i,s,o)&&Oc(h,e,n,i,r,s,o);const u=Nu(t,l);uc(u,a,i,s,o)&&Oc(u,e,n,i,r,s,o)}}const Fc=["x","y","z"];function Rc(t,e,n,i,r,s){Ru.setBuffer(t._roots[e]);const o=Uc(0,t,n,i,r,s);return Ru.clearBuffer(),o}function Uc(t,e,n,i,r,s){const{float32Array:o,uint16Array:a,uint32Array:h}=Ru;let l=2*t;if(Cu(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=oc(a,e,n,h?h[c]:c,null,s,o),t&&t.distance<l&&(u=t,l=t.distance)}return u}(e,n,i,Pu(t,h),Eu(l,a),r,s)}{const a=Iu(t,h),l=Fc[a],u=i.direction[l]>=0;let c,d;u?(c=ku(t),d=Nu(t,h)):(c=Nu(t,h),d=ku(t));const p=uc(c,o,i,r,s)?Uc(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=uc(d,o,i,r,s)?Uc(d,e,n,i,r,s):null;return p&&f?p.distance<=f.distance?p:f:p||f||null}}const Vc=new Re,Lc=new Au,qc=new Au,Dc=new Xt,Xc=new zu,Zc=new zu;function jc(t,e,n,i){Ru.setBuffer(t._roots[e]);const r=Gc(0,t,n,i);return Ru.clearBuffer(),r}function Gc(t,e,n,i,r=null){const{float32Array:s,uint16Array:o,uint32Array:a}=Ru;let h=2*t;null===r&&(n.boundingBox||n.computeBoundingBox(),Xc.set(n.boundingBox.min,n.boundingBox.max,i),r=Xc);if(!Cu(h,o)){const o=ku(t),h=Nu(t,a);Wl(o,s,Vc);if(r.intersectsBox(Vc)&&Gc(o,e,n,i,r))return!0;Wl(h,s,Vc);return!!(r.intersectsBox(Vc)&&Gc(h,e,n,i,r))}{const r=e.geometry,l=r.index,u=r.attributes.position,c=n.index,d=n.attributes.position,p=Pu(t,a),f=Eu(h,o);if(Dc.copy(i).invert(),n.boundsTree){Wl(t,s,Zc),Zc.matrix.copy(Dc),Zc.needsUpdate=!0;return n.boundsTree.shapecast({intersectsBounds:t=>Zc.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(ac(qc,3*e.resolveTriangleIndex(n),l,u),qc.needsUpdate=!0,t.intersectsTriangle(qc))return!0;return!1}})}{const t=Dl(n);for(let n=p,i=f+p;n<i;n++){const i=e.resolveTriangleIndex(n);ac(Lc,3*i,l,u),Lc.a.applyMatrix4(Dc),Lc.b.applyMatrix4(Dc),Lc.c.applyMatrix4(Dc),Lc.needsUpdate=!0;for(let e=0,n=3*t;e<n;e+=3)if(ac(qc,e,c,d),qc.needsUpdate=!0,Lc.intersectsTriangle(qc))return!0}}}}const Jc=new Xt,Wc=new zu,$c=new zu,Yc=new St,Hc=new St,Qc=new St,Kc=new St;function td(t,e,n,i={},r={},s=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Wc.set(e.boundingBox.min,e.boundingBox.max,n),Wc.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,u=e.attributes.position,c=e.index,d=Bu.getPrimitive(),p=Bu.getPrimitive();let f=Yc,y=Hc,m=null,g=null;r&&(m=Qc,g=Kc);let x=1/0,b=null,w=null;return Jc.copy(n).invert(),$c.matrix.copy(Jc),t.shapecast({boundsTraverseOrder:t=>Wc.distanceToBox(t),intersectsBounds:(t,e,n)=>n<x&&n<o&&(e&&($c.min.copy(t.min),$c.max.copy(t.max),$c.needsUpdate=!0),!0),intersectsRange:(i,r)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>$c.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);ac(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);ac(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=Dl(e);o<a;o++){ac(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);ac(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}}}}),Bu.releasePrimitive(d),Bu.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(Jc),y.applyMatrix4(Jc),r.distance=y.sub(r.point).length(),r.faceIndex=w),i)}const ed=new Ru.constructor,nd=new Ru.constructor,id=new _u(()=>new Re),rd=new Re,sd=new Re,od=new Re,ad=new Re;let hd=!1;function ld(t,e,n,i,r,s=0,o=0,a=0,h=0,l=null,u=!1){let c,d;u?(c=nd,d=ed):(c=ed,d=nd);const p=c.float32Array,f=c.uint32Array,y=c.uint16Array,m=d.float32Array,g=d.uint32Array,x=d.uint16Array,b=2*e,w=Cu(2*t,y),v=Cu(b,x);let M=!1;if(v&&w)M=u?r(Pu(e,g),Eu(2*e,x),Pu(t,f),Eu(2*t,y),h,o+e/8,a,s+t/8):r(Pu(t,f),Eu(2*t,y),Pu(e,g),Eu(2*e,x),a,s+t/8,h,o+e/8);else if(v){const l=id.getPrimitive();Wl(e,m,l),l.applyMatrix4(n);const c=ku(t),d=Nu(t,f);Wl(c,p,rd),Wl(d,p,sd);const y=l.intersectsBox(rd),g=l.intersectsBox(sd);M=y&&ld(e,c,i,n,r,o,s,h,a+1,l,!u)||g&&ld(e,d,i,n,r,o,s,h,a+1,l,!u),id.releasePrimitive(l)}else{const c=ku(e),d=Nu(e,g);Wl(c,m,od),Wl(d,m,ad);const y=l.intersectsBox(od),x=l.intersectsBox(ad);if(y&&x)M=ld(t,c,n,i,r,s,o,a,h+1,l,u)||ld(t,d,n,i,r,s,o,a,h+1,l,u);else if(y)if(w)M=ld(t,c,n,i,r,s,o,a,h+1,l,u);else{const e=id.getPrimitive();e.copy(od).applyMatrix4(n);const l=ku(t),d=Nu(t,f);Wl(l,p,rd),Wl(d,p,sd);const y=e.intersectsBox(rd),m=e.intersectsBox(sd);M=y&&ld(c,l,i,n,r,o,s,h,a+1,e,!u)||m&&ld(c,d,i,n,r,o,s,h,a+1,e,!u),id.releasePrimitive(e)}else if(x)if(w)M=ld(t,d,n,i,r,s,o,a,h+1,l,u);else{const e=id.getPrimitive();e.copy(ad).applyMatrix4(n);const l=ku(t),c=Nu(t,f);Wl(l,p,rd),Wl(c,p,sd);const y=e.intersectsBox(rd),m=e.intersectsBox(sd);M=y&&ld(d,l,i,n,r,o,s,h,a+1,e,!u)||m&&ld(d,c,i,n,r,o,s,h,a+1,e,!u),id.releasePrimitive(e)}}return M}const ud=new zu,cd=new Re,dd={strategy:0,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class pd{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/Vl;t<e;t++){const e=8*t;Cu(2*e,r)||(i[e+6]=i[e+6]/8-t)}}}(r));const o=new pd(e,c(u({},n),{[ql]:!0}));if(o._roots=r,o._indirectBuffer=s||null,n.setIndex){const n=e.getIndex();if(null===n){const n=new en(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({},dd),{[ql]:!1}),e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[ql]||(mu(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Re))),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/Vl;for(let e=0;e<o;e++){const n=8*e;Cu(2*n,s)&&(r[n+6]+=t)}}}}refit(t=null){return(this.indirect?Nc:lc)(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=Cu(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=ku(s),a=Nu(s,i),l=Iu(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?Ic:dc;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?Rc:yc;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?jc:Sc;for(let s=0,o=i.length;s<o&&(n=r(this,s,t,e),!n);s++);return n}shapecast(t){const e=Bu.getPrimitive(),n=this.indirect?cc:hc;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=Du(this,u,r,s,i,h),a)break;h+=t.byteLength/Vl}return Bu.releasePrimitive(e),a}bvhcast(t,e,n){let{intersectsRanges:i,intersectsTriangles:r}=n;const s=Bu.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);ac(s,3*e,o,a)}:t=>{ac(s,3*t,o,a)},l=Bu.getPrimitive(),u=t.geometry.index,c=t.geometry.attributes.position,d=t.indirect?e=>{const n=t.resolveTriangleIndex(e);ac(l,3*n,u,c)}:t=>{ac(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(hd)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");hd=!0;const r=t._roots,s=e._roots;let o,a=0,h=0;const l=(new Xt).copy(n).invert();for(let u=0,c=r.length;u<c;u++){ed.setBuffer(r[u]),h=0;const t=id.getPrimitive();Wl(Ou(0),ed.float32Array,t),t.applyMatrix4(l);for(let e=0,r=s.length;e<r&&(nd.setBuffer(s[e]),o=ld(0,0,n,l,i,a,h,0,0,t),nd.clearBuffer(),h+=s[e].byteLength/Vl,!o);e++);if(id.releasePrimitive(t),ed.clearBuffer(),a+=r[u].byteLength/Vl,o)break}return hd=!1,o}(this,t,e,i)}intersectsBox(t,e){return ud.set(t.min,t.max,e),ud.needsUpdate=!0,this.shapecast({intersectsBounds:t=>ud.intersectsBox(t),intersectsTriangle:t=>ud.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?td:kc)(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=>(Zu.copy(e).clamp(t.min,t.max),Zu.distanceToSquared(e)),intersectsBounds:(t,e,n)=>n<a&&n<o,intersectsTriangle:(t,n)=>{t.closestPointToPoint(e,Zu);const i=e.distanceToSquared(Zu);return i<a&&(ju.copy(Zu),a=i,h=n),i<s}}),a===1/0)return null;const l=Math.sqrt(a);return n.point?n.point.copy(ju):n.point=ju.clone(),n.distance=l,n.faceIndex=h,n}(this,t,e,n,i)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach(e=>{Wl(0,new Float32Array(e),cd),t.union(cd)}),t}}const fd=1e-6,yd=Math.pow(10,-Math.log10(fd)),md=5e-7*yd;function gd(t){return~~(t*yd+md)}function xd(t){return`${gd(t.x)},${gd(t.y)}`}function bd(t){return`${gd(t.x)},${gd(t.y)},${gd(t.z)}`}function wd(t){return`${gd(t.x)},${gd(t.y)},${gd(t.z)},${gd(t.w)}`}function vd(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 Md(){return"undefined"!=typeof SharedArrayBuffer}function Sd(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 Ad(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 en(i,1));for(let t=0;t<n;t++)i[t]=t}}function zd(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}const _d=new St;function Td(t){return~~(t/3)}function Bd(t){return t%3}function Cd(t,e){return t.start-e.start}function Pd(t,e){return _d.subVectors(e,t.origin).dot(t.direction)}const Ed=1e-5,kd=1e-4;class Nd{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)>Ed;return t.direction.angleTo(e.direction)>kd||n}function o(t,e){const n=t.origin.distanceTo(e.origin),i=t.direction.angleTo(e.direction);return n/Ed+i/kd}}}const Id=new St,Od=new St,Fd=new Tn;function Rd(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 Nd;for(let u=0,c=h.length;u<c;u++){const t=h[u],e=Td(t),n=Bd(t);let i,o=3*e+n,c=3*e+(n+1)%3;r&&(o=r.getX(o),c=r.getX(c)),Id.fromBufferAttribute(s,o),Od.fromBufferAttribute(s,c),vd(Id,Od,Fd);let d=l.findClosestRay(Fd);null===d&&(d=Fd.clone(),l.addRay(d)),a.has(d)||a.set(d,{forward:[],reverse:[],ray:d}),i=a.get(d);let p=Pd(d,Id),f=Pd(d,Od);p>f&&([p,f]=[f,p]),Fd.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(Cd),e.sort(Cd);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 Ud=new vt,Vd=new St,Ld=new Dt,qd=["","",""];class Dd{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=gd(i.getX(t));break;case 2:r=xd(Ud.fromBufferAttribute(i,t));break;case 3:r=bd(Vd.fromBufferAttribute(i,t));break;case 4:r=wd(Ld.fromBufferAttribute(i,t))}""!==e&&(e+="|"),e+=r}return e}:function(t){return Vd.fromBufferAttribute(u,t),bd(Vd)},o=new Map,{attributes:a}=t,h=e?Object.keys(a):null,l=t.index,u=a.position;let c=zd(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)),qd[e]=s(n)}for(let e=0;e<3;e++){const n=(e+1)%3,i=qd[e],r=qd[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}=Rd(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 Xd extends Ln{constructor(...t){super(...t),this.isBrush=!0,this._previousMatrix=new Xt,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=Md();if(n)for(const i in e){const t=e[i];if(t.isInterleavedBufferAttribute)throw new Error("Brush: InterleavedBufferAttributes are not supported.");t.array=Sd(t.array)}if(t.boundsTree||(Ad(t,{useSharedArrayBuffer:n}),t.boundsTree=new pd(t,{maxLeafTris:3,indirect:!0,useSharedArrayBuffer:n})),t.halfEdges||(t.halfEdges=new Dd(t)),!t.groupIndices){const e=zd(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 Zd=new St,jd=new St,Gd=new St;function Jd(t,e=1e-14){Zd.subVectors(t.b,t.a),jd.subVectors(t.c,t.a),Gd.subVectors(t.b,t.c);const n=Zd.angleTo(jd),i=Zd.angleTo(Gd),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 Wd=1e-10,$d=1e-10,Yd=new Ki,Hd=new Ki,Qd=new St,Kd=new St,tp=new St,ep=new jn,np=new Au;class ip{constructor(){this._pool=[],this._index=0}getTriangle(){return this._index>=this._pool.length&&this._pool.push(new Fe),this._pool[this._index++]}clear(){this._index=0}reset(){this._pool.length=0,this._index=0}}class rp{constructor(){this.trianglePool=new ip,this.triangles=[],this.normal=new St,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(Qd).dot(i))>Wd)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(Kd).normalize(),Math.abs(1-Math.abs(Kd.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];Qd.subVectors(s,r).normalize(),tp.crossVectors(Kd,Qd),ep.setFromNormalAndCoplanarPoint(tp,r),this.splitByPlane(ep,t)}}else t.getPlane(ep),this.splitByPlane(ep,t)}splitByPlane(t,e){const{triangles:n,trianglePool:i}=this;np.copy(e),np.needsUpdate=!0;for(let r=0,s=n.length;r<s;r++){const e=n[r];if(!np.intersectsTriangle(e,Yd,!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;Yd.start.copy(f[n]),Yd.end.copy(f[e]);const i=t.distanceToPoint(Yd.start),r=t.distanceToPoint(Yd.end);if(Math.abs(i)<$d&&Math.abs(r)<$d){c=!0;break}if(i>0?d.push(n):p.push(n),Math.abs(i)<$d)continue;let s=!!t.intersectLine(Yd,Qd);!s&&Math.abs(r)<$d&&(Qd.copy(Yd.end),s=!0),!s||Qd.distanceTo(Yd.start)<Wd||(Qd.distanceTo(Yd.end)<Wd&&(u=n),0===l?Hd.start.copy(Qd):Hd.end.copy(Qd),l++)}if(!c&&2===l&&Hd.distance()>$d)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(Hd.end),a.c.copy(Hd.start),Jd(a)||n.push(a),e.a.copy(f[t]),e.b.copy(Hd.start),e.c.copy(Hd.end),Jd(e)&&(n.splice(r,1),r--,s--)}else{const t=d.length>=2?p[0]:d[0];if(0===t){let t=Hd.start;Hd.start=Hd.end,Hd.end=t}const o=(t+1)%3,a=(t+2)%3,h=i.getTriangle(),l=i.getTriangle();f[o].distanceToSquared(Hd.start)<f[a].distanceToSquared(Hd.end)?(h.a.copy(f[o]),h.b.copy(Hd.start),h.c.copy(Hd.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Hd.start)):(h.a.copy(f[a]),h.b.copy(Hd.start),h.c.copy(Hd.end),l.a.copy(f[o]),l.b.copy(f[a]),l.c.copy(Hd.end)),e.a.copy(f[t]),e.b.copy(Hd.end),e.c.copy(Hd.start),Jd(h)||n.push(h),Jd(l)||n.push(l),Jd(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 sp{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(Md()?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 op{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 sp(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 sp(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 ap{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 hp=new Tn,lp=new Xt,up=new Fe,cp=new St,dp=new Dt,pp=new Dt,fp=new Dt,yp=new Dt,mp=new Dt,gp=new Dt,xp=new Ki,bp=new St,wp=1e-8,vp=-1;let Mp=null;function Sp(t){Mp=t}function Ap(t,e){t.getMidpoint(hp.origin),t.getNormal(hp.direction);const n=e.raycastFirst(hp,2);return Boolean(n&&hp.direction.dot(n.face.normal)>0)?vp:1}function zp(t,e){function n(){return Math.random()-.5}t.getNormal(bp),hp.direction.copy(bp),t.getMidpoint(hp.origin);let i=0,r=1/0;for(let s=0;s<3;s++){hp.direction.x+=n()*wp,hp.direction.y+=n()*wp,hp.direction.z+=n()*wp,hp.direction.multiplyScalar(-1);const t=e.raycastFirst(hp,2);if(Boolean(t&&hp.direction.dot(t.face.normal)>0)&&i++,null!==t&&(r=Math.min(r,t.distance)),r<=1e-15)return t.face.normal.dot(bp)>0?2:-2;if(i/3>.5||(s-i+1)/3>.5)break}return i/3>.5?vp:1}function _p(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?(up.a.fromBufferAttribute(t,u).applyMatrix4(i),up.b.fromBufferAttribute(t,c).applyMatrix4(i),up.c.fromBufferAttribute(t,d).applyMatrix4(i),Cp(up.a,up.b,up.c,e,3,n,o)):"normal"===p?(up.a.fromBufferAttribute(t,u).applyNormalMatrix(r),up.b.fromBufferAttribute(t,c).applyNormalMatrix(r),up.c.fromBufferAttribute(t,d).applyNormalMatrix(r),o&&(up.a.multiplyScalar(-1),up.b.multiplyScalar(-1),up.c.multiplyScalar(-1)),Cp(up.a,up.b,up.c,e,3,n,o,!0)):(dp.fromBufferAttribute(t,u),pp.fromBufferAttribute(t,c),fp.fromBufferAttribute(t,d),Cp(dp,pp,fp,e,h,n,o))}}function Tp(t,e,n,i,r,s,o,a=!1){Pp(t,i,r,s,o,a),Pp(a?n:e,i,r,s,o,a),Pp(a?e:n,i,r,s,o,a)}function Bp(t,e,n=!1){switch(t){case 0:if(1===e||2===e&&!n)return 1;break;case 1:if(n){if(e===vp)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===vp)return 0;break;case 4:if(e===vp)return 0;if(1===e)return 1;break;case 3:if(e===vp||2===e&&!n)return 1;break;case 5:if(!n&&(1===e||-2===e))return 1;break;case 6:if(!n&&(e===vp||2===e))return 1;break;default:throw new Error(`Unrecognized CSG operation enum "${t}".`)}return 2}function Cp(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)};yp.set(0,0,0,0).addScaledVector(t,i.a.x).addScaledVector(e,i.a.y).addScaledVector(n,i.a.z),mp.set(0,0,0,0).addScaledVector(t,i.b.x).addScaledVector(e,i.b.y).addScaledVector(n,i.b.z),gp.set(0,0,0,0).addScaledVector(t,i.c.x).addScaledVector(e,i.c.y).addScaledVector(n,i.c.z),a&&(yp.normalize(),mp.normalize(),gp.normalize()),h(yp),o?(h(gp),h(mp)):(h(mp),h(gp))}function Pp(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?(cp.fromBufferAttribute(a,t).applyMatrix4(n),h.push(cp.x,cp.y,cp.z)):"normal"===o?(cp.fromBufferAttribute(a,t).applyNormalMatrix(i),s&&cp.multiplyScalar(-1),h.push(cp.x,cp.y,cp.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 Ep{constructor(t){this.triangle=(new Fe).copy(t),this.intersects={}}addTriangle(t,e){this.intersects[t]=(new Fe).copy(e)}getIntersectArray(){const t=[],{intersects:e}=this;for(const n in e)t.push(e[n]);return t}}class kp{constructor(){this.data={}}addTriangleIntersection(t,e,n,i){const{data:r}=this;r[t]||(r[t]=new Ep(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 Np{constructor(){this.enabled=!1,this.triangleIntersectsA=new kp,this.triangleIntersectsB=new kp,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(),Sp(this))}complete(){this.enabled&&Sp(null)}}const Ip=new Xt,Op=new _t,Fp=new Fe,Rp=new Fe,Up=new Fe,Vp=new Fe,Lp=[],qp=[];function Dp(t){for(const e of t)return e}function Xp(t,e,n,i,r,s={}){const{useGroups:o=!0}=s,{aIntersections:a,bIntersections:h}=function(t,e){const n=new ap,i=new ap;return lp.copy(t.matrixWorld).invert().multiply(e.matrixWorld),t.geometry.boundsTree.bvhcast(e.geometry.boundsTree,lp,{intersectsTriangles(r,s,o,a){if(!Jd(r)&&!Jd(s)){let h=r.intersectsTriangle(s,xp,!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),Mp&&(Mp.addEdge(xp),Mp.addIntersectingTriangles(o,r,a,s))}}return!1}}),{aIntersections:n,bIntersections:i}}(t,e);let l;l=o?0:-1,Zp(t,e,a,n,!1,i,r,l),jp(t,e,a,n,!1,r,l);return-1!==n.findIndex(t=>6!==t&&5!==t)&&(l=o?t.geometry.groups.length||1:-1,Zp(e,t,h,n,!0,i,r,l),jp(e,t,h,n,!0,r,l)),Lp.length=0,qp.length=0,{groups:[],materials:null}}function Zp(t,e,n,i,r,s,o,a=0){const h=t.matrixWorld.determinant()<0;Ip.copy(e.matrixWorld).invert().multiply(t.matrixWorld),Op.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);Fp.a.fromBufferAttribute(c,b).applyMatrix4(Ip),Fp.b.fromBufferAttribute(c,w).applyMatrix4(Ip),Fp.c.fromBufferAttribute(c,v).applyMatrix4(Ip),s.reset(),s.initialize(Fp);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);Rp.a.fromBufferAttribute(f,n),Rp.b.fromBufferAttribute(f,i),Rp.c.fromBufferAttribute(f,r),s.splitByTriangle(Rp)}const S=s.triangles;for(let a=0,l=S.length;a<l;a++){const l=S[a],u=s.coplanarTriangleUsed?zp(l,d):Ap(l,d);Lp.length=0,qp.length=0;for(let t=0,e=i.length;t<e;t++){const e=Bp(i[t],u,r);2!==e&&(qp.push(e),Lp.push(o[t].getGroupAttrSet(n)))}if(0!==Lp.length){Fp.getBarycoord(l.a,Vp.a),Fp.getBarycoord(l.b,Vp.b),Fp.getBarycoord(l.c,Vp.c);for(let n=0,i=Lp.length;n<i;n++){const i=Lp[n],r=0===qp[n];_p(e,Vp,t.geometry,t.matrixWorld,Op,i,h!==r)}}}}return y.length}function jp(t,e,n,i,r,s,o=0){const a=t.matrixWorld.determinant()<0;Ip.copy(e.matrixWorld).invert().multiply(t.matrixWorld),Op.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=zd(t.geometry);m<g;m++)m in n.intersectionSet||y.add(m);for(;y.size>0;){const e=Dp(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);Up.a.fromBufferAttribute(d,m).applyMatrix4(Ip),Up.b.fromBufferAttribute(d,g).applyMatrix4(Ip),Up.c.fromBufferAttribute(d,x).applyMatrix4(Ip);const b=Ap(Up,h);qp.length=0,Lp.length=0;for(let t=0,o=i.length;t<o;t++){const e=Bp(i[t],b,r);2!==e&&(qp.push(e),Lp.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!==Lp.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(Up.a.fromBufferAttribute(d,i),Up.b.fromBufferAttribute(d,r),Up.c.fromBufferAttribute(d,s),!Jd(Up))for(let e=0,o=Lp.length;e<o;e++){const n=qp[e],o=Lp[e].getGroupAttrSet(h),l=0===n;Tp(i,r,s,c,t.matrixWorld,Op,o,l!==a)}}}}}function Gp(t,e){let n=e;return Array.isArray(e)||(n=[],t.forEach(t=>{n[t.materialIndex]=e})),n}class Jp{constructor(){this.triangleSplitter=new rp,this.attributeData=[],this.attributes=["position","uv","normal"],this.useGroups=!0,this.consolidateGroups=!0,this.debug=new Np}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 Xd){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 op);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(),Xp(t,e,n,s,o,{useGroups:h}),d.complete();const p=this.getGroupRanges(t.geometry),f=Gp(p,t.material),y=this.getGroupRanges(e.geometry),m=Gp(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 en(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 Xd){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()}}class Wp extends Fl{constructor(t,e){super(t,e);const n=new Xd(new Fl(t,c(u({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const i=(new Re).setFromObject(n),r=new St;i.getSize(r);const s=new St(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 St;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;const h=new ji(r.x,r.y,o,o),l=new Xd(h);l.position.set(s.x,s.y,s.z),l.updateMatrixWorld();const d=(new Jp).evaluate(l,n,3),p=d.geometry.getAttribute("position"),f=new sn(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 St).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 Fl(t,c(u({},e),{hasTop:!1})),m=kl([d.geometry,y],2);this.copy(m.toNonIndexed())}}const $p=t=>{const{box3:e,sideBox:n}=t,i=e.getSize(new St),r=n.getSize(new St);return t.sideRepeat&&(r.z/=t.sideRepeat),{generateTopUV(t,n,r,s,o){const a=n[3*r],h=n[3*r+1],l=n[3*s],u=n[3*s+1],c=n[3*o],d=n[3*o+1];return[new vt((a-e.min.x)/i.x,(h-e.min.y)/i.y),new vt((l-e.min.x)/i.x,(u-e.min.y)/i.y),new vt((c-e.min.x)/i.x,(d-e.min.y)/i.y)]},generateSideWallUV(t,e,i,s,o,a){const h=e[3*i],l=e[3*i+1],u=e[3*i+2],c=e[3*s],d=e[3*s+1],p=e[3*s+2],f=e[3*o],y=e[3*o+1],m=e[3*o+2],g=e[3*a],x=e[3*a+1],b=e[3*a+2];return Math.abs(l-d)<Math.abs(h-c)?[new vt((h-n.min.x)/r.x,(u-n.min.z)/r.z),new vt((c-n.min.x)/r.x,(p-n.min.z)/r.z),new vt((f-n.min.x)/r.x,(m-n.min.z)/r.z),new vt((g-n.min.x)/r.x,(b-n.min.z)/r.z)]:[new vt((l-n.min.y)/r.y,(u-n.min.z)/r.z),new vt((d-n.min.y)/r.y,(p-n.min.z)/r.z),new vt((y-n.min.y)/r.y,(m-n.min.z)/r.z),new vt((x-n.min.y)/r.y,(b-n.min.z)/r.z)]}}};var Yp=Math.abs,Hp=Math.cos,Qp=Math.sin,Kp=1e-6,tf=Math.PI,ef=tf/2;function nf(t){return t>1?0:t<-1?tf:Math.acos(t)}function rf(t){return t>0?Math.sqrt(t):0}function sf(t,e){var n=Hp(e),i=function(t){return t?t/Math.sin(t):1}(nf(n*Hp(t/=2)));return[2*n*Qp(t)*i,Qp(e)*i]}function of(t,e){var n=sf(t,e);return[(n[0]+t/ef)/2,(n[1]+e)/2]}of.invert=(t,e)=>{var n=t,i=e,r=25;do{var s,o=Hp(i),a=Qp(i),h=Qp(2*i),l=a*a,u=o*o,c=Qp(n),d=Hp(n/2),p=Qp(n/2),f=p*p,y=1-u*d*d,m=y?nf(o*d)*rf(s=1/y):s=0,g=.5*(2*m*o*p+n/ef)-t,x=.5*(m*a+i)-e,b=.5*s*(u*f+m*o*d*l)+.5/ef,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((Yp(A)>Kp||Yp(z)>Kp)&&--r>0);return[n,i]};const af={mercator:function(){return function(t){var e,n,i,r=xa(t),s=r.center,o=r.scale,a=r.translate,h=r.clipExtent,l=null;function u(){var s=_r*o(),a=r(vo(r.rotate()).invert([0,0]));return h(null==l?[[a[0]-s,a[1]-s],[a[0]+s,a[1]+s]]:t===ba?[[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()}(ba).scale(961/Cr)},equirectangular:function(){return xa(wa).scale(152.63)},winkel3:function(){return xa(of).scale(158.837)}},hf=t=>{var e,n,i;const r=af[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),r},lf=(t,e)=>t.map(t=>{let n;if(e){const[i,r]=e([...t]);n=new vt(i,-r)}else n=new vt(...t);return n});function uf(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&&n[s]&&r.push(n[s],n[s])}else i.push(t),n&&n[s]&&r.push(n[s])}),{splitPolygons:i,splitMeta:r}}function cf({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,bbox:r,projection:s,hasTop:o,hasBottom:a,hasSide:h,splitPolygons:l,topSegments:d}){const p=s&&hf(s);let f,y=e||(t?t.map(t=>lf(t,p)):[]),m=n;if(l){const t=uf(y,l,n);y=t.splitPolygons,m=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;lf([[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?hf(c(u({},s),{rotate:void 0})):p,"winkel3"===(null==s?void 0:s.projectionType)?10:0);f=new Re(new St(e[0],e[1],0),new St(n[0],n[1],0))}return y.map((t,e)=>{var n,r,s;const l=(null==m?void 0:m[e])||i||[],u=null!=(n=l[0])?n:0,c=null!=(r=l[1])?r:0,p=(t=>{const{depth:e,points:n,box3:i,hasTop:r,hasBottom:s,hasSide:o,sideRepeat:a,topSegments:h}=t,l=h?Wp:Fl;let u=i;if(!u){u=new Re;const t=n.flatMap(t=>[t.x,t.y,0]);u.setFromArray(t)}const c=u.clone();return c.min.z=0,c.max.z=e,new l(new fi(n),{depth:e,bevelEnabled:!1,box3:u,UVGenerator:$p({box3:u,sideBox:c,sideRepeat:a}),hasTop:r,hasBottom:s,hasSide:o,topSegments:h})})({points:t,sideRepeat:null!=(s=l[2])?s:1,depth:u,hasTop:o,hasBottom:a,hasSide:h,box3:f,topSegments:d});if(c){const t=p.attributes.position;for(let e=0;e<t.count;e++)t.setZ(e,t.getZ(e)+c);t.needsUpdate=!0}return p})}function df({coordinatesArr:t,pointsArr:e,metaArray:n,globalMeta:i,projection:r,splitPolygons:s}){const o=r&&hf(r);let a=e||(t?t.map(t=>((t,e)=>t.map(t=>{let n;if(e){const[i,r]=e([...t]);n=new St(i,-r,0)}else n=new St(...t);return n}))(t,o)):[]),h=n;if(s){const t=uf(a,s,h);a=t.splitPolygons,h=t.splitMeta}return a.map((t,e)=>{var n;const r=null!=(n=((null==h?void 0:h[e])||i||[])[0])?n:1;return Bl({nodes:t,setPointWidth:()=>r})})}(e=>{const n={run(t,e){const n=new Function("return ("+t+").apply(null, arguments);");return n.apply(n,e)},methods:()=>Object.keys(n)};addEventListener("message",e=>((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,[e],function*({data:e}){try{const t=n[e.method];if(!t)throw new Error(\'Unknown method "\'+e.method+\'"\');{const n=yield t.apply(t,e.params);n.transfer&&n.message?postMessage({id:e.id,result:n.message,error:null},n.transfer):postMessage({id:e.id,result:n,error:null})}}catch(i){postMessage({id:e.id,result:null,error:t(i)})}})),Object.keys(e).forEach(t=>{n[t]=e[t]}),postMessage("ready")})({extrudePolygon:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,dimension:s=2,useGroups:o,projection:a}=e,h=d(e,["coordinates","lengths","metaLength","dimension","useGroups","projection"]);const l=((t,e,n=2,i)=>{const r=new Array(e.length);let s=0;const o=[0,0];for(let a=0;a<e.length;a++){const h=e[a],l=new Array(h);for(let e=0;e<h;e++){let r=t[s],a=t[s+1];if(i){o[0]=r,o[1]=a;const t=i(o);t&&(r=t[0],a=t[1]),l[e]=new vt(r,-a)}else l[e]=new vt(r,a);s+=n}r[a]=l}return r})(n,i,s,a?hf(a):void 0),c=Cl(n,i,r,s),p=cf(u({pointsArr:l,metaArray:c,projection:a},h));return Nl(p,o)},line:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,dimension:s=2,useGroups:o,projection:a}=e,h=d(e,["coordinates","lengths","metaLength","dimension","useGroups","projection"]);const l=((t,e,n=2,i)=>{const r=new Array(e.length);let s=0;const o=[0,0];for(let a=0;a<e.length;a++){const h=e[a],l=new Array(h);for(let e=0;e<h;e++){let r=t[s],a=t[s+1];if(i){o[0]=r,o[1]=a;const t=i(o);t&&(r=t[0],a=t[1]),l[e]=new St(r,-a,0)}else{const i=3===n?t[s+2]:0;l[e]=new St(r,a,i)}s+=n}r[a]=l}return r})(n,i,s,a?hf(a):void 0),c=Cl(n,i,r,s),p=df(u({pointsArr:l,metaArray:c,projection:a},h));return Nl(p,o)},conicPolygon:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,useGroups:s}=e,o=d(e,["coordinates","lengths","metaLength","useGroups"]);const{coordinatesArr:a,metaArray:h}=Pl({coordinates:n,lengths:i,metaLength:r}),l=Il(u({coordinatesArr:a,metaArray:h},o));return Nl(l,s)},conicLine:t=>{var e=t,{coordinates:n,lengths:i,metaLength:r,useGroups:s}=e,o=d(e,["coordinates","lengths","metaLength","useGroups"]);const{coordinatesArr:a,metaArray:h}=Pl({coordinates:n,lengths:i,metaLength:r}),l=function({coordinatesArr:t,metaArray:e,globalMeta:n,projection:i="sphere",useRTC:r=!1}){let s;return t.map((t,r)=>{var s;const o=null!=(s=(e&&e[r]||n||[])[1])?s:0;return zl({polygonGeoJson:[t],startHeight:o,projection:i}).topVerts}).map((t,i)=>{var o;const a=null!=(o=(e&&e[i]||n||[])[0])?o:1,h=Bl({nodes:t,setPointWidth:()=>a,useRTC:r,rtcCenter:s});return 0===i&&(s=h.getRTCCenter()),h})}(u({coordinatesArr:a,metaArray:h},o));return Nl(l,s)}})}();\n',tr="undefined"!=typeof self&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Qs],{type:"text/javascript;charset=utf-8"});function er(t){let e;try{if(e=tr&&(self.URL||self.webkitURL).createObjectURL(tr),!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(Qs),{name:null==t?void 0:t.name})}}class nr{constructor(t){u(this,"options"),u(this,"pool"),u(this,"cacheManager"),this.options=h({dbName:"pencil_cache",cacheVersion:"1",maxCacheSize:100},t),this.cacheManager=new on({dbName:this.options.dbName,maxCacheSize:this.options.maxCacheSize,cacheVersion:this.options.cacheVersion});const e=new Re(er,{maxWorkers:this.options.maxWorkers});this.pool=e}geoGeometry(t,e){return d(this,null,function*(){const{mesaage:n,coordinatesArr:i,metaArray:s,globalMeta:r,cacheKey:o,userData:a,cb:l,useFloat64Array:c}=h(h({},this.options),e),u=this.pool,{flat:d,lengths:p,metaLength:f}=this.flattenCoordinates(i,s,r,c),{err:m,res:y}=yield u.exec(t,[h(h({coordinates:d,lengths:p,metaLength:f},n),r?{globalMeta:r}:{})],{on:()=>{},transfer:[d.buffer]},!0);if(m)throw m;const g=Ks(y);return Object.assign(g.userData,h({},a)),l&&(yield l(g)),o&&this.cacheManager.addToCache(o,h({attributes:y},a)),g})}getCachedGeometry(t){return d(this,null,function*(){const{cacheKey:e}=t;if(e){const t=yield this.cacheManager.get(e);if(t){this.cacheManager.recordMetadataUpdate(e);const n=t,{attributes:i}=n,s=c(n,["attributes"]),r=Ks(i);return Object.assign(r.userData,h({},s)),r}return null}return null})}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,i=!1){const s=t.length,r=new Array(s);let o=0;for(let d=0;d<s;d++){const e=t[d].length;r[d]=e,o+=e}let a=0;const h=e&&e.length>0;let l=0;h&&(a=e[0].length,l=e.length*a);const c=i?new Float64Array(2*o+l):new Float32Array(2*o+l);let u=0;for(let d=0;d<s;d++){const e=t[d];for(let t=0;t<e.length;t++){const n=e[t];c[u++]=n[0],c[u++]=n[1]}}if(h)for(let d=0;d<e.length;d++){const t=e[d];for(let e=0;e<t.length;e++)c[u++]=t[e]}return{flat:c,lengths:r,metaLength:a}}dispose(){this.cacheManager.dispose(),this.pool.dispose(),this.pool.workers.length=0}}const ir=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 yt),u(this,"maxBackufferArea",33177600),u(this,"installPlugins",/* @__PURE__ */new Map),u(this,"attributesWorker"),u(this,"_cameraPositon",new y),u(this,"_cameraTarget",new y),u(this,"event",new p),u(this,"timer",new Ut),u(this,"userData",{}),u(this,"TweenRaf"),u(this,"pageActiveIndex",0),u(this,"pages",new Ie),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:_n}),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(),this.attributesWorker=new nr({cacheVersion:this.options.attributesWorkerVersion})}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(){Nt.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 Js({width:c,height:u,renderer:this.options.WebGPURenderer,rendererParams:Ys}):new Zs({width:c,height:u,rendererParams:l(h({},r),{antialias:!1})});this.rendererController=d;const p=new He({width:c,height:u}),f=new Xs({}),m=new As({controlsParams:{domElement:null!=(t=null==o?void 0:o.domElement)?t:d.renderer.domElement}}),y=new Vs({loaderParams:h({anisotropy:this.maxAnisotropy},a)}),g=new qs({pencil:this}),x=new Ds({pencil:this});this.sceneController=f,this.cameraController=p,this.controlsController=m,this.loaderController=y,this.mListController=g,this.leadController=x;const v=this.addPage({sceneOptions:this.options.scene,cameraOptions:this.options.camera});if(this.showPage(v),i){const t=new zs({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 zi({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 Os(t,i);e&&r.addRenderer("css2d",i),n&&r.addRenderer("css3d",s),this.cssRendererController=r}}initTransformControls(){const t=new $s({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 j);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 j),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 j,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(),Nt.update();const o=this.timer.getDelta(),a=this.timer.getElapsed();this.controlsController.update(o,a),this.cameraController.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),this.leadController.update(o,a),(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(),Nt.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.attributesWorker.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(ir,"options",{stats:Fe,helper:Fe,viewHelper:Fe,controls:!0,transformControls:Fe,renderer:Gs,composer:{multisampling:4,premultiplieAlpha:!1},scene:{background:null},camera:We,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({},Cs),css3DRenderer:!1,css3DRendererParams:h({},Cs),attributesWorkerVersion:"1"});let sr=ir;const rr={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 j(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 xt(0,0,0,0)},color:{value:new at(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=ke(!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 Nt.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 xt(0,0,0,1e-4)},color:{value:new at(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=ke(!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 Nt.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()}}},or=Ss.ACTION;export{Ln as AmbientLightObject,Cn as BaseObject,kn as CSS2DObjectObject,Rn as CSS3DObjectObject,Bn as CSS3DSpriteObject,Dn as DirectionalLightObject,Wn as EllipsoidObject,hi as ExtrudePolygonObject,On as GroupObject,Fn as HemisphereLightObject,jn as InstancedMeshObject,Ht as Line2Material,yi as LineObject,qt as LineSegmentsGeometry,li as MeshLineGeometry,ci as MeshLineMaterial,ui as MeshLineRaycast,zn as MeshObject,xi as NodeObject,sr as Pencil,vi as PieObject,Un as PointLightObject,En as PointsObject,Vn as RectAreaLightObject,qe as ResourceTracker,Nn as SpotLightObject,Pn as SpriteObject,or as cameraControlsAction,sr as default,rr as effect,Sn as utils};
|