@maqiuyao/dxf-viewer 0.2.7 → 0.2.9

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.
@@ -1,4 +1,4 @@
1
- "use strict";var Ml=Object.defineProperty;var Tl=(c,t,e)=>t in c?Ml(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var g=(c,t,e)=>Tl(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("three"),Cl=require("loglevel"),xo=require("three/examples/jsm/renderers/CSS2DRenderer.js"),Sl=require("three/examples/jsm/exporters/DRACOExporter.js"),El=require("three/examples/jsm/exporters/GLTFExporter.js"),Ol=require("three/examples/jsm/exporters/OBJExporter.js"),_l=require("three/examples/jsm/exporters/STLExporter.js"),Pl=require("poly-extrude"),Al=require("i18next"),Pe=require("three/examples/jsm/utils/BufferGeometryUtils.js"),Il=require("three/src/extras/Earcut.js"),Bl=require("2d-polygon-self-intersections"),kl=require("three/examples/jsm/modifiers/SimplifyModifier.js"),Dl=require("three/examples/jsm/renderers/SVGRenderer.js"),Ll=require("three/examples/jsm/loaders/RGBELoader.js"),Rl=require("js-base64"),Fl=require("concaveman"),zl=require("polybooljs"),Ms=require("jsbi"),Vl=require("3d-tiles-renderer"),jl=require("protobufjs"),Ul=require("three/examples/jsm/loaders/DDSLoader.js"),Cr=require("pako"),Hl=require("three/examples/jsm/geometries/TextGeometry.js"),Nl=require("opentype.js"),Gl=require("three/examples/jsm/loaders/FontLoader.js"),ql=require("three/examples/jsm/loaders/ColladaLoader.js"),Wl=require("three/examples/jsm/loaders/DRACOLoader.js"),Yl=require("three/examples/jsm/loaders/FBXLoader.js"),Xl=require("three/examples/jsm/loaders/GLTFLoader.js"),Zl=require("three/examples/jsm/loaders/MTLLoader.js"),Kl=require("three/examples/jsm/loaders/OBJLoader.js"),$l=require("three/examples/jsm/loaders/PLYLoader.js"),Jl=require("three/examples/jsm/loaders/STLLoader.js"),Ui=require("polygon-clipping"),Ql=require("three/examples/jsm/postprocessing/EffectComposer.js"),ec=require("three/examples/jsm/postprocessing/RenderPass.js"),tc=require("three/examples/jsm/postprocessing/ShaderPass.js"),ic=require("three/examples/jsm/postprocessing/SAOPass.js"),sc=require("three/examples/jsm/postprocessing/SSAOPass.js"),nc=require("three/examples/jsm/postprocessing/OutlinePass.js"),rc=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),ac=require("three/examples/jsm/postprocessing/BloomPass.js"),oc=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),lc=require("three/examples/jsm/shaders/FXAAShader.js"),cc=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),Ur=require("lodash");function xs(c){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const e in c)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(c,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>c[e]})}}return t.default=c,Object.freeze(t)}const p=xs(D),Hr=xs(Cl),hc=xs(Rl),Xt=xs(zl),dc=xs(jl),Oi=1,dt=new p.Sphere,Sn=new p.Vector3,En=new p.Vector3,Nr=new p.Vector3,Gr=new p.Vector3;p.Line.prototype.raycast=function(c,t){const e=this.geometry,i=this.matrixWorld,s=c.params.Line.threshold,n=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),dt.copy(e.boundingSphere),dt.applyMatrix4(i),dt.radius+=s,c.ray.intersectsSphere(dt)===!1)return;const r=s*s,a=this.isLineSegments?2:1,o=e.index,l=e.attributes,h=l.position,d=t.length;if(o!==null){const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(dt.copy(m.boundingSphere),dt.applyMatrix4(i),c.ray.intersectsSphere(dt)!==!1)for(let b=m.indexStart,y=m.indexStart+m.indexCount-1;b<y;b+=a){const C=o.getX(b),w=o.getX(b+1);if(Ts(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=Oi))return}}else{const f=Math.max(0,n.start),m=Math.min(o.count,n.start+n.count);for(let b=f,y=m-1;b<y;b+=a){const C=o.getX(b),w=o.getX(b+1);if(Ts(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=Oi))return}}}else{const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(dt.copy(m.boundingSphere),dt.applyMatrix4(i),c.ray.intersectsSphere(dt)!==!1){for(let b=m.positionStart,y=m.positionStart+m.positionCount-1;b<y;b+=a)if(Ts(this,h,c,b,b+1,r,t)&&t.length-d>=Oi)return}}else{const f=Math.max(0,n.start),m=Math.min(h.count,n.start+n.count);for(let b=f,y=m-1;b<y;b+=a)if(Ts(this,h,c,b,b+1,r,t)&&t.length-d>=Oi)return}}};function Ts(c,t,e,i,s,n,r){if(Sn.fromBufferAttribute(t,i),Sn.applyMatrix4(c.matrixWorld),En.fromBufferAttribute(t,s),En.applyMatrix4(c.matrixWorld),e.ray.distanceSqToSegment(Sn,En,Gr,Nr)>n)return!1;const o=e.ray.origin.distanceTo(Gr);return o<e.near||o>e.far?!1:(r.push({distance:o,point:Nr.clone(),index:i,object:c}),!0)}const uc=p.Line,bo=0,fc=1,pc=2,qr=2,On=1.25,Wr=1,Ae=32,be=Ae/4,wo=65535,nn=Math.pow(2,-24),Sr=Symbol("SKIP_GENERATION"),vo={strategy:bo,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Sr]:!1};function ce(c,t,e){return e.min.x=t[c],e.min.y=t[c+1],e.min.z=t[c+2],e.max.x=t[c+3],e.max.y=t[c+4],e.max.z=t[c+5],e}function ar(c){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=c[i+3]-c[i];s>e&&(e=s,t=i)}return t}function Yr(c,t){t.set(c)}function Xr(c,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=c[n],s=t[n],e[n]=i<s?i:s,i=c[r],s=t[r],e[r]=i>s?i:s}}function Cs(c,t,e){for(let i=0;i<3;i++){const s=t[c+2*i],n=t[c+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function Hi(c){const t=c[3]-c[0],e=c[4]-c[1],i=c[5]-c[2];return 2*(t*e+e*i+i*t)}function he(c,t){return t[c+15]===wo}function Te(c,t){return t[c+6]}function Ie(c,t){return t[c+14]}function we(c){return c+be}function ve(c,t){const e=t[c+6];return c+e*be}function Er(c,t){return t[c+7]}function _n(c,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0,d=1/0,u=1/0,f=1/0,m=-1/0,b=-1/0,y=-1/0;const C=c.offset||0;for(let w=(t-C)*6,x=(t+e-C)*6;w<x;w+=6){const E=c[w+0],M=c[w+1],O=E-M,S=E+M;O<n&&(n=O),S>o&&(o=S),E<d&&(d=E),E>m&&(m=E);const v=c[w+2],T=c[w+3],_=v-T,A=v+T;_<r&&(r=_),A>l&&(l=A),v<u&&(u=v),v>b&&(b=v);const I=c[w+4],B=c[w+5],k=I-B,L=I+B;k<a&&(a=k),L>h&&(h=L),I<f&&(f=I),I>y&&(y=I)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=l,i[5]=h,s[0]=d,s[1]=u,s[2]=f,s[3]=m,s[4]=b,s[5]=y}const vt=32,mc=(c,t)=>c.candidate-t.candidate,At=new Array(vt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ss=new Float32Array(6);function gc(c,t,e,i,s,n){let r=-1,a=0;if(n===bo)r=ar(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===fc)r=ar(c),r!==-1&&(a=yc(e,i,s,r));else if(n===pc){const o=Hi(c);let l=On*s;const h=e.offset||0,d=(i-h)*6,u=(i+s-h)*6;for(let f=0;f<3;f++){const m=t[f],C=(t[f+3]-m)/vt;if(s<vt/4){const w=[...At];w.length=s;let x=0;for(let M=d;M<u;M+=6,x++){const O=w[x];O.candidate=e[M+2*f],O.count=0;const{bounds:S,leftCacheBounds:v,rightCacheBounds:T}=O;for(let _=0;_<3;_++)T[_]=1/0,T[_+3]=-1/0,v[_]=1/0,v[_+3]=-1/0,S[_]=1/0,S[_+3]=-1/0;Cs(M,e,S)}w.sort(mc);let E=s;for(let M=0;M<E;M++){const O=w[M];for(;M+1<E&&w[M+1].candidate===O.candidate;)w.splice(M+1,1),E--}for(let M=d;M<u;M+=6){const O=e[M+2*f];for(let S=0;S<E;S++){const v=w[S];O>=v.candidate?Cs(M,e,v.rightCacheBounds):(Cs(M,e,v.leftCacheBounds),v.count++)}}for(let M=0;M<E;M++){const O=w[M],S=O.count,v=s-O.count,T=O.leftCacheBounds,_=O.rightCacheBounds;let A=0;S!==0&&(A=Hi(T)/o);let I=0;v!==0&&(I=Hi(_)/o);const B=Wr+On*(A*S+I*v);B<l&&(r=f,l=B,a=O.candidate)}}else{for(let E=0;E<vt;E++){const M=At[E];M.count=0,M.candidate=m+C+E*C;const O=M.bounds;for(let S=0;S<3;S++)O[S]=1/0,O[S+3]=-1/0}for(let E=d;E<u;E+=6){let S=~~((e[E+2*f]-m)/C);S>=vt&&(S=vt-1);const v=At[S];v.count++,Cs(E,e,v.bounds)}const w=At[vt-1];Yr(w.bounds,w.rightCacheBounds);for(let E=vt-2;E>=0;E--){const M=At[E],O=At[E+1];Xr(M.bounds,O.rightCacheBounds,M.rightCacheBounds)}let x=0;for(let E=0;E<vt-1;E++){const M=At[E],O=M.count,S=M.bounds,T=At[E+1].rightCacheBounds;O!==0&&(x===0?Yr(S,Ss):Xr(S,Ss,Ss)),x+=O;let _=0,A=0;x!==0&&(_=Hi(Ss)/o);const I=s-x;I!==0&&(A=Hi(T)/o);const B=Wr+On*(_*x+A*I);B<l&&(r=f,l=B,a=M.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function yc(c,t,e,i){let s=0;const n=c.offset;for(let r=t,a=t+e;r<a;r++)s+=c[(r-n)*6+i*2];return s/e}class Pn{constructor(){this.boundingData=new Float32Array(6)}}function xc(c,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,l=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+l]<o;)r++;for(;r<=a&&e[(a-h)*6+l]>=o;)a--;if(r<a){for(let d=0;d<t;d++){let u=c[r*t+d];c[r*t+d]=c[a*t+d],c[a*t+d]=u}for(let d=0;d<6;d++){const u=r-h,f=a-h,m=e[u*6+d];e[u*6+d]=e[f*6+d],e[f*6+d]=m}r++,a--}else return r}}let Mo,rn,or,To;const bc=Math.pow(2,32);function lr(c){return"count"in c?1:1+lr(c.left)+lr(c.right)}function wc(c,t,e){return Mo=new Float32Array(e),rn=new Uint32Array(e),or=new Uint16Array(e),To=new Uint8Array(e),cr(c,t)}function cr(c,t){const e=c/4,i=c/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Mo[e+r]=n[r];if(s)return t.buffer?(To.set(new Uint8Array(t.buffer),c),c+t.buffer.byteLength):(rn[e+6]=t.offset,or[i+14]=t.count,or[i+15]=wo,c+Ae);{const{left:r,right:a,splitAxis:o}=t,l=c+Ae;let h=cr(l,r);const d=c/Ae,f=h/Ae-d;if(f>bc)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return rn[e+6]=f,rn[e+7]=o,cr(h,a)}}function vc(c,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:l=1/0,strategy:h,onProgress:d}=s,u=c.primitiveBuffer,f=c.primitiveBufferStride,m=new Float32Array(6);let b=!1;const y=new Pn;return _n(t,e,i,y.boundingData,m),w(y,e,i,m),y;function C(x){d&&d((x-n.offset)/n.count)}function w(x,E,M,O=null,S=0){!b&&S>=r&&(b=!0,a&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const v=M>l;if(M<=o&&!v||S>=r)return C(E+M),x.offset=E,x.count=M,x;const T=gc(x.boundingData,O,t,E,M,h);let _=T.axis===-1?-1:xc(u,f,t,E,M,T);if(T.axis===-1||_===E||_===E+M){if(!v)return C(E+M),x.offset=E,x.count=M,x;T.axis=Math.max(0,ar(x.boundingData)),_=E+Math.max(1,Math.floor(M/2))}x.splitAxis=T.axis;const A=new Pn,I=E,B=_-E;x.left=A,_n(t,I,B,A.boundingData,m),w(A,I,B,m,S+1);const k=new Pn,L=_,F=M-B;return x.right=k,_n(t,L,F,k.boundingData,m),w(k,L,F,m,S+1),x}}function Mc(c,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=c.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,c.computePrimitiveBounds(r.offset,r.count,a),c._roots=i.map(o=>{const l=vc(c,a,o.offset,o.count,t,r),h=lr(l),d=new e(Ae*h);return wc(0,l,d),d})}class Or{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Tc{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const ne=new Tc;let Ft,_i;const oi=[],Es=new Or(()=>new D.Box3);function Cc(c,t,e,i,s,n){Ft=Es.getPrimitive(),_i=Es.getPrimitive(),oi.push(Ft,_i),ne.setBuffer(c._roots[t]);const r=hr(0,c.geometry,e,i,s,n);ne.clearBuffer(),Es.releasePrimitive(Ft),Es.releasePrimitive(_i),oi.pop(),oi.pop();const a=oi.length;return a>0&&(_i=oi[a-1],Ft=oi[a-2]),r}function hr(c,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:l}=ne;let h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);return ce(c,a,Ft),i(u,f,!1,r,n+c/be,Ft)}else{let _=function(I){const{uint16Array:B,uint32Array:k}=ne;let L=I*2;for(;!he(L,B);)I=we(I),L=I*2;return Te(I,k)},A=function(I){const{uint16Array:B,uint32Array:k}=ne;let L=I*2;for(;!he(L,B);)I=ve(I,k),L=I*2;return Te(I,k)+Ie(L,B)};const u=we(c),f=ve(c,l);let m=u,b=f,y,C,w,x;if(s&&(w=Ft,x=_i,ce(m,a,w),ce(b,a,x),y=s(w),C=s(x),C<y)){m=f,b=u;const I=y;y=C,C=I,w=x}w||(w=Ft,ce(m,a,w));const E=he(m*2,o),M=e(w,E,y,r+1,n+m/be);let O;if(M===qr){const I=_(m),k=A(m)-I;O=i(I,k,!0,r+1,n+m/be,w)}else O=M&&hr(m,t,e,i,s,n,r+1);if(O)return!0;x=_i,ce(b,a,x);const S=he(b*2,o),v=e(x,S,C,r+1,n+b/be);let T;if(v===qr){const I=_(b),k=A(b)-I;T=i(I,k,!0,r+1,n+b/be,x)}else T=v&&hr(b,t,e,i,s,n,r+1);return!!T}}const rs=new ne.constructor,fn=new ne.constructor,kt=new Or(()=>new D.Box3),li=new D.Box3,ci=new D.Box3,An=new D.Box3,In=new D.Box3;let Bn=!1;function Sc(c,t,e,i){if(Bn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Bn=!0;const s=c._roots,n=t._roots;let r,a=0,o=0;const l=new D.Matrix4().copy(e).invert();for(let h=0,d=s.length;h<d;h++){rs.setBuffer(s[h]),o=0;const u=kt.getPrimitive();ce(0,rs.float32Array,u),u.applyMatrix4(l);for(let f=0,m=n.length;f<m&&(fn.setBuffer(n[f]),r=nt(0,0,e,l,i,a,o,0,0,u),fn.clearBuffer(),o+=n[f].byteLength/Ae,!r);f++);if(kt.releasePrimitive(u),rs.clearBuffer(),a+=s[h].byteLength/Ae,r)break}return Bn=!1,r}function nt(c,t,e,i,s,n=0,r=0,a=0,o=0,l=null,h=!1){let d,u;h?(d=fn,u=rs):(d=rs,u=fn);const f=d.float32Array,m=d.uint32Array,b=d.uint16Array,y=u.float32Array,C=u.uint32Array,w=u.uint16Array,x=c*2,E=t*2,M=he(x,b),O=he(E,w);let S=!1;if(O&&M)h?S=s(Te(t,C),Ie(t*2,w),Te(c,m),Ie(c*2,b),o,r+t/be,a,n+c/be):S=s(Te(c,m),Ie(c*2,b),Te(t,C),Ie(t*2,w),a,n+c/be,o,r+t/be);else if(O){const v=kt.getPrimitive();ce(t,y,v),v.applyMatrix4(e);const T=we(c),_=ve(c,m);ce(T,f,li),ce(_,f,ci);const A=v.intersectsBox(li),I=v.intersectsBox(ci);S=A&&nt(t,T,i,e,s,r,n,o,a+1,v,!h)||I&&nt(t,_,i,e,s,r,n,o,a+1,v,!h),kt.releasePrimitive(v)}else{const v=we(t),T=ve(t,C);ce(v,y,An),ce(T,y,In);const _=l.intersectsBox(An),A=l.intersectsBox(In);if(_&&A)S=nt(c,v,e,i,s,n,r,a,o+1,l,h)||nt(c,T,e,i,s,n,r,a,o+1,l,h);else if(_)if(M)S=nt(c,v,e,i,s,n,r,a,o+1,l,h);else{const I=kt.getPrimitive();I.copy(An).applyMatrix4(e);const B=we(c),k=ve(c,m);ce(B,f,li),ce(k,f,ci);const L=I.intersectsBox(li),F=I.intersectsBox(ci);S=L&&nt(v,B,i,e,s,r,n,o,a+1,I,!h)||F&&nt(v,k,i,e,s,r,n,o,a+1,I,!h),kt.releasePrimitive(I)}else if(A)if(M)S=nt(c,T,e,i,s,n,r,a,o+1,l,h);else{const I=kt.getPrimitive();I.copy(In).applyMatrix4(e);const B=we(c),k=ve(c,m);ce(B,f,li),ce(k,f,ci);const L=I.intersectsBox(li),F=I.intersectsBox(ci);S=L&&nt(T,B,i,e,s,r,n,o,a+1,I,!h)||F&&nt(T,k,i,e,s,r,n,o,a+1,I,!h),kt.releasePrimitive(I)}}return S}const kn=new class{constructor(){let c=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=c=n._roots[r],this.uint16Array=e=new Uint16Array(c),this.uint32Array=t=new Uint32Array(c)},this.reset=()=>{this.root=null,this.buffer=c=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!he(r,e);)n=we(n),r=n*2;return Te(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!he(r,e);)n=ve(n,t),r=n*2;return Te(n,t)+Ie(r,e)};const s=(n,r,a)=>{const o=r*2,l=he(o,e);if(!n(a,l,r)&&!l){const d=we(r),u=ve(r,t);s(n,d,a+1),s(n,u,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const l=o*2,h=t[o+6],d=e[l+14];return n(r,a,new Float32Array(c,o*4,6),h,d)}else{const l=Er(o,t);return n(r,a,new Float32Array(c,o*4,6),l)}})}}},Zr=new D.Box3,hi=new Float32Array(6);class Ec{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...vo,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Mc(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0;for(let d=t,u=t+e;d<u;d++){this.writePrimitiveBounds(d,hi,0);const[f,m,b,y,C,w]=hi;f<n&&(n=f),y>o&&(o=y),m<r&&(r=m),C>l&&(l=C),b<a&&(a=b),w>h&&(h=w)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=l,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,hi,0);const[a,o,l,h,d,u]=hi,f=(a+h)/2,m=(o+d)/2,b=(l+u)/2,y=(h-a)/2,C=(d-o)/2,w=(u-l)/2,x=(n-s)*6;i[x+0]=f,i[x+1]=y+(Math.abs(f)+y)*nn,i[x+2]=m,i[x+3]=C+(Math.abs(m)+C)*nn,i[x+4]=b,i[x+5]=w+(Math.abs(b)+w)*nn}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/Ae;for(let l=0;l<o;l++){const h=be*l,d=2*h;he(d,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){kn.setBVH(this,e),kn.traverse(t),kn.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/Ae;for(let l=o-1;l>=0;l--){const h=l*be,d=h*2;if(he(d,r)){const f=Te(h,n),m=Ie(d,r);this.writePrimitiveRangeBounds(f,m,hi,0),a.set(hi,h)}else{const f=we(h),m=ve(h,n);for(let b=0;b<3;b++){const y=a[f+b],C=a[f+b+3],w=a[m+b],x=a[m+b+3];a[h+b]=y<w?y:w,a[h+b+3]=C>x?C:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{ce(0,new Float32Array(i),Zr),t.union(Zr)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const d=s;s=(u,f,m,b,y)=>d(u,f,m,b,y)?!0:a(u,f,this,n,m,b,r)}else s||(n?s=(d,u,f,m)=>a(d,u,this,n,f,m,r):s=(d,u,f)=>f);let o=!1,l=0;const h=this._roots;for(let d=0,u=h.length;d<u;d++){const f=h[d];if(o=Cc(this,d,i,s,e,l),o)break;l+=f.byteLength/Ae}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Sc(this,t,e,s)}}function Oc(){return typeof SharedArrayBuffer<"u"}function _r(c){return c.index?c.index.count:c.attributes.position.count}function bn(c){return _r(c)/3}function _c(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function Pc(c,t){if(!c.index){const e=c.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=_c(e,i);c.setIndex(new D.BufferAttribute(s,1));for(let n=0;n<e;n++)s[n]=n}}function Ac(c,t,e){const i=_r(c)/e,s=t||c.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function Ic(c,t){return c.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Kr(c,t,e){const i=Ac(c,t,e),s=Ic(c,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=_r(c)/e,l=[];for(const u of s){const{offset:f,count:m}=u,b=f,y=isFinite(m)?m:o-f,C=f+y;b<a&&C>r&&(l.push({pos:Math.max(r,b),isStart:!0}),l.push({pos:Math.min(a,C),isStart:!1}))}l.sort((u,f)=>u.pos!==f.pos?u.pos-f.pos:u.type==="end"?-1:1);let h=0,d=null;for(const u of l){const f=u.pos;h!==0&&f!==d&&n.push({offset:d,count:f-d}),h+=u.isStart?1:-1,d=f}return n}function Bc(c,t){const e=c[c.length-1],i=e.offset+e.count>2**16,s=c.reduce((l,h)=>l+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let l=0;l<c.length;l++){const{offset:h,count:d}=c[l];for(let u=0;u<d;u++)a[o+u]=h+u;o+=d}return a}class kc extends Ec{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Oc())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...vo,...e},e[Sr]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Kr(e,t.range,i),n=Bc(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else Pc(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new D.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Kr(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class _t{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}_t.prototype.setFromBox=(function(){const c=new D.Vector3;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){c.x=s.x*o+n.x*(1-o),c.y=s.y*l+n.y*(1-l),c.z=s.z*h+n.z*(1-h);const d=e.dot(c);r=Math.min(d,r),a=Math.max(d,a)}this.min=r,this.max=a}})();const Dc=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Vector3;return function(s,n,r){const a=s.start,o=c,l=n.start,h=t;e.subVectors(a,l),c.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const d=e.dot(h),u=h.dot(o),f=h.dot(h),m=e.dot(o),y=o.dot(o)*f-u*u;let C,w;y!==0?C=(d*u-m*f)/y:C=0,w=(d+C*u)/f,r.x=C,r.y=w}})(),Pr=(function(){const c=new D.Vector2,t=new D.Vector3,e=new D.Vector3;return function(s,n,r,a){Dc(s,n,c);let o=c.x,l=c.y;if(o>=0&&o<=1&&l>=0&&l<=1){s.at(o,r),n.at(l,a);return}else if(o>=0&&o<=1){l<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(l>=0&&l<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let d;l<0?d=n.start:d=n.end;const u=t,f=e;if(s.closestPointToPoint(d,!0,t),n.closestPointToPoint(h,!0,e),u.distanceToSquared(d)<=f.distanceToSquared(h)){r.copy(u),a.copy(d);return}else{r.copy(h),a.copy(f);return}}}})(),Lc=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Plane,i=new D.Line3;return function(n,r){const{radius:a,center:o}=n,{a:l,b:h,c:d}=r;if(i.start=l,i.end=h,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a||(i.start=l,i.end=d,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a)||(i.start=h,i.end=d,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a))return!0;const b=r.getPlane(e);if(Math.abs(b.distanceToPoint(o))<=a){const C=b.projectPoint(o,t);if(r.containsPoint(C))return!0}return!1}})(),Rc=["x","y","z"],Ct=1e-15,$r=Ct*Ct;function We(c){return Math.abs(c)<Ct}class lt extends D.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new D.Vector3),this.satBounds=new Array(4).fill().map(()=>new _t),this.points=[this.a,this.b,this.c],this.plane=new D.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new D.Line3,this.needsUpdate=!0}intersectsSphere(t){return Lc(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const l=n[1],h=r[1];l.subVectors(t,e),h.setFromPoints(l,s);const d=n[2],u=r[2];d.subVectors(e,i),u.setFromPoints(d,s);const f=n[3],m=r[3];f.subVectors(i,t),m.setFromPoints(f,s);const b=l.length(),y=d.length(),C=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,b<Ct?y<Ct||C<Ct?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):y<Ct?C<Ct?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):C<Ct&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}lt.prototype.closestPointToSegment=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Line3;return function(s,n=null,r=null){const{start:a,end:o}=s,l=this.points;let h,d=1/0;for(let u=0;u<3;u++){const f=(u+1)%3;e.start.copy(l[u]),e.end.copy(l[f]),Pr(e,s,c,t),h=c.distanceToSquared(t),h<d&&(d=h,n&&n.copy(c),r&&r.copy(t))}return this.closestPointToPoint(a,c),h=a.distanceToSquared(c),h<d&&(d=h,n&&n.copy(c),r&&r.copy(a)),this.closestPointToPoint(o,c),h=o.distanceToSquared(c),h<d&&(d=h,n&&n.copy(c),r&&r.copy(o)),Math.sqrt(d)}})();lt.prototype.intersectsTriangle=(function(){const c=new lt,t=new _t,e=new _t,i=new D.Vector3,s=new D.Vector3,n=new D.Vector3,r=new D.Vector3,a=new D.Line3,o=new D.Line3,l=new D.Vector3,h=new D.Vector2,d=new D.Vector2;function u(x,E,M,O){const S=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?S.copy(x.plane.normal):S.copy(E.plane.normal);const v=x.satBounds,T=x.satAxes;for(let I=1;I<4;I++){const B=v[I],k=T[I];if(t.setFromPoints(k,E.points),B.isSeparated(t)||(r.copy(S).cross(k),t.setFromPoints(r,x.points),e.setFromPoints(r,E.points),t.isSeparated(e)))return!1}const _=E.satBounds,A=E.satAxes;for(let I=1;I<4;I++){const B=_[I],k=A[I];if(t.setFromPoints(k,x.points),B.isSeparated(t)||(r.crossVectors(S,k),t.setFromPoints(r,x.points),e.setFromPoints(r,E.points),t.isSeparated(e)))return!1}return M&&(O||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),M.start.set(0,0,0),M.end.set(0,0,0)),!0}function f(x,E,M,O,S,v,T,_,A,I,B){let k=T/(T-_);I.x=O+(S-O)*k,B.start.subVectors(E,x).multiplyScalar(k).add(x),k=T/(T-A),I.y=O+(v-O)*k,B.end.subVectors(M,x).multiplyScalar(k).add(x)}function m(x,E,M,O,S,v,T,_,A,I,B){if(S>0)f(x.c,x.a,x.b,O,E,M,A,T,_,I,B);else if(v>0)f(x.b,x.a,x.c,M,E,O,_,T,A,I,B);else if(_*A>0||T!=0)f(x.a,x.b,x.c,E,M,O,T,_,A,I,B);else if(_!=0)f(x.b,x.a,x.c,M,E,O,_,T,A,I,B);else if(A!=0)f(x.c,x.a,x.b,O,E,M,A,T,_,I,B);else return!0;return!1}function b(x,E,M,O){const S=E.degenerateSegment,v=x.plane.distanceToPoint(S.start),T=x.plane.distanceToPoint(S.end);return We(v)?We(T)?u(x,E,M,O):(M&&(M.start.copy(S.start),M.end.copy(S.start)),x.containsPoint(S.start)):We(T)?(M&&(M.start.copy(S.end),M.end.copy(S.end)),x.containsPoint(S.end)):x.plane.intersectLine(S,i)!=null?(M&&(M.start.copy(i),M.end.copy(i)),x.containsPoint(i)):!1}function y(x,E,M){const O=E.a;return We(x.plane.distanceToPoint(O))&&x.containsPoint(O)?(M&&(M.start.copy(O),M.end.copy(O)),!0):!1}function C(x,E,M){const O=x.degenerateSegment,S=E.a;return O.closestPointToPoint(S,!0,i),S.distanceToSquared(i)<$r?(M&&(M.start.copy(S),M.end.copy(S)),!0):!1}function w(x,E,M,O){if(x.isDegenerateIntoSegment)if(E.isDegenerateIntoSegment){const S=x.degenerateSegment,v=E.degenerateSegment,T=s,_=n;S.delta(T),v.delta(_);const A=i.subVectors(v.start,S.start),I=T.x*_.y-T.y*_.x;if(We(I))return!1;const B=(A.x*_.y-A.y*_.x)/I,k=-(T.x*A.y-T.y*A.x)/I;if(B<0||B>1||k<0||k>1)return!1;const L=S.start.z+T.z*B,F=v.start.z+_.z*k;return We(L-F)?(M&&(M.start.copy(S.start).addScaledVector(T,B),M.end.copy(S.start).addScaledVector(T,B)),!0):!1}else return E.isDegenerateIntoPoint?C(x,E,M):b(E,x,M,O);else{if(x.isDegenerateIntoPoint)return E.isDegenerateIntoPoint?E.a.distanceToSquared(x.a)<$r?(M&&(M.start.copy(x.a),M.end.copy(x.a)),!0):!1:E.isDegenerateIntoSegment?C(E,x,M):y(E,x,M);if(E.isDegenerateIntoPoint)return y(x,E,M);if(E.isDegenerateIntoSegment)return b(x,E,M,O)}}return function(E,M=null,O=!1){this.needsUpdate&&this.update(),E.isExtendedTriangle?E.needsUpdate&&E.update():(c.copy(E),c.update(),E=c);const S=w(this,E,M,O);if(S!==void 0)return S;const v=this.plane,T=E.plane;let _=T.distanceToPoint(this.a),A=T.distanceToPoint(this.b),I=T.distanceToPoint(this.c);We(_)&&(_=0),We(A)&&(A=0),We(I)&&(I=0);const B=_*A,k=_*I;if(B>0&&k>0)return!1;let L=v.distanceToPoint(E.a),F=v.distanceToPoint(E.b),ie=v.distanceToPoint(E.c);We(L)&&(L=0),We(F)&&(F=0),We(ie)&&(ie=0);const se=L*F,Fe=L*ie;if(se>0&&Fe>0)return!1;s.copy(v.normal),n.copy(T.normal);const ht=s.cross(n);let Me=0,Vi=Math.abs(ht.x);const et=Math.abs(ht.y);et>Vi&&(Vi=et,Me=1),Math.abs(ht.z)>Vi&&(Me=2);const ke=Rc[Me],Pt=this.a[ke],ji=this.b[ke],Gt=this.c[ke],qt=E.a[ke],Wt=E.b[ke],Yt=E.c[ke];if(m(this,Pt,ji,Gt,B,k,_,A,I,h,a))return u(this,E,M,O);if(m(E,qt,Wt,Yt,se,Fe,L,F,ie,d,o))return u(this,E,M,O);if(h.y<h.x){const Cn=h.y;h.y=h.x,h.x=Cn,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(d.y<d.x){const Cn=d.y;d.y=d.x,d.x=Cn,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}return h.y<d.x||d.y<h.x?!1:(M&&(d.x>h.x?M.start.copy(o.start):M.start.copy(a.start),d.y<h.y?M.end.copy(o.end):M.end.copy(a.end)),!0)}})();lt.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();lt.prototype.distanceToTriangle=(function(){const c=new D.Vector3,t=new D.Vector3,e=["a","b","c"],i=new D.Line3,s=new D.Line3;return function(r,a=null,o=null){const l=a||o?i:null;if(this.intersectsTriangle(r,l,!0))return(a||o)&&(a&&l.getCenter(a),o&&l.getCenter(o)),0;let h=1/0;for(let d=0;d<3;d++){let u;const f=e[d],m=r[f];this.closestPointToPoint(m,c),u=m.distanceToSquared(c),u<h&&(h=u,a&&a.copy(c),o&&o.copy(m));const b=this[f];r.closestPointToPoint(b,c),u=b.distanceToSquared(c),u<h&&(h=u,a&&a.copy(b),o&&o.copy(c))}for(let d=0;d<3;d++){const u=e[d],f=e[(d+1)%3];i.set(this[u],this[f]);for(let m=0;m<3;m++){const b=e[m],y=e[(m+1)%3];s.set(r[b],r[y]),Pr(i,s,c,t);const C=c.distanceToSquared(t);C<h&&(h=C,a&&a.copy(c),o&&o.copy(t))}}return Math.sqrt(h)}})();class Le{constructor(t,e,i){this.isOrientedBox=!0,this.min=new D.Vector3,this.max=new D.Vector3,this.matrix=new D.Matrix4,this.invMatrix=new D.Matrix4,this.points=new Array(8).fill().map(()=>new D.Vector3),this.satAxes=new Array(3).fill().map(()=>new D.Vector3),this.satBounds=new Array(3).fill().map(()=>new _t),this.alignedSatBounds=new Array(3).fill().map(()=>new _t),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Le.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let d=0;d<=1;d++){const u=1*l|2*h|4*d,f=s[u];f.x=l?i.x:e.x,f.y=h?i.y:e.y,f.z=d?i.z:e.z,f.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let l=0;l<3;l++){const h=r[l],d=n[l],u=1<<l,f=s[u];h.subVectors(a,f),d.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();Le.prototype.intersectsBox=(function(){const c=new _t;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(c.min=i.x,c.max=s.x,a[0].isSeparated(c)||(c.min=i.y,c.max=s.y,a[1].isSeparated(c))||(c.min=i.z,c.max=s.z,a[2].isSeparated(c)))return!1;for(let o=0;o<3;o++){const l=r[o],h=n[o];if(c.setFromBox(l,e),h.isSeparated(c))return!1}return!0}})();Le.prototype.intersectsTriangle=(function(){const c=new lt,t=new Array(3),e=new _t,i=new _t,s=new D.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(c.copy(r),c.update(),r=c);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let u=0;u<3;u++){const f=a[u],m=o[u];if(e.setFromPoints(m,t),f.isSeparated(e))return!1}const l=r.satBounds,h=r.satAxes,d=this.points;for(let u=0;u<3;u++){const f=l[u],m=h[u];if(e.setFromPoints(m,d),f.isSeparated(e))return!1}for(let u=0;u<3;u++){const f=o[u];for(let m=0;m<4;m++){const b=h[m];if(s.crossVectors(f,b),e.setFromPoints(s,t),i.setFromPoints(s,d),e.isSeparated(i))return!1}}return!0}})();Le.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}})();Le.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();Le.prototype.distanceToBox=(function(){const c=["x","y","z"],t=new Array(12).fill().map(()=>new D.Line3),e=new Array(12).fill().map(()=>new D.Line3),i=new D.Vector3,s=new D.Vector3;return function(r,a=0,o=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||l)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),l&&l.copy(s)),0;const h=a*a,d=r.min,u=r.max,f=this.points;let m=1/0;for(let y=0;y<8;y++){const C=f[y];s.copy(C).clamp(d,u);const w=C.distanceToSquared(s);if(w<m&&(m=w,o&&o.copy(C),l&&l.copy(s),w<h))return Math.sqrt(w)}let b=0;for(let y=0;y<3;y++)for(let C=0;C<=1;C++)for(let w=0;w<=1;w++){const x=(y+1)%3,E=(y+2)%3,M=C<<x|w<<E,O=1<<y|C<<x|w<<E,S=f[M],v=f[O];t[b].set(S,v);const _=c[y],A=c[x],I=c[E],B=e[b],k=B.start,L=B.end;k[_]=d[_],k[A]=C?d[A]:u[A],k[I]=w?d[I]:u[A],L[_]=u[_],L[A]=C?d[A]:u[A],L[I]=w?d[I]:u[A],b++}for(let y=0;y<=1;y++)for(let C=0;C<=1;C++)for(let w=0;w<=1;w++){s.x=y?u.x:d.x,s.y=C?u.y:d.y,s.z=w?u.z:d.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<m&&(m=x,o&&o.copy(i),l&&l.copy(s),x<h))return Math.sqrt(x)}for(let y=0;y<12;y++){const C=t[y];for(let w=0;w<12;w++){const x=e[w];Pr(C,x,i,s);const E=i.distanceToSquared(s);if(E<m&&(m=E,o&&o.copy(i),l&&l.copy(s),E<h))return Math.sqrt(E)}}return Math.sqrt(m)}})();class Fc extends Or{constructor(){super(()=>new lt)}}const Je=new Fc,Ni=new D.Vector3,Dn=new D.Vector3;function zc(c,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(c.shapecast({boundsTraverseOrder:h=>(Ni.copy(t).clamp(h.min,h.max),Ni.distanceToSquared(t)),intersectsBounds:(h,d,u)=>u<a&&u<r,intersectsTriangle:(h,d)=>{h.closestPointToPoint(t,Ni);const u=t.distanceToSquared(Ni);return u<a&&(Dn.copy(Ni),a=u,o=d),u<n}}),a===1/0)return null;const l=Math.sqrt(a);return e.point?e.point.copy(Dn):e.point=Dn.clone(),e.distance=l,e.faceIndex=o,e}const Os=parseInt(D.REVISION)>=169,Vc=parseInt(D.REVISION)<=161,Zt=new D.Vector3,Kt=new D.Vector3,$t=new D.Vector3,_s=new D.Vector2,Ps=new D.Vector2,As=new D.Vector2,Jr=new D.Vector3,Qr=new D.Vector3,ea=new D.Vector3,Gi=new D.Vector3;function jc(c,t,e,i,s,n,r,a){let o;if(n===D.BackSide?o=c.intersectTriangle(i,e,t,!0,s):o=c.intersectTriangle(t,e,i,n!==D.DoubleSide,s),o===null)return null;const l=c.origin.distanceTo(s);return l<r||l>a?null:{distance:l,point:s.clone()}}function ta(c,t,e,i,s,n,r,a,o,l,h){Zt.fromBufferAttribute(t,n),Kt.fromBufferAttribute(t,r),$t.fromBufferAttribute(t,a);const d=jc(c,Zt,Kt,$t,Gi,o,l,h);if(d){if(i){_s.fromBufferAttribute(i,n),Ps.fromBufferAttribute(i,r),As.fromBufferAttribute(i,a),d.uv=new D.Vector2;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,_s,Ps,As,d.uv);Os||(d.uv=f)}if(s){_s.fromBufferAttribute(s,n),Ps.fromBufferAttribute(s,r),As.fromBufferAttribute(s,a),d.uv1=new D.Vector2;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,_s,Ps,As,d.uv1);Os||(d.uv1=f),Vc&&(d.uv2=d.uv1)}if(e){Jr.fromBufferAttribute(e,n),Qr.fromBufferAttribute(e,r),ea.fromBufferAttribute(e,a),d.normal=new D.Vector3;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,Jr,Qr,ea,d.normal);d.normal.dot(c.direction)>0&&d.normal.multiplyScalar(-1),Os||(d.normal=f)}const u={a:n,b:r,c:a,normal:new D.Vector3,materialIndex:0};if(D.Triangle.getNormal(Zt,Kt,$t,u.normal),d.face=u,d.faceIndex=n,Os){const f=new D.Vector3;D.Triangle.getBarycoord(Gi,Zt,Kt,$t,f),d.barycoord=f}}return d}function ia(c){return c&&c.isMaterial?c.side:c}function wn(c,t,e,i,s,n,r){const a=i*3;let o=a+0,l=a+1,h=a+2;const{index:d,groups:u}=c;c.index&&(o=d.getX(o),l=d.getX(l),h=d.getX(h));const{position:f,normal:m,uv:b,uv1:y}=c.attributes;if(Array.isArray(t)){const C=i*3;for(let w=0,x=u.length;w<x;w++){const{start:E,count:M,materialIndex:O}=u[w];if(C>=E&&C<E+M){const S=ia(t[O]),v=ta(e,f,m,b,y,o,l,h,S,n,r);if(v)if(v.faceIndex=i,v.face.materialIndex=O,s)s.push(v);else return v}}}else{const C=ia(t),w=ta(e,f,m,b,y,o,l,h,C,n,r);if(w)if(w.faceIndex=i,w.face.materialIndex=0,s)s.push(w);else return w}return null}function pe(c,t,e,i){const s=c.a,n=c.b,r=c.c;let a=t,o=t+1,l=t+2;e&&(a=e.getX(a),o=e.getX(o),l=e.getX(l)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(l),r.y=i.getY(l),r.z=i.getZ(l)}function Uc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++)wn(o,t,e,h,n,r,a)}function Hc(c,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=c;let l=1/0,h=null;for(let d=i,u=i+s;d<u;d++){let f;f=wn(a,t,e,d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Nc(c,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,l=a.attributes.position;for(let h=c,d=t+c;h<d;h++){let u;if(u=h,pe(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function Gc(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=c.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,l=0;const h=c._roots;for(let u=0,f=h.length;u<f;u++)n=h[u],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),d(0,l),l+=n.byteLength;function d(u,f,m=!1){const b=u*2;if(he(b,a)){const y=Te(u,r),C=Ie(b,a);let w=1/0,x=1/0,E=1/0,M=-1/0,O=-1/0,S=-1/0;for(let v=3*y,T=3*(y+C);v<T;v++){let _=i[v];const A=s.getX(_),I=s.getY(_),B=s.getZ(_);A<w&&(w=A),A>M&&(M=A),I<x&&(x=I),I>O&&(O=I),B<E&&(E=B),B>S&&(S=B)}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==E||o[u+3]!==M||o[u+4]!==O||o[u+5]!==S?(o[u+0]=w,o[u+1]=x,o[u+2]=E,o[u+3]=M,o[u+4]=O,o[u+5]=S,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,E=!1;if(t){if(!w){const _=y/be+f/Ae,A=C/be+f/Ae;x=t.has(_),E=t.has(A),w=!x&&!E}}else x=!0,E=!0;const M=w||x,O=w||E;let S=!1;M&&(S=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=S||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],L=o[I],F=o[I+3];o[u+_]=B<L?B:L,o[u+_+3]=k>F?k:F}return T}}}function jt(c,t,e,i,s){let n,r,a,o,l,h;const d=1/e.direction.x,u=1/e.direction.y,f=1/e.direction.z,m=e.origin.x,b=e.origin.y,y=e.origin.z;let C=t[c],w=t[c+3],x=t[c+1],E=t[c+3+1],M=t[c+2],O=t[c+3+2];return d>=0?(n=(C-m)*d,r=(w-m)*d):(n=(w-m)*d,r=(C-m)*d),u>=0?(a=(x-b)*u,o=(E-b)*u):(a=(E-b)*u,o=(x-b)*u),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),f>=0?(l=(M-y)*f,h=(O-y)*f):(l=(O-y)*f,h=(M-y)*f),n>h||l>r)?!1:((l>n||n!==n)&&(n=l),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function qc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++){let u=l?l[h]:h;wn(o,t,e,u,n,r,a)}}function Wc(c,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=c;let l=1/0,h=null;for(let d=i,u=i+s;d<u;d++){let f;f=wn(a,t,e,o?o[d]:d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Yc(c,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,l=a.attributes.position;for(let h=c,d=t+c;h<d;h++){let u;if(u=e.resolveTriangleIndex(h),pe(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function Xc(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),dr(0,c,e,i,s,n,r),ne.clearBuffer()}function dr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);Uc(t,e,i,u,f,s,n,r)}else{const u=we(c);jt(u,a,i,n,r)&&dr(u,t,e,i,s,n,r);const f=ve(c,l);jt(f,a,i,n,r)&&dr(f,t,e,i,s,n,r)}}const Zc=["x","y","z"];function Kc(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=ur(0,c,e,i,s,n);return ne.clearBuffer(),r}function ur(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(he(l,a)){const d=Te(c,o),u=Ie(l,a);return Hc(t,e,i,d,u,s,n)}else{const d=Er(c,o),u=Zc[d],m=i.direction[u]>=0;let b,y;m?(b=we(c),y=ve(c,o)):(b=ve(c,o),y=we(c));const w=jt(b,r,i,s,n)?ur(b,t,e,i,s,n):null;if(w){const M=w.point[u];if(m?M<=r[y+d]:M>=r[y+d+3])return w}const E=jt(y,r,i,s,n)?ur(y,t,e,i,s,n):null;return w&&E?w.distance<=E.distance?w:E:w||E||null}}const Is=new D.Box3,di=new lt,ui=new lt,qi=new D.Matrix4,sa=new Le,Bs=new Le;function $c(c,t,e,i){ne.setBuffer(c._roots[t]);const s=fr(0,c,e,i);return ne.clearBuffer(),s}function fr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),sa.set(e.boundingBox.min,e.boundingBox.max,i),s=sa),he(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Te(c,a),y=Ie(o,r);if(qi.copy(i).invert(),e.boundsTree)return ce(c,n,Bs),Bs.matrix.copy(qi),Bs.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Bs.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b*3,E=(y+b)*3;x<E;x+=3)if(pe(ui,x,d,u),ui.needsUpdate=!0,w.intersectsTriangle(ui))return!0;return!1}});{const C=bn(e);for(let w=b*3,x=(y+b)*3;w<x;w+=3){pe(di,w,d,u),di.a.applyMatrix4(qi),di.b.applyMatrix4(qi),di.c.applyMatrix4(qi),di.needsUpdate=!0;for(let E=0,M=C*3;E<M;E+=3)if(pe(ui,E,f,m),ui.needsUpdate=!0,di.intersectsTriangle(ui))return!0}}}else{const h=we(c),d=ve(c,a);return ce(h,n,Is),!!(s.intersectsBox(Is)&&fr(h,t,e,i,s)||(ce(d,n,Is),s.intersectsBox(Is)&&fr(d,t,e,i,s)))}}const ks=new D.Matrix4,Ln=new Le,Wi=new Le,Jc=new D.Vector3,Qc=new D.Vector3,eh=new D.Vector3,th=new D.Vector3;function ih(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Ln.set(t.boundingBox.min,t.boundingBox.max,e),Ln.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Je.getPrimitive(),f=Je.getPrimitive();let m=Jc,b=Qc,y=null,C=null;s&&(y=eh,C=th);let w=1/0,x=null,E=null;return ks.copy(e).invert(),Wi.matrix.copy(ks),c.shapecast({boundsTraverseOrder:M=>Ln.distanceToBox(M),intersectsBounds:(M,O,S)=>S<w&&S<r?(O&&(Wi.min.copy(M.min),Wi.max.copy(M.max),Wi.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:v=>Wi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,A=v+T;_<A;_++){pe(f,3*_,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let I=M,B=M+O;I<B;I++){pe(u,3*I,l,o),u.needsUpdate=!0;const k=u.distanceToTriangle(f,m,y);if(k<w&&(b.copy(m),C&&C.copy(y),w=k,x=I,E=_),k<n)return!0}}}});{const S=bn(t);for(let v=0,T=S;v<T;v++){pe(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=M,A=M+O;_<A;_++){pe(u,3*_,l,o),u.needsUpdate=!0;const I=u.distanceToTriangle(f,m,y);if(I<w&&(b.copy(m),C&&C.copy(y),w=I,x=_,E=v),I<n)return!0}}}}}),Je.releasePrimitive(u),Je.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=w,i.faceIndex=x,s&&(s.point?s.point.copy(C):s.point=C.clone(),s.point.applyMatrix4(ks),b.applyMatrix4(ks),s.distance=b.sub(s.point).length(),s.faceIndex=E),i)}function sh(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=c.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,l=0;const h=c._roots;for(let u=0,f=h.length;u<f;u++)n=h[u],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),d(0,l),l+=n.byteLength;function d(u,f,m=!1){const b=u*2;if(he(b,a)){const y=Te(u,r),C=Ie(b,a);let w=1/0,x=1/0,E=1/0,M=-1/0,O=-1/0,S=-1/0;for(let v=y,T=y+C;v<T;v++){const _=3*c.resolveTriangleIndex(v);for(let A=0;A<3;A++){let I=_+A;I=i?i[I]:I;const B=s.getX(I),k=s.getY(I),L=s.getZ(I);B<w&&(w=B),B>M&&(M=B),k<x&&(x=k),k>O&&(O=k),L<E&&(E=L),L>S&&(S=L)}}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==E||o[u+3]!==M||o[u+4]!==O||o[u+5]!==S?(o[u+0]=w,o[u+1]=x,o[u+2]=E,o[u+3]=M,o[u+4]=O,o[u+5]=S,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,E=!1;if(t){if(!w){const _=y/be+f/Ae,A=C/be+f/Ae;x=t.has(_),E=t.has(A),w=!x&&!E}}else x=!0,E=!0;const M=w||x,O=w||E;let S=!1;M&&(S=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=S||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],L=o[I],F=o[I+3];o[u+_]=B<L?B:L,o[u+_+3]=k>F?k:F}return T}}}function nh(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),pr(0,c,e,i,s,n,r),ne.clearBuffer()}function pr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);qc(t,e,i,u,f,s,n,r)}else{const u=we(c);jt(u,a,i,n,r)&&pr(u,t,e,i,s,n,r);const f=ve(c,l);jt(f,a,i,n,r)&&pr(f,t,e,i,s,n,r)}}const rh=["x","y","z"];function ah(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=mr(0,c,e,i,s,n);return ne.clearBuffer(),r}function mr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(he(l,a)){const d=Te(c,o),u=Ie(l,a);return Wc(t,e,i,d,u,s,n)}else{const d=Er(c,o),u=rh[d],m=i.direction[u]>=0;let b,y;m?(b=we(c),y=ve(c,o)):(b=ve(c,o),y=we(c));const w=jt(b,r,i,s,n)?mr(b,t,e,i,s,n):null;if(w){const M=w.point[u];if(m?M<=r[y+d]:M>=r[y+d+3])return w}const E=jt(y,r,i,s,n)?mr(y,t,e,i,s,n):null;return w&&E?w.distance<=E.distance?w:E:w||E||null}}const Ds=new D.Box3,fi=new lt,pi=new lt,Yi=new D.Matrix4,na=new Le,Ls=new Le;function oh(c,t,e,i){ne.setBuffer(c._roots[t]);const s=gr(0,c,e,i);return ne.clearBuffer(),s}function gr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),na.set(e.boundingBox.min,e.boundingBox.max,i),s=na),he(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Te(c,a),y=Ie(o,r);if(Yi.copy(i).invert(),e.boundsTree)return ce(c,n,Ls),Ls.matrix.copy(Yi),Ls.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Ls.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b,E=y+b;x<E;x++)if(pe(pi,3*t.resolveTriangleIndex(x),d,u),pi.needsUpdate=!0,w.intersectsTriangle(pi))return!0;return!1}});{const C=bn(e);for(let w=b,x=y+b;w<x;w++){const E=t.resolveTriangleIndex(w);pe(fi,3*E,d,u),fi.a.applyMatrix4(Yi),fi.b.applyMatrix4(Yi),fi.c.applyMatrix4(Yi),fi.needsUpdate=!0;for(let M=0,O=C*3;M<O;M+=3)if(pe(pi,M,f,m),pi.needsUpdate=!0,fi.intersectsTriangle(pi))return!0}}}else{const h=we(c),d=ve(c,a);return ce(h,n,Ds),!!(s.intersectsBox(Ds)&&gr(h,t,e,i,s)||(ce(d,n,Ds),s.intersectsBox(Ds)&&gr(d,t,e,i,s)))}}const Rs=new D.Matrix4,Rn=new Le,Xi=new Le,lh=new D.Vector3,ch=new D.Vector3,hh=new D.Vector3,dh=new D.Vector3;function uh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Rn.set(t.boundingBox.min,t.boundingBox.max,e),Rn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Je.getPrimitive(),f=Je.getPrimitive();let m=lh,b=ch,y=null,C=null;s&&(y=hh,C=dh);let w=1/0,x=null,E=null;return Rs.copy(e).invert(),Xi.matrix.copy(Rs),c.shapecast({boundsTraverseOrder:M=>Rn.distanceToBox(M),intersectsBounds:(M,O,S)=>S<w&&S<r?(O&&(Xi.min.copy(M.min),Xi.max.copy(M.max),Xi.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:v=>Xi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,A=v+T;_<A;_++){const I=S.resolveTriangleIndex(_);pe(f,3*I,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=M,k=M+O;B<k;B++){const L=c.resolveTriangleIndex(B);pe(u,3*L,l,o),u.needsUpdate=!0;const F=u.distanceToTriangle(f,m,y);if(F<w&&(b.copy(m),C&&C.copy(y),w=F,x=B,E=_),F<n)return!0}}}})}else{const S=bn(t);for(let v=0,T=S;v<T;v++){pe(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=M,A=M+O;_<A;_++){const I=c.resolveTriangleIndex(_);pe(u,3*I,l,o),u.needsUpdate=!0;const B=u.distanceToTriangle(f,m,y);if(B<w&&(b.copy(m),C&&C.copy(y),w=B,x=_,E=v),B<n)return!0}}}}}),Je.releasePrimitive(u),Je.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=w,i.faceIndex=x,s&&(s.point?s.point.copy(C):s.point=C.clone(),s.point.applyMatrix4(Rs),b.applyMatrix4(Rs),s.distance=b.sub(s.point).length(),s.faceIndex=E),i)}function ra(c,t,e){return c===null?null:(c.point.applyMatrix4(t.matrixWorld),c.distance=c.point.distanceTo(e.ray.origin),c.object=t,c)}const Fs=new Le,zs=new D.Ray,aa=new D.Vector3,oa=new D.Matrix4,la=new D.Vector3,Fn=["getX","getY","getZ"];class ps extends kc{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new ps(e,{...i,[Sr]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const l=e.getIndex();if(l===null){const h=new D.BufferAttribute(t.index,1,!1);e.setIndex(h)}else l.array!==s&&(l.array.set(s),l.needsUpdate=!0)}return a;function o(l){for(let h=0;h<l.length;h++){const d=l[h],u=new Uint32Array(d),f=new Uint16Array(d);for(let m=0,b=d.byteLength/Ae;m<b;m++){const y=be*m,C=2*y;he(C,f)||(u[y+6]=u[y+6]/be-m)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,l=(n?n[t]:t)*3;let h=l+0,d=l+1,u=l+2;a&&(h=a[h],d=a[d],u=a[u]);for(let f=0;f<3;f++){const m=r[Fn[f]](h),b=r[Fn[f]](d),y=r[Fn[f]](u);let C=m;b<C&&(C=b),y<C&&(C=y);let w=m;b>w&&(w=b),y>w&&(w=y),e[i+f]=C,e[i+f+3]=w}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=r.array,h=r.offset||0;let d=3;r.isInterleavedBufferAttribute&&(d=r.data.stride);const u=["getX","getY","getZ"],f=i.offset;for(let m=t,b=t+e;m<b;m++){const C=(n?n[m]:m)*3,w=(m-f)*6;let x=C+0,E=C+1,M=C+2;a&&(x=a[x],E=a[E],M=a[M]),o||(x=x*d+h,E=E*d+h,M=M*d+h);for(let O=0;O<3;O++){let S,v,T;o?(S=r[u[O]](x),v=r[u[O]](E),T=r[u[O]](M)):(S=l[x+O],v=l[E+O],T=l[M+O]);let _=S;v<_&&(_=v),T<_&&(_=T);let A=S;v>A&&(A=v),T>A&&(A=T);const I=(A-_)/2,B=O*2;i[w+B+0]=_+I,i[w+B+1]=I+(Math.abs(_)+I)*nn}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;oa.copy(t.matrixWorld).invert(),zs.copy(e.ray).applyMatrix4(oa),la.setFromMatrixScale(t.matrixWorld),aa.copy(zs.direction).multiply(la);const n=aa.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(zs,s,r,a);o=ra(o,t,e),o&&i.push(o)}else{const o=this.raycast(zs,s,r,a);for(let l=0,h=o.length;l<h;l++){const d=ra(o[l],t,e);d&&i.push(d)}}return i}refit(t=null){return(this.indirect?sh:Gc)(this,t)}raycast(t,e=D.FrontSide,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?nh:Xc;for(let o=0,l=n.length;o<l;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=D.FrontSide,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?ah:Kc;for(let o=0,l=n.length;o<l;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?oh:$c;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=Je.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Yc:Nc});return Je.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=Je.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,l=this.indirect?m=>{const b=this.resolveTriangleIndex(m);pe(r,b*3,a,o)}:m=>{pe(r,m*3,a,o)},h=Je.getPrimitive(),d=t.geometry.index,u=t.geometry.attributes.position,f=t.indirect?m=>{const b=t.resolveTriangleIndex(m);pe(h,b*3,d,u)}:m=>{pe(h,m*3,d,u)};if(n){if(!(t instanceof ps))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const m=(b,y,C,w,x,E,M,O)=>{for(let S=C,v=C+w;S<v;S++){f(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let T=b,_=b+y;T<_;T++)if(l(T),r.needsUpdate=!0,n(r,h,T,S,x,E,M,O))return!0}return!1};if(s){const b=s;s=function(y,C,w,x,E,M,O,S){return b(y,C,w,x,E,M,O,S)?!0:m(y,C,w,x,E,M,O,S)}}else s=m}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return Fs.set(t.min,t.max,e),Fs.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Fs.intersectsBox(i),intersectsTriangle:i=>Fs.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?uh:ih)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return zc(this,t,e,i,s)}}const Ti={Mesh:D.Mesh.prototype.raycast,Line:D.Line.prototype.raycast,LineSegments:D.LineSegments.prototype.raycast,LineLoop:D.LineLoop.prototype.raycast,Points:D.Points.prototype.raycast,BatchedMesh:D.BatchedMesh.prototype.raycast},Ce=new D.Mesh,Vs=[];function fh(c,t){if(this.isBatchedMesh)ph.call(this,c,t);else{const{geometry:e}=this;if(e.boundsTree)e.boundsTree.raycastObject3D(this,c,t);else{let i;if(this instanceof D.Mesh)i=Ti.Mesh;else if(this instanceof D.LineSegments)i=Ti.LineSegments;else if(this instanceof D.LineLoop)i=Ti.LineLoop;else if(this instanceof D.Line)i=Ti.Line;else if(this instanceof D.Points)i=Ti.Points;else throw new Error("BVH: Fallback raycast function not found.");i.call(this,c,t)}}}function ph(c,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,n=this.matrixWorld;Ce.material=this.material,Ce.geometry=this.geometry;const r=Ce.geometry.boundsTree,a=Ce.geometry.drawRange;Ce.geometry.boundingSphere===null&&(Ce.geometry.boundingSphere=new D.Sphere);for(let o=0,l=i.length;o<l;o++){if(!this.getVisibleAt(o))continue;const h=i[o].geometryIndex;if(Ce.geometry.boundsTree=e[h],this.getMatrixAt(o,Ce.matrixWorld).premultiply(n),!Ce.geometry.boundsTree){this.getBoundingBoxAt(h,Ce.geometry.boundingBox),this.getBoundingSphereAt(h,Ce.geometry.boundingSphere);const d=s[h];Ce.geometry.setDrawRange(d.start,d.count)}Ce.raycast(c,Vs);for(let d=0,u=Vs.length;d<u;d++){const f=Vs[d];f.object=this,f.batchId=o,t.push(f)}Vs.length=0}Ce.geometry.boundsTree=r,Ce.geometry.drawRange=a,Ce.material=null,Ce.geometry=null}else Ti.BatchedMesh.call(this,c,t)}D.Mesh.prototype.raycast=fh;const js=new p.Sphere,Us=new p.Vector3;p.Points.prototype.raycast=function(c,t){const e=this.geometry,i=this.matrixWorld,s=c.params.Points.threshold,n=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),js.copy(e.boundingSphere),js.applyMatrix4(i),js.radius+=s,c.ray.intersectsSphere(js)===!1)return;const r=s*s,a=e.index,o=e.attributes,l=o.position,h=t.length;if(a!==null){const d=Math.max(0,n.start),u=Math.min(a.count,n.start+n.count);for(let f=d,m=u;f<m;f++){const b=a.getX(f);if(Us.fromBufferAttribute(l,b).applyMatrix4(i),ca(Us,b,r,c,t,this),t.length-h>=Oi)return}}else{const d=Math.max(0,n.start),u=Math.min(l.count,n.start+n.count);for(let f=d,m=u;f<m;f++)if(Us.fromBufferAttribute(l,f).applyMatrix4(i),ca(Us,f,r,c,t,this),t.length-h>=Oi)return}};function ca(c,t,e,i,s,n){const r=i.ray.distanceSqToPoint(c);if(r<e){const a=new p.Vector3;i.ray.closestPointToPoint(c,a);const o=i.ray.origin.distanceTo(a);if(o<i.near||o>i.far)return;s.push({distance:o,distanceToRay:Math.sqrt(r),point:a,index:t,face:null,object:n})}}const mh=p.Points,gh=`
1
+ "use strict";var Tl=Object.defineProperty;var Cl=(c,t,e)=>t in c?Tl(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var g=(c,t,e)=>Cl(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("three"),Sl=require("loglevel"),yo=require("three/examples/jsm/renderers/CSS2DRenderer.js"),El=require("three/examples/jsm/exporters/DRACOExporter.js"),Ol=require("three/examples/jsm/exporters/GLTFExporter.js"),_l=require("three/examples/jsm/exporters/OBJExporter.js"),Pl=require("three/examples/jsm/exporters/STLExporter.js"),Al=require("poly-extrude"),Il=require("i18next"),Pe=require("three/examples/jsm/utils/BufferGeometryUtils.js"),Bl=require("three/src/extras/Earcut.js"),kl=require("2d-polygon-self-intersections"),Dl=require("three/examples/jsm/modifiers/SimplifyModifier.js"),Ll=require("three/examples/jsm/renderers/SVGRenderer.js"),Rl=require("three/examples/jsm/loaders/RGBELoader.js"),Fl=require("js-base64"),zl=require("concaveman"),Vl=require("polybooljs"),Ms=require("jsbi"),jl=require("3d-tiles-renderer"),Ul=require("protobufjs"),Hl=require("three/examples/jsm/loaders/DDSLoader.js"),Tr=require("pako"),Nl=require("three/examples/jsm/geometries/TextGeometry.js"),Gl=require("opentype.js"),ql=require("three/examples/jsm/loaders/FontLoader.js"),Wl=require("three/examples/jsm/loaders/ColladaLoader.js"),Yl=require("three/examples/jsm/loaders/DRACOLoader.js"),Xl=require("three/examples/jsm/loaders/FBXLoader.js"),Zl=require("three/examples/jsm/loaders/GLTFLoader.js"),Kl=require("three/examples/jsm/loaders/MTLLoader.js"),$l=require("three/examples/jsm/loaders/OBJLoader.js"),Jl=require("three/examples/jsm/loaders/PLYLoader.js"),Ql=require("three/examples/jsm/loaders/STLLoader.js"),Ui=require("polygon-clipping"),ec=require("three/examples/jsm/postprocessing/EffectComposer.js"),tc=require("three/examples/jsm/postprocessing/RenderPass.js"),ic=require("three/examples/jsm/postprocessing/ShaderPass.js"),sc=require("three/examples/jsm/postprocessing/SAOPass.js"),nc=require("three/examples/jsm/postprocessing/SSAOPass.js"),rc=require("three/examples/jsm/postprocessing/OutlinePass.js"),ac=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),oc=require("three/examples/jsm/postprocessing/BloomPass.js"),lc=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),cc=require("three/examples/jsm/shaders/FXAAShader.js"),hc=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),jr=require("lodash");function xs(c){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const e in c)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(c,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>c[e]})}}return t.default=c,Object.freeze(t)}const p=xs(D),Ur=xs(Sl),dc=xs(Fl),Xt=xs(Vl),uc=xs(Ul),Oi=1,dt=new p.Sphere,Sn=new p.Vector3,En=new p.Vector3,Hr=new p.Vector3,Nr=new p.Vector3;p.Line.prototype.raycast=function(c,t){const e=this.geometry,i=this.matrixWorld,s=c.params.Line.threshold,n=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),dt.copy(e.boundingSphere),dt.applyMatrix4(i),dt.radius+=s,c.ray.intersectsSphere(dt)===!1)return;const r=s*s,a=this.isLineSegments?2:1,o=e.index,l=e.attributes,h=l.position,d=t.length;if(o!==null){const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(dt.copy(m.boundingSphere),dt.applyMatrix4(i),c.ray.intersectsSphere(dt)!==!1)for(let b=m.indexStart,y=m.indexStart+m.indexCount-1;b<y;b+=a){const C=o.getX(b),w=o.getX(b+1);if(Ts(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=Oi))return}}else{const f=Math.max(0,n.start),m=Math.min(o.count,n.start+n.count);for(let b=f,y=m-1;b<y;b+=a){const C=o.getX(b),w=o.getX(b+1);if(Ts(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=Oi))return}}}else{const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(dt.copy(m.boundingSphere),dt.applyMatrix4(i),c.ray.intersectsSphere(dt)!==!1){for(let b=m.positionStart,y=m.positionStart+m.positionCount-1;b<y;b+=a)if(Ts(this,h,c,b,b+1,r,t)&&t.length-d>=Oi)return}}else{const f=Math.max(0,n.start),m=Math.min(h.count,n.start+n.count);for(let b=f,y=m-1;b<y;b+=a)if(Ts(this,h,c,b,b+1,r,t)&&t.length-d>=Oi)return}}};function Ts(c,t,e,i,s,n,r){if(Sn.fromBufferAttribute(t,i),Sn.applyMatrix4(c.matrixWorld),En.fromBufferAttribute(t,s),En.applyMatrix4(c.matrixWorld),e.ray.distanceSqToSegment(Sn,En,Nr,Hr)>n)return!1;const o=e.ray.origin.distanceTo(Nr);return o<e.near||o>e.far?!1:(r.push({distance:o,point:Hr.clone(),index:i,object:c}),!0)}const fc=p.Line,xo=0,pc=1,mc=2,Gr=2,On=1.25,qr=1,Ae=32,be=Ae/4,bo=65535,nn=Math.pow(2,-24),Cr=Symbol("SKIP_GENERATION"),wo={strategy:xo,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Cr]:!1};function ce(c,t,e){return e.min.x=t[c],e.min.y=t[c+1],e.min.z=t[c+2],e.max.x=t[c+3],e.max.y=t[c+4],e.max.z=t[c+5],e}function ar(c){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=c[i+3]-c[i];s>e&&(e=s,t=i)}return t}function Wr(c,t){t.set(c)}function Yr(c,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=c[n],s=t[n],e[n]=i<s?i:s,i=c[r],s=t[r],e[r]=i>s?i:s}}function Cs(c,t,e){for(let i=0;i<3;i++){const s=t[c+2*i],n=t[c+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function Hi(c){const t=c[3]-c[0],e=c[4]-c[1],i=c[5]-c[2];return 2*(t*e+e*i+i*t)}function he(c,t){return t[c+15]===bo}function Te(c,t){return t[c+6]}function Ie(c,t){return t[c+14]}function we(c){return c+be}function ve(c,t){const e=t[c+6];return c+e*be}function Sr(c,t){return t[c+7]}function _n(c,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0,d=1/0,u=1/0,f=1/0,m=-1/0,b=-1/0,y=-1/0;const C=c.offset||0;for(let w=(t-C)*6,x=(t+e-C)*6;w<x;w+=6){const E=c[w+0],M=c[w+1],O=E-M,S=E+M;O<n&&(n=O),S>o&&(o=S),E<d&&(d=E),E>m&&(m=E);const v=c[w+2],T=c[w+3],_=v-T,A=v+T;_<r&&(r=_),A>l&&(l=A),v<u&&(u=v),v>b&&(b=v);const I=c[w+4],B=c[w+5],k=I-B,L=I+B;k<a&&(a=k),L>h&&(h=L),I<f&&(f=I),I>y&&(y=I)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=l,i[5]=h,s[0]=d,s[1]=u,s[2]=f,s[3]=m,s[4]=b,s[5]=y}const Mt=32,gc=(c,t)=>c.candidate-t.candidate,It=new Array(Mt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ss=new Float32Array(6);function yc(c,t,e,i,s,n){let r=-1,a=0;if(n===xo)r=ar(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===pc)r=ar(c),r!==-1&&(a=xc(e,i,s,r));else if(n===mc){const o=Hi(c);let l=On*s;const h=e.offset||0,d=(i-h)*6,u=(i+s-h)*6;for(let f=0;f<3;f++){const m=t[f],C=(t[f+3]-m)/Mt;if(s<Mt/4){const w=[...It];w.length=s;let x=0;for(let M=d;M<u;M+=6,x++){const O=w[x];O.candidate=e[M+2*f],O.count=0;const{bounds:S,leftCacheBounds:v,rightCacheBounds:T}=O;for(let _=0;_<3;_++)T[_]=1/0,T[_+3]=-1/0,v[_]=1/0,v[_+3]=-1/0,S[_]=1/0,S[_+3]=-1/0;Cs(M,e,S)}w.sort(gc);let E=s;for(let M=0;M<E;M++){const O=w[M];for(;M+1<E&&w[M+1].candidate===O.candidate;)w.splice(M+1,1),E--}for(let M=d;M<u;M+=6){const O=e[M+2*f];for(let S=0;S<E;S++){const v=w[S];O>=v.candidate?Cs(M,e,v.rightCacheBounds):(Cs(M,e,v.leftCacheBounds),v.count++)}}for(let M=0;M<E;M++){const O=w[M],S=O.count,v=s-O.count,T=O.leftCacheBounds,_=O.rightCacheBounds;let A=0;S!==0&&(A=Hi(T)/o);let I=0;v!==0&&(I=Hi(_)/o);const B=qr+On*(A*S+I*v);B<l&&(r=f,l=B,a=O.candidate)}}else{for(let E=0;E<Mt;E++){const M=It[E];M.count=0,M.candidate=m+C+E*C;const O=M.bounds;for(let S=0;S<3;S++)O[S]=1/0,O[S+3]=-1/0}for(let E=d;E<u;E+=6){let S=~~((e[E+2*f]-m)/C);S>=Mt&&(S=Mt-1);const v=It[S];v.count++,Cs(E,e,v.bounds)}const w=It[Mt-1];Wr(w.bounds,w.rightCacheBounds);for(let E=Mt-2;E>=0;E--){const M=It[E],O=It[E+1];Yr(M.bounds,O.rightCacheBounds,M.rightCacheBounds)}let x=0;for(let E=0;E<Mt-1;E++){const M=It[E],O=M.count,S=M.bounds,T=It[E+1].rightCacheBounds;O!==0&&(x===0?Wr(S,Ss):Yr(S,Ss,Ss)),x+=O;let _=0,A=0;x!==0&&(_=Hi(Ss)/o);const I=s-x;I!==0&&(A=Hi(T)/o);const B=qr+On*(_*x+A*I);B<l&&(r=f,l=B,a=M.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function xc(c,t,e,i){let s=0;const n=c.offset;for(let r=t,a=t+e;r<a;r++)s+=c[(r-n)*6+i*2];return s/e}class Pn{constructor(){this.boundingData=new Float32Array(6)}}function bc(c,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,l=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+l]<o;)r++;for(;r<=a&&e[(a-h)*6+l]>=o;)a--;if(r<a){for(let d=0;d<t;d++){let u=c[r*t+d];c[r*t+d]=c[a*t+d],c[a*t+d]=u}for(let d=0;d<6;d++){const u=r-h,f=a-h,m=e[u*6+d];e[u*6+d]=e[f*6+d],e[f*6+d]=m}r++,a--}else return r}}let vo,rn,or,Mo;const wc=Math.pow(2,32);function lr(c){return"count"in c?1:1+lr(c.left)+lr(c.right)}function vc(c,t,e){return vo=new Float32Array(e),rn=new Uint32Array(e),or=new Uint16Array(e),Mo=new Uint8Array(e),cr(c,t)}function cr(c,t){const e=c/4,i=c/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)vo[e+r]=n[r];if(s)return t.buffer?(Mo.set(new Uint8Array(t.buffer),c),c+t.buffer.byteLength):(rn[e+6]=t.offset,or[i+14]=t.count,or[i+15]=bo,c+Ae);{const{left:r,right:a,splitAxis:o}=t,l=c+Ae;let h=cr(l,r);const d=c/Ae,f=h/Ae-d;if(f>wc)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return rn[e+6]=f,rn[e+7]=o,cr(h,a)}}function Mc(c,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:l=1/0,strategy:h,onProgress:d}=s,u=c.primitiveBuffer,f=c.primitiveBufferStride,m=new Float32Array(6);let b=!1;const y=new Pn;return _n(t,e,i,y.boundingData,m),w(y,e,i,m),y;function C(x){d&&d((x-n.offset)/n.count)}function w(x,E,M,O=null,S=0){!b&&S>=r&&(b=!0,a&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const v=M>l;if(M<=o&&!v||S>=r)return C(E+M),x.offset=E,x.count=M,x;const T=yc(x.boundingData,O,t,E,M,h);let _=T.axis===-1?-1:bc(u,f,t,E,M,T);if(T.axis===-1||_===E||_===E+M){if(!v)return C(E+M),x.offset=E,x.count=M,x;T.axis=Math.max(0,ar(x.boundingData)),_=E+Math.max(1,Math.floor(M/2))}x.splitAxis=T.axis;const A=new Pn,I=E,B=_-E;x.left=A,_n(t,I,B,A.boundingData,m),w(A,I,B,m,S+1);const k=new Pn,L=_,F=M-B;return x.right=k,_n(t,L,F,k.boundingData,m),w(k,L,F,m,S+1),x}}function Tc(c,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=c.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,c.computePrimitiveBounds(r.offset,r.count,a),c._roots=i.map(o=>{const l=Mc(c,a,o.offset,o.count,t,r),h=lr(l),d=new e(Ae*h);return vc(0,l,d),d})}class Er{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Cc{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const ne=new Cc;let Ft,_i;const oi=[],Es=new Er(()=>new D.Box3);function Sc(c,t,e,i,s,n){Ft=Es.getPrimitive(),_i=Es.getPrimitive(),oi.push(Ft,_i),ne.setBuffer(c._roots[t]);const r=hr(0,c.geometry,e,i,s,n);ne.clearBuffer(),Es.releasePrimitive(Ft),Es.releasePrimitive(_i),oi.pop(),oi.pop();const a=oi.length;return a>0&&(_i=oi[a-1],Ft=oi[a-2]),r}function hr(c,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:l}=ne;let h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);return ce(c,a,Ft),i(u,f,!1,r,n+c/be,Ft)}else{let _=function(I){const{uint16Array:B,uint32Array:k}=ne;let L=I*2;for(;!he(L,B);)I=we(I),L=I*2;return Te(I,k)},A=function(I){const{uint16Array:B,uint32Array:k}=ne;let L=I*2;for(;!he(L,B);)I=ve(I,k),L=I*2;return Te(I,k)+Ie(L,B)};const u=we(c),f=ve(c,l);let m=u,b=f,y,C,w,x;if(s&&(w=Ft,x=_i,ce(m,a,w),ce(b,a,x),y=s(w),C=s(x),C<y)){m=f,b=u;const I=y;y=C,C=I,w=x}w||(w=Ft,ce(m,a,w));const E=he(m*2,o),M=e(w,E,y,r+1,n+m/be);let O;if(M===Gr){const I=_(m),k=A(m)-I;O=i(I,k,!0,r+1,n+m/be,w)}else O=M&&hr(m,t,e,i,s,n,r+1);if(O)return!0;x=_i,ce(b,a,x);const S=he(b*2,o),v=e(x,S,C,r+1,n+b/be);let T;if(v===Gr){const I=_(b),k=A(b)-I;T=i(I,k,!0,r+1,n+b/be,x)}else T=v&&hr(b,t,e,i,s,n,r+1);return!!T}}const rs=new ne.constructor,fn=new ne.constructor,Dt=new Er(()=>new D.Box3),li=new D.Box3,ci=new D.Box3,An=new D.Box3,In=new D.Box3;let Bn=!1;function Ec(c,t,e,i){if(Bn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Bn=!0;const s=c._roots,n=t._roots;let r,a=0,o=0;const l=new D.Matrix4().copy(e).invert();for(let h=0,d=s.length;h<d;h++){rs.setBuffer(s[h]),o=0;const u=Dt.getPrimitive();ce(0,rs.float32Array,u),u.applyMatrix4(l);for(let f=0,m=n.length;f<m&&(fn.setBuffer(n[f]),r=nt(0,0,e,l,i,a,o,0,0,u),fn.clearBuffer(),o+=n[f].byteLength/Ae,!r);f++);if(Dt.releasePrimitive(u),rs.clearBuffer(),a+=s[h].byteLength/Ae,r)break}return Bn=!1,r}function nt(c,t,e,i,s,n=0,r=0,a=0,o=0,l=null,h=!1){let d,u;h?(d=fn,u=rs):(d=rs,u=fn);const f=d.float32Array,m=d.uint32Array,b=d.uint16Array,y=u.float32Array,C=u.uint32Array,w=u.uint16Array,x=c*2,E=t*2,M=he(x,b),O=he(E,w);let S=!1;if(O&&M)h?S=s(Te(t,C),Ie(t*2,w),Te(c,m),Ie(c*2,b),o,r+t/be,a,n+c/be):S=s(Te(c,m),Ie(c*2,b),Te(t,C),Ie(t*2,w),a,n+c/be,o,r+t/be);else if(O){const v=Dt.getPrimitive();ce(t,y,v),v.applyMatrix4(e);const T=we(c),_=ve(c,m);ce(T,f,li),ce(_,f,ci);const A=v.intersectsBox(li),I=v.intersectsBox(ci);S=A&&nt(t,T,i,e,s,r,n,o,a+1,v,!h)||I&&nt(t,_,i,e,s,r,n,o,a+1,v,!h),Dt.releasePrimitive(v)}else{const v=we(t),T=ve(t,C);ce(v,y,An),ce(T,y,In);const _=l.intersectsBox(An),A=l.intersectsBox(In);if(_&&A)S=nt(c,v,e,i,s,n,r,a,o+1,l,h)||nt(c,T,e,i,s,n,r,a,o+1,l,h);else if(_)if(M)S=nt(c,v,e,i,s,n,r,a,o+1,l,h);else{const I=Dt.getPrimitive();I.copy(An).applyMatrix4(e);const B=we(c),k=ve(c,m);ce(B,f,li),ce(k,f,ci);const L=I.intersectsBox(li),F=I.intersectsBox(ci);S=L&&nt(v,B,i,e,s,r,n,o,a+1,I,!h)||F&&nt(v,k,i,e,s,r,n,o,a+1,I,!h),Dt.releasePrimitive(I)}else if(A)if(M)S=nt(c,T,e,i,s,n,r,a,o+1,l,h);else{const I=Dt.getPrimitive();I.copy(In).applyMatrix4(e);const B=we(c),k=ve(c,m);ce(B,f,li),ce(k,f,ci);const L=I.intersectsBox(li),F=I.intersectsBox(ci);S=L&&nt(T,B,i,e,s,r,n,o,a+1,I,!h)||F&&nt(T,k,i,e,s,r,n,o,a+1,I,!h),Dt.releasePrimitive(I)}}return S}const kn=new class{constructor(){let c=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=c=n._roots[r],this.uint16Array=e=new Uint16Array(c),this.uint32Array=t=new Uint32Array(c)},this.reset=()=>{this.root=null,this.buffer=c=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!he(r,e);)n=we(n),r=n*2;return Te(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!he(r,e);)n=ve(n,t),r=n*2;return Te(n,t)+Ie(r,e)};const s=(n,r,a)=>{const o=r*2,l=he(o,e);if(!n(a,l,r)&&!l){const d=we(r),u=ve(r,t);s(n,d,a+1),s(n,u,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const l=o*2,h=t[o+6],d=e[l+14];return n(r,a,new Float32Array(c,o*4,6),h,d)}else{const l=Sr(o,t);return n(r,a,new Float32Array(c,o*4,6),l)}})}}},Xr=new D.Box3,hi=new Float32Array(6);class Oc{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...wo,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Tc(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0;for(let d=t,u=t+e;d<u;d++){this.writePrimitiveBounds(d,hi,0);const[f,m,b,y,C,w]=hi;f<n&&(n=f),y>o&&(o=y),m<r&&(r=m),C>l&&(l=C),b<a&&(a=b),w>h&&(h=w)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=l,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,hi,0);const[a,o,l,h,d,u]=hi,f=(a+h)/2,m=(o+d)/2,b=(l+u)/2,y=(h-a)/2,C=(d-o)/2,w=(u-l)/2,x=(n-s)*6;i[x+0]=f,i[x+1]=y+(Math.abs(f)+y)*nn,i[x+2]=m,i[x+3]=C+(Math.abs(m)+C)*nn,i[x+4]=b,i[x+5]=w+(Math.abs(b)+w)*nn}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/Ae;for(let l=0;l<o;l++){const h=be*l,d=2*h;he(d,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){kn.setBVH(this,e),kn.traverse(t),kn.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/Ae;for(let l=o-1;l>=0;l--){const h=l*be,d=h*2;if(he(d,r)){const f=Te(h,n),m=Ie(d,r);this.writePrimitiveRangeBounds(f,m,hi,0),a.set(hi,h)}else{const f=we(h),m=ve(h,n);for(let b=0;b<3;b++){const y=a[f+b],C=a[f+b+3],w=a[m+b],x=a[m+b+3];a[h+b]=y<w?y:w,a[h+b+3]=C>x?C:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{ce(0,new Float32Array(i),Xr),t.union(Xr)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const d=s;s=(u,f,m,b,y)=>d(u,f,m,b,y)?!0:a(u,f,this,n,m,b,r)}else s||(n?s=(d,u,f,m)=>a(d,u,this,n,f,m,r):s=(d,u,f)=>f);let o=!1,l=0;const h=this._roots;for(let d=0,u=h.length;d<u;d++){const f=h[d];if(o=Sc(this,d,i,s,e,l),o)break;l+=f.byteLength/Ae}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Ec(this,t,e,s)}}function _c(){return typeof SharedArrayBuffer<"u"}function Or(c){return c.index?c.index.count:c.attributes.position.count}function bn(c){return Or(c)/3}function Pc(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function Ac(c,t){if(!c.index){const e=c.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Pc(e,i);c.setIndex(new D.BufferAttribute(s,1));for(let n=0;n<e;n++)s[n]=n}}function Ic(c,t,e){const i=Or(c)/e,s=t||c.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function Bc(c,t){return c.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Zr(c,t,e){const i=Ic(c,t,e),s=Bc(c,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Or(c)/e,l=[];for(const u of s){const{offset:f,count:m}=u,b=f,y=isFinite(m)?m:o-f,C=f+y;b<a&&C>r&&(l.push({pos:Math.max(r,b),isStart:!0}),l.push({pos:Math.min(a,C),isStart:!1}))}l.sort((u,f)=>u.pos!==f.pos?u.pos-f.pos:u.type==="end"?-1:1);let h=0,d=null;for(const u of l){const f=u.pos;h!==0&&f!==d&&n.push({offset:d,count:f-d}),h+=u.isStart?1:-1,d=f}return n}function kc(c,t){const e=c[c.length-1],i=e.offset+e.count>2**16,s=c.reduce((l,h)=>l+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let l=0;l<c.length;l++){const{offset:h,count:d}=c[l];for(let u=0;u<d;u++)a[o+u]=h+u;o+=d}return a}class Dc extends Oc{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!_c())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...wo,...e},e[Cr]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Zr(e,t.range,i),n=kc(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else Ac(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new D.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Zr(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class Pt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}Pt.prototype.setFromBox=(function(){const c=new D.Vector3;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){c.x=s.x*o+n.x*(1-o),c.y=s.y*l+n.y*(1-l),c.z=s.z*h+n.z*(1-h);const d=e.dot(c);r=Math.min(d,r),a=Math.max(d,a)}this.min=r,this.max=a}})();const Lc=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Vector3;return function(s,n,r){const a=s.start,o=c,l=n.start,h=t;e.subVectors(a,l),c.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const d=e.dot(h),u=h.dot(o),f=h.dot(h),m=e.dot(o),y=o.dot(o)*f-u*u;let C,w;y!==0?C=(d*u-m*f)/y:C=0,w=(d+C*u)/f,r.x=C,r.y=w}})(),_r=(function(){const c=new D.Vector2,t=new D.Vector3,e=new D.Vector3;return function(s,n,r,a){Lc(s,n,c);let o=c.x,l=c.y;if(o>=0&&o<=1&&l>=0&&l<=1){s.at(o,r),n.at(l,a);return}else if(o>=0&&o<=1){l<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(l>=0&&l<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let d;l<0?d=n.start:d=n.end;const u=t,f=e;if(s.closestPointToPoint(d,!0,t),n.closestPointToPoint(h,!0,e),u.distanceToSquared(d)<=f.distanceToSquared(h)){r.copy(u),a.copy(d);return}else{r.copy(h),a.copy(f);return}}}})(),Rc=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Plane,i=new D.Line3;return function(n,r){const{radius:a,center:o}=n,{a:l,b:h,c:d}=r;if(i.start=l,i.end=h,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a||(i.start=l,i.end=d,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a)||(i.start=h,i.end=d,i.closestPointToPoint(o,!0,c).distanceTo(o)<=a))return!0;const b=r.getPlane(e);if(Math.abs(b.distanceToPoint(o))<=a){const C=b.projectPoint(o,t);if(r.containsPoint(C))return!0}return!1}})(),Fc=["x","y","z"],St=1e-15,Kr=St*St;function Ye(c){return Math.abs(c)<St}class lt extends D.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new D.Vector3),this.satBounds=new Array(4).fill().map(()=>new Pt),this.points=[this.a,this.b,this.c],this.plane=new D.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new D.Line3,this.needsUpdate=!0}intersectsSphere(t){return Rc(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const l=n[1],h=r[1];l.subVectors(t,e),h.setFromPoints(l,s);const d=n[2],u=r[2];d.subVectors(e,i),u.setFromPoints(d,s);const f=n[3],m=r[3];f.subVectors(i,t),m.setFromPoints(f,s);const b=l.length(),y=d.length(),C=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,b<St?y<St||C<St?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):y<St?C<St?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):C<St&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}lt.prototype.closestPointToSegment=(function(){const c=new D.Vector3,t=new D.Vector3,e=new D.Line3;return function(s,n=null,r=null){const{start:a,end:o}=s,l=this.points;let h,d=1/0;for(let u=0;u<3;u++){const f=(u+1)%3;e.start.copy(l[u]),e.end.copy(l[f]),_r(e,s,c,t),h=c.distanceToSquared(t),h<d&&(d=h,n&&n.copy(c),r&&r.copy(t))}return this.closestPointToPoint(a,c),h=a.distanceToSquared(c),h<d&&(d=h,n&&n.copy(c),r&&r.copy(a)),this.closestPointToPoint(o,c),h=o.distanceToSquared(c),h<d&&(d=h,n&&n.copy(c),r&&r.copy(o)),Math.sqrt(d)}})();lt.prototype.intersectsTriangle=(function(){const c=new lt,t=new Pt,e=new Pt,i=new D.Vector3,s=new D.Vector3,n=new D.Vector3,r=new D.Vector3,a=new D.Line3,o=new D.Line3,l=new D.Vector3,h=new D.Vector2,d=new D.Vector2;function u(x,E,M,O){const S=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?S.copy(x.plane.normal):S.copy(E.plane.normal);const v=x.satBounds,T=x.satAxes;for(let I=1;I<4;I++){const B=v[I],k=T[I];if(t.setFromPoints(k,E.points),B.isSeparated(t)||(r.copy(S).cross(k),t.setFromPoints(r,x.points),e.setFromPoints(r,E.points),t.isSeparated(e)))return!1}const _=E.satBounds,A=E.satAxes;for(let I=1;I<4;I++){const B=_[I],k=A[I];if(t.setFromPoints(k,x.points),B.isSeparated(t)||(r.crossVectors(S,k),t.setFromPoints(r,x.points),e.setFromPoints(r,E.points),t.isSeparated(e)))return!1}return M&&(O||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),M.start.set(0,0,0),M.end.set(0,0,0)),!0}function f(x,E,M,O,S,v,T,_,A,I,B){let k=T/(T-_);I.x=O+(S-O)*k,B.start.subVectors(E,x).multiplyScalar(k).add(x),k=T/(T-A),I.y=O+(v-O)*k,B.end.subVectors(M,x).multiplyScalar(k).add(x)}function m(x,E,M,O,S,v,T,_,A,I,B){if(S>0)f(x.c,x.a,x.b,O,E,M,A,T,_,I,B);else if(v>0)f(x.b,x.a,x.c,M,E,O,_,T,A,I,B);else if(_*A>0||T!=0)f(x.a,x.b,x.c,E,M,O,T,_,A,I,B);else if(_!=0)f(x.b,x.a,x.c,M,E,O,_,T,A,I,B);else if(A!=0)f(x.c,x.a,x.b,O,E,M,A,T,_,I,B);else return!0;return!1}function b(x,E,M,O){const S=E.degenerateSegment,v=x.plane.distanceToPoint(S.start),T=x.plane.distanceToPoint(S.end);return Ye(v)?Ye(T)?u(x,E,M,O):(M&&(M.start.copy(S.start),M.end.copy(S.start)),x.containsPoint(S.start)):Ye(T)?(M&&(M.start.copy(S.end),M.end.copy(S.end)),x.containsPoint(S.end)):x.plane.intersectLine(S,i)!=null?(M&&(M.start.copy(i),M.end.copy(i)),x.containsPoint(i)):!1}function y(x,E,M){const O=E.a;return Ye(x.plane.distanceToPoint(O))&&x.containsPoint(O)?(M&&(M.start.copy(O),M.end.copy(O)),!0):!1}function C(x,E,M){const O=x.degenerateSegment,S=E.a;return O.closestPointToPoint(S,!0,i),S.distanceToSquared(i)<Kr?(M&&(M.start.copy(S),M.end.copy(S)),!0):!1}function w(x,E,M,O){if(x.isDegenerateIntoSegment)if(E.isDegenerateIntoSegment){const S=x.degenerateSegment,v=E.degenerateSegment,T=s,_=n;S.delta(T),v.delta(_);const A=i.subVectors(v.start,S.start),I=T.x*_.y-T.y*_.x;if(Ye(I))return!1;const B=(A.x*_.y-A.y*_.x)/I,k=-(T.x*A.y-T.y*A.x)/I;if(B<0||B>1||k<0||k>1)return!1;const L=S.start.z+T.z*B,F=v.start.z+_.z*k;return Ye(L-F)?(M&&(M.start.copy(S.start).addScaledVector(T,B),M.end.copy(S.start).addScaledVector(T,B)),!0):!1}else return E.isDegenerateIntoPoint?C(x,E,M):b(E,x,M,O);else{if(x.isDegenerateIntoPoint)return E.isDegenerateIntoPoint?E.a.distanceToSquared(x.a)<Kr?(M&&(M.start.copy(x.a),M.end.copy(x.a)),!0):!1:E.isDegenerateIntoSegment?C(E,x,M):y(E,x,M);if(E.isDegenerateIntoPoint)return y(x,E,M);if(E.isDegenerateIntoSegment)return b(x,E,M,O)}}return function(E,M=null,O=!1){this.needsUpdate&&this.update(),E.isExtendedTriangle?E.needsUpdate&&E.update():(c.copy(E),c.update(),E=c);const S=w(this,E,M,O);if(S!==void 0)return S;const v=this.plane,T=E.plane;let _=T.distanceToPoint(this.a),A=T.distanceToPoint(this.b),I=T.distanceToPoint(this.c);Ye(_)&&(_=0),Ye(A)&&(A=0),Ye(I)&&(I=0);const B=_*A,k=_*I;if(B>0&&k>0)return!1;let L=v.distanceToPoint(E.a),F=v.distanceToPoint(E.b),ie=v.distanceToPoint(E.c);Ye(L)&&(L=0),Ye(F)&&(F=0),Ye(ie)&&(ie=0);const se=L*F,Fe=L*ie;if(se>0&&Fe>0)return!1;s.copy(v.normal),n.copy(T.normal);const ht=s.cross(n);let Me=0,Vi=Math.abs(ht.x);const et=Math.abs(ht.y);et>Vi&&(Vi=et,Me=1),Math.abs(ht.z)>Vi&&(Me=2);const ke=Fc[Me],At=this.a[ke],ji=this.b[ke],Gt=this.c[ke],qt=E.a[ke],Wt=E.b[ke],Yt=E.c[ke];if(m(this,At,ji,Gt,B,k,_,A,I,h,a))return u(this,E,M,O);if(m(E,qt,Wt,Yt,se,Fe,L,F,ie,d,o))return u(this,E,M,O);if(h.y<h.x){const Cn=h.y;h.y=h.x,h.x=Cn,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(d.y<d.x){const Cn=d.y;d.y=d.x,d.x=Cn,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}return h.y<d.x||d.y<h.x?!1:(M&&(d.x>h.x?M.start.copy(o.start):M.start.copy(a.start),d.y<h.y?M.end.copy(o.end):M.end.copy(a.end)),!0)}})();lt.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();lt.prototype.distanceToTriangle=(function(){const c=new D.Vector3,t=new D.Vector3,e=["a","b","c"],i=new D.Line3,s=new D.Line3;return function(r,a=null,o=null){const l=a||o?i:null;if(this.intersectsTriangle(r,l,!0))return(a||o)&&(a&&l.getCenter(a),o&&l.getCenter(o)),0;let h=1/0;for(let d=0;d<3;d++){let u;const f=e[d],m=r[f];this.closestPointToPoint(m,c),u=m.distanceToSquared(c),u<h&&(h=u,a&&a.copy(c),o&&o.copy(m));const b=this[f];r.closestPointToPoint(b,c),u=b.distanceToSquared(c),u<h&&(h=u,a&&a.copy(b),o&&o.copy(c))}for(let d=0;d<3;d++){const u=e[d],f=e[(d+1)%3];i.set(this[u],this[f]);for(let m=0;m<3;m++){const b=e[m],y=e[(m+1)%3];s.set(r[b],r[y]),_r(i,s,c,t);const C=c.distanceToSquared(t);C<h&&(h=C,a&&a.copy(c),o&&o.copy(t))}}return Math.sqrt(h)}})();class Le{constructor(t,e,i){this.isOrientedBox=!0,this.min=new D.Vector3,this.max=new D.Vector3,this.matrix=new D.Matrix4,this.invMatrix=new D.Matrix4,this.points=new Array(8).fill().map(()=>new D.Vector3),this.satAxes=new Array(3).fill().map(()=>new D.Vector3),this.satBounds=new Array(3).fill().map(()=>new Pt),this.alignedSatBounds=new Array(3).fill().map(()=>new Pt),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}Le.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let d=0;d<=1;d++){const u=1*l|2*h|4*d,f=s[u];f.x=l?i.x:e.x,f.y=h?i.y:e.y,f.z=d?i.z:e.z,f.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let l=0;l<3;l++){const h=r[l],d=n[l],u=1<<l,f=s[u];h.subVectors(a,f),d.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();Le.prototype.intersectsBox=(function(){const c=new Pt;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(c.min=i.x,c.max=s.x,a[0].isSeparated(c)||(c.min=i.y,c.max=s.y,a[1].isSeparated(c))||(c.min=i.z,c.max=s.z,a[2].isSeparated(c)))return!1;for(let o=0;o<3;o++){const l=r[o],h=n[o];if(c.setFromBox(l,e),h.isSeparated(c))return!1}return!0}})();Le.prototype.intersectsTriangle=(function(){const c=new lt,t=new Array(3),e=new Pt,i=new Pt,s=new D.Vector3;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(c.copy(r),c.update(),r=c);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let u=0;u<3;u++){const f=a[u],m=o[u];if(e.setFromPoints(m,t),f.isSeparated(e))return!1}const l=r.satBounds,h=r.satAxes,d=this.points;for(let u=0;u<3;u++){const f=l[u],m=h[u];if(e.setFromPoints(m,d),f.isSeparated(e))return!1}for(let u=0;u<3;u++){const f=o[u];for(let m=0;m<4;m++){const b=h[m];if(s.crossVectors(f,b),e.setFromPoints(s,t),i.setFromPoints(s,d),e.isSeparated(i))return!1}}return!0}})();Le.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}})();Le.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();Le.prototype.distanceToBox=(function(){const c=["x","y","z"],t=new Array(12).fill().map(()=>new D.Line3),e=new Array(12).fill().map(()=>new D.Line3),i=new D.Vector3,s=new D.Vector3;return function(r,a=0,o=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||l)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),l&&l.copy(s)),0;const h=a*a,d=r.min,u=r.max,f=this.points;let m=1/0;for(let y=0;y<8;y++){const C=f[y];s.copy(C).clamp(d,u);const w=C.distanceToSquared(s);if(w<m&&(m=w,o&&o.copy(C),l&&l.copy(s),w<h))return Math.sqrt(w)}let b=0;for(let y=0;y<3;y++)for(let C=0;C<=1;C++)for(let w=0;w<=1;w++){const x=(y+1)%3,E=(y+2)%3,M=C<<x|w<<E,O=1<<y|C<<x|w<<E,S=f[M],v=f[O];t[b].set(S,v);const _=c[y],A=c[x],I=c[E],B=e[b],k=B.start,L=B.end;k[_]=d[_],k[A]=C?d[A]:u[A],k[I]=w?d[I]:u[A],L[_]=u[_],L[A]=C?d[A]:u[A],L[I]=w?d[I]:u[A],b++}for(let y=0;y<=1;y++)for(let C=0;C<=1;C++)for(let w=0;w<=1;w++){s.x=y?u.x:d.x,s.y=C?u.y:d.y,s.z=w?u.z:d.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<m&&(m=x,o&&o.copy(i),l&&l.copy(s),x<h))return Math.sqrt(x)}for(let y=0;y<12;y++){const C=t[y];for(let w=0;w<12;w++){const x=e[w];_r(C,x,i,s);const E=i.distanceToSquared(s);if(E<m&&(m=E,o&&o.copy(i),l&&l.copy(s),E<h))return Math.sqrt(E)}}return Math.sqrt(m)}})();class zc extends Er{constructor(){super(()=>new lt)}}const Qe=new zc,Ni=new D.Vector3,Dn=new D.Vector3;function Vc(c,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(c.shapecast({boundsTraverseOrder:h=>(Ni.copy(t).clamp(h.min,h.max),Ni.distanceToSquared(t)),intersectsBounds:(h,d,u)=>u<a&&u<r,intersectsTriangle:(h,d)=>{h.closestPointToPoint(t,Ni);const u=t.distanceToSquared(Ni);return u<a&&(Dn.copy(Ni),a=u,o=d),u<n}}),a===1/0)return null;const l=Math.sqrt(a);return e.point?e.point.copy(Dn):e.point=Dn.clone(),e.distance=l,e.faceIndex=o,e}const Os=parseInt(D.REVISION)>=169,jc=parseInt(D.REVISION)<=161,Zt=new D.Vector3,Kt=new D.Vector3,$t=new D.Vector3,_s=new D.Vector2,Ps=new D.Vector2,As=new D.Vector2,$r=new D.Vector3,Jr=new D.Vector3,Qr=new D.Vector3,Gi=new D.Vector3;function Uc(c,t,e,i,s,n,r,a){let o;if(n===D.BackSide?o=c.intersectTriangle(i,e,t,!0,s):o=c.intersectTriangle(t,e,i,n!==D.DoubleSide,s),o===null)return null;const l=c.origin.distanceTo(s);return l<r||l>a?null:{distance:l,point:s.clone()}}function ea(c,t,e,i,s,n,r,a,o,l,h){Zt.fromBufferAttribute(t,n),Kt.fromBufferAttribute(t,r),$t.fromBufferAttribute(t,a);const d=Uc(c,Zt,Kt,$t,Gi,o,l,h);if(d){if(i){_s.fromBufferAttribute(i,n),Ps.fromBufferAttribute(i,r),As.fromBufferAttribute(i,a),d.uv=new D.Vector2;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,_s,Ps,As,d.uv);Os||(d.uv=f)}if(s){_s.fromBufferAttribute(s,n),Ps.fromBufferAttribute(s,r),As.fromBufferAttribute(s,a),d.uv1=new D.Vector2;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,_s,Ps,As,d.uv1);Os||(d.uv1=f),jc&&(d.uv2=d.uv1)}if(e){$r.fromBufferAttribute(e,n),Jr.fromBufferAttribute(e,r),Qr.fromBufferAttribute(e,a),d.normal=new D.Vector3;const f=D.Triangle.getInterpolation(Gi,Zt,Kt,$t,$r,Jr,Qr,d.normal);d.normal.dot(c.direction)>0&&d.normal.multiplyScalar(-1),Os||(d.normal=f)}const u={a:n,b:r,c:a,normal:new D.Vector3,materialIndex:0};if(D.Triangle.getNormal(Zt,Kt,$t,u.normal),d.face=u,d.faceIndex=n,Os){const f=new D.Vector3;D.Triangle.getBarycoord(Gi,Zt,Kt,$t,f),d.barycoord=f}}return d}function ta(c){return c&&c.isMaterial?c.side:c}function wn(c,t,e,i,s,n,r){const a=i*3;let o=a+0,l=a+1,h=a+2;const{index:d,groups:u}=c;c.index&&(o=d.getX(o),l=d.getX(l),h=d.getX(h));const{position:f,normal:m,uv:b,uv1:y}=c.attributes;if(Array.isArray(t)){const C=i*3;for(let w=0,x=u.length;w<x;w++){const{start:E,count:M,materialIndex:O}=u[w];if(C>=E&&C<E+M){const S=ta(t[O]),v=ea(e,f,m,b,y,o,l,h,S,n,r);if(v)if(v.faceIndex=i,v.face.materialIndex=O,s)s.push(v);else return v}}}else{const C=ta(t),w=ea(e,f,m,b,y,o,l,h,C,n,r);if(w)if(w.faceIndex=i,w.face.materialIndex=0,s)s.push(w);else return w}return null}function pe(c,t,e,i){const s=c.a,n=c.b,r=c.c;let a=t,o=t+1,l=t+2;e&&(a=e.getX(a),o=e.getX(o),l=e.getX(l)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(l),r.y=i.getY(l),r.z=i.getZ(l)}function Hc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++)wn(o,t,e,h,n,r,a)}function Nc(c,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=c;let l=1/0,h=null;for(let d=i,u=i+s;d<u;d++){let f;f=wn(a,t,e,d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Gc(c,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,l=a.attributes.position;for(let h=c,d=t+c;h<d;h++){let u;if(u=h,pe(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function qc(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=c.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,l=0;const h=c._roots;for(let u=0,f=h.length;u<f;u++)n=h[u],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),d(0,l),l+=n.byteLength;function d(u,f,m=!1){const b=u*2;if(he(b,a)){const y=Te(u,r),C=Ie(b,a);let w=1/0,x=1/0,E=1/0,M=-1/0,O=-1/0,S=-1/0;for(let v=3*y,T=3*(y+C);v<T;v++){let _=i[v];const A=s.getX(_),I=s.getY(_),B=s.getZ(_);A<w&&(w=A),A>M&&(M=A),I<x&&(x=I),I>O&&(O=I),B<E&&(E=B),B>S&&(S=B)}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==E||o[u+3]!==M||o[u+4]!==O||o[u+5]!==S?(o[u+0]=w,o[u+1]=x,o[u+2]=E,o[u+3]=M,o[u+4]=O,o[u+5]=S,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,E=!1;if(t){if(!w){const _=y/be+f/Ae,A=C/be+f/Ae;x=t.has(_),E=t.has(A),w=!x&&!E}}else x=!0,E=!0;const M=w||x,O=w||E;let S=!1;M&&(S=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=S||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],L=o[I],F=o[I+3];o[u+_]=B<L?B:L,o[u+_+3]=k>F?k:F}return T}}}function jt(c,t,e,i,s){let n,r,a,o,l,h;const d=1/e.direction.x,u=1/e.direction.y,f=1/e.direction.z,m=e.origin.x,b=e.origin.y,y=e.origin.z;let C=t[c],w=t[c+3],x=t[c+1],E=t[c+3+1],M=t[c+2],O=t[c+3+2];return d>=0?(n=(C-m)*d,r=(w-m)*d):(n=(w-m)*d,r=(C-m)*d),u>=0?(a=(x-b)*u,o=(E-b)*u):(a=(E-b)*u,o=(x-b)*u),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),f>=0?(l=(M-y)*f,h=(O-y)*f):(l=(O-y)*f,h=(M-y)*f),n>h||l>r)?!1:((l>n||n!==n)&&(n=l),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function Wc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++){let u=l?l[h]:h;wn(o,t,e,u,n,r,a)}}function Yc(c,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=c;let l=1/0,h=null;for(let d=i,u=i+s;d<u;d++){let f;f=wn(a,t,e,o?o[d]:d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Xc(c,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,l=a.attributes.position;for(let h=c,d=t+c;h<d;h++){let u;if(u=e.resolveTriangleIndex(h),pe(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function Zc(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),dr(0,c,e,i,s,n,r),ne.clearBuffer()}function dr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);Hc(t,e,i,u,f,s,n,r)}else{const u=we(c);jt(u,a,i,n,r)&&dr(u,t,e,i,s,n,r);const f=ve(c,l);jt(f,a,i,n,r)&&dr(f,t,e,i,s,n,r)}}const Kc=["x","y","z"];function $c(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=ur(0,c,e,i,s,n);return ne.clearBuffer(),r}function ur(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(he(l,a)){const d=Te(c,o),u=Ie(l,a);return Nc(t,e,i,d,u,s,n)}else{const d=Sr(c,o),u=Kc[d],m=i.direction[u]>=0;let b,y;m?(b=we(c),y=ve(c,o)):(b=ve(c,o),y=we(c));const w=jt(b,r,i,s,n)?ur(b,t,e,i,s,n):null;if(w){const M=w.point[u];if(m?M<=r[y+d]:M>=r[y+d+3])return w}const E=jt(y,r,i,s,n)?ur(y,t,e,i,s,n):null;return w&&E?w.distance<=E.distance?w:E:w||E||null}}const Is=new D.Box3,di=new lt,ui=new lt,qi=new D.Matrix4,ia=new Le,Bs=new Le;function Jc(c,t,e,i){ne.setBuffer(c._roots[t]);const s=fr(0,c,e,i);return ne.clearBuffer(),s}function fr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),ia.set(e.boundingBox.min,e.boundingBox.max,i),s=ia),he(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Te(c,a),y=Ie(o,r);if(qi.copy(i).invert(),e.boundsTree)return ce(c,n,Bs),Bs.matrix.copy(qi),Bs.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Bs.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b*3,E=(y+b)*3;x<E;x+=3)if(pe(ui,x,d,u),ui.needsUpdate=!0,w.intersectsTriangle(ui))return!0;return!1}});{const C=bn(e);for(let w=b*3,x=(y+b)*3;w<x;w+=3){pe(di,w,d,u),di.a.applyMatrix4(qi),di.b.applyMatrix4(qi),di.c.applyMatrix4(qi),di.needsUpdate=!0;for(let E=0,M=C*3;E<M;E+=3)if(pe(ui,E,f,m),ui.needsUpdate=!0,di.intersectsTriangle(ui))return!0}}}else{const h=we(c),d=ve(c,a);return ce(h,n,Is),!!(s.intersectsBox(Is)&&fr(h,t,e,i,s)||(ce(d,n,Is),s.intersectsBox(Is)&&fr(d,t,e,i,s)))}}const ks=new D.Matrix4,Ln=new Le,Wi=new Le,Qc=new D.Vector3,eh=new D.Vector3,th=new D.Vector3,ih=new D.Vector3;function sh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Ln.set(t.boundingBox.min,t.boundingBox.max,e),Ln.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Qe.getPrimitive(),f=Qe.getPrimitive();let m=Qc,b=eh,y=null,C=null;s&&(y=th,C=ih);let w=1/0,x=null,E=null;return ks.copy(e).invert(),Wi.matrix.copy(ks),c.shapecast({boundsTraverseOrder:M=>Ln.distanceToBox(M),intersectsBounds:(M,O,S)=>S<w&&S<r?(O&&(Wi.min.copy(M.min),Wi.max.copy(M.max),Wi.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:v=>Wi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,A=v+T;_<A;_++){pe(f,3*_,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let I=M,B=M+O;I<B;I++){pe(u,3*I,l,o),u.needsUpdate=!0;const k=u.distanceToTriangle(f,m,y);if(k<w&&(b.copy(m),C&&C.copy(y),w=k,x=I,E=_),k<n)return!0}}}});{const S=bn(t);for(let v=0,T=S;v<T;v++){pe(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=M,A=M+O;_<A;_++){pe(u,3*_,l,o),u.needsUpdate=!0;const I=u.distanceToTriangle(f,m,y);if(I<w&&(b.copy(m),C&&C.copy(y),w=I,x=_,E=v),I<n)return!0}}}}}),Qe.releasePrimitive(u),Qe.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=w,i.faceIndex=x,s&&(s.point?s.point.copy(C):s.point=C.clone(),s.point.applyMatrix4(ks),b.applyMatrix4(ks),s.distance=b.sub(s.point).length(),s.faceIndex=E),i)}function nh(c,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=c.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,l=0;const h=c._roots;for(let u=0,f=h.length;u<f;u++)n=h[u],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),d(0,l),l+=n.byteLength;function d(u,f,m=!1){const b=u*2;if(he(b,a)){const y=Te(u,r),C=Ie(b,a);let w=1/0,x=1/0,E=1/0,M=-1/0,O=-1/0,S=-1/0;for(let v=y,T=y+C;v<T;v++){const _=3*c.resolveTriangleIndex(v);for(let A=0;A<3;A++){let I=_+A;I=i?i[I]:I;const B=s.getX(I),k=s.getY(I),L=s.getZ(I);B<w&&(w=B),B>M&&(M=B),k<x&&(x=k),k>O&&(O=k),L<E&&(E=L),L>S&&(S=L)}}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==E||o[u+3]!==M||o[u+4]!==O||o[u+5]!==S?(o[u+0]=w,o[u+1]=x,o[u+2]=E,o[u+3]=M,o[u+4]=O,o[u+5]=S,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,E=!1;if(t){if(!w){const _=y/be+f/Ae,A=C/be+f/Ae;x=t.has(_),E=t.has(A),w=!x&&!E}}else x=!0,E=!0;const M=w||x,O=w||E;let S=!1;M&&(S=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=S||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],L=o[I],F=o[I+3];o[u+_]=B<L?B:L,o[u+_+3]=k>F?k:F}return T}}}function rh(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),pr(0,c,e,i,s,n,r),ne.clearBuffer()}function pr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(he(h,o)){const u=Te(c,l),f=Ie(h,o);Wc(t,e,i,u,f,s,n,r)}else{const u=we(c);jt(u,a,i,n,r)&&pr(u,t,e,i,s,n,r);const f=ve(c,l);jt(f,a,i,n,r)&&pr(f,t,e,i,s,n,r)}}const ah=["x","y","z"];function oh(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=mr(0,c,e,i,s,n);return ne.clearBuffer(),r}function mr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(he(l,a)){const d=Te(c,o),u=Ie(l,a);return Yc(t,e,i,d,u,s,n)}else{const d=Sr(c,o),u=ah[d],m=i.direction[u]>=0;let b,y;m?(b=we(c),y=ve(c,o)):(b=ve(c,o),y=we(c));const w=jt(b,r,i,s,n)?mr(b,t,e,i,s,n):null;if(w){const M=w.point[u];if(m?M<=r[y+d]:M>=r[y+d+3])return w}const E=jt(y,r,i,s,n)?mr(y,t,e,i,s,n):null;return w&&E?w.distance<=E.distance?w:E:w||E||null}}const Ds=new D.Box3,fi=new lt,pi=new lt,Yi=new D.Matrix4,sa=new Le,Ls=new Le;function lh(c,t,e,i){ne.setBuffer(c._roots[t]);const s=gr(0,c,e,i);return ne.clearBuffer(),s}function gr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),sa.set(e.boundingBox.min,e.boundingBox.max,i),s=sa),he(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Te(c,a),y=Ie(o,r);if(Yi.copy(i).invert(),e.boundsTree)return ce(c,n,Ls),Ls.matrix.copy(Yi),Ls.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Ls.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b,E=y+b;x<E;x++)if(pe(pi,3*t.resolveTriangleIndex(x),d,u),pi.needsUpdate=!0,w.intersectsTriangle(pi))return!0;return!1}});{const C=bn(e);for(let w=b,x=y+b;w<x;w++){const E=t.resolveTriangleIndex(w);pe(fi,3*E,d,u),fi.a.applyMatrix4(Yi),fi.b.applyMatrix4(Yi),fi.c.applyMatrix4(Yi),fi.needsUpdate=!0;for(let M=0,O=C*3;M<O;M+=3)if(pe(pi,M,f,m),pi.needsUpdate=!0,fi.intersectsTriangle(pi))return!0}}}else{const h=we(c),d=ve(c,a);return ce(h,n,Ds),!!(s.intersectsBox(Ds)&&gr(h,t,e,i,s)||(ce(d,n,Ds),s.intersectsBox(Ds)&&gr(d,t,e,i,s)))}}const Rs=new D.Matrix4,Rn=new Le,Xi=new Le,ch=new D.Vector3,hh=new D.Vector3,dh=new D.Vector3,uh=new D.Vector3;function fh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Rn.set(t.boundingBox.min,t.boundingBox.max,e),Rn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Qe.getPrimitive(),f=Qe.getPrimitive();let m=ch,b=hh,y=null,C=null;s&&(y=dh,C=uh);let w=1/0,x=null,E=null;return Rs.copy(e).invert(),Xi.matrix.copy(Rs),c.shapecast({boundsTraverseOrder:M=>Rn.distanceToBox(M),intersectsBounds:(M,O,S)=>S<w&&S<r?(O&&(Xi.min.copy(M.min),Xi.max.copy(M.max),Xi.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree){const S=t.boundsTree;return S.shapecast({boundsTraverseOrder:v=>Xi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,A=v+T;_<A;_++){const I=S.resolveTriangleIndex(_);pe(f,3*I,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=M,k=M+O;B<k;B++){const L=c.resolveTriangleIndex(B);pe(u,3*L,l,o),u.needsUpdate=!0;const F=u.distanceToTriangle(f,m,y);if(F<w&&(b.copy(m),C&&C.copy(y),w=F,x=B,E=_),F<n)return!0}}}})}else{const S=bn(t);for(let v=0,T=S;v<T;v++){pe(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=M,A=M+O;_<A;_++){const I=c.resolveTriangleIndex(_);pe(u,3*I,l,o),u.needsUpdate=!0;const B=u.distanceToTriangle(f,m,y);if(B<w&&(b.copy(m),C&&C.copy(y),w=B,x=_,E=v),B<n)return!0}}}}}),Qe.releasePrimitive(u),Qe.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(b):i.point=b.clone(),i.distance=w,i.faceIndex=x,s&&(s.point?s.point.copy(C):s.point=C.clone(),s.point.applyMatrix4(Rs),b.applyMatrix4(Rs),s.distance=b.sub(s.point).length(),s.faceIndex=E),i)}function na(c,t,e){return c===null?null:(c.point.applyMatrix4(t.matrixWorld),c.distance=c.point.distanceTo(e.ray.origin),c.object=t,c)}const Fs=new Le,zs=new D.Ray,ra=new D.Vector3,aa=new D.Matrix4,oa=new D.Vector3,Fn=["getX","getY","getZ"];class ps extends Dc{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new ps(e,{...i,[Cr]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const l=e.getIndex();if(l===null){const h=new D.BufferAttribute(t.index,1,!1);e.setIndex(h)}else l.array!==s&&(l.array.set(s),l.needsUpdate=!0)}return a;function o(l){for(let h=0;h<l.length;h++){const d=l[h],u=new Uint32Array(d),f=new Uint16Array(d);for(let m=0,b=d.byteLength/Ae;m<b;m++){const y=be*m,C=2*y;he(C,f)||(u[y+6]=u[y+6]/be-m)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,l=(n?n[t]:t)*3;let h=l+0,d=l+1,u=l+2;a&&(h=a[h],d=a[d],u=a[u]);for(let f=0;f<3;f++){const m=r[Fn[f]](h),b=r[Fn[f]](d),y=r[Fn[f]](u);let C=m;b<C&&(C=b),y<C&&(C=y);let w=m;b>w&&(w=b),y>w&&(w=y),e[i+f]=C,e[i+f+3]=w}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=r.array,h=r.offset||0;let d=3;r.isInterleavedBufferAttribute&&(d=r.data.stride);const u=["getX","getY","getZ"],f=i.offset;for(let m=t,b=t+e;m<b;m++){const C=(n?n[m]:m)*3,w=(m-f)*6;let x=C+0,E=C+1,M=C+2;a&&(x=a[x],E=a[E],M=a[M]),o||(x=x*d+h,E=E*d+h,M=M*d+h);for(let O=0;O<3;O++){let S,v,T;o?(S=r[u[O]](x),v=r[u[O]](E),T=r[u[O]](M)):(S=l[x+O],v=l[E+O],T=l[M+O]);let _=S;v<_&&(_=v),T<_&&(_=T);let A=S;v>A&&(A=v),T>A&&(A=T);const I=(A-_)/2,B=O*2;i[w+B+0]=_+I,i[w+B+1]=I+(Math.abs(_)+I)*nn}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;aa.copy(t.matrixWorld).invert(),zs.copy(e.ray).applyMatrix4(aa),oa.setFromMatrixScale(t.matrixWorld),ra.copy(zs.direction).multiply(oa);const n=ra.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(zs,s,r,a);o=na(o,t,e),o&&i.push(o)}else{const o=this.raycast(zs,s,r,a);for(let l=0,h=o.length;l<h;l++){const d=na(o[l],t,e);d&&i.push(d)}}return i}refit(t=null){return(this.indirect?nh:qc)(this,t)}raycast(t,e=D.FrontSide,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?rh:Zc;for(let o=0,l=n.length;o<l;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=D.FrontSide,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?oh:$c;for(let o=0,l=n.length;o<l;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?lh:Jc;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=Qe.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Xc:Gc});return Qe.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=Qe.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,l=this.indirect?m=>{const b=this.resolveTriangleIndex(m);pe(r,b*3,a,o)}:m=>{pe(r,m*3,a,o)},h=Qe.getPrimitive(),d=t.geometry.index,u=t.geometry.attributes.position,f=t.indirect?m=>{const b=t.resolveTriangleIndex(m);pe(h,b*3,d,u)}:m=>{pe(h,m*3,d,u)};if(n){if(!(t instanceof ps))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const m=(b,y,C,w,x,E,M,O)=>{for(let S=C,v=C+w;S<v;S++){f(S),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let T=b,_=b+y;T<_;T++)if(l(T),r.needsUpdate=!0,n(r,h,T,S,x,E,M,O))return!0}return!1};if(s){const b=s;s=function(y,C,w,x,E,M,O,S){return b(y,C,w,x,E,M,O,S)?!0:m(y,C,w,x,E,M,O,S)}}else s=m}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return Fs.set(t.min,t.max,e),Fs.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Fs.intersectsBox(i),intersectsTriangle:i=>Fs.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?fh:sh)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Vc(this,t,e,i,s)}}const Ti={Mesh:D.Mesh.prototype.raycast,Line:D.Line.prototype.raycast,LineSegments:D.LineSegments.prototype.raycast,LineLoop:D.LineLoop.prototype.raycast,Points:D.Points.prototype.raycast,BatchedMesh:D.BatchedMesh.prototype.raycast},Ce=new D.Mesh,Vs=[];function ph(c,t){if(this.isBatchedMesh)mh.call(this,c,t);else{const{geometry:e}=this;if(e.boundsTree)e.boundsTree.raycastObject3D(this,c,t);else{let i;if(this instanceof D.Mesh)i=Ti.Mesh;else if(this instanceof D.LineSegments)i=Ti.LineSegments;else if(this instanceof D.LineLoop)i=Ti.LineLoop;else if(this instanceof D.Line)i=Ti.Line;else if(this instanceof D.Points)i=Ti.Points;else throw new Error("BVH: Fallback raycast function not found.");i.call(this,c,t)}}}function mh(c,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,n=this.matrixWorld;Ce.material=this.material,Ce.geometry=this.geometry;const r=Ce.geometry.boundsTree,a=Ce.geometry.drawRange;Ce.geometry.boundingSphere===null&&(Ce.geometry.boundingSphere=new D.Sphere);for(let o=0,l=i.length;o<l;o++){if(!this.getVisibleAt(o))continue;const h=i[o].geometryIndex;if(Ce.geometry.boundsTree=e[h],this.getMatrixAt(o,Ce.matrixWorld).premultiply(n),!Ce.geometry.boundsTree){this.getBoundingBoxAt(h,Ce.geometry.boundingBox),this.getBoundingSphereAt(h,Ce.geometry.boundingSphere);const d=s[h];Ce.geometry.setDrawRange(d.start,d.count)}Ce.raycast(c,Vs);for(let d=0,u=Vs.length;d<u;d++){const f=Vs[d];f.object=this,f.batchId=o,t.push(f)}Vs.length=0}Ce.geometry.boundsTree=r,Ce.geometry.drawRange=a,Ce.material=null,Ce.geometry=null}else Ti.BatchedMesh.call(this,c,t)}D.Mesh.prototype.raycast=ph;const js=new p.Sphere,Us=new p.Vector3;p.Points.prototype.raycast=function(c,t){const e=this.geometry,i=this.matrixWorld,s=c.params.Points.threshold,n=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),js.copy(e.boundingSphere),js.applyMatrix4(i),js.radius+=s,c.ray.intersectsSphere(js)===!1)return;const r=s*s,a=e.index,o=e.attributes,l=o.position,h=t.length;if(a!==null){const d=Math.max(0,n.start),u=Math.min(a.count,n.start+n.count);for(let f=d,m=u;f<m;f++){const b=a.getX(f);if(Us.fromBufferAttribute(l,b).applyMatrix4(i),la(Us,b,r,c,t,this),t.length-h>=Oi)return}}else{const d=Math.max(0,n.start),u=Math.min(l.count,n.start+n.count);for(let f=d,m=u;f<m;f++)if(Us.fromBufferAttribute(l,f).applyMatrix4(i),la(Us,f,r,c,t,this),t.length-h>=Oi)return}};function la(c,t,e,i,s,n){const r=i.ray.distanceSqToPoint(c);if(r<e){const a=new p.Vector3;i.ray.closestPointToPoint(c,a);const o=i.ray.origin.distanceTo(a);if(o<i.near||o>i.far)return;s.push({distance:o,distanceToRay:Math.sqrt(r),point:a,index:t,face:null,object:n})}}const gh=p.Points,yh=`
2
2
  // When an object is transparent, we'll change its alpha value,
3
3
  // but we should not assign a fixed value because it may already
4
4
  // has an alpha value that is lower than 1.
@@ -140,12 +140,12 @@
140
140
  }
141
141
 
142
142
  // TODO: isHighlighted isOverride isHovered
143
- `,yh=`
143
+ `,xh=`
144
144
  attribute int tileObjectId;
145
145
  flat varying int vTileObjectId;
146
- `,xh=`
147
- vTileObjectId = tileObjectId;
148
146
  `,bh=`
147
+ vTileObjectId = tileObjectId;
148
+ `,wh=`
149
149
  #ifdef USE_BC_OUTLINE
150
150
  // Restore barycentric coordinates
151
151
  int barycentricX = int(barycentric) & 0x1;
@@ -153,14 +153,14 @@
153
153
  int barycentricZ = int(barycentric) & 0x4;
154
154
  vBarycentric = vec3(float(barycentricX), float(barycentricY), float(barycentricZ));
155
155
  #endif
156
- `,wh=`
156
+ `,vh=`
157
157
  #ifdef USE_BC_OUTLINE
158
158
  vec3 finWireframeColor = outlineColor;
159
159
  vec3 tempColor = gl_FragColor.rgb;
160
160
 
161
161
  gl_FragColor.rgb = mix(finWireframeColor, tempColor, edgeFactor3());
162
162
  #endif
163
- `,vh=`
163
+ `,Mh=`
164
164
  #ifdef USE_BC_OUTLINE
165
165
  varying vec3 vBarycentric;
166
166
  uniform vec3 outlineColor;
@@ -174,12 +174,12 @@
174
174
  return min(min(a3.x, a3.y), a3.z);
175
175
  }
176
176
  #endif
177
- `,Mh=`
177
+ `,Th=`
178
178
  #ifdef USE_BC_OUTLINE
179
179
  attribute float barycentric;
180
180
  varying vec3 vBarycentric;
181
181
  #endif
182
- `,Th=`
182
+ `,Ch=`
183
183
  flat varying int vTileObjectId;
184
184
  uniform float uTextureWidth;
185
185
  uniform float uTextureHeight;
@@ -188,7 +188,7 @@
188
188
  // uniform int uHoverId;
189
189
  // uniform bool uIsIsolating;
190
190
  // uniform bool uTransparentOthersForIsolation;
191
- `,Ch=`
191
+ `,Sh=`
192
192
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
193
193
  // if (uHoverId == tileObjectId) {
194
194
  // gl_FragColor = uHoverColor;
@@ -225,7 +225,7 @@
225
225
  // gl_FragColor = vec4(0.5, 0.5, 0.5, 0.8);
226
226
  // }
227
227
  // }
228
- `,Sh=`
228
+ `,Eh=`
229
229
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
230
230
  // State priority (high to low):
231
231
  // - Hidden
@@ -243,7 +243,7 @@
243
243
  gl_FragColor = HIGHLIGHT_COLOR;
244
244
  return;
245
245
  }
246
- `,Eh=`
246
+ `,Oh=`
247
247
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
248
248
  // State priority (high to low):
249
249
  // - Hidden
@@ -261,7 +261,7 @@
261
261
  gl_FragColor = HIGHLIGHT_COLOR;
262
262
  return;
263
263
  }
264
- `,Oh=`
264
+ `,_h=`
265
265
  #define STANDARD
266
266
 
267
267
  varying vec3 vViewPosition;
@@ -321,7 +321,7 @@ void main() {
321
321
 
322
322
  #endif
323
323
  }
324
- `,_h=`
324
+ `,Ph=`
325
325
  #define STANDARD
326
326
 
327
327
  #ifdef PHYSICAL
@@ -487,7 +487,7 @@ void main() {
487
487
 
488
488
  #include <outline_bc_fragment>
489
489
  }
490
- `,Ph=`
490
+ `,Ah=`
491
491
  #include <clipping_planes_pars_vertex>
492
492
 
493
493
  attribute int tileObjectId;
@@ -504,7 +504,7 @@ void main() {
504
504
  #endif
505
505
  gl_Position = projectionMatrix * modelViewMatrix * mvPosition;
506
506
  }
507
- `,Ah=`
507
+ `,Ih=`
508
508
  #include <clipping_planes_pars_fragment>
509
509
 
510
510
  flat varying int vTileObjectId;
@@ -531,9 +531,9 @@ void main() {
531
531
 
532
532
  gl_FragColor = tileObjectId2Color(vTileObjectId);
533
533
  }
534
- `,Re=p.ShaderChunk;Re.outline_bc_vertex=bh;Re.outline_bc_fragment=wh;Re.outline_bc_pars_fragment=vh;Re.outline_bc_pars_vertex=Mh;Re.standard_ex_vertex=Oh;Re.standard_ex_fragment=_h;Re.common_ex=gh;Re.id_pars_vertex=yh;Re.id_vertex=xh;Re.state_pars_fragment=Th;Re.state_fragment=Ch;Re.state_transparent_fragment=Sh;Re.state_highlight_fragment=Eh;Re.pick_ex_vertex=Ph;Re.pick_ex_fragment=Ah;const Ih=p.ShaderChunk;class Bh{constructor(t){g(this,"promise");g(this,"cancelReject");const e=new Promise((i,s)=>{this.cancelReject=s});this.promise=Promise.race([e,t])}cancel(){this.cancelReject&&this.cancelReject({type:"cancel"})}}const kh=Hr.default??Hr,P=kh;P.setLevel("warn");const Co=c=>{try{P.setLevel(c)}catch(t){P.setLevel("error"),P.error(t)}},Ai=class Ai{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),r=/(?:iPhone)/.test(t)&&!n,a=!r&&!e,o=Ai.isTouchScreenDevice();e&&P.debug("[DI] is android"),i&&P.debug("[DI] is fireFox"),s&&P.debug("[DI] is chrome"),n&&P.debug("[DI] is tablet"),r&&P.debug("[DI] is iPhone"),a&&P.debug("[DI] is PC"),o&&P.debug("[DI] is touch device")}static creatReactNativeCanvas(t){const e=t,i=e.drawingBufferWidth||e.width||0,s=e.drawingBufferHeight||e.height||0;return{style:{},width:i,height:s,clientWidth:Math.ceil(i/(window.devicePixelRatio||1)),clientHeight:Math.ceil(s/(window.devicePixelRatio||1)),addEventListener:()=>{},removeEventListener:()=>{}}}};g(Ai,"isMobile",/mobile/i.test(navigator.userAgent)),g(Ai,"isBrowser",typeof document<"u"),g(Ai,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let Be=Ai;const Ii=class Ii{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof p.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof p.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof p.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new p.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(t instanceof p.Vector2)return new p.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new p.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof p.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new p.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,n=(t.max.y-t.min.y)*e,r=(t.max.z-t.min.z)*e,a=new p.Vector3(i.x-s/2,i.y-n/2,i.z-r/2),o=new p.Vector3(i.x+s/2,i.y+n/2,i.z+r/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new p.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,n=t.max.y-t.min.y,r=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),n<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),r<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const n=Math.max(e.min.x,0),r=Math.max(e.min.y,0),a=Math.max(e.max.x-n,0),o=Math.max(e.max.y-r,0),l=t.getImageData(n,r,a,o),h=document.createElement("canvas");return h.width=a,h.height=o,h.getContext("2d").putImageData(l,0,0),h.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!Be.isBrowser)return;const e=performance.memory;if(!e){P.warn("[Util] performance.memory is not available in this browser");return}const i=(e.jsHeapSizeLimit/(1024*1024)).toFixed(2),s=(e.totalJSHeapSize/(1024*1024)).toFixed(2),n=(e.usedJSHeapSize/(1024*1024)).toFixed(2);P.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+n+"M ")}static printGpuInfo(t){if(!Be.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);P.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ii.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,n=Date.now();n-e>s&&(await Ii.sleep(0),e=n)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async n=>{if(e&&(n%i===0||n===t-1)){e(new ProgressEvent("",{loaded:n+1,total:t}));const r=500,a=Date.now();(a-s>r||n===t-1)&&(await Ii.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return n=>{let r=n.loaded*100/n.total;r=r*(e-t)/100+t,r>e&&(s||(P.warn("[Progress] Invalid ProgressEvent:",n),s=!0),r=e),i&&i(new ProgressEvent(n.type,{loaded:r,total:100}))}}};g(Ii,"twinklingObjectIds",{});let j=Ii;const Dh=(c,t,e)=>{const{default:i,active:s}=t;e?(c.remove(i),c.add(s||i)):(s&&c.remove(s),c.add(i))};class Li{static color2rgba(t){let e=[0,0,0,1],i;if(i=/^(\w+)\(([^)]*)\)/.exec(t)){let s;const n=i[1],r=i[2];switch(n){case"rgb":case"rgba":(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,Number(s[4]||1)]),(s=/^\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,Number(s[4]||1)]);break;case"hsl":case"hsla":(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,Number(s[4]||1)]);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],n=s.length;if(n===3)e=[parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,1];else if(n===6){const r=parseInt(s,16);e=[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255,1]}else console.warn("THREE.Color: Invalid hex color "+t)}return e}static rgba2Color(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]),n=t[3]!=null?t[3]:1;return"rgba("+e+","+i+","+s+","+n+")"}static colorStr2Rgba(t){let e=t.replace("rgba(","");e=e.replace(")","");const i=e.split(","),s=[];return s.push(this.to1(parseInt(i[0]))),s.push(this.to1(parseInt(i[1]))),s.push(this.to1(parseInt(i[2]))),i[3]!=null&&s.push(parseFloat(i[3])),s}static rgb2Hex(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]);return(e<<16)+(i<<8)+s}static to255(t){let e=Math.max(t,0);return e=Math.min(t,1),e*255}static to1(t){let e=Math.max(t,0);return e=Math.min(t,255),e/255}}class Ee{static getScreenCoordinateByEvent(t,e){const i=new p.Vector2,{left:s,top:n}=e.getBoundingClientRect();return i.x=t.clientX-s,i.y=t.clientY-n,i}static getScreenCoordinateByTouchEvent(t,e){const i=new p.Vector2,{left:s,top:n}=e.getBoundingClientRect();return i.x=t.touches[0].clientX-s,i.y=t.touches[0].clientY-n,i}static world2Screen(t,e,i){const{clientWidth:s,clientHeight:n}=i,r=t.clone(),a=new p.Vector2;return r.project(e),a.x=Math.round((.5+r.x/2)*s),a.y=Math.round((.5-r.y/2)*n),a}static worldBBox2Screen(t,e,i){const s=new p.Box2,n=t.min,r=t.max,a=(o,l,h)=>{const d=new p.Vector3(o,l,h),u=this.world2Screen(d,e,i);s.expandByPoint(u)};return a(n.x,n.y,n.z),a(n.x,n.y,r.z),a(n.x,r.y,n.z),a(n.x,r.y,r.z),a(r.x,n.y,n.z),a(r.x,n.y,r.z),a(r.x,r.y,n.z),a(r.x,r.y,r.z),s}static screen2World(t,e,i){const s=Ee.screen2Ndc(t,e,i);return new p.Vector3(s.x,s.y,1).unproject(e)}static screen2Ndc(t,e,i){const{clientWidth:s,clientHeight:n}=i,r=new p.Vector2;return r.x=t.x/s*2-1,r.y=-(t.y/n)*2+1,r}static world2NormalizedScreen(t,e,i){const s=new p.Vector3,n=t instanceof p.Vector2?0:t.z;s.set(t.x,t.y,n);const r=Ee.world2Screen(s,e,i);return r.x/=i.clientWidth,r.y/=i.clientHeight,r}}class Lh{static createCSS2DObject(t){const e=new xo.CSS2DObject(t);return t.dataset.objectId=e.id.toString(),e}static createDefaultHotpoint(t=12){const e=document.createElement("div"),i=e.style;return i.width=t+"px",i.height=t+"px",i.opacity="0.8",i.cursor="pointer",i.top=-t/2+"px",i.left=-t/2+"px",i.backgroundColor="#ffffff",i.border="2px solid #00DAB7",i.borderRadius="50%",this.createCSS2DObject(e)}static createHotpoint(t){if(t){const e=document.createElement("div"),i=e.style;return i.top="0px",i.left="0px",e.innerHTML=t,this.createCSS2DObject(e)}return this.createDefaultHotpoint()}static createLabel(t,e=""){const i=document.createElement("div");if(i.innerHTML=t,e)i.classList.add(e);else{const s=i.style;s.padding="5px 9px",s.color="#ffffffdd",s.fontSize="12px",s.position="absolute",s.backgroundColor="rgba(0, 0, 0, 0.3)",s.borderRadius="12px",s.cursor="pointer",s.top="0px",s.left="0px"}return this.createCSS2DObject(i)}static tryFindObjectId(t){if(t.dataset.objectId!=null)return parseInt(t.dataset.objectId);const e=t.parentElement;if(e&&!(e instanceof HTMLBodyElement))return this.tryFindObjectId(e)}}const So={"Precision from file":99},Rh=(c,t)=>c.toFixed(t===So["Precision from file"]?2:t),Eo="en",ct=!1,Oo=10,je=11,Ut=12,Ar=583902,Fh=[.031,.906,.867,.5],an=[.3,.3,.3,.8],Ir=.5,on=.1,ln=5e3,_o=45,zh="x-viewer-iconfont",Vh="x-viewer-iconfont2",Br=10,ha=new p.Vector3,da=new p.Vector3,ua=new p.Vector3,as=new p.Vector3,Et=new p.Vector3,fa=new p.Triangle;function jh(c,t,e,i,s){const n=[],r={};let a,o,l,h;const u=Math.pow(10,4);let f,m,b=0;for(f=0,m=c.length;f<m;f+=3)a=c[f],o=c[f+1],l=c[f+2],h=Math.round(a*u)+"_"+Math.round(o*u)+"_"+Math.round(l*u),!r[h]&&(r[h]=b/3,e[b++]=a,e[b++]=o,e[b++]=l),n[f/3]=r[h];for(f=0,m=t.length;f<m;f++)s[f]=n[t[f]],i[s[f]]=t[f]}function Uh(c,t,e,i){for(let s=0,n=c;s<n;s+=3){const r=t[s]*3,a=t[s+1]*3,o=t[s+2]*3;ha.set(e[r],e[r+1],e[r+2]),da.set(e[a],e[a+1],e[a+2]),ua.set(e[o],e[o+1],e[o+2]),p.Triangle.getNormal(ha,da,ua,as),i.push({normal:as.clone()})}}const zn=[new p.Vector3(1,0,0),new p.Vector3(0,1,0),new p.Vector3(0,0,1),new p.Vector3(1,1,0),new p.Vector3(0,1,1),new p.Vector3(1,0,1),new p.Vector3(1,1,1),new p.Vector3(0,0,0)];function Hh(c,t){return Et.addVectors(c,t),Et.x===0||Et.y===0||Et.z===0}class Po{static buildEdge(t,e,i=Br){const s=[],n=[],r=[];jh(t,e,s,n,r);const a=[];Uh(e.length,r,s,a);const o=[],l=Math.cos(p.MathUtils.DEG2RAD*i),h={};let d=!1;for(let u=0,f=e.length;u<f;u+=3){const m=u/3;for(let b=0;b<3;b++){const y=r[u+b],C=r[u+(b+1)%3],w=Math.min(y,C),x=Math.max(y,C),E=w+","+x;h[E]===void 0?h[E]={index1:w,index2:x,face1:m,face2:void 0}:h[E].face2=m}}for(const u in h){const f=h[u];if(f.face2!==void 0){const y=a[f.face1].normal,C=a[f.face2].normal;if(y.dot(C)>l)continue}const m=n[f.index1],b=n[f.index2];(!d&&m>65535||b>65535)&&(d=!0),o.push(m),o.push(b)}return d?new Uint32Array(o):new Uint16Array(o)}static buildBarycentrics(t){const e=t.getAttribute("position");if(!e||e.count===0)return console.warn(" no positions in geometry!"),!1;const i=4,s=Math.pow(10,i),n=Math.cos(p.MathUtils.DEG2RAD*20),r=t.getIndex(),a=r?r.count:e.count,o=[0,0,0],l=new Array(3),h=zn.length,d=[];for(let T=0;T<e.count;T++)d.push({point:new p.Vector3(1,1,1),inited:!1,barycentricIndex:-1});const u={},f={},m={},b={};for(let T=0;T<a;T+=3){r?(o[0]=r.getX(T),o[1]=r.getX(T+1),o[2]=r.getX(T+2)):(o[0]=T,o[1]=T+1,o[2]=T+2);const{a:_,b:A,c:I}=fa;if(_.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),fa.getNormal(as),m[o[0]]?l[0]=m[o[0]]:(l[0]=Math.round(_.x*s)+","+Math.round(_.y*s)+","+Math.round(_.z*s),m[o[0]]=l[0]),m[o[1]]?l[1]=m[o[1]]:(l[1]=Math.round(A.x*s)+","+Math.round(A.y*s)+","+Math.round(A.z*s),m[o[1]]=l[1]),m[o[2]]?l[2]=m[o[2]]:(l[2]=Math.round(I.x*s)+","+Math.round(I.y*s)+","+Math.round(I.z*s),m[o[2]]=l[2]),l[0]===l[1]||l[1]===l[2]||l[2]===l[0]){P.warn(" skip degenerate triangles in geometry!");continue}const B={a:o[0],b:o[1],c:o[2]};!f[o[0]]&&(f[o[0]]=[]),f[o[0]].push(B),!f[o[1]]&&(f[o[1]]=[]),f[o[1]].push(B),!f[o[2]]&&(f[o[2]]=[]),f[o[2]].push(B);for(let k=0;k<3;k++){const L=(k+1)%3,F=l[k],ie=l[L],se=o[k],Fe=o[L];!u[se]&&(u[se]=new Set),u[se].add(Fe),!u[Fe]&&(u[Fe]=new Set),u[Fe].add(se);const ht=F+"_"+ie,Me=ie+"_"+F;if(Me in b&&b[Me]){if(b[Me].outer){P.warn("[Edge] edge: "+Me+" is already outer!");continue}as.dot(b[Me].normal)<=n?b[Me].outer=!0:b[Me].find=!0}else ht in b?P.warn("[Edge] "+ht+" has existed in geometry!"):b[ht]={startIndex:se,endIndex:Fe,normal:as.clone(),outer:!1,find:!1}}}for(const T in b)b[T]&&!b[T].find&&!b[T].outer&&(b[T].outer=!0);const y=[],C=[];for(const T in f)C.push(f[T]);let w=new Set;for(const T of C[0])w.add(T.a),w.add(T.b),w.add(T.c);let x=0;for(C.splice(x,1);;){let T=!1;for(let _=0;_<C.length&&!T;_++)for(const A of C[_])if(w.has(A.a)||w.has(A.b)||w.has(A.c)){x=_,T=!0;break}if(T){for(const _ of C[x])w.add(_.a),w.add(_.b),w.add(_.c);if(C.splice(x,1),x=0,C.length===0){y.push(w);break}}else if(!T)if(y.push(w),C.length>0){w=new Set;for(const _ of C[x])w.add(_.a),w.add(_.b),w.add(_.c);C.splice(x,1),x=0}else break}const E=new Set;for(let T=0;T<y.length;T++)y[T].forEach(A=>{E.has(A)?P.warn("[Edge] "+A+" is already in positionIndexSet!"):E.add(A)});const M=(T,_)=>{let A=!1;const I=m[T];if(!I)return console.warn(T+" is not in positionIndexHash!"),A;const B=m[_];if(!B)return console.warn(_+" is not in positionIndexHash!"),A;const k=I+"_"+B;if(b[k])A=b[k].outer;else{const L=B+"_"+I;b[L]&&(A=b[L].outer)}return A},O=(T,_,A)=>{const I=[];return I.push(M(T,_)),I.push(M(_,A)),I.push(M(A,T)),I.filter(B=>B===!0).length>=2},S=(T,_)=>{if(!u[T])return P.warn("[Edge] "+T+" position isn't used!"),!0;const A=u[T];for(const B of A){const k=M(T,B),L=d[B];if(!L.inited)continue;const F=Hh(_,L.point);if(k&&!F||!k&&F)return!1}const I=f[T];for(const B of I){const k=_;let L=d[B.b],F=d[B.c];if(B.b===T?L=d[B.a]:B.c===T&&(F=d[B.a]),O(B.a,B.b,B.c)&&(L.inited&&k.equals(L.point)||F.inited&&k.equals(F.point)))return!1;if(!(!L.inited||!F.inited)&&(Et.addVectors(k,L.point),Et.add(F.point),Et.x+Et.y+Et.z<2))return!1}return!0};let v=!1;for(let T=0;T<y.length;T++){const _=Array.from(y[T]);v=!1;let A=0,I=0;for(;I>=0;){A=_[I];let B=d[A].inited?d[A].barycentricIndex+1:0;for(;B<h&&!S(A,zn[B]);B++);if(B<h)if(d[A].inited=!0,d[A].barycentricIndex=B,d[A].point.copy(zn[B]),I==_.length-1){v=!0,P.debug("[Edge]",d);break}else I++;else d[A].inited=!1,I--}if(!v){P.warn("[Edge] no result: "+_+"!");break}}if(v){const T=[];for(let A=0;A<d.length;A++){!d[A].inited&&P.warn("[Edge] "+A+" is not initialized !");let I=0;I|=d[A].point.x,I|=d[A].point.y<<1,I|=d[A].point.z<<2,T.push(I)}const _=new p.Uint8BufferAttribute(T,1,!1);t.setAttribute("barycentric",_)}else P.warn("[Edge] No suitable barycentric found!");return v}}class Nt{constructor(){g(this,"map");this.map=new Map}addEventListener(t,e){let i=this.map.get(t);i||(i=new Set,this.map.set(t,i)),i.add(e)}dispatchEvent(t,e={}){const i=this.map.get(t);if(!i)return;[...i].forEach(n=>n(e))}hasEventListener(t){return!!this.map.get(t)}removeEventListener(t,e){if(!t){this.map.clear();return}if(!e){this.map.delete(t);return}const i=this.map.get(t);i&&i.delete(e)}}const Z=class Z{static exportToGltf(t,e){Z.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){Z.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new El.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,r=>{if(i.binary){e=Z.addExtention(e,Z.EXTENSION_GLB);const a=r;Z.saveArrayBuffer(a,e)}else e=Z.addExtention(e,Z.EXTENSION_GLTF),Z.saveJson(r,e)},r=>console.log(r),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_OBJ);const i=new Ol.OBJExporter,s=i.parse(t);Z.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_DRACO);const s=new Sl.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const r=s.parse(t,i);Z.saveArrayBuffer(r,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_STL);const s=new _l.STLExporter;if(i){const n={binary:!0},r=s.parse(t,n);Z.saveDataView(r,e)}else{const n=s.parse(t);Z.saveString(n,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(Z.EXTENSION_JSON)||(e+=Z.EXTENSION_JSON),Z.saveJson(i,e)}static save(t,e){let i=Z.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),Z.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){Z.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){Z.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){Z.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){Z.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){Z.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};g(Z,"EXTENSION_GLTF",".gltf"),g(Z,"EXTENSION_GLB",".glb"),g(Z,"EXTENSION_OBJ",".obj"),g(Z,"EXTENSION_DRACO",".drc"),g(Z,"EXTENSION_JSON",".json"),g(Z,"EXTENSION_STL",".stl"),g(Z,"downloadLink");let yr=Z;class Nh{constructor(){g(this,"prevTime");g(this,"beginTime");g(this,"frames");g(this,"fps");this.prevTime=(performance||Date).now(),this.beginTime=(performance||Date).now(),this.frames=0,this.fps=Number.NaN}begin(){this.beginTime=(performance||Date).now()}end(){this.frames++;const t=(performance||Date).now();return t>=this.prevTime+1e3&&(this.fps=Math.round(this.frames*1e3/(t-this.prevTime)),this.frames=0,this.prevTime=t),t}update(){this.beginTime=this.end()}}const Vn=1e-15,pa=new p.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),ma=new p.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class z{static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static floorNumber(t,e){return Math.floor(t*Math.pow(10,e))/Math.pow(10,e)}static areNumbersEqual(t,e,i=1e-7){return Math.abs(t-e)<i*Math.max(1,Math.abs(t),Math.abs(e))}static areVector2sEqual(t,e,i=1e-7){return z.areNumbersEqual(t.x,e.x,i)&&z.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return z.areNumbersEqual(t.x,e.x,i)&&z.areNumbersEqual(t.y,e.y,i)&&z.areNumbersEqual(t.z,e.z,i)}static areNumbersClose(t,e,i=1e-9,s=1e-12){return Math.abs(t-e)<=Math.max(i*Math.max(Math.abs(t),Math.abs(e)),s)}static areVector2sClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)}static areVectorsClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)&&this.areNumbersClose(t.z,e.z,i,s)}static getArcAngleSpanInRadian(t,e){const i=Math.PI*2;return z.areNumbersClose(t,e,Vn)?0:(t%=i,z.areNumbersClose(t,e%i,Vn)?i:(z.areNumbersClose(e,i,Vn)&&(e%=i),e<t&&(e+=i),e-t))}static getIntegerPartLength(t){return t=Math.abs(t),t<1?0:Math.ceil(Math.log10(Math.abs(t)+1))}static getRelativeEps(t,e=1e-7){const i=z.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(z.getRelativeEps(t.x,e),z.getRelativeEps(t.y,e))}static getControlPointByTwoPoints(t,e){const i=new p.Vector2().subVectors(e,t),s=i.angle(),n=i.length(),r=p.MathUtils.degToRad(45),a=n/2/Math.cos(r);return new p.Vector2(t.x+a*Math.cos(r-s),t.y-a*Math.sin(r-s))}static convertPointFromUEToGltf(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(pa.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(pa),e}static convertPointFromUEToRevit(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(ma.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(ma),e}static getBox(t,e){const i=[Math.min(t.x,e.x),Math.min(t.y,e.y),Math.min(t.z,e.z)],s=[Math.max(t.x,e.x),Math.max(t.y,e.y),Math.max(t.z,e.z)];return[...i,...s]}static getCenter(t){const e=new p.Vector3(t.min.x,t.min.y,t.min.z),i=new p.Vector3(t.max.x,t.max.y,t.max.z),s=new p.Vector3().addVectors(e,i).multiplyScalar(.5);return{x:s.x,y:s.y,z:s.z}}static convertBoxFromGltfToUE(t){const e=z.convertPointFromGltfToUE(t.min),i=z.convertPointFromGltfToUE(t.max);return z.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=z.convertPointFromUEToGltf(t.min),i=z.convertPointFromUEToGltf(t.max);return z.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=z.convertPointFromRevitToUE(t.min),i=z.convertPointFromRevitToUE(t.max);return z.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=z.convertPointFromUEToRevit(t.min),i=z.convertPointFromUEToRevit(t.max);return z.getBox(e,i)}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static getLookAtMatrix(t,e,i){const s=new p.Matrix4,n=new p.Vector3(t.x,t.y,t.z),r=new p.Vector3(e.x,e.y,e.z),a=new p.Vector3(i.x,i.y,i.z);s.lookAt(n,r,a),s.transpose();const o=[];return s.toArray(o),o}static getLocationFromMatrix(t){const e=new p.Vector3;return e.setFromMatrixPosition(t),e}static toDegrees(t){return p.MathUtils.radToDeg(t)}static toRadians(t){return p.MathUtils.degToRad(t)}static signNotZero(t){return t<0?-1:1}static fromSnorm(t,e){return z.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=z.fromSnorm(t.x,i),e.y=z.fromSnorm(t.y,i),e.z=1-(Math.abs(e.x)+Math.abs(e.y)),e.z<0){const s=e.x;e.x=(1-Math.abs(e.y))*z.signNotZero(s),e.y=(1-Math.abs(s))*z.signNotZero(e.y)}}}const jn=1e7,ga=new p.Box2,ya=new p.Box2,xa=new p.Vector3,ba=new p.Vector3,wa=new p.Vector3,It=new p.Triangle,Gh=/not find (pre|next) vertex|has repeat vertex|translateLine line eror|not find Intersection/;function qh(c){const t=console.error;console.error=(...e)=>{typeof e[0]=="string"&&Gh.test(e[0])||t.apply(console,e)};try{return c()}finally{console.error=t}}class N{static geometriesEqual(t,e){return t===e?!0:t.type===e.type&&t.name===e.name&&t.morphTargetsRelative===e.morphTargetsRelative&&this.equal(t.boundingBox,e.boundingBox)&&this.equal(t.boundingSphere,e.boundingSphere)&&this.attributesEqual(t.attributes,e.attributes)&&this.bufferAttributesEqual(t.index,e.index)}static equal(t,e){return t===e||!t&&!e?!0:t&&e?t.equals(e):!1}static attributesEqual(t,e){if(t===e)return!0;const i=Object.keys(t).sort(),s=Object.keys(e).sort();if(i.length!==s.length)return!1;for(let n=0;n<i.length;++n){if(i[n]!==s[n])return!1;const r=t[i[n]],a=e[s[n]];if(!this.bufferAttributesEqual(r,a))return!1}return!0}static bufferAttributesEqual(t,e){if(t===e)return!0;if(!t||!e||!(t.name===e.name&&t.itemSize===e.itemSize&&t.count===e.count&&t.normalized===e.normalized))return!1;if(t.array&&e.array){if(t.array.length!==e.array.length)return!1;for(let r=0;r<t.array.length;++r)if(t.array[r]!==e.array[r])return!1}else if(t.array||e.array)return!1;const s=t.data,n=e.data;if(s&&n){if(s.length!==n.length)return!1;for(let r=0;r<s.length;++r)if(s[r]!==n[r])return!1}else if(s||n)return!1;return!0}static tryConvertInterleavedBufferAttributes(t){!t||!t.attributes||Object.keys(t.attributes).forEach(e=>{const i=t.attributes[e];if(i instanceof p.InterleavedBufferAttribute){const s=i.clone();t.attributes[e]=s}})}static isPointInPolygon(t,e,i=!1){const s=t.x,n=t.y;let r=!1;const a=e.length;for(let o=0,l=a-1;o<a;l=o++){const h=e[o].x,d=e[o].y,u=e[l].x,f=e[l].y;let m=d>n!=f>n;i&&(m=d>=n!=f>=n),m&&s<(u-h)*(n-d)/(f-d)+h&&(r=!r)}return r}static caculateGeometryCenter(t){if(!t.hasAttribute("position"))return null;const e=t.getAttribute("position");if(e.count===0)return null;const i=new p.Vector3,s=e.itemSize,n=e.array,r=[0,0,0];for(let a=0;a<e.count;a++)for(let o=0;o<s;o++)r[o]+=n[a*s+o];for(let a=0;a<s;a++)i.setComponent(a,r[a]/e.count);return i}static isConvex(t){const e=t.length;let i=0,s=0;const n=new p.Vector2,r=new p.Vector2;for(let a=0;a<e;++a){const o=t[a],l=t[(a+1)%e],h=t[(a+2)%e];if(n.subVectors(l,o),r.subVectors(h,l),s=n.cross(r),s!=0){if(s>0&&i<0||s<0&&i>0)return!1;i=s}}return!0}static areLineSegmentsIntersecting(t,e){const{start:i,end:s}=t,{start:n,end:r}=e,a=n.clone().sub(i),o=s.clone().sub(i),l=r.clone().sub(i),h=a.cross(o).dot(l.cross(o)),d=i.clone().sub(n),u=r.clone().sub(n),f=s.clone().sub(n),m=d.cross(u).dot(f.cross(u));return h<0&&m<0}static getLineSegmentsIntersectingPoint(t,e){const{start:i,end:s}=t,{start:n,end:r}=e,a=xa.subVectors(s,i).normalize(),o=ba.subVectors(r,n).normalize();if(a.dot(o)===1)return null;const l=wa.subVectors(n,i),h=a.clone().cross(o),d=l.clone().cross(o),u=l.clone().dot(h);if(u>=1e-5||u<=-1e-5)return null;const f=h.lengthSq();if(z.areNumbersEqual(0,f))return;const m=d.clone().dot(h)/f,b=i.clone().add(a.multiplyScalar(m));return b.equals(i)||b.equals(s)?null:b}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:n}=e,r=xa.subVectors(s,n).length(),a=ba.subVectors(t,s).length(),o=wa.subVectors(t,n).length();return Math.abs(r-(a+o))<=i}static isPointOnLineSegments(t,e,i=.001){let s=!1;for(let n=0;n<e.length-1;n+=2){const r=e[n],a=e[n+1];if(s=this.isPointOnLineSegment(t,{start:r,end:a},i),s)break}return s}static checkAndRebasePositionsOnRTC(t,e){if(t.length===0)return!1;const i=t[0]instanceof p.Vector3;t.forEach(n=>{i?e.add(n):(e.x+=n.x,e.y+=n.y)}),e.divideScalar(t.length);let s=!1;if(N.shouldRebasePositionOnRTC(e)){s=!0;for(let n=0;n<t.length;n++){const r=t[n].x-e.x,a=t[n].y-e.y;i?t[n]=new p.Vector3(r,a,t[n].z-e.z):t[n]=new p.Vector2(r,a)}}else e.setScalar(0);return s}static shouldRebasePositionOnRTC(t){return Math.abs(t.x)>jn||Math.abs(t.y)>jn||t instanceof p.Vector3&&Math.abs(t.z)>jn}static calculateSurfaceArea(t){let e=0;const i=t.getAttribute("position"),s=t.index;if(s)for(let n=0;n<s.count;n+=3)It.a.fromBufferAttribute(i,s.getX(n)),It.b.fromBufferAttribute(i,s.getX(n+1)),It.c.fromBufferAttribute(i,s.getX(n+2)),e+=It.getArea();else for(let n=0;n<i.count;n+=3)It.a.fromBufferAttribute(i,n),It.b.fromBufferAttribute(i,n+1),It.c.fromBufferAttribute(i,n+2),e+=It.getArea();return e}static convertLineStripToLine(t,e=!1){const i=t.getIndex();if(!i)return;const s=i.array.constructor,n=i.count;let r=n;n>2&&(r=e?n*2:n*2-2);const a=new s(r);let o=0;for(let l=0;l<n;l++){const h=i.getX(l);a[o++]=h,l>0&&l<n-1&&(a[o++]=h)}e&&(a[o++]=i.getX(n-1),a[o++]=i.getX(0)),t.setIndex(a)}static convertGeometryWithIndexedToNonIndexed(t){if(!t.index)return t;const e=new p.BufferGeometry,i=t.index;for(const s in t.attributes)e.setAttribute(s,N.createGeometryAttributeByIndex(t.attributes[s],i));return e}static createGeometryAttributeByIndex(t,e){const i=e.count,s=t.itemSize,n=t.array.constructor,r=new n(i*s);for(let a=0;a<i;a++){const o=e.getX(a),l=o*s;for(let h=0;h<s;h++)r[a*s+h]=t.array[l+h]}return new p.BufferAttribute(r,s,t.normalized)}static getLineEndPointsByIndex(t,e){const i=l=>{const h=t.geometry.attributes.position,d=h.array;return t.localToWorld(new p.Vector3(d[3*l],d[3*l+1],d[3*l+2]))};t.updateWorldMatrix(!0,!1);const s=t.geometry.getIndex()?.array||[],n=s[e]??e,r=s[e+1]??e+1,a=i(n),o=i(r);return[a,o]}static arePolygonsIntersect(t,e){if(t.length===0||e.length===0||(ga.setFromPoints(t),ya.setFromPoints(e),!ga.intersectsBox(ya)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&z.areVector2sEqual(t[i+1],t[i])&&++i,++i}return!1}static getLineLineIntersectionPoint(t,e,i,s,n=.001){const r=e.clone().sub(t).normalize(),a=s.clone().sub(i).normalize();if(Math.abs(r.dot(a))>1-n)return;const o=e.y-t.y,l=t.x-e.x,h=o*t.x+l*t.y,d=s.y-i.y,u=i.x-s.x,f=d*i.x+u*i.y,m=o*u-d*l;if(Math.abs(m)<n)return;const b=(u*h-l*f)/m,y=(o*f-d*h)/m;return new p.Vector2(b,y)}static getOffsetPoint(t,e,i){const s=e.x-t.x,n=e.y-t.y,r=Math.sqrt(s*s+n*n),a=i/r;return new p.Vector2(-a*n,a*s)}static convertSimpleWidthLineToMeshGeometry(t,e){let i,s=!1,n=!1,r=[],a=[],o,l,h=new p.Vector2,d=new p.Vector2,u=new p.Vector2,f=new p.Vector2;const m=[],b=e/2;for(let x=0,E=t.length-1;x<E;x++)s=!x,n=x===t.length-2,i=this.getOffsetPoint(t[x],t[x+1],b),h=new p.Vector2(t[x].x+i.x,t[x].y+i.y),d=new p.Vector2(t[x+1].x+i.x,t[x+1].y+i.y),u=new p.Vector2(t[x].x-i.x,t[x].y-i.y),f=new p.Vector2(t[x+1].x-i.x,t[x+1].y-i.y),s||(o=this.getLineLineIntersectionPoint(r[0],r[1],h,d),o!==void 0?m.unshift(o):m.unshift(h),l=this.getLineLineIntersectionPoint(a[0],a[1],u,f),l!==void 0?m.push(l):m.push(u)),s&&(m.unshift(h),m.push(u)),n&&(m.unshift(d),m.push(f)),n||(r=[h,d],a=[u,f]);if(m.length<3)return;const y=p.ShapeUtils.triangulateShape(m,[]),C=[];for(let x=0;x<y.length;x++)C.push(...y[x]);const w=new p.BufferGeometry().setFromPoints(m);return w.setIndex(C),w}static convertWidthLineToMeshGeometry(t,e){if(t.length<2)return;const i=[];t.forEach(s=>{i.push([s.x,s.y])});try{const{indices:s,position:n}=qh(()=>Pl.extrudePolylines([i],{lineWidth:e,depth:1})),r=new p.BufferGeometry;return r.setAttribute("position",new p.Float32BufferAttribute(n,3)),r.setIndex(Array.from(s)),r}catch{return}}static releaseGeometryManually(t){t.index=null,t.attributes={}}static getAdjacentNonRepeatPoints(t,e=1e-7){const i=[],s=t.length;for(let n=0;n<s-1;n++)z.areVector3sEqual(t[n],t[n+1],e)||i.push(t[n]);return i.push(t[s-1]),i}static mergeBBoxes(t){const e=[...t];if(e.length<2)return e;const i=[],s=[];for(let n=0;n<e.length;n++){const r=e[n];if(!s.includes(n)){for(let a=0;a<e.length;a++){const o=e[a];r.equals(o)||r.intersectsBox(o)&&(r.union(o),s.push(a))}i.push(r)}}return i}}const Wh={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"}},xr={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"}},Qe=Al.createInstance(),Yh="cn";Qe.init({lng:Yh,debug:!1,resources:{en:{translation:xr},cn:{translation:xr}}});class xe{static materialEquals(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t instanceof p.Material&&e instanceof p.Material){const i=t,s=e;return i.alphaTest===s.alphaTest&&i.opacity===s.opacity&&i.side===s.side&&i.visible===s.visible&&i.name===s.name&&i.transparent===s.transparent&&this.colorEquals(i.color,s.color)&&this.colorEquals(i.emissive,s.emissive)&&i.roughness===s.roughness&&i.metalness===s.metalness&&i.alphaMap===s.alphaMap&&i.uniforms===s.uniforms&&i.defines===s.defines&&i.vertexShader===s.vertexShader&&i.fragmentShader===s.fragmentShader&&i.clippingPlanes===s.clippingPlanes&&i.map===s.map&&i.clipIntersection===s.clipIntersection}return!1}static materialsEquals(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length){for(let i=0;i<t.length;++i)if(!this.materialEquals(t[i],e[i]))return!1;return!0}else if(t instanceof p.Material&&e instanceof p.Material)return this.materialEquals(t,e);return!1}static colorEquals(t,e){return t===e?!0:t instanceof p.Color&&e instanceof p.Color?t.equals(e):!1}static clonedHighlightMaterials(t,e={}){if(!t||!t.material)return;const i=t.material;if(Array.isArray(i)&&i.length>0){const s=[];return i.forEach(n=>{s.push(this.clonedHighlightMaterial(n,e))}),s}else{if(i instanceof p.Material)return this.clonedHighlightMaterial(i,e);console.warn("[MaterialUtils] Invalid material: "+i)}}static clonedHighlightMaterial(t,e={}){const{depthTest:i=void 0,highlightColor:s=new p.Color(Ar),opacity:n=.7}=e,r=t.clone();return this.setMaterialColor(r,s),r.opacity=n,r.transparent=!0,i!==void 0&&(r.depthTest=i,r.side=p.DoubleSide),r}static cloneMaterial(t){if(!t)return t;if(Array.isArray(t)){const e=[];return t.forEach(i=>{e.push(i.clone())}),e}return t.clone()}static getMaterialColor(t){let e=new p.Color(16777215);return t instanceof p.PointsMaterial||t instanceof p.LineBasicMaterial||t instanceof p.MeshBasicMaterial?e=t.color:t instanceof p.ShaderMaterial&&t.uniforms.u_color&&(e=t.uniforms.u_color.value),e}static setMaterialColor(t,e){const i=t;i.color?.set(e),i.emissive?.set(e),i.uniforms?.u_color&&i.uniforms.u_color.value.set(e)}static setMaterialOpacity(t,e){const i=t;i.transparent=!0,i.opacity=e,i.uniforms?.opacity&&(i.uniforms.opacity.value=e)}static cloneMaterials(t){const e=new Map,i=s=>{if(Array.isArray(s)){const n=[];return s.forEach(r=>{let a=e.get(r);a||(a=r.clone(),e.set(r,a)),n.push(a)}),n}if(s){let n=e.get(s);return n||(n=s.clone(),e.set(s,n)),n}return s};t.traverse(s=>{const n=s;n.material&&(n.material=i(n.material))})}}const Xh=new p.Vector3(0,1,0),Xe=class Xe{static resetObjectStyle(t){this.revertWireframeMode(t),this.revertObjectOpacity(t,[]),this.revertAppliedMaterialToObject(t),this.revertVisibleForFloors(t)}static resetObjectStyleById(t,e){const i=this.getObjectById(t,e);this.resetObjectStyle(i)}static setObjectOpacity(t,e=.3,i,s){const n=[],r=o=>{n.find(l=>l.id===o.id)||(n.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side}),o.opacity*=e,o.transparent=!0,o.side=p.DoubleSide)},a=o=>{const l=n.find(h=>h.id===o.id);if(!l){const h=o.clone();return n.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side,material:o,clonedMaterial:h}),h.opacity*=e,h.transparent=!0,h}return l.clonedMaterial};return t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof p.Mesh){const l=o;if(i||s){if(Array.isArray(l.material)){const h=[];l.material.forEach(d=>{const u=a(d);u&&h.push(u)}),l.material=h}else if(l.material){const h=a(l.material);h&&(l.material=h)}}else if(Array.isArray(l.material))l.material.forEach(h=>{r(h)});else if(l.material){const h=l.material;r(h)}}}),n}static revertObjectOpacity(t,e,i,s){const n=new Set,r=o=>{if(!o||o.id==null||n.has(o.id))return;n.add(o.id);const l=e.find(h=>h.id===o.id);l&&(o.opacity=l.opacity,o.transparent=l.transparent,o.side=l.side,o.opacity===0&&P.warn("[ObjectUtils] Material '"+o.name+"'s opacity is 0, you may not be able to see your objects!"))},a=o=>{const l=e.find(h=>h.clonedMaterial&&h.clonedMaterial.id===o.id);if(l)return l.material};t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof p.Mesh){if(Array.isArray(o.material)){const l=[];o.material.forEach(h=>{const d=a(h);d?l.push(d):r(h)}),o.material=l}else if(o.material){const l=a(o.material);l?o.material=l:r(o.material)}}})}static setObjectOpacityById(t,e,i=.3,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);return Xe.setObjectOpacity(r,i,s,n)}static revertObjectOpacityById(t,e,i,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);Xe.revertObjectOpacity(r,i,s,n)}static applyMaterialToObject(t,e,i,s){t.traverse(n=>{s&&s.indexOf(n.id)!==-1||i&&i.indexOf(n.id)===-1||n instanceof p.Mesh&&(n.userData.originalMaterial||(n.userData.originalMaterial=n.material),n.material=e)})}static revertAppliedMaterialToObject(t,e,i){t.traverse(s=>{i&&i.indexOf(s.id)!==-1||e&&e.indexOf(s.id)===-1||s.userData.originalMaterial&&(s.material=s.userData.originalMaterial,s.userData.originalMaterial=void 0)})}static applyMaterialToObjectById(t,e,i,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);this.applyMaterialToObject(r,i,s,n)}static revertAppliedMaterialToObjectById(t,e,i,s){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);this.revertAppliedMaterialToObject(n,i,s)}static applyOpacityMaterialToObject(t,e,i){const s=new p.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});this.applyMaterialToObject(t,s,e,i)}static setDoubleSidedMaterialToObject(t){const e=i=>{i.side!==p.DoubleSide&&(i.userData.originalSide==null&&(i.userData.originalSide=i.side),i.side=p.DoubleSide)};t.traverse(i=>{i instanceof p.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof p.Material&&e(i.material))})}static revertDoubleSidedMaterialToObject(t){const e=i=>{i.userData.originalSide!=null&&(i.side=i.userData.originalSide,i.userData.originalSide=void 0)};t.traverse(i=>{i instanceof p.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof p.Material&&e(i.material))})}static setWireframeMode(t){const e=new p.MeshBasicMaterial({color:16732160,wireframe:!0,transparent:!0,opacity:.8});t.traverseVisible(i=>{if(i instanceof p.Mesh){const s=i;s.userData.materialForWireframe=s.material,s.material=e}})}static setWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);Xe.setWireframeMode(i)}static revertWireframeMode(t){t.traverseVisible(e=>{e instanceof p.Mesh&&e.userData.materialForWireframe&&(e.material=e.userData.materialForWireframe,e.userData.materialForWireframe=void 0)})}static revertWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);Xe.revertWireframeMode(i)}static findInner(t,e,i=[],s=!1){const n=e.toLowerCase(),r=[],a=h=>h.toLowerCase().indexOf(n)!==-1,o=h=>h.toString().indexOf(n)!==-1,l=h=>{if(h.name&&h.name.toLowerCase().indexOf(n)!==-1)return!0;if(h.gltfExtensions){const d=h.gltfExtensions,u=d.objectId&&d.objectId.Value||d.elementId&&d.elementId.Value;if(u&&u.toLowerCase().indexOf(n)!==-1)return!0}return!1};if(i.length>0)for(let h=0;h<i.length;++h){const d=i[h],u=t.getObjectById(d);if(u&&u.traverse(f=>{(a(f.name)||o(f.id)||l(f.userData))&&r.push(f)}),s&&r.length>0)return[r[0]]}else if(t.traverse(h=>{(a(h.name)||o(h.id)||l(h.userData))&&r.push(h)}),s&&r.length>0)return[r[0]];return r}static find(t,e,i=[],s=!1){return this.findInner(t,e,i,s)}static findFirst(t,e,i=[],s=!1){const n=this.findInner(t,e,i,s);if(n.length>0)return n[0]}static getFloorsFromString(t){const e=[],s=new RegExp(/(?:-?(?:\d+(?:\.5)?)F)(?=\W|$)/,"g").exec(t);return s&&s.length>0&&s.forEach(n=>{if(n){const r=n.replace("F",""),a=Number(r);a?e.push(a):console.log("[OU] invalid floor: "+n)}}),e}static matchFloor(t,e){return this.getFloorsFromString(t).findIndex(n=>n===e)!==-1}static matchFloors(t,e){return this.getFloorsFromString(t).findIndex(n=>e.findIndex(a=>a===n)!==-1)!==-1}static distinctFloors(t,e){const i=[],s=n=>{this.getFloorsFromString(n).forEach(a=>{i[a]=!0})};return e.forEach(n=>{const r=t.getObjectById(n);r&&r.traverse(a=>{if(s(a.name),a.userData.gltfExtensions){const o=a.userData.gltfExtensions;o.level&&o.level.Value&&s(o.level.Value)}})}),Object.keys(i).sort()}static traverseObjectByFloors(t,e,i,s,n){const r=t.getObjectById(e);if(!r)return[];r.traverse(a=>{let o=this.matchFloors(a.name,i);if(!o&&a.userData&&a.userData.gltfExtensions){const l=a.userData.gltfExtensions;l.level&&l.level.Value&&(o=this.matchFloors(l.level.Value,i))}o&&s&&s(a),!o&&n&&n(a)})}static setVisibleForFloors(t,e,i,s=!0){this.traverseObjectByFloors(t,e,i,n=>{let r=n;for(;r;)r.visible=!0,r=r.parent||void 0},n=>{s&&(n.visible=!1)})}static revertVisibleForFloors(t){t.traverse(e=>{e.visible=!0})}static revertVisibleForFloorsById(t,e){const i=this.getObjectById(t,e);this.revertVisibleForFloors(i)}static getObjectById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);return i}static async createOutlines(t,e={onlyVisible:!0,meshOnly:!0},i){if(!t)return[];if(t.children.length===0&&(e.onlyVisible&&!t.visible||e.meshOnly&&!(t instanceof p.Mesh)))return[];const s=[],n=t,r=n.children.length,a=Math.round(Math.pow(r,.5)),o=j.getUpdateProgressFuncAsync(i);for(let l=r-1;l>=0;--l){const h=r-l-1;let d;if(i&&(h%a===0||h===0||h===r-1)){const m=h*90/r,b=(h+1)*90/r;d=j.getUpdateSubProgressFunc(m,b,i)}const u=n.children[l],f=await this.createOutlines(u,e,d);s.push(...f)}if(!n.geometry)return await o(100),s;if(n instanceof p.Mesh&&!this.hasOutline(n,!1)){await o(50);const l=this.createOutline(n.geometry);n.add(l),l.updateWorldMatrix(!0,!1),s.push(l)}return await o(100),s}static removeOutlines(t){if(!(!t||!Array.isArray(t.children)))for(let e=t.children.length-1;e>=0;--e){const i=t.children[e];i.children.length>0&&this.removeOutlines(i),i.userData.isOutline&&t.remove(i)}}static hasOutline(t,e=!0){let i=!1;for(let s=0;s<t.children.length;++s){const n=t.children[s];if(n.userData.isOutline){i=!0;break}if(e&&n.children.length>0&&(i=this.hasOutline(n),i))break}return i}static setOutlinesVisibility(t,e){t.traverse(i=>{i.userData.isOutline&&(i.visible=e)})}static createOutline(t,e=this.OUTLINE_MATERIAL,i){const s=new p.EdgesGeometry(t,Br),n=new p.LineSegments(s,e);return n.layers.enableAll(),Xe.disableLayerChannels(n,[Ut,je]),n.userData.isOutline=!0,n.matrixAutoUpdate=ct,i&&n.applyMatrix4(i),n}static cloneObject(t,e=!0){const i=t.clone();return e&&i.traverse(s=>{if(s instanceof p.Mesh||s instanceof p.Line){const n=s;n.material=xe.cloneMaterial(n.material)}}),i}static createBox(t,e,i,s=this.BOX_FACE_MATERIAL,n=!0){const r=[],a=(h,d,u)=>{r.push(new p.Vector3(h,d,u))};a(0,0,0),a(t,0,0),a(t,e,0),a(0,e,0),a(0,0,i),a(t,0,i),a(t,e,i),a(0,e,i);const o=new p.BufferGeometry;o.setFromPoints(r);const l=[0,3,2,0,2,1,4,6,7,4,5,6,0,7,3,0,4,7,3,6,2,3,7,6,1,6,5,1,2,6];return n&&l.push(0,5,4,0,1,5),o.setIndex(l),o.computeVertexNormals(),new p.Mesh(o,s)}static rebaseObjectOnRTC(t){const e=t;if(!(e.isMesh||e.isLine||e.isPoints)||!e.geometry||!(e.geometry instanceof p.BufferGeometry))return t;const i=e.geometry;if(!i.hasAttribute("position"))return t;const s=i.getAttribute("position");if(s.count===0)return t;const n=s.itemSize,r=s.array,a=[];for(let h=0;h<n;h++)a.push(r[h]);for(let h=0;h<s.count;h++)for(let d=0;d<n;d++)r[h*n+d]-=a[d];t.updateMatrix();const o=t.matrix.clone();t.matrix.makeTranslation(a[0],a[1],a.length>2?a[2]:0);const l=t.matrixAutoUpdate;return t.matrixAutoUpdate=!1,t.applyMatrix4(o),t.matrixAutoUpdate=l,t}static isEmptyObject(t){if(t.children.length===0){const i=t.geometry;if(!i||!i.hasAttribute("position")||i.getAttribute("position").count===0)return!0}return!1}static removeEmptyObjects(t){for(let e=0;e<t.children.length;)this.removeEmptyObjects(t.children[e])||++e;return this.isEmptyObject(t)?(t.removeFromParent(),!0):!1}static removeEmptyObjectsFromRemovingObjects(t,e){t.length!==0&&(t.forEach(i=>{i.removeFromParent()}),this.removeEmptyObjects(e))}static setSharedVariablesOfObject(t){t.uuid="",t.up=Xh;const e=t;e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.uuid&&(i.uuid="")}):e.material.uuid&&(e.material.uuid=""))}static isLeafObject(t){return!(t instanceof p.Mesh)&&!(t instanceof p.Line)&&!(t instanceof p.Points)?!1:!!t.geometry}static enableLayerChannels(t,e,i=!0){for(let s=0,n=e.length;s<n;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Xe.enableLayerChannels(s[n],e,!0)}}static disableLayerChannels(t,e,i=!0){for(let s=0,n=e.length;s<n;s++)t.layers.disable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Xe.disableLayerChannels(s[n],e,!0)}}static setLayerChannels(t,e,i=!0){t.layers.disableAll();for(let s=0,n=e.length;s<n;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Xe.setLayerChannels(s[n],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(Oo)}static isObjectSnapable(t){return t.layers.isEnabled(je)}static isObjectSelectable(t){return t.layers.isEnabled(Ut)}};g(Xe,"OUTLINE_MATERIAL",new p.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),g(Xe,"BOX_FACE_MATERIAL",new p.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:p.FrontSide}));let J=Xe;const Hs=new p.Matrix4,Zh=new p.Matrix4,ds=class ds{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},n=[];for(let h=0;h<i;++h){const d=t.children[h];if(d.children.length>0){this.mergeInner(d,e);continue}if(d.isInstancedMesh||!d.geometry||!(d.geometry instanceof p.BufferGeometry))continue;let u=!1;const f=Object.values(s);for(let m=f.length-1;m>=0;--m){const b=f[m].indexes[0];if(u=this.tryHandleMergeableObjects(t,h,b,s,n),u)break}for(let m=n.length-1;!u&&m>=0;--m){const b=n[m];if(u=this.tryHandleMergeableObjects(t,h,b,s,n),u)break}!u&&n.push(h)}if(Object.keys(s).length<=0)return;const r=[],a=[],o=[],l=[];Object.values(s).forEach(h=>{const d=h.indexes,u=t.children[d[0]];let f=[],m=0,b=0,y=0;const C=[];if(d.forEach(x=>{const E=t.children[x],M=E.geometry.clone();if(M.applyMatrix4(E.matrix),N.tryConvertInterleavedBufferAttributes(M),M.userData.isLineSegments=E.isLineSegments===!0,f.push(M),e){const O=E.name,S=M.attributes?.position?.count,v=M.index?.count||0,T={batchId:m,name:O,positionStart:b,positionCount:S,indexStart:y,indexCount:v};Object.keys(E.userData).length!==0&&(T.userData=E.userData),C.push(T),b+=S,y+=v,m++}}),f.length===0)return;let w;if(u.isMesh){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new p.Mesh(x,u.material),r.push(w)}else if(u.isLine){const x=this.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,C);if(!x)return;w=new p.LineSegments(x,u.material),a.push(w)}else if(u.isPoints){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new p.Points(x,u.material),o.push(w)}w&&(e?w.userData.batches=C:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.matrixAutoUpdate=ct,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,w.visible=u.visible,l.push(...d)),f.forEach(x=>{x.dispose(),N.releaseGeometryManually(x)}),f=[]}),l.sort((h,d)=>d-h),l.forEach(h=>{const d=t.children[h];t.remove(d)}),[...r,...a,...o].forEach(h=>{t.add(h)}),t.updateMatrix(),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=r.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,n){let r=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return r;const l=a?t[e]:t.children[e],h=a?t[i]:t.children[i];return this.areObjectsMergeable(l,h)&&this.areGeometriesMergeable(l.geometry,h.geometry)&&xe.materialsEquals(l.material,h.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(n,i)),s[i].indexes.push(e),r=!0),r}static deepMerge(t,e=void 0,i=!0,s=!0,n=!0){const r={added:[],removed:[]};if(t.length<=1)return r;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){const C=t[y];if(C.isInstancedMesh||!C.geometry||!(C.geometry instanceof p.BufferGeometry))continue;let w=!1;const x=Object.values(o);for(let E=x.length-1;E>=0;--E){const M=x[E].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let E=l.length-1;!w&&E>=0;--E){const M=l[E];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}!w&&l.push(y)}if(Object.keys(o).length<=0)return r;P.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const h=[],d=[],u=[],f=[];Object.values(o).forEach(y=>{const C=y.indexes;if(C.length<2)return;const w=t[C[0]];let x=[],E=0,M=0,O=0;const S=[];if(C.forEach(T=>{const _=t[T],A=_.geometry.clone();if(w.material instanceof p.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,_,e),A.userData.isLineSegments=_.isLineSegments===!0,x.push(A),n){const I=_.name,B=A.attributes?.position?.count,k=A.index?.count||0;let L;w.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),L=A.boundingSphere.clone());const F={batchId:E,name:I,positionStart:M,positionCount:B,indexStart:O,indexCount:k,boundingSphere:L};!_.parent.geometry&&Object.keys(_.parent.userData).length!==0&&(F.parentUserData=_.parent.userData),Object.keys(_.userData).length!==0&&(F.userData=_.userData),S.push(F),M+=B,O+=k,E++}}),x.length===0)return;let v;if(w.isMesh){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new p.Mesh(T,w.material),h.push(v)}else if(w.isLine){const T=this.mergeLineGeometries(x,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,S);if(!T)return;v=new p.LineSegments(T,w.material),d.push(v)}else if(w.isPoints){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new p.Points(T,w.material),u.push(v)}v&&(n?v.userData.batches=S:(v.userData=w.userData,v.userData.batches=void 0),v.userData.layerName=w.userData.layerName,v.name="[Merged] "+w.name,v.matrixAutoUpdate=ct,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,v.visible=w.visible,C.forEach(T=>f.push(T))),x.forEach(T=>{T.dispose(),N.releaseGeometryManually(T)}),x=[]}),P.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(y=>{const C=t[y];m.push(C),i&&C.removeFromParent()});const b=r.added;return[...h,...d,...u].forEach(y=>{b.push(y),i&&e&&(e.add(y),y.updateWorldMatrix(!1,!1))}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&J.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Hs.identity();s&&s!==i&&(Hs.premultiply(s.matrix),!!s.parent);)s=s.parent;return Hs.equals(Zh)?t:t.applyMatrix4(Hs)}static mergeLineGeometries(t,e,i,s){let n;if(i)n=ds.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(n=Pe.mergeGeometries(t),!n)return;n.userData={};const r=[];let a=0;t.forEach((o,l)=>{const h=o.attributes.position;if(!h)return;const d=o.index,u=o.userData.isLineSegments===!0,f=r.length;if(d)for(let m=0;m<d.count;m++){const b=d.array[m];u?r.push(a+b):m>0&&r.push(a+d.array[m-1],a+b)}else for(let m=0;m<h.count;m++)m>0&&(u?m%2===1&&r.push(a+m-1,a+m):r.push(a+m-1,a+m));a+=h.count,e&&s&&(s[l].indexStart=f,s[l].indexCount=r.length-f)}),n.setIndex(r)}return n}static mergeBufferGeometriesWithLinesToLineSegments(t,e,i){const s=new Set(Object.keys(t[0].attributes)),n={},r=new p.BufferGeometry,a=[];let o=0;for(let l=0;l<t.length;++l){let h=t[l];const d=h.userData.isLineSegments===!0;a.push(d),h.index&&(P.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),h=N.convertGeometryWithIndexedToNonIndexed(h));let u=0;for(const f in h.attributes){if(!s.has(f))return P.error("[Merge] mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure "+f+" attribute exists among all geometries, or in none of them"),void 0;!n[f]&&(n[f]=[]),n[f].push(h.attributes[f]),u++}if(u!==s.size)return P.error("[Merge] mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),void 0;if(e&&i){const f=h.attributes.position;i[l].indexStart=0,i[l].indexCount=0;const m=d?f.count:f.count*2-2;i[l].positionStart=o,i[l].positionCount=m,o+=m}}for(const l in n){const h=ds.mergeBufferAttributesWithLinesToLineSegments(n[l],a);if(!h)return P.error("[Merge] mergeGeometries() failed while trying to merge the "+l+" attribute."),void 0;r.setAttribute(l,h)}return r}static mergeBufferAttributesWithLinesToLineSegments(t,e){let i,s,n,r=0;for(let l=0;l<t.length;++l){const h=t[l];if(i===void 0&&(i=h.array.constructor),i!==h.array.constructor)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes."),void 0;if(s===void 0&&(s=h.itemSize),s!==h.itemSize)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes."),void 0;if(n===void 0&&(n=h.normalized),n!==h.normalized)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes."),void 0;const d=e[l],u=d?0:h.count-2,f=h.count+u;r+=f*s}const a=new i(r);let o=0;for(let l=0;l<t.length;++l){const h=e[l],d=t[l],u=h?0:d.count-2,f=d.count+u,m=d.itemSize,b=new i(f*m);let y=0;for(let C=0;C<d.count;C++){const w=C*m,x=C!==0&&C!==d.count-1&&!h;for(let E=0;E<m;E++)b[y+E]=d.array[w+E],x&&(b[y+m+E]=d.array[w+E]);y+=x?2*m:m}a.set(b,o),o+=f*m}return new p.BufferAttribute(a,s,n)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static removeObjectFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areGeometriesMergeable(t,e){if(!t||!e||t.type==="InstancedBufferGeometry"||e.type==="InstancedBufferGeometry"||!!t.index!=!!e.index)return!1;const i=Object.keys(t.attributes);if(i.length!==Object.keys(e.attributes).length)return!1;for(const s of i)if(!e.attributes[s])return!1;return!0}static areObjectsMergeable(t,e){if(t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.visible!==e.visible||t.userData.layerName!==e.userData.layerName)return!1;if(t.type===e.type)return!0;const i=t,s=e;return i.isMesh&&s.isMesh||i.isLine&&s.isLine||i.isPoints&&s.isPoints}static isMergedMesh(t){return!!(t&&t.userData.batches)}static isFaceIndexInBatch(t,e,i){if(t.boundsTree){const s=t.index,n=s.getX(i*3);if(n>=e.positionStart&&n<e.positionStart+e.positionCount)return!0}else if(t.index){const s=e.indexStart/3,n=(e.indexStart+e.indexCount)/3-1;if(i>=s&&i<=n)return!0}else{const s=i*3;if(s>=e.positionStart&&s<e.positionStart+e.positionCount)return!0}return!1}static getBatchByFaceIndex(t,e){if(e<0)return P.error("[Merge]: Invalid faceIndex: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const n=i[s];if(this.isFaceIndexInBatch(t.geometry,n,e))return n}}static getBatchByLineIndex(t,e){if(e<0)return P.error("[Merge]: Invalid index: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(!i)return;const s=t.geometry,n=s.index;for(let r=0;r<i.length;++r){const a=i[r];if(n){if(e>=a.indexStart&&e<a.indexStart+a.indexCount)return a}else if(e>=a.positionStart&&e<a.positionStart+a.positionCount)return a}}static getBatchIdByFaceIndex(t,e){const i=this.getBatchByFaceIndex(t,e);return i?i.batchId:-1}static getBatchByBatchId(t,e){const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const n=i[s];if(n.batchId===e)return n}}static cloneGeometryForBatch(t,e){const i=t&&t.geometry;if(!i)return;const s=i.attributes.position,n=s?.array;let r=i.index?.array;if(!n||!r)return P.warn("[Merge]: Unexpected position: "+n+", or index: "+r+"!"),void 0;const a=new p.BufferGeometry,o=e.positionStart,l=e.positionStart+e.positionCount,h=i.attributes;for(const b in h){const y=h[b],C=y.itemSize,w=y.array.slice(o*C,l*C);a.setAttribute(b,new p.BufferAttribute(w,C,y.normalized))}if(i.boundsTree&&(r=i.userData.originalIndex,!r))return P.warn("[Merge] After building bvh, the original index data is not preserved !"),void 0;const d=e.indexStart,u=e.indexStart+e.indexCount,f=[];let m=0;for(let b=d;b<u&&b<r.length;++b)f[m++]=r[b]-e.positionStart;return a.setIndex(f),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};g(ds,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let fe=ds;const Kh=.01;class $h{static getFaces(t){const e=t.map(n=>n.toArray()).reduce((n,r)=>(n.push(...r),n),[]),i=[];return Il.Earcut.triangulate(e,[],3).forEach(n=>i.push(n)),i}static arePointsCoplanar(t){if(t.length<4)return!0;const e=t[1].clone().sub(t[0]),s=t[2].clone().sub(t[0]).cross(e).normalize();for(let n=3;n<t.length;n++)if(t[n].clone().sub(t[0]).projectOnVector(s).length()>Kh)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return Bl(e).length>0}}class Ot{static getVisibleObjectBoundingBox(t){const e=new p.Box3;return t.traverse(i=>{i.visible&&(i instanceof p.Mesh||i instanceof p.Line)&&J.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new p.Box3;return e.forEach(n=>{const r=t.getObjectById(n);if(r){const a=Ot.getBoundingBox(r,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new p.Box3;if(t instanceof p.InstancedMesh)return Ot.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let n=1;s>20&&(n=3),s>100&&(n=5),s>200&&(n=10),s>1e3&&(n=100),t.updateMatrixWorld(!1);for(let r=0;r<s;++r){const a=t.children[r];if(!e||r%n===0)if(a.updateMatrix(),a instanceof p.InstancedMesh){const o=Ot.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(j.isMatrixValid(a.matrixWorld)){const o=Ot.getBoundingBox(a);o.isEmpty()||i.union(o)}else console.warn("[SceneUtils] Found object("+a.type+") with invalid matrix: "+a.matrixWorld.elements)}return t.geometry&&i.expandByObject(t),i}static getInstancedMeshBoundingBox(t){const e=new p.Box3,i=new p.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const n=t.geometry.clone();if(n.boundingBox){const r=n.boundingBox.applyMatrix4(i);!r.isEmpty()&&j.isBoxValid(r)&&e.union(r)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=Ot.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class zt{static setMaterialSection(t,e,i=!1,s=!1){const n=i&&t.clippingPlanes?t.clippingPlanes:[];n.push(...e),t.clippingPlanes=n,t.clipIntersection=s}static removeSection(t){t&&t.traverse(e=>{const i=e.material;Array.isArray(i)?i.forEach(s=>{s.clippingPlanes=[]}):i&&(i.clippingPlanes=[])})}static addSection(t,e,i=!1,s=!1){t&&t.traverse(n=>{const r=n.material;Array.isArray(r)?r.forEach(a=>{zt.setMaterialSection(a,e,i,s)}):r&&zt.setMaterialSection(r,e,i,s)})}static generateSectionPlanesByBox(t){const e=t.min,i=t.max;return[new p.Plane(new p.Vector3(0,-1,0),i.y),new p.Plane(new p.Vector3(0,1,0),-e.y),new p.Plane(new p.Vector3(1,0,0),-e.x),new p.Plane(new p.Vector3(-1,0,0),i.x)]}static generateSectionPlanesByPoints(t,e=!0){const i=t.length;if(i<2)return;const s=[];for(let n=0;n<i-1;n++){const r=t[n],a=t[(n+1)%i],o=new p.Plane;o.setFromCoplanarPoints(new p.Vector3(r.x,r.y,-1),new p.Vector3(r.x,r.y,0),new p.Vector3(a.x,a.y,0)),e||o.negate(),s.push(o)}return s}}class Jh{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new kl.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof p.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const Qh=10;var St=(c=>(c.TripleCross="TripleCross",c.Square="Square",c.Triangle="Triangle",c.CircleWithCross="CircleWithCross",c.Cross="Cross",c.Perpendicular="Perpendicular",c))(St||{});class ed{static createSVGObject(t){return new Dl.SVGObject(t)}}class ms{static async createEnvTexture(t,e){const i=new Ll.RGBELoader;return new Promise(s=>{i.load(e,n=>{if(t){const r=t.fromEquirectangular(n).texture;t.dispose(),s(r)}})})}static async createEnvTextureFromDataArray(t,e=this.HDR_CITY_STREET_64x32,i=64,s=32){if(t){const n=new p.DataTexture(e,i,s);n.flipY=!0,n.magFilter=p.LinearFilter,n.minFilter=p.LinearFilter,n.type=p.HalfFloatType,n.version=1;const r=t.fromEquirectangular(n).texture;return t.dispose(),Promise.resolve(r)}return Promise.reject("Invalid pmremGenerator!")}}g(ms,"HDR_CITY_STREET_64x32",Uint16Array.from([11910,12340,12797,15360,11926,12348,12806,15360,11958,12364,12814,15360,11974,12380,12830,15360,11958,12364,12822,15360,11926,12348,12797,15360,11878,12324,12773,15360,11830,12308,12749,15360,11798,12292,12733,15360,11782,12279,12725,15360,11765,12263,12709,15360,11749,12247,12701,15360,11733,12231,12701,15360,11701,12215,12693,15360,11685,12199,12685,15360,11685,12199,12685,15360,11701,12215,12693,15360,11717,12231,12701,15360,11733,12247,12709,15360,11749,12263,12717,15360,11749,12279,12717,15360,11765,12279,12725,15360,11765,12279,12725,15360,11765,12292,12725,15360,11798,12300,12733,15360,11830,12316,12749,15360,11846,12324,12757,15360,11894,12340,12781,15360,11926,12356,12797,15360,11942,12356,12797,15360,11926,12348,12789,15360,11926,12348,12789,15360,11942,12356,12797,15360,11942,12356,12797,15360,11942,12348,12806,15360,11942,12356,12806,15360,11942,12356,12814,15360,11958,12372,12830,15360,11974,12372,12830,15360,11974,12372,12838,15360,11990,12388,12854,15360,12055,12420,12886,15360,12119,12452,12918,15360,12167,12476,12950,15360,12231,12500,12982,15360,12263,12516,12998,15360,12231,12500,12974,15360,12199,12484,12958,15360,12199,12484,12958,15360,12199,12492,12966,15360,12247,12508,12982,15360,12247,12508,12990,15360,12231,12500,12982,15360,12199,12484,12966,15360,12167,12468,12942,15360,12119,12444,12918,15360,12087,12436,12902,15360,12055,12420,12886,15360,12055,12412,12878,15360,12039,12412,12878,15360,12022,12396,12862,15360,12006,12388,12846,15360,11958,12364,12830,15360,11910,12340,12806,15360,12119,12508,13103,15360,12087,12484,13071,15360,12055,12468,13046,15360,12006,12436,13006,15360,11926,12396,12958,15360,11878,12364,12926,15360,11846,12348,12894,15360,11782,12308,12854,15360,11749,12292,12830,15360,11717,12263,12814,15360,11685,12247,12806,15360,11669,12215,12789,15360,11685,12231,12789,15360,11701,12247,12797,15360,11701,12247,12806,15360,11717,12263,12814,15360,11749,12292,12822,15360,11782,12308,12838,15360,11798,12316,12846,15360,11814,12332,12862,15360,11846,12340,12870,15360,11862,12348,12878,15360,11846,12340,12870,15360,11846,12340,12862,15360,11878,12356,12886,15360,11910,12372,12910,15360,11942,12396,12934,15360,11958,12412,12958,15360,12039,12452,12998,15360,12071,12468,13022,15360,12039,12452,12998,15360,12039,12452,12998,15360,12006,12444,13006,15360,11974,12436,12998,15360,11942,12412,12982,15360,11926,12396,12974,15360,11926,12404,12974,15360,11958,12420,12998,15360,12006,12452,13038,15360,12055,12476,13071,15360,12039,12476,13079,15360,12087,12508,13127,15360,12247,12597,13231,15360,12388,12693,13332,15360,12420,12741,13364,15360,12436,12757,13372,15360,12468,12773,13380,15360,12500,12806,13388,15360,12516,12822,13404,15360,12629,12934,13452,15360,12741,13046,13508,15360,12806,13095,13532,15360,12757,13046,13516,15360,12645,12950,13460,15360,12565,12870,13428,15360,12532,12838,13412,15360,12549,12854,13412,15360,12516,12838,13396,15360,12452,12757,13356,15360,12420,12725,13340,15360,12404,12709,13332,15360,12372,12677,13316,15360,12279,12589,13207,15360,12135,12516,13119,15360,12388,12709,13348,15360,12247,12581,13223,15360,12055,12476,13087,15360,11910,12388,12982,15360,11733,12308,12886,15360,11669,12247,12846,15360,11621,12199,12814,15360,11541,12103,12765,15360,11492,12055,12733,15360,11508,12055,12733,15360,11476,12022,12717,15360,11525,12055,12725,15360,11589,12135,12757,15360,11669,12199,12765,15360,11765,12292,12814,15360,11862,12348,12886,15360,11910,12372,12910,15360,12006,12420,12966,15360,12071,12452,12998,15360,12119,12476,13022,15360,12167,12492,13046,15360,12183,12500,13063,15360,12199,12524,13079,15360,12308,12589,13151,15360,12300,12581,13151,15360,12167,12516,13087,15360,12087,12468,13030,15360,12022,12444,13014,15360,11990,12420,12990,15360,11974,12420,12990,15360,11974,12420,12990,15360,11990,12436,13014,15360,11990,12444,13030,15360,12103,12500,13103,15360,12087,12508,13111,15360,12039,12484,13103,15360,12039,12476,13103,15360,11942,12436,13054,15360,11974,12452,13087,15360,12039,12492,13135,15360,12103,12532,13199,15360,12183,12581,13263,15360,12308,12661,13340,15360,12484,12822,13436,15360,12613,12918,13484,15360,12725,13046,13540,15360,13046,13332,13677,15360,13143,13380,13717,15360,13223,13420,13741,15360,13396,13540,13862,15360,13436,13589,13902,15360,13484,13629,13942,15360,13468,13621,13934,15360,13412,13564,13878,15360,13372,13524,13846,15360,13287,13452,13781,15360,13223,13428,13749,15360,13340,13492,13805,15360,13239,13428,13749,15360,13095,13364,13685,15360,12918,13223,13597,15360,12822,13111,13556,15360,12613,12934,13468,15360,12532,12854,13428,15360,12565,12870,13444,15360,12468,12789,13396,15360,12372,12693,13340,15360,12087,12492,13111,15360,11846,12364,12958,15360,11717,12300,12878,15360,11557,12135,12781,15360,11476,12055,12741,15360,11460,12022,12725,15360,11476,12022,12725,15360,11476,12022,12709,15360,11476,11958,12605,15360,11364,11733,12332,15360,11111,11412,11661,15360,11223,11476,11773,15360,11388,11669,12095,15360,11765,12119,12492,15360,12388,12613,13079,15360,12661,12902,13356,15360,12998,13255,13564,15360,13372,13508,13797,15360,13412,13548,13846,15360,13287,13436,13725,15360,13271,13428,13709,15360,13287,13428,13717,15360,13014,13287,13597,15360,12709,12998,13460,15360,12452,12741,13332,15360,12364,12653,13271,15360,12404,12693,13316,15360,12420,12709,13316,15360,12420,12709,13332,15360,12263,12589,13231,15360,12332,12661,13312,15360,12300,12629,13295,15360,12263,12605,13287,15360,12231,12597,13279,15360,12247,12613,13303,15360,12231,12597,13295,15360,12231,12605,13312,15360,12199,12597,13324,15360,12231,12613,13340,15360,12516,12870,13468,15360,12725,13063,13564,15360,12741,13079,13573,15360,12854,13175,13613,15360,12902,13223,13629,15360,13046,13348,13693,15360,13356,13516,13846,15360,13605,13765,14078,15360,13717,13870,14191,15360,13765,13918,14255,15360,13765,13910,14247,15360,13701,13854,14191,15360,13573,13733,14070,15360,13508,13677,14006,15360,13380,13548,13886,15360,13111,13380,13741,15360,13063,13348,13709,15360,12886,13207,13629,15360,12725,13046,13548,15360,12645,12966,13508,15360,12677,12982,13508,15360,12629,12950,13492,15360,12452,12789,13412,15360,12324,12661,13332,15360,12356,12677,13340,15360,12388,12693,13348,15360,12279,12597,13247,15360,11894,12396,12998,15360,11637,12231,12846,15360,11573,12135,12789,15360,11589,12151,12797,15360,11621,12167,12797,15360,11637,12119,12677,15360,11079,11404,11693,15360,10517,10701,10653,15360,10252,10348,10007,15360,9902,9999,9428,15360,9846,9886,9047,15360,10135,10260,9685,15360,10412,10533,10412,15360,11268,11436,11549,15360,12364,12605,13087,15360,12444,12709,13255,15360,12549,12822,13348,15360,12613,12886,13396,15360,12597,12886,13412,15360,12581,12870,13404,15360,12661,12950,13460,15360,12725,13014,13492,15360,13079,13332,13645,15360,12757,13046,13500,15360,12677,12982,13476,15360,12854,13143,13556,15360,12693,12982,13492,15360,12581,12886,13452,15360,12709,13030,13508,15360,12372,12709,13364,15360,12324,12661,13348,15360,12292,12645,13340,15360,12292,12645,13348,15360,12468,12806,13436,15360,12532,12854,13460,15360,12500,12854,13468,15360,12500,12854,13484,15360,12725,13063,13589,15360,12982,13324,13701,15360,13111,13388,13741,15360,13014,13340,13709,15360,13014,13332,13717,15360,13287,13476,13862,15360,13436,13621,13974,15360,13532,13717,14095,15360,13725,13902,14295,15360,13942,14103,14420,15360,13974,14135,14436,15360,13862,14022,14388,15360,13725,13894,14295,15360,13789,13958,14336,15360,13830,13990,14348,15360,13372,13548,13942,15360,13014,13332,13733,15360,12886,13239,13661,15360,12854,13207,13637,15360,12757,13095,13589,15360,12757,13079,13573,15360,12645,12982,13516,15360,12629,12966,13532,15360,12549,12870,13468,15360,12356,12693,13372,15360,12151,12549,13231,15360,12215,12573,13247,15360,12199,12565,13231,15360,12071,12492,13135,15360,12055,12468,13087,15360,11878,12372,12958,15360,11685,12199,12781,15360,10774,11159,11412,15360,9533,9621,8870,15360,9308,9340,8071,15360,9276,9300,7878,15360,9324,9332,8420,15360,9191,9216,7991,15360,8950,8983,7766,15360,9493,9525,8677,15360,10252,10332,10007,15360,10661,10846,10894,15360,10701,10926,10998,15360,10950,11276,11428,15360,11364,11637,12063,15360,11958,12388,12926,15360,12183,12540,13175,15360,12340,12645,13295,15360,12420,12693,13316,15360,12757,13030,13460,15360,13046,13324,13645,15360,13095,13348,13677,15360,13303,13460,13781,15360,13207,13404,13741,15360,13127,13372,13717,15360,13372,13524,13862,15360,12693,13030,13540,15360,12725,13046,13548,15360,12468,12822,13436,15360,12263,12629,13348,15360,12436,12773,13428,15360,12693,12998,13524,15360,12725,13046,13564,15360,12645,12982,13556,15360,12613,12966,13556,15360,12886,13255,13685,15360,13436,13629,14022,15360,13637,13813,14231,15360,13621,13789,14215,15360,13878,14038,14412,15360,14022,14183,14468,15360,13926,14119,14452,15360,14054,14231,14508,15360,14135,14311,14540,15360,14348,14436,14669,15360,14460,14540,14749,15360,14404,14484,14709,15360,14420,14500,14709,15360,14653,14717,14894,15360,14119,14279,14508,15360,13484,13669,14078,15360,13063,13380,13773,15360,12677,13079,13613,15360,12484,12886,13516,15360,12436,12822,13476,15360,12468,12838,13476,15360,12039,12532,13316,15360,12231,12613,13340,15360,12468,12789,13436,15360,12388,12725,13396,15360,12135,12557,13287,15360,12151,12557,13271,15360,12039,12484,13175,15360,11878,12396,13038,15360,11814,12348,12950,15360,11492,11894,12460,15360,9950,10103,9621,15360,8830,8838,7220,15360,8565,8533,7015,15360,8541,8501,6919,15360,8332,8300,6822,15360,8412,8372,7220,15360,8710,8701,7686,15360,9372,9404,8549,15360,9533,9621,9079,15360,9268,9292,8196,15360,9452,9460,8167,15360,9533,9581,8533,15360,9742,9870,9316,15360,11460,11814,12348,15360,11942,12388,12902,15360,11749,12167,12573,15360,11300,11492,11621,15360,11974,12332,12669,15360,12436,12741,13364,15360,12597,12886,13460,15360,12966,13271,13653,15360,12998,13303,13669,15360,13476,13629,13974,15360,13733,13886,14239,15360,13364,13524,13894,15360,13063,13356,13725,15360,12982,13287,13669,15360,12484,12806,13444,15360,12565,12902,13500,15360,12950,13287,13693,15360,12934,13271,13677,15360,12693,13046,13589,15360,12661,13030,13605,15360,12870,13271,13717,15360,13348,13548,13966,15360,13621,13813,14271,15360,13797,13974,14412,15360,13942,14119,14484,15360,14263,14388,14629,15360,14420,14508,14733,15360,14460,14548,14773,15360,14982,15046,15231,15360,15564,15580,15669,15360,15974,15982,16078,15360,15805,15821,15926,15360,15460,15476,15572,15360,15436,15460,15556,15360,14781,14862,15127,15360,13621,13813,14348,15360,12789,13207,13757,15360,12452,12886,13581,15360,12263,12709,13476,15360,12039,12597,13396,15360,11942,12516,13340,15360,11846,12468,13271,15360,11733,12380,13127,15360,11926,12460,13191,15360,12055,12524,13263,15360,11878,12428,13159,15360,11605,12231,12886,15360,11412,11990,12709,15360,11508,12103,12789,15360,11637,12231,12854,15360,10661,11079,11380,15360,9541,9685,9252,15360,8573,8605,7493,15360,8404,8388,7348,15360,8830,8822,8212,15360,9308,9324,9095,15360,9324,9364,9220,15360,9047,9119,8653,15360,9023,9055,8404,15360,9055,9063,8167,15360,8870,8846,7541,15360,8862,8806,7380,15360,8950,8910,7252,15360,9268,9284,7557,15360,10316,10468,10380,15360,11239,11476,11677,15360,10653,10942,11047,15360,9661,9814,9324,15360,10693,10958,11047,15360,11396,11653,11990,15360,11878,12292,12597,15360,12468,12789,13396,15360,12773,13095,13589,15360,13364,13516,13894,15360,13894,14054,14380,15360,13717,13870,14247,15360,13420,13589,13958,15360,13255,13452,13830,15360,12806,13143,13637,15360,13159,13412,13830,15360,13629,13813,14215,15360,13303,13500,13910,15360,13079,13396,13805,15360,13191,13452,13878,15360,13412,13621,14062,15360,14103,14279,14540,15360,14773,14854,15086,15360,14717,14805,15046,15360,14295,14420,14685,15360,14380,14476,14733,15360,14572,14661,14902,15360,15596,15612,15701,15360,16351,16335,16384,15360,16484,16476,16492,15360,16516,16500,16516,15360,16388,16375,16404,15360,16054,16054,16118,15360,15918,15926,16006,15360,15556,15572,15669,15360,14653,14725,14982,15360,13637,13838,14319,15360,13412,13613,14054,15360,12870,13287,13789,15360,12404,12838,13524,15360,12199,12677,13428,15360,12324,12741,13452,15360,11942,12516,13324,15360,11765,12380,13111,15360,11428,11942,12589,15360,10886,11388,11902,15360,10372,10717,11006,15360,9846,10240,10191,15360,10252,10549,10766,15360,10613,11079,11484,15360,10581,10998,11388,15360,9613,9846,9629,15360,8525,8557,7541,15360,8605,8613,7814,15360,9292,9324,9079,15360,9388,9396,9220,15360,10709,10846,11031,15360,9894,9966,9854,15360,9252,9236,8774,15360,8822,8790,8183,15360,8292,8260,6533,15360,8111,8007,6324,15360,8228,8183,6405,15360,8501,8501,6565,15360,8814,8878,7172,15360,9260,9364,8244,15360,8902,9095,8252,15360,9444,9581,9047,15360,9509,9637,8790,15360,9477,9613,8806,15360,10725,11063,11079,15360,11508,11910,12356,15360,12484,12789,13380,15360,12838,13159,13629,15360,13428,13589,13974,15360,14135,14279,14484,15360,13942,14087,14396,15360,13677,13846,14247,15360,13436,13613,14006,15360,13597,13781,14183,15360,14183,14340,14540,15360,14022,14215,14484,15360,13637,13838,14271,15360,14038,14231,14508,15360,14380,14476,14701,15360,14757,14854,15078,15360,15030,15111,15343,15360,15420,15452,15556,15360,15476,15500,15588,15360,15351,15388,15492,15360,15572,15596,15677,15360,15653,15669,15717,15360,15821,15821,15853,15360,15845,15845,15869,15360,15998,15990,16022,15360,15926,15926,15974,15360,15653,15669,15733,15360,15661,15677,15749,15360,15612,15629,15717,15360,15271,15335,15452,15360,14484,14572,14821,15360,14215,14372,14588,15360,13468,13677,14167,15360,12773,13175,13653,15360,12725,13143,13637,15360,12452,12886,13532,15360,12263,12709,13444,15360,11894,12436,13103,15360,10252,10533,10661,15360,8613,8693,7445,15360,8742,8782,7047,15360,8420,8412,6565,15360,7926,7910,6405,15360,8806,8854,7300,15360,9127,9228,8007,15360,8685,8750,7300,15360,8348,8356,6758,15360,8380,8340,7300,15360,8991,8918,8388,15360,9838,9790,9549,15360,10055,10127,10047,15360,9501,9493,9268,15360,9332,9292,8902,15360,9079,9007,8509,15360,8300,8260,7252,15360,8693,8701,8196,15360,8228,8212,7111,15360,8469,8501,7380,15360,8420,8501,6919,15360,8549,8645,6983,15360,8581,8661,6951,15360,9268,9332,7718,15360,9063,9207,7445,15360,9284,9380,7718,15360,9412,9557,8693,15360,10276,10517,10103,15360,11830,12279,12589,15360,12725,13079,13589,15360,13127,13396,13773,15360,14087,14231,14460,15360,13974,14119,14412,15360,13677,13854,14247,15360,14119,14279,14500,15360,13990,14167,14460,15360,14364,14452,14653,15360,14564,14653,14837,15360,14404,14492,14701,15360,14870,14942,15135,15360,15388,15420,15500,15360,15207,15287,15420,15360,14797,14894,15127,15360,15271,15335,15452,15360,15926,15942,15990,15360,16207,16207,16231,15360,16118,16110,16126,15360,15741,15733,15741,15360,16239,16207,16175,15360,16444,16460,16484,15360,16046,16022,16006,15360,15942,15950,15966,15360,15773,15789,15829,15360,15789,15797,15845,15360,15693,15709,15757,15360,15540,15564,15653,15360,15303,15364,15468,15360,14733,14813,15014,15360,13862,14054,14420,15360,12838,13255,13725,15360,12789,13207,13693,15360,12468,12918,13564,15360,12404,12838,13500,15360,11428,11862,12412,15360,9143,9276,8388,15360,8541,8533,6726,15360,8444,8428,6629,15360,8212,8183,6597,15360,8388,8380,7015,15360,8726,8710,6758,15360,8332,8316,6437,15360,8453,8428,6565,15360,8597,8605,7814,15360,8701,8661,8151,15360,9452,9396,9015,15360,10581,10557,10380,15360,10950,10974,10846,15360,10380,10356,10252,15360,10749,10741,10685,15360,9870,9854,9693,15360,9023,9039,8669,15360,8790,8854,8509,15360,8196,8167,7332,15360,7975,8015,7079,15360,8589,8750,7445,15360,9095,9260,7111,15360,8983,9135,7188,15360,8902,8991,7252,15360,8862,9007,7015,15360,8967,9111,7300,15360,8742,8878,7493,15360,9557,9999,9549,15360,11292,11613,11862,15360,12135,12468,12982,15360,12215,12460,12878,15360,13356,13468,13685,15360,13821,13934,14199,15360,13548,13701,14022,15360,14103,14263,14468,15360,14279,14388,14572,15360,14364,14452,14645,15360,14709,14789,14950,15360,15143,15199,15327,15360,15388,15412,15468,15360,15476,15500,15548,15360,15420,15444,15492,15360,15436,15460,15516,15360,15612,15637,15685,15360,16086,16086,16110,15360,16396,16388,16396,15360,16094,16094,16110,15360,15869,15861,15861,15360,16135,16110,16070,15360,16428,16420,16404,15360,15588,15556,15524,15360,15484,15500,15508,15360,15335,15364,15396,15360,15677,15685,15717,15360,15604,15621,15661,15360,15420,15444,15500,15360,15303,15372,15452,15360,14717,14805,14998,15360,14412,14508,14701,15360,13548,13765,14199,15360,13271,13508,13942,15360,12661,13159,13709,15360,12468,12854,13436,15360,10260,10484,10509,15360,8613,8669,6951,15360,8151,8143,6469,15360,8653,8629,7814,15360,8469,8444,7541,15360,8718,8693,7814,15360,8372,8332,6597,15360,8356,8308,7111,15360,9047,8983,8396,15360,8822,8798,8308,15360,9372,9348,8967,15360,10364,10364,10183,15360,10268,10260,9894,15360,10541,10533,10468,15360,10380,10364,10276,15360,10621,10613,10549,15360,9910,9942,9758,15360,8364,8380,7621,15360,8581,8637,8135,15360,8252,8300,7573,15360,8119,8175,7300,15360,8372,8453,7493,15360,8420,8501,6983,15360,8742,8822,7573,15360,8782,8854,8151,15360,8581,8661,7079,15360,9220,9268,8340,15360,9549,9645,8854,15360,11717,11950,12127,15360,12468,12741,13207,15360,12709,12966,13388,15360,12300,12508,12886,15360,12492,12709,13063,15360,13239,13372,13548,15360,12476,12597,12814,15360,13581,13685,13878,15360,14476,14548,14685,15360,14556,14629,14773,15360,14765,14829,14966,15360,15159,15207,15303,15360,15372,15396,15444,15360,15516,15532,15572,15360,15653,15661,15693,15360,15829,15837,15853,15360,16022,16014,16022,15360,16311,16295,16279,15360,16343,16319,16303,15360,16412,16388,16359,15360,15813,15797,15773,15360,13063,13151,13183,15360,11484,11701,11798,15360,12300,12412,12468,15360,14613,14637,14653,15360,11974,12215,12316,15360,14135,14215,14303,15360,15604,15629,15677,15360,15524,15548,15596,15360,15351,15380,15428,15360,14797,14894,15054,15360,13990,14231,14500,15360,13492,13709,14070,15360,12886,13316,13701,15360,12613,13207,13749,15360,11525,11974,12428,15360,9284,9412,8629,15360,8597,8653,6951,15360,7806,7790,6292,15360,7589,7541,6437,15360,7485,7437,6597,15360,7453,7404,6180,15360,7774,7686,6565,15360,8300,8260,7332,15360,9918,9942,9862,15360,10348,10372,10231,15360,9725,9709,9228,15360,10613,10621,10509,15360,10199,10175,9838,15360,10380,10388,10340,15360,11207,11255,11284,15360,10661,10717,10725,15360,10103,10135,9950,15360,8444,8436,7669,15360,8469,8501,7445,15360,8950,9111,8854,15360,9485,9798,10071,15360,8364,8501,8039,15360,7959,7951,6806,15360,8597,8605,8039,15360,8501,8533,7557,15360,8758,8830,7509,15360,10758,10830,10693,15360,11508,11605,11621,15360,13524,13669,13886,15360,13830,14022,14327,15360,13926,14103,14364,15360,13460,13621,13886,15360,12854,13191,13420,15360,13597,13733,13926,15360,13846,13990,14223,15360,13773,13942,14199,15360,13910,14087,14356,15360,13813,14022,14319,15360,14247,14396,14540,15360,14693,14765,14878,15360,15223,15279,15343,15360,15508,15524,15540,15360,15540,15548,15564,15360,15327,15335,15319,15360,15303,15311,15303,15360,15918,15910,15886,15360,16247,16207,16151,15360,16175,16143,16086,15360,14436,14452,14436,15360,12263,12380,12404,15360,11476,11701,11773,15360,12380,12492,12532,15360,14797,14797,14757,15360,11372,11589,11677,15360,12597,12934,13356,15360,13990,14364,14725,15360,14183,14444,14773,15360,14231,14444,14717,15360,14412,14532,14709,15360,14054,14199,14380,15360,12372,12500,12605,15360,12199,12565,13006,15360,12581,13175,13653,15360,10055,10380,10324,15360,8557,8573,6726,15360,8167,8196,6533,15360,7517,7485,6119,15360,7244,7172,5798,15360,7071,6959,5718,15360,7669,7581,6260,15360,8661,8605,7975,15360,10942,11079,11151,15360,12573,12741,13014,15360,11902,12030,12191,15360,10308,10332,10135,15360,11255,11300,11284,15360,11276,11348,11396,15360,10055,10215,10292,15360,12183,12332,12468,15360,9918,9966,9798,15360,8734,8742,8196,15360,8967,8950,8469,15360,10260,10276,10039,15360,9734,9758,9605,15360,9388,9404,9308,15360,7943,7878,7095,15360,7726,7637,6645,15360,8047,7983,7204,15360,9284,9236,8693,15360,9621,9565,9143,15360,11255,11268,11047,15360,13175,13332,13420,15360,13773,13934,14175,15360,13854,14022,14271,15360,13870,14038,14279,15360,13388,13516,13677,15360,12279,12629,12966,15360,13348,13452,13564,15360,13821,13918,14054,15360,13701,13846,14022,15360,13460,13605,13781,15360,13492,13637,13821,15360,13709,13821,13950,15360,14372,14428,14476,15360,14516,14572,14613,15360,14741,14789,14813,15360,14725,14749,14749,15360,13452,13484,13468,15360,13476,13500,13492,15360,14990,15022,15022,15360,14556,14572,14564,15360,15094,15111,15094,15360,13231,13287,13215,15360,11255,11380,11175,15360,10677,10886,10492,15360,11846,12006,11934,15360,14327,14340,14279,15360,10766,11039,10862,15360,12918,13255,13452,15360,14231,14548,14886,15360,13878,14380,14765,15360,13444,13862,14412,15360,12151,12404,12621,15360,12637,12902,13215,15360,11549,11749,11870,15360,12279,12653,13119,15360,13223,13404,13516,15360,9228,9260,8276,15360,8087,7991,6308,15360,7918,7814,6919,15360,7469,7364,6148,15360,7485,7380,6212,15360,8228,7991,7204,15360,9276,8967,8212,15360,9806,9573,8742,15360,10135,10087,9621,15360,11452,11452,11452,15360,10629,10637,10509,15360,10693,10733,10637,15360,11095,11111,10982,15360,11292,11348,11372,15360,10199,10244,10167,15360,10814,10926,10846,15360,8669,8774,7493,15360,7870,7910,6244,15360,8204,8183,6919,15360,9806,9758,9159,15360,9460,9436,8629,15360,9159,9087,8260,15360,7637,7509,6790,15360,7758,7629,6838,15360,7967,7918,6774,15360,10854,10749,10501,15360,11508,11412,11316,15360,12372,12300,12151,15360,12030,12119,12063,15360,12781,12910,12982,15360,13476,13581,13661,15360,13484,13589,13677,15360,12404,12428,12380,15360,11605,11765,11798,15360,11492,11533,11452,15360,11838,11886,11798,15360,12263,12372,12380,15360,12151,12231,12175,15360,11492,11508,11412,15360,11119,11111,10838,15360,12508,12581,12573,15360,12621,12693,12677,15360,12573,12629,12589,15360,12292,12324,12231,15360,12476,12565,12573,15360,11998,12159,12215,15360,12950,13071,13159,15360,12263,12372,12428,15360,12380,12428,12444,15360,11300,11308,11143,15360,10199,10244,9734,15360,9709,9701,9252,15360,10492,10581,10404,15360,11476,11516,11388,15360,9477,9517,8790,15360,11717,11854,11838,15360,14247,14420,14524,15360,14054,14311,14436,15360,13597,13805,13982,15360,11364,11533,11597,15360,12263,12428,12549,15360,11436,11605,11653,15360,13079,13324,13444,15360,12516,12613,12605,15360,10039,10015,9605,15360,8693,8621,7878,15360,7951,7862,6902,15360,8196,8204,7015,15360,8677,8589,7637,15360,9284,9031,8340,15360,9814,9605,8902,15360,10685,10428,9910,15360,10492,10260,9685,15360,9404,9252,7943,15360,8830,8766,7220,15360,9220,9047,7943,15360,9693,9669,9015,15360,11412,11468,11372,15360,11135,11159,11023,15360,10087,10055,9428,15360,9910,10007,9621,15360,9236,9300,8934,15360,9597,9557,8902,15360,10669,10549,9782,15360,9926,9870,9127,15360,9894,9918,9047,15360,8685,8742,7910,15360,9958,10167,10284,15360,10215,10332,10396,15360,11396,11428,11452,15360,11223,11255,11300,15360,11814,11862,11958,15360,10685,10846,10870,15360,10340,10380,10007,15360,11175,11207,10894,15360,12103,12207,12215,15360,11143,11103,10902,15360,9910,9966,9613,15360,10015,10079,9493,15360,10806,10846,10517,15360,10862,10934,10637,15360,10838,10942,10661,15360,10958,11087,10878,15360,10709,10838,10701,15360,10669,10741,10589,15360,10581,10669,10525,15360,10252,10348,9974,15360,11396,11500,11525,15360,11207,11255,11264,15360,10878,10910,10934,15360,11031,11063,11159,15360,11292,11324,11396,15360,11223,11255,11300,15360,10693,10685,10645,15360,10428,10420,10324,15360,10300,10252,9991,15360,10838,10846,10798,15360,10428,10428,10364,15360,9669,9605,9380,15360,10167,10244,10087,15360,11709,11854,11910,15360,11223,11284,11268,15360,10231,10244,9878,15360,10199,10244,9862,15360,10183,10260,9942,15360,10525,10653,10541,15360,12500,12597,12621,15360,11814,11741,11597,15360,11533,11460,11175,15360,11103,11006,10557,15360,10444,10396,9846,15360,10007,10023,9228,15360,9653,9790,8469,15360,9316,9372,8039,15360,9557,9830,8071,15360,9621,9918,8071,15360,9677,10015,8167,15360,9991,10284,8420,15360,10215,10436,8581,15360,10260,10484,8645,15360,10292,10476,8902,15360,10324,10468,9252,15360,9910,9894,8886,15360,10525,10573,9701,15360,9782,10039,8581,15360,9565,9814,8167,15360,9950,10039,8934,15360,10749,10758,10199,15360,10669,10685,10244,15360,10838,10838,10460,15360,11215,10910,10087,15360,11492,11364,10806,15360,11095,11159,11055,15360,11364,11388,11356,15360,11023,11039,10990,15360,11653,11653,11613,15360,11798,11725,11557,15360,11974,11862,11637,15360,12039,11942,11765,15360,12119,12047,11934,15360,12151,12071,11950,15360,12087,12006,11886,15360,12047,11966,11838,15360,11990,11926,11790,15360,11974,11910,11798,15360,11998,11934,11814,15360,12111,12039,11886,15360,12231,12143,11998,15360,12292,12199,12039,15360,12039,11974,11846,15360,11822,11782,11653,15360,11862,11838,11765,15360,11798,11765,11701,15360,11782,11733,11669,15360,11798,11749,11685,15360,11838,11790,11725,15360,11870,11822,11749,15360,11741,11701,11621,15360,11565,11541,11452,15360,11533,11500,11412,15360,11621,11581,11484,15360,11605,11557,11460,15360,11516,11468,11372,15360,11565,11533,11444,15360,11677,11637,11541,15360,11725,11661,11557,15360,11725,11661,11557,15360,11733,11669,11573,15360,11838,11773,11677,15360,11998,11926,11814,15360,12014,11926,11798,15360,11460,11404,11332,15360,11637,11557,11428,15360,12014,11894,11693,15360,12167,12022,11765,15360,12119,11982,11709,15360,11926,11806,11516,15360,11685,11589,11300,15360,11476,11404,10886,15360,11239,11151,10468,15360,10766,10733,9894,15360,10565,10565,9589,15360,10436,10444,9332,15360,10308,10308,9031,15360,10308,10316,8999,15360,10199,10244,8774,15360,9725,9645,8549,15360,10244,10276,8967,15360,10878,10838,10183,15360,11055,10966,10348,15360,11119,11006,10404,15360,11264,11135,10565,15360,11404,11316,10822,15360,11492,11388,10982,15360,11798,11613,11223,15360,12047,11830,11412,15360,12039,11894,11597,15360,12127,11990,11693,15360,12127,11990,11725,15360,12191,12055,11806,15360,12191,12055,11830,15360,11870,11773,11613,15360,11573,11516,11428,15360,11533,11484,11412,15360,11541,11492,11420,15360,11565,11516,11452,15360,11589,11541,11476,15360,11605,11557,11500,15360,11637,11589,11533,15360,11669,11621,11557,15360,11701,11645,11573,15360,11733,11669,11589,15360,11798,11717,11605,15360,11838,11749,11621,15360,11878,11782,11661,15360,11894,11798,11661,15360,11926,11806,11653,15360,11958,11822,11661,15360,11982,11846,11677,15360,12006,11870,11685,15360,12095,11950,11765,15360,12047,11910,11741,15360,11886,11765,11605,15360,11838,11733,11589,15360,11814,11717,11589,15360,11814,11709,11573,15360,11790,11693,11565,15360,11741,11677,11589,15360,11733,11677,11613,15360,11733,11685,11629,15360,11717,11669,11621,15360,11685,11645,11589,15360,11629,11589,11533,15360,11573,11525,11468,15360,11492,11444,11380,15360,11316,11255,11111,15360,11348,11292,11143,15360,11516,11436,11316,15360,11854,11749,11589,15360,12127,11990,11765,15360,12199,12055,11782,15360,12340,12231,11910,15360,12372,12292,11958,15360,12380,12300,11974,15360,12348,12247,11910,15360,12324,12215,11878,15360,12247,12103,11773,15360,12095,11958,11637,15360,12055,11926,11613,15360,11974,11854,11541,15360,11870,11765,11468,15360,11966,11854,11541,15360,12300,12151,11846,15360,12396,12316,12006,15360,12388,12308,11990,15360,12388,12308,12006,15360,12396,12316,12022,15360,12396,12308,12022,15360,12396,12308,12022,15360,12364,12279,11974,15360,12340,12247,11942,15360,12340,12231,11926,15360,12215,12071,11806,15360,12095,11966,11749,15360,11741,11645,11500,15360,11420,11356,11255,15360,11364,11308,11207,15360,11356,11300,11175,15360,11348,11292,11191,15360,11372,11324,11255,15360,11412,11364,11308,15360,11420,11372,11316,15360,11428,11380,11324,15360,11444,11388,11332,15360,11484,11428,11364,15360,11508,11460,11396,15360,11557,11500,11436,15360,11589,11533,11460,15360,11613,11557,11484,15360,11621,11557,11492,15360,11613,11557,11500,15360,11621,11557,11500,15360,11629,11573,11508,15360,11629,11573,11508,15360,11605,11557,11484,15360,11589,11533,11468,15360,11557,11508,11436,15360,11549,11500,11428,15360,11557,11500,11436,15360,11549,11492,11436,15360,11533,11484,11428,15360,11525,11476,11428,15360,11516,11476,11428,15360,11525,11484,11444,15360,11516,11476,11428,15360,11468,11428,11380,15360,11428,11388,11332,15360,11356,11308,11239,15360,11308,11255,11127,15360,11167,11071,10926,15360,11223,11119,10966,15360,11276,11175,10998,15360,11404,11332,11191,15360,11773,11693,11557,15360,11926,11798,11613,15360,12207,12039,11773,15360,12348,12231,11894,15360,12308,12151,11846,15360,12332,12215,11894,15360,12364,12279,11958,15360,12380,12292,11974,15360,12396,12316,12022,15360,12404,12316,12039,15360,12412,12332,12087,15360,12412,12332,12103,15360,12436,12356,12135,15360,12372,12292,12039,15360,12420,12332,12087,15360,12396,12316,12055,15360,12356,12263,11990,15360,12340,12231,11942,15360,12271,12127,11854,15360,12215,12071,11814,15360,12292,12135,11878,15360,12288,12135,11870,15360,12111,11982,11765,15360,11990,11886,11717,15360,11637,11557,11428,15360,11364,11300,11143,15360,11316,11239,11079,15360,11300,11207,11047,15360,11268,11159,11015,15360,11268,11159,11015,15360,11268,11159,11031,15360,11300,11223,11095,15360,11340,11292,11191,15360,11348,11300,11223,15360,11372,11324,11255,15360,11380,11332,11255,15360,11372,11316,11239,15360,11396,11340,11268,15360,11468,11404,11300,15360,11460,11404,11324,15360,11484,11428,11356,15360,11492,11436,11372,15360,11500,11444,11388,15360,11508,11460,11404,15360,11500,11452,11396,15360,11492,11436,11380,15360,11468,11412,11356,15360,11444,11388,11324,15360,11444,11388,11324,15360,11428,11380,11316,15360,11412,11356,11300,15360,11404,11348,11300,15360,11404,11356,11308,15360,11396,11356,11308,15360,11388,11348,11308,15360,11372,11340,11292,15360,11348,11308,11255,15360,11284,11223,11111,15360,11231,11143,11023,15360,11199,11111,10974,15360,11047,10958,10814,15360,11127,11023,10870,15360,11119,11006,10846,15360,11175,11055,10886,15360,11292,11191,10998,15360,11525,11404,11284,15360,11822,11637,11476,15360,11878,11733,11549,15360,11918,11790,11573,15360,12063,11918,11653,15360,12223,12063,11765,15360,12300,12151,11846,15360,12255,12103,11814,15360,12271,12127,11846,15360,12271,12127,11862,15360,12271,12127,11886,15360,12308,12183,11942,15360,12175,12039,11814,15360,12063,11934,11709,15360,12159,12014,11765,15360,12215,12063,11798,15360,12143,11998,11757,15360,12071,11934,11693,15360,11998,11870,11661,15360,11974,11870,11685,15360,11998,11910,11757,15360,11846,11765,11629,15360,11468,11396,11284,15360,11308,11223,11031,15360,11215,11103,10934,15360,11207,11095,10942,15360,11215,11103,10950,15360,11191,11087,10942,15360,11175,11079,10942,15360,11167,11063,10934,15360,11143,11031,10902,15360,11247,11143,11015,15360,11284,11191,11079,15360,11300,11223,11095,15360,11316,11268,11127,15360,11340,11284,11143,15360,11340,11284,11159,15360,11356,11300,11191,15360,11372,11316,11239,15360,11380,11324,11255,15360,11372,11316,11255,15360,11380,11324,11276,15360,11380,11324,11268,15360,11372,11316,11255,15360,11364,11316,11255,15360,11364,11308,11239,15360,11348,11292,11207,15360,11340,11284,11191,15360,11348,11292,11191,15360,11348,11292,11207,15360,11340,11292,11207,15360,11340,11292,11207,15360,11324,11276,11207,15360,11308,11255,11175,15360,11264,11175,11079,15360,11119,11039,10934,15360,11103,11015,10902,15360,11095,11006,10878,15360,11031,10942,10806,15360,10990,10902,10766,15360,11047,10942,10814,15360,11031,10926,10790,15360,11055,10942,10806,15360,11119,10998,10846,15360,11151,11015,10830,15360,11268,11095,10886,15360,11484,11396,11268,15360,11790,11701,11549,15360,11886,11790,11637,15360,11838,11741,11581,15360,11838,11725,11541,15360,11902,11782,11581,15360,11966,11838,11629,15360,11974,11846,11629,15360,11958,11838,11629,15360,11950,11838,11637,15360,11814,11701,11525,15360,11581,11492,11332,15360,11645,11541,11380,15360,11806,11701,11533,15360,11902,11806,11637,15360,11950,11862,11717,15360,12014,11934,11790,15360,11942,11862,11725,15360,11565,11492,11388,15360,11292,11191,11015,15360,11231,11111,10950,15360,11159,11047,10894,15360,11119,11006,10854,15360,11127,11023,10878,15360,11159,11055,10902,15360,11135,11031,10894,15360,11111,11006,10878,15360,11095,10990,10870,15360,11095,10998,10886,15360,11071,10966,10846,15360,11111,11006,10902,15360,11191,11095,10974,15360,11268,11159,11031,15360,11284,11191,11063,15360,11292,11207,11063,15360,11300,11223,11079,15360,11332,11268,11143,15360,11316,11255,11127,15360,11316,11255,11143,15360,11308,11239,11127,15360,11316,11255,11159,15360,11300,11223,11127,15360,11292,11207,11095,15360,11300,11223,11111,15360,11300,11223,11095,15360,11300,11223,11095,15360,11308,11239,11111,15360,11300,11223,11111,15360,11292,11207,11111,15360,11264,11167,11071,15360,11215,11127,11047,15360,11135,11055,10966,15360,11015,10934,10846,15360,10918,10838,10733,15360,10982,10894,10782,15360,10974,10886,10766,15360,10982,10894,10766,15360,10958,10862,10749,15360,10982,10886,10774,15360,10958,10862,10758,15360,10958,10862,10749,15360,11015,10910,10790,15360,11023,10910,10774,15360,11079,10958,10806,15360,11103,10974,10798,15360,11191,11047,10846,15360,11468,11388,11276,15360,11846,11765,11637,15360,12006,11918,11782,15360,11998,11910,11782,15360,11902,11822,11693,15360,11838,11749,11637,15360,11782,11709,11605,15360,11806,11741,11645,15360,11782,11717,11629,15360,11773,11717,11621,15360,11870,11806,11701,15360,11942,11862,11757,15360,12183,12103,11974,15360,11974,11894,11765,15360,11476,11404,11308,15360,11268,11143,10966,15360,11183,11063,10902,15360,11111,10998,10854,15360,11055,10942,10806,15360,11023,10910,10766,15360,11047,10934,10782,15360,11039,10926,10782,15360,11079,10966,10830,15360,11031,10918,10782,15360,11031,10926,10806,15360,10990,10894,10782,15360,10974,10886,10790,15360,10966,10870,10774,15360,11006,10902,10806,15360,11039,10942,10838,15360,11127,11023,10910,15360,11175,11079,10958,15360,11191,11087,10958,15360,11207,11095,10958,15360,11268,11143,11015,15360,11276,11175,11047,15360,11284,11191,11079,15360,11292,11191,11079,15360,11276,11175,11079,15360,11239,11135,11031,15360,11268,11159,11047,15360,11215,11111,11006,15360,11239,11127,11015,15360,11255,11143,11031,15360,11223,11119,11015,15360,11199,11103,10998,15360,11175,11087,10982,15360,11143,11047,10958,15360,11031,10942,10854,15360,10958,10878,10790,15360,10910,10830,10741,15360,10942,10862,10758,15360,10926,10838,10733,15360,10854,10758,10637,15360,10918,10830,10709,15360,10910,10822,10717,15360,10942,10846,10749,15360,10942,10854,10741,15360,10942,10854,10749,15360,10966,10870,10758,15360,10966,10870,10758,15360,10958,10854,10733,15360,10998,10886,10741,15360,10942,10830,10677,15360,11039,10918,10749,15360,11095,10974,10806,15360,11308,11223,11031,15360,11468,11396,11292,15360,11605,11533,11428,15360,11701,11621,11525,15360,11693,11629,11541,15360,11685,11621,11549,15360,11685,11629,11549,15360,11629,11565,11484,15360,11589,11533,11444,15360,11364,11308,11191,15360,11191,11087,10958,15360,11135,11031,10902,15360,11135,11031,10894,15360,11055,10950,10830,15360,11015,10910,10782,15360,10958,10854,10733,15360,10942,10838,10717,15360,10974,10870,10733,15360,10982,10878,10749,15360,10990,10886,10758,15360,11015,10910,10798,15360,10966,10862,10758,15360,10950,10854,10758,15360,10910,10822,10733,15360,10894,10798,10709,15360,10902,10814,10725,15360,10934,10846,10758,15360,10910,10822,10733,15360,10950,10854,10749,15360,10974,10878,10766,15360,11047,10942,10830,15360,11095,10990,10878,15360,11167,11055,10942,15360,11199,11103,10990,15360,11191,11087,10982,15360,11151,11047,10950,15360,11135,11031,10934,15360,11095,10998,10902,15360,11143,11047,10950,15360,11079,10990,10894,15360,11079,10990,10902,15360,11103,11006,10910,15360,11079,10982,10886,15360,11023,10926,10822,15360,10982,10894,10798,15360,10958,10870,10782,15360,10910,10814,10725,15360,10926,10838,10741,15360,10934,10838,10733,15360,10950,10854,10749,15360,10886,10798,10709,15360,10910,10814,10709,15360,10926,10830,10725,15360,10910,10814,10701,15360,10862,10774,10677,15360,10950,10854,10733,15360,10926,10830,10717,15360,10926,10838,10725,15360,10926,10830,10725,15360,10894,10798,10685,15360,10926,10830,10701,15360,10958,10854,10717,15360,10934,10830,10685,15360,10950,10846,10709,15360,10974,10862,10717,15360,10942,10830,10685,15360,10958,10846,10701,15360,11006,10894,10749,15360,10950,10846,10725,15360,10958,10862,10741,15360,10894,10806,10701,15360,10854,10774,10669,15360,10886,10806,10701,15360,10862,10790,10693,15360,10878,10806,10717,15360,10982,10902,10798,15360,10990,10902,10798,15360,10950,10862,10758,15360,10942,10846,10733,15360,10870,10774,10669,15360,10894,10798,10693,15360,10918,10830,10725,15360,10894,10806,10701,15360,10926,10830,10733,15360,10902,10830,10725,15360,10870,10790,10693,15360,10886,10814,10725,15360,10814,10741,10661,15360,10838,10766,10677,15360,10822,10741,10661,15360,10822,10741,10669,15360,10862,10790,10709,15360,10846,10758,10669,15360,10894,10798,10693,15360,10974,10878,10766,15360,10966,10870,10766,15360,11023,10926,10814,15360,11079,10974,10862,15360,11006,10910,10814,15360,10950,10862,10766,15360,10982,10894,10798,15360,10958,10862,10774,15360,10958,10870,10782,15360,10910,10830,10741,15360,10950,10862,10766,15360,10982,10886,10790,15360,10918,10822,10725,15360,10886,10798,10701,15360,10854,10766,10669,15360,10894,10806,10709,15360,10926,10830,10725,15360,10926,10830,10725,15360,10958,10862,10749,15360,10958,10862,10749,15360,10894,10806,10717,15360,10902,10814,10717,15360,10878,10790,10677,15360,10942,10838,10717,15360,10918,10814,10701,15360,10886,10790,10661,15360,10942,10838,10717,15360,10950,10854,10725,15360,10950,10854,10725,15360,10910,10814,10693,15360,10910,10814,10685,15360,10942,10838,10709,15360,10894,10790,10661,15360,10910,10806,10669,15360,10822,10725,10597,15360,10749,10661,10541,15360,10830,10733,10613,15360,10838,10741,10629,15360,10806,10709,10597,15360,10854,10766,10653,15360,10862,10774,10669,15360,10798,10725,10629,15360,10822,10749,10653,15360,10854,10782,10693,15360,10806,10741,10661,15360,10862,10790,10701,15360,10870,10790,10685,15360,10870,10790,10693,15360,10878,10790,10677,15360,10862,10782,10677,15360,10870,10790,10693,15360,10870,10782,10685,15360,10894,10814,10709,15360,10886,10814,10709,15360,10846,10782,10685,15360,10741,10669,10573,15360,10766,10693,10589,15360,10709,10637,10541,15360,10741,10669,10589,15360,10741,10677,10589,15360,10709,10637,10557,15360,10774,10701,10613,15360,10862,10774,10677,15360,11006,10918,10806,15360,11006,10902,10782,15360,10974,10870,10749,15360,10958,10854,10733,15360,10934,10838,10725,15360,10934,10838,10733,15360,10934,10838,10725,15360,10886,10790,10685,15360,10854,10766,10661,15360,10886,10798,10701,15360,10838,10749,10645,15360,10878,10782,10661,15360,10822,10725,10613,15360,10822,10717,10605,15360,10846,10749,10629,15360,10854,10749,10637,15360,10950,10854,10733,15360,10958,10854,10741,15360,10910,10806,10693,15360,10926,10822,10693,15360,10934,10838,10725,15360,10910,10822,10709,15360,10910,10822,10709,15360,10886,10782,10661,15360,10910,10814,10677,15360,10910,10806,10677,15360,10926,10822,10685,15360,10958,10854,10717,15360,10974,10870,10725,15360,10926,10830,10693,15360,10926,10830,10693,15360,10918,10822,10693,15360,10934,10838,10701,15360,10918,10814,10685,15360,10878,10782,10653,15360,10870,10774,10645,15360,10838,10749,10629,15360,10806,10717,10605,15360,10822,10733,10621,15360,10822,10733,10621,15360,10846,10758,10653,15360,10846,10766,10653,15360,10822,10741,10629,15360,10806,10733,10629,15360,10806,10725,10621,15360,10790,10709,10605,15360,10766,10693,10589,15360,10814,10741,10629,15360,10846,10766,10653,15360,10838,10758,10653,15360,10878,10790,10677,15360,10894,10798,10685,15360,10830,10741,10629,15360,10830,10758,10653,15360,10798,10725,10629,15360,10806,10733,10629,15360,10717,10637,10525,15360,10661,10581,10476,15360,10701,10621,10517,15360,10733,10661,10565,15360,10782,10685,10557,15360,10862,10758,10613,15360,10974,10862,10725,15360,10958,10846,10709,15360,11006,10902,10766,15360,11006,10902,10774,15360,11039,10934,10814,15360,11006,10902,10790,15360,11006,10910,10790,15360,10950,10854,10741,15360,10934,10830,10709,15360,10918,10814,10701,15360,10854,10758,10653,15360,10918,10814,10701,15360,10870,10766,10645,15360,10830,10733,10621,15360,10934,10830,10709,15360,10990,10886,10758,15360,10950,10838,10717,15360,10910,10814,10701,15360,10926,10822,10693,15360,10934,10830,10709,15360,10878,10774,10653,15360,10934,10830,10701,15360,10926,10822,10693,15360,10878,10782,10661,15360,10878,10782,10661,15360,10862,10766,10621,15360,10886,10782,10645,15360,10886,10782,10653,15360,10926,10822,10701,15360,10902,10806,10685,15360,10926,10822,10701,15360,10918,10814,10685,15360,10878,10782,10645,15360,10910,10806,10669,15360,10854,10758,10621,15360,10886,10790,10645,15360,10854,10758,10629,15360,10830,10741,10613,15360,10918,10814,10685,15360,10862,10766,10645,15360,10830,10741,10613,15360,10806,10717,10597,15360,10741,10661,10557,15360,10774,10693,10581,15360,10749,10669,10557,15360,10774,10693,10581,15360,10766,10685,10573,15360,10790,10709,10597,15360,10782,10701,10589,15360,10790,10709,10597,15360,10838,10749,10621,15360,10870,10774,10645,15360,10894,10790,10661,15360,10878,10782,10653,15360,10846,10741,10613,15360,10790,10693,10557,15360,10814,10717,10597,15360,10790,10701,10581,15360,10741,10645,10525,15360,10717,10629,10509,15360,10774,10685,10573,15360,10725,10637,10525,15360,10854,10749,10621,15360,10950,10846,10701,15360,10966,10854,10709,15360,10934,10814,10677,15360,10926,10822,10701,15360,10982,10878,10766,15360,10998,10894,10782,15360,10990,10878,10766,15360,10998,10894,10782,15360,10998,10886,10774,15360,10998,10886,10758,15360,11006,10894,10774,15360,10942,10838,10733,15360,10958,10854,10741,15360,10958,10854,10749,15360,11006,10902,10790,15360,11015,10902,10798,15360,10982,10870,10758,15360,10998,10894,10782,15360,10974,10870,10758,15360,11006,10902,10790,15360,10998,10894,10774,15360,10974,10870,10758,15360,10950,10854,10741,15360,10878,10790,10693,15360,10902,10814,10701,15360,10918,10822,10709,15360,10838,10733,10613,15360,10878,10782,10661,15360,10934,10838,10717,15360,10902,10806,10693,15360,10918,10822,10709,15360,10926,10830,10709,15360,10838,10733,10605,15360,10910,10806,10661,15360,10942,10838,10693,15360,10886,10782,10645,15360,10886,10782,10637,15360,10854,10749,10621,15360,10926,10830,10709,15360,10966,10862,10741,15360,10846,10749,10629,15360,10830,10733,10605,15360,10854,10758,10637,15360,10822,10725,10605,15360,10886,10790,10661,15360,10902,10806,10669,15360,10918,10814,10677,15360,10830,10733,10605,15360,10806,10717,10589,15360,10870,10774,10645,15360,10934,10838,10709,15360,10958,10862,10733,15360,10886,10790,10661,15360,10894,10798,10661,15360,10958,10854,10709,15360,10934,10830,10709,15360,10814,10717,10581,15360,10862,10758,10613,15360,10854,10741,10589,15360,10814,10717,10573,15360,10886,10782,10645,15360,10814,10725,10597,15360,10862,10766,10637,15360,10910,10806,10669,15360,10942,10838,10709,15360,10966,10862,10733,15360,10974,10870,10741,15360,10974,10870,10749,15360,10958,10862,10749,15360,11031,10934,10822,15360,10998,10894,10782,15360,10974,10870,10766,15360,11023,10918,10814,15360,11039,10926,10822,15360,10958,10846,10741,15360,10918,10814,10693,15360,10966,10870,10741,15360,10982,10886,10766,15360,10982,10878,10766,15360,10942,10846,10733,15360,10958,10862,10758,15360,10950,10854,10758,15360,10934,10830,10717,15360,10966,10862,10733,15360,10942,10846,10725,15360,10934,10846,10733,15360,10934,10846,10733,15360,10878,10798,10693,15360,10886,10798,10693,15360,10910,10814,10709,15360,10942,10846,10733,15360,10838,10733,10597,15360,10878,10774,10645,15360,10918,10822,10701,15360,10878,10782,10653,15360,10894,10790,10661,15360,10934,10838,10725,15360,10958,10854,10725,15360,10966,10862,10733,15360,10910,10806,10685,15360,10982,10878,10758,15360,10942,10854,10749,15360,10934,10838,10733,15360,10918,10814,10701,15360,10894,10798,10669,15360,10894,10798,10669,15360,10814,10725,10605,15360,10902,10798,10669,15360,10814,10725,10605,15360,10894,10798,10685,15360,10958,10862,10749,15360,10910,10814,10701,15360,10910,10806,10685,15360,10918,10814,10693,15360,10926,10822,10709,15360,10894,10790,10661,15360,10902,10806,10677,15360,10902,10806,10685,15360,10934,10838,10717,15360,10934,10838,10701,15360,10934,10838,10717,15360,10950,10854,10725,15360,10894,10798,10661,15360,10862,10749,10597,15360,10894,10798,10677,15360,10878,10782,10661,15360,10926,10838,10717,15360,10926,10838,10717,15360,10918,10822,10709,15360,10934,10838,10733,15360,10926,10838,10733,15360,10958,10870,10766,15360,10942,10854,10749,15360,10958,10870,10774,15360,10974,10878,10774,15360,10958,10854,10741,15360,10950,10846,10741,15360,10950,10854,10758,15360,10934,10838,10733,15360,10942,10846,10725,15360,10966,10862,10741,15360,10926,10838,10733,15360,10958,10862,10749,15360,10910,10822,10709,15360,10942,10854,10758,15360,10926,10838,10733,15360,10910,10822,10717,15360,10934,10838,10733,15360,10934,10846,10733,15360,10902,10814,10709,15360,10926,10830,10717,15360,10918,10822,10709,15360,10838,10749,10637,15360,10878,10790,10677,15360,10942,10846,10733,15360,10926,10822,10701,15360,10958,10862,10749,15360,10886,10790,10685,15360,10918,10814,10693,15360,10910,10814,10693,15360,10902,10806,10701,15360,10878,10774,10637,15360,10798,10693,10565,15360,10822,10725,10597,15360,10934,10838,10709,15360,10958,10854,10725,15360,10886,10790,10669,15360,10910,10806,10677,15360,10886,10782,10645,15360,10830,10725,10597,15360,10822,10717,10581,15360,10862,10758,10637,15360,10878,10782,10669,15360,10926,10822,10709,15360,10974,10878,10774,15360,10966,10870,10758,15360,10918,10822,10709,15360,10846,10749,10645,15360,10894,10798,10693,15360,10918,10822,10709,15360,10974,10878,10774,15360,10918,10822,10717,15360,10982,10886,10774,15360,10974,10878,10758,15360,10950,10854,10741,15360,10958,10854,10725,15360,10982,10886,10766,15360,10918,10822,10701,15360,10878,10782,10669,15360,10886,10790,10669,15360,10934,10838,10717,15360,10950,10854,10741,15360,10934,10838,10733,15360,10982,10886,10782,15360,10886,10798,10701,15360,10870,10782,10685,15360,10894,10814,10717,15360,10910,10822,10725,15360,10934,10838,10733,15360,10950,10846,10741,15360,10934,10838,10725,15360,10934,10846,10749,15360,10902,10814,10717,15360,10878,10790,10677,15360,10878,10782,10669,15360,10854,10766,10645,15360,10838,10749,10629,15360,10902,10814,10701,15360,10910,10814,10693,15360,10902,10798,10669,15360,10910,10806,10677,15360,10886,10782,10653,15360,10854,10749,10629,15360,10870,10774,10653,15360,10974,10870,10758,15360,10990,10878,10758,15360,10918,10822,10709,15360,10926,10838,10725,15360,10958,10854,10733,15360,10894,10790,10653,15360,10822,10725,10605,15360,10878,10782,10661,15360,10974,10870,10749,15360,10902,10806,10677,15360,10934,10838,10725,15360,10870,10774,10653,15360,10798,10701,10581,15360,10854,10749,10621,15360,10894,10798,10669,15360,10934,10822,10685,15360,10942,10830,10701,15360,10910,10806,10669,15360,10870,10758,10629,15360,10886,10774,10645,15360,10950,10838,10701,15360,10966,10870,10749,15360,10886,10790,10685,15360,10870,10782,10677,15360,10934,10838,10733,15360,10934,10838,10725,15360,10822,10725,10621,15360,10878,10790,10677,15360,10894,10798,10693,15360,10822,10733,10629,15360,10894,10798,10685,15360,10998,10902,10790,15360,11015,10918,10806,15360,10950,10854,10741,15360,10950,10846,10741,15360,10934,10838,10733,15360,10942,10846,10749,15360,10910,10822,10725,15360,10846,10758,10653,15360,10878,10790,10685,15360,10894,10798,10701,15360,10862,10774,10669,15360,10814,10725,10621,15360,10846,10758,10645,15360,10870,10774,10661,15360,10870,10774,10677,15360,10878,10790,10693,15360,10878,10782,10677,15360,10830,10741,10637,15360,10870,10782,10677,15360,10966,10870,10766,15360,11015,10918,10814,15360,10910,10814,10701,15360,10942,10846,10725,15360,10950,10846,10725,15360,10942,10838,10725,15360,10934,10830,10701,15360,10910,10798,10677,15360,10886,10782,10653,15360,10838,10733,10597,15360,10902,10806,10669,15360,10830,10733,10613,15360,10838,10741,10621,15360,10838,10741,10621,15360,10894,10798,10669,15360,10934,10830,10685,15360,10886,10790,10669,15360,10902,10806,10685,15360,10854,10749,10637,15360]));function td(){if(Be.isBrowser){const c=document.createElement("div");return c.setAttribute("style","height: 1in; visibility: hidden; position: absolute; margin: 0; padding: 0;"),document.body.appendChild(c),.0254/c.clientHeight}else return .0254/96}const br={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:td()},Ao={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},Io=c=>c===2?"²":c===3?"³":"",wr=(c,t=1)=>Ao[c]+Io(t),id=(c,t,e,i=1)=>(e==null&&(e=t),e===t?{value:c,unit:wr(e)}:{value:c*Math.pow(br[t]/br[e],i),unit:wr(e)+Io(i)});var Bo=(c=>(c.Top="Top",c.Bottom="Bottom",c.Front="Front",c.Back="Back",c.Left="Left",c.Right="Right",c))(Bo||{});class sd{static getCameraDirectionByView(t){const e=new p.Vector3(1,0,0);return t==="Top"?e.set(0,-1,0):t==="Bottom"?e.set(0,1,0):t==="Front"?e.set(0,0,-1):t==="Back"?e.set(0,0,1):t==="Left"?e.set(1,0,0):t==="Right"&&e.set(-1,0,0),e}}var le=(c=>(c.MouseClick="mouseclick",c.LayoutChange="layoutchange",c.ModelLoad="modelload",c.BeforeRender="beforerender",c.AfterRender="afterrender",c.OnAnimate="onanimate",c.CameraChange="camerachange",c.ControlChange="controlchange",c.BoxSelectActivate="boxselectactivate",c.BoxSelectDeactivate="boxselectdeactivate",c.PickMarkupActivate="pickmarkupactivate",c.PickMarkupDeactivate="pickmarkupdeactivate",c.MarkupActivate="markupactivate",c.MarkupDeactivate="markupdeactivate",c.MarkupAdd="markupadd",c.MarkupUpdate="markupupdate",c.MarkupRemove="markupremove",c.BeforeRemoveMarkup="beforeremovemarkup",c.MeasurementActivate="measurementactivate",c.MeasurementDeactivate="measurementdeactivate",c.MeasurementAdd="measurementadd",c.MeasurementRemove="measurementremove",c.HotpointClick="hotpointclick",c))(le||{});const va={};class bs extends Nt{constructor(e){super();g(this,"viewer");g(this,"drawableLists");g(this,"canvas");g(this,"context");g(this,"frustum");g(this,"projScreenMatrix");this.drawableLists=[],this.frustum=new p.Frustum,this.projScreenMatrix=new p.Matrix4,this.viewer=e,this.init()}static _registerDrawableClass(e){const i=e;va[i.prototype.getClassType()]=e}static createDrawable(e){const i=va[e.type];if(!i)throw new Error("Invalid drawable type: "+i);const s=e.points.map(r=>new p.Vector3(r[0],r[1],r[2]||0)),n=new i(e.id,s);return n.setData(e),n}get is3d(){return this.viewer.is3d()}get container(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}init(){this.initCanvas(),this.viewer.addEventListener(le.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(Be.isBrowser&&!e.context2d){const i=this.canvas=document.createElement("canvas"),s=this.viewer.viewerContainer;s.appendChild(i),i.classList.add("overlay-renderer"),i.style.pointerEvents="none",i.style.position="absolute",i.style.left="0px",i.style.top="0px",i.style.userSelect="none",this.context=i.getContext("2d",{willReadFrequently:!0});const{clientWidth:n,clientHeight:r}=s;this.setSize(n,r)}else e.context2d&&(this.context=e.context2d,this.canvas=Be.creatReactNativeCanvas(this.context),this.context.canvas||(this.context.canvas=this.canvas))}toHighDpr(e,i,s){const n=Math.max(window.devicePixelRatio||1,1),r=this.canvas;return r.width=i*n,r.height=s*n,e.scale(n,n),r.style.width=i+"px",r.style.height=s+"px",e}clearCanvas(){this.context?.clearRect(0,0,this.canvas?.width??0,this.canvas?.height??0)}addDrawableList(e){this.drawableLists.push(e)}render(){if(!this.canvas||!this.context||this.drawableLists.length<1)return;this.clearCanvas();const e=this.getSortedDrawables(!1);if(e.length===0)return;const i=new p.Sphere,s=this.viewer.getPixelSizeInWorldCoord();for(let n=0;n<e.length;n++){const r=e[n];r.setTolerance(s),!(!r.visible||(r.getBounds().getBoundingSphere(i),r.needsFrustumCulled&&!this.frustum.intersectsSphere(i)))&&r.render(this.context,this.camera)}}setSize(e,i){const s=this.canvas;s.width=e,s.height=i,s.style.width=e+"px",s.style.height=i+"px",this.toHighDpr(this.context,e,i)}getSortedDrawables(e=!1){const i=[];return this.drawableLists.forEach(s=>{let n=Array.from(s.getDrawables().values());e&&(n=n.filter(r=>r.visible)),n.length>0&&i.push(...n)}),i.sort((s,n)=>s.renderOrder===n.renderOrder?n.getCenter().distanceTo(this.camera.position)-s.getCenter().distanceTo(this.camera.position):s.renderOrder-n.renderOrder),i}getDrawablesByDrawableListAndPosition(e,i){return this.is3d||(i.z=0),e.getDrawableByPosition(i,this.raycaster)}getDrawablesByPosition(e){this.is3d||(e.z=0);const i=this.getSortedDrawables(),s=[];for(let n=0;n<i.length;n++){const r=i[n];r.isPointInPath(e,this.raycaster)&&s.push(r)}return s}getDrawableById(e){return this.getSortedDrawables().find(s=>s.id===e)}measureTextLength(e,i){const s=this.context,n=e.split(`
535
- `);let r=0;for(let a=0;a<n.length;a++){const o=n[a];s.save(),s.font=i;const l=s.measureText(o).width;s.restore(),r=Math.max(r,l)}return r}getImage(e){this.clearCanvas();const i=this.getSortedDrawables();for(let s=0;s<i.length;s++){const n=i[s];e(n)&&n.render(this.context,this.camera)}return j.canvasToImage(this.canvas)}getCanvas(){return this.canvas}destroy(){this.drawableLists.forEach(e=>e.clear()),this.drawableLists=[],this.canvas&&(this.viewer.viewerContainer?.removeChild(this.canvas),this.canvas=void 0)}}class ws extends Nt{constructor(e){super();g(this,"category");g(this,"drawableMap");this.drawableMap=new Map,this.category=e}addDrawable(e){this.drawableMap.set(e.id,e),this.dispatchEvent("add",e.getData())}updateDrawable(e,i){e.setData(i),this.dispatchEvent("update",e.getData())}removeDrawable(e){this.drawableMap.delete(e.id),this.dispatchEvent("remove",e.getData())}getDrawableById(e){return this.drawableMap.get(e)}clear(){this.drawableMap.forEach(e=>this.removeDrawable(e))}getDrawables(){return this.drawableMap}getDrawableDatas(){return Array.from(this.drawableMap).map(([,e])=>e.getData())}setDrawableDatas(e){for(let i=0;i<e.length;i++){const s=e[i],n=bs.createDrawable(s);this.addDrawable(n)}}getDrawableByPosition(e,i){let s;for(const[,n]of this.drawableMap)if(n.visible&&n.isPointInPath(e,i)){s=n;break}return s}}class Ht extends Nt{constructor(e){super();g(this,"DEFAULT_LINE_WIDTH",1);g(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);g(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);g(this,"id");g(this,"lineWidth");g(this,"lineColor");g(this,"fillColor");g(this,"x");g(this,"y");g(this,"width");g(this,"height");g(this,"points");g(this,"userData");g(this,"tolerance");g(this,"visible");g(this,"selected");g(this,"renderOrder");g(this,"needsFrustumCulled");g(this,"editPointSize");g(this,"editPointFillColor");g(this,"editPointStrokeColor");g(this,"matrix");g(this,"ctx");this.lineWidth=this.DEFAULT_LINE_WIDTH,this.lineColor=this.DEFAULT_STROKE_STYLE,this.fillColor=this.DEFAULT_FILL_STYLE,this.x=0,this.y=0,this.width=0,this.height=0,this.points=[],this.userData={},this.tolerance=1,this.visible=!0,this.selected=!1,this.renderOrder=1,this.needsFrustumCulled=!0,this.editPointSize=3,this.editPointFillColor="#ffffff",this.editPointStrokeColor="#939ea4",this.matrix=new p.Matrix4,this.id=e||j.guid()}setTolerance(e){this.tolerance=e}render(e,i){this.ctx=e,this.draw(e,i),this.selected&&this.drawSelect(e,i)}getData(){return{id:this.id,points:this.points.map(e=>[e.x,e.y]),lineWidth:this.lineWidth,lineColor:this.lineColor,fillColor:this.fillColor,type:this.getClassType()}}setData(e){this.id=e.id,this.setLineWidth(e.lineWidth),this.setLineColor(e.lineColor),this.setFillColor(e.fillColor)}getVertexes(){const e=new p.Vector3(this.x,this.y,0),i=new p.Vector3(this.x+this.width,this.y,0),s=new p.Vector3(this.x+this.width,this.y-this.height,0),n=new p.Vector3(this.x,this.y-this.height,0);return[e,i,s,n]}setLineWidth(e){this.lineWidth=e||this.DEFAULT_LINE_WIDTH}setLineColor(e){this.lineColor=e||this.DEFAULT_STROKE_STYLE}setFillColor(e){this.fillColor=e||this.DEFAULT_FILL_STYLE}isSelected(){return this.selected}getCenter(){return this.getBounds().getCenter(new p.Vector3)}transToScreenCoord(e,i){return this.ctx?Ee.world2Screen(e,i,this.ctx.canvas):new p.Vector2}drawBounds(e,i){const{min:s,max:n}=this.getBounds(),r=[],a=(o,l,h)=>r.push(new p.Vector3(o,l,h));a(n.x,n.y,n.z),a(s.x,n.y,n.z),a(s.x,s.y,n.z),a(n.x,s.y,n.z),a(n.x,n.y,s.z),a(s.x,n.y,s.z),a(s.x,s.y,s.z),a(n.x,s.y,s.z),a(s.x,n.y,n.z),a(s.x,s.y,n.z),a(n.x,n.y,n.z),a(n.x,s.y,n.z),a(n.x,n.y,s.z),a(n.x,s.y,s.z),a(s.x,n.y,s.z),a(s.x,s.y,s.z),a(s.x,n.y,n.z),a(s.x,n.y,s.z),a(n.x,n.y,n.z),a(n.x,n.y,s.z),a(s.x,s.y,n.z),a(s.x,s.y,s.z),a(n.x,s.y,n.z),a(n.x,s.y,s.z),e.save(),e.strokeStyle="yellow",e.beginPath(),r.forEach((o,l)=>{const h=this.transToScreenCoord(o,i);l%2===0?e.moveTo(h.x,h.y):e.lineTo(h.x,h.y)}),e.closePath(),e.stroke(),e.restore()}drawCenter(e,i){const s=this.transToScreenCoord(this.getCenter(),i);e.save(),e.fillStyle="yellow",e.beginPath(),e.arc(s.x,s.y,5,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}getBounds(){const e=this.getVertexes();return new p.Box3().setFromPoints(e)}}const Un=new p.Vector3;class bt extends Ht{constructor(e,i,s=[1,0,0,1],n){super(e);g(this,"boxes");g(this,"lineSegments");this.lineSegments=[],this.boxes=bt.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=n??[s[0],s[1],s[2],.12],this.lineWidth=2,this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),n=s.getSize(Un),r=Math.max(n.x,n.y)*.12||1;return s.expandByScalar(r)})}calculateCloudLineSegments(e){for(let i=0;i<e.length;i++){const s=e[i],n=[new p.Vector3(s.min.x,s.min.y),new p.Vector3(s.max.x,s.min.y),new p.Vector3(s.max.x,s.max.y),new p.Vector3(s.min.x,s.max.y),new p.Vector3(s.min.x,s.min.y)],r=Un.subVectors(n[0],n[2]).length()/10||1e-4,a=[];for(let o=0;o<n.length-1;o++){const l=n[o],h=n[o+1],d=Un.subVectors(h,l),u=d.length(),f=d.normalize(),m=Math.ceil(u/r);for(let b=0;b<m;b++)a.push(l.clone().add(f.clone().multiplyScalar(r*b)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=Li.rgba2Color(this.lineColor),e.fillStyle=Li.rgba2Color(this.fillColor);for(let s=0;s<this.lineSegments.length;s++){const n=this.boxes[s];n&&this.fillRect(e,i,n);const r=this.lineSegments[s];this.drawBox(e,i,r)}e.restore()}fillRect(e,i,s){const n=[new p.Vector3(s.min.x,s.min.y),new p.Vector3(s.max.x,s.min.y),new p.Vector3(s.max.x,s.max.y),new p.Vector3(s.min.x,s.max.y)];e.beginPath();for(let r=0;r<n.length;r++){const a=this.transToScreenCoord(n[r],i);r===0?e.moveTo(a.x,a.y):e.lineTo(a.x,a.y)}e.closePath(),e.fill()}drawBox(e,i,s){e.beginPath();for(let n=0;n<s.length-1;n++){const r=this.transToScreenCoord(s[n],i),a=this.transToScreenCoord(s[n+1],i),o=bt.getControlPointByTwoPoints(a,r);n===0&&e.moveTo(r.x,r.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new p.Vector2().subVectors(i,e),n=s.angle(),r=s.length(),a=p.MathUtils.degToRad(45),o=r/2/Math.cos(a);return new p.Vector2(e.x+o*Math.cos(a-n),e.y-o*Math.sin(a-n))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new p.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}bs._registerDrawableClass(bt);const nd=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215],rd=["PROXY","REGION","INSERT","HATCH"];function ki(c){return nd[c]}function Ye(c){const t={};let e=c.lastReadGroup,i=e.code;if(t.x=e.value,i+=10,e=c.next(),e.code!==i)throw new Error("Expected code for point value to be "+i+" but got "+e.code);return t.y=e.value,i+=10,e=c.next(),e.code!==i||(t.z=e.value,c.next()),t}const ad="OriginalHandle",od="OriginalType",ld="Outlines";function ee(c,t){switch(t.code){case 0:c.type=t.value;break;case 5:c.handle=t.value;break;case 6:c.lineType=(t.value||"BYLAYER").toUpperCase();break;case 8:c.layer=t.value||"0";break;case 39:c.thickness=t.value;break;case 48:c.lineTypeScale=t.value>0?t.value:1;break;case 60:c.visible=t.value!==1;break;case 62:if(!c.isTrueColor){const e=t.value;c.colorIndex=e,e<0&&console.warn("[DxfParser] Negative colorIndex indicates layer is off or BYBLOCK/BYLAYER"),c.color=ki(Math.abs(e))}break;case 67:c.inPaperSpace=t.value===1;break;case 330:c.ownerHandle=t.value;break;case 370:c.lineweight=t.value;break;case 410:c.layoutName=t.value;break;case 420:c.isTrueColor=!0,c.color=t.value;break;case 1e3:if(t.value&&typeof t.value=="string"){if(t.value.includes(ad)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalHandle=e[1]}if(t.value.includes(ld)&&(c.extendedData||(c.extendedData={}),c.extendedData.outlines=[]),t.value.includes(od)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalType=e[1]}}break;case 1001:break;case 92:case 331:case 347:break;default:return!1}return!0}function zi(c,t){switch(t.code){case 0:c.type=t.value;break;case 5:c.handle=t.value;break;case 330:c.ownerHandle=t.value;break;case 1e3:break;case 1001:break;default:return!1}return!0}const kr="BYLAYER",gs="BYBLOCK";var Oe=(c=>(c[c.Mesh=-1]="Mesh",c[c.MeshWithPattern=0]="MeshWithPattern",c[c.LineWithWidth=1]="LineWithWidth",c[c.Line=2]="Line",c[c.LineWithPattern=3]="LineWithPattern",c[c.Point=4]="Point",c[c.Text=5]="Text",c))(Oe||{});const os=["INSERT","DIMENSION"];function cd(c,t,e,i,s){if(!t)return 0;const n=/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/.test(c),r=s&&s.toLowerCase().endsWith(".shx");let a=0,o=0;if(t.userData&&typeof t.userData.advanceWidth=="number")a=t.userData.advanceWidth,n||(a+=a*.15);else if(t.boundingBox){const l=new p.Vector3;t.boundingBox.getSize(l),a=l.x}if(c===" ")return a=e*.25,a;if(r)i>1?o=(i-1)*e*.1:o=a*.05;else{const l=e*.04;n?o=i>1?(i-1)*e*.1:0:o=i*l}return a+o}function hd(c){const t=/(\\M\+(?:[0-5])[0-9A-Fa-f]{4,})/g,e=c.match(t);if(!e)return c;let i=c;for(const s of e){const n=s.substring(4);if(n.length<4){console.error(`警告:提取的十六进制数 '${n}' 长度不足,已保留原始编码。`);continue}const r=n.substring(0,4),a=n.substring(4);try{const o=new Uint8Array(r.match(/.{1,2}/g).map(d=>parseInt(d,16))),h=new TextDecoder("gbk").decode(o);i=i.replace(s,h+a)}catch(o){console.error("转换失败:",o)}}return i}function Ma(c){const t=[];let e=c;const i=/\\[a-z]+\d*\.?\d*;?/g;return(c.match(i)||[]).forEach(n=>{e=e.replace(n,""),t.push(n)}),{formatCodes:t,plainText:e}}function dd(c,t){const e=Ma(c.text).plainText,i=Ma(t.text).plainText;return e===i}var Ve=(c=>(c.Added="Added",c.Removed="Removed",c.Modified="Modified",c.NoChange="NoChange",c))(Ve||{});let De=1;const Tt=class Tt{constructor(t,e,i={}){g(this,"dxf1");g(this,"dxf2");g(this,"changes");g(this,"comparedBlocks");g(this,"isComparingBlock");g(this,"isComparingDimension");g(this,"enableDetailComparision");if(this.changes={},this.comparedBlocks=new Map,this.isComparingBlock=!1,this.isComparingDimension=!1,this.enableDetailComparision=i.enableDetailComparision!=null?i.enableDetailComparision:!0,this.dxf1=t,this.dxf2=e,!t||!e)throw new Error("Invalid DXF data to compare!")}getLayerFrozen(t,e){const i=e.layer;if(!i)return;const s=t.tables?.layer?.layers;return s?s[i]?.frozen:void 0}async compare(t){this.changes={};const e=[],i=new Map;return this.dxf1.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf1,s)===!0;!Tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf2,s)===!0;!Tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&i.set(s.handle,s)}}),await this.compareEntities(e,i,t),Promise.resolve(this.changes)}isDimensionBlock(t){return t.includes("*D")}compareInsertOrDemensionEntities(t,e,i,s){if(!t.block||!e.block)return;const n=t.block;let r;if(this.isComparingBlock=!0,this.isDimensionBlock(n)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,r=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,P.debug("[DxfCompare] compare block: "+n+" took "+(Date.now()-l)/1e3+"s")}else{if(!this.comparedBlocks.has(n)){const a=this.dxf1.blocks[n],o=this.dxf2.blocks[n],l=Date.now(),h=this.compareBlock(t,e,a,o);this.comparedBlocks.set(n,h),P.debug("[DxfCompare] compare block: "+n+" took "+(Date.now()-l)/1e3+"s")}r=this.comparedBlocks.get(n)}return r?.forEach(a=>{if(!a.parentHandles&&(a.parentHandles=[]),i&&s)a.type==="Added"?a.parentHandles.push(s):a.type==="Removed"&&a.parentHandles.push(i);else{const o=[...a.parentHandles,t.handle];a.type==="Added"?this.changes[De]={id:De,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[De]={id:De,...a,parentHandles:o}),De++}}),!i&&!s&&(this.isComparingBlock=!1),r}compareBlock(t,e,i,s){const n=[],r=[];i?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&n.push(l)}),s?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&r.push(l)});const a=[],o=[];for(let l=0;l<n.length;l++){const h=n[l];let d=!1;r.length===0&&(d=!0),!this.isComparingDimension&&(this.isComparingDimension=h.type==="DIMENSION");for(let u=0;u<r.length;u++){const f=r[u];if(!this.entitiesEqual(h,f,t,e))d=!0;else if(h.type==="INSERT"&&f.type==="INSERT"||h.type==="DIMENSION"&&f.type==="DIMENSION"){const m=this.compareInsertOrDemensionEntities(h,f,h.handle,f.handle);m&&m.length>0&&a.push(...m),d=!1,r.splice(u--,1);break}else{d=!1,r.splice(u--,1);break}}d&&(a.push({type:"Removed",handle:h.handle}),o.push(h.handle))}return r.forEach(l=>{!o.includes(l.handle)&&a.push({type:"Added",handle:l.handle})}),a}async compareEntities(t,e,i){const s=j.getUpdateProgressFuncForLoop(t.length,i);for(let n=0;n<t.length;n++){const r=t[n].handle;if(!e.has(r))this.changes[De]={id:De,type:"Removed",handle:r},De++;else{const a=t[n],o=e.get(r),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(os.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(r),P.warn("[DxfCompare] We cannot compare insert (handle '"+a.handle+"') yet, ignored!");continue}this.compareInsertOrDemensionEntities(a,o)}}else{if(a.extendedData?.originalType&&o.extendedData?.originalType&&a.block!==o.block){e.delete(r);continue}this.changes[De]={id:De,type:"Modified",handle:r},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[De].detailChanges=l),De++}e.delete(r)}await s(n)}for(const n of e){const r=n[0];this.changes[De]={id:De,type:"Added",handle:r},De++}}bIgnoreChildEntitiesOriginalType(t){return rd.includes(t.extendedData?.originalType)}entitiesEqual(t,e,i,s,n){if(!this.baseEntitiesEqual(t,e,i,s,n))return!1;const r=t.type;let a=!0;switch(r){case"CIRCLE":case"ARC":a=this.arcsEqual(t,e);break;case"LWPOLYLINE":case"LINE":a=this.linesEqual(t,e,n);break;case"POLYLINE":a=this.polylinesEqual(t,e);break;case"TEXT":a=this.textsEqual(t,e);break;case"SOLID":a=this.solidsEqual(t,e);break;case"POINT":a=this.pointsEqual(t,e);break;case"INSERT":a=this.insertsEqual(t,e);break;case"SPLINE":a=this.splinesEqual(t,e);break;case"MTEXT":a=this.mtextsEqual(t,e);break;case"ELLIPSE":a=this.ellipsesEqual(t,e);break;case"DIMENSION":a=this.dimensionsEqual(t,e);break;case"REGION":a=this.regionsEqual(t,e);break;case"ATTDEF":a=this.attDefsEqual(t,e);break;case"ATTRIB":a=this.attribsEqual(t,e);break;case"HATCH":a=this.hatchesEqual(t,e);break;case"VIEWPORT":a=this.viewportsEqual(t,e);break;case"LEADER":a=this.leadersEqual(t,e);break;case"MULTILEADER":a=this.mleadersEqual(t,e);break;case"OLE2FRAME":a=this.ole2framesEqual(t,e);break;case"SEQEND":a=!0;break;default:a=!1}return a}getColor(t,e,i){if(t.isTrueColor||t.colorIndex>0&&t.colorIndex<256)return t.color;if(t.colorIndex===0)return i?this.getColor(i,e):e.tables?.layer?.layers[0].color;let s=0;if(t.colorIndex===256){const n=e.tables?.layer?.layers,r=n&&n[t.layer],a=n&&i&&n[i.layer];r&&r.name!=="0"?s=r.color:a?s=a.color:r?s=r.color:s=e.tables?.layer?.layers[0].color}return s}getLineType(t,e,i){if(i&&i.type==="DIMENSION")return this.getLineType(i,e);if(t.lineType!==kr&&t.lineType!==gs)return t.lineType;if(t.lineType===gs)return i?this.getLineType(i,e):t.lineType;const s=e.tables?.layer?.layers,n="CONTINUOUS";if(t.layer!=="0"){const r=s&&s[t.layer];if(r)return r.lineType}else if(i){const r=s&&s[i.layer];if(r)return r.lineType}return n}addModificationItem(t,e,i,s){s&&(s[i]={old:t,new:e})}baseEntitiesEqual(t,e,i,s,n){let r=!0;const a=this.getColor(t,this.dxf1,i),o=this.getColor(e,this.dxf2,s);if(a!==o)if(r=!1,this.enableDetailComparision)this.addModificationItem(a,o,"color",n);else return r;const l=this.getLineType(t,this.dxf1,i),h=this.getLineType(e,this.dxf2,s);if(l!==h){if(r=!1,this.enableDetailComparision)this.addModificationItem(l,h,"lineType",n);else return r;return!1}return t.extendedData?.originalType!==e.extendedData?.originalType||!this.isComparingBlock&&!this.isComparingDimension&&t.handle!==e.handle||!this.isComparingDimension&&t.ownerHandle!==e.ownerHandle||t.type!==e.type?!1:r}arcsEqual(t,e){return!(!this.vectorsEqual(t.center,e.center)||!this.numberEqual(t.radius,e.radius)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}linesEqual(t,e,i){let s=!0;const n=t.constantWidth,r=e.constantWidth;if(!this.numberEqual(n,r))if(s=!1,this.enableDetailComparision)this.addModificationItem(n||0,r||0,"constantWidth",i);else return!1;return!this.verticesEqual(t.vertices,e.vertices)||t.shape!==e.shape?!1:s}polylinesEqual(t,e){return!(!this.vertexEntitiesEqual(t.vertices,e.vertices)||t.shape!==e.shape||t.isPolyfaceMesh!==e.isPolyfaceMesh)}textsEqual(t,e){if(t.halign!==e.halign)return!1;if(t.halign===3||t.halign===5){if(!this.pointsEqual(t.startPoint,e.startPoint))return!1}else if(!this.pointsEqual(t.endPoint,e.endPoint))return!1;return t.text===e.text}solidsEqual(t,e){return!!this.verticesEqual(t.points,e.points)}pointEntitiesEqual(t,e){return!!this.pointsEqual(t.position,e.position)}splinesEqual(t,e){return!(!this.verticesEqual(t.controlPoints,e.controlPoints)||!this.numbersEqual(t.knotValues,e.knotValues)||!this.numberEqual(t.degreeOfSplineCurve,e.degreeOfSplineCurve))}mtextsEqual(t,e,i={}){const{compareFormat:s=!1,comparePosition:n=!0}=i;if(n&&!this.pointsEqual(t.position,e.position))return!1;if(s){if(t.text!==e.text)return!1}else if(!dd(t,e))return!1;return!!this.numberEqual(t.rotation,e.rotation)}ellipsesEqual(t,e){return!(!this.pointsEqual(t.center,e.center)||!this.pointsEqual(t.majorAxisEndPoint,e.majorAxisEndPoint)||!this.numberEqual(t.axisRatio,e.axisRatio)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}attDefsEqual(t,e){return!(!this.pointsEqual(t.startPoint,e.startPoint)||!this.pointsEqual(t.endPoint,e.endPoint)||!this.numberEqual(t.xScale,e.xScale)||t.text!==e.text||t.tag!==e.tag||t.prompt!==e.prompt)}attribsEqual(t,e){return this.attDefsEqual(t,e)}hatchesEqual(t,e){const i=t,s=e;return!(!this.numberEqual(i.elevationX,s.elevationX)||!this.numberEqual(i.elevationY,s.elevationY)||!this.numberEqual(i.elevationZ,s.elevationZ)||!this.hatchBoundaryPathArraysEqual(i.boundaryPaths,s.boundaryPaths))}viewportsEqual(t,e){const i=t,s=e;return!(!this.pointsEqual(i.centerPoint,s.centerPoint)||!this.pointsEqual(i.centerPoint_dcs,s.centerPoint_dcs)||!this.pointsEqual(i.viewDirection,s.viewDirection)||!this.numberEqual(i.viewHeight,s.viewHeight)||i.width_paperSpace!==s.width_paperSpace||i.height_paperSpace!==s.height_paperSpace)}leadersEqual(t,e){return!(!this.pointsEqual(t.position,e.position)||!this.verticesEqual(t.vertices,e.vertices)||t.arrowHeadBlockHandle!==e.arrowHeadBlockHandle||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)||!this.numberEqual(t.rotation,e.rotation)||t.block!==e.block)}mleadersEqual(t,e){return t.arrowHeadId!==e.arrowHeadId||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)?!1:this.mleaderContextEqual(t.contextData,e.contextData)}ole2framesEqual(t,e){return!(t.leftUpX!==e.leftUpX||t.leftUpY!==e.leftUpY||t.leftUpZ!==e.leftUpZ||t.rightDownX!==e.rightDownX||t.rightDownY!==e.rightDownY||t.rightDownZ!==e.rightDownZ)}insertsEqual(t,e){return t.extendedData?.originalType==="INSERT"&&e.extendedData?.originalType==="INSERT"?(P.warn("[DxfCompare] We cannot compare insert (handle '"+t.handle+"') yet, ignored!"),!0):!(!this.pointsEqual(t.position,e.position)||!this.numberEqual(t.xScale===void 0?1:t.xScale,e.xScale===void 0?1:e.xScale)||!this.numberEqual(t.yScale===void 0?1:t.yScale,e.yScale===void 0?1:e.yScale)||!this.numberEqual(t.zScale===void 0?1:t.zScale,e.zScale===void 0?1:e.zScale)||t.block!==e.block||t.entities?.length!==e.entities?.length)}dimensionsEqual(t,e){return!!this.pointsEqual(t.anchorPoint,e.anchorPoint)}regionsEqual(t,e){return P.warn("Cannot compare region yet!"),!0}vectorsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z):!1}pointsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z)&&this.numberEqual(t.bulge,e.bulge):!1}vertexEntityEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t,e)||t.polyfaceMeshVertex!==e.polyfaceMeshVertex||t.threeDPolylineMesh!==e.threeDPolylineMesh):!1}numbersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.numberEqual(t[i],e[i]))return!1;return!0}return!1}numberEqual(t,e){return t==null&&e==null?!0:t!=null&&e!=null?z.areNumbersEqual(t,e):!1}vectorArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vectorsEqual(t[i],e[i]))return!1;return!0}return!1}verticesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.pointsEqual(t[i],e[i]))return!1;return!0}return!1}verticesArrayEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.verticesEqual(t[i],e[i]))return!1;return!0}return!1}vertexEntitiesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vertexEntityEqual(t[i],e[i]))return!1;return!0}return!1}hatchEdgesEqual(t,e){return!t&&!e?!0:t&&e?t.type===e.type:!1}hatchEdgeArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchEdgesEqual(t[i],e[i]))return!1;return!0}return!1}hatchBoundaryPathsEqual(t,e){return!t&&!e?!0:t&&e?t.pathTypeFlag!==e.pathTypeFlag?!1:this.hatchEdgeArraysEqual(t.edges,e.edges):!1}hatchBoundaryPathArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchBoundaryPathsEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLineEqual(t,e){return!t&&!e?!0:t&&e?!(!this.verticesArrayEqual(t.vertices,e.vertices)||t.leaderLineIndex!==e.leaderLineIndex):!1}mleaderLinesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLineEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLeaderEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.lastLeaderLinePoint,e.lastLeaderLinePoint)||!this.pointsEqual(t.doglegVector,e.doglegVector)||!this.mleaderLinesEqual(t.leaderLines,e.leaderLines)):!1}mleaderLeadersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLeaderEqual(t[i],e[i]))return!1;return!0}return!1}mleaderContextEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.contentBasePosition,e.contentBasePosition)||!this.pointsEqual(t.blockContentPosition,e.blockContentPosition)||!this.mleaderLeadersEqual(t.leaders,e.leaders)):!1}compareHexStrings(t,e){return parseInt(t,16)-parseInt(e,16)}};g(Tt,"ENTITY_COLOR_ADDED",65280),g(Tt,"ENTITY_COLOR_REMOVED",16711680),g(Tt,"ENTITY_COLOR_NO_CHANGE",10066329),g(Tt,"ENTITY_COLOR_MARKUP",16744231),g(Tt,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let at=Tt;var G=(c=>(c[c.Object=0]="Object",c[c.Point=1]="Point",c[c.Line=2]="Line",c[c.LineSegment=3]="LineSegment",c[c.Mesh=4]="Mesh",c))(G||{});const Hn=new D.Box3,Nn=new D.Matrix4;class V{constructor(t=0){g(this,"name");g(this,"type");g(this,"matrix");g(this,"parent");g(this,"children");g(this,"layers");g(this,"renderOrder");g(this,"userData");g(this,"material");g(this,"geometry");g(this,"matrixWorld");this.name="",this.type=0,this.matrix=new D.Matrix4,this.children=[],this.layers=new D.Layers,this.renderOrder=0,this.userData={},this.type=t}add(t,...e){for(let i=0;i<e.length;i++)this.add(e[i]);return t===this?(console.error("object can't be added as a child of itself.",t),this):(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),this)}remove(t,...e){for(let s=0;s<e.length;s++)this.remove(e[s]);const i=this.children.indexOf(t);return i!==-1&&(t.parent=void 0,this.children.splice(i,1)),this}removeFromParent(){const t=this.parent;return t&&t.remove(this),this}clear(){this.material=void 0,this.geometry=void 0;for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=void 0}return this.children.length=0,this}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}clone(t=!0){return new V().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.type=t.type,this.matrix.copy(t.matrix),this.layers.mask=t.layers.mask,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),this.material=t.material,this.geometry=t.geometry,e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}convertToThreejsObject(t=!0){let e;switch(this.type){case 0:e=new D.Object3D;break;case 1:if(!this.geometry)return;e=new p.Points(this.geometry,this.material);break;case 2:if(!this.geometry)return;e=new p.Line(this.geometry,this.material);break;case 3:if(!this.geometry)return;e=new p.LineSegments(this.geometry,this.material);break;case 4:if(!this.geometry)return;e=new p.Mesh(this.geometry,this.material);break}if(e){if(e.name=this.name,e.matrixAutoUpdate=ct,e.applyMatrix4(this.matrix),e.layers.mask=this.layers.mask,e.renderOrder=this.renderOrder,e.userData=this.userData,t===!0)for(let i=0;i<this.children.length;i++){const s=this.children[i],n=s.convertToThreejsObject(t);n&&e.add(n)}return e}}static getBox(t,e,i){if(t.geometry)!t.geometry.boundingBox&&t.geometry.computeBoundingBox(),Nn.copy(t.matrix),i&&Nn.premultiply(i),Hn.copy(t.geometry.boundingBox),Hn.applyMatrix4(Nn),e.union(Hn);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new D.Matrix4),t.matrixWorld.copy(t.matrix),i&&t.matrixWorld.premultiply(i);const s=t.children;for(let n=0,r=s.length;n<r;n++)this.getBox(s[n],e,t.matrixWorld)}return e}computeBoundingllBox(t,e,i){const s={x:0,y:0};s.x=e.position?.x||0,s.y=e.position?.y||0;let n=e.blockPosition?.x||0,r=e.blockPosition?.y||0;s.x=s.x-n,s.y=s.y-r;const a=new D.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new D.Box3;!l.geometry&&l.children&&l.children.length===1;)l={...l.children[0],loneMatrix:l.matrix};if(l.geometry){!l.geometry.boundingBox&&l.geometry.computeBoundingBox();const h=new D.Box3().copy(l.geometry.boundingBox);h.applyMatrix4(l.loneMatrix||l.matrix),o.push({min:{x:h.min.x,y:h.min.y,z:h.min.z},max:{x:h.max.x,y:h.max.y,z:h.max.z},positions:[{x:h.min.x+s.x,y:h.min.y+s.y},{x:h.min.x+s.x,y:h.max.y+s.y},{x:h.max.x+s.x,y:h.max.y+s.y},{x:h.max.x+s.x,y:h.min.y+s.y}],rotation:e.rotation,center:{x:(h.min.x+h.max.x)/2+s.x,y:(h.min.y+h.max.y)/2+s.y,z:(h.min.z+h.max.z)/2},size:{x:h.max.x-h.min.x,y:h.max.y-h.min.y,z:h.max.z-h.min.z}}),a.union(h)}}),!a.isEmpty()&&a.max.x-a.min.x<20&&a.max.y-a.min.y<20?t.userData.boundingBoxs=[{min:{x:a.min.x,y:a.min.y,z:a.min.z},max:{x:a.max.x,y:a.max.y,z:a.max.z},positions:[{x:a.min.x+s.x,y:a.min.y+s.y},{x:a.min.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.min.y+s.y}],rotation:e.rotation,center:{x:(a.min.x+a.max.x)/2+s.x,y:(a.min.y+a.max.y)/2+s.y,z:(a.min.z+a.max.z)/2},size:{x:a.max.x-a.min.x,y:a.max.y-a.min.y,z:a.max.z-a.min.z}}]:t.userData.boundingBoxs=o}rotateRectByBottomLeft(t,e,i,s,n){const r=i-t,a=s-e,o=n*Math.PI/180,l=Math.cos(o),h=Math.sin(o);return[{dx:0,dy:0},{dx:r,dy:0},{dx:r,dy:a},{dx:0,dy:a}].map(u=>{const f=u.dx*l-u.dy*h,m=u.dx*h+u.dy*l;return{x:t+f,y:e+m}})}}const Ns=new p.Matrix4,ud=new p.Matrix4;class Mt{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},n=[];for(let h=0;h<i;++h){const d=t.children[h];if(d.children.length>0){this.mergeInner(d,e);continue}if(d.userData.relativeToCenter||!d.geometry)continue;let f=!1;const m=Object.values(s);for(let b=m.length-1;b>=0;--b){const y=m[b].indexes[0];if(f=this.tryHandleMergeableObjects(t,h,y,s,n),f)break}for(let b=n.length-1;!f&&b>=0;--b){const y=n[b];if(f=this.tryHandleMergeableObjects(t,h,y,s,n),f)break}!f&&n.push(h)}if(Object.keys(s).length<=0)return;const r=[],a=[],o=[],l=[];Object.values(s).forEach(h=>{const d=h.indexes,u=t.children[d[0]];let f=[],m=0,b=0,y=0;const C=[];if(d.forEach(x=>{const E=t.children[x],M=E.geometry?.clone();if(M.applyMatrix4(E.matrix),M.userData.isLineSegments=E.type===G.LineSegment,f.push(M),e){const O=M.attributes?.position?.count,S=M.index?.count||0;C.push({batchId:m,positionStart:b,positionCount:O,indexStart:y,indexCount:S}),b+=O,y+=S,m++}}),f.length===0)return;let w;if(u.type===G.Mesh){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new V(u.type),w.geometry=x,w.material=u.material,r.push(w)}else if(u.type===G.Line||u.type===G.LineSegment){const x=fe.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,C);if(!x)return;w=new V(G.LineSegment),w.geometry=x,w.material=u.material,a.push(w)}else if(u.type===G.Point){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new V(u.type),w.geometry=x,w.material=u.material,o.push(w)}w&&(e?w.userData.batches=C:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,l.push(...d)),f.forEach(x=>{x.dispose(),N.releaseGeometryManually(x)}),f=[]}),l.sort((h,d)=>d-h),l.forEach(h=>{const d=t.children[h];t.remove(d)}),[...r,...a,...o].forEach(h=>{t.add(h)}),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=r.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,n){let r=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return r;const l=a?t[e]:t.children[e],h=a?t[i]:t.children[i];return this.areObjectsMergeable(l,h)&&fe.areGeometriesMergeable(l.geometry,h.geometry)&&xe.materialsEquals(l.material,h.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(n,i)),s[i].indexes.push(e),r=!0),r}static isFilteredByOtherFactors(t,e){const i=t;if(i.type===G.Mesh&&i.material&&i.material.isShaderMaterial)return!0;let s=!1,n=t;for(;n&&n!==e;){const r=n.userData;if(r.relativeToCenter||r.spatialFilterHandle){s=!0;break}n=n.parent}return s}static deepMerge(t,e=void 0,i=!0,s=!0,n=!0){const r={added:[],removed:[]};if(t.length<=1)return r;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){if(!t[y].geometry||this.isFilteredByOtherFactors(t[y],e))continue;let w=!1;const x=Object.values(o);for(let E=x.length-1;E>=0;--E){const M=x[E].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let E=l.length-1;!w&&E>=0;--E){const M=l[E];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}!w&&l.push(y)}if(Object.keys(o).length<=0)return r;P.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const h=[],d=[],u=[],f=[];Object.values(o).forEach(y=>{const C=y.indexes;if(C.length<2)return;const w=t[C[0]];let x=[],E=0,M=0,O=0;const S=[];if(C.forEach(T=>{const _=t[T],A=_.geometry?.clone();if(w.material instanceof p.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,_,e),A.userData.isLineSegments=_.type===G.LineSegment,x.push(A),n){const I=A.attributes?.position?.count,B=A.index?.count||0;let k;(w.type===G.Line||w.type===G.LineSegment)&&(!A.boundingSphere&&A.computeBoundingSphere(),k=A.boundingSphere?.clone());const L={batchId:E,positionStart:M,positionCount:I,indexStart:O,indexCount:B,boundingSphere:k};Object.keys(_.userData).length!==0&&(L.userData=_.userData),S.push(L),M+=I,O+=B,E++}}),x.length===0)return;let v;if(w.type===G.Mesh){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new V(w.type),v.geometry=T,v.material=w.material,h.push(v)}else if(w.type===G.Line||w.type===G.LineSegment){const T=fe.mergeLineGeometries(x,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,S);if(!T)return;v=new V(G.LineSegment),v.geometry=T,v.material=w.material,d.push(v)}else if(w.type===G.Point){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new V(w.type),v.geometry=T,v.material=w.material,u.push(v)}v&&(n?v.userData.batches=S:(v.userData=w.userData,v.userData.batches=void 0),v.userData.layerName=w.userData.layerName,v.name="[Merged] "+w.name,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,C.forEach(T=>f.push(T))),x.forEach(T=>{T.dispose(),N.releaseGeometryManually(T)}),x=[]}),P.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(y=>{const C=t[y];m.push(C),i&&C.removeFromParent()});const b=r.added;return[...h,...d,...u].forEach(y=>{b.push(y),i&&e&&e.add(y)}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&J.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Ns.identity();s&&s!==i&&(Ns.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ns.equals(ud)?t:t.applyMatrix4(Ns)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areObjectsMergeable(t,e){return t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===G.Line||t.type===G.LineSegment)&&(e.type===G.Line||e.type===G.LineSegment)}}g(Mt,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const ko=(c,t)=>{if(typeof t>"u"||+t==0)return Math.round(c);let e=+c;if(t=+t,isNaN(e)||!(typeof t=="number"&&t%1===0))return NaN;let i=e.toString().split("e");return e=Math.round(+(i[0]+"e"+(i[1]?+i[1]-t:-t))),i=e.toString().split("e"),+(i[0]+"e"+(i[1]?+i[1]+t:t))},Do=(c,t,e,i,s)=>{const n=e.length,r=e[0].length;if(c<0||c>1)throw new Error("t out of bounds [0,1]: "+c);if(t<1)throw new Error("degree must be at least 1 (linear)");if(t>n-1)throw new Error("degree must be less than or equal to point count - 1");if(i){if(i.length!==n+t+1)throw new Error("bad knot vector length")}else{i=[];for(let m=0;m<n+t+1;m++)i[m]=m}const a=[t,i.length-1-t],o=i[a[0]],l=i[a[1]];c=c*(l-o)+o,c=Math.max(c,o),c=Math.min(c,l);let h;for(h=a[0];h<a[1]&&!(c>=i[h]&&c<=i[h+1]);h++);const d=[];for(let m=0;m<n;m++){d[m]=[];const b=s?s[m]:1;for(let y=0;y<r;y++)d[m][y]=e[m][y]*b;d[m][r]=b}let u;for(let m=1;m<=t+1;m++)for(let b=h;b>h-t-1+m;b--){u=(c-i[b])/(i[b+t+1-m]-i[b]);for(let y=0;y<r+1;y++)d[b][y]=(1-u)*d[b-1][y]+u*d[b][y]}const f=[];for(let m=0;m<r;m++)f[m]=ko(d[h][m]/d[h][r],-9);return f},fd={d:"°",c:"⌀",p:"±"},ls=(c,t)=>{if(!c)return[];c=c.replace(/%%(.)/g,(o,l)=>fd[l]||l).replace(/\^I/g," ");const e=t?.encoding;let i=e instanceof TextDecoder?e:void 0,s="",n;const r=[],a=o=>{s&&(r.push(s),s=""),r.push(o)};for(let o=0;o<c.length;o++)switch(n=c[o]){default:s+=n;break;case"\\":{switch(n=c[++o]){default:s+=n;break;case"p":{const l=c.slice(o,o=c.indexOf(";",o));l.startsWith("pxq")||l.startsWith("pxi")||l.startsWith("pxt")||l.startsWith("pt")||l.startsWith("pi")||(l.startsWith("psm")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):l.startsWith("pq")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):a({[l.slice(0,l.length-1)]:l[l.length-1]}));break}case"P":s+=`
536
- `;break;case"f":case"F":{let l="";for(;n=c[++o];){if(n===";"){a({f:l});break}if(n==="|"){const h={f:l},d=c.indexOf(";",++o);for(const u of c.slice(o,d).split("|"))h[u[0]]=+u.slice(1);o=d,a(h);break}l+=n==="\\"?c[++o]:n}break}case"S":{let l="",h,d="";for(;n=c[++o];){if(n===";"){const u=l+d;u&&a(u);break}if(n==="\\"){const u=c[++o];h?d+=u:l+=u}else!h&&(n==="^"||n==="/"||n==="#")?h=n:h?d+=n:l+=n}break}case"H":case"W":{const l=++o,[,h,d]=c.slice(l,o=c.indexOf(";",o)).match(/^(\d*(?:\.\d+)?)(\D*)$/);a({[n]:[+h,d]})}break;case"Q":case"A":case"C":case"c":case"T":{const l=++o;a({[n]:+c.slice(l,o=c.indexOf(";",o))});break}case"L":case"O":case"K":a({[n]:1});break;case"l":case"o":case"k":a({[n.toUpperCase()]:0});break;case"U":case"u":c[o+1]==="+"?(s+=String.fromCodePoint(parseInt(c.substr(o+2,4),16)),o+=5):s+=n;break;case"M":case"m":e?c[o+1]==="+"&&(c[o+2]==="0"||c[o+2]==="1")?(s+=(i=i||new TextDecoder(e)).decode(new Uint8Array([parseInt(c.substr(o+3,2),16),parseInt(c.substr(o+5,2),16)])),o+=6):s+=n:s+="\\"+n;break}break}case"{":{let l=1;const h=o;for(;n=c[++o];)if(n==="{")l++;else if(n==="}"){if(--l===0){a(ls(c.slice(h+1,o)));break}}else n==="\\"&&o++;break}}return s&&r.push(s),r},pd={d:"°",c:"⌀",p:"±"},Lo=(c,t)=>(c=Ro(c),t?Fo(c,t):c),Ro=c=>c.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),Fo=(c,t)=>{let e=t instanceof TextDecoder?t:new TextDecoder(t);return c.replace(/\\[mM]\+[0|1]([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,(i,s,n)=>(e=e||new TextDecoder(t)).decode(new Uint8Array([parseInt(s,16),parseInt(n,16)])))},cn=(c,t)=>{c=Lo(c,t?.encoding);let e=0,i={text:""};const s=[i],n=c.matchAll(/%%(\d\d\d|.)/g);for(const r of n){i.text+=c.slice(e,r.index);const a=r[1],o=a.toLowerCase(),l=pd[o];l?i.text+=l:o.length===3?i.text+=String.fromCodePoint(+o):o==="k"||o==="o"||o==="u"?(i=Object.assign(Object.assign({},i),{text:""}),i[o]?delete i[o]:i[o]=1,s.push(i)):i.text+=o,e=r.index+r[0].length}return i.text+=c.slice(e),s.filter(r=>r.text)};class zo{static createLineShaderMaterial(t,e,i,s,n){let r=0;const a=[];for(let d=0;d<t.length;d++)a[d]=t[d],a[d]===0&&(a[d]=.5),a[d]*=i,r+=Math.abs(a[d]);const o=p.UniformsUtils.merge([p.UniformsLib.common,{pattern:{value:a},patternLength:{value:r},u_color:{value:new p.Color(e)}}]);o.u_viewportScale=s,o.u_cameraZoom=n;const l=`
534
+ `,Re=p.ShaderChunk;Re.outline_bc_vertex=wh;Re.outline_bc_fragment=vh;Re.outline_bc_pars_fragment=Mh;Re.outline_bc_pars_vertex=Th;Re.standard_ex_vertex=_h;Re.standard_ex_fragment=Ph;Re.common_ex=yh;Re.id_pars_vertex=xh;Re.id_vertex=bh;Re.state_pars_fragment=Ch;Re.state_fragment=Sh;Re.state_transparent_fragment=Eh;Re.state_highlight_fragment=Oh;Re.pick_ex_vertex=Ah;Re.pick_ex_fragment=Ih;const Bh=p.ShaderChunk;class kh{constructor(t){g(this,"promise");g(this,"cancelReject");const e=new Promise((i,s)=>{this.cancelReject=s});this.promise=Promise.race([e,t])}cancel(){this.cancelReject&&this.cancelReject({type:"cancel"})}}const Dh=Ur.default??Ur,P=Dh;P.setLevel("warn");const To=c=>{try{P.setLevel(c)}catch(t){P.setLevel("error"),P.error(t)}},Ai=class Ai{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),r=/(?:iPhone)/.test(t)&&!n,a=!r&&!e,o=Ai.isTouchScreenDevice();e&&P.debug("[DI] is android"),i&&P.debug("[DI] is fireFox"),s&&P.debug("[DI] is chrome"),n&&P.debug("[DI] is tablet"),r&&P.debug("[DI] is iPhone"),a&&P.debug("[DI] is PC"),o&&P.debug("[DI] is touch device")}static creatReactNativeCanvas(t){const e=t,i=e.drawingBufferWidth||e.width||0,s=e.drawingBufferHeight||e.height||0;return{style:{},width:i,height:s,clientWidth:Math.ceil(i/(window.devicePixelRatio||1)),clientHeight:Math.ceil(s/(window.devicePixelRatio||1)),addEventListener:()=>{},removeEventListener:()=>{}}}};g(Ai,"isMobile",/mobile/i.test(navigator.userAgent)),g(Ai,"isBrowser",typeof document<"u"),g(Ai,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let Be=Ai;const Ii=class Ii{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof p.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof p.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof p.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new p.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(t instanceof p.Vector2)return new p.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new p.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof p.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new p.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,n=(t.max.y-t.min.y)*e,r=(t.max.z-t.min.z)*e,a=new p.Vector3(i.x-s/2,i.y-n/2,i.z-r/2),o=new p.Vector3(i.x+s/2,i.y+n/2,i.z+r/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new p.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,n=t.max.y-t.min.y,r=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),n<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),r<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const n=Math.max(e.min.x,0),r=Math.max(e.min.y,0),a=Math.max(e.max.x-n,0),o=Math.max(e.max.y-r,0),l=t.getImageData(n,r,a,o),h=document.createElement("canvas");return h.width=a,h.height=o,h.getContext("2d").putImageData(l,0,0),h.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!Be.isBrowser)return;const e=performance.memory;if(!e){P.warn("[Util] performance.memory is not available in this browser");return}const i=(e.jsHeapSizeLimit/(1024*1024)).toFixed(2),s=(e.totalJSHeapSize/(1024*1024)).toFixed(2),n=(e.usedJSHeapSize/(1024*1024)).toFixed(2);P.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+n+"M ")}static printGpuInfo(t){if(!Be.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);P.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ii.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,n=Date.now();n-e>s&&(await Ii.sleep(0),e=n)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async n=>{if(e&&(n%i===0||n===t-1)){e(new ProgressEvent("",{loaded:n+1,total:t}));const r=500,a=Date.now();(a-s>r||n===t-1)&&(await Ii.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return n=>{let r=n.loaded*100/n.total;r=r*(e-t)/100+t,r>e&&(s||(P.warn("[Progress] Invalid ProgressEvent:",n),s=!0),r=e),i&&i(new ProgressEvent(n.type,{loaded:r,total:100}))}}};g(Ii,"twinklingObjectIds",{});let j=Ii;const Lh=(c,t,e)=>{const{default:i,active:s}=t;e?(c.remove(i),c.add(s||i)):(s&&c.remove(s),c.add(i))};class Li{static color2rgba(t){let e=[0,0,0,1],i;if(i=/^(\w+)\(([^)]*)\)/.exec(t)){let s;const n=i[1],r=i[2];switch(n){case"rgb":case"rgba":(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[Math.min(255,parseInt(s[1],10))/255,Math.min(255,parseInt(s[2],10))/255,Math.min(255,parseInt(s[3],10))/255,Number(s[4]||1)]),(s=/^\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[Math.min(100,parseInt(s[1],10))/100,Math.min(100,parseInt(s[2],10))/100,Math.min(100,parseInt(s[3],10))/100,Number(s[4]||1)]);break;case"hsl":case"hsla":(s=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))&&(e=[parseFloat(s[1])/360,parseFloat(s[2])/100,parseFloat(s[3])/100,Number(s[4]||1)]);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],n=s.length;if(n===3)e=[parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,1];else if(n===6){const r=parseInt(s,16);e=[(r>>16&255)/255,(r>>8&255)/255,(r&255)/255,1]}else console.warn("THREE.Color: Invalid hex color "+t)}return e}static rgba2Color(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]),n=t[3]!=null?t[3]:1;return"rgba("+e+","+i+","+s+","+n+")"}static colorStr2Rgba(t){let e=t.replace("rgba(","");e=e.replace(")","");const i=e.split(","),s=[];return s.push(this.to1(parseInt(i[0]))),s.push(this.to1(parseInt(i[1]))),s.push(this.to1(parseInt(i[2]))),i[3]!=null&&s.push(parseFloat(i[3])),s}static rgb2Hex(t){const e=this.to255(t[0]),i=this.to255(t[1]),s=this.to255(t[2]);return(e<<16)+(i<<8)+s}static to255(t){let e=Math.max(t,0);return e=Math.min(t,1),e*255}static to1(t){let e=Math.max(t,0);return e=Math.min(t,255),e/255}}class Ee{static getScreenCoordinateByEvent(t,e){const i=new p.Vector2,{left:s,top:n}=e.getBoundingClientRect();return i.x=t.clientX-s,i.y=t.clientY-n,i}static getScreenCoordinateByTouchEvent(t,e){const i=new p.Vector2,{left:s,top:n}=e.getBoundingClientRect();return i.x=t.touches[0].clientX-s,i.y=t.touches[0].clientY-n,i}static world2Screen(t,e,i){const{clientWidth:s,clientHeight:n}=i,r=t.clone(),a=new p.Vector2;return r.project(e),a.x=Math.round((.5+r.x/2)*s),a.y=Math.round((.5-r.y/2)*n),a}static worldBBox2Screen(t,e,i){const s=new p.Box2,n=t.min,r=t.max,a=(o,l,h)=>{const d=new p.Vector3(o,l,h),u=this.world2Screen(d,e,i);s.expandByPoint(u)};return a(n.x,n.y,n.z),a(n.x,n.y,r.z),a(n.x,r.y,n.z),a(n.x,r.y,r.z),a(r.x,n.y,n.z),a(r.x,n.y,r.z),a(r.x,r.y,n.z),a(r.x,r.y,r.z),s}static screen2World(t,e,i){const s=Ee.screen2Ndc(t,e,i);return new p.Vector3(s.x,s.y,1).unproject(e)}static screen2Ndc(t,e,i){const{clientWidth:s,clientHeight:n}=i,r=new p.Vector2;return r.x=t.x/s*2-1,r.y=-(t.y/n)*2+1,r}static world2NormalizedScreen(t,e,i){const s=new p.Vector3,n=t instanceof p.Vector2?0:t.z;s.set(t.x,t.y,n);const r=Ee.world2Screen(s,e,i);return r.x/=i.clientWidth,r.y/=i.clientHeight,r}}class Rh{static createCSS2DObject(t){const e=new yo.CSS2DObject(t);return t.dataset.objectId=e.id.toString(),e}static createDefaultHotpoint(t=12){const e=document.createElement("div"),i=e.style;return i.width=t+"px",i.height=t+"px",i.opacity="0.8",i.cursor="pointer",i.top=-t/2+"px",i.left=-t/2+"px",i.backgroundColor="#ffffff",i.border="2px solid #00DAB7",i.borderRadius="50%",this.createCSS2DObject(e)}static createHotpoint(t){if(t){const e=document.createElement("div"),i=e.style;return i.top="0px",i.left="0px",e.innerHTML=t,this.createCSS2DObject(e)}return this.createDefaultHotpoint()}static createLabel(t,e=""){const i=document.createElement("div");if(i.innerHTML=t,e)i.classList.add(e);else{const s=i.style;s.padding="5px 9px",s.color="#ffffffdd",s.fontSize="12px",s.position="absolute",s.backgroundColor="rgba(0, 0, 0, 0.3)",s.borderRadius="12px",s.cursor="pointer",s.top="0px",s.left="0px"}return this.createCSS2DObject(i)}static tryFindObjectId(t){if(t.dataset.objectId!=null)return parseInt(t.dataset.objectId);const e=t.parentElement;if(e&&!(e instanceof HTMLBodyElement))return this.tryFindObjectId(e)}}const Co={"Precision from file":99},Fh=(c,t)=>c.toFixed(t===Co["Precision from file"]?2:t),So="en",ct=!1,Eo=10,je=11,Ut=12,Pr=583902,zh=[.031,.906,.867,.5],an=[.3,.3,.3,.8],Ar=.5,on=.1,ln=5e3,Oo=45,Vh="x-viewer-iconfont",jh="x-viewer-iconfont2",Ir=10,ca=new p.Vector3,ha=new p.Vector3,da=new p.Vector3,as=new p.Vector3,Ot=new p.Vector3,ua=new p.Triangle;function Uh(c,t,e,i,s){const n=[],r={};let a,o,l,h;const u=Math.pow(10,4);let f,m,b=0;for(f=0,m=c.length;f<m;f+=3)a=c[f],o=c[f+1],l=c[f+2],h=Math.round(a*u)+"_"+Math.round(o*u)+"_"+Math.round(l*u),!r[h]&&(r[h]=b/3,e[b++]=a,e[b++]=o,e[b++]=l),n[f/3]=r[h];for(f=0,m=t.length;f<m;f++)s[f]=n[t[f]],i[s[f]]=t[f]}function Hh(c,t,e,i){for(let s=0,n=c;s<n;s+=3){const r=t[s]*3,a=t[s+1]*3,o=t[s+2]*3;ca.set(e[r],e[r+1],e[r+2]),ha.set(e[a],e[a+1],e[a+2]),da.set(e[o],e[o+1],e[o+2]),p.Triangle.getNormal(ca,ha,da,as),i.push({normal:as.clone()})}}const zn=[new p.Vector3(1,0,0),new p.Vector3(0,1,0),new p.Vector3(0,0,1),new p.Vector3(1,1,0),new p.Vector3(0,1,1),new p.Vector3(1,0,1),new p.Vector3(1,1,1),new p.Vector3(0,0,0)];function Nh(c,t){return Ot.addVectors(c,t),Ot.x===0||Ot.y===0||Ot.z===0}class _o{static buildEdge(t,e,i=Ir){const s=[],n=[],r=[];Uh(t,e,s,n,r);const a=[];Hh(e.length,r,s,a);const o=[],l=Math.cos(p.MathUtils.DEG2RAD*i),h={};let d=!1;for(let u=0,f=e.length;u<f;u+=3){const m=u/3;for(let b=0;b<3;b++){const y=r[u+b],C=r[u+(b+1)%3],w=Math.min(y,C),x=Math.max(y,C),E=w+","+x;h[E]===void 0?h[E]={index1:w,index2:x,face1:m,face2:void 0}:h[E].face2=m}}for(const u in h){const f=h[u];if(f.face2!==void 0){const y=a[f.face1].normal,C=a[f.face2].normal;if(y.dot(C)>l)continue}const m=n[f.index1],b=n[f.index2];(!d&&m>65535||b>65535)&&(d=!0),o.push(m),o.push(b)}return d?new Uint32Array(o):new Uint16Array(o)}static buildBarycentrics(t){const e=t.getAttribute("position");if(!e||e.count===0)return console.warn(" no positions in geometry!"),!1;const i=4,s=Math.pow(10,i),n=Math.cos(p.MathUtils.DEG2RAD*20),r=t.getIndex(),a=r?r.count:e.count,o=[0,0,0],l=new Array(3),h=zn.length,d=[];for(let T=0;T<e.count;T++)d.push({point:new p.Vector3(1,1,1),inited:!1,barycentricIndex:-1});const u={},f={},m={},b={};for(let T=0;T<a;T+=3){r?(o[0]=r.getX(T),o[1]=r.getX(T+1),o[2]=r.getX(T+2)):(o[0]=T,o[1]=T+1,o[2]=T+2);const{a:_,b:A,c:I}=ua;if(_.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),ua.getNormal(as),m[o[0]]?l[0]=m[o[0]]:(l[0]=Math.round(_.x*s)+","+Math.round(_.y*s)+","+Math.round(_.z*s),m[o[0]]=l[0]),m[o[1]]?l[1]=m[o[1]]:(l[1]=Math.round(A.x*s)+","+Math.round(A.y*s)+","+Math.round(A.z*s),m[o[1]]=l[1]),m[o[2]]?l[2]=m[o[2]]:(l[2]=Math.round(I.x*s)+","+Math.round(I.y*s)+","+Math.round(I.z*s),m[o[2]]=l[2]),l[0]===l[1]||l[1]===l[2]||l[2]===l[0]){P.warn(" skip degenerate triangles in geometry!");continue}const B={a:o[0],b:o[1],c:o[2]};!f[o[0]]&&(f[o[0]]=[]),f[o[0]].push(B),!f[o[1]]&&(f[o[1]]=[]),f[o[1]].push(B),!f[o[2]]&&(f[o[2]]=[]),f[o[2]].push(B);for(let k=0;k<3;k++){const L=(k+1)%3,F=l[k],ie=l[L],se=o[k],Fe=o[L];!u[se]&&(u[se]=new Set),u[se].add(Fe),!u[Fe]&&(u[Fe]=new Set),u[Fe].add(se);const ht=F+"_"+ie,Me=ie+"_"+F;if(Me in b&&b[Me]){if(b[Me].outer){P.warn("[Edge] edge: "+Me+" is already outer!");continue}as.dot(b[Me].normal)<=n?b[Me].outer=!0:b[Me].find=!0}else ht in b?P.warn("[Edge] "+ht+" has existed in geometry!"):b[ht]={startIndex:se,endIndex:Fe,normal:as.clone(),outer:!1,find:!1}}}for(const T in b)b[T]&&!b[T].find&&!b[T].outer&&(b[T].outer=!0);const y=[],C=[];for(const T in f)C.push(f[T]);let w=new Set;for(const T of C[0])w.add(T.a),w.add(T.b),w.add(T.c);let x=0;for(C.splice(x,1);;){let T=!1;for(let _=0;_<C.length&&!T;_++)for(const A of C[_])if(w.has(A.a)||w.has(A.b)||w.has(A.c)){x=_,T=!0;break}if(T){for(const _ of C[x])w.add(_.a),w.add(_.b),w.add(_.c);if(C.splice(x,1),x=0,C.length===0){y.push(w);break}}else if(!T)if(y.push(w),C.length>0){w=new Set;for(const _ of C[x])w.add(_.a),w.add(_.b),w.add(_.c);C.splice(x,1),x=0}else break}const E=new Set;for(let T=0;T<y.length;T++)y[T].forEach(A=>{E.has(A)?P.warn("[Edge] "+A+" is already in positionIndexSet!"):E.add(A)});const M=(T,_)=>{let A=!1;const I=m[T];if(!I)return console.warn(T+" is not in positionIndexHash!"),A;const B=m[_];if(!B)return console.warn(_+" is not in positionIndexHash!"),A;const k=I+"_"+B;if(b[k])A=b[k].outer;else{const L=B+"_"+I;b[L]&&(A=b[L].outer)}return A},O=(T,_,A)=>{const I=[];return I.push(M(T,_)),I.push(M(_,A)),I.push(M(A,T)),I.filter(B=>B===!0).length>=2},S=(T,_)=>{if(!u[T])return P.warn("[Edge] "+T+" position isn't used!"),!0;const A=u[T];for(const B of A){const k=M(T,B),L=d[B];if(!L.inited)continue;const F=Nh(_,L.point);if(k&&!F||!k&&F)return!1}const I=f[T];for(const B of I){const k=_;let L=d[B.b],F=d[B.c];if(B.b===T?L=d[B.a]:B.c===T&&(F=d[B.a]),O(B.a,B.b,B.c)&&(L.inited&&k.equals(L.point)||F.inited&&k.equals(F.point)))return!1;if(!(!L.inited||!F.inited)&&(Ot.addVectors(k,L.point),Ot.add(F.point),Ot.x+Ot.y+Ot.z<2))return!1}return!0};let v=!1;for(let T=0;T<y.length;T++){const _=Array.from(y[T]);v=!1;let A=0,I=0;for(;I>=0;){A=_[I];let B=d[A].inited?d[A].barycentricIndex+1:0;for(;B<h&&!S(A,zn[B]);B++);if(B<h)if(d[A].inited=!0,d[A].barycentricIndex=B,d[A].point.copy(zn[B]),I==_.length-1){v=!0,P.debug("[Edge]",d);break}else I++;else d[A].inited=!1,I--}if(!v){P.warn("[Edge] no result: "+_+"!");break}}if(v){const T=[];for(let A=0;A<d.length;A++){!d[A].inited&&P.warn("[Edge] "+A+" is not initialized !");let I=0;I|=d[A].point.x,I|=d[A].point.y<<1,I|=d[A].point.z<<2,T.push(I)}const _=new p.Uint8BufferAttribute(T,1,!1);t.setAttribute("barycentric",_)}else P.warn("[Edge] No suitable barycentric found!");return v}}class Nt{constructor(){g(this,"map");this.map=new Map}addEventListener(t,e){let i=this.map.get(t);i||(i=new Set,this.map.set(t,i)),i.add(e)}dispatchEvent(t,e={}){const i=this.map.get(t);if(!i)return;[...i].forEach(n=>n(e))}hasEventListener(t){return!!this.map.get(t)}removeEventListener(t,e){if(!t){this.map.clear();return}if(!e){this.map.delete(t);return}const i=this.map.get(t);i&&i.delete(e)}}const Z=class Z{static exportToGltf(t,e){Z.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){Z.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new Ol.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,r=>{if(i.binary){e=Z.addExtention(e,Z.EXTENSION_GLB);const a=r;Z.saveArrayBuffer(a,e)}else e=Z.addExtention(e,Z.EXTENSION_GLTF),Z.saveJson(r,e)},r=>console.log(r),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_OBJ);const i=new _l.OBJExporter,s=i.parse(t);Z.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_DRACO);const s=new El.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const r=s.parse(t,i);Z.saveArrayBuffer(r,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=Z.addExtention(e,Z.EXTENSION_STL);const s=new Pl.STLExporter;if(i){const n={binary:!0},r=s.parse(t,n);Z.saveDataView(r,e)}else{const n=s.parse(t);Z.saveString(n,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(Z.EXTENSION_JSON)||(e+=Z.EXTENSION_JSON),Z.saveJson(i,e)}static save(t,e){let i=Z.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),Z.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){Z.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){Z.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){Z.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){Z.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){Z.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};g(Z,"EXTENSION_GLTF",".gltf"),g(Z,"EXTENSION_GLB",".glb"),g(Z,"EXTENSION_OBJ",".obj"),g(Z,"EXTENSION_DRACO",".drc"),g(Z,"EXTENSION_JSON",".json"),g(Z,"EXTENSION_STL",".stl"),g(Z,"downloadLink");let yr=Z;class Gh{constructor(){g(this,"prevTime");g(this,"beginTime");g(this,"frames");g(this,"fps");this.prevTime=(performance||Date).now(),this.beginTime=(performance||Date).now(),this.frames=0,this.fps=Number.NaN}begin(){this.beginTime=(performance||Date).now()}end(){this.frames++;const t=(performance||Date).now();return t>=this.prevTime+1e3&&(this.fps=Math.round(this.frames*1e3/(t-this.prevTime)),this.frames=0,this.prevTime=t),t}update(){this.beginTime=this.end()}}const Vn=1e-15,fa=new p.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),pa=new p.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class z{static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static floorNumber(t,e){return Math.floor(t*Math.pow(10,e))/Math.pow(10,e)}static areNumbersEqual(t,e,i=1e-7){return Math.abs(t-e)<i*Math.max(1,Math.abs(t),Math.abs(e))}static areVector2sEqual(t,e,i=1e-7){return z.areNumbersEqual(t.x,e.x,i)&&z.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return z.areNumbersEqual(t.x,e.x,i)&&z.areNumbersEqual(t.y,e.y,i)&&z.areNumbersEqual(t.z,e.z,i)}static areNumbersClose(t,e,i=1e-9,s=1e-12){return Math.abs(t-e)<=Math.max(i*Math.max(Math.abs(t),Math.abs(e)),s)}static areVector2sClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)}static areVectorsClose(t,e,i=1e-9,s=1e-12){return this.areNumbersClose(t.x,e.x,i,s)&&this.areNumbersClose(t.y,e.y,i,s)&&this.areNumbersClose(t.z,e.z,i,s)}static getArcAngleSpanInRadian(t,e){const i=Math.PI*2;return z.areNumbersClose(t,e,Vn)?0:(t%=i,z.areNumbersClose(t,e%i,Vn)?i:(z.areNumbersClose(e,i,Vn)&&(e%=i),e<t&&(e+=i),e-t))}static getIntegerPartLength(t){return t=Math.abs(t),t<1?0:Math.ceil(Math.log10(Math.abs(t)+1))}static getRelativeEps(t,e=1e-7){const i=z.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(z.getRelativeEps(t.x,e),z.getRelativeEps(t.y,e))}static getControlPointByTwoPoints(t,e){const i=new p.Vector2().subVectors(e,t),s=i.angle(),n=i.length(),r=p.MathUtils.degToRad(45),a=n/2/Math.cos(r);return new p.Vector2(t.x+a*Math.cos(r-s),t.y-a*Math.sin(r-s))}static convertPointFromUEToGltf(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(fa.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(fa),e}static convertPointFromUEToRevit(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(pa.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(pa),e}static getBox(t,e){const i=[Math.min(t.x,e.x),Math.min(t.y,e.y),Math.min(t.z,e.z)],s=[Math.max(t.x,e.x),Math.max(t.y,e.y),Math.max(t.z,e.z)];return[...i,...s]}static getCenter(t){const e=new p.Vector3(t.min.x,t.min.y,t.min.z),i=new p.Vector3(t.max.x,t.max.y,t.max.z),s=new p.Vector3().addVectors(e,i).multiplyScalar(.5);return{x:s.x,y:s.y,z:s.z}}static convertBoxFromGltfToUE(t){const e=z.convertPointFromGltfToUE(t.min),i=z.convertPointFromGltfToUE(t.max);return z.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=z.convertPointFromUEToGltf(t.min),i=z.convertPointFromUEToGltf(t.max);return z.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=z.convertPointFromRevitToUE(t.min),i=z.convertPointFromRevitToUE(t.max);return z.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=z.convertPointFromUEToRevit(t.min),i=z.convertPointFromUEToRevit(t.max);return z.getBox(e,i)}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static getLookAtMatrix(t,e,i){const s=new p.Matrix4,n=new p.Vector3(t.x,t.y,t.z),r=new p.Vector3(e.x,e.y,e.z),a=new p.Vector3(i.x,i.y,i.z);s.lookAt(n,r,a),s.transpose();const o=[];return s.toArray(o),o}static getLocationFromMatrix(t){const e=new p.Vector3;return e.setFromMatrixPosition(t),e}static toDegrees(t){return p.MathUtils.radToDeg(t)}static toRadians(t){return p.MathUtils.degToRad(t)}static signNotZero(t){return t<0?-1:1}static fromSnorm(t,e){return z.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=z.fromSnorm(t.x,i),e.y=z.fromSnorm(t.y,i),e.z=1-(Math.abs(e.x)+Math.abs(e.y)),e.z<0){const s=e.x;e.x=(1-Math.abs(e.y))*z.signNotZero(s),e.y=(1-Math.abs(s))*z.signNotZero(e.y)}}}const jn=1e7,ma=new p.Box2,ga=new p.Box2,ya=new p.Vector3,xa=new p.Vector3,ba=new p.Vector3,Bt=new p.Triangle,qh=/not find (pre|next) vertex|has repeat vertex|translateLine line eror|not find Intersection/;function Wh(c){const t=console.error;console.error=(...e)=>{typeof e[0]=="string"&&qh.test(e[0])||t.apply(console,e)};try{return c()}finally{console.error=t}}class N{static geometriesEqual(t,e){return t===e?!0:t.type===e.type&&t.name===e.name&&t.morphTargetsRelative===e.morphTargetsRelative&&this.equal(t.boundingBox,e.boundingBox)&&this.equal(t.boundingSphere,e.boundingSphere)&&this.attributesEqual(t.attributes,e.attributes)&&this.bufferAttributesEqual(t.index,e.index)}static equal(t,e){return t===e||!t&&!e?!0:t&&e?t.equals(e):!1}static attributesEqual(t,e){if(t===e)return!0;const i=Object.keys(t).sort(),s=Object.keys(e).sort();if(i.length!==s.length)return!1;for(let n=0;n<i.length;++n){if(i[n]!==s[n])return!1;const r=t[i[n]],a=e[s[n]];if(!this.bufferAttributesEqual(r,a))return!1}return!0}static bufferAttributesEqual(t,e){if(t===e)return!0;if(!t||!e||!(t.name===e.name&&t.itemSize===e.itemSize&&t.count===e.count&&t.normalized===e.normalized))return!1;if(t.array&&e.array){if(t.array.length!==e.array.length)return!1;for(let r=0;r<t.array.length;++r)if(t.array[r]!==e.array[r])return!1}else if(t.array||e.array)return!1;const s=t.data,n=e.data;if(s&&n){if(s.length!==n.length)return!1;for(let r=0;r<s.length;++r)if(s[r]!==n[r])return!1}else if(s||n)return!1;return!0}static tryConvertInterleavedBufferAttributes(t){!t||!t.attributes||Object.keys(t.attributes).forEach(e=>{const i=t.attributes[e];if(i instanceof p.InterleavedBufferAttribute){const s=i.clone();t.attributes[e]=s}})}static isPointInPolygon(t,e,i=!1){const s=t.x,n=t.y;let r=!1;const a=e.length;for(let o=0,l=a-1;o<a;l=o++){const h=e[o].x,d=e[o].y,u=e[l].x,f=e[l].y;let m=d>n!=f>n;i&&(m=d>=n!=f>=n),m&&s<(u-h)*(n-d)/(f-d)+h&&(r=!r)}return r}static caculateGeometryCenter(t){if(!t.hasAttribute("position"))return null;const e=t.getAttribute("position");if(e.count===0)return null;const i=new p.Vector3,s=e.itemSize,n=e.array,r=[0,0,0];for(let a=0;a<e.count;a++)for(let o=0;o<s;o++)r[o]+=n[a*s+o];for(let a=0;a<s;a++)i.setComponent(a,r[a]/e.count);return i}static isConvex(t){const e=t.length;let i=0,s=0;const n=new p.Vector2,r=new p.Vector2;for(let a=0;a<e;++a){const o=t[a],l=t[(a+1)%e],h=t[(a+2)%e];if(n.subVectors(l,o),r.subVectors(h,l),s=n.cross(r),s!=0){if(s>0&&i<0||s<0&&i>0)return!1;i=s}}return!0}static areLineSegmentsIntersecting(t,e){const{start:i,end:s}=t,{start:n,end:r}=e,a=n.clone().sub(i),o=s.clone().sub(i),l=r.clone().sub(i),h=a.cross(o).dot(l.cross(o)),d=i.clone().sub(n),u=r.clone().sub(n),f=s.clone().sub(n),m=d.cross(u).dot(f.cross(u));return h<0&&m<0}static getLineSegmentsIntersectingPoint(t,e){const{start:i,end:s}=t,{start:n,end:r}=e,a=ya.subVectors(s,i).normalize(),o=xa.subVectors(r,n).normalize();if(a.dot(o)===1)return null;const l=ba.subVectors(n,i),h=a.clone().cross(o),d=l.clone().cross(o),u=l.clone().dot(h);if(u>=1e-5||u<=-1e-5)return null;const f=h.lengthSq();if(z.areNumbersEqual(0,f))return;const m=d.clone().dot(h)/f,b=i.clone().add(a.multiplyScalar(m));return b.equals(i)||b.equals(s)?null:b}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:n}=e,r=ya.subVectors(s,n).length(),a=xa.subVectors(t,s).length(),o=ba.subVectors(t,n).length();return Math.abs(r-(a+o))<=i}static isPointOnLineSegments(t,e,i=.001){let s=!1;for(let n=0;n<e.length-1;n+=2){const r=e[n],a=e[n+1];if(s=this.isPointOnLineSegment(t,{start:r,end:a},i),s)break}return s}static checkAndRebasePositionsOnRTC(t,e){if(t.length===0)return!1;const i=t[0]instanceof p.Vector3;t.forEach(n=>{i?e.add(n):(e.x+=n.x,e.y+=n.y)}),e.divideScalar(t.length);let s=!1;if(N.shouldRebasePositionOnRTC(e)){s=!0;for(let n=0;n<t.length;n++){const r=t[n].x-e.x,a=t[n].y-e.y;i?t[n]=new p.Vector3(r,a,t[n].z-e.z):t[n]=new p.Vector2(r,a)}}else e.setScalar(0);return s}static shouldRebasePositionOnRTC(t){return Math.abs(t.x)>jn||Math.abs(t.y)>jn||t instanceof p.Vector3&&Math.abs(t.z)>jn}static calculateSurfaceArea(t){let e=0;const i=t.getAttribute("position"),s=t.index;if(s)for(let n=0;n<s.count;n+=3)Bt.a.fromBufferAttribute(i,s.getX(n)),Bt.b.fromBufferAttribute(i,s.getX(n+1)),Bt.c.fromBufferAttribute(i,s.getX(n+2)),e+=Bt.getArea();else for(let n=0;n<i.count;n+=3)Bt.a.fromBufferAttribute(i,n),Bt.b.fromBufferAttribute(i,n+1),Bt.c.fromBufferAttribute(i,n+2),e+=Bt.getArea();return e}static convertLineStripToLine(t,e=!1){const i=t.getIndex();if(!i)return;const s=i.array.constructor,n=i.count;let r=n;n>2&&(r=e?n*2:n*2-2);const a=new s(r);let o=0;for(let l=0;l<n;l++){const h=i.getX(l);a[o++]=h,l>0&&l<n-1&&(a[o++]=h)}e&&(a[o++]=i.getX(n-1),a[o++]=i.getX(0)),t.setIndex(a)}static convertGeometryWithIndexedToNonIndexed(t){if(!t.index)return t;const e=new p.BufferGeometry,i=t.index;for(const s in t.attributes)e.setAttribute(s,N.createGeometryAttributeByIndex(t.attributes[s],i));return e}static createGeometryAttributeByIndex(t,e){const i=e.count,s=t.itemSize,n=t.array.constructor,r=new n(i*s);for(let a=0;a<i;a++){const o=e.getX(a),l=o*s;for(let h=0;h<s;h++)r[a*s+h]=t.array[l+h]}return new p.BufferAttribute(r,s,t.normalized)}static getLineEndPointsByIndex(t,e){const i=l=>{const h=t.geometry.attributes.position,d=h.array;return t.localToWorld(new p.Vector3(d[3*l],d[3*l+1],d[3*l+2]))};t.updateWorldMatrix(!0,!1);const s=t.geometry.getIndex()?.array||[],n=s[e]??e,r=s[e+1]??e+1,a=i(n),o=i(r);return[a,o]}static arePolygonsIntersect(t,e){if(t.length===0||e.length===0||(ma.setFromPoints(t),ga.setFromPoints(e),!ma.intersectsBox(ga)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&z.areVector2sEqual(t[i+1],t[i])&&++i,++i}return!1}static getLineLineIntersectionPoint(t,e,i,s,n=.001){const r=e.clone().sub(t).normalize(),a=s.clone().sub(i).normalize();if(Math.abs(r.dot(a))>1-n)return;const o=e.y-t.y,l=t.x-e.x,h=o*t.x+l*t.y,d=s.y-i.y,u=i.x-s.x,f=d*i.x+u*i.y,m=o*u-d*l;if(Math.abs(m)<n)return;const b=(u*h-l*f)/m,y=(o*f-d*h)/m;return new p.Vector2(b,y)}static getOffsetPoint(t,e,i){const s=e.x-t.x,n=e.y-t.y,r=Math.sqrt(s*s+n*n),a=i/r;return new p.Vector2(-a*n,a*s)}static convertSimpleWidthLineToMeshGeometry(t,e){let i,s=!1,n=!1,r=[],a=[],o,l,h=new p.Vector2,d=new p.Vector2,u=new p.Vector2,f=new p.Vector2;const m=[],b=e/2;for(let x=0,E=t.length-1;x<E;x++)s=!x,n=x===t.length-2,i=this.getOffsetPoint(t[x],t[x+1],b),h=new p.Vector2(t[x].x+i.x,t[x].y+i.y),d=new p.Vector2(t[x+1].x+i.x,t[x+1].y+i.y),u=new p.Vector2(t[x].x-i.x,t[x].y-i.y),f=new p.Vector2(t[x+1].x-i.x,t[x+1].y-i.y),s||(o=this.getLineLineIntersectionPoint(r[0],r[1],h,d),o!==void 0?m.unshift(o):m.unshift(h),l=this.getLineLineIntersectionPoint(a[0],a[1],u,f),l!==void 0?m.push(l):m.push(u)),s&&(m.unshift(h),m.push(u)),n&&(m.unshift(d),m.push(f)),n||(r=[h,d],a=[u,f]);if(m.length<3)return;const y=p.ShapeUtils.triangulateShape(m,[]),C=[];for(let x=0;x<y.length;x++)C.push(...y[x]);const w=new p.BufferGeometry().setFromPoints(m);return w.setIndex(C),w}static convertWidthLineToMeshGeometry(t,e){if(t.length<2)return;const i=[];t.forEach(s=>{i.push([s.x,s.y])});try{const{indices:s,position:n}=Wh(()=>Al.extrudePolylines([i],{lineWidth:e,depth:1})),r=new p.BufferGeometry;return r.setAttribute("position",new p.Float32BufferAttribute(n,3)),r.setIndex(Array.from(s)),r}catch{return}}static releaseGeometryManually(t){t.index=null,t.attributes={}}static getAdjacentNonRepeatPoints(t,e=1e-7){const i=[],s=t.length;for(let n=0;n<s-1;n++)z.areVector3sEqual(t[n],t[n+1],e)||i.push(t[n]);return i.push(t[s-1]),i}static mergeBBoxes(t){const e=[...t];if(e.length<2)return e;const i=[],s=[];for(let n=0;n<e.length;n++){const r=e[n];if(!s.includes(n)){for(let a=0;a<e.length;a++){const o=e[a];r.equals(o)||r.intersectsBox(o)&&(r.union(o),s.push(a))}i.push(r)}}return i}}const Po={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"},WebGL:{NotAvailable:"Unable to create a WebGL context in this browser/GPU environment, the drawing cannot be rendered. Please update the graphics driver, enable hardware acceleration in the browser, or switch to a WebGL-capable browser."}},Ao={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"},WebGL:{NotAvailable:"当前浏览器或显卡环境无法创建 WebGL 上下文,图纸无法渲染。请更新显卡驱动、开启浏览器硬件加速,或更换支持 WebGL 的浏览器后重试。"}},We=Il.createInstance(),Yh="cn";We.init({lng:Yh,debug:!1,resources:{en:{translation:Po},cn:{translation:Ao}}});class xe{static materialEquals(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t instanceof p.Material&&e instanceof p.Material){const i=t,s=e;return i.alphaTest===s.alphaTest&&i.opacity===s.opacity&&i.side===s.side&&i.visible===s.visible&&i.name===s.name&&i.transparent===s.transparent&&this.colorEquals(i.color,s.color)&&this.colorEquals(i.emissive,s.emissive)&&i.roughness===s.roughness&&i.metalness===s.metalness&&i.alphaMap===s.alphaMap&&i.uniforms===s.uniforms&&i.defines===s.defines&&i.vertexShader===s.vertexShader&&i.fragmentShader===s.fragmentShader&&i.clippingPlanes===s.clippingPlanes&&i.map===s.map&&i.clipIntersection===s.clipIntersection}return!1}static materialsEquals(t,e){if(t===e)return!0;if(Array.isArray(t)&&Array.isArray(e)&&t.length===e.length){for(let i=0;i<t.length;++i)if(!this.materialEquals(t[i],e[i]))return!1;return!0}else if(t instanceof p.Material&&e instanceof p.Material)return this.materialEquals(t,e);return!1}static colorEquals(t,e){return t===e?!0:t instanceof p.Color&&e instanceof p.Color?t.equals(e):!1}static clonedHighlightMaterials(t,e={}){if(!t||!t.material)return;const i=t.material;if(Array.isArray(i)&&i.length>0){const s=[];return i.forEach(n=>{s.push(this.clonedHighlightMaterial(n,e))}),s}else{if(i instanceof p.Material)return this.clonedHighlightMaterial(i,e);console.warn("[MaterialUtils] Invalid material: "+i)}}static clonedHighlightMaterial(t,e={}){const{depthTest:i=void 0,highlightColor:s=new p.Color(Pr),opacity:n=.7}=e,r=t.clone();return this.setMaterialColor(r,s),r.opacity=n,r.transparent=!0,i!==void 0&&(r.depthTest=i,r.side=p.DoubleSide),r}static cloneMaterial(t){if(!t)return t;if(Array.isArray(t)){const e=[];return t.forEach(i=>{e.push(i.clone())}),e}return t.clone()}static getMaterialColor(t){let e=new p.Color(16777215);return t instanceof p.PointsMaterial||t instanceof p.LineBasicMaterial||t instanceof p.MeshBasicMaterial?e=t.color:t instanceof p.ShaderMaterial&&t.uniforms.u_color&&(e=t.uniforms.u_color.value),e}static setMaterialColor(t,e){const i=t;i.color?.set(e),i.emissive?.set(e),i.uniforms?.u_color&&i.uniforms.u_color.value.set(e)}static setMaterialOpacity(t,e){const i=t;i.transparent=!0,i.opacity=e,i.uniforms?.opacity&&(i.uniforms.opacity.value=e)}static cloneMaterials(t){const e=new Map,i=s=>{if(Array.isArray(s)){const n=[];return s.forEach(r=>{let a=e.get(r);a||(a=r.clone(),e.set(r,a)),n.push(a)}),n}if(s){let n=e.get(s);return n||(n=s.clone(),e.set(s,n)),n}return s};t.traverse(s=>{const n=s;n.material&&(n.material=i(n.material))})}}const Xh=new p.Vector3(0,1,0),Ze=class Ze{static resetObjectStyle(t){this.revertWireframeMode(t),this.revertObjectOpacity(t,[]),this.revertAppliedMaterialToObject(t),this.revertVisibleForFloors(t)}static resetObjectStyleById(t,e){const i=this.getObjectById(t,e);this.resetObjectStyle(i)}static setObjectOpacity(t,e=.3,i,s){const n=[],r=o=>{n.find(l=>l.id===o.id)||(n.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side}),o.opacity*=e,o.transparent=!0,o.side=p.DoubleSide)},a=o=>{const l=n.find(h=>h.id===o.id);if(!l){const h=o.clone();return n.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side,material:o,clonedMaterial:h}),h.opacity*=e,h.transparent=!0,h}return l.clonedMaterial};return t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof p.Mesh){const l=o;if(i||s){if(Array.isArray(l.material)){const h=[];l.material.forEach(d=>{const u=a(d);u&&h.push(u)}),l.material=h}else if(l.material){const h=a(l.material);h&&(l.material=h)}}else if(Array.isArray(l.material))l.material.forEach(h=>{r(h)});else if(l.material){const h=l.material;r(h)}}}),n}static revertObjectOpacity(t,e,i,s){const n=new Set,r=o=>{if(!o||o.id==null||n.has(o.id))return;n.add(o.id);const l=e.find(h=>h.id===o.id);l&&(o.opacity=l.opacity,o.transparent=l.transparent,o.side=l.side,o.opacity===0&&P.warn("[ObjectUtils] Material '"+o.name+"'s opacity is 0, you may not be able to see your objects!"))},a=o=>{const l=e.find(h=>h.clonedMaterial&&h.clonedMaterial.id===o.id);if(l)return l.material};t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof p.Mesh){if(Array.isArray(o.material)){const l=[];o.material.forEach(h=>{const d=a(h);d?l.push(d):r(h)}),o.material=l}else if(o.material){const l=a(o.material);l?o.material=l:r(o.material)}}})}static setObjectOpacityById(t,e,i=.3,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);return Ze.setObjectOpacity(r,i,s,n)}static revertObjectOpacityById(t,e,i,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);Ze.revertObjectOpacity(r,i,s,n)}static applyMaterialToObject(t,e,i,s){t.traverse(n=>{s&&s.indexOf(n.id)!==-1||i&&i.indexOf(n.id)===-1||n instanceof p.Mesh&&(n.userData.originalMaterial||(n.userData.originalMaterial=n.material),n.material=e)})}static revertAppliedMaterialToObject(t,e,i){t.traverse(s=>{i&&i.indexOf(s.id)!==-1||e&&e.indexOf(s.id)===-1||s.userData.originalMaterial&&(s.material=s.userData.originalMaterial,s.userData.originalMaterial=void 0)})}static applyMaterialToObjectById(t,e,i,s,n){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);this.applyMaterialToObject(r,i,s,n)}static revertAppliedMaterialToObjectById(t,e,i,s){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);this.revertAppliedMaterialToObject(n,i,s)}static applyOpacityMaterialToObject(t,e,i){const s=new p.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});this.applyMaterialToObject(t,s,e,i)}static setDoubleSidedMaterialToObject(t){const e=i=>{i.side!==p.DoubleSide&&(i.userData.originalSide==null&&(i.userData.originalSide=i.side),i.side=p.DoubleSide)};t.traverse(i=>{i instanceof p.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof p.Material&&e(i.material))})}static revertDoubleSidedMaterialToObject(t){const e=i=>{i.userData.originalSide!=null&&(i.side=i.userData.originalSide,i.userData.originalSide=void 0)};t.traverse(i=>{i instanceof p.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof p.Material&&e(i.material))})}static setWireframeMode(t){const e=new p.MeshBasicMaterial({color:16732160,wireframe:!0,transparent:!0,opacity:.8});t.traverseVisible(i=>{if(i instanceof p.Mesh){const s=i;s.userData.materialForWireframe=s.material,s.material=e}})}static setWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);Ze.setWireframeMode(i)}static revertWireframeMode(t){t.traverseVisible(e=>{e instanceof p.Mesh&&e.userData.materialForWireframe&&(e.material=e.userData.materialForWireframe,e.userData.materialForWireframe=void 0)})}static revertWireframeModeById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);Ze.revertWireframeMode(i)}static findInner(t,e,i=[],s=!1){const n=e.toLowerCase(),r=[],a=h=>h.toLowerCase().indexOf(n)!==-1,o=h=>h.toString().indexOf(n)!==-1,l=h=>{if(h.name&&h.name.toLowerCase().indexOf(n)!==-1)return!0;if(h.gltfExtensions){const d=h.gltfExtensions,u=d.objectId&&d.objectId.Value||d.elementId&&d.elementId.Value;if(u&&u.toLowerCase().indexOf(n)!==-1)return!0}return!1};if(i.length>0)for(let h=0;h<i.length;++h){const d=i[h],u=t.getObjectById(d);if(u&&u.traverse(f=>{(a(f.name)||o(f.id)||l(f.userData))&&r.push(f)}),s&&r.length>0)return[r[0]]}else if(t.traverse(h=>{(a(h.name)||o(h.id)||l(h.userData))&&r.push(h)}),s&&r.length>0)return[r[0]];return r}static find(t,e,i=[],s=!1){return this.findInner(t,e,i,s)}static findFirst(t,e,i=[],s=!1){const n=this.findInner(t,e,i,s);if(n.length>0)return n[0]}static getFloorsFromString(t){const e=[],s=new RegExp(/(?:-?(?:\d+(?:\.5)?)F)(?=\W|$)/,"g").exec(t);return s&&s.length>0&&s.forEach(n=>{if(n){const r=n.replace("F",""),a=Number(r);a?e.push(a):console.log("[OU] invalid floor: "+n)}}),e}static matchFloor(t,e){return this.getFloorsFromString(t).findIndex(n=>n===e)!==-1}static matchFloors(t,e){return this.getFloorsFromString(t).findIndex(n=>e.findIndex(a=>a===n)!==-1)!==-1}static distinctFloors(t,e){const i=[],s=n=>{this.getFloorsFromString(n).forEach(a=>{i[a]=!0})};return e.forEach(n=>{const r=t.getObjectById(n);r&&r.traverse(a=>{if(s(a.name),a.userData.gltfExtensions){const o=a.userData.gltfExtensions;o.level&&o.level.Value&&s(o.level.Value)}})}),Object.keys(i).sort()}static traverseObjectByFloors(t,e,i,s,n){const r=t.getObjectById(e);if(!r)return[];r.traverse(a=>{let o=this.matchFloors(a.name,i);if(!o&&a.userData&&a.userData.gltfExtensions){const l=a.userData.gltfExtensions;l.level&&l.level.Value&&(o=this.matchFloors(l.level.Value,i))}o&&s&&s(a),!o&&n&&n(a)})}static setVisibleForFloors(t,e,i,s=!0){this.traverseObjectByFloors(t,e,i,n=>{let r=n;for(;r;)r.visible=!0,r=r.parent||void 0},n=>{s&&(n.visible=!1)})}static revertVisibleForFloors(t){t.traverse(e=>{e.visible=!0})}static revertVisibleForFloorsById(t,e){const i=this.getObjectById(t,e);this.revertVisibleForFloors(i)}static getObjectById(t,e){const i=t.getObjectById(e);if(!i)throw new Error("Failed to find object by id: "+e);return i}static async createOutlines(t,e={onlyVisible:!0,meshOnly:!0},i){if(!t)return[];if(t.children.length===0&&(e.onlyVisible&&!t.visible||e.meshOnly&&!(t instanceof p.Mesh)))return[];const s=[],n=t,r=n.children.length,a=Math.round(Math.pow(r,.5)),o=j.getUpdateProgressFuncAsync(i);for(let l=r-1;l>=0;--l){const h=r-l-1;let d;if(i&&(h%a===0||h===0||h===r-1)){const m=h*90/r,b=(h+1)*90/r;d=j.getUpdateSubProgressFunc(m,b,i)}const u=n.children[l],f=await this.createOutlines(u,e,d);s.push(...f)}if(!n.geometry)return await o(100),s;if(n instanceof p.Mesh&&!this.hasOutline(n,!1)){await o(50);const l=this.createOutline(n.geometry);n.add(l),l.updateWorldMatrix(!0,!1),s.push(l)}return await o(100),s}static removeOutlines(t){if(!(!t||!Array.isArray(t.children)))for(let e=t.children.length-1;e>=0;--e){const i=t.children[e];i.children.length>0&&this.removeOutlines(i),i.userData.isOutline&&t.remove(i)}}static hasOutline(t,e=!0){let i=!1;for(let s=0;s<t.children.length;++s){const n=t.children[s];if(n.userData.isOutline){i=!0;break}if(e&&n.children.length>0&&(i=this.hasOutline(n),i))break}return i}static setOutlinesVisibility(t,e){t.traverse(i=>{i.userData.isOutline&&(i.visible=e)})}static createOutline(t,e=this.OUTLINE_MATERIAL,i){const s=new p.EdgesGeometry(t,Ir),n=new p.LineSegments(s,e);return n.layers.enableAll(),Ze.disableLayerChannels(n,[Ut,je]),n.userData.isOutline=!0,n.matrixAutoUpdate=ct,i&&n.applyMatrix4(i),n}static cloneObject(t,e=!0){const i=t.clone();return e&&i.traverse(s=>{if(s instanceof p.Mesh||s instanceof p.Line){const n=s;n.material=xe.cloneMaterial(n.material)}}),i}static createBox(t,e,i,s=this.BOX_FACE_MATERIAL,n=!0){const r=[],a=(h,d,u)=>{r.push(new p.Vector3(h,d,u))};a(0,0,0),a(t,0,0),a(t,e,0),a(0,e,0),a(0,0,i),a(t,0,i),a(t,e,i),a(0,e,i);const o=new p.BufferGeometry;o.setFromPoints(r);const l=[0,3,2,0,2,1,4,6,7,4,5,6,0,7,3,0,4,7,3,6,2,3,7,6,1,6,5,1,2,6];return n&&l.push(0,5,4,0,1,5),o.setIndex(l),o.computeVertexNormals(),new p.Mesh(o,s)}static rebaseObjectOnRTC(t){const e=t;if(!(e.isMesh||e.isLine||e.isPoints)||!e.geometry||!(e.geometry instanceof p.BufferGeometry))return t;const i=e.geometry;if(!i.hasAttribute("position"))return t;const s=i.getAttribute("position");if(s.count===0)return t;const n=s.itemSize,r=s.array,a=[];for(let h=0;h<n;h++)a.push(r[h]);for(let h=0;h<s.count;h++)for(let d=0;d<n;d++)r[h*n+d]-=a[d];t.updateMatrix();const o=t.matrix.clone();t.matrix.makeTranslation(a[0],a[1],a.length>2?a[2]:0);const l=t.matrixAutoUpdate;return t.matrixAutoUpdate=!1,t.applyMatrix4(o),t.matrixAutoUpdate=l,t}static isEmptyObject(t){if(t.children.length===0){const i=t.geometry;if(!i||!i.hasAttribute("position")||i.getAttribute("position").count===0)return!0}return!1}static removeEmptyObjects(t){for(let e=0;e<t.children.length;)this.removeEmptyObjects(t.children[e])||++e;return this.isEmptyObject(t)?(t.removeFromParent(),!0):!1}static removeEmptyObjectsFromRemovingObjects(t,e){t.length!==0&&(t.forEach(i=>{i.removeFromParent()}),this.removeEmptyObjects(e))}static setSharedVariablesOfObject(t){t.uuid="",t.up=Xh;const e=t;e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.uuid&&(i.uuid="")}):e.material.uuid&&(e.material.uuid=""))}static isLeafObject(t){return!(t instanceof p.Mesh)&&!(t instanceof p.Line)&&!(t instanceof p.Points)?!1:!!t.geometry}static enableLayerChannels(t,e,i=!0){for(let s=0,n=e.length;s<n;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Ze.enableLayerChannels(s[n],e,!0)}}static disableLayerChannels(t,e,i=!0){for(let s=0,n=e.length;s<n;s++)t.layers.disable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Ze.disableLayerChannels(s[n],e,!0)}}static setLayerChannels(t,e,i=!0){t.layers.disableAll();for(let s=0,n=e.length;s<n;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let n=0,r=s.length;n<r;n++)Ze.setLayerChannels(s[n],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(Eo)}static isObjectSnapable(t){return t.layers.isEnabled(je)}static isObjectSelectable(t){return t.layers.isEnabled(Ut)}};g(Ze,"OUTLINE_MATERIAL",new p.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),g(Ze,"BOX_FACE_MATERIAL",new p.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:p.FrontSide}));let J=Ze;const Hs=new p.Matrix4,Zh=new p.Matrix4,ds=class ds{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},n=[];for(let h=0;h<i;++h){const d=t.children[h];if(d.children.length>0){this.mergeInner(d,e);continue}if(d.isInstancedMesh||!d.geometry||!(d.geometry instanceof p.BufferGeometry))continue;let u=!1;const f=Object.values(s);for(let m=f.length-1;m>=0;--m){const b=f[m].indexes[0];if(u=this.tryHandleMergeableObjects(t,h,b,s,n),u)break}for(let m=n.length-1;!u&&m>=0;--m){const b=n[m];if(u=this.tryHandleMergeableObjects(t,h,b,s,n),u)break}!u&&n.push(h)}if(Object.keys(s).length<=0)return;const r=[],a=[],o=[],l=[];Object.values(s).forEach(h=>{const d=h.indexes,u=t.children[d[0]];let f=[],m=0,b=0,y=0;const C=[];if(d.forEach(x=>{const E=t.children[x],M=E.geometry.clone();if(M.applyMatrix4(E.matrix),N.tryConvertInterleavedBufferAttributes(M),M.userData.isLineSegments=E.isLineSegments===!0,f.push(M),e){const O=E.name,S=M.attributes?.position?.count,v=M.index?.count||0,T={batchId:m,name:O,positionStart:b,positionCount:S,indexStart:y,indexCount:v};Object.keys(E.userData).length!==0&&(T.userData=E.userData),C.push(T),b+=S,y+=v,m++}}),f.length===0)return;let w;if(u.isMesh){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new p.Mesh(x,u.material),r.push(w)}else if(u.isLine){const x=this.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,C);if(!x)return;w=new p.LineSegments(x,u.material),a.push(w)}else if(u.isPoints){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new p.Points(x,u.material),o.push(w)}w&&(e?w.userData.batches=C:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.matrixAutoUpdate=ct,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,w.visible=u.visible,l.push(...d)),f.forEach(x=>{x.dispose(),N.releaseGeometryManually(x)}),f=[]}),l.sort((h,d)=>d-h),l.forEach(h=>{const d=t.children[h];t.remove(d)}),[...r,...a,...o].forEach(h=>{t.add(h)}),t.updateMatrix(),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=r.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,n){let r=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return r;const l=a?t[e]:t.children[e],h=a?t[i]:t.children[i];return this.areObjectsMergeable(l,h)&&this.areGeometriesMergeable(l.geometry,h.geometry)&&xe.materialsEquals(l.material,h.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(n,i)),s[i].indexes.push(e),r=!0),r}static deepMerge(t,e=void 0,i=!0,s=!0,n=!0){const r={added:[],removed:[]};if(t.length<=1)return r;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){const C=t[y];if(C.isInstancedMesh||!C.geometry||!(C.geometry instanceof p.BufferGeometry))continue;let w=!1;const x=Object.values(o);for(let E=x.length-1;E>=0;--E){const M=x[E].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let E=l.length-1;!w&&E>=0;--E){const M=l[E];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}!w&&l.push(y)}if(Object.keys(o).length<=0)return r;P.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const h=[],d=[],u=[],f=[];Object.values(o).forEach(y=>{const C=y.indexes;if(C.length<2)return;const w=t[C[0]];let x=[],E=0,M=0,O=0;const S=[];if(C.forEach(T=>{const _=t[T],A=_.geometry.clone();if(w.material instanceof p.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,_,e),A.userData.isLineSegments=_.isLineSegments===!0,x.push(A),n){const I=_.name,B=A.attributes?.position?.count,k=A.index?.count||0;let L;w.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),L=A.boundingSphere.clone());const F={batchId:E,name:I,positionStart:M,positionCount:B,indexStart:O,indexCount:k,boundingSphere:L};!_.parent.geometry&&Object.keys(_.parent.userData).length!==0&&(F.parentUserData=_.parent.userData),Object.keys(_.userData).length!==0&&(F.userData=_.userData),S.push(F),M+=B,O+=k,E++}}),x.length===0)return;let v;if(w.isMesh){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new p.Mesh(T,w.material),h.push(v)}else if(w.isLine){const T=this.mergeLineGeometries(x,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,S);if(!T)return;v=new p.LineSegments(T,w.material),d.push(v)}else if(w.isPoints){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new p.Points(T,w.material),u.push(v)}v&&(n?v.userData.batches=S:(v.userData=w.userData,v.userData.batches=void 0),v.userData.layerName=w.userData.layerName,v.name="[Merged] "+w.name,v.matrixAutoUpdate=ct,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,v.visible=w.visible,C.forEach(T=>f.push(T))),x.forEach(T=>{T.dispose(),N.releaseGeometryManually(T)}),x=[]}),P.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(y=>{const C=t[y];m.push(C),i&&C.removeFromParent()});const b=r.added;return[...h,...d,...u].forEach(y=>{b.push(y),i&&e&&(e.add(y),y.updateWorldMatrix(!1,!1))}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&J.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Hs.identity();s&&s!==i&&(Hs.premultiply(s.matrix),!!s.parent);)s=s.parent;return Hs.equals(Zh)?t:t.applyMatrix4(Hs)}static mergeLineGeometries(t,e,i,s){let n;if(i)n=ds.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(n=Pe.mergeGeometries(t),!n)return;n.userData={};const r=[];let a=0;t.forEach((o,l)=>{const h=o.attributes.position;if(!h)return;const d=o.index,u=o.userData.isLineSegments===!0,f=r.length;if(d)for(let m=0;m<d.count;m++){const b=d.array[m];u?r.push(a+b):m>0&&r.push(a+d.array[m-1],a+b)}else for(let m=0;m<h.count;m++)m>0&&(u?m%2===1&&r.push(a+m-1,a+m):r.push(a+m-1,a+m));a+=h.count,e&&s&&(s[l].indexStart=f,s[l].indexCount=r.length-f)}),n.setIndex(r)}return n}static mergeBufferGeometriesWithLinesToLineSegments(t,e,i){const s=new Set(Object.keys(t[0].attributes)),n={},r=new p.BufferGeometry,a=[];let o=0;for(let l=0;l<t.length;++l){let h=t[l];const d=h.userData.isLineSegments===!0;a.push(d),h.index&&(P.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),h=N.convertGeometryWithIndexedToNonIndexed(h));let u=0;for(const f in h.attributes){if(!s.has(f))return P.error("[Merge] mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure "+f+" attribute exists among all geometries, or in none of them"),void 0;!n[f]&&(n[f]=[]),n[f].push(h.attributes[f]),u++}if(u!==s.size)return P.error("[Merge] mergeGeometries() failed with geometry at index "+l+". Make sure all geometries have the same number of attributes."),void 0;if(e&&i){const f=h.attributes.position;i[l].indexStart=0,i[l].indexCount=0;const m=d?f.count:f.count*2-2;i[l].positionStart=o,i[l].positionCount=m,o+=m}}for(const l in n){const h=ds.mergeBufferAttributesWithLinesToLineSegments(n[l],a);if(!h)return P.error("[Merge] mergeGeometries() failed while trying to merge the "+l+" attribute."),void 0;r.setAttribute(l,h)}return r}static mergeBufferAttributesWithLinesToLineSegments(t,e){let i,s,n,r=0;for(let l=0;l<t.length;++l){const h=t[l];if(i===void 0&&(i=h.array.constructor),i!==h.array.constructor)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes."),void 0;if(s===void 0&&(s=h.itemSize),s!==h.itemSize)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes."),void 0;if(n===void 0&&(n=h.normalized),n!==h.normalized)return P.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes."),void 0;const d=e[l],u=d?0:h.count-2,f=h.count+u;r+=f*s}const a=new i(r);let o=0;for(let l=0;l<t.length;++l){const h=e[l],d=t[l],u=h?0:d.count-2,f=d.count+u,m=d.itemSize,b=new i(f*m);let y=0;for(let C=0;C<d.count;C++){const w=C*m,x=C!==0&&C!==d.count-1&&!h;for(let E=0;E<m;E++)b[y+E]=d.array[w+E],x&&(b[y+m+E]=d.array[w+E]);y+=x?2*m:m}a.set(b,o),o+=f*m}return new p.BufferAttribute(a,s,n)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static removeObjectFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areGeometriesMergeable(t,e){if(!t||!e||t.type==="InstancedBufferGeometry"||e.type==="InstancedBufferGeometry"||!!t.index!=!!e.index)return!1;const i=Object.keys(t.attributes);if(i.length!==Object.keys(e.attributes).length)return!1;for(const s of i)if(!e.attributes[s])return!1;return!0}static areObjectsMergeable(t,e){if(t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.visible!==e.visible||t.userData.layerName!==e.userData.layerName)return!1;if(t.type===e.type)return!0;const i=t,s=e;return i.isMesh&&s.isMesh||i.isLine&&s.isLine||i.isPoints&&s.isPoints}static isMergedMesh(t){return!!(t&&t.userData.batches)}static isFaceIndexInBatch(t,e,i){if(t.boundsTree){const s=t.index,n=s.getX(i*3);if(n>=e.positionStart&&n<e.positionStart+e.positionCount)return!0}else if(t.index){const s=e.indexStart/3,n=(e.indexStart+e.indexCount)/3-1;if(i>=s&&i<=n)return!0}else{const s=i*3;if(s>=e.positionStart&&s<e.positionStart+e.positionCount)return!0}return!1}static getBatchByFaceIndex(t,e){if(e<0)return P.error("[Merge]: Invalid faceIndex: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const n=i[s];if(this.isFaceIndexInBatch(t.geometry,n,e))return n}}static getBatchByLineIndex(t,e){if(e<0)return P.error("[Merge]: Invalid index: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(!i)return;const s=t.geometry,n=s.index;for(let r=0;r<i.length;++r){const a=i[r];if(n){if(e>=a.indexStart&&e<a.indexStart+a.indexCount)return a}else if(e>=a.positionStart&&e<a.positionStart+a.positionCount)return a}}static getBatchIdByFaceIndex(t,e){const i=this.getBatchByFaceIndex(t,e);return i?i.batchId:-1}static getBatchByBatchId(t,e){const i=t&&t.geometry&&t.userData.batches;if(i)for(let s=0;s<i.length;++s){const n=i[s];if(n.batchId===e)return n}}static cloneGeometryForBatch(t,e){const i=t&&t.geometry;if(!i)return;const s=i.attributes.position,n=s?.array;let r=i.index?.array;if(!n||!r)return P.warn("[Merge]: Unexpected position: "+n+", or index: "+r+"!"),void 0;const a=new p.BufferGeometry,o=e.positionStart,l=e.positionStart+e.positionCount,h=i.attributes;for(const b in h){const y=h[b],C=y.itemSize,w=y.array.slice(o*C,l*C);a.setAttribute(b,new p.BufferAttribute(w,C,y.normalized))}if(i.boundsTree&&(r=i.userData.originalIndex,!r))return P.warn("[Merge] After building bvh, the original index data is not preserved !"),void 0;const d=e.indexStart,u=e.indexStart+e.indexCount,f=[];let m=0;for(let b=d;b<u&&b<r.length;++b)f[m++]=r[b]-e.positionStart;return a.setIndex(f),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};g(ds,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let fe=ds;const Kh=.01;class $h{static getFaces(t){const e=t.map(n=>n.toArray()).reduce((n,r)=>(n.push(...r),n),[]),i=[];return Bl.Earcut.triangulate(e,[],3).forEach(n=>i.push(n)),i}static arePointsCoplanar(t){if(t.length<4)return!0;const e=t[1].clone().sub(t[0]),s=t[2].clone().sub(t[0]).cross(e).normalize();for(let n=3;n<t.length;n++)if(t[n].clone().sub(t[0]).projectOnVector(s).length()>Kh)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return kl(e).length>0}}class _t{static getVisibleObjectBoundingBox(t){const e=new p.Box3;return t.traverse(i=>{i.visible&&(i instanceof p.Mesh||i instanceof p.Line)&&J.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new p.Box3;return e.forEach(n=>{const r=t.getObjectById(n);if(r){const a=_t.getBoundingBox(r,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new p.Box3;if(t instanceof p.InstancedMesh)return _t.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let n=1;s>20&&(n=3),s>100&&(n=5),s>200&&(n=10),s>1e3&&(n=100),t.updateMatrixWorld(!1);for(let r=0;r<s;++r){const a=t.children[r];if(!e||r%n===0)if(a.updateMatrix(),a instanceof p.InstancedMesh){const o=_t.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(j.isMatrixValid(a.matrixWorld)){const o=_t.getBoundingBox(a);o.isEmpty()||i.union(o)}else console.warn("[SceneUtils] Found object("+a.type+") with invalid matrix: "+a.matrixWorld.elements)}return t.geometry&&i.expandByObject(t),i}static getInstancedMeshBoundingBox(t){const e=new p.Box3,i=new p.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const n=t.geometry.clone();if(n.boundingBox){const r=n.boundingBox.applyMatrix4(i);!r.isEmpty()&&j.isBoxValid(r)&&e.union(r)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=_t.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class zt{static setMaterialSection(t,e,i=!1,s=!1){const n=i&&t.clippingPlanes?t.clippingPlanes:[];n.push(...e),t.clippingPlanes=n,t.clipIntersection=s}static removeSection(t){t&&t.traverse(e=>{const i=e.material;Array.isArray(i)?i.forEach(s=>{s.clippingPlanes=[]}):i&&(i.clippingPlanes=[])})}static addSection(t,e,i=!1,s=!1){t&&t.traverse(n=>{const r=n.material;Array.isArray(r)?r.forEach(a=>{zt.setMaterialSection(a,e,i,s)}):r&&zt.setMaterialSection(r,e,i,s)})}static generateSectionPlanesByBox(t){const e=t.min,i=t.max;return[new p.Plane(new p.Vector3(0,-1,0),i.y),new p.Plane(new p.Vector3(0,1,0),-e.y),new p.Plane(new p.Vector3(1,0,0),-e.x),new p.Plane(new p.Vector3(-1,0,0),i.x)]}static generateSectionPlanesByPoints(t,e=!0){const i=t.length;if(i<2)return;const s=[];for(let n=0;n<i-1;n++){const r=t[n],a=t[(n+1)%i],o=new p.Plane;o.setFromCoplanarPoints(new p.Vector3(r.x,r.y,-1),new p.Vector3(r.x,r.y,0),new p.Vector3(a.x,a.y,0)),e||o.negate(),s.push(o)}return s}}class Jh{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new Dl.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof p.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const Qh=10;var Et=(c=>(c.TripleCross="TripleCross",c.Square="Square",c.Triangle="Triangle",c.CircleWithCross="CircleWithCross",c.Cross="Cross",c.Perpendicular="Perpendicular",c))(Et||{});class ed{static createSVGObject(t){return new Ll.SVGObject(t)}}class ms{static async createEnvTexture(t,e){const i=new Rl.RGBELoader;return new Promise(s=>{i.load(e,n=>{if(t){const r=t.fromEquirectangular(n).texture;t.dispose(),s(r)}})})}static async createEnvTextureFromDataArray(t,e=this.HDR_CITY_STREET_64x32,i=64,s=32){if(t){const n=new p.DataTexture(e,i,s);n.flipY=!0,n.magFilter=p.LinearFilter,n.minFilter=p.LinearFilter,n.type=p.HalfFloatType,n.version=1;const r=t.fromEquirectangular(n).texture;return t.dispose(),Promise.resolve(r)}return Promise.reject("Invalid pmremGenerator!")}}g(ms,"HDR_CITY_STREET_64x32",Uint16Array.from([11910,12340,12797,15360,11926,12348,12806,15360,11958,12364,12814,15360,11974,12380,12830,15360,11958,12364,12822,15360,11926,12348,12797,15360,11878,12324,12773,15360,11830,12308,12749,15360,11798,12292,12733,15360,11782,12279,12725,15360,11765,12263,12709,15360,11749,12247,12701,15360,11733,12231,12701,15360,11701,12215,12693,15360,11685,12199,12685,15360,11685,12199,12685,15360,11701,12215,12693,15360,11717,12231,12701,15360,11733,12247,12709,15360,11749,12263,12717,15360,11749,12279,12717,15360,11765,12279,12725,15360,11765,12279,12725,15360,11765,12292,12725,15360,11798,12300,12733,15360,11830,12316,12749,15360,11846,12324,12757,15360,11894,12340,12781,15360,11926,12356,12797,15360,11942,12356,12797,15360,11926,12348,12789,15360,11926,12348,12789,15360,11942,12356,12797,15360,11942,12356,12797,15360,11942,12348,12806,15360,11942,12356,12806,15360,11942,12356,12814,15360,11958,12372,12830,15360,11974,12372,12830,15360,11974,12372,12838,15360,11990,12388,12854,15360,12055,12420,12886,15360,12119,12452,12918,15360,12167,12476,12950,15360,12231,12500,12982,15360,12263,12516,12998,15360,12231,12500,12974,15360,12199,12484,12958,15360,12199,12484,12958,15360,12199,12492,12966,15360,12247,12508,12982,15360,12247,12508,12990,15360,12231,12500,12982,15360,12199,12484,12966,15360,12167,12468,12942,15360,12119,12444,12918,15360,12087,12436,12902,15360,12055,12420,12886,15360,12055,12412,12878,15360,12039,12412,12878,15360,12022,12396,12862,15360,12006,12388,12846,15360,11958,12364,12830,15360,11910,12340,12806,15360,12119,12508,13103,15360,12087,12484,13071,15360,12055,12468,13046,15360,12006,12436,13006,15360,11926,12396,12958,15360,11878,12364,12926,15360,11846,12348,12894,15360,11782,12308,12854,15360,11749,12292,12830,15360,11717,12263,12814,15360,11685,12247,12806,15360,11669,12215,12789,15360,11685,12231,12789,15360,11701,12247,12797,15360,11701,12247,12806,15360,11717,12263,12814,15360,11749,12292,12822,15360,11782,12308,12838,15360,11798,12316,12846,15360,11814,12332,12862,15360,11846,12340,12870,15360,11862,12348,12878,15360,11846,12340,12870,15360,11846,12340,12862,15360,11878,12356,12886,15360,11910,12372,12910,15360,11942,12396,12934,15360,11958,12412,12958,15360,12039,12452,12998,15360,12071,12468,13022,15360,12039,12452,12998,15360,12039,12452,12998,15360,12006,12444,13006,15360,11974,12436,12998,15360,11942,12412,12982,15360,11926,12396,12974,15360,11926,12404,12974,15360,11958,12420,12998,15360,12006,12452,13038,15360,12055,12476,13071,15360,12039,12476,13079,15360,12087,12508,13127,15360,12247,12597,13231,15360,12388,12693,13332,15360,12420,12741,13364,15360,12436,12757,13372,15360,12468,12773,13380,15360,12500,12806,13388,15360,12516,12822,13404,15360,12629,12934,13452,15360,12741,13046,13508,15360,12806,13095,13532,15360,12757,13046,13516,15360,12645,12950,13460,15360,12565,12870,13428,15360,12532,12838,13412,15360,12549,12854,13412,15360,12516,12838,13396,15360,12452,12757,13356,15360,12420,12725,13340,15360,12404,12709,13332,15360,12372,12677,13316,15360,12279,12589,13207,15360,12135,12516,13119,15360,12388,12709,13348,15360,12247,12581,13223,15360,12055,12476,13087,15360,11910,12388,12982,15360,11733,12308,12886,15360,11669,12247,12846,15360,11621,12199,12814,15360,11541,12103,12765,15360,11492,12055,12733,15360,11508,12055,12733,15360,11476,12022,12717,15360,11525,12055,12725,15360,11589,12135,12757,15360,11669,12199,12765,15360,11765,12292,12814,15360,11862,12348,12886,15360,11910,12372,12910,15360,12006,12420,12966,15360,12071,12452,12998,15360,12119,12476,13022,15360,12167,12492,13046,15360,12183,12500,13063,15360,12199,12524,13079,15360,12308,12589,13151,15360,12300,12581,13151,15360,12167,12516,13087,15360,12087,12468,13030,15360,12022,12444,13014,15360,11990,12420,12990,15360,11974,12420,12990,15360,11974,12420,12990,15360,11990,12436,13014,15360,11990,12444,13030,15360,12103,12500,13103,15360,12087,12508,13111,15360,12039,12484,13103,15360,12039,12476,13103,15360,11942,12436,13054,15360,11974,12452,13087,15360,12039,12492,13135,15360,12103,12532,13199,15360,12183,12581,13263,15360,12308,12661,13340,15360,12484,12822,13436,15360,12613,12918,13484,15360,12725,13046,13540,15360,13046,13332,13677,15360,13143,13380,13717,15360,13223,13420,13741,15360,13396,13540,13862,15360,13436,13589,13902,15360,13484,13629,13942,15360,13468,13621,13934,15360,13412,13564,13878,15360,13372,13524,13846,15360,13287,13452,13781,15360,13223,13428,13749,15360,13340,13492,13805,15360,13239,13428,13749,15360,13095,13364,13685,15360,12918,13223,13597,15360,12822,13111,13556,15360,12613,12934,13468,15360,12532,12854,13428,15360,12565,12870,13444,15360,12468,12789,13396,15360,12372,12693,13340,15360,12087,12492,13111,15360,11846,12364,12958,15360,11717,12300,12878,15360,11557,12135,12781,15360,11476,12055,12741,15360,11460,12022,12725,15360,11476,12022,12725,15360,11476,12022,12709,15360,11476,11958,12605,15360,11364,11733,12332,15360,11111,11412,11661,15360,11223,11476,11773,15360,11388,11669,12095,15360,11765,12119,12492,15360,12388,12613,13079,15360,12661,12902,13356,15360,12998,13255,13564,15360,13372,13508,13797,15360,13412,13548,13846,15360,13287,13436,13725,15360,13271,13428,13709,15360,13287,13428,13717,15360,13014,13287,13597,15360,12709,12998,13460,15360,12452,12741,13332,15360,12364,12653,13271,15360,12404,12693,13316,15360,12420,12709,13316,15360,12420,12709,13332,15360,12263,12589,13231,15360,12332,12661,13312,15360,12300,12629,13295,15360,12263,12605,13287,15360,12231,12597,13279,15360,12247,12613,13303,15360,12231,12597,13295,15360,12231,12605,13312,15360,12199,12597,13324,15360,12231,12613,13340,15360,12516,12870,13468,15360,12725,13063,13564,15360,12741,13079,13573,15360,12854,13175,13613,15360,12902,13223,13629,15360,13046,13348,13693,15360,13356,13516,13846,15360,13605,13765,14078,15360,13717,13870,14191,15360,13765,13918,14255,15360,13765,13910,14247,15360,13701,13854,14191,15360,13573,13733,14070,15360,13508,13677,14006,15360,13380,13548,13886,15360,13111,13380,13741,15360,13063,13348,13709,15360,12886,13207,13629,15360,12725,13046,13548,15360,12645,12966,13508,15360,12677,12982,13508,15360,12629,12950,13492,15360,12452,12789,13412,15360,12324,12661,13332,15360,12356,12677,13340,15360,12388,12693,13348,15360,12279,12597,13247,15360,11894,12396,12998,15360,11637,12231,12846,15360,11573,12135,12789,15360,11589,12151,12797,15360,11621,12167,12797,15360,11637,12119,12677,15360,11079,11404,11693,15360,10517,10701,10653,15360,10252,10348,10007,15360,9902,9999,9428,15360,9846,9886,9047,15360,10135,10260,9685,15360,10412,10533,10412,15360,11268,11436,11549,15360,12364,12605,13087,15360,12444,12709,13255,15360,12549,12822,13348,15360,12613,12886,13396,15360,12597,12886,13412,15360,12581,12870,13404,15360,12661,12950,13460,15360,12725,13014,13492,15360,13079,13332,13645,15360,12757,13046,13500,15360,12677,12982,13476,15360,12854,13143,13556,15360,12693,12982,13492,15360,12581,12886,13452,15360,12709,13030,13508,15360,12372,12709,13364,15360,12324,12661,13348,15360,12292,12645,13340,15360,12292,12645,13348,15360,12468,12806,13436,15360,12532,12854,13460,15360,12500,12854,13468,15360,12500,12854,13484,15360,12725,13063,13589,15360,12982,13324,13701,15360,13111,13388,13741,15360,13014,13340,13709,15360,13014,13332,13717,15360,13287,13476,13862,15360,13436,13621,13974,15360,13532,13717,14095,15360,13725,13902,14295,15360,13942,14103,14420,15360,13974,14135,14436,15360,13862,14022,14388,15360,13725,13894,14295,15360,13789,13958,14336,15360,13830,13990,14348,15360,13372,13548,13942,15360,13014,13332,13733,15360,12886,13239,13661,15360,12854,13207,13637,15360,12757,13095,13589,15360,12757,13079,13573,15360,12645,12982,13516,15360,12629,12966,13532,15360,12549,12870,13468,15360,12356,12693,13372,15360,12151,12549,13231,15360,12215,12573,13247,15360,12199,12565,13231,15360,12071,12492,13135,15360,12055,12468,13087,15360,11878,12372,12958,15360,11685,12199,12781,15360,10774,11159,11412,15360,9533,9621,8870,15360,9308,9340,8071,15360,9276,9300,7878,15360,9324,9332,8420,15360,9191,9216,7991,15360,8950,8983,7766,15360,9493,9525,8677,15360,10252,10332,10007,15360,10661,10846,10894,15360,10701,10926,10998,15360,10950,11276,11428,15360,11364,11637,12063,15360,11958,12388,12926,15360,12183,12540,13175,15360,12340,12645,13295,15360,12420,12693,13316,15360,12757,13030,13460,15360,13046,13324,13645,15360,13095,13348,13677,15360,13303,13460,13781,15360,13207,13404,13741,15360,13127,13372,13717,15360,13372,13524,13862,15360,12693,13030,13540,15360,12725,13046,13548,15360,12468,12822,13436,15360,12263,12629,13348,15360,12436,12773,13428,15360,12693,12998,13524,15360,12725,13046,13564,15360,12645,12982,13556,15360,12613,12966,13556,15360,12886,13255,13685,15360,13436,13629,14022,15360,13637,13813,14231,15360,13621,13789,14215,15360,13878,14038,14412,15360,14022,14183,14468,15360,13926,14119,14452,15360,14054,14231,14508,15360,14135,14311,14540,15360,14348,14436,14669,15360,14460,14540,14749,15360,14404,14484,14709,15360,14420,14500,14709,15360,14653,14717,14894,15360,14119,14279,14508,15360,13484,13669,14078,15360,13063,13380,13773,15360,12677,13079,13613,15360,12484,12886,13516,15360,12436,12822,13476,15360,12468,12838,13476,15360,12039,12532,13316,15360,12231,12613,13340,15360,12468,12789,13436,15360,12388,12725,13396,15360,12135,12557,13287,15360,12151,12557,13271,15360,12039,12484,13175,15360,11878,12396,13038,15360,11814,12348,12950,15360,11492,11894,12460,15360,9950,10103,9621,15360,8830,8838,7220,15360,8565,8533,7015,15360,8541,8501,6919,15360,8332,8300,6822,15360,8412,8372,7220,15360,8710,8701,7686,15360,9372,9404,8549,15360,9533,9621,9079,15360,9268,9292,8196,15360,9452,9460,8167,15360,9533,9581,8533,15360,9742,9870,9316,15360,11460,11814,12348,15360,11942,12388,12902,15360,11749,12167,12573,15360,11300,11492,11621,15360,11974,12332,12669,15360,12436,12741,13364,15360,12597,12886,13460,15360,12966,13271,13653,15360,12998,13303,13669,15360,13476,13629,13974,15360,13733,13886,14239,15360,13364,13524,13894,15360,13063,13356,13725,15360,12982,13287,13669,15360,12484,12806,13444,15360,12565,12902,13500,15360,12950,13287,13693,15360,12934,13271,13677,15360,12693,13046,13589,15360,12661,13030,13605,15360,12870,13271,13717,15360,13348,13548,13966,15360,13621,13813,14271,15360,13797,13974,14412,15360,13942,14119,14484,15360,14263,14388,14629,15360,14420,14508,14733,15360,14460,14548,14773,15360,14982,15046,15231,15360,15564,15580,15669,15360,15974,15982,16078,15360,15805,15821,15926,15360,15460,15476,15572,15360,15436,15460,15556,15360,14781,14862,15127,15360,13621,13813,14348,15360,12789,13207,13757,15360,12452,12886,13581,15360,12263,12709,13476,15360,12039,12597,13396,15360,11942,12516,13340,15360,11846,12468,13271,15360,11733,12380,13127,15360,11926,12460,13191,15360,12055,12524,13263,15360,11878,12428,13159,15360,11605,12231,12886,15360,11412,11990,12709,15360,11508,12103,12789,15360,11637,12231,12854,15360,10661,11079,11380,15360,9541,9685,9252,15360,8573,8605,7493,15360,8404,8388,7348,15360,8830,8822,8212,15360,9308,9324,9095,15360,9324,9364,9220,15360,9047,9119,8653,15360,9023,9055,8404,15360,9055,9063,8167,15360,8870,8846,7541,15360,8862,8806,7380,15360,8950,8910,7252,15360,9268,9284,7557,15360,10316,10468,10380,15360,11239,11476,11677,15360,10653,10942,11047,15360,9661,9814,9324,15360,10693,10958,11047,15360,11396,11653,11990,15360,11878,12292,12597,15360,12468,12789,13396,15360,12773,13095,13589,15360,13364,13516,13894,15360,13894,14054,14380,15360,13717,13870,14247,15360,13420,13589,13958,15360,13255,13452,13830,15360,12806,13143,13637,15360,13159,13412,13830,15360,13629,13813,14215,15360,13303,13500,13910,15360,13079,13396,13805,15360,13191,13452,13878,15360,13412,13621,14062,15360,14103,14279,14540,15360,14773,14854,15086,15360,14717,14805,15046,15360,14295,14420,14685,15360,14380,14476,14733,15360,14572,14661,14902,15360,15596,15612,15701,15360,16351,16335,16384,15360,16484,16476,16492,15360,16516,16500,16516,15360,16388,16375,16404,15360,16054,16054,16118,15360,15918,15926,16006,15360,15556,15572,15669,15360,14653,14725,14982,15360,13637,13838,14319,15360,13412,13613,14054,15360,12870,13287,13789,15360,12404,12838,13524,15360,12199,12677,13428,15360,12324,12741,13452,15360,11942,12516,13324,15360,11765,12380,13111,15360,11428,11942,12589,15360,10886,11388,11902,15360,10372,10717,11006,15360,9846,10240,10191,15360,10252,10549,10766,15360,10613,11079,11484,15360,10581,10998,11388,15360,9613,9846,9629,15360,8525,8557,7541,15360,8605,8613,7814,15360,9292,9324,9079,15360,9388,9396,9220,15360,10709,10846,11031,15360,9894,9966,9854,15360,9252,9236,8774,15360,8822,8790,8183,15360,8292,8260,6533,15360,8111,8007,6324,15360,8228,8183,6405,15360,8501,8501,6565,15360,8814,8878,7172,15360,9260,9364,8244,15360,8902,9095,8252,15360,9444,9581,9047,15360,9509,9637,8790,15360,9477,9613,8806,15360,10725,11063,11079,15360,11508,11910,12356,15360,12484,12789,13380,15360,12838,13159,13629,15360,13428,13589,13974,15360,14135,14279,14484,15360,13942,14087,14396,15360,13677,13846,14247,15360,13436,13613,14006,15360,13597,13781,14183,15360,14183,14340,14540,15360,14022,14215,14484,15360,13637,13838,14271,15360,14038,14231,14508,15360,14380,14476,14701,15360,14757,14854,15078,15360,15030,15111,15343,15360,15420,15452,15556,15360,15476,15500,15588,15360,15351,15388,15492,15360,15572,15596,15677,15360,15653,15669,15717,15360,15821,15821,15853,15360,15845,15845,15869,15360,15998,15990,16022,15360,15926,15926,15974,15360,15653,15669,15733,15360,15661,15677,15749,15360,15612,15629,15717,15360,15271,15335,15452,15360,14484,14572,14821,15360,14215,14372,14588,15360,13468,13677,14167,15360,12773,13175,13653,15360,12725,13143,13637,15360,12452,12886,13532,15360,12263,12709,13444,15360,11894,12436,13103,15360,10252,10533,10661,15360,8613,8693,7445,15360,8742,8782,7047,15360,8420,8412,6565,15360,7926,7910,6405,15360,8806,8854,7300,15360,9127,9228,8007,15360,8685,8750,7300,15360,8348,8356,6758,15360,8380,8340,7300,15360,8991,8918,8388,15360,9838,9790,9549,15360,10055,10127,10047,15360,9501,9493,9268,15360,9332,9292,8902,15360,9079,9007,8509,15360,8300,8260,7252,15360,8693,8701,8196,15360,8228,8212,7111,15360,8469,8501,7380,15360,8420,8501,6919,15360,8549,8645,6983,15360,8581,8661,6951,15360,9268,9332,7718,15360,9063,9207,7445,15360,9284,9380,7718,15360,9412,9557,8693,15360,10276,10517,10103,15360,11830,12279,12589,15360,12725,13079,13589,15360,13127,13396,13773,15360,14087,14231,14460,15360,13974,14119,14412,15360,13677,13854,14247,15360,14119,14279,14500,15360,13990,14167,14460,15360,14364,14452,14653,15360,14564,14653,14837,15360,14404,14492,14701,15360,14870,14942,15135,15360,15388,15420,15500,15360,15207,15287,15420,15360,14797,14894,15127,15360,15271,15335,15452,15360,15926,15942,15990,15360,16207,16207,16231,15360,16118,16110,16126,15360,15741,15733,15741,15360,16239,16207,16175,15360,16444,16460,16484,15360,16046,16022,16006,15360,15942,15950,15966,15360,15773,15789,15829,15360,15789,15797,15845,15360,15693,15709,15757,15360,15540,15564,15653,15360,15303,15364,15468,15360,14733,14813,15014,15360,13862,14054,14420,15360,12838,13255,13725,15360,12789,13207,13693,15360,12468,12918,13564,15360,12404,12838,13500,15360,11428,11862,12412,15360,9143,9276,8388,15360,8541,8533,6726,15360,8444,8428,6629,15360,8212,8183,6597,15360,8388,8380,7015,15360,8726,8710,6758,15360,8332,8316,6437,15360,8453,8428,6565,15360,8597,8605,7814,15360,8701,8661,8151,15360,9452,9396,9015,15360,10581,10557,10380,15360,10950,10974,10846,15360,10380,10356,10252,15360,10749,10741,10685,15360,9870,9854,9693,15360,9023,9039,8669,15360,8790,8854,8509,15360,8196,8167,7332,15360,7975,8015,7079,15360,8589,8750,7445,15360,9095,9260,7111,15360,8983,9135,7188,15360,8902,8991,7252,15360,8862,9007,7015,15360,8967,9111,7300,15360,8742,8878,7493,15360,9557,9999,9549,15360,11292,11613,11862,15360,12135,12468,12982,15360,12215,12460,12878,15360,13356,13468,13685,15360,13821,13934,14199,15360,13548,13701,14022,15360,14103,14263,14468,15360,14279,14388,14572,15360,14364,14452,14645,15360,14709,14789,14950,15360,15143,15199,15327,15360,15388,15412,15468,15360,15476,15500,15548,15360,15420,15444,15492,15360,15436,15460,15516,15360,15612,15637,15685,15360,16086,16086,16110,15360,16396,16388,16396,15360,16094,16094,16110,15360,15869,15861,15861,15360,16135,16110,16070,15360,16428,16420,16404,15360,15588,15556,15524,15360,15484,15500,15508,15360,15335,15364,15396,15360,15677,15685,15717,15360,15604,15621,15661,15360,15420,15444,15500,15360,15303,15372,15452,15360,14717,14805,14998,15360,14412,14508,14701,15360,13548,13765,14199,15360,13271,13508,13942,15360,12661,13159,13709,15360,12468,12854,13436,15360,10260,10484,10509,15360,8613,8669,6951,15360,8151,8143,6469,15360,8653,8629,7814,15360,8469,8444,7541,15360,8718,8693,7814,15360,8372,8332,6597,15360,8356,8308,7111,15360,9047,8983,8396,15360,8822,8798,8308,15360,9372,9348,8967,15360,10364,10364,10183,15360,10268,10260,9894,15360,10541,10533,10468,15360,10380,10364,10276,15360,10621,10613,10549,15360,9910,9942,9758,15360,8364,8380,7621,15360,8581,8637,8135,15360,8252,8300,7573,15360,8119,8175,7300,15360,8372,8453,7493,15360,8420,8501,6983,15360,8742,8822,7573,15360,8782,8854,8151,15360,8581,8661,7079,15360,9220,9268,8340,15360,9549,9645,8854,15360,11717,11950,12127,15360,12468,12741,13207,15360,12709,12966,13388,15360,12300,12508,12886,15360,12492,12709,13063,15360,13239,13372,13548,15360,12476,12597,12814,15360,13581,13685,13878,15360,14476,14548,14685,15360,14556,14629,14773,15360,14765,14829,14966,15360,15159,15207,15303,15360,15372,15396,15444,15360,15516,15532,15572,15360,15653,15661,15693,15360,15829,15837,15853,15360,16022,16014,16022,15360,16311,16295,16279,15360,16343,16319,16303,15360,16412,16388,16359,15360,15813,15797,15773,15360,13063,13151,13183,15360,11484,11701,11798,15360,12300,12412,12468,15360,14613,14637,14653,15360,11974,12215,12316,15360,14135,14215,14303,15360,15604,15629,15677,15360,15524,15548,15596,15360,15351,15380,15428,15360,14797,14894,15054,15360,13990,14231,14500,15360,13492,13709,14070,15360,12886,13316,13701,15360,12613,13207,13749,15360,11525,11974,12428,15360,9284,9412,8629,15360,8597,8653,6951,15360,7806,7790,6292,15360,7589,7541,6437,15360,7485,7437,6597,15360,7453,7404,6180,15360,7774,7686,6565,15360,8300,8260,7332,15360,9918,9942,9862,15360,10348,10372,10231,15360,9725,9709,9228,15360,10613,10621,10509,15360,10199,10175,9838,15360,10380,10388,10340,15360,11207,11255,11284,15360,10661,10717,10725,15360,10103,10135,9950,15360,8444,8436,7669,15360,8469,8501,7445,15360,8950,9111,8854,15360,9485,9798,10071,15360,8364,8501,8039,15360,7959,7951,6806,15360,8597,8605,8039,15360,8501,8533,7557,15360,8758,8830,7509,15360,10758,10830,10693,15360,11508,11605,11621,15360,13524,13669,13886,15360,13830,14022,14327,15360,13926,14103,14364,15360,13460,13621,13886,15360,12854,13191,13420,15360,13597,13733,13926,15360,13846,13990,14223,15360,13773,13942,14199,15360,13910,14087,14356,15360,13813,14022,14319,15360,14247,14396,14540,15360,14693,14765,14878,15360,15223,15279,15343,15360,15508,15524,15540,15360,15540,15548,15564,15360,15327,15335,15319,15360,15303,15311,15303,15360,15918,15910,15886,15360,16247,16207,16151,15360,16175,16143,16086,15360,14436,14452,14436,15360,12263,12380,12404,15360,11476,11701,11773,15360,12380,12492,12532,15360,14797,14797,14757,15360,11372,11589,11677,15360,12597,12934,13356,15360,13990,14364,14725,15360,14183,14444,14773,15360,14231,14444,14717,15360,14412,14532,14709,15360,14054,14199,14380,15360,12372,12500,12605,15360,12199,12565,13006,15360,12581,13175,13653,15360,10055,10380,10324,15360,8557,8573,6726,15360,8167,8196,6533,15360,7517,7485,6119,15360,7244,7172,5798,15360,7071,6959,5718,15360,7669,7581,6260,15360,8661,8605,7975,15360,10942,11079,11151,15360,12573,12741,13014,15360,11902,12030,12191,15360,10308,10332,10135,15360,11255,11300,11284,15360,11276,11348,11396,15360,10055,10215,10292,15360,12183,12332,12468,15360,9918,9966,9798,15360,8734,8742,8196,15360,8967,8950,8469,15360,10260,10276,10039,15360,9734,9758,9605,15360,9388,9404,9308,15360,7943,7878,7095,15360,7726,7637,6645,15360,8047,7983,7204,15360,9284,9236,8693,15360,9621,9565,9143,15360,11255,11268,11047,15360,13175,13332,13420,15360,13773,13934,14175,15360,13854,14022,14271,15360,13870,14038,14279,15360,13388,13516,13677,15360,12279,12629,12966,15360,13348,13452,13564,15360,13821,13918,14054,15360,13701,13846,14022,15360,13460,13605,13781,15360,13492,13637,13821,15360,13709,13821,13950,15360,14372,14428,14476,15360,14516,14572,14613,15360,14741,14789,14813,15360,14725,14749,14749,15360,13452,13484,13468,15360,13476,13500,13492,15360,14990,15022,15022,15360,14556,14572,14564,15360,15094,15111,15094,15360,13231,13287,13215,15360,11255,11380,11175,15360,10677,10886,10492,15360,11846,12006,11934,15360,14327,14340,14279,15360,10766,11039,10862,15360,12918,13255,13452,15360,14231,14548,14886,15360,13878,14380,14765,15360,13444,13862,14412,15360,12151,12404,12621,15360,12637,12902,13215,15360,11549,11749,11870,15360,12279,12653,13119,15360,13223,13404,13516,15360,9228,9260,8276,15360,8087,7991,6308,15360,7918,7814,6919,15360,7469,7364,6148,15360,7485,7380,6212,15360,8228,7991,7204,15360,9276,8967,8212,15360,9806,9573,8742,15360,10135,10087,9621,15360,11452,11452,11452,15360,10629,10637,10509,15360,10693,10733,10637,15360,11095,11111,10982,15360,11292,11348,11372,15360,10199,10244,10167,15360,10814,10926,10846,15360,8669,8774,7493,15360,7870,7910,6244,15360,8204,8183,6919,15360,9806,9758,9159,15360,9460,9436,8629,15360,9159,9087,8260,15360,7637,7509,6790,15360,7758,7629,6838,15360,7967,7918,6774,15360,10854,10749,10501,15360,11508,11412,11316,15360,12372,12300,12151,15360,12030,12119,12063,15360,12781,12910,12982,15360,13476,13581,13661,15360,13484,13589,13677,15360,12404,12428,12380,15360,11605,11765,11798,15360,11492,11533,11452,15360,11838,11886,11798,15360,12263,12372,12380,15360,12151,12231,12175,15360,11492,11508,11412,15360,11119,11111,10838,15360,12508,12581,12573,15360,12621,12693,12677,15360,12573,12629,12589,15360,12292,12324,12231,15360,12476,12565,12573,15360,11998,12159,12215,15360,12950,13071,13159,15360,12263,12372,12428,15360,12380,12428,12444,15360,11300,11308,11143,15360,10199,10244,9734,15360,9709,9701,9252,15360,10492,10581,10404,15360,11476,11516,11388,15360,9477,9517,8790,15360,11717,11854,11838,15360,14247,14420,14524,15360,14054,14311,14436,15360,13597,13805,13982,15360,11364,11533,11597,15360,12263,12428,12549,15360,11436,11605,11653,15360,13079,13324,13444,15360,12516,12613,12605,15360,10039,10015,9605,15360,8693,8621,7878,15360,7951,7862,6902,15360,8196,8204,7015,15360,8677,8589,7637,15360,9284,9031,8340,15360,9814,9605,8902,15360,10685,10428,9910,15360,10492,10260,9685,15360,9404,9252,7943,15360,8830,8766,7220,15360,9220,9047,7943,15360,9693,9669,9015,15360,11412,11468,11372,15360,11135,11159,11023,15360,10087,10055,9428,15360,9910,10007,9621,15360,9236,9300,8934,15360,9597,9557,8902,15360,10669,10549,9782,15360,9926,9870,9127,15360,9894,9918,9047,15360,8685,8742,7910,15360,9958,10167,10284,15360,10215,10332,10396,15360,11396,11428,11452,15360,11223,11255,11300,15360,11814,11862,11958,15360,10685,10846,10870,15360,10340,10380,10007,15360,11175,11207,10894,15360,12103,12207,12215,15360,11143,11103,10902,15360,9910,9966,9613,15360,10015,10079,9493,15360,10806,10846,10517,15360,10862,10934,10637,15360,10838,10942,10661,15360,10958,11087,10878,15360,10709,10838,10701,15360,10669,10741,10589,15360,10581,10669,10525,15360,10252,10348,9974,15360,11396,11500,11525,15360,11207,11255,11264,15360,10878,10910,10934,15360,11031,11063,11159,15360,11292,11324,11396,15360,11223,11255,11300,15360,10693,10685,10645,15360,10428,10420,10324,15360,10300,10252,9991,15360,10838,10846,10798,15360,10428,10428,10364,15360,9669,9605,9380,15360,10167,10244,10087,15360,11709,11854,11910,15360,11223,11284,11268,15360,10231,10244,9878,15360,10199,10244,9862,15360,10183,10260,9942,15360,10525,10653,10541,15360,12500,12597,12621,15360,11814,11741,11597,15360,11533,11460,11175,15360,11103,11006,10557,15360,10444,10396,9846,15360,10007,10023,9228,15360,9653,9790,8469,15360,9316,9372,8039,15360,9557,9830,8071,15360,9621,9918,8071,15360,9677,10015,8167,15360,9991,10284,8420,15360,10215,10436,8581,15360,10260,10484,8645,15360,10292,10476,8902,15360,10324,10468,9252,15360,9910,9894,8886,15360,10525,10573,9701,15360,9782,10039,8581,15360,9565,9814,8167,15360,9950,10039,8934,15360,10749,10758,10199,15360,10669,10685,10244,15360,10838,10838,10460,15360,11215,10910,10087,15360,11492,11364,10806,15360,11095,11159,11055,15360,11364,11388,11356,15360,11023,11039,10990,15360,11653,11653,11613,15360,11798,11725,11557,15360,11974,11862,11637,15360,12039,11942,11765,15360,12119,12047,11934,15360,12151,12071,11950,15360,12087,12006,11886,15360,12047,11966,11838,15360,11990,11926,11790,15360,11974,11910,11798,15360,11998,11934,11814,15360,12111,12039,11886,15360,12231,12143,11998,15360,12292,12199,12039,15360,12039,11974,11846,15360,11822,11782,11653,15360,11862,11838,11765,15360,11798,11765,11701,15360,11782,11733,11669,15360,11798,11749,11685,15360,11838,11790,11725,15360,11870,11822,11749,15360,11741,11701,11621,15360,11565,11541,11452,15360,11533,11500,11412,15360,11621,11581,11484,15360,11605,11557,11460,15360,11516,11468,11372,15360,11565,11533,11444,15360,11677,11637,11541,15360,11725,11661,11557,15360,11725,11661,11557,15360,11733,11669,11573,15360,11838,11773,11677,15360,11998,11926,11814,15360,12014,11926,11798,15360,11460,11404,11332,15360,11637,11557,11428,15360,12014,11894,11693,15360,12167,12022,11765,15360,12119,11982,11709,15360,11926,11806,11516,15360,11685,11589,11300,15360,11476,11404,10886,15360,11239,11151,10468,15360,10766,10733,9894,15360,10565,10565,9589,15360,10436,10444,9332,15360,10308,10308,9031,15360,10308,10316,8999,15360,10199,10244,8774,15360,9725,9645,8549,15360,10244,10276,8967,15360,10878,10838,10183,15360,11055,10966,10348,15360,11119,11006,10404,15360,11264,11135,10565,15360,11404,11316,10822,15360,11492,11388,10982,15360,11798,11613,11223,15360,12047,11830,11412,15360,12039,11894,11597,15360,12127,11990,11693,15360,12127,11990,11725,15360,12191,12055,11806,15360,12191,12055,11830,15360,11870,11773,11613,15360,11573,11516,11428,15360,11533,11484,11412,15360,11541,11492,11420,15360,11565,11516,11452,15360,11589,11541,11476,15360,11605,11557,11500,15360,11637,11589,11533,15360,11669,11621,11557,15360,11701,11645,11573,15360,11733,11669,11589,15360,11798,11717,11605,15360,11838,11749,11621,15360,11878,11782,11661,15360,11894,11798,11661,15360,11926,11806,11653,15360,11958,11822,11661,15360,11982,11846,11677,15360,12006,11870,11685,15360,12095,11950,11765,15360,12047,11910,11741,15360,11886,11765,11605,15360,11838,11733,11589,15360,11814,11717,11589,15360,11814,11709,11573,15360,11790,11693,11565,15360,11741,11677,11589,15360,11733,11677,11613,15360,11733,11685,11629,15360,11717,11669,11621,15360,11685,11645,11589,15360,11629,11589,11533,15360,11573,11525,11468,15360,11492,11444,11380,15360,11316,11255,11111,15360,11348,11292,11143,15360,11516,11436,11316,15360,11854,11749,11589,15360,12127,11990,11765,15360,12199,12055,11782,15360,12340,12231,11910,15360,12372,12292,11958,15360,12380,12300,11974,15360,12348,12247,11910,15360,12324,12215,11878,15360,12247,12103,11773,15360,12095,11958,11637,15360,12055,11926,11613,15360,11974,11854,11541,15360,11870,11765,11468,15360,11966,11854,11541,15360,12300,12151,11846,15360,12396,12316,12006,15360,12388,12308,11990,15360,12388,12308,12006,15360,12396,12316,12022,15360,12396,12308,12022,15360,12396,12308,12022,15360,12364,12279,11974,15360,12340,12247,11942,15360,12340,12231,11926,15360,12215,12071,11806,15360,12095,11966,11749,15360,11741,11645,11500,15360,11420,11356,11255,15360,11364,11308,11207,15360,11356,11300,11175,15360,11348,11292,11191,15360,11372,11324,11255,15360,11412,11364,11308,15360,11420,11372,11316,15360,11428,11380,11324,15360,11444,11388,11332,15360,11484,11428,11364,15360,11508,11460,11396,15360,11557,11500,11436,15360,11589,11533,11460,15360,11613,11557,11484,15360,11621,11557,11492,15360,11613,11557,11500,15360,11621,11557,11500,15360,11629,11573,11508,15360,11629,11573,11508,15360,11605,11557,11484,15360,11589,11533,11468,15360,11557,11508,11436,15360,11549,11500,11428,15360,11557,11500,11436,15360,11549,11492,11436,15360,11533,11484,11428,15360,11525,11476,11428,15360,11516,11476,11428,15360,11525,11484,11444,15360,11516,11476,11428,15360,11468,11428,11380,15360,11428,11388,11332,15360,11356,11308,11239,15360,11308,11255,11127,15360,11167,11071,10926,15360,11223,11119,10966,15360,11276,11175,10998,15360,11404,11332,11191,15360,11773,11693,11557,15360,11926,11798,11613,15360,12207,12039,11773,15360,12348,12231,11894,15360,12308,12151,11846,15360,12332,12215,11894,15360,12364,12279,11958,15360,12380,12292,11974,15360,12396,12316,12022,15360,12404,12316,12039,15360,12412,12332,12087,15360,12412,12332,12103,15360,12436,12356,12135,15360,12372,12292,12039,15360,12420,12332,12087,15360,12396,12316,12055,15360,12356,12263,11990,15360,12340,12231,11942,15360,12271,12127,11854,15360,12215,12071,11814,15360,12292,12135,11878,15360,12288,12135,11870,15360,12111,11982,11765,15360,11990,11886,11717,15360,11637,11557,11428,15360,11364,11300,11143,15360,11316,11239,11079,15360,11300,11207,11047,15360,11268,11159,11015,15360,11268,11159,11015,15360,11268,11159,11031,15360,11300,11223,11095,15360,11340,11292,11191,15360,11348,11300,11223,15360,11372,11324,11255,15360,11380,11332,11255,15360,11372,11316,11239,15360,11396,11340,11268,15360,11468,11404,11300,15360,11460,11404,11324,15360,11484,11428,11356,15360,11492,11436,11372,15360,11500,11444,11388,15360,11508,11460,11404,15360,11500,11452,11396,15360,11492,11436,11380,15360,11468,11412,11356,15360,11444,11388,11324,15360,11444,11388,11324,15360,11428,11380,11316,15360,11412,11356,11300,15360,11404,11348,11300,15360,11404,11356,11308,15360,11396,11356,11308,15360,11388,11348,11308,15360,11372,11340,11292,15360,11348,11308,11255,15360,11284,11223,11111,15360,11231,11143,11023,15360,11199,11111,10974,15360,11047,10958,10814,15360,11127,11023,10870,15360,11119,11006,10846,15360,11175,11055,10886,15360,11292,11191,10998,15360,11525,11404,11284,15360,11822,11637,11476,15360,11878,11733,11549,15360,11918,11790,11573,15360,12063,11918,11653,15360,12223,12063,11765,15360,12300,12151,11846,15360,12255,12103,11814,15360,12271,12127,11846,15360,12271,12127,11862,15360,12271,12127,11886,15360,12308,12183,11942,15360,12175,12039,11814,15360,12063,11934,11709,15360,12159,12014,11765,15360,12215,12063,11798,15360,12143,11998,11757,15360,12071,11934,11693,15360,11998,11870,11661,15360,11974,11870,11685,15360,11998,11910,11757,15360,11846,11765,11629,15360,11468,11396,11284,15360,11308,11223,11031,15360,11215,11103,10934,15360,11207,11095,10942,15360,11215,11103,10950,15360,11191,11087,10942,15360,11175,11079,10942,15360,11167,11063,10934,15360,11143,11031,10902,15360,11247,11143,11015,15360,11284,11191,11079,15360,11300,11223,11095,15360,11316,11268,11127,15360,11340,11284,11143,15360,11340,11284,11159,15360,11356,11300,11191,15360,11372,11316,11239,15360,11380,11324,11255,15360,11372,11316,11255,15360,11380,11324,11276,15360,11380,11324,11268,15360,11372,11316,11255,15360,11364,11316,11255,15360,11364,11308,11239,15360,11348,11292,11207,15360,11340,11284,11191,15360,11348,11292,11191,15360,11348,11292,11207,15360,11340,11292,11207,15360,11340,11292,11207,15360,11324,11276,11207,15360,11308,11255,11175,15360,11264,11175,11079,15360,11119,11039,10934,15360,11103,11015,10902,15360,11095,11006,10878,15360,11031,10942,10806,15360,10990,10902,10766,15360,11047,10942,10814,15360,11031,10926,10790,15360,11055,10942,10806,15360,11119,10998,10846,15360,11151,11015,10830,15360,11268,11095,10886,15360,11484,11396,11268,15360,11790,11701,11549,15360,11886,11790,11637,15360,11838,11741,11581,15360,11838,11725,11541,15360,11902,11782,11581,15360,11966,11838,11629,15360,11974,11846,11629,15360,11958,11838,11629,15360,11950,11838,11637,15360,11814,11701,11525,15360,11581,11492,11332,15360,11645,11541,11380,15360,11806,11701,11533,15360,11902,11806,11637,15360,11950,11862,11717,15360,12014,11934,11790,15360,11942,11862,11725,15360,11565,11492,11388,15360,11292,11191,11015,15360,11231,11111,10950,15360,11159,11047,10894,15360,11119,11006,10854,15360,11127,11023,10878,15360,11159,11055,10902,15360,11135,11031,10894,15360,11111,11006,10878,15360,11095,10990,10870,15360,11095,10998,10886,15360,11071,10966,10846,15360,11111,11006,10902,15360,11191,11095,10974,15360,11268,11159,11031,15360,11284,11191,11063,15360,11292,11207,11063,15360,11300,11223,11079,15360,11332,11268,11143,15360,11316,11255,11127,15360,11316,11255,11143,15360,11308,11239,11127,15360,11316,11255,11159,15360,11300,11223,11127,15360,11292,11207,11095,15360,11300,11223,11111,15360,11300,11223,11095,15360,11300,11223,11095,15360,11308,11239,11111,15360,11300,11223,11111,15360,11292,11207,11111,15360,11264,11167,11071,15360,11215,11127,11047,15360,11135,11055,10966,15360,11015,10934,10846,15360,10918,10838,10733,15360,10982,10894,10782,15360,10974,10886,10766,15360,10982,10894,10766,15360,10958,10862,10749,15360,10982,10886,10774,15360,10958,10862,10758,15360,10958,10862,10749,15360,11015,10910,10790,15360,11023,10910,10774,15360,11079,10958,10806,15360,11103,10974,10798,15360,11191,11047,10846,15360,11468,11388,11276,15360,11846,11765,11637,15360,12006,11918,11782,15360,11998,11910,11782,15360,11902,11822,11693,15360,11838,11749,11637,15360,11782,11709,11605,15360,11806,11741,11645,15360,11782,11717,11629,15360,11773,11717,11621,15360,11870,11806,11701,15360,11942,11862,11757,15360,12183,12103,11974,15360,11974,11894,11765,15360,11476,11404,11308,15360,11268,11143,10966,15360,11183,11063,10902,15360,11111,10998,10854,15360,11055,10942,10806,15360,11023,10910,10766,15360,11047,10934,10782,15360,11039,10926,10782,15360,11079,10966,10830,15360,11031,10918,10782,15360,11031,10926,10806,15360,10990,10894,10782,15360,10974,10886,10790,15360,10966,10870,10774,15360,11006,10902,10806,15360,11039,10942,10838,15360,11127,11023,10910,15360,11175,11079,10958,15360,11191,11087,10958,15360,11207,11095,10958,15360,11268,11143,11015,15360,11276,11175,11047,15360,11284,11191,11079,15360,11292,11191,11079,15360,11276,11175,11079,15360,11239,11135,11031,15360,11268,11159,11047,15360,11215,11111,11006,15360,11239,11127,11015,15360,11255,11143,11031,15360,11223,11119,11015,15360,11199,11103,10998,15360,11175,11087,10982,15360,11143,11047,10958,15360,11031,10942,10854,15360,10958,10878,10790,15360,10910,10830,10741,15360,10942,10862,10758,15360,10926,10838,10733,15360,10854,10758,10637,15360,10918,10830,10709,15360,10910,10822,10717,15360,10942,10846,10749,15360,10942,10854,10741,15360,10942,10854,10749,15360,10966,10870,10758,15360,10966,10870,10758,15360,10958,10854,10733,15360,10998,10886,10741,15360,10942,10830,10677,15360,11039,10918,10749,15360,11095,10974,10806,15360,11308,11223,11031,15360,11468,11396,11292,15360,11605,11533,11428,15360,11701,11621,11525,15360,11693,11629,11541,15360,11685,11621,11549,15360,11685,11629,11549,15360,11629,11565,11484,15360,11589,11533,11444,15360,11364,11308,11191,15360,11191,11087,10958,15360,11135,11031,10902,15360,11135,11031,10894,15360,11055,10950,10830,15360,11015,10910,10782,15360,10958,10854,10733,15360,10942,10838,10717,15360,10974,10870,10733,15360,10982,10878,10749,15360,10990,10886,10758,15360,11015,10910,10798,15360,10966,10862,10758,15360,10950,10854,10758,15360,10910,10822,10733,15360,10894,10798,10709,15360,10902,10814,10725,15360,10934,10846,10758,15360,10910,10822,10733,15360,10950,10854,10749,15360,10974,10878,10766,15360,11047,10942,10830,15360,11095,10990,10878,15360,11167,11055,10942,15360,11199,11103,10990,15360,11191,11087,10982,15360,11151,11047,10950,15360,11135,11031,10934,15360,11095,10998,10902,15360,11143,11047,10950,15360,11079,10990,10894,15360,11079,10990,10902,15360,11103,11006,10910,15360,11079,10982,10886,15360,11023,10926,10822,15360,10982,10894,10798,15360,10958,10870,10782,15360,10910,10814,10725,15360,10926,10838,10741,15360,10934,10838,10733,15360,10950,10854,10749,15360,10886,10798,10709,15360,10910,10814,10709,15360,10926,10830,10725,15360,10910,10814,10701,15360,10862,10774,10677,15360,10950,10854,10733,15360,10926,10830,10717,15360,10926,10838,10725,15360,10926,10830,10725,15360,10894,10798,10685,15360,10926,10830,10701,15360,10958,10854,10717,15360,10934,10830,10685,15360,10950,10846,10709,15360,10974,10862,10717,15360,10942,10830,10685,15360,10958,10846,10701,15360,11006,10894,10749,15360,10950,10846,10725,15360,10958,10862,10741,15360,10894,10806,10701,15360,10854,10774,10669,15360,10886,10806,10701,15360,10862,10790,10693,15360,10878,10806,10717,15360,10982,10902,10798,15360,10990,10902,10798,15360,10950,10862,10758,15360,10942,10846,10733,15360,10870,10774,10669,15360,10894,10798,10693,15360,10918,10830,10725,15360,10894,10806,10701,15360,10926,10830,10733,15360,10902,10830,10725,15360,10870,10790,10693,15360,10886,10814,10725,15360,10814,10741,10661,15360,10838,10766,10677,15360,10822,10741,10661,15360,10822,10741,10669,15360,10862,10790,10709,15360,10846,10758,10669,15360,10894,10798,10693,15360,10974,10878,10766,15360,10966,10870,10766,15360,11023,10926,10814,15360,11079,10974,10862,15360,11006,10910,10814,15360,10950,10862,10766,15360,10982,10894,10798,15360,10958,10862,10774,15360,10958,10870,10782,15360,10910,10830,10741,15360,10950,10862,10766,15360,10982,10886,10790,15360,10918,10822,10725,15360,10886,10798,10701,15360,10854,10766,10669,15360,10894,10806,10709,15360,10926,10830,10725,15360,10926,10830,10725,15360,10958,10862,10749,15360,10958,10862,10749,15360,10894,10806,10717,15360,10902,10814,10717,15360,10878,10790,10677,15360,10942,10838,10717,15360,10918,10814,10701,15360,10886,10790,10661,15360,10942,10838,10717,15360,10950,10854,10725,15360,10950,10854,10725,15360,10910,10814,10693,15360,10910,10814,10685,15360,10942,10838,10709,15360,10894,10790,10661,15360,10910,10806,10669,15360,10822,10725,10597,15360,10749,10661,10541,15360,10830,10733,10613,15360,10838,10741,10629,15360,10806,10709,10597,15360,10854,10766,10653,15360,10862,10774,10669,15360,10798,10725,10629,15360,10822,10749,10653,15360,10854,10782,10693,15360,10806,10741,10661,15360,10862,10790,10701,15360,10870,10790,10685,15360,10870,10790,10693,15360,10878,10790,10677,15360,10862,10782,10677,15360,10870,10790,10693,15360,10870,10782,10685,15360,10894,10814,10709,15360,10886,10814,10709,15360,10846,10782,10685,15360,10741,10669,10573,15360,10766,10693,10589,15360,10709,10637,10541,15360,10741,10669,10589,15360,10741,10677,10589,15360,10709,10637,10557,15360,10774,10701,10613,15360,10862,10774,10677,15360,11006,10918,10806,15360,11006,10902,10782,15360,10974,10870,10749,15360,10958,10854,10733,15360,10934,10838,10725,15360,10934,10838,10733,15360,10934,10838,10725,15360,10886,10790,10685,15360,10854,10766,10661,15360,10886,10798,10701,15360,10838,10749,10645,15360,10878,10782,10661,15360,10822,10725,10613,15360,10822,10717,10605,15360,10846,10749,10629,15360,10854,10749,10637,15360,10950,10854,10733,15360,10958,10854,10741,15360,10910,10806,10693,15360,10926,10822,10693,15360,10934,10838,10725,15360,10910,10822,10709,15360,10910,10822,10709,15360,10886,10782,10661,15360,10910,10814,10677,15360,10910,10806,10677,15360,10926,10822,10685,15360,10958,10854,10717,15360,10974,10870,10725,15360,10926,10830,10693,15360,10926,10830,10693,15360,10918,10822,10693,15360,10934,10838,10701,15360,10918,10814,10685,15360,10878,10782,10653,15360,10870,10774,10645,15360,10838,10749,10629,15360,10806,10717,10605,15360,10822,10733,10621,15360,10822,10733,10621,15360,10846,10758,10653,15360,10846,10766,10653,15360,10822,10741,10629,15360,10806,10733,10629,15360,10806,10725,10621,15360,10790,10709,10605,15360,10766,10693,10589,15360,10814,10741,10629,15360,10846,10766,10653,15360,10838,10758,10653,15360,10878,10790,10677,15360,10894,10798,10685,15360,10830,10741,10629,15360,10830,10758,10653,15360,10798,10725,10629,15360,10806,10733,10629,15360,10717,10637,10525,15360,10661,10581,10476,15360,10701,10621,10517,15360,10733,10661,10565,15360,10782,10685,10557,15360,10862,10758,10613,15360,10974,10862,10725,15360,10958,10846,10709,15360,11006,10902,10766,15360,11006,10902,10774,15360,11039,10934,10814,15360,11006,10902,10790,15360,11006,10910,10790,15360,10950,10854,10741,15360,10934,10830,10709,15360,10918,10814,10701,15360,10854,10758,10653,15360,10918,10814,10701,15360,10870,10766,10645,15360,10830,10733,10621,15360,10934,10830,10709,15360,10990,10886,10758,15360,10950,10838,10717,15360,10910,10814,10701,15360,10926,10822,10693,15360,10934,10830,10709,15360,10878,10774,10653,15360,10934,10830,10701,15360,10926,10822,10693,15360,10878,10782,10661,15360,10878,10782,10661,15360,10862,10766,10621,15360,10886,10782,10645,15360,10886,10782,10653,15360,10926,10822,10701,15360,10902,10806,10685,15360,10926,10822,10701,15360,10918,10814,10685,15360,10878,10782,10645,15360,10910,10806,10669,15360,10854,10758,10621,15360,10886,10790,10645,15360,10854,10758,10629,15360,10830,10741,10613,15360,10918,10814,10685,15360,10862,10766,10645,15360,10830,10741,10613,15360,10806,10717,10597,15360,10741,10661,10557,15360,10774,10693,10581,15360,10749,10669,10557,15360,10774,10693,10581,15360,10766,10685,10573,15360,10790,10709,10597,15360,10782,10701,10589,15360,10790,10709,10597,15360,10838,10749,10621,15360,10870,10774,10645,15360,10894,10790,10661,15360,10878,10782,10653,15360,10846,10741,10613,15360,10790,10693,10557,15360,10814,10717,10597,15360,10790,10701,10581,15360,10741,10645,10525,15360,10717,10629,10509,15360,10774,10685,10573,15360,10725,10637,10525,15360,10854,10749,10621,15360,10950,10846,10701,15360,10966,10854,10709,15360,10934,10814,10677,15360,10926,10822,10701,15360,10982,10878,10766,15360,10998,10894,10782,15360,10990,10878,10766,15360,10998,10894,10782,15360,10998,10886,10774,15360,10998,10886,10758,15360,11006,10894,10774,15360,10942,10838,10733,15360,10958,10854,10741,15360,10958,10854,10749,15360,11006,10902,10790,15360,11015,10902,10798,15360,10982,10870,10758,15360,10998,10894,10782,15360,10974,10870,10758,15360,11006,10902,10790,15360,10998,10894,10774,15360,10974,10870,10758,15360,10950,10854,10741,15360,10878,10790,10693,15360,10902,10814,10701,15360,10918,10822,10709,15360,10838,10733,10613,15360,10878,10782,10661,15360,10934,10838,10717,15360,10902,10806,10693,15360,10918,10822,10709,15360,10926,10830,10709,15360,10838,10733,10605,15360,10910,10806,10661,15360,10942,10838,10693,15360,10886,10782,10645,15360,10886,10782,10637,15360,10854,10749,10621,15360,10926,10830,10709,15360,10966,10862,10741,15360,10846,10749,10629,15360,10830,10733,10605,15360,10854,10758,10637,15360,10822,10725,10605,15360,10886,10790,10661,15360,10902,10806,10669,15360,10918,10814,10677,15360,10830,10733,10605,15360,10806,10717,10589,15360,10870,10774,10645,15360,10934,10838,10709,15360,10958,10862,10733,15360,10886,10790,10661,15360,10894,10798,10661,15360,10958,10854,10709,15360,10934,10830,10709,15360,10814,10717,10581,15360,10862,10758,10613,15360,10854,10741,10589,15360,10814,10717,10573,15360,10886,10782,10645,15360,10814,10725,10597,15360,10862,10766,10637,15360,10910,10806,10669,15360,10942,10838,10709,15360,10966,10862,10733,15360,10974,10870,10741,15360,10974,10870,10749,15360,10958,10862,10749,15360,11031,10934,10822,15360,10998,10894,10782,15360,10974,10870,10766,15360,11023,10918,10814,15360,11039,10926,10822,15360,10958,10846,10741,15360,10918,10814,10693,15360,10966,10870,10741,15360,10982,10886,10766,15360,10982,10878,10766,15360,10942,10846,10733,15360,10958,10862,10758,15360,10950,10854,10758,15360,10934,10830,10717,15360,10966,10862,10733,15360,10942,10846,10725,15360,10934,10846,10733,15360,10934,10846,10733,15360,10878,10798,10693,15360,10886,10798,10693,15360,10910,10814,10709,15360,10942,10846,10733,15360,10838,10733,10597,15360,10878,10774,10645,15360,10918,10822,10701,15360,10878,10782,10653,15360,10894,10790,10661,15360,10934,10838,10725,15360,10958,10854,10725,15360,10966,10862,10733,15360,10910,10806,10685,15360,10982,10878,10758,15360,10942,10854,10749,15360,10934,10838,10733,15360,10918,10814,10701,15360,10894,10798,10669,15360,10894,10798,10669,15360,10814,10725,10605,15360,10902,10798,10669,15360,10814,10725,10605,15360,10894,10798,10685,15360,10958,10862,10749,15360,10910,10814,10701,15360,10910,10806,10685,15360,10918,10814,10693,15360,10926,10822,10709,15360,10894,10790,10661,15360,10902,10806,10677,15360,10902,10806,10685,15360,10934,10838,10717,15360,10934,10838,10701,15360,10934,10838,10717,15360,10950,10854,10725,15360,10894,10798,10661,15360,10862,10749,10597,15360,10894,10798,10677,15360,10878,10782,10661,15360,10926,10838,10717,15360,10926,10838,10717,15360,10918,10822,10709,15360,10934,10838,10733,15360,10926,10838,10733,15360,10958,10870,10766,15360,10942,10854,10749,15360,10958,10870,10774,15360,10974,10878,10774,15360,10958,10854,10741,15360,10950,10846,10741,15360,10950,10854,10758,15360,10934,10838,10733,15360,10942,10846,10725,15360,10966,10862,10741,15360,10926,10838,10733,15360,10958,10862,10749,15360,10910,10822,10709,15360,10942,10854,10758,15360,10926,10838,10733,15360,10910,10822,10717,15360,10934,10838,10733,15360,10934,10846,10733,15360,10902,10814,10709,15360,10926,10830,10717,15360,10918,10822,10709,15360,10838,10749,10637,15360,10878,10790,10677,15360,10942,10846,10733,15360,10926,10822,10701,15360,10958,10862,10749,15360,10886,10790,10685,15360,10918,10814,10693,15360,10910,10814,10693,15360,10902,10806,10701,15360,10878,10774,10637,15360,10798,10693,10565,15360,10822,10725,10597,15360,10934,10838,10709,15360,10958,10854,10725,15360,10886,10790,10669,15360,10910,10806,10677,15360,10886,10782,10645,15360,10830,10725,10597,15360,10822,10717,10581,15360,10862,10758,10637,15360,10878,10782,10669,15360,10926,10822,10709,15360,10974,10878,10774,15360,10966,10870,10758,15360,10918,10822,10709,15360,10846,10749,10645,15360,10894,10798,10693,15360,10918,10822,10709,15360,10974,10878,10774,15360,10918,10822,10717,15360,10982,10886,10774,15360,10974,10878,10758,15360,10950,10854,10741,15360,10958,10854,10725,15360,10982,10886,10766,15360,10918,10822,10701,15360,10878,10782,10669,15360,10886,10790,10669,15360,10934,10838,10717,15360,10950,10854,10741,15360,10934,10838,10733,15360,10982,10886,10782,15360,10886,10798,10701,15360,10870,10782,10685,15360,10894,10814,10717,15360,10910,10822,10725,15360,10934,10838,10733,15360,10950,10846,10741,15360,10934,10838,10725,15360,10934,10846,10749,15360,10902,10814,10717,15360,10878,10790,10677,15360,10878,10782,10669,15360,10854,10766,10645,15360,10838,10749,10629,15360,10902,10814,10701,15360,10910,10814,10693,15360,10902,10798,10669,15360,10910,10806,10677,15360,10886,10782,10653,15360,10854,10749,10629,15360,10870,10774,10653,15360,10974,10870,10758,15360,10990,10878,10758,15360,10918,10822,10709,15360,10926,10838,10725,15360,10958,10854,10733,15360,10894,10790,10653,15360,10822,10725,10605,15360,10878,10782,10661,15360,10974,10870,10749,15360,10902,10806,10677,15360,10934,10838,10725,15360,10870,10774,10653,15360,10798,10701,10581,15360,10854,10749,10621,15360,10894,10798,10669,15360,10934,10822,10685,15360,10942,10830,10701,15360,10910,10806,10669,15360,10870,10758,10629,15360,10886,10774,10645,15360,10950,10838,10701,15360,10966,10870,10749,15360,10886,10790,10685,15360,10870,10782,10677,15360,10934,10838,10733,15360,10934,10838,10725,15360,10822,10725,10621,15360,10878,10790,10677,15360,10894,10798,10693,15360,10822,10733,10629,15360,10894,10798,10685,15360,10998,10902,10790,15360,11015,10918,10806,15360,10950,10854,10741,15360,10950,10846,10741,15360,10934,10838,10733,15360,10942,10846,10749,15360,10910,10822,10725,15360,10846,10758,10653,15360,10878,10790,10685,15360,10894,10798,10701,15360,10862,10774,10669,15360,10814,10725,10621,15360,10846,10758,10645,15360,10870,10774,10661,15360,10870,10774,10677,15360,10878,10790,10693,15360,10878,10782,10677,15360,10830,10741,10637,15360,10870,10782,10677,15360,10966,10870,10766,15360,11015,10918,10814,15360,10910,10814,10701,15360,10942,10846,10725,15360,10950,10846,10725,15360,10942,10838,10725,15360,10934,10830,10701,15360,10910,10798,10677,15360,10886,10782,10653,15360,10838,10733,10597,15360,10902,10806,10669,15360,10830,10733,10613,15360,10838,10741,10621,15360,10838,10741,10621,15360,10894,10798,10669,15360,10934,10830,10685,15360,10886,10790,10669,15360,10902,10806,10685,15360,10854,10749,10637,15360]));function td(){if(Be.isBrowser){const c=document.createElement("div");return c.setAttribute("style","height: 1in; visibility: hidden; position: absolute; margin: 0; padding: 0;"),document.body.appendChild(c),.0254/c.clientHeight}else return .0254/96}const xr={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:td()},Io={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},Bo=c=>c===2?"²":c===3?"³":"",br=(c,t=1)=>Io[c]+Bo(t),id=(c,t,e,i=1)=>(e==null&&(e=t),e===t?{value:c,unit:br(e)}:{value:c*Math.pow(xr[t]/xr[e],i),unit:br(e)+Bo(i)});var ko=(c=>(c.Top="Top",c.Bottom="Bottom",c.Front="Front",c.Back="Back",c.Left="Left",c.Right="Right",c))(ko||{});class sd{static getCameraDirectionByView(t){const e=new p.Vector3(1,0,0);return t==="Top"?e.set(0,-1,0):t==="Bottom"?e.set(0,1,0):t==="Front"?e.set(0,0,-1):t==="Back"?e.set(0,0,1):t==="Left"?e.set(1,0,0):t==="Right"&&e.set(-1,0,0),e}}var le=(c=>(c.MouseClick="mouseclick",c.LayoutChange="layoutchange",c.ModelLoad="modelload",c.BeforeRender="beforerender",c.AfterRender="afterrender",c.OnAnimate="onanimate",c.CameraChange="camerachange",c.ControlChange="controlchange",c.BoxSelectActivate="boxselectactivate",c.BoxSelectDeactivate="boxselectdeactivate",c.PickMarkupActivate="pickmarkupactivate",c.PickMarkupDeactivate="pickmarkupdeactivate",c.MarkupActivate="markupactivate",c.MarkupDeactivate="markupdeactivate",c.MarkupAdd="markupadd",c.MarkupUpdate="markupupdate",c.MarkupRemove="markupremove",c.BeforeRemoveMarkup="beforeremovemarkup",c.MeasurementActivate="measurementactivate",c.MeasurementDeactivate="measurementdeactivate",c.MeasurementAdd="measurementadd",c.MeasurementRemove="measurementremove",c.HotpointClick="hotpointclick",c))(le||{});const wa={};class bs extends Nt{constructor(e){super();g(this,"viewer");g(this,"drawableLists");g(this,"canvas");g(this,"context");g(this,"frustum");g(this,"projScreenMatrix");this.drawableLists=[],this.frustum=new p.Frustum,this.projScreenMatrix=new p.Matrix4,this.viewer=e,this.init()}static _registerDrawableClass(e){const i=e;wa[i.prototype.getClassType()]=e}static createDrawable(e){const i=wa[e.type];if(!i)throw new Error("Invalid drawable type: "+i);const s=e.points.map(r=>new p.Vector3(r[0],r[1],r[2]||0)),n=new i(e.id,s);return n.setData(e),n}get is3d(){return this.viewer.is3d()}get container(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}init(){this.initCanvas(),this.viewer.addEventListener(le.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(Be.isBrowser&&!e.context2d){const i=this.canvas=document.createElement("canvas"),s=this.viewer.viewerContainer;s.appendChild(i),i.classList.add("overlay-renderer"),i.style.pointerEvents="none",i.style.position="absolute",i.style.left="0px",i.style.top="0px",i.style.userSelect="none",this.context=i.getContext("2d",{willReadFrequently:!0});const{clientWidth:n,clientHeight:r}=s;this.setSize(n,r)}else e.context2d&&(this.context=e.context2d,this.canvas=Be.creatReactNativeCanvas(this.context),this.context.canvas||(this.context.canvas=this.canvas))}toHighDpr(e,i,s){const n=Math.max(window.devicePixelRatio||1,1),r=this.canvas;return r.width=i*n,r.height=s*n,e.scale(n,n),r.style.width=i+"px",r.style.height=s+"px",e}clearCanvas(){this.context?.clearRect(0,0,this.canvas?.width??0,this.canvas?.height??0)}addDrawableList(e){this.drawableLists.push(e)}render(){if(!this.canvas||!this.context||this.drawableLists.length<1)return;this.clearCanvas();const e=this.getSortedDrawables(!1);if(e.length===0)return;const i=new p.Sphere,s=this.viewer.getPixelSizeInWorldCoord();for(let n=0;n<e.length;n++){const r=e[n];r.setTolerance(s),!(!r.visible||(r.getBounds().getBoundingSphere(i),r.needsFrustumCulled&&!this.frustum.intersectsSphere(i)))&&r.render(this.context,this.camera)}}setSize(e,i){const s=this.canvas;s.width=e,s.height=i,s.style.width=e+"px",s.style.height=i+"px",this.toHighDpr(this.context,e,i)}getSortedDrawables(e=!1){const i=[];return this.drawableLists.forEach(s=>{let n=Array.from(s.getDrawables().values());e&&(n=n.filter(r=>r.visible)),n.length>0&&i.push(...n)}),i.sort((s,n)=>s.renderOrder===n.renderOrder?n.getCenter().distanceTo(this.camera.position)-s.getCenter().distanceTo(this.camera.position):s.renderOrder-n.renderOrder),i}getDrawablesByDrawableListAndPosition(e,i){return this.is3d||(i.z=0),e.getDrawableByPosition(i,this.raycaster)}getDrawablesByPosition(e){this.is3d||(e.z=0);const i=this.getSortedDrawables(),s=[];for(let n=0;n<i.length;n++){const r=i[n];r.isPointInPath(e,this.raycaster)&&s.push(r)}return s}getDrawableById(e){return this.getSortedDrawables().find(s=>s.id===e)}measureTextLength(e,i){const s=this.context,n=e.split(`
535
+ `);let r=0;for(let a=0;a<n.length;a++){const o=n[a];s.save(),s.font=i;const l=s.measureText(o).width;s.restore(),r=Math.max(r,l)}return r}getImage(e){this.clearCanvas();const i=this.getSortedDrawables();for(let s=0;s<i.length;s++){const n=i[s];e(n)&&n.render(this.context,this.camera)}return j.canvasToImage(this.canvas)}getCanvas(){return this.canvas}destroy(){this.drawableLists.forEach(e=>e.clear()),this.drawableLists=[],this.canvas&&(this.viewer.viewerContainer?.removeChild(this.canvas),this.canvas=void 0)}}class ws extends Nt{constructor(e){super();g(this,"category");g(this,"drawableMap");this.drawableMap=new Map,this.category=e}addDrawable(e){this.drawableMap.set(e.id,e),this.dispatchEvent("add",e.getData())}updateDrawable(e,i){e.setData(i),this.dispatchEvent("update",e.getData())}removeDrawable(e){this.drawableMap.delete(e.id),this.dispatchEvent("remove",e.getData())}getDrawableById(e){return this.drawableMap.get(e)}clear(){this.drawableMap.forEach(e=>this.removeDrawable(e))}getDrawables(){return this.drawableMap}getDrawableDatas(){return Array.from(this.drawableMap).map(([,e])=>e.getData())}setDrawableDatas(e){for(let i=0;i<e.length;i++){const s=e[i],n=bs.createDrawable(s);this.addDrawable(n)}}getDrawableByPosition(e,i){let s;for(const[,n]of this.drawableMap)if(n.visible&&n.isPointInPath(e,i)){s=n;break}return s}}class Ht extends Nt{constructor(e){super();g(this,"DEFAULT_LINE_WIDTH",1);g(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);g(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);g(this,"id");g(this,"lineWidth");g(this,"lineColor");g(this,"fillColor");g(this,"x");g(this,"y");g(this,"width");g(this,"height");g(this,"points");g(this,"userData");g(this,"tolerance");g(this,"visible");g(this,"selected");g(this,"renderOrder");g(this,"needsFrustumCulled");g(this,"editPointSize");g(this,"editPointFillColor");g(this,"editPointStrokeColor");g(this,"matrix");g(this,"ctx");this.lineWidth=this.DEFAULT_LINE_WIDTH,this.lineColor=this.DEFAULT_STROKE_STYLE,this.fillColor=this.DEFAULT_FILL_STYLE,this.x=0,this.y=0,this.width=0,this.height=0,this.points=[],this.userData={},this.tolerance=1,this.visible=!0,this.selected=!1,this.renderOrder=1,this.needsFrustumCulled=!0,this.editPointSize=3,this.editPointFillColor="#ffffff",this.editPointStrokeColor="#939ea4",this.matrix=new p.Matrix4,this.id=e||j.guid()}setTolerance(e){this.tolerance=e}render(e,i){this.ctx=e,this.draw(e,i),this.selected&&this.drawSelect(e,i)}getData(){return{id:this.id,points:this.points.map(e=>[e.x,e.y]),lineWidth:this.lineWidth,lineColor:this.lineColor,fillColor:this.fillColor,type:this.getClassType()}}setData(e){this.id=e.id,this.setLineWidth(e.lineWidth),this.setLineColor(e.lineColor),this.setFillColor(e.fillColor)}getVertexes(){const e=new p.Vector3(this.x,this.y,0),i=new p.Vector3(this.x+this.width,this.y,0),s=new p.Vector3(this.x+this.width,this.y-this.height,0),n=new p.Vector3(this.x,this.y-this.height,0);return[e,i,s,n]}setLineWidth(e){this.lineWidth=e||this.DEFAULT_LINE_WIDTH}setLineColor(e){this.lineColor=e||this.DEFAULT_STROKE_STYLE}setFillColor(e){this.fillColor=e||this.DEFAULT_FILL_STYLE}isSelected(){return this.selected}getCenter(){return this.getBounds().getCenter(new p.Vector3)}transToScreenCoord(e,i){return this.ctx?Ee.world2Screen(e,i,this.ctx.canvas):new p.Vector2}drawBounds(e,i){const{min:s,max:n}=this.getBounds(),r=[],a=(o,l,h)=>r.push(new p.Vector3(o,l,h));a(n.x,n.y,n.z),a(s.x,n.y,n.z),a(s.x,s.y,n.z),a(n.x,s.y,n.z),a(n.x,n.y,s.z),a(s.x,n.y,s.z),a(s.x,s.y,s.z),a(n.x,s.y,s.z),a(s.x,n.y,n.z),a(s.x,s.y,n.z),a(n.x,n.y,n.z),a(n.x,s.y,n.z),a(n.x,n.y,s.z),a(n.x,s.y,s.z),a(s.x,n.y,s.z),a(s.x,s.y,s.z),a(s.x,n.y,n.z),a(s.x,n.y,s.z),a(n.x,n.y,n.z),a(n.x,n.y,s.z),a(s.x,s.y,n.z),a(s.x,s.y,s.z),a(n.x,s.y,n.z),a(n.x,s.y,s.z),e.save(),e.strokeStyle="yellow",e.beginPath(),r.forEach((o,l)=>{const h=this.transToScreenCoord(o,i);l%2===0?e.moveTo(h.x,h.y):e.lineTo(h.x,h.y)}),e.closePath(),e.stroke(),e.restore()}drawCenter(e,i){const s=this.transToScreenCoord(this.getCenter(),i);e.save(),e.fillStyle="yellow",e.beginPath(),e.arc(s.x,s.y,5,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}getBounds(){const e=this.getVertexes();return new p.Box3().setFromPoints(e)}}const Un=new p.Vector3;class wt extends Ht{constructor(e,i,s=[1,0,0,1],n){super(e);g(this,"boxes");g(this,"lineSegments");this.lineSegments=[],this.boxes=wt.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=n??[s[0],s[1],s[2],.12],this.lineWidth=2,this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),n=s.getSize(Un),r=Math.max(n.x,n.y)*.12||1;return s.expandByScalar(r)})}calculateCloudLineSegments(e){for(let i=0;i<e.length;i++){const s=e[i],n=[new p.Vector3(s.min.x,s.min.y),new p.Vector3(s.max.x,s.min.y),new p.Vector3(s.max.x,s.max.y),new p.Vector3(s.min.x,s.max.y),new p.Vector3(s.min.x,s.min.y)],r=Un.subVectors(n[0],n[2]).length()/10||1e-4,a=[];for(let o=0;o<n.length-1;o++){const l=n[o],h=n[o+1],d=Un.subVectors(h,l),u=d.length(),f=d.normalize(),m=Math.ceil(u/r);for(let b=0;b<m;b++)a.push(l.clone().add(f.clone().multiplyScalar(r*b)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=Li.rgba2Color(this.lineColor),e.fillStyle=Li.rgba2Color(this.fillColor);for(let s=0;s<this.lineSegments.length;s++){const n=this.boxes[s];n&&this.fillRect(e,i,n);const r=this.lineSegments[s];this.drawBox(e,i,r)}e.restore()}fillRect(e,i,s){const n=[new p.Vector3(s.min.x,s.min.y),new p.Vector3(s.max.x,s.min.y),new p.Vector3(s.max.x,s.max.y),new p.Vector3(s.min.x,s.max.y)];e.beginPath();for(let r=0;r<n.length;r++){const a=this.transToScreenCoord(n[r],i);r===0?e.moveTo(a.x,a.y):e.lineTo(a.x,a.y)}e.closePath(),e.fill()}drawBox(e,i,s){e.beginPath();for(let n=0;n<s.length-1;n++){const r=this.transToScreenCoord(s[n],i),a=this.transToScreenCoord(s[n+1],i),o=wt.getControlPointByTwoPoints(a,r);n===0&&e.moveTo(r.x,r.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new p.Vector2().subVectors(i,e),n=s.angle(),r=s.length(),a=p.MathUtils.degToRad(45),o=r/2/Math.cos(a);return new p.Vector2(e.x+o*Math.cos(a-n),e.y-o*Math.sin(a-n))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new p.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}bs._registerDrawableClass(wt);const nd=[0,16711680,16776960,65280,65535,255,16711935,16777215,8421504,12632256,16711680,16744319,13369344,13395558,10027008,10046540,8323072,8339263,4980736,4990502,16727808,16752511,13382400,13401958,10036736,10051404,8331008,8343359,4985600,4992806,16744192,16760703,13395456,13408614,10046464,10056268,8339200,8347455,4990464,4995366,16760576,16768895,13408512,13415014,10056192,10061132,8347392,8351551,4995328,4997670,16776960,16777087,13421568,13421670,10000384,10000460,8355584,8355647,5000192,5000230,12582656,14679935,10079232,11717734,7510016,8755276,6258432,7307071,3755008,4344870,8388352,12582783,6736896,10079334,5019648,7510092,4161280,6258495,2509824,3755046,4194048,10485631,3394560,8375398,2529280,6264908,2064128,5209919,1264640,3099686,65280,8388479,52224,6736998,38912,5019724,32512,4161343,19456,2509862,65343,8388511,52275,6737023,38950,5019743,32543,4161359,19475,2509871,65407,8388543,52326,6737049,38988,5019762,32575,4161375,19494,2509881,65471,8388575,52377,6737074,39026,5019781,32607,4161391,19513,2509890,65535,8388607,52428,6737100,39064,5019800,32639,4161407,19532,2509900,49151,8380415,39372,6730444,29336,5014936,24447,4157311,14668,2507340,32767,8372223,26316,6724044,19608,5010072,16255,4153215,9804,2505036,16383,8364031,13260,6717388,9880,5005208,8063,4149119,4940,2502476,255,8355839,204,6710988,152,5000344,127,4145023,76,2500172,4129023,10452991,3342540,8349388,2490520,6245528,2031743,5193599,1245260,3089996,8323327,12550143,6684876,10053324,4980888,7490712,4128895,6242175,2490444,3745356,12517631,14647295,10027212,11691724,7471256,8735896,6226047,7290751,3735628,4335180,16711935,16744447,13369548,13395660,9961624,9981080,8323199,8339327,4980812,4990540,16711871,16744415,13369497,13395634,9961586,9981061,8323167,8339311,4980793,4990530,16711807,16744383,13369446,13395609,9961548,9981042,8323135,8339295,4980774,4990521,16711743,16744351,13369395,13395583,9961510,9981023,8323103,8339279,4980755,4990511,3355443,5987163,8684676,11382189,14079702,16777215],rd=["PROXY","REGION","INSERT","HATCH"];function ki(c){return nd[c]}function Xe(c){const t={};let e=c.lastReadGroup,i=e.code;if(t.x=e.value,i+=10,e=c.next(),e.code!==i)throw new Error("Expected code for point value to be "+i+" but got "+e.code);return t.y=e.value,i+=10,e=c.next(),e.code!==i||(t.z=e.value,c.next()),t}const ad="OriginalHandle",od="OriginalType",ld="Outlines";function ee(c,t){switch(t.code){case 0:c.type=t.value;break;case 5:c.handle=t.value;break;case 6:c.lineType=(t.value||"BYLAYER").toUpperCase();break;case 8:c.layer=t.value||"0";break;case 39:c.thickness=t.value;break;case 48:c.lineTypeScale=t.value>0?t.value:1;break;case 60:c.visible=t.value!==1;break;case 62:if(!c.isTrueColor){const e=t.value;c.colorIndex=e,e<0&&console.warn("[DxfParser] Negative colorIndex indicates layer is off or BYBLOCK/BYLAYER"),c.color=ki(Math.abs(e))}break;case 67:c.inPaperSpace=t.value===1;break;case 330:c.ownerHandle=t.value;break;case 370:c.lineweight=t.value;break;case 410:c.layoutName=t.value;break;case 420:c.isTrueColor=!0,c.color=t.value;break;case 1e3:if(t.value&&typeof t.value=="string"){if(t.value.includes(ad)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalHandle=e[1]}if(t.value.includes(ld)&&(c.extendedData||(c.extendedData={}),c.extendedData.outlines=[]),t.value.includes(od)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalType=e[1]}}break;case 1001:break;case 92:case 331:case 347:break;default:return!1}return!0}function zi(c,t){switch(t.code){case 0:c.type=t.value;break;case 5:c.handle=t.value;break;case 330:c.ownerHandle=t.value;break;case 1e3:break;case 1001:break;default:return!1}return!0}const Br="BYLAYER",gs="BYBLOCK";var Oe=(c=>(c[c.Mesh=-1]="Mesh",c[c.MeshWithPattern=0]="MeshWithPattern",c[c.LineWithWidth=1]="LineWithWidth",c[c.Line=2]="Line",c[c.LineWithPattern=3]="LineWithPattern",c[c.Point=4]="Point",c[c.Text=5]="Text",c))(Oe||{});const os=["INSERT","DIMENSION"];function cd(c,t,e,i,s){if(!t)return 0;const n=/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/.test(c),r=s&&s.toLowerCase().endsWith(".shx");let a=0,o=0;if(t.userData&&typeof t.userData.advanceWidth=="number")a=t.userData.advanceWidth,n||(a+=a*.15);else if(t.boundingBox){const l=new p.Vector3;t.boundingBox.getSize(l),a=l.x}if(c===" ")return a=e*.25,a;if(r)i>1?o=(i-1)*e*.1:o=a*.05;else{const l=e*.04;n?o=i>1?(i-1)*e*.1:0:o=i*l}return a+o}function hd(c){const t=/(\\M\+(?:[0-5])[0-9A-Fa-f]{4,})/g,e=c.match(t);if(!e)return c;let i=c;for(const s of e){const n=s.substring(4);if(n.length<4){console.error(`警告:提取的十六进制数 '${n}' 长度不足,已保留原始编码。`);continue}const r=n.substring(0,4),a=n.substring(4);try{const o=new Uint8Array(r.match(/.{1,2}/g).map(d=>parseInt(d,16))),h=new TextDecoder("gbk").decode(o);i=i.replace(s,h+a)}catch(o){console.error("转换失败:",o)}}return i}function va(c){const t=[];let e=c;const i=/\\[a-z]+\d*\.?\d*;?/g;return(c.match(i)||[]).forEach(n=>{e=e.replace(n,""),t.push(n)}),{formatCodes:t,plainText:e}}function dd(c,t){const e=va(c.text).plainText,i=va(t.text).plainText;return e===i}var Ve=(c=>(c.Added="Added",c.Removed="Removed",c.Modified="Modified",c.NoChange="NoChange",c))(Ve||{});let De=1;const Ct=class Ct{constructor(t,e,i={}){g(this,"dxf1");g(this,"dxf2");g(this,"changes");g(this,"comparedBlocks");g(this,"isComparingBlock");g(this,"isComparingDimension");g(this,"enableDetailComparision");if(this.changes={},this.comparedBlocks=new Map,this.isComparingBlock=!1,this.isComparingDimension=!1,this.enableDetailComparision=i.enableDetailComparision!=null?i.enableDetailComparision:!0,this.dxf1=t,this.dxf2=e,!t||!e)throw new Error("Invalid DXF data to compare!")}getLayerFrozen(t,e){const i=e.layer;if(!i)return;const s=t.tables?.layer?.layers;return s?s[i]?.frozen:void 0}async compare(t){this.changes={};const e=[],i=new Map;return this.dxf1.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf1,s)===!0;!Ct.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf2,s)===!0;!Ct.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&i.set(s.handle,s)}}),await this.compareEntities(e,i,t),Promise.resolve(this.changes)}isDimensionBlock(t){return t.includes("*D")}compareInsertOrDemensionEntities(t,e,i,s){if(!t.block||!e.block)return;const n=t.block;let r;if(this.isComparingBlock=!0,this.isDimensionBlock(n)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,r=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,P.debug("[DxfCompare] compare block: "+n+" took "+(Date.now()-l)/1e3+"s")}else{if(!this.comparedBlocks.has(n)){const a=this.dxf1.blocks[n],o=this.dxf2.blocks[n],l=Date.now(),h=this.compareBlock(t,e,a,o);this.comparedBlocks.set(n,h),P.debug("[DxfCompare] compare block: "+n+" took "+(Date.now()-l)/1e3+"s")}r=this.comparedBlocks.get(n)}return r?.forEach(a=>{if(!a.parentHandles&&(a.parentHandles=[]),i&&s)a.type==="Added"?a.parentHandles.push(s):a.type==="Removed"&&a.parentHandles.push(i);else{const o=[...a.parentHandles,t.handle];a.type==="Added"?this.changes[De]={id:De,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[De]={id:De,...a,parentHandles:o}),De++}}),!i&&!s&&(this.isComparingBlock=!1),r}compareBlock(t,e,i,s){const n=[],r=[];i?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&n.push(l)}),s?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&r.push(l)});const a=[],o=[];for(let l=0;l<n.length;l++){const h=n[l];let d=!1;r.length===0&&(d=!0),!this.isComparingDimension&&(this.isComparingDimension=h.type==="DIMENSION");for(let u=0;u<r.length;u++){const f=r[u];if(!this.entitiesEqual(h,f,t,e))d=!0;else if(h.type==="INSERT"&&f.type==="INSERT"||h.type==="DIMENSION"&&f.type==="DIMENSION"){const m=this.compareInsertOrDemensionEntities(h,f,h.handle,f.handle);m&&m.length>0&&a.push(...m),d=!1,r.splice(u--,1);break}else{d=!1,r.splice(u--,1);break}}d&&(a.push({type:"Removed",handle:h.handle}),o.push(h.handle))}return r.forEach(l=>{!o.includes(l.handle)&&a.push({type:"Added",handle:l.handle})}),a}async compareEntities(t,e,i){const s=j.getUpdateProgressFuncForLoop(t.length,i);for(let n=0;n<t.length;n++){const r=t[n].handle;if(!e.has(r))this.changes[De]={id:De,type:"Removed",handle:r},De++;else{const a=t[n],o=e.get(r),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(os.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(r),P.warn("[DxfCompare] We cannot compare insert (handle '"+a.handle+"') yet, ignored!");continue}this.compareInsertOrDemensionEntities(a,o)}}else{if(a.extendedData?.originalType&&o.extendedData?.originalType&&a.block!==o.block){e.delete(r);continue}this.changes[De]={id:De,type:"Modified",handle:r},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[De].detailChanges=l),De++}e.delete(r)}await s(n)}for(const n of e){const r=n[0];this.changes[De]={id:De,type:"Added",handle:r},De++}}bIgnoreChildEntitiesOriginalType(t){return rd.includes(t.extendedData?.originalType)}entitiesEqual(t,e,i,s,n){if(!this.baseEntitiesEqual(t,e,i,s,n))return!1;const r=t.type;let a=!0;switch(r){case"CIRCLE":case"ARC":a=this.arcsEqual(t,e);break;case"LWPOLYLINE":case"LINE":a=this.linesEqual(t,e,n);break;case"POLYLINE":a=this.polylinesEqual(t,e);break;case"TEXT":a=this.textsEqual(t,e);break;case"SOLID":a=this.solidsEqual(t,e);break;case"POINT":a=this.pointsEqual(t,e);break;case"INSERT":a=this.insertsEqual(t,e);break;case"SPLINE":a=this.splinesEqual(t,e);break;case"MTEXT":a=this.mtextsEqual(t,e);break;case"ELLIPSE":a=this.ellipsesEqual(t,e);break;case"DIMENSION":a=this.dimensionsEqual(t,e);break;case"REGION":a=this.regionsEqual(t,e);break;case"ATTDEF":a=this.attDefsEqual(t,e);break;case"ATTRIB":a=this.attribsEqual(t,e);break;case"HATCH":a=this.hatchesEqual(t,e);break;case"VIEWPORT":a=this.viewportsEqual(t,e);break;case"LEADER":a=this.leadersEqual(t,e);break;case"MULTILEADER":a=this.mleadersEqual(t,e);break;case"OLE2FRAME":a=this.ole2framesEqual(t,e);break;case"SEQEND":a=!0;break;default:a=!1}return a}getColor(t,e,i){if(t.isTrueColor||t.colorIndex>0&&t.colorIndex<256)return t.color;if(t.colorIndex===0)return i?this.getColor(i,e):e.tables?.layer?.layers[0].color;let s=0;if(t.colorIndex===256){const n=e.tables?.layer?.layers,r=n&&n[t.layer],a=n&&i&&n[i.layer];r&&r.name!=="0"?s=r.color:a?s=a.color:r?s=r.color:s=e.tables?.layer?.layers[0].color}return s}getLineType(t,e,i){if(i&&i.type==="DIMENSION")return this.getLineType(i,e);if(t.lineType!==Br&&t.lineType!==gs)return t.lineType;if(t.lineType===gs)return i?this.getLineType(i,e):t.lineType;const s=e.tables?.layer?.layers,n="CONTINUOUS";if(t.layer!=="0"){const r=s&&s[t.layer];if(r)return r.lineType}else if(i){const r=s&&s[i.layer];if(r)return r.lineType}return n}addModificationItem(t,e,i,s){s&&(s[i]={old:t,new:e})}baseEntitiesEqual(t,e,i,s,n){let r=!0;const a=this.getColor(t,this.dxf1,i),o=this.getColor(e,this.dxf2,s);if(a!==o)if(r=!1,this.enableDetailComparision)this.addModificationItem(a,o,"color",n);else return r;const l=this.getLineType(t,this.dxf1,i),h=this.getLineType(e,this.dxf2,s);if(l!==h){if(r=!1,this.enableDetailComparision)this.addModificationItem(l,h,"lineType",n);else return r;return!1}return t.extendedData?.originalType!==e.extendedData?.originalType||!this.isComparingBlock&&!this.isComparingDimension&&t.handle!==e.handle||!this.isComparingDimension&&t.ownerHandle!==e.ownerHandle||t.type!==e.type?!1:r}arcsEqual(t,e){return!(!this.vectorsEqual(t.center,e.center)||!this.numberEqual(t.radius,e.radius)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}linesEqual(t,e,i){let s=!0;const n=t.constantWidth,r=e.constantWidth;if(!this.numberEqual(n,r))if(s=!1,this.enableDetailComparision)this.addModificationItem(n||0,r||0,"constantWidth",i);else return!1;return!this.verticesEqual(t.vertices,e.vertices)||t.shape!==e.shape?!1:s}polylinesEqual(t,e){return!(!this.vertexEntitiesEqual(t.vertices,e.vertices)||t.shape!==e.shape||t.isPolyfaceMesh!==e.isPolyfaceMesh)}textsEqual(t,e){if(t.halign!==e.halign)return!1;if(t.halign===3||t.halign===5){if(!this.pointsEqual(t.startPoint,e.startPoint))return!1}else if(!this.pointsEqual(t.endPoint,e.endPoint))return!1;return t.text===e.text}solidsEqual(t,e){return!!this.verticesEqual(t.points,e.points)}pointEntitiesEqual(t,e){return!!this.pointsEqual(t.position,e.position)}splinesEqual(t,e){return!(!this.verticesEqual(t.controlPoints,e.controlPoints)||!this.numbersEqual(t.knotValues,e.knotValues)||!this.numberEqual(t.degreeOfSplineCurve,e.degreeOfSplineCurve))}mtextsEqual(t,e,i={}){const{compareFormat:s=!1,comparePosition:n=!0}=i;if(n&&!this.pointsEqual(t.position,e.position))return!1;if(s){if(t.text!==e.text)return!1}else if(!dd(t,e))return!1;return!!this.numberEqual(t.rotation,e.rotation)}ellipsesEqual(t,e){return!(!this.pointsEqual(t.center,e.center)||!this.pointsEqual(t.majorAxisEndPoint,e.majorAxisEndPoint)||!this.numberEqual(t.axisRatio,e.axisRatio)||!this.numberEqual(t.startAngle,e.startAngle)||!this.numberEqual(t.endAngle,e.endAngle))}attDefsEqual(t,e){return!(!this.pointsEqual(t.startPoint,e.startPoint)||!this.pointsEqual(t.endPoint,e.endPoint)||!this.numberEqual(t.xScale,e.xScale)||t.text!==e.text||t.tag!==e.tag||t.prompt!==e.prompt)}attribsEqual(t,e){return this.attDefsEqual(t,e)}hatchesEqual(t,e){const i=t,s=e;return!(!this.numberEqual(i.elevationX,s.elevationX)||!this.numberEqual(i.elevationY,s.elevationY)||!this.numberEqual(i.elevationZ,s.elevationZ)||!this.hatchBoundaryPathArraysEqual(i.boundaryPaths,s.boundaryPaths))}viewportsEqual(t,e){const i=t,s=e;return!(!this.pointsEqual(i.centerPoint,s.centerPoint)||!this.pointsEqual(i.centerPoint_dcs,s.centerPoint_dcs)||!this.pointsEqual(i.viewDirection,s.viewDirection)||!this.numberEqual(i.viewHeight,s.viewHeight)||i.width_paperSpace!==s.width_paperSpace||i.height_paperSpace!==s.height_paperSpace)}leadersEqual(t,e){return!(!this.pointsEqual(t.position,e.position)||!this.verticesEqual(t.vertices,e.vertices)||t.arrowHeadBlockHandle!==e.arrowHeadBlockHandle||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)||!this.numberEqual(t.rotation,e.rotation)||t.block!==e.block)}mleadersEqual(t,e){return t.arrowHeadId!==e.arrowHeadId||!this.numberEqual(t.arrowHeadSize,e.arrowHeadSize)?!1:this.mleaderContextEqual(t.contextData,e.contextData)}ole2framesEqual(t,e){return!(t.leftUpX!==e.leftUpX||t.leftUpY!==e.leftUpY||t.leftUpZ!==e.leftUpZ||t.rightDownX!==e.rightDownX||t.rightDownY!==e.rightDownY||t.rightDownZ!==e.rightDownZ)}insertsEqual(t,e){return t.extendedData?.originalType==="INSERT"&&e.extendedData?.originalType==="INSERT"?(P.warn("[DxfCompare] We cannot compare insert (handle '"+t.handle+"') yet, ignored!"),!0):!(!this.pointsEqual(t.position,e.position)||!this.numberEqual(t.xScale===void 0?1:t.xScale,e.xScale===void 0?1:e.xScale)||!this.numberEqual(t.yScale===void 0?1:t.yScale,e.yScale===void 0?1:e.yScale)||!this.numberEqual(t.zScale===void 0?1:t.zScale,e.zScale===void 0?1:e.zScale)||t.block!==e.block||t.entities?.length!==e.entities?.length)}dimensionsEqual(t,e){return!!this.pointsEqual(t.anchorPoint,e.anchorPoint)}regionsEqual(t,e){return P.warn("Cannot compare region yet!"),!0}vectorsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z):!1}pointsEqual(t,e){return!t&&!e?!0:t&&e?this.numberEqual(t.x,e.x)&&this.numberEqual(t.y,e.y)&&this.numberEqual(t.z,e.z)&&this.numberEqual(t.bulge,e.bulge):!1}vertexEntityEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t,e)||t.polyfaceMeshVertex!==e.polyfaceMeshVertex||t.threeDPolylineMesh!==e.threeDPolylineMesh):!1}numbersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.numberEqual(t[i],e[i]))return!1;return!0}return!1}numberEqual(t,e){return t==null&&e==null?!0:t!=null&&e!=null?z.areNumbersEqual(t,e):!1}vectorArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vectorsEqual(t[i],e[i]))return!1;return!0}return!1}verticesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.pointsEqual(t[i],e[i]))return!1;return!0}return!1}verticesArrayEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.verticesEqual(t[i],e[i]))return!1;return!0}return!1}vertexEntitiesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.vertexEntityEqual(t[i],e[i]))return!1;return!0}return!1}hatchEdgesEqual(t,e){return!t&&!e?!0:t&&e?t.type===e.type:!1}hatchEdgeArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchEdgesEqual(t[i],e[i]))return!1;return!0}return!1}hatchBoundaryPathsEqual(t,e){return!t&&!e?!0:t&&e?t.pathTypeFlag!==e.pathTypeFlag?!1:this.hatchEdgeArraysEqual(t.edges,e.edges):!1}hatchBoundaryPathArraysEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.hatchBoundaryPathsEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLineEqual(t,e){return!t&&!e?!0:t&&e?!(!this.verticesArrayEqual(t.vertices,e.vertices)||t.leaderLineIndex!==e.leaderLineIndex):!1}mleaderLinesEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLineEqual(t[i],e[i]))return!1;return!0}return!1}mleaderLeaderEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.lastLeaderLinePoint,e.lastLeaderLinePoint)||!this.pointsEqual(t.doglegVector,e.doglegVector)||!this.mleaderLinesEqual(t.leaderLines,e.leaderLines)):!1}mleaderLeadersEqual(t,e){if(!t&&!e)return!0;if(t&&e){if(t.length!==e.length)return!1;for(let i=0;i<t.length;++i)if(!this.mleaderLeaderEqual(t[i],e[i]))return!1;return!0}return!1}mleaderContextEqual(t,e){return!t&&!e?!0:t&&e?!(!this.pointsEqual(t.contentBasePosition,e.contentBasePosition)||!this.pointsEqual(t.blockContentPosition,e.blockContentPosition)||!this.mleaderLeadersEqual(t.leaders,e.leaders)):!1}compareHexStrings(t,e){return parseInt(t,16)-parseInt(e,16)}};g(Ct,"ENTITY_COLOR_ADDED",65280),g(Ct,"ENTITY_COLOR_REMOVED",16711680),g(Ct,"ENTITY_COLOR_NO_CHANGE",10066329),g(Ct,"ENTITY_COLOR_MARKUP",16744231),g(Ct,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let at=Ct;var G=(c=>(c[c.Object=0]="Object",c[c.Point=1]="Point",c[c.Line=2]="Line",c[c.LineSegment=3]="LineSegment",c[c.Mesh=4]="Mesh",c))(G||{});const Hn=new D.Box3,Nn=new D.Matrix4;class V{constructor(t=0){g(this,"name");g(this,"type");g(this,"matrix");g(this,"parent");g(this,"children");g(this,"layers");g(this,"renderOrder");g(this,"userData");g(this,"material");g(this,"geometry");g(this,"matrixWorld");this.name="",this.type=0,this.matrix=new D.Matrix4,this.children=[],this.layers=new D.Layers,this.renderOrder=0,this.userData={},this.type=t}add(t,...e){for(let i=0;i<e.length;i++)this.add(e[i]);return t===this?(console.error("object can't be added as a child of itself.",t),this):(t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),this)}remove(t,...e){for(let s=0;s<e.length;s++)this.remove(e[s]);const i=this.children.indexOf(t);return i!==-1&&(t.parent=void 0,this.children.splice(i,1)),this}removeFromParent(){const t=this.parent;return t&&t.remove(this),this}clear(){this.material=void 0,this.geometry=void 0;for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=void 0}return this.children.length=0,this}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}clone(t=!0){return new V().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.type=t.type,this.matrix.copy(t.matrix),this.layers.mask=t.layers.mask,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),this.material=t.material,this.geometry=t.geometry,e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}convertToThreejsObject(t=!0){let e;switch(this.type){case 0:e=new D.Object3D;break;case 1:if(!this.geometry)return;e=new p.Points(this.geometry,this.material);break;case 2:if(!this.geometry)return;e=new p.Line(this.geometry,this.material);break;case 3:if(!this.geometry)return;e=new p.LineSegments(this.geometry,this.material);break;case 4:if(!this.geometry)return;e=new p.Mesh(this.geometry,this.material);break}if(e){if(e.name=this.name,e.matrixAutoUpdate=ct,e.applyMatrix4(this.matrix),e.layers.mask=this.layers.mask,e.renderOrder=this.renderOrder,e.userData=this.userData,t===!0)for(let i=0;i<this.children.length;i++){const s=this.children[i],n=s.convertToThreejsObject(t);n&&e.add(n)}return e}}static getBox(t,e,i){if(t.geometry)!t.geometry.boundingBox&&t.geometry.computeBoundingBox(),Nn.copy(t.matrix),i&&Nn.premultiply(i),Hn.copy(t.geometry.boundingBox),Hn.applyMatrix4(Nn),e.union(Hn);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new D.Matrix4),t.matrixWorld.copy(t.matrix),i&&t.matrixWorld.premultiply(i);const s=t.children;for(let n=0,r=s.length;n<r;n++)this.getBox(s[n],e,t.matrixWorld)}return e}computeBoundingllBox(t,e,i){const s={x:0,y:0};s.x=e.position?.x||0,s.y=e.position?.y||0;let n=e.blockPosition?.x||0,r=e.blockPosition?.y||0;s.x=s.x-n,s.y=s.y-r;const a=new D.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new D.Box3;!l.geometry&&l.children&&l.children.length===1;)l={...l.children[0],loneMatrix:l.matrix};if(l.geometry){!l.geometry.boundingBox&&l.geometry.computeBoundingBox();const h=new D.Box3().copy(l.geometry.boundingBox);h.applyMatrix4(l.loneMatrix||l.matrix),o.push({min:{x:h.min.x,y:h.min.y,z:h.min.z},max:{x:h.max.x,y:h.max.y,z:h.max.z},positions:[{x:h.min.x+s.x,y:h.min.y+s.y},{x:h.min.x+s.x,y:h.max.y+s.y},{x:h.max.x+s.x,y:h.max.y+s.y},{x:h.max.x+s.x,y:h.min.y+s.y}],rotation:e.rotation,center:{x:(h.min.x+h.max.x)/2+s.x,y:(h.min.y+h.max.y)/2+s.y,z:(h.min.z+h.max.z)/2},size:{x:h.max.x-h.min.x,y:h.max.y-h.min.y,z:h.max.z-h.min.z}}),a.union(h)}}),!a.isEmpty()&&a.max.x-a.min.x<20&&a.max.y-a.min.y<20?t.userData.boundingBoxs=[{min:{x:a.min.x,y:a.min.y,z:a.min.z},max:{x:a.max.x,y:a.max.y,z:a.max.z},positions:[{x:a.min.x+s.x,y:a.min.y+s.y},{x:a.min.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.max.y+s.y},{x:a.max.x+s.x,y:a.min.y+s.y}],rotation:e.rotation,center:{x:(a.min.x+a.max.x)/2+s.x,y:(a.min.y+a.max.y)/2+s.y,z:(a.min.z+a.max.z)/2},size:{x:a.max.x-a.min.x,y:a.max.y-a.min.y,z:a.max.z-a.min.z}}]:t.userData.boundingBoxs=o}rotateRectByBottomLeft(t,e,i,s,n){const r=i-t,a=s-e,o=n*Math.PI/180,l=Math.cos(o),h=Math.sin(o);return[{dx:0,dy:0},{dx:r,dy:0},{dx:r,dy:a},{dx:0,dy:a}].map(u=>{const f=u.dx*l-u.dy*h,m=u.dx*h+u.dy*l;return{x:t+f,y:e+m}})}}const Ns=new p.Matrix4,ud=new p.Matrix4;class Tt{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},n=[];for(let h=0;h<i;++h){const d=t.children[h];if(d.children.length>0){this.mergeInner(d,e);continue}if(d.userData.relativeToCenter||!d.geometry)continue;let f=!1;const m=Object.values(s);for(let b=m.length-1;b>=0;--b){const y=m[b].indexes[0];if(f=this.tryHandleMergeableObjects(t,h,y,s,n),f)break}for(let b=n.length-1;!f&&b>=0;--b){const y=n[b];if(f=this.tryHandleMergeableObjects(t,h,y,s,n),f)break}!f&&n.push(h)}if(Object.keys(s).length<=0)return;const r=[],a=[],o=[],l=[];Object.values(s).forEach(h=>{const d=h.indexes,u=t.children[d[0]];let f=[],m=0,b=0,y=0;const C=[];if(d.forEach(x=>{const E=t.children[x],M=E.geometry?.clone();if(M.applyMatrix4(E.matrix),M.userData.isLineSegments=E.type===G.LineSegment,f.push(M),e){const O=M.attributes?.position?.count,S=M.index?.count||0;C.push({batchId:m,positionStart:b,positionCount:O,indexStart:y,indexCount:S}),b+=O,y+=S,m++}}),f.length===0)return;let w;if(u.type===G.Mesh){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new V(u.type),w.geometry=x,w.material=u.material,r.push(w)}else if(u.type===G.Line||u.type===G.LineSegment){const x=fe.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,C);if(!x)return;w=new V(G.LineSegment),w.geometry=x,w.material=u.material,a.push(w)}else if(u.type===G.Point){const x=Pe.mergeGeometries(f);if(!x)return;x.userData={},w=new V(u.type),w.geometry=x,w.material=u.material,o.push(w)}w&&(e?w.userData.batches=C:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,l.push(...d)),f.forEach(x=>{x.dispose(),N.releaseGeometryManually(x)}),f=[]}),l.sort((h,d)=>d-h),l.forEach(h=>{const d=t.children[h];t.remove(d)}),[...r,...a,...o].forEach(h=>{t.add(h)}),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=r.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,n){let r=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return r;const l=a?t[e]:t.children[e],h=a?t[i]:t.children[i];return this.areObjectsMergeable(l,h)&&fe.areGeometriesMergeable(l.geometry,h.geometry)&&xe.materialsEquals(l.material,h.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(n,i)),s[i].indexes.push(e),r=!0),r}static isFilteredByOtherFactors(t,e){const i=t;if(i.type===G.Mesh&&i.material&&i.material.isShaderMaterial)return!0;let s=!1,n=t;for(;n&&n!==e;){const r=n.userData;if(r.relativeToCenter||r.spatialFilterHandle){s=!0;break}n=n.parent}return s}static deepMerge(t,e=void 0,i=!0,s=!0,n=!0){const r={added:[],removed:[]};if(t.length<=1)return r;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){if(!t[y].geometry||this.isFilteredByOtherFactors(t[y],e))continue;let w=!1;const x=Object.values(o);for(let E=x.length-1;E>=0;--E){const M=x[E].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let E=l.length-1;!w&&E>=0;--E){const M=l[E];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}!w&&l.push(y)}if(Object.keys(o).length<=0)return r;P.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const h=[],d=[],u=[],f=[];Object.values(o).forEach(y=>{const C=y.indexes;if(C.length<2)return;const w=t[C[0]];let x=[],E=0,M=0,O=0;const S=[];if(C.forEach(T=>{const _=t[T],A=_.geometry?.clone();if(w.material instanceof p.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,_,e),A.userData.isLineSegments=_.type===G.LineSegment,x.push(A),n){const I=A.attributes?.position?.count,B=A.index?.count||0;let k;(w.type===G.Line||w.type===G.LineSegment)&&(!A.boundingSphere&&A.computeBoundingSphere(),k=A.boundingSphere?.clone());const L={batchId:E,positionStart:M,positionCount:I,indexStart:O,indexCount:B,boundingSphere:k};Object.keys(_.userData).length!==0&&(L.userData=_.userData),S.push(L),M+=I,O+=B,E++}}),x.length===0)return;let v;if(w.type===G.Mesh){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new V(w.type),v.geometry=T,v.material=w.material,h.push(v)}else if(w.type===G.Line||w.type===G.LineSegment){const T=fe.mergeLineGeometries(x,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,S);if(!T)return;v=new V(G.LineSegment),v.geometry=T,v.material=w.material,d.push(v)}else if(w.type===G.Point){const T=Pe.mergeGeometries(x);if(!T)return;T.userData={},v=new V(w.type),v.geometry=T,v.material=w.material,u.push(v)}v&&(n?v.userData.batches=S:(v.userData=w.userData,v.userData.batches=void 0),v.userData.layerName=w.userData.layerName,v.name="[Merged] "+w.name,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,C.forEach(T=>f.push(T))),x.forEach(T=>{T.dispose(),N.releaseGeometryManually(T)}),x=[]}),P.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(y=>{const C=t[y];m.push(C),i&&C.removeFromParent()});const b=r.added;return[...h,...d,...u].forEach(y=>{b.push(y),i&&e&&e.add(y)}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&J.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Ns.identity();s&&s!==i&&(Ns.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ns.equals(ud)?t:t.applyMatrix4(Ns)}static removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}static areObjectsMergeable(t,e){return t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===G.Line||t.type===G.LineSegment)&&(e.type===G.Line||e.type===G.LineSegment)}}g(Tt,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const Do=(c,t)=>{if(typeof t>"u"||+t==0)return Math.round(c);let e=+c;if(t=+t,isNaN(e)||!(typeof t=="number"&&t%1===0))return NaN;let i=e.toString().split("e");return e=Math.round(+(i[0]+"e"+(i[1]?+i[1]-t:-t))),i=e.toString().split("e"),+(i[0]+"e"+(i[1]?+i[1]+t:t))},Lo=(c,t,e,i,s)=>{const n=e.length,r=e[0].length;if(c<0||c>1)throw new Error("t out of bounds [0,1]: "+c);if(t<1)throw new Error("degree must be at least 1 (linear)");if(t>n-1)throw new Error("degree must be less than or equal to point count - 1");if(i){if(i.length!==n+t+1)throw new Error("bad knot vector length")}else{i=[];for(let m=0;m<n+t+1;m++)i[m]=m}const a=[t,i.length-1-t],o=i[a[0]],l=i[a[1]];c=c*(l-o)+o,c=Math.max(c,o),c=Math.min(c,l);let h;for(h=a[0];h<a[1]&&!(c>=i[h]&&c<=i[h+1]);h++);const d=[];for(let m=0;m<n;m++){d[m]=[];const b=s?s[m]:1;for(let y=0;y<r;y++)d[m][y]=e[m][y]*b;d[m][r]=b}let u;for(let m=1;m<=t+1;m++)for(let b=h;b>h-t-1+m;b--){u=(c-i[b])/(i[b+t+1-m]-i[b]);for(let y=0;y<r+1;y++)d[b][y]=(1-u)*d[b-1][y]+u*d[b][y]}const f=[];for(let m=0;m<r;m++)f[m]=Do(d[h][m]/d[h][r],-9);return f},fd={d:"°",c:"⌀",p:"±"},ls=(c,t)=>{if(!c)return[];c=c.replace(/%%(.)/g,(o,l)=>fd[l]||l).replace(/\^I/g," ");const e=t?.encoding;let i=e instanceof TextDecoder?e:void 0,s="",n;const r=[],a=o=>{s&&(r.push(s),s=""),r.push(o)};for(let o=0;o<c.length;o++)switch(n=c[o]){default:s+=n;break;case"\\":{switch(n=c[++o]){default:s+=n;break;case"p":{const l=c.slice(o,o=c.indexOf(";",o));l.startsWith("pxq")||l.startsWith("pxi")||l.startsWith("pxt")||l.startsWith("pt")||l.startsWith("pi")||(l.startsWith("psm")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):l.startsWith("pq")?a({[l.slice(0,l.length-1)]:l[l.length-1]}):a({[l.slice(0,l.length-1)]:l[l.length-1]}));break}case"P":s+=`
536
+ `;break;case"f":case"F":{let l="";for(;n=c[++o];){if(n===";"){a({f:l});break}if(n==="|"){const h={f:l},d=c.indexOf(";",++o);for(const u of c.slice(o,d).split("|"))h[u[0]]=+u.slice(1);o=d,a(h);break}l+=n==="\\"?c[++o]:n}break}case"S":{let l="",h,d="";for(;n=c[++o];){if(n===";"){const u=l+d;u&&a(u);break}if(n==="\\"){const u=c[++o];h?d+=u:l+=u}else!h&&(n==="^"||n==="/"||n==="#")?h=n:h?d+=n:l+=n}break}case"H":case"W":{const l=++o,[,h,d]=c.slice(l,o=c.indexOf(";",o)).match(/^(\d*(?:\.\d+)?)(\D*)$/);a({[n]:[+h,d]})}break;case"Q":case"A":case"C":case"c":case"T":{const l=++o;a({[n]:+c.slice(l,o=c.indexOf(";",o))});break}case"L":case"O":case"K":a({[n]:1});break;case"l":case"o":case"k":a({[n.toUpperCase()]:0});break;case"U":case"u":c[o+1]==="+"?(s+=String.fromCodePoint(parseInt(c.substr(o+2,4),16)),o+=5):s+=n;break;case"M":case"m":e?c[o+1]==="+"&&(c[o+2]==="0"||c[o+2]==="1")?(s+=(i=i||new TextDecoder(e)).decode(new Uint8Array([parseInt(c.substr(o+3,2),16),parseInt(c.substr(o+5,2),16)])),o+=6):s+=n:s+="\\"+n;break}break}case"{":{let l=1;const h=o;for(;n=c[++o];)if(n==="{")l++;else if(n==="}"){if(--l===0){a(ls(c.slice(h+1,o)));break}}else n==="\\"&&o++;break}}return s&&r.push(s),r},pd={d:"°",c:"⌀",p:"±"},Ro=(c,t)=>(c=Fo(c),t?zo(c,t):c),Fo=c=>c.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),zo=(c,t)=>{let e=t instanceof TextDecoder?t:new TextDecoder(t);return c.replace(/\\[mM]\+[0|1]([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,(i,s,n)=>(e=e||new TextDecoder(t)).decode(new Uint8Array([parseInt(s,16),parseInt(n,16)])))},cn=(c,t)=>{c=Ro(c,t?.encoding);let e=0,i={text:""};const s=[i],n=c.matchAll(/%%(\d\d\d|.)/g);for(const r of n){i.text+=c.slice(e,r.index);const a=r[1],o=a.toLowerCase(),l=pd[o];l?i.text+=l:o.length===3?i.text+=String.fromCodePoint(+o):o==="k"||o==="o"||o==="u"?(i=Object.assign(Object.assign({},i),{text:""}),i[o]?delete i[o]:i[o]=1,s.push(i)):i.text+=o,e=r.index+r[0].length}return i.text+=c.slice(e),s.filter(r=>r.text)};class Vo{static createLineShaderMaterial(t,e,i,s,n){let r=0;const a=[];for(let d=0;d<t.length;d++)a[d]=t[d],a[d]===0&&(a[d]=.5),a[d]*=i,r+=Math.abs(a[d]);const o=p.UniformsUtils.merge([p.UniformsLib.common,{pattern:{value:a},patternLength:{value:r},u_color:{value:new p.Color(e)}}]);o.u_viewportScale=s,o.u_cameraZoom=n;const l=`
537
537
  attribute float lineDistance;
538
538
  varying float vLineDistance;
539
539
 
@@ -588,7 +588,7 @@ void main() {
588
588
  }
589
589
  }
590
590
  #include <colorspace_fragment>
591
- }`;return new p.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:h,clipping:!0})}}function Vo(c,t,e,i,s=0){const n={u_cameraZoom:e,u_patternLines:{value:c},u_patternAngle:{value:t},u_color:{value:i}},r=`
591
+ }`;return new p.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:h,clipping:!0})}}function jo(c,t,e,i,s=0){const n={u_cameraZoom:e,u_patternLines:{value:c},u_patternAngle:{value:t},u_color:{value:i}},r=`
592
592
  varying vec3 v_pos;
593
593
 
594
594
  #include <clipping_planes_pars_vertex>
@@ -788,14 +788,14 @@ void main() {
788
788
  gl_FragColor = vec4(u_color * total, 1.0);
789
789
  #include <colorspace_fragment>
790
790
  }
791
- `;return new p.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:a,clipping:!0})}var Ze=(c=>(c.Unitless="Unitless",c.Inches="Inches",c.Feet="Feet",c.Millimeters="Millimeters",c.Centimeters="Centimeters",c.Meters="Meters",c))(Ze||{});const vr=c=>c==="Unitless"?1:c==="Inches"?.0254:c==="Feet"?.3048:c==="Millimeters"?.001:c==="Centimeters"?.01:(c==="Meters"||console.warn("[Units] Unsupported unit '"+c+"', will return 1 for unit scale."),1),md=(c,t)=>vr(c)/vr(t);class jo{constructor(){g(this,"pointer");g(this,"eof");g(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class vs{constructor(t,e){g(this,"endian");g(this,"position");g(this,"data");g(this,"decoder");this.endian=e&&e==="big"?"big":"little",this.position=0,this.data=new DataView(t)}readAsciiString(t){if(this.data.byteLength<this.position+t)throw"range error";let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.data.getInt8(this.position+i));return this.position+=t,e}readUtf8String(t){const e=this.readBytes(t);return this.decoder||(this.decoder=new TextDecoder("utf-8")),this.decoder.decode(e)}readBytes(t=1){if(this.data.byteLength<this.position+t)throw"range error";const e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=this.data.getUint8(this.position+i);return this.position+=t,e}readUint8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getUint8(this.position);return this.position+=1,t}readInt8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getInt8(this.position);return this.position+=1,t}readUint16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getUint16(this.position,this.endian==="little");return this.position+=2,t}readInt16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getInt16(this.position,this.endian==="little");return this.position+=2,t}readUint32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getUint32(this.position,this.endian==="little");return this.position+=4,t}readInt32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getInt32(this.position,this.endian==="little");return this.position+=4,t}readFloat32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getFloat32(this.position,this.endian==="little");return this.position+=4,t}readFloat64(){if(this.data.byteLength<this.position+8)throw"range error";const t=this.data.getFloat64(this.position,this.endian==="little");return this.position+=8,t}readInt64(){if(this.data.byteLength<this.position+8)throw"range error";const t=Ms.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,Ms.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=Ms.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,Ms.toNumber(t)}getPosition(){return this.position}setPosition(t){if(this.data.byteLength<t)throw"range error";this.position=t}isEnd(){return this.position===this.data.byteLength-1}}const Ta=1e3;class gd extends jo{constructor(e){super();g(this,"reader");g(this,"decoder");g(this,"int8Array");g(this,"caches");this.int8Array=new Int8Array(Ta),this.caches=new Map,this.reader=new vs(e);const i=this.reader.readBytes(22);let s="";for(let n=0;n<18;n++)s+=String.fromCharCode(i[n]);if(s!=="AutoCAD Binary DXF")throw new Error("Invalid DXF file")}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file.");const e={code:this.reader.readInt16()};return e.value=this.parseGroupValue(e.code),e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return this.eof?!1:!this.reader.isEnd()}isEOF(){return this.eof}parseGroupValue(e){if(e>=0&&e<=9)return this.readNullTerminatedString();if(e>=10&&e<=59)return this.reader.readFloat64();if(e>=60&&e<=79)return this.reader.readInt16();if(e>=90&&e<=99)return this.reader.readInt32();if(e>=100&&e<=109)return this.readNullTerminatedString();if(e>=110&&e<=149)return this.reader.readFloat64();if(e>=160&&e<=169)return this.reader.readInt64();if(e>=170&&e<=179)return this.reader.readInt16();if(e>=210&&e<=239)return this.reader.readFloat64();if(e>=270&&e<=289)return this.reader.readInt16();if(e>=290&&e<=299)return this.reader.readInt8()>0;if(e>=300&&e<=309)return this.readNullTerminatedString();if(e>=310&&e<=319){const i=this.ReadBinaryData();return Ca(i)}if(e>=320&&e<=369)return this.readNullTerminatedString();if(e>=370&&e<=389)return this.reader.readInt16();if(e>=390&&e<=399)return this.readNullTerminatedString();if(e>=400&&e<=409)return this.reader.readInt16();if(e>=410&&e<=419)return this.readNullTerminatedString();if(e>=420&&e<=429)return this.reader.readInt32();if(e>=430&&e<=439)return this.readNullTerminatedString();if(e>=440&&e<=449)return this.reader.readInt32();if(e>=450&&e<=459)return this.reader.readFloat64();if(e>=460&&e<=469)return this.readNullTerminatedString();if(e>=470&&e<=479)return this.readNullTerminatedString();if(e>=480&&e<=481)return this.readNullTerminatedString();if(e>=999&&e<=999)throw new Error("The comment group 999, is not used in binary DXF files at byte address!");if(e===1004){const i=this.ReadBinaryData();return Ca(i)}if(e>=1e3&&e<=1009)return this.readNullTerminatedString();if(e>=1010&&e<=1059)return this.reader.readFloat64();if(e>=1060&&e<=1070)return this.reader.readInt16();if(e===1071)return this.reader.readInt32();console.warn("[DxfBinReader] Invalid code '"+e+"' at byte address "+this.reader.getPosition())}readNullTerminatedString(){this.decoder||(this.decoder=new TextDecoder("utf-8"));let e=0,i=this.reader.readInt8();for(;i!==0;)this.int8Array[e++]=i,i=this.reader.readInt8();if(e===0)return"";if(e>Ta)return console.warn("[DxfBinReader] Failed to read string! The number of bytes is "+e+" !"),"";const s=this.int8Array.subarray(0,e),n=s.toString();if(this.caches.get(n))return this.caches.get(n);const r=this.decoder?.decode(s);return this.caches.set(n,r),r}ReadBinaryData(){const e=this.reader.readUint8();return this.reader.readBytes(e)}}function Ca(c){return Array.prototype.map.call(c,t=>("00"+t.toString(16)).slice(-2)).join("")}class Sa extends jo{constructor(e){super();g(this,"data");this.data=e}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this.data[this.pointer]);const e={code:parseInt(this.data[this.pointer])};return this.pointer++,e.value=yd(e.code,this.data[this.pointer].trim(),this.data[this.pointer]),this.pointer++,e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return!(this.eof||this.pointer>this.data.length-2)}isEOF(){return this.eof}}function yd(c,t,e){return c>=0&&c<=9?e:c>=10&&c<=59?parseFloat(t):c>=60&&c<=99?parseInt(t):c>=100&&c<=109?t:c>=110&&c<=149?parseFloat(t):c>=160&&c<=179?parseInt(t):c>=210&&c<=239?parseFloat(t):c>=270&&c<=289?parseInt(t):c>=290&&c<=299?xd(t):c>=300&&c<=369?t:c>=370&&c<=389?parseInt(t):c>=390&&c<=399?t:c>=400&&c<=409?parseInt(t):c>=410&&c<=419?t:c>=420&&c<=429?parseInt(t):c>=430&&c<=439?t:c>=440&&c<=449?parseInt(t):c>=450&&c<=459?parseFloat(t):c>=460&&c<=469||c===999||c>=1e3&&c<=1009?t:c>=1010&&c<=1059?parseFloat(t):c>=1060&&c<=1071?parseInt(t):(console.info("WARNING: Group code does not have a defined type: %j",{code:c,value:t}),t)}function xd(c){if(c==="0")return!1;if(c==="1")return!0;throw TypeError("String '"+c+"' cannot be cast to Boolean type")}function bd(c){if(c==null)return!0;for(const t in c)if(Object.prototype.hasOwnProperty.call(c,t))return!1;return!0}function wd(c,t){const e=[];let i=!1,s=!1;const n=4;for(let r=0;r<=n;r++){const a={};for(;!c.isEOF()&&!(t.code===0||s);){switch(t.code){case 10:case 11:case 12:case 13:if(i){s=!0;continue}a.x=t.value,i=!0;break;case 20:case 21:case 22:case 23:a.y=t.value;break;case 30:case 31:case 32:case 33:a.z=t.value;break;default:return e}t=c.next()}bd(a)||e.push(a),i=!1,s=!1}return e}class vd{constructor(){g(this,"ForEntityName","3DFACE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:if(e.value!==0){const s=Math.log2(e.value)-1;i.vertices.splice(s,0,1)}e=t.next();break;case 10:i.vertices=wd(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Md{constructor(){g(this,"ForEntityName","ARC")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Td(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:i.endAngle=Math.PI/180*e.value,i.angleLength=i.endAngle-i.startAngle,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Td(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Cd{constructor(){g(this,"ForEntityName","ATTDEF")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=Ea(t),e=t.lastReadGroup;break;case 11:i.endPoint=Ea(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,i.halign=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,i.valign=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Ea(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Sd{constructor(){g(this,"ForEntityName","ATTRIB")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=Oa(t),e=t.lastReadGroup;break;case 11:i.endPoint=Oa(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,i.halign=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,i.valign=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Oa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Ed{constructor(){g(this,"ForEntityName","CIRCLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Od(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:const s=Math.PI/180*e.value;s<i.startAngle?i.angleLength=s+2*Math.PI-i.startAngle:i.angleLength=s-i.startAngle,i.endAngle=s,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Od(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class _d{constructor(){g(this,"ForEntityName","DIMENSION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 3:i.dimStyleName=e.value,e=t.next();break;case 10:i.anchorPoint=Jt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=Jt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=Jt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=Jt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=Jt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=Jt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=Jt(t),e=t.lastReadGroup;break;case 70:i.dimensionType=e.value,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 42:i.actualMeasurement=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 50:i.angle=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Jt(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Pd{constructor(){g(this,"ForEntityName","MULTILEADER")}parseEntity(t,e){const i={type:e.value};i.contextData={leaders:[]},e=t.next();const s=()=>{const o=i.contextData.leaders[i.contextData.leaders.length-1],l={vertices:[[]]};for(o.leaderLines.push(l);!t.isEOF();)switch(e.code){case 10:l.vertices[0].push(Ne(t)),e=t.lastReadGroup;break;case 305:return;default:e=t.next();break}},n=()=>{const o={leaderLines:[]};for(i.contextData.leaders.push(o);!t.isEOF();)switch(e.code){case 290:o.hasSetLastLeaderLinePoint=e.value,e=t.next();break;case 291:o.hasSetDoglegVector=e.value,e=t.next();break;case 10:o.lastLeaderLinePoint=Ne(t),e=t.lastReadGroup;break;case 11:o.doglegVector=Ne(t),e=t.lastReadGroup;break;case 90:o.leaderBranchIndex=e.value,e=t.next();break;case 40:o.doglegLength=e.value,e=t.next();break;case 303:return;case 304:s(),e=t.lastReadGroup;break;default:e=t.next();break}},r=()=>{for(;!t.isEOF();)switch(e.code){case 40:i.contextData.contentScale=e.value,e=t.next();break;case 10:i.contextData.contentBasePosition=Ne(t),e=t.lastReadGroup;break;case 145:i.contextData.landingGap=e.value,e=t.next();break;case 290:i.contextData.hasMText=e.value,e=t.next();break;case 300:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=Ne(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=Ne(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=Ne(t),e=t.lastReadGroup;break;case 140:i.contextData.arrowHeadSize=e.value,e=t.next();break;case 41:i.contextData.textHeight=e.value,e=t.next();break;case 42:i.contextData.textRotation=e.value,e=t.next();break;case 43:i.contextData.textWidth=e.value,e=t.next();break;case 44:e=t.next();break;case 45:i.contextData.textLineSpacingFactor=e.value,e=t.next();break;case 90:i.contextData.textColor=e.value,e=t.next();break;case 170:i.contextData.textLineSpacingStyle=e.value,e=t.next();break;case 171:i.contextData.textAttachment=e.value,e=t.next();break;case 172:i.contextData.textFlowDirection=e.value,e=t.next();break;case 141:i.contextData.textBackgroundScaleFactor=e.value,e=t.next();break;case 92:i.contextData.textBackgroundTransparency=e.value,e=t.next();break;case 291:i.contextData.textBackgroundColorOn=e.value,e=t.next();break;case 292:i.contextData.textBackgroundFillOn=e.value,e=t.next();break;case 293:i.contextData.textUseAutoHeight=e.value,e=t.next();break;case 173:i.contextData.textColumnType=e.value,e=t.next();break;case 142:i.contextData.textColumnWidth=e.value,e=t.next();break;case 143:i.contextData.textColumnGutterWidth=e.value,e=t.next();break;case 144:i.contextData.textColumnHeight=e.value,e=t.next();break;case 295:i.contextData.textUseWordBreak=e.value,e=t.next();break;case 296:i.contextData.hasBlock=e.value,e=t.next();break;case 341:i.contextData.blockContentId=e.value,e=t.next();break;case 14:i.contextData.blockContentNormalDirection=Ne(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=Ne(t),e=t.lastReadGroup;break;case 16:i.contextData.blockContentScale=e.value,e=t.next();break;case 46:i.contextData.blockContentRotation=e.value,e=t.next();break;case 93:i.contextData.blockContentColor=e.value,e=t.next();break;case 47:i.contextData.blockTransformationMatrix=Ad(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=Ne(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=Ne(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=Ne(t),e=t.lastReadGroup;break;case 297:i.contextData.planeNormalReversed=e.value,e=t.next();break;case 301:return;case 302:n(),e=t.lastReadGroup;break;default:e=t.next();break}};return(()=>{for(;!t.isEOF();)switch(e.code){case 0:return;case 340:i.leaderStyleId=e.value,e=t.next();break;case 170:i.leaderLineType=e.value,e=t.next();break;case 91:i.leaderLineColor=e.value,e=t.next();break;case 341:i.leaderLineTypeId=e.value,e=t.next();break;case 171:i.leaderLineWeight=e.value,e=t.next();break;case 41:i.doglegLength=e.value,e=t.next();break;case 290:i.enableLanding=e.value,e=t.next();break;case 291:i.enableDogLeg=e.value,e=t.next();break;case 342:i.arrowHeadId=e.value,e=t.next();break;case 42:i.arrowHeadSize=e.value,e=t.next();break;case 172:i.contentType=e.value,e=t.next();break;case 173:i.textLeftAttachmentType=e.value,e=t.next();break;case 95:i.textLeftAttachmentType=e.value,e=t.next();break;case 174:i.textAngleType=e.value,e=t.next();break;case 175:i.textAlignmentType=e.value,e=t.next();break;case 343:i.textStyleId=e.value,e=t.next();break;case 92:i.textColor=e.value,e=t.next();break;case 292:i.enableFrameText=e.value,e=t.next();break;case 344:i.blockContentId=e.value,e=t.next();break;case 93:i.blockContentColor=e.value,e=t.next();break;case 10:i.blockContentScale=Ne(t),e=t.lastReadGroup;break;case 43:i.blockContentRotation=e.value,e=t.next();break;case 176:i.blockContentConnectionType=e.value,e=t.next();break;case 293:i.enableAnotationScale=e.value,e=t.next();break;case 94:i.arrowHeadIndex=e.value,e=t.next();break;case 177:i.blockAttributeIndex=e.value,e=t.next();break;case 44:i.blockAttributeWidth=e.value,e=t.next();break;case 302:i.blockAttributeTextString=e.value,e=t.next();break;case 294:i.textDirectionNegative=e.value,e=t.next();break;case 178:i.textAlignInIPE=e.value,e=t.next();break;case 179:i.textAttachmentPoint=e.value,e=t.next();break;case 271:i.textAttachmentDirectionMText=e.value,e=t.next();break;case 272:i.textAttachmentDirectionBottom=e.value,e=t.next();break;case 273:i.textAttachmentDirectionTop=e.value,e=t.next();break;case 300:r(),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}})(),i}}function Ne(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 110:case 111:case 112:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 120:case 121:case 122:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}function Ad(c,t){const e=[];let i=c.lastReadGroup||c.next();for(;!c.isEOF()&&(i.code>=t&&i.code<t+16);){e.push(i.value);i=c.next()}return e}class Id{constructor(){g(this,"ForEntityName","ELLIPSE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Gn(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=Gn(t),e=t.lastReadGroup;break;case 40:i.axisRatio=e.value,e=t.next();break;case 41:i.startAngle=e.value,e=t.next();break;case 42:i.endAngle=e.value,e=t.next();break;case 210:i.extrusionDirection=Gn(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Gn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}var Uo=(c=>(c[c.Default=0]="Default",c[c.External=1]="External",c[c.Polyline=2]="Polyline",c[c.Derived=4]="Derived",c[c.Textbox=8]="Textbox",c[c.Outermost=16]="Outermost",c[c.MaxFlags=31]="MaxFlags",c))(Uo||{}),Ci=(c=>(c[c.Polyline=0]="Polyline",c[c.Line=1]="Line",c[c.Arc=2]="Arc",c[c.Ellipse=3]="Ellipse",c[c.Spline=4]="Spline",c))(Ci||{});function Si(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;if(e.code===i)if(t.x=e.value,!c.isEOF()&&c.hasNext())e=c.next();else return t;if(e.code===i+10)if(t.y=e.value,!c.isEOF()&&c.hasNext())e=c.next();else return t;return e.code===i+20&&(t.z=e.value,!c.isEOF()&&c.hasNext()&&(e=c.next())),t}function Bd(c){const t={type:0,points:[],isClosed:!0};let e=c.next();const i=e.value!==0;e=c.next(),t.isClosed=e.value!==0,e=c.next();const s=e.value;e=c.next();for(let r=0;r<s;r++){const a=Si(c);e=c.lastReadGroup,i&&(a.bulge=e.value,e=c.next()),t.points.push(a)}e=c.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const n=e.value;e=c.next();for(let r=0;r<n;r++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=c.next();return{edges:[t],pathTypeFlag:-1}}function kd(c,t){const e=[];let i=t.next();for(;e.length<c;){if(i.code!==72){i=t.next();continue}switch(i.value){case 1:{i=t.next();const r={type:1,startPoint:Si(t),endPoint:Si(t)};i=t.lastReadGroup,e.push(r);break}case 2:{i=t.next();const r={type:2,center:Si(t),radius:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,r.radius=i.value,i=t.next(),r.startAngle=i.value,i=t.next(),r.endAngle=i.value,i=t.next(),r.bCounterclockwise=i.value!==0,i=t.next(),e.push(r);break}case 3:{i=t.next();const r={type:3,center:Si(t),majorAxisEndPoint:Si(t),minorRatio:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,r.minorRatio=i.value,i=t.next(),r.startAngle=i.value,i=t.next(),r.endAngle=i.value,i=t.next(),r.bCounterclockwise=i.value!==0,i=t.next(),e.push(r);break}case 4:{i=t.next();const r={type:4,degreeOfSplineCurve:i.value,bRational:!1,bPeriodic:!1,numKnots:0,numControlPoints:0,knotValues:[],controlPoints:[]};i=t.next(),r.bRational=i.value!==0,i=t.next(),r.bPeriodic=i.value!==0,i=t.next(),r.numKnots=i.value,i=t.next(),r.numControlPoints=i.value,i=t.next();for(let a=0;a<r.numKnots;a++)r.knotValues.push(i.value),i=t.next();for(let a=0;a<r.numControlPoints;a++){const o=i.value;i=t.next();const l=i.value;let h=1;i=t.next(),i.code===42&&(h=i.value,i=t.next()),r.controlPoints.push({x:o,y:l,z:h})}e.push(r);break}default:i=t.next();break}}i=t.lastReadGroup,console.assert(i.code===97,"The reference count code 97 was expected.");const s=i.value;i=t.next();for(let n=0;n<s;n++)console.assert(i.code===330,"The reference handle code 330 was expected."),i=t.next();return{edges:e,pathTypeFlag:-1}}function Dd(c,t){const e=[];let i=-1,s=t.next();for(;e.length<c;){let n;switch(s.code){case 92:if(i=s.value,i&2){if(n=Bd(t),n)n.pathTypeFlag=i,e.push(n);else throw new Error("[Hatch] Failed to parse hatch polyline boundary path !");s=t.lastReadGroup}else s=t.next();break;case 93:{const r=s.value;n=kd(r,t),n.pathTypeFlag=i,e.push(n),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function Ld(c,t){if(c<=0){t.next();return}const e=[];let i=t.next();for(let s=0;s<c;s++){let n=0;const r={x:0,y:0},a={x:0,y:0};let o=-1;const l=[];for(;!t.isEOF()&&i.code!==0;){let h=!1;switch(i.code){case 53:n=i.value;break;case 43:r.x=i.value;break;case 44:r.y=i.value;break;case 45:a.x=i.value;break;case 46:a.y=i.value;break;case 79:o=i.value;break;case 49:l.push(i.value);break;default:h=!0}if(i=t.next(),h||l.length===o)break}o>=0&&e.push({angle:n,origin:r,delta:a,dashPattern:l})}return e}function Rd(c,t){const e=[];let i=t.next();for(;e.length<c&&!t.isEOF()&&i.code!==void 0&&i.code!==0;)switch(i.code){case 63:i=t.next();break;case 421:e.push(i.value),i=t.next();break;default:i=t.next();break}return e}class Fd{constructor(){g(this,"ForEntityName","HATCH")}parseEntity(t,e){const i={type:e.value,boundaryPaths:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.patternName=e.value,e=t.next();break;case 10:i.elevationX=e.value,e=t.next();break;case 20:i.elevationY=e.value,e=t.next();break;case 30:i.elevationZ=e.value,e=t.next();break;case 41:i.patternScale=e.value,e=t.next();break;case 47:i.pixelSize=e.value,e=t.next();break;case 52:i.patternAngle=e.value,e=t.next();break;case 63:i.patternFillColor=e.value,e=t.next();break;case 70:i.solidFill=(e.value&1)!==0,e=t.next();break;case 71:i.associativity=(e.value&1)!==0,e=t.next();break;case 73:i.annotatedBoundary=(e.value&1)!==0,e=t.next();break;case 75:i.style=e.value,e=t.next();break;case 76:i.patternType=e.value,e=t.next();break;case 78:i.patternLines=Ld(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=Dd(i.boundaryPathsCount,t),e=t.lastReadGroup;break;case 98:i.seedPointsCount=e.value,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 450:i.isGradientColor=e.value===1,e=t.next();break;case 451:e=t.next();break;case 452:e=t.next();break;case 453:i.gradientColorCount=e.value,i.gradientColors=Rd(i.gradientColorCount,t),e=t.next();break;case 460:e=t.next();break;case 461:e=t.next();break;case 462:e=t.next();break;case 463:e=t.next();break;case 470:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}var hn=(c=>(c[c.ShowImage=1]="ShowImage",c[c.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",c[c.UseClippingBoundary=4]="UseClippingBoundary",c[c.TransparencyIsOn=8]="TransparencyIsOn",c))(hn||{});let zd=class{constructor(){g(this,"ForEntityName","IMAGE")}parseEntity(t,e){const i={type:e.value,clippingBoundaryPath:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Zi(t),e=t.lastReadGroup;break;case 11:i.uPixel=Zi(t),e=t.lastReadGroup;break;case 12:i.vPixel=Zi(t),e=t.lastReadGroup;break;case 13:i.imageSize=Zi(t),e=t.lastReadGroup;break;case 340:i.imageDefHandle=e.value,e=t.next();break;case 70:i.flags=e.value,e=t.next();break;case 280:i.clipping=e.value,e=t.next();break;case 281:i.brightness=e.value,e=t.next();break;case 282:i.contrast=e.value,e=t.next();break;case 283:i.fade=e.value,e=t.next();break;case 360:i.imageDefReactorHandle=e.value,e=t.next();break;case 71:i.clippingBoundaryType=e.value,e=t.next();break;case 91:i.countBoundaryPoints=e.value,e=t.next();break;case 14:i.clippingBoundaryPath.push(Zi(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}};function Zi(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}class Vd{constructor(){g(this,"ForEntityName","INSERT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 66:i.attributesFollow=e.value!=0,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 42:i.yScale=e.value,e=t.next();break;case 43:i.zScale=e.value,e=t.next();break;case 10:i.position=_a(t),e=t.lastReadGroup;break;case 50:i.rotation=e.value,e=t.next();break;case 70:i.columnCount=e.value,e=t.next();break;case 71:i.rowCount=e.value,e=t.next();break;case 44:i.columnSpacing=e.value,e=t.next();break;case 45:i.rowSpacing=e.value,e=t.next();break;case 210:i.extrusionDirection=_a(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;case 1e3:i.zdysx?i.zdysx+=e.value:i.zdysx=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function _a(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function jd(c){switch(c){case 40:return"DIMSCALE";case 41:return"DIMASZ";case 42:return"DIMEXO";case 44:return"DIMEXE";case 75:return"DIMSE1";case 76:return"DIMSE2";case 77:return"DIMTAD";case 140:return"DIMTXT";case 144:return"DIMLFAC";case 147:return"DIMGAP";case 176:return"DIMCLRD";case 178:return"DIMCLRT";case 271:return"DIMDEC";case 341:return"DIMLDRBLK";default:return null}}class Ud{constructor(){g(this,"ForEntityName","LEADER")}parseEntity(t,e){const i={type:e.value,arrowFlag:1,vertices:[]};e=t.next();let s=!1;for(;!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.push(Hd(t)),e=t.lastReadGroup;break;case 3:i.dimensionStyle=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.textWidth=e.value,e=t.next();break;case 71:i.arrowFlag=e.value,e=t.next();break;case 72:i.pathType=e.value,e=t.next();break;case 73:i.creationFlag=e.value,e=t.next();break;case 74:i.direction=e.value,e=t.next();break;case 75:i.hasHookline=e.value===1,e=t.next();break;case 1001:s=e.value==="ACAD",e=t.next();break;case 1070:if(s){const n=jd(e.value);n&&(e=t.next(),(e.code==1005||e.code==1040||e.code==1070)&&(n==="DIMLDRBLK"?i.arrowHeadBlockHandle=e.value:n==="DIMASZ"?i.arrowHeight=e.value:n==="DIMSCALE"?i.arrowHeadScale=e.value:n==="DIMCLRD"&&e.value>0&&(i.colorIndex=e.value,i.color=ki(Math.abs(e.value)))))}e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Hd(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Nd{constructor(){g(this,"ForEntityName","LINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(qn(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(qn(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=qn(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function qn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function Gd(c,t){if(!c||c<=0)throw Error("n must be greater than 0 verticies");const e=[];let i=!1,s=!1,n=t.lastReadGroup;const r={};for(;!t.isEOF()&&!(n.code===0||s);)switch(n.code){case 10:if(i){s=!0;continue}r.x=n.value,i=!0,n=t.next();break;case 20:r.y=n.value,n=t.next();break;case 30:r.z=n.value,n=t.next();break;case 40:r.startWidth=n.value,n=t.next();break;case 41:r.endWidth=n.value,n=t.next();break;case 42:n.value!=0&&(r.bulge=n.value),n=t.next();break;default:return i&&e.push(r),e}return e.push(r),i=!1,s=!1,e}class qd{constructor(){g(this,"ForEntityName","LWPOLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};let s=0;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 38:i.elevation=e.value,e=t.next();break;case 39:i.thickness=e.value,e=t.next();break;case 70:i.shape=(e.value&1)===1,i.hasContinuousLinetypePattern=(e.value&128)===128,e=t.next();break;case 90:s=e.value,e=t.next();break;case 10:i.vertices.push(...Gd(s,t)),e=t.lastReadGroup;break;case 43:e.value!==0&&(i.constantWidth=e.value),e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Wd{constructor(){g(this,"ForEntityName","MTEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 3:const s=e.value;i.text?i.text+=s:i.text=s,e=t.next();break;case 1:const n=e.value;i.text?i.text+=n:i.text=n,e=t.next();break;case 10:i.position=Pa(t),e=t.lastReadGroup;break;case 7:i.textStyle=e.value,e=t.next();break;case 44:i.lineSpaceFactor=e.value,e=t.next();break;case 11:i.directionVector=Pa(t),i.rotation=void 0,e=t.lastReadGroup;break;case 40:i.height=e.value,e=t.next();break;case 41:const r=e.value;Math.abs(r)<1e-6?i.width=void 0:i.width=r,e=t.next();break;case 50:i.rotation=e.value,i.directionVector=void 0,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 72:i.drawingDirection=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Pa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Yd{constructor(){g(this,"ForEntityName","OLE2FRAME")}parseEntity(t,e){const i={type:e.value,binaryData:""};for(e=t.next();e.value!=="OLE"&&e.code!==0;)switch(e.code){case 3:i.documentType=e.value,e=t.next();break;case 70:i.version=e.value,e=t.next();break;case 10:i.leftUpX=e.value,e=t.next();break;case 20:i.leftUpY=e.value,e=t.next();break;case 30:i.leftUpZ=e.value,e=t.next();break;case 11:i.rightDownX=e.value,e=t.next();break;case 21:i.rightDownY=e.value,e=t.next();break;case 31:i.rightDownZ=e.value,e=t.next();break;case 90:i.lengthOfBinaryData=e.value,e=t.next();break;case 310:i.binaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Xd{constructor(){g(this,"ForEntityName","POINT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Aa(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=Aa(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Aa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Zd{constructor(){g(this,"ForEntityName","VERTEX")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.x=e.value,e=t.next();break;case 20:i.y=e.value,e=t.next();break;case 30:i.z=e.value,e=t.next();break;case 40:e=t.next();break;case 41:e=t.next();break;case 42:e.value!=0&&(i.bulge=e.value),e=t.next();break;case 70:i.curveFittingVertex=(e.value&1)!==0,i.curveFitTangent=(e.value&2)!==0,i.splineVertex=(e.value&8)!==0,i.splineControlPoint=(e.value&16)!==0,i.threeDPolylineVertex=(e.value&32)!==0,i.threeDPolylineMesh=(e.value&64)!==0,i.polyfaceMeshVertex=(e.value&128)!==0,e=t.next();break;case 50:e=t.next();break;case 71:i.faceA=e.value,e=t.next();break;case 72:i.faceB=e.value,e=t.next();break;case 73:i.faceC=e.value,e=t.next();break;case 74:i.faceD=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Kd(c,t){const e=new Zd,i=[];for(;!c.isEOF();)if(t.code===0){if(t.value==="VERTEX")i.push(e.parseEntity(c,t)),t=c.lastReadGroup;else if(t.value==="SEQEND"){$d(c,t);break}}return i}function $d(c,t){const e={type:t.value};for(t=c.next();!c.isEOF()&&t.code!==0;)if(t.code===101)for(;t.code!=0;)t=c.next();else ee(e,t),t=c.next();return e}class Jd{constructor(){g(this,"ForEntityName","POLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:e=t.next();break;case 20:e=t.next();break;case 30:e=t.next();break;case 39:e=t.next(),i.thickness=e.value;break;case 40:e=t.next();break;case 41:e=t.next();break;case 70:i.shape=(e.value&1)!==0,i.includesCurveFitVertices=(e.value&2)!==0,i.includesSplineFitVertices=(e.value&4)!==0,i.is3dPolyline=(e.value&8)!==0,i.is3dPolygonMesh=(e.value&16)!==0,i.is3dPolygonMeshClosed=(e.value&32)!==0,i.isPolyfaceMesh=(e.value&64)!==0,i.hasContinuousLinetypePattern=(e.value&128)!==0,e=t.next();break;case 71:e=t.next();break;case 72:e=t.next();break;case 73:e=t.next();break;case 74:e=t.next();break;case 75:e=t.next();break;case 210:i.extrusionDirection=Qd(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i.vertices=Kd(t,e),i}}function Qd(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class e1{constructor(){g(this,"ForEntityName","REGION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:i.modelerVersion=e.value,e=t.next();break;case 1:i.proprietaryData=e.value,e=t.next();break;case 3:i.proprietaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class t1{constructor(){g(this,"ForEntityName","RAY")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(Ia(t)),e=t.lastReadGroup;break;case 11:i.directionVector=Ia(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Ia(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class i1{constructor(){g(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(ee(i,e),e=t.next());return i}}class s1{constructor(){g(this,"ForEntityName","SOLID")}parseEntity(t,e){const i={type:e.value,points:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.points[0]=Ki(t),e=t.lastReadGroup;break;case 11:i.points[1]=Ki(t),e=t.lastReadGroup;break;case 12:i.points[2]=Ki(t),e=t.lastReadGroup;break;case 13:i.points[3]=Ki(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=Ki(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Ki(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class n1{constructor(){g(this,"ForEntityName","SPLINE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.controlPoints||(i.controlPoints=[]),i.controlPoints.push($i(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push($i(t)),e=t.lastReadGroup;break;case 12:i.startTangent=$i(t),e=t.lastReadGroup;break;case 13:i.endTangent=$i(t),e=t.lastReadGroup;break;case 40:i.knotValues||(i.knotValues=[]),i.knotValues.push(e.value),e=t.next();break;case 70:(e.value&1)!=0&&(i.closed=!0),(e.value&2)!=0&&(i.periodic=!0),(e.value&4)!=0&&(i.rational=!0),(e.value&8)!=0&&(i.planar=!0),(e.value&16)!=0&&(i.planar=!0,i.linear=!0),e=t.next();break;case 71:i.degreeOfSplineCurve=e.value,e=t.next();break;case 72:i.numberOfKnots=e.value,e=t.next();break;case 73:i.numberOfControlPoints=e.value,e=t.next();break;case 74:i.numberOfFitPoints=e.value,e=t.next();break;case 210:i.normalVector=$i(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function $i(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function r1(c,t,e){let i=c;for(;i.code!==304;)switch(i.code){case 301:i=e.next();break;case 93:i=e.next();break;case 90:i=e.next();break;case 1:t.text=i.value,i=e.next();break;case 94:i=e.next();break;case 300:t.attrText=i.value,i=e.next();break;case 302:t.text=i.value?i.value:t.text,i=e.next();break;default:console.log("[DXF ACAD_TABLE] ignore code: "+i.code+", value: "+i.value),i=e.next();break}}function Ba(c,t){const e={};for(c.code===171&&(e.cellType=c.value);!t.isEOF();){const i=t.next();if(i.code===0||i.code===171){t.lastReadGroup=i;break}if(i.code===301){r1(i,e,t);continue}switch(i.code){case 172:e.flagValue=i.value;break;case 173:e.mergedValue=i.value;break;case 174:e.autoFit=i.value;break;case 175:e.borderWidth=i.value;break;case 176:e.borderHeight=i.value;break;case 177:e.overrideFlag=i.value;break;case 178:e.virtualEdgeFlag=i.value;break;case 145:e.rotation=i.value;break;case 140:e.textHeight=i.value;break;case 170:e.attachmentPoint=i.value;break;case 91:e.extendedCellFlags=i.value;break;case 7:e.textStyle=i.value;break;case 340:e.blockTableRecordId=i.value;break;case 345:e.fieldObjetId=i.value;break;case 146:e.blockScale=i.value;break;case 179:e.blockAttrNum=i.value;break;case 1:e.text=i.value;break;case 302:e.attrText=i.value;break}}return e}class a1{constructor(){g(this,"ForEntityName","ACAD_TABLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=ka(t),e=t.lastReadGroup;break;case 11:i.directionVector=ka(t),e=t.lastReadGroup;break;case 90:i.tableValue=e.value,e=t.next();break;case 91:i.rowCount=e.value,e=t.next();break;case 92:i.columnCount=e.value,e=t.next();break;case 93:i.overrideFlag=e.value,e=t.next();break;case 94:i.borderColorOverrideFlag=e.value,e=t.next();break;case 95:i.borderLineWeightOverrideFlag=e.value,e=t.next();break;case 96:i.borderVisibilityOverrideFlag=e.value,e=t.next();break;case 141:i.rowHeightArr?i.rowHeightArr.push(e.value):i.rowHeightArr=[e.value],e=t.next();break;case 142:i.columnWidthArr?i.columnWidthArr.push(e.value):i.columnWidthArr=[e.value],e=t.next();break;case 280:i.version=e.value,e=t.next();break;case 342:i.tableStyleId=e.value,e=t.next();break;case 343:i.blockRecordHandle=e.value,e=t.next();break;case 171:i.cells?i.cells.push(Ba(e,t)):i.cells=[Ba(e,t)],e=t.lastReadGroup;break;default:ee(i,e),e=t.next();break}return i}}function ka(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class o1{constructor(){g(this,"ForEntityName","TEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=Da(t),e=t.lastReadGroup;break;case 11:i.endPoint=Da(t),e=t.lastReadGroup;break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 72:i.halign=e.value,e=t.next();break;case 73:i.valign=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 71:i.mirrored=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Da(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class l1{constructor(){g(this,"ForEntityName","VIEWPORT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 68:i.viewportStatus=e.value,e=t.next();break;case 40:i.width_paperSpace=e.value,e=t.next();break;case 41:i.height_paperSpace=e.value,e=t.next();break;case 69:i.viewportId=e.value,e=t.next();break;case 10:i.centerPoint=ut(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=ut(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=ut(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=ut(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=ut(t),e=t.lastReadGroup;break;case 16:i.viewDirection=ut(t),e=t.lastReadGroup;break;case 17:i.viewTarget=ut(t),e=t.lastReadGroup;break;case 42:i.perspectiveLens=e.value,e=t.next();break;case 43:i.frontClippingPlaneZ=e.value,e=t.next();break;case 44:i.backClippingPlaneZ=e.value,e=t.next();break;case 45:i.viewHeight=e.value,e=t.next();break;case 50:i.snapAngle=e.value,e=t.next();break;case 51:i.viewTwistAngle=e.value,e=t.next();break;case 72:i.circleZoomPercent=e.value,e=t.next();break;case 331:i.frozenLayerHandles=i.frozenLayerHandles||[],i.frozenLayerHandles.push(e.value),e=t.next();break;case 90:i.viewportStatusFlags=e.value,e=t.next();break;case 340:i.viewportClippingBoundaryhandleId=e.value,e=t.next();break;case 1:i.plotStyleSheetName=e.value,e=t.next();break;case 281:i.renderMode=e.value,e=t.next();break;case 71:i.viewportFlag_ucs=e.value,e=t.next();break;case 74:i.ucsIcon=e.value,e=t.next();break;case 110:i.ucsOrigin=ut(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=ut(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=ut(t),e=t.lastReadGroup;break;case 345:i.ucsTableRecordHandle=e.value,e=t.next();break;case 346:i.baseUcsTableRecordHandle=e.value,e=t.next();break;case 79:i.orthographicType=e.value,e=t.next();break;case 146:i.elevation=e.value,e=t.next();break;case 170:i.shadePlotMode=e.value,e=t.next();break;case 61:i.frequency=e.value,e=t.next();break;case 292:i.lightingFlag=e.value,e=t.next();break;case 282:i.lightingType=e.value,e=t.next();break;case 141:i.viewBrightness=e.value,e=t.next();break;case 142:i.viewContrast=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function ut(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 12:case 13:case 14:case 15:case 16:case 17:case 110:case 111:case 112:t.x=e.value;break;case 20:case 22:case 23:case 24:case 25:case 26:case 27:case 120:case 121:case 122:t.y=e.value;break;case 30:case 32:case 33:case 34:case 35:case 36:case 37:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}class c1{constructor(){g(this,"ForEntityName","XLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(La(t)),e=t.lastReadGroup;break;case 11:i.directionVector=La(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function La(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class h1{constructor(){g(this,"ForObjectName","DICTIONARY")}parseObject(t,e){const s={type:e.value},n=[],r=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 280:s.isHardOwner=e.value===1,e=t.next();break;case 281:s.cloningFlag=e.value,e=t.next();break;case 3:n.push(e.value),e=t.next();break;case 350:r.push(e.value),e=t.next();break;case 360:r.push(e.value),e=t.next();break;case 100:e=t.next();break;case 102:e=t.next();break;default:zi(s,e),e=t.next();break}if(n.length!==r.length)throw new Error("The number of Dictionary entries does not match !");return s.entries={},n.forEach((a,o)=>{s.entries[r[o]]=a}),s}}class d1{constructor(){g(this,"ForObjectName","IMAGEDEF")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 90:s.classVersion=e.value,e=t.next();break;case 1:s.filename=e.value,e=t.next();break;case 10:s.imageSize=Ra(t),e=t.next();break;case 11:s.pixelSize=Ra(t),e=t.next();break;case 280:s.loaded=e.value,e=t.next();break;case 281:s.resolutionUnits=e.value,e=t.next();break;default:zi(s,e),e=t.next();break}return s}}function Ra(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class u1{constructor(){g(this,"ForObjectName","LAYOUT")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 1:s.layoutName=e.value,e=t.next();break;case 70:s.flag=e.value,e=t.next();break;case 71:s.tabOrder=e.value,e=t.next();break;case 76:s.orthographicType=e.value,e=t.next();break;case 10:s.minLimit=Bt(t),e=t.lastReadGroup;break;case 11:s.maxLimit=Bt(t),e=t.lastReadGroup;break;case 12:s.basePoint=Bt(t),e=t.lastReadGroup;break;case 13:s.origin=Bt(t),e=t.lastReadGroup;break;case 14:s.minExtent=Bt(t),e=t.lastReadGroup;break;case 15:s.maxExtent=Bt(t),e=t.lastReadGroup;break;case 16:s.XAxis=Bt(t),e=t.lastReadGroup;break;case 17:s.YAxis=Bt(t),e=t.lastReadGroup;break;case 146:s.elevation=e.value,e=t.next();break;case 330:s.viewportHandle=e.value,e=t.next();break;default:zi(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function Bt(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class f1{constructor(){g(this,"ForObjectName","SORTENTSTABLE")}parseObject(t,e){const s={type:e.value};let n=!1;s.sortEntsObject={},s.sortEntsObject.entityHandles=[];let r=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 5:n?(r.push(e.value),s.sortEntsObject.entityHandles.push(r),r=[]):s.handle=e.value,e=t.next();break;case 100:e=t.next(),n=!0;break;case 102:e=t.next();break;case 330:n?s.sortEntsObject.ownerHandle=e.value:s.ownerHandle=e.value,e=t.next();break;case 331:r.push(e.value),e=t.next();break;default:zi(s,e),e=t.next();break}return s}}class p1{constructor(){g(this,"ForObjectName","SPATIAL_FILTER")}parseObject(t,e){const s={type:e.value};s.vertices=[];let n,r;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 11:s.origin=dn(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),n=dn(t),e=t.lastReadGroup,r=dn(t),e=t.lastReadGroup,s.vertices.push(n,{x:r.x,y:n.y},r,{x:n.x,y:r.y},n)):s.numberOfPointsOnClipBoundary>2?(s.vertices=m1(s.numberOfPointsOnClipBoundary,t),e=t.lastReadGroup):e=t.next();break;case 71:s.clipBoundaryVisible=e.value===1,e=t.next();break;case 72:s.frontClippingPlaneFlag=e.value===1,e=t.next(),s.frontClippingPlaneFlag&&e.code===40&&(s.frontClippingPlaneDistance=e.value,e=t.next());break;case 73:s.backClippingPlaneFlag=e.value===1,e=t.next(),s.backClippingPlaneFlag&&e.code===41&&(s.backClippingPlaneDistance=e.value,e=t.next());break;case 100:e=t.next();break;case 102:e=t.next();break;case 210:s.extrusionDirectionX=e.value,e=t.next();break;case 220:s.extrusionDirectionY=e.value,e=t.next();break;case 230:s.extrusionDirectionZ=e.value,e=t.next();break;case 40:s.invertBlockMatrix=Fa(t,40),s.matrix=Fa(t,40),e=t.lastReadGroup;break;default:zi(s,e),e=t.next();break}return s}}function m1(c,t){t.next();const e=[];for(;e.length<c;)e.push(dn(t));return e}function Fa(c,t){let e=c.lastReadGroup;const i=[];for(let s=0;s<12;s++){if(e.code!==t)throw new Error("Expected code for matrix value to be "+t+" but got "+e.code);i.push(e.value),e=c.next()}return i}function dn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class g1{constructor(){g(this,"ForObjectName","XRECORD")}parseObject(t,e){const s={type:e.value,binaryData:""};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 280:s.cloningFlag=e.value,e=t.next();break;case 310:s.binaryData+=e.value,e=t.next();break;case 311:e=t.next();break;default:zi(s,e),e=t.next();break}return s}}function y1(c){c.registerEntityHandler(vd),c.registerEntityHandler(Md),c.registerEntityHandler(Cd),c.registerEntityHandler(Sd),c.registerEntityHandler(Ed),c.registerEntityHandler(_d),c.registerEntityHandler(Pd),c.registerEntityHandler(Id),c.registerEntityHandler(Fd),c.registerEntityHandler(zd),c.registerEntityHandler(Vd),c.registerEntityHandler(Ud),c.registerEntityHandler(Nd),c.registerEntityHandler(qd),c.registerEntityHandler(Wd),c.registerEntityHandler(Yd),c.registerEntityHandler(Xd),c.registerEntityHandler(Jd),c.registerEntityHandler(e1),c.registerEntityHandler(t1),c.registerEntityHandler(i1),c.registerEntityHandler(s1),c.registerEntityHandler(n1),c.registerEntityHandler(a1),c.registerEntityHandler(o1),c.registerEntityHandler(l1),c.registerEntityHandler(c1)}function x1(c){c.registerObjectHandler(h1),c.registerObjectHandler(d1),c.registerObjectHandler(u1),c.registerObjectHandler(f1),c.registerObjectHandler(p1),c.registerObjectHandler(g1)}function b1(c){const t=new Uint8Array(c,0,18);let e="";for(let i=0;i<18;i++)e+=String.fromCharCode(t[i]);return e==="AutoCAD Binary DXF"}class Ho{constructor(t){g(this,"_entityHandlers",{});g(this,"_objectHandlers",{});g(this,"_layoutBlocks",{});g(this,"unhandledSections",{});g(this,"unhandledObjects",{});g(this,"unhandledEntities",{});g(this,"unsupportedLineTypes",{});g(this,"encoding");this.encoding=t,y1(this),x1(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new Sa(e);return this._parse(i)}else{let e;if(b1(t))e=new gd(t);else{const i=new TextDecoder(this.encoding).decode(t),s=Date.now(),n=this.splitByLineSeparator(i);console.info("[DxfParser] string.split took "+(Date.now()-s)/1e3+"s, it is avoidable by using dxf in binary."),e=new Sa(n)}return this._parse(e)}}registerEntityHandler(t){const e=new t;this._entityHandlers[e.ForEntityName]=e}registerObjectHandler(t){const e=new t;this._objectHandlers[e.ForObjectName]=e}parseSync(t){return this.parse(t)}parseStream(t){let e="";const i=this;return new Promise((s,n)=>{t.on("data",r=>{e+=r}),t.on("end",()=>{try{s(i.parse(e))}catch(r){n(r)}}),t.on("error",r=>{n(r)})})}_parse(t){const e={};let i=0;if(!t.hasNext())throw Error("Empty file");const s=this;let n;function r(){for(n=t.next();n.code===999;)n=t.next();for(;!t.isEOF();)if(n.code===0&&n.value==="SECTION"){if(n=t.next(),n.code!==2){console.error("Unexpected code %s after 0:SECTION",No(n)),n=t.next();continue}if(n.value==="HEADER")P.trace("> HEADER"),e.header=a(),P.trace("<");else if(n.value==="TABLES")P.trace("> TABLES"),e.tables=h(),P.trace("<");else if(n.value==="BLOCKS")P.trace("> BLOCKS"),e.blocks=o(),P.trace("<");else if(n.value==="ENTITIES")P.trace("> ENTITIES"),e.entities=E(!1),P.trace("<");else if(n.value==="OBJECTS")P.trace("> OBJECTS"),e.objects=M(),P.trace("<");else if(n.value==="EOF")P.trace("EOF");else{const S=n.value;s.unhandledSections[S]?s.unhandledSections[S]++:s.unhandledSections[S]=1}}else n=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let S=null,v=null;const T={};for(n=t.next();;){if(Ge(n,0,"ENDSEC")){S&&(T[S]=v);break}else n.code===9?(S&&(T[S]=v),S=n.value):n.code===10?v={x:n.value}:n.code===20?v.y=n.value:n.code===30?v.z=n.value:v=n.value;n=t.next()}return n=t.next(),T}function o(){const S={};for(n=t.next();n.value!=="EOF"&&!Ge(n,0,"ENDSEC");)if(Ge(n,0,"BLOCK")){P.trace("block {");const v=l();P.trace("}"),O(v),v.name?S[v.name]=v:console.error("[DxfParser] Block with handle '"+v.handle+"' is missing a name, ignored!")}else wt(n),n=t.next();return S}function l(){const S={};for(n=t.next();n.value!=="EOF";){switch(n.code){case 1:S.xrefPath=n.value,n=t.next();break;case 2:S.name=n.value,n=t.next();break;case 3:S.name2=n.value,n=t.next();break;case 4:S.description=n.value,n=t.next();break;case 5:S.handle=n.value,n=t.next();break;case 8:S.layer=n.value,n=t.next();break;case 10:S.position=Ye(t),n=t.lastReadGroup;break;case 67:S.paperSpace=!!(n.value&&n.value===1),n=t.next();break;case 70:S.blockType=n.value,n=t.next();break;case 100:n=t.next();break;case 330:S.ownerHandle=n.value,n=t.next();break;case 0:if(n.value==="ENDBLK")break;S.entities=E(!0);break;default:wt(n),n=t.next();break}if(Ge(n,0,"ENDBLK")){n=t.next();break}}return S}function h(){const S={};for(n=t.next();n.value!=="EOF"&&!Ge(n,0,"ENDSEC");)Ge(n,0,"TABLE")?(n=t.next(),x[n.value]?(P.trace(n.value+" Table {"),S[x[n.value].tableName]=u(n),P.trace("}")):P.trace("Unhandled Table "+n.value)):n=t.next();return n=t.next(),S}const d="ENDTAB";function u(S){const v=x[S.value],T={};let _=0;for(n=t.next();!Ge(n,0,d);)switch(n.code){case 5:T.handle=n.value,n=t.next();break;case 330:T.ownerHandle=n.value,n=t.next();break;case 100:n.value==="AcDbSymbolTable"||wt(n),n=t.next();break;case 70:_=n.value,n=t.next();break;case 0:n.value===v.dxfSymbolName?T[v.tableRecordsProperty]=v.parseTableRecords():(wt(n),n=t.next());break;default:wt(n),n=t.next();break}const A=T[v.tableRecordsProperty];if(A){const I=(()=>{if(A.constructor===Array)return A.length;if(typeof A=="object")return Object.keys(A).length})();_!==I&&console.warn("[DxfParser] Parsed "+I+" "+v.dxfSymbolName+"s but expected "+_)}return n=t.next(),T}function f(){const S=[];let v={};for(P.trace("Viewport {"),n=t.next();!Ge(n,0,d);)switch(n.code){case 2:v.name=n.value,n=t.next();break;case 10:v.lowerLeftCorner=Ye(t),n=t.lastReadGroup;break;case 11:v.upperRightCorner=Ye(t),n=t.lastReadGroup;break;case 12:v.center=Ye(t),n=t.lastReadGroup;break;case 13:v.snapBasePoint=Ye(t),n=t.lastReadGroup;break;case 14:v.snapSpacing=Ye(t),n=t.lastReadGroup;break;case 15:v.gridSpacing=Ye(t),n=t.lastReadGroup;break;case 16:v.viewDirectionFromTarget=Ye(t),n=t.lastReadGroup;break;case 17:v.viewTarget=Ye(t),n=t.lastReadGroup;break;case 40:v.viewHeight=n.value,n=t.next();break;case 41:v.aspectRatio=n.value,n=t.next();break;case 42:v.lensLength=n.value,n=t.next();break;case 43:v.frontClippingPlane=n.value,n=t.next();break;case 44:v.backClippingPlane=n.value,n=t.next();break;case 45:v.viewHeight=n.value,n=t.next();break;case 50:v.snapRotationAngle=n.value,n=t.next();break;case 51:v.viewTwistAngle=n.value,n=t.next();break;case 79:v.orthographicType=n.value,n=t.next();break;case 110:v.ucsOrigin=Ye(t),n=t.lastReadGroup;break;case 111:v.ucsXAxis=Ye(t),n=t.lastReadGroup;break;case 112:v.ucsYAxis=Ye(t),n=t.lastReadGroup;break;case 281:v.renderMode=n.value,n=t.next();break;case 282:v.defaultLightingType=n.value,n=t.next();break;case 292:v.defaultLightingOn=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 63:case 421:case 431:v.ambientColor=n.value,n=t.next();break;case 0:n.value==="VPORT"&&(P.trace("}"),S.push(v),P.trace("Viewport {"),v={},n=t.next());break;default:wt(n),n=t.next();break}return P.trace("}"),S.push(v),S}function m(){const S={};let v={},T=0,_="",A=!1;for(P.trace("LType {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.name=n.value.toUpperCase(),_=v.name,n=t.next();break;case 3:v.description=n.value,n=t.next();break;case 9:n=t.next();break;case 40:v.patternLength=n.value,n=t.next();break;case 44:n=t.next();break;case 45:n=t.next();break;case 46:n=t.next();break;case 49:let I=n.value;A&&(I=Math.abs(I),A=!1),v.pattern.push(I),n=t.next();break;case 70:n=t.next();break;case 73:T=n.value,T>0&&(v.pattern=[]),n=t.next();break;case 74:n.value!==0&&(A=!0,s.unsupportedLineTypes[v.name]?s.unsupportedLineTypes[v.name]++:s.unsupportedLineTypes[v.name]=1),n=t.next();break;case 75:n=t.next();break;case 0:P.trace("}"),T>0&&T!==v.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),S[_]=v,v={},P.trace("LType {"),n=t.next();break;default:n=t.next();break}return P.trace("}"),S[_]=v,S}function b(){const S={};let v={},T;for(P.trace("Layer {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.name=n.value,T=n.value,n=t.next();break;case 5:v.handle=n.value,n=t.next();break;case 62:v.visible=n.value>=0,v.colorIndex=Math.abs(n.value),v.color=ki(v.colorIndex),n=t.next();break;case 70:v.flag=n.value,v.frozen=(v.flag&1)>0,n=t.next();break;case 420:v.color=Math.abs(n.value),n=t.next();break;case 6:v.lineType=n.value.toUpperCase(),n=t.next();break;case 370:v.lineweight=n.value,n=t.next();break;case 0:n.value==="LAYER"&&(P.trace("}"),T&&(S[T]=v),P.trace("Layer {"),v={},T=void 0,n=t.next());break;default:wt(n),n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function y(){const S={};let v={},T;for(P.trace("Style {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.styleName=n.value,T=n.value,n=t.next();break;case 3:v.fontFile=n.value,n=t.next();break;case 4:v.bigFontFile=n.value,n=t.next();break;case 5:v.handle=n.value,n=t.next();break;case 40:v.textHeight=n.value,n=t.next();break;case 41:v.xScale=n.value,n=t.next();break;case 42:v.priorTextHeight=n.value,n=t.next();break;case 50:v.rotation=n.value,n=t.next();break;case 70:n=t.next();break;case 71:v.mirrorType=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 0:n.value==="STYLE"&&(P.trace("}"),T&&(S[T]=v),P.trace("Style {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function C(){const S={};let v={},T;for(P.trace("DimStyle {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.styleName=n.value,T=n.value,n=t.next();break;case 40:v.DIMSCALE=n.value,n=t.next();break;case 41:v.DIMASZ=n.value,n=t.next();break;case 42:v.DIMEXO=n.value,n=t.next();break;case 44:v.DIMEXE=n.value,n=t.next();break;case 75:v.DIMSE1=n.value,n=t.next();break;case 76:v.DIMSE2=n.value,n=t.next();break;case 77:v.DIMTAD=n.value,n=t.next();break;case 140:v.DIMTXT=n.value,n=t.next();break;case 144:v.DIMLFAC=n.value,n=t.next();break;case 147:v.DIMGAP=n.value,n=t.next();break;case 176:v.DIMCLRD=n.value,n=t.next();break;case 178:v.DIMCLRT=n.value,n=t.next();break;case 271:v.DIMDEC=n.value,n=t.next();break;case 341:v.DIMLDRBLK=n.value,n=t.next();break;case 70:n=t.next();break;case 0:n.value==="DIMSTYLE"&&(P.trace("}"),T&&(S[T]=v),P.trace("DimStyle {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function w(){const S={};let v={},T;for(P.trace("BlockRecord {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 5:v.handle=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 2:v.blockName=n.value,T=v.blockName,n=t.next();break;case 340:v.layoutHandle=n.value,n=t.next();break;case 70:v.blockInsertUnits=n.value,n=t.next();break;case 280:v.blockExplodability=n.value,n=t.next();break;case 281:v.blockScalability=n.value,n=t.next();break;case 310:v.bitmap=n.value,n=t.next();break;case 0:if(n.value==="BLOCK_RECORD"){P.trace("}"),T&&(S[T]=v);const A=v.layoutHandle;T&&A&&A.length>0&&A!=="0"&&(s._layoutBlocks[A]=v),P.trace("BlockRecord {"),v={},T=void 0,n=t.next()}else wt(n),n=t.next();break;default:wt(n),n=t.next();break}P.trace("}"),T&&(S[T]=v);const _=v.layoutHandle;return T&&_&&_.length>0&&_!=="0"&&(s._layoutBlocks[_]=v),S}const x={VPORT:{tableRecordsProperty:"viewports",tableName:"viewport",dxfSymbolName:"VPORT",parseTableRecords:f},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:m},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:b},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:w},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:y},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:C}};function E(S){const v=[],T=S?"ENDBLK":"ENDSEC";for(S||(n=t.next());;)if(n.code===0){if(n.value===T)break;const _=s._entityHandlers[n.value];if(_!=null){P.trace(n.value+" {");const A=_.parseEntity(t,n);A&&(A.layer||(A.layer="0"),A.colorIndex===void 0&&(A.colorIndex=256),A.lineType||(A.lineType="BYLAYER"),n=t.lastReadGroup,P.trace("}"),O(A),v.push(A))}else{const A=n.value;s.unhandledEntities[A]||(s.unhandledEntities[A]=0),s.unhandledEntities[A]++,n=t.next();continue}}else n=t.next();return T==="ENDSEC"&&(n=t.next()),v}function M(){const S={},v="ENDSEC";for(n=t.next();n.value!=="EOF";)if(n.code===0){if(n.value===v)break;const T=s._objectHandlers[n.value];if(T!=null){P.trace(n.value+" {");const _=T.parseObject(t,n),A=n.value;n=t.lastReadGroup,P.trace("}"),O(_),S[A]||(S[A]=[]),S[A].push(_)}else{const _=n.value;s.unhandledObjects[_]||(s.unhandledObjects[_]=0),s.unhandledObjects[_]++,n=t.next();continue}}else n=t.next();return n=t.next(),S.LAYOUT&&(Object.keys(s._layoutBlocks).length!==S.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),S.LAYOUT.forEach(T=>{s._layoutBlocks[T.handle]&&(T.associatedBlockName=s._layoutBlocks[T.handle].blockName)}),S.LAYOUT.sort((T,_)=>T.tabOrder-_.tabOrder)),S}function O(S){if(!S)throw new TypeError("entity cannot be undefined or null");S.handle||(S.handle=(i++).toString())}return r(),e}splitByLineSeparator(t){const e=[];let i=0;for(let s=0,n=t.length;s<n;++s){const r=t[s];if(r==="\r"||r===`
791
+ `;return new p.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:a,clipping:!0})}var Ke=(c=>(c.Unitless="Unitless",c.Inches="Inches",c.Feet="Feet",c.Millimeters="Millimeters",c.Centimeters="Centimeters",c.Meters="Meters",c))(Ke||{});const wr=c=>c==="Unitless"?1:c==="Inches"?.0254:c==="Feet"?.3048:c==="Millimeters"?.001:c==="Centimeters"?.01:(c==="Meters"||console.warn("[Units] Unsupported unit '"+c+"', will return 1 for unit scale."),1),md=(c,t)=>wr(c)/wr(t);class Uo{constructor(){g(this,"pointer");g(this,"eof");g(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class vs{constructor(t,e){g(this,"endian");g(this,"position");g(this,"data");g(this,"decoder");this.endian=e&&e==="big"?"big":"little",this.position=0,this.data=new DataView(t)}readAsciiString(t){if(this.data.byteLength<this.position+t)throw"range error";let e="";for(let i=0;i<t;i++)e+=String.fromCharCode(this.data.getInt8(this.position+i));return this.position+=t,e}readUtf8String(t){const e=this.readBytes(t);return this.decoder||(this.decoder=new TextDecoder("utf-8")),this.decoder.decode(e)}readBytes(t=1){if(this.data.byteLength<this.position+t)throw"range error";const e=new Uint8Array(t);for(let i=0;i<t;i++)e[i]=this.data.getUint8(this.position+i);return this.position+=t,e}readUint8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getUint8(this.position);return this.position+=1,t}readInt8(){if(this.data.byteLength<this.position+1)throw"range error";const t=this.data.getInt8(this.position);return this.position+=1,t}readUint16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getUint16(this.position,this.endian==="little");return this.position+=2,t}readInt16(){if(this.data.byteLength<this.position+2)throw"range error";const t=this.data.getInt16(this.position,this.endian==="little");return this.position+=2,t}readUint32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getUint32(this.position,this.endian==="little");return this.position+=4,t}readInt32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getInt32(this.position,this.endian==="little");return this.position+=4,t}readFloat32(){if(this.data.byteLength<this.position+4)throw"range error";const t=this.data.getFloat32(this.position,this.endian==="little");return this.position+=4,t}readFloat64(){if(this.data.byteLength<this.position+8)throw"range error";const t=this.data.getFloat64(this.position,this.endian==="little");return this.position+=8,t}readInt64(){if(this.data.byteLength<this.position+8)throw"range error";const t=Ms.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,Ms.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=Ms.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,Ms.toNumber(t)}getPosition(){return this.position}setPosition(t){if(this.data.byteLength<t)throw"range error";this.position=t}isEnd(){return this.position===this.data.byteLength-1}}const Ma=1e3;class gd extends Uo{constructor(e){super();g(this,"reader");g(this,"decoder");g(this,"int8Array");g(this,"caches");this.int8Array=new Int8Array(Ma),this.caches=new Map,this.reader=new vs(e);const i=this.reader.readBytes(22);let s="";for(let n=0;n<18;n++)s+=String.fromCharCode(i[n]);if(s!=="AutoCAD Binary DXF")throw new Error("Invalid DXF file")}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file.");const e={code:this.reader.readInt16()};return e.value=this.parseGroupValue(e.code),e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return this.eof?!1:!this.reader.isEnd()}isEOF(){return this.eof}parseGroupValue(e){if(e>=0&&e<=9)return this.readNullTerminatedString();if(e>=10&&e<=59)return this.reader.readFloat64();if(e>=60&&e<=79)return this.reader.readInt16();if(e>=90&&e<=99)return this.reader.readInt32();if(e>=100&&e<=109)return this.readNullTerminatedString();if(e>=110&&e<=149)return this.reader.readFloat64();if(e>=160&&e<=169)return this.reader.readInt64();if(e>=170&&e<=179)return this.reader.readInt16();if(e>=210&&e<=239)return this.reader.readFloat64();if(e>=270&&e<=289)return this.reader.readInt16();if(e>=290&&e<=299)return this.reader.readInt8()>0;if(e>=300&&e<=309)return this.readNullTerminatedString();if(e>=310&&e<=319){const i=this.ReadBinaryData();return Ta(i)}if(e>=320&&e<=369)return this.readNullTerminatedString();if(e>=370&&e<=389)return this.reader.readInt16();if(e>=390&&e<=399)return this.readNullTerminatedString();if(e>=400&&e<=409)return this.reader.readInt16();if(e>=410&&e<=419)return this.readNullTerminatedString();if(e>=420&&e<=429)return this.reader.readInt32();if(e>=430&&e<=439)return this.readNullTerminatedString();if(e>=440&&e<=449)return this.reader.readInt32();if(e>=450&&e<=459)return this.reader.readFloat64();if(e>=460&&e<=469)return this.readNullTerminatedString();if(e>=470&&e<=479)return this.readNullTerminatedString();if(e>=480&&e<=481)return this.readNullTerminatedString();if(e>=999&&e<=999)throw new Error("The comment group 999, is not used in binary DXF files at byte address!");if(e===1004){const i=this.ReadBinaryData();return Ta(i)}if(e>=1e3&&e<=1009)return this.readNullTerminatedString();if(e>=1010&&e<=1059)return this.reader.readFloat64();if(e>=1060&&e<=1070)return this.reader.readInt16();if(e===1071)return this.reader.readInt32();console.warn("[DxfBinReader] Invalid code '"+e+"' at byte address "+this.reader.getPosition())}readNullTerminatedString(){this.decoder||(this.decoder=new TextDecoder("utf-8"));let e=0,i=this.reader.readInt8();for(;i!==0;)this.int8Array[e++]=i,i=this.reader.readInt8();if(e===0)return"";if(e>Ma)return console.warn("[DxfBinReader] Failed to read string! The number of bytes is "+e+" !"),"";const s=this.int8Array.subarray(0,e),n=s.toString();if(this.caches.get(n))return this.caches.get(n);const r=this.decoder?.decode(s);return this.caches.set(n,r),r}ReadBinaryData(){const e=this.reader.readUint8();return this.reader.readBytes(e)}}function Ta(c){return Array.prototype.map.call(c,t=>("00"+t.toString(16)).slice(-2)).join("")}class Ca extends Uo{constructor(e){super();g(this,"data");this.data=e}next(){if(!this.hasNext())throw this.eof?new Error("Cannot call 'next' after EOF group has been read"):new Error("Unexpected end of input: EOF group not read before end of file. Ended on code "+this.data[this.pointer]);const e={code:parseInt(this.data[this.pointer])};return this.pointer++,e.value=yd(e.code,this.data[this.pointer].trim(),this.data[this.pointer]),this.pointer++,e.code===0&&e.value==="EOF"&&(this.eof=!0),this.lastReadGroup=e,e}hasNext(){return!(this.eof||this.pointer>this.data.length-2)}isEOF(){return this.eof}}function yd(c,t,e){return c>=0&&c<=9?e:c>=10&&c<=59?parseFloat(t):c>=60&&c<=99?parseInt(t):c>=100&&c<=109?t:c>=110&&c<=149?parseFloat(t):c>=160&&c<=179?parseInt(t):c>=210&&c<=239?parseFloat(t):c>=270&&c<=289?parseInt(t):c>=290&&c<=299?xd(t):c>=300&&c<=369?t:c>=370&&c<=389?parseInt(t):c>=390&&c<=399?t:c>=400&&c<=409?parseInt(t):c>=410&&c<=419?t:c>=420&&c<=429?parseInt(t):c>=430&&c<=439?t:c>=440&&c<=449?parseInt(t):c>=450&&c<=459?parseFloat(t):c>=460&&c<=469||c===999||c>=1e3&&c<=1009?t:c>=1010&&c<=1059?parseFloat(t):c>=1060&&c<=1071?parseInt(t):(console.info("WARNING: Group code does not have a defined type: %j",{code:c,value:t}),t)}function xd(c){if(c==="0")return!1;if(c==="1")return!0;throw TypeError("String '"+c+"' cannot be cast to Boolean type")}function bd(c){if(c==null)return!0;for(const t in c)if(Object.prototype.hasOwnProperty.call(c,t))return!1;return!0}function wd(c,t){const e=[];let i=!1,s=!1;const n=4;for(let r=0;r<=n;r++){const a={};for(;!c.isEOF()&&!(t.code===0||s);){switch(t.code){case 10:case 11:case 12:case 13:if(i){s=!0;continue}a.x=t.value,i=!0;break;case 20:case 21:case 22:case 23:a.y=t.value;break;case 30:case 31:case 32:case 33:a.z=t.value;break;default:return e}t=c.next()}bd(a)||e.push(a),i=!1,s=!1}return e}class vd{constructor(){g(this,"ForEntityName","3DFACE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:if(e.value!==0){const s=Math.log2(e.value)-1;i.vertices.splice(s,0,1)}e=t.next();break;case 10:i.vertices=wd(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Md{constructor(){g(this,"ForEntityName","ARC")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Td(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:i.endAngle=Math.PI/180*e.value,i.angleLength=i.endAngle-i.startAngle,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Td(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Cd{constructor(){g(this,"ForEntityName","ATTDEF")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=Sa(t),e=t.lastReadGroup;break;case 11:i.endPoint=Sa(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,i.halign=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,i.valign=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Sa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Sd{constructor(){g(this,"ForEntityName","ATTRIB")}parseEntity(t,e){const i={type:e.value,xScale:1,textStyle:"STANDARD"};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 1:i.text=e.value,e=t.next();break;case 2:i.tag=e.value,e=t.next();break;case 3:i.prompt=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 10:i.startPoint=Ea(t),e=t.lastReadGroup;break;case 11:i.endPoint=Ea(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 51:i.obliqueAngle=e.value,e=t.next();break;case 70:i.invisible=!!(e.value&1),i.constant=!!(e.value&2),i.verificationRequired=!!(e.value&4),i.preset=!!(e.value&8),e=t.next();break;case 71:i.backwards=!!(e.value&2),i.mirrored=!!(e.value&4),e=t.next();break;case 72:i.horizontalJustification=e.value,i.halign=e.value,e=t.next();break;case 73:i.fieldLength=e.value,e=t.next();break;case 74:i.verticalJustification=e.value,i.valign=e.value,e=t.next();break;case 100:e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Ea(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Ed{constructor(){g(this,"ForEntityName","CIRCLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Od(t),e=t.lastReadGroup;break;case 40:i.radius=e.value,e=t.next();break;case 50:i.startAngle=Math.PI/180*e.value,e=t.next();break;case 51:const s=Math.PI/180*e.value;s<i.startAngle?i.angleLength=s+2*Math.PI-i.startAngle:i.angleLength=s-i.startAngle,i.endAngle=s,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Od(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class _d{constructor(){g(this,"ForEntityName","DIMENSION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 3:i.dimStyleName=e.value,e=t.next();break;case 10:i.anchorPoint=Jt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=Jt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=Jt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=Jt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=Jt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=Jt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=Jt(t),e=t.lastReadGroup;break;case 70:i.dimensionType=e.value,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 42:i.actualMeasurement=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 50:i.angle=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Jt(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Pd{constructor(){g(this,"ForEntityName","MULTILEADER")}parseEntity(t,e){const i={type:e.value};i.contextData={leaders:[]},e=t.next();const s=()=>{const o=i.contextData.leaders[i.contextData.leaders.length-1],l={vertices:[[]]};for(o.leaderLines.push(l);!t.isEOF();)switch(e.code){case 10:l.vertices[0].push(Ne(t)),e=t.lastReadGroup;break;case 305:return;default:e=t.next();break}},n=()=>{const o={leaderLines:[]};for(i.contextData.leaders.push(o);!t.isEOF();)switch(e.code){case 290:o.hasSetLastLeaderLinePoint=e.value,e=t.next();break;case 291:o.hasSetDoglegVector=e.value,e=t.next();break;case 10:o.lastLeaderLinePoint=Ne(t),e=t.lastReadGroup;break;case 11:o.doglegVector=Ne(t),e=t.lastReadGroup;break;case 90:o.leaderBranchIndex=e.value,e=t.next();break;case 40:o.doglegLength=e.value,e=t.next();break;case 303:return;case 304:s(),e=t.lastReadGroup;break;default:e=t.next();break}},r=()=>{for(;!t.isEOF();)switch(e.code){case 40:i.contextData.contentScale=e.value,e=t.next();break;case 10:i.contextData.contentBasePosition=Ne(t),e=t.lastReadGroup;break;case 145:i.contextData.landingGap=e.value,e=t.next();break;case 290:i.contextData.hasMText=e.value,e=t.next();break;case 300:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=Ne(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=Ne(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=Ne(t),e=t.lastReadGroup;break;case 140:i.contextData.arrowHeadSize=e.value,e=t.next();break;case 41:i.contextData.textHeight=e.value,e=t.next();break;case 42:i.contextData.textRotation=e.value,e=t.next();break;case 43:i.contextData.textWidth=e.value,e=t.next();break;case 44:e=t.next();break;case 45:i.contextData.textLineSpacingFactor=e.value,e=t.next();break;case 90:i.contextData.textColor=e.value,e=t.next();break;case 170:i.contextData.textLineSpacingStyle=e.value,e=t.next();break;case 171:i.contextData.textAttachment=e.value,e=t.next();break;case 172:i.contextData.textFlowDirection=e.value,e=t.next();break;case 141:i.contextData.textBackgroundScaleFactor=e.value,e=t.next();break;case 92:i.contextData.textBackgroundTransparency=e.value,e=t.next();break;case 291:i.contextData.textBackgroundColorOn=e.value,e=t.next();break;case 292:i.contextData.textBackgroundFillOn=e.value,e=t.next();break;case 293:i.contextData.textUseAutoHeight=e.value,e=t.next();break;case 173:i.contextData.textColumnType=e.value,e=t.next();break;case 142:i.contextData.textColumnWidth=e.value,e=t.next();break;case 143:i.contextData.textColumnGutterWidth=e.value,e=t.next();break;case 144:i.contextData.textColumnHeight=e.value,e=t.next();break;case 295:i.contextData.textUseWordBreak=e.value,e=t.next();break;case 296:i.contextData.hasBlock=e.value,e=t.next();break;case 341:i.contextData.blockContentId=e.value,e=t.next();break;case 14:i.contextData.blockContentNormalDirection=Ne(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=Ne(t),e=t.lastReadGroup;break;case 16:i.contextData.blockContentScale=e.value,e=t.next();break;case 46:i.contextData.blockContentRotation=e.value,e=t.next();break;case 93:i.contextData.blockContentColor=e.value,e=t.next();break;case 47:i.contextData.blockTransformationMatrix=Ad(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=Ne(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=Ne(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=Ne(t),e=t.lastReadGroup;break;case 297:i.contextData.planeNormalReversed=e.value,e=t.next();break;case 301:return;case 302:n(),e=t.lastReadGroup;break;default:e=t.next();break}};return(()=>{for(;!t.isEOF();)switch(e.code){case 0:return;case 340:i.leaderStyleId=e.value,e=t.next();break;case 170:i.leaderLineType=e.value,e=t.next();break;case 91:i.leaderLineColor=e.value,e=t.next();break;case 341:i.leaderLineTypeId=e.value,e=t.next();break;case 171:i.leaderLineWeight=e.value,e=t.next();break;case 41:i.doglegLength=e.value,e=t.next();break;case 290:i.enableLanding=e.value,e=t.next();break;case 291:i.enableDogLeg=e.value,e=t.next();break;case 342:i.arrowHeadId=e.value,e=t.next();break;case 42:i.arrowHeadSize=e.value,e=t.next();break;case 172:i.contentType=e.value,e=t.next();break;case 173:i.textLeftAttachmentType=e.value,e=t.next();break;case 95:i.textLeftAttachmentType=e.value,e=t.next();break;case 174:i.textAngleType=e.value,e=t.next();break;case 175:i.textAlignmentType=e.value,e=t.next();break;case 343:i.textStyleId=e.value,e=t.next();break;case 92:i.textColor=e.value,e=t.next();break;case 292:i.enableFrameText=e.value,e=t.next();break;case 344:i.blockContentId=e.value,e=t.next();break;case 93:i.blockContentColor=e.value,e=t.next();break;case 10:i.blockContentScale=Ne(t),e=t.lastReadGroup;break;case 43:i.blockContentRotation=e.value,e=t.next();break;case 176:i.blockContentConnectionType=e.value,e=t.next();break;case 293:i.enableAnotationScale=e.value,e=t.next();break;case 94:i.arrowHeadIndex=e.value,e=t.next();break;case 177:i.blockAttributeIndex=e.value,e=t.next();break;case 44:i.blockAttributeWidth=e.value,e=t.next();break;case 302:i.blockAttributeTextString=e.value,e=t.next();break;case 294:i.textDirectionNegative=e.value,e=t.next();break;case 178:i.textAlignInIPE=e.value,e=t.next();break;case 179:i.textAttachmentPoint=e.value,e=t.next();break;case 271:i.textAttachmentDirectionMText=e.value,e=t.next();break;case 272:i.textAttachmentDirectionBottom=e.value,e=t.next();break;case 273:i.textAttachmentDirectionTop=e.value,e=t.next();break;case 300:r(),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}})(),i}}function Ne(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:case 15:case 16:case 110:case 111:case 112:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:case 25:case 26:case 120:case 121:case 122:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:case 35:case 36:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}function Ad(c,t){const e=[];let i=c.lastReadGroup||c.next();for(;!c.isEOF()&&(i.code>=t&&i.code<t+16);){e.push(i.value);i=c.next()}return e}class Id{constructor(){g(this,"ForEntityName","ELLIPSE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.center=Gn(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=Gn(t),e=t.lastReadGroup;break;case 40:i.axisRatio=e.value,e=t.next();break;case 41:i.startAngle=e.value,e=t.next();break;case 42:i.endAngle=e.value,e=t.next();break;case 210:i.extrusionDirection=Gn(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Gn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}var Ho=(c=>(c[c.Default=0]="Default",c[c.External=1]="External",c[c.Polyline=2]="Polyline",c[c.Derived=4]="Derived",c[c.Textbox=8]="Textbox",c[c.Outermost=16]="Outermost",c[c.MaxFlags=31]="MaxFlags",c))(Ho||{}),Ci=(c=>(c[c.Polyline=0]="Polyline",c[c.Line=1]="Line",c[c.Arc=2]="Arc",c[c.Ellipse=3]="Ellipse",c[c.Spline=4]="Spline",c))(Ci||{});function Si(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;if(e.code===i)if(t.x=e.value,!c.isEOF()&&c.hasNext())e=c.next();else return t;if(e.code===i+10)if(t.y=e.value,!c.isEOF()&&c.hasNext())e=c.next();else return t;return e.code===i+20&&(t.z=e.value,!c.isEOF()&&c.hasNext()&&(e=c.next())),t}function Bd(c){const t={type:0,points:[],isClosed:!0};let e=c.next();const i=e.value!==0;e=c.next(),t.isClosed=e.value!==0,e=c.next();const s=e.value;e=c.next();for(let r=0;r<s;r++){const a=Si(c);e=c.lastReadGroup,i&&(a.bulge=e.value,e=c.next()),t.points.push(a)}e=c.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const n=e.value;e=c.next();for(let r=0;r<n;r++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=c.next();return{edges:[t],pathTypeFlag:-1}}function kd(c,t){const e=[];let i=t.next();for(;e.length<c;){if(i.code!==72){i=t.next();continue}switch(i.value){case 1:{i=t.next();const r={type:1,startPoint:Si(t),endPoint:Si(t)};i=t.lastReadGroup,e.push(r);break}case 2:{i=t.next();const r={type:2,center:Si(t),radius:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,r.radius=i.value,i=t.next(),r.startAngle=i.value,i=t.next(),r.endAngle=i.value,i=t.next(),r.bCounterclockwise=i.value!==0,i=t.next(),e.push(r);break}case 3:{i=t.next();const r={type:3,center:Si(t),majorAxisEndPoint:Si(t),minorRatio:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,r.minorRatio=i.value,i=t.next(),r.startAngle=i.value,i=t.next(),r.endAngle=i.value,i=t.next(),r.bCounterclockwise=i.value!==0,i=t.next(),e.push(r);break}case 4:{i=t.next();const r={type:4,degreeOfSplineCurve:i.value,bRational:!1,bPeriodic:!1,numKnots:0,numControlPoints:0,knotValues:[],controlPoints:[]};i=t.next(),r.bRational=i.value!==0,i=t.next(),r.bPeriodic=i.value!==0,i=t.next(),r.numKnots=i.value,i=t.next(),r.numControlPoints=i.value,i=t.next();for(let a=0;a<r.numKnots;a++)r.knotValues.push(i.value),i=t.next();for(let a=0;a<r.numControlPoints;a++){const o=i.value;i=t.next();const l=i.value;let h=1;i=t.next(),i.code===42&&(h=i.value,i=t.next()),r.controlPoints.push({x:o,y:l,z:h})}e.push(r);break}default:i=t.next();break}}i=t.lastReadGroup,console.assert(i.code===97,"The reference count code 97 was expected.");const s=i.value;i=t.next();for(let n=0;n<s;n++)console.assert(i.code===330,"The reference handle code 330 was expected."),i=t.next();return{edges:e,pathTypeFlag:-1}}function Dd(c,t){const e=[];let i=-1,s=t.next();for(;e.length<c;){let n;switch(s.code){case 92:if(i=s.value,i&2){if(n=Bd(t),n)n.pathTypeFlag=i,e.push(n);else throw new Error("[Hatch] Failed to parse hatch polyline boundary path !");s=t.lastReadGroup}else s=t.next();break;case 93:{const r=s.value;n=kd(r,t),n.pathTypeFlag=i,e.push(n),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function Ld(c,t){if(c<=0){t.next();return}const e=[];let i=t.next();for(let s=0;s<c;s++){let n=0;const r={x:0,y:0},a={x:0,y:0};let o=-1;const l=[];for(;!t.isEOF()&&i.code!==0;){let h=!1;switch(i.code){case 53:n=i.value;break;case 43:r.x=i.value;break;case 44:r.y=i.value;break;case 45:a.x=i.value;break;case 46:a.y=i.value;break;case 79:o=i.value;break;case 49:l.push(i.value);break;default:h=!0}if(i=t.next(),h||l.length===o)break}o>=0&&e.push({angle:n,origin:r,delta:a,dashPattern:l})}return e}function Rd(c,t){const e=[];let i=t.next();for(;e.length<c&&!t.isEOF()&&i.code!==void 0&&i.code!==0;)switch(i.code){case 63:i=t.next();break;case 421:e.push(i.value),i=t.next();break;default:i=t.next();break}return e}class Fd{constructor(){g(this,"ForEntityName","HATCH")}parseEntity(t,e){const i={type:e.value,boundaryPaths:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.patternName=e.value,e=t.next();break;case 10:i.elevationX=e.value,e=t.next();break;case 20:i.elevationY=e.value,e=t.next();break;case 30:i.elevationZ=e.value,e=t.next();break;case 41:i.patternScale=e.value,e=t.next();break;case 47:i.pixelSize=e.value,e=t.next();break;case 52:i.patternAngle=e.value,e=t.next();break;case 63:i.patternFillColor=e.value,e=t.next();break;case 70:i.solidFill=(e.value&1)!==0,e=t.next();break;case 71:i.associativity=(e.value&1)!==0,e=t.next();break;case 73:i.annotatedBoundary=(e.value&1)!==0,e=t.next();break;case 75:i.style=e.value,e=t.next();break;case 76:i.patternType=e.value,e=t.next();break;case 78:i.patternLines=Ld(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=Dd(i.boundaryPathsCount,t),e=t.lastReadGroup;break;case 98:i.seedPointsCount=e.value,e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 450:i.isGradientColor=e.value===1,e=t.next();break;case 451:e=t.next();break;case 452:e=t.next();break;case 453:i.gradientColorCount=e.value,i.gradientColors=Rd(i.gradientColorCount,t),e=t.next();break;case 460:e=t.next();break;case 461:e=t.next();break;case 462:e=t.next();break;case 463:e=t.next();break;case 470:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}var hn=(c=>(c[c.ShowImage=1]="ShowImage",c[c.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",c[c.UseClippingBoundary=4]="UseClippingBoundary",c[c.TransparencyIsOn=8]="TransparencyIsOn",c))(hn||{});let zd=class{constructor(){g(this,"ForEntityName","IMAGE")}parseEntity(t,e){const i={type:e.value,clippingBoundaryPath:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Zi(t),e=t.lastReadGroup;break;case 11:i.uPixel=Zi(t),e=t.lastReadGroup;break;case 12:i.vPixel=Zi(t),e=t.lastReadGroup;break;case 13:i.imageSize=Zi(t),e=t.lastReadGroup;break;case 340:i.imageDefHandle=e.value,e=t.next();break;case 70:i.flags=e.value,e=t.next();break;case 280:i.clipping=e.value,e=t.next();break;case 281:i.brightness=e.value,e=t.next();break;case 282:i.contrast=e.value,e=t.next();break;case 283:i.fade=e.value,e=t.next();break;case 360:i.imageDefReactorHandle=e.value,e=t.next();break;case 71:i.clippingBoundaryType=e.value,e=t.next();break;case 91:i.countBoundaryPoints=e.value,e=t.next();break;case 14:i.clippingBoundaryPath.push(Zi(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}};function Zi(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 11:case 12:case 13:case 14:t.x=e.value;break;case 20:case 21:case 22:case 23:case 24:t.y=e.value;break;case 30:case 31:case 32:case 33:case 34:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}class Vd{constructor(){g(this,"ForEntityName","INSERT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 2:i.block=e.value,e=t.next();break;case 66:i.attributesFollow=e.value!=0,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 42:i.yScale=e.value,e=t.next();break;case 43:i.zScale=e.value,e=t.next();break;case 10:i.position=Oa(t),e=t.lastReadGroup;break;case 50:i.rotation=e.value,e=t.next();break;case 70:i.columnCount=e.value,e=t.next();break;case 71:i.rowCount=e.value,e=t.next();break;case 44:i.columnSpacing=e.value,e=t.next();break;case 45:i.rowSpacing=e.value,e=t.next();break;case 210:i.extrusionDirection=Oa(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;case 1e3:i.zdysx?i.zdysx+=e.value:i.zdysx=e.value,e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Oa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function jd(c){switch(c){case 40:return"DIMSCALE";case 41:return"DIMASZ";case 42:return"DIMEXO";case 44:return"DIMEXE";case 75:return"DIMSE1";case 76:return"DIMSE2";case 77:return"DIMTAD";case 140:return"DIMTXT";case 144:return"DIMLFAC";case 147:return"DIMGAP";case 176:return"DIMCLRD";case 178:return"DIMCLRT";case 271:return"DIMDEC";case 341:return"DIMLDRBLK";default:return null}}class Ud{constructor(){g(this,"ForEntityName","LEADER")}parseEntity(t,e){const i={type:e.value,arrowFlag:1,vertices:[]};e=t.next();let s=!1;for(;!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.push(Hd(t)),e=t.lastReadGroup;break;case 3:i.dimensionStyle=e.value,e=t.next();break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.textWidth=e.value,e=t.next();break;case 71:i.arrowFlag=e.value,e=t.next();break;case 72:i.pathType=e.value,e=t.next();break;case 73:i.creationFlag=e.value,e=t.next();break;case 74:i.direction=e.value,e=t.next();break;case 75:i.hasHookline=e.value===1,e=t.next();break;case 1001:s=e.value==="ACAD",e=t.next();break;case 1070:if(s){const n=jd(e.value);n&&(e=t.next(),(e.code==1005||e.code==1040||e.code==1070)&&(n==="DIMLDRBLK"?i.arrowHeadBlockHandle=e.value:n==="DIMASZ"?i.arrowHeight=e.value:n==="DIMSCALE"?i.arrowHeadScale=e.value:n==="DIMCLRD"&&e.value>0&&(i.colorIndex=e.value,i.color=ki(Math.abs(e.value)))))}e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Hd(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Nd{constructor(){g(this,"ForEntityName","LINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(qn(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(qn(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=qn(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function qn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function Gd(c,t){if(!c||c<=0)throw Error("n must be greater than 0 verticies");const e=[];let i=!1,s=!1,n=t.lastReadGroup;const r={};for(;!t.isEOF()&&!(n.code===0||s);)switch(n.code){case 10:if(i){s=!0;continue}r.x=n.value,i=!0,n=t.next();break;case 20:r.y=n.value,n=t.next();break;case 30:r.z=n.value,n=t.next();break;case 40:r.startWidth=n.value,n=t.next();break;case 41:r.endWidth=n.value,n=t.next();break;case 42:n.value!=0&&(r.bulge=n.value),n=t.next();break;default:return i&&e.push(r),e}return e.push(r),i=!1,s=!1,e}class qd{constructor(){g(this,"ForEntityName","LWPOLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};let s=0;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 38:i.elevation=e.value,e=t.next();break;case 39:i.thickness=e.value,e=t.next();break;case 70:i.shape=(e.value&1)===1,i.hasContinuousLinetypePattern=(e.value&128)===128,e=t.next();break;case 90:s=e.value,e=t.next();break;case 10:i.vertices.push(...Gd(s,t)),e=t.lastReadGroup;break;case 43:e.value!==0&&(i.constantWidth=e.value),e=t.next();break;case 210:i.extrusionDirectionX=e.value,e=t.next();break;case 220:i.extrusionDirectionY=e.value,e=t.next();break;case 230:i.extrusionDirectionZ=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Wd{constructor(){g(this,"ForEntityName","MTEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 3:const s=e.value;i.text?i.text+=s:i.text=s,e=t.next();break;case 1:const n=e.value;i.text?i.text+=n:i.text=n,e=t.next();break;case 10:i.position=_a(t),e=t.lastReadGroup;break;case 7:i.textStyle=e.value,e=t.next();break;case 44:i.lineSpaceFactor=e.value,e=t.next();break;case 11:i.directionVector=_a(t),i.rotation=void 0,e=t.lastReadGroup;break;case 40:i.height=e.value,e=t.next();break;case 41:const r=e.value;Math.abs(r)<1e-6?i.width=void 0:i.width=r,e=t.next();break;case 50:i.rotation=e.value,i.directionVector=void 0,e=t.next();break;case 71:i.attachmentPoint=e.value,e=t.next();break;case 72:i.drawingDirection=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function _a(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Yd{constructor(){g(this,"ForEntityName","OLE2FRAME")}parseEntity(t,e){const i={type:e.value,binaryData:""};for(e=t.next();e.value!=="OLE"&&e.code!==0;)switch(e.code){case 3:i.documentType=e.value,e=t.next();break;case 70:i.version=e.value,e=t.next();break;case 10:i.leftUpX=e.value,e=t.next();break;case 20:i.leftUpY=e.value,e=t.next();break;case 30:i.leftUpZ=e.value,e=t.next();break;case 11:i.rightDownX=e.value,e=t.next();break;case 21:i.rightDownY=e.value,e=t.next();break;case 31:i.rightDownZ=e.value,e=t.next();break;case 90:i.lengthOfBinaryData=e.value,e=t.next();break;case 310:i.binaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class Xd{constructor(){g(this,"ForEntityName","POINT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.position=Pa(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=Pa(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Pa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class Zd{constructor(){g(this,"ForEntityName","VERTEX")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.x=e.value,e=t.next();break;case 20:i.y=e.value,e=t.next();break;case 30:i.z=e.value,e=t.next();break;case 40:e=t.next();break;case 41:e=t.next();break;case 42:e.value!=0&&(i.bulge=e.value),e=t.next();break;case 70:i.curveFittingVertex=(e.value&1)!==0,i.curveFitTangent=(e.value&2)!==0,i.splineVertex=(e.value&8)!==0,i.splineControlPoint=(e.value&16)!==0,i.threeDPolylineVertex=(e.value&32)!==0,i.threeDPolylineMesh=(e.value&64)!==0,i.polyfaceMeshVertex=(e.value&128)!==0,e=t.next();break;case 50:e=t.next();break;case 71:i.faceA=e.value,e=t.next();break;case 72:i.faceB=e.value,e=t.next();break;case 73:i.faceC=e.value,e=t.next();break;case 74:i.faceD=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Kd(c,t){const e=new Zd,i=[];for(;!c.isEOF();)if(t.code===0){if(t.value==="VERTEX")i.push(e.parseEntity(c,t)),t=c.lastReadGroup;else if(t.value==="SEQEND"){$d(c,t);break}}return i}function $d(c,t){const e={type:t.value};for(t=c.next();!c.isEOF()&&t.code!==0;)if(t.code===101)for(;t.code!=0;)t=c.next();else ee(e,t),t=c.next();return e}class Jd{constructor(){g(this,"ForEntityName","POLYLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:e=t.next();break;case 20:e=t.next();break;case 30:e=t.next();break;case 39:e=t.next(),i.thickness=e.value;break;case 40:e=t.next();break;case 41:e=t.next();break;case 70:i.shape=(e.value&1)!==0,i.includesCurveFitVertices=(e.value&2)!==0,i.includesSplineFitVertices=(e.value&4)!==0,i.is3dPolyline=(e.value&8)!==0,i.is3dPolygonMesh=(e.value&16)!==0,i.is3dPolygonMeshClosed=(e.value&32)!==0,i.isPolyfaceMesh=(e.value&64)!==0,i.hasContinuousLinetypePattern=(e.value&128)!==0,e=t.next();break;case 71:e=t.next();break;case 72:e=t.next();break;case 73:e=t.next();break;case 74:e=t.next();break;case 75:e=t.next();break;case 210:i.extrusionDirection=Qd(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i.vertices=Kd(t,e),i}}function Qd(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class e1{constructor(){g(this,"ForEntityName","REGION")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 70:i.modelerVersion=e.value,e=t.next();break;case 1:i.proprietaryData=e.value,e=t.next();break;case 3:i.proprietaryData+=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}class t1{constructor(){g(this,"ForEntityName","RAY")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(Aa(t)),e=t.lastReadGroup;break;case 11:i.directionVector=Aa(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Aa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class i1{constructor(){g(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(ee(i,e),e=t.next());return i}}class s1{constructor(){g(this,"ForEntityName","SOLID")}parseEntity(t,e){const i={type:e.value,points:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.points[0]=Ki(t),e=t.lastReadGroup;break;case 11:i.points[1]=Ki(t),e=t.lastReadGroup;break;case 12:i.points[2]=Ki(t),e=t.lastReadGroup;break;case 13:i.points[3]=Ki(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=Ki(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Ki(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class n1{constructor(){g(this,"ForEntityName","SPLINE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.controlPoints||(i.controlPoints=[]),i.controlPoints.push($i(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push($i(t)),e=t.lastReadGroup;break;case 12:i.startTangent=$i(t),e=t.lastReadGroup;break;case 13:i.endTangent=$i(t),e=t.lastReadGroup;break;case 40:i.knotValues||(i.knotValues=[]),i.knotValues.push(e.value),e=t.next();break;case 70:(e.value&1)!=0&&(i.closed=!0),(e.value&2)!=0&&(i.periodic=!0),(e.value&4)!=0&&(i.rational=!0),(e.value&8)!=0&&(i.planar=!0),(e.value&16)!=0&&(i.planar=!0,i.linear=!0),e=t.next();break;case 71:i.degreeOfSplineCurve=e.value,e=t.next();break;case 72:i.numberOfKnots=e.value,e=t.next();break;case 73:i.numberOfControlPoints=e.value,e=t.next();break;case 74:i.numberOfFitPoints=e.value,e=t.next();break;case 210:i.normalVector=$i(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function $i(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}function r1(c,t,e){let i=c;for(;i.code!==304;)switch(i.code){case 301:i=e.next();break;case 93:i=e.next();break;case 90:i=e.next();break;case 1:t.text=i.value,i=e.next();break;case 94:i=e.next();break;case 300:t.attrText=i.value,i=e.next();break;case 302:t.text=i.value?i.value:t.text,i=e.next();break;default:console.log("[DXF ACAD_TABLE] ignore code: "+i.code+", value: "+i.value),i=e.next();break}}function Ia(c,t){const e={};for(c.code===171&&(e.cellType=c.value);!t.isEOF();){const i=t.next();if(i.code===0||i.code===171){t.lastReadGroup=i;break}if(i.code===301){r1(i,e,t);continue}switch(i.code){case 172:e.flagValue=i.value;break;case 173:e.mergedValue=i.value;break;case 174:e.autoFit=i.value;break;case 175:e.borderWidth=i.value;break;case 176:e.borderHeight=i.value;break;case 177:e.overrideFlag=i.value;break;case 178:e.virtualEdgeFlag=i.value;break;case 145:e.rotation=i.value;break;case 140:e.textHeight=i.value;break;case 170:e.attachmentPoint=i.value;break;case 91:e.extendedCellFlags=i.value;break;case 7:e.textStyle=i.value;break;case 340:e.blockTableRecordId=i.value;break;case 345:e.fieldObjetId=i.value;break;case 146:e.blockScale=i.value;break;case 179:e.blockAttrNum=i.value;break;case 1:e.text=i.value;break;case 302:e.attrText=i.value;break}}return e}class a1{constructor(){g(this,"ForEntityName","ACAD_TABLE")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=Ba(t),e=t.lastReadGroup;break;case 11:i.directionVector=Ba(t),e=t.lastReadGroup;break;case 90:i.tableValue=e.value,e=t.next();break;case 91:i.rowCount=e.value,e=t.next();break;case 92:i.columnCount=e.value,e=t.next();break;case 93:i.overrideFlag=e.value,e=t.next();break;case 94:i.borderColorOverrideFlag=e.value,e=t.next();break;case 95:i.borderLineWeightOverrideFlag=e.value,e=t.next();break;case 96:i.borderVisibilityOverrideFlag=e.value,e=t.next();break;case 141:i.rowHeightArr?i.rowHeightArr.push(e.value):i.rowHeightArr=[e.value],e=t.next();break;case 142:i.columnWidthArr?i.columnWidthArr.push(e.value):i.columnWidthArr=[e.value],e=t.next();break;case 280:i.version=e.value,e=t.next();break;case 342:i.tableStyleId=e.value,e=t.next();break;case 343:i.blockRecordHandle=e.value,e=t.next();break;case 171:i.cells?i.cells.push(Ia(e,t)):i.cells=[Ia(e,t)],e=t.lastReadGroup;break;default:ee(i,e),e=t.next();break}return i}}function Ba(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class o1{constructor(){g(this,"ForEntityName","TEXT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.startPoint=ka(t),e=t.lastReadGroup;break;case 11:i.endPoint=ka(t),e=t.lastReadGroup;break;case 40:i.textHeight=e.value,e=t.next();break;case 41:i.xScale=e.value,e=t.next();break;case 50:i.rotation=e.value,e=t.next();break;case 1:i.text=e.value,e=t.next();break;case 72:i.halign=e.value,e=t.next();break;case 73:i.valign=e.value,e=t.next();break;case 7:i.textStyle=e.value,e=t.next();break;case 71:i.mirrored=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function ka(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class l1{constructor(){g(this,"ForEntityName","VIEWPORT")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 68:i.viewportStatus=e.value,e=t.next();break;case 40:i.width_paperSpace=e.value,e=t.next();break;case 41:i.height_paperSpace=e.value,e=t.next();break;case 69:i.viewportId=e.value,e=t.next();break;case 10:i.centerPoint=ut(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=ut(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=ut(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=ut(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=ut(t),e=t.lastReadGroup;break;case 16:i.viewDirection=ut(t),e=t.lastReadGroup;break;case 17:i.viewTarget=ut(t),e=t.lastReadGroup;break;case 42:i.perspectiveLens=e.value,e=t.next();break;case 43:i.frontClippingPlaneZ=e.value,e=t.next();break;case 44:i.backClippingPlaneZ=e.value,e=t.next();break;case 45:i.viewHeight=e.value,e=t.next();break;case 50:i.snapAngle=e.value,e=t.next();break;case 51:i.viewTwistAngle=e.value,e=t.next();break;case 72:i.circleZoomPercent=e.value,e=t.next();break;case 331:i.frozenLayerHandles=i.frozenLayerHandles||[],i.frozenLayerHandles.push(e.value),e=t.next();break;case 90:i.viewportStatusFlags=e.value,e=t.next();break;case 340:i.viewportClippingBoundaryhandleId=e.value,e=t.next();break;case 1:i.plotStyleSheetName=e.value,e=t.next();break;case 281:i.renderMode=e.value,e=t.next();break;case 71:i.viewportFlag_ucs=e.value,e=t.next();break;case 74:i.ucsIcon=e.value,e=t.next();break;case 110:i.ucsOrigin=ut(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=ut(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=ut(t),e=t.lastReadGroup;break;case 345:i.ucsTableRecordHandle=e.value,e=t.next();break;case 346:i.baseUcsTableRecordHandle=e.value,e=t.next();break;case 79:i.orthographicType=e.value,e=t.next();break;case 146:i.elevation=e.value,e=t.next();break;case 170:i.shadePlotMode=e.value,e=t.next();break;case 61:i.frequency=e.value,e=t.next();break;case 292:i.lightingFlag=e.value,e=t.next();break;case 282:i.lightingType=e.value,e=t.next();break;case 141:i.viewBrightness=e.value,e=t.next();break;case 142:i.viewContrast=e.value,e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function ut(c){const t={};let e=c.lastReadGroup||c.next();for(;!c.isEOF();){switch(e.code){case 10:case 12:case 13:case 14:case 15:case 16:case 17:case 110:case 111:case 112:t.x=e.value;break;case 20:case 22:case 23:case 24:case 25:case 26:case 27:case 120:case 121:case 122:t.y=e.value;break;case 30:case 32:case 33:case 34:case 35:case 36:case 37:case 130:case 131:case 132:t.z=e.value;break;case 42:t.bulge=e.value;break;default:return t}e=c.next()}return t}class c1{constructor(){g(this,"ForEntityName","XLINE")}parseEntity(t,e){const i={type:e.value,vertices:[]};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 10:i.vertices.unshift(Da(t)),e=t.lastReadGroup;break;case 11:i.directionVector=Da(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Da(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class h1{constructor(){g(this,"ForObjectName","DICTIONARY")}parseObject(t,e){const s={type:e.value},n=[],r=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 280:s.isHardOwner=e.value===1,e=t.next();break;case 281:s.cloningFlag=e.value,e=t.next();break;case 3:n.push(e.value),e=t.next();break;case 350:r.push(e.value),e=t.next();break;case 360:r.push(e.value),e=t.next();break;case 100:e=t.next();break;case 102:e=t.next();break;default:zi(s,e),e=t.next();break}if(n.length!==r.length)throw new Error("The number of Dictionary entries does not match !");return s.entries={},n.forEach((a,o)=>{s.entries[r[o]]=a}),s}}class d1{constructor(){g(this,"ForObjectName","IMAGEDEF")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 90:s.classVersion=e.value,e=t.next();break;case 1:s.filename=e.value,e=t.next();break;case 10:s.imageSize=La(t),e=t.next();break;case 11:s.pixelSize=La(t),e=t.next();break;case 280:s.loaded=e.value,e=t.next();break;case 281:s.resolutionUnits=e.value,e=t.next();break;default:zi(s,e),e=t.next();break}return s}}function La(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class u1{constructor(){g(this,"ForObjectName","LAYOUT")}parseObject(t,e){const s={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 1:s.layoutName=e.value,e=t.next();break;case 70:s.flag=e.value,e=t.next();break;case 71:s.tabOrder=e.value,e=t.next();break;case 76:s.orthographicType=e.value,e=t.next();break;case 10:s.minLimit=kt(t),e=t.lastReadGroup;break;case 11:s.maxLimit=kt(t),e=t.lastReadGroup;break;case 12:s.basePoint=kt(t),e=t.lastReadGroup;break;case 13:s.origin=kt(t),e=t.lastReadGroup;break;case 14:s.minExtent=kt(t),e=t.lastReadGroup;break;case 15:s.maxExtent=kt(t),e=t.lastReadGroup;break;case 16:s.XAxis=kt(t),e=t.lastReadGroup;break;case 17:s.YAxis=kt(t),e=t.lastReadGroup;break;case 146:s.elevation=e.value,e=t.next();break;case 330:s.viewportHandle=e.value,e=t.next();break;default:zi(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function kt(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class f1{constructor(){g(this,"ForObjectName","SORTENTSTABLE")}parseObject(t,e){const s={type:e.value};let n=!1;s.sortEntsObject={},s.sortEntsObject.entityHandles=[];let r=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 5:n?(r.push(e.value),s.sortEntsObject.entityHandles.push(r),r=[]):s.handle=e.value,e=t.next();break;case 100:e=t.next(),n=!0;break;case 102:e=t.next();break;case 330:n?s.sortEntsObject.ownerHandle=e.value:s.ownerHandle=e.value,e=t.next();break;case 331:r.push(e.value),e=t.next();break;default:zi(s,e),e=t.next();break}return s}}class p1{constructor(){g(this,"ForObjectName","SPATIAL_FILTER")}parseObject(t,e){const s={type:e.value};s.vertices=[];let n,r;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 11:s.origin=dn(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),n=dn(t),e=t.lastReadGroup,r=dn(t),e=t.lastReadGroup,s.vertices.push(n,{x:r.x,y:n.y},r,{x:n.x,y:r.y},n)):s.numberOfPointsOnClipBoundary>2?(s.vertices=m1(s.numberOfPointsOnClipBoundary,t),e=t.lastReadGroup):e=t.next();break;case 71:s.clipBoundaryVisible=e.value===1,e=t.next();break;case 72:s.frontClippingPlaneFlag=e.value===1,e=t.next(),s.frontClippingPlaneFlag&&e.code===40&&(s.frontClippingPlaneDistance=e.value,e=t.next());break;case 73:s.backClippingPlaneFlag=e.value===1,e=t.next(),s.backClippingPlaneFlag&&e.code===41&&(s.backClippingPlaneDistance=e.value,e=t.next());break;case 100:e=t.next();break;case 102:e=t.next();break;case 210:s.extrusionDirectionX=e.value,e=t.next();break;case 220:s.extrusionDirectionY=e.value,e=t.next();break;case 230:s.extrusionDirectionZ=e.value,e=t.next();break;case 40:s.invertBlockMatrix=Ra(t,40),s.matrix=Ra(t,40),e=t.lastReadGroup;break;default:zi(s,e),e=t.next();break}return s}}function m1(c,t){t.next();const e=[];for(;e.length<c;)e.push(dn(t));return e}function Ra(c,t){let e=c.lastReadGroup;const i=[];for(let s=0;s<12;s++){if(e.code!==t)throw new Error("Expected code for matrix value to be "+t+" but got "+e.code);i.push(e.value),e=c.next()}return i}function dn(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class g1{constructor(){g(this,"ForObjectName","XRECORD")}parseObject(t,e){const s={type:e.value,binaryData:""};for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 100:e=t.next();break;case 280:s.cloningFlag=e.value,e=t.next();break;case 310:s.binaryData+=e.value,e=t.next();break;case 311:e=t.next();break;default:zi(s,e),e=t.next();break}return s}}function y1(c){c.registerEntityHandler(vd),c.registerEntityHandler(Md),c.registerEntityHandler(Cd),c.registerEntityHandler(Sd),c.registerEntityHandler(Ed),c.registerEntityHandler(_d),c.registerEntityHandler(Pd),c.registerEntityHandler(Id),c.registerEntityHandler(Fd),c.registerEntityHandler(zd),c.registerEntityHandler(Vd),c.registerEntityHandler(Ud),c.registerEntityHandler(Nd),c.registerEntityHandler(qd),c.registerEntityHandler(Wd),c.registerEntityHandler(Yd),c.registerEntityHandler(Xd),c.registerEntityHandler(Jd),c.registerEntityHandler(e1),c.registerEntityHandler(t1),c.registerEntityHandler(i1),c.registerEntityHandler(s1),c.registerEntityHandler(n1),c.registerEntityHandler(a1),c.registerEntityHandler(o1),c.registerEntityHandler(l1),c.registerEntityHandler(c1)}function x1(c){c.registerObjectHandler(h1),c.registerObjectHandler(d1),c.registerObjectHandler(u1),c.registerObjectHandler(f1),c.registerObjectHandler(p1),c.registerObjectHandler(g1)}function b1(c){const t=new Uint8Array(c,0,18);let e="";for(let i=0;i<18;i++)e+=String.fromCharCode(t[i]);return e==="AutoCAD Binary DXF"}class No{constructor(t){g(this,"_entityHandlers",{});g(this,"_objectHandlers",{});g(this,"_layoutBlocks",{});g(this,"unhandledSections",{});g(this,"unhandledObjects",{});g(this,"unhandledEntities",{});g(this,"unsupportedLineTypes",{});g(this,"encoding");this.encoding=t,y1(this),x1(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new Ca(e);return this._parse(i)}else{let e;if(b1(t))e=new gd(t);else{const i=new TextDecoder(this.encoding).decode(t),s=Date.now(),n=this.splitByLineSeparator(i);console.info("[DxfParser] string.split took "+(Date.now()-s)/1e3+"s, it is avoidable by using dxf in binary."),e=new Ca(n)}return this._parse(e)}}registerEntityHandler(t){const e=new t;this._entityHandlers[e.ForEntityName]=e}registerObjectHandler(t){const e=new t;this._objectHandlers[e.ForObjectName]=e}parseSync(t){return this.parse(t)}parseStream(t){let e="";const i=this;return new Promise((s,n)=>{t.on("data",r=>{e+=r}),t.on("end",()=>{try{s(i.parse(e))}catch(r){n(r)}}),t.on("error",r=>{n(r)})})}_parse(t){const e={};let i=0;if(!t.hasNext())throw Error("Empty file");const s=this;let n;function r(){for(n=t.next();n.code===999;)n=t.next();for(;!t.isEOF();)if(n.code===0&&n.value==="SECTION"){if(n=t.next(),n.code!==2){console.error("Unexpected code %s after 0:SECTION",Go(n)),n=t.next();continue}if(n.value==="HEADER")P.trace("> HEADER"),e.header=a(),P.trace("<");else if(n.value==="TABLES")P.trace("> TABLES"),e.tables=h(),P.trace("<");else if(n.value==="BLOCKS")P.trace("> BLOCKS"),e.blocks=o(),P.trace("<");else if(n.value==="ENTITIES")P.trace("> ENTITIES"),e.entities=E(!1),P.trace("<");else if(n.value==="OBJECTS")P.trace("> OBJECTS"),e.objects=M(),P.trace("<");else if(n.value==="EOF")P.trace("EOF");else{const S=n.value;s.unhandledSections[S]?s.unhandledSections[S]++:s.unhandledSections[S]=1}}else n=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let S=null,v=null;const T={};for(n=t.next();;){if(Ge(n,0,"ENDSEC")){S&&(T[S]=v);break}else n.code===9?(S&&(T[S]=v),S=n.value):n.code===10?v={x:n.value}:n.code===20?v.y=n.value:n.code===30?v.z=n.value:v=n.value;n=t.next()}return n=t.next(),T}function o(){const S={};for(n=t.next();n.value!=="EOF"&&!Ge(n,0,"ENDSEC");)if(Ge(n,0,"BLOCK")){P.trace("block {");const v=l();P.trace("}"),O(v),v.name?S[v.name]=v:console.error("[DxfParser] Block with handle '"+v.handle+"' is missing a name, ignored!")}else vt(n),n=t.next();return S}function l(){const S={};for(n=t.next();n.value!=="EOF";){switch(n.code){case 1:S.xrefPath=n.value,n=t.next();break;case 2:S.name=n.value,n=t.next();break;case 3:S.name2=n.value,n=t.next();break;case 4:S.description=n.value,n=t.next();break;case 5:S.handle=n.value,n=t.next();break;case 8:S.layer=n.value,n=t.next();break;case 10:S.position=Xe(t),n=t.lastReadGroup;break;case 67:S.paperSpace=!!(n.value&&n.value===1),n=t.next();break;case 70:S.blockType=n.value,n=t.next();break;case 100:n=t.next();break;case 330:S.ownerHandle=n.value,n=t.next();break;case 0:if(n.value==="ENDBLK")break;S.entities=E(!0);break;default:vt(n),n=t.next();break}if(Ge(n,0,"ENDBLK")){n=t.next();break}}return S}function h(){const S={};for(n=t.next();n.value!=="EOF"&&!Ge(n,0,"ENDSEC");)Ge(n,0,"TABLE")?(n=t.next(),x[n.value]?(P.trace(n.value+" Table {"),S[x[n.value].tableName]=u(n),P.trace("}")):P.trace("Unhandled Table "+n.value)):n=t.next();return n=t.next(),S}const d="ENDTAB";function u(S){const v=x[S.value],T={};let _=0;for(n=t.next();!Ge(n,0,d);)switch(n.code){case 5:T.handle=n.value,n=t.next();break;case 330:T.ownerHandle=n.value,n=t.next();break;case 100:n.value==="AcDbSymbolTable"||vt(n),n=t.next();break;case 70:_=n.value,n=t.next();break;case 0:n.value===v.dxfSymbolName?T[v.tableRecordsProperty]=v.parseTableRecords():(vt(n),n=t.next());break;default:vt(n),n=t.next();break}const A=T[v.tableRecordsProperty];if(A){const I=(()=>{if(A.constructor===Array)return A.length;if(typeof A=="object")return Object.keys(A).length})();_!==I&&console.warn("[DxfParser] Parsed "+I+" "+v.dxfSymbolName+"s but expected "+_)}return n=t.next(),T}function f(){const S=[];let v={};for(P.trace("Viewport {"),n=t.next();!Ge(n,0,d);)switch(n.code){case 2:v.name=n.value,n=t.next();break;case 10:v.lowerLeftCorner=Xe(t),n=t.lastReadGroup;break;case 11:v.upperRightCorner=Xe(t),n=t.lastReadGroup;break;case 12:v.center=Xe(t),n=t.lastReadGroup;break;case 13:v.snapBasePoint=Xe(t),n=t.lastReadGroup;break;case 14:v.snapSpacing=Xe(t),n=t.lastReadGroup;break;case 15:v.gridSpacing=Xe(t),n=t.lastReadGroup;break;case 16:v.viewDirectionFromTarget=Xe(t),n=t.lastReadGroup;break;case 17:v.viewTarget=Xe(t),n=t.lastReadGroup;break;case 40:v.viewHeight=n.value,n=t.next();break;case 41:v.aspectRatio=n.value,n=t.next();break;case 42:v.lensLength=n.value,n=t.next();break;case 43:v.frontClippingPlane=n.value,n=t.next();break;case 44:v.backClippingPlane=n.value,n=t.next();break;case 45:v.viewHeight=n.value,n=t.next();break;case 50:v.snapRotationAngle=n.value,n=t.next();break;case 51:v.viewTwistAngle=n.value,n=t.next();break;case 79:v.orthographicType=n.value,n=t.next();break;case 110:v.ucsOrigin=Xe(t),n=t.lastReadGroup;break;case 111:v.ucsXAxis=Xe(t),n=t.lastReadGroup;break;case 112:v.ucsYAxis=Xe(t),n=t.lastReadGroup;break;case 281:v.renderMode=n.value,n=t.next();break;case 282:v.defaultLightingType=n.value,n=t.next();break;case 292:v.defaultLightingOn=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 63:case 421:case 431:v.ambientColor=n.value,n=t.next();break;case 0:n.value==="VPORT"&&(P.trace("}"),S.push(v),P.trace("Viewport {"),v={},n=t.next());break;default:vt(n),n=t.next();break}return P.trace("}"),S.push(v),S}function m(){const S={};let v={},T=0,_="",A=!1;for(P.trace("LType {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.name=n.value.toUpperCase(),_=v.name,n=t.next();break;case 3:v.description=n.value,n=t.next();break;case 9:n=t.next();break;case 40:v.patternLength=n.value,n=t.next();break;case 44:n=t.next();break;case 45:n=t.next();break;case 46:n=t.next();break;case 49:let I=n.value;A&&(I=Math.abs(I),A=!1),v.pattern.push(I),n=t.next();break;case 70:n=t.next();break;case 73:T=n.value,T>0&&(v.pattern=[]),n=t.next();break;case 74:n.value!==0&&(A=!0,s.unsupportedLineTypes[v.name]?s.unsupportedLineTypes[v.name]++:s.unsupportedLineTypes[v.name]=1),n=t.next();break;case 75:n=t.next();break;case 0:P.trace("}"),T>0&&T!==v.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),S[_]=v,v={},P.trace("LType {"),n=t.next();break;default:n=t.next();break}return P.trace("}"),S[_]=v,S}function b(){const S={};let v={},T;for(P.trace("Layer {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.name=n.value,T=n.value,n=t.next();break;case 5:v.handle=n.value,n=t.next();break;case 62:v.visible=n.value>=0,v.colorIndex=Math.abs(n.value),v.color=ki(v.colorIndex),n=t.next();break;case 70:v.flag=n.value,v.frozen=(v.flag&1)>0,n=t.next();break;case 420:v.color=Math.abs(n.value),n=t.next();break;case 6:v.lineType=n.value.toUpperCase(),n=t.next();break;case 370:v.lineweight=n.value,n=t.next();break;case 0:n.value==="LAYER"&&(P.trace("}"),T&&(S[T]=v),P.trace("Layer {"),v={},T=void 0,n=t.next());break;default:vt(n),n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function y(){const S={};let v={},T;for(P.trace("Style {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.styleName=n.value,T=n.value,n=t.next();break;case 3:v.fontFile=n.value,n=t.next();break;case 4:v.bigFontFile=n.value,n=t.next();break;case 5:v.handle=n.value,n=t.next();break;case 40:v.textHeight=n.value,n=t.next();break;case 41:v.xScale=n.value,n=t.next();break;case 42:v.priorTextHeight=n.value,n=t.next();break;case 50:v.rotation=n.value,n=t.next();break;case 70:n=t.next();break;case 71:v.mirrorType=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 0:n.value==="STYLE"&&(P.trace("}"),T&&(S[T]=v),P.trace("Style {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function C(){const S={};let v={},T;for(P.trace("DimStyle {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 2:v.styleName=n.value,T=n.value,n=t.next();break;case 40:v.DIMSCALE=n.value,n=t.next();break;case 41:v.DIMASZ=n.value,n=t.next();break;case 42:v.DIMEXO=n.value,n=t.next();break;case 44:v.DIMEXE=n.value,n=t.next();break;case 75:v.DIMSE1=n.value,n=t.next();break;case 76:v.DIMSE2=n.value,n=t.next();break;case 77:v.DIMTAD=n.value,n=t.next();break;case 140:v.DIMTXT=n.value,n=t.next();break;case 144:v.DIMLFAC=n.value,n=t.next();break;case 147:v.DIMGAP=n.value,n=t.next();break;case 176:v.DIMCLRD=n.value,n=t.next();break;case 178:v.DIMCLRT=n.value,n=t.next();break;case 271:v.DIMDEC=n.value,n=t.next();break;case 341:v.DIMLDRBLK=n.value,n=t.next();break;case 70:n=t.next();break;case 0:n.value==="DIMSTYLE"&&(P.trace("}"),T&&(S[T]=v),P.trace("DimStyle {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(S[T]=v),S}function w(){const S={};let v={},T;for(P.trace("BlockRecord {"),n=t.next();!Ge(n,0,"ENDTAB");)switch(n.code){case 5:v.handle=n.value,n=t.next();break;case 330:v.ownerHandle=n.value,n=t.next();break;case 2:v.blockName=n.value,T=v.blockName,n=t.next();break;case 340:v.layoutHandle=n.value,n=t.next();break;case 70:v.blockInsertUnits=n.value,n=t.next();break;case 280:v.blockExplodability=n.value,n=t.next();break;case 281:v.blockScalability=n.value,n=t.next();break;case 310:v.bitmap=n.value,n=t.next();break;case 0:if(n.value==="BLOCK_RECORD"){P.trace("}"),T&&(S[T]=v);const A=v.layoutHandle;T&&A&&A.length>0&&A!=="0"&&(s._layoutBlocks[A]=v),P.trace("BlockRecord {"),v={},T=void 0,n=t.next()}else vt(n),n=t.next();break;default:vt(n),n=t.next();break}P.trace("}"),T&&(S[T]=v);const _=v.layoutHandle;return T&&_&&_.length>0&&_!=="0"&&(s._layoutBlocks[_]=v),S}const x={VPORT:{tableRecordsProperty:"viewports",tableName:"viewport",dxfSymbolName:"VPORT",parseTableRecords:f},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:m},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:b},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:w},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:y},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:C}};function E(S){const v=[],T=S?"ENDBLK":"ENDSEC";for(S||(n=t.next());;)if(n.code===0){if(n.value===T)break;const _=s._entityHandlers[n.value];if(_!=null){P.trace(n.value+" {");const A=_.parseEntity(t,n);A&&(A.layer||(A.layer="0"),A.colorIndex===void 0&&(A.colorIndex=256),A.lineType||(A.lineType="BYLAYER"),n=t.lastReadGroup,P.trace("}"),O(A),v.push(A))}else{const A=n.value;s.unhandledEntities[A]||(s.unhandledEntities[A]=0),s.unhandledEntities[A]++,n=t.next();continue}}else n=t.next();return T==="ENDSEC"&&(n=t.next()),v}function M(){const S={},v="ENDSEC";for(n=t.next();n.value!=="EOF";)if(n.code===0){if(n.value===v)break;const T=s._objectHandlers[n.value];if(T!=null){P.trace(n.value+" {");const _=T.parseObject(t,n),A=n.value;n=t.lastReadGroup,P.trace("}"),O(_),S[A]||(S[A]=[]),S[A].push(_)}else{const _=n.value;s.unhandledObjects[_]||(s.unhandledObjects[_]=0),s.unhandledObjects[_]++,n=t.next();continue}}else n=t.next();return n=t.next(),S.LAYOUT&&(Object.keys(s._layoutBlocks).length!==S.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),S.LAYOUT.forEach(T=>{s._layoutBlocks[T.handle]&&(T.associatedBlockName=s._layoutBlocks[T.handle].blockName)}),S.LAYOUT.sort((T,_)=>T.tabOrder-_.tabOrder)),S}function O(S){if(!S)throw new TypeError("entity cannot be undefined or null");S.handle||(S.handle=(i++).toString())}return r(),e}splitByLineSeparator(t){const e=[];let i=0;for(let s=0,n=t.length;s<n;++s){const r=t[s];if(r==="\r"||r===`
792
792
  `){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=hd(a)),a&&(a=a),e.push(a),r==="\r"&&t[s+1]===`
793
- `&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Ge(c,t,e){return c.code===t&&c.value===e}function wt(c){P.trace("unhandled group "+No(c))}function No(c){return c.code+":"+c.value}const Go="0.4.0",qo="VERSION",w1=()=>window.localStorage.getItem(qo),v1=()=>{window.localStorage.setItem(qo,Go)},M1=()=>w1()!==Go?(v1(),!0):!1,si=class si{constructor(){g(this,"DATABASE_NAME","x_viewer");g(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);g(this,"db");g(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!si._instance&&(si._instance=new si),si._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),M1()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,P.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,P.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,P.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{P.debug("onversionchange",e)},this.db=t,Promise.resolve(this.db)}closeDatabase(){this.db&&this.db.close()}deleteDataBase(t){return new Promise((e,i)=>{const s=window.indexedDB.deleteDatabase(t);s.onerror=n=>{P.debug(n),i(n)},s.onsuccess=n=>{const r=n.target;P.debug("[DB] Db "+t+" delete old version "+n.oldVersion+"."),e(r)}})}async getDB(t){return new Promise((e,i)=>{const s=window.indexedDB.open(t);s.onerror=i,s.onsuccess=n=>{const r=n.target.result;P.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async getUpgradedDB(t){return new Promise((e,i)=>{P.debug("[DB] Upgrading db "+t.name+" (version "+t.version+")");const s=window.indexedDB.open(t.name,t.version+1);s.onerror=i,s.onblocked=n=>{P.debug("onblocked",n)},s.onupgradeneeded=n=>{const r=n.target.transaction;r.oncomplete=()=>{P.debug("[DB] Upgrade is done (new version: "+a.version+").")};const a=n.target.result,o=[];for(let l=0;l<this.tables.length;++l){const h=this.tables[l];if(!a.objectStoreNames.contains(h.name)){P.debug("[DB] Creating table "+h.name+"...");const d=this.createTable(a,h.name,h.options,h.indexArray);o.push(d)}}o.length>0&&Promise.all(o).then(()=>{P.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=n=>{const r=n.target.result;P.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async createTable(t,e,i,s){return new Promise(n=>{const r=t.createObjectStore(e,i);s&&s.forEach(a=>{r.createIndex(a.name,a.fields,{unique:a.unique})}),P.debug("[DB] Table "+e+" created."),n(t)})}};g(si,"_instance");let ue=si;class Wo{constructor(){g(this,"db");g(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,ue.instance().getTables().findIndex(i=>i.name===this.tableName())===-1)throw new Error("Failed to find table '"+this.tableName()+"' from indexeddb!")}tableName(){throw new Error("Derived class have to override 'tableName', and set a proper table name!")}add(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()}).catch(n=>{i&&i(n)})}save(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()})}update(){ue.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readonly").objectStore(i),r=n.openCursor();r.onsuccess=a=>{const o=a.target.result;o&&o.continue(),t&&t(o)},r.onerror=e}).finally(()=>{ue.instance().closeDatabase()})}queryByIndex(t,e,i,s){const n=this.tableName();ue.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.index(t).get(e);o.onerror=s,o.onsuccess=function(l){const h=l.target?.result;i&&i(h)}}).finally(()=>{ue.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readonly").objectStore(i),r=n.getAll();r.onsuccess=a=>{t&&t(a.target.result)},r.onerror=e}).finally(()=>{ue.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readwrite").objectStore(i),r=n.clear();r.onsuccess=a=>{t&&t(a)},r.onerror=a=>{e&&e(a)}}).finally(()=>{ue.instance().closeDatabase()})}}const ni=class ni extends Wo{tableName(){return"dxf_data"}static instance(){return!ni._instance&&(ni._instance=new ni),ni._instance}query(t,e,i){const s=[],n=this.tableName();ue.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.get(t);o.onerror=l=>{i&&i(l),P.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{ue.instance().closeDatabase()})}};g(ni,"_instance");let pn=ni;const qe=new p.Vector3(1,0,0),Wn=new p.Vector3(0,1,0),mi=new p.Vector3(0,0,1),za=new p.Vector3(0,0,0),Rt=16777215,T1="CONTINUOUS",Gs=new p.PointsMaterial({color:Rt}),me=new p.LineBasicMaterial({color:Rt}),gi=new p.MeshBasicMaterial({color:Rt}),Va=new p.BufferGeometry().setFromPoints([new p.Vector3]),ja=new p.Matrix4,tt=new p.Matrix4,de=new p.Matrix4,U=new p.Vector3,K=new p.Vector3,it=new p.Vector3,Ji=new p.Vector2,ge=new p.Quaternion,qs=new p.Object3D,ft=new p.Box3,Ua=new p.PointsMaterial({color:65280,size:5,depthTest:!1}),Ha=new p.PointsMaterial({color:65280,depthTest:!1}),Na=new p.PointsMaterial({color:65280,depthTest:!1}),C1=c=>c.viewDirectionFromTarget!==void 0,S1=c=>{if(c){const t=c.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);if(t&&t.length>0){const e=t[1],i=c.replace("data:"+e+";","").split(",");if(i&&i.length===2&&i[0]==="base64"){const s=i[1];return hc.decode(s)}}}return null},Ga=(c,t)=>{const e=new p.Vector2(c.x,c.y),i=new p.Vector2(t.x,t.y);return i.sub(e),i.normalize(),i.y<0?-Math.acos(i.x):Math.acos(i.x)},qa=(c,t,e)=>({x:c.x+t*Math.cos(e),y:c.y+t*Math.sin(e)}),E1=(c,t,e,i)=>{const s=c?new p.Vector2(c.x,c.y):new p.Vector2(0,0),n=t?new p.Vector2(t.x,t.y):new p.Vector2(1,0);e=e||1;const r=4*Math.atan(e),a=s.distanceTo(n)/2/Math.sin(r/2),o=qa(c,a,Ga(s,n)+(Math.PI/2-r/2));i=i||Math.max(Math.abs(Math.ceil(r/(Math.PI/18))),6);const l=Ga(o,s),h=r/i,d=[];d.push(new p.Vector3(s.x,s.y,0));for(let u=1;u<=i-1;u++){const f=qa(o,Math.abs(a),l+h*u);d.push(new p.Vector3(f.x,f.y,0))}return d},Wa=(c,t,e,i=c.length*2,s)=>{const n=[];if(!c||c.length<t+1||t<1)return n;const r=c.map(a=>[a.x,a.y]);try{for(let a=0;a<1;a+=1/i){const o=Do(a,t,r,e,s);n.push(new p.Vector3(o[0],o[1],0))}}catch{if(n.length===0)return n}return n},Yn=(c,t=!1)=>{const e=[],i=c.length;for(let s=0;s<i;s++){const n=c[s];if(n.bulge&&(s!==i-1||t)){const r=n.bulge,a=s+1<i?c[s+1]:e[0],o=E1(n,a,r);e.push(...o)}else e.push(new p.Vector3(n.x,n.y,0))}return e},O1=c=>{const t=[];return c.faceA&&t.push(c.faceA),c.faceB&&t.push(c.faceB),c.faceC&&t.push(c.faceC),c.faceD&&t.push(c.faceD),t},_1=c=>{const t=[],e=[];c.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new p.Vector3(s.x,s.y,s.z)):e.push(O1(s)))});const i=[];for(let s=0;s<e.length;s++){const n=e[s];if(n.length===0)continue;const r=[];let a=!0;for(let o=0;o<n.length;o++){const l=n[o]-1;if(l>=t.length||l<0){a=!1;break}r.push(t[l])}!a||r.length===0||(r.push(r[0]),i.push(r))}return i},H=class H extends p.Loader{constructor(e,i){super(e);g(this,"timer");g(this,"ignorePaperSpace");g(this,"font");g(this,"encoding");g(this,"overrideColor");g(this,"overrideHatchPatternLineThickness");g(this,"angBase");g(this,"angDir");g(this,"header");g(this,"pointsMaterials");g(this,"lineBasicMaterials");g(this,"lineShaderMaterials");g(this,"meshBasicMaterials");g(this,"meshTextureMaterials");g(this,"hatchShaderMaterials");g(this,"entityCount");g(this,"curveCount");g(this,"averageCurveSize");g(this,"enableRenderOrder");g(this,"enableLocalCache");g(this,"enableReleaseData");g(this,"enableMerge");g(this,"enableRTC");g(this,"enablePlineWidth");g(this,"dxfDataId");g(this,"compareContext");g(this,"statsInfo");g(this,"llbDatas");g(this,"mtextDatas");g(this,"requestHeader");g(this,"blockReferencesCache");g(this,"blockRecordsCache");g(this,"entitiesCache");g(this,"blocksCache");g(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");g(this,"spatialFiltersCache");g(this,"entityThreejsCache");g(this,"entityTypesAndTimes");g(this,"nonSnapableTypes");g(this,"layoutsSnapObjectsMap");g(this,"aborted");g(this,"entityHandlesWithRenderOrder");g(this,"addViewport");this.timer=Date.now(),this.ignorePaperSpace=!1,this.encoding="UTF-8",this.angBase=0,this.angDir=0,this.header=void 0,this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[],this.entityCount=0,this.curveCount=0,this.averageCurveSize=0,this.enableRenderOrder=!1,this.enableLocalCache=!1,this.enableReleaseData=!0,this.enableMerge=!0,this.enableRTC=!0,this.enablePlineWidth=!0,this.dxfDataId=void 0,this.compareContext=void 0,this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0,requestHeader:{}},this.llbDatas=[],this.mtextDatas=[],this.blockReferencesCache={},this.blockRecordsCache=void 0,this.entitiesCache=void 0,this.blocksCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.nonSnapableTypes=new Set(["ATTDEF","ATTRIB","LEADER","MTEXT","MULTILEADER","OLE2FRAME","TEXT"]),this.layoutsSnapObjectsMap={},this.aborted=!1,this.entityHandlesWithRenderOrder={},this.addViewport=(s,n)=>{if(s.type==="VIEWPORT"){!n[s.ownerHandle]&&(n[s.ownerHandle]=[]);const r=s;n[s.ownerHandle].push(r)}},i&&(this.ignorePaperSpace=i.ignorePaperSpace===!0,this.enableLocalCache=i.enableLocalCache===!0,this.enableMerge=H.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.requestHeaders&&(this.requestHeader=i.requestHeaders),i.overrideColor!=null&&(this.overrideColor=Li.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[Rt]=Gs,this.lineBasicMaterials[Rt]=me,this.meshBasicMaterials[Rt]=gi}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=S1(e);if(!s){const n=Date.now(),r=new p.FileLoader(this.manager);this.requestHeader&&Object.keys(this.requestHeader).length>0&&r.setRequestHeader(this.requestHeader),r.setResponseType("arraybuffer"),r.setPath(this.path),s=await r.loadAsync(e,i),P.info("[Dxf] "+e+" dxf file downloaded in "+(Date.now()-n)/1e3+"s")}return s}async loadEx(e,i,s){return this.enableLocalCache&&i&&(i=i.trim()).length>0&&(this.dxfDataId=i),this.loadAsync(e,s)}async loadAsync(e,i){const s=j.getUpdateSubProgressFunc(0,50,i),n=j.getUpdateSubProgressFunc(50,100,i),r=j.getUpdateSubProgressFunc(10,100,i);if(Be.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),P.info("[Dxf] Loaded DxfData from indexedDb in "+(Date.now()-this.timer)/1e3+"s");const h=await this.loadEntities(l,r);return Promise.resolve(h)}}catch(h){P.warn("[Dxf] Failed to parse data from indexedDb",h)}}const a=await this.parse(e,s);return this.tryFixDxfData(a),await this.loadEntities(a,n)}async parse(e,i){const s=j.getUpdateProgressFunc(i),n=j.getUpdateSubProgressFunc(0,40,i),r=await this.download(e,n);if(!r)return Promise.reject("[Dxf] Failed to download "+e);if(this.aborted)return Promise.reject("[Dxf] Job aborted");this.timer=Date.now(),P.info("[Dxf] Start parsing...");const a=new Ho(this.encoding).parseSync(r);if(this.tryFixDxfData(a),s(80),P.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&Be.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),P.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){P.warn("[Dxf] Failed to save '"+this.dxfDataId+"' to indexedDb!",l)}}return s(100),a}abort(){this.aborted=!0}isAborted(){return this.aborted}parseHeader(e){if(!e){P.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&P.warn("[Dxf] Unexpected version: "+i+". But we'll try to continue."),this.angBase=e.$ANGBASE||0,this.angDir=e.$ANGDIR||0}tryFixDxfData(e){e&&(!e.objects&&(P.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(P.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:H.MODEL_LAYOUT_NAME}]),!e.tables&&(P.warn("[Dxf] No tables found, Will add one."),e.tables={}),!e.tables.layer&&(e.tables.layer={}),!e.tables.layer.layers&&(e.tables.layer.layers={}))}async loadEntities(e,i){const s=Date.now();this.parseHeader(e.header),this.enableRenderOrder&&(this.initRenderOrderInfo(e),this.enableMerge=!1),this.getFontFilesFromDxf(e);let n=0;const r=e.entities.length;this.entityCount=r,Object.keys(e.blocks).forEach(x=>{this.entityCount+=e.blocks[x].entities?.length||0});const a=j.getUpdateProgressFuncForLoop(r,i);let o={};const l=x=>{const E=x.userData.layerName;let M=o[E];!M&&(M=[],o[E]=M),M.push(x)},h={},d={},u=new V;for(let x=0;x<r&&!this.aborted;x++){const E=e.entities[x];this.addViewport(E,h);const M=this.loadEntity(E,e);if(!M&&await a(x),!M)continue;const O=this.getLayout(e,E),S=O.layoutName;let v=u.children.find(T=>T.name===S);if(!v&&(v=new V,v.name=S,v.userData.isLayoutLevelObject=!0,u.add(v)),M.traverse(T=>{T.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[S]&&(this.layoutsSnapObjectsMap[S]=[]),this.layoutsSnapObjectsMap[S].push(T))}),this.enableMerge){Mt.merge(M,!1),!d[S]&&(d[S]={object:v,layerObjects:{}});const _=d[S];if(M.geometry){const A=M.userData.layerName;!_.layerObjects[A]&&(_.layerObjects[A]=[]),_.layerObjects[A].push(M),M.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else M.children.length>0&&(v.add(M),M.traverse(A=>{A.geometry&&l(A)}))}else v.add(M),M.traverse(T=>{T.geometry&&l(T)});n++,await a(x)}e.objects.LAYOUT.forEach(x=>{const E=x,M=E.layoutName;if(this.ignorePaperSpace&&M!==H.MODEL_LAYOUT_NAME)return;const O=E.associatedBlockName,S=e.blocks[O];S&&this.loadLayout(S,e,E,u,o,h)}),P.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const x in this.layoutsSnapObjectsMap){const E=u.children.find(S=>S.name===x),M=new V;M.name=H.SNAP_GROUP_NAME,M.userData.isSnapGroup=!0,E.add(M);const O=this.layoutsSnapObjectsMap[x];for(let S=0;S<O.length;S++){const v=O[S],T=v.userData.layerName;this.getLayerVisible(e,T)===!1&&v.layers.disable(je),H.SHOW_SNAP_OBJECT&&(v.layers.enableAll(),v.material instanceof p.PointsMaterial?v.material=Ua:v.material instanceof p.LineBasicMaterial?v.material=Ha:v.material instanceof p.MeshBasicMaterial&&(v.material=Na));let _=v;const A=de.identity();for(;_&&_.userData.isLayoutLevelObject!==!0;)A.premultiply(_.matrix),_=_.parent;v.matrix.copy(A),M.add(v)}}if(this.enableMerge)for(const x in d){const E=d[x],M=E.object;for(const O in E.layerObjects){const S=E.layerObjects[O],v=Mt.deepMerge(S,void 0,!1,!1,!0),T=v.added,_=v.removed;if(_.length!==S.length){let A=_;_.length>=100&&(A=new Set(_));const I=B=>Array.isArray(A)?A.indexOf(B)>=0:A.has(B);for(let B=0,k=S.length;B<k;B++){const L=S[B];!I(L)&&(M.add(L),l(L))}}for(let A=0;A<T.length;A++){const I=T[A];M.add(I),l(I)}E.layerObjects[O]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&H.mergeDxfObjects({root:u,layersAndObjects:o});const m=u.convertToThreejsObject();u.clear(),o={};const b={};e.objects.LAYOUT.forEach(x=>{const E=x;b[E.layoutName]=E});const y={},C=x=>{const E=x.userData.layerName;let M=y[E];!M&&(M=[],y[E]=M),M.push(x)};m.children.forEach(x=>{if(J.setSharedVariablesOfObject(x),!x.userData.isLayoutLevelObject)return;const E=x.name;let M;if(E!==H.MODEL_LAYOUT_NAME){const O=b[E];!O.directAssociatedLeafObjectSet&&(O.directAssociatedLeafObjectSet=new Set),M=O.directAssociatedLeafObjectSet}x.traverse(O=>{if(J.setSharedVariablesOfObject(O),O.userData.isSnapGroup&&(O.visible=H.SHOW_SNAP_OBJECT),O.geometry){const S=O.userData.layerName;this.getLayerVisible(e,S)===!1&&(O.visible=!1,O.userData.layerVisible=!1),C(O),M&&M.add(O)}})}),P.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const w=Object.assign(Object.assign({},e),{threejsObject:m,layersAndThreejsObjects:y,loadedEntityCount:n,layoutViewportsMap:h});if(H.LOADLLDATA){const x=m.children[0].children,E=[];for(let M=0;M<x.length;M++){const O=x[M];if(O?.userData?.llbData){const S=new p.Box3().setFromObject(O);S.getSize(new p.Vector3);const v=S.getCenter(new p.Vector3);E.push({...O,boundingBox:{max:S.max,min:S.min,center:v}})}else if(O.children&&O.children.some(S=>S.userData?.llbData))for(let S=0;S<O.children.length;S++){const v=O.children[S];if(v.userData?.llbData){v.updateWorldMatrix(!0,!0);const T=new p.Box3().setFromObject(v);T.getSize(new p.Vector3);const _=T.getCenter(new p.Vector3);E.push({...v,boundingBox:{max:T.max,min:T.min,center:_}})}}}w.llbMesh=E}return Promise.resolve(w)}getFontFilesFromDxf(e){const i=new Set,s=e.tables?.style?.styles;if(s)for(const n in s){const r=s[n],a=r.fontFile,o=r.bigFontFile;a&&i.add(a),o&&i.add(o)}P.info("[Dxf] Fonts used by dxf: "+Array.from(i).join())}async loadEntitiesForCompare(e,i,s,n=!0,r){const a=e.entities.length,o=i.entities.length,l=async()=>{const d=this.compareContext,u=d.isTheFirstFile,f=u?e:i,m=new V,b=u?a:o;this.entityCount=b,Object.keys(f.blocks).forEach(v=>{this.entityCount+=f.blocks[v].entities?.length||0});const y=Math.round(Math.pow(b,.5));let C=Date.now();const w=async v=>{if(r&&(v%y===0||v===b-1)){let T=v+1;!u&&(T+=a),r(new ProgressEvent("parseProgress",{loaded:T,total:a+o}));const _=500,A=Date.now();(A-C>_||v===b-1)&&(await j.sleep(0),C=A)}};this.parseHeader(f.header);let x={};for(let v=0;v<b;v++){if(this.aborted)return;const T=f.entities[v],_=this.getLayout(f,T);if(_.layoutName!==H.MODEL_LAYOUT_NAME){await w(v);continue}const A=this.loadEntity(T,f);if(!A){await w(v);continue}let I=m.children.find(B=>B.name===H.MODEL_LAYOUT_NAME);!I&&(I=new V,I.name=H.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,m.add(I)),I.add(A),A.traverse(B=>{if(B.geometry){const k=B.userData.layerName,L=this.getLayerVisible(f,k);B.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[_.layoutName]&&(this.layoutsSnapObjectsMap[_.layoutName]=[]),this.layoutsSnapObjectsMap[_.layoutName].push(B),L===!1&&A.layers.disable(je));let F=x[k];!F&&(F=[],x[k]=F),F.push(B)}}),await w(v)}n&&u&&!d.preservedHandles&&(d.preservedHandles=new Set);for(const v in s){const T=s[v];u&&(T.type===Ve.Added||T.type===Ve.Modified)&&(d.preservedHandles?.add(T.handle),T.parentHandles&&T.parentHandles.forEach(A=>d.preservedHandles?.add(A)));let _=this.entityThreejsCache&&this.entityThreejsCache[T.handle];if(T.parentHandles&&(_=this.entityThreejsCache&&this.entityThreejsCache[T.parentHandles[T.parentHandles.length-1]]),_){if(_.parent&&_.parent.userData.originalType){this.setObjectColorByChange(_,{type:Ve.NoChange});continue}_=this.setObjectColorByChange(_,T)}if(T.type!==Ve.NoChange&&_){let A=_.parent;const I=de.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;ft.makeEmpty();const B=V.getBox(_,ft);B.applyMatrix4(I),T.type===Ve.Added?!u&&(T.box=new p.Box3().copy(B)):T.type===Ve.Removed?u&&(T.box=new p.Box3().copy(B)):T.type===Ve.Modified&&(T.box?T.box.union(B):T.box=new p.Box3().copy(B))}}for(const v in this.layoutsSnapObjectsMap){const T=m.children.find(I=>I.name===v),_=new V;_.name=H.SNAP_GROUP_NAME,T.add(_);const A=this.layoutsSnapObjectsMap[v];for(let I=0;I<A.length;I++){const B=A[I];H.SHOW_SNAP_OBJECT&&(B.layers.enableAll(),B.material instanceof p.PointsMaterial?B.material=Ua:B.material instanceof p.LineBasicMaterial?B.material=Ha:B.material instanceof p.MeshBasicMaterial&&(B.material=Na));let k=B;const L=de.identity();for(;k&&k.userData.isLayoutLevelObject!==!0;)L.premultiply(k.matrix),k=k.parent;B.matrix.copy(L),_.add(B)}}this.enableMerge&&H.mergeDxfObjects({root:m,layersAndObjects:x});const E=m.convertToThreejsObject();m.clear(),x={};const M={},O=v=>{const T=v.userData.layerName;let _=M[T];!_&&(_=[],M[T]=_),_.push(v)};E.children.forEach(v=>{J.setSharedVariablesOfObject(v),v.userData.isLayoutLevelObject&&v.traverse(T=>{if(J.setSharedVariablesOfObject(T),T.userData.isSnapGroup&&(T.visible=H.SHOW_SNAP_OBJECT),T.geometry){const _=T.userData.layerName;this.getLayerVisible(f,_)===!1&&(T.visible=!1,T.userData.layerVisible=!1),O(T)}})});const S=f;S.threejsObject=E,S.layersAndThreejsObjects=M,S.layoutViewportsMap={}};let h=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},j.printMemory("Before loading entities for first dxf"),await l(),P.info("[Dxf] loadEntities for first dxf in "+(Date.now()-h)/1e3+"s"),j.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),j.printMemory("Before loading entities for second dxf"),h=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),P.info("[Dxf] loadEntities for second dxf in "+(Date.now()-h)/1e3+"s"),this.printStatsInfo();for(const d of Object.values(s))!d.box&&delete s[d.id];this.compareContext.preservedHandles=void 0,this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(i)),j.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=at.ENTITY_COLOR_NO_CHANGE;return a.type===Ve.Added?o=at.ENTITY_COLOR_ADDED:a.type===Ve.Removed?o=at.ENTITY_COLOR_REMOVED:a.type===Ve.Modified&&(o=this.compareContext?.isTheFirstFile?at.ENTITY_COLOR_REMOVED:at.ENTITY_COLOR_ADDED),o},n=(a,o)=>{a.traverse(l=>{if(l.material){if(l.material instanceof p.LineBasicMaterial)l.material=this.getLineBasicMaterial(o);else if(l.material instanceof p.MeshBasicMaterial)l.material=this.getMeshBasicMaterial(o);else if(l.material instanceof p.PointsMaterial)l.material=this.getPointsMaterial(o);else if(l.material instanceof p.ShaderMaterial){const h=l.material.clone();H.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o),l.material=h}}})},r=s(i);return e.traverse(a=>{i.parentHandles?a.userData&&a.userData.handle&&a.userData.handle===i.handle&&(n(a,r),e=a):n(a,r)}),e}releaseCachedData(e=!0){e&&(this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[]),this.header=void 0,this.blockReferencesCache={},this.blockRecordsCache=void 0,this.blocksCache=void 0,this.entitiesCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.entityHandlesWithRenderOrder={},this.layoutsSnapObjectsMap={},this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0}}releaseEntity(e){e.vertices&&(e.vertices=void 0),e.knotValues&&(e.knotValues=void 0),e.controlPoints&&(e.controlPoints=void 0),e.binaryData&&(e.binaryData=void 0),e.text&&(e.text=void 0),e.extendedData&&(e.extendedData=void 0),e.contextData&&(e.contextData=void 0);const i=e;i.boundaryPaths&&(i.boundaryPaths=[]),i.patternLines&&(i.patternLines=void 0)}releaseDxfData(e){delete e.objects.DICTIONARY,delete e.objects.SORTENTSTABLE,delete e.objects.XRECORD,e.tables&&(delete e.tables.dimStyle,delete e.tables.lineType,delete e.tables.style,delete e.tables.blockRecord),e.entities=[],e.blocks={}}loadEntity(e,i,s,n=!1){if(this.compareContext&&this.compareContext.preservedHandles&&this.compareContext.preservedHandles.has(e.handle)&&os.includes(e.type)&&(n=!0),!n&&this.compareContext&&this.compareContext.preservedHandles&&!os.includes(e.type)&&!this.compareContext.preservedHandles.has(e.handle)&&(!s||s&&!this.compareContext.preservedHandles.has(s.handle)))return;if(this.getLayerFrozen(i,e)===!0){const f=e.layer;return!this.statsInfo.ignoredFrozenLayersAndEntityCount[f]&&(this.statsInfo.ignoredFrozenLayersAndEntityCount[f]=0),this.statsInfo.ignoredFrozenLayersAndEntityCount[f]++,void 0}if(e.visible===!1||e.invisible)return!this.statsInfo.invisibleEntities[e.type]&&(this.statsInfo.invisibleEntities[e.type]=0),this.statsInfo.invisibleEntities[e.type]++,void 0;if(this.ignorePaperSpace&&e.inPaperSpace)return!this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]&&(this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]=0),this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]++,void 0;!this.entityThreejsCache&&(this.entityThreejsCache={});const a=Date.now();let o,l=!1;if(!this.compareContext&&this.entityThreejsCache[e.handle])o=this.entityThreejsCache[e.handle].clone(),l=!0;else if(!this.statsInfo.unsupportedEntity[e.handle]){const f=e.isTable;if(e.type==="CIRCLE"||e.type==="ARC")o=this.loadArc(e,i,s);else if(e.type==="LINE"||e.type==="POLYLINE")o=this.loadLine(e,i);else if(e.type==="XLINE")o=this.loadXLine(e);else if(e.type!=="SEQEND"){if(e.type==="RAY")o=this.loadRay(e);else if(e.type==="LWPOLYLINE")o=this.loadLWPolyline(e,i,s);else if(e.type==="3DFACE")o=this.load3DFace(e);else if(e.type==="TEXT")o=this.loadText(e,i,s);else if(e.type==="SOLID")o=this.loadSolid(e,i,s);else if(e.type==="POINT")o=this.loadPoint(e,i,s);else if(e.type==="IMAGE")o=this.loadImage(e,i,s);else if(e.type==="INSERT")o=this.loadInsert(e,i,s,n);else if(e.type==="SPLINE")o=this.loadSpline(e,s);else if(e.type==="MTEXT")f?o=this.loadTableMText(e,i,s):o=this.loadMText(e,i,s);else if(e.type==="ELLIPSE")o=this.loadEllipse(e,i,s);else if(e.type==="DIMENSION")o=this.loadDimension(e,i);else if(e.type!=="REGION")if(e.type==="ATTDEF")o=this.loadAttDef(e,i,s);else if(e.type==="ATTRIB"){if(!s)for(let m=0;m<i.entities.length;m++){const b=i.entities[m];if(e.ownerHandle===b.handle&&(s=b,s.attributesFollow))break}o=this.loadAttrib(e,i,s)}else e.type==="HATCH"?o=this.loadHatch(e,i,s):e.type==="VIEWPORT"?o=this.loadViewport(e,i,s):e.type==="LEADER"?o=this.loadLeader(e,i,s):e.type==="MULTILEADER"?o=this.loadMLeader(e,i,s):e.type==="OLE2FRAME"?o=this.loadOle2frame(e,i):e.type==="ACAD_TABLE"&&(o=this.loadTable(e,i))}o&&(this.entityThreejsCache[e.handle]=o),this.enableReleaseData&&!this.compareContext&&this.releaseEntity(e)}if(o){const f=this.getLayerName(e,i,s);o.userData.handle=e.handle,e.type!=="INSERT"&&e.type!=="DIMENSION"&&o.traverse(m=>{m.geometry&&(m.userData.layerName=f,m.userData.handle=e.handle,m.userData.dxfType=e.type,this.setMaterial(m,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(m=>{m.layers.disable(je)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16)))}const h=e.type,d=e.handle,u=os.includes(h);if(!u){this.entityTypesAndTimes||(this.entityTypesAndTimes={}),this.entityTypesAndTimes[h]||(this.entityTypesAndTimes[h]={createCount:0,totalTime:0,averageTime:0});const f=this.entityTypesAndTimes[h];f.createCount++,f.totalTime+=Date.now()-a}return o?this.statsInfo.entityTypesAndMeshCount[h]?this.statsInfo.entityTypesAndMeshCount[h]++:this.statsInfo.entityTypesAndMeshCount[h]=1:(this.statsInfo.unsupportedEntityTypes[h]?this.statsInfo.unsupportedEntityTypes[h]++:this.statsInfo.unsupportedEntityTypes[h]=1,u||(this.statsInfo.unsupportedEntity[d]?this.statsInfo.unsupportedEntity[d]++:this.statsInfo.unsupportedEntity[d]=1)),o}loadEllipse(e,i,s){if(!e.majorAxisEndPoint||!e.center||e.axisRatio===void 0||e.startAngle===void 0||e.endAngle===void 0)return;let n=e.startAngle,r=e.endAngle;if(e.extrusionDirection&&e.extrusionDirection.z<0&&(n=Math.PI*2-e.endAngle,r=Math.PI*2-e.startAngle),z.areNumbersEqual(n,r,1e-5))return P.warn("[Dxf] Ellipse entity (handle '%s') contains the same start and end angle, ignored!",e.handle),void 0;let a=r-n;for(;a>Math.PI*2;)a-=Math.PI*2;Math.abs(a)<=1e-5&&(r=z.floorNumber(n+Math.PI*2,5));const o=Math.sqrt(Math.pow(e.majorAxisEndPoint.x,2)+Math.pow(e.majorAxisEndPoint.y,2)),l=o*e.axisRatio,h=Math.atan2(e.majorAxisEndPoint.y,e.majorAxisEndPoint.x),d=new p.EllipseCurve(e.center.x,e.center.y,o,l,n,r,!1,h);let u=1;const f=s;f?.xScale&&f?.yScale&&(u=Math.max(Math.abs(f.xScale),Math.abs(f.yScale)));const m=this.getDivision(n,r,Math.max(o,l)*u),b=d.getPoints(m),y=[],C=b.length;for(let S=0;S<C-1;S++)z.areVector2sEqual(b[S],b[S+1],1e-9)||y.push(b[S]);if(y.push(b[C-1]),y.length<2)return P.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const w=new p.Vector3;let x=!1;this.enableRTC&&(x=N.checkAndRebasePositionsOnRTC(y,w));const E=new p.BufferGeometry().setFromPoints(y),M=new V(G.Line);M.geometry=E,M.material=me;const O=new V(G.Point);return O.geometry=Va,O.material=Gs,O.matrix.setPosition(e.center.x,e.center.y,e.center.z),O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(je),M.add(O),x&&(this.setRTCUserData(M),M.matrix.setPosition(w.x,w.y,0)),M.layers.enableAll(),M}loadMText(e,i,s){if(!e.text)return;if(!this.font)return P.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ls(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(K,ge,it),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,it)),ft.makeEmpty();const l=V.getBox(o,ft),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u,m=e.text;let b=0,y=0;switch(document.createElement("canvas").getContext("2d"),e.attachmentPoint){case 1:b=0,y=0;break;case 2:b-=d/2,y=0;break;case 3:b-=d,y=0;break;case 4:b=0,y+=f/2;break;case 5:b-=d/2,y+=f/2;break;case 6:b-=d,y+=f/2;break;case 7:b=0,y+=f;break;case 8:b-=d/2,y+=f;break;case 9:b-=d,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=u;break;case 4:break;case 5:const I=m.split("\\P");let B=0;I>1&&(B=I-1),B>1?y+=u*(B-1):y-=u/4;break;default:return}o.traverse(I=>{I.geometry&&I.geometry.translate(b,y,0),I.layers.enableAll()});let w=0;if(e.rotation&&(w=e.rotation*Math.PI/180),e.directionVector){const I=e.directionVector,B=new p.Vector3(I.x,I.y,I.z),k=B.clone().cross(qe),L=qe.angleTo(B);w=k.z>0?-L:L}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,it);const x=e.position?K.clone().sub(e.position):K;tt.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),o.matrix.multiply(tt),o.matrix.multiply(de),o.matrix.multiply(tt.invert()),o.userData||(o.userData={});const E=o.matrix.elements,M=E&&E[12]||0,O=E&&E[13]||0,S=E&&E[14]||0,v=new p.Box3;V.getBox(o,v);const T=new p.Vector3;v.getCenter(T);const _=new p.Vector3;v.getSize(_),o.userData.renderArea={position:{x:M,y:O,z:S},bbox:{min:{x:v.min.x,y:v.min.y,z:v.min.z},max:{x:v.max.x,y:v.max.y,z:v.max.z},center:{x:T.x,y:T.y,z:T.z},width:_.x,height:_.y,depth:_.z},textSize:{width:d,height:u},rotation:w,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const A=this;return o.userData.textContent=e.text||"",o.userData.cleanText=A.cleanMTextContent?A.cleanMTextContent(e.text):e.text,o.userData.dxfType="MTEXT",o.userData.isMText=!0,o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",o.traverse(I=>{I.geometry&&(I.userData.textContent=e.text||"",I.userData.dxfType="MTEXT",I.userData.layer=e.layer||"0",I.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return P.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ls(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(K,ge,it),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,it)),ft.makeEmpty();const l=V.getBox(o,ft),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,b=0;switch(e.attachmentPoint){case 1:m=0,b=0;break;case 2:m-=d/2,b=0;break;case 3:m-=d,b=0;break;case 4:m=0,b+=f/2;break;case 5:m-=d/2,b+=f/2;break;case 6:m-=d,b+=f/2;break;case 7:m=0,b+=f;break;case 8:m-=d/2,b+=f;break;case 9:m-=d,b+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:b+=u;break;case 4:break;case 5:break;default:return}o.traverse(w=>{w.geometry&&w.geometry.translate(m,b,0),w.layers.enableAll()});let y=0;if(e.rotation&&(y=e.rotation*Math.PI/180),e.directionVector){const w=e.directionVector,x=new p.Vector3(w.x,w.y,w.z),E=x.clone().cross(qe),M=qe.angleTo(x);y=E.z>0?-M:M}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,it);const C=e.position?K.clone().sub(e.position):K;return tt.makeTranslation(-C.x,-C.y,0),de.makeRotationZ(y),o.matrix.multiply(tt),o.matrix.multiply(de),o.matrix.multiply(tt.invert()),o}getMTextGroup(e,i,s,n,r,a=0,o=0,l=[]){if(e.length===0)return;let h=i.height||i.contextData&&i.contextData.textHeight||0;if(i.textStyle){if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const M=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[M]&&(this.statsInfo.unsupportedTextStyles[M]=0),this.statsInfo.unsupportedTextStyles[M]++}h=h||s.textHeight}let d="Left";i.width&&i.attachmentPoint&&([1,4,7].includes(i.attachmentPoint)?d="Left":[2,5,8].includes(i.attachmentPoint)?d="Center":[3,6,9].includes(i.attachmentPoint)&&(d="Right"));const u=i.width||0,f=new V;let m,b=s.fontFile,y=1,C=1,w=256,x=h*.8,E=x+h;for(let M=0;M<e.length;M++){const O=e[M];if(typeof O=="string"){const S=[],v=A=>{let I;if(A.forEach((B,k)=>{!B.boundingBox&&B.computeBoundingBox(),k===0?I=B.boundingBox:I.union(B.boundingBox)}),I){const B=I.getSize(U);switch(d){case"Left":break;case"Center":A.forEach(k=>k.translate((u-B.x)/2,0,0));break;case"Right":A.forEach(k=>k.translate(u-B.x,0,0));break}}S.push(...A)};let T;for(let A=0;A<O.length;A++){const I=O[A];if(I===`
794
- `){a=0,o-=E,l.length>0&&v(l),l=[];continue}if(x=h*.8,E=x+h,T=this.font?.getCharShape(I,b,h),s.bigFontFile&&!T&&(T=this.font?.getCharShape(I,s.bigFontFile,h)),!T&&(T=this.font?.getCharShape(I,"",h)),!T&&(T=this.font?.getNotFoundTextShape(h)),!T){a+=h+C*(h/3.5);continue}a>(u||1/0)&&(l.length>0&&v(l),a=0,o-=E,l=[]),T.translate(a,o,0),T.scale(y,1,1),T.boundingBox||T.computeBoundingBox(),O.T&&(C=O.T);const B=cd(I,T,h,C,b);a+=B,l.push(T)}l.length>0&&(v(l),l=[]);const _=new V;if(S.length>0){!m&&(m=i.colorIndex),w!==void 0&&w!==256?(i.color=ki(w),i.colorIndex=w):i.colorIndex=m;const A=this.getColor(i,n,r),I=S.filter(k=>k instanceof p.ExtrudeGeometry),B=S.filter(k=>!(k instanceof p.ExtrudeGeometry));if(I.length>0){const k=new V(G.Mesh);k.geometry=Pe.mergeGeometries(I),k.material=this.getMeshBasicMaterial(A),_.add(k)}if(B.length>0){const k=new V(G.LineSegment);k.geometry=Pe.mergeGeometries(B),k.material=this.getLineBasicMaterial(A),_.add(k)}}_.matrix.makeTranslation(0,-h,0),f.add(_),y=1,C=1,w=256}else if(Array.isArray(O)){const S=this.getMTextGroup(O,i,s,n,r,a,o,l);S&&(f.add(S.object),a=S.hOffset,o=S.vOffset)}else typeof O=="object"&&(O.f&&(b=O.f,b&&b.includes(".shx")&&P.info("[Dxf] Doesn't support custom fonts: "+b)),O.C&&(w=O.C),O.W&&(O.W[1]==="x"?y=O.W[0]*i.width:y=O.W[0]),O.H&&(O.H[1]==="x"?h=O.H[0]*i.height:h=O.H[0]),O.T&&(C=O.T))}if(f.children.length!==0)return Mt.merge(f,!1),m&&(i.colorIndex=m),f.children.length===1?{object:f.children[0],hOffset:a,vOffset:o}:{object:f,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},n={};let r=1;const a=[];for(let o=0;o<e.length;o++){const l=e[o];if(typeof l=="string"){if(l.startsWith("\\pxq")&&l.endsWith(";"))l.indexOf("c")!==-1?s.horizontalAlignment="center":l.indexOf("l")!==-1?s.horizontalAlignment="left":l.indexOf("r")!==-1?s.horizontalAlignment="right":l.indexOf("j")!==-1&&(s.horizontalAlignment="justify");else if(!l.startsWith("pi")){if(!l.startsWith("pxt")){if(!l.startsWith("pt")){const h=this.getTextLineNum(l);a.push({font:n.f,colorIndex:n.C,text:l,lineNum:r}),r+=h}}}}else if(Array.isArray(l)){const h=this.mtextContentAndFormattingToTextAndStyle(l,i);h.text.forEach(d=>{a.push(d)}),r=h.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const h=l.S[0]+"/"+l.S[2],d=this.getTextLineNum(h);a.push({text:l.S[0]+"/"+l.S[2],lineNum:r}),r+=d}else l.C!==void 0?n.C=l.C:l.W!==void 0?n.W=l.W:l.H!==void 0?n.H=l.H:l.f!==void 0&&(n.f=l.f)}return{text:a,lineLength:r,style:s}}getTextLineNum(e){const i=e.match(new RegExp("\\n","g"));return i?i.length:0}load3DFace(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=e.vertices.map(o=>new p.Vector3(o.x,o.y,o.z));if(i.length===0)return;!z.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new p.Vector3;let n=!1;this.enableRTC&&(n=N.checkAndRebasePositionsOnRTC(i,s));const r=new p.BufferGeometry().setFromPoints(i),a=new V(G.Line);return a.geometry=r,a.material=me,n&&(this.setRTCUserData(a),a.matrix.setPosition(s.x,s.y,0)),a.layers.enableAll(),a}loadSpline(e,i){if(!e.controlPoints||!e.degreeOfSplineCurve||!e.knotValues)return;if(e.controlPoints.length<e.degreeOfSplineCurve+1)return P.warn("[Dxf] Spline entity (handle '%s') has degree (%s) >= point count (%s), ignored!",e.handle,e.degreeOfSplineCurve,e.controlPoints.length),void 0;let s=1/0,n=1/0,r=-1/0,a=-1/0;for(const w of e.controlPoints)w.x<s&&(s=w.x),w.y<n&&(n=w.y),w.x>r&&(r=w.x),w.y>a&&(a=w.y);let o=1;const l=i;l?.xScale&&l?.yScale&&(o=Math.max(Math.abs(l.xScale),Math.abs(l.yScale)));const h=Math.max(r-s,a-n),d=this.getBSplineInterpolationsPerSplineSegment(e.controlPoints.length,h*o),u=Wa(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,d),f=new p.Vector3;let m=!1;this.enableRTC&&(m=N.checkAndRebasePositionsOnRTC(u,f));const b=N.getAdjacentNonRepeatPoints(u);if(b.length<2)return P.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const y=new p.BufferGeometry().setFromPoints(b),C=new V(G.Line);return C.geometry=y,C.material=me,m&&(this.setRTCUserData(C),C.matrix.setPosition(f.x,f.y,0)),C.layers.enableAll(),C}loadXLine(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=j.arrayOrObjectToVector3(e.directionVector),s=new p.Vector3(e.vertices[0].x,e.vertices[0].y,0),n=[];if(n.push(i.clone().multiplyScalar(-1e6).add(s)),n.push(i.clone().multiplyScalar(1e6).add(s)),n.length===0)return;const r=new p.Vector3;let a=!1;this.enableRTC&&(a=N.checkAndRebasePositionsOnRTC(n,r));const o=new p.BufferGeometry().setFromPoints(n),l=new V(G.Line);return l.geometry=o,l.material=me,a&&(this.setRTCUserData(l),l.matrix.setPosition(r.x,r.y,0)),l.layers.enableAll(),l}loadRay(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=j.arrayOrObjectToVector3(e.directionVector),s=e.vertices.map(l=>new p.Vector3(l.x,l.y,0));if(s.push(i.multiplyScalar(1e6).add(s[0])),s.length===0)return;const n=new p.Vector3;let r=!1;this.enableRTC&&(r=N.checkAndRebasePositionsOnRTC(s,n));const a=new p.BufferGeometry().setFromPoints(s),o=new V(G.Line);return o.geometry=a,o.material=me,r&&(this.setRTCUserData(o),o.matrix.setPosition(n.x,n.y,0)),o.layers.enableAll(),o}loadLine(e,i){if(!e.vertices||e.vertices.length===0){P.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=_1(e.vertices);else{const h=Yn(e.vertices,e.shape);e.shape&&h.length>0&&h.push(h[0]),h.length>0&&(s=[h])}if(s.length===0)return;const n=[];for(let h=0;h<s.length;){const[d,u]=s[h];z.areVector3sEqual(d,u)&&s[h].length<=2?(n.push(d.clone()),s.splice(h,1)):h++}const r=new p.Vector3;let a=!1,o=0;s.forEach(h=>{h.forEach(d=>r.add(d)),o+=h.length}),o>0&&(r.divideScalar(o),a=this.enableRTC&&N.shouldRebasePositionOnRTC(r));let l=null;if(s.length>0){let h=function(w){return Array.isArray(w.pattern)&&w.pattern.length>0};const d=[],u=[];let f=0;s.forEach(w=>{w.forEach(x=>{a?d.push(new p.Vector3(x.x-r.x,x.y-r.y,x.z-r.z)):d.push(x.clone())});for(let x=1;x<w.length;x++)u.push(f+x-1,f+x);f+=w.length});const m=this.getLineType(e,i),b=i.tables?.lineType?.lineTypes?.[m],y=new p.BufferGeometry().setFromPoints(d);let C=me;if(b&&h(b)){let w=function(O){const S=O.attributes.position,v=S.count,T=new Float32Array(v);for(let _=0;_<v;_+=2){const A=_*3,I=(_+1)*3,B=S.array[I]-S.array[A],k=S.array[I+1]-S.array[A+1],L=S.array[I+2]-S.array[A+2],F=Math.sqrt(B*B+k*k+L*L);T[_]=_===0?0:T[_-1],T[_+1]=T[_]+F}O.setAttribute("lineDistance",new p.Float32BufferAttribute(T,1))};const x=b.pattern?.[0]||.5,E=b.pattern?.[1]||.5,M=.1;C=new p.LineDashedMaterial({color:me.color,linewidth:me.linewidth||1,dashSize:x*M,gapSize:E*M,scale:M}),w(y)}else y.setIndex(u);l=new V(G.LineSegment),l.geometry=y,l.material=C}if(n.length>0){a&&N.checkAndRebasePositionsOnRTC(n,r);const h=new p.BufferGeometry().setFromPoints(n),d=new V(G.Point);d.geometry=h,d.material=Gs,l?console.warn("Line has both segments and points – consider using a Group"):l=d}if(l)return a&&(this.setRTCUserData(l),l.matrix.setPosition(r.x,r.y,r.z)),l.layers.enableAll(),l}loadLWPolyline(e,i,s){if(!e.vertices||e.vertices.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const n=[...e.vertices];if(e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0){U.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const b=H.getOcsMatrix(U).invert(),y=e.elevation!==void 0?e.elevation:0;n.forEach(C=>{U.set(C.x,C.y,y).applyMatrix4(b),C.x=U.x,C.y=U.y})}let r=Yn(n,e.shape);if(e.shape&&r.length>0&&!z.areVector3sEqual(r[0],r[r.length-1])&&r.push(r[0]),r.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new V;const o=e.extendedData;if(o?.outlines){const b=o.outlines,y=[];b.forEach(x=>{const E=new p.Shape;x.forEach((M,O)=>{O===0?E.moveTo(M[0],M[1]):E.lineTo(M[0],M[1])}),E.closePath(),y.push(new p.ShapeGeometry(E))});const C=Pe.mergeGeometries(y),w=new V(G.Mesh);w.geometry=C,w.material=gi,w.layers.enableAll(),w.layers.disable(je),a.add(w)}let l=!1;const h=new p.Vector3;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(r,h));const d=N.getAdjacentNonRepeatPoints(r);if(d.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const u=e.constantWidth,f=d.length>2&&z.areVector3sEqual(d[0],d[d.length-1]);if(this.enablePlineWidth&&!f){const b=n.some(y=>y.startWidth!==void 0||y.endWidth!==void 0);if(b||u!==void 0&&u>0){let y;const C=i.tables?.lineType?.lineTypes,w=this.getLineType(e,i,s),x=C?.[w];if(!x||!x.pattern||x.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,b?y=this.createTaperedPolylineGeometry(n):y=N.convertWidthLineToMeshGeometry(d,u),!y)P.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const E=new V(G.Mesh);E.geometry=y,E.material=gi,E.layers.enableAll(),E.layers.disable(je),a.add(E);const M=J.createOutline(y,me,E.matrix),O=new V(G.LineSegment);O.geometry=M.geometry,O.material=M.material,O.matrix=M.matrix,O.layers.enableAll(),O.layers.disable(je),a.add(O)}}}const m=new V(G.Line);return m.geometry=new p.BufferGeometry().setFromPoints(d),m.material=me,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(h)),a}createTaperedPolylineGeometry(e){if(!e||e.length<2)return null;const i=[],s=[],n=[],r=[];for(let l=0;l<e.length-1;l++){const h=e[l],d=e[l+1],u=d.x-h.x,f=d.y-h.y,m=Math.hypot(u,f);if(m===0)continue;const b=-f/m,y=u/m,C=l===0?h.startWidth:h.endWidth,w=d.startWidth,x=C/2,E=w/2;h.x+b*x,h.y+y*x,h.x-b*x,h.y-y*x;const M={x:d.x+b*E,y:d.y+y*E},O={x:d.x-b*E,y:d.y-y*E};n.push(M),r.push(O)}const a=n.length;for(let l=0;l<a;l++)i.push(n[l].x,n[l].y,0),i.push(r[l].x,r[l].y,0);for(let l=0;l<a-1;l++){const h=l*2;s.push(h,h+1,h+2),s.push(h+1,h+3,h+2)}const o=new p.BufferGeometry;return o.setAttribute("position",new p.Float32BufferAttribute(i,3)),o.setIndex(s),o}loadMLeader(e,i,s){const n=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i),r=e.contextData?.defaultTextContents;if(!r)return;const a=new V,o=ls(r),l=this.getTextStyle(i,e),h=this.getMTextGroup(o,e,l,i,s),d=h&&h.object;if(d){d.matrix.decompose(K,ge,it),e.contextData?.textLocation&&(K.x+=e.contextData.textLocation.x,K.y+=e.contextData.textLocation.y,d.matrix.compose(K,ge,it)),ft.makeEmpty();const u=V.getBox(d,ft),f=u.getSize(U),m=f.x,b=f.y;let y=0,C=0;switch(e.contextData?.textAttachment){case 1:y=0,C=0;break;case 2:y-=m/2,C=0;break;case 3:y-=m,C=0;break;case 4:y=0,C+=b/2;break;case 5:y-=m/2,C+=b/2;break;case 6:y-=m,C+=b/2;break;case 7:y=0,C+=b;break;case 8:y-=m/2,C+=b;break;case 9:y-=m,C+=b;break;default:return}d.traverse(E=>{E.geometry&&E.geometry.translate(y,C,0)});let w=0;if(e.contextData?.textRotation&&(w=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const E=e.contextData.textDirection,M=new p.Vector3(E.x,E.y,E.z),O=M.clone().cross(qe),S=qe.angleTo(M);w+=O.z>0?-S:S}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(d),d.matrix.compose(K,ge,it),e.contextData?.textLocation?U.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):U.set(0,0,0);const x=K.clone().sub(U);tt.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),d.matrix.multiply(tt),d.matrix.multiply(de),d.matrix.multiply(tt.invert()),d.renderOrder=Oe.Text,a.add(d)}if(e.leaderLineType!==0){const u=[],f=e.contextData?.leaders[0];if(!f)return a;const m=f.lastLeaderLinePoint;if(e.enableDogLeg){const E=new p.Vector3(m.x,m.y,m.z),M=f.doglegLength,O=new p.Vector3(f.doglegVector.x,f.doglegVector.y,f.doglegVector.z),S=O.multiplyScalar(M),v=E.clone().add(S);u.push(v,E)}const b=e.contextData?.leaders[0].leaderLines||[];for(let E=0;E<b.length;E++){const M=b[E].vertices[0],O=M.reverse().map(B=>new p.Vector3(B.x,B.y,B.z));let S=new p.Vector3(m.x,m.y,m.z);for(let B=0;B<O.length;B++)u.push(S,O[B]),S=O[B];const v=U.subVectors(u[0],u[1]).length(),T=e.arrowHeadSize||n.DIMASZ||2.5,_=e.arrowHeadScale||n.DIMSCALE||1,A=T*_;e.leaderLineType;let I="";if(e.arrowHeadId?I=e.arrowHeadId:n&&n.DIMLDRBLK&&(I=n.DIMLDRBLK),I){const B=this.getBlockByHandle(i.blocks,I);if(B&&B.entities)for(let k=0;k<B.entities.length;k++){const L=this.loadEntity(B.entities[k],i,e);if(L){const F=new p.Vector3(u[u.length-1].x,u[u.length-1].y,u[u.length-1].z),ie=new p.Vector3(u[u.length-2].x,u[u.length-2].y,u[u.length-2].z),se=Math.atan2(F.y-ie.y,F.x-ie.x);U.copy(F),K.setScalar(A),ge.setFromAxisAngle(mi,se),L.matrix.compose(U,ge,K),a.add(L)}}}else this.loadDefaultLeadArrow(u[u.length-2],u[u.length-1],v/2e3,u)}const y=new p.Vector3;let C=!1;this.enableRTC&&(C=N.checkAndRebasePositionsOnRTC(u,y));const w=new p.BufferGeometry().setFromPoints(u),x=new V(G.LineSegment);x.geometry=w,x.material=me,x.renderOrder=Oe.Line,C&&(this.setRTCUserData(x),x.matrix.setPosition(y.x,y.y,0)),a.add(x)}else return d?.traverse(u=>{u.layers.enableAll()}),d;return Mt.merge(a,!1),a.traverse(u=>{u.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const n=[];if(!e.vertices)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return P.warn("leader's vertices number must be greater than 2"),void 0;const r=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i);let a=e.vertices;if(e.pathType===1&&(a=new p.SplineCurve(e.vertices).getPoints(50)),e.textWidth){const C=e.textWidth,w=new p.Vector3(a[a.length-1].x,a[a.length-1].y,a[a.length-1].z);if(e.direction===0){const x=new p.Vector3(1,0,0).multiplyScalar(C);a.push(x.add(w))}else{const x=new p.Vector3(-1,0,0).multiplyScalar(C);a.push(x.add(w))}}for(let C=0;C<a.length-1;C++){const w=a[C],x=a[C+1];n.push(w,x)}const o=U.subVectors(n[0],n[1]).setZ(0).length(),l=e.arrowHeight||r.DIMASZ||2.5,h=e.arrowHeadScale||r.DIMSCALE||1,d=l*h,u=new V;if(e.arrowFlag===1){let C="";e.arrowHeadBlockHandle?C=e.arrowHeadBlockHandle:r&&r.DIMLDRBLK&&(C=r.DIMLDRBLK);const w=this.getBlockByHandle(i.blocks,C);if(w&&w.entities){r&&(e.colorIndex=r.DIMCLRD||256,e.color=ki(e.colorIndex));for(let x=0;x<w.entities.length;x++){const E=this.loadEntity(w.entities[x],i,e);if(E){const M=new p.Vector3(n[0].x,n[0].y,n[0].z),O=new p.Vector3(n[1].x,n[1].y,n[1].z),S=Math.atan2(M.y-O.y,M.x-O.x);U.copy(M),K.setScalar(d),ge.setFromAxisAngle(mi,S),E.matrix.compose(U,ge,K),u.add(E)}}}else this.loadDefaultLeadArrow(n[1],n[0],d/o/2,n)}if(n.length===0)return;const f=new p.Vector3;let m=!1;this.enableRTC&&(m=N.checkAndRebasePositionsOnRTC(n,f));const b=new p.BufferGeometry().setFromPoints(n),y=new V(G.Line);return y.geometry=b,y.material=me,y.renderOrder=Oe.Line,m&&(this.setRTCUserData(y),y.matrix.setPosition(f.x,f.y,0)),u.children.length>0?(u.add(y),Mt.merge(u,!1),u.traverse(C=>{C.layers.enableAll()}),u.children.length===1?u.children[0]:u):(y.layers.enableAll(),y)}getTableTextOffset(e,i,s){const n=new p.Vector3;switch(e){case 1:break;case 2:n.setX(i/2);break;case 3:n.setX(i);break;case 4:n.setY(-s/2);break;case 5:n.set(i/2,-s/2,0);break;case 6:n.set(i,-s/2,0);break;case 7:n.setY(-s);break;case 8:n.set(i/2,-s,0);break;case 9:n.set(i,-s,0);break}return n}loadTable(e,i,s){if(!e.startPoint){P.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){P.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){P.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){P.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const n=new V,{cells:r,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:h}=e,d=[];let u=0;for(let y=0;y<a;y++){d[y]=[];for(let C=0;C<o;C++)d[y][C]=u<r.length?r[u++]:null}for(let y=0;y<a;y++)for(let C=0;C<o;C++){const w=d[y][C];if(!w||w.mergedValue!==0)continue;let x=1,E=1;for(;y+x<a&&d[y+x][C]&&d[y+x][C].mergedValue===1;)x++;for(;C+E<o&&d[y][C+E]&&d[y][C+E].mergedValue===1;)E++;w.rowSpan=x,w.colSpan=E}const f=[0];for(let y=0;y<a;y++)f.push(f[y]-l[y]);const m=[0];for(let y=0;y<o;y++)m.push(m[y]+h[y]);const b=[];for(let y=0;y<=a;y++){let C=m[0],w=!1;for(let x=0;x<o;x++){y>0&&d[y-1][x],y<a&&d[y][x];let E=!0;if(y===0||y===a)E=!0;else{const M=this._getMergeOwner(d,y-1,x,a,o),O=this._getMergeOwner(d,y,x,a,o);E=M!==O}E?w||(w=!0,C=m[x]):w&&(b.push(new p.Vector3(C,f[y],0),new p.Vector3(m[x],f[y],0)),w=!1)}w&&b.push(new p.Vector3(C,f[y],0),new p.Vector3(m[o],f[y],0))}for(let y=0;y<=o;y++){let C=f[0],w=!1;for(let x=0;x<a;x++){y>0&&d[x][y-1],y<o&&d[x][y];let E=!0;if(y===0||y===o)E=!0;else{const M=this._getMergeOwner(d,x,y-1,a,o),O=this._getMergeOwner(d,x,y,a,o);E=M!==O}E?w||(w=!0,C=f[x]):w&&(b.push(new p.Vector3(m[y],C,0),new p.Vector3(m[y],f[x],0)),w=!1)}w&&b.push(new p.Vector3(m[y],C,0),new p.Vector3(m[y],f[a],0))}if(b.length>0){const y=new p.BufferGeometry().setFromPoints(b),C=new V(G.LineSegment);C.geometry=y,C.material=me,C.layers.enableAll(),n.add(C)}for(let y=0;y<a;y++)for(let C=0;C<o;C++){const w=d[y][C];if(!w||w.mergedValue!==0)continue;const x=m[C],E=f[y];let M=0;for(let T=0;T<(w.colSpan||1);T++)M+=h[C+T];let O=0;for(let T=0;T<(w.rowSpan||1);T++)O+=l[y+T];w.colorIndex=e.colorIndex,w.height=w.textHeight||2.5;const S=this.getTableTextOffset(w.attachmentPoint||1,M,O);U.set(x,E,0),U.add(S),w.position=U.clone();const v=this.loadMText(w,i,s);v&&n.add(v)}if(e.blockRecordHandle){const y=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(y&&y.entities)for(const C of y.entities){C.isTable=!0;const w=this.loadEntity(C,i,e);w&&n.add(w)}}return n.matrix.decompose(U,ge,it),U.x+=e.startPoint.x,U.y+=e.startPoint.y,n.matrix.compose(U,ge,it),n}_getMergeOwner(e,i,s,n,r){let a=i,o=s;for(;a>=0&&e[a][o]&&e[a][o].mergedValue===1;){if(a>0&&e[a-1][o]&&e[a-1][o].mergedValue!==1){a--;break}if(o>0&&e[a][o-1]&&e[a][o-1].mergedValue!==1){o--;break}if(a>0)a--;else if(o>0)o--;else break}return e[a]?.[o]||null}loadDefaultLeadArrow(e,i,s,n){const r=s*(e.x-i.x),a=s*(e.y-i.y),o=a,l=-r,h=new p.Vector3(i.x+r+o/6,i.y+a+l/6,0),d=new p.Vector3(i.x+r-o/6,i.y+a-l/6,0);n.push(i,h),n.push(i,d),n.push(h,d)}getBlockByHandle(e,i){if(!this.blocksCache){this.blocksCache={};for(const s in e){const n=e[s];!this.blocksCache[n.ownerHandle]&&(this.blocksCache[n.ownerHandle]=n)}}return this.blocksCache[i]}static updateMaterialUniforms(e){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=H.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=H.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=U.set(Math.cos(i)*1,Math.sin(i)*1,0),n=s.applyMatrix4(e);return Math.atan2(n.y,n.x)}static getArcAnglesByOcsMatrix(e,i,s){let n=z.getArcAngleSpanInRadian(i,s);const r=H.transformAngleByOcsMatrix(e,i),a=H.transformAngleByOcsMatrix(e,s);let o;if(z.areNumbersClose(n,Math.PI)){n=1;const l=H.transformAngleByOcsMatrix(e,i+n);o=z.getArcAngleSpanInRadian(r,l)}else{if(z.areNumbersClose(n,Math.PI*2))return[r,r+Math.PI*2];o=z.getArcAngleSpanInRadian(r,a)}return z.areNumbersClose(n,o,1e-5)?[r,a]:[a,r]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return P.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return P.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is too small, ignored!"),void 0;const n=new p.Vector3(0,0,1);e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0&&n.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const r=H.getOcsMatrix(n);let a,o;if(e.type==="CIRCLE")a=e.startAngle||0,o=a+2*Math.PI;else{if(e.startAngle==null||e.endAngle==null||(a=e.startAngle,o=e.endAngle,z.areNumbersEqual(a,o,1e-6)))return;if(!z.areNumbersClose(z.getArcAngleSpanInRadian(a,o),Math.PI*2)){const O=H.getArcAnglesByOcsMatrix(r,a,o);a=O[0],o=O[1]}}const l=new p.ArcCurve(0,0,e.radius,a,o,this.angBase!==0);let h=1;const d=s;d?.xScale&&d?.yScale&&(h=Math.max(Math.abs(d.xScale),Math.abs(d.yScale)));const u=this.getDivision(a,o,e.radius*h),f=l.getPoints(u),m=new p.Vector3;let b=!1;this.enableRTC&&(b=N.checkAndRebasePositionsOnRTC(f,m));const y=new p.BufferGeometry().setFromPoints(f),C=new V(G.Line);C.geometry=y,C.material=me;const w=new p.Vector3;e.center&&(w.x=e.center.x,w.y=e.center.y);const x=new p.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(r.invert());w.x=x.x,w.y=x.y;const E=w,M=new V(G.Point);return M.geometry=Va,M.material=Gs,M.userData.handle=e.handle,M.userData.isSnapObject=!0,M.userData.type="CircleCenter",M.layers.set(je),C.add(M),b?(this.setRTCUserData(C),E.x+=m.x,E.y+=m.y):N.shouldRebasePositionOnRTC(E)&&this.setRTCUserData(C),C.matrix.setPosition(E),C.layers.enableAll(),C}addTriangleFacingCamera(e,i,s,n){const r=new p.Vector3,a=new p.Vector3;r.subVectors(s,i),a.subVectors(n,i),r.cross(a);const o=new p.Vector3(i.x,i.y,i.z),l=new p.Vector3(s.x,s.y,s.z),h=new p.Vector3(n.x,n.y,n.z);r.z<0?e.push(h,l,o):e.push(o,l,h)}loadSolid(e,i,s){const n=e.points;if(!n||n.length<4)return;if(e.extrusionDirection&&e.extrusionDirection.z){U.set(0,0,e.extrusionDirection.z);const u=H.getOcsMatrix(U).invert();n.forEach(f=>{const m=U.set(f.x,f.y,0).applyMatrix4(u);f.x=m.x,f.y=m.y})}const r=[],a=[];this.addTriangleFacingCamera(r,n[0],n[1],n[2]),a.push(0,1,2),this.addTriangleFacingCamera(r,n[1],n[2],n[3]),a.push(3,4,5);const o=new p.Vector3;let l=!1;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(r,o));const h=new p.BufferGeometry().setFromPoints(r);h.setIndex(a);const d=new V(G.Mesh);return d.geometry=h,d.material=gi,l&&(this.setRTCUserData(d),d.matrix.setPosition(o.x,o.y,0)),d.layers.enableAll(),d}getTextStyle(e,i){const s=e.tables?.style?.styles;return s?s[i.textStyle]||s.STANDARD||s.Standard||{}:{}}getDefaultDimensionStyle(e){return e.tables.dimStyle.dimStyles.STANDARD||e.tables.dimStyle.dimStyles.Standard||{}}getTextEncoding(e){return e?.bigFontFile&&e.bigFontFile.toUpperCase().startsWith("GB")?"gbk":"utf8"}getTextMesh(e,i,s,n){if(!e)return;const r=s?.styleName||"";if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const h=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[h]&&(this.statsInfo.unsupportedTextStyles[h]=0),this.statsInfo.unsupportedTextStyles[h]++}let a=.8;const o={_TCH_DIM:1.45,ROMANS:1};r&&o[r]&&(a=o[r]),n.xScale&&(a*=n.xScale),a>1&&r&&(a*=s?.xScale||1,i=i||s?.textHeight||0),i===0&&(r?i=1:i=.2);const l=this.createTextMeshByText(e,s,i,0,i/12,a);return l.traverse(h=>{h.geometry&&h.geometry.scale(a,1,1)}),l}createTextMeshByText(e,i,s=12,n=0,r=0,a=1,o=1/0,l=0){const h=new V,d=[];let u=0,f=0;i?.xScale;const m=n+s,b=i?.fontFile||"",y=typeof b=="string"&&b.toLowerCase().endsWith(".shx"),C=y?s*.06:s*.04,w=[];for(let M=0;M<e.length;M++){const O=e[M];O!==" "&&O!==`
793
+ `&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Ge(c,t,e){return c.code===t&&c.value===e}function vt(c){P.trace("unhandled group "+Go(c))}function Go(c){return c.code+":"+c.value}const qo="0.4.0",Wo="VERSION",w1=()=>window.localStorage.getItem(Wo),v1=()=>{window.localStorage.setItem(Wo,qo)},M1=()=>w1()!==qo?(v1(),!0):!1,si=class si{constructor(){g(this,"DATABASE_NAME","x_viewer");g(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);g(this,"db");g(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!si._instance&&(si._instance=new si),si._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),M1()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,P.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,P.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,P.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{P.debug("onversionchange",e)},this.db=t,Promise.resolve(this.db)}closeDatabase(){this.db&&this.db.close()}deleteDataBase(t){return new Promise((e,i)=>{const s=window.indexedDB.deleteDatabase(t);s.onerror=n=>{P.debug(n),i(n)},s.onsuccess=n=>{const r=n.target;P.debug("[DB] Db "+t+" delete old version "+n.oldVersion+"."),e(r)}})}async getDB(t){return new Promise((e,i)=>{const s=window.indexedDB.open(t);s.onerror=i,s.onsuccess=n=>{const r=n.target.result;P.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async getUpgradedDB(t){return new Promise((e,i)=>{P.debug("[DB] Upgrading db "+t.name+" (version "+t.version+")");const s=window.indexedDB.open(t.name,t.version+1);s.onerror=i,s.onblocked=n=>{P.debug("onblocked",n)},s.onupgradeneeded=n=>{const r=n.target.transaction;r.oncomplete=()=>{P.debug("[DB] Upgrade is done (new version: "+a.version+").")};const a=n.target.result,o=[];for(let l=0;l<this.tables.length;++l){const h=this.tables[l];if(!a.objectStoreNames.contains(h.name)){P.debug("[DB] Creating table "+h.name+"...");const d=this.createTable(a,h.name,h.options,h.indexArray);o.push(d)}}o.length>0&&Promise.all(o).then(()=>{P.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=n=>{const r=n.target.result;P.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async createTable(t,e,i,s){return new Promise(n=>{const r=t.createObjectStore(e,i);s&&s.forEach(a=>{r.createIndex(a.name,a.fields,{unique:a.unique})}),P.debug("[DB] Table "+e+" created."),n(t)})}};g(si,"_instance");let ue=si;class Yo{constructor(){g(this,"db");g(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,ue.instance().getTables().findIndex(i=>i.name===this.tableName())===-1)throw new Error("Failed to find table '"+this.tableName()+"' from indexeddb!")}tableName(){throw new Error("Derived class have to override 'tableName', and set a proper table name!")}add(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()}).catch(n=>{i&&i(n)})}save(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();ue.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ue.instance().closeDatabase()})}update(){ue.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readonly").objectStore(i),r=n.openCursor();r.onsuccess=a=>{const o=a.target.result;o&&o.continue(),t&&t(o)},r.onerror=e}).finally(()=>{ue.instance().closeDatabase()})}queryByIndex(t,e,i,s){const n=this.tableName();ue.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.index(t).get(e);o.onerror=s,o.onsuccess=function(l){const h=l.target?.result;i&&i(h)}}).finally(()=>{ue.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readonly").objectStore(i),r=n.getAll();r.onsuccess=a=>{t&&t(a.target.result)},r.onerror=e}).finally(()=>{ue.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();ue.instance().getDatabase().then(s=>{const n=s.transaction([i],"readwrite").objectStore(i),r=n.clear();r.onsuccess=a=>{t&&t(a)},r.onerror=a=>{e&&e(a)}}).finally(()=>{ue.instance().closeDatabase()})}}const ni=class ni extends Yo{tableName(){return"dxf_data"}static instance(){return!ni._instance&&(ni._instance=new ni),ni._instance}query(t,e,i){const s=[],n=this.tableName();ue.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.get(t);o.onerror=l=>{i&&i(l),P.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{ue.instance().closeDatabase()})}};g(ni,"_instance");let pn=ni;const qe=new p.Vector3(1,0,0),Wn=new p.Vector3(0,1,0),mi=new p.Vector3(0,0,1),Fa=new p.Vector3(0,0,0),Rt=16777215,T1="CONTINUOUS",Gs=new p.PointsMaterial({color:Rt}),me=new p.LineBasicMaterial({color:Rt}),gi=new p.MeshBasicMaterial({color:Rt}),za=new p.BufferGeometry().setFromPoints([new p.Vector3]),Va=new p.Matrix4,tt=new p.Matrix4,de=new p.Matrix4,U=new p.Vector3,K=new p.Vector3,it=new p.Vector3,Ji=new p.Vector2,ge=new p.Quaternion,qs=new p.Object3D,ft=new p.Box3,ja=new p.PointsMaterial({color:65280,size:5,depthTest:!1}),Ua=new p.PointsMaterial({color:65280,depthTest:!1}),Ha=new p.PointsMaterial({color:65280,depthTest:!1}),C1=c=>c.viewDirectionFromTarget!==void 0,S1=c=>{if(c){const t=c.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);if(t&&t.length>0){const e=t[1],i=c.replace("data:"+e+";","").split(",");if(i&&i.length===2&&i[0]==="base64"){const s=i[1];return dc.decode(s)}}}return null},Na=(c,t)=>{const e=new p.Vector2(c.x,c.y),i=new p.Vector2(t.x,t.y);return i.sub(e),i.normalize(),i.y<0?-Math.acos(i.x):Math.acos(i.x)},Ga=(c,t,e)=>({x:c.x+t*Math.cos(e),y:c.y+t*Math.sin(e)}),E1=(c,t,e,i)=>{const s=c?new p.Vector2(c.x,c.y):new p.Vector2(0,0),n=t?new p.Vector2(t.x,t.y):new p.Vector2(1,0);e=e||1;const r=4*Math.atan(e),a=s.distanceTo(n)/2/Math.sin(r/2),o=Ga(c,a,Na(s,n)+(Math.PI/2-r/2));i=i||Math.max(Math.abs(Math.ceil(r/(Math.PI/18))),6);const l=Na(o,s),h=r/i,d=[];d.push(new p.Vector3(s.x,s.y,0));for(let u=1;u<=i-1;u++){const f=Ga(o,Math.abs(a),l+h*u);d.push(new p.Vector3(f.x,f.y,0))}return d},qa=(c,t,e,i=c.length*2,s)=>{const n=[];if(!c||c.length<t+1||t<1)return n;const r=c.map(a=>[a.x,a.y]);try{for(let a=0;a<1;a+=1/i){const o=Lo(a,t,r,e,s);n.push(new p.Vector3(o[0],o[1],0))}}catch{if(n.length===0)return n}return n},Yn=(c,t=!1)=>{const e=[],i=c.length;for(let s=0;s<i;s++){const n=c[s];if(n.bulge&&(s!==i-1||t)){const r=n.bulge,a=s+1<i?c[s+1]:e[0],o=E1(n,a,r);e.push(...o)}else e.push(new p.Vector3(n.x,n.y,0))}return e},O1=c=>{const t=[];return c.faceA&&t.push(c.faceA),c.faceB&&t.push(c.faceB),c.faceC&&t.push(c.faceC),c.faceD&&t.push(c.faceD),t},_1=c=>{const t=[],e=[];c.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new p.Vector3(s.x,s.y,s.z)):e.push(O1(s)))});const i=[];for(let s=0;s<e.length;s++){const n=e[s];if(n.length===0)continue;const r=[];let a=!0;for(let o=0;o<n.length;o++){const l=n[o]-1;if(l>=t.length||l<0){a=!1;break}r.push(t[l])}!a||r.length===0||(r.push(r[0]),i.push(r))}return i},H=class H extends p.Loader{constructor(e,i){super(e);g(this,"timer");g(this,"ignorePaperSpace");g(this,"font");g(this,"encoding");g(this,"overrideColor");g(this,"overrideHatchPatternLineThickness");g(this,"angBase");g(this,"angDir");g(this,"header");g(this,"pointsMaterials");g(this,"lineBasicMaterials");g(this,"lineShaderMaterials");g(this,"meshBasicMaterials");g(this,"meshTextureMaterials");g(this,"hatchShaderMaterials");g(this,"entityCount");g(this,"curveCount");g(this,"averageCurveSize");g(this,"enableRenderOrder");g(this,"enableLocalCache");g(this,"enableReleaseData");g(this,"enableMerge");g(this,"enableRTC");g(this,"enablePlineWidth");g(this,"dxfDataId");g(this,"compareContext");g(this,"statsInfo");g(this,"llbDatas");g(this,"mtextDatas");g(this,"requestHeader");g(this,"blockReferencesCache");g(this,"blockRecordsCache");g(this,"entitiesCache");g(this,"blocksCache");g(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");g(this,"spatialFiltersCache");g(this,"entityThreejsCache");g(this,"entityTypesAndTimes");g(this,"nonSnapableTypes");g(this,"layoutsSnapObjectsMap");g(this,"aborted");g(this,"entityHandlesWithRenderOrder");g(this,"addViewport");this.timer=Date.now(),this.ignorePaperSpace=!1,this.encoding="UTF-8",this.angBase=0,this.angDir=0,this.header=void 0,this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[],this.entityCount=0,this.curveCount=0,this.averageCurveSize=0,this.enableRenderOrder=!1,this.enableLocalCache=!1,this.enableReleaseData=!0,this.enableMerge=!0,this.enableRTC=!0,this.enablePlineWidth=!0,this.dxfDataId=void 0,this.compareContext=void 0,this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0,requestHeader:{}},this.llbDatas=[],this.mtextDatas=[],this.blockReferencesCache={},this.blockRecordsCache=void 0,this.entitiesCache=void 0,this.blocksCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.nonSnapableTypes=new Set(["ATTDEF","ATTRIB","LEADER","MTEXT","MULTILEADER","OLE2FRAME","TEXT"]),this.layoutsSnapObjectsMap={},this.aborted=!1,this.entityHandlesWithRenderOrder={},this.addViewport=(s,n)=>{if(s.type==="VIEWPORT"){!n[s.ownerHandle]&&(n[s.ownerHandle]=[]);const r=s;n[s.ownerHandle].push(r)}},i&&(this.ignorePaperSpace=i.ignorePaperSpace===!0,this.enableLocalCache=i.enableLocalCache===!0,this.enableMerge=H.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.requestHeaders&&(this.requestHeader=i.requestHeaders),i.overrideColor!=null&&(this.overrideColor=Li.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[Rt]=Gs,this.lineBasicMaterials[Rt]=me,this.meshBasicMaterials[Rt]=gi}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=S1(e);if(!s){const n=Date.now(),r=new p.FileLoader(this.manager);this.requestHeader&&Object.keys(this.requestHeader).length>0&&r.setRequestHeader(this.requestHeader),r.setResponseType("arraybuffer"),r.setPath(this.path),s=await r.loadAsync(e,i),P.info("[Dxf] "+e+" dxf file downloaded in "+(Date.now()-n)/1e3+"s")}return s}async loadEx(e,i,s){return this.enableLocalCache&&i&&(i=i.trim()).length>0&&(this.dxfDataId=i),this.loadAsync(e,s)}async loadAsync(e,i){const s=j.getUpdateSubProgressFunc(0,50,i),n=j.getUpdateSubProgressFunc(50,100,i),r=j.getUpdateSubProgressFunc(10,100,i);if(Be.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),P.info("[Dxf] Loaded DxfData from indexedDb in "+(Date.now()-this.timer)/1e3+"s");const h=await this.loadEntities(l,r);return Promise.resolve(h)}}catch(h){P.warn("[Dxf] Failed to parse data from indexedDb",h)}}const a=await this.parse(e,s);return this.tryFixDxfData(a),await this.loadEntities(a,n)}async parse(e,i){const s=j.getUpdateProgressFunc(i),n=j.getUpdateSubProgressFunc(0,40,i),r=await this.download(e,n);if(!r)return Promise.reject("[Dxf] Failed to download "+e);if(this.aborted)return Promise.reject("[Dxf] Job aborted");this.timer=Date.now(),P.info("[Dxf] Start parsing...");const a=new No(this.encoding).parseSync(r);if(this.tryFixDxfData(a),s(80),P.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&Be.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),P.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){P.warn("[Dxf] Failed to save '"+this.dxfDataId+"' to indexedDb!",l)}}return s(100),a}abort(){this.aborted=!0}isAborted(){return this.aborted}parseHeader(e){if(!e){P.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&P.warn("[Dxf] Unexpected version: "+i+". But we'll try to continue."),this.angBase=e.$ANGBASE||0,this.angDir=e.$ANGDIR||0}tryFixDxfData(e){e&&(!e.objects&&(P.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(P.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:H.MODEL_LAYOUT_NAME}]),!e.tables&&(P.warn("[Dxf] No tables found, Will add one."),e.tables={}),!e.tables.layer&&(e.tables.layer={}),!e.tables.layer.layers&&(e.tables.layer.layers={}))}async loadEntities(e,i){const s=Date.now();this.parseHeader(e.header),this.enableRenderOrder&&(this.initRenderOrderInfo(e),this.enableMerge=!1),this.getFontFilesFromDxf(e);let n=0;const r=e.entities.length;this.entityCount=r,Object.keys(e.blocks).forEach(x=>{this.entityCount+=e.blocks[x].entities?.length||0});const a=j.getUpdateProgressFuncForLoop(r,i);let o={};const l=x=>{const E=x.userData.layerName;let M=o[E];!M&&(M=[],o[E]=M),M.push(x)},h={},d={},u=new V;for(let x=0;x<r&&!this.aborted;x++){const E=e.entities[x];this.addViewport(E,h);const M=this.loadEntity(E,e);if(!M&&await a(x),!M)continue;const O=this.getLayout(e,E),S=O.layoutName;let v=u.children.find(T=>T.name===S);if(!v&&(v=new V,v.name=S,v.userData.isLayoutLevelObject=!0,u.add(v)),M.traverse(T=>{T.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[S]&&(this.layoutsSnapObjectsMap[S]=[]),this.layoutsSnapObjectsMap[S].push(T))}),this.enableMerge){Tt.merge(M,!1),!d[S]&&(d[S]={object:v,layerObjects:{}});const _=d[S];if(M.geometry){const A=M.userData.layerName;!_.layerObjects[A]&&(_.layerObjects[A]=[]),_.layerObjects[A].push(M),M.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else M.children.length>0&&(v.add(M),M.traverse(A=>{A.geometry&&l(A)}))}else v.add(M),M.traverse(T=>{T.geometry&&l(T)});n++,await a(x)}e.objects.LAYOUT.forEach(x=>{const E=x,M=E.layoutName;if(this.ignorePaperSpace&&M!==H.MODEL_LAYOUT_NAME)return;const O=E.associatedBlockName,S=e.blocks[O];S&&this.loadLayout(S,e,E,u,o,h)}),P.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const x in this.layoutsSnapObjectsMap){const E=u.children.find(S=>S.name===x),M=new V;M.name=H.SNAP_GROUP_NAME,M.userData.isSnapGroup=!0,E.add(M);const O=this.layoutsSnapObjectsMap[x];for(let S=0;S<O.length;S++){const v=O[S],T=v.userData.layerName;this.getLayerVisible(e,T)===!1&&v.layers.disable(je),H.SHOW_SNAP_OBJECT&&(v.layers.enableAll(),v.material instanceof p.PointsMaterial?v.material=ja:v.material instanceof p.LineBasicMaterial?v.material=Ua:v.material instanceof p.MeshBasicMaterial&&(v.material=Ha));let _=v;const A=de.identity();for(;_&&_.userData.isLayoutLevelObject!==!0;)A.premultiply(_.matrix),_=_.parent;v.matrix.copy(A),M.add(v)}}if(this.enableMerge)for(const x in d){const E=d[x],M=E.object;for(const O in E.layerObjects){const S=E.layerObjects[O],v=Tt.deepMerge(S,void 0,!1,!1,!0),T=v.added,_=v.removed;if(_.length!==S.length){let A=_;_.length>=100&&(A=new Set(_));const I=B=>Array.isArray(A)?A.indexOf(B)>=0:A.has(B);for(let B=0,k=S.length;B<k;B++){const L=S[B];!I(L)&&(M.add(L),l(L))}}for(let A=0;A<T.length;A++){const I=T[A];M.add(I),l(I)}E.layerObjects[O]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&H.mergeDxfObjects({root:u,layersAndObjects:o});const m=u.convertToThreejsObject();u.clear(),o={};const b={};e.objects.LAYOUT.forEach(x=>{const E=x;b[E.layoutName]=E});const y={},C=x=>{const E=x.userData.layerName;let M=y[E];!M&&(M=[],y[E]=M),M.push(x)};m.children.forEach(x=>{if(J.setSharedVariablesOfObject(x),!x.userData.isLayoutLevelObject)return;const E=x.name;let M;if(E!==H.MODEL_LAYOUT_NAME){const O=b[E];!O.directAssociatedLeafObjectSet&&(O.directAssociatedLeafObjectSet=new Set),M=O.directAssociatedLeafObjectSet}x.traverse(O=>{if(J.setSharedVariablesOfObject(O),O.userData.isSnapGroup&&(O.visible=H.SHOW_SNAP_OBJECT),O.geometry){const S=O.userData.layerName;this.getLayerVisible(e,S)===!1&&(O.visible=!1,O.userData.layerVisible=!1),C(O),M&&M.add(O)}})}),P.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const w=Object.assign(Object.assign({},e),{threejsObject:m,layersAndThreejsObjects:y,loadedEntityCount:n,layoutViewportsMap:h});if(H.LOADLLDATA){const x=m.children[0].children,E=[];for(let M=0;M<x.length;M++){const O=x[M];if(O?.userData?.llbData){const S=new p.Box3().setFromObject(O);S.getSize(new p.Vector3);const v=S.getCenter(new p.Vector3);E.push({...O,boundingBox:{max:S.max,min:S.min,center:v}})}else if(O.children&&O.children.some(S=>S.userData?.llbData))for(let S=0;S<O.children.length;S++){const v=O.children[S];if(v.userData?.llbData){v.updateWorldMatrix(!0,!0);const T=new p.Box3().setFromObject(v);T.getSize(new p.Vector3);const _=T.getCenter(new p.Vector3);E.push({...v,boundingBox:{max:T.max,min:T.min,center:_}})}}}w.llbMesh=E}return Promise.resolve(w)}getFontFilesFromDxf(e){const i=new Set,s=e.tables?.style?.styles;if(s)for(const n in s){const r=s[n],a=r.fontFile,o=r.bigFontFile;a&&i.add(a),o&&i.add(o)}P.info("[Dxf] Fonts used by dxf: "+Array.from(i).join())}async loadEntitiesForCompare(e,i,s,n=!0,r){const a=e.entities.length,o=i.entities.length,l=async()=>{const d=this.compareContext,u=d.isTheFirstFile,f=u?e:i,m=new V,b=u?a:o;this.entityCount=b,Object.keys(f.blocks).forEach(v=>{this.entityCount+=f.blocks[v].entities?.length||0});const y=Math.round(Math.pow(b,.5));let C=Date.now();const w=async v=>{if(r&&(v%y===0||v===b-1)){let T=v+1;!u&&(T+=a),r(new ProgressEvent("parseProgress",{loaded:T,total:a+o}));const _=500,A=Date.now();(A-C>_||v===b-1)&&(await j.sleep(0),C=A)}};this.parseHeader(f.header);let x={};for(let v=0;v<b;v++){if(this.aborted)return;const T=f.entities[v],_=this.getLayout(f,T);if(_.layoutName!==H.MODEL_LAYOUT_NAME){await w(v);continue}const A=this.loadEntity(T,f);if(!A){await w(v);continue}let I=m.children.find(B=>B.name===H.MODEL_LAYOUT_NAME);!I&&(I=new V,I.name=H.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,m.add(I)),I.add(A),A.traverse(B=>{if(B.geometry){const k=B.userData.layerName,L=this.getLayerVisible(f,k);B.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[_.layoutName]&&(this.layoutsSnapObjectsMap[_.layoutName]=[]),this.layoutsSnapObjectsMap[_.layoutName].push(B),L===!1&&A.layers.disable(je));let F=x[k];!F&&(F=[],x[k]=F),F.push(B)}}),await w(v)}n&&u&&!d.preservedHandles&&(d.preservedHandles=new Set);for(const v in s){const T=s[v];u&&(T.type===Ve.Added||T.type===Ve.Modified)&&(d.preservedHandles?.add(T.handle),T.parentHandles&&T.parentHandles.forEach(A=>d.preservedHandles?.add(A)));let _=this.entityThreejsCache&&this.entityThreejsCache[T.handle];if(T.parentHandles&&(_=this.entityThreejsCache&&this.entityThreejsCache[T.parentHandles[T.parentHandles.length-1]]),_){if(_.parent&&_.parent.userData.originalType){this.setObjectColorByChange(_,{type:Ve.NoChange});continue}_=this.setObjectColorByChange(_,T)}if(T.type!==Ve.NoChange&&_){let A=_.parent;const I=de.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;ft.makeEmpty();const B=V.getBox(_,ft);B.applyMatrix4(I),T.type===Ve.Added?!u&&(T.box=new p.Box3().copy(B)):T.type===Ve.Removed?u&&(T.box=new p.Box3().copy(B)):T.type===Ve.Modified&&(T.box?T.box.union(B):T.box=new p.Box3().copy(B))}}for(const v in this.layoutsSnapObjectsMap){const T=m.children.find(I=>I.name===v),_=new V;_.name=H.SNAP_GROUP_NAME,T.add(_);const A=this.layoutsSnapObjectsMap[v];for(let I=0;I<A.length;I++){const B=A[I];H.SHOW_SNAP_OBJECT&&(B.layers.enableAll(),B.material instanceof p.PointsMaterial?B.material=ja:B.material instanceof p.LineBasicMaterial?B.material=Ua:B.material instanceof p.MeshBasicMaterial&&(B.material=Ha));let k=B;const L=de.identity();for(;k&&k.userData.isLayoutLevelObject!==!0;)L.premultiply(k.matrix),k=k.parent;B.matrix.copy(L),_.add(B)}}this.enableMerge&&H.mergeDxfObjects({root:m,layersAndObjects:x});const E=m.convertToThreejsObject();m.clear(),x={};const M={},O=v=>{const T=v.userData.layerName;let _=M[T];!_&&(_=[],M[T]=_),_.push(v)};E.children.forEach(v=>{J.setSharedVariablesOfObject(v),v.userData.isLayoutLevelObject&&v.traverse(T=>{if(J.setSharedVariablesOfObject(T),T.userData.isSnapGroup&&(T.visible=H.SHOW_SNAP_OBJECT),T.geometry){const _=T.userData.layerName;this.getLayerVisible(f,_)===!1&&(T.visible=!1,T.userData.layerVisible=!1),O(T)}})});const S=f;S.threejsObject=E,S.layersAndThreejsObjects=M,S.layoutViewportsMap={}};let h=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},j.printMemory("Before loading entities for first dxf"),await l(),P.info("[Dxf] loadEntities for first dxf in "+(Date.now()-h)/1e3+"s"),j.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),j.printMemory("Before loading entities for second dxf"),h=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),P.info("[Dxf] loadEntities for second dxf in "+(Date.now()-h)/1e3+"s"),this.printStatsInfo();for(const d of Object.values(s))!d.box&&delete s[d.id];this.compareContext.preservedHandles=void 0,this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(i)),j.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=at.ENTITY_COLOR_NO_CHANGE;return a.type===Ve.Added?o=at.ENTITY_COLOR_ADDED:a.type===Ve.Removed?o=at.ENTITY_COLOR_REMOVED:a.type===Ve.Modified&&(o=this.compareContext?.isTheFirstFile?at.ENTITY_COLOR_REMOVED:at.ENTITY_COLOR_ADDED),o},n=(a,o)=>{a.traverse(l=>{if(l.material){if(l.material instanceof p.LineBasicMaterial)l.material=this.getLineBasicMaterial(o);else if(l.material instanceof p.MeshBasicMaterial)l.material=this.getMeshBasicMaterial(o);else if(l.material instanceof p.PointsMaterial)l.material=this.getPointsMaterial(o);else if(l.material instanceof p.ShaderMaterial){const h=l.material.clone();H.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o),l.material=h}}})},r=s(i);return e.traverse(a=>{i.parentHandles?a.userData&&a.userData.handle&&a.userData.handle===i.handle&&(n(a,r),e=a):n(a,r)}),e}releaseCachedData(e=!0){e&&(this.pointsMaterials={},this.lineBasicMaterials={},this.lineShaderMaterials={},this.meshBasicMaterials={},this.meshTextureMaterials={},this.hatchShaderMaterials=[]),this.header=void 0,this.blockReferencesCache={},this.blockRecordsCache=void 0,this.blocksCache=void 0,this.entitiesCache=void 0,this.dictionaryOwnerHandleAndSpatialFilterHandlesCache=void 0,this.spatialFiltersCache=void 0,this.entityThreejsCache=void 0,this.entityTypesAndTimes=void 0,this.entityHandlesWithRenderOrder={},this.layoutsSnapObjectsMap={},this.statsInfo={unsupportedEntity:{},unsupportedEntityTypes:{},unsupportedTextStyles:{},unsupportedHatchPatterns:{},unsupportedPolylineCount:0,invisibleEntities:{},ignoredFrozenLayersAndEntityCount:{},ignoredInserts:{},entityTypesAndMeshCount:{},ignoredPaperSpaceEntityTypesAndCount:{},rebasedEntityCount:0}}releaseEntity(e){e.vertices&&(e.vertices=void 0),e.knotValues&&(e.knotValues=void 0),e.controlPoints&&(e.controlPoints=void 0),e.binaryData&&(e.binaryData=void 0),e.text&&(e.text=void 0),e.extendedData&&(e.extendedData=void 0),e.contextData&&(e.contextData=void 0);const i=e;i.boundaryPaths&&(i.boundaryPaths=[]),i.patternLines&&(i.patternLines=void 0)}releaseDxfData(e){delete e.objects.DICTIONARY,delete e.objects.SORTENTSTABLE,delete e.objects.XRECORD,e.tables&&(delete e.tables.dimStyle,delete e.tables.lineType,delete e.tables.style,delete e.tables.blockRecord),e.entities=[],e.blocks={}}loadEntity(e,i,s,n=!1){if(this.compareContext&&this.compareContext.preservedHandles&&this.compareContext.preservedHandles.has(e.handle)&&os.includes(e.type)&&(n=!0),!n&&this.compareContext&&this.compareContext.preservedHandles&&!os.includes(e.type)&&!this.compareContext.preservedHandles.has(e.handle)&&(!s||s&&!this.compareContext.preservedHandles.has(s.handle)))return;if(this.getLayerFrozen(i,e)===!0){const f=e.layer;return!this.statsInfo.ignoredFrozenLayersAndEntityCount[f]&&(this.statsInfo.ignoredFrozenLayersAndEntityCount[f]=0),this.statsInfo.ignoredFrozenLayersAndEntityCount[f]++,void 0}if(e.visible===!1||e.invisible)return!this.statsInfo.invisibleEntities[e.type]&&(this.statsInfo.invisibleEntities[e.type]=0),this.statsInfo.invisibleEntities[e.type]++,void 0;if(this.ignorePaperSpace&&e.inPaperSpace)return!this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]&&(this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]=0),this.statsInfo.ignoredPaperSpaceEntityTypesAndCount[e.type]++,void 0;!this.entityThreejsCache&&(this.entityThreejsCache={});const a=Date.now();let o,l=!1;if(!this.compareContext&&this.entityThreejsCache[e.handle])o=this.entityThreejsCache[e.handle].clone(),l=!0;else if(!this.statsInfo.unsupportedEntity[e.handle]){const f=e.isTable;if(e.type==="CIRCLE"||e.type==="ARC")o=this.loadArc(e,i,s);else if(e.type==="LINE"||e.type==="POLYLINE")o=this.loadLine(e,i);else if(e.type==="XLINE")o=this.loadXLine(e);else if(e.type!=="SEQEND"){if(e.type==="RAY")o=this.loadRay(e);else if(e.type==="LWPOLYLINE")o=this.loadLWPolyline(e,i,s);else if(e.type==="3DFACE")o=this.load3DFace(e);else if(e.type==="TEXT")o=this.loadText(e,i,s);else if(e.type==="SOLID")o=this.loadSolid(e,i,s);else if(e.type==="POINT")o=this.loadPoint(e,i,s);else if(e.type==="IMAGE")o=this.loadImage(e,i,s);else if(e.type==="INSERT")o=this.loadInsert(e,i,s,n);else if(e.type==="SPLINE")o=this.loadSpline(e,s);else if(e.type==="MTEXT")f?o=this.loadTableMText(e,i,s):o=this.loadMText(e,i,s);else if(e.type==="ELLIPSE")o=this.loadEllipse(e,i,s);else if(e.type==="DIMENSION")o=this.loadDimension(e,i);else if(e.type!=="REGION")if(e.type==="ATTDEF")o=this.loadAttDef(e,i,s);else if(e.type==="ATTRIB"){if(!s)for(let m=0;m<i.entities.length;m++){const b=i.entities[m];if(e.ownerHandle===b.handle&&(s=b,s.attributesFollow))break}o=this.loadAttrib(e,i,s)}else e.type==="HATCH"?o=this.loadHatch(e,i,s):e.type==="VIEWPORT"?o=this.loadViewport(e,i,s):e.type==="LEADER"?o=this.loadLeader(e,i,s):e.type==="MULTILEADER"?o=this.loadMLeader(e,i,s):e.type==="OLE2FRAME"?o=this.loadOle2frame(e,i):e.type==="ACAD_TABLE"&&(o=this.loadTable(e,i))}o&&(this.entityThreejsCache[e.handle]=o),this.enableReleaseData&&!this.compareContext&&this.releaseEntity(e)}if(o){const f=this.getLayerName(e,i,s);o.userData.handle=e.handle,e.type!=="INSERT"&&e.type!=="DIMENSION"&&o.traverse(m=>{m.geometry&&(m.userData.layerName=f,m.userData.handle=e.handle,m.userData.dxfType=e.type,this.setMaterial(m,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(m=>{m.layers.disable(je)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16)))}const h=e.type,d=e.handle,u=os.includes(h);if(!u){this.entityTypesAndTimes||(this.entityTypesAndTimes={}),this.entityTypesAndTimes[h]||(this.entityTypesAndTimes[h]={createCount:0,totalTime:0,averageTime:0});const f=this.entityTypesAndTimes[h];f.createCount++,f.totalTime+=Date.now()-a}return o?this.statsInfo.entityTypesAndMeshCount[h]?this.statsInfo.entityTypesAndMeshCount[h]++:this.statsInfo.entityTypesAndMeshCount[h]=1:(this.statsInfo.unsupportedEntityTypes[h]?this.statsInfo.unsupportedEntityTypes[h]++:this.statsInfo.unsupportedEntityTypes[h]=1,u||(this.statsInfo.unsupportedEntity[d]?this.statsInfo.unsupportedEntity[d]++:this.statsInfo.unsupportedEntity[d]=1)),o}loadEllipse(e,i,s){if(!e.majorAxisEndPoint||!e.center||e.axisRatio===void 0||e.startAngle===void 0||e.endAngle===void 0)return;let n=e.startAngle,r=e.endAngle;if(e.extrusionDirection&&e.extrusionDirection.z<0&&(n=Math.PI*2-e.endAngle,r=Math.PI*2-e.startAngle),z.areNumbersEqual(n,r,1e-5))return P.warn("[Dxf] Ellipse entity (handle '%s') contains the same start and end angle, ignored!",e.handle),void 0;let a=r-n;for(;a>Math.PI*2;)a-=Math.PI*2;Math.abs(a)<=1e-5&&(r=z.floorNumber(n+Math.PI*2,5));const o=Math.sqrt(Math.pow(e.majorAxisEndPoint.x,2)+Math.pow(e.majorAxisEndPoint.y,2)),l=o*e.axisRatio,h=Math.atan2(e.majorAxisEndPoint.y,e.majorAxisEndPoint.x),d=new p.EllipseCurve(e.center.x,e.center.y,o,l,n,r,!1,h);let u=1;const f=s;f?.xScale&&f?.yScale&&(u=Math.max(Math.abs(f.xScale),Math.abs(f.yScale)));const m=this.getDivision(n,r,Math.max(o,l)*u),b=d.getPoints(m),y=[],C=b.length;for(let S=0;S<C-1;S++)z.areVector2sEqual(b[S],b[S+1],1e-9)||y.push(b[S]);if(y.push(b[C-1]),y.length<2)return P.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const w=new p.Vector3;let x=!1;this.enableRTC&&(x=N.checkAndRebasePositionsOnRTC(y,w));const E=new p.BufferGeometry().setFromPoints(y),M=new V(G.Line);M.geometry=E,M.material=me;const O=new V(G.Point);return O.geometry=za,O.material=Gs,O.matrix.setPosition(e.center.x,e.center.y,e.center.z),O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(je),M.add(O),x&&(this.setRTCUserData(M),M.matrix.setPosition(w.x,w.y,0)),M.layers.enableAll(),M}loadMText(e,i,s){if(!e.text)return;if(!this.font)return P.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ls(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(K,ge,it),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,it)),ft.makeEmpty();const l=V.getBox(o,ft),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u,m=e.text;let b=0,y=0;switch(document.createElement("canvas").getContext("2d"),e.attachmentPoint){case 1:b=0,y=0;break;case 2:b-=d/2,y=0;break;case 3:b-=d,y=0;break;case 4:b=0,y+=f/2;break;case 5:b-=d/2,y+=f/2;break;case 6:b-=d,y+=f/2;break;case 7:b=0,y+=f;break;case 8:b-=d/2,y+=f;break;case 9:b-=d,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=u;break;case 4:break;case 5:const I=m.split("\\P");let B=0;I>1&&(B=I-1),B>1?y+=u*(B-1):y-=u/4;break;default:return}o.traverse(I=>{I.geometry&&I.geometry.translate(b,y,0),I.layers.enableAll()});let w=0;if(e.rotation&&(w=e.rotation*Math.PI/180),e.directionVector){const I=e.directionVector,B=new p.Vector3(I.x,I.y,I.z),k=B.clone().cross(qe),L=qe.angleTo(B);w=k.z>0?-L:L}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,it);const x=e.position?K.clone().sub(e.position):K;tt.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),o.matrix.multiply(tt),o.matrix.multiply(de),o.matrix.multiply(tt.invert()),o.userData||(o.userData={});const E=o.matrix.elements,M=E&&E[12]||0,O=E&&E[13]||0,S=E&&E[14]||0,v=new p.Box3;V.getBox(o,v);const T=new p.Vector3;v.getCenter(T);const _=new p.Vector3;v.getSize(_),o.userData.renderArea={position:{x:M,y:O,z:S},bbox:{min:{x:v.min.x,y:v.min.y,z:v.min.z},max:{x:v.max.x,y:v.max.y,z:v.max.z},center:{x:T.x,y:T.y,z:T.z},width:_.x,height:_.y,depth:_.z},textSize:{width:d,height:u},rotation:w,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const A=this;return o.userData.textContent=e.text||"",o.userData.cleanText=A.cleanMTextContent?A.cleanMTextContent(e.text):e.text,o.userData.dxfType="MTEXT",o.userData.isMText=!0,o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",o.traverse(I=>{I.geometry&&(I.userData.textContent=e.text||"",I.userData.dxfType="MTEXT",I.userData.layer=e.layer||"0",I.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return P.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ls(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(K,ge,it),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,it)),ft.makeEmpty();const l=V.getBox(o,ft),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,b=0;switch(e.attachmentPoint){case 1:m=0,b=0;break;case 2:m-=d/2,b=0;break;case 3:m-=d,b=0;break;case 4:m=0,b+=f/2;break;case 5:m-=d/2,b+=f/2;break;case 6:m-=d,b+=f/2;break;case 7:m=0,b+=f;break;case 8:m-=d/2,b+=f;break;case 9:m-=d,b+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:b+=u;break;case 4:break;case 5:break;default:return}o.traverse(w=>{w.geometry&&w.geometry.translate(m,b,0),w.layers.enableAll()});let y=0;if(e.rotation&&(y=e.rotation*Math.PI/180),e.directionVector){const w=e.directionVector,x=new p.Vector3(w.x,w.y,w.z),E=x.clone().cross(qe),M=qe.angleTo(x);y=E.z>0?-M:M}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,it);const C=e.position?K.clone().sub(e.position):K;return tt.makeTranslation(-C.x,-C.y,0),de.makeRotationZ(y),o.matrix.multiply(tt),o.matrix.multiply(de),o.matrix.multiply(tt.invert()),o}getMTextGroup(e,i,s,n,r,a=0,o=0,l=[]){if(e.length===0)return;let h=i.height||i.contextData&&i.contextData.textHeight||0;if(i.textStyle){if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const M=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[M]&&(this.statsInfo.unsupportedTextStyles[M]=0),this.statsInfo.unsupportedTextStyles[M]++}h=h||s.textHeight}let d="Left";i.width&&i.attachmentPoint&&([1,4,7].includes(i.attachmentPoint)?d="Left":[2,5,8].includes(i.attachmentPoint)?d="Center":[3,6,9].includes(i.attachmentPoint)&&(d="Right"));const u=i.width||0,f=new V;let m,b=s.fontFile,y=1,C=1,w=256,x=h*.8,E=x+h;for(let M=0;M<e.length;M++){const O=e[M];if(typeof O=="string"){const S=[],v=A=>{let I;if(A.forEach((B,k)=>{!B.boundingBox&&B.computeBoundingBox(),k===0?I=B.boundingBox:I.union(B.boundingBox)}),I){const B=I.getSize(U);switch(d){case"Left":break;case"Center":A.forEach(k=>k.translate((u-B.x)/2,0,0));break;case"Right":A.forEach(k=>k.translate(u-B.x,0,0));break}}S.push(...A)};let T;for(let A=0;A<O.length;A++){const I=O[A];if(I===`
794
+ `){a=0,o-=E,l.length>0&&v(l),l=[];continue}if(x=h*.8,E=x+h,T=this.font?.getCharShape(I,b,h),s.bigFontFile&&!T&&(T=this.font?.getCharShape(I,s.bigFontFile,h)),!T&&(T=this.font?.getCharShape(I,"",h)),!T&&(T=this.font?.getNotFoundTextShape(h)),!T){a+=h+C*(h/3.5);continue}a>(u||1/0)&&(l.length>0&&v(l),a=0,o-=E,l=[]),T.translate(a,o,0),T.scale(y,1,1),T.boundingBox||T.computeBoundingBox(),O.T&&(C=O.T);const B=cd(I,T,h,C,b);a+=B,l.push(T)}l.length>0&&(v(l),l=[]);const _=new V;if(S.length>0){!m&&(m=i.colorIndex),w!==void 0&&w!==256?(i.color=ki(w),i.colorIndex=w):i.colorIndex=m;const A=this.getColor(i,n,r),I=S.filter(k=>k instanceof p.ExtrudeGeometry),B=S.filter(k=>!(k instanceof p.ExtrudeGeometry));if(I.length>0){const k=new V(G.Mesh);k.geometry=Pe.mergeGeometries(I),k.material=this.getMeshBasicMaterial(A),_.add(k)}if(B.length>0){const k=new V(G.LineSegment);k.geometry=Pe.mergeGeometries(B),k.material=this.getLineBasicMaterial(A),_.add(k)}}_.matrix.makeTranslation(0,-h,0),f.add(_),y=1,C=1,w=256}else if(Array.isArray(O)){const S=this.getMTextGroup(O,i,s,n,r,a,o,l);S&&(f.add(S.object),a=S.hOffset,o=S.vOffset)}else typeof O=="object"&&(O.f&&(b=O.f,b&&b.includes(".shx")&&P.info("[Dxf] Doesn't support custom fonts: "+b)),O.C&&(w=O.C),O.W&&(O.W[1]==="x"?y=O.W[0]*i.width:y=O.W[0]),O.H&&(O.H[1]==="x"?h=O.H[0]*i.height:h=O.H[0]),O.T&&(C=O.T))}if(f.children.length!==0)return Tt.merge(f,!1),m&&(i.colorIndex=m),f.children.length===1?{object:f.children[0],hOffset:a,vOffset:o}:{object:f,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},n={};let r=1;const a=[];for(let o=0;o<e.length;o++){const l=e[o];if(typeof l=="string"){if(l.startsWith("\\pxq")&&l.endsWith(";"))l.indexOf("c")!==-1?s.horizontalAlignment="center":l.indexOf("l")!==-1?s.horizontalAlignment="left":l.indexOf("r")!==-1?s.horizontalAlignment="right":l.indexOf("j")!==-1&&(s.horizontalAlignment="justify");else if(!l.startsWith("pi")){if(!l.startsWith("pxt")){if(!l.startsWith("pt")){const h=this.getTextLineNum(l);a.push({font:n.f,colorIndex:n.C,text:l,lineNum:r}),r+=h}}}}else if(Array.isArray(l)){const h=this.mtextContentAndFormattingToTextAndStyle(l,i);h.text.forEach(d=>{a.push(d)}),r=h.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const h=l.S[0]+"/"+l.S[2],d=this.getTextLineNum(h);a.push({text:l.S[0]+"/"+l.S[2],lineNum:r}),r+=d}else l.C!==void 0?n.C=l.C:l.W!==void 0?n.W=l.W:l.H!==void 0?n.H=l.H:l.f!==void 0&&(n.f=l.f)}return{text:a,lineLength:r,style:s}}getTextLineNum(e){const i=e.match(new RegExp("\\n","g"));return i?i.length:0}load3DFace(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=e.vertices.map(o=>new p.Vector3(o.x,o.y,o.z));if(i.length===0)return;!z.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new p.Vector3;let n=!1;this.enableRTC&&(n=N.checkAndRebasePositionsOnRTC(i,s));const r=new p.BufferGeometry().setFromPoints(i),a=new V(G.Line);return a.geometry=r,a.material=me,n&&(this.setRTCUserData(a),a.matrix.setPosition(s.x,s.y,0)),a.layers.enableAll(),a}loadSpline(e,i){if(!e.controlPoints||!e.degreeOfSplineCurve||!e.knotValues)return;if(e.controlPoints.length<e.degreeOfSplineCurve+1)return P.warn("[Dxf] Spline entity (handle '%s') has degree (%s) >= point count (%s), ignored!",e.handle,e.degreeOfSplineCurve,e.controlPoints.length),void 0;let s=1/0,n=1/0,r=-1/0,a=-1/0;for(const w of e.controlPoints)w.x<s&&(s=w.x),w.y<n&&(n=w.y),w.x>r&&(r=w.x),w.y>a&&(a=w.y);let o=1;const l=i;l?.xScale&&l?.yScale&&(o=Math.max(Math.abs(l.xScale),Math.abs(l.yScale)));const h=Math.max(r-s,a-n),d=this.getBSplineInterpolationsPerSplineSegment(e.controlPoints.length,h*o),u=qa(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,d),f=new p.Vector3;let m=!1;this.enableRTC&&(m=N.checkAndRebasePositionsOnRTC(u,f));const b=N.getAdjacentNonRepeatPoints(u);if(b.length<2)return P.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const y=new p.BufferGeometry().setFromPoints(b),C=new V(G.Line);return C.geometry=y,C.material=me,m&&(this.setRTCUserData(C),C.matrix.setPosition(f.x,f.y,0)),C.layers.enableAll(),C}loadXLine(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=j.arrayOrObjectToVector3(e.directionVector),s=new p.Vector3(e.vertices[0].x,e.vertices[0].y,0),n=[];if(n.push(i.clone().multiplyScalar(-1e6).add(s)),n.push(i.clone().multiplyScalar(1e6).add(s)),n.length===0)return;const r=new p.Vector3;let a=!1;this.enableRTC&&(a=N.checkAndRebasePositionsOnRTC(n,r));const o=new p.BufferGeometry().setFromPoints(n),l=new V(G.Line);return l.geometry=o,l.material=me,a&&(this.setRTCUserData(l),l.matrix.setPosition(r.x,r.y,0)),l.layers.enableAll(),l}loadRay(e){if(!e.vertices||e.vertices.length===0)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=j.arrayOrObjectToVector3(e.directionVector),s=e.vertices.map(l=>new p.Vector3(l.x,l.y,0));if(s.push(i.multiplyScalar(1e6).add(s[0])),s.length===0)return;const n=new p.Vector3;let r=!1;this.enableRTC&&(r=N.checkAndRebasePositionsOnRTC(s,n));const a=new p.BufferGeometry().setFromPoints(s),o=new V(G.Line);return o.geometry=a,o.material=me,r&&(this.setRTCUserData(o),o.matrix.setPosition(n.x,n.y,0)),o.layers.enableAll(),o}loadLine(e,i){if(!e.vertices||e.vertices.length===0){P.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=_1(e.vertices);else{const h=Yn(e.vertices,e.shape);e.shape&&h.length>0&&h.push(h[0]),h.length>0&&(s=[h])}if(s.length===0)return;const n=[];for(let h=0;h<s.length;){const[d,u]=s[h];z.areVector3sEqual(d,u)&&s[h].length<=2?(n.push(d.clone()),s.splice(h,1)):h++}const r=new p.Vector3;let a=!1,o=0;s.forEach(h=>{h.forEach(d=>r.add(d)),o+=h.length}),o>0&&(r.divideScalar(o),a=this.enableRTC&&N.shouldRebasePositionOnRTC(r));let l=null;if(s.length>0){let h=function(w){return Array.isArray(w.pattern)&&w.pattern.length>0};const d=[],u=[];let f=0;s.forEach(w=>{w.forEach(x=>{a?d.push(new p.Vector3(x.x-r.x,x.y-r.y,x.z-r.z)):d.push(x.clone())});for(let x=1;x<w.length;x++)u.push(f+x-1,f+x);f+=w.length});const m=this.getLineType(e,i),b=i.tables?.lineType?.lineTypes?.[m],y=new p.BufferGeometry().setFromPoints(d);let C=me;if(b&&h(b)){let w=function(O){const S=O.attributes.position,v=S.count,T=new Float32Array(v);for(let _=0;_<v;_+=2){const A=_*3,I=(_+1)*3,B=S.array[I]-S.array[A],k=S.array[I+1]-S.array[A+1],L=S.array[I+2]-S.array[A+2],F=Math.sqrt(B*B+k*k+L*L);T[_]=_===0?0:T[_-1],T[_+1]=T[_]+F}O.setAttribute("lineDistance",new p.Float32BufferAttribute(T,1))};const x=b.pattern?.[0]||.5,E=b.pattern?.[1]||.5,M=.1;C=new p.LineDashedMaterial({color:me.color,linewidth:me.linewidth||1,dashSize:x*M,gapSize:E*M,scale:M}),w(y)}else y.setIndex(u);l=new V(G.LineSegment),l.geometry=y,l.material=C}if(n.length>0){a&&N.checkAndRebasePositionsOnRTC(n,r);const h=new p.BufferGeometry().setFromPoints(n),d=new V(G.Point);d.geometry=h,d.material=Gs,l?console.warn("Line has both segments and points – consider using a Group"):l=d}if(l)return a&&(this.setRTCUserData(l),l.matrix.setPosition(r.x,r.y,r.z)),l.layers.enableAll(),l}loadLWPolyline(e,i,s){if(!e.vertices||e.vertices.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const n=[...e.vertices];if(e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0){U.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const b=H.getOcsMatrix(U).invert(),y=e.elevation!==void 0?e.elevation:0;n.forEach(C=>{U.set(C.x,C.y,y).applyMatrix4(b),C.x=U.x,C.y=U.y})}let r=Yn(n,e.shape);if(e.shape&&r.length>0&&!z.areVector3sEqual(r[0],r[r.length-1])&&r.push(r[0]),r.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new V;const o=e.extendedData;if(o?.outlines){const b=o.outlines,y=[];b.forEach(x=>{const E=new p.Shape;x.forEach((M,O)=>{O===0?E.moveTo(M[0],M[1]):E.lineTo(M[0],M[1])}),E.closePath(),y.push(new p.ShapeGeometry(E))});const C=Pe.mergeGeometries(y),w=new V(G.Mesh);w.geometry=C,w.material=gi,w.layers.enableAll(),w.layers.disable(je),a.add(w)}let l=!1;const h=new p.Vector3;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(r,h));const d=N.getAdjacentNonRepeatPoints(r);if(d.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const u=e.constantWidth,f=d.length>2&&z.areVector3sEqual(d[0],d[d.length-1]);if(this.enablePlineWidth&&!f){const b=n.some(y=>y.startWidth!==void 0||y.endWidth!==void 0);if(b||u!==void 0&&u>0){let y;const C=i.tables?.lineType?.lineTypes,w=this.getLineType(e,i,s),x=C?.[w];if(!x||!x.pattern||x.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,b?y=this.createTaperedPolylineGeometry(n):y=N.convertWidthLineToMeshGeometry(d,u),!y)P.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const E=new V(G.Mesh);E.geometry=y,E.material=gi,E.layers.enableAll(),E.layers.disable(je),a.add(E);const M=J.createOutline(y,me,E.matrix),O=new V(G.LineSegment);O.geometry=M.geometry,O.material=M.material,O.matrix=M.matrix,O.layers.enableAll(),O.layers.disable(je),a.add(O)}}}const m=new V(G.Line);return m.geometry=new p.BufferGeometry().setFromPoints(d),m.material=me,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(h)),a}createTaperedPolylineGeometry(e){if(!e||e.length<2)return null;const i=[],s=[],n=[],r=[];for(let l=0;l<e.length-1;l++){const h=e[l],d=e[l+1],u=d.x-h.x,f=d.y-h.y,m=Math.hypot(u,f);if(m===0)continue;const b=-f/m,y=u/m,C=l===0?h.startWidth:h.endWidth,w=d.startWidth,x=C/2,E=w/2;h.x+b*x,h.y+y*x,h.x-b*x,h.y-y*x;const M={x:d.x+b*E,y:d.y+y*E},O={x:d.x-b*E,y:d.y-y*E};n.push(M),r.push(O)}const a=n.length;for(let l=0;l<a;l++)i.push(n[l].x,n[l].y,0),i.push(r[l].x,r[l].y,0);for(let l=0;l<a-1;l++){const h=l*2;s.push(h,h+1,h+2),s.push(h+1,h+3,h+2)}const o=new p.BufferGeometry;return o.setAttribute("position",new p.Float32BufferAttribute(i,3)),o.setIndex(s),o}loadMLeader(e,i,s){const n=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i),r=e.contextData?.defaultTextContents;if(!r)return;const a=new V,o=ls(r),l=this.getTextStyle(i,e),h=this.getMTextGroup(o,e,l,i,s),d=h&&h.object;if(d){d.matrix.decompose(K,ge,it),e.contextData?.textLocation&&(K.x+=e.contextData.textLocation.x,K.y+=e.contextData.textLocation.y,d.matrix.compose(K,ge,it)),ft.makeEmpty();const u=V.getBox(d,ft),f=u.getSize(U),m=f.x,b=f.y;let y=0,C=0;switch(e.contextData?.textAttachment){case 1:y=0,C=0;break;case 2:y-=m/2,C=0;break;case 3:y-=m,C=0;break;case 4:y=0,C+=b/2;break;case 5:y-=m/2,C+=b/2;break;case 6:y-=m,C+=b/2;break;case 7:y=0,C+=b;break;case 8:y-=m/2,C+=b;break;case 9:y-=m,C+=b;break;default:return}d.traverse(E=>{E.geometry&&E.geometry.translate(y,C,0)});let w=0;if(e.contextData?.textRotation&&(w=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const E=e.contextData.textDirection,M=new p.Vector3(E.x,E.y,E.z),O=M.clone().cross(qe),S=qe.angleTo(M);w+=O.z>0?-S:S}N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(d),d.matrix.compose(K,ge,it),e.contextData?.textLocation?U.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):U.set(0,0,0);const x=K.clone().sub(U);tt.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),d.matrix.multiply(tt),d.matrix.multiply(de),d.matrix.multiply(tt.invert()),d.renderOrder=Oe.Text,a.add(d)}if(e.leaderLineType!==0){const u=[],f=e.contextData?.leaders[0];if(!f)return a;const m=f.lastLeaderLinePoint;if(e.enableDogLeg){const E=new p.Vector3(m.x,m.y,m.z),M=f.doglegLength,O=new p.Vector3(f.doglegVector.x,f.doglegVector.y,f.doglegVector.z),S=O.multiplyScalar(M),v=E.clone().add(S);u.push(v,E)}const b=e.contextData?.leaders[0].leaderLines||[];for(let E=0;E<b.length;E++){const M=b[E].vertices[0],O=M.reverse().map(B=>new p.Vector3(B.x,B.y,B.z));let S=new p.Vector3(m.x,m.y,m.z);for(let B=0;B<O.length;B++)u.push(S,O[B]),S=O[B];const v=U.subVectors(u[0],u[1]).length(),T=e.arrowHeadSize||n.DIMASZ||2.5,_=e.arrowHeadScale||n.DIMSCALE||1,A=T*_;e.leaderLineType;let I="";if(e.arrowHeadId?I=e.arrowHeadId:n&&n.DIMLDRBLK&&(I=n.DIMLDRBLK),I){const B=this.getBlockByHandle(i.blocks,I);if(B&&B.entities)for(let k=0;k<B.entities.length;k++){const L=this.loadEntity(B.entities[k],i,e);if(L){const F=new p.Vector3(u[u.length-1].x,u[u.length-1].y,u[u.length-1].z),ie=new p.Vector3(u[u.length-2].x,u[u.length-2].y,u[u.length-2].z),se=Math.atan2(F.y-ie.y,F.x-ie.x);U.copy(F),K.setScalar(A),ge.setFromAxisAngle(mi,se),L.matrix.compose(U,ge,K),a.add(L)}}}else this.loadDefaultLeadArrow(u[u.length-2],u[u.length-1],v/2e3,u)}const y=new p.Vector3;let C=!1;this.enableRTC&&(C=N.checkAndRebasePositionsOnRTC(u,y));const w=new p.BufferGeometry().setFromPoints(u),x=new V(G.LineSegment);x.geometry=w,x.material=me,x.renderOrder=Oe.Line,C&&(this.setRTCUserData(x),x.matrix.setPosition(y.x,y.y,0)),a.add(x)}else return d?.traverse(u=>{u.layers.enableAll()}),d;return Tt.merge(a,!1),a.traverse(u=>{u.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const n=[];if(!e.vertices)return P.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return P.warn("leader's vertices number must be greater than 2"),void 0;const r=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i);let a=e.vertices;if(e.pathType===1&&(a=new p.SplineCurve(e.vertices).getPoints(50)),e.textWidth){const C=e.textWidth,w=new p.Vector3(a[a.length-1].x,a[a.length-1].y,a[a.length-1].z);if(e.direction===0){const x=new p.Vector3(1,0,0).multiplyScalar(C);a.push(x.add(w))}else{const x=new p.Vector3(-1,0,0).multiplyScalar(C);a.push(x.add(w))}}for(let C=0;C<a.length-1;C++){const w=a[C],x=a[C+1];n.push(w,x)}const o=U.subVectors(n[0],n[1]).setZ(0).length(),l=e.arrowHeight||r.DIMASZ||2.5,h=e.arrowHeadScale||r.DIMSCALE||1,d=l*h,u=new V;if(e.arrowFlag===1){let C="";e.arrowHeadBlockHandle?C=e.arrowHeadBlockHandle:r&&r.DIMLDRBLK&&(C=r.DIMLDRBLK);const w=this.getBlockByHandle(i.blocks,C);if(w&&w.entities){r&&(e.colorIndex=r.DIMCLRD||256,e.color=ki(e.colorIndex));for(let x=0;x<w.entities.length;x++){const E=this.loadEntity(w.entities[x],i,e);if(E){const M=new p.Vector3(n[0].x,n[0].y,n[0].z),O=new p.Vector3(n[1].x,n[1].y,n[1].z),S=Math.atan2(M.y-O.y,M.x-O.x);U.copy(M),K.setScalar(d),ge.setFromAxisAngle(mi,S),E.matrix.compose(U,ge,K),u.add(E)}}}else this.loadDefaultLeadArrow(n[1],n[0],d/o/2,n)}if(n.length===0)return;const f=new p.Vector3;let m=!1;this.enableRTC&&(m=N.checkAndRebasePositionsOnRTC(n,f));const b=new p.BufferGeometry().setFromPoints(n),y=new V(G.Line);return y.geometry=b,y.material=me,y.renderOrder=Oe.Line,m&&(this.setRTCUserData(y),y.matrix.setPosition(f.x,f.y,0)),u.children.length>0?(u.add(y),Tt.merge(u,!1),u.traverse(C=>{C.layers.enableAll()}),u.children.length===1?u.children[0]:u):(y.layers.enableAll(),y)}getTableTextOffset(e,i,s){const n=new p.Vector3;switch(e){case 1:break;case 2:n.setX(i/2);break;case 3:n.setX(i);break;case 4:n.setY(-s/2);break;case 5:n.set(i/2,-s/2,0);break;case 6:n.set(i,-s/2,0);break;case 7:n.setY(-s);break;case 8:n.set(i/2,-s,0);break;case 9:n.set(i,-s,0);break}return n}loadTable(e,i,s){if(!e.startPoint){P.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){P.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){P.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){P.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const n=new V,{cells:r,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:h}=e,d=[];let u=0;for(let y=0;y<a;y++){d[y]=[];for(let C=0;C<o;C++)d[y][C]=u<r.length?r[u++]:null}for(let y=0;y<a;y++)for(let C=0;C<o;C++){const w=d[y][C];if(!w||w.mergedValue!==0)continue;let x=1,E=1;for(;y+x<a&&d[y+x][C]&&d[y+x][C].mergedValue===1;)x++;for(;C+E<o&&d[y][C+E]&&d[y][C+E].mergedValue===1;)E++;w.rowSpan=x,w.colSpan=E}const f=[0];for(let y=0;y<a;y++)f.push(f[y]-l[y]);const m=[0];for(let y=0;y<o;y++)m.push(m[y]+h[y]);const b=[];for(let y=0;y<=a;y++){let C=m[0],w=!1;for(let x=0;x<o;x++){y>0&&d[y-1][x],y<a&&d[y][x];let E=!0;if(y===0||y===a)E=!0;else{const M=this._getMergeOwner(d,y-1,x,a,o),O=this._getMergeOwner(d,y,x,a,o);E=M!==O}E?w||(w=!0,C=m[x]):w&&(b.push(new p.Vector3(C,f[y],0),new p.Vector3(m[x],f[y],0)),w=!1)}w&&b.push(new p.Vector3(C,f[y],0),new p.Vector3(m[o],f[y],0))}for(let y=0;y<=o;y++){let C=f[0],w=!1;for(let x=0;x<a;x++){y>0&&d[x][y-1],y<o&&d[x][y];let E=!0;if(y===0||y===o)E=!0;else{const M=this._getMergeOwner(d,x,y-1,a,o),O=this._getMergeOwner(d,x,y,a,o);E=M!==O}E?w||(w=!0,C=f[x]):w&&(b.push(new p.Vector3(m[y],C,0),new p.Vector3(m[y],f[x],0)),w=!1)}w&&b.push(new p.Vector3(m[y],C,0),new p.Vector3(m[y],f[a],0))}if(b.length>0){const y=new p.BufferGeometry().setFromPoints(b),C=new V(G.LineSegment);C.geometry=y,C.material=me,C.layers.enableAll(),n.add(C)}for(let y=0;y<a;y++)for(let C=0;C<o;C++){const w=d[y][C];if(!w||w.mergedValue!==0)continue;const x=m[C],E=f[y];let M=0;for(let T=0;T<(w.colSpan||1);T++)M+=h[C+T];let O=0;for(let T=0;T<(w.rowSpan||1);T++)O+=l[y+T];w.colorIndex=e.colorIndex,w.height=w.textHeight||2.5;const S=this.getTableTextOffset(w.attachmentPoint||1,M,O);U.set(x,E,0),U.add(S),w.position=U.clone();const v=this.loadMText(w,i,s);v&&n.add(v)}if(e.blockRecordHandle){const y=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(y&&y.entities)for(const C of y.entities){C.isTable=!0;const w=this.loadEntity(C,i,e);w&&n.add(w)}}return n.matrix.decompose(U,ge,it),U.x+=e.startPoint.x,U.y+=e.startPoint.y,n.matrix.compose(U,ge,it),n}_getMergeOwner(e,i,s,n,r){let a=i,o=s;for(;a>=0&&e[a][o]&&e[a][o].mergedValue===1;){if(a>0&&e[a-1][o]&&e[a-1][o].mergedValue!==1){a--;break}if(o>0&&e[a][o-1]&&e[a][o-1].mergedValue!==1){o--;break}if(a>0)a--;else if(o>0)o--;else break}return e[a]?.[o]||null}loadDefaultLeadArrow(e,i,s,n){const r=s*(e.x-i.x),a=s*(e.y-i.y),o=a,l=-r,h=new p.Vector3(i.x+r+o/6,i.y+a+l/6,0),d=new p.Vector3(i.x+r-o/6,i.y+a-l/6,0);n.push(i,h),n.push(i,d),n.push(h,d)}getBlockByHandle(e,i){if(!this.blocksCache){this.blocksCache={};for(const s in e){const n=e[s];!this.blocksCache[n.ownerHandle]&&(this.blocksCache[n.ownerHandle]=n)}}return this.blocksCache[i]}static updateMaterialUniforms(e){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=H.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=H.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=U.set(Math.cos(i)*1,Math.sin(i)*1,0),n=s.applyMatrix4(e);return Math.atan2(n.y,n.x)}static getArcAnglesByOcsMatrix(e,i,s){let n=z.getArcAngleSpanInRadian(i,s);const r=H.transformAngleByOcsMatrix(e,i),a=H.transformAngleByOcsMatrix(e,s);let o;if(z.areNumbersClose(n,Math.PI)){n=1;const l=H.transformAngleByOcsMatrix(e,i+n);o=z.getArcAngleSpanInRadian(r,l)}else{if(z.areNumbersClose(n,Math.PI*2))return[r,r+Math.PI*2];o=z.getArcAngleSpanInRadian(r,a)}return z.areNumbersClose(n,o,1e-5)?[r,a]:[a,r]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return P.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return P.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is too small, ignored!"),void 0;const n=new p.Vector3(0,0,1);e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0&&n.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const r=H.getOcsMatrix(n);let a,o;if(e.type==="CIRCLE")a=e.startAngle||0,o=a+2*Math.PI;else{if(e.startAngle==null||e.endAngle==null||(a=e.startAngle,o=e.endAngle,z.areNumbersEqual(a,o,1e-6)))return;if(!z.areNumbersClose(z.getArcAngleSpanInRadian(a,o),Math.PI*2)){const O=H.getArcAnglesByOcsMatrix(r,a,o);a=O[0],o=O[1]}}const l=new p.ArcCurve(0,0,e.radius,a,o,this.angBase!==0);let h=1;const d=s;d?.xScale&&d?.yScale&&(h=Math.max(Math.abs(d.xScale),Math.abs(d.yScale)));const u=this.getDivision(a,o,e.radius*h),f=l.getPoints(u),m=new p.Vector3;let b=!1;this.enableRTC&&(b=N.checkAndRebasePositionsOnRTC(f,m));const y=new p.BufferGeometry().setFromPoints(f),C=new V(G.Line);C.geometry=y,C.material=me;const w=new p.Vector3;e.center&&(w.x=e.center.x,w.y=e.center.y);const x=new p.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(r.invert());w.x=x.x,w.y=x.y;const E=w,M=new V(G.Point);return M.geometry=za,M.material=Gs,M.userData.handle=e.handle,M.userData.isSnapObject=!0,M.userData.type="CircleCenter",M.layers.set(je),C.add(M),b?(this.setRTCUserData(C),E.x+=m.x,E.y+=m.y):N.shouldRebasePositionOnRTC(E)&&this.setRTCUserData(C),C.matrix.setPosition(E),C.layers.enableAll(),C}addTriangleFacingCamera(e,i,s,n){const r=new p.Vector3,a=new p.Vector3;r.subVectors(s,i),a.subVectors(n,i),r.cross(a);const o=new p.Vector3(i.x,i.y,i.z),l=new p.Vector3(s.x,s.y,s.z),h=new p.Vector3(n.x,n.y,n.z);r.z<0?e.push(h,l,o):e.push(o,l,h)}loadSolid(e,i,s){const n=e.points;if(!n||n.length<4)return;if(e.extrusionDirection&&e.extrusionDirection.z){U.set(0,0,e.extrusionDirection.z);const u=H.getOcsMatrix(U).invert();n.forEach(f=>{const m=U.set(f.x,f.y,0).applyMatrix4(u);f.x=m.x,f.y=m.y})}const r=[],a=[];this.addTriangleFacingCamera(r,n[0],n[1],n[2]),a.push(0,1,2),this.addTriangleFacingCamera(r,n[1],n[2],n[3]),a.push(3,4,5);const o=new p.Vector3;let l=!1;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(r,o));const h=new p.BufferGeometry().setFromPoints(r);h.setIndex(a);const d=new V(G.Mesh);return d.geometry=h,d.material=gi,l&&(this.setRTCUserData(d),d.matrix.setPosition(o.x,o.y,0)),d.layers.enableAll(),d}getTextStyle(e,i){const s=e.tables?.style?.styles;return s?s[i.textStyle]||s.STANDARD||s.Standard||{}:{}}getDefaultDimensionStyle(e){return e.tables.dimStyle.dimStyles.STANDARD||e.tables.dimStyle.dimStyles.Standard||{}}getTextEncoding(e){return e?.bigFontFile&&e.bigFontFile.toUpperCase().startsWith("GB")?"gbk":"utf8"}getTextMesh(e,i,s,n){if(!e)return;const r=s?.styleName||"";if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const h=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[h]&&(this.statsInfo.unsupportedTextStyles[h]=0),this.statsInfo.unsupportedTextStyles[h]++}let a=.8;const o={_TCH_DIM:1.45,ROMANS:1};r&&o[r]&&(a=o[r]),n.xScale&&(a*=n.xScale),a>1&&r&&(a*=s?.xScale||1,i=i||s?.textHeight||0),i===0&&(r?i=1:i=.2);const l=this.createTextMeshByText(e,s,i,0,i/12,a);return l.traverse(h=>{h.geometry&&h.geometry.scale(a,1,1)}),l}createTextMeshByText(e,i,s=12,n=0,r=0,a=1,o=1/0,l=0){const h=new V,d=[];let u=0,f=0;i?.xScale;const m=n+s,b=i?.fontFile||"",y=typeof b=="string"&&b.toLowerCase().endsWith(".shx"),C=y?s*.06:s*.04,w=[];for(let M=0;M<e.length;M++){const O=e[M];O!==" "&&O!==`
795
795
  `&&w.push(M)}const x=w.length;let E=0;for(let M=0;M<e.length;M++){const O=e[M];if(O===" "){u+=s*(y?.4:.33);continue}if(O===`
796
- `){u=0,f-=m*.5;continue}let S=this.font?.getCharShape?.(O,i?.fontFile,s);if(!S&&i?.bigFontFile&&(S=this.font?.getCharShape?.(O,i.bigFontFile,s)),!S&&this.font?.fileNames){const v=this.font.fileNames.filter(T=>T!==i?.fontFile);for(let T=v.length-1;T>=0&&(i.fontFile=v[T],i.styleName="Standard",S=this.font?.getCharShape?.(O,i.fontFile,s),!S);T--);}if(S||(S=this.font?.getNotFoundTextShape?.(s)),!!S){if(S.translate(u,f,0),u>o)u=0,f-=m;else{!S.boundingBox&&S.computeBoundingBox();const v=S.boundingBox.getSize(U).x,T=O.charCodeAt(0),A=T>=19968&&T<=40959||T>=13312&&T<=19903||T>=63744&&T<=64255||T>=12288&&T<=12351||T>=65280&&T<=65519||[8216,8217,8220,8221].includes(T)?Math.max(v,s):v+C;E++,u+=A+(E===x?0:l)}d.push(S)}}if(d.length>0){const M=d.filter(S=>S instanceof p.ExtrudeGeometry),O=d.filter(S=>!(S instanceof p.ExtrudeGeometry));if(M.length>0){const S=new V(G.Mesh);S.geometry=Pe.mergeGeometries(M),S.material=gi,h.add(S)}if(O.length>0){const S=new V(G.LineSegment);S.geometry=Pe.mergeGeometries(O),S.material=me,h.add(S)}}return h}transformTextMesh(e,i){ft.makeEmpty();const s=V.getBox(i,ft),n=s.getSize(U),{halign:r,valign:a}=e;i.matrix.decompose(qs.position,qs.quaternion,qs.scale);const o=qs,l=e.width||e.textWidth||n.x,h=e.height||e.textHeight||n.y;if(r===void 0&&a===void 0&&e.startPoint||[3,5].includes(r)&&e.startPoint?(o.position.x+=e.startPoint.x,o.position.y+=e.startPoint.y,o.position.z+=e.startPoint.z):e.endPoint&&(o.position.x+=e.endPoint.x,o.position.y+=e.endPoint.y,o.position.z+=e.endPoint.z),r!==3&&r!==5){if(e.rotation){const d=e.rotation*Math.PI/180;o.rotateZ(d)}e.mirrored&2&&o.rotateY(Math.PI),e.mirrored&4&&o.rotateX(Math.PI)}switch(r){case 0:break;case 1:o.translateX(-l/2);break;case 2:o.translateX(-l);break;case 3:if(e.startPoint&&e.endPoint){const d=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),u=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),f=new p.Vector3().subVectors(d,u),m=f.length(),b=m/l;o.scale.multiplyScalar(b);const y=f.clone().cross(qe),C=f.angleTo(qe);o.rotateZ(y.z>0?Math.PI-C:C-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-h/12);break;case 5:if(e.startPoint&&e.endPoint){const d=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),u=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),f=new p.Vector3().subVectors(d,u),m=f.length(),b=m/l,C=(e.text||"").length;if(C>1){const E=(m-l)/(C-1);o.userData.letterSpacing=E}else b<3&&o.scale.setX(b);const w=f.clone().cross(qe),x=f.angleTo(qe);o.rotateZ(w.z>0?Math.PI-x:x-Math.PI)}break}switch(a){case 0:break;case 1:break;case 2:o.translateY(-h/2);break;case 3:o.translateY(-h);break}return o.position.z=0,o.updateMatrix(),i.matrix.copy(o.matrix),i}loadText(e,i,s){const n=e.text;if(!n)return;if(!this.font){P.info("[Dxf] Font file not set, ignoring text entity.");return}const r=this.getTextStyle(i,e),o=cn(n,{encoding:this.getTextEncoding(r)}).map(d=>d.text).join(""),l=this.getTextMesh(o,e.textHeight,r,e);if(!l||l.children.length===0)return;this.transformTextMesh(e,l),U.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const h=N.shouldRebasePositionOnRTC(U);return h&&this.setRTCUserData(l),l.userData={...l.userData,textContent:n,dxfType:"TEXT",isMText:!1,layer:e.layer||"0",handle:e.handle,entityId:e.entityId||e.handle},l.traverse(d=>{const u=d.geometry;if(u){if(d.userData.textContent=n,d.userData.dxfType="TEXT",d.userData.layer=e.layer||"0",d.userData.handle=e.handle,d instanceof p.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let b=0;b<f.count;b+=3)m.push(b,b+1,b+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!h){const f=N.caculateGeometryCenter(u);f&&N.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(d)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){let n=e.tag||e.text||e.prompt;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=cn(n).map(h=>h.text).join();const o=this.getTextMesh(n,e.textHeight,r,e);if(!o||o.children.length===0)return;this.transformTextMesh(e,o),U.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=N.shouldRebasePositionOnRTC(U);return l&&this.setRTCUserData(o),o.traverse(h=>{const d=h.geometry;if(d){if(h instanceof p.Mesh&&!d.getIndex()){const u=d.getAttribute("position"),f=[];for(let m=0;m<u.count;m+=3)f.push(m,m+1,m+2);d.setIndex(f)}if(d.hasAttribute("uv")&&d.deleteAttribute("uv"),d.hasAttribute("normal")&&d.deleteAttribute("normal"),!l){const u=N.caculateGeometryCenter(d);u&&N.shouldRebasePositionOnRTC(u)&&this.setRTCUserData(h)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){let n=e.text;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=cn(n).map(u=>u.text).join("");const o=this.getTextMesh(n,e.textHeight,r,e);if(!o||o.children.length===0)return;const l=s?.zdysx;o.userData.llbData=l;let h;if(l)try{h=JSON.parse(l)}catch{h=l}o.userData.textContent=n||"",o.userData.dxfType="ATTRIB",o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",this.transformTextMesh(e,o),U.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const d=N.shouldRebasePositionOnRTC(U);return d&&this.setRTCUserData(o),o.traverse(u=>{const f=u.geometry;if(f){if(u instanceof p.Mesh&&!f.getIndex()){const m=f.getAttribute("position"),b=[];for(let y=0;y<m.count;y+=3)b.push(y,y+1,y+2);f.setIndex(b)}if(f.hasAttribute("uv")&&f.deleteAttribute("uv"),f.hasAttribute("normal")&&f.deleteAttribute("normal"),u instanceof p.Mesh&&(u.entity=e,u.userData.entity=e),u.userData.textContent=n,u.userData.dxfType="ATTRIB",u.userData.layer=e.layer||"0",u.userData.handle=e.handle||"",h!==void 0&&(u.userData.xdata=h),!d){const m=N.caculateGeometryCenter(f);m&&N.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!e.position)return;const n=new p.BufferGeometry,r=[new p.Vector3(e.position.x,e.position.y,e.position.z)];U.set(0,0,0);const a=U;let o=!1;this.enableRTC&&(o=N.checkAndRebasePositionsOnRTC(r,a)),n.setFromPoints(r);const l=new V(G.Point);return l.geometry=n,l.material=me,o&&(this.setRTCUserData(l),l.matrix.setPosition(a.x,a.y,0)),l.layers.enableAll(),l}loadDimension(e,i){if(!e.block)return;const s=i.blocks[e.block];if(!s||!s.entities)return;const n=i.tables.dimStyle.dimStyles[e.dimStyleName]||this.getDefaultDimensionStyle(i);n&&n.DIMCLRD>0&&(e.colorIndex=n.DIMCLRD,e.color=ki(e.colorIndex));const r=new V;for(let o=0;o<s.entities.length;o++){const l=this.loadEntity(s.entities[o],i,e);l&&r.add(l)}if(r.children.length===0){const o=e.name||e.block;return!this.statsInfo.ignoredInserts[o]&&(this.statsInfo.ignoredInserts[o]=0),this.statsInfo.ignoredInserts[o]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const o=this.blockReferencesCache[e.block];o.referenceCount++}r.name=e.type+"<"+s.name+">",r.userData.entityType=e.type;const a=e.insertionPoint;return U.set(0,0,0),a&&U.set(a.x,a.y,0),N.shouldRebasePositionOnRTC(U)&&this.setRTCUserData(r),r.matrix.setPosition(U),r}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const n=i.objects.IMAGEDEF.filter(y=>y.handle===e.imageDefHandle)[0];if(!n)return;const r=e.imageSize.x,a=e.imageSize.y,o=new V;let l=!1;e.flags===hn.ShowImageWhenNotAlignedWithScreen||e.flags===hn.UseClippingBoundary||e.flags===hn.TransparencyIsOn||(l=!0);const h=new p.PlaneGeometry(r,a);if(l){const y=new p.TextureLoader(this.manager).load(n.filename,void 0,void 0,()=>{console.warn("Please upload the pictures in the same folder, or use url link in the dxf file.")});y.colorSpace=p.SRGBColorSpace;const C=new p.MeshBasicMaterial({transparent:!0,side:p.FrontSide,map:y}),w=new V(G.Mesh);w.geometry=h,w.material=C,o.add(w)}const d=new p.EdgesGeometry(h),u=this.getColor(e,i,s),f=new V(G.Line);f.geometry=d,f.material=this.getLineBasicMaterial(u);const m=e.uPixel?new p.Vector3(e.uPixel.x,e.uPixel.y,e.uPixel.z):new p.Vector3(n.pixelSize.x,0,0),b=e.vPixel?new p.Vector3(e.vPixel.x,e.vPixel.y,e.vPixel.z):new p.Vector3(n.pixelSize.y,0,0);if(o.add(f),K.set(m.x,b.y,1),U.set(0,0,0),e.position){const y=new p.Vector3(e.position.x,e.position.y,e.position.z);y.add(m.multiplyScalar(r/2)).add(b.multiplyScalar(a/2)),U.copy(y)}return N.shouldRebasePositionOnRTC(U)&&this.setRTCUserData(o),ge.identity(),o.matrix.compose(U,ge,K),o}loadInsert(e,i,s,n=!1){if(!e||!e.block)return;const r=i.blocks[e.block];if(!r||!r.entities)return;s&&e.layer==="0"&&(e.layer=s.layer),e.blockPosition=r.position;const a=new V,o=e.zdysx;let l;if(o)try{l=JSON.parse(o)}catch{l=o}for(let m=0;m<r.entities.length;m++){if(r.entities[m].type==="ATTDEF")continue;const b=this.loadEntity(r.entities[m],i,e,n);b&&(o&&H.LOADLLDATA&&(b.userData.llbData=o),l!==void 0&&b.traverse(y=>{y.geometry&&(y.userData.xdata=l)}),a.add(b))}if(a.children.length===0){const m=e.name||e.block;return!this.statsInfo.ignoredInserts[m]&&(this.statsInfo.ignoredInserts[m]=0),this.statsInfo.ignoredInserts[m]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const m=this.blockReferencesCache[e.block];m.referenceCount++}a.name=e.type+"<"+r.name+">",a.userData.entityType=e.type,l!==void 0&&(a.userData.xdata=l),e.extendedData?.originalType&&(a.userData.originalType=e.extendedData?.originalType),e?.blockPosition&&a.matrix.setPosition(-e.blockPosition.x,-e.blockPosition.y,0);const h=U.set(1,1,1);e.xScale&&(h.x=e.xScale),e.yScale&&(h.y=e.yScale);const d=new p.Euler;e.rotation&&(d.z=e.rotation*Math.PI/180),ge.setFromEuler(d,!1);const u=K.set(0,0,0);e.position&&(u.x=e.position.x,u.y=e.position.y),de.compose(u,ge,h),e.extrusionDirection&&e.extrusionDirection.z<0&&de.premultiply(ja.identity().makeScale(-1,1,1)),tt.copy(a.matrix),a.matrix.premultiply(de),K.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(a);const f=this.findSpatialFilterByHandle(e.handle,i);if(f){this.loadSpatialFilter(f);const m=f;m&&m.clipPolylines&&m.clipPolylines.length>0&&(a.userData.spatialFilterHandle=f.handle,this.cloneMaterialsForSpatialFilter(a),P.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;de.set(s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],0,0,0,1);const n=[];e.vertices.forEach(o=>{n.push(new p.Vector3(o.x,o.y,0))});const r={polyline:[],bConcave:!1,bReversed:!1};if(e.numberOfPointsOnClipBoundary===2)r.polyline=n;else{const o=e.numberOfPointsOnClipBoundary,l=3;if(o<l)return P.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let h=[],d=-1;for(let m=0;m<o;m++){const b=n[m];for(let y=o-1;y>m;y--){const C=n[y];if(z.areVector3sEqual(b,C)&&m+1<y-1&&m+1<o-1&&z.areVector3sEqual(n[m+1],n[y-1])){h.push(b),d=y;break}}if(d>0)break;h.push(b)}if(d>0)for(let m=d+1;m<o;m++)h.push(n[m]);if(h.length<l)return P.warn("[Dxf] Invalid clipBoundary: "+e.handle+"!"),void 0;const u=[],f=[];if(h.forEach(m=>{u.push(new p.Vector2(m.x,m.y)),f.push([m.x,m.y])}),!N.isConvex(u)){P.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const m=Fl(f,1/0);h=[],m.forEach(b=>{h.push(new p.Vector3(b[0],b[1],0))})}!z.areVector3sEqual(h[0],h[h.length-1])&&h.push(h[0]),r.polyline=h,r.bReversed=d>0}let a;return this.enableReleaseData&&(e.vertices=[],e.matrix=[],e.invertBlockMatrix=[]),i.localMatrix=de.clone(),i.clipPolylines=[],i.clipPolylines.push(r),a}loadLayout(e,i,s,n,r,a){if(!e.entities)return;const o=new V;for(let d=0;d<e.entities.length;d++){const u=e.entities[d];this.addViewport(u,a);const f=this.loadEntity(u,i);f&&(this.enableMerge&&Mt.merge(f,!1),o.add(f),f.traverse(m=>{if(m.geometry){const b=m.userData.layerName;let y=r[b];!y&&(y=[],r[b]=y),y.push(m),m.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[s.layoutName]&&(this.layoutsSnapObjectsMap[s.layoutName]=[]),this.layoutsSnapObjectsMap[s.layoutName].push(m))}}))}if(o.children.length===0)return;o.userData.layerName=e.layer;const l=s.layoutName;let h=n.children.find(d=>d.name===l);!h&&(h=new V,h.name=l,h.userData.isLayoutLevelObject=!0,n.add(h)),h.add(o),e.position&&o.matrix.setPosition(e.position.x,e.position.y,e.position.z||0)}convertEdgeToPoints(e){const i=[];if(!e)return i;switch(e.type){case Ci.Line:{const n=e;i.push(new p.Vector2(n.startPoint.x,n.startPoint.y)),i.push(new p.Vector2(n.endPoint.x,n.endPoint.y));break}case Ci.Arc:{const n=e;let r=n.startAngle*p.MathUtils.DEG2RAD,a=n.endAngle*p.MathUtils.DEG2RAD;!n.bCounterclockwise&&(r=Math.PI*2-r,a=Math.PI*2-a);const o=new p.ArcCurve(n.center.x,n.center.y,n.radius,r,a,!n.bCounterclockwise),l=this.getDivision(r,a,n.radius),h=o.getPoints(l);e.startPoint=h[0],e.endPoint=h[h.length-1],i.push(...h);break}case Ci.Ellipse:{const n=e,r=Math.sqrt(Math.pow(n.majorAxisEndPoint.x,2)+Math.pow(n.majorAxisEndPoint.y,2)),a=r*n.minorRatio,o=Math.atan2(n.majorAxisEndPoint.y,n.majorAxisEndPoint.x);let l=n.startAngle*p.MathUtils.DEG2RAD,h=n.endAngle*p.MathUtils.DEG2RAD;!n.bCounterclockwise&&(l=Math.PI*2-l,h=Math.PI*2-h);const d=new p.EllipseCurve(n.center.x,n.center.y,r,a,l,h,!n.bCounterclockwise,o),u=this.getDivision(l,h,Math.max(r,a)),f=d.getPoints(u);e.startPoint=f[0],e.endPoint=f[f.length-1],i.push(...f);break}case Ci.Spline:{const n=e,r=Wa(n.controlPoints,n.degreeOfSplineCurve,n.knotValues);if(r.length===0)break;e.startPoint=r[0],e.endPoint=r[r.length-1],i.push(...r);break}case Ci.Polyline:{const n=e,r=Yn(n.points,n.isClosed);e.startPoint=r[0],e.endPoint=r[r.length-1],i.push(...r);break}}return i}loadHatch(e,i,s){const n=e;let r=[];function a(M,O){const{startPoint:S,endPoint:v}=M,{startPoint:T,endPoint:_}=O,A=v.x-S.x,I=v.y-S.y,B=_.x-T.x,k=_.y-T.y,L=A*k-I*B;if(Math.abs(L)<1e-10)return null;const F=S.x-T.x,ie=S.y-T.y,se=(B*ie-k*F)/L,Fe=(A*ie-I*F)/L;return se>=0&&se<=1&&Fe>=0&&Fe<=1?{x:S.x+se*A,y:S.y+se*I}:null}function o(M){const{edges:O}=M,S=[],v=O.length;if({...M},v!==4)return[M];for(let T=0;T<v;T++)for(let _=T+2;_<v;_++){if(_===T+1||T===0&&_===v-1)continue;const A=a(O[T],O[_]);A&&S.push({edgeIndex1:T,edgeIndex2:_,point:{x:A.x,y:A.y}})}if(S.length&&S.length===1){const T={pathTypeFlag:M.pathTypeFlag,edges:[O[S[0].edgeIndex1-1],{startPoint:{...O[S[0].edgeIndex1].startPoint},endPoint:{x:S[0].point.x,y:S[0].point.y},type:O[S[0].edgeIndex1].type},{startPoint:{x:S[0].point.x,y:S[0].point.y},endPoint:{x:O[S[0].edgeIndex2].startPoint.x,y:O[S[0].edgeIndex2].startPoint.y},type:O[S[0].edgeIndex2].type}]},_={pathTypeFlag:M.pathTypeFlag,edges:[{startPoint:{x:S[0].point.x-1e-5,y:S[0].point.y-1e-5},endPoint:{...O[S[0].edgeIndex1].endPoint},type:O[S[0].edgeIndex1].type},{...O[S[0].edgeIndex2-1]},{startPoint:O[S[0].edgeIndex2].startPoint,endPoint:{x:S[0].point.x-1e-5,y:S[0].point.y-1e-5},type:O[S[0].edgeIndex2].type}]};return[T,_]}return[M]}if(n.boundaryPaths.length==0)return;for(let M=0;M<n.boundaryPaths.length;M++){const O=n.boundaryPaths[M],S=o(O);r=[...r,...S]}if(n.boundaryPaths=r,!n.solidFill&&!n.patternLines?.length){P.warn("[Dxf] Hatch entity(handle: '"+n.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],h=[],d=[],u=M=>{const O=[];let S=[];S.push(...this.convertEdgeToPoints(M[0]));for(let v=1;v<M.length;v++){const T=this.convertEdgeToPoints(M[v]);if(S.push(...T),S.length>2){const _=this.convertEdgeToPoints(M[v-1]);z.areVector2sEqual(_[_.length-1],T[0])?z.areVector2sEqual(S[0],T[T.length-1],1e-5)&&(O.push(S),S=[]):z.areVector2sEqual(_[0],T[T.length-1])?z.areVector2sEqual(S[1],T[0],1e-5)&&(O.push(S),S=[]):S=[]}}return O};if(n.boundaryPaths.forEach((M,O)=>{let S=[];if(this.IsfilteredByPathTypeFlag(M.pathTypeFlag)){P.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",M.pathTypeFlag,O,n.handle);return}const v=M.edges;if(v.length===0)return;const T=[];for(let _=0;_<v.length;_++){const A=this.convertEdgeToPoints(v[_]);if(A.length<2){P.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",_,O,n.handle);continue}T.push(...A)}if(T.length<3){P.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",O,n.handle);return}if(S.push(T),M.pathTypeFlag>Uo.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const B=A[I-1].endPoint,k=A[I].startPoint;if(!B||!k||!z.areVector2sEqual(B,k))return!1}return!0})(M.edges)||!n.associativity)&&(S=u(v),S.length<2)){P.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",O,n.handle);return}S.forEach(_=>{!z.areVector2sEqual(_[0],_[_.length-1])&&_.push(_[0]);const A=_.map(I=>new p.Vector2(j.roundNumber(I.x,7),j.roundNumber(I.y,7)));if(A?.length>0){l.push(A);const I=new p.Box2().setFromPoints(A);h.push(I);const B=I.getSize(Ji),k=B.x*B.y;d.push({area:k,index:l.length-1})}})}),l.length===0)return;const f=new p.Vector2,m=this.checkAndRebasePolygonsOnRTC(l,f);d.sort((M,O)=>M.area-O.area);const b=[];d.forEach(M=>{b.push(M.index)});const y=this.buildContainHierarchyTree(l,h,b),C=[];this.buildHatchGeometry(l,y,C);let w;if(C.length>0&&(w=Pe.mergeGeometries(C)),!w||!w.getIndex()||w.getIndex()?.count===0)return P.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const x=new V(G.Mesh);x.geometry=w,x.material=gi,this.setHatchMaterial(x,n,i,f,s);const E=x;return m&&(this.setRTCUserData(E),E.matrix.setPosition(f.x,f.y,0)),E.traverse(M=>{M.layers.enableAll(),M.layers.disable(je)}),E}loadOle2frame(e,i){const{leftUpX:s,leftUpY:n,rightDownX:r,rightDownY:a}=e;if(!s||!n||!r||!a)return;const o=[new p.Vector2(s,n),new p.Vector2(s,a),new p.Vector2(r,a),new p.Vector2(r,n),new p.Vector2(s,n)],l=new p.Vector3;let h=!1;this.enableRTC&&(h=N.checkAndRebasePositionsOnRTC(o,l));const d=new p.BufferGeometry().setFromPoints(o),u=this.getLineBasicMaterial(16777215),f=new V(G.Line);f.geometry=d,f.material=u,f.layers.enableAll(),h&&(this.setRTCUserData(f),f.matrix.setPosition(l.x,l.y,0));const m=new V;m.add(f);let b;const y=i.objects.DICTIONARY;for(const w of y)for(const x in w.entries)if(w.entries[x]===e.handle){b=x;break}let C;if(b)if(this.meshTextureMaterials[b])C=this.meshTextureMaterials[b];else for(let w=0;w<i.objects.XRECORD.length;w++){const x=i.objects.XRECORD[w];if(x.handle===b){const E=x.binaryData,M=j.hexToBase64(E),O="data:image/jpg;base64,"+M,S=new p.TextureLoader(this.manager).load(O);S.colorSpace=p.SRGBColorSpace;const v=new p.MeshBasicMaterial({transparent:!0,map:S});this.meshTextureMaterials[b]=v,C=v;break}}if(C){const w=new p.Box2().setFromPoints(o),x=w.getSize(Ji),E=new p.PlaneGeometry(x.x,x.y),M=new V(G.Mesh);M.geometry=E,M.material=C;const O=w.getCenter(Ji);U.set(O.x,O.y,0),h&&(this.setRTCUserData(M),U.x+=l.x,U.y+=l.y),M.matrix.setPosition(U),M.layers.enableAll(),m.add(M)}return m.children.length>1?m:f}static getOcsMatrix(e){let i=qe,s=Wn,n=mi;const r=new p.Vector3(0,1,0),a=new p.Vector3(0,0,1);return z.areVectorsClose(e,a)?de.identity():(n=e.clone().normalize(),!z.areVectorsClose(n,a)&&(Math.abs(n.x)<1/64&&Math.abs(n.y)<1/64?i=r.cross(n).normalize():i=a.cross(n).normalize(),s=n.clone().cross(i).normalize()),de.set(i.x,i.y,i.z,0,s.x,s.y,s.z,0,n.x,n.y,n.z,0,0,0,0,1))}static getDcs2WcsMatrix(e,i){let s;C1(e)?s=e.viewDirectionFromTarget:s=e.viewDirection,s??(s={x:0,y:0,z:1});const n=e.viewTarget??{x:0,y:0,z:0},r=new p.Vector3(z.roundNumber(s.x,7),z.roundNumber(s.y,7),s.z),a=new p.Vector3(n.x,n.y,n.z),o=e.viewTwistAngle||0;let l,h,d;d=r.clone().normalize(),l=mi.clone().cross(r),l.length()>0?(l.normalize(),h=d.clone().cross(l)):d.z<0?(l=qe.clone().negate(),h=Wn,d=mi.clone().negate()):(l=qe,h=Wn,d=mi);const u=new p.Matrix4,f=de.identity();return f.makeBasis(l,h,d),u.premultiply(f),u.premultiply(de.identity().compose(a.clone(),new p.Quaternion().setFromAxisAngle(new p.Vector3(0,0,1),p.MathUtils.degToRad(i?o:-o)),new p.Vector3(1,1,1))),u}getViewportMsToPsMatrix(e){const i=e.centerPoint_dcs??{x:0,y:0},s=e.centerPoint??{x:0,y:0,z:0},n=new p.Vector3(i.x,i.y,0),r=new p.Vector3(s.x,s.y,s.z),a=e.viewHeight,o=e.height_paperSpace||1,l=(a||o)/o,h=H.getDcs2WcsMatrix(e,this.angDir),d=new p.Matrix4;d.setPosition(za.clone().sub(r));const u=ja.identity();u.scale(U.set(l,l,l));const f=tt.identity().setPosition(za.clone().sub(r));u.premultiply(f.clone().invert()).multiply(f),d.multiply(u);const m=de.identity();m.setPosition(n),h.multiply(m);const b=de.identity();return d.invert().multiply(b).multiply(h.invert())}loadViewport(e,i,s){if(e.viewportId+""=="1"){e.psBBox=new p.Box3,e.msToPsMatrix=new p.Matrix4;return}const n=e.centerPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y)){e.psBBox=new p.Box3,e.msToPsMatrix=new p.Matrix4;return}const r=e.width_paperSpace/2,a=e.height_paperSpace/2,o=[new p.Vector3(n.x-r,n.y-a,0),new p.Vector3(n.x-r,n.y+a,0),new p.Vector3(n.x+r,n.y+a,0),new p.Vector3(n.x+r,n.y-a,0)];o.push(o[0]),e.psBBox=new p.Box3().setFromPoints([o[0],o[2]]),e.msToPsMatrix=this.getViewportMsToPsMatrix(e);let l=!1;const h=new p.Vector3;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(o,h));const d=new p.BufferGeometry().setFromPoints(o),u=new V(G.Line);u.geometry=d,u.material=me,u.userData.entityType=e.type,u.layers.enableAll(),l&&(this.setRTCUserData(u),u.matrix.setPosition(h.x,h.y,0));const f=e.psBBox.clone();f.applyMatrix4(e.msToPsMatrix.clone().invert()),f.min.z=0,f.max.z=0;const m=[f.min,new p.Vector3(f.min.x,f.max.y,0),f.max,new p.Vector3(f.max.x,f.min.y,0)];m.push(m[0]);let b=!1;const y=new p.Vector3;this.enableRTC&&(b=N.checkAndRebasePositionsOnRTC(m,y));const C=new p.BufferGeometry().setFromPoints(m),w=new V(G.Line);w.geometry=C,w.material=me,w.userData.entityType=e.type,w.userData.inPaperSpace=[],w.layers.enableAll(),b&&(this.setRTCUserData(w),w.matrix.setPosition(y.x,y.y,0));const x=new V;return x.add(u),x.add(w),u}getColor(e,i,s){if(this.compareContext)return at.ENTITY_COLOR_NO_CHANGE;if(this.overrideColor!=null)return this.overrideColor;const n=e;if(n&&n.isGradientColor){const r=n.gradientColors;if(r&&r.length>=2){if(r[0]!==r[1]){const a="[Dxf] Gradient colors are not supported for hatch '"+e.handle+"', will use the first color!";P.warn(a)}return r[0]}}if(e.isTrueColor||e.colorIndex>0&&e.colorIndex<256)return e.color;if(e.colorIndex===0)return s?this.getColor(s,i):i.tables?.layer?.layers[0].color;if(e.colorIndex===256){const r=i.tables?.layer?.layers,a=r&&r[e.layer],o=r&&s&&r[s.layer];let l=Rt;return a&&a.name!=="0"?l=a.color:o?l=o.color:a?l=a.color:r&&r[0].color&&(l=r[0].color),l}return P.warn("[Dxf] Unknown colorIndex"),Rt}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==kr&&e.lineType!==gs)return e.lineType;if(e.lineType===gs)return s?this.getLineType(s,i):e.lineType;const n=i.tables?.layer?.layers,r=T1;if(e.layer!=="0"){const a=n&&n[e.layer];if(a)return a.lineType}else if(s){const a=n&&n[s.layer];if(a)return a.lineType}return r}getLayerName(e,i,s){const n=h=>{r&&h&&!r[e.layer]&&(console.warn("[Dxf] Failed to find layer object for '"+h+"', adding a default one."),r[h]={name:h,handle:"",colorIndex:256,lineType:"",visible:!0})},r=i.tables?.layer?.layers;n(e.layer);const a=r&&r[e.layer];n(s?.layer);const o=r&&s&&r[s.layer];let l=a?.name||"";return a&&a.name==="0"&&o&&(l=o.name),l}setMaterial(e,i,s,n){const r=e;if(!r.geometry||(this.setRenderOrderByObjectType(e),i.type==="OLE2FRAME"))return;if(i.type==="MTEXT"){e.renderOrder=Oe.Text;return}if(i.type==="HATCH"){Ji.set(0,0),this.setHatchMaterial(e,i,s,Ji,n);return}if(i.type==="IMAGE")return;let a;const o=this.getColor(i,s,n);if(i.type==="LWPOLYLINE"&&(r.isMesh?(a=this.getMeshBasicMaterial(o),e.renderOrder=Oe.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=Oe.LineWithPattern),a)){r.material=a;return}if(i.type==="SOLID")a=this.getMeshBasicMaterial(o);else if(i.type==="TEXT"||i.type==="ATTDEF"||i.type==="ATTRIB")a=this.getLineBasicMaterial(o),e.renderOrder=Oe.Text;else if(i.type==="LEADER"||i.type==="MULTILEADER"||i.type==="VIEWPORT")a=this.getLineBasicMaterial(o);else if(i.type==="POINT")a=this.getPointsMaterial(o);else{if(e.material instanceof p.PointsMaterial){a=this.getPointsMaterial(o),r.material=a;return}const l=s.tables?.lineType?.lineTypes,h=l&&l[this.getLineType(i,s,n)];if(h&&h.pattern&&h.pattern.length!==0){const d=i.lineTypeScale||1;a=this.getLineShaderMaterial(h,o,d),e.renderOrder=Oe.LineWithPattern}else a=this.getLineBasicMaterial(o)}r.material=a}setHatchMaterial(e,i,s,n,r){const a=e;if(!a.geometry)return;const o=this.getColor(i,s,r);if(a.type===G.Line||a.type===G.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=Oe.Mesh,h;if(i.solidFill)h=this.getMeshBasicMaterial(o);else{if(a.material instanceof p.ShaderMaterial){h=a.material;const d=new p.Color(o);!a.material.uniforms.u_color.value.equals(d)&&(h=a.material.clone(),H.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o))}else h=this.getHatchShaderMaterial(i,o,n);l=Oe.MeshWithPattern}!h&&(h=this.getMeshBasicMaterial(o),l=Oe.Mesh),a.material=h,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=Oe.Mesh:i.isLine?s=Oe.Line:i.isPoints&&(s=Oe.Point),e.renderOrder=s}getPointsMaterial(e){return!this.pointsMaterials[e]&&(this.pointsMaterials[e]=new p.PointsMaterial({size:.2,color:e})),this.pointsMaterials[e]}getLineBasicMaterial(e){return!this.lineBasicMaterials[e]&&(this.lineBasicMaterials[e]=new p.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,i,s){const n=e.name+"_"+i+"_"+s;if(!this.lineShaderMaterials[n]){const r=this.getLineTypeScales(),a=r.ltScale*r.celtScale*s;this.lineShaderMaterials[n]=zo.createLineShaderMaterial(e.pattern,i,a,H.ViewportScaleUniform,H.CameraZoomUniform)}return this.lineShaderMaterials[n]}getMeshBasicMaterial(e){return!this.meshBasicMaterials[e]&&(this.meshBasicMaterials[e]=new p.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getHatchShaderMaterial(e,i,s){if(!e.patternLines||e.patternLines.length<1)return;const n=this.findMatchedHatchShaderMaterial(e,i);if(n)return n;const r=.005,a=.05;let o=2;e.patternLines.forEach(f=>{o=Math.max(f.dashPattern.length,o)});let l=0;const h=[],d=new p.Vector2;for(const f of e.patternLines){const m=new p.Vector2(f.origin.x,f.origin.y).sub(s).rotateAround(d,-p.MathUtils.degToRad(e.patternAngle)),b=new p.Vector2(f.delta.x,f.delta.y).rotateAround(d,-p.MathUtils.degToRad(f.angle));if(b.y===0)return P.warn("[Dxf] delta.y is equal to zero !"),void 0;const y=f.dashPattern.length;let C=!0,w=0;for(let v=0;v<y;++v){const T=f.dashPattern[v];T>0&&(C=!1),w+=Math.abs(T)}const x=C?a:r,E=[],M=[];let O=0;M[0]=O;for(let v=0;v<y;++v)E[v]=f.dashPattern[v],E[v]===0&&(E[v]=x*w),O+=Math.abs(E[v]),M[v+1]=O;for(let v=y;v<o;++v)E[v]=0;for(let v=M.length;v<o+1;++v)M[v]=O;const S={origin:m,delta:b,angle:f.angle-e.patternAngle,pattern:E,patternSum:M,patternLength:O};if(l+=4,l+=o,l+=o+1,l>H.MaxFragmentUniforms){P.warn("[Dxf] There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(S)}const u=Vo(h,e.patternAngle,H.CameraZoomUniform,new p.Color(i),this.overrideHatchPatternLineThickness);return u.defines={MAX_PATTERN_SEGMENT_COUNT:o},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:i,material:u}),u}getDivision(e,i,s){let n=Math.round(5e4/this.entityCount);n=Math.max(n,2),n=Math.min(n,10);const r=n*5;let o=n*2;if(this.averageCurveSize){const d=Math.pow(s/this.averageCurveSize,.5);o*=d,o=Math.max(o,n),o=Math.min(o,r)}let l=i-e;l<0&&(l+=Math.PI*2),o=Math.ceil(o*(l/Math.PI));let h=8;return l<.087?h=2:l<.174?h=3:l<.52?h=4:l<1.57?h=5:l<3.14?h=6:l<4.71&&(h=7),o=Math.max(o,h),this.averageCurveSize=(this.averageCurveSize*this.curveCount+s)/(this.curveCount+1),this.curveCount++,Math.max(o,12)}getBSplineInterpolationsPerSplineSegment(e,i){let s=1;this.averageCurveSize&&(s=Math.pow(i/this.averageCurveSize,.5),s=Math.max(s,.5),s=Math.min(s,2)),this.averageCurveSize=(this.averageCurveSize*this.curveCount+i)/(this.curveCount+1),this.curveCount++;let n=e*2*s;if(e>20){const r=Math.log10(e);n/=r}return n}async setDxfDataToIndexedDb(e,i){const s={dxfDataId:e,dxf:i};return new Promise((n,r)=>{pn.instance().add(s,()=>{P.info("[Dxf] Saved '"+e+"' to indexedDb"),n()},a=>{r(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{pn.instance().query(e,n=>{n&&n.length>0&&i(n[0].dxf),i(void 0)},()=>s())})}buildContainHierarchyTree(e,i,s){const n=new Map,r=s.length;for(let o=0;o<r;o++)n.set(s[o],{index:s[o],children:[]});const a={index:-1,children:[]};for(let o=0;o<r;o++){const l=s[o],h=e[l],d=i[l];let u=o+1;for(;u<r;u++){const f=s[u],m=e[f];if(i[f].containsBox(d)&&N.isPointInPolygon(h[j.generateRandomInt(0,h.length-1)],m)){n.get(f)?.children.push(n.get(l));break}}u===r&&a.children.push(n.get(l))}return a}buildHatchGeometry(e,i,s){if(i.children.length===0)return;const n=[],r=new Map;i.children.forEach(l=>{l.children.length===0?n.push(l.index):r.set(l.index,l.children.map(h=>h.index))});const a=l=>{try{const h=new p.ShapeGeometry(l);h.hasAttribute("uv")&&h.deleteAttribute("uv"),h.hasAttribute("normal")&&h.deleteAttribute("normal"),s.push(h)}catch{P.warn("[Dxf] triangulate shape error: "+l.getPoints().map(d=>d.toArray()).toString())}};n.forEach(l=>{const h=e[l];if(h.length===0)return;const d=new p.Shape(h);a(d)});const o=l=>l.map(h=>h.toArray());for(const l of r){const h=new p.Shape(e[l[0]]);let d={regions:[],inverted:!1};const u=this.findIntersectHole(e,l[1]);u.forEach(m=>{let b={regions:[],inverted:!1};try{m.forEach((y,C)=>{if(Xt.epsilon(z.getVector2RelativeEps(e[y][0]),1e-6),C===0)b=Xt.segments({regions:[o(e[y])],inverted:!1});else{const w=Xt.segments({regions:[o(e[y])],inverted:!1}),x=Xt.combine(b,w);d=Xt.polygon(Xt.selectUnion(x)),d.regions.length>0?d.regions.forEach(E=>{if(E.length===0)return;const M=E.map(O=>new p.Vector2(O[0],O[1]));h.holes.push(new p.Path(M))}):P.warn("[Dxf] mergedHoles.regions is empty")}})}catch(y){P.warn("[Dxf] polybooljs has error: "+y+", epsilon is "+Xt.epsilon())}});const f=u.flat(2);for(let m=0;m<l[1].length;m++){const b=l[1][m];!f.includes(b)&&h.holes.push(new p.Path(e[b]))}a(h)}i.children.forEach(l=>{l.children.forEach(h=>{this.buildHatchGeometry(e,h,s)})})}findIntersectHole(e,i){const s=i.length,n=[];for(let r=0;r<s;r++){const a=e[i[r]];let o=!1;const l=[];for(let h=r+1;h<s;h++){const d=e[i[h]];N.arePolygonsIntersect(a,d)&&(o=!0,l.push(i[h]))}o&&(l.push(i[r]),n.push(l))}return n}checkAndRebasePolygonsOnRTC(e,i){if(!this.enableRTC||e.length===0)return!1;let s=0;e.forEach(r=>{r.forEach(a=>{i.add(a),s++})}),i.divideScalar(s);let n=!1;if(this.enableRTC&&N.shouldRebasePositionOnRTC(i)){n=!0;for(let r=0;r<e.length;r++){const a=e[r];for(let o=0;o<a.length;o++){const l=a[o].x-i.x,h=a[o].y-i.y;a[o]=new p.Vector2(l,h)}}}else i.set(0,0);return n}setRTCUserData(e){e.userData.relativeToCenter=!0,this.statsInfo.rebasedEntityCount++}IsfilteredByPathTypeFlag(e){return e<0}findSpatialFilterByHandle(e,i){const s=i.objects.DICTIONARY;if(!s)return;if(!this.dictionaryOwnerHandleAndSpatialFilterHandlesCache){this.dictionaryOwnerHandleAndSpatialFilterHandlesCache={};for(const r of s){const a=r;let o="";for(const l in a.entries)if(a.entries[l]==="ACAD_FILTER"){o=l;break}o&&(this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[r.ownerHandle]&&P.warn("[Dxf] Why this.dictionaryObjectsCache[obj.ownerHandle] already exist?",r.ownerHandle),this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[r.ownerHandle]=o)}}const n=this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[e];if(n){if(!this.spatialFiltersCache){this.spatialFiltersCache={};const r=i.objects.SPATIAL_FILTER||[];for(const a of r){const o=a;o.numberOfPointsOnClipBoundary<2||(this.spatialFiltersCache[o.ownerHandle]&&P.warn("[Dxf] Why this.spatialFiltersCache[spatialFilterObj.ownerHandle] already exist?",n),this.spatialFiltersCache[o.ownerHandle]=o)}}return this.spatialFiltersCache[n]}}initRenderOrderInfo(e){const i=new Set,s=e.objects.DICTIONARY;for(const r of s){const a=r;Object.keys(a.entries).forEach(o=>{a.entries[o]&&a.entries[o]==="ACAD_SORTENTS"&&i.add(o)})}if(i.size===0)return;const n=e.objects.SORTENTSTABLE;if(n)for(let r=0;r<n.length;++r){const a=n[r];if(i.has(a.handle)){for(let o=0;o<a.sortEntsObject.entityHandles.length;++o){const l=a.sortEntsObject.entityHandles[o];l.length===2&&!this.entityHandlesWithRenderOrder[l[0]]?this.entityHandlesWithRenderOrder[l[0]]=l[1]:P.warn("[Dxf] Failed to handle sortEntsTable: "+a.handle+".")}break}}}findMatchedHatchShaderMaterial(e,i){const s=e.patternLines;if(!s||s.length<1)return;const n=(h,d)=>Math.abs(h-d)<1e-5,r=(h,d)=>{if(h.length!==d.length)return!1;for(let u=0;u<h.length;++u)if(!n(h[u],d[u]))return!1;return!0},a=(h,d)=>n(h.angle,d.angle)&&n(h.delta.x,d.delta.x)&&n(h.delta.y,d.delta.y)&&n(h.origin.x,d.origin.x)&&n(h.origin.y,d.origin.y)&&r(h.dashPattern,d.dashPattern),o=(h,d)=>{if(h.length!==d.length)return!1;for(let u=0;u<h.length;++u)if(!a(h[u],d[u]))return!1;return!0};return this.hatchShaderMaterials.find(h=>h.color===i&&h.patternAngle===e.patternAngle&&o(h.patternLines,s))?.material}getLayout(e,i){if(!this.blockRecordsCache){this.blockRecordsCache={};const r=this.blockRecordsCache,a=e.tables?.blockRecord?.blockRecords;a&&Object.values(a).forEach(o=>{r[o.handle]=o.layoutHandle})}const s=this.blockRecordsCache[i.ownerHandle];if(s){const r=e.objects.LAYOUT,a=r.find(o=>o.handle===s);if(a)return a}if(!this.entitiesCache){this.entitiesCache={};const r=this.entitiesCache;Object.values(e.entities).forEach(a=>{r[a.handle]=a})}const n=this.entitiesCache[i.ownerHandle];return n?this.getLayout(e,n):e.objects.LAYOUT.find(r=>r.layoutName===H.MODEL_LAYOUT_NAME)}getLayerVisible(e,i){const s=e.tables?.layer?.layers;return s&&s[i]?.visible}getLayerFrozen(e,i){const s=e.tables?.layer?.layers;return s&&s[i.layer]?.frozen}cloneMaterialsForSpatialFilter(e){const i=new Map,s=n=>{let r;if(Array.isArray(n)){const a=[];r=a,n.forEach(o=>{if(i.has(o.id))a.push(i.get(o.id));else{const l=o.clone();H.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else n&&(i.has(n.id)?r=i.get(n.id):(r=n.clone(),H.updateMaterialUniforms(r),i.set(n.id,r)));return r};e.traverse(n=>{n.material&&(n.material=s(n.material))})}getLineTypeScales(){const e={ltScale:1,celtScale:1};return this.header&&(e.ltScale=this.header.$LTSCALE||1,e.celtScale=this.header.$CELTSCALE||1),e}static getDxfUnits(e){switch(e||0){case 0:return Ze.Unitless;case 1:return Ze.Inches;case 2:return Ze.Feet;case 4:return Ze.Millimeters;case 5:return Ze.Centimeters;case 6:return Ze.Meters;default:P.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return Ze.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const n=e.matrixWorld;if(s.index&&(P.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=N.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){P.debug("[Dxf] This line has been merged!");let r=0;e.userData.batches.forEach(a=>{a.positionStart=r,a.positionCount=a.indexCount,a.indexStart=0,a.indexCount=0,r+=a.positionCount})}if(s.index===null){const r=s.attributes.position;if(!r||r.count===0)return;const a=[];if(i)for(let o=0,l=r.count;o<l;o+=2)U.fromBufferAttribute(r,o).applyMatrix4(n),K.fromBufferAttribute(r,o+1).applyMatrix4(n),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+U.distanceTo(K);else{a[0]=0;for(let o=1,l=r.count;o<l;o++)U.fromBufferAttribute(r,o-1).applyMatrix4(n),K.fromBufferAttribute(r,o).applyMatrix4(n),a[o]=a[o-1],a[o]+=U.distanceTo(K)}s.setAttribute("lineDistance",new p.Float32BufferAttribute(a,1)),e.geometry=s}else P.warn("[Dxf] computeLineDistances only possible with non-indexed BufferGeometry.")}static computeLineDistances(e){const i=Date.now();e.traverse(s=>{const n=s;n.isLine&&n.material instanceof p.ShaderMaterial&&H.computeLineDistance(n)}),P.debug("[Dxf] Computed line distances in "+(Date.now()-i)/1e3+"s")}static mergeDxfObjects(e){const i=Date.now(),s={},n={},r=15e3;let a=0,o=0;const l=()=>{const d=Date.now();for(const u in s){const f=s[u];H.removeEmptyObjectsFromRemovingMarkedObjects2(f.children,f.object),f.children=[]}a=0,o+=Date.now()-d};for(const d in e.layersAndObjects){const u=e.layersAndObjects[d];if(u.length<=1)continue;const f=Date.now(),m={},b=[];for(const y of u){if(y.userData.isSnapObject){b.push(y);continue}let C,w=y;for(;w;){if(w.userData.isLayoutLevelObject){C=w;break}w=w.parent}if(!C)continue;const x=C.name;!m[x]&&(m[x]={object:C,children:[]}),m[x].children.push(y)}for(const y in m){const C=m[y],w=Mt.deepMerge(C.children,C.object,!1,!1,!0),x=w.added,E=w.removed;!s[y]&&(s[y]={object:C.object,children:[]}),!n[y]&&(n[y]={object:C.object,children:[]});const M=E.length>r;if(M){const O=Date.now();H.removeEmptyObjectsFromRemovingMarkedObjects2(E,C.object),o+=Date.now()-O}else a+=E.length;if(E.length===C.children.length)!M&&E.forEach(O=>{s[y].children.push(O)});else{let O=E;E.length>=100&&(O=new Set(E));const S=v=>Array.isArray(O)?O.indexOf(v)>=0:O.has(v);for(let v=0;v<C.children.length;v++){const T=C.children[v];S(T)?!M&&s[y].children.push(T):b.push(T)}}for(let O=0;O<x.length;O++){const S=x[O];b.push(S),n[y].children.push(S)}a>r&&l()}e.layersAndObjects[d]=b,P.debug("[Dxf] Merged layer '"+d+"' in "+(Date.now()-f)/1e3+"s")}a>0&&l();for(const d in n){const u=n[d];!e.root.children.find(m=>m.name===d)&&e.root.add(u.object),u.children.forEach(m=>{u.object.add(m)}),u.children=[]}P.debug("[Dxf] MergeUtils.deepMerge took "+fe.MergeInfo.elapsedTime/1e3+"s"),P.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),P.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const h=fe.MergeInfo;P.debug("[Dxf] Totally merged "+h.removedObjects+" objects to "+h.mergedMeshes+"meshes, "+h.mergedLines+"lines, "+h.mergedPoints+"points, "+(h.mergedUnknownTypeObjects?h.mergedUnknownTypeObjects+" unknown type,":" ")+" ")}static async merge(e,i){const s=j.getUpdateProgressFuncAsync(i),n={};e.objects.LAYOUT.forEach(y=>{const C=y;n[C.layoutName]=C,C.directAssociatedLeafObjectSet?.clear()});const r=Date.now(),a={},o={},l=15e3;let h=0,d=0;const u=()=>{const y=Date.now();for(const C in a){const w=a[C];H.removeEmptyObjectsFromRemovingMarkedObjects(w.children,w.object),w.children=[]}h=0,d+=Date.now()-y},f=Object.keys(e.layersAndThreejsObjects).length;let m=0;for(const y in e.layersAndThreejsObjects){const C=e.layersAndThreejsObjects[y];if(C.length<=1){await s(++m/f*100);continue}const w=Date.now(),x={},E=[];for(const S of C){if(S.userData.isSnapObject){E.push(S);continue}let v,T=S;for(;T;){if(T.userData.isLayoutLevelObject){v=T;break}T=T.parent}if(!v)continue;const _=v.name;!x[_]&&(x[_]={object:v,children:[]}),x[_].children.push(S)}const M=Object.keys(x).length;let O=0;for(const S in x){let v;if(S!==H.MODEL_LAYOUT_NAME){const k=n[S];!k.directAssociatedLeafObjectSet&&(k.directAssociatedLeafObjectSet=new Set),v=k.directAssociatedLeafObjectSet}const T=x[S],_=fe.deepMerge(T.children,T.object,!1,!1,!0),A=_.added,I=_.removed;!a[S]&&(a[S]={object:T.object,children:[]}),!o[S]&&(o[S]={object:T.object,children:[]});const B=I.length>l;if(B){const k=Date.now();H.removeEmptyObjectsFromRemovingMarkedObjects(I,T.object),d+=Date.now()-k}else h+=I.length;if(I.length===T.children.length)!B&&I.forEach(k=>{a[S].children.push(k)});else{let k=I;I.length>=100&&(k=new Set(I));const L=F=>Array.isArray(k)?k.indexOf(F)>=0:k.has(F);for(let F=0;F<T.children.length;F++){const ie=T.children[F];L(ie)?!B&&a[S].children.push(ie):(E.push(ie),v&&v.add(ie))}}for(let k=0;k<A.length;k++){const L=A[k];J.setSharedVariablesOfObject(L),E.push(L),o[S].children.push(L),v&&v.add(L)}h>l&&u(),await s((m+ ++O/M)/f*100)}await s(++m/f*100),e.layersAndThreejsObjects[y]=E,P.debug("[Dxf] Merged layer '"+y+"' in "+(Date.now()-w)/1e3+"s")}h>0&&u();for(const y in o){const C=o[y],w=e.threejsObject.children.find(x=>x.name===y);if(w){const x=w.children.find(E=>E.name===H.SNAP_GROUP_NAME);if(x&&y!==H.MODEL_LAYOUT_NAME){const E=n[y];!E.directAssociatedLeafObjectSet&&(E.directAssociatedLeafObjectSet=new Set),x.children.forEach(M=>E.directAssociatedLeafObjectSet?.add(M))}}!w&&e.threejsObject.add(C.object),C.children.forEach(x=>{!x.visible&&(x.userData.layerVisible=!1),C.object.add(x),x.updateWorldMatrix(!1,!1)}),C.children=[]}P.debug("[Dxf] MergeUtils.deepMerge took "+fe.MergeInfo.elapsedTime/1e3+"s"),P.debug("[Dxf] The remove operation of deep merge took "+d/1e3+"s"),P.debug("[Dxf] Deep merge totally took "+(Date.now()-r)/1e3+"s");const b=fe.MergeInfo;P.debug("[Dxf] Totally merged "+b.removedObjects+" objects to "+b.mergedMeshes+"meshes, "+b.mergedLines+"lines, "+b.mergedPoints+"points, "+(b.mergedUnknownTypeObjects?b.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const n in e)e[n].averageTime=e[n].totalTime/e[n].createCount;P.debug("[Dxf] Entity types and took how much time in ms:",e),P.debug("[Dxf] Entity types and mesh count:",this.statsInfo.entityTypesAndMeshCount);let i=0;if(Object.values(this.statsInfo.entityTypesAndMeshCount).forEach(n=>{i+=n}),this.enableRTC&&P.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const n=fe.MergeInfo;P.debug("[Dxf] Inner merged "+n.removedObjects+" objects to "+n.mergedMeshes+"meshes, "+n.mergedLines+"lines, "+n.mergedPoints+"points, "+(n.mergedUnknownTypeObjects?n.mergedUnknownTypeObjects+" unknown type,":" ")+"in "+n.elapsedTime/1e3+"s")}const s=(n,r,...a)=>{Object.keys(r).length>0};s("[Dxf] Unsupported entity types and count:",this.statsInfo.unsupportedEntityTypes),s("[Dxf] Unsupported text style names and count:",this.statsInfo.unsupportedTextStyles,". Will use a default style."),s("[Dxf] Unsupported hatch pattern names and count:",this.statsInfo.unsupportedHatchPatterns,". Filling in solid lines instead."),this.statsInfo.unsupportedPolylineCount&&P.warn("[Dxf] Unsupported polyline (with both width and linetype) count: "+this.statsInfo.unsupportedPolylineCount+", linetype will be ignored."),s("[Dxf] Ignored invisible entity types and count:",this.statsInfo.invisibleEntities),s("[Dxf] Ignored frozen layers and entity count:",this.statsInfo.ignoredFrozenLayersAndEntityCount),s("[Dxf] Ignored inserts and count (may because they don't contain anything):",this.statsInfo.ignoredInserts),this.ignorePaperSpace&&s("[Dxf] Ignored paper space entity count:",this.statsInfo.ignoredPaperSpaceEntityTypesAndCount),this.font&&s("[Dxf] Unsupported chars and count:",this.font.getUnsupportedChar())}static statLayoutAndLayerObjects(e){const i=new WeakSet;let s=0;for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&(s++,i.has(l)?console.warn(l):i.add(l))});const n=new WeakSet;let r=0;if(e.threejsObject.traverse(a=>{a.geometry&&(r++,n.has(a)?console.warn(a):n.add(a))}),s!=r)for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&!n.has(l)&&console.warn(l)});P.info("[Dxf] The count of layer objects is "+s+",The count of layout objects is "+r+" ")}static removeEmptyObjectsFromRemovingMarkedObjects(e,i){if(e.length===0)return;const s=n=>{const r=[];for(const a of n){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&r.push(o))}r.length>0&&s(r)};s(e),this.removeEmptyObjectsFromMark(i)}static removeEmptyObjectsFromMark(e){if(e.userData.validCount===0||J.isEmptyObject(e))return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark(e.children[i])&&++i;return!1}static removeEmptyObjectsFromRemovingMarkedObjects2(e,i){if(e.length===0)return;const s=n=>{const r=[];for(const a of n){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&r.push(o))}r.length>0&&s(r)};s(e),this.removeEmptyObjectsFromMark2(i)}static removeEmptyObjectsFromMark2(e){if(e.userData.validCount===0||e.type===G.Object&&e.children.length===0)return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark2(e.children[i])&&++i;return!1}};g(H,"MODEL_LAYOUT_NAME","Model"),g(H,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),g(H,"SHOW_SNAP_OBJECT",!1),g(H,"CameraZoomUniform",{value:1}),g(H,"ViewportScaleUniform",{value:1}),g(H,"TransformMatrixUniform",{value:new p.Matrix4}),g(H,"ResolutionUniform",{value:new p.Vector2}),g(H,"LOADLLDATA",!1),g(H,"MaxFragmentUniforms",1024);let X=H;class Mr extends Nt{constructor(e){super();g(this,"viewer");g(this,"overlayRender");g(this,"drawableList");this.drawableList=new ws("compare"),this.viewer=e,this.overlayRender=this.viewer.getOverlayRender(),this.overlayRender?.addDrawableList(this.drawableList)}drawCompareDrawable(e){const i=[],s=[],n=[];for(const l of Object.values(e)){const h=l.box;h&&(l.type===Ve.Added?i.push(h):l.type===Ve.Removed?s.push(h):n.push(h))}const r=N.mergeBBoxes(i),a=N.mergeBBoxes(s),o=N.mergeBBoxes(n);this.drawableList.addDrawable(new bt(j.guid(),r,[.1,.9,.2,1])),this.drawableList.addDrawable(new bt(j.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new bt(j.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class vn{}const yi=new p.Matrix4,Xn=new p.Box3;class Ri extends vn{constructor(e){super();g(this,"modelId");g(this,"modelData");g(this,"modelObject");g(this,"bbox");this.modelData=e,this.modelId=e.modelId,this.modelObject=e.dxfData?.threejsObject||e.pdfData?.threejsObject,this.modelObject.name=this.modelId,this.modelObject.userData.modelId=this.modelId}get pdfData(){return this.modelData.pdfData}get dxfData(){return this.modelData.dxfData}get msTransformMatrix(){return this.modelData.msTransformMatrix}set msTransformMatrix(e){this.modelData.msTransformMatrix=e}get loadedEntityCount(){return this.dxfData?.loadedEntityCount||this.pdfData?.loadedEntityCount||0}get header(){return this.dxfData?.header}get viewports(){return this.dxfData?.tables.viewport.viewports}get layers(){const e=this.dxfData||this.pdfData;return e.tables?.layer.layers||e.layers}get layoutViewportsMap(){return this.dxfData?.layoutViewportsMap}getModelObject(){const e=this.dxfData||this.pdfData;if(!e)throw new Error("Failed to find model by modelId '"+this.modelId+"'!");return e.threejsObject}getBBox(){if(!this.bbox){const e=new p.Box3,i=this.getModelObject();e.setFromObject(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return Ze.Unitless;const e=this.dxfData.header;if(!e)return P.warn("DxfData or its header is undefined!"),Ze.Unitless;const i=e.$INSUNITS;return X.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new p.Vector3,s=new p.Vector3;if(!e){P.error("Header is undefined in "+this.modelId+"!");return}const n=this.viewports;let r=e.$EXTMIN,a=e.$EXTMAX;const o=e.$ANGDIR;if(n&&n.length>0)for(let l=0;l<n.length;l++){const h=n[l];if(h.name.toLocaleUpperCase()==="*ACTIVE"){const{center:d,viewHeight:u,aspectRatio:f}=h,m=u*f,b=X.getDcs2WcsMatrix(h,o),y=new p.Vector3(d.x,d.y,0);y.applyMatrix4(b),r={x:y.x-m/2,y:y.y-u/2,z:0},a={x:y.x+m/2,y:y.y+u/2,z:0};break}}return i.set(r.x,r.y,r.z),s.set(a.x,a.y,a.z),new p.Box3(i,s)}getLayer(e){if(this.layers)return this.layers[e]}getObjectsByLayer(e){const i=this.dxfData||this.pdfData;return i?.layersAndThreejsObjects&&i.layersAndThreejsObjects[e]}getLayouts(){const e=[];return this.dxfData?.objects.LAYOUT?.forEach(n=>{e.push(n)}),e}getLayoutByName(e){let i;const s=this.getLayouts();for(const n of s)if(n.layoutName===e){i=n;break}return i}getLayoutExtent(e){const i=this.header,s=new p.Vector3,n=new p.Vector3;if(!i)throw new Error("Header is undefined in "+this.modelId+"!");const r=this.getLayoutViewports(e);let a=i.$PEXTMIN,o=i.$PEXTMAX;const l=i.$ANGDIR;if(r&&r.length>0){const h=r.filter(C=>parseInt(C.viewportId)===1);let d;h.length>0?d=h[0]:d=r[0];const{centerPoint:u,width_paperSpace:f,height_paperSpace:m}=d,b=X.getDcs2WcsMatrix(d,l),y=new p.Vector3(u.x,u.y,0);y.applyMatrix4(b),a={x:y.x-f/2,y:y.y-m/2,z:0},o={x:y.x+f/2,y:y.y+m/2,z:0}}return s.set(a.x,a.y,a.z),n.set(o.x,o.y,o.z),new p.Box3(s,n)}getLayoutViewports(e){const s=this.layoutViewportsMap[e.ownerHandle];return s||[]}getLayoutLevelObject(e){return this.getModelObject()?.children.find(s=>s.name===e)}setVisible(e){const i=this.getModelObject();i.visible=e}setLayerVisible(e,i,s,n){const r=this.getLayer(e);r?r.visible=i:P.warn("[Viewer] Layer '"+e+"' not found from modelData!");const a=this.getObjectsByLayer(e);if(a)for(let o=0;o<a.length;o++){const l=a[o];!(s&&i&&n&&l.userData.visibleMinZoom&&n<l.userData.visibleMinZoom)&&(l.visible=i),(i===!1||l.userData.layerVisible!=null)&&(l.userData.layerVisible=i),l.userData.isSnapObject&&(l.visible?X.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(je):X.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(je))}else P.info("[Viewer] No object found for layer '"+e+"'")}setLayerOpacity(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const n=this.getObjectsByLayer(e);n?n.forEach(r=>{const a=r;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=xe.cloneMaterial(a.material));const o=xe.cloneMaterial(a.material);xe.setMaterialOpacity(o,i),X.updateMaterialUniforms(o),a.material=o}}):P.info("[Viewer] No object found for layer '"+e+"'")}setLayerColor(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const n=this.getObjectsByLayer(e);n?n.forEach(r=>{const a=r;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=xe.cloneMaterial(a.material));const o=xe.cloneMaterial(a.material);xe.setMaterialColor(o,new p.Color(i)),X.updateMaterialUniforms(o),a.material=o}}):P.info("[Viewer] No object found for layer '"+e+"'")}resetLayerColor(e){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const s=this.getObjectsByLayer(e);s?s.forEach(n=>{const r=n;r.material&&r.userData.originalMaterial&&(r.material.dispose(),r.material=r.userData.originalMaterial,delete r.userData.originalMaterial)}):P.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(yi.identity(),!i||!j.isMatrixValid(i)||i.equals(yi))return;const s=this.getLayoutLevelObject(X.MODEL_LAYOUT_NAME);s&&(e===X.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=X.MODEL_LAYOUT_NAME,i){this.switchTransformMs(e);const s=this.getLayoutByName(e);if(s){if(!i){const n=this.getLayoutViewports(s);let r=[];n.length>0&&(r=n[0].frozenLayerHandles);const a=e!==X.MODEL_LAYOUT_NAME,o=this.getLayoutLevelObject(e);if(o){const d=[];o.traverse(u=>{this.addSpatialFilterSection(u,this.dxfData);const f=u;if(a&&f.material&&f.geometry){const m=f.userData.layerName;if(this.isLayerFrozenForViewport(m,r))return;d.push(f);let b=-1;const y=this.getObjectsByLayer(m);y&&(b=y.indexOf(f),b>=0&&y.splice(b,1)),b<0&&P.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+m+"', layout '"+e+"'")}}),d.forEach(u=>{u.removeFromParent()})}const l=this.getFilteredViewports(s);P.debug("[Viewer] Active layout:",e,", viewports:",l);const h=Date.now();l.forEach(d=>{this.generateObjectsByViewport(e,d,this)}),P.info("[Viewer] generateObjectsByViewport in "+(Date.now()-h)/1e3+"s")}this.showLayoutObjects(e)}}getFilteredViewports(e){const i=this.getLayoutViewports(e);let s=i.filter(n=>n.viewportId!=="1");return s.length===i.length&&(s=i.filter((n,r)=>r!==0)),s}generateObjectsByViewport(e,i,s,n=[]){const r=i;if(i.viewportId=="1")return;if(!r.psBBox||!r.msToPsMatrix)throw new Error("The bbox or matrix is invalid in the viewport!");X.TransformMatrixUniform={value:r.msToPsMatrix},X.ViewportScaleUniform={value:i.viewHeight/i.height_paperSpace};const a=r.psBBox.clone();a.applyMatrix4(r.msToPsMatrix.clone().invert()),a.min.setZ(-1),a.max.setZ(1);const o=this.getObjectsByBoundingBox(a);if(o.length===0)return;const l=r.psBBox.min,h=r.psBBox.max,d=new p.Box2(new p.Vector2(l.x,l.y),new p.Vector2(h.x,h.y)),u=zt.generateSectionPlanesByBox(d),f=[],m=T=>(!f[T.id]&&(f[T.id]=T.clone(),this.setMaterialUniforms(f[T.id],s.dxfData),zt.setMaterialSection(f[T.id],u)),f[T.id]),b=T=>{if(Array.isArray(T)){const _=[];return T.forEach(A=>{const I=m(A);_.push(I)}),_}else return m(T)},y=[...n,...i.frozenLayerHandles||[]];let C;if(e!==X.MODEL_LAYOUT_NAME){const T=r;!T.associatedLeafObjectSet&&(T.associatedLeafObjectSet=new Set),C=T.associatedLeafObjectSet}const w=new p.Group;w.name=r.viewportId;const x=[];if(o.forEach(T=>{const _=T.clone();_.traverse(A=>{const I=A;if(I.material&&I.geometry){const B=I.userData.layerName;if(this.isLayerFrozenForViewport(B,y)){x.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=b(I.material),C?.add(I);const k=s.getObjectsByLayer(B);k?k.push(I):P.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+B+"', layout '"+e+"'")}}),w.add(_)}),C&&C.size===0)return;const E=s.getModelObject();let M=s.getLayoutLevelObject(e);!M&&(M=new p.Group,J.setSharedVariablesOfObject(M),M.name=e,E?.add(M)),M.add(w),w.applyMatrix4(r.msToPsMatrix),w.updateMatrixWorld(!0);let O=M.children.find(T=>T.name===X.SNAP_GROUP_NAME);!O&&(O=new p.Group,O.visible=X.SHOW_SNAP_OBJECT,O.name=X.SNAP_GROUP_NAME,M.add(O));const S=s.getLayoutLevelObject(X.MODEL_LAYOUT_NAME),v=S?.children.find(T=>T.name===X.SNAP_GROUP_NAME);v&&v.traverse(T=>{if(!T.geometry)return;const _=T.userData.layerName;if(this.isLayerFrozenForViewport(_,y)||(Xn.makeEmpty(),Xn.expandByObject(T),!a.intersectsBox(Xn)))return;const A=T.clone();J.setSharedVariablesOfObject(A);let I=A.parent;const B=yi.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)B.premultiply(I.matrix),I=I.parent;B.premultiply(r.msToPsMatrix),A.applyMatrix4(B),O?.add(A),C?.add(A);const k=s.getObjectsByLayer(_);k&&k.push(A)}),x.length>0&&J.removeEmptyObjectsFromRemovingObjects(x,w),w.traverse(T=>{J.setSharedVariablesOfObject(T),this.addSpatialFilterSection(T,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=X.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=X.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return P.warn("[Viewer] bbox is empty !"),i;const s=r=>{const a=Ot.getBoundingBox(r,!1);e.intersectsBox(a)&&i.push(r)},n=this.getLayoutLevelObject(X.MODEL_LAYOUT_NAME);return n&&n.children.forEach(r=>{r.name!==X.SNAP_GROUP_NAME&&s(r)}),i}showLayoutObjects(e){let i=0,s=0;const n=this.getModelObject();n.children.forEach(r=>{const a=r.name===e;r.visible=a,a?i++:s++}),P.debug("[Viewer] showLayoutObjects('"+e+"') sets "+i+" layout level object(s) to visible and "+s+" to hidden for model '"+n?.name+"'")}isLayerFrozenForViewport(e,i){const s=this.getLayer(e);return s&&(s.flag&1)>0?!0:!i||i.length<=0?!1:s&&i.indexOf(s.handle)>=0}addSpatialFilterSection(e,i,s=!1){if(e.userData.entityType!=="INSERT"||!e.userData.spatialFilterHandle)return;const n=this.findSpatialFilter(e.userData.spatialFilterHandle,i);if(n){let r=s,a=!1;const o=this.getAnyMaterial(e);if(o&&(o.clippingPlanes&&(r=o.clippingPlanes.length>0),a=o.clipIntersection),r&&a!==n.clipPolylines[0].bReversed){P.warn("[Viewer] Material cannot set clipIntersection to different values at the same time. clipIntersection needs to be set to true here!");return}a=n.clipPolylines[0].bReversed;const l=this.generateSectionsBySpatialFilter(n,e.matrixWorld);if(l){const h=f=>{let m=0;return f.clippingPlanes&&(m=f.clippingPlanes.length),m+l.length>X.MaxFragmentUniforms},d=new Set,u=f=>{d.has(f.id)||(d.add(f.id),!h(f)&&zt.setMaterialSection(f,l,r,a))};e.traverse(f=>{const m=f.material;Array.isArray(m)?m.forEach(b=>{u(b)}):m&&u(m)})}}}findSpatialFilter(e,i){const s=i.objects.SPATIAL_FILTER;if(!s)return;let n;for(const r of s)if(r.handle===e){n=r;break}return n}getAnyMaterial(e){const i=e;if(i.material)return Array.isArray(i.material)?i.material[0]:i.material;let s;for(let n=0;n<e.children.length&&(s=this.getAnyMaterial(e.children[n]),!s);n++);return s}generateSectionsBySpatialFilter(e,i){const s=e.clipPolylines[0];if(s.bConcave){P.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}yi.copy(i),e.localMatrix&&yi.multiply(e.localMatrix);const n=s.polyline,r=[];n.forEach(l=>{const h=l.clone().applyMatrix4(yi);r.push(new p.Vector2(h.x,h.y))});const a=p.ShapeUtils.isClockWise(r),o=!a&&!s.bReversed||a&&s.bReversed;return zt.generateSectionPlanesByPoints(r,o)}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}highlightObject(e){if(!this.hasObject(e))return;const i=xe.clonedHighlightMaterials(e,{depthTest:!1});i&&(e.userData.originalMaterial=e.material,e.material=i)}unHighlightObject(e){if(!this.hasObject(e))return;const i=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(i)?i.forEach(s=>s.dispose()):i instanceof p.Material&&i.dispose()}clearHighlight(){}}class Dr extends vn{constructor(e){super();g(this,"modelId");g(this,"bbox");g(this,"rootObject");g(this,"modelObject");g(this,"highlighUsage");g(this,"transparentUsage");g(this,"edges");g(this,"highlighedObject");this.modelId=e.modelId,this.bbox=e.bbox,this.modelObject=e.object,this.rootObject=new p.Group,this.rootObject.name="rootObject-"+this.modelId,this.rootObject.userData.modelId=this.modelId,this.highlighUsage=new p.Group,this.highlighUsage.name="highlighUsage-"+this.modelId,this.highlighUsage.layers.disable(Ut),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(Ut),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&J.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&J.revertDoubleSidedMaterialToObject(e)})}getModelObject(){return this.rootObject}getBBox(){return!this.bbox&&(this.bbox=new p.Box3,this.bbox.setFromObject(this.getModelObject())),this.bbox}async enableOutline(e,i){e&&!this.edges&&(this.edges=await J.createOutlines(this.getModelObject(),void 0,i)),this.edges&&this.edges.forEach(s=>s.visible=e)}setObjectColor(e,i){this.hasObject(e)&&e.material.color.set(i)}setObjectOpacity(e,i=.5,s,n){if(this.hasObject(e)){if(e instanceof p.InstancedMesh&&n){const r=this.createInstanceMeshById(e,n,{opacity:i});r.material.opacity*=i,e.userData.instanceId=n,e.userData.transparentedMesh=r,this.transparentUsage.add(r)}else if(fe.isMergedMesh(e)&&s){const r=this.createBatchMeshById(e,s,{opacity:i});r.material.opacity*=i,e.userData.batchId=s,e.userData.transparentedMesh=r,this.transparentUsage.add(r)}else{const r=new p.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});r&&(e.userData.originalMaterial=e.material,e.material=r)}e.userData.isTransparent=!0}}clearObjectOpacity(e,i,s){if(!this.isObjectTransparent(e))return;const{transparentedMesh:n,originalMaterial:r}=e.userData;n&&(this.transparentUsage.remove(n),delete e.userData.batchId,delete e.userData.instanceId,delete e.userData.transparentedMesh),r&&(e.material=r),delete e.userData.isTransparent}isObjectTransparent(e){const{isTransparent:i}=e.userData;return!!i}setOpacity(e=.5){this.getModelObject().traverse(i=>{i instanceof p.Mesh&&this.setObjectOpacity(i,e)})}clearOpacity(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&this.clearObjectOpacity(e)})}highlightObjectById(e,i,s){if(!this.hasObjectWithId(e))return;const n=this.getModelObject().getObjectById(e);n&&this.highlightObject(n,i,s)}highlightObject(e,i,s){if(!this.hasObject(e))return;const n=new p.Color(Ar);if(e instanceof p.InstancedMesh&&s){const r=this.createInstanceMeshById(e,s,{depthTest:!1});r.material.opacity=.7,xe.setMaterialColor(r.material,n),e.userData.instanceId=s,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else if(fe.isMergedMesh(e)&&i){const r=this.createBatchMeshById(e,i,{depthTest:!1});r.material.opacity=.7,xe.setMaterialColor(r.material,n),e.userData.batchId=i,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else{const r=xe.clonedHighlightMaterials(e,{depthTest:!1});r&&(e.userData.originalMaterial=e.material,e.material=r)}e.userData.isHighlight=!0,this.highlighedObject=e}clearHighlight(){if(this.highlighedObject&&this.highlighedObject.userData){const e=this.highlighedObject.userData,{clonedMesh:i,originalMaterial:s,instanceId:n,originalMatrix:r}=e;i&&(i.removeFromParent(),i.geometry.dispose(),delete e.clonedMesh),n&&r&&(this.highlighedObject.setMatrixAt(n,r),delete e.instanceId,delete e.originalMatrix),s&&(this.highlighedObject.material=s,delete e.originalMaterial),delete e.isHighlight}this.highlighUsage.clear(),this.highlighedObject=void 0}setObjectVisible(e,i){this.hasObject(e)&&(e.visible=i)}setVisible(e){this.getModelObject().traverse(i=>{i instanceof p.Mesh&&(i.visible=e)})}hasVisibleObject(){let e=0;return this.modelObject.traverseVisible(i=>{i instanceof p.Mesh&&e++}),e>0}hasInvisibleObject(){let e=0;return this.modelObject.traverse(i=>{i instanceof p.Mesh&&e++}),this.modelObject.traverseVisible(i=>{i instanceof p.Mesh&&e--}),e>0}createBatchMeshById(e,i,{opacity:s=1,depthTest:n=!0}){const r=fe.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+r?.name,r?.userData&&(a+=`
796
+ `){u=0,f-=m*.5;continue}let S=this.font?.getCharShape?.(O,i?.fontFile,s);if(!S&&i?.bigFontFile&&(S=this.font?.getCharShape?.(O,i.bigFontFile,s)),!S&&this.font?.fileNames){const v=this.font.fileNames.filter(T=>T!==i?.fontFile);for(let T=v.length-1;T>=0&&(i.fontFile=v[T],i.styleName="Standard",S=this.font?.getCharShape?.(O,i.fontFile,s),!S);T--);}if(S||(S=this.font?.getNotFoundTextShape?.(s)),!!S){if(S.translate(u,f,0),u>o)u=0,f-=m;else{!S.boundingBox&&S.computeBoundingBox();const v=S.boundingBox.getSize(U).x,T=O.charCodeAt(0),A=T>=19968&&T<=40959||T>=13312&&T<=19903||T>=63744&&T<=64255||T>=12288&&T<=12351||T>=65280&&T<=65519||[8216,8217,8220,8221].includes(T)?Math.max(v,s):v+C;E++,u+=A+(E===x?0:l)}d.push(S)}}if(d.length>0){const M=d.filter(S=>S instanceof p.ExtrudeGeometry),O=d.filter(S=>!(S instanceof p.ExtrudeGeometry));if(M.length>0){const S=new V(G.Mesh);S.geometry=Pe.mergeGeometries(M),S.material=gi,h.add(S)}if(O.length>0){const S=new V(G.LineSegment);S.geometry=Pe.mergeGeometries(O),S.material=me,h.add(S)}}return h}transformTextMesh(e,i){ft.makeEmpty();const s=V.getBox(i,ft),n=s.getSize(U),{halign:r,valign:a}=e;i.matrix.decompose(qs.position,qs.quaternion,qs.scale);const o=qs,l=e.width||e.textWidth||n.x,h=e.height||e.textHeight||n.y;if(r===void 0&&a===void 0&&e.startPoint||[3,5].includes(r)&&e.startPoint?(o.position.x+=e.startPoint.x,o.position.y+=e.startPoint.y,o.position.z+=e.startPoint.z):e.endPoint&&(o.position.x+=e.endPoint.x,o.position.y+=e.endPoint.y,o.position.z+=e.endPoint.z),r!==3&&r!==5){if(e.rotation){const d=e.rotation*Math.PI/180;o.rotateZ(d)}e.mirrored&2&&o.rotateY(Math.PI),e.mirrored&4&&o.rotateX(Math.PI)}switch(r){case 0:break;case 1:o.translateX(-l/2);break;case 2:o.translateX(-l);break;case 3:if(e.startPoint&&e.endPoint){const d=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),u=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),f=new p.Vector3().subVectors(d,u),m=f.length(),b=m/l;o.scale.multiplyScalar(b);const y=f.clone().cross(qe),C=f.angleTo(qe);o.rotateZ(y.z>0?Math.PI-C:C-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-h/12);break;case 5:if(e.startPoint&&e.endPoint){const d=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),u=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),f=new p.Vector3().subVectors(d,u),m=f.length(),b=m/l,C=(e.text||"").length;if(C>1){const E=(m-l)/(C-1);o.userData.letterSpacing=E}else b<3&&o.scale.setX(b);const w=f.clone().cross(qe),x=f.angleTo(qe);o.rotateZ(w.z>0?Math.PI-x:x-Math.PI)}break}switch(a){case 0:break;case 1:break;case 2:o.translateY(-h/2);break;case 3:o.translateY(-h);break}return o.position.z=0,o.updateMatrix(),i.matrix.copy(o.matrix),i}loadText(e,i,s){const n=e.text;if(!n)return;if(!this.font){P.info("[Dxf] Font file not set, ignoring text entity.");return}const r=this.getTextStyle(i,e),o=cn(n,{encoding:this.getTextEncoding(r)}).map(d=>d.text).join(""),l=this.getTextMesh(o,e.textHeight,r,e);if(!l||l.children.length===0)return;this.transformTextMesh(e,l),U.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const h=N.shouldRebasePositionOnRTC(U);return h&&this.setRTCUserData(l),l.userData={...l.userData,textContent:n,dxfType:"TEXT",isMText:!1,layer:e.layer||"0",handle:e.handle,entityId:e.entityId||e.handle},l.traverse(d=>{const u=d.geometry;if(u){if(d.userData.textContent=n,d.userData.dxfType="TEXT",d.userData.layer=e.layer||"0",d.userData.handle=e.handle,d instanceof p.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let b=0;b<f.count;b+=3)m.push(b,b+1,b+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!h){const f=N.caculateGeometryCenter(u);f&&N.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(d)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){let n=e.tag||e.text||e.prompt;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=cn(n).map(h=>h.text).join();const o=this.getTextMesh(n,e.textHeight,r,e);if(!o||o.children.length===0)return;this.transformTextMesh(e,o),U.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=N.shouldRebasePositionOnRTC(U);return l&&this.setRTCUserData(o),o.traverse(h=>{const d=h.geometry;if(d){if(h instanceof p.Mesh&&!d.getIndex()){const u=d.getAttribute("position"),f=[];for(let m=0;m<u.count;m+=3)f.push(m,m+1,m+2);d.setIndex(f)}if(d.hasAttribute("uv")&&d.deleteAttribute("uv"),d.hasAttribute("normal")&&d.deleteAttribute("normal"),!l){const u=N.caculateGeometryCenter(d);u&&N.shouldRebasePositionOnRTC(u)&&this.setRTCUserData(h)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){let n=e.text;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=cn(n).map(u=>u.text).join("");const o=this.getTextMesh(n,e.textHeight,r,e);if(!o||o.children.length===0)return;const l=s?.zdysx;o.userData.llbData=l;let h;if(l)try{h=JSON.parse(l)}catch{h=l}o.userData.textContent=n||"",o.userData.dxfType="ATTRIB",o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",this.transformTextMesh(e,o),U.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const d=N.shouldRebasePositionOnRTC(U);return d&&this.setRTCUserData(o),o.traverse(u=>{const f=u.geometry;if(f){if(u instanceof p.Mesh&&!f.getIndex()){const m=f.getAttribute("position"),b=[];for(let y=0;y<m.count;y+=3)b.push(y,y+1,y+2);f.setIndex(b)}if(f.hasAttribute("uv")&&f.deleteAttribute("uv"),f.hasAttribute("normal")&&f.deleteAttribute("normal"),u instanceof p.Mesh&&(u.entity=e,u.userData.entity=e),u.userData.textContent=n,u.userData.dxfType="ATTRIB",u.userData.layer=e.layer||"0",u.userData.handle=e.handle||"",h!==void 0&&(u.userData.xdata=h),!d){const m=N.caculateGeometryCenter(f);m&&N.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!e.position)return;const n=new p.BufferGeometry,r=[new p.Vector3(e.position.x,e.position.y,e.position.z)];U.set(0,0,0);const a=U;let o=!1;this.enableRTC&&(o=N.checkAndRebasePositionsOnRTC(r,a)),n.setFromPoints(r);const l=new V(G.Point);return l.geometry=n,l.material=me,o&&(this.setRTCUserData(l),l.matrix.setPosition(a.x,a.y,0)),l.layers.enableAll(),l}loadDimension(e,i){if(!e.block)return;const s=i.blocks[e.block];if(!s||!s.entities)return;const n=i.tables.dimStyle.dimStyles[e.dimStyleName]||this.getDefaultDimensionStyle(i);n&&n.DIMCLRD>0&&(e.colorIndex=n.DIMCLRD,e.color=ki(e.colorIndex));const r=new V;for(let o=0;o<s.entities.length;o++){const l=this.loadEntity(s.entities[o],i,e);l&&r.add(l)}if(r.children.length===0){const o=e.name||e.block;return!this.statsInfo.ignoredInserts[o]&&(this.statsInfo.ignoredInserts[o]=0),this.statsInfo.ignoredInserts[o]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const o=this.blockReferencesCache[e.block];o.referenceCount++}r.name=e.type+"<"+s.name+">",r.userData.entityType=e.type;const a=e.insertionPoint;return U.set(0,0,0),a&&U.set(a.x,a.y,0),N.shouldRebasePositionOnRTC(U)&&this.setRTCUserData(r),r.matrix.setPosition(U),r}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const n=i.objects.IMAGEDEF.filter(y=>y.handle===e.imageDefHandle)[0];if(!n)return;const r=e.imageSize.x,a=e.imageSize.y,o=new V;let l=!1;e.flags===hn.ShowImageWhenNotAlignedWithScreen||e.flags===hn.UseClippingBoundary||e.flags===hn.TransparencyIsOn||(l=!0);const h=new p.PlaneGeometry(r,a);if(l){const y=new p.TextureLoader(this.manager).load(n.filename,void 0,void 0,()=>{console.warn("Please upload the pictures in the same folder, or use url link in the dxf file.")});y.colorSpace=p.SRGBColorSpace;const C=new p.MeshBasicMaterial({transparent:!0,side:p.FrontSide,map:y}),w=new V(G.Mesh);w.geometry=h,w.material=C,o.add(w)}const d=new p.EdgesGeometry(h),u=this.getColor(e,i,s),f=new V(G.Line);f.geometry=d,f.material=this.getLineBasicMaterial(u);const m=e.uPixel?new p.Vector3(e.uPixel.x,e.uPixel.y,e.uPixel.z):new p.Vector3(n.pixelSize.x,0,0),b=e.vPixel?new p.Vector3(e.vPixel.x,e.vPixel.y,e.vPixel.z):new p.Vector3(n.pixelSize.y,0,0);if(o.add(f),K.set(m.x,b.y,1),U.set(0,0,0),e.position){const y=new p.Vector3(e.position.x,e.position.y,e.position.z);y.add(m.multiplyScalar(r/2)).add(b.multiplyScalar(a/2)),U.copy(y)}return N.shouldRebasePositionOnRTC(U)&&this.setRTCUserData(o),ge.identity(),o.matrix.compose(U,ge,K),o}loadInsert(e,i,s,n=!1){if(!e||!e.block)return;const r=i.blocks[e.block];if(!r||!r.entities)return;s&&e.layer==="0"&&(e.layer=s.layer),e.blockPosition=r.position;const a=new V,o=e.zdysx;let l;if(o)try{l=JSON.parse(o)}catch{l=o}for(let m=0;m<r.entities.length;m++){if(r.entities[m].type==="ATTDEF")continue;const b=this.loadEntity(r.entities[m],i,e,n);b&&(o&&H.LOADLLDATA&&(b.userData.llbData=o),l!==void 0&&b.traverse(y=>{y.geometry&&(y.userData.xdata=l)}),a.add(b))}if(a.children.length===0){const m=e.name||e.block;return!this.statsInfo.ignoredInserts[m]&&(this.statsInfo.ignoredInserts[m]=0),this.statsInfo.ignoredInserts[m]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const m=this.blockReferencesCache[e.block];m.referenceCount++}a.name=e.type+"<"+r.name+">",a.userData.entityType=e.type,l!==void 0&&(a.userData.xdata=l),e.extendedData?.originalType&&(a.userData.originalType=e.extendedData?.originalType),e?.blockPosition&&a.matrix.setPosition(-e.blockPosition.x,-e.blockPosition.y,0);const h=U.set(1,1,1);e.xScale&&(h.x=e.xScale),e.yScale&&(h.y=e.yScale);const d=new p.Euler;e.rotation&&(d.z=e.rotation*Math.PI/180),ge.setFromEuler(d,!1);const u=K.set(0,0,0);e.position&&(u.x=e.position.x,u.y=e.position.y),de.compose(u,ge,h),e.extrusionDirection&&e.extrusionDirection.z<0&&de.premultiply(Va.identity().makeScale(-1,1,1)),tt.copy(a.matrix),a.matrix.premultiply(de),K.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),N.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(a);const f=this.findSpatialFilterByHandle(e.handle,i);if(f){this.loadSpatialFilter(f);const m=f;m&&m.clipPolylines&&m.clipPolylines.length>0&&(a.userData.spatialFilterHandle=f.handle,this.cloneMaterialsForSpatialFilter(a),P.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;de.set(s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],0,0,0,1);const n=[];e.vertices.forEach(o=>{n.push(new p.Vector3(o.x,o.y,0))});const r={polyline:[],bConcave:!1,bReversed:!1};if(e.numberOfPointsOnClipBoundary===2)r.polyline=n;else{const o=e.numberOfPointsOnClipBoundary,l=3;if(o<l)return P.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let h=[],d=-1;for(let m=0;m<o;m++){const b=n[m];for(let y=o-1;y>m;y--){const C=n[y];if(z.areVector3sEqual(b,C)&&m+1<y-1&&m+1<o-1&&z.areVector3sEqual(n[m+1],n[y-1])){h.push(b),d=y;break}}if(d>0)break;h.push(b)}if(d>0)for(let m=d+1;m<o;m++)h.push(n[m]);if(h.length<l)return P.warn("[Dxf] Invalid clipBoundary: "+e.handle+"!"),void 0;const u=[],f=[];if(h.forEach(m=>{u.push(new p.Vector2(m.x,m.y)),f.push([m.x,m.y])}),!N.isConvex(u)){P.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const m=zl(f,1/0);h=[],m.forEach(b=>{h.push(new p.Vector3(b[0],b[1],0))})}!z.areVector3sEqual(h[0],h[h.length-1])&&h.push(h[0]),r.polyline=h,r.bReversed=d>0}let a;return this.enableReleaseData&&(e.vertices=[],e.matrix=[],e.invertBlockMatrix=[]),i.localMatrix=de.clone(),i.clipPolylines=[],i.clipPolylines.push(r),a}loadLayout(e,i,s,n,r,a){if(!e.entities)return;const o=new V;for(let d=0;d<e.entities.length;d++){const u=e.entities[d];this.addViewport(u,a);const f=this.loadEntity(u,i);f&&(this.enableMerge&&Tt.merge(f,!1),o.add(f),f.traverse(m=>{if(m.geometry){const b=m.userData.layerName;let y=r[b];!y&&(y=[],r[b]=y),y.push(m),m.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[s.layoutName]&&(this.layoutsSnapObjectsMap[s.layoutName]=[]),this.layoutsSnapObjectsMap[s.layoutName].push(m))}}))}if(o.children.length===0)return;o.userData.layerName=e.layer;const l=s.layoutName;let h=n.children.find(d=>d.name===l);!h&&(h=new V,h.name=l,h.userData.isLayoutLevelObject=!0,n.add(h)),h.add(o),e.position&&o.matrix.setPosition(e.position.x,e.position.y,e.position.z||0)}convertEdgeToPoints(e){const i=[];if(!e)return i;switch(e.type){case Ci.Line:{const n=e;i.push(new p.Vector2(n.startPoint.x,n.startPoint.y)),i.push(new p.Vector2(n.endPoint.x,n.endPoint.y));break}case Ci.Arc:{const n=e;let r=n.startAngle*p.MathUtils.DEG2RAD,a=n.endAngle*p.MathUtils.DEG2RAD;!n.bCounterclockwise&&(r=Math.PI*2-r,a=Math.PI*2-a);const o=new p.ArcCurve(n.center.x,n.center.y,n.radius,r,a,!n.bCounterclockwise),l=this.getDivision(r,a,n.radius),h=o.getPoints(l);e.startPoint=h[0],e.endPoint=h[h.length-1],i.push(...h);break}case Ci.Ellipse:{const n=e,r=Math.sqrt(Math.pow(n.majorAxisEndPoint.x,2)+Math.pow(n.majorAxisEndPoint.y,2)),a=r*n.minorRatio,o=Math.atan2(n.majorAxisEndPoint.y,n.majorAxisEndPoint.x);let l=n.startAngle*p.MathUtils.DEG2RAD,h=n.endAngle*p.MathUtils.DEG2RAD;!n.bCounterclockwise&&(l=Math.PI*2-l,h=Math.PI*2-h);const d=new p.EllipseCurve(n.center.x,n.center.y,r,a,l,h,!n.bCounterclockwise,o),u=this.getDivision(l,h,Math.max(r,a)),f=d.getPoints(u);e.startPoint=f[0],e.endPoint=f[f.length-1],i.push(...f);break}case Ci.Spline:{const n=e,r=qa(n.controlPoints,n.degreeOfSplineCurve,n.knotValues);if(r.length===0)break;e.startPoint=r[0],e.endPoint=r[r.length-1],i.push(...r);break}case Ci.Polyline:{const n=e,r=Yn(n.points,n.isClosed);e.startPoint=r[0],e.endPoint=r[r.length-1],i.push(...r);break}}return i}loadHatch(e,i,s){const n=e;let r=[];function a(M,O){const{startPoint:S,endPoint:v}=M,{startPoint:T,endPoint:_}=O,A=v.x-S.x,I=v.y-S.y,B=_.x-T.x,k=_.y-T.y,L=A*k-I*B;if(Math.abs(L)<1e-10)return null;const F=S.x-T.x,ie=S.y-T.y,se=(B*ie-k*F)/L,Fe=(A*ie-I*F)/L;return se>=0&&se<=1&&Fe>=0&&Fe<=1?{x:S.x+se*A,y:S.y+se*I}:null}function o(M){const{edges:O}=M,S=[],v=O.length;if({...M},v!==4)return[M];for(let T=0;T<v;T++)for(let _=T+2;_<v;_++){if(_===T+1||T===0&&_===v-1)continue;const A=a(O[T],O[_]);A&&S.push({edgeIndex1:T,edgeIndex2:_,point:{x:A.x,y:A.y}})}if(S.length&&S.length===1){const T={pathTypeFlag:M.pathTypeFlag,edges:[O[S[0].edgeIndex1-1],{startPoint:{...O[S[0].edgeIndex1].startPoint},endPoint:{x:S[0].point.x,y:S[0].point.y},type:O[S[0].edgeIndex1].type},{startPoint:{x:S[0].point.x,y:S[0].point.y},endPoint:{x:O[S[0].edgeIndex2].startPoint.x,y:O[S[0].edgeIndex2].startPoint.y},type:O[S[0].edgeIndex2].type}]},_={pathTypeFlag:M.pathTypeFlag,edges:[{startPoint:{x:S[0].point.x-1e-5,y:S[0].point.y-1e-5},endPoint:{...O[S[0].edgeIndex1].endPoint},type:O[S[0].edgeIndex1].type},{...O[S[0].edgeIndex2-1]},{startPoint:O[S[0].edgeIndex2].startPoint,endPoint:{x:S[0].point.x-1e-5,y:S[0].point.y-1e-5},type:O[S[0].edgeIndex2].type}]};return[T,_]}return[M]}if(n.boundaryPaths.length==0)return;for(let M=0;M<n.boundaryPaths.length;M++){const O=n.boundaryPaths[M],S=o(O);r=[...r,...S]}if(n.boundaryPaths=r,!n.solidFill&&!n.patternLines?.length){P.warn("[Dxf] Hatch entity(handle: '"+n.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],h=[],d=[],u=M=>{const O=[];let S=[];S.push(...this.convertEdgeToPoints(M[0]));for(let v=1;v<M.length;v++){const T=this.convertEdgeToPoints(M[v]);if(S.push(...T),S.length>2){const _=this.convertEdgeToPoints(M[v-1]);z.areVector2sEqual(_[_.length-1],T[0])?z.areVector2sEqual(S[0],T[T.length-1],1e-5)&&(O.push(S),S=[]):z.areVector2sEqual(_[0],T[T.length-1])?z.areVector2sEqual(S[1],T[0],1e-5)&&(O.push(S),S=[]):S=[]}}return O};if(n.boundaryPaths.forEach((M,O)=>{let S=[];if(this.IsfilteredByPathTypeFlag(M.pathTypeFlag)){P.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",M.pathTypeFlag,O,n.handle);return}const v=M.edges;if(v.length===0)return;const T=[];for(let _=0;_<v.length;_++){const A=this.convertEdgeToPoints(v[_]);if(A.length<2){P.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",_,O,n.handle);continue}T.push(...A)}if(T.length<3){P.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",O,n.handle);return}if(S.push(T),M.pathTypeFlag>Ho.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const B=A[I-1].endPoint,k=A[I].startPoint;if(!B||!k||!z.areVector2sEqual(B,k))return!1}return!0})(M.edges)||!n.associativity)&&(S=u(v),S.length<2)){P.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",O,n.handle);return}S.forEach(_=>{!z.areVector2sEqual(_[0],_[_.length-1])&&_.push(_[0]);const A=_.map(I=>new p.Vector2(j.roundNumber(I.x,7),j.roundNumber(I.y,7)));if(A?.length>0){l.push(A);const I=new p.Box2().setFromPoints(A);h.push(I);const B=I.getSize(Ji),k=B.x*B.y;d.push({area:k,index:l.length-1})}})}),l.length===0)return;const f=new p.Vector2,m=this.checkAndRebasePolygonsOnRTC(l,f);d.sort((M,O)=>M.area-O.area);const b=[];d.forEach(M=>{b.push(M.index)});const y=this.buildContainHierarchyTree(l,h,b),C=[];this.buildHatchGeometry(l,y,C);let w;if(C.length>0&&(w=Pe.mergeGeometries(C)),!w||!w.getIndex()||w.getIndex()?.count===0)return P.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const x=new V(G.Mesh);x.geometry=w,x.material=gi,this.setHatchMaterial(x,n,i,f,s);const E=x;return m&&(this.setRTCUserData(E),E.matrix.setPosition(f.x,f.y,0)),E.traverse(M=>{M.layers.enableAll(),M.layers.disable(je)}),E}loadOle2frame(e,i){const{leftUpX:s,leftUpY:n,rightDownX:r,rightDownY:a}=e;if(!s||!n||!r||!a)return;const o=[new p.Vector2(s,n),new p.Vector2(s,a),new p.Vector2(r,a),new p.Vector2(r,n),new p.Vector2(s,n)],l=new p.Vector3;let h=!1;this.enableRTC&&(h=N.checkAndRebasePositionsOnRTC(o,l));const d=new p.BufferGeometry().setFromPoints(o),u=this.getLineBasicMaterial(16777215),f=new V(G.Line);f.geometry=d,f.material=u,f.layers.enableAll(),h&&(this.setRTCUserData(f),f.matrix.setPosition(l.x,l.y,0));const m=new V;m.add(f);let b;const y=i.objects.DICTIONARY;for(const w of y)for(const x in w.entries)if(w.entries[x]===e.handle){b=x;break}let C;if(b)if(this.meshTextureMaterials[b])C=this.meshTextureMaterials[b];else for(let w=0;w<i.objects.XRECORD.length;w++){const x=i.objects.XRECORD[w];if(x.handle===b){const E=x.binaryData,M=j.hexToBase64(E),O="data:image/jpg;base64,"+M,S=new p.TextureLoader(this.manager).load(O);S.colorSpace=p.SRGBColorSpace;const v=new p.MeshBasicMaterial({transparent:!0,map:S});this.meshTextureMaterials[b]=v,C=v;break}}if(C){const w=new p.Box2().setFromPoints(o),x=w.getSize(Ji),E=new p.PlaneGeometry(x.x,x.y),M=new V(G.Mesh);M.geometry=E,M.material=C;const O=w.getCenter(Ji);U.set(O.x,O.y,0),h&&(this.setRTCUserData(M),U.x+=l.x,U.y+=l.y),M.matrix.setPosition(U),M.layers.enableAll(),m.add(M)}return m.children.length>1?m:f}static getOcsMatrix(e){let i=qe,s=Wn,n=mi;const r=new p.Vector3(0,1,0),a=new p.Vector3(0,0,1);return z.areVectorsClose(e,a)?de.identity():(n=e.clone().normalize(),!z.areVectorsClose(n,a)&&(Math.abs(n.x)<1/64&&Math.abs(n.y)<1/64?i=r.cross(n).normalize():i=a.cross(n).normalize(),s=n.clone().cross(i).normalize()),de.set(i.x,i.y,i.z,0,s.x,s.y,s.z,0,n.x,n.y,n.z,0,0,0,0,1))}static getDcs2WcsMatrix(e,i){let s;C1(e)?s=e.viewDirectionFromTarget:s=e.viewDirection,s??(s={x:0,y:0,z:1});const n=e.viewTarget??{x:0,y:0,z:0},r=new p.Vector3(z.roundNumber(s.x,7),z.roundNumber(s.y,7),s.z),a=new p.Vector3(n.x,n.y,n.z),o=e.viewTwistAngle||0;let l,h,d;d=r.clone().normalize(),l=mi.clone().cross(r),l.length()>0?(l.normalize(),h=d.clone().cross(l)):d.z<0?(l=qe.clone().negate(),h=Wn,d=mi.clone().negate()):(l=qe,h=Wn,d=mi);const u=new p.Matrix4,f=de.identity();return f.makeBasis(l,h,d),u.premultiply(f),u.premultiply(de.identity().compose(a.clone(),new p.Quaternion().setFromAxisAngle(new p.Vector3(0,0,1),p.MathUtils.degToRad(i?o:-o)),new p.Vector3(1,1,1))),u}getViewportMsToPsMatrix(e){const i=e.centerPoint_dcs??{x:0,y:0},s=e.centerPoint??{x:0,y:0,z:0},n=new p.Vector3(i.x,i.y,0),r=new p.Vector3(s.x,s.y,s.z),a=e.viewHeight,o=e.height_paperSpace||1,l=(a||o)/o,h=H.getDcs2WcsMatrix(e,this.angDir),d=new p.Matrix4;d.setPosition(Fa.clone().sub(r));const u=Va.identity();u.scale(U.set(l,l,l));const f=tt.identity().setPosition(Fa.clone().sub(r));u.premultiply(f.clone().invert()).multiply(f),d.multiply(u);const m=de.identity();m.setPosition(n),h.multiply(m);const b=de.identity();return d.invert().multiply(b).multiply(h.invert())}loadViewport(e,i,s){if(e.viewportId+""=="1"){e.psBBox=new p.Box3,e.msToPsMatrix=new p.Matrix4;return}const n=e.centerPoint;if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y)){e.psBBox=new p.Box3,e.msToPsMatrix=new p.Matrix4;return}const r=e.width_paperSpace/2,a=e.height_paperSpace/2,o=[new p.Vector3(n.x-r,n.y-a,0),new p.Vector3(n.x-r,n.y+a,0),new p.Vector3(n.x+r,n.y+a,0),new p.Vector3(n.x+r,n.y-a,0)];o.push(o[0]),e.psBBox=new p.Box3().setFromPoints([o[0],o[2]]),e.msToPsMatrix=this.getViewportMsToPsMatrix(e);let l=!1;const h=new p.Vector3;this.enableRTC&&(l=N.checkAndRebasePositionsOnRTC(o,h));const d=new p.BufferGeometry().setFromPoints(o),u=new V(G.Line);u.geometry=d,u.material=me,u.userData.entityType=e.type,u.layers.enableAll(),l&&(this.setRTCUserData(u),u.matrix.setPosition(h.x,h.y,0));const f=e.psBBox.clone();f.applyMatrix4(e.msToPsMatrix.clone().invert()),f.min.z=0,f.max.z=0;const m=[f.min,new p.Vector3(f.min.x,f.max.y,0),f.max,new p.Vector3(f.max.x,f.min.y,0)];m.push(m[0]);let b=!1;const y=new p.Vector3;this.enableRTC&&(b=N.checkAndRebasePositionsOnRTC(m,y));const C=new p.BufferGeometry().setFromPoints(m),w=new V(G.Line);w.geometry=C,w.material=me,w.userData.entityType=e.type,w.userData.inPaperSpace=[],w.layers.enableAll(),b&&(this.setRTCUserData(w),w.matrix.setPosition(y.x,y.y,0));const x=new V;return x.add(u),x.add(w),u}getColor(e,i,s){if(this.compareContext)return at.ENTITY_COLOR_NO_CHANGE;if(this.overrideColor!=null)return this.overrideColor;const n=e;if(n&&n.isGradientColor){const r=n.gradientColors;if(r&&r.length>=2){if(r[0]!==r[1]){const a="[Dxf] Gradient colors are not supported for hatch '"+e.handle+"', will use the first color!";P.warn(a)}return r[0]}}if(e.isTrueColor||e.colorIndex>0&&e.colorIndex<256)return e.color;if(e.colorIndex===0)return s?this.getColor(s,i):i.tables?.layer?.layers[0].color;if(e.colorIndex===256){const r=i.tables?.layer?.layers,a=r&&r[e.layer],o=r&&s&&r[s.layer];let l=Rt;return a&&a.name!=="0"?l=a.color:o?l=o.color:a?l=a.color:r&&r[0].color&&(l=r[0].color),l}return P.warn("[Dxf] Unknown colorIndex"),Rt}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Br&&e.lineType!==gs)return e.lineType;if(e.lineType===gs)return s?this.getLineType(s,i):e.lineType;const n=i.tables?.layer?.layers,r=T1;if(e.layer!=="0"){const a=n&&n[e.layer];if(a)return a.lineType}else if(s){const a=n&&n[s.layer];if(a)return a.lineType}return r}getLayerName(e,i,s){const n=h=>{r&&h&&!r[e.layer]&&(console.warn("[Dxf] Failed to find layer object for '"+h+"', adding a default one."),r[h]={name:h,handle:"",colorIndex:256,lineType:"",visible:!0})},r=i.tables?.layer?.layers;n(e.layer);const a=r&&r[e.layer];n(s?.layer);const o=r&&s&&r[s.layer];let l=a?.name||"";return a&&a.name==="0"&&o&&(l=o.name),l}setMaterial(e,i,s,n){const r=e;if(!r.geometry||(this.setRenderOrderByObjectType(e),i.type==="OLE2FRAME"))return;if(i.type==="MTEXT"){e.renderOrder=Oe.Text;return}if(i.type==="HATCH"){Ji.set(0,0),this.setHatchMaterial(e,i,s,Ji,n);return}if(i.type==="IMAGE")return;let a;const o=this.getColor(i,s,n);if(i.type==="LWPOLYLINE"&&(r.isMesh?(a=this.getMeshBasicMaterial(o),e.renderOrder=Oe.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=Oe.LineWithPattern),a)){r.material=a;return}if(i.type==="SOLID")a=this.getMeshBasicMaterial(o);else if(i.type==="TEXT"||i.type==="ATTDEF"||i.type==="ATTRIB")a=this.getLineBasicMaterial(o),e.renderOrder=Oe.Text;else if(i.type==="LEADER"||i.type==="MULTILEADER"||i.type==="VIEWPORT")a=this.getLineBasicMaterial(o);else if(i.type==="POINT")a=this.getPointsMaterial(o);else{if(e.material instanceof p.PointsMaterial){a=this.getPointsMaterial(o),r.material=a;return}const l=s.tables?.lineType?.lineTypes,h=l&&l[this.getLineType(i,s,n)];if(h&&h.pattern&&h.pattern.length!==0){const d=i.lineTypeScale||1;a=this.getLineShaderMaterial(h,o,d),e.renderOrder=Oe.LineWithPattern}else a=this.getLineBasicMaterial(o)}r.material=a}setHatchMaterial(e,i,s,n,r){const a=e;if(!a.geometry)return;const o=this.getColor(i,s,r);if(a.type===G.Line||a.type===G.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=Oe.Mesh,h;if(i.solidFill)h=this.getMeshBasicMaterial(o);else{if(a.material instanceof p.ShaderMaterial){h=a.material;const d=new p.Color(o);!a.material.uniforms.u_color.value.equals(d)&&(h=a.material.clone(),H.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o))}else h=this.getHatchShaderMaterial(i,o,n);l=Oe.MeshWithPattern}!h&&(h=this.getMeshBasicMaterial(o),l=Oe.Mesh),a.material=h,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=Oe.Mesh:i.isLine?s=Oe.Line:i.isPoints&&(s=Oe.Point),e.renderOrder=s}getPointsMaterial(e){return!this.pointsMaterials[e]&&(this.pointsMaterials[e]=new p.PointsMaterial({size:.2,color:e})),this.pointsMaterials[e]}getLineBasicMaterial(e){return!this.lineBasicMaterials[e]&&(this.lineBasicMaterials[e]=new p.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,i,s){const n=e.name+"_"+i+"_"+s;if(!this.lineShaderMaterials[n]){const r=this.getLineTypeScales(),a=r.ltScale*r.celtScale*s;this.lineShaderMaterials[n]=Vo.createLineShaderMaterial(e.pattern,i,a,H.ViewportScaleUniform,H.CameraZoomUniform)}return this.lineShaderMaterials[n]}getMeshBasicMaterial(e){return!this.meshBasicMaterials[e]&&(this.meshBasicMaterials[e]=new p.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getHatchShaderMaterial(e,i,s){if(!e.patternLines||e.patternLines.length<1)return;const n=this.findMatchedHatchShaderMaterial(e,i);if(n)return n;const r=.005,a=.05;let o=2;e.patternLines.forEach(f=>{o=Math.max(f.dashPattern.length,o)});let l=0;const h=[],d=new p.Vector2;for(const f of e.patternLines){const m=new p.Vector2(f.origin.x,f.origin.y).sub(s).rotateAround(d,-p.MathUtils.degToRad(e.patternAngle)),b=new p.Vector2(f.delta.x,f.delta.y).rotateAround(d,-p.MathUtils.degToRad(f.angle));if(b.y===0)return P.warn("[Dxf] delta.y is equal to zero !"),void 0;const y=f.dashPattern.length;let C=!0,w=0;for(let v=0;v<y;++v){const T=f.dashPattern[v];T>0&&(C=!1),w+=Math.abs(T)}const x=C?a:r,E=[],M=[];let O=0;M[0]=O;for(let v=0;v<y;++v)E[v]=f.dashPattern[v],E[v]===0&&(E[v]=x*w),O+=Math.abs(E[v]),M[v+1]=O;for(let v=y;v<o;++v)E[v]=0;for(let v=M.length;v<o+1;++v)M[v]=O;const S={origin:m,delta:b,angle:f.angle-e.patternAngle,pattern:E,patternSum:M,patternLength:O};if(l+=4,l+=o,l+=o+1,l>H.MaxFragmentUniforms){P.warn("[Dxf] There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}h.push(S)}const u=jo(h,e.patternAngle,H.CameraZoomUniform,new p.Color(i),this.overrideHatchPatternLineThickness);return u.defines={MAX_PATTERN_SEGMENT_COUNT:o},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:i,material:u}),u}getDivision(e,i,s){let n=Math.round(5e4/this.entityCount);n=Math.max(n,2),n=Math.min(n,10);const r=n*5;let o=n*2;if(this.averageCurveSize){const d=Math.pow(s/this.averageCurveSize,.5);o*=d,o=Math.max(o,n),o=Math.min(o,r)}let l=i-e;l<0&&(l+=Math.PI*2),o=Math.ceil(o*(l/Math.PI));let h=8;return l<.087?h=2:l<.174?h=3:l<.52?h=4:l<1.57?h=5:l<3.14?h=6:l<4.71&&(h=7),o=Math.max(o,h),this.averageCurveSize=(this.averageCurveSize*this.curveCount+s)/(this.curveCount+1),this.curveCount++,Math.max(o,12)}getBSplineInterpolationsPerSplineSegment(e,i){let s=1;this.averageCurveSize&&(s=Math.pow(i/this.averageCurveSize,.5),s=Math.max(s,.5),s=Math.min(s,2)),this.averageCurveSize=(this.averageCurveSize*this.curveCount+i)/(this.curveCount+1),this.curveCount++;let n=e*2*s;if(e>20){const r=Math.log10(e);n/=r}return n}async setDxfDataToIndexedDb(e,i){const s={dxfDataId:e,dxf:i};return new Promise((n,r)=>{pn.instance().add(s,()=>{P.info("[Dxf] Saved '"+e+"' to indexedDb"),n()},a=>{r(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{pn.instance().query(e,n=>{n&&n.length>0&&i(n[0].dxf),i(void 0)},()=>s())})}buildContainHierarchyTree(e,i,s){const n=new Map,r=s.length;for(let o=0;o<r;o++)n.set(s[o],{index:s[o],children:[]});const a={index:-1,children:[]};for(let o=0;o<r;o++){const l=s[o],h=e[l],d=i[l];let u=o+1;for(;u<r;u++){const f=s[u],m=e[f];if(i[f].containsBox(d)&&N.isPointInPolygon(h[j.generateRandomInt(0,h.length-1)],m)){n.get(f)?.children.push(n.get(l));break}}u===r&&a.children.push(n.get(l))}return a}buildHatchGeometry(e,i,s){if(i.children.length===0)return;const n=[],r=new Map;i.children.forEach(l=>{l.children.length===0?n.push(l.index):r.set(l.index,l.children.map(h=>h.index))});const a=l=>{try{const h=new p.ShapeGeometry(l);h.hasAttribute("uv")&&h.deleteAttribute("uv"),h.hasAttribute("normal")&&h.deleteAttribute("normal"),s.push(h)}catch{P.warn("[Dxf] triangulate shape error: "+l.getPoints().map(d=>d.toArray()).toString())}};n.forEach(l=>{const h=e[l];if(h.length===0)return;const d=new p.Shape(h);a(d)});const o=l=>l.map(h=>h.toArray());for(const l of r){const h=new p.Shape(e[l[0]]);let d={regions:[],inverted:!1};const u=this.findIntersectHole(e,l[1]);u.forEach(m=>{let b={regions:[],inverted:!1};try{m.forEach((y,C)=>{if(Xt.epsilon(z.getVector2RelativeEps(e[y][0]),1e-6),C===0)b=Xt.segments({regions:[o(e[y])],inverted:!1});else{const w=Xt.segments({regions:[o(e[y])],inverted:!1}),x=Xt.combine(b,w);d=Xt.polygon(Xt.selectUnion(x)),d.regions.length>0?d.regions.forEach(E=>{if(E.length===0)return;const M=E.map(O=>new p.Vector2(O[0],O[1]));h.holes.push(new p.Path(M))}):P.warn("[Dxf] mergedHoles.regions is empty")}})}catch(y){P.warn("[Dxf] polybooljs has error: "+y+", epsilon is "+Xt.epsilon())}});const f=u.flat(2);for(let m=0;m<l[1].length;m++){const b=l[1][m];!f.includes(b)&&h.holes.push(new p.Path(e[b]))}a(h)}i.children.forEach(l=>{l.children.forEach(h=>{this.buildHatchGeometry(e,h,s)})})}findIntersectHole(e,i){const s=i.length,n=[];for(let r=0;r<s;r++){const a=e[i[r]];let o=!1;const l=[];for(let h=r+1;h<s;h++){const d=e[i[h]];N.arePolygonsIntersect(a,d)&&(o=!0,l.push(i[h]))}o&&(l.push(i[r]),n.push(l))}return n}checkAndRebasePolygonsOnRTC(e,i){if(!this.enableRTC||e.length===0)return!1;let s=0;e.forEach(r=>{r.forEach(a=>{i.add(a),s++})}),i.divideScalar(s);let n=!1;if(this.enableRTC&&N.shouldRebasePositionOnRTC(i)){n=!0;for(let r=0;r<e.length;r++){const a=e[r];for(let o=0;o<a.length;o++){const l=a[o].x-i.x,h=a[o].y-i.y;a[o]=new p.Vector2(l,h)}}}else i.set(0,0);return n}setRTCUserData(e){e.userData.relativeToCenter=!0,this.statsInfo.rebasedEntityCount++}IsfilteredByPathTypeFlag(e){return e<0}findSpatialFilterByHandle(e,i){const s=i.objects.DICTIONARY;if(!s)return;if(!this.dictionaryOwnerHandleAndSpatialFilterHandlesCache){this.dictionaryOwnerHandleAndSpatialFilterHandlesCache={};for(const r of s){const a=r;let o="";for(const l in a.entries)if(a.entries[l]==="ACAD_FILTER"){o=l;break}o&&(this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[r.ownerHandle]&&P.warn("[Dxf] Why this.dictionaryObjectsCache[obj.ownerHandle] already exist?",r.ownerHandle),this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[r.ownerHandle]=o)}}const n=this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[e];if(n){if(!this.spatialFiltersCache){this.spatialFiltersCache={};const r=i.objects.SPATIAL_FILTER||[];for(const a of r){const o=a;o.numberOfPointsOnClipBoundary<2||(this.spatialFiltersCache[o.ownerHandle]&&P.warn("[Dxf] Why this.spatialFiltersCache[spatialFilterObj.ownerHandle] already exist?",n),this.spatialFiltersCache[o.ownerHandle]=o)}}return this.spatialFiltersCache[n]}}initRenderOrderInfo(e){const i=new Set,s=e.objects.DICTIONARY;for(const r of s){const a=r;Object.keys(a.entries).forEach(o=>{a.entries[o]&&a.entries[o]==="ACAD_SORTENTS"&&i.add(o)})}if(i.size===0)return;const n=e.objects.SORTENTSTABLE;if(n)for(let r=0;r<n.length;++r){const a=n[r];if(i.has(a.handle)){for(let o=0;o<a.sortEntsObject.entityHandles.length;++o){const l=a.sortEntsObject.entityHandles[o];l.length===2&&!this.entityHandlesWithRenderOrder[l[0]]?this.entityHandlesWithRenderOrder[l[0]]=l[1]:P.warn("[Dxf] Failed to handle sortEntsTable: "+a.handle+".")}break}}}findMatchedHatchShaderMaterial(e,i){const s=e.patternLines;if(!s||s.length<1)return;const n=(h,d)=>Math.abs(h-d)<1e-5,r=(h,d)=>{if(h.length!==d.length)return!1;for(let u=0;u<h.length;++u)if(!n(h[u],d[u]))return!1;return!0},a=(h,d)=>n(h.angle,d.angle)&&n(h.delta.x,d.delta.x)&&n(h.delta.y,d.delta.y)&&n(h.origin.x,d.origin.x)&&n(h.origin.y,d.origin.y)&&r(h.dashPattern,d.dashPattern),o=(h,d)=>{if(h.length!==d.length)return!1;for(let u=0;u<h.length;++u)if(!a(h[u],d[u]))return!1;return!0};return this.hatchShaderMaterials.find(h=>h.color===i&&h.patternAngle===e.patternAngle&&o(h.patternLines,s))?.material}getLayout(e,i){if(!this.blockRecordsCache){this.blockRecordsCache={};const r=this.blockRecordsCache,a=e.tables?.blockRecord?.blockRecords;a&&Object.values(a).forEach(o=>{r[o.handle]=o.layoutHandle})}const s=this.blockRecordsCache[i.ownerHandle];if(s){const r=e.objects.LAYOUT,a=r.find(o=>o.handle===s);if(a)return a}if(!this.entitiesCache){this.entitiesCache={};const r=this.entitiesCache;Object.values(e.entities).forEach(a=>{r[a.handle]=a})}const n=this.entitiesCache[i.ownerHandle];return n?this.getLayout(e,n):e.objects.LAYOUT.find(r=>r.layoutName===H.MODEL_LAYOUT_NAME)}getLayerVisible(e,i){const s=e.tables?.layer?.layers;return s&&s[i]?.visible}getLayerFrozen(e,i){const s=e.tables?.layer?.layers;return s&&s[i.layer]?.frozen}cloneMaterialsForSpatialFilter(e){const i=new Map,s=n=>{let r;if(Array.isArray(n)){const a=[];r=a,n.forEach(o=>{if(i.has(o.id))a.push(i.get(o.id));else{const l=o.clone();H.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else n&&(i.has(n.id)?r=i.get(n.id):(r=n.clone(),H.updateMaterialUniforms(r),i.set(n.id,r)));return r};e.traverse(n=>{n.material&&(n.material=s(n.material))})}getLineTypeScales(){const e={ltScale:1,celtScale:1};return this.header&&(e.ltScale=this.header.$LTSCALE||1,e.celtScale=this.header.$CELTSCALE||1),e}static getDxfUnits(e){switch(e||0){case 0:return Ke.Unitless;case 1:return Ke.Inches;case 2:return Ke.Feet;case 4:return Ke.Millimeters;case 5:return Ke.Centimeters;case 6:return Ke.Meters;default:P.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return Ke.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const n=e.matrixWorld;if(s.index&&(P.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=N.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){P.debug("[Dxf] This line has been merged!");let r=0;e.userData.batches.forEach(a=>{a.positionStart=r,a.positionCount=a.indexCount,a.indexStart=0,a.indexCount=0,r+=a.positionCount})}if(s.index===null){const r=s.attributes.position;if(!r||r.count===0)return;const a=[];if(i)for(let o=0,l=r.count;o<l;o+=2)U.fromBufferAttribute(r,o).applyMatrix4(n),K.fromBufferAttribute(r,o+1).applyMatrix4(n),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+U.distanceTo(K);else{a[0]=0;for(let o=1,l=r.count;o<l;o++)U.fromBufferAttribute(r,o-1).applyMatrix4(n),K.fromBufferAttribute(r,o).applyMatrix4(n),a[o]=a[o-1],a[o]+=U.distanceTo(K)}s.setAttribute("lineDistance",new p.Float32BufferAttribute(a,1)),e.geometry=s}else P.warn("[Dxf] computeLineDistances only possible with non-indexed BufferGeometry.")}static computeLineDistances(e){const i=Date.now();e.traverse(s=>{const n=s;n.isLine&&n.material instanceof p.ShaderMaterial&&H.computeLineDistance(n)}),P.debug("[Dxf] Computed line distances in "+(Date.now()-i)/1e3+"s")}static mergeDxfObjects(e){const i=Date.now(),s={},n={},r=15e3;let a=0,o=0;const l=()=>{const d=Date.now();for(const u in s){const f=s[u];H.removeEmptyObjectsFromRemovingMarkedObjects2(f.children,f.object),f.children=[]}a=0,o+=Date.now()-d};for(const d in e.layersAndObjects){const u=e.layersAndObjects[d];if(u.length<=1)continue;const f=Date.now(),m={},b=[];for(const y of u){if(y.userData.isSnapObject){b.push(y);continue}let C,w=y;for(;w;){if(w.userData.isLayoutLevelObject){C=w;break}w=w.parent}if(!C)continue;const x=C.name;!m[x]&&(m[x]={object:C,children:[]}),m[x].children.push(y)}for(const y in m){const C=m[y],w=Tt.deepMerge(C.children,C.object,!1,!1,!0),x=w.added,E=w.removed;!s[y]&&(s[y]={object:C.object,children:[]}),!n[y]&&(n[y]={object:C.object,children:[]});const M=E.length>r;if(M){const O=Date.now();H.removeEmptyObjectsFromRemovingMarkedObjects2(E,C.object),o+=Date.now()-O}else a+=E.length;if(E.length===C.children.length)!M&&E.forEach(O=>{s[y].children.push(O)});else{let O=E;E.length>=100&&(O=new Set(E));const S=v=>Array.isArray(O)?O.indexOf(v)>=0:O.has(v);for(let v=0;v<C.children.length;v++){const T=C.children[v];S(T)?!M&&s[y].children.push(T):b.push(T)}}for(let O=0;O<x.length;O++){const S=x[O];b.push(S),n[y].children.push(S)}a>r&&l()}e.layersAndObjects[d]=b,P.debug("[Dxf] Merged layer '"+d+"' in "+(Date.now()-f)/1e3+"s")}a>0&&l();for(const d in n){const u=n[d];!e.root.children.find(m=>m.name===d)&&e.root.add(u.object),u.children.forEach(m=>{u.object.add(m)}),u.children=[]}P.debug("[Dxf] MergeUtils.deepMerge took "+fe.MergeInfo.elapsedTime/1e3+"s"),P.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),P.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const h=fe.MergeInfo;P.debug("[Dxf] Totally merged "+h.removedObjects+" objects to "+h.mergedMeshes+"meshes, "+h.mergedLines+"lines, "+h.mergedPoints+"points, "+(h.mergedUnknownTypeObjects?h.mergedUnknownTypeObjects+" unknown type,":" ")+" ")}static async merge(e,i){const s=j.getUpdateProgressFuncAsync(i),n={};e.objects.LAYOUT.forEach(y=>{const C=y;n[C.layoutName]=C,C.directAssociatedLeafObjectSet?.clear()});const r=Date.now(),a={},o={},l=15e3;let h=0,d=0;const u=()=>{const y=Date.now();for(const C in a){const w=a[C];H.removeEmptyObjectsFromRemovingMarkedObjects(w.children,w.object),w.children=[]}h=0,d+=Date.now()-y},f=Object.keys(e.layersAndThreejsObjects).length;let m=0;for(const y in e.layersAndThreejsObjects){const C=e.layersAndThreejsObjects[y];if(C.length<=1){await s(++m/f*100);continue}const w=Date.now(),x={},E=[];for(const S of C){if(S.userData.isSnapObject){E.push(S);continue}let v,T=S;for(;T;){if(T.userData.isLayoutLevelObject){v=T;break}T=T.parent}if(!v)continue;const _=v.name;!x[_]&&(x[_]={object:v,children:[]}),x[_].children.push(S)}const M=Object.keys(x).length;let O=0;for(const S in x){let v;if(S!==H.MODEL_LAYOUT_NAME){const k=n[S];!k.directAssociatedLeafObjectSet&&(k.directAssociatedLeafObjectSet=new Set),v=k.directAssociatedLeafObjectSet}const T=x[S],_=fe.deepMerge(T.children,T.object,!1,!1,!0),A=_.added,I=_.removed;!a[S]&&(a[S]={object:T.object,children:[]}),!o[S]&&(o[S]={object:T.object,children:[]});const B=I.length>l;if(B){const k=Date.now();H.removeEmptyObjectsFromRemovingMarkedObjects(I,T.object),d+=Date.now()-k}else h+=I.length;if(I.length===T.children.length)!B&&I.forEach(k=>{a[S].children.push(k)});else{let k=I;I.length>=100&&(k=new Set(I));const L=F=>Array.isArray(k)?k.indexOf(F)>=0:k.has(F);for(let F=0;F<T.children.length;F++){const ie=T.children[F];L(ie)?!B&&a[S].children.push(ie):(E.push(ie),v&&v.add(ie))}}for(let k=0;k<A.length;k++){const L=A[k];J.setSharedVariablesOfObject(L),E.push(L),o[S].children.push(L),v&&v.add(L)}h>l&&u(),await s((m+ ++O/M)/f*100)}await s(++m/f*100),e.layersAndThreejsObjects[y]=E,P.debug("[Dxf] Merged layer '"+y+"' in "+(Date.now()-w)/1e3+"s")}h>0&&u();for(const y in o){const C=o[y],w=e.threejsObject.children.find(x=>x.name===y);if(w){const x=w.children.find(E=>E.name===H.SNAP_GROUP_NAME);if(x&&y!==H.MODEL_LAYOUT_NAME){const E=n[y];!E.directAssociatedLeafObjectSet&&(E.directAssociatedLeafObjectSet=new Set),x.children.forEach(M=>E.directAssociatedLeafObjectSet?.add(M))}}!w&&e.threejsObject.add(C.object),C.children.forEach(x=>{!x.visible&&(x.userData.layerVisible=!1),C.object.add(x),x.updateWorldMatrix(!1,!1)}),C.children=[]}P.debug("[Dxf] MergeUtils.deepMerge took "+fe.MergeInfo.elapsedTime/1e3+"s"),P.debug("[Dxf] The remove operation of deep merge took "+d/1e3+"s"),P.debug("[Dxf] Deep merge totally took "+(Date.now()-r)/1e3+"s");const b=fe.MergeInfo;P.debug("[Dxf] Totally merged "+b.removedObjects+" objects to "+b.mergedMeshes+"meshes, "+b.mergedLines+"lines, "+b.mergedPoints+"points, "+(b.mergedUnknownTypeObjects?b.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const n in e)e[n].averageTime=e[n].totalTime/e[n].createCount;P.debug("[Dxf] Entity types and took how much time in ms:",e),P.debug("[Dxf] Entity types and mesh count:",this.statsInfo.entityTypesAndMeshCount);let i=0;if(Object.values(this.statsInfo.entityTypesAndMeshCount).forEach(n=>{i+=n}),this.enableRTC&&P.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const n=fe.MergeInfo;P.debug("[Dxf] Inner merged "+n.removedObjects+" objects to "+n.mergedMeshes+"meshes, "+n.mergedLines+"lines, "+n.mergedPoints+"points, "+(n.mergedUnknownTypeObjects?n.mergedUnknownTypeObjects+" unknown type,":" ")+"in "+n.elapsedTime/1e3+"s")}const s=(n,r,...a)=>{Object.keys(r).length>0};s("[Dxf] Unsupported entity types and count:",this.statsInfo.unsupportedEntityTypes),s("[Dxf] Unsupported text style names and count:",this.statsInfo.unsupportedTextStyles,". Will use a default style."),s("[Dxf] Unsupported hatch pattern names and count:",this.statsInfo.unsupportedHatchPatterns,". Filling in solid lines instead."),this.statsInfo.unsupportedPolylineCount&&P.warn("[Dxf] Unsupported polyline (with both width and linetype) count: "+this.statsInfo.unsupportedPolylineCount+", linetype will be ignored."),s("[Dxf] Ignored invisible entity types and count:",this.statsInfo.invisibleEntities),s("[Dxf] Ignored frozen layers and entity count:",this.statsInfo.ignoredFrozenLayersAndEntityCount),s("[Dxf] Ignored inserts and count (may because they don't contain anything):",this.statsInfo.ignoredInserts),this.ignorePaperSpace&&s("[Dxf] Ignored paper space entity count:",this.statsInfo.ignoredPaperSpaceEntityTypesAndCount),this.font&&s("[Dxf] Unsupported chars and count:",this.font.getUnsupportedChar())}static statLayoutAndLayerObjects(e){const i=new WeakSet;let s=0;for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&(s++,i.has(l)?console.warn(l):i.add(l))});const n=new WeakSet;let r=0;if(e.threejsObject.traverse(a=>{a.geometry&&(r++,n.has(a)?console.warn(a):n.add(a))}),s!=r)for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&!n.has(l)&&console.warn(l)});P.info("[Dxf] The count of layer objects is "+s+",The count of layout objects is "+r+" ")}static removeEmptyObjectsFromRemovingMarkedObjects(e,i){if(e.length===0)return;const s=n=>{const r=[];for(const a of n){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&r.push(o))}r.length>0&&s(r)};s(e),this.removeEmptyObjectsFromMark(i)}static removeEmptyObjectsFromMark(e){if(e.userData.validCount===0||J.isEmptyObject(e))return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark(e.children[i])&&++i;return!1}static removeEmptyObjectsFromRemovingMarkedObjects2(e,i){if(e.length===0)return;const s=n=>{const r=[];for(const a of n){a.userData.validCount=0;const o=a.parent;o&&o!==i&&(o.userData.validCount===void 0&&(o.userData.validCount=o.children.length),--o.userData.validCount===0&&r.push(o))}r.length>0&&s(r)};s(e),this.removeEmptyObjectsFromMark2(i)}static removeEmptyObjectsFromMark2(e){if(e.userData.validCount===0||e.type===G.Object&&e.children.length===0)return e.removeFromParent(),!0;for(let i=0;i<e.children.length;)!this.removeEmptyObjectsFromMark2(e.children[i])&&++i;return!1}};g(H,"MODEL_LAYOUT_NAME","Model"),g(H,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),g(H,"SHOW_SNAP_OBJECT",!1),g(H,"CameraZoomUniform",{value:1}),g(H,"ViewportScaleUniform",{value:1}),g(H,"TransformMatrixUniform",{value:new p.Matrix4}),g(H,"ResolutionUniform",{value:new p.Vector2}),g(H,"LOADLLDATA",!1),g(H,"MaxFragmentUniforms",1024);let X=H;class vr extends Nt{constructor(e){super();g(this,"viewer");g(this,"overlayRender");g(this,"drawableList");this.drawableList=new ws("compare"),this.viewer=e,this.overlayRender=this.viewer.getOverlayRender(),this.overlayRender?.addDrawableList(this.drawableList)}drawCompareDrawable(e){const i=[],s=[],n=[];for(const l of Object.values(e)){const h=l.box;h&&(l.type===Ve.Added?i.push(h):l.type===Ve.Removed?s.push(h):n.push(h))}const r=N.mergeBBoxes(i),a=N.mergeBBoxes(s),o=N.mergeBBoxes(n);this.drawableList.addDrawable(new wt(j.guid(),r,[.1,.9,.2,1])),this.drawableList.addDrawable(new wt(j.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new wt(j.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class vn{}const yi=new p.Matrix4,Xn=new p.Box3;class Ri extends vn{constructor(e){super();g(this,"modelId");g(this,"modelData");g(this,"modelObject");g(this,"bbox");this.modelData=e,this.modelId=e.modelId,this.modelObject=e.dxfData?.threejsObject||e.pdfData?.threejsObject,this.modelObject.name=this.modelId,this.modelObject.userData.modelId=this.modelId}get pdfData(){return this.modelData.pdfData}get dxfData(){return this.modelData.dxfData}get msTransformMatrix(){return this.modelData.msTransformMatrix}set msTransformMatrix(e){this.modelData.msTransformMatrix=e}get loadedEntityCount(){return this.dxfData?.loadedEntityCount||this.pdfData?.loadedEntityCount||0}get header(){return this.dxfData?.header}get viewports(){return this.dxfData?.tables.viewport.viewports}get layers(){const e=this.dxfData||this.pdfData;return e.tables?.layer.layers||e.layers}get layoutViewportsMap(){return this.dxfData?.layoutViewportsMap}getModelObject(){const e=this.dxfData||this.pdfData;if(!e)throw new Error("Failed to find model by modelId '"+this.modelId+"'!");return e.threejsObject}getBBox(){if(!this.bbox){const e=new p.Box3,i=this.getModelObject();e.setFromObject(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return Ke.Unitless;const e=this.dxfData.header;if(!e)return P.warn("DxfData or its header is undefined!"),Ke.Unitless;const i=e.$INSUNITS;return X.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new p.Vector3,s=new p.Vector3;if(!e){P.error("Header is undefined in "+this.modelId+"!");return}const n=this.viewports;let r=e.$EXTMIN,a=e.$EXTMAX;const o=e.$ANGDIR;if(n&&n.length>0)for(let l=0;l<n.length;l++){const h=n[l];if(h.name.toLocaleUpperCase()==="*ACTIVE"){const{center:d,viewHeight:u,aspectRatio:f}=h,m=u*f,b=X.getDcs2WcsMatrix(h,o),y=new p.Vector3(d.x,d.y,0);y.applyMatrix4(b),r={x:y.x-m/2,y:y.y-u/2,z:0},a={x:y.x+m/2,y:y.y+u/2,z:0};break}}return i.set(r.x,r.y,r.z),s.set(a.x,a.y,a.z),new p.Box3(i,s)}getLayer(e){if(this.layers)return this.layers[e]}getObjectsByLayer(e){const i=this.dxfData||this.pdfData;return i?.layersAndThreejsObjects&&i.layersAndThreejsObjects[e]}getLayouts(){const e=[];return this.dxfData?.objects.LAYOUT?.forEach(n=>{e.push(n)}),e}getLayoutByName(e){let i;const s=this.getLayouts();for(const n of s)if(n.layoutName===e){i=n;break}return i}getLayoutExtent(e){const i=this.header,s=new p.Vector3,n=new p.Vector3;if(!i)throw new Error("Header is undefined in "+this.modelId+"!");const r=this.getLayoutViewports(e);let a=i.$PEXTMIN,o=i.$PEXTMAX;const l=i.$ANGDIR;if(r&&r.length>0){const h=r.filter(C=>parseInt(C.viewportId)===1);let d;h.length>0?d=h[0]:d=r[0];const{centerPoint:u,width_paperSpace:f,height_paperSpace:m}=d,b=X.getDcs2WcsMatrix(d,l),y=new p.Vector3(u.x,u.y,0);y.applyMatrix4(b),a={x:y.x-f/2,y:y.y-m/2,z:0},o={x:y.x+f/2,y:y.y+m/2,z:0}}return s.set(a.x,a.y,a.z),n.set(o.x,o.y,o.z),new p.Box3(s,n)}getLayoutViewports(e){const s=this.layoutViewportsMap[e.ownerHandle];return s||[]}getLayoutLevelObject(e){return this.getModelObject()?.children.find(s=>s.name===e)}setVisible(e){const i=this.getModelObject();i.visible=e}setLayerVisible(e,i,s,n){const r=this.getLayer(e);r?r.visible=i:P.warn("[Viewer] Layer '"+e+"' not found from modelData!");const a=this.getObjectsByLayer(e);if(a)for(let o=0;o<a.length;o++){const l=a[o];!(s&&i&&n&&l.userData.visibleMinZoom&&n<l.userData.visibleMinZoom)&&(l.visible=i),(i===!1||l.userData.layerVisible!=null)&&(l.userData.layerVisible=i),l.userData.isSnapObject&&(l.visible?X.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(je):X.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(je))}else P.info("[Viewer] No object found for layer '"+e+"'")}setLayerOpacity(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const n=this.getObjectsByLayer(e);n?n.forEach(r=>{const a=r;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=xe.cloneMaterial(a.material));const o=xe.cloneMaterial(a.material);xe.setMaterialOpacity(o,i),X.updateMaterialUniforms(o),a.material=o}}):P.info("[Viewer] No object found for layer '"+e+"'")}setLayerColor(e,i){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const n=this.getObjectsByLayer(e);n?n.forEach(r=>{const a=r;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=xe.cloneMaterial(a.material));const o=xe.cloneMaterial(a.material);xe.setMaterialColor(o,new p.Color(i)),X.updateMaterialUniforms(o),a.material=o}}):P.info("[Viewer] No object found for layer '"+e+"'")}resetLayerColor(e){if(!this.getLayer(e))throw new Error("Failed to find layer by layerName '"+e+"'!");const s=this.getObjectsByLayer(e);s?s.forEach(n=>{const r=n;r.material&&r.userData.originalMaterial&&(r.material.dispose(),r.material=r.userData.originalMaterial,delete r.userData.originalMaterial)}):P.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(yi.identity(),!i||!j.isMatrixValid(i)||i.equals(yi))return;const s=this.getLayoutLevelObject(X.MODEL_LAYOUT_NAME);s&&(e===X.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=X.MODEL_LAYOUT_NAME,i){this.switchTransformMs(e);const s=this.getLayoutByName(e);if(s){if(!i){const n=this.getLayoutViewports(s);let r=[];n.length>0&&(r=n[0].frozenLayerHandles);const a=e!==X.MODEL_LAYOUT_NAME,o=this.getLayoutLevelObject(e);if(o){const d=[];o.traverse(u=>{this.addSpatialFilterSection(u,this.dxfData);const f=u;if(a&&f.material&&f.geometry){const m=f.userData.layerName;if(this.isLayerFrozenForViewport(m,r))return;d.push(f);let b=-1;const y=this.getObjectsByLayer(m);y&&(b=y.indexOf(f),b>=0&&y.splice(b,1)),b<0&&P.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+m+"', layout '"+e+"'")}}),d.forEach(u=>{u.removeFromParent()})}const l=this.getFilteredViewports(s);P.debug("[Viewer] Active layout:",e,", viewports:",l);const h=Date.now();l.forEach(d=>{this.generateObjectsByViewport(e,d,this)}),P.info("[Viewer] generateObjectsByViewport in "+(Date.now()-h)/1e3+"s")}this.showLayoutObjects(e)}}getFilteredViewports(e){const i=this.getLayoutViewports(e);let s=i.filter(n=>n.viewportId!=="1");return s.length===i.length&&(s=i.filter((n,r)=>r!==0)),s}generateObjectsByViewport(e,i,s,n=[]){const r=i;if(i.viewportId=="1")return;if(!r.psBBox||!r.msToPsMatrix)throw new Error("The bbox or matrix is invalid in the viewport!");X.TransformMatrixUniform={value:r.msToPsMatrix},X.ViewportScaleUniform={value:i.viewHeight/i.height_paperSpace};const a=r.psBBox.clone();a.applyMatrix4(r.msToPsMatrix.clone().invert()),a.min.setZ(-1),a.max.setZ(1);const o=this.getObjectsByBoundingBox(a);if(o.length===0)return;const l=r.psBBox.min,h=r.psBBox.max,d=new p.Box2(new p.Vector2(l.x,l.y),new p.Vector2(h.x,h.y)),u=zt.generateSectionPlanesByBox(d),f=[],m=T=>(!f[T.id]&&(f[T.id]=T.clone(),this.setMaterialUniforms(f[T.id],s.dxfData),zt.setMaterialSection(f[T.id],u)),f[T.id]),b=T=>{if(Array.isArray(T)){const _=[];return T.forEach(A=>{const I=m(A);_.push(I)}),_}else return m(T)},y=[...n,...i.frozenLayerHandles||[]];let C;if(e!==X.MODEL_LAYOUT_NAME){const T=r;!T.associatedLeafObjectSet&&(T.associatedLeafObjectSet=new Set),C=T.associatedLeafObjectSet}const w=new p.Group;w.name=r.viewportId;const x=[];if(o.forEach(T=>{const _=T.clone();_.traverse(A=>{const I=A;if(I.material&&I.geometry){const B=I.userData.layerName;if(this.isLayerFrozenForViewport(B,y)){x.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=b(I.material),C?.add(I);const k=s.getObjectsByLayer(B);k?k.push(I):P.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+B+"', layout '"+e+"'")}}),w.add(_)}),C&&C.size===0)return;const E=s.getModelObject();let M=s.getLayoutLevelObject(e);!M&&(M=new p.Group,J.setSharedVariablesOfObject(M),M.name=e,E?.add(M)),M.add(w),w.applyMatrix4(r.msToPsMatrix),w.updateMatrixWorld(!0);let O=M.children.find(T=>T.name===X.SNAP_GROUP_NAME);!O&&(O=new p.Group,O.visible=X.SHOW_SNAP_OBJECT,O.name=X.SNAP_GROUP_NAME,M.add(O));const S=s.getLayoutLevelObject(X.MODEL_LAYOUT_NAME),v=S?.children.find(T=>T.name===X.SNAP_GROUP_NAME);v&&v.traverse(T=>{if(!T.geometry)return;const _=T.userData.layerName;if(this.isLayerFrozenForViewport(_,y)||(Xn.makeEmpty(),Xn.expandByObject(T),!a.intersectsBox(Xn)))return;const A=T.clone();J.setSharedVariablesOfObject(A);let I=A.parent;const B=yi.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)B.premultiply(I.matrix),I=I.parent;B.premultiply(r.msToPsMatrix),A.applyMatrix4(B),O?.add(A),C?.add(A);const k=s.getObjectsByLayer(_);k&&k.push(A)}),x.length>0&&J.removeEmptyObjectsFromRemovingObjects(x,w),w.traverse(T=>{J.setSharedVariablesOfObject(T),this.addSpatialFilterSection(T,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=X.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=X.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return P.warn("[Viewer] bbox is empty !"),i;const s=r=>{const a=_t.getBoundingBox(r,!1);e.intersectsBox(a)&&i.push(r)},n=this.getLayoutLevelObject(X.MODEL_LAYOUT_NAME);return n&&n.children.forEach(r=>{r.name!==X.SNAP_GROUP_NAME&&s(r)}),i}showLayoutObjects(e){let i=0,s=0;const n=this.getModelObject();n.children.forEach(r=>{const a=r.name===e;r.visible=a,a?i++:s++}),P.debug("[Viewer] showLayoutObjects('"+e+"') sets "+i+" layout level object(s) to visible and "+s+" to hidden for model '"+n?.name+"'")}isLayerFrozenForViewport(e,i){const s=this.getLayer(e);return s&&(s.flag&1)>0?!0:!i||i.length<=0?!1:s&&i.indexOf(s.handle)>=0}addSpatialFilterSection(e,i,s=!1){if(e.userData.entityType!=="INSERT"||!e.userData.spatialFilterHandle)return;const n=this.findSpatialFilter(e.userData.spatialFilterHandle,i);if(n){let r=s,a=!1;const o=this.getAnyMaterial(e);if(o&&(o.clippingPlanes&&(r=o.clippingPlanes.length>0),a=o.clipIntersection),r&&a!==n.clipPolylines[0].bReversed){P.warn("[Viewer] Material cannot set clipIntersection to different values at the same time. clipIntersection needs to be set to true here!");return}a=n.clipPolylines[0].bReversed;const l=this.generateSectionsBySpatialFilter(n,e.matrixWorld);if(l){const h=f=>{let m=0;return f.clippingPlanes&&(m=f.clippingPlanes.length),m+l.length>X.MaxFragmentUniforms},d=new Set,u=f=>{d.has(f.id)||(d.add(f.id),!h(f)&&zt.setMaterialSection(f,l,r,a))};e.traverse(f=>{const m=f.material;Array.isArray(m)?m.forEach(b=>{u(b)}):m&&u(m)})}}}findSpatialFilter(e,i){const s=i.objects.SPATIAL_FILTER;if(!s)return;let n;for(const r of s)if(r.handle===e){n=r;break}return n}getAnyMaterial(e){const i=e;if(i.material)return Array.isArray(i.material)?i.material[0]:i.material;let s;for(let n=0;n<e.children.length&&(s=this.getAnyMaterial(e.children[n]),!s);n++);return s}generateSectionsBySpatialFilter(e,i){const s=e.clipPolylines[0];if(s.bConcave){P.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}yi.copy(i),e.localMatrix&&yi.multiply(e.localMatrix);const n=s.polyline,r=[];n.forEach(l=>{const h=l.clone().applyMatrix4(yi);r.push(new p.Vector2(h.x,h.y))});const a=p.ShapeUtils.isClockWise(r),o=!a&&!s.bReversed||a&&s.bReversed;return zt.generateSectionPlanesByPoints(r,o)}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}highlightObject(e){if(!this.hasObject(e))return;const i=xe.clonedHighlightMaterials(e,{depthTest:!1});i&&(e.userData.originalMaterial=e.material,e.material=i)}unHighlightObject(e){if(!this.hasObject(e))return;const i=e.material;e.material=e.userData.originalMaterial,delete e.userData.originalMaterial,Array.isArray(i)?i.forEach(s=>s.dispose()):i instanceof p.Material&&i.dispose()}clearHighlight(){}}class kr extends vn{constructor(e){super();g(this,"modelId");g(this,"bbox");g(this,"rootObject");g(this,"modelObject");g(this,"highlighUsage");g(this,"transparentUsage");g(this,"edges");g(this,"highlighedObject");this.modelId=e.modelId,this.bbox=e.bbox,this.modelObject=e.object,this.rootObject=new p.Group,this.rootObject.name="rootObject-"+this.modelId,this.rootObject.userData.modelId=this.modelId,this.highlighUsage=new p.Group,this.highlighUsage.name="highlighUsage-"+this.modelId,this.highlighUsage.layers.disable(Ut),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(Ut),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&J.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&J.revertDoubleSidedMaterialToObject(e)})}getModelObject(){return this.rootObject}getBBox(){return!this.bbox&&(this.bbox=new p.Box3,this.bbox.setFromObject(this.getModelObject())),this.bbox}async enableOutline(e,i){e&&!this.edges&&(this.edges=await J.createOutlines(this.getModelObject(),void 0,i)),this.edges&&this.edges.forEach(s=>s.visible=e)}setObjectColor(e,i){this.hasObject(e)&&e.material.color.set(i)}setObjectOpacity(e,i=.5,s,n){if(this.hasObject(e)){if(e instanceof p.InstancedMesh&&n){const r=this.createInstanceMeshById(e,n,{opacity:i});r.material.opacity*=i,e.userData.instanceId=n,e.userData.transparentedMesh=r,this.transparentUsage.add(r)}else if(fe.isMergedMesh(e)&&s){const r=this.createBatchMeshById(e,s,{opacity:i});r.material.opacity*=i,e.userData.batchId=s,e.userData.transparentedMesh=r,this.transparentUsage.add(r)}else{const r=new p.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});r&&(e.userData.originalMaterial=e.material,e.material=r)}e.userData.isTransparent=!0}}clearObjectOpacity(e,i,s){if(!this.isObjectTransparent(e))return;const{transparentedMesh:n,originalMaterial:r}=e.userData;n&&(this.transparentUsage.remove(n),delete e.userData.batchId,delete e.userData.instanceId,delete e.userData.transparentedMesh),r&&(e.material=r),delete e.userData.isTransparent}isObjectTransparent(e){const{isTransparent:i}=e.userData;return!!i}setOpacity(e=.5){this.getModelObject().traverse(i=>{i instanceof p.Mesh&&this.setObjectOpacity(i,e)})}clearOpacity(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&this.clearObjectOpacity(e)})}highlightObjectById(e,i,s){if(!this.hasObjectWithId(e))return;const n=this.getModelObject().getObjectById(e);n&&this.highlightObject(n,i,s)}highlightObject(e,i,s){if(!this.hasObject(e))return;const n=new p.Color(Pr);if(e instanceof p.InstancedMesh&&s){const r=this.createInstanceMeshById(e,s,{depthTest:!1});r.material.opacity=.7,xe.setMaterialColor(r.material,n),e.userData.instanceId=s,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else if(fe.isMergedMesh(e)&&i){const r=this.createBatchMeshById(e,i,{depthTest:!1});r.material.opacity=.7,xe.setMaterialColor(r.material,n),e.userData.batchId=i,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else{const r=xe.clonedHighlightMaterials(e,{depthTest:!1});r&&(e.userData.originalMaterial=e.material,e.material=r)}e.userData.isHighlight=!0,this.highlighedObject=e}clearHighlight(){if(this.highlighedObject&&this.highlighedObject.userData){const e=this.highlighedObject.userData,{clonedMesh:i,originalMaterial:s,instanceId:n,originalMatrix:r}=e;i&&(i.removeFromParent(),i.geometry.dispose(),delete e.clonedMesh),n&&r&&(this.highlighedObject.setMatrixAt(n,r),delete e.instanceId,delete e.originalMatrix),s&&(this.highlighedObject.material=s,delete e.originalMaterial),delete e.isHighlight}this.highlighUsage.clear(),this.highlighedObject=void 0}setObjectVisible(e,i){this.hasObject(e)&&(e.visible=i)}setVisible(e){this.getModelObject().traverse(i=>{i instanceof p.Mesh&&(i.visible=e)})}hasVisibleObject(){let e=0;return this.modelObject.traverseVisible(i=>{i instanceof p.Mesh&&e++}),e>0}hasInvisibleObject(){let e=0;return this.modelObject.traverse(i=>{i instanceof p.Mesh&&e++}),this.modelObject.traverseVisible(i=>{i instanceof p.Mesh&&e--}),e>0}createBatchMeshById(e,i,{opacity:s=1,depthTest:n=!0}){const r=fe.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+r?.name,r?.userData&&(a+=`
797
797
  userData: `+JSON.stringify(r.userData)),r?.parentUserData&&(a+=`
798
- parentUserData: `+JSON.stringify(r.parentUserData)),P.info(a);const o=xe.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!n&&(o.depthTest=n,o.depthWrite=n,o.side=p.DoubleSide);const l=fe.cloneGeometryForBatch(e,r),h=new p.Mesh(l,o);return h.applyMatrix4(e.matrixWorld),h.matrixWorldNeedsUpdate=!0,h.name="Cloned mesh for highlighting",h.layers.enableAll(),h}createInstanceMeshById(e,i,{opacity:s=1,depthTest:n=!0}){const r=e,a=new p.Matrix4,o=new p.Matrix4;o.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),r.getMatrixAt(i,a);const l=xe.cloneMaterial(r.material);l.opacity=s,l.transparent=s<1,!n&&(l.depthTest=n,l.depthWrite=n,l.side=p.DoubleSide);const h=new p.Mesh(r.geometry.clone(),l);h.applyMatrix4(e.matrixWorld.multiply(a)),h.matrixWorldNeedsUpdate=!0,h.name="Cloned mesh for highlighting",h.layers.enableAll();const d=a.clone();return d.multiplyMatrices(a,o),r.setMatrixAt(i,d),r.instanceMatrix.needsUpdate=!0,r.updateMatrix(),e.userData.originalMatrix=a,h}setClipPlanes(e){this.getModelObject().traverse(i=>{const s=i.material;s&&(Array.isArray(s)?s.forEach(n=>{n.clippingPlanes=e,n.clipIntersection=!1}):(s.clippingPlanes=e,s.clipIntersection=!1))})}getObjectTree(){}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}}class Ya extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesMaterial");g(this,"type");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");g(this,"defaultOutlineColor");g(this,"useBCOutline");g(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new p.Color(an[0],an[1],an[2]),this.useBCOutline=!1,this.outlineVisible=!0;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},outlineColor:{value:this.defaultOutlineColor}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
798
+ parentUserData: `+JSON.stringify(r.parentUserData)),P.info(a);const o=xe.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!n&&(o.depthTest=n,o.depthWrite=n,o.side=p.DoubleSide);const l=fe.cloneGeometryForBatch(e,r),h=new p.Mesh(l,o);return h.applyMatrix4(e.matrixWorld),h.matrixWorldNeedsUpdate=!0,h.name="Cloned mesh for highlighting",h.layers.enableAll(),h}createInstanceMeshById(e,i,{opacity:s=1,depthTest:n=!0}){const r=e,a=new p.Matrix4,o=new p.Matrix4;o.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),r.getMatrixAt(i,a);const l=xe.cloneMaterial(r.material);l.opacity=s,l.transparent=s<1,!n&&(l.depthTest=n,l.depthWrite=n,l.side=p.DoubleSide);const h=new p.Mesh(r.geometry.clone(),l);h.applyMatrix4(e.matrixWorld.multiply(a)),h.matrixWorldNeedsUpdate=!0,h.name="Cloned mesh for highlighting",h.layers.enableAll();const d=a.clone();return d.multiplyMatrices(a,o),r.setMatrixAt(i,d),r.instanceMatrix.needsUpdate=!0,r.updateMatrix(),e.userData.originalMatrix=a,h}setClipPlanes(e){this.getModelObject().traverse(i=>{const s=i.material;s&&(Array.isArray(s)?s.forEach(n=>{n.clippingPlanes=e,n.clipIntersection=!1}):(s.clippingPlanes=e,s.clipIntersection=!1))})}getObjectTree(){}hasObject(e){return!!this.modelObject.getObjectById(e.id)}hasObjectWithId(e){return!!this.modelObject.getObjectById(e)}}class Wa extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesMaterial");g(this,"type");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");g(this,"defaultOutlineColor");g(this,"useBCOutline");g(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new p.Color(an[0],an[1],an[2]),this.useBCOutline=!1,this.outlineVisible=!0;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},outlineColor:{value:this.defaultOutlineColor}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
799
799
  #include <common>
800
800
  #include <id_pars_vertex>
801
801
  #include <outline_bc_pars_vertex>`).replace("#include <color_vertex>",`
@@ -1072,7 +1072,7 @@ parentUserData: `+JSON.stringify(r.parentUserData)),P.info(a);const o=xe.cloneMa
1072
1072
  gl_FragColor = HIGHLIGHT_COLOR;
1073
1073
  return;
1074
1074
  }
1075
- `,Yo=`
1075
+ `,Xo=`
1076
1076
  #include <clipping_planes_pars_vertex>
1077
1077
 
1078
1078
  attribute int tileObjectId;
@@ -1089,7 +1089,7 @@ parentUserData: `+JSON.stringify(r.parentUserData)),P.info(a);const o=xe.cloneMa
1089
1089
  #endif
1090
1090
  gl_Position = projectionMatrix * modelViewMatrix * mvPosition;
1091
1091
  }
1092
- `,Xo=`
1092
+ `,Zo=`
1093
1093
  #include <clipping_planes_pars_fragment>
1094
1094
 
1095
1095
  flat varying int vTileObjectId;
@@ -1342,7 +1342,7 @@ void main() {
1342
1342
 
1343
1343
  #include <outline_bc_fragment>
1344
1344
  }
1345
- `;p.ShaderChunk.outline_bc_vertex=B1;p.ShaderChunk.outline_bc_fragment=k1;p.ShaderChunk.outline_bc_pars_fragment=D1;p.ShaderChunk.outline_bc_pars_vertex=L1;p.ShaderChunk.standard_ex_vertex=j1;p.ShaderChunk.standard_ex_fragment=U1;p.ShaderChunk.common_ex=P1;p.ShaderChunk.id_pars_vertex=A1;p.ShaderChunk.id_vertex=I1;p.ShaderChunk.state_pars_fragment=z1;p.ShaderChunk.state_fragment=R1;p.ShaderChunk.state_transparent_fragment=V1;p.ShaderChunk.state_highlight_fragment=F1;p.ShaderChunk.pick_ex_vertex=Yo;p.ShaderChunk.pick_ex_fragment=Xo;class H1 extends p.ShaderMaterial{constructor(e){super(e);g(this,"isBimTilesPickMaterial");g(this,"type");g(this,"stateTexture");this.isBimTilesPickMaterial=!0,this.type="BimTilesPickMaterial";const i=e.stateTexture;this.stateTexture=i,this.uniforms={uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},uStateTexture:{value:i}},this.vertexShader=Yo,this.fragmentShader=Xo,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class N1 extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesHighlightMaterial");g(this,"type");g(this,"transparent");g(this,"opacity");g(this,"depthTest");g(this,"side");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Ir,this.depthTest=!1,this.side=p.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
1345
+ `;p.ShaderChunk.outline_bc_vertex=B1;p.ShaderChunk.outline_bc_fragment=k1;p.ShaderChunk.outline_bc_pars_fragment=D1;p.ShaderChunk.outline_bc_pars_vertex=L1;p.ShaderChunk.standard_ex_vertex=j1;p.ShaderChunk.standard_ex_fragment=U1;p.ShaderChunk.common_ex=P1;p.ShaderChunk.id_pars_vertex=A1;p.ShaderChunk.id_vertex=I1;p.ShaderChunk.state_pars_fragment=z1;p.ShaderChunk.state_fragment=R1;p.ShaderChunk.state_transparent_fragment=V1;p.ShaderChunk.state_highlight_fragment=F1;p.ShaderChunk.pick_ex_vertex=Xo;p.ShaderChunk.pick_ex_fragment=Zo;class H1 extends p.ShaderMaterial{constructor(e){super(e);g(this,"isBimTilesPickMaterial");g(this,"type");g(this,"stateTexture");this.isBimTilesPickMaterial=!0,this.type="BimTilesPickMaterial";const i=e.stateTexture;this.stateTexture=i,this.uniforms={uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},uStateTexture:{value:i}},this.vertexShader=Xo,this.fragmentShader=Zo,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class N1 extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesHighlightMaterial");g(this,"type");g(this,"transparent");g(this,"opacity");g(this,"depthTest");g(this,"side");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Ar,this.depthTest=!1,this.side=p.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
1346
1346
  #include <common>
1347
1347
  #include <id_pars_vertex>`).replace("#include <begin_vertex>",`
1348
1348
  #include <begin_vertex>
@@ -1352,7 +1352,7 @@ void main() {
1352
1352
  #include <state_pars_fragment>
1353
1353
  `).replace("#include <logdepthbuf_fragment>",`
1354
1354
  #include <state_highlight_fragment>
1355
- #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class G1 extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesTransparentMaterial");g(this,"type");g(this,"transparent");g(this,"opacity");g(this,"side");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Ir,this.side=p.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
1355
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class G1 extends p.MeshStandardMaterial{constructor(e){super(e);g(this,"isBimTilesTransparentMaterial");g(this,"type");g(this,"transparent");g(this,"opacity");g(this,"side");g(this,"uniforms");g(this,"vertexShader");g(this,"fragmentShader");g(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Ar,this.side=p.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
1356
1356
  #include <common>
1357
1357
  #include <id_pars_vertex>`).replace("#include <begin_vertex>",`
1358
1358
  #include <begin_vertex>
@@ -1362,7 +1362,7 @@ void main() {
1362
1362
  #include <state_pars_fragment>
1363
1363
  `).replace("#include <logdepthbuf_fragment>",`
1364
1364
  #include <state_transparent_fragment>
1365
- #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var ii=(c=>(c[c.Hidden=0]="Hidden",c[c.Transparent=1]="Transparent",c[c.Highlighted=2]="Highlighted",c[c.Hovered=3]="Hovered",c))(ii||{});class q1{constructor(t,e){g(this,"_pickMaterial");g(this,"_highlightMaterial");g(this,"_transparentMaterial");g(this,"stateTexture");g(this,"batchMaterialMap",new Map);g(this,"instanceMaterialMap",new Map);g(this,"tileRenderer");g(this,"highlightMesh");this.tileRenderer=t,this.stateTexture=this.createStateTexture(e.maxId)}createBatchMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.batchMaterialMap.get(s)){const n=new Ya(Object.assign(Object.assign({},e),{vertexColors:!0,stateTexture:this.stateTexture}));i&&n.enableOutline(!0),this.batchMaterialMap.set(s,n)}return this.batchMaterialMap.get(s)}createInstanceMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.instanceMaterialMap.get(s)){const n=new Ya(Object.assign(Object.assign({},e),{stateTexture:this.stateTexture}));i&&n.enableOutline(!0),this.instanceMaterialMap.set(s,n)}return this.instanceMaterialMap.get(s)}get highlightMaterial(){return this._highlightMaterial||(this._highlightMaterial=new N1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new G1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new H1({stateTexture:this.stateTexture})),this._pickMaterial}createStateTexture(t){t+=1;const e=p.MathUtils.ceilPowerOfTwo(Math.sqrt(t)),i=p.MathUtils.ceilPowerOfTwo(Math.ceil(t/e));return new p.DataTexture(new Uint8Array(e*i*4),e,i,p.RGBAFormat,p.UnsignedByteType)}updateState(t,e,i,s){const n=this.stateTexture.image.data;for(let r=0;r<e.length;r++){const a=e[r],o=a*4;switch(t){case 0:n[o]=this.setFlag(n[o],t,i);break;case 1:{n[o]=this.setFlag(n[o],t,i);let l=0;i&&s!=null&&(l=this.opacity2Int8(s)),n[o+1]=l,n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],2,!1)}break;case 2:n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],t,i);break;case 3:n[o]=this.setFlag(n[o],t,i);break}}switch(t){case 1:this.setHiddenForTransparent(e,i);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setHiddenForTransparent(t,e){if(t.length===0)return;const i=Date.now(),s=this.stateTexture.image,n=this.stateTexture.image.data;for(let r=0;r<s.width*s.height;r++){const a=r*4;this.getFlag(n[a],1)?n[a+2]=this.setFlag(n[a],0,!1):n[a+2]=this.setFlag(n[a],0,!0)}e?this.updateClonedTransparentMesh(t):this.clearClonedTransparentMesh(t),P.info("[BimTiles] setHiddenForTransparent took "+(Date.now()-i)/1e3+"s")}updateClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r],o=a.userData.userIds;if(!o||a.sourceMesh)continue;const l=a.clonedMesh;for(let h=0;h<t.length;h++){const d=t[h];if(o.indexOf(d)>-1){if(l){l.userData.handleUserIds.has(d)||l.userData.handleUserIds.add(d);continue}this.cloneMeshForTransparent(e,a),a.clonedMesh.userData.handleUserIds.clear(),a.clonedMesh.userData.handleUserIds.add(d)}}}})}clearClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r];if(!a||!a.userData.userIds||a.sourceMesh)continue;const l=a.clonedMesh;for(let h=0;h<t.length;h++){const d=t[h];l&&l.userData.handleUserIds.has(d)&&l.userData.handleUserIds.delete(d)}l&&l.userData.handleUserIds.size===0&&this.disposeClonedTransparentMesh(a)}})}cloneMeshForTransparent(t,e){if(e.clonedMesh)return;const i=e.clone();i.userData={},i.userData.handleUserIds=new Set(e.userData.userIds),i.sourceMesh=e;const s=new p.BufferGeometry,n=e.geometry.getAttribute("position"),r=e.geometry.index,a=e.geometry.getAttribute("tileObjectId");s.setAttribute("position",n),s.setAttribute("tileObjectId",a),r&&s.setIndex(r),i.geometry=s,i.material=this.transparentMaterial,e.clonedMesh=i,t.add(i)}disposeClonedTransparentMesh(t){t.clonedMesh&&(t.clonedMesh.removeFromParent(),t.clonedMesh=void 0)}updateAllClonedTransparentMesh(){this.tileRenderer.forEachLoadedModel((t,e)=>{const i=t.children,s=i.length;for(let n=0;n<s;n++){const r=i[n];if(!r)break;!r.userData.userIds||r.sourceMesh||r.clonedMesh||this.cloneMeshForTransparent(t,r)}})}clearAllClonedTransparentMesh(){const t=[];this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r];if(!a)break;!a.userData.userIds||a.sourceMesh||a.clonedMesh&&t.push(a)}});for(let e=0;e<t.length;e++)this.disposeClonedTransparentMesh(t[e])}setHidden(t){const e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;i[n]=this.setFlag(i[n],0,t)}this.updateMaterialStates(),this.updateHighlightMesh()}setOpacity(t){const e=Date.now(),i=this.opacity2Int8(t),s=t<1,n=this.stateTexture.image,r=this.stateTexture.image.data;for(let a=0;a<n.width*n.height;a++){const o=a*4;r[o]=this.setFlag(r[o],1,s),r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],2,!1),r[o+1]=i,r[o+2]=this.setFlag(r[o],0,!s)}s?this.updateAllClonedTransparentMesh():this.clearAllClonedTransparentMesh(),this.updateMaterialStates(),P.info("[BimTiles] setOpacity took "+(Date.now()-e)/1e3+"s")}clearHovered(){const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;e[s]=this.setFlag(e[s],3,!1)}this.updateMaterialStates()}updateHighlightMesh(){this.highlightMesh&&this.clearHighlightMesh();const t=this.getHighlightUserIds();if(t.length===0)return;const e=this.tileRenderer.getGeometryByUserIds(t);if(!e){P.warn("[BimTiles] Failed to get geometry by userIds:",t);return}this.highlightMesh=new p.Mesh(e,this.highlightMaterial),this.tileRenderer.highlighUsage.add(this.highlightMesh)}clearHighlightMesh(){this.disposeMesh(this.highlightMesh),this.highlightMesh=void 0}clearState(t){const e=this.stateTexture.image.data;for(let i=0;i<e.length;i+=4)e[i]=this.setFlag(e[i],t,!1);switch(t){case 1:this.setOpacity(1);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setDoubleSidedMaterials(){const t=e=>{e.side!==p.DoubleSide&&(e.userData.originalSide==null&&(e.userData.originalSide=e.side),e.side=p.DoubleSide)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}revertDoubleSidedMaterials(){const t=e=>{e.userData.originalSide!=null&&(e.side=e.userData.originalSide,e.userData.originalSide=void 0)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}setClipPlanes(t){const e=t.length>0;this.batchMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.instanceMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.highlightMaterial.clippingPlanes=e?t:[],this.highlightMaterial.clipIntersection=!1,this.highlightMaterial.clipShadows=!0,this.pickMaterial.clippingPlanes=e?t:[],this.pickMaterial.clipIntersection=!1,this.pickMaterial.clipShadows=!0}resetState(){this.clearAllClonedTransparentMesh(),this.clearHighlightMesh(),this.clearHovered(),this.stateTexture.image.data.fill(0),this.updateMaterialStates()}updateMaterialStates(){this.stateTexture.needsUpdate=!0}dispose(){this.stateTexture.dispose(),this.batchMaterialMap.forEach(t=>t.dispose()),this.instanceMaterialMap.forEach(t=>t.dispose()),this.pickMaterial.dispose(),this.highlightMaterial.dispose(),this.transparentMaterial.dispose()}disposeMesh(t){t&&(t.removeFromParent(),t.geometry.dispose(),t.geometry.attributes={},t.geometry.index=null)}hasVisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],0))return!0}return!1}hasInvisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(!this.getFlag(e[s],0))return!0}return!1}getTransparentUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;this.getFlag(i[n],1)&&t.push(s)}return t}getHighlightUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;this.getFlag(i[n],2)&&t.push(s)}return t}getHoveredObject(){if(!this.stateTexture)return;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],3)){const r=i;return{tilesetId:this.tileRenderer.tilesetId,userId:r}}}}opacity2Int8(t){let e=Math.floor(t*255);return e<=0?e=1:e>=255&&(e=0),e}setFlag(t,e,i){const s=Number(e);if(i){const n=1<<s;return t|n}else{const n=~(1<<s);return t&n}}getFlag(t,e){const i=Number(e);return(t&1<<i)!==0}}const W1={9728:p.NearestFilter,9729:p.LinearFilter},Y1={9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},Xa={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping};var un=(c=>(c.Opaque="OPAQUE",c.Mask="MASK",c.Blend="BLEND",c))(un||{});const Zo={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var Lr=(c=>(c[c.scalar=1]="scalar",c[c.vec2=2]="vec2",c[c.vec3=3]="vec3",c[c.vec4=4]="vec4",c[c.mat2=4]="mat2",c[c.mat3=9]="mat3",c[c.mat4=16]="mat4",c))(Lr||{});class X1{constructor(t,e){g(this,"baseUrl");g(this,"textureLoaderCache",new Map);g(this,"materialCache",new Map);g(this,"textureCache",new Map);g(this,"userDataCache",new Map);g(this,"familyInstanceIdCache",new Map);g(this,"familyInstanceAndUserIdsCache",new Map);g(this,"userIdAndUserDataCache",new Map);g(this,"userBoxCache",new Map);g(this,"protoRoot");g(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return j.isBinaryFile(t)?this.getPropertyFromBinary(t,e,i):this.getPropertyFromJson(t,e)}async getPropertyFromJson(t,e){return await fetch(this.baseUrl+t,e).then(i=>{if(i.ok)return i.json();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+i.status+" : "+i.statusText)})}async getPropertyFromBinary(t,e,i){return await fetch(this.baseUrl+t,e).then(s=>{if(s.ok)return s.arrayBuffer();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+s.status+" : "+s.statusText)}).then(s=>{const n=new Uint8Array(s),r=Cr.inflate(n);return this.protoRoot.lookupType(i).decode(r)})}getTextureLoader(t){if(t!=="dds"&&(t="default"),this.textureLoaderCache.has(t))return this.textureLoaderCache.get(t);let e;return t==="dds"?e=new Ul.DDSLoader:e=new p.TextureLoader,this.textureLoaderCache.set(t,e),e}loadTexture(t,e){const i=e.textures[t],s=e.images[i.image],n=s.uri+":"+i.sampler;if(this.textureCache.get(n))return this.textureCache.get(n);const r=this.getTextureLoader(s.type),a=new Promise((o,l)=>{r.load(this.baseUrl+s.uri,h=>{const d=e.samplers||{},u=d[h.sampler]||{};h.magFilter=W1[u.magFilter]||p.LinearFilter,h.minFilter=Y1[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=Xa[u.wrapS]||p.RepeatWrapping,h.wrapT=Xa[u.wrapT]||p.RepeatWrapping,o(h)},void 0,h=>{throw P.error("[BimTiles] Couldn't load texture",s.uri),l(h),h})});return this.textureCache.set(n,a),a}assignTexture(t,e,i,s,n){return i.index?this.loadTexture(i.index,s).then(r=>r?(i.texCoord!==void 0&&i.texCoord>0&&(r=r.clone(),r.channel=i.texCoord),n!==void 0&&(r.colorSpace=n),r):null).catch(()=>null):Promise.resolve(null)}async parseMaterial(t){const e=Object.values(t.materials).map(async i=>{const s={};if(i.name&&(s.name=i.name),s.color=new p.Color(1,1,1),s.opacity=1,Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;s.color.setRGB(r[0],r[1],r[2],p.LinearSRGBColorSpace),s.opacity=r[3]}i.baseColorTexture&&(s.map=await this.assignTexture(s,"map",i.baseColorTexture,t,p.SRGBColorSpace)),s.metalness=i.metallicFactor!==void 0?i.metallicFactor:1,s.roughness=i.roughnessFactor!==void 0?i.roughnessFactor:1,i.metallicRoughnessTexture&&(s.metalnessMap=await this.assignTexture(s,"metalnessMap",i.metallicRoughnessTexture,t),s.roughnessMap=await this.assignTexture(s,"roughnessMap",i.metallicRoughnessTexture,t)),i.doubleSided===!0&&(s.side=p.DoubleSide);const n=i.alphaMode||un.Opaque;if(n===un.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,n===un.Mask&&(s.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture&&(s.normalMap=await this.assignTexture(s,"normalMap",i.normalTexture,t),s.normalScale=new p.Vector2(1,1)),i.occlusionTexture&&(s.aoMap=await this.assignTexture(s,"aoMap",i.occlusionTexture,t)),i.emissiveFactor){const r=i.emissiveFactor;s.emissive=new p.Color().setRGB(r[0],r[1],r[2],p.LinearSRGBColorSpace)}return i.emissiveTexture&&(s.emissiveMap=await this.assignTexture(s,"emissiveMap",i.emissiveTexture,t,p.SRGBColorSpace)),this.materialCache.get(i.id)||this.materialCache.set(i.id,s),this.materialCache.get(i.id)});return Promise.all(e).then(()=>{P.info("[BimTilesPropertyParser] material parser complete.")})}parseUserData(t){const{userDataKeys:e,userDataValues:i,userDataItems:s}=t;s.forEach((n,r)=>{n.indexMap&&(n=n.indexMap);const a={};for(const o in n)a[e[o]]=i[n[o]];this.userDataCache.set(r,a)})}parseUserId(t){const{modelIds:e,familyInstanceIds:i,modelTable:s,userIdTable:n}=t;Object.keys(s).forEach(r=>{const a=Number(r),o=e[a],l=s[a].value||s[a],h=l.map(d=>i[d]);this.familyInstanceIdCache.set(o,h)}),Object.keys(n).forEach(r=>{const a=Number(r),o=n[a].value||n[a],l=e[o[0]],h=i[o[1]],d=l+"#"+h;this.familyInstanceAndUserIdsCache.has(d)||this.familyInstanceAndUserIdsCache.set(d,[]),this.familyInstanceAndUserIdsCache.get(d).push(a);const u=o[2];this.userIdAndUserDataCache.set(a,{modelId:l,familyInstanceId:h,userDataIndex:u})})}parseUserIdBox(t,e){t.boxMap&&(t=t.boxMap),Object.keys(t).forEach(i=>{const s=Number(i),n=t[s].value?t[s].value:t[s],r=new p.Box3().setFromArray(n);e&&r.applyMatrix4(e),this.userBoxCache.set(s,r)})}getMaterialParameters(t){return this.materialCache.get(t)}getUserData(t){if(this.userIdAndUserDataCache.size===0)return;const e=this.userIdAndUserDataCache.get(t);if(!e?.userDataIndex)return;let i=this.userDataCache.get(e.userDataIndex);return i||(i={}),i.modelId=e.modelId,i.familyInstanceId=e.familyInstanceId,i}getFamilyInstanceIdsByModelId(t){return this.familyInstanceIdCache.get(t)}getUserIdBox(t){return this.userBoxCache.get(t)}getUserIds(){return Array.from(this.userIdAndUserDataCache.keys())}getUserIdsByFamilyInstanceId(t,e){if(this.familyInstanceAndUserIdsCache.size===0)return[];const i=t+"#"+e;return this.familyInstanceAndUserIdsCache.get(i)||[]}getUserIdByUserDataIndex(t){if(this.userIdAndUserDataCache.size!==0){for(const[e,i]of this.userIdAndUserDataCache)if(i.userDataIndex===t)return e}}getUserIdByFilter(t){const e=[];return this.userDataCache.size===0||this.userDataCache.forEach((i,s)=>{if(t(i)){const n=this.getUserIdByUserDataIndex(s);n!==void 0&&e.push(n)}}),e}dispose(){this.textureLoaderCache.clear(),this.materialCache.clear(),this.textureCache.clear(),this.userDataCache.clear(),this.familyInstanceIdCache.clear(),this.familyInstanceAndUserIdsCache.clear(),this.userIdAndUserDataCache.clear(),this.userBoxCache.clear()}}function Ko(c){return new TextDecoder().decode(c)}function Za(c,t){return((c&255)<<24)+(t&16777215)}function Z1(c){return c[3]}function K1(c){return(c[0]<<16)+(c[1]<<8)+c[2]}function $o(c){const t=c.BYTES_PER_ELEMENT,e=(1<<8*t-1)-1,i=2,s=c.length/i,n=new p.Vector2,r=new p.Vector3,a=new Float32Array(s*3);for(let o=0;o<s;o++)n.fromArray(c,o*i),z.OctDecode(n,r,e),r.toArray(a,o*3);return a}class Ka{parse(t,e){const i=[];for(let s=0;s<e.length;s++){const n=e[s],{byteOffset:r,byteLength:a,batchTable:o}=n,l=t.slice(r,r+a);i.push(this.parseMesh(l,n,o))}return i}parseMesh(t,e,i){const s=e.primitive,n=e.buffers,r=this.parseTypedArray(t,n[s.position]),a=s.color?this.parseTypedArray(t,n[s.color]):new Float32Array,o=s.indice?this.parseTypedArray(t,n[s.indice]):new Uint16Array;let l=s.normal?this.parseTypedArray(t,n[s.normal]):new Float32Array;s.normal>=0&&s.normalCompressed&&(l=$o(l));const h=s.tangent?this.parseTypedArray(t,n[s.tangent]):new Float32Array,d=s.uv_0?this.parseTypedArray(t,n[s.uv_0]):new Float32Array,u=s.barycentric?this.parseTypedArray(t,n[s.barycentric]):new Uint8Array,f=new Array(r.length/3);return i.forEach(m=>{f.fill(m.userId,m.positionStart,m.positionStart+m.positionCount)}),{type:s.type,position:r,indice:o,color:a,normal:l,tangent:h,barycentric:u,uv:d,userIds:f,materialId:s.materialId||s.material,batchTable:e.batchTable}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:n,type:r,componentType:a}=e,o=Number(Lr[r]),l=Zo[a],h=t.slice(i,i+s);return new l(h,0,n*o)}}const ri=class ri{constructor(){g(this,"header")}async parse(t,e,i){const s=[];for(let n=0;n<t.length;n++){const{blobId:r,url:a,instances:o}=t[n],l=await this.getInstancedMeshByUrlAndBlobId(e+a,r,i);if(!l){P.warn("[BimTiles] Failed to get InstancedMesh by "+(e+a)+", bloblId '"+r+"'");continue}const h=[],d=[];o.forEach(f=>{h.push(f.userId),d.push(...f.transform)});const u=Object.assign(Object.assign({},l),{userIds:h,matrices:d});s.push(u)}return s}parseInstanceBuffer(t){const e=new vs(t);this.header={magic:e.readUtf8String(4),version:e.readUint32(),byteLength:e.readUint64()};const i=e.readUint32(),s=e.readUint32(),n=e.readUint32(),r=e.readUint64(),a=t.slice(i,i+s),o=Ko(new Uint8Array(a,0,s)),l=JSON.parse(o),h=t.slice(n,n+r);return this.parseMeshes(h,l.meshes)}parseInstanceProto(t,e){const i=Cr.inflate(t),s=e.lookupType("PBTileContent"),n=s.decode(i);return this.parseMeshes(n.binaries.slice().buffer,n.meshes)}parseMeshes(t,e){const i=[];for(let s=0;s<e.length;s++){const n=e[s],{byteOffset:r=0,byteLength:a}=n,o=t.slice(r,r+a);i.push(this.parseMesh(o,n))}return i}parseMesh(t,e){const i=e.primitive,s=e.buffers,n=this.parseTypedArray(t,s[i.position]),r=i.color?this.parseTypedArray(t,s[i.color]):new Float32Array,a=i.indice?this.parseTypedArray(t,s[i.indice]):new Uint16Array;let o=i.normal?this.parseTypedArray(t,s[i.normal]):new Float32Array;i.normal>=0&&i.normalCompressed&&(o=$o(o));const l=i.tangent?this.parseTypedArray(t,s[i.tangent]):new Float32Array,h=i.uv_0?this.parseTypedArray(t,s[i.uv_0]):new Float32Array,d=i.barycentric?this.parseTypedArray(t,s[i.barycentric]):new Uint8Array,u=[],f=[];return{type:i.type,position:n,indice:a,color:r,normal:o,tangent:l,uv:h,barycentric:d,userIds:u,matrices:f,materialId:i.materialId||i.material}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:n,type:r,componentType:a}=e,o=Number(Lr[r]),l=Zo[a],h=t.slice(i,i+s);return new l(h,0,n*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!ri.instanceDataMap[t]){const s=await fetch(t).then(r=>r.arrayBuffer()),n=new Uint8Array(s);j.isGzip(n)&&i?ri.instanceDataMap[t]=this.parseInstanceProto(n,i):ri.instanceDataMap[t]=this.parseInstanceBuffer(s)}return ri.instanceDataMap[t][e]}};g(ri,"instanceDataMap",{});let mn=ri;class $1{async parse(t,e,i){const s=new Uint8Array(t);return j.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new vs(t),s=i.readUtf8String(4),n=i.readUint32(),r=i.readUint64(),a=i.readUint32(),o=i.readUint32(),l=i.readUint32(),h=i.readUint64(),d=t.slice(a,a+o),u=Ko(new Uint8Array(d,0,o)),f=JSON.parse(u);P.debug("[BimTiles] Tile, magic("+s+"), version("+n+"), byteLength("+r+"), tileJson:",f);const m=t.slice(l,l+h),b=new Ka().parse(m,f.batchedMeshes),y=await new mn().parse(f.instancedMeshes,e);return{batchedMeshes:b,instancedMeshes:y}}async parseProto(t,e,i){const s=Cr.inflate(t),n=i.lookupType("PBTileContent").decode(s),r=n.header;P.debug("[BimTiles] Tile, magic("+r.magic+"), version("+r.version+"), byteLength("+s.byteLength+"), tileJson:",n);const a=n.binaries.slice().buffer,o=new Ka().parse(a,n.meshes),l=await new mn().parse(n.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const J1=`syntax = "proto3";\r
1365
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var ii=(c=>(c[c.Hidden=0]="Hidden",c[c.Transparent=1]="Transparent",c[c.Highlighted=2]="Highlighted",c[c.Hovered=3]="Hovered",c))(ii||{});class q1{constructor(t,e){g(this,"_pickMaterial");g(this,"_highlightMaterial");g(this,"_transparentMaterial");g(this,"stateTexture");g(this,"batchMaterialMap",new Map);g(this,"instanceMaterialMap",new Map);g(this,"tileRenderer");g(this,"highlightMesh");this.tileRenderer=t,this.stateTexture=this.createStateTexture(e.maxId)}createBatchMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.batchMaterialMap.get(s)){const n=new Wa(Object.assign(Object.assign({},e),{vertexColors:!0,stateTexture:this.stateTexture}));i&&n.enableOutline(!0),this.batchMaterialMap.set(s,n)}return this.batchMaterialMap.get(s)}createInstanceMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.instanceMaterialMap.get(s)){const n=new Wa(Object.assign(Object.assign({},e),{stateTexture:this.stateTexture}));i&&n.enableOutline(!0),this.instanceMaterialMap.set(s,n)}return this.instanceMaterialMap.get(s)}get highlightMaterial(){return this._highlightMaterial||(this._highlightMaterial=new N1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new G1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new H1({stateTexture:this.stateTexture})),this._pickMaterial}createStateTexture(t){t+=1;const e=p.MathUtils.ceilPowerOfTwo(Math.sqrt(t)),i=p.MathUtils.ceilPowerOfTwo(Math.ceil(t/e));return new p.DataTexture(new Uint8Array(e*i*4),e,i,p.RGBAFormat,p.UnsignedByteType)}updateState(t,e,i,s){const n=this.stateTexture.image.data;for(let r=0;r<e.length;r++){const a=e[r],o=a*4;switch(t){case 0:n[o]=this.setFlag(n[o],t,i);break;case 1:{n[o]=this.setFlag(n[o],t,i);let l=0;i&&s!=null&&(l=this.opacity2Int8(s)),n[o+1]=l,n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],2,!1)}break;case 2:n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],t,i);break;case 3:n[o]=this.setFlag(n[o],t,i);break}}switch(t){case 1:this.setHiddenForTransparent(e,i);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setHiddenForTransparent(t,e){if(t.length===0)return;const i=Date.now(),s=this.stateTexture.image,n=this.stateTexture.image.data;for(let r=0;r<s.width*s.height;r++){const a=r*4;this.getFlag(n[a],1)?n[a+2]=this.setFlag(n[a],0,!1):n[a+2]=this.setFlag(n[a],0,!0)}e?this.updateClonedTransparentMesh(t):this.clearClonedTransparentMesh(t),P.info("[BimTiles] setHiddenForTransparent took "+(Date.now()-i)/1e3+"s")}updateClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r],o=a.userData.userIds;if(!o||a.sourceMesh)continue;const l=a.clonedMesh;for(let h=0;h<t.length;h++){const d=t[h];if(o.indexOf(d)>-1){if(l){l.userData.handleUserIds.has(d)||l.userData.handleUserIds.add(d);continue}this.cloneMeshForTransparent(e,a),a.clonedMesh.userData.handleUserIds.clear(),a.clonedMesh.userData.handleUserIds.add(d)}}}})}clearClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r];if(!a||!a.userData.userIds||a.sourceMesh)continue;const l=a.clonedMesh;for(let h=0;h<t.length;h++){const d=t[h];l&&l.userData.handleUserIds.has(d)&&l.userData.handleUserIds.delete(d)}l&&l.userData.handleUserIds.size===0&&this.disposeClonedTransparentMesh(a)}})}cloneMeshForTransparent(t,e){if(e.clonedMesh)return;const i=e.clone();i.userData={},i.userData.handleUserIds=new Set(e.userData.userIds),i.sourceMesh=e;const s=new p.BufferGeometry,n=e.geometry.getAttribute("position"),r=e.geometry.index,a=e.geometry.getAttribute("tileObjectId");s.setAttribute("position",n),s.setAttribute("tileObjectId",a),r&&s.setIndex(r),i.geometry=s,i.material=this.transparentMaterial,e.clonedMesh=i,t.add(i)}disposeClonedTransparentMesh(t){t.clonedMesh&&(t.clonedMesh.removeFromParent(),t.clonedMesh=void 0)}updateAllClonedTransparentMesh(){this.tileRenderer.forEachLoadedModel((t,e)=>{const i=t.children,s=i.length;for(let n=0;n<s;n++){const r=i[n];if(!r)break;!r.userData.userIds||r.sourceMesh||r.clonedMesh||this.cloneMeshForTransparent(t,r)}})}clearAllClonedTransparentMesh(){const t=[];this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,n=s.length;for(let r=0;r<n;r++){const a=s[r];if(!a)break;!a.userData.userIds||a.sourceMesh||a.clonedMesh&&t.push(a)}});for(let e=0;e<t.length;e++)this.disposeClonedTransparentMesh(t[e])}setHidden(t){const e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;i[n]=this.setFlag(i[n],0,t)}this.updateMaterialStates(),this.updateHighlightMesh()}setOpacity(t){const e=Date.now(),i=this.opacity2Int8(t),s=t<1,n=this.stateTexture.image,r=this.stateTexture.image.data;for(let a=0;a<n.width*n.height;a++){const o=a*4;r[o]=this.setFlag(r[o],1,s),r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],2,!1),r[o+1]=i,r[o+2]=this.setFlag(r[o],0,!s)}s?this.updateAllClonedTransparentMesh():this.clearAllClonedTransparentMesh(),this.updateMaterialStates(),P.info("[BimTiles] setOpacity took "+(Date.now()-e)/1e3+"s")}clearHovered(){const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;e[s]=this.setFlag(e[s],3,!1)}this.updateMaterialStates()}updateHighlightMesh(){this.highlightMesh&&this.clearHighlightMesh();const t=this.getHighlightUserIds();if(t.length===0)return;const e=this.tileRenderer.getGeometryByUserIds(t);if(!e){P.warn("[BimTiles] Failed to get geometry by userIds:",t);return}this.highlightMesh=new p.Mesh(e,this.highlightMaterial),this.tileRenderer.highlighUsage.add(this.highlightMesh)}clearHighlightMesh(){this.disposeMesh(this.highlightMesh),this.highlightMesh=void 0}clearState(t){const e=this.stateTexture.image.data;for(let i=0;i<e.length;i+=4)e[i]=this.setFlag(e[i],t,!1);switch(t){case 1:this.setOpacity(1);break;case 2:this.updateHighlightMesh();break}this.updateMaterialStates()}setDoubleSidedMaterials(){const t=e=>{e.side!==p.DoubleSide&&(e.userData.originalSide==null&&(e.userData.originalSide=e.side),e.side=p.DoubleSide)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}revertDoubleSidedMaterials(){const t=e=>{e.userData.originalSide!=null&&(e.side=e.userData.originalSide,e.userData.originalSide=void 0)};this.batchMaterialMap.forEach(e=>t(e)),this.instanceMaterialMap.forEach(e=>t(e))}setClipPlanes(t){const e=t.length>0;this.batchMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.instanceMaterialMap.forEach(i=>{i.clippingPlanes=e?t:[],i.clipIntersection=!1,i.clipShadows=!0}),this.highlightMaterial.clippingPlanes=e?t:[],this.highlightMaterial.clipIntersection=!1,this.highlightMaterial.clipShadows=!0,this.pickMaterial.clippingPlanes=e?t:[],this.pickMaterial.clipIntersection=!1,this.pickMaterial.clipShadows=!0}resetState(){this.clearAllClonedTransparentMesh(),this.clearHighlightMesh(),this.clearHovered(),this.stateTexture.image.data.fill(0),this.updateMaterialStates()}updateMaterialStates(){this.stateTexture.needsUpdate=!0}dispose(){this.stateTexture.dispose(),this.batchMaterialMap.forEach(t=>t.dispose()),this.instanceMaterialMap.forEach(t=>t.dispose()),this.pickMaterial.dispose(),this.highlightMaterial.dispose(),this.transparentMaterial.dispose()}disposeMesh(t){t&&(t.removeFromParent(),t.geometry.dispose(),t.geometry.attributes={},t.geometry.index=null)}hasVisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],0))return!0}return!1}hasInvisibleObject(){if(!this.stateTexture)return!1;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(!this.getFlag(e[s],0))return!0}return!1}getTransparentUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;this.getFlag(i[n],1)&&t.push(s)}return t}getHighlightUserIds(){if(!this.stateTexture)return[];const t=[],e=this.stateTexture.image,i=this.stateTexture.image.data;for(let s=0;s<e.width*e.height;s++){const n=s*4;this.getFlag(i[n],2)&&t.push(s)}return t}getHoveredObject(){if(!this.stateTexture)return;const t=this.stateTexture.image,e=this.stateTexture.image.data;for(let i=0;i<t.width*t.height;i++){const s=i*4;if(this.getFlag(e[s],3)){const r=i;return{tilesetId:this.tileRenderer.tilesetId,userId:r}}}}opacity2Int8(t){let e=Math.floor(t*255);return e<=0?e=1:e>=255&&(e=0),e}setFlag(t,e,i){const s=Number(e);if(i){const n=1<<s;return t|n}else{const n=~(1<<s);return t&n}}getFlag(t,e){const i=Number(e);return(t&1<<i)!==0}}const W1={9728:p.NearestFilter,9729:p.LinearFilter},Y1={9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},Ya={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping};var un=(c=>(c.Opaque="OPAQUE",c.Mask="MASK",c.Blend="BLEND",c))(un||{});const Ko={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var Dr=(c=>(c[c.scalar=1]="scalar",c[c.vec2=2]="vec2",c[c.vec3=3]="vec3",c[c.vec4=4]="vec4",c[c.mat2=4]="mat2",c[c.mat3=9]="mat3",c[c.mat4=16]="mat4",c))(Dr||{});class X1{constructor(t,e){g(this,"baseUrl");g(this,"textureLoaderCache",new Map);g(this,"materialCache",new Map);g(this,"textureCache",new Map);g(this,"userDataCache",new Map);g(this,"familyInstanceIdCache",new Map);g(this,"familyInstanceAndUserIdsCache",new Map);g(this,"userIdAndUserDataCache",new Map);g(this,"userBoxCache",new Map);g(this,"protoRoot");g(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return j.isBinaryFile(t)?this.getPropertyFromBinary(t,e,i):this.getPropertyFromJson(t,e)}async getPropertyFromJson(t,e){return await fetch(this.baseUrl+t,e).then(i=>{if(i.ok)return i.json();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+i.status+" : "+i.statusText)})}async getPropertyFromBinary(t,e,i){return await fetch(this.baseUrl+t,e).then(s=>{if(s.ok)return s.arrayBuffer();throw new Error('[BimTiles] Failed to load property "'+t+'", status '+s.status+" : "+s.statusText)}).then(s=>{const n=new Uint8Array(s),r=Tr.inflate(n);return this.protoRoot.lookupType(i).decode(r)})}getTextureLoader(t){if(t!=="dds"&&(t="default"),this.textureLoaderCache.has(t))return this.textureLoaderCache.get(t);let e;return t==="dds"?e=new Hl.DDSLoader:e=new p.TextureLoader,this.textureLoaderCache.set(t,e),e}loadTexture(t,e){const i=e.textures[t],s=e.images[i.image],n=s.uri+":"+i.sampler;if(this.textureCache.get(n))return this.textureCache.get(n);const r=this.getTextureLoader(s.type),a=new Promise((o,l)=>{r.load(this.baseUrl+s.uri,h=>{const d=e.samplers||{},u=d[h.sampler]||{};h.magFilter=W1[u.magFilter]||p.LinearFilter,h.minFilter=Y1[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=Ya[u.wrapS]||p.RepeatWrapping,h.wrapT=Ya[u.wrapT]||p.RepeatWrapping,o(h)},void 0,h=>{throw P.error("[BimTiles] Couldn't load texture",s.uri),l(h),h})});return this.textureCache.set(n,a),a}assignTexture(t,e,i,s,n){return i.index?this.loadTexture(i.index,s).then(r=>r?(i.texCoord!==void 0&&i.texCoord>0&&(r=r.clone(),r.channel=i.texCoord),n!==void 0&&(r.colorSpace=n),r):null).catch(()=>null):Promise.resolve(null)}async parseMaterial(t){const e=Object.values(t.materials).map(async i=>{const s={};if(i.name&&(s.name=i.name),s.color=new p.Color(1,1,1),s.opacity=1,Array.isArray(i.baseColorFactor)){const r=i.baseColorFactor;s.color.setRGB(r[0],r[1],r[2],p.LinearSRGBColorSpace),s.opacity=r[3]}i.baseColorTexture&&(s.map=await this.assignTexture(s,"map",i.baseColorTexture,t,p.SRGBColorSpace)),s.metalness=i.metallicFactor!==void 0?i.metallicFactor:1,s.roughness=i.roughnessFactor!==void 0?i.roughnessFactor:1,i.metallicRoughnessTexture&&(s.metalnessMap=await this.assignTexture(s,"metalnessMap",i.metallicRoughnessTexture,t),s.roughnessMap=await this.assignTexture(s,"roughnessMap",i.metallicRoughnessTexture,t)),i.doubleSided===!0&&(s.side=p.DoubleSide);const n=i.alphaMode||un.Opaque;if(n===un.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,n===un.Mask&&(s.alphaTest=i.alphaCutoff!==void 0?i.alphaCutoff:.5)),i.normalTexture&&(s.normalMap=await this.assignTexture(s,"normalMap",i.normalTexture,t),s.normalScale=new p.Vector2(1,1)),i.occlusionTexture&&(s.aoMap=await this.assignTexture(s,"aoMap",i.occlusionTexture,t)),i.emissiveFactor){const r=i.emissiveFactor;s.emissive=new p.Color().setRGB(r[0],r[1],r[2],p.LinearSRGBColorSpace)}return i.emissiveTexture&&(s.emissiveMap=await this.assignTexture(s,"emissiveMap",i.emissiveTexture,t,p.SRGBColorSpace)),this.materialCache.get(i.id)||this.materialCache.set(i.id,s),this.materialCache.get(i.id)});return Promise.all(e).then(()=>{P.info("[BimTilesPropertyParser] material parser complete.")})}parseUserData(t){const{userDataKeys:e,userDataValues:i,userDataItems:s}=t;s.forEach((n,r)=>{n.indexMap&&(n=n.indexMap);const a={};for(const o in n)a[e[o]]=i[n[o]];this.userDataCache.set(r,a)})}parseUserId(t){const{modelIds:e,familyInstanceIds:i,modelTable:s,userIdTable:n}=t;Object.keys(s).forEach(r=>{const a=Number(r),o=e[a],l=s[a].value||s[a],h=l.map(d=>i[d]);this.familyInstanceIdCache.set(o,h)}),Object.keys(n).forEach(r=>{const a=Number(r),o=n[a].value||n[a],l=e[o[0]],h=i[o[1]],d=l+"#"+h;this.familyInstanceAndUserIdsCache.has(d)||this.familyInstanceAndUserIdsCache.set(d,[]),this.familyInstanceAndUserIdsCache.get(d).push(a);const u=o[2];this.userIdAndUserDataCache.set(a,{modelId:l,familyInstanceId:h,userDataIndex:u})})}parseUserIdBox(t,e){t.boxMap&&(t=t.boxMap),Object.keys(t).forEach(i=>{const s=Number(i),n=t[s].value?t[s].value:t[s],r=new p.Box3().setFromArray(n);e&&r.applyMatrix4(e),this.userBoxCache.set(s,r)})}getMaterialParameters(t){return this.materialCache.get(t)}getUserData(t){if(this.userIdAndUserDataCache.size===0)return;const e=this.userIdAndUserDataCache.get(t);if(!e?.userDataIndex)return;let i=this.userDataCache.get(e.userDataIndex);return i||(i={}),i.modelId=e.modelId,i.familyInstanceId=e.familyInstanceId,i}getFamilyInstanceIdsByModelId(t){return this.familyInstanceIdCache.get(t)}getUserIdBox(t){return this.userBoxCache.get(t)}getUserIds(){return Array.from(this.userIdAndUserDataCache.keys())}getUserIdsByFamilyInstanceId(t,e){if(this.familyInstanceAndUserIdsCache.size===0)return[];const i=t+"#"+e;return this.familyInstanceAndUserIdsCache.get(i)||[]}getUserIdByUserDataIndex(t){if(this.userIdAndUserDataCache.size!==0){for(const[e,i]of this.userIdAndUserDataCache)if(i.userDataIndex===t)return e}}getUserIdByFilter(t){const e=[];return this.userDataCache.size===0||this.userDataCache.forEach((i,s)=>{if(t(i)){const n=this.getUserIdByUserDataIndex(s);n!==void 0&&e.push(n)}}),e}dispose(){this.textureLoaderCache.clear(),this.materialCache.clear(),this.textureCache.clear(),this.userDataCache.clear(),this.familyInstanceIdCache.clear(),this.familyInstanceAndUserIdsCache.clear(),this.userIdAndUserDataCache.clear(),this.userBoxCache.clear()}}function $o(c){return new TextDecoder().decode(c)}function Xa(c,t){return((c&255)<<24)+(t&16777215)}function Z1(c){return c[3]}function K1(c){return(c[0]<<16)+(c[1]<<8)+c[2]}function Jo(c){const t=c.BYTES_PER_ELEMENT,e=(1<<8*t-1)-1,i=2,s=c.length/i,n=new p.Vector2,r=new p.Vector3,a=new Float32Array(s*3);for(let o=0;o<s;o++)n.fromArray(c,o*i),z.OctDecode(n,r,e),r.toArray(a,o*3);return a}class Za{parse(t,e){const i=[];for(let s=0;s<e.length;s++){const n=e[s],{byteOffset:r,byteLength:a,batchTable:o}=n,l=t.slice(r,r+a);i.push(this.parseMesh(l,n,o))}return i}parseMesh(t,e,i){const s=e.primitive,n=e.buffers,r=this.parseTypedArray(t,n[s.position]),a=s.color?this.parseTypedArray(t,n[s.color]):new Float32Array,o=s.indice?this.parseTypedArray(t,n[s.indice]):new Uint16Array;let l=s.normal?this.parseTypedArray(t,n[s.normal]):new Float32Array;s.normal>=0&&s.normalCompressed&&(l=Jo(l));const h=s.tangent?this.parseTypedArray(t,n[s.tangent]):new Float32Array,d=s.uv_0?this.parseTypedArray(t,n[s.uv_0]):new Float32Array,u=s.barycentric?this.parseTypedArray(t,n[s.barycentric]):new Uint8Array,f=new Array(r.length/3);return i.forEach(m=>{f.fill(m.userId,m.positionStart,m.positionStart+m.positionCount)}),{type:s.type,position:r,indice:o,color:a,normal:l,tangent:h,barycentric:u,uv:d,userIds:f,materialId:s.materialId||s.material,batchTable:e.batchTable}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:n,type:r,componentType:a}=e,o=Number(Dr[r]),l=Ko[a],h=t.slice(i,i+s);return new l(h,0,n*o)}}const ri=class ri{constructor(){g(this,"header")}async parse(t,e,i){const s=[];for(let n=0;n<t.length;n++){const{blobId:r,url:a,instances:o}=t[n],l=await this.getInstancedMeshByUrlAndBlobId(e+a,r,i);if(!l){P.warn("[BimTiles] Failed to get InstancedMesh by "+(e+a)+", bloblId '"+r+"'");continue}const h=[],d=[];o.forEach(f=>{h.push(f.userId),d.push(...f.transform)});const u=Object.assign(Object.assign({},l),{userIds:h,matrices:d});s.push(u)}return s}parseInstanceBuffer(t){const e=new vs(t);this.header={magic:e.readUtf8String(4),version:e.readUint32(),byteLength:e.readUint64()};const i=e.readUint32(),s=e.readUint32(),n=e.readUint32(),r=e.readUint64(),a=t.slice(i,i+s),o=$o(new Uint8Array(a,0,s)),l=JSON.parse(o),h=t.slice(n,n+r);return this.parseMeshes(h,l.meshes)}parseInstanceProto(t,e){const i=Tr.inflate(t),s=e.lookupType("PBTileContent"),n=s.decode(i);return this.parseMeshes(n.binaries.slice().buffer,n.meshes)}parseMeshes(t,e){const i=[];for(let s=0;s<e.length;s++){const n=e[s],{byteOffset:r=0,byteLength:a}=n,o=t.slice(r,r+a);i.push(this.parseMesh(o,n))}return i}parseMesh(t,e){const i=e.primitive,s=e.buffers,n=this.parseTypedArray(t,s[i.position]),r=i.color?this.parseTypedArray(t,s[i.color]):new Float32Array,a=i.indice?this.parseTypedArray(t,s[i.indice]):new Uint16Array;let o=i.normal?this.parseTypedArray(t,s[i.normal]):new Float32Array;i.normal>=0&&i.normalCompressed&&(o=Jo(o));const l=i.tangent?this.parseTypedArray(t,s[i.tangent]):new Float32Array,h=i.uv_0?this.parseTypedArray(t,s[i.uv_0]):new Float32Array,d=i.barycentric?this.parseTypedArray(t,s[i.barycentric]):new Uint8Array,u=[],f=[];return{type:i.type,position:n,indice:a,color:r,normal:o,tangent:l,uv:h,barycentric:d,userIds:u,matrices:f,materialId:i.materialId||i.material}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:n,type:r,componentType:a}=e,o=Number(Dr[r]),l=Ko[a],h=t.slice(i,i+s);return new l(h,0,n*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!ri.instanceDataMap[t]){const s=await fetch(t).then(r=>r.arrayBuffer()),n=new Uint8Array(s);j.isGzip(n)&&i?ri.instanceDataMap[t]=this.parseInstanceProto(n,i):ri.instanceDataMap[t]=this.parseInstanceBuffer(s)}return ri.instanceDataMap[t][e]}};g(ri,"instanceDataMap",{});let mn=ri;class $1{async parse(t,e,i){const s=new Uint8Array(t);return j.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new vs(t),s=i.readUtf8String(4),n=i.readUint32(),r=i.readUint64(),a=i.readUint32(),o=i.readUint32(),l=i.readUint32(),h=i.readUint64(),d=t.slice(a,a+o),u=$o(new Uint8Array(d,0,o)),f=JSON.parse(u);P.debug("[BimTiles] Tile, magic("+s+"), version("+n+"), byteLength("+r+"), tileJson:",f);const m=t.slice(l,l+h),b=new Za().parse(m,f.batchedMeshes),y=await new mn().parse(f.instancedMeshes,e);return{batchedMeshes:b,instancedMeshes:y}}async parseProto(t,e,i){const s=Tr.inflate(t),n=i.lookupType("PBTileContent").decode(s),r=n.header;P.debug("[BimTiles] Tile, magic("+r.magic+"), version("+r.version+"), byteLength("+s.byteLength+"), tileJson:",n);const a=n.binaries.slice().buffer,o=new Za().parse(a,n.meshes),l=await new mn().parse(n.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const J1=`syntax = "proto3";\r
1366
1366
  \r
1367
1367
  package BimTiles;\r
1368
1368
  \r
@@ -1528,6 +1528,6 @@ message PBTileContent {\r
1528
1528
  repeated PBMesh meshes = 3;\r
1529
1529
  bytes binaries = 4;\r
1530
1530
  }\r
1531
- `,Jo=Symbol("INITIAL_FRUSTUM_CULLED");function Q1(c,t){c.traverse(e=>{e.frustumCulled=e[Jo]&&t})}const Ws=new p.Vector3,Ys=new p.Vector3,Zn=new p.Box3;class Qo extends Vl.TilesRenderer{constructor(e,i){super(e);g(this,"highlighUsage");g(this,"transparentUsage");g(this,"pickUsage");g(this,"materialManager");g(this,"baseUrl");g(this,"propertyParser");g(this,"tilesetId");g(this,"onBeforeParseTile");g(this,"protoRoot");this.downloadQueue.maxJobs=6,this.parseQueue.maxJobs=4,this.optimizeRaycast=!1,this.errorTarget=8,this.loadSiblings=!1,this.tilesetId=i,this.baseUrl=e.replace(/\/[^\\/]*\/?$/,"/"),this.highlighUsage=new p.Group,this.highlighUsage.name="highlighUsage-"+this.tilesetId,this.group.add(this.highlighUsage),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.tilesetId,this.group.add(this.transparentUsage),this.pickUsage=new p.Group,this.protoRoot=dc.parse(J1).root,this.propertyParser=new X1(this.baseUrl,this.protoRoot)}getVertexColorArray(e,i=new p.Color(16777215)){const s=[],{r:n,g:r,b:a}=i;for(let o=0;o<e;o+=3)s.push(n,r,a);return new Float32Array(s)}createBatchedMesh(e){const{position:i,uv:s,normal:n,indice:r,barycentric:a,userIds:o,materialId:l,batchTable:h}=e;let d=e.color;const u=o.map(x=>Za(this.tilesetId,x)),f=new p.BufferGeometry;f.setAttribute("position",new p.Float32BufferAttribute(i,3)),f.setAttribute("normal",new p.Float32BufferAttribute(n,3)),f.setAttribute("uv",new p.Float32BufferAttribute(s,2)),f.setAttribute("tileObjectId",new p.Int32BufferAttribute(u,1)),f.setIndex(Array.from(r));const m=this.propertyParser.getMaterialParameters(l);d.length===0&&(d=this.getVertexColorArray(i.length,m?.color)),f.setAttribute("color",new p.Float32BufferAttribute(d,3));const b=a.length>0;b&&f.setAttribute("barycentric",new p.BufferAttribute(a,1));const y=this.materialManager?.createBatchMaterial(l,m,b),C=new p.Mesh(f,y),w=new p.Mesh(f,this.materialManager?.pickMaterial);return{mesh:C,pickMesh:w,batchTable:h}}createInstancedMesh(e){const{position:i,uv:s,color:n,normal:r,indice:a,barycentric:o,matrices:l,userIds:h,materialId:d}=e,u=h.map(M=>Za(this.tilesetId,M)),f=h.length,m=new p.BufferGeometry;m.setIndex(Array.from(a)),m.setAttribute("position",new p.Float32BufferAttribute(i,3)),m.setAttribute("uv",new p.Float32BufferAttribute(s,2)),m.setAttribute("normal",new p.Float32BufferAttribute(r,3)),m.setAttribute("tileObjectId",new p.InstancedBufferAttribute(new Int32Array(u),1));const b=o.length>0;b&&m.setAttribute("barycentric",new p.BufferAttribute(o,1));const y=this.propertyParser.getMaterialParameters(d),C=this.materialManager?.createInstanceMaterial(d,y,b),w=new p.InstancedMesh(m,C,f);w.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16);let x=n;x.length===0&&(x=this.getVertexColorArray(f*3,y?.color)),w.instanceColor=new p.InstancedBufferAttribute(x,3);const E=new p.InstancedMesh(m,this.materialManager?.pickMaterial,f);return E.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16),{mesh:w,pickMesh:E,userIds:h}}getGeometryByUserIds(e){const i=Date.now(),s=[];return this.visibleTiles.forEach(n=>{const r=n.cached.scene.children;for(let a=0;a<r.length;a++){const o=r[a];if(!o||o.sourceMesh)continue;const l=o.userData.userIds;if(l)for(let h=0;h<e.length;h++){const d=e[h],u=l.indexOf(d);if(u>-1){const f=new p.BufferGeometry,m=o.geometry.getAttribute("position"),b=o.geometry.index,y=o.geometry.getAttribute("tileObjectId");if(o instanceof p.InstancedMesh){const C=new p.Matrix4;o.getMatrixAt(u,C),f.setAttribute("position",m.clone());const w=y.array[u*y.itemSize];f.setAttribute("tileObjectId",new p.Int32BufferAttribute(new Array(m.array.length/3).fill(w),1)),b&&f.setIndex(b),f.applyMatrix4(C)}else{const{indexStart:C,indexCount:w,positionStart:x,positionCount:E}=o.userData.batchTable.find(_=>_.userId===d),M=m.itemSize,O=m.array.slice(x*M,x*M+E*M),S=new p.Float32BufferAttribute(O,M);f.setAttribute("position",S);const v=y.array.slice(x,x+E),T=new p.Int32BufferAttribute(v,1);if(f.setAttribute("tileObjectId",T),b){const _=b.array.slice(C,C+w);for(let A=0;A<_.length;A++)_[A]-=x;f.setIndex(new p.BufferAttribute(_,1))}}f.applyMatrix4(o.matrixWorld),s.push(f)}}}}),P.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?Pe.mergeGeometries(s):s[0]}parseTile(e,i,s){this.onBeforeParseTile&&this.onBeforeParseTile(i),i._loadIndex=i._loadIndex||0,i._loadIndex++;const n=i.cached,r=n.transform;return new $1().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{P.debug("[BimTiles] batchedMeshes:",o),P.debug("[BimTiles] instancedMeshes:",l);const h=new p.Group;h.name="TileGroup";const d=new p.Group;d.name="TileGroup-pick",o.forEach(f=>{const{mesh:m,pickMesh:b,batchTable:y}=this.createBatchedMesh(f);h.add(m),m.userData.batchTable=y,m.userData.userIds=y.map(C=>C.userId),d.add(b)}),l.forEach(f=>{const{mesh:m,pickMesh:b,userIds:y}=this.createInstancedMesh(f);h.add(m),m.userData.userIds=y,d.add(b)});const u=f=>{f.applyMatrix4(r)};u(h),h.traverse(f=>{f[Jo]=f.frustumCulled}),Q1(h,!this.autoDisableRendererCulling),u(d),n.scene=h,n.pickScene=d,this.onLoadModel&&this.onLoadModel(h,i)})}disposeTile(e){const i=e.cached;if(i.scene){const s=n=>{n.traverse(r=>{r.geometry&&r.geometry.dispose()}),n.removeFromParent()};s(i.scene),i.pickScene&&s(i.pickScene),this.onDisposeModel&&this.onDisposeModel(i.scene,e),i.scene=null,i.pickScene=null,i.materials=null,i.textures=null,i.geometry=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}preprocessNode(e,i,s){super.preprocessNode(e,i,s),Array.isArray(e.boundingVolume)&&(Zn.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(Zn.getCenter(Ws),Zn.getSize(Ys),e.cached.boundingVolume.setObbData([Ws.x,Ws.y,Ws.z,Ys.x/2,0,0,0,Ys.y/2,0,0,0,Ys.z/2],e.cached.transform)))}async fetchTileSet(e,i,s){return fetch(e,i).then(n=>{if(n.ok)return n.json();throw new Error('BimTilesRenderer: Failed to load tileset "'+e+'" with status '+n.status+" : "+n.statusText)}).then(async n=>{const{material:r,userData:a,userId:o,userIdBox:l}=n.properties,h=[];if(r.url){const u=this.propertyParser.getProperty(r.url,i,"PBMaterials").then(f=>this.propertyParser.parseMaterial(f));h.push(u)}if(a.url){const u=this.propertyParser.getProperty(a.url,i,"PBUserData").then(f=>this.propertyParser.parseUserData(f));h.push(u)}if(o.url){const u=this.propertyParser.getProperty(o.url,i,"PBUserId").then(f=>this.propertyParser.parseUserId(f));h.push(u)}if(l.url){const u=this.propertyParser.getProperty(l.url,i,"PBUserIdBox").then(f=>this.propertyParser.parseUserIdBox(f,this.group.matrix));h.push(u)}await Promise.all(h);let d=e.replace(/\/[^\\/]*\/?$/,"");return d=new URL(d,window.location.href).toString(),this.preprocessNode(n.root,d,s),this.onLoadTileSet&&Promise.resolve().then(()=>{this.onLoadTileSet(n)}),n})}loadRootTileSet(e){const i=this.tileSets;if(e in i)return i[e]instanceof Error?Promise.reject(i[e]):Promise.resolve(i[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then(n=>{i[e]=n,this.materialManager=new q1(this,{maxId:n.properties.userId.maxUserIdIndex})});return s.catch(n=>{P.error("[BimTiles] loadRootTileSet error:",n),i[e]=n}),i[e]=s,s}}update(){super.update()}setTileVisible(e,i){const{scene:s,pickScene:n}=e.cached,r=this.visibleTiles,a=this.group;i?(r.add(e),a.add(s),this.pickUsage.add(n),s.updateMatrixWorld(!0),n.updateMatrixWorld(!0)):(r.delete(e),a.remove(s),this.pickUsage.remove(n)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,i)}calculateError(e){const i=e.cached,s=i.inFrustum,n=this.cameras,r=this.cameraInfo,a=i.boundingVolume;let o=-1/0,l=1/0;for(let h=0,d=n.length;h<d;h++){if(!s[h])continue;const u=r[h],f=u.invScale;let m;if(u.isOrthographic){const b=u.pixelSize;m=e.geometricError/(b*f)}else{const b=a.distanceToPoint(u.position),y=b*f,C=u.sseDenominator;m=e.geometricError/(y*C),l=Math.min(l,y)}o=Math.max(o,m)}e.__distanceFromCamera=l,e.__error=o}}class Rr extends vn{constructor(e,i,s){super();g(this,"modelId");g(this,"_bbox");g(this,"tilesRenderer");g(this,"metadata");g(this,"statistics");this.modelId=e.modelId;const n=i+s.getMetadata().root;this.tilesRenderer=new Qo(n,Number(this.modelId)),this._bbox=e.bbox,this.metadata=s.getMetadata(),this.statistics=s.getStatistics()}getTilesRenderer(){return this.tilesRenderer}get materialManager(){return this.tilesRenderer.materialManager}get propertyParser(){return this.tilesRenderer.propertyParser}get highlighUsageGroup(){return this.tilesRenderer.highlighUsage}get transparentUsageGroup(){return this.tilesRenderer.transparentUsage}get pickUsageGroup(){return this.tilesRenderer.pickUsage}getModelObject(){return this.tilesRenderer.group}traverseObjectByUserId(e,i){if(i.userData.userIds){const n=i.userData.userIds;for(let r=0,a=n.length;r<a;r++)if(n[r]===e)return i}const s=i.children;for(let n=0,r=s.length;n<r;n++)if(this.traverseObjectByUserId(e,s[n]))return s[n]}getObjectByUserId(e){let i;return this.tilesRenderer.visibleTiles.forEach(s=>{i=this.traverseObjectByUserId(e,s.cached.scene)}),i}getBBox(){return this._bbox||(this._bbox=new p.Box3,this._bbox.setFromObject(this.getModelObject())),this._bbox}setObjectHoveredByUserId(e,i){this.materialManager.updateState(ii.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(ii.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(ii.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(ii.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(ii.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(ii.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function eu(){let c=new Map;return{on(t,e){const i=c.get(t);i?i.push(e):c.set(t,[e])},off(t,e){const i=c.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):c.set(t,[]))},emit(t,e){const i=c.get(t);i&&i.slice().map(s=>s(e)),c.get("*")&&c.get("*").slice().map(s=>s(t,e))}}}class tu{constructor(t){g(this,"viewer");g(this,"element");g(this,"content");g(this,"itemList");g(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(le.ModelLoad,()=>{this.init()})}init(){const t=document.createElement("div");t.classList.add("model-layout-switch-bar");const e=document.createElement("div");e.classList.add("model-layout-switch-bar-content"),e.addEventListener("wheel",this.handleMouseWheel),this.viewer.getLayoutNames().forEach((i,s)=>{const n=this.createItem(i,s);this.itemList[i]=n,n.resetActivate=()=>{for(const r in this.itemList)this.itemList[r].resetActive()},e?.appendChild(n.element)}),this.element=t,this.content=e,this.element.appendChild(this.content),this.viewer.widgetContainer?.appendChild(this.element)}createItem(t,e){const i=new iu(this.viewer,t);return e===0&&i.setActive(!0),i}destroy(){for(const t in this.itemList){const e=this.itemList[t];e.destroy(),this.content?.removeChild(e.element)}this.itemList={},this.element&&this.content&&(this.element.removeChild(this.content),this.element.removeEventListener("wheel",this.handleMouseWheel),this.viewer.widgetContainer?.removeChild(this.element),this.element=void 0)}show(){this.element&&(this.element.style.display="block")}hide(){this.element&&(this.element.style.display="none")}}class iu{constructor(t,e){g(this,"viewer");g(this,"eventBus");g(this,"element");g(this,"resetActivate");g(this,"active");this.viewer=t,this.eventBus=eu(),this.active=!1,this.element=this.createItem(e),this.eventBus.on("activechange",i=>{this.resetActivate&&this.resetActivate(),i?(this.element.classList.add("activate"),this.viewer.activateLayout(e)):this.element.classList.remove("activate")})}createItem(t){const e=document.createElement("div"),i=document.createElement("span");return e.classList.add("model-layout-switch-item"),e.onclick=()=>{this.active=!this.active,this.eventBus.emit("activechange",this.active)},i.innerText=t,e.appendChild(i),e}setActive(t){this.active!==t&&(this.active=t,this.eventBus.emit("activechange",t))}resetActive(){this.active=!1,this.element.classList.remove("activate")}destroy(){this.eventBus.off("activechange")}}class el{constructor(t){g(this,"element");g(this,"jobCount");this.jobCount=0;const e=document.createElement("div");e.classList.add("x-spinner");for(let s=0;s<4;s++)e.appendChild(document.createElement("span"));const i=t?.widgetContainer;i&&i.appendChild(e),this.element=e,this.setSpinnerVisibility(this.jobCount>0)}setSpinnerVisibility(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){if(this.jobCount<=0){console.warn("[Viewer] jobCount should be at least 1 here!");return}this.setSpinnerVisibility(--this.jobCount>0)}destroy(){this.element.remove(),this.jobCount=0}}class Fr{constructor(t){g(this,"width");g(this,"height");g(this,"container");g(this,"viewerContainer");g(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(P.warn("[Container] containerId:",t,"is not found in dom tree! will append to document body"),e=document.body);const i=document.createElement("div");i.classList.add("x-container"),i.style.cssText="width: 100%; height: 100%; position: relative;",e.appendChild(i),this.container=i,this.width=e.clientWidth,this.height=e.clientHeight,this.initViewerContainer(),this.initWidgetContainer()}initViewerContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-viewer-container"),e.style.cssText="width: 100%; height: 100%; display: inline-block; position: relative; overflow: hidden;",t.appendChild(e),this.viewerContainer=e}initWidgetContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-widget-container"),t.appendChild(e),this.widgetContainer=e}get needResize(){const t=this.width!==this.container.clientWidth||this.height!==this.container.clientHeight;return t&&(this.width=this.container.clientWidth,this.height=this.container.clientHeight),t}destroy(){this.widgetContainer&&(this.widgetContainer.remove(),this.widgetContainer=void 0),this.viewerContainer&&(this.viewerContainer.remove(),this.viewerContainer=void 0),this.container.remove()}}class zr{constructor(t){g(this,"element");g(this,"progressItems");g(this,"replaceReg");this.progressItems=new Map,this.replaceReg=new RegExp(/<em>[\s\S]*<\/em>/,"g");const e=document.createElement("div");e.classList.add("progress-bar"),t?.widgetContainer?.appendChild(e),this.element=e}addProgressItem(t,e="ProgressBar.Loading",i){this.progressItems.get(t)&&P.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=Qe.t(e)+": <em></em>",this.element.append(s),this.progressItems.set(t,{div:s,onProgress:i})}removeProgressItem(t){this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t),this.progressItems.size===0&&this.setVisible(!1)}updateProgress(t,e,i){const s=this.progressItems.get(t);if(!s)return;let n=e?""+e:"";e&&i!=null&&(n+=": "),i!=null&&(i<0||i>100?(console.warn("[ProgressBar] Invalid progress value: "+i),n+="--%"):n+=i.toFixed(2)+"%"),s.div.innerHTML=n}updateProgressBar(t,e,i=0,s=100){const n=this.progressItems.get(t);if(!n)return;const r=e instanceof ProgressEvent?e.loaded:e,a=e instanceof ProgressEvent?e.total:100,o=r*100/a*(s-i)/100+i;n.div.innerHTML=n.div.innerHTML.replace(this.replaceReg,"<em>"+(o<0||o>100?"--":o.toFixed(2))+"%</em>"),n.onProgress?.call(n,new ProgressEvent("LoadProgress",{loaded:r,total:100}))}setVisible(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}delayRemoveProgressItem(t,e=3e3){setTimeout(()=>{this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t)},e)}destroy(){this.progressItems.forEach(t=>{t.div.remove()}),this.progressItems.clear(),this.element.remove()}}var Ke=(c=>(c.BaseViewer="BaseViewer",c.Viewer3d="Viewer3d",c.Viewer2d="Viewer2d",c.BimTilesViewer="BimTilesViewer",c))(Ke||{}),xt=(c=>(c.Perspective="Perspective",c.Orthographic="Orthographic",c))(xt||{});const su={enableSpinner:!0,containerId:"myCanvas"},W={LEFT:1,RIGHT:2,MIDDLE:4},R=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function rt(c){return c.isPerspectiveCamera}function Ue(c){return c.isOrthographicCamera}class nu{constructor(){g(this,"_listeners");this._listeners={}}addEventListener(t,e){const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t)}}}const xi=Math.PI*2,$a=Math.PI/2;function Kn(c,t){t.set(0,0),c.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=c.length,t.y/=c.length}function $n(c,t){return Ue(c)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const tl=1e-5,Qi=Math.PI/180;function Ei(c,t,e){return Math.max(t,Math.min(e,c))}function ae(c,t=tl){return Math.abs(c)<t}function re(c,t,e=tl){return ae(c-t,e)}function Ja(c,t){return Math.round(c/t)*t}function es(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ts(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function Xs(c,t,e,i,s=1/0,n){i=Math.max(1e-4,i);const r=2/i,a=r*n,o=1/(1+a+.48*a*a+.235*a*a*a);let l=c-t;const h=t,d=s*i;l=Ei(l,-d,d),t=c-l;const u=(e.value+r*l)*n;e.value=(e.value-r*u)*o;let f=t+(l+u)*o;return h-c>0==f>h&&(f=h,e.value=(f-h)/n),f}function Qa(c,t,e,i,s=1/0,n,r){i=Math.max(1e-4,i);const a=2/i,o=a*n,l=1/(1+o+.48*o*o+.235*o*o*o);let h=t.x,d=t.y,u=t.z,f=c.x-h,m=c.y-d,b=c.z-u;const y=h,C=d,w=u,x=s*i,E=x*x,M=f*f+m*m+b*b;if(M>E){const L=Math.sqrt(M);f=f/L*x,m=m/L*x,b=b/L*x}h=c.x-f,d=c.y-m,u=c.z-b;const O=(e.x+a*f)*n,S=(e.y+a*m)*n,v=(e.z+a*b)*n;e.x=(e.x-a*O)*l,e.y=(e.y-a*S)*l,e.z=(e.z-a*v)*l,r.x=h+(f+O)*l,r.y=d+(m+S)*l,r.z=u+(b+v)*l;const T=y-c.x,_=C-c.y,A=w-c.z,I=r.x-y,B=r.y-C,k=r.z-w;return T*I+_*B+A*k>0&&(r.x=y,r.y=C,r.z=w,e.x=(r.x-y)/n,e.y=(r.y-C)/n,e.z=(r.z-w)/n),r}const Zs=1/8,ru=Be.isBrowser&&/Mac/.test(navigator.platform),au=!(Be.isBrowser&&"PointerEvent"in window);let q,eo,Ks,Jn,ze,Y,te,bi,pt,mt,Qt,to,io,st,is,wi,so,Qn,no,er,tr,$s;class $ extends nu{constructor(e,i){super();g(this,"minPolarAngle");g(this,"maxPolarAngle");g(this,"minAzimuthAngle");g(this,"maxAzimuthAngle");g(this,"minDistance");g(this,"maxDistance");g(this,"infinityDolly");g(this,"minZoom");g(this,"maxZoom");g(this,"smoothTime");g(this,"draggingSmoothTime");g(this,"maxSpeed");g(this,"azimuthRotateSpeed");g(this,"polarRotateSpeed");g(this,"dollySpeed");g(this,"truckSpeed");g(this,"dollyToCursor");g(this,"dragToOffset");g(this,"verticalDragToForward");g(this,"boundaryFriction");g(this,"restThreshold");g(this,"colliderMeshes");g(this,"mouseButtons");g(this,"touches");g(this,"cancel");g(this,"_enabled");g(this,"_camera");g(this,"_yAxisUpSpace");g(this,"_yAxisUpSpaceInverse");g(this,"_state");g(this,"_domElement");g(this,"_viewport");g(this,"_target");g(this,"_targetEnd");g(this,"_focalOffset");g(this,"_focalOffsetEnd");g(this,"_spherical");g(this,"_sphericalEnd");g(this,"_zoom");g(this,"_zoomEnd");g(this,"_target0");g(this,"_position0");g(this,"_zoom0");g(this,"_focalOffset0");g(this,"_dollyControlAmount");g(this,"_dollyControlCoord");g(this,"_nearPlaneCorners");g(this,"_hasRested");g(this,"_boundary");g(this,"_boundaryEnclosesCamera");g(this,"_needsUpdate");g(this,"_updatedLastTime");g(this,"_elementRect");g(this,"_activePointers");g(this,"_isUserControllingRotate");g(this,"_isUserControllingDolly");g(this,"_isUserControllingTruck");g(this,"_isUserControllingOffset");g(this,"_isUserControllingZoom");g(this,"_thetaVelocity");g(this,"_phiVelocity");g(this,"_radiusVelocity");g(this,"_targetVelocity");g(this,"_focalOffsetVelocity");g(this,"_zoomVelocity");g(this,"_truckInternal");g(this,"_rotateInternal");g(this,"_dollyInternal");g(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=R.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=Be.isBrowser?new DOMRect:{x:0,y:0,width:0,height:0,left:0,right:0,top:0,bottom:0},this._activePointers=[],this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new q.Vector3,this._focalOffsetVelocity=new q.Vector3,this._zoomVelocity={value:0},this._truckInternal=(x,E,M)=>{if(rt(this._camera)){const O=Y.copy(this._camera.position).sub(this._target),S=this._camera.getEffectiveFOV()*Qi,v=O.length()*Math.tan(S*.5),T=this.truckSpeed*x*v/this._elementRect.height,_=this.truckSpeed*E*v/this._elementRect.height;this.verticalDragToForward?(M?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(T,0,!0),this.forward(-_,!0)):M?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y+_,this._focalOffsetEnd.z,!0):this.truck(T,_,!0)}else if(Ue(this._camera)){const O=this._camera,S=this.truckSpeed*x*(O.right-O.left)/O.zoom/this._elementRect.width,v=this.truckSpeed*E*(O.top-O.bottom)/O.zoom/this._elementRect.height;M?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(S,v,!0)}},this._rotateInternal=(x,E)=>{const M=xi*this.azimuthRotateSpeed*x/this._elementRect.height,O=xi*this.polarRotateSpeed*E/this._elementRect.height;this.rotate(M,O,!0)},this._dollyInternal=(x,E,M)=>{const O=Math.pow(.95,-x*this.dollySpeed),S=this._sphericalEnd.radius*O,v=this._sphericalEnd.radius,T=v*(x>=0?-1:1);this.dollyTo(S),this.infinityDolly&&(S<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(Y),this._targetEnd.add(Y.normalize().multiplyScalar(T)),this._target.add(Y.normalize().multiplyScalar(T))),this.dollyToCursor&&(this._dollyControlAmount+=this._sphericalEnd.radius-v,this.infinityDolly&&(S<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=T),this._dollyControlCoord.set(E,M))},this._zoomInternal=(x,E,M)=>{const O=Math.pow(.95,x*this.dollySpeed),S=this._zoomEnd;this.zoomTo(this._zoom*O),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-S,this._dollyControlCoord.set(E,M))},typeof q>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new q.Quaternion().setFromUnitVectors(this._camera.up,Ks),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=R.NONE,this._target=new q.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new q.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new q.Spherical().setFromVector3(Y.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new q.Vector3,new q.Vector3,new q.Vector3,new q.Vector3],this._updateNearPlaneCorners(),this._boundary=new q.Box3(new q.Vector3(-1/0,-1/0,-1/0),new q.Vector3(1/0,1/0,1/0)),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlAmount=0,this._dollyControlCoord=new q.Vector2,this.mouseButtons={left:R.ROTATE,middle:R.DOLLY,right:R.TRUCK,wheel:rt(this._camera)?R.DOLLY:Ue(this._camera)?R.ZOOM:R.NONE},this.touches={one:R.TOUCH_ROTATE,two:rt(this._camera)?R.TOUCH_DOLLY_TRUCK:Ue(this._camera)?R.TOUCH_ZOOM_TRUCK:R.NONE,three:R.TOUCH_TRUCK};const s=new q.Vector2,n=new q.Vector2,r=new q.Vector2,a=x=>{if(!this._enabled||!this._domElement)return;const E=x.pointerType!=="mouse"?null:(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.MIDDLE?W.MIDDLE:(x.buttons&W.RIGHT)===W.RIGHT?W.RIGHT:null;if(E!==null){const O=this._findPointerByMouseButton(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const M={pointerId:x.pointerId,clientX:x.clientX,clientY:x.clientY,deltaX:0,deltaY:0,mouseButton:E};this._activePointers.push(M),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",d),y(x)},o=x=>{if(!this._enabled||!this._domElement)return;const E=(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.MIDDLE?W.MIDDLE:(x.buttons&W.RIGHT)===W.RIGHT?W.RIGHT:null;if(E!==null){const O=this._findPointerByMouseButton(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const M={pointerId:0,clientX:x.clientX,clientY:x.clientY,deltaX:0,deltaY:0,mouseButton:(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.LEFT?W.MIDDLE:(x.buttons&W.RIGHT)===W.LEFT?W.RIGHT:null};this._activePointers.push(M),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u),this._domElement.addEventListener("mousemove",h),this._domElement.addEventListener("mouseup",u),y(x)},l=x=>{const E=x.pointerId,M=this._findPointerById(E);if(M){if(M.clientX=x.clientX,M.clientY=x.clientY,M.deltaX=x.movementX,M.deltaY=x.movementY,x.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right);C()}},h=x=>{const E=this._findPointerById(0);E&&(E.clientX=x.clientX,E.clientY=x.clientY,E.deltaX=x.movementX,E.deltaY=x.movementY,this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right),C())},d=x=>{const E=x.pointerId,M=this._findPointerById(E);if(M&&this._activePointers.splice(this._activePointers.indexOf(M),1),x.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=R.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=R.NONE;w()},u=()=>{const x=this._findPointerById(0);x&&this._activePointers.splice(this._activePointers.indexOf(x),1),this._state=R.NONE,w()};let f=-1;const m=x=>{if(!this._enabled||this.mouseButtons.wheel===R.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===R.ROTATE||this.mouseButtons.wheel===R.TRUCK){const v=performance.now();f-v<1e3&&this._getClientRect(this._elementRect),f=v}const E=ru?-1:-3,M=x.deltaMode===1?x.deltaY/E:x.deltaY/(E*10),O=this.dollyToCursor?(x.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(x.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case R.ROTATE:{this._rotateInternal(x.deltaX,x.deltaY),this._isUserControllingRotate=!0;break}case R.TRUCK:{this._truckInternal(x.deltaX,x.deltaY,!1),this._isUserControllingTruck=!0;break}case R.OFFSET:{this._truckInternal(x.deltaX,x.deltaY,!0),this._isUserControllingOffset=!0;break}case R.DOLLY:{this._dollyInternal(-M,O,S),this._isUserControllingDolly=!0;break}case R.ZOOM:{this._zoomInternal(-M,O,S),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},b=x=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===$.ACTION.NONE){const E=x instanceof PointerEvent?x.pointerId:(x instanceof MouseEvent,0),M=this._findPointerById(E);M&&this._activePointers.splice(this._activePointers.indexOf(M),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u);return}},y=x=>{if(!this._enabled)return;if(Kn(this._activePointers,ze),this._getClientRect(this._elementRect),s.copy(ze),n.copy(ze),this._activePointers.length>=2){const M=ze.x-this._activePointers[1].clientX,O=ze.y-this._activePointers[1].clientY,S=Math.sqrt(M*M+O*O);r.set(0,S);const v=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,T=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;n.set(v,T)}if("pointerType"in x&&x.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&R.DOLLY)===R.DOLLY||(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&R.ZOOM)===R.ZOOM||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},C=()=>{if(!this._enabled)return;Kn(this._activePointers,ze);const x=Be.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,E=x?-this._activePointers[0].deltaX:n.x-ze.x,M=x?-this._activePointers[0].deltaY:n.y-ze.y;if(n.copy(ze),((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(E,M),this._isUserControllingRotate=!0),(this._state&R.DOLLY)===R.DOLLY||(this._state&R.ZOOM)===R.ZOOM){const O=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.DOLLY)===R.DOLLY?(this._dollyInternal(M*Zs,O,S),this._isUserControllingDolly=!0):(this._zoomInternal(M*Zs,O,S),this._isUserControllingZoom=!0)}if((this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE){const O=ze.x-this._activePointers[1].clientX,S=ze.y-this._activePointers[1].clientY,v=Math.sqrt(O*O+S*S),T=r.y-v;r.set(0,v);const _=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET?(this._dollyInternal(T*Zs,_,A),this._isUserControllingDolly=!0):(this._zoomInternal(T*Zs,_,A),this._isUserControllingZoom=!0)}((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(E,M,!1),this._isUserControllingTruck=!0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(E,M,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},w=()=>{Kn(this._activePointers,ze),n.copy(ze),this._activePointers.length===0&&this._domElement&&(this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u),this.dispatchEvent({type:"controlend"}))};this._addAllEventListeners=x=>{this._domElement=x,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),au&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",d),this._domElement.addEventListener("wheel",m,{passive:!1}),this._domElement.addEventListener("contextmenu",b)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",d),this._domElement.removeEventListener("wheel",m),this._domElement.removeEventListener("contextmenu",b),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u))},this.cancel=()=>{this._state!==R.NONE&&(this._state=R.NONE,this._activePointers.length=0,w())},i&&this.connect(i),this.update(0)}static install(e){q=e.THREE,eo=Object.freeze(new q.Vector3(0,0,0)),Ks=Object.freeze(new q.Vector3(0,1,0)),Jn=Object.freeze(new q.Vector3(0,0,1)),ze=new q.Vector2,Y=new q.Vector3,te=new q.Vector3,bi=new q.Vector3,pt=new q.Vector3,mt=new q.Vector3,Qt=new q.Vector3,to=new q.Vector3,io=new q.Vector3,st=new q.Spherical,is=new q.Spherical,wi=new q.Box3,so=new q.Box3,Qn=new q.Sphere,no=new q.Quaternion,er=new q.Quaternion,tr=new q.Matrix4,$s=new q.Raycaster}static get ACTION(){return R}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const n=Ei(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=Ei(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,n=Ei(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=re(o,this._spherical.radius);if(!(s>n)&&l)return Promise.resolve();this._sphericalEnd.radius=Math.min(n,o)}else this._sphericalEnd.radius=n;this._needsUpdate=!0,i||(this._spherical.radius=this._sphericalEnd.radius);const a=!i||re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Ei(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||re(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),pt.multiplyScalar(e),mt.multiplyScalar(-i);const n=Y.copy(pt).add(mt),r=te.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,i=!1){Y.setFromMatrixColumn(this._camera.matrix,0),Y.crossVectors(this._camera.up,Y),Y.multiplyScalar(e);const s=te.copy(this._targetEnd).add(Y);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return Y.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+Y.x,this._targetEnd.y+Y.y,this._targetEnd.z+Y.z,i)}moveTo(e,i,s,n=!1){this._isUserControllingTruck=!1;const r=Y.set(e,i,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,n||this._target.copy(this._targetEnd);const a=!n||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,n=!1){const o=Y.set(e,i,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,n)}fitToBox(e,i,{cover:s=!1,paddingLeft:n=0,paddingRight:r=0,paddingBottom:a=0,paddingTop:o=0}={}){const l=[],h=e.isBox3?wi.copy(e):wi.setFromObject(e);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const d=Ja(this._sphericalEnd.theta,$a),u=Ja(this._sphericalEnd.phi,$a);l.push(this.rotateTo(d,u,i));const f=Y.setFromSpherical(this._sphericalEnd).normalize(),m=no.setFromUnitVectors(f,Jn),b=re(Math.abs(f.y),1);b&&m.multiply(er.setFromAxisAngle(Ks,d)),m.multiply(this._yAxisUpSpaceInverse);const y=so.makeEmpty();te.copy(h.min).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setX(h.max.x).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setY(h.max.y).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setZ(h.min.z).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setZ(h.max.z).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setY(h.min.y).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setX(h.min.x).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).applyQuaternion(m),y.expandByPoint(te),y.min.x-=n,y.min.y-=a,y.max.x+=r,y.max.y+=o,m.setFromUnitVectors(Jn,f),b&&m.premultiply(er.invert()),m.premultiply(this._yAxisUpSpace);const C=y.getSize(Y),w=y.getCenter(te).applyQuaternion(m);if(rt(this._camera)){const x=this.getDistanceToFitBox(C.x,C.y,C.z,s);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.dollyTo(x,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(Ue(this._camera)){const x=this._camera,E=x.right-x.left,M=x.top-x.bottom,O=s?Math.max(E/C.x,M/C.y):Math.min(E/C.x,M/C.y);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.zoomTo(O,i)),l.push(this.setFocalOffset(0,0,0,i))}return Promise.all(l)}fitToSphere(e,i){const s=[],r=e instanceof q.Sphere?Qn.copy(e):$.createBoundingSphere(e,Qn);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,i)),rt(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,i))}else if(Ue(this._camera)){const a=this._camera,o=a.right-a.left,l=a.top-a.bottom,h=2*r.radius,d=Math.min(o/h,l/h);s.push(this.zoomTo(d,i))}return s.push(this.setFocalOffset(0,0,0,i)),Promise.all(s)}setLookAt(e,i,s,n,r,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const l=te.set(n,r,a),h=Y.set(e,i,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(h.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const d=!o||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold)&&re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(d)}lerpLookAt(e,i,s,n,r,a,o,l,h,d,u,f,m,b=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const y=Y.set(n,r,a),C=te.set(e,i,s);st.setFromVector3(C.sub(y).applyQuaternion(this._yAxisUpSpace));const w=bi.set(d,u,f),x=te.set(o,l,h);is.setFromVector3(x.sub(w).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(w,m));const E=is.theta-st.theta,M=is.phi-st.phi,O=is.radius-st.radius;this._sphericalEnd.set(st.radius+O*m,st.phi+M*m,st.theta+E*m),this.normalizeRotations(),this._needsUpdate=!0,b||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const S=!b||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold)&&re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(S)}setPosition(e,i,s,n=!1){return this.setLookAt(e,i,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,n)}setTarget(e,i,s,n=!1){const r=this.getPosition(Y),a=this.setLookAt(r.x,r.y,r.z,e,i,s,n);return this._sphericalEnd.phi=Ei(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||re(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&re(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&re(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),mt.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Qt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=Y.set(e,i,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);pt.multiplyScalar(a.x),mt.multiplyScalar(a.y),Qt.multiplyScalar(a.z),Y.copy(pt).add(mt).add(Qt),Y.z=Y.z+r,this.dollyTo(r,!1),this.setFocalOffset(-Y.x,Y.y,-Y.z,!1),this.moveTo(e,i,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,i,s,n){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new q.Vector4,typeof e=="number"?this._viewport.set(e,i,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,n=!1){if($n(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/i,a=this._camera.getEffectiveFOV()*Qi,o=this._camera.aspect;return((n?r>o:r<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if($n(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*Qi,s=Math.atan(Math.tan(i*.5)*this._camera.aspect)*2,n=1<this._camera.aspect?i:s;return e/Math.sin(n*.5)}getTarget(e){return(e&&e.isVector3?e:new q.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new q.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new q.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%xi,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=xi),this._spherical.theta+=xi*Math.round((this._sphericalEnd.theta-this._spherical.theta)/xi)}reset(e=!1){const i=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(i)}saveState(){this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Ks),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert}update(e){const i=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,n=this._sphericalEnd.radius-this._spherical.radius,r=to.subVectors(this._targetEnd,this._target),a=io.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ae(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Xs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(ae(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Xs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(ae(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Xs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(ae(r.x)&&ae(r.y)&&ae(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Qa(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ae(a.x)&&ae(a.y)&&ae(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Qa(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(rt(this._camera)){const u=this._camera,f=Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),m=te.copy(f).cross(u.up).normalize();m.lengthSq()===0&&(m.x=1);const b=bi.crossVectors(m,f),y=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*Qi*.5),w=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,x=Y.copy(this._targetEnd).add(m.multiplyScalar(this._dollyControlCoord.x*y*u.aspect)).add(b.multiplyScalar(this._dollyControlCoord.y*y));this._targetEnd.lerp(x,w)}else if(Ue(this._camera)){const u=this._camera,f=Y.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),m=te.set(0,0,-1).applyQuaternion(u.quaternion),b=bi.copy(f).add(m.multiplyScalar(-f.dot(u.up))),C=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,w=Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),x=this._targetEnd.dot(w);this._targetEnd.lerp(b,C);const E=this._targetEnd.dot(w),M=w.multiplyScalar(E-x);this._targetEnd.sub(M)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ae(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Xs(this._zoom,this._zoomEnd,this._zoomVelocity,u,1/0,e)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0);const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!ae(this._focalOffset.x)||!ae(this._focalOffset.y)||!ae(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),Qt.setFromMatrixColumn(this._camera.matrix,2),pt.multiplyScalar(this._focalOffset.x),mt.multiplyScalar(-this._focalOffset.y),Qt.multiplyScalar(this._focalOffset.z),Y.copy(pt).add(mt).add(Qt),this._camera.position.add(Y)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const d=this._needsUpdate;return d&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):d?(this.dispatchEvent({type:"update"}),ae(i,this.restThreshold)&&ae(s,this.restThreshold)&&ae(n,this.restThreshold)&&ae(r.x,this.restThreshold)&&ae(r.y,this.restThreshold)&&ae(r.z,this.restThreshold)&&ae(a.x,this.restThreshold)&&ae(a.y,this.restThreshold)&&ae(a.z,this.restThreshold)&&ae(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!d&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._updatedLastTime=d,this._needsUpdate=!1,d}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:es(this.maxDistance),minZoom:this.minZoom,maxZoom:es(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:es(this.maxPolarAngle),minAzimuthAngle:es(this.minAzimuthAngle),maxAzimuthAngle:es(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:Y.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,i=!1){const s=JSON.parse(e),n=Y.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ts(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ts(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ts(s.maxPolarAngle),this.minAzimuthAngle=ts(s.minAzimuthAngle),this.maxAzimuthAngle=ts(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],i),st.setFromVector3(n.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(st.theta,st.phi,i),this.zoomTo(s.zoom,i),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],i),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(e)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_findPointerById(e){return this._activePointers.find(i=>i.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(i=>i.mouseButton===e)}_encloseToBoundary(e,i,s){const n=i.lengthSq();if(n===0)return e;const r=te.copy(i).add(e),o=this._boundary.clampPoint(r,bi).sub(r),l=o.lengthSq();if(l===0)return e.add(i);if(l===n)return e;if(s===0)return e.add(i).add(o);{const h=1+s*l/i.dot(o);return e.add(te.copy(i).multiplyScalar(h)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(rt(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*Qi,n=Math.tan(s*.5)*i,r=n*e.aspect;this._nearPlaneCorners[0].set(-r,-n,0),this._nearPlaneCorners[1].set(r,-n,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(-r,n,0)}else if(Ue(this._camera)){const e=this._camera,i=1/e.zoom,s=e.left*i,n=e.right*i,r=e.top*i,a=e.bottom*i;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(n,r,0),this._nearPlaneCorners[2].set(n,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||$n(this._camera,"_collisionTest"))return e;const s=Y.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);tr.lookAt(eo,s,this._camera.up);for(let n=0;n<4;n++){const r=te.copy(this._nearPlaneCorners[n]);r.applyMatrix4(tr);const a=bi.addVectors(this._target,r);$s.set(a,s),$s.far=this._spherical.radius+1;const o=$s.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<e&&(e=o[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const i=this._domElement.getBoundingClientRect();return e.x=i.left,e.y=i.top,this._viewport?(e.x+=this._viewport.x,e.y+=i.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=i.width,e.height=i.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(i=>{const s=()=>{this.removeEventListener("rest",s),i()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}static createBoundingSphere(e,i=new q.Sphere){const s=i,n=s.center;wi.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&wi.expandByObject(a)}),wi.getCenter(n);let r=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a,l=o.geometry.clone();if(l.applyMatrix4(o.matrixWorld),l.isBufferGeometry){const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)Y.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(Y))}else{const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)Y.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(Y))}}),s.radius=Math.sqrt(r),s}}var ot=(c=>(c[c.Orbit=0]="Orbit",c[c.FirstPerson=1]="FirstPerson",c[c.Plan=2]="Plan",c))(ot||{});class il{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=ot.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:$.ACTION.ROTATE,middle:$.ACTION.DOLLY,right:$.ACTION.TRUCK,wheel:rt(t)?$.ACTION.DOLLY:Ue(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_ROTATE,two:rt(t)?$.ACTION.TOUCH_DOLLY_TRUCK:Ue(t)?$.ACTION.TOUCH_ZOOM_TRUCK:$.ACTION.NONE,three:$.ACTION.TOUCH_TRUCK},e.dollyToCursor=!0,e.azimuthRotateSpeed=1,e.polarRotateSpeed=1,e.minDistance=1,e.maxDistance=300,e.minZoom=3,this.cameraManager.cameraControls.truckSpeed=2}adjustCameraByBBox(t){const e=this.cameraManager.cameraControls,i=new p.Vector3;t.getSize(i);const s=i.length();e.minDistance=1,e.maxDistance=s*10,e.minZoom=3}}class sl{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=ot.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:$.ACTION.TRUCK,middle:$.ACTION.TRUCK,right:$.ACTION.TRUCK,wheel:rt(t)?$.ACTION.DOLLY:Ue(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_TRUCK,two:rt(t)?$.ACTION.TOUCH_DOLLY_TRUCK:Ue(t)?$.ACTION.TOUCH_ZOOM_TRUCK:$.ACTION.NONE,three:$.ACTION.NONE},e.dollyToCursor=!0,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0,e.truckSpeed=1,e.maxZoom=1/0,e.minZoom=-1/0}adjustCameraByBBox(t){}}const vi=50,ir=new p.Vector3;class ou{constructor(t){g(this,"viewer");g(this,"perspectiveCamera");g(this,"orthographicCamera");g(this,"activeCamera");g(this,"cameraControls");g(this,"previousDistance");g(this,"previousAzimuthRotateSpeed");g(this,"previousPolarRotateSpeed");g(this,"previousDollySpeed");g(this,"previousTruckSpeed");g(this,"previousMouseLeft");g(this,"enableKeyDown");g(this,"controlsMap");g(this,"activeControls");g(this,"projection");g(this,"anchor");g(this,"onKeyDown");g(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=$.ACTION.NONE,this.enableKeyDown=!0,this.projection=xt.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const n=this.cameraControls,r=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Ke.Viewer3d||this.viewer.name===Ke.BimTilesViewer;switch(s.code){case"ArrowLeft":a?n.rotate(.1,0,!0):this.viewer.name===Ke.Viewer2d&&n.truck(r,0,!0);break;case"ArrowRight":a?n.rotate(-.1,0,!0):this.viewer.name===Ke.Viewer2d&&n.truck(-r,0,!0);break;case"ArrowUp":a?n.rotate(0,.1,!0):this.viewer.name===Ke.Viewer2d&&n.truck(0,r,!0);break;case"ArrowDown":a?n.rotate(0,-.1,!0):this.viewer.name===Ke.Viewer2d&&n.truck(0,-r,!0);break;case"KeyW":a&&(Ue(this.activeCamera)?n.zoom(.01,!0):n.dolly(1,!0));break;case"KeyA":a&&n.truck(-r,0,!0);break;case"KeyS":a&&(Ue(this.activeCamera)?n.zoom(-.01,!0):n.dolly(-1,!0));break;case"KeyD":a&&n.truck(r,0,!0);break;case"KeyQ":a&&n.truck(0,-r,!0);break;case"KeyE":a&&n.truck(0,r,!0);break}},this.onChange=()=>{this.viewer.enableRender()},this.viewer=t;const e=t.viewerContainer,i=e.clientWidth/e.clientHeight;this.perspectiveCamera=new p.PerspectiveCamera(_o,i,on,ln),this.orthographicCamera=new p.OrthographicCamera(vi*i/-2,vi*i/2,vi/2,vi/-2,on,ln),this.activeCamera=this.perspectiveCamera,this.setupCameras(),$.install({THREE:p}),this.cameraControls=new $(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[ot.Orbit]:new il(this),[ot.Plan]:new sl(this)},this.activeControls=this.controlsMap[ot.Orbit],this.setupControls(),this.setProjection(xt.Perspective),this.anchor=this.createAnchor()}get viewerContainer(){return this.viewer.viewerContainer}get inputManager(){return this.viewer.getInputManager()}createAnchor(){const t=document.createElement("div");return t.className="anchor",this.viewerContainer?.appendChild(t),this.cameraControls.addEventListener("control",()=>{if(this.isOrbitPointVisible()){const e=this.getTarget(),i=Ee.world2Screen(e,this.activeCamera,this.viewerContainer);this.setAnchorPosition(i.x,i.y)}}),t}setAnchorPosition(t,e){this.anchor.style.left=t+"px",this.anchor.style.top=e+"px"}setOrbitPointVisible(t){t?this.anchor.classList.add("active"):this.anchor.classList.remove("active")}isOrbitPointVisible(){return this.anchor.classList.contains("active")}setOrthoCameraAspect(t,e){const i=t/e;this.orthographicCamera.left=-50*i/2,this.orthographicCamera.right=vi*i/2,this.orthographicCamera.top=vi/2,this.orthographicCamera.bottom=-50/2,this.orthographicCamera.updateProjectionMatrix()}setupCameras(){this.setCameraPositionAndTarget(this.perspectiveCamera)}setCameraPositionAndTarget(t){t.position.z=10,t.position.y=10,t.position.x=10,t.lookAt(new p.Vector3(0,0,0))}setupControls(){const t=this.cameraControls;t.smoothTime=.1,t.draggingSmoothTime=0,t.infinityDolly=!0,t.setTarget(0,0,0),t.addEventListener("controlstart",()=>this.onChange),t.addEventListener("control",()=>this.onChange),t.addEventListener("update",()=>this.viewer.dispatchEvent(le.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===ot.FirstPerson)return;this.previousDistance=this.cameraControls.distance,this.cameraControls.distance=200;const{width:t,height:e}=this.getDims();this.setupOrthoCamera(e,t),this.activeCamera=this.orthographicCamera,this.projection=xt.Orthographic}getDims(){const t=new p.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new p.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:n,clientHeight:r}=this.viewer.viewerContainer,a=n/r,o=this.perspectiveCamera.fov,l=s*2*Math.atan(o*(Math.PI/180)/2);return{width:l*a,height:l}}setupOrthoCamera(t,e){this.cameraControls.mouseButtons.wheel=$.ACTION.ZOOM;const i=this.perspectiveCamera,s=this.orthographicCamera;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this.cameraControls.camera=s}setPerspectiveCamera(){const t=this.cameraControls;t.mouseButtons.wheel=$.ACTION.DOLLY;const e=this.perspectiveCamera,i=this.orthographicCamera;e.position.copy(i.position),e.quaternion.copy(i.quaternion),e.updateProjectionMatrix(),t.camera=e,t.mouseButtons.wheel=$.ACTION.DOLLY,this.activeCamera=e,this.projection=xt.Perspective,t.distance=this.previousDistance,t.zoomTo(1)}update(t){const e=this.cameraControls.update(t);return this.camera.updateMatrixWorld(),e}updateAspect(){const{clientWidth:t,clientHeight:e}=this.viewer.viewerContainer;this.perspectiveCamera.aspect=t/e,this.perspectiveCamera.updateProjectionMatrix(),this.setOrthoCameraAspect(t,e)}get camera(){return this.activeCamera}enableKeyControl(t){this.enableKeyDown=t}getTarget(){return this.cameraControls.getTarget(ir)}getPosition(){return this.cameraControls.getPosition(ir)}adjustCameraByBBox(t){const e=this.camera.near,i=this.camera.far,s=new p.Vector3;t.getSize(s);const n=s.length(),r=5,a=n/r,o=n*r;if(e>a||i<o){const l=h=>j.numberToString(h);P.info("[Viewer] BBox's longest side is: "+l(n)),e>a&&(P.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(P.warn("[Viewer] camera.far("+l(i)+") shouldn't smaller than "+l(o)+", will change it!"),this.camera.far=o)}this.activeControls.adjustCameraByBBox(t),this.cameraControls.update(0)}enableControl(t){this.cameraControls.enabled=t}get enableRotate(){const t=this.cameraControls;return!!t.azimuthRotateSpeed||!!t.polarRotateSpeed}set enableRotate(t){const e=this.cameraControls;t?(e.azimuthRotateSpeed=this.previousAzimuthRotateSpeed,e.polarRotateSpeed=this.previousPolarRotateSpeed):(this.previousAzimuthRotateSpeed=e.azimuthRotateSpeed,this.previousPolarRotateSpeed=e.polarRotateSpeed,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0)}enableZoom(t){const e=this.cameraControls;t?e.dollySpeed=this.previousDollySpeed:(this.previousDollySpeed=e.dollySpeed,e.dollySpeed=0)}enablePan(t){const e=this.cameraControls;t?e.truckSpeed=this.previousTruckSpeed:(this.previousTruckSpeed=e.dollySpeed,e.truckSpeed=0)}enableMouseLeft(t){const e=this.cameraControls;t?e.mouseButtons.left=this.previousMouseLeft:(this.previousMouseLeft=e.mouseButtons.left,e.mouseButtons.left=$.ACTION.NONE)}setCameraPosition(t){this.cameraControls.setPosition(t.x,t.y,t.z)}setCameraTarget(t){this.cameraControls.setTarget(t.x,t.y,t.z)}flyTo(t,e,i=!0){const s=this.cameraControls;s.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,i),s.setFocalOffset(0,0,0,!0)}flyToPosition(t,e,i){this.cameraControls.moveTo(t,e,i,!0)}flyToBox(t,e){const i=new p.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new p.Box3().setFromObject(t),i=new p.Sphere;e.getBoundingSphere(i),this.cameraControls.fitToSphere(i,!0)}flyToViewpoint(t){this.flyTo(t.eye,t.look),t.zoom!=null&&(this.orthographicCamera.zoom=t.zoom)}getDistanceToFitSphere(t){return this.cameraControls.getDistanceToFitSphere(t)}setNavigationMode(t){this.activeControls.mode!==t&&(this.activeControls=this.controlsMap[t],this.activeControls.setupControl())}getProjection(){return this.projection}setProjection(t){this.projection!==t&&(this.projection=t,t===xt.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(ir)}getCameraConfig(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,near:this.activeCamera.near,far:this.activeCamera.far,zoom:this.activeCamera.zoom}}getCurrentViewpoint(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,zoom:this.activeCamera.zoom}}setCameraConfig(t){const e=this.cameraControls,{near:i=on,far:s=ln,up:n=new p.Vector3(0,1,0),zoom:r=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(n.x,n.y,n.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(r),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const ai=class ai extends Wo{tableName(){return"fonts"}static instance(){return!ai._instance&&(ai._instance=new ai),ai._instance}query(t){let e;return new Promise((i,s)=>{super.query(n=>{if(!n){i(e);return}!n.value||n.value.fileName!==t||(e=n.value)},n=>{s(n)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};g(ai,"_instance");let Fi=ai;var nl=(c=>(c[c.Horizontal=0]="Horizontal",c[c.Vertical=1]="Vertical",c[c.All=2]="All",c))(nl||{}),He=(c=>(c[c.Shapes=0]="Shapes",c[c.Bigfont=1]="Bigfont",c[c.Unifont=2]="Unifont",c))(He||{});class rl extends Gl.Font{constructor(e,i){super(i);g(this,"info");g(this,"orientation");g(this,"baseUp");g(this,"baseDown");g(this,"fileHeader");g(this,"fileVersion");g(this,"fileName");g(this,"data");g(this,"order");g(this,"unsupportedChars");this.info="",this.orientation=nl.Horizontal,this.baseUp=0,this.baseDown=0,this.fileHeader="",this.fileVersion="",this.order=0,this.unsupportedChars={},this.fileName=e}addUnsupportedChar(e){!this.unsupportedChars[e]&&(this.unsupportedChars[e]=0),this.unsupportedChars[e]++}getFontFile(){return{order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}async setFontDataToIndexedDb(){const e=this.getFontFile();return new Promise((i,s)=>{Fi.instance().save(e,()=>{console.log("[FontFile] Saved '"+this.fileName+"' ("+this.fileHeader+") to indexedDb"),i()},n=>s("[FontFile] Failed to save '"+this.fileName+"' ("+this.fileHeader+") to indexedDb! "+n))})}async getFontDataByIndexedDb(){return Fi.instance().query(this.fileName)}releaseFontData(){this.data={}}}class ei extends rl{constructor(e,i){super(e,i);g(this,"reversed");this.reversed=!1,i instanceof ArrayBuffer?this.data=this.parseTTF(i):i.fileName?this.setFontFile(i):this.data=i,this.type="MeshFont"}generateShapes(e,i){return super.generateShapes(e,i)}getCharShape(e,i){const s=ro(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return ro("?",e,0,0,this.data)?.path}parseTTF(e){function i(n,r){const a=Math.round,o={},l=1e5/((n.unitsPerEm||2048)*72),h=n.encoding.cmap.glyphIndexMap,d=Object.keys(h);for(let u=0;u<d.length;u++){const f=d[u],m=n.glyphs.glyphs[h[f]];if(f!==void 0){const b={ha:a(m.advanceWidth*l),x_min:a(m.xMin*l),x_max:a(m.xMax*l),o:""};r&&(m.path.commands=s(m.path.commands)),m.path.commands.forEach(function(y){y.type.toLowerCase()==="c"&&(y.type="b"),b.o+=y.type.toLowerCase()+" ",y.x!==void 0&&y.y!==void 0&&(b.o+=a(y.x*l)+" "+a(y.y*l)+" "),y.x1!==void 0&&y.y1!==void 0&&(b.o+=a(y.x1*l)+" "+a(y.y1*l)+" "),y.x2!==void 0&&y.y2!==void 0&&(b.o+=a(y.x2*l)+" "+a(y.y2*l)+" ")}),o[String.fromCodePoint(m.unicode)]=b}}return{glyphs:o,familyName:n.getEnglishName("fullName"),ascender:a(n.ascender*l),descender:a(n.descender*l),underlinePosition:n.tables.post.underlinePosition,underlineThickness:n.tables.post.underlineThickness,boundingBox:{xMin:n.tables.head.xMin,xMax:n.tables.head.xMax,yMin:n.tables.head.yMin,yMax:n.tables.head.yMax},resolution:1e3,original_font_information:n.tables.name}}function s(n){const r=[];let a;n.forEach(function(l){l.type.toLowerCase()==="m"?(a=[l],r.push(a)):l.type.toLowerCase()!=="z"&&a.push(l)});const o=[];return r.forEach(function(l){const h={type:"m",x:l[l.length-1].x,y:l[l.length-1].y};o.push(h);for(let d=l.length-1;d>0;d--){const u=l[d],f={type:u.type};u.x2!==void 0&&u.y2!==void 0?(f.x1=u.x2,f.y1=u.y2,f.x2=u.x1,f.y2=u.y1):u.x1!==void 0&&u.y1!==void 0&&(f.x1=u.x1,f.y1=u.y1),f.x=l[d-1].x,f.y=l[d-1].y,o.push(f)}}),o}return i(Nl.parse(e),this.reversed)}}function ro(c,t,e,i,s){const n=s.glyphs[c];if(!n)return;const r=new p.ShapePath;let a,o,l,h,d,u,f,m;if(n.o){const b=n._cachedOutline||(n._cachedOutline=n.o.split(" "));for(let y=0,C=b.length;y<C;)switch(b[y++]){case"m":a=b[y++]*t+e,o=b[y++]*t+i,r.moveTo(a,o);break;case"l":a=b[y++]*t+e,o=b[y++]*t+i,r.lineTo(a,o);break;case"q":l=b[y++]*t+e,h=b[y++]*t+i,d=b[y++]*t+e,u=b[y++]*t+i,r.quadraticCurveTo(d,u,l,h);break;case"b":l=b[y++]*t+e,h=b[y++]*t+i,d=b[y++]*t+e,u=b[y++]*t+i,f=b[y++]*t+e,m=b[y++]*t+i,r.bezierCurveTo(d,u,f,m,l,h);break}}return{offsetX:n.ha*t,path:r}}class Q{static GetBytes(t){switch(typeof t){case"string":{const e=new Uint16Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return new Uint8Array(e.buffer)}case"number":return t-Math.floor(t)==0?t>4294967295?(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Int32Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1));case"boolean":return(function(e){return e[0]=Number(t),e})(new Uint8Array(1));default:if(t instanceof Array){const e=[];for(let r=0;r<t.length;r++)e.push(Q.GetBytes(t[r]));let i=0;for(let r=0;r<e.length;r++)i+=e[r].length;const s=new Uint8Array(i);let n=0;for(let r=0;r<e.length;r++)for(let a=0;a<e[r].length;a++)s[n++]=e[r][a];return s}throw"Can't Convert To Bytes!!"}}static Get1Bytes(t){switch(typeof t){case"number":case"boolean":return new Uint8Array([Number(t)]);default:if(t instanceof Array){const e=[];for(let r=0;r<t.length;r++)e.push(this.Get1Bytes(t[r]));let i=0;for(let r=0;r<e.length;r++)i+=e[r].length;const s=new Uint8Array(i);let n=0;for(let r=0;r<e.length;r++)for(let a=0;a<e[r].length;a++)s[n++]=e[r][a];return s}throw"Can't Convert To Bytes!!"}}static byteTosbyte(t){return(t&127)-(t&128?128:0)}static ToBoolean(t,e){return e=e||0,!!t[e]}static ToInt8(t,e){return e=e||0,t[e]&128?-((t[e]^255)+1):t[e]}static ToUInt8(t,e){return e=e||0,t[e]}static ToInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Int16Array(i.buffer,0,1)[0]}static ToInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Int32Array(i.buffer,0,1)[0]}static ToUInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Uint16Array(i.buffer,0,1)[0]}static ToUInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Uint32Array(i.buffer,0,1)[0]}static ToChar(t,e){e=e||0;const i=t.slice(e,e+2);return String.fromCharCode(new Uint16Array(i.buffer,0,1)[0])}static ToAscii(t,e){return e=e||0,String.fromCharCode(t[e])}static ToAsciiString(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);let s="";for(let n=0;n<i;n++)s+=String.fromCharCode(t[e+n]||0);return s}static ToUTF16String(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);const s=new Uint8Array(i);for(let n=0;n<i;n++)s[n]=t[e+n]||0;return String.fromCharCode.apply(null,Array.from(new Uint16Array(s.buffer,0,i/2)))}static ToFloat32(t,e){e=e||0;const i=t.slice(e,e+4);return new Float32Array(i.buffer,0,1)[0]}static ToFloat64(t,e){e=e||0;const i=t.slice(e,e+8);return new Float64Array(i.buffer,0,1)[0]}}let gn;function lu(){const c=[[161,169,161,254],[176,247,161,254],[129,160,64,254],[170,254,64,160],[168,169,64,160],[170,175,161,254],[248,254,161,254],[161,167,64,160]],t=new Uint16Array(23940);let e=0;for(const[s,n,r,a]of c)for(let o=r;o<=a;o++)if(o!==127)for(let l=s;l<=n;l++)t[e++]=o<<8|l;const i=new TextDecoder("gbk").decode(t);for(gn=new Uint16Array(65536),e=0;e<i.length;e++)gn[i.charCodeAt(e)]=t[e]}function cu(c){!gn&&lu();const t=new Uint8Array(c.length*2);let e=0;for(let i=0;i<c.length;i++){const s=c.charCodeAt(i);if(s<128)t[e++]=s;else{const n=gn[s];t[e++]=n&255,t[e++]=n>>8}}return t.subarray(0,e)}new p.Vector2;class ys extends p.Shape{constructor(e,i){super();g(this,"width");g(this,"lastPoint");g(this,"polylines");g(this,"bounds");this.width=0,this.bounds=new p.Box2,this.lastPoint=e,this.polylines=i,this.width=this.calcWidth(i)}offset(e){const i=[];for(let s=0;s<this.polylines.length;s++){const n=this.polylines[s],r=[];for(let a=0;a<n.length;a++){const o=n[a];r.push(o.clone().add(e))}i.push(r)}return new ys(this.lastPoint,i)}transform(e){const i=[];for(let s=0;s<this.polylines.length;s++){const n=this.polylines[s],r=[];for(let a=0;a<n.length;a++){const o=n[a];r.push(o.clone().applyMatrix3(e))}i.push(r)}return new ys(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let r=0;r<e.length;r++){const a=e[r];for(let o=0;o<a.length;o++){const l=a[o];i.expandByPoint(l)}}const s=i.min.x||0;return(i.max.x||0)-s}toThreeGeometry(){const e=this.polylines,i=[],s=[];let n=0;const r=new p.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const h=o[l];i.push(h.x,h.y,0),l===o.length-1||s.push(n,n+1),n++}}return r.userData={advanceWidth:this.width},r.setAttribute("position",new p.Float32BufferAttribute(i,3)),r.setIndex(s),r}}const gt=class gt{static parserHeader(t,e){let i="",s=!1,n=0;const r=!0;for(;r;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[n]?n++:(s=!1,n=0);else{if(o===e[n]){s=!0,n++;continue}i+=o}if(s&&n===e.length)break}return i}static getCode(t){const e=cu(t);return e.length<2?e[0]:e.length<4?Q.ToUInt16(e,0):Q.ToUInt32(e,0)}static parserCode(t,e,i){let s=new p.Vector2;const n=[];let r=[];const a=[];let o=!1;for(let l=0;l<e.length;l++){const h=e[l];switch(h){case 0:break;case 1:o=!0,r.push(s.clone());break;case 2:o=!1,r.length>1?(n.push(r.slice()),r=[]):s.set(0,0);break;case 3:l++,i/=e[l];break;case 4:l++,i*=e[l];break;case 5:if(a.length===4)throw"The position stack is only four locations deep";a.push(s.clone());break;case 6:if(a.length===0)break;s=a.pop(),r.length>1&&(n.push(r.slice()),r=[]),o&&r.push(s.clone());break;case 7:{let d=0,u,f=i*t.baseUp;const m=s.clone();switch(r.length>1&&(n.push(r.slice()),r=[]),t.fontType){case He.Shapes:l++,d=e[l];break;case He.Bigfont:l++,d=e[l],d==0&&(l++,d=Q.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),m.x=e[l++]*i,m.y=e[l++]*i,f=e[l]*i);break;case He.Unifont:l+=2,d=Q.ToUInt16(new Uint8Array([e[l-1],e[l]]),0);break}d!==0&&(u=t.getGraphicDataByCodeWithOffset(d,f,m),u&&(n.push(...u.polylines.slice()),s=u.lastPoint.clone()))}break;case 8:{const d=new p.Vector2;d.x=Q.byteTosbyte(e[++l]),d.y=Q.byteTosbyte(e[++l]),s.add(d.multiplyScalar(i)),o&&r.push(s.clone())}break;case 9:for(;;){const u=new p.Vector2;if(u.x=Q.byteTosbyte(e[++l]),u.y=Q.byteTosbyte(e[++l]),!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;s.add(u.multiplyScalar(i)),o&&r.push(s.clone())}break;case 10:{const d=e[++l]*i,u=Q.byteTosbyte(e[++l]),f=(u&112)>>4;let m=u&7;m==0&&(m=8);const b=Math.PI/4;let y=b*m,C=gt.CIRCLE_SPAN;u<0&&(C=-C,y=-y);const w=b*f,x=w+y,E=s.clone().sub(new p.Vector2(Math.cos(w)*d,Math.sin(w)*d));if(s=E.clone().add(new p.Vector2(Math.cos(x)*d,Math.sin(x)*d)),o){let M=w;const O=!0;for(;O&&(M+=C,!!Number.isFinite(M));)if(u>=0&&M<x||u<0&&M>x)r.push(E.clone().add(new p.Vector2(d*Math.cos(M),d*Math.sin(M))));else break;r.push(s.clone())}}break;case 11:{const d=e[++l],u=e[++l],f=e[++l],m=e[++l],b=(f*255+m)*i,y=Q.byteTosbyte(e[++l]),C=(y&112)>>4;let w=y&7;w==0&&(w=8),u!=0&&w--;const x=Math.PI/4;let E=x*w,M=gt.CIRCLE_SPAN,O=1;y<0&&(M=-M,E=-E,O=-1);let S=x*C,v=S+E;S+=x*d/256*O,v+=x*u/256*O;const T=s.clone().sub(new p.Vector2(b*Math.cos(S),b*Math.sin(S)));if(s=T.clone().add(new p.Vector2(b*Math.cos(v),b*Math.sin(v))),o){let _=S;const A=!0;for(;A&&(_+=M,!!Number.isFinite(_));)if(y>0&&_<v||y<0&&_>v)r.push(T.clone().add(new p.Vector2(b*Math.cos(_),b*Math.sin(_))));else break;r.push(s.clone())}}break;case 12:{const d=new p.Vector2;d.x=Q.byteTosbyte(e[++l])*i,d.y=Q.byteTosbyte(e[++l])*i;let u=Q.byteTosbyte(e[++l]);u<-127&&(u=-127),o&&(u==0?r.push(s.clone().add(d)):r.push(gt.generateArcPoints(s,d,u/127))),s.add(d)}break;case 13:for(;;){const u=new p.Vector2;if(u.x=Q.byteTosbyte(e[++l])*i,u.y=Q.byteTosbyte(e[++l])*i,!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;let f=Q.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?r.push(s.clone().add(u)):r.push(gt.generateArcPoints(s.clone(),u,f/127))),s.add(u)}break;case 14:l=gt.skipCode(t,e,++l);break;default:if(h>15){const d=(h&240)>>4,u=h&15,f=new p.Vector2;switch(u){case 0:f.x=1;break;case 1:f.x=1,f.y=.5;break;case 2:f.x=1,f.y=1;break;case 3:f.x=.5,f.y=1;break;case 4:f.y=1;break;case 5:f.x=-.5,f.y=1;break;case 6:f.x=-1,f.y=1;break;case 7:f.x=-1,f.y=.5;break;case 8:f.x=-1;break;case 9:f.x=-1,f.y=-.5;break;case 10:f.x=-1,f.y=-1;break;case 11:f.x=-.5,f.y=-1;break;case 12:f.y=-1;break;case 13:f.x=.5,f.y=-1;break;case 14:f.x=1,f.y=-1;break;case 15:f.x=1,f.y=-.5;break}s.add(f.multiplyScalar(d*i)),o&&r.push(s.clone())}break}}return new ys(s,n)}static skipCode(t,e,i){switch(e[i]){case 0:break;case 1:break;case 2:break;case 3:case 4:i++;break;case 5:break;case 6:break;case 7:switch(t.fontType){case He.Shapes:i++;break;case He.Bigfont:i++,e[i]==0&&(i+=6);break;case He.Unifont:i+=2;break}break;case 8:i+=2;break;case 9:for(;;){const r=e[++i],a=e[++i];if(r===void 0||a===void 0||r==0&&a==0)break}break;case 10:i+=2;break;case 11:i+=5;break;case 12:i+=3;break;case 13:for(;;){const r=e[++i],a=e[++i];if(r===void 0||a===void 0||r==0&&a==0)break;e[++i]}break}return i}static generateArcPoints(t,e,i){const s=t.clone().add(e),n=i<0,r=!1;i=Math.abs(i);const a=e.length()/2,o=a*i,l=2*Math.atan(1/i),h=new p.Vector2(e.y,-e.x);h.normalize(),h.multiplyScalar(o);const d=Math.abs(a/Math.sin(l/2)),u=t.add(e.divideScalar(2));r!==n?u.add(h):u.sub(h);const f=t.sub(u),m=s.sub(u);let b=Math.atan2(f.y,f.x);const y=Math.atan2(m.y,m.x);let C=gt.CIRCLE_SPAN;n?(C=-C,b<y&&(b+=2*Math.PI)):b>y&&(b-=2*Math.PI);let w=b;const x=!0;for(;x;){if(w+=C,!n&&w<y||n&&w>y)return u.add(new p.Vector2(d*Math.cos(w),d*Math.sin(w)));break}return s}};g(gt,"FILE_STOP_FLAG",["\r",`
1532
- `,""]),g(gt,"CIRCLE_SPAN",Math.PI/18);let Dt=gt;const sr={130:[[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],131:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],132:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],133:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]]],134:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],135:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],136:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],178:[[[1.142,9.285],[1.142,9.428],[1.285,9.714],[1.428,9.857],[1.714,10],[2.285,10],[2.571,9.857],[2.714,9.714],[2.857,9.428],[2.857,9.142],[2.714,8.857],[2.428,8.428],[1,7],[3,7]]],8960:[[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]],[[0,0],[8,8]]],20393:[[[0,0],[0,6.666]],[[0,4.761],[1.428,6.19],[2.38,6.666],[3.809,6.666],[4.761,6.19],[5.238,4.761],[5.238,0]],[[5.238,4.761],[6.666,6.19],[7.619,6.666],[9.047,6.666],[10,6.19],[10.476,4.761],[10.476,0]],[[11.142,9.285],[11.142,9.428],[11.285,9.714],[11.428,9.857],[11.714,10],[12.285,10],[12.571,9.857],[12.714,9.714],[12.857,9.428],[12.857,9.142],[12.714,8.857],[12.428,8.428],[11,7],[13,7]]],41123:[],55714:[[[2,5.9],[2.6,6.1],[3.4,7],[3.4,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],55970:[[[2.3,5.6],[2.3,5.9],[2.6,6.4],[2.9,6.7],[3.4,7],[4.6,7],[5.1,6.7],[5.4,6.4],[5.7,5.9],[5.7,5.3],[5.4,4.7],[4.9,3.9],[2,1],[6,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56226:[[[2.6,7],[5.7,7],[4,4.7],[4.9,4.7],[5.4,4.4],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56482:[[[4.9,7],[2,3],[6.3,3]],[[4.9,7],[4.9,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56738:[[[5.4,7],[2.6,7],[2.3,4.4],[2.6,4.7],[3.4,5],[4.3,5],[5.1,4.7],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56994:[[[5.4,6.1],[5.1,6.7],[4.3,7],[3.7,7],[2.9,6.7],[2.3,5.9],[2,4.4],[2,3],[2.3,1.9],[2.9,1.3],[3.7,1],[4,1],[4.9,1.3],[5.4,1.9],[5.7,2.7],[5.7,3],[5.4,3.9],[4.9,4.4],[4,4.7],[3.7,4.7],[2.9,4.4],[2.3,3.9],[2,3]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57250:[[[2,7],[6,7],[3.1,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57506:[[[3.4,7],[2.6,6.7],[2.3,6.1],[2.3,5.6],[2.6,5],[3.1,4.7],[4.3,4.4],[5.1,4.1],[5.7,3.6],[6,3],[6,2.1],[5.7,1.6],[5.4,1.3],[4.6,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1],[2,3],[2.3,3.6],[2.9,4.1],[3.7,4.4],[4.9,4.7],[5.4,5],[5.7,5.6],[5.7,6.1],[5.4,6.7],[4.6,7],[3.4,7]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57762:[[[5.7,5],[5.4,4.1],[4.9,3.6],[4,3.3],[3.7,3.3],[2.9,3.6],[2.3,4.1],[2,5],[2,5.3],[2.3,6.1],[2.9,6.7],[3.7,7],[4,7],[4.9,6.7],[5.4,6.1],[5.7,5],[5.7,3.6],[5.4,2.1],[4.9,1.3],[4,1],[3.4,1],[2.6,1.3],[2.3,1.9]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],60070:[[[0,6],[10,6],[10,4]]],60326:[[[0,7],[0,5],[10,5]]]},ao=new p.Matrix3,us=class us extends rl{constructor(e,i){super(e,i);g(this,"isExtend");g(this,"isUniCode");g(this,"isEmbedded");g(this,"fontType");g(this,"textShapesCache");g(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=He.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new vs(i),n=Dt.parserHeader(s,Dt.FILE_STOP_FLAG),r=n.split(" ");switch(r[1]){case"shapes":this.parseShapeFont(s),this.fontType=He.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=He.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=He.Unifont;break}this.fileHeader=r[0],this.fileVersion=r[2]}else this.setFontFile(i)}generateShapes(e,i){const s=[];let n=0;for(let r=0;r<e.length;r++){const a=e[r];if(a===" "){n+=i;continue}const o=this.getCharShape(a,i);if(!o){n+=i,this.addUnsupportedChar(a);continue}s.push(o.offset(new p.Vector2(n,0))),n+=o.width}return s}getCharShape(e,i){let s=Dt.getCode(e);s===0&&(s=e.charCodeAt(0));const n=this.getGraphicDataByCode(s,i);if(!n)return this.addUnsupportedChar?.(e),null;if(n.polylines&&n.polylines.length===0&&(n.width=i*.8),typeof n.width!="number"||n.width<=0){const r=n,a=r.xMin!=null?r.xMin:0,o=r.xMax!=null?r.xMax:0;n.width=Math.max(.1,o-a)}return n}getGraphicDataByCode(e,i){const s=e+"_"+i;if(this.textShapesCache.has(s))return this.textShapesCache.get(s);if(e===0)return;const n=this.data;let r;if(!this.graphicData.has(e)){if(n[e]){const a=n[e],o=us.DEFAULT_SIZE/this.baseUp;r=Dt.parserCode(this,a,o),this.graphicData.set(e,r)}else if(sr[e]){const a=[];for(let o=0;o<sr[e].length;o++)a.push(sr[e][o].map(l=>new p.Vector2(l[0],l[1])));r=new ys(new p.Vector2,a),this.graphicData.set(e,r)}}if(this.graphicData.has(e)){const a=i/us.DEFAULT_SIZE;ao.identity().scale(a,a),r=this.graphicData.get(e).transform(ao)}return r}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){Q.ToInt16(e.readBytes(2),0);const i=Q.ToInt16(e.readBytes(2),0),s=Q.ToInt16(e.readBytes(2),0);for(let l=0;l<s;l++)e.readBytes(2),e.readBytes(2);const n=[];for(let l=0;l<i;l++){const h=e.readBytes(8),d=Q.ToUInt16(new Uint8Array([h[1],h[0]]),0),u=Q.ToUInt16(h,2),f=Q.ToUInt32(h,4);d===0&&u===0&&f===0||n.push({code:d,length:u,offset:f})}const r={};for(const l of n)e.setPosition(l.offset),r[l.code]=e.readBytes(l.length);const a=r[0];this.info=hu(a);let o=this.info.indexOf("\0")+1;a.length-o===4?(this.baseUp=a[o++],this.baseDown=a[o++],this.orientation=a[o++]):(this.baseUp=a[o++],o++,this.orientation=a[o++],this.baseDown=a[o++],this.isExtend=!0),this.data=r}parseUniFont(e){const i=Q.ToInt32(e.readBytes(4),0),s=Q.ToInt16(e.readBytes(2),0),n=e.readBytes(s);this.info=new TextDecoder().decode(n);let r=this.info.indexOf("\0");this.baseUp=n[++r],this.baseDown=n[++r],this.orientation=n[++r],this.isUniCode=n[++r]==0,this.isEmbedded=n[++r]==0;const a={};for(let o=0;o<i-1;o++){const l=Q.ToUInt16(e.readBytes(2),0),h=Q.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(h)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=Q.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=Q.ToUInt16(e.readBytes(2),0),h=Q.ToUInt16(e.readBytes(2),0);s.push({code:l,length:h})}const n={};for(const o of s)n[o.code]=e.readBytes(o.length);const r=n[0];this.info=new TextDecoder().decode(r);let a=this.info.indexOf("\0");this.baseUp=r[++a],this.baseDown=r[++a],this.orientation=r[++a],this.data=n}getNotFoundTextShape(e){let i=0;return this.fontType===He.Bigfont&&(i=Dt.getCode("?")),this.fontType===He.Unifont&&(i=Dt.getCode("?")),this.getGraphicDataByCode(i,e)}getFontFile(){return{fontType:this.fontType,order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.fontType=e.fontType||He.Unifont,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}releaseFontData(){super.releaseFontData(),this.graphicData.clear(),this.textShapesCache.clear()}};g(us,"DEFAULT_SIZE",12);let Lt=us;function hu(c){let t,e,i,s,n;t="";const r=c.length;for(e=0;e<r;)switch(i=c[e++],i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(i);break;case 12:case 13:s=c[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=c[e++],n=c[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(n&63)<<0);break}return t}class yt{constructor(){g(this,"loader");g(this,"fontMap");g(this,"fileNames");g(this,"unsupportedChars");g(this,"missingFonts");g(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new p.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:yt.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,n=[],r=[];typeof i=="object"?(n=Object.keys(i),r=Object.values(i),s=n[0]):s=yt.getFileName(i.toLowerCase());let a;if(n.length){const o=n[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new Lt(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}}else if(yt.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new ei(s,o)}else if(yt.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new Lt(s,o)}else if(yt.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ei(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&Be.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}let s=this.fontMap.get(e.toLowerCase());return!s&&(s=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++),s?.generateShapes(t,i)}getCharShape(t,e,i){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}e==null&&(e="");let s=this.fontMap.get(e.toLowerCase());if(!s){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,r]of this.fontMap)if(r.getCharShape(t,i)){s=r;break}}let n=s?.getCharShape(t,i);if(!n)for(const[,r]of this.fontMap){if(r===s)continue;const a=r.getCharShape(t,i);if(a){s=r,n=a;break}}if(n){if(s instanceof Lt)return n.toThreeGeometry();if(s instanceof ei)return new Hl.TextGeometry(t,{font:s,depth:0,size:i||12,curveSegments:3,bevelSegments:3})}}getNotFoundTextShape(t){let e,i;for(const[,s]of this.fontMap){const n=s.getNotFoundTextShape(t);if(n){e=n,i=s;break}}if(i instanceof Lt)return e.toThreeGeometry();if(i instanceof ei)return new p.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!Be.isBrowser)return!1;let e=!1;for(let i=0;i<t.length;i++){const s=t[i];let n=null;typeof s=="object"?n=Object.keys(s)[0]:n=yt.getFileName(s.toLowerCase());const r=await Fi.instance().query(n);if(r)e=!0;else{e=!1;break}if(r.codes!==void 0){e=!1;break}}return e}async getFontFromIndexeddb(){if(this.fontMap.size!==0)return;const t=(await Fi.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:n}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let r;n?r=new Lt(s,i):r=new ei(s,i),this.fontMap.set(s,r)}P.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}let e=this.fontMap.get(t);return!e&&(e=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[t]&&(this.missingFonts[t]=0),this.missingFonts[t]++),e instanceof Lt}getUnsupportedChar(){return this.fontMap.forEach(t=>{Object.assign(this.unsupportedChars,t.unsupportedChars)}),this.unsupportedChars}releaseFontData(){this.fontMap.forEach(t=>{t.releaseFontData()}),this.fontMap.clear()}destroy(){this.releaseFontData(),this.fontMap.clear()}static isShxFile(t){return j.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(j.getExtension(t).toUpperCase())}static isJsonFile(t){return j.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class du{constructor(t){g(this,"object");this.object=t}instantiate(){const t=Date.now();this.instantiateInner(this.object),console.log("[Inst] instantiate() took "+(Date.now()-t)/1e3+"s")}instantiateInner(t){if(!t.children||t.children.length===0)return;const e=t.children.length,i={},s=[];for(let a=0;a<e;++a){const o=t.children[a];if(this.instantiateInner(o),o.children&&o.children.length>0||!o.geometry)continue;let l=!1;const h=Object.values(i);for(let d=h.length-1;d>=0;--d){const u=h[d].indexes[0],f=t.children[u];if(this.geometryEquals(o.geometry,f.geometry)&&xe.materialsEquals(o.material,f.material)){!i[u]&&(i[u]={indexes:[u]},this.removeFromArray(s,u)),i[u].indexes.push(a),l=!0;break}}for(let d=s.length-1;!l&&d>=0;--d){const u=s[d],f=t.children[u];if(this.geometryEquals(o.geometry,f.geometry)&&xe.materialsEquals(o.material,f.material)){!i[u]&&(i[u]={indexes:[u]},this.removeFromArray(s,u)),i[u].indexes.push(a),l=!0;break}}!l&&s.push(a)}if(Object.keys(i).length<=0)return;const n=[],r=[];Object.values(i).forEach(a=>{const o=a.indexes;r.push(...o);const l=t.children[o[0]];let h=l.material;if(h instanceof p.Material)h=h.clone();else if(Array.isArray(h)){const u=[];h.forEach(f=>u.push(f.clone())),h=u}const d=new p.InstancedMesh(l.geometry,h,o.length);d.name="[Instanced] "+l.name;for(let u=0;u<o.length;++u){const f=o[u],m=t.children[f];m.updateMatrix(),d.setMatrixAt(u,m.matrix)}d.matrixAutoUpdate=ct,d.updateMatrix(),n.push(d)}),r.sort((a,o)=>o-a),r.forEach(a=>t.remove(t.children[a])),n.forEach(a=>{a.parent=t,t.children.push(a)}),t.updateMatrix(),console.log("[Inst] "+r.length+"(out of "+e+") objects instanced to "+n.length+" InstancedMesh")}removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}geometryEquals(t,e){return N.geometriesEqual(t,e)}}class al{constructor(){g(this,"TIMEOUT","timeout");g(this,"INTERVAL","interval");g(this,"timeoutMap",{});g(this,"intervalMap",{})}run(t=this.INTERVAL,e,i=16.7){const s=Date.now;let n=s(),r=n;const a=Symbol(""),o=()=>{this.setIdMap(a,t,o),r=s(),r-n>=i&&(t===this.intervalMap&&(n=s(),r=n),e(),t===this.TIMEOUT&&this.clearTimeout(a))};return this.setIdMap(a,t,o),a}setIdMap(t,e,i){const s=requestAnimationFrame(i);e===this.INTERVAL?this.intervalMap[t]=s:e===this.TIMEOUT&&(this.timeoutMap[t]=s)}setTimeout(t,e){return this.run(this.TIMEOUT,t,e)}clearTimeout(t){cancelAnimationFrame(this.timeoutMap[t])}setInterval(t,e){return this.run(this.INTERVAL,t,e)}clearInterval(t){cancelAnimationFrame(this.intervalMap[t])}}class yn{constructor(t){g(this,"buffer");g(this,"u8");this.buffer=t,this.u8=new Uint8Array(t)}getBit(t){var e=this.u8[t>>3],i=t&7;return(e&128>>i)>>7-i}setBit(t,e){var i=t>>3,s=this.u8[i],n=t&7;e?this.u8[i]=s|128>>n:this.u8[i]=s&~(128>>n)}getInt12(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],n=this.u8[e+2],r=t%8,a=8-r,o=Math.min(12-a,8),l=Math.max(12-a-o,0),h=~(255<<a),d=255<<8-o,u=255<<8-l;return i&=h,s&=d,n&=u,((i<<16)+(s<<8)+n>>12-r)-2048}setInt12(t,e){e+=2048;var i=t/8|0,s=t%8,n=e<<12-s,r=(n&16711680)>>16,a=(n&65280)>>8,o=n&255,l=8-s,h=Math.min(12-l,8),d=Math.max(12-l-h,0),u=255<<l;this.u8[i]=(this.u8[i]&u)+r;var f=~(255<<8-h);this.u8[i+1]=(this.u8[i+1]&f)+a;var m=~(255<<8-d);this.u8[i+2]=(this.u8[i+2]&m)+o}getInt6(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],n=t%8,r=8-n,a=Math.max(6-r,0),o=~((255<<r)+(255>>8-(2-n))),l=255<<8-a;return i&=o,s&=l,((i<<8)+s>>10-n)-32}setInt6(t,e){e+=32;var i=t/8|0,s=t%8,n=e<<10-s,r=(n&65280)>>8,a=n&255,o=8-s,l=Math.max(6-o,0),h=(255<<o)+(255>>8-(2-s));this.u8[i]=(this.u8[i]&h)+r;var d=~(255<<8-l);this.u8[i+1]=(this.u8[i+1]&d)+a}test(){var t=new ArrayBuffer(3),e=new yn(t),i,s;for(i=0;i<12;i++)for(s=-2048;s<2048;s++)if(e.setInt12(i,s),e.getInt12(i)!=s){console.log("12-bit prob at",i,s),console.log("expected",s,"got",e.getInt12(i));break}for(i=0;i<18;i++)for(s=-32;s<32;s++)if(e.setInt6(i,s),e.getInt6(i)!=s){console.log("6-bit prob at",i,s),console.log("expected",s,"got",e.getInt6(i));break}return e}}var ns=(c=>(c[c.NULL=0]="NULL",c[c.POINT=1]="POINT",c[c.POLYLINE=3]="POLYLINE",c[c.POLYGON=5]="POLYGON",c))(ns||{});class uu{parse(t){var e={},i=new DataView(t),s=0;if(e.fileCode=i.getInt32(s,!1),e.fileCode!=9994)throw new Error("Unknown file code: "+e.fileCode);for(s+=24,e.wordLength=i.getInt32(s,!1),e.byteLength=e.wordLength*2,s+=4,e.version=i.getInt32(s,!0),s+=4,e.shapeType=i.getInt32(s,!0),s+=4,e.minX=i.getFloat64(s,!0),e.minY=i.getFloat64(s+8,!0),e.maxX=i.getFloat64(s+16,!0),e.maxY=i.getFloat64(s+24,!0),e.minZ=i.getFloat64(s+32,!0),e.maxZ=i.getFloat64(s+40,!0),e.minM=i.getFloat64(s+48,!0),e.maxM=i.getFloat64(s+56,!0),s+=64,e.records=[];s<e.byteLength;){var n={};n.number=i.getInt32(s,!1),s+=4,n.length=i.getInt32(s,!1),s+=4;try{n.shape=this.parseShape(i,s,n.length)}catch(r){console.log(r,n)}s+=n.length*2,e.records.push(n)}return e}parseShape(t,e,i){var s=0,n=null,r={};switch(r.type=t.getInt32(e,!0),e+=4,r.type){case 0:break;case 1:r.content={x:t.getFloat64(e,!0),y:t.getFloat64(e+8,!0)};break;case 3:case 5:for(n=r.content={minX:t.getFloat64(e,!0),minY:t.getFloat64(e+8,!0),maxX:t.getFloat64(e+16,!0),maxY:t.getFloat64(e+24,!0),parts:new Int32Array(t.getInt32(e+32,!0)),points:new Float64Array(t.getInt32(e+36,!0)*2)},e+=40,s=0;s<n.parts.length;s++)n.parts[s]=t.getInt32(e,!0),e+=4;for(s=0;s<n.points.length;s++)n.points[s]=t.getFloat64(e,!0),e+=8;break;case 8:case 11:case 13:case 15:case 18:case 21:case 23:case 25:case 28:case 31:throw new Error("Shape type not supported: "+r.type+":"+ +r.type);default:throw new Error("Unknown shape type at "+(e-4)+": "+r.type)}return r}}class fu{constructor(){g(this,"LINE_MATERIAL");g(this,"MESH_MATERIAL");this.LINE_MATERIAL=new p.LineBasicMaterial({color:0,linewidth:2,opacity:.8,transparent:!0}),this.MESH_MATERIAL=new p.MeshBasicMaterial({color:1926655,opacity:.8,transparent:!0})}createModel(t){for(var e=[],i=[],s=0;s<t.records.length;s++){var n=t.records[s].shape;if(n.type===ns.POLYLINE||n.type===ns.POLYGON)for(var r=n.content.points,a=n.content.parts,o=0;o<a.length;o++){const m=[];for(var l=a[o],h=a[o+1]||r.length/2;l<h;l++){var d=r[l*2],u=r[l*2+1];m.push(new p.Vector3(d,u,0))}if(n.type===ns.POLYGON){const b=p.ShapeUtils.triangulateShape(m,[]),y=[];b.forEach(x=>y.push(...x));const C=new p.BufferGeometry;C.setFromPoints(m),C.setIndex(y),e.push(C);const w=new p.BufferGeometry;m.length>2&&!m[0].equals(m[m.length-1])&&m.push(m[0]),w.setFromPoints(m),i.push(w)}else{const b=new p.BufferGeometry;b.setFromPoints(m),i.push(b)}}}for(var f=new p.Object3D,s=0;s<i.length;s++)f.add(new p.Line(i[s],this.LINE_MATERIAL));for(var s=0;s<e.length;s++)f.add(new p.Mesh(e[s],this.MESH_MATERIAL));return console.log("parsed",e.length,i.length),f}loadCompressed(t){for(var e=this.deltaDecode6(t),i=[],s=[],n=0;n<e.length;n++){let d=[];if(e[n]===-32768){for(var r=[],a=1;a<d.length;a++)!(d[a-1].x==d[a].x&&d[a-1].y==d[a].y)&&r.push(d[a]);const u=new p.BufferGeometry;u.setFromPoints(r),i.push(u),d=[];continue}var o=e[n]*180/32767,l=e[n+1]*180/32767;n++,d.push(new p.Vector3(o,l,0))}for(var h=new p.Object3D,n=0;n<s.length;n++)h.add(new p.Line(s[n],this.LINE_MATERIAL));for(var n=0;n<i.length;n++)h.add(new p.Mesh(i[n],this.MESH_MATERIAL));return console.log("parsed compressed",i.length,s.length),h}compress(t){for(var e=[],i=0;i<t.records.length;i++){var s=t.records[i].shape;if(s.type===ns.POLYGON)for(var n=s.content.points,r=s.content.parts,a=0;a<r.length;a++){for(var o=r[a],l=r[a+1]||n.length/2;o<l;o++){var h=n[o*2],d=n[o*2+1];e.push(h/180*32767,d/180*32767)}e.push(-32768)}}var u=new Int16Array(e);console.log("16-bit quantized byteLength",u.buffer.byteLength);var f=this.deltaEncode6(u);return console.log("delta-encoded byteLength",f.byteLength),f}deltaEncode(t){for(var e=[],i=[],s=[],n=0,r=0,a=0,o=0;o<t.length;o++){if(t[o]==-32768){i.push(s),e.push(i),i=[],s=[],a+=3;continue}s.length==0?(n=t[o],r=t[o+1],s.push(n,r),a+=4,o++):Math.abs(n-t[o])>1023||Math.abs(r-t[o+1])>1023?(i.push(s),a+=1,s=[],n=t[o],r=t[o+1],s.push(n,r),a+=4,o++):(s.push((t[o]-n)/8,(t[o+1]-r)/8),n+=((t[o]-n)/8|0)*8,r+=((t[o+1]-r)/8|0)*8,a+=2,o++)}return this.storeDeltas(a,e)}deltaEncode6(t){var e=[],i=[],s=[],n=0,r=0,a=0,o=0;for(a=0;a<t.length;a++)t[a]=0|t[a]/16;for(a=0;a<t.length;a++){if(t[a]===-2048){i.push(s),e.push(i),i=[],s=[],o+=3;continue}s.length==0?(n=t[a],r=t[a+1],s.push(n,r),o+=4,a++):Math.abs(n-t[a])>31||Math.abs(r-t[a+1])>31?(i.push(s),o+=1,s=[],n=t[a],r=t[a+1],s.push(n,r),o+=4,a++):(s.push(t[a]-n,t[a+1]-r),n+=t[a]-n,r+=t[a+1]-r,o+=2,a++)}return this.storeDeltas6(o,e)}storeDeltas(t,e){for(var i=new ArrayBuffer(t),s=new DataView(i),n=0,r=0;r<e.length;r++){for(var a=e[r],o=0;o<a.length;o++){var l=a[o];s.setInt16(n,l[0]),n+=2,s.setInt16(n,l[1]),n+=2;for(var h=2;h<l.length;h++)s.setInt8(n++,l[h]);s.setInt8(n,-128),n+=1}s.setInt16(n,-32768),n+=2}return i}deltaDecode(t){for(var e=new DataView(t),i=0,s=[];i<t.byteLength;){var n=e.getInt16(i);if(i+=2,n===-32768){s.push(-32768);continue}var r=e.getInt16(i);for(i+=2,s.push(n,r);i<t.byteLength;){var a=e.getInt8(i);if(i++,a==-128)break;var o=e.getInt8(i);i++,n+=a*8,r+=o*8,s.push(n,r)}}return s}storeDeltas6(t,e){for(var i=new ArrayBuffer(Math.ceil(t*.75)+4),s=new yn(i),n=32,r=0;r<e.length;r++){for(var a=e[r],o=0;o<a.length;o++){var l=a[o];s.setInt12(n,l[0]),n+=12,s.setInt12(n,l[1]),n+=12;for(var h=2;h<l.length;h++)s.setInt6(n,l[h]),n+=6;s.setInt6(n,-32),n+=6}s.setInt12(n,-2048),n+=12}return new DataView(i).setUint32(0,n),i}deltaDecode6(t){for(var e=new DataView(t).getUint32(0),i=new yn(t),s=32,n=[];s<e;){var r=i.getInt12(s);if(s+=12,r===-2048){n.push(-2048);continue}var a=i.getInt12(s);for(s+=12,n.push(r,a);s<e;){var o=i.getInt6(s);if(s+=6,o===-32)break;var l=i.getInt6(s);s+=6,r+=o,a+=l,n.push(r,a)}}for(var h=0;h<n.length;h++)n[h]*=16;return n}}class pu{async load(t,e,i,s){this.updateProgress(i,0);const n=new XMLHttpRequest;n.responseType="arraybuffer",n.onload=()=>{this.updateProgress(i,50);const r=new uu,a=r.parse(n.response),o=new fu().createModel(a);this.updateProgress(i,100),e(o)},n.onerror=s,n.open("GET",t),n.send(null)}updateProgress(t,e){if(t){const i={lengthComputable:!0,loaded:e,total:100};t(new ProgressEvent("progress",i))}}}const fs=class fs{constructor(t){g(this,"gltfLoader");g(this,"font");g(this,"manager");this.manager=t}setLoadManager(t){this.manager=t}async loadLocalModel(t,e,i){const s=e.toLowerCase();return s.endsWith("fbx")?this.loadFbx(t,i):s.endsWith("obj")?this.loadObj(t,i):s.endsWith("stl")?this.loadStl(t,i):s.endsWith("ifc")?(P.warn("[LoadingHelper] IFC is not supported directly since three.js r150!"),Promise.reject("Not supported!")):s.endsWith("shp")?this.loadShp(t,i):s.endsWith("dae")?this.loadDae(t,i):s.endsWith("dxf")?this.loadDxf(t,i):s.endsWith("jpg")||s.endsWith("jpeg")||s.endsWith("png")?this.loadImage(t,i):this.loadGltf(t,i)}async loadModel(t,e,i){const s=t;if(!s)return Promise.resolve();let n=e?.toLowerCase()||"";if(!n){const r=s.split("?")[0].toLowerCase();if(r){const a=r.lastIndexOf(".");a!==-1&&(n=r.slice(a+1))}}if(n.endsWith("fbx"))return this.loadFbx(s,i);if(n.endsWith("obj"))return this.loadObj(s,i);if(n.endsWith("stl"))return this.loadStl(s,i);if(n.endsWith("ifc"))P.warn("[LoadingHelper] IFC is not supported directly since three.js r150!");else return n.endsWith("shp")?this.loadShp(s,i):n.endsWith("dae")?this.loadDae(s,i):n.endsWith("dxf")?this.loadDxf(s,i):n.endsWith("jpg")||n.endsWith("jpeg")||n.endsWith("png")?this.loadImage(s,i):this.loadGltf(s,i)}async loadGltf(t,e){const i=this.getGltfLoader();t.indexOf("#")!==-1&&console.warn("[LoadingHelper] '#' is not allowed in filename "+t),t=t.replace(/#/g,encodeURIComponent("#"));const s=r=>{r.total===0&&r.loaded>0||e&&e(r)},n=await i.loadAsync(t,s);return Promise.resolve(n.scene)}parseGltf(t,e,i,s){return this.getGltfLoader().parse(t,e,r=>i(r.scene),s)}async loadFbx(t,e){const i=new Yl.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Kl.OBJLoader(this.manager),s=new Zl.MTLLoader(this.manager),n=t.replace(".obj",".mtl"),r=await s.loadAsync(n,e);r.preload(),i.setMaterials(r);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new Jl.STLLoader(this.manager),s=await i.loadAsync(t,e),n=new p.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),r=new p.Mesh(s,n);return Promise.resolve(r)}async loadShp(t,e){const i=new pu;return new Promise((s,n)=>{i.load(t,r=>{s(r)},e,r=>{n(r)})})}async loadDae(t,e){const i=new ql.ColladaLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s.scene)}async load3dm(t,e){return Promise.reject("3dm format is not supported since three.js r159 (Rhino3dmLoader removed)")}async loadDxf(t,e){this.font||console.warn("[LoadingHelper] Should set font first!");const i={ignorePaperSpace:!0,enableLocalCache:!1,overrideHatchPatternLineThickness:2},s=new X(this.manager,i);s.setFont(this.font),await this.font?.getFontFromIndexeddb();try{const n=await s.loadAsync(t,e);return Promise.resolve(n.threejsObject)}catch{const r=new ErrorEvent("");return Promise.reject(r)}}async loadPly(t,e){const i=new $l.PLYLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(new p.Mesh(s))}async loadImage(t,e){const i=new p.TextureLoader(this.manager),s=await i.loadAsync(t,e);if(!s)return Promise.reject("Failed to load image!");const n=10,r=s.image;let a=r&&r.height||n,o=r&&r.width||n;a=n/o*a,o=n;const l=new p.MeshBasicMaterial({map:s,side:p.DoubleSide,transparent:!0}),h=new p.PlaneGeometry(o,a),d=new p.Mesh(h,l);return Promise.resolve(d)}async loadDxfData(t,e,i,s,n){this.font||console.warn("[LoadingHelper] Should set font first!");const r=new X(this.manager,n);return r.setFont(this.font),await this.font?.getFontFromIndexeddb(),r.manager.onLoad=()=>{s&&s()},r.loadEx(t,e,i)}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new Xl.GLTFLoader(this.manager);const t=new Wl.DRACOLoader(this.manager);t.setDecoderPath(fs.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};g(fs,"DecoderPath","libs/draco/gltf/"),g(fs,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let Vt=fs;const ol=`(function(){"use strict";function Ks(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function ms(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}const ps={};function xs(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function yt(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Ut(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}function yi(...f){const t=f.join(" ");t in ps||(ps[t]=!0,yt(...f))}class Ve{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const $=["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 Re(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return($[f&255]+$[f>>8&255]+$[f>>16&255]+$[f>>24&255]+"-"+$[t&255]+$[t>>8&255]+"-"+$[t>>16&15|64]+$[t>>24&255]+"-"+$[e&63|128]+$[e>>8&255]+"-"+$[e>>16&255]+$[e>>24&255]+$[i&255]+$[i>>8&255]+$[i>>16&255]+$[i>>24&255]).toLowerCase()}function V(f,t,e){return Math.max(t,Math.min(e,f))}function me(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:case Uint8ClampedArray:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function K(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:case Uint8ClampedArray:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const hs=class hs{constructor(t=0,e=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("THREE.Vector2: 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("THREE.Vector2: 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,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,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 i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};hs.prototype.isVector2=!0;let Y=hs;class pe{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let z=o*l+c*d+h*y+u*m;z<0&&(l=-l,d=-d,y=-y,m=-m,z=-z);let b=1-a;if(z<.9995){const p=Math.acos(z),x=Math.sin(p);b=Math.sin(b*p)/x,a=Math.sin(a*p)/x,o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a}else{o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*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,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,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 i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:yt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(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=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(V(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),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 t===0?(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 i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*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}}const ls=class ls{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,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("THREE.Vector3: 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("THREE.Vector3: 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(gs.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(gs.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,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,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return mi.copy(this).projectOnVector(t),this.sub(mi)}reflect(t){return this.sub(mi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}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,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,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(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}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=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};ls.prototype.isVector3=!0;let S=ls;const mi=new S,gs=new pe,us=class us{constructor(t,e,i,s,n,r,a,o,c){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.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 i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],z=s[3],b=s[6],p=s[1],x=s[4],g=s[7],w=s[2],B=s[5],_=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*z+a*x+o*B,n[6]=r*b+a*g+o*_,n[1]=c*m+h*p+u*w,n[4]=c*z+h*x+u*B,n[7]=c*b+h*g+u*_,n[2]=l*m+d*p+y*w,n[5]=l*z+d*x+y*B,n[8]=l*b+d*g+y*_,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],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,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,i,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return yi("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(pi.makeScale(t,e)),this}rotate(t){return yi("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(pi.makeRotation(-t)),this}translate(t,e){return yi("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(pi.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),i=Math.sin(t);return this.set(e,-i,0,i,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,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}};us.prototype.isMatrix3=!0;let xt=us;const pi=new xt;function xi(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Zt;class tn{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Zt===void 0&&(Zt=ms("canvas")),Zt.width=t.width,Zt.height=t.height;const s=Zt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Zt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ms("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=xi(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(xi(e[i]/255)*255):e[i]=xi(e[i]);return{data:e,width:t.width,height:t.height}}else return yt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let en=0;class sn{constructor(t=null){this.isTextureSource=!0,Object.defineProperty(this,"id",{value:en++}),this.uuid=Re(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(gi(s[r].image)):n.push(gi(s[r]))}else n=gi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function gi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?tn.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(yt("Texture: Unable to serialize Texture."),{})}let nn=0;const wi=new S;class Nt extends Ve{constructor(t=Nt.DEFAULT_IMAGE,e=Nt.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Nt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Re(),this.name="",this.source=new sn(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(wi).x}get height(){return this.source.getSize(wi).y}get depth(){return this.source.getSize(wi).z}get image(){return this.source.data}set image(t){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){yt(\`Texture.setValues(): parameter '\${e}' has value of undefined.\`);continue}const s=this[e];if(s===void 0){yt(\`Texture.setValues(): property '\${e}' does not exist.\`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,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&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)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 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Nt.DEFAULT_IMAGE=null,Nt.DEFAULT_MAPPING=300,Nt.DEFAULT_ANISOTROPY=1;const fs=class fs{constructor(t=0,e=0,i=0,s=1){this.x=t,this.y=e,this.z=i,this.w=s}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,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,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("THREE.Vector4: 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("THREE.Vector4: 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=t.w!==void 0?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,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,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,i,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],z=o[6],b=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-z)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+z)<.1&&Math.abs(c+d+b-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,g=(d+1)/2,w=(b+1)/2,B=(h+l)/4,_=(u+m)/4,M=(y+z)/4;return x>g&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=B/i,n=_/i):g>w?g<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(g),i=B/s,n=M/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=_/n,s=M/n),this.set(i,s,n,e),this}let p=Math.sqrt((z-y)*(z-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(z-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+b-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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this.w=V(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this.w=V(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,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}};fs.prototype.isVector4=!0;let xe=fs;const ui=class ui{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){const b=this.elements;return b[0]=t,b[4]=e,b[8]=i,b[12]=s,b[1]=n,b[5]=r,b[9]=a,b[13]=o,b[2]=c,b[6]=h,b[10]=u,b[14]=l,b[3]=d,b[7]=y,b[11]=m,b[15]=z,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 ui().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[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,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,s=1/$t.setFromMatrixColumn(t,0).length(),n=1/$t.setFromMatrixColumn(t,1).length(),r=1/$t.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}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(rn,t,on)}lookAt(t,e,i){const s=this.elements;return et.subVectors(t,e),et.lengthSq()===0&&(et.z=1),et.normalize(),Pt.crossVectors(i,et),Pt.lengthSq()===0&&(Math.abs(i.z)===1?et.x+=1e-4:et.z+=1e-4,et.normalize(),Pt.crossVectors(i,et)),Pt.normalize(),ke.crossVectors(et,Pt),s[0]=Pt.x,s[4]=ke.x,s[8]=et.x,s[1]=Pt.y,s[5]=ke.y,s[9]=et.y,s[2]=Pt.z,s[6]=ke.z,s[10]=et.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],z=i[10],b=i[14],p=i[3],x=i[7],g=i[11],w=i[15],B=s[0],_=s[4],M=s[8],P=s[12],A=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],R=s[10],Z=s[14],tt=s[3],dt=s[7],at=s[11],pt=s[15];return n[0]=r*B+a*A+o*I+c*tt,n[4]=r*_+a*C+o*F+c*dt,n[8]=r*M+a*T+o*R+c*at,n[12]=r*P+a*E+o*Z+c*pt,n[1]=h*B+u*A+l*I+d*tt,n[5]=h*_+u*C+l*F+d*dt,n[9]=h*M+u*T+l*R+d*at,n[13]=h*P+u*E+l*Z+d*pt,n[2]=y*B+m*A+z*I+b*tt,n[6]=y*_+m*C+z*F+b*dt,n[10]=y*M+m*T+z*R+b*at,n[14]=y*P+m*E+z*Z+b*pt,n[3]=p*B+x*A+g*I+w*tt,n[7]=p*_+x*C+g*F+w*dt,n[11]=p*M+x*T+g*R+w*at,n[15]=p*P+x*E+g*Z+w*pt,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],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],z=t[11],b=t[15],p=o*d-c*l,x=a*d-c*u,g=a*l-o*u,w=r*d-c*h,B=r*l-o*h,_=r*u-a*h;return e*(m*p-z*x+b*g)-i*(y*p-z*w+b*B)+s*(y*x-m*w+b*_)-n*(y*g-m*B+z*_)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[1],r=t[5],a=t[9],o=t[2],c=t[6],h=t[10];return e*(r*h-a*c)-i*(n*h-a*o)+s*(n*c-r*o)}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,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],z=t[14],b=t[15],p=e*a-i*r,x=e*o-s*r,g=e*c-n*r,w=i*o-s*a,B=i*c-n*a,_=s*c-n*o,M=h*m-u*y,P=h*z-l*y,A=h*b-d*y,C=u*z-l*m,T=u*b-d*m,E=l*b-d*z,I=p*E-x*T+g*C+w*A-B*P+_*M;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*_-z*B+b*w)*F,t[3]=(l*B-u*_-d*w)*F,t[4]=(o*A-r*E-c*P)*F,t[5]=(e*E-s*A+n*P)*F,t[6]=(z*g-y*_-b*x)*F,t[7]=(h*_-l*g+d*x)*F,t[8]=(r*T-a*A+c*M)*F,t[9]=(i*A-e*T-n*M)*F,t[10]=(y*B-m*g+b*p)*F,t[11]=(u*g-h*B-d*p)*F,t[12]=(a*P-r*C-o*M)*F,t[13]=(e*C-i*P+s*M)*F,t[14]=(m*x-y*w-z*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){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,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,z=r*u,b=a*u,p=o*c,x=o*h,g=o*u,w=i.x,B=i.y,_=i.z;return s[0]=(1-(m+b))*w,s[1]=(d+g)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-g)*B,s[5]=(1-(l+b))*B,s[6]=(z+p)*B,s[7]=0,s[8]=(y+x)*_,s[9]=(z-p)*_,s[10]=(1-(l+m))*_,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinantAffine();if(n===0)return i.set(1,1,1),e.identity(),this;let r=$t.set(s[0],s[1],s[2]).length();const a=$t.set(s[4],s[5],s[6]).length(),o=$t.set(s[8],s[9],s[10]).length();n<0&&(r=-r),ct.copy(this);const c=1/r,h=1/a,u=1/o;return ct.elements[0]*=c,ct.elements[1]*=c,ct.elements[2]*=c,ct.elements[4]*=h,ct.elements[5]*=h,ct.elements[6]*=h,ct.elements[8]*=u,ct.elements[9]*=u,ct.elements[10]*=u,e.setFromRotationMatrix(ct),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}};ui.prototype.isMatrix4=!0;let H=ui;const $t=new S,ct=new H,rn=new S(0,0,0),on=new S(1,1,1),Pt=new S,ke=new S,et=new S,ws=new H,bs=new pe;class Ue{constructor(t=0,e=0,i=0,s=Ue.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}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,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,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,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(V(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-V(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(V(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-V(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(V(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-V(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:yt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ws.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ws,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bs.setFromEuler(this),this.setFromQuaternion(bs,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],t[3]!==void 0&&(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}}Ue.DEFAULT_ORDER="XYZ";class an{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let cn=0;const zs=new S,Jt=new pe,gt=new H,Ne=new S,ge=new S,hn=new S,ln=new pe,_s=new S(1,0,0),Ms=new S(0,1,0),As=new S(0,0,1),Ss={type:"added"},un={type:"removed"},Gt={type:"childadded",child:null},bi={type:"childremoved",child:null};class Ct extends Ve{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cn++}),this.uuid=Re(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ct.DEFAULT_UP.clone();const t=new S,e=new Ue,i=new pe,s=new S(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new H},normalMatrix:{value:new xt}}),this.matrix=new H,this.matrixWorld=new H,this.matrixAutoUpdate=Ct.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new an,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.multiply(Jt),this}rotateOnWorldAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.premultiply(Jt),this}rotateX(t){return this.rotateOnAxis(_s,t)}rotateY(t){return this.rotateOnAxis(Ms,t)}rotateZ(t){return this.rotateOnAxis(As,t)}translateOnAxis(t,e){return zs.copy(t).applyQuaternion(this.quaternion),this.position.add(zs.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(_s,t)}translateY(t){return this.translateOnAxis(Ms,t)}translateZ(t){return this.translateOnAxis(As,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(gt.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ne.copy(t):Ne.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),ge.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?gt.lookAt(ge,Ne,this.up):gt.lookAt(Ne,ge,this.up),this.quaternion.setFromRotationMatrix(gt),s&&(gt.extractRotation(s.matrixWorld),Jt.setFromRotationMatrix(gt),this.quaternion.premultiply(Jt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Ut("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(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null):Ut("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(un),bi.child=t,this.dispatchEvent(bi),bi.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),gt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),gt.multiply(t.parent.matrixWorld)),t.applyMatrix4(gt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.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 i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,t,hn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,ln,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}intersectsFrustum(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const n=this.children;for(let r=0,a=n.length;r<a;r++)n[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,s.name=this.name,s.castShadow=this.castShadow,s.receiveShadow=this.receiveShadow,s.visible=this.visible,s.frustumCulled=this.frustumCulled,s.renderOrder=this.renderOrder,s.static=this.static,s.matrixAutoUpdate=this.matrixAutoUpdate,Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}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.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}dispose(){this.dispatchEvent({type:"dispose"})}}Ct.DEFAULT_UP=new S(0,1,0),Ct.DEFAULT_MATRIX_AUTO_UPDATE=!0,Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ht=new S,wt=new S,zi=new S,bt=new S,Qt=new S,jt=new S,Bs=new S,_i=new S,Mi=new S,Ai=new S,Si=new xe,Bi=new xe,Ti=new xe;class st{constructor(t=new S,e=new S,i=new S){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ht.subVectors(t,e),s.cross(ht);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ht.subVectors(s,e),wt.subVectors(i,e),zi.subVectors(t,e);const r=ht.dot(ht),a=ht.dot(wt),o=ht.dot(zi),c=wt.dot(wt),h=wt.dot(zi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,bt)===null?!1:bt.x>=0&&bt.y>=0&&bt.x+bt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,bt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,bt.x),o.addScaledVector(r,bt.y),o.addScaledVector(a,bt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return Si.setScalar(0),Bi.setScalar(0),Ti.setScalar(0),Si.fromBufferAttribute(t,e),Bi.fromBufferAttribute(t,i),Ti.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(Si,n.x),r.addScaledVector(Bi,n.y),r.addScaledVector(Ti,n.z),r}static isFrontFacing(t,e,i,s){return ht.subVectors(i,e),wt.subVectors(t,e),ht.cross(wt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),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 ht.subVectors(this.c,this.b),wt.subVectors(this.a,this.b),ht.cross(wt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return st.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return st.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return st.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return st.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return st.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Qt.subVectors(s,i),jt.subVectors(n,i),_i.subVectors(t,i);const o=Qt.dot(_i),c=jt.dot(_i);if(o<=0&&c<=0)return e.copy(i);Mi.subVectors(t,s);const h=Qt.dot(Mi),u=jt.dot(Mi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Qt,r);Ai.subVectors(t,n);const d=Qt.dot(Ai),y=jt.dot(Ai);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(jt,a);const z=h*y-d*u;if(z<=0&&u-h>=0&&d-y>=0)return Bs.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(Bs,a);const b=1/(z+m+l);return r=m*b,a=l*b,e.copy(i).addScaledVector(Qt,r).addScaledVector(jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Q{constructor(t=new S(1/0,1/0,1/0),e=new S(-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,i=t.length;e<i;e+=3)this.expandByPoint(lt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(lt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=lt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),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 i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,lt):lt.fromBufferAttribute(n,r),lt.applyMatrix4(t.matrixWorld),this.expandByPoint(lt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Le.copy(i.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],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,lt),lt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(we),De.subVectors(this.max,we),Kt.subVectors(t.a,we),te.subVectors(t.b,we),ee.subVectors(t.c,we),Et.subVectors(te,Kt),It.subVectors(ee,te),Lt.subVectors(Kt,ee);let e=[0,-Et.z,Et.y,0,-It.z,It.y,0,-Lt.z,Lt.y,Et.z,0,-Et.x,It.z,0,-It.x,Lt.z,0,-Lt.x,-Et.y,Et.x,0,-It.y,It.x,0,-Lt.y,Lt.x,0];return!Pi(e,Kt,te,ee,De)||(e=[1,0,0,0,1,0,0,0,1],!Pi(e,Kt,te,ee,De))?!1:(qe.crossVectors(Et,It),e=[qe.x,qe.y,qe.z],Pi(e,Kt,te,ee,De))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,lt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(lt).length()*.5),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()?this:(zt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),zt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),zt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),zt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),zt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),zt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),zt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),zt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(zt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const zt=[new S,new S,new S,new S,new S,new S,new S,new S],lt=new S,Le=new Q,Kt=new S,te=new S,ee=new S,Et=new S,It=new S,Lt=new S,we=new S,De=new S,qe=new S,Dt=new S;function Pi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Dt.fromArray(f,n);const a=s.x*Math.abs(Dt.x)+s.y*Math.abs(Dt.y)+s.z*Math.abs(Dt.z),o=t.dot(Dt),c=e.dot(Dt),h=i.dot(Dt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const L=new S,ve=new Y;let fn=0;class mt extends Ve{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:fn++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&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,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)ve.fromBufferAttribute(this,e),ve.applyMatrix3(t),this.setXY(e,ve.x,ve.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix3(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix4(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyNormalMatrix(t),this.setXYZ(e,L.x,L.y,L.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.transformDirection(t),this.setXYZ(e,L.x,L.y,L.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=me(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=K(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=me(e,this.array)),e}setX(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=me(e,this.array)),e}setY(t,e){return this.normalized&&(e=K(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=me(e,this.array)),e}setZ(t,e){return this.normalized&&(e=K(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=me(e,this.array)),e}setW(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array),n=K(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,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 t.name=this.name,t.usage=this.usage,t.gpuType=this.gpuType,t}dispose(){this.dispatchEvent({type:"dispose"})}}class dn extends mt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class yn extends mt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class mn extends mt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const pn=new Q,be=new S,Ci=new S;class xn{constructor(t=new S,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 i=this.center;e!==void 0?i.copy(e):pn.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),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 i=this.center.distanceToSquared(t);return e.copy(t),i>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;be.subVectors(t,this.center);const e=be.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(be,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Ci.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(be.copy(t.center).add(Ci)),this.expandByPoint(be.copy(t.center).sub(Ci))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let gn=0;const nt=new H,Ei=new Ct,ie=new S,it=new Q,ze=new Q,W=new S;class Ii extends Ve{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:gn++}),this.uuid=Re(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ks(t)?yn:dn)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new xt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return nt.makeRotationFromQuaternion(t),this.applyMatrix4(nt),this}rotateX(t){return nt.makeRotationX(t),this.applyMatrix4(nt),this}rotateY(t){return nt.makeRotationY(t),this.applyMatrix4(nt),this}rotateZ(t){return nt.makeRotationZ(t),this.applyMatrix4(nt),this}translate(t,e,i){return nt.makeTranslation(t,e,i),this.applyMatrix4(nt),this}scale(t,e,i){return nt.makeScale(t,e,i),this.applyMatrix4(nt),this}lookAt(t){return Ei.lookAt(t),Ei.updateMatrix(),this.applyMatrix4(Ei.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ie).negate(),this.translate(ie.x,ie.y,ie.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new mn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&yt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Q);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new S(-1/0,-1/0,-1/0),new S(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];it.setFromBufferAttribute(n),this.morphTargetsRelative?(W.addVectors(this.boundingBox.min,it.min),this.boundingBox.expandByPoint(W),W.addVectors(this.boundingBox.max,it.max),this.boundingBox.expandByPoint(W)):(this.boundingBox.expandByPoint(it.min),this.boundingBox.expandByPoint(it.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ut('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new xn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new S,1/0);return}if(t){const i=this.boundingSphere.center;if(it.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ze.setFromBufferAttribute(a),this.morphTargetsRelative?(W.addVectors(it.min,ze.min),it.expandByPoint(W),W.addVectors(it.max,ze.max),it.expandByPoint(W)):(it.expandByPoint(ze.min),it.expandByPoint(ze.max))}it.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)W.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(W));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)W.fromBufferAttribute(a,c),o&&(ie.fromBufferAttribute(t,c),W.add(ie)),s=Math.max(s,i.distanceToSquared(W))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Ut('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(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Ut("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new mt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],o=[];for(let M=0;M<i.count;M++)a[M]=new S,o[M]=new S;const c=new S,h=new S,u=new S,l=new Y,d=new Y,y=new Y,m=new S,z=new S;function b(M,P,A){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,A),l.fromBufferAttribute(n,M),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,A),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),z.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[M].add(m),a[P].add(m),a[A].add(m),o[M].add(z),o[P].add(z),o[A].add(z))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)b(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new S,g=new S,w=new S,B=new S;function _(M){w.fromBufferAttribute(s,M),B.copy(w);const P=a[M];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),g.crossVectors(B,P);const C=g.dot(o[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,C)}for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)_(t.getX(E+0)),_(t.getX(E+1)),_(t.getX(E+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new mt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new S,n=new S,r=new S,a=new S,o=new S,c=new S,h=new S,u=new S;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),z=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,z),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,z),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(z,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)W.fromBufferAttribute(t,e),W.normalize(),t.setXYZ(e,W.x,W.y,W.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,z=o.length;m<z;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let b=0;b<h;b++)l[y++]=c[d++]}return new mt(l,h,u)}if(this.index===null)return yt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Ii,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,t.name=this.name,Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Fi=new S,wn=new S,bn=new xt;class Ts{constructor(t=new S(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,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Fi.subVectors(i,e).cross(wn.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,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,i=!0){const s=t.delta(Fi),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/n;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<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 i=e||bn.getNormalMatrix(t),s=this.coplanarPoint(Fi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),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)}toJSON(){return{normal:this.normal.toArray(),constant:this.constant}}fromJSON(t){return this.normal.fromArray(t.normal),this.constant=t.constant,this}}const _t=new S,Vi=new S,Oe=new S,We=new S;class zn{constructor(t=new S,e=new S(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,_t)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=_t.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(_t.copy(this.origin).addScaledVector(this.direction,e),_t.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){Vi.copy(t).add(e).multiplyScalar(.5),Oe.copy(e).sub(t).normalize(),We.copy(this.origin).sub(Vi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(Oe),a=We.dot(this.direction),o=-We.dot(Oe),c=We.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(Vi).addScaledVector(Oe,l),d}intersectSphere(t,e){if(t.radius<0)return null;_t.subVectors(t.center,this.origin);const i=_t.dot(this.direction),s=_t.dot(_t)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,_t)!==null}intersectTriangle(t,e,i,s,n){const r=this.origin,a=this.direction,o=a.x,c=a.y,h=a.z,u=t.x-r.x,l=t.y-r.y,d=t.z-r.z,y=e.x-r.x,m=e.y-r.y,z=e.z-r.z,b=i.x-r.x,p=i.y-r.y,x=i.z-r.z,g=Math.abs(o),w=Math.abs(c),B=Math.abs(h);let _,M,P,A,C,T,E,I,F,R,Z,tt;if(g>=w&&g>=B?(P=o,T=u,F=y,tt=b,o>=0?(_=c,M=h,A=l,C=d,E=m,I=z,R=p,Z=x):(_=h,M=c,A=d,C=l,E=z,I=m,R=x,Z=p)):w>=B?(P=c,T=l,F=m,tt=p,c>=0?(_=h,M=o,A=d,C=u,E=z,I=y,R=x,Z=b):(_=o,M=h,A=u,C=d,E=y,I=z,R=b,Z=x)):(P=h,T=d,F=z,tt=x,h>=0?(_=o,M=c,A=u,C=l,E=y,I=m,R=b,Z=p):(_=c,M=o,A=l,C=u,E=m,I=y,R=p,Z=b)),P===0)return null;const dt=_/P,at=M/P,pt=1/P,ye=A-dt*T,Ie=C-at*T,ys=E-dt*F,Tt=I-at*F,fi=R-dt*tt,di=Z-at*tt,Wt=fi*Tt-di*ys,Xt=ye*di-Ie*fi,Yt=ys*Ie-Tt*ye;if(s){if(Wt<0||Xt<0||Yt<0)return null}else if((Wt<0||Xt<0||Yt<0)&&(Wt>0||Xt>0||Yt>0))return null;const Fe=Wt+Xt+Yt;if(Fe===0)return null;const Ht=pt*(Wt*T+Xt*F+Yt*tt);return(Fe>0?Ht<0:Ht>0)?null:this.at(Ht/Fe,n)}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)}}const ds=class ds{constructor(t,e,i,s){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,s){const n=this.elements;return n[0]=t,n[2]=e,n[1]=i,n[3]=s,this}};ds.prototype.isMatrix2=!0;let Ps=ds;const Cs=new S,Xe=new S,se=new S,ne=new S,Ri=new S,_n=new S,Mn=new S;class Mt{constructor(t=new S,e=new S){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){Cs.subVectors(t,this.start),Xe.subVectors(this.end,this.start);const i=Xe.dot(Xe);if(i===0)return 0;let n=Xe.dot(Cs)/i;return e&&(n=V(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=_n,i=Mn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;se.subVectors(c,a),ne.subVectors(h,o),Ri.subVectors(a,o);const u=se.dot(se),l=ne.dot(ne),d=ne.dot(Ri);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=V(r,0,1);else{const y=se.dot(Ri);if(l<=s)r=0,n=V(-y/u,0,1);else{const m=se.dot(ne),z=u*l-m*m;z!==0?n=V((m*d-y*l)/z,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=V(-y/u,0,1)):r>1&&(r=1,n=V((m-y)/u,0,1))}}return e.copy(a).addScaledVector(se,n),i.copy(o).addScaledVector(ne,r),e.distanceToSquared(i)}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)}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"186"}})),typeof window<"u"&&(window.__THREE__?yt("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="186");new xt().set(-1,0,0,0,1,0,0,0,1),new xt().set(-1,0,0,0,1,0,0,0,1);const Es=0,An=1,Sn=2,Is=2,ki=1.25,Fs=1,J=32,q=J/4,Vs=65535,Ye=Math.pow(2,-24),Ui=Symbol("SKIP_GENERATION"),Rs={strategy:Es,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ui]:!1};function U(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ni(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function ks(f,t){t.set(f)}function Us(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function He(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function N(f,t){return t[f+15]===Vs}function X(f,t){return t[f+6]}function G(f,t){return t[f+14]}function v(f){return f+q}function O(f,t){const e=t[f+6];return f+e*q}function Li(f,t){return t[f+7]}function Wr(f){return f}function Di(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,z=-1/0;const b=f.offset||0;for(let p=(t-b)*6,x=(t+e-b)*6;p<x;p+=6){const g=f[p+0],w=f[p+1],B=g-w,_=g+w;B<n&&(n=B),_>o&&(o=_),g<u&&(u=g),g>y&&(y=g);const M=f[p+2],P=f[p+3],A=M-P,C=M+P;A<r&&(r=A),C>c&&(c=C),M<l&&(l=M),M>m&&(m=M);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>z&&(z=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=z}const At=32,Bn=(f,t)=>f.candidate-t.candidate,Ft=new Array(At).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ze=new Float32Array(6);function Tn(f,t,e,i,s,n){let r=-1,a=0;if(n===Es)r=Ni(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===An)r=Ni(f),r!==-1&&(a=Pn(e,i,s,r));else if(n===Sn){const o=_e(f);let c=ki*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],b=(t[d+3]-y)/At;if(s<At/4){const p=[...Ft];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const B=p[x];B.candidate=e[w+2*d],B.count=0;const{bounds:_,leftCacheBounds:M,rightCacheBounds:P}=B;for(let A=0;A<3;A++)P[A]=1/0,P[A+3]=-1/0,M[A]=1/0,M[A+3]=-1/0,_[A]=1/0,_[A+3]=-1/0;He(w,e,_)}p.sort(Bn);let g=s;for(let w=0;w<g;w++){const B=p[w];for(;w+1<g&&p[w+1].candidate===B.candidate;)p.splice(w+1,1),g--}for(let w=u;w<l;w+=6){const B=e[w+2*d];for(let _=0;_<g;_++){const M=p[_];B>=M.candidate?He(w,e,M.rightCacheBounds):(He(w,e,M.leftCacheBounds),M.count++)}}for(let w=0;w<g;w++){const B=p[w],_=B.count,M=s-B.count,P=B.leftCacheBounds,A=B.rightCacheBounds;let C=0;_!==0&&(C=_e(P)/o);let T=0;M!==0&&(T=_e(A)/o);const E=Fs+ki*(C*_+T*M);E<c&&(r=d,c=E,a=B.candidate)}}else{for(let g=0;g<At;g++){const w=Ft[g];w.count=0,w.candidate=y+b+g*b;const B=w.bounds;for(let _=0;_<3;_++)B[_]=1/0,B[_+3]=-1/0}for(let g=u;g<l;g+=6){let _=~~((e[g+2*d]-y)/b);_>=At&&(_=At-1);const M=Ft[_];M.count++,He(g,e,M.bounds)}const p=Ft[At-1];ks(p.bounds,p.rightCacheBounds);for(let g=At-2;g>=0;g--){const w=Ft[g],B=Ft[g+1];Us(w.bounds,B.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let g=0;g<At-1;g++){const w=Ft[g],B=w.count,_=w.bounds,P=Ft[g+1].rightCacheBounds;B!==0&&(x===0?ks(_,Ze):Us(_,Ze,Ze)),x+=B;let A=0,C=0;x!==0&&(A=_e(Ze)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=Fs+ki*(A*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(\`BVH: Invalid build strategy value \${n} used.\`);return{axis:r,pos:a}}function Pn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class qi{constructor(){this.boundingData=new Float32Array(6)}}function Cn(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Ns,$e,vi,Ls;const En=Math.pow(2,32);function Oi(f){return"count"in f?1:1+Oi(f.left)+Oi(f.right)}function In(f,t,e){return Ns=new Float32Array(e),$e=new Uint32Array(e),vi=new Uint16Array(e),Ls=new Uint8Array(e),Wi(f,t)}function Wi(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Ns[e+r]=n[r];if(s)return t.buffer?(Ls.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):($e[e+6]=t.offset,vi[i+14]=t.count,vi[i+15]=Vs,f+J);{const{left:r,right:a,splitAxis:o}=t,c=f+J;let h=Wi(c,r);const u=f/J,d=h/J-u;if(d>En)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return $e[e+6]=d,$e[e+7]=o,Wi(h,a)}}function Fn(f,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:c=1/0,strategy:h,onProgress:u}=s,l=f.primitiveBuffer,d=f.primitiveBufferStride,y=new Float32Array(6);let m=!1;const z=new qi;return Di(t,e,i,z.boundingData,y),p(z,e,i,y),z;function b(x){u&&u((x-n.offset)/n.count)}function p(x,g,w,B=null,_=0){!m&&_>=r&&(m=!0,a&&console.warn(\`BVH: Max depth of \${r} reached when generating BVH. Consider increasing maxDepth.\`));const M=w>c;if(w<=o&&!M||_>=r)return b(g+w),x.offset=g,x.count=w,x;const P=Tn(x.boundingData,B,t,g,w,h);let A=P.axis===-1?-1:Cn(l,d,t,g,w,P);if(P.axis===-1||A===g||A===g+w){if(!M)return b(g+w),x.offset=g,x.count=w,x;P.axis=Math.max(0,Ni(x.boundingData)),A=g+Math.max(1,Math.floor(w/2))}x.splitAxis=P.axis;const C=new qi,T=g,E=A-g;x.left=C,Di(t,T,E,C.boundingData,y),p(C,T,E,y,_+1);const I=new qi,F=A,R=w-E;return x.right=I,Di(t,F,R,I.boundingData,y),p(I,F,R,y,_+1),x}}function Vn(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=Fn(f,a,o.offset,o.count,t,r),h=Oi(c),u=new e(J*h);return In(0,c,u),u})}class Xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const k=new Rn;let Vt,re;const oe=[],Je=new Xi(()=>new Q);function kn(f,t,e,i,s,n){Vt=Je.getPrimitive(),re=Je.getPrimitive(),oe.push(Vt,re),k.setBuffer(f._roots[t]);const r=Yi(0,f.geometry,e,i,s,n);k.clearBuffer(),Je.releasePrimitive(Vt),Je.releasePrimitive(re),oe.pop(),oe.pop();const a=oe.length;return a>0&&(re=oe[a-1],Vt=oe[a-2]),r}function Yi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=k;let h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);return U(f,a,Vt),i(l,d,!1,r,n+f/q,Vt)}else{let A=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=v(T),F=T*2;return X(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=O(T,I),F=T*2;return X(T,I)+G(F,E)};const l=v(f),d=O(f,c);let y=l,m=d,z,b,p,x;if(s&&(p=Vt,x=re,U(y,a,p),U(m,a,x),z=s(p),b=s(x),b<z)){y=d,m=l;const T=z;z=b,b=T,p=x}p||(p=Vt,U(y,a,p));const g=N(y*2,o),w=e(p,g,z,r+1,n+y/q);let B;if(w===Is){const T=A(y),I=C(y)-T;B=i(T,I,!0,r+1,n+y/q,p)}else B=w&&Yi(y,t,e,i,s,n,r+1);if(B)return!0;x=re,U(m,a,x);const _=N(m*2,o),M=e(x,_,b,r+1,n+m/q);let P;if(M===Is){const T=A(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/q,x)}else P=M&&Yi(m,t,e,i,s,n,r+1);return!!P}}const Me=new k.constructor,Ge=new k.constructor,Rt=new Xi(()=>new Q),ae=new Q,ce=new Q,Hi=new Q,Zi=new Q;let $i=!1;function Un(f,t,e,i){if($i)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");$i=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new H().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Me.setBuffer(s[h]),o=0;const l=Rt.getPrimitive();U(0,Me.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(Ge.setBuffer(n[d]),r=ut(0,0,e,c,i,a,o,0,0,l),Ge.clearBuffer(),o+=n[d].byteLength/J,!r);d++);if(Rt.releasePrimitive(l),Me.clearBuffer(),a+=s[h].byteLength/J,r)break}return $i=!1,r}function ut(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=Ge,l=Me):(u=Me,l=Ge);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,z=l.float32Array,b=l.uint32Array,p=l.uint16Array,x=f*2,g=t*2,w=N(x,m),B=N(g,p);let _=!1;if(B&&w)h?_=s(X(t,b),G(t*2,p),X(f,y),G(f*2,m),o,r+t/q,a,n+f/q):_=s(X(f,y),G(f*2,m),X(t,b),G(t*2,p),a,n+f/q,o,r+t/q);else if(B){const M=Rt.getPrimitive();U(t,z,M),M.applyMatrix4(e);const P=v(f),A=O(f,y);U(P,d,ae),U(A,d,ce);const C=M.intersectsBox(ae),T=M.intersectsBox(ce);_=C&&ut(t,P,i,e,s,r,n,o,a+1,M,!h)||T&&ut(t,A,i,e,s,r,n,o,a+1,M,!h),Rt.releasePrimitive(M)}else{const M=v(t),P=O(t,b);U(M,z,Hi),U(P,z,Zi);const A=c.intersectsBox(Hi),C=c.intersectsBox(Zi);if(A&&C)_=ut(f,M,e,i,s,n,r,a,o+1,c,h)||ut(f,P,e,i,s,n,r,a,o+1,c,h);else if(A)if(w)_=ut(f,M,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Hi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(M,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(M,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}else if(C)if(w)_=ut(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Zi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(P,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(P,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}}return _}const Ji=new class{constructor(){let f=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=f=n._roots[r],this.uint16Array=e=new Uint16Array(f),this.uint32Array=t=new Uint32Array(f)},this.reset=()=>{this.root=null,this.buffer=f=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!N(r,e);)n=v(n),r=n*2;return X(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!N(r,e);)n=O(n,t),r=n*2;return X(n,t)+G(r,e)};const s=(n,r,a)=>{const o=r*2,c=N(o,e);if(!n(a,c,r)&&!c){const u=v(r),l=O(r,t);s(n,u,a+1),s(n,l,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const c=o*2,h=t[o+6],u=e[c+14];return n(r,a,new Float32Array(f,o*4,6),h,u)}else{const c=Li(o,t);return n(r,a,new Float32Array(f,o*4,6),c)}})}}},Ds=new Q,he=new Float32Array(6);class Nn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...Rs,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Vn(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,he,0);const[d,y,m,z,b,p]=he;d<n&&(n=d),z>o&&(o=z),y<r&&(r=y),b>c&&(c=b),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,he,0);const[a,o,c,h,u,l]=he,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,z=(h-a)/2,b=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=z+(Math.abs(d)+z)*Ye,i[x+2]=y,i[x+3]=b+(Math.abs(y)+b)*Ye,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Ye}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/J;for(let c=0;c<o;c++){const h=q*c,u=2*h;N(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){Ji.setBVH(this,e),Ji.traverse(t),Ji.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/J;for(let c=o-1;c>=0;c--){const h=c*q,u=h*2;if(N(u,r)){const d=X(h,n),y=G(u,r);this.writePrimitiveRangeBounds(d,y,he,0),a.set(he,h)}else{const d=v(h),y=O(h,n);for(let m=0;m<3;m++){const z=a[d+m],b=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=z<p?z:p,a[h+m+3]=b>x?b:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{U(0,new Float32Array(i),Ds),t.union(Ds)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,z)=>u(l,d,y,m,z)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=kn(this,u,i,s,e,c),o)break;c+=d.byteLength/J}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Un(this,t,e,s)}}function Ln(){return typeof SharedArrayBuffer<"u"}function Gi(f){return f.index?f.index.count:f.attributes.position.count}function Qe(f){return Gi(f)/3}function Dn(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function qn(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Dn(e,i);f.setIndex(new mt(s,1));for(let n=0;n<e;n++)s[n]=n}}function vn(f,t,e){const i=Gi(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function On(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function qs(f,t,e){const i=vn(f,t,e),s=On(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Gi(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,z=isFinite(y)?y:o-d,b=d+z;m<a&&b>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,b),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}function Wn(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class Xn extends Nn{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Ln())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...Rs,...e},e[Ui]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=qs(e,t.range,i),n=Wn(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else qn(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Q))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:qs(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class St{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}St.prototype.setFromBox=(function(){const f=new S;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const Yn=(function(){const f=new S,t=new S,e=new S;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),z=o.dot(o)*d-l*l;let b,p;z!==0?b=(u*l-y*d)/z:b=0,p=(u+b*l)/d,r.x=b,r.y=p}})(),Qi=(function(){const f=new Y,t=new S,e=new S;return function(s,n,r,a){Yn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),Hn=(function(){const f=new S,t=new S,e=new Ts,i=new Mt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const b=m.projectPoint(o,t);if(r.containsPoint(b))return!0}return!1}})(),Zn=["x","y","z"],Bt=1e-15,vs=Bt*Bt;function rt(f){return Math.abs(f)<Bt}class ft extends st{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new S),this.satBounds=new Array(4).fill().map(()=>new St),this.points=[this.a,this.b,this.c],this.plane=new Ts,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Mt,this.needsUpdate=!0}intersectsSphere(t){return Hn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),z=u.length(),b=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<Bt?z<Bt||b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):z<Bt?b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):b<Bt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ft.prototype.closestPointToSegment=(function(){const f=new S,t=new S,e=new Mt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Qi(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ft.prototype.intersectsTriangle=(function(){const f=new ft,t=new St,e=new St,i=new S,s=new S,n=new S,r=new S,a=new Mt,o=new Mt,c=new S,h=new Y,u=new Y;function l(x,g,w,B){const _=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?_.copy(x.plane.normal):_.copy(g.plane.normal);const M=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=M[T],I=P[T];if(t.setFromPoints(I,g.points),E.isSeparated(t)||(r.copy(_).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}const A=g.satBounds,C=g.satAxes;for(let T=1;T<4;T++){const E=A[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(_,I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}return w&&(B||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,g,w,B,_,M,P,A,C,T,E){let I=P/(P-A);T.x=B+(_-B)*I,E.start.subVectors(g,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=B+(M-B)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,g,w,B,_,M,P,A,C,T,E){if(_>0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else if(M>0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(A*C>0||P!=0)d(x.a,x.b,x.c,g,w,B,P,A,C,T,E);else if(A!=0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else return!0;return!1}function m(x,g,w,B){const _=g.degenerateSegment,M=x.plane.distanceToPoint(_.start),P=x.plane.distanceToPoint(_.end);return rt(M)?rt(P)?l(x,g,w,B):(w&&(w.start.copy(_.start),w.end.copy(_.start)),x.containsPoint(_.start)):rt(P)?(w&&(w.start.copy(_.end),w.end.copy(_.end)),x.containsPoint(_.end)):x.plane.intersectLine(_,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function z(x,g,w){const B=g.a;return rt(x.plane.distanceToPoint(B))&&x.containsPoint(B)?(w&&(w.start.copy(B),w.end.copy(B)),!0):!1}function b(x,g,w){const B=x.degenerateSegment,_=g.a;return B.closestPointToPoint(_,!0,i),_.distanceToSquared(i)<vs?(w&&(w.start.copy(_),w.end.copy(_)),!0):!1}function p(x,g,w,B){if(x.isDegenerateIntoSegment)if(g.isDegenerateIntoSegment){const _=x.degenerateSegment,M=g.degenerateSegment,P=s,A=n;_.delta(P),M.delta(A);const C=i.subVectors(M.start,_.start),T=P.x*A.y-P.y*A.x;if(rt(T))return!1;const E=(C.x*A.y-C.y*A.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=_.start.z+P.z*E,R=M.start.z+A.z*I;return rt(F-R)?(w&&(w.start.copy(_.start).addScaledVector(P,E),w.end.copy(_.start).addScaledVector(P,E)),!0):!1}else return g.isDegenerateIntoPoint?b(x,g,w):m(g,x,w,B);else{if(x.isDegenerateIntoPoint)return g.isDegenerateIntoPoint?g.a.distanceToSquared(x.a)<vs?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:g.isDegenerateIntoSegment?b(g,x,w):z(g,x,w);if(g.isDegenerateIntoPoint)return z(x,g,w);if(g.isDegenerateIntoSegment)return m(x,g,w,B)}}return function(g,w=null,B=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(f.copy(g),f.update(),g=f);const _=p(this,g,w,B);if(_!==void 0)return _;const M=this.plane,P=g.plane;let A=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);rt(A)&&(A=0),rt(C)&&(C=0),rt(T)&&(T=0);const E=A*C,I=A*T;if(E>0&&I>0)return!1;let F=M.distanceToPoint(g.a),R=M.distanceToPoint(g.b),Z=M.distanceToPoint(g.c);rt(F)&&(F=0),rt(R)&&(R=0),rt(Z)&&(Z=0);const tt=F*R,dt=F*Z;if(tt>0&&dt>0)return!1;s.copy(M.normal),n.copy(P.normal);const at=s.cross(n);let pt=0,ye=Math.abs(at.x);const Ie=Math.abs(at.y);Ie>ye&&(ye=Ie,pt=1),Math.abs(at.z)>ye&&(pt=2);const Tt=Zn[pt],fi=this.a[Tt],di=this.b[Tt],Wt=this.c[Tt],Xt=g.a[Tt],Yt=g.b[Tt],Fe=g.c[Tt];if(y(this,fi,di,Wt,E,I,A,C,T,h,a))return l(this,g,w,B);if(y(g,Xt,Yt,Fe,tt,dt,F,R,Z,u,o))return l(this,g,w,B);if(h.y<h.x){const Ht=h.y;h.y=h.x,h.x=Ht,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const Ht=u.y;u.y=u.x,u.x=Ht,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ft.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ft.prototype.distanceToTriangle=(function(){const f=new S,t=new S,e=["a","b","c"],i=new Mt,s=new Mt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c,!0))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],z=e[(y+1)%3];s.set(r[m],r[z]),Qi(i,s,f,t);const b=f.distanceToSquared(t);b<h&&(h=b,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class j{constructor(t,e,i){this.isOrientedBox=!0,this.min=new S,this.max=new S,this.matrix=new H,this.invMatrix=new H,this.points=new Array(8).fill().map(()=>new S),this.satAxes=new Array(3).fill().map(()=>new S),this.satBounds=new Array(3).fill().map(()=>new St),this.alignedSatBounds=new Array(3).fill().map(()=>new St),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}j.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),j.prototype.intersectsBox=(function(){const f=new St;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),j.prototype.intersectsTriangle=(function(){const f=new ft,t=new Array(3),e=new St,i=new St,s=new S;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),j.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}})(),j.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),j.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new Mt),e=new Array(12).fill().map(()=>new Mt),i=new S,s=new S;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let z=0;z<8;z++){const b=d[z];s.copy(b).clamp(u,l);const p=b.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(b),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let z=0;z<3;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const x=(z+1)%3,g=(z+2)%3,w=b<<x|p<<g,B=1<<z|b<<x|p<<g,_=d[w],M=d[B];t[m].set(_,M);const A=f[z],C=f[x],T=f[g],E=e[m],I=E.start,F=E.end;I[A]=u[A],I[C]=b?u[C]:l[C],I[T]=p?u[T]:l[C],F[A]=l[A],F[C]=b?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let z=0;z<=1;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=z?l.x:u.x,s.y=b?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let z=0;z<12;z++){const b=t[z];for(let p=0;p<12;p++){const x=e[p];Qi(b,x,i,s);const g=i.distanceToSquared(s);if(g<y&&(y=g,o&&o.copy(i),c&&c.copy(s),g<h))return Math.sqrt(g)}}return Math.sqrt(y)}})();class $n extends Xi{constructor(){super(()=>new ft)}}const ot=new $n,Ae=new S,ji=new S;function Jn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(Ae.copy(t).clamp(h.min,h.max),Ae.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,Ae);const l=t.distanceToSquared(Ae);return l<a&&(ji.copy(Ae),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(ji):e.point=ji.clone(),e.distance=c,e.faceIndex=o,e}const je=parseInt("186")>=169,Gn=parseInt("186")<=161,qt=new S,vt=new S,Ot=new S,Ke=new Y,ti=new Y,ei=new Y,Os=new S,Ws=new S,Xs=new S,Se=new S;function Qn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function Ys(f,t,e,i,s,n,r,a,o,c,h){qt.fromBufferAttribute(t,n),vt.fromBufferAttribute(t,r),Ot.fromBufferAttribute(t,a);const u=Qn(f,qt,vt,Ot,Se,o,c,h);if(u){if(i){Ke.fromBufferAttribute(i,n),ti.fromBufferAttribute(i,r),ei.fromBufferAttribute(i,a),u.uv=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv);je||(u.uv=d)}if(s){Ke.fromBufferAttribute(s,n),ti.fromBufferAttribute(s,r),ei.fromBufferAttribute(s,a),u.uv1=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv1);je||(u.uv1=d),Gn&&(u.uv2=u.uv1)}if(e){Os.fromBufferAttribute(e,n),Ws.fromBufferAttribute(e,r),Xs.fromBufferAttribute(e,a),u.normal=new S;const d=st.getInterpolation(Se,qt,vt,Ot,Os,Ws,Xs,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),je||(u.normal=d)}const l={a:n,b:r,c:a,normal:new S,materialIndex:0};if(st.getNormal(qt,vt,Ot,l.normal),u.face=l,u.faceIndex=n,je){const d=new S;st.getBarycoord(Se,qt,vt,Ot,d),u.barycoord=d}}return u}function Hs(f){return f&&f.isMaterial?f.side:f}function ii(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:z}=f.attributes;if(Array.isArray(t)){const b=i*3;for(let p=0,x=l.length;p<x;p++){const{start:g,count:w,materialIndex:B}=l[p];if(b>=g&&b<g+w){const _=Hs(t[B]),M=Ys(e,d,y,m,z,o,c,h,_,n,r);if(M)if(M.faceIndex=i,M.face.materialIndex=B,s)s.push(M);else return M}}}else{const b=Hs(t),p=Ys(e,d,y,m,z,o,c,h,b,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function jn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)ii(o,t,e,h,n,r,a)}function Kn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function tr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function er(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=3*z,P=3*(z+b);M<P;M++){let A=i[M];const C=s.getX(A),T=s.getY(A),E=s.getZ(A);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>B&&(B=T),E<g&&(g=E),E>_&&(_=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function kt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,z=e.origin.z;let b=t[f],p=t[f+3],x=t[f+1],g=t[f+3+1],w=t[f+2],B=t[f+3+2];return u>=0?(n=(b-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(b-y)*u),l>=0?(a=(x-m)*l,o=(g-m)*l):(a=(g-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-z)*d,h=(B-z)*d):(c=(B-z)*d,h=(w-z)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function ir(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;ii(o,t,e,l,n,r,a)}}function sr(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function nr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function rr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),Ki(0,f,e,i,s,n,r),k.clearBuffer()}function Ki(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);jn(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&Ki(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&Ki(d,t,e,i,s,n,r)}}const or=["x","y","z"];function ar(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ts(0,f,e,i,s,n);return k.clearBuffer(),r}function ts(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return Kn(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=or[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ts(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ts(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const si=new Q,le=new ft,ue=new ft,Be=new H,Zs=new j,ni=new j;function cr(f,t,e,i){k.setBuffer(f._roots[t]);const s=es(0,f,e,i);return k.clearBuffer(),s}function es(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Zs.set(e.boundingBox.min,e.boundingBox.max,i),s=Zs),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Be.copy(i).invert(),e.boundsTree)return U(f,n,ni),ni.matrix.copy(Be),ni.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ni.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,g=(z+m)*3;x<g;x+=3)if(D(ue,x,u,l),ue.needsUpdate=!0,p.intersectsTriangle(ue))return!0;return!1}});{const b=Qe(e);for(let p=m*3,x=(z+m)*3;p<x;p+=3){D(le,p,u,l),le.a.applyMatrix4(Be),le.b.applyMatrix4(Be),le.c.applyMatrix4(Be),le.needsUpdate=!0;for(let g=0,w=b*3;g<w;g+=3)if(D(ue,g,d,y),ue.needsUpdate=!0,le.intersectsTriangle(ue))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,si),!!(s.intersectsBox(si)&&es(h,t,e,i,s)||(U(u,n,si),s.intersectsBox(si)&&es(u,t,e,i,s)))}}const ri=new H,is=new j,Te=new j,hr=new S,lr=new S,ur=new S,fr=new S;function dr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),is.set(t.boundingBox.min,t.boundingBox.max,e),is.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=hr,m=lr,z=null,b=null;s&&(z=ur,b=fr);let p=1/0,x=null,g=null;return ri.copy(e).invert(),Te.matrix.copy(ri),f.shapecast({boundsTraverseOrder:w=>is.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Te.min.copy(w.min),Te.max.copy(w.max),Te.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:M=>Te.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+B;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,z);if(I<p&&(m.copy(y),b&&b.copy(z),p=I,x=T,g=A),I<n)return!0}}}});{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){D(l,3*A,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,z);if(T<p&&(m.copy(y),b&&b.copy(z),p=T,x=A,g=M),T<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ri),m.applyMatrix4(ri),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function yr(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=z,P=z+b;M<P;M++){const A=3*f.resolveTriangleIndex(M);for(let C=0;C<3;C++){let T=A+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>B&&(B=I),F<g&&(g=F),F>_&&(_=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function mr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),ss(0,f,e,i,s,n,r),k.clearBuffer()}function ss(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);ir(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&ss(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&ss(d,t,e,i,s,n,r)}}const pr=["x","y","z"];function xr(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ns(0,f,e,i,s,n);return k.clearBuffer(),r}function ns(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return sr(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=pr[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ns(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ns(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const oi=new Q,fe=new ft,de=new ft,Pe=new H,$s=new j,ai=new j;function gr(f,t,e,i){k.setBuffer(f._roots[t]);const s=rs(0,f,e,i);return k.clearBuffer(),s}function rs(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),$s.set(e.boundingBox.min,e.boundingBox.max,i),s=$s),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Pe.copy(i).invert(),e.boundsTree)return U(f,n,ai),ai.matrix.copy(Pe),ai.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ai.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,g=z+m;x<g;x++)if(D(de,3*t.resolveTriangleIndex(x),u,l),de.needsUpdate=!0,p.intersectsTriangle(de))return!0;return!1}});{const b=Qe(e);for(let p=m,x=z+m;p<x;p++){const g=t.resolveTriangleIndex(p);D(fe,3*g,u,l),fe.a.applyMatrix4(Pe),fe.b.applyMatrix4(Pe),fe.c.applyMatrix4(Pe),fe.needsUpdate=!0;for(let w=0,B=b*3;w<B;w+=3)if(D(de,w,d,y),de.needsUpdate=!0,fe.intersectsTriangle(de))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,oi),!!(s.intersectsBox(oi)&&rs(h,t,e,i,s)||(U(u,n,oi),s.intersectsBox(oi)&&rs(u,t,e,i,s)))}}const ci=new H,os=new j,Ce=new j,wr=new S,br=new S,zr=new S,_r=new S;function Mr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),os.set(t.boundingBox.min,t.boundingBox.max,e),os.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=wr,m=br,z=null,b=null;s&&(z=zr,b=_r);let p=1/0,x=null,g=null;return ci.copy(e).invert(),Ce.matrix.copy(ci),f.shapecast({boundsTraverseOrder:w=>os.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Ce.min.copy(w.min),Ce.max.copy(w.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree){const _=t.boundsTree;return _.shapecast({boundsTraverseOrder:M=>Ce.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){const T=_.resolveTriangleIndex(A);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+B;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const R=l.distanceToTriangle(d,y,z);if(R<p&&(m.copy(y),b&&b.copy(z),p=R,x=E,g=A),R<n)return!0}}}})}else{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){const T=f.resolveTriangleIndex(A);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,z);if(E<p&&(m.copy(y),b&&b.copy(z),p=E,x=A,g=M),E<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ci),m.applyMatrix4(ci),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function Js(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}const hi=new j,li=new zn,Gs=new S,Qs=new H,js=new S,as=["getX","getY","getZ"];class Ee extends Xn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Ee(e,{...i,[Ui]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new mt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/J;y<m;y++){const z=q*y,b=2*z;N(b,d)||(l[z+6]=l[z+6]/q-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[as[d]](h),m=r[as[d]](u),z=r[as[d]](l);let b=y;m<b&&(b=m),z<b&&(b=z);let p=y;m>p&&(p=m),z>p&&(p=z),e[i+d]=b,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const b=(n?n[y]:y)*3,p=(y-d)*6;let x=b+0,g=b+1,w=b+2;a&&(x=a[x],g=a[g],w=a[w]),o||(x=x*u+h,g=g*u+h,w=w*u+h);for(let B=0;B<3;B++){let _,M,P;o?(_=r[l[B]](x),M=r[l[B]](g),P=r[l[B]](w)):(_=c[x+B],M=c[g+B],P=c[w+B]);let A=_;M<A&&(A=M),P<A&&(A=P);let C=_;M>C&&(C=M),P>C&&(C=P);const T=(C-A)/2,E=B*2;i[p+E+0]=A+T,i[p+E+1]=T+(Math.abs(A)+T)*Ye}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;Qs.copy(t.matrixWorld).invert(),li.copy(e.ray).applyMatrix4(Qs),js.setFromMatrixScale(t.matrixWorld),Gs.copy(li.direction).multiply(js);const n=Gs.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(li,s,r,a);o=Js(o,t,e),o&&i.push(o)}else{const o=this.raycast(li,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Js(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?yr:er)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?mr:rr;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?xr:ar;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?gr:cr;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ot.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?nr:tr});return ot.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ot.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=ot.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Ee))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,z,b,p,x,g,w,B)=>{for(let _=b,M=b+p;_<M;_++){d(_),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,A=m+z;P<A;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,_,x,g,w,B))return!0}return!1};if(s){const m=s;s=function(z,b,p,x,g,w,B,_){return m(z,b,p,x,g,w,B,_)?!0:y(z,b,p,x,g,w,B,_)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return hi.set(t.min,t.max,e),hi.needsUpdate=!0,this.shapecast({intersectsBounds:i=>hi.intersectsBox(i),intersectsTriangle:i=>hi.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Mr:dr)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Jn(this,t,e,i,s)}}const cs=self;cs.addEventListener("message",async({data:f})=>{let t=performance.now();function e(a){const o=performance.now();(o-t>=10||a===1)&&(postMessage({error:void 0,serialized:void 0,position:void 0,progress:a}),t=o)}const{id:i,index:s,position:n,options:r}=f;try{const a=new Ii;if(a.setAttribute("position",new mt(n,3,!1)),s&&a.setIndex(new mt(s,1,!1)),r.includedProgressCallback&&(r.onProgress=e),r.groups){const h=r.groups;for(const u in h){const l=h[u];a.addGroup(l.start,l.count,l.materialIndex)}}const o=new Ee(a,r),c=Ee.serialize(o,{cloneBuffers:!1});cs.postMessage({id:i,error:void 0,serialized:c,position:n,progress:1},[c.index.buffer,n.buffer,...c.roots])}catch(a){cs.postMessage({id:i,error:a,serialized:void 0,position:void 0,progress:1})}})})();
1533
- `,oo=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ol],{type:"text/javascript;charset=utf-8"});function mu(c){let t;try{if(t=oo&&(self.URL||self.webkitURL).createObjectURL(oo),!t)throw"";const e=new Worker(t,{name:c?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(ol),{name:c?.name})}}class ll{constructor(){g(this,"running");g(this,"worker");this.running=!1,this.worker=new mu,this.worker.onerror=t=>{throw t.message?new Error(`[GenerateMeshBVHWorker] Could not create Web Worker with error "${t.message}"`):new Error("[GenerateMeshBVHWorker] Could not create Web Worker.")}}isRunning(){return this.running}generate(t,e={}){if(this.running){P.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){P.warn("[GenerateMeshBVHWorker] Worker has been disposed.");return}const{worker:i}=this;this.running=!0;const s=new Map;t.forEach(r=>{s.set(r.id,r)});let n=0;return new Promise((r,a)=>{const o=()=>{++n===s.size&&(this.running=!1,i.onmessage=null,r())};i.onerror=l=>{P.warn("[GenerateMeshBVHWorker] "+l.message),a(new Error("[GenerateMeshBVHWorker] "+l.message)),this.running=!1},i.onmessage=l=>{this.running=!1;const{data:h}=l;if(h.error)P.warn(h.error),o();else if(h.serialized){const{serialized:d,position:u,id:f}=h,m=s.get(f),b=ps.deserialize(d,m,{setIndex:!1}),y=Object.assign({setBoundingBox:!0},e);if(y.transferred&&(m.attributes.position.array=u),m.index)e.saveOriginalIndex&&!m.userData.originalIndex&&(m.userData.originalIndex=m.index.array),P.debug("before update, index:",m.index.array),m.index.array=d.index;else{const C=new D.BufferAttribute(d.index,1,!1);m.setIndex(C)}m.index&&(P.debug("after update, index:",m.index.array),m.index.needsUpdate=!0),y.setBoundingBox&&!m.boundingBox&&(m.boundingBox=b.getBoundingBox(new D.Box3)),m.boundsTree=b,o()}else e.onProgress&&e.onProgress(h.progress)};for(const[l,h]of s){const d=h.index?h.index.array:void 0,u=h.attributes.position,f=u.array;if(u.isInterleavedBufferAttribute||d&&d.isInterleavedBufferAttribute){P.warn("[GenerateMeshBVHWorker] InterleavedBufferAttribute are not supported for the geometry attributes."),o();continue}const m=[];e.transferred&&(m.push(f),d&&(m.push(d),e.saveOriginalIndex&&(h.userData.originalIndex=d.slice()))),i.postMessage({id:l,index:d,position:f,options:Object.assign(Object.assign({},e),{onProgress:null,includedProgressCallback:!!e.onProgress,groups:[...h.groups]})},m.length>0?m.map(b=>b.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Vr{constructor(t){g(this,"running");g(this,"workers");this.running=!1,this.workers=[];let e=1;t?e=t:window.navigator&&(e=Math.max(e,window.navigator.hardwareConcurrency-1));for(let i=0;i<e;i++)this.workers[i]=new ll}isRunning(){return this.running}async generate(t,e={}){if(this.running){P.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){P.warn("[BVHHelper] Worker has been disposed.");return}return this.running=!0,new Promise(i=>{const s=this.workers.length,n=t.length,r=[],a=Math.floor(n/s),o=n%s;let l=0,h=0;for(let d=0;d<s;d++){const u=this.workers[d];if(d<o?(l=d*a+d,h=l+a+1):(l=d*a+o,h=l+a),l=Math.min(l,n),h=Math.min(h,n),l>=h)break;P.debug("startIndex: "+l+" endIndex: "+h),r.push(u.generate(t.slice(l,h),e))}Promise.allSettled(r).then(()=>{this.running=!1,i()})})}dispose(){for(let t=0;t<this.workers.length;t++)this.workers[t].dispose();this.workers=[]}static createMeshBvhSync(t,e={}){const i=new Set;t.forEach(s=>{s.traverse(n=>{const r=n;if(r.isMesh&&r.geometry&&fe.isMergedMesh(r)&&!(r instanceof p.InstancedMesh)){if(i.has(r.geometry.id))return;r.geometry.index&&e.saveOriginalIndex&&(r.geometry.userData.originalIndex=r.geometry.index.array.slice()),r.geometry.boundsTree=new ps(r.geometry,e),i.add(r.geometry.id)}})})}static createMeshBvhAsync(t,e={}){const i=new Set,s=[];t.forEach(r=>{r.traverse(a=>{const o=a;if(o.isMesh&&o.geometry&&fe.isMergedMesh(o)&&!(o instanceof p.InstancedMesh)){if(i.has(o.geometry.id))return;s.push(o.geometry),i.add(o.geometry.id)}})});const n=new Vr;return n.generate(s,e).then(()=>{n.dispose()})}}class gu{constructor(t,e,i,s,n){g(this,"object");g(this,"camera");g(this,"targetPixelHeight",100);g(this,"canvasHeight",800);this.camera=t,this.object=i,this.targetPixelHeight=s,this.canvasHeight=n,this.adjustSize(),e.addEventListener("update",()=>{this.adjustSize()})}adjustSize(){const t=new p.Box3;if(this.object.updateMatrix(),t.expandByObject(this.object),!t)return;const e=t.max.x-t.min.x,i=this.camera.position.distanceTo(this.object.position),s=yu(e,i,this.canvasHeight);if(Math.abs(s-this.targetPixelHeight)<5)return;let r=this.object.scale.x;r*=this.targetPixelHeight/s,this.object.scale.set(r,r,r),this.object.updateMatrix()}}const yu=(c,t,e=800,i=45)=>{const s=i*(Math.PI/180),n=2*Math.tan(s/2)*t,r=c/n;return e*r},Js=new p.Vector2,Qs=new p.Vector2,en=new p.Vector2,lo=new p.Vector2,xu=new p.Vector2,bu=new p.Vector2,ye=class ye extends Ht{constructor(e){super(j.guid());g(this,"needsFrustumCulled");g(this,"renderOrder");g(this,"snapType");g(this,"osnapInfo");g(this,"drawSnapFunctions");g(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=St.TripleCross,this.snapLineVisible=!1,this.snapType=e,this.drawSnapFunctions={TripleCross:this.drawTripleCorss.bind(this),Square:this.drawSquare.bind(this),Triangle:this.drawTriangle.bind(this),CircleWithCross:this.drawCircleWithCross.bind(this),Cross:this.drawCross.bind(this),Perpendicular:this.drawPerpendicular.bind(this)}}setSnapLineVisible(e){this.snapLineVisible=e}draw(e,i){this.osnapInfo&&(this.snapLineVisible&&this.drawSnapLine(e,i),e.save(),e.fillStyle=ye.FILL_COLOR_NONE,e.strokeStyle=ye.lineColor,e.lineWidth=ye.lineWidth,e.beginPath(),this.drawSnapFunctions[this.snapType](e,i),e.closePath(),e.fill(),e.stroke(),e.restore())}drawDebug(e,i){}drawSelect(e,i){}isPointInPath(e){return!1}drawSnapLine(e,i){e.save(),e.strokeStyle=ye.SNAP_LINE_COLOR,e.lineWidth=ye.lineWidth;const s=this.osnapInfo.line;if(!s)return;const n=this.transToScreenCoord(s.start,i),r=this.transToScreenCoord(s.end,i);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke(),e.restore()}drawTripleCorss(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/1.6,r=Js.set(s.x,s.y-n),a=Qs.set(s.x-.87*n,s.y+n/1.4),o=en.set(s.x+.87*n,s.y+n/1.4);e.moveTo(s.x,s.y),e.lineTo(r.x,r.y),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.moveTo(s.x,s.y),e.lineTo(o.x,o.y)}drawSquare(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize,r=ye.iconSize;e.rect(s.x-n/2,s.y-r/2,n,r)}drawTriangle(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/1.6,r=Js.set(s.x,s.y-n),a=Qs.set(s.x-.87*n,s.y+n/2),o=en.set(s.x+.87*n,s.y+n/2);e.moveTo(r.x,r.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y)}drawCircleWithCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2;e.arc(s.x,s.y,n,0,Math.PI*2),e.moveTo(s.x-n/1.8,s.y),e.lineTo(s.x+n/1.8,s.y),e.moveTo(s.x,s.y-n/1.8),e.lineTo(s.x,s.y+n/1.8)}drawCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2,r=Js.set(s.x-n,s.y-n),a=Qs.set(s.x+n,s.y+n),o=en.set(s.x+n,s.y-n),l=lo.set(s.x-n,s.y+n);e.moveTo(r.x,r.y),e.lineTo(a.x,a.y),e.moveTo(o.x,o.y),e.lineTo(l.x,l.y)}drawPerpendicular(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2,r=Js.set(s.x,s.y),a=Qs.set(s.x-n,s.y),o=en.set(s.x,s.y+n),l=lo.set(s.x-n,s.y-n),h=xu.set(s.x-n,s.y+n),d=bu.set(s.x+n,s.y+n);e.moveTo(a.x,a.y),e.lineTo(r.x,r.y),e.lineTo(o.x,o.y),e.moveTo(l.x,l.y),e.lineTo(h.x,h.y),e.lineTo(d.x,d.y),e.lineTo(l.x,l.y)}update(e){this.osnapInfo=e}getClassType(){return"SnapDrawable"}};g(ye,"lineColor","rgba(255, 119, 0, 1)"),g(ye,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),g(ye,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),g(ye,"lineWidth",2),g(ye,"iconSize",14);let _e=ye;bs._registerDrawableClass(_e);var cl=(c=>(c[c.None=0]="None",c[c.Vertex=1]="Vertex",c[c.MiddlePoint=2]="MiddlePoint",c[c.Edge=4]="Edge",c[c.Face=8]="Face",c[c.FootOfPerpendicular=16]="FootOfPerpendicular",c[c.Intersection=32]="Intersection",c[c.CircleCenter=64]="CircleCenter",c))(cl||{});const wu=1e-5,oe=new p.Vector3,Se=new p.Vector3,Di=new p.Vector3,cs=new p.Vector3,ti=new p.Matrix4,hs=new p.Line3;function vu(c,t){let e=Number.MAX_VALUE,i=0;for(let s=0;s<c.vertices.length;s++){const n=t.distanceTo(c.vertices[s]);n<e&&(i=s,e=n)}return{vertex:c.vertices[i],distance:e}}function Mu(c){if(!(c.object instanceof p.Mesh)||!c.face)return;const t=c.object,e=t.geometry.attributes.position;let i=t.geometry.index;if(e.count<3)return;const s=fe.getBatchByFaceIndex(t,c.faceIndex);t.geometry.boundsTree&&(i=new p.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),ti.identity(),t instanceof p.InstancedMesh&&c.instanceId!==void 0&&t.getMatrixAt(c.instanceId,ti),ti.premultiply(t.matrixWorld);const n=t.geometry.drawRange;let r,a=e.array;if(i){let f=Math.max(0,n.start),m=Math.min(i.count,n.start+n.count);if(r=i.array,s){f=Math.max(f,s.indexStart),m=Math.min(m,s.indexStart+s.indexCount),r=i.array.slice(f,m),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let b=0;b<r.length;b++)r[b]=r[b]-s.positionStart}else(f!==0||m!==i.count)&&(r=i.array.slice(f,m))}else{let f=Math.max(0,n.start),m=Math.min(e.count,n.start+n.count);s?(f=Math.max(f,s.positionStart),m=Math.min(m,s.positionStart+s.positionCount),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3)):(f!==0||m!==e.count)&&(a=e.array.slice(f*3,m*3));const b=a.length/3;r=b>65535?new Uint32Array(b):new Uint16Array(b);for(let y=0,C=b;y<C;y++)r[y]=y}const o=Po.buildEdge(a,r,20);let l=Number.MAX_VALUE,h=0;for(let f=0;f<o.length;f+=2){const m=o[f],b=o[f+1];oe.set(a[m*3],a[m*3+1],a[m*3+2]),oe.applyMatrix4(ti),Se.set(a[b*3],a[b*3+1],a[b*3+2]),Se.applyMatrix4(ti),hs.set(oe,Se),hs.closestPointToPoint(c.point,!0,Di);const y=c.point.distanceTo(Di);y<l&&(h=f,l=y,cs.copy(Di))}const d=o[h],u=o[h+1];return oe.set(a[d*3],a[d*3+1],a[d*3+2]),oe.applyMatrix4(ti),Se.set(a[u*3],a[u*3+1],a[u*3+2]),Se.applyMatrix4(ti),{vertices:[oe.clone(),Se.clone()],vertex:cs.clone(),distance:l}}class Tu{constructor(t){g(this,"drawableList",new ws("snap"));g(this,"overlayRender");g(this,"markers",{});g(this,"activeOSnapType",0);g(this,"snapToleranceInWorldCoord",1);g(this,"intersectionLimit",10);g(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});g(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new _e(St.TripleCross),e=new _e(St.Square),i=new _e(St.Triangle),s=new _e(St.CircleWithCross),n=new _e(St.Cross),r=new _e(St.Perpendicular);this.markers[1]=e,this.markers[2]=i,this.markers[4]=t,this.markers[32]=n,this.markers[64]=s,this.markers[16]=r,Object.values(this.markers).forEach(a=>{a.visible=!1,this.drawableList.addDrawable(a)})}isOSnapTypeEnabled(t){return!!(this.enabledOSnapTypes&t)}setOSnapTypeEnabled(t,e){if(e)this.enabledOSnapTypes|=t;else{const i=~t;this.enabledOSnapTypes&=i}}setSnapTolerance(t){this.snapToleranceInWorldCoord=t}getSnapTolerance(){return this.snapToleranceInWorldCoord}setIntersectionLimit(t){this.intersectionLimit=t}getIntersectionLimit(){return this.intersectionLimit}getMarkerLineColor(){return Li.colorStr2Rgba(_e.lineColor)}setMarkerLineColor(t){_e.lineColor=Li.rgba2Color(t)}getMarkerLineWidth(){return _e.lineWidth}setMarkerLineWidth(t){_e.lineWidth=t}getMarkerIconSize(){return _e.iconSize}setMarkerIconSize(t){_e.iconSize=t}getMarker(t){return this.markers[t]}setAllSnapLinesVisible(t){Object.values(this.markers).forEach(e=>{e.setSnapLineVisible(t)})}deactivate(){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1,this.overlayRender?.render()),this.activeOSnapType=0}destroy(){}handleSnap(t,e,i){if(!t||t.length<1){this.deactivate();return}P.debug("[OSnap] intersections before handleSnap:",t);const s=[];let n=!1,r;for(const o of t)o.object instanceof p.Mesh?(!r&&(r=o.point),!n&&o.object.name!=="groundPlane"&&(s.push(o),n=!0)):s.push(o);if(!e&&r){r.setZ(0);for(const l of s)l.point.z=0,l.distance=l.point.distanceTo(r);const o=l=>l instanceof p.Points?0:l instanceof p.LineSegments?2:l instanceof p.Line?1:3;s.sort((l,h)=>{const d=o(l.object),u=o(h.object);return d!==u?d-u:l.distance-h.distance})}return r||(P.warn("[OSnap] Potential to produce erroneous snap results"),r=s[0].point),P.debug("[OSnap] intersections:",s),P.debug("[OSnap] mousePosition:",r),this.getSnapPointAndUpdateMarker(r,s,e,i)?.clone()||r}getSnapPointAndUpdateMarker(t,e,i,s){if(!e.length){this.activateMarker(0);return}const n=this.getSnapInfo(t,e,i,s);if(!n||n.type===0){this.activateMarker(0);return}return this.activateMarker(n.type,n),n.point}activateMarker(t,e){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1),this.activeOSnapType=t;const i=this.markers[t];i&&e&&(i.update(e),i.visible=!0),this.overlayRender?.render()}getFootOfPerpendicular(t,e,i=wu){const{start:s,end:n}=e,r=s.x-n.x,a=s.y-n.y,o=s.z-n.z;if(s.distanceTo(n)<i)return s.clone();let l=(t.x-s.x)*(s.x-n.x)+(t.y-s.y)*(s.y-n.y)+(t.z-s.z)*(s.z-n.z);return l=l/(r*r+a*a+o*o),new p.Vector3(s.x+l*r,s.y+l*a,s.z+l*o)}getSnapInfo(t,e,i,s){const n=this.snapToleranceInWorldCoord*2;P.debug("[OSnap] snap radius:",n);const r=[],a={line:void 0};let o=this.osnapTypePriorities[0];for(let l=0;l<e.length&&l<this.intersectionLimit;++l){const h=e[l],d=h.object;let u;d instanceof p.Mesh?u=this.getOsnapInfoListFromMesh(t,h,n,o):d instanceof p.Line?u=this.getOsnapInfoListFromLine(t,h,i,n,a,o,s):d instanceof p.Points&&(u=this.getOsnapInfoListFromPoint(t,h,i,n,o)),u&&(o=this.osnapTypePriorities[u.type],r.push(u))}if(r.length!==0)return r.sort((l,h)=>{const d=this.osnapTypePriorities[l.type],u=this.osnapTypePriorities[h.type];return d!==u?d-u:l.distance-h.distance}),r[0]}getOsnapInfoListFromMesh(t,e,i,s){if(s<this.osnapTypePriorities[1])return;const n=Date.now(),r=Mu(e);if(!r){P.warn("[OSnap] Failed to get edge !");return}const a=Date.now();P.debug("[OSnap] getEdgeSnappingInfo took "+(a-n)/1e3+"s "),P.debug("[OSnap] edge:",r);const o=vu(r,t);if(P.debug("[OSnap] vertex:",o),o.distance<=i&&this.isOSnapTypeEnabled(1))return{distance:o.distance,type:1,point:o.vertex};if(r.distance<=i){if(this.isOSnapTypeEnabled(2)&&s<this.osnapTypePriorities[2])return;oe.copy(r.vertices[0]),oe.add(r.vertices[1]),oe.divideScalar(2);const l=oe.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:oe.clone()}:!this.isOSnapTypeEnabled(4)||s<this.osnapTypePriorities[4]?void 0:{distance:r.distance,type:4,point:r.vertex,line:{start:r.vertices[0],end:r.vertices[1]}}}else P.debug("[OSnap] Face")}getOsnapInfoFromSegment(t,e,i,s,n,r,a){const o={start:e,end:i};if(a&&r>=this.osnapTypePriorities[16]&&this.isOSnapTypeEnabled(16)){const f=this.getFootOfPerpendicular(a,o,s),m=t.distanceTo(f);if(m<=s)return{distance:z.floorNumber(m,7),type:16,point:f.clone()}}if(r<this.osnapTypePriorities[1])return;hs.set(e,i),hs.closestPointToPoint(t,!0,Di);const l=t.distanceTo(Di);if(l>s)return;const h=t.distanceTo(e),d=t.distanceTo(i);if(Math.min(h,d)<=s&&this.isOSnapTypeEnabled(1)){let f=h,m=e;return d<h&&(f=d,m=i),{distance:z.floorNumber(f,7),type:1,point:m.clone()}}if(r<this.osnapTypePriorities[2])return;hs.getCenter(cs);const u=t.distanceTo(cs);if(u<s&&this.isOSnapTypeEnabled(2))return{point:cs.clone(),distance:z.floorNumber(u,7),type:2};if(!(r<this.osnapTypePriorities[4])){if(n.line&&this.isOSnapTypeEnabled(32)){const f=N.getLineSegmentsIntersectingPoint(n.line,o);if(!f)return;const m=t.distanceTo(f)/2;return m<s?(n.line=void 0,{point:f.clone(),distance:z.floorNumber(m,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return n.line={start:e.clone(),end:i.clone()},{point:Di.clone(),distance:z.floorNumber(l,7),type:4,line:{start:e.clone(),end:i.clone()}}}}getOsnapInfoListFromLine(t,e,i,s,n,r,a){const o=[],l=e.object,h=l instanceof p.LineSegments?2:1,d=l.geometry.index,u=l.geometry.attributes.position,f=l.geometry.drawRange,m=fe.getBatchByLineIndex(l,e.index);if(d){let b=Math.max(0,f.start),y=Math.min(d.count,f.start+f.count);m&&(b=Math.max(b,m.indexStart),y=Math.min(y,m.indexStart+m.indexCount));for(let C=b,w=y;C<w-1;C+=h){const x=d.getX(C),E=d.getX(C+1);oe.fromBufferAttribute(u,x),Se.fromBufferAttribute(u,E),oe.applyMatrix4(l.matrixWorld),Se.applyMatrix4(l.matrixWorld),!i&&(oe.setZ(0),Se.setZ(0));const M=this.getOsnapInfoFromSegment(t,oe,Se,s,n,r,a);M&&(r=this.osnapTypePriorities[M.type],o.push(M))}}else{let b=Math.max(0,f.start),y=Math.min(u.count,f.start+f.count);m&&(b=Math.max(b,m.positionStart),y=Math.min(y,m.positionStart+m.positionCount));for(let C=b,w=y;C<w-1;C+=h){oe.fromBufferAttribute(u,C),Se.fromBufferAttribute(u,C+1),oe.applyMatrix4(l.matrixWorld),Se.applyMatrix4(l.matrixWorld),!i&&(oe.setZ(0),Se.setZ(0));const x=this.getOsnapInfoFromSegment(t,oe,Se,s,n,r,a);x&&(r=this.osnapTypePriorities[x.type],o.push(x))}}if(o.length!==0)return o.sort((b,y)=>{const C=this.osnapTypePriorities[b.type],w=this.osnapTypePriorities[y.type];return C!==w?C-w:b.distance-y.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,n){if(n<this.osnapTypePriorities[1])return;const r=e.object,a=r.geometry.getAttribute("position");oe.fromBufferAttribute(a,e.index),oe.applyMatrix4(r.matrixWorld),Se.copy(t),!i&&(oe.setZ(0),Se.setZ(0));const o=Se.distanceTo(oe);if(o>s)return;const l={distance:o,point:oe.clone(),type:1};if(r.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(P.debug("[OSnap] Other types of vertices !"),!this.isOSnapTypeEnabled(1))return;return l}getIntersectsIncludeOutline(t,e){const i=t.slice(),s=[];for(let r=0;r<t.length&&r<this.intersectionLimit;r++){const a=t[r].object;if(a.updateWorldMatrix(!0,!1),a instanceof p.Mesh&&!J.hasOutline(a,!1)){const o=J.createOutline(a.geometry);o.visible=!1,a.add(o),o.updateWorldMatrix(!0,!1),s.push(o)}}let n=[];return s.length>0&&(n=e.intersectObjects(s)||[],P.debug("[OSnap] Intersected with newly created edges: ",n),n.length>0&&i.push(...n)),i.sort((r,a)=>r.distance-a.distance),i}}class hl{constructor(t,e,i){g(this,"node");g(this,"parentNode");g(this,"target");g(this,"childNode");g(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});g(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));g(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));g(this,"destroy",()=>{this.target?this.target.removeEventListener("mousemove",this.follow):document.removeEventListener("mousemove",this.follow),this.parentNode.removeChild(this.node)});this.node=document.createElement("div"),this.node.id=t,e&&this.node.append(e),this.childNode=document.createElement("div"),this.target=i?.target,this.parentNode=i?.parentNode||document.body,i?.followPointer&&(this.node.classList.add("follow-tooltip"),this.target?this.target.addEventListener("mousemove",this.follow):document.addEventListener("mousemove",this.follow)),this.parentNode.appendChild(this.node),!i?.showOnCreate&&this.node.setAttribute("hidden","")}setContent(t){this.node.textContent&&(this.node.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.node.append(t),this.node.appendChild(this.childNode)}updateChildContent(t){this.childNode.textContent&&(this.childNode.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.childNode.append(t)}}class Cu{constructor(t){g(this,"viewer");g(this,"active",!1);g(this,"tooltip");g(this,"resolve");g(this,"reject");g(this,"isResolvedOrRejected",!1);g(this,"mouseClicked",t=>{const e=t;if(e.markupData){const i=e.markupData.id,s=this.viewer.getOverlayRender().getDrawableById(i);if(s){let n=s.getBounds();n=n.clone().expandByScalar(20*this.viewer.getPixelSizeInWorldCoord());const r=Ee.world2NormalizedScreen(n.min,this.camera,this.viewerContainer),a=Ee.world2NormalizedScreen(n.max,this.camera,this.viewerContainer),o=new p.Box2(new p.Vector2(Math.min(r.x,a.x),Math.min(r.y,a.y)),new p.Vector2(Math.max(r.x,a.x),Math.max(r.y,a.y)));o.min.x=Math.max(o.min.x,0)*this.viewerContainer.clientWidth,o.min.y=Math.max(o.min.y,0)*this.viewerContainer.clientHeight,o.max.x=Math.min(o.max.x,1)*this.viewerContainer.clientWidth,o.max.y=Math.min(o.max.y,1)*this.viewerContainer.clientHeight,this.resolve&&(this.resolve(o),this.isResolvedOrRejected=!0),this.deactivate();const l=this.viewer;typeof l.clearSelection=="function"&&l.clearSelection()}}});g(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("PickMarkupHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.viewer.addEventListener(le.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new hl("pick-markup-tooltip",Qe.t("Tooltip.pickMarkup"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("pick-markup-tooltip");t&&(t.style.pointerEvents="none");const e=Qe.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(le.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(le.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(le.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Bi=class Bi{constructor(t){g(this,"viewer");g(this,"input");g(this,"mouseDown",!1);g(this,"mouseMove",!1);g(this,"mouseDownPositionX",-1);g(this,"mouseDownPositionY",-1);g(this,"tempKey");g(this,"tempTouch");g(this,"tempEnableRotate",!1);g(this,"rectDom");g(this,"tooltip");g(this,"active",!1);g(this,"resolve");g(this,"reject");g(this,"isResolvedOrRejected",!1);g(this,"mousedown",t=>{if(t.button===0){this.mouseDown=!0;const e=new p.Vector2(t.x,t.y);this.mouseDownPositionX=e.x,this.mouseDownPositionY=e.y,this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0}});g(this,"mousemove",t=>{if(!this.mouseDown)return;const e=new p.Vector2(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(e.x-this.mouseDownPositionX)>=5||Math.abs(e.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const s=new p.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),n=new p.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y));this.drawRect(s,n)}});g(this,"mouseup",t=>{if(this.mouseDown&&this.mouseMove){const e=new p.Vector2(t.x,t.y),i=new p.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),s=new p.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y)),n=new p.Box2(i,s);this.resolve&&(this.resolve(n),this.isResolvedOrRejected=!0),this.deactivate(),this.setRectDomVisible(!1)}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1});g(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t,this.input=t.getInputManager()}get viewerContainer(){return this.viewer.viewerContainer}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("BoxSelectHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.input.addEventListener("pointerdown",this.mousedown),this.input.addEventListener("pointermove",this.mousemove),this.input.addEventListener("pointerup",this.mouseup),this.input.addEventListener("keydown",this.keydown),this.viewer.getCameraManager().enableMouseLeft(!1),this.tooltip=new hl("box-select-tooltip",Qe.t("Tooltip.boxSelect"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("box-select-tooltip");t&&(t.style.pointerEvents="none");const e=Qe.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(le.BoxSelectActivate)}deactivate(){this.active=!1,this.input.removeEventListener("pointerdown",this.mousedown),this.input.removeEventListener("pointermove",this.mousemove),this.input.removeEventListener("pointerup",this.mouseup),this.input.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.getCameraManager().enableMouseLeft(!0),this.viewer.dispatchEvent(le.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Bi.BORDER_WIDTH} solid ${Bi.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};g(Bi,"BORDER_COLOR","#fff000"),g(Bi,"BORDER_WIDTH","2px");let xn=Bi;class dl{constructor(t){g(this,"viewer");g(this,"boxSelectHelper");g(this,"active",!1);this.viewer=t,this.boxSelectHelper=new xn(t)}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}isActive(){return this.active}activate(){this.active=!0,this.boxSelectHelper?.select().then(t=>{t&&this.handleZoomToRect(t.min,t.max)})}deactivate(){this.active=!1,this.boxSelectHelper?.deactivate()}pickPositionByScreenPoint(t){return this.viewer.pickObject(t)?.point}handleZoomToRect(t,e){const i=this.pickPositionByScreenPoint(t),s=this.pickPositionByScreenPoint(e);if(i&&s){const n=new p.Vector3(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),r=new p.Vector3(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),a=new p.Box3(n,r);this.viewer.zoomToBBox(a)}}destroy(){this.boxSelectHelper?.destroy(),this.boxSelectHelper=void 0}}function co(c){return c?c.replace(/%%[dD]/g,"°").replace(/%%[cC]/g,"⌀").replace(/%%[pP]/g,"±").replace(/%%(U|O)/gi,"").replace(/\\P/g," ").replace(/\\[A-Za-z][^;\\]*;/g,"").replace(/[{}]/g,"").replace(/\\\\/g,"\\").replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))).trim():""}const tn=new p.Box3,Su=new p.Vector3;function Eu(c,t){return c.trim().toLowerCase()===t?2e6:0}function Ou(c,t){const e=c.toLowerCase(),i=e.indexOf(t);if(i>=0)return(e===t?2e6:1e6)+(1e3-i)-Math.min(e.length,500);let s=0,n=-1,r=-1,a=0;for(let l=0;l<t.length;l++){const h=t[l];let d=-1;for(;s<e.length;s++)if(e[s]===h){d=s;break}if(d<0)return 0;n<0?n=d:r>=0&&d-r>1&&(a+=d-r-1),r=d,s=d+1}const o=5e5-a*50-n*5-Math.min(e.length,500);return o>0?o:1}class Tr{constructor(t){g(this,"viewer");g(this,"overlayRender");g(this,"drawableList");g(this,"indexedModelObject");g(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}buildIndex(){const t=this.getMasterModel();if(!t){this.index=[],this.indexedModelObject=void 0;return}const e=t.getModelObject();if(e===this.indexedModelObject&&this.index.length>0)return;this.indexedModelObject=e,this.index=[];const i=new p.Matrix4,s=new p.Vector3,n=new Map;e.updateWorldMatrix(!0,!0);const r=(a,o,l,h,d)=>{if(a&&n.has(a)){n.get(a).box.union(d);return}n.set(a||o+h,{text:o,layer:l,layoutName:h,box:d.clone()})};e.traverse(a=>{const o=a.userData;if(o){if(typeof o.textContent=="string"&&o.textContent.length){const l=co(o.textContent);if(!l||(tn.makeEmpty(),tn.setFromObject(a),tn.isEmpty()))return;r(o.handle||"",l,o.layer||"0",this.findLayoutName(a),tn);return}if(Array.isArray(o.batches)){const l=a.geometry?.getAttribute?.("position");if(!l)return;i.copy(a.matrixWorld);for(const h of o.batches){const d=h?.userData?.textContent;if(typeof d!="string"||!d.length)continue;const u=co(d);if(!u)continue;const f=new p.Box3,m=h.positionStart||0,b=h.positionCount||0;for(let y=m;y<m+b;y++)s.fromBufferAttribute(l,y).applyMatrix4(i),f.expandByPoint(s);f.isEmpty()||r(h.userData.handle||"",u,h.userData.layer||"0",this.findLayoutName(a),f)}}}}),n.forEach((a,o)=>{this.index.push({handle:o,layer:a.layer,layoutName:a.layoutName,text:a.text,box:a.box})})}findLayoutName(t){let e=t;for(;e;){if(e.userData?.isLayoutLevelObject===!0)return e.name||"Model";e=e.parent}return"Model"}search(t,e){const i=(t||"").trim().toLowerCase();if(!i)return[];this.buildIndex();const s=e?.mode??"fuzzy",n=e?.layer?.trim().toLowerCase(),r=e?.maxResults??200,a=[];for(const o of this.index){if(n&&o.layer.toLowerCase()!==n)continue;const l=s==="exact"?Eu(o.text,i):Ou(o.text,i);l>0&&a.push({item:o,score:l})}return a.sort((o,l)=>l.score-o.score),a.slice(0,r).map(o=>o.item)}focus(t){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const e=t.box.clone();this.viewer.zoomToBBox(e.expandByScalar(Math.max(e.getSize(Su).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new ws("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new bt(j.guid(),[t.box.clone()],[1,.55,0,1],[1,.55,0,.15])),this.viewer.enableRender())}clearHighlight(){this.drawableList?.clear(),this.viewer.enableRender()}invalidate(){this.indexedModelObject=void 0,this.index=[]}destroy(){this.clearHighlight(),this.overlayRender=void 0,this.drawableList=void 0,this.index=[],this.indexedModelObject=void 0}}class _u extends Ht{constructor(e){super("MobileHelper");g(this,"position");g(this,"needsFrustumCulled");g(this,"renderOrder");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.position=e}setPosition(e){this.position=e}isPointInPath(e,i){return!1}draw(e,i){this.drawInnerCircle(e),this.drawOuterRing(e),this.drawSnapTriangle(e)}drawInnerCircle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(137, 137, 138, 0.8)",e.beginPath(),e.arc(i,s,25,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}drawOuterRing(e){const{x:i,y:s}=this.position;e.save(),e.strokeStyle="rgba(17, 17, 19, 0.8)",e.lineWidth=10,e.beginPath(),e.arc(i,s,30,0,Math.PI*2),e.closePath(),e.stroke(),e.restore(),e.save(),e.strokeStyle="rgba(173, 173, 174, 0.8)",e.lineWidth=3,e.beginPath(),e.arc(i,s,35,0,Math.PI*2),e.closePath(),e.stroke(),e.restore()}drawSnapTriangle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(17, 17, 19, 0.8)",e.strokeStyle="rgba(137, 137, 138, 0.8)",e.lineWidth=2,e.beginPath(),e.moveTo(i-35,s-35),e.lineTo(i-35+12,s-35),e.lineTo(i-35,s-35+12),e.closePath(),e.fill(),e.stroke(),e.restore()}translate(e,i){this.position.add(new p.Vector2(e,i))}getTouchPoint(){return{x:this.position.x-35,y:this.position.y-35}}isIntersect(e){return this.position.x-35<e.x&&this.position.y-35<e.y&&this.position.x+35>e.x&&this.position.y+35>e.y}drawSelect(e,i){}getClassType(){return"MobileTouchHelperDrawable"}}var $e=(c=>(c[c.Left=0]="Left",c[c.Middle=1]="Middle",c[c.Right=2]="Right",c[c.Back=3]="Back",c[c.Forward=4]="Forward",c))($e||{});class ul extends Nt{constructor(e){super();g(this,"element");g(this,"enabled");g(this,"keyboardEnabled");g(this,"mouseDownPositionX");g(this,"mouseDownPositionY");g(this,"lastLeftPointerUpTime");g(this,"pointers");g(this,"handleClick");g(this,"handlePointerDown");g(this,"handlePointerMove");g(this,"handlePointerUp");g(this,"handlePointerCancel");g(this,"handleMouseWheel");g(this,"handleContextMenu");g(this,"handlePointerEnter");g(this,"handlePointerLeave");g(this,"handleResize");g(this,"handleKeydown");g(this,"handleKeyup");g(this,"style");this.enabled=!0,this.keyboardEnabled=!0,this.mouseDownPositionX=0,this.mouseDownPositionY=0,this.lastLeftPointerUpTime=0,this.pointers=[],this.handleClick=i=>{if(!this.enabled)return;const s=this.getBaseEvent(i);this.dispatchEvent("click",s)},this.handlePointerDown=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isDoubleClick(s)?(this.lastLeftPointerUpTime=0,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.dispatchEvent("dblclick",s)):(this.mouseDownPositionX=s.x,this.mouseDownPositionY=s.y),this.dispatchEvent("pointerdown",s),i.pointerType==="touch"?(this.pointers.push(s),s.pointers=this.pointers,this.dispatchEvent("touchstart",s)):this.dispatchEvent("mousedown",s)},this.handlePointerMove=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isCloseToLastPosition(s)||(this.dispatchEvent("pointermove",s),i.pointerType==="touch"?(this.updatePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchmove",s)):this.dispatchEvent("mousemove",s))},this.handlePointerUp=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);s.button===0&&(this.lastLeftPointerUpTime=s.timestamp),this.dispatchEvent("pointerup",s),i.pointerType==="touch"?(this.removePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchend",s)):this.dispatchEvent("mouseup",s)},this.handlePointerCancel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointercancel",this.getBaseEvent(i)))},this.handleMouseWheel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("wheel",this.getBaseEvent(i)))},this.handleContextMenu=i=>{if(this.enabled)return this.stop(i),this.dispatchEvent("contextmenu",this.getBaseEvent(i)),!1},this.handlePointerEnter=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerenter",this.getBaseEvent(i)))},this.handlePointerLeave=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerleave",this.getBaseEvent(i)))},this.handleResize=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("resize",this.getBaseEvent(i)))},this.handleKeydown=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keydown",this.getBaseEvent(i))},this.handleKeyup=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keyup",this.getBaseEvent(i))},this.style={},this.element=e,this.bindEvents()}getEnabled(){return this.enabled}setEnabled(e){this.enabled=e}getkKeyboardEnabled(){return this.keyboardEnabled}setkKeyboardEnabled(e){this.keyboardEnabled=e}setCursor(e){this.element.style&&(this.element.style.cursor=e||"default")}bindEvents(){this.element.style.touchAction="none",this.element.style.userSelect="none",this.element.style.webkitUserSelect="none",this.element.addEventListener("click",this.handleClick),this.element.addEventListener("pointerdown",this.handlePointerDown),this.element.addEventListener("pointermove",this.handlePointerMove),this.element.addEventListener("pointerup",this.handlePointerUp),this.element.addEventListener("pointercancel",this.handlePointerCancel),this.element.addEventListener("pointerenter",this.handlePointerEnter),this.element.addEventListener("pointerleave",this.handlePointerLeave),this.element.addEventListener("contextmenu",this.handleContextMenu),this.element.addEventListener("wheel",this.handleMouseWheel,{passive:!1}),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),window.addEventListener("keyup",this.handleKeyup)}unBindEvents(){this.element.removeEventListener("pointerdown",this.handlePointerDown),this.element.removeEventListener("pointermove",this.handlePointerMove),this.element.removeEventListener("pointerup",this.handlePointerUp),this.element.removeEventListener("pointerenter",this.handlePointerEnter),this.element.removeEventListener("pointerleave",this.handlePointerLeave),this.element.removeEventListener("contextmenu",this.handleContextMenu),this.element.removeEventListener("wheel",this.handleMouseWheel),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),window.removeEventListener("keyup",this.handleKeyup),this.element.style.touchAction="",this.element.style.userSelect="",this.element.style.webkitUserSelect=""}getBaseEvent(e){const i=e,s={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,deltaX:0,deltaY:0,movementX:0,movementY:0,deltaMode:0,pointerId:0,timestamp:0,buttons:0,pointerType:"mouse",altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,originalEvent:i};if(s.timestamp=i.timeStamp,sn(i,"clientX"))if(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.clientX=i.clientX,s.clientY=i.clientY,s.button=i.button,sn(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const n=Ee.getScreenCoordinateByEvent(i,this.element);s.x=n.x,s.y=n.y,s.movementX=i.movementX,s.movementY=i.movementY}else sn(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else sn(i,"code")&&(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.metaKey=i.metaKey,s.code=i.code);return s}stop(e){e.preventDefault()}updatePointers(e){for(let i=0;i<this.pointers.length;i++)if(e.pointerId==this.pointers[i].pointerId){this.pointers[i]=e;break}}removePointers(e){for(let i=0;i<this.pointers.length;i++)if(this.pointers[i].pointerId==e.pointerId){this.pointers.splice(i,1);break}}getBoundingClientRect(){return this.element.getBoundingClientRect()}isCloseToLastPosition(e){return this.mouseDownPositionX===-1||this.mouseDownPositionY===-1?!1:Math.abs(e.x-this.mouseDownPositionX)<5&&Math.abs(e.y-this.mouseDownPositionY)<5}isDoubleClick(e){const s=e.timestamp-this.lastLeftPointerUpTime;return!!(e.button===0&&s<300&&this.isCloseToLastPosition(e))}}function sn(c,t){return c[t]!==void 0}class Pu{constructor(t){g(this,"CLEAR_COLOR");g(this,"CLEAR_COLOR_ALPHA");g(this,"EMPTY_MODEL_ID");g(this,"viewer");g(this,"raycaster");g(this,"pickingTexture");this.CLEAR_COLOR=new p.Color().setRGB(1,1,1),this.CLEAR_COLOR_ALPHA=1,this.EMPTY_MODEL_ID=255,this.viewer=t,this.raycaster=new p.Raycaster,this.pickingTexture=new p.WebGLRenderTarget(1,1)}get scene(){return this.viewer.scene}get camera(){return this.viewer.camera}get renderer(){return this.viewer.renderer}get overlayRender(){return this.viewer.getOverlayRender()}get viewerContainer(){return this.viewer.viewerContainer}getRaycaster(){return this.raycaster}pickObjectsByNdc(t,e,i){return!e||e.length===0?[]:(this.raycaster.setFromCamera(t,this.camera),this.setLayerChannels(i),this.raycaster.intersectObjects(e,!0)||[])}pickObject(t,e,i,s){const n=this.pickObjects(t,e,i,s);if(n.length!==0)return n[0]}pickObjects(t,e,i,s=0){const n=Ee.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const r=[],a=new Map,o=Ee.screen2Ndc(t,this.camera,this.viewerContainer),l=Ee.screen2Ndc({x:t.x+s,y:t.y},this.camera,this.viewerContainer),h=new p.Vector3(o.x,o.y,0).unproject(this.camera),d=new p.Vector3(l.x,l.y,0).unproject(this.camera),u=h.distanceTo(d),f=this.raycaster.params.Line.threshold;this.raycaster.params.Line.threshold=u,this.setLayerChannels(i);const m=8;for(let y=0;y<m;y++){const C=y/m*Math.PI*2,w=Math.cos(C)*s,x=Math.sin(C)*s,E={x:t.x+w,y:t.y+x},M=Ee.screen2Ndc(E,this.camera,this.viewerContainer);this.raycaster.setFromCamera(M,this.camera),this.raycaster.layers.enableAll();const O=this.raycaster.intersectObjects(e,!0)||[];for(const S of O)S.object&&!a.has(S.object.uuid)&&(a.set(S.object.uuid,S),r.push(S))}this.raycaster.setFromCamera(o,this.camera);const b=this.raycaster.intersectObjects(e,!0)||[];for(const y of b)y.object&&!a.has(y.object.uuid)&&(a.set(y.object.uuid,y),r.push(y));if(this.raycaster.params.Line.threshold=f,r.length>1){const y=this.raycaster.ray.origin.clone();r.sort((C,w)=>{const x=C.point||C.object.getWorldPosition(new p.Vector3),E=w.point||w.object.getWorldPosition(new p.Vector3);return x.distanceTo(y)-E.distanceTo(y)})}return r}return this.pickObjectsByNdc(n,e,i)}pickDrawable(t){return this.overlayRender.getDrawablesByPosition(t)}pick(t,e){const i=this.pickBuffer(t,e),s=[i[0],i[1],i[2],i[3]],n=Z1(s),r=K1(s);if(n!==this.EMPTY_MODEL_ID)return P.info("[PickMgr] Picked: tilesetId("+n+"), userId("+r+")"),{tilesetId:n,userId:r}}setLayerChannels(t){t&&t.length>0?(this.raycaster.layers.disableAll(),t.forEach(e=>{this.raycaster.layers.enable(e)})):this.raycaster.layers.enableAll()}pickBuffer(t,e,i=1,s=1){const{pickingTexture:n,renderer:r,camera:a}=this;n.setSize(i,s);const o=r.getPixelRatio(),l=r.getContext().drawingBufferWidth,h=r.getContext().drawingBufferHeight,d=t.x*o|0,u=t.y*o|0;a.setViewOffset(l,h,d,u,i,s),r.setRenderTarget(n);const f=new p.Color;r.getClearColor(f);const m=r.getClearAlpha();r.setClearColor(this.CLEAR_COLOR,this.CLEAR_COLOR_ALPHA),r.render(e,a);const b=new Uint8Array(4*i*s);return r.readRenderTargetPixels(n,0,0,i,s,b),r.setRenderTarget(null),a.clearViewOffset(),r.setClearColor(f,m),b}}const ho=new p.Vector3;class Au{constructor(t){g(this,"viewer");g(this,"scene");g(this,"renderer");g(this,"pmremGenerator");g(this,"lights");g(this,"modelGroup");this.viewer=t;const e=new p.Scene;e.matrixAutoUpdate=ct,e.matrixWorldAutoUpdate=ct,this.scene=e,this.modelGroup=new p.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:n}=t.container,r=new p.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0});r.setPixelRatio(window.devicePixelRatio),r.setSize(i,s),r.outputColorSpace=p.SRGBColorSpace,r.toneMappingExposure=1,r.localClippingEnabled=!0,r.shadowMap.enabled=!1,r.shadowMap.type=p.PCFSoftShadowMap,r.shadowMap.autoUpdate=!1,r.domElement.style.outlineWidth="0",n?.appendChild(r.domElement),this.renderer=r,j.printGpuInfo(r.getContext())}initLights(){const t=new p.Group;t.name="lights";const e=1.5,i=16777215,s=new p.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const n=new p.AmbientLight(i);n.name="ambient";const r=new p.HemisphereLight(i,14540253,.2);r.name="hemisphere",r.position.set(0,300,0);const a=new p.Group;a.name="lightHelpers",a.visible=!1;const o=new p.DirectionalLightHelper(s),l=new p.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(n),t.add(r),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new p.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}enableShadow(t){this.renderer.shadowMap.enabled=t,this.directionalLight.castShadow=t,t&&(this.tryAdjustDirectionalLight(),this.updateDirectionalLightShadow()),this.modelGroup.traverse(e=>{e.isMesh&&(e.castShadow=t,e.receiveShadow=t)})}enableClipping(t){this.renderer.localClippingEnabled=t}setClipPlanes(t){this.renderer.clippingPlanes=t}enableLights(t){let e=this.lights;e||(e=this.initLights()),e.visible=t}debugLights(t){!this.lights||!this.lightHelpers||(this.lightHelpers.visible=t)}setBackground(t){this.scene.background=t}get directionalLight(){return this.lights?.getObjectByName("sun")}get ambientLight(){return this.lights?.getObjectByName("ambient")}get hemisphereLight(){return this.lights?.getObjectByName("hemisphere")}get lightHelpers(){return this.lights?.getObjectByName("lightHelpers")}get directionalLightHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];if(i instanceof p.DirectionalLightHelper){t=i;break}}return t}get cameraHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];i instanceof p.CameraHelper&&(t=i)}return t}async setEnvironmentFromData(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ms.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ms.createEnvTexture(this.pmremGenerator,t);this.scene.environment?.dispose(),this.scene.environment=e}resize(){const{width:t,height:e}=this.viewer.container;this.renderer.setSize(t,e)}getRaycastableObjects(){const t=[];return this.modelGroup.traverse(e=>{t.push(e)}),t}tryAdjustDirectionalLight(){const t=this.directionalLight;if(!t)return;const e=this.viewer.getBBox(),i=new p.Sphere;e.getBoundingSphere(i);const s=i.center,n=i.radius,r=t.shadow.camera;r.zoom=1,r.top=n,r.bottom=-n,r.right=n,r.left=-n,r.near=.1,r.far=2*n,r.updateProjectionMatrix();const a=new p.Vector3(-1,-.5,1);a.normalize().multiplyScalar(n),t.position.copy(s).addScaledVector(a,-1),t.target.position.copy(s),P.debug("[Scene] directionalLight.position",t.position),P.debug("[Scene] directionalLight.target.position",t.target.position),this.updateDirectionalLight(),this.viewer.enableRender()}updateDirectionalLight(){const t=this.directionalLight;if(t&&(t.updateMatrixWorld(),t.target.updateMatrixWorld(),this.directionalLightHelper&&(this.directionalLightHelper.update(),this.scene?.matrixAutoUpdate||this.directionalLightHelper.updateWorldMatrix(!1,!0)),t.shadow.needsUpdate=!0,t.shadow.camera.updateProjectionMatrix(),this.cameraHelper&&(this.cameraHelper.update(),!this.scene?.matrixAutoUpdate))){const e=t.shadow.camera;e.position.setFromMatrixPosition(t.matrixWorld),ho.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(ho),e.updateMatrixWorld(),this.cameraHelper.updateWorldMatrix(!1,!0)}}updateDirectionalLightShadow(){this.directionalLight&&(this.directionalLight.shadow.needsUpdate=!0)}showDirectionalLightHelper(t){this.directionalLightHelper&&(this.directionalLightHelper.visible=t),this.cameraHelper&&(this.cameraHelper.visible=t)}destroy(){this.lightHelpers?.clear(),this.lightHelpers?.removeFromParent(),this.lightHelpers?.traverse(t=>{t.dispose?.call(t)}),this.lights?.clear(),this.lights?.removeFromParent(),this.lights?.traverse(t=>{t.dispose?.call(t)}),this.lights=void 0,this.pmremGenerator?.dispose(),this.renderer.domElement.remove(),this.renderer.clear(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.scene.clear()}}class Iu{constructor(t){g(this,"history");g(this,"step");g(this,"maxCount");g(this,"isBatchCommand");g(this,"batchCommands");this.history=[],this.step=0,this.maxCount=50,this.isBatchCommand=!1,this.batchCommands=[],this.maxCount=t||this.maxCount}addCommand(t){this.isBatchCommand?this.batchCommands.push(t):(this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.history.push(t),this.step++)}startTransaction(){this.isBatchCommand=!0}endTransaction(){this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.batchCommands.length>0&&(this.history.push(this.batchCommands.slice()),this.step++),this.isBatchCommand=!1,this.batchCommands=[]}undo(){if(this.canUndo())return!1;this.step--;const t=this.history[this.step];return t&&(Array.isArray(t)?t.forEach(e=>e.undo()):t.undo()),!0}redo(){if(this.canRedo())return!1;this.step++;const t=this.history[this.step-1];return t&&(Array.isArray(t)?t.forEach(e=>e.redo()):t.redo()),!0}getCommands(){return this.history}canUndo(){return this.step<=0}canRedo(){return this.step>=this.history.length}clear(){this.history=[],this.step=0}destroy(){this.clear(),this.maxCount=0}}class Mn extends Nt{constructor(e){super();g(this,"name");g(this,"viewerCfg");g(this,"clock");g(this,"targetMaxFps");g(this,"timeStamp");g(this,"renderEnabled");g(this,"requestAnimationFrameHandle");g(this,"container");g(this,"plugins");g(this,"loadedModels");g(this,"raf");g(this,"timeoutSymbol");g(this,"homeView");g(this,"inputManager");g(this,"cameraManager");g(this,"sceneManager");g(this,"fontManager");g(this,"pickManager");g(this,"undoManager");g(this,"overlayRender");g(this,"css2dRenderer");g(this,"spinner");g(this,"progressBar");g(this,"loaderHelper");g(this,"zoomToRectHelper");g(this,"_enableSelection");g(this,"enableRender");this.name=Ke.BaseViewer,this.clock=new p.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new al,this._enableSelection=!0,this.enableRender=(i=1e3)=>{this.renderEnabled=!0,this.raf&&(this.timeoutSymbol&&this.raf.clearTimeout(this.timeoutSymbol),this.timeoutSymbol=this.raf.setTimeout(()=>{this.renderEnabled=!1},i))},this.viewerCfg=e,this.initLogLevel(),this.initLocalization(),this.container=new Fr(e.containerId),e.enableProgressBar&&(this.progressBar=new zr(this.container)),this.spinner=new el(this.container),this.sceneManager=new Au(this),this.pickManager=new Pu(this),this.overlayRender=new bs(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new ul(this.viewerContainer),this.cameraManager=new ou(this),this.loaderHelper=new Vt,this.undoManager=new Iu,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&Co(e)}initLocalization(){const e=this.viewerCfg.language||Eo;Qe.changeLanguage(e)}get viewerContainer(){return this.container.viewerContainer}get widgetContainer(){return this.container.widgetContainer}getUndoManager(){return this.undoManager}getInputManager(){return this.inputManager}getCssRender(){return this.css2dRenderer}getCameraManager(){return this.cameraManager}getOverlayRender(){return this.overlayRender}getSceneManager(){return this.sceneManager}get renderer(){return this.sceneManager.renderer}get camera(){return this.cameraManager.camera}get scene(){return this.sceneManager.scene}getRaycaster(){return this.pickManager.getRaycaster()}getViewerConfig(){return this.viewerCfg}getSpinner(){return this.spinner}getFontManager(){return this.fontManager}initCSS2DRenderer(){const e=new xo.CSS2DRenderer,{width:i,height:s}=this.viewerContainer.getBoundingClientRect();return e.setSize(i,s),e.domElement.style.height="0",e.domElement.style.width="0",e.domElement.style.position="absolute",e.domElement.style.top="0",e.domElement.style.left="0",e.domElement.style.overflow="visible",e.domElement.classList.add("css2d-renderer"),this.viewerContainer?.appendChild(e.domElement),e}animate(){const e=Date.now()-this.timeStamp,i=1/this.targetMaxFps;if(e<i){this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this));return}const s=this.cameraManager.update(this.clock.getDelta());this.container.needResize&&(this.resize(),this.renderEnabled=!0),(this.renderEnabled||s)&&(this.dispatchEvent(le.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(le.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(le.OnAnimate)}resize(){this.sceneManager.resize(),this.cameraManager.updateAspect();const{clientWidth:e,clientHeight:i}=this.viewerContainer;this.css2dRenderer.setSize(e,i),this.overlayRender.setSize(e,i)}setDracoDecoderPath(e){Vt.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=ct,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new yt),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let n=1;if(e.type==="OrthographicCamera"){const r=e;n=Math.max(r.right-r.left,r.top-r.bottom)/r.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const r=e,a=new p.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(n=2*(a.distanceTo(o)*Math.tan(r.fov/2*(Math.PI/180)))/s)}return n}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new dl(this)),this.zoomToRectHelper.activate()}deactivateZoomRect(){this.zoomToRectHelper?.deactivate()}getUniqueModelId(e){let i=e;const s=n=>!!this.loadedModels.find(r=>r.modelId===n);if(s(i)){let n=1;for(;s(i+"_"+n);)n++;i=i+"_"+n,P.warn("[Viewer] Model '"+i+"' is loaded more than once!")}return i}getBBox(){const e=new p.Box3;return this.loadedModels.forEach(i=>{e.union(i.getBBox())}),e}flyToObject(e){this.cameraManager.flyToObject(e)}flyToObjects(e){const i=new p.Box3;e.forEach(n=>{const r=new p.Box3().setFromObject(n);i.union(r)});const s=new p.Sphere;i.getBoundingSphere(s),this.cameraManager.fitToSphere(s)}flyTo(e,i,s=!0){const n=this.camera;if(e.equals(i)){P.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!j.isVectorValid(e)||!j.isVectorValid(i)){P.error("[Viewer] invalid position or lookAt!");return}const r=e.distanceTo(i);r<n.near?(e=e.clone().sub(i).normalize().multiplyScalar(n.near*1.1),P.warn("[Viewer] camera could be too close to see the object!")):r>n.far&&(e=e.clone().sub(i).normalize().multiplyScalar(n.far*.9),P.warn("[Viewer] camera could be too far to see the object!")),this.cameraManager.flyTo(e,i,s)}flyToDirection(e){const i=this.getBBox(),s=i.getSize(new p.Vector3);let n=Math.max(s.x,s.y,s.z)/2;n===0&&(n=1);const r=this.cameraManager.getDistanceToFitSphere(n),a=new p.Vector3;i.getCenter(a);const o=a.clone().add(e.clone().multiplyScalar(r));this.flyTo(o,a)}goToHomeView(){if(this.homeView)this.cameraManager.flyToViewpoint(this.homeView);else{const e=new p.Vector3(1,.5,1);this.flyToDirection(e)}}viewFitAll(){const e=this.getBBox(),i=new p.Sphere;e.getBoundingSphere(i),this.cameraManager.fitToSphere(i)}zoomToBBox(e){this.cameraManager.flyToBox(e)}pickObject(e,i,s){let n=this.pickManager.pickObject(e,this.getRaycastableObjects(),i,s);return this.renderer&&this.renderer.clippingPlanes.length>0&&this.renderer?.clippingPlanes?.every(a=>{n&&a.distanceToPoint(n.point)>0})&&(n=void 0),n}pickObjects(e,i){let s=this.pickManager.pickObjects(e,this.getRaycastableObjects(),i);return s&&this.renderer.clippingPlanes.length>0&&(s=s.filter(n=>this.renderer.clippingPlanes.every(r=>r.distanceToPoint(n.point)>0))),s}getRaycastableObjects(){return this.sceneManager.getRaycastableObjects()}setBackgroundColor(e,i,s){if(!this.scene.background&&(this.scene.background=new p.Color(e,i,s)),this.scene.background instanceof p.Color){const n=new p.Color;n.setRGB(e,i,s,this.renderer.outputColorSpace),this.scene.background.copy(n)}this.enableRender()}setGlobalClipPlanes(e){}getCameraProjection(){return this.cameraManager.getProjection()}setCameraProjection(e){this.cameraManager.setProjection(e)}enableControl(e){this.cameraManager.enableControl(e)}enableRotate(e){this.cameraManager.enableRotate=e}enableZoom(e){this.cameraManager.enableZoom(e)}enablePan(e){this.cameraManager.enablePan(e)}getHomeView(){return this.homeView}setHomeView(e){this.homeView=e}getCameraConfig(){return this.cameraManager.getCameraConfig()}setCameraConfig(e){return this.cameraManager.setCameraConfig(e)}getCameraDirection(){return this.cameraManager.getCameraDirection()}getRenderInfo(){const e=this.renderer.info;return{drawCalls:e.render.calls,lines:e.render.lines,points:e.render.points,triangles:e.render.triangles,geometries:e.memory.geometries,textures:e.memory.textures,materials:e.programs?.length||0}}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.css2dRenderer.domElement.remove(),this.container.destroy(),this.sceneManager.destroy(),this.cameraManager.destroy(),this.overlayRender.destroy(),this.spinner.destroy(),this.progressBar?.destroy(),this.undoManager.destroy()}addPlugin(e){if(this.plugins.find(s=>s.id===e.id)){P.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),P.debug("[Viewer] Added plugin: "+e.id)}removePlugin(e){for(let i=0,s=this.plugins.length;i<s;i++)if(this.plugins[i]===e){this.plugins.splice(i,1);return}}clearPlugins(){this.plugins=[]}findPlugin(e){return this.plugins.find(i=>i.id===e)}}const fl=-1e3,Mi=new p.Vector3,uo=new p.Matrix4,fo=new p.Frustum,nr=new p.Box3,po=new p.Matrix4;class jr extends Mn{constructor(e){super(e);g(this,"name");g(this,"loadedModels");g(this,"masterModelId");g(this,"activeLayoutName");g(this,"dxfLayoutBar");g(this,"layoutInfos");g(this,"units");g(this,"enableHideVisuallySmallObjects");g(this,"sortedHidableObjects");g(this,"lastCameraZoom");g(this,"groundPlane");g(this,"raycastableObjects");g(this,"selectedObject");g(this,"loadingDxfCount");g(this,"textSearchHelper");g(this,"clickHighlightList");g(this,"_enableClickHighlight",!1);g(this,"requestHeaders");g(this,"_printCaptureMode",!1);this.name=Ke.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects!==!1,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new tu(this)),this.cameraManager.setProjection(xt.Orthographic),this.cameraManager.setNavigationMode(ot.Plan);const i=new p.Vector3(0,0,100),s=new p.Vector3(0,0,0);this.cameraManager.setCameraConfig({eye:i,look:s}),this.resize(),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(le.BeforeRender,()=>{this.updateRaycasterThreshold(),this.updateCameraZoomUniform(this.camera.zoom),this.updateHidableObjectsVisibility()})}get camera(){return this.cameraManager.camera}setupDefaultEvents(){let e=!1,i=!1;this.inputManager.addEventListener("pointerdown",s=>{i=!1,e=!0,s.button===$e.Middle&&this.inputManager?.setCursor("move")}),this.inputManager.addEventListener("pointermove",()=>{e&&(i=!0,this.inputManager?.setCursor("move"))}),this.inputManager.addEventListener("pointerup",s=>{if(e=!1,this.inputManager?.setCursor("default"),i){i=!1;return}const n=new p.Vector2(s.x,s.y),r=this.getWorldPositionByMousePick(n),a=this.pickManager.pickObjects(n,this.getRaycastableObjects(),void 0,3);let o;for(const d of a){const u=this.resolveEntityFromPick(d);if(u){u.hit=d,o=u;break}}const l=o?.userData;if(this._enableClickHighlight&&o){const d=this.getEntityBoundingBox(o);d&&this.highlightEntityBox(d)}else this.clearClickHighlight();const h={event:s,position:n,worldPosition:r,pooo:r,entity:l?o?.object:void 0,object:l?o?.object:void 0,point:l?o?.hit?.point:void 0,userData:l,handle:l?.handle};this.dispatchEvent(le.MouseClick,h)})}resolveEntityFromPick(e){if(!e)return;const i=e.object,s=i.userData?.batches;if(s&&s.length>0){const r=i.geometry,a=i.isMesh===!0,o=e.index;let l;a&&typeof e.faceIndex=="number"&&(l=r?.index?r.index.getX(e.faceIndex*3):e.faceIndex*3);const h=s.find(d=>{const u=typeof o=="number"&&o>=d.indexStart&&o<d.indexStart+(d.indexCount||1),f=typeof o=="number"&&o>=d.positionStart&&o<d.positionStart+d.positionCount||typeof l=="number"&&l>=d.positionStart&&l<d.positionStart+d.positionCount;return u||f});if(h?.userData)return{userData:h.userData,batch:h,object:i}}let n=i;for(;n;){if(n.userData?.handle)return{userData:n.userData,object:n};n=n.parent??void 0}}getEntityBoundingBox(e){const i=e.object,s=i.geometry?.getAttribute?.("position");if(e.batch&&s){const r=new p.Box3,a=e.batch.positionStart||0,o=e.batch.positionCount||0;if(o>0){i.updateWorldMatrix(!0,!1),po.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Mi.fromBufferAttribute(s,l).applyMatrix4(po),r.expandByPoint(Mi);if(!r.isEmpty())return r}}const n=new p.Box3;return n.setFromObject(i),n.isEmpty()?void 0:n}highlightEntityBox(e){const i=this.getOverlayRender();i&&(!this.clickHighlightList&&(this.clickHighlightList=new ws("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new bt(j.guid(),[e.clone()],[.031,.906,.867,1],[.031,.906,.867,.15])),this.enableRender())}get enableClickHighlight(){return this._enableClickHighlight}set enableClickHighlight(e){this._enableClickHighlight=e,e||this.clearClickHighlight()}clearClickHighlight(){this.clickHighlightList?.clear(),this.enableRender()}setRequestHeaders(e){this.requestHeaders=e}handleMouseClick(e){if(!this.enableSelection)return;const i=new p.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const n=this.overlayRender.getDrawablesByPosition(s)[0];if(n){this.selectedObject===n?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=n,this.selectedObject.selected=!0),this.enableRender();return}const r=this.pickObject(i,[Ut]);if(r){const a=r?.object;this.selectedObject===a?(this.setObjectUnHighlight(this.selectedObject),this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=a,this.setObjectHighlight(this.selectedObject)),this.enableRender();return}this.clearSelection(),this.enableRender()}setDefaultBackground(){this.setBackgroundColor(.0295,.0212,.0152)}async loadModel(e,i,s){const n=this.getUniqueModelId(e.modelId||e.src);this.spinner.increaseJobCount(),this.loaderHelper.setFont(this.fontManager),this.masterModelId||(this.masterModelId=n);const r=n,a=Qe.t("ProgressBar.Loading"),o=b=>{this.progressBar?.updateProgress(r,a,b),i?.(new ProgressEvent("LoadProgress",{loaded:b,total:100}))},l=(b,y,C)=>{let w=b.loaded*100/b.total;w=w*(C-y)/100+y,this.progressBar?.updateProgress(r,a,w),i?.(new ProgressEvent("LoadProgress",{loaded:w,total:100}))},h=b=>l(b,0,90);this.progressBar?.addProgressItem(r),o(0);const d=this.viewerCfg,u=await this.loaderHelper.loadDxfData(e.src,e.modelId,h,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:d.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor,requestHeaders:e.headers??this.requestHeaders}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),f=u.threejsObject;if(s&&s({threejsObject:f,llbMesh:u.llbMesh}),e.matrix&&e.matrix.length===16){const b=new p.Matrix4;b.elements=e.matrix,f.applyMatrix4(b)}const m=new Ri({modelId:n,dxfData:u});this.addModel(m),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(r),this.dispatchEvent(le.ModelLoad)}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(X.MODEL_LAYOUT_NAME):this.handleOverlayDxf(i);const s=e.getBBox(),n=new p.Vector3;s.getCenter(n),this.cameraManager.adjustCameraByBBox(s);const r=this.getDxfUnits(e);this.masterModelId===i&&(this.units=r)}else{const s=e.getModelObject();this.activeLayoutName=X.MODEL_LAYOUT_NAME;const n=new p.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:n,extent:n},s.matrixAutoUpdate=ct,this.scene.add(s);const r=n.max.z;r>this.camera.position.z&&(this.camera.position.z=r,this.camera.updateProjectionMatrix()),this.flyToObject(s)}this.updateGroundPlane()}getDxfUnits(e){return!e&&this.loadedModels.length>0&&(e=this.loadedModels.find(i=>this.masterModelId===i.modelId)),e?e.getUnits():Ze.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(n=>e===n.modelId);if(!i){P.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(X.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(X.MODEL_LAYOUT_NAME)?.traverse(n=>{i.addSpatialFilterSection(n,i.dxfData)}),i.showLayoutObjects(X.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof p.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clickHighlightList?.clear()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],n=(o,l,h)=>{s.push(new p.Vector3(o,l,h))},r=i.getSize(new p.Vector3),a=i.getCenter(new p.Vector3);if(n(-r.x/2,-r.y/2,0),n(r.x/2,-r.y/2,0),n(r.x/2,r.y/2,0),n(-r.x/2,r.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new p.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new p.MeshBasicMaterial({color:"#888",side:p.DoubleSide});this.groundPlane=new p.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=fl,this.groundPlane.layers.enableAll(),J.disableLayerChannels(this.groundPlane,[Ut]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===X.MODEL_LAYOUT_NAME){if(this.raycastableObjects)return this.raycastableObjects;if(this.renderer?.renderLists){const s=this.renderer?.renderLists.get(this.scene,0);s&&(s.opaque.forEach(n=>{n.object&&n.object.geometry&&e.push(n.object)}),s.transparent.forEach(n=>{n.object&&n.object.geometry&&e.push(n.object)}))}uo.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),fo.setFromProjectionMatrix(uo);for(const s of this.loadedModels){const n=s.getModelObject(),r=n.children.find(a=>a.name===this.activeLayoutName);r&&r.children.find(o=>o.name===X.SNAP_GROUP_NAME)?.traverse(o=>{if(J.isLeafObject(o)){if(nr.makeEmpty(),nr.expandByObject(o),!fo.intersectsBox(nr))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),P.debug("[Viewer] getRaycastableObjectsByMouse() from modelSpace"),this.raycastableObjects=e}else{const s=new WeakSet,n=this.getLayoutByName(this.activeLayoutName);n&&n.directAssociatedLeafObjectSet?.forEach(o=>{o.visible&&!s.has(o)&&(e.push(o),s.add(o))});const r=this.getViewportByPoint(this.pickManager.getRaycaster().ray.origin);r&&r.associatedLeafObjectSet?(r.associatedLeafObjectSet?.forEach(a=>{!s.has(a)&&(a.visible||a.userData.isSnapObject)&&(e.push(a),s.add(a))}),P.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",r.viewportId)):P.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return P.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===X.MODEL_LAYOUT_NAME)return;const i=this.getLayoutByName(this.activeLayoutName);if(!i)return;const s=a=>e.x<a.min.x||e.x>a.max.x||e.y<a.min.y||e.y>a.max.y,n=this.loadedModels.find(a=>this.masterModelId===a.modelId);if(!n)return;const r=n.getFilteredViewports(i);for(let a=0,o=r.length;a<o;a++){const l=r[a];if(!s(l.psBBox))return l}}getWorldPositionByMousePick(e){const i=[];this.groundPlane&&i.push(this.groundPlane);for(const n of this.loadedModels){const r=n.getModelObject();r&&(i.push(r),r.traverse(a=>{(a.isMesh||a.isLine)&&i.push(a)}))}return this.pickManager.pickObject(e,i)?.point}activateLayout(e=X.MODEL_LAYOUT_NAME){if(this.activeLayoutName===e||!this.masterModelId)return;const i=this.loadedModels.find(d=>this.masterModelId===d.modelId);if(!i)return;const s=i.getLayoutByName(e);if(!s)return;const n=this.getActiveLayoutInfo();if(this.groundPlane){const d=this.getCurrentViewExtent(),u=this.camera.position.z;n.lastViewExtent=new p.Box3(new p.Vector3(d.min.x,d.min.y,0),new p.Vector3(d.max.x,d.max.y,u))}const r=d=>!!this.layoutInfos[d]?.lastViewExtent,a=r(e);i?.activateLayout(e,a),this.activeLayoutName=e;const o=i.getFilteredViewports(s);if(P.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const d=this.camera.position.z;let u=0;o.forEach(m=>{const b=m?.msToPsMatrix?.elements[14];b&&b>u&&(u=b)});const f=this.cameraManager.getPosition();if(u>f.z+d){const m=Math.ceil(u+d);f.z=m,P.info("[Viewer] Changing camera's z value from "+f.z+" to "+m),this.cameraManager.setCameraPosition(f)}}const l=this.getActiveLayoutInfo();if(l.lastViewExtent)this.zoomToBBox(l.lastViewExtent);else{l.extent=this.getBBox();let d=this.getLayoutExtentEx(s);if(d){const b=d.max.x-d.min.x,y=d.max.y-d.min.y;(b<1e-16||y<1e-16||b>1e16||y>1e16)&&(P.warn("[Viewer] Got wired bbox, max: "+d.max.toArray()+", min: "+d.min.toArray()+", going to use the calculated one..."),d=l.extent)}else P.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),d=l.extent;const u=l.extent;d&&!u.isEmpty()&&(d.intersectsBox(u)?d.union(u):(P.warn("[Viewer] Layout extent from header is far from actual geometry, using computed bbox instead."),d=u.clone())),l.homeViewExtent=d,this.zoomToBBox(d)}const h=i.getLayoutLevelObject(e);h&&this.setLayoutHidableObjectArray(h),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===X.MODEL_LAYOUT_NAME?i.getModelSpaceExtent():i.getLayoutExtent(e)}getActiveLayoutInfo(){return this.getLayoutInfo(this.activeLayoutName)}getLayoutByName(e){let i;const s=this.loadedModels.find(r=>this.masterModelId===r.modelId);if(!s)return;const n=s.getLayouts();for(const r of n)if(r.layoutName===e){i=r;break}return i}getEntityCount(){let e=0;return this.loadedModels.forEach(i=>{e+=i.loadedEntityCount}),e}getLayoutNames(){const e=[];return(this.loadedModels.find(n=>this.masterModelId===n.modelId)?.getLayouts()||[]).forEach(n=>{e.push(n.layoutName)}),e}getLayoutInfo(e){return this.layoutInfos[e]||(this.layoutInfos[e]={}),this.layoutInfos[e]}goToHomeView(){const e=this.getActiveLayoutInfo();e.homeViewExtent?this.zoomToBBox(e.homeViewExtent):P.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Mi),s=e.max.x-e.min.x,n=e.max.y-e.min.y,r=this.camera.right-this.camera.left,a=this.camera.top-this.camera.bottom;let o=Math.min(r/s,a/n);o/=1.1,this.cameraManager.cameraControls.moveTo(i.x,i.y,i.z),this.cameraManager.cameraControls.zoomTo(o)}getCurrentViewExtent(){const e=this.getHitResultByNdcCoordinate(new p.Vector2(-1,-1)),i=this.getHitResultByNdcCoordinate(new p.Vector2(1,1));return new p.Box2(e,i)}getHitResultByNdcCoordinate(e){const i=[];this.groundPlane&&i.push(this.groundPlane);const s=this.pickManager.pickObjectsByNdc(e,i);if(s.length>0){const n=s[0].point;return new p.Vector2(n.x,n.y)}}getHitResult(e){const i=this.viewerContainer,s=Ee.getScreenCoordinateByEvent(e,i),n=Ee.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(n)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new Tr(this)),this.textSearchHelper.search(e,i)}focusText(e){!this.textSearchHelper&&(this.textSearchHelper=new Tr(this)),this.textSearchHelper.focus(e)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}async print(e={}){const{area:i="view",paperSize:s="A4",orientation:n="auto",invertColors:r=!1,fitToPage:a=!0,margins:o=10,title:l="图纸"}=e;if(!this.loadedModels.length){P.warn("[Viewer] print: no model loaded.");return}const h=this.capturePrintImage(i,r),d=new Image;await new Promise((f,m)=>{d.onload=()=>f(),d.onerror=()=>m(new Error("Failed to load captured print image.")),d.src=h});const u=n==="auto"?d.width>=d.height?"landscape":"portrait":n;this.printImageInIframe({dataUrl:h,width:d.width,height:d.height,paperSize:s,orientation:u,invertColors:r,fitToPage:a,margins:o,title:l})}capturePrintImage(e,i){const s=this.cameraManager.cameraControls,n=this.renderer,r=s.getPosition(new p.Vector3),a=s.getTarget(new p.Vector3),o=this.camera.zoom,l=n.getPixelRatio();let h;e==="extents"&&(h=this.getActiveLayoutInfo().homeViewExtent??this.getBBox(),this.zoomToBBox(h)),this._printCaptureMode=!0;const d=this.sortedHidableObjects[this.activeLayoutName],u=[];if(d)for(const O of d)O.object.userData?.layerVisible!==!1&&(u.push({object:O.object,visible:O.object.visible}),O.object.visible=!0);const{clientWidth:f,clientHeight:m}=this.viewerContainer,b=Math.min(n.capabilities.maxTextureSize||4096,8192),y=Math.min(4,b/Math.max(f,m));y>l&&n.setPixelRatio(y),this.cameraManager.update(0),this.dispatchEvent(le.BeforeRender),n.render(this.scene,this.camera),this.dispatchEvent(le.AfterRender);const C=n.domElement,w=this.overlayRender.getCanvas(),x=document.createElement("canvas");x.width=C.width,x.height=C.height;const E=x.getContext("2d");if(E.drawImage(C,0,0),w&&w.width>0&&w.height>0&&E.drawImage(w,0,0,x.width,x.height),i){const O=new p.Color(1973806);this.scene.background instanceof p.Color?O.copy(this.scene.background):n.getClearColor(O),O.convertLinearToSRGB(),this.invertForPrint(x,Math.max(1,Math.round(y/2)),{r:O.r*255,g:O.g*255,b:O.b*255})}let M=x.toDataURL("image/png");if(h&&this.camera.type==="OrthographicCamera"){const O=this.cropCanvasToBox(x,h);O&&(M=O)}this._printCaptureMode=!1;for(const{object:O,visible:S}of u)O.visible=S;return n.setPixelRatio(l),s.zoomTo(o),s.setLookAt(r.x,r.y,r.z,a.x,a.y,a.z),this.cameraManager.update(0),this.enableRender(),M}invertForPrint(e,i,s){const n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const r=e.width,a=e.height,o=n.getImageData(0,0,r,a),l=o.data,h=r*a,d=45,u=.72,f=new Float32Array(h);for(let S=0,v=0;S<h;S++,v+=4){const T=l[v],_=l[v+1],A=l[v+2],I=T-s.r,B=_-s.g,k=A-s.b;if(Math.sqrt(I*I+B*B+k*k)<d){l[v]=255,l[v+1]=255,l[v+2]=255,f[S]=255;continue}const L=T/255,F=_/255,ie=A/255,se=Math.max(L,F,ie),Fe=Math.min(L,F,ie),ht=(se+Fe)/2,Me=se-Fe,Vi=Me===0?0:Me/(1-Math.abs(2*ht-1));let et=0;Me!==0&&(se===L?et=(F-ie)/Me%6:se===F?et=(ie-L)/Me+2:et=(L-F)/Me+4,et/=6,et<0&&(et+=1));const Tn=Math.min(.55,(1-ht)*u),ke=(1-Math.abs(2*Tn-1))*Vi,Pt=ke*(1-Math.abs(et*6%2-1)),ji=Tn-ke/2;let Gt=0,qt=0,Wt=0;const Yt=Math.floor(et*6)%6;Yt===0?(Gt=ke,qt=Pt):Yt===1?(Gt=Pt,qt=ke):Yt===2?(qt=ke,Wt=Pt):Yt===3?(qt=Pt,Wt=ke):Yt===4?(Gt=Pt,Wt=ke):(Gt=ke,Wt=Pt),l[v]=(Gt+ji)*255,l[v+1]=(qt+ji)*255,l[v+2]=(Wt+ji)*255,f[S]=.299*l[v]+.587*l[v+1]+.114*l[v+2]}const m=Math.max(1,i),b=new Float32Array(h),y=new Uint8ClampedArray(h),C=new Uint8ClampedArray(h),w=new Uint8ClampedArray(h);for(let S=0;S<a;S++){const v=S*r;for(let T=0;T<r;T++){let _=255,A=v+T;const I=Math.max(0,T-m),B=Math.min(r-1,T+m);for(let k=I;k<=B;k++){const L=f[v+k];L<_&&(_=L,A=v+k)}b[v+T]=_,y[v+T]=l[A*4],C[v+T]=l[A*4+1],w[v+T]=l[A*4+2]}}const x=new Float32Array(h),E=new Uint8ClampedArray(h),M=new Uint8ClampedArray(h),O=new Uint8ClampedArray(h);for(let S=0;S<r;S++)for(let v=0;v<a;v++){let T=255,_=v*r+S;const A=Math.max(0,v-m),I=Math.min(a-1,v+m);for(let k=A;k<=I;k++){const L=b[k*r+S];L<T&&(T=L,_=k*r+S)}const B=v*r+S;x[B]=T,E[B]=y[_],M[B]=C[_],O[B]=w[_]}for(let S=0,v=0;S<h;S++,v+=4)f[S]>250&&x[S]<250&&(l[v]=E[S],l[v+1]=M[S],l[v+2]=O[S]);n.putImageData(o,0,0)}cropCanvasToBox(e,i){const s=this.camera,n=s.zoom||1,r=s.position.x,a=s.position.y,o=r+s.left/n,l=r+s.right/n,h=a+s.bottom/n,d=a+s.top/n,u=l-o,f=d-h;if(u<=0||f<=0)return;const m=v=>(v-o)/u*e.width,b=v=>(d-v)/f*e.height,y=Math.max(u,f)*.01,C=Math.max(0,Math.floor(m(i.min.x-y))),w=Math.min(e.width,Math.ceil(m(i.max.x+y))),x=Math.max(0,Math.floor(b(i.max.y+y))),E=Math.min(e.height,Math.ceil(b(i.min.y-y))),M=w-C,O=E-x;if(M<16||O<16)return;const S=document.createElement("canvas");return S.width=M,S.height=O,S.getContext("2d").drawImage(e,C,x,M,O,0,0,M,O),S.toDataURL("image/png")}printImageInIframe(e){const{dataUrl:i,width:s,height:n,paperSize:r,orientation:a,invertColors:o,fitToPage:l,margins:h,title:d}=e,u={A4:[210,297],A3:[297,420],A2:[420,594],A1:[594,841],A0:[841,1189],Letter:[215.9,279.4]};let[f,m]=u[r]??u.A4;a==="landscape"&&([f,m]=[m,f]);const b=document.createElement("iframe");b.setAttribute("aria-hidden","true");const y=96/25.4;b.style.cssText=`position:fixed;left:-20000px;top:0;border:0;visibility:hidden;width:${Math.ceil(f*y)}px;height:${Math.ceil(m*y)}px;`;const C=v=>v.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),w=l?"max-width:100%;max-height:100%;width:auto;height:auto;":"width:100%;height:auto;",x=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${C(d)}</title><style>@page{size:${r} ${a};margin:${h}mm;}html,body{margin:0;padding:0;background:#fff;}body{display:flex;align-items:center;justify-content:center;width:${f-2*h}mm;height:${m-2*h}mm;overflow:hidden;}img{display:block;${w}}</style></head><body><img src="${i}" alt="${C(d)}"></body></html>`;document.body.appendChild(b);const E=()=>{b.contentWindow?.removeEventListener("afterprint",E),setTimeout(()=>b.remove(),100)},M=b.contentDocument;M.open(),M.write(x),M.close();const O=M.querySelector("img"),S=()=>{const v=b.contentWindow;v.addEventListener("afterprint",E),v.focus(),v.print(),setTimeout(E,6e4)};O.complete?S():(O.onload=S,O.onerror=E)}getLayers(){const e=[];if(this.masterModelId){const i=this.loadedModels.find(n=>this.masterModelId===n.modelId),s=i?.layers;s&&e.push({modelId:this.masterModelId,layers:s})}for(const i of this.loadedModels){const s=i.modelId;if(s===this.masterModelId)continue;const n=i.layers;n&&e.push({modelId:s,layers:n})}return e}setModelVisibility(e,i){const s=this.loadedModels.find(n=>e===n.modelId);if(!s)throw new Error("Failed to find model by modelId '"+e+"'!");s.setVisible(i),this.enableRender()}setLayerVisibility(e,i,s){const n=this.camera;s=s||this.masterModelId;const r=this.loadedModels.find(a=>s===a.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");r.setLayerVisible(e,i,this.enableHideVisuallySmallObjects,n.zoom),this.raycastableObjects=void 0,this.enableRender()}setLayerOpacity(e,i,s){s=s||this.masterModelId;const n=this.loadedModels.find(r=>s===r.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");n.setLayerOpacity(e,i),this.enableRender()}setLayerColor(e,i,s){s=s||this.masterModelId;const n=this.loadedModels.find(r=>s===r.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");this.clearSelection(),n.setLayerColor(e,i),this.enableRender()}resetLayerColor(e,i){i=i||this.masterModelId;const s=this.loadedModels.find(n=>i===n.modelId);if(!s)throw new Error("Failed to find model by modelId '"+i+"'!");this.clearSelection(),s.resetLayerColor(e),this.enableRender()}getVisiblePixelSize(e){const i=p.MathUtils.smoothstep(e,1e4,3e4)*6.5+.5;return P.debug("[Viewer] visiblePixelSize:",i),i}setLayoutHidableObjectArray(e){const i=this.camera;if(!this.enableHideVisuallySmallObjects||!i)return;const s=Date.now(),n=e.name;this.sortedHidableObjects[n]||(this.sortedHidableObjects[n]=[]);const r=this.sortedHidableObjects[n];this.cameraManager.update(0);const a=i.zoom;this.lastCameraZoom=a;let o=1;e.traverse(h=>{if(h.userData.isSnapObject||!J.isLeafObject(h))return;const d=h.geometry;d.boundingBox||d.computeBoundingBox();const u=d.boundingBox.clone();if(!u||!j.isBoxValid(u))return;u.applyMatrix4(h.matrixWorld),u.getSize(Mi);const f=Math.max(Mi.x,Mi.y),m=o/f;m<1/0?r.push({visibleMinZoom:m,object:h}):h instanceof p.Points?r.push({visibleMinZoom:o,object:h}):P.warn("[Viewer] The size of bbox is 0 ! ",h)}),o=this.getVisiblePixelSize(r.length);let l=0;r.forEach(h=>{const d=h.visibleMinZoom*o;h.visibleMinZoom=d,h.object.userData.visibleMinZoom=d,d>a&&(h.object.visible=!1,l++)}),r.sort((h,d)=>h.visibleMinZoom-d.visibleMinZoom),P.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5)return;if(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,this._printCaptureMode){this.lastCameraZoom=s;return}if(!this.sortedHidableObjects[this.activeLayoutName])return;const n=this.sortedHidableObjects[this.activeLayoutName];if(n.length===0)return;const r=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let h=0;for(let d=0;d<n.length;++d)if(n[d].object.userData.layerVisible!==!1){if(n[d].visibleMinZoom<a){l.push(n[d].object);continue}else if(n[d].visibleMinZoom>o)break;n[d].object.visible=r,r&&l.push(n[d].object),h++}this.lastCameraZoom=s,P.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+h+"(out of "+n.length+") objects changed to "+(r?"visible":"hidden"))}updateCameraZoomUniform(e){X.CameraZoomUniform.value=e*this.container.height/50}}class pl{constructor(t){g(this,"viewer");g(this,"fontManager");g(this,"loader");g(this,"loadingManager");g(this,"changes");g(this,"container");g(this,"spinner");g(this,"jobCount");g(this,"loadingProgressBar");this.jobCount=0,this.viewer=new jr(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Fr(t.containerId);this.loadingProgressBar=new zr(i);const s={ignorePaperSpace:!0};this.loader=new X(this.loadingManager,s),this.initSpinner()}initSpinner(){const t=document.createElement("div");t.classList.add("x-spinner"),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),this.container.appendChild(t),this.spinner=t,this.setSpinnerVisibility(this.jobCount>0)}async setFont(t){const e=Date.now();!this.fontManager&&(this.fontManager=new yt),await this.fontManager.loadFonts(t),P.info("[DxfCompareHelper] Font file(s) load time in "+(Date.now()-e)/1e3+"s")}async compare(t,e,i,s){const{src:n,modelId:r}=t,{src:a}=e;this.viewer.masterModelId=r||n;const o=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=n+a,h=Qe.t("ProgressBar.Comparing"),d=B=>{this.loadingProgressBar?.updateProgress(l,h,B),s&&s(new ProgressEvent("CompareProgress",{loaded:B,total:100}))},u=(B,k,L)=>{let F=B.loaded*100/B.total;F=F*(L-k)/100+k,this.loadingProgressBar?.updateProgress(l,h,F),s&&s(new ProgressEvent("CompareProgress",{loaded:F,total:100}))},f=B=>u(B,0,15),m=B=>u(B,15,30),b=B=>u(B,30,60),y=B=>u(B,60,95);j.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),d(0);let C=Date.now();const w=this.loader.parse(n,f),x=this.loader.parse(a,m),[E,M]=await Promise.allSettled([w,x]);if(E.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+n);if(M.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+a);if(P.info("[DxfCompareHelper] loadFiles in "+(Date.now()-C)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const O=E.value,S=M.value;C=Date.now();const v=await new at(O,S,i).compare(b);if(P.info("[DxfCompareHelper] Compared in "+(Date.now()-C)/1e3+"s"),P.debug("[DxfCompareHelper] Compared results:",v),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");j.printMemory("After getting the comparison results"),C=Date.now(),await this.loader.loadEntitiesForCompare(O,S,v,!0,y),j.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=v,P.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-C)/1e3+"s");const T=O,_=S;if(this.decreaseJobCount(),!Object.keys(v).length&&P.info("[DxfCompareHelper] No change found"),T.threejsObject?.children.length===0&&_.threejsObject?.children.length===0){const B="[DxfCompareHelper] Nothing was loaded from "+n+" and "+a;return P.warn(B),Promise.reject(B)}const A=T.threejsObject,I=_.threejsObject;return A.name=n,I.name=a,C=Date.now(),this.viewer.addModel(new Ri({modelId:t.modelId||t.src,dxfData:T})),this.viewer.flyToObject(A),j.printMemory("After adding first loaded Model to scene"),d(95),this.viewer.addModel(new Ri({modelId:e.modelId||e.src,dxfData:_})),j.printMemory("After adding second loaded Model to scene"),P.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-C)/1e3+"s"),P.info("[DxfCompareHelper] The comparison between "+n+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),d(100),this.loadingProgressBar?.delayRemoveProgressItem(l),Promise.resolve()}getChanges(){return this.changes}zoomToChange(t){if(this.changes){const e=this.changes[t];if(!e)return;const i=e.box;i&&this.viewer.zoomToBBox(i.clone().expandByScalar(1.2))}}setSpinnerVisibility(t){this.spinner&&(t?this.spinner.classList.remove("hidden"):this.spinner.classList.add("hidden"))}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){this.setSpinnerVisibility(--this.jobCount>0)}}class Bu extends pl{constructor(e,i){super(e);g(this,"viewer2");g(this,"syncCamera");g(this,"markupManager1");g(this,"markupManager2");g(this,"syncCameraControls");this.syncCamera=!1,this.syncCameraControls=(s,n,r)=>{const a=new p.Vector3,o=new p.Vector3,l=new p.Vector3;s.getPosition(o),s.getTarget(l),s.getFocalOffset(a),n.setLookAt(o.x,o.y,o.z,l.x,l.y,l.z),n.zoomTo(r),n.dispatchEvent({type:"control"})},this.viewer2=new jr(i),this.initSyncCameraEvent()}initSyncCameraEvent(){const e=this.viewer.getCameraManager().cameraControls,i=this.viewer2.getCameraManager().cameraControls;let s=!1;e.addEventListener("control",()=>{s=!1}),e.addEventListener("update",()=>{!this.syncCamera||s||this.syncCameraControls(e,i,this.viewer.camera.zoom)}),i.addEventListener("control",()=>{s=!0}),i.addEventListener("update",()=>{!this.syncCamera||!s||this.syncCameraControls(i,e,this.viewer2.camera.zoom)})}enableSyncCamera(e){if(this.syncCamera=e,e){const i=this.viewer.getCameraManager().cameraControls,s=this.viewer2.getCameraManager().cameraControls;this.syncCameraControls(i,s,this.viewer.camera.zoom)}}async compare(e,i,s,n){const{src:r,modelId:a}=e,{src:o,modelId:l}=i;this.viewer.masterModelId=a||r,this.viewer2.masterModelId=l||o;const h=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const d=r+o,u=Qe.t("ProgressBar.Comparing"),f=L=>{this.loadingProgressBar?.updateProgress(d,u,L),n&&n(new ProgressEvent("CompareProgress",{loaded:L,total:100}))},m=(L,F,ie)=>{let se=L.loaded*100/L.total;se=se*(ie-F)/100+F,this.loadingProgressBar?.updateProgress(d,u,se),n&&n(new ProgressEvent("CompareProgress",{loaded:se,total:100}))},b=L=>m(L,0,15),y=L=>m(L,15,30),C=L=>m(L,30,60),w=L=>m(L,60,95);j.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(d),f(0);let x=Date.now();const E=this.loader.parse(r,b),M=this.loader.parse(o,y),[O,S]=await Promise.allSettled([E,M]);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(S.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+o);if(P.info("[DxfCompareHelper] loadFiles in "+(Date.now()-x)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const v=O.value,T=S.value;x=Date.now();const _=await new at(v,T,s).compare(C);if(P.info("[DxfCompareHelper] Compared in "+(Date.now()-x)/1e3+"s"),P.debug("Compared results:",_),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");j.printMemory("After getting the comparison results"),x=Date.now(),await this.loader.loadEntitiesForCompare(v,T,_,!1,w),j.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=_,P.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-x)/1e3+"s");const A=v,I=T;if(this.decreaseJobCount(),!Object.keys(_).length&&P.info("[DxfCompareHelper] No change found"),A.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const L="[DxfCompareHelper] Nothing was loaded from "+r+" and "+o;return P.warn(L),Promise.reject(L)}const B=A.threejsObject,k=I.threejsObject;return B.name=r,k.name=o,x=Date.now(),this.viewer.addModel(new Ri({modelId:e.modelId||e.src,dxfData:A})),j.printMemory("After adding first loaded Model to scene"),f(95),this.viewer2.addModel(new Ri({modelId:i.modelId||i.src,dxfData:I})),j.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),P.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-x)/1e3+"s"),P.info("[DxfCompareHelper] The comparison between "+r+"' and '"+o+"' is completed in "+(Date.now()-h)/1e3+"s !"),f(100),this.loadingProgressBar?.delayRemoveProgressItem(d),Promise.resolve()}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new Mr(this.viewer)),this.markupManager2??(this.markupManager2=new Mr(this.viewer2)),requestAnimationFrame(()=>{this.markupManager1?.drawCompareDrawable(this.changes),this.markupManager2?.drawCompareDrawable(this.changes),this.viewer.enableRender(),this.viewer2.enableRender()}))}zoomToChange(e){if(this.changes){const i=this.changes[e];if(!i)return;const s=i.box;s&&(this.viewer.zoomToBBox(s.clone().expandByScalar(1.2)),this.viewer2.zoomToBBox(s.clone().expandByScalar(1.2)))}}}class Pi{constructor(t,e){g(this,"current");g(this,"next");g(this,"inNormal");g(this,"outNormal");this.current=t,this.next=e,this.inNormal=this.inwardsNormal(),this.outNormal=this.outwardsNormal()}outwardsNormal(){const t=this.inwardsNormal();return[-t[0],-t[1]]}inwardsNormal(){const t=this.next[0]-this.current[0],e=this.next[1]-this.current[1],i=Math.sqrt(t*t+e*e);if(i===0)throw new Error("Vertices overlap");return[-e/i,t/i]}offset(t,e){return Pi.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return Pi.offsetEdge(this.next,this.current,t,e)}inverse(){return new Pi(this.next,this.current)}static offsetEdge(t,e,i,s){return new Pi([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const ss=Array.isArray,mo=(c,t)=>c[0]===t[0]&&c[1]===t[1],rr=c=>Array.isArray(c)&&c.length,ml=(c,t=0,e=!1)=>{let i,s;if(rr(c)&&typeof c[0][0]=="number"){let n=0;const r=c;for(i=0,s=r.length;i<s;i++){const a=r[i],o=r[(i+1)%s];n+=a[0]*o[1],n-=o[0]*a[1]}(!e&&n>0||e&&n<0)&&r.reverse()}else for(i=0,s=c.length;i<s;i++)ml(c[i],t+1,i>0);if(t===0&&rr(c)&&rr(c[0])&&typeof c[0][0][0]=="number"){const n=c[0].slice(0,1)[0];c[0].pop(),c[0].push([n[0],n[1]])}return c};class ku{constructor(t,e=5){g(this,"vertices");g(this,"edges");g(this,"arcSegments");g(this,"distance");if(this.distance=0,this.arcSegments=e,!ss(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],ss(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=ml(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(ss(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,mo(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new Pi(t[i],t[(i+1)%s]));else for(t=t,e=e,i=0,s=t.length;i<s;i++)e.push([]),this.processContour(t[i],e[e.length-1])}setArcSegments(t){return this.arcSegments=t,this}createArc(t,e,i,s,n,r,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),h=Math.atan2(n[1]-e[1],n[0]-e[0]);r%2===0&&(r-=1),l<0&&(l+=o),h<0&&(h+=o);let d=l>h?l-h:l+o-h;const u=(a?-d:o-d)/r;t.push(s);for(let f=1;f<r;++f)d=l+u*f,t.push([e[0]+Math.cos(d)*i,e[1]+Math.sin(d)*i]);return t.push(n),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return mo(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const n=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],r=[];for(let a=0,o=2;a<o;a++){const l=n[a],h=n[(a+o-1)%o];this.createArc(r,a===0?t:e,s,h.next,l.current,this.arcSegments,!0)}return r}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Ui.union(this.vertices,e),e}padding(t){if(this.setDistance(t),this.distance===0)return this.vertices;if(this.vertices.length===2&&typeof this.vertices[0]=="number")return this.vertices;const e=this.offsetLines(this.distance);return Ui.difference(this.vertices,e)}offsetLine(t){return t===0?this.vertices:this.offsetLines(t)}offsetLines(t){if(t<0)throw new Error("Cannot apply negative margin to the line");this.setDistance(t);let e=[];if(ss(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,n=this.edges.length;s<n;s++){const r=this.offsetContour(this.vertices[s],this.edges[s]);r.length>0&&i.push(r)}i.length>0&&(e=i.length===1?i[0]:Ui.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,n=0;if(ss(t[0])&&typeof t[0][0]=="number"){for(s=0,n=t.length-1;s<n;s++){const r=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[r];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Ui.union(i[0],i.slice(1)))}else{const r=[];for(s=0,n=e.length;s<n;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&r.push(a)}r.length>0&&(i=r.length===1?r[0]:Ui.union(r[0],...r.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,n=this.distance;let r=0;e%2===0&&e++;for(let a=0;a<e;a++)r+=2*Math.PI/e,i.push([s[0]+n*Math.cos(r),s[1]+n*Math.sin(r)]);return[[this.ensureLastPoint(i)]]}}class gl{constructor(t){g(this,"viewer");g(this,"composerEnabled");g(this,"composer");g(this,"renderPass");g(this,"effectFxaaPass");g(this,"saoPass");g(this,"ssaoPass");g(this,"outlinePass");g(this,"ssaaRenderPass");g(this,"bloomPass");g(this,"unrealBloomPass");g(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Ql.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(le.AfterRender,()=>this.render())}get enabled(){return this.composerEnabled}set enabled(t){this.composerEnabled=t}get renderPassEnabled(){return!!this.renderPass?.enabled}set renderPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.renderPass){const r=new ec.RenderPass(e,i);r.setSize(s,n),this.composer.addPass(r),this.renderPass=r}this.renderPass&&(this.renderPass.enabled=t),this.viewer.enableRender()}}get fxaaPassEnabled(){return!!this.effectFxaaPass?.enabled}set fxaaPassEnabled(t){if(!this.composer)return;const{width:e,height:i}=this.viewer.container;if(t&&!this.effectFxaaPass){const s=new tc.ShaderPass(lc.FXAAShader);s.uniforms.resolution.value.set(1/e,1/i),s.renderToScreen=!0,s.setSize(e,i),this.composer.addPass(s),this.effectFxaaPass=s}this.effectFxaaPass&&(this.effectFxaaPass.enabled=t),this.viewer.enableRender()}get saoPassEnabled(){return!!this.saoPass?.enabled}set saoPassEnabled(t){const{width:e,height:i}=this.viewer.container,s=this.viewer.scene,n=this.viewer.camera;if(this.composer){if(t&&!this.saoPass){const r=new ic.SAOPass(s,n,new p.Vector2(1/e,1/i));r.setSize(e,i),r.params.output=0,r.params.saoBias=.5,r.params.saoIntensity=3e-4,r.params.saoScale=8,r.params.saoKernelRadius=40,r.params.saoMinResolution=0,this.composer.addPass(r),this.saoPass=r}this.saoPass&&(this.saoPass.enabled=t),this.viewer.enableRender()}}get ssaoPassEnabled(){return!!this.ssaoPass?.enabled}set ssaoPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.ssaoPass){const r=new sc.SSAOPass(e,i,s,n);r.kernelRadius=16,r.minDistance=1e-4,r.maxDistance=.3,this.composer.addPass(r),this.ssaoPass=r}this.ssaoPass&&(this.ssaoPass.enabled=t),this.viewer.enableRender()}}get outlinePassEnabled(){return!!this.outlinePass?.enabled}set outlinePassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.outlinePass){const r=new nc.OutlinePass(new p.Vector2(s,n),e,i);r.edgeStrength=3,r.edgeGlow=0,r.edgeThickness=2,r.pulsePeriod=0,r.visibleEdgeColor.set(16711680),r.hiddenEdgeColor.set(16752768),this.composer.addPass(r),this.outlinePass=r}this.outlinePass&&(this.outlinePass.enabled=t),this.viewer.enableRender()}}get ssaaPassEnabled(){return!!this.ssaaRenderPass?.enabled}set ssaaPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera;if(this.composer){if(t&&!this.ssaaRenderPass){const s=new rc.SSAARenderPass(e,i,16777215,0);this.composer.addPass(s),this.ssaaRenderPass=s,this.ssaaRenderPass=s}this.ssaaRenderPass&&(this.ssaaRenderPass.enabled=t),this.viewer.enableRender()}}get bloomPassEnabled(){return!!this.bloomPass?.enabled}set bloomPassEnabled(t){if(this.composer){if(t&&!this.bloomPass){const e=new ac.BloomPass(1,25,4);e.renderToScreen=!0,this.composer.addPass(e),this.bloomPass=e}this.bloomPass&&(this.bloomPass.enabled=t),this.viewer.enableRender()}}get unrealBloomPassEnabled(){return!!this.unrealBloomPass?.enabled}set unrealBloomPassEnabled(t){const{width:e,height:i}=this.viewer.container;if(this.composer){if(t&&!this.unrealBloomPass){const s=new oc.UnrealBloomPass(new p.Vector2(e,i),1,0,0);s.threshold=0,s.strength=.5,s.radius=0,this.composer.addPass(s),this.unrealBloomPass=s}this.unrealBloomPass&&(this.unrealBloomPass.enabled=t),this.viewer.enableRender()}}setOutlinePassSelectObjects(t){this.outlinePass&&(this.outlinePass.selectedObjects=t)}enableModelEdges(t){const e=this.viewer.loadedModels;for(let i=0;i<e.length;++i){const s=e[i];if(s instanceof Dr)if(t&&!s.edges){const n=s.getModelObject();n&&(P.debug("[Viewer] Generating outlines for model '"+n.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(n=>n.visible=t);else s instanceof Rr&&P.warn("[BimTiles] enableModelEdges() is not implemented for bimtiles yet.")}this.viewer.enableRender()}showVertexNormals(t,e=.1){t?(!this.vertexNormalsHelpers&&(this.vertexNormalsHelpers=new p.Group),this.viewer.scene.traverseVisible(i=>{const s=["SKYBOX","GROUND_GRID","GROUND_GRASS","BIM_VIEWER_BOX_HELPER"];if(i instanceof p.Mesh&&!s.includes(i.name)){if(!i.geometry.attributes.normal)return;const r=new cc.VertexNormalsHelper(i,e,16711680);this.vertexNormalsHelpers?.add(r)}}),this.viewer.scene.add(this.vertexNormalsHelpers)):this.vertexNormalsHelpers&&(this.viewer.scene.remove(this.vertexNormalsHelpers),this.vertexNormalsHelpers=void 0)}render(){!this.composer||!this.enabled||this.composer.render()}destroy(){this.renderPass&&(this.composer?.removePass(this.renderPass),this.renderPass.dispose(),this.renderPass=void 0),this.effectFxaaPass&&(this.composer?.removePass(this.effectFxaaPass),this.effectFxaaPass.dispose(),this.effectFxaaPass=void 0),this.saoPass&&(this.composer?.removePass(this.saoPass),this.saoPass.dispose(),this.saoPass=void 0),this.ssaoPass&&(this.composer?.removePass(this.ssaoPass),this.ssaoPass.dispose(),this.ssaoPass=void 0),this.outlinePass&&(this.composer?.removePass(this.outlinePass),this.outlinePass.dispose(),this.outlinePass=void 0),this.ssaaRenderPass&&(this.composer?.removePass(this.ssaaRenderPass),this.ssaaRenderPass.dispose(),this.ssaaRenderPass=void 0),this.bloomPass&&(this.composer?.removePass(this.bloomPass),this.bloomPass.dispose(),this.bloomPass=void 0),this.unrealBloomPass&&(this.composer?.removePass(this.unrealBloomPass),this.unrealBloomPass.dispose(),this.unrealBloomPass=void 0),this.composer&&(this.composer?.dispose(),this.composer=void 0)}}class Du extends Mn{constructor(e,i){super(e);g(this,"name");g(this,"loadedModels");g(this,"distanceCullingFactor");g(this,"selectedObject");g(this,"effect");if(this.name=Ke.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new gl(this),this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new p.Vector3(100,50,100),n=new p.Vector3(0,0,0),r={eye:s,look:n};this.cameraManager.flyToViewpoint(r)}this.cameraManager.setProjection(xt.Perspective),this.cameraManager.setNavigationMode(ot.Orbit),this.setupDefaultEvents(),this.setDefaultBackground()}setupDefaultEvents(){let e=!1,i,s=0,n=0,r=0;const a=300,o=u=>n===-1||r===-1?!1:Math.abs(u.x-n)<5&&Math.abs(u.y-r)<5,l=u=>{const f=u.timestamp-s;return!!(u.button===$e.Left&&f<a&&o(u))};let h,d=!1;this.inputManager.addEventListener("pointerdown",u=>{e=!1,i=u.button;const f=new p.Vector2(u.x,u.y);h=this.pickObject(f),d=h?.object===this.selectedObject,u.button===$e.Left&&this.handleAnchorPoint(h)}),this.inputManager.addEventListener("pointermove",u=>{i!==void 0&&(e=!o(u),i===$e.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0))}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===$e.Left?l(u)?(h?.object?this.flyToObject(h.object):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.selectedObject instanceof Ht?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h?.object&&!d&&this.handleClickObject(h.object)):(u.button,$e.Right)})}setDefaultBackground(){this.sceneManager.renderer.setClearColor(11119017,1),this.sceneManager.setBackground(null),this.sceneManager.setEnvironmentFromData()}handleAnchorPoint(e){const i=new p.Vector3;this.selectedObject?new p.Box3().setFromObject(this.selectedObject).getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=r=>!r.userData.modelId&&r.parent?i(r.parent):r.userData.modelId,s=i(e);this.loadedModels.find(r=>r.modelId===s)?.highlightObject(e),this.selectedObject=e,this.enableRender()}is3d(){return!0}async loadLocalModel(e,i,s,n){return this.loadModelInternal(i,n,!0,e,s)}async loadModel(e,i){return this.loadModelInternal(e,i)}async loadModelInternal(e,i,s,n,r){this.spinner.increaseJobCount();const a=e.modelId||e.src,o=Qe.t("ProgressBar.Loading"),l=x=>{this.progressBar?.updateProgress(a,o,x),i?.(new ProgressEvent("LoadProgress",{loaded:x,total:100}))};let h=!1;const d=(x,E,M)=>{let O=x.loaded*100/x.total;O=O*(M-E)/100+E,O>M&&(h||(P.warn("[Progress] Invalid ProgressEvent:",x),h=!0),O=M),this.progressBar?.updateProgress(a,o,O),i?.(new ProgressEvent("LoadProgress",{loaded:O,total:100}))},u=x=>d(x,0,50);this.progressBar?.addProgressItem(a),l(0);let f;if(s?(this.loaderHelper.setLoadManager(r),f=await this.loaderHelper.loadLocalModel(n,e.src,i)):f=await this.loaderHelper.loadModel(e.src,e.fileFormat,u),e.matrix&&e.matrix.length===16){const x=new p.Matrix4;x.elements=e.matrix,f.applyMatrix4(x)}const m=this.getUniqueModelId(e.modelId||e.src),b=new Dr({modelId:m,object:f});this.addModel(b),l(90);const y=b.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const w=new p.Vector3;y.getCenter(w),this.cameraManager.setOrbitPoint(w),this.spinner.decreaseJobCount(),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(le.ModelLoad)}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(n=>n.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function go(c){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),c)}function yo(c){return Object.assign(Object.assign({},{elementCount:0,batchElementCount:0,instanceElementCount:0,batchCount:0,instanceCount:0,tileCount:0,userDataCount:0,materialCount:0,meshVertexCount:0,meshFaceCount:0,textureCount:0,texturePixels:0}),c)}function Lu(c){const t={transform:new p.Matrix4,boundingVolume:new p.Box3};return Object.assign(Object.assign({},t),c)}class Ru{constructor(t){g(this,"url");g(this,"metadata");g(this,"statistics");g(this,"view");this.url=t,this.metadata=go(),this.statistics=yo(),this.view=Lu()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(P.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=go(t.metadata),this.statistics=yo(t.statistics),t.view.transform&&t.view.transform.length===16&&this.view.transform.fromArray(t.view.transform),t.view.boundingVolume&&t.view.boundingVolume.length===6&&this.view.boundingVolume.setFromArray(t.view.boundingVolume),Promise.resolve(!0)))}getMetadata(){return this.metadata}getStatistics(){return this.statistics}getView(){return this.view}}let Fu=0;class zu extends Mn{constructor(e,i){super(e);g(this,"name");g(this,"pickUsageScene");g(this,"effect");g(this,"loadedModels");g(this,"selectedObject");g(this,"enableHoverEffect");if(this.name=Ke.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new gl(this),this.pickUsageScene=new p.Scene,this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new p.Vector3(100,50,100),n=new p.Vector3(0,0,0),r={eye:s,look:n};this.cameraManager.flyToViewpoint(r)}this.cameraManager.setProjection(xt.Perspective),this.cameraManager.setNavigationMode(ot.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(le.BeforeRender,()=>{this.update3dTiles()})}setupDefaultEvents(){let e=!1,i,s=0,n=0,r=0;const a=300,o=u=>n===-1||r===-1?!1:Math.abs(u.x-n)<5&&Math.abs(u.y-r)<5,l=u=>{const f=u.timestamp-s;return!!(u.button===$e.Left&&f<a&&o(u))};let h,d=!1;this.inputManager.addEventListener("pointerdown",u=>{e=!1,i=u.button,this.renderImmediately();const f=new p.Vector2(u.x,u.y);if(h=this.pickManager.pick(f,this.pickUsageScene),d=!!this.selectedObject&&h?.tilesetId===this.selectedObject?.tilesetId&&h?.userId===this.selectedObject?.userId,u.button===$e.Left){let m=this.pickUsageScene;if(h){const y=this.loadedModels.find(C=>C.modelId===""+h?.tilesetId);if(y){const C=y.getObjectByUserId(h.userId);C&&(m=C)}}const b=this.pickManager.pickObject(f,[m]);this.handleAnchorPoint(b)}}),this.inputManager.addEventListener("pointermove",u=>{if(i!==void 0)e=!o(u),i===$e.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0);else if(this.enableHoverEffect){const f=new p.Vector2(u.x,u.y),m=this.pickManager.pick(f,this.pickUsageScene),b=this.getHoveredObject();m?(!b||b.tilesetId!==m.tilesetId||b.userId!==m.userId)&&this.setObjectHoveredByUserId(m.tilesetId,m.userId,!0):b&&this.clearHovered()}this.handleMouseMove(u)}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===$e.Left?l(u)?(h?this.flyToUserId(h.tilesetId,h.userId):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h&&!d&&this.handleClickObject(h)):(u.button,$e.Right)})}setDefaultBackground(){this.sceneManager.setBackground(new p.Color(11119017)),this.sceneManager.setEnvironmentFromData()}renderImmediately(){const{renderer:e,scene:i,camera:s}=this;!e||!i||!s||e.render(i,s)}handleAnchorPoint(e){const i=new p.Vector3;this.selectedObject?this.getBoxByUserId(this.selectedObject.tilesetId,this.selectedObject.userId)?.getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=this.loadedModels.find(s=>s.modelId===""+e.tilesetId);i&&(i?.setObjectHighlightedByUserIds([e.userId],!0),this.selectedObject=e),this.enableRender()}is3d(){return!0}setModelOpacity(e,i){this.loadedModels.find(n=>n.modelId===e)?.setOpacity(i),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}enableModelOutline(e,i){P.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){P.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(n=>n.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new Ru(e.src);if(!await s.parse())return Promise.reject();let r=e.src.replace(/\/[^\\/]*\/?$/,"/");r=new URL(r,window.location.href).toString(),this.spinner.increaseJobCount();const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Rr({modelId:""+Fu++,bbox:a},r,s),l=o.getTilesRenderer(),h=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=d=>{d.traverse(u=>{u.matrixAutoUpdate&&(u.matrixAutoUpdate=ct,u.updateMatrix()),u.isMesh&&(u.castShadow=!0,u.receiveShadow=!0),u.geometry&&u.layers.enableAll()}),this.enableRender(),setTimeout(()=>this.spinner.decreaseJobCount(),100)},l.setCamera(this.camera),l.setResolutionFromRenderer(this.camera,this.renderer),l.update(),h){h.applyMatrix4(s.getView().transform),o.pickUsageGroup.applyMatrix4(s.getView().transform),this.pickUsageScene.add(o.pickUsageGroup),this.addModel(o),this.cameraManager.adjustCameraByBBox(a);const d=new p.Vector3;return a.getCenter(d),this.cameraManager.setOrbitPoint(d),this.loadedModels.length===1&&this.goToHomeView(),this.spinner.decreaseJobCount(),this.dispatchEvent(le.ModelLoad),Promise.resolve()}return this.spinner.decreaseJobCount(),Promise.reject()}setObjectHighlightedByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectHighlightedByUserIds(i,s),this.enableRender()}setObjectOpacityByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectOpacityByUserIds(i,s),this.enableRender()}setOtherObjectOpacityByUserIds(e,i,s){this.loadedModels.forEach(a=>{a.setOpacity(s)});const n=""+e;this.loadedModels.find(a=>a.modelId===n)?.clearObjectOpacityByUserIds(i),this.enableRender()}setObjectVisibleByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectVisibleByUserIds(i,s),this.enableRender()}setOtherObjectVisibleByUserIds(e,i,s){this.loadedModels.forEach(r=>{r.setVisible(s)}),this.loadedModels.find(r=>r.modelId===""+e)?.setObjectVisibleByUserIds(i,!s),this.enableRender()}setObjectHoveredByUserId(e,i,s){if(!this.enableHoverEffect)return;this.clearHovered(),this.loadedModels.find(r=>r.modelId===""+e)?.setObjectHoveredByUserId(i,s),this.enableRender()}getHoveredObject(){for(const e of this.loadedModels){const i=e.getHoveredObject();if(i)return i}}clearHovered(){this.loadedModels.forEach(e=>e.clearHovered()),this.enableRender()}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(!i),this.sceneManager.setClipPlanes(e)}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}pickObjects(e,i){const s=this.pickManager.pick(e,this.pickUsageScene);let n=this.pickUsageScene;if(s){const a=this.loadedModels.find(o=>o.modelId===""+s?.tilesetId);if(a){const o=a.getObjectByUserId(s.userId);o&&(n=o)}}let r=this.pickManager.pickObjects(e,[n],i);return r&&this.renderer.clippingPlanes.length>0&&(r=r.filter(a=>this.renderer.clippingPlanes.every(function(o){return o.distanceToPoint(a.point)>0}))),r}getErrorTarget(){return this.loadedModels.length>0?this.loadedModels[0].getTilesRenderer().errorTarget:8}setErrorTarget(e){this.loadedModels.forEach(i=>{i.getTilesRenderer().errorTarget=e})}}class Vu extends Nt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();g(this,"id");g(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}$.install({THREE:p});class ju extends ${constructor(e,i){super(e,i);g(this,"minZoom");g(this,"draggingSmoothTime");g(this,"dollySpeedBackup");g(this,"azimuthRotateSpeedBackup");g(this,"polarRotateSpeedBackup");g(this,"truckSpeedBackup");g(this,"onKeyDown");g(this,"onKeyUp");g(this,"keyTruckSpeed");g(this,"keys");this.minZoom=0,this.draggingSmoothTime=0,this.keyTruckSpeed=7,this.keys={left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",bottom:"ArrowDown"},this.onKeyDown=s=>{if(this.enabled){switch(s.code){case this.keys.up:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,1),this._isUserControllingRotate=!0):(this._truckInternal(0,this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.bottom:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,-1),this._isUserControllingRotate=!0):(this._truckInternal(0,-this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.left:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(1,0),this._isUserControllingRotate=!0):(this._truckInternal(this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break;case this.keys.right:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(-1,0),this._isUserControllingRotate=!0):(this._truckInternal(-this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break}this.dispatchEvent({type:"control"})}},this.onKeyUp=s=>{this.dispatchEvent({type:"controlend"})},this._getClientRect(this._elementRect),this.dollySpeedBackup=this.dollySpeed,this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.truckSpeedBackup=this.truckSpeed}get enableZoom(){return!!this.dollySpeed}set enableZoom(e){e?this.dollySpeed=this.dollySpeedBackup:(this.dollySpeedBackup=this.dollySpeed,this.dollySpeed=0)}get enableRotate(){return!!this.azimuthRotateSpeed||!!this.polarRotateSpeed}set enableRotate(e){e?(this.azimuthRotateSpeed=this.azimuthRotateSpeedBackup,this.polarRotateSpeed=this.polarRotateSpeedBackup):(this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.azimuthRotateSpeed=0,this.polarRotateSpeed=0)}get enableTruck(){return!!this.truckSpeed}set enableTruck(e){e?this.truckSpeed=this.truckSpeedBackup:(this.truckSpeedBackup=this.truckSpeed,this.truckSpeed=0)}listenToKeyEvents(){this._domElement?.addEventListener("keydown",this.onKeyDown),this._domElement?.addEventListener("keyup",this.onKeyUp)}stopListenToKeyEvents(){this._domElement?.removeEventListener("keydown",this.onKeyDown),this._domElement?.removeEventListener("keyup",this.onKeyUp)}dispose(){super.dispose(),this.stopListenToKeyEvents()}}var yl=(c=>(c[c.Browser=0]="Browser",c[c.Browserless=1]="Browserless",c[c.Headless=2]="Headless",c))(yl||{});class Uu{constructor(t,e,i){g(this,"containerOrCanvas");g(this,"glContext");g(this,"camera");g(this,"scene");g(this,"renderer");g(this,"renderTarget");g(this,"controls");g(this,"selectedObject");g(this,"loadedModels");g(this,"pmremGenerator");g(this,"clock");g(this,"viewerMode");g(this,"raycaster");g(this,"savedMaterialsForOpacity");g(this,"jobCount");g(this,"bbox");g(this,"outlineMaterial");g(this,"outlineRoot");g(this,"transparentObjectIds");g(this,"requestAnimationFrameHandle");g(this,"applyOptionsAndAddToScene");g(this,"getMeshes");if(this.scene=this.initScene(),this.selectedObject=void 0,this.loadedModels=[],this.clock=new p.Clock,this.viewerMode=0,this.raycaster=new p.Raycaster,this.savedMaterialsForOpacity=[],this.jobCount=0,this.bbox=new p.Box3,this.outlineMaterial=new p.LineBasicMaterial({color:1118481}),this.outlineRoot=new p.Group,this.transparentObjectIds=[],this.applyOptionsAndAddToScene=async(s,n,r,a)=>{if(P.info("[Viewer] '"+s+"' is loaded, adding to scene..."),r.matrix&&r.matrix.length===16){const u=new p.Matrix4;u.elements=r.matrix,n.applyMatrix4(u)}n.traverse(u=>{u.geometry&&u.layers.enableAll(),u instanceof p.Light&&(u.visible=!1)});let o;r.edges&&(o=await J.createOutlines(n,void 0,a));let l=r.modelId||r.src;const h=u=>!!this.loadedModels.find(f=>f.modelId===u);if(h(l)){let u=1;for(;h(l+"_"+u);)u++;l=l+"_"+u,P.warn("[Viewer] Model '"+l+"' is loaded more than once!")}const d={modelId:l,object:n,edges:o};this.addModel(d)},this.getMeshes=s=>{const n=[];return s instanceof p.Mesh?n.push(s):s.traverseVisible(r=>{r instanceof p.Mesh&&n.push(r)}),n},this.containerOrCanvas=t,e&&(this.viewerMode=e),this.glContext=i,this.viewerMode===1&&!(!(t instanceof HTMLDivElement)&&i))throw new Error("[Viewer] Parameters don't match Browserless viewerMode !");this.increaseJobCount(),this.init(),this.decreaseJobCount(),P.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new p.Scene;return t.background=new p.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});const i=new p.WebGLRenderer(t);if(e){const s=this.containerOrCanvas.width,n=this.containerOrCanvas.height;P.info("[Viewer] Render target size: "+s+" x "+n),this.renderTarget=new p.WebGLRenderTarget(s,n,{minFilter:p.LinearFilter,magFilter:p.NearestFilter,format:p.RGBAFormat,type:p.UnsignedByteType}),i.setRenderTarget(this.renderTarget)}else{const s=this.containerOrCanvas.clientWidth,n=this.containerOrCanvas.clientHeight;this.containerOrCanvas.append(i.domElement),i.setPixelRatio(window.devicePixelRatio),i.setSize(s,n)}i.outputColorSpace=p.SRGBColorSpace,i.toneMappingExposure=1,i.setClearColor(11119017,1),i.shadowMap.enabled=!0,i.shadowMap.type=p.PCFSoftShadowMap,this.renderer=i,e||(this.pmremGenerator=new p.PMREMGenerator(i),this.pmremGenerator.compileEquirectangularShader(),this.setEnvironmentFromDataArray())}initCamera(){if(!this.scene)return;const t=this.containerOrCanvas.clientWidth||this.containerOrCanvas.width||0,e=this.containerOrCanvas.clientHeight||this.containerOrCanvas.height||0;let i=1;t&&e&&(i=t/e),this.camera=new p.PerspectiveCamera(68,i,.05,1e4),this.camera.position.set(10,10,10),this.camera.lookAt(0,0,0),this.scene.add(this.camera)}initControls(){if(!this.renderer)return;const t=this.camera;if(!t)return;const e=new ju(t,this.renderer.domElement);e.smoothTime=.05,e.enabled=!0,e.keyTruckSpeed=10,e.keys={left:"KeyD",up:"KeyE",right:"KeyA",bottom:"KeyQ"},e.update(0),this.controls=e,e.addEventListener("update",()=>{!this.isBrowserMode()&&this.renderer&&this.renderer.render(this.scene,t)})}initLights(){if(!this.scene)return;const t=16777215,e=.3,i=new p.DirectionalLight(t,e);i.position.set(-2,2,4);const s=new p.AmbientLight(3158064),n=new p.HemisphereLight(t,14540253,3);n.position.set(0,300,0),this.scene.add(i),this.scene.add(s),this.scene.add(n)}initPointerEvents(){if(!this.renderer||!this.camera||!this.controls)return;let t=!1,e=!1,i=-1,s=-1;this.renderer.domElement.addEventListener("pointerdown",n=>{i=n.x,s=n.y,t=!1}),this.renderer.domElement.addEventListener("pointermove",n=>{i>=0&&s>=0&&(Math.abs(n.x-i)>5||Math.abs(n.y-s)>5)&&(t=!0)}),this.renderer.domElement.addEventListener("pointerup",()=>{e&&setTimeout(()=>{e=!1},200),i=-1,s=-1}),this.renderer.domElement.addEventListener("dblclick",n=>{e=!0,t||(this.handleMouseClick(n),this.flyToSelectedObject())})}animate(){this.isBrowserMode()&&requestAnimationFrame(this.animate.bind(this));const t=this.clock.getDelta();this.controls&&this.controls.update(t),this.scene&&this.camera&&this.renderer?.render(this.scene,this.camera)}destroy(){this.camera=void 0,this.scene&&this.scene.clear(),this.requestAnimationFrameHandle&&(cancelAnimationFrame(this.requestAnimationFrameHandle),this.requestAnimationFrameHandle=void 0),this.renderer&&(this.containerOrCanvas.removeChild(this.renderer.domElement),this.renderer.clear(),this.renderer.dispose(),this.renderer=void 0),this.controls&&(this.controls.dispose(),this.controls=void 0),this.renderTarget&&(this.renderTarget.dispose(),this.renderTarget=void 0),this.raycaster=void 0,this.selectedObject=void 0,this.savedMaterialsForOpacity=void 0,this.loadedModels=[]}async loadLocalModel(t,e,i){const n=await new Vt().loadLocalModel(t,e.src,i);return n?(await this.applyOptionsAndAddToScene(t,n,e),Promise.resolve()):Promise.reject()}async loadModel(t,e){this.increaseJobCount();const s=await new Vt().loadModel(t.src,t.fileFormat,e);return s?(await this.applyOptionsAndAddToScene(t.src,s,t),Promise.resolve()):Promise.reject()}parseGltf(t,e,i,s){this.increaseJobCount(),new Vt().parseGltf(t,e.src,n=>{this.applyOptionsAndAddToScene(e.src,n,e),i&&i(n)},n=>{s&&s(n)})}addModel(t){if(!this.scene||!this.renderer)return;this.increaseJobCount();const e=new p.Box3().setFromObject(t.object);t.bbox||(t.bbox=e),this.scene.add(t.object),this.loadedModels.push(t),this.computeBoundingBox(),this.loadedModels.length===1&&(this.tryAdjustCameraNearAndFar(),this.goToHomeView()),this.renderer.shadowMap.needsUpdate=!0,P.info("[Viewer] Added '"+t.modelId+"' to scene"),this.decreaseJobCount()}addOrRemoveObjectOpacity(t=!0,e=.3,i,s){if(this.savedMaterialsForOpacity||(this.savedMaterialsForOpacity=[]),!this.scene)return;const n=this.scene,r=[];this.loadedModels.forEach(a=>{const o=a.object.id;if(t){this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0&&J.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity);const l=J.setObjectOpacityById(n,o,e,i,s);r.push(...l)}else this.savedMaterialsForOpacity&&J.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity)}),t?this.savedMaterialsForOpacity=r:this.savedMaterialsForOpacity=[]}hasTransparentObject(){return!!(this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0)}getIntersections(t){if(!this.raycaster||!this.camera||!this.scene)return[];let e=new p.Vector2;t&&(e=Ee.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=Ee.screen2Ndc(e,this.camera,this.containerOrCanvas);this.raycaster.setFromCamera(i,this.camera);const s=[];return this.loadedModels.forEach(n=>{const r=n.object;r&&r.visible&&s.push(r)}),this.raycaster.intersectObjects(s,!0)||[]}handleMouseClick(t){this.raycaster&&this.raycaster.layers.set(Ut);const i=this.getIntersections(t).find(n=>{const r=n.object;return r.visible&&r instanceof p.Mesh});let s=i&&i.object||void 0;s&&this.selectedObject&&this.selectedObject.id===s.id&&(s=void 0),s?this.selectObject(s):this.clearSelection()}selectObject(t){if(this.selectedObject){const i=this.selectedObject.userData;if(i.originalMaterial){if(this.selectedObject.material){const s=this.selectedObject.material;Array.isArray(s)?s.forEach(n=>n.dispose()):s instanceof p.Material&&s.dispose()}this.selectedObject.material=i.originalMaterial,delete i.originalMaterial}this.selectedObject=void 0}if(!this.scene||!t)return;const e=xe.clonedHighlightMaterials(t);e&&(this.selectedObject=t,this.selectedObject.userData.originalMaterial=this.selectedObject.material,this.selectedObject.material=e)}clearSelection(){this.selectObject()}flyToObjects(t){if(!t||t.length===0||!this.camera)return;const e=new p.Box3;t.forEach(n=>{const r=Ot.getBoundingBox(n);e.union(r)});const i=new p.Sphere;e.getBoundingSphere(i),this.controls?.fitToSphere(i,!0)}flyToObject(t){this.flyToObjects([t])}flyToSelectedObject(){this.selectedObject&&this.flyToObject(this.selectedObject)}flyTo(t,e,i){const s=this.camera,n=this.controls;if(!s||!n)return;t=Array.isArray(t)?new p.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new p.Vector3(e[0],e[1],e[2]):e;const r=t,a=e;P.info("[Viewer] flyTo: ",j.vectorToString(r)),n.setPosition(r.x,r.y,r.z),n.setTarget(a.x,a.y,a.z),this.isBrowserMode()||this.renderer?.render(this.scene,s),i&&i()}goToHomeView(){const t=new p.Sphere;this.bbox.getBoundingSphere(t),this.controls?.fitToSphere(t,!0)}setEnvironmentFromDataArray(t){ms.createEnvTextureFromDataArray(this.pmremGenerator,t).then(e=>{this.scene.environment=e,this.isBrowserMode()||this.animate()})}tryAdjustCameraNearAndFar(){const t=this.camera;if(!this.scene||!t)return;const e=this.bbox,i=t.near,s=t.far,n=e.max.x-e.min.x,r=e.max.y-e.min.y,a=e.max.z-e.min.z,o=Math.max(n,r,a),l=5,h=o/l,d=o*l;if(i>h||s<d){const u=f=>j.numberToString(f);P.info("[Viewer] BBox's longest side is: "+u(o)),i>h&&(P.warn("[Viewer] camera.near("+u(i)+") shouldn't bigger than "+u(h)+", will change it!"),t.near=h),s<d&&(P.warn("[Viewer] camera.far("+u(s)+") shouldn't smaller than "+u(d)+", will change it!"),t.far=d)}t.updateProjectionMatrix()}isolateObjects(t){const e=this.transparentObjectIds.length>0?void 0:this.transparentObjectIds,i=this.transparentObjectIds.length>0?this.transparentObjectIds:void 0,s=new p.MeshBasicMaterial({color:16777215,transparent:!0,opacity:.1});this.loadedModels.forEach(r=>{const a=r.object.id;J.applyMaterialToObjectById(this.scene,a,s,i,e)}),this.outlineRoot.clear();let n=[];if(t.forEach(r=>{const a=r.modelId;let l=this.loadedModels.find(h=>h.modelId===a)?.object;l||(P.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(h=>{if(Ur.includes(r.id,Ur.get(h.userData,"UniqueId"))){const d=this.getMeshes(h);n=n.concat(d)}})}),n.length>0){n.forEach(a=>{const o=J.createOutline(a.geometry,this.outlineMaterial);o.applyMatrix4(a.matrixWorld),this.outlineRoot.add(o),o.updateWorldMatrix(!0,!1)});const r=n.map(a=>a.id);this.loadedModels.forEach(a=>{const o=a.object.id;J.revertAppliedMaterialToObjectById(this.scene,o,r)}),this.transparentObjectIds=r,this.flyToObjects(n)}else P.warn("[Viewer] No object found with uniqueIds: "+t.map(r=>r.id));this.isBrowserMode()||this.animate()}increaseJobCount(){++this.jobCount}decreaseJobCount(){--this.jobCount}computeBoundingBox(){const t=new p.Box3;return this.loadedModels.forEach(e=>{e.bbox&&!e.bbox.isEmpty()&&t.union(e.bbox)}),this.bbox=t,t}getContext(){return this.renderer?.getContext()}getCameraDirection(){const t=new p.Vector3;return this.camera?.getWorldDirection(t),{x:t.x,y:t.y,z:t.z}}setFov(t){this.camera&&(this.camera.fov=t,this.camera.updateProjectionMatrix())}}const xl="1.0.0",bl="VERSION",wl=()=>window.localStorage.getItem(bl),vl=()=>{window.localStorage.setItem(bl,xl)},Hu=()=>wl()!==xl?(vl(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>D.Mesh});exports.BaseDxfCompareHelper=pl;exports.BaseViewer=Mn;exports.BimTilesModel=Rr;exports.BimTilesRenderer=Qo;exports.BimTilesViewer=zu;exports.BinaryReader=vs;exports.BoxSelectHelper=xn;exports.ByBlock=gs;exports.ByLayer=kr;exports.CSS2DObjectUtils=Lh;exports.CameraProjection=xt;exports.CancelablePromise=Bh;exports.CanvasRender=bs;exports.ColorUtils=Li;exports.CommonUtils=j;exports.CompareDrawable=bt;exports.Container=Fr;exports.ControlsMode=ot;exports.CoordinateUtils=Ee;exports.DecimalPrecisionRange=So;exports.DefaultCameraFar=ln;exports.DefaultCameraFov=_o;exports.DefaultCameraNear=on;exports.DefaultLanguage=Eo;exports.DefaultOpacity=Ir;exports.DefaultViewer3dConfig=su;exports.DeviceUtils=Be;exports.Drawable=Ht;exports.DrawableList=ws;exports.DxfChangeType=Ve;exports.DxfCompare=at;exports.DxfCompareHelper=Bu;exports.DxfCompareMarkupManager=Mr;exports.DxfLoader=X;exports.DxfParser=Ho;exports.DxfRenderOrder=Oe;exports.DxfUtils=Mt;exports.EdgeUtils=Po;exports.Event=Nt;exports.ExportUtils=yr;exports.FontManager=yt;exports.FpsUtils=Nh;exports.GenerateMeshBvhWorker=ll;exports.GeometryUtils=N;exports.GroundPlaneRenderOrder=fl;exports.HighlightColor=Ar;exports.HighlightColorRgba=Fh;exports.IconfontClass=zh;exports.IconfontClass2=Vh;exports.InputManager=ul;exports.InstantiateHelper=du;exports.LayerForHitableObjects=Oo;exports.LayerForSelectableObjects=Ut;exports.LayerForSnapableObjects=je;exports.Line=uc;exports.LinePatternShaders=zo;exports.LoadingHelper=Vt;exports.MaterialUtils=xe;exports.MathUtils=z;exports.MatrixAutoUpdate=ct;exports.MergeUtils=fe;exports.MeshBvhHelper=Vr;exports.MobileTouchHelperDrawable=_u;exports.Model=vn;exports.Model2d=Ri;exports.Model3d=Dr;exports.NestedCompareTypes=os;exports.OSnapHelper=Tu;exports.OSnapIconSize=Qh;exports.OSnapMarkerType=St;exports.OSnapType=cl;exports.ObjectPixelSizeHelper=gu;exports.ObjectUtils=J;exports.Offset=ku;exports.OrbitControls=il;exports.OutlineColorRgba=an;exports.PickMarkupHelper=Cu;exports.PlanControls=sl;exports.Plugin=Vu;exports.Points=mh;exports.PolygonUtils=$h;exports.ProgressBar=zr;exports.RafHelper=al;exports.SVGObjectUtils=ed;exports.SceneUtils=Ot;exports.SectionUtils=zt;exports.ShaderChunk=Ih;exports.SimplifyUtils=Jh;exports.SnapDrawable=_e;exports.Spinner=el;exports.TextSearchHelper=Tr;exports.TextureUtils=ms;exports.ThresholdAngleForEdge=Br;exports.UnitConversionByMeter=br;exports.UnitLabels=Ao;exports.UnitScaleConversion=md;exports.UnitScaleToMeter=vr;exports.Units=Ze;exports.Viewer2d=jr;exports.Viewer3d=Du;exports.Viewer3dLite=Uu;exports.Viewer3dUtils=sd;exports.ViewerEvent=le;exports.ViewerMode=yl;exports.ViewerName=Ke;exports.Views=Bo;exports.ZoomToRectHelper=dl;exports.bspline=Do;exports.checkIsNewVersion=Hu;exports.cn=xr;exports.createHatchPatternShaderMaterial=Vo;exports.decodeDxfTextCharacterCodes=Lo;exports.decodeDxfTextMbcsCharacterCodes=Fo;exports.decodeDxfTextUnicodeCodePoints=Ro;exports.en=Wh;exports.getLengthValueByUnit=id;exports.getUnitStr=wr;exports.getVersionFromLocalStorage=wl;exports.i18n=Qe;exports.log=P;exports.parseDxfMTextContent=ls;exports.parseDxfTextContent=cn;exports.round10=ko;exports.setIcon=Dh;exports.setLogLevel=Co;exports.setVersionToLocalStorage=vl;exports.showPrecisionValue=Rh;
1531
+ `,Qo=Symbol("INITIAL_FRUSTUM_CULLED");function Q1(c,t){c.traverse(e=>{e.frustumCulled=e[Qo]&&t})}const Ws=new p.Vector3,Ys=new p.Vector3,Zn=new p.Box3;class el extends jl.TilesRenderer{constructor(e,i){super(e);g(this,"highlighUsage");g(this,"transparentUsage");g(this,"pickUsage");g(this,"materialManager");g(this,"baseUrl");g(this,"propertyParser");g(this,"tilesetId");g(this,"onBeforeParseTile");g(this,"protoRoot");this.downloadQueue.maxJobs=6,this.parseQueue.maxJobs=4,this.optimizeRaycast=!1,this.errorTarget=8,this.loadSiblings=!1,this.tilesetId=i,this.baseUrl=e.replace(/\/[^\\/]*\/?$/,"/"),this.highlighUsage=new p.Group,this.highlighUsage.name="highlighUsage-"+this.tilesetId,this.group.add(this.highlighUsage),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.tilesetId,this.group.add(this.transparentUsage),this.pickUsage=new p.Group,this.protoRoot=uc.parse(J1).root,this.propertyParser=new X1(this.baseUrl,this.protoRoot)}getVertexColorArray(e,i=new p.Color(16777215)){const s=[],{r:n,g:r,b:a}=i;for(let o=0;o<e;o+=3)s.push(n,r,a);return new Float32Array(s)}createBatchedMesh(e){const{position:i,uv:s,normal:n,indice:r,barycentric:a,userIds:o,materialId:l,batchTable:h}=e;let d=e.color;const u=o.map(x=>Xa(this.tilesetId,x)),f=new p.BufferGeometry;f.setAttribute("position",new p.Float32BufferAttribute(i,3)),f.setAttribute("normal",new p.Float32BufferAttribute(n,3)),f.setAttribute("uv",new p.Float32BufferAttribute(s,2)),f.setAttribute("tileObjectId",new p.Int32BufferAttribute(u,1)),f.setIndex(Array.from(r));const m=this.propertyParser.getMaterialParameters(l);d.length===0&&(d=this.getVertexColorArray(i.length,m?.color)),f.setAttribute("color",new p.Float32BufferAttribute(d,3));const b=a.length>0;b&&f.setAttribute("barycentric",new p.BufferAttribute(a,1));const y=this.materialManager?.createBatchMaterial(l,m,b),C=new p.Mesh(f,y),w=new p.Mesh(f,this.materialManager?.pickMaterial);return{mesh:C,pickMesh:w,batchTable:h}}createInstancedMesh(e){const{position:i,uv:s,color:n,normal:r,indice:a,barycentric:o,matrices:l,userIds:h,materialId:d}=e,u=h.map(M=>Xa(this.tilesetId,M)),f=h.length,m=new p.BufferGeometry;m.setIndex(Array.from(a)),m.setAttribute("position",new p.Float32BufferAttribute(i,3)),m.setAttribute("uv",new p.Float32BufferAttribute(s,2)),m.setAttribute("normal",new p.Float32BufferAttribute(r,3)),m.setAttribute("tileObjectId",new p.InstancedBufferAttribute(new Int32Array(u),1));const b=o.length>0;b&&m.setAttribute("barycentric",new p.BufferAttribute(o,1));const y=this.propertyParser.getMaterialParameters(d),C=this.materialManager?.createInstanceMaterial(d,y,b),w=new p.InstancedMesh(m,C,f);w.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16);let x=n;x.length===0&&(x=this.getVertexColorArray(f*3,y?.color)),w.instanceColor=new p.InstancedBufferAttribute(x,3);const E=new p.InstancedMesh(m,this.materialManager?.pickMaterial,f);return E.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16),{mesh:w,pickMesh:E,userIds:h}}getGeometryByUserIds(e){const i=Date.now(),s=[];return this.visibleTiles.forEach(n=>{const r=n.cached.scene.children;for(let a=0;a<r.length;a++){const o=r[a];if(!o||o.sourceMesh)continue;const l=o.userData.userIds;if(l)for(let h=0;h<e.length;h++){const d=e[h],u=l.indexOf(d);if(u>-1){const f=new p.BufferGeometry,m=o.geometry.getAttribute("position"),b=o.geometry.index,y=o.geometry.getAttribute("tileObjectId");if(o instanceof p.InstancedMesh){const C=new p.Matrix4;o.getMatrixAt(u,C),f.setAttribute("position",m.clone());const w=y.array[u*y.itemSize];f.setAttribute("tileObjectId",new p.Int32BufferAttribute(new Array(m.array.length/3).fill(w),1)),b&&f.setIndex(b),f.applyMatrix4(C)}else{const{indexStart:C,indexCount:w,positionStart:x,positionCount:E}=o.userData.batchTable.find(_=>_.userId===d),M=m.itemSize,O=m.array.slice(x*M,x*M+E*M),S=new p.Float32BufferAttribute(O,M);f.setAttribute("position",S);const v=y.array.slice(x,x+E),T=new p.Int32BufferAttribute(v,1);if(f.setAttribute("tileObjectId",T),b){const _=b.array.slice(C,C+w);for(let A=0;A<_.length;A++)_[A]-=x;f.setIndex(new p.BufferAttribute(_,1))}}f.applyMatrix4(o.matrixWorld),s.push(f)}}}}),P.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?Pe.mergeGeometries(s):s[0]}parseTile(e,i,s){this.onBeforeParseTile&&this.onBeforeParseTile(i),i._loadIndex=i._loadIndex||0,i._loadIndex++;const n=i.cached,r=n.transform;return new $1().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{P.debug("[BimTiles] batchedMeshes:",o),P.debug("[BimTiles] instancedMeshes:",l);const h=new p.Group;h.name="TileGroup";const d=new p.Group;d.name="TileGroup-pick",o.forEach(f=>{const{mesh:m,pickMesh:b,batchTable:y}=this.createBatchedMesh(f);h.add(m),m.userData.batchTable=y,m.userData.userIds=y.map(C=>C.userId),d.add(b)}),l.forEach(f=>{const{mesh:m,pickMesh:b,userIds:y}=this.createInstancedMesh(f);h.add(m),m.userData.userIds=y,d.add(b)});const u=f=>{f.applyMatrix4(r)};u(h),h.traverse(f=>{f[Qo]=f.frustumCulled}),Q1(h,!this.autoDisableRendererCulling),u(d),n.scene=h,n.pickScene=d,this.onLoadModel&&this.onLoadModel(h,i)})}disposeTile(e){const i=e.cached;if(i.scene){const s=n=>{n.traverse(r=>{r.geometry&&r.geometry.dispose()}),n.removeFromParent()};s(i.scene),i.pickScene&&s(i.pickScene),this.onDisposeModel&&this.onDisposeModel(i.scene,e),i.scene=null,i.pickScene=null,i.materials=null,i.textures=null,i.geometry=null}this.activeTiles.delete(e),this.visibleTiles.delete(e),e._loadIndex++}preprocessNode(e,i,s){super.preprocessNode(e,i,s),Array.isArray(e.boundingVolume)&&(Zn.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(Zn.getCenter(Ws),Zn.getSize(Ys),e.cached.boundingVolume.setObbData([Ws.x,Ws.y,Ws.z,Ys.x/2,0,0,0,Ys.y/2,0,0,0,Ys.z/2],e.cached.transform)))}async fetchTileSet(e,i,s){return fetch(e,i).then(n=>{if(n.ok)return n.json();throw new Error('BimTilesRenderer: Failed to load tileset "'+e+'" with status '+n.status+" : "+n.statusText)}).then(async n=>{const{material:r,userData:a,userId:o,userIdBox:l}=n.properties,h=[];if(r.url){const u=this.propertyParser.getProperty(r.url,i,"PBMaterials").then(f=>this.propertyParser.parseMaterial(f));h.push(u)}if(a.url){const u=this.propertyParser.getProperty(a.url,i,"PBUserData").then(f=>this.propertyParser.parseUserData(f));h.push(u)}if(o.url){const u=this.propertyParser.getProperty(o.url,i,"PBUserId").then(f=>this.propertyParser.parseUserId(f));h.push(u)}if(l.url){const u=this.propertyParser.getProperty(l.url,i,"PBUserIdBox").then(f=>this.propertyParser.parseUserIdBox(f,this.group.matrix));h.push(u)}await Promise.all(h);let d=e.replace(/\/[^\\/]*\/?$/,"");return d=new URL(d,window.location.href).toString(),this.preprocessNode(n.root,d,s),this.onLoadTileSet&&Promise.resolve().then(()=>{this.onLoadTileSet(n)}),n})}loadRootTileSet(e){const i=this.tileSets;if(e in i)return i[e]instanceof Error?Promise.reject(i[e]):Promise.resolve(i[e]);{const s=this.fetchTileSet(this.preprocessURL?this.preprocessURL(e):e,this.fetchOptions).then(n=>{i[e]=n,this.materialManager=new q1(this,{maxId:n.properties.userId.maxUserIdIndex})});return s.catch(n=>{P.error("[BimTiles] loadRootTileSet error:",n),i[e]=n}),i[e]=s,s}}update(){super.update()}setTileVisible(e,i){const{scene:s,pickScene:n}=e.cached,r=this.visibleTiles,a=this.group;i?(r.add(e),a.add(s),this.pickUsage.add(n),s.updateMatrixWorld(!0),n.updateMatrixWorld(!0)):(r.delete(e),a.remove(s),this.pickUsage.remove(n)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,i)}calculateError(e){const i=e.cached,s=i.inFrustum,n=this.cameras,r=this.cameraInfo,a=i.boundingVolume;let o=-1/0,l=1/0;for(let h=0,d=n.length;h<d;h++){if(!s[h])continue;const u=r[h],f=u.invScale;let m;if(u.isOrthographic){const b=u.pixelSize;m=e.geometricError/(b*f)}else{const b=a.distanceToPoint(u.position),y=b*f,C=u.sseDenominator;m=e.geometricError/(y*C),l=Math.min(l,y)}o=Math.max(o,m)}e.__distanceFromCamera=l,e.__error=o}}class Lr extends vn{constructor(e,i,s){super();g(this,"modelId");g(this,"_bbox");g(this,"tilesRenderer");g(this,"metadata");g(this,"statistics");this.modelId=e.modelId;const n=i+s.getMetadata().root;this.tilesRenderer=new el(n,Number(this.modelId)),this._bbox=e.bbox,this.metadata=s.getMetadata(),this.statistics=s.getStatistics()}getTilesRenderer(){return this.tilesRenderer}get materialManager(){return this.tilesRenderer.materialManager}get propertyParser(){return this.tilesRenderer.propertyParser}get highlighUsageGroup(){return this.tilesRenderer.highlighUsage}get transparentUsageGroup(){return this.tilesRenderer.transparentUsage}get pickUsageGroup(){return this.tilesRenderer.pickUsage}getModelObject(){return this.tilesRenderer.group}traverseObjectByUserId(e,i){if(i.userData.userIds){const n=i.userData.userIds;for(let r=0,a=n.length;r<a;r++)if(n[r]===e)return i}const s=i.children;for(let n=0,r=s.length;n<r;n++)if(this.traverseObjectByUserId(e,s[n]))return s[n]}getObjectByUserId(e){let i;return this.tilesRenderer.visibleTiles.forEach(s=>{i=this.traverseObjectByUserId(e,s.cached.scene)}),i}getBBox(){return this._bbox||(this._bbox=new p.Box3,this._bbox.setFromObject(this.getModelObject())),this._bbox}setObjectHoveredByUserId(e,i){this.materialManager.updateState(ii.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(ii.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(ii.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(ii.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(ii.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(ii.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function eu(){let c=new Map;return{on(t,e){const i=c.get(t);i?i.push(e):c.set(t,[e])},off(t,e){const i=c.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):c.set(t,[]))},emit(t,e){const i=c.get(t);i&&i.slice().map(s=>s(e)),c.get("*")&&c.get("*").slice().map(s=>s(t,e))}}}class tu{constructor(t){g(this,"viewer");g(this,"element");g(this,"content");g(this,"itemList");g(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(le.ModelLoad,()=>{this.init()})}init(){const t=document.createElement("div");t.classList.add("model-layout-switch-bar");const e=document.createElement("div");e.classList.add("model-layout-switch-bar-content"),e.addEventListener("wheel",this.handleMouseWheel),this.viewer.getLayoutNames().forEach((i,s)=>{const n=this.createItem(i,s);this.itemList[i]=n,n.resetActivate=()=>{for(const r in this.itemList)this.itemList[r].resetActive()},e?.appendChild(n.element)}),this.element=t,this.content=e,this.element.appendChild(this.content),this.viewer.widgetContainer?.appendChild(this.element)}createItem(t,e){const i=new iu(this.viewer,t);return e===0&&i.setActive(!0),i}destroy(){for(const t in this.itemList){const e=this.itemList[t];e.destroy(),this.content?.removeChild(e.element)}this.itemList={},this.element&&this.content&&(this.element.removeChild(this.content),this.element.removeEventListener("wheel",this.handleMouseWheel),this.viewer.widgetContainer?.removeChild(this.element),this.element=void 0)}show(){this.element&&(this.element.style.display="block")}hide(){this.element&&(this.element.style.display="none")}}class iu{constructor(t,e){g(this,"viewer");g(this,"eventBus");g(this,"element");g(this,"resetActivate");g(this,"active");this.viewer=t,this.eventBus=eu(),this.active=!1,this.element=this.createItem(e),this.eventBus.on("activechange",i=>{this.resetActivate&&this.resetActivate(),i?(this.element.classList.add("activate"),this.viewer.activateLayout(e)):this.element.classList.remove("activate")})}createItem(t){const e=document.createElement("div"),i=document.createElement("span");return e.classList.add("model-layout-switch-item"),e.onclick=()=>{this.active=!this.active,this.eventBus.emit("activechange",this.active)},i.innerText=t,e.appendChild(i),e}setActive(t){this.active!==t&&(this.active=t,this.eventBus.emit("activechange",t))}resetActive(){this.active=!1,this.element.classList.remove("activate")}destroy(){this.eventBus.off("activechange")}}class tl{constructor(t){g(this,"element");g(this,"jobCount");this.jobCount=0;const e=document.createElement("div");e.classList.add("x-spinner");for(let s=0;s<4;s++)e.appendChild(document.createElement("span"));const i=t?.widgetContainer;i&&i.appendChild(e),this.element=e,this.setSpinnerVisibility(this.jobCount>0)}setSpinnerVisibility(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){if(this.jobCount<=0){console.warn("[Viewer] jobCount should be at least 1 here!");return}this.setSpinnerVisibility(--this.jobCount>0)}destroy(){this.element.remove(),this.jobCount=0}}class Rr{constructor(t){g(this,"width");g(this,"height");g(this,"container");g(this,"viewerContainer");g(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(P.warn("[Container] containerId:",t,"is not found in dom tree! will append to document body"),e=document.body);const i=document.createElement("div");i.classList.add("x-container"),i.style.cssText="width: 100%; height: 100%; position: relative;",e.appendChild(i),this.container=i,this.width=e.clientWidth,this.height=e.clientHeight,this.initViewerContainer(),this.initWidgetContainer()}initViewerContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-viewer-container"),e.style.cssText="width: 100%; height: 100%; display: inline-block; position: relative; overflow: hidden;",t.appendChild(e),this.viewerContainer=e}initWidgetContainer(){const t=this.container;if(!t)return;const e=document.createElement("div");e.classList.add("x-widget-container"),t.appendChild(e),this.widgetContainer=e}get needResize(){const t=this.width!==this.container.clientWidth||this.height!==this.container.clientHeight;return t&&(this.width=this.container.clientWidth,this.height=this.container.clientHeight),t}destroy(){this.widgetContainer&&(this.widgetContainer.remove(),this.widgetContainer=void 0),this.viewerContainer&&(this.viewerContainer.remove(),this.viewerContainer=void 0),this.container.remove()}}class Fr{constructor(t){g(this,"element");g(this,"progressItems");g(this,"replaceReg");this.progressItems=new Map,this.replaceReg=new RegExp(/<em>[\s\S]*<\/em>/,"g");const e=document.createElement("div");e.classList.add("progress-bar"),t?.widgetContainer?.appendChild(e),this.element=e}addProgressItem(t,e="ProgressBar.Loading",i){this.progressItems.get(t)&&P.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=We.t(e)+": <em></em>",this.element.append(s),this.progressItems.set(t,{div:s,onProgress:i})}removeProgressItem(t){this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t),this.progressItems.size===0&&this.setVisible(!1)}updateProgress(t,e,i){const s=this.progressItems.get(t);if(!s)return;let n=e?""+e:"";e&&i!=null&&(n+=": "),i!=null&&(i<0||i>100?(console.warn("[ProgressBar] Invalid progress value: "+i),n+="--%"):n+=i.toFixed(2)+"%"),s.div.innerHTML=n}updateProgressBar(t,e,i=0,s=100){const n=this.progressItems.get(t);if(!n)return;const r=e instanceof ProgressEvent?e.loaded:e,a=e instanceof ProgressEvent?e.total:100,o=r*100/a*(s-i)/100+i;n.div.innerHTML=n.div.innerHTML.replace(this.replaceReg,"<em>"+(o<0||o>100?"--":o.toFixed(2))+"%</em>"),n.onProgress?.call(n,new ProgressEvent("LoadProgress",{loaded:r,total:100}))}setVisible(t){t?this.element.classList.remove("hidden"):this.element.classList.add("hidden")}delayRemoveProgressItem(t,e=3e3){setTimeout(()=>{this.progressItems.get(t)?.div.remove(),this.progressItems.delete(t)},e)}destroy(){this.progressItems.forEach(t=>{t.div.remove()}),this.progressItems.clear(),this.element.remove()}}var $e=(c=>(c.BaseViewer="BaseViewer",c.Viewer3d="Viewer3d",c.Viewer2d="Viewer2d",c.BimTilesViewer="BimTilesViewer",c))($e||{}),bt=(c=>(c.Perspective="Perspective",c.Orthographic="Orthographic",c))(bt||{});const su={enableSpinner:!0,containerId:"myCanvas"},W={LEFT:1,RIGHT:2,MIDDLE:4},R=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function rt(c){return c.isPerspectiveCamera}function Ue(c){return c.isOrthographicCamera}class nu{constructor(){g(this,"_listeners");this._listeners={}}addEventListener(t,e){const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const s=this._listeners[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}removeAllEventListeners(t){if(!t){this._listeners={};return}Array.isArray(this._listeners[t])&&(this._listeners[t].length=0)}dispatchEvent(t){const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t)}}}const xi=Math.PI*2,Ka=Math.PI/2;function Kn(c,t){t.set(0,0),c.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=c.length,t.y/=c.length}function $n(c,t){return Ue(c)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const il=1e-5,Qi=Math.PI/180;function Ei(c,t,e){return Math.max(t,Math.min(e,c))}function ae(c,t=il){return Math.abs(c)<t}function re(c,t,e=il){return ae(c-t,e)}function $a(c,t){return Math.round(c/t)*t}function es(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ts(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function Xs(c,t,e,i,s=1/0,n){i=Math.max(1e-4,i);const r=2/i,a=r*n,o=1/(1+a+.48*a*a+.235*a*a*a);let l=c-t;const h=t,d=s*i;l=Ei(l,-d,d),t=c-l;const u=(e.value+r*l)*n;e.value=(e.value-r*u)*o;let f=t+(l+u)*o;return h-c>0==f>h&&(f=h,e.value=(f-h)/n),f}function Ja(c,t,e,i,s=1/0,n,r){i=Math.max(1e-4,i);const a=2/i,o=a*n,l=1/(1+o+.48*o*o+.235*o*o*o);let h=t.x,d=t.y,u=t.z,f=c.x-h,m=c.y-d,b=c.z-u;const y=h,C=d,w=u,x=s*i,E=x*x,M=f*f+m*m+b*b;if(M>E){const L=Math.sqrt(M);f=f/L*x,m=m/L*x,b=b/L*x}h=c.x-f,d=c.y-m,u=c.z-b;const O=(e.x+a*f)*n,S=(e.y+a*m)*n,v=(e.z+a*b)*n;e.x=(e.x-a*O)*l,e.y=(e.y-a*S)*l,e.z=(e.z-a*v)*l,r.x=h+(f+O)*l,r.y=d+(m+S)*l,r.z=u+(b+v)*l;const T=y-c.x,_=C-c.y,A=w-c.z,I=r.x-y,B=r.y-C,k=r.z-w;return T*I+_*B+A*k>0&&(r.x=y,r.y=C,r.z=w,e.x=(r.x-y)/n,e.y=(r.y-C)/n,e.z=(r.z-w)/n),r}const Zs=1/8,ru=Be.isBrowser&&/Mac/.test(navigator.platform),au=!(Be.isBrowser&&"PointerEvent"in window);let q,Qa,Ks,Jn,ze,Y,te,bi,pt,mt,Qt,eo,to,st,is,wi,io,Qn,so,er,tr,$s;class $ extends nu{constructor(e,i){super();g(this,"minPolarAngle");g(this,"maxPolarAngle");g(this,"minAzimuthAngle");g(this,"maxAzimuthAngle");g(this,"minDistance");g(this,"maxDistance");g(this,"infinityDolly");g(this,"minZoom");g(this,"maxZoom");g(this,"smoothTime");g(this,"draggingSmoothTime");g(this,"maxSpeed");g(this,"azimuthRotateSpeed");g(this,"polarRotateSpeed");g(this,"dollySpeed");g(this,"truckSpeed");g(this,"dollyToCursor");g(this,"dragToOffset");g(this,"verticalDragToForward");g(this,"boundaryFriction");g(this,"restThreshold");g(this,"colliderMeshes");g(this,"mouseButtons");g(this,"touches");g(this,"cancel");g(this,"_enabled");g(this,"_camera");g(this,"_yAxisUpSpace");g(this,"_yAxisUpSpaceInverse");g(this,"_state");g(this,"_domElement");g(this,"_viewport");g(this,"_target");g(this,"_targetEnd");g(this,"_focalOffset");g(this,"_focalOffsetEnd");g(this,"_spherical");g(this,"_sphericalEnd");g(this,"_zoom");g(this,"_zoomEnd");g(this,"_target0");g(this,"_position0");g(this,"_zoom0");g(this,"_focalOffset0");g(this,"_dollyControlAmount");g(this,"_dollyControlCoord");g(this,"_nearPlaneCorners");g(this,"_hasRested");g(this,"_boundary");g(this,"_boundaryEnclosesCamera");g(this,"_needsUpdate");g(this,"_updatedLastTime");g(this,"_elementRect");g(this,"_activePointers");g(this,"_isUserControllingRotate");g(this,"_isUserControllingDolly");g(this,"_isUserControllingTruck");g(this,"_isUserControllingOffset");g(this,"_isUserControllingZoom");g(this,"_thetaVelocity");g(this,"_phiVelocity");g(this,"_radiusVelocity");g(this,"_targetVelocity");g(this,"_focalOffsetVelocity");g(this,"_zoomVelocity");g(this,"_truckInternal");g(this,"_rotateInternal");g(this,"_dollyInternal");g(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=R.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=Be.isBrowser?new DOMRect:{x:0,y:0,width:0,height:0,left:0,right:0,top:0,bottom:0},this._activePointers=[],this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1,this._isUserControllingOffset=!1,this._isUserControllingZoom=!1,this._thetaVelocity={value:0},this._phiVelocity={value:0},this._radiusVelocity={value:0},this._targetVelocity=new q.Vector3,this._focalOffsetVelocity=new q.Vector3,this._zoomVelocity={value:0},this._truckInternal=(x,E,M)=>{if(rt(this._camera)){const O=Y.copy(this._camera.position).sub(this._target),S=this._camera.getEffectiveFOV()*Qi,v=O.length()*Math.tan(S*.5),T=this.truckSpeed*x*v/this._elementRect.height,_=this.truckSpeed*E*v/this._elementRect.height;this.verticalDragToForward?(M?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(T,0,!0),this.forward(-_,!0)):M?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y+_,this._focalOffsetEnd.z,!0):this.truck(T,_,!0)}else if(Ue(this._camera)){const O=this._camera,S=this.truckSpeed*x*(O.right-O.left)/O.zoom/this._elementRect.width,v=this.truckSpeed*E*(O.top-O.bottom)/O.zoom/this._elementRect.height;M?this.setFocalOffset(this._focalOffsetEnd.x+S,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(S,v,!0)}},this._rotateInternal=(x,E)=>{const M=xi*this.azimuthRotateSpeed*x/this._elementRect.height,O=xi*this.polarRotateSpeed*E/this._elementRect.height;this.rotate(M,O,!0)},this._dollyInternal=(x,E,M)=>{const O=Math.pow(.95,-x*this.dollySpeed),S=this._sphericalEnd.radius*O,v=this._sphericalEnd.radius,T=v*(x>=0?-1:1);this.dollyTo(S),this.infinityDolly&&(S<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(Y),this._targetEnd.add(Y.normalize().multiplyScalar(T)),this._target.add(Y.normalize().multiplyScalar(T))),this.dollyToCursor&&(this._dollyControlAmount+=this._sphericalEnd.radius-v,this.infinityDolly&&(S<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=T),this._dollyControlCoord.set(E,M))},this._zoomInternal=(x,E,M)=>{const O=Math.pow(.95,x*this.dollySpeed),S=this._zoomEnd;this.zoomTo(this._zoom*O),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-S,this._dollyControlCoord.set(E,M))},typeof q>"u"&&console.error("camera-controls: `THREE` is undefined. You must first run `CameraControls.install( { THREE: THREE } )`. Check the docs for further information."),this._camera=e,this._yAxisUpSpace=new q.Quaternion().setFromUnitVectors(this._camera.up,Ks),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=R.NONE,this._target=new q.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new q.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new q.Spherical().setFromVector3(Y.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new q.Vector3,new q.Vector3,new q.Vector3,new q.Vector3],this._updateNearPlaneCorners(),this._boundary=new q.Box3(new q.Vector3(-1/0,-1/0,-1/0),new q.Vector3(1/0,1/0,1/0)),this._target0=this._target.clone(),this._position0=this._camera.position.clone(),this._zoom0=this._zoom,this._focalOffset0=this._focalOffset.clone(),this._dollyControlAmount=0,this._dollyControlCoord=new q.Vector2,this.mouseButtons={left:R.ROTATE,middle:R.DOLLY,right:R.TRUCK,wheel:rt(this._camera)?R.DOLLY:Ue(this._camera)?R.ZOOM:R.NONE},this.touches={one:R.TOUCH_ROTATE,two:rt(this._camera)?R.TOUCH_DOLLY_TRUCK:Ue(this._camera)?R.TOUCH_ZOOM_TRUCK:R.NONE,three:R.TOUCH_TRUCK};const s=new q.Vector2,n=new q.Vector2,r=new q.Vector2,a=x=>{if(!this._enabled||!this._domElement)return;const E=x.pointerType!=="mouse"?null:(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.MIDDLE?W.MIDDLE:(x.buttons&W.RIGHT)===W.RIGHT?W.RIGHT:null;if(E!==null){const O=this._findPointerByMouseButton(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const M={pointerId:x.pointerId,clientX:x.clientX,clientY:x.clientY,deltaX:0,deltaY:0,mouseButton:E};this._activePointers.push(M),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",d),y(x)},o=x=>{if(!this._enabled||!this._domElement)return;const E=(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.MIDDLE?W.MIDDLE:(x.buttons&W.RIGHT)===W.RIGHT?W.RIGHT:null;if(E!==null){const O=this._findPointerByMouseButton(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const M={pointerId:0,clientX:x.clientX,clientY:x.clientY,deltaX:0,deltaY:0,mouseButton:(x.buttons&W.LEFT)===W.LEFT?W.LEFT:(x.buttons&W.MIDDLE)===W.LEFT?W.MIDDLE:(x.buttons&W.RIGHT)===W.LEFT?W.RIGHT:null};this._activePointers.push(M),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u),this._domElement.addEventListener("mousemove",h),this._domElement.addEventListener("mouseup",u),y(x)},l=x=>{const E=x.pointerId,M=this._findPointerById(E);if(M){if(M.clientX=x.clientX,M.clientY=x.clientY,M.deltaX=x.movementX,M.deltaY=x.movementY,x.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right);C()}},h=x=>{const E=this._findPointerById(0);E&&(E.clientX=x.clientX,E.clientY=x.clientY,E.deltaX=x.movementX,E.deltaY=x.movementY,this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right),C())},d=x=>{const E=x.pointerId,M=this._findPointerById(E);if(M&&this._activePointers.splice(this._activePointers.indexOf(M),1),x.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=R.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=R.NONE;w()},u=()=>{const x=this._findPointerById(0);x&&this._activePointers.splice(this._activePointers.indexOf(x),1),this._state=R.NONE,w()};let f=-1;const m=x=>{if(!this._enabled||this.mouseButtons.wheel===R.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===R.ROTATE||this.mouseButtons.wheel===R.TRUCK){const v=performance.now();f-v<1e3&&this._getClientRect(this._elementRect),f=v}const E=ru?-1:-3,M=x.deltaMode===1?x.deltaY/E:x.deltaY/(E*10),O=this.dollyToCursor?(x.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(x.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case R.ROTATE:{this._rotateInternal(x.deltaX,x.deltaY),this._isUserControllingRotate=!0;break}case R.TRUCK:{this._truckInternal(x.deltaX,x.deltaY,!1),this._isUserControllingTruck=!0;break}case R.OFFSET:{this._truckInternal(x.deltaX,x.deltaY,!0),this._isUserControllingOffset=!0;break}case R.DOLLY:{this._dollyInternal(-M,O,S),this._isUserControllingDolly=!0;break}case R.ZOOM:{this._zoomInternal(-M,O,S),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},b=x=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===$.ACTION.NONE){const E=x instanceof PointerEvent?x.pointerId:(x instanceof MouseEvent,0),M=this._findPointerById(E);M&&this._activePointers.splice(this._activePointers.indexOf(M),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u);return}},y=x=>{if(!this._enabled)return;if(Kn(this._activePointers,ze),this._getClientRect(this._elementRect),s.copy(ze),n.copy(ze),this._activePointers.length>=2){const M=ze.x-this._activePointers[1].clientX,O=ze.y-this._activePointers[1].clientY,S=Math.sqrt(M*M+O*O);r.set(0,S);const v=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,T=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;n.set(v,T)}if("pointerType"in x&&x.pointerType==="touch")switch(this._activePointers.length){case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=0,(x.buttons&W.LEFT)===W.LEFT&&(this._state=this._state|this.mouseButtons.left),(x.buttons&W.MIDDLE)===W.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(x.buttons&W.RIGHT)===W.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&R.DOLLY)===R.DOLLY||(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&R.ZOOM)===R.ZOOM||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},C=()=>{if(!this._enabled)return;Kn(this._activePointers,ze);const x=Be.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,E=x?-this._activePointers[0].deltaX:n.x-ze.x,M=x?-this._activePointers[0].deltaY:n.y-ze.y;if(n.copy(ze),((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(E,M),this._isUserControllingRotate=!0),(this._state&R.DOLLY)===R.DOLLY||(this._state&R.ZOOM)===R.ZOOM){const O=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,S=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.DOLLY)===R.DOLLY?(this._dollyInternal(M*Zs,O,S),this._isUserControllingDolly=!0):(this._zoomInternal(M*Zs,O,S),this._isUserControllingZoom=!0)}if((this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE){const O=ze.x-this._activePointers[1].clientX,S=ze.y-this._activePointers[1].clientY,v=Math.sqrt(O*O+S*S),T=r.y-v;r.set(0,v);const _=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET?(this._dollyInternal(T*Zs,_,A),this._isUserControllingDolly=!0):(this._zoomInternal(T*Zs,_,A),this._isUserControllingZoom=!0)}((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(E,M,!1),this._isUserControllingTruck=!0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(E,M,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},w=()=>{Kn(this._activePointers,ze),n.copy(ze),this._activePointers.length===0&&this._domElement&&(this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u),this.dispatchEvent({type:"controlend"}))};this._addAllEventListeners=x=>{this._domElement=x,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),au&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",d),this._domElement.addEventListener("wheel",m,{passive:!1}),this._domElement.addEventListener("contextmenu",b)},this._removeAllEventListeners=()=>{this._domElement&&(this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect="",this._domElement.removeEventListener("pointerdown",a),this._domElement.removeEventListener("mousedown",o),this._domElement.removeEventListener("pointercancel",d),this._domElement.removeEventListener("wheel",m),this._domElement.removeEventListener("contextmenu",b),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u))},this.cancel=()=>{this._state!==R.NONE&&(this._state=R.NONE,this._activePointers.length=0,w())},i&&this.connect(i),this.update(0)}static install(e){q=e.THREE,Qa=Object.freeze(new q.Vector3(0,0,0)),Ks=Object.freeze(new q.Vector3(0,1,0)),Jn=Object.freeze(new q.Vector3(0,0,1)),ze=new q.Vector2,Y=new q.Vector3,te=new q.Vector3,bi=new q.Vector3,pt=new q.Vector3,mt=new q.Vector3,Qt=new q.Vector3,eo=new q.Vector3,to=new q.Vector3,st=new q.Spherical,is=new q.Spherical,wi=new q.Box3,io=new q.Box3,Qn=new q.Sphere,so=new q.Quaternion,er=new q.Quaternion,tr=new q.Matrix4,$s=new q.Raycaster}static get ACTION(){return R}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const n=Ei(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=Ei(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,n=Ei(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=re(o,this._spherical.radius);if(!(s>n)&&l)return Promise.resolve();this._sphericalEnd.radius=Math.min(n,o)}else this._sphericalEnd.radius=n;this._needsUpdate=!0,i||(this._spherical.radius=this._sphericalEnd.radius);const a=!i||re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Ei(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||re(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),pt.multiplyScalar(e),mt.multiplyScalar(-i);const n=Y.copy(pt).add(mt),r=te.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,i=!1){Y.setFromMatrixColumn(this._camera.matrix,0),Y.crossVectors(this._camera.up,Y),Y.multiplyScalar(e);const s=te.copy(this._targetEnd).add(Y);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return Y.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+Y.x,this._targetEnd.y+Y.y,this._targetEnd.z+Y.z,i)}moveTo(e,i,s,n=!1){this._isUserControllingTruck=!1;const r=Y.set(e,i,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,r,this.boundaryFriction),this._needsUpdate=!0,n||this._target.copy(this._targetEnd);const a=!n||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,n=!1){const o=Y.set(e,i,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,n)}fitToBox(e,i,{cover:s=!1,paddingLeft:n=0,paddingRight:r=0,paddingBottom:a=0,paddingTop:o=0}={}){const l=[],h=e.isBox3?wi.copy(e):wi.setFromObject(e);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const d=$a(this._sphericalEnd.theta,Ka),u=$a(this._sphericalEnd.phi,Ka);l.push(this.rotateTo(d,u,i));const f=Y.setFromSpherical(this._sphericalEnd).normalize(),m=so.setFromUnitVectors(f,Jn),b=re(Math.abs(f.y),1);b&&m.multiply(er.setFromAxisAngle(Ks,d)),m.multiply(this._yAxisUpSpaceInverse);const y=io.makeEmpty();te.copy(h.min).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setX(h.max.x).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setY(h.max.y).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setZ(h.min.z).applyQuaternion(m),y.expandByPoint(te),te.copy(h.min).setZ(h.max.z).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setY(h.min.y).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).setX(h.min.x).applyQuaternion(m),y.expandByPoint(te),te.copy(h.max).applyQuaternion(m),y.expandByPoint(te),y.min.x-=n,y.min.y-=a,y.max.x+=r,y.max.y+=o,m.setFromUnitVectors(Jn,f),b&&m.premultiply(er.invert()),m.premultiply(this._yAxisUpSpace);const C=y.getSize(Y),w=y.getCenter(te).applyQuaternion(m);if(rt(this._camera)){const x=this.getDistanceToFitBox(C.x,C.y,C.z,s);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.dollyTo(x,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(Ue(this._camera)){const x=this._camera,E=x.right-x.left,M=x.top-x.bottom,O=s?Math.max(E/C.x,M/C.y):Math.min(E/C.x,M/C.y);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.zoomTo(O,i)),l.push(this.setFocalOffset(0,0,0,i))}return Promise.all(l)}fitToSphere(e,i){const s=[],r=e instanceof q.Sphere?Qn.copy(e):$.createBoundingSphere(e,Qn);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,i)),rt(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,i))}else if(Ue(this._camera)){const a=this._camera,o=a.right-a.left,l=a.top-a.bottom,h=2*r.radius,d=Math.min(o/h,l/h);s.push(this.zoomTo(d,i))}return s.push(this.setFocalOffset(0,0,0,i)),Promise.all(s)}setLookAt(e,i,s,n,r,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const l=te.set(n,r,a),h=Y.set(e,i,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(h.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const d=!o||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold)&&re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(d)}lerpLookAt(e,i,s,n,r,a,o,l,h,d,u,f,m,b=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const y=Y.set(n,r,a),C=te.set(e,i,s);st.setFromVector3(C.sub(y).applyQuaternion(this._yAxisUpSpace));const w=bi.set(d,u,f),x=te.set(o,l,h);is.setFromVector3(x.sub(w).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(w,m));const E=is.theta-st.theta,M=is.phi-st.phi,O=is.radius-st.radius;this._sphericalEnd.set(st.radius+O*m,st.phi+M*m,st.theta+E*m),this.normalizeRotations(),this._needsUpdate=!0,b||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const S=!b||re(this._target.x,this._targetEnd.x,this.restThreshold)&&re(this._target.y,this._targetEnd.y,this.restThreshold)&&re(this._target.z,this._targetEnd.z,this.restThreshold)&&re(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&re(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&re(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(S)}setPosition(e,i,s,n=!1){return this.setLookAt(e,i,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,n)}setTarget(e,i,s,n=!1){const r=this.getPosition(Y),a=this.setLookAt(r.x,r.y,r.z,e,i,s,n);return this._sphericalEnd.phi=Ei(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||re(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&re(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&re(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),mt.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Qt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=Y.set(e,i,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);pt.multiplyScalar(a.x),mt.multiplyScalar(a.y),Qt.multiplyScalar(a.z),Y.copy(pt).add(mt).add(Qt),Y.z=Y.z+r,this.dollyTo(r,!1),this.setFocalOffset(-Y.x,Y.y,-Y.z,!1),this.moveTo(e,i,s,!1)}setBoundary(e){if(!e){this._boundary.min.set(-1/0,-1/0,-1/0),this._boundary.max.set(1/0,1/0,1/0),this._needsUpdate=!0;return}this._boundary.copy(e),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._needsUpdate=!0}setViewport(e,i,s,n){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new q.Vector4,typeof e=="number"?this._viewport.set(e,i,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,n=!1){if($n(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/i,a=this._camera.getEffectiveFOV()*Qi,o=this._camera.aspect;return((n?r>o:r<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if($n(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*Qi,s=Math.atan(Math.tan(i*.5)*this._camera.aspect)*2,n=1<this._camera.aspect?i:s;return e/Math.sin(n*.5)}getTarget(e){return(e&&e.isVector3?e:new q.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new q.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new q.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%xi,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=xi),this._spherical.theta+=xi*Math.round((this._sphericalEnd.theta-this._spherical.theta)/xi)}reset(e=!1){const i=[this.setLookAt(this._position0.x,this._position0.y,this._position0.z,this._target0.x,this._target0.y,this._target0.z,e),this.setFocalOffset(this._focalOffset0.x,this._focalOffset0.y,this._focalOffset0.z,e),this.zoomTo(this._zoom0,e)];return Promise.all(i)}saveState(){this.getTarget(this._target0),this.getPosition(this._position0),this._zoom0=this._zoom,this._focalOffset0.copy(this._focalOffset)}updateCameraUp(){this._yAxisUpSpace.setFromUnitVectors(this._camera.up,Ks),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert}update(e){const i=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,n=this._sphericalEnd.radius-this._spherical.radius,r=eo.subVectors(this._targetEnd,this._target),a=to.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ae(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Xs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(ae(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Xs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(ae(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Xs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(ae(r.x)&&ae(r.y)&&ae(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Ja(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ae(a.x)&&ae(a.y)&&ae(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Ja(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(rt(this._camera)){const u=this._camera,f=Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),m=te.copy(f).cross(u.up).normalize();m.lengthSq()===0&&(m.x=1);const b=bi.crossVectors(m,f),y=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*Qi*.5),w=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,x=Y.copy(this._targetEnd).add(m.multiplyScalar(this._dollyControlCoord.x*y*u.aspect)).add(b.multiplyScalar(this._dollyControlCoord.y*y));this._targetEnd.lerp(x,w)}else if(Ue(this._camera)){const u=this._camera,f=Y.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),m=te.set(0,0,-1).applyQuaternion(u.quaternion),b=bi.copy(f).add(m.multiplyScalar(-f.dot(u.up))),C=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,w=Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),x=this._targetEnd.dot(w);this._targetEnd.lerp(b,C);const E=this._targetEnd.dot(w),M=w.multiplyScalar(E-x);this._targetEnd.sub(M)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ae(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Xs(this._zoom,this._zoomEnd,this._zoomVelocity,u,1/0,e)}this._camera.zoom!==this._zoom&&(this._camera.zoom=this._zoom,this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0);const l=this._collisionTest();this._spherical.radius=Math.min(this._spherical.radius,l),this._spherical.makeSafe(),this._camera.position.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).add(this._target),this._camera.lookAt(this._target),(!ae(this._focalOffset.x)||!ae(this._focalOffset.y)||!ae(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),Qt.setFromMatrixColumn(this._camera.matrix,2),pt.multiplyScalar(this._focalOffset.x),mt.multiplyScalar(-this._focalOffset.y),Qt.multiplyScalar(this._focalOffset.z),Y.copy(pt).add(mt).add(Qt),this._camera.position.add(Y)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),Y.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const d=this._needsUpdate;return d&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):d?(this.dispatchEvent({type:"update"}),ae(i,this.restThreshold)&&ae(s,this.restThreshold)&&ae(n,this.restThreshold)&&ae(r.x,this.restThreshold)&&ae(r.y,this.restThreshold)&&ae(r.z,this.restThreshold)&&ae(a.x,this.restThreshold)&&ae(a.y,this.restThreshold)&&ae(a.z,this.restThreshold)&&ae(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!d&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._updatedLastTime=d,this._needsUpdate=!1,d}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:es(this.maxDistance),minZoom:this.minZoom,maxZoom:es(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:es(this.maxPolarAngle),minAzimuthAngle:es(this.minAzimuthAngle),maxAzimuthAngle:es(this.maxAzimuthAngle),smoothTime:this.smoothTime,draggingSmoothTime:this.draggingSmoothTime,dollySpeed:this.dollySpeed,truckSpeed:this.truckSpeed,dollyToCursor:this.dollyToCursor,verticalDragToForward:this.verticalDragToForward,target:this._targetEnd.toArray(),position:Y.setFromSpherical(this._sphericalEnd).add(this._targetEnd).toArray(),zoom:this._zoomEnd,focalOffset:this._focalOffsetEnd.toArray(),target0:this._target0.toArray(),position0:this._position0.toArray(),zoom0:this._zoom0,focalOffset0:this._focalOffset0.toArray()})}fromJSON(e,i=!1){const s=JSON.parse(e),n=Y.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ts(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ts(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ts(s.maxPolarAngle),this.minAzimuthAngle=ts(s.minAzimuthAngle),this.maxAzimuthAngle=ts(s.maxAzimuthAngle),this.smoothTime=s.smoothTime,this.draggingSmoothTime=s.draggingSmoothTime,this.dollySpeed=s.dollySpeed,this.truckSpeed=s.truckSpeed,this.dollyToCursor=s.dollyToCursor,this.verticalDragToForward=s.verticalDragToForward,this._target0.fromArray(s.target0),this._position0.fromArray(s.position0),this._zoom0=s.zoom0,this._focalOffset0.fromArray(s.focalOffset0),this.moveTo(s.target[0],s.target[1],s.target[2],i),st.setFromVector3(n.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(st.theta,st.phi,i),this.zoomTo(s.zoom,i),this.setFocalOffset(s.focalOffset[0],s.focalOffset[1],s.focalOffset[2],i),this._needsUpdate=!0}connect(e){if(this._domElement){console.warn("camera-controls is already connected.");return}this._addAllEventListeners(e)}disconnect(){this.cancel(),this._removeAllEventListeners(),this._domElement&&(this._domElement=void 0)}dispose(){this.removeAllEventListeners(),this.disconnect()}_findPointerById(e){return this._activePointers.find(i=>i.pointerId===e)}_findPointerByMouseButton(e){return this._activePointers.find(i=>i.mouseButton===e)}_encloseToBoundary(e,i,s){const n=i.lengthSq();if(n===0)return e;const r=te.copy(i).add(e),o=this._boundary.clampPoint(r,bi).sub(r),l=o.lengthSq();if(l===0)return e.add(i);if(l===n)return e;if(s===0)return e.add(i).add(o);{const h=1+s*l/i.dot(o);return e.add(te.copy(i).multiplyScalar(h)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(rt(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*Qi,n=Math.tan(s*.5)*i,r=n*e.aspect;this._nearPlaneCorners[0].set(-r,-n,0),this._nearPlaneCorners[1].set(r,-n,0),this._nearPlaneCorners[2].set(r,n,0),this._nearPlaneCorners[3].set(-r,n,0)}else if(Ue(this._camera)){const e=this._camera,i=1/e.zoom,s=e.left*i,n=e.right*i,r=e.top*i,a=e.bottom*i;this._nearPlaneCorners[0].set(s,r,0),this._nearPlaneCorners[1].set(n,r,0),this._nearPlaneCorners[2].set(n,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||$n(this._camera,"_collisionTest"))return e;const s=Y.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);tr.lookAt(Qa,s,this._camera.up);for(let n=0;n<4;n++){const r=te.copy(this._nearPlaneCorners[n]);r.applyMatrix4(tr);const a=bi.addVectors(this._target,r);$s.set(a,s),$s.far=this._spherical.radius+1;const o=$s.intersectObjects(this.colliderMeshes);o.length!==0&&o[0].distance<e&&(e=o[0].distance)}return e}_getClientRect(e){if(!this._domElement)return;const i=this._domElement.getBoundingClientRect();return e.x=i.left,e.y=i.top,this._viewport?(e.x+=this._viewport.x,e.y+=i.height-this._viewport.w-this._viewport.y,e.width=this._viewport.z,e.height=this._viewport.w):(e.width=i.width,e.height=i.height),e}_createOnRestPromise(e){return e?Promise.resolve():(this._hasRested=!1,this.dispatchEvent({type:"transitionstart"}),new Promise(i=>{const s=()=>{this.removeEventListener("rest",s),i()};this.addEventListener("rest",s)}))}_addAllEventListeners(e){}_removeAllEventListeners(){}static createBoundingSphere(e,i=new q.Sphere){const s=i,n=s.center;wi.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&wi.expandByObject(a)}),wi.getCenter(n);let r=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a,l=o.geometry.clone();if(l.applyMatrix4(o.matrixWorld),l.isBufferGeometry){const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)Y.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(Y))}else{const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)Y.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(Y))}}),s.radius=Math.sqrt(r),s}}var ot=(c=>(c[c.Orbit=0]="Orbit",c[c.FirstPerson=1]="FirstPerson",c[c.Plan=2]="Plan",c))(ot||{});class sl{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=ot.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:$.ACTION.ROTATE,middle:$.ACTION.DOLLY,right:$.ACTION.TRUCK,wheel:rt(t)?$.ACTION.DOLLY:Ue(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_ROTATE,two:rt(t)?$.ACTION.TOUCH_DOLLY_TRUCK:Ue(t)?$.ACTION.TOUCH_ZOOM_TRUCK:$.ACTION.NONE,three:$.ACTION.TOUCH_TRUCK},e.dollyToCursor=!0,e.azimuthRotateSpeed=1,e.polarRotateSpeed=1,e.minDistance=1,e.maxDistance=300,e.minZoom=3,this.cameraManager.cameraControls.truckSpeed=2}adjustCameraByBBox(t){const e=this.cameraManager.cameraControls,i=new p.Vector3;t.getSize(i);const s=i.length();e.minDistance=1,e.maxDistance=s*10,e.minZoom=3}}class nl{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=ot.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:$.ACTION.TRUCK,middle:$.ACTION.TRUCK,right:$.ACTION.TRUCK,wheel:rt(t)?$.ACTION.DOLLY:Ue(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_TRUCK,two:rt(t)?$.ACTION.TOUCH_DOLLY_TRUCK:Ue(t)?$.ACTION.TOUCH_ZOOM_TRUCK:$.ACTION.NONE,three:$.ACTION.NONE},e.dollyToCursor=!0,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0,e.truckSpeed=1,e.maxZoom=1/0,e.minZoom=-1/0}adjustCameraByBBox(t){}}const vi=50,ir=new p.Vector3;class ou{constructor(t){g(this,"viewer");g(this,"perspectiveCamera");g(this,"orthographicCamera");g(this,"activeCamera");g(this,"cameraControls");g(this,"previousDistance");g(this,"previousAzimuthRotateSpeed");g(this,"previousPolarRotateSpeed");g(this,"previousDollySpeed");g(this,"previousTruckSpeed");g(this,"previousMouseLeft");g(this,"enableKeyDown");g(this,"controlsMap");g(this,"activeControls");g(this,"projection");g(this,"anchor");g(this,"onKeyDown");g(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=$.ACTION.NONE,this.enableKeyDown=!0,this.projection=bt.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const n=this.cameraControls,r=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===$e.Viewer3d||this.viewer.name===$e.BimTilesViewer;switch(s.code){case"ArrowLeft":a?n.rotate(.1,0,!0):this.viewer.name===$e.Viewer2d&&n.truck(r,0,!0);break;case"ArrowRight":a?n.rotate(-.1,0,!0):this.viewer.name===$e.Viewer2d&&n.truck(-r,0,!0);break;case"ArrowUp":a?n.rotate(0,.1,!0):this.viewer.name===$e.Viewer2d&&n.truck(0,r,!0);break;case"ArrowDown":a?n.rotate(0,-.1,!0):this.viewer.name===$e.Viewer2d&&n.truck(0,-r,!0);break;case"KeyW":a&&(Ue(this.activeCamera)?n.zoom(.01,!0):n.dolly(1,!0));break;case"KeyA":a&&n.truck(-r,0,!0);break;case"KeyS":a&&(Ue(this.activeCamera)?n.zoom(-.01,!0):n.dolly(-1,!0));break;case"KeyD":a&&n.truck(r,0,!0);break;case"KeyQ":a&&n.truck(0,-r,!0);break;case"KeyE":a&&n.truck(0,r,!0);break}},this.onChange=()=>{this.viewer.enableRender()},this.viewer=t;const e=t.viewerContainer,i=e.clientWidth/e.clientHeight;this.perspectiveCamera=new p.PerspectiveCamera(Oo,i,on,ln),this.orthographicCamera=new p.OrthographicCamera(vi*i/-2,vi*i/2,vi/2,vi/-2,on,ln),this.activeCamera=this.perspectiveCamera,this.setupCameras(),$.install({THREE:p}),this.cameraControls=new $(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[ot.Orbit]:new sl(this),[ot.Plan]:new nl(this)},this.activeControls=this.controlsMap[ot.Orbit],this.setupControls(),this.setProjection(bt.Perspective),this.anchor=this.createAnchor()}get viewerContainer(){return this.viewer.viewerContainer}get inputManager(){return this.viewer.getInputManager()}createAnchor(){const t=document.createElement("div");return t.className="anchor",this.viewerContainer?.appendChild(t),this.cameraControls.addEventListener("control",()=>{if(this.isOrbitPointVisible()){const e=this.getTarget(),i=Ee.world2Screen(e,this.activeCamera,this.viewerContainer);this.setAnchorPosition(i.x,i.y)}}),t}setAnchorPosition(t,e){this.anchor.style.left=t+"px",this.anchor.style.top=e+"px"}setOrbitPointVisible(t){t?this.anchor.classList.add("active"):this.anchor.classList.remove("active")}isOrbitPointVisible(){return this.anchor.classList.contains("active")}setOrthoCameraAspect(t,e){const i=t/e;this.orthographicCamera.left=-50*i/2,this.orthographicCamera.right=vi*i/2,this.orthographicCamera.top=vi/2,this.orthographicCamera.bottom=-50/2,this.orthographicCamera.updateProjectionMatrix()}setupCameras(){this.setCameraPositionAndTarget(this.perspectiveCamera)}setCameraPositionAndTarget(t){t.position.z=10,t.position.y=10,t.position.x=10,t.lookAt(new p.Vector3(0,0,0))}setupControls(){const t=this.cameraControls;t.smoothTime=.1,t.draggingSmoothTime=0,t.infinityDolly=!0,t.setTarget(0,0,0),t.addEventListener("controlstart",()=>this.onChange),t.addEventListener("control",()=>this.onChange),t.addEventListener("update",()=>this.viewer.dispatchEvent(le.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===ot.FirstPerson)return;this.previousDistance=this.cameraControls.distance,this.cameraControls.distance=200;const{width:t,height:e}=this.getDims();this.setupOrthoCamera(e,t),this.activeCamera=this.orthographicCamera,this.projection=bt.Orthographic}getDims(){const t=new p.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new p.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:n,clientHeight:r}=this.viewer.viewerContainer,a=n/r,o=this.perspectiveCamera.fov,l=s*2*Math.atan(o*(Math.PI/180)/2);return{width:l*a,height:l}}setupOrthoCamera(t,e){this.cameraControls.mouseButtons.wheel=$.ACTION.ZOOM;const i=this.perspectiveCamera,s=this.orthographicCamera;s.zoom=1,s.left=e/-2,s.right=e/2,s.top=t/2,s.bottom=t/-2,s.updateProjectionMatrix(),s.position.copy(i.position),s.quaternion.copy(i.quaternion),this.cameraControls.camera=s}setPerspectiveCamera(){const t=this.cameraControls;t.mouseButtons.wheel=$.ACTION.DOLLY;const e=this.perspectiveCamera,i=this.orthographicCamera;e.position.copy(i.position),e.quaternion.copy(i.quaternion),e.updateProjectionMatrix(),t.camera=e,t.mouseButtons.wheel=$.ACTION.DOLLY,this.activeCamera=e,this.projection=bt.Perspective,t.distance=this.previousDistance,t.zoomTo(1)}update(t){const e=this.cameraControls.update(t);return this.camera.updateMatrixWorld(),e}updateAspect(){const{clientWidth:t,clientHeight:e}=this.viewer.viewerContainer;this.perspectiveCamera.aspect=t/e,this.perspectiveCamera.updateProjectionMatrix(),this.setOrthoCameraAspect(t,e)}get camera(){return this.activeCamera}enableKeyControl(t){this.enableKeyDown=t}getTarget(){return this.cameraControls.getTarget(ir)}getPosition(){return this.cameraControls.getPosition(ir)}adjustCameraByBBox(t){const e=this.camera.near,i=this.camera.far,s=new p.Vector3;t.getSize(s);const n=s.length(),r=5,a=n/r,o=n*r;if(e>a||i<o){const l=h=>j.numberToString(h);P.info("[Viewer] BBox's longest side is: "+l(n)),e>a&&(P.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(P.warn("[Viewer] camera.far("+l(i)+") shouldn't smaller than "+l(o)+", will change it!"),this.camera.far=o)}this.activeControls.adjustCameraByBBox(t),this.cameraControls.update(0)}enableControl(t){this.cameraControls.enabled=t}get enableRotate(){const t=this.cameraControls;return!!t.azimuthRotateSpeed||!!t.polarRotateSpeed}set enableRotate(t){const e=this.cameraControls;t?(e.azimuthRotateSpeed=this.previousAzimuthRotateSpeed,e.polarRotateSpeed=this.previousPolarRotateSpeed):(this.previousAzimuthRotateSpeed=e.azimuthRotateSpeed,this.previousPolarRotateSpeed=e.polarRotateSpeed,e.azimuthRotateSpeed=0,e.polarRotateSpeed=0)}enableZoom(t){const e=this.cameraControls;t?e.dollySpeed=this.previousDollySpeed:(this.previousDollySpeed=e.dollySpeed,e.dollySpeed=0)}enablePan(t){const e=this.cameraControls;t?e.truckSpeed=this.previousTruckSpeed:(this.previousTruckSpeed=e.dollySpeed,e.truckSpeed=0)}enableMouseLeft(t){const e=this.cameraControls;t?e.mouseButtons.left=this.previousMouseLeft:(this.previousMouseLeft=e.mouseButtons.left,e.mouseButtons.left=$.ACTION.NONE)}setCameraPosition(t){this.cameraControls.setPosition(t.x,t.y,t.z)}setCameraTarget(t){this.cameraControls.setTarget(t.x,t.y,t.z)}flyTo(t,e,i=!0){const s=this.cameraControls;s.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,i),s.setFocalOffset(0,0,0,!0)}flyToPosition(t,e,i){this.cameraControls.moveTo(t,e,i,!0)}flyToBox(t,e){const i=new p.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new p.Box3().setFromObject(t),i=new p.Sphere;e.getBoundingSphere(i),this.cameraControls.fitToSphere(i,!0)}flyToViewpoint(t){this.flyTo(t.eye,t.look),t.zoom!=null&&(this.orthographicCamera.zoom=t.zoom)}getDistanceToFitSphere(t){return this.cameraControls.getDistanceToFitSphere(t)}setNavigationMode(t){this.activeControls.mode!==t&&(this.activeControls=this.controlsMap[t],this.activeControls.setupControl())}getProjection(){return this.projection}setProjection(t){this.projection!==t&&(this.projection=t,t===bt.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(ir)}getCameraConfig(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,near:this.activeCamera.near,far:this.activeCamera.far,zoom:this.activeCamera.zoom}}getCurrentViewpoint(){return{eye:this.activeCamera.position,look:this.getTarget(),up:this.activeCamera.up,zoom:this.activeCamera.zoom}}setCameraConfig(t){const e=this.cameraControls,{near:i=on,far:s=ln,up:n=new p.Vector3(0,1,0),zoom:r=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(n.x,n.y,n.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(r),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const ai=class ai extends Yo{tableName(){return"fonts"}static instance(){return!ai._instance&&(ai._instance=new ai),ai._instance}query(t){let e;return new Promise((i,s)=>{super.query(n=>{if(!n){i(e);return}!n.value||n.value.fileName!==t||(e=n.value)},n=>{s(n)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};g(ai,"_instance");let Fi=ai;var rl=(c=>(c[c.Horizontal=0]="Horizontal",c[c.Vertical=1]="Vertical",c[c.All=2]="All",c))(rl||{}),He=(c=>(c[c.Shapes=0]="Shapes",c[c.Bigfont=1]="Bigfont",c[c.Unifont=2]="Unifont",c))(He||{});class al extends ql.Font{constructor(e,i){super(i);g(this,"info");g(this,"orientation");g(this,"baseUp");g(this,"baseDown");g(this,"fileHeader");g(this,"fileVersion");g(this,"fileName");g(this,"data");g(this,"order");g(this,"unsupportedChars");this.info="",this.orientation=rl.Horizontal,this.baseUp=0,this.baseDown=0,this.fileHeader="",this.fileVersion="",this.order=0,this.unsupportedChars={},this.fileName=e}addUnsupportedChar(e){!this.unsupportedChars[e]&&(this.unsupportedChars[e]=0),this.unsupportedChars[e]++}getFontFile(){return{order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}async setFontDataToIndexedDb(){const e=this.getFontFile();return new Promise((i,s)=>{Fi.instance().save(e,()=>{console.log("[FontFile] Saved '"+this.fileName+"' ("+this.fileHeader+") to indexedDb"),i()},n=>s("[FontFile] Failed to save '"+this.fileName+"' ("+this.fileHeader+") to indexedDb! "+n))})}async getFontDataByIndexedDb(){return Fi.instance().query(this.fileName)}releaseFontData(){this.data={}}}class ei extends al{constructor(e,i){super(e,i);g(this,"reversed");this.reversed=!1,i instanceof ArrayBuffer?this.data=this.parseTTF(i):i.fileName?this.setFontFile(i):this.data=i,this.type="MeshFont"}generateShapes(e,i){return super.generateShapes(e,i)}getCharShape(e,i){const s=no(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return no("?",e,0,0,this.data)?.path}parseTTF(e){function i(n,r){const a=Math.round,o={},l=1e5/((n.unitsPerEm||2048)*72),h=n.encoding.cmap.glyphIndexMap,d=Object.keys(h);for(let u=0;u<d.length;u++){const f=d[u],m=n.glyphs.glyphs[h[f]];if(f!==void 0){const b={ha:a(m.advanceWidth*l),x_min:a(m.xMin*l),x_max:a(m.xMax*l),o:""};r&&(m.path.commands=s(m.path.commands)),m.path.commands.forEach(function(y){y.type.toLowerCase()==="c"&&(y.type="b"),b.o+=y.type.toLowerCase()+" ",y.x!==void 0&&y.y!==void 0&&(b.o+=a(y.x*l)+" "+a(y.y*l)+" "),y.x1!==void 0&&y.y1!==void 0&&(b.o+=a(y.x1*l)+" "+a(y.y1*l)+" "),y.x2!==void 0&&y.y2!==void 0&&(b.o+=a(y.x2*l)+" "+a(y.y2*l)+" ")}),o[String.fromCodePoint(m.unicode)]=b}}return{glyphs:o,familyName:n.getEnglishName("fullName"),ascender:a(n.ascender*l),descender:a(n.descender*l),underlinePosition:n.tables.post.underlinePosition,underlineThickness:n.tables.post.underlineThickness,boundingBox:{xMin:n.tables.head.xMin,xMax:n.tables.head.xMax,yMin:n.tables.head.yMin,yMax:n.tables.head.yMax},resolution:1e3,original_font_information:n.tables.name}}function s(n){const r=[];let a;n.forEach(function(l){l.type.toLowerCase()==="m"?(a=[l],r.push(a)):l.type.toLowerCase()!=="z"&&a.push(l)});const o=[];return r.forEach(function(l){const h={type:"m",x:l[l.length-1].x,y:l[l.length-1].y};o.push(h);for(let d=l.length-1;d>0;d--){const u=l[d],f={type:u.type};u.x2!==void 0&&u.y2!==void 0?(f.x1=u.x2,f.y1=u.y2,f.x2=u.x1,f.y2=u.y1):u.x1!==void 0&&u.y1!==void 0&&(f.x1=u.x1,f.y1=u.y1),f.x=l[d-1].x,f.y=l[d-1].y,o.push(f)}}),o}return i(Gl.parse(e),this.reversed)}}function no(c,t,e,i,s){const n=s.glyphs[c];if(!n)return;const r=new p.ShapePath;let a,o,l,h,d,u,f,m;if(n.o){const b=n._cachedOutline||(n._cachedOutline=n.o.split(" "));for(let y=0,C=b.length;y<C;)switch(b[y++]){case"m":a=b[y++]*t+e,o=b[y++]*t+i,r.moveTo(a,o);break;case"l":a=b[y++]*t+e,o=b[y++]*t+i,r.lineTo(a,o);break;case"q":l=b[y++]*t+e,h=b[y++]*t+i,d=b[y++]*t+e,u=b[y++]*t+i,r.quadraticCurveTo(d,u,l,h);break;case"b":l=b[y++]*t+e,h=b[y++]*t+i,d=b[y++]*t+e,u=b[y++]*t+i,f=b[y++]*t+e,m=b[y++]*t+i,r.bezierCurveTo(d,u,f,m,l,h);break}}return{offsetX:n.ha*t,path:r}}class Q{static GetBytes(t){switch(typeof t){case"string":{const e=new Uint16Array(t.length);for(let i=0;i<t.length;i++)e[i]=t.charCodeAt(i);return new Uint8Array(e.buffer)}case"number":return t-Math.floor(t)==0?t>4294967295?(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Int32Array(1)):(function(e){return e[0]=t,new Uint8Array(e.buffer)})(new Float64Array(1));case"boolean":return(function(e){return e[0]=Number(t),e})(new Uint8Array(1));default:if(t instanceof Array){const e=[];for(let r=0;r<t.length;r++)e.push(Q.GetBytes(t[r]));let i=0;for(let r=0;r<e.length;r++)i+=e[r].length;const s=new Uint8Array(i);let n=0;for(let r=0;r<e.length;r++)for(let a=0;a<e[r].length;a++)s[n++]=e[r][a];return s}throw"Can't Convert To Bytes!!"}}static Get1Bytes(t){switch(typeof t){case"number":case"boolean":return new Uint8Array([Number(t)]);default:if(t instanceof Array){const e=[];for(let r=0;r<t.length;r++)e.push(this.Get1Bytes(t[r]));let i=0;for(let r=0;r<e.length;r++)i+=e[r].length;const s=new Uint8Array(i);let n=0;for(let r=0;r<e.length;r++)for(let a=0;a<e[r].length;a++)s[n++]=e[r][a];return s}throw"Can't Convert To Bytes!!"}}static byteTosbyte(t){return(t&127)-(t&128?128:0)}static ToBoolean(t,e){return e=e||0,!!t[e]}static ToInt8(t,e){return e=e||0,t[e]&128?-((t[e]^255)+1):t[e]}static ToUInt8(t,e){return e=e||0,t[e]}static ToInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Int16Array(i.buffer,0,1)[0]}static ToInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Int32Array(i.buffer,0,1)[0]}static ToUInt16(t,e){e=e||0;const i=t.slice(e,e+2);return new Uint16Array(i.buffer,0,1)[0]}static ToUInt32(t,e){e=e||0;const i=t.slice(e,e+4);return new Uint32Array(i.buffer,0,1)[0]}static ToChar(t,e){e=e||0;const i=t.slice(e,e+2);return String.fromCharCode(new Uint16Array(i.buffer,0,1)[0])}static ToAscii(t,e){return e=e||0,String.fromCharCode(t[e])}static ToAsciiString(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);let s="";for(let n=0;n<i;n++)s+=String.fromCharCode(t[e+n]||0);return s}static ToUTF16String(t,e,i){e=e||0,i=i||t.length,i+e>t.length&&(i-=e);const s=new Uint8Array(i);for(let n=0;n<i;n++)s[n]=t[e+n]||0;return String.fromCharCode.apply(null,Array.from(new Uint16Array(s.buffer,0,i/2)))}static ToFloat32(t,e){e=e||0;const i=t.slice(e,e+4);return new Float32Array(i.buffer,0,1)[0]}static ToFloat64(t,e){e=e||0;const i=t.slice(e,e+8);return new Float64Array(i.buffer,0,1)[0]}}let gn;function lu(){const c=[[161,169,161,254],[176,247,161,254],[129,160,64,254],[170,254,64,160],[168,169,64,160],[170,175,161,254],[248,254,161,254],[161,167,64,160]],t=new Uint16Array(23940);let e=0;for(const[s,n,r,a]of c)for(let o=r;o<=a;o++)if(o!==127)for(let l=s;l<=n;l++)t[e++]=o<<8|l;const i=new TextDecoder("gbk").decode(t);for(gn=new Uint16Array(65536),e=0;e<i.length;e++)gn[i.charCodeAt(e)]=t[e]}function cu(c){!gn&&lu();const t=new Uint8Array(c.length*2);let e=0;for(let i=0;i<c.length;i++){const s=c.charCodeAt(i);if(s<128)t[e++]=s;else{const n=gn[s];t[e++]=n&255,t[e++]=n>>8}}return t.subarray(0,e)}new p.Vector2;class ys extends p.Shape{constructor(e,i){super();g(this,"width");g(this,"lastPoint");g(this,"polylines");g(this,"bounds");this.width=0,this.bounds=new p.Box2,this.lastPoint=e,this.polylines=i,this.width=this.calcWidth(i)}offset(e){const i=[];for(let s=0;s<this.polylines.length;s++){const n=this.polylines[s],r=[];for(let a=0;a<n.length;a++){const o=n[a];r.push(o.clone().add(e))}i.push(r)}return new ys(this.lastPoint,i)}transform(e){const i=[];for(let s=0;s<this.polylines.length;s++){const n=this.polylines[s],r=[];for(let a=0;a<n.length;a++){const o=n[a];r.push(o.clone().applyMatrix3(e))}i.push(r)}return new ys(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let r=0;r<e.length;r++){const a=e[r];for(let o=0;o<a.length;o++){const l=a[o];i.expandByPoint(l)}}const s=i.min.x||0;return(i.max.x||0)-s}toThreeGeometry(){const e=this.polylines,i=[],s=[];let n=0;const r=new p.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const h=o[l];i.push(h.x,h.y,0),l===o.length-1||s.push(n,n+1),n++}}return r.userData={advanceWidth:this.width},r.setAttribute("position",new p.Float32BufferAttribute(i,3)),r.setIndex(s),r}}const yt=class yt{static parserHeader(t,e){let i="",s=!1,n=0;const r=!0;for(;r;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[n]?n++:(s=!1,n=0);else{if(o===e[n]){s=!0,n++;continue}i+=o}if(s&&n===e.length)break}return i}static getCode(t){const e=cu(t);return e.length<2?e[0]:e.length<4?Q.ToUInt16(e,0):Q.ToUInt32(e,0)}static parserCode(t,e,i){let s=new p.Vector2;const n=[];let r=[];const a=[];let o=!1;for(let l=0;l<e.length;l++){const h=e[l];switch(h){case 0:break;case 1:o=!0,r.push(s.clone());break;case 2:o=!1,r.length>1?(n.push(r.slice()),r=[]):s.set(0,0);break;case 3:l++,i/=e[l];break;case 4:l++,i*=e[l];break;case 5:if(a.length===4)throw"The position stack is only four locations deep";a.push(s.clone());break;case 6:if(a.length===0)break;s=a.pop(),r.length>1&&(n.push(r.slice()),r=[]),o&&r.push(s.clone());break;case 7:{let d=0,u,f=i*t.baseUp;const m=s.clone();switch(r.length>1&&(n.push(r.slice()),r=[]),t.fontType){case He.Shapes:l++,d=e[l];break;case He.Bigfont:l++,d=e[l],d==0&&(l++,d=Q.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),m.x=e[l++]*i,m.y=e[l++]*i,f=e[l]*i);break;case He.Unifont:l+=2,d=Q.ToUInt16(new Uint8Array([e[l-1],e[l]]),0);break}d!==0&&(u=t.getGraphicDataByCodeWithOffset(d,f,m),u&&(n.push(...u.polylines.slice()),s=u.lastPoint.clone()))}break;case 8:{const d=new p.Vector2;d.x=Q.byteTosbyte(e[++l]),d.y=Q.byteTosbyte(e[++l]),s.add(d.multiplyScalar(i)),o&&r.push(s.clone())}break;case 9:for(;;){const u=new p.Vector2;if(u.x=Q.byteTosbyte(e[++l]),u.y=Q.byteTosbyte(e[++l]),!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;s.add(u.multiplyScalar(i)),o&&r.push(s.clone())}break;case 10:{const d=e[++l]*i,u=Q.byteTosbyte(e[++l]),f=(u&112)>>4;let m=u&7;m==0&&(m=8);const b=Math.PI/4;let y=b*m,C=yt.CIRCLE_SPAN;u<0&&(C=-C,y=-y);const w=b*f,x=w+y,E=s.clone().sub(new p.Vector2(Math.cos(w)*d,Math.sin(w)*d));if(s=E.clone().add(new p.Vector2(Math.cos(x)*d,Math.sin(x)*d)),o){let M=w;const O=!0;for(;O&&(M+=C,!!Number.isFinite(M));)if(u>=0&&M<x||u<0&&M>x)r.push(E.clone().add(new p.Vector2(d*Math.cos(M),d*Math.sin(M))));else break;r.push(s.clone())}}break;case 11:{const d=e[++l],u=e[++l],f=e[++l],m=e[++l],b=(f*255+m)*i,y=Q.byteTosbyte(e[++l]),C=(y&112)>>4;let w=y&7;w==0&&(w=8),u!=0&&w--;const x=Math.PI/4;let E=x*w,M=yt.CIRCLE_SPAN,O=1;y<0&&(M=-M,E=-E,O=-1);let S=x*C,v=S+E;S+=x*d/256*O,v+=x*u/256*O;const T=s.clone().sub(new p.Vector2(b*Math.cos(S),b*Math.sin(S)));if(s=T.clone().add(new p.Vector2(b*Math.cos(v),b*Math.sin(v))),o){let _=S;const A=!0;for(;A&&(_+=M,!!Number.isFinite(_));)if(y>0&&_<v||y<0&&_>v)r.push(T.clone().add(new p.Vector2(b*Math.cos(_),b*Math.sin(_))));else break;r.push(s.clone())}}break;case 12:{const d=new p.Vector2;d.x=Q.byteTosbyte(e[++l])*i,d.y=Q.byteTosbyte(e[++l])*i;let u=Q.byteTosbyte(e[++l]);u<-127&&(u=-127),o&&(u==0?r.push(s.clone().add(d)):r.push(yt.generateArcPoints(s,d,u/127))),s.add(d)}break;case 13:for(;;){const u=new p.Vector2;if(u.x=Q.byteTosbyte(e[++l])*i,u.y=Q.byteTosbyte(e[++l])*i,!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;let f=Q.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?r.push(s.clone().add(u)):r.push(yt.generateArcPoints(s.clone(),u,f/127))),s.add(u)}break;case 14:l=yt.skipCode(t,e,++l);break;default:if(h>15){const d=(h&240)>>4,u=h&15,f=new p.Vector2;switch(u){case 0:f.x=1;break;case 1:f.x=1,f.y=.5;break;case 2:f.x=1,f.y=1;break;case 3:f.x=.5,f.y=1;break;case 4:f.y=1;break;case 5:f.x=-.5,f.y=1;break;case 6:f.x=-1,f.y=1;break;case 7:f.x=-1,f.y=.5;break;case 8:f.x=-1;break;case 9:f.x=-1,f.y=-.5;break;case 10:f.x=-1,f.y=-1;break;case 11:f.x=-.5,f.y=-1;break;case 12:f.y=-1;break;case 13:f.x=.5,f.y=-1;break;case 14:f.x=1,f.y=-1;break;case 15:f.x=1,f.y=-.5;break}s.add(f.multiplyScalar(d*i)),o&&r.push(s.clone())}break}}return new ys(s,n)}static skipCode(t,e,i){switch(e[i]){case 0:break;case 1:break;case 2:break;case 3:case 4:i++;break;case 5:break;case 6:break;case 7:switch(t.fontType){case He.Shapes:i++;break;case He.Bigfont:i++,e[i]==0&&(i+=6);break;case He.Unifont:i+=2;break}break;case 8:i+=2;break;case 9:for(;;){const r=e[++i],a=e[++i];if(r===void 0||a===void 0||r==0&&a==0)break}break;case 10:i+=2;break;case 11:i+=5;break;case 12:i+=3;break;case 13:for(;;){const r=e[++i],a=e[++i];if(r===void 0||a===void 0||r==0&&a==0)break;e[++i]}break}return i}static generateArcPoints(t,e,i){const s=t.clone().add(e),n=i<0,r=!1;i=Math.abs(i);const a=e.length()/2,o=a*i,l=2*Math.atan(1/i),h=new p.Vector2(e.y,-e.x);h.normalize(),h.multiplyScalar(o);const d=Math.abs(a/Math.sin(l/2)),u=t.add(e.divideScalar(2));r!==n?u.add(h):u.sub(h);const f=t.sub(u),m=s.sub(u);let b=Math.atan2(f.y,f.x);const y=Math.atan2(m.y,m.x);let C=yt.CIRCLE_SPAN;n?(C=-C,b<y&&(b+=2*Math.PI)):b>y&&(b-=2*Math.PI);let w=b;const x=!0;for(;x;){if(w+=C,!n&&w<y||n&&w>y)return u.add(new p.Vector2(d*Math.cos(w),d*Math.sin(w)));break}return s}};g(yt,"FILE_STOP_FLAG",["\r",`
1532
+ `,""]),g(yt,"CIRCLE_SPAN",Math.PI/18);let Lt=yt;const sr={130:[[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],131:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],132:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]]],133:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]]],134:[[[3,0],[7,0]],[[5,0],[5,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],135:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],136:[[[3,0],[7,0]],[[4,0],[4,9.5]],[[6,0],[6,9.5]],[[4,7.1],[2.6,6.6],[2.1,6.2],[1.7,5.4],[1.6,4],[2.1,3],[2.6,2.6],[3.9,2.2],[6.1,2.2],[7.5,2.6],[8,3.1],[8.4,3.9],[8.4,5.2],[7.9,6.1],[7.5,6.6],[6.1,7.1],[4,7.1]],[[3,9.5],[7,9.5]],[[12,10],[9,10],[9,6]],[[9,8],[11,8]]],178:[[[1.142,9.285],[1.142,9.428],[1.285,9.714],[1.428,9.857],[1.714,10],[2.285,10],[2.571,9.857],[2.714,9.714],[2.857,9.428],[2.857,9.142],[2.714,8.857],[2.428,8.428],[1,7],[3,7]]],8960:[[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]],[[0,0],[8,8]]],20393:[[[0,0],[0,6.666]],[[0,4.761],[1.428,6.19],[2.38,6.666],[3.809,6.666],[4.761,6.19],[5.238,4.761],[5.238,0]],[[5.238,4.761],[6.666,6.19],[7.619,6.666],[9.047,6.666],[10,6.19],[10.476,4.761],[10.476,0]],[[11.142,9.285],[11.142,9.428],[11.285,9.714],[11.428,9.857],[11.714,10],[12.285,10],[12.571,9.857],[12.714,9.714],[12.857,9.428],[12.857,9.142],[12.714,8.857],[12.428,8.428],[11,7],[13,7]]],41123:[],55714:[[[2,5.9],[2.6,6.1],[3.4,7],[3.4,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],55970:[[[2.3,5.6],[2.3,5.9],[2.6,6.4],[2.9,6.7],[3.4,7],[4.6,7],[5.1,6.7],[5.4,6.4],[5.7,5.9],[5.7,5.3],[5.4,4.7],[4.9,3.9],[2,1],[6,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56226:[[[2.6,7],[5.7,7],[4,4.7],[4.9,4.7],[5.4,4.4],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56482:[[[4.9,7],[2,3],[6.3,3]],[[4.9,7],[4.9,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56738:[[[5.4,7],[2.6,7],[2.3,4.4],[2.6,4.7],[3.4,5],[4.3,5],[5.1,4.7],[5.7,4.1],[6,3.3],[6,2.7],[5.7,1.9],[5.1,1.3],[4.3,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],56994:[[[5.4,6.1],[5.1,6.7],[4.3,7],[3.7,7],[2.9,6.7],[2.3,5.9],[2,4.4],[2,3],[2.3,1.9],[2.9,1.3],[3.7,1],[4,1],[4.9,1.3],[5.4,1.9],[5.7,2.7],[5.7,3],[5.4,3.9],[4.9,4.4],[4,4.7],[3.7,4.7],[2.9,4.4],[2.3,3.9],[2,3]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57250:[[[2,7],[6,7],[3.1,1]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57506:[[[3.4,7],[2.6,6.7],[2.3,6.1],[2.3,5.6],[2.6,5],[3.1,4.7],[4.3,4.4],[5.1,4.1],[5.7,3.6],[6,3],[6,2.1],[5.7,1.6],[5.4,1.3],[4.6,1],[3.4,1],[2.6,1.3],[2.3,1.6],[2,2.1],[2,3],[2.3,3.6],[2.9,4.1],[3.7,4.4],[4.9,4.7],[5.4,5],[5.7,5.6],[5.7,6.1],[5.4,6.7],[4.6,7],[3.4,7]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],57762:[[[5.7,5],[5.4,4.1],[4.9,3.6],[4,3.3],[3.7,3.3],[2.9,3.6],[2.3,4.1],[2,5],[2,5.3],[2.3,6.1],[2.9,6.7],[3.7,7],[4,7],[4.9,6.7],[5.4,6.1],[5.7,5],[5.7,3.6],[5.4,2.1],[4.9,1.3],[4,1],[3.4,1],[2.6,1.3],[2.3,1.9]],[[2.9,8],[1.7,7.4],[.6,6.3],[0,4.6],[0,3.4],[.6,1.7],[1.7,.6],[2.9,0],[4.6,0],[5.7,.6],[6.9,1.7],[7.4,3.4],[7.4,4.6],[6.9,6.3],[5.7,7.4],[4.6,8],[2.9,8]]],60070:[[[0,6],[10,6],[10,4]]],60326:[[[0,7],[0,5],[10,5]]]},ro=new p.Matrix3,us=class us extends al{constructor(e,i){super(e,i);g(this,"isExtend");g(this,"isUniCode");g(this,"isEmbedded");g(this,"fontType");g(this,"textShapesCache");g(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=He.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new vs(i),n=Lt.parserHeader(s,Lt.FILE_STOP_FLAG),r=n.split(" ");switch(r[1]){case"shapes":this.parseShapeFont(s),this.fontType=He.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=He.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=He.Unifont;break}this.fileHeader=r[0],this.fileVersion=r[2]}else this.setFontFile(i)}generateShapes(e,i){const s=[];let n=0;for(let r=0;r<e.length;r++){const a=e[r];if(a===" "){n+=i;continue}const o=this.getCharShape(a,i);if(!o){n+=i,this.addUnsupportedChar(a);continue}s.push(o.offset(new p.Vector2(n,0))),n+=o.width}return s}getCharShape(e,i){let s=Lt.getCode(e);s===0&&(s=e.charCodeAt(0));const n=this.getGraphicDataByCode(s,i);if(!n)return this.addUnsupportedChar?.(e),null;if(n.polylines&&n.polylines.length===0&&(n.width=i*.8),typeof n.width!="number"||n.width<=0){const r=n,a=r.xMin!=null?r.xMin:0,o=r.xMax!=null?r.xMax:0;n.width=Math.max(.1,o-a)}return n}getGraphicDataByCode(e,i){const s=e+"_"+i;if(this.textShapesCache.has(s))return this.textShapesCache.get(s);if(e===0)return;const n=this.data;let r;if(!this.graphicData.has(e)){if(n[e]){const a=n[e],o=us.DEFAULT_SIZE/this.baseUp;r=Lt.parserCode(this,a,o),this.graphicData.set(e,r)}else if(sr[e]){const a=[];for(let o=0;o<sr[e].length;o++)a.push(sr[e][o].map(l=>new p.Vector2(l[0],l[1])));r=new ys(new p.Vector2,a),this.graphicData.set(e,r)}}if(this.graphicData.has(e)){const a=i/us.DEFAULT_SIZE;ro.identity().scale(a,a),r=this.graphicData.get(e).transform(ro)}return r}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){Q.ToInt16(e.readBytes(2),0);const i=Q.ToInt16(e.readBytes(2),0),s=Q.ToInt16(e.readBytes(2),0);for(let l=0;l<s;l++)e.readBytes(2),e.readBytes(2);const n=[];for(let l=0;l<i;l++){const h=e.readBytes(8),d=Q.ToUInt16(new Uint8Array([h[1],h[0]]),0),u=Q.ToUInt16(h,2),f=Q.ToUInt32(h,4);d===0&&u===0&&f===0||n.push({code:d,length:u,offset:f})}const r={};for(const l of n)e.setPosition(l.offset),r[l.code]=e.readBytes(l.length);const a=r[0];this.info=hu(a);let o=this.info.indexOf("\0")+1;a.length-o===4?(this.baseUp=a[o++],this.baseDown=a[o++],this.orientation=a[o++]):(this.baseUp=a[o++],o++,this.orientation=a[o++],this.baseDown=a[o++],this.isExtend=!0),this.data=r}parseUniFont(e){const i=Q.ToInt32(e.readBytes(4),0),s=Q.ToInt16(e.readBytes(2),0),n=e.readBytes(s);this.info=new TextDecoder().decode(n);let r=this.info.indexOf("\0");this.baseUp=n[++r],this.baseDown=n[++r],this.orientation=n[++r],this.isUniCode=n[++r]==0,this.isEmbedded=n[++r]==0;const a={};for(let o=0;o<i-1;o++){const l=Q.ToUInt16(e.readBytes(2),0),h=Q.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(h)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=Q.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=Q.ToUInt16(e.readBytes(2),0),h=Q.ToUInt16(e.readBytes(2),0);s.push({code:l,length:h})}const n={};for(const o of s)n[o.code]=e.readBytes(o.length);const r=n[0];this.info=new TextDecoder().decode(r);let a=this.info.indexOf("\0");this.baseUp=r[++a],this.baseDown=r[++a],this.orientation=r[++a],this.data=n}getNotFoundTextShape(e){let i=0;return this.fontType===He.Bigfont&&(i=Lt.getCode("?")),this.fontType===He.Unifont&&(i=Lt.getCode("?")),this.getGraphicDataByCode(i,e)}getFontFile(){return{fontType:this.fontType,order:this.order,data:this.data,info:this.info,orientation:this.orientation,baseUp:this.baseUp,baseDown:this.baseDown,fileName:this.fileName,fileHeader:this.fileHeader,fileVersion:this.fileVersion}}setFontFile(e){this.fileName=e.fileName,this.fontType=e.fontType||He.Unifont,this.data=e.data,this.info=e.info,this.order=e.order,this.orientation=e.orientation,this.baseUp=e.baseUp,this.baseDown=e.baseDown,this.fileHeader=e.fileHeader,this.fileVersion=e.fileVersion}releaseFontData(){super.releaseFontData(),this.graphicData.clear(),this.textShapesCache.clear()}};g(us,"DEFAULT_SIZE",12);let gt=us;function hu(c){let t,e,i,s,n;t="";const r=c.length;for(e=0;e<r;)switch(i=c[e++],i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(i);break;case 12:case 13:s=c[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=c[e++],n=c[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(n&63)<<0);break}return t}class xt{constructor(){g(this,"loader");g(this,"fontMap");g(this,"fileNames");g(this,"unsupportedChars");g(this,"missingFonts");g(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new p.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:xt.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,n=[],r=[];typeof i=="object"?(n=Object.keys(i),r=Object.values(i),s=n[0]):s=xt.getFileName(i.toLowerCase());let a;if(n.length){const o=n[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new gt(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}}else if(xt.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new ei(s,o)}else if(xt.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new gt(s,o)}else if(xt.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ei(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&Be.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}let s=this.fontMap.get(e.toLowerCase());return!s&&(s=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++),s?.generateShapes(t,i)}getCharShape(t,e,i){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}e==null&&(e="");const s=t.charCodeAt(0)>255,n=o=>{const l=o.getCharShape(t,i);if(l&&!(s&&o instanceof gt&&l.width<i*.5))return l};let r=this.fontMap.get(e.toLowerCase());if(!r){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,o]of this.fontMap)if(n(o)){r=o;break}}let a=r?.getCharShape(t,i);if(a&&s&&r instanceof gt&&a.width<i*.5&&(a=void 0),!a)for(const[,o]of this.fontMap){if(o===r)continue;const l=n(o);if(l){r=o,a=l;break}}if(a){if(r instanceof gt)return a.toThreeGeometry();if(r instanceof ei)return new Nl.TextGeometry(t,{font:r,depth:0,size:i||12,curveSegments:3,bevelSegments:3})}}getNotFoundTextShape(t){let e,i;for(const[,s]of this.fontMap){const n=s.getNotFoundTextShape(t);if(n){e=n,i=s;break}}if(i instanceof gt)return e.toThreeGeometry();if(i instanceof ei)return new p.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!Be.isBrowser)return!1;let e=!1;for(let i=0;i<t.length;i++){const s=t[i];let n=null;typeof s=="object"?n=Object.keys(s)[0]:n=xt.getFileName(s.toLowerCase());const r=await Fi.instance().query(n);if(r)e=!0;else{e=!1;break}if(r.codes!==void 0){e=!1;break}}return e}async getFontFromIndexeddb(){if(this.fontMap.size!==0)return;const t=(await Fi.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:n}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let r;n?r=new gt(s,i):r=new ei(s,i),this.fontMap.set(s,r)}P.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){P.warn("[FontManager] no font loaded.");return}let e=this.fontMap.get(t);return!e&&(e=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[t]&&(this.missingFonts[t]=0),this.missingFonts[t]++),e instanceof gt}getUnsupportedChar(){return this.fontMap.forEach(t=>{Object.assign(this.unsupportedChars,t.unsupportedChars)}),this.unsupportedChars}releaseFontData(){this.fontMap.forEach(t=>{t.releaseFontData()}),this.fontMap.clear()}destroy(){this.releaseFontData(),this.fontMap.clear()}static isShxFile(t){return j.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(j.getExtension(t).toUpperCase())}static isJsonFile(t){return j.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class du{constructor(t){g(this,"object");this.object=t}instantiate(){const t=Date.now();this.instantiateInner(this.object),console.log("[Inst] instantiate() took "+(Date.now()-t)/1e3+"s")}instantiateInner(t){if(!t.children||t.children.length===0)return;const e=t.children.length,i={},s=[];for(let a=0;a<e;++a){const o=t.children[a];if(this.instantiateInner(o),o.children&&o.children.length>0||!o.geometry)continue;let l=!1;const h=Object.values(i);for(let d=h.length-1;d>=0;--d){const u=h[d].indexes[0],f=t.children[u];if(this.geometryEquals(o.geometry,f.geometry)&&xe.materialsEquals(o.material,f.material)){!i[u]&&(i[u]={indexes:[u]},this.removeFromArray(s,u)),i[u].indexes.push(a),l=!0;break}}for(let d=s.length-1;!l&&d>=0;--d){const u=s[d],f=t.children[u];if(this.geometryEquals(o.geometry,f.geometry)&&xe.materialsEquals(o.material,f.material)){!i[u]&&(i[u]={indexes:[u]},this.removeFromArray(s,u)),i[u].indexes.push(a),l=!0;break}}!l&&s.push(a)}if(Object.keys(i).length<=0)return;const n=[],r=[];Object.values(i).forEach(a=>{const o=a.indexes;r.push(...o);const l=t.children[o[0]];let h=l.material;if(h instanceof p.Material)h=h.clone();else if(Array.isArray(h)){const u=[];h.forEach(f=>u.push(f.clone())),h=u}const d=new p.InstancedMesh(l.geometry,h,o.length);d.name="[Instanced] "+l.name;for(let u=0;u<o.length;++u){const f=o[u],m=t.children[f];m.updateMatrix(),d.setMatrixAt(u,m.matrix)}d.matrixAutoUpdate=ct,d.updateMatrix(),n.push(d)}),r.sort((a,o)=>o-a),r.forEach(a=>t.remove(t.children[a])),n.forEach(a=>{a.parent=t,t.children.push(a)}),t.updateMatrix(),console.log("[Inst] "+r.length+"(out of "+e+") objects instanced to "+n.length+" InstancedMesh")}removeFromArray(t,e){for(let i=t.length-1;i>=0;--i)if(t[i]===e){t.splice(i,1);return}}geometryEquals(t,e){return N.geometriesEqual(t,e)}}class ol{constructor(){g(this,"TIMEOUT","timeout");g(this,"INTERVAL","interval");g(this,"timeoutMap",{});g(this,"intervalMap",{})}run(t=this.INTERVAL,e,i=16.7){const s=Date.now;let n=s(),r=n;const a=Symbol(""),o=()=>{this.setIdMap(a,t,o),r=s(),r-n>=i&&(t===this.intervalMap&&(n=s(),r=n),e(),t===this.TIMEOUT&&this.clearTimeout(a))};return this.setIdMap(a,t,o),a}setIdMap(t,e,i){const s=requestAnimationFrame(i);e===this.INTERVAL?this.intervalMap[t]=s:e===this.TIMEOUT&&(this.timeoutMap[t]=s)}setTimeout(t,e){return this.run(this.TIMEOUT,t,e)}clearTimeout(t){cancelAnimationFrame(this.timeoutMap[t])}setInterval(t,e){return this.run(this.INTERVAL,t,e)}clearInterval(t){cancelAnimationFrame(this.intervalMap[t])}}class yn{constructor(t){g(this,"buffer");g(this,"u8");this.buffer=t,this.u8=new Uint8Array(t)}getBit(t){var e=this.u8[t>>3],i=t&7;return(e&128>>i)>>7-i}setBit(t,e){var i=t>>3,s=this.u8[i],n=t&7;e?this.u8[i]=s|128>>n:this.u8[i]=s&~(128>>n)}getInt12(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],n=this.u8[e+2],r=t%8,a=8-r,o=Math.min(12-a,8),l=Math.max(12-a-o,0),h=~(255<<a),d=255<<8-o,u=255<<8-l;return i&=h,s&=d,n&=u,((i<<16)+(s<<8)+n>>12-r)-2048}setInt12(t,e){e+=2048;var i=t/8|0,s=t%8,n=e<<12-s,r=(n&16711680)>>16,a=(n&65280)>>8,o=n&255,l=8-s,h=Math.min(12-l,8),d=Math.max(12-l-h,0),u=255<<l;this.u8[i]=(this.u8[i]&u)+r;var f=~(255<<8-h);this.u8[i+1]=(this.u8[i+1]&f)+a;var m=~(255<<8-d);this.u8[i+2]=(this.u8[i+2]&m)+o}getInt6(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],n=t%8,r=8-n,a=Math.max(6-r,0),o=~((255<<r)+(255>>8-(2-n))),l=255<<8-a;return i&=o,s&=l,((i<<8)+s>>10-n)-32}setInt6(t,e){e+=32;var i=t/8|0,s=t%8,n=e<<10-s,r=(n&65280)>>8,a=n&255,o=8-s,l=Math.max(6-o,0),h=(255<<o)+(255>>8-(2-s));this.u8[i]=(this.u8[i]&h)+r;var d=~(255<<8-l);this.u8[i+1]=(this.u8[i+1]&d)+a}test(){var t=new ArrayBuffer(3),e=new yn(t),i,s;for(i=0;i<12;i++)for(s=-2048;s<2048;s++)if(e.setInt12(i,s),e.getInt12(i)!=s){console.log("12-bit prob at",i,s),console.log("expected",s,"got",e.getInt12(i));break}for(i=0;i<18;i++)for(s=-32;s<32;s++)if(e.setInt6(i,s),e.getInt6(i)!=s){console.log("6-bit prob at",i,s),console.log("expected",s,"got",e.getInt6(i));break}return e}}var ns=(c=>(c[c.NULL=0]="NULL",c[c.POINT=1]="POINT",c[c.POLYLINE=3]="POLYLINE",c[c.POLYGON=5]="POLYGON",c))(ns||{});class uu{parse(t){var e={},i=new DataView(t),s=0;if(e.fileCode=i.getInt32(s,!1),e.fileCode!=9994)throw new Error("Unknown file code: "+e.fileCode);for(s+=24,e.wordLength=i.getInt32(s,!1),e.byteLength=e.wordLength*2,s+=4,e.version=i.getInt32(s,!0),s+=4,e.shapeType=i.getInt32(s,!0),s+=4,e.minX=i.getFloat64(s,!0),e.minY=i.getFloat64(s+8,!0),e.maxX=i.getFloat64(s+16,!0),e.maxY=i.getFloat64(s+24,!0),e.minZ=i.getFloat64(s+32,!0),e.maxZ=i.getFloat64(s+40,!0),e.minM=i.getFloat64(s+48,!0),e.maxM=i.getFloat64(s+56,!0),s+=64,e.records=[];s<e.byteLength;){var n={};n.number=i.getInt32(s,!1),s+=4,n.length=i.getInt32(s,!1),s+=4;try{n.shape=this.parseShape(i,s,n.length)}catch(r){console.log(r,n)}s+=n.length*2,e.records.push(n)}return e}parseShape(t,e,i){var s=0,n=null,r={};switch(r.type=t.getInt32(e,!0),e+=4,r.type){case 0:break;case 1:r.content={x:t.getFloat64(e,!0),y:t.getFloat64(e+8,!0)};break;case 3:case 5:for(n=r.content={minX:t.getFloat64(e,!0),minY:t.getFloat64(e+8,!0),maxX:t.getFloat64(e+16,!0),maxY:t.getFloat64(e+24,!0),parts:new Int32Array(t.getInt32(e+32,!0)),points:new Float64Array(t.getInt32(e+36,!0)*2)},e+=40,s=0;s<n.parts.length;s++)n.parts[s]=t.getInt32(e,!0),e+=4;for(s=0;s<n.points.length;s++)n.points[s]=t.getFloat64(e,!0),e+=8;break;case 8:case 11:case 13:case 15:case 18:case 21:case 23:case 25:case 28:case 31:throw new Error("Shape type not supported: "+r.type+":"+ +r.type);default:throw new Error("Unknown shape type at "+(e-4)+": "+r.type)}return r}}class fu{constructor(){g(this,"LINE_MATERIAL");g(this,"MESH_MATERIAL");this.LINE_MATERIAL=new p.LineBasicMaterial({color:0,linewidth:2,opacity:.8,transparent:!0}),this.MESH_MATERIAL=new p.MeshBasicMaterial({color:1926655,opacity:.8,transparent:!0})}createModel(t){for(var e=[],i=[],s=0;s<t.records.length;s++){var n=t.records[s].shape;if(n.type===ns.POLYLINE||n.type===ns.POLYGON)for(var r=n.content.points,a=n.content.parts,o=0;o<a.length;o++){const m=[];for(var l=a[o],h=a[o+1]||r.length/2;l<h;l++){var d=r[l*2],u=r[l*2+1];m.push(new p.Vector3(d,u,0))}if(n.type===ns.POLYGON){const b=p.ShapeUtils.triangulateShape(m,[]),y=[];b.forEach(x=>y.push(...x));const C=new p.BufferGeometry;C.setFromPoints(m),C.setIndex(y),e.push(C);const w=new p.BufferGeometry;m.length>2&&!m[0].equals(m[m.length-1])&&m.push(m[0]),w.setFromPoints(m),i.push(w)}else{const b=new p.BufferGeometry;b.setFromPoints(m),i.push(b)}}}for(var f=new p.Object3D,s=0;s<i.length;s++)f.add(new p.Line(i[s],this.LINE_MATERIAL));for(var s=0;s<e.length;s++)f.add(new p.Mesh(e[s],this.MESH_MATERIAL));return console.log("parsed",e.length,i.length),f}loadCompressed(t){for(var e=this.deltaDecode6(t),i=[],s=[],n=0;n<e.length;n++){let d=[];if(e[n]===-32768){for(var r=[],a=1;a<d.length;a++)!(d[a-1].x==d[a].x&&d[a-1].y==d[a].y)&&r.push(d[a]);const u=new p.BufferGeometry;u.setFromPoints(r),i.push(u),d=[];continue}var o=e[n]*180/32767,l=e[n+1]*180/32767;n++,d.push(new p.Vector3(o,l,0))}for(var h=new p.Object3D,n=0;n<s.length;n++)h.add(new p.Line(s[n],this.LINE_MATERIAL));for(var n=0;n<i.length;n++)h.add(new p.Mesh(i[n],this.MESH_MATERIAL));return console.log("parsed compressed",i.length,s.length),h}compress(t){for(var e=[],i=0;i<t.records.length;i++){var s=t.records[i].shape;if(s.type===ns.POLYGON)for(var n=s.content.points,r=s.content.parts,a=0;a<r.length;a++){for(var o=r[a],l=r[a+1]||n.length/2;o<l;o++){var h=n[o*2],d=n[o*2+1];e.push(h/180*32767,d/180*32767)}e.push(-32768)}}var u=new Int16Array(e);console.log("16-bit quantized byteLength",u.buffer.byteLength);var f=this.deltaEncode6(u);return console.log("delta-encoded byteLength",f.byteLength),f}deltaEncode(t){for(var e=[],i=[],s=[],n=0,r=0,a=0,o=0;o<t.length;o++){if(t[o]==-32768){i.push(s),e.push(i),i=[],s=[],a+=3;continue}s.length==0?(n=t[o],r=t[o+1],s.push(n,r),a+=4,o++):Math.abs(n-t[o])>1023||Math.abs(r-t[o+1])>1023?(i.push(s),a+=1,s=[],n=t[o],r=t[o+1],s.push(n,r),a+=4,o++):(s.push((t[o]-n)/8,(t[o+1]-r)/8),n+=((t[o]-n)/8|0)*8,r+=((t[o+1]-r)/8|0)*8,a+=2,o++)}return this.storeDeltas(a,e)}deltaEncode6(t){var e=[],i=[],s=[],n=0,r=0,a=0,o=0;for(a=0;a<t.length;a++)t[a]=0|t[a]/16;for(a=0;a<t.length;a++){if(t[a]===-2048){i.push(s),e.push(i),i=[],s=[],o+=3;continue}s.length==0?(n=t[a],r=t[a+1],s.push(n,r),o+=4,a++):Math.abs(n-t[a])>31||Math.abs(r-t[a+1])>31?(i.push(s),o+=1,s=[],n=t[a],r=t[a+1],s.push(n,r),o+=4,a++):(s.push(t[a]-n,t[a+1]-r),n+=t[a]-n,r+=t[a+1]-r,o+=2,a++)}return this.storeDeltas6(o,e)}storeDeltas(t,e){for(var i=new ArrayBuffer(t),s=new DataView(i),n=0,r=0;r<e.length;r++){for(var a=e[r],o=0;o<a.length;o++){var l=a[o];s.setInt16(n,l[0]),n+=2,s.setInt16(n,l[1]),n+=2;for(var h=2;h<l.length;h++)s.setInt8(n++,l[h]);s.setInt8(n,-128),n+=1}s.setInt16(n,-32768),n+=2}return i}deltaDecode(t){for(var e=new DataView(t),i=0,s=[];i<t.byteLength;){var n=e.getInt16(i);if(i+=2,n===-32768){s.push(-32768);continue}var r=e.getInt16(i);for(i+=2,s.push(n,r);i<t.byteLength;){var a=e.getInt8(i);if(i++,a==-128)break;var o=e.getInt8(i);i++,n+=a*8,r+=o*8,s.push(n,r)}}return s}storeDeltas6(t,e){for(var i=new ArrayBuffer(Math.ceil(t*.75)+4),s=new yn(i),n=32,r=0;r<e.length;r++){for(var a=e[r],o=0;o<a.length;o++){var l=a[o];s.setInt12(n,l[0]),n+=12,s.setInt12(n,l[1]),n+=12;for(var h=2;h<l.length;h++)s.setInt6(n,l[h]),n+=6;s.setInt6(n,-32),n+=6}s.setInt12(n,-2048),n+=12}return new DataView(i).setUint32(0,n),i}deltaDecode6(t){for(var e=new DataView(t).getUint32(0),i=new yn(t),s=32,n=[];s<e;){var r=i.getInt12(s);if(s+=12,r===-2048){n.push(-2048);continue}var a=i.getInt12(s);for(s+=12,n.push(r,a);s<e;){var o=i.getInt6(s);if(s+=6,o===-32)break;var l=i.getInt6(s);s+=6,r+=o,a+=l,n.push(r,a)}}for(var h=0;h<n.length;h++)n[h]*=16;return n}}class pu{async load(t,e,i,s){this.updateProgress(i,0);const n=new XMLHttpRequest;n.responseType="arraybuffer",n.onload=()=>{this.updateProgress(i,50);const r=new uu,a=r.parse(n.response),o=new fu().createModel(a);this.updateProgress(i,100),e(o)},n.onerror=s,n.open("GET",t),n.send(null)}updateProgress(t,e){if(t){const i={lengthComputable:!0,loaded:e,total:100};t(new ProgressEvent("progress",i))}}}const fs=class fs{constructor(t){g(this,"gltfLoader");g(this,"font");g(this,"manager");this.manager=t}setLoadManager(t){this.manager=t}async loadLocalModel(t,e,i){const s=e.toLowerCase();return s.endsWith("fbx")?this.loadFbx(t,i):s.endsWith("obj")?this.loadObj(t,i):s.endsWith("stl")?this.loadStl(t,i):s.endsWith("ifc")?(P.warn("[LoadingHelper] IFC is not supported directly since three.js r150!"),Promise.reject("Not supported!")):s.endsWith("shp")?this.loadShp(t,i):s.endsWith("dae")?this.loadDae(t,i):s.endsWith("dxf")?this.loadDxf(t,i):s.endsWith("jpg")||s.endsWith("jpeg")||s.endsWith("png")?this.loadImage(t,i):this.loadGltf(t,i)}async loadModel(t,e,i){const s=t;if(!s)return Promise.resolve();let n=e?.toLowerCase()||"";if(!n){const r=s.split("?")[0].toLowerCase();if(r){const a=r.lastIndexOf(".");a!==-1&&(n=r.slice(a+1))}}if(n.endsWith("fbx"))return this.loadFbx(s,i);if(n.endsWith("obj"))return this.loadObj(s,i);if(n.endsWith("stl"))return this.loadStl(s,i);if(n.endsWith("ifc"))P.warn("[LoadingHelper] IFC is not supported directly since three.js r150!");else return n.endsWith("shp")?this.loadShp(s,i):n.endsWith("dae")?this.loadDae(s,i):n.endsWith("dxf")?this.loadDxf(s,i):n.endsWith("jpg")||n.endsWith("jpeg")||n.endsWith("png")?this.loadImage(s,i):this.loadGltf(s,i)}async loadGltf(t,e){const i=this.getGltfLoader();t.indexOf("#")!==-1&&console.warn("[LoadingHelper] '#' is not allowed in filename "+t),t=t.replace(/#/g,encodeURIComponent("#"));const s=r=>{r.total===0&&r.loaded>0||e&&e(r)},n=await i.loadAsync(t,s);return Promise.resolve(n.scene)}parseGltf(t,e,i,s){return this.getGltfLoader().parse(t,e,r=>i(r.scene),s)}async loadFbx(t,e){const i=new Xl.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new $l.OBJLoader(this.manager),s=new Kl.MTLLoader(this.manager),n=t.replace(".obj",".mtl"),r=await s.loadAsync(n,e);r.preload(),i.setMaterials(r);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new Ql.STLLoader(this.manager),s=await i.loadAsync(t,e),n=new p.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),r=new p.Mesh(s,n);return Promise.resolve(r)}async loadShp(t,e){const i=new pu;return new Promise((s,n)=>{i.load(t,r=>{s(r)},e,r=>{n(r)})})}async loadDae(t,e){const i=new Wl.ColladaLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s.scene)}async load3dm(t,e){return Promise.reject("3dm format is not supported since three.js r159 (Rhino3dmLoader removed)")}async loadDxf(t,e){this.font||console.warn("[LoadingHelper] Should set font first!");const i={ignorePaperSpace:!0,enableLocalCache:!1,overrideHatchPatternLineThickness:2},s=new X(this.manager,i);s.setFont(this.font),await this.font?.getFontFromIndexeddb();try{const n=await s.loadAsync(t,e);return Promise.resolve(n.threejsObject)}catch{const r=new ErrorEvent("");return Promise.reject(r)}}async loadPly(t,e){const i=new Jl.PLYLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(new p.Mesh(s))}async loadImage(t,e){const i=new p.TextureLoader(this.manager),s=await i.loadAsync(t,e);if(!s)return Promise.reject("Failed to load image!");const n=10,r=s.image;let a=r&&r.height||n,o=r&&r.width||n;a=n/o*a,o=n;const l=new p.MeshBasicMaterial({map:s,side:p.DoubleSide,transparent:!0}),h=new p.PlaneGeometry(o,a),d=new p.Mesh(h,l);return Promise.resolve(d)}async loadDxfData(t,e,i,s,n){this.font||console.warn("[LoadingHelper] Should set font first!");const r=new X(this.manager,n);return r.setFont(this.font),await this.font?.getFontFromIndexeddb(),r.manager.onLoad=()=>{s&&s()},r.loadEx(t,e,i)}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new Zl.GLTFLoader(this.manager);const t=new Yl.DRACOLoader(this.manager);t.setDecoderPath(fs.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};g(fs,"DecoderPath","libs/draco/gltf/"),g(fs,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let Vt=fs;const ll=`(function(){"use strict";function Ks(f){for(let t=f.length-1;t>=0;--t)if(f[t]>=65535)return!0;return!1}function ms(f){return document.createElementNS("http://www.w3.org/1999/xhtml",f)}const ps={};function xs(f){const t=f[0];if(typeof t=="string"&&t.startsWith("TSL:")){const e=f[1];e&&e.isStackTrace?f[0]+=" "+e.getLocation():f[1]='Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces.'}return f}function yt(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.warn(e.getError(t)):console.warn(t,...f)}}function Ut(...f){f=xs(f);const t="THREE."+f.shift();{const e=f[0];e&&e.isStackTrace?console.error(e.getError(t)):console.error(t,...f)}}function yi(...f){const t=f.join(" ");t in ps||(ps[t]=!0,yt(...f))}class Ve{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){const i=this._listeners;return i===void 0?!1:i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){const i=this._listeners;if(i===void 0)return;const s=i[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){const e=this._listeners;if(e===void 0)return;const i=e[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const $=["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 Re(){const f=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return($[f&255]+$[f>>8&255]+$[f>>16&255]+$[f>>24&255]+"-"+$[t&255]+$[t>>8&255]+"-"+$[t>>16&15|64]+$[t>>24&255]+"-"+$[e&63|128]+$[e>>8&255]+"-"+$[e>>16&255]+$[e>>24&255]+$[i&255]+$[i>>8&255]+$[i>>16&255]+$[i>>24&255]).toLowerCase()}function V(f,t,e){return Math.max(t,Math.min(e,f))}function me(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return f/4294967295;case Uint16Array:return f/65535;case Uint8Array:case Uint8ClampedArray:return f/255;case Int32Array:return Math.max(f/2147483647,-1);case Int16Array:return Math.max(f/32767,-1);case Int8Array:return Math.max(f/127,-1);default:throw new Error("THREE.MathUtils: Invalid component type.")}}function K(f,t){switch(t.constructor){case Float32Array:return f;case Uint32Array:return Math.round(f*4294967295);case Uint16Array:return Math.round(f*65535);case Uint8Array:case Uint8ClampedArray:return Math.round(f*255);case Int32Array:return Math.round(f*2147483647);case Int16Array:return Math.round(f*32767);case Int8Array:return Math.round(f*127);default:throw new Error("THREE.MathUtils: Invalid component type.")}}const hs=class hs{constructor(t=0,e=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("THREE.Vector2: 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("THREE.Vector2: 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,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,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 i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};hs.prototype.isVector2=!0;let Y=hs;class pe{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],c=i[s+1],h=i[s+2],u=i[s+3],l=n[r+0],d=n[r+1],y=n[r+2],m=n[r+3];if(u!==m||o!==l||c!==d||h!==y){let z=o*l+c*d+h*y+u*m;z<0&&(l=-l,d=-d,y=-y,m=-m,z=-z);let b=1-a;if(z<.9995){const p=Math.acos(z),x=Math.sin(p);b=Math.sin(b*p)/x,a=Math.sin(a*p)/x,o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a}else{o=o*b+l*a,c=c*b+d*a,h=h*b+y*a,u=u*b+m*a;const p=1/Math.sqrt(o*o+c*c+h*h+u*u);o*=p,c*=p,h*=p,u*=p}}t[e]=o,t[e+1]=c,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],c=i[s+2],h=i[s+3],u=n[r],l=n[r+1],d=n[r+2],y=n[r+3];return t[e]=a*y+h*u+o*d-c*l,t[e+1]=o*y+h*l+c*u-a*d,t[e+2]=c*y+h*d+a*l-o*u,t[e+3]=h*y-a*u-o*l-c*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,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,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 i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,c=a(i/2),h=a(s/2),u=a(n/2),l=o(i/2),d=o(s/2),y=o(n/2);switch(r){case"XYZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"YXZ":this._x=l*h*u+c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"ZXY":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u-l*d*y;break;case"ZYX":this._x=l*h*u-c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u+l*d*y;break;case"YZX":this._x=l*h*u+c*d*y,this._y=c*d*u+l*h*y,this._z=c*h*y-l*d*u,this._w=c*h*u-l*d*y;break;case"XZY":this._x=l*h*u-c*d*y,this._y=c*d*u-l*h*y,this._z=c*h*y+l*d*u,this._w=c*h*u+l*d*y;break;default:yt("Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],c=e[2],h=e[6],u=e[10],l=i+a+u;if(l>0){const d=.5/Math.sqrt(l+1);this._w=.25/d,this._x=(h-o)*d,this._y=(n-c)*d,this._z=(r-s)*d}else if(i>a&&i>u){const d=2*Math.sqrt(1+i-a-u);this._w=(h-o)/d,this._x=.25*d,this._y=(s+r)/d,this._z=(n+c)/d}else if(a>u){const d=2*Math.sqrt(1+a-i-u);this._w=(n-c)/d,this._x=(s+r)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+u-i-a);this._w=(r-s)/d,this._x=(n+c)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<1e-8?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(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=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(V(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),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 t===0?(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 i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,c=e._z,h=e._w;return this._x=i*h+r*a+s*c-n*o,this._y=s*h+r*o+n*a-i*c,this._z=n*h+r*c+i*o-s*a,this._w=r*h-i*a-s*o-n*c,this._onChangeCallback(),this}slerp(t,e){let i=t._x,s=t._y,n=t._z,r=t._w,a=this.dot(t);a<0&&(i=-i,s=-s,n=-n,r=-r,a=-a);let o=1-e;if(a<.9995){const c=Math.acos(a),h=Math.sin(c);o=Math.sin(o*c)/h,e=Math.sin(e*c)/h,this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this._onChangeCallback()}else this._x=this._x*o+i*e,this._y=this._y*o+s*e,this._z=this._z*o+n*e,this._w=this._w*o+r*e,this.normalize();return this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*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}}const ls=class ls{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,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("THREE.Vector3: 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("THREE.Vector3: 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(gs.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(gs.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,c=2*(r*s-a*i),h=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*c+r*u-a*h,this.y=i+o*h+a*c-n*u,this.z=s+o*u+n*h-r*c,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,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return mi.copy(this).projectOnVector(t),this.sub(mi)}reflect(t){return this.sub(mi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(V(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}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,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,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(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}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=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};ls.prototype.isVector3=!0;let S=ls;const mi=new S,gs=new pe,us=class us{constructor(t,e,i,s,n,r,a,o,c){this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c)}set(t,e,i,s,n,r,a,o,c){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.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 i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],c=i[1],h=i[4],u=i[7],l=i[2],d=i[5],y=i[8],m=s[0],z=s[3],b=s[6],p=s[1],x=s[4],g=s[7],w=s[2],B=s[5],_=s[8];return n[0]=r*m+a*p+o*w,n[3]=r*z+a*x+o*B,n[6]=r*b+a*g+o*_,n[1]=c*m+h*p+u*w,n[4]=c*z+h*x+u*B,n[7]=c*b+h*g+u*_,n[2]=l*m+d*p+y*w,n[5]=l*z+d*x+y*B,n[8]=l*b+d*g+y*_,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],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8];return e*r*h-e*a*c-i*n*h+i*a*o+s*n*c-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=h*r-a*c,l=a*o-h*n,d=c*n-r*o,y=e*u+i*l+s*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/y;return t[0]=u*m,t[1]=(s*c-h*i)*m,t[2]=(a*i-s*r)*m,t[3]=l*m,t[4]=(h*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=d*m,t[7]=(i*o-c*e)*m,t[8]=(r*e-i*n)*m,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,i,s,n,r,a){const o=Math.cos(n),c=Math.sin(n);return this.set(i*o,i*c,-i*(o*r+c*a)+r+t,-s*c,s*o,-s*(-c*r+o*a)+a+e,0,0,1),this}scale(t,e){return yi("Matrix3: .scale() is deprecated. Use .makeScale() instead."),this.premultiply(pi.makeScale(t,e)),this}rotate(t){return yi("Matrix3: .rotate() is deprecated. Use .makeRotation() instead."),this.premultiply(pi.makeRotation(-t)),this}translate(t,e){return yi("Matrix3: .translate() is deprecated. Use .makeTranslation() instead."),this.premultiply(pi.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),i=Math.sin(t);return this.set(e,-i,0,i,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,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}};us.prototype.isMatrix3=!0;let xt=us;const pi=new xt;function xi(f){return f<.04045?f*.0773993808:Math.pow(f*.9478672986+.0521327014,2.4)}let Zt;class tn{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let i;if(t instanceof HTMLCanvasElement)i=t;else{Zt===void 0&&(Zt=ms("canvas")),Zt.width=t.width,Zt.height=t.height;const s=Zt.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),i=Zt}return i.toDataURL(e)}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=ms("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=xi(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(xi(e[i]/255)*255):e[i]=xi(e[i]);return{data:e,width:t.width,height:t.height}}else return yt("ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let en=0;class sn{constructor(t=null){this.isTextureSource=!0,Object.defineProperty(this,"id",{value:en++}),this.uuid=Re(),this.data=t,this.dataReady=!0,this.version=0}getSize(t){const e=this.data;return typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement?t.set(e.videoWidth,e.videoHeight,0):typeof VideoFrame<"u"&&e instanceof VideoFrame?t.set(e.displayWidth,e.displayHeight,0):e!==null?t.set(e.width,e.height,e.depth||0):t.set(0,0,0),t}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(gi(s[r].image)):n.push(gi(s[r]))}else n=gi(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function gi(f){return typeof HTMLImageElement<"u"&&f instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&f instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&f instanceof ImageBitmap?tn.getDataURL(f):f.data?{data:Array.from(f.data),width:f.width,height:f.height,type:f.data.constructor.name}:(yt("Texture: Unable to serialize Texture."),{})}let nn=0;const wi=new S;class Nt extends Ve{constructor(t=Nt.DEFAULT_IMAGE,e=Nt.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,c=Nt.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:nn++}),this.uuid=Re(),this.name="",this.source=new sn(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=c,this.format=a,this.internalFormat=null,this.type=o,this.offset=new Y(0,0),this.repeat=new Y(1,1),this.center=new Y(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new xt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.isArrayTexture=!!(t&&t.depth&&t.depth>1),this.pmremVersion=0,this.normalized=!1}get width(){return this.source.getSize(wi).x}get height(){return this.source.getSize(wi).y}get depth(){return this.source.getSize(wi).z}get image(){return this.source.data}set image(t){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.normalized=t.normalized,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const i=t[e];if(i===void 0){yt(\`Texture.setValues(): parameter '\${e}' has value of undefined.\`);continue}const s=this[e];if(s===void 0){yt(\`Texture.setValues(): property '\${e}' does not exist.\`);continue}s&&i&&s.isVector2&&i.isVector2||s&&i&&s.isVector3&&i.isVector3||s&&i&&s.isMatrix3&&i.isMatrix3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,normalized:this.normalized,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&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==300)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 1001:t.x=t.x<0?0:1;break;case 1002:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case 1e3:t.y=t.y-Math.floor(t.y);break;case 1001:t.y=t.y<0?0:1;break;case 1002:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}Nt.DEFAULT_IMAGE=null,Nt.DEFAULT_MAPPING=300,Nt.DEFAULT_ANISOTROPY=1;const fs=class fs{constructor(t=0,e=0,i=0,s=1){this.x=t,this.y=e,this.z=i,this.w=s}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,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,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("THREE.Vector4: 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("THREE.Vector4: 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=t.w!==void 0?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,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,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,i,s,n;const o=t.elements,c=o[0],h=o[4],u=o[8],l=o[1],d=o[5],y=o[9],m=o[2],z=o[6],b=o[10];if(Math.abs(h-l)<.01&&Math.abs(u-m)<.01&&Math.abs(y-z)<.01){if(Math.abs(h+l)<.1&&Math.abs(u+m)<.1&&Math.abs(y+z)<.1&&Math.abs(c+d+b-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const x=(c+1)/2,g=(d+1)/2,w=(b+1)/2,B=(h+l)/4,_=(u+m)/4,M=(y+z)/4;return x>g&&x>w?x<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(x),s=B/i,n=_/i):g>w?g<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(g),i=B/s,n=M/s):w<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(w),i=_/n,s=M/n),this.set(i,s,n,e),this}let p=Math.sqrt((z-y)*(z-y)+(u-m)*(u-m)+(l-h)*(l-h));return Math.abs(p)<.001&&(p=1),this.x=(z-y)/p,this.y=(u-m)/p,this.z=(l-h)/p,this.w=Math.acos((c+d+b-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=V(this.x,t.x,e.x),this.y=V(this.y,t.y,e.y),this.z=V(this.z,t.z,e.z),this.w=V(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=V(this.x,t,e),this.y=V(this.y,t,e),this.z=V(this.z,t,e),this.w=V(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(V(i,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,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,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}};fs.prototype.isVector4=!0;let xe=fs;const ui=class ui{constructor(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z)}set(t,e,i,s,n,r,a,o,c,h,u,l,d,y,m,z){const b=this.elements;return b[0]=t,b[4]=e,b[8]=i,b[12]=s,b[1]=n,b[5]=r,b[9]=a,b[13]=o,b[2]=c,b[6]=h,b[10]=u,b[14]=l,b[3]=d,b[7]=y,b[11]=m,b[15]=z,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 ui().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[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,i){return this.determinantAffine()===0?(t.set(1,0,0),e.set(0,1,0),i.set(0,0,1),this):(t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this)}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){if(t.determinantAffine()===0)return this.identity();const e=this.elements,i=t.elements,s=1/$t.setFromMatrixColumn(t,0).length(),n=1/$t.setFromMatrixColumn(t,1).length(),r=1/$t.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),c=Math.sin(s),h=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=-o*u,e[8]=c,e[1]=d+y*c,e[5]=l-m*c,e[9]=-a*o,e[2]=m-l*c,e[6]=y+d*c,e[10]=r*o}else if(t.order==="YXZ"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l+m*a,e[4]=y*a-d,e[8]=r*c,e[1]=r*u,e[5]=r*h,e[9]=-a,e[2]=d*a-y,e[6]=m+l*a,e[10]=r*o}else if(t.order==="ZXY"){const l=o*h,d=o*u,y=c*h,m=c*u;e[0]=l-m*a,e[4]=-r*u,e[8]=y+d*a,e[1]=d+y*a,e[5]=r*h,e[9]=m-l*a,e[2]=-r*c,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const l=r*h,d=r*u,y=a*h,m=a*u;e[0]=o*h,e[4]=y*c-d,e[8]=l*c+m,e[1]=o*u,e[5]=m*c+l,e[9]=d*c-y,e[2]=-c,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=m-l*u,e[8]=y*u+d,e[1]=u,e[5]=r*h,e[9]=-a*h,e[2]=-c*h,e[6]=d*u+y,e[10]=l-m*u}else if(t.order==="XZY"){const l=r*o,d=r*c,y=a*o,m=a*c;e[0]=o*h,e[4]=-u,e[8]=c*h,e[1]=l*u+m,e[5]=r*h,e[9]=d*u-y,e[2]=y*u-d,e[6]=a*h,e[10]=m*u+l}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(rn,t,on)}lookAt(t,e,i){const s=this.elements;return et.subVectors(t,e),et.lengthSq()===0&&(et.z=1),et.normalize(),Pt.crossVectors(i,et),Pt.lengthSq()===0&&(Math.abs(i.z)===1?et.x+=1e-4:et.z+=1e-4,et.normalize(),Pt.crossVectors(i,et)),Pt.normalize(),ke.crossVectors(et,Pt),s[0]=Pt.x,s[4]=ke.x,s[8]=et.x,s[1]=Pt.y,s[5]=ke.y,s[9]=et.y,s[2]=Pt.z,s[6]=ke.z,s[10]=et.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],c=i[12],h=i[1],u=i[5],l=i[9],d=i[13],y=i[2],m=i[6],z=i[10],b=i[14],p=i[3],x=i[7],g=i[11],w=i[15],B=s[0],_=s[4],M=s[8],P=s[12],A=s[1],C=s[5],T=s[9],E=s[13],I=s[2],F=s[6],R=s[10],Z=s[14],tt=s[3],dt=s[7],at=s[11],pt=s[15];return n[0]=r*B+a*A+o*I+c*tt,n[4]=r*_+a*C+o*F+c*dt,n[8]=r*M+a*T+o*R+c*at,n[12]=r*P+a*E+o*Z+c*pt,n[1]=h*B+u*A+l*I+d*tt,n[5]=h*_+u*C+l*F+d*dt,n[9]=h*M+u*T+l*R+d*at,n[13]=h*P+u*E+l*Z+d*pt,n[2]=y*B+m*A+z*I+b*tt,n[6]=y*_+m*C+z*F+b*dt,n[10]=y*M+m*T+z*R+b*at,n[14]=y*P+m*E+z*Z+b*pt,n[3]=p*B+x*A+g*I+w*tt,n[7]=p*_+x*C+g*F+w*dt,n[11]=p*M+x*T+g*R+w*at,n[15]=p*P+x*E+g*Z+w*pt,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],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],c=t[13],h=t[2],u=t[6],l=t[10],d=t[14],y=t[3],m=t[7],z=t[11],b=t[15],p=o*d-c*l,x=a*d-c*u,g=a*l-o*u,w=r*d-c*h,B=r*l-o*h,_=r*u-a*h;return e*(m*p-z*x+b*g)-i*(y*p-z*w+b*B)+s*(y*x-m*w+b*_)-n*(y*g-m*B+z*_)}determinantAffine(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[1],r=t[5],a=t[9],o=t[2],c=t[6],h=t[10];return e*(r*h-a*c)-i*(n*h-a*o)+s*(n*c-r*o)}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,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],c=t[7],h=t[8],u=t[9],l=t[10],d=t[11],y=t[12],m=t[13],z=t[14],b=t[15],p=e*a-i*r,x=e*o-s*r,g=e*c-n*r,w=i*o-s*a,B=i*c-n*a,_=s*c-n*o,M=h*m-u*y,P=h*z-l*y,A=h*b-d*y,C=u*z-l*m,T=u*b-d*m,E=l*b-d*z,I=p*E-x*T+g*C+w*A-B*P+_*M;if(I===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const F=1/I;return t[0]=(a*E-o*T+c*C)*F,t[1]=(s*T-i*E-n*C)*F,t[2]=(m*_-z*B+b*w)*F,t[3]=(l*B-u*_-d*w)*F,t[4]=(o*A-r*E-c*P)*F,t[5]=(e*E-s*A+n*P)*F,t[6]=(z*g-y*_-b*x)*F,t[7]=(h*_-l*g+d*x)*F,t[8]=(r*T-a*A+c*M)*F,t[9]=(i*A-e*T-n*M)*F,t[10]=(y*B-m*g+b*p)*F,t[11]=(u*g-h*B-d*p)*F,t[12]=(a*P-r*C-o*M)*F,t[13]=(e*C-i*P+s*M)*F,t[14]=(m*x-y*w-z*p)*F,t[15]=(h*w-u*x+l*p)*F,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){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,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,c=n*r,h=n*a;return this.set(c*r+i,c*a-s*o,c*o+s*a,0,c*a+s*o,h*a+i,h*o-s*r,0,c*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,c=n+n,h=r+r,u=a+a,l=n*c,d=n*h,y=n*u,m=r*h,z=r*u,b=a*u,p=o*c,x=o*h,g=o*u,w=i.x,B=i.y,_=i.z;return s[0]=(1-(m+b))*w,s[1]=(d+g)*w,s[2]=(y-x)*w,s[3]=0,s[4]=(d-g)*B,s[5]=(1-(l+b))*B,s[6]=(z+p)*B,s[7]=0,s[8]=(y+x)*_,s[9]=(z-p)*_,s[10]=(1-(l+m))*_,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;t.x=s[12],t.y=s[13],t.z=s[14];const n=this.determinantAffine();if(n===0)return i.set(1,1,1),e.identity(),this;let r=$t.set(s[0],s[1],s[2]).length();const a=$t.set(s[4],s[5],s[6]).length(),o=$t.set(s[8],s[9],s[10]).length();n<0&&(r=-r),ct.copy(this);const c=1/r,h=1/a,u=1/o;return ct.elements[0]*=c,ct.elements[1]*=c,ct.elements[2]*=c,ct.elements[4]*=h,ct.elements[5]*=h,ct.elements[6]*=h,ct.elements[8]*=u,ct.elements[9]*=u,ct.elements[10]*=u,e.setFromRotationMatrix(ct),i.x=r,i.y=a,i.z=o,this}makePerspective(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2*n/(e-t),u=2*n/(i-s),l=(e+t)/(e-t),d=(i+s)/(i-s);let y,m;if(o)y=n/(r-n),m=r*n/(r-n);else if(a===2e3)y=-(r+n)/(r-n),m=-2*r*n/(r-n);else if(a===2001)y=-r/(r-n),m=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=l,c[12]=0,c[1]=0,c[5]=u,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3,o=!1){const c=this.elements,h=2/(e-t),u=2/(i-s),l=-(e+t)/(e-t),d=-(i+s)/(i-s);let y,m;if(o)y=1/(r-n),m=r/(r-n);else if(a===2e3)y=-2/(r-n),m=-(r+n)/(r-n);else if(a===2001)y=-1/(r-n),m=-n/(r-n);else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return c[0]=h,c[4]=0,c[8]=0,c[12]=l,c[1]=0,c[5]=u,c[9]=0,c[13]=d,c[2]=0,c[6]=0,c[10]=y,c[14]=m,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}};ui.prototype.isMatrix4=!0;let H=ui;const $t=new S,ct=new H,rn=new S(0,0,0),on=new S(1,1,1),Pt=new S,ke=new S,et=new S,ws=new H,bs=new pe;class Ue{constructor(t=0,e=0,i=0,s=Ue.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}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,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,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,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],c=s[5],h=s[9],u=s[2],l=s[6],d=s[10];switch(e){case"XYZ":this._y=Math.asin(V(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(l,c),this._z=0);break;case"YXZ":this._x=Math.asin(-V(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,c)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(V(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-r,c)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-V(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(l,d),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,c));break;case"YZX":this._z=Math.asin(V(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,c),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-V(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(l,c),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,d),this._y=0);break;default:yt("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return ws.makeRotationFromQuaternion(t),this.setFromRotationMatrix(ws,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bs.setFromEuler(this),this.setFromQuaternion(bs,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],t[3]!==void 0&&(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}}Ue.DEFAULT_ORDER="XYZ";class an{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let cn=0;const zs=new S,Jt=new pe,gt=new H,Ne=new S,ge=new S,hn=new S,ln=new pe,_s=new S(1,0,0),Ms=new S(0,1,0),As=new S(0,0,1),Ss={type:"added"},un={type:"removed"},Gt={type:"childadded",child:null},bi={type:"childremoved",child:null};class Ct extends Ve{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:cn++}),this.uuid=Re(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Ct.DEFAULT_UP.clone();const t=new S,e=new Ue,i=new pe,s=new S(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new H},normalMatrix:{value:new xt}}),this.matrix=new H,this.matrixWorld=new H,this.matrixAutoUpdate=Ct.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new an,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.static=!1,this.userData={},this.pivot=null}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.multiply(Jt),this}rotateOnWorldAxis(t,e){return Jt.setFromAxisAngle(t,e),this.quaternion.premultiply(Jt),this}rotateX(t){return this.rotateOnAxis(_s,t)}rotateY(t){return this.rotateOnAxis(Ms,t)}rotateZ(t){return this.rotateOnAxis(As,t)}translateOnAxis(t,e){return zs.copy(t).applyQuaternion(this.quaternion),this.position.add(zs.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(_s,t)}translateY(t){return this.translateOnAxis(Ms,t)}translateZ(t){return this.translateOnAxis(As,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(gt.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ne.copy(t):Ne.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),ge.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?gt.lookAt(ge,Ne,this.up):gt.lookAt(Ne,ge,this.up),this.quaternion.setFromRotationMatrix(gt),s&&(gt.extractRotation(s.matrixWorld),Jt.setFromRotationMatrix(gt),this.quaternion.premultiply(Jt.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(Ut("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(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.child=null):Ut("Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(un),bi.child=t,this.dispatchEvent(bi),bi.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),gt.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),gt.multiply(t.parent.matrixWorld)),t.applyMatrix4(gt),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Ss),Gt.child=t,this.dispatchEvent(Gt),Gt.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 i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,t,hn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(ge,ln,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}intersectsFrustum(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);const t=this.pivot;if(t!==null){const e=t.x,i=t.y,s=t.z,n=this.matrix.elements;n[12]+=e-n[0]*e-n[4]*i-n[8]*s,n[13]+=i-n[1]*e-n[5]*i-n[9]*s,n[14]+=s-n[2]*e-n[6]*i-n[10]*s}this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e,i=!1){const s=this.parent;if(t===!0&&s!==null&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||i)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,i=!0),e===!0){const n=this.children;for(let r=0,a=n.length;r<a;r++)n[r].updateWorldMatrix(!1,!0,i)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.7,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,s.name=this.name,s.castShadow=this.castShadow,s.receiveShadow=this.receiveShadow,s.visible=this.visible,s.frustumCulled=this.frustumCulled,s.renderOrder=this.renderOrder,s.static=this.static,s.matrixAutoUpdate=this.matrixAutoUpdate,Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.pivot!==null&&(s.pivot=this.pivot.toArray()),this.morphTargetDictionary!==void 0&&(s.morphTargetDictionary=Object.assign({},this.morphTargetDictionary)),this.morphTargetInfluences!==void 0&&(s.morphTargetInfluences=this.morphTargetInfluences.slice()),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.geometryInfo=this._geometryInfo.map(a=>({...a,boundingBox:a.boundingBox?a.boundingBox.toJSON():void 0,boundingSphere:a.boundingSphere?a.boundingSphere.toJSON():void 0})),s.instanceInfo=this._instanceInfo.map(a=>({...a})),s.availableInstanceIds=this._availableInstanceIds.slice(),s.availableGeometryIds=this._availableGeometryIds.slice(),s.nextIndexStart=this._nextIndexStart,s.nextVertexStart=this._nextVertexStart,s.geometryCount=this._geometryCount,s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.matricesTexture=this._matricesTexture.toJSON(t),s.indirectTexture=this._indirectTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere=this.boundingSphere.toJSON()),this.boundingBox!==null&&(s.boundingBox=this.boundingBox.toJSON()));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let c=0,h=o.length;c<h;c++){const u=o[c];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,c=this.material.length;o<c;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),c=r(t.textures),h=r(t.images),u=r(t.shapes),l=r(t.skeletons),d=r(t.animations),y=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),c.length>0&&(i.textures=c),h.length>0&&(i.images=h),u.length>0&&(i.shapes=u),l.length>0&&(i.skeletons=l),d.length>0&&(i.animations=d),y.length>0&&(i.nodes=y)}return i.object=s,i;function r(a){const o=[];for(const c in a){const h=a[c];delete h.metadata,o.push(h)}return o}}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.pivot=t.pivot!==null?t.pivot.clone():null,this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.static=t.static,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}dispose(){this.dispatchEvent({type:"dispose"})}}Ct.DEFAULT_UP=new S(0,1,0),Ct.DEFAULT_MATRIX_AUTO_UPDATE=!0,Ct.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ht=new S,wt=new S,zi=new S,bt=new S,Qt=new S,jt=new S,Bs=new S,_i=new S,Mi=new S,Ai=new S,Si=new xe,Bi=new xe,Ti=new xe;class st{constructor(t=new S,e=new S,i=new S){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ht.subVectors(t,e),s.cross(ht);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ht.subVectors(s,e),wt.subVectors(i,e),zi.subVectors(t,e);const r=ht.dot(ht),a=ht.dot(wt),o=ht.dot(zi),c=wt.dot(wt),h=wt.dot(zi),u=r*c-a*a;if(u===0)return n.set(0,0,0),null;const l=1/u,d=(c*o-a*h)*l,y=(r*h-a*o)*l;return n.set(1-d-y,y,d)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,bt)===null?!1:bt.x>=0&&bt.y>=0&&bt.x+bt.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,bt)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,bt.x),o.addScaledVector(r,bt.y),o.addScaledVector(a,bt.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return Si.setScalar(0),Bi.setScalar(0),Ti.setScalar(0),Si.fromBufferAttribute(t,e),Bi.fromBufferAttribute(t,i),Ti.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(Si,n.x),r.addScaledVector(Bi,n.y),r.addScaledVector(Ti,n.z),r}static isFrontFacing(t,e,i,s){return ht.subVectors(i,e),wt.subVectors(t,e),ht.cross(wt).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),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 ht.subVectors(this.c,this.b),wt.subVectors(this.a,this.b),ht.cross(wt).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return st.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return st.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return st.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return st.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return st.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;Qt.subVectors(s,i),jt.subVectors(n,i),_i.subVectors(t,i);const o=Qt.dot(_i),c=jt.dot(_i);if(o<=0&&c<=0)return e.copy(i);Mi.subVectors(t,s);const h=Qt.dot(Mi),u=jt.dot(Mi);if(h>=0&&u<=h)return e.copy(s);const l=o*u-h*c;if(l<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Qt,r);Ai.subVectors(t,n);const d=Qt.dot(Ai),y=jt.dot(Ai);if(y>=0&&d<=y)return e.copy(n);const m=d*c-o*y;if(m<=0&&c>=0&&y<=0)return a=c/(c-y),e.copy(i).addScaledVector(jt,a);const z=h*y-d*u;if(z<=0&&u-h>=0&&d-y>=0)return Bs.subVectors(n,s),a=(u-h)/(u-h+(d-y)),e.copy(s).addScaledVector(Bs,a);const b=1/(z+m+l);return r=m*b,a=l*b,e.copy(i).addScaledVector(Qt,r).addScaledVector(jt,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}class Q{constructor(t=new S(1/0,1/0,1/0),e=new S(-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,i=t.length;e<i;e+=3)this.expandByPoint(lt.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(lt.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=lt.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),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 i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,lt):lt.fromBufferAttribute(n,r),lt.applyMatrix4(t.matrixWorld),this.expandByPoint(lt);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Le.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Le.copy(i.boundingBox)),Le.applyMatrix4(t.matrixWorld),this.union(Le)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],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,lt),lt.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(we),De.subVectors(this.max,we),Kt.subVectors(t.a,we),te.subVectors(t.b,we),ee.subVectors(t.c,we),Et.subVectors(te,Kt),It.subVectors(ee,te),Lt.subVectors(Kt,ee);let e=[0,-Et.z,Et.y,0,-It.z,It.y,0,-Lt.z,Lt.y,Et.z,0,-Et.x,It.z,0,-It.x,Lt.z,0,-Lt.x,-Et.y,Et.x,0,-It.y,It.x,0,-Lt.y,Lt.x,0];return!Pi(e,Kt,te,ee,De)||(e=[1,0,0,0,1,0,0,0,1],!Pi(e,Kt,te,ee,De))?!1:(qe.crossVectors(Et,It),e=[qe.x,qe.y,qe.z],Pi(e,Kt,te,ee,De))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,lt).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(lt).length()*.5),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()?this:(zt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),zt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),zt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),zt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),zt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),zt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),zt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),zt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(zt),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const zt=[new S,new S,new S,new S,new S,new S,new S,new S],lt=new S,Le=new Q,Kt=new S,te=new S,ee=new S,Et=new S,It=new S,Lt=new S,we=new S,De=new S,qe=new S,Dt=new S;function Pi(f,t,e,i,s){for(let n=0,r=f.length-3;n<=r;n+=3){Dt.fromArray(f,n);const a=s.x*Math.abs(Dt.x)+s.y*Math.abs(Dt.y)+s.z*Math.abs(Dt.z),o=t.dot(Dt),c=e.dot(Dt),h=i.dot(Dt);if(Math.max(-Math.max(o,c,h),Math.min(o,c,h))>a)return!1}return!0}const L=new S,ve=new Y;let fn=0;class mt extends Ve{constructor(t,e,i=!1){if(super(),Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:fn++}),this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRanges=[],this.gpuType=1015,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&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,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)ve.fromBufferAttribute(this,e),ve.applyMatrix3(t),this.setXY(e,ve.x,ve.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix3(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyMatrix4(t),this.setXYZ(e,L.x,L.y,L.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.applyNormalMatrix(t),this.setXYZ(e,L.x,L.y,L.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)L.fromBufferAttribute(this,e),L.transformDirection(t),this.setXYZ(e,L.x,L.y,L.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=me(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=K(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=me(e,this.array)),e}setX(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=me(e,this.array)),e}setY(t,e){return this.normalized&&(e=K(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=me(e,this.array)),e}setZ(t,e){return this.normalized&&(e=K(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=me(e,this.array)),e}setW(t,e){return this.normalized&&(e=K(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=K(e,this.array),i=K(i,this.array),s=K(s,this.array),n=K(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,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 t.name=this.name,t.usage=this.usage,t.gpuType=this.gpuType,t}dispose(){this.dispatchEvent({type:"dispose"})}}class dn extends mt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class yn extends mt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class mn extends mt{constructor(t,e,i){super(new Float32Array(t),e,i)}}const pn=new Q,be=new S,Ci=new S;class xn{constructor(t=new S,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 i=this.center;e!==void 0?i.copy(e):pn.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),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 i=this.center.distanceToSquared(t);return e.copy(t),i>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;be.subVectors(t,this.center);const e=be.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(be,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Ci.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(be.copy(t.center).add(Ci)),this.expandByPoint(be.copy(t.center).sub(Ci))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}let gn=0;const nt=new H,Ei=new Ct,ie=new S,it=new Q,ze=new Q,W=new S;class Ii extends Ve{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:gn++}),this.uuid=Re(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.indirectOffset=0,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={},this._transformed=!1}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Ks(t)?yn:dn)(t,1):this.index=t,this}setIndirect(t,e=0){return this.indirect=t,this.indirectOffset=e,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new xt().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this._transformed=!0,this}applyQuaternion(t){return nt.makeRotationFromQuaternion(t),this.applyMatrix4(nt),this}rotateX(t){return nt.makeRotationX(t),this.applyMatrix4(nt),this}rotateY(t){return nt.makeRotationY(t),this.applyMatrix4(nt),this}rotateZ(t){return nt.makeRotationZ(t),this.applyMatrix4(nt),this}translate(t,e,i){return nt.makeTranslation(t,e,i),this.applyMatrix4(nt),this}scale(t,e,i){return nt.makeScale(t,e,i),this.applyMatrix4(nt),this}lookAt(t){return Ei.lookAt(t),Ei.updateMatrix(),this.applyMatrix4(Ei.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ie).negate(),this.translate(ie.x,ie.y,ie.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new mn(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&yt("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Q);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new S(-1/0,-1/0,-1/0),new S(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];it.setFromBufferAttribute(n),this.morphTargetsRelative?(W.addVectors(this.boundingBox.min,it.min),this.boundingBox.expandByPoint(W),W.addVectors(this.boundingBox.max,it.max),this.boundingBox.expandByPoint(W)):(this.boundingBox.expandByPoint(it.min),this.boundingBox.expandByPoint(it.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&Ut('BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new xn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){Ut("BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new S,1/0);return}if(t){const i=this.boundingSphere.center;if(it.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];ze.setFromBufferAttribute(a),this.morphTargetsRelative?(W.addVectors(it.min,ze.min),it.expandByPoint(W),W.addVectors(it.max,ze.max),it.expandByPoint(W)):(it.expandByPoint(ze.min),it.expandByPoint(ze.max))}it.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)W.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(W));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let c=0,h=a.count;c<h;c++)W.fromBufferAttribute(a,c),o&&(ie.fromBufferAttribute(t,c),W.add(ie)),s=Math.max(s,i.distanceToSquared(W))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&Ut('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(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){Ut("BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;let r=this.getAttribute("tangent");(r===void 0||r.count!==i.count)&&(r=new mt(new Float32Array(4*i.count),4),this.setAttribute("tangent",r));const a=[],o=[];for(let M=0;M<i.count;M++)a[M]=new S,o[M]=new S;const c=new S,h=new S,u=new S,l=new Y,d=new Y,y=new Y,m=new S,z=new S;function b(M,P,A){c.fromBufferAttribute(i,M),h.fromBufferAttribute(i,P),u.fromBufferAttribute(i,A),l.fromBufferAttribute(n,M),d.fromBufferAttribute(n,P),y.fromBufferAttribute(n,A),h.sub(c),u.sub(c),d.sub(l),y.sub(l);const C=1/(d.x*y.y-y.x*d.y);isFinite(C)&&(m.copy(h).multiplyScalar(y.y).addScaledVector(u,-d.y).multiplyScalar(C),z.copy(u).multiplyScalar(d.x).addScaledVector(h,-y.x).multiplyScalar(C),a[M].add(m),a[P].add(m),a[A].add(m),o[M].add(z),o[P].add(z),o[A].add(z))}let p=this.groups;p.length===0&&(p=[{start:0,count:t.count}]);for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)b(t.getX(E+0),t.getX(E+1),t.getX(E+2))}const x=new S,g=new S,w=new S,B=new S;function _(M){w.fromBufferAttribute(s,M),B.copy(w);const P=a[M];x.copy(P),x.sub(w.multiplyScalar(w.dot(P))).normalize(),g.crossVectors(B,P);const C=g.dot(o[M])<0?-1:1;r.setXYZW(M,x.x,x.y,x.z,C)}for(let M=0,P=p.length;M<P;++M){const A=p[M],C=A.start,T=A.count;for(let E=C,I=C+T;E<I;E+=3)_(t.getX(E+0)),_(t.getX(E+1)),_(t.getX(E+2))}this._transformed=!0}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0||i.count!==e.count)i=new mt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let l=0,d=i.count;l<d;l++)i.setXYZ(l,0,0,0);const s=new S,n=new S,r=new S,a=new S,o=new S,c=new S,h=new S,u=new S;if(t)for(let l=0,d=t.count;l<d;l+=3){const y=t.getX(l+0),m=t.getX(l+1),z=t.getX(l+2);s.fromBufferAttribute(e,y),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,z),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),a.fromBufferAttribute(i,y),o.fromBufferAttribute(i,m),c.fromBufferAttribute(i,z),a.add(h),o.add(h),c.add(h),i.setXYZ(y,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(z,c.x,c.y,c.z)}else for(let l=0,d=e.count;l<d;l+=3)s.fromBufferAttribute(e,l+0),n.fromBufferAttribute(e,l+1),r.fromBufferAttribute(e,l+2),h.subVectors(r,n),u.subVectors(s,n),h.cross(u),i.setXYZ(l+0,h.x,h.y,h.z),i.setXYZ(l+1,h.x,h.y,h.z),i.setXYZ(l+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)W.fromBufferAttribute(t,e),W.normalize(),t.setXYZ(e,W.x,W.y,W.z)}toNonIndexed(){function t(a,o){const c=a.array,h=a.itemSize,u=a.normalized,l=new c.constructor(o.length*h);let d=0,y=0;for(let m=0,z=o.length;m<z;m++){a.isInterleavedBufferAttribute?d=o[m]*a.data.stride+a.offset:d=o[m]*h;for(let b=0;b<h;b++)l[y++]=c[d++]}return new mt(l,h,u)}if(this.index===null)return yt("BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Ii,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],c=t(o,i);e.setAttribute(a,c)}const n=this.morphAttributes;for(const a in n){const o=[],c=n[a];for(let h=0,u=c.length;h<u;h++){const l=c[h],d=t(l,i);o.push(d)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const c=r[a];e.addGroup(c.start,c.count,c.materialIndex)}return e}toJSON(){const t={metadata:{version:4.7,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.parameters!==void 0&&this._transformed===!0?"BufferGeometry":this.type,t.name=this.name,Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0&&this._transformed!==!0){const o=this.parameters;for(const c in o)o[c]!==void 0&&(t[c]=o[c]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const c=i[o];t.data.attributes[o]=c.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const c=this.morphAttributes[o],h=[];for(let u=0,l=c.length;u<l;u++){const d=c[u];h.push(d.toJSON(t.data))}h.length>0&&(s[o]=h,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere=a.toJSON()),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone());const s=t.attributes;for(const c in s){const h=s[c];this.setAttribute(c,h.clone(e))}const n=t.morphAttributes;for(const c in n){const h=[],u=n[c];for(let l=0,d=u.length;l<d;l++)h.push(u[l].clone(e));this.morphAttributes[c]=h}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let c=0,h=r.length;c<h;c++){const u=r[c];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this._transformed=t._transformed,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Fi=new S,wn=new S,bn=new xt;class Ts{constructor(t=new S(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,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=Fi.subVectors(i,e).cross(wn.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,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,i=!0){const s=t.delta(Fi),n=this.normal.dot(s);if(n===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/n;return i===!0&&(r<0||r>1)?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<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 i=e||bn.getNormalMatrix(t),s=this.coplanarPoint(Fi).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),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)}toJSON(){return{normal:this.normal.toArray(),constant:this.constant}}fromJSON(t){return this.normal.fromArray(t.normal),this.constant=t.constant,this}}const _t=new S,Vi=new S,Oe=new S,We=new S;class zn{constructor(t=new S,e=new S(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,_t)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=_t.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(_t.copy(this.origin).addScaledVector(this.direction,e),_t.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){Vi.copy(t).add(e).multiplyScalar(.5),Oe.copy(e).sub(t).normalize(),We.copy(this.origin).sub(Vi);const n=t.distanceTo(e)*.5,r=-this.direction.dot(Oe),a=We.dot(this.direction),o=-We.dot(Oe),c=We.lengthSq(),h=Math.abs(1-r*r);let u,l,d,y;if(h>0)if(u=r*o-a,l=r*a-o,y=n*h,u>=0)if(l>=-y)if(l<=y){const m=1/h;u*=m,l*=m,d=u*(u+r*l+2*a)+l*(r*u+l+2*o)+c}else l=n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l=-n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;else l<=-y?(u=Math.max(0,-(-r*n+a)),l=u>0?-n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c):l<=y?(u=0,l=Math.min(Math.max(-n,-o),n),d=l*(l+2*o)+c):(u=Math.max(0,-(r*n+a)),l=u>0?n:Math.min(Math.max(-n,-o),n),d=-u*u+l*(l+2*o)+c);else l=r>0?-n:n,u=Math.max(0,-(r*l+a)),d=-u*u+l*(l+2*o)+c;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy(Vi).addScaledVector(Oe,l),d}intersectSphere(t,e){if(t.radius<0)return null;_t.subVectors(t.center,this.origin);const i=_t.dot(this.direction),s=_t.dot(_t)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return t.radius<0?!1:this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const c=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,l=this.origin;return c>=0?(i=(t.min.x-l.x)*c,s=(t.max.x-l.x)*c):(i=(t.max.x-l.x)*c,s=(t.min.x-l.x)*c),h>=0?(n=(t.min.y-l.y)*h,r=(t.max.y-l.y)*h):(n=(t.max.y-l.y)*h,r=(t.min.y-l.y)*h),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-l.z)*u,o=(t.max.z-l.z)*u):(a=(t.max.z-l.z)*u,o=(t.min.z-l.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,_t)!==null}intersectTriangle(t,e,i,s,n){const r=this.origin,a=this.direction,o=a.x,c=a.y,h=a.z,u=t.x-r.x,l=t.y-r.y,d=t.z-r.z,y=e.x-r.x,m=e.y-r.y,z=e.z-r.z,b=i.x-r.x,p=i.y-r.y,x=i.z-r.z,g=Math.abs(o),w=Math.abs(c),B=Math.abs(h);let _,M,P,A,C,T,E,I,F,R,Z,tt;if(g>=w&&g>=B?(P=o,T=u,F=y,tt=b,o>=0?(_=c,M=h,A=l,C=d,E=m,I=z,R=p,Z=x):(_=h,M=c,A=d,C=l,E=z,I=m,R=x,Z=p)):w>=B?(P=c,T=l,F=m,tt=p,c>=0?(_=h,M=o,A=d,C=u,E=z,I=y,R=x,Z=b):(_=o,M=h,A=u,C=d,E=y,I=z,R=b,Z=x)):(P=h,T=d,F=z,tt=x,h>=0?(_=o,M=c,A=u,C=l,E=y,I=m,R=b,Z=p):(_=c,M=o,A=l,C=u,E=m,I=y,R=p,Z=b)),P===0)return null;const dt=_/P,at=M/P,pt=1/P,ye=A-dt*T,Ie=C-at*T,ys=E-dt*F,Tt=I-at*F,fi=R-dt*tt,di=Z-at*tt,Wt=fi*Tt-di*ys,Xt=ye*di-Ie*fi,Yt=ys*Ie-Tt*ye;if(s){if(Wt<0||Xt<0||Yt<0)return null}else if((Wt<0||Xt<0||Yt<0)&&(Wt>0||Xt>0||Yt>0))return null;const Fe=Wt+Xt+Yt;if(Fe===0)return null;const Ht=pt*(Wt*T+Xt*F+Yt*tt);return(Fe>0?Ht<0:Ht>0)?null:this.at(Ht/Fe,n)}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)}}const ds=class ds{constructor(t,e,i,s){this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,s){const n=this.elements;return n[0]=t,n[2]=e,n[1]=i,n[3]=s,this}};ds.prototype.isMatrix2=!0;let Ps=ds;const Cs=new S,Xe=new S,se=new S,ne=new S,Ri=new S,_n=new S,Mn=new S;class Mt{constructor(t=new S,e=new S){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){Cs.subVectors(t,this.start),Xe.subVectors(this.end,this.start);const i=Xe.dot(Xe);if(i===0)return 0;let n=Xe.dot(Cs)/i;return e&&(n=V(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}distanceSqToLine3(t,e=_n,i=Mn){const s=10000000000000001e-32;let n,r;const a=this.start,o=t.start,c=this.end,h=t.end;se.subVectors(c,a),ne.subVectors(h,o),Ri.subVectors(a,o);const u=se.dot(se),l=ne.dot(ne),d=ne.dot(Ri);if(u<=s&&l<=s)return e.copy(a),i.copy(o),e.sub(i),e.dot(e);if(u<=s)n=0,r=d/l,r=V(r,0,1);else{const y=se.dot(Ri);if(l<=s)r=0,n=V(-y/u,0,1);else{const m=se.dot(ne),z=u*l-m*m;z!==0?n=V((m*d-y*l)/z,0,1):n=0,r=(m*n+d)/l,r<0?(r=0,n=V(-y/u,0,1)):r>1&&(r=1,n=V((m-y)/u,0,1))}}return e.copy(a).addScaledVector(se,n),i.copy(o).addScaledVector(ne,r),e.distanceToSquared(i)}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)}}typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:"186"}})),typeof window<"u"&&(window.__THREE__?yt("WARNING: Multiple instances of Three.js being imported."):window.__THREE__="186");new xt().set(-1,0,0,0,1,0,0,0,1),new xt().set(-1,0,0,0,1,0,0,0,1);const Es=0,An=1,Sn=2,Is=2,ki=1.25,Fs=1,J=32,q=J/4,Vs=65535,Ye=Math.pow(2,-24),Ui=Symbol("SKIP_GENERATION"),Rs={strategy:Es,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ui]:!1};function U(f,t,e){return e.min.x=t[f],e.min.y=t[f+1],e.min.z=t[f+2],e.max.x=t[f+3],e.max.y=t[f+4],e.max.z=t[f+5],e}function Ni(f){let t=-1,e=-1/0;for(let i=0;i<3;i++){const s=f[i+3]-f[i];s>e&&(e=s,t=i)}return t}function ks(f,t){t.set(f)}function Us(f,t,e){let i,s;for(let n=0;n<3;n++){const r=n+3;i=f[n],s=t[n],e[n]=i<s?i:s,i=f[r],s=t[r],e[r]=i>s?i:s}}function He(f,t,e){for(let i=0;i<3;i++){const s=t[f+2*i],n=t[f+2*i+1],r=s-n,a=s+n;r<e[i]&&(e[i]=r),a>e[i+3]&&(e[i+3]=a)}}function _e(f){const t=f[3]-f[0],e=f[4]-f[1],i=f[5]-f[2];return 2*(t*e+e*i+i*t)}function N(f,t){return t[f+15]===Vs}function X(f,t){return t[f+6]}function G(f,t){return t[f+14]}function v(f){return f+q}function O(f,t){const e=t[f+6];return f+e*q}function Li(f,t){return t[f+7]}function Wr(f){return f}function Di(f,t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0,u=1/0,l=1/0,d=1/0,y=-1/0,m=-1/0,z=-1/0;const b=f.offset||0;for(let p=(t-b)*6,x=(t+e-b)*6;p<x;p+=6){const g=f[p+0],w=f[p+1],B=g-w,_=g+w;B<n&&(n=B),_>o&&(o=_),g<u&&(u=g),g>y&&(y=g);const M=f[p+2],P=f[p+3],A=M-P,C=M+P;A<r&&(r=A),C>c&&(c=C),M<l&&(l=M),M>m&&(m=M);const T=f[p+4],E=f[p+5],I=T-E,F=T+E;I<a&&(a=I),F>h&&(h=F),T<d&&(d=T),T>z&&(z=T)}i[0]=n,i[1]=r,i[2]=a,i[3]=o,i[4]=c,i[5]=h,s[0]=u,s[1]=l,s[2]=d,s[3]=y,s[4]=m,s[5]=z}const At=32,Bn=(f,t)=>f.candidate-t.candidate,Ft=new Array(At).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ze=new Float32Array(6);function Tn(f,t,e,i,s,n){let r=-1,a=0;if(n===Es)r=Ni(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===An)r=Ni(f),r!==-1&&(a=Pn(e,i,s,r));else if(n===Sn){const o=_e(f);let c=ki*s;const h=e.offset||0,u=(i-h)*6,l=(i+s-h)*6;for(let d=0;d<3;d++){const y=t[d],b=(t[d+3]-y)/At;if(s<At/4){const p=[...Ft];p.length=s;let x=0;for(let w=u;w<l;w+=6,x++){const B=p[x];B.candidate=e[w+2*d],B.count=0;const{bounds:_,leftCacheBounds:M,rightCacheBounds:P}=B;for(let A=0;A<3;A++)P[A]=1/0,P[A+3]=-1/0,M[A]=1/0,M[A+3]=-1/0,_[A]=1/0,_[A+3]=-1/0;He(w,e,_)}p.sort(Bn);let g=s;for(let w=0;w<g;w++){const B=p[w];for(;w+1<g&&p[w+1].candidate===B.candidate;)p.splice(w+1,1),g--}for(let w=u;w<l;w+=6){const B=e[w+2*d];for(let _=0;_<g;_++){const M=p[_];B>=M.candidate?He(w,e,M.rightCacheBounds):(He(w,e,M.leftCacheBounds),M.count++)}}for(let w=0;w<g;w++){const B=p[w],_=B.count,M=s-B.count,P=B.leftCacheBounds,A=B.rightCacheBounds;let C=0;_!==0&&(C=_e(P)/o);let T=0;M!==0&&(T=_e(A)/o);const E=Fs+ki*(C*_+T*M);E<c&&(r=d,c=E,a=B.candidate)}}else{for(let g=0;g<At;g++){const w=Ft[g];w.count=0,w.candidate=y+b+g*b;const B=w.bounds;for(let _=0;_<3;_++)B[_]=1/0,B[_+3]=-1/0}for(let g=u;g<l;g+=6){let _=~~((e[g+2*d]-y)/b);_>=At&&(_=At-1);const M=Ft[_];M.count++,He(g,e,M.bounds)}const p=Ft[At-1];ks(p.bounds,p.rightCacheBounds);for(let g=At-2;g>=0;g--){const w=Ft[g],B=Ft[g+1];Us(w.bounds,B.rightCacheBounds,w.rightCacheBounds)}let x=0;for(let g=0;g<At-1;g++){const w=Ft[g],B=w.count,_=w.bounds,P=Ft[g+1].rightCacheBounds;B!==0&&(x===0?ks(_,Ze):Us(_,Ze,Ze)),x+=B;let A=0,C=0;x!==0&&(A=_e(Ze)/o);const T=s-x;T!==0&&(C=_e(P)/o);const E=Fs+ki*(A*x+C*T);E<c&&(r=d,c=E,a=w.candidate)}}}}else console.warn(\`BVH: Invalid build strategy value \${n} used.\`);return{axis:r,pos:a}}function Pn(f,t,e,i){let s=0;const n=f.offset;for(let r=t,a=t+e;r<a;r++)s+=f[(r-n)*6+i*2];return s/e}class qi{constructor(){this.boundingData=new Float32Array(6)}}function Cn(f,t,e,i,s,n){let r=i,a=i+s-1;const o=n.pos,c=n.axis*2,h=e.offset||0;for(;;){for(;r<=a&&e[(r-h)*6+c]<o;)r++;for(;r<=a&&e[(a-h)*6+c]>=o;)a--;if(r<a){for(let u=0;u<t;u++){let l=f[r*t+u];f[r*t+u]=f[a*t+u],f[a*t+u]=l}for(let u=0;u<6;u++){const l=r-h,d=a-h,y=e[l*6+u];e[l*6+u]=e[d*6+u],e[d*6+u]=y}r++,a--}else return r}}let Ns,$e,vi,Ls;const En=Math.pow(2,32);function Oi(f){return"count"in f?1:1+Oi(f.left)+Oi(f.right)}function In(f,t,e){return Ns=new Float32Array(e),$e=new Uint32Array(e),vi=new Uint16Array(e),Ls=new Uint8Array(e),Wi(f,t)}function Wi(f,t){const e=f/4,i=f/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)Ns[e+r]=n[r];if(s)return t.buffer?(Ls.set(new Uint8Array(t.buffer),f),f+t.buffer.byteLength):($e[e+6]=t.offset,vi[i+14]=t.count,vi[i+15]=Vs,f+J);{const{left:r,right:a,splitAxis:o}=t,c=f+J;let h=Wi(c,r);const u=f/J,d=h/J-u;if(d>En)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return $e[e+6]=d,$e[e+7]=o,Wi(h,a)}}function Fn(f,t,e,i,s,n){const{maxDepth:r,verbose:a,targetLeafSize:o,_strictLeafSize:c=1/0,strategy:h,onProgress:u}=s,l=f.primitiveBuffer,d=f.primitiveBufferStride,y=new Float32Array(6);let m=!1;const z=new qi;return Di(t,e,i,z.boundingData,y),p(z,e,i,y),z;function b(x){u&&u((x-n.offset)/n.count)}function p(x,g,w,B=null,_=0){!m&&_>=r&&(m=!0,a&&console.warn(\`BVH: Max depth of \${r} reached when generating BVH. Consider increasing maxDepth.\`));const M=w>c;if(w<=o&&!M||_>=r)return b(g+w),x.offset=g,x.count=w,x;const P=Tn(x.boundingData,B,t,g,w,h);let A=P.axis===-1?-1:Cn(l,d,t,g,w,P);if(P.axis===-1||A===g||A===g+w){if(!M)return b(g+w),x.offset=g,x.count=w,x;P.axis=Math.max(0,Ni(x.boundingData)),A=g+Math.max(1,Math.floor(w/2))}x.splitAxis=P.axis;const C=new qi,T=g,E=A-g;x.left=C,Di(t,T,E,C.boundingData,y),p(C,T,E,y,_+1);const I=new qi,F=A,R=w-E;return x.right=I,Di(t,F,R,I.boundingData,y),p(I,F,R,y,_+1),x}}function Vn(f,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=f.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,f.computePrimitiveBounds(r.offset,r.count,a),f._roots=i.map(o=>{const c=Fn(f,a,o.offset,o.count,t,r),h=Oi(c),u=new e(J*h);return In(0,c,u),u})}class Xi{constructor(t){this._getNewPrimitive=t,this._primitives=[]}getPrimitive(){const t=this._primitives;return t.length===0?this._getNewPrimitive():t.pop()}releasePrimitive(t){this._primitives.push(t)}}class Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const k=new Rn;let Vt,re;const oe=[],Je=new Xi(()=>new Q);function kn(f,t,e,i,s,n){Vt=Je.getPrimitive(),re=Je.getPrimitive(),oe.push(Vt,re),k.setBuffer(f._roots[t]);const r=Yi(0,f.geometry,e,i,s,n);k.clearBuffer(),Je.releasePrimitive(Vt),Je.releasePrimitive(re),oe.pop(),oe.pop();const a=oe.length;return a>0&&(re=oe[a-1],Vt=oe[a-2]),r}function Yi(f,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:c}=k;let h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);return U(f,a,Vt),i(l,d,!1,r,n+f/q,Vt)}else{let A=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=v(T),F=T*2;return X(T,I)},C=function(T){const{uint16Array:E,uint32Array:I}=k;let F=T*2;for(;!N(F,E);)T=O(T,I),F=T*2;return X(T,I)+G(F,E)};const l=v(f),d=O(f,c);let y=l,m=d,z,b,p,x;if(s&&(p=Vt,x=re,U(y,a,p),U(m,a,x),z=s(p),b=s(x),b<z)){y=d,m=l;const T=z;z=b,b=T,p=x}p||(p=Vt,U(y,a,p));const g=N(y*2,o),w=e(p,g,z,r+1,n+y/q);let B;if(w===Is){const T=A(y),I=C(y)-T;B=i(T,I,!0,r+1,n+y/q,p)}else B=w&&Yi(y,t,e,i,s,n,r+1);if(B)return!0;x=re,U(m,a,x);const _=N(m*2,o),M=e(x,_,b,r+1,n+m/q);let P;if(M===Is){const T=A(m),I=C(m)-T;P=i(T,I,!0,r+1,n+m/q,x)}else P=M&&Yi(m,t,e,i,s,n,r+1);return!!P}}const Me=new k.constructor,Ge=new k.constructor,Rt=new Xi(()=>new Q),ae=new Q,ce=new Q,Hi=new Q,Zi=new Q;let $i=!1;function Un(f,t,e,i){if($i)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");$i=!0;const s=f._roots,n=t._roots;let r,a=0,o=0;const c=new H().copy(e).invert();for(let h=0,u=s.length;h<u;h++){Me.setBuffer(s[h]),o=0;const l=Rt.getPrimitive();U(0,Me.float32Array,l),l.applyMatrix4(c);for(let d=0,y=n.length;d<y&&(Ge.setBuffer(n[d]),r=ut(0,0,e,c,i,a,o,0,0,l),Ge.clearBuffer(),o+=n[d].byteLength/J,!r);d++);if(Rt.releasePrimitive(l),Me.clearBuffer(),a+=s[h].byteLength/J,r)break}return $i=!1,r}function ut(f,t,e,i,s,n=0,r=0,a=0,o=0,c=null,h=!1){let u,l;h?(u=Ge,l=Me):(u=Me,l=Ge);const d=u.float32Array,y=u.uint32Array,m=u.uint16Array,z=l.float32Array,b=l.uint32Array,p=l.uint16Array,x=f*2,g=t*2,w=N(x,m),B=N(g,p);let _=!1;if(B&&w)h?_=s(X(t,b),G(t*2,p),X(f,y),G(f*2,m),o,r+t/q,a,n+f/q):_=s(X(f,y),G(f*2,m),X(t,b),G(t*2,p),a,n+f/q,o,r+t/q);else if(B){const M=Rt.getPrimitive();U(t,z,M),M.applyMatrix4(e);const P=v(f),A=O(f,y);U(P,d,ae),U(A,d,ce);const C=M.intersectsBox(ae),T=M.intersectsBox(ce);_=C&&ut(t,P,i,e,s,r,n,o,a+1,M,!h)||T&&ut(t,A,i,e,s,r,n,o,a+1,M,!h),Rt.releasePrimitive(M)}else{const M=v(t),P=O(t,b);U(M,z,Hi),U(P,z,Zi);const A=c.intersectsBox(Hi),C=c.intersectsBox(Zi);if(A&&C)_=ut(f,M,e,i,s,n,r,a,o+1,c,h)||ut(f,P,e,i,s,n,r,a,o+1,c,h);else if(A)if(w)_=ut(f,M,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Hi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(M,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(M,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}else if(C)if(w)_=ut(f,P,e,i,s,n,r,a,o+1,c,h);else{const T=Rt.getPrimitive();T.copy(Zi).applyMatrix4(e);const E=v(f),I=O(f,y);U(E,d,ae),U(I,d,ce);const F=T.intersectsBox(ae),R=T.intersectsBox(ce);_=F&&ut(P,E,i,e,s,r,n,o,a+1,T,!h)||R&&ut(P,I,i,e,s,r,n,o,a+1,T,!h),Rt.releasePrimitive(T)}}return _}const Ji=new class{constructor(){let f=null,t=null,e=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(n,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=f=n._roots[r],this.uint16Array=e=new Uint16Array(f),this.uint32Array=t=new Uint32Array(f)},this.reset=()=>{this.root=null,this.buffer=f=null,this.uint16Array=e=null,this.uint32Array=t=null},this.getRangeStart=n=>{let r=n*2;for(;!N(r,e);)n=v(n),r=n*2;return X(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!N(r,e);)n=O(n,t),r=n*2;return X(n,t)+G(r,e)};const s=(n,r,a)=>{const o=r*2,c=N(o,e);if(!n(a,c,r)&&!c){const u=v(r),l=O(r,t);s(n,u,a+1),s(n,l,a+1)}};this.traverseBuffer=n=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(n,0,0)}finally{i=!1}},this.traverse=n=>{this.traverseBuffer((r,a,o)=>{if(a){const c=o*2,h=t[o+6],u=e[c+14];return n(r,a,new Float32Array(f,o*4,6),h,u)}else{const c=Li(o,t);return n(r,a,new Float32Array(f,o*4,6),c)}})}}},Ds=new Q,he=new Float32Array(6);class Nn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...Rs,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),Vn(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,c=-1/0,h=-1/0;for(let u=t,l=t+e;u<l;u++){this.writePrimitiveBounds(u,he,0);const[d,y,m,z,b,p]=he;d<n&&(n=d),z>o&&(o=z),y<r&&(r=y),b>c&&(c=b),m<a&&(a=m),p>h&&(h=p)}return i[s+0]=n,i[s+1]=r,i[s+2]=a,i[s+3]=o,i[s+4]=c,i[s+5]=h,i}computePrimitiveBounds(t,e,i){const s=i.offset||0;for(let n=t,r=t+e;n<r;n++){this.writePrimitiveBounds(n,he,0);const[a,o,c,h,u,l]=he,d=(a+h)/2,y=(o+u)/2,m=(c+l)/2,z=(h-a)/2,b=(u-o)/2,p=(l-c)/2,x=(n-s)*6;i[x+0]=d,i[x+1]=z+(Math.abs(d)+z)*Ye,i[x+2]=y,i[x+3]=b+(Math.abs(y)+b)*Ye,i[x+4]=m,i[x+5]=p+(Math.abs(m)+p)*Ye}return i}shiftPrimitiveOffsets(t){const e=this._indirectBuffer;if(e)for(let i=0,s=e.length;i<s;i++)e[i]+=t;else{const i=this._roots;for(let s=0;s<i.length;s++){const n=i[s],r=new Uint32Array(n),a=new Uint16Array(n),o=n.byteLength/J;for(let c=0;c<o;c++){const h=q*c,u=2*h;N(u,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){Ji.setBVH(this,e),Ji.traverse(t),Ji.reset()}refit(){const t=this._roots;for(let e=0,i=t.length;e<i;e++){const s=t[e],n=new Uint32Array(s),r=new Uint16Array(s),a=new Float32Array(s),o=s.byteLength/J;for(let c=o-1;c>=0;c--){const h=c*q,u=h*2;if(N(u,r)){const d=X(h,n),y=G(u,r);this.writePrimitiveRangeBounds(d,y,he,0),a.set(he,h)}else{const d=v(h),y=O(h,n);for(let m=0;m<3;m++){const z=a[d+m],b=a[d+m+3],p=a[y+m],x=a[y+m+3];a[h+m]=z<p?z:p,a[h+m+3]=b>x?b:x}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{U(0,new Float32Array(i),Ds),t.union(Ds)}),t}shapecast(t){let{boundsTraverseOrder:e,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:n,scratchPrimitive:r,iterate:a}=t;if(s&&n){const u=s;s=(l,d,y,m,z)=>u(l,d,y,m,z)?!0:a(l,d,this,n,y,m,r)}else s||(n?s=(u,l,d,y)=>a(u,l,this,n,d,y,r):s=(u,l,d)=>d);let o=!1,c=0;const h=this._roots;for(let u=0,l=h.length;u<l;u++){const d=h[u];if(o=kn(this,u,i,s,e,c),o)break;c+=d.byteLength/J}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Un(this,t,e,s)}}function Ln(){return typeof SharedArrayBuffer<"u"}function Gi(f){return f.index?f.index.count:f.attributes.position.count}function Qe(f){return Gi(f)/3}function Dn(f,t=ArrayBuffer){return f>65535?new Uint32Array(new t(4*f)):new Uint16Array(new t(2*f))}function qn(f,t){if(!f.index){const e=f.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Dn(e,i);f.setIndex(new mt(s,1));for(let n=0;n<e;n++)s[n]=n}}function vn(f,t,e){const i=Gi(f)/e,s=t||f.drawRange,n=s.start/e,r=(s.start+s.count)/e,a=Math.max(0,n),o=Math.min(i,r)-a;return{offset:Math.floor(a),count:Math.floor(o)}}function On(f,t){return f.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function qs(f,t,e){const i=vn(f,t,e),s=On(f,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Gi(f)/e,c=[];for(const l of s){const{offset:d,count:y}=l,m=d,z=isFinite(y)?y:o-d,b=d+z;m<a&&b>r&&(c.push({pos:Math.max(r,m),isStart:!0}),c.push({pos:Math.min(a,b),isStart:!1}))}c.sort((l,d)=>l.pos!==d.pos?l.pos-d.pos:l.type==="end"?-1:1);let h=0,u=null;for(const l of c){const d=l.pos;h!==0&&d!==u&&n.push({offset:u,count:d-u}),h+=l.isStart?1:-1,u=d}return n}function Wn(f,t){const e=f[f.length-1],i=e.offset+e.count>2**16,s=f.reduce((c,h)=>c+h.count,0),n=i?4:2,r=t?new SharedArrayBuffer(s*n):new ArrayBuffer(s*n),a=i?new Uint32Array(r):new Uint16Array(r);let o=0;for(let c=0;c<f.length;c++){const{offset:h,count:u}=f[c];for(let l=0;l<u;l++)a[o+l]=h+l;o+=u}return a}class Xn extends Nn{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(t){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(t){}constructor(t,e={}){if(t.isBufferGeometry){if(t.index&&t.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(e.useSharedArrayBuffer&&!Ln())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=t,this.resolvePrimitiveIndex=e.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,e={...Rs,...e},e[Ui]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=qs(e,t.range,i),n=Wn(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else qn(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Q))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:qs(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class St{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(t,e){let i=1/0,s=-1/0;for(let n=0,r=t.length;n<r;n++){const o=t[n][e];i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}setFromPoints(t,e){let i=1/0,s=-1/0;for(let n=0,r=e.length;n<r;n++){const a=e[n],o=t.dot(a);i=o<i?o:i,s=o>s?o:s}this.min=i,this.max=s}isSeparated(t){return this.min>t.max||t.min>this.max}}St.prototype.setFromBox=(function(){const f=new S;return function(e,i){const s=i.min,n=i.max;let r=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let h=0;h<=1;h++){f.x=s.x*o+n.x*(1-o),f.y=s.y*c+n.y*(1-c),f.z=s.z*h+n.z*(1-h);const u=e.dot(f);r=Math.min(u,r),a=Math.max(u,a)}this.min=r,this.max=a}})();const Yn=(function(){const f=new S,t=new S,e=new S;return function(s,n,r){const a=s.start,o=f,c=n.start,h=t;e.subVectors(a,c),f.subVectors(s.end,s.start),t.subVectors(n.end,n.start);const u=e.dot(h),l=h.dot(o),d=h.dot(h),y=e.dot(o),z=o.dot(o)*d-l*l;let b,p;z!==0?b=(u*l-y*d)/z:b=0,p=(u+b*l)/d,r.x=b,r.y=p}})(),Qi=(function(){const f=new Y,t=new S,e=new S;return function(s,n,r,a){Yn(s,n,f);let o=f.x,c=f.y;if(o>=0&&o<=1&&c>=0&&c<=1){s.at(o,r),n.at(c,a);return}else if(o>=0&&o<=1){c<0?n.at(0,a):n.at(1,a),s.closestPointToPoint(a,!0,r);return}else if(c>=0&&c<=1){o<0?s.at(0,r):s.at(1,r),n.closestPointToPoint(r,!0,a);return}else{let h;o<0?h=s.start:h=s.end;let u;c<0?u=n.start:u=n.end;const l=t,d=e;if(s.closestPointToPoint(u,!0,t),n.closestPointToPoint(h,!0,e),l.distanceToSquared(u)<=d.distanceToSquared(h)){r.copy(l),a.copy(u);return}else{r.copy(h),a.copy(d);return}}}})(),Hn=(function(){const f=new S,t=new S,e=new Ts,i=new Mt;return function(n,r){const{radius:a,center:o}=n,{a:c,b:h,c:u}=r;if(i.start=c,i.end=h,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a||(i.start=c,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a)||(i.start=h,i.end=u,i.closestPointToPoint(o,!0,f).distanceTo(o)<=a))return!0;const m=r.getPlane(e);if(Math.abs(m.distanceToPoint(o))<=a){const b=m.projectPoint(o,t);if(r.containsPoint(b))return!0}return!1}})(),Zn=["x","y","z"],Bt=1e-15,vs=Bt*Bt;function rt(f){return Math.abs(f)<Bt}class ft extends st{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new S),this.satBounds=new Array(4).fill().map(()=>new St),this.points=[this.a,this.b,this.c],this.plane=new Ts,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new Mt,this.needsUpdate=!0}intersectsSphere(t){return Hn(t,this)}update(){const t=this.a,e=this.b,i=this.c,s=this.points,n=this.satAxes,r=this.satBounds,a=n[0],o=r[0];this.getNormal(a),o.setFromPoints(a,s);const c=n[1],h=r[1];c.subVectors(t,e),h.setFromPoints(c,s);const u=n[2],l=r[2];u.subVectors(e,i),l.setFromPoints(u,s);const d=n[3],y=r[3];d.subVectors(i,t),y.setFromPoints(d,s);const m=c.length(),z=u.length(),b=d.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<Bt?z<Bt||b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):z<Bt?b<Bt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):b<Bt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ft.prototype.closestPointToSegment=(function(){const f=new S,t=new S,e=new Mt;return function(s,n=null,r=null){const{start:a,end:o}=s,c=this.points;let h,u=1/0;for(let l=0;l<3;l++){const d=(l+1)%3;e.start.copy(c[l]),e.end.copy(c[d]),Qi(e,s,f,t),h=f.distanceToSquared(t),h<u&&(u=h,n&&n.copy(f),r&&r.copy(t))}return this.closestPointToPoint(a,f),h=a.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(a)),this.closestPointToPoint(o,f),h=o.distanceToSquared(f),h<u&&(u=h,n&&n.copy(f),r&&r.copy(o)),Math.sqrt(u)}})(),ft.prototype.intersectsTriangle=(function(){const f=new ft,t=new St,e=new St,i=new S,s=new S,n=new S,r=new S,a=new Mt,o=new Mt,c=new S,h=new Y,u=new Y;function l(x,g,w,B){const _=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?_.copy(x.plane.normal):_.copy(g.plane.normal);const M=x.satBounds,P=x.satAxes;for(let T=1;T<4;T++){const E=M[T],I=P[T];if(t.setFromPoints(I,g.points),E.isSeparated(t)||(r.copy(_).cross(I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}const A=g.satBounds,C=g.satAxes;for(let T=1;T<4;T++){const E=A[T],I=C[T];if(t.setFromPoints(I,x.points),E.isSeparated(t)||(r.crossVectors(_,I),t.setFromPoints(r,x.points),e.setFromPoints(r,g.points),t.isSeparated(e)))return!1}return w&&(B||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),w.start.set(0,0,0),w.end.set(0,0,0)),!0}function d(x,g,w,B,_,M,P,A,C,T,E){let I=P/(P-A);T.x=B+(_-B)*I,E.start.subVectors(g,x).multiplyScalar(I).add(x),I=P/(P-C),T.y=B+(M-B)*I,E.end.subVectors(w,x).multiplyScalar(I).add(x)}function y(x,g,w,B,_,M,P,A,C,T,E){if(_>0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else if(M>0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(A*C>0||P!=0)d(x.a,x.b,x.c,g,w,B,P,A,C,T,E);else if(A!=0)d(x.b,x.a,x.c,w,g,B,A,P,C,T,E);else if(C!=0)d(x.c,x.a,x.b,B,g,w,C,P,A,T,E);else return!0;return!1}function m(x,g,w,B){const _=g.degenerateSegment,M=x.plane.distanceToPoint(_.start),P=x.plane.distanceToPoint(_.end);return rt(M)?rt(P)?l(x,g,w,B):(w&&(w.start.copy(_.start),w.end.copy(_.start)),x.containsPoint(_.start)):rt(P)?(w&&(w.start.copy(_.end),w.end.copy(_.end)),x.containsPoint(_.end)):x.plane.intersectLine(_,i)!=null?(w&&(w.start.copy(i),w.end.copy(i)),x.containsPoint(i)):!1}function z(x,g,w){const B=g.a;return rt(x.plane.distanceToPoint(B))&&x.containsPoint(B)?(w&&(w.start.copy(B),w.end.copy(B)),!0):!1}function b(x,g,w){const B=x.degenerateSegment,_=g.a;return B.closestPointToPoint(_,!0,i),_.distanceToSquared(i)<vs?(w&&(w.start.copy(_),w.end.copy(_)),!0):!1}function p(x,g,w,B){if(x.isDegenerateIntoSegment)if(g.isDegenerateIntoSegment){const _=x.degenerateSegment,M=g.degenerateSegment,P=s,A=n;_.delta(P),M.delta(A);const C=i.subVectors(M.start,_.start),T=P.x*A.y-P.y*A.x;if(rt(T))return!1;const E=(C.x*A.y-C.y*A.x)/T,I=-(P.x*C.y-P.y*C.x)/T;if(E<0||E>1||I<0||I>1)return!1;const F=_.start.z+P.z*E,R=M.start.z+A.z*I;return rt(F-R)?(w&&(w.start.copy(_.start).addScaledVector(P,E),w.end.copy(_.start).addScaledVector(P,E)),!0):!1}else return g.isDegenerateIntoPoint?b(x,g,w):m(g,x,w,B);else{if(x.isDegenerateIntoPoint)return g.isDegenerateIntoPoint?g.a.distanceToSquared(x.a)<vs?(w&&(w.start.copy(x.a),w.end.copy(x.a)),!0):!1:g.isDegenerateIntoSegment?b(g,x,w):z(g,x,w);if(g.isDegenerateIntoPoint)return z(x,g,w);if(g.isDegenerateIntoSegment)return m(x,g,w,B)}}return function(g,w=null,B=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(f.copy(g),f.update(),g=f);const _=p(this,g,w,B);if(_!==void 0)return _;const M=this.plane,P=g.plane;let A=P.distanceToPoint(this.a),C=P.distanceToPoint(this.b),T=P.distanceToPoint(this.c);rt(A)&&(A=0),rt(C)&&(C=0),rt(T)&&(T=0);const E=A*C,I=A*T;if(E>0&&I>0)return!1;let F=M.distanceToPoint(g.a),R=M.distanceToPoint(g.b),Z=M.distanceToPoint(g.c);rt(F)&&(F=0),rt(R)&&(R=0),rt(Z)&&(Z=0);const tt=F*R,dt=F*Z;if(tt>0&&dt>0)return!1;s.copy(M.normal),n.copy(P.normal);const at=s.cross(n);let pt=0,ye=Math.abs(at.x);const Ie=Math.abs(at.y);Ie>ye&&(ye=Ie,pt=1),Math.abs(at.z)>ye&&(pt=2);const Tt=Zn[pt],fi=this.a[Tt],di=this.b[Tt],Wt=this.c[Tt],Xt=g.a[Tt],Yt=g.b[Tt],Fe=g.c[Tt];if(y(this,fi,di,Wt,E,I,A,C,T,h,a))return l(this,g,w,B);if(y(g,Xt,Yt,Fe,tt,dt,F,R,Z,u,o))return l(this,g,w,B);if(h.y<h.x){const Ht=h.y;h.y=h.x,h.x=Ht,c.copy(a.start),a.start.copy(a.end),a.end.copy(c)}if(u.y<u.x){const Ht=u.y;u.y=u.x,u.x=Ht,c.copy(o.start),o.start.copy(o.end),o.end.copy(c)}return h.y<u.x||u.y<h.x?!1:(w&&(u.x>h.x?w.start.copy(o.start):w.start.copy(a.start),u.y<h.y?w.end.copy(o.end):w.end.copy(a.end)),!0)}})(),ft.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),ft.prototype.distanceToTriangle=(function(){const f=new S,t=new S,e=["a","b","c"],i=new Mt,s=new Mt;return function(r,a=null,o=null){const c=a||o?i:null;if(this.intersectsTriangle(r,c,!0))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let h=1/0;for(let u=0;u<3;u++){let l;const d=e[u],y=r[d];this.closestPointToPoint(y,f),l=y.distanceToSquared(f),l<h&&(h=l,a&&a.copy(f),o&&o.copy(y));const m=this[d];r.closestPointToPoint(m,f),l=m.distanceToSquared(f),l<h&&(h=l,a&&a.copy(m),o&&o.copy(f))}for(let u=0;u<3;u++){const l=e[u],d=e[(u+1)%3];i.set(this[l],this[d]);for(let y=0;y<3;y++){const m=e[y],z=e[(y+1)%3];s.set(r[m],r[z]),Qi(i,s,f,t);const b=f.distanceToSquared(t);b<h&&(h=b,a&&a.copy(f),o&&o.copy(t))}}return Math.sqrt(h)}})();class j{constructor(t,e,i){this.isOrientedBox=!0,this.min=new S,this.max=new S,this.matrix=new H,this.invMatrix=new H,this.points=new Array(8).fill().map(()=>new S),this.satAxes=new Array(3).fill().map(()=>new S),this.satBounds=new Array(3).fill().map(()=>new St),this.alignedSatBounds=new Array(3).fill().map(()=>new St),this.needsUpdate=!1,t&&this.min.copy(t),e&&this.max.copy(e),i&&this.matrix.copy(i)}set(t,e,i){this.min.copy(t),this.max.copy(e),this.matrix.copy(i),this.needsUpdate=!0}copy(t){this.min.copy(t.min),this.max.copy(t.max),this.matrix.copy(t.matrix),this.needsUpdate=!0}}j.prototype.update=(function(){return function(){const t=this.matrix,e=this.min,i=this.max,s=this.points;for(let c=0;c<=1;c++)for(let h=0;h<=1;h++)for(let u=0;u<=1;u++){const l=1*c|2*h|4*u,d=s[l];d.x=c?i.x:e.x,d.y=h?i.y:e.y,d.z=u?i.z:e.z,d.applyMatrix4(t)}const n=this.satBounds,r=this.satAxes,a=s[0];for(let c=0;c<3;c++){const h=r[c],u=n[c],l=1<<c,d=s[l];h.subVectors(a,d),u.setFromPoints(h,s)}const o=this.alignedSatBounds;o[0].setFromPointsField(s,"x"),o[1].setFromPointsField(s,"y"),o[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),j.prototype.intersectsBox=(function(){const f=new St;return function(e){this.needsUpdate&&this.update();const i=e.min,s=e.max,n=this.satBounds,r=this.satAxes,a=this.alignedSatBounds;if(f.min=i.x,f.max=s.x,a[0].isSeparated(f)||(f.min=i.y,f.max=s.y,a[1].isSeparated(f))||(f.min=i.z,f.max=s.z,a[2].isSeparated(f)))return!1;for(let o=0;o<3;o++){const c=r[o],h=n[o];if(f.setFromBox(c,e),h.isSeparated(f))return!1}return!0}})(),j.prototype.intersectsTriangle=(function(){const f=new ft,t=new Array(3),e=new St,i=new St,s=new S;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(f.copy(r),f.update(),r=f);const a=this.satBounds,o=this.satAxes;t[0]=r.a,t[1]=r.b,t[2]=r.c;for(let l=0;l<3;l++){const d=a[l],y=o[l];if(e.setFromPoints(y,t),d.isSeparated(e))return!1}const c=r.satBounds,h=r.satAxes,u=this.points;for(let l=0;l<3;l++){const d=c[l],y=h[l];if(e.setFromPoints(y,u),d.isSeparated(e))return!1}for(let l=0;l<3;l++){const d=o[l];for(let y=0;y<4;y++){const m=h[y];if(s.crossVectors(d,m),e.setFromPoints(s,t),i.setFromPoints(s,u),e.isSeparated(i))return!1}}return!0}})(),j.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}})(),j.prototype.distanceToPoint=(function(){const f=new S;return function(e){return this.closestPointToPoint(e,f),e.distanceTo(f)}})(),j.prototype.distanceToBox=(function(){const f=["x","y","z"],t=new Array(12).fill().map(()=>new Mt),e=new Array(12).fill().map(()=>new Mt),i=new S,s=new S;return function(r,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(o||c)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),o&&o.copy(i),c&&c.copy(s)),0;const h=a*a,u=r.min,l=r.max,d=this.points;let y=1/0;for(let z=0;z<8;z++){const b=d[z];s.copy(b).clamp(u,l);const p=b.distanceToSquared(s);if(p<y&&(y=p,o&&o.copy(b),c&&c.copy(s),p<h))return Math.sqrt(p)}let m=0;for(let z=0;z<3;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const x=(z+1)%3,g=(z+2)%3,w=b<<x|p<<g,B=1<<z|b<<x|p<<g,_=d[w],M=d[B];t[m].set(_,M);const A=f[z],C=f[x],T=f[g],E=e[m],I=E.start,F=E.end;I[A]=u[A],I[C]=b?u[C]:l[C],I[T]=p?u[T]:l[C],F[A]=l[A],F[C]=b?u[C]:l[C],F[T]=p?u[T]:l[C],m++}for(let z=0;z<=1;z++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=z?l.x:u.x,s.y=b?l.y:u.y,s.z=p?l.z:u.z,this.closestPointToPoint(s,i);const x=s.distanceToSquared(i);if(x<y&&(y=x,o&&o.copy(i),c&&c.copy(s),x<h))return Math.sqrt(x)}for(let z=0;z<12;z++){const b=t[z];for(let p=0;p<12;p++){const x=e[p];Qi(b,x,i,s);const g=i.distanceToSquared(s);if(g<y&&(y=g,o&&o.copy(i),c&&c.copy(s),g<h))return Math.sqrt(g)}}return Math.sqrt(y)}})();class $n extends Xi{constructor(){super(()=>new ft)}}const ot=new $n,Ae=new S,ji=new S;function Jn(f,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(f.shapecast({boundsTraverseOrder:h=>(Ae.copy(t).clamp(h.min,h.max),Ae.distanceToSquared(t)),intersectsBounds:(h,u,l)=>l<a&&l<r,intersectsTriangle:(h,u)=>{h.closestPointToPoint(t,Ae);const l=t.distanceToSquared(Ae);return l<a&&(ji.copy(Ae),a=l,o=u),l<n}}),a===1/0)return null;const c=Math.sqrt(a);return e.point?e.point.copy(ji):e.point=ji.clone(),e.distance=c,e.faceIndex=o,e}const je=parseInt("186")>=169,Gn=parseInt("186")<=161,qt=new S,vt=new S,Ot=new S,Ke=new Y,ti=new Y,ei=new Y,Os=new S,Ws=new S,Xs=new S,Se=new S;function Qn(f,t,e,i,s,n,r,a){let o;if(n===1?o=f.intersectTriangle(i,e,t,!0,s):o=f.intersectTriangle(t,e,i,n!==2,s),o===null)return null;const c=f.origin.distanceTo(s);return c<r||c>a?null:{distance:c,point:s.clone()}}function Ys(f,t,e,i,s,n,r,a,o,c,h){qt.fromBufferAttribute(t,n),vt.fromBufferAttribute(t,r),Ot.fromBufferAttribute(t,a);const u=Qn(f,qt,vt,Ot,Se,o,c,h);if(u){if(i){Ke.fromBufferAttribute(i,n),ti.fromBufferAttribute(i,r),ei.fromBufferAttribute(i,a),u.uv=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv);je||(u.uv=d)}if(s){Ke.fromBufferAttribute(s,n),ti.fromBufferAttribute(s,r),ei.fromBufferAttribute(s,a),u.uv1=new Y;const d=st.getInterpolation(Se,qt,vt,Ot,Ke,ti,ei,u.uv1);je||(u.uv1=d),Gn&&(u.uv2=u.uv1)}if(e){Os.fromBufferAttribute(e,n),Ws.fromBufferAttribute(e,r),Xs.fromBufferAttribute(e,a),u.normal=new S;const d=st.getInterpolation(Se,qt,vt,Ot,Os,Ws,Xs,u.normal);u.normal.dot(f.direction)>0&&u.normal.multiplyScalar(-1),je||(u.normal=d)}const l={a:n,b:r,c:a,normal:new S,materialIndex:0};if(st.getNormal(qt,vt,Ot,l.normal),u.face=l,u.faceIndex=n,je){const d=new S;st.getBarycoord(Se,qt,vt,Ot,d),u.barycoord=d}}return u}function Hs(f){return f&&f.isMaterial?f.side:f}function ii(f,t,e,i,s,n,r){const a=i*3;let o=a+0,c=a+1,h=a+2;const{index:u,groups:l}=f;f.index&&(o=u.getX(o),c=u.getX(c),h=u.getX(h));const{position:d,normal:y,uv:m,uv1:z}=f.attributes;if(Array.isArray(t)){const b=i*3;for(let p=0,x=l.length;p<x;p++){const{start:g,count:w,materialIndex:B}=l[p];if(b>=g&&b<g+w){const _=Hs(t[B]),M=Ys(e,d,y,m,z,o,c,h,_,n,r);if(M)if(M.faceIndex=i,M.face.materialIndex=B,s)s.push(M);else return M}}}else{const b=Hs(t),p=Ys(e,d,y,m,z,o,c,h,b,n,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function D(f,t,e,i){const s=f.a,n=f.b,r=f.c;let a=t,o=t+1,c=t+2;e&&(a=e.getX(a),o=e.getX(o),c=e.getX(c)),s.x=i.getX(a),s.y=i.getY(a),s.z=i.getZ(a),n.x=i.getX(o),n.y=i.getY(o),n.z=i.getZ(o),r.x=i.getX(c),r.y=i.getY(c),r.z=i.getZ(c)}function jn(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++)ii(o,t,e,h,n,r,a)}function Kn(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function tr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=h,D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function er(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=3*z,P=3*(z+b);M<P;M++){let A=i[M];const C=s.getX(A),T=s.getY(A),E=s.getZ(A);C<p&&(p=C),C>w&&(w=C),T<x&&(x=T),T>B&&(B=T),E<g&&(g=E),E>_&&(_=E)}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function kt(f,t,e,i,s){let n,r,a,o,c,h;const u=1/e.direction.x,l=1/e.direction.y,d=1/e.direction.z,y=e.origin.x,m=e.origin.y,z=e.origin.z;let b=t[f],p=t[f+3],x=t[f+1],g=t[f+3+1],w=t[f+2],B=t[f+3+2];return u>=0?(n=(b-y)*u,r=(p-y)*u):(n=(p-y)*u,r=(b-y)*u),l>=0?(a=(x-m)*l,o=(g-m)*l):(a=(g-m)*l,o=(x-m)*l),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),d>=0?(c=(w-z)*d,h=(B-z)*d):(c=(B-z)*d,h=(w-z)*d),n>h||c>r)?!1:((c>n||n!==n)&&(n=c),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function ir(f,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:c}=f;for(let h=i,u=i+s;h<u;h++){let l=c?c[h]:h;ii(o,t,e,l,n,r,a)}}function sr(f,t,e,i,s,n,r){const{geometry:a,_indirectBuffer:o}=f;let c=1/0,h=null;for(let u=i,l=i+s;u<l;u++){let d;d=ii(a,t,e,o?o[u]:u,null,n,r),d&&d.distance<c&&(h=d,c=d.distance)}return h}function nr(f,t,e,i,s,n,r){const{geometry:a}=e,{index:o}=a,c=a.attributes.position;for(let h=f,u=t+f;h<u;h++){let l;if(l=e.resolveTriangleIndex(h),D(r,l*3,o,c),r.needsUpdate=!0,i(r,l,s,n))return!0}return!1}function rr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),Ki(0,f,e,i,s,n,r),k.clearBuffer()}function Ki(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);jn(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&Ki(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&Ki(d,t,e,i,s,n,r)}}const or=["x","y","z"];function ar(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ts(0,f,e,i,s,n);return k.clearBuffer(),r}function ts(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return Kn(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=or[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ts(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ts(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const si=new Q,le=new ft,ue=new ft,Be=new H,Zs=new j,ni=new j;function cr(f,t,e,i){k.setBuffer(f._roots[t]);const s=es(0,f,e,i);return k.clearBuffer(),s}function es(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Zs.set(e.boundingBox.min,e.boundingBox.max,i),s=Zs),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Be.copy(i).invert(),e.boundsTree)return U(f,n,ni),ni.matrix.copy(Be),ni.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ni.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m*3,g=(z+m)*3;x<g;x+=3)if(D(ue,x,u,l),ue.needsUpdate=!0,p.intersectsTriangle(ue))return!0;return!1}});{const b=Qe(e);for(let p=m*3,x=(z+m)*3;p<x;p+=3){D(le,p,u,l),le.a.applyMatrix4(Be),le.b.applyMatrix4(Be),le.c.applyMatrix4(Be),le.needsUpdate=!0;for(let g=0,w=b*3;g<w;g+=3)if(D(ue,g,d,y),ue.needsUpdate=!0,le.intersectsTriangle(ue))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,si),!!(s.intersectsBox(si)&&es(h,t,e,i,s)||(U(u,n,si),s.intersectsBox(si)&&es(u,t,e,i,s)))}}const ri=new H,is=new j,Te=new j,hr=new S,lr=new S,ur=new S,fr=new S;function dr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),is.set(t.boundingBox.min,t.boundingBox.max,e),is.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=hr,m=lr,z=null,b=null;s&&(z=ur,b=fr);let p=1/0,x=null,g=null;return ri.copy(e).invert(),Te.matrix.copy(ri),f.shapecast({boundsTraverseOrder:w=>is.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Te.min.copy(w.min),Te.max.copy(w.max),Te.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:M=>Te.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){D(d,3*A,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let T=w,E=w+B;T<E;T++){D(l,3*T,c,o),l.needsUpdate=!0;const I=l.distanceToTriangle(d,y,z);if(I<p&&(m.copy(y),b&&b.copy(z),p=I,x=T,g=A),I<n)return!0}}}});{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){D(l,3*A,c,o),l.needsUpdate=!0;const T=l.distanceToTriangle(d,y,z);if(T<p&&(m.copy(y),b&&b.copy(z),p=T,x=A,g=M),T<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ri),m.applyMatrix4(ri),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function yr(f,t=null){t&&Array.isArray(t)&&(t=new Set(t));const e=f.geometry,i=e.index?e.index.array:null,s=e.attributes.position;let n,r,a,o,c=0;const h=f._roots;for(let l=0,d=h.length;l<d;l++)n=h[l],r=new Uint32Array(n),a=new Uint16Array(n),o=new Float32Array(n),u(0,c),c+=n.byteLength;function u(l,d,y=!1){const m=l*2;if(N(m,a)){const z=X(l,r),b=G(m,a);let p=1/0,x=1/0,g=1/0,w=-1/0,B=-1/0,_=-1/0;for(let M=z,P=z+b;M<P;M++){const A=3*f.resolveTriangleIndex(M);for(let C=0;C<3;C++){let T=A+C;T=i?i[T]:T;const E=s.getX(T),I=s.getY(T),F=s.getZ(T);E<p&&(p=E),E>w&&(w=E),I<x&&(x=I),I>B&&(B=I),F<g&&(g=F),F>_&&(_=F)}}return o[l+0]!==p||o[l+1]!==x||o[l+2]!==g||o[l+3]!==w||o[l+4]!==B||o[l+5]!==_?(o[l+0]=p,o[l+1]=x,o[l+2]=g,o[l+3]=w,o[l+4]=B,o[l+5]=_,!0):!1}else{const z=v(l),b=O(l,r);let p=y,x=!1,g=!1;if(t){if(!p){const A=z/q+d/J,C=b/q+d/J;x=t.has(A),g=t.has(C),p=!x&&!g}}else x=!0,g=!0;const w=p||x,B=p||g;let _=!1;w&&(_=u(z,d,p));let M=!1;B&&(M=u(b,d,p));const P=_||M;if(P)for(let A=0;A<3;A++){const C=z+A,T=b+A,E=o[C],I=o[C+3],F=o[T],R=o[T+3];o[l+A]=E<F?E:F,o[l+A+3]=I>R?I:R}return P}}}function mr(f,t,e,i,s,n,r){k.setBuffer(f._roots[t]),ss(0,f,e,i,s,n,r),k.clearBuffer()}function ss(f,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:c}=k,h=f*2;if(N(h,o)){const l=X(f,c),d=G(h,o);ir(t,e,i,l,d,s,n,r)}else{const l=v(f);kt(l,a,i,n,r)&&ss(l,t,e,i,s,n,r);const d=O(f,c);kt(d,a,i,n,r)&&ss(d,t,e,i,s,n,r)}}const pr=["x","y","z"];function xr(f,t,e,i,s,n){k.setBuffer(f._roots[t]);const r=ns(0,f,e,i,s,n);return k.clearBuffer(),r}function ns(f,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=k;let c=f*2;if(N(c,a)){const u=X(f,o),l=G(c,a);return sr(t,e,i,u,l,s,n)}else{const u=Li(f,o),l=pr[u],y=i.direction[l]>=0;let m,z;y?(m=v(f),z=O(f,o)):(m=O(f,o),z=v(f));const p=kt(m,r,i,s,n)?ns(m,t,e,i,s,n):null;if(p){const w=p.point[l];if(y?w<=r[z+u]:w>=r[z+u+3])return p}const g=kt(z,r,i,s,n)?ns(z,t,e,i,s,n):null;return p&&g?p.distance<=g.distance?p:g:p||g||null}}const oi=new Q,fe=new ft,de=new ft,Pe=new H,$s=new j,ai=new j;function gr(f,t,e,i){k.setBuffer(f._roots[t]);const s=rs(0,f,e,i);return k.clearBuffer(),s}function rs(f,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=k;let o=f*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),$s.set(e.boundingBox.min,e.boundingBox.max,i),s=$s),N(o,r)){const h=t.geometry,u=h.index,l=h.attributes.position,d=e.index,y=e.attributes.position,m=X(f,a),z=G(o,r);if(Pe.copy(i).invert(),e.boundsTree)return U(f,n,ai),ai.matrix.copy(Pe),ai.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:p=>ai.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let x=m,g=z+m;x<g;x++)if(D(de,3*t.resolveTriangleIndex(x),u,l),de.needsUpdate=!0,p.intersectsTriangle(de))return!0;return!1}});{const b=Qe(e);for(let p=m,x=z+m;p<x;p++){const g=t.resolveTriangleIndex(p);D(fe,3*g,u,l),fe.a.applyMatrix4(Pe),fe.b.applyMatrix4(Pe),fe.c.applyMatrix4(Pe),fe.needsUpdate=!0;for(let w=0,B=b*3;w<B;w+=3)if(D(de,w,d,y),de.needsUpdate=!0,fe.intersectsTriangle(de))return!0}}}else{const h=v(f),u=O(f,a);return U(h,n,oi),!!(s.intersectsBox(oi)&&rs(h,t,e,i,s)||(U(u,n,oi),s.intersectsBox(oi)&&rs(u,t,e,i,s)))}}const ci=new H,os=new j,Ce=new j,wr=new S,br=new S,zr=new S,_r=new S;function Mr(f,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),os.set(t.boundingBox.min,t.boundingBox.max,e),os.needsUpdate=!0;const a=f.geometry,o=a.attributes.position,c=a.index,h=t.attributes.position,u=t.index,l=ot.getPrimitive(),d=ot.getPrimitive();let y=wr,m=br,z=null,b=null;s&&(z=zr,b=_r);let p=1/0,x=null,g=null;return ci.copy(e).invert(),Ce.matrix.copy(ci),f.shapecast({boundsTraverseOrder:w=>os.distanceToBox(w),intersectsBounds:(w,B,_)=>_<p&&_<r?(B&&(Ce.min.copy(w.min),Ce.max.copy(w.max),Ce.needsUpdate=!0),!0):!1,intersectsRange:(w,B)=>{if(t.boundsTree){const _=t.boundsTree;return _.shapecast({boundsTraverseOrder:M=>Ce.distanceToBox(M),intersectsBounds:(M,P,A)=>A<p&&A<r,intersectsRange:(M,P)=>{for(let A=M,C=M+P;A<C;A++){const T=_.resolveTriangleIndex(A);D(d,3*T,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let E=w,I=w+B;E<I;E++){const F=f.resolveTriangleIndex(E);D(l,3*F,c,o),l.needsUpdate=!0;const R=l.distanceToTriangle(d,y,z);if(R<p&&(m.copy(y),b&&b.copy(z),p=R,x=E,g=A),R<n)return!0}}}})}else{const _=Qe(t);for(let M=0,P=_;M<P;M++){D(d,3*M,u,h),d.a.applyMatrix4(e),d.b.applyMatrix4(e),d.c.applyMatrix4(e),d.needsUpdate=!0;for(let A=w,C=w+B;A<C;A++){const T=f.resolveTriangleIndex(A);D(l,3*T,c,o),l.needsUpdate=!0;const E=l.distanceToTriangle(d,y,z);if(E<p&&(m.copy(y),b&&b.copy(z),p=E,x=A,g=M),E<n)return!0}}}}}),ot.releasePrimitive(l),ot.releasePrimitive(d),p===1/0?null:(i.point?i.point.copy(m):i.point=m.clone(),i.distance=p,i.faceIndex=x,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(ci),m.applyMatrix4(ci),s.distance=m.sub(s.point).length(),s.faceIndex=g),i)}function Js(f,t,e){return f===null?null:(f.point.applyMatrix4(t.matrixWorld),f.distance=f.point.distanceTo(e.ray.origin),f.object=t,f)}const hi=new j,li=new zn,Gs=new S,Qs=new H,js=new S,as=["getX","getY","getZ"];class Ee extends Xn{static serialize(t,e={}){e={cloneBuffers:!0,...e};const i=t.geometry,s=t._roots,n=t._indirectBuffer,r=i.getIndex(),a={version:1,roots:null,index:null,indirectBuffer:null};return e.cloneBuffers?(a.roots=s.map(o=>o.slice()),a.index=r?r.array.slice():null,a.indirectBuffer=n?n.slice():null):(a.roots=s,a.index=r?r.array:null,a.indirectBuffer=n),a}static deserialize(t,e,i={}){i={setIndex:!0,indirect:!!t.indirectBuffer,...i};const{index:s,roots:n,indirectBuffer:r}=t;t.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),o(n));const a=new Ee(e,{...i,[Ui]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const c=e.getIndex();if(c===null){const h=new mt(t.index,1,!1);e.setIndex(h)}else c.array!==s&&(c.array.set(s),c.needsUpdate=!0)}return a;function o(c){for(let h=0;h<c.length;h++){const u=c[h],l=new Uint32Array(u),d=new Uint16Array(u);for(let y=0,m=u.byteLength/J;y<m;y++){const z=q*y,b=2*z;N(b,d)||(l[z+6]=l[z+6]/q-y)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(t,e={}){e.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafTris}),super(t,e)}shiftTriangleOffsets(t){return super.shiftPrimitiveOffsets(t)}writePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,c=(n?n[t]:t)*3;let h=c+0,u=c+1,l=c+2;a&&(h=a[h],u=a[u],l=a[l]);for(let d=0;d<3;d++){const y=r[as[d]](h),m=r[as[d]](u),z=r[as[d]](l);let b=y;m<b&&(b=m),z<b&&(b=z);let p=y;m>p&&(p=m),z>p&&(p=z),e[i+d]=b,e[i+d+3]=p}return e}computePrimitiveBounds(t,e,i){const s=this.geometry,n=this._indirectBuffer,r=s.attributes.position,a=s.index?s.index.array:null,o=r.normalized;if(t<0||e+t-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const c=r.array,h=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const l=["getX","getY","getZ"],d=i.offset;for(let y=t,m=t+e;y<m;y++){const b=(n?n[y]:y)*3,p=(y-d)*6;let x=b+0,g=b+1,w=b+2;a&&(x=a[x],g=a[g],w=a[w]),o||(x=x*u+h,g=g*u+h,w=w*u+h);for(let B=0;B<3;B++){let _,M,P;o?(_=r[l[B]](x),M=r[l[B]](g),P=r[l[B]](w)):(_=c[x+B],M=c[g+B],P=c[w+B]);let A=_;M<A&&(A=M),P<A&&(A=P);let C=_;M>C&&(C=M),P>C&&(C=P);const T=(C-A)/2,E=B*2;i[p+E+0]=A+T,i[p+E+1]=T+(Math.abs(A)+T)*Ye}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;Qs.copy(t.matrixWorld).invert(),li.copy(e.ray).applyMatrix4(Qs),js.setFromMatrixScale(t.matrixWorld),Gs.copy(li.direction).multiply(js);const n=Gs.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(li,s,r,a);o=Js(o,t,e),o&&i.push(o)}else{const o=this.raycast(li,s,r,a);for(let c=0,h=o.length;c<h;c++){const u=Js(o[c],t,e);u&&i.push(u)}}return i}refit(t=null){return(this.indirect?yr:er)(this,t)}raycast(t,e=0,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?mr:rr;for(let o=0,c=n.length;o<c;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=0,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?xr:ar;for(let o=0,c=n.length;o<c;o++){const h=a(this,o,e,t,i,s);h!=null&&(r==null||h.distance<r.distance)&&(r=h)}return r}intersectsGeometry(t,e){let i=!1;const s=this._roots,n=this.indirect?gr:cr;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=ot.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?nr:tr});return ot.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=ot.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,c=this.indirect?y=>{const m=this.resolveTriangleIndex(y);D(r,m*3,a,o)}:y=>{D(r,y*3,a,o)},h=ot.getPrimitive(),u=t.geometry.index,l=t.geometry.attributes.position,d=t.indirect?y=>{const m=t.resolveTriangleIndex(y);D(h,m*3,u,l)}:y=>{D(h,y*3,u,l)};if(n){if(!(t instanceof Ee))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const y=(m,z,b,p,x,g,w,B)=>{for(let _=b,M=b+p;_<M;_++){d(_),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let P=m,A=m+z;P<A;P++)if(c(P),r.needsUpdate=!0,n(r,h,P,_,x,g,w,B))return!0}return!1};if(s){const m=s;s=function(z,b,p,x,g,w,B,_){return m(z,b,p,x,g,w,B,_)?!0:y(z,b,p,x,g,w,B,_)}}else s=y}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return hi.set(t.min,t.max,e),hi.needsUpdate=!0,this.shapecast({intersectsBounds:i=>hi.intersectsBox(i),intersectsTriangle:i=>hi.intersectsTriangle(i)})}intersectsSphere(t){return this.shapecast({intersectsBounds:e=>t.intersectsBox(e),intersectsTriangle:e=>e.intersectsSphere(t)})}closestPointToGeometry(t,e,i={},s={},n=0,r=1/0){return(this.indirect?Mr:dr)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Jn(this,t,e,i,s)}}const cs=self;cs.addEventListener("message",async({data:f})=>{let t=performance.now();function e(a){const o=performance.now();(o-t>=10||a===1)&&(postMessage({error:void 0,serialized:void 0,position:void 0,progress:a}),t=o)}const{id:i,index:s,position:n,options:r}=f;try{const a=new Ii;if(a.setAttribute("position",new mt(n,3,!1)),s&&a.setIndex(new mt(s,1,!1)),r.includedProgressCallback&&(r.onProgress=e),r.groups){const h=r.groups;for(const u in h){const l=h[u];a.addGroup(l.start,l.count,l.materialIndex)}}const o=new Ee(a,r),c=Ee.serialize(o,{cloneBuffers:!1});cs.postMessage({id:i,error:void 0,serialized:c,position:n,progress:1},[c.index.buffer,n.buffer,...c.roots])}catch(a){cs.postMessage({id:i,error:a,serialized:void 0,position:void 0,progress:1})}})})();
1533
+ `,ao=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",ll],{type:"text/javascript;charset=utf-8"});function mu(c){let t;try{if(t=ao&&(self.URL||self.webkitURL).createObjectURL(ao),!t)throw"";const e=new Worker(t,{name:c?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(ll),{name:c?.name})}}class cl{constructor(){g(this,"running");g(this,"worker");this.running=!1,this.worker=new mu,this.worker.onerror=t=>{throw t.message?new Error(`[GenerateMeshBVHWorker] Could not create Web Worker with error "${t.message}"`):new Error("[GenerateMeshBVHWorker] Could not create Web Worker.")}}isRunning(){return this.running}generate(t,e={}){if(this.running){P.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){P.warn("[GenerateMeshBVHWorker] Worker has been disposed.");return}const{worker:i}=this;this.running=!0;const s=new Map;t.forEach(r=>{s.set(r.id,r)});let n=0;return new Promise((r,a)=>{const o=()=>{++n===s.size&&(this.running=!1,i.onmessage=null,r())};i.onerror=l=>{P.warn("[GenerateMeshBVHWorker] "+l.message),a(new Error("[GenerateMeshBVHWorker] "+l.message)),this.running=!1},i.onmessage=l=>{this.running=!1;const{data:h}=l;if(h.error)P.warn(h.error),o();else if(h.serialized){const{serialized:d,position:u,id:f}=h,m=s.get(f),b=ps.deserialize(d,m,{setIndex:!1}),y=Object.assign({setBoundingBox:!0},e);if(y.transferred&&(m.attributes.position.array=u),m.index)e.saveOriginalIndex&&!m.userData.originalIndex&&(m.userData.originalIndex=m.index.array),P.debug("before update, index:",m.index.array),m.index.array=d.index;else{const C=new D.BufferAttribute(d.index,1,!1);m.setIndex(C)}m.index&&(P.debug("after update, index:",m.index.array),m.index.needsUpdate=!0),y.setBoundingBox&&!m.boundingBox&&(m.boundingBox=b.getBoundingBox(new D.Box3)),m.boundsTree=b,o()}else e.onProgress&&e.onProgress(h.progress)};for(const[l,h]of s){const d=h.index?h.index.array:void 0,u=h.attributes.position,f=u.array;if(u.isInterleavedBufferAttribute||d&&d.isInterleavedBufferAttribute){P.warn("[GenerateMeshBVHWorker] InterleavedBufferAttribute are not supported for the geometry attributes."),o();continue}const m=[];e.transferred&&(m.push(f),d&&(m.push(d),e.saveOriginalIndex&&(h.userData.originalIndex=d.slice()))),i.postMessage({id:l,index:d,position:f,options:Object.assign(Object.assign({},e),{onProgress:null,includedProgressCallback:!!e.onProgress,groups:[...h.groups]})},m.length>0?m.map(b=>b.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class zr{constructor(t){g(this,"running");g(this,"workers");this.running=!1,this.workers=[];let e=1;t?e=t:window.navigator&&(e=Math.max(e,window.navigator.hardwareConcurrency-1));for(let i=0;i<e;i++)this.workers[i]=new cl}isRunning(){return this.running}async generate(t,e={}){if(this.running){P.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){P.warn("[BVHHelper] Worker has been disposed.");return}return this.running=!0,new Promise(i=>{const s=this.workers.length,n=t.length,r=[],a=Math.floor(n/s),o=n%s;let l=0,h=0;for(let d=0;d<s;d++){const u=this.workers[d];if(d<o?(l=d*a+d,h=l+a+1):(l=d*a+o,h=l+a),l=Math.min(l,n),h=Math.min(h,n),l>=h)break;P.debug("startIndex: "+l+" endIndex: "+h),r.push(u.generate(t.slice(l,h),e))}Promise.allSettled(r).then(()=>{this.running=!1,i()})})}dispose(){for(let t=0;t<this.workers.length;t++)this.workers[t].dispose();this.workers=[]}static createMeshBvhSync(t,e={}){const i=new Set;t.forEach(s=>{s.traverse(n=>{const r=n;if(r.isMesh&&r.geometry&&fe.isMergedMesh(r)&&!(r instanceof p.InstancedMesh)){if(i.has(r.geometry.id))return;r.geometry.index&&e.saveOriginalIndex&&(r.geometry.userData.originalIndex=r.geometry.index.array.slice()),r.geometry.boundsTree=new ps(r.geometry,e),i.add(r.geometry.id)}})})}static createMeshBvhAsync(t,e={}){const i=new Set,s=[];t.forEach(r=>{r.traverse(a=>{const o=a;if(o.isMesh&&o.geometry&&fe.isMergedMesh(o)&&!(o instanceof p.InstancedMesh)){if(i.has(o.geometry.id))return;s.push(o.geometry),i.add(o.geometry.id)}})});const n=new zr;return n.generate(s,e).then(()=>{n.dispose()})}}class gu{constructor(t,e,i,s,n){g(this,"object");g(this,"camera");g(this,"targetPixelHeight",100);g(this,"canvasHeight",800);this.camera=t,this.object=i,this.targetPixelHeight=s,this.canvasHeight=n,this.adjustSize(),e.addEventListener("update",()=>{this.adjustSize()})}adjustSize(){const t=new p.Box3;if(this.object.updateMatrix(),t.expandByObject(this.object),!t)return;const e=t.max.x-t.min.x,i=this.camera.position.distanceTo(this.object.position),s=yu(e,i,this.canvasHeight);if(Math.abs(s-this.targetPixelHeight)<5)return;let r=this.object.scale.x;r*=this.targetPixelHeight/s,this.object.scale.set(r,r,r),this.object.updateMatrix()}}const yu=(c,t,e=800,i=45)=>{const s=i*(Math.PI/180),n=2*Math.tan(s/2)*t,r=c/n;return e*r},Js=new p.Vector2,Qs=new p.Vector2,en=new p.Vector2,oo=new p.Vector2,xu=new p.Vector2,bu=new p.Vector2,ye=class ye extends Ht{constructor(e){super(j.guid());g(this,"needsFrustumCulled");g(this,"renderOrder");g(this,"snapType");g(this,"osnapInfo");g(this,"drawSnapFunctions");g(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=Et.TripleCross,this.snapLineVisible=!1,this.snapType=e,this.drawSnapFunctions={TripleCross:this.drawTripleCorss.bind(this),Square:this.drawSquare.bind(this),Triangle:this.drawTriangle.bind(this),CircleWithCross:this.drawCircleWithCross.bind(this),Cross:this.drawCross.bind(this),Perpendicular:this.drawPerpendicular.bind(this)}}setSnapLineVisible(e){this.snapLineVisible=e}draw(e,i){this.osnapInfo&&(this.snapLineVisible&&this.drawSnapLine(e,i),e.save(),e.fillStyle=ye.FILL_COLOR_NONE,e.strokeStyle=ye.lineColor,e.lineWidth=ye.lineWidth,e.beginPath(),this.drawSnapFunctions[this.snapType](e,i),e.closePath(),e.fill(),e.stroke(),e.restore())}drawDebug(e,i){}drawSelect(e,i){}isPointInPath(e){return!1}drawSnapLine(e,i){e.save(),e.strokeStyle=ye.SNAP_LINE_COLOR,e.lineWidth=ye.lineWidth;const s=this.osnapInfo.line;if(!s)return;const n=this.transToScreenCoord(s.start,i),r=this.transToScreenCoord(s.end,i);e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke(),e.restore()}drawTripleCorss(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/1.6,r=Js.set(s.x,s.y-n),a=Qs.set(s.x-.87*n,s.y+n/1.4),o=en.set(s.x+.87*n,s.y+n/1.4);e.moveTo(s.x,s.y),e.lineTo(r.x,r.y),e.moveTo(s.x,s.y),e.lineTo(a.x,a.y),e.moveTo(s.x,s.y),e.lineTo(o.x,o.y)}drawSquare(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize,r=ye.iconSize;e.rect(s.x-n/2,s.y-r/2,n,r)}drawTriangle(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/1.6,r=Js.set(s.x,s.y-n),a=Qs.set(s.x-.87*n,s.y+n/2),o=en.set(s.x+.87*n,s.y+n/2);e.moveTo(r.x,r.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y)}drawCircleWithCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2;e.arc(s.x,s.y,n,0,Math.PI*2),e.moveTo(s.x-n/1.8,s.y),e.lineTo(s.x+n/1.8,s.y),e.moveTo(s.x,s.y-n/1.8),e.lineTo(s.x,s.y+n/1.8)}drawCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2,r=Js.set(s.x-n,s.y-n),a=Qs.set(s.x+n,s.y+n),o=en.set(s.x+n,s.y-n),l=oo.set(s.x-n,s.y+n);e.moveTo(r.x,r.y),e.lineTo(a.x,a.y),e.moveTo(o.x,o.y),e.lineTo(l.x,l.y)}drawPerpendicular(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),n=ye.iconSize/2,r=Js.set(s.x,s.y),a=Qs.set(s.x-n,s.y),o=en.set(s.x,s.y+n),l=oo.set(s.x-n,s.y-n),h=xu.set(s.x-n,s.y+n),d=bu.set(s.x+n,s.y+n);e.moveTo(a.x,a.y),e.lineTo(r.x,r.y),e.lineTo(o.x,o.y),e.moveTo(l.x,l.y),e.lineTo(h.x,h.y),e.lineTo(d.x,d.y),e.lineTo(l.x,l.y)}update(e){this.osnapInfo=e}getClassType(){return"SnapDrawable"}};g(ye,"lineColor","rgba(255, 119, 0, 1)"),g(ye,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),g(ye,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),g(ye,"lineWidth",2),g(ye,"iconSize",14);let _e=ye;bs._registerDrawableClass(_e);var hl=(c=>(c[c.None=0]="None",c[c.Vertex=1]="Vertex",c[c.MiddlePoint=2]="MiddlePoint",c[c.Edge=4]="Edge",c[c.Face=8]="Face",c[c.FootOfPerpendicular=16]="FootOfPerpendicular",c[c.Intersection=32]="Intersection",c[c.CircleCenter=64]="CircleCenter",c))(hl||{});const wu=1e-5,oe=new p.Vector3,Se=new p.Vector3,Di=new p.Vector3,cs=new p.Vector3,ti=new p.Matrix4,hs=new p.Line3;function vu(c,t){let e=Number.MAX_VALUE,i=0;for(let s=0;s<c.vertices.length;s++){const n=t.distanceTo(c.vertices[s]);n<e&&(i=s,e=n)}return{vertex:c.vertices[i],distance:e}}function Mu(c){if(!(c.object instanceof p.Mesh)||!c.face)return;const t=c.object,e=t.geometry.attributes.position;let i=t.geometry.index;if(e.count<3)return;const s=fe.getBatchByFaceIndex(t,c.faceIndex);t.geometry.boundsTree&&(i=new p.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),ti.identity(),t instanceof p.InstancedMesh&&c.instanceId!==void 0&&t.getMatrixAt(c.instanceId,ti),ti.premultiply(t.matrixWorld);const n=t.geometry.drawRange;let r,a=e.array;if(i){let f=Math.max(0,n.start),m=Math.min(i.count,n.start+n.count);if(r=i.array,s){f=Math.max(f,s.indexStart),m=Math.min(m,s.indexStart+s.indexCount),r=i.array.slice(f,m),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let b=0;b<r.length;b++)r[b]=r[b]-s.positionStart}else(f!==0||m!==i.count)&&(r=i.array.slice(f,m))}else{let f=Math.max(0,n.start),m=Math.min(e.count,n.start+n.count);s?(f=Math.max(f,s.positionStart),m=Math.min(m,s.positionStart+s.positionCount),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3)):(f!==0||m!==e.count)&&(a=e.array.slice(f*3,m*3));const b=a.length/3;r=b>65535?new Uint32Array(b):new Uint16Array(b);for(let y=0,C=b;y<C;y++)r[y]=y}const o=_o.buildEdge(a,r,20);let l=Number.MAX_VALUE,h=0;for(let f=0;f<o.length;f+=2){const m=o[f],b=o[f+1];oe.set(a[m*3],a[m*3+1],a[m*3+2]),oe.applyMatrix4(ti),Se.set(a[b*3],a[b*3+1],a[b*3+2]),Se.applyMatrix4(ti),hs.set(oe,Se),hs.closestPointToPoint(c.point,!0,Di);const y=c.point.distanceTo(Di);y<l&&(h=f,l=y,cs.copy(Di))}const d=o[h],u=o[h+1];return oe.set(a[d*3],a[d*3+1],a[d*3+2]),oe.applyMatrix4(ti),Se.set(a[u*3],a[u*3+1],a[u*3+2]),Se.applyMatrix4(ti),{vertices:[oe.clone(),Se.clone()],vertex:cs.clone(),distance:l}}class Tu{constructor(t){g(this,"drawableList",new ws("snap"));g(this,"overlayRender");g(this,"markers",{});g(this,"activeOSnapType",0);g(this,"snapToleranceInWorldCoord",1);g(this,"intersectionLimit",10);g(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});g(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new _e(Et.TripleCross),e=new _e(Et.Square),i=new _e(Et.Triangle),s=new _e(Et.CircleWithCross),n=new _e(Et.Cross),r=new _e(Et.Perpendicular);this.markers[1]=e,this.markers[2]=i,this.markers[4]=t,this.markers[32]=n,this.markers[64]=s,this.markers[16]=r,Object.values(this.markers).forEach(a=>{a.visible=!1,this.drawableList.addDrawable(a)})}isOSnapTypeEnabled(t){return!!(this.enabledOSnapTypes&t)}setOSnapTypeEnabled(t,e){if(e)this.enabledOSnapTypes|=t;else{const i=~t;this.enabledOSnapTypes&=i}}setSnapTolerance(t){this.snapToleranceInWorldCoord=t}getSnapTolerance(){return this.snapToleranceInWorldCoord}setIntersectionLimit(t){this.intersectionLimit=t}getIntersectionLimit(){return this.intersectionLimit}getMarkerLineColor(){return Li.colorStr2Rgba(_e.lineColor)}setMarkerLineColor(t){_e.lineColor=Li.rgba2Color(t)}getMarkerLineWidth(){return _e.lineWidth}setMarkerLineWidth(t){_e.lineWidth=t}getMarkerIconSize(){return _e.iconSize}setMarkerIconSize(t){_e.iconSize=t}getMarker(t){return this.markers[t]}setAllSnapLinesVisible(t){Object.values(this.markers).forEach(e=>{e.setSnapLineVisible(t)})}deactivate(){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1,this.overlayRender?.render()),this.activeOSnapType=0}destroy(){}handleSnap(t,e,i){if(!t||t.length<1){this.deactivate();return}P.debug("[OSnap] intersections before handleSnap:",t);const s=[];let n=!1,r;for(const o of t)o.object instanceof p.Mesh?(!r&&(r=o.point),!n&&o.object.name!=="groundPlane"&&(s.push(o),n=!0)):s.push(o);if(!e&&r){r.setZ(0);for(const l of s)l.point.z=0,l.distance=l.point.distanceTo(r);const o=l=>l instanceof p.Points?0:l instanceof p.LineSegments?2:l instanceof p.Line?1:3;s.sort((l,h)=>{const d=o(l.object),u=o(h.object);return d!==u?d-u:l.distance-h.distance})}return r||(P.warn("[OSnap] Potential to produce erroneous snap results"),r=s[0].point),P.debug("[OSnap] intersections:",s),P.debug("[OSnap] mousePosition:",r),this.getSnapPointAndUpdateMarker(r,s,e,i)?.clone()||r}getSnapPointAndUpdateMarker(t,e,i,s){if(!e.length){this.activateMarker(0);return}const n=this.getSnapInfo(t,e,i,s);if(!n||n.type===0){this.activateMarker(0);return}return this.activateMarker(n.type,n),n.point}activateMarker(t,e){this.activeOSnapType&&(this.markers[this.activeOSnapType].visible=!1),this.activeOSnapType=t;const i=this.markers[t];i&&e&&(i.update(e),i.visible=!0),this.overlayRender?.render()}getFootOfPerpendicular(t,e,i=wu){const{start:s,end:n}=e,r=s.x-n.x,a=s.y-n.y,o=s.z-n.z;if(s.distanceTo(n)<i)return s.clone();let l=(t.x-s.x)*(s.x-n.x)+(t.y-s.y)*(s.y-n.y)+(t.z-s.z)*(s.z-n.z);return l=l/(r*r+a*a+o*o),new p.Vector3(s.x+l*r,s.y+l*a,s.z+l*o)}getSnapInfo(t,e,i,s){const n=this.snapToleranceInWorldCoord*2;P.debug("[OSnap] snap radius:",n);const r=[],a={line:void 0};let o=this.osnapTypePriorities[0];for(let l=0;l<e.length&&l<this.intersectionLimit;++l){const h=e[l],d=h.object;let u;d instanceof p.Mesh?u=this.getOsnapInfoListFromMesh(t,h,n,o):d instanceof p.Line?u=this.getOsnapInfoListFromLine(t,h,i,n,a,o,s):d instanceof p.Points&&(u=this.getOsnapInfoListFromPoint(t,h,i,n,o)),u&&(o=this.osnapTypePriorities[u.type],r.push(u))}if(r.length!==0)return r.sort((l,h)=>{const d=this.osnapTypePriorities[l.type],u=this.osnapTypePriorities[h.type];return d!==u?d-u:l.distance-h.distance}),r[0]}getOsnapInfoListFromMesh(t,e,i,s){if(s<this.osnapTypePriorities[1])return;const n=Date.now(),r=Mu(e);if(!r){P.warn("[OSnap] Failed to get edge !");return}const a=Date.now();P.debug("[OSnap] getEdgeSnappingInfo took "+(a-n)/1e3+"s "),P.debug("[OSnap] edge:",r);const o=vu(r,t);if(P.debug("[OSnap] vertex:",o),o.distance<=i&&this.isOSnapTypeEnabled(1))return{distance:o.distance,type:1,point:o.vertex};if(r.distance<=i){if(this.isOSnapTypeEnabled(2)&&s<this.osnapTypePriorities[2])return;oe.copy(r.vertices[0]),oe.add(r.vertices[1]),oe.divideScalar(2);const l=oe.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:oe.clone()}:!this.isOSnapTypeEnabled(4)||s<this.osnapTypePriorities[4]?void 0:{distance:r.distance,type:4,point:r.vertex,line:{start:r.vertices[0],end:r.vertices[1]}}}else P.debug("[OSnap] Face")}getOsnapInfoFromSegment(t,e,i,s,n,r,a){const o={start:e,end:i};if(a&&r>=this.osnapTypePriorities[16]&&this.isOSnapTypeEnabled(16)){const f=this.getFootOfPerpendicular(a,o,s),m=t.distanceTo(f);if(m<=s)return{distance:z.floorNumber(m,7),type:16,point:f.clone()}}if(r<this.osnapTypePriorities[1])return;hs.set(e,i),hs.closestPointToPoint(t,!0,Di);const l=t.distanceTo(Di);if(l>s)return;const h=t.distanceTo(e),d=t.distanceTo(i);if(Math.min(h,d)<=s&&this.isOSnapTypeEnabled(1)){let f=h,m=e;return d<h&&(f=d,m=i),{distance:z.floorNumber(f,7),type:1,point:m.clone()}}if(r<this.osnapTypePriorities[2])return;hs.getCenter(cs);const u=t.distanceTo(cs);if(u<s&&this.isOSnapTypeEnabled(2))return{point:cs.clone(),distance:z.floorNumber(u,7),type:2};if(!(r<this.osnapTypePriorities[4])){if(n.line&&this.isOSnapTypeEnabled(32)){const f=N.getLineSegmentsIntersectingPoint(n.line,o);if(!f)return;const m=t.distanceTo(f)/2;return m<s?(n.line=void 0,{point:f.clone(),distance:z.floorNumber(m,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return n.line={start:e.clone(),end:i.clone()},{point:Di.clone(),distance:z.floorNumber(l,7),type:4,line:{start:e.clone(),end:i.clone()}}}}getOsnapInfoListFromLine(t,e,i,s,n,r,a){const o=[],l=e.object,h=l instanceof p.LineSegments?2:1,d=l.geometry.index,u=l.geometry.attributes.position,f=l.geometry.drawRange,m=fe.getBatchByLineIndex(l,e.index);if(d){let b=Math.max(0,f.start),y=Math.min(d.count,f.start+f.count);m&&(b=Math.max(b,m.indexStart),y=Math.min(y,m.indexStart+m.indexCount));for(let C=b,w=y;C<w-1;C+=h){const x=d.getX(C),E=d.getX(C+1);oe.fromBufferAttribute(u,x),Se.fromBufferAttribute(u,E),oe.applyMatrix4(l.matrixWorld),Se.applyMatrix4(l.matrixWorld),!i&&(oe.setZ(0),Se.setZ(0));const M=this.getOsnapInfoFromSegment(t,oe,Se,s,n,r,a);M&&(r=this.osnapTypePriorities[M.type],o.push(M))}}else{let b=Math.max(0,f.start),y=Math.min(u.count,f.start+f.count);m&&(b=Math.max(b,m.positionStart),y=Math.min(y,m.positionStart+m.positionCount));for(let C=b,w=y;C<w-1;C+=h){oe.fromBufferAttribute(u,C),Se.fromBufferAttribute(u,C+1),oe.applyMatrix4(l.matrixWorld),Se.applyMatrix4(l.matrixWorld),!i&&(oe.setZ(0),Se.setZ(0));const x=this.getOsnapInfoFromSegment(t,oe,Se,s,n,r,a);x&&(r=this.osnapTypePriorities[x.type],o.push(x))}}if(o.length!==0)return o.sort((b,y)=>{const C=this.osnapTypePriorities[b.type],w=this.osnapTypePriorities[y.type];return C!==w?C-w:b.distance-y.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,n){if(n<this.osnapTypePriorities[1])return;const r=e.object,a=r.geometry.getAttribute("position");oe.fromBufferAttribute(a,e.index),oe.applyMatrix4(r.matrixWorld),Se.copy(t),!i&&(oe.setZ(0),Se.setZ(0));const o=Se.distanceTo(oe);if(o>s)return;const l={distance:o,point:oe.clone(),type:1};if(r.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(P.debug("[OSnap] Other types of vertices !"),!this.isOSnapTypeEnabled(1))return;return l}getIntersectsIncludeOutline(t,e){const i=t.slice(),s=[];for(let r=0;r<t.length&&r<this.intersectionLimit;r++){const a=t[r].object;if(a.updateWorldMatrix(!0,!1),a instanceof p.Mesh&&!J.hasOutline(a,!1)){const o=J.createOutline(a.geometry);o.visible=!1,a.add(o),o.updateWorldMatrix(!0,!1),s.push(o)}}let n=[];return s.length>0&&(n=e.intersectObjects(s)||[],P.debug("[OSnap] Intersected with newly created edges: ",n),n.length>0&&i.push(...n)),i.sort((r,a)=>r.distance-a.distance),i}}class dl{constructor(t,e,i){g(this,"node");g(this,"parentNode");g(this,"target");g(this,"childNode");g(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});g(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));g(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));g(this,"destroy",()=>{this.target?this.target.removeEventListener("mousemove",this.follow):document.removeEventListener("mousemove",this.follow),this.parentNode.removeChild(this.node)});this.node=document.createElement("div"),this.node.id=t,e&&this.node.append(e),this.childNode=document.createElement("div"),this.target=i?.target,this.parentNode=i?.parentNode||document.body,i?.followPointer&&(this.node.classList.add("follow-tooltip"),this.target?this.target.addEventListener("mousemove",this.follow):document.addEventListener("mousemove",this.follow)),this.parentNode.appendChild(this.node),!i?.showOnCreate&&this.node.setAttribute("hidden","")}setContent(t){this.node.textContent&&(this.node.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.node.append(t),this.node.appendChild(this.childNode)}updateChildContent(t){this.childNode.textContent&&(this.childNode.textContent=null);for(let e=0;e<this.node.children.length;++e){const i=this.node.children[e];this.node.removeChild(i)}this.childNode.append(t)}}class Cu{constructor(t){g(this,"viewer");g(this,"active",!1);g(this,"tooltip");g(this,"resolve");g(this,"reject");g(this,"isResolvedOrRejected",!1);g(this,"mouseClicked",t=>{const e=t;if(e.markupData){const i=e.markupData.id,s=this.viewer.getOverlayRender().getDrawableById(i);if(s){let n=s.getBounds();n=n.clone().expandByScalar(20*this.viewer.getPixelSizeInWorldCoord());const r=Ee.world2NormalizedScreen(n.min,this.camera,this.viewerContainer),a=Ee.world2NormalizedScreen(n.max,this.camera,this.viewerContainer),o=new p.Box2(new p.Vector2(Math.min(r.x,a.x),Math.min(r.y,a.y)),new p.Vector2(Math.max(r.x,a.x),Math.max(r.y,a.y)));o.min.x=Math.max(o.min.x,0)*this.viewerContainer.clientWidth,o.min.y=Math.max(o.min.y,0)*this.viewerContainer.clientHeight,o.max.x=Math.min(o.max.x,1)*this.viewerContainer.clientWidth,o.max.y=Math.min(o.max.y,1)*this.viewerContainer.clientHeight,this.resolve&&(this.resolve(o),this.isResolvedOrRejected=!0),this.deactivate();const l=this.viewer;typeof l.clearSelection=="function"&&l.clearSelection()}}});g(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("PickMarkupHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.viewer.addEventListener(le.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new dl("pick-markup-tooltip",We.t("Tooltip.pickMarkup"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("pick-markup-tooltip");t&&(t.style.pointerEvents="none");const e=We.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(le.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(le.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(le.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Bi=class Bi{constructor(t){g(this,"viewer");g(this,"input");g(this,"mouseDown",!1);g(this,"mouseMove",!1);g(this,"mouseDownPositionX",-1);g(this,"mouseDownPositionY",-1);g(this,"tempKey");g(this,"tempTouch");g(this,"tempEnableRotate",!1);g(this,"rectDom");g(this,"tooltip");g(this,"active",!1);g(this,"resolve");g(this,"reject");g(this,"isResolvedOrRejected",!1);g(this,"mousedown",t=>{if(t.button===0){this.mouseDown=!0;const e=new p.Vector2(t.x,t.y);this.mouseDownPositionX=e.x,this.mouseDownPositionY=e.y,this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0}});g(this,"mousemove",t=>{if(!this.mouseDown)return;const e=new p.Vector2(t.x,t.y);if(this.mouseDownPositionX>=0&&this.mouseDownPositionY>=0&&(Math.abs(e.x-this.mouseDownPositionX)>=5||Math.abs(e.y-this.mouseDownPositionY)>=5)){this.mouseMove=!0;const s=new p.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),n=new p.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y));this.drawRect(s,n)}});g(this,"mouseup",t=>{if(this.mouseDown&&this.mouseMove){const e=new p.Vector2(t.x,t.y),i=new p.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),s=new p.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y)),n=new p.Box2(i,s);this.resolve&&(this.resolve(n),this.isResolvedOrRejected=!0),this.deactivate(),this.setRectDomVisible(!1)}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1});g(this,"keydown",t=>{t.code==="Escape"&&this.deactivate()});this.viewer=t,this.input=t.getInputManager()}get viewerContainer(){return this.viewer.viewerContainer}isActive(){return this.active}activate(){if(this.isActive()){this.reject&&(this.deactivate(),this.reject("BoxSelectHelper is already actived!"),this.isResolvedOrRejected=!0);return}this.active=!0,this.input.addEventListener("pointerdown",this.mousedown),this.input.addEventListener("pointermove",this.mousemove),this.input.addEventListener("pointerup",this.mouseup),this.input.addEventListener("keydown",this.keydown),this.viewer.getCameraManager().enableMouseLeft(!1),this.tooltip=new dl("box-select-tooltip",We.t("Tooltip.boxSelect"),{followPointer:!0,showOnCreate:!0,parentNode:this.viewer.widgetContainer,target:this.viewerContainer});const t=document.getElementById("box-select-tooltip");t&&(t.style.pointerEvents="none");const e=We.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(le.BoxSelectActivate)}deactivate(){this.active=!1,this.input.removeEventListener("pointerdown",this.mousedown),this.input.removeEventListener("pointermove",this.mousemove),this.input.removeEventListener("pointerup",this.mouseup),this.input.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.getCameraManager().enableMouseLeft(!0),this.viewer.dispatchEvent(le.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Bi.BORDER_WIDTH} solid ${Bi.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};g(Bi,"BORDER_COLOR","#fff000"),g(Bi,"BORDER_WIDTH","2px");let xn=Bi;class ul{constructor(t){g(this,"viewer");g(this,"boxSelectHelper");g(this,"active",!1);this.viewer=t,this.boxSelectHelper=new xn(t)}get viewerContainer(){return this.viewer.viewerContainer}get camera(){return this.viewer.camera}get raycaster(){return this.viewer.getRaycaster()}isActive(){return this.active}activate(){this.active=!0,this.boxSelectHelper?.select().then(t=>{t&&this.handleZoomToRect(t.min,t.max)})}deactivate(){this.active=!1,this.boxSelectHelper?.deactivate()}pickPositionByScreenPoint(t){return this.viewer.pickObject(t)?.point}handleZoomToRect(t,e){const i=this.pickPositionByScreenPoint(t),s=this.pickPositionByScreenPoint(e);if(i&&s){const n=new p.Vector3(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),r=new p.Vector3(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),a=new p.Box3(n,r);this.viewer.zoomToBBox(a)}}destroy(){this.boxSelectHelper?.destroy(),this.boxSelectHelper=void 0}}function lo(c){return c?c.replace(/%%[dD]/g,"°").replace(/%%[cC]/g,"⌀").replace(/%%[pP]/g,"±").replace(/%%(U|O)/gi,"").replace(/\\P/g," ").replace(/\\[A-Za-z][^;\\]*;/g,"").replace(/[{}]/g,"").replace(/\\\\/g,"\\").replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))).trim():""}const tn=new p.Box3,Su=new p.Vector3;function Eu(c,t){return c.trim().toLowerCase()===t?2e6:0}function Ou(c,t){const e=c.toLowerCase(),i=e.indexOf(t);if(i>=0)return(e===t?2e6:1e6)+(1e3-i)-Math.min(e.length,500);let s=0,n=-1,r=-1,a=0;for(let l=0;l<t.length;l++){const h=t[l];let d=-1;for(;s<e.length;s++)if(e[s]===h){d=s;break}if(d<0)return 0;n<0?n=d:r>=0&&d-r>1&&(a+=d-r-1),r=d,s=d+1}const o=5e5-a*50-n*5-Math.min(e.length,500);return o>0?o:1}class Mr{constructor(t){g(this,"viewer");g(this,"overlayRender");g(this,"drawableList");g(this,"indexedModelObject");g(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}buildIndex(){const t=this.getMasterModel();if(!t){this.index=[],this.indexedModelObject=void 0;return}const e=t.getModelObject();if(e===this.indexedModelObject&&this.index.length>0)return;this.indexedModelObject=e,this.index=[];const i=new p.Matrix4,s=new p.Vector3,n=new Map;e.updateWorldMatrix(!0,!0);const r=(a,o,l,h,d)=>{if(a&&n.has(a)){n.get(a).box.union(d);return}n.set(a||o+h,{text:o,layer:l,layoutName:h,box:d.clone()})};e.traverse(a=>{const o=a.userData;if(o){if(typeof o.textContent=="string"&&o.textContent.length){const l=lo(o.textContent);if(!l||(tn.makeEmpty(),tn.setFromObject(a),tn.isEmpty()))return;r(o.handle||"",l,o.layer||"0",this.findLayoutName(a),tn);return}if(Array.isArray(o.batches)){const l=a.geometry?.getAttribute?.("position");if(!l)return;i.copy(a.matrixWorld);for(const h of o.batches){const d=h?.userData?.textContent;if(typeof d!="string"||!d.length)continue;const u=lo(d);if(!u)continue;const f=new p.Box3,m=h.positionStart||0,b=h.positionCount||0;for(let y=m;y<m+b;y++)s.fromBufferAttribute(l,y).applyMatrix4(i),f.expandByPoint(s);f.isEmpty()||r(h.userData.handle||"",u,h.userData.layer||"0",this.findLayoutName(a),f)}}}}),n.forEach((a,o)=>{this.index.push({handle:o,layer:a.layer,layoutName:a.layoutName,text:a.text,box:a.box})})}findLayoutName(t){let e=t;for(;e;){if(e.userData?.isLayoutLevelObject===!0)return e.name||"Model";e=e.parent}return"Model"}search(t,e){const i=(t||"").trim().toLowerCase();if(!i)return[];this.buildIndex();const s=e?.mode??"fuzzy",n=e?.layer?.trim().toLowerCase(),r=e?.maxResults??200,a=[];for(const o of this.index){if(n&&o.layer.toLowerCase()!==n)continue;const l=s==="exact"?Eu(o.text,i):Ou(o.text,i);l>0&&a.push({item:o,score:l})}return a.sort((o,l)=>l.score-o.score),a.slice(0,r).map(o=>o.item)}focus(t){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const e=t.box.clone();this.viewer.zoomToBBox(e.expandByScalar(Math.max(e.getSize(Su).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new ws("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new wt(j.guid(),[t.box.clone()],[1,.55,0,1],[1,.55,0,.15])),this.viewer.enableRender())}clearHighlight(){this.drawableList?.clear(),this.viewer.enableRender()}invalidate(){this.indexedModelObject=void 0,this.index=[]}destroy(){this.clearHighlight(),this.overlayRender=void 0,this.drawableList=void 0,this.index=[],this.indexedModelObject=void 0}}class _u extends Ht{constructor(e){super("MobileHelper");g(this,"position");g(this,"needsFrustumCulled");g(this,"renderOrder");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.position=e}setPosition(e){this.position=e}isPointInPath(e,i){return!1}draw(e,i){this.drawInnerCircle(e),this.drawOuterRing(e),this.drawSnapTriangle(e)}drawInnerCircle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(137, 137, 138, 0.8)",e.beginPath(),e.arc(i,s,25,0,Math.PI*2),e.closePath(),e.fill(),e.restore()}drawOuterRing(e){const{x:i,y:s}=this.position;e.save(),e.strokeStyle="rgba(17, 17, 19, 0.8)",e.lineWidth=10,e.beginPath(),e.arc(i,s,30,0,Math.PI*2),e.closePath(),e.stroke(),e.restore(),e.save(),e.strokeStyle="rgba(173, 173, 174, 0.8)",e.lineWidth=3,e.beginPath(),e.arc(i,s,35,0,Math.PI*2),e.closePath(),e.stroke(),e.restore()}drawSnapTriangle(e){const{x:i,y:s}=this.position;e.save(),e.fillStyle="rgba(17, 17, 19, 0.8)",e.strokeStyle="rgba(137, 137, 138, 0.8)",e.lineWidth=2,e.beginPath(),e.moveTo(i-35,s-35),e.lineTo(i-35+12,s-35),e.lineTo(i-35,s-35+12),e.closePath(),e.fill(),e.stroke(),e.restore()}translate(e,i){this.position.add(new p.Vector2(e,i))}getTouchPoint(){return{x:this.position.x-35,y:this.position.y-35}}isIntersect(e){return this.position.x-35<e.x&&this.position.y-35<e.y&&this.position.x+35>e.x&&this.position.y+35>e.y}drawSelect(e,i){}getClassType(){return"MobileTouchHelperDrawable"}}var Je=(c=>(c[c.Left=0]="Left",c[c.Middle=1]="Middle",c[c.Right=2]="Right",c[c.Back=3]="Back",c[c.Forward=4]="Forward",c))(Je||{});class fl extends Nt{constructor(e){super();g(this,"element");g(this,"enabled");g(this,"keyboardEnabled");g(this,"mouseDownPositionX");g(this,"mouseDownPositionY");g(this,"lastLeftPointerUpTime");g(this,"pointers");g(this,"handleClick");g(this,"handlePointerDown");g(this,"handlePointerMove");g(this,"handlePointerUp");g(this,"handlePointerCancel");g(this,"handleMouseWheel");g(this,"handleContextMenu");g(this,"handlePointerEnter");g(this,"handlePointerLeave");g(this,"handleResize");g(this,"handleKeydown");g(this,"handleKeyup");g(this,"style");this.enabled=!0,this.keyboardEnabled=!0,this.mouseDownPositionX=0,this.mouseDownPositionY=0,this.lastLeftPointerUpTime=0,this.pointers=[],this.handleClick=i=>{if(!this.enabled)return;const s=this.getBaseEvent(i);this.dispatchEvent("click",s)},this.handlePointerDown=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isDoubleClick(s)?(this.lastLeftPointerUpTime=0,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1,this.dispatchEvent("dblclick",s)):(this.mouseDownPositionX=s.x,this.mouseDownPositionY=s.y),this.dispatchEvent("pointerdown",s),i.pointerType==="touch"?(this.pointers.push(s),s.pointers=this.pointers,this.dispatchEvent("touchstart",s)):this.dispatchEvent("mousedown",s)},this.handlePointerMove=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);this.isCloseToLastPosition(s)||(this.dispatchEvent("pointermove",s),i.pointerType==="touch"?(this.updatePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchmove",s)):this.dispatchEvent("mousemove",s))},this.handlePointerUp=i=>{if(!this.enabled)return;this.stop(i);const s=this.getBaseEvent(i);s.button===0&&(this.lastLeftPointerUpTime=s.timestamp),this.dispatchEvent("pointerup",s),i.pointerType==="touch"?(this.removePointers(s),s.pointers=this.pointers,this.dispatchEvent("touchend",s)):this.dispatchEvent("mouseup",s)},this.handlePointerCancel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointercancel",this.getBaseEvent(i)))},this.handleMouseWheel=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("wheel",this.getBaseEvent(i)))},this.handleContextMenu=i=>{if(this.enabled)return this.stop(i),this.dispatchEvent("contextmenu",this.getBaseEvent(i)),!1},this.handlePointerEnter=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerenter",this.getBaseEvent(i)))},this.handlePointerLeave=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("pointerleave",this.getBaseEvent(i)))},this.handleResize=i=>{this.enabled&&(this.stop(i),this.dispatchEvent("resize",this.getBaseEvent(i)))},this.handleKeydown=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keydown",this.getBaseEvent(i))},this.handleKeyup=i=>{!this.enabled||!this.keyboardEnabled||this.dispatchEvent("keyup",this.getBaseEvent(i))},this.style={},this.element=e,this.bindEvents()}getEnabled(){return this.enabled}setEnabled(e){this.enabled=e}getkKeyboardEnabled(){return this.keyboardEnabled}setkKeyboardEnabled(e){this.keyboardEnabled=e}setCursor(e){this.element.style&&(this.element.style.cursor=e||"default")}bindEvents(){this.element.style.touchAction="none",this.element.style.userSelect="none",this.element.style.webkitUserSelect="none",this.element.addEventListener("click",this.handleClick),this.element.addEventListener("pointerdown",this.handlePointerDown),this.element.addEventListener("pointermove",this.handlePointerMove),this.element.addEventListener("pointerup",this.handlePointerUp),this.element.addEventListener("pointercancel",this.handlePointerCancel),this.element.addEventListener("pointerenter",this.handlePointerEnter),this.element.addEventListener("pointerleave",this.handlePointerLeave),this.element.addEventListener("contextmenu",this.handleContextMenu),this.element.addEventListener("wheel",this.handleMouseWheel,{passive:!1}),window.addEventListener("resize",this.handleResize),window.addEventListener("keydown",this.handleKeydown),window.addEventListener("keyup",this.handleKeyup)}unBindEvents(){this.element.removeEventListener("pointerdown",this.handlePointerDown),this.element.removeEventListener("pointermove",this.handlePointerMove),this.element.removeEventListener("pointerup",this.handlePointerUp),this.element.removeEventListener("pointerenter",this.handlePointerEnter),this.element.removeEventListener("pointerleave",this.handlePointerLeave),this.element.removeEventListener("contextmenu",this.handleContextMenu),this.element.removeEventListener("wheel",this.handleMouseWheel),window.removeEventListener("resize",this.handleResize),window.removeEventListener("keydown",this.handleKeydown),window.removeEventListener("keyup",this.handleKeyup),this.element.style.touchAction="",this.element.style.userSelect="",this.element.style.webkitUserSelect=""}getBaseEvent(e){const i=e,s={x:0,y:0,pageX:0,pageY:0,clientX:0,clientY:0,deltaX:0,deltaY:0,movementX:0,movementY:0,deltaMode:0,pointerId:0,timestamp:0,buttons:0,pointerType:"mouse",altKey:!1,ctrlKey:!1,shiftKey:!1,metaKey:!1,originalEvent:i};if(s.timestamp=i.timeStamp,sn(i,"clientX"))if(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.clientX=i.clientX,s.clientY=i.clientY,s.button=i.button,sn(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const n=Ee.getScreenCoordinateByEvent(i,this.element);s.x=n.x,s.y=n.y,s.movementX=i.movementX,s.movementY=i.movementY}else sn(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else sn(i,"code")&&(s.altKey=i.altKey,s.ctrlKey=i.ctrlKey,s.shiftKey=i.shiftKey,s.metaKey=i.metaKey,s.code=i.code);return s}stop(e){e.preventDefault()}updatePointers(e){for(let i=0;i<this.pointers.length;i++)if(e.pointerId==this.pointers[i].pointerId){this.pointers[i]=e;break}}removePointers(e){for(let i=0;i<this.pointers.length;i++)if(this.pointers[i].pointerId==e.pointerId){this.pointers.splice(i,1);break}}getBoundingClientRect(){return this.element.getBoundingClientRect()}isCloseToLastPosition(e){return this.mouseDownPositionX===-1||this.mouseDownPositionY===-1?!1:Math.abs(e.x-this.mouseDownPositionX)<5&&Math.abs(e.y-this.mouseDownPositionY)<5}isDoubleClick(e){const s=e.timestamp-this.lastLeftPointerUpTime;return!!(e.button===0&&s<300&&this.isCloseToLastPosition(e))}}function sn(c,t){return c[t]!==void 0}class Pu{constructor(t){g(this,"CLEAR_COLOR");g(this,"CLEAR_COLOR_ALPHA");g(this,"EMPTY_MODEL_ID");g(this,"viewer");g(this,"raycaster");g(this,"pickingTexture");this.CLEAR_COLOR=new p.Color().setRGB(1,1,1),this.CLEAR_COLOR_ALPHA=1,this.EMPTY_MODEL_ID=255,this.viewer=t,this.raycaster=new p.Raycaster,this.pickingTexture=new p.WebGLRenderTarget(1,1)}get scene(){return this.viewer.scene}get camera(){return this.viewer.camera}get renderer(){return this.viewer.renderer}get overlayRender(){return this.viewer.getOverlayRender()}get viewerContainer(){return this.viewer.viewerContainer}getRaycaster(){return this.raycaster}pickObjectsByNdc(t,e,i){return!e||e.length===0?[]:(this.raycaster.setFromCamera(t,this.camera),this.setLayerChannels(i),this.raycaster.intersectObjects(e,!0)||[])}pickObject(t,e,i,s){const n=this.pickObjects(t,e,i,s);if(n.length!==0)return n[0]}pickObjects(t,e,i,s=0){const n=Ee.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const r=[],a=new Map,o=Ee.screen2Ndc(t,this.camera,this.viewerContainer),l=Ee.screen2Ndc({x:t.x+s,y:t.y},this.camera,this.viewerContainer),h=new p.Vector3(o.x,o.y,0).unproject(this.camera),d=new p.Vector3(l.x,l.y,0).unproject(this.camera),u=h.distanceTo(d),f=this.raycaster.params.Line.threshold;this.raycaster.params.Line.threshold=u,this.setLayerChannels(i);const m=8;for(let y=0;y<m;y++){const C=y/m*Math.PI*2,w=Math.cos(C)*s,x=Math.sin(C)*s,E={x:t.x+w,y:t.y+x},M=Ee.screen2Ndc(E,this.camera,this.viewerContainer);this.raycaster.setFromCamera(M,this.camera),this.raycaster.layers.enableAll();const O=this.raycaster.intersectObjects(e,!0)||[];for(const S of O)S.object&&!a.has(S.object.uuid)&&(a.set(S.object.uuid,S),r.push(S))}this.raycaster.setFromCamera(o,this.camera);const b=this.raycaster.intersectObjects(e,!0)||[];for(const y of b)y.object&&!a.has(y.object.uuid)&&(a.set(y.object.uuid,y),r.push(y));if(this.raycaster.params.Line.threshold=f,r.length>1){const y=this.raycaster.ray.origin.clone();r.sort((C,w)=>{const x=C.point||C.object.getWorldPosition(new p.Vector3),E=w.point||w.object.getWorldPosition(new p.Vector3);return x.distanceTo(y)-E.distanceTo(y)})}return r}return this.pickObjectsByNdc(n,e,i)}pickDrawable(t){return this.overlayRender.getDrawablesByPosition(t)}pick(t,e){const i=this.pickBuffer(t,e),s=[i[0],i[1],i[2],i[3]],n=Z1(s),r=K1(s);if(n!==this.EMPTY_MODEL_ID)return P.info("[PickMgr] Picked: tilesetId("+n+"), userId("+r+")"),{tilesetId:n,userId:r}}setLayerChannels(t){t&&t.length>0?(this.raycaster.layers.disableAll(),t.forEach(e=>{this.raycaster.layers.enable(e)})):this.raycaster.layers.enableAll()}pickBuffer(t,e,i=1,s=1){const{pickingTexture:n,renderer:r,camera:a}=this;n.setSize(i,s);const o=r.getPixelRatio(),l=r.getContext().drawingBufferWidth,h=r.getContext().drawingBufferHeight,d=t.x*o|0,u=t.y*o|0;a.setViewOffset(l,h,d,u,i,s),r.setRenderTarget(n);const f=new p.Color;r.getClearColor(f);const m=r.getClearAlpha();r.setClearColor(this.CLEAR_COLOR,this.CLEAR_COLOR_ALPHA),r.render(e,a);const b=new Uint8Array(4*i*s);return r.readRenderTargetPixels(n,0,0,i,s,b),r.setRenderTarget(null),a.clearViewOffset(),r.setClearColor(f,m),b}}const co=new p.Vector3;class Au{constructor(t){g(this,"viewer");g(this,"scene");g(this,"renderer");g(this,"pmremGenerator");g(this,"lights");g(this,"modelGroup");this.viewer=t;const e=new p.Scene;e.matrixAutoUpdate=ct,e.matrixWorldAutoUpdate=ct,this.scene=e,this.modelGroup=new p.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:n}=t.container;let r;try{r=new p.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0})}catch{try{r=new p.WebGLRenderer,P.warn("WebGL context created with fallback settings (antialias disabled).")}catch(o){throw this.showWebGLUnavailable(n),new Error("WebGLUnavailable: failed to create WebGL context. "+o.message)}}r.setPixelRatio(window.devicePixelRatio),r.setSize(i,s),r.outputColorSpace=p.SRGBColorSpace,r.toneMappingExposure=1,r.localClippingEnabled=!0,r.shadowMap.enabled=!1,r.shadowMap.type=p.PCFSoftShadowMap,r.shadowMap.autoUpdate=!1,r.domElement.style.outlineWidth="0",n?.appendChild(r.domElement),this.renderer=r,j.printGpuInfo(r.getContext())}showWebGLUnavailable(t){if(!t)return;const e=document.createElement("div");e.style.cssText=["position:absolute","left:0","top:0","width:100%","height:100%","display:flex","align-items:center","justify-content:center","text-align:center","padding:0 24px","box-sizing:border-box","background:rgba(255,255,255,0.95)","color:#333","font-size:14px","line-height:1.8","z-index:9999"].join(";"),e.textContent=We.t("WebGL.NotAvailable"),t.appendChild(e)}initLights(){const t=new p.Group;t.name="lights";const e=1.5,i=16777215,s=new p.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const n=new p.AmbientLight(i);n.name="ambient";const r=new p.HemisphereLight(i,14540253,.2);r.name="hemisphere",r.position.set(0,300,0);const a=new p.Group;a.name="lightHelpers",a.visible=!1;const o=new p.DirectionalLightHelper(s),l=new p.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(n),t.add(r),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new p.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}enableShadow(t){this.renderer.shadowMap.enabled=t,this.directionalLight.castShadow=t,t&&(this.tryAdjustDirectionalLight(),this.updateDirectionalLightShadow()),this.modelGroup.traverse(e=>{e.isMesh&&(e.castShadow=t,e.receiveShadow=t)})}enableClipping(t){this.renderer.localClippingEnabled=t}setClipPlanes(t){this.renderer.clippingPlanes=t}enableLights(t){let e=this.lights;e||(e=this.initLights()),e.visible=t}debugLights(t){!this.lights||!this.lightHelpers||(this.lightHelpers.visible=t)}setBackground(t){this.scene.background=t}get directionalLight(){return this.lights?.getObjectByName("sun")}get ambientLight(){return this.lights?.getObjectByName("ambient")}get hemisphereLight(){return this.lights?.getObjectByName("hemisphere")}get lightHelpers(){return this.lights?.getObjectByName("lightHelpers")}get directionalLightHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];if(i instanceof p.DirectionalLightHelper){t=i;break}}return t}get cameraHelper(){let t;for(let e=0;this.lightHelpers&&e<this.lightHelpers?.children.length;++e){const i=this.lightHelpers.children[e];i instanceof p.CameraHelper&&(t=i)}return t}async setEnvironmentFromData(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ms.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ms.createEnvTexture(this.pmremGenerator,t);this.scene.environment?.dispose(),this.scene.environment=e}resize(){const{width:t,height:e}=this.viewer.container;this.renderer.setSize(t,e)}getRaycastableObjects(){const t=[];return this.modelGroup.traverse(e=>{t.push(e)}),t}tryAdjustDirectionalLight(){const t=this.directionalLight;if(!t)return;const e=this.viewer.getBBox(),i=new p.Sphere;e.getBoundingSphere(i);const s=i.center,n=i.radius,r=t.shadow.camera;r.zoom=1,r.top=n,r.bottom=-n,r.right=n,r.left=-n,r.near=.1,r.far=2*n,r.updateProjectionMatrix();const a=new p.Vector3(-1,-.5,1);a.normalize().multiplyScalar(n),t.position.copy(s).addScaledVector(a,-1),t.target.position.copy(s),P.debug("[Scene] directionalLight.position",t.position),P.debug("[Scene] directionalLight.target.position",t.target.position),this.updateDirectionalLight(),this.viewer.enableRender()}updateDirectionalLight(){const t=this.directionalLight;if(t&&(t.updateMatrixWorld(),t.target.updateMatrixWorld(),this.directionalLightHelper&&(this.directionalLightHelper.update(),this.scene?.matrixAutoUpdate||this.directionalLightHelper.updateWorldMatrix(!1,!0)),t.shadow.needsUpdate=!0,t.shadow.camera.updateProjectionMatrix(),this.cameraHelper&&(this.cameraHelper.update(),!this.scene?.matrixAutoUpdate))){const e=t.shadow.camera;e.position.setFromMatrixPosition(t.matrixWorld),co.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(co),e.updateMatrixWorld(),this.cameraHelper.updateWorldMatrix(!1,!0)}}updateDirectionalLightShadow(){this.directionalLight&&(this.directionalLight.shadow.needsUpdate=!0)}showDirectionalLightHelper(t){this.directionalLightHelper&&(this.directionalLightHelper.visible=t),this.cameraHelper&&(this.cameraHelper.visible=t)}destroy(){this.lightHelpers?.clear(),this.lightHelpers?.removeFromParent(),this.lightHelpers?.traverse(t=>{t.dispose?.call(t)}),this.lights?.clear(),this.lights?.removeFromParent(),this.lights?.traverse(t=>{t.dispose?.call(t)}),this.lights=void 0,this.pmremGenerator?.dispose(),this.renderer.domElement.remove(),this.renderer.clear(),this.renderer.dispose(),this.renderer.forceContextLoss(),this.scene.clear()}}class Iu{constructor(t){g(this,"history");g(this,"step");g(this,"maxCount");g(this,"isBatchCommand");g(this,"batchCommands");this.history=[],this.step=0,this.maxCount=50,this.isBatchCommand=!1,this.batchCommands=[],this.maxCount=t||this.maxCount}addCommand(t){this.isBatchCommand?this.batchCommands.push(t):(this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.history.push(t),this.step++)}startTransaction(){this.isBatchCommand=!0}endTransaction(){this.history.length===this.maxCount&&this.history.shift(),this.step!==this.history.length&&this.history.splice(this.step),this.batchCommands.length>0&&(this.history.push(this.batchCommands.slice()),this.step++),this.isBatchCommand=!1,this.batchCommands=[]}undo(){if(this.canUndo())return!1;this.step--;const t=this.history[this.step];return t&&(Array.isArray(t)?t.forEach(e=>e.undo()):t.undo()),!0}redo(){if(this.canRedo())return!1;this.step++;const t=this.history[this.step-1];return t&&(Array.isArray(t)?t.forEach(e=>e.redo()):t.redo()),!0}getCommands(){return this.history}canUndo(){return this.step<=0}canRedo(){return this.step>=this.history.length}clear(){this.history=[],this.step=0}destroy(){this.clear(),this.maxCount=0}}class Mn extends Nt{constructor(e){super();g(this,"name");g(this,"viewerCfg");g(this,"clock");g(this,"targetMaxFps");g(this,"timeStamp");g(this,"renderEnabled");g(this,"requestAnimationFrameHandle");g(this,"container");g(this,"plugins");g(this,"loadedModels");g(this,"raf");g(this,"timeoutSymbol");g(this,"homeView");g(this,"inputManager");g(this,"cameraManager");g(this,"sceneManager");g(this,"fontManager");g(this,"pickManager");g(this,"undoManager");g(this,"overlayRender");g(this,"css2dRenderer");g(this,"spinner");g(this,"progressBar");g(this,"loaderHelper");g(this,"zoomToRectHelper");g(this,"_enableSelection");g(this,"enableRender");this.name=$e.BaseViewer,this.clock=new p.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new ol,this._enableSelection=!0,this.enableRender=(i=1e3)=>{this.renderEnabled=!0,this.raf&&(this.timeoutSymbol&&this.raf.clearTimeout(this.timeoutSymbol),this.timeoutSymbol=this.raf.setTimeout(()=>{this.renderEnabled=!1},i))},this.viewerCfg=e,this.initLogLevel(),this.initLocalization(),this.container=new Rr(e.containerId),e.enableProgressBar&&(this.progressBar=new Fr(this.container)),this.spinner=new tl(this.container),this.sceneManager=new Au(this),this.pickManager=new Pu(this),this.overlayRender=new bs(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new fl(this.viewerContainer),this.cameraManager=new ou(this),this.loaderHelper=new Vt,this.undoManager=new Iu,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&To(e)}initLocalization(){const e=this.viewerCfg.language||So;We.changeLanguage(e)}get viewerContainer(){return this.container.viewerContainer}get widgetContainer(){return this.container.widgetContainer}getUndoManager(){return this.undoManager}getInputManager(){return this.inputManager}getCssRender(){return this.css2dRenderer}getCameraManager(){return this.cameraManager}getOverlayRender(){return this.overlayRender}getSceneManager(){return this.sceneManager}get renderer(){return this.sceneManager.renderer}get camera(){return this.cameraManager.camera}get scene(){return this.sceneManager.scene}getRaycaster(){return this.pickManager.getRaycaster()}getViewerConfig(){return this.viewerCfg}getSpinner(){return this.spinner}getFontManager(){return this.fontManager}initCSS2DRenderer(){const e=new yo.CSS2DRenderer,{width:i,height:s}=this.viewerContainer.getBoundingClientRect();return e.setSize(i,s),e.domElement.style.height="0",e.domElement.style.width="0",e.domElement.style.position="absolute",e.domElement.style.top="0",e.domElement.style.left="0",e.domElement.style.overflow="visible",e.domElement.classList.add("css2d-renderer"),this.viewerContainer?.appendChild(e.domElement),e}animate(){const e=Date.now()-this.timeStamp,i=1/this.targetMaxFps;if(e<i){this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this));return}const s=this.cameraManager.update(this.clock.getDelta());this.container.needResize&&(this.resize(),this.renderEnabled=!0),(this.renderEnabled||s)&&(this.dispatchEvent(le.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(le.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(le.OnAnimate)}resize(){this.sceneManager.resize(),this.cameraManager.updateAspect();const{clientWidth:e,clientHeight:i}=this.viewerContainer;this.css2dRenderer.setSize(e,i),this.overlayRender.setSize(e,i)}setDracoDecoderPath(e){Vt.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=ct,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new xt),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let n=1;if(e.type==="OrthographicCamera"){const r=e;n=Math.max(r.right-r.left,r.top-r.bottom)/r.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const r=e,a=new p.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(n=2*(a.distanceTo(o)*Math.tan(r.fov/2*(Math.PI/180)))/s)}return n}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new ul(this)),this.zoomToRectHelper.activate()}deactivateZoomRect(){this.zoomToRectHelper?.deactivate()}getUniqueModelId(e){let i=e;const s=n=>!!this.loadedModels.find(r=>r.modelId===n);if(s(i)){let n=1;for(;s(i+"_"+n);)n++;i=i+"_"+n,P.warn("[Viewer] Model '"+i+"' is loaded more than once!")}return i}getBBox(){const e=new p.Box3;return this.loadedModels.forEach(i=>{e.union(i.getBBox())}),e}flyToObject(e){this.cameraManager.flyToObject(e)}flyToObjects(e){const i=new p.Box3;e.forEach(n=>{const r=new p.Box3().setFromObject(n);i.union(r)});const s=new p.Sphere;i.getBoundingSphere(s),this.cameraManager.fitToSphere(s)}flyTo(e,i,s=!0){const n=this.camera;if(e.equals(i)){P.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!j.isVectorValid(e)||!j.isVectorValid(i)){P.error("[Viewer] invalid position or lookAt!");return}const r=e.distanceTo(i);r<n.near?(e=e.clone().sub(i).normalize().multiplyScalar(n.near*1.1),P.warn("[Viewer] camera could be too close to see the object!")):r>n.far&&(e=e.clone().sub(i).normalize().multiplyScalar(n.far*.9),P.warn("[Viewer] camera could be too far to see the object!")),this.cameraManager.flyTo(e,i,s)}flyToDirection(e){const i=this.getBBox(),s=i.getSize(new p.Vector3);let n=Math.max(s.x,s.y,s.z)/2;n===0&&(n=1);const r=this.cameraManager.getDistanceToFitSphere(n),a=new p.Vector3;i.getCenter(a);const o=a.clone().add(e.clone().multiplyScalar(r));this.flyTo(o,a)}goToHomeView(){if(this.homeView)this.cameraManager.flyToViewpoint(this.homeView);else{const e=new p.Vector3(1,.5,1);this.flyToDirection(e)}}viewFitAll(){const e=this.getBBox(),i=new p.Sphere;e.getBoundingSphere(i),this.cameraManager.fitToSphere(i)}zoomToBBox(e){this.cameraManager.flyToBox(e)}pickObject(e,i,s){let n=this.pickManager.pickObject(e,this.getRaycastableObjects(),i,s);return this.renderer&&this.renderer.clippingPlanes.length>0&&this.renderer?.clippingPlanes?.every(a=>{n&&a.distanceToPoint(n.point)>0})&&(n=void 0),n}pickObjects(e,i){let s=this.pickManager.pickObjects(e,this.getRaycastableObjects(),i);return s&&this.renderer.clippingPlanes.length>0&&(s=s.filter(n=>this.renderer.clippingPlanes.every(r=>r.distanceToPoint(n.point)>0))),s}getRaycastableObjects(){return this.sceneManager.getRaycastableObjects()}setBackgroundColor(e,i,s){if(!this.scene.background&&(this.scene.background=new p.Color(e,i,s)),this.scene.background instanceof p.Color){const n=new p.Color;n.setRGB(e,i,s,this.renderer.outputColorSpace),this.scene.background.copy(n)}this.enableRender()}setGlobalClipPlanes(e){}getCameraProjection(){return this.cameraManager.getProjection()}setCameraProjection(e){this.cameraManager.setProjection(e)}enableControl(e){this.cameraManager.enableControl(e)}enableRotate(e){this.cameraManager.enableRotate=e}enableZoom(e){this.cameraManager.enableZoom(e)}enablePan(e){this.cameraManager.enablePan(e)}getHomeView(){return this.homeView}setHomeView(e){this.homeView=e}getCameraConfig(){return this.cameraManager.getCameraConfig()}setCameraConfig(e){return this.cameraManager.setCameraConfig(e)}getCameraDirection(){return this.cameraManager.getCameraDirection()}getRenderInfo(){const e=this.renderer.info;return{drawCalls:e.render.calls,lines:e.render.lines,points:e.render.points,triangles:e.render.triangles,geometries:e.memory.geometries,textures:e.memory.textures,materials:e.programs?.length||0}}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.css2dRenderer.domElement.remove(),this.container.destroy(),this.sceneManager.destroy(),this.cameraManager.destroy(),this.overlayRender.destroy(),this.spinner.destroy(),this.progressBar?.destroy(),this.undoManager.destroy()}addPlugin(e){if(this.plugins.find(s=>s.id===e.id)){P.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),P.debug("[Viewer] Added plugin: "+e.id)}removePlugin(e){for(let i=0,s=this.plugins.length;i<s;i++)if(this.plugins[i]===e){this.plugins.splice(i,1);return}}clearPlugins(){this.plugins=[]}findPlugin(e){return this.plugins.find(i=>i.id===e)}}const pl=-1e3,Mi=new p.Vector3,ho=new p.Matrix4,uo=new p.Frustum,nr=new p.Box3,fo=new p.Matrix4;class Vr extends Mn{constructor(e){super(e);g(this,"name");g(this,"loadedModels");g(this,"masterModelId");g(this,"activeLayoutName");g(this,"dxfLayoutBar");g(this,"layoutInfos");g(this,"units");g(this,"enableHideVisuallySmallObjects");g(this,"sortedHidableObjects");g(this,"lastCameraZoom");g(this,"groundPlane");g(this,"raycastableObjects");g(this,"selectedObject");g(this,"loadingDxfCount");g(this,"textSearchHelper");g(this,"clickHighlightList");g(this,"_enableClickHighlight",!1);g(this,"requestHeaders");g(this,"_printCaptureMode",!1);this.name=$e.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects!==!1,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new tu(this)),this.cameraManager.setProjection(bt.Orthographic),this.cameraManager.setNavigationMode(ot.Plan);const i=new p.Vector3(0,0,100),s=new p.Vector3(0,0,0);this.cameraManager.setCameraConfig({eye:i,look:s}),this.resize(),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(le.BeforeRender,()=>{this.updateRaycasterThreshold(),this.updateCameraZoomUniform(this.camera.zoom),this.updateHidableObjectsVisibility()})}get camera(){return this.cameraManager.camera}setupDefaultEvents(){let e=!1,i=!1;this.inputManager.addEventListener("pointerdown",s=>{i=!1,e=!0,s.button===Je.Middle&&this.inputManager?.setCursor("move")}),this.inputManager.addEventListener("pointermove",()=>{e&&(i=!0,this.inputManager?.setCursor("move"))}),this.inputManager.addEventListener("pointerup",s=>{if(e=!1,this.inputManager?.setCursor("default"),i){i=!1;return}const n=new p.Vector2(s.x,s.y),r=this.getWorldPositionByMousePick(n),a=this.pickManager.pickObjects(n,this.getRaycastableObjects(),void 0,3);let o;for(const d of a){const u=this.resolveEntityFromPick(d);if(u){u.hit=d,o=u;break}}const l=o?.userData;if(this._enableClickHighlight&&o){const d=this.getEntityBoundingBox(o);d&&this.highlightEntityBox(d)}else this.clearClickHighlight();const h={event:s,position:n,worldPosition:r,pooo:r,entity:l?o?.object:void 0,object:l?o?.object:void 0,point:l?o?.hit?.point:void 0,userData:l,handle:l?.handle};this.dispatchEvent(le.MouseClick,h)})}resolveEntityFromPick(e){if(!e)return;const i=e.object,s=i.userData?.batches;if(s&&s.length>0){const r=i.geometry,a=i.isMesh===!0,o=e.index;let l;a&&typeof e.faceIndex=="number"&&(l=r?.index?r.index.getX(e.faceIndex*3):e.faceIndex*3);const h=s.find(d=>{const u=typeof o=="number"&&o>=d.indexStart&&o<d.indexStart+(d.indexCount||1),f=typeof o=="number"&&o>=d.positionStart&&o<d.positionStart+d.positionCount||typeof l=="number"&&l>=d.positionStart&&l<d.positionStart+d.positionCount;return u||f});if(h?.userData)return{userData:h.userData,batch:h,object:i}}let n=i;for(;n;){if(n.userData?.handle)return{userData:n.userData,object:n};n=n.parent??void 0}}getEntityBoundingBox(e){const i=e.object,s=i.geometry?.getAttribute?.("position");if(e.batch&&s){const r=new p.Box3,a=e.batch.positionStart||0,o=e.batch.positionCount||0;if(o>0){i.updateWorldMatrix(!0,!1),fo.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Mi.fromBufferAttribute(s,l).applyMatrix4(fo),r.expandByPoint(Mi);if(!r.isEmpty())return r}}const n=new p.Box3;return n.setFromObject(i),n.isEmpty()?void 0:n}highlightEntityBox(e){const i=this.getOverlayRender();i&&(!this.clickHighlightList&&(this.clickHighlightList=new ws("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new wt(j.guid(),[e.clone()],[.031,.906,.867,1],[.031,.906,.867,.15])),this.enableRender())}get enableClickHighlight(){return this._enableClickHighlight}set enableClickHighlight(e){this._enableClickHighlight=e,e||this.clearClickHighlight()}clearClickHighlight(){this.clickHighlightList?.clear(),this.enableRender()}setRequestHeaders(e){this.requestHeaders=e}handleMouseClick(e){if(!this.enableSelection)return;const i=new p.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const n=this.overlayRender.getDrawablesByPosition(s)[0];if(n){this.selectedObject===n?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=n,this.selectedObject.selected=!0),this.enableRender();return}const r=this.pickObject(i,[Ut]);if(r){const a=r?.object;this.selectedObject===a?(this.setObjectUnHighlight(this.selectedObject),this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=a,this.setObjectHighlight(this.selectedObject)),this.enableRender();return}this.clearSelection(),this.enableRender()}setDefaultBackground(){this.setBackgroundColor(.0295,.0212,.0152)}async loadModel(e,i,s){const n=this.getUniqueModelId(e.modelId||e.src);this.spinner.increaseJobCount(),this.loaderHelper.setFont(this.fontManager),this.masterModelId||(this.masterModelId=n);const r=n,a=We.t("ProgressBar.Loading"),o=b=>{this.progressBar?.updateProgress(r,a,b),i?.(new ProgressEvent("LoadProgress",{loaded:b,total:100}))},l=(b,y,C)=>{let w=b.loaded*100/b.total;w=w*(C-y)/100+y,this.progressBar?.updateProgress(r,a,w),i?.(new ProgressEvent("LoadProgress",{loaded:w,total:100}))},h=b=>l(b,0,90);this.progressBar?.addProgressItem(r),o(0);const d=this.viewerCfg,u=await this.loaderHelper.loadDxfData(e.src,e.modelId,h,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:d.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor,requestHeaders:e.headers??this.requestHeaders}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),f=u.threejsObject;if(s&&s({threejsObject:f,llbMesh:u.llbMesh}),e.matrix&&e.matrix.length===16){const b=new p.Matrix4;b.elements=e.matrix,f.applyMatrix4(b)}const m=new Ri({modelId:n,dxfData:u});this.addModel(m),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(r),this.dispatchEvent(le.ModelLoad)}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(X.MODEL_LAYOUT_NAME):this.handleOverlayDxf(i);const s=e.getBBox(),n=new p.Vector3;s.getCenter(n),this.cameraManager.adjustCameraByBBox(s);const r=this.getDxfUnits(e);this.masterModelId===i&&(this.units=r)}else{const s=e.getModelObject();this.activeLayoutName=X.MODEL_LAYOUT_NAME;const n=new p.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:n,extent:n},s.matrixAutoUpdate=ct,this.scene.add(s);const r=n.max.z;r>this.camera.position.z&&(this.camera.position.z=r,this.camera.updateProjectionMatrix()),this.flyToObject(s)}this.updateGroundPlane()}getDxfUnits(e){return!e&&this.loadedModels.length>0&&(e=this.loadedModels.find(i=>this.masterModelId===i.modelId)),e?e.getUnits():Ke.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(n=>e===n.modelId);if(!i){P.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(X.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(X.MODEL_LAYOUT_NAME)?.traverse(n=>{i.addSpatialFilterSection(n,i.dxfData)}),i.showLayoutObjects(X.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof p.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clickHighlightList?.clear()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],n=(o,l,h)=>{s.push(new p.Vector3(o,l,h))},r=i.getSize(new p.Vector3),a=i.getCenter(new p.Vector3);if(n(-r.x/2,-r.y/2,0),n(r.x/2,-r.y/2,0),n(r.x/2,r.y/2,0),n(-r.x/2,r.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new p.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new p.MeshBasicMaterial({color:"#888",side:p.DoubleSide});this.groundPlane=new p.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=pl,this.groundPlane.layers.enableAll(),J.disableLayerChannels(this.groundPlane,[Ut]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===X.MODEL_LAYOUT_NAME){if(this.raycastableObjects)return this.raycastableObjects;if(this.renderer?.renderLists){const s=this.renderer?.renderLists.get(this.scene,0);s&&(s.opaque.forEach(n=>{n.object&&n.object.geometry&&e.push(n.object)}),s.transparent.forEach(n=>{n.object&&n.object.geometry&&e.push(n.object)}))}ho.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),uo.setFromProjectionMatrix(ho);for(const s of this.loadedModels){const n=s.getModelObject(),r=n.children.find(a=>a.name===this.activeLayoutName);r&&r.children.find(o=>o.name===X.SNAP_GROUP_NAME)?.traverse(o=>{if(J.isLeafObject(o)){if(nr.makeEmpty(),nr.expandByObject(o),!uo.intersectsBox(nr))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),P.debug("[Viewer] getRaycastableObjectsByMouse() from modelSpace"),this.raycastableObjects=e}else{const s=new WeakSet,n=this.getLayoutByName(this.activeLayoutName);n&&n.directAssociatedLeafObjectSet?.forEach(o=>{o.visible&&!s.has(o)&&(e.push(o),s.add(o))});const r=this.getViewportByPoint(this.pickManager.getRaycaster().ray.origin);r&&r.associatedLeafObjectSet?(r.associatedLeafObjectSet?.forEach(a=>{!s.has(a)&&(a.visible||a.userData.isSnapObject)&&(e.push(a),s.add(a))}),P.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",r.viewportId)):P.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return P.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===X.MODEL_LAYOUT_NAME)return;const i=this.getLayoutByName(this.activeLayoutName);if(!i)return;const s=a=>e.x<a.min.x||e.x>a.max.x||e.y<a.min.y||e.y>a.max.y,n=this.loadedModels.find(a=>this.masterModelId===a.modelId);if(!n)return;const r=n.getFilteredViewports(i);for(let a=0,o=r.length;a<o;a++){const l=r[a];if(!s(l.psBBox))return l}}getWorldPositionByMousePick(e){const i=[];this.groundPlane&&i.push(this.groundPlane);for(const n of this.loadedModels){const r=n.getModelObject();r&&(i.push(r),r.traverse(a=>{(a.isMesh||a.isLine)&&i.push(a)}))}return this.pickManager.pickObject(e,i)?.point}activateLayout(e=X.MODEL_LAYOUT_NAME){if(this.activeLayoutName===e||!this.masterModelId)return;const i=this.loadedModels.find(d=>this.masterModelId===d.modelId);if(!i)return;const s=i.getLayoutByName(e);if(!s)return;const n=this.getActiveLayoutInfo();if(this.groundPlane){const d=this.getCurrentViewExtent(),u=this.camera.position.z;n.lastViewExtent=new p.Box3(new p.Vector3(d.min.x,d.min.y,0),new p.Vector3(d.max.x,d.max.y,u))}const r=d=>!!this.layoutInfos[d]?.lastViewExtent,a=r(e);i?.activateLayout(e,a),this.activeLayoutName=e;const o=i.getFilteredViewports(s);if(P.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const d=this.camera.position.z;let u=0;o.forEach(m=>{const b=m?.msToPsMatrix?.elements[14];b&&b>u&&(u=b)});const f=this.cameraManager.getPosition();if(u>f.z+d){const m=Math.ceil(u+d);f.z=m,P.info("[Viewer] Changing camera's z value from "+f.z+" to "+m),this.cameraManager.setCameraPosition(f)}}const l=this.getActiveLayoutInfo();if(l.lastViewExtent)this.zoomToBBox(l.lastViewExtent);else{l.extent=this.getBBox();let d=this.getLayoutExtentEx(s);if(d){const b=d.max.x-d.min.x,y=d.max.y-d.min.y;(b<1e-16||y<1e-16||b>1e16||y>1e16)&&(P.warn("[Viewer] Got wired bbox, max: "+d.max.toArray()+", min: "+d.min.toArray()+", going to use the calculated one..."),d=l.extent)}else P.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),d=l.extent;const u=l.extent;d&&!u.isEmpty()&&(d.intersectsBox(u)?d.union(u):(P.warn("[Viewer] Layout extent from header is far from actual geometry, using computed bbox instead."),d=u.clone())),l.homeViewExtent=d,this.zoomToBBox(d)}const h=i.getLayoutLevelObject(e);h&&this.setLayoutHidableObjectArray(h),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===X.MODEL_LAYOUT_NAME?i.getModelSpaceExtent():i.getLayoutExtent(e)}getActiveLayoutInfo(){return this.getLayoutInfo(this.activeLayoutName)}getLayoutByName(e){let i;const s=this.loadedModels.find(r=>this.masterModelId===r.modelId);if(!s)return;const n=s.getLayouts();for(const r of n)if(r.layoutName===e){i=r;break}return i}getEntityCount(){let e=0;return this.loadedModels.forEach(i=>{e+=i.loadedEntityCount}),e}getLayoutNames(){const e=[];return(this.loadedModels.find(n=>this.masterModelId===n.modelId)?.getLayouts()||[]).forEach(n=>{e.push(n.layoutName)}),e}getLayoutInfo(e){return this.layoutInfos[e]||(this.layoutInfos[e]={}),this.layoutInfos[e]}goToHomeView(){const e=this.getActiveLayoutInfo();e.homeViewExtent?this.zoomToBBox(e.homeViewExtent):P.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Mi),s=e.max.x-e.min.x,n=e.max.y-e.min.y,r=this.camera.right-this.camera.left,a=this.camera.top-this.camera.bottom;let o=Math.min(r/s,a/n);o/=1.1,this.cameraManager.cameraControls.moveTo(i.x,i.y,i.z),this.cameraManager.cameraControls.zoomTo(o)}getCurrentViewExtent(){const e=this.getHitResultByNdcCoordinate(new p.Vector2(-1,-1)),i=this.getHitResultByNdcCoordinate(new p.Vector2(1,1));return new p.Box2(e,i)}getHitResultByNdcCoordinate(e){const i=[];this.groundPlane&&i.push(this.groundPlane);const s=this.pickManager.pickObjectsByNdc(e,i);if(s.length>0){const n=s[0].point;return new p.Vector2(n.x,n.y)}}getHitResult(e){const i=this.viewerContainer,s=Ee.getScreenCoordinateByEvent(e,i),n=Ee.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(n)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new Mr(this)),this.textSearchHelper.search(e,i)}focusText(e){!this.textSearchHelper&&(this.textSearchHelper=new Mr(this)),this.textSearchHelper.focus(e)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}async print(e={}){const{area:i="view",paperSize:s="A4",orientation:n="auto",invertColors:r=!1,fitToPage:a=!0,margins:o=10,title:l="图纸"}=e;if(!this.loadedModels.length){P.warn("[Viewer] print: no model loaded.");return}const h=this.capturePrintImage(i,r),d=new Image;await new Promise((f,m)=>{d.onload=()=>f(),d.onerror=()=>m(new Error("Failed to load captured print image.")),d.src=h});const u=n==="auto"?d.width>=d.height?"landscape":"portrait":n;this.printImageInIframe({dataUrl:h,width:d.width,height:d.height,paperSize:s,orientation:u,invertColors:r,fitToPage:a,margins:o,title:l})}capturePrintImage(e,i){const s=this.cameraManager.cameraControls,n=this.renderer,r=s.getPosition(new p.Vector3),a=s.getTarget(new p.Vector3),o=this.camera.zoom,l=n.getPixelRatio();let h;e==="extents"&&(h=this.getActiveLayoutInfo().homeViewExtent??this.getBBox(),this.zoomToBBox(h)),this._printCaptureMode=!0;const d=this.sortedHidableObjects[this.activeLayoutName],u=[];if(d)for(const O of d)O.object.userData?.layerVisible!==!1&&(u.push({object:O.object,visible:O.object.visible}),O.object.visible=!0);const{clientWidth:f,clientHeight:m}=this.viewerContainer,b=Math.min(n.capabilities.maxTextureSize||4096,8192),y=Math.min(4,b/Math.max(f,m));y>l&&n.setPixelRatio(y),this.cameraManager.update(0),this.dispatchEvent(le.BeforeRender),n.render(this.scene,this.camera),this.dispatchEvent(le.AfterRender);const C=n.domElement,w=this.overlayRender.getCanvas(),x=document.createElement("canvas");x.width=C.width,x.height=C.height;const E=x.getContext("2d");if(E.drawImage(C,0,0),w&&w.width>0&&w.height>0&&E.drawImage(w,0,0,x.width,x.height),i){const O=new p.Color(1973806);this.scene.background instanceof p.Color?O.copy(this.scene.background):n.getClearColor(O),O.convertLinearToSRGB(),this.invertForPrint(x,Math.max(1,Math.round(y/2)),{r:O.r*255,g:O.g*255,b:O.b*255})}let M=x.toDataURL("image/png");if(h&&this.camera.type==="OrthographicCamera"){const O=this.cropCanvasToBox(x,h);O&&(M=O)}this._printCaptureMode=!1;for(const{object:O,visible:S}of u)O.visible=S;return n.setPixelRatio(l),s.zoomTo(o),s.setLookAt(r.x,r.y,r.z,a.x,a.y,a.z),this.cameraManager.update(0),this.enableRender(),M}invertForPrint(e,i,s){const n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const r=e.width,a=e.height,o=n.getImageData(0,0,r,a),l=o.data,h=r*a,d=45,u=.72,f=new Float32Array(h);for(let S=0,v=0;S<h;S++,v+=4){const T=l[v],_=l[v+1],A=l[v+2],I=T-s.r,B=_-s.g,k=A-s.b;if(Math.sqrt(I*I+B*B+k*k)<d){l[v]=255,l[v+1]=255,l[v+2]=255,f[S]=255;continue}const L=T/255,F=_/255,ie=A/255,se=Math.max(L,F,ie),Fe=Math.min(L,F,ie),ht=(se+Fe)/2,Me=se-Fe,Vi=Me===0?0:Me/(1-Math.abs(2*ht-1));let et=0;Me!==0&&(se===L?et=(F-ie)/Me%6:se===F?et=(ie-L)/Me+2:et=(L-F)/Me+4,et/=6,et<0&&(et+=1));const Tn=Math.min(.55,(1-ht)*u),ke=(1-Math.abs(2*Tn-1))*Vi,At=ke*(1-Math.abs(et*6%2-1)),ji=Tn-ke/2;let Gt=0,qt=0,Wt=0;const Yt=Math.floor(et*6)%6;Yt===0?(Gt=ke,qt=At):Yt===1?(Gt=At,qt=ke):Yt===2?(qt=ke,Wt=At):Yt===3?(qt=At,Wt=ke):Yt===4?(Gt=At,Wt=ke):(Gt=ke,Wt=At),l[v]=(Gt+ji)*255,l[v+1]=(qt+ji)*255,l[v+2]=(Wt+ji)*255,f[S]=.299*l[v]+.587*l[v+1]+.114*l[v+2]}const m=Math.max(1,i),b=new Float32Array(h),y=new Uint8ClampedArray(h),C=new Uint8ClampedArray(h),w=new Uint8ClampedArray(h);for(let S=0;S<a;S++){const v=S*r;for(let T=0;T<r;T++){let _=255,A=v+T;const I=Math.max(0,T-m),B=Math.min(r-1,T+m);for(let k=I;k<=B;k++){const L=f[v+k];L<_&&(_=L,A=v+k)}b[v+T]=_,y[v+T]=l[A*4],C[v+T]=l[A*4+1],w[v+T]=l[A*4+2]}}const x=new Float32Array(h),E=new Uint8ClampedArray(h),M=new Uint8ClampedArray(h),O=new Uint8ClampedArray(h);for(let S=0;S<r;S++)for(let v=0;v<a;v++){let T=255,_=v*r+S;const A=Math.max(0,v-m),I=Math.min(a-1,v+m);for(let k=A;k<=I;k++){const L=b[k*r+S];L<T&&(T=L,_=k*r+S)}const B=v*r+S;x[B]=T,E[B]=y[_],M[B]=C[_],O[B]=w[_]}for(let S=0,v=0;S<h;S++,v+=4)f[S]>250&&x[S]<250&&(l[v]=E[S],l[v+1]=M[S],l[v+2]=O[S]);n.putImageData(o,0,0)}cropCanvasToBox(e,i){const s=this.camera,n=s.zoom||1,r=s.position.x,a=s.position.y,o=r+s.left/n,l=r+s.right/n,h=a+s.bottom/n,d=a+s.top/n,u=l-o,f=d-h;if(u<=0||f<=0)return;const m=v=>(v-o)/u*e.width,b=v=>(d-v)/f*e.height,y=Math.max(u,f)*.01,C=Math.max(0,Math.floor(m(i.min.x-y))),w=Math.min(e.width,Math.ceil(m(i.max.x+y))),x=Math.max(0,Math.floor(b(i.max.y+y))),E=Math.min(e.height,Math.ceil(b(i.min.y-y))),M=w-C,O=E-x;if(M<16||O<16)return;const S=document.createElement("canvas");return S.width=M,S.height=O,S.getContext("2d").drawImage(e,C,x,M,O,0,0,M,O),S.toDataURL("image/png")}printImageInIframe(e){const{dataUrl:i,width:s,height:n,paperSize:r,orientation:a,invertColors:o,fitToPage:l,margins:h,title:d}=e,u={A4:[210,297],A3:[297,420],A2:[420,594],A1:[594,841],A0:[841,1189],Letter:[215.9,279.4]};let[f,m]=u[r]??u.A4;a==="landscape"&&([f,m]=[m,f]);const b=document.createElement("iframe");b.setAttribute("aria-hidden","true");const y=96/25.4;b.style.cssText=`position:fixed;left:-20000px;top:0;border:0;visibility:hidden;width:${Math.ceil(f*y)}px;height:${Math.ceil(m*y)}px;`;const C=v=>v.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),w=l?"max-width:100%;max-height:100%;width:auto;height:auto;":"width:100%;height:auto;",x=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${C(d)}</title><style>@page{size:${r} ${a};margin:${h}mm;}html,body{margin:0;padding:0;background:#fff;}body{display:flex;align-items:center;justify-content:center;width:${f-2*h}mm;height:${m-2*h}mm;overflow:hidden;}img{display:block;${w}}</style></head><body><img src="${i}" alt="${C(d)}"></body></html>`;document.body.appendChild(b);const E=()=>{b.contentWindow?.removeEventListener("afterprint",E),setTimeout(()=>b.remove(),100)},M=b.contentDocument;M.open(),M.write(x),M.close();const O=M.querySelector("img"),S=()=>{const v=b.contentWindow;v.addEventListener("afterprint",E),v.focus(),v.print(),setTimeout(E,6e4)};O.complete?S():(O.onload=S,O.onerror=E)}getLayers(){const e=[];if(this.masterModelId){const i=this.loadedModels.find(n=>this.masterModelId===n.modelId),s=i?.layers;s&&e.push({modelId:this.masterModelId,layers:s})}for(const i of this.loadedModels){const s=i.modelId;if(s===this.masterModelId)continue;const n=i.layers;n&&e.push({modelId:s,layers:n})}return e}setModelVisibility(e,i){const s=this.loadedModels.find(n=>e===n.modelId);if(!s)throw new Error("Failed to find model by modelId '"+e+"'!");s.setVisible(i),this.enableRender()}setLayerVisibility(e,i,s){const n=this.camera;s=s||this.masterModelId;const r=this.loadedModels.find(a=>s===a.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");r.setLayerVisible(e,i,this.enableHideVisuallySmallObjects,n.zoom),this.raycastableObjects=void 0,this.enableRender()}setLayerOpacity(e,i,s){s=s||this.masterModelId;const n=this.loadedModels.find(r=>s===r.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");n.setLayerOpacity(e,i),this.enableRender()}setLayerColor(e,i,s){s=s||this.masterModelId;const n=this.loadedModels.find(r=>s===r.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");this.clearSelection(),n.setLayerColor(e,i),this.enableRender()}resetLayerColor(e,i){i=i||this.masterModelId;const s=this.loadedModels.find(n=>i===n.modelId);if(!s)throw new Error("Failed to find model by modelId '"+i+"'!");this.clearSelection(),s.resetLayerColor(e),this.enableRender()}getVisiblePixelSize(e){const i=p.MathUtils.smoothstep(e,1e4,3e4)*6.5+.5;return P.debug("[Viewer] visiblePixelSize:",i),i}setLayoutHidableObjectArray(e){const i=this.camera;if(!this.enableHideVisuallySmallObjects||!i)return;const s=Date.now(),n=e.name;this.sortedHidableObjects[n]||(this.sortedHidableObjects[n]=[]);const r=this.sortedHidableObjects[n];this.cameraManager.update(0);const a=i.zoom;this.lastCameraZoom=a;let o=1;e.traverse(h=>{if(h.userData.isSnapObject||!J.isLeafObject(h))return;const d=h.geometry;d.boundingBox||d.computeBoundingBox();const u=d.boundingBox.clone();if(!u||!j.isBoxValid(u))return;u.applyMatrix4(h.matrixWorld),u.getSize(Mi);const f=Math.max(Mi.x,Mi.y),m=o/f;m<1/0?r.push({visibleMinZoom:m,object:h}):h instanceof p.Points?r.push({visibleMinZoom:o,object:h}):P.warn("[Viewer] The size of bbox is 0 ! ",h)}),o=this.getVisiblePixelSize(r.length);let l=0;r.forEach(h=>{const d=h.visibleMinZoom*o;h.visibleMinZoom=d,h.object.userData.visibleMinZoom=d,d>a&&(h.object.visible=!1,l++)}),r.sort((h,d)=>h.visibleMinZoom-d.visibleMinZoom),P.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5)return;if(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,this._printCaptureMode){this.lastCameraZoom=s;return}if(!this.sortedHidableObjects[this.activeLayoutName])return;const n=this.sortedHidableObjects[this.activeLayoutName];if(n.length===0)return;const r=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let h=0;for(let d=0;d<n.length;++d)if(n[d].object.userData.layerVisible!==!1){if(n[d].visibleMinZoom<a){l.push(n[d].object);continue}else if(n[d].visibleMinZoom>o)break;n[d].object.visible=r,r&&l.push(n[d].object),h++}this.lastCameraZoom=s,P.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+h+"(out of "+n.length+") objects changed to "+(r?"visible":"hidden"))}updateCameraZoomUniform(e){X.CameraZoomUniform.value=e*this.container.height/50}}class ml{constructor(t){g(this,"viewer");g(this,"fontManager");g(this,"loader");g(this,"loadingManager");g(this,"changes");g(this,"container");g(this,"spinner");g(this,"jobCount");g(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Vr(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Rr(t.containerId);this.loadingProgressBar=new Fr(i);const s={ignorePaperSpace:!0};this.loader=new X(this.loadingManager,s),this.initSpinner()}initSpinner(){const t=document.createElement("div");t.classList.add("x-spinner"),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),this.container.appendChild(t),this.spinner=t,this.setSpinnerVisibility(this.jobCount>0)}async setFont(t){const e=Date.now();!this.fontManager&&(this.fontManager=new xt),await this.fontManager.loadFonts(t),P.info("[DxfCompareHelper] Font file(s) load time in "+(Date.now()-e)/1e3+"s")}async compare(t,e,i,s){const{src:n,modelId:r}=t,{src:a}=e;this.viewer.masterModelId=r||n;const o=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=n+a,h=We.t("ProgressBar.Comparing"),d=B=>{this.loadingProgressBar?.updateProgress(l,h,B),s&&s(new ProgressEvent("CompareProgress",{loaded:B,total:100}))},u=(B,k,L)=>{let F=B.loaded*100/B.total;F=F*(L-k)/100+k,this.loadingProgressBar?.updateProgress(l,h,F),s&&s(new ProgressEvent("CompareProgress",{loaded:F,total:100}))},f=B=>u(B,0,15),m=B=>u(B,15,30),b=B=>u(B,30,60),y=B=>u(B,60,95);j.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),d(0);let C=Date.now();const w=this.loader.parse(n,f),x=this.loader.parse(a,m),[E,M]=await Promise.allSettled([w,x]);if(E.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+n);if(M.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+a);if(P.info("[DxfCompareHelper] loadFiles in "+(Date.now()-C)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const O=E.value,S=M.value;C=Date.now();const v=await new at(O,S,i).compare(b);if(P.info("[DxfCompareHelper] Compared in "+(Date.now()-C)/1e3+"s"),P.debug("[DxfCompareHelper] Compared results:",v),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");j.printMemory("After getting the comparison results"),C=Date.now(),await this.loader.loadEntitiesForCompare(O,S,v,!0,y),j.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=v,P.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-C)/1e3+"s");const T=O,_=S;if(this.decreaseJobCount(),!Object.keys(v).length&&P.info("[DxfCompareHelper] No change found"),T.threejsObject?.children.length===0&&_.threejsObject?.children.length===0){const B="[DxfCompareHelper] Nothing was loaded from "+n+" and "+a;return P.warn(B),Promise.reject(B)}const A=T.threejsObject,I=_.threejsObject;return A.name=n,I.name=a,C=Date.now(),this.viewer.addModel(new Ri({modelId:t.modelId||t.src,dxfData:T})),this.viewer.flyToObject(A),j.printMemory("After adding first loaded Model to scene"),d(95),this.viewer.addModel(new Ri({modelId:e.modelId||e.src,dxfData:_})),j.printMemory("After adding second loaded Model to scene"),P.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-C)/1e3+"s"),P.info("[DxfCompareHelper] The comparison between "+n+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),d(100),this.loadingProgressBar?.delayRemoveProgressItem(l),Promise.resolve()}getChanges(){return this.changes}zoomToChange(t){if(this.changes){const e=this.changes[t];if(!e)return;const i=e.box;i&&this.viewer.zoomToBBox(i.clone().expandByScalar(1.2))}}setSpinnerVisibility(t){this.spinner&&(t?this.spinner.classList.remove("hidden"):this.spinner.classList.add("hidden"))}increaseJobCount(){this.setSpinnerVisibility(++this.jobCount>0)}decreaseJobCount(){this.setSpinnerVisibility(--this.jobCount>0)}}class Bu extends ml{constructor(e,i){super(e);g(this,"viewer2");g(this,"syncCamera");g(this,"markupManager1");g(this,"markupManager2");g(this,"syncCameraControls");this.syncCamera=!1,this.syncCameraControls=(s,n,r)=>{const a=new p.Vector3,o=new p.Vector3,l=new p.Vector3;s.getPosition(o),s.getTarget(l),s.getFocalOffset(a),n.setLookAt(o.x,o.y,o.z,l.x,l.y,l.z),n.zoomTo(r),n.dispatchEvent({type:"control"})},this.viewer2=new Vr(i),this.initSyncCameraEvent()}initSyncCameraEvent(){const e=this.viewer.getCameraManager().cameraControls,i=this.viewer2.getCameraManager().cameraControls;let s=!1;e.addEventListener("control",()=>{s=!1}),e.addEventListener("update",()=>{!this.syncCamera||s||this.syncCameraControls(e,i,this.viewer.camera.zoom)}),i.addEventListener("control",()=>{s=!0}),i.addEventListener("update",()=>{!this.syncCamera||!s||this.syncCameraControls(i,e,this.viewer2.camera.zoom)})}enableSyncCamera(e){if(this.syncCamera=e,e){const i=this.viewer.getCameraManager().cameraControls,s=this.viewer2.getCameraManager().cameraControls;this.syncCameraControls(i,s,this.viewer.camera.zoom)}}async compare(e,i,s,n){const{src:r,modelId:a}=e,{src:o,modelId:l}=i;this.viewer.masterModelId=a||r,this.viewer2.masterModelId=l||o;const h=Date.now();if(this.increaseJobCount(),!this.fontManager)return Promise.reject("[DxfCompareHelper] Should set font first!");this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const d=r+o,u=We.t("ProgressBar.Comparing"),f=L=>{this.loadingProgressBar?.updateProgress(d,u,L),n&&n(new ProgressEvent("CompareProgress",{loaded:L,total:100}))},m=(L,F,ie)=>{let se=L.loaded*100/L.total;se=se*(ie-F)/100+F,this.loadingProgressBar?.updateProgress(d,u,se),n&&n(new ProgressEvent("CompareProgress",{loaded:se,total:100}))},b=L=>m(L,0,15),y=L=>m(L,15,30),C=L=>m(L,30,60),w=L=>m(L,60,95);j.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(d),f(0);let x=Date.now();const E=this.loader.parse(r,b),M=this.loader.parse(o,y),[O,S]=await Promise.allSettled([E,M]);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(S.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+o);if(P.info("[DxfCompareHelper] loadFiles in "+(Date.now()-x)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const v=O.value,T=S.value;x=Date.now();const _=await new at(v,T,s).compare(C);if(P.info("[DxfCompareHelper] Compared in "+(Date.now()-x)/1e3+"s"),P.debug("Compared results:",_),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");j.printMemory("After getting the comparison results"),x=Date.now(),await this.loader.loadEntitiesForCompare(v,T,_,!1,w),j.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=_,P.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-x)/1e3+"s");const A=v,I=T;if(this.decreaseJobCount(),!Object.keys(_).length&&P.info("[DxfCompareHelper] No change found"),A.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const L="[DxfCompareHelper] Nothing was loaded from "+r+" and "+o;return P.warn(L),Promise.reject(L)}const B=A.threejsObject,k=I.threejsObject;return B.name=r,k.name=o,x=Date.now(),this.viewer.addModel(new Ri({modelId:e.modelId||e.src,dxfData:A})),j.printMemory("After adding first loaded Model to scene"),f(95),this.viewer2.addModel(new Ri({modelId:i.modelId||i.src,dxfData:I})),j.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),P.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-x)/1e3+"s"),P.info("[DxfCompareHelper] The comparison between "+r+"' and '"+o+"' is completed in "+(Date.now()-h)/1e3+"s !"),f(100),this.loadingProgressBar?.delayRemoveProgressItem(d),Promise.resolve()}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new vr(this.viewer)),this.markupManager2??(this.markupManager2=new vr(this.viewer2)),requestAnimationFrame(()=>{this.markupManager1?.drawCompareDrawable(this.changes),this.markupManager2?.drawCompareDrawable(this.changes),this.viewer.enableRender(),this.viewer2.enableRender()}))}zoomToChange(e){if(this.changes){const i=this.changes[e];if(!i)return;const s=i.box;s&&(this.viewer.zoomToBBox(s.clone().expandByScalar(1.2)),this.viewer2.zoomToBBox(s.clone().expandByScalar(1.2)))}}}class Pi{constructor(t,e){g(this,"current");g(this,"next");g(this,"inNormal");g(this,"outNormal");this.current=t,this.next=e,this.inNormal=this.inwardsNormal(),this.outNormal=this.outwardsNormal()}outwardsNormal(){const t=this.inwardsNormal();return[-t[0],-t[1]]}inwardsNormal(){const t=this.next[0]-this.current[0],e=this.next[1]-this.current[1],i=Math.sqrt(t*t+e*e);if(i===0)throw new Error("Vertices overlap");return[-e/i,t/i]}offset(t,e){return Pi.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return Pi.offsetEdge(this.next,this.current,t,e)}inverse(){return new Pi(this.next,this.current)}static offsetEdge(t,e,i,s){return new Pi([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const ss=Array.isArray,po=(c,t)=>c[0]===t[0]&&c[1]===t[1],rr=c=>Array.isArray(c)&&c.length,gl=(c,t=0,e=!1)=>{let i,s;if(rr(c)&&typeof c[0][0]=="number"){let n=0;const r=c;for(i=0,s=r.length;i<s;i++){const a=r[i],o=r[(i+1)%s];n+=a[0]*o[1],n-=o[0]*a[1]}(!e&&n>0||e&&n<0)&&r.reverse()}else for(i=0,s=c.length;i<s;i++)gl(c[i],t+1,i>0);if(t===0&&rr(c)&&rr(c[0])&&typeof c[0][0][0]=="number"){const n=c[0].slice(0,1)[0];c[0].pop(),c[0].push([n[0],n[1]])}return c};class ku{constructor(t,e=5){g(this,"vertices");g(this,"edges");g(this,"arcSegments");g(this,"distance");if(this.distance=0,this.arcSegments=e,!ss(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],ss(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=gl(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(ss(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,po(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new Pi(t[i],t[(i+1)%s]));else for(t=t,e=e,i=0,s=t.length;i<s;i++)e.push([]),this.processContour(t[i],e[e.length-1])}setArcSegments(t){return this.arcSegments=t,this}createArc(t,e,i,s,n,r,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),h=Math.atan2(n[1]-e[1],n[0]-e[0]);r%2===0&&(r-=1),l<0&&(l+=o),h<0&&(h+=o);let d=l>h?l-h:l+o-h;const u=(a?-d:o-d)/r;t.push(s);for(let f=1;f<r;++f)d=l+u*f,t.push([e[0]+Math.cos(d)*i,e[1]+Math.sin(d)*i]);return t.push(n),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return po(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const n=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],r=[];for(let a=0,o=2;a<o;a++){const l=n[a],h=n[(a+o-1)%o];this.createArc(r,a===0?t:e,s,h.next,l.current,this.arcSegments,!0)}return r}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Ui.union(this.vertices,e),e}padding(t){if(this.setDistance(t),this.distance===0)return this.vertices;if(this.vertices.length===2&&typeof this.vertices[0]=="number")return this.vertices;const e=this.offsetLines(this.distance);return Ui.difference(this.vertices,e)}offsetLine(t){return t===0?this.vertices:this.offsetLines(t)}offsetLines(t){if(t<0)throw new Error("Cannot apply negative margin to the line");this.setDistance(t);let e=[];if(ss(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,n=this.edges.length;s<n;s++){const r=this.offsetContour(this.vertices[s],this.edges[s]);r.length>0&&i.push(r)}i.length>0&&(e=i.length===1?i[0]:Ui.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,n=0;if(ss(t[0])&&typeof t[0][0]=="number"){for(s=0,n=t.length-1;s<n;s++){const r=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[r];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Ui.union(i[0],i.slice(1)))}else{const r=[];for(s=0,n=e.length;s<n;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&r.push(a)}r.length>0&&(i=r.length===1?r[0]:Ui.union(r[0],...r.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,n=this.distance;let r=0;e%2===0&&e++;for(let a=0;a<e;a++)r+=2*Math.PI/e,i.push([s[0]+n*Math.cos(r),s[1]+n*Math.sin(r)]);return[[this.ensureLastPoint(i)]]}}class yl{constructor(t){g(this,"viewer");g(this,"composerEnabled");g(this,"composer");g(this,"renderPass");g(this,"effectFxaaPass");g(this,"saoPass");g(this,"ssaoPass");g(this,"outlinePass");g(this,"ssaaRenderPass");g(this,"bloomPass");g(this,"unrealBloomPass");g(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new ec.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(le.AfterRender,()=>this.render())}get enabled(){return this.composerEnabled}set enabled(t){this.composerEnabled=t}get renderPassEnabled(){return!!this.renderPass?.enabled}set renderPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.renderPass){const r=new tc.RenderPass(e,i);r.setSize(s,n),this.composer.addPass(r),this.renderPass=r}this.renderPass&&(this.renderPass.enabled=t),this.viewer.enableRender()}}get fxaaPassEnabled(){return!!this.effectFxaaPass?.enabled}set fxaaPassEnabled(t){if(!this.composer)return;const{width:e,height:i}=this.viewer.container;if(t&&!this.effectFxaaPass){const s=new ic.ShaderPass(cc.FXAAShader);s.uniforms.resolution.value.set(1/e,1/i),s.renderToScreen=!0,s.setSize(e,i),this.composer.addPass(s),this.effectFxaaPass=s}this.effectFxaaPass&&(this.effectFxaaPass.enabled=t),this.viewer.enableRender()}get saoPassEnabled(){return!!this.saoPass?.enabled}set saoPassEnabled(t){const{width:e,height:i}=this.viewer.container,s=this.viewer.scene,n=this.viewer.camera;if(this.composer){if(t&&!this.saoPass){const r=new sc.SAOPass(s,n,new p.Vector2(1/e,1/i));r.setSize(e,i),r.params.output=0,r.params.saoBias=.5,r.params.saoIntensity=3e-4,r.params.saoScale=8,r.params.saoKernelRadius=40,r.params.saoMinResolution=0,this.composer.addPass(r),this.saoPass=r}this.saoPass&&(this.saoPass.enabled=t),this.viewer.enableRender()}}get ssaoPassEnabled(){return!!this.ssaoPass?.enabled}set ssaoPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.ssaoPass){const r=new nc.SSAOPass(e,i,s,n);r.kernelRadius=16,r.minDistance=1e-4,r.maxDistance=.3,this.composer.addPass(r),this.ssaoPass=r}this.ssaoPass&&(this.ssaoPass.enabled=t),this.viewer.enableRender()}}get outlinePassEnabled(){return!!this.outlinePass?.enabled}set outlinePassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera,{width:s,height:n}=this.viewer.container;if(this.composer){if(t&&!this.outlinePass){const r=new rc.OutlinePass(new p.Vector2(s,n),e,i);r.edgeStrength=3,r.edgeGlow=0,r.edgeThickness=2,r.pulsePeriod=0,r.visibleEdgeColor.set(16711680),r.hiddenEdgeColor.set(16752768),this.composer.addPass(r),this.outlinePass=r}this.outlinePass&&(this.outlinePass.enabled=t),this.viewer.enableRender()}}get ssaaPassEnabled(){return!!this.ssaaRenderPass?.enabled}set ssaaPassEnabled(t){const e=this.viewer.scene,i=this.viewer.camera;if(this.composer){if(t&&!this.ssaaRenderPass){const s=new ac.SSAARenderPass(e,i,16777215,0);this.composer.addPass(s),this.ssaaRenderPass=s,this.ssaaRenderPass=s}this.ssaaRenderPass&&(this.ssaaRenderPass.enabled=t),this.viewer.enableRender()}}get bloomPassEnabled(){return!!this.bloomPass?.enabled}set bloomPassEnabled(t){if(this.composer){if(t&&!this.bloomPass){const e=new oc.BloomPass(1,25,4);e.renderToScreen=!0,this.composer.addPass(e),this.bloomPass=e}this.bloomPass&&(this.bloomPass.enabled=t),this.viewer.enableRender()}}get unrealBloomPassEnabled(){return!!this.unrealBloomPass?.enabled}set unrealBloomPassEnabled(t){const{width:e,height:i}=this.viewer.container;if(this.composer){if(t&&!this.unrealBloomPass){const s=new lc.UnrealBloomPass(new p.Vector2(e,i),1,0,0);s.threshold=0,s.strength=.5,s.radius=0,this.composer.addPass(s),this.unrealBloomPass=s}this.unrealBloomPass&&(this.unrealBloomPass.enabled=t),this.viewer.enableRender()}}setOutlinePassSelectObjects(t){this.outlinePass&&(this.outlinePass.selectedObjects=t)}enableModelEdges(t){const e=this.viewer.loadedModels;for(let i=0;i<e.length;++i){const s=e[i];if(s instanceof kr)if(t&&!s.edges){const n=s.getModelObject();n&&(P.debug("[Viewer] Generating outlines for model '"+n.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(n=>n.visible=t);else s instanceof Lr&&P.warn("[BimTiles] enableModelEdges() is not implemented for bimtiles yet.")}this.viewer.enableRender()}showVertexNormals(t,e=.1){t?(!this.vertexNormalsHelpers&&(this.vertexNormalsHelpers=new p.Group),this.viewer.scene.traverseVisible(i=>{const s=["SKYBOX","GROUND_GRID","GROUND_GRASS","BIM_VIEWER_BOX_HELPER"];if(i instanceof p.Mesh&&!s.includes(i.name)){if(!i.geometry.attributes.normal)return;const r=new hc.VertexNormalsHelper(i,e,16711680);this.vertexNormalsHelpers?.add(r)}}),this.viewer.scene.add(this.vertexNormalsHelpers)):this.vertexNormalsHelpers&&(this.viewer.scene.remove(this.vertexNormalsHelpers),this.vertexNormalsHelpers=void 0)}render(){!this.composer||!this.enabled||this.composer.render()}destroy(){this.renderPass&&(this.composer?.removePass(this.renderPass),this.renderPass.dispose(),this.renderPass=void 0),this.effectFxaaPass&&(this.composer?.removePass(this.effectFxaaPass),this.effectFxaaPass.dispose(),this.effectFxaaPass=void 0),this.saoPass&&(this.composer?.removePass(this.saoPass),this.saoPass.dispose(),this.saoPass=void 0),this.ssaoPass&&(this.composer?.removePass(this.ssaoPass),this.ssaoPass.dispose(),this.ssaoPass=void 0),this.outlinePass&&(this.composer?.removePass(this.outlinePass),this.outlinePass.dispose(),this.outlinePass=void 0),this.ssaaRenderPass&&(this.composer?.removePass(this.ssaaRenderPass),this.ssaaRenderPass.dispose(),this.ssaaRenderPass=void 0),this.bloomPass&&(this.composer?.removePass(this.bloomPass),this.bloomPass.dispose(),this.bloomPass=void 0),this.unrealBloomPass&&(this.composer?.removePass(this.unrealBloomPass),this.unrealBloomPass.dispose(),this.unrealBloomPass=void 0),this.composer&&(this.composer?.dispose(),this.composer=void 0)}}class Du extends Mn{constructor(e,i){super(e);g(this,"name");g(this,"loadedModels");g(this,"distanceCullingFactor");g(this,"selectedObject");g(this,"effect");if(this.name=$e.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new yl(this),this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new p.Vector3(100,50,100),n=new p.Vector3(0,0,0),r={eye:s,look:n};this.cameraManager.flyToViewpoint(r)}this.cameraManager.setProjection(bt.Perspective),this.cameraManager.setNavigationMode(ot.Orbit),this.setupDefaultEvents(),this.setDefaultBackground()}setupDefaultEvents(){let e=!1,i,s=0,n=0,r=0;const a=300,o=u=>n===-1||r===-1?!1:Math.abs(u.x-n)<5&&Math.abs(u.y-r)<5,l=u=>{const f=u.timestamp-s;return!!(u.button===Je.Left&&f<a&&o(u))};let h,d=!1;this.inputManager.addEventListener("pointerdown",u=>{e=!1,i=u.button;const f=new p.Vector2(u.x,u.y);h=this.pickObject(f),d=h?.object===this.selectedObject,u.button===Je.Left&&this.handleAnchorPoint(h)}),this.inputManager.addEventListener("pointermove",u=>{i!==void 0&&(e=!o(u),i===Je.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0))}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===Je.Left?l(u)?(h?.object?this.flyToObject(h.object):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.selectedObject instanceof Ht?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h?.object&&!d&&this.handleClickObject(h.object)):(u.button,Je.Right)})}setDefaultBackground(){this.sceneManager.renderer.setClearColor(11119017,1),this.sceneManager.setBackground(null),this.sceneManager.setEnvironmentFromData()}handleAnchorPoint(e){const i=new p.Vector3;this.selectedObject?new p.Box3().setFromObject(this.selectedObject).getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=r=>!r.userData.modelId&&r.parent?i(r.parent):r.userData.modelId,s=i(e);this.loadedModels.find(r=>r.modelId===s)?.highlightObject(e),this.selectedObject=e,this.enableRender()}is3d(){return!0}async loadLocalModel(e,i,s,n){return this.loadModelInternal(i,n,!0,e,s)}async loadModel(e,i){return this.loadModelInternal(e,i)}async loadModelInternal(e,i,s,n,r){this.spinner.increaseJobCount();const a=e.modelId||e.src,o=We.t("ProgressBar.Loading"),l=x=>{this.progressBar?.updateProgress(a,o,x),i?.(new ProgressEvent("LoadProgress",{loaded:x,total:100}))};let h=!1;const d=(x,E,M)=>{let O=x.loaded*100/x.total;O=O*(M-E)/100+E,O>M&&(h||(P.warn("[Progress] Invalid ProgressEvent:",x),h=!0),O=M),this.progressBar?.updateProgress(a,o,O),i?.(new ProgressEvent("LoadProgress",{loaded:O,total:100}))},u=x=>d(x,0,50);this.progressBar?.addProgressItem(a),l(0);let f;if(s?(this.loaderHelper.setLoadManager(r),f=await this.loaderHelper.loadLocalModel(n,e.src,i)):f=await this.loaderHelper.loadModel(e.src,e.fileFormat,u),e.matrix&&e.matrix.length===16){const x=new p.Matrix4;x.elements=e.matrix,f.applyMatrix4(x)}const m=this.getUniqueModelId(e.modelId||e.src),b=new kr({modelId:m,object:f});this.addModel(b),l(90);const y=b.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const w=new p.Vector3;y.getCenter(w),this.cameraManager.setOrbitPoint(w),this.spinner.decreaseJobCount(),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(le.ModelLoad)}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(n=>n.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function mo(c){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),c)}function go(c){return Object.assign(Object.assign({},{elementCount:0,batchElementCount:0,instanceElementCount:0,batchCount:0,instanceCount:0,tileCount:0,userDataCount:0,materialCount:0,meshVertexCount:0,meshFaceCount:0,textureCount:0,texturePixels:0}),c)}function Lu(c){const t={transform:new p.Matrix4,boundingVolume:new p.Box3};return Object.assign(Object.assign({},t),c)}class Ru{constructor(t){g(this,"url");g(this,"metadata");g(this,"statistics");g(this,"view");this.url=t,this.metadata=mo(),this.statistics=go(),this.view=Lu()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(P.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=mo(t.metadata),this.statistics=go(t.statistics),t.view.transform&&t.view.transform.length===16&&this.view.transform.fromArray(t.view.transform),t.view.boundingVolume&&t.view.boundingVolume.length===6&&this.view.boundingVolume.setFromArray(t.view.boundingVolume),Promise.resolve(!0)))}getMetadata(){return this.metadata}getStatistics(){return this.statistics}getView(){return this.view}}let Fu=0;class zu extends Mn{constructor(e,i){super(e);g(this,"name");g(this,"pickUsageScene");g(this,"effect");g(this,"loadedModels");g(this,"selectedObject");g(this,"enableHoverEffect");if(this.name=$e.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new yl(this),this.pickUsageScene=new p.Scene,this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new p.Vector3(100,50,100),n=new p.Vector3(0,0,0),r={eye:s,look:n};this.cameraManager.flyToViewpoint(r)}this.cameraManager.setProjection(bt.Perspective),this.cameraManager.setNavigationMode(ot.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(le.BeforeRender,()=>{this.update3dTiles()})}setupDefaultEvents(){let e=!1,i,s=0,n=0,r=0;const a=300,o=u=>n===-1||r===-1?!1:Math.abs(u.x-n)<5&&Math.abs(u.y-r)<5,l=u=>{const f=u.timestamp-s;return!!(u.button===Je.Left&&f<a&&o(u))};let h,d=!1;this.inputManager.addEventListener("pointerdown",u=>{e=!1,i=u.button,this.renderImmediately();const f=new p.Vector2(u.x,u.y);if(h=this.pickManager.pick(f,this.pickUsageScene),d=!!this.selectedObject&&h?.tilesetId===this.selectedObject?.tilesetId&&h?.userId===this.selectedObject?.userId,u.button===Je.Left){let m=this.pickUsageScene;if(h){const y=this.loadedModels.find(C=>C.modelId===""+h?.tilesetId);if(y){const C=y.getObjectByUserId(h.userId);C&&(m=C)}}const b=this.pickManager.pickObject(f,[m]);this.handleAnchorPoint(b)}}),this.inputManager.addEventListener("pointermove",u=>{if(i!==void 0)e=!o(u),i===Je.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0);else if(this.enableHoverEffect){const f=new p.Vector2(u.x,u.y),m=this.pickManager.pick(f,this.pickUsageScene),b=this.getHoveredObject();m?(!b||b.tilesetId!==m.tilesetId||b.userId!==m.userId)&&this.setObjectHoveredByUserId(m.tilesetId,m.userId,!0):b&&this.clearHovered()}this.handleMouseMove(u)}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===Je.Left?l(u)?(h?this.flyToUserId(h.tilesetId,h.userId):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h&&!d&&this.handleClickObject(h)):(u.button,Je.Right)})}setDefaultBackground(){this.sceneManager.setBackground(new p.Color(11119017)),this.sceneManager.setEnvironmentFromData()}renderImmediately(){const{renderer:e,scene:i,camera:s}=this;!e||!i||!s||e.render(i,s)}handleAnchorPoint(e){const i=new p.Vector3;this.selectedObject?this.getBoxByUserId(this.selectedObject.tilesetId,this.selectedObject.userId)?.getCenter(i):e&&e.point?i.copy(e.point):this.getBBox().getCenter(i),this.cameraManager.setOrbitPoint(i),this.cameraManager.update(0)}handleClickObject(e){if(!this.enableSelection)return;const i=this.loadedModels.find(s=>s.modelId===""+e.tilesetId);i&&(i?.setObjectHighlightedByUserIds([e.userId],!0),this.selectedObject=e),this.enableRender()}is3d(){return!0}setModelOpacity(e,i){this.loadedModels.find(n=>n.modelId===e)?.setOpacity(i),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}enableModelOutline(e,i){P.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){P.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(n=>n.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new Ru(e.src);if(!await s.parse())return Promise.reject();let r=e.src.replace(/\/[^\\/]*\/?$/,"/");r=new URL(r,window.location.href).toString(),this.spinner.increaseJobCount();const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Lr({modelId:""+Fu++,bbox:a},r,s),l=o.getTilesRenderer(),h=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=d=>{d.traverse(u=>{u.matrixAutoUpdate&&(u.matrixAutoUpdate=ct,u.updateMatrix()),u.isMesh&&(u.castShadow=!0,u.receiveShadow=!0),u.geometry&&u.layers.enableAll()}),this.enableRender(),setTimeout(()=>this.spinner.decreaseJobCount(),100)},l.setCamera(this.camera),l.setResolutionFromRenderer(this.camera,this.renderer),l.update(),h){h.applyMatrix4(s.getView().transform),o.pickUsageGroup.applyMatrix4(s.getView().transform),this.pickUsageScene.add(o.pickUsageGroup),this.addModel(o),this.cameraManager.adjustCameraByBBox(a);const d=new p.Vector3;return a.getCenter(d),this.cameraManager.setOrbitPoint(d),this.loadedModels.length===1&&this.goToHomeView(),this.spinner.decreaseJobCount(),this.dispatchEvent(le.ModelLoad),Promise.resolve()}return this.spinner.decreaseJobCount(),Promise.reject()}setObjectHighlightedByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectHighlightedByUserIds(i,s),this.enableRender()}setObjectOpacityByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectOpacityByUserIds(i,s),this.enableRender()}setOtherObjectOpacityByUserIds(e,i,s){this.loadedModels.forEach(a=>{a.setOpacity(s)});const n=""+e;this.loadedModels.find(a=>a.modelId===n)?.clearObjectOpacityByUserIds(i),this.enableRender()}setObjectVisibleByUserIds(e,i,s){this.loadedModels.find(r=>r.modelId===""+e)?.setObjectVisibleByUserIds(i,s),this.enableRender()}setOtherObjectVisibleByUserIds(e,i,s){this.loadedModels.forEach(r=>{r.setVisible(s)}),this.loadedModels.find(r=>r.modelId===""+e)?.setObjectVisibleByUserIds(i,!s),this.enableRender()}setObjectHoveredByUserId(e,i,s){if(!this.enableHoverEffect)return;this.clearHovered(),this.loadedModels.find(r=>r.modelId===""+e)?.setObjectHoveredByUserId(i,s),this.enableRender()}getHoveredObject(){for(const e of this.loadedModels){const i=e.getHoveredObject();if(i)return i}}clearHovered(){this.loadedModels.forEach(e=>e.clearHovered()),this.enableRender()}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(!i),this.sceneManager.setClipPlanes(e)}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}pickObjects(e,i){const s=this.pickManager.pick(e,this.pickUsageScene);let n=this.pickUsageScene;if(s){const a=this.loadedModels.find(o=>o.modelId===""+s?.tilesetId);if(a){const o=a.getObjectByUserId(s.userId);o&&(n=o)}}let r=this.pickManager.pickObjects(e,[n],i);return r&&this.renderer.clippingPlanes.length>0&&(r=r.filter(a=>this.renderer.clippingPlanes.every(function(o){return o.distanceToPoint(a.point)>0}))),r}getErrorTarget(){return this.loadedModels.length>0?this.loadedModels[0].getTilesRenderer().errorTarget:8}setErrorTarget(e){this.loadedModels.forEach(i=>{i.getTilesRenderer().errorTarget=e})}}class Vu extends Nt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();g(this,"id");g(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}$.install({THREE:p});class ju extends ${constructor(e,i){super(e,i);g(this,"minZoom");g(this,"draggingSmoothTime");g(this,"dollySpeedBackup");g(this,"azimuthRotateSpeedBackup");g(this,"polarRotateSpeedBackup");g(this,"truckSpeedBackup");g(this,"onKeyDown");g(this,"onKeyUp");g(this,"keyTruckSpeed");g(this,"keys");this.minZoom=0,this.draggingSmoothTime=0,this.keyTruckSpeed=7,this.keys={left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",bottom:"ArrowDown"},this.onKeyDown=s=>{if(this.enabled){switch(s.code){case this.keys.up:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,1),this._isUserControllingRotate=!0):(this._truckInternal(0,this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.bottom:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(0,-1),this._isUserControllingRotate=!0):(this._truckInternal(0,-this.keyTruckSpeed,!1),this._isUserControllingTruck=!0);break;case this.keys.left:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(1,0),this._isUserControllingRotate=!0):(this._truckInternal(this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break;case this.keys.right:s.ctrlKey||s.metaKey||s.shiftKey?(this._rotateInternal(-1,0),this._isUserControllingRotate=!0):(this._truckInternal(-this.keyTruckSpeed,0,!1),this._isUserControllingTruck=!0);break}this.dispatchEvent({type:"control"})}},this.onKeyUp=s=>{this.dispatchEvent({type:"controlend"})},this._getClientRect(this._elementRect),this.dollySpeedBackup=this.dollySpeed,this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.truckSpeedBackup=this.truckSpeed}get enableZoom(){return!!this.dollySpeed}set enableZoom(e){e?this.dollySpeed=this.dollySpeedBackup:(this.dollySpeedBackup=this.dollySpeed,this.dollySpeed=0)}get enableRotate(){return!!this.azimuthRotateSpeed||!!this.polarRotateSpeed}set enableRotate(e){e?(this.azimuthRotateSpeed=this.azimuthRotateSpeedBackup,this.polarRotateSpeed=this.polarRotateSpeedBackup):(this.azimuthRotateSpeedBackup=this.azimuthRotateSpeed,this.polarRotateSpeedBackup=this.polarRotateSpeed,this.azimuthRotateSpeed=0,this.polarRotateSpeed=0)}get enableTruck(){return!!this.truckSpeed}set enableTruck(e){e?this.truckSpeed=this.truckSpeedBackup:(this.truckSpeedBackup=this.truckSpeed,this.truckSpeed=0)}listenToKeyEvents(){this._domElement?.addEventListener("keydown",this.onKeyDown),this._domElement?.addEventListener("keyup",this.onKeyUp)}stopListenToKeyEvents(){this._domElement?.removeEventListener("keydown",this.onKeyDown),this._domElement?.removeEventListener("keyup",this.onKeyUp)}dispose(){super.dispose(),this.stopListenToKeyEvents()}}var xl=(c=>(c[c.Browser=0]="Browser",c[c.Browserless=1]="Browserless",c[c.Headless=2]="Headless",c))(xl||{});class Uu{constructor(t,e,i){g(this,"containerOrCanvas");g(this,"glContext");g(this,"camera");g(this,"scene");g(this,"renderer");g(this,"renderTarget");g(this,"controls");g(this,"selectedObject");g(this,"loadedModels");g(this,"pmremGenerator");g(this,"clock");g(this,"viewerMode");g(this,"raycaster");g(this,"savedMaterialsForOpacity");g(this,"jobCount");g(this,"bbox");g(this,"outlineMaterial");g(this,"outlineRoot");g(this,"transparentObjectIds");g(this,"requestAnimationFrameHandle");g(this,"applyOptionsAndAddToScene");g(this,"getMeshes");if(this.scene=this.initScene(),this.selectedObject=void 0,this.loadedModels=[],this.clock=new p.Clock,this.viewerMode=0,this.raycaster=new p.Raycaster,this.savedMaterialsForOpacity=[],this.jobCount=0,this.bbox=new p.Box3,this.outlineMaterial=new p.LineBasicMaterial({color:1118481}),this.outlineRoot=new p.Group,this.transparentObjectIds=[],this.applyOptionsAndAddToScene=async(s,n,r,a)=>{if(P.info("[Viewer] '"+s+"' is loaded, adding to scene..."),r.matrix&&r.matrix.length===16){const u=new p.Matrix4;u.elements=r.matrix,n.applyMatrix4(u)}n.traverse(u=>{u.geometry&&u.layers.enableAll(),u instanceof p.Light&&(u.visible=!1)});let o;r.edges&&(o=await J.createOutlines(n,void 0,a));let l=r.modelId||r.src;const h=u=>!!this.loadedModels.find(f=>f.modelId===u);if(h(l)){let u=1;for(;h(l+"_"+u);)u++;l=l+"_"+u,P.warn("[Viewer] Model '"+l+"' is loaded more than once!")}const d={modelId:l,object:n,edges:o};this.addModel(d)},this.getMeshes=s=>{const n=[];return s instanceof p.Mesh?n.push(s):s.traverseVisible(r=>{r instanceof p.Mesh&&n.push(r)}),n},this.containerOrCanvas=t,e&&(this.viewerMode=e),this.glContext=i,this.viewerMode===1&&!(!(t instanceof HTMLDivElement)&&i))throw new Error("[Viewer] Parameters don't match Browserless viewerMode !");this.increaseJobCount(),this.init(),this.decreaseJobCount(),P.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new p.Scene;return t.background=new p.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});let i;try{i=new p.WebGLRenderer(t)}catch(s){if(e||!t.antialias)throw s;i=new p.WebGLRenderer({canvas:this.containerOrCanvas}),P.warn("WebGL context created with fallback settings (antialias disabled).")}if(e){const s=this.containerOrCanvas.width,n=this.containerOrCanvas.height;P.info("[Viewer] Render target size: "+s+" x "+n),this.renderTarget=new p.WebGLRenderTarget(s,n,{minFilter:p.LinearFilter,magFilter:p.NearestFilter,format:p.RGBAFormat,type:p.UnsignedByteType}),i.setRenderTarget(this.renderTarget)}else{const s=this.containerOrCanvas.clientWidth,n=this.containerOrCanvas.clientHeight;this.containerOrCanvas.append(i.domElement),i.setPixelRatio(window.devicePixelRatio),i.setSize(s,n)}i.outputColorSpace=p.SRGBColorSpace,i.toneMappingExposure=1,i.setClearColor(11119017,1),i.shadowMap.enabled=!0,i.shadowMap.type=p.PCFSoftShadowMap,this.renderer=i,e||(this.pmremGenerator=new p.PMREMGenerator(i),this.pmremGenerator.compileEquirectangularShader(),this.setEnvironmentFromDataArray())}initCamera(){if(!this.scene)return;const t=this.containerOrCanvas.clientWidth||this.containerOrCanvas.width||0,e=this.containerOrCanvas.clientHeight||this.containerOrCanvas.height||0;let i=1;t&&e&&(i=t/e),this.camera=new p.PerspectiveCamera(68,i,.05,1e4),this.camera.position.set(10,10,10),this.camera.lookAt(0,0,0),this.scene.add(this.camera)}initControls(){if(!this.renderer)return;const t=this.camera;if(!t)return;const e=new ju(t,this.renderer.domElement);e.smoothTime=.05,e.enabled=!0,e.keyTruckSpeed=10,e.keys={left:"KeyD",up:"KeyE",right:"KeyA",bottom:"KeyQ"},e.update(0),this.controls=e,e.addEventListener("update",()=>{!this.isBrowserMode()&&this.renderer&&this.renderer.render(this.scene,t)})}initLights(){if(!this.scene)return;const t=16777215,e=.3,i=new p.DirectionalLight(t,e);i.position.set(-2,2,4);const s=new p.AmbientLight(3158064),n=new p.HemisphereLight(t,14540253,3);n.position.set(0,300,0),this.scene.add(i),this.scene.add(s),this.scene.add(n)}initPointerEvents(){if(!this.renderer||!this.camera||!this.controls)return;let t=!1,e=!1,i=-1,s=-1;this.renderer.domElement.addEventListener("pointerdown",n=>{i=n.x,s=n.y,t=!1}),this.renderer.domElement.addEventListener("pointermove",n=>{i>=0&&s>=0&&(Math.abs(n.x-i)>5||Math.abs(n.y-s)>5)&&(t=!0)}),this.renderer.domElement.addEventListener("pointerup",()=>{e&&setTimeout(()=>{e=!1},200),i=-1,s=-1}),this.renderer.domElement.addEventListener("dblclick",n=>{e=!0,t||(this.handleMouseClick(n),this.flyToSelectedObject())})}animate(){this.isBrowserMode()&&requestAnimationFrame(this.animate.bind(this));const t=this.clock.getDelta();this.controls&&this.controls.update(t),this.scene&&this.camera&&this.renderer?.render(this.scene,this.camera)}destroy(){this.camera=void 0,this.scene&&this.scene.clear(),this.requestAnimationFrameHandle&&(cancelAnimationFrame(this.requestAnimationFrameHandle),this.requestAnimationFrameHandle=void 0),this.renderer&&(this.containerOrCanvas.removeChild(this.renderer.domElement),this.renderer.clear(),this.renderer.dispose(),this.renderer=void 0),this.controls&&(this.controls.dispose(),this.controls=void 0),this.renderTarget&&(this.renderTarget.dispose(),this.renderTarget=void 0),this.raycaster=void 0,this.selectedObject=void 0,this.savedMaterialsForOpacity=void 0,this.loadedModels=[]}async loadLocalModel(t,e,i){const n=await new Vt().loadLocalModel(t,e.src,i);return n?(await this.applyOptionsAndAddToScene(t,n,e),Promise.resolve()):Promise.reject()}async loadModel(t,e){this.increaseJobCount();const s=await new Vt().loadModel(t.src,t.fileFormat,e);return s?(await this.applyOptionsAndAddToScene(t.src,s,t),Promise.resolve()):Promise.reject()}parseGltf(t,e,i,s){this.increaseJobCount(),new Vt().parseGltf(t,e.src,n=>{this.applyOptionsAndAddToScene(e.src,n,e),i&&i(n)},n=>{s&&s(n)})}addModel(t){if(!this.scene||!this.renderer)return;this.increaseJobCount();const e=new p.Box3().setFromObject(t.object);t.bbox||(t.bbox=e),this.scene.add(t.object),this.loadedModels.push(t),this.computeBoundingBox(),this.loadedModels.length===1&&(this.tryAdjustCameraNearAndFar(),this.goToHomeView()),this.renderer.shadowMap.needsUpdate=!0,P.info("[Viewer] Added '"+t.modelId+"' to scene"),this.decreaseJobCount()}addOrRemoveObjectOpacity(t=!0,e=.3,i,s){if(this.savedMaterialsForOpacity||(this.savedMaterialsForOpacity=[]),!this.scene)return;const n=this.scene,r=[];this.loadedModels.forEach(a=>{const o=a.object.id;if(t){this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0&&J.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity);const l=J.setObjectOpacityById(n,o,e,i,s);r.push(...l)}else this.savedMaterialsForOpacity&&J.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity)}),t?this.savedMaterialsForOpacity=r:this.savedMaterialsForOpacity=[]}hasTransparentObject(){return!!(this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0)}getIntersections(t){if(!this.raycaster||!this.camera||!this.scene)return[];let e=new p.Vector2;t&&(e=Ee.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=Ee.screen2Ndc(e,this.camera,this.containerOrCanvas);this.raycaster.setFromCamera(i,this.camera);const s=[];return this.loadedModels.forEach(n=>{const r=n.object;r&&r.visible&&s.push(r)}),this.raycaster.intersectObjects(s,!0)||[]}handleMouseClick(t){this.raycaster&&this.raycaster.layers.set(Ut);const i=this.getIntersections(t).find(n=>{const r=n.object;return r.visible&&r instanceof p.Mesh});let s=i&&i.object||void 0;s&&this.selectedObject&&this.selectedObject.id===s.id&&(s=void 0),s?this.selectObject(s):this.clearSelection()}selectObject(t){if(this.selectedObject){const i=this.selectedObject.userData;if(i.originalMaterial){if(this.selectedObject.material){const s=this.selectedObject.material;Array.isArray(s)?s.forEach(n=>n.dispose()):s instanceof p.Material&&s.dispose()}this.selectedObject.material=i.originalMaterial,delete i.originalMaterial}this.selectedObject=void 0}if(!this.scene||!t)return;const e=xe.clonedHighlightMaterials(t);e&&(this.selectedObject=t,this.selectedObject.userData.originalMaterial=this.selectedObject.material,this.selectedObject.material=e)}clearSelection(){this.selectObject()}flyToObjects(t){if(!t||t.length===0||!this.camera)return;const e=new p.Box3;t.forEach(n=>{const r=_t.getBoundingBox(n);e.union(r)});const i=new p.Sphere;e.getBoundingSphere(i),this.controls?.fitToSphere(i,!0)}flyToObject(t){this.flyToObjects([t])}flyToSelectedObject(){this.selectedObject&&this.flyToObject(this.selectedObject)}flyTo(t,e,i){const s=this.camera,n=this.controls;if(!s||!n)return;t=Array.isArray(t)?new p.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new p.Vector3(e[0],e[1],e[2]):e;const r=t,a=e;P.info("[Viewer] flyTo: ",j.vectorToString(r)),n.setPosition(r.x,r.y,r.z),n.setTarget(a.x,a.y,a.z),this.isBrowserMode()||this.renderer?.render(this.scene,s),i&&i()}goToHomeView(){const t=new p.Sphere;this.bbox.getBoundingSphere(t),this.controls?.fitToSphere(t,!0)}setEnvironmentFromDataArray(t){ms.createEnvTextureFromDataArray(this.pmremGenerator,t).then(e=>{this.scene.environment=e,this.isBrowserMode()||this.animate()})}tryAdjustCameraNearAndFar(){const t=this.camera;if(!this.scene||!t)return;const e=this.bbox,i=t.near,s=t.far,n=e.max.x-e.min.x,r=e.max.y-e.min.y,a=e.max.z-e.min.z,o=Math.max(n,r,a),l=5,h=o/l,d=o*l;if(i>h||s<d){const u=f=>j.numberToString(f);P.info("[Viewer] BBox's longest side is: "+u(o)),i>h&&(P.warn("[Viewer] camera.near("+u(i)+") shouldn't bigger than "+u(h)+", will change it!"),t.near=h),s<d&&(P.warn("[Viewer] camera.far("+u(s)+") shouldn't smaller than "+u(d)+", will change it!"),t.far=d)}t.updateProjectionMatrix()}isolateObjects(t){const e=this.transparentObjectIds.length>0?void 0:this.transparentObjectIds,i=this.transparentObjectIds.length>0?this.transparentObjectIds:void 0,s=new p.MeshBasicMaterial({color:16777215,transparent:!0,opacity:.1});this.loadedModels.forEach(r=>{const a=r.object.id;J.applyMaterialToObjectById(this.scene,a,s,i,e)}),this.outlineRoot.clear();let n=[];if(t.forEach(r=>{const a=r.modelId;let l=this.loadedModels.find(h=>h.modelId===a)?.object;l||(P.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(h=>{if(jr.includes(r.id,jr.get(h.userData,"UniqueId"))){const d=this.getMeshes(h);n=n.concat(d)}})}),n.length>0){n.forEach(a=>{const o=J.createOutline(a.geometry,this.outlineMaterial);o.applyMatrix4(a.matrixWorld),this.outlineRoot.add(o),o.updateWorldMatrix(!0,!1)});const r=n.map(a=>a.id);this.loadedModels.forEach(a=>{const o=a.object.id;J.revertAppliedMaterialToObjectById(this.scene,o,r)}),this.transparentObjectIds=r,this.flyToObjects(n)}else P.warn("[Viewer] No object found with uniqueIds: "+t.map(r=>r.id));this.isBrowserMode()||this.animate()}increaseJobCount(){++this.jobCount}decreaseJobCount(){--this.jobCount}computeBoundingBox(){const t=new p.Box3;return this.loadedModels.forEach(e=>{e.bbox&&!e.bbox.isEmpty()&&t.union(e.bbox)}),this.bbox=t,t}getContext(){return this.renderer?.getContext()}getCameraDirection(){const t=new p.Vector3;return this.camera?.getWorldDirection(t),{x:t.x,y:t.y,z:t.z}}setFov(t){this.camera&&(this.camera.fov=t,this.camera.updateProjectionMatrix())}}const bl="1.0.0",wl="VERSION",vl=()=>window.localStorage.getItem(wl),Ml=()=>{window.localStorage.setItem(wl,bl)},Hu=()=>vl()!==bl?(Ml(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>D.Mesh});exports.BaseDxfCompareHelper=ml;exports.BaseViewer=Mn;exports.BimTilesModel=Lr;exports.BimTilesRenderer=el;exports.BimTilesViewer=zu;exports.BinaryReader=vs;exports.BoxSelectHelper=xn;exports.ByBlock=gs;exports.ByLayer=Br;exports.CSS2DObjectUtils=Rh;exports.CameraProjection=bt;exports.CancelablePromise=kh;exports.CanvasRender=bs;exports.ColorUtils=Li;exports.CommonUtils=j;exports.CompareDrawable=wt;exports.Container=Rr;exports.ControlsMode=ot;exports.CoordinateUtils=Ee;exports.DecimalPrecisionRange=Co;exports.DefaultCameraFar=ln;exports.DefaultCameraFov=Oo;exports.DefaultCameraNear=on;exports.DefaultLanguage=So;exports.DefaultOpacity=Ar;exports.DefaultViewer3dConfig=su;exports.DeviceUtils=Be;exports.Drawable=Ht;exports.DrawableList=ws;exports.DxfChangeType=Ve;exports.DxfCompare=at;exports.DxfCompareHelper=Bu;exports.DxfCompareMarkupManager=vr;exports.DxfLoader=X;exports.DxfParser=No;exports.DxfRenderOrder=Oe;exports.DxfUtils=Tt;exports.EdgeUtils=_o;exports.Event=Nt;exports.ExportUtils=yr;exports.FontManager=xt;exports.FpsUtils=Gh;exports.GenerateMeshBvhWorker=cl;exports.GeometryUtils=N;exports.GroundPlaneRenderOrder=pl;exports.HighlightColor=Pr;exports.HighlightColorRgba=zh;exports.IconfontClass=Vh;exports.IconfontClass2=jh;exports.InputManager=fl;exports.InstantiateHelper=du;exports.LayerForHitableObjects=Eo;exports.LayerForSelectableObjects=Ut;exports.LayerForSnapableObjects=je;exports.Line=fc;exports.LinePatternShaders=Vo;exports.LoadingHelper=Vt;exports.MaterialUtils=xe;exports.MathUtils=z;exports.MatrixAutoUpdate=ct;exports.MergeUtils=fe;exports.MeshBvhHelper=zr;exports.MobileTouchHelperDrawable=_u;exports.Model=vn;exports.Model2d=Ri;exports.Model3d=kr;exports.NestedCompareTypes=os;exports.OSnapHelper=Tu;exports.OSnapIconSize=Qh;exports.OSnapMarkerType=Et;exports.OSnapType=hl;exports.ObjectPixelSizeHelper=gu;exports.ObjectUtils=J;exports.Offset=ku;exports.OrbitControls=sl;exports.OutlineColorRgba=an;exports.PickMarkupHelper=Cu;exports.PlanControls=nl;exports.Plugin=Vu;exports.Points=gh;exports.PolygonUtils=$h;exports.ProgressBar=Fr;exports.RafHelper=ol;exports.SVGObjectUtils=ed;exports.SceneUtils=_t;exports.SectionUtils=zt;exports.ShaderChunk=Bh;exports.SimplifyUtils=Jh;exports.SnapDrawable=_e;exports.Spinner=tl;exports.TextSearchHelper=Mr;exports.TextureUtils=ms;exports.ThresholdAngleForEdge=Ir;exports.UnitConversionByMeter=xr;exports.UnitLabels=Io;exports.UnitScaleConversion=md;exports.UnitScaleToMeter=wr;exports.Units=Ke;exports.Viewer2d=Vr;exports.Viewer3d=Du;exports.Viewer3dLite=Uu;exports.Viewer3dUtils=sd;exports.ViewerEvent=le;exports.ViewerMode=xl;exports.ViewerName=$e;exports.Views=ko;exports.ZoomToRectHelper=ul;exports.bspline=Lo;exports.checkIsNewVersion=Hu;exports.cn=Ao;exports.createHatchPatternShaderMaterial=jo;exports.decodeDxfTextCharacterCodes=Ro;exports.decodeDxfTextMbcsCharacterCodes=zo;exports.decodeDxfTextUnicodeCodePoints=Fo;exports.en=Po;exports.getLengthValueByUnit=id;exports.getUnitStr=br;exports.getVersionFromLocalStorage=vl;exports.i18n=We;exports.log=P;exports.parseDxfMTextContent=ls;exports.parseDxfTextContent=cn;exports.round10=Do;exports.setIcon=Lh;exports.setLogLevel=To;exports.setVersionToLocalStorage=Ml;exports.showPrecisionValue=Fh;