@qaecy/cue-ui 0.0.18 → 0.0.20
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/419.js +1 -1
- package/js/worker.mjs +7 -0
- package/package.json +3 -2
package/js/worker.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
var t,e,s,i,r,n,o,a,h,l,c,u,d,p,f,m,_,b,g,y,x,w,v,S,M,A,I,C,z,T,P,B,E,F,R,k,V,L,O,D,U,N,W,H,q,Z,G,j,X,Y,J,Q,$,K,tt,et,st,it,rt,nt=Object.defineProperty,ot=(t,e,s)=>(((t,e,s)=>{e in t?nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(t,"symbol"!=typeof e?e+"":e,s),s),at=(t,e,s)=>{if(!e.has(t))throw TypeError("Cannot "+s)},ht=(t,e,s)=>(at(t,e,"read from private field"),s?s.call(t):e.get(t)),lt=(t,e,s)=>{if(e.has(t))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(t):e.set(t,s)},ct=(t,e,s,i)=>(at(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),ut=(t,e,s,i)=>({set _(i){ct(t,e,i,s)},get _(){return ht(t,e,i)}}),dt=(t,e,s)=>(at(t,e,"access private method"),s);class pt{constructor(){ot(this,"_list",new Map),ot(this,"_communicationKey",0)}setupInput(t){t.requestId=this._communicationKey++}set(t,e,s){const i=this.newHandler(e,s);this._list.set(t,i)}run(t){const e=this._list.get(t.requestId);this._list.delete(t.requestId),e(t)}newHandler(t,e){return s=>{s.errorInfo?t(s.errorInfo):e(s)}}}
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2010-2025 Three.js Authors
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/const ft=1001,mt="srgb",_t="srgb-linear",bt="linear",gt="srgb",yt=7680,xt=2e3,wt=2001;class vt{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){const s=this._listeners;return void 0!==s&&(void 0!==s[t]&&-1!==s[t].indexOf(e))}removeEventListener(t,e){const s=this._listeners;if(void 0===s)return;const i=s[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 s=e[t.type];if(void 0!==s){t.target=this;const e=s.slice(0);for(let s=0,i=e.length;s<i;s++)e[s].call(this,t);t.target=null}}}const St=["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"];function Mt(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,s=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(St[255&t]+St[t>>8&255]+St[t>>16&255]+St[t>>24&255]+"-"+St[255&e]+St[e>>8&255]+"-"+St[e>>16&15|64]+St[e>>24&255]+"-"+St[63&s|128]+St[s>>8&255]+"-"+St[s>>16&255]+St[s>>24&255]+St[255&i]+St[i>>8&255]+St[i>>16&255]+St[i>>24&255]).toLowerCase()}function At(t,e,s){return Math.max(e,Math.min(s,t))}function It(t,e,s){return(1-s)*t+s*e}function Ct(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 zt(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.")}}class Tt{constructor(t=0,e=0){Tt.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,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+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=At(this.x,t.x,e.x),this.y=At(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=At(this.x,t,e),this.y=At(this.y,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(At(s,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 s=this.dot(t)/e;return Math.acos(At(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,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 s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Pt{constructor(t,e,s,i,r,n,o,a,h){Pt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,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]=s,l[7]=n,l[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.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 s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],l=s[4],c=s[7],u=s[2],d=s[5],p=s[8],f=i[0],m=i[3],_=i[6],b=i[1],g=i[4],y=i[7],x=i[2],w=i[5],v=i[8];return r[0]=n*f+o*b+a*x,r[3]=n*m+o*g+a*w,r[6]=n*_+o*y+a*v,r[1]=h*f+l*b+c*x,r[4]=h*m+l*g+c*w,r[7]=h*_+l*y+c*v,r[2]=u*f+d*b+p*x,r[5]=u*m+d*g+p*w,r[8]=u*_+d*y+p*v,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],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8];return e*n*l-e*o*h-s*r*l+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=l*n-o*h,u=o*a-l*r,d=h*r-n*a,p=e*c+s*u+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=c*f,t[1]=(i*h-l*s)*f,t[2]=(o*s-i*n)*f,t[3]=u*f,t[4]=(l*e-i*a)*f,t[5]=(i*r-o*e)*f,t[6]=d*f,t[7]=(s*a-h*e)*f,t[8]=(n*e-s*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,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(Bt.makeScale(t,e)),this}rotate(t){return this.premultiply(Bt.makeRotation(-t)),this}translate(t,e){return this.premultiply(Bt.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),s=Math.sin(t);return this.set(e,-s,0,s,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,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const Bt=new Pt;function Et(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const Ft=(new Pt).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Rt=(new Pt).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function kt(){const t={enabled:!0,workingColorSpace:_t,spaces:{},convert:function(t,e,s){return!1!==this.enabled&&e!==s&&e&&s?(this.spaces[e].transfer===gt&&(t.r=Lt(t.r),t.g=Lt(t.g),t.b=Lt(t.b)),this.spaces[e].primaries!==this.spaces[s].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[s].fromXYZ)),this.spaces[s].transfer===gt&&(t.r=Ot(t.r),t.g=Ot(t.g),t.b=Ot(t.b)),t):t},fromWorkingColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return""===t?bt:this.spaces[t].transfer},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,s){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[s].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}},e=[.64,.33,.3,.6,.15,.06],s=[.2126,.7152,.0722],i=[.3127,.329];return t.define({[_t]:{primaries:e,whitePoint:i,transfer:bt,toXYZ:Ft,fromXYZ:Rt,luminanceCoefficients:s,workingColorSpaceConfig:{unpackColorSpace:mt},outputColorSpaceConfig:{drawingBufferColorSpace:mt}},[mt]:{primaries:e,whitePoint:i,transfer:gt,toXYZ:Ft,fromXYZ:Rt,luminanceCoefficients:s,outputColorSpaceConfig:{drawingBufferColorSpace:mt}}}),t}const Vt=kt();function Lt(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function Ot(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let Dt;class Ut{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let s;if(t instanceof HTMLCanvasElement)s=t;else{void 0===Dt&&(Dt=Et("canvas")),Dt.width=t.width,Dt.height=t.height;const e=Dt.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),s=Dt}return s.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=Et("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*Lt(r[t]/255);return s.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*Lt(e[t]/255)):e[t]=Lt(e[t]);return{data:e,width:t.width,height:t.height}}return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Nt=0;class Wt{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Nt++}),this.uuid=Mt(),this.data=t,this.dataReady=!0,this.version=0}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 s={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,s=i.length;e<s;e++)i[e].isDataTexture?t.push(Ht(i[e].image)):t.push(Ht(i[e]))}else t=Ht(i);s.url=t}return e||(t.images[this.uuid]=s),s}}function Ht(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Ut.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let qt=0;class Zt extends vt{constructor(t=Zt.DEFAULT_IMAGE,e=Zt.DEFAULT_MAPPING,s=1001,i=1001,r=1006,n=1008,o=1023,a=1009,h=Zt.DEFAULT_ANISOTROPY,l=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:qt++}),this.uuid=Mt(),this.name="",this.source=new Wt(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=r,this.minFilter=n,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new Tt(0,0),this.repeat=new Tt(1,1),this.center=new Tt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Pt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=l,this.userData={},this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}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)}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.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const s={metadata:{version:4.6,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&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}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 ft: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 ft: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++}}Zt.DEFAULT_IMAGE=null,Zt.DEFAULT_MAPPING=300,Zt.DEFAULT_ANISOTROPY=1;class Gt{constructor(t=0,e=0,s=0,i=1){Gt.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,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,s,i){return this.x=t,this.y=e,this.z=s,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,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[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,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],l=a[4],c=a[8],u=a[1],d=a[5],p=a[9],f=a[2],m=a[6],_=a[10];if(Math.abs(l-u)<n&&Math.abs(c-f)<n&&Math.abs(p-m)<n){if(Math.abs(l+u)<o&&Math.abs(c+f)<o&&Math.abs(p+m)<o&&Math.abs(h+d+_-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,b=(_+1)/2,g=(l+u)/4,y=(c+f)/4,x=(p+m)/4;return t>a&&t>b?t<n?(s=0,i=.707106781,r=.707106781):(s=Math.sqrt(t),i=g/s,r=y/s):a>b?a<n?(s=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),s=g/i,r=x/i):b<n?(s=.707106781,i=.707106781,r=0):(r=Math.sqrt(b),s=y/r,i=x/r),this.set(s,i,r,e),this}let b=Math.sqrt((m-p)*(m-p)+(c-f)*(c-f)+(u-l)*(u-l));return Math.abs(b)<.001&&(b=1),this.x=(m-p)/b,this.y=(c-f)/b,this.z=(u-l)/b,this.w=Math.acos((h+d+_-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=At(this.x,t.x,e.x),this.y=At(this.y,t.y,e.y),this.z=At(this.z,t.z,e.z),this.w=At(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=At(this.x,t,e),this.y=At(this.y,t,e),this.z=At(this.z,t,e),this.w=At(this.w,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(At(s,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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,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 jt{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let a=s[i+0],h=s[i+1],l=s[i+2],c=s[i+3];const u=r[n+0],d=r[n+1],p=r[n+2],f=r[n+3];if(0===o)return t[e+0]=a,t[e+1]=h,t[e+2]=l,void(t[e+3]=c);if(1===o)return t[e+0]=u,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(c!==f||a!==u||h!==d||l!==p){let t=1-o;const e=a*u+h*d+l*p+c*f,s=e>=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+u*r,h=h*t+d*r,l=l*t+p*r,c=c*t+f*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+l*l+c*c);a*=t,h*=t,l*=t,c*=t}}t[e]=a,t[e+1]=h,t[e+2]=l,t[e+3]=c}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],l=s[i+3],c=r[n],u=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+l*c+a*d-h*u,t[e+1]=a*p+l*u+h*c-o*d,t[e+2]=h*p+l*d+o*u-a*c,t[e+3]=l*p-o*c-a*u-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,s,i){return this._x=t,this._y=e,this._z=s,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 s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),l=o(i/2),c=o(r/2),u=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"YXZ":this._x=u*l*c+h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"ZXY":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c-u*d*p;break;case"ZYX":this._x=u*l*c-h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c+u*d*p;break;case"YZX":this._x=u*l*c+h*d*p,this._y=h*d*c+u*l*p,this._z=h*l*p-u*d*c,this._w=h*l*c-u*d*p;break;case"XZY":this._x=u*l*c-h*d*p,this._y=h*d*c-u*l*p,this._z=h*l*p+u*d*c,this._w=h*l*c+u*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],l=e[6],c=e[10],u=s+o+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(l-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>c){const t=2*Math.sqrt(1+s-o-c);this._w=(l-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>c){const t=2*Math.sqrt(1+o-s-c);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+l)/t}else{const t=2*Math.sqrt(1+c-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+l)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(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=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(At(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);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 s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,l=e._w;return this._x=s*l+n*o+i*h-r*a,this._y=i*l+n*a+r*o-s*h,this._z=r*l+n*h+s*a-i*o,this._w=n*l-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),l=Math.atan2(h,o),c=Math.sin((1-e)*l)/h,u=Math.sin(e*l)/h;return this._w=n*c+this._w*u,this._x=s*c+this._x*u,this._y=i*c+this._y*u,this._z=r*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);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 Xt{constructor(t=0,e=0,s=0){Xt.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,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(Jt.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Jt.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),l=2*(o*e-r*i),c=2*(r*s-n*e);return this.x=e+a*h+n*c-o*l,this.y=s+a*l+o*h-r*c,this.z=i+a*c+r*l-n*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,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+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=At(this.x,t.x,e.x),this.y=At(this.y,t.y,e.y),this.z=At(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=At(this.x,t,e),this.y=At(this.y,t,e),this.z=At(this.z,t,e),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(At(s,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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Yt.copy(this).projectOnVector(t),this.sub(Yt)}reflect(t){return this.sub(Yt.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 s=this.dot(t)/e;return Math.acos(At(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+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,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,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(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,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,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Yt=new Xt,Jt=new jt;class Qt{constructor(t=new Xt(1/0,1/0,1/0),e=new Xt(-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,s=t.length;e<s;e+=3)this.expandByPoint(Kt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Kt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Kt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),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 s=t.geometry;if(void 0!==s){const i=s.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,s=i.count;e<s;e++)!0===t.isMesh?t.getVertexPosition(e,Kt):Kt.fromBufferAttribute(i,e),Kt.applyMatrix4(t.matrixWorld),this.expandByPoint(Kt);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),te.copy(t.boundingBox)):(null===s.boundingBox&&s.computeBoundingBox(),te.copy(s.boundingBox)),te.applyMatrix4(t.matrixWorld),this.union(te)}const i=t.children;for(let t=0,s=i.length;t<s;t++)this.expandByObject(i[t],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,Kt),Kt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(ae),he.subVectors(this.max,ae),ee.subVectors(t.a,ae),se.subVectors(t.b,ae),ie.subVectors(t.c,ae),re.subVectors(se,ee),ne.subVectors(ie,se),oe.subVectors(ee,ie);let e=[0,-re.z,re.y,0,-ne.z,ne.y,0,-oe.z,oe.y,re.z,0,-re.x,ne.z,0,-ne.x,oe.z,0,-oe.x,-re.y,re.x,0,-ne.y,ne.x,0,-oe.y,oe.x,0];return!!ue(e,ee,se,ie,he)&&(e=[1,0,0,0,1,0,0,0,1],!!ue(e,ee,se,ie,he)&&(le.crossVectors(re,ne),e=[le.x,le.y,le.z],ue(e,ee,se,ie,he)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Kt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Kt).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()||($t[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),$t[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),$t[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),$t[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),$t[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),$t[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),$t[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),$t[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints($t)),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)}}const $t=[new Xt,new Xt,new Xt,new Xt,new Xt,new Xt,new Xt,new Xt],Kt=new Xt,te=new Qt,ee=new Xt,se=new Xt,ie=new Xt,re=new Xt,ne=new Xt,oe=new Xt,ae=new Xt,he=new Xt,le=new Xt,ce=new Xt;function ue(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){ce.fromArray(t,n);const o=r.x*Math.abs(ce.x)+r.y*Math.abs(ce.y)+r.z*Math.abs(ce.z),a=e.dot(ce),h=s.dot(ce),l=i.dot(ce);if(Math.max(-Math.max(a,h,l),Math.min(a,h,l))>o)return!1}return!0}const de=new Qt,pe=new Xt,fe=new Xt;class me{constructor(t=new Xt,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 s=this.center;void 0!==e?s.copy(e):de.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;e<r;e++)i=Math.max(i,s.distanceToSquared(t[e]));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 s=this.center.distanceToSquared(t);return e.copy(t),s>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;pe.subVectors(t,this.center);const e=pe.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(pe,s/t),this.radius+=s}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):(fe.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(pe.copy(t.center).add(fe)),this.expandByPoint(pe.copy(t.center).sub(fe))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const _e=new Xt,be=new Xt,ge=new Xt,ye=new Xt,xe=new Xt,we=new Xt,ve=new Xt;class Se{constructor(t=new Xt,e=new Xt(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,_e)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=_e.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(_e.copy(this.origin).addScaledVector(this.direction,e),_e.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){be.copy(t).add(e).multiplyScalar(.5),ge.copy(e).sub(t).normalize(),ye.copy(this.origin).sub(be);const r=.5*t.distanceTo(e),n=-this.direction.dot(ge),o=ye.dot(this.direction),a=-ye.dot(ge),h=ye.lengthSq(),l=Math.abs(1-n*n);let c,u,d,p;if(l>0)if(c=n*a-o,u=n*o-a,p=r*l,c>=0)if(u>=-p)if(u<=p){const t=1/l;c*=t,u*=t,d=c*(c+n*u+2*o)+u*(n*c+u+2*a)+h}else u=r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;else u=-r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;else u<=-p?(c=Math.max(0,-(-n*r+o)),u=c>0?-r:Math.min(Math.max(-r,-a),r),d=-c*c+u*(u+2*a)+h):u<=p?(c=0,u=Math.min(Math.max(-r,-a),r),d=u*(u+2*a)+h):(c=Math.max(0,-(n*r+o)),u=c>0?r:Math.min(Math.max(-r,-a),r),d=-c*c+u*(u+2*a)+h);else u=n>0?-r:r,c=Math.max(0,-(n*u+o)),d=-c*c+u*(u+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,c),i&&i.copy(be).addScaledVector(ge,u),d}intersectSphere(t,e){_e.subVectors(t.center,this.origin);const s=_e.dot(this.direction),i=_e.dot(_e)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return 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 s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,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 s,i,r,n,o,a;const h=1/this.direction.x,l=1/this.direction.y,c=1/this.direction.z,u=this.origin;return h>=0?(s=(t.min.x-u.x)*h,i=(t.max.x-u.x)*h):(s=(t.max.x-u.x)*h,i=(t.min.x-u.x)*h),l>=0?(r=(t.min.y-u.y)*l,n=(t.max.y-u.y)*l):(r=(t.max.y-u.y)*l,n=(t.min.y-u.y)*l),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),c>=0?(o=(t.min.z-u.z)*c,a=(t.max.z-u.z)*c):(o=(t.max.z-u.z)*c,a=(t.min.z-u.z)*c),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(s>=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,_e)}intersectTriangle(t,e,s,i,r){xe.subVectors(e,t),we.subVectors(s,t),ve.crossVectors(xe,we);let n,o=this.direction.dot(ve);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}ye.subVectors(this.origin,t);const a=n*this.direction.dot(we.crossVectors(ye,we));if(a<0)return null;const h=n*this.direction.dot(xe.cross(ye));if(h<0)return null;if(a+h>o)return null;const l=-n*ye.dot(ve);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 Me{constructor(t,e,s,i,r,n,o,a,h,l,c,u,d,p,f,m){Me.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,s,i,r,n,o,a,h,l,c,u,d,p,f,m)}set(t,e,s,i,r,n,o,a,h,l,c,u,d,p,f,m){const _=this.elements;return _[0]=t,_[4]=e,_[8]=s,_[12]=i,_[1]=r,_[5]=n,_[9]=o,_[13]=a,_[2]=h,_[6]=l,_[10]=c,_[14]=u,_[3]=d,_[7]=p,_[11]=f,_[15]=m,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 Me).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[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,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/Ae.setFromMatrixColumn(t,0).length(),r=1/Ae.setFromMatrixColumn(t,1).length(),n=1/Ae.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),l=Math.cos(r),c=Math.sin(r);if("XYZ"===t.order){const t=n*l,s=n*c,i=o*l,r=o*c;e[0]=a*l,e[4]=-a*c,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*l,s=a*c,i=h*l,r=h*c;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*c,e[5]=n*l,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*l,s=a*c,i=h*l,r=h*c;e[0]=t-r*o,e[4]=-n*c,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*l,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*l,s=n*c,i=o*l,r=o*c;e[0]=a*l,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*c,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*l,e[4]=r-t*c,e[8]=i*c+s,e[1]=c,e[5]=n*l,e[9]=-o*l,e[2]=-h*l,e[6]=s*c+i,e[10]=t-r*c}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*l,e[4]=-c,e[8]=h*l,e[1]=t*c+r,e[5]=n*l,e[9]=s*c-i,e[2]=i*c-s,e[6]=o*l,e[10]=r*c+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(Ce,t,ze)}lookAt(t,e,s){const i=this.elements;return Be.subVectors(t,e),0===Be.lengthSq()&&(Be.z=1),Be.normalize(),Te.crossVectors(s,Be),0===Te.lengthSq()&&(1===Math.abs(s.z)?Be.x+=1e-4:Be.z+=1e-4,Be.normalize(),Te.crossVectors(s,Be)),Te.normalize(),Pe.crossVectors(Be,Te),i[0]=Te.x,i[4]=Pe.x,i[8]=Be.x,i[1]=Te.y,i[5]=Pe.y,i[9]=Be.y,i[2]=Te.z,i[6]=Pe.z,i[10]=Be.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],l=s[1],c=s[5],u=s[9],d=s[13],p=s[2],f=s[6],m=s[10],_=s[14],b=s[3],g=s[7],y=s[11],x=s[15],w=i[0],v=i[4],S=i[8],M=i[12],A=i[1],I=i[5],C=i[9],z=i[13],T=i[2],P=i[6],B=i[10],E=i[14],F=i[3],R=i[7],k=i[11],V=i[15];return r[0]=n*w+o*A+a*T+h*F,r[4]=n*v+o*I+a*P+h*R,r[8]=n*S+o*C+a*B+h*k,r[12]=n*M+o*z+a*E+h*V,r[1]=l*w+c*A+u*T+d*F,r[5]=l*v+c*I+u*P+d*R,r[9]=l*S+c*C+u*B+d*k,r[13]=l*M+c*z+u*E+d*V,r[2]=p*w+f*A+m*T+_*F,r[6]=p*v+f*I+m*P+_*R,r[10]=p*S+f*C+m*B+_*k,r[14]=p*M+f*z+m*E+_*V,r[3]=b*w+g*A+y*T+x*F,r[7]=b*v+g*I+y*P+x*R,r[11]=b*S+g*C+y*B+x*k,r[15]=b*M+g*z+y*E+x*V,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],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],l=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+r*a*c-i*h*c-r*o*u+s*h*u+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*u+r*n*u-i*n*d+i*h*l-r*a*l)+t[11]*(+e*h*c-e*o*d-r*n*c+s*n*d+r*o*l-s*h*l)+t[15]*(-i*o*l-e*a*c+e*o*u+i*n*c-s*n*u+s*a*l)}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,s){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]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],l=t[8],c=t[9],u=t[10],d=t[11],p=t[12],f=t[13],m=t[14],_=t[15],b=c*m*h-f*u*h+f*a*d-o*m*d-c*a*_+o*u*_,g=p*u*h-l*m*h-p*a*d+n*m*d+l*a*_-n*u*_,y=l*f*h-p*c*h+p*o*d-n*f*d-l*o*_+n*c*_,x=p*c*a-l*f*a-p*o*u+n*f*u+l*o*m-n*c*m,w=e*b+s*g+i*y+r*x;if(0===w)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const v=1/w;return t[0]=b*v,t[1]=(f*u*r-c*m*r-f*i*d+s*m*d+c*i*_-s*u*_)*v,t[2]=(o*m*r-f*a*r+f*i*h-s*m*h-o*i*_+s*a*_)*v,t[3]=(c*a*r-o*u*r-c*i*h+s*u*h+o*i*d-s*a*d)*v,t[4]=g*v,t[5]=(l*m*r-p*u*r+p*i*d-e*m*d-l*i*_+e*u*_)*v,t[6]=(p*a*r-n*m*r-p*i*h+e*m*h+n*i*_-e*a*_)*v,t[7]=(n*u*r-l*a*r+l*i*h-e*u*h-n*i*d+e*a*d)*v,t[8]=y*v,t[9]=(p*c*r-l*f*r-p*s*d+e*f*d+l*s*_-e*c*_)*v,t[10]=(n*f*r-p*o*r+p*s*h-e*f*h-n*s*_+e*o*_)*v,t[11]=(l*o*r-n*c*r-l*s*h+e*c*h+n*s*d-e*o*d)*v,t[12]=x*v,t[13]=(l*f*i-p*c*i+p*s*u-e*f*u-l*s*m+e*c*m)*v,t[14]=(p*o*i-n*f*i-p*s*a+e*f*a+n*s*m-e*o*m)*v,t[15]=(n*c*i-l*o*i+l*s*a-e*c*a-n*s*u+e*o*u)*v,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,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],s=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,s,i))}makeTranslation(t,e,s){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,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,l=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,l*o+s,l*a-i*n,0,h*a-i*o,l*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,l=n+n,c=o+o,u=r*h,d=r*l,p=r*c,f=n*l,m=n*c,_=o*c,b=a*h,g=a*l,y=a*c,x=s.x,w=s.y,v=s.z;return i[0]=(1-(f+_))*x,i[1]=(d+y)*x,i[2]=(p-g)*x,i[3]=0,i[4]=(d-y)*w,i[5]=(1-(u+_))*w,i[6]=(m+b)*w,i[7]=0,i[8]=(p+g)*v,i[9]=(m-b)*v,i[10]=(1-(u+f))*v,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=Ae.set(i[0],i[1],i[2]).length();const n=Ae.set(i[4],i[5],i[6]).length(),o=Ae.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],Ie.copy(this);const a=1/r,h=1/n,l=1/o;return Ie.elements[0]*=a,Ie.elements[1]*=a,Ie.elements[2]*=a,Ie.elements[4]*=h,Ie.elements[5]*=h,Ie.elements[6]*=h,Ie.elements[8]*=l,Ie.elements[9]*=l,Ie.elements[10]*=l,e.setFromRotationMatrix(Ie),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),l=2*r/(s-i),c=(e+t)/(e-t),u=(s+i)/(s-i);let d,p;if(o===xt)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==wt)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=c,a[12]=0,a[1]=0,a[5]=l,a[9]=u,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),l=1/(s-i),c=1/(n-r),u=(e+t)*h,d=(s+i)*l;let p,f;if(o===xt)p=(n+r)*c,f=-2*c;else{if(o!==wt)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*c,f=-1*c}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-u,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=f,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const Ae=new Xt,Ie=new Me,Ce=new Xt(0,0,0),ze=new Xt(1,1,1),Te=new Xt,Pe=new Xt,Be=new Xt,Ee=new Me,Fe=new jt;class Re{constructor(t=0,e=0,s=0,i=Re.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,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,s,i=this._order){return this._x=t,this._y=e,this._z=s,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,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],l=i[9],c=i[2],u=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(At(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(u,h),this._z=0);break;case"YXZ":this._x=Math.asin(-At(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-c,r),this._z=0);break;case"ZXY":this._x=Math.asin(At(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-At(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin(At(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-c,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-At(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(u,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-l,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return Ee.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Ee,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Fe.setFromEuler(this),this.setFromQuaternion(Fe,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}}Re.DEFAULT_ORDER="XYZ";class ke{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!!(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let Ve=0;const Le=new Xt,Oe=new jt,De=new Me,Ue=new Xt,Ne=new Xt,We=new Xt,He=new jt,qe=new Xt(1,0,0),Ze=new Xt(0,1,0),Ge=new Xt(0,0,1),je={type:"added"},Xe={type:"removed"},Ye={type:"childadded",child:null},Je={type:"childremoved",child:null};class Qe extends vt{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Ve++}),this.uuid=Mt(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Qe.DEFAULT_UP.clone();const t=new Xt,e=new Re,s=new jt,i=new Xt(1,1,1);e._onChange((function(){s.setFromEuler(e,!1)})),s._onChange((function(){e.setFromQuaternion(s,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:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new Me},normalMatrix:{value:new Pt}}),this.matrix=new Me,this.matrixWorld=new Me,this.matrixAutoUpdate=Qe.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Qe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new ke,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Oe.setFromAxisAngle(t,e),this.quaternion.multiply(Oe),this}rotateOnWorldAxis(t,e){return Oe.setFromAxisAngle(t,e),this.quaternion.premultiply(Oe),this}rotateX(t){return this.rotateOnAxis(qe,t)}rotateY(t){return this.rotateOnAxis(Ze,t)}rotateZ(t){return this.rotateOnAxis(Ge,t)}translateOnAxis(t,e){return Le.copy(t).applyQuaternion(this.quaternion),this.position.add(Le.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(qe,t)}translateY(t){return this.translateOnAxis(Ze,t)}translateZ(t){return this.translateOnAxis(Ge,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(De.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?Ue.copy(t):Ue.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),Ne.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?De.lookAt(Ne,Ue,this.up):De.lookAt(Ue,Ne,this.up),this.quaternion.setFromRotationMatrix(De),i&&(De.extractRotation(i.matrixWorld),Oe.setFromRotationMatrix(De),this.quaternion.premultiply(Oe.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this?(console.error("THREE.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(je),Ye.child=t,this.dispatchEvent(Ye),Ye.child=null):console.error("THREE.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(Xe),Je.child=t,this.dispatchEvent(Je),Je.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),De.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),De.multiply(t.parent.matrixWorld)),t.applyMatrix4(De),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(je),Ye.child=t,this.dispatchEvent(Ye),Ye.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 s=0,i=this.children.length;s<i;s++){const i=this.children[s].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Ne,t,We),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Ne,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 s=0,i=e.length;s<i;s++)e[s].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,i=e.length;s<i;s++){e[s].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const s=this.parent;if(!0===t&&null!==s&&s.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,s=t.length;e<s;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,s){return void 0===e[s.uuid]&&(e[s.uuid]=s.toJSON(t)),s.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),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 s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e<i;e++){const i=s[e];r(t.shapes,i)}else r(t.shapes,s)}}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 s=0,i=this.material.length;s<i;s++)e.push(r(t.materials,this.material[s]));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 s=this.animations[e];i.animations.push(r(t.animations,s))}}if(e){const e=n(t.geometries),i=n(t.materials),r=n(t.textures),o=n(t.images),a=n(t.shapes),h=n(t.skeletons),l=n(t.animations),c=n(t.nodes);e.length>0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),l.length>0&&(s.animations=l),c.length>0&&(s.nodes=c)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e<t.children.length;e++){const s=t.children[e];this.add(s.clone())}return this}}Qe.DEFAULT_UP=new Xt(0,1,0),Qe.DEFAULT_MATRIX_AUTO_UPDATE=!0,Qe.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const $e=new Xt,Ke=new Xt,ts=new Xt,es=new Xt,ss=new Xt,is=new Xt,rs=new Xt,ns=new Xt,os=new Xt,as=new Xt,hs=new Gt,ls=new Gt,cs=new Gt;class us{constructor(t=new Xt,e=new Xt,s=new Xt){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),$e.subVectors(t,e),i.cross($e);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){$e.subVectors(i,e),Ke.subVectors(s,e),ts.subVectors(t,e);const n=$e.dot($e),o=$e.dot(Ke),a=$e.dot(ts),h=Ke.dot(Ke),l=Ke.dot(ts),c=n*h-o*o;if(0===c)return r.set(0,0,0),null;const u=1/c,d=(h*a-o*l)*u,p=(n*l-o*a)*u;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,es)&&(es.x>=0&&es.y>=0&&es.x+es.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,es)?(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,es.x),a.addScaledVector(n,es.y),a.addScaledVector(o,es.z),a)}static getInterpolatedAttribute(t,e,s,i,r,n){return hs.setScalar(0),ls.setScalar(0),cs.setScalar(0),hs.fromBufferAttribute(t,e),ls.fromBufferAttribute(t,s),cs.fromBufferAttribute(t,i),n.setScalar(0),n.addScaledVector(hs,r.x),n.addScaledVector(ls,r.y),n.addScaledVector(cs,r.z),n}static isFrontFacing(t,e,s,i){return $e.subVectors(s,e),Ke.subVectors(t,e),$e.cross(Ke).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),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 $e.subVectors(this.c,this.b),Ke.subVectors(this.a,this.b),.5*$e.cross(Ke).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return us.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return us.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return us.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return us.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return us.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;ss.subVectors(i,s),is.subVectors(r,s),ns.subVectors(t,s);const a=ss.dot(ns),h=is.dot(ns);if(a<=0&&h<=0)return e.copy(s);os.subVectors(t,i);const l=ss.dot(os),c=is.dot(os);if(l>=0&&c<=l)return e.copy(i);const u=a*c-l*h;if(u<=0&&a>=0&&l<=0)return n=a/(a-l),e.copy(s).addScaledVector(ss,n);as.subVectors(t,r);const d=ss.dot(as),p=is.dot(as);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(s).addScaledVector(is,o);const m=l*p-d*c;if(m<=0&&c-l>=0&&d-p>=0)return rs.subVectors(r,i),o=(c-l)/(c-l+(d-p)),e.copy(i).addScaledVector(rs,o);const _=1/(m+f+u);return n=f*_,o=u*_,e.copy(s).addScaledVector(ss,n).addScaledVector(is,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const ds={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},ps={h:0,s:0,l:0},fs={h:0,s:0,l:0};function ms(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class _s{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){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,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=mt){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,Vt.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=Vt.workingColorSpace){return this.r=t,this.g=e,this.b=s,Vt.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=Vt.workingColorSpace){var r;if(t=(t%(r=1)+r)%r,e=At(e,0,1),s=At(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=ms(r,i,t+1/3),this.g=ms(r,i,t),this.b=ms(r,i,t-1/3)}return Vt.toWorkingColorSpace(this,i),this}setStyle(t,e=mt){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(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 s(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 s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=mt){const s=ds[t.toLowerCase()];return void 0!==s?this.setHex(s,e):console.warn("THREE.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=Lt(t.r),this.g=Lt(t.g),this.b=Lt(t.b),this}copyLinearToSRGB(t){return this.r=Ot(t.r),this.g=Ot(t.g),this.b=Ot(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=mt){return Vt.fromWorkingColorSpace(bs.copy(this),t),65536*Math.round(At(255*bs.r,0,255))+256*Math.round(At(255*bs.g,0,255))+Math.round(At(255*bs.b,0,255))}getHexString(t=mt){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Vt.workingColorSpace){Vt.fromWorkingColorSpace(bs.copy(this),e);const s=bs.r,i=bs.g,r=bs.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const l=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=l<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i<r?6:0);break;case i:a=(r-s)/t+2;break;case r:a=(s-i)/t+4}a/=6}return t.h=a,t.s=h,t.l=l,t}getRGB(t,e=Vt.workingColorSpace){return Vt.fromWorkingColorSpace(bs.copy(this),e),t.r=bs.r,t.g=bs.g,t.b=bs.b,t}getStyle(t=mt){Vt.fromWorkingColorSpace(bs.copy(this),t);const e=bs.r,s=bs.g,i=bs.b;return t!==mt?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*s)},${Math.round(255*i)})`}offsetHSL(t,e,s){return this.getHSL(ps),this.setHSL(ps.h+t,ps.s+e,ps.l+s)}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,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(ps),t.getHSL(fs);const s=It(ps.h,fs.h,e),i=It(ps.s,fs.s,e),r=It(ps.l,fs.l,e);return this.setHSL(s,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,s=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*s+r[6]*i,this.g=r[1]*e+r[4]*s+r[7]*i,this.b=r[2]*e+r[5]*s+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 bs=new _s;_s.NAMES=ds;let gs=0,ys=class extends vt{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:gs++}),this.uuid=Mt(),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 _s(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=yt,this.stencilZFail=yt,this.stencilZPass=yt,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 s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.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 s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),0!==this.side&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),204!==this.blendSrc&&(s.blendSrc=this.blendSrc),205!==this.blendDst&&(s.blendDst=this.blendDst),100!==this.blendEquation&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==yt&&(s.stencilFail=this.stencilFail),this.stencilZFail!==yt&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==yt&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}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 s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,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.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++}onBuild(){console.warn("Material: onBuild() has been removed.")}};class xs extends ys{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new _s(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 Re,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 ws=new Xt,vs=new Tt;let Ss=0;class Ms{constructor(t,e,s=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Ss++}),this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=s,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,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[s+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,s=this.count;e<s;e++)vs.fromBufferAttribute(this,e),vs.applyMatrix3(t),this.setXY(e,vs.x,vs.y);else if(3===this.itemSize)for(let e=0,s=this.count;e<s;e++)ws.fromBufferAttribute(this,e),ws.applyMatrix3(t),this.setXYZ(e,ws.x,ws.y,ws.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)ws.fromBufferAttribute(this,e),ws.applyMatrix4(t),this.setXYZ(e,ws.x,ws.y,ws.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)ws.fromBufferAttribute(this,e),ws.applyNormalMatrix(t),this.setXYZ(e,ws.x,ws.y,ws.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)ws.fromBufferAttribute(this,e),ws.transformDirection(t),this.setXYZ(e,ws.x,ws.y,ws.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=Ct(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=zt(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Ct(e,this.array)),e}setX(t,e){return this.normalized&&(e=zt(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Ct(e,this.array)),e}setY(t,e){return this.normalized&&(e=zt(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=Ct(e,this.array)),e}setZ(t,e){return this.normalized&&(e=zt(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=Ct(e,this.array)),e}setW(t,e){return this.normalized&&(e=zt(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=zt(e,this.array),s=zt(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=zt(e,this.array),s=zt(s,this.array),i=zt(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=zt(e,this.array),s=zt(s,this.array),i=zt(i,this.array),r=zt(r,this.array)),this.array[t+0]=e,this.array[t+1]=s,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 As extends Ms{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class Is extends Ms{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class Cs extends Ms{constructor(t,e,s){super(new Float32Array(t),e,s)}}let zs=0;const Ts=new Me,Ps=new Qe,Bs=new Xt,Es=new Qt,Fs=new Qt,Rs=new Xt;class ks extends vt{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:zs++}),this.uuid=Mt(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,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)?Is:As)(t,1):this.index=t,this}setIndirect(t){return this.indirect=t,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,s=0){this.groups.push({start:t,count:e,materialIndex:s})}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 s=this.attributes.normal;if(void 0!==s){const e=(new Pt).getNormalMatrix(t);s.applyNormalMatrix(e),s.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 Ts.makeRotationFromQuaternion(t),this.applyMatrix4(Ts),this}rotateX(t){return Ts.makeRotationX(t),this.applyMatrix4(Ts),this}rotateY(t){return Ts.makeRotationY(t),this.applyMatrix4(Ts),this}rotateZ(t){return Ts.makeRotationZ(t),this.applyMatrix4(Ts),this}translate(t,e,s){return Ts.makeTranslation(t,e,s),this.applyMatrix4(Ts),this}scale(t,e,s){return Ts.makeScale(t,e,s),this.applyMatrix4(Ts),this}lookAt(t){return Ps.lookAt(t),Ps.updateMatrix(),this.applyMatrix4(Ps.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Bs).negate(),this.translate(Bs.x,Bs.y,Bs.z),this}setFromPoints(t){const e=this.getAttribute("position");if(void 0===e){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s];e.push(i.x,i.y,i.z||0)}this.setAttribute("position",new Cs(e,3))}else{const s=Math.min(t.length,e.count);for(let i=0;i<s;i++){const s=t[i];e.setXYZ(i,s.x,s.y,s.z||0)}t.length>e.count&&console.warn("THREE.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 Qt);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Xt(-1/0,-1/0,-1/0),new Xt(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];Es.setFromBufferAttribute(s),this.morphTargetsRelative?(Rs.addVectors(this.boundingBox.min,Es.min),this.boundingBox.expandByPoint(Rs),Rs.addVectors(this.boundingBox.max,Es.max),this.boundingBox.expandByPoint(Rs)):(this.boundingBox.expandByPoint(Es.min),this.boundingBox.expandByPoint(Es.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.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 me);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new Xt,1/0);if(t){const s=this.boundingSphere.center;if(Es.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];Fs.setFromBufferAttribute(s),this.morphTargetsRelative?(Rs.addVectors(Es.min,Fs.min),Es.expandByPoint(Rs),Rs.addVectors(Es.max,Fs.max),Es.expandByPoint(Rs)):(Es.expandByPoint(Fs.min),Es.expandByPoint(Fs.max))}Es.getCenter(s);let i=0;for(let e=0,r=t.count;e<r;e++)Rs.fromBufferAttribute(t,e),i=Math.max(i,s.distanceToSquared(Rs));if(e)for(let r=0,n=e.length;r<n;r++){const n=e[r],o=this.morphTargetsRelative;for(let e=0,r=n.count;e<r;e++)Rs.fromBufferAttribute(n,e),o&&(Bs.fromBufferAttribute(t,e),Rs.add(Bs)),i=Math.max(i,s.distanceToSquared(Rs))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error('THREE.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 console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const s=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new Ms(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),o=[],a=[];for(let t=0;t<s.count;t++)o[t]=new Xt,a[t]=new Xt;const h=new Xt,l=new Xt,c=new Xt,u=new Tt,d=new Tt,p=new Tt,f=new Xt,m=new Xt;function _(t,e,i){h.fromBufferAttribute(s,t),l.fromBufferAttribute(s,e),c.fromBufferAttribute(s,i),u.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),l.sub(h),c.sub(h),d.sub(u),p.sub(u);const n=1/(d.x*p.y-p.x*d.y);isFinite(n)&&(f.copy(l).multiplyScalar(p.y).addScaledVector(c,-d.y).multiplyScalar(n),m.copy(c).multiplyScalar(d.x).addScaledVector(l,-p.x).multiplyScalar(n),o[t].add(f),o[e].add(f),o[i].add(f),a[t].add(m),a[e].add(m),a[i].add(m))}let b=this.groups;0===b.length&&(b=[{start:0,count:t.count}]);for(let e=0,s=b.length;e<s;++e){const s=b[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)_(t.getX(e+0),t.getX(e+1),t.getX(e+2))}const g=new Xt,y=new Xt,x=new Xt,w=new Xt;function v(t){x.fromBufferAttribute(i,t),w.copy(x);const e=o[t];g.copy(e),g.sub(x.multiplyScalar(x.dot(e))).normalize(),y.crossVectors(w,e);const s=y.dot(a[t])<0?-1:1;n.setXYZW(t,g.x,g.y,g.z,s)}for(let e=0,s=b.length;e<s;++e){const s=b[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)v(t.getX(e+0)),v(t.getX(e+1)),v(t.getX(e+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let s=this.getAttribute("normal");if(void 0===s)s=new Ms(new Float32Array(3*e.count),3),this.setAttribute("normal",s);else for(let t=0,e=s.count;t<e;t++)s.setXYZ(t,0,0,0);const i=new Xt,r=new Xt,n=new Xt,o=new Xt,a=new Xt,h=new Xt,l=new Xt,c=new Xt;if(t)for(let u=0,d=t.count;u<d;u+=3){const d=t.getX(u+0),p=t.getX(u+1),f=t.getX(u+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),n.fromBufferAttribute(e,f),l.subVectors(n,r),c.subVectors(i,r),l.cross(c),o.fromBufferAttribute(s,d),a.fromBufferAttribute(s,p),h.fromBufferAttribute(s,f),o.add(l),a.add(l),h.add(l),s.setXYZ(d,o.x,o.y,o.z),s.setXYZ(p,a.x,a.y,a.z),s.setXYZ(f,h.x,h.y,h.z)}else for(let t=0,o=e.count;t<o;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),n.fromBufferAttribute(e,t+2),l.subVectors(n,r),c.subVectors(i,r),l.cross(c),s.setXYZ(t+0,l.x,l.y,l.z),s.setXYZ(t+1,l.x,l.y,l.z),s.setXYZ(t+2,l.x,l.y,l.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)Rs.fromBufferAttribute(t,e),Rs.normalize(),t.setXYZ(e,Rs.x,Rs.y,Rs.z)}toNonIndexed(){function t(t,e){const s=t.array,i=t.itemSize,r=t.normalized,n=new s.constructor(e.length*i);let o=0,a=0;for(let r=0,h=e.length;r<h;r++){o=t.isInterleavedBufferAttribute?e[r]*t.data.stride+t.offset:e[r]*i;for(let t=0;t<i;t++)n[a++]=s[o++]}return new Ms(n,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new ks,s=this.index.array,i=this.attributes;for(const r in i){const n=t(i[r],s);e.setAttribute(r,n)}const r=this.morphAttributes;for(const i in r){const n=[],o=r[i];for(let e=0,i=o.length;e<i;e++){const i=t(o[e],s);n.push(i)}e.morphAttributes[i]=n}e.morphTargetsRelative=this.morphTargetsRelative;const n=this.groups;for(let t=0,s=n.length;t<s;t++){const s=n[t];e.addGroup(s.start,s.count,s.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,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 s in e)void 0!==e[s]&&(t[s]=e[s]);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 s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e<i;e++){const i=s[e];n.push(i.toJSON(t.data))}n.length>0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),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 s=t.index;null!==s&&this.setIndex(s.clone());const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t<r;t++)s.push(i[t].clone(e));this.morphAttributes[t]=s}this.morphTargetsRelative=t.morphTargetsRelative;const n=t.groups;for(let t=0,e=n.length;t<e;t++){const e=n[t];this.addGroup(e.start,e.count,e.materialIndex)}const o=t.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=t.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Vs=new Me,Ls=new Se,Os=new me,Ds=new Xt,Us=new Xt,Ns=new Xt,Ws=new Xt,Hs=new Xt,qs=new Xt,Zs=new Xt,Gs=new Xt;class js extends Qe{constructor(t=new ks,e=new xs){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,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 s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const s=this.geometry,i=s.attributes.position,r=s.morphAttributes.position,n=s.morphTargetsRelative;e.fromBufferAttribute(i,t);const o=this.morphTargetInfluences;if(r&&o){qs.set(0,0,0);for(let s=0,i=r.length;s<i;s++){const i=o[s],a=r[s];0!==i&&(Hs.fromBufferAttribute(a,t),n?qs.addScaledVector(Hs,i):qs.addScaledVector(Hs.sub(e),i))}e.add(qs)}return e}raycast(t,e){const s=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===s.boundingSphere&&s.computeBoundingSphere(),Os.copy(s.boundingSphere),Os.applyMatrix4(r),Ls.copy(t.ray).recast(t.near),!1===Os.containsPoint(Ls.origin)){if(null===Ls.intersectSphere(Os,Ds))return;if(Ls.origin.distanceToSquared(Ds)>(t.far-t.near)**2)return}Vs.copy(r).invert(),Ls.copy(t.ray).applyMatrix4(Vs),null!==s.boundingBox&&!1===Ls.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,Ls)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,l=r.attributes.uv1,c=r.attributes.normal,u=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=u.length;r<a;r++){const a=u[r],p=n[a.materialIndex];for(let r=Math.max(a.start,d.start),n=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<n;r+=3){i=Xs(this,p,t,s,h,l,c,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=a.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=Xs(this,n,t,s,h,l,c,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(n))for(let r=0,o=u.length;r<o;r++){const o=u[r],p=n[o.materialIndex];for(let r=Math.max(o.start,d.start),n=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<n;r+=3){i=Xs(this,p,t,s,h,l,c,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=o.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=Xs(this,n,t,s,h,l,c,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function Xs(t,e,s,i,r,n,o,a,h,l){t.getVertexPosition(a,Us),t.getVertexPosition(h,Ns),t.getVertexPosition(l,Ws);const c=function(t,e,s,i,r,n,o,a){let h;if(h=1===e.side?i.intersectTriangle(o,n,r,!0,a):i.intersectTriangle(r,n,o,0===e.side,a),null===h)return null;Gs.copy(a),Gs.applyMatrix4(t.matrixWorld);const l=s.ray.origin.distanceTo(Gs);return l<s.near||l>s.far?null:{distance:l,point:Gs.clone(),object:t}}(t,e,s,i,Us,Ns,Ws,Zs);if(c){const t=new Xt;us.getBarycoord(Zs,Us,Ns,Ws,t),r&&(c.uv=us.getInterpolatedAttribute(r,a,h,l,t,new Tt)),n&&(c.uv1=us.getInterpolatedAttribute(n,a,h,l,t,new Tt)),o&&(c.normal=us.getInterpolatedAttribute(o,a,h,l,t,new Xt),c.normal.dot(i.direction)>0&&c.normal.multiplyScalar(-1));const e={a:a,b:h,c:l,normal:new Xt,materialIndex:0};us.getNormal(Us,Ns,Ws,e.normal),c.face=e,c.barycoord=t}return c}class Ys extends Zt{constructor(t=null,e=1,s=1,i,r,n,o,a,h=1003,l=1003,c,u){super(null,n,o,a,h,l,i,r,c,u),this.isDataTexture=!0,this.image={data:t,width:e,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Js extends Ms{constructor(t,e,s,i=1){super(t,e,s),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const Qs=new Me,$s=new Me,Ks=[],ti=new Qt,ei=new Me,si=new js,ii=new me;class ri extends js{constructor(t,e,s){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new Js(new Float32Array(16*s),16),this.instanceColor=null,this.morphTexture=null,this.count=s,this.boundingBox=null,this.boundingSphere=null;for(let t=0;t<s;t++)this.setMatrixAt(t,ei)}computeBoundingBox(){const t=this.geometry,e=this.count;null===this.boundingBox&&(this.boundingBox=new Qt),null===t.boundingBox&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Qs),ti.copy(t.boundingBox).applyMatrix4(Qs),this.boundingBox.union(ti)}computeBoundingSphere(){const t=this.geometry,e=this.count;null===this.boundingSphere&&(this.boundingSphere=new me),null===t.boundingSphere&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Qs),ii.copy(t.boundingSphere).applyMatrix4(Qs),this.boundingSphere.union(ii)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),null!==t.morphTexture&&(this.morphTexture=t.morphTexture.clone()),null!==t.instanceColor&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){e.fromArray(this.instanceColor.array,3*t)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,16*t)}getMorphAt(t,e){const s=e.morphTargetInfluences,i=this.morphTexture.source.data.data,r=t*(s.length+1)+1;for(let t=0;t<s.length;t++)s[t]=i[r+t]}raycast(t,e){const s=this.matrixWorld,i=this.count;if(si.geometry=this.geometry,si.material=this.material,void 0!==si.material&&(null===this.boundingSphere&&this.computeBoundingSphere(),ii.copy(this.boundingSphere),ii.applyMatrix4(s),!1!==t.ray.intersectsSphere(ii)))for(let r=0;r<i;r++){this.getMatrixAt(r,Qs),$s.multiplyMatrices(s,Qs),si.matrixWorld=$s,si.raycast(t,Ks);for(let t=0,s=Ks.length;t<s;t++){const s=Ks[t];s.instanceId=r,s.object=this,e.push(s)}Ks.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new Js(new Float32Array(3*this.instanceMatrix.count).fill(1),3)),e.toArray(this.instanceColor.array,3*t)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,16*t)}setMorphAt(t,e){const s=e.morphTargetInfluences,i=s.length+1;null===this.morphTexture&&(this.morphTexture=new Ys(new Float32Array(i*this.count),i,this.count,1028,1015));const r=this.morphTexture.source.data.data;let n=0;for(let t=0;t<s.length;t++)n+=s[t];const o=this.geometry.morphTargetsRelative?1:1-n,a=i*t;r[a]=o,r.set(s,a+1)}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),null!==this.morphTexture&&(this.morphTexture.dispose(),this.morphTexture=null)}}const ni=new Xt,oi=new Xt,ai=new Pt;class hi{constructor(t=new Xt(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,s,i){return this.normal.set(t,e,s),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,s){const i=ni.subVectors(s,e).cross(oi.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 s=t.delta(ni),i=this.normal.dot(s);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(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<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 s=e||ai.getNormalMatrix(t),i=this.coplanarPoint(ni).applyMatrix4(t),r=this.normal.applyMatrix3(s).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)}}const li=new me,ci=new Xt;class ui{constructor(t=new hi,e=new hi,s=new hi,i=new hi,r=new hi,n=new hi){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],l=i[5],c=i[6],u=i[7],d=i[8],p=i[9],f=i[10],m=i[11],_=i[12],b=i[13],g=i[14],y=i[15];if(s[0].setComponents(a-r,u-h,m-d,y-_).normalize(),s[1].setComponents(a+r,u+h,m+d,y+_).normalize(),s[2].setComponents(a+n,u+l,m+p,y+b).normalize(),s[3].setComponents(a-n,u-l,m-p,y-b).normalize(),s[4].setComponents(a-o,u-c,m-f,y-g).normalize(),e===xt)s[5].setComponents(a+o,u+c,m+f,y+g).normalize();else{if(e!==wt)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,c,f,g).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),li.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),li.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(li)}intersectsSprite(t){return li.center.set(0,0,0),li.radius=.7071067811865476,li.applyMatrix4(t.matrixWorld),this.intersectsSphere(li)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)<i)return!1}return!0}intersectsBox(t){const e=this.planes;for(let s=0;s<6;s++){const i=e[s];if(ci.x=i.normal.x>0?t.max.x:t.min.x,ci.y=i.normal.y>0?t.max.y:t.min.y,ci.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ci)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}const di=new Xt,pi=new Xt;class fi{constructor(t=new Xt,e=new Xt){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){di.subVectors(t,this.start),pi.subVectors(this.end,this.start);const s=pi.dot(pi);let i=pi.dot(di)/s;return e&&(i=At(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).add(this.start)}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:"175"}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="175");const mi=65536;var _i=(t=>(t[t.LINE=0]="LINE",t[t.SHELL=1]="SHELL",t))(_i||{}),bi=(t=>(t[t.UPDATE=0]="UPDATE",t[t.CREATE=1]="CREATE",t[t.DELETE=2]="DELETE",t[t.FINISH=3]="FINISH",t))(bi||{}),gi=(t=>(t[t.GEOMETRY=0]="GEOMETRY",t[t.WIRES=1]="WIRES",t[t.INVISIBLE=2]="INVISIBLE",t))(gi||{}),yi=(t=>(t[t.CREATE_MODEL=0]="CREATE_MODEL",t[t.DELETE_MODEL=1]="DELETE_MODEL",t[t.EXECUTE=2]="EXECUTE",t[t.RAYCAST=3]="RAYCAST",t[t.FETCH_BOXES=4]="FETCH_BOXES",t[t.REFRESH_VIEW=5]="REFRESH_VIEW",t[t.RECOMPUTE_MESHES=6]="RECOMPUTE_MESHES",t[t.CREATE_MATERIAL=7]="CREATE_MATERIAL",t[t.THROW_ERROR=8]="THROW_ERROR",t))(yi||{}),xi=(t=>(t[t.VISIBLE=0]="VISIBLE",t))(xi||{}),wi=(t=>(t[t.POINT=0]="POINT",t[t.LINE=1]="LINE",t[t.FACE=2]="FACE",t))(wi||{});class vi{static newThread(t){return new Worker(t,{type:"module"})}static newUpdater(t,e){return setInterval(t,e)}static getMeshComputeRequest(t,e){return{class:yi.RECOMPUTE_MESHES,modelId:t,list:e}}static planeSet(t){const e=[];for(const s of t){const t=this.array(s.normal),i=s.constant,r=new hi(t,i);e.push(r)}return e}static data(t){var e,s;if(void 0!==(null==t?void 0:t.elements))return vi.transform(t);if(void 0!==(null==t?void 0:t.origin)&&void 0!==(null==t?void 0:t.direction))return vi.beam(t);if(void 0!==(null==t?void 0:t.planes))return vi.frustum(t);const i=void 0!==(null==t?void 0:t.normal),r=void 0!==(null==t?void 0:t.constant);if(i&&r)return vi.plane(t);const n=void 0!==(null==(e=t[0])?void 0:e.normal),o=void 0!==(null==(s=t[0])?void 0:s.constant);if(n&&o)return vi.planeSet(t);const a=void 0!==(null==t?void 0:t.x),h=void 0!==(null==t?void 0:t.y),l=void 0!==(null==t?void 0:t.z);return a&&h&&l?vi.array(t):t}static getExecuteRequest(t,e,s){const i=Array.from(s);return{class:yi.EXECUTE,modelId:t,function:e,parameters:i}}static plane(t){const e=this.array(t.normal),s=t.constant;return new hi(e,s)}static getRequestContent(t){const e=[];for(const s of t.list)vi.setupCreateRequest(s,e),vi.setupUpdateRequest(s,e);return e}static array(t){const e=new Xt;return e.set(t.x,t.y,t.z),e}static cleanRequests(t){const e=[],s=vi;for(const i of t){s.isFinishRequest(i)||e.push(i)}return e}static frustum(t){const e=this.planeSet(t.planes),[s,i,r,n,o,a]=e;return new ui(s,i,r,n,o,a)}static beam(t){const e=this.array(t.origin),s=this.array(t.direction);return new Se(e,s)}static transform(t){const e=new Me;return e.copy(t),e}static deleteUpdater(t){clearInterval(t)}static areCoresAvailable(t){const e=vi.getCpuCapacity();return t<Math.max(e,2)}static isFinishRequest(t){return t.tileRequestClass===bi.FINISH}static setupUpdateRequest(t,e){t.tileRequestClass===bi.UPDATE&&this.addAllTileData(t,e)}static getCpuCapacity(){var t;return(null==(t=globalThis.navigator)?void 0:t.hardwareConcurrency)?navigator.hardwareConcurrency-3:0}static addAllTileData(t,e){this.addRequestTileData(t,e,"visibilityData");this.addRequestTileData(t,e,"highlightData",["highlightIds"])}static addRequestContent(t,e,s){if(!e[t])return;const i=e[t].buffer;s.push(i)}static addRequestTileData(t,e,s,i=[]){const r=t.tileData[s];if(r){e.push(r.position.buffer),e.push(r.size.buffer);for(const s of i)e.push(t.tileData[s].buffer)}}static setupCreateRequest(t,e){if(t.tileRequestClass!==bi.CREATE)return;const s=this.getCreateRequestIds();for(const i of s)this.addRequestContent(i,t,e);this.addAllTileData(t,e)}static getCreateRequestIds(){return["positions","indices","normals","itemIds"]}}class Si{constructor(t){ot(this,"_handlers",new pt),ot(this,"_handleInput"),ot(this,"_port"),ot(this,"onInput",(t=>{t.data.toMainThread?this._handlers.run(t.data):this.manageInput(t.data)})),this._handleInput=t}fetchMeshCompute(t,e){const s=vi,i=s.getMeshComputeRequest(t,e),r=s.getRequestContent(i);this.fetch(i,r)}fetch(t,e){return this._handlers.setupInput(t),new Promise(((s,i)=>{this._handlers.set(t.requestId,i,s),this.executeConnection(t,e)}))}init(t){this._port=t,this.initConnection(t)}initConnection(t){t.onmessage=this.onInput}async fetchConnection(t){if(!this._port)throw new Error("Fragments: Connection not initialized");return this._port}async executeConnection(t,e){(await this.fetchConnection(t)).postMessage(t,e)}async manageOutput(t){const e=await this.fetchConnection(t);t.toMainThread=!0,e.postMessage(t)}async manageConnection(t){try{await this._handleInput(t)}catch(e){t.errorInfo=e.toString(),console.error(e)}}async manageInput(t){await this.manageConnection(t),await this.manageOutput(t)}}
|
|
7
|
+
/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function Mi(t){let e=t.length;for(;--e>=0;)t[e]=0}const Ai=256,Ii=286,Ci=30,zi=15,Ti=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),Pi=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),Bi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),Ei=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fi=new Array(576);Mi(Fi);const Ri=new Array(60);Mi(Ri);const ki=new Array(512);Mi(ki);const Vi=new Array(256);Mi(Vi);const Li=new Array(29);Mi(Li);const Oi=new Array(Ci);function Di(t,e,s,i,r){this.static_tree=t,this.extra_bits=e,this.extra_base=s,this.elems=i,this.max_length=r,this.has_stree=t&&t.length}let Ui,Ni,Wi;function Hi(t,e){this.dyn_tree=t,this.max_code=0,this.stat_desc=e}Mi(Oi);const qi=t=>t<256?ki[t]:ki[256+(t>>>7)],Zi=(t,e)=>{t.pending_buf[t.pending++]=255&e,t.pending_buf[t.pending++]=e>>>8&255},Gi=(t,e,s)=>{t.bi_valid>16-s?(t.bi_buf|=e<<t.bi_valid&65535,Zi(t,t.bi_buf),t.bi_buf=e>>16-t.bi_valid,t.bi_valid+=s-16):(t.bi_buf|=e<<t.bi_valid&65535,t.bi_valid+=s)},ji=(t,e,s)=>{Gi(t,s[2*e],s[2*e+1])},Xi=(t,e)=>{let s=0;do{s|=1&t,t>>>=1,s<<=1}while(--e>0);return s>>>1},Yi=(t,e,s)=>{const i=new Array(16);let r,n,o=0;for(r=1;r<=zi;r++)o=o+s[r-1]<<1,i[r]=o;for(n=0;n<=e;n++){let e=t[2*n+1];0!==e&&(t[2*n]=Xi(i[e]++,e))}},Ji=t=>{let e;for(e=0;e<Ii;e++)t.dyn_ltree[2*e]=0;for(e=0;e<Ci;e++)t.dyn_dtree[2*e]=0;for(e=0;e<19;e++)t.bl_tree[2*e]=0;t.dyn_ltree[512]=1,t.opt_len=t.static_len=0,t.sym_next=t.matches=0},Qi=t=>{t.bi_valid>8?Zi(t,t.bi_buf):t.bi_valid>0&&(t.pending_buf[t.pending++]=t.bi_buf),t.bi_buf=0,t.bi_valid=0},$i=(t,e,s,i)=>{const r=2*e,n=2*s;return t[r]<t[n]||t[r]===t[n]&&i[e]<=i[s]},Ki=(t,e,s)=>{const i=t.heap[s];let r=s<<1;for(;r<=t.heap_len&&(r<t.heap_len&&$i(e,t.heap[r+1],t.heap[r],t.depth)&&r++,!$i(e,i,t.heap[r],t.depth));)t.heap[s]=t.heap[r],s=r,r<<=1;t.heap[s]=i},tr=(t,e,s)=>{let i,r,n,o,a=0;if(0!==t.sym_next)do{i=255&t.pending_buf[t.sym_buf+a++],i+=(255&t.pending_buf[t.sym_buf+a++])<<8,r=t.pending_buf[t.sym_buf+a++],0===i?ji(t,r,e):(n=Vi[r],ji(t,n+Ai+1,e),o=Ti[n],0!==o&&(r-=Li[n],Gi(t,r,o)),i--,n=qi(i),ji(t,n,s),o=Pi[n],0!==o&&(i-=Oi[n],Gi(t,i,o)))}while(a<t.sym_next);ji(t,256,e)},er=(t,e)=>{const s=e.dyn_tree,i=e.stat_desc.static_tree,r=e.stat_desc.has_stree,n=e.stat_desc.elems;let o,a,h,l=-1;for(t.heap_len=0,t.heap_max=573,o=0;o<n;o++)0!==s[2*o]?(t.heap[++t.heap_len]=l=o,t.depth[o]=0):s[2*o+1]=0;for(;t.heap_len<2;)h=t.heap[++t.heap_len]=l<2?++l:0,s[2*h]=1,t.depth[h]=0,t.opt_len--,r&&(t.static_len-=i[2*h+1]);for(e.max_code=l,o=t.heap_len>>1;o>=1;o--)Ki(t,s,o);h=n;do{o=t.heap[1],t.heap[1]=t.heap[t.heap_len--],Ki(t,s,1),a=t.heap[1],t.heap[--t.heap_max]=o,t.heap[--t.heap_max]=a,s[2*h]=s[2*o]+s[2*a],t.depth[h]=(t.depth[o]>=t.depth[a]?t.depth[o]:t.depth[a])+1,s[2*o+1]=s[2*a+1]=h,t.heap[1]=h++,Ki(t,s,1)}while(t.heap_len>=2);t.heap[--t.heap_max]=t.heap[1],((t,e)=>{const s=e.dyn_tree,i=e.max_code,r=e.stat_desc.static_tree,n=e.stat_desc.has_stree,o=e.stat_desc.extra_bits,a=e.stat_desc.extra_base,h=e.stat_desc.max_length;let l,c,u,d,p,f,m=0;for(d=0;d<=zi;d++)t.bl_count[d]=0;for(s[2*t.heap[t.heap_max]+1]=0,l=t.heap_max+1;l<573;l++)c=t.heap[l],d=s[2*s[2*c+1]+1]+1,d>h&&(d=h,m++),s[2*c+1]=d,c>i||(t.bl_count[d]++,p=0,c>=a&&(p=o[c-a]),f=s[2*c],t.opt_len+=f*(d+p),n&&(t.static_len+=f*(r[2*c+1]+p)));if(0!==m){do{for(d=h-1;0===t.bl_count[d];)d--;t.bl_count[d]--,t.bl_count[d+1]+=2,t.bl_count[h]--,m-=2}while(m>0);for(d=h;0!==d;d--)for(c=t.bl_count[d];0!==c;)u=t.heap[--l],u>i||(s[2*u+1]!==d&&(t.opt_len+=(d-s[2*u+1])*s[2*u],s[2*u+1]=d),c--)}})(t,e),Yi(s,l,t.bl_count)},sr=(t,e,s)=>{let i,r,n=-1,o=e[1],a=0,h=7,l=4;for(0===o&&(h=138,l=3),e[2*(s+1)+1]=65535,i=0;i<=s;i++)r=o,o=e[2*(i+1)+1],++a<h&&r===o||(a<l?t.bl_tree[2*r]+=a:0!==r?(r!==n&&t.bl_tree[2*r]++,t.bl_tree[32]++):a<=10?t.bl_tree[34]++:t.bl_tree[36]++,a=0,n=r,0===o?(h=138,l=3):r===o?(h=6,l=3):(h=7,l=4))},ir=(t,e,s)=>{let i,r,n=-1,o=e[1],a=0,h=7,l=4;for(0===o&&(h=138,l=3),i=0;i<=s;i++)if(r=o,o=e[2*(i+1)+1],!(++a<h&&r===o)){if(a<l)do{ji(t,r,t.bl_tree)}while(0!=--a);else 0!==r?(r!==n&&(ji(t,r,t.bl_tree),a--),ji(t,16,t.bl_tree),Gi(t,a-3,2)):a<=10?(ji(t,17,t.bl_tree),Gi(t,a-3,3)):(ji(t,18,t.bl_tree),Gi(t,a-11,7));a=0,n=r,0===o?(h=138,l=3):r===o?(h=6,l=3):(h=7,l=4)}};let rr=!1;const nr=(t,e,s,i)=>{Gi(t,0+(i?1:0),3),Qi(t),Zi(t,s),Zi(t,~s),s&&t.pending_buf.set(t.window.subarray(e,e+s),t.pending),t.pending+=s};var or={_tr_init:t=>{rr||((()=>{let t,e,s,i,r;const n=new Array(16);for(s=0,i=0;i<28;i++)for(Li[i]=s,t=0;t<1<<Ti[i];t++)Vi[s++]=i;for(Vi[s-1]=i,r=0,i=0;i<16;i++)for(Oi[i]=r,t=0;t<1<<Pi[i];t++)ki[r++]=i;for(r>>=7;i<Ci;i++)for(Oi[i]=r<<7,t=0;t<1<<Pi[i]-7;t++)ki[256+r++]=i;for(e=0;e<=zi;e++)n[e]=0;for(t=0;t<=143;)Fi[2*t+1]=8,t++,n[8]++;for(;t<=255;)Fi[2*t+1]=9,t++,n[9]++;for(;t<=279;)Fi[2*t+1]=7,t++,n[7]++;for(;t<=287;)Fi[2*t+1]=8,t++,n[8]++;for(Yi(Fi,287,n),t=0;t<Ci;t++)Ri[2*t+1]=5,Ri[2*t]=Xi(t,5);Ui=new Di(Fi,Ti,257,Ii,zi),Ni=new Di(Ri,Pi,0,Ci,zi),Wi=new Di(new Array(0),Bi,0,19,7)})(),rr=!0),t.l_desc=new Hi(t.dyn_ltree,Ui),t.d_desc=new Hi(t.dyn_dtree,Ni),t.bl_desc=new Hi(t.bl_tree,Wi),t.bi_buf=0,t.bi_valid=0,Ji(t)},_tr_stored_block:nr,_tr_flush_block:(t,e,s,i)=>{let r,n,o=0;t.level>0?(2===t.strm.data_type&&(t.strm.data_type=(t=>{let e,s=4093624447;for(e=0;e<=31;e++,s>>>=1)if(1&s&&0!==t.dyn_ltree[2*e])return 0;if(0!==t.dyn_ltree[18]||0!==t.dyn_ltree[20]||0!==t.dyn_ltree[26])return 1;for(e=32;e<Ai;e++)if(0!==t.dyn_ltree[2*e])return 1;return 0})(t)),er(t,t.l_desc),er(t,t.d_desc),o=(t=>{let e;for(sr(t,t.dyn_ltree,t.l_desc.max_code),sr(t,t.dyn_dtree,t.d_desc.max_code),er(t,t.bl_desc),e=18;e>=3&&0===t.bl_tree[2*Ei[e]+1];e--);return t.opt_len+=3*(e+1)+5+5+4,e})(t),r=t.opt_len+3+7>>>3,n=t.static_len+3+7>>>3,n<=r&&(r=n)):r=n=s+5,s+4<=r&&-1!==e?nr(t,e,s,i):4===t.strategy||n===r?(Gi(t,2+(i?1:0),3),tr(t,Fi,Ri)):(Gi(t,4+(i?1:0),3),((t,e,s,i)=>{let r;for(Gi(t,e-257,5),Gi(t,s-1,5),Gi(t,i-4,4),r=0;r<i;r++)Gi(t,t.bl_tree[2*Ei[r]+1],3);ir(t,t.dyn_ltree,e-1),ir(t,t.dyn_dtree,s-1)})(t,t.l_desc.max_code+1,t.d_desc.max_code+1,o+1),tr(t,t.dyn_ltree,t.dyn_dtree)),Ji(t),i&&Qi(t)},_tr_tally:(t,e,s)=>(t.pending_buf[t.sym_buf+t.sym_next++]=e,t.pending_buf[t.sym_buf+t.sym_next++]=e>>8,t.pending_buf[t.sym_buf+t.sym_next++]=s,0===e?t.dyn_ltree[2*s]++:(t.matches++,e--,t.dyn_ltree[2*(Vi[s]+Ai+1)]++,t.dyn_dtree[2*qi(e)]++),t.sym_next===t.sym_end),_tr_align:t=>{Gi(t,2,3),ji(t,256,Fi),(t=>{16===t.bi_valid?(Zi(t,t.bi_buf),t.bi_buf=0,t.bi_valid=0):t.bi_valid>=8&&(t.pending_buf[t.pending++]=255&t.bi_buf,t.bi_buf>>=8,t.bi_valid-=8)})(t)}};var ar=(t,e,s,i)=>{let r=65535&t,n=t>>>16&65535,o=0;for(;0!==s;){o=s>2e3?2e3:s,s-=o;do{r=r+e[i++]|0,n=n+r|0}while(--o);r%=65521,n%=65521}return r|n<<16};const hr=new Uint32Array((()=>{let t,e=[];for(var s=0;s<256;s++){t=s;for(var i=0;i<8;i++)t=1&t?3988292384^t>>>1:t>>>1;e[s]=t}return e})());var lr=(t,e,s,i)=>{const r=hr,n=i+s;t^=-1;for(let s=i;s<n;s++)t=t>>>8^r[255&(t^e[s])];return~t},cr={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},ur={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:dr,_tr_stored_block:pr,_tr_flush_block:fr,_tr_tally:mr,_tr_align:_r}=or,{Z_NO_FLUSH:br,Z_PARTIAL_FLUSH:gr,Z_FULL_FLUSH:yr,Z_FINISH:xr,Z_BLOCK:wr,Z_OK:vr,Z_STREAM_END:Sr,Z_STREAM_ERROR:Mr,Z_DATA_ERROR:Ar,Z_BUF_ERROR:Ir,Z_DEFAULT_COMPRESSION:Cr,Z_FILTERED:zr,Z_HUFFMAN_ONLY:Tr,Z_RLE:Pr,Z_FIXED:Br,Z_DEFAULT_STRATEGY:Er,Z_UNKNOWN:Fr,Z_DEFLATED:Rr}=ur,kr=258,Vr=262,Lr=42,Or=113,Dr=666,Ur=(t,e)=>(t.msg=cr[e],e),Nr=t=>2*t-(t>4?9:0),Wr=t=>{let e=t.length;for(;--e>=0;)t[e]=0},Hr=t=>{let e,s,i,r=t.w_size;e=t.hash_size,i=e;do{s=t.head[--i],t.head[i]=s>=r?s-r:0}while(--e);e=r,i=e;do{s=t.prev[--i],t.prev[i]=s>=r?s-r:0}while(--e)};let qr=(t,e,s)=>(e<<t.hash_shift^s)&t.hash_mask;const Zr=t=>{const e=t.state;let s=e.pending;s>t.avail_out&&(s=t.avail_out),0!==s&&(t.output.set(e.pending_buf.subarray(e.pending_out,e.pending_out+s),t.next_out),t.next_out+=s,e.pending_out+=s,t.total_out+=s,t.avail_out-=s,e.pending-=s,0===e.pending&&(e.pending_out=0))},Gr=(t,e)=>{fr(t,t.block_start>=0?t.block_start:-1,t.strstart-t.block_start,e),t.block_start=t.strstart,Zr(t.strm)},jr=(t,e)=>{t.pending_buf[t.pending++]=e},Xr=(t,e)=>{t.pending_buf[t.pending++]=e>>>8&255,t.pending_buf[t.pending++]=255&e},Yr=(t,e,s,i)=>{let r=t.avail_in;return r>i&&(r=i),0===r?0:(t.avail_in-=r,e.set(t.input.subarray(t.next_in,t.next_in+r),s),1===t.state.wrap?t.adler=ar(t.adler,e,r,s):2===t.state.wrap&&(t.adler=lr(t.adler,e,r,s)),t.next_in+=r,t.total_in+=r,r)},Jr=(t,e)=>{let s,i,r=t.max_chain_length,n=t.strstart,o=t.prev_length,a=t.nice_match;const h=t.strstart>t.w_size-Vr?t.strstart-(t.w_size-Vr):0,l=t.window,c=t.w_mask,u=t.prev,d=t.strstart+kr;let p=l[n+o-1],f=l[n+o];t.prev_length>=t.good_match&&(r>>=2),a>t.lookahead&&(a=t.lookahead);do{if(s=e,l[s+o]===f&&l[s+o-1]===p&&l[s]===l[n]&&l[++s]===l[n+1]){n+=2,s++;do{}while(l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&l[++n]===l[++s]&&n<d);if(i=kr-(d-n),n=d-kr,i>o){if(t.match_start=e,o=i,i>=a)break;p=l[n+o-1],f=l[n+o]}}}while((e=u[e&c])>h&&0!=--r);return o<=t.lookahead?o:t.lookahead},Qr=t=>{const e=t.w_size;let s,i,r;do{if(i=t.window_size-t.lookahead-t.strstart,t.strstart>=e+(e-Vr)&&(t.window.set(t.window.subarray(e,e+e-i),0),t.match_start-=e,t.strstart-=e,t.block_start-=e,t.insert>t.strstart&&(t.insert=t.strstart),Hr(t),i+=e),0===t.strm.avail_in)break;if(s=Yr(t.strm,t.window,t.strstart+t.lookahead,i),t.lookahead+=s,t.lookahead+t.insert>=3)for(r=t.strstart-t.insert,t.ins_h=t.window[r],t.ins_h=qr(t,t.ins_h,t.window[r+1]);t.insert&&(t.ins_h=qr(t,t.ins_h,t.window[r+3-1]),t.prev[r&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=r,r++,t.insert--,!(t.lookahead+t.insert<3)););}while(t.lookahead<Vr&&0!==t.strm.avail_in)},$r=(t,e)=>{let s,i,r,n=t.pending_buf_size-5>t.w_size?t.w_size:t.pending_buf_size-5,o=0,a=t.strm.avail_in;do{if(s=65535,r=t.bi_valid+42>>3,t.strm.avail_out<r)break;if(r=t.strm.avail_out-r,i=t.strstart-t.block_start,s>i+t.strm.avail_in&&(s=i+t.strm.avail_in),s>r&&(s=r),s<n&&(0===s&&e!==xr||e===br||s!==i+t.strm.avail_in))break;o=e===xr&&s===i+t.strm.avail_in?1:0,pr(t,0,0,o),t.pending_buf[t.pending-4]=s,t.pending_buf[t.pending-3]=s>>8,t.pending_buf[t.pending-2]=~s,t.pending_buf[t.pending-1]=~s>>8,Zr(t.strm),i&&(i>s&&(i=s),t.strm.output.set(t.window.subarray(t.block_start,t.block_start+i),t.strm.next_out),t.strm.next_out+=i,t.strm.avail_out-=i,t.strm.total_out+=i,t.block_start+=i,s-=i),s&&(Yr(t.strm,t.strm.output,t.strm.next_out,s),t.strm.next_out+=s,t.strm.avail_out-=s,t.strm.total_out+=s)}while(0===o);return a-=t.strm.avail_in,a&&(a>=t.w_size?(t.matches=2,t.window.set(t.strm.input.subarray(t.strm.next_in-t.w_size,t.strm.next_in),0),t.strstart=t.w_size,t.insert=t.strstart):(t.window_size-t.strstart<=a&&(t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,t.insert>t.strstart&&(t.insert=t.strstart)),t.window.set(t.strm.input.subarray(t.strm.next_in-a,t.strm.next_in),t.strstart),t.strstart+=a,t.insert+=a>t.w_size-t.insert?t.w_size-t.insert:a),t.block_start=t.strstart),t.high_water<t.strstart&&(t.high_water=t.strstart),o?4:e!==br&&e!==xr&&0===t.strm.avail_in&&t.strstart===t.block_start?2:(r=t.window_size-t.strstart,t.strm.avail_in>r&&t.block_start>=t.w_size&&(t.block_start-=t.w_size,t.strstart-=t.w_size,t.window.set(t.window.subarray(t.w_size,t.w_size+t.strstart),0),t.matches<2&&t.matches++,r+=t.w_size,t.insert>t.strstart&&(t.insert=t.strstart)),r>t.strm.avail_in&&(r=t.strm.avail_in),r&&(Yr(t.strm,t.window,t.strstart,r),t.strstart+=r,t.insert+=r>t.w_size-t.insert?t.w_size-t.insert:r),t.high_water<t.strstart&&(t.high_water=t.strstart),r=t.bi_valid+42>>3,r=t.pending_buf_size-r>65535?65535:t.pending_buf_size-r,n=r>t.w_size?t.w_size:r,i=t.strstart-t.block_start,(i>=n||(i||e===xr)&&e!==br&&0===t.strm.avail_in&&i<=r)&&(s=i>r?r:i,o=e===xr&&0===t.strm.avail_in&&s===i?1:0,pr(t,t.block_start,s,o),t.block_start+=s,Zr(t.strm)),o?3:1)},Kr=(t,e)=>{let s,i;for(;;){if(t.lookahead<Vr){if(Qr(t),t.lookahead<Vr&&e===br)return 1;if(0===t.lookahead)break}if(s=0,t.lookahead>=3&&(t.ins_h=qr(t,t.ins_h,t.window[t.strstart+3-1]),s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),0!==s&&t.strstart-s<=t.w_size-Vr&&(t.match_length=Jr(t,s)),t.match_length>=3)if(i=mr(t,t.strstart-t.match_start,t.match_length-3),t.lookahead-=t.match_length,t.match_length<=t.max_lazy_match&&t.lookahead>=3){t.match_length--;do{t.strstart++,t.ins_h=qr(t,t.ins_h,t.window[t.strstart+3-1]),s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart}while(0!=--t.match_length);t.strstart++}else t.strstart+=t.match_length,t.match_length=0,t.ins_h=t.window[t.strstart],t.ins_h=qr(t,t.ins_h,t.window[t.strstart+1]);else i=mr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++;if(i&&(Gr(t,!1),0===t.strm.avail_out))return 1}return t.insert=t.strstart<2?t.strstart:2,e===xr?(Gr(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Gr(t,!1),0===t.strm.avail_out)?1:2},tn=(t,e)=>{let s,i,r;for(;;){if(t.lookahead<Vr){if(Qr(t),t.lookahead<Vr&&e===br)return 1;if(0===t.lookahead)break}if(s=0,t.lookahead>=3&&(t.ins_h=qr(t,t.ins_h,t.window[t.strstart+3-1]),s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart),t.prev_length=t.match_length,t.prev_match=t.match_start,t.match_length=2,0!==s&&t.prev_length<t.max_lazy_match&&t.strstart-s<=t.w_size-Vr&&(t.match_length=Jr(t,s),t.match_length<=5&&(t.strategy===zr||3===t.match_length&&t.strstart-t.match_start>4096)&&(t.match_length=2)),t.prev_length>=3&&t.match_length<=t.prev_length){r=t.strstart+t.lookahead-3,i=mr(t,t.strstart-1-t.prev_match,t.prev_length-3),t.lookahead-=t.prev_length-1,t.prev_length-=2;do{++t.strstart<=r&&(t.ins_h=qr(t,t.ins_h,t.window[t.strstart+3-1]),s=t.prev[t.strstart&t.w_mask]=t.head[t.ins_h],t.head[t.ins_h]=t.strstart)}while(0!=--t.prev_length);if(t.match_available=0,t.match_length=2,t.strstart++,i&&(Gr(t,!1),0===t.strm.avail_out))return 1}else if(t.match_available){if(i=mr(t,0,t.window[t.strstart-1]),i&&Gr(t,!1),t.strstart++,t.lookahead--,0===t.strm.avail_out)return 1}else t.match_available=1,t.strstart++,t.lookahead--}return t.match_available&&(i=mr(t,0,t.window[t.strstart-1]),t.match_available=0),t.insert=t.strstart<2?t.strstart:2,e===xr?(Gr(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Gr(t,!1),0===t.strm.avail_out)?1:2};function en(t,e,s,i,r){this.good_length=t,this.max_lazy=e,this.nice_length=s,this.max_chain=i,this.func=r}const sn=[new en(0,0,0,0,$r),new en(4,4,8,4,Kr),new en(4,5,16,8,Kr),new en(4,6,32,32,Kr),new en(4,4,16,16,tn),new en(8,16,32,32,tn),new en(8,16,128,128,tn),new en(8,32,128,256,tn),new en(32,128,258,1024,tn),new en(32,258,258,4096,tn)];function rn(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Rr,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),Wr(this.dyn_ltree),Wr(this.dyn_dtree),Wr(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),Wr(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Wr(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const nn=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.status!==Lr&&57!==e.status&&69!==e.status&&73!==e.status&&91!==e.status&&103!==e.status&&e.status!==Or&&e.status!==Dr?1:0},on=t=>{if(nn(t))return Ur(t,Mr);t.total_in=t.total_out=0,t.data_type=Fr;const e=t.state;return e.pending=0,e.pending_out=0,e.wrap<0&&(e.wrap=-e.wrap),e.status=2===e.wrap?57:e.wrap?Lr:Or,t.adler=2===e.wrap?0:1,e.last_flush=-2,dr(e),vr},an=t=>{const e=on(t);var s;return e===vr&&((s=t.state).window_size=2*s.w_size,Wr(s.head),s.max_lazy_match=sn[s.level].max_lazy,s.good_match=sn[s.level].good_length,s.nice_match=sn[s.level].nice_length,s.max_chain_length=sn[s.level].max_chain,s.strstart=0,s.block_start=0,s.lookahead=0,s.insert=0,s.match_length=s.prev_length=2,s.match_available=0,s.ins_h=0),e},hn=(t,e,s,i,r,n)=>{if(!t)return Mr;let o=1;if(e===Cr&&(e=6),i<0?(o=0,i=-i):i>15&&(o=2,i-=16),r<1||r>9||s!==Rr||i<8||i>15||e<0||e>9||n<0||n>Br||8===i&&1!==o)return Ur(t,Mr);8===i&&(i=9);const a=new rn;return t.state=a,a.strm=t,a.status=Lr,a.wrap=o,a.gzhead=null,a.w_bits=i,a.w_size=1<<a.w_bits,a.w_mask=a.w_size-1,a.hash_bits=r+7,a.hash_size=1<<a.hash_bits,a.hash_mask=a.hash_size-1,a.hash_shift=~~((a.hash_bits+3-1)/3),a.window=new Uint8Array(2*a.w_size),a.head=new Uint16Array(a.hash_size),a.prev=new Uint16Array(a.w_size),a.lit_bufsize=1<<r+6,a.pending_buf_size=4*a.lit_bufsize,a.pending_buf=new Uint8Array(a.pending_buf_size),a.sym_buf=a.lit_bufsize,a.sym_end=3*(a.lit_bufsize-1),a.level=e,a.strategy=n,a.method=s,an(t)};var ln={deflateInit:(t,e)=>hn(t,e,Rr,15,8,Er),deflateInit2:hn,deflateReset:an,deflateResetKeep:on,deflateSetHeader:(t,e)=>nn(t)||2!==t.state.wrap?Mr:(t.state.gzhead=e,vr),deflate:(t,e)=>{if(nn(t)||e>wr||e<0)return t?Ur(t,Mr):Mr;const s=t.state;if(!t.output||0!==t.avail_in&&!t.input||s.status===Dr&&e!==xr)return Ur(t,0===t.avail_out?Ir:Mr);const i=s.last_flush;if(s.last_flush=e,0!==s.pending){if(Zr(t),0===t.avail_out)return s.last_flush=-1,vr}else if(0===t.avail_in&&Nr(e)<=Nr(i)&&e!==xr)return Ur(t,Ir);if(s.status===Dr&&0!==t.avail_in)return Ur(t,Ir);if(s.status===Lr&&0===s.wrap&&(s.status=Or),s.status===Lr){let e=Rr+(s.w_bits-8<<4)<<8,i=-1;if(i=s.strategy>=Tr||s.level<2?0:s.level<6?1:6===s.level?2:3,e|=i<<6,0!==s.strstart&&(e|=32),e+=31-e%31,Xr(s,e),0!==s.strstart&&(Xr(s,t.adler>>>16),Xr(s,65535&t.adler)),t.adler=1,s.status=Or,Zr(t),0!==s.pending)return s.last_flush=-1,vr}if(57===s.status)if(t.adler=0,jr(s,31),jr(s,139),jr(s,8),s.gzhead)jr(s,(s.gzhead.text?1:0)+(s.gzhead.hcrc?2:0)+(s.gzhead.extra?4:0)+(s.gzhead.name?8:0)+(s.gzhead.comment?16:0)),jr(s,255&s.gzhead.time),jr(s,s.gzhead.time>>8&255),jr(s,s.gzhead.time>>16&255),jr(s,s.gzhead.time>>24&255),jr(s,9===s.level?2:s.strategy>=Tr||s.level<2?4:0),jr(s,255&s.gzhead.os),s.gzhead.extra&&s.gzhead.extra.length&&(jr(s,255&s.gzhead.extra.length),jr(s,s.gzhead.extra.length>>8&255)),s.gzhead.hcrc&&(t.adler=lr(t.adler,s.pending_buf,s.pending,0)),s.gzindex=0,s.status=69;else if(jr(s,0),jr(s,0),jr(s,0),jr(s,0),jr(s,0),jr(s,9===s.level?2:s.strategy>=Tr||s.level<2?4:0),jr(s,3),s.status=Or,Zr(t),0!==s.pending)return s.last_flush=-1,vr;if(69===s.status){if(s.gzhead.extra){let e=s.pending,i=(65535&s.gzhead.extra.length)-s.gzindex;for(;s.pending+i>s.pending_buf_size;){let r=s.pending_buf_size-s.pending;if(s.pending_buf.set(s.gzhead.extra.subarray(s.gzindex,s.gzindex+r),s.pending),s.pending=s.pending_buf_size,s.gzhead.hcrc&&s.pending>e&&(t.adler=lr(t.adler,s.pending_buf,s.pending-e,e)),s.gzindex+=r,Zr(t),0!==s.pending)return s.last_flush=-1,vr;e=0,i-=r}let r=new Uint8Array(s.gzhead.extra);s.pending_buf.set(r.subarray(s.gzindex,s.gzindex+i),s.pending),s.pending+=i,s.gzhead.hcrc&&s.pending>e&&(t.adler=lr(t.adler,s.pending_buf,s.pending-e,e)),s.gzindex=0}s.status=73}if(73===s.status){if(s.gzhead.name){let e,i=s.pending;do{if(s.pending===s.pending_buf_size){if(s.gzhead.hcrc&&s.pending>i&&(t.adler=lr(t.adler,s.pending_buf,s.pending-i,i)),Zr(t),0!==s.pending)return s.last_flush=-1,vr;i=0}e=s.gzindex<s.gzhead.name.length?255&s.gzhead.name.charCodeAt(s.gzindex++):0,jr(s,e)}while(0!==e);s.gzhead.hcrc&&s.pending>i&&(t.adler=lr(t.adler,s.pending_buf,s.pending-i,i)),s.gzindex=0}s.status=91}if(91===s.status){if(s.gzhead.comment){let e,i=s.pending;do{if(s.pending===s.pending_buf_size){if(s.gzhead.hcrc&&s.pending>i&&(t.adler=lr(t.adler,s.pending_buf,s.pending-i,i)),Zr(t),0!==s.pending)return s.last_flush=-1,vr;i=0}e=s.gzindex<s.gzhead.comment.length?255&s.gzhead.comment.charCodeAt(s.gzindex++):0,jr(s,e)}while(0!==e);s.gzhead.hcrc&&s.pending>i&&(t.adler=lr(t.adler,s.pending_buf,s.pending-i,i))}s.status=103}if(103===s.status){if(s.gzhead.hcrc){if(s.pending+2>s.pending_buf_size&&(Zr(t),0!==s.pending))return s.last_flush=-1,vr;jr(s,255&t.adler),jr(s,t.adler>>8&255),t.adler=0}if(s.status=Or,Zr(t),0!==s.pending)return s.last_flush=-1,vr}if(0!==t.avail_in||0!==s.lookahead||e!==br&&s.status!==Dr){let i=0===s.level?$r(s,e):s.strategy===Tr?((t,e)=>{let s;for(;;){if(0===t.lookahead&&(Qr(t),0===t.lookahead)){if(e===br)return 1;break}if(t.match_length=0,s=mr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++,s&&(Gr(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===xr?(Gr(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Gr(t,!1),0===t.strm.avail_out)?1:2})(s,e):s.strategy===Pr?((t,e)=>{let s,i,r,n;const o=t.window;for(;;){if(t.lookahead<=kr){if(Qr(t),t.lookahead<=kr&&e===br)return 1;if(0===t.lookahead)break}if(t.match_length=0,t.lookahead>=3&&t.strstart>0&&(r=t.strstart-1,i=o[r],i===o[++r]&&i===o[++r]&&i===o[++r])){n=t.strstart+kr;do{}while(i===o[++r]&&i===o[++r]&&i===o[++r]&&i===o[++r]&&i===o[++r]&&i===o[++r]&&i===o[++r]&&i===o[++r]&&r<n);t.match_length=kr-(n-r),t.match_length>t.lookahead&&(t.match_length=t.lookahead)}if(t.match_length>=3?(s=mr(t,1,t.match_length-3),t.lookahead-=t.match_length,t.strstart+=t.match_length,t.match_length=0):(s=mr(t,0,t.window[t.strstart]),t.lookahead--,t.strstart++),s&&(Gr(t,!1),0===t.strm.avail_out))return 1}return t.insert=0,e===xr?(Gr(t,!0),0===t.strm.avail_out?3:4):t.sym_next&&(Gr(t,!1),0===t.strm.avail_out)?1:2})(s,e):sn[s.level].func(s,e);if(3!==i&&4!==i||(s.status=Dr),1===i||3===i)return 0===t.avail_out&&(s.last_flush=-1),vr;if(2===i&&(e===gr?_r(s):e!==wr&&(pr(s,0,0,!1),e===yr&&(Wr(s.head),0===s.lookahead&&(s.strstart=0,s.block_start=0,s.insert=0))),Zr(t),0===t.avail_out))return s.last_flush=-1,vr}return e!==xr?vr:s.wrap<=0?Sr:(2===s.wrap?(jr(s,255&t.adler),jr(s,t.adler>>8&255),jr(s,t.adler>>16&255),jr(s,t.adler>>24&255),jr(s,255&t.total_in),jr(s,t.total_in>>8&255),jr(s,t.total_in>>16&255),jr(s,t.total_in>>24&255)):(Xr(s,t.adler>>>16),Xr(s,65535&t.adler)),Zr(t),s.wrap>0&&(s.wrap=-s.wrap),0!==s.pending?vr:Sr)},deflateEnd:t=>{if(nn(t))return Mr;const e=t.state.status;return t.state=null,e===Or?Ur(t,Ar):vr},deflateSetDictionary:(t,e)=>{let s=e.length;if(nn(t))return Mr;const i=t.state,r=i.wrap;if(2===r||1===r&&i.status!==Lr||i.lookahead)return Mr;if(1===r&&(t.adler=ar(t.adler,e,s,0)),i.wrap=0,s>=i.w_size){0===r&&(Wr(i.head),i.strstart=0,i.block_start=0,i.insert=0);let t=new Uint8Array(i.w_size);t.set(e.subarray(s-i.w_size,s),0),e=t,s=i.w_size}const n=t.avail_in,o=t.next_in,a=t.input;for(t.avail_in=s,t.next_in=0,t.input=e,Qr(i);i.lookahead>=3;){let t=i.strstart,e=i.lookahead-2;do{i.ins_h=qr(i,i.ins_h,i.window[t+3-1]),i.prev[t&i.w_mask]=i.head[i.ins_h],i.head[i.ins_h]=t,t++}while(--e);i.strstart=t,i.lookahead=2,Qr(i)}return i.strstart+=i.lookahead,i.block_start=i.strstart,i.insert=i.lookahead,i.lookahead=0,i.match_length=i.prev_length=2,i.match_available=0,t.next_in=o,t.input=a,t.avail_in=n,i.wrap=r,vr},deflateInfo:"pako deflate (from Nodeca project)"};const cn=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var un=function(t){const e=Array.prototype.slice.call(arguments,1);for(;e.length;){const s=e.shift();if(s){if("object"!=typeof s)throw new TypeError(s+"must be non-object");for(const e in s)cn(s,e)&&(t[e]=s[e])}}return t},dn=t=>{let e=0;for(let s=0,i=t.length;s<i;s++)e+=t[s].length;const s=new Uint8Array(e);for(let e=0,i=0,r=t.length;e<r;e++){let r=t[e];s.set(r,i),i+=r.length}return s};let pn=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(t){pn=!1}const fn=new Uint8Array(256);for(let t=0;t<256;t++)fn[t]=t>=252?6:t>=248?5:t>=240?4:t>=224?3:t>=192?2:1;fn[254]=fn[254]=1;var mn=t=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(t);let e,s,i,r,n,o=t.length,a=0;for(r=0;r<o;r++)s=t.charCodeAt(r),55296==(64512&s)&&r+1<o&&(i=t.charCodeAt(r+1),56320==(64512&i)&&(s=65536+(s-55296<<10)+(i-56320),r++)),a+=s<128?1:s<2048?2:s<65536?3:4;for(e=new Uint8Array(a),n=0,r=0;n<a;r++)s=t.charCodeAt(r),55296==(64512&s)&&r+1<o&&(i=t.charCodeAt(r+1),56320==(64512&i)&&(s=65536+(s-55296<<10)+(i-56320),r++)),s<128?e[n++]=s:s<2048?(e[n++]=192|s>>>6,e[n++]=128|63&s):s<65536?(e[n++]=224|s>>>12,e[n++]=128|s>>>6&63,e[n++]=128|63&s):(e[n++]=240|s>>>18,e[n++]=128|s>>>12&63,e[n++]=128|s>>>6&63,e[n++]=128|63&s);return e},_n=(t,e)=>{const s=e||t.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(t.subarray(0,e));let i,r;const n=new Array(2*s);for(r=0,i=0;i<s;){let e=t[i++];if(e<128){n[r++]=e;continue}let o=fn[e];if(o>4)n[r++]=65533,i+=o-1;else{for(e&=2===o?31:3===o?15:7;o>1&&i<s;)e=e<<6|63&t[i++],o--;o>1?n[r++]=65533:e<65536?n[r++]=e:(e-=65536,n[r++]=55296|e>>10&1023,n[r++]=56320|1023&e)}}return((t,e)=>{if(e<65534&&t.subarray&&pn)return String.fromCharCode.apply(null,t.length===e?t:t.subarray(0,e));let s="";for(let i=0;i<e;i++)s+=String.fromCharCode(t[i]);return s})(n,r)},bn=(t,e)=>{(e=e||t.length)>t.length&&(e=t.length);let s=e-1;for(;s>=0&&128==(192&t[s]);)s--;return s<0||0===s?e:s+fn[t[s]]>e?s:e};var gn=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const yn=Object.prototype.toString,{Z_NO_FLUSH:xn,Z_SYNC_FLUSH:wn,Z_FULL_FLUSH:vn,Z_FINISH:Sn,Z_OK:Mn,Z_STREAM_END:An,Z_DEFAULT_COMPRESSION:In,Z_DEFAULT_STRATEGY:Cn,Z_DEFLATED:zn}=ur;function Tn(t){this.options=un({level:In,method:zn,chunkSize:16384,windowBits:15,memLevel:8,strategy:Cn},t||{});let e=this.options;e.raw&&e.windowBits>0?e.windowBits=-e.windowBits:e.gzip&&e.windowBits>0&&e.windowBits<16&&(e.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new gn,this.strm.avail_out=0;let s=ln.deflateInit2(this.strm,e.level,e.method,e.windowBits,e.memLevel,e.strategy);if(s!==Mn)throw new Error(cr[s]);if(e.header&&ln.deflateSetHeader(this.strm,e.header),e.dictionary){let t;if(t="string"==typeof e.dictionary?mn(e.dictionary):"[object ArrayBuffer]"===yn.call(e.dictionary)?new Uint8Array(e.dictionary):e.dictionary,s=ln.deflateSetDictionary(this.strm,t),s!==Mn)throw new Error(cr[s]);this._dict_set=!0}}function Pn(t,e){const s=new Tn(e);if(s.push(t,!0),s.err)throw s.msg||cr[s.err];return s.result}Tn.prototype.push=function(t,e){const s=this.strm,i=this.options.chunkSize;let r,n;if(this.ended)return!1;for(n=e===~~e?e:!0===e?Sn:xn,"string"==typeof t?s.input=mn(t):"[object ArrayBuffer]"===yn.call(t)?s.input=new Uint8Array(t):s.input=t,s.next_in=0,s.avail_in=s.input.length;;)if(0===s.avail_out&&(s.output=new Uint8Array(i),s.next_out=0,s.avail_out=i),(n===wn||n===vn)&&s.avail_out<=6)this.onData(s.output.subarray(0,s.next_out)),s.avail_out=0;else{if(r=ln.deflate(s,n),r===An)return s.next_out>0&&this.onData(s.output.subarray(0,s.next_out)),r=ln.deflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===Mn;if(0!==s.avail_out){if(n>0&&s.next_out>0)this.onData(s.output.subarray(0,s.next_out)),s.avail_out=0;else if(0===s.avail_in)break}else this.onData(s.output)}return!0},Tn.prototype.onData=function(t){this.chunks.push(t)},Tn.prototype.onEnd=function(t){t===Mn&&(this.result=dn(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Bn={Deflate:Tn,deflate:Pn,deflateRaw:function(t,e){return(e=e||{}).raw=!0,Pn(t,e)},gzip:function(t,e){return(e=e||{}).gzip=!0,Pn(t,e)}};const En=16209;var Fn=function(t,e){let s,i,r,n,o,a,h,l,c,u,d,p,f,m,_,b,g,y,x,w,v,S,M,A;const I=t.state;s=t.next_in,M=t.input,i=s+(t.avail_in-5),r=t.next_out,A=t.output,n=r-(e-t.avail_out),o=r+(t.avail_out-257),a=I.dmax,h=I.wsize,l=I.whave,c=I.wnext,u=I.window,d=I.hold,p=I.bits,f=I.lencode,m=I.distcode,_=(1<<I.lenbits)-1,b=(1<<I.distbits)-1;t:do{p<15&&(d+=M[s++]<<p,p+=8,d+=M[s++]<<p,p+=8),g=f[d&_];e:for(;;){if(y=g>>>24,d>>>=y,p-=y,y=g>>>16&255,0===y)A[r++]=65535&g;else{if(!(16&y)){if(64&y){if(32&y){I.mode=16191;break t}t.msg="invalid literal/length code",I.mode=En;break t}g=f[(65535&g)+(d&(1<<y)-1)];continue e}for(x=65535&g,y&=15,y&&(p<y&&(d+=M[s++]<<p,p+=8),x+=d&(1<<y)-1,d>>>=y,p-=y),p<15&&(d+=M[s++]<<p,p+=8,d+=M[s++]<<p,p+=8),g=m[d&b];;){if(y=g>>>24,d>>>=y,p-=y,y=g>>>16&255,16&y){if(w=65535&g,y&=15,p<y&&(d+=M[s++]<<p,p+=8,p<y&&(d+=M[s++]<<p,p+=8)),w+=d&(1<<y)-1,w>a){t.msg="invalid distance too far back",I.mode=En;break t}if(d>>>=y,p-=y,y=r-n,w>y){if(y=w-y,y>l&&I.sane){t.msg="invalid distance too far back",I.mode=En;break t}if(v=0,S=u,0===c){if(v+=h-y,y<x){x-=y;do{A[r++]=u[v++]}while(--y);v=r-w,S=A}}else if(c<y){if(v+=h+c-y,y-=c,y<x){x-=y;do{A[r++]=u[v++]}while(--y);if(v=0,c<x){y=c,x-=y;do{A[r++]=u[v++]}while(--y);v=r-w,S=A}}}else if(v+=c-y,y<x){x-=y;do{A[r++]=u[v++]}while(--y);v=r-w,S=A}for(;x>2;)A[r++]=S[v++],A[r++]=S[v++],A[r++]=S[v++],x-=3;x&&(A[r++]=S[v++],x>1&&(A[r++]=S[v++]))}else{v=r-w;do{A[r++]=A[v++],A[r++]=A[v++],A[r++]=A[v++],x-=3}while(x>2);x&&(A[r++]=A[v++],x>1&&(A[r++]=A[v++]))}break}if(64&y){t.msg="invalid distance code",I.mode=En;break t}g=m[(65535&g)+(d&(1<<y)-1)]}}break}}while(s<i&&r<o);x=p>>3,s-=x,p-=x<<3,d&=(1<<p)-1,t.next_in=s,t.next_out=r,t.avail_in=s<i?i-s+5:5-(s-i),t.avail_out=r<o?o-r+257:257-(r-o),I.hold=d,I.bits=p};const Rn=15,kn=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Vn=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Ln=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),On=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var Dn=(t,e,s,i,r,n,o,a)=>{const h=a.bits;let l,c,u,d,p,f,m=0,_=0,b=0,g=0,y=0,x=0,w=0,v=0,S=0,M=0,A=null;const I=new Uint16Array(16),C=new Uint16Array(16);let z,T,P,B=null;for(m=0;m<=Rn;m++)I[m]=0;for(_=0;_<i;_++)I[e[s+_]]++;for(y=h,g=Rn;g>=1&&0===I[g];g--);if(y>g&&(y=g),0===g)return r[n++]=20971520,r[n++]=20971520,a.bits=1,0;for(b=1;b<g&&0===I[b];b++);for(y<b&&(y=b),v=1,m=1;m<=Rn;m++)if(v<<=1,v-=I[m],v<0)return-1;if(v>0&&(0===t||1!==g))return-1;for(C[1]=0,m=1;m<Rn;m++)C[m+1]=C[m]+I[m];for(_=0;_<i;_++)0!==e[s+_]&&(o[C[e[s+_]]++]=_);if(0===t?(A=B=o,f=20):1===t?(A=kn,B=Vn,f=257):(A=Ln,B=On,f=0),M=0,_=0,m=b,p=n,x=y,w=0,u=-1,S=1<<y,d=S-1,1===t&&S>852||2===t&&S>592)return 1;for(;;){z=m-w,o[_]+1<f?(T=0,P=o[_]):o[_]>=f?(T=B[o[_]-f],P=A[o[_]-f]):(T=96,P=0),l=1<<m-w,c=1<<x,b=c;do{c-=l,r[p+(M>>w)+c]=z<<24|T<<16|P}while(0!==c);for(l=1<<m-1;M&l;)l>>=1;if(0!==l?(M&=l-1,M+=l):M=0,_++,0==--I[m]){if(m===g)break;m=e[s+o[_]]}if(m>y&&(M&d)!==u){for(0===w&&(w=y),p+=b,x=m-w,v=1<<x;x+w<g&&(v-=I[x+w],!(v<=0));)x++,v<<=1;if(S+=1<<x,1===t&&S>852||2===t&&S>592)return 1;u=M&d,r[u]=y<<24|x<<16|p-n}}return 0!==M&&(r[p+M]=m-w<<24|64<<16),a.bits=y,0};const{Z_FINISH:Un,Z_BLOCK:Nn,Z_TREES:Wn,Z_OK:Hn,Z_STREAM_END:qn,Z_NEED_DICT:Zn,Z_STREAM_ERROR:Gn,Z_DATA_ERROR:jn,Z_MEM_ERROR:Xn,Z_BUF_ERROR:Yn,Z_DEFLATED:Jn}=ur,Qn=16180,$n=16190,Kn=16191,to=16192,eo=16194,so=16199,io=16200,ro=16206,no=16209,oo=t=>(t>>>24&255)+(t>>>8&65280)+((65280&t)<<8)+((255&t)<<24);function ao(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const ho=t=>{if(!t)return 1;const e=t.state;return!e||e.strm!==t||e.mode<Qn||e.mode>16211?1:0},lo=t=>{if(ho(t))return Gn;const e=t.state;return t.total_in=t.total_out=e.total=0,t.msg="",e.wrap&&(t.adler=1&e.wrap),e.mode=Qn,e.last=0,e.havedict=0,e.flags=-1,e.dmax=32768,e.head=null,e.hold=0,e.bits=0,e.lencode=e.lendyn=new Int32Array(852),e.distcode=e.distdyn=new Int32Array(592),e.sane=1,e.back=-1,Hn},co=t=>{if(ho(t))return Gn;const e=t.state;return e.wsize=0,e.whave=0,e.wnext=0,lo(t)},uo=(t,e)=>{let s;if(ho(t))return Gn;const i=t.state;return e<0?(s=0,e=-e):(s=5+(e>>4),e<48&&(e&=15)),e&&(e<8||e>15)?Gn:(null!==i.window&&i.wbits!==e&&(i.window=null),i.wrap=s,i.wbits=e,co(t))},po=(t,e)=>{if(!t)return Gn;const s=new ao;t.state=s,s.strm=t,s.window=null,s.mode=Qn;const i=uo(t,e);return i!==Hn&&(t.state=null),i};let fo,mo,_o=!0;const bo=t=>{if(_o){fo=new Int32Array(512),mo=new Int32Array(32);let e=0;for(;e<144;)t.lens[e++]=8;for(;e<256;)t.lens[e++]=9;for(;e<280;)t.lens[e++]=7;for(;e<288;)t.lens[e++]=8;for(Dn(1,t.lens,0,288,fo,0,t.work,{bits:9}),e=0;e<32;)t.lens[e++]=5;Dn(2,t.lens,0,32,mo,0,t.work,{bits:5}),_o=!1}t.lencode=fo,t.lenbits=9,t.distcode=mo,t.distbits=5},go=(t,e,s,i)=>{let r;const n=t.state;return null===n.window&&(n.wsize=1<<n.wbits,n.wnext=0,n.whave=0,n.window=new Uint8Array(n.wsize)),i>=n.wsize?(n.window.set(e.subarray(s-n.wsize,s),0),n.wnext=0,n.whave=n.wsize):(r=n.wsize-n.wnext,r>i&&(r=i),n.window.set(e.subarray(s-i,s-i+r),n.wnext),(i-=r)?(n.window.set(e.subarray(s-i,s),0),n.wnext=i,n.whave=n.wsize):(n.wnext+=r,n.wnext===n.wsize&&(n.wnext=0),n.whave<n.wsize&&(n.whave+=r))),0};var yo={inflateReset:co,inflateReset2:uo,inflateResetKeep:lo,inflateInit:t=>po(t,15),inflateInit2:po,inflate:(t,e)=>{let s,i,r,n,o,a,h,l,c,u,d,p,f,m,_,b,g,y,x,w,v,S,M=0;const A=new Uint8Array(4);let I,C;const z=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(ho(t)||!t.output||!t.input&&0!==t.avail_in)return Gn;s=t.state,s.mode===Kn&&(s.mode=to),o=t.next_out,r=t.output,h=t.avail_out,n=t.next_in,i=t.input,a=t.avail_in,l=s.hold,c=s.bits,u=a,d=h,S=Hn;t:for(;;)switch(s.mode){case Qn:if(0===s.wrap){s.mode=to;break}for(;c<16;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(2&s.wrap&&35615===l){0===s.wbits&&(s.wbits=15),s.check=0,A[0]=255&l,A[1]=l>>>8&255,s.check=lr(s.check,A,2,0),l=0,c=0,s.mode=16181;break}if(s.head&&(s.head.done=!1),!(1&s.wrap)||(((255&l)<<8)+(l>>8))%31){t.msg="incorrect header check",s.mode=no;break}if((15&l)!==Jn){t.msg="unknown compression method",s.mode=no;break}if(l>>>=4,c-=4,v=8+(15&l),0===s.wbits&&(s.wbits=v),v>15||v>s.wbits){t.msg="invalid window size",s.mode=no;break}s.dmax=1<<s.wbits,s.flags=0,t.adler=s.check=1,s.mode=512&l?16189:Kn,l=0,c=0;break;case 16181:for(;c<16;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(s.flags=l,(255&s.flags)!==Jn){t.msg="unknown compression method",s.mode=no;break}if(57344&s.flags){t.msg="unknown header flags set",s.mode=no;break}s.head&&(s.head.text=l>>8&1),512&s.flags&&4&s.wrap&&(A[0]=255&l,A[1]=l>>>8&255,s.check=lr(s.check,A,2,0)),l=0,c=0,s.mode=16182;case 16182:for(;c<32;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.head&&(s.head.time=l),512&s.flags&&4&s.wrap&&(A[0]=255&l,A[1]=l>>>8&255,A[2]=l>>>16&255,A[3]=l>>>24&255,s.check=lr(s.check,A,4,0)),l=0,c=0,s.mode=16183;case 16183:for(;c<16;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.head&&(s.head.xflags=255&l,s.head.os=l>>8),512&s.flags&&4&s.wrap&&(A[0]=255&l,A[1]=l>>>8&255,s.check=lr(s.check,A,2,0)),l=0,c=0,s.mode=16184;case 16184:if(1024&s.flags){for(;c<16;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.length=l,s.head&&(s.head.extra_len=l),512&s.flags&&4&s.wrap&&(A[0]=255&l,A[1]=l>>>8&255,s.check=lr(s.check,A,2,0)),l=0,c=0}else s.head&&(s.head.extra=null);s.mode=16185;case 16185:if(1024&s.flags&&(p=s.length,p>a&&(p=a),p&&(s.head&&(v=s.head.extra_len-s.length,s.head.extra||(s.head.extra=new Uint8Array(s.head.extra_len)),s.head.extra.set(i.subarray(n,n+p),v)),512&s.flags&&4&s.wrap&&(s.check=lr(s.check,i,p,n)),a-=p,n+=p,s.length-=p),s.length))break t;s.length=0,s.mode=16186;case 16186:if(2048&s.flags){if(0===a)break t;p=0;do{v=i[n+p++],s.head&&v&&s.length<65536&&(s.head.name+=String.fromCharCode(v))}while(v&&p<a);if(512&s.flags&&4&s.wrap&&(s.check=lr(s.check,i,p,n)),a-=p,n+=p,v)break t}else s.head&&(s.head.name=null);s.length=0,s.mode=16187;case 16187:if(4096&s.flags){if(0===a)break t;p=0;do{v=i[n+p++],s.head&&v&&s.length<65536&&(s.head.comment+=String.fromCharCode(v))}while(v&&p<a);if(512&s.flags&&4&s.wrap&&(s.check=lr(s.check,i,p,n)),a-=p,n+=p,v)break t}else s.head&&(s.head.comment=null);s.mode=16188;case 16188:if(512&s.flags){for(;c<16;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(4&s.wrap&&l!==(65535&s.check)){t.msg="header crc mismatch",s.mode=no;break}l=0,c=0}s.head&&(s.head.hcrc=s.flags>>9&1,s.head.done=!0),t.adler=s.check=0,s.mode=Kn;break;case 16189:for(;c<32;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}t.adler=s.check=oo(l),l=0,c=0,s.mode=$n;case $n:if(0===s.havedict)return t.next_out=o,t.avail_out=h,t.next_in=n,t.avail_in=a,s.hold=l,s.bits=c,Zn;t.adler=s.check=1,s.mode=Kn;case Kn:if(e===Nn||e===Wn)break t;case to:if(s.last){l>>>=7&c,c-=7&c,s.mode=ro;break}for(;c<3;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}switch(s.last=1&l,l>>>=1,c-=1,3&l){case 0:s.mode=16193;break;case 1:if(bo(s),s.mode=so,e===Wn){l>>>=2,c-=2;break t}break;case 2:s.mode=16196;break;case 3:t.msg="invalid block type",s.mode=no}l>>>=2,c-=2;break;case 16193:for(l>>>=7&c,c-=7&c;c<32;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if((65535&l)!=(l>>>16^65535)){t.msg="invalid stored block lengths",s.mode=no;break}if(s.length=65535&l,l=0,c=0,s.mode=eo,e===Wn)break t;case eo:s.mode=16195;case 16195:if(p=s.length,p){if(p>a&&(p=a),p>h&&(p=h),0===p)break t;r.set(i.subarray(n,n+p),o),a-=p,n+=p,h-=p,o+=p,s.length-=p;break}s.mode=Kn;break;case 16196:for(;c<14;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(s.nlen=257+(31&l),l>>>=5,c-=5,s.ndist=1+(31&l),l>>>=5,c-=5,s.ncode=4+(15&l),l>>>=4,c-=4,s.nlen>286||s.ndist>30){t.msg="too many length or distance symbols",s.mode=no;break}s.have=0,s.mode=16197;case 16197:for(;s.have<s.ncode;){for(;c<3;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.lens[z[s.have++]]=7&l,l>>>=3,c-=3}for(;s.have<19;)s.lens[z[s.have++]]=0;if(s.lencode=s.lendyn,s.lenbits=7,I={bits:s.lenbits},S=Dn(0,s.lens,0,19,s.lencode,0,s.work,I),s.lenbits=I.bits,S){t.msg="invalid code lengths set",s.mode=no;break}s.have=0,s.mode=16198;case 16198:for(;s.have<s.nlen+s.ndist;){for(;M=s.lencode[l&(1<<s.lenbits)-1],_=M>>>24,b=M>>>16&255,g=65535&M,!(_<=c);){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(g<16)l>>>=_,c-=_,s.lens[s.have++]=g;else{if(16===g){for(C=_+2;c<C;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(l>>>=_,c-=_,0===s.have){t.msg="invalid bit length repeat",s.mode=no;break}v=s.lens[s.have-1],p=3+(3&l),l>>>=2,c-=2}else if(17===g){for(C=_+3;c<C;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}l>>>=_,c-=_,v=0,p=3+(7&l),l>>>=3,c-=3}else{for(C=_+7;c<C;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}l>>>=_,c-=_,v=0,p=11+(127&l),l>>>=7,c-=7}if(s.have+p>s.nlen+s.ndist){t.msg="invalid bit length repeat",s.mode=no;break}for(;p--;)s.lens[s.have++]=v}}if(s.mode===no)break;if(0===s.lens[256]){t.msg="invalid code -- missing end-of-block",s.mode=no;break}if(s.lenbits=9,I={bits:s.lenbits},S=Dn(1,s.lens,0,s.nlen,s.lencode,0,s.work,I),s.lenbits=I.bits,S){t.msg="invalid literal/lengths set",s.mode=no;break}if(s.distbits=6,s.distcode=s.distdyn,I={bits:s.distbits},S=Dn(2,s.lens,s.nlen,s.ndist,s.distcode,0,s.work,I),s.distbits=I.bits,S){t.msg="invalid distances set",s.mode=no;break}if(s.mode=so,e===Wn)break t;case so:s.mode=io;case io:if(a>=6&&h>=258){t.next_out=o,t.avail_out=h,t.next_in=n,t.avail_in=a,s.hold=l,s.bits=c,Fn(t,d),o=t.next_out,r=t.output,h=t.avail_out,n=t.next_in,i=t.input,a=t.avail_in,l=s.hold,c=s.bits,s.mode===Kn&&(s.back=-1);break}for(s.back=0;M=s.lencode[l&(1<<s.lenbits)-1],_=M>>>24,b=M>>>16&255,g=65535&M,!(_<=c);){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(b&&!(240&b)){for(y=_,x=b,w=g;M=s.lencode[w+((l&(1<<y+x)-1)>>y)],_=M>>>24,b=M>>>16&255,g=65535&M,!(y+_<=c);){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}l>>>=y,c-=y,s.back+=y}if(l>>>=_,c-=_,s.back+=_,s.length=g,0===b){s.mode=16205;break}if(32&b){s.back=-1,s.mode=Kn;break}if(64&b){t.msg="invalid literal/length code",s.mode=no;break}s.extra=15&b,s.mode=16201;case 16201:if(s.extra){for(C=s.extra;c<C;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.length+=l&(1<<s.extra)-1,l>>>=s.extra,c-=s.extra,s.back+=s.extra}s.was=s.length,s.mode=16202;case 16202:for(;M=s.distcode[l&(1<<s.distbits)-1],_=M>>>24,b=M>>>16&255,g=65535&M,!(_<=c);){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(!(240&b)){for(y=_,x=b,w=g;M=s.distcode[w+((l&(1<<y+x)-1)>>y)],_=M>>>24,b=M>>>16&255,g=65535&M,!(y+_<=c);){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}l>>>=y,c-=y,s.back+=y}if(l>>>=_,c-=_,s.back+=_,64&b){t.msg="invalid distance code",s.mode=no;break}s.offset=g,s.extra=15&b,s.mode=16203;case 16203:if(s.extra){for(C=s.extra;c<C;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}s.offset+=l&(1<<s.extra)-1,l>>>=s.extra,c-=s.extra,s.back+=s.extra}if(s.offset>s.dmax){t.msg="invalid distance too far back",s.mode=no;break}s.mode=16204;case 16204:if(0===h)break t;if(p=d-h,s.offset>p){if(p=s.offset-p,p>s.whave&&s.sane){t.msg="invalid distance too far back",s.mode=no;break}p>s.wnext?(p-=s.wnext,f=s.wsize-p):f=s.wnext-p,p>s.length&&(p=s.length),m=s.window}else m=r,f=o-s.offset,p=s.length;p>h&&(p=h),h-=p,s.length-=p;do{r[o++]=m[f++]}while(--p);0===s.length&&(s.mode=io);break;case 16205:if(0===h)break t;r[o++]=s.length,h--,s.mode=io;break;case ro:if(s.wrap){for(;c<32;){if(0===a)break t;a--,l|=i[n++]<<c,c+=8}if(d-=h,t.total_out+=d,s.total+=d,4&s.wrap&&d&&(t.adler=s.check=s.flags?lr(s.check,r,d,o-d):ar(s.check,r,d,o-d)),d=h,4&s.wrap&&(s.flags?l:oo(l))!==s.check){t.msg="incorrect data check",s.mode=no;break}l=0,c=0}s.mode=16207;case 16207:if(s.wrap&&s.flags){for(;c<32;){if(0===a)break t;a--,l+=i[n++]<<c,c+=8}if(4&s.wrap&&l!==(4294967295&s.total)){t.msg="incorrect length check",s.mode=no;break}l=0,c=0}s.mode=16208;case 16208:S=qn;break t;case no:S=jn;break t;case 16210:return Xn;default:return Gn}return t.next_out=o,t.avail_out=h,t.next_in=n,t.avail_in=a,s.hold=l,s.bits=c,(s.wsize||d!==t.avail_out&&s.mode<no&&(s.mode<ro||e!==Un))&&go(t,t.output,t.next_out,d-t.avail_out),u-=t.avail_in,d-=t.avail_out,t.total_in+=u,t.total_out+=d,s.total+=d,4&s.wrap&&d&&(t.adler=s.check=s.flags?lr(s.check,r,d,t.next_out-d):ar(s.check,r,d,t.next_out-d)),t.data_type=s.bits+(s.last?64:0)+(s.mode===Kn?128:0)+(s.mode===so||s.mode===eo?256:0),(0===u&&0===d||e===Un)&&S===Hn&&(S=Yn),S},inflateEnd:t=>{if(ho(t))return Gn;let e=t.state;return e.window&&(e.window=null),t.state=null,Hn},inflateGetHeader:(t,e)=>{if(ho(t))return Gn;const s=t.state;return 2&s.wrap?(s.head=e,e.done=!1,Hn):Gn},inflateSetDictionary:(t,e)=>{const s=e.length;let i,r,n;return ho(t)?Gn:(i=t.state,0!==i.wrap&&i.mode!==$n?Gn:i.mode===$n&&(r=1,r=ar(r,e,s,0),r!==i.check)?jn:(n=go(t,e,s,s),n?(i.mode=16210,Xn):(i.havedict=1,Hn)))},inflateInfo:"pako inflate (from Nodeca project)"};var xo=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const wo=Object.prototype.toString,{Z_NO_FLUSH:vo,Z_FINISH:So,Z_OK:Mo,Z_STREAM_END:Ao,Z_NEED_DICT:Io,Z_STREAM_ERROR:Co,Z_DATA_ERROR:zo,Z_MEM_ERROR:To}=ur;function Po(t){this.options=un({chunkSize:65536,windowBits:15,to:""},t||{});const e=this.options;e.raw&&e.windowBits>=0&&e.windowBits<16&&(e.windowBits=-e.windowBits,0===e.windowBits&&(e.windowBits=-15)),!(e.windowBits>=0&&e.windowBits<16)||t&&t.windowBits||(e.windowBits+=32),e.windowBits>15&&e.windowBits<48&&(15&e.windowBits||(e.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new gn,this.strm.avail_out=0;let s=yo.inflateInit2(this.strm,e.windowBits);if(s!==Mo)throw new Error(cr[s]);if(this.header=new xo,yo.inflateGetHeader(this.strm,this.header),e.dictionary&&("string"==typeof e.dictionary?e.dictionary=mn(e.dictionary):"[object ArrayBuffer]"===wo.call(e.dictionary)&&(e.dictionary=new Uint8Array(e.dictionary)),e.raw&&(s=yo.inflateSetDictionary(this.strm,e.dictionary),s!==Mo)))throw new Error(cr[s])}function Bo(t,e){const s=new Po(e);if(s.push(t),s.err)throw s.msg||cr[s.err];return s.result}Po.prototype.push=function(t,e){const s=this.strm,i=this.options.chunkSize,r=this.options.dictionary;let n,o,a;if(this.ended)return!1;for(o=e===~~e?e:!0===e?So:vo,"[object ArrayBuffer]"===wo.call(t)?s.input=new Uint8Array(t):s.input=t,s.next_in=0,s.avail_in=s.input.length;;){for(0===s.avail_out&&(s.output=new Uint8Array(i),s.next_out=0,s.avail_out=i),n=yo.inflate(s,o),n===Io&&r&&(n=yo.inflateSetDictionary(s,r),n===Mo?n=yo.inflate(s,o):n===zo&&(n=Io));s.avail_in>0&&n===Ao&&s.state.wrap>0&&0!==t[s.next_in];)yo.inflateReset(s),n=yo.inflate(s,o);switch(n){case Co:case zo:case Io:case To:return this.onEnd(n),this.ended=!0,!1}if(a=s.avail_out,s.next_out&&(0===s.avail_out||n===Ao))if("string"===this.options.to){let t=bn(s.output,s.next_out),e=s.next_out-t,r=_n(s.output,t);s.next_out=e,s.avail_out=i-e,e&&s.output.set(s.output.subarray(t,t+e),0),this.onData(r)}else this.onData(s.output.length===s.next_out?s.output:s.output.subarray(0,s.next_out));if(n!==Mo||0!==a){if(n===Ao)return n=yo.inflateEnd(this.strm),this.onEnd(n),this.ended=!0,!0;if(0===s.avail_in)break}}return!0},Po.prototype.onData=function(t){this.chunks.push(t)},Po.prototype.onEnd=function(t){t===Mo&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=dn(this.chunks)),this.chunks=[],this.err=t,this.msg=this.strm.msg};var Eo={Inflate:Po,inflate:Bo,inflateRaw:function(t,e){return(e=e||{}).raw=!0,Bo(t,e)},ungzip:Bo};const{Deflate:Fo,deflate:Ro,deflateRaw:ko,gzip:Vo}=Bn,{Inflate:Lo,inflate:Oo,inflateRaw:Do,ungzip:Uo}=Eo;var No={Deflate:Fo,deflate:Ro,deflateRaw:ko,gzip:Vo,Inflate:Lo,inflate:Oo,inflateRaw:Do,ungzip:Uo,constants:ur};class Wo{constructor(t){ot(this,"id"),ot(this,"thread"),this.id=this.getId(),this.thread=t,this.thread.actions[this.id]=t=>this.execute(t)}}const Ho=new Int32Array(2),qo=new Float32Array(Ho.buffer),Zo=new Float64Array(Ho.buffer),Go=1===new Uint16Array(new Uint8Array([1,0]).buffer)[0];var jo,Xo;(Xo=jo||(jo={}))[Xo.UTF8_BYTES=1]="UTF8_BYTES",Xo[Xo.UTF16_STRING=2]="UTF16_STRING";class Yo{constructor(t){this.bytes_=t,this.position_=0,this.text_decoder_=new TextDecoder}static allocate(t){return new Yo(new Uint8Array(t))}clear(){this.position_=0}bytes(){return this.bytes_}position(){return this.position_}setPosition(t){this.position_=t}capacity(){return this.bytes_.length}readInt8(t){return this.readUint8(t)<<24>>24}readUint8(t){return this.bytes_[t]}readInt16(t){return this.readUint16(t)<<16>>16}readUint16(t){return this.bytes_[t]|this.bytes_[t+1]<<8}readInt32(t){return this.bytes_[t]|this.bytes_[t+1]<<8|this.bytes_[t+2]<<16|this.bytes_[t+3]<<24}readUint32(t){return this.readInt32(t)>>>0}readInt64(t){return BigInt.asIntN(64,BigInt(this.readUint32(t))+(BigInt(this.readUint32(t+4))<<BigInt(32)))}readUint64(t){return BigInt.asUintN(64,BigInt(this.readUint32(t))+(BigInt(this.readUint32(t+4))<<BigInt(32)))}readFloat32(t){return Ho[0]=this.readInt32(t),qo[0]}readFloat64(t){return Ho[Go?0:1]=this.readInt32(t),Ho[Go?1:0]=this.readInt32(t+4),Zo[0]}writeInt8(t,e){this.bytes_[t]=e}writeUint8(t,e){this.bytes_[t]=e}writeInt16(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8}writeUint16(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8}writeInt32(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8,this.bytes_[t+2]=e>>16,this.bytes_[t+3]=e>>24}writeUint32(t,e){this.bytes_[t]=e,this.bytes_[t+1]=e>>8,this.bytes_[t+2]=e>>16,this.bytes_[t+3]=e>>24}writeInt64(t,e){this.writeInt32(t,Number(BigInt.asIntN(32,e))),this.writeInt32(t+4,Number(BigInt.asIntN(32,e>>BigInt(32))))}writeUint64(t,e){this.writeUint32(t,Number(BigInt.asUintN(32,e))),this.writeUint32(t+4,Number(BigInt.asUintN(32,e>>BigInt(32))))}writeFloat32(t,e){qo[0]=e,this.writeInt32(t,Ho[0])}writeFloat64(t,e){Zo[0]=e,this.writeInt32(t,Ho[Go?0:1]),this.writeInt32(t+4,Ho[Go?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+4+4)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let t="";for(let e=0;e<4;e++)t+=String.fromCharCode(this.readInt8(this.position_+4+e));return t}__offset(t,e){const s=t-this.readInt32(t);return e<this.readInt16(s)?this.readInt16(s+e):0}__union(t,e){return t.bb_pos=e+this.readInt32(e),t.bb=this,t}__string(t,e){t+=this.readInt32(t);const s=this.readInt32(t);t+=4;const i=this.bytes_.subarray(t,t+s);return e===jo.UTF8_BYTES?i:this.text_decoder_.decode(i)}__union_with_string(t,e){return"string"==typeof t?this.__string(e):this.__union(t,e)}__indirect(t){return t+this.readInt32(t)}__vector(t){return t+this.readInt32(t)+4}__vector_len(t){return this.readInt32(t+this.readInt32(t))}__has_identifier(t){if(4!=t.length)throw new Error("FlatBuffers: file identifier must be length 4");for(let e=0;e<4;e++)if(t.charCodeAt(e)!=this.readInt8(this.position()+4+e))return!1;return!0}createScalarList(t,e){const s=[];for(let i=0;i<e;++i){const e=t(i);null!==e&&s.push(e)}return s}createObjList(t,e){const s=[];for(let i=0;i<e;++i){const e=t(i);null!==e&&s.push(e.unpack())}return s}}const Jo=1.25,Qo=65535,$o=Math.pow(2,-24),Ko=Symbol("SKIP_GENERATION");function ta(t){return function(t){return t.index?t.index.count:t.attributes.position.count}(t)/3}function ea(t,e){if(!t.index){const s=t.attributes.position.count,i=function(t,e=ArrayBuffer){return t>65535?new Uint32Array(new e(4*t)):new Uint16Array(new e(2*t))}(s,e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);t.setIndex(new Ms(i,1));for(let t=0;t<s;t++)i[t]=t}}function sa(t){const e=ta(t),s=t.drawRange,i=s.start/3,r=(s.start+s.count)/3,n=Math.max(0,i),o=Math.min(e,r)-n;return[{offset:Math.floor(n),count:Math.floor(o)}]}function ia(t){if(!t.groups||!t.groups.length)return sa(t);const e=[],s=new Set,i=t.drawRange,r=i.start/3,n=(i.start+i.count)/3;for(const e of t.groups){const t=e.start/3,i=(e.start+e.count)/3;s.add(Math.max(r,t)),s.add(Math.min(n,i))}const o=Array.from(s.values()).sort(((t,e)=>t-e));for(let t=0;t<o.length-1;t++){const s=o[t],i=o[t+1];e.push({offset:Math.floor(s),count:Math.floor(i-s)})}return e}function ra(t,e,s){return s.min.x=e[t],s.min.y=e[t+1],s.min.z=e[t+2],s.max.x=e[t+3],s.max.y=e[t+4],s.max.z=e[t+5],s}function na(t){let e=-1,s=-1/0;for(let i=0;i<3;i++){const r=t[i+3]-t[i];r>s&&(s=r,e=i)}return e}function oa(t,e){e.set(t)}function aa(t,e,s){let i,r;for(let n=0;n<3;n++){const o=n+3;i=t[n],r=e[n],s[n]=i<r?i:r,i=t[o],r=e[o],s[o]=i>r?i:r}}function ha(t,e,s){for(let i=0;i<3;i++){const r=e[t+2*i],n=e[t+2*i+1],o=r-n,a=r+n;o<s[i]&&(s[i]=o),a>s[i+3]&&(s[i+3]=a)}}function la(t){const e=t[3]-t[0],s=t[4]-t[1],i=t[5]-t[2];return 2*(e*s+s*i+i*e)}function ca(t,e,s,i,r=null){let n=1/0,o=1/0,a=1/0,h=-1/0,l=-1/0,c=-1/0,u=1/0,d=1/0,p=1/0,f=-1/0,m=-1/0,_=-1/0;const b=null!==r;for(let i=6*e,r=6*(e+s);i<r;i+=6){const e=t[i+0],s=t[i+1],r=e-s,g=e+s;r<n&&(n=r),g>h&&(h=g),b&&e<u&&(u=e),b&&e>f&&(f=e);const y=t[i+2],x=t[i+3],w=y-x,v=y+x;w<o&&(o=w),v>l&&(l=v),b&&y<d&&(d=y),b&&y>m&&(m=y);const S=t[i+4],M=t[i+5],A=S-M,I=S+M;A<a&&(a=A),I>c&&(c=I),b&&S<p&&(p=S),b&&S>_&&(_=S)}i[0]=n,i[1]=o,i[2]=a,i[3]=h,i[4]=l,i[5]=c,b&&(r[0]=u,r[1]=d,r[2]=p,r[3]=f,r[4]=m,r[5]=_)}const ua=32,da=(t,e)=>t.candidate-e.candidate,pa=new Array(ua).fill().map((()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0}))),fa=new Float32Array(6);class ma{constructor(){}}function _a(t,e,s,i,r,n){let o=i,a=i+r-1;const h=n.pos,l=2*n.axis;for(;;){for(;o<=a&&s[6*o+l]<h;)o++;for(;o<=a&&s[6*a+l]>=h;)a--;if(!(o<a))return o;for(let t=0;t<3;t++){let s=e[3*o+t];e[3*o+t]=e[3*a+t],e[3*a+t]=s}for(let t=0;t<6;t++){let e=s[6*o+t];s[6*o+t]=s[6*a+t],s[6*a+t]=e}o++,a--}}function ba(t,e,s,i,r,n){let o=i,a=i+r-1;const h=n.pos,l=2*n.axis;for(;;){for(;o<=a&&s[6*o+l]<h;)o++;for(;o<=a&&s[6*a+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++){let e=s[6*o+t];s[6*o+t]=s[6*a+t],s[6*a+t]=e}o++,a--}}}function ga(t,e){const s=t.geometry,i=s.index?s.index.array:null,r=e.maxDepth,n=e.verbose,o=e.maxLeafTris,a=e.strategy,h=e.onProgress,l=ta(s),c=t._indirectBuffer;let u=!1;const d=new Float32Array(6),p=new Float32Array(6),f=function(t,e){var s;(s=e)[0]=s[1]=s[2]=1/0,s[3]=s[4]=s[5]=-1/0;const i=t.attributes.position,r=t.index?t.index.array:null,n=ta(t),o=new Float32Array(6*n),a=i.normalized,h=i.array,l=i.offset||0;let c=3;i.isInterleavedBufferAttribute&&(c=i.data.stride);const u=["getX","getY","getZ"];for(let t=0;t<n;t++){const s=3*t,n=6*t;let d=s+0,p=s+1,f=s+2;r&&(d=r[d],p=r[p],f=r[f]),a||(d=d*c+l,p=p*c+l,f=f*c+l);for(let t=0;t<3;t++){let s,r,l;a?(s=i[u[t]](d),r=i[u[t]](p),l=i[u[t]](f)):(s=h[d+t],r=h[p+t],l=h[f+t]);let c=s;r<c&&(c=r),l<c&&(c=l);let m=s;r>m&&(m=r),l>m&&(m=l);const _=(m-c)/2,b=2*t;o[n+b+0]=c+_,o[n+b+1]=_+(Math.abs(c)+_)*$o,c<e[t]&&(e[t]=c),m>e[t+3]&&(e[t+3]=m)}}return o}(s,d),m=e.indirect?ba:_a,_=[],b=e.indirect?sa(s):ia(s);if(1===b.length){const t=b[0],e=new ma;e.boundingData=d,function(t,e,s,i){let r=1/0,n=1/0,o=1/0,a=-1/0,h=-1/0,l=-1/0;for(let i=6*e,c=6*(e+s);i<c;i+=6){const e=t[i+0];e<r&&(r=e),e>a&&(a=e);const s=t[i+2];s<n&&(n=s),s>h&&(h=s);const c=t[i+4];c<o&&(o=c),c>l&&(l=c)}i[0]=r,i[1]=n,i[2]=o,i[3]=a,i[4]=h,i[5]=l}(f,t.offset,t.count,p),y(e,t.offset,t.count,p),_.push(e)}else for(let t of b){const e=new ma;e.boundingData=new Float32Array(6),ca(f,t.offset,t.count,e.boundingData,p),y(e,t.offset,t.count,p),_.push(e)}return _;function g(t){h&&h(t/l)}function y(t,e,h,l=null,d=0){if(!u&&d>=r&&(u=!0,n&&(console.warn(`MeshBVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`),console.warn(s))),h<=o||d>=r)return g(e+h),t.offset=e,t.count=h,t;const _=function(t,e,s,i,r,n){let o=-1,a=0;if(0===n)o=na(e),-1!==o&&(a=(e[o]+e[o+3])/2);else if(1===n)o=na(t),-1!==o&&(a=function(t,e,s,i){let r=0;for(let n=e,o=e+s;n<o;n++)r+=t[6*n+2*i];return r/s}(s,i,r,o));else if(2===n){const n=la(t);let h=Jo*r;const l=6*i,c=6*(i+r);for(let t=0;t<3;t++){const i=e[t],u=(e[t+3]-i)/ua;if(r<8){const e=[...pa];e.length=r;let i=0;for(let r=l;r<c;r+=6,i++){const n=e[i];n.candidate=s[r+2*t],n.count=0;const{bounds:o,leftCacheBounds:a,rightCacheBounds:h}=n;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;ha(r,s,o)}e.sort(da);let u=r;for(let t=0;t<u;t++){const s=e[t];for(;t+1<u&&e[t+1].candidate===s.candidate;)e.splice(t+1,1),u--}for(let i=l;i<c;i+=6){const r=s[i+2*t];for(let t=0;t<u;t++){const n=e[t];r>=n.candidate?ha(i,s,n.rightCacheBounds):(ha(i,s,n.leftCacheBounds),n.count++)}}for(let s=0;s<u;s++){const i=e[s],l=i.count,c=r-i.count,u=i.leftCacheBounds,d=i.rightCacheBounds;let p=0;0!==l&&(p=la(u)/n);let f=0;0!==c&&(f=la(d)/n);const m=1+Jo*(p*l+f*c);m<h&&(o=t,h=m,a=i.candidate)}}else{for(let t=0;t<ua;t++){const e=pa[t];e.count=0,e.candidate=i+u+t*u;const s=e.bounds;for(let t=0;t<3;t++)s[t]=1/0,s[t+3]=-1/0}for(let e=l;e<c;e+=6){let r=~~((s[e+2*t]-i)/u);r>=ua&&(r=31);const n=pa[r];n.count++,ha(e,s,n.bounds)}const e=pa[31];oa(e.bounds,e.rightCacheBounds);for(let t=30;t>=0;t--){const e=pa[t],s=pa[t+1];aa(e.bounds,s.rightCacheBounds,e.rightCacheBounds)}let d=0;for(let e=0;e<31;e++){const s=pa[e],i=s.count,l=s.bounds,c=pa[e+1].rightCacheBounds;0!==i&&(0===d?oa(l,fa):aa(l,fa,fa)),d+=i;let u=0,p=0;0!==d&&(u=la(fa)/n);const f=r-d;0!==f&&(p=la(c)/n);const m=1+Jo*(u*d+p*f);m<h&&(o=t,h=m,a=s.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${n} used.`);return{axis:o,pos:a}}(t.boundingData,l,f,e,h,a);if(-1===_.axis)return g(e+h),t.offset=e,t.count=h,t;const b=m(c,i,f,e,h,_);if(b===e||b===e+h)g(e+h),t.offset=e,t.count=h;else{t.splitAxis=_.axis;const s=new ma,i=e,r=b-e;t.left=s,s.boundingData=new Float32Array(6),ca(f,i,r,s.boundingData,p),y(s,i,r,p,d+1);const n=new ma,o=b,a=h-r;t.right=n,n.boundingData=new Float32Array(6),ca(f,o,a,n.boundingData,p),y(n,o,a,p,d+1)}return t}}function ya(t,e){const s=t.geometry;e.indirect&&(t._indirectBuffer=function(t,e){const s=(t.index?t.index.count:t.attributes.position.count)/3,i=s>65536,r=i?4:2,n=e?new SharedArrayBuffer(s*r):new ArrayBuffer(s*r),o=i?new Uint32Array(n):new Uint16Array(n);for(let t=0,e=o.length;t<e;t++)o[t]=t;return o}(s,e.useSharedArrayBuffer),function(t){if(0===t.groups.length)return!1;const e=ta(t),s=ia(t).sort(((t,e)=>t.offset-e.offset)),i=s[s.length-1];i.count=Math.min(e-i.offset,i.count);let r=0;return s.forEach((({count:t})=>r+=t)),e!==r}(s)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),t._indirectBuffer||ea(s,e);const i=ga(t,e);let r,n,o;const a=[],h=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;for(let t=0;t<i.length;t++){const e=i[t];const s=new h(32*l(e));r=new Float32Array(s),n=new Uint32Array(s),o=new Uint16Array(s),c(0,e),a.push(s)}return void(t._roots=a);function l(t){return t.count?1:1+l(t.left)+l(t.right)}function c(t,e){const s=t/4,i=t/2,a=!!e.count,h=e.boundingData;for(let t=0;t<6;t++)r[s+t]=h[t];if(a){const r=e.offset,a=e.count;return n[s+6]=r,o[i+14]=a,o[i+15]=Qo,t+32}{const i=e.left,r=e.right,o=e.splitAxis;let a;if(a=c(t+32,i),a/4>Math.pow(2,32))throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return n[s+6]=a/4,a=c(a,r),n[s+7]=o,a}}}class xa{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let s=1/0,i=-1/0;for(let r=0,n=t.length;r<n;r++){const n=t[r][e];s=n<s?n:s,i=n>i?n:i}this.min=s,this.max=i}setFromPoints(t,e){let s=1/0,i=-1/0;for(let r=0,n=e.length;r<n;r++){const n=e[r],o=t.dot(n);s=o<s?o:s,i=o>i?o:i}this.min=s,this.max=i}isSeparated(t){return this.min>t.max||t.min>this.max}}xa.prototype.setFromBox=function(){const t=new Xt;return function(e,s){const i=s.min,r=s.max;let n=1/0,o=-1/0;for(let s=0;s<=1;s++)for(let a=0;a<=1;a++)for(let h=0;h<=1;h++){t.x=i.x*s+r.x*(1-s),t.y=i.y*a+r.y*(1-a),t.z=i.z*h+r.z*(1-h);const l=e.dot(t);n=Math.min(l,n),o=Math.max(l,o)}this.min=n,this.max=o}}();const wa=function(){const t=new Xt,e=new Xt,s=new Xt;return function(i,r,n){const o=i.start,a=t,h=r.start,l=e;s.subVectors(o,h),t.subVectors(i.end,i.start),e.subVectors(r.end,r.start);const c=s.dot(l),u=l.dot(a),d=l.dot(l),p=s.dot(a),f=a.dot(a)*d-u*u;let m,_;m=0!==f?(c*u-p*d)/f:0,_=(c+m*u)/d,n.x=m,n.y=_}}(),va=function(){const t=new Tt,e=new Xt,s=new Xt;return function(i,r,n,o){wa(i,r,t);let a=t.x,h=t.y;if(a>=0&&a<=1&&h>=0&&h<=1)return i.at(a,n),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,n);if(h>=0&&h<=1)return a<0?i.at(0,n):i.at(1,n),void r.closestPointToPoint(n,!0,o);{let t,l;t=a<0?i.start:i.end,l=h<0?r.start:r.end;const c=e,u=s;return i.closestPointToPoint(l,!0,e),r.closestPointToPoint(t,!0,s),c.distanceToSquared(l)<=u.distanceToSquared(t)?(n.copy(c),void o.copy(l)):(n.copy(t),void o.copy(u))}}}(),Sa=function(){const t=new Xt,e=new Xt,s=new hi,i=new fi;return function(r,n){const{radius:o,center:a}=r,{a:h,b:l,c:c}=n;i.start=h,i.end=l;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=h,i.end=c;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;i.start=l,i.end=c;if(i.closestPointToPoint(a,!0,t).distanceTo(a)<=o)return!0;const u=n.getPlane(s);if(Math.abs(u.distanceToPoint(a))<=o){const t=u.projectPoint(a,e);if(n.containsPoint(t))return!0}return!1}}();function Ma(t){return Math.abs(t)<1e-15}class Aa extends us{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map((()=>new Xt)),this.satBounds=new Array(4).fill().map((()=>new xa)),this.points=[this.a,this.b,this.c],this.sphere=new me,this.plane=new hi,this.needsUpdate=!0}intersectsSphere(t){return Sa(t,this)}update(){const t=this.a,e=this.b,s=this.c,i=this.points,r=this.satAxes,n=this.satBounds,o=r[0],a=n[0];this.getNormal(o),a.setFromPoints(o,i);const h=r[1],l=n[1];h.subVectors(t,e),l.setFromPoints(h,i);const c=r[2],u=n[2];c.subVectors(e,s),u.setFromPoints(c,i);const d=r[3],p=n[3];d.subVectors(s,t),p.setFromPoints(d,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,t),this.needsUpdate=!1}}Aa.prototype.closestPointToSegment=function(){const t=new Xt,e=new Xt,s=new fi;return function(i,r=null,n=null){const{start:o,end:a}=i,h=this.points;let l,c=1/0;for(let o=0;o<3;o++){const a=(o+1)%3;s.start.copy(h[o]),s.end.copy(h[a]),va(s,i,t,e),l=t.distanceToSquared(e),l<c&&(c=l,r&&r.copy(t),n&&n.copy(e))}return this.closestPointToPoint(o,t),l=o.distanceToSquared(t),l<c&&(c=l,r&&r.copy(t),n&&n.copy(o)),this.closestPointToPoint(a,t),l=a.distanceToSquared(t),l<c&&(c=l,r&&r.copy(t),n&&n.copy(a)),Math.sqrt(c)}}(),Aa.prototype.intersectsTriangle=function(){const t=new Aa,e=new Array(3),s=new Array(3),i=new xa,r=new xa,n=new Xt,o=new Xt,a=new Xt,h=new Xt,l=new Xt,c=new fi,u=new fi,d=new fi,p=new Xt;function f(t,e,s){const i=t.points;let r=0,n=-1;for(let t=0;t<3;t++){const{start:a,end:h}=c;a.copy(i[t]),h.copy(i[(t+1)%3]),c.delta(o);const l=Ma(e.distanceToPoint(a));if(Ma(e.normal.dot(o))&&l){s.copy(c),r=2;break}const u=e.intersectLine(c,p);if(!u&&l&&p.copy(a),(u||l)&&!Ma(p.distanceTo(h))){if(r<=1){(1===r?s.start:s.end).copy(p),l&&(n=r)}else if(r>=2){(1===n?s.start:s.end).copy(p),r=2;break}if(r++,2===r&&-1===n)break}}return r}return function(o,c=null,p=!1){this.needsUpdate&&this.update(),o.isExtendedTriangle?o.needsUpdate&&o.update():(t.copy(o),t.update(),o=t);const m=this.plane,_=o.plane;if(Math.abs(m.normal.dot(_.normal))>1-1e-10){const t=this.satBounds,a=this.satAxes;s[0]=o.a,s[1]=o.b,s[2]=o.c;for(let e=0;e<4;e++){const r=t[e],n=a[e];if(i.setFromPoints(n,s),r.isSeparated(i))return!1}const h=o.satBounds,l=o.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let t=0;t<4;t++){const s=h[t],r=l[t];if(i.setFromPoints(r,e),s.isSeparated(i))return!1}for(let t=0;t<4;t++){const o=a[t];for(let t=0;t<4;t++){const a=l[t];if(n.crossVectors(o,a),i.setFromPoints(n,e),r.setFromPoints(n,s),i.isSeparated(r))return!1}}return c&&(p||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),c.start.set(0,0,0),c.end.set(0,0,0)),!0}{const t=f(this,_,u);if(1===t&&o.containsPoint(u.end))return c&&(c.start.copy(u.end),c.end.copy(u.end)),!0;if(2!==t)return!1;const e=f(o,m,d);if(1===e&&this.containsPoint(d.end))return c&&(c.start.copy(d.end),c.end.copy(d.end)),!0;if(2!==e)return!1;if(u.delta(a),d.delta(h),a.dot(h)<0){let t=d.start;d.start=d.end,d.end=t}const s=u.start.dot(a),i=u.end.dot(a),r=d.start.dot(a),n=d.end.dot(a);return(s===n||r===i||i<r!==s<n)&&(c&&(l.subVectors(u.start,d.start),l.dot(a)>0?c.start.copy(u.start):c.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(a)<0?c.end.copy(u.end):c.end.copy(d.end)),!0)}}}(),Aa.prototype.distanceToPoint=function(){const t=new Xt;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Aa.prototype.distanceToTriangle=function(){const t=new Xt,e=new Xt,s=["a","b","c"],i=new fi,r=new fi;return function(n,o=null,a=null){const h=o||a?i:null;if(this.intersectsTriangle(n,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=s[e],h=n[r];this.closestPointToPoint(h,t),i=h.distanceToSquared(t),i<l&&(l=i,o&&o.copy(t),a&&a.copy(h));const c=this[r];n.closestPointToPoint(c,t),i=c.distanceToSquared(t),i<l&&(l=i,o&&o.copy(c),a&&a.copy(t))}for(let h=0;h<3;h++){const c=s[h],u=s[(h+1)%3];i.set(this[c],this[u]);for(let h=0;h<3;h++){const c=s[h],u=s[(h+1)%3];r.set(n[c],n[u]),va(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 Ia{constructor(t,e,s){this.isOrientedBox=!0,this.min=new Xt,this.max=new Xt,this.matrix=new Me,this.invMatrix=new Me,this.points=new Array(8).fill().map((()=>new Xt)),this.satAxes=new Array(3).fill().map((()=>new Xt)),this.satBounds=new Array(3).fill().map((()=>new xa)),this.alignedSatBounds=new Array(3).fill().map((()=>new xa)),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),s&&this.matrix.copy(s)}set(t,e,s){this.min.copy(t),this.max.copy(e),this.matrix.copy(s),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Ia.prototype.update=function(){return function(){const t=this.matrix,e=this.min,s=this.max,i=this.points;for(let r=0;r<=1;r++)for(let n=0;n<=1;n++)for(let o=0;o<=1;o++){const a=i[1*r|2*n|4*o];a.x=r?s.x:e.x,a.y=n?s.y:e.y,a.z=o?s.z:e.z,a.applyMatrix4(t)}const r=this.satBounds,n=this.satAxes,o=i[0];for(let t=0;t<3;t++){const e=n[t],s=r[t],a=i[1<<t];e.subVectors(o,a),s.setFromPoints(e,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}}(),Ia.prototype.intersectsBox=function(){const t=new xa;return function(e){this.needsUpdate&&this.update();const s=e.min,i=e.max,r=this.satBounds,n=this.satAxes,o=this.alignedSatBounds;if(t.min=s.x,t.max=i.x,o[0].isSeparated(t))return!1;if(t.min=s.y,t.max=i.y,o[1].isSeparated(t))return!1;if(t.min=s.z,t.max=i.z,o[2].isSeparated(t))return!1;for(let s=0;s<3;s++){const i=n[s],o=r[s];if(t.setFromBox(i,e),o.isSeparated(t))return!1}return!0}}(),Ia.prototype.intersectsTriangle=function(){const t=new Aa,e=new Array(3),s=new xa,i=new xa,r=new Xt;return function(n){this.needsUpdate&&this.update(),n.isExtendedTriangle?n.needsUpdate&&n.update():(t.copy(n),t.update(),n=t);const o=this.satBounds,a=this.satAxes;e[0]=n.a,e[1]=n.b,e[2]=n.c;for(let t=0;t<3;t++){const i=o[t],r=a[t];if(s.setFromPoints(r,e),i.isSeparated(s))return!1}const h=n.satBounds,l=n.satAxes,c=this.points;for(let t=0;t<3;t++){const e=h[t],i=l[t];if(s.setFromPoints(i,c),e.isSeparated(s))return!1}for(let t=0;t<3;t++){const n=a[t];for(let t=0;t<4;t++){const o=l[t];if(r.crossVectors(n,o),s.setFromPoints(r,e),i.setFromPoints(r,c),s.isSeparated(i))return!1}}return!0}}(),Ia.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}}(),Ia.prototype.distanceToPoint=function(){const t=new Xt;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}}(),Ia.prototype.distanceToBox=function(){const t=["x","y","z"],e=new Array(12).fill().map((()=>new fi)),s=new Array(12).fill().map((()=>new fi)),i=new Xt,r=new Xt;return function(n,o=0,a=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(n))return(a||h)&&(n.getCenter(r),this.closestPointToPoint(r,i),n.closestPointToPoint(i,r),a&&a.copy(i),h&&h.copy(r)),0;const l=o*o,c=n.min,u=n.max,d=this.points;let p=1/0;for(let t=0;t<8;t++){const e=d[t];r.copy(e).clamp(c,u);const s=e.distanceToSquared(r);if(s<p&&(p=s,a&&a.copy(e),h&&h.copy(r),s<l))return Math.sqrt(s)}let f=0;for(let i=0;i<3;i++)for(let r=0;r<=1;r++)for(let n=0;n<=1;n++){const o=(i+1)%3,a=(i+2)%3,h=1<<i|r<<o|n<<a,l=d[r<<o|n<<a],p=d[h];e[f].set(l,p);const m=t[i],_=t[o],b=t[a],g=s[f],y=g.start,x=g.end;y[m]=c[m],y[_]=r?c[_]:u[_],y[b]=n?c[b]:u[_],x[m]=u[m],x[_]=r?c[_]:u[_],x[b]=n?c[b]:u[_],f++}for(let t=0;t<=1;t++)for(let e=0;e<=1;e++)for(let s=0;s<=1;s++){r.x=t?u.x:c.x,r.y=e?u.y:c.y,r.z=s?u.z:c.z,this.closestPointToPoint(r,i);const n=r.distanceToSquared(i);if(n<p&&(p=n,a&&a.copy(i),h&&h.copy(r),n<l))return Math.sqrt(n)}for(let t=0;t<12;t++){const n=e[t];for(let t=0;t<12;t++){const e=s[t];va(n,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 Ca{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 za extends Ca{constructor(){super((()=>new Aa))}}const Ta=new za;function Pa(t,e){return 65535===e[t+15]}function Ba(t,e){return e[t+6]}function Ea(t,e){return e[t+14]}function Fa(t){return t+8}function Ra(t,e){return e[t+6]}function ka(t,e){return e[t+7]}const Va=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=s=>{e&&t.push(e),e=s,this.float32Array=new Float32Array(s),this.uint16Array=new Uint16Array(s),this.uint32Array=new Uint32Array(s)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,0!==t.length&&this.setBuffer(t.pop())}}};let La,Oa;const Da=[],Ua=new Ca((()=>new Qt));function Na(t,e,s,i,r,n){La=Ua.getPrimitive(),Oa=Ua.getPrimitive(),Da.push(La,Oa),Va.setBuffer(t._roots[e]);const o=Wa(0,t.geometry,s,i,r,n);Va.clearBuffer(),Ua.releasePrimitive(La),Ua.releasePrimitive(Oa),Da.pop(),Da.pop();const a=Da.length;return a>0&&(Oa=Da[a-1],La=Da[a-2]),o}function Wa(t,e,s,i,r=null,n=0,o=0){const{float32Array:a,uint16Array:h,uint32Array:l}=Va;let c=2*t;if(Pa(c,h)){const e=Ba(t,l),s=Ea(c,h);return ra(t,a,La),i(e,s,!1,o,n+t,La)}{let c=function(t){const{uint16Array:e,uint32Array:s}=Va;let i=2*t;for(;!Pa(i,e);)i=2*(t=Fa(t));return Ba(t,s)},u=function(t){const{uint16Array:e,uint32Array:s}=Va;let i=2*t;for(;!Pa(i,e);)i=2*(t=Ra(t,s));return Ba(t,s)+Ea(i,e)};const d=Fa(t),p=Ra(t,l);let f,m,_,b,g=d,y=p;if(r&&(_=La,b=Oa,ra(g,a,_),ra(y,a,b),f=r(_),m=r(b),m<f)){g=p,y=d;const t=f;f=m,m=t,_=b}_||(_=La,ra(g,a,_));const x=s(_,Pa(2*g,h),f,o+1,n+g);let w;if(2===x){const t=c(g);w=i(t,u(g)-t,!0,o+1,n+g,_)}else w=x&&Wa(g,e,s,i,r,n,o+1);if(w)return!0;b=Oa,ra(y,a,b);const v=s(b,Pa(2*y,h),m,o+1,n+y);let S;if(2===v){const t=c(y);S=i(t,u(y)-t,!0,o+1,n+y,b)}else S=v&&Wa(y,e,s,i,r,n,o+1);return!!S}}const Ha=new Xt,qa=new Xt;const Za=new Xt,Ga=new Xt,ja=new Xt,Xa=new Tt,Ya=new Tt,Ja=new Tt,Qa=new Xt,$a=new Xt,Ka=new Xt,th=new Xt;function eh(t,e,s,i,r){const n=3*i;let o=n+0,a=n+1,h=n+2;const l=t.index;t.index&&(o=l.getX(o),a=l.getX(a),h=l.getX(h));const{position:c,normal:u,uv:d,uv1:p}=t.attributes,f=function(t,e,s,i,r,n,o,a,h){Za.fromBufferAttribute(e,n),Ga.fromBufferAttribute(e,o),ja.fromBufferAttribute(e,a);const l=function(t,e,s,i,r,n){let o;return o=1===n?t.intersectTriangle(i,s,e,!0,r):t.intersectTriangle(e,s,i,2!==n,r),null===o?null:{distance:t.origin.distanceTo(r),point:r.clone()}}(t,Za,Ga,ja,th,h);if(l){i&&(Xa.fromBufferAttribute(i,n),Ya.fromBufferAttribute(i,o),Ja.fromBufferAttribute(i,a),l.uv=us.getInterpolation(th,Za,Ga,ja,Xa,Ya,Ja,new Tt)),r&&(Xa.fromBufferAttribute(r,n),Ya.fromBufferAttribute(r,o),Ja.fromBufferAttribute(r,a),l.uv1=us.getInterpolation(th,Za,Ga,ja,Xa,Ya,Ja,new Tt)),s&&(Qa.fromBufferAttribute(s,n),$a.fromBufferAttribute(s,o),Ka.fromBufferAttribute(s,a),l.normal=us.getInterpolation(th,Za,Ga,ja,Qa,$a,Ka,new Xt),l.normal.dot(t.direction)>0&&l.normal.multiplyScalar(-1));const e={a:n,b:o,c:a,normal:new Xt,materialIndex:0};us.getNormal(Za,Ga,ja,e.normal),l.face=e,l.faceIndex=n}return l}(s,c,u,d,p,o,a,h,e);return f?(f.faceIndex=i,r&&r.push(f),f):null}function sh(t,e,s,i){const r=t.a,n=t.b,o=t.c;let a=e,h=e+1,l=e+2;s&&(a=s.getX(a),h=s.getX(h),l=s.getX(l)),r.x=i.getX(a),r.y=i.getY(a),r.z=i.getZ(a),n.x=i.getX(h),n.y=i.getY(h),n.z=i.getZ(h),o.x=i.getX(l),o.y=i.getY(l),o.z=i.getZ(l)}function ih(t,e,s,i,r,n,o){const{geometry:a}=s,{index:h}=a,l=a.attributes.position;for(let s=t,a=e+t;s<a;s++){let t;if(t=s,sh(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,n))return!0}return!1}function rh(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const s=t.geometry,i=s.index?s.index.array:null,r=s.attributes.position;let n,o,a,h,l=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)n=c[t],o=new Uint32Array(n),a=new Uint16Array(n),h=new Float32Array(n),u(0,l),l+=n.byteLength;function u(t,s,n=!1){const l=2*t;if(a[l+15]===Qo){const e=o[t+6];let s=1/0,n=1/0,c=1/0,u=-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<s&&(s=o),o>u&&(u=o),a<n&&(n=a),a>d&&(d=a),h<c&&(c=h),h>p&&(p=h)}return(h[t+0]!==s||h[t+1]!==n||h[t+2]!==c||h[t+3]!==u||h[t+4]!==d||h[t+5]!==p)&&(h[t+0]=s,h[t+1]=n,h[t+2]=c,h[t+3]=u,h[t+4]=d,h[t+5]=p,!0)}{const i=t+8,r=o[t+6],a=i+s,l=r+s;let c=n,d=!1,p=!1;e?c||(d=e.has(a),p=e.has(l),c=!d&&!p):(d=!0,p=!0);const f=c||p;let m=!1;(c||d)&&(m=u(i,s,c));let _=!1;f&&(_=u(r,s,c));const b=m||_;if(b)for(let e=0;e<3;e++){const s=i+e,n=r+e,o=h[s],a=h[s+3],l=h[n],c=h[n+3];h[t+e]=o<l?o:l,h[t+e+3]=a>c?a:c}return b}}}const nh=new Qt;function oh(t,e,s,i){return ra(t,e,nh),s.intersectBox(nh,i)}function ah(t,e,s,i,r,n,o){const{geometry:a}=s,{index:h}=a,l=a.attributes.position;for(let a=t,c=e+t;a<c;a++){let t;if(t=s.resolveTriangleIndex(a),sh(o,3*t,h,l),o.needsUpdate=!0,i(o,t,r,n))return!0}return!1}const hh=new Xt;function lh(t,e,s,i,r){Va.setBuffer(t._roots[e]),ch(0,t,s,i,r),Va.clearBuffer()}function ch(t,e,s,i,r){const{float32Array:n,uint16Array:o,uint32Array:a}=Va,h=2*t;if(Pa(h,o)){!function(t,e,s,i,r,n){const{geometry:o,_indirectBuffer:a}=t;for(let t=i,a=i+r;t<a;t++)eh(o,e,s,t,n)}(e,s,i,Ba(t,a),Ea(h,o),r)}else{const o=Fa(t);oh(o,n,i,hh)&&ch(o,e,s,i,r);const h=Ra(t,a);oh(h,n,i,hh)&&ch(h,e,s,i,r)}}const uh=new Xt,dh=["x","y","z"];function ph(t,e,s,i){Va.setBuffer(t._roots[e]);const r=fh(0,t,s,i);return Va.clearBuffer(),r}function fh(t,e,s,i){const{float32Array:r,uint16Array:n,uint32Array:o}=Va;let a=2*t;if(Pa(a,n)){return function(t,e,s,i,r){const{geometry:n,_indirectBuffer:o}=t;let a=1/0,h=null;for(let t=i,o=i+r;t<o;t++){let i;i=eh(n,e,s,t),i&&i.distance<a&&(h=i,a=i.distance)}return h}(e,s,i,Ba(t,o),Ea(a,n))}{const n=ka(t,o),a=dh[n],h=i.direction[a]>=0;let l,c;h?(l=Fa(t),c=Ra(t,o)):(l=Ra(t,o),c=Fa(t));const u=oh(l,r,i,uh)?fh(l,e,s,i):null;if(u){const t=u.point[a];if(h?t<=r[c+n]:t>=r[c+n+3])return u}const d=oh(c,r,i,uh)?fh(c,e,s,i):null;return u&&d?u.distance<=d.distance?u:d:u||d||null}}const mh=new Qt,_h=new Aa,bh=new Aa,gh=new Me,yh=new Ia,xh=new Ia;function wh(t,e,s,i){Va.setBuffer(t._roots[e]);const r=vh(0,t,s,i);return Va.clearBuffer(),r}function vh(t,e,s,i,r=null){const{float32Array:n,uint16Array:o,uint32Array:a}=Va;let h=2*t;null===r&&(s.boundingBox||s.computeBoundingBox(),yh.set(s.boundingBox.min,s.boundingBox.max,i),r=yh);if(!Pa(h,o)){const o=t+8,h=a[t+6];ra(o,n,mh);if(r.intersectsBox(mh)&&vh(o,e,s,i,r))return!0;ra(h,n,mh);return!!(r.intersectsBox(mh)&&vh(h,e,s,i,r))}{const r=e.geometry,l=r.index,c=r.attributes.position,u=s.index,d=s.attributes.position,p=Ba(t,a),f=Ea(h,o);if(gh.copy(i).invert(),s.boundsTree){ra(t,n,xh),xh.matrix.copy(gh),xh.needsUpdate=!0;return s.boundsTree.shapecast({intersectsBounds:t=>xh.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let e=3*p,s=3*(f+p);e<s;e+=3)if(sh(bh,e,l,c),bh.needsUpdate=!0,t.intersectsTriangle(bh))return!0;return!1}})}for(let t=3*p,e=3*(f+p);t<e;t+=3){sh(_h,t,l,c),_h.a.applyMatrix4(gh),_h.b.applyMatrix4(gh),_h.c.applyMatrix4(gh),_h.needsUpdate=!0;for(let t=0,e=u.count;t<e;t+=3)if(sh(bh,t,u,d),bh.needsUpdate=!0,_h.intersectsTriangle(bh))return!0}}}const Sh=new Me,Mh=new Ia,Ah=new Ia,Ih=new Xt,Ch=new Xt,zh=new Xt,Th=new Xt;function Ph(t,e,s,i={},r={},n=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Mh.set(e.boundingBox.min,e.boundingBox.max,s),Mh.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,c=e.attributes.position,u=e.index,d=Ta.getPrimitive(),p=Ta.getPrimitive();let f=Ih,m=Ch,_=null,b=null;r&&(_=zh,b=Th);let g=1/0,y=null,x=null;return Sh.copy(s).invert(),Ah.matrix.copy(Sh),t.shapecast({boundsTraverseOrder:t=>Mh.distanceToBox(t),intersectsBounds:(t,e,s)=>s<g&&s<o&&(e&&(Ah.min.copy(t.min),Ah.max.copy(t.max),Ah.needsUpdate=!0),!0),intersectsRange:(t,i)=>{if(e.boundsTree){return e.boundsTree.shapecast({boundsTraverseOrder:t=>Ah.distanceToBox(t),intersectsBounds:(t,e,s)=>s<g&&s<o,intersectsRange:(e,r)=>{for(let o=e,a=e+r;o<a;o++){sh(p,3*o,u,c),p.a.applyMatrix4(s),p.b.applyMatrix4(s),p.c.applyMatrix4(s),p.needsUpdate=!0;for(let e=t,s=t+i;e<s;e++){sh(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,_);if(t<g&&(m.copy(f),b&&b.copy(_),g=t,y=e,x=o),t<n)return!0}}}})}for(let r=0,o=ta(e);r<o;r++){sh(p,3*r,u,c),p.a.applyMatrix4(s),p.b.applyMatrix4(s),p.c.applyMatrix4(s),p.needsUpdate=!0;for(let e=t,s=t+i;e<s;e++){sh(d,3*e,l,h),d.needsUpdate=!0;const t=d.distanceToTriangle(p,f,_);if(t<g&&(m.copy(f),b&&b.copy(_),g=t,y=e,x=r),t<n)return!0}}}}),Ta.releasePrimitive(d),Ta.releasePrimitive(p),g===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=g,i.faceIndex=y,r&&(r.point?r.point.copy(b):r.point=b.clone(),r.point.applyMatrix4(Sh),m.applyMatrix4(Sh),r.distance=m.sub(r.point).length(),r.faceIndex=x),i)}function Bh(t,e=null){e&&Array.isArray(e)&&(e=new Set(e));const s=t.geometry,i=s.index?s.index.array:null,r=s.attributes.position;let n,o,a,h,l=0;const c=t._roots;for(let t=0,e=c.length;t<e;t++)n=c[t],o=new Uint32Array(n),a=new Uint16Array(n),h=new Float32Array(n),u(0,l),l+=n.byteLength;function u(s,n,l=!1){const c=2*s;if(a[c+15]===Qo){const e=o[s+6];let n=1/0,l=1/0,u=1/0,d=-1/0,p=-1/0,f=-1/0;for(let s=e,o=e+a[c+14];s<o;s++){const e=3*t.resolveTriangleIndex(s);for(let t=0;t<3;t++){let s=e+t;s=i?i[s]:s;const o=r.getX(s),a=r.getY(s),h=r.getZ(s);o<n&&(n=o),o>d&&(d=o),a<l&&(l=a),a>p&&(p=a),h<u&&(u=h),h>f&&(f=h)}}return(h[s+0]!==n||h[s+1]!==l||h[s+2]!==u||h[s+3]!==d||h[s+4]!==p||h[s+5]!==f)&&(h[s+0]=n,h[s+1]=l,h[s+2]=u,h[s+3]=d,h[s+4]=p,h[s+5]=f,!0)}{const t=s+8,i=o[s+6],r=t+n,a=i+n;let c=l,d=!1,p=!1;e?c||(d=e.has(r),p=e.has(a),c=!d&&!p):(d=!0,p=!0);const f=c||p;let m=!1;(c||d)&&(m=u(t,n,c));let _=!1;f&&(_=u(i,n,c));const b=m||_;if(b)for(let e=0;e<3;e++){const r=t+e,n=i+e,o=h[r],a=h[r+3],l=h[n],c=h[n+3];h[s+e]=o<l?o:l,h[s+e+3]=a>c?a:c}return b}}}const Eh=new Xt;function Fh(t,e,s,i,r){Va.setBuffer(t._roots[e]),Rh(0,t,s,i,r),Va.clearBuffer()}function Rh(t,e,s,i,r){const{float32Array:n,uint16Array:o,uint32Array:a}=Va,h=2*t;if(Pa(h,o)){!function(t,e,s,i,r,n){const{geometry:o,_indirectBuffer:a}=t;for(let t=i,h=i+r;t<h;t++)eh(o,e,s,a?a[t]:t,n)}(e,s,i,Ba(t,a),Ea(h,o),r)}else{const o=Fa(t);oh(o,n,i,Eh)&&Rh(o,e,s,i,r);const h=Ra(t,a);oh(h,n,i,Eh)&&Rh(h,e,s,i,r)}}const kh=new Xt,Vh=["x","y","z"];function Lh(t,e,s,i){Va.setBuffer(t._roots[e]);const r=Oh(0,t,s,i);return Va.clearBuffer(),r}function Oh(t,e,s,i){const{float32Array:r,uint16Array:n,uint32Array:o}=Va;let a=2*t;if(Pa(a,n)){return function(t,e,s,i,r){const{geometry:n,_indirectBuffer:o}=t;let a=1/0,h=null;for(let t=i,l=i+r;t<l;t++){let i;i=eh(n,e,s,o?o[t]:t),i&&i.distance<a&&(h=i,a=i.distance)}return h}(e,s,i,Ba(t,o),Ea(a,n))}{const n=ka(t,o),a=Vh[n],h=i.direction[a]>=0;let l,c;h?(l=Fa(t),c=Ra(t,o)):(l=Ra(t,o),c=Fa(t));const u=oh(l,r,i,kh)?Oh(l,e,s,i):null;if(u){const t=u.point[a];if(h?t<=r[c+n]:t>=r[c+n+3])return u}const d=oh(c,r,i,kh)?Oh(c,e,s,i):null;return u&&d?u.distance<=d.distance?u:d:u||d||null}}const Dh=new Qt,Uh=new Aa,Nh=new Aa,Wh=new Me,Hh=new Ia,qh=new Ia;function Zh(t,e,s,i){Va.setBuffer(t._roots[e]);const r=Gh(0,t,s,i);return Va.clearBuffer(),r}function Gh(t,e,s,i,r=null){const{float32Array:n,uint16Array:o,uint32Array:a}=Va;let h=2*t;null===r&&(s.boundingBox||s.computeBoundingBox(),Hh.set(s.boundingBox.min,s.boundingBox.max,i),r=Hh);if(!Pa(h,o)){const o=t+8,h=a[t+6];ra(o,n,Dh);if(r.intersectsBox(Dh)&&Gh(o,e,s,i,r))return!0;ra(h,n,Dh);return!!(r.intersectsBox(Dh)&&Gh(h,e,s,i,r))}{const r=e.geometry,l=r.index,c=r.attributes.position,u=s.index,d=s.attributes.position,p=Ba(t,a),f=Ea(h,o);if(Wh.copy(i).invert(),s.boundsTree){ra(t,n,qh),qh.matrix.copy(Wh),qh.needsUpdate=!0;return s.boundsTree.shapecast({intersectsBounds:t=>qh.intersectsBox(t),intersectsTriangle:t=>{t.a.applyMatrix4(i),t.b.applyMatrix4(i),t.c.applyMatrix4(i),t.needsUpdate=!0;for(let s=p,i=f+p;s<i;s++)if(sh(Nh,3*e.resolveTriangleIndex(s),l,c),Nh.needsUpdate=!0,t.intersectsTriangle(Nh))return!0;return!1}})}for(let t=p,s=f+p;t<s;t++){const s=e.resolveTriangleIndex(t);sh(Uh,3*s,l,c),Uh.a.applyMatrix4(Wh),Uh.b.applyMatrix4(Wh),Uh.c.applyMatrix4(Wh),Uh.needsUpdate=!0;for(let t=0,e=u.count;t<e;t+=3)if(sh(Nh,t,u,d),Nh.needsUpdate=!0,Uh.intersectsTriangle(Nh))return!0}}}const jh=new Me,Xh=new Ia,Yh=new Ia,Jh=new Xt,Qh=new Xt,$h=new Xt,Kh=new Xt;function tl(t,e,s,i={},r={},n=0,o=1/0){e.boundingBox||e.computeBoundingBox(),Xh.set(e.boundingBox.min,e.boundingBox.max,s),Xh.needsUpdate=!0;const a=t.geometry,h=a.attributes.position,l=a.index,c=e.attributes.position,u=e.index,d=Ta.getPrimitive(),p=Ta.getPrimitive();let f=Jh,m=Qh,_=null,b=null;r&&(_=$h,b=Kh);let g=1/0,y=null,x=null;return jh.copy(s).invert(),Yh.matrix.copy(jh),t.shapecast({boundsTraverseOrder:t=>Xh.distanceToBox(t),intersectsBounds:(t,e,s)=>s<g&&s<o&&(e&&(Yh.min.copy(t.min),Yh.max.copy(t.max),Yh.needsUpdate=!0),!0),intersectsRange:(i,r)=>{if(e.boundsTree){const a=e.boundsTree;return a.shapecast({boundsTraverseOrder:t=>Yh.distanceToBox(t),intersectsBounds:(t,e,s)=>s<g&&s<o,intersectsRange:(e,o)=>{for(let w=e,v=e+o;w<v;w++){const e=a.resolveTriangleIndex(w);sh(p,3*e,u,c),p.a.applyMatrix4(s),p.b.applyMatrix4(s),p.c.applyMatrix4(s),p.needsUpdate=!0;for(let e=i,s=i+r;e<s;e++){const s=t.resolveTriangleIndex(e);sh(d,3*s,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,_);if(i<g&&(m.copy(f),b&&b.copy(_),g=i,y=e,x=w),i<n)return!0}}}})}for(let o=0,a=ta(e);o<a;o++){sh(p,3*o,u,c),p.a.applyMatrix4(s),p.b.applyMatrix4(s),p.c.applyMatrix4(s),p.needsUpdate=!0;for(let e=i,s=i+r;e<s;e++){const s=t.resolveTriangleIndex(e);sh(d,3*s,l,h),d.needsUpdate=!0;const i=d.distanceToTriangle(p,f,_);if(i<g&&(m.copy(f),b&&b.copy(_),g=i,y=e,x=o),i<n)return!0}}}}),Ta.releasePrimitive(d),Ta.releasePrimitive(p),g===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=g,i.faceIndex=y,r&&(r.point?r.point.copy(b):r.point=b.clone(),r.point.applyMatrix4(jh),m.applyMatrix4(jh),r.distance=m.sub(r.point).length(),r.faceIndex=x),i)}const el=new Va.constructor,sl=new Va.constructor,il=new Ca((()=>new Qt)),rl=new Qt,nl=new Qt,ol=new Qt,al=new Qt;let hl=!1;function ll(t,e,s,i,r,n=0,o=0,a=0,h=0,l=null,c=!1){let u,d;c?(u=sl,d=el):(u=el,d=sl);const p=u.float32Array,f=u.uint32Array,m=u.uint16Array,_=d.float32Array,b=d.uint32Array,g=d.uint16Array,y=2*e,x=Pa(2*t,m),w=Pa(y,g);let v=!1;if(w&&x)v=c?r(Ba(e,b),Ea(2*e,g),Ba(t,f),Ea(2*t,m),h,o+e,a,n+t):r(Ba(t,f),Ea(2*t,m),Ba(e,b),Ea(2*e,g),a,n+t,h,o+e);else if(w){const l=il.getPrimitive();ra(e,_,l),l.applyMatrix4(s);const u=Fa(t),d=Ra(t,f);ra(u,p,rl),ra(d,p,nl);const m=l.intersectsBox(rl),b=l.intersectsBox(nl);v=m&&ll(e,u,i,s,r,o,n,h,a+1,l,!c)||b&&ll(e,d,i,s,r,o,n,h,a+1,l,!c),il.releasePrimitive(l)}else{const u=Fa(e),d=Ra(e,b);ra(u,_,ol),ra(d,_,al);const m=l.intersectsBox(ol),g=l.intersectsBox(al);if(m&&g)v=ll(t,u,s,i,r,n,o,a,h+1,l,c)||ll(t,d,s,i,r,n,o,a,h+1,l,c);else if(m)if(x)v=ll(t,u,s,i,r,n,o,a,h+1,l,c);else{const e=il.getPrimitive();e.copy(ol).applyMatrix4(s);const l=Fa(t),d=Ra(t,f);ra(l,p,rl),ra(d,p,nl);const m=e.intersectsBox(rl),_=e.intersectsBox(nl);v=m&&ll(u,l,i,s,r,o,n,h,a+1,e,!c)||_&&ll(u,d,i,s,r,o,n,h,a+1,e,!c),il.releasePrimitive(e)}else if(g)if(x)v=ll(t,d,s,i,r,n,o,a,h+1,l,c);else{const e=il.getPrimitive();e.copy(al).applyMatrix4(s);const l=Fa(t),u=Ra(t,f);ra(l,p,rl),ra(u,p,nl);const m=e.intersectsBox(rl),_=e.intersectsBox(nl);v=m&&ll(d,l,i,s,r,o,n,h,a+1,e,!c)||_&&ll(d,u,i,s,r,o,n,h,a+1,e,!c),il.releasePrimitive(e)}}return v}const cl=new Ia,ul=new Qt;class dl{static serialize(t,e={}){e={cloneBuffers:!0,...e};const s=t.geometry,i=t._roots,r=t._indirectBuffer,n=s.getIndex();let o;return o=e.cloneBuffers?{roots:i.map((t=>t.slice())),index:n.array.slice(),indirectBuffer:r?r.slice():null}:{roots:i,index:n.array,indirectBuffer:r},o}static deserialize(t,e,s={}){s={setIndex:!0,indirect:Boolean(t.indirectBuffer),...s};const{index:i,roots:r,indirectBuffer:n}=t,o=new dl(e,{...s,[Ko]:!0});if(o._roots=r,o._indirectBuffer=n||null,s.setIndex){const s=e.getIndex();if(null===s){const s=new Ms(t.index,1,!1);e.setIndex(s)}else s.array!==i&&(s.array.set(i),s.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({strategy:0,maxDepth:40,maxLeafTris:10,verbose:!0,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,[Ko]:!1},e)).useSharedArrayBuffer&&"undefined"==typeof SharedArrayBuffer)throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=t,this._roots=null,this._indirectBuffer=null,e[Ko]||(ya(this,e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Qt)));const{_indirectBuffer:s}=this;this.resolveTriangleIndex=e.indirect?t=>s[t]:t=>t}refit(t=null){return(this.indirect?Bh:rh)(this,t)}traverse(t,e=0){const s=this._roots[e],i=new Uint32Array(s),r=new Uint16Array(s);!function e(n,o=0){const a=2*n,h=r[a+15]===Qo;if(h){const e=i[n+6],l=r[a+14];t(o,h,new Float32Array(s,4*n,6),e,l)}else{const r=n+8,a=i[n+6],l=i[n+7];t(o,h,new Float32Array(s,4*n,6),l)||(e(r,o+1),e(a,o+1))}}(0)}raycast(t,e=0){const s=this._roots,i=this.geometry,r=[],n=e.isMaterial,o=Array.isArray(e),a=i.groups,h=n?e.side:e,l=this.indirect?Fh:lh;for(let i=0,n=s.length;i<n;i++){const s=o?e[a[i].materialIndex].side:h,n=r.length;if(l(this,i,s,t,r),o){const t=a[i].materialIndex;for(let e=n,s=r.length;e<s;e++)r[e].face.materialIndex=t}}return r}raycastFirst(t,e=0){const s=this._roots,i=this.geometry,r=e.isMaterial,n=Array.isArray(e);let o=null;const a=i.groups,h=r?e.side:e,l=this.indirect?Lh:ph;for(let i=0,r=s.length;i<r;i++){const s=l(this,i,n?e[a[i].materialIndex].side:h,t);null!=s&&(null==o||s.distance<o.distance)&&(o=s,n&&(s.face.materialIndex=a[i].materialIndex))}return o}intersectsGeometry(t,e){let s=!1;const i=this._roots,r=this.indirect?Zh:wh;for(let n=0,o=i.length;n<o&&(s=r(this,n,t,e),!s);n++);return s}shapecast(t){const e=Ta.getPrimitive(),s=this.indirect?ah:ih;let{boundsTraverseOrder:i,intersectsBounds:r,intersectsRange:n,intersectsTriangle:o}=t;if(n&&o){const t=n;n=(i,r,n,a,h)=>!!t(i,r,n,a,h)||s(i,r,this,o,n,a,e)}else n||(n=o?(t,i,r,n)=>s(t,i,this,o,r,n,e):(t,e,s)=>s);let a=!1,h=0;const l=this._roots;for(let t=0,e=l.length;t<e;t++){const e=l[t];if(a=Na(this,t,r,n,i,h),a)break;h+=e.byteLength}return Ta.releasePrimitive(e),a}bvhcast(t,e,s){let{intersectsRanges:i,intersectsTriangles:r}=s;const n=Ta.getPrimitive(),o=this.geometry.index,a=this.geometry.attributes.position,h=this.indirect?t=>{const e=this.resolveTriangleIndex(t);sh(n,3*e,o,a)}:t=>{sh(n,3*t,o,a)},l=Ta.getPrimitive(),c=t.geometry.index,u=t.geometry.attributes.position,d=t.indirect?e=>{const s=t.resolveTriangleIndex(e);sh(l,3*s,c,u)}:t=>{sh(l,3*t,c,u)};if(r){const t=(t,s,i,o,a,c,u,p)=>{for(let f=i,m=i+o;f<m;f++){d(f),l.a.applyMatrix4(e),l.b.applyMatrix4(e),l.c.applyMatrix4(e),l.needsUpdate=!0;for(let e=t,i=t+s;e<i;e++)if(h(e),n.needsUpdate=!0,r(n,l,e,f,a,c,u,p))return!0}return!1};if(i){const e=i;i=function(s,i,r,n,o,a,h,l){return!!e(s,i,r,n,o,a,h,l)||t(s,i,r,n,o,a,h,l)}}else i=t}return function(t,e,s,i){if(hl)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");hl=!0;const r=t._roots,n=e._roots;let o,a=0,h=0;const l=(new Me).copy(s).invert();for(let t=0,e=r.length;t<e;t++){el.setBuffer(r[t]),h=0;const e=il.getPrimitive();ra(0,el.float32Array,e),e.applyMatrix4(l);for(let r=0,c=n.length;r<c&&(sl.setBuffer(n[t]),o=ll(0,0,s,l,i,a,h,0,0,e),sl.clearBuffer(),h+=n[r].length,!o);r++);if(il.releasePrimitive(e),el.clearBuffer(),a+=r[t].length,o)break}return hl=!1,o}(this,t,e,i)}intersectsBox(t,e){return cl.set(t.min,t.max,e),cl.needsUpdate=!0,this.shapecast({intersectsBounds:t=>cl.intersectsBox(t),intersectsTriangle:t=>cl.intersectsTriangle(t)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,s={},i={},r=0,n=1/0){return(this.indirect?tl:Ph)(this,t,e,s,i,r,n)}closestPointToPoint(t,e={},s=0,i=1/0){return function(t,e,s={},i=0,r=1/0){const n=i*i,o=r*r;let a=1/0,h=null;if(t.shapecast({boundsTraverseOrder:t=>(Ha.copy(e).clamp(t.min,t.max),Ha.distanceToSquared(e)),intersectsBounds:(t,e,s)=>s<a&&s<o,intersectsTriangle:(t,s)=>{t.closestPointToPoint(e,Ha);const i=e.distanceToSquared(Ha);return i<a&&(qa.copy(Ha),a=i,h=s),i<n}}),a===1/0)return null;const l=Math.sqrt(a);return s.point?s.point.copy(qa):s.point=qa.clone(),s.distance=l,s.faceIndex=h,s}(this,t,e,s,i)}getBoundingBox(t){t.makeEmpty();return this._roots.forEach((e=>{ra(0,new Float32Array(e),ul),t.union(ul)})),t}}function pl(t,e,s){return null===t?null:(t.point.applyMatrix4(e.matrixWorld),t.distance=t.point.distanceTo(s.ray.origin),t.object=e,t.distance<s.near||t.distance>s.far?null:t)}const fl=new Se,ml=new Me,_l=js.prototype.raycast;function bl(t,e){if(this.geometry.boundsTree){if(void 0===this.material)return;ml.copy(this.matrixWorld).invert(),fl.copy(t.ray).applyMatrix4(ml);const s=this.geometry.boundsTree;if(!0===t.firstHitOnly){const i=pl(s.raycastFirst(fl,this.material),this,t);i&&e.push(i)}else{const i=s.raycast(fl,this.material);for(let s=0,r=i.length;s<r;s++){const r=pl(i[s],this,t);r&&e.push(r)}}}else _l.call(this,t,e)}function gl(t){return this.boundsTree=new dl(this,t),this.boundsTree}function yl(){this.boundsTree=null}class xl{static containedInParallelPlanes(t,e){let s=!0;for(const i of t){const t=i.distanceToPoint(e);s=s&&t>=0}return s}static collides(t,e,s){for(const i of e){if(this.getPointDistance(i,s,t)<0)return!1}return!0}static getPointDistance(t,e,s){const i=t.normal;for(const t of this.dimensions){const r=i[t]>=0!==e;this.tempPoint[t]=r?s.max[t]:s.min[t]}return t.distanceToPoint(this.tempPoint)}}ot(xl,"tempPoint",new Xt),ot(xl,"dimensions",["x","y","z"]);class wl{static transform(t,e,s=new ui){for(let i=0;i<s.planes.length;i++){const r=s.planes[i],n=t.planes[i];r.copy(n),r.applyMatrix4(e)}return s}static isIncluded(t,e){return xl.collides(t,e,!0)}static collides(t,e){return xl.collides(t,e,!1)}}function vl(t,e,s=2){const i=e&&e.length,r=i?e[0]*s:t.length;let n=Sl(t,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=function(t,e,s,i){const r=[];for(let s=0,n=e.length;s<n;s++){const o=Sl(t,e[s]*i,s<n-1?e[s+1]*i:t.length,i,!1);o===o.next&&(o.steiner=!0),r.push(Rl(o))}r.sort(Pl);for(let t=0;t<r.length;t++)s=Bl(r[t],s);return s}(t,e,n,s)),t.length>80*s){a=1/0,h=1/0;let e=-1/0,i=-1/0;for(let n=s;n<r;n+=s){const s=t[n],r=t[n+1];s<a&&(a=s),r<h&&(h=r),s>e&&(e=s),r>i&&(i=r)}l=Math.max(e-a,i-h),l=0!==l?32767/l:0}return Al(n,o,s,a,h,l,0),o}function Sl(t,e,s,i,r){let n;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n<s;n+=i)r+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return r}(t,e,s,i)>0)for(let r=e;r<s;r+=i)n=Zl(r/i|0,t[r],t[r+1],n);else for(let r=s-i;r>=e;r-=i)n=Zl(r/i|0,t[r],t[r+1],n);return n&&Dl(n,n.next)&&(Gl(n),n=n.next),n}function Ml(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Dl(i,i.next)&&0!==Ol(i.prev,i,i.next))i=i.next;else{if(Gl(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Al(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=Fl(r.x,r.y,e,s,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,s=1;do{let i,r=t;t=null;let n=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<s&&(a++,o=o.nextZ,o);t++);let h=s;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--),n?n.nextZ=i:t=i,i.prevZ=n,n=i;r=o}n.nextZ=null,s*=2}while(e>1)}(r)}(t,i,r,n);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(n?Cl(t,i,r,n):Il(t))e.push(h.i,t.i,l.i),Gl(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?Al(t=zl(Ml(t),e),e,s,i,r,n,2):2===o&&Tl(t,e,s,i,r,n):Al(Ml(t),e,s,i,r,n,1);break}}}function Il(t){const e=t.prev,s=t,i=t.next;if(Ol(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,l=i.y,c=Math.min(r,n,o),u=Math.min(a,h,l),d=Math.max(r,n,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=c&&f.x<=d&&f.y>=u&&f.y<=p&&Vl(r,a,n,h,o,l,f.x,f.y)&&Ol(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Cl(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Ol(r,n,o)>=0)return!1;const a=r.x,h=n.x,l=o.x,c=r.y,u=n.y,d=o.y,p=Math.min(a,h,l),f=Math.min(c,u,d),m=Math.max(a,h,l),_=Math.max(c,u,d),b=Fl(p,f,e,s,i),g=Fl(m,_,e,s,i);let y=t.prevZ,x=t.nextZ;for(;y&&y.z>=b&&x&&x.z<=g;){if(y.x>=p&&y.x<=m&&y.y>=f&&y.y<=_&&y!==r&&y!==o&&Vl(a,c,h,u,l,d,y.x,y.y)&&Ol(y.prev,y,y.next)>=0)return!1;if(y=y.prevZ,x.x>=p&&x.x<=m&&x.y>=f&&x.y<=_&&x!==r&&x!==o&&Vl(a,c,h,u,l,d,x.x,x.y)&&Ol(x.prev,x,x.next)>=0)return!1;x=x.nextZ}for(;y&&y.z>=b;){if(y.x>=p&&y.x<=m&&y.y>=f&&y.y<=_&&y!==r&&y!==o&&Vl(a,c,h,u,l,d,y.x,y.y)&&Ol(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;x&&x.z<=g;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=_&&x!==r&&x!==o&&Vl(a,c,h,u,l,d,x.x,x.y)&&Ol(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function zl(t,e){let s=t;do{const i=s.prev,r=s.next.next;!Dl(i,r)&&Ul(i,s,s.next,r)&&Hl(i,r)&&Hl(r,i)&&(e.push(i.i,s.i,r.i),Gl(s),Gl(s.next),s=t=r),s=s.next}while(s!==t);return Ml(s)}function Tl(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Ll(o,t)){let a=ql(o,t);return o=Ml(o,o.next),a=Ml(a,a.next),Al(o,e,s,i,r,n,0),void Al(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Pl(t,e){let s=t.x-e.x;if(0===s&&(s=t.y-e.y,0===s)){s=(t.next.y-t.y)/(t.next.x-t.x)-(e.next.y-e.y)/(e.next.x-e.x)}return s}function Bl(t,e){const s=function(t,e){let s=e;const i=t.x,r=t.y;let n,o=-1/0;if(Dl(t,s))return s;do{if(Dl(t,s.next))return s.next;if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){const t=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(t<=i&&t>o&&(o=t,n=s.x<s.next.x?s:s.next,t===i))return n}s=s.next}while(s!==e);if(!n)return null;const a=n,h=n.x,l=n.y;let c=1/0;s=n;do{if(i>=s.x&&s.x>=h&&i!==s.x&&kl(r<l?i:o,r,h,l,r<l?o:i,r,s.x,s.y)){const e=Math.abs(r-s.y)/(i-s.x);Hl(s,t)&&(e<c||e===c&&(s.x>n.x||s.x===n.x&&El(n,s)))&&(n=s,c=e)}s=s.next}while(s!==a);return n}(t,e);if(!s)return e;const i=ql(s,t);return Ml(i,i.next),Ml(s,s.next)}function El(t,e){return Ol(t.prev,t,e.prev)<0&&Ol(e.next,t,t.next)<0}function Fl(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*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 Rl(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function kl(t,e,s,i,r,n,o,a){return(r-o)*(e-a)>=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Vl(t,e,s,i,r,n,o,a){return!(t===o&&e===a)&&kl(t,e,s,i,r,n,o,a)}function Ll(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Ul(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(Hl(t,e)&&Hl(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Ol(t.prev,t,e.prev)||Ol(t,e.prev,e))||Dl(t,e)&&Ol(t.prev,t,t.next)>0&&Ol(e.prev,e,e.next)>0)}function Ol(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Dl(t,e){return t.x===e.x&&t.y===e.y}function Ul(t,e,s,i){const r=Wl(Ol(t,e,s)),n=Wl(Ol(t,e,i)),o=Wl(Ol(s,i,t)),a=Wl(Ol(s,i,e));return r!==n&&o!==a||(!(0!==r||!Nl(t,s,e))||(!(0!==n||!Nl(t,i,e))||(!(0!==o||!Nl(s,t,i))||!(0!==a||!Nl(s,e,i)))))}function Nl(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function Wl(t){return t>0?1:t<0?-1:0}function Hl(t,e){return Ol(t.prev,t,t.next)<0?Ol(t,e,t.next)>=0&&Ol(t,t.prev,e)>=0:Ol(t,e,t.prev)<0||Ol(t,t.next,e)<0}function ql(t,e){const s=jl(t.i,t.x,t.y),i=jl(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function Zl(t,e,s,i){const r=jl(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function Gl(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 jl(t,e,s){return{i:t,x:e,y:s,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}class Xl{constructor(){ot(this,"_inverseMatrix",new Me),ot(this,"_localPlane",new hi),ot(this,"_tempLine",new fi),ot(this,"_tempVector",new Xt),ot(this,"_plane"),ot(this,"_plane2DCoordinateSystem",new Me),ot(this,"_precission",1e4)}get plane(){if(!this._plane)throw new Error("Fragments: Plane not set");return this._plane}set plane(t){this._plane=t}createEdges(t){const{meshes:e,posAttr:s}=t;let i=0;s.array.fill(0);const r=[];let n=0;const o=new js;for(const t of e)if(t.geometry){if(t.geometry.boundsTree||t.geometry.computeBoundsTree(),!t.geometry.boundsTree)throw new Error("Fragments: Bounds tree not found for edges generation.");if(t instanceof ri){if(0===t.count)continue;const e=t;for(let a=0;a<e.count;a++){o.geometry=t.geometry,o.matrix.copy(t.matrix);const h=new Me;e.getMatrixAt(a,h),o.applyMatrix4(h),o.applyMatrix4(t.matrixWorld),o.updateMatrix(),o.updateMatrixWorld(),this._inverseMatrix.copy(o.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),i=this.shapecast(o,s,i),i!==n&&(r.push(i),n=i)}}else this._inverseMatrix.copy(t.matrixWorld).invert(),this._localPlane.copy(this.plane).applyMatrix4(this._inverseMatrix),i=this.shapecast(t,s,i),i!==n&&(r.push(i),n=i)}return{indexes:r,index:i}}createFills(t,e){this.updatePlane2DCoordinateSystem();const s=[];let i=0;for(let r=0;r<e.length;r++){const n=e[r],o=[];for(let t=i;t<n;t+=2)o.push(3*t);const a=this.computeFill(o,t);for(const t of a)s.push(t);i=n}return s}computeFill(t,e){const s=new Map,i={},r=new Map;let n=0;const o=new Map,a=new Map,h=new Set,l=this._precission;for(let c=0;c<t.length;c++){const u=t[c];let d=0,p=0,f=0,m=0;const _=e[u],b=e[u+1],g=e[u+2],y=e[u+3],x=e[u+4],w=e[u+5];if(this._tempVector.set(_,b,g),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),d=Math.trunc(this._tempVector.x*l)/l,p=Math.trunc(this._tempVector.y*l)/l,this._tempVector.set(y,x,w),this._tempVector.applyMatrix4(this._plane2DCoordinateSystem),f=Math.trunc(this._tempVector.x*l)/l,m=Math.trunc(this._tempVector.y*l)/l,d===f&&p===m)continue;const v=`${d}|${p}`,S=`${f}|${m}`;s.has(v)||s.set(v,u/3),s.has(S)||s.set(S,u/3+1);const M=s.get(v),A=s.get(S);i[M]=[d,p],i[A]=[f,m];const I=a.has(M),C=o.has(M),z=a.has(A),T=o.has(A);if(!(I||C||z||T))a.set(M,n),o.set(A,n),h.add(n),r.set(n,[M,A]),n++;else if(I&&T){const t=a.get(M),e=o.get(A);if(t!==e){const s=r.get(e),i=r.get(t);if(!s||!i)continue;r.delete(t),h.delete(t),o.set(i[i.length-1],e),o.delete(s[s.length-1]);for(const t of i)s.push(t)}else h.delete(e);a.delete(M),o.delete(A)}else if(C&&z){const t=a.get(A),e=o.get(M);if(t!==e){const s=r.get(e),i=r.get(t);if(!s||!i)continue;r.delete(t),h.delete(t),o.set(i[i.length-1],e),o.delete(s[s.length-1]);for(const t of i)s.push(t)}else h.delete(e);a.delete(A),o.delete(M)}else if(I&&z){const t=a.get(A),e=a.get(M),s=r.get(e),i=r.get(t);if(!s||!i)continue;r.delete(t),h.delete(t),a.delete(s[0]),a.delete(i[0]),o.delete(i[i.length-1]),a.set(i[i.length-1],e),i.reverse(),s.splice(0,0,...i)}else if(C&&T){const t=o.get(A),e=o.get(M),s=r.get(e),i=r.get(t);if(!s||!i)continue;r.delete(t),h.delete(t),o.delete(s[s.length-1]),o.delete(i[i.length-1]),a.delete(i[0]),o.set(i[0],e),i.reverse(),s.push(...i)}else if(I){const t=a.get(M),e=r.get(t);if(!e)continue;e.unshift(A),a.delete(M),a.set(A,t)}else if(C){const t=o.get(M),e=r.get(t);if(!e)continue;e.push(A),o.delete(M),o.set(A,t)}else if(z){const t=a.get(A),e=r.get(t);if(!e)continue;e.unshift(M),a.delete(A),a.set(M,t)}else if(T){const t=o.get(A),e=r.get(t);if(!e)continue;e.push(M),o.delete(A),o.set(M,t)}}const c=[];for(const[t,e]of r){if(h.has(t))continue;const s=[],r=new Map;let n=0;for(const t of e){const e=i[t];s.push(e[0],e[1]),r.set(n++,t)}const o=vl(s);for(const t of o){const e=r.get(t);if(void 0===e)throw new Error("Fragments: Map error!");c.push(e)}}return c}updatePlane2DCoordinateSystem(){this._plane2DCoordinateSystem=new Me;const t=this.plane.normal,e=new Xt;let s,i;if(this.plane.coplanarPoint(e),Math.abs(t.z)>.99)s=new Xt(1,0,0),i=new Xt(0,1,0);else if(Math.abs(t.x)>.99)s=new Xt(0,1,0),i=new Xt(0,0,1);else if(Math.abs(t.y)>.99)s=new Xt(1,0,0),i=new Xt(0,0,1);else{const e=Math.abs(t.x)<.5?new Xt(1,0,0):new Xt(0,1,0);s=new Xt,s.crossVectors(e,t).normalize(),i=new Xt,i.crossVectors(t,s).normalize()}this._plane2DCoordinateSystem.fromArray([s.x,s.y,s.z,0,i.x,i.y,i.z,0,t.x,t.y,t.z,0,e.x,e.y,e.z,1]),this._plane2DCoordinateSystem.invert()}shapecast(t,e,s){return t.geometry.boundsTree.shapecast({intersectsBounds:t=>this._localPlane.intersectsBox(t),intersectsTriangle:i=>{let r=0;if(this._tempLine.start.copy(i.a),this._tempLine.end.copy(i.b),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const i=this._tempVector.applyMatrix4(t.matrixWorld);e.setXYZ(s,i.x,i.y,i.z),r++,s++}if(this._tempLine.start.copy(i.b),this._tempLine.end.copy(i.c),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const i=this._tempVector.applyMatrix4(t.matrixWorld);e.setXYZ(s,i.x,i.y,i.z),r++,s++}if(this._tempLine.start.copy(i.c),this._tempLine.end.copy(i.a),this._localPlane.intersectLine(this._tempLine,this._tempVector)){const i=this._tempVector.applyMatrix4(t.matrixWorld);e.setXYZ(s,i.x,i.y,i.z),r++,s++}2!==r&&(s-=r)}}),s}}class Yl{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsAlignment(t,e){return(e||new Yl).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsAlignment(t,e){return t.setPosition(t.position()+4),(e||new Yl).__init(t.readInt32(t.position())+t.position(),t)}absolute(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}absoluteLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}absoluteArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}horizontal(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}horizontalLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}horizontalArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}vertical(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}verticalLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}verticalArray(){const t=this.bb.__offset(this.bb_pos,8);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startAlignment(t){t.startObject(3)}static addAbsolute(t,e){t.addFieldOffset(0,e,0)}static createAbsoluteVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startAbsoluteVector(t,e){t.startVector(4,e,4)}static addHorizontal(t,e){t.addFieldOffset(1,e,0)}static createHorizontalVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startHorizontalVector(t,e){t.startVector(4,e,4)}static addVertical(t,e){t.addFieldOffset(2,e,0)}static createVerticalVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startVerticalVector(t,e){t.startVector(4,e,4)}static endAlignment(t){return t.endObject()}static createAlignment(t,e,s,i){return Yl.startAlignment(t),Yl.addAbsolute(t,e),Yl.addHorizontal(t,s),Yl.addVertical(t,i),Yl.endAlignment(t)}}class Jl{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsAttribute(t,e){return(e||new Jl).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsAttribute(t,e){return t.setPosition(t.position()+4),(e||new Jl).__init(t.readInt32(t.position())+t.position(),t)}data(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}dataLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startAttribute(t){t.startObject(1)}static addData(t,e){t.addFieldOffset(0,e,0)}static createDataVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startDataVector(t,e){t.startVector(4,e,4)}static endAttribute(t){const e=t.endObject();return t.requiredField(e,4),e}static createAttribute(t,e){return Jl.startAttribute(t),Jl.addData(t,e),Jl.endAttribute(t)}}class Ql{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}x(){return this.bb.readFloat32(this.bb_pos)}mutate_x(t){return this.bb.writeFloat32(this.bb_pos+0,t),!0}y(){return this.bb.readFloat32(this.bb_pos+4)}mutate_y(t){return this.bb.writeFloat32(this.bb_pos+4,t),!0}z(){return this.bb.readFloat32(this.bb_pos+8)}mutate_z(t){return this.bb.writeFloat32(this.bb_pos+8,t),!0}static sizeOf(){return 12}static createFloatVector(t,e,s,i){return t.prep(4,12),t.writeFloat32(i),t.writeFloat32(s),t.writeFloat32(e),t.offset()}}class $l{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}aperture(){return this.bb.readFloat32(this.bb_pos)}mutate_aperture(t){return this.bb.writeFloat32(this.bb_pos+0,t),!0}position(t){return(t||new Ql).__init(this.bb_pos+4,this.bb)}radius(){return this.bb.readFloat32(this.bb_pos+16)}mutate_radius(t){return this.bb.writeFloat32(this.bb_pos+16,t),!0}xDirection(t){return(t||new Ql).__init(this.bb_pos+20,this.bb)}yDirection(t){return(t||new Ql).__init(this.bb_pos+32,this.bb)}static sizeOf(){return 44}static createCircleCurve(t,e,s,i,r,n,o,a,h,l,c,u){return t.prep(4,44),t.prep(4,12),t.writeFloat32(u),t.writeFloat32(c),t.writeFloat32(l),t.prep(4,12),t.writeFloat32(h),t.writeFloat32(a),t.writeFloat32(o),t.writeFloat32(n),t.prep(4,12),t.writeFloat32(r),t.writeFloat32(i),t.writeFloat32(s),t.writeFloat32(e),t.offset()}}class Kl{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}p1(t){return(t||new Ql).__init(this.bb_pos,this.bb)}p2(t){return(t||new Ql).__init(this.bb_pos+12,this.bb)}static sizeOf(){return 24}static createWire(t,e,s,i,r,n,o){return t.prep(4,24),t.prep(4,12),t.writeFloat32(o),t.writeFloat32(n),t.writeFloat32(r),t.prep(4,12),t.writeFloat32(i),t.writeFloat32(s),t.writeFloat32(e),t.offset()}}class tc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsWireSet(t,e){return(e||new tc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsWireSet(t,e){return t.setPosition(t.position()+4),(e||new tc).__init(t.readInt32(t.position())+t.position(),t)}ps(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new Ql).__init(this.bb.__vector(this.bb_pos+s)+12*t,this.bb):null}psLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startWireSet(t){t.startObject(1)}static addPs(t,e){t.addFieldOffset(0,e,0)}static startPsVector(t,e){t.startVector(12,e,4)}static endWireSet(t){return t.endObject()}static createWireSet(t,e){return tc.startWireSet(t),tc.addPs(t,e),tc.endWireSet(t)}}class ec{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsAxis(t,e){return(e||new ec).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsAxis(t,e){return t.setPosition(t.position()+4),(e||new ec).__init(t.readInt32(t.position())+t.position(),t)}wires(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new Kl).__init(this.bb.__vector(this.bb_pos+s)+24*t,this.bb):null}wiresLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}order(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}orderLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}orderArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}parts(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readInt8(this.bb.__vector(this.bb_pos+e)+t):0}partsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}partsArray(){const t=this.bb.__offset(this.bb_pos,8);return t?new Int8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}wireSets(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new tc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}wireSetsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}circleCurves(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?(e||new $l).__init(this.bb.__vector(this.bb_pos+s)+44*t,this.bb):null}circleCurvesLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}static startAxis(t){t.startObject(5)}static addWires(t,e){t.addFieldOffset(0,e,0)}static startWiresVector(t,e){t.startVector(24,e,4)}static addOrder(t,e){t.addFieldOffset(1,e,0)}static createOrderVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startOrderVector(t,e){t.startVector(4,e,4)}static addParts(t,e){t.addFieldOffset(2,e,0)}static createPartsVector(t,e){t.startVector(1,e.length,1);for(let s=e.length-1;s>=0;s--)t.addInt8(e[s]);return t.endVector()}static startPartsVector(t,e){t.startVector(1,e,1)}static addWireSets(t,e){t.addFieldOffset(3,e,0)}static createWireSetsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startWireSetsVector(t,e){t.startVector(4,e,4)}static addCircleCurves(t,e){t.addFieldOffset(4,e,0)}static startCircleCurvesVector(t,e){t.startVector(44,e,4)}static endAxis(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),t.requiredField(e,10),t.requiredField(e,12),e}static createAxis(t,e,s,i,r,n){return ec.startAxis(t),ec.addWires(t,e),ec.addOrder(t,s),ec.addParts(t,i),ec.addWireSets(t,r),ec.addCircleCurves(t,n),ec.endAxis(t)}}var sc=(t=>(t[t.NONE=0]="NONE",t[t.WIRE=1]="WIRE",t[t.WIRE_SET=2]="WIRE_SET",t[t.CIRCLE_CURVE=3]="CIRCLE_CURVE",t))(sc||{});class ic{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsBigShellHole(t,e){return(e||new ic).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsBigShellHole(t,e){return t.setPosition(t.position()+4),(e||new ic).__init(t.readInt32(t.position())+t.position(),t)}indices(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}indicesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}indicesArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}profileId(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint16(this.bb_pos+t):0}mutate_profile_id(t){const e=this.bb.__offset(this.bb_pos,6);return 0!==e&&(this.bb.writeUint16(this.bb_pos+e,t),!0)}static startBigShellHole(t){t.startObject(2)}static addIndices(t,e){t.addFieldOffset(0,e,0)}static createIndicesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startIndicesVector(t,e){t.startVector(4,e,4)}static addProfileId(t,e){t.addFieldInt16(1,e,0)}static endBigShellHole(t){const e=t.endObject();return t.requiredField(e,4),e}static createBigShellHole(t,e,s){return ic.startBigShellHole(t),ic.addIndices(t,e),ic.addProfileId(t,s),ic.endBigShellHole(t)}}class rc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsBigShellProfile(t,e){return(e||new rc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsBigShellProfile(t,e){return t.setPosition(t.position()+4),(e||new rc).__init(t.readInt32(t.position())+t.position(),t)}indices(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}indicesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}indicesArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startBigShellProfile(t){t.startObject(1)}static addIndices(t,e){t.addFieldOffset(0,e,0)}static createIndicesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startIndicesVector(t,e){t.startVector(4,e,4)}static endBigShellProfile(t){const e=t.endObject();return t.requiredField(e,4),e}static createBigShellProfile(t,e){return rc.startBigShellProfile(t),rc.addIndices(t,e),rc.endBigShellProfile(t)}}class nc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}min(t){return(t||new Ql).__init(this.bb_pos,this.bb)}max(t){return(t||new Ql).__init(this.bb_pos+12,this.bb)}static sizeOf(){return 24}static createBoundingBox(t,e,s,i,r,n,o){return t.prep(4,24),t.prep(4,12),t.writeFloat32(o),t.writeFloat32(n),t.writeFloat32(r),t.prep(4,12),t.writeFloat32(i),t.writeFloat32(s),t.writeFloat32(e),t.offset()}}class oc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsCircleExtrusion(t,e){return(e||new oc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsCircleExtrusion(t,e){return t.setPosition(t.position()+4),(e||new oc).__init(t.readInt32(t.position())+t.position(),t)}radius(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readFloat64(this.bb.__vector(this.bb_pos+e)+8*t):0}radiusLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}radiusArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Float64Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}axes(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new ec).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}axesLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}static startCircleExtrusion(t){t.startObject(2)}static addRadius(t,e){t.addFieldOffset(0,e,0)}static createRadiusVector(t,e){t.startVector(8,e.length,8);for(let s=e.length-1;s>=0;s--)t.addFloat64(e[s]);return t.endVector()}static startRadiusVector(t,e){t.startVector(8,e,8)}static addAxes(t,e){t.addFieldOffset(1,e,0)}static createAxesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startAxesVector(t,e){t.startVector(4,e,4)}static endCircleExtrusion(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),e}static createCircleExtrusion(t,e,s){return oc.startCircleExtrusion(t),oc.addRadius(t,e),oc.addAxes(t,s),oc.endCircleExtrusion(t)}}class ac{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}x(){return this.bb.readFloat64(this.bb_pos)}mutate_x(t){return this.bb.writeFloat64(this.bb_pos+0,t),!0}y(){return this.bb.readFloat64(this.bb_pos+8)}mutate_y(t){return this.bb.writeFloat64(this.bb_pos+8,t),!0}z(){return this.bb.readFloat64(this.bb_pos+16)}mutate_z(t){return this.bb.writeFloat64(this.bb_pos+16,t),!0}static sizeOf(){return 24}static createDoubleVector(t,e,s,i){return t.prep(8,24),t.writeFloat64(i),t.writeFloat64(s),t.writeFloat64(e),t.offset()}}class hc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGeometryLines(t,e){return(e||new hc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGeometryLines(t,e){return t.setPosition(t.position()+4),(e||new hc).__init(t.readInt32(t.position())+t.position(),t)}points(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readFloat32(this.bb.__vector(this.bb_pos+e)+4*t):0}pointsLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}pointsArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Float32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startGeometryLines(t){t.startObject(1)}static addPoints(t,e){t.addFieldOffset(0,e,0)}static createPointsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addFloat32(e[s]);return t.endVector()}static startPointsVector(t,e){t.startVector(4,e,4)}static endGeometryLines(t){const e=t.endObject();return t.requiredField(e,4),e}static createGeometryLines(t,e){return hc.startGeometryLines(t),hc.addPoints(t,e),hc.endGeometryLines(t)}}class lc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}id(){return this.bb.readUint32(this.bb_pos)}mutate_id(t){return this.bb.writeUint32(this.bb_pos+0,t),!0}geometryClass(){return this.bb.readInt8(this.bb_pos+4)}mutate_geometry_class(t){return this.bb.writeInt8(this.bb_pos+4,t),!0}static sizeOf(){return 8}static createGeometryRepresentation(t,e,s){return t.prep(4,8),t.pad(3),t.writeInt8(s),t.writeInt32(e),t.offset()}}class cc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}id(){return this.bb.readUint32(this.bb_pos)}mutate_id(t){return this.bb.writeUint32(this.bb_pos+0,t),!0}transform(){return this.bb.readUint32(this.bb_pos+4)}mutate_transform(t){return this.bb.writeUint32(this.bb_pos+4,t),!0}static sizeOf(){return 8}static createGeometrySample(t,e,s){return t.prep(4,8),t.writeInt32(s),t.writeInt32(e),t.offset()}}class uc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}start(t){return(t||new Ql).__init(this.bb_pos,this.bb)}end(t){return(t||new Ql).__init(this.bb_pos+12,this.bb)}height(){return this.bb.readFloat32(this.bb_pos+24)}mutate_height(t){return this.bb.writeFloat32(this.bb_pos+24,t),!0}width(){return this.bb.readFloat32(this.bb_pos+28)}mutate_width(t){return this.bb.writeFloat32(this.bb_pos+28,t),!0}offset(){return this.bb.readFloat32(this.bb_pos+32)}mutate_offset(t){return this.bb.writeFloat32(this.bb_pos+32,t),!0}static sizeOf(){return 36}static createGeometryWall(t,e,s,i,r,n,o,a,h,l){return t.prep(4,36),t.writeFloat32(l),t.writeFloat32(h),t.writeFloat32(a),t.prep(4,12),t.writeFloat32(o),t.writeFloat32(n),t.writeFloat32(r),t.prep(4,12),t.writeFloat32(i),t.writeFloat32(s),t.writeFloat32(e),t.offset()}}class dc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}position(t){return(t||new ac).__init(this.bb_pos,this.bb)}xDirection(t){return(t||new Ql).__init(this.bb_pos+24,this.bb)}yDirection(t){return(t||new Ql).__init(this.bb_pos+36,this.bb)}static sizeOf(){return 48}static createTransform(t,e,s,i,r,n,o,a,h,l){return t.prep(8,48),t.prep(4,12),t.writeFloat32(l),t.writeFloat32(h),t.writeFloat32(a),t.prep(4,12),t.writeFloat32(o),t.writeFloat32(n),t.writeFloat32(r),t.prep(8,24),t.writeFloat64(i),t.writeFloat64(s),t.writeFloat64(e),t.offset()}}class pc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsGeometries(t,e){return(e||new pc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsGeometries(t,e){return t.setPosition(t.position()+4),(e||new pc).__init(t.readInt32(t.position())+t.position(),t)}samples(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new cc).__init(this.bb.__vector(this.bb_pos+s)+8*t,this.bb):null}samplesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}sampleIds(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}sampleIdsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}sampleIdsArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}representations(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new lc).__init(this.bb.__vector(this.bb_pos+s)+8*t,this.bb):null}representationsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}representationIds(t){const e=this.bb.__offset(this.bb_pos,10);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}representationIdsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}representationIdsArray(){const t=this.bb.__offset(this.bb_pos,10);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}transforms(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?(e||new dc).__init(this.bb.__vector(this.bb_pos+s)+48*t,this.bb):null}transformsLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}transformIds(t){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}transformIdsLength(){const t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__vector_len(this.bb_pos+t):0}transformIdsArray(){const t=this.bb.__offset(this.bb_pos,14);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}representationsSamples(t){const e=this.bb.__offset(this.bb_pos,16);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}representationsSamplesLength(){const t=this.bb.__offset(this.bb_pos,16);return t?this.bb.__vector_len(this.bb_pos+t):0}representationsSamplesArray(){const t=this.bb.__offset(this.bb_pos,16);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}lines(t,e){const s=this.bb.__offset(this.bb_pos,18);return s?(e||new hc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}linesLength(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.__vector_len(this.bb_pos+t):0}walls(t,e){const s=this.bb.__offset(this.bb_pos,20);return s?(e||new uc).__init(this.bb.__vector(this.bb_pos+s)+36*t,this.bb):null}wallsLength(){const t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__vector_len(this.bb_pos+t):0}static startGeometries(t){t.startObject(9)}static addSamples(t,e){t.addFieldOffset(0,e,0)}static startSamplesVector(t,e){t.startVector(8,e,4)}static addSampleIds(t,e){t.addFieldOffset(1,e,0)}static createSampleIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startSampleIdsVector(t,e){t.startVector(4,e,4)}static addRepresentations(t,e){t.addFieldOffset(2,e,0)}static startRepresentationsVector(t,e){t.startVector(8,e,4)}static addRepresentationIds(t,e){t.addFieldOffset(3,e,0)}static createRepresentationIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startRepresentationIdsVector(t,e){t.startVector(4,e,4)}static addTransforms(t,e){t.addFieldOffset(4,e,0)}static startTransformsVector(t,e){t.startVector(48,e,8)}static addTransformIds(t,e){t.addFieldOffset(5,e,0)}static createTransformIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startTransformIdsVector(t,e){t.startVector(4,e,4)}static addRepresentationsSamples(t,e){t.addFieldOffset(6,e,0)}static createRepresentationsSamplesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startRepresentationsSamplesVector(t,e){t.startVector(4,e,4)}static addLines(t,e){t.addFieldOffset(7,e,0)}static createLinesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startLinesVector(t,e){t.startVector(4,e,4)}static addWalls(t,e){t.addFieldOffset(8,e,0)}static startWallsVector(t,e){t.startVector(36,e,4)}static endGeometries(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,8),t.requiredField(e,12),t.requiredField(e,18),e}static createGeometries(t,e,s,i,r,n,o,a,h,l){return pc.startGeometries(t),pc.addSamples(t,e),pc.addSampleIds(t,s),pc.addRepresentations(t,i),pc.addRepresentationIds(t,r),pc.addTransforms(t,n),pc.addTransformIds(t,o),pc.addRepresentationsSamples(t,a),pc.addLines(t,h),pc.addWalls(t,l),pc.endGeometries(t)}}class fc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}r(){return this.bb.readUint8(this.bb_pos)}mutate_r(t){return this.bb.writeUint8(this.bb_pos+0,t),!0}g(){return this.bb.readUint8(this.bb_pos+1)}mutate_g(t){return this.bb.writeUint8(this.bb_pos+1,t),!0}b(){return this.bb.readUint8(this.bb_pos+2)}mutate_b(t){return this.bb.writeUint8(this.bb_pos+2,t),!0}a(){return this.bb.readUint8(this.bb_pos+3)}mutate_a(t){return this.bb.writeUint8(this.bb_pos+3,t),!0}renderedFaces(){return this.bb.readInt8(this.bb_pos+4)}mutate_rendered_faces(t){return this.bb.writeInt8(this.bb_pos+4,t),!0}stroke(){return this.bb.readInt8(this.bb_pos+5)}mutate_stroke(t){return this.bb.writeInt8(this.bb_pos+5,t),!0}static sizeOf(){return 6}static createMaterial(t,e,s,i,r,n,o){return t.prep(1,6),t.writeInt8(o),t.writeInt8(n),t.writeInt8(r),t.writeInt8(i),t.writeInt8(s),t.writeInt8(e),t.offset()}}class mc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}id(){return this.bb.readUint32(this.bb_pos)}mutate_id(t){return this.bb.writeUint32(this.bb_pos+0,t),!0}bbox(t){return(t||new nc).__init(this.bb_pos+4,this.bb)}representationClass(){return this.bb.readInt8(this.bb_pos+28)}mutate_representation_class(t){return this.bb.writeInt8(this.bb_pos+28,t),!0}static sizeOf(){return 32}static createRepresentation(t,e,s,i,r,n,o,a,h){return t.prep(4,32),t.pad(3),t.writeInt8(h),t.prep(4,24),t.prep(4,12),t.writeFloat32(a),t.writeFloat32(o),t.writeFloat32(n),t.prep(4,12),t.writeFloat32(r),t.writeFloat32(i),t.writeFloat32(s),t.writeInt32(e),t.offset()}}class _c{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}item(){return this.bb.readUint32(this.bb_pos)}mutate_item(t){return this.bb.writeUint32(this.bb_pos+0,t),!0}material(){return this.bb.readUint32(this.bb_pos+4)}mutate_material(t){return this.bb.writeUint32(this.bb_pos+4,t),!0}representation(){return this.bb.readUint32(this.bb_pos+8)}mutate_representation(t){return this.bb.writeUint32(this.bb_pos+8,t),!0}localTransform(){return this.bb.readUint32(this.bb_pos+12)}mutate_local_transform(t){return this.bb.writeUint32(this.bb_pos+12,t),!0}static sizeOf(){return 16}static createSample(t,e,s,i,r){return t.prep(4,16),t.writeInt32(r),t.writeInt32(i),t.writeInt32(s),t.writeInt32(e),t.offset()}}class bc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsShellHole(t,e){return(e||new bc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsShellHole(t,e){return t.setPosition(t.position()+4),(e||new bc).__init(t.readInt32(t.position())+t.position(),t)}indices(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+2*t):0}indicesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}indicesArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}profileId(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.readUint16(this.bb_pos+t):0}mutate_profile_id(t){const e=this.bb.__offset(this.bb_pos,6);return 0!==e&&(this.bb.writeUint16(this.bb_pos+e,t),!0)}static startShellHole(t){t.startObject(2)}static addIndices(t,e){t.addFieldOffset(0,e,0)}static createIndicesVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startIndicesVector(t,e){t.startVector(2,e,2)}static addProfileId(t,e){t.addFieldInt16(1,e,0)}static endShellHole(t){const e=t.endObject();return t.requiredField(e,4),e}static createShellHole(t,e,s){return bc.startShellHole(t),bc.addIndices(t,e),bc.addProfileId(t,s),bc.endShellHole(t)}}class gc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsShellProfile(t,e){return(e||new gc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsShellProfile(t,e){return t.setPosition(t.position()+4),(e||new gc).__init(t.readInt32(t.position())+t.position(),t)}indices(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.readUint16(this.bb.__vector(this.bb_pos+e)+2*t):0}indicesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}indicesArray(){const t=this.bb.__offset(this.bb_pos,4);return t?new Uint16Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}static startShellProfile(t){t.startObject(1)}static addIndices(t,e){t.addFieldOffset(0,e,0)}static createIndicesVector(t,e){t.startVector(2,e.length,2);for(let s=e.length-1;s>=0;s--)t.addInt16(e[s]);return t.endVector()}static startIndicesVector(t,e){t.startVector(2,e,2)}static endShellProfile(t){const e=t.endObject();return t.requiredField(e,4),e}static createShellProfile(t,e){return gc.startShellProfile(t),gc.addIndices(t,e),gc.endShellProfile(t)}}var yc=(t=>(t[t.NONE=0]="NONE",t[t.BIG=1]="BIG",t))(yc||{});class xc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsShell(t,e){return(e||new xc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsShell(t,e){return t.setPosition(t.position()+4),(e||new xc).__init(t.readInt32(t.position())+t.position(),t)}profiles(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?(e||new gc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}profilesLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}holes(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?(e||new bc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}holesLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}points(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new Ql).__init(this.bb.__vector(this.bb_pos+s)+12*t,this.bb):null}pointsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}bigProfiles(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new rc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}bigProfilesLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}bigHoles(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?(e||new ic).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}bigHolesLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}type(){const t=this.bb.__offset(this.bb_pos,14);return t?this.bb.readInt8(this.bb_pos+t):yc.NONE}mutate_type(t){const e=this.bb.__offset(this.bb_pos,14);return 0!==e&&(this.bb.writeInt8(this.bb_pos+e,t),!0)}static startShell(t){t.startObject(6)}static addProfiles(t,e){t.addFieldOffset(0,e,0)}static createProfilesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startProfilesVector(t,e){t.startVector(4,e,4)}static addHoles(t,e){t.addFieldOffset(1,e,0)}static createHolesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startHolesVector(t,e){t.startVector(4,e,4)}static addPoints(t,e){t.addFieldOffset(2,e,0)}static startPointsVector(t,e){t.startVector(12,e,4)}static addBigProfiles(t,e){t.addFieldOffset(3,e,0)}static createBigProfilesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startBigProfilesVector(t,e){t.startVector(4,e,4)}static addBigHoles(t,e){t.addFieldOffset(4,e,0)}static createBigHolesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startBigHolesVector(t,e){t.startVector(4,e,4)}static addType(t,e){t.addFieldInt8(5,e,yc.NONE)}static endShell(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),t.requiredField(e,10),t.requiredField(e,12),e}static createShell(t,e,s,i,r,n,o){return xc.startShell(t),xc.addProfiles(t,e),xc.addHoles(t,s),xc.addPoints(t,i),xc.addBigProfiles(t,r),xc.addBigHoles(t,n),xc.addType(t,o),xc.endShell(t)}}class wc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsMeshes(t,e){return(e||new wc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsMeshes(t,e){return t.setPosition(t.position()+4),(e||new wc).__init(t.readInt32(t.position())+t.position(),t)}coordinates(t){const e=this.bb.__offset(this.bb_pos,4);return e?(t||new dc).__init(this.bb_pos+e,this.bb):null}meshesItems(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}meshesItemsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}meshesItemsArray(){const t=this.bb.__offset(this.bb_pos,6);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}samples(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new _c).__init(this.bb.__vector(this.bb_pos+s)+16*t,this.bb):null}samplesLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}representations(t,e){const s=this.bb.__offset(this.bb_pos,10);return s?(e||new mc).__init(this.bb.__vector(this.bb_pos+s)+32*t,this.bb):null}representationsLength(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.__vector_len(this.bb_pos+t):0}materials(t,e){const s=this.bb.__offset(this.bb_pos,12);return s?(e||new fc).__init(this.bb.__vector(this.bb_pos+s)+6*t,this.bb):null}materialsLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}circleExtrusions(t,e){const s=this.bb.__offset(this.bb_pos,14);return s?(e||new oc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}circleExtrusionsLength(){const t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__vector_len(this.bb_pos+t):0}shells(t,e){const s=this.bb.__offset(this.bb_pos,16);return s?(e||new xc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}shellsLength(){const t=this.bb.__offset(this.bb_pos,16);return t?this.bb.__vector_len(this.bb_pos+t):0}localTransforms(t,e){const s=this.bb.__offset(this.bb_pos,18);return s?(e||new dc).__init(this.bb.__vector(this.bb_pos+s)+48*t,this.bb):null}localTransformsLength(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.__vector_len(this.bb_pos+t):0}globalTransforms(t,e){const s=this.bb.__offset(this.bb_pos,20);return s?(e||new dc).__init(this.bb.__vector(this.bb_pos+s)+48*t,this.bb):null}globalTransformsLength(){const t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__vector_len(this.bb_pos+t):0}static startMeshes(t){t.startObject(9)}static addCoordinates(t,e){t.addFieldStruct(0,e,0)}static addMeshesItems(t,e){t.addFieldOffset(1,e,0)}static createMeshesItemsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startMeshesItemsVector(t,e){t.startVector(4,e,4)}static addSamples(t,e){t.addFieldOffset(2,e,0)}static startSamplesVector(t,e){t.startVector(16,e,4)}static addRepresentations(t,e){t.addFieldOffset(3,e,0)}static startRepresentationsVector(t,e){t.startVector(32,e,4)}static addMaterials(t,e){t.addFieldOffset(4,e,0)}static startMaterialsVector(t,e){t.startVector(6,e,1)}static addCircleExtrusions(t,e){t.addFieldOffset(5,e,0)}static createCircleExtrusionsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startCircleExtrusionsVector(t,e){t.startVector(4,e,4)}static addShells(t,e){t.addFieldOffset(6,e,0)}static createShellsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startShellsVector(t,e){t.startVector(4,e,4)}static addLocalTransforms(t,e){t.addFieldOffset(7,e,0)}static startLocalTransformsVector(t,e){t.startVector(48,e,8)}static addGlobalTransforms(t,e){t.addFieldOffset(8,e,0)}static startGlobalTransformsVector(t,e){t.startVector(48,e,8)}static endMeshes(t){const e=t.endObject();return t.requiredField(e,4),t.requiredField(e,6),t.requiredField(e,8),t.requiredField(e,10),t.requiredField(e,12),t.requiredField(e,14),t.requiredField(e,16),t.requiredField(e,18),t.requiredField(e,20),e}static createMeshes(t,e,s,i,r,n,o,a,h,l){return wc.startMeshes(t),wc.addCoordinates(t,e),wc.addMeshesItems(t,s),wc.addSamples(t,i),wc.addRepresentations(t,r),wc.addMaterials(t,n),wc.addCircleExtrusions(t,o),wc.addShells(t,a),wc.addLocalTransforms(t,h),wc.addGlobalTransforms(t,l),wc.endMeshes(t)}}class vc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsRelation(t,e){return(e||new vc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsRelation(t,e){return t.setPosition(t.position()+4),(e||new vc).__init(t.readInt32(t.position())+t.position(),t)}data(t,e){const s=this.bb.__offset(this.bb_pos,4);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}dataLength(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__vector_len(this.bb_pos+t):0}static startRelation(t){t.startObject(1)}static addData(t,e){t.addFieldOffset(0,e,0)}static createDataVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startDataVector(t,e){t.startVector(4,e,4)}static endRelation(t){const e=t.endObject();return t.requiredField(e,4),e}static createRelation(t,e){return vc.startRelation(t),vc.addData(t,e),vc.endRelation(t)}}class Sc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsSpatialStructure(t,e){return(e||new Sc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsSpatialStructure(t,e){return t.setPosition(t.position()+4),(e||new Sc).__init(t.readInt32(t.position())+t.position(),t)}localId(){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.readUint32(this.bb_pos+t):null}mutate_local_id(t){const e=this.bb.__offset(this.bb_pos,4);return 0!==e&&(this.bb.writeUint32(this.bb_pos+e,t),!0)}category(t){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.__string(this.bb_pos+e,t):null}children(t,e){const s=this.bb.__offset(this.bb_pos,8);return s?(e||new Sc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}childrenLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}static startSpatialStructure(t){t.startObject(3)}static addLocalId(t,e){t.addFieldInt32(0,e,null)}static addCategory(t,e){t.addFieldOffset(1,e,0)}static addChildren(t,e){t.addFieldOffset(2,e,0)}static createChildrenVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startChildrenVector(t,e){t.startVector(4,e,4)}static endSpatialStructure(t){return t.endObject()}static createSpatialStructure(t,e,s,i){return Sc.startSpatialStructure(t),null!==e&&Sc.addLocalId(t,e),Sc.addCategory(t,s),Sc.addChildren(t,i),Sc.endSpatialStructure(t)}}class Mc{constructor(){ot(this,"bb",null),ot(this,"bb_pos",0)}__init(t,e){return this.bb_pos=t,this.bb=e,this}static getRootAsModel(t,e){return(e||new Mc).__init(t.readInt32(t.position())+t.position(),t)}static getSizePrefixedRootAsModel(t,e){return t.setPosition(t.position()+4),(e||new Mc).__init(t.readInt32(t.position())+t.position(),t)}static bufferHasIdentifier(t){return t.__has_identifier("0001")}metadata(t){const e=this.bb.__offset(this.bb_pos,4);return e?this.bb.__string(this.bb_pos+e,t):null}guids(t,e){const s=this.bb.__offset(this.bb_pos,6);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}guidsLength(){const t=this.bb.__offset(this.bb_pos,6);return t?this.bb.__vector_len(this.bb_pos+t):0}guidsItems(t){const e=this.bb.__offset(this.bb_pos,8);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}guidsItemsLength(){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__vector_len(this.bb_pos+t):0}guidsItemsArray(){const t=this.bb.__offset(this.bb_pos,8);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}maxLocalId(){const t=this.bb.__offset(this.bb_pos,10);return t?this.bb.readUint32(this.bb_pos+t):0}mutate_max_local_id(t){const e=this.bb.__offset(this.bb_pos,10);return 0!==e&&(this.bb.writeUint32(this.bb_pos+e,t),!0)}localIds(t){const e=this.bb.__offset(this.bb_pos,12);return e?this.bb.readUint32(this.bb.__vector(this.bb_pos+e)+4*t):0}localIdsLength(){const t=this.bb.__offset(this.bb_pos,12);return t?this.bb.__vector_len(this.bb_pos+t):0}localIdsArray(){const t=this.bb.__offset(this.bb_pos,12);return t?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}categories(t,e){const s=this.bb.__offset(this.bb_pos,14);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}categoriesLength(){const t=this.bb.__offset(this.bb_pos,14);return t?this.bb.__vector_len(this.bb_pos+t):0}meshes(t){const e=this.bb.__offset(this.bb_pos,16);return e?(t||new wc).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}attributes(t,e){const s=this.bb.__offset(this.bb_pos,18);return s?(e||new Jl).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}attributesLength(){const t=this.bb.__offset(this.bb_pos,18);return t?this.bb.__vector_len(this.bb_pos+t):0}relations(t,e){const s=this.bb.__offset(this.bb_pos,20);return s?(e||new vc).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}relationsLength(){const t=this.bb.__offset(this.bb_pos,20);return t?this.bb.__vector_len(this.bb_pos+t):0}relationsItems(t){const e=this.bb.__offset(this.bb_pos,22);return e?this.bb.readInt32(this.bb.__vector(this.bb_pos+e)+4*t):0}relationsItemsLength(){const t=this.bb.__offset(this.bb_pos,22);return t?this.bb.__vector_len(this.bb_pos+t):0}relationsItemsArray(){const t=this.bb.__offset(this.bb_pos,22);return t?new Int32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+t),this.bb.__vector_len(this.bb_pos+t)):null}guid(t){const e=this.bb.__offset(this.bb_pos,24);return e?this.bb.__string(this.bb_pos+e,t):null}spatialStructure(t){const e=this.bb.__offset(this.bb_pos,26);return e?(t||new Sc).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}alignments(t,e){const s=this.bb.__offset(this.bb_pos,28);return s?(e||new Yl).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+s)+4*t),this.bb):null}alignmentsLength(){const t=this.bb.__offset(this.bb_pos,28);return t?this.bb.__vector_len(this.bb_pos+t):0}geometries(t){const e=this.bb.__offset(this.bb_pos,30);return e?(t||new pc).__init(this.bb.__indirect(this.bb_pos+e),this.bb):null}uniqueAttributes(t,e){const s=this.bb.__offset(this.bb_pos,32);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}uniqueAttributesLength(){const t=this.bb.__offset(this.bb_pos,32);return t?this.bb.__vector_len(this.bb_pos+t):0}relationNames(t,e){const s=this.bb.__offset(this.bb_pos,34);return s?this.bb.__string(this.bb.__vector(this.bb_pos+s)+4*t,e):null}relationNamesLength(){const t=this.bb.__offset(this.bb_pos,34);return t?this.bb.__vector_len(this.bb_pos+t):0}static startModel(t){t.startObject(16)}static addMetadata(t,e){t.addFieldOffset(0,e,0)}static addGuids(t,e){t.addFieldOffset(1,e,0)}static createGuidsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startGuidsVector(t,e){t.startVector(4,e,4)}static addGuidsItems(t,e){t.addFieldOffset(2,e,0)}static createGuidsItemsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startGuidsItemsVector(t,e){t.startVector(4,e,4)}static addMaxLocalId(t,e){t.addFieldInt32(3,e,0)}static addLocalIds(t,e){t.addFieldOffset(4,e,0)}static createLocalIdsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startLocalIdsVector(t,e){t.startVector(4,e,4)}static addCategories(t,e){t.addFieldOffset(5,e,0)}static createCategoriesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startCategoriesVector(t,e){t.startVector(4,e,4)}static addMeshes(t,e){t.addFieldOffset(6,e,0)}static addAttributes(t,e){t.addFieldOffset(7,e,0)}static createAttributesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startAttributesVector(t,e){t.startVector(4,e,4)}static addRelations(t,e){t.addFieldOffset(8,e,0)}static createRelationsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelationsVector(t,e){t.startVector(4,e,4)}static addRelationsItems(t,e){t.addFieldOffset(9,e,0)}static createRelationsItemsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addInt32(e[s]);return t.endVector()}static startRelationsItemsVector(t,e){t.startVector(4,e,4)}static addGuid(t,e){t.addFieldOffset(10,e,0)}static addSpatialStructure(t,e){t.addFieldOffset(11,e,0)}static addAlignments(t,e){t.addFieldOffset(12,e,0)}static createAlignmentsVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startAlignmentsVector(t,e){t.startVector(4,e,4)}static addGeometries(t,e){t.addFieldOffset(13,e,0)}static addUniqueAttributes(t,e){t.addFieldOffset(14,e,0)}static createUniqueAttributesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startUniqueAttributesVector(t,e){t.startVector(4,e,4)}static addRelationNames(t,e){t.addFieldOffset(15,e,0)}static createRelationNamesVector(t,e){t.startVector(4,e.length,4);for(let s=e.length-1;s>=0;s--)t.addOffset(e[s]);return t.endVector()}static startRelationNamesVector(t,e){t.startVector(4,e,4)}static endModel(t){const e=t.endObject();return t.requiredField(e,6),t.requiredField(e,8),t.requiredField(e,12),t.requiredField(e,14),t.requiredField(e,16),t.requiredField(e,24),e}static finishModelBuffer(t,e){t.finish(e,"0001")}static finishSizePrefixedModelBuffer(t,e){t.finish(e,"0001",!0)}}var Ac=(t=>(t[t.ONE=0]="ONE",t[t.TWO=1]="TWO",t))(Ac||{}),Ic=(t=>(t[t.NONE=0]="NONE",t[t.SHELL=1]="SHELL",t[t.CIRCLE_EXTRUSION=2]="CIRCLE_EXTRUSION",t))(Ic||{});class Cc{constructor(){ot(this,"int"),ot(this,"float"),ot(this,"buffer"),ot(this,"s1",4),ot(this,"s2",8);const{intBuffer:t,floatBuffer:e,buffer:s}=this.newBuffers();this.int=t,this.float=e,this.buffer=s}newBuffers(){const t=new Int32Array(1),e=t.buffer;return{intBuffer:t,floatBuffer:new Float32Array(e),buffer:new Uint8Array(e)}}}class zc{static check(t){const e=Number.isInteger(t),s=t<this._max,i=t>this._min;return e&&s&&i}}ot(zc,"_max",2147483647),ot(zc,"_min",-2147483648);const Tc=class t{constructor(){ot(this,"_core",new Cc),ot(this,"_handlers"),ot(this,"_result",-1),ot(this,"handleObject",(t=>{const e=Object.keys(t);for(const s of e)t.hasOwnProperty(s)&&this.compute(t[s])})),ot(this,"handleString",(t=>{const e=t.length;for(let s=0;s<e;++s){const e=t.codePointAt(s);this._core.int[0]=e,this.update()}})),ot(this,"handleBoolean",(t=>{this._core.int[0]=t?1:0,this.update()})),ot(this,"handleNumber",(t=>{(zc.check(t)?this._core.int:this._core.float)[0]=t,this.update()})),this._handlers=this.newHandlers()}get value(){return~this._result}fromMaterialData(t){const{modelId:e,objectClass:s,currentLod:i,templateId:r,...n}=t;this.reset(),this.compute(e),this.compute(s),this.compute(n),this.compute(i),this.compute(void 0!==r)}generate(t){this.reset();for(const e of t)this.compute(e);return this.value}compute(t){return this.getHandler(t)(t),this}reset(){return this._result=-1,this}getHandler(t){const e=typeof t,s=this._handlers[e];if(!s)throw new Error("Fragments: Unsupported input type");return s}newHandlers(){return{number:this.handleNumber,boolean:this.handleBoolean,string:this.handleString,object:this.handleObject}}update(){for(let e=0;e<this._core.s1;++e){this._result^=this._core.buffer[e];for(let e=0;e<this._core.s2;++e)1&this._result?this._result=this._result>>1^t._polynomial:this._result>>=1}}};ot(Tc,"_polynomial",2197175160);let Pc=Tc;const Bc=class t{constructor(t,e){ot(this,"_first"),this._first=this.newData(t,e)}static getComplementary(t,e){let s=0;const i=t.position.length;s=this.makeBufferComplementary(i,t,s,e),s!==1/0&&e(s,1/0)}static get(t,e,s,i){const{filtered:r,position:n,size:o}=this.getData(t,s);return this.setAllBufferData(r,e,n,o,i),{position:n,size:o}}fullOf(t){const e=this._first.following,s=this._first.data;return null===e&&s===t}update(t,e){const s=this.getBufferData(t);if(!(s.data===e)){const{a:i,c:r,b:n}=this.newBuffers(t,s,e);this.setupInputData(s,i,r),this.setupUpdateBuffers(i,n,r)}}size(t){let e=0,s=this._first;for(;null!==s;){this.doesFilterPass(t,s)&&e++,s=s.following}return e}static setAllBufferData(t,e,s,i,r){for(let n=0;n<t.length;++n){const o=t[n];this.transform(o,e),this.setBuffers(s,i,n),r&&r(n,o.data)}}static makeBufferComplementary(t,e,s,i){for(let r=0;r<t;++r){const t=this.getBuffers(e,r),{position:n,size:o}=t;n>s&&i(s,n-s),s=n+o}return s}static setBuffers(t,e,s){t[s]=this._tempData.position;const i=this._tempData.size===1/0;e[s]=i?this._inf:this._tempData.size}add(e,s,i){if(!t._stash.length)return this.newData(s,i,e);const r=t._stash.pop();if(!r)throw new Error("Fragments: No stash found");return r.position=e,r.size=s,r.data=i,r}remove(e){e&&(e.following=null,e.past=null,t._stash.push(e))}static getData(t,e){const s=t.filter(e),i=s.length;return{filtered:s,position:new Uint32Array(i),size:new Uint32Array(i)}}filter(t){const e=[];let s=this._first;for(;null!==s;){this.doesFilterPass(t,s)&&e.push(s),s=s.following}return e}static transform(t,e){const s=this.getTempData(),i=t.position+t.size,r=i===e.length;if(s.position=e[t.position],r)s.size=1/0;else{const t=e[i];s.size=t-s.position}return s}static getBuffers(t,e){const s=t.position[e];let i;return i=t.size[e]===this._inf?1/0:t.size[e],{position:s,size:i}}static getTempData(){return this._tempData?this._tempData:{position:0,size:0}}doesFilterPass(t,e){return!t||t(e.data)}setupUpdateBuffers(t,e,s){this.chainBuffers(t,e,s),this.setupFirstBuffer(t,e),this.setupLastBuffer(s,e),this.setupMiddleBufferStart(e),this.setupMiddleBufferEnd(e)}setupMiddleBufferEnd(t){var e;if((null==(e=t.following)?void 0:e.data)===t.data){if(!t.following)return;const e=t.following.size+t.size,s=t.following.following;t.size=e,this.remove(t.following),t.following=s,t.following&&(t.following.past=t)}}setupFirstBuffer(t,e){t.size||(t.past?t.past.following=e:this._first=e,e.past=t.past,this.remove(t))}setupMiddleBufferStart(t){var e;if((null==(e=t.past)?void 0:e.data)===t.data){if(!t.past)return;t.size=t.past.size+t.size,t.position=t.past.position;const e=t.past.past;this.remove(t.past),t.past=e,t.past?t.past.following=t:this._first=t}}chainBuffers(t,e,s){t.following=e,e.past=t,e.following=s,s.past=e}setupLastBuffer(t,e){t.size||(t.following&&(t.following.past=e),e.following=t.following,this.remove(t))}newBuffers(t,e,s){const i=t-e.position,r=this.add(e.position,i,e.data),n=this.add(t,1,s),o=e.size-r.size-1;return{a:r,c:this.add(t+1,o,e.data),b:n}}setupInputData(t,e,s){t.past?(t.past.following=e,e.past=t.past):this._first=e,t.following&&(t.following.past=s,s.following=t.following),this.remove(t)}newData(t,e,s=0){return{position:s,size:t,past:null,following:null,data:e}}getBufferData(t){let e=this._first;for(;;){const s=null===e,i=e.position<=t,r=t<e.position+e.size;if(s||i&&r)return e;e=e.following}}};ot(Bc,"_stash",[]),ot(Bc,"_tempData",{position:0,size:0}),ot(Bc,"_inf",4294967295);let Ec=Bc;class Fc{static fixNumber(t){return Number.isNaN(t)?0:Number.isFinite(t)?t:0}static forEach(t,e){if(Array.isArray(t)){let s=0;for(const i of t)e(i,s++)}else e(t,0)}}class Rc{static check(t,e,s){const i=this.get(s),r=t[e];return Boolean(r&i)}static apply(t,e,s,i){const r=this.get(s);i?t[e]|=r:t[e]&=~r}static checkMemory(t){if(t>mi)throw new Error("Fragments: Memory overflow!")}static get(t){return 1<<t}}class kc{static parseMaterial(t){const e=t.r()/255,s=t.g()/255,i=t.b()/255,r=t.a()/255,n=t.a()<255;return{color:new _s(e,s,i),renderedFaces:t.renderedFaces(),opacity:r,transparent:n}}static parseBox(t,e){this.getBox(t,e,"min"),this.getBox(t,e,"max")}static parseTransform(t,e){return this.getVector(t,"position",this._doubleVector),this.getVector(t,"xDirection",this._floatVector),this.getVector(t,"yDirection",this._floatVector),this.computeZVector(),this.setTransform(e),e}static setTransform(t){const{x:e,y:s,z:i}=this._temp.xDirection,{x:r,y:n,z:o}=this._temp.yDirection,{x:a,y:h,z:l}=this._temp.zDirection,{x:c,y:u,z:d}=this._temp.position;t.set(e,r,a,c,s,n,h,u,i,o,l,d,0,0,0,1)}static getBox(t,e,s){t[s](this._floatVector);const i=this._floatVector.x(),r=this._floatVector.y(),n=this._floatVector.z();e[s].x=Fc.fixNumber(i),e[s].y=Fc.fixNumber(r),e[s].z=Fc.fixNumber(n)}static getVector(t,e,s){t[e](s);const i=this._temp[e],r=s.x(),n=s.y(),o=s.z();i.x=Fc.fixNumber(r),i.y=Fc.fixNumber(n),i.z=Fc.fixNumber(o)}static computeZVector(){this._temp.zDirection.crossVectors(this._temp.xDirection,this._temp.yDirection)}}ot(kc,"_temp",{position:new Xt,xDirection:new Xt,yDirection:new Xt,zDirection:new Xt}),ot(kc,"_doubleVector",new ac),ot(kc,"_floatVector",new Ql);const Vc=class{static get(t,e,s){this.fetchSampleTransform(t,e),this.fetchItemTransform(t,e),s.multiplyMatrices(this._item,this._sample)}static getBox(t,e){t.bbox(this._box),kc.parseBox(this._box,e)}static getBoxData(t){this._min.copy(t.min),this._max.copy(t.max),this._center.addVectors(this._min,this._max),this._center.divideScalar(2),t.getSize(this._distance)}static boxSize(t){return this.getBoxData(t),this.applyTransformer(),this._edge.start=this._min.clone(),this._edge.end=this._max.clone(),this._edge}static applyTransformer(){const{x:t,y:e,z:s}=this._distance,i=Math.max(t,e,s);t===i?this._transformers.x():e===i?this._transformers.y():this._transformers.z()}static fetchItemTransform(t,e){const s=t.item();e.globalTransforms(s,this._transform),kc.parseTransform(this._transform,this._item)}static fetchSampleTransform(t,e){const s=t.localTransform();e.localTransforms(s,this._transform),kc.parseTransform(this._transform,this._sample)}static setBoxZ(){this._min.set(this._center.x,this._center.y,this._min.z),this._max.set(this._center.x,this._center.y,this._max.z)}static setBoxY(){this._min.set(this._center.x,this._min.y,this._center.z),this._max.set(this._center.x,this._max.y,this._center.z)}static setBoxX(){this._min.set(this._min.x,this._center.y,this._center.z),this._max.set(this._max.x,this._center.y,this._center.z)}};ot(Vc,"_transform",new dc),ot(Vc,"_min",new Xt),ot(Vc,"_max",new Xt),ot(Vc,"_center",new Xt),ot(Vc,"_distance",new Xt),ot(Vc,"_edge",new fi),ot(Vc,"_item",new Me),ot(Vc,"_sample",new Me),ot(Vc,"_box",new nc),ot(Vc,"_transformers",{x:()=>Vc.setBoxX(),y:()=>Vc.setBoxY(),z:()=>Vc.setBoxZ()});let Lc=Vc;class Oc{static getWidth(t){return t.getSize(this._temp.vector),this._temp.vector.x>this._temp.vector.y&&this._temp.vector.set(this._temp.vector.y,this._temp.vector.x,this._temp.vector.z),this._temp.vector.y>this._temp.vector.z&&this._temp.vector.set(this._temp.vector.x,this._temp.vector.z,this._temp.vector.y),this._temp.vector.x>this._temp.vector.y&&this._temp.vector.set(this._temp.vector.y,this._temp.vector.x,this._temp.vector.z),this._temp.vector.y}}ot(Oc,"_temp",{vector:new Xt});class Dc{static getEarcutDimensions(t){const e=Math.abs(t.x),s=Math.abs(t.y),i=Math.abs(t.z);if(i>e&&i>s){return t.z>0?[0,1]:[1,0]}if(s>e&&s>i){return t.y>0?[2,0]:[0,2]}return t.x>0?[1,2]:[2,1]}}class Uc{constructor(t,e){ot(this,"meshes"),ot(this,"_templateController",new hd),ot(this,"_meshIds",new Set),ot(this,"_idGenerator",new Pc),ot(this,"_modelCode"),this.meshes=e,this._modelCode=this.getModelCode(t)}dispose(){ed.delete(this._meshIds)}useMesh(t,e,s){const i=this.meshCode(t,s);ed.lockIn(e),this._templateController.add(i,e)}getMesh(t,e){const s=this.meshCode(t,e);return ed.get(s)??this._templateController.get(s)}saveMesh(t,e,s){Fc.forEach(e,ed.updateMeshMemory);const i=this.meshCode(t,s);ed.add(i,e),this._meshIds.add(i)}meshCode(t,e){const s=[this._modelCode,this.getRepresentation(),e,t];return this._idGenerator.generate(s)}getModelCode(t){return this._idGenerator.generate([t])}}const Nc=32767;var Wc=(t=>(t[t.NONE=0]="NONE",t[t.AABB=1]="AABB",t[t.CUSTOM=2]="CUSTOM",t))(Wc||{});const Hc=class t{static getProfile(t,e,s){return t.type()===yc.BIG?t.bigProfiles(e,s):t.profiles(e,s)}static getPoints(t){const e=new Float32Array(3*t.pointsLength());for(let s=0;s<t.pointsLength();s++)t.points(s,this._tempPoint),e[3*s]=this._tempPoint.x(),e[3*s+1]=this._tempPoint.y(),e[3*s+2]=this._tempPoint.z();return e}static getProfileIndices(e,s){const i=e.type()===yc.BIG,r={outer:[],inners:[]},n=i?e.bigHolesLength():e.holesLength(),o=i?"bigHoles":"holes",a=t.getProfile(e,s);r.outer=Array.from(a.indicesArray());for(let t=0;t<n;t++){const i=e[o](t);if(i.profileId()===s){const t=Array.from(i.indicesArray());r.inners.push(t)}}return r}static getHole(t,e,s){return t.type()===yc.BIG?t.bigHoles(e,s):t.holes(e,s)}static getProfilesLength(t){return t.type()===yc.BIG?t.bigProfilesLength():t.profilesLength()}static getHolesLength(t){return t.type()===yc.BIG?t.bigHolesLength():t.holesLength()}static getShell(t,e){return t.shells(e,this._shell)}static point(t,e,s){t instanceof xc&&t.points(e,this._tempPoint);const i=this._tempPoint.x(),r=this._tempPoint.y(),n=this._tempPoint.z();s.set(i,r,n)}static getNormalsOfShellProfile(e,s){const i=t.getProfilesLength(e);for(let r=0;r<i;r++){const i=t.getProfile(e,r),n=this.fetchNormalsOfProfile(e,i);s.push(n)}return s}static computeNormalsAvg(t,e,s,i){this.setupNormalBuffer(t);const r=s[e];for(let e=0;e<t.length;e++){const n=t[e],o=i.get(n);this.aggregateNormals(o,s,r),this.computeAvgNormal(e)}return this._normalBuffer}static getBuffer(t){const e=t.bb,s=e.__offset(t.bb_pos,8),i=3*t.pointsLength(),r=e.__vector(t.bb_pos+s),n=e.bytes().buffer;return new Float32Array(n,r,i)}static getPointsShell(e){return this._pointsByProfile.clear(),this.fetchAllPointsByProfile(e),t.fetchAllPointsByHole(e),this._pointsByProfile}static addNormals(t,e,s){for(const i of t){const t=e[i];s.dot(t)>this._faceThreshold&&this._tempNormal.add(t)}}static setupNormalBuffer(t){const e=3*t.length;this._normalBuffer.length<e&&(this._normalBuffer=new Int16Array(e))}static fetchNormalsOfProfile(t,e){const s=e.indicesLength();return this.isTooSmall(t,s)?new Xt(1,0,0):this.computeProfileNormal(s,e,t)}static fetchAllPointsByHole(e){const s=t.getHolesLength(e),i=this.getTempHole(e);for(let r=0;r<s;r++){t.getHole(e,r,i);const s=i.profileId(),n=i.indicesLength();for(let e=0;e<n;e++){const r=i.indices(e);t.savePointByProfile(r,s)}}}static computeProfileNormal(t,e,s){this._v3.set(0,0,0);for(let i=0;i<t;i++)this.fetchPointsForNormal(i,t,e,s),this.computeProfilePointNormal();const i=this._v3.clone();return i.normalize(),i}static computeProfilePointNormal(){const t=this._v1.x-this._v2.x,e=this._v1.y-this._v2.y,s=this._v1.z-this._v2.z,i=this._v1.x+this._v2.x,r=this._v1.y+this._v2.y,n=this._v1.z+this._v2.z;this._v3.x+=e*n,this._v3.y+=s*i,this._v3.z+=t*r}static aggregateNormals(e,s,i){this._tempNormal.set(0,0,0);if(!e||!e.length)return void this._tempNormal.set(1,0,0);if(1===e.length){const t=e[0];this._tempNormal=s[t].clone()}else t.addNormals(e,s,i)}static fetchPointsForNormal(t,e,s,i){const r=(t+1)%e,n=s.indices(t),o=s.indices(r);this.point(i,n,this._v1),this.point(i,o,this._v2)}static savePointByProfile(t,e){this._pointsByProfile.has(t)||this._pointsByProfile.set(t,[]),this._pointsByProfile.get(t).push(e)}static isTooSmall(t,e){return t.pointsLength()<=2||e<=2}static fetchAllPointsByProfile(e){const s=this.getProfilesLength(e),i=this.getTempProfile(e);for(let r=0;r<s;r++){t.getProfile(e,r,i);const s=i.indicesLength();for(let e=0;e<s;e++){const s=i.indices(e);t.savePointByProfile(s,r)}}}static computeAvgNormal(t){this._tempNormal.normalize(),this._tempNormal.multiplyScalar(Nc),this._tempNormal.toArray(this._normalBuffer,3*t)}static getTempProfile(t){return t.type()===yc.BIG?this._bigShellProfile:this._shellProfile}static getTempHole(t){return t.type()===yc.BIG?this._bigShellHole:this._shellHole}};ot(Hc,"_faceThreshold",Math.cos(Math.PI/8)),ot(Hc,"_shell",new xc),ot(Hc,"_normalBuffer",new Int16Array),ot(Hc,"_tempNormal",new Xt),ot(Hc,"_tempPoint",new Ql),ot(Hc,"_shellProfile",new gc),ot(Hc,"_bigShellProfile",new rc),ot(Hc,"_shellHole",new bc),ot(Hc,"_bigShellHole",new ic),ot(Hc,"_pointsByProfile",new Map),ot(Hc,"_v1",new Xt),ot(Hc,"_v2",new Xt),ot(Hc,"_v3",new Xt);let qc=Hc;class Zc{constructor(){ot(this,"_shellHole",new bc),ot(this,"_bigShellHole",new ic),ot(this,"holePoints",0),ot(this,"profilePoints",0),ot(this,"triangleAmount",0),ot(this,"indexCount",0),ot(this,"meshes",[]),ot(this,"_shellProfile",new gc),ot(this,"_bigShellProfile",new rc)}newMeshTemplate(t){return this.getIsEmpty(t)?{objectClass:_i.SHELL}:(this.reset(!0),this.processShell(t),this.getResult())}manageDataLeft(){this.getIsDataLeft()&&this.setMesh()}getIsEmpty(t){return 0===qc.getProfilesLength(t)}processShellHoles(t,e){let s=!1;const i=qc.getHolesLength(t),r=this.getTempHole(t);for(let n=0;n<i;n++){qc.getHole(t,n,r);r.profileId()===e&&(this.updateBuffers(t,s),s=!0)}this.manageFoundHoles(t,s)}newMesh(){return{objectClass:_i.SHELL,indexCount:3*this.triangleAmount,positionCount:3*(this.holePoints+this.profilePoints),normalCount:3*(this.holePoints+this.profilePoints)}}reset(t){this.holePoints=0,this.profilePoints=0,this.triangleAmount=0,t&&(this.meshes=void 0)}getIsDataLeft(){const t=this.triangleAmount>0,e=this.holePoints>0,s=this.profilePoints>0;return t||e||s}processShell(t){const e=qc.getProfilesLength(t),s=this.getTempProfile(t);for(let i=0;i<e;i++)qc.getProfile(t,i,s),this.indexCount=s.indicesLength(),this.profilePoints+=this.indexCount,this.processShellHoles(t,i),this.manageMemory();this.manageDataLeft()}manageFoundHoles(t,e){const s=this.getTempProfile(t).indicesLength();e?this.triangleAmount+=s:s>2&&(this.triangleAmount+=s-2)}getResult(){const t=this.meshes;return this.meshes=void 0,t}manageMemory(){this.holePoints+this.profilePoints+this.indexCount>mi&&this.setMesh()}updateBuffers(t,e){const s=this.getTempHole(t);this.holePoints+=s.indicesLength(),this.triangleAmount+=s.indicesLength(),e&&(this.triangleAmount+=2)}setMesh(){const t=this.newMesh();this.meshes?Array.isArray(this.meshes)?this.meshes.push(t):this.meshes=[this.meshes,t]:this.meshes=t,this.reset(!1)}getTempProfile(t){return t.type()===yc.BIG?this._bigShellProfile:this._shellProfile}getTempHole(t){return t.type()===yc.BIG?this._bigShellHole:this._shellHole}}var Gc=(t=>(t[t.four=4]="four",t[t.three=3]="three",t))(Gc||{});function jc(t,e,s,i,r,n){const o=e&&e.length,a=o?e[0]*s:t.length;let h,l,c,u=Xc(t,0,a,s,!0,i,r);if(u&&u.next!==u.prev){if(o&&(u=function(t,e,s,i,r,n){const o=[];for(let s=0,a=e.length;s<a;s++){const h=Xc(t,e[s]*i,s<a-1?e[s+1]*i:t.length,i,!1,r,n);h===h.next&&(h.steiner=!0),o.push(nu(h))}o.sort(eu);for(let t=0;t<o.length;t++)s=Yc(s=su(o[t],s),s.next);return s}(t,e,u,s,i,r)),t.length>80*s){let e=t[i],n=t[r];h=e,l=n;for(let o=s;o<a;o+=s){const s=t[o+i],a=t[o+r];s<h&&(h=s),a<l&&(l=a),s>e&&(e=s),a>n&&(n=a)}c=Math.max(e-h,n-l),c=0!==c?1/c:0}Jc(u,n,s,h,l,c)}}function Xc(t,e,s,i,r,n,o){let a,h,l;if(r===function(t,e,s,i,r,n){let o=0;for(let a=e,h=s-i;a<s;a+=i)o+=(t[h+r]-t[a+r])*(t[a+n]+t[h+n]),h=a;return o}(t,e,s,i,n,o)>0)for(l=e;l<s;l+=i)a=mu(l,t[l+n],t[l+o],a);else for(l=s-i;l>=e;l-=i)a=mu(l,t[l+n],t[l+o],a);return a&&lu(a,a.next)&&(h=a.next,_u(a),a=h),a}function Yc(t,e){if(!t)return t;e||(e=t);let s,i,r=t;do{if(s=!1,r.steiner||!lu(r,r.next)&&0!==hu(r.prev,r,r.next))r=r.next;else{if(i=r.prev,_u(r),r=e=i,r===r.next)break;s=!0}}while(s||r!==e);return e}function Jc(t,e,s,i,r,n,o){!o&&n&&function(t,e,s,i){let r=t;do{null===r.z&&(r.z=ru(r.x,r.y,e,s,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,s=1;do{let i,r=t;t=null;let n=null;for(e=0;r;){e++;let o=r,a=0;for(let t=0;t<s&&(a++,o=o.nextZ,o);t++);let h=s;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--),n?n.nextZ=i:t=i,i.prevZ=n,n=i;r=o}n.nextZ=null,s*=2}while(e>1)}(r)}(t,i,r,n);let a=t;for(;t.prev!==t.next;){const h=t.prev,l=t.next;if(n?$c(t,i,r,n):Qc(t))e(h.i/s,t.i/s,l.i/s),_u(t),t=l.next,a=l.next;else if((t=l)===a){o?1===o?Jc(t=Kc(Yc(t),e,s),e,s,i,r,n,2):2===o&&tu(t,e,s,i,r,n):Jc(Yc(t),e,s,i,r,n,1);break}}}function Qc(t){const e=t.prev,s=t,i=t.next;if(hu(e,s,i)>=0)return!1;let r=t.next.next;for(;r!==t.prev;){if(ou(e.x,e.y,s.x,s.y,i.x,i.y,r.x,r.y)&&hu(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function $c(t,e,s,i){const r=t.prev,n=t,o=t.next;if(hu(r,n,o)>=0)return!1;const a=Math.min(r.x,n.x,o.x),h=Math.min(r.y,n.y,o.y),l=Math.max(r.x,n.x,o.x),c=Math.max(r.y,n.y,o.y),u=ru(a,h,e,s,i),d=ru(l,c,e,s,i);let p=t.prevZ,f=t.nextZ;for(;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&ou(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&hu(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&ou(r.x,r.y,n.x,n.y,o.x,o.y,f.x,f.y)&&hu(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&ou(r.x,r.y,n.x,n.y,o.x,o.y,p.x,p.y)&&hu(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&ou(r.x,r.y,n.x,n.y,o.x,o.y,f.x,f.y)&&hu(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function Kc(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!lu(r,n)&&cu(r,i,i.next,n)&&pu(r,n)&&pu(n,r)&&(e(r.i/s,i.i/s,n.i/s),_u(i.next),_u(i),i=t=n),i=i.next}while(i!==t);return Yc(i)}function tu(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&au(o,t)){let a=fu(o,t);return o=Yc(o,o.next),a=Yc(a,a.next),Jc(o,e,s,i,r,n),void Jc(a,e,s,i,r,n)}t=t.next}o=o.next}while(o!==t)}function eu(t,e){return t.x-e.x}function su(t,e){const s=function(t,e){let s=e;const i=t.x,r=t.y;let n,o=-1/0;do{if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){const t=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(t<=i&&t>o){if(o=t,t===i){if(r===s.y)return s;if(r===s.next.y)return s.next}n=s.x<s.next.x?s:s.next}}s=s.next}while(s!==e);if(!n)return null;if(i===o)return n;const a=n,h=n.x,l=n.y;let c=1/0;s=n;do{if(i>=s.x&&s.x>=h&&i!==s.x&&ou(r<l?i:o,r,h,l,r<l?o:i,r,s.x,s.y)){const e=Math.abs(r-s.y)/(i-s.x);pu(s,t)&&(e<c||e===c&&(s.x>n.x||s.x===n.x&&iu(n,s)))&&(n=s,c=e)}s=s.next}while(s!==a);return n}(t,e);if(!s)return e;const i=fu(s,t),r=Yc(s,s.next);return Yc(i,i.next),e===e.next||s===e?r:e}function iu(t,e){return hu(t.prev,t,e.prev)<0&&hu(e.next,t,t.next)<0}function ru(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-s)*r)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)*r)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function nu(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function ou(t,e,s,i,r,n,o,a){return(r-o)*(e-a)-(t-o)*(n-a)>=0&&(t-o)*(i-a)-(s-o)*(e-a)>=0&&(s-o)*(n-a)-(r-o)*(i-a)>=0}function au(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&cu(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(pu(t,e)&&pu(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(hu(t.prev,t,e.prev)||hu(t,e.prev,e))||lu(t,e)&&hu(t.prev,t,t.next)>0&&hu(e.prev,e,e.next)>0)}function hu(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function lu(t,e){return t.x===e.x&&t.y===e.y}function cu(t,e,s,i){const r=du(hu(t,e,s)),n=du(hu(t,e,i)),o=du(hu(s,i,t)),a=du(hu(s,i,e));return r!==n&&o!==a||(!(0!==r||!uu(t,s,e))||(!(0!==n||!uu(t,i,e))||(!(0!==o||!uu(s,t,i))||!(0!==a||!uu(s,e,i)))))}function uu(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function du(t){return t>0?1:t<0?-1:0}function pu(t,e){return hu(t.prev,t,t.next)<0?hu(t,e,t.next)>=0&&hu(t,t.prev,e)>=0:hu(t,e,t.prev)<0||hu(t,t.next,e)<0}function fu(t,e){const s=bu(t.i,t.x,t.y),i=bu(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function mu(t,e,s,i){const r=bu(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function _u(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),t.next=t,t.prev=t}function bu(t,e,s){return{i:t,x:e,y:s,prev:null,next:null,z:null,prevZ:null,nextZ:null,steiner:!1}}const gu=class t{static create(e,s,i,r,n,o,a,h){const l=e.length,c=a.verticesAmount;t.processBuffers(l,e,n,a,s,i);const u=n.positionBuffer,d=(a.verticesAmount-c)/3;this.processNormals(u,this._tempVec,d,c),this.triangulate(o,r,l,n,a,c),this.setFaceId(c,a,n,h)}static setFaceId(t,e,s,i){const r=t/3,n=e.verticesAmount/3;for(let t=r;t<n;t++)s.faceIdBuffer[t]=i}static getVertices(t,e,s){const i=t.positionBuffer.buffer,r=4*e,n=s.verticesAmount-e;return new Float32Array(i,r,n)}static getEvent(t,e,s){return(i,r,n)=>{const o=t.indexBuffer;o[e.indices++]=i+s/3,o[e.indices++]=r+s/3,o[e.indices++]=n+s/3}}static processBuffers(t,e,s,i,r,n){for(let o=0;o<t;o++)this.processPositionBuffer(s,e,o,i,r),this.processNormalbuffer(s,n,o,i),this.updateBufferData(i)}static getHoles(t,e,s,i,r){if(!t)return;if(t.has(e)){const n=t.get(e),o=[];for(const t of n.indices)o.push(t+s);return this.setHolesBuffers(i,n,r),o}}static setHolesBuffers(t,e,s){const i=t.positionBuffer,r=t.normalBuffer;i.set(e.points,s.verticesAmount);const n=e.points.length;s.verticesAmount+=n,s.vertices+=n/3,r.set(e.normals,s.normalsAmount),s.normalsAmount+=n}static updateBufferData(t){t.vertices+=1,t.verticesAmount+=3,t.normalsAmount+=3}static processPositionBuffer(t,e,s,i,r){const n=t.positionBuffer;for(let t=0;t<3;t++){const o=3*e[s];n[i.verticesAmount+t]=r[o+t]}}static triangulate(e,s,i,r,n,o){const a=this.getHoles(e,s,i,r,n),h=t.getVertices(r,o,n),l=Dc.getEarcutDimensions(this._tempVec),c=this.getEvent(r,n,o);jc(h,a,3,l[0],l[1],c)}static processNormals(t,e,s,i=0){e.set(0,0,0);for(let r=0;r<s;r++){const n=i+3*r,o=i+3*((r+1)%s),a=t[n+0],h=t[o+0],l=t[n+1],c=t[o+1],u=t[n+2],d=t[o+2];e.x+=(l-c)*(u+d),e.y+=(u-d)*(a+h),e.z+=(a-h)*(l+c)}e.normalize()}static processNormalbuffer(t,e,s,i){const r=t.normalBuffer,n=3*s,o=e[n],a=e[n+1],h=e[n+2];r.set([o,a,h],i.normalsAmount)}};ot(gu,"_tempVec",new Xt);let yu=gu;const xu=class{static create(t,e,s,i,r,n,o){this.setAllVectors(t,e);this.getIsConvex()?this.processConvexFace4(r,n,s,o):yu.create(t,e,s,i,r,void 0,n,o)}static setAllVectors(t,e){this.setVector(t,e,this.a,0),this.setVector(t,e,this.b,1),this.setVector(t,e,this.c,2),this.setVector(t,e,this.d,3),this.getCrossVectors()}static processConvexFace4(t,e,s,i){this.processIndices(t,e),this.processPoints(t,e),this.processNormal(t,e,s),this.setFaceId(t,e,i),this.updateData(e)}static setFaceId(t,e,s){const i=t.faceIdBuffer;for(let t=e.vertices;t<e.vertices+4;t++)i[t]=s}static getIsConvex(){return this.h.dot(this.i)>0}static getCrossVectors(){this.e.copy(this.b),this.f.copy(this.c),this.g.copy(this.d),this.e.sub(this.a),this.f.sub(this.a),this.g.sub(this.a),this.h.crossVectors(this.e,this.f),this.i.crossVectors(this.f,this.g)}static updateData(t){t.normalsAmount+=this.totalIncrease,t.vertices+=this.vertexIncrease,t.verticesAmount+=this.totalIncrease}static processPoints(t,e){let s=0;const i=t.positionBuffer,r=e.verticesAmount;for(let t=0;t<this.vertexIncrease;t++){const e=this._vecs[t];i[r+s++]=e.x,i[r+s++]=e.y,i[r+s++]=e.z}}static setVector(t,e,s,i){const r=3*t[i],n=e[r],o=e[r+1],a=e[r+2];s.set(n,o,a)}static processNormal(t,e,s){const i=t.normalBuffer,r=e.normalsAmount;for(let t=0;t<this.totalIncrease;t++)i[r+t]=s[t]}static processIndices(t,e){const s=t.indexBuffer;for(let t=0;t<this.indexIncrease;t++){const i=this._convexIndices[t];s[e.indices+t]=e.vertices+i}e.indices+=this.indexIncrease}};ot(xu,"a",new Xt),ot(xu,"b",new Xt),ot(xu,"c",new Xt),ot(xu,"d",new Xt),ot(xu,"e",new Xt),ot(xu,"f",new Xt),ot(xu,"g",new Xt),ot(xu,"h",new Xt),ot(xu,"i",new Xt),ot(xu,"_vecs",[xu.a,xu.b,xu.c,xu.d]),ot(xu,"_convexIndices",[0,1,3,3,1,2]),ot(xu,"totalIncrease",12),ot(xu,"indexIncrease",6),ot(xu,"vertexIncrease",4);let wu=xu;const vu=class t{static create(t,e,s,i,r,n){this.setFaceIds(r,i,n),this.setIndices(i,r),this.setPoints(t,i,r,e),this.setNormals(i,r,s),this.updateData(r)}static setFaceIds(t,e,s){const i=t.verticesAmount/3,r=i+3;for(let t=i;t<r;t++)e.faceIdBuffer[t]=s}static setNormals(t,e,s){const i=t.normalBuffer;for(let t=0;t<this.totalIncrease;t++)i[e.normalsAmount+t]=s[t]}static setPoints(t,e,s,i){let r=0;const n=e.positionBuffer;for(let e=0;e<this.vertexIncrease;e++){const o=t[e]*this.vertexIncrease;for(let t=0;t<this.vertexIncrease;t++)n[s.verticesAmount+r]=i[o+t],r++}}static setIndices(t,e){const s=t.indexBuffer;for(let t=0;t<this.vertexIncrease;t++)s[e.indices+t]=e.vertices+t;e.indices+=this.vertexIncrease}static updateData(e){e.normalsAmount+=t.totalIncrease,e.vertices+=t.vertexIncrease,e.verticesAmount+=t.totalIncrease}};ot(vu,"vertexIncrease",3),ot(vu,"totalIncrease",9);let Su=vu;class Mu{constructor(){ot(this,"point",new Ql),ot(this,"_shellHole",new bc),ot(this,"_bigShellHole",new ic),ot(this,"interiorProfiles",new Map),ot(this,"normalsAvgInterior",new Int16Array),ot(this,"_pointsPerProfile",new Map),ot(this,"_shellProfile",new gc),ot(this,"_bigShellProfile",new rc),ot(this,"_normalsAvg",new Int16Array),ot(this,"_normals",[]),ot(this,"_indices",0),ot(this,"_sizes",{vertices:0,indices:0,verticesAmount:0,normalsAmount:0,normals:0}),ot(this,"_tileData"),ot(this,"_nextFaceId",1),ot(this,"nextBuffer",(t=>{this.setTileData(t),this.initializeIndices(),this.initializePositions(),this.initializeNormals(),this.initializeFaceIds(),this.initializeSizes(),this._indices++}))}construct(t,e){this.resetConstructData(e),this.getPointsPerWire(t);const s=qc.getBuffer(t);this.newShellInteriorProfiles(t),this.constructShell(t,s,e),this._tileData=void 0}getIntProfileNormalsAvg(t,e){const s=this.getTempHole(t).indicesArray();this.normalsAvgInterior=qc.computeNormalsAvg(s,e,this._normals,this._pointsPerProfile)}saveInteriorProfile(t){const e=this.getTempHole(t).profileId();if(this.interiorProfiles.has(e))return this.saveExistingInteriorProfile(e),e;const s=this.getNewIntProfileData();return this.interiorProfiles.set(e,s),e}computeNormalsAvg(t,e,s){if(!this.isShell(t))return;const i=this._normals,r=this._pointsPerProfile;this._normalsAvg=qc.computeNormalsAvg(e,s,i,r)}isShell(t){return t instanceof xc}getPointsPerWire(t){this.isShell(t)&&(qc.getNormalsOfShellProfile(t,this._normals),this._pointsPerProfile=qc.getPointsShell(t))}getIndices(t,e){const s=this.getTempProfile(t);return qc.getProfile(t,e,s),s.indicesArray()}resetConstructData(t){this._indices=0,this._tileData=void 0,this.nextBuffer(t),this._normals.length=0}initializeIndices(){const t=this._tileData.indexCount;this._tileData.indexBuffer=new Uint16Array(t)}constructFace4(t,e,s){const i=this.getNextFaceId();wu.create(t,e,this._normalsAvg,s,this._tileData,this._sizes,i)}initializeSizes(){this._sizes.vertices=0,this._sizes.indices=0,this._sizes.verticesAmount=0,this._sizes.normalsAmount=0,this._sizes.normals=0}getInteriorProfileBuffer(t,e){const s=this.getTempHole(t).indicesLength();if(this.isShell(t))for(let i=0;i<s;i++)this.getIntProfilePoints(i,t,e),this.getIntProfileNormals(e,i)}constructProfile(t,e,s,i){const r=this.getTempProfile(e).indicesLength(),n=!this.interiorProfiles.has(t);if(r===Gc.three&&n)return void this.constructFace3(s,i);r===Gc.four&&n?this.constructFace4(s,i,t):this.constructFaceX(s,i,t)}getIntProfileNormals(t,e){const s=3*e,i=this.normalsAvgInterior[s],r=this.normalsAvgInterior[s+1],n=this.normalsAvgInterior[s+2];t.normals.push(i,r,n)}saveExistingInteriorProfile(t){const e=this.interiorProfiles.get(t),s=e.points.length/3;e.indices.push(s),this.interiorProfiles.set(t,e)}getNewIntProfileData(){return{indices:[0],points:[],normals:[]}}constructFace3(t,e){const s=this.getNextFaceId();Su.create(t,e,this._normalsAvg,this._tileData,this._sizes,s)}getIntProfilePoints(t,e,s){const i=this.getTempHole(e).indices(t);e.points(i,this.point);const r=this.point.x(),n=this.point.y(),o=this.point.z();s.points.push(r,n,o)}manageMemory(t,e){const s=this.getTempProfile(t).indicesLength();this._sizes.verticesAmount/3+s>mi&&this.nextBuffer(e)}initializeFaceIds(){const t=this._tileData.positionCount;this._tileData.faceIdBuffer=new Uint32Array(t/3)}getNextFaceId(){return this._nextFaceId++}newShellInteriorProfiles(t){this.interiorProfiles.clear();const e=qc.getHolesLength(t),s=this.getTempHole(t);for(let i=0;i<e;i++){qc.getHole(t,i,s);const e=this.saveInteriorProfile(t),r=this.interiorProfiles.get(e);this.getIntProfileNormalsAvg(t,e),this.getInteriorProfileBuffer(t,r)}return this.interiorProfiles}initializePositions(){const t=this._tileData.positionCount;this._tileData.positionBuffer=new Float32Array(t)}initializeNormals(){const t=this._tileData.normalCount;this._tileData.normalBuffer=new Int16Array(t)}setTileData(t){Array.isArray(t)?this._tileData=t[this._indices]:this._tileData=t}constructShell(t,e,s){const i=qc.getProfilesLength(t);for(let r=0;r<i;r++){const i=this.getIndices(t,r);this.computeNormalsAvg(t,i,r),this.constructProfile(r,t,i,e),this.manageMemory(t,s)}}constructFaceX(t,e,s){const i=this.getNextFaceId();yu.create(t,e,this._normalsAvg,s,this._tileData,this.interiorProfiles,this._sizes,i)}getTempProfile(t){return t.type()===yc.BIG?this._bigShellProfile:this._shellProfile}getTempHole(t){return t.type()===yc.BIG?this._bigShellHole:this._shellHole}}class Au{constructor(t){ot(this,"a",new Xt),ot(this,"b",new Xt),ot(this,"c",new Xt),ot(this,"d",new Xt),ot(this,"e",new Xt),ot(this,"f",new Xt),ot(this,"g",new Xt),ot(this,"h",new Xt),ot(this,"i",new Xt),ot(this,"j",new Xt),ot(this,"k",new Xt),ot(this,"tempTriangle",new us),ot(this,"tempPlane",new hi),ot(this,"includedVertices",[]),ot(this,"interiorProfiles",new Map),ot(this,"_meshes"),this._meshes=t}faceRaycast(t,e){const s=qc.getShell(this._meshes,t);this.resetData(),this.getInteriorProfiles(s);const i=qc.getBuffer(s);return this.processAllCollisions(s,i,e),this.includedVertices}resetVectors(){this.a.set(0,0,0),this.b.set(0,0,0),this.c.set(0,0,0),this.d.set(0,0,0)}resetData(){this.includedVertices.length=0,this.interiorProfiles.clear()}getInteriorProfiles(t){const e=qc.getHolesLength(t);for(let s=0;s<e;s++){const e=qc.getHole(t,s).profileId();this.interiorProfiles.has(e)||this.interiorProfiles.set(e,[]);this.interiorProfiles.get(e).push(s)}}processTriangle(t,e,s){const i=3*t[0],r=3*t[1],n=3*t[2];this.saveTriPoint(this.e,e,i),this.saveTriPoint(this.f,e,r),this.saveTriPoint(this.g,e,n);const o=this.triangleHit(s);if(o){const s=this.getTriangleBuffer(e,t);o.facePoints=s.points,o.faceIndices=s.indices,this.includedVertices.push(o)}}processAllCollisions(t,e,s){const i=qc.getProfilesLength(t);for(let r=0;r<i;r++){this.resetVectors();const i=this.getIndices(t,r);this.getValidCollision(i,e,s,r,t)&&this.processCollision(t,r,e,i)}}saveTriPoint(t,e,s){const i=e[s],r=e[s+1],n=e[s+2];t.set(i,r,n)}getIndices(t,e){return qc.getProfile(t,e).indicesArray()}getIsTriangle(t){return 3===t.length}getNormal(){this.tempTriangle.a=this.e,this.tempTriangle.b=this.f,this.tempTriangle.c=this.g;const t=new Xt;return this.tempTriangle.getNormal(t),t}isHole(t,e,s){if(this.interiorProfiles.has(t)){const i=this.interiorProfiles.get(t);return this.holeContains(i,e,s)}return!1}computeNormal(t,e){this.d.set(0,0,0);const s=e.length;for(let i=0;i<s;i++){const r=(i+1)%s,n=3*e[i],o=3*e[r];this.processNormal(t,n,o)}this.d.normalize()}holeContains(t,e,s){const i=t.length;for(let r=0;r<i;r++){const i=qc.getHole(e,t[r]).indicesArray();if(this.polygonContains(s,i))return!0}return!1}triangleHit(t){const e=this.e,s=this.f,i=this.g;if(!t.intersectTriangle(e,s,i,!1,this.h))return;const r=this.getNormal();return{point:this.h.clone(),normal:r}}getValidCollision(t,e,s,i,r){if(this.getIsTriangle(t))return this.processTriangle(t,e,s),!1;if(!this.getCollidesPlane(t,e,s))return!1;return!this.isHole(i,r,e)}processCollision(t,e,s,i){if(!this.polygonContains(s,i))return;const r=this.b.clone(),n=this.tempPlane.normal.clone(),o=this.getFaceBuffer(t,e,s);this.includedVertices.push({point:r,normal:n,facePoints:o.points,faceIndices:o.indices})}newOrthoNormalBasis(){const t=this.tempPlane.normal,e=this.j,s=this.i;if(Math.abs(t.x)>=Math.abs(t.y)){const i=1/Math.sqrt(t.x*t.x+t.z*t.z),r=-t.z*i,n=0,o=t.x*i;e.set(r,n,o);const a=t.y*e.z,h=t.z*e.x-t.x*e.z,l=-t.y*e.x;s.set(a,h,l)}else{const i=1/Math.sqrt(t.y*t.y+t.z*t.z),r=0,n=t.z*i,o=-t.y*i;e.set(r,n,o);const a=t.y*e.z-t.z*e.y,h=-t.x*e.z,l=t.x*e.y;s.set(a,h,l)}e.normalize(),s.normalize()}polygonContains(t,e){let s=!1;this.newOrthoNormalBasis(),this.setPolyContainVec(e,t);let i=this.k.dot(this.i),r=this.k.dot(this.j);for(let n=0;n<e.length;n++){const o=3*e[n],a=t[o],h=t[o+1],l=t[o+2];this.k.set(a,h,l),this.k.sub(this.b);const c=this.k.dot(this.i),u=this.k.dot(this.j);if(u>0!==r>0){(i-c)*-u/(r-u)+c>0&&(s=!s)}i=c,r=u}return s}processNormal(t,e,s){const i=t[e+0],r=t[s+0],n=t[e+1],o=t[s+1],a=t[e+2],h=t[s+2];this.d.x+=(n-o)*(a+h),this.d.y+=(a-h)*(i+r),this.d.z+=(i-r)*(n+o)}getCollidesPlane(t,e,s){const i=3*t[0],r=e[i],n=e[i+1],o=e[i+2];this.a.set(r,n,o),this.computeNormal(e,t),this.tempPlane.setFromNormalAndCoplanarPoint(this.d,this.a);return s.intersectPlane(this.tempPlane,this.b)}setPolyContainVec(t,e){const s=3*t[t.length-1],i=e[s],r=e[s+1],n=e[s+2];this.k.set(i,r,n),this.k.sub(this.b)}getTriangleBuffer(t,e){const s=[],i=[];for(let r=0;r<e.length;r++){const n=3*e[r];s.push(t[n],t[n+1],t[n+2]),i.push(r)}return{points:new Float32Array(s),indices:i}}getFaceBuffer(t,e,s){const i=qc.getProfileIndices(t,e),{outer:r,inners:n}=i,o=[];for(let t=0;t<r.length;t++){const e=3*r[t];o.push(s[e],s[e+1],s[e+2])}const a=[];for(let t=0;t<n.length;t++){const e=n[t];a.push(o.length/3);for(let t=0;t<e.length;t++){const i=3*e[t];o.push(s[i],s[i+1],s[i+2])}}const h=new Xt,l=new Xt,c=new Xt;h.set(o[0],o[1],o[2]),l.set(o[3],o[4],o[5]),c.set(o[6],o[7],o[8]);const u=new us;u.set(h,l,c);const d=new Xt;u.getNormal(d);const[p,f]=Dc.getEarcutDimensions(d),m=[];for(let t=0;t<o.length;t+=3){const e=[o[t],o[t+1],o[t+2]];m.push(e[p],e[f])}const _=vl(m,a);return{points:new Float32Array(o),indices:_}}}class Iu{constructor(t){ot(this,"_meshes"),ot(this,"_minAngle",Math.PI/32),ot(this,"_shellProfile",new gc),ot(this,"_bigShellProfile",new rc),ot(this,"_tempV1",new Xt),ot(this,"_tempV2",new Xt),ot(this,"_tempPoint",new Xt),ot(this,"_normals",[]),ot(this,"_pointsByProfile",new Map),ot(this,"_shell",new xc),ot(this,"_result",[]),this._meshes=t}lineRaycast(t,e,s){return this.resetData(t),this.lineRaycastItems(e,s),this._result}lineRaycastItems(t,e){const s=qc.getProfilesLength(this._shell);for(let i=0;i<s;i++){const s=this.getTempProfile(this._shell);qc.getProfile(this._shell,i,s),this.lineRaycastProfile(t,e,i)}}resetData(t){this._shell=qc.getShell(this._meshes,t),this._normals.length=0,qc.getNormalsOfShellProfile(this._shell,this._normals),this._pointsByProfile=qc.getPointsShell(this._shell),this._result=[]}lineRaycastProfile(t,e,s){const i=this.getTempProfile(this._shell),r=i.indicesLength();for(let n=0;n<r;n++){const o=i.indices(n),a=this.getSecondIndex(n,r);this.cast(o,a,t,e,s)&&this.saveResult(s)}}isInvalidAngle(t,e,s){const i=this.getProfile(t,e,s);if(!i.length)return!0;const r=this._normals[i[0]],n=this._normals[s];return r.dot(n)>Math.cos(this._minAngle)}getProfile(t,e,s){const i=this._pointsByProfile.get(t),r=this._pointsByProfile.get(e),n=[];for(const t of i)-1!==r.indexOf(t)&&t!==s&&n.push(t);return n}cast(t,e,s,i,r){qc.point(this._shell,t,this._tempV1),qc.point(this._shell,e,this._tempV2),this.raycastSegment(s);if(!i.containsPoint(this._tempPoint))return!1;return!this.isInvalidAngle(t,e,r)}saveResult(t){const e=this._tempV1.clone(),s=this._tempV2.clone(),i=this._normals[t],r=this._tempPoint.clone();this._result.push({point:r,normal:i,snappedEdgeP1:e,snappedEdgeP2:s})}getSecondIndex(t,e){const s=t===e-1,i=this.getTempProfile(this._shell);return s?i.indices(0):i.indices(t+1)}raycastSegment(t){t.distanceSqToSegment(this._tempV1,this._tempV2,void 0,this._tempPoint)}getTempProfile(t){return t.type()===yc.BIG?this._bigShellProfile:this._shellProfile}}class Cu{constructor(t){ot(this,"_meshes"),ot(this,"_tempVec",new Xt),this._meshes=t}pointRaycast(t,e){const s=qc.getShell(this._meshes,t),i=[];return this.cast(s,e,i),i}cast(t,e,s){const i=t.pointsLength();for(let r=0;r<i;r++){qc.point(t,r,this._tempVec);if(!e.containsPoint(this._tempVec))continue;const i=this._tempVec.clone();s.push({point:i})}}}class zu extends Uc{constructor(){super(...arguments),ot(this,"_lodClass",Wc.AABB),ot(this,"_objectClass",_i.SHELL),ot(this,"_representationClass",Ic.SHELL),ot(this,"_templates",new Zc),ot(this,"_constructor",new Mu),ot(this,"_faceRaycaster",new Au(this.meshes)),ot(this,"_lineRaycaster",new Iu(this.meshes)),ot(this,"_pointRaycaster",new Cu(this.meshes))}fetchMeshes(t,e){const s=this.getMesh(t,gi.GEOMETRY);return this.constructMesh(s,e,t),s}newMeshTemplate(t){return this._templates.newMeshTemplate(t)}lineRaycast(t,e,s){return this._lineRaycaster.lineRaycast(t,e,s)}faceRaycast(t,e){return this._faceRaycaster.faceRaycast(t,e)}raycast(t,e){return this._faceRaycaster.faceRaycast(t,e)}pointRaycast(t,e,s){return this._pointRaycaster.pointRaycast(t,s)}setupTemplates(){for(let t=0,e=this.meshes.shellsLength();t<e;t++){const e=qc.getShell(this.meshes,t);this.useMesh(t,this.newMeshTemplate(e),gi.GEOMETRY)}}getRepresentation(){return this._representationClass}getObjectClass(){return this._objectClass}getLodClass(){return this._lodClass}isVoidMesh(t){return Array.isArray(t)?void 0===t[0].positionBuffer:void 0===t.positionBuffer}constructMesh(t,e,s){if(!this.isVoidMesh(t)||!e)return;const i=qc.getShell(this.meshes,s);this._constructor.construct(i,t),this.saveMesh(s,t,gi.GEOMETRY)}}class Tu{static circleCurve3Divisions(t){const e=t.aperture()*t.radius()*4,s=Math.round(e);return Math.min(Math.max(s,4),32)}static traverseCircleCurve(t,e,s){const i=t.circleCurvesLength();for(let r=0;r<i;r++){this.getAllCircleCurveData(t,r);const i=s(this._circleCurve);this._circlePoints.length=i-2,this.getCircleCurveMids(i),this.getNewCircleCurveData(),e(this._circleP1,this._circlePoints,this._circleP2)}}static traverseWireSets(t,e){const s=t.wireSetsLength();for(let i=0;i<s;i++)t.wireSets(i,this._wireSet),this.traverseWireSetWires(e)}static raycastCircleExtr(t,e,s,i){const r=e.distanceTo(t);return this.setupCircleExtrusionAxes(e,t),this.setupCircleExtrusionTransform(t,i),this.setupCircleExtrusionRay(s),this.computeCircleExtrusionRaycast(r,i)}static traverseWires(t,e){const s=t.wiresLength();for(let i=0;i<s;i++)t.wires(i,this._wire),this.setWire(),e(this._wireP1,this._wireP2)}static getNewCircleCurveData(){this._circleP2.copy(this._circleP1);const t=this._circleCurve.aperture(),e=this._circleCurve.radius();this._circleP2.applyAxisAngle(this._circleOrientation,t),this._circleP2.multiplyScalar(e),this._circleP2.add(this._circleOrigin),this._circleP1.multiplyScalar(e),this._circleP1.add(this._circleOrigin)}static setWire(){this.setWirePoint("p1",this._wireP1),this.setWirePoint("p2",this._wireP2)}static getCircleCurveMids(t){const e=this._circlePoints.length;for(let s=0;s<e;s++)this._circlePoints[s]=this.newCirclePoint(s,t)}static newCirclePoint(t,e){const s=e-1,i=t+1,r=new Xt;r.copy(this._circleP1);const n=this._circleCurve.radius(),o=this._circleCurve.aperture()*i/s;return r.applyAxisAngle(this._circleOrientation,o),r.multiplyScalar(n),r.add(this._circleOrigin),r}static getAllCircleCurveData(t,e){t.circleCurves(e,this._circleCurve),this.getCircleCurveData(this._circleOrigin,"position"),this.getCircleCurveData(this._circleOrientation,"xDirection"),this.getCircleCurveData(this._circleP1,"yDirection")}static setWirePoint(t,e){this._wire[t](this._floats);const s=this._floats.x(),i=this._floats.y(),r=this._floats.z();e.set(s,i,r)}static getCircleCurveData(t,e){const s=this._circleCurve[e]();this.getVectorData(s,t)}static getVectorData(t,e){const s=t.x(),i=t.y(),r=t.z();e.set(s,i,r)}static traverseWireSetWires(t){const e=this._wireSet.psLength()-1;for(let s=0;s<e;s++)this.getWiresetPoint(this._currentWireSetPoint,s),this.getWiresetPoint(this._nextWireSetPoint,s+1),t(this._currentWireSetPoint,this._nextWireSetPoint)}static getWiresetPoint(t,e){const s=this._wireSet.ps(e);this.getVectorData(s,t)}static setupCircleExtrusionTransform(t,e){this._ceTransform.identity(),this._ceTransform.makeBasis(this._ceAxisX,this._ceAxisY,this._ceAxisZ),this._ceTransform.setPosition(t),this._ceSize.set(e,e,e),this._ceTransform.scale(this._ceSize)}static computeCircleExtrusionRaycastFactors(){const t=this._ceRay.direction,e=this._ceRay.origin,s=t.x*t.x+t.y*t.y,i=2*e.x*t.x+2*e.y*t.y,r=4*s*(e.x*e.x+e.y*e.y-1),n=i*i;if(r>n)return null;const o=2*s,a=Math.sqrt(n-r);return{factorA:(-i+a)/o,factorB:(-i-a)/o}}static computeCircleExtrusionRaycast(t,e){const s=this.computeCircleExtrusionRaycastFactors();if(null===s)return[];const{factorA:i,factorB:r}=s;return this._ceInverseTransform.transpose(),this._ceRaycastPoints=[],this.computeCircleExtrusionRaycastPoints(i,t,e),this.computeCircleExtrusionRaycastPoints(r,t,e),this._ceRaycastPoints}static setupCircleExtrusionRay(t){this._ceInverseTransform.copy(this._ceTransform),this._ceInverseTransform.invert(),this._ceRay.copy(t),this._ceRay.applyMatrix4(this._ceInverseTransform)}static computeCircleExtrusionRaycastPoints(t,e,s){if(!this.checkIfCircleExtrusionClashes(t,e,s))return;this._ceRaycastPoint.applyMatrix4(this._ceTransform);const i=this._ceRaycastPoint.clone();this._ceRaycastPoints.push({point:i})}static setupCircleExtrusionAxes(t,e){this._ceAxisZ.copy(t),this._ceAxisZ.sub(e),this._ceAxisZ.normalize(),this.computeNormal(this._ceAxisZ,this._ceAxisX),this._ceAxisY.crossVectors(this._ceAxisZ,this._ceAxisX)}static computeNormal(t,e){const s=t.dot(this._ceAbsoluteX),i=Math.abs(s)>.9?this._ceAbsoluteZ:this._ceAbsoluteX;e.crossVectors(t,i),e.normalize()}static setupCircleExtrusionRaycastPoint(t){this._ceRaycastPoint.copy(this._ceRay.direction),this._ceRaycastPoint.normalize(),this._ceRaycastPoint.multiplyScalar(t),this._ceRaycastPoint.add(this._ceRay.origin)}static checkIfCircleExtrusionClashes(t,e,s){this.setupCircleExtrusionRaycastPoint(t);const i=e/s,r=this._ceRaycastPoint.z;return r>=0&&r<=i}}ot(Tu,"_floats",new Ql),ot(Tu,"_wire",new Kl),ot(Tu,"_wireSet",new tc),ot(Tu,"_circleCurve",new $l),ot(Tu,"_wireP1",new Xt),ot(Tu,"_wireP2",new Xt),ot(Tu,"_circleP1",new Xt),ot(Tu,"_circleP2",new Xt),ot(Tu,"_circleOrigin",new Xt),ot(Tu,"_circleOrientation",new Xt),ot(Tu,"_currentWireSetPoint",new Xt),ot(Tu,"_nextWireSetPoint",new Xt),ot(Tu,"_ceAxisZ",new Xt),ot(Tu,"_ceAxisY",new Xt),ot(Tu,"_ceAxisX",new Xt),ot(Tu,"_ceRaycastPoint",new Xt),ot(Tu,"_ceSize",new Xt),ot(Tu,"_ceAbsoluteX",new Xt(0,0,1)),ot(Tu,"_ceAbsoluteZ",new Xt(1,0,0)),ot(Tu,"_circlePoints",[]),ot(Tu,"_ceTransform",new Me),ot(Tu,"_ceInverseTransform",new Me),ot(Tu,"_ceRay",new Se),ot(Tu,"_ceRaycastPoints",[]);const Pu=class t{static newPaths(e,s){const i=t.newPathData();return this.fetchCircleCurveData(e,i),this.fetchCircleCurveMids(s,i,e),this.fetchCircleCurveEnds(i,e),this.fetchCircleCurveCuts(i),i.cuts}static getAxisPartSize(e,s,i){const r=e.parts(s),n=e.order(s),o=t.getAxisPartData(r,i,e,n);return t.fetchAxisPartSize(i,o),this._axisPartSize}static vertexLength(e,s=200){const i=Math.round(e*s),r=Math.max(i,t._minSize);return Math.min(r,t._maxSize)}static setPathVertices(t){const e=this.circleCurvePoints,s=!e,i=e&&e.length!==t;if(s||i){this.circleCurvePoints=[];for(let e=0;e<t;e++){const s=2*Math.PI*e/t,i=Math.sin(s),r=Math.cos(s),n=new Xt(i,r,0);this.circleCurvePoints.push(n)}}}static fetchCircleCurveEnds(t,e){t.last.copy(t.first),t.last.applyAxisAngle(t.axis,e.aperture()),t.last.multiplyScalar(e.radius()),t.last.add(t.center),t.first.multiplyScalar(e.radius()),t.first.add(t.center)}static getAxisPartData(t,e,s,i){return{[sc.WIRE]:this.getAxisPartWireData,[sc.WIRE_SET]:this.getAxisPartWireSetData,[sc.CIRCLE_CURVE]:this.getAxisPartCircleCurveData}[t](s,i,e)}static newEmptyAxisPartData(){return{indices:0,points:0,faces:0,links:0}}static fetchCircleCurveMids(t,e,s){const i=t-2;for(let r=0;r<i;r++){const i=new Xt;i.copy(e.first);const n=s.aperture()*(r+1)/(t-1);i.applyAxisAngle(e.axis,n),i.multiplyScalar(s.radius()),i.add(e.center),e.mids[r]=i}}static validSize(t,e,s){return mi>=t+e+s}static fetchCircleCurveCuts(t){t.cuts.push(t.first),t.cuts.push(...t.mids),t.cuts.push(t.last)}static fetchCircleCurveData(t,e){const s=t.position();e.center.set(s.x(),s.y(),s.z());const i=t.xDirection();e.axis.set(i.x(),i.y(),i.z());const r=t.yDirection();e.first.set(r.x(),r.y(),r.z())}static newPathData(){return{axis:new Xt,cuts:[],center:new Xt,last:new Xt,first:new Xt,mids:[]}}static fetchAxisPartSize(t,e){const s=t-2,i=e.faces*s*3,r=e.links*t*this._wireSize;this._axisPartSize.verticesLength=e.points,this._axisPartSize.indicesLength=e.indices+i+r}};ot(Pu,"up",new Xt(0,0,1)),ot(Pu,"circleCurves",[]),ot(Pu,"circleCurvePoints"),ot(Pu,"temp",{circleExtrusion:new oc,circleCurve:new $l,wireSet:new tc,axis:new ec,rotation:new jt,vector:new Xt}),ot(Pu,"_wireSize",6),ot(Pu,"_minSize",6),ot(Pu,"_maxSize",30),ot(Pu,"_axisPartSize",{verticesLength:0,indicesLength:0}),ot(Pu,"getAxisPartWireSetData",((t,e,s)=>{const i=Pu.newEmptyAxisPartData();t.wireSets(e,Pu.temp.wireSet);const r=Pu.temp.wireSet.psLength()-1;return i.points=2*r*s,i.indices=Pu._wireSize*r*s,i.faces=2*r,i})),ot(Pu,"getAxisPartWireData",((t,e,s)=>{const i=Pu.newEmptyAxisPartData();return i.points=2*s,i.indices=Pu._wireSize*s,i.faces=2,i})),ot(Pu,"getAxisPartCircleCurveData",((t,e,s)=>{const i=Pu.newEmptyAxisPartData();t.circleCurves(e,Pu.temp.circleCurve);const r=Tu.circleCurve3Divisions(Pu.temp.circleCurve),n=s*r;i.points=n;const o=s*(r-1),a=Pu._wireSize*o;i.indices=a;return i.faces=2,i.links=2,i}));let Bu=Pu;class Eu{constructor(){ot(this,"_minLinkDistance",1e-8),ot(this,"_first",new Xt),ot(this,"_last",new Xt),ot(this,"_currentPoint"),ot(this,"_currentIndex"),ot(this,"_v1",new Xt),ot(this,"_v2",new Xt),ot(this,"_v3",new Xt),ot(this,"_v4",new Xt),ot(this,"_tempLine",new fi),ot(this,"_total",0),ot(this,"_closest",0),ot(this,"_result",0)}newTemplate(t,e,s){const i=t.radius(e),r=t.axes(e,Bu.temp.axis),n=Bu.vertexLength(i);let o=s[s.length-1];const a=r.orderLength();for(let t=0;t<a;t++)o=this.generateTemplate(r,t,n,o,s)}construct(t,e){const s={};let i=0;for(let r=0,n=t.axesLength();r<n;r++){const n=t.radius(r);t.axes(r,Bu.temp.axis);const o=Bu.vertexLength(n);i=this.constructVce(o,s,undefined,i,0,e,n)}}getTemplateCreationData(t,e,s){const i=!t;let r=!1;if(!i){const i=t.positionCount/3,n=e.verticesLength;r=Bu.validSize(i,n,s)}return{isStart:i,fits:r}}generateTemplate(t,e,s,i,r){const n=Bu.getAxisPartSize(t,e,s),{isStart:o,fits:a}=this.getTemplateCreationData(i,n,s);return(o||!a)&&(i=this.newTemplateData(),r.push(i),this.savePrevious(o,e,s,i)),i.positionCount+=3*n.verticesLength,i.normalCount+=3*n.verticesLength,i.indexCount+=n.indicesLength,i}savePrevious(t,e,s,i){if(!t&&0!==e){const t=3*(s-2);i.positionCount+=3*s,i.normalCount+=3*s,i.indexCount+=t}}constructNewVce(t,e,s,i,r,n,o){const a=!t;let h=!1;if(!a){const t=e.verticesLength;h=Bu.validSize(s,t,i)}if(a||!h){t=r[n++],this.setupNewVceBuffers(t);const e=this._currentPoint;s=this.clearOffset(s);if(!a&&0!==o){const o=r[n-2];this.getClone(o,t,e,i),s+=i}}return{data:t,pointAmount:s,position:n}}constructVce(t,e,s,i,r,n,o){const a=Bu.temp.axis.orderLength();for(let h=0;h<a;h++){const a=Bu.temp.axis,l=Bu.getAxisPartSize(a,h,t);this.setupLink(h,e),({data:s,pointAmount:i,position:r}=this.constructNewVce(s,l,i,t,n,r,h)),this.newAxisPart(Bu.temp.axis,h,s,o,t,e),i+=l.verticesLength}return i}newTemplateData(){return{objectClass:_i.SHELL,indexCount:0,positionCount:0,normalCount:0}}setupNewVceBuffers(t){t.positionBuffer=new Float32Array(t.positionCount),t.normalBuffer=new Int16Array(t.normalCount),t.indexBuffer=new Uint16Array(t.indexCount)}clearOffset(t){return this._currentPoint=0,this._currentIndex=0,0}getClone(t,e,s,i){for(let r=-3*i;r<0;r++){const i=e.positionBuffer,n=t.positionBuffer,o=e.normalBuffer,a=t.normalBuffer;i[this._currentPoint]=n[s+r],o[this._currentPoint]=a[s+r],this._currentPoint++}}manageAxisPartCreation(t,e,s,i,r,n,o){if(t!==sc.CIRCLE_CURVE)if(t!==sc.WIRE_SET){if(t===sc.WIRE){const t=e.wires(s);this.newWire(t,i,r,n,o)}}else{const t=e.wireSets(s);this.newWireSet(t,i,r,n,o)}else{const t=e.circleCurves(s);this.newCircleCurve(t,i,r,n,o)}}newWireSetStart(t,e,s,i){1===t?this.linkStart(e,s,i,this._first,sc.WIRE_SET):this.newPathOrderData(e,s)}newWireSet(t,e,s,i,r){for(let n=1,o=t.psLength();n<o;n++){const a=Bu.temp.rotation;this.getWireSetPoints(t,n),this.setWireSetVector(),this.newPath(this._first,e,a,s,i),this.newWireSetStart(n,s,i,r),this.newPath(this._last,e,a,s,i),this.fillWireSetData(n,o,r,s,i),this.linkPaths(s,i)}}fillWireSetData(t,e,s,i,r){t!==e-1||s.last?this.newPathOrderData(i,r,!0):(s.placement=this._last,s.axisClass=sc.WIRE_SET)}setWireSetVector(){Bu.temp.vector.copy(this._last),Bu.temp.vector.sub(this._first),Bu.temp.vector.normalize(),Bu.temp.rotation.setFromUnitVectors(Bu.up,Bu.temp.vector)}newCircleCurveBody(t,e,s,i){const r=t-2;for(let t=0;t<r;t++){const r=Bu.circleCurves[t],n=Bu.circleCurves[t+1],o=Bu.circleCurves[t+2],a=Bu.temp.vector;a.copy(o),a.sub(r),a.normalize(),Bu.temp.rotation.setFromUnitVectors(Bu.up,a),this.newPath(n,e,Bu.temp.rotation,s,i),this.linkPaths(s,i,!0)}}newCircleCurveFinish(t,e,s,i,r){const n=t-2,o=t-1,a=Bu.circleCurves[n],h=Bu.circleCurves[o],l=Bu.temp.vector;l.copy(h),l.sub(a),l.normalize(),Bu.temp.rotation.setFromUnitVectors(Bu.up,l),this.newPath(h,e,Bu.temp.rotation,s,i),r.last?this.newPathOrderData(s,i,!0):(r.placement=Bu.circleCurves[o],r.axisClass=sc.CIRCLE_CURVE)}setupLink(t,e){0===t&&(e.first=!0);t===Bu.temp.axis.orderLength()-1&&(e.last=!0)}newCircleCurveStart(t,e,s,i){const r=Bu.circleCurves[0],n=Bu.circleCurves[1],o=Bu.temp.vector;o.copy(n),o.sub(r),o.normalize(),Bu.temp.rotation.setFromUnitVectors(Bu.up,o),this.newPath(r,t,Bu.temp.rotation,e,s);const a=sc.CIRCLE_CURVE;this.linkStart(e,s,i,r,a)}getWireSetPoints(t,e){const s=t.ps(e-1);this._first.set(s.x(),s.y(),s.z());const i=t.ps(e);this._last.set(i.x(),i.y(),i.z())}finishWire(t,e,s,i){this.newPath(this._last,t,Bu.temp.rotation,e,s),i.last?this.newPathOrderData(e,s,!0):(i.placement=this._last,i.axisClass=sc.WIRE),this.linkPaths(e,s)}linkPaths(t,e,s=!1){const i=e,{p1:r,p2:n,p3:o}=this.getPathPositions(i,s,t),a=t.indexBuffer;for(let t=0;t<i;t++){const e=(t+1)%i,{i3:s,i4:h,i1:l,i2:c}=this.getLinkPathIndices(o,t,r,i,e,n);a[this._currentIndex++]=s,a[this._currentIndex++]=h,a[this._currentIndex++]=l,a[this._currentIndex++]=l,a[this._currentIndex++]=h,a[this._currentIndex++]=c}}startWire(t,e,s,i){this.newPath(this._first,t,Bu.temp.rotation,e,s);const r=sc.WIRE;this.linkStart(e,s,i,this._first,r)}setupWireVectors(){const t=Bu.temp.vector;t.copy(this._last),t.sub(this._first),t.normalize(),Bu.temp.rotation.setFromUnitVectors(Bu.up,t)}getLinkPathIndices(t,e,s,i,r,n){let o=0,a=0,h=0,l=0;return o=t+e>=s?t+e-i:t+e,a=t+r>=s?t+r-i:t+r,h=n+e>=s+i?n+e-i:n+e,l=n+r>=s+i?n+r-i:n+r,{i3:h,i4:l,i1:o,i2:a}}fetchWirePoints(t){const e=t.p1(),s=t.p2();this._first.set(e.x(),e.y(),e.z()),this._last.set(s.x(),s.y(),s.z())}findLinkedVertex(t,e,s,i,r){for(let n=t;n<e;n++){this.point(n,s,this._v1);const e=n-i+r,o=e>=t?e-i:e;this.point(o,s,this._v2);const a=e+1>=t?e+1-i:e+1;this.point(a,s,this._v3),this._tempLine.set(this._v2,this._v3),this._tempLine.closestPointToPoint(this._v1,!0,this._v4),this._total+=this._v4.distanceTo(this._v1)}}newPath(t,e,s,i,r){Bu.setPathVertices(r);for(let n=0;n<r;n++)this.setPathPosition(n,e,s,t,i),this.setPathNormal(n,s,i),this._currentPoint+=3}linkStart(t,e,s,i,r){if(s.first)return void this.newPathOrderData(t,e);const n=sc.CIRCLE_CURVE,o=s.axisClass===n||r===n,a=s.placement.distanceToSquared(i)<this._minLinkDistance;if(!o||!a)return this.newPathOrderData(t,e,!0,!0),void this.newPathOrderData(t,e);this.linkPaths(t,e,!0)}setPathPosition(t,e,s,i,r){const n=Bu.temp.vector;n.copy(Bu.circleCurvePoints[t]),n.multiplyScalar(e),n.applyQuaternion(s),n.add(i);const o=r.positionBuffer,a=this._currentPoint,h=this._currentPoint+1,l=this._currentPoint+2;o[a]=n.x,o[h]=n.y,o[l]=n.z}newWire(t,e,s,i,r){this.fetchWirePoints(t),this.setupWireVectors(),this.startWire(e,s,i,r),this.finishWire(e,s,i,r)}newCircleCurve(t,e,s,i,r){const n=Tu.circleCurve3Divisions(t);Bu.circleCurves=Bu.newPaths(t,n),this.newCircleCurveStart(e,s,i,r),this.newCircleCurveBody(n,e,s,i),this.newCircleCurveFinish(n,e,s,i,r),this.linkPaths(s,i,!0)}newPathOrderData(t,e,s=!1,i=!1){const r=e-2,n=t.indexBuffer;for(let t=0;t<r;t++){const r=this._currentPoint/3,o=e*(i?2:1),a=r-o;n[this._currentIndex]=a,this._currentIndex++;const h=r+t+(s?2:1)-o;n[this._currentIndex]=h,this._currentIndex++;const l=r+t+(s?1:2)-o;n[this._currentIndex]=l,this._currentIndex++}}getPathPositions(t,e,s){const i=this._currentPoint/3-t,r=i;let n=i-t;return e&&(n=this.fetchLinkedVertex(i,s,t)),{p3:n,p1:i,p2:r}}newAxisPart(t,e,s,i,r,n){const o=t.parts(e),a=t.order(e);this.manageAxisPartCreation(o,t,a,i,s,r,n),n.first=!1,n.last=!1}fetchLinkedVertex(t,e,s){this._closest=Number.MAX_VALUE;for(let i=0;i<s;i++){this._total=0;const r=t+s;this.findLinkedVertex(t,r,e,s,i);this._total<this._closest&&(this._closest=this._total,this._result=t-s+i+1)}return this._result}setPathNormal(t,e,s){const i=Bu.temp.vector,r=Bu.circleCurvePoints[t];i.copy(r),i.applyQuaternion(e);const n=s.normalBuffer,o=this._currentPoint,a=this._currentPoint+1,h=this._currentPoint+2;n[o]=i.x*Nc,n[a]=i.y*Nc,n[h]=i.z*Nc}point(t,e,s){const i=e.positionBuffer,r=3*t+1,n=3*t+2,o=i[3*t],a=i[r],h=i[n];return s.set(o,a,h),s}}class Fu{constructor(t){ot(this,"_meshes"),ot(this,"_results",[]),ot(this,"_circleExtrusion",new oc),ot(this,"_axis",new ec),this._meshes=t}raycast(t,e){this._results.length=0,this._meshes.circleExtrusions(t,this._circleExtrusion);for(let t=0,s=this._circleExtrusion.axesLength();t<s;t++){this._circleExtrusion.axes(t,this._axis);const s=this._circleExtrusion.radius(t);this.traverseAllCurves(e,s)}return this._results}getTraverseWiresEvent(t,e){return(s,i)=>{this.castCurveExtrusion(s,i,t,e)}}castCurveExtrusion(t,e,s,i){const r=Tu.raycastCircleExtr(t,e,s,i);for(const t of r)this._results.push(t)}getTraverseCircleCurveEvent(t,e){return(s,i,r)=>{const n=i[0];this.castCurveExtrusion(s,n,t,e);for(let s=0;s<i.length;s++){if(0===s)continue;const r=i[s-1],n=i[s];this.castCurveExtrusion(r,n,t,e)}const o=i[i.length-1];this.castCurveExtrusion(o,r,t,e)}}traverseAllCurves(t,e){const s=this.getTraverseWiresEvent(t,e);Tu.traverseWires(this._axis,s);const i=this.getTraverseCircleCurveEvent(t,e),r=Tu.circleCurve3Divisions;Tu.traverseCircleCurve(this._axis,i,r);const n=this.getTraverseWiresEvent(t,e);Tu.traverseWireSets(this._axis,n)}}class Ru{constructor(t){ot(this,"_meshes"),ot(this,"_found",[]),ot(this,"_circleExtrusion",new oc),ot(this,"_axis",new ec),ot(this,"_wirePoint",new Xt),this._meshes=t}lineRaycast(t,e){this._found.length=0,this._meshes.circleExtrusions(t,this._circleExtrusion);const s=this._circleExtrusion.axesLength();for(let t=0;t<s;t++)this._circleExtrusion.axes(t,this._axis),this.processLineRaycast(t,e);return this._found}wireSetRaycast(t,e){const s=this._axis;Tu.traverseWireSets(s,((s,i)=>{this.cylinderRaycast(s,i,t,e)}))}exclusiveCylinderRaycast(t,e){const s=this._axis,i=this.getCylinderRaycastEvent(t,e);Tu.traverseWires(s,i)}processLineRaycast(t,e){const s=this._circleExtrusion.radius(t);this.exclusiveCylinderRaycast(e,s),this.circleCurveRaycast(e,s),this.wireSetRaycast(e,s)}getCylinderRaycastEvent(t,e){return(s,i)=>{this.cylinderRaycast(s,i,t,e)}}processCircleCurveBody(t,e,s){for(let i=0;i<t.length;i++){if(0===i)continue;const r=t[i],n=t[i-1];this.cylinderRaycast(n,r,e,s)}}getCircleCurveRaycastEvent(t,e){return(s,i,r)=>{this.cylinderRaycast(s,i[0],t,e),this.processCircleCurveBody(i,t,e);const n=i[i.length-1];this.cylinderRaycast(n,r,t,e)}}fetchCylinderRaycastResult(t,e,s){t.distanceSqToSegment(e,s,void 0,this._wirePoint);const i=this.newResult(e,s);this._found.push(i)}circleCurveRaycast(t,e){const s=Tu.circleCurve3Divisions,i=this.getCircleCurveRaycastEvent(t,e);Tu.traverseCircleCurve(this._axis,i,s)}newResult(t,e){return{point:this._wirePoint.clone(),raySquaredDistance:void 0,snappedEdgeP1:t.clone(),snappedEdgeP2:e.clone()}}cylinderRaycast(t,e,s,i){const r=Tu.raycastCircleExtr(t,e,s,i);for(const i of r)i.point&&this.fetchCylinderRaycastResult(s,t,e)}}class ku{constructor(t){ot(this,"_meshes"),ot(this,"_results",[]),ot(this,"_circleExtrusion",new oc),ot(this,"_axis",new ec),ot(this,"_normal",new Xt),ot(this,"_point",new Xt),ot(this,"_plane",new hi),this._meshes=t}pointRaycast(t,e){return this._results.length=0,this._meshes.circleExtrusions(t,this._circleExtrusion),this.traverseAllCircleExtrusions(e),this.getCleanResults()}fetchOrientation(t,e){Bu.temp.vector.copy(t),Bu.temp.vector.sub(e),Bu.temp.vector.normalize();Bu.temp.rotation.setFromUnitVectors(Bu.up,Bu.temp.vector)}getTraverseWiresEvent(t,e){return(s,i)=>{this.fetchOrientation(s,i);const r=this.raycastCutCircleExtrusion(s,t,e),n=this.raycastCutCircleExtrusion(i,t,e);this._results.push(r,n)}}traverseAllCircleExtrusions(t){const e=this._circleExtrusion.axesLength();for(let s=0;s<e;s++){this._circleExtrusion.axes(s,this._axis);const e=this._circleExtrusion.radius(s),i=Bu.vertexLength(e);Bu.setPathVertices(i),this.traverseAllCurves(t,e)}}setupCuttedCircleExtrusion(t){this._normal.set(0,0,1),this._normal.applyQuaternion(Bu.temp.rotation),this._plane.setFromNormalAndCoplanarPoint(this._normal,t)}getTraverseCircleCurveEvent(t,e){return(s,i,r)=>{this.fetchOrientation(s,i[0]);const n=this.raycastCutCircleExtrusion(s,t,e),o=i[i.length-1];this.fetchOrientation(o,r);const a=this.raycastCutCircleExtrusion(r,t,e);this._results.push(n,a)}}computeCutCircleExtrCast(t,e,s){s.intersectPlane(this._plane,this._point);if(this._point.distanceTo(t)<=e){return{point:t.clone()}}}raycastCutCircleExtrusion(t,e,s){this.setupCuttedCircleExtrusion(t);if(e.intersectsPlane(this._plane))return this.computeCutCircleExtrCast(t,s,e)}getCleanResults(){const t=[];for(const e of this._results)e&&t.push(e);return t}traverseAllCurves(t,e){const s=this.getTraverseWiresEvent(t,e);Tu.traverseWires(this._axis,s);const i=this.getTraverseCircleCurveEvent(t,e),r=Tu.circleCurve3Divisions;Tu.traverseCircleCurve(this._axis,i,r);const n=this.getTraverseWiresEvent(t,e);Tu.traverseWireSets(this._axis,n)}}class Vu{constructor(){ot(this,"_currentElement",0),ot(this,"_wireSize",6),ot(this,"newCircleCurveLod",((t,e,s)=>{const i=this.newCircleCurveLodPath(t,e),r=s.positionBuffer;for(let t=1;t<i;t++){const e=Bu.circleCurves[t-1],s=Bu.circleCurves[t];this.newWire(r,e,s)}})),ot(this,"newWireSetLod",((t,e,s)=>{const i=t.wireSets(e),r=i.psLength(),n=s.positionBuffer;for(let t=1;t<r;t++){const e=i.ps(t-1),s=i.ps(t);this.newWire(n,e,s)}})),ot(this,"newWireTemplate",((t,e)=>{e.positionCount+=this._wireSize})),ot(this,"newWireSetTemplate",((t,e)=>{const s=Bu.temp.axis.wireSets(t,Bu.temp.wireSet).psLength()-1;e.positionCount+=this._wireSize*s})),ot(this,"newWireLod",((t,e,s)=>{const i=t.wires(e),r=i.p1(),n=i.p2(),o=s.positionBuffer;this.newWire(o,r,n)})),ot(this,"newCircleCurveTemplate",((t,e)=>{const s=Bu.temp.axis.circleCurves(t,Bu.temp.circleCurve),i=Tu.circleCurve3Divisions(s);e.positionCount+=this._wireSize*(i-1)}))}construct(t,e){this._currentElement=0,e.positionBuffer=new Float32Array(e.positionCount);for(let s=0,i=t.axesLength();s<i;s++)t.axes(s,Bu.temp.axis),this.constructLod(e);return e}constructCircleExtrusionLod(t,e){const s=Bu.temp.axis,i=s.parts(t),r=s.order(t);this.getLodConstructor(i)(s,r,e)}newCircleCurveLodPath(t,e){const s=t.circleCurves(e),i=Tu.circleCurve3Divisions(s);return Bu.circleCurves=Bu.newPaths(s,i),i}selectNextWire(){this._currentElement+=this._wireSize}getAxisPartVertexSize(t,e){const s=Bu.temp.axis,i=s.parts(t),r=s.order(t);this.getTemplateConstructor(i)(r,e)}getIndices(){return{i1:this._currentElement,i2:this._currentElement+1,i3:this._currentElement+2,i4:this._currentElement+3,i5:this._currentElement+4,i6:this._currentElement+5}}setAxisTemplate(t,e){Bu.temp.circleExtrusion.axes(t,Bu.temp.axis);const s=Bu.temp.axis.partsLength();for(let t=0;t<s;t++)this.getAxisPartVertexSize(t,e);this.setAxisThickness(e,t)}constructLod(t){const e=Bu.temp.axis.orderLength();for(let s=0;s<e;s++)this.constructCircleExtrusionLod(s,t)}getLodConstructor(t){return{[sc.WIRE]:this.newWireLod,[sc.WIRE_SET]:this.newWireSetLod,[sc.CIRCLE_CURVE]:this.newCircleCurveLod}[t]}newTemplate(){const t=Bu.temp.circleExtrusion,e=this.newTemplateData(),s=t.axesLength();for(let t=0;t<s;t++)this.setAxisTemplate(t,e);return e}setAxisThickness(t,e){const s=t.lodThickness,i=Bu.temp.circleExtrusion.radius(e);t.lodThickness=Math.max(s,i)}newTemplateData(){return{objectClass:_i.LINE,lod:gi.WIRES,lodThickness:0,positionCount:0}}getTemplateConstructor(t){return{[sc.WIRE]:this.newWireTemplate,[sc.WIRE_SET]:this.newWireSetTemplate,[sc.CIRCLE_CURVE]:this.newCircleCurveTemplate}[t]}newWire(t,e,s){const i=e instanceof Xt?e.x:e.x(),r=e instanceof Xt?e.y:e.y(),n=e instanceof Xt?e.z:e.z(),o=s instanceof Xt?s.x:s.x(),a=s instanceof Xt?s.y:s.y(),h=s instanceof Xt?s.z:s.z(),{i1:l,i2:c,i3:u,i4:d,i5:p,i6:f}=this.getIndices();t[l]=i,t[c]=r,t[u]=n,t[d]=o,t[p]=a,t[f]=h,this.selectNextWire()}}class Lu extends Uc{constructor(){super(...arguments),ot(this,"_vceConstructor",new Eu),ot(this,"_lodConstructor",new Vu),ot(this,"_vceRaycaster",new Fu(this.meshes)),ot(this,"_vceLineRaycaster",new Ru(this.meshes)),ot(this,"_vcePointRaycaster",new ku(this.meshes)),ot(this,"_representationClass",Ic.CIRCLE_EXTRUSION),ot(this,"_objectClass",_i.LINE),ot(this,"lodClass",Wc.CUSTOM)}setupTemplates(){const t=this.meshes.circleExtrusionsLength();for(let e=0;e<t;e++)this.newCircleExtrusionTemplate(e)}fetchLod(t,e){const s=this.getMesh(t,gi.WIRES);return this.generateLodIfNeeded(t,e,s),s}fetchMeshes(t,e){const s=this.getMesh(t,gi.GEOMETRY);return this.generateMeshesIfNeeded(t,e,s),s}raycast(t,e){return this._vceRaycaster.raycast(t,e)}faceRaycast(){return[]}pointRaycast(t,e){return this._vcePointRaycaster.pointRaycast(t,e)}lineRaycast(t,e){return this._vceLineRaycaster.lineRaycast(t,e)}getObjectClass(){return this._objectClass}getRepresentation(){return this._representationClass}getLodClass(){return this.lodClass}newMeshes(t,e){this.meshes.circleExtrusions(t,Bu.temp.circleExtrusion);const s=Bu.temp.circleExtrusion;this._vceConstructor.construct(s,e),this.saveMesh(t,e,gi.GEOMETRY)}generateMeshesIfNeeded(t,e,s){if(0===s.length)return;const i=Boolean(s.length),r=!s[0].positionBuffer;e&&r&&i&&this.newMeshes(t,s)}newCircleExtrusionTemplate(t){const e=[];this.meshes.circleExtrusions(t,Bu.temp.circleExtrusion);const s=Bu.temp.circleExtrusion,i=s.axesLength();for(let t=0;t<i;t++)this._vceConstructor.newTemplate(s,t,e);const r=this._lodConstructor.newTemplate();this.useMesh(t,e,gi.GEOMETRY),this.useMesh(t,r,gi.WIRES)}generateLodIfNeeded(t,e,s){!s.positionBuffer&&e&&(this.meshes.circleExtrusions(t,Bu.temp.circleExtrusion),this._lodConstructor.construct(Bu.temp.circleExtrusion,s),this.saveMesh(t,s,gi.WIRES))}}class Ou{constructor(t){ot(this,"size"),ot(this,"_data"),ot(this,"_highlightData"),this.size=t,this._data=new Uint8Array(t),this._highlightData=new Uint16Array(t),this._data.fill(1)}getHighlight(t){return this._highlightData[t]}setHighlight(t,e){Rc.checkMemory(e),this._highlightData[t]=e}clearHighlight(){this._highlightData.fill(0)}visible(t){return Rc.check(this._data,t,xi.VISIBLE)}setVisible(t,e){Rc.apply(this._data,t,xi.VISIBLE,e)}clearVisible(){this._data.fill(1)}}class Du{constructor(t,e){ot(this,"_rate",64),ot(this,"_updater"),ot(this,"_modelId"),ot(this,"_threshold",16),ot(this,"_connection"),ot(this,"_list",[]),ot(this,"refresh",(()=>{if(this._list.length){const t=this._list;this._connection.fetchMeshCompute(this._modelId,t),this._list=[]}})),this._modelId=t,this._connection=e,this._updater=vi.newUpdater(this.refresh,this._rate)}get needsRefresh(){return this._list.length>this._threshold}dispose(){vi.deleteUpdater(this._updater)}clean(){this._list=vi.cleanRequests(this._list)}process(t){this._list.push(t),this.needsRefresh&&this.refresh()}}class Uu{constructor(t,e,s,i){ot(this,"_meshes"),ot(this,"_model"),ot(this,"_boxes"),ot(this,"_tiles"),ot(this,"_items"),ot(this,"_edgeThreshold",8),ot(this,"_raycastMultiplier",32),ot(this,"_maxDuration",512),ot(this,"_precission",.001),ot(this,"_temp",{sample:new _c,representation:new mc,tempPlane:new hi,ray:new Se,frustum:new ui,m1:new Me,m2:new Me,m3:new Me,v1:new Xt,planes:[]}),this._model=t,this._boxes=e,this._tiles=s,this._items=i,this._meshes=t.meshes()}static cast(t,e,s,i,r){const n=e.id();return r===wi.FACE?t.faceRaycast(n,s,i):r===wi.LINE?t.lineRaycast(n,s,i):r===wi.POINT?t.pointRaycast(n,s,i):void 0===r?t.raycast(n,s,i):void 0}raycast(t,e,s){const i={ray:t,frustum:e,planes:s},r=this.castBox(e,s);return r.length?this.computeRaycastList(r,i):null}snapRaycast(t,e,s,i){const r=[],n={ray:t,frustum:e,planes:i},o=this.raycast(t,e,i);return o?(this.getSnaps(o,n,s,r),o.normal?this.filterOnFront(r):r):this.snapCastEdges(n,s)}rectangleRaycast(t,e,s){const i=this._boxes.lookup.collideFrustum(e,t,s),r=this.filterVisible(i);return this.localIdsFromItemIds(r)}snapCastEdges(t,e){const s=[],i=e.includes(wi.POINT),r=e.includes(wi.LINE);return(i||r)&&this.computeEdgesCast(t,e,s),this.addDistanceToEdgeResult(s,t.ray),s}filterVisible(t){const e=[];for(const s of t){this._meshes.samples(s,this._temp.sample);const t=this._temp.sample.item();this._items.visible(t)&&e.push(s)}return e}computeSnaps(t,e,s,i){for(const r of t){if(this.isValidSnap(r)){const t={snap:r,...e},n=this.castSample(s,t);for(const t of n)i.push(t)}}}computeEdgesCast(t,e,s){const i=this.getRawEdges(t),r=performance.now();for(const n of i){this.fetchSampleData(n),this.computeSnaps(e,t,n,s);if(this.isTimeExceeded(r))break}}addDistanceToEdgeResult(t,e){for(const s of t){const t=s.point;s.raySquaredDistance=e.distanceSqToPoint(t)}}getRawEdges(t){const e=this.castBox(t.frustum,t.planes);return e.length<=this._edgeThreshold?e:this.sortBoxes(t.ray,e,this._edgeThreshold)}sortBoxes(t,e,s){const i=[],r=new Xt,n=t.origin;for(let s=0;s<e.length;s++){const o=e[s],a=this._boxes.get(o);t.intersectBox(a,r);const h=r.distanceToSquared(n);i.push(h)}const o=this.dataSort(e,i);return s&&o.length>s&&o.splice(s),o}castBox(t,e){const s=this._boxes.lookup;if(t instanceof Se){const i=s.collideRay(e,t);return this.filterVisible(i)}const i=s.collideFrustum(e,t);return this.filterVisible(i)}dataSort(t,e){const s=Array.from(t.keys()).sort(((t,s)=>e[t]-e[s])),i=[];for(const e of s){const s=t[e];i.push(s)}return i}localIdsFromItemIds(t){const e=new Set;for(const s of t){this._meshes.samples(s,this._temp.sample);const t=this._temp.sample.item(),i=this._meshes.meshesItems(t);if(null===i)continue;const r=this._model.localIds(i);null!==r&&e.add(r)}return Array.from(e)}getNearest(t){let e=t[0];for(let s=1;s<t.length;s++){const i=t[s];if(e.raySquaredDistance&&i.raySquaredDistance){const t=this.getNearScore(e);this.getNearScore(i)<t&&(e=i)}else i.cameraSquaredDistance<e.cameraSquaredDistance&&(e=i)}return e}getEdges(t,e,s){const i=this.snapCastEdges(t,e);if(i)for(const t of i)s.push(t)}getNearScore(t){const e=this._raycastMultiplier;return t.raySquaredDistance*e+t.cameraSquaredDistance}setupSampleCastData(t){Lc.get(this._temp.sample,this._meshes,this._temp.m1),this._temp.m2.copy(this._temp.m1).invert(),this._temp.ray.copy(t.ray).applyMatrix4(this._temp.m2),wl.transform(t.frustum,this._temp.m2,this._temp.frustum)}addLocalId(t){if(!t)return;const e=this._meshes.meshesItems(t.itemId);null!==e&&(t.localId=this._model.localIds(e))}fetchSampleData(t){this._meshes.samples(t,this._temp.sample);const e=this._temp.sample.representation();this._meshes.representations(e,this._temp.representation)}computeRaycastList(t,e){const s=Array.from(new Set(t)),i=this.sortBoxes(e.ray,s),r=this.castBox(e.ray,e.planes),n=this.findAll(i,r,e);if(n.length){const t=this.getNearest(n);return this.addLocalId(t),t}return null}formatRaycastResult(t,e,s){for(const i of t){if(i.point.applyMatrix4(this._temp.m1),i.normal&&i.normal.transformDirection(this._temp.m1),"facePoints"in i){const t=this._meshes.samples(e,this._temp.sample);Lc.get(t,this._meshes,this._temp.m3);for(let t=0;t<i.facePoints.length;t+=3){const e=i.facePoints[t],s=i.facePoints[t+1],r=i.facePoints[t+2];this._temp.v1.set(e,s,r),this._temp.v1.applyMatrix4(this._temp.m3),i.facePoints[t]=this._temp.v1.x,i.facePoints[t+1]=this._temp.v1.y,i.facePoints[t+2]=this._temp.v1.z}}i.sampleId=e,i.itemId=this._temp.sample.item();const t=s.ray.origin.distanceToSquared(i.point);i.cameraSquaredDistance=t,i.snappingClass||(i.snappingClass=s.snap),i.snappedEdgeP1&&i.snappedEdgeP1.applyMatrix4(this._temp.m1),i.snappedEdgeP2&&i.snappedEdgeP2.applyMatrix4(this._temp.m1)}}findAll(t,e,s){const i=[],r=performance.now();for(const n of t){if(this.fetchSampleData(n),!e.includes(n))continue;const t=this.castSample(n,s);for(const e of t)i.push(e);if(this.isTimeExceeded(r))break}return i}isTimeExceeded(t){return performance.now()-t>this._maxDuration}getFilteredSampleCast(t){const e=this._tiles.raycast(this._temp.representation,this._temp.ray,this._temp.frustum,t.snap);if(0===this._temp.planes.length)return e;const s=[];if(e)for(const t of e){const e=this._temp.planes,i=t.point;xl.containedInParallelPlanes(e,i)&&s.push(t)}return s}getSnaps(t,e,s,i){this.fetchSampleData(t.sampleId),t.normal&&(this.setCastSide(t,e.ray),this.setCastPlane(t)),this.getFaces(s,e,t,i),this.getEdges(e,s,i);for(const t of i)this.addLocalId(t)}filterOnFront(t){const e=[];for(const s of t){this._temp.tempPlane.distanceToPoint(s.point)>=0&&e.push(s)}return e}setCastSide(t,e){const s=t.point.clone().sub(e.origin);t.normal.dot(s)>0&&t.normal.negate()}getFaces(t,e,s,i){for(const r of t){const t={snap:r,...e},n=this.castSample(s.sampleId,t);for(const t of n)i.push(t)}}setCastPlane(t){const e=this._temp.tempPlane,s=t.point.clone(),i=t.normal.clone();i.multiplyScalar(this._precission),s.sub(i),e.setFromNormalAndCoplanarPoint(t.normal,s)}castSample(t,e){this.setupSampleCastData(e),this.setupPlanesForSampleCast(e);const s=this.getFilteredSampleCast(e);return s&&this.formatRaycastResult(s,t,e),s}isValidSnap(t){const e=t===wi.LINE,s=t===wi.POINT;return e||s}transform(t,e){const s=[];if(t)for(const i of t){const t=(new hi).copy(i);t.applyMatrix4(e),s.push(t)}return s}setupPlanesForSampleCast(t){if(this._temp.planes.length=0,t.planes&&t.planes.length>0){const e=this.transform(t.planes,this._temp.m2);for(const t of e)this._temp.planes.push(t)}}}const Nu="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,Wu=new Set,Hu="object"==typeof process&&process?process:{},qu=(t,e,s,i)=>{"function"==typeof Hu.emitWarning?Hu.emitWarning(t,e,s,i):console.error(`[${s}] ${e}: ${t}`)};let Zu=globalThis.AbortController,Gu=globalThis.AbortSignal;if(void 0===Zu){Gu=class{constructor(){ot(this,"onabort"),ot(this,"_onabort",[]),ot(this,"reason"),ot(this,"aborted",!1)}addEventListener(t,e){this._onabort.push(e)}},Zu=class{constructor(){ot(this,"signal",new Gu),s()}abort(t){var e,s;if(!this.signal.aborted){this.signal.reason=t,this.signal.aborted=!0;for(const e of this.signal._onabort)e(t);null==(s=(e=this.signal).onabort)||s.call(e,t)}}};let e="1"!==(null==(t=Hu.env)?void 0:t.LRU_CACHE_IGNORE_AC_WARNING);const s=()=>{e&&(e=!1,qu("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",s))}}const ju=t=>t&&t===Math.floor(t)&&t>0&&isFinite(t),Xu=t=>ju(t)?t<=Math.pow(2,8)?Uint8Array:t<=Math.pow(2,16)?Uint16Array:t<=Math.pow(2,32)?Uint32Array:t<=Number.MAX_SAFE_INTEGER?Yu:null:null;class Yu extends Array{constructor(t){super(t),this.fill(0)}}const Ju=class t{constructor(s,i){if(ot(this,"heap"),ot(this,"length"),!ht(t,e))throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new i(s),this.length=0}static create(s){const i=Xu(s);if(!i)return[];ct(t,e,!0);const r=new t(s,i);return ct(t,e,!1),r}push(t){this.heap[this.length++]=t}pop(){return this.heap[--this.length]}};e=new WeakMap,lt(Ju,e,!1);let Qu=Ju;const $u=class t{constructor(e){lt(this,C),lt(this,F),lt(this,O),lt(this,U),lt(this,W),lt(this,Z),lt(this,j),lt(this,Y),lt(this,Q),lt(this,K),lt(this,et),lt(this,it),lt(this,s,void 0),lt(this,i,void 0),lt(this,r,void 0),lt(this,n,void 0),lt(this,o,void 0),lt(this,a,void 0),lt(this,h,void 0),ot(this,"ttl"),ot(this,"ttlResolution"),ot(this,"ttlAutopurge"),ot(this,"updateAgeOnGet"),ot(this,"updateAgeOnHas"),ot(this,"allowStale"),ot(this,"noDisposeOnSet"),ot(this,"noUpdateTTL"),ot(this,"maxEntrySize"),ot(this,"sizeCalculation"),ot(this,"noDeleteOnFetchRejection"),ot(this,"noDeleteOnStaleGet"),ot(this,"allowStaleOnFetchAbort"),ot(this,"allowStaleOnFetchRejection"),ot(this,"ignoreFetchAbort"),lt(this,l,void 0),lt(this,c,void 0),lt(this,u,void 0),lt(this,d,void 0),lt(this,p,void 0),lt(this,f,void 0),lt(this,m,void 0),lt(this,_,void 0),lt(this,b,void 0),lt(this,g,void 0),lt(this,y,void 0),lt(this,x,void 0),lt(this,w,void 0),lt(this,v,void 0),lt(this,S,void 0),lt(this,M,void 0),lt(this,A,void 0),lt(this,I,void 0),lt(this,T,(()=>{})),lt(this,P,(()=>{})),lt(this,B,(()=>{})),lt(this,E,(()=>!1)),lt(this,k,(t=>{})),lt(this,V,((t,e,s)=>{})),lt(this,L,((t,e,s,i)=>{if(s||i)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0})),ot(this,q,"LRUCache");const{max:D=0,ttl:N,ttlResolution:H=1,ttlAutopurge:G,updateAgeOnGet:X,updateAgeOnHas:J,allowStale:$,dispose:tt,onInsert:st,disposeAfter:rt,noDisposeOnSet:nt,noUpdateTTL:at,maxSize:ut=0,maxEntrySize:pt=0,sizeCalculation:ft,fetchMethod:mt,memoMethod:_t,noDeleteOnFetchRejection:bt,noDeleteOnStaleGet:gt,allowStaleOnFetchRejection:yt,allowStaleOnFetchAbort:xt,ignoreFetchAbort:wt}=e;if(0!==D&&!ju(D))throw new TypeError("max option must be a nonnegative integer");const vt=D?Xu(D):Array;if(!vt)throw new Error("invalid max value: "+D);if(ct(this,s,D),ct(this,i,ut),this.maxEntrySize=pt||ht(this,i),this.sizeCalculation=ft,this.sizeCalculation){if(!ht(this,i)&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==_t&&"function"!=typeof _t)throw new TypeError("memoMethod must be a function if defined");if(ct(this,h,_t),void 0!==mt&&"function"!=typeof mt)throw new TypeError("fetchMethod must be a function if specified");if(ct(this,a,mt),ct(this,M,!!mt),ct(this,u,new Map),ct(this,d,new Array(D).fill(void 0)),ct(this,p,new Array(D).fill(void 0)),ct(this,f,new vt(D)),ct(this,m,new vt(D)),ct(this,_,0),ct(this,b,0),ct(this,g,Qu.create(D)),ct(this,l,0),ct(this,c,0),"function"==typeof tt&&ct(this,r,tt),"function"==typeof st&&ct(this,n,st),"function"==typeof rt?(ct(this,o,rt),ct(this,y,[])):(ct(this,o,void 0),ct(this,y,void 0)),ct(this,S,!!ht(this,r)),ct(this,I,!!ht(this,n)),ct(this,A,!!ht(this,o)),this.noDisposeOnSet=!!nt,this.noUpdateTTL=!!at,this.noDeleteOnFetchRejection=!!bt,this.allowStaleOnFetchRejection=!!yt,this.allowStaleOnFetchAbort=!!xt,this.ignoreFetchAbort=!!wt,0!==this.maxEntrySize){if(0!==ht(this,i)&&!ju(ht(this,i)))throw new TypeError("maxSize must be a positive integer if specified");if(!ju(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");dt(this,F,R).call(this)}if(this.allowStale=!!$,this.noDeleteOnStaleGet=!!gt,this.updateAgeOnGet=!!X,this.updateAgeOnHas=!!J,this.ttlResolution=ju(H)||0===H?H:1,this.ttlAutopurge=!!G,this.ttl=N||0,this.ttl){if(!ju(this.ttl))throw new TypeError("ttl must be a positive integer if specified");dt(this,C,z).call(this)}if(0===ht(this,s)&&0===this.ttl&&0===ht(this,i))throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!ht(this,s)&&!ht(this,i)){const e="LRU_CACHE_UNBOUNDED";if((t=>!Wu.has(t))(e)){Wu.add(e);qu("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",e,t)}}}static unsafeExposeInternals(t){return{starts:ht(t,w),ttls:ht(t,v),sizes:ht(t,x),keyMap:ht(t,u),keyList:ht(t,d),valList:ht(t,p),next:ht(t,f),prev:ht(t,m),get head(){return ht(t,_)},get tail(){return ht(t,b)},free:ht(t,g),isBackgroundFetch:e=>{var s;return dt(s=t,Y,J).call(s,e)},backgroundFetch:(e,s,i,r)=>{var n;return dt(n=t,j,X).call(n,e,s,i,r)},moveToTail:e=>{var s;return dt(s=t,K,tt).call(s,e)},indexes:e=>{var s;return dt(s=t,O,D).call(s,e)},rindexes:e=>{var s;return dt(s=t,U,N).call(s,e)},isStale:e=>{var s;return ht(s=t,E).call(s,e)}}}get max(){return ht(this,s)}get maxSize(){return ht(this,i)}get calculatedSize(){return ht(this,c)}get size(){return ht(this,l)}get fetchMethod(){return ht(this,a)}get memoMethod(){return ht(this,h)}get dispose(){return ht(this,r)}get onInsert(){return ht(this,n)}get disposeAfter(){return ht(this,o)}getRemainingTTL(t){return ht(this,u).has(t)?1/0:0}*entries(){for(const t of dt(this,O,D).call(this))void 0===ht(this,p)[t]||void 0===ht(this,d)[t]||dt(this,Y,J).call(this,ht(this,p)[t])||(yield[ht(this,d)[t],ht(this,p)[t]])}*rentries(){for(const t of dt(this,U,N).call(this))void 0===ht(this,p)[t]||void 0===ht(this,d)[t]||dt(this,Y,J).call(this,ht(this,p)[t])||(yield[ht(this,d)[t],ht(this,p)[t]])}*keys(){for(const t of dt(this,O,D).call(this)){const e=ht(this,d)[t];void 0===e||dt(this,Y,J).call(this,ht(this,p)[t])||(yield e)}}*rkeys(){for(const t of dt(this,U,N).call(this)){const e=ht(this,d)[t];void 0===e||dt(this,Y,J).call(this,ht(this,p)[t])||(yield e)}}*values(){for(const t of dt(this,O,D).call(this)){void 0===ht(this,p)[t]||dt(this,Y,J).call(this,ht(this,p)[t])||(yield ht(this,p)[t])}}*rvalues(){for(const t of dt(this,U,N).call(this)){void 0===ht(this,p)[t]||dt(this,Y,J).call(this,ht(this,p)[t])||(yield ht(this,p)[t])}}[Symbol.iterator](){return this.entries()}find(t,e={}){for(const s of dt(this,O,D).call(this)){const i=ht(this,p)[s],r=dt(this,Y,J).call(this,i)?i.__staleWhileFetching:i;if(void 0!==r&&t(r,ht(this,d)[s],this))return this.get(ht(this,d)[s],e)}}forEach(t,e=this){for(const s of dt(this,O,D).call(this)){const i=ht(this,p)[s],r=dt(this,Y,J).call(this,i)?i.__staleWhileFetching:i;void 0!==r&&t.call(e,r,ht(this,d)[s],this)}}rforEach(t,e=this){for(const s of dt(this,U,N).call(this)){const i=ht(this,p)[s],r=dt(this,Y,J).call(this,i)?i.__staleWhileFetching:i;void 0!==r&&t.call(e,r,ht(this,d)[s],this)}}purgeStale(){let t=!1;for(const e of dt(this,U,N).call(this,{allowStale:!0}))ht(this,E).call(this,e)&&(dt(this,et,st).call(this,ht(this,d)[e],"expire"),t=!0);return t}info(t){const e=ht(this,u).get(t);if(void 0===e)return;const s=ht(this,p)[e],i=dt(this,Y,J).call(this,s)?s.__staleWhileFetching:s;if(void 0===i)return;const r={value:i};if(ht(this,v)&&ht(this,w)){const t=ht(this,v)[e],s=ht(this,w)[e];if(t&&s){const e=t-(Nu.now()-s);r.ttl=e,r.start=Date.now()}}return ht(this,x)&&(r.size=ht(this,x)[e]),r}dump(){const t=[];for(const e of dt(this,O,D).call(this,{allowStale:!0})){const s=ht(this,d)[e],i=ht(this,p)[e],r=dt(this,Y,J).call(this,i)?i.__staleWhileFetching:i;if(void 0===r||void 0===s)continue;const n={value:r};if(ht(this,v)&&ht(this,w)){n.ttl=ht(this,v)[e];const t=Nu.now()-ht(this,w)[e];n.start=Math.floor(Date.now()-t)}ht(this,x)&&(n.size=ht(this,x)[e]),t.unshift([s,n])}return t}load(t){this.clear();for(const[e,s]of t){if(s.start){const t=Date.now()-s.start;s.start=Nu.now()-t}this.set(e,s.value,s)}}set(t,e,i={}){var a,h,c,_,x,w,T;if(void 0===e)return this.delete(t),this;const{ttl:E=this.ttl,start:F,noDisposeOnSet:R=this.noDisposeOnSet,sizeCalculation:O=this.sizeCalculation,status:D}=i;let{noUpdateTTL:U=this.noUpdateTTL}=i;const N=ht(this,L).call(this,t,e,i.size||0,O);if(this.maxEntrySize&&N>this.maxEntrySize)return D&&(D.set="miss",D.maxEntrySizeExceeded=!0),dt(this,et,st).call(this,t,"set"),this;let W=0===ht(this,l)?void 0:ht(this,u).get(t);if(void 0===W)W=0===ht(this,l)?ht(this,b):0!==ht(this,g).length?ht(this,g).pop():ht(this,l)===ht(this,s)?dt(this,Z,G).call(this,!1):ht(this,l),ht(this,d)[W]=t,ht(this,p)[W]=e,ht(this,u).set(t,W),ht(this,f)[ht(this,b)]=W,ht(this,m)[W]=ht(this,b),ct(this,b,W),ut(this,l)._++,ht(this,V).call(this,W,N,D),D&&(D.set="add"),U=!1,ht(this,I)&&(null==(a=ht(this,n))||a.call(this,e,t,"add"));else{dt(this,K,tt).call(this,W);const s=ht(this,p)[W];if(e!==s){if(ht(this,M)&&dt(this,Y,J).call(this,s)){s.__abortController.abort(new Error("replaced"));const{__staleWhileFetching:e}=s;void 0===e||R||(ht(this,S)&&(null==(h=ht(this,r))||h.call(this,e,t,"set")),ht(this,A)&&(null==(c=ht(this,y))||c.push([e,t,"set"])))}else R||(ht(this,S)&&(null==(_=ht(this,r))||_.call(this,s,t,"set")),ht(this,A)&&(null==(x=ht(this,y))||x.push([s,t,"set"])));if(ht(this,k).call(this,W),ht(this,V).call(this,W,N,D),ht(this,p)[W]=e,D){D.set="replace";const t=s&&dt(this,Y,J).call(this,s)?s.__staleWhileFetching:s;void 0!==t&&(D.oldValue=t)}}else D&&(D.set="update");ht(this,I)&&(null==(w=this.onInsert)||w.call(this,e,t,e===s?"update":"replace"))}if(0===E||ht(this,v)||dt(this,C,z).call(this),ht(this,v)&&(U||ht(this,B).call(this,W,E,F),D&&ht(this,P).call(this,D,W)),!R&&ht(this,A)&&ht(this,y)){const t=ht(this,y);let e;for(;e=null==t?void 0:t.shift();)null==(T=ht(this,o))||T.call(this,...e)}return this}pop(){var t;try{for(;ht(this,l);){const t=ht(this,p)[ht(this,_)];if(dt(this,Z,G).call(this,!0),dt(this,Y,J).call(this,t)){if(t.__staleWhileFetching)return t.__staleWhileFetching}else if(void 0!==t)return t}}finally{if(ht(this,A)&&ht(this,y)){const e=ht(this,y);let s;for(;s=null==e?void 0:e.shift();)null==(t=ht(this,o))||t.call(this,...s)}}}has(t,e={}){const{updateAgeOnHas:s=this.updateAgeOnHas,status:i}=e,r=ht(this,u).get(t);if(void 0!==r){const t=ht(this,p)[r];if(dt(this,Y,J).call(this,t)&&void 0===t.__staleWhileFetching)return!1;if(!ht(this,E).call(this,r))return s&&ht(this,T).call(this,r),i&&(i.has="hit",ht(this,P).call(this,i,r)),!0;i&&(i.has="stale",ht(this,P).call(this,i,r))}else i&&(i.has="miss");return!1}peek(t,e={}){const{allowStale:s=this.allowStale}=e,i=ht(this,u).get(t);if(void 0===i||!s&&ht(this,E).call(this,i))return;const r=ht(this,p)[i];return dt(this,Y,J).call(this,r)?r.__staleWhileFetching:r}async fetch(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,ttl:n=this.ttl,noDisposeOnSet:o=this.noDisposeOnSet,size:a=0,sizeCalculation:h=this.sizeCalculation,noUpdateTTL:l=this.noUpdateTTL,noDeleteOnFetchRejection:c=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:d=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:m=this.allowStaleOnFetchAbort,context:_,forceRefresh:b=!1,status:g,signal:y}=e;if(!ht(this,M))return g&&(g.fetch="get"),this.get(t,{allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:r,status:g});const x={allowStale:s,updateAgeOnGet:i,noDeleteOnStaleGet:r,ttl:n,noDisposeOnSet:o,size:a,sizeCalculation:h,noUpdateTTL:l,noDeleteOnFetchRejection:c,allowStaleOnFetchRejection:d,allowStaleOnFetchAbort:m,ignoreFetchAbort:f,status:g,signal:y};let w=ht(this,u).get(t);if(void 0===w){g&&(g.fetch="miss");const e=dt(this,j,X).call(this,t,w,x,_);return e.__returned=e}{const e=ht(this,p)[w];if(dt(this,Y,J).call(this,e)){const t=s&&void 0!==e.__staleWhileFetching;return g&&(g.fetch="inflight",t&&(g.returnedStale=!0)),t?e.__staleWhileFetching:e.__returned=e}const r=ht(this,E).call(this,w);if(!b&&!r)return g&&(g.fetch="hit"),dt(this,K,tt).call(this,w),i&&ht(this,T).call(this,w),g&&ht(this,P).call(this,g,w),e;const n=dt(this,j,X).call(this,t,w,x,_),o=void 0!==n.__staleWhileFetching&&s;return g&&(g.fetch=r?"stale":"refresh",o&&r&&(g.returnedStale=!0)),o?n.__staleWhileFetching:n.__returned=n}}async forceFetch(t,e={}){const s=await this.fetch(t,e);if(void 0===s)throw new Error("fetch() returned undefined");return s}memo(t,e={}){const s=ht(this,h);if(!s)throw new Error("no memoMethod provided to constructor");const{context:i,forceRefresh:r,...n}=e,o=this.get(t,n);if(!r&&void 0!==o)return o;const a=s(t,o,{options:n,context:i});return this.set(t,a,n),a}get(t,e={}){const{allowStale:s=this.allowStale,updateAgeOnGet:i=this.updateAgeOnGet,noDeleteOnStaleGet:r=this.noDeleteOnStaleGet,status:n}=e,o=ht(this,u).get(t);if(void 0!==o){const e=ht(this,p)[o],a=dt(this,Y,J).call(this,e);return n&&ht(this,P).call(this,n,o),ht(this,E).call(this,o)?(n&&(n.get="stale"),a?(n&&s&&void 0!==e.__staleWhileFetching&&(n.returnedStale=!0),s?e.__staleWhileFetching:void 0):(r||dt(this,et,st).call(this,t,"expire"),n&&s&&(n.returnedStale=!0),s?e:void 0)):(n&&(n.get="hit"),a?e.__staleWhileFetching:(dt(this,K,tt).call(this,o),i&&ht(this,T).call(this,o),e))}n&&(n.get="miss")}delete(t){return dt(this,et,st).call(this,t,"delete")}clear(){return dt(this,it,rt).call(this,"delete")}};q=Symbol.toStringTag,s=new WeakMap,i=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,a=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,m=new WeakMap,_=new WeakMap,b=new WeakMap,g=new WeakMap,y=new WeakMap,x=new WeakMap,w=new WeakMap,v=new WeakMap,S=new WeakMap,M=new WeakMap,A=new WeakMap,I=new WeakMap,C=new WeakSet,z=function(){const t=new Yu(ht(this,s)),e=new Yu(ht(this,s));ct(this,v,t),ct(this,w,e),ct(this,B,((s,i,r=Nu.now())=>{if(e[s]=0!==i?r:0,t[s]=i,0!==i&&this.ttlAutopurge){const t=setTimeout((()=>{ht(this,E).call(this,s)&&dt(this,et,st).call(this,ht(this,d)[s],"expire")}),i+1);t.unref&&t.unref()}})),ct(this,T,(s=>{e[s]=0!==t[s]?Nu.now():0})),ct(this,P,((s,n)=>{if(t[n]){const o=t[n],a=e[n];if(!o||!a)return;s.ttl=o,s.start=a,s.now=i||r();const h=s.now-a;s.remainingTTL=o-h}}));let i=0;const r=()=>{const t=Nu.now();if(this.ttlResolution>0){i=t;const e=setTimeout((()=>i=0),this.ttlResolution);e.unref&&e.unref()}return t};this.getRemainingTTL=s=>{const n=ht(this,u).get(s);if(void 0===n)return 0;const o=t[n],a=e[n];if(!o||!a)return 1/0;return o-((i||r())-a)},ct(this,E,(s=>{const n=e[s],o=t[s];return!!o&&!!n&&(i||r())-n>o}))},T=new WeakMap,P=new WeakMap,B=new WeakMap,E=new WeakMap,F=new WeakSet,R=function(){const t=new Yu(ht(this,s));ct(this,c,0),ct(this,x,t),ct(this,k,(e=>{ct(this,c,ht(this,c)-t[e]),t[e]=0})),ct(this,L,((t,e,s,i)=>{if(dt(this,Y,J).call(this,e))return 0;if(!ju(s)){if(!i)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof i)throw new TypeError("sizeCalculation must be a function");if(s=i(e,t),!ju(s))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return s})),ct(this,V,((e,s,r)=>{if(t[e]=s,ht(this,i)){const s=ht(this,i)-t[e];for(;ht(this,c)>s;)dt(this,Z,G).call(this,!0)}ct(this,c,ht(this,c)+t[e]),r&&(r.entrySize=s,r.totalCalculatedSize=ht(this,c))}))},k=new WeakMap,V=new WeakMap,L=new WeakMap,O=new WeakSet,D=function*({allowStale:t=this.allowStale}={}){if(ht(this,l))for(let e=ht(this,b);dt(this,W,H).call(this,e)&&(!t&&ht(this,E).call(this,e)||(yield e),e!==ht(this,_));)e=ht(this,m)[e]},U=new WeakSet,N=function*({allowStale:t=this.allowStale}={}){if(ht(this,l))for(let e=ht(this,_);dt(this,W,H).call(this,e)&&(!t&&ht(this,E).call(this,e)||(yield e),e!==ht(this,b));)e=ht(this,f)[e]},W=new WeakSet,H=function(t){return void 0!==t&&ht(this,u).get(ht(this,d)[t])===t},Z=new WeakSet,G=function(t){var e,s;const i=ht(this,_),n=ht(this,d)[i],o=ht(this,p)[i];return ht(this,M)&&dt(this,Y,J).call(this,o)?o.__abortController.abort(new Error("evicted")):(ht(this,S)||ht(this,A))&&(ht(this,S)&&(null==(e=ht(this,r))||e.call(this,o,n,"evict")),ht(this,A)&&(null==(s=ht(this,y))||s.push([o,n,"evict"]))),ht(this,k).call(this,i),t&&(ht(this,d)[i]=void 0,ht(this,p)[i]=void 0,ht(this,g).push(i)),1===ht(this,l)?(ct(this,_,ct(this,b,0)),ht(this,g).length=0):ct(this,_,ht(this,f)[i]),ht(this,u).delete(n),ut(this,l)._--,i},j=new WeakSet,X=function(t,e,s,i){const r=void 0===e?void 0:ht(this,p)[e];if(dt(this,Y,J).call(this,r))return r;const n=new Zu,{signal:o}=s;null==o||o.addEventListener("abort",(()=>n.abort(o.reason)),{signal:n.signal});const h={signal:n.signal,options:s,context:i},l=(i,r=!1)=>{const{aborted:o}=n.signal,a=s.ignoreFetchAbort&&void 0!==i;if(s.status&&(o&&!r?(s.status.fetchAborted=!0,s.status.fetchError=n.signal.reason,a&&(s.status.fetchAbortIgnored=!0)):s.status.fetchResolved=!0),o&&!a&&!r)return c(n.signal.reason);const l=d;return ht(this,p)[e]===d&&(void 0===i?l.__staleWhileFetching?ht(this,p)[e]=l.__staleWhileFetching:dt(this,et,st).call(this,t,"fetch"):(s.status&&(s.status.fetchUpdated=!0),this.set(t,i,h.options))),i},c=i=>{const{aborted:r}=n.signal,o=r&&s.allowStaleOnFetchAbort,a=o||s.allowStaleOnFetchRejection,h=a||s.noDeleteOnFetchRejection,l=d;if(ht(this,p)[e]===d){!h||void 0===l.__staleWhileFetching?dt(this,et,st).call(this,t,"fetch"):o||(ht(this,p)[e]=l.__staleWhileFetching)}if(a)return s.status&&void 0!==l.__staleWhileFetching&&(s.status.returnedStale=!0),l.__staleWhileFetching;if(l.__returned===l)throw i};s.status&&(s.status.fetchDispatched=!0);const d=new Promise(((e,i)=>{var o;const c=null==(o=ht(this,a))?void 0:o.call(this,t,r,h);c&&c instanceof Promise&&c.then((t=>e(void 0===t?void 0:t)),i),n.signal.addEventListener("abort",(()=>{s.ignoreFetchAbort&&!s.allowStaleOnFetchAbort||(e(void 0),s.allowStaleOnFetchAbort&&(e=t=>l(t,!0)))}))})).then(l,(t=>(s.status&&(s.status.fetchRejected=!0,s.status.fetchError=t),c(t)))),f=Object.assign(d,{__abortController:n,__staleWhileFetching:r,__returned:void 0});return void 0===e?(this.set(t,f,{...h.options,status:void 0}),e=ht(this,u).get(t)):ht(this,p)[e]=f,f},Y=new WeakSet,J=function(t){if(!ht(this,M))return!1;const e=t;return!!e&&e instanceof Promise&&e.hasOwnProperty("__staleWhileFetching")&&e.__abortController instanceof Zu},Q=new WeakSet,$=function(t,e){ht(this,m)[e]=t,ht(this,f)[t]=e},K=new WeakSet,tt=function(t){t!==ht(this,b)&&(t===ht(this,_)?ct(this,_,ht(this,f)[t]):dt(this,Q,$).call(this,ht(this,m)[t],ht(this,f)[t]),dt(this,Q,$).call(this,ht(this,b),t),ct(this,b,t))},et=new WeakSet,st=function(t,e){var s,i,n,a;let h=!1;if(0!==ht(this,l)){const n=ht(this,u).get(t);if(void 0!==n)if(h=!0,1===ht(this,l))dt(this,it,rt).call(this,e);else{ht(this,k).call(this,n);const o=ht(this,p)[n];if(dt(this,Y,J).call(this,o)?o.__abortController.abort(new Error("deleted")):(ht(this,S)||ht(this,A))&&(ht(this,S)&&(null==(s=ht(this,r))||s.call(this,o,t,e)),ht(this,A)&&(null==(i=ht(this,y))||i.push([o,t,e]))),ht(this,u).delete(t),ht(this,d)[n]=void 0,ht(this,p)[n]=void 0,n===ht(this,b))ct(this,b,ht(this,m)[n]);else if(n===ht(this,_))ct(this,_,ht(this,f)[n]);else{const t=ht(this,m)[n];ht(this,f)[t]=ht(this,f)[n];const e=ht(this,f)[n];ht(this,m)[e]=ht(this,m)[n]}ut(this,l)._--,ht(this,g).push(n)}}if(ht(this,A)&&(null==(n=ht(this,y))?void 0:n.length)){const t=ht(this,y);let e;for(;e=null==t?void 0:t.shift();)null==(a=ht(this,o))||a.call(this,...e)}return h},it=new WeakSet,rt=function(t){var e,s,i;for(const i of dt(this,U,N).call(this,{allowStale:!0})){const n=ht(this,p)[i];if(dt(this,Y,J).call(this,n))n.__abortController.abort(new Error("deleted"));else{const o=ht(this,d)[i];ht(this,S)&&(null==(e=ht(this,r))||e.call(this,n,o,t)),ht(this,A)&&(null==(s=ht(this,y))||s.push([n,o,t]))}}if(ht(this,u).clear(),ht(this,p).fill(void 0),ht(this,d).fill(void 0),ht(this,v)&&ht(this,w)&&(ht(this,v).fill(0),ht(this,w).fill(0)),ht(this,x)&&ht(this,x).fill(0),ct(this,_,0),ct(this,b,0),ht(this,g).length=0,ct(this,c,0),ct(this,l,0),ht(this,A)&&ht(this,y)){const t=ht(this,y);let e;for(;e=null==t?void 0:t.shift();)null==(i=ht(this,o))||i.call(this,...e)}};let Ku=$u;const td=class{static get(t){return this._meshes.get(t)}static lockIn(t){Object.seal(t)}static add(t,e){this._meshes.set(t,e)}static delete(t){for(const e of t)this._meshes.delete(e)}static setCapacity(t){t!==this._capacity&&(this._meshes.clear(),this._meshes=this.setupMeshes(t),this._capacity=t)}static setupMeshes(t){const e=Math.max(t??this.computeCapacity(),1),s=this.getSizeCalculationEvent();return new Ku({maxSize:e,sizeCalculation:s})}static computeCapacity(){const t=globalThis.navigator&&"deviceMemory"in globalThis.navigator?globalThis.navigator.deviceMemory:null,e=null!==t?t:2,s=this.oneHundredMb*e;return Math.trunc(s)}static getDataSetMemory(t){let e=0;for(const s of t)e+=s.usedMemory;return Math.max(e,1)}static getSizeCalculationEvent(){return t=>Array.isArray(t)?this.getDataSetMemory(t):Math.max(t.usedMemory,1)}};ot(td,"oneHundredMb",1e8),ot(td,"_meshes",td.setupMeshes()),ot(td,"_capacity"),ot(td,"_memoryAttributes",["positionBuffer","indexBuffer","normalBuffer"]),ot(td,"updateMeshMemory",(t=>{t.usedMemory=0;for(const e of td._memoryAttributes)void 0!==t.usedMemory&&t[e]&&(t.usedMemory+=t[e].byteLength);td.lockIn(t)}));let ed=td;const sd=class t{constructor(t){ot(this,"meshes"),ot(this,"tilesUpdated",!1),ot(this,"_sampleAmount"),ot(this,"_tileDimension"),ot(this,"_tileBySample"),ot(this,"_lodBySample"),ot(this,"_virtualMeshes",new Map),ot(this,"_meshConnection"),ot(this,"_samples"),ot(this,"_tileIdGenerator",new Pc),ot(this,"_tiles",new Map),ot(this,"_tilesChanged",new Set),ot(this,"_sizeByTile",new Map),ot(this,"_samplesDimensions"),ot(this,"_sampleLodClass"),ot(this,"_sampleLodState"),ot(this,"_sampleLodSize"),ot(this,"_boxes"),ot(this,"_items"),ot(this,"_materials"),ot(this,"_modelId"),ot(this,"_lastView",{rotation:new Xt,location:new Xt}),ot(this,"_params",{updateTime:16,updateSamples:64,updateviewOrientation:8*Math.PI/180,updateViewPosition:256,smallTileSize:.32,mediumTileSize:4,smallObjectSize:2,smallScreenSize:2,mediumScreenSize:4,largeScreenSize:16,tempTileDataSize:6,tileIdIncrement:1,tileSizeMultiplier:10,minTileDimension:32,tileDimensionFactor:8}),ot(this,"_temp",{sample:new _c,representation:new mc,vector:new Xt,matrix:new Me,transform:new Me,boundingBox:new Qt,sampleGeometry:{},box:new Qt,raycastPoints:[],tileData:{positionCount:this._params.tempTileDataSize,objectClass:_i.LINE,positionBuffer:new Float32Array(this._params.tempTileDataSize)},tileCenter:new Xt,tile:{objectClass:_i.LINE,positionCount:6},viewDimension:0,pastFieldOfview:0}),ot(this,"_currentSample",0),ot(this,"_virtualPlanes",[]),ot(this,"_changedSamples",0),ot(this,"_virtualView"),this._modelId=t.modelId,this._boxes=t.boxes,this._items=t.items,this._materials=t.materials,this._meshConnection=new Du(t.modelId,t.connection),this.meshes=t.model.meshes(),this._sampleAmount=this.meshes.samplesLength(),this._samples=new Ou(this._sampleAmount),this._samplesDimensions=new Int32Array(this._sampleAmount),this._sampleLodClass=new Uint8Array(this._sampleAmount),this._sampleLodState=new Uint8Array(this._sampleAmount),this._sampleLodSize=new Float32Array(this._sampleAmount),this._tileDimension=this.computeTileSize(),this._tileBySample=new Array(this._sampleAmount),this._lodBySample=new Array(this._sampleAmount),this.init()}restart(){this.resetUpdateProcess(),this._meshConnection.clean()}fetchSample(t,e){this.fetchSampleAndRepresentation(t);const s=this.fetchCurrentMesh(),i=this.sampleTemplate(t);return i.geometries=this.sampleGeoms(i,e,s),i}dispose(){this._meshConnection.dispose();for(const[,t]of this._virtualMeshes)t.dispose()}generate(){for(const[,t]of this._virtualMeshes)t.setupTemplates();for(let t=0;t<this._sampleAmount;t++)this.generateSampleInTiles(t);this.setupTileVisibilityAndHighlight()}setupView(t){this._virtualView=t,ed.setCapacity(t.meshThreshold),this.restart(),this.updateOrientationIfNeeded(),this.updatePositionIfNeeded(),this.setupViewPlanes()}updateVirtualMeshes(t){if(t&&this._virtualView){for(const e of t)this.updateItem(e);this.restart()}}getSampleTransform(t){this.fetchSampleAndRepresentation(t);return this.sampleTemplate(t).transform}async update(t){this.updateTiles(t),this.notifyUpdateFinished();for(const t of this._tilesChanged){const e=this._tiles.get(t);this._meshConnection.process({tileRequestClass:bi.UPDATE,modelId:this._modelId,tileId:t,objectClass:e.objectClass,material:e.materialId,tileData:this.getTileData(e),currentLod:e.lod})}this._tilesChanged.clear()}raycast(t,e,s,i){this._temp.raycastPoints=[];const r=t.representationClass(),n=this._virtualMeshes.get(r);return this.manageRaycast(n,t,e,s,i),this._temp.raycastPoints}init(){const t=new zu(this._modelId,this.meshes),e=t.getRepresentation();this._virtualMeshes.set(e,t);const s=new Lu(this._modelId,this.meshes),i=s.getRepresentation();this._virtualMeshes.set(i,s),this.processSamplesDimension(),this.fetchSampleLodSize()}initSampleLod(t){this.fetchSampleAndRepresentation(t);const e=this.fetchCurrentMesh();this._sampleLodClass[t]=e.getLodClass(),this._sampleLodState[t]=gi.INVISIBLE}fetchSampleAndRepresentation(t){this.meshes.samples(t,this._temp.sample),this.meshes.representations(this._temp.sample.representation(),this._temp.representation)}fetchCurrentMesh(){const t=this._temp.representation.representationClass();return this._virtualMeshes.get(t)}fetchCurrentMaterial(){const t=this._temp.sample.material();return this._materials[t]}fetchSampleLodSize(){for(let t=0;t<this._sampleAmount;t++)this.initSampleLod(t),Lc.getBox(this._temp.representation,this._temp.box),this._sampleLodSize[t]=Oc.getWidth(this._temp.box)}setupTileVisibilityAndHighlight(){for(const[,t]of this._tiles)t.visibilities=new Ec(t.size,!1),t.highlights=new Ec(t.size,0)}addLodToTile(t,e,s){t.getLodClass()!==Wc.AABB?t.getLodClass()===Wc.CUSTOM&&this.addCustomLodToTile(t,e,s):this.addBoxLodToTile(e,s)}addBoxLodToTile(t,e){this._lodBySample[t]=this.lodTileAppendSample(t,e)}notifyUpdateFinished(){const t=!this.tilesUpdated;this._changedSamples>=this._sampleAmount&&t&&(this._meshConnection.process({tileRequestClass:bi.FINISH,modelId:this._modelId}),this.tilesUpdated=!0)}updatePositionIfNeeded(){const t=this._params.updateViewPosition,e=this._virtualView.cameraPosition;e.distanceToSquared(this._lastView.location)>t&&(this._currentSample=0,this._lastView.location.copy(e))}updateCurrentSample(){this._currentSample++,this._currentSample>=this._sampleAmount&&(this._currentSample=0),this._changedSamples++}processSamplesDimension(){for(let t=0;t<this._sampleAmount;t++)this._samplesDimensions[t]=t;this._samplesDimensions.sort(((t,e)=>this._boxes.dimensionOf(e)-this._boxes.dimensionOf(t)))}setupViewPlanes(){this._virtualPlanes=[];for(const t of this._virtualView.cameraFrustum.planes)this._virtualPlanes.push(t);if(this._virtualView.clippingPlanes)for(const t of this._virtualView.clippingPlanes)this._virtualPlanes.push(t)}updateOrientationIfNeeded(){const t=this.getCurrentViewOrientation(),e=this._params.updateviewOrientation;t.angleTo(this._lastView.rotation)>e&&(this._currentSample=0,this._lastView.rotation.copy(t))}getCurrentViewOrientation(){return this._virtualView.cameraFrustum.planes[4].normal}resetUpdateProcess(){this._changedSamples=0,this.tilesUpdated=!1}manageRaycast(t,e,s,i,r){const n=Uu.cast(t,e,s,i,r);if(n)for(const e of n)e.representationClass=t.getObjectClass(),this._temp.raycastPoints.push(e)}setTileShellBuffer(t){void 0!==t.usedMemory&&t.objectClass===_i.SHELL&&(t.ids=new Float32Array(t.positionCount/3),t.usedMemory+=t.ids.byteLength)}getTileWhenSamplePut(t,e,s){let i=this._tiles.get(t);if(void 0===i){const r=e.lod||gi.GEOMETRY;i=this.newTile(e.objectClass,s,r),this._tiles.set(t,i)}return i}getPerspTrueDim(t,e){const s=Math.PI/180;return e*Math.tan(.5*t*s)}getTileHighlight(t,e){let s,i;const r=t.highlights;if(!r)return{highlightData:void 0,highlightIds:void 0};const n=r.size((t=>0!==t));if(n>0){i=new Uint16Array(n);const t=t=>0!==t,o=(t,e)=>i[t]=e;s=Ec.get(r,e,t,o)}return{highlightData:s,highlightIds:i}}setupTileSampleAttributes(t,e,s,i){const r=3*t.vertexLocation[e];for(let e=0;e<s.positionBuffer.length;e+=3)this._temp.vector.fromArray(s.positionBuffer,e),this._temp.vector.applyMatrix4(this._temp.matrix),this._temp.vector.toArray(t.positionBuffer,r+e);if(t.normalBuffer){const i=3*t.vertexLocation[e];for(let e=0;e<s.normalBuffer.length;e+=3)this._temp.vector.fromArray(s.normalBuffer,e),this._temp.vector.transformDirection(this._temp.matrix),this._temp.vector.multiplyScalar(Nc),this._temp.vector.toArray(t.normalBuffer,i+e)}if(t.indexBuffer){const i=t.indexLocation[e],r=t.vertexLocation[e];for(let e=0;e<s.indexCount;e++){const n=s.indexBuffer[e]+r;t.indexBuffer[e+i]=n}}if(t.faceIdBuffer&&s.faceIdBuffer){const r=100*i.sample,n=t.vertexLocation[e],o=n+s.positionCount/3;for(let e=n;e<o;e++)t.faceIdBuffer[e]=s.faceIdBuffer[e-n]+r}if(s.objectClass===_i.SHELL){const r=t.vertexLocation[e],n=r+s.positionCount/3;t.ids.fill(this.itemId(i.sample),r,n)}}getTileVisibility(t,e){if(!t.visibilities)throw new Error("Fragments: Malformed tile!");if(t.visibilities.fullOf(!1))return;return Ec.get(t.visibilities,e,(t=>t))}memoryOverflow(){return t._graphicMemoryConsumed>this._virtualView.graphicThreshold}updateMesh(t){let e=this.fetchLodLevel(t);const s=this._sampleLodState[t];e=this.hideHighlightedLods(e,t),e!==s?this.updateVisible(s,e,t):this.updateSampleIfSeen(e,t)}tileLoadSample(t,e,s){const i=t.sampleLocation.get(e.sample),r=this.getSampleGeometries(e,s);this.setupTileLocation(t,r,e),this.fetchSampleTransform(t,e),this.setupTileSampleAttributes(t,i,r,e)}updateSampleIfSeen(t,e){t!==gi.INVISIBLE&&this.updateSample(e,t)}hideHighlightedLods(t,e){return t===gi.WIRES&&this._samples.getHighlight(e)&&(t=gi.INVISIBLE),t}updateVisible(t,e,s){t!==gi.INVISIBLE&&this.makeSampleInvisible(s,t);const i=e!==gi.INVISIBLE;i&&this.updateSample(s,e),this._samples.setVisible(s,i),this._sampleLodState[s]=e}makeInvisibleFromTile(t,e){const s=this._tiles.get(t);this.updateTileData(s,e,!1,0),this.deleteTileIfNeeded(s,t)}updateSample(t,e){const s=this.itemId(t),i=this._items.visible(s),r=this._items.getHighlight(s);this.hasChanged(t,e,i,r)&&this.setSample(t,i,r,e)}hasHighlightChanged(t,e){return e!==this._samples.getHighlight(t)}hasVisibleChanged(t,e){return e!==this._samples.visible(t)}newTile(t,e,s){const i={notVirtual:!1};return i.materialId=e,i.indexLocation=[],i.box=new Qt,i.objectClass=t,i.lod=s,i.normalCount=0,i.indexCount=0,i.vertexLocation=[],i.size=0,i.geometriesLocation=[],i.positionCount=0,i.sampleLocation=new Map,i.faceIdBuffer=new Uint32Array(0),i}createLod(t){const e=Lc.boxSize(t),s=this._temp.tileData.positionBuffer;if(!s)throw new Error("Fragments: Malformed tiles!");return s[0]=e.start.x,s[1]=e.start.y,s[2]=e.start.z,s[3]=e.end.x,s[4]=e.end.y,s[5]=e.end.z,this._temp.tileData}sampleTemplate(t){const e=this._temp.sample,s=this._temp.representation;Lc.get(e,this.meshes,this._temp.transform),Lc.getBox(s,this._temp.boundingBox),this._temp.sampleGeometry.sample=t;const i=e.material();return this._temp.sampleGeometry.material=this._materials[i],this._temp.sampleGeometry.transform=this._temp.transform,this._temp.sampleGeometry.aabb=this._temp.boundingBox,delete this._temp.sampleGeometry.geometries,this._temp.sampleGeometry}makeSampleInvisible(t,e){const s=this.getTileIds(t,e);if(!s)return;Fc.forEach(s,(e=>this.makeInvisibleFromTile(e,t)))}setSample(t,e,s,i){this._samples.setVisible(t,e),this._samples.setHighlight(t,s);const r=this.getTileIds(t,i);void 0!==r&&Fc.forEach(r,(e=>{this.updateTile(e,t,s,0===s)}))}getTileIds(t,e){return e===gi.GEOMETRY?this._tileBySample[t]:this._lodBySample[t]}addBasicTileData(t,e,s){t.sampleLocation.set(e,t.size),t.size++,t.geometriesLocation.push(s),t.indexLocation.push(t.indexCount||0),t.vertexLocation.push((t.positionCount||0)/3)}buildNewVirtualTile(t,e){this.constructTile(t),this.loadTile(e,t),t.notVirtual=!0,delete t.indexBuffer,delete t.positionBuffer,delete t.normalBuffer,delete t.faceIdBuffer,delete t.ids}deleteTileIfNeeded(e,s){if(this.getShouldDeleteTile(e))return this.deleteGeometry(s),e.notVirtual=!1,void(t._graphicMemoryConsumed-=e.usedMemory);this._tilesChanged.add(s)}getShouldDeleteTile(t){if(!t.visibilities||!t.highlights)throw new Error("Fragments: Malformed tile!");const e=t.visibilities.fullOf(!1),s=t.highlights.fullOf(0),i=this.memoryOverflow();return e&&s&&i}checkTileMemoryOverflow(t,e){const s=this._tiles.get(t);return(s?s.positionCount:0)+e.positionCount>mi}updateTileData(t,e,s,i){if(!t.visibilities||!t.highlights)throw new Error("Fragments: Malformed tile!");const r=t.sampleLocation.get(e);t.visibilities.update(r,s),t.highlights.update(r,i)}getKeepUpdating(t,e){const s=this._params.updateTime,i=this._params.updateSamples,r=t<this._sampleAmount,n=performance.now()-e;return r&&(n<s||t<i)}computeTileSize(){const t=this._boxes.fullBox.getSize(this._temp.vector),e=Math.max(t.x,t.y,t.z)/this._params.tileDimensionFactor,s=Math.ceil(e);return Math.max(this._params.minTileDimension,s)}newTileId(t,e,s){this.logBufferOverflowIfNeeded(s);const i=s.lod||gi.GEOMETRY,r=this.generateTileCode(t,e,s,i),n=this._sizeByTile.get(r)||1;let o=r+n-1;return this.checkTileMemoryOverflow(o,s)&&(o+=this._params.tileIdIncrement,this._sizeByTile.set(r,n+1)),o}logBufferOverflowIfNeeded(t){t.positionCount/3>mi&&console.log("Fragments: Buffer overflow")}fetchLodLevel(t){const e=this._boxes.get(t);if(!wl.collides(e,this._virtualPlanes))return gi.INVISIBLE;this.meshes.samples(t,this._temp.sample);const s=this._temp.sample.item();if(!this._items.visible(s))return gi.INVISIBLE;const i=this._virtualView.graphicQuality,r=this._boxes.dimensionOf(t),n=e.distanceToPoint(this._virtualView.cameraPosition),o=this.screenSize(r,n),a=r<this._params.smallObjectSize,h=!a,l=this._params.smallScreenSize*i,c=this._params.mediumScreenSize*i,u=this._params.largeScreenSize*i,d=o<c,p=a&&o<u,f=h&&d;if(a&&d||h&&o<l)return gi.INVISIBLE;if(p||f)return gi.WIRES;const m=this._sampleLodSize[t];return this.screenSize(m,n)<Math.max(c,this._params.mediumScreenSize)?gi.WIRES:gi.GEOMETRY}generateTileCode(t,e,s,i){this._tileIdGenerator.reset(),this.processTileDataId(s,e,i);const r=this.processTileSpatialId(t,i);return this.processTileDimensionId(r),this._tileIdGenerator.value}processTileDataId(t,e,s){this._tileIdGenerator.compute(void 0!==t.objectClass?t.objectClass:0),this._tileIdGenerator.compute(e),this._tileIdGenerator.compute(s)}deleteGeometry(t){this._meshConnection.process({tileRequestClass:bi.DELETE,modelId:this._modelId,tileId:t})}processTileSpatialId(t,e){const s=this._temp.tileCenter.x,i=this._temp.tileCenter.y,r=this._temp.tileCenter.z,n=this._boxes.get(t);n.getCenter(this._temp.tileCenter);const o=this.getTileDimension(e),a=s-s%o,h=i-i%o,l=r-r%o;return this._tileIdGenerator.compute(a),this._tileIdGenerator.compute(h),this._tileIdGenerator.compute(l),n}addCustomLodToTile(t,e,s){const i=this.meshData(t,!1,gi.WIRES);this._sampleLodSize[e]=i.lodThickness||0,this._lodBySample[e]=this.putSampleInTiles(e,s,i)}getTileLocations(t){return t.indexCount?t.indexLocation:t.vertexLocation}getTileDimension(t){let e=this._tileDimension;return t===gi.GEOMETRY&&(e*=this._params.tileSizeMultiplier),e}processTileDimensionId(t){const e=this.getTileDimensionClass(t);this._tileIdGenerator.compute(e)}tileAppend(t,e,s,i){this.addBasicTileData(t,s,i),this.tileAppendAttribute(t,e,"indexCount",!1),this.tileAppendAttribute(t,e,"positionCount",!1),this.tileAppendAttribute(t,e,"normalCount",!1),this.tileAppendAttribute(t,e,"materialId",!0)}putSampleInTiles(t,e,s){let i;return Fc.forEach(s,((s,r)=>{const n=this.newTileId(t,e,s);i=this.getTileIdsWhenSamplePut(i,n);const o=this.getTileWhenSamplePut(n,s,e);this.tileAppend(o,s,t,r)})),i}hasLodChanged(t,e){return e!==this._sampleLodState[t]}getTileIdsWhenSamplePut(t,e){return void 0===t?t=e:"number"==typeof t?t!==e&&(t=[t,e]):t.includes(e)||t.push(e),t}updateTile(t,e,s,i){const r=this._tiles.get(t);this.updateTileData(r,e,i,s),r.notVirtual?this._tilesChanged.add(t):this.buildNewVirtualTile(r,t)}getLodTileWhenPutSample(t,e){let s=this._tiles.get(t);if(!s){const i=this._temp.tile.objectClass;s=this.newTile(i,e,gi.WIRES),this._tiles.set(t,s)}return s}lodTileAppendSample(t,e){const s=gi.WIRES,i=this._temp.tile,r=this.generateTileCode(t,e,i,s),n=this.getLodTileWhenPutSample(r,e);return this.tileAppend(n,i,t,0),r}addSampleToTile(t,e,s){const i=this.meshData(t,!1,gi.GEOMETRY);this._tileBySample[e]=this.putSampleInTiles(e,s,i)}setTileBuffer(t,e,s){if(void 0===t.usedMemory)return;const i=t[`${e}Count`];if(i>0){const r=s?new Uint16Array(i):new Int16Array(i);t[`${e}Buffer`]=r,t.usedMemory+=r.byteLength}}updateTiles(t){const e=this._changedSamples<this._sampleAmount;if(!(void 0!==this._virtualView)||!e)return;let s=!0,i=0;for(;s;){const e=this._samplesDimensions[this._currentSample];this.updateMesh(e),this.updateCurrentSample(),i++,s=this.getKeepUpdating(i,t)}}sampleGeoms(t,e,s){return s.getLodClass()===Wc.AABB&&e===gi.WIRES?this.createLod(t.aabb):this.meshData(s,!0,e)}generateSampleInTiles(t){this.fetchSampleAndRepresentation(t);const e=this.fetchCurrentMaterial(),s=this.fetchCurrentMesh();this.addSampleToTile(s,t,e),this.addLodToTile(s,t,e)}buildSampleInTile(t,e,s,i,r){const n=t.geometriesLocation[e];if(this.tileLoadSample(t,s,n),i){const e=this._boxes.get(r);this._temp.vector.copy(t.location),this._temp.vector.negate(),e.translate(this._temp.vector),t.box.union(e)}}getSampleGeometries(t,e){return Array.isArray(t.geometries)?t.geometries[e]:t.geometries}constructTile(t){void 0===t.positionBuffer&&(t.positionBuffer=new Float32Array(t.positionCount),t.usedMemory=t.positionBuffer.byteLength,this.setTileBuffer(t,"index",!0),this.setTileBuffer(t,"normal",!1),this.setTileShellBuffer(t),t.faceIdBuffer=new Uint32Array(t.positionCount/3),t.usedMemory+=t.faceIdBuffer.byteLength);const e=!t.location;for(const[s,i]of t.sampleLocation){const r=this.fetchSample(s,t.lod);r&&r.geometries&&this.buildSampleInTile(t,i,r,e,s)}}fetchSampleTransform(t,e){this._temp.vector.copy(t.location),this._temp.vector.negate(),this._temp.matrix.identity(),this._temp.matrix.setPosition(this._temp.vector),this._temp.matrix.multiply(e.transform)}hasChanged(t,e,s,i){const r=this.hasLodChanged(t,e),n=this.hasVisibleChanged(t,s),o=this.hasHighlightChanged(t,i);return r||n||o}setupTileLocation(t,e,s){if(t.location)return;const i=new Xt;i.fromArray(e.positionBuffer),i.applyMatrix4(s.transform),t.location=i}getTileData(t){const e=this.getTileLocations(t),s=this.getTileVisibility(t,e),i=this.getTileHighlight(t,e),{highlightData:r,highlightIds:n}=i;return{visibilityData:s,highlightData:r,highlightIds:n}}updateMemoryOnTileLoad(e){t._graphicMemoryConsumed+=e.usedMemory}fetchTileMatrixOnLoad(t){t.location&&(this._temp.matrix.identity(),this._temp.matrix.setPosition(t.location))}updateItem(t){const e=this._boxes.sampleOf(t);if(e)for(const t of e)this.updateMesh(t)}screenSize(t,e){return t/this.getViewDimension(e)*this._virtualView.viewSize}getTileDimensionClass(t){const e=t.min.distanceToSquared(t.max),s=this._params.smallTileSize;return e>this._params.mediumTileSize?2:e>s?1:0}getViewDimension(t){if(this._virtualView.orthogonalDimension)return this._virtualView.orthogonalDimension;const e=this._virtualView.fov;return e!==this._temp.pastFieldOfview&&(this._temp.viewDimension=this.getPerspTrueDim(e,1),this._temp.pastFieldOfview=e),t*this._temp.viewDimension}loadTile(t,e){const s=this.getTileData(e);this.fetchTileMatrixOnLoad(e);const i=this.getFaceIds(e);this._meshConnection.process({tileRequestClass:bi.CREATE,modelId:this._modelId,objectClass:e.objectClass,tileId:t,itemId:void 0,tileData:s,indices:e.indexBuffer,positions:e.positionBuffer,normals:e.normalBuffer,faceIds:i,itemIds:e.ids,material:e.materialId,matrix:this._temp.matrix.clone(),aabb:e.box.clone(),currentLod:e.lod}),this.updateMemoryOnTileLoad(e)}getFaceIds(t){const e=new _s,s=t.faceIdBuffer,i=new Float32Array(3*s.length);for(let t=0;t<s.length;t++){const r=s[t];e.set(0+r),i[3*t]=e.r,i[3*t+1]=e.g,i[3*t+2]=e.b}return i}meshData(t,e,s){const i=this._temp.representation.id(),r=t.getLodClass()===Wc.CUSTOM,n=s===gi.WIRES;if(r&&n){return t.fetchLod(i,e)}return t.fetchMeshes(i,e)}tileAppendAttribute(t,e,s,i){void 0!==e[s]&&(i?t[s]=e[s]:t[s]+=e[s])}itemId(t){return this.meshes.samples(t,this._temp.sample),this._temp.sample.item()}};ot(sd,"_graphicMemoryConsumed",0);let id=sd;class rd{static isSame(t,e){const s=this.checkSameColor(t.color,e.color),i=this.checkSame(t.opacity,e.opacity,1),r=t.renderedFaces,n=e.renderedFaces,o=this.checkSame(r,n,Ac.ONE);return s&&i&&o}static checkSame(t,e,s){return t===e||(t===s&&void 0===e||void 0===t&&e===s)}static checkSameColor(t,e){if(t===e)return!0;if(void 0===t||void 0===e)return!1;const{r:s,g:i,b:r}=t,{r:n,g:o,b:a}=e;return s===n&&i===o&&r===a}}class nd{constructor(t,e){ot(this,"_modelId"),ot(this,"_list",[]),ot(this,"_onTransfer"),this._modelId=t,this._onTransfer=e}update(t){const e=t.meshes();return this.getAll(e,[])}fetch(t){return this._list[t]}transfer(t){const e=this.deduplicateMaterials(t),{materialDefinitions:s,ids:i}=e;return this.transferMaterialData(s),i}getItemsMaterialDefinition(t,e,s){const i=[],r=t.meshes();if(!r)return[];const n=new Map;for(const[t,i]of e.entries()){const e=r.samples(i);if(!e)continue;const o=e.material();let a=n.get(o);a||(a=new Set,n.set(o,a)),a.add(s[t])}for(const[t,e]of n.entries()){const s=r.materials(t);if(!s)continue;const n=kc.parseMaterial(s);i.push({localIds:[...e],definition:n})}return i}checkMaterialExists(t,e){const s=this._list.length;for(let i=0;i<s;i++){const s=this._list[i];if(rd.isSame(t,s))return e.push(i),!0}return!1}deduplicateMaterials(t){const e=[],s=[];for(const i of t){if(!this.checkMaterialExists(i,e)){this._list.push(i),s.push(i);const t=this._list.length-1;e.push(t)}}return{materialDefinitions:s,ids:e}}getAll(t,e){const s=t.materialsLength();for(let i=0;i<s;i++){const s=t.materials(i),r=kc.parseMaterial(s);e.push(r)}return this.transfer(e)}transferMaterialData(t){this._onTransfer({class:yi.CREATE_MATERIAL,modelId:this._modelId,materialDefinitions:t})}}class od{constructor(t,e,s){if(ot(this,"_model"),ot(this,"_boxes"),ot(this,"_localIdsToGeometryIds",new Map),ot(this,"_guidToLocalIdMap",new Map),ot(this,"_items",new Map),ot(this,"_itemDataCache",new Map),ot(this,"_itemDataConfig",{attributesDefault:!0,relationsDefault:{attributes:!1,relations:!1}}),ot(this,"_spatialStructure",null),ot(this,"_relations",new Map),this._model=t,this._boxes=e,this.preindexGeometryIds(),s&&s.extraRelations)for(const t of s.extraRelations){const{category:e,relation:s,inverseName:i}=t;this.addInverseRelation(e,s,i)}const i=this._model.localIdsArray();if(i){for(let t=0;t<this._model.localIdsLength();t++){const e=this._model.categories(t),s=i[t];let r=this._items.get(s);r||(r={category:null,guid:null,geometryIds:null,attrs:null},this._items.set(s,r)),r.category=e}for(let t=0;t<this._model.guidsItemsLength();t++){const e=this._model.guidsItems(t);if(null===e)continue;const s=this._model.guids(t);this._guidToLocalIdMap.set(s,e);let i=this._items.get(e);i||(i={category:null,guid:null,geometryIds:null,attrs:null},this._items.set(e,i)),i.guid=s}}}getAllLocalIds(){return this._model.localIdsArray()??[]}addInverseRelation(t,e,s){const i=this.getItemsOfCategories([new RegExp(`^${t}$`)])[t];for(const t of i){const i=this.getItemRelations(t);if(!i||!i[e])continue;const r=i[e];for(const e of r){let i=this._relations.get(e);i||(i={},this._relations.set(e,i));let r=i[s];r||(r=[],i[s]=r),r.push(t)}}}getItemsCount(){return this._model.localIdsLength()}getMaxLocalId(){return this._model.maxLocalId()}getMetadata(){const t=this._model.metadata();return t?JSON.parse(t):null}getItemIdsFromLocalIds(t){if(!t)return Array.from(this._model.meshes().meshesItemsArray());const e=[];for(const s of t){const t=this._localIdsToGeometryIds.get(s);if(t)for(const s of t)e.push(s)}return e}getLocalIdsFromItemIds(t){const e=[],s=this._localIdsToGeometryIds.entries();for(const[i,r]of s)for(const s of t)r.includes(s)&&e.push(i);return e}getBox(t,e){for(const s of t){const t=this._boxes.sampleOf(s);if(t)for(const s of t){const t=this._boxes.get(s);e.union(t)}}}getSpatialStructure(){if(this._spatialStructure)return this._spatialStructure;const t=this._model.spatialStructure();return t?(this._spatialStructure=this.getTreeItem(t),this._spatialStructure):{}}getItemsChildren(t){const e=new Set;for(const s of t){const t=this.convertToLocalId(s);null!==t&&this.traverseSpatialStructure(t,e)}return[...e]}getGuids(){const t=[];for(let e=0;e<this._model.guidsLength();e++){const s=this._model.guids(e);t.push(s)}return t}getLocalIds(){const t=this._model.localIdsArray();return t?Array.from(t):[]}getItemsCategories(t){var e;const s=[];for(const i of t){const t=this.convertToLocalId(i);if(null===t)continue;const r=(null==(e=this._items.get(t))?void 0:e.category)??null;s.push(r)}return s}getLocalIdsByGuids(t){const e=[];for(const s of t){const t=this._guidToLocalIdMap.get(s);e.push(void 0!==t?t:null)}return e}getGuidsByLocalIds(t){var e;const s=[];for(const i of t){const t=null==(e=this._items.get(i))?void 0:e.guid;s.push(void 0!==t?t:null)}return s}getAttributeNames(){const t=new Set;for(let e=0;e<this._model.uniqueAttributesLength();e++){const s=this._model.uniqueAttributes(e);if(!s)continue;const[i]=JSON.parse(s);t.add(i)}return[...t]}getAttributeValues(){const t=new Set;for(let e=0;e<this._model.uniqueAttributesLength();e++){const s=this._model.uniqueAttributes(e);if(!s)continue;const[,i]=JSON.parse(s);t.add(i)}return[...t]}getAttributesUniqueValues(t){var e,s,i;const r=new Map,n=t.every((t=>void 0!==t.categories)),o=t.map((t=>t.categories)).filter((t=>void 0!==t)).flat();for(let a=0;a<this._model.categoriesLength();a++){let h=!0;if(n){const t=this._model.categories(a);h=o.some((e=>null==e?void 0:e.test(t)))}if(!h)continue;const l=this._model.attributes(a);if(!l)continue;const c={};for(let t=0;t<l.dataLength();t++){const e=l.data(t);if(!e)continue;const[s,i,r]=JSON.parse(e);c[s]={value:i,type:r}}const u=Object.keys(c),d=this._model.categories(a);for(const{key:n,attributes:o,get:a,categories:h}of t){let t=!0;if(h&&(t=h.some((t=>t.test(d)))),!t)continue;let l=!0;if(o){const{aggregation:t,queries:s}=o,i=[];for(const{name:t,value:r,type:n,negate:o}of s){const s=u.find((e=>t.test(e)));if(!s||void 0===(null==(e=c[s])?void 0:e.value))break;let a=!1;const{value:h,type:l}=c[s];a=r instanceof RegExp?"string"==typeof h&&r.test(h):h===r,void 0!==n&&(a=a&&"string"==typeof l&&n.test(l)),o&&(a=!a),i.push(a)}l="exclusive"===t?i.every((t=>t)):i.some((t=>t))}if(l){const t=u.find((t=>a.test(t)));if(!t||void 0===(null==(s=c[t])?void 0:s.value))continue;const e=n??t;let o=r.get(e);o||(o=new Set,r.set(e,o)),o.add(null==(i=c[t])?void 0:i.value)}}}const a={};for(const[t,e]of r)a[t]=Array.from(e);return a}getAttributeTypes(){const t=new Set;for(let e=0;e<this._model.uniqueAttributesLength();e++){const s=this._model.uniqueAttributes(e);if(!s)continue;const[,,i]=JSON.parse(s);t.add(i)}return[...t]}getRelationNames(){const t=new Set;for(let e=0;e<this._model.relationNamesLength();e++){const s=this._model.relationNames(e);s&&t.add(s)}return[...t]}getItemAttributes(t){var e;const s="number"==typeof t?t:this.getLocalIdsByGuids([t])[0];if(null===s)return null;const i=null==(e=this._model.localIdsArray())?void 0:e.indexOf(s);if(void 0===i||-1===i)return null;const r=this._model.attributes(i);if(!r)return null;const n={};for(let t=0;t<r.dataLength();t++){const e=r.data(t);if(!e)continue;const[s,i,o]=JSON.parse(e);n[s]={value:i,type:o}}return n}getItemData(t,e={}){var s,i;const r=this._itemDataConfig.attributesDefault,n=this._itemDataConfig.attributes,o=this._itemDataConfig.relations??{};let{attributes:a,relations:h}=this._itemDataConfig.relationsDefault;const{parentName:l,rel:c}=e;if(l||c){const t=l&&l in o;if(c&&c in o){const t=o[c];t&&(a=t.attributes,h=t.relations)}else if(t){const t=o[l];t&&(a=t.attributes,h=t.relations)}}else a=!0,h=!0;if(!a&&!h)return{};if(this._itemDataCache.has(t))return this._itemDataCache.get(t);const u="number"==typeof t?t:this._guidToLocalIdMap.get(t)??null,d={_category:{value:null!==u?(null==(s=this._items.get(u))?void 0:s.category)??null:null},_localId:{value:u},_guid:{value:"string"==typeof t?t:(null==(i=this._items.get(t))?void 0:i.guid)??null}};if(this._itemDataCache.set(t,d),a&&null!==u){const e=this.getItemAttributes(t);for(const[t,s]of Object.entries(e??{}))r?(null==n?void 0:n.includes(t))||(d[t]=s):(null==n?void 0:n.includes(t))&&(d[t]=s)}if(h){const e=this.getItemRelations(t);for(const[t,s]of Object.entries(e??{}))for(const e of s){const s=this.getItemData(e,{parentName:c,rel:t});if(0===Object.keys(s).length)continue;const i=d[t];Array.isArray(i)?i.push(s):d[t]=[s]}}return d}getItemsData(t,e={}){this._itemDataCache.clear();const s=[],i=0!==t.length?t:this._model.localIdsArray();if(!i)return s;this._itemDataConfig={...this._itemDataConfig,...e};for(const t of i)s.push(this.getItemData(t));return this._itemDataCache.clear(),this._itemDataConfig={relationsDefault:{attributes:!1,relations:!1},attributesDefault:!0},s}getItemRelations(t){var e;const s="number"==typeof t?t:this.getLocalIdsByGuids([t])[0];if(null===s)return null;const i=this._relations.get(s)??{},r=null==(e=this._model.relationsItemsArray())?void 0:e.indexOf(s);if(void 0===r||-1===r)return Object.keys(i).length>0?i:null;const n=this._model.relations(r);if(!n)return Object.keys(i).length>0?i:null;for(let t=0;t<n.dataLength();t++){const e=n.data(t);if(!e)continue;const[s,...r]=JSON.parse(e);i[s]=r}return i}getCategories(){const t=new Set;for(let e=0;e<this._model.categoriesLength();e++){const s=this._model.categories(e);s&&t.add(s)}return[...t]}getItemsOfCategories(t){const e={},s=this._model.localIdsArray();if(!s)return e;for(let i=0;i<this._model.categoriesLength();i++){const r=this._model.categories(i);if(r)for(const n of t)if(n.test(r)){e[r]||(e[r]=[]),e[r].push(s[i]);break}}return e}getItemsWithGeometry(){const t=this._model.meshes(new wc),e=[];if(!t)return e;const s=t.meshesItemsArray();if(!s)return e;for(const t of s){const s=this._model.localIds(t);null!==s&&e.push(s)}return e}getItemsWithGeometryCategories(){const t=this.getItemsWithGeometry();return this.getItemsCategories(t)}getItemsByAttribute({name:t,value:e,type:s,negate:i,itemIds:r}){const n=this._model.attributesLength(),o=[];for(let a=0;a<n;a++){const n=this._model.localIds(a);if(null===n)continue;if((null==r?void 0:r.length)&&!r.includes(n))continue;const h=this._model.attributes(a);if(!h)continue;const l=null==h?void 0:h.dataLength();let c=!1;for(let i=0;i<l;i++){const r=h.data(i);if(!r)continue;const[n,o,a]=JSON.parse(r);if(t.test(n)){let t=void 0===e&&void 0===s;if(t||(void 0!==e&&(t=Array.isArray(e)?e.some((t=>"string"==typeof o&&t.test(o))):e instanceof RegExp?"string"==typeof o&&e.test(o):o===e),void 0!==s&&(t=t&&"string"==typeof a&&s.test(a))),t){c=!0;break}}}(i?!c:c)&&o.push(n)}return o}getItemsByRelation({name:t,targetItemIds:e,sourceItemIds:s}){const i=[],r=s??this.getAllLocalIds();for(const s of r){const r=this.getItemRelations(s),n=null==r?void 0:r[t];if(n)if(e){for(const t of n)if(e.has(t)){i.push(s);break}}else i.push(s)}return i}getItemsByQuery(t){var e;const{categories:s,attributes:i,relation:r}=t;let n=(null==(e=null==s?void 0:s.filter(Boolean))?void 0:e.length)?Object.values(this.getItemsOfCategories(s)).flat():void 0;if(0===(null==n?void 0:n.length))return[];if(i){const t=i.aggregation??"exclusive",e=[];for(const t of i.queries)if(i&&Boolean(t.name)){const s=this.getItemsByAttribute({...t,itemIds:n});e.push(s)}const s=new Set;if("inclusive"===t)for(const t of e)for(const e of t)s.add(e);else{const t=new Map;for(const s of e)for(const e of s){const s=t.get(e);void 0===s?t.set(e,1):t.set(e,s+1)}for(const[i,r]of t)r===e.length&&s.add(i)}n=[...s]}if(0===(null==n?void 0:n.length))return[];if(r&&Boolean(r.name)){const{name:t,query:e}=r,s=e?new Set(this.getItemsByQuery(e)):void 0;n=this.getItemsByRelation({name:t,targetItemIds:s,sourceItemIds:n})}return Array.from(new Set(n))}getTreeItem(t){const e={category:t.category(),localId:t.localId()},s=[];for(let e=0;e<t.childrenLength();e++){const i=t.children(e);i&&s.push(this.getTreeItem(i))}return s.length>0&&(e.children=s),e}preindexGeometryIds(){const t=this._model.meshes(),e=t.meshesItemsLength();for(let s=0;s<e;s++){const e=t.meshesItems(s),i=this._model.localIds(e);null!==i&&(this._localIdsToGeometryIds.has(i)||this._localIdsToGeometryIds.set(i,[]),this._localIdsToGeometryIds.get(i).push(s))}}convertToLocalId(t){if("number"==typeof t)return t;const e=this._guidToLocalIdMap.get(t);return void 0===e?null:e}getChildrenLocalIds(t,e){if(null!==t.localId&&e.add(t.localId),t.children)for(const s of t.children)this.getChildrenLocalIds(s,e)}traverseSpatialStructure(t,e,s=this.getSpatialStructure()){if(s)if(s.localId===t&&s.children)for(const t of s.children)this.getChildrenLocalIds(t,e);else if(s.children)for(const i of s.children)this.traverseSpatialStructure(t,e,i)}}class ad{constructor(t){ot(this,"_model"),this._model=t}async getAlignments(){const t=[],e=this._model.alignmentsLength();for(let s=0;s<e;s++){const e=this._model.alignments(s),i={absolute:[],horizontal:[],vertical:[]};t.push(i),this.constructAlignment(e,i,"absolute"),this.constructAlignment(e,i,"horizontal"),this.constructAlignment(e,i,"vertical")}return t}constructAlignment(t,e,s){const i=t[{absolute:"absoluteLength",horizontal:"horizontalLength",vertical:"verticalLength"}[s]](),r=this._model.geometries();for(let n=0;n<i;n++){const i=t[s](n),o=r.samples(i).id(),a=r.representations(o),h=a.id(),l=a.geometryClass(),c=[],u=r.lines(h).pointsArray();for(const t of u)c.push(t);e[s].push({points:new Float32Array(c),type:l})}}}class hd{constructor(){ot(this,"_templates",new Map)}add(t,e){this._templates.set(t,e)}get(t){const e=this._templates.get(t);return Array.isArray(e)?this.getTemplateSet(e):{...e}}getTemplateSet(t){const e=[];for(const s of t){const t={...s};e.push(t)}return e}}const ld=class t{constructor(e,s){ot(this,"_dataBuffer"),ot(this,"_dataPosition"),this._dataBuffer=s||this.getDefaultData(),this._dataPosition=e||t._data.defaultPosition}set(e){let s=0;for(const i of t._data.points)for(const r of t._data.coords){const t=this.getPosition(r,i),n=e[s++];this.setValue(t,n)}}get(t,e){const s=this.getPosition(t,e);return this._dataBuffer[s]}clone(e){for(const s of t._data.points)for(const i of t._data.coords){const t=this.getPosition(i,s),r=e.get(i,s);this.setValue(t,r)}}combine(e,s){for(const i of t._data.points)for(const r of t._data.coords)this.save(r,i,e,s)}setValue(t,e){this._dataBuffer[t]=e}getDefaultData(){return new Float64Array(t._data.size)}getPosition(e,s){return t._data[s][e]+this._dataPosition}save(t,e,s,i){const r=this.getPosition(t,e),n=s.get(t,e),o=i.get(t,e),a=Math[e](n,o);this.setValue(r,a)}};ot(ld,"_data",{size:6,defaultPosition:0,min:{x:0,y:2,z:4},max:{x:1,y:3,z:5},coords:["x","y","z"],points:["min","max"]});let cd=ld;const ud=class t{constructor(t,e){ot(this,"box"),ot(this,"data",0),this.box=new cd(t,e)}get size(){return this.data*t._data.factor}get isPoint(){return this.data>=t._data.threshold}transform(e,s,i){i||(e*=t._data.factor),this.data=e,this.box.clone(s)}};ot(ud,"_data",{threshold:0,factor:-1});let dd=ud;class pd{constructor(t){ot(this,"_boxes"),ot(this,"_min",new Xt),ot(this,"_max",new Xt),this._boxes=t}inflate(t){const e=this._boxes.fullBox.min,s=this.getVector(t,e,"min"),i=this.getVector(t,e,"max");return new Qt(s,i)}deflate(t,e){this.read(t);const s=[];s.push(this._min.x,this._min.y,this._min.z),s.push(this._max.x,this._max.y,this._max.z),e.set(s)}getVector(t,e,s){const i=t.get("x",s)+e.x,r=t.get("y",s)+e.y,n=t.get("z",s)+e.z;return new Xt(i,r,n)}read(t){const{min:e}=this._boxes.fullBox;this._min.subVectors(t.min,e),this._max.subVectors(t.max,e)}}class fd{constructor(t,e){ot(this,"_data"),ot(this,"_compressor"),this._data=e,this._compressor=t}frustumCollide(t,e,s=!1){const i=this.getFrustumPlanes(e,t),r=this.getFrustumOnCollide(i),n=this.getFrustumOnIncludes(i),o=this.newDefaultCallback(!0);return this.collide(r,n,o,s)}rayCollide(t,e){const s=this.getRayOnCollide(e),i=this.newDefaultCallback(!1),r=this.getRayOnSeen(t);return this.collide(s,i,r)}addPoint(t,e,s,i){t?i&&e.push(this.getPointData(s)):e.push(this.getPointData(s))}getPointData(t){return this.getPoint(t).data}getBounds(t){const e=this.getPoint(t);return this._compressor.inflate(e.box)}isPoint(t){return this.getPoint(t).isPoint}newDefaultCallback(t){return e=>t}groupSize(t){return this.getPoint(t).size}getPoint(t){return this._data.points[t]}getRayOnSeen(t){let e=this.newDefaultCallback(!0);return(null==t?void 0:t.length)>0&&(e=e=>wl.collides(e,t)),e}getRayOnCollide(t){return e=>t.intersectsBox(e)}collide(t,e,s,i=!1){const r=this._data.points.length,n=[];let o=0;const a=(t,e)=>{const r=o+this.groupSize(o);for(;o<r;o++){this.isPoint(o)&&s(t)&&(i?e&&this.savePoint(o,n):this.savePoint(o,n))}},h=()=>{const r=this.getBounds(o),h=e(r),l=this.isPoint(o),c=h||t(r);l&&c&&s(r)&&this.addPoint(i,n,o,h),c||l?(o++,h&&!l&&a(r,h)):o+=this.groupSize(o)};for(;o<r;)h();return n}getFrustumOnIncludes(t){return e=>wl.isIncluded(e,t)}getFrustumOnCollide(t){return e=>wl.collides(e,t)}getFrustumPlanes(t,e){const s=[];for(const e of t.planes)s.push(e);if(e)for(const t of e)s.push(t);return s}savePoint(t,e){const s=this.getPoint(t);e.push(s.data)}}class md{constructor(t){ot(this,"_boxes"),ot(this,"_total",new Xt),ot(this,"_change",new Xt),ot(this,"_average",new Xt),ot(this,"_tempCenterVector",new Xt),ot(this,"_tempVectors",{x:new Xt,y:new Xt,z:new Xt}),this._boxes=t}sort(t,e,s){this.average(this._average,t,e,s),this.getDataToTotal(e,s,t);let i=this.anySort(e,s,t);return i=this.adjust(s,e,i),Math.round(i)}anySort(t,e,s){return this._total.x>this._total.y?this._total.x>this._total.z?this.sortDim("x",this._average.x,t,e,s):this.sortDim("z",this._average.z,t,e,s):this._total.y>this._total.z?this.sortDim("y",this._average.y,t,e,s):this.sortDim("z",this._average.z,t,e,s)}getDataToTotal(t,e,s){this._total.set(0,0,0);for(let i=t;i<e;i++){this._boxes.get(s[i]).getCenter(this._change).sub(this._average);const t=this._change.multiply(this._change);this._total.add(t)}}sortDim(t,e,s,i,r){let n=s;for(let o=s;o<i;o++){this.getValue(r,o,t)>e&&(this.exchange(o,n,r),n++)}return n}exchange(t,e,s){const i=s[t];s[t]=s[e],s[e]=i}getValue(t,e,s){const i=this.getBox(t,e),r=this._tempVectors[s];return i.getCenter(r)[s]}average(t,e,s,i){const r=this.getBox(e,s);return r.getCenter(t),this.aggregate(s,i,e,r,t),t.divideScalar(i-s)}aggregate(t,e,s,i,r){for(let i=t+1;i<e;i++){const t=s[i],e=this._boxes.get(t).getCenter(this._tempCenterVector);r.add(e)}}adjust(t,e,s){const i=(e+t)/2,r=(t-e)/3;return(s<=e+r||s>=t-1-r)&&(s=i),s}getBox(t,e){const s=t[e];return this._boxes.get(s)}}class _d{constructor(t,e,s){ot(this,"_data"),ot(this,"_compressor"),ot(this,"_boxes"),ot(this,"_sorter"),this._data=s,this._compressor=e,this._boxes=t,this._sorter=new md(t)}make(t,e,s=0,i=0,r=0,n=0){const o=s-i;return 1===o?this.makePoint(t,i,e,n):2===o?this.makeGroup3(n,t,i,e):this.makeGroup(r,t,i,s,n,e)}makeGroup3(t,e,s,i){const r=this.makeBox(t+1,e,s),n=this.makeBox(t+2,e,s+1);return i.combine(r,n),this.newGroup(t,3,i),3}makeGroup(t,e,s,i,r,n){const o=this._data.limits.primary[t],a=this._data.limits.secondary[t],h=this._sorter.sort(e,s,i),l=this.make(e,o,h,s,t+1,r+1),c=r+l+1,u=this.make(e,a,i,h,t+1,c);n.combine(o,a);const d=l+u+1;return this.newGroup(r,d,n),d}makeBox(t,e,s){const i=this._data.points[t].box,r=e[s],n=this._boxes.get(r);return this._compressor.deflate(n,i),this.set(t,r),i}makePoint(t,e,s,i){const r=this._boxes.get(t[e]);return this._compressor.deflate(r,s),this.newPoint(i,t[e],s),1}newGroup(t,e,s){this.get(t).transform(e,s,!1)}get(t){return this._data.points[t]}newPoint(t,e,s){this.get(t).transform(e,s,!0)}set(t,e){this.get(t).data=e}}const bd=class t{constructor(t){ot(this,"_compressor"),ot(this,"_collider"),ot(this,"_maker"),ot(this,"_data"),ot(this,"_boxes"),this._boxes=t,this._compressor=new pd(t),this._data=this.getData(),this._collider=new fd(this._compressor,this._data),this._maker=new _d(this._boxes,this._compressor,this._data),this.initData()}collideFrustum(t,e,s=!1){return this._collider.frustumCollide(t,e,s)}collideRay(t,e){return this._collider.rayCollide(t,e)}setupLimits(){for(let e=0;e<t._limitThreshold;e++)this._data.limits.primary.push(new cd),this._data.limits.secondary.push(new cd)}getPointBuffer(){const t=this._boxes.getCount(),e=new Uint32Array(t);for(let t=0;t<e.length;t++)e[t]=t;return e}getPointsAmount(t){return 2*t.length-1}initData(){const e=this.getPointBuffer(),s=this.getPointsAmount(e),i=s*t._boxSize,r=new Float64Array(i);for(let e=0;e<s;e++){const s=e*t._boxSize,i=new dd(s,r);this._data.points.push(i)}this.setupLimits();const n=new cd;this._maker.make(e,n,e.length)}getData(){return{points:[],limits:{primary:[],secondary:[]}}}};ot(bd,"_boxSize",6),ot(bd,"_limitThreshold",32);let gd=bd;class yd{constructor(t){ot(this,"lookup"),ot(this,"_boxSize",6),ot(this,"_pointSize",3),ot(this,"_temp"),ot(this,"_dimensionsOfSamples"),ot(this,"_samples",[]),ot(this,"_boxes"),ot(this,"_meshes"),ot(this,"_box"),this._temp={box:new Qt,vector:new Xt,transform:new Me,sample:new _c,representation:new mc},this._box=new Qt;const e=t.meshes();if(!e)throw new Error("Fragments: Malformed fragments data!");this._meshes=e;const s=e.samplesLength();this._dimensionsOfSamples=new Float32Array(s);const i=s*this._boxSize;this._boxes=new Float64Array(i),this.lookup=this.newLookup()}get fullBox(){return this._box}set fullBox(t){this._box=t}sampleOf(t){return this._samples[t]}get(t){const e=this.getMinPosition(t),s=this.getMaxPosition(t);return this._temp.box.min.fromArray(this._boxes,e),this._temp.box.max.fromArray(this._boxes,s),this._temp.box}process(t){this.fetchSampleAndRepresentation(t),this.getBox(),this.addToFullBox();const e=this.getMinPosition(t),s=this.getMaxPosition(t);this._temp.box.min.toArray(this._boxes,e),this._temp.box.max.toArray(this._boxes,s)}getCount(){return this._boxes.length/this._boxSize}dimensionOf(t){const e=this._dimensionsOfSamples[t];if(!e)throw new Error("Fragments: Dimension not found!");return e}newLookup(){const t=this._meshes.samplesLength(),e=this._meshes.globalTransformsLength();for(let e=0;e<t;e++){this.fetchSampleAndRepresentation(e),Lc.getBox(this._temp.representation,this._temp.box);const t=this._temp.box.getSize(this._temp.vector);this._dimensionsOfSamples[e]=t.length(),this.process(e)}this._samples=new Array(e);for(let e=0;e<t;e++)this.storeBox(e);if(!this.getCount())throw new Error("Fragments: Malformed boxes!");return new gd(this)}getBox(){Lc.get(this._temp.sample,this._meshes,this._temp.transform),Lc.getBox(this._temp.representation,this._temp.box),this._temp.box.applyMatrix4(this._temp.transform)}fetchSampleAndRepresentation(t){this._meshes.samples(t,this._temp.sample);const e=this._temp.sample.representation();this._meshes.representations(e,this._temp.representation)}getMinPosition(t){return t*this._boxSize}storeBox(t){this.fetchSampleAndRepresentation(t);const e=this._temp.sample.item();void 0===this._samples[e]&&(this._samples[e]=[]),this._samples[e].push(t)}getMaxPosition(t){return t*this._boxSize+this._pointSize}addToFullBox(){this.fullBox.union(this._temp.box)}}class xd{raycast(t,e,s){if(t.view)return t.raycaster.raycast(e,s,t.view.clippingPlanes)}snapRaycast(t,e,s,i){return t.view?t.raycaster.snapRaycast(e,s,i,t.view.clippingPlanes):[]}rectangleRaycast(t,e,s){return t.view?t.raycaster.rectangleRaycast(e,t.view.clippingPlanes,s):[]}}class wd{getPositions(t,e){const s=[],i=t.properties.getItemIdsFromLocalIds(e);for(const e of i){const i=t.tiles.meshes.globalTransforms(e);if(!i)continue;const r=i.position(),n=r.x(),o=r.y(),a=r.z();s.push({x:n,y:o,z:a})}return s}getCoordinates(t){const e=t.data.meshes().coordinates(),s=e.position(),i=e.xDirection(),r=e.yDirection();return[s.x(),s.y(),s.z(),i.x(),i.y(),i.z(),r.x(),r.y(),r.z()]}}class vd{constructor(){ot(this,"_highlightProps",["color","opacity","transparent","renderedFaces"])}resetHighlight(t,e){const s=t.properties.getItemIdsFromLocalIds(e);this.resetHighlightForItems(s,t),t.tiles.restart()}getHighlight(t,e){const s=[],i=t.properties.getItemIdsFromLocalIds(e),r=this.getFetchEvent(t,s);return t.traverse(i,r),s}getHighlightItems(t){const e=[],s=t.itemConfig.size;for(let i=0;i<s;i++){if(!t.itemConfig.getHighlight(i))continue;const[s]=t.properties.getLocalIdsFromItemIds([i]);e.push(s)}return e}highlight(t,e,s){const i=t.properties.getItemIdsFromLocalIds(e),r=[],n=this.getCheckEvent(t,s,r);t.traverse(i,n);const o=t.materials.transfer(r),a=this.getCreateEvent(t,o);t.traverse(i,a),t.tiles.updateVirtualMeshes(i)}getFetchEvent(t,e){return s=>{const i=t.itemConfig.getHighlight(s);if(i){const s=t.materials.fetch(i);e.push(s)}else e.push(void 0)}}setHighlightProperty(t,e,s){void 0===t[s]&&void 0!==e[s]&&(t[s]=e[s])}getNewHighFromPast(t,e,s){const i=t.materials.fetch(e),r={...s};for(const t of this._highlightProps)this.setHighlightProperty(r,i,t);return r}getCheckEvent(t,e,s){return i=>{const r=t.itemConfig.getHighlight(i);if(void 0===r)s.push(e);else{const i=this.getNewHighFromPast(t,r,e);s.push(i)}}}getCreateEvent(t,e){return(s,i)=>{t.itemConfig.setHighlight(s,e[i])}}resetHighlightForItems(t,e){if(t)for(const s of t)e.itemConfig.setHighlight(s,0);else e.itemConfig.clearHighlight()}}class Sd{resetVisible(t){t.itemConfig.clearVisible(),t.tiles.restart()}getVisible(t,e){const s=t.properties.getItemIdsFromLocalIds(e),i=[];for(const e of s){const s=t.itemConfig.visible(e);i.push(s)}return i}getItemsByVisibility(t,e){const s=this.getVisibleCondition(t,e),i=t.getItemsByConfig(s);return t.properties.getLocalIdsFromItemIds(i)}toggleVisible(t,e){const s=t.properties.getItemIdsFromLocalIds(e),i=this.getToggleEvent(t);t.traverse(s,i),t.tiles.updateVirtualMeshes(s)}setVisible(t,e,s){const i=t.properties.getItemIdsFromLocalIds(e),r=this.getSetEvent(t,s);t.traverse(i,r),t.tiles.updateVirtualMeshes(i)}getSetEvent(t,e){return s=>{t.itemConfig.setVisible(s,e)}}getVisibleCondition(t,e){return s=>t.itemConfig.visible(s)===e}getToggleEvent(t){return e=>{const s=t.itemConfig.visible(e);t.itemConfig.setVisible(e,!s)}}}class Md{getGeometriesLength(t){return t.data.meshes().globalTransformsLength()}getGeometry(t,e){const s=t.boxes.sampleOf(e),i=[];if(!s)return i;for(const e of s){const s=t.tiles.fetchSample(e,gi.GEOMETRY),r=Array.isArray(s.geometries)?s.geometries:[s.geometries];for(const t of r)i.push({transform:s.transform.clone(),indices:t.indexBuffer,positions:t.positionBuffer,normals:t.normalBuffer})}return i}getVolume(t,e){let s=0;const i={x:0,y:0,z:0},r={x:0,y:0,z:0},n={x:0,y:0,z:0},o=this.getGeometry(t,e);for(const{indices:t,positions:e}of o)if(t&&e)for(let o=0;o<t.length-2;o+=3){const a=3*t[o],h=3*t[o+1],l=3*t[o+2];i.x=e[a],i.y=e[a+1],i.z=e[a+2],r.x=e[h],r.y=e[h+1],r.z=e[h+2],n.x=e[l],n.y=e[l+1],n.z=e[l+2],s+=this.getSignedVolumeOfTriangle(i,r,n)}return Math.abs(s)}getSignedVolumeOfTriangle(t,e,s){return 1/6*(-(s.x*e.y*t.z)+e.x*s.y*t.z+s.x*t.y*e.z-t.x*s.y*e.z-e.x*t.y*s.z+t.x*e.y*s.z)}}class Ad{constructor(){ot(this,"_sectionGenerator",new Xl)}async getSection(t,e,s){this._sectionGenerator.plane=e,performance.now();const i=new Map,r=[];for(const n of s){const s=t.boxes.sampleOf(n);if(s)for(const o of s){const s=t.boxes.get(o);if(!e.intersectsBox(s))continue;const a=t.tiles.meshes.meshesItems(n);if("IFCSPACE"===t.data.categories(a))continue;const h=t.tiles.meshes.samples(o);if(!h)continue;const l=h.representation();if(!i.has(l)){const e=[],s=t.tiles.fetchSample(o,gi.GEOMETRY);Fc.forEach(s.geometries,(t=>{if(!t.indexBuffer||!t.positionBuffer)return;const s=new ks;s.setIndex(Array.from(t.indexBuffer)),s.setAttribute("position",new Ms(t.positionBuffer,3)),e.push(s)})),i.set(l,e)}const c=i.get(l);if(c)for(const e of c){const s=new js(e),i=t.tiles.getSampleTransform(o);s.applyMatrix4(i),s.updateWorldMatrix(!0,!0),r.push(s)}}}const n=new Float32Array(6e5),o=new Ms(n,3,!1),{index:a,indexes:h}=this._sectionGenerator.createEdges({meshes:r,posAttr:o}),l=this._sectionGenerator.createFills(n,h);for(const[,t]of i)for(const e of t)e.dispose();return{buffer:n,index:a,fillsIndices:l}}}class Id{constructor(t){ot(this,"_model"),ot(this,"sequenceSelectorFunction",{withVisiblity:t=>this._model.getItemsByVisibility(t),highlighted:()=>this._model.getHighlightItemIds(),children:t=>this._model.getItemsChildren(t),ofCategory:t=>{const e=this._model.getItemsOfCategories(t);return Object.values(e).flat()},withCondition:()=>[],withGeometry:()=>this._model.getItemsWithGeometry()}),ot(this,"sequenceResultFunction",{attributes:t=>t.map((t=>this._model.getItemAttributes(t))),mergedBoxes:t=>this._model.getBBoxes(t),category:t=>this._model.getItemsCategories(t),children:t=>this._model.getItemsChildren(t),data:(t,...e)=>this._model.getItemsData(t,e[0]),geometry:t=>this._model.getItemsGeometry(t),guid:t=>this._model.getGuidsByLocalIds(t),highlight:t=>this._model.getHighlight(t),relations:t=>t.map((t=>this._model.getItemRelations(t))),visibility:t=>this._model.getVisible(t)}),this._model=t}getSequenced(t,e,s){var i;const r=this.sequenceResultFunction[t];if(!r)return null;let n=[],o=0;for(const t of e){const e=this.sequenceSelectorFunction[t];if(!e)continue;const r=null==(i=null==s?void 0:s.selector)?void 0:i[t];n=e(0===o?r:n),o++}return r(n,null==s?void 0:s.result)}}class Cd{traverse(t,e,s){e?this.traverseItems(e,s):this.traverseAllItems(t,s)}getItemsByConfig(t,e){const s=[],i=t.data.localIdsLength();for(let t=0;t<i;t++){e(t)&&s.push(t)}return s}traverseItems(t,e){const s=t.length;for(let i=0;i<s;i++)e(t[i],i)}traverseAllItems(t,e){const s=t.itemConfig.size;for(let t=0;t<s;t++)e(t,t)}}class zd{constructor(t,e,s,i){ot(this,"data"),ot(this,"view"),ot(this,"raycaster"),ot(this,"itemConfig"),ot(this,"properties"),ot(this,"materials"),ot(this,"tiles"),ot(this,"boxes"),ot(this,"_raycastHelper",new xd),ot(this,"_coordinatesHelper",new wd),ot(this,"_highlightHelper",new vd),ot(this,"_visibilityHelper",new Sd),ot(this,"_geometryHelper",new Md),ot(this,"_sectionHelper",new Ad),ot(this,"_itemsHelper",new Cd),ot(this,"_sequenceHelper",new Id(this)),ot(this,"_config",{}),ot(this,"_modelId"),ot(this,"_alignments"),ot(this,"_connection"),ot(this,"_onTransferMaterial",((t,e)=>{if(this._connection)return this._connection.fetch(t,e)})),this._modelId=t,this._connection=s,this._config={...this._config,...i},this.data=this.setupModel(e),this.boxes=new yd(this.data),this.materials=this.setupMaterials(t),this._alignments=new ad(this.data),this.itemConfig=this.setupItemsConfig(),this.tiles=this.setupTiles(),this.properties=this.setupProperties(),this.raycaster=this.setupRaycaster(),this.setupBVH()}getItemsByConfig(t){return this._itemsHelper.getItemsByConfig(this,t)}getItemsCategories(t){return this.properties.getItemsCategories(t)}getItemIdsByLocalIds(t){return this.properties.getItemIdsFromLocalIds(t)}getItemAttributes(t){return this.properties.getItemAttributes(t)}getAttributesUniqueValues(t){return this.properties.getAttributesUniqueValues(t)}getItemsData(t,e){return this.properties.getItemsData(t,e)}getItemsOfCategories(t){return this.properties.getItemsOfCategories(t)}getItemsWithGeometry(){return this.properties.getItemsWithGeometry()}getItemsWithGeometryCategories(){return this.properties.getItemsWithGeometryCategories()}getItemsByQuery(t){return this.properties.getItemsByQuery(t)}getItemRelations(t){return this.properties.getItemRelations(t)}getSpatialStructure(){return this.properties.getSpatialStructure()}getMaxLocalId(){return this.properties.getMaxLocalId()}getCategories(){return this.properties.getCategories()}getMetadata(){return this.properties.getMetadata()}getLocalIdsByGuids(t){return this.properties.getLocalIdsByGuids(t)}getGuidsByLocalIds(t){return this.properties.getGuidsByLocalIds(t)}getSequenced(t,e,s){return this._sequenceHelper.getSequenced(t,e,s)}highlight(t,e){this._highlightHelper.highlight(this,t,e)}getHighlight(t){return this._highlightHelper.getHighlight(this,t)}getHighlightItemIds(){return this._highlightHelper.getHighlightItems(this)}resetHighlight(t){this._highlightHelper.resetHighlight(this,t)}getCoordinates(){return this._coordinatesHelper.getCoordinates(this)}getPositions(t){return this._coordinatesHelper.getPositions(this,t)}getGeometriesLength(){return this._geometryHelper.getGeometriesLength(this)}getGuids(){return this.properties.getGuids()}getLocalIds(){return this.properties.getLocalIds()}getItemsGeometry(t){const e=this.properties.getItemIdsFromLocalIds(t),s=[];for(const t of e){const e=this._geometryHelper.getGeometry(this,t);s.push(e)}return s}getItemsVolume(t){const e=this.properties.getItemIdsFromLocalIds(t);let s=0;for(const t of e)s+=this._geometryHelper.getVolume(this,t);return s}getAttributeNames(){return this.properties.getAttributeNames()}getAttributeValues(){return this.properties.getAttributeValues()}getAttributeTypes(){return this.properties.getAttributeTypes()}getRelationNames(){return this.properties.getRelationNames()}getItemsMaterialDefinition(t){const e=this.properties.getItemIdsFromLocalIds(t);return this.materials.getItemsMaterialDefinition(this.data,e,t)}resetVisible(){this._visibilityHelper.resetVisible(this)}getItemsByVisibility(t){return this._visibilityHelper.getItemsByVisibility(this,t)}raycast(t,e){return this._raycastHelper.raycast(this,t,e)}snapRaycast(t,e,s){return this._raycastHelper.snapRaycast(this,t,e,s)}rectangleRaycast(t,e){return this._raycastHelper.rectangleRaycast(this,t,e)}async getSection(t,e){const s=this.properties.getItemIdsFromLocalIds(e);return this._sectionHelper.getSection(this,t,s)}async getAlignments(){return this._alignments.getAlignments()}getBuffer(t){const e=this.data.bb.bytes().buffer;return t?e:No.deflate(e)}dispose(){this.tiles.dispose()}setVisible(t,e){this._visibilityHelper.setVisible(this,t,e)}toggleVisible(t){this._visibilityHelper.toggleVisible(this,t)}getVisible(t){return this._visibilityHelper.getVisible(this,t)}getItemsChildren(t){return this.properties.getItemsChildren(t)}setupData(){this.tiles.generate()}refreshView(t){this.view=t,this.tiles.setupView(t)}getFullBBox(){return this.boxes.fullBox}getBBoxes(t){const e=new Qt;return this.properties.getBox(t,e),e}traverse(t,e){this._itemsHelper.traverse(this,t,e)}update(t){return this.tiles.update(t),this.tiles.tilesUpdated}setupBVH(){ks.prototype.computeBoundsTree=gl,ks.prototype.disposeBoundsTree=yl,js.prototype.raycast=bl}setupProperties(){return new od(this.data,this.boxes,this._config.properties)}setupRaycaster(){return new Uu(this.data,this.boxes,this.tiles,this.itemConfig)}setupMaterials(t){return new nd(t,this._onTransferMaterial)}setupTiles(){const t=this.materials.update(this.data);return new id({modelId:this._modelId,connection:this._connection,model:this.data,boxes:this.boxes,items:this.itemConfig,materials:t})}setupModel(t){const e=new Uint8Array(t),s=new Yo(e);return Mc.getRootAsModel(s)}setupItemsConfig(){const t=this.data.localIdsLength();return new Ou(t)}}class Td extends Wo{getId(){return yi.CREATE_MODEL}async execute(t){this.inflate(t);const e=this.createModel(t);this.setupData(t,e)}setupData(t,e){t.boundingBox=e.getFullBBox(),t.modelData=void 0}createModel(t){const{modelId:e,modelData:s,config:i}=t,{connection:r}=this.thread,n=new zd(e,s,r,i);return n.setupData(),this.thread.list.set(e,n),n}inflate(t){t.raw||(t.modelData=No.inflate(t.modelData))}}class Pd extends Wo{getId(){return yi.RAYCAST}async execute(t){const e=this.getRaycastType(t);if(0!==e)if(2!==e){if(1!==e)throw new Error("Fragments: Invalid raycast type");this.raycastRectangle(t)}else this.raycastWithSnap(t);else this.raycastBeam(t)}getRaycastType(t){return t.snappingClass?2:t.ray?0:1}raycastRectangle(t){const e=this.thread.getModel(t.modelId),s=vi.frustum(t.frustum),i=t.fullyIncluded,r=e.rectangleRaycast(s,i);t.localIds=r}raycastWithSnap(t){const e=this.thread.getModel(t.modelId),s=vi.beam(t.ray),i=vi.frustum(t.frustum),r=t.snappingClass,n=e.snapRaycast(s,i,r);t.results=n}raycastBeam(t){const e=this.thread.getModel(t.modelId),s=vi.beam(t.ray),i=vi.frustum(t.frustum),r=e.raycast(s,i);r&&(t.results=[r])}}class Bd extends Wo{getId(){return yi.DELETE_MODEL}async execute(t){const{modelId:e}=t;this.thread.getModel(e).dispose(),this.thread.list.delete(e)}}class Ed extends Wo{getId(){return yi.REFRESH_VIEW}async execute(t){const e=this.thread.list.get(t.modelId);e&&(this.safeCopyFrustum(t),this.safeCopyPosition(t),this.safeCopyPlanes(t),e.refreshView(t.view))}safeCopyFrustum(t){const e=t.view.cameraFrustum;t.view.cameraFrustum=vi.frustum(e)}safeCopyPosition(t){const e=t.view.cameraPosition;t.view.cameraPosition=vi.array(e)}safeCopyPlanes(t){const e=t.view.clippingPlanes;t.view.clippingPlanes=vi.planeSet(e)}}class Fd extends Wo{getId(){return yi.FETCH_BOXES}async execute(t){t.boxes=[],t.localIds?this.getBoxesFromLocalIds(t):this.getAllBoxes(t)}getBoxesFromLocalIds(t){const e=this.thread.getModel(t.modelId);for(const s of t.localIds){const i=e.getItemIdsByLocalIds(s),r=e.getBBoxes(i);t.boxes.push(r)}t.localIds=void 0}getAllBoxes(t){const e=this.thread.getModel(t.modelId),s=e.getGeometriesLength();for(let i=0;i<s;i++){const s=e.getBBoxes([i]);t.boxes.push(s)}t.localIds=void 0}}class Rd extends Wo{getId(){return yi.EXECUTE}async execute(t){const e=this.thread.getModel(t.modelId);this.safeCopyData(t),t.result=await e[t.function](...t.parameters),t.parameters=void 0}safeCopyData(t){for(let e=0;e<t.parameters.length;e++){const s=t.parameters[e];s&&(t.parameters[e]=vi.data(s))}}}class kd{constructor(t){ot(this,"_thread"),ot(this,"_updateThreshold",16),ot(this,"_updateDelay",128),this._thread=t;const e=()=>{const t=this.updateAllModels()?this._updateDelay:0;setTimeout(e,t)};e()}updateAllModels(){const t=performance.now();let e=!0;for(const[,s]of this._thread.list){const i=s.update(t);e=e&&i;if(performance.now()-t>this._updateThreshold)break}return e}}class Vd{constructor(t){ot(this,"thread"),ot(this,"modelCreator"),ot(this,"raycaster"),ot(this,"modelDeleter"),ot(this,"viewRefresher"),ot(this,"boxFetcher"),ot(this,"executor"),ot(this,"updater"),this.thread=t,this.modelCreator=new Td(t),this.raycaster=new Pd(t),this.modelDeleter=new Bd(t),this.viewRefresher=new Ed(t),this.boxFetcher=new Fd(t),this.executor=new Rd(t),this.updater=new kd(t)}}class Ld{constructor(){ot(this,"actions",{}),ot(this,"list",new Map),ot(this,"controllerManager",new Vd(this)),ot(this,"_connection")}get connection(){if(!this._connection)throw new Error("Fragments: Connection not set");return this._connection}set connection(t){this._connection=t}useConnection(t){this.connection=new Si((async t=>{await this.actions[t.class](t)})),this.connection.init(t)}getModel(t){const e=this.list.get(t);if(!e)throw new Error(`Fragments: Model not found: ${t}`);return e}}const Od=new Ld;globalThis.onmessage=t=>{Od.useConnection(t.data)};export{Ld as FragmentsThread};
|