@maqiuyao/dxf-viewer 0.2.3 → 0.2.4

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 sa=Object.defineProperty;var ra=(h,t,e)=>t in h?sa(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e;var p=(h,t,e)=>ra(h,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Se=require("three"),ks=require("three-mesh-bvh"),na=require("loglevel"),rn=require("three/examples/jsm/renderers/CSS2DRenderer.js"),aa=require("three/examples/jsm/exporters/DRACOExporter.js"),oa=require("three/examples/jsm/exporters/GLTFExporter.js"),la=require("three/examples/jsm/exporters/OBJExporter.js"),ha=require("three/examples/jsm/exporters/STLExporter.js"),ca=require("poly-extrude"),da=require("i18next"),xe=require("three/examples/jsm/utils/BufferGeometryUtils.js"),ua=require("three/src/extras/Earcut.js"),fa=require("2d-polygon-self-intersections"),pa=require("three/examples/jsm/modifiers/SimplifyModifier.js"),ma=require("three/examples/jsm/renderers/SVGRenderer.js"),ga=require("three/examples/jsm/loaders/RGBELoader.js"),ya=require("js-base64"),xa=require("concaveman"),ba=require("polybooljs"),wi=require("jsbi"),va=require("3d-tiles-renderer"),wa=require("protobufjs"),Ma=require("three/examples/jsm/loaders/DDSLoader.js"),Ds=require("pako"),Ta=require("three/examples/jsm/geometries/TextGeometry.js"),Ca=require("opentype.js"),Sa=require("three/examples/jsm/loaders/FontLoader.js"),Oa=require("three/examples/jsm/loaders/ColladaLoader.js"),Ea=require("three/examples/jsm/loaders/DRACOLoader.js"),_a=require("three/examples/jsm/loaders/FBXLoader.js"),Pa=require("three/examples/jsm/loaders/GLTFLoader.js"),Aa=require("three/examples/jsm/loaders/MTLLoader.js"),Ia=require("three/examples/jsm/loaders/OBJLoader.js"),ka=require("three/examples/jsm/loaders/PLYLoader.js"),Da=require("three/examples/jsm/loaders/STLLoader.js"),Zt=require("polygon-clipping"),Ba=require("three/examples/jsm/postprocessing/EffectComposer.js"),La=require("three/examples/jsm/postprocessing/RenderPass.js"),Ra=require("three/examples/jsm/postprocessing/ShaderPass.js"),Fa=require("three/examples/jsm/postprocessing/SAOPass.js"),za=require("three/examples/jsm/postprocessing/SSAOPass.js"),ja=require("three/examples/jsm/postprocessing/OutlinePass.js"),Va=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),Ua=require("three/examples/jsm/postprocessing/BloomPass.js"),Ha=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),Na=require("three/examples/jsm/shaders/FXAAShader.js"),Ga=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),qs=require("lodash");function yi(h){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const e in h)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>h[e]})}}return t.default=h,Object.freeze(t)}const d=yi(Se),Ws=yi(na),qa=yi(ya),yt=yi(ba),Wa=yi(wa),zt=1,Ge=new d.Sphere,ts=new d.Vector3,is=new d.Vector3,Ys=new d.Vector3,Xs=new d.Vector3;d.Line.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Line.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),Ge.copy(e.boundingSphere),Ge.applyMatrix4(i),Ge.radius+=s,h.ray.intersectsSphere(Ge)===!1)return;const n=s*s,a=this.isLineSegments?2:1,o=e.index,l=e.attributes,c=l.position,u=t.length;if(o!==null){const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1)for(let x=g.indexStart,y=g.indexStart+g.indexCount-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(Mi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=zt))return}}else{const m=Math.max(0,r.start),g=Math.min(o.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a){const T=o.getX(x),v=o.getX(x+1);if(Mi(this,c,h,T,v,n,t)&&(t[t.length-1].index=x,t.length-u>=zt))return}}}else{const f=this.userData.batches;if(f&&f.length>0&&f[0].boundingSphere)for(let m=0;m<f.length;m++){const g=f[m];if(Ge.copy(g.boundingSphere),Ge.applyMatrix4(i),h.ray.intersectsSphere(Ge)!==!1){for(let x=g.positionStart,y=g.positionStart+g.positionCount-1;x<y;x+=a)if(Mi(this,c,h,x,x+1,n,t)&&t.length-u>=zt)return}}else{const m=Math.max(0,r.start),g=Math.min(c.count,r.start+r.count);for(let x=m,y=g-1;x<y;x+=a)if(Mi(this,c,h,x,x+1,n,t)&&t.length-u>=zt)return}}};function Mi(h,t,e,i,s,r,n){if(ts.fromBufferAttribute(t,i),ts.applyMatrix4(h.matrixWorld),is.fromBufferAttribute(t,s),is.applyMatrix4(h.matrixWorld),e.ray.distanceSqToSegment(ts,is,Xs,Ys)>r)return!1;const o=e.ray.origin.distanceTo(Xs);return o<e.near||o>e.far?!1:(n.push({distance:o,point:Ys.clone(),index:i,object:h}),!0)}const Ya=d.Line;Se.Mesh.prototype.raycast=ks.acceleratedRaycast;const Ti=new d.Sphere,Ci=new d.Vector3;d.Points.prototype.raycast=function(h,t){const e=this.geometry,i=this.matrixWorld,s=h.params.Points.threshold,r=e.drawRange;if(e.boundingSphere===null&&e.computeBoundingSphere(),Ti.copy(e.boundingSphere),Ti.applyMatrix4(i),Ti.radius+=s,h.ray.intersectsSphere(Ti)===!1)return;const n=s*s,a=e.index,o=e.attributes,l=o.position,c=t.length;if(a!==null){const u=Math.max(0,r.start),f=Math.min(a.count,r.start+r.count);for(let m=u,g=f;m<g;m++){const x=a.getX(m);if(Ci.fromBufferAttribute(l,x).applyMatrix4(i),Zs(Ci,x,n,h,t,this),t.length-c>=zt)return}}else{const u=Math.max(0,r.start),f=Math.min(l.count,r.start+r.count);for(let m=u,g=f;m<g;m++)if(Ci.fromBufferAttribute(l,m).applyMatrix4(i),Zs(Ci,m,n,h,t,this),t.length-c>=zt)return}};function Zs(h,t,e,i,s,r){const n=i.ray.distanceSqToPoint(h);if(n<e){const a=new d.Vector3;i.ray.closestPointToPoint(h,a);const o=i.ray.origin.distanceTo(a);if(o<i.near||o>i.far)return;s.push({distance:o,distanceToRay:Math.sqrt(n),point:a,index:t,face:null,object:r})}}const Xa=d.Points,Za=`
1
+ "use strict";var vl=Object.defineProperty;var Ml=(c,t,e)=>t in c?vl(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var g=(c,t,e)=>Ml(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const D=require("three"),Tl=require("loglevel"),ho=require("three/examples/jsm/renderers/CSS2DRenderer.js"),Cl=require("three/examples/jsm/exporters/DRACOExporter.js"),Sl=require("three/examples/jsm/exporters/GLTFExporter.js"),El=require("three/examples/jsm/exporters/OBJExporter.js"),Ol=require("three/examples/jsm/exporters/STLExporter.js"),_l=require("poly-extrude"),Pl=require("i18next"),_e=require("three/examples/jsm/utils/BufferGeometryUtils.js"),Al=require("three/src/extras/Earcut.js"),Il=require("2d-polygon-self-intersections"),Bl=require("three/examples/jsm/modifiers/SimplifyModifier.js"),kl=require("three/examples/jsm/renderers/SVGRenderer.js"),Dl=require("three/examples/jsm/loaders/RGBELoader.js"),Ll=require("js-base64"),Rl=require("concaveman"),Fl=require("polybooljs"),ps=require("jsbi"),zl=require("3d-tiles-renderer"),Vl=require("protobufjs"),jl=require("three/examples/jsm/loaders/DDSLoader.js"),gr=require("pako"),Ul=require("three/examples/jsm/geometries/TextGeometry.js"),Nl=require("opentype.js"),Hl=require("three/examples/jsm/loaders/FontLoader.js"),Gl=require("three/examples/jsm/loaders/ColladaLoader.js"),ql=require("three/examples/jsm/loaders/DRACOLoader.js"),Wl=require("three/examples/jsm/loaders/FBXLoader.js"),Yl=require("three/examples/jsm/loaders/GLTFLoader.js"),Xl=require("three/examples/jsm/loaders/MTLLoader.js"),Zl=require("three/examples/jsm/loaders/OBJLoader.js"),Kl=require("three/examples/jsm/loaders/PLYLoader.js"),$l=require("three/examples/jsm/loaders/STLLoader.js"),ki=require("polygon-clipping"),Jl=require("three/examples/jsm/postprocessing/EffectComposer.js"),Ql=require("three/examples/jsm/postprocessing/RenderPass.js"),ec=require("three/examples/jsm/postprocessing/ShaderPass.js"),tc=require("three/examples/jsm/postprocessing/SAOPass.js"),ic=require("three/examples/jsm/postprocessing/SSAOPass.js"),sc=require("three/examples/jsm/postprocessing/OutlinePass.js"),nc=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),rc=require("three/examples/jsm/postprocessing/BloomPass.js"),ac=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),oc=require("three/examples/jsm/shaders/FXAAShader.js"),lc=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),Dr=require("lodash");function hs(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=hs(D),Lr=hs(Tl),cc=hs(Ll),Ut=hs(Fl),hc=hs(Vl),vi=1,lt=new p.Sphere,yn=new p.Vector3,xn=new p.Vector3,Rr=new p.Vector3,Fr=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(),lt.copy(e.boundingSphere),lt.applyMatrix4(i),lt.radius+=s,c.ray.intersectsSphere(lt)===!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(lt.copy(m.boundingSphere),lt.applyMatrix4(i),c.ray.intersectsSphere(lt)!==!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(ms(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=vi))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(ms(this,h,c,C,w,r,t)&&(t[t.length-1].index=b,t.length-d>=vi))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(lt.copy(m.boundingSphere),lt.applyMatrix4(i),c.ray.intersectsSphere(lt)!==!1){for(let b=m.positionStart,y=m.positionStart+m.positionCount-1;b<y;b+=a)if(ms(this,h,c,b,b+1,r,t)&&t.length-d>=vi)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(ms(this,h,c,b,b+1,r,t)&&t.length-d>=vi)return}}};function ms(c,t,e,i,s,n,r){if(yn.fromBufferAttribute(t,i),yn.applyMatrix4(c.matrixWorld),xn.fromBufferAttribute(t,s),xn.applyMatrix4(c.matrixWorld),e.ray.distanceSqToSegment(yn,xn,Fr,Rr)>n)return!1;const o=e.ray.origin.distanceTo(Fr);return o<e.near||o>e.far?!1:(r.push({distance:o,point:Rr.clone(),index:i,object:c}),!0)}const dc=p.Line,uo=0,uc=1,fc=2,zr=2,bn=1.25,Vr=1,Pe=32,be=Pe/4,fo=65535,Zs=Math.pow(2,-24),yr=Symbol("SKIP_GENERATION"),po={strategy:uo,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[yr]:!1};function ae(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 Jn(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 jr(c,t){t.set(c)}function Ur(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 gs(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 Di(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 ce(c,t){return t[c+15]===fo}function Me(c,t){return t[c+6]}function Ae(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 xr(c,t){return t[c+7]}function wn(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 S=c[w+0],M=c[w+1],O=S-M,E=S+M;O<n&&(n=O),E>o&&(o=E),S<d&&(d=S),S>m&&(m=S);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,R=I+B;k<a&&(a=k),R>h&&(h=R),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 xt=32,pc=(c,t)=>c.candidate-t.candidate,Et=new Array(xt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ys=new Float32Array(6);function mc(c,t,e,i,s,n){let r=-1,a=0;if(n===uo)r=Jn(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===uc)r=Jn(c),r!==-1&&(a=gc(e,i,s,r));else if(n===fc){const o=Di(c);let l=bn*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)/xt;if(s<xt/4){const w=[...Et];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:E,leftCacheBounds:v,rightCacheBounds:T}=O;for(let _=0;_<3;_++)T[_]=1/0,T[_+3]=-1/0,v[_]=1/0,v[_+3]=-1/0,E[_]=1/0,E[_+3]=-1/0;gs(M,e,E)}w.sort(pc);let S=s;for(let M=0;M<S;M++){const O=w[M];for(;M+1<S&&w[M+1].candidate===O.candidate;)w.splice(M+1,1),S--}for(let M=d;M<u;M+=6){const O=e[M+2*f];for(let E=0;E<S;E++){const v=w[E];O>=v.candidate?gs(M,e,v.rightCacheBounds):(gs(M,e,v.leftCacheBounds),v.count++)}}for(let M=0;M<S;M++){const O=w[M],E=O.count,v=s-O.count,T=O.leftCacheBounds,_=O.rightCacheBounds;let A=0;E!==0&&(A=Di(T)/o);let I=0;v!==0&&(I=Di(_)/o);const B=Vr+bn*(A*E+I*v);B<l&&(r=f,l=B,a=O.candidate)}}else{for(let S=0;S<xt;S++){const M=Et[S];M.count=0,M.candidate=m+C+S*C;const O=M.bounds;for(let E=0;E<3;E++)O[E]=1/0,O[E+3]=-1/0}for(let S=d;S<u;S+=6){let E=~~((e[S+2*f]-m)/C);E>=xt&&(E=xt-1);const v=Et[E];v.count++,gs(S,e,v.bounds)}const w=Et[xt-1];jr(w.bounds,w.rightCacheBounds);for(let S=xt-2;S>=0;S--){const M=Et[S],O=Et[S+1];Ur(M.bounds,O.rightCacheBounds,M.rightCacheBounds)}let x=0;for(let S=0;S<xt-1;S++){const M=Et[S],O=M.count,E=M.bounds,T=Et[S+1].rightCacheBounds;O!==0&&(x===0?jr(E,ys):Ur(E,ys,ys)),x+=O;let _=0,A=0;x!==0&&(_=Di(ys)/o);const I=s-x;I!==0&&(A=Di(T)/o);const B=Vr+bn*(_*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 gc(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 vn{constructor(){this.boundingData=new Float32Array(6)}}function yc(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,Ks,Qn,go;const xc=Math.pow(2,32);function er(c){return"count"in c?1:1+er(c.left)+er(c.right)}function bc(c,t,e){return mo=new Float32Array(e),Ks=new Uint32Array(e),Qn=new Uint16Array(e),go=new Uint8Array(e),tr(c,t)}function tr(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?(go.set(new Uint8Array(t.buffer),c),c+t.buffer.byteLength):(Ks[e+6]=t.offset,Qn[i+14]=t.count,Qn[i+15]=fo,c+Pe);{const{left:r,right:a,splitAxis:o}=t,l=c+Pe;let h=tr(l,r);const d=c/Pe,f=h/Pe-d;if(f>xc)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ks[e+6]=f,Ks[e+7]=o,tr(h,a)}}function wc(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 vn;return wn(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,S,M,O=null,E=0){!b&&E>=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||E>=r)return C(S+M),x.offset=S,x.count=M,x;const T=mc(x.boundingData,O,t,S,M,h);let _=T.axis===-1?-1:yc(u,f,t,S,M,T);if(T.axis===-1||_===S||_===S+M){if(!v)return C(S+M),x.offset=S,x.count=M,x;T.axis=Math.max(0,Jn(x.boundingData)),_=S+Math.max(1,Math.floor(M/2))}x.splitAxis=T.axis;const A=new vn,I=S,B=_-S;x.left=A,wn(t,I,B,A.boundingData,m),w(A,I,B,m,E+1);const k=new vn,R=_,z=M-B;return x.right=k,wn(t,R,z,k.boundingData,m),w(k,R,z,m,E+1),x}}function vc(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=wc(c,a,o.offset,o.count,t,r),h=er(l),d=new e(Pe*h);return bc(0,l,d),d})}class br{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 Mc{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 ie=new Mc;let kt,Mi;const ti=[],xs=new br(()=>new D.Box3);function Tc(c,t,e,i,s,n){kt=xs.getPrimitive(),Mi=xs.getPrimitive(),ti.push(kt,Mi),ie.setBuffer(c._roots[t]);const r=ir(0,c.geometry,e,i,s,n);ie.clearBuffer(),xs.releasePrimitive(kt),xs.releasePrimitive(Mi),ti.pop(),ti.pop();const a=ti.length;return a>0&&(Mi=ti[a-1],kt=ti[a-2]),r}function ir(c,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:l}=ie;let h=c*2;if(ce(h,o)){const u=Me(c,l),f=Ae(h,o);return ae(c,a,kt),i(u,f,!1,r,n+c/be,kt)}else{let _=function(I){const{uint16Array:B,uint32Array:k}=ie;let R=I*2;for(;!ce(R,B);)I=we(I),R=I*2;return Me(I,k)},A=function(I){const{uint16Array:B,uint32Array:k}=ie;let R=I*2;for(;!ce(R,B);)I=ve(I,k),R=I*2;return Me(I,k)+Ae(R,B)};const u=we(c),f=ve(c,l);let m=u,b=f,y,C,w,x;if(s&&(w=kt,x=Mi,ae(m,a,w),ae(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=kt,ae(m,a,w));const S=ce(m*2,o),M=e(w,S,y,r+1,n+m/be);let O;if(M===zr){const I=_(m),k=A(m)-I;O=i(I,k,!0,r+1,n+m/be,w)}else O=M&&ir(m,t,e,i,s,n,r+1);if(O)return!0;x=Mi,ae(b,a,x);const E=ce(b*2,o),v=e(x,E,C,r+1,n+b/be);let T;if(v===zr){const I=_(b),k=A(b)-I;T=i(I,k,!0,r+1,n+b/be,x)}else T=v&&ir(b,t,e,i,s,n,r+1);return!!T}}const $i=new ie.constructor,rn=new ie.constructor,Pt=new br(()=>new D.Box3),ii=new D.Box3,si=new D.Box3,Mn=new D.Box3,Tn=new D.Box3;let Cn=!1;function Cc(c,t,e,i){if(Cn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Cn=!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++){$i.setBuffer(s[h]),o=0;const u=Pt.getPrimitive();ae(0,$i.float32Array,u),u.applyMatrix4(l);for(let f=0,m=n.length;f<m&&(rn.setBuffer(n[f]),r=it(0,0,e,l,i,a,o,0,0,u),rn.clearBuffer(),o+=n[f].byteLength/Pe,!r);f++);if(Pt.releasePrimitive(u),$i.clearBuffer(),a+=s[h].byteLength/Pe,r)break}return Cn=!1,r}function it(c,t,e,i,s,n=0,r=0,a=0,o=0,l=null,h=!1){let d,u;h?(d=rn,u=$i):(d=$i,u=rn);const f=d.float32Array,m=d.uint32Array,b=d.uint16Array,y=u.float32Array,C=u.uint32Array,w=u.uint16Array,x=c*2,S=t*2,M=ce(x,b),O=ce(S,w);let E=!1;if(O&&M)h?E=s(Me(t,C),Ae(t*2,w),Me(c,m),Ae(c*2,b),o,r+t/be,a,n+c/be):E=s(Me(c,m),Ae(c*2,b),Me(t,C),Ae(t*2,w),a,n+c/be,o,r+t/be);else if(O){const v=Pt.getPrimitive();ae(t,y,v),v.applyMatrix4(e);const T=we(c),_=ve(c,m);ae(T,f,ii),ae(_,f,si);const A=v.intersectsBox(ii),I=v.intersectsBox(si);E=A&&it(t,T,i,e,s,r,n,o,a+1,v,!h)||I&&it(t,_,i,e,s,r,n,o,a+1,v,!h),Pt.releasePrimitive(v)}else{const v=we(t),T=ve(t,C);ae(v,y,Mn),ae(T,y,Tn);const _=l.intersectsBox(Mn),A=l.intersectsBox(Tn);if(_&&A)E=it(c,v,e,i,s,n,r,a,o+1,l,h)||it(c,T,e,i,s,n,r,a,o+1,l,h);else if(_)if(M)E=it(c,v,e,i,s,n,r,a,o+1,l,h);else{const I=Pt.getPrimitive();I.copy(Mn).applyMatrix4(e);const B=we(c),k=ve(c,m);ae(B,f,ii),ae(k,f,si);const R=I.intersectsBox(ii),z=I.intersectsBox(si);E=R&&it(v,B,i,e,s,r,n,o,a+1,I,!h)||z&&it(v,k,i,e,s,r,n,o,a+1,I,!h),Pt.releasePrimitive(I)}else if(A)if(M)E=it(c,T,e,i,s,n,r,a,o+1,l,h);else{const I=Pt.getPrimitive();I.copy(Tn).applyMatrix4(e);const B=we(c),k=ve(c,m);ae(B,f,ii),ae(k,f,si);const R=I.intersectsBox(ii),z=I.intersectsBox(si);E=R&&it(T,B,i,e,s,r,n,o,a+1,I,!h)||z&&it(T,k,i,e,s,r,n,o,a+1,I,!h),Pt.releasePrimitive(I)}}return E}const Sn=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(;!ce(r,e);)n=we(n),r=n*2;return Me(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!ce(r,e);)n=ve(n,t),r=n*2;return Me(n,t)+Ae(r,e)};const s=(n,r,a)=>{const o=r*2,l=ce(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=xr(o,t);return n(r,a,new Float32Array(c,o*4,6),l)}})}}},Nr=new D.Box3,ni=new Float32Array(6);class Sc{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...po,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),vc(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,ni,0);const[f,m,b,y,C,w]=ni;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,ni,0);const[a,o,l,h,d,u]=ni,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)*Zs,i[x+2]=m,i[x+3]=C+(Math.abs(m)+C)*Zs,i[x+4]=b,i[x+5]=w+(Math.abs(b)+w)*Zs}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/Pe;for(let l=0;l<o;l++){const h=be*l,d=2*h;ce(d,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){Sn.setBVH(this,e),Sn.traverse(t),Sn.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/Pe;for(let l=o-1;l>=0;l--){const h=l*be,d=h*2;if(ce(d,r)){const f=Me(h,n),m=Ae(d,r);this.writePrimitiveRangeBounds(f,m,ni,0),a.set(ni,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=>{ae(0,new Float32Array(i),Nr),t.union(Nr)}),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=Tc(this,d,i,s,e,l),o)break;l+=f.byteLength/Pe}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return Cc(this,t,e,s)}}function Ec(){return typeof SharedArrayBuffer<"u"}function wr(c){return c.index?c.index.count:c.attributes.position.count}function dn(c){return wr(c)/3}function Oc(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function _c(c,t){if(!c.index){const e=c.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Oc(e,i);c.setIndex(new D.BufferAttribute(s,1));for(let n=0;n<e;n++)s[n]=n}}function Pc(c,t,e){const i=wr(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 Ac(c,t){return c.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Hr(c,t,e){const i=Pc(c,t,e),s=Ac(c,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=wr(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 Ic(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 Bc extends Sc{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&&!Ec())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={...po,...e},e[yr]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Hr(e,t.range,i),n=Ic(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else _c(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}]:Hr(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 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 kc=(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}})(),vr=(function(){const c=new D.Vector2,t=new D.Vector3,e=new D.Vector3;return function(s,n,r,a){kc(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}}}})(),Dc=(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}})(),Lc=["x","y","z"],vt=1e-15,Gr=vt*vt;function He(c){return Math.abs(c)<vt}class at 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 St),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 Dc(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<vt?y<vt||C<vt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):y<vt?C<vt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):C<vt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}at.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]),vr(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)}})();at.prototype.intersectsTriangle=(function(){const c=new at,t=new St,e=new St,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,S,M,O){const E=i;!x.isDegenerateIntoPoint&&!x.isDegenerateIntoSegment?E.copy(x.plane.normal):E.copy(S.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,S.points),B.isSeparated(t)||(r.copy(E).cross(k),t.setFromPoints(r,x.points),e.setFromPoints(r,S.points),t.isSeparated(e)))return!1}const _=S.satBounds,A=S.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(E,k),t.setFromPoints(r,x.points),e.setFromPoints(r,S.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,S,M,O,E,v,T,_,A,I,B){let k=T/(T-_);I.x=O+(E-O)*k,B.start.subVectors(S,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,S,M,O,E,v,T,_,A,I,B){if(E>0)f(x.c,x.a,x.b,O,S,M,A,T,_,I,B);else if(v>0)f(x.b,x.a,x.c,M,S,O,_,T,A,I,B);else if(_*A>0||T!=0)f(x.a,x.b,x.c,S,M,O,T,_,A,I,B);else if(_!=0)f(x.b,x.a,x.c,M,S,O,_,T,A,I,B);else if(A!=0)f(x.c,x.a,x.b,O,S,M,A,T,_,I,B);else return!0;return!1}function b(x,S,M,O){const E=S.degenerateSegment,v=x.plane.distanceToPoint(E.start),T=x.plane.distanceToPoint(E.end);return He(v)?He(T)?u(x,S,M,O):(M&&(M.start.copy(E.start),M.end.copy(E.start)),x.containsPoint(E.start)):He(T)?(M&&(M.start.copy(E.end),M.end.copy(E.end)),x.containsPoint(E.end)):x.plane.intersectLine(E,i)!=null?(M&&(M.start.copy(i),M.end.copy(i)),x.containsPoint(i)):!1}function y(x,S,M){const O=S.a;return He(x.plane.distanceToPoint(O))&&x.containsPoint(O)?(M&&(M.start.copy(O),M.end.copy(O)),!0):!1}function C(x,S,M){const O=x.degenerateSegment,E=S.a;return O.closestPointToPoint(E,!0,i),E.distanceToSquared(i)<Gr?(M&&(M.start.copy(E),M.end.copy(E)),!0):!1}function w(x,S,M,O){if(x.isDegenerateIntoSegment)if(S.isDegenerateIntoSegment){const E=x.degenerateSegment,v=S.degenerateSegment,T=s,_=n;E.delta(T),v.delta(_);const A=i.subVectors(v.start,E.start),I=T.x*_.y-T.y*_.x;if(He(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 R=E.start.z+T.z*B,z=v.start.z+_.z*k;return He(R-z)?(M&&(M.start.copy(E.start).addScaledVector(T,B),M.end.copy(E.start).addScaledVector(T,B)),!0):!1}else return S.isDegenerateIntoPoint?C(x,S,M):b(S,x,M,O);else{if(x.isDegenerateIntoPoint)return S.isDegenerateIntoPoint?S.a.distanceToSquared(x.a)<Gr?(M&&(M.start.copy(x.a),M.end.copy(x.a)),!0):!1:S.isDegenerateIntoSegment?C(S,x,M):y(S,x,M);if(S.isDegenerateIntoPoint)return y(x,S,M);if(S.isDegenerateIntoSegment)return b(x,S,M,O)}}return function(S,M=null,O=!1){this.needsUpdate&&this.update(),S.isExtendedTriangle?S.needsUpdate&&S.update():(c.copy(S),c.update(),S=c);const E=w(this,S,M,O);if(E!==void 0)return E;const v=this.plane,T=S.plane;let _=T.distanceToPoint(this.a),A=T.distanceToPoint(this.b),I=T.distanceToPoint(this.c);He(_)&&(_=0),He(A)&&(A=0),He(I)&&(I=0);const B=_*A,k=_*I;if(B>0&&k>0)return!1;let R=v.distanceToPoint(S.a),z=v.distanceToPoint(S.b),oe=v.distanceToPoint(S.c);He(R)&&(R=0),He(z)&&(z=0),He(oe)&&(oe=0);const le=R*z,$e=R*oe;if(le>0&&$e>0)return!1;s.copy(v.normal),n.copy(T.normal);const jt=s.cross(n);let Je=0,mn=Math.abs(jt.x);const kr=Math.abs(jt.y);kr>mn&&(mn=kr,Je=1),Math.abs(jt.z)>mn&&(Je=2);const ei=Lc[Je],ml=this.a[ei],gl=this.b[ei],yl=this.c[ei],xl=S.a[ei],bl=S.b[ei],wl=S.c[ei];if(m(this,ml,gl,yl,B,k,_,A,I,h,a))return u(this,S,M,O);if(m(S,xl,bl,wl,le,$e,R,z,oe,d,o))return u(this,S,M,O);if(h.y<h.x){const gn=h.y;h.y=h.x,h.x=gn,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(d.y<d.x){const gn=d.y;d.y=d.x,d.x=gn,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)}})();at.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();at.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]),vr(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 ke{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 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}}ke.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}})();ke.prototype.intersectsBox=(function(){const c=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(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}})();ke.prototype.intersectsTriangle=(function(){const c=new at,t=new Array(3),e=new St,i=new St,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}})();ke.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}})();ke.prototype.distanceToPoint=(function(){const c=new D.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();ke.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,S=(y+2)%3,M=C<<x|w<<S,O=1<<y|C<<x|w<<S,E=f[M],v=f[O];t[b].set(E,v);const _=c[y],A=c[x],I=c[S],B=e[b],k=B.start,R=B.end;k[_]=d[_],k[A]=C?d[A]:u[A],k[I]=w?d[I]:u[A],R[_]=u[_],R[A]=C?d[A]:u[A],R[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];vr(C,x,i,s);const S=i.distanceToSquared(s);if(S<m&&(m=S,o&&o.copy(i),l&&l.copy(s),S<h))return Math.sqrt(S)}}return Math.sqrt(m)}})();class Rc extends br{constructor(){super(()=>new at)}}const Ze=new Rc,Li=new D.Vector3,En=new D.Vector3;function Fc(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=>(Li.copy(t).clamp(h.min,h.max),Li.distanceToSquared(t)),intersectsBounds:(h,d,u)=>u<a&&u<r,intersectsTriangle:(h,d)=>{h.closestPointToPoint(t,Li);const u=t.distanceToSquared(Li);return u<a&&(En.copy(Li),a=u,o=d),u<n}}),a===1/0)return null;const l=Math.sqrt(a);return e.point?e.point.copy(En):e.point=En.clone(),e.distance=l,e.faceIndex=o,e}const bs=parseInt(D.REVISION)>=169,zc=parseInt(D.REVISION)<=161,Nt=new D.Vector3,Ht=new D.Vector3,Gt=new D.Vector3,ws=new D.Vector2,vs=new D.Vector2,Ms=new D.Vector2,qr=new D.Vector3,Wr=new D.Vector3,Yr=new D.Vector3,Ri=new D.Vector3;function Vc(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 Xr(c,t,e,i,s,n,r,a,o,l,h){Nt.fromBufferAttribute(t,n),Ht.fromBufferAttribute(t,r),Gt.fromBufferAttribute(t,a);const d=Vc(c,Nt,Ht,Gt,Ri,o,l,h);if(d){if(i){ws.fromBufferAttribute(i,n),vs.fromBufferAttribute(i,r),Ms.fromBufferAttribute(i,a),d.uv=new D.Vector2;const f=D.Triangle.getInterpolation(Ri,Nt,Ht,Gt,ws,vs,Ms,d.uv);bs||(d.uv=f)}if(s){ws.fromBufferAttribute(s,n),vs.fromBufferAttribute(s,r),Ms.fromBufferAttribute(s,a),d.uv1=new D.Vector2;const f=D.Triangle.getInterpolation(Ri,Nt,Ht,Gt,ws,vs,Ms,d.uv1);bs||(d.uv1=f),zc&&(d.uv2=d.uv1)}if(e){qr.fromBufferAttribute(e,n),Wr.fromBufferAttribute(e,r),Yr.fromBufferAttribute(e,a),d.normal=new D.Vector3;const f=D.Triangle.getInterpolation(Ri,Nt,Ht,Gt,qr,Wr,Yr,d.normal);d.normal.dot(c.direction)>0&&d.normal.multiplyScalar(-1),bs||(d.normal=f)}const u={a:n,b:r,c:a,normal:new D.Vector3,materialIndex:0};if(D.Triangle.getNormal(Nt,Ht,Gt,u.normal),d.face=u,d.faceIndex=n,bs){const f=new D.Vector3;D.Triangle.getBarycoord(Ri,Nt,Ht,Gt,f),d.barycoord=f}}return d}function Zr(c){return c&&c.isMaterial?c.side:c}function un(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:S,count:M,materialIndex:O}=u[w];if(C>=S&&C<S+M){const E=Zr(t[O]),v=Xr(e,f,m,b,y,o,l,h,E,n,r);if(v)if(v.faceIndex=i,v.face.materialIndex=O,s)s.push(v);else return v}}}else{const C=Zr(t),w=Xr(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 jc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++)un(o,t,e,h,n,r,a)}function Uc(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=un(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 Hc(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(ce(b,a)){const y=Me(u,r),C=Ae(b,a);let w=1/0,x=1/0,S=1/0,M=-1/0,O=-1/0,E=-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<S&&(S=B),B>E&&(E=B)}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==S||o[u+3]!==M||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=x,o[u+2]=S,o[u+3]=M,o[u+4]=O,o[u+5]=E,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,S=!1;if(t){if(!w){const _=y/be+f/Pe,A=C/be+f/Pe;x=t.has(_),S=t.has(A),w=!x&&!S}}else x=!0,S=!0;const M=w||x,O=w||S;let E=!1;M&&(E=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=E||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],R=o[I],z=o[I+3];o[u+_]=B<R?B:R,o[u+_+3]=k>z?k:z}return T}}}function Rt(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],S=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=(S-b)*u):(a=(S-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 Gc(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;un(o,t,e,u,n,r,a)}}function qc(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=un(a,t,e,o?o[d]:d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Wc(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 Yc(c,t,e,i,s,n,r){ie.setBuffer(c._roots[t]),sr(0,c,e,i,s,n,r),ie.clearBuffer()}function sr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ie,h=c*2;if(ce(h,o)){const u=Me(c,l),f=Ae(h,o);jc(t,e,i,u,f,s,n,r)}else{const u=we(c);Rt(u,a,i,n,r)&&sr(u,t,e,i,s,n,r);const f=ve(c,l);Rt(f,a,i,n,r)&&sr(f,t,e,i,s,n,r)}}const Xc=["x","y","z"];function Zc(c,t,e,i,s,n){ie.setBuffer(c._roots[t]);const r=nr(0,c,e,i,s,n);return ie.clearBuffer(),r}function nr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ie;let l=c*2;if(ce(l,a)){const d=Me(c,o),u=Ae(l,a);return Uc(t,e,i,d,u,s,n)}else{const d=xr(c,o),u=Xc[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=Rt(b,r,i,s,n)?nr(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 S=Rt(y,r,i,s,n)?nr(y,t,e,i,s,n):null;return w&&S?w.distance<=S.distance?w:S:w||S||null}}const Ts=new D.Box3,ri=new at,ai=new at,Fi=new D.Matrix4,Kr=new ke,Cs=new ke;function Kc(c,t,e,i){ie.setBuffer(c._roots[t]);const s=rr(0,c,e,i);return ie.clearBuffer(),s}function rr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ie;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Kr.set(e.boundingBox.min,e.boundingBox.max,i),s=Kr),ce(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Me(c,a),y=Ae(o,r);if(Fi.copy(i).invert(),e.boundsTree)return ae(c,n,Cs),Cs.matrix.copy(Fi),Cs.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Cs.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b*3,S=(y+b)*3;x<S;x+=3)if(pe(ai,x,d,u),ai.needsUpdate=!0,w.intersectsTriangle(ai))return!0;return!1}});{const C=dn(e);for(let w=b*3,x=(y+b)*3;w<x;w+=3){pe(ri,w,d,u),ri.a.applyMatrix4(Fi),ri.b.applyMatrix4(Fi),ri.c.applyMatrix4(Fi),ri.needsUpdate=!0;for(let S=0,M=C*3;S<M;S+=3)if(pe(ai,S,f,m),ai.needsUpdate=!0,ri.intersectsTriangle(ai))return!0}}}else{const h=we(c),d=ve(c,a);return ae(h,n,Ts),!!(s.intersectsBox(Ts)&&rr(h,t,e,i,s)||(ae(d,n,Ts),s.intersectsBox(Ts)&&rr(d,t,e,i,s)))}}const Ss=new D.Matrix4,On=new ke,zi=new ke,$c=new D.Vector3,Jc=new D.Vector3,Qc=new D.Vector3,eh=new D.Vector3;function th(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),On.set(t.boundingBox.min,t.boundingBox.max,e),On.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Ze.getPrimitive(),f=Ze.getPrimitive();let m=$c,b=Jc,y=null,C=null;s&&(y=Qc,C=eh);let w=1/0,x=null,S=null;return Ss.copy(e).invert(),zi.matrix.copy(Ss),c.shapecast({boundsTraverseOrder:M=>On.distanceToBox(M),intersectsBounds:(M,O,E)=>E<w&&E<r?(O&&(zi.min.copy(M.min),zi.max.copy(M.max),zi.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:v=>zi.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,S=_),k<n)return!0}}}});{const E=dn(t);for(let v=0,T=E;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=_,S=v),I<n)return!0}}}}}),Ze.releasePrimitive(u),Ze.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(Ss),b.applyMatrix4(Ss),s.distance=b.sub(s.point).length(),s.faceIndex=S),i)}function ih(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(ce(b,a)){const y=Me(u,r),C=Ae(b,a);let w=1/0,x=1/0,S=1/0,M=-1/0,O=-1/0,E=-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),R=s.getZ(I);B<w&&(w=B),B>M&&(M=B),k<x&&(x=k),k>O&&(O=k),R<S&&(S=R),R>E&&(E=R)}}return o[u+0]!==w||o[u+1]!==x||o[u+2]!==S||o[u+3]!==M||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=x,o[u+2]=S,o[u+3]=M,o[u+4]=O,o[u+5]=E,!0):!1}else{const y=we(u),C=ve(u,r);let w=m,x=!1,S=!1;if(t){if(!w){const _=y/be+f/Pe,A=C/be+f/Pe;x=t.has(_),S=t.has(A),w=!x&&!S}}else x=!0,S=!0;const M=w||x,O=w||S;let E=!1;M&&(E=d(y,f,w));let v=!1;O&&(v=d(C,f,w));const T=E||v;if(T)for(let _=0;_<3;_++){const A=y+_,I=C+_,B=o[A],k=o[A+3],R=o[I],z=o[I+3];o[u+_]=B<R?B:R,o[u+_+3]=k>z?k:z}return T}}}function sh(c,t,e,i,s,n,r){ie.setBuffer(c._roots[t]),ar(0,c,e,i,s,n,r),ie.clearBuffer()}function ar(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ie,h=c*2;if(ce(h,o)){const u=Me(c,l),f=Ae(h,o);Gc(t,e,i,u,f,s,n,r)}else{const u=we(c);Rt(u,a,i,n,r)&&ar(u,t,e,i,s,n,r);const f=ve(c,l);Rt(f,a,i,n,r)&&ar(f,t,e,i,s,n,r)}}const nh=["x","y","z"];function rh(c,t,e,i,s,n){ie.setBuffer(c._roots[t]);const r=or(0,c,e,i,s,n);return ie.clearBuffer(),r}function or(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ie;let l=c*2;if(ce(l,a)){const d=Me(c,o),u=Ae(l,a);return qc(t,e,i,d,u,s,n)}else{const d=xr(c,o),u=nh[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=Rt(b,r,i,s,n)?or(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 S=Rt(y,r,i,s,n)?or(y,t,e,i,s,n):null;return w&&S?w.distance<=S.distance?w:S:w||S||null}}const Es=new D.Box3,oi=new at,li=new at,Vi=new D.Matrix4,$r=new ke,Os=new ke;function ah(c,t,e,i){ie.setBuffer(c._roots[t]);const s=lr(0,c,e,i);return ie.clearBuffer(),s}function lr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ie;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),$r.set(e.boundingBox.min,e.boundingBox.max,i),s=$r),ce(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,b=Me(c,a),y=Ae(o,r);if(Vi.copy(i).invert(),e.boundsTree)return ae(c,n,Os),Os.matrix.copy(Vi),Os.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Os.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let x=b,S=y+b;x<S;x++)if(pe(li,3*t.resolveTriangleIndex(x),d,u),li.needsUpdate=!0,w.intersectsTriangle(li))return!0;return!1}});{const C=dn(e);for(let w=b,x=y+b;w<x;w++){const S=t.resolveTriangleIndex(w);pe(oi,3*S,d,u),oi.a.applyMatrix4(Vi),oi.b.applyMatrix4(Vi),oi.c.applyMatrix4(Vi),oi.needsUpdate=!0;for(let M=0,O=C*3;M<O;M+=3)if(pe(li,M,f,m),li.needsUpdate=!0,oi.intersectsTriangle(li))return!0}}}else{const h=we(c),d=ve(c,a);return ae(h,n,Es),!!(s.intersectsBox(Es)&&lr(h,t,e,i,s)||(ae(d,n,Es),s.intersectsBox(Es)&&lr(d,t,e,i,s)))}}const _s=new D.Matrix4,_n=new ke,ji=new ke,oh=new D.Vector3,lh=new D.Vector3,ch=new D.Vector3,hh=new D.Vector3;function dh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),_n.set(t.boundingBox.min,t.boundingBox.max,e),_n.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=Ze.getPrimitive(),f=Ze.getPrimitive();let m=oh,b=lh,y=null,C=null;s&&(y=ch,C=hh);let w=1/0,x=null,S=null;return _s.copy(e).invert(),ji.matrix.copy(_s),c.shapecast({boundsTraverseOrder:M=>_n.distanceToBox(M),intersectsBounds:(M,O,E)=>E<w&&E<r?(O&&(ji.min.copy(M.min),ji.max.copy(M.max),ji.needsUpdate=!0),!0):!1,intersectsRange:(M,O)=>{if(t.boundsTree){const E=t.boundsTree;return E.shapecast({boundsTraverseOrder:v=>ji.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,A=v+T;_<A;_++){const I=E.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 R=c.resolveTriangleIndex(B);pe(u,3*R,l,o),u.needsUpdate=!0;const z=u.distanceToTriangle(f,m,y);if(z<w&&(b.copy(m),C&&C.copy(y),w=z,x=B,S=_),z<n)return!0}}}})}else{const E=dn(t);for(let v=0,T=E;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=_,S=v),B<n)return!0}}}}}),Ze.releasePrimitive(u),Ze.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(_s),b.applyMatrix4(_s),s.distance=b.sub(s.point).length(),s.faceIndex=S),i)}function Jr(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 Ps=new ke,As=new D.Ray,Qr=new D.Vector3,ea=new D.Matrix4,ta=new D.Vector3,Pn=["getX","getY","getZ"];class as extends Bc{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 as(e,{...i,[yr]:!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/Pe;m<b;m++){const y=be*m,C=2*y;ce(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[Pn[f]](h),b=r[Pn[f]](d),y=r[Pn[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,S=C+1,M=C+2;a&&(x=a[x],S=a[S],M=a[M]),o||(x=x*d+h,S=S*d+h,M=M*d+h);for(let O=0;O<3;O++){let E,v,T;o?(E=r[u[O]](x),v=r[u[O]](S),T=r[u[O]](M)):(E=l[x+O],v=l[S+O],T=l[M+O]);let _=E;v<_&&(_=v),T<_&&(_=T);let A=E;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)*Zs}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;ea.copy(t.matrixWorld).invert(),As.copy(e.ray).applyMatrix4(ea),ta.setFromMatrixScale(t.matrixWorld),Qr.copy(As.direction).multiply(ta);const n=Qr.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(As,s,r,a);o=Jr(o,t,e),o&&i.push(o)}else{const o=this.raycast(As,s,r,a);for(let l=0,h=o.length;l<h;l++){const d=Jr(o[l],t,e);d&&i.push(d)}}return i}refit(t=null){return(this.indirect?ih:Hc)(this,t)}raycast(t,e=D.FrontSide,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?sh:Yc;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?rh:Zc;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?ah:Kc;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=Ze.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Wc:Nc});return Ze.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=Ze.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=Ze.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 as))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const m=(b,y,C,w,x,S,M,O)=>{for(let E=C,v=C+w;E<v;E++){f(E),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,E,x,S,M,O))return!0}return!1};if(s){const b=s;s=function(y,C,w,x,S,M,O,E){return b(y,C,w,x,S,M,O,E)?!0:m(y,C,w,x,S,M,O,E)}}else s=m}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return Ps.set(t.min,t.max,e),Ps.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Ps.intersectsBox(i),intersectsTriangle:i=>Ps.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?dh:th)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Fc(this,t,e,i,s)}}const yi={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},Te=new D.Mesh,Is=[];function uh(c,t){if(this.isBatchedMesh)fh.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=yi.Mesh;else if(this instanceof D.LineSegments)i=yi.LineSegments;else if(this instanceof D.LineLoop)i=yi.LineLoop;else if(this instanceof D.Line)i=yi.Line;else if(this instanceof D.Points)i=yi.Points;else throw new Error("BVH: Fallback raycast function not found.");i.call(this,c,t)}}}function fh(c,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,n=this.matrixWorld;Te.material=this.material,Te.geometry=this.geometry;const r=Te.geometry.boundsTree,a=Te.geometry.drawRange;Te.geometry.boundingSphere===null&&(Te.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(Te.geometry.boundsTree=e[h],this.getMatrixAt(o,Te.matrixWorld).premultiply(n),!Te.geometry.boundsTree){this.getBoundingBoxAt(h,Te.geometry.boundingBox),this.getBoundingSphereAt(h,Te.geometry.boundingSphere);const d=s[h];Te.geometry.setDrawRange(d.start,d.count)}Te.raycast(c,Is);for(let d=0,u=Is.length;d<u;d++){const f=Is[d];f.object=this,f.batchId=o,t.push(f)}Is.length=0}Te.geometry.boundsTree=r,Te.geometry.drawRange=a,Te.material=null,Te.geometry=null}else yi.BatchedMesh.call(this,c,t)}D.Mesh.prototype.raycast=uh;const Bs=new p.Sphere,ks=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(),Bs.copy(e.boundingSphere),Bs.applyMatrix4(i),Bs.radius+=s,c.ray.intersectsSphere(Bs)===!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(ks.fromBufferAttribute(l,b).applyMatrix4(i),ia(ks,b,r,c,t,this),t.length-h>=vi)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(ks.fromBufferAttribute(l,f).applyMatrix4(i),ia(ks,f,r,c,t,this),t.length-h>=vi)return}};function ia(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 ph=p.Points,mh=`
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
- `,Ka=`
143
+ `,gh=`
144
144
  attribute int tileObjectId;
145
145
  flat varying int vTileObjectId;
146
- `,$a=`
146
+ `,yh=`
147
147
  vTileObjectId = tileObjectId;
148
- `,Ja=`
148
+ `,xh=`
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
- `,Qa=`
156
+ `,bh=`
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
- `,eo=`
163
+ `,wh=`
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
- `,to=`
177
+ `,vh=`
178
178
  #ifdef USE_BC_OUTLINE
179
179
  attribute float barycentric;
180
180
  varying vec3 vBarycentric;
181
181
  #endif
182
- `,io=`
182
+ `,Mh=`
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
- `,so=`
191
+ `,Th=`
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
- `,ro=`
228
+ `,Ch=`
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
- `,no=`
246
+ `,Sh=`
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
- `,ao=`
264
+ `,Eh=`
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
- `,oo=`
324
+ `,Oh=`
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
- `,lo=`
490
+ `,_h=`
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
- `,ho=`
507
+ `,Ph=`
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
- `,we=d.ShaderChunk;we.outline_bc_vertex=Ja;we.outline_bc_fragment=Qa;we.outline_bc_pars_fragment=eo;we.outline_bc_pars_vertex=to;we.standard_ex_vertex=ao;we.standard_ex_fragment=oo;we.common_ex=Za;we.id_pars_vertex=Ka;we.id_vertex=$a;we.state_pars_fragment=io;we.state_fragment=so;we.state_transparent_fragment=ro;we.state_highlight_fragment=no;we.pick_ex_vertex=lo;we.pick_ex_fragment=ho;const co=d.ShaderChunk;class uo{constructor(t){p(this,"promise");p(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 fo=Ws.default??Ws,S=fo;S.setLevel("warn");const nn=h=>{try{S.setLevel(h)}catch(t){S.setLevel("error"),S.error(t)}},Vt=class Vt{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),r=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),n=/(?:iPhone)/.test(t)&&!r,a=!n&&!e,o=Vt.isTouchScreenDevice();e&&S.debug("[DI] is android"),i&&S.debug("[DI] is fireFox"),s&&S.debug("[DI] is chrome"),r&&S.debug("[DI] is tablet"),n&&S.debug("[DI] is iPhone"),a&&S.debug("[DI] is PC"),o&&S.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:()=>{}}}};p(Vt,"isMobile",/mobile/i.test(navigator.userAgent)),p(Vt,"isBrowser",typeof document<"u"),p(Vt,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let be=Vt;const Ut=class Ut{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 d.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 d.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof d.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new d.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof d.Vector3)return t;if(t instanceof d.Vector2)return new d.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new d.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new d.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 d.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 d.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,r=(t.max.y-t.min.y)*e,n=(t.max.z-t.min.z)*e,a=new d.Vector3(i.x-s/2,i.y-r/2,i.z-n/2),o=new d.Vector3(i.x+s/2,i.y+r/2,i.z+n/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new d.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,r=t.max.y-t.min.y,n=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),r<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),n<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 r=Math.max(e.min.x,0),n=Math.max(e.min.y,0),a=Math.max(e.max.x-r,0),o=Math.max(e.max.y-n,0),l=t.getImageData(r,n,a,o),c=document.createElement("canvas");return c.width=a,c.height=o,c.getContext("2d").putImageData(l,0,0),c.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!be.isBrowser)return;const e=performance.memory;if(!e){S.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),r=(e.usedJSHeapSize/(1024*1024)).toFixed(2);S.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+r+"M ")}static printGpuInfo(t){if(!be.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);S.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ut.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,r=Date.now();r-e>s&&(await Ut.sleep(0),e=r)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async r=>{if(e&&(r%i===0||r===t-1)){e(new ProgressEvent("",{loaded:r+1,total:t}));const n=500,a=Date.now();(a-s>n||r===t-1)&&(await Ut.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return r=>{let n=r.loaded*100/r.total;n=n*(e-t)/100+t,n>e&&(s||(S.warn("[Progress] Invalid ProgressEvent:",r),s=!0),n=e),i&&i(new ProgressEvent(r.type,{loaded:n,total:100}))}}};p(Ut,"twinklingObjectIds",{});let z=Ut;const po=(h,t,e)=>{const{default:i,active:s}=t;e?(h.remove(i),h.add(s||i)):(s&&h.remove(s),h.add(i))};class qt{static color2rgba(t){let e=[0,0,0,1],i;if(i=/^(\w+)\(([^)]*)\)/.exec(t)){let s;const r=i[1],n=i[2];switch(r){case"rgb":case"rgba":(s=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))&&(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(n))&&(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(n))&&(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],r=s.length;if(r===3)e=[parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,1];else if(r===6){const n=parseInt(s,16);e=[(n>>16&255)/255,(n>>8&255)/255,(n&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]),r=t[3]!=null?t[3]:1;return"rgba("+e+","+i+","+s+","+r+")"}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 pe{static getScreenCoordinateByEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.clientX-s,i.y=t.clientY-r,i}static getScreenCoordinateByTouchEvent(t,e){const i=new d.Vector2,{left:s,top:r}=e.getBoundingClientRect();return i.x=t.touches[0].clientX-s,i.y=t.touches[0].clientY-r,i}static world2Screen(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=t.clone(),a=new d.Vector2;return n.project(e),a.x=Math.round((.5+n.x/2)*s),a.y=Math.round((.5-n.y/2)*r),a}static worldBBox2Screen(t,e,i){const s=new d.Box2,r=t.min,n=t.max,a=(o,l,c)=>{const u=new d.Vector3(o,l,c),f=this.world2Screen(u,e,i);s.expandByPoint(f)};return a(r.x,r.y,r.z),a(r.x,r.y,n.z),a(r.x,n.y,r.z),a(r.x,n.y,n.z),a(n.x,r.y,r.z),a(n.x,r.y,n.z),a(n.x,n.y,r.z),a(n.x,n.y,n.z),s}static screen2World(t,e,i){const s=pe.screen2Ndc(t,e,i);return new d.Vector3(s.x,s.y,1).unproject(e)}static screen2Ndc(t,e,i){const{clientWidth:s,clientHeight:r}=i,n=new d.Vector2;return n.x=t.x/s*2-1,n.y=-(t.y/r)*2+1,n}static world2NormalizedScreen(t,e,i){const s=new d.Vector3,r=t instanceof d.Vector2?0:t.z;s.set(t.x,t.y,r);const n=pe.world2Screen(s,e,i);return n.x/=i.clientWidth,n.y/=i.clientHeight,n}}class mo{static createCSS2DObject(t){const e=new rn.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 an={"Precision from file":99},go=(h,t)=>h.toFixed(t===an["Precision from file"]?2:t),on="en",Ne=!1,ln=10,Ce=11,ft=12,Bs=583902,yo=[.031,.906,.867,.5],Vi=[.3,.3,.3,.8],Ls=.5,Ui=.1,Hi=5e3,hn=45,xo="x-viewer-iconfont",bo="x-viewer-iconfont2",Rs=10,Ks=new d.Vector3,$s=new d.Vector3,Js=new d.Vector3,ai=new d.Vector3,st=new d.Vector3,Qs=new d.Triangle;function vo(h,t,e,i,s){const r=[],n={};let a,o,l,c;const f=Math.pow(10,4);let m,g,x=0;for(m=0,g=h.length;m<g;m+=3)a=h[m],o=h[m+1],l=h[m+2],c=Math.round(a*f)+"_"+Math.round(o*f)+"_"+Math.round(l*f),!n[c]&&(n[c]=x/3,e[x++]=a,e[x++]=o,e[x++]=l),r[m/3]=n[c];for(m=0,g=t.length;m<g;m++)s[m]=r[t[m]],i[s[m]]=t[m]}function wo(h,t,e,i){for(let s=0,r=h;s<r;s+=3){const n=t[s]*3,a=t[s+1]*3,o=t[s+2]*3;Ks.set(e[n],e[n+1],e[n+2]),$s.set(e[a],e[a+1],e[a+2]),Js.set(e[o],e[o+1],e[o+2]),d.Triangle.getNormal(Ks,$s,Js,ai),i.push({normal:ai.clone()})}}const ss=[new d.Vector3(1,0,0),new d.Vector3(0,1,0),new d.Vector3(0,0,1),new d.Vector3(1,1,0),new d.Vector3(0,1,1),new d.Vector3(1,0,1),new d.Vector3(1,1,1),new d.Vector3(0,0,0)];function Mo(h,t){return st.addVectors(h,t),st.x===0||st.y===0||st.z===0}class cn{static buildEdge(t,e,i=Rs){const s=[],r=[],n=[];vo(t,e,s,r,n);const a=[];wo(e.length,n,s,a);const o=[],l=Math.cos(d.MathUtils.DEG2RAD*i),c={};let u=!1;for(let f=0,m=e.length;f<m;f+=3){const g=f/3;for(let x=0;x<3;x++){const y=n[f+x],T=n[f+(x+1)%3],v=Math.min(y,T),b=Math.max(y,T),E=v+","+b;c[E]===void 0?c[E]={index1:v,index2:b,face1:g,face2:void 0}:c[E].face2=g}}for(const f in c){const m=c[f];if(m.face2!==void 0){const y=a[m.face1].normal,T=a[m.face2].normal;if(y.dot(T)>l)continue}const g=r[m.index1],x=r[m.index2];(!u&&g>65535||x>65535)&&(u=!0),o.push(g),o.push(x)}return u?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),r=Math.cos(d.MathUtils.DEG2RAD*20),n=t.getIndex(),a=n?n.count:e.count,o=[0,0,0],l=new Array(3),c=ss.length,u=[];for(let M=0;M<e.count;M++)u.push({point:new d.Vector3(1,1,1),inited:!1,barycentricIndex:-1});const f={},m={},g={},x={};for(let M=0;M<a;M+=3){n?(o[0]=n.getX(M),o[1]=n.getX(M+1),o[2]=n.getX(M+2)):(o[0]=M,o[1]=M+1,o[2]=M+2);const{a:P,b:A,c:I}=Qs;if(P.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),Qs.getNormal(ai),g[o[0]]?l[0]=g[o[0]]:(l[0]=Math.round(P.x*s)+","+Math.round(P.y*s)+","+Math.round(P.z*s),g[o[0]]=l[0]),g[o[1]]?l[1]=g[o[1]]:(l[1]=Math.round(A.x*s)+","+Math.round(A.y*s)+","+Math.round(A.z*s),g[o[1]]=l[1]),g[o[2]]?l[2]=g[o[2]]:(l[2]=Math.round(I.x*s)+","+Math.round(I.y*s)+","+Math.round(I.z*s),g[o[2]]=l[2]),l[0]===l[1]||l[1]===l[2]||l[2]===l[0]){S.warn(" skip degenerate triangles in geometry!");continue}const k={a:o[0],b:o[1],c:o[2]};!m[o[0]]&&(m[o[0]]=[]),m[o[0]].push(k),!m[o[1]]&&(m[o[1]]=[]),m[o[1]].push(k),!m[o[2]]&&(m[o[2]]=[]),m[o[2]].push(k);for(let B=0;B<3;B++){const L=(B+1)%3,q=l[B],me=l[L],ue=o[B],nt=o[L];!f[ue]&&(f[ue]=new Set),f[ue].add(nt),!f[nt]&&(f[nt]=new Set),f[nt].add(ue);const es=q+"_"+me,gt=me+"_"+q;if(gt in x&&x[gt]){if(x[gt].outer){S.warn("[Edge] edge: "+gt+" is already outer!");continue}ai.dot(x[gt].normal)<=r?x[gt].outer=!0:x[gt].find=!0}else es in x?S.warn("[Edge] "+es+" has existed in geometry!"):x[es]={startIndex:ue,endIndex:nt,normal:ai.clone(),outer:!1,find:!1}}}for(const M in x)x[M]&&!x[M].find&&!x[M].outer&&(x[M].outer=!0);const y=[],T=[];for(const M in m)T.push(m[M]);let v=new Set;for(const M of T[0])v.add(M.a),v.add(M.b),v.add(M.c);let b=0;for(T.splice(b,1);;){let M=!1;for(let P=0;P<T.length&&!M;P++)for(const A of T[P])if(v.has(A.a)||v.has(A.b)||v.has(A.c)){b=P,M=!0;break}if(M){for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);if(T.splice(b,1),b=0,T.length===0){y.push(v);break}}else if(!M)if(y.push(v),T.length>0){v=new Set;for(const P of T[b])v.add(P.a),v.add(P.b),v.add(P.c);T.splice(b,1),b=0}else break}const E=new Set;for(let M=0;M<y.length;M++)y[M].forEach(A=>{E.has(A)?S.warn("[Edge] "+A+" is already in positionIndexSet!"):E.add(A)});const O=(M,P)=>{let A=!1;const I=g[M];if(!I)return console.warn(M+" is not in positionIndexHash!"),A;const k=g[P];if(!k)return console.warn(P+" is not in positionIndexHash!"),A;const B=I+"_"+k;if(x[B])A=x[B].outer;else{const L=k+"_"+I;x[L]&&(A=x[L].outer)}return A},_=(M,P,A)=>{const I=[];return I.push(O(M,P)),I.push(O(P,A)),I.push(O(A,M)),I.filter(k=>k===!0).length>=2},C=(M,P)=>{if(!f[M])return S.warn("[Edge] "+M+" position isn't used!"),!0;const A=f[M];for(const k of A){const B=O(M,k),L=u[k];if(!L.inited)continue;const q=Mo(P,L.point);if(B&&!q||!B&&q)return!1}const I=m[M];for(const k of I){const B=P;let L=u[k.b],q=u[k.c];if(k.b===M?L=u[k.a]:k.c===M&&(q=u[k.a]),_(k.a,k.b,k.c)&&(L.inited&&B.equals(L.point)||q.inited&&B.equals(q.point)))return!1;if(!(!L.inited||!q.inited)&&(st.addVectors(B,L.point),st.add(q.point),st.x+st.y+st.z<2))return!1}return!0};let w=!1;for(let M=0;M<y.length;M++){const P=Array.from(y[M]);w=!1;let A=0,I=0;for(;I>=0;){A=P[I];let k=u[A].inited?u[A].barycentricIndex+1:0;for(;k<c&&!C(A,ss[k]);k++);if(k<c)if(u[A].inited=!0,u[A].barycentricIndex=k,u[A].point.copy(ss[k]),I==P.length-1){w=!0,S.debug("[Edge]",u);break}else I++;else u[A].inited=!1,I--}if(!w){S.warn("[Edge] no result: "+P+"!");break}}if(w){const M=[];for(let A=0;A<u.length;A++){!u[A].inited&&S.warn("[Edge] "+A+" is not initialized !");let I=0;I|=u[A].point.x,I|=u[A].point.y<<1,I|=u[A].point.z<<2,M.push(I)}const P=new d.Uint8BufferAttribute(M,1,!1);t.setAttribute("barycentric",P)}else S.warn("[Edge] No suitable barycentric found!");return w}}class mt{constructor(){p(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(r=>r(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 X=class X{static exportToGltf(t,e){X.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){X.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new oa.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,n=>{if(i.binary){e=X.addExtention(e,X.EXTENSION_GLB);const a=n;X.saveArrayBuffer(a,e)}else e=X.addExtention(e,X.EXTENSION_GLTF),X.saveJson(n,e)},n=>console.log(n),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_OBJ);const i=new la.OBJExporter,s=i.parse(t);X.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_DRACO);const s=new aa.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const n=s.parse(t,i);X.saveArrayBuffer(n,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=X.addExtention(e,X.EXTENSION_STL);const s=new ha.STLExporter;if(i){const r={binary:!0},n=s.parse(t,r);X.saveDataView(n,e)}else{const r=s.parse(t);X.saveString(r,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(X.EXTENSION_JSON)||(e+=X.EXTENSION_JSON),X.saveJson(i,e)}static save(t,e){let i=X.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),X.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){X.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){X.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){X.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){X.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};p(X,"EXTENSION_GLTF",".gltf"),p(X,"EXTENSION_GLB",".glb"),p(X,"EXTENSION_OBJ",".obj"),p(X,"EXTENSION_DRACO",".drc"),p(X,"EXTENSION_JSON",".json"),p(X,"EXTENSION_STL",".stl"),p(X,"downloadLink");let Ss=X;class To{constructor(){p(this,"prevTime");p(this,"beginTime");p(this,"frames");p(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 rs=1e-15,er=new d.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),tr=new d.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class R{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 R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return R.areNumbersEqual(t.x,e.x,i)&&R.areNumbersEqual(t.y,e.y,i)&&R.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 R.areNumbersClose(t,e,rs)?0:(t%=i,R.areNumbersClose(t,e%i,rs)?i:(R.areNumbersClose(e,i,rs)&&(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=R.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(R.getRelativeEps(t.x,e),R.getRelativeEps(t.y,e))}static getControlPointByTwoPoints(t,e){const i=new d.Vector2().subVectors(e,t),s=i.angle(),r=i.length(),n=d.MathUtils.degToRad(45),a=r/2/Math.cos(n);return new d.Vector2(t.x+a*Math.cos(n-s),t.y-a*Math.sin(n-s))}static convertPointFromUEToGltf(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(er),e}static convertPointFromUEToRevit(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new d.Vector3(t.x,t.y,t.z);return e.applyMatrix4(tr),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 d.Vector3(t.min.x,t.min.y,t.min.z),i=new d.Vector3(t.max.x,t.max.y,t.max.z),s=new d.Vector3().addVectors(e,i).multiplyScalar(.5);return{x:s.x,y:s.y,z:s.z}}static convertBoxFromGltfToUE(t){const e=R.convertPointFromGltfToUE(t.min),i=R.convertPointFromGltfToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=R.convertPointFromUEToGltf(t.min),i=R.convertPointFromUEToGltf(t.max);return R.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=R.convertPointFromRevitToUE(t.min),i=R.convertPointFromRevitToUE(t.max);return R.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=R.convertPointFromUEToRevit(t.min),i=R.convertPointFromUEToRevit(t.max);return R.getBox(e,i)}static clamp(t,e,i){return Math.max(e,Math.min(i,t))}static getLookAtMatrix(t,e,i){const s=new d.Matrix4,r=new d.Vector3(t.x,t.y,t.z),n=new d.Vector3(e.x,e.y,e.z),a=new d.Vector3(i.x,i.y,i.z);s.lookAt(r,n,a),s.transpose();const o=[];return s.toArray(o),o}static getLocationFromMatrix(t){const e=new d.Vector3;return e.setFromMatrixPosition(t),e}static toDegrees(t){return d.MathUtils.radToDeg(t)}static toRadians(t){return d.MathUtils.degToRad(t)}static signNotZero(t){return t<0?-1:1}static fromSnorm(t,e){return R.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=R.fromSnorm(t.x,i),e.y=R.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))*R.signNotZero(s),e.y=(1-Math.abs(s))*R.signNotZero(e.y)}}}const ns=1e7,ir=new d.Box2,sr=new d.Box2,rr=new d.Vector3,nr=new d.Vector3,ar=new d.Vector3,at=new d.Triangle;class U{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 r=0;r<i.length;++r){if(i[r]!==s[r])return!1;const n=t[i[r]],a=e[s[r]];if(!this.bufferAttributesEqual(n,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 n=0;n<t.array.length;++n)if(t.array[n]!==e.array[n])return!1}else if(t.array||e.array)return!1;const s=t.data,r=e.data;if(s&&r){if(s.length!==r.length)return!1;for(let n=0;n<s.length;++n)if(s[n]!==r[n])return!1}else if(s||r)return!1;return!0}static tryConvertInterleavedBufferAttributes(t){!t||!t.attributes||Object.keys(t.attributes).forEach(e=>{const i=t.attributes[e];if(i instanceof d.InterleavedBufferAttribute){const s=i.clone();t.attributes[e]=s}})}static isPointInPolygon(t,e,i=!1){const s=t.x,r=t.y;let n=!1;const a=e.length;for(let o=0,l=a-1;o<a;l=o++){const c=e[o].x,u=e[o].y,f=e[l].x,m=e[l].y;let g=u>r!=m>r;i&&(g=u>=r!=m>=r),g&&s<(f-c)*(r-u)/(m-u)+c&&(n=!n)}return n}static caculateGeometryCenter(t){if(!t.hasAttribute("position"))return null;const e=t.getAttribute("position");if(e.count===0)return null;const i=new d.Vector3,s=e.itemSize,r=e.array,n=[0,0,0];for(let a=0;a<e.count;a++)for(let o=0;o<s;o++)n[o]+=r[a*s+o];for(let a=0;a<s;a++)i.setComponent(a,n[a]/e.count);return i}static isConvex(t){const e=t.length;let i=0,s=0;const r=new d.Vector2,n=new d.Vector2;for(let a=0;a<e;++a){const o=t[a],l=t[(a+1)%e],c=t[(a+2)%e];if(r.subVectors(l,o),n.subVectors(c,l),s=r.cross(n),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:r,end:n}=e,a=r.clone().sub(i),o=s.clone().sub(i),l=n.clone().sub(i),c=a.cross(o).dot(l.cross(o)),u=i.clone().sub(r),f=n.clone().sub(r),m=s.clone().sub(r),g=u.cross(f).dot(m.cross(f));return c<0&&g<0}static getLineSegmentsIntersectingPoint(t,e){const{start:i,end:s}=t,{start:r,end:n}=e,a=rr.subVectors(s,i).normalize(),o=nr.subVectors(n,r).normalize();if(a.dot(o)===1)return null;const l=ar.subVectors(r,i),c=a.clone().cross(o),u=l.clone().cross(o),f=l.clone().dot(c);if(f>=1e-5||f<=-1e-5)return null;const m=c.lengthSq();if(R.areNumbersEqual(0,m))return;const g=u.clone().dot(c)/m,x=i.clone().add(a.multiplyScalar(g));return x.equals(i)||x.equals(s)?null:x}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:r}=e,n=rr.subVectors(s,r).length(),a=nr.subVectors(t,s).length(),o=ar.subVectors(t,r).length();return Math.abs(n-(a+o))<=i}static isPointOnLineSegments(t,e,i=.001){let s=!1;for(let r=0;r<e.length-1;r+=2){const n=e[r],a=e[r+1];if(s=this.isPointOnLineSegment(t,{start:n,end:a},i),s)break}return s}static checkAndRebasePositionsOnRTC(t,e){if(t.length===0)return!1;const i=t[0]instanceof d.Vector3;t.forEach(r=>{i?e.add(r):(e.x+=r.x,e.y+=r.y)}),e.divideScalar(t.length);let s=!1;if(U.shouldRebasePositionOnRTC(e)){s=!0;for(let r=0;r<t.length;r++){const n=t[r].x-e.x,a=t[r].y-e.y;i?t[r]=new d.Vector3(n,a,t[r].z-e.z):t[r]=new d.Vector2(n,a)}}else e.setScalar(0);return s}static shouldRebasePositionOnRTC(t){return Math.abs(t.x)>ns||Math.abs(t.y)>ns||t instanceof d.Vector3&&Math.abs(t.z)>ns}static calculateSurfaceArea(t){let e=0;const i=t.getAttribute("position"),s=t.index;if(s)for(let r=0;r<s.count;r+=3)at.a.fromBufferAttribute(i,s.getX(r)),at.b.fromBufferAttribute(i,s.getX(r+1)),at.c.fromBufferAttribute(i,s.getX(r+2)),e+=at.getArea();else for(let r=0;r<i.count;r+=3)at.a.fromBufferAttribute(i,r),at.b.fromBufferAttribute(i,r+1),at.c.fromBufferAttribute(i,r+2),e+=at.getArea();return e}static convertLineStripToLine(t,e=!1){const i=t.getIndex();if(!i)return;const s=i.array.constructor,r=i.count;let n=r;r>2&&(n=e?r*2:r*2-2);const a=new s(n);let o=0;for(let l=0;l<r;l++){const c=i.getX(l);a[o++]=c,l>0&&l<r-1&&(a[o++]=c)}e&&(a[o++]=i.getX(r-1),a[o++]=i.getX(0)),t.setIndex(a)}static convertGeometryWithIndexedToNonIndexed(t){if(!t.index)return t;const e=new d.BufferGeometry,i=t.index;for(const s in t.attributes)e.setAttribute(s,U.createGeometryAttributeByIndex(t.attributes[s],i));return e}static createGeometryAttributeByIndex(t,e){const i=e.count,s=t.itemSize,r=t.array.constructor,n=new r(i*s);for(let a=0;a<i;a++){const o=e.getX(a),l=o*s;for(let c=0;c<s;c++)n[a*s+c]=t.array[l+c]}return new d.BufferAttribute(n,s,t.normalized)}static getLineEndPointsByIndex(t,e){const i=l=>{const c=t.geometry.attributes.position,u=c.array;return t.localToWorld(new d.Vector3(u[3*l],u[3*l+1],u[3*l+2]))};t.updateWorldMatrix(!0,!1);const s=t.geometry.getIndex()?.array||[],r=s[e]??e,n=s[e+1]??e+1,a=i(r),o=i(n);return[a,o]}static arePolygonsIntersect(t,e){if(t.length===0||e.length===0||(ir.setFromPoints(t),sr.setFromPoints(e),!ir.intersectsBox(sr)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&R.areVector2sEqual(t[i+1],t[i])&&++i,++i}return!1}static getLineLineIntersectionPoint(t,e,i,s,r=.001){const n=e.clone().sub(t).normalize(),a=s.clone().sub(i).normalize();if(Math.abs(n.dot(a))>1-r)return;const o=e.y-t.y,l=t.x-e.x,c=o*t.x+l*t.y,u=s.y-i.y,f=i.x-s.x,m=u*i.x+f*i.y,g=o*f-u*l;if(Math.abs(g)<r)return;const x=(f*c-l*m)/g,y=(o*m-u*c)/g;return new d.Vector2(x,y)}static getOffsetPoint(t,e,i){const s=e.x-t.x,r=e.y-t.y,n=Math.sqrt(s*s+r*r),a=i/n;return new d.Vector2(-a*r,a*s)}static convertSimpleWidthLineToMeshGeometry(t,e){let i,s=!1,r=!1,n=[],a=[],o,l,c=new d.Vector2,u=new d.Vector2,f=new d.Vector2,m=new d.Vector2;const g=[],x=e/2;for(let b=0,E=t.length-1;b<E;b++)s=!b,r=b===t.length-2,i=this.getOffsetPoint(t[b],t[b+1],x),c=new d.Vector2(t[b].x+i.x,t[b].y+i.y),u=new d.Vector2(t[b+1].x+i.x,t[b+1].y+i.y),f=new d.Vector2(t[b].x-i.x,t[b].y-i.y),m=new d.Vector2(t[b+1].x-i.x,t[b+1].y-i.y),s||(o=this.getLineLineIntersectionPoint(n[0],n[1],c,u),o!==void 0?g.unshift(o):g.unshift(c),l=this.getLineLineIntersectionPoint(a[0],a[1],f,m),l!==void 0?g.push(l):g.push(f)),s&&(g.unshift(c),g.push(f)),r&&(g.unshift(u),g.push(m)),r||(n=[c,u],a=[f,m]);if(g.length<3)return;const y=d.ShapeUtils.triangulateShape(g,[]),T=[];for(let b=0;b<y.length;b++)T.push(...y[b]);const v=new d.BufferGeometry().setFromPoints(g);return v.setIndex(T),v}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:r}=ca.extrudePolylines([i],{lineWidth:e,depth:1}),n=new d.BufferGeometry;return n.setAttribute("position",new d.Float32BufferAttribute(r,3)),n.setIndex(Array.from(s)),n}catch{return}}static releaseGeometryManually(t){t.index=null,t.attributes={}}static getAdjacentNonRepeatPoints(t,e=1e-7){const i=[],s=t.length;for(let r=0;r<s-1;r++)R.areVector3sEqual(t[r],t[r+1],e)||i.push(t[r]);return i.push(t[s-1]),i}static mergeBBoxes(t){const e=[...t];if(e.length<2)return e;const i=[],s=[];for(let r=0;r<e.length;r++){const n=e[r];if(!s.includes(r)){for(let a=0;a<e.length;a++){const o=e[a];n.equals(o)||n.intersectsBox(o)&&(n.union(o),s.push(a))}i.push(n)}}return i}}const Co={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"}},Os={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"}},Re=da.createInstance(),So="cn";Re.init({lng:So,debug:!1,resources:{en:{translation:Os},cn:{translation:Os}}});class de{static materialEquals(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t instanceof d.Material&&e instanceof d.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 d.Material&&e instanceof d.Material)return this.materialEquals(t,e);return!1}static colorEquals(t,e){return t===e?!0:t instanceof d.Color&&e instanceof d.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(r=>{s.push(this.clonedHighlightMaterial(r,e))}),s}else{if(i instanceof d.Material)return this.clonedHighlightMaterial(i,e);console.warn("[MaterialUtils] Invalid material: "+i)}}static clonedHighlightMaterial(t,e={}){const{depthTest:i=void 0,highlightColor:s=new d.Color(Bs),opacity:r=.7}=e,n=t.clone();return this.setMaterialColor(n,s),n.opacity=r,n.transparent=!0,i!==void 0&&(n.depthTest=i,n.side=d.DoubleSide),n}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 d.Color(16777215);return t instanceof d.PointsMaterial||t instanceof d.LineBasicMaterial||t instanceof d.MeshBasicMaterial?e=t.color:t instanceof d.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 r=[];return s.forEach(n=>{let a=e.get(n);a||(a=n.clone(),e.set(n,a)),r.push(a)}),r}if(s){let r=e.get(s);return r||(r=s.clone(),e.set(s,r)),r}return s};t.traverse(s=>{const r=s;r.material&&(r.material=i(r.material))})}}const Oo=new d.Vector3(0,1,0),ke=class ke{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 r=[],n=o=>{r.find(l=>l.id===o.id)||(r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side}),o.opacity*=e,o.transparent=!0,o.side=d.DoubleSide)},a=o=>{const l=r.find(c=>c.id===o.id);if(!l){const c=o.clone();return r.push({id:o.id,opacity:o.opacity,transparent:o.transparent,side:o.side,material:o,clonedMaterial:c}),c.opacity*=e,c.transparent=!0,c}return l.clonedMaterial};return t.traverse(o=>{if(!(s&&s.indexOf(o.id)!==-1)&&!(i&&i.indexOf(o.id)===-1)&&o instanceof d.Mesh){const l=o;if(i||s){if(Array.isArray(l.material)){const c=[];l.material.forEach(u=>{const f=a(u);f&&c.push(f)}),l.material=c}else if(l.material){const c=a(l.material);c&&(l.material=c)}}else if(Array.isArray(l.material))l.material.forEach(c=>{n(c)});else if(l.material){const c=l.material;n(c)}}}),r}static revertObjectOpacity(t,e,i,s){const r=new Set,n=o=>{if(!o||o.id==null||r.has(o.id))return;r.add(o.id);const l=e.find(c=>c.id===o.id);l&&(o.opacity=l.opacity,o.transparent=l.transparent,o.side=l.side,o.opacity===0&&S.warn("[ObjectUtils] Material '"+o.name+"'s opacity is 0, you may not be able to see your objects!"))},a=o=>{const l=e.find(c=>c.clonedMaterial&&c.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 d.Mesh){if(Array.isArray(o.material)){const l=[];o.material.forEach(c=>{const u=a(c);u?l.push(u):n(c)}),o.material=l}else if(o.material){const l=a(o.material);l?o.material=l:n(o.material)}}})}static setObjectOpacityById(t,e,i=.3,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);return ke.setObjectOpacity(n,i,s,r)}static revertObjectOpacityById(t,e,i,s,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);ke.revertObjectOpacity(n,i,s,r)}static applyMaterialToObject(t,e,i,s){t.traverse(r=>{s&&s.indexOf(r.id)!==-1||i&&i.indexOf(r.id)===-1||r instanceof d.Mesh&&(r.userData.originalMaterial||(r.userData.originalMaterial=r.material),r.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,r){const n=t.getObjectById(e);if(!n)throw new Error("Failed to find object by id: "+e);this.applyMaterialToObject(n,i,s,r)}static revertAppliedMaterialToObjectById(t,e,i,s){const r=t.getObjectById(e);if(!r)throw new Error("Failed to find object by id: "+e);this.revertAppliedMaterialToObject(r,i,s)}static applyOpacityMaterialToObject(t,e,i){const s=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});this.applyMaterialToObject(t,s,e,i)}static setDoubleSidedMaterialToObject(t){const e=i=>{i.side!==d.DoubleSide&&(i.userData.originalSide==null&&(i.userData.originalSide=i.side),i.side=d.DoubleSide)};t.traverse(i=>{i instanceof d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.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 d.Mesh&&(Array.isArray(i.material)?i.material.forEach(s=>{e(s)}):i.material instanceof d.Material&&e(i.material))})}static setWireframeMode(t){const e=new d.MeshBasicMaterial({color:16732160,wireframe:!0,transparent:!0,opacity:.8});t.traverseVisible(i=>{if(i instanceof d.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);ke.setWireframeMode(i)}static revertWireframeMode(t){t.traverseVisible(e=>{e instanceof d.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);ke.revertWireframeMode(i)}static findInner(t,e,i=[],s=!1){const r=e.toLowerCase(),n=[],a=c=>c.toLowerCase().indexOf(r)!==-1,o=c=>c.toString().indexOf(r)!==-1,l=c=>{if(c.name&&c.name.toLowerCase().indexOf(r)!==-1)return!0;if(c.gltfExtensions){const u=c.gltfExtensions,f=u.objectId&&u.objectId.Value||u.elementId&&u.elementId.Value;if(f&&f.toLowerCase().indexOf(r)!==-1)return!0}return!1};if(i.length>0)for(let c=0;c<i.length;++c){const u=i[c],f=t.getObjectById(u);if(f&&f.traverse(m=>{(a(m.name)||o(m.id)||l(m.userData))&&n.push(m)}),s&&n.length>0)return[n[0]]}else if(t.traverse(c=>{(a(c.name)||o(c.id)||l(c.userData))&&n.push(c)}),s&&n.length>0)return[n[0]];return n}static find(t,e,i=[],s=!1){return this.findInner(t,e,i,s)}static findFirst(t,e,i=[],s=!1){const r=this.findInner(t,e,i,s);if(r.length>0)return r[0]}static getFloorsFromString(t){const e=[],s=new RegExp(/(?:-?(?:\d+(?:\.5)?)F)(?=\W|$)/,"g").exec(t);return s&&s.length>0&&s.forEach(r=>{if(r){const n=r.replace("F",""),a=Number(n);a?e.push(a):console.log("[OU] invalid floor: "+r)}}),e}static matchFloor(t,e){return this.getFloorsFromString(t).findIndex(r=>r===e)!==-1}static matchFloors(t,e){return this.getFloorsFromString(t).findIndex(r=>e.findIndex(a=>a===r)!==-1)!==-1}static distinctFloors(t,e){const i=[],s=r=>{this.getFloorsFromString(r).forEach(a=>{i[a]=!0})};return e.forEach(r=>{const n=t.getObjectById(r);n&&n.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,r){const n=t.getObjectById(e);if(!n)return[];n.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&&r&&r(a)})}static setVisibleForFloors(t,e,i,s=!0){this.traverseObjectByFloors(t,e,i,r=>{let n=r;for(;n;)n.visible=!0,n=n.parent||void 0},r=>{s&&(r.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 d.Mesh)))return[];const s=[],r=t,n=r.children.length,a=Math.round(Math.pow(n,.5)),o=z.getUpdateProgressFuncAsync(i);for(let l=n-1;l>=0;--l){const c=n-l-1;let u;if(i&&(c%a===0||c===0||c===n-1)){const g=c*90/n,x=(c+1)*90/n;u=z.getUpdateSubProgressFunc(g,x,i)}const f=r.children[l],m=await this.createOutlines(f,e,u);s.push(...m)}if(!r.geometry)return await o(100),s;if(r instanceof d.Mesh&&!this.hasOutline(r,!1)){await o(50);const l=this.createOutline(r.geometry);r.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 r=t.children[s];if(r.userData.isOutline){i=!0;break}if(e&&r.children.length>0&&(i=this.hasOutline(r),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 d.EdgesGeometry(t,Rs),r=new d.LineSegments(s,e);return r.layers.enableAll(),ke.disableLayerChannels(r,[ft,Ce]),r.userData.isOutline=!0,r.matrixAutoUpdate=Ne,i&&r.applyMatrix4(i),r}static cloneObject(t,e=!0){const i=t.clone();return e&&i.traverse(s=>{if(s instanceof d.Mesh||s instanceof d.Line){const r=s;r.material=de.cloneMaterial(r.material)}}),i}static createBox(t,e,i,s=this.BOX_FACE_MATERIAL,r=!0){const n=[],a=(c,u,f)=>{n.push(new d.Vector3(c,u,f))};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 d.BufferGeometry;o.setFromPoints(n);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 r&&l.push(0,5,4,0,1,5),o.setIndex(l),o.computeVertexNormals(),new d.Mesh(o,s)}static rebaseObjectOnRTC(t){const e=t;if(!(e.isMesh||e.isLine||e.isPoints)||!e.geometry||!(e.geometry instanceof d.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 r=s.itemSize,n=s.array,a=[];for(let c=0;c<r;c++)a.push(n[c]);for(let c=0;c<s.count;c++)for(let u=0;u<r;u++)n[c*r+u]-=a[u];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=Oo;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 d.Mesh)&&!(t instanceof d.Line)&&!(t instanceof d.Points)?!1:!!t.geometry}static enableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.enableLayerChannels(s[r],e,!0)}}static disableLayerChannels(t,e,i=!0){for(let s=0,r=e.length;s<r;s++)t.layers.disable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.disableLayerChannels(s[r],e,!0)}}static setLayerChannels(t,e,i=!0){t.layers.disableAll();for(let s=0,r=e.length;s<r;s++)t.layers.enable(e[s]);if(i){const s=t.children;for(let r=0,n=s.length;r<n;r++)ke.setLayerChannels(s[r],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(ln)}static isObjectSnapable(t){return t.layers.isEnabled(Ce)}static isObjectSelectable(t){return t.layers.isEnabled(ft)}};p(ke,"OUTLINE_MATERIAL",new d.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),p(ke,"BOX_FACE_MATERIAL",new d.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:d.FrontSide}));let $=ke;const Si=new d.Matrix4,Eo=new d.Matrix4,di=class di{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={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.isInstancedMesh||!u.geometry||!(u.geometry instanceof d.BufferGeometry))continue;let f=!1;const m=Object.values(s);for(let g=m.length-1;g>=0;--g){const x=m[g].indexes[0];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}for(let g=r.length-1;!f&&g>=0;--g){const x=r[g];if(f=this.tryHandleMergeableObjects(t,c,x,s,r),f)break}!f&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry.clone();if(O.applyMatrix4(E.matrix),U.tryConvertInterleavedBufferAttributes(O),O.userData.isLineSegments=E.isLineSegments===!0,m.push(O),e){const _=E.name,C=O.attributes?.position?.count,w=O.index?.count||0,M={batchId:g,name:_,positionStart:x,positionCount:C,indexStart:y,indexCount:w};Object.keys(E.userData).length!==0&&(M.userData=E.userData),T.push(M),x+=C,y+=w,g++}}),m.length===0)return;let v;if(f.isMesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Mesh(b,f.material),n.push(v)}else if(f.isLine){const b=this.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new d.LineSegments(b,f.material),a.push(v)}else if(f.isPoints){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new d.Points(b,f.material),o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.matrixAutoUpdate=Ne,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,v.visible=f.visible,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),t.updateMatrix(),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&this.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;let a=Date.now();const o={},l=[];for(let y=0;y<t.length;++y){const T=t[y];if(T.isInstancedMesh||!T.geometry||!(T.geometry instanceof d.BufferGeometry))continue;let v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.isLineSegments===!0,b.push(A),r){const I=P.name,k=A.attributes?.position?.count,B=A.index?.count||0;let L;v.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),L=A.boundingSphere.clone());const q={batchId:E,name:I,positionStart:O,positionCount:k,indexStart:_,indexCount:B,boundingSphere:L};!P.parent.geometry&&Object.keys(P.parent.userData).length!==0&&(q.parentUserData=P.parent.userData),Object.keys(P.userData).length!==0&&(q.userData=P.userData),C.push(q),O+=k,_+=B,E++}}),b.length===0)return;let w;if(v.isMesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Mesh(M,v.material),c.push(w)}else if(v.isLine){const M=this.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new d.LineSegments(M,v.material),u.push(w)}else if(v.isPoints){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new d.Points(M,v.material),f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.matrixAutoUpdate=Ne,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,w.visible=v.visible,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&(e.add(y),y.updateWorldMatrix(!1,!1))}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Si.identity();s&&s!==i&&(Si.premultiply(s.matrix),!!s.parent);)s=s.parent;return Si.equals(Eo)?t:t.applyMatrix4(Si)}static mergeLineGeometries(t,e,i,s){let r;if(i)r=di.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(r=xe.mergeGeometries(t),!r)return;r.userData={};const n=[];let a=0;t.forEach((o,l)=>{const c=o.attributes.position;if(!c)return;const u=o.index,f=o.userData.isLineSegments===!0,m=n.length;if(u)for(let g=0;g<u.count;g++){const x=u.array[g];f?n.push(a+x):g>0&&n.push(a+u.array[g-1],a+x)}else for(let g=0;g<c.count;g++)g>0&&(f?g%2===1&&n.push(a+g-1,a+g):n.push(a+g-1,a+g));a+=c.count,e&&s&&(s[l].indexStart=m,s[l].indexCount=n.length-m)}),r.setIndex(n)}return r}static mergeBufferGeometriesWithLinesToLineSegments(t,e,i){const s=new Set(Object.keys(t[0].attributes)),r={},n=new d.BufferGeometry,a=[];let o=0;for(let l=0;l<t.length;++l){let c=t[l];const u=c.userData.isLineSegments===!0;a.push(u),c.index&&(S.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),c=U.convertGeometryWithIndexedToNonIndexed(c));let f=0;for(const m in c.attributes){if(!s.has(m))return S.error("[Merge] mergeGeometries() failed with geometry at index "+l+". All geometries must have compatible attributes; make sure "+m+" attribute exists among all geometries, or in none of them"),void 0;!r[m]&&(r[m]=[]),r[m].push(c.attributes[m]),f++}if(f!==s.size)return S.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 m=c.attributes.position;i[l].indexStart=0,i[l].indexCount=0;const g=u?m.count:m.count*2-2;i[l].positionStart=o,i[l].positionCount=g,o+=g}}for(const l in r){const c=di.mergeBufferAttributesWithLinesToLineSegments(r[l],a);if(!c)return S.error("[Merge] mergeGeometries() failed while trying to merge the "+l+" attribute."),void 0;n.setAttribute(l,c)}return n}static mergeBufferAttributesWithLinesToLineSegments(t,e){let i,s,r,n=0;for(let l=0;l<t.length;++l){const c=t[l];if(i===void 0&&(i=c.array.constructor),i!==c.array.constructor)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.array must be of consistent array types across matching attributes."),void 0;if(s===void 0&&(s=c.itemSize),s!==c.itemSize)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.itemSize must be consistent across matching attributes."),void 0;if(r===void 0&&(r=c.normalized),r!==c.normalized)return S.error("[Merge] mergeBufferAttributes() failed. THREE.BufferAttribute.normalized must be consistent across matching attributes."),void 0;const u=e[l],f=u?0:c.count-2,m=c.count+f;n+=m*s}const a=new i(n);let o=0;for(let l=0;l<t.length;++l){const c=e[l],u=t[l],f=c?0:u.count-2,m=u.count+f,g=u.itemSize,x=new i(m*g);let y=0;for(let T=0;T<u.count;T++){const v=T*g,b=T!==0&&T!==u.count-1&&!c;for(let E=0;E<g;E++)x[y+E]=u.array[v+E],b&&(x[y+g+E]=u.array[v+E]);y+=b?2*g:g}a.set(x,o),o+=m*g}return new d.BufferAttribute(a,s,r)}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,r=s.getX(i*3);if(r>=e.positionStart&&r<e.positionStart+e.positionCount)return!0}else if(t.index){const s=e.indexStart/3,r=(e.indexStart+e.indexCount)/3-1;if(i>=s&&i<=r)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 S.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 r=i[s];if(this.isFaceIndexInBatch(t.geometry,r,e))return r}}static getBatchByLineIndex(t,e){if(e<0)return S.error("[Merge]: Invalid index: "+e),void 0;const i=t&&t.geometry&&t.userData.batches;if(!i)return;const s=t.geometry,r=s.index;for(let n=0;n<i.length;++n){const a=i[n];if(r){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 r=i[s];if(r.batchId===e)return r}}static cloneGeometryForBatch(t,e){const i=t&&t.geometry;if(!i)return;const s=i.attributes.position,r=s?.array;let n=i.index?.array;if(!r||!n)return S.warn("[Merge]: Unexpected position: "+r+", or index: "+n+"!"),void 0;const a=new d.BufferGeometry,o=e.positionStart,l=e.positionStart+e.positionCount,c=i.attributes;for(const x in c){const y=c[x],T=y.itemSize,v=y.array.slice(o*T,l*T);a.setAttribute(x,new d.BufferAttribute(v,T,y.normalized))}if(i.boundsTree&&(n=i.userData.originalIndex,!n))return S.warn("[Merge] After building bvh, the original index data is not preserved !"),void 0;const u=e.indexStart,f=e.indexStart+e.indexCount,m=[];let g=0;for(let x=u;x<f&&x<n.length;++x)m[g++]=n[x]-e.positionStart;return a.setIndex(m),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};p(di,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let oe=di;const _o=.01;class Po{static getFaces(t){const e=t.map(r=>r.toArray()).reduce((r,n)=>(r.push(...n),r),[]),i=[];return ua.Earcut.triangulate(e,[],3).forEach(r=>i.push(r)),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 r=3;r<t.length;r++)if(t[r].clone().sub(t[0]).projectOnVector(s).length()>_o)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return fa(e).length>0}}class rt{static getVisibleObjectBoundingBox(t){const e=new d.Box3;return t.traverse(i=>{i.visible&&(i instanceof d.Mesh||i instanceof d.Line)&&$.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new d.Box3;return e.forEach(r=>{const n=t.getObjectById(r);if(n){const a=rt.getBoundingBox(n,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new d.Box3;if(t instanceof d.InstancedMesh)return rt.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let r=1;s>20&&(r=3),s>100&&(r=5),s>200&&(r=10),s>1e3&&(r=100),t.updateMatrixWorld(!1);for(let n=0;n<s;++n){const a=t.children[n];if(!e||n%r===0)if(a.updateMatrix(),a instanceof d.InstancedMesh){const o=rt.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(z.isMatrixValid(a.matrixWorld)){const o=rt.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 d.Box3,i=new d.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const r=t.geometry.clone();if(r.boundingBox){const n=r.boundingBox.applyMatrix4(i);!n.isEmpty()&&z.isBoxValid(n)&&e.union(n)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=rt.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class dt{static setMaterialSection(t,e,i=!1,s=!1){const r=i&&t.clippingPlanes?t.clippingPlanes:[];r.push(...e),t.clippingPlanes=r,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(r=>{const n=r.material;Array.isArray(n)?n.forEach(a=>{dt.setMaterialSection(a,e,i,s)}):n&&dt.setMaterialSection(n,e,i,s)})}static generateSectionPlanesByBox(t){const e=t.min,i=t.max;return[new d.Plane(new d.Vector3(0,-1,0),i.y),new d.Plane(new d.Vector3(0,1,0),-e.y),new d.Plane(new d.Vector3(1,0,0),-e.x),new d.Plane(new d.Vector3(-1,0,0),i.x)]}static generateSectionPlanesByPoints(t,e=!0){const i=t.length;if(i<2)return;const s=[];for(let r=0;r<i-1;r++){const n=t[r],a=t[(r+1)%i],o=new d.Plane;o.setFromCoplanarPoints(new d.Vector3(n.x,n.y,-1),new d.Vector3(n.x,n.y,0),new d.Vector3(a.x,a.y,0)),e||o.negate(),s.push(o)}return s}}class Ao{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new pa.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof d.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const Io=10;var it=(h=>(h.TripleCross="TripleCross",h.Square="Square",h.Triangle="Triangle",h.CircleWithCross="CircleWithCross",h.Cross="Cross",h.Perpendicular="Perpendicular",h))(it||{});class ko{static createSVGObject(t){return new ma.SVGObject(t)}}class pi{static async createEnvTexture(t,e){const i=new ga.RGBELoader;return new Promise(s=>{i.load(e,r=>{if(t){const n=t.fromEquirectangular(r).texture;t.dispose(),s(n)}})})}static async createEnvTextureFromDataArray(t,e=this.HDR_CITY_STREET_64x32,i=64,s=32){if(t){const r=new d.DataTexture(e,i,s);r.flipY=!0,r.magFilter=d.LinearFilter,r.minFilter=d.LinearFilter,r.type=d.HalfFloatType,r.version=1;const n=t.fromEquirectangular(r).texture;return t.dispose(),Promise.resolve(n)}return Promise.reject("Invalid pmremGenerator!")}}p(pi,"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 Do(){if(be.isBrowser){const h=document.createElement("div");return h.setAttribute("style","height: 1in; visibility: hidden; position: absolute; margin: 0; padding: 0;"),document.body.appendChild(h),.0254/h.clientHeight}else return .0254/96}const Es={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:Do()},dn={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},un=h=>h===2?"²":h===3?"³":"",_s=(h,t=1)=>dn[h]+un(t),Bo=(h,t,e,i=1)=>(e==null&&(e=t),e===t?{value:h,unit:_s(e)}:{value:h*Math.pow(Es[t]/Es[e],i),unit:_s(e)+un(i)});var fn=(h=>(h.Top="Top",h.Bottom="Bottom",h.Front="Front",h.Back="Back",h.Left="Left",h.Right="Right",h))(fn||{});class Lo{static getCameraDirectionByView(t){const e=new d.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 re=(h=>(h.MouseClick="mouseclick",h.LayoutChange="layoutchange",h.ModelLoad="modelload",h.BeforeRender="beforerender",h.AfterRender="afterrender",h.OnAnimate="onanimate",h.CameraChange="camerachange",h.ControlChange="controlchange",h.BoxSelectActivate="boxselectactivate",h.BoxSelectDeactivate="boxselectdeactivate",h.PickMarkupActivate="pickmarkupactivate",h.PickMarkupDeactivate="pickmarkupdeactivate",h.MarkupActivate="markupactivate",h.MarkupDeactivate="markupdeactivate",h.MarkupAdd="markupadd",h.MarkupUpdate="markupupdate",h.MarkupRemove="markupremove",h.BeforeRemoveMarkup="beforeremovemarkup",h.MeasurementActivate="measurementactivate",h.MeasurementDeactivate="measurementdeactivate",h.MeasurementAdd="measurementadd",h.MeasurementRemove="measurementremove",h.HotpointClick="hotpointclick",h))(re||{});const or={};class xi extends mt{constructor(e){super();p(this,"viewer");p(this,"drawableLists");p(this,"canvas");p(this,"context");p(this,"frustum");p(this,"projScreenMatrix");this.drawableLists=[],this.frustum=new d.Frustum,this.projScreenMatrix=new d.Matrix4,this.viewer=e,this.init()}static _registerDrawableClass(e){const i=e;or[i.prototype.getClassType()]=e}static createDrawable(e){const i=or[e.type];if(!i)throw new Error("Invalid drawable type: "+i);const s=e.points.map(n=>new d.Vector3(n[0],n[1],n[2]||0)),r=new i(e.id,s);return r.setData(e),r}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(re.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:r,clientHeight:n}=s;this.setSize(r,n)}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 r=Math.max(window.devicePixelRatio||1,1),n=this.canvas;return n.width=i*r,n.height=s*r,e.scale(r,r),n.style.width=i+"px",n.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 d.Sphere,s=this.viewer.getPixelSizeInWorldCoord();for(let r=0;r<e.length;r++){const n=e[r];n.setTolerance(s),!(!n.visible||(n.getBounds().getBoundingSphere(i),n.needsFrustumCulled&&!this.frustum.intersectsSphere(i)))&&n.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 r=Array.from(s.getDrawables().values());e&&(r=r.filter(n=>n.visible)),r.length>0&&i.push(...r)}),i.sort((s,r)=>s.renderOrder===r.renderOrder?r.getCenter().distanceTo(this.camera.position)-s.getCenter().distanceTo(this.camera.position):s.renderOrder-r.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 r=0;r<i.length;r++){const n=i[r];n.isPointInPath(e,this.raycaster)&&s.push(n)}return s}getDrawableById(e){return this.getSortedDrawables().find(s=>s.id===e)}measureTextLength(e,i){const s=this.context,r=e.split(`
535
- `);let n=0;for(let a=0;a<r.length;a++){const o=r[a];s.save(),s.font=i;const l=s.measureText(o).width;s.restore(),n=Math.max(n,l)}return n}getImage(e){this.clearCanvas();const i=this.getSortedDrawables();for(let s=0;s<i.length;s++){const r=i[s];e(r)&&r.render(this.context,this.camera)}return z.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 bi extends mt{constructor(e){super();p(this,"category");p(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],r=xi.createDrawable(s);this.addDrawable(r)}}getDrawableByPosition(e,i){let s;for(const[,r]of this.drawableMap)if(r.visible&&r.isPointInPath(e,i)){s=r;break}return s}}class pt extends mt{constructor(e){super();p(this,"DEFAULT_LINE_WIDTH",1);p(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);p(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);p(this,"id");p(this,"lineWidth");p(this,"lineColor");p(this,"fillColor");p(this,"x");p(this,"y");p(this,"width");p(this,"height");p(this,"points");p(this,"userData");p(this,"tolerance");p(this,"visible");p(this,"selected");p(this,"renderOrder");p(this,"needsFrustumCulled");p(this,"editPointSize");p(this,"editPointFillColor");p(this,"editPointStrokeColor");p(this,"matrix");p(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 d.Matrix4,this.id=e||z.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 d.Vector3(this.x,this.y,0),i=new d.Vector3(this.x+this.width,this.y,0),s=new d.Vector3(this.x+this.width,this.y-this.height,0),r=new d.Vector3(this.x,this.y-this.height,0);return[e,i,s,r]}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 d.Vector3)}transToScreenCoord(e,i){return this.ctx?pe.world2Screen(e,i,this.ctx.canvas):new d.Vector2}drawBounds(e,i){const{min:s,max:r}=this.getBounds(),n=[],a=(o,l,c)=>n.push(new d.Vector3(o,l,c));a(r.x,r.y,r.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,s.y,r.z),a(r.x,r.y,r.z),a(r.x,s.y,r.z),a(r.x,r.y,s.z),a(r.x,s.y,s.z),a(s.x,r.y,s.z),a(s.x,s.y,s.z),a(s.x,r.y,r.z),a(s.x,r.y,s.z),a(r.x,r.y,r.z),a(r.x,r.y,s.z),a(s.x,s.y,r.z),a(s.x,s.y,s.z),a(r.x,s.y,r.z),a(r.x,s.y,s.z),e.save(),e.strokeStyle="yellow",e.beginPath(),n.forEach((o,l)=>{const c=this.transToScreenCoord(o,i);l%2===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.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 d.Box3().setFromPoints(e)}}const as=new d.Vector3;class Je extends pt{constructor(e,i,s=[1,0,0,1],r){super(e);p(this,"boxes");p(this,"lineSegments");this.lineSegments=[],this.boxes=Je.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=r??[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(),r=s.getSize(as),n=Math.max(r.x,r.y)*.12||1;return s.expandByScalar(n)})}calculateCloudLineSegments(e){for(let i=0;i<e.length;i++){const s=e[i],r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y),new d.Vector3(s.min.x,s.min.y)],n=as.subVectors(r[0],r[2]).length()/10||1e-4,a=[];for(let o=0;o<r.length-1;o++){const l=r[o],c=r[o+1],u=as.subVectors(c,l),f=u.length(),m=u.normalize(),g=Math.ceil(f/n);for(let x=0;x<g;x++)a.push(l.clone().add(m.clone().multiplyScalar(n*x)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=qt.rgba2Color(this.lineColor),e.fillStyle=qt.rgba2Color(this.fillColor);for(let s=0;s<this.lineSegments.length;s++){const r=this.boxes[s];r&&this.fillRect(e,i,r);const n=this.lineSegments[s];this.drawBox(e,i,n)}e.restore()}fillRect(e,i,s){const r=[new d.Vector3(s.min.x,s.min.y),new d.Vector3(s.max.x,s.min.y),new d.Vector3(s.max.x,s.max.y),new d.Vector3(s.min.x,s.max.y)];e.beginPath();for(let n=0;n<r.length;n++){const a=this.transToScreenCoord(r[n],i);n===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 r=0;r<s.length-1;r++){const n=this.transToScreenCoord(s[r],i),a=this.transToScreenCoord(s[r+1],i),o=Je.getControlPointByTwoPoints(a,n);r===0&&e.moveTo(n.x,n.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new d.Vector2().subVectors(i,e),r=s.angle(),n=s.length(),a=d.MathUtils.degToRad(45),o=n/2/Math.cos(a);return new d.Vector2(e.x+o*Math.cos(a-r),e.y-o*Math.sin(a-r))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new d.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}xi._registerDrawableClass(Je);const Ro=[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],Fo=["PROXY","REGION","INSERT","HATCH"];function Nt(h){return Ro[h]}function Ie(h){const t={};let e=h.lastReadGroup,i=e.code;if(t.x=e.value,i+=10,e=h.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=h.next(),e.code!==i||(t.z=e.value,h.next()),t}const zo="OriginalHandle",jo="OriginalType",Vo="Outlines";function Q(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 6:h.lineType=(t.value||"BYLAYER").toUpperCase();break;case 8:h.layer=t.value||"0";break;case 39:h.thickness=t.value;break;case 48:h.lineTypeScale=t.value>0?t.value:1;break;case 60:h.visible=t.value!==1;break;case 62:if(!h.isTrueColor){const e=t.value;h.colorIndex=e,e<0&&console.warn("[DxfParser] Negative colorIndex indicates layer is off or BYBLOCK/BYLAYER"),h.color=Nt(Math.abs(e))}break;case 67:h.inPaperSpace=t.value===1;break;case 330:h.ownerHandle=t.value;break;case 370:h.lineweight=t.value;break;case 410:h.layoutName=t.value;break;case 420:h.isTrueColor=!0,h.color=t.value;break;case 1e3:if(t.value&&typeof t.value=="string"){if(t.value.includes(zo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalHandle=e[1]}if(t.value.includes(Vo)&&(h.extendedData||(h.extendedData={}),h.extendedData.outlines=[]),t.value.includes(jo)){const e=t.value.split(":").map(i=>i.trim());h.extendedData||(h.extendedData={}),h.extendedData.originalType=e[1]}}break;case 1001:break;case 92:case 331:case 347:break;default:return!1}return!0}function Xt(h,t){switch(t.code){case 0:h.type=t.value;break;case 5:h.handle=t.value;break;case 330:h.ownerHandle=t.value;break;case 1e3:break;case 1001:break;default:return!1}return!0}const Fs="BYLAYER",mi="BYBLOCK";var ge=(h=>(h[h.Mesh=-1]="Mesh",h[h.MeshWithPattern=0]="MeshWithPattern",h[h.LineWithWidth=1]="LineWithWidth",h[h.Line=2]="Line",h[h.LineWithPattern=3]="LineWithPattern",h[h.Point=4]="Point",h[h.Text=5]="Text",h))(ge||{});const oi=["INSERT","DIMENSION"];function Uo(h,t,e,i,s){if(!t)return 0;const r=/[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff]/.test(h),n=s&&s.toLowerCase().endsWith(".shx");let a=0,o=0;if(t.userData&&typeof t.userData.advanceWidth=="number")a=t.userData.advanceWidth,r||(a+=a*.15);else if(t.boundingBox){const l=new d.Vector3;t.boundingBox.getSize(l),a=l.x}if(h===" ")return a=e*.25,a;if(n)i>1?o=(i-1)*e*.1:o=a*.05;else{const l=e*.04;r?o=i>1?(i-1)*e*.1:0:o=i*l}return a+o}function Ho(h){const t=/(\\M\+(?:[0-5])[0-9A-Fa-f]{4,})/g,e=h.match(t);if(!e)return h;let i=h;for(const s of e){const r=s.substring(4);if(r.length<4){console.error(`警告:提取的十六进制数 '${r}' 长度不足,已保留原始编码。`);continue}const n=r.substring(0,4),a=r.substring(4);try{const o=new Uint8Array(n.match(/.{1,2}/g).map(u=>parseInt(u,16))),c=new TextDecoder("gbk").decode(o);i=i.replace(s,c+a)}catch(o){console.error("转换失败:",o)}}return i}function lr(h){const t=[];let e=h;const i=/\\[a-z]+\d*\.?\d*;?/g;return(h.match(i)||[]).forEach(r=>{e=e.replace(r,""),t.push(r)}),{formatCodes:t,plainText:e}}function No(h,t){const e=lr(h.text).plainText,i=lr(t.text).plainText;return e===i}var Te=(h=>(h.Added="Added",h.Removed="Removed",h.Modified="Modified",h.NoChange="NoChange",h))(Te||{});let ve=1;const tt=class tt{constructor(t,e,i={}){p(this,"dxf1");p(this,"dxf2");p(this,"changes");p(this,"comparedBlocks");p(this,"isComparingBlock");p(this,"isComparingDimension");p(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 r=this.getLayerFrozen(this.dxf1,s)===!0;!tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const r=this.getLayerFrozen(this.dxf2,s)===!0;!tt.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!r&&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 r=t.block;let n;if(this.isComparingBlock=!0,this.isDimensionBlock(r)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,n=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}else{if(!this.comparedBlocks.has(r)){const a=this.dxf1.blocks[r],o=this.dxf2.blocks[r],l=Date.now(),c=this.compareBlock(t,e,a,o);this.comparedBlocks.set(r,c),S.debug("[DxfCompare] compare block: "+r+" took "+(Date.now()-l)/1e3+"s")}n=this.comparedBlocks.get(r)}return n?.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[ve]={id:ve,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[ve]={id:ve,...a,parentHandles:o}),ve++}}),!i&&!s&&(this.isComparingBlock=!1),n}compareBlock(t,e,i,s){const r=[],n=[];i?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&r.push(l)}),s?.entities?.forEach(l=>{l.type!=="ATTDEF"&&!this.bIgnoreChildEntitiesOriginalType(l)&&n.push(l)});const a=[],o=[];for(let l=0;l<r.length;l++){const c=r[l];let u=!1;n.length===0&&(u=!0),!this.isComparingDimension&&(this.isComparingDimension=c.type==="DIMENSION");for(let f=0;f<n.length;f++){const m=n[f];if(!this.entitiesEqual(c,m,t,e))u=!0;else if(c.type==="INSERT"&&m.type==="INSERT"||c.type==="DIMENSION"&&m.type==="DIMENSION"){const g=this.compareInsertOrDemensionEntities(c,m,c.handle,m.handle);g&&g.length>0&&a.push(...g),u=!1,n.splice(f--,1);break}else{u=!1,n.splice(f--,1);break}}u&&(a.push({type:"Removed",handle:c.handle}),o.push(c.handle))}return n.forEach(l=>{!o.includes(l.handle)&&a.push({type:"Added",handle:l.handle})}),a}async compareEntities(t,e,i){const s=z.getUpdateProgressFuncForLoop(t.length,i);for(let r=0;r<t.length;r++){const n=t[r].handle;if(!e.has(n))this.changes[ve]={id:ve,type:"Removed",handle:n},ve++;else{const a=t[r],o=e.get(n),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(oi.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(n),S.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(n);continue}this.changes[ve]={id:ve,type:"Modified",handle:n},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[ve].detailChanges=l),ve++}e.delete(n)}await s(r)}for(const r of e){const n=r[0];this.changes[ve]={id:ve,type:"Added",handle:n},ve++}}bIgnoreChildEntitiesOriginalType(t){return Fo.includes(t.extendedData?.originalType)}entitiesEqual(t,e,i,s,r){if(!this.baseEntitiesEqual(t,e,i,s,r))return!1;const n=t.type;let a=!0;switch(n){case"CIRCLE":case"ARC":a=this.arcsEqual(t,e);break;case"LWPOLYLINE":case"LINE":a=this.linesEqual(t,e,r);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 r=e.tables?.layer?.layers,n=r&&r[t.layer],a=r&&i&&r[i.layer];n&&n.name!=="0"?s=n.color:a?s=a.color:n?s=n.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!==Fs&&t.lineType!==mi)return t.lineType;if(t.lineType===mi)return i?this.getLineType(i,e):t.lineType;const s=e.tables?.layer?.layers,r="CONTINUOUS";if(t.layer!=="0"){const n=s&&s[t.layer];if(n)return n.lineType}else if(i){const n=s&&s[i.layer];if(n)return n.lineType}return r}addModificationItem(t,e,i,s){s&&(s[i]={old:t,new:e})}baseEntitiesEqual(t,e,i,s,r){let n=!0;const a=this.getColor(t,this.dxf1,i),o=this.getColor(e,this.dxf2,s);if(a!==o)if(n=!1,this.enableDetailComparision)this.addModificationItem(a,o,"color",r);else return n;const l=this.getLineType(t,this.dxf1,i),c=this.getLineType(e,this.dxf2,s);if(l!==c){if(n=!1,this.enableDetailComparision)this.addModificationItem(l,c,"lineType",r);else return n;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:n}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 r=t.constantWidth,n=e.constantWidth;if(!this.numberEqual(r,n))if(s=!1,this.enableDetailComparision)this.addModificationItem(r||0,n||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:r=!0}=i;if(r&&!this.pointsEqual(t.position,e.position))return!1;if(s){if(t.text!==e.text)return!1}else if(!No(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"?(S.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 S.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?R.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)}};p(tt,"ENTITY_COLOR_ADDED",65280),p(tt,"ENTITY_COLOR_REMOVED",16711680),p(tt,"ENTITY_COLOR_NO_CHANGE",10066329),p(tt,"ENTITY_COLOR_MARKUP",16744231),p(tt,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let Ue=tt;var H=(h=>(h[h.Object=0]="Object",h[h.Point=1]="Point",h[h.Line=2]="Line",h[h.LineSegment=3]="LineSegment",h[h.Mesh=4]="Mesh",h))(H||{});const os=new Se.Box3,ls=new Se.Matrix4;class F{constructor(t=0){p(this,"name");p(this,"type");p(this,"matrix");p(this,"parent");p(this,"children");p(this,"layers");p(this,"renderOrder");p(this,"userData");p(this,"material");p(this,"geometry");p(this,"matrixWorld");this.name="",this.type=0,this.matrix=new Se.Matrix4,this.children=[],this.layers=new Se.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 F().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 Se.Object3D;break;case 1:if(!this.geometry)return;e=new d.Points(this.geometry,this.material);break;case 2:if(!this.geometry)return;e=new d.Line(this.geometry,this.material);break;case 3:if(!this.geometry)return;e=new d.LineSegments(this.geometry,this.material);break;case 4:if(!this.geometry)return;e=new d.Mesh(this.geometry,this.material);break}if(e){if(e.name=this.name,e.matrixAutoUpdate=Ne,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],r=s.convertToThreejsObject(t);r&&e.add(r)}return e}}static getBox(t,e,i){if(t.geometry)!t.geometry.boundingBox&&t.geometry.computeBoundingBox(),ls.copy(t.matrix),i&&ls.premultiply(i),os.copy(t.geometry.boundingBox),os.applyMatrix4(ls),e.union(os);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new Se.Matrix4),t.matrixWorld.copy(t.matrix),i&&t.matrixWorld.premultiply(i);const s=t.children;for(let r=0,n=s.length;r<n;r++)this.getBox(s[r],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 r=e.blockPosition?.x||0,n=e.blockPosition?.y||0;s.x=s.x-r,s.y=s.y-n;const a=new Se.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new Se.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 c=new Se.Box3().copy(l.geometry.boundingBox);c.applyMatrix4(l.loneMatrix||l.matrix),o.push({min:{x:c.min.x,y:c.min.y,z:c.min.z},max:{x:c.max.x,y:c.max.y,z:c.max.z},positions:[{x:c.min.x+s.x,y:c.min.y+s.y},{x:c.min.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.max.y+s.y},{x:c.max.x+s.x,y:c.min.y+s.y}],rotation:e.rotation,center:{x:(c.min.x+c.max.x)/2+s.x,y:(c.min.y+c.max.y)/2+s.y,z:(c.min.z+c.max.z)/2},size:{x:c.max.x-c.min.x,y:c.max.y-c.min.y,z:c.max.z-c.min.z}}),a.union(c)}}),!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,r){const n=i-t,a=s-e,o=r*Math.PI/180,l=Math.cos(o),c=Math.sin(o);return[{dx:0,dy:0},{dx:n,dy:0},{dx:n,dy:a},{dx:0,dy:a}].map(f=>{const m=f.dx*l-f.dy*c,g=f.dx*c+f.dy*l;return{x:t+m,y:e+g}})}}const Oi=new d.Matrix4,Go=new d.Matrix4;class et{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={},r=[];for(let c=0;c<i;++c){const u=t.children[c];if(u.children.length>0){this.mergeInner(u,e);continue}if(u.userData.relativeToCenter||!u.geometry)continue;let m=!1;const g=Object.values(s);for(let x=g.length-1;x>=0;--x){const y=g[x].indexes[0];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}for(let x=r.length-1;!m&&x>=0;--x){const y=r[x];if(m=this.tryHandleMergeableObjects(t,c,y,s,r),m)break}!m&&r.push(c)}if(Object.keys(s).length<=0)return;const n=[],a=[],o=[],l=[];Object.values(s).forEach(c=>{const u=c.indexes,f=t.children[u[0]];let m=[],g=0,x=0,y=0;const T=[];if(u.forEach(b=>{const E=t.children[b],O=E.geometry?.clone();if(O.applyMatrix4(E.matrix),O.userData.isLineSegments=E.type===H.LineSegment,m.push(O),e){const _=O.attributes?.position?.count,C=O.index?.count||0;T.push({batchId:g,positionStart:x,positionCount:_,indexStart:y,indexCount:C}),x+=_,y+=C,g++}}),m.length===0)return;let v;if(f.type===H.Mesh){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,n.push(v)}else if(f.type===H.Line||f.type===H.LineSegment){const b=oe.mergeLineGeometries(m,e,f.material instanceof d.LineDashedMaterial||f.material instanceof d.ShaderMaterial,T);if(!b)return;v=new F(H.LineSegment),v.geometry=b,v.material=f.material,a.push(v)}else if(f.type===H.Point){const b=xe.mergeGeometries(m);if(!b)return;b.userData={},v=new F(f.type),v.geometry=b,v.material=f.material,o.push(v)}v&&(e?v.userData.batches=T:(v.userData=f.userData,v.userData.batches=void 0),v.userData.layerName=f.userData.layerName,v.name="[Merged] "+f.name,v.renderOrder=f.renderOrder,v.layers.mask=f.layers.mask,l.push(...u)),m.forEach(b=>{b.dispose(),U.releaseGeometryManually(b)}),m=[]}),l.sort((c,u)=>u-c),l.forEach(c=>{const u=t.children[c];t.remove(u)}),[...n,...a,...o].forEach(c=>{t.add(c)}),this.MergeInfo.removedObjects+=l.length,this.MergeInfo.mergedMeshes+=n.length,this.MergeInfo.mergedLines+=a.length,this.MergeInfo.mergedPoints+=o.length}static tryHandleMergeableObjects(t,e,i,s,r){let n=!1;const a=Array.isArray(t),o=a?t.length:t.children.length;if(e===i||e>=o||i>=o)return n;const l=a?t[e]:t.children[e],c=a?t[i]:t.children[i];return this.areObjectsMergeable(l,c)&&oe.areGeometriesMergeable(l.geometry,c.geometry)&&de.materialsEquals(l.material,c.material)&&(!s[i]&&(s[i]={indexes:[i]},this.removeFromArray(r,i)),s[i].indexes.push(e),n=!0),n}static isFilteredByOtherFactors(t,e){const i=t;if(i.type===H.Mesh&&i.material&&i.material.isShaderMaterial)return!0;let s=!1,r=t;for(;r&&r!==e;){const n=r.userData;if(n.relativeToCenter||n.spatialFilterHandle){s=!0;break}r=r.parent}return s}static deepMerge(t,e=void 0,i=!0,s=!0,r=!0){const n={added:[],removed:[]};if(t.length<=1)return n;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 v=!1;const b=Object.values(o);for(let E=b.length-1;E>=0;--E){const O=b[E].indexes[0];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}for(let E=l.length-1;!v&&E>=0;--E){const O=l[E];if(v=this.tryHandleMergeableObjects(t,y,O,o,l),v)break}!v&&l.push(y)}if(Object.keys(o).length<=0)return n;S.debug("[Merge] Built merged indexes for "+t.length+" objects in "+(Date.now()-a)/1e3+"s"),a=Date.now();const c=[],u=[],f=[],m=[];Object.values(o).forEach(y=>{const T=y.indexes;if(T.length<2)return;const v=t[T[0]];let b=[],E=0,O=0,_=0;const C=[];if(T.forEach(M=>{const P=t[M],A=P.geometry?.clone();if(v.material instanceof d.LineBasicMaterial&&A.deleteAttribute("lineDistance"),this.applyMatrix(A,P,e),A.userData.isLineSegments=P.type===H.LineSegment,b.push(A),r){const I=A.attributes?.position?.count,k=A.index?.count||0;let B;(v.type===H.Line||v.type===H.LineSegment)&&(!A.boundingSphere&&A.computeBoundingSphere(),B=A.boundingSphere?.clone());const L={batchId:E,positionStart:O,positionCount:I,indexStart:_,indexCount:k,boundingSphere:B};Object.keys(P.userData).length!==0&&(L.userData=P.userData),C.push(L),O+=I,_+=k,E++}}),b.length===0)return;let w;if(v.type===H.Mesh){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,c.push(w)}else if(v.type===H.Line||v.type===H.LineSegment){const M=oe.mergeLineGeometries(b,r,v.material instanceof d.LineDashedMaterial||v.material instanceof d.ShaderMaterial,C);if(!M)return;w=new F(H.LineSegment),w.geometry=M,w.material=v.material,u.push(w)}else if(v.type===H.Point){const M=xe.mergeGeometries(b);if(!M)return;M.userData={},w=new F(v.type),w.geometry=M,w.material=v.material,f.push(w)}w&&(r?w.userData.batches=C:(w.userData=v.userData,w.userData.batches=void 0),w.userData.layerName=v.userData.layerName,w.name="[Merged] "+v.name,w.renderOrder=v.renderOrder,w.layers.mask=v.layers.mask,T.forEach(M=>m.push(M))),b.forEach(M=>{M.dispose(),U.releaseGeometryManually(M)}),b=[]}),S.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const g=n.removed;m.forEach(y=>{const T=t[y];g.push(T),i&&T.removeFromParent()});const x=n.added;return[...c,...u,...f].forEach(y=>{x.push(y),i&&e&&e.add(y)}),this.MergeInfo.removedObjects+=m.length,this.MergeInfo.mergedMeshes+=c.length,this.MergeInfo.mergedLines+=u.length,this.MergeInfo.mergedPoints+=f.length,s&&e&&$.removeEmptyObjects(e),n}static applyMatrix(t,e,i){let s=e;for(Oi.identity();s&&s!==i&&(Oi.premultiply(s.matrix),!!s.parent);)s=s.parent;return Oi.equals(Go)?t:t.applyMatrix4(Oi)}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===H.Line||t.type===H.LineSegment)&&(e.type===H.Line||e.type===H.LineSegment)}}p(et,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const pn=(h,t)=>{if(typeof t>"u"||+t==0)return Math.round(h);let e=+h;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))},mn=(h,t,e,i,s)=>{const r=e.length,n=e[0].length;if(h<0||h>1)throw new Error("t out of bounds [0,1]: "+h);if(t<1)throw new Error("degree must be at least 1 (linear)");if(t>r-1)throw new Error("degree must be less than or equal to point count - 1");if(i){if(i.length!==r+t+1)throw new Error("bad knot vector length")}else{i=[];for(let g=0;g<r+t+1;g++)i[g]=g}const a=[t,i.length-1-t],o=i[a[0]],l=i[a[1]];h=h*(l-o)+o,h=Math.max(h,o),h=Math.min(h,l);let c;for(c=a[0];c<a[1]&&!(h>=i[c]&&h<=i[c+1]);c++);const u=[];for(let g=0;g<r;g++){u[g]=[];const x=s?s[g]:1;for(let y=0;y<n;y++)u[g][y]=e[g][y]*x;u[g][n]=x}let f;for(let g=1;g<=t+1;g++)for(let x=c;x>c-t-1+g;x--){f=(h-i[x])/(i[x+t+1-g]-i[x]);for(let y=0;y<n+1;y++)u[x][y]=(1-f)*u[x-1][y]+f*u[x][y]}const m=[];for(let g=0;g<n;g++)m[g]=pn(u[c][g]/u[c][n],-9);return m},qo={d:"°",c:"⌀",p:"±"},li=(h,t)=>{if(!h)return[];h=h.replace(/%%(.)/g,(o,l)=>qo[l]||l).replace(/\^I/g," ");const e=t?.encoding;let i=e instanceof TextDecoder?e:void 0,s="",r;const n=[],a=o=>{s&&(n.push(s),s=""),n.push(o)};for(let o=0;o<h.length;o++)switch(r=h[o]){default:s+=r;break;case"\\":{switch(r=h[++o]){default:s+=r;break;case"p":{const l=h.slice(o,o=h.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(;r=h[++o];){if(r===";"){a({f:l});break}if(r==="|"){const c={f:l},u=h.indexOf(";",++o);for(const f of h.slice(o,u).split("|"))c[f[0]]=+f.slice(1);o=u,a(c);break}l+=r==="\\"?h[++o]:r}break}case"S":{let l="",c,u="";for(;r=h[++o];){if(r===";"){const f=l+u;f&&a(f);break}if(r==="\\"){const f=h[++o];c?u+=f:l+=f}else!c&&(r==="^"||r==="/"||r==="#")?c=r:c?u+=r:l+=r}break}case"H":case"W":{const l=++o,[,c,u]=h.slice(l,o=h.indexOf(";",o)).match(/^(\d*(?:\.\d+)?)(\D*)$/);a({[r]:[+c,u]})}break;case"Q":case"A":case"C":case"c":case"T":{const l=++o;a({[r]:+h.slice(l,o=h.indexOf(";",o))});break}case"L":case"O":case"K":a({[r]:1});break;case"l":case"o":case"k":a({[r.toUpperCase()]:0});break;case"U":case"u":h[o+1]==="+"?(s+=String.fromCodePoint(parseInt(h.substr(o+2,4),16)),o+=5):s+=r;break;case"M":case"m":e?h[o+1]==="+"&&(h[o+2]==="0"||h[o+2]==="1")?(s+=(i=i||new TextDecoder(e)).decode(new Uint8Array([parseInt(h.substr(o+3,2),16),parseInt(h.substr(o+5,2),16)])),o+=6):s+=r:s+="\\"+r;break}break}case"{":{let l=1;const c=o;for(;r=h[++o];)if(r==="{")l++;else if(r==="}"){if(--l===0){a(li(h.slice(c+1,o)));break}}else r==="\\"&&o++;break}}return s&&n.push(s),n},Wo={d:"°",c:"⌀",p:"±"},gn=(h,t)=>(h=yn(h),t?xn(h,t):h),yn=h=>h.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),xn=(h,t)=>{let e=t instanceof TextDecoder?t:new TextDecoder(t);return h.replace(/\\[mM]\+[0|1]([0-9a-fA-F]{2})([0-9a-fA-F]{2})/g,(i,s,r)=>(e=e||new TextDecoder(t)).decode(new Uint8Array([parseInt(s,16),parseInt(r,16)])))},Ni=(h,t)=>{h=gn(h,t?.encoding);let e=0,i={text:""};const s=[i],r=h.matchAll(/%%(\d\d\d|.)/g);for(const n of r){i.text+=h.slice(e,n.index);const a=n[1],o=a.toLowerCase(),l=Wo[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=n.index+n[0].length}return i.text+=h.slice(e),s.filter(n=>n.text)};class bn{static createLineShaderMaterial(t,e,i,s,r){let n=0;const a=[];for(let u=0;u<t.length;u++)a[u]=t[u],a[u]===0&&(a[u]=.5),a[u]*=i,n+=Math.abs(a[u]);const o=d.UniformsUtils.merge([d.UniformsLib.common,{pattern:{value:a},patternLength:{value:n},u_color:{value:new d.Color(e)}}]);o.u_viewportScale=s,o.u_cameraZoom=r;const l=`
534
+ `,De=p.ShaderChunk;De.outline_bc_vertex=xh;De.outline_bc_fragment=bh;De.outline_bc_pars_fragment=wh;De.outline_bc_pars_vertex=vh;De.standard_ex_vertex=Eh;De.standard_ex_fragment=Oh;De.common_ex=mh;De.id_pars_vertex=gh;De.id_vertex=yh;De.state_pars_fragment=Mh;De.state_fragment=Th;De.state_transparent_fragment=Ch;De.state_highlight_fragment=Sh;De.pick_ex_vertex=_h;De.pick_ex_fragment=Ph;const Ah=p.ShaderChunk;class Ih{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 Bh=Lr.default??Lr,P=Bh;P.setLevel("warn");const yo=c=>{try{P.setLevel(c)}catch(t){P.setLevel("error"),P.error(t)}},Ci=class Ci{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=Ci.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(Ci,"isMobile",/mobile/i.test(navigator.userAgent)),g(Ci,"isBrowser",typeof document<"u"),g(Ci,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let Ie=Ci;const Si=class Si{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(!Ie.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(!Ie.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 Si.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 Si.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 Si.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(Si,"twinklingObjectIds",{});let j=Si;const kh=(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 Pi{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 Se{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=Se.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=Se.world2Screen(s,e,i);return r.x/=i.clientWidth,r.y/=i.clientHeight,r}}class Dh{static createCSS2DObject(t){const e=new ho.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 xo={"Precision from file":99},Lh=(c,t)=>c.toFixed(t===xo["Precision from file"]?2:t),bo="en",ot=!1,wo=10,Fe=11,Ft=12,Mr=583902,Rh=[.031,.906,.867,.5],$s=[.3,.3,.3,.8],Tr=.5,Js=.1,Qs=5e3,vo=45,Fh="x-viewer-iconfont",zh="x-viewer-iconfont2",Cr=10,sa=new p.Vector3,na=new p.Vector3,ra=new p.Vector3,Ji=new p.Vector3,Tt=new p.Vector3,aa=new p.Triangle;function Vh(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 jh(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;sa.set(e[r],e[r+1],e[r+2]),na.set(e[a],e[a+1],e[a+2]),ra.set(e[o],e[o+1],e[o+2]),p.Triangle.getNormal(sa,na,ra,Ji),i.push({normal:Ji.clone()})}}const An=[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 Uh(c,t){return Tt.addVectors(c,t),Tt.x===0||Tt.y===0||Tt.z===0}class Mo{static buildEdge(t,e,i=Cr){const s=[],n=[],r=[];Vh(t,e,s,n,r);const a=[];jh(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),S=w+","+x;h[S]===void 0?h[S]={index1:w,index2:x,face1:m,face2:void 0}:h[S].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=An.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}=aa;if(_.fromBufferAttribute(e,o[0]),A.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),aa.getNormal(Ji),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 R=(k+1)%3,z=l[k],oe=l[R],le=o[k],$e=o[R];!u[le]&&(u[le]=new Set),u[le].add($e),!u[$e]&&(u[$e]=new Set),u[$e].add(le);const jt=z+"_"+oe,Je=oe+"_"+z;if(Je in b&&b[Je]){if(b[Je].outer){P.warn("[Edge] edge: "+Je+" is already outer!");continue}Ji.dot(b[Je].normal)<=n?b[Je].outer=!0:b[Je].find=!0}else jt in b?P.warn("[Edge] "+jt+" has existed in geometry!"):b[jt]={startIndex:le,endIndex:$e,normal:Ji.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 S=new Set;for(let T=0;T<y.length;T++)y[T].forEach(A=>{S.has(A)?P.warn("[Edge] "+A+" is already in positionIndexSet!"):S.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 R=B+"_"+I;b[R]&&(A=b[R].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},E=(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),R=d[B];if(!R.inited)continue;const z=Uh(_,R.point);if(k&&!z||!k&&z)return!1}const I=f[T];for(const B of I){const k=_;let R=d[B.b],z=d[B.c];if(B.b===T?R=d[B.a]:B.c===T&&(z=d[B.a]),O(B.a,B.b,B.c)&&(R.inited&&k.equals(R.point)||z.inited&&k.equals(z.point)))return!1;if(!(!R.inited||!z.inited)&&(Tt.addVectors(k,R.point),Tt.add(z.point),Tt.x+Tt.y+Tt.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&&!E(A,An[B]);B++);if(B<h)if(d[A].inited=!0,d[A].barycentricIndex=B,d[A].point.copy(An[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 Vt{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 Sl.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 El.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 Cl.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 Ol.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 cr=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 In=1e-15,oa=new p.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),la=new p.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class F{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 F.areNumbersEqual(t.x,e.x,i)&&F.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return F.areNumbersEqual(t.x,e.x,i)&&F.areNumbersEqual(t.y,e.y,i)&&F.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 F.areNumbersClose(t,e,In)?0:(t%=i,F.areNumbersClose(t,e%i,In)?i:(F.areNumbersClose(e,i,In)&&(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=F.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(F.getRelativeEps(t.x,e),F.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(oa.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(oa),e}static convertPointFromUEToRevit(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(la.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(la),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=F.convertPointFromGltfToUE(t.min),i=F.convertPointFromGltfToUE(t.max);return F.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=F.convertPointFromUEToGltf(t.min),i=F.convertPointFromUEToGltf(t.max);return F.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=F.convertPointFromRevitToUE(t.min),i=F.convertPointFromRevitToUE(t.max);return F.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=F.convertPointFromUEToRevit(t.min),i=F.convertPointFromUEToRevit(t.max);return F.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 F.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=F.fromSnorm(t.x,i),e.y=F.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))*F.signNotZero(s),e.y=(1-Math.abs(s))*F.signNotZero(e.y)}}}const Bn=1e7,ca=new p.Box2,ha=new p.Box2,da=new p.Vector3,ua=new p.Vector3,fa=new p.Vector3,Ot=new p.Triangle;class H{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=da.subVectors(s,i).normalize(),o=ua.subVectors(r,n).normalize();if(a.dot(o)===1)return null;const l=fa.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(F.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=da.subVectors(s,n).length(),a=ua.subVectors(t,s).length(),o=fa.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(H.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)>Bn||Math.abs(t.y)>Bn||t instanceof p.Vector3&&Math.abs(t.z)>Bn}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)Ot.a.fromBufferAttribute(i,s.getX(n)),Ot.b.fromBufferAttribute(i,s.getX(n+1)),Ot.c.fromBufferAttribute(i,s.getX(n+2)),e+=Ot.getArea();else for(let n=0;n<i.count;n+=3)Ot.a.fromBufferAttribute(i,n),Ot.b.fromBufferAttribute(i,n+1),Ot.c.fromBufferAttribute(i,n+2),e+=Ot.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,H.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||(ca.setFromPoints(t),ha.setFromPoints(e),!ca.intersectsBox(ha)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&F.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,S=t.length-1;x<S;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}=_l.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++)F.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 Hh={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"}},hr={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"}},Ke=Pl.createInstance(),Gh="cn";Ke.init({lng:Gh,debug:!1,resources:{en:{translation:hr},cn:{translation:hr}}});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(Mr),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 qh=new p.Vector3(0,1,0),qe=class qe{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 qe.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);qe.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);qe.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);qe.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,Cr),n=new p.LineSegments(s,e);return n.layers.enableAll(),qe.disableLayerChannels(n,[Ft,Fe]),n.userData.isOutline=!0,n.matrixAutoUpdate=ot,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=qh;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++)qe.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++)qe.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++)qe.setLayerChannels(s[n],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(wo)}static isObjectSnapable(t){return t.layers.isEnabled(Fe)}static isObjectSelectable(t){return t.layers.isEnabled(Ft)}};g(qe,"OUTLINE_MATERIAL",new p.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),g(qe,"BOX_FACE_MATERIAL",new p.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:p.FrontSide}));let J=qe;const Ds=new p.Matrix4,Wh=new p.Matrix4,ss=class ss{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 S=t.children[x],M=S.geometry.clone();if(M.applyMatrix4(S.matrix),H.tryConvertInterleavedBufferAttributes(M),M.userData.isLineSegments=S.isLineSegments===!0,f.push(M),e){const O=S.name,E=M.attributes?.position?.count,v=M.index?.count||0,T={batchId:m,name:O,positionStart:b,positionCount:E,indexStart:y,indexCount:v};Object.keys(S.userData).length!==0&&(T.userData=S.userData),C.push(T),b+=E,y+=v,m++}}),f.length===0)return;let w;if(u.isMesh){const x=_e.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=_e.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=ot,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,w.visible=u.visible,l.push(...d)),f.forEach(x=>{x.dispose(),H.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 S=x.length-1;S>=0;--S){const M=x[S].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let S=l.length-1;!w&&S>=0;--S){const M=l[S];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=[],S=0,M=0,O=0;const E=[];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 R;w.isLine&&(!A.boundingSphere&&A.computeBoundingSphere(),R=A.boundingSphere.clone());const z={batchId:S,name:I,positionStart:M,positionCount:B,indexStart:O,indexCount:k,boundingSphere:R};!_.parent.geometry&&Object.keys(_.parent.userData).length!==0&&(z.parentUserData=_.parent.userData),Object.keys(_.userData).length!==0&&(z.userData=_.userData),E.push(z),M+=B,O+=k,S++}}),x.length===0)return;let v;if(w.isMesh){const T=_e.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,E);if(!T)return;v=new p.LineSegments(T,w.material),d.push(v)}else if(w.isPoints){const T=_e.mergeGeometries(x);if(!T)return;T.userData={},v=new p.Points(T,w.material),u.push(v)}v&&(n?v.userData.batches=E:(v.userData=w.userData,v.userData.batches=void 0),v.userData.layerName=w.userData.layerName,v.name="[Merged] "+w.name,v.matrixAutoUpdate=ot,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(),H.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(Ds.identity();s&&s!==i&&(Ds.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ds.equals(Wh)?t:t.applyMatrix4(Ds)}static mergeLineGeometries(t,e,i,s){let n;if(i)n=ss.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(n=_e.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=H.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=ss.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 S=0;S<m;S++)b[y+S]=d.array[w+S],x&&(b[y+m+S]=d.array[w+S]);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(ss,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let fe=ss;const Yh=.01;class Xh{static getFaces(t){const e=t.map(n=>n.toArray()).reduce((n,r)=>(n.push(...r),n),[]),i=[];return Al.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()>Yh)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return Il(e).length>0}}class Ct{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=Ct.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 Ct.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=Ct.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(j.isMatrixValid(a.matrixWorld)){const o=Ct.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=Ct.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class Dt{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=>{Dt.setMaterialSection(a,e,i,s)}):r&&Dt.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 Zh{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new Bl.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 Kh=10;var Mt=(c=>(c.TripleCross="TripleCross",c.Square="Square",c.Triangle="Triangle",c.CircleWithCross="CircleWithCross",c.Cross="Cross",c.Perpendicular="Perpendicular",c))(Mt||{});class $h{static createSVGObject(t){return new kl.SVGObject(t)}}class os{static async createEnvTexture(t,e){const i=new Dl.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(os,"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 Jh(){if(Ie.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 dr={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:Jh()},To={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},Co=c=>c===2?"²":c===3?"³":"",ur=(c,t=1)=>To[c]+Co(t),Qh=(c,t,e,i=1)=>(e==null&&(e=t),e===t?{value:c,unit:ur(e)}:{value:c*Math.pow(dr[t]/dr[e],i),unit:ur(e)+Co(i)});var So=(c=>(c.Top="Top",c.Bottom="Bottom",c.Front="Front",c.Back="Back",c.Left="Left",c.Right="Right",c))(So||{});class ed{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 he=(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))(he||{});const pa={};class ds extends Vt{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;pa[i.prototype.getClassType()]=e}static createDrawable(e){const i=pa[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(he.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(Ie.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=Ie.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 us extends Vt{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=ds.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 zt extends Vt{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?Se.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 kn=new p.Vector3;class gt extends zt{constructor(e,i,s=[1,0,0,1],n){super(e);g(this,"boxes");g(this,"lineSegments");this.lineSegments=[],this.boxes=gt.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(kn),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=kn.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=kn.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=Pi.rgba2Color(this.lineColor),e.fillStyle=Pi.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=gt.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"}}ds._registerDrawableClass(gt);const td=[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],id=["PROXY","REGION","INSERT","HATCH"];function Oi(c){return td[c]}function Ge(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 sd="OriginalHandle",nd="OriginalType",rd="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=Oi(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(sd)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalHandle=e[1]}if(t.value.includes(rd)&&(c.extendedData||(c.extendedData={}),c.extendedData.outlines=[]),t.value.includes(nd)){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 Bi(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 Sr="BYLAYER",ls="BYBLOCK";var Ee=(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))(Ee||{});const Qi=["INSERT","DIMENSION"];function ad(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 od(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 ld(c,t){const e=ma(c.text).plainText,i=ma(t.text).plainText;return e===i}var Re=(c=>(c.Added="Added",c.Removed="Removed",c.Modified="Modified",c.NoChange="NoChange",c))(Re||{});let Be=1;const wt=class wt{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;!wt.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;!wt.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[Be]={id:Be,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[Be]={id:Be,...a,parentHandles:o}),Be++}}),!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[Be]={id:Be,type:"Removed",handle:r},Be++;else{const a=t[n],o=e.get(r),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(Qi.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[Be]={id:Be,type:"Modified",handle:r},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[Be].detailChanges=l),Be++}e.delete(r)}await s(n)}for(const n of e){const r=n[0];this.changes[Be]={id:Be,type:"Added",handle:r},Be++}}bIgnoreChildEntitiesOriginalType(t){return id.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!==Sr&&t.lineType!==ls)return t.lineType;if(t.lineType===ls)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(!ld(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?F.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(wt,"ENTITY_COLOR_ADDED",65280),g(wt,"ENTITY_COLOR_REMOVED",16711680),g(wt,"ENTITY_COLOR_NO_CHANGE",10066329),g(wt,"ENTITY_COLOR_MARKUP",16744231),g(wt,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let nt=wt;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 Dn=new D.Box3,Ln=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=ot,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(),Ln.copy(t.matrix),i&&Ln.premultiply(i),Dn.copy(t.geometry.boundingBox),Dn.applyMatrix4(Ln),e.union(Dn);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 Ls=new p.Matrix4,cd=new p.Matrix4;class bt{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 S=t.children[x],M=S.geometry?.clone();if(M.applyMatrix4(S.matrix),M.userData.isLineSegments=S.type===G.LineSegment,f.push(M),e){const O=M.attributes?.position?.count,E=M.index?.count||0;C.push({batchId:m,positionStart:b,positionCount:O,indexStart:y,indexCount:E}),b+=O,y+=E,m++}}),f.length===0)return;let w;if(u.type===G.Mesh){const x=_e.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=_e.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(),H.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 S=x.length-1;S>=0;--S){const M=x[S].indexes[0];if(w=this.tryHandleMergeableObjects(t,y,M,o,l),w)break}for(let S=l.length-1;!w&&S>=0;--S){const M=l[S];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=[],S=0,M=0,O=0;const E=[];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 R={batchId:S,positionStart:M,positionCount:I,indexStart:O,indexCount:B,boundingSphere:k};Object.keys(_.userData).length!==0&&(R.userData=_.userData),E.push(R),M+=I,O+=B,S++}}),x.length===0)return;let v;if(w.type===G.Mesh){const T=_e.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,E);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=_e.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=E:(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(),H.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(Ls.identity();s&&s!==i&&(Ls.premultiply(s.matrix),!!s.parent);)s=s.parent;return Ls.equals(cd)?t:t.applyMatrix4(Ls)}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(bt,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});const Eo=(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))},Oo=(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]=Eo(d[h][m]/d[h][r],-9);return f},hd={d:"°",c:"⌀",p:"±"},es=(c,t)=>{if(!c)return[];c=c.replace(/%%(.)/g,(o,l)=>hd[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(es(c.slice(h+1,o)));break}}else n==="\\"&&o++;break}}return s&&r.push(s),r},dd={d:"°",c:"⌀",p:"±"},_o=(c,t)=>(c=Po(c),t?Ao(c,t):c),Po=c=>c.replace(/\\[uU]\+([0-9a-fA-F]{4})/g,(t,e)=>String.fromCodePoint(parseInt(e,16))),Ao=(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)])))},en=(c,t)=>{c=_o(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=dd[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 Io{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
 
@@ -545,7 +545,7 @@ void main() {
545
545
  #include <begin_vertex>
546
546
  #include <project_vertex>
547
547
  #include <clipping_planes_vertex>
548
- }`,c=`
548
+ }`,h=`
549
549
  uniform mat4 modelMatrix;
550
550
  uniform vec3 diffuse;
551
551
  uniform vec3 u_color;
@@ -588,7 +588,7 @@ void main() {
588
588
  }
589
589
  }
590
590
  #include <colorspace_fragment>
591
- }`;return new d.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:c,clipping:!0})}}function vn(h,t,e,i,s=0){const r={u_cameraZoom:e,u_patternLines:{value:h},u_patternAngle:{value:t},u_color:{value:i}},n=`
591
+ }`;return new p.ShaderMaterial({uniforms:o,vertexShader:l,fragmentShader:h,clipping:!0})}}function Bo(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>
@@ -614,7 +614,7 @@ void main() {
614
614
  float patternLength;
615
615
  };
616
616
 
617
- uniform PatternLine u_patternLines[${h.length}];
617
+ uniform PatternLine u_patternLines[${c.length}];
618
618
  uniform float u_patternAngle;
619
619
 
620
620
  #include <clipping_planes_pars_fragment>
@@ -767,7 +767,7 @@ void main() {
767
767
 
768
768
  float total = 0.0;
769
769
 
770
- #if ${h.length} > 1
770
+ #if ${c.length} > 1
771
771
  #pragma unroll_loop_start
772
772
  for (int i = 0; i < u_patternLines.length(); i++) {
773
773
  PatternLine pl = u_patternLines[i];
@@ -788,20 +788,20 @@ void main() {
788
788
  gl_FragColor = vec4(u_color * total, 1.0);
789
789
  #include <colorspace_fragment>
790
790
  }
791
- `;return new d.ShaderMaterial({uniforms:r,vertexShader:n,fragmentShader:a,clipping:!0})}var De=(h=>(h.Unitless="Unitless",h.Inches="Inches",h.Feet="Feet",h.Millimeters="Millimeters",h.Centimeters="Centimeters",h.Meters="Meters",h))(De||{});const Ps=h=>h==="Unitless"?1:h==="Inches"?.0254:h==="Feet"?.3048:h==="Millimeters"?.001:h==="Centimeters"?.01:(h==="Meters"||console.warn("[Units] Unsupported unit '"+h+"', will return 1 for unit scale."),1),Yo=(h,t)=>Ps(h)/Ps(t);class wn{constructor(){p(this,"pointer");p(this,"eof");p(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class vi{constructor(t,e){p(this,"endian");p(this,"position");p(this,"data");p(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=wi.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,wi.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=wi.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,wi.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 hr=1e3;class Xo extends wn{constructor(e){super();p(this,"reader");p(this,"decoder");p(this,"int8Array");p(this,"caches");this.int8Array=new Int8Array(hr),this.caches=new Map,this.reader=new vi(e);const i=this.reader.readBytes(22);let s="";for(let r=0;r<18;r++)s+=String.fromCharCode(i[r]);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 cr(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 cr(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>hr)return console.warn("[DxfBinReader] Failed to read string! The number of bytes is "+e+" !"),"";const s=this.int8Array.subarray(0,e),r=s.toString();if(this.caches.get(r))return this.caches.get(r);const n=this.decoder?.decode(s);return this.caches.set(r,n),n}ReadBinaryData(){const e=this.reader.readUint8();return this.reader.readBytes(e)}}function cr(h){return Array.prototype.map.call(h,t=>("00"+t.toString(16)).slice(-2)).join("")}class dr extends wn{constructor(e){super();p(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=Zo(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 Zo(h,t,e){return h>=0&&h<=9?e:h>=10&&h<=59?parseFloat(t):h>=60&&h<=99?parseInt(t):h>=100&&h<=109?t:h>=110&&h<=149?parseFloat(t):h>=160&&h<=179?parseInt(t):h>=210&&h<=239?parseFloat(t):h>=270&&h<=289?parseInt(t):h>=290&&h<=299?Ko(t):h>=300&&h<=369?t:h>=370&&h<=389?parseInt(t):h>=390&&h<=399?t:h>=400&&h<=409?parseInt(t):h>=410&&h<=419?t:h>=420&&h<=429?parseInt(t):h>=430&&h<=439?t:h>=440&&h<=449?parseInt(t):h>=450&&h<=459?parseFloat(t):h>=460&&h<=469||h===999||h>=1e3&&h<=1009?t:h>=1010&&h<=1059?parseFloat(t):h>=1060&&h<=1071?parseInt(t):(console.info("WARNING: Group code does not have a defined type: %j",{code:h,value:t}),t)}function Ko(h){if(h==="0")return!1;if(h==="1")return!0;throw TypeError("String '"+h+"' cannot be cast to Boolean type")}function $o(h){if(h==null)return!0;for(const t in h)if(Object.prototype.hasOwnProperty.call(h,t))return!1;return!0}function Jo(h,t){const e=[];let i=!1,s=!1;const r=4;for(let n=0;n<=r;n++){const a={};for(;!h.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=h.next()}$o(a)||e.push(a),i=!1,s=!1}return e}class Qo{constructor(){p(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=Jo(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}class el{constructor(){p(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=tl(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:Q(i,e),e=t.next();break}return i}}function tl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class il{constructor(){p(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=ur(t),e=t.lastReadGroup;break;case 11:i.endPoint=ur(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:Q(i,e),e=t.next();break}return i}}function ur(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class sl{constructor(){p(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=fr(t),e=t.lastReadGroup;break;case 11:i.endPoint=fr(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:Q(i,e),e=t.next();break}return i}}function fr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class rl{constructor(){p(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=nl(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:Q(i,e),e=t.next();break}return i}}function nl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class al{constructor(){p(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=xt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=xt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=xt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=xt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=xt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=xt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=xt(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:Q(i,e),e=t.next();break}return i}}function xt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class ol{constructor(){p(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(_e(t)),e=t.lastReadGroup;break;case 305:return;default:e=t.next();break}},r=()=>{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=_e(t),e=t.lastReadGroup;break;case 11:o.doglegVector=_e(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}},n=()=>{for(;!t.isEOF();)switch(e.code){case 40:i.contextData.contentScale=e.value,e=t.next();break;case 10:i.contextData.contentBasePosition=_e(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=_e(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=_e(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=_e(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=_e(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=_e(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=ll(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=_e(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=_e(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=_e(t),e=t.lastReadGroup;break;case 297:i.contextData.planeNormalReversed=e.value,e=t.next();break;case 301:return;case 302:r(),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=_e(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:n(),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}})(),i}}function _e(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.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=h.next()}return t}function ll(h,t){const e=[];let i=h.lastReadGroup||h.next();for(;!h.isEOF()&&(i.code>=t&&i.code<t+16);){e.push(i.value);i=h.next()}return e}class hl{constructor(){p(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=hs(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=hs(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=hs(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function hs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}var Mn=(h=>(h[h.Default=0]="Default",h[h.External=1]="External",h[h.Polyline=2]="Polyline",h[h.Derived=4]="Derived",h[h.Textbox=8]="Textbox",h[h.Outermost=16]="Outermost",h[h.MaxFlags=31]="MaxFlags",h))(Mn||{}),Lt=(h=>(h[h.Polyline=0]="Polyline",h[h.Line=1]="Line",h[h.Arc=2]="Arc",h[h.Ellipse=3]="Ellipse",h[h.Spline=4]="Spline",h))(Lt||{});function Rt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;if(e.code===i)if(t.x=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;if(e.code===i+10)if(t.y=e.value,!h.isEOF()&&h.hasNext())e=h.next();else return t;return e.code===i+20&&(t.z=e.value,!h.isEOF()&&h.hasNext()&&(e=h.next())),t}function cl(h){const t={type:0,points:[],isClosed:!0};let e=h.next();const i=e.value!==0;e=h.next(),t.isClosed=e.value!==0,e=h.next();const s=e.value;e=h.next();for(let n=0;n<s;n++){const a=Rt(h);e=h.lastReadGroup,i&&(a.bulge=e.value,e=h.next()),t.points.push(a)}e=h.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const r=e.value;e=h.next();for(let n=0;n<r;n++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=h.next();return{edges:[t],pathTypeFlag:-1}}function dl(h,t){const e=[];let i=t.next();for(;e.length<h;){if(i.code!==72){i=t.next();continue}switch(i.value){case 1:{i=t.next();const n={type:1,startPoint:Rt(t),endPoint:Rt(t)};i=t.lastReadGroup,e.push(n);break}case 2:{i=t.next();const n={type:2,center:Rt(t),radius:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.radius=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 3:{i=t.next();const n={type:3,center:Rt(t),majorAxisEndPoint:Rt(t),minorRatio:0,startAngle:0,endAngle:0,bCounterclockwise:!1};i=t.lastReadGroup,n.minorRatio=i.value,i=t.next(),n.startAngle=i.value,i=t.next(),n.endAngle=i.value,i=t.next(),n.bCounterclockwise=i.value!==0,i=t.next(),e.push(n);break}case 4:{i=t.next();const n={type:4,degreeOfSplineCurve:i.value,bRational:!1,bPeriodic:!1,numKnots:0,numControlPoints:0,knotValues:[],controlPoints:[]};i=t.next(),n.bRational=i.value!==0,i=t.next(),n.bPeriodic=i.value!==0,i=t.next(),n.numKnots=i.value,i=t.next(),n.numControlPoints=i.value,i=t.next();for(let a=0;a<n.numKnots;a++)n.knotValues.push(i.value),i=t.next();for(let a=0;a<n.numControlPoints;a++){const o=i.value;i=t.next();const l=i.value;let c=1;i=t.next(),i.code===42&&(c=i.value,i=t.next()),n.controlPoints.push({x:o,y:l,z:c})}e.push(n);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 r=0;r<s;r++)console.assert(i.code===330,"The reference handle code 330 was expected."),i=t.next();return{edges:e,pathTypeFlag:-1}}function ul(h,t){const e=[];let i=-1,s=t.next();for(;e.length<h;){let r;switch(s.code){case 92:if(i=s.value,i&2){if(r=cl(t),r)r.pathTypeFlag=i,e.push(r);else throw new Error("[Hatch] Failed to parse hatch polyline boundary path !");s=t.lastReadGroup}else s=t.next();break;case 93:{const n=s.value;r=dl(n,t),r.pathTypeFlag=i,e.push(r),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function fl(h,t){if(h<=0){t.next();return}const e=[];let i=t.next();for(let s=0;s<h;s++){let r=0;const n={x:0,y:0},a={x:0,y:0};let o=-1;const l=[];for(;!t.isEOF()&&i.code!==0;){let c=!1;switch(i.code){case 53:r=i.value;break;case 43:n.x=i.value;break;case 44:n.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:c=!0}if(i=t.next(),c||l.length===o)break}o>=0&&e.push({angle:r,origin:n,delta:a,dashPattern:l})}return e}function pl(h,t){const e=[];let i=t.next();for(;e.length<h&&!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 ml{constructor(){p(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=fl(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=ul(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=pl(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:Q(i,e),e=t.next();break}return i}}var Gi=(h=>(h[h.ShowImage=1]="ShowImage",h[h.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",h[h.UseClippingBoundary=4]="UseClippingBoundary",h[h.TransparencyIsOn=8]="TransparencyIsOn",h))(Gi||{});let gl=class{constructor(){p(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=Kt(t),e=t.lastReadGroup;break;case 11:i.uPixel=Kt(t),e=t.lastReadGroup;break;case 12:i.vPixel=Kt(t),e=t.lastReadGroup;break;case 13:i.imageSize=Kt(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(Kt(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:Q(i,e),e=t.next();break}return i}};function Kt(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.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=h.next()}return t}class yl{constructor(){p(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=pr(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=pr(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:Q(i,e),e=t.next();break}return i}}function pr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}function xl(h){switch(h){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 bl{constructor(){p(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(vl(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 r=xl(e.value);r&&(e=t.next(),(e.code==1005||e.code==1040||e.code==1070)&&(r==="DIMLDRBLK"?i.arrowHeadBlockHandle=e.value:r==="DIMASZ"?i.arrowHeight=e.value:r==="DIMSCALE"?i.arrowHeadScale=e.value:r==="DIMCLRD"&&e.value>0&&(i.colorIndex=e.value,i.color=Nt(Math.abs(e.value)))))}e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function vl(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class wl{constructor(){p(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(cs(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(cs(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=cs(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function cs(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}function Ml(h,t){if(!h||h<=0)throw Error("n must be greater than 0 verticies");const e=[];let i=!1,s=!1,r=t.lastReadGroup;const n={};for(;!t.isEOF()&&!(r.code===0||s);)switch(r.code){case 10:if(i){s=!0;continue}n.x=r.value,i=!0,r=t.next();break;case 20:n.y=r.value,r=t.next();break;case 30:n.z=r.value,r=t.next();break;case 40:n.startWidth=r.value,r=t.next();break;case 41:n.endWidth=r.value,r=t.next();break;case 42:r.value!=0&&(n.bulge=r.value),r=t.next();break;default:return i&&e.push(n),e}return e.push(n),i=!1,s=!1,e}class Tl{constructor(){p(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(...Ml(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:Q(i,e),e=t.next();break}return i}}class Cl{constructor(){p(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 r=e.value;i.text?i.text+=r:i.text=r,e=t.next();break;case 10:i.position=mr(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=mr(t),i.rotation=void 0,e=t.lastReadGroup;break;case 40:i.height=e.value,e=t.next();break;case 41:const n=e.value;Math.abs(n)<1e-6?i.width=void 0:i.width=n,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:Q(i,e),e=t.next();break}return i}}function mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Sl{constructor(){p(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:Q(i,e),e=t.next();break}return i}}class Ol{constructor(){p(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=gr(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=gr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function gr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class El{constructor(){p(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:Q(i,e),e=t.next();break}return i}}function _l(h,t){const e=new El,i=[];for(;!h.isEOF();)if(t.code===0){if(t.value==="VERTEX")i.push(e.parseEntity(h,t)),t=h.lastReadGroup;else if(t.value==="SEQEND"){Pl(h,t);break}}return i}function Pl(h,t){const e={type:t.value};for(t=h.next();!h.isEOF()&&t.code!==0;)if(t.code===101)for(;t.code!=0;)t=h.next();else Q(e,t),t=h.next();return e}class Al{constructor(){p(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=Il(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i.vertices=_l(t,e),i}}function Il(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class kl{constructor(){p(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:Q(i,e),e=t.next();break}return i}}class Dl{constructor(){p(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(yr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=yr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function yr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Bl{constructor(){p(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(Q(i,e),e=t.next());return i}}class Ll{constructor(){p(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]=$t(t),e=t.lastReadGroup;break;case 11:i.points[1]=$t(t),e=t.lastReadGroup;break;case 12:i.points[2]=$t(t),e=t.lastReadGroup;break;case 13:i.points[3]=$t(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=$t(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function $t(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Rl{constructor(){p(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(Jt(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(Jt(t)),e=t.lastReadGroup;break;case 12:i.startTangent=Jt(t),e=t.lastReadGroup;break;case 13:i.endTangent=Jt(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=Jt(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function Jt(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}function Fl(h,t,e){let i=h;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 xr(h,t){const e={};for(h.code===171&&(e.cellType=h.value);!t.isEOF();){const i=t.next();if(i.code===0||i.code===171){t.lastReadGroup=i;break}if(i.code===301){Fl(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 zl{constructor(){p(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=br(t),e=t.lastReadGroup;break;case 11:i.directionVector=br(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(xr(e,t)):i.cells=[xr(e,t)],e=t.lastReadGroup;break;default:Q(i,e),e=t.next();break}return i}}function br(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class jl{constructor(){p(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=vr(t),e=t.lastReadGroup;break;case 11:i.endPoint=vr(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:Q(i,e),e=t.next();break}return i}}function vr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Vl{constructor(){p(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=qe(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=qe(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=qe(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=qe(t),e=t.lastReadGroup;break;case 16:i.viewDirection=qe(t),e=t.lastReadGroup;break;case 17:i.viewTarget=qe(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=qe(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=qe(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=qe(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:Q(i,e),e=t.next();break}return i}}function qe(h){const t={};let e=h.lastReadGroup||h.next();for(;!h.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=h.next()}return t}class Ul{constructor(){p(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(wr(t)),e=t.lastReadGroup;break;case 11:i.directionVector=wr(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:Q(i,e),e=t.next();break}return i}}function wr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Hl{constructor(){p(this,"ForObjectName","DICTIONARY")}parseObject(t,e){const s={type:e.value},r=[],n=[];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:r.push(e.value),e=t.next();break;case 350:n.push(e.value),e=t.next();break;case 360:n.push(e.value),e=t.next();break;case 100:e=t.next();break;case 102:e=t.next();break;default:Xt(s,e),e=t.next();break}if(r.length!==n.length)throw new Error("The number of Dictionary entries does not match !");return s.entries={},r.forEach((a,o)=>{s.entries[n[o]]=a}),s}}class Nl{constructor(){p(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=Mr(t),e=t.next();break;case 11:s.pixelSize=Mr(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:Xt(s,e),e=t.next();break}return s}}function Mr(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Gl{constructor(){p(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=ot(t),e=t.lastReadGroup;break;case 11:s.maxLimit=ot(t),e=t.lastReadGroup;break;case 12:s.basePoint=ot(t),e=t.lastReadGroup;break;case 13:s.origin=ot(t),e=t.lastReadGroup;break;case 14:s.minExtent=ot(t),e=t.lastReadGroup;break;case 15:s.maxExtent=ot(t),e=t.lastReadGroup;break;case 16:s.XAxis=ot(t),e=t.lastReadGroup;break;case 17:s.YAxis=ot(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:Xt(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function ot(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class ql{constructor(){p(this,"ForObjectName","SORTENTSTABLE")}parseObject(t,e){const s={type:e.value};let r=!1;s.sortEntsObject={},s.sortEntsObject.entityHandles=[];let n=[];for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 5:r?(n.push(e.value),s.sortEntsObject.entityHandles.push(n),n=[]):s.handle=e.value,e=t.next();break;case 100:e=t.next(),r=!0;break;case 102:e=t.next();break;case 330:r?s.sortEntsObject.ownerHandle=e.value:s.ownerHandle=e.value,e=t.next();break;case 331:n.push(e.value),e=t.next();break;default:Xt(s,e),e=t.next();break}return s}}class Wl{constructor(){p(this,"ForObjectName","SPATIAL_FILTER")}parseObject(t,e){const s={type:e.value};s.vertices=[];let r,n;for(e=t.next();!t.isEOF()&&e.code!==0;)switch(e.code){case 11:s.origin=qi(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),r=qi(t),e=t.lastReadGroup,n=qi(t),e=t.lastReadGroup,s.vertices.push(r,{x:n.x,y:r.y},n,{x:r.x,y:n.y},r)):s.numberOfPointsOnClipBoundary>2?(s.vertices=Yl(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=Tr(t,40),s.matrix=Tr(t,40),e=t.lastReadGroup;break;default:Xt(s,e),e=t.next();break}return s}}function Yl(h,t){t.next();const e=[];for(;e.length<h;)e.push(qi(t));return e}function Tr(h,t){let e=h.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=h.next()}return i}function qi(h){const t={};let e=h.lastReadGroup||h.next();const i=e.code;for(;!h.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=h.next()}return t}class Xl{constructor(){p(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:Xt(s,e),e=t.next();break}return s}}function Zl(h){h.registerEntityHandler(Qo),h.registerEntityHandler(el),h.registerEntityHandler(il),h.registerEntityHandler(sl),h.registerEntityHandler(rl),h.registerEntityHandler(al),h.registerEntityHandler(ol),h.registerEntityHandler(hl),h.registerEntityHandler(ml),h.registerEntityHandler(gl),h.registerEntityHandler(yl),h.registerEntityHandler(bl),h.registerEntityHandler(wl),h.registerEntityHandler(Tl),h.registerEntityHandler(Cl),h.registerEntityHandler(Sl),h.registerEntityHandler(Ol),h.registerEntityHandler(Al),h.registerEntityHandler(kl),h.registerEntityHandler(Dl),h.registerEntityHandler(Bl),h.registerEntityHandler(Ll),h.registerEntityHandler(Rl),h.registerEntityHandler(zl),h.registerEntityHandler(jl),h.registerEntityHandler(Vl),h.registerEntityHandler(Ul)}function Kl(h){h.registerObjectHandler(Hl),h.registerObjectHandler(Nl),h.registerObjectHandler(Gl),h.registerObjectHandler(ql),h.registerObjectHandler(Wl),h.registerObjectHandler(Xl)}function $l(h){const t=new Uint8Array(h,0,18);let e="";for(let i=0;i<18;i++)e+=String.fromCharCode(t[i]);return e==="AutoCAD Binary DXF"}class Tn{constructor(t){p(this,"_entityHandlers",{});p(this,"_objectHandlers",{});p(this,"_layoutBlocks",{});p(this,"unhandledSections",{});p(this,"unhandledObjects",{});p(this,"unhandledEntities",{});p(this,"unsupportedLineTypes",{});p(this,"encoding");this.encoding=t,Zl(this),Kl(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new dr(e);return this._parse(i)}else{let e;if($l(t))e=new Xo(t);else{const i=new TextDecoder(this.encoding).decode(t),s=Date.now(),r=this.splitByLineSeparator(i);console.info("[DxfParser] string.split took "+(Date.now()-s)/1e3+"s, it is avoidable by using dxf in binary."),e=new dr(r)}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,r)=>{t.on("data",n=>{e+=n}),t.on("end",()=>{try{s(i.parse(e))}catch(n){r(n)}}),t.on("error",n=>{r(n)})})}_parse(t){const e={};let i=0;if(!t.hasNext())throw Error("Empty file");const s=this;let r;function n(){for(r=t.next();r.code===999;)r=t.next();for(;!t.isEOF();)if(r.code===0&&r.value==="SECTION"){if(r=t.next(),r.code!==2){console.error("Unexpected code %s after 0:SECTION",Cn(r)),r=t.next();continue}if(r.value==="HEADER")S.trace("> HEADER"),e.header=a(),S.trace("<");else if(r.value==="TABLES")S.trace("> TABLES"),e.tables=c(),S.trace("<");else if(r.value==="BLOCKS")S.trace("> BLOCKS"),e.blocks=o(),S.trace("<");else if(r.value==="ENTITIES")S.trace("> ENTITIES"),e.entities=E(!1),S.trace("<");else if(r.value==="OBJECTS")S.trace("> OBJECTS"),e.objects=O(),S.trace("<");else if(r.value==="EOF")S.trace("EOF");else{const C=r.value;s.unhandledSections[C]?s.unhandledSections[C]++:s.unhandledSections[C]=1}}else r=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let C=null,w=null;const M={};for(r=t.next();;){if(Pe(r,0,"ENDSEC")){C&&(M[C]=w);break}else r.code===9?(C&&(M[C]=w),C=r.value):r.code===10?w={x:r.value}:r.code===20?w.y=r.value:r.code===30?w.z=r.value:w=r.value;r=t.next()}return r=t.next(),M}function o(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)if(Pe(r,0,"BLOCK")){S.trace("block {");const w=l();S.trace("}"),_(w),w.name?C[w.name]=w:console.error("[DxfParser] Block with handle '"+w.handle+"' is missing a name, ignored!")}else Qe(r),r=t.next();return C}function l(){const C={};for(r=t.next();r.value!=="EOF";){switch(r.code){case 1:C.xrefPath=r.value,r=t.next();break;case 2:C.name=r.value,r=t.next();break;case 3:C.name2=r.value,r=t.next();break;case 4:C.description=r.value,r=t.next();break;case 5:C.handle=r.value,r=t.next();break;case 8:C.layer=r.value,r=t.next();break;case 10:C.position=Ie(t),r=t.lastReadGroup;break;case 67:C.paperSpace=!!(r.value&&r.value===1),r=t.next();break;case 70:C.blockType=r.value,r=t.next();break;case 100:r=t.next();break;case 330:C.ownerHandle=r.value,r=t.next();break;case 0:if(r.value==="ENDBLK")break;C.entities=E(!0);break;default:Qe(r),r=t.next();break}if(Pe(r,0,"ENDBLK")){r=t.next();break}}return C}function c(){const C={};for(r=t.next();r.value!=="EOF"&&!Pe(r,0,"ENDSEC");)Pe(r,0,"TABLE")?(r=t.next(),b[r.value]?(S.trace(r.value+" Table {"),C[b[r.value].tableName]=f(r),S.trace("}")):S.trace("Unhandled Table "+r.value)):r=t.next();return r=t.next(),C}const u="ENDTAB";function f(C){const w=b[C.value],M={};let P=0;for(r=t.next();!Pe(r,0,u);)switch(r.code){case 5:M.handle=r.value,r=t.next();break;case 330:M.ownerHandle=r.value,r=t.next();break;case 100:r.value==="AcDbSymbolTable"||Qe(r),r=t.next();break;case 70:P=r.value,r=t.next();break;case 0:r.value===w.dxfSymbolName?M[w.tableRecordsProperty]=w.parseTableRecords():(Qe(r),r=t.next());break;default:Qe(r),r=t.next();break}const A=M[w.tableRecordsProperty];if(A){const I=(()=>{if(A.constructor===Array)return A.length;if(typeof A=="object")return Object.keys(A).length})();P!==I&&console.warn("[DxfParser] Parsed "+I+" "+w.dxfSymbolName+"s but expected "+P)}return r=t.next(),M}function m(){const C=[];let w={};for(S.trace("Viewport {"),r=t.next();!Pe(r,0,u);)switch(r.code){case 2:w.name=r.value,r=t.next();break;case 10:w.lowerLeftCorner=Ie(t),r=t.lastReadGroup;break;case 11:w.upperRightCorner=Ie(t),r=t.lastReadGroup;break;case 12:w.center=Ie(t),r=t.lastReadGroup;break;case 13:w.snapBasePoint=Ie(t),r=t.lastReadGroup;break;case 14:w.snapSpacing=Ie(t),r=t.lastReadGroup;break;case 15:w.gridSpacing=Ie(t),r=t.lastReadGroup;break;case 16:w.viewDirectionFromTarget=Ie(t),r=t.lastReadGroup;break;case 17:w.viewTarget=Ie(t),r=t.lastReadGroup;break;case 40:w.viewHeight=r.value,r=t.next();break;case 41:w.aspectRatio=r.value,r=t.next();break;case 42:w.lensLength=r.value,r=t.next();break;case 43:w.frontClippingPlane=r.value,r=t.next();break;case 44:w.backClippingPlane=r.value,r=t.next();break;case 45:w.viewHeight=r.value,r=t.next();break;case 50:w.snapRotationAngle=r.value,r=t.next();break;case 51:w.viewTwistAngle=r.value,r=t.next();break;case 79:w.orthographicType=r.value,r=t.next();break;case 110:w.ucsOrigin=Ie(t),r=t.lastReadGroup;break;case 111:w.ucsXAxis=Ie(t),r=t.lastReadGroup;break;case 112:w.ucsYAxis=Ie(t),r=t.lastReadGroup;break;case 281:w.renderMode=r.value,r=t.next();break;case 282:w.defaultLightingType=r.value,r=t.next();break;case 292:w.defaultLightingOn=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 63:case 421:case 431:w.ambientColor=r.value,r=t.next();break;case 0:r.value==="VPORT"&&(S.trace("}"),C.push(w),S.trace("Viewport {"),w={},r=t.next());break;default:Qe(r),r=t.next();break}return S.trace("}"),C.push(w),C}function g(){const C={};let w={},M=0,P="",A=!1;for(S.trace("LType {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value.toUpperCase(),P=w.name,r=t.next();break;case 3:w.description=r.value,r=t.next();break;case 9:r=t.next();break;case 40:w.patternLength=r.value,r=t.next();break;case 44:r=t.next();break;case 45:r=t.next();break;case 46:r=t.next();break;case 49:let I=r.value;A&&(I=Math.abs(I),A=!1),w.pattern.push(I),r=t.next();break;case 70:r=t.next();break;case 73:M=r.value,M>0&&(w.pattern=[]),r=t.next();break;case 74:r.value!==0&&(A=!0,s.unsupportedLineTypes[w.name]?s.unsupportedLineTypes[w.name]++:s.unsupportedLineTypes[w.name]=1),r=t.next();break;case 75:r=t.next();break;case 0:S.trace("}"),M>0&&M!==w.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),C[P]=w,w={},S.trace("LType {"),r=t.next();break;default:r=t.next();break}return S.trace("}"),C[P]=w,C}function x(){const C={};let w={},M;for(S.trace("Layer {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.name=r.value,M=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 62:w.visible=r.value>=0,w.colorIndex=Math.abs(r.value),w.color=Nt(w.colorIndex),r=t.next();break;case 70:w.flag=r.value,w.frozen=(w.flag&1)>0,r=t.next();break;case 420:w.color=Math.abs(r.value),r=t.next();break;case 6:w.lineType=r.value.toUpperCase(),r=t.next();break;case 370:w.lineweight=r.value,r=t.next();break;case 0:r.value==="LAYER"&&(S.trace("}"),M&&(C[M]=w),S.trace("Layer {"),w={},M=void 0,r=t.next());break;default:Qe(r),r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function y(){const C={};let w={},M;for(S.trace("Style {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 3:w.fontFile=r.value,r=t.next();break;case 4:w.bigFontFile=r.value,r=t.next();break;case 5:w.handle=r.value,r=t.next();break;case 40:w.textHeight=r.value,r=t.next();break;case 41:w.xScale=r.value,r=t.next();break;case 42:w.priorTextHeight=r.value,r=t.next();break;case 50:w.rotation=r.value,r=t.next();break;case 70:r=t.next();break;case 71:w.mirrorType=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 0:r.value==="STYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("Style {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function T(){const C={};let w={},M;for(S.trace("DimStyle {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 2:w.styleName=r.value,M=r.value,r=t.next();break;case 40:w.DIMSCALE=r.value,r=t.next();break;case 41:w.DIMASZ=r.value,r=t.next();break;case 42:w.DIMEXO=r.value,r=t.next();break;case 44:w.DIMEXE=r.value,r=t.next();break;case 75:w.DIMSE1=r.value,r=t.next();break;case 76:w.DIMSE2=r.value,r=t.next();break;case 77:w.DIMTAD=r.value,r=t.next();break;case 140:w.DIMTXT=r.value,r=t.next();break;case 144:w.DIMLFAC=r.value,r=t.next();break;case 147:w.DIMGAP=r.value,r=t.next();break;case 176:w.DIMCLRD=r.value,r=t.next();break;case 178:w.DIMCLRT=r.value,r=t.next();break;case 271:w.DIMDEC=r.value,r=t.next();break;case 341:w.DIMLDRBLK=r.value,r=t.next();break;case 70:r=t.next();break;case 0:r.value==="DIMSTYLE"&&(S.trace("}"),M&&(C[M]=w),S.trace("DimStyle {"),w={},M=void 0,r=t.next());break;default:r=t.next();break}return S.trace("}"),M&&(C[M]=w),C}function v(){const C={};let w={},M;for(S.trace("BlockRecord {"),r=t.next();!Pe(r,0,"ENDTAB");)switch(r.code){case 5:w.handle=r.value,r=t.next();break;case 330:w.ownerHandle=r.value,r=t.next();break;case 2:w.blockName=r.value,M=w.blockName,r=t.next();break;case 340:w.layoutHandle=r.value,r=t.next();break;case 70:w.blockInsertUnits=r.value,r=t.next();break;case 280:w.blockExplodability=r.value,r=t.next();break;case 281:w.blockScalability=r.value,r=t.next();break;case 310:w.bitmap=r.value,r=t.next();break;case 0:if(r.value==="BLOCK_RECORD"){S.trace("}"),M&&(C[M]=w);const A=w.layoutHandle;M&&A&&A.length>0&&A!=="0"&&(s._layoutBlocks[A]=w),S.trace("BlockRecord {"),w={},M=void 0,r=t.next()}else Qe(r),r=t.next();break;default:Qe(r),r=t.next();break}S.trace("}"),M&&(C[M]=w);const P=w.layoutHandle;return M&&P&&P.length>0&&P!=="0"&&(s._layoutBlocks[P]=w),C}const b={VPORT:{tableRecordsProperty:"viewports",tableName:"viewport",dxfSymbolName:"VPORT",parseTableRecords:m},LTYPE:{tableRecordsProperty:"lineTypes",tableName:"lineType",dxfSymbolName:"LTYPE",parseTableRecords:g},LAYER:{tableRecordsProperty:"layers",tableName:"layer",dxfSymbolName:"LAYER",parseTableRecords:x},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:v},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:y},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:T}};function E(C){const w=[],M=C?"ENDBLK":"ENDSEC";for(C||(r=t.next());;)if(r.code===0){if(r.value===M)break;const P=s._entityHandlers[r.value];if(P!=null){S.trace(r.value+" {");const A=P.parseEntity(t,r);A&&(A.layer||(A.layer="0"),A.colorIndex===void 0&&(A.colorIndex=256),A.lineType||(A.lineType="BYLAYER"),r=t.lastReadGroup,S.trace("}"),_(A),w.push(A))}else{const A=r.value;s.unhandledEntities[A]||(s.unhandledEntities[A]=0),s.unhandledEntities[A]++,r=t.next();continue}}else r=t.next();return M==="ENDSEC"&&(r=t.next()),w}function O(){const C={},w="ENDSEC";for(r=t.next();r.value!=="EOF";)if(r.code===0){if(r.value===w)break;const M=s._objectHandlers[r.value];if(M!=null){S.trace(r.value+" {");const P=M.parseObject(t,r),A=r.value;r=t.lastReadGroup,S.trace("}"),_(P),C[A]||(C[A]=[]),C[A].push(P)}else{const P=r.value;s.unhandledObjects[P]||(s.unhandledObjects[P]=0),s.unhandledObjects[P]++,r=t.next();continue}}else r=t.next();return r=t.next(),C.LAYOUT&&(Object.keys(s._layoutBlocks).length!==C.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),C.LAYOUT.forEach(M=>{s._layoutBlocks[M.handle]&&(M.associatedBlockName=s._layoutBlocks[M.handle].blockName)}),C.LAYOUT.sort((M,P)=>M.tabOrder-P.tabOrder)),C}function _(C){if(!C)throw new TypeError("entity cannot be undefined or null");C.handle||(C.handle=(i++).toString())}return n(),e}splitByLineSeparator(t){const e=[];let i=0;for(let s=0,r=t.length;s<r;++s){const n=t[s];if(n==="\r"||n===`
792
- `){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=Ho(a)),a&&(a=a),e.push(a),n==="\r"&&t[s+1]===`
793
- `&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Pe(h,t,e){return h.code===t&&h.value===e}function Qe(h){S.trace("unhandled group "+Cn(h))}function Cn(h){return h.code+":"+h.value}const Sn="0.4.0",On="VERSION",Jl=()=>window.localStorage.getItem(On),Ql=()=>{window.localStorage.setItem(On,Sn)},eh=()=>Jl()!==Sn?(Ql(),!0):!1,Tt=class Tt{constructor(){p(this,"DATABASE_NAME","x_viewer");p(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);p(this,"db");p(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!Tt._instance&&(Tt._instance=new Tt),Tt._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(),eh()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,S.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,S.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{S.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=r=>{S.debug(r),i(r)},s.onsuccess=r=>{const n=r.target;S.debug("[DB] Db "+t+" delete old version "+r.oldVersion+"."),e(n)}})}async getDB(t){return new Promise((e,i)=>{const s=window.indexedDB.open(t);s.onerror=i,s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async getUpgradedDB(t){return new Promise((e,i)=>{S.debug("[DB] Upgrading db "+t.name+" (version "+t.version+")");const s=window.indexedDB.open(t.name,t.version+1);s.onerror=i,s.onblocked=r=>{S.debug("onblocked",r)},s.onupgradeneeded=r=>{const n=r.target.transaction;n.oncomplete=()=>{S.debug("[DB] Upgrade is done (new version: "+a.version+").")};const a=r.target.result,o=[];for(let l=0;l<this.tables.length;++l){const c=this.tables[l];if(!a.objectStoreNames.contains(c.name)){S.debug("[DB] Creating table "+c.name+"...");const u=this.createTable(a,c.name,c.options,c.indexArray);o.push(u)}}o.length>0&&Promise.all(o).then(()=>{S.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=r=>{const n=r.target.result;S.debug("[DB] Db "+n.name+" opened (version "+n.version+")."),e(n)}})}async createTable(t,e,i,s){return new Promise(r=>{const n=t.createObjectStore(e,i);s&&s.forEach(a=>{n.createIndex(a.name,a.fields,{unique:a.unique})}),S.debug("[DB] Table "+e+" created."),r(t)})}};p(Tt,"_instance");let ae=Tt;class En{constructor(){p(this,"db");p(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,ae.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();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()}).catch(r=>{i&&i(r)})}save(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();ae.instance().getDatabase().then(r=>{const n=r.transaction([s],"readwrite").objectStore(s),a=n.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{ae.instance().closeDatabase()})}update(){ae.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.openCursor();n.onsuccess=a=>{const o=a.target.result;o&&o.continue(),t&&t(o)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}queryByIndex(t,e,i,s){const r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.index(t).get(e);o.onerror=s,o.onsuccess=function(l){const c=l.target?.result;i&&i(c)}}).finally(()=>{ae.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readonly").objectStore(i),n=r.getAll();n.onsuccess=a=>{t&&t(a.target.result)},n.onerror=e}).finally(()=>{ae.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();ae.instance().getDatabase().then(s=>{const r=s.transaction([i],"readwrite").objectStore(i),n=r.clear();n.onsuccess=a=>{t&&t(a)},n.onerror=a=>{e&&e(a)}}).finally(()=>{ae.instance().closeDatabase()})}}const Ct=class Ct extends En{tableName(){return"dxf_data"}static instance(){return!Ct._instance&&(Ct._instance=new Ct),Ct._instance}query(t,e,i){const s=[],r=this.tableName();ae.instance().getDatabase().then(n=>{const a=n.transaction([r],"readonly").objectStore(r),o=a.get(t);o.onerror=l=>{i&&i(l),S.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{ae.instance().closeDatabase()})}};p(Ct,"_instance");let Yi=Ct;const Ae=new d.Vector3(1,0,0),ds=new d.Vector3(0,1,0),Et=new d.Vector3(0,0,1),Cr=new d.Vector3(0,0,0),ct=16777215,th="CONTINUOUS",Ei=new d.PointsMaterial({color:ct}),le=new d.LineBasicMaterial({color:ct}),_t=new d.MeshBasicMaterial({color:ct}),Sr=new d.BufferGeometry().setFromPoints([new d.Vector3]),Or=new d.Matrix4,Fe=new d.Matrix4,ne=new d.Matrix4,j=new d.Vector3,Z=new d.Vector3,ze=new d.Vector3,Qt=new d.Vector2,he=new d.Quaternion,_i=new d.Object3D,We=new d.Box3,Er=new d.PointsMaterial({color:65280,size:5,depthTest:!1}),_r=new d.PointsMaterial({color:65280,depthTest:!1}),Pr=new d.PointsMaterial({color:65280,depthTest:!1}),ih=h=>h.viewDirectionFromTarget!==void 0,sh=h=>{if(h){const t=h.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);if(t&&t.length>0){const e=t[1],i=h.replace("data:"+e+";","").split(",");if(i&&i.length===2&&i[0]==="base64"){const s=i[1];return qa.decode(s)}}}return null},Ar=(h,t)=>{const e=new d.Vector2(h.x,h.y),i=new d.Vector2(t.x,t.y);return i.sub(e),i.normalize(),i.y<0?-Math.acos(i.x):Math.acos(i.x)},Ir=(h,t,e)=>({x:h.x+t*Math.cos(e),y:h.y+t*Math.sin(e)}),rh=(h,t,e,i)=>{const s=h?new d.Vector2(h.x,h.y):new d.Vector2(0,0),r=t?new d.Vector2(t.x,t.y):new d.Vector2(1,0);e=e||1;const n=4*Math.atan(e),a=s.distanceTo(r)/2/Math.sin(n/2),o=Ir(h,a,Ar(s,r)+(Math.PI/2-n/2));i=i||Math.max(Math.abs(Math.ceil(n/(Math.PI/18))),6);const l=Ar(o,s),c=n/i,u=[];u.push(new d.Vector3(s.x,s.y,0));for(let f=1;f<=i-1;f++){const m=Ir(o,Math.abs(a),l+c*f);u.push(new d.Vector3(m.x,m.y,0))}return u},kr=(h,t,e,i=h.length*2,s)=>{const r=[];if(!h||h.length<t+1||t<1)return r;const n=h.map(a=>[a.x,a.y]);try{for(let a=0;a<1;a+=1/i){const o=mn(a,t,n,e,s);r.push(new d.Vector3(o[0],o[1],0))}}catch{if(r.length===0)return r}return r},us=(h,t=!1)=>{const e=[],i=h.length;for(let s=0;s<i;s++){const r=h[s];if(r.bulge&&(s!==i-1||t)){const n=r.bulge,a=s+1<i?h[s+1]:e[0],o=rh(r,a,n);e.push(...o)}else e.push(new d.Vector3(r.x,r.y,0))}return e},nh=h=>{const t=[];return h.faceA&&t.push(h.faceA),h.faceB&&t.push(h.faceB),h.faceC&&t.push(h.faceC),h.faceD&&t.push(h.faceD),t},ah=h=>{const t=[],e=[];h.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new d.Vector3(s.x,s.y,s.z)):e.push(nh(s)))});const i=[];for(let s=0;s<e.length;s++){const r=e[s];if(r.length===0)continue;const n=[];let a=!0;for(let o=0;o<r.length;o++){const l=r[o]-1;if(l>=t.length||l<0){a=!1;break}n.push(t[l])}!a||n.length===0||(n.push(n[0]),i.push(n))}return i},V=class V extends d.Loader{constructor(e,i){super(e);p(this,"timer");p(this,"ignorePaperSpace");p(this,"font");p(this,"encoding");p(this,"overrideColor");p(this,"overrideHatchPatternLineThickness");p(this,"angBase");p(this,"angDir");p(this,"header");p(this,"pointsMaterials");p(this,"lineBasicMaterials");p(this,"lineShaderMaterials");p(this,"meshBasicMaterials");p(this,"meshTextureMaterials");p(this,"hatchShaderMaterials");p(this,"entityCount");p(this,"curveCount");p(this,"averageCurveSize");p(this,"enableRenderOrder");p(this,"enableLocalCache");p(this,"enableReleaseData");p(this,"enableMerge");p(this,"enableRTC");p(this,"enablePlineWidth");p(this,"dxfDataId");p(this,"compareContext");p(this,"statsInfo");p(this,"llbDatas");p(this,"mtextDatas");p(this,"requestHeader");p(this,"blockReferencesCache");p(this,"blockRecordsCache");p(this,"entitiesCache");p(this,"blocksCache");p(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");p(this,"spatialFiltersCache");p(this,"entityThreejsCache");p(this,"entityTypesAndTimes");p(this,"nonSnapableTypes");p(this,"layoutsSnapObjectsMap");p(this,"aborted");p(this,"entityHandlesWithRenderOrder");p(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,r)=>{if(s.type==="VIEWPORT"){!r[s.ownerHandle]&&(r[s.ownerHandle]=[]);const n=s;r[s.ownerHandle].push(n)}},i&&(this.ignorePaperSpace=i.ignorePaperSpace===!0,this.enableLocalCache=i.enableLocalCache===!0,this.enableMerge=V.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.overrideColor!=null&&(this.overrideColor=qt.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[ct]=Ei,this.lineBasicMaterials[ct]=le,this.meshBasicMaterials[ct]=_t}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=sh(e);if(!s){const r=Date.now(),n=new d.FileLoader(this.manager),a=V.REQUWSTHEADER;a&&n.setRequestHeader(a),n.setResponseType("arraybuffer"),n.setPath(this.path),s=await n.loadAsync(e,i),S.info("[Dxf] "+e+" dxf file downloaded in "+(Date.now()-r)/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=z.getUpdateSubProgressFunc(0,50,i),r=z.getUpdateSubProgressFunc(50,100,i),n=z.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),S.info("[Dxf] Loaded DxfData from indexedDb in "+(Date.now()-this.timer)/1e3+"s");const c=await this.loadEntities(l,n);return Promise.resolve(c)}}catch(c){S.warn("[Dxf] Failed to parse data from indexedDb",c)}}const a=await this.parse(e,s);return this.tryFixDxfData(a),await this.loadEntities(a,r)}async parse(e,i){const s=z.getUpdateProgressFunc(i),r=z.getUpdateSubProgressFunc(0,40,i),n=await this.download(e,r);if(!n)return Promise.reject("[Dxf] Failed to download "+e);if(this.aborted)return Promise.reject("[Dxf] Job aborted");this.timer=Date.now(),S.info("[Dxf] Start parsing...");const a=new Tn(this.encoding).parseSync(n);if(this.tryFixDxfData(a),s(80),S.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),S.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){S.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){S.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&S.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&&(S.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(S.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:V.MODEL_LAYOUT_NAME}]),!e.tables&&(S.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 r=0;const n=e.entities.length;this.entityCount=n,Object.keys(e.blocks).forEach(b=>{this.entityCount+=e.blocks[b].entities?.length||0});const a=z.getUpdateProgressFuncForLoop(n,i);let o={};const l=b=>{const E=b.userData.layerName;let O=o[E];!O&&(O=[],o[E]=O),O.push(b)},c={},u={},f=new F;for(let b=0;b<n&&!this.aborted;b++){const E=e.entities[b];this.addViewport(E,c);const O=this.loadEntity(E,e);if(!O&&await a(b),!O)continue;const _=this.getLayout(e,E),C=_.layoutName;let w=f.children.find(M=>M.name===C);if(!w&&(w=new F,w.name=C,w.userData.isLayoutLevelObject=!0,f.add(w)),O.traverse(M=>{M.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[C]&&(this.layoutsSnapObjectsMap[C]=[]),this.layoutsSnapObjectsMap[C].push(M))}),this.enableMerge){et.merge(O,!1),!u[C]&&(u[C]={object:w,layerObjects:{}});const P=u[C];if(O.geometry){const A=O.userData.layerName;!P.layerObjects[A]&&(P.layerObjects[A]=[]),P.layerObjects[A].push(O),O.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else O.children.length>0&&(w.add(O),O.traverse(A=>{A.geometry&&l(A)}))}else w.add(O),O.traverse(M=>{M.geometry&&l(M)});r++,await a(b)}e.objects.LAYOUT.forEach(b=>{const E=b,O=E.layoutName;if(this.ignorePaperSpace&&O!==V.MODEL_LAYOUT_NAME)return;const _=E.associatedBlockName,C=e.blocks[_];C&&this.loadLayout(C,e,E,f,o,c)}),S.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const b in this.layoutsSnapObjectsMap){const E=f.children.find(C=>C.name===b),O=new F;O.name=V.SNAP_GROUP_NAME,O.userData.isSnapGroup=!0,E.add(O);const _=this.layoutsSnapObjectsMap[b];for(let C=0;C<_.length;C++){const w=_[C],M=w.userData.layerName;this.getLayerVisible(e,M)===!1&&w.layers.disable(Ce),V.SHOW_SNAP_OBJECT&&(w.layers.enableAll(),w.material instanceof d.PointsMaterial?w.material=Er:w.material instanceof d.LineBasicMaterial?w.material=_r:w.material instanceof d.MeshBasicMaterial&&(w.material=Pr));let P=w;const A=ne.identity();for(;P&&P.userData.isLayoutLevelObject!==!0;)A.premultiply(P.matrix),P=P.parent;w.matrix.copy(A),O.add(w)}}if(this.enableMerge)for(const b in u){const E=u[b],O=E.object;for(const _ in E.layerObjects){const C=E.layerObjects[_],w=et.deepMerge(C,void 0,!1,!1,!0),M=w.added,P=w.removed;if(P.length!==C.length){let A=P;P.length>=100&&(A=new Set(P));const I=k=>Array.isArray(A)?A.indexOf(k)>=0:A.has(k);for(let k=0,B=C.length;k<B;k++){const L=C[k];!I(L)&&(O.add(L),l(L))}}for(let A=0;A<M.length;A++){const I=M[A];O.add(I),l(I)}E.layerObjects[_]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&V.mergeDxfObjects({root:f,layersAndObjects:o});const g=f.convertToThreejsObject();f.clear(),o={};const x={};e.objects.LAYOUT.forEach(b=>{const E=b;x[E.layoutName]=E});const y={},T=b=>{const E=b.userData.layerName;let O=y[E];!O&&(O=[],y[E]=O),O.push(b)};g.children.forEach(b=>{if($.setSharedVariablesOfObject(b),!b.userData.isLayoutLevelObject)return;const E=b.name;let O;if(E!==V.MODEL_LAYOUT_NAME){const _=x[E];!_.directAssociatedLeafObjectSet&&(_.directAssociatedLeafObjectSet=new Set),O=_.directAssociatedLeafObjectSet}b.traverse(_=>{if($.setSharedVariablesOfObject(_),_.userData.isSnapGroup&&(_.visible=V.SHOW_SNAP_OBJECT),_.geometry){const C=_.userData.layerName;this.getLayerVisible(e,C)===!1&&(_.visible=!1,_.userData.layerVisible=!1),T(_),O&&O.add(_)}})}),S.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const v=Object.assign(Object.assign({},e),{threejsObject:g,layersAndThreejsObjects:y,loadedEntityCount:r,layoutViewportsMap:c});if(V.LOADLLDATA){const b=g.children[0].children,E=[];for(let O=0;O<b.length;O++){const _=b[O];if(_?.userData?.llbData){const C=new d.Box3().setFromObject(_);C.getSize(new d.Vector3);const w=C.getCenter(new d.Vector3);E.push({..._,boundingBox:{max:C.max,min:C.min,center:w}})}else if(_.children&&_.children.some(C=>C.userData?.llbData))for(let C=0;C<_.children.length;C++){const w=_.children[C];if(w.userData?.llbData){w.updateWorldMatrix(!0,!0);const M=new d.Box3().setFromObject(w);M.getSize(new d.Vector3);const P=M.getCenter(new d.Vector3);E.push({...w,boundingBox:{max:M.max,min:M.min,center:P}})}}}v.llbMesh=E}return Promise.resolve(v)}getFontFilesFromDxf(e){const i=new Set,s=e.tables?.style?.styles;if(s)for(const r in s){const n=s[r],a=n.fontFile,o=n.bigFontFile;a&&i.add(a),o&&i.add(o)}S.info("[Dxf] Fonts used by dxf: "+Array.from(i).join())}async loadEntitiesForCompare(e,i,s,r=!0,n){const a=e.entities.length,o=i.entities.length,l=async()=>{const u=this.compareContext,f=u.isTheFirstFile,m=f?e:i,g=new F,x=f?a:o;this.entityCount=x,Object.keys(m.blocks).forEach(w=>{this.entityCount+=m.blocks[w].entities?.length||0});const y=Math.round(Math.pow(x,.5));let T=Date.now();const v=async w=>{if(n&&(w%y===0||w===x-1)){let M=w+1;!f&&(M+=a),n(new ProgressEvent("parseProgress",{loaded:M,total:a+o}));const P=500,A=Date.now();(A-T>P||w===x-1)&&(await z.sleep(0),T=A)}};this.parseHeader(m.header);let b={};for(let w=0;w<x;w++){if(this.aborted)return;const M=m.entities[w],P=this.getLayout(m,M);if(P.layoutName!==V.MODEL_LAYOUT_NAME){await v(w);continue}const A=this.loadEntity(M,m);if(!A){await v(w);continue}let I=g.children.find(k=>k.name===V.MODEL_LAYOUT_NAME);!I&&(I=new F,I.name=V.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,g.add(I)),I.add(A),A.traverse(k=>{if(k.geometry){const B=k.userData.layerName,L=this.getLayerVisible(m,B);k.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[P.layoutName]&&(this.layoutsSnapObjectsMap[P.layoutName]=[]),this.layoutsSnapObjectsMap[P.layoutName].push(k),L===!1&&A.layers.disable(Ce));let q=b[B];!q&&(q=[],b[B]=q),q.push(k)}}),await v(w)}r&&f&&!u.preservedHandles&&(u.preservedHandles=new Set);for(const w in s){const M=s[w];f&&(M.type===Te.Added||M.type===Te.Modified)&&(u.preservedHandles?.add(M.handle),M.parentHandles&&M.parentHandles.forEach(A=>u.preservedHandles?.add(A)));let P=this.entityThreejsCache&&this.entityThreejsCache[M.handle];if(M.parentHandles&&(P=this.entityThreejsCache&&this.entityThreejsCache[M.parentHandles[M.parentHandles.length-1]]),P){if(P.parent&&P.parent.userData.originalType){this.setObjectColorByChange(P,{type:Te.NoChange});continue}P=this.setObjectColorByChange(P,M)}if(M.type!==Te.NoChange&&P){let A=P.parent;const I=ne.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;We.makeEmpty();const k=F.getBox(P,We);k.applyMatrix4(I),M.type===Te.Added?!f&&(M.box=new d.Box3().copy(k)):M.type===Te.Removed?f&&(M.box=new d.Box3().copy(k)):M.type===Te.Modified&&(M.box?M.box.union(k):M.box=new d.Box3().copy(k))}}for(const w in this.layoutsSnapObjectsMap){const M=g.children.find(I=>I.name===w),P=new F;P.name=V.SNAP_GROUP_NAME,M.add(P);const A=this.layoutsSnapObjectsMap[w];for(let I=0;I<A.length;I++){const k=A[I];V.SHOW_SNAP_OBJECT&&(k.layers.enableAll(),k.material instanceof d.PointsMaterial?k.material=Er:k.material instanceof d.LineBasicMaterial?k.material=_r:k.material instanceof d.MeshBasicMaterial&&(k.material=Pr));let B=k;const L=ne.identity();for(;B&&B.userData.isLayoutLevelObject!==!0;)L.premultiply(B.matrix),B=B.parent;k.matrix.copy(L),P.add(k)}}this.enableMerge&&V.mergeDxfObjects({root:g,layersAndObjects:b});const E=g.convertToThreejsObject();g.clear(),b={};const O={},_=w=>{const M=w.userData.layerName;let P=O[M];!P&&(P=[],O[M]=P),P.push(w)};E.children.forEach(w=>{$.setSharedVariablesOfObject(w),w.userData.isLayoutLevelObject&&w.traverse(M=>{if($.setSharedVariablesOfObject(M),M.userData.isSnapGroup&&(M.visible=V.SHOW_SNAP_OBJECT),M.geometry){const P=M.userData.layerName;this.getLayerVisible(m,P)===!1&&(M.visible=!1,M.userData.layerVisible=!1),_(M)}})});const C=m;C.threejsObject=E,C.layersAndThreejsObjects=O,C.layoutViewportsMap={}};let c=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},z.printMemory("Before loading entities for first dxf"),await l(),S.info("[Dxf] loadEntities for first dxf in "+(Date.now()-c)/1e3+"s"),z.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),z.printMemory("Before loading entities for second dxf"),c=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),S.info("[Dxf] loadEntities for second dxf in "+(Date.now()-c)/1e3+"s"),this.printStatsInfo();for(const u of Object.values(s))!u.box&&delete s[u.id];this.compareContext.preservedHandles=void 0,this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(i)),z.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=Ue.ENTITY_COLOR_NO_CHANGE;return a.type===Te.Added?o=Ue.ENTITY_COLOR_ADDED:a.type===Te.Removed?o=Ue.ENTITY_COLOR_REMOVED:a.type===Te.Modified&&(o=this.compareContext?.isTheFirstFile?Ue.ENTITY_COLOR_REMOVED:Ue.ENTITY_COLOR_ADDED),o},r=(a,o)=>{a.traverse(l=>{if(l.material){if(l.material instanceof d.LineBasicMaterial)l.material=this.getLineBasicMaterial(o);else if(l.material instanceof d.MeshBasicMaterial)l.material=this.getMeshBasicMaterial(o);else if(l.material instanceof d.PointsMaterial)l.material=this.getPointsMaterial(o);else if(l.material instanceof d.ShaderMaterial){const c=l.material.clone();V.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o),l.material=c}}})},n=s(i);return e.traverse(a=>{i.parentHandles?a.userData&&a.userData.handle&&a.userData.handle===i.handle&&(r(a,n),e=a):r(a,n)}),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,r=!1){if(this.compareContext&&this.compareContext.preservedHandles&&this.compareContext.preservedHandles.has(e.handle)&&oi.includes(e.type)&&(r=!0),!r&&this.compareContext&&this.compareContext.preservedHandles&&!oi.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 m=e.layer;return!this.statsInfo.ignoredFrozenLayersAndEntityCount[m]&&(this.statsInfo.ignoredFrozenLayersAndEntityCount[m]=0),this.statsInfo.ignoredFrozenLayersAndEntityCount[m]++,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 m=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,r);else if(e.type==="SPLINE")o=this.loadSpline(e,s);else if(e.type==="MTEXT")m?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 g=0;g<i.entities.length;g++){const x=i.entities[g];if(e.ownerHandle===x.handle&&(s=x,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 m=this.getLayerName(e,i,s);o.userData.handle=e.handle,e.type!=="INSERT"&&e.type!=="DIMENSION"&&o.traverse(g=>{g.geometry&&(g.userData.layerName=m,g.userData.handle=e.handle,g.userData.dxfType=e.type,this.setMaterial(g,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(g=>{g.layers.disable(Ce)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16)))}const c=e.type,u=e.handle,f=oi.includes(c);if(!f){this.entityTypesAndTimes||(this.entityTypesAndTimes={}),this.entityTypesAndTimes[c]||(this.entityTypesAndTimes[c]={createCount:0,totalTime:0,averageTime:0});const m=this.entityTypesAndTimes[c];m.createCount++,m.totalTime+=Date.now()-a}return o?this.statsInfo.entityTypesAndMeshCount[c]?this.statsInfo.entityTypesAndMeshCount[c]++:this.statsInfo.entityTypesAndMeshCount[c]=1:(this.statsInfo.unsupportedEntityTypes[c]?this.statsInfo.unsupportedEntityTypes[c]++:this.statsInfo.unsupportedEntityTypes[c]=1,f||(this.statsInfo.unsupportedEntity[u]?this.statsInfo.unsupportedEntity[u]++:this.statsInfo.unsupportedEntity[u]=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 r=e.startAngle,n=e.endAngle;if(e.extrusionDirection&&e.extrusionDirection.z<0&&(r=Math.PI*2-e.endAngle,n=Math.PI*2-e.startAngle),R.areNumbersEqual(r,n,1e-5))return S.warn("[Dxf] Ellipse entity (handle '%s') contains the same start and end angle, ignored!",e.handle),void 0;let a=n-r;for(;a>Math.PI*2;)a-=Math.PI*2;Math.abs(a)<=1e-5&&(n=R.floorNumber(r+Math.PI*2,5));const o=Math.sqrt(Math.pow(e.majorAxisEndPoint.x,2)+Math.pow(e.majorAxisEndPoint.y,2)),l=o*e.axisRatio,c=Math.atan2(e.majorAxisEndPoint.y,e.majorAxisEndPoint.x),u=new d.EllipseCurve(e.center.x,e.center.y,o,l,r,n,!1,c);let f=1;const m=s;m?.xScale&&m?.yScale&&(f=Math.max(Math.abs(m.xScale),Math.abs(m.yScale)));const g=this.getDivision(r,n,Math.max(o,l)*f),x=u.getPoints(g),y=[],T=x.length;for(let C=0;C<T-1;C++)R.areVector2sEqual(x[C],x[C+1],1e-9)||y.push(x[C]);if(y.push(x[T-1]),y.length<2)return S.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const v=new d.Vector3;let b=!1;this.enableRTC&&(b=U.checkAndRebasePositionsOnRTC(y,v));const E=new d.BufferGeometry().setFromPoints(y),O=new F(H.Line);O.geometry=E,O.material=le;const _=new F(H.Point);return _.geometry=Sr,_.material=Ei,_.matrix.setPosition(e.center.x,e.center.y,e.center.z),_.userData.isSnapObject=!0,_.userData.type="CircleCenter",_.layers.set(Ce),O.add(_),b&&(this.setRTCUserData(O),O.matrix.setPosition(v.x,v.y,0)),O.layers.enableAll(),O}loadMText(e,i,s){if(!e.text)return;if(!this.font)return S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=li(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(j),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(document.createElement("canvas").getContext("2d"),e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const k=g.split("\\P").length-1;k>0?y+=f*(k+1)+f*m*.8*k:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:const I=g.split("\\P");let k=0;I>1&&(k=I-1),k>1?y+=f*(k-1):y-=f/4;break;default:return}o.traverse(I=>{I.geometry&&I.geometry.translate(x,y,0),I.layers.enableAll()});let v=0;if(e.rotation&&(v=e.rotation*Math.PI/180),e.directionVector){const I=e.directionVector,k=new d.Vector3(I.x,I.y,I.z),B=k.clone().cross(Ae),L=Ae.angleTo(k);v=B.z>0?-L:L}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const b=e.position?Z.clone().sub(e.position):Z;Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o.userData||(o.userData={});const E=o.matrix.elements,O=E&&E[12]||0,_=E&&E[13]||0,C=E&&E[14]||0,w=new d.Box3;F.getBox(o,w);const M=new d.Vector3;w.getCenter(M);const P=new d.Vector3;w.getSize(P),o.userData.renderArea={position:{x:O,y:_,z:C},bbox:{min:{x:w.min.x,y:w.min.y,z:w.min.z},max:{x:w.max.x,y:w.max.y,z:w.max.z},center:{x:M.x,y:M.y,z:M.z},width:P.x,height:P.y,depth:P.z},textSize:{width:u,height:f},rotation:v,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 S.info("[Dxf] Font file not set, ignoring text entity."),void 0;const r=this.getTextStyle(i,e),n=li(e.text,{encoding:this.getTextEncoding(r)}),a=this.getMTextGroup(n,e,r,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose(Z,he,ze),e.position&&(Z.x+=e.position.x,Z.y+=e.position.y,o.matrix.compose(Z,he,ze)),We.makeEmpty();const l=F.getBox(o,We),c=l.getSize(j),u=e.width||c.x,f=e.height||c.y,m=e.lineSpaceFactor||1.657,g=e.text;let x=0,y=0;switch(e.attachmentPoint){case 1:x=0,y=0;break;case 2:x-=u/2,y=0;break;case 3:x-=u,y=0;break;case 4:x=0,y+=f/2;break;case 5:x-=u/2,y+=f/2;break;case 6:x-=u,y+=f/2;break;case 7:x=0;const E=g.split("\\P").length-1;E>0?y+=f*(E+1)+f*m*.8*E:y+=f;break;case 8:x-=u/2,y+=f;break;case 9:x-=u,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=f;break;case 4:break;case 5:break;default:return}o.traverse(b=>{b.geometry&&b.geometry.translate(x,y,0),b.layers.enableAll()});let T=0;if(e.rotation&&(T=e.rotation*Math.PI/180),e.directionVector){const b=e.directionVector,E=new d.Vector3(b.x,b.y,b.z),O=E.clone().cross(Ae),_=Ae.angleTo(E);T=O.z>0?-_:_}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(o),o.matrix.compose(Z,he,ze);const v=e.position?Z.clone().sub(e.position):Z;return Fe.makeTranslation(-v.x,-v.y,0),ne.makeRotationZ(T),o.matrix.multiply(Fe),o.matrix.multiply(ne),o.matrix.multiply(Fe.invert()),o}getMTextGroup(e,i,s,r,n,a=0,o=0,l=[]){if(e.length===0)return;let c=i.height||i.contextData&&i.contextData.textHeight||0;if(i.textStyle){if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const O=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[O]&&(this.statsInfo.unsupportedTextStyles[O]=0),this.statsInfo.unsupportedTextStyles[O]++}c=c||s.textHeight}let u="Left";i.width&&i.attachmentPoint&&([1,4,7].includes(i.attachmentPoint)?u="Left":[2,5,8].includes(i.attachmentPoint)?u="Center":[3,6,9].includes(i.attachmentPoint)&&(u="Right"));const f=i.width||0,m=new F;let g,x=s.fontFile,y=1,T=1,v=256,b=c*.8,E=b+c;for(let O=0;O<e.length;O++){const _=e[O];if(typeof _=="string"){const C=[],w=A=>{let I;if(A.forEach((k,B)=>{!k.boundingBox&&k.computeBoundingBox(),B===0?I=k.boundingBox:I.union(k.boundingBox)}),I){const k=I.getSize(j);switch(u){case"Left":break;case"Center":A.forEach(B=>B.translate((f-k.x)/2,0,0));break;case"Right":A.forEach(B=>B.translate(f-k.x,0,0));break}}C.push(...A)};let M;for(let A=0;A<_.length;A++){const I=_[A];if(I===`
794
- `){a=0,o-=E,l.length>0&&w(l),l=[];continue}if(b=c*.8,E=b+c,M=this.font?.getCharShape(I,x,c),s.bigFontFile&&!M&&(M=this.font?.getCharShape(I,s.bigFontFile,c)),!M&&(M=this.font?.getCharShape(I,"",c)),!M&&(M=this.font?.getNotFoundTextShape(c)),!M){a+=c+T*(c/3.5);continue}a>(f||1/0)&&(l.length>0&&w(l),a=0,o-=E,l=[]),M.translate(a,o,0),M.scale(y,1,1),M.boundingBox||M.computeBoundingBox(),_.T&&(T=_.T);const k=Uo(I,M,c,T,x);a+=k,l.push(M)}l.length>0&&(w(l),l=[]);const P=new F;if(C.length>0){!g&&(g=i.colorIndex),v!==void 0&&v!==256?(i.color=Nt(v),i.colorIndex=v):i.colorIndex=g;const A=this.getColor(i,r,n),I=C.filter(B=>B instanceof d.ExtrudeGeometry),k=C.filter(B=>!(B instanceof d.ExtrudeGeometry));if(I.length>0){const B=new F(H.Mesh);B.geometry=xe.mergeGeometries(I),B.material=this.getMeshBasicMaterial(A),P.add(B)}if(k.length>0){const B=new F(H.LineSegment);B.geometry=xe.mergeGeometries(k),B.material=this.getLineBasicMaterial(A),P.add(B)}}P.matrix.makeTranslation(0,-c,0),m.add(P),y=1,T=1,v=256}else if(Array.isArray(_)){const C=this.getMTextGroup(_,i,s,r,n,a,o,l);C&&(m.add(C.object),a=C.hOffset,o=C.vOffset)}else typeof _=="object"&&(_.f&&(x=_.f,x&&x.includes(".shx")&&S.info("[Dxf] Doesn't support custom fonts: "+x)),_.C&&(v=_.C),_.W&&(_.W[1]==="x"?y=_.W[0]*i.width:y=_.W[0]),_.H&&(_.H[1]==="x"?c=_.H[0]*i.height:c=_.H[0]),_.T&&(T=_.T))}if(m.children.length!==0)return et.merge(m,!1),g&&(i.colorIndex=g),m.children.length===1?{object:m.children[0],hOffset:a,vOffset:o}:{object:m,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},r={};let n=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 c=this.getTextLineNum(l);a.push({font:r.f,colorIndex:r.C,text:l,lineNum:n}),n+=c}}}}else if(Array.isArray(l)){const c=this.mtextContentAndFormattingToTextAndStyle(l,i);c.text.forEach(u=>{a.push(u)}),n=c.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const c=l.S[0]+"/"+l.S[2],u=this.getTextLineNum(c);a.push({text:l.S[0]+"/"+l.S[2],lineNum:n}),n+=u}else l.C!==void 0?r.C=l.C:l.W!==void 0?r.W=l.W:l.H!==void 0?r.H=l.H:l.f!==void 0&&(r.f=l.f)}return{text:a,lineLength:n,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 S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=e.vertices.map(o=>new d.Vector3(o.x,o.y,o.z));if(i.length===0)return;!R.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new d.Vector3;let r=!1;this.enableRTC&&(r=U.checkAndRebasePositionsOnRTC(i,s));const n=new d.BufferGeometry().setFromPoints(i),a=new F(H.Line);return a.geometry=n,a.material=le,r&&(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 S.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,r=1/0,n=-1/0,a=-1/0;for(const v of e.controlPoints)v.x<s&&(s=v.x),v.y<r&&(r=v.y),v.x>n&&(n=v.x),v.y>a&&(a=v.y);let o=1;const l=i;l?.xScale&&l?.yScale&&(o=Math.max(Math.abs(l.xScale),Math.abs(l.yScale)));const c=Math.max(n-s,a-r),u=this.getBSplineInterpolationsPerSplineSegment(e.controlPoints.length,c*o),f=kr(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,u),m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(f,m));const x=U.getAdjacentNonRepeatPoints(f);if(x.length<2)return S.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const y=new d.BufferGeometry().setFromPoints(x),T=new F(H.Line);return T.geometry=y,T.material=le,g&&(this.setRTCUserData(T),T.matrix.setPosition(m.x,m.y,0)),T.layers.enableAll(),T}loadXLine(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=z.arrayOrObjectToVector3(e.directionVector),s=new d.Vector3(e.vertices[0].x,e.vertices[0].y,0),r=[];if(r.push(i.clone().multiplyScalar(-1e6).add(s)),r.push(i.clone().multiplyScalar(1e6).add(s)),r.length===0)return;const n=new d.Vector3;let a=!1;this.enableRTC&&(a=U.checkAndRebasePositionsOnRTC(r,n));const o=new d.BufferGeometry().setFromPoints(r),l=new F(H.Line);return l.geometry=o,l.material=le,a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,0)),l.layers.enableAll(),l}loadRay(e){if(!e.vertices||e.vertices.length===0)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=z.arrayOrObjectToVector3(e.directionVector),s=e.vertices.map(l=>new d.Vector3(l.x,l.y,0));if(s.push(i.multiplyScalar(1e6).add(s[0])),s.length===0)return;const r=new d.Vector3;let n=!1;this.enableRTC&&(n=U.checkAndRebasePositionsOnRTC(s,r));const a=new d.BufferGeometry().setFromPoints(s),o=new F(H.Line);return o.geometry=a,o.material=le,n&&(this.setRTCUserData(o),o.matrix.setPosition(r.x,r.y,0)),o.layers.enableAll(),o}loadLine(e,i){if(!e.vertices||e.vertices.length===0){S.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=ah(e.vertices);else{const c=us(e.vertices,e.shape);e.shape&&c.length>0&&c.push(c[0]),c.length>0&&(s=[c])}if(s.length===0)return;const r=[];for(let c=0;c<s.length;){const[u,f]=s[c];R.areVector3sEqual(u,f)&&s[c].length<=2?(r.push(u.clone()),s.splice(c,1)):c++}const n=new d.Vector3;let a=!1,o=0;s.forEach(c=>{c.forEach(u=>n.add(u)),o+=c.length}),o>0&&(n.divideScalar(o),a=this.enableRTC&&U.shouldRebasePositionOnRTC(n));let l=null;if(s.length>0){let c=function(v){return Array.isArray(v.pattern)&&v.pattern.length>0};const u=[],f=[];let m=0;s.forEach(v=>{v.forEach(b=>{a?u.push(new d.Vector3(b.x-n.x,b.y-n.y,b.z-n.z)):u.push(b.clone())});for(let b=1;b<v.length;b++)f.push(m+b-1,m+b);m+=v.length});const g=this.getLineType(e,i),x=i.tables?.lineType?.lineTypes?.[g],y=new d.BufferGeometry().setFromPoints(u);let T=le;if(x&&c(x)){let v=function(_){const C=_.attributes.position,w=C.count,M=new Float32Array(w);for(let P=0;P<w;P+=2){const A=P*3,I=(P+1)*3,k=C.array[I]-C.array[A],B=C.array[I+1]-C.array[A+1],L=C.array[I+2]-C.array[A+2],q=Math.sqrt(k*k+B*B+L*L);M[P]=P===0?0:M[P-1],M[P+1]=M[P]+q}_.setAttribute("lineDistance",new d.Float32BufferAttribute(M,1))};const b=x.pattern?.[0]||.5,E=x.pattern?.[1]||.5,O=.1;T=new d.LineDashedMaterial({color:le.color,linewidth:le.linewidth||1,dashSize:b*O,gapSize:E*O,scale:O}),v(y)}else y.setIndex(f);l=new F(H.LineSegment),l.geometry=y,l.material=T}if(r.length>0){a&&U.checkAndRebasePositionsOnRTC(r,n);const c=new d.BufferGeometry().setFromPoints(r),u=new F(H.Point);u.geometry=c,u.material=Ei,l?console.warn("Line has both segments and points – consider using a Group"):l=u}if(l)return a&&(this.setRTCUserData(l),l.matrix.setPosition(n.x,n.y,n.z)),l.layers.enableAll(),l}loadLWPolyline(e,i,s){if(!e.vertices||e.vertices.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const r=[...e.vertices];if(e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0){j.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const g=V.getOcsMatrix(j).invert(),x=e.elevation!==void 0?e.elevation:0;r.forEach(y=>{j.set(y.x,y.y,x).applyMatrix4(g),y.x=j.x,y.y=j.y})}let n=us(r,e.shape);if(e.shape&&n.length>0&&!R.areVector3sEqual(n[0],n[n.length-1])&&n.push(n[0]),n.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new F;const o=e.extendedData;if(o?.outlines){const g=o.outlines,x=[];g.forEach(v=>{const b=new d.Shape;v.forEach((E,O)=>{O===0?b.moveTo(E[0],E[1]):b.lineTo(E[0],E[1])}),b.closePath(),x.push(new d.ShapeGeometry(b))});const y=xe.mergeGeometries(x),T=new F(H.Mesh);T.geometry=y,T.material=_t,T.layers.enableAll(),T.layers.disable(Ce),a.add(T)}let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,c));const u=U.getAdjacentNonRepeatPoints(n);if(u.length<2){S.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const f=e.constantWidth;if(this.enablePlineWidth){const g=r.some(x=>x.startWidth!==void 0||x.endWidth!==void 0);if(g||f!==void 0&&f>0){let x;const y=i.tables?.lineType?.lineTypes,T=this.getLineType(e,i,s),v=y?.[T];if(!v||!v.pattern||v.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,g?x=this.createTaperedPolylineGeometry(r):x=U.convertWidthLineToMeshGeometry(u,f),!x)S.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const b=new F(H.Mesh);b.geometry=x,b.material=_t,b.layers.enableAll(),b.layers.disable(Ce),a.add(b);const E=$.createOutline(x,le,b.matrix),O=new F(H.LineSegment);O.geometry=E.geometry,O.material=E.material,O.matrix=E.matrix,O.layers.enableAll(),O.layers.disable(Ce),a.add(O)}}}const m=new F(H.Line);return m.geometry=new d.BufferGeometry().setFromPoints(u),m.material=le,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(c)),a}createTaperedPolylineGeometry(e){if(!e||e.length<2)return null;const i=[],s=[],r=[],n=[];for(let l=0;l<e.length-1;l++){const c=e[l],u=e[l+1],f=u.x-c.x,m=u.y-c.y,g=Math.hypot(f,m);if(g===0)continue;const x=-m/g,y=f/g,T=l===0?c.startWidth:c.endWidth,v=u.startWidth,b=T/2,E=v/2;c.x+x*b,c.y+y*b,c.x-x*b,c.y-y*b;const O={x:u.x+x*E,y:u.y+y*E},_={x:u.x-x*E,y:u.y-y*E};r.push(O),n.push(_)}const a=r.length;for(let l=0;l<a;l++)i.push(r[l].x,r[l].y,0),i.push(n[l].x,n[l].y,0);for(let l=0;l<a-1;l++){const c=l*2;s.push(c,c+1,c+2),s.push(c+1,c+3,c+2)}const o=new d.BufferGeometry;return o.setAttribute("position",new d.Float32BufferAttribute(i,3)),o.setIndex(s),o}loadMLeader(e,i,s){const r=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i),n=e.contextData?.defaultTextContents;if(!n)return;const a=new F,o=li(n),l=this.getTextStyle(i,e),c=this.getMTextGroup(o,e,l,i,s),u=c&&c.object;if(u){u.matrix.decompose(Z,he,ze),e.contextData?.textLocation&&(Z.x+=e.contextData.textLocation.x,Z.y+=e.contextData.textLocation.y,u.matrix.compose(Z,he,ze)),We.makeEmpty();const f=F.getBox(u,We),m=f.getSize(j),g=m.x,x=m.y;let y=0,T=0;switch(e.contextData?.textAttachment){case 1:y=0,T=0;break;case 2:y-=g/2,T=0;break;case 3:y-=g,T=0;break;case 4:y=0,T+=x/2;break;case 5:y-=g/2,T+=x/2;break;case 6:y-=g,T+=x/2;break;case 7:y=0,T+=x;break;case 8:y-=g/2,T+=x;break;case 9:y-=g,T+=x;break;default:return}u.traverse(E=>{E.geometry&&E.geometry.translate(y,T,0)});let v=0;if(e.contextData?.textRotation&&(v=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const E=e.contextData.textDirection,O=new d.Vector3(E.x,E.y,E.z),_=O.clone().cross(Ae),C=Ae.angleTo(O);v+=_.z>0?-C:C}U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(u),u.matrix.compose(Z,he,ze),e.contextData?.textLocation?j.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):j.set(0,0,0);const b=Z.clone().sub(j);Fe.makeTranslation(-b.x,-b.y,0),ne.makeRotationZ(v),u.matrix.multiply(Fe),u.matrix.multiply(ne),u.matrix.multiply(Fe.invert()),u.renderOrder=ge.Text,a.add(u)}if(e.leaderLineType!==0){const f=[],m=e.contextData?.leaders[0];if(!m)return a;const g=m.lastLeaderLinePoint;if(e.enableDogLeg){const E=new d.Vector3(g.x,g.y,g.z),O=m.doglegLength,_=new d.Vector3(m.doglegVector.x,m.doglegVector.y,m.doglegVector.z),C=_.multiplyScalar(O),w=E.clone().add(C);f.push(w,E)}const x=e.contextData?.leaders[0].leaderLines||[];for(let E=0;E<x.length;E++){const O=x[E].vertices[0],_=O.reverse().map(k=>new d.Vector3(k.x,k.y,k.z));let C=new d.Vector3(g.x,g.y,g.z);for(let k=0;k<_.length;k++)f.push(C,_[k]),C=_[k];const w=j.subVectors(f[0],f[1]).length(),M=e.arrowHeadSize||r.DIMASZ||2.5,P=e.arrowHeadScale||r.DIMSCALE||1,A=M*P;e.leaderLineType;let I="";if(e.arrowHeadId?I=e.arrowHeadId:r&&r.DIMLDRBLK&&(I=r.DIMLDRBLK),I){const k=this.getBlockByHandle(i.blocks,I);if(k&&k.entities)for(let B=0;B<k.entities.length;B++){const L=this.loadEntity(k.entities[B],i,e);if(L){const q=new d.Vector3(f[f.length-1].x,f[f.length-1].y,f[f.length-1].z),me=new d.Vector3(f[f.length-2].x,f[f.length-2].y,f[f.length-2].z),ue=Math.atan2(q.y-me.y,q.x-me.x);j.copy(q),Z.setScalar(A),he.setFromAxisAngle(Et,ue),L.matrix.compose(j,he,Z),a.add(L)}}}else this.loadDefaultLeadArrow(f[f.length-2],f[f.length-1],w/2e3,f)}const y=new d.Vector3;let T=!1;this.enableRTC&&(T=U.checkAndRebasePositionsOnRTC(f,y));const v=new d.BufferGeometry().setFromPoints(f),b=new F(H.LineSegment);b.geometry=v,b.material=le,b.renderOrder=ge.Line,T&&(this.setRTCUserData(b),b.matrix.setPosition(y.x,y.y,0)),a.add(b)}else return u?.traverse(f=>{f.layers.enableAll()}),u;return et.merge(a,!1),a.traverse(f=>{f.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const r=[];if(!e.vertices)return S.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return S.warn("leader's vertices number must be greater than 2"),void 0;const n=i.tables.dimStyle.dimStyles[e.dimensionStyle]||this.getDefaultDimensionStyle(i);let a=e.vertices;if(e.pathType===1&&(a=new d.SplineCurve(e.vertices).getPoints(50)),e.textWidth){const T=e.textWidth,v=new d.Vector3(a[a.length-1].x,a[a.length-1].y,a[a.length-1].z);if(e.direction===0){const b=new d.Vector3(1,0,0).multiplyScalar(T);a.push(b.add(v))}else{const b=new d.Vector3(-1,0,0).multiplyScalar(T);a.push(b.add(v))}}for(let T=0;T<a.length-1;T++){const v=a[T],b=a[T+1];r.push(v,b)}const o=j.subVectors(r[0],r[1]).setZ(0).length(),l=e.arrowHeight||n.DIMASZ||2.5,c=e.arrowHeadScale||n.DIMSCALE||1,u=l*c,f=new F;if(e.arrowFlag===1){let T="";e.arrowHeadBlockHandle?T=e.arrowHeadBlockHandle:n&&n.DIMLDRBLK&&(T=n.DIMLDRBLK);const v=this.getBlockByHandle(i.blocks,T);if(v&&v.entities){n&&(e.colorIndex=n.DIMCLRD||256,e.color=Nt(e.colorIndex));for(let b=0;b<v.entities.length;b++){const E=this.loadEntity(v.entities[b],i,e);if(E){const O=new d.Vector3(r[0].x,r[0].y,r[0].z),_=new d.Vector3(r[1].x,r[1].y,r[1].z),C=Math.atan2(O.y-_.y,O.x-_.x);j.copy(O),Z.setScalar(u),he.setFromAxisAngle(Et,C),E.matrix.compose(j,he,Z),f.add(E)}}}else this.loadDefaultLeadArrow(r[1],r[0],u/o/2,r)}if(r.length===0)return;const m=new d.Vector3;let g=!1;this.enableRTC&&(g=U.checkAndRebasePositionsOnRTC(r,m));const x=new d.BufferGeometry().setFromPoints(r),y=new F(H.Line);return y.geometry=x,y.material=le,y.renderOrder=ge.Line,g&&(this.setRTCUserData(y),y.matrix.setPosition(m.x,m.y,0)),f.children.length>0?(f.add(y),et.merge(f,!1),f.traverse(T=>{T.layers.enableAll()}),f.children.length===1?f.children[0]:f):(y.layers.enableAll(),y)}getTableTextOffset(e,i,s){const r=new d.Vector3;switch(e){case 1:break;case 2:r.setX(i/2);break;case 3:r.setX(i);break;case 4:r.setY(-s/2);break;case 5:r.set(i/2,-s/2,0);break;case 6:r.set(i,-s/2,0);break;case 7:r.setY(-s);break;case 8:r.set(i/2,-s,0);break;case 9:r.set(i,-s,0);break}return r}loadTable(e,i,s){if(!e.startPoint){S.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){S.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){S.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){S.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const r=new F,{cells:n,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:c}=e,u=[];let f=0;for(let y=0;y<a;y++){u[y]=[];for(let T=0;T<o;T++)u[y][T]=f<n.length?n[f++]:null}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;let b=1,E=1;for(;y+b<a&&u[y+b][T]&&u[y+b][T].mergedValue===1;)b++;for(;T+E<o&&u[y][T+E]&&u[y][T+E].mergedValue===1;)E++;v.rowSpan=b,v.colSpan=E}const m=[0];for(let y=0;y<a;y++)m.push(m[y]-l[y]);const g=[0];for(let y=0;y<o;y++)g.push(g[y]+c[y]);const x=[];for(let y=0;y<=a;y++){let T=g[0],v=!1;for(let b=0;b<o;b++){y>0&&u[y-1][b],y<a&&u[y][b];let E=!0;if(y===0||y===a)E=!0;else{const O=this._getMergeOwner(u,y-1,b,a,o),_=this._getMergeOwner(u,y,b,a,o);E=O!==_}E?v||(v=!0,T=g[b]):v&&(x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[b],m[y],0)),v=!1)}v&&x.push(new d.Vector3(T,m[y],0),new d.Vector3(g[o],m[y],0))}for(let y=0;y<=o;y++){let T=m[0],v=!1;for(let b=0;b<a;b++){y>0&&u[b][y-1],y<o&&u[b][y];let E=!0;if(y===0||y===o)E=!0;else{const O=this._getMergeOwner(u,b,y-1,a,o),_=this._getMergeOwner(u,b,y,a,o);E=O!==_}E?v||(v=!0,T=m[b]):v&&(x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[b],0)),v=!1)}v&&x.push(new d.Vector3(g[y],T,0),new d.Vector3(g[y],m[a],0))}if(x.length>0){const y=new d.BufferGeometry().setFromPoints(x),T=new F(H.LineSegment);T.geometry=y,T.material=le,T.layers.enableAll(),r.add(T)}for(let y=0;y<a;y++)for(let T=0;T<o;T++){const v=u[y][T];if(!v||v.mergedValue!==0)continue;const b=g[T],E=m[y];let O=0;for(let M=0;M<(v.colSpan||1);M++)O+=c[T+M];let _=0;for(let M=0;M<(v.rowSpan||1);M++)_+=l[y+M];v.colorIndex=e.colorIndex,v.height=v.textHeight||2.5;const C=this.getTableTextOffset(v.attachmentPoint||1,O,_);j.set(b,E,0),j.add(C),v.position=j.clone();const w=this.loadMText(v,i,s);w&&r.add(w)}if(e.blockRecordHandle){const y=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(y&&y.entities)for(const T of y.entities){T.isTable=!0;const v=this.loadEntity(T,i,e);v&&r.add(v)}}return r.matrix.decompose(j,he,ze),j.x+=e.startPoint.x,j.y+=e.startPoint.y,r.matrix.compose(j,he,ze),r}_getMergeOwner(e,i,s,r,n){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,r){const n=s*(e.x-i.x),a=s*(e.y-i.y),o=a,l=-n,c=new d.Vector3(i.x+n+o/6,i.y+a+l/6,0),u=new d.Vector3(i.x+n-o/6,i.y+a-l/6,0);r.push(i,c),r.push(i,u),r.push(c,u)}getBlockByHandle(e,i){if(!this.blocksCache){this.blocksCache={};for(const s in e){const r=e[s];!this.blocksCache[r.ownerHandle]&&(this.blocksCache[r.ownerHandle]=r)}}return this.blocksCache[i]}static updateMaterialUniforms(e){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=V.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=V.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=j.set(Math.cos(i)*1,Math.sin(i)*1,0),r=s.applyMatrix4(e);return Math.atan2(r.y,r.x)}static getArcAnglesByOcsMatrix(e,i,s){let r=R.getArcAngleSpanInRadian(i,s);const n=V.transformAngleByOcsMatrix(e,i),a=V.transformAngleByOcsMatrix(e,s);let o;if(R.areNumbersClose(r,Math.PI)){r=1;const l=V.transformAngleByOcsMatrix(e,i+r);o=R.getArcAngleSpanInRadian(n,l)}else{if(R.areNumbersClose(r,Math.PI*2))return[n,n+Math.PI*2];o=R.getArcAngleSpanInRadian(n,a)}return R.areNumbersClose(r,o,1e-5)?[n,a]:[a,n]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return S.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is too small, ignored!"),void 0;const r=new d.Vector3(0,0,1);e.extrusionDirectionX!==void 0&&e.extrusionDirectionY!==void 0&&e.extrusionDirectionZ!==void 0&&r.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const n=V.getOcsMatrix(r);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,R.areNumbersEqual(a,o,1e-6)))return;if(!R.areNumbersClose(R.getArcAngleSpanInRadian(a,o),Math.PI*2)){const _=V.getArcAnglesByOcsMatrix(n,a,o);a=_[0],o=_[1]}}const l=new d.ArcCurve(0,0,e.radius,a,o,this.angBase!==0);let c=1;const u=s;u?.xScale&&u?.yScale&&(c=Math.max(Math.abs(u.xScale),Math.abs(u.yScale)));const f=this.getDivision(a,o,e.radius*c),m=l.getPoints(f),g=new d.Vector3;let x=!1;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(m,g));const y=new d.BufferGeometry().setFromPoints(m),T=new F(H.Line);T.geometry=y,T.material=le;const v=new d.Vector3;e.center&&(v.x=e.center.x,v.y=e.center.y);const b=new d.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(n.invert());v.x=b.x,v.y=b.y;const E=v,O=new F(H.Point);return O.geometry=Sr,O.material=Ei,O.userData.handle=e.handle,O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(Ce),T.add(O),x?(this.setRTCUserData(T),E.x+=g.x,E.y+=g.y):U.shouldRebasePositionOnRTC(E)&&this.setRTCUserData(T),T.matrix.setPosition(E),T.layers.enableAll(),T}addTriangleFacingCamera(e,i,s,r){const n=new d.Vector3,a=new d.Vector3;n.subVectors(s,i),a.subVectors(r,i),n.cross(a);const o=new d.Vector3(i.x,i.y,i.z),l=new d.Vector3(s.x,s.y,s.z),c=new d.Vector3(r.x,r.y,r.z);n.z<0?e.push(c,l,o):e.push(o,l,c)}loadSolid(e,i,s){const r=e.points;if(!r||r.length<4)return;if(e.extrusionDirection&&e.extrusionDirection.z){j.set(0,0,e.extrusionDirection.z);const f=V.getOcsMatrix(j).invert();r.forEach(m=>{const g=j.set(m.x,m.y,0).applyMatrix4(f);m.x=g.x,m.y=g.y})}const n=[],a=[];this.addTriangleFacingCamera(n,r[0],r[1],r[2]),a.push(0,1,2),this.addTriangleFacingCamera(n,r[1],r[2],r[3]),a.push(3,4,5);const o=new d.Vector3;let l=!1;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(n,o));const c=new d.BufferGeometry().setFromPoints(n);c.setIndex(a);const u=new F(H.Mesh);return u.geometry=c,u.material=_t,l&&(this.setRTCUserData(u),u.matrix.setPosition(o.x,o.y,0)),u.layers.enableAll(),u}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,r){if(!e)return;const n=s?.styleName||"";if(s&&s.fontFile&&s.fontFile.endsWith(".shx")){const c=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[c]&&(this.statsInfo.unsupportedTextStyles[c]=0),this.statsInfo.unsupportedTextStyles[c]++}let a=.8;const o={_TCH_DIM:1.45,ROMANS:1};n&&o[n]&&(a=o[n]),r.xScale&&(a*=r.xScale),a>1&&n&&(a*=s?.xScale||1,i=i||s?.textHeight||0),i===0&&(n?i=1:i=.2);const l=this.createTextMeshByText(e,s,i,0,i/12,a);return l.traverse(c=>{c.geometry&&c.geometry.scale(a,1,1)}),l}createTextMeshByText(e,i,s=12,r=0,n=0,a=1,o=1/0,l=0){const c=new F,u=[];let f=0,m=0;i?.xScale;const g=r+s,x=i?.fontFile||"",y=typeof x=="string"&&x.toLowerCase().endsWith(".shx"),T=y?s*.06:s*.04,v=[];for(let O=0;O<e.length;O++){const _=e[O];_!==" "&&_!==`
795
- `&&v.push(O)}const b=v.length;let E=0;for(let O=0;O<e.length;O++){const _=e[O];if(_===" "){f+=s*(y?.4:.33);continue}if(_===`
796
- `){f=0,m-=g*.5;continue}let C=this.font?.getCharShape?.(_,i?.fontFile,s);if(!C&&i?.bigFontFile&&(C=this.font?.getCharShape?.(_,i.bigFontFile,s)),!C&&this.font?.fileNames){const w=this.font.fileNames.filter(M=>M!==i?.fontFile);for(let M=w.length-1;M>=0&&(i.fontFile=w[M],i.styleName="Standard",C=this.font?.getCharShape?.(_,i.fontFile,s),!C);M--);}if(C||(C=this.font?.getNotFoundTextShape?.(s)),!!C){if(C.translate(f,m,0),f>o)f=0,m-=g;else{!C.boundingBox&&C.computeBoundingBox();const w=C.boundingBox.getSize(j).x,M=_.charCodeAt(0),A=M>=19968&&M<=40959||M>=13312&&M<=19903||M>=63744&&M<=64255||M>=12288&&M<=12351||M>=65280&&M<=65519||[8216,8217,8220,8221].includes(M)?Math.max(w,s):w+T;E++,f+=A+(E===b?0:l)}u.push(C)}}if(u.length>0){const O=u.filter(C=>C instanceof d.ExtrudeGeometry),_=u.filter(C=>!(C instanceof d.ExtrudeGeometry));if(O.length>0){const C=new F(H.Mesh);C.geometry=xe.mergeGeometries(O),C.material=_t,c.add(C)}if(_.length>0){const C=new F(H.LineSegment);C.geometry=xe.mergeGeometries(_),C.material=le,c.add(C)}}return c}transformTextMesh(e,i){We.makeEmpty();const s=F.getBox(i,We),r=s.getSize(j),{halign:n,valign:a}=e;i.matrix.decompose(_i.position,_i.quaternion,_i.scale);const o=_i,l=e.width||e.textWidth||r.x,c=e.height||e.textHeight||r.y;if(n===void 0&&a===void 0&&e.startPoint||[3,5].includes(n)&&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),n!==3&&n!==5){if(e.rotation){const u=e.rotation*Math.PI/180;o.rotateZ(u)}e.mirrored&2&&o.rotateY(Math.PI),e.mirrored&4&&o.rotateX(Math.PI)}switch(n){case 0:break;case 1:o.translateX(-l/2);break;case 2:o.translateX(-l);break;case 3:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l;o.scale.multiplyScalar(x);const y=m.clone().cross(Ae),T=m.angleTo(Ae);o.rotateZ(y.z>0?Math.PI-T:T-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-c/12);break;case 5:if(e.startPoint&&e.endPoint){const u=new d.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new d.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new d.Vector3().subVectors(u,f),g=m.length(),x=g/l,T=(e.text||"").length;if(T>1){const E=(g-l)/(T-1);o.userData.letterSpacing=E}else x<3&&o.scale.setX(x);const v=m.clone().cross(Ae),b=m.angleTo(Ae);o.rotateZ(v.z>0?Math.PI-b:b-Math.PI)}break}switch(a){case 0:break;case 1:break;case 2:o.translateY(-c/2);break;case 3:o.translateY(-c);break}return o.position.z=0,o.updateMatrix(),i.matrix.copy(o.matrix),i}loadText(e,i,s){const r=e.text;if(!r)return;if(!this.font){S.info("[Dxf] Font file not set, ignoring text entity.");return}const n=this.getTextStyle(i,e),o=Ni(r,{encoding:this.getTextEncoding(n)}).map(u=>u.text).join(""),l=this.getTextMesh(o,e.textHeight,n,e);if(!l||l.children.length===0)return;this.transformTextMesh(e,l),j.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const c=U.shouldRebasePositionOnRTC(j);return c&&this.setRTCUserData(l),l.userData={...l.userData,textContent:r,dxfType:"TEXT",isMText:!1,layer:e.layer||"0",handle:e.handle,entityId:e.entityId||e.handle},l.traverse(u=>{const f=u.geometry;if(f){if(u.userData.textContent=r,u.userData.dxfType="TEXT",u.userData.layer=e.layer||"0",u.userData.handle=e.handle,u instanceof d.Mesh&&!f.getIndex()){const m=f.getAttribute("position"),g=[];for(let x=0;x<m.count;x+=3)g.push(x,x+1,x+2);f.setIndex(g)}if(f.hasAttribute("uv")&&f.deleteAttribute("uv"),f.hasAttribute("normal")&&f.deleteAttribute("normal"),!c){const m=U.caculateGeometryCenter(f);m&&U.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){let r=e.tag||e.text||e.prompt;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(c=>c.text).join();const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;this.transformTextMesh(e,o),j.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=U.shouldRebasePositionOnRTC(j);return l&&this.setRTCUserData(o),o.traverse(c=>{const u=c.geometry;if(u){if(c instanceof d.Mesh&&!u.getIndex()){const f=u.getAttribute("position"),m=[];for(let g=0;g<f.count;g+=3)m.push(g,g+1,g+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!l){const f=U.caculateGeometryCenter(u);f&&U.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(c)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){let r=e.text;if(!r||!this.font)return;const n=this.getTextStyle(i,e);r=Ni(r).map(f=>f.text).join("");const o=this.getTextMesh(r,e.textHeight,n,e);if(!o||o.children.length===0)return;const l=s?.zdysx;o.userData.llbData=l;let c;if(l)try{c=JSON.parse(l)}catch{c=l}o.userData.textContent=r||"",o.userData.dxfType="ATTRIB",o.userData.layer=e.layer||"0",o.userData.handle=e.handle||"",this.transformTextMesh(e,o),j.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const u=U.shouldRebasePositionOnRTC(j);return u&&this.setRTCUserData(o),o.traverse(f=>{const m=f.geometry;if(m){if(f instanceof d.Mesh&&!m.getIndex()){const g=m.getAttribute("position"),x=[];for(let y=0;y<g.count;y+=3)x.push(y,y+1,y+2);m.setIndex(x)}if(m.hasAttribute("uv")&&m.deleteAttribute("uv"),m.hasAttribute("normal")&&m.deleteAttribute("normal"),f instanceof d.Mesh&&(f.entity=e,f.userData.entity=e),f.userData.textContent=r,f.userData.dxfType="ATTRIB",f.userData.layer=e.layer||"0",f.userData.handle=e.handle||"",c!==void 0&&(f.userData.xdata=c),!u){const g=U.caculateGeometryCenter(m);g&&U.shouldRebasePositionOnRTC(g)&&this.setRTCUserData(f)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!e.position)return;const r=new d.BufferGeometry,n=[new d.Vector3(e.position.x,e.position.y,e.position.z)];j.set(0,0,0);const a=j;let o=!1;this.enableRTC&&(o=U.checkAndRebasePositionsOnRTC(n,a)),r.setFromPoints(n);const l=new F(H.Point);return l.geometry=r,l.material=le,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 r=i.tables.dimStyle.dimStyles[e.dimStyleName]||this.getDefaultDimensionStyle(i);r&&r.DIMCLRD>0&&(e.colorIndex=r.DIMCLRD,e.color=Nt(e.colorIndex));const n=new F;for(let o=0;o<s.entities.length;o++){const l=this.loadEntity(s.entities[o],i,e);l&&n.add(l)}if(n.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++}n.name=e.type+"<"+s.name+">",n.userData.entityType=e.type;const a=e.insertionPoint;return j.set(0,0,0),a&&j.set(a.x,a.y,0),U.shouldRebasePositionOnRTC(j)&&this.setRTCUserData(n),n.matrix.setPosition(j),n}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const r=i.objects.IMAGEDEF.filter(y=>y.handle===e.imageDefHandle)[0];if(!r)return;const n=e.imageSize.x,a=e.imageSize.y,o=new F;let l=!1;e.flags===Gi.ShowImageWhenNotAlignedWithScreen||e.flags===Gi.UseClippingBoundary||e.flags===Gi.TransparencyIsOn||(l=!0);const c=new d.PlaneGeometry(n,a);if(l){const y=new d.TextureLoader(this.manager).load(r.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=d.SRGBColorSpace;const T=new d.MeshBasicMaterial({transparent:!0,side:d.FrontSide,map:y}),v=new F(H.Mesh);v.geometry=c,v.material=T,o.add(v)}const u=new d.EdgesGeometry(c),f=this.getColor(e,i,s),m=new F(H.Line);m.geometry=u,m.material=this.getLineBasicMaterial(f);const g=e.uPixel?new d.Vector3(e.uPixel.x,e.uPixel.y,e.uPixel.z):new d.Vector3(r.pixelSize.x,0,0),x=e.vPixel?new d.Vector3(e.vPixel.x,e.vPixel.y,e.vPixel.z):new d.Vector3(r.pixelSize.y,0,0);if(o.add(m),Z.set(g.x,x.y,1),j.set(0,0,0),e.position){const y=new d.Vector3(e.position.x,e.position.y,e.position.z);y.add(g.multiplyScalar(n/2)).add(x.multiplyScalar(a/2)),j.copy(y)}return U.shouldRebasePositionOnRTC(j)&&this.setRTCUserData(o),he.identity(),o.matrix.compose(j,he,Z),o}loadInsert(e,i,s,r=!1){if(!e||!e.block)return;const n=i.blocks[e.block];if(!n||!n.entities)return;s&&e.layer==="0"&&(e.layer=s.layer),e.blockPosition=n.position;const a=new F,o=e.zdysx;let l;if(o)try{l=JSON.parse(o)}catch{l=o}for(let g=0;g<n.entities.length;g++){if(n.entities[g].type==="ATTDEF")continue;const x=this.loadEntity(n.entities[g],i,e,r);x&&(o&&V.LOADLLDATA&&(x.userData.llbData=o),l!==void 0&&x.traverse(y=>{y.geometry&&(y.userData.xdata=l)}),a.add(x))}if(a.children.length===0){const g=e.name||e.block;return!this.statsInfo.ignoredInserts[g]&&(this.statsInfo.ignoredInserts[g]=0),this.statsInfo.ignoredInserts[g]++,void 0}else{!this.blockReferencesCache[e.block]&&(this.blockReferencesCache[e.block]={referenceCount:0});const g=this.blockReferencesCache[e.block];g.referenceCount++}a.name=e.type+"<"+n.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 c=j.set(1,1,1);e.xScale&&(c.x=e.xScale),e.yScale&&(c.y=e.yScale);const u=new d.Euler;e.rotation&&(u.z=e.rotation*Math.PI/180),he.setFromEuler(u,!1);const f=Z.set(0,0,0);e.position&&(f.x=e.position.x,f.y=e.position.y),ne.compose(f,he,c),e.extrusionDirection&&e.extrusionDirection.z<0&&ne.premultiply(Or.identity().makeScale(-1,1,1)),Fe.copy(a.matrix),a.matrix.premultiply(ne),Z.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),U.shouldRebasePositionOnRTC(Z)&&this.setRTCUserData(a);const m=this.findSpatialFilterByHandle(e.handle,i);if(m){this.loadSpatialFilter(m);const g=m;g&&g.clipPolylines&&g.clipPolylines.length>0&&(a.userData.spatialFilterHandle=m.handle,this.cloneMaterialsForSpatialFilter(a),S.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;ne.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 r=[];e.vertices.forEach(o=>{r.push(new d.Vector3(o.x,o.y,0))});const n={polyline:[],bConcave:!1,bReversed:!1};if(e.numberOfPointsOnClipBoundary===2)n.polyline=r;else{const o=e.numberOfPointsOnClipBoundary,l=3;if(o<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let c=[],u=-1;for(let g=0;g<o;g++){const x=r[g];for(let y=o-1;y>g;y--){const T=r[y];if(R.areVector3sEqual(x,T)&&g+1<y-1&&g+1<o-1&&R.areVector3sEqual(r[g+1],r[y-1])){c.push(x),u=y;break}}if(u>0)break;c.push(x)}if(u>0)for(let g=u+1;g<o;g++)c.push(r[g]);if(c.length<l)return S.warn("[Dxf] Invalid clipBoundary: "+e.handle+"!"),void 0;const f=[],m=[];if(c.forEach(g=>{f.push(new d.Vector2(g.x,g.y)),m.push([g.x,g.y])}),!U.isConvex(f)){S.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const g=xa(m,1/0);c=[],g.forEach(x=>{c.push(new d.Vector3(x[0],x[1],0))})}!R.areVector3sEqual(c[0],c[c.length-1])&&c.push(c[0]),n.polyline=c,n.bReversed=u>0}let a;return this.enableReleaseData&&(e.vertices=[],e.matrix=[],e.invertBlockMatrix=[]),i.localMatrix=ne.clone(),i.clipPolylines=[],i.clipPolylines.push(n),a}loadLayout(e,i,s,r,n,a){if(!e.entities)return;const o=new F;for(let u=0;u<e.entities.length;u++){const f=e.entities[u];this.addViewport(f,a);const m=this.loadEntity(f,i);m&&(this.enableMerge&&et.merge(m,!1),o.add(m),m.traverse(g=>{if(g.geometry){const x=g.userData.layerName;let y=n[x];!y&&(y=[],n[x]=y),y.push(g),g.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[s.layoutName]&&(this.layoutsSnapObjectsMap[s.layoutName]=[]),this.layoutsSnapObjectsMap[s.layoutName].push(g))}}))}if(o.children.length===0)return;o.userData.layerName=e.layer;const l=s.layoutName;let c=r.children.find(u=>u.name===l);!c&&(c=new F,c.name=l,c.userData.isLayoutLevelObject=!0,r.add(c)),c.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 Lt.Line:{const r=e;i.push(new d.Vector2(r.startPoint.x,r.startPoint.y)),i.push(new d.Vector2(r.endPoint.x,r.endPoint.y));break}case Lt.Arc:{const r=e;let n=r.startAngle*d.MathUtils.DEG2RAD,a=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(n=Math.PI*2-n,a=Math.PI*2-a);const o=new d.ArcCurve(r.center.x,r.center.y,r.radius,n,a,!r.bCounterclockwise),l=this.getDivision(n,a,r.radius),c=o.getPoints(l);e.startPoint=c[0],e.endPoint=c[c.length-1],i.push(...c);break}case Lt.Ellipse:{const r=e,n=Math.sqrt(Math.pow(r.majorAxisEndPoint.x,2)+Math.pow(r.majorAxisEndPoint.y,2)),a=n*r.minorRatio,o=Math.atan2(r.majorAxisEndPoint.y,r.majorAxisEndPoint.x);let l=r.startAngle*d.MathUtils.DEG2RAD,c=r.endAngle*d.MathUtils.DEG2RAD;!r.bCounterclockwise&&(l=Math.PI*2-l,c=Math.PI*2-c);const u=new d.EllipseCurve(r.center.x,r.center.y,n,a,l,c,!r.bCounterclockwise,o),f=this.getDivision(l,c,Math.max(n,a)),m=u.getPoints(f);e.startPoint=m[0],e.endPoint=m[m.length-1],i.push(...m);break}case Lt.Spline:{const r=e,n=kr(r.controlPoints,r.degreeOfSplineCurve,r.knotValues);if(n.length===0)break;e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}case Lt.Polyline:{const r=e,n=us(r.points,r.isClosed);e.startPoint=n[0],e.endPoint=n[n.length-1],i.push(...n);break}}return i}loadHatch(e,i,s){const r=e;let n=[];function a(O,_){const{startPoint:C,endPoint:w}=O,{startPoint:M,endPoint:P}=_,A=w.x-C.x,I=w.y-C.y,k=P.x-M.x,B=P.y-M.y,L=A*B-I*k;if(Math.abs(L)<1e-10)return null;const q=C.x-M.x,me=C.y-M.y,ue=(k*me-B*q)/L,nt=(A*me-I*q)/L;return ue>=0&&ue<=1&&nt>=0&&nt<=1?{x:C.x+ue*A,y:C.y+ue*I}:null}function o(O){const{edges:_}=O,C=[],w=_.length;if({...O},w!==4)return[O];for(let M=0;M<w;M++)for(let P=M+2;P<w;P++){if(P===M+1||M===0&&P===w-1)continue;const A=a(_[M],_[P]);A&&C.push({edgeIndex1:M,edgeIndex2:P,point:{x:A.x,y:A.y}})}if(C.length&&C.length===1){const M={pathTypeFlag:O.pathTypeFlag,edges:[_[C[0].edgeIndex1-1],{startPoint:{..._[C[0].edgeIndex1].startPoint},endPoint:{x:C[0].point.x,y:C[0].point.y},type:_[C[0].edgeIndex1].type},{startPoint:{x:C[0].point.x,y:C[0].point.y},endPoint:{x:_[C[0].edgeIndex2].startPoint.x,y:_[C[0].edgeIndex2].startPoint.y},type:_[C[0].edgeIndex2].type}]},P={pathTypeFlag:O.pathTypeFlag,edges:[{startPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},endPoint:{..._[C[0].edgeIndex1].endPoint},type:_[C[0].edgeIndex1].type},{..._[C[0].edgeIndex2-1]},{startPoint:_[C[0].edgeIndex2].startPoint,endPoint:{x:C[0].point.x-1e-5,y:C[0].point.y-1e-5},type:_[C[0].edgeIndex2].type}]};return[M,P]}return[O]}if(r.boundaryPaths.length==0)return;for(let O=0;O<r.boundaryPaths.length;O++){const _=r.boundaryPaths[O],C=o(_);n=[...n,...C]}if(r.boundaryPaths=n,!r.solidFill&&!r.patternLines?.length){S.warn("[Dxf] Hatch entity(handle: '"+r.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],c=[],u=[],f=O=>{const _=[];let C=[];C.push(...this.convertEdgeToPoints(O[0]));for(let w=1;w<O.length;w++){const M=this.convertEdgeToPoints(O[w]);if(C.push(...M),C.length>2){const P=this.convertEdgeToPoints(O[w-1]);R.areVector2sEqual(P[P.length-1],M[0])?R.areVector2sEqual(C[0],M[M.length-1],1e-5)&&(_.push(C),C=[]):R.areVector2sEqual(P[0],M[M.length-1])?R.areVector2sEqual(C[1],M[0],1e-5)&&(_.push(C),C=[]):C=[]}}return _};if(r.boundaryPaths.forEach((O,_)=>{let C=[];if(this.IsfilteredByPathTypeFlag(O.pathTypeFlag)){S.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",O.pathTypeFlag,_,r.handle);return}const w=O.edges;if(w.length===0)return;const M=[];for(let P=0;P<w.length;P++){const A=this.convertEdgeToPoints(w[P]);if(A.length<2){S.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",P,_,r.handle);continue}M.push(...A)}if(M.length<3){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",_,r.handle);return}if(C.push(M),O.pathTypeFlag>Mn.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const k=A[I-1].endPoint,B=A[I].startPoint;if(!k||!B||!R.areVector2sEqual(k,B))return!1}return!0})(O.edges)||!r.associativity)&&(C=f(w),C.length<2)){S.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",_,r.handle);return}C.forEach(P=>{!R.areVector2sEqual(P[0],P[P.length-1])&&P.push(P[0]);const A=P.map(I=>new d.Vector2(z.roundNumber(I.x,7),z.roundNumber(I.y,7)));if(A?.length>0){l.push(A);const I=new d.Box2().setFromPoints(A);c.push(I);const k=I.getSize(Qt),B=k.x*k.y;u.push({area:B,index:l.length-1})}})}),l.length===0)return;const m=new d.Vector2,g=this.checkAndRebasePolygonsOnRTC(l,m);u.sort((O,_)=>O.area-_.area);const x=[];u.forEach(O=>{x.push(O.index)});const y=this.buildContainHierarchyTree(l,c,x),T=[];this.buildHatchGeometry(l,y,T);let v;if(T.length>0&&(v=xe.mergeGeometries(T)),!v||!v.getIndex()||v.getIndex()?.count===0)return S.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const b=new F(H.Mesh);b.geometry=v,b.material=_t,this.setHatchMaterial(b,r,i,m,s);const E=b;return g&&(this.setRTCUserData(E),E.matrix.setPosition(m.x,m.y,0)),E.traverse(O=>{O.layers.enableAll(),O.layers.disable(Ce)}),E}loadOle2frame(e,i){const{leftUpX:s,leftUpY:r,rightDownX:n,rightDownY:a}=e;if(!s||!r||!n||!a)return;const o=[new d.Vector2(s,r),new d.Vector2(s,a),new d.Vector2(n,a),new d.Vector2(n,r),new d.Vector2(s,r)],l=new d.Vector3;let c=!1;this.enableRTC&&(c=U.checkAndRebasePositionsOnRTC(o,l));const u=new d.BufferGeometry().setFromPoints(o),f=this.getLineBasicMaterial(16777215),m=new F(H.Line);m.geometry=u,m.material=f,m.layers.enableAll(),c&&(this.setRTCUserData(m),m.matrix.setPosition(l.x,l.y,0));const g=new F;g.add(m);let x;const y=i.objects.DICTIONARY;for(const v of y)for(const b in v.entries)if(v.entries[b]===e.handle){x=b;break}let T;if(x)if(this.meshTextureMaterials[x])T=this.meshTextureMaterials[x];else for(let v=0;v<i.objects.XRECORD.length;v++){const b=i.objects.XRECORD[v];if(b.handle===x){const E=b.binaryData,O=z.hexToBase64(E),_="data:image/jpg;base64,"+O,C=new d.TextureLoader(this.manager).load(_);C.colorSpace=d.SRGBColorSpace;const w=new d.MeshBasicMaterial({transparent:!0,map:C});this.meshTextureMaterials[x]=w,T=w;break}}if(T){const v=new d.Box2().setFromPoints(o),b=v.getSize(Qt),E=new d.PlaneGeometry(b.x,b.y),O=new F(H.Mesh);O.geometry=E,O.material=T;const _=v.getCenter(Qt);j.set(_.x,_.y,0),c&&(this.setRTCUserData(O),j.x+=l.x,j.y+=l.y),O.matrix.setPosition(j),O.layers.enableAll(),g.add(O)}return g.children.length>1?g:m}static getOcsMatrix(e){let i=Ae,s=ds,r=Et;const n=new d.Vector3(0,1,0),a=new d.Vector3(0,0,1);return R.areVectorsClose(e,a)?ne.identity():(r=e.clone().normalize(),!R.areVectorsClose(r,a)&&(Math.abs(r.x)<1/64&&Math.abs(r.y)<1/64?i=n.cross(r).normalize():i=a.cross(r).normalize(),s=r.clone().cross(i).normalize()),ne.set(i.x,i.y,i.z,0,s.x,s.y,s.z,0,r.x,r.y,r.z,0,0,0,0,1))}static getDcs2WcsMatrix(e,i){let s;ih(e)?s=e.viewDirectionFromTarget:s=e.viewDirection,s??(s={x:0,y:0,z:1});const r=e.viewTarget??{x:0,y:0,z:0},n=new d.Vector3(R.roundNumber(s.x,7),R.roundNumber(s.y,7),s.z),a=new d.Vector3(r.x,r.y,r.z),o=e.viewTwistAngle||0;let l,c,u;u=n.clone().normalize(),l=Et.clone().cross(n),l.length()>0?(l.normalize(),c=u.clone().cross(l)):u.z<0?(l=Ae.clone().negate(),c=ds,u=Et.clone().negate()):(l=Ae,c=ds,u=Et);const f=new d.Matrix4,m=ne.identity();return m.makeBasis(l,c,u),f.premultiply(m),f.premultiply(ne.identity().compose(a.clone(),new d.Quaternion().setFromAxisAngle(new d.Vector3(0,0,1),d.MathUtils.degToRad(i?o:-o)),new d.Vector3(1,1,1))),f}getViewportMsToPsMatrix(e){const i=e.centerPoint_dcs??{x:0,y:0},s=e.centerPoint??{x:0,y:0,z:0},r=new d.Vector3(i.x,i.y,0),n=new d.Vector3(s.x,s.y,s.z),a=e.viewHeight,o=e.height_paperSpace||1,l=(a||o)/o,c=V.getDcs2WcsMatrix(e,this.angDir),u=new d.Matrix4;u.setPosition(Cr.clone().sub(n));const f=Or.identity();f.scale(j.set(l,l,l));const m=Fe.identity().setPosition(Cr.clone().sub(n));f.premultiply(m.clone().invert()).multiply(m),u.multiply(f);const g=ne.identity();g.setPosition(r),c.multiply(g);const x=ne.identity();return u.invert().multiply(x).multiply(c.invert())}loadViewport(e,i,s){if(e.viewportId+""=="1"){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const r=e.centerPoint;if(!r||!Number.isFinite(r.x)||!Number.isFinite(r.y)){e.psBBox=new d.Box3,e.msToPsMatrix=new d.Matrix4;return}const n=e.width_paperSpace/2,a=e.height_paperSpace/2,o=[new d.Vector3(r.x-n,r.y-a,0),new d.Vector3(r.x-n,r.y+a,0),new d.Vector3(r.x+n,r.y+a,0),new d.Vector3(r.x+n,r.y-a,0)];o.push(o[0]),e.psBBox=new d.Box3().setFromPoints([o[0],o[2]]),e.msToPsMatrix=this.getViewportMsToPsMatrix(e);let l=!1;const c=new d.Vector3;this.enableRTC&&(l=U.checkAndRebasePositionsOnRTC(o,c));const u=new d.BufferGeometry().setFromPoints(o),f=new F(H.Line);f.geometry=u,f.material=le,f.userData.entityType=e.type,f.layers.enableAll(),l&&(this.setRTCUserData(f),f.matrix.setPosition(c.x,c.y,0));const m=e.psBBox.clone();m.applyMatrix4(e.msToPsMatrix.clone().invert()),m.min.z=0,m.max.z=0;const g=[m.min,new d.Vector3(m.min.x,m.max.y,0),m.max,new d.Vector3(m.max.x,m.min.y,0)];g.push(g[0]);let x=!1;const y=new d.Vector3;this.enableRTC&&(x=U.checkAndRebasePositionsOnRTC(g,y));const T=new d.BufferGeometry().setFromPoints(g),v=new F(H.Line);v.geometry=T,v.material=le,v.userData.entityType=e.type,v.userData.inPaperSpace=[],v.layers.enableAll(),x&&(this.setRTCUserData(v),v.matrix.setPosition(y.x,y.y,0));const b=new F;return b.add(f),b.add(v),f}getColor(e,i,s){if(this.compareContext)return Ue.ENTITY_COLOR_NO_CHANGE;if(this.overrideColor!=null)return this.overrideColor;const r=e;if(r&&r.isGradientColor){const n=r.gradientColors;if(n&&n.length>=2){if(n[0]!==n[1]){const a="[Dxf] Gradient colors are not supported for hatch '"+e.handle+"', will use the first color!";S.warn(a)}return n[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 n=i.tables?.layer?.layers,a=n&&n[e.layer],o=n&&s&&n[s.layer];let l=ct;return a&&a.name!=="0"?l=a.color:o?l=o.color:a?l=a.color:n&&n[0].color&&(l=n[0].color),l}return S.warn("[Dxf] Unknown colorIndex"),ct}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Fs&&e.lineType!==mi)return e.lineType;if(e.lineType===mi)return s?this.getLineType(s,i):e.lineType;const r=i.tables?.layer?.layers,n=th;if(e.layer!=="0"){const a=r&&r[e.layer];if(a)return a.lineType}else if(s){const a=r&&r[s.layer];if(a)return a.lineType}return n}getLayerName(e,i,s){const r=c=>{n&&c&&!n[e.layer]&&(console.warn("[Dxf] Failed to find layer object for '"+c+"', adding a default one."),n[c]={name:c,handle:"",colorIndex:256,lineType:"",visible:!0})},n=i.tables?.layer?.layers;r(e.layer);const a=n&&n[e.layer];r(s?.layer);const o=n&&s&&n[s.layer];let l=a?.name||"";return a&&a.name==="0"&&o&&(l=o.name),l}setMaterial(e,i,s,r){const n=e;if(!n.geometry||(this.setRenderOrderByObjectType(e),i.type==="OLE2FRAME"))return;if(i.type==="MTEXT"){e.renderOrder=ge.Text;return}if(i.type==="HATCH"){Qt.set(0,0),this.setHatchMaterial(e,i,s,Qt,r);return}if(i.type==="IMAGE")return;let a;const o=this.getColor(i,s,r);if(i.type==="LWPOLYLINE"&&(n.isMesh?(a=this.getMeshBasicMaterial(o),e.renderOrder=ge.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=ge.LineWithPattern),a)){n.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=ge.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 d.PointsMaterial){a=this.getPointsMaterial(o),n.material=a;return}const l=s.tables?.lineType?.lineTypes,c=l&&l[this.getLineType(i,s,r)];if(c&&c.pattern&&c.pattern.length!==0){const u=i.lineTypeScale||1;a=this.getLineShaderMaterial(c,o,u),e.renderOrder=ge.LineWithPattern}else a=this.getLineBasicMaterial(o)}n.material=a}setHatchMaterial(e,i,s,r,n){const a=e;if(!a.geometry)return;const o=this.getColor(i,s,n);if(a.type===H.Line||a.type===H.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=ge.Mesh,c;if(i.solidFill)c=this.getMeshBasicMaterial(o);else{if(a.material instanceof d.ShaderMaterial){c=a.material;const u=new d.Color(o);!a.material.uniforms.u_color.value.equals(u)&&(c=a.material.clone(),V.updateMaterialUniforms(c),c.uniforms.u_color.value.set(o))}else c=this.getHatchShaderMaterial(i,o,r);l=ge.MeshWithPattern}!c&&(c=this.getMeshBasicMaterial(o),l=ge.Mesh),a.material=c,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=ge.Mesh:i.isLine?s=ge.Line:i.isPoints&&(s=ge.Point),e.renderOrder=s}getPointsMaterial(e){return!this.pointsMaterials[e]&&(this.pointsMaterials[e]=new d.PointsMaterial({size:.2,color:e})),this.pointsMaterials[e]}getLineBasicMaterial(e){return!this.lineBasicMaterials[e]&&(this.lineBasicMaterials[e]=new d.LineBasicMaterial({color:e})),this.lineBasicMaterials[e]}getLineShaderMaterial(e,i,s){const r=e.name+"_"+i+"_"+s;if(!this.lineShaderMaterials[r]){const n=this.getLineTypeScales(),a=n.ltScale*n.celtScale*s;this.lineShaderMaterials[r]=bn.createLineShaderMaterial(e.pattern,i,a,V.ViewportScaleUniform,V.CameraZoomUniform)}return this.lineShaderMaterials[r]}getMeshBasicMaterial(e){return!this.meshBasicMaterials[e]&&(this.meshBasicMaterials[e]=new d.MeshBasicMaterial({color:e})),this.meshBasicMaterials[e]}getHatchShaderMaterial(e,i,s){if(!e.patternLines||e.patternLines.length<1)return;const r=this.findMatchedHatchShaderMaterial(e,i);if(r)return r;const n=.005,a=.05;let o=2;e.patternLines.forEach(m=>{o=Math.max(m.dashPattern.length,o)});let l=0;const c=[],u=new d.Vector2;for(const m of e.patternLines){const g=new d.Vector2(m.origin.x,m.origin.y).sub(s).rotateAround(u,-d.MathUtils.degToRad(e.patternAngle)),x=new d.Vector2(m.delta.x,m.delta.y).rotateAround(u,-d.MathUtils.degToRad(m.angle));if(x.y===0)return S.warn("[Dxf] delta.y is equal to zero !"),void 0;const y=m.dashPattern.length;let T=!0,v=0;for(let w=0;w<y;++w){const M=m.dashPattern[w];M>0&&(T=!1),v+=Math.abs(M)}const b=T?a:n,E=[],O=[];let _=0;O[0]=_;for(let w=0;w<y;++w)E[w]=m.dashPattern[w],E[w]===0&&(E[w]=b*v),_+=Math.abs(E[w]),O[w+1]=_;for(let w=y;w<o;++w)E[w]=0;for(let w=O.length;w<o+1;++w)O[w]=_;const C={origin:g,delta:x,angle:m.angle-e.patternAngle,pattern:E,patternSum:O,patternLength:_};if(l+=4,l+=o,l+=o+1,l>V.MaxFragmentUniforms){S.warn("[Dxf] There will be warning in fragment shader when number of uniforms exceeds 1024, so extra hatch line patterns are ignored here!");break}c.push(C)}const f=vn(c,e.patternAngle,V.CameraZoomUniform,new d.Color(i),this.overrideHatchPatternLineThickness);return f.defines={MAX_PATTERN_SEGMENT_COUNT:o},this.hatchShaderMaterials.push({patternLines:e.patternLines,patternAngle:e.patternAngle,color:i,material:f}),f}getDivision(e,i,s){let r=Math.round(5e4/this.entityCount);r=Math.max(r,2),r=Math.min(r,10);const n=r*5;let o=r*2;if(this.averageCurveSize){const u=Math.pow(s/this.averageCurveSize,.5);o*=u,o=Math.max(o,r),o=Math.min(o,n)}let l=i-e;l<0&&(l+=Math.PI*2),o=Math.ceil(o*(l/Math.PI));let c=8;return l<.087?c=2:l<.174?c=3:l<.52?c=4:l<1.57?c=5:l<3.14?c=6:l<4.71&&(c=7),o=Math.max(o,c),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 r=e*2*s;if(e>20){const n=Math.log10(e);r/=n}return r}async setDxfDataToIndexedDb(e,i){const s={dxfDataId:e,dxf:i};return new Promise((r,n)=>{Yi.instance().add(s,()=>{S.info("[Dxf] Saved '"+e+"' to indexedDb"),r()},a=>{n(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{Yi.instance().query(e,r=>{r&&r.length>0&&i(r[0].dxf),i(void 0)},()=>s())})}buildContainHierarchyTree(e,i,s){const r=new Map,n=s.length;for(let o=0;o<n;o++)r.set(s[o],{index:s[o],children:[]});const a={index:-1,children:[]};for(let o=0;o<n;o++){const l=s[o],c=e[l],u=i[l];let f=o+1;for(;f<n;f++){const m=s[f],g=e[m];if(i[m].containsBox(u)&&U.isPointInPolygon(c[z.generateRandomInt(0,c.length-1)],g)){r.get(m)?.children.push(r.get(l));break}}f===n&&a.children.push(r.get(l))}return a}buildHatchGeometry(e,i,s){if(i.children.length===0)return;const r=[],n=new Map;i.children.forEach(l=>{l.children.length===0?r.push(l.index):n.set(l.index,l.children.map(c=>c.index))});const a=l=>{try{const c=new d.ShapeGeometry(l);c.hasAttribute("uv")&&c.deleteAttribute("uv"),c.hasAttribute("normal")&&c.deleteAttribute("normal"),s.push(c)}catch{S.warn("[Dxf] triangulate shape error: "+l.getPoints().map(u=>u.toArray()).toString())}};r.forEach(l=>{const c=e[l];if(c.length===0)return;const u=new d.Shape(c);a(u)});const o=l=>l.map(c=>c.toArray());for(const l of n){const c=new d.Shape(e[l[0]]);let u={regions:[],inverted:!1};const f=this.findIntersectHole(e,l[1]);f.forEach(g=>{let x={regions:[],inverted:!1};try{g.forEach((y,T)=>{if(yt.epsilon(R.getVector2RelativeEps(e[y][0]),1e-6),T===0)x=yt.segments({regions:[o(e[y])],inverted:!1});else{const v=yt.segments({regions:[o(e[y])],inverted:!1}),b=yt.combine(x,v);u=yt.polygon(yt.selectUnion(b)),u.regions.length>0?u.regions.forEach(E=>{if(E.length===0)return;const O=E.map(_=>new d.Vector2(_[0],_[1]));c.holes.push(new d.Path(O))}):S.warn("[Dxf] mergedHoles.regions is empty")}})}catch(y){S.warn("[Dxf] polybooljs has error: "+y+", epsilon is "+yt.epsilon())}});const m=f.flat(2);for(let g=0;g<l[1].length;g++){const x=l[1][g];!m.includes(x)&&c.holes.push(new d.Path(e[x]))}a(c)}i.children.forEach(l=>{l.children.forEach(c=>{this.buildHatchGeometry(e,c,s)})})}findIntersectHole(e,i){const s=i.length,r=[];for(let n=0;n<s;n++){const a=e[i[n]];let o=!1;const l=[];for(let c=n+1;c<s;c++){const u=e[i[c]];U.arePolygonsIntersect(a,u)&&(o=!0,l.push(i[c]))}o&&(l.push(i[n]),r.push(l))}return r}checkAndRebasePolygonsOnRTC(e,i){if(!this.enableRTC||e.length===0)return!1;let s=0;e.forEach(n=>{n.forEach(a=>{i.add(a),s++})}),i.divideScalar(s);let r=!1;if(this.enableRTC&&U.shouldRebasePositionOnRTC(i)){r=!0;for(let n=0;n<e.length;n++){const a=e[n];for(let o=0;o<a.length;o++){const l=a[o].x-i.x,c=a[o].y-i.y;a[o]=new d.Vector2(l,c)}}}else i.set(0,0);return r}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 n of s){const a=n;let o="";for(const l in a.entries)if(a.entries[l]==="ACAD_FILTER"){o=l;break}o&&(this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]&&S.warn("[Dxf] Why this.dictionaryObjectsCache[obj.ownerHandle] already exist?",n.ownerHandle),this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[n.ownerHandle]=o)}}const r=this.dictionaryOwnerHandleAndSpatialFilterHandlesCache[e];if(r){if(!this.spatialFiltersCache){this.spatialFiltersCache={};const n=i.objects.SPATIAL_FILTER||[];for(const a of n){const o=a;o.numberOfPointsOnClipBoundary<2||(this.spatialFiltersCache[o.ownerHandle]&&S.warn("[Dxf] Why this.spatialFiltersCache[spatialFilterObj.ownerHandle] already exist?",r),this.spatialFiltersCache[o.ownerHandle]=o)}}return this.spatialFiltersCache[r]}}initRenderOrderInfo(e){const i=new Set,s=e.objects.DICTIONARY;for(const n of s){const a=n;Object.keys(a.entries).forEach(o=>{a.entries[o]&&a.entries[o]==="ACAD_SORTENTS"&&i.add(o)})}if(i.size===0)return;const r=e.objects.SORTENTSTABLE;if(r)for(let n=0;n<r.length;++n){const a=r[n];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]:S.warn("[Dxf] Failed to handle sortEntsTable: "+a.handle+".")}break}}}findMatchedHatchShaderMaterial(e,i){const s=e.patternLines;if(!s||s.length<1)return;const r=(c,u)=>Math.abs(c-u)<1e-5,n=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!r(c[f],u[f]))return!1;return!0},a=(c,u)=>r(c.angle,u.angle)&&r(c.delta.x,u.delta.x)&&r(c.delta.y,u.delta.y)&&r(c.origin.x,u.origin.x)&&r(c.origin.y,u.origin.y)&&n(c.dashPattern,u.dashPattern),o=(c,u)=>{if(c.length!==u.length)return!1;for(let f=0;f<c.length;++f)if(!a(c[f],u[f]))return!1;return!0};return this.hatchShaderMaterials.find(c=>c.color===i&&c.patternAngle===e.patternAngle&&o(c.patternLines,s))?.material}getLayout(e,i){if(!this.blockRecordsCache){this.blockRecordsCache={};const n=this.blockRecordsCache,a=e.tables?.blockRecord?.blockRecords;a&&Object.values(a).forEach(o=>{n[o.handle]=o.layoutHandle})}const s=this.blockRecordsCache[i.ownerHandle];if(s){const n=e.objects.LAYOUT,a=n.find(o=>o.handle===s);if(a)return a}if(!this.entitiesCache){this.entitiesCache={};const n=this.entitiesCache;Object.values(e.entities).forEach(a=>{n[a.handle]=a})}const r=this.entitiesCache[i.ownerHandle];return r?this.getLayout(e,r):e.objects.LAYOUT.find(n=>n.layoutName===V.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=r=>{let n;if(Array.isArray(r)){const a=[];n=a,r.forEach(o=>{if(i.has(o.id))a.push(i.get(o.id));else{const l=o.clone();V.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else r&&(i.has(r.id)?n=i.get(r.id):(n=r.clone(),V.updateMaterialUniforms(n),i.set(r.id,n)));return n};e.traverse(r=>{r.material&&(r.material=s(r.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 De.Unitless;case 1:return De.Inches;case 2:return De.Feet;case 4:return De.Millimeters;case 5:return De.Centimeters;case 6:return De.Meters;default:S.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return De.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const r=e.matrixWorld;if(s.index&&(S.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=U.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){S.debug("[Dxf] This line has been merged!");let n=0;e.userData.batches.forEach(a=>{a.positionStart=n,a.positionCount=a.indexCount,a.indexStart=0,a.indexCount=0,n+=a.positionCount})}if(s.index===null){const n=s.attributes.position;if(!n||n.count===0)return;const a=[];if(i)for(let o=0,l=n.count;o<l;o+=2)j.fromBufferAttribute(n,o).applyMatrix4(r),Z.fromBufferAttribute(n,o+1).applyMatrix4(r),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+j.distanceTo(Z);else{a[0]=0;for(let o=1,l=n.count;o<l;o++)j.fromBufferAttribute(n,o-1).applyMatrix4(r),Z.fromBufferAttribute(n,o).applyMatrix4(r),a[o]=a[o-1],a[o]+=j.distanceTo(Z)}s.setAttribute("lineDistance",new d.Float32BufferAttribute(a,1)),e.geometry=s}else S.warn("[Dxf] computeLineDistances only possible with non-indexed BufferGeometry.")}static computeLineDistances(e){const i=Date.now();e.traverse(s=>{const r=s;r.isLine&&r.material instanceof d.ShaderMaterial&&V.computeLineDistance(r)}),S.debug("[Dxf] Computed line distances in "+(Date.now()-i)/1e3+"s")}static mergeDxfObjects(e){const i=Date.now(),s={},r={},n=15e3;let a=0,o=0;const l=()=>{const u=Date.now();for(const f in s){const m=s[f];V.removeEmptyObjectsFromRemovingMarkedObjects2(m.children,m.object),m.children=[]}a=0,o+=Date.now()-u};for(const u in e.layersAndObjects){const f=e.layersAndObjects[u];if(f.length<=1)continue;const m=Date.now(),g={},x=[];for(const y of f){if(y.userData.isSnapObject){x.push(y);continue}let T,v=y;for(;v;){if(v.userData.isLayoutLevelObject){T=v;break}v=v.parent}if(!T)continue;const b=T.name;!g[b]&&(g[b]={object:T,children:[]}),g[b].children.push(y)}for(const y in g){const T=g[y],v=et.deepMerge(T.children,T.object,!1,!1,!0),b=v.added,E=v.removed;!s[y]&&(s[y]={object:T.object,children:[]}),!r[y]&&(r[y]={object:T.object,children:[]});const O=E.length>n;if(O){const _=Date.now();V.removeEmptyObjectsFromRemovingMarkedObjects2(E,T.object),o+=Date.now()-_}else a+=E.length;if(E.length===T.children.length)!O&&E.forEach(_=>{s[y].children.push(_)});else{let _=E;E.length>=100&&(_=new Set(E));const C=w=>Array.isArray(_)?_.indexOf(w)>=0:_.has(w);for(let w=0;w<T.children.length;w++){const M=T.children[w];C(M)?!O&&s[y].children.push(M):x.push(M)}}for(let _=0;_<b.length;_++){const C=b[_];x.push(C),r[y].children.push(C)}a>n&&l()}e.layersAndObjects[u]=x,S.debug("[Dxf] Merged layer '"+u+"' in "+(Date.now()-m)/1e3+"s")}a>0&&l();for(const u in r){const f=r[u];!e.root.children.find(g=>g.name===u)&&e.root.add(f.object),f.children.forEach(g=>{f.object.add(g)}),f.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const c=oe.MergeInfo;S.debug("[Dxf] Totally merged "+c.removedObjects+" objects to "+c.mergedMeshes+"meshes, "+c.mergedLines+"lines, "+c.mergedPoints+"points, "+(c.mergedUnknownTypeObjects?c.mergedUnknownTypeObjects+" unknown type,":" ")+" ")}static async merge(e,i){const s=z.getUpdateProgressFuncAsync(i),r={};e.objects.LAYOUT.forEach(y=>{const T=y;r[T.layoutName]=T,T.directAssociatedLeafObjectSet?.clear()});const n=Date.now(),a={},o={},l=15e3;let c=0,u=0;const f=()=>{const y=Date.now();for(const T in a){const v=a[T];V.removeEmptyObjectsFromRemovingMarkedObjects(v.children,v.object),v.children=[]}c=0,u+=Date.now()-y},m=Object.keys(e.layersAndThreejsObjects).length;let g=0;for(const y in e.layersAndThreejsObjects){const T=e.layersAndThreejsObjects[y];if(T.length<=1){await s(++g/m*100);continue}const v=Date.now(),b={},E=[];for(const C of T){if(C.userData.isSnapObject){E.push(C);continue}let w,M=C;for(;M;){if(M.userData.isLayoutLevelObject){w=M;break}M=M.parent}if(!w)continue;const P=w.name;!b[P]&&(b[P]={object:w,children:[]}),b[P].children.push(C)}const O=Object.keys(b).length;let _=0;for(const C in b){let w;if(C!==V.MODEL_LAYOUT_NAME){const B=r[C];!B.directAssociatedLeafObjectSet&&(B.directAssociatedLeafObjectSet=new Set),w=B.directAssociatedLeafObjectSet}const M=b[C],P=oe.deepMerge(M.children,M.object,!1,!1,!0),A=P.added,I=P.removed;!a[C]&&(a[C]={object:M.object,children:[]}),!o[C]&&(o[C]={object:M.object,children:[]});const k=I.length>l;if(k){const B=Date.now();V.removeEmptyObjectsFromRemovingMarkedObjects(I,M.object),u+=Date.now()-B}else c+=I.length;if(I.length===M.children.length)!k&&I.forEach(B=>{a[C].children.push(B)});else{let B=I;I.length>=100&&(B=new Set(I));const L=q=>Array.isArray(B)?B.indexOf(q)>=0:B.has(q);for(let q=0;q<M.children.length;q++){const me=M.children[q];L(me)?!k&&a[C].children.push(me):(E.push(me),w&&w.add(me))}}for(let B=0;B<A.length;B++){const L=A[B];$.setSharedVariablesOfObject(L),E.push(L),o[C].children.push(L),w&&w.add(L)}c>l&&f(),await s((g+ ++_/O)/m*100)}await s(++g/m*100),e.layersAndThreejsObjects[y]=E,S.debug("[Dxf] Merged layer '"+y+"' in "+(Date.now()-v)/1e3+"s")}c>0&&f();for(const y in o){const T=o[y],v=e.threejsObject.children.find(b=>b.name===y);if(v){const b=v.children.find(E=>E.name===V.SNAP_GROUP_NAME);if(b&&y!==V.MODEL_LAYOUT_NAME){const E=r[y];!E.directAssociatedLeafObjectSet&&(E.directAssociatedLeafObjectSet=new Set),b.children.forEach(O=>E.directAssociatedLeafObjectSet?.add(O))}}!v&&e.threejsObject.add(T.object),T.children.forEach(b=>{!b.visible&&(b.userData.layerVisible=!1),T.object.add(b),b.updateWorldMatrix(!1,!1)}),T.children=[]}S.debug("[Dxf] MergeUtils.deepMerge took "+oe.MergeInfo.elapsedTime/1e3+"s"),S.debug("[Dxf] The remove operation of deep merge took "+u/1e3+"s"),S.debug("[Dxf] Deep merge totally took "+(Date.now()-n)/1e3+"s");const x=oe.MergeInfo;S.debug("[Dxf] Totally merged "+x.removedObjects+" objects to "+x.mergedMeshes+"meshes, "+x.mergedLines+"lines, "+x.mergedPoints+"points, "+(x.mergedUnknownTypeObjects?x.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const r in e)e[r].averageTime=e[r].totalTime/e[r].createCount;S.debug("[Dxf] Entity types and took how much time in ms:",e),S.debug("[Dxf] Entity types and mesh count:",this.statsInfo.entityTypesAndMeshCount);let i=0;if(Object.values(this.statsInfo.entityTypesAndMeshCount).forEach(r=>{i+=r}),this.enableRTC&&S.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const r=oe.MergeInfo;S.debug("[Dxf] Inner merged "+r.removedObjects+" objects to "+r.mergedMeshes+"meshes, "+r.mergedLines+"lines, "+r.mergedPoints+"points, "+(r.mergedUnknownTypeObjects?r.mergedUnknownTypeObjects+" unknown type,":" ")+"in "+r.elapsedTime/1e3+"s")}const s=(r,n,...a)=>{Object.keys(n).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&&S.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 r=new WeakSet;let n=0;if(e.threejsObject.traverse(a=>{a.geometry&&(n++,r.has(a)?console.warn(a):r.add(a))}),s!=n)for(const a in e.layersAndThreejsObjects)e.layersAndThreejsObjects[a].forEach(l=>{l.geometry&&!r.has(l)&&console.warn(l)});S.info("[Dxf] The count of layer objects is "+s+",The count of layout objects is "+n+" ")}static removeEmptyObjectsFromRemovingMarkedObjects(e,i){if(e.length===0)return;const s=r=>{const n=[];for(const a of r){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&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark(i)}static removeEmptyObjectsFromMark(e){if(e.userData.validCount===0||$.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=r=>{const n=[];for(const a of r){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&&n.push(o))}n.length>0&&s(n)};s(e),this.removeEmptyObjectsFromMark2(i)}static removeEmptyObjectsFromMark2(e){if(e.userData.validCount===0||e.type===H.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}};p(V,"MODEL_LAYOUT_NAME","Model"),p(V,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),p(V,"SHOW_SNAP_OBJECT",!1),p(V,"REQUWSTHEADER"),p(V,"CameraZoomUniform",{value:1}),p(V,"ViewportScaleUniform",{value:1}),p(V,"TransformMatrixUniform",{value:new d.Matrix4}),p(V,"ResolutionUniform",{value:new d.Vector2}),p(V,"LOADLLDATA",!1),p(V,"MaxFragmentUniforms",1024);let Y=V;class As extends mt{constructor(e){super();p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");this.drawableList=new bi("compare"),this.viewer=e,this.overlayRender=this.viewer.getOverlayRender(),this.overlayRender?.addDrawableList(this.drawableList)}drawCompareDrawable(e){const i=[],s=[],r=[];for(const l of Object.values(e)){const c=l.box;c&&(l.type===Te.Added?i.push(c):l.type===Te.Removed?s.push(c):r.push(c))}const n=U.mergeBBoxes(i),a=U.mergeBBoxes(s),o=U.mergeBBoxes(r);this.drawableList.addDrawable(new Je(z.guid(),n,[.1,.9,.2,1])),this.drawableList.addDrawable(new Je(z.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new Je(z.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class Ji{}const Pt=new d.Matrix4,fs=new d.Box3;class Wt extends Ji{constructor(e){super();p(this,"modelId");p(this,"modelData");p(this,"modelObject");p(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 d.Box3,i=this.getModelObject();e.setFromObject(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return De.Unitless;const e=this.dxfData.header;if(!e)return S.warn("DxfData or its header is undefined!"),De.Unitless;const i=e.$INSUNITS;return Y.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new d.Vector3,s=new d.Vector3;if(!e){S.error("Header is undefined in "+this.modelId+"!");return}const r=this.viewports;let n=e.$EXTMIN,a=e.$EXTMAX;const o=e.$ANGDIR;if(r&&r.length>0)for(let l=0;l<r.length;l++){const c=r[l];if(c.name.toLocaleUpperCase()==="*ACTIVE"){const{center:u,viewHeight:f,aspectRatio:m}=c,g=f*m,x=Y.getDcs2WcsMatrix(c,o),y=new d.Vector3(u.x,u.y,0);y.applyMatrix4(x),n={x:y.x-g/2,y:y.y-f/2,z:0},a={x:y.x+g/2,y:y.y+f/2,z:0};break}}return i.set(n.x,n.y,n.z),s.set(a.x,a.y,a.z),new d.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(r=>{e.push(r)}),e}getLayoutByName(e){let i;const s=this.getLayouts();for(const r of s)if(r.layoutName===e){i=r;break}return i}getLayoutExtent(e){const i=this.header,s=new d.Vector3,r=new d.Vector3;if(!i)throw new Error("Header is undefined in "+this.modelId+"!");const n=this.getLayoutViewports(e);let a=i.$PEXTMIN,o=i.$PEXTMAX;const l=i.$ANGDIR;if(n&&n.length>0){const c=n.filter(T=>parseInt(T.viewportId)===1);let u;c.length>0?u=c[0]:u=n[0];const{centerPoint:f,width_paperSpace:m,height_paperSpace:g}=u,x=Y.getDcs2WcsMatrix(u,l),y=new d.Vector3(f.x,f.y,0);y.applyMatrix4(x),a={x:y.x-m/2,y:y.y-g/2,z:0},o={x:y.x+m/2,y:y.y+g/2,z:0}}return s.set(a.x,a.y,a.z),r.set(o.x,o.y,o.z),new d.Box3(s,r)}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,r){const n=this.getLayer(e);n?n.visible=i:S.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&&r&&l.userData.visibleMinZoom&&r<l.userData.visibleMinZoom)&&(l.visible=i),(i===!1||l.userData.layerVisible!=null)&&(l.userData.layerVisible=i),l.userData.isSnapObject&&(l.visible?Y.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(Ce):Y.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(Ce))}else S.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 r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialOpacity(o,i),Y.updateMaterialUniforms(o),a.material=o}}):S.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 r=this.getObjectsByLayer(e);r?r.forEach(n=>{const a=n;if(a.material){!a.userData.originalMaterial&&(a.userData.originalMaterial=de.cloneMaterial(a.material));const o=de.cloneMaterial(a.material);de.setMaterialColor(o,new d.Color(i)),Y.updateMaterialUniforms(o),a.material=o}}):S.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(r=>{const n=r;n.material&&n.userData.originalMaterial&&(n.material.dispose(),n.material=n.userData.originalMaterial,delete n.userData.originalMaterial)}):S.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(Pt.identity(),!i||!z.isMatrixValid(i)||i.equals(Pt))return;const s=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);s&&(e===Y.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=Y.MODEL_LAYOUT_NAME,i){this.switchTransformMs(e);const s=this.getLayoutByName(e);if(s){if(!i){const r=this.getLayoutViewports(s);let n=[];r.length>0&&(n=r[0].frozenLayerHandles);const a=e!==Y.MODEL_LAYOUT_NAME,o=this.getLayoutLevelObject(e);if(o){const u=[];o.traverse(f=>{this.addSpatialFilterSection(f,this.dxfData);const m=f;if(a&&m.material&&m.geometry){const g=m.userData.layerName;if(this.isLayerFrozenForViewport(g,n))return;u.push(m);let x=-1;const y=this.getObjectsByLayer(g);y&&(x=y.indexOf(m),x>=0&&y.splice(x,1)),x<0&&S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+g+"', layout '"+e+"'")}}),u.forEach(f=>{f.removeFromParent()})}const l=this.getFilteredViewports(s);S.debug("[Viewer] Active layout:",e,", viewports:",l);const c=Date.now();l.forEach(u=>{this.generateObjectsByViewport(e,u,this)}),S.info("[Viewer] generateObjectsByViewport in "+(Date.now()-c)/1e3+"s")}this.showLayoutObjects(e)}}getFilteredViewports(e){const i=this.getLayoutViewports(e);let s=i.filter(r=>r.viewportId!=="1");return s.length===i.length&&(s=i.filter((r,n)=>n!==0)),s}generateObjectsByViewport(e,i,s,r=[]){const n=i;if(i.viewportId=="1")return;if(!n.psBBox||!n.msToPsMatrix)throw new Error("The bbox or matrix is invalid in the viewport!");Y.TransformMatrixUniform={value:n.msToPsMatrix},Y.ViewportScaleUniform={value:i.viewHeight/i.height_paperSpace};const a=n.psBBox.clone();a.applyMatrix4(n.msToPsMatrix.clone().invert()),a.min.setZ(-1),a.max.setZ(1);const o=this.getObjectsByBoundingBox(a);if(o.length===0)return;const l=n.psBBox.min,c=n.psBBox.max,u=new d.Box2(new d.Vector2(l.x,l.y),new d.Vector2(c.x,c.y)),f=dt.generateSectionPlanesByBox(u),m=[],g=M=>(!m[M.id]&&(m[M.id]=M.clone(),this.setMaterialUniforms(m[M.id],s.dxfData),dt.setMaterialSection(m[M.id],f)),m[M.id]),x=M=>{if(Array.isArray(M)){const P=[];return M.forEach(A=>{const I=g(A);P.push(I)}),P}else return g(M)},y=[...r,...i.frozenLayerHandles||[]];let T;if(e!==Y.MODEL_LAYOUT_NAME){const M=n;!M.associatedLeafObjectSet&&(M.associatedLeafObjectSet=new Set),T=M.associatedLeafObjectSet}const v=new d.Group;v.name=n.viewportId;const b=[];if(o.forEach(M=>{const P=M.clone();P.traverse(A=>{const I=A;if(I.material&&I.geometry){const k=I.userData.layerName;if(this.isLayerFrozenForViewport(k,y)){b.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=x(I.material),T?.add(I);const B=s.getObjectsByLayer(k);B?B.push(I):S.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+k+"', layout '"+e+"'")}}),v.add(P)}),T&&T.size===0)return;const E=s.getModelObject();let O=s.getLayoutLevelObject(e);!O&&(O=new d.Group,$.setSharedVariablesOfObject(O),O.name=e,E?.add(O)),O.add(v),v.applyMatrix4(n.msToPsMatrix),v.updateMatrixWorld(!0);let _=O.children.find(M=>M.name===Y.SNAP_GROUP_NAME);!_&&(_=new d.Group,_.visible=Y.SHOW_SNAP_OBJECT,_.name=Y.SNAP_GROUP_NAME,O.add(_));const C=s.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME),w=C?.children.find(M=>M.name===Y.SNAP_GROUP_NAME);w&&w.traverse(M=>{if(!M.geometry)return;const P=M.userData.layerName;if(this.isLayerFrozenForViewport(P,y)||(fs.makeEmpty(),fs.expandByObject(M),!a.intersectsBox(fs)))return;const A=M.clone();$.setSharedVariablesOfObject(A);let I=A.parent;const k=Pt.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)k.premultiply(I.matrix),I=I.parent;k.premultiply(n.msToPsMatrix),A.applyMatrix4(k),_?.add(A),T?.add(A);const B=s.getObjectsByLayer(P);B&&B.push(A)}),b.length>0&&$.removeEmptyObjectsFromRemovingObjects(b,v),v.traverse(M=>{$.setSharedVariablesOfObject(M),this.addSpatialFilterSection(M,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof d.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=Y.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=Y.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return S.warn("[Viewer] bbox is empty !"),i;const s=n=>{const a=rt.getBoundingBox(n,!1);e.intersectsBox(a)&&i.push(n)},r=this.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME);return r&&r.children.forEach(n=>{n.name!==Y.SNAP_GROUP_NAME&&s(n)}),i}showLayoutObjects(e){let i=0,s=0;const r=this.getModelObject();r.children.forEach(n=>{const a=n.name===e;n.visible=a,a?i++:s++}),S.debug("[Viewer] showLayoutObjects('"+e+"') sets "+i+" layout level object(s) to visible and "+s+" to hidden for model '"+r?.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 r=this.findSpatialFilter(e.userData.spatialFilterHandle,i);if(r){let n=s,a=!1;const o=this.getAnyMaterial(e);if(o&&(o.clippingPlanes&&(n=o.clippingPlanes.length>0),a=o.clipIntersection),n&&a!==r.clipPolylines[0].bReversed){S.warn("[Viewer] Material cannot set clipIntersection to different values at the same time. clipIntersection needs to be set to true here!");return}a=r.clipPolylines[0].bReversed;const l=this.generateSectionsBySpatialFilter(r,e.matrixWorld);if(l){const c=m=>{let g=0;return m.clippingPlanes&&(g=m.clippingPlanes.length),g+l.length>Y.MaxFragmentUniforms},u=new Set,f=m=>{u.has(m.id)||(u.add(m.id),!c(m)&&dt.setMaterialSection(m,l,n,a))};e.traverse(m=>{const g=m.material;Array.isArray(g)?g.forEach(x=>{f(x)}):g&&f(g)})}}}findSpatialFilter(e,i){const s=i.objects.SPATIAL_FILTER;if(!s)return;let r;for(const n of s)if(n.handle===e){r=n;break}return r}getAnyMaterial(e){const i=e;if(i.material)return Array.isArray(i.material)?i.material[0]:i.material;let s;for(let r=0;r<e.children.length&&(s=this.getAnyMaterial(e.children[r]),!s);r++);return s}generateSectionsBySpatialFilter(e,i){const s=e.clipPolylines[0];if(s.bConcave){S.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}Pt.copy(i),e.localMatrix&&Pt.multiply(e.localMatrix);const r=s.polyline,n=[];r.forEach(l=>{const c=l.clone().applyMatrix4(Pt);n.push(new d.Vector2(c.x,c.y))});const a=d.ShapeUtils.isClockWise(n),o=!a&&!s.bReversed||a&&s.bReversed;return dt.generateSectionPlanesByPoints(n,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=de.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 d.Material&&i.dispose()}clearHighlight(){}}class zs extends Ji{constructor(e){super();p(this,"modelId");p(this,"bbox");p(this,"rootObject");p(this,"modelObject");p(this,"highlighUsage");p(this,"transparentUsage");p(this,"edges");p(this,"highlighedObject");this.modelId=e.modelId,this.bbox=e.bbox,this.modelObject=e.object,this.rootObject=new d.Group,this.rootObject.name="rootObject-"+this.modelId,this.rootObject.userData.modelId=this.modelId,this.highlighUsage=new d.Group,this.highlighUsage.name="highlighUsage-"+this.modelId,this.highlighUsage.layers.disable(ft),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(ft),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&$.revertDoubleSidedMaterialToObject(e)})}getModelObject(){return this.rootObject}getBBox(){return!this.bbox&&(this.bbox=new d.Box3,this.bbox.setFromObject(this.getModelObject())),this.bbox}async enableOutline(e,i){e&&!this.edges&&(this.edges=await $.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,r){if(this.hasObject(e)){if(e instanceof d.InstancedMesh&&r){const n=this.createInstanceMeshById(e,r,{opacity:i});n.material.opacity*=i,e.userData.instanceId=r,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else if(oe.isMergedMesh(e)&&s){const n=this.createBatchMeshById(e,s,{opacity:i});n.material.opacity*=i,e.userData.batchId=s,e.userData.transparentedMesh=n,this.transparentUsage.add(n)}else{const n=new d.MeshBasicMaterial({color:0,transparent:!0,opacity:.05});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isTransparent=!0}}clearObjectOpacity(e,i,s){if(!this.isObjectTransparent(e))return;const{transparentedMesh:r,originalMaterial:n}=e.userData;r&&(this.transparentUsage.remove(r),delete e.userData.batchId,delete e.userData.instanceId,delete e.userData.transparentedMesh),n&&(e.material=n),delete e.userData.isTransparent}isObjectTransparent(e){const{isTransparent:i}=e.userData;return!!i}setOpacity(e=.5){this.getModelObject().traverse(i=>{i instanceof d.Mesh&&this.setObjectOpacity(i,e)})}clearOpacity(){this.getModelObject().traverse(e=>{e instanceof d.Mesh&&this.clearObjectOpacity(e)})}highlightObjectById(e,i,s){if(!this.hasObjectWithId(e))return;const r=this.getModelObject().getObjectById(e);r&&this.highlightObject(r,i,s)}highlightObject(e,i,s){if(!this.hasObject(e))return;const r=new d.Color(Bs);if(e instanceof d.InstancedMesh&&s){const n=this.createInstanceMeshById(e,s,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.instanceId=s,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else if(oe.isMergedMesh(e)&&i){const n=this.createBatchMeshById(e,i,{depthTest:!1});n.material.opacity=.7,de.setMaterialColor(n.material,r),e.userData.batchId=i,e.userData.clonedMesh=n,this.highlighUsage.add(n)}else{const n=de.clonedHighlightMaterials(e,{depthTest:!1});n&&(e.userData.originalMaterial=e.material,e.material=n)}e.userData.isHighlight=!0,this.highlighedObject=e}clearHighlight(){if(this.highlighedObject&&this.highlighedObject.userData){const e=this.highlighedObject.userData,{clonedMesh:i,originalMaterial:s,instanceId:r,originalMatrix:n}=e;i&&(i.removeFromParent(),i.geometry.dispose(),delete e.clonedMesh),r&&n&&(this.highlighedObject.setMatrixAt(r,n),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 d.Mesh&&(i.visible=e)})}hasVisibleObject(){let e=0;return this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e++}),e>0}hasInvisibleObject(){let e=0;return this.modelObject.traverse(i=>{i instanceof d.Mesh&&e++}),this.modelObject.traverseVisible(i=>{i instanceof d.Mesh&&e--}),e>0}createBatchMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=oe.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+n?.name,n?.userData&&(a+=`
797
- userData: `+JSON.stringify(n.userData)),n?.parentUserData&&(a+=`
798
- parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!r&&(o.depthTest=r,o.depthWrite=r,o.side=d.DoubleSide);const l=oe.cloneGeometryForBatch(e,n),c=new d.Mesh(l,o);return c.applyMatrix4(e.matrixWorld),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll(),c}createInstanceMeshById(e,i,{opacity:s=1,depthTest:r=!0}){const n=e,a=new d.Matrix4,o=new d.Matrix4;o.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),n.getMatrixAt(i,a);const l=de.cloneMaterial(n.material);l.opacity=s,l.transparent=s<1,!r&&(l.depthTest=r,l.depthWrite=r,l.side=d.DoubleSide);const c=new d.Mesh(n.geometry.clone(),l);c.applyMatrix4(e.matrixWorld.multiply(a)),c.matrixWorldNeedsUpdate=!0,c.name="Cloned mesh for highlighting",c.layers.enableAll();const u=a.clone();return u.multiplyMatrices(a,o),n.setMatrixAt(i,u),n.instanceMatrix.needsUpdate=!0,n.updateMatrix(),e.userData.originalMatrix=a,c}setClipPlanes(e){this.getModelObject().traverse(i=>{const s=i.material;s&&(Array.isArray(s)?s.forEach(r=>{r.clippingPlanes=e,r.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 Dr extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesMaterial");p(this,"type");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");p(this,"defaultOutlineColor");p(this,"useBCOutline");p(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new d.Color(Vi[0],Vi[1],Vi[2]),this.useBCOutline=!1,this.outlineVisible=!0;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height},outlineColor:{value:this.defaultOutlineColor}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
791
+ `;return new p.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:a,clipping:!0})}var We=(c=>(c.Unitless="Unitless",c.Inches="Inches",c.Feet="Feet",c.Millimeters="Millimeters",c.Centimeters="Centimeters",c.Meters="Meters",c))(We||{});const fr=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),ud=(c,t)=>fr(c)/fr(t);class ko{constructor(){g(this,"pointer");g(this,"eof");g(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class fs{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=ps.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,ps.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=ps.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,ps.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 ga=1e3;class fd extends ko{constructor(e){super();g(this,"reader");g(this,"decoder");g(this,"int8Array");g(this,"caches");this.int8Array=new Int8Array(ga),this.caches=new Map,this.reader=new fs(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 ya(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 ya(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>ga)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 ya(c){return Array.prototype.map.call(c,t=>("00"+t.toString(16)).slice(-2)).join("")}class xa extends ko{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=pd(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 pd(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?md(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 md(c){if(c==="0")return!1;if(c==="1")return!0;throw TypeError("String '"+c+"' cannot be cast to Boolean type")}function gd(c){if(c==null)return!0;for(const t in c)if(Object.prototype.hasOwnProperty.call(c,t))return!1;return!0}function yd(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()}gd(a)||e.push(a),i=!1,s=!1}return e}class xd{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=yd(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 bd{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=wd(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 wd(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 vd{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=ba(t),e=t.lastReadGroup;break;case 11:i.endPoint=ba(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 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 Md{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=wa(t),e=t.lastReadGroup;break;case 11:i.endPoint=wa(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 wa(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 Td{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=Cd(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 Cd(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","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=qt(t),e=t.lastReadGroup;break;case 11:i.middleOfText=qt(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=qt(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=qt(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=qt(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=qt(t),e=t.lastReadGroup;break;case 16:i.arcPoint=qt(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 qt(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","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(je(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=je(t),e=t.lastReadGroup;break;case 11:o.doglegVector=je(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=je(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=je(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=je(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=je(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=je(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=je(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=Od(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=je(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=je(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=je(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=je(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 je(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 Od(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 _d{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=Rn(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=Rn(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=Rn(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 Rn(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 Do=(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))(Do||{}),xi=(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))(xi||{});function bi(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 Pd(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=bi(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 Ad(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:bi(t),endPoint:bi(t)};i=t.lastReadGroup,e.push(r);break}case 2:{i=t.next();const r={type:2,center:bi(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:bi(t),majorAxisEndPoint:bi(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 Id(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=Pd(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=Ad(r,t),n.pathTypeFlag=i,e.push(n),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function Bd(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 kd(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 Dd{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=Bd(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=Id(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=kd(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 tn=(c=>(c[c.ShowImage=1]="ShowImage",c[c.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",c[c.UseClippingBoundary=4]="UseClippingBoundary",c[c.TransparencyIsOn=8]="TransparencyIsOn",c))(tn||{});let Ld=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=Ui(t),e=t.lastReadGroup;break;case 11:i.uPixel=Ui(t),e=t.lastReadGroup;break;case 12:i.vPixel=Ui(t),e=t.lastReadGroup;break;case 13:i.imageSize=Ui(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(Ui(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 Ui(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 Rd{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=va(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=va(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 va(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 Fd(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 zd{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(Vd(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=Fd(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=Oi(Math.abs(e.value)))))}e=t.next();break;default:ee(i,e),e=t.next();break}return i}}function Vd(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 jd{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(Fn(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(Fn(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=Fn(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 Fn(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 Ud(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 Nd{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(...Ud(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 Hd{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=Ma(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=Ma(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 Ma(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 Gd{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 qd{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=Ta(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=Ta(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 Ta(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 Wd{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 Yd(c,t){const e=new Wd,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"){Xd(c,t);break}}return i}function Xd(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 Zd{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=Kd(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=Yd(t,e),i}}function Kd(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","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 Jd{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(Ca(t)),e=t.lastReadGroup;break;case 11:i.directionVector=Ca(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 Ca(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 Qd{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 e1{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]=Ni(t),e=t.lastReadGroup;break;case 11:i.points[1]=Ni(t),e=t.lastReadGroup;break;case 12:i.points[2]=Ni(t),e=t.lastReadGroup;break;case 13:i.points[3]=Ni(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=Ni(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 Ni(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 t1{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(Hi(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(Hi(t)),e=t.lastReadGroup;break;case 12:i.startTangent=Hi(t),e=t.lastReadGroup;break;case 13:i.endTangent=Hi(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=Hi(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 Hi(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 i1(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 Sa(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){i1(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 s1{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=Ea(t),e=t.lastReadGroup;break;case 11:i.directionVector=Ea(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(Sa(e,t)):i.cells=[Sa(e,t)],e=t.lastReadGroup;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 n1{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=Oa(t),e=t.lastReadGroup;break;case 11:i.endPoint=Oa(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 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 r1{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=ct(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=ct(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=ct(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=ct(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=ct(t),e=t.lastReadGroup;break;case 16:i.viewDirection=ct(t),e=t.lastReadGroup;break;case 17:i.viewTarget=ct(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=ct(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=ct(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=ct(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 ct(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 a1{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(_a(t)),e=t.lastReadGroup;break;case 11:i.directionVector=_a(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 _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 o1{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:Bi(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 l1{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=Pa(t),e=t.next();break;case 11:s.pixelSize=Pa(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:Bi(s,e),e=t.next();break}return s}}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 c1{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=_t(t),e=t.lastReadGroup;break;case 11:s.maxLimit=_t(t),e=t.lastReadGroup;break;case 12:s.basePoint=_t(t),e=t.lastReadGroup;break;case 13:s.origin=_t(t),e=t.lastReadGroup;break;case 14:s.minExtent=_t(t),e=t.lastReadGroup;break;case 15:s.maxExtent=_t(t),e=t.lastReadGroup;break;case 16:s.XAxis=_t(t),e=t.lastReadGroup;break;case 17:s.YAxis=_t(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:Bi(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function _t(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","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:Bi(s,e),e=t.next();break}return s}}class d1{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=sn(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),n=sn(t),e=t.lastReadGroup,r=sn(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=u1(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=Aa(t,40),s.matrix=Aa(t,40),e=t.lastReadGroup;break;default:Bi(s,e),e=t.next();break}return s}}function u1(c,t){t.next();const e=[];for(;e.length<c;)e.push(sn(t));return e}function Aa(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 sn(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","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:Bi(s,e),e=t.next();break}return s}}function p1(c){c.registerEntityHandler(xd),c.registerEntityHandler(bd),c.registerEntityHandler(vd),c.registerEntityHandler(Md),c.registerEntityHandler(Td),c.registerEntityHandler(Sd),c.registerEntityHandler(Ed),c.registerEntityHandler(_d),c.registerEntityHandler(Dd),c.registerEntityHandler(Ld),c.registerEntityHandler(Rd),c.registerEntityHandler(zd),c.registerEntityHandler(jd),c.registerEntityHandler(Nd),c.registerEntityHandler(Hd),c.registerEntityHandler(Gd),c.registerEntityHandler(qd),c.registerEntityHandler(Zd),c.registerEntityHandler($d),c.registerEntityHandler(Jd),c.registerEntityHandler(Qd),c.registerEntityHandler(e1),c.registerEntityHandler(t1),c.registerEntityHandler(s1),c.registerEntityHandler(n1),c.registerEntityHandler(r1),c.registerEntityHandler(a1)}function m1(c){c.registerObjectHandler(o1),c.registerObjectHandler(l1),c.registerObjectHandler(c1),c.registerObjectHandler(h1),c.registerObjectHandler(d1),c.registerObjectHandler(f1)}function g1(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 Lo{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,p1(this),m1(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new xa(e);return this._parse(i)}else{let e;if(g1(t))e=new fd(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 xa(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",Ro(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=S(!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 E=n.value;s.unhandledSections[E]?s.unhandledSections[E]++:s.unhandledSections[E]=1}}else n=t.next();s.unhandledSections={},s.unhandledEntities={},s.unhandledObjects={},s.unsupportedLineTypes={}}function a(){let E=null,v=null;const T={};for(n=t.next();;){if(Ue(n,0,"ENDSEC")){E&&(T[E]=v);break}else n.code===9?(E&&(T[E]=v),E=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 E={};for(n=t.next();n.value!=="EOF"&&!Ue(n,0,"ENDSEC");)if(Ue(n,0,"BLOCK")){P.trace("block {");const v=l();P.trace("}"),O(v),v.name?E[v.name]=v:console.error("[DxfParser] Block with handle '"+v.handle+"' is missing a name, ignored!")}else yt(n),n=t.next();return E}function l(){const E={};for(n=t.next();n.value!=="EOF";){switch(n.code){case 1:E.xrefPath=n.value,n=t.next();break;case 2:E.name=n.value,n=t.next();break;case 3:E.name2=n.value,n=t.next();break;case 4:E.description=n.value,n=t.next();break;case 5:E.handle=n.value,n=t.next();break;case 8:E.layer=n.value,n=t.next();break;case 10:E.position=Ge(t),n=t.lastReadGroup;break;case 67:E.paperSpace=!!(n.value&&n.value===1),n=t.next();break;case 70:E.blockType=n.value,n=t.next();break;case 100:n=t.next();break;case 330:E.ownerHandle=n.value,n=t.next();break;case 0:if(n.value==="ENDBLK")break;E.entities=S(!0);break;default:yt(n),n=t.next();break}if(Ue(n,0,"ENDBLK")){n=t.next();break}}return E}function h(){const E={};for(n=t.next();n.value!=="EOF"&&!Ue(n,0,"ENDSEC");)Ue(n,0,"TABLE")?(n=t.next(),x[n.value]?(P.trace(n.value+" Table {"),E[x[n.value].tableName]=u(n),P.trace("}")):P.trace("Unhandled Table "+n.value)):n=t.next();return n=t.next(),E}const d="ENDTAB";function u(E){const v=x[E.value],T={};let _=0;for(n=t.next();!Ue(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"||yt(n),n=t.next();break;case 70:_=n.value,n=t.next();break;case 0:n.value===v.dxfSymbolName?T[v.tableRecordsProperty]=v.parseTableRecords():(yt(n),n=t.next());break;default:yt(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 E=[];let v={};for(P.trace("Viewport {"),n=t.next();!Ue(n,0,d);)switch(n.code){case 2:v.name=n.value,n=t.next();break;case 10:v.lowerLeftCorner=Ge(t),n=t.lastReadGroup;break;case 11:v.upperRightCorner=Ge(t),n=t.lastReadGroup;break;case 12:v.center=Ge(t),n=t.lastReadGroup;break;case 13:v.snapBasePoint=Ge(t),n=t.lastReadGroup;break;case 14:v.snapSpacing=Ge(t),n=t.lastReadGroup;break;case 15:v.gridSpacing=Ge(t),n=t.lastReadGroup;break;case 16:v.viewDirectionFromTarget=Ge(t),n=t.lastReadGroup;break;case 17:v.viewTarget=Ge(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=Ge(t),n=t.lastReadGroup;break;case 111:v.ucsXAxis=Ge(t),n=t.lastReadGroup;break;case 112:v.ucsYAxis=Ge(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("}"),E.push(v),P.trace("Viewport {"),v={},n=t.next());break;default:yt(n),n=t.next();break}return P.trace("}"),E.push(v),E}function m(){const E={};let v={},T=0,_="",A=!1;for(P.trace("LType {"),n=t.next();!Ue(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"),E[_]=v,v={},P.trace("LType {"),n=t.next();break;default:n=t.next();break}return P.trace("}"),E[_]=v,E}function b(){const E={};let v={},T;for(P.trace("Layer {"),n=t.next();!Ue(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=Oi(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&&(E[T]=v),P.trace("Layer {"),v={},T=void 0,n=t.next());break;default:yt(n),n=t.next();break}return P.trace("}"),T&&(E[T]=v),E}function y(){const E={};let v={},T;for(P.trace("Style {"),n=t.next();!Ue(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&&(E[T]=v),P.trace("Style {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(E[T]=v),E}function C(){const E={};let v={},T;for(P.trace("DimStyle {"),n=t.next();!Ue(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&&(E[T]=v),P.trace("DimStyle {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return P.trace("}"),T&&(E[T]=v),E}function w(){const E={};let v={},T;for(P.trace("BlockRecord {"),n=t.next();!Ue(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&&(E[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 yt(n),n=t.next();break;default:yt(n),n=t.next();break}P.trace("}"),T&&(E[T]=v);const _=v.layoutHandle;return T&&_&&_.length>0&&_!=="0"&&(s._layoutBlocks[_]=v),E}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 S(E){const v=[],T=E?"ENDBLK":"ENDSEC";for(E||(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 E={},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(_),E[A]||(E[A]=[]),E[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(),E.LAYOUT&&(Object.keys(s._layoutBlocks).length!==E.LAYOUT.length&&console.warn("[DxfParser] The number of layout and block associations does not match!"),E.LAYOUT.forEach(T=>{s._layoutBlocks[T.handle]&&(T.associatedBlockName=s._layoutBlocks[T.handle].blockName)}),E.LAYOUT.sort((T,_)=>T.tabOrder-_.tabOrder)),E}function O(E){if(!E)throw new TypeError("entity cannot be undefined or null");E.handle||(E.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
+ `){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=od(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 Ue(c,t,e){return c.code===t&&c.value===e}function yt(c){P.trace("unhandled group "+Ro(c))}function Ro(c){return c.code+":"+c.value}const Fo="0.4.0",zo="VERSION",y1=()=>window.localStorage.getItem(zo),x1=()=>{window.localStorage.setItem(zo,Fo)},b1=()=>y1()!==Fo?(x1(),!0):!1,Kt=class Kt{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!Kt._instance&&(Kt._instance=new Kt),Kt._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(),b1()&&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(Kt,"_instance");let ue=Kt;class Vo{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 $t=class $t extends Vo{tableName(){return"dxf_data"}static instance(){return!$t._instance&&($t._instance=new $t),$t._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($t,"_instance");let an=$t;const Ne=new p.Vector3(1,0,0),zn=new p.Vector3(0,1,0),ci=new p.Vector3(0,0,1),Ia=new p.Vector3(0,0,0),Bt=16777215,w1="CONTINUOUS",Rs=new p.PointsMaterial({color:Bt}),me=new p.LineBasicMaterial({color:Bt}),hi=new p.MeshBasicMaterial({color:Bt}),Ba=new p.BufferGeometry().setFromPoints([new p.Vector3]),ka=new p.Matrix4,Qe=new p.Matrix4,de=new p.Matrix4,U=new p.Vector3,K=new p.Vector3,et=new p.Vector3,Gi=new p.Vector2,ge=new p.Quaternion,Fs=new p.Object3D,ht=new p.Box3,Da=new p.PointsMaterial({color:65280,size:5,depthTest:!1}),La=new p.PointsMaterial({color:65280,depthTest:!1}),Ra=new p.PointsMaterial({color:65280,depthTest:!1}),v1=c=>c.viewDirectionFromTarget!==void 0,M1=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 cc.decode(s)}}}return null},Fa=(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)},za=(c,t,e)=>({x:c.x+t*Math.cos(e),y:c.y+t*Math.sin(e)}),T1=(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=za(c,a,Fa(s,n)+(Math.PI/2-r/2));i=i||Math.max(Math.abs(Math.ceil(r/(Math.PI/18))),6);const l=Fa(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=za(o,Math.abs(a),l+h*u);d.push(new p.Vector3(f.x,f.y,0))}return d},Va=(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=Oo(a,t,r,e,s);n.push(new p.Vector3(o[0],o[1],0))}}catch{if(n.length===0)return n}return n},Vn=(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=T1(n,a,r);e.push(...o)}else e.push(new p.Vector3(n.x,n.y,0))}return e},C1=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},S1=c=>{const t=[],e=[];c.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new p.Vector3(s.x,s.y,s.z)):e.push(C1(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},N=class N 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=N.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.overrideColor!=null&&(this.overrideColor=Pi.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[Bt]=Rs,this.lineBasicMaterials[Bt]=me,this.meshBasicMaterials[Bt]=hi}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=M1(e);if(!s){const n=Date.now(),r=new p.FileLoader(this.manager),a=N.REQUWSTHEADER;a&&r.setRequestHeader(a),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(Ie.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 Lo(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&&Ie.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:N.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 S=x.userData.layerName;let M=o[S];!M&&(M=[],o[S]=M),M.push(x)},h={},d={},u=new V;for(let x=0;x<r&&!this.aborted;x++){const S=e.entities[x];this.addViewport(S,h);const M=this.loadEntity(S,e);if(!M&&await a(x),!M)continue;const O=this.getLayout(e,S),E=O.layoutName;let v=u.children.find(T=>T.name===E);if(!v&&(v=new V,v.name=E,v.userData.isLayoutLevelObject=!0,u.add(v)),M.traverse(T=>{T.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[E]&&(this.layoutsSnapObjectsMap[E]=[]),this.layoutsSnapObjectsMap[E].push(T))}),this.enableMerge){bt.merge(M,!1),!d[E]&&(d[E]={object:v,layerObjects:{}});const _=d[E];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 S=x,M=S.layoutName;if(this.ignorePaperSpace&&M!==N.MODEL_LAYOUT_NAME)return;const O=S.associatedBlockName,E=e.blocks[O];E&&this.loadLayout(E,e,S,u,o,h)}),P.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const x in this.layoutsSnapObjectsMap){const S=u.children.find(E=>E.name===x),M=new V;M.name=N.SNAP_GROUP_NAME,M.userData.isSnapGroup=!0,S.add(M);const O=this.layoutsSnapObjectsMap[x];for(let E=0;E<O.length;E++){const v=O[E],T=v.userData.layerName;this.getLayerVisible(e,T)===!1&&v.layers.disable(Fe),N.SHOW_SNAP_OBJECT&&(v.layers.enableAll(),v.material instanceof p.PointsMaterial?v.material=Da:v.material instanceof p.LineBasicMaterial?v.material=La:v.material instanceof p.MeshBasicMaterial&&(v.material=Ra));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 S=d[x],M=S.object;for(const O in S.layerObjects){const E=S.layerObjects[O],v=bt.deepMerge(E,void 0,!1,!1,!0),T=v.added,_=v.removed;if(_.length!==E.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=E.length;B<k;B++){const R=E[B];!I(R)&&(M.add(R),l(R))}}for(let A=0;A<T.length;A++){const I=T[A];M.add(I),l(I)}S.layerObjects[O]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&N.mergeDxfObjects({root:u,layersAndObjects:o});const m=u.convertToThreejsObject();u.clear(),o={};const b={};e.objects.LAYOUT.forEach(x=>{const S=x;b[S.layoutName]=S});const y={},C=x=>{const S=x.userData.layerName;let M=y[S];!M&&(M=[],y[S]=M),M.push(x)};m.children.forEach(x=>{if(J.setSharedVariablesOfObject(x),!x.userData.isLayoutLevelObject)return;const S=x.name;let M;if(S!==N.MODEL_LAYOUT_NAME){const O=b[S];!O.directAssociatedLeafObjectSet&&(O.directAssociatedLeafObjectSet=new Set),M=O.directAssociatedLeafObjectSet}x.traverse(O=>{if(J.setSharedVariablesOfObject(O),O.userData.isSnapGroup&&(O.visible=N.SHOW_SNAP_OBJECT),O.geometry){const E=O.userData.layerName;this.getLayerVisible(e,E)===!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(N.LOADLLDATA){const x=m.children[0].children,S=[];for(let M=0;M<x.length;M++){const O=x[M];if(O?.userData?.llbData){const E=new p.Box3().setFromObject(O);E.getSize(new p.Vector3);const v=E.getCenter(new p.Vector3);S.push({...O,boundingBox:{max:E.max,min:E.min,center:v}})}else if(O.children&&O.children.some(E=>E.userData?.llbData))for(let E=0;E<O.children.length;E++){const v=O.children[E];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);S.push({...v,boundingBox:{max:T.max,min:T.min,center:_}})}}}w.llbMesh=S}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!==N.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===N.MODEL_LAYOUT_NAME);!I&&(I=new V,I.name=N.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,m.add(I)),I.add(A),A.traverse(B=>{if(B.geometry){const k=B.userData.layerName,R=this.getLayerVisible(f,k);B.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[_.layoutName]&&(this.layoutsSnapObjectsMap[_.layoutName]=[]),this.layoutsSnapObjectsMap[_.layoutName].push(B),R===!1&&A.layers.disable(Fe));let z=x[k];!z&&(z=[],x[k]=z),z.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===Re.Added||T.type===Re.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:Re.NoChange});continue}_=this.setObjectColorByChange(_,T)}if(T.type!==Re.NoChange&&_){let A=_.parent;const I=de.identity();for(;A&&A.userData.isLayoutLevelObject!==!0;)I.premultiply(A.matrix),A=A.parent;ht.makeEmpty();const B=V.getBox(_,ht);B.applyMatrix4(I),T.type===Re.Added?!u&&(T.box=new p.Box3().copy(B)):T.type===Re.Removed?u&&(T.box=new p.Box3().copy(B)):T.type===Re.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=N.SNAP_GROUP_NAME,T.add(_);const A=this.layoutsSnapObjectsMap[v];for(let I=0;I<A.length;I++){const B=A[I];N.SHOW_SNAP_OBJECT&&(B.layers.enableAll(),B.material instanceof p.PointsMaterial?B.material=Da:B.material instanceof p.LineBasicMaterial?B.material=La:B.material instanceof p.MeshBasicMaterial&&(B.material=Ra));let k=B;const R=de.identity();for(;k&&k.userData.isLayoutLevelObject!==!0;)R.premultiply(k.matrix),k=k.parent;B.matrix.copy(R),_.add(B)}}this.enableMerge&&N.mergeDxfObjects({root:m,layersAndObjects:x});const S=m.convertToThreejsObject();m.clear(),x={};const M={},O=v=>{const T=v.userData.layerName;let _=M[T];!_&&(_=[],M[T]=_),_.push(v)};S.children.forEach(v=>{J.setSharedVariablesOfObject(v),v.userData.isLayoutLevelObject&&v.traverse(T=>{if(J.setSharedVariablesOfObject(T),T.userData.isSnapGroup&&(T.visible=N.SHOW_SNAP_OBJECT),T.geometry){const _=T.userData.layerName;this.getLayerVisible(f,_)===!1&&(T.visible=!1,T.userData.layerVisible=!1),O(T)}})});const E=f;E.threejsObject=S,E.layersAndThreejsObjects=M,E.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=nt.ENTITY_COLOR_NO_CHANGE;return a.type===Re.Added?o=nt.ENTITY_COLOR_ADDED:a.type===Re.Removed?o=nt.ENTITY_COLOR_REMOVED:a.type===Re.Modified&&(o=this.compareContext?.isTheFirstFile?nt.ENTITY_COLOR_REMOVED:nt.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();N.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)&&Qi.includes(e.type)&&(n=!0),!n&&this.compareContext&&this.compareContext.preservedHandles&&!Qi.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(Fe)}),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=Qi.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),F.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=F.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 E=0;E<C-1;E++)F.areVector2sEqual(b[E],b[E+1],1e-9)||y.push(b[E]);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=H.checkAndRebasePositionsOnRTC(y,w));const S=new p.BufferGeometry().setFromPoints(y),M=new V(G.Line);M.geometry=S,M.material=me;const O=new V(G.Point);return O.geometry=Ba,O.material=Rs,O.matrix.setPosition(e.center.x,e.center.y,e.center.z),O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(Fe),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=es(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,et),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,et)),ht.makeEmpty();const l=V.getBox(o,ht),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=e.lineSpaceFactor||1.657,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+=u/2;break;case 5:b-=d/2,y+=u/2;break;case 6:b-=d,y+=u/2;break;case 7:b=0;const B=m.split("\\P").length-1;B>0?y+=u*(B+1)+u*f*.8*B:y+=u;break;case 8:b-=d/2,y+=u;break;case 9:b-=d,y+=u;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(Ne),R=Ne.angleTo(B);w=k.z>0?-R:R}H.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,et);const x=e.position?K.clone().sub(e.position):K;Qe.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),o.matrix.multiply(Qe),o.matrix.multiply(de),o.matrix.multiply(Qe.invert()),o.userData||(o.userData={});const S=o.matrix.elements,M=S&&S[12]||0,O=S&&S[13]||0,E=S&&S[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:E},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=es(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,et),e.position&&(K.x+=e.position.x,K.y+=e.position.y,o.matrix.compose(K,ge,et)),ht.makeEmpty();const l=V.getBox(o,ht),h=l.getSize(U),d=e.width||h.x,u=e.height||h.y,f=e.lineSpaceFactor||1.657,m=e.text;let b=0,y=0;switch(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+=u/2;break;case 5:b-=d/2,y+=u/2;break;case 6:b-=d,y+=u/2;break;case 7:b=0;const S=m.split("\\P").length-1;S>0?y+=u*(S+1)+u*f*.8*S:y+=u;break;case 8:b-=d/2,y+=u;break;case 9:b-=d,y+=u;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=u;break;case 4:break;case 5:break;default:return}o.traverse(x=>{x.geometry&&x.geometry.translate(b,y,0),x.layers.enableAll()});let C=0;if(e.rotation&&(C=e.rotation*Math.PI/180),e.directionVector){const x=e.directionVector,S=new p.Vector3(x.x,x.y,x.z),M=S.clone().cross(Ne),O=Ne.angleTo(S);C=M.z>0?-O:O}H.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(o),o.matrix.compose(K,ge,et);const w=e.position?K.clone().sub(e.position):K;return Qe.makeTranslation(-w.x,-w.y,0),de.makeRotationZ(C),o.matrix.multiply(Qe),o.matrix.multiply(de),o.matrix.multiply(Qe.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,S=x+h;for(let M=0;M<e.length;M++){const O=e[M];if(typeof O=="string"){const E=[],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}}E.push(...A)};let T;for(let A=0;A<O.length;A++){const I=O[A];if(I===`
794
+ `){a=0,o-=S,l.length>0&&v(l),l=[];continue}if(x=h*.8,S=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-=S,l=[]),T.translate(a,o,0),T.scale(y,1,1),T.boundingBox||T.computeBoundingBox(),O.T&&(C=O.T);const B=ad(I,T,h,C,b);a+=B,l.push(T)}l.length>0&&(v(l),l=[]);const _=new V;if(E.length>0){!m&&(m=i.colorIndex),w!==void 0&&w!==256?(i.color=Oi(w),i.colorIndex=w):i.colorIndex=m;const A=this.getColor(i,n,r),I=E.filter(k=>k instanceof p.ExtrudeGeometry),B=E.filter(k=>!(k instanceof p.ExtrudeGeometry));if(I.length>0){const k=new V(G.Mesh);k.geometry=_e.mergeGeometries(I),k.material=this.getMeshBasicMaterial(A),_.add(k)}if(B.length>0){const k=new V(G.LineSegment);k.geometry=_e.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 E=this.getMTextGroup(O,i,s,n,r,a,o,l);E&&(f.add(E.object),a=E.hOffset,o=E.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 bt.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;!F.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new p.Vector3;let n=!1;this.enableRTC&&(n=H.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=Va(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,d),f=new p.Vector3;let m=!1;this.enableRTC&&(m=H.checkAndRebasePositionsOnRTC(u,f));const b=H.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=H.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=H.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=S1(e.vertices);else{const h=Vn(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];F.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&&H.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 E=O.attributes.position,v=E.count,T=new Float32Array(v);for(let _=0;_<v;_+=2){const A=_*3,I=(_+1)*3,B=E.array[I]-E.array[A],k=E.array[I+1]-E.array[A+1],R=E.array[I+2]-E.array[A+2],z=Math.sqrt(B*B+k*k+R*R);T[_]=_===0?0:T[_-1],T[_+1]=T[_]+z}O.setAttribute("lineDistance",new p.Float32BufferAttribute(T,1))};const x=b.pattern?.[0]||.5,S=b.pattern?.[1]||.5,M=.1;C=new p.LineDashedMaterial({color:me.color,linewidth:me.linewidth||1,dashSize:x*M,gapSize:S*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&&H.checkAndRebasePositionsOnRTC(n,r);const h=new p.BufferGeometry().setFromPoints(n),d=new V(G.Point);d.geometry=h,d.material=Rs,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 m=N.getOcsMatrix(U).invert(),b=e.elevation!==void 0?e.elevation:0;n.forEach(y=>{U.set(y.x,y.y,b).applyMatrix4(m),y.x=U.x,y.y=U.y})}let r=Vn(n,e.shape);if(e.shape&&r.length>0&&!F.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 m=o.outlines,b=[];m.forEach(w=>{const x=new p.Shape;w.forEach((S,M)=>{M===0?x.moveTo(S[0],S[1]):x.lineTo(S[0],S[1])}),x.closePath(),b.push(new p.ShapeGeometry(x))});const y=_e.mergeGeometries(b),C=new V(G.Mesh);C.geometry=y,C.material=hi,C.layers.enableAll(),C.layers.disable(Fe),a.add(C)}let l=!1;const h=new p.Vector3;this.enableRTC&&(l=H.checkAndRebasePositionsOnRTC(r,h));const d=H.getAdjacentNonRepeatPoints(r);if(d.length<2){P.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const u=e.constantWidth;if(this.enablePlineWidth){const m=n.some(b=>b.startWidth!==void 0||b.endWidth!==void 0);if(m||u!==void 0&&u>0){let b;const y=i.tables?.lineType?.lineTypes,C=this.getLineType(e,i,s),w=y?.[C];if(!w||!w.pattern||w.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,m?b=this.createTaperedPolylineGeometry(n):b=H.convertWidthLineToMeshGeometry(d,u),!b)P.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const x=new V(G.Mesh);x.geometry=b,x.material=hi,x.layers.enableAll(),x.layers.disable(Fe),a.add(x);const S=J.createOutline(b,me,x.matrix),M=new V(G.LineSegment);M.geometry=S.geometry,M.material=S.material,M.matrix=S.matrix,M.layers.enableAll(),M.layers.disable(Fe),a.add(M)}}}const f=new V(G.Line);return f.geometry=new p.BufferGeometry().setFromPoints(d),f.material=me,f.layers.enableAll(),a.children.length>0?a.add(f):a=f,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,S=w/2;h.x+b*x,h.y+y*x,h.x-b*x,h.y-y*x;const M={x:d.x+b*S,y:d.y+y*S},O={x:d.x-b*S,y:d.y-y*S};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=es(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,et),e.contextData?.textLocation&&(K.x+=e.contextData.textLocation.x,K.y+=e.contextData.textLocation.y,d.matrix.compose(K,ge,et)),ht.makeEmpty();const u=V.getBox(d,ht),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(S=>{S.geometry&&S.geometry.translate(y,C,0)});let w=0;if(e.contextData?.textRotation&&(w=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const S=e.contextData.textDirection,M=new p.Vector3(S.x,S.y,S.z),O=M.clone().cross(Ne),E=Ne.angleTo(M);w+=O.z>0?-E:E}H.shouldRebasePositionOnRTC(K)&&this.setRTCUserData(d),d.matrix.compose(K,ge,et),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);Qe.makeTranslation(-x.x,-x.y,0),de.makeRotationZ(w),d.matrix.multiply(Qe),d.matrix.multiply(de),d.matrix.multiply(Qe.invert()),d.renderOrder=Ee.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 S=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),E=O.multiplyScalar(M),v=S.clone().add(E);u.push(v,S)}const b=e.contextData?.leaders[0].leaderLines||[];for(let S=0;S<b.length;S++){const M=b[S].vertices[0],O=M.reverse().map(B=>new p.Vector3(B.x,B.y,B.z));let E=new p.Vector3(m.x,m.y,m.z);for(let B=0;B<O.length;B++)u.push(E,O[B]),E=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 R=this.loadEntity(B.entities[k],i,e);if(R){const z=new p.Vector3(u[u.length-1].x,u[u.length-1].y,u[u.length-1].z),oe=new p.Vector3(u[u.length-2].x,u[u.length-2].y,u[u.length-2].z),le=Math.atan2(z.y-oe.y,z.x-oe.x);U.copy(z),K.setScalar(A),ge.setFromAxisAngle(ci,le),R.matrix.compose(U,ge,K),a.add(R)}}}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=H.checkAndRebasePositionsOnRTC(u,y));const w=new p.BufferGeometry().setFromPoints(u),x=new V(G.LineSegment);x.geometry=w,x.material=me,x.renderOrder=Ee.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 bt.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=Oi(e.colorIndex));for(let x=0;x<w.entities.length;x++){const S=this.loadEntity(w.entities[x],i,e);if(S){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),E=Math.atan2(M.y-O.y,M.x-O.x);U.copy(M),K.setScalar(d),ge.setFromAxisAngle(ci,E),S.matrix.compose(U,ge,K),u.add(S)}}}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=H.checkAndRebasePositionsOnRTC(n,f));const b=new p.BufferGeometry().setFromPoints(n),y=new V(G.Line);return y.geometry=b,y.material=me,y.renderOrder=Ee.Line,m&&(this.setRTCUserData(y),y.matrix.setPosition(f.x,f.y,0)),u.children.length>0?(u.add(y),bt.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,S=1;for(;y+x<a&&d[y+x][C]&&d[y+x][C].mergedValue===1;)x++;for(;C+S<o&&d[y][C+S]&&d[y][C+S].mergedValue===1;)S++;w.rowSpan=x,w.colSpan=S}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 S=!0;if(y===0||y===a)S=!0;else{const M=this._getMergeOwner(d,y-1,x,a,o),O=this._getMergeOwner(d,y,x,a,o);S=M!==O}S?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 S=!0;if(y===0||y===o)S=!0;else{const M=this._getMergeOwner(d,x,y-1,a,o),O=this._getMergeOwner(d,x,y,a,o);S=M!==O}S?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],S=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 E=this.getTableTextOffset(w.attachmentPoint||1,M,O);U.set(x,S,0),U.add(E),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,et),U.x+=e.startPoint.x,U.y+=e.startPoint.y,n.matrix.compose(U,ge,et),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=N.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=N.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=F.getArcAngleSpanInRadian(i,s);const r=N.transformAngleByOcsMatrix(e,i),a=N.transformAngleByOcsMatrix(e,s);let o;if(F.areNumbersClose(n,Math.PI)){n=1;const l=N.transformAngleByOcsMatrix(e,i+n);o=F.getArcAngleSpanInRadian(r,l)}else{if(F.areNumbersClose(n,Math.PI*2))return[r,r+Math.PI*2];o=F.getArcAngleSpanInRadian(r,a)}return F.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=N.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,F.areNumbersEqual(a,o,1e-6)))return;if(!F.areNumbersClose(F.getArcAngleSpanInRadian(a,o),Math.PI*2)){const O=N.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=H.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 S=w,M=new V(G.Point);return M.geometry=Ba,M.material=Rs,M.userData.handle=e.handle,M.userData.isSnapObject=!0,M.userData.type="CircleCenter",M.layers.set(Fe),C.add(M),b?(this.setRTCUserData(C),S.x+=m.x,S.y+=m.y):H.shouldRebasePositionOnRTC(S)&&this.setRTCUserData(C),C.matrix.setPosition(S),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=N.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=H.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=hi,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
+ `&&w.push(M)}const x=w.length;let S=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 E=this.font?.getCharShape?.(O,i?.fontFile,s);if(!E&&i?.bigFontFile&&(E=this.font?.getCharShape?.(O,i.bigFontFile,s)),!E&&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",E=this.font?.getCharShape?.(O,i.fontFile,s),!E);T--);}if(E||(E=this.font?.getNotFoundTextShape?.(s)),!!E){if(E.translate(u,f,0),u>o)u=0,f-=m;else{!E.boundingBox&&E.computeBoundingBox();const v=E.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;S++,u+=A+(S===x?0:l)}d.push(E)}}if(d.length>0){const M=d.filter(E=>E instanceof p.ExtrudeGeometry),O=d.filter(E=>!(E instanceof p.ExtrudeGeometry));if(M.length>0){const E=new V(G.Mesh);E.geometry=_e.mergeGeometries(M),E.material=hi,h.add(E)}if(O.length>0){const E=new V(G.LineSegment);E.geometry=_e.mergeGeometries(O),E.material=me,h.add(E)}}return h}transformTextMesh(e,i){ht.makeEmpty();const s=V.getBox(i,ht),n=s.getSize(U),{halign:r,valign:a}=e;i.matrix.decompose(Fs.position,Fs.quaternion,Fs.scale);const o=Fs,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(Ne),C=f.angleTo(Ne);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 S=(m-l)/(C-1);o.userData.letterSpacing=S}else b<3&&o.scale.setX(b);const w=f.clone().cross(Ne),x=f.angleTo(Ne);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=en(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=H.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=H.caculateGeometryCenter(u);f&&H.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=en(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=H.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=H.caculateGeometryCenter(d);u&&H.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=en(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=H.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=H.caculateGeometryCenter(f);m&&H.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=H.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=Oi(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),H.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===tn.ShowImageWhenNotAlignedWithScreen||e.flags===tn.UseClippingBoundary||e.flags===tn.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 H.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&&N.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(ka.identity().makeScale(-1,1,1)),Qe.copy(a.matrix),a.matrix.premultiply(de),K.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),H.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(F.areVector3sEqual(b,C)&&m+1<y-1&&m+1<o-1&&F.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])}),!H.isConvex(u)){P.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const m=Rl(f,1/0);h=[],m.forEach(b=>{h.push(new p.Vector3(b[0],b[1],0))})}!F.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&&bt.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 xi.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 xi.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 xi.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 xi.Spline:{const n=e,r=Va(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 xi.Polyline:{const n=e,r=Vn(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:E,endPoint:v}=M,{startPoint:T,endPoint:_}=O,A=v.x-E.x,I=v.y-E.y,B=_.x-T.x,k=_.y-T.y,R=A*k-I*B;if(Math.abs(R)<1e-10)return null;const z=E.x-T.x,oe=E.y-T.y,le=(B*oe-k*z)/R,$e=(A*oe-I*z)/R;return le>=0&&le<=1&&$e>=0&&$e<=1?{x:E.x+le*A,y:E.y+le*I}:null}function o(M){const{edges:O}=M,E=[],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&&E.push({edgeIndex1:T,edgeIndex2:_,point:{x:A.x,y:A.y}})}if(E.length&&E.length===1){const T={pathTypeFlag:M.pathTypeFlag,edges:[O[E[0].edgeIndex1-1],{startPoint:{...O[E[0].edgeIndex1].startPoint},endPoint:{x:E[0].point.x,y:E[0].point.y},type:O[E[0].edgeIndex1].type},{startPoint:{x:E[0].point.x,y:E[0].point.y},endPoint:{x:O[E[0].edgeIndex2].startPoint.x,y:O[E[0].edgeIndex2].startPoint.y},type:O[E[0].edgeIndex2].type}]},_={pathTypeFlag:M.pathTypeFlag,edges:[{startPoint:{x:E[0].point.x-1e-5,y:E[0].point.y-1e-5},endPoint:{...O[E[0].edgeIndex1].endPoint},type:O[E[0].edgeIndex1].type},{...O[E[0].edgeIndex2-1]},{startPoint:O[E[0].edgeIndex2].startPoint,endPoint:{x:E[0].point.x-1e-5,y:E[0].point.y-1e-5},type:O[E[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],E=o(O);r=[...r,...E]}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 E=[];E.push(...this.convertEdgeToPoints(M[0]));for(let v=1;v<M.length;v++){const T=this.convertEdgeToPoints(M[v]);if(E.push(...T),E.length>2){const _=this.convertEdgeToPoints(M[v-1]);F.areVector2sEqual(_[_.length-1],T[0])?F.areVector2sEqual(E[0],T[T.length-1],1e-5)&&(O.push(E),E=[]):F.areVector2sEqual(_[0],T[T.length-1])?F.areVector2sEqual(E[1],T[0],1e-5)&&(O.push(E),E=[]):E=[]}}return O};if(n.boundaryPaths.forEach((M,O)=>{let E=[];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(E.push(T),M.pathTypeFlag>Do.MaxFlags&&(!(A=>{for(let I=1;I<A.length;++I){const B=A[I-1].endPoint,k=A[I].startPoint;if(!B||!k||!F.areVector2sEqual(B,k))return!1}return!0})(M.edges)||!n.associativity)&&(E=u(v),E.length<2)){P.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",O,n.handle);return}E.forEach(_=>{!F.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(Gi),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=_e.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=hi,this.setHatchMaterial(x,n,i,f,s);const S=x;return m&&(this.setRTCUserData(S),S.matrix.setPosition(f.x,f.y,0)),S.traverse(M=>{M.layers.enableAll(),M.layers.disable(Fe)}),S}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=H.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 S=x.binaryData,M=j.hexToBase64(S),O="data:image/jpg;base64,"+M,E=new p.TextureLoader(this.manager).load(O);E.colorSpace=p.SRGBColorSpace;const v=new p.MeshBasicMaterial({transparent:!0,map:E});this.meshTextureMaterials[b]=v,C=v;break}}if(C){const w=new p.Box2().setFromPoints(o),x=w.getSize(Gi),S=new p.PlaneGeometry(x.x,x.y),M=new V(G.Mesh);M.geometry=S,M.material=C;const O=w.getCenter(Gi);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=Ne,s=zn,n=ci;const r=new p.Vector3(0,1,0),a=new p.Vector3(0,0,1);return F.areVectorsClose(e,a)?de.identity():(n=e.clone().normalize(),!F.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;v1(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(F.roundNumber(s.x,7),F.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=ci.clone().cross(r),l.length()>0?(l.normalize(),h=d.clone().cross(l)):d.z<0?(l=Ne.clone().negate(),h=zn,d=ci.clone().negate()):(l=Ne,h=zn,d=ci);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=N.getDcs2WcsMatrix(e,this.angDir),d=new p.Matrix4;d.setPosition(Ia.clone().sub(r));const u=ka.identity();u.scale(U.set(l,l,l));const f=Qe.identity().setPosition(Ia.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=H.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=H.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 nt.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=Bt;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"),Bt}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Sr&&e.lineType!==ls)return e.lineType;if(e.lineType===ls)return s?this.getLineType(s,i):e.lineType;const n=i.tables?.layer?.layers,r=w1;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=Ee.Text;return}if(i.type==="HATCH"){Gi.set(0,0),this.setHatchMaterial(e,i,s,Gi,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=Ee.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=Ee.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=Ee.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=Ee.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=Ee.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(),N.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o))}else h=this.getHatchShaderMaterial(i,o,n);l=Ee.MeshWithPattern}!h&&(h=this.getMeshBasicMaterial(o),l=Ee.Mesh),a.material=h,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=Ee.Mesh:i.isLine?s=Ee.Line:i.isPoints&&(s=Ee.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]=Io.createLineShaderMaterial(e.pattern,i,a,N.ViewportScaleUniform,N.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,S=[],M=[];let O=0;M[0]=O;for(let v=0;v<y;++v)S[v]=f.dashPattern[v],S[v]===0&&(S[v]=x*w),O+=Math.abs(S[v]),M[v+1]=O;for(let v=y;v<o;++v)S[v]=0;for(let v=M.length;v<o+1;++v)M[v]=O;const E={origin:m,delta:b,angle:f.angle-e.patternAngle,pattern:S,patternSum:M,patternLength:O};if(l+=4,l+=o,l+=o+1,l>N.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(E)}const u=Bo(h,e.patternAngle,N.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)=>{an.instance().add(s,()=>{P.info("[Dxf] Saved '"+e+"' to indexedDb"),n()},a=>{r(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{an.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)&&H.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(Ut.epsilon(F.getVector2RelativeEps(e[y][0]),1e-6),C===0)b=Ut.segments({regions:[o(e[y])],inverted:!1});else{const w=Ut.segments({regions:[o(e[y])],inverted:!1}),x=Ut.combine(b,w);d=Ut.polygon(Ut.selectUnion(x)),d.regions.length>0?d.regions.forEach(S=>{if(S.length===0)return;const M=S.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 "+Ut.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]];H.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&&H.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===N.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();N.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else n&&(i.has(n.id)?r=i.get(n.id):(r=n.clone(),N.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 We.Unitless;case 1:return We.Inches;case 2:return We.Feet;case 4:return We.Millimeters;case 5:return We.Centimeters;case 6:return We.Meters;default:P.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return We.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=H.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&&N.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];N.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=bt.deepMerge(C.children,C.object,!1,!1,!0),x=w.added,S=w.removed;!s[y]&&(s[y]={object:C.object,children:[]}),!n[y]&&(n[y]={object:C.object,children:[]});const M=S.length>r;if(M){const O=Date.now();N.removeEmptyObjectsFromRemovingMarkedObjects2(S,C.object),o+=Date.now()-O}else a+=S.length;if(S.length===C.children.length)!M&&S.forEach(O=>{s[y].children.push(O)});else{let O=S;S.length>=100&&(O=new Set(S));const E=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];E(T)?!M&&s[y].children.push(T):b.push(T)}}for(let O=0;O<x.length;O++){const E=x[O];b.push(E),n[y].children.push(E)}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];N.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={},S=[];for(const E of C){if(E.userData.isSnapObject){S.push(E);continue}let v,T=E;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(E)}const M=Object.keys(x).length;let O=0;for(const E in x){let v;if(E!==N.MODEL_LAYOUT_NAME){const k=n[E];!k.directAssociatedLeafObjectSet&&(k.directAssociatedLeafObjectSet=new Set),v=k.directAssociatedLeafObjectSet}const T=x[E],_=fe.deepMerge(T.children,T.object,!1,!1,!0),A=_.added,I=_.removed;!a[E]&&(a[E]={object:T.object,children:[]}),!o[E]&&(o[E]={object:T.object,children:[]});const B=I.length>l;if(B){const k=Date.now();N.removeEmptyObjectsFromRemovingMarkedObjects(I,T.object),d+=Date.now()-k}else h+=I.length;if(I.length===T.children.length)!B&&I.forEach(k=>{a[E].children.push(k)});else{let k=I;I.length>=100&&(k=new Set(I));const R=z=>Array.isArray(k)?k.indexOf(z)>=0:k.has(z);for(let z=0;z<T.children.length;z++){const oe=T.children[z];R(oe)?!B&&a[E].children.push(oe):(S.push(oe),v&&v.add(oe))}}for(let k=0;k<A.length;k++){const R=A[k];J.setSharedVariablesOfObject(R),S.push(R),o[E].children.push(R),v&&v.add(R)}h>l&&u(),await s((m+ ++O/M)/f*100)}await s(++m/f*100),e.layersAndThreejsObjects[y]=S,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(S=>S.name===N.SNAP_GROUP_NAME);if(x&&y!==N.MODEL_LAYOUT_NAME){const S=n[y];!S.directAssociatedLeafObjectSet&&(S.directAssociatedLeafObjectSet=new Set),x.children.forEach(M=>S.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(N,"MODEL_LAYOUT_NAME","Model"),g(N,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),g(N,"SHOW_SNAP_OBJECT",!1),g(N,"REQUWSTHEADER"),g(N,"CameraZoomUniform",{value:1}),g(N,"ViewportScaleUniform",{value:1}),g(N,"TransformMatrixUniform",{value:new p.Matrix4}),g(N,"ResolutionUniform",{value:new p.Vector2}),g(N,"LOADLLDATA",!1),g(N,"MaxFragmentUniforms",1024);let X=N;class pr extends Vt{constructor(e){super();g(this,"viewer");g(this,"overlayRender");g(this,"drawableList");this.drawableList=new us("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===Re.Added?i.push(h):l.type===Re.Removed?s.push(h):n.push(h))}const r=H.mergeBBoxes(i),a=H.mergeBBoxes(s),o=H.mergeBBoxes(n);this.drawableList.addDrawable(new gt(j.guid(),r,[.1,.9,.2,1])),this.drawableList.addDrawable(new gt(j.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new gt(j.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class fn{}const di=new p.Matrix4,jn=new p.Box3;class Ai extends fn{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 We.Unitless;const e=this.dxfData.header;if(!e)return P.warn("DxfData or its header is undefined!"),We.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(Fe):X.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(Fe))}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(di.identity(),!i||!j.isMatrixValid(i)||i.equals(di))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=Dt.generateSectionPlanesByBox(d),f=[],m=T=>(!f[T.id]&&(f[T.id]=T.clone(),this.setMaterialUniforms(f[T.id],s.dxfData),Dt.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 S=s.getModelObject();let M=s.getLayoutLevelObject(e);!M&&(M=new p.Group,J.setSharedVariablesOfObject(M),M.name=e,S?.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 E=s.getLayoutLevelObject(X.MODEL_LAYOUT_NAME),v=E?.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)||(jn.makeEmpty(),jn.expandByObject(T),!a.intersectsBox(jn)))return;const A=T.clone();J.setSharedVariablesOfObject(A);let I=A.parent;const B=di.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=Ct.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)&&Dt.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}di.copy(i),e.localMatrix&&di.multiply(e.localMatrix);const n=s.polyline,r=[];n.forEach(l=>{const h=l.clone().applyMatrix4(di);r.push(new p.Vector2(h.x,h.y))});const a=p.ShapeUtils.isClockWise(r),o=!a&&!s.bReversed||a&&s.bReversed;return Dt.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 Er extends fn{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(Ft),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(Ft),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(Mr);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
+ 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 ja 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($s[0],$s[1],$s[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>",`
802
802
  #include <color_vertex>
803
803
  #include <id_vertex>
804
- #include <outline_bc_vertex>`),this.fragmentShader=r.replace("#include <common>",`
804
+ #include <outline_bc_vertex>`),this.fragmentShader=n.replace("#include <common>",`
805
805
  #include <common>
806
806
  #include <common_ex>
807
807
  #include <state_pars_fragment>
@@ -809,7 +809,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
809
809
  #include <state_fragment>
810
810
  #include <logdepthbuf_fragment>`).replace("#include <dithering_fragment>",`
811
811
  #include <dithering_fragment>
812
- #include <outline_bc_fragment>`)}setOutlineVisible(e){this.outlineVisible=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}enableOutline(e){this.useBCOutline=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}setOutLineColor(e){const i=e||this.defaultOutlineColor;this.uniforms.outlineColor={value:i}}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}const oh=`
812
+ #include <outline_bc_fragment>`)}setOutlineVisible(e){this.outlineVisible=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}enableOutline(e){this.useBCOutline=e,this.useBCOutline&&this.outlineVisible?this.defines.USE_BC_OUTLINE="":delete this.defines.USE_BC_OUTLINE}setOutLineColor(e){const i=e||this.defaultOutlineColor;this.uniforms.outlineColor={value:i}}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}const E1=`
813
813
  // When an object is transparent, we'll change its alpha value,
814
814
  // but we should not assign a fixed value because it may already
815
815
  // has an alpha value that is lower than 1.
@@ -951,12 +951,12 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
951
951
  }
952
952
 
953
953
  // TODO: isHighlighted isOverride isHovered
954
- `,lh=`
954
+ `,O1=`
955
955
  attribute int tileObjectId;
956
956
  flat varying int vTileObjectId;
957
- `,hh=`
957
+ `,_1=`
958
958
  vTileObjectId = tileObjectId;
959
- `,ch=`
959
+ `,P1=`
960
960
  #ifdef USE_BC_OUTLINE
961
961
  // Restore barycentric coordinates
962
962
  int barycentricX = int(barycentric) & 0x1;
@@ -964,14 +964,14 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
964
964
  int barycentricZ = int(barycentric) & 0x4;
965
965
  vBarycentric = vec3(float(barycentricX), float(barycentricY), float(barycentricZ));
966
966
  #endif
967
- `,dh=`
967
+ `,A1=`
968
968
  #ifdef USE_BC_OUTLINE
969
969
  vec3 finWireframeColor = outlineColor;
970
970
  vec3 tempColor = gl_FragColor.rgb;
971
971
 
972
972
  gl_FragColor.rgb = mix(finWireframeColor, tempColor, edgeFactor3());
973
973
  #endif
974
- `,uh=`
974
+ `,I1=`
975
975
  #ifdef USE_BC_OUTLINE
976
976
  varying vec3 vBarycentric;
977
977
  uniform vec3 outlineColor;
@@ -985,12 +985,12 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
985
985
  return min(min(a3.x, a3.y), a3.z);
986
986
  }
987
987
  #endif
988
- `,fh=`
988
+ `,B1=`
989
989
  #ifdef USE_BC_OUTLINE
990
990
  attribute float barycentric;
991
991
  varying vec3 vBarycentric;
992
992
  #endif
993
- `,ph=`
993
+ `,k1=`
994
994
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
995
995
  // if (uHoverId == tileObjectId) {
996
996
  // gl_FragColor = uHoverColor;
@@ -1027,7 +1027,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1027
1027
  // gl_FragColor = vec4(0.5, 0.5, 0.5, 0.8);
1028
1028
  // }
1029
1029
  // }
1030
- `,mh=`
1030
+ `,D1=`
1031
1031
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
1032
1032
  // State priority (high to low):
1033
1033
  // - Hidden
@@ -1045,7 +1045,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1045
1045
  gl_FragColor = HIGHLIGHT_COLOR;
1046
1046
  return;
1047
1047
  }
1048
- `,gh=`
1048
+ `,L1=`
1049
1049
  flat varying int vTileObjectId;
1050
1050
  uniform float uTextureWidth;
1051
1051
  uniform float uTextureHeight;
@@ -1054,7 +1054,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1054
1054
  // uniform int uHoverId;
1055
1055
  // uniform bool uIsIsolating;
1056
1056
  // uniform bool uTransparentOthersForIsolation;
1057
- `,yh=`
1057
+ `,R1=`
1058
1058
  vec4 textureColor = getTextureColorByTileObjectId(uStateTexture, uTextureWidth, uTextureHeight, vTileObjectId);
1059
1059
  // State priority (high to low):
1060
1060
  // - Hidden
@@ -1072,7 +1072,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1072
1072
  gl_FragColor = HIGHLIGHT_COLOR;
1073
1073
  return;
1074
1074
  }
1075
- `,_n=`
1075
+ `,jo=`
1076
1076
  #include <clipping_planes_pars_vertex>
1077
1077
 
1078
1078
  attribute int tileObjectId;
@@ -1089,7 +1089,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1089
1089
  #endif
1090
1090
  gl_Position = projectionMatrix * modelViewMatrix * mvPosition;
1091
1091
  }
1092
- `,Pn=`
1092
+ `,Uo=`
1093
1093
  #include <clipping_planes_pars_fragment>
1094
1094
 
1095
1095
  flat varying int vTileObjectId;
@@ -1116,7 +1116,7 @@ parentUserData: `+JSON.stringify(n.parentUserData)),S.info(a);const o=de.cloneMa
1116
1116
 
1117
1117
  gl_FragColor = tileObjectId2Color(vTileObjectId);
1118
1118
  }
1119
- `,xh=`
1119
+ `,F1=`
1120
1120
  #define STANDARD
1121
1121
 
1122
1122
  varying vec3 vViewPosition;
@@ -1176,7 +1176,7 @@ void main() {
1176
1176
 
1177
1177
  #endif
1178
1178
  }
1179
- `,bh=`
1179
+ `,z1=`
1180
1180
  #define STANDARD
1181
1181
 
1182
1182
  #ifdef PHYSICAL
@@ -1342,27 +1342,27 @@ void main() {
1342
1342
 
1343
1343
  #include <outline_bc_fragment>
1344
1344
  }
1345
- `;d.ShaderChunk.outline_bc_vertex=ch;d.ShaderChunk.outline_bc_fragment=dh;d.ShaderChunk.outline_bc_pars_fragment=uh;d.ShaderChunk.outline_bc_pars_vertex=fh;d.ShaderChunk.standard_ex_vertex=xh;d.ShaderChunk.standard_ex_fragment=bh;d.ShaderChunk.common_ex=oh;d.ShaderChunk.id_pars_vertex=lh;d.ShaderChunk.id_vertex=hh;d.ShaderChunk.state_pars_fragment=gh;d.ShaderChunk.state_fragment=ph;d.ShaderChunk.state_transparent_fragment=yh;d.ShaderChunk.state_highlight_fragment=mh;d.ShaderChunk.pick_ex_vertex=_n;d.ShaderChunk.pick_ex_fragment=Pn;class vh extends d.ShaderMaterial{constructor(e){super(e);p(this,"isBimTilesPickMaterial");p(this,"type");p(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=_n,this.fragmentShader=Pn,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class wh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesHighlightMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"depthTest");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Ls,this.depthTest=!1,this.side=d.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
1345
+ `;p.ShaderChunk.outline_bc_vertex=P1;p.ShaderChunk.outline_bc_fragment=A1;p.ShaderChunk.outline_bc_pars_fragment=I1;p.ShaderChunk.outline_bc_pars_vertex=B1;p.ShaderChunk.standard_ex_vertex=F1;p.ShaderChunk.standard_ex_fragment=z1;p.ShaderChunk.common_ex=E1;p.ShaderChunk.id_pars_vertex=O1;p.ShaderChunk.id_vertex=_1;p.ShaderChunk.state_pars_fragment=L1;p.ShaderChunk.state_fragment=k1;p.ShaderChunk.state_transparent_fragment=R1;p.ShaderChunk.state_highlight_fragment=D1;p.ShaderChunk.pick_ex_vertex=jo;p.ShaderChunk.pick_ex_fragment=Uo;class V1 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=jo,this.fragmentShader=Uo,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class j1 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=Tr,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>
1349
- #include <id_vertex>`),this.fragmentShader=r.replace("#include <common>",`
1349
+ #include <id_vertex>`),this.fragmentShader=n.replace("#include <common>",`
1350
1350
  #include <common>
1351
1351
  #include <common_ex>
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 Mh extends d.MeshStandardMaterial{constructor(e){super(e);p(this,"isBimTilesTransparentMaterial");p(this,"type");p(this,"transparent");p(this,"opacity");p(this,"side");p(this,"uniforms");p(this,"vertexShader");p(this,"fragmentShader");p(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Ls,this.side=d.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:r,vertexShader:n}=d.ShaderLib.standard;this.uniforms=d.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=n.replace("#include <common>",`
1355
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class U1 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=Tr,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>
1359
- #include <id_vertex>`),this.fragmentShader=r.replace("#include <common>",`
1359
+ #include <id_vertex>`),this.fragmentShader=n.replace("#include <common>",`
1360
1360
  #include <common>
1361
1361
  #include <common_ex>
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 Mt=(h=>(h[h.Hidden=0]="Hidden",h[h.Transparent=1]="Transparent",h[h.Highlighted=2]="Highlighted",h[h.Hovered=3]="Hovered",h))(Mt||{});class Th{constructor(t,e){p(this,"_pickMaterial");p(this,"_highlightMaterial");p(this,"_transparentMaterial");p(this,"stateTexture");p(this,"batchMaterialMap",new Map);p(this,"instanceMaterialMap",new Map);p(this,"tileRenderer");p(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 r=new Dr(Object.assign(Object.assign({},e),{vertexColors:!0,stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.batchMaterialMap.set(s,r)}return this.batchMaterialMap.get(s)}createInstanceMaterial(t,e={},i=!1){const s=t+Number(i);if(!this.instanceMaterialMap.get(s)){const r=new Dr(Object.assign(Object.assign({},e),{stateTexture:this.stateTexture}));i&&r.enableOutline(!0),this.instanceMaterialMap.set(s,r)}return this.instanceMaterialMap.get(s)}get highlightMaterial(){return this._highlightMaterial||(this._highlightMaterial=new wh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new Mh({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new vh({stateTexture:this.stateTexture})),this._pickMaterial}createStateTexture(t){t+=1;const e=d.MathUtils.ceilPowerOfTwo(Math.sqrt(t)),i=d.MathUtils.ceilPowerOfTwo(Math.ceil(t/e));return new d.DataTexture(new Uint8Array(e*i*4),e,i,d.RGBAFormat,d.UnsignedByteType)}updateState(t,e,i,s){const r=this.stateTexture.image.data;for(let n=0;n<e.length;n++){const a=e[n],o=a*4;switch(t){case 0:r[o]=this.setFlag(r[o],t,i);break;case 1:{r[o]=this.setFlag(r[o],t,i);let l=0;i&&s!=null&&(l=this.opacity2Int8(s)),r[o+1]=l,r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],2,!1)}break;case 2:r[o]=this.setFlag(r[o],3,!1),r[o]=this.setFlag(r[o],t,i);break;case 3:r[o]=this.setFlag(r[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,r=this.stateTexture.image.data;for(let n=0;n<s.width*s.height;n++){const a=n*4;this.getFlag(r[a],1)?r[a+2]=this.setFlag(r[a],0,!1):r[a+2]=this.setFlag(r[a],0,!0)}e?this.updateClonedTransparentMesh(t):this.clearClonedTransparentMesh(t),S.info("[BimTiles] setHiddenForTransparent took "+(Date.now()-i)/1e3+"s")}updateClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n],o=a.userData.userIds;if(!o||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];if(o.indexOf(u)>-1){if(l){l.userData.handleUserIds.has(u)||l.userData.handleUserIds.add(u);continue}this.cloneMeshForTransparent(e,a),a.clonedMesh.userData.handleUserIds.clear(),a.clonedMesh.userData.handleUserIds.add(u)}}}})}clearClonedTransparentMesh(t){t.length!==0&&this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];if(!a||!a.userData.userIds||a.sourceMesh)continue;const l=a.clonedMesh;for(let c=0;c<t.length;c++){const u=t[c];l&&l.userData.handleUserIds.has(u)&&l.userData.handleUserIds.delete(u)}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 d.BufferGeometry,r=e.geometry.getAttribute("position"),n=e.geometry.index,a=e.geometry.getAttribute("tileObjectId");s.setAttribute("position",r),s.setAttribute("tileObjectId",a),n&&s.setIndex(n),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 r=0;r<s;r++){const n=i[r];if(!n)break;!n.userData.userIds||n.sourceMesh||n.clonedMesh||this.cloneMeshForTransparent(t,n)}})}clearAllClonedTransparentMesh(){const t=[];this.tileRenderer.forEachLoadedModel((e,i)=>{const s=e.children,r=s.length;for(let n=0;n<r;n++){const a=s[n];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 r=s*4;i[r]=this.setFlag(i[r],0,t)}this.updateMaterialStates(),this.updateHighlightMesh()}setOpacity(t){const e=Date.now(),i=this.opacity2Int8(t),s=t<1,r=this.stateTexture.image,n=this.stateTexture.image.data;for(let a=0;a<r.width*r.height;a++){const o=a*4;n[o]=this.setFlag(n[o],1,s),n[o]=this.setFlag(n[o],3,!1),n[o]=this.setFlag(n[o],2,!1),n[o+1]=i,n[o+2]=this.setFlag(n[o],0,!s)}s?this.updateAllClonedTransparentMesh():this.clearAllClonedTransparentMesh(),this.updateMaterialStates(),S.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){S.warn("[BimTiles] Failed to get geometry by userIds:",t);return}this.highlightMesh=new d.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!==d.DoubleSide&&(e.userData.originalSide==null&&(e.userData.originalSide=e.side),e.side=d.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 r=s*4;this.getFlag(i[r],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 r=s*4;this.getFlag(i[r],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 n=i;return{tilesetId:this.tileRenderer.tilesetId,userId:n}}}}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 r=1<<s;return t|r}else{const r=~(1<<s);return t&r}}getFlag(t,e){const i=Number(e);return(t&1<<i)!==0}}const Ch={9728:d.NearestFilter,9729:d.LinearFilter},Sh={9984:d.NearestMipmapNearestFilter,9985:d.LinearMipmapNearestFilter,9986:d.NearestMipmapLinearFilter,9987:d.LinearMipmapLinearFilter},Br={33071:d.ClampToEdgeWrapping,33648:d.MirroredRepeatWrapping,10497:d.RepeatWrapping};var Wi=(h=>(h.Opaque="OPAQUE",h.Mask="MASK",h.Blend="BLEND",h))(Wi||{});const An={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var js=(h=>(h[h.scalar=1]="scalar",h[h.vec2=2]="vec2",h[h.vec3=3]="vec3",h[h.vec4=4]="vec4",h[h.mat2=4]="mat2",h[h.mat3=9]="mat3",h[h.mat4=16]="mat4",h))(js||{});class Oh{constructor(t,e){p(this,"baseUrl");p(this,"textureLoaderCache",new Map);p(this,"materialCache",new Map);p(this,"textureCache",new Map);p(this,"userDataCache",new Map);p(this,"familyInstanceIdCache",new Map);p(this,"familyInstanceAndUserIdsCache",new Map);p(this,"userIdAndUserDataCache",new Map);p(this,"userBoxCache",new Map);p(this,"protoRoot");p(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return z.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 r=new Uint8Array(s),n=Ds.inflate(r);return this.protoRoot.lookupType(i).decode(n)})}getTextureLoader(t){if(t!=="dds"&&(t="default"),this.textureLoaderCache.has(t))return this.textureLoaderCache.get(t);let e;return t==="dds"?e=new Ma.DDSLoader:e=new d.TextureLoader,this.textureLoaderCache.set(t,e),e}loadTexture(t,e){const i=e.textures[t],s=e.images[i.image],r=s.uri+":"+i.sampler;if(this.textureCache.get(r))return this.textureCache.get(r);const n=this.getTextureLoader(s.type),a=new Promise((o,l)=>{n.load(this.baseUrl+s.uri,c=>{const u=e.samplers||{},f=u[c.sampler]||{};c.magFilter=Ch[f.magFilter]||d.LinearFilter,c.minFilter=Sh[f.minFilter]||d.LinearMipmapLinearFilter,c.wrapS=Br[f.wrapS]||d.RepeatWrapping,c.wrapT=Br[f.wrapT]||d.RepeatWrapping,o(c)},void 0,c=>{throw S.error("[BimTiles] Couldn't load texture",s.uri),l(c),c})});return this.textureCache.set(r,a),a}assignTexture(t,e,i,s,r){return i.index?this.loadTexture(i.index,s).then(n=>n?(i.texCoord!==void 0&&i.texCoord>0&&(n=n.clone(),n.channel=i.texCoord),r!==void 0&&(n.colorSpace=r),n):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 d.Color(1,1,1),s.opacity=1,Array.isArray(i.baseColorFactor)){const n=i.baseColorFactor;s.color.setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace),s.opacity=n[3]}i.baseColorTexture&&(s.map=await this.assignTexture(s,"map",i.baseColorTexture,t,d.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=d.DoubleSide);const r=i.alphaMode||Wi.Opaque;if(r===Wi.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,r===Wi.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 d.Vector2(1,1)),i.occlusionTexture&&(s.aoMap=await this.assignTexture(s,"aoMap",i.occlusionTexture,t)),i.emissiveFactor){const n=i.emissiveFactor;s.emissive=new d.Color().setRGB(n[0],n[1],n[2],d.LinearSRGBColorSpace)}return i.emissiveTexture&&(s.emissiveMap=await this.assignTexture(s,"emissiveMap",i.emissiveTexture,t,d.SRGBColorSpace)),this.materialCache.get(i.id)||this.materialCache.set(i.id,s),this.materialCache.get(i.id)});return Promise.all(e).then(()=>{S.info("[BimTilesPropertyParser] material parser complete.")})}parseUserData(t){const{userDataKeys:e,userDataValues:i,userDataItems:s}=t;s.forEach((r,n)=>{r.indexMap&&(r=r.indexMap);const a={};for(const o in r)a[e[o]]=i[r[o]];this.userDataCache.set(n,a)})}parseUserId(t){const{modelIds:e,familyInstanceIds:i,modelTable:s,userIdTable:r}=t;Object.keys(s).forEach(n=>{const a=Number(n),o=e[a],l=s[a].value||s[a],c=l.map(u=>i[u]);this.familyInstanceIdCache.set(o,c)}),Object.keys(r).forEach(n=>{const a=Number(n),o=r[a].value||r[a],l=e[o[0]],c=i[o[1]],u=l+"#"+c;this.familyInstanceAndUserIdsCache.has(u)||this.familyInstanceAndUserIdsCache.set(u,[]),this.familyInstanceAndUserIdsCache.get(u).push(a);const f=o[2];this.userIdAndUserDataCache.set(a,{modelId:l,familyInstanceId:c,userDataIndex:f})})}parseUserIdBox(t,e){t.boxMap&&(t=t.boxMap),Object.keys(t).forEach(i=>{const s=Number(i),r=t[s].value?t[s].value:t[s],n=new d.Box3().setFromArray(r);e&&n.applyMatrix4(e),this.userBoxCache.set(s,n)})}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 r=this.getUserIdByUserDataIndex(s);r!==void 0&&e.push(r)}}),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 In(h){return new TextDecoder().decode(h)}function Lr(h,t){return((h&255)<<24)+(t&16777215)}function Eh(h){return h[3]}function _h(h){return(h[0]<<16)+(h[1]<<8)+h[2]}function kn(h){const t=h.BYTES_PER_ELEMENT,e=(1<<8*t-1)-1,i=2,s=h.length/i,r=new d.Vector2,n=new d.Vector3,a=new Float32Array(s*3);for(let o=0;o<s;o++)r.fromArray(h,o*i),R.OctDecode(r,n,e),n.toArray(a,o*3);return a}class Rr{parse(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n,byteLength:a,batchTable:o}=r,l=t.slice(n,n+a);i.push(this.parseMesh(l,r,o))}return i}parseMesh(t,e,i){const s=e.primitive,r=e.buffers,n=this.parseTypedArray(t,r[s.position]),a=s.color?this.parseTypedArray(t,r[s.color]):new Float32Array,o=s.indice?this.parseTypedArray(t,r[s.indice]):new Uint16Array;let l=s.normal?this.parseTypedArray(t,r[s.normal]):new Float32Array;s.normal>=0&&s.normalCompressed&&(l=kn(l));const c=s.tangent?this.parseTypedArray(t,r[s.tangent]):new Float32Array,u=s.uv_0?this.parseTypedArray(t,r[s.uv_0]):new Float32Array,f=s.barycentric?this.parseTypedArray(t,r[s.barycentric]):new Uint8Array,m=new Array(n.length/3);return i.forEach(g=>{m.fill(g.userId,g.positionStart,g.positionStart+g.positionCount)}),{type:s.type,position:n,indice:o,color:a,normal:l,tangent:c,barycentric:f,uv:u,userIds:m,materialId:s.materialId||s.material,batchTable:e.batchTable}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=An[a],c=t.slice(i,i+s);return new l(c,0,r*o)}}const St=class St{constructor(){p(this,"header")}async parse(t,e,i){const s=[];for(let r=0;r<t.length;r++){const{blobId:n,url:a,instances:o}=t[r],l=await this.getInstancedMeshByUrlAndBlobId(e+a,n,i);if(!l){S.warn("[BimTiles] Failed to get InstancedMesh by "+(e+a)+", bloblId '"+n+"'");continue}const c=[],u=[];o.forEach(m=>{c.push(m.userId),u.push(...m.transform)});const f=Object.assign(Object.assign({},l),{userIds:c,matrices:u});s.push(f)}return s}parseInstanceBuffer(t){const e=new vi(t);this.header={magic:e.readUtf8String(4),version:e.readUint32(),byteLength:e.readUint64()};const i=e.readUint32(),s=e.readUint32(),r=e.readUint32(),n=e.readUint64(),a=t.slice(i,i+s),o=In(new Uint8Array(a,0,s)),l=JSON.parse(o),c=t.slice(r,r+n);return this.parseMeshes(c,l.meshes)}parseInstanceProto(t,e){const i=Ds.inflate(t),s=e.lookupType("PBTileContent"),r=s.decode(i);return this.parseMeshes(r.binaries.slice().buffer,r.meshes)}parseMeshes(t,e){const i=[];for(let s=0;s<e.length;s++){const r=e[s],{byteOffset:n=0,byteLength:a}=r,o=t.slice(n,n+a);i.push(this.parseMesh(o,r))}return i}parseMesh(t,e){const i=e.primitive,s=e.buffers,r=this.parseTypedArray(t,s[i.position]),n=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=kn(o));const l=i.tangent?this.parseTypedArray(t,s[i.tangent]):new Float32Array,c=i.uv_0?this.parseTypedArray(t,s[i.uv_0]):new Float32Array,u=i.barycentric?this.parseTypedArray(t,s[i.barycentric]):new Uint8Array,f=[],m=[];return{type:i.type,position:r,indice:a,color:n,normal:o,tangent:l,uv:c,barycentric:u,userIds:f,matrices:m,materialId:i.materialId||i.material}}parseTypedArray(t,e){const{byteOffset:i,byteLength:s,count:r,type:n,componentType:a}=e,o=Number(js[n]),l=An[a],c=t.slice(i,i+s);return new l(c,0,r*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!St.instanceDataMap[t]){const s=await fetch(t).then(n=>n.arrayBuffer()),r=new Uint8Array(s);z.isGzip(r)&&i?St.instanceDataMap[t]=this.parseInstanceProto(r,i):St.instanceDataMap[t]=this.parseInstanceBuffer(s)}return St.instanceDataMap[t][e]}};p(St,"instanceDataMap",{});let Xi=St;class Ph{async parse(t,e,i){const s=new Uint8Array(t);return z.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new vi(t),s=i.readUtf8String(4),r=i.readUint32(),n=i.readUint64(),a=i.readUint32(),o=i.readUint32(),l=i.readUint32(),c=i.readUint64(),u=t.slice(a,a+o),f=In(new Uint8Array(u,0,o)),m=JSON.parse(f);S.debug("[BimTiles] Tile, magic("+s+"), version("+r+"), byteLength("+n+"), tileJson:",m);const g=t.slice(l,l+c),x=new Rr().parse(g,m.batchedMeshes),y=await new Xi().parse(m.instancedMeshes,e);return{batchedMeshes:x,instancedMeshes:y}}async parseProto(t,e,i){const s=Ds.inflate(t),r=i.lookupType("PBTileContent").decode(s),n=r.header;S.debug("[BimTiles] Tile, magic("+n.magic+"), version("+n.version+"), byteLength("+s.byteLength+"), tileJson:",r);const a=r.binaries.slice().buffer,o=new Rr().parse(a,r.meshes),l=await new Xi().parse(r.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const Ah=`syntax = "proto3";\r
1365
+ #include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var Zt=(c=>(c[c.Hidden=0]="Hidden",c[c.Transparent=1]="Transparent",c[c.Highlighted=2]="Highlighted",c[c.Hovered=3]="Hovered",c))(Zt||{});class N1{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 ja(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 ja(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 j1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new U1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new V1({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 H1={9728:p.NearestFilter,9729:p.LinearFilter},G1={9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},Ua={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping};var nn=(c=>(c.Opaque="OPAQUE",c.Mask="MASK",c.Blend="BLEND",c))(nn||{});const No={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var Or=(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))(Or||{});class q1{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=gr.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 jl.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=H1[u.magFilter]||p.LinearFilter,h.minFilter=G1[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=Ua[u.wrapS]||p.RepeatWrapping,h.wrapT=Ua[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||nn.Opaque;if(n===nn.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,n===nn.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 Ho(c){return new TextDecoder().decode(c)}function Na(c,t){return((c&255)<<24)+(t&16777215)}function W1(c){return c[3]}function Y1(c){return(c[0]<<16)+(c[1]<<8)+c[2]}function Go(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),F.OctDecode(n,r,e),r.toArray(a,o*3);return a}class Ha{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=Go(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(Or[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}}const Jt=class Jt{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 fs(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=Ho(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=gr.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=Go(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(Or[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!Jt.instanceDataMap[t]){const s=await fetch(t).then(r=>r.arrayBuffer()),n=new Uint8Array(s);j.isGzip(n)&&i?Jt.instanceDataMap[t]=this.parseInstanceProto(n,i):Jt.instanceDataMap[t]=this.parseInstanceBuffer(s)}return Jt.instanceDataMap[t][e]}};g(Jt,"instanceDataMap",{});let on=Jt;class X1{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 fs(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=Ho(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 Ha().parse(m,f.batchedMeshes),y=await new on().parse(f.instancedMeshes,e);return{batchedMeshes:b,instancedMeshes:y}}async parseProto(t,e,i){const s=gr.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 Ha().parse(a,n.meshes),l=await new on().parse(n.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const Z1=`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
- `,Dn=Symbol("INITIAL_FRUSTUM_CULLED");function Ih(h,t){h.traverse(e=>{e.frustumCulled=e[Dn]&&t})}const Pi=new d.Vector3,Ai=new d.Vector3,ps=new d.Box3;class Bn extends va.TilesRenderer{constructor(e,i){super(e);p(this,"highlighUsage");p(this,"transparentUsage");p(this,"pickUsage");p(this,"materialManager");p(this,"baseUrl");p(this,"propertyParser");p(this,"tilesetId");p(this,"onBeforeParseTile");p(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 d.Group,this.highlighUsage.name="highlighUsage-"+this.tilesetId,this.group.add(this.highlighUsage),this.transparentUsage=new d.Group,this.transparentUsage.name="transparentUsage-"+this.tilesetId,this.group.add(this.transparentUsage),this.pickUsage=new d.Group,this.protoRoot=Wa.parse(Ah).root,this.propertyParser=new Oh(this.baseUrl,this.protoRoot)}getVertexColorArray(e,i=new d.Color(16777215)){const s=[],{r,g:n,b:a}=i;for(let o=0;o<e;o+=3)s.push(r,n,a);return new Float32Array(s)}createBatchedMesh(e){const{position:i,uv:s,normal:r,indice:n,barycentric:a,userIds:o,materialId:l,batchTable:c}=e;let u=e.color;const f=o.map(b=>Lr(this.tilesetId,b)),m=new d.BufferGeometry;m.setAttribute("position",new d.Float32BufferAttribute(i,3)),m.setAttribute("normal",new d.Float32BufferAttribute(r,3)),m.setAttribute("uv",new d.Float32BufferAttribute(s,2)),m.setAttribute("tileObjectId",new d.Int32BufferAttribute(f,1)),m.setIndex(Array.from(n));const g=this.propertyParser.getMaterialParameters(l);u.length===0&&(u=this.getVertexColorArray(i.length,g?.color)),m.setAttribute("color",new d.Float32BufferAttribute(u,3));const x=a.length>0;x&&m.setAttribute("barycentric",new d.BufferAttribute(a,1));const y=this.materialManager?.createBatchMaterial(l,g,x),T=new d.Mesh(m,y),v=new d.Mesh(m,this.materialManager?.pickMaterial);return{mesh:T,pickMesh:v,batchTable:c}}createInstancedMesh(e){const{position:i,uv:s,color:r,normal:n,indice:a,barycentric:o,matrices:l,userIds:c,materialId:u}=e,f=c.map(O=>Lr(this.tilesetId,O)),m=c.length,g=new d.BufferGeometry;g.setIndex(Array.from(a)),g.setAttribute("position",new d.Float32BufferAttribute(i,3)),g.setAttribute("uv",new d.Float32BufferAttribute(s,2)),g.setAttribute("normal",new d.Float32BufferAttribute(n,3)),g.setAttribute("tileObjectId",new d.InstancedBufferAttribute(new Int32Array(f),1));const x=o.length>0;x&&g.setAttribute("barycentric",new d.BufferAttribute(o,1));const y=this.propertyParser.getMaterialParameters(u),T=this.materialManager?.createInstanceMaterial(u,y,x),v=new d.InstancedMesh(g,T,m);v.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16);let b=r;b.length===0&&(b=this.getVertexColorArray(m*3,y?.color)),v.instanceColor=new d.InstancedBufferAttribute(b,3);const E=new d.InstancedMesh(g,this.materialManager?.pickMaterial,m);return E.instanceMatrix=new d.InstancedBufferAttribute(new Float32Array(l),16),{mesh:v,pickMesh:E,userIds:c}}getGeometryByUserIds(e){const i=Date.now(),s=[];return this.visibleTiles.forEach(r=>{const n=r.cached.scene.children;for(let a=0;a<n.length;a++){const o=n[a];if(!o||o.sourceMesh)continue;const l=o.userData.userIds;if(l)for(let c=0;c<e.length;c++){const u=e[c],f=l.indexOf(u);if(f>-1){const m=new d.BufferGeometry,g=o.geometry.getAttribute("position"),x=o.geometry.index,y=o.geometry.getAttribute("tileObjectId");if(o instanceof d.InstancedMesh){const T=new d.Matrix4;o.getMatrixAt(f,T),m.setAttribute("position",g.clone());const v=y.array[f*y.itemSize];m.setAttribute("tileObjectId",new d.Int32BufferAttribute(new Array(g.array.length/3).fill(v),1)),x&&m.setIndex(x),m.applyMatrix4(T)}else{const{indexStart:T,indexCount:v,positionStart:b,positionCount:E}=o.userData.batchTable.find(P=>P.userId===u),O=g.itemSize,_=g.array.slice(b*O,b*O+E*O),C=new d.Float32BufferAttribute(_,O);m.setAttribute("position",C);const w=y.array.slice(b,b+E),M=new d.Int32BufferAttribute(w,1);if(m.setAttribute("tileObjectId",M),x){const P=x.array.slice(T,T+v);for(let A=0;A<P.length;A++)P[A]-=b;m.setIndex(new d.BufferAttribute(P,1))}}m.applyMatrix4(o.matrixWorld),s.push(m)}}}}),S.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?xe.mergeGeometries(s):s[0]}parseTile(e,i,s){this.onBeforeParseTile&&this.onBeforeParseTile(i),i._loadIndex=i._loadIndex||0,i._loadIndex++;const r=i.cached,n=r.transform;return new Ph().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{S.debug("[BimTiles] batchedMeshes:",o),S.debug("[BimTiles] instancedMeshes:",l);const c=new d.Group;c.name="TileGroup";const u=new d.Group;u.name="TileGroup-pick",o.forEach(m=>{const{mesh:g,pickMesh:x,batchTable:y}=this.createBatchedMesh(m);c.add(g),g.userData.batchTable=y,g.userData.userIds=y.map(T=>T.userId),u.add(x)}),l.forEach(m=>{const{mesh:g,pickMesh:x,userIds:y}=this.createInstancedMesh(m);c.add(g),g.userData.userIds=y,u.add(x)});const f=m=>{m.applyMatrix4(n)};f(c),c.traverse(m=>{m[Dn]=m.frustumCulled}),Ih(c,!this.autoDisableRendererCulling),f(u),r.scene=c,r.pickScene=u,this.onLoadModel&&this.onLoadModel(c,i)})}disposeTile(e){const i=e.cached;if(i.scene){const s=r=>{r.traverse(n=>{n.geometry&&n.geometry.dispose()}),r.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)&&(ps.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(ps.getCenter(Pi),ps.getSize(Ai),e.cached.boundingVolume.setObbData([Pi.x,Pi.y,Pi.z,Ai.x/2,0,0,0,Ai.y/2,0,0,0,Ai.z/2],e.cached.transform)))}async fetchTileSet(e,i,s){return fetch(e,i).then(r=>{if(r.ok)return r.json();throw new Error('BimTilesRenderer: Failed to load tileset "'+e+'" with status '+r.status+" : "+r.statusText)}).then(async r=>{const{material:n,userData:a,userId:o,userIdBox:l}=r.properties,c=[];if(n.url){const f=this.propertyParser.getProperty(n.url,i,"PBMaterials").then(m=>this.propertyParser.parseMaterial(m));c.push(f)}if(a.url){const f=this.propertyParser.getProperty(a.url,i,"PBUserData").then(m=>this.propertyParser.parseUserData(m));c.push(f)}if(o.url){const f=this.propertyParser.getProperty(o.url,i,"PBUserId").then(m=>this.propertyParser.parseUserId(m));c.push(f)}if(l.url){const f=this.propertyParser.getProperty(l.url,i,"PBUserIdBox").then(m=>this.propertyParser.parseUserIdBox(m,this.group.matrix));c.push(f)}await Promise.all(c);let u=e.replace(/\/[^\\/]*\/?$/,"");return u=new URL(u,window.location.href).toString(),this.preprocessNode(r.root,u,s),this.onLoadTileSet&&Promise.resolve().then(()=>{this.onLoadTileSet(r)}),r})}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(r=>{i[e]=r,this.materialManager=new Th(this,{maxId:r.properties.userId.maxUserIdIndex})});return s.catch(r=>{S.error("[BimTiles] loadRootTileSet error:",r),i[e]=r}),i[e]=s,s}}update(){super.update()}setTileVisible(e,i){const{scene:s,pickScene:r}=e.cached,n=this.visibleTiles,a=this.group;i?(n.add(e),a.add(s),this.pickUsage.add(r),s.updateMatrixWorld(!0),r.updateMatrixWorld(!0)):(n.delete(e),a.remove(s),this.pickUsage.remove(r)),this.onTileVisibilityChange&&this.onTileVisibilityChange(s,e,i)}calculateError(e){const i=e.cached,s=i.inFrustum,r=this.cameras,n=this.cameraInfo,a=i.boundingVolume;let o=-1/0,l=1/0;for(let c=0,u=r.length;c<u;c++){if(!s[c])continue;const f=n[c],m=f.invScale;let g;if(f.isOrthographic){const x=f.pixelSize;g=e.geometricError/(x*m)}else{const x=a.distanceToPoint(f.position),y=x*m,T=f.sseDenominator;g=e.geometricError/(y*T),l=Math.min(l,y)}o=Math.max(o,g)}e.__distanceFromCamera=l,e.__error=o}}class Vs extends Ji{constructor(e,i,s){super();p(this,"modelId");p(this,"_bbox");p(this,"tilesRenderer");p(this,"metadata");p(this,"statistics");this.modelId=e.modelId;const r=i+s.getMetadata().root;this.tilesRenderer=new Bn(r,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 r=i.userData.userIds;for(let n=0,a=r.length;n<a;n++)if(r[n]===e)return i}const s=i.children;for(let r=0,n=s.length;r<n;r++)if(this.traverseObjectByUserId(e,s[r]))return s[r]}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 d.Box3,this._bbox.setFromObject(this.getModelObject())),this._bbox}setObjectHoveredByUserId(e,i){this.materialManager.updateState(Mt.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(Mt.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(Mt.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(Mt.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(Mt.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(Mt.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 kh(){let h=new Map;return{on(t,e){const i=h.get(t);i?i.push(e):h.set(t,[e])},off(t,e){const i=h.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):h.set(t,[]))},emit(t,e){const i=h.get(t);i&&i.slice().map(s=>s(e)),h.get("*")&&h.get("*").slice().map(s=>s(t,e))}}}class Dh{constructor(t){p(this,"viewer");p(this,"element");p(this,"content");p(this,"itemList");p(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(re.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 r=this.createItem(i,s);this.itemList[i]=r,r.resetActivate=()=>{for(const n in this.itemList)this.itemList[n].resetActive()},e?.appendChild(r.element)}),this.element=t,this.content=e,this.element.appendChild(this.content),this.viewer.widgetContainer?.appendChild(this.element)}createItem(t,e){const i=new Bh(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 Bh{constructor(t,e){p(this,"viewer");p(this,"eventBus");p(this,"element");p(this,"resetActivate");p(this,"active");this.viewer=t,this.eventBus=kh(),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 Ln{constructor(t){p(this,"element");p(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 Us{constructor(t){p(this,"width");p(this,"height");p(this,"container");p(this,"viewerContainer");p(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(S.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 Hs{constructor(t){p(this,"element");p(this,"progressItems");p(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)&&S.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=Re.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 r=e?""+e:"";e&&i!=null&&(r+=": "),i!=null&&(i<0||i>100?(console.warn("[ProgressBar] Invalid progress value: "+i),r+="--%"):r+=i.toFixed(2)+"%"),s.div.innerHTML=r}updateProgressBar(t,e,i=0,s=100){const r=this.progressItems.get(t);if(!r)return;const n=e instanceof ProgressEvent?e.loaded:e,a=e instanceof ProgressEvent?e.total:100,o=n*100/a*(s-i)/100+i;r.div.innerHTML=r.div.innerHTML.replace(this.replaceReg,"<em>"+(o<0||o>100?"--":o.toFixed(2))+"%</em>"),r.onProgress?.call(r,new ProgressEvent("LoadProgress",{loaded:n,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 Be=(h=>(h.BaseViewer="BaseViewer",h.Viewer3d="Viewer3d",h.Viewer2d="Viewer2d",h.BimTilesViewer="BimTilesViewer",h))(Be||{}),$e=(h=>(h.Perspective="Perspective",h.Orthographic="Orthographic",h))($e||{});const Lh={enableSpinner:!0,containerId:"myCanvas"},G={LEFT:1,RIGHT:2,MIDDLE:4},D=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 Ve(h){return h.isPerspectiveCamera}function Oe(h){return h.isOrthographicCamera}class Rh{constructor(){p(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 r=s.indexOf(e);r!==-1&&s.splice(r,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 r=0,n=s.length;r<n;r++)s[r].call(this,t)}}}const At=Math.PI*2,Fr=Math.PI/2;function ms(h,t){t.set(0,0),h.forEach(e=>{t.x+=e.clientX,t.y+=e.clientY}),t.x/=h.length,t.y/=h.length}function gs(h,t){return Oe(h)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Rn=1e-5,ei=Math.PI/180;function Ft(h,t,e){return Math.max(t,Math.min(e,h))}function ie(h,t=Rn){return Math.abs(h)<t}function te(h,t,e=Rn){return ie(h-t,e)}function zr(h,t){return Math.round(h/t)*t}function ti(h){return isFinite(h)?h:h<0?-Number.MAX_VALUE:Number.MAX_VALUE}function ii(h){return Math.abs(h)<Number.MAX_VALUE?h:h*(1/0)}function Ii(h,t,e,i,s=1/0,r){i=Math.max(1e-4,i);const n=2/i,a=n*r,o=1/(1+a+.48*a*a+.235*a*a*a);let l=h-t;const c=t,u=s*i;l=Ft(l,-u,u),t=h-l;const f=(e.value+n*l)*r;e.value=(e.value-n*f)*o;let m=t+(l+f)*o;return c-h>0==m>c&&(m=c,e.value=(m-c)/r),m}function jr(h,t,e,i,s=1/0,r,n){i=Math.max(1e-4,i);const a=2/i,o=a*r,l=1/(1+o+.48*o*o+.235*o*o*o);let c=t.x,u=t.y,f=t.z,m=h.x-c,g=h.y-u,x=h.z-f;const y=c,T=u,v=f,b=s*i,E=b*b,O=m*m+g*g+x*x;if(O>E){const L=Math.sqrt(O);m=m/L*b,g=g/L*b,x=x/L*b}c=h.x-m,u=h.y-g,f=h.z-x;const _=(e.x+a*m)*r,C=(e.y+a*g)*r,w=(e.z+a*x)*r;e.x=(e.x-a*_)*l,e.y=(e.y-a*C)*l,e.z=(e.z-a*w)*l,n.x=c+(m+_)*l,n.y=u+(g+C)*l,n.z=f+(x+w)*l;const M=y-h.x,P=T-h.y,A=v-h.z,I=n.x-y,k=n.y-T,B=n.z-v;return M*I+P*k+A*B>0&&(n.x=y,n.y=T,n.z=v,e.x=(n.x-y)/r,e.y=(n.y-T)/r,e.z=(n.z-v)/r),n}const ki=1/8,Fh=be.isBrowser&&/Mac/.test(navigator.platform),zh=!(be.isBrowser&&"PointerEvent"in window);let N,Vr,Di,ys,Me,W,ee,It,Ye,Xe,bt,Ur,Hr,je,si,kt,Nr,xs,Gr,bs,vs,Bi;class K extends Rh{constructor(e,i){super();p(this,"minPolarAngle");p(this,"maxPolarAngle");p(this,"minAzimuthAngle");p(this,"maxAzimuthAngle");p(this,"minDistance");p(this,"maxDistance");p(this,"infinityDolly");p(this,"minZoom");p(this,"maxZoom");p(this,"smoothTime");p(this,"draggingSmoothTime");p(this,"maxSpeed");p(this,"azimuthRotateSpeed");p(this,"polarRotateSpeed");p(this,"dollySpeed");p(this,"truckSpeed");p(this,"dollyToCursor");p(this,"dragToOffset");p(this,"verticalDragToForward");p(this,"boundaryFriction");p(this,"restThreshold");p(this,"colliderMeshes");p(this,"mouseButtons");p(this,"touches");p(this,"cancel");p(this,"_enabled");p(this,"_camera");p(this,"_yAxisUpSpace");p(this,"_yAxisUpSpaceInverse");p(this,"_state");p(this,"_domElement");p(this,"_viewport");p(this,"_target");p(this,"_targetEnd");p(this,"_focalOffset");p(this,"_focalOffsetEnd");p(this,"_spherical");p(this,"_sphericalEnd");p(this,"_zoom");p(this,"_zoomEnd");p(this,"_target0");p(this,"_position0");p(this,"_zoom0");p(this,"_focalOffset0");p(this,"_dollyControlAmount");p(this,"_dollyControlCoord");p(this,"_nearPlaneCorners");p(this,"_hasRested");p(this,"_boundary");p(this,"_boundaryEnclosesCamera");p(this,"_needsUpdate");p(this,"_updatedLastTime");p(this,"_elementRect");p(this,"_activePointers");p(this,"_isUserControllingRotate");p(this,"_isUserControllingDolly");p(this,"_isUserControllingTruck");p(this,"_isUserControllingOffset");p(this,"_isUserControllingZoom");p(this,"_thetaVelocity");p(this,"_phiVelocity");p(this,"_radiusVelocity");p(this,"_targetVelocity");p(this,"_focalOffsetVelocity");p(this,"_zoomVelocity");p(this,"_truckInternal");p(this,"_rotateInternal");p(this,"_dollyInternal");p(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=D.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 N.Vector3,this._focalOffsetVelocity=new N.Vector3,this._zoomVelocity={value:0},this._truckInternal=(b,E,O)=>{if(Ve(this._camera)){const _=W.copy(this._camera.position).sub(this._target),C=this._camera.getEffectiveFOV()*ei,w=_.length()*Math.tan(C*.5),M=this.truckSpeed*b*w/this._elementRect.height,P=this.truckSpeed*E*w/this._elementRect.height;this.verticalDragToForward?(O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(M,0,!0),this.forward(-P,!0)):O?this.setFocalOffset(this._focalOffsetEnd.x+M,this._focalOffsetEnd.y+P,this._focalOffsetEnd.z,!0):this.truck(M,P,!0)}else if(Oe(this._camera)){const _=this._camera,C=this.truckSpeed*b*(_.right-_.left)/_.zoom/this._elementRect.width,w=this.truckSpeed*E*(_.top-_.bottom)/_.zoom/this._elementRect.height;O?this.setFocalOffset(this._focalOffsetEnd.x+C,this._focalOffsetEnd.y+w,this._focalOffsetEnd.z,!0):this.truck(C,w,!0)}},this._rotateInternal=(b,E)=>{const O=At*this.azimuthRotateSpeed*b/this._elementRect.height,_=At*this.polarRotateSpeed*E/this._elementRect.height;this.rotate(O,_,!0)},this._dollyInternal=(b,E,O)=>{const _=Math.pow(.95,-b*this.dollySpeed),C=this._sphericalEnd.radius*_,w=this._sphericalEnd.radius,M=w*(b>=0?-1:1);this.dollyTo(C),this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(W),this._targetEnd.add(W.normalize().multiplyScalar(M)),this._target.add(W.normalize().multiplyScalar(M))),this.dollyToCursor&&(this._dollyControlAmount+=this._sphericalEnd.radius-w,this.infinityDolly&&(C<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=M),this._dollyControlCoord.set(E,O))},this._zoomInternal=(b,E,O)=>{const _=Math.pow(.95,b*this.dollySpeed),C=this._zoomEnd;this.zoomTo(this._zoom*_),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-C,this._dollyControlCoord.set(E,O))},typeof N>"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 N.Quaternion().setFromUnitVectors(this._camera.up,Di),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=D.NONE,this._target=new N.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new N.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new N.Spherical().setFromVector3(W.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new N.Vector3,new N.Vector3,new N.Vector3,new N.Vector3],this._updateNearPlaneCorners(),this._boundary=new N.Box3(new N.Vector3(-1/0,-1/0,-1/0),new N.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 N.Vector2,this.mouseButtons={left:D.ROTATE,middle:D.DOLLY,right:D.TRUCK,wheel:Ve(this._camera)?D.DOLLY:Oe(this._camera)?D.ZOOM:D.NONE},this.touches={one:D.TOUCH_ROTATE,two:Ve(this._camera)?D.TOUCH_DOLLY_TRUCK:Oe(this._camera)?D.TOUCH_ZOOM_TRUCK:D.NONE,three:D.TOUCH_TRUCK};const s=new N.Vector2,r=new N.Vector2,n=new N.Vector2,a=b=>{if(!this._enabled||!this._domElement)return;const E=b.pointerType!=="mouse"?null:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:b.pointerId,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:E};this._activePointers.push(O),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",u),y(b)},o=b=>{if(!this._enabled||!this._domElement)return;const E=(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.MIDDLE?G.MIDDLE:(b.buttons&G.RIGHT)===G.RIGHT?G.RIGHT:null;if(E!==null){const _=this._findPointerByMouseButton(E);_&&this._activePointers.splice(this._activePointers.indexOf(_),1)}const O={pointerId:0,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:(b.buttons&G.LEFT)===G.LEFT?G.LEFT:(b.buttons&G.MIDDLE)===G.LEFT?G.MIDDLE:(b.buttons&G.RIGHT)===G.LEFT?G.RIGHT:null};this._activePointers.push(O),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f),this._domElement.addEventListener("mousemove",c),this._domElement.addEventListener("mouseup",f),y(b)},l=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O){if(O.clientX=b.clientX,O.clientY=b.clientY,O.deltaX=b.movementX,O.deltaY=b.movementY,b.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,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);T()}},c=b=>{const E=this._findPointerById(0);E&&(E.clientX=b.clientX,E.clientY=b.clientY,E.deltaX=b.movementX,E.deltaY=b.movementY,this._state=0,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right),T())},u=b=>{const E=b.pointerId,O=this._findPointerById(E);if(O&&this._activePointers.splice(this._activePointers.indexOf(O),1),b.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=D.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=D.NONE;v()},f=()=>{const b=this._findPointerById(0);b&&this._activePointers.splice(this._activePointers.indexOf(b),1),this._state=D.NONE,v()};let m=-1;const g=b=>{if(!this._enabled||this.mouseButtons.wheel===D.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===D.ROTATE||this.mouseButtons.wheel===D.TRUCK){const w=performance.now();m-w<1e3&&this._getClientRect(this._elementRect),m=w}const E=Fh?-1:-3,O=b.deltaMode===1?b.deltaY/E:b.deltaY/(E*10),_=this.dollyToCursor?(b.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(b.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case D.ROTATE:{this._rotateInternal(b.deltaX,b.deltaY),this._isUserControllingRotate=!0;break}case D.TRUCK:{this._truckInternal(b.deltaX,b.deltaY,!1),this._isUserControllingTruck=!0;break}case D.OFFSET:{this._truckInternal(b.deltaX,b.deltaY,!0),this._isUserControllingOffset=!0;break}case D.DOLLY:{this._dollyInternal(-O,_,C),this._isUserControllingDolly=!0;break}case D.ZOOM:{this._zoomInternal(-O,_,C),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},x=b=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===K.ACTION.NONE){const E=b instanceof PointerEvent?b.pointerId:(b instanceof MouseEvent,0),O=this._findPointerById(E);O&&this._activePointers.splice(this._activePointers.indexOf(O),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("mouseup",f);return}},y=b=>{if(!this._enabled)return;if(ms(this._activePointers,Me),this._getClientRect(this._elementRect),s.copy(Me),r.copy(Me),this._activePointers.length>=2){const O=Me.x-this._activePointers[1].clientX,_=Me.y-this._activePointers[1].clientY,C=Math.sqrt(O*O+_*_);n.set(0,C);const w=(this._activePointers[0].clientX+this._activePointers[1].clientX)*.5,M=(this._activePointers[0].clientY+this._activePointers[1].clientY)*.5;r.set(w,M)}if("pointerType"in b&&b.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,(b.buttons&G.LEFT)===G.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&G.MIDDLE)===G.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&G.RIGHT)===G.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.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&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&D.DOLLY)===D.DOLLY||(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&D.ZOOM)===D.ZOOM||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},T=()=>{if(!this._enabled)return;ms(this._activePointers,Me);const b=be.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,E=b?-this._activePointers[0].deltaX:r.x-Me.x,O=b?-this._activePointers[0].deltaY:r.y-Me.y;if(r.copy(Me),((this._state&D.ROTATE)===D.ROTATE||(this._state&D.TOUCH_ROTATE)===D.TOUCH_ROTATE||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(E,O),this._isUserControllingRotate=!0),(this._state&D.DOLLY)===D.DOLLY||(this._state&D.ZOOM)===D.ZOOM){const _=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,C=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.DOLLY)===D.DOLLY?(this._dollyInternal(O*ki,_,C),this._isUserControllingDolly=!0):(this._zoomInternal(O*ki,_,C),this._isUserControllingZoom=!0)}if((this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_ZOOM)===D.TOUCH_ZOOM||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_ZOOM_ROTATE)===D.TOUCH_ZOOM_ROTATE){const _=Me.x-this._activePointers[1].clientX,C=Me.y-this._activePointers[1].clientY,w=Math.sqrt(_*_+C*C),M=n.y-w;n.set(0,w);const P=this.dollyToCursor?(r.x-this._elementRect.x)/this._elementRect.width*2-1:0,A=this.dollyToCursor?(r.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&D.TOUCH_DOLLY)===D.TOUCH_DOLLY||(this._state&D.TOUCH_DOLLY_ROTATE)===D.TOUCH_DOLLY_ROTATE||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET?(this._dollyInternal(M*ki,P,A),this._isUserControllingDolly=!0):(this._zoomInternal(M*ki,P,A),this._isUserControllingZoom=!0)}((this._state&D.TRUCK)===D.TRUCK||(this._state&D.TOUCH_TRUCK)===D.TOUCH_TRUCK||(this._state&D.TOUCH_DOLLY_TRUCK)===D.TOUCH_DOLLY_TRUCK||(this._state&D.TOUCH_ZOOM_TRUCK)===D.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(E,O,!1),this._isUserControllingTruck=!0),((this._state&D.OFFSET)===D.OFFSET||(this._state&D.TOUCH_OFFSET)===D.TOUCH_OFFSET||(this._state&D.TOUCH_DOLLY_OFFSET)===D.TOUCH_DOLLY_OFFSET||(this._state&D.TOUCH_ZOOM_OFFSET)===D.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(E,O,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},v=()=>{ms(this._activePointers,Me),r.copy(Me),this._activePointers.length===0&&this._domElement&&(this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f),this.dispatchEvent({type:"controlend"}))};this._addAllEventListeners=b=>{this._domElement=b,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),zh&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",u),this._domElement.addEventListener("wheel",g,{passive:!1}),this._domElement.addEventListener("contextmenu",x)},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",u),this._domElement.removeEventListener("wheel",g),this._domElement.removeEventListener("contextmenu",x),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",c),this._domElement.removeEventListener("pointerup",u),this._domElement.removeEventListener("mouseup",f))},this.cancel=()=>{this._state!==D.NONE&&(this._state=D.NONE,this._activePointers.length=0,v())},i&&this.connect(i),this.update(0)}static install(e){N=e.THREE,Vr=Object.freeze(new N.Vector3(0,0,0)),Di=Object.freeze(new N.Vector3(0,1,0)),ys=Object.freeze(new N.Vector3(0,0,1)),Me=new N.Vector2,W=new N.Vector3,ee=new N.Vector3,It=new N.Vector3,Ye=new N.Vector3,Xe=new N.Vector3,bt=new N.Vector3,Ur=new N.Vector3,Hr=new N.Vector3,je=new N.Spherical,si=new N.Spherical,kt=new N.Box3,Nr=new N.Box3,xs=new N.Sphere,Gr=new N.Quaternion,bs=new N.Quaternion,vs=new N.Matrix4,Bi=new N.Raycaster}static get ACTION(){return D}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 r=Ft(e,this.minAzimuthAngle,this.maxAzimuthAngle),n=Ft(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=r,this._sphericalEnd.phi=n,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(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,r=Ft(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=te(o,this._spherical.radius);if(!(s>r)&&l)return Promise.resolve();this._sphericalEnd.radius=Math.min(r,o)}else this._sphericalEnd.radius=r;this._needsUpdate=!0,i||(this._spherical.radius=this._sphericalEnd.radius);const a=!i||te(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=Ft(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||te(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),Ye.multiplyScalar(e),Xe.multiplyScalar(-i);const r=W.copy(Ye).add(Xe),n=ee.copy(this._targetEnd).add(r);return this.moveTo(n.x,n.y,n.z,s)}forward(e,i=!1){W.setFromMatrixColumn(this._camera.matrix,0),W.crossVectors(this._camera.up,W),W.multiplyScalar(e);const s=ee.copy(this._targetEnd).add(W);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return W.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+W.x,this._targetEnd.y+W.y,this._targetEnd.z+W.z,i)}moveTo(e,i,s,r=!1){this._isUserControllingTruck=!1;const n=W.set(e,i,s).sub(this._targetEnd);this._encloseToBoundary(this._targetEnd,n,this.boundaryFriction),this._needsUpdate=!0,r||this._target.copy(this._targetEnd);const a=!r||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,r=!1){const o=W.set(e,i,s).sub(this._targetEnd).normalize().multiplyScalar(-this._sphericalEnd.radius);return this.setPosition(o.x,o.y,o.z,r)}fitToBox(e,i,{cover:s=!1,paddingLeft:r=0,paddingRight:n=0,paddingBottom:a=0,paddingTop:o=0}={}){const l=[],c=e.isBox3?kt.copy(e):kt.setFromObject(e);c.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const u=zr(this._sphericalEnd.theta,Fr),f=zr(this._sphericalEnd.phi,Fr);l.push(this.rotateTo(u,f,i));const m=W.setFromSpherical(this._sphericalEnd).normalize(),g=Gr.setFromUnitVectors(m,ys),x=te(Math.abs(m.y),1);x&&g.multiply(bs.setFromAxisAngle(Di,u)),g.multiply(this._yAxisUpSpaceInverse);const y=Nr.makeEmpty();ee.copy(c.min).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setX(c.max.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setY(c.max.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setZ(c.min.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.min).setZ(c.max.z).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setY(c.min.y).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).setX(c.min.x).applyQuaternion(g),y.expandByPoint(ee),ee.copy(c.max).applyQuaternion(g),y.expandByPoint(ee),y.min.x-=r,y.min.y-=a,y.max.x+=n,y.max.y+=o,g.setFromUnitVectors(ys,m),x&&g.premultiply(bs.invert()),g.premultiply(this._yAxisUpSpace);const T=y.getSize(W),v=y.getCenter(ee).applyQuaternion(g);if(Ve(this._camera)){const b=this.getDistanceToFitBox(T.x,T.y,T.z,s);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.dollyTo(b,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(Oe(this._camera)){const b=this._camera,E=b.right-b.left,O=b.top-b.bottom,_=s?Math.max(E/T.x,O/T.y):Math.min(E/T.x,O/T.y);l.push(this.moveTo(v.x,v.y,v.z,i)),l.push(this.zoomTo(_,i)),l.push(this.setFocalOffset(0,0,0,i))}return Promise.all(l)}fitToSphere(e,i){const s=[],n=e instanceof N.Sphere?xs.copy(e):K.createBoundingSphere(e,xs);if(s.push(this.moveTo(n.center.x,n.center.y,n.center.z,i)),Ve(this._camera)){const a=this.getDistanceToFitSphere(n.radius);s.push(this.dollyTo(a,i))}else if(Oe(this._camera)){const a=this._camera,o=a.right-a.left,l=a.top-a.bottom,c=2*n.radius,u=Math.min(o/c,l/c);s.push(this.zoomTo(u,i))}return s.push(this.setFocalOffset(0,0,0,i)),Promise.all(s)}setLookAt(e,i,s,r,n,a,o=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const l=ee.set(r,n,a),c=W.set(e,i,s);this._targetEnd.copy(l),this._sphericalEnd.setFromVector3(c.sub(l).applyQuaternion(this._yAxisUpSpace)),this.normalizeRotations(),this._needsUpdate=!0,o||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const u=!o||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(u)}lerpLookAt(e,i,s,r,n,a,o,l,c,u,f,m,g,x=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const y=W.set(r,n,a),T=ee.set(e,i,s);je.setFromVector3(T.sub(y).applyQuaternion(this._yAxisUpSpace));const v=It.set(u,f,m),b=ee.set(o,l,c);si.setFromVector3(b.sub(v).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(v,g));const E=si.theta-je.theta,O=si.phi-je.phi,_=si.radius-je.radius;this._sphericalEnd.set(je.radius+_*g,je.phi+O*g,je.theta+E*g),this.normalizeRotations(),this._needsUpdate=!0,x||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const C=!x||te(this._target.x,this._targetEnd.x,this.restThreshold)&&te(this._target.y,this._targetEnd.y,this.restThreshold)&&te(this._target.z,this._targetEnd.z,this.restThreshold)&&te(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&te(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&te(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(C)}setPosition(e,i,s,r=!1){return this.setLookAt(e,i,s,this._targetEnd.x,this._targetEnd.y,this._targetEnd.z,r)}setTarget(e,i,s,r=!1){const n=this.getPosition(W),a=this.setLookAt(n.x,n.y,n.z,e,i,s,r);return this._sphericalEnd.phi=Ft(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,r=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,r||this._focalOffset.copy(this._focalOffsetEnd);const n=!r||te(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&te(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&te(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(n)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrixWorldInverse,0),Xe.setFromMatrixColumn(this._camera.matrixWorldInverse,1),bt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const r=W.set(e,i,s),n=r.distanceTo(this._camera.position),a=r.sub(this._camera.position);Ye.multiplyScalar(a.x),Xe.multiplyScalar(a.y),bt.multiplyScalar(a.z),W.copy(Ye).add(Xe).add(bt),W.z=W.z+n,this.dollyTo(n,!1),this.setFocalOffset(-W.x,W.y,-W.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,r){if(e===null){this._viewport=null;return}this._viewport=this._viewport||new N.Vector4,typeof e=="number"?this._viewport.set(e,i,s,r):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,r=!1){if(gs(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const n=e/i,a=this._camera.getEffectiveFOV()*ei,o=this._camera.aspect;return((r?n>o:n<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(gs(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*ei,s=Math.atan(Math.tan(i*.5)*this._camera.aspect)*2,r=1<this._camera.aspect?i:s;return e/Math.sin(r*.5)}getTarget(e){return(e&&e.isVector3?e:new N.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new N.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new N.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%At,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=At),this._spherical.theta+=At*Math.round((this._sphericalEnd.theta-this._spherical.theta)/At)}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,Di),this._yAxisUpSpaceInverse.copy(this._yAxisUpSpace).invert}update(e){const i=this._sphericalEnd.theta-this._spherical.theta,s=this._sphericalEnd.phi-this._spherical.phi,r=this._sphericalEnd.radius-this._spherical.radius,n=Ur.subVectors(this._targetEnd,this._target),a=Hr.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ie(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=Ii(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const f=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=Ii(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,f,1/0,e),this._needsUpdate=!0}if(ie(r))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const f=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=Ii(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,f,this.maxSpeed,e),this._needsUpdate=!0}if(ie(n.x)&&ie(n.y)&&ie(n.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const f=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;jr(this._target,this._targetEnd,this._targetVelocity,f,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ie(a.x)&&ie(a.y)&&ie(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const f=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;jr(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,f,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(Ve(this._camera)){const f=this._camera,m=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),g=ee.copy(m).cross(f.up).normalize();g.lengthSq()===0&&(g.x=1);const x=It.crossVectors(g,m),y=this._sphericalEnd.radius*Math.tan(f.getEffectiveFOV()*ei*.5),v=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,b=W.copy(this._targetEnd).add(g.multiplyScalar(this._dollyControlCoord.x*y*f.aspect)).add(x.multiplyScalar(this._dollyControlCoord.y*y));this._targetEnd.lerp(b,v)}else if(Oe(this._camera)){const f=this._camera,m=W.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(f.near+f.far)/(f.near-f.far)).unproject(f),g=ee.set(0,0,-1).applyQuaternion(f.quaternion),x=It.copy(m).add(g.multiplyScalar(-m.dot(f.up))),T=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,v=W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),b=this._targetEnd.dot(v);this._targetEnd.lerp(x,T);const E=this._targetEnd.dot(v),O=v.multiplyScalar(E-b);this._targetEnd.sub(O)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ie(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const f=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=Ii(this._zoom,this._zoomEnd,this._zoomVelocity,f,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),(!ie(this._focalOffset.x)||!ie(this._focalOffset.y)||!ie(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),Ye.setFromMatrixColumn(this._camera.matrix,0),Xe.setFromMatrixColumn(this._camera.matrix,1),bt.setFromMatrixColumn(this._camera.matrix,2),Ye.multiplyScalar(this._focalOffset.x),Xe.multiplyScalar(-this._focalOffset.y),bt.multiplyScalar(this._focalOffset.z),W.copy(Ye).add(Xe).add(bt),this._camera.position.add(W)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),W.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse),1);const u=this._needsUpdate;return u&&!this._updatedLastTime?(this._hasRested=!1,this.dispatchEvent({type:"wake"}),this.dispatchEvent({type:"update"})):u?(this.dispatchEvent({type:"update"}),ie(i,this.restThreshold)&&ie(s,this.restThreshold)&&ie(r,this.restThreshold)&&ie(n.x,this.restThreshold)&&ie(n.y,this.restThreshold)&&ie(n.z,this.restThreshold)&&ie(a.x,this.restThreshold)&&ie(a.y,this.restThreshold)&&ie(a.z,this.restThreshold)&&ie(o,this.restThreshold)&&!this._hasRested&&(this._hasRested=!0,this.dispatchEvent({type:"rest"}))):!u&&this._updatedLastTime&&this.dispatchEvent({type:"sleep"}),this._updatedLastTime=u,this._needsUpdate=!1,u}toJSON(){return JSON.stringify({enabled:this._enabled,minDistance:this.minDistance,maxDistance:ti(this.maxDistance),minZoom:this.minZoom,maxZoom:ti(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:ti(this.maxPolarAngle),minAzimuthAngle:ti(this.minAzimuthAngle),maxAzimuthAngle:ti(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:W.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),r=W.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=ii(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=ii(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=ii(s.maxPolarAngle),this.minAzimuthAngle=ii(s.minAzimuthAngle),this.maxAzimuthAngle=ii(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),je.setFromVector3(r.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(je.theta,je.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 r=i.lengthSq();if(r===0)return e;const n=ee.copy(i).add(e),o=this._boundary.clampPoint(n,It).sub(n),l=o.lengthSq();if(l===0)return e.add(i);if(l===r)return e;if(s===0)return e.add(i).add(o);{const c=1+s*l/i.dot(o);return e.add(ee.copy(i).multiplyScalar(c)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(Ve(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*ei,r=Math.tan(s*.5)*i,n=r*e.aspect;this._nearPlaneCorners[0].set(-n,-r,0),this._nearPlaneCorners[1].set(n,-r,0),this._nearPlaneCorners[2].set(n,r,0),this._nearPlaneCorners[3].set(-n,r,0)}else if(Oe(this._camera)){const e=this._camera,i=1/e.zoom,s=e.left*i,r=e.right*i,n=e.top*i,a=e.bottom*i;this._nearPlaneCorners[0].set(s,n,0),this._nearPlaneCorners[1].set(r,n,0),this._nearPlaneCorners[2].set(r,a,0),this._nearPlaneCorners[3].set(s,a,0)}}_collisionTest(){let e=1/0;if(!(this.colliderMeshes.length>=1)||gs(this._camera,"_collisionTest"))return e;const s=W.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);vs.lookAt(Vr,s,this._camera.up);for(let r=0;r<4;r++){const n=ee.copy(this._nearPlaneCorners[r]);n.applyMatrix4(vs);const a=It.addVectors(this._target,n);Bi.set(a,s),Bi.far=this._spherical.radius+1;const o=Bi.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 N.Sphere){const s=i,r=s.center;kt.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&kt.expandByObject(a)}),kt.getCenter(r);let n=0;return e.traverseVisible(a=>{if(!a.isMesh)return;const o=a,l=o.geometry.clone();if(l.applyMatrix4(o.matrixWorld),l.isBufferGeometry){const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}else{const u=l.attributes.position;for(let f=0,m=u.count;f<m;f++)W.fromBufferAttribute(u,f),n=Math.max(n,r.distanceToSquared(W))}}),s.radius=Math.sqrt(n),s}}var He=(h=>(h[h.Orbit=0]="Orbit",h[h.FirstPerson=1]="FirstPerson",h[h.Plan=2]="Plan",h))(He||{});class Fn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=He.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.ROTATE,middle:K.ACTION.DOLLY,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_ROTATE,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.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 d.Vector3;t.getSize(i);const s=i.length();e.minDistance=1,e.maxDistance=s*10,e.minZoom=3}}class zn{constructor(t){p(this,"mode");p(this,"cameraManager");this.mode=He.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:K.ACTION.TRUCK,middle:K.ACTION.TRUCK,right:K.ACTION.TRUCK,wheel:Ve(t)?K.ACTION.DOLLY:Oe(t)?K.ACTION.ZOOM:K.ACTION.NONE},e.touches={one:K.ACTION.TOUCH_TRUCK,two:Ve(t)?K.ACTION.TOUCH_DOLLY_TRUCK:Oe(t)?K.ACTION.TOUCH_ZOOM_TRUCK:K.ACTION.NONE,three:K.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 Dt=50,ws=new d.Vector3;class jh{constructor(t){p(this,"viewer");p(this,"perspectiveCamera");p(this,"orthographicCamera");p(this,"activeCamera");p(this,"cameraControls");p(this,"previousDistance");p(this,"previousAzimuthRotateSpeed");p(this,"previousPolarRotateSpeed");p(this,"previousDollySpeed");p(this,"previousTruckSpeed");p(this,"previousMouseLeft");p(this,"enableKeyDown");p(this,"controlsMap");p(this,"activeControls");p(this,"projection");p(this,"anchor");p(this,"onKeyDown");p(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=K.ACTION.NONE,this.enableKeyDown=!0,this.projection=$e.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const r=this.cameraControls,n=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Be.Viewer3d||this.viewer.name===Be.BimTilesViewer;switch(s.code){case"ArrowLeft":a?r.rotate(.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(n,0,!0);break;case"ArrowRight":a?r.rotate(-.1,0,!0):this.viewer.name===Be.Viewer2d&&r.truck(-n,0,!0);break;case"ArrowUp":a?r.rotate(0,.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,n,!0);break;case"ArrowDown":a?r.rotate(0,-.1,!0):this.viewer.name===Be.Viewer2d&&r.truck(0,-n,!0);break;case"KeyW":a&&(Oe(this.activeCamera)?r.zoom(.01,!0):r.dolly(1,!0));break;case"KeyA":a&&r.truck(-n,0,!0);break;case"KeyS":a&&(Oe(this.activeCamera)?r.zoom(-.01,!0):r.dolly(-1,!0));break;case"KeyD":a&&r.truck(n,0,!0);break;case"KeyQ":a&&r.truck(0,-n,!0);break;case"KeyE":a&&r.truck(0,n,!0);break}},this.onChange=()=>{this.viewer.enableRender()},this.viewer=t;const e=t.viewerContainer,i=e.clientWidth/e.clientHeight;this.perspectiveCamera=new d.PerspectiveCamera(hn,i,Ui,Hi),this.orthographicCamera=new d.OrthographicCamera(Dt*i/-2,Dt*i/2,Dt/2,Dt/-2,Ui,Hi),this.activeCamera=this.perspectiveCamera,this.setupCameras(),K.install({THREE:d}),this.cameraControls=new K(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[He.Orbit]:new Fn(this),[He.Plan]:new zn(this)},this.activeControls=this.controlsMap[He.Orbit],this.setupControls(),this.setProjection($e.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=pe.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=Dt*i/2,this.orthographicCamera.top=Dt/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 d.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(re.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===He.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=$e.Orthographic}getDims(){const t=new d.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new d.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:r,clientHeight:n}=this.viewer.viewerContainer,a=r/n,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=K.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=K.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=K.ACTION.DOLLY,this.activeCamera=e,this.projection=$e.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(ws)}getPosition(){return this.cameraControls.getPosition(ws)}adjustCameraByBBox(t){const e=this.camera.near,i=this.camera.far,s=new d.Vector3;t.getSize(s);const r=s.length(),n=5,a=r/n,o=r*n;if(e>a||i<o){const l=c=>z.numberToString(c);S.info("[Viewer] BBox's longest side is: "+l(r)),e>a&&(S.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(S.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=K.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 d.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new d.Box3().setFromObject(t),i=new d.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===$e.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(ws)}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=Ui,far:s=Hi,up:r=new d.Vector3(0,1,0),zoom:n=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(r.x,r.y,r.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(n),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 Ot=class Ot extends En{tableName(){return"fonts"}static instance(){return!Ot._instance&&(Ot._instance=new Ot),Ot._instance}query(t){let e;return new Promise((i,s)=>{super.query(r=>{if(!r){i(e);return}!r.value||r.value.fileName!==t||(e=r.value)},r=>{s(r)})})}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)})})}};p(Ot,"_instance");let Yt=Ot;var jn=(h=>(h[h.Horizontal=0]="Horizontal",h[h.Vertical=1]="Vertical",h[h.All=2]="All",h))(jn||{}),Ee=(h=>(h[h.Shapes=0]="Shapes",h[h.Bigfont=1]="Bigfont",h[h.Unifont=2]="Unifont",h))(Ee||{});class Vn extends Sa.Font{constructor(e,i){super(i);p(this,"info");p(this,"orientation");p(this,"baseUp");p(this,"baseDown");p(this,"fileHeader");p(this,"fileVersion");p(this,"fileName");p(this,"data");p(this,"order");p(this,"unsupportedChars");this.info="",this.orientation=jn.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)=>{Yt.instance().save(e,()=>{console.log("[FontFile] Saved '"+this.fileName+"' ("+this.fileHeader+") to indexedDb"),i()},r=>s("[FontFile] Failed to save '"+this.fileName+"' ("+this.fileHeader+") to indexedDb! "+r))})}async getFontDataByIndexedDb(){return Yt.instance().query(this.fileName)}releaseFontData(){this.data={}}}class vt extends Vn{constructor(e,i){super(e,i);p(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=qr(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return qr("?",e,0,0,this.data)?.path}parseTTF(e){function i(r,n){const a=Math.round,o={},l=1e5/((r.unitsPerEm||2048)*72),c=r.encoding.cmap.glyphIndexMap,u=Object.keys(c);for(let f=0;f<u.length;f++){const m=u[f],g=r.glyphs.glyphs[c[m]];if(m!==void 0){const x={ha:a(g.advanceWidth*l),x_min:a(g.xMin*l),x_max:a(g.xMax*l),o:""};n&&(g.path.commands=s(g.path.commands)),g.path.commands.forEach(function(y){y.type.toLowerCase()==="c"&&(y.type="b"),x.o+=y.type.toLowerCase()+" ",y.x!==void 0&&y.y!==void 0&&(x.o+=a(y.x*l)+" "+a(y.y*l)+" "),y.x1!==void 0&&y.y1!==void 0&&(x.o+=a(y.x1*l)+" "+a(y.y1*l)+" "),y.x2!==void 0&&y.y2!==void 0&&(x.o+=a(y.x2*l)+" "+a(y.y2*l)+" ")}),o[String.fromCodePoint(g.unicode)]=x}}return{glyphs:o,familyName:r.getEnglishName("fullName"),ascender:a(r.ascender*l),descender:a(r.descender*l),underlinePosition:r.tables.post.underlinePosition,underlineThickness:r.tables.post.underlineThickness,boundingBox:{xMin:r.tables.head.xMin,xMax:r.tables.head.xMax,yMin:r.tables.head.yMin,yMax:r.tables.head.yMax},resolution:1e3,original_font_information:r.tables.name}}function s(r){const n=[];let a;r.forEach(function(l){l.type.toLowerCase()==="m"?(a=[l],n.push(a)):l.type.toLowerCase()!=="z"&&a.push(l)});const o=[];return n.forEach(function(l){const c={type:"m",x:l[l.length-1].x,y:l[l.length-1].y};o.push(c);for(let u=l.length-1;u>0;u--){const f=l[u],m={type:f.type};f.x2!==void 0&&f.y2!==void 0?(m.x1=f.x2,m.y1=f.y2,m.x2=f.x1,m.y2=f.y1):f.x1!==void 0&&f.y1!==void 0&&(m.x1=f.x1,m.y1=f.y1),m.x=l[u-1].x,m.y=l[u-1].y,o.push(m)}}),o}return i(Ca.parse(e),this.reversed)}}function qr(h,t,e,i,s){const r=s.glyphs[h];if(!r)return;const n=new d.ShapePath;let a,o,l,c,u,f,m,g;if(r.o){const x=r._cachedOutline||(r._cachedOutline=r.o.split(" "));for(let y=0,T=x.length;y<T;)switch(x[y++]){case"m":a=x[y++]*t+e,o=x[y++]*t+i,n.moveTo(a,o);break;case"l":a=x[y++]*t+e,o=x[y++]*t+i,n.lineTo(a,o);break;case"q":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,n.quadraticCurveTo(u,f,l,c);break;case"b":l=x[y++]*t+e,c=x[y++]*t+i,u=x[y++]*t+e,f=x[y++]*t+i,m=x[y++]*t+e,g=x[y++]*t+i,n.bezierCurveTo(u,f,m,g,l,c);break}}return{offsetX:r.ha*t,path:n}}class J{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 n=0;n<t.length;n++)e.push(J.GetBytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][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 n=0;n<t.length;n++)e.push(this.Get1Bytes(t[n]));let i=0;for(let n=0;n<e.length;n++)i+=e[n].length;const s=new Uint8Array(i);let r=0;for(let n=0;n<e.length;n++)for(let a=0;a<e[n].length;a++)s[r++]=e[n][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 r=0;r<i;r++)s+=String.fromCharCode(t[e+r]||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 r=0;r<i;r++)s[r]=t[e+r]||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 Zi;function Vh(){const h=[[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,r,n,a]of h)for(let o=n;o<=a;o++)if(o!==127)for(let l=s;l<=r;l++)t[e++]=o<<8|l;const i=new TextDecoder("gbk").decode(t);for(Zi=new Uint16Array(65536),e=0;e<i.length;e++)Zi[i.charCodeAt(e)]=t[e]}function Uh(h){!Zi&&Vh();const t=new Uint8Array(h.length*2);let e=0;for(let i=0;i<h.length;i++){const s=h.charCodeAt(i);if(s<128)t[e++]=s;else{const r=Zi[s];t[e++]=r&255,t[e++]=r>>8}}return t.subarray(0,e)}new d.Vector2;class gi extends d.Shape{constructor(e,i){super();p(this,"width");p(this,"lastPoint");p(this,"polylines");p(this,"bounds");this.width=0,this.bounds=new d.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 r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().add(e))}i.push(n)}return new gi(this.lastPoint,i)}transform(e){const i=[];for(let s=0;s<this.polylines.length;s++){const r=this.polylines[s],n=[];for(let a=0;a<r.length;a++){const o=r[a];n.push(o.clone().applyMatrix3(e))}i.push(n)}return new gi(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let n=0;n<e.length;n++){const a=e[n];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 r=0;const n=new d.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const c=o[l];i.push(c.x,c.y,0),l===o.length-1||s.push(r,r+1),r++}}return n.userData={advanceWidth:this.width},n.setAttribute("position",new d.Float32BufferAttribute(i,3)),n.setIndex(s),n}}const Ze=class Ze{static parserHeader(t,e){let i="",s=!1,r=0;const n=!0;for(;n;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[r]?r++:(s=!1,r=0);else{if(o===e[r]){s=!0,r++;continue}i+=o}if(s&&r===e.length)break}return i}static getCode(t){const e=Uh(t);return e.length<2?e[0]:e.length<4?J.ToUInt16(e,0):J.ToUInt32(e,0)}static parserCode(t,e,i){let s=new d.Vector2;const r=[];let n=[];const a=[];let o=!1;for(let l=0;l<e.length;l++){const c=e[l];switch(c){case 0:break;case 1:o=!0,n.push(s.clone());break;case 2:o=!1,n.length>1?(r.push(n.slice()),n=[]):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(),n.length>1&&(r.push(n.slice()),n=[]),o&&n.push(s.clone());break;case 7:{let u=0,f,m=i*t.baseUp;const g=s.clone();switch(n.length>1&&(r.push(n.slice()),n=[]),t.fontType){case Ee.Shapes:l++,u=e[l];break;case Ee.Bigfont:l++,u=e[l],u==0&&(l++,u=J.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),g.x=e[l++]*i,g.y=e[l++]*i,m=e[l]*i);break;case Ee.Unifont:l+=2,u=J.ToUInt16(new Uint8Array([e[l-1],e[l]]),0);break}u!==0&&(f=t.getGraphicDataByCodeWithOffset(u,m,g),f&&(r.push(...f.polylines.slice()),s=f.lastPoint.clone()))}break;case 8:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l]),u.y=J.byteTosbyte(e[++l]),s.add(u.multiplyScalar(i)),o&&n.push(s.clone())}break;case 9:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l]),f.y=J.byteTosbyte(e[++l]),!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;s.add(f.multiplyScalar(i)),o&&n.push(s.clone())}break;case 10:{const u=e[++l]*i,f=J.byteTosbyte(e[++l]),m=(f&112)>>4;let g=f&7;g==0&&(g=8);const x=Math.PI/4;let y=x*g,T=Ze.CIRCLE_SPAN;f<0&&(T=-T,y=-y);const v=x*m,b=v+y,E=s.clone().sub(new d.Vector2(Math.cos(v)*u,Math.sin(v)*u));if(s=E.clone().add(new d.Vector2(Math.cos(b)*u,Math.sin(b)*u)),o){let O=v;const _=!0;for(;_&&(O+=T,!!Number.isFinite(O));)if(f>=0&&O<b||f<0&&O>b)n.push(E.clone().add(new d.Vector2(u*Math.cos(O),u*Math.sin(O))));else break;n.push(s.clone())}}break;case 11:{const u=e[++l],f=e[++l],m=e[++l],g=e[++l],x=(m*255+g)*i,y=J.byteTosbyte(e[++l]),T=(y&112)>>4;let v=y&7;v==0&&(v=8),f!=0&&v--;const b=Math.PI/4;let E=b*v,O=Ze.CIRCLE_SPAN,_=1;y<0&&(O=-O,E=-E,_=-1);let C=b*T,w=C+E;C+=b*u/256*_,w+=b*f/256*_;const M=s.clone().sub(new d.Vector2(x*Math.cos(C),x*Math.sin(C)));if(s=M.clone().add(new d.Vector2(x*Math.cos(w),x*Math.sin(w))),o){let P=C;const A=!0;for(;A&&(P+=O,!!Number.isFinite(P));)if(y>0&&P<w||y<0&&P>w)n.push(M.clone().add(new d.Vector2(x*Math.cos(P),x*Math.sin(P))));else break;n.push(s.clone())}}break;case 12:{const u=new d.Vector2;u.x=J.byteTosbyte(e[++l])*i,u.y=J.byteTosbyte(e[++l])*i;let f=J.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?n.push(s.clone().add(u)):n.push(Ze.generateArcPoints(s,u,f/127))),s.add(u)}break;case 13:for(;;){const f=new d.Vector2;if(f.x=J.byteTosbyte(e[++l])*i,f.y=J.byteTosbyte(e[++l])*i,!Number.isFinite(f.x)||!Number.isFinite(f.y)||f.x==0&&f.y==0)break;let m=J.byteTosbyte(e[++l]);m<-127&&(m=-127),o&&(m==0?n.push(s.clone().add(f)):n.push(Ze.generateArcPoints(s.clone(),f,m/127))),s.add(f)}break;case 14:l=Ze.skipCode(t,e,++l);break;default:if(c>15){const u=(c&240)>>4,f=c&15,m=new d.Vector2;switch(f){case 0:m.x=1;break;case 1:m.x=1,m.y=.5;break;case 2:m.x=1,m.y=1;break;case 3:m.x=.5,m.y=1;break;case 4:m.y=1;break;case 5:m.x=-.5,m.y=1;break;case 6:m.x=-1,m.y=1;break;case 7:m.x=-1,m.y=.5;break;case 8:m.x=-1;break;case 9:m.x=-1,m.y=-.5;break;case 10:m.x=-1,m.y=-1;break;case 11:m.x=-.5,m.y=-1;break;case 12:m.y=-1;break;case 13:m.x=.5,m.y=-1;break;case 14:m.x=1,m.y=-1;break;case 15:m.x=1,m.y=-.5;break}s.add(m.multiplyScalar(u*i)),o&&n.push(s.clone())}break}}return new gi(s,r)}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 Ee.Shapes:i++;break;case Ee.Bigfont:i++,e[i]==0&&(i+=6);break;case Ee.Unifont:i+=2;break}break;case 8:i+=2;break;case 9:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break}break;case 10:i+=2;break;case 11:i+=5;break;case 12:i+=3;break;case 13:for(;;){const n=e[++i],a=e[++i];if(n===void 0||a===void 0||n==0&&a==0)break;e[++i]}break}return i}static generateArcPoints(t,e,i){const s=t.clone().add(e),r=i<0,n=!1;i=Math.abs(i);const a=e.length()/2,o=a*i,l=2*Math.atan(1/i),c=new d.Vector2(e.y,-e.x);c.normalize(),c.multiplyScalar(o);const u=Math.abs(a/Math.sin(l/2)),f=t.add(e.divideScalar(2));n!==r?f.add(c):f.sub(c);const m=t.sub(f),g=s.sub(f);let x=Math.atan2(m.y,m.x);const y=Math.atan2(g.y,g.x);let T=Ze.CIRCLE_SPAN;r?(T=-T,x<y&&(x+=2*Math.PI)):x>y&&(x-=2*Math.PI);let v=x;const b=!0;for(;b;){if(v+=T,!r&&v<y||r&&v>y)return f.add(new d.Vector2(u*Math.cos(v),u*Math.sin(v)));break}return s}};p(Ze,"FILE_STOP_FLAG",["\r",`
1532
- `,""]),p(Ze,"CIRCLE_SPAN",Math.PI/18);let lt=Ze;const Ms={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]]]},Wr=new d.Matrix3,ui=class ui extends Vn{constructor(e,i){super(e,i);p(this,"isExtend");p(this,"isUniCode");p(this,"isEmbedded");p(this,"fontType");p(this,"textShapesCache");p(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=Ee.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new vi(i),r=lt.parserHeader(s,lt.FILE_STOP_FLAG),n=r.split(" ");switch(n[1]){case"shapes":this.parseShapeFont(s),this.fontType=Ee.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=Ee.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=Ee.Unifont;break}this.fileHeader=n[0],this.fileVersion=n[2]}else this.setFontFile(i)}generateShapes(e,i){const s=[];let r=0;for(let n=0;n<e.length;n++){const a=e[n];if(a===" "){r+=i;continue}const o=this.getCharShape(a,i);if(!o){r+=i,this.addUnsupportedChar(a);continue}s.push(o.offset(new d.Vector2(r,0))),r+=o.width}return s}getCharShape(e,i){let s=lt.getCode(e);s===0&&(s=e.charCodeAt(0));const r=this.getGraphicDataByCode(s,i);if(!r)return this.addUnsupportedChar?.(e),null;if(r.polylines&&r.polylines.length===0&&(r.width=i*.8),typeof r.width!="number"||r.width<=0){const n=r,a=n.xMin!=null?n.xMin:0,o=n.xMax!=null?n.xMax:0;r.width=Math.max(.1,o-a)}return r}getGraphicDataByCode(e,i){const s=e+"_"+i;if(this.textShapesCache.has(s))return this.textShapesCache.get(s);if(e===0)return;const r=this.data;let n;if(!this.graphicData.has(e)){if(r[e]){const a=r[e],o=ui.DEFAULT_SIZE/this.baseUp;n=lt.parserCode(this,a,o),this.graphicData.set(e,n)}else if(Ms[e]){const a=[];for(let o=0;o<Ms[e].length;o++)a.push(Ms[e][o].map(l=>new d.Vector2(l[0],l[1])));n=new gi(new d.Vector2,a),this.graphicData.set(e,n)}}if(this.graphicData.has(e)){const a=i/ui.DEFAULT_SIZE;Wr.identity().scale(a,a),n=this.graphicData.get(e).transform(Wr)}return n}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){J.ToInt16(e.readBytes(2),0);const i=J.ToInt16(e.readBytes(2),0),s=J.ToInt16(e.readBytes(2),0);for(let l=0;l<s;l++)e.readBytes(2),e.readBytes(2);const r=[];for(let l=0;l<i;l++){const c=e.readBytes(8),u=J.ToUInt16(new Uint8Array([c[1],c[0]]),0),f=J.ToUInt16(c,2),m=J.ToUInt32(c,4);u===0&&f===0&&m===0||r.push({code:u,length:f,offset:m})}const n={};for(const l of r)e.setPosition(l.offset),n[l.code]=e.readBytes(l.length);const a=n[0];this.info=Hh(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=n}parseUniFont(e){const i=J.ToInt32(e.readBytes(4),0),s=J.ToInt16(e.readBytes(2),0),r=e.readBytes(s);this.info=new TextDecoder().decode(r);let n=this.info.indexOf("\0");this.baseUp=r[++n],this.baseDown=r[++n],this.orientation=r[++n],this.isUniCode=r[++n]==0,this.isEmbedded=r[++n]==0;const a={};for(let o=0;o<i-1;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(c)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=J.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=J.ToUInt16(e.readBytes(2),0),c=J.ToUInt16(e.readBytes(2),0);s.push({code:l,length:c})}const r={};for(const o of s)r[o.code]=e.readBytes(o.length);const n=r[0];this.info=new TextDecoder().decode(n);let a=this.info.indexOf("\0");this.baseUp=n[++a],this.baseDown=n[++a],this.orientation=n[++a],this.data=r}getNotFoundTextShape(e){let i=0;return this.fontType===Ee.Bigfont&&(i=lt.getCode("?")),this.fontType===Ee.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||Ee.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()}};p(ui,"DEFAULT_SIZE",12);let ht=ui;function Hh(h){let t,e,i,s,r;t="";const n=h.length;for(e=0;e<n;)switch(i=h[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=h[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=h[e++],r=h[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(r&63)<<0);break}return t}class Ke{constructor(){p(this,"loader");p(this,"fontMap");p(this,"fileNames");p(this,"unsupportedChars");p(this,"missingFonts");p(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new d.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:Ke.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,r=[],n=[];typeof i=="object"?(r=Object.keys(i),n=Object.values(i),s=r[0]):s=Ke.getFileName(i.toLowerCase());let a;if(r.length){const o=r[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new ht(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(n[0]);a=new vt(s,l)}}else if(Ke.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new vt(s,o)}else if(Ke.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ht(s,o)}else if(Ke.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new vt(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){S.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){S.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[,n]of this.fontMap)if(n.getCharShape(t,i)){s=n;break}}let r=s?.getCharShape(t,i);if(!r)for(const[,n]of this.fontMap){if(n===s)continue;const a=n.getCharShape(t,i);if(a){s=n,r=a;break}}if(r){if(s instanceof ht)return r.toThreeGeometry();if(s instanceof vt)return new Ta.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 r=s.getNotFoundTextShape(t);if(r){e=r,i=s;break}}if(i instanceof ht)return e.toThreeGeometry();if(i instanceof vt)return new d.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 r=null;typeof s=="object"?r=Object.keys(s)[0]:r=Ke.getFileName(s.toLowerCase());const n=await Yt.instance().query(r);if(n)e=!0;else{e=!1;break}if(n.codes!==void 0){e=!1;break}}return e}async getFontFromIndexeddb(){if(this.fontMap.size!==0)return;const t=(await Yt.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:r}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let n;r?n=new ht(s,i):n=new vt(s,i),this.fontMap.set(s,n)}S.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){S.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 ht}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 z.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(z.getExtension(t).toUpperCase())}static isJsonFile(t){return z.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class Nh{constructor(t){p(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 c=Object.values(i);for(let u=c.length-1;u>=0;--u){const f=c[u].indexes[0],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}for(let u=s.length-1;!l&&u>=0;--u){const f=s[u],m=t.children[f];if(this.geometryEquals(o.geometry,m.geometry)&&de.materialsEquals(o.material,m.material)){!i[f]&&(i[f]={indexes:[f]},this.removeFromArray(s,f)),i[f].indexes.push(a),l=!0;break}}!l&&s.push(a)}if(Object.keys(i).length<=0)return;const r=[],n=[];Object.values(i).forEach(a=>{const o=a.indexes;n.push(...o);const l=t.children[o[0]];let c=l.material;if(c instanceof d.Material)c=c.clone();else if(Array.isArray(c)){const f=[];c.forEach(m=>f.push(m.clone())),c=f}const u=new d.InstancedMesh(l.geometry,c,o.length);u.name="[Instanced] "+l.name;for(let f=0;f<o.length;++f){const m=o[f],g=t.children[m];g.updateMatrix(),u.setMatrixAt(f,g.matrix)}u.matrixAutoUpdate=Ne,u.updateMatrix(),r.push(u)}),n.sort((a,o)=>o-a),n.forEach(a=>t.remove(t.children[a])),r.forEach(a=>{a.parent=t,t.children.push(a)}),t.updateMatrix(),console.log("[Inst] "+n.length+"(out of "+e+") objects instanced to "+r.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 U.geometriesEqual(t,e)}}class Un{constructor(){p(this,"TIMEOUT","timeout");p(this,"INTERVAL","interval");p(this,"timeoutMap",{});p(this,"intervalMap",{})}run(t=this.INTERVAL,e,i=16.7){const s=Date.now;let r=s(),n=r;const a=Symbol(""),o=()=>{this.setIdMap(a,t,o),n=s(),n-r>=i&&(t===this.intervalMap&&(r=s(),n=r),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 Ki{constructor(t){p(this,"buffer");p(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],r=t&7;e?this.u8[i]=s|128>>r:this.u8[i]=s&~(128>>r)}getInt12(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=this.u8[e+2],n=t%8,a=8-n,o=Math.min(12-a,8),l=Math.max(12-a-o,0),c=~(255<<a),u=255<<8-o,f=255<<8-l;return i&=c,s&=u,r&=f,((i<<16)+(s<<8)+r>>12-n)-2048}setInt12(t,e){e+=2048;var i=t/8|0,s=t%8,r=e<<12-s,n=(r&16711680)>>16,a=(r&65280)>>8,o=r&255,l=8-s,c=Math.min(12-l,8),u=Math.max(12-l-c,0),f=255<<l;this.u8[i]=(this.u8[i]&f)+n;var m=~(255<<8-c);this.u8[i+1]=(this.u8[i+1]&m)+a;var g=~(255<<8-u);this.u8[i+2]=(this.u8[i+2]&g)+o}getInt6(t){var e=t/8|0,i=this.u8[e],s=this.u8[e+1],r=t%8,n=8-r,a=Math.max(6-n,0),o=~((255<<n)+(255>>8-(2-r))),l=255<<8-a;return i&=o,s&=l,((i<<8)+s>>10-r)-32}setInt6(t,e){e+=32;var i=t/8|0,s=t%8,r=e<<10-s,n=(r&65280)>>8,a=r&255,o=8-s,l=Math.max(6-o,0),c=(255<<o)+(255>>8-(2-s));this.u8[i]=(this.u8[i]&c)+n;var u=~(255<<8-l);this.u8[i+1]=(this.u8[i+1]&u)+a}test(){var t=new ArrayBuffer(3),e=new Ki(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 ni=(h=>(h[h.NULL=0]="NULL",h[h.POINT=1]="POINT",h[h.POLYLINE=3]="POLYLINE",h[h.POLYGON=5]="POLYGON",h))(ni||{});class Gh{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 r={};r.number=i.getInt32(s,!1),s+=4,r.length=i.getInt32(s,!1),s+=4;try{r.shape=this.parseShape(i,s,r.length)}catch(n){console.log(n,r)}s+=r.length*2,e.records.push(r)}return e}parseShape(t,e,i){var s=0,r=null,n={};switch(n.type=t.getInt32(e,!0),e+=4,n.type){case 0:break;case 1:n.content={x:t.getFloat64(e,!0),y:t.getFloat64(e+8,!0)};break;case 3:case 5:for(r=n.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<r.parts.length;s++)r.parts[s]=t.getInt32(e,!0),e+=4;for(s=0;s<r.points.length;s++)r.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: "+n.type+":"+ +n.type);default:throw new Error("Unknown shape type at "+(e-4)+": "+n.type)}return n}}class qh{constructor(){p(this,"LINE_MATERIAL");p(this,"MESH_MATERIAL");this.LINE_MATERIAL=new d.LineBasicMaterial({color:0,linewidth:2,opacity:.8,transparent:!0}),this.MESH_MATERIAL=new d.MeshBasicMaterial({color:1926655,opacity:.8,transparent:!0})}createModel(t){for(var e=[],i=[],s=0;s<t.records.length;s++){var r=t.records[s].shape;if(r.type===ni.POLYLINE||r.type===ni.POLYGON)for(var n=r.content.points,a=r.content.parts,o=0;o<a.length;o++){const g=[];for(var l=a[o],c=a[o+1]||n.length/2;l<c;l++){var u=n[l*2],f=n[l*2+1];g.push(new d.Vector3(u,f,0))}if(r.type===ni.POLYGON){const x=d.ShapeUtils.triangulateShape(g,[]),y=[];x.forEach(b=>y.push(...b));const T=new d.BufferGeometry;T.setFromPoints(g),T.setIndex(y),e.push(T);const v=new d.BufferGeometry;g.length>2&&!g[0].equals(g[g.length-1])&&g.push(g[0]),v.setFromPoints(g),i.push(v)}else{const x=new d.BufferGeometry;x.setFromPoints(g),i.push(x)}}}for(var m=new d.Object3D,s=0;s<i.length;s++)m.add(new d.Line(i[s],this.LINE_MATERIAL));for(var s=0;s<e.length;s++)m.add(new d.Mesh(e[s],this.MESH_MATERIAL));return console.log("parsed",e.length,i.length),m}loadCompressed(t){for(var e=this.deltaDecode6(t),i=[],s=[],r=0;r<e.length;r++){let u=[];if(e[r]===-32768){for(var n=[],a=1;a<u.length;a++)!(u[a-1].x==u[a].x&&u[a-1].y==u[a].y)&&n.push(u[a]);const f=new d.BufferGeometry;f.setFromPoints(n),i.push(f),u=[];continue}var o=e[r]*180/32767,l=e[r+1]*180/32767;r++,u.push(new d.Vector3(o,l,0))}for(var c=new d.Object3D,r=0;r<s.length;r++)c.add(new d.Line(s[r],this.LINE_MATERIAL));for(var r=0;r<i.length;r++)c.add(new d.Mesh(i[r],this.MESH_MATERIAL));return console.log("parsed compressed",i.length,s.length),c}compress(t){for(var e=[],i=0;i<t.records.length;i++){var s=t.records[i].shape;if(s.type===ni.POLYGON)for(var r=s.content.points,n=s.content.parts,a=0;a<n.length;a++){for(var o=n[a],l=n[a+1]||r.length/2;o<l;o++){var c=r[o*2],u=r[o*2+1];e.push(c/180*32767,u/180*32767)}e.push(-32768)}}var f=new Int16Array(e);console.log("16-bit quantized byteLength",f.buffer.byteLength);var m=this.deltaEncode6(f);return console.log("delta-encoded byteLength",m.byteLength),m}deltaEncode(t){for(var e=[],i=[],s=[],r=0,n=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?(r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):Math.abs(r-t[o])>1023||Math.abs(n-t[o+1])>1023?(i.push(s),a+=1,s=[],r=t[o],n=t[o+1],s.push(r,n),a+=4,o++):(s.push((t[o]-r)/8,(t[o+1]-n)/8),r+=((t[o]-r)/8|0)*8,n+=((t[o+1]-n)/8|0)*8,a+=2,o++)}return this.storeDeltas(a,e)}deltaEncode6(t){var e=[],i=[],s=[],r=0,n=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?(r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):Math.abs(r-t[a])>31||Math.abs(n-t[a+1])>31?(i.push(s),o+=1,s=[],r=t[a],n=t[a+1],s.push(r,n),o+=4,a++):(s.push(t[a]-r,t[a+1]-n),r+=t[a]-r,n+=t[a+1]-n,o+=2,a++)}return this.storeDeltas6(o,e)}storeDeltas(t,e){for(var i=new ArrayBuffer(t),s=new DataView(i),r=0,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt16(r,l[0]),r+=2,s.setInt16(r,l[1]),r+=2;for(var c=2;c<l.length;c++)s.setInt8(r++,l[c]);s.setInt8(r,-128),r+=1}s.setInt16(r,-32768),r+=2}return i}deltaDecode(t){for(var e=new DataView(t),i=0,s=[];i<t.byteLength;){var r=e.getInt16(i);if(i+=2,r===-32768){s.push(-32768);continue}var n=e.getInt16(i);for(i+=2,s.push(r,n);i<t.byteLength;){var a=e.getInt8(i);if(i++,a==-128)break;var o=e.getInt8(i);i++,r+=a*8,n+=o*8,s.push(r,n)}}return s}storeDeltas6(t,e){for(var i=new ArrayBuffer(Math.ceil(t*.75)+4),s=new Ki(i),r=32,n=0;n<e.length;n++){for(var a=e[n],o=0;o<a.length;o++){var l=a[o];s.setInt12(r,l[0]),r+=12,s.setInt12(r,l[1]),r+=12;for(var c=2;c<l.length;c++)s.setInt6(r,l[c]),r+=6;s.setInt6(r,-32),r+=6}s.setInt12(r,-2048),r+=12}return new DataView(i).setUint32(0,r),i}deltaDecode6(t){for(var e=new DataView(t).getUint32(0),i=new Ki(t),s=32,r=[];s<e;){var n=i.getInt12(s);if(s+=12,n===-2048){r.push(-2048);continue}var a=i.getInt12(s);for(s+=12,r.push(n,a);s<e;){var o=i.getInt6(s);if(s+=6,o===-32)break;var l=i.getInt6(s);s+=6,n+=o,a+=l,r.push(n,a)}}for(var c=0;c<r.length;c++)r[c]*=16;return r}}class Wh{async load(t,e,i,s){this.updateProgress(i,0);const r=new XMLHttpRequest;r.responseType="arraybuffer",r.onload=()=>{this.updateProgress(i,50);const n=new Gh,a=n.parse(r.response),o=new qh().createModel(a);this.updateProgress(i,100),e(o)},r.onerror=s,r.open("GET",t),r.send(null)}updateProgress(t,e){if(t){const i={lengthComputable:!0,loaded:e,total:100};t(new ProgressEvent("progress",i))}}}const fi=class fi{constructor(t){p(this,"gltfLoader");p(this,"font");p(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")?(S.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 r=e?.toLowerCase()||"";if(!r){const n=s.split("?")[0].toLowerCase();if(n){const a=n.lastIndexOf(".");a!==-1&&(r=n.slice(a+1))}}if(r.endsWith("fbx"))return this.loadFbx(s,i);if(r.endsWith("obj"))return this.loadObj(s,i);if(r.endsWith("stl"))return this.loadStl(s,i);if(r.endsWith("ifc"))S.warn("[LoadingHelper] IFC is not supported directly since three.js r150!");else return r.endsWith("shp")?this.loadShp(s,i):r.endsWith("dae")?this.loadDae(s,i):r.endsWith("dxf")?this.loadDxf(s,i):r.endsWith("jpg")||r.endsWith("jpeg")||r.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=n=>{n.total===0&&n.loaded>0||e&&e(n)},r=await i.loadAsync(t,s);return Promise.resolve(r.scene)}parseGltf(t,e,i,s){return this.getGltfLoader().parse(t,e,n=>i(n.scene),s)}async loadFbx(t,e){const i=new _a.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Ia.OBJLoader(this.manager),s=new Aa.MTLLoader(this.manager),r=t.replace(".obj",".mtl"),n=await s.loadAsync(r,e);n.preload(),i.setMaterials(n);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new Da.STLLoader(this.manager),s=await i.loadAsync(t,e),r=new d.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),n=new d.Mesh(s,r);return Promise.resolve(n)}async loadShp(t,e){const i=new Wh;return new Promise((s,r)=>{i.load(t,n=>{s(n)},e,n=>{r(n)})})}async loadDae(t,e){const i=new Oa.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 Y(this.manager,i);s.setFont(this.font),await this.font?.getFontFromIndexeddb();try{const r=await s.loadAsync(t,e);return Promise.resolve(r.threejsObject)}catch{const n=new ErrorEvent("");return Promise.reject(n)}}async loadPly(t,e){const i=new ka.PLYLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(new d.Mesh(s))}async loadImage(t,e){const i=new d.TextureLoader(this.manager),s=await i.loadAsync(t,e);if(!s)return Promise.reject("Failed to load image!");const r=10,n=s.image;let a=n&&n.height||r,o=n&&n.width||r;a=r/o*a,o=r;const l=new d.MeshBasicMaterial({map:s,side:d.DoubleSide,transparent:!0}),c=new d.PlaneGeometry(o,a),u=new d.Mesh(c,l);return Promise.resolve(u)}async loadDxfData(t,e,i,s,r){this.font||console.warn("[LoadingHelper] Should set font first!");const n=new Y(this.manager,r);return n.setFont(this.font),await this.font?.getFontFromIndexeddb(),n.manager.onLoad=()=>{s&&s()},n.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 Pa.GLTFLoader(this.manager);const t=new Ea.DRACOLoader(this.manager);t.setDecoderPath(fi.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};p(fi,"DecoderPath","libs/draco/gltf/"),p(fi,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let ut=fi;const Hn=`(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
- `,Yr=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",Hn],{type:"text/javascript;charset=utf-8"});function Yh(h){let t;try{if(t=Yr&&(self.URL||self.webkitURL).createObjectURL(Yr),!t)throw"";const e=new Worker(t,{name:h?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(Hn),{name:h?.name})}}class Nn{constructor(){p(this,"running");p(this,"worker");this.running=!1,this.worker=new Yh,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){S.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){S.warn("[GenerateMeshBVHWorker] Worker has been disposed.");return}const{worker:i}=this;this.running=!0;const s=new Map;t.forEach(n=>{s.set(n.id,n)});let r=0;return new Promise((n,a)=>{const o=()=>{++r===s.size&&(this.running=!1,i.onmessage=null,n())};i.onerror=l=>{S.warn("[GenerateMeshBVHWorker] "+l.message),a(new Error("[GenerateMeshBVHWorker] "+l.message)),this.running=!1},i.onmessage=l=>{this.running=!1;const{data:c}=l;if(c.error)S.warn(c.error),o();else if(c.serialized){const{serialized:u,position:f,id:m}=c,g=s.get(m),x=ks.MeshBVH.deserialize(u,g,{setIndex:!1}),y=Object.assign({setBoundingBox:!0},e);if(y.transferred&&(g.attributes.position.array=f),g.index)e.saveOriginalIndex&&!g.userData.originalIndex&&(g.userData.originalIndex=g.index.array),S.debug("before update, index:",g.index.array),g.index.array=u.index;else{const T=new Se.BufferAttribute(u.index,1,!1);g.setIndex(T)}g.index&&(S.debug("after update, index:",g.index.array),g.index.needsUpdate=!0),y.setBoundingBox&&!g.boundingBox&&(g.boundingBox=x.getBoundingBox(new Se.Box3)),g.boundsTree=x,o()}else e.onProgress&&e.onProgress(c.progress)};for(const[l,c]of s){const u=c.index?c.index.array:void 0,f=c.attributes.position,m=f.array;if(f.isInterleavedBufferAttribute||u&&u.isInterleavedBufferAttribute){S.warn("[GenerateMeshBVHWorker] InterleavedBufferAttribute are not supported for the geometry attributes."),o();continue}const g=[];e.transferred&&(g.push(m),u&&(g.push(u),e.saveOriginalIndex&&(c.userData.originalIndex=u.slice()))),i.postMessage({id:l,index:u,position:m,options:Object.assign(Object.assign({},e),{onProgress:null,includedProgressCallback:!!e.onProgress,groups:[...c.groups]})},g.length>0?g.map(x=>x.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Ns{constructor(t){p(this,"running");p(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 Nn}isRunning(){return this.running}async generate(t,e={}){if(this.running){S.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){S.warn("[BVHHelper] Worker has been disposed.");return}return this.running=!0,new Promise(i=>{const s=this.workers.length,r=t.length,n=[],a=Math.floor(r/s),o=r%s;let l=0,c=0;for(let u=0;u<s;u++){const f=this.workers[u];if(u<o?(l=u*a+u,c=l+a+1):(l=u*a+o,c=l+a),l=Math.min(l,r),c=Math.min(c,r),l>=c)break;S.debug("startIndex: "+l+" endIndex: "+c),n.push(f.generate(t.slice(l,c),e))}Promise.allSettled(n).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(r=>{const n=r;if(n.isMesh&&n.geometry&&oe.isMergedMesh(n)&&!(n instanceof d.InstancedMesh)){if(i.has(n.geometry.id))return;n.geometry.index&&e.saveOriginalIndex&&(n.geometry.userData.originalIndex=n.geometry.index.array.slice()),n.geometry.boundsTree=new ks.MeshBVH(n.geometry,e),i.add(n.geometry.id)}})})}static createMeshBvhAsync(t,e={}){const i=new Set,s=[];t.forEach(n=>{n.traverse(a=>{const o=a;if(o.isMesh&&o.geometry&&oe.isMergedMesh(o)&&!(o instanceof d.InstancedMesh)){if(i.has(o.geometry.id))return;s.push(o.geometry),i.add(o.geometry.id)}})});const r=new Ns;return r.generate(s,e).then(()=>{r.dispose()})}}class Xh{constructor(t,e,i,s,r){p(this,"object");p(this,"camera");p(this,"targetPixelHeight",100);p(this,"canvasHeight",800);this.camera=t,this.object=i,this.targetPixelHeight=s,this.canvasHeight=r,this.adjustSize(),e.addEventListener("update",()=>{this.adjustSize()})}adjustSize(){const t=new d.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=Zh(e,i,this.canvasHeight);if(Math.abs(s-this.targetPixelHeight)<5)return;let n=this.object.scale.x;n*=this.targetPixelHeight/s,this.object.scale.set(n,n,n),this.object.updateMatrix()}}const Zh=(h,t,e=800,i=45)=>{const s=i*(Math.PI/180),r=2*Math.tan(s/2)*t,n=h/r;return e*n},Li=new d.Vector2,Ri=new d.Vector2,Fi=new d.Vector2,Xr=new d.Vector2,Kh=new d.Vector2,$h=new d.Vector2,ce=class ce extends pt{constructor(e){super(z.guid());p(this,"needsFrustumCulled");p(this,"renderOrder");p(this,"snapType");p(this,"osnapInfo");p(this,"drawSnapFunctions");p(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=it.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=ce.FILL_COLOR_NONE,e.strokeStyle=ce.lineColor,e.lineWidth=ce.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=ce.SNAP_LINE_COLOR,e.lineWidth=ce.lineWidth;const s=this.osnapInfo.line;if(!s)return;const r=this.transToScreenCoord(s.start,i),n=this.transToScreenCoord(s.end,i);e.moveTo(r.x,r.y),e.lineTo(n.x,n.y),e.stroke(),e.restore()}drawTripleCorss(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Li.set(s.x,s.y-r),a=Ri.set(s.x-.87*r,s.y+r/1.4),o=Fi.set(s.x+.87*r,s.y+r/1.4);e.moveTo(s.x,s.y),e.lineTo(n.x,n.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),r=ce.iconSize,n=ce.iconSize;e.rect(s.x-r/2,s.y-n/2,r,n)}drawTriangle(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/1.6,n=Li.set(s.x,s.y-r),a=Ri.set(s.x-.87*r,s.y+r/2),o=Fi.set(s.x+.87*r,s.y+r/2);e.moveTo(n.x,n.y),e.lineTo(a.x,a.y),e.lineTo(o.x,o.y)}drawCircleWithCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2;e.arc(s.x,s.y,r,0,Math.PI*2),e.moveTo(s.x-r/1.8,s.y),e.lineTo(s.x+r/1.8,s.y),e.moveTo(s.x,s.y-r/1.8),e.lineTo(s.x,s.y+r/1.8)}drawCross(e,i){const s=this.transToScreenCoord(this.osnapInfo.point,i),r=ce.iconSize/2,n=Li.set(s.x-r,s.y-r),a=Ri.set(s.x+r,s.y+r),o=Fi.set(s.x+r,s.y-r),l=Xr.set(s.x-r,s.y+r);e.moveTo(n.x,n.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),r=ce.iconSize/2,n=Li.set(s.x,s.y),a=Ri.set(s.x-r,s.y),o=Fi.set(s.x,s.y+r),l=Xr.set(s.x-r,s.y-r),c=Kh.set(s.x-r,s.y+r),u=$h.set(s.x+r,s.y+r);e.moveTo(a.x,a.y),e.lineTo(n.x,n.y),e.lineTo(o.x,o.y),e.moveTo(l.x,l.y),e.lineTo(c.x,c.y),e.lineTo(u.x,u.y),e.lineTo(l.x,l.y)}update(e){this.osnapInfo=e}getClassType(){return"SnapDrawable"}};p(ce,"lineColor","rgba(255, 119, 0, 1)"),p(ce,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),p(ce,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),p(ce,"lineWidth",2),p(ce,"iconSize",14);let ye=ce;xi._registerDrawableClass(ye);var Gn=(h=>(h[h.None=0]="None",h[h.Vertex=1]="Vertex",h[h.MiddlePoint=2]="MiddlePoint",h[h.Edge=4]="Edge",h[h.Face=8]="Face",h[h.FootOfPerpendicular=16]="FootOfPerpendicular",h[h.Intersection=32]="Intersection",h[h.CircleCenter=64]="CircleCenter",h))(Gn||{});const Jh=1e-5,se=new d.Vector3,fe=new d.Vector3,Gt=new d.Vector3,hi=new d.Vector3,wt=new d.Matrix4,ci=new d.Line3;function Qh(h,t){let e=Number.MAX_VALUE,i=0;for(let s=0;s<h.vertices.length;s++){const r=t.distanceTo(h.vertices[s]);r<e&&(i=s,e=r)}return{vertex:h.vertices[i],distance:e}}function ec(h){if(!(h.object instanceof d.Mesh)||!h.face)return;const t=h.object,e=t.geometry.attributes.position;let i=t.geometry.index;if(e.count<3)return;const s=oe.getBatchByFaceIndex(t,h.faceIndex);t.geometry.boundsTree&&(i=new d.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),wt.identity(),t instanceof d.InstancedMesh&&h.instanceId!==void 0&&t.getMatrixAt(h.instanceId,wt),wt.premultiply(t.matrixWorld);const r=t.geometry.drawRange;let n,a=e.array;if(i){let m=Math.max(0,r.start),g=Math.min(i.count,r.start+r.count);if(n=i.array,s){m=Math.max(m,s.indexStart),g=Math.min(g,s.indexStart+s.indexCount),n=i.array.slice(m,g),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let x=0;x<n.length;x++)n[x]=n[x]-s.positionStart}else(m!==0||g!==i.count)&&(n=i.array.slice(m,g))}else{let m=Math.max(0,r.start),g=Math.min(e.count,r.start+r.count);s?(m=Math.max(m,s.positionStart),g=Math.min(g,s.positionStart+s.positionCount),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3)):(m!==0||g!==e.count)&&(a=e.array.slice(m*3,g*3));const x=a.length/3;n=x>65535?new Uint32Array(x):new Uint16Array(x);for(let y=0,T=x;y<T;y++)n[y]=y}const o=cn.buildEdge(a,n,20);let l=Number.MAX_VALUE,c=0;for(let m=0;m<o.length;m+=2){const g=o[m],x=o[m+1];se.set(a[g*3],a[g*3+1],a[g*3+2]),se.applyMatrix4(wt),fe.set(a[x*3],a[x*3+1],a[x*3+2]),fe.applyMatrix4(wt),ci.set(se,fe),ci.closestPointToPoint(h.point,!0,Gt);const y=h.point.distanceTo(Gt);y<l&&(c=m,l=y,hi.copy(Gt))}const u=o[c],f=o[c+1];return se.set(a[u*3],a[u*3+1],a[u*3+2]),se.applyMatrix4(wt),fe.set(a[f*3],a[f*3+1],a[f*3+2]),fe.applyMatrix4(wt),{vertices:[se.clone(),fe.clone()],vertex:hi.clone(),distance:l}}class tc{constructor(t){p(this,"drawableList",new bi("snap"));p(this,"overlayRender");p(this,"markers",{});p(this,"activeOSnapType",0);p(this,"snapToleranceInWorldCoord",1);p(this,"intersectionLimit",10);p(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});p(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new ye(it.TripleCross),e=new ye(it.Square),i=new ye(it.Triangle),s=new ye(it.CircleWithCross),r=new ye(it.Cross),n=new ye(it.Perpendicular);this.markers[1]=e,this.markers[2]=i,this.markers[4]=t,this.markers[32]=r,this.markers[64]=s,this.markers[16]=n,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 qt.colorStr2Rgba(ye.lineColor)}setMarkerLineColor(t){ye.lineColor=qt.rgba2Color(t)}getMarkerLineWidth(){return ye.lineWidth}setMarkerLineWidth(t){ye.lineWidth=t}getMarkerIconSize(){return ye.iconSize}setMarkerIconSize(t){ye.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}S.debug("[OSnap] intersections before handleSnap:",t);const s=[];let r=!1,n;for(const o of t)o.object instanceof d.Mesh?(!n&&(n=o.point),!r&&o.object.name!=="groundPlane"&&(s.push(o),r=!0)):s.push(o);if(!e&&n){n.setZ(0);for(const l of s)l.point.z=0,l.distance=l.point.distanceTo(n);const o=l=>l instanceof d.Points?0:l instanceof d.LineSegments?2:l instanceof d.Line?1:3;s.sort((l,c)=>{const u=o(l.object),f=o(c.object);return u!==f?u-f:l.distance-c.distance})}return n||(S.warn("[OSnap] Potential to produce erroneous snap results"),n=s[0].point),S.debug("[OSnap] intersections:",s),S.debug("[OSnap] mousePosition:",n),this.getSnapPointAndUpdateMarker(n,s,e,i)?.clone()||n}getSnapPointAndUpdateMarker(t,e,i,s){if(!e.length){this.activateMarker(0);return}const r=this.getSnapInfo(t,e,i,s);if(!r||r.type===0){this.activateMarker(0);return}return this.activateMarker(r.type,r),r.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=Jh){const{start:s,end:r}=e,n=s.x-r.x,a=s.y-r.y,o=s.z-r.z;if(s.distanceTo(r)<i)return s.clone();let l=(t.x-s.x)*(s.x-r.x)+(t.y-s.y)*(s.y-r.y)+(t.z-s.z)*(s.z-r.z);return l=l/(n*n+a*a+o*o),new d.Vector3(s.x+l*n,s.y+l*a,s.z+l*o)}getSnapInfo(t,e,i,s){const r=this.snapToleranceInWorldCoord*2;S.debug("[OSnap] snap radius:",r);const n=[],a={line:void 0};let o=this.osnapTypePriorities[0];for(let l=0;l<e.length&&l<this.intersectionLimit;++l){const c=e[l],u=c.object;let f;u instanceof d.Mesh?f=this.getOsnapInfoListFromMesh(t,c,r,o):u instanceof d.Line?f=this.getOsnapInfoListFromLine(t,c,i,r,a,o,s):u instanceof d.Points&&(f=this.getOsnapInfoListFromPoint(t,c,i,r,o)),f&&(o=this.osnapTypePriorities[f.type],n.push(f))}if(n.length!==0)return n.sort((l,c)=>{const u=this.osnapTypePriorities[l.type],f=this.osnapTypePriorities[c.type];return u!==f?u-f:l.distance-c.distance}),n[0]}getOsnapInfoListFromMesh(t,e,i,s){if(s<this.osnapTypePriorities[1])return;const r=Date.now(),n=ec(e);if(!n){S.warn("[OSnap] Failed to get edge !");return}const a=Date.now();S.debug("[OSnap] getEdgeSnappingInfo took "+(a-r)/1e3+"s "),S.debug("[OSnap] edge:",n);const o=Qh(n,t);if(S.debug("[OSnap] vertex:",o),o.distance<=i&&this.isOSnapTypeEnabled(1))return{distance:o.distance,type:1,point:o.vertex};if(n.distance<=i){if(this.isOSnapTypeEnabled(2)&&s<this.osnapTypePriorities[2])return;se.copy(n.vertices[0]),se.add(n.vertices[1]),se.divideScalar(2);const l=se.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:se.clone()}:!this.isOSnapTypeEnabled(4)||s<this.osnapTypePriorities[4]?void 0:{distance:n.distance,type:4,point:n.vertex,line:{start:n.vertices[0],end:n.vertices[1]}}}else S.debug("[OSnap] Face")}getOsnapInfoFromSegment(t,e,i,s,r,n,a){const o={start:e,end:i};if(a&&n>=this.osnapTypePriorities[16]&&this.isOSnapTypeEnabled(16)){const m=this.getFootOfPerpendicular(a,o,s),g=t.distanceTo(m);if(g<=s)return{distance:R.floorNumber(g,7),type:16,point:m.clone()}}if(n<this.osnapTypePriorities[1])return;ci.set(e,i),ci.closestPointToPoint(t,!0,Gt);const l=t.distanceTo(Gt);if(l>s)return;const c=t.distanceTo(e),u=t.distanceTo(i);if(Math.min(c,u)<=s&&this.isOSnapTypeEnabled(1)){let m=c,g=e;return u<c&&(m=u,g=i),{distance:R.floorNumber(m,7),type:1,point:g.clone()}}if(n<this.osnapTypePriorities[2])return;ci.getCenter(hi);const f=t.distanceTo(hi);if(f<s&&this.isOSnapTypeEnabled(2))return{point:hi.clone(),distance:R.floorNumber(f,7),type:2};if(!(n<this.osnapTypePriorities[4])){if(r.line&&this.isOSnapTypeEnabled(32)){const m=U.getLineSegmentsIntersectingPoint(r.line,o);if(!m)return;const g=t.distanceTo(m)/2;return g<s?(r.line=void 0,{point:m.clone(),distance:R.floorNumber(g,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return r.line={start:e.clone(),end:i.clone()},{point:Gt.clone(),distance:R.floorNumber(l,7),type:4,line:{start:e.clone(),end:i.clone()}}}}getOsnapInfoListFromLine(t,e,i,s,r,n,a){const o=[],l=e.object,c=l instanceof d.LineSegments?2:1,u=l.geometry.index,f=l.geometry.attributes.position,m=l.geometry.drawRange,g=oe.getBatchByLineIndex(l,e.index);if(u){let x=Math.max(0,m.start),y=Math.min(u.count,m.start+m.count);g&&(x=Math.max(x,g.indexStart),y=Math.min(y,g.indexStart+g.indexCount));for(let T=x,v=y;T<v-1;T+=c){const b=u.getX(T),E=u.getX(T+1);se.fromBufferAttribute(f,b),fe.fromBufferAttribute(f,E),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const O=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);O&&(n=this.osnapTypePriorities[O.type],o.push(O))}}else{let x=Math.max(0,m.start),y=Math.min(f.count,m.start+m.count);g&&(x=Math.max(x,g.positionStart),y=Math.min(y,g.positionStart+g.positionCount));for(let T=x,v=y;T<v-1;T+=c){se.fromBufferAttribute(f,T),fe.fromBufferAttribute(f,T+1),se.applyMatrix4(l.matrixWorld),fe.applyMatrix4(l.matrixWorld),!i&&(se.setZ(0),fe.setZ(0));const b=this.getOsnapInfoFromSegment(t,se,fe,s,r,n,a);b&&(n=this.osnapTypePriorities[b.type],o.push(b))}}if(o.length!==0)return o.sort((x,y)=>{const T=this.osnapTypePriorities[x.type],v=this.osnapTypePriorities[y.type];return T!==v?T-v:x.distance-y.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,r){if(r<this.osnapTypePriorities[1])return;const n=e.object,a=n.geometry.getAttribute("position");se.fromBufferAttribute(a,e.index),se.applyMatrix4(n.matrixWorld),fe.copy(t),!i&&(se.setZ(0),fe.setZ(0));const o=fe.distanceTo(se);if(o>s)return;const l={distance:o,point:se.clone(),type:1};if(n.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(S.debug("[OSnap] Other types of vertices !"),!this.isOSnapTypeEnabled(1))return;return l}getIntersectsIncludeOutline(t,e){const i=t.slice(),s=[];for(let n=0;n<t.length&&n<this.intersectionLimit;n++){const a=t[n].object;if(a.updateWorldMatrix(!0,!1),a instanceof d.Mesh&&!$.hasOutline(a,!1)){const o=$.createOutline(a.geometry);o.visible=!1,a.add(o),o.updateWorldMatrix(!0,!1),s.push(o)}}let r=[];return s.length>0&&(r=e.intersectObjects(s)||[],S.debug("[OSnap] Intersected with newly created edges: ",r),r.length>0&&i.push(...r)),i.sort((n,a)=>n.distance-a.distance),i}}class qn{constructor(t,e,i){p(this,"node");p(this,"parentNode");p(this,"target");p(this,"childNode");p(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});p(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));p(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));p(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 ic{constructor(t){p(this,"viewer");p(this,"active",!1);p(this,"tooltip");p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mouseClicked",t=>{const e=t;if(e.markupData){const i=e.markupData.id,s=this.viewer.getOverlayRender().getDrawableById(i);if(s){let r=s.getBounds();r=r.clone().expandByScalar(20*this.viewer.getPixelSizeInWorldCoord());const n=pe.world2NormalizedScreen(r.min,this.camera,this.viewerContainer),a=pe.world2NormalizedScreen(r.max,this.camera,this.viewerContainer),o=new d.Box2(new d.Vector2(Math.min(n.x,a.x),Math.min(n.y,a.y)),new d.Vector2(Math.max(n.x,a.x),Math.max(n.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()}}});p(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(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new qn("pick-markup-tooltip",Re.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=Re.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(re.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(re.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 Ht=class Ht{constructor(t){p(this,"viewer");p(this,"input");p(this,"mouseDown",!1);p(this,"mouseMove",!1);p(this,"mouseDownPositionX",-1);p(this,"mouseDownPositionY",-1);p(this,"tempKey");p(this,"tempTouch");p(this,"tempEnableRotate",!1);p(this,"rectDom");p(this,"tooltip");p(this,"active",!1);p(this,"resolve");p(this,"reject");p(this,"isResolvedOrRejected",!1);p(this,"mousedown",t=>{if(t.button===0){this.mouseDown=!0;const e=new d.Vector2(t.x,t.y);this.mouseDownPositionX=e.x,this.mouseDownPositionY=e.y,this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0}});p(this,"mousemove",t=>{if(!this.mouseDown)return;const e=new d.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 d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),r=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y));this.drawRect(s,r)}});p(this,"mouseup",t=>{if(this.mouseDown&&this.mouseMove){const e=new d.Vector2(t.x,t.y),i=new d.Vector2(Math.min(this.mouseDownPositionX,e.x),Math.min(this.mouseDownPositionY,e.y)),s=new d.Vector2(Math.max(this.mouseDownPositionX,e.x),Math.max(this.mouseDownPositionY,e.y)),r=new d.Box2(i,s);this.resolve&&(this.resolve(r),this.isResolvedOrRejected=!0),this.deactivate(),this.setRectDomVisible(!1)}this.mouseDown=!1,this.mouseMove=!1,this.mouseDownPositionX=-1,this.mouseDownPositionY=-1});p(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 qn("box-select-tooltip",Re.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=Re.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(re.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(re.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: ${Ht.BORDER_WIDTH} solid ${Ht.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!")}};p(Ht,"BORDER_COLOR","#fff000"),p(Ht,"BORDER_WIDTH","2px");let $i=Ht;class Wn{constructor(t){p(this,"viewer");p(this,"boxSelectHelper");p(this,"active",!1);this.viewer=t,this.boxSelectHelper=new $i(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 r=new d.Vector3(Math.min(i.x,s.x),Math.min(i.y,s.y),Math.min(i.z,s.z)),n=new d.Vector3(Math.max(i.x,s.x),Math.max(i.y,s.y),Math.max(i.z,s.z)),a=new d.Box3(r,n);this.viewer.zoomToBBox(a)}}destroy(){this.boxSelectHelper?.destroy(),this.boxSelectHelper=void 0}}function Zr(h){return h?h.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 zi=new d.Box3,sc=new d.Vector3;function rc(h,t){return h.trim().toLowerCase()===t?2e6:0}function nc(h,t){const e=h.toLowerCase(),i=e.indexOf(t);if(i>=0)return(e===t?2e6:1e6)+(1e3-i)-Math.min(e.length,500);let s=0,r=-1,n=-1,a=0;for(let l=0;l<t.length;l++){const c=t[l];let u=-1;for(;s<e.length;s++)if(e[s]===c){u=s;break}if(u<0)return 0;r<0?r=u:n>=0&&u-n>1&&(a+=u-n-1),n=u,s=u+1}const o=5e5-a*50-r*5-Math.min(e.length,500);return o>0?o:1}class Is{constructor(t){p(this,"viewer");p(this,"overlayRender");p(this,"drawableList");p(this,"indexedModelObject");p(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 d.Matrix4,s=new d.Vector3,r=new Map;e.updateWorldMatrix(!0,!0);const n=(a,o,l,c,u)=>{if(a&&r.has(a)){r.get(a).box.union(u);return}r.set(a||o+c,{text:o,layer:l,layoutName:c,box:u.clone()})};e.traverse(a=>{const o=a.userData;if(o){if(typeof o.textContent=="string"&&o.textContent.length){const l=Zr(o.textContent);if(!l||(zi.makeEmpty(),zi.setFromObject(a),zi.isEmpty()))return;n(o.handle||"",l,o.layer||"0",this.findLayoutName(a),zi);return}if(Array.isArray(o.batches)){const l=a.geometry?.getAttribute?.("position");if(!l)return;i.copy(a.matrixWorld);for(const c of o.batches){const u=c?.userData?.textContent;if(typeof u!="string"||!u.length)continue;const f=Zr(u);if(!f)continue;const m=new d.Box3,g=c.positionStart||0,x=c.positionCount||0;for(let y=g;y<g+x;y++)s.fromBufferAttribute(l,y).applyMatrix4(i),m.expandByPoint(s);m.isEmpty()||n(c.userData.handle||"",f,c.userData.layer||"0",this.findLayoutName(a),m)}}}}),r.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",r=e?.layer?.trim().toLowerCase(),n=e?.maxResults??200,a=[];for(const o of this.index){if(r&&o.layer.toLowerCase()!==r)continue;const l=s==="exact"?rc(o.text,i):nc(o.text,i);l>0&&a.push({item:o,score:l})}return a.sort((o,l)=>l.score-o.score),a.slice(0,n).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(sc).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new bi("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new Je(z.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 ac extends pt{constructor(e){super("MobileHelper");p(this,"position");p(this,"needsFrustumCulled");p(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 d.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 Le=(h=>(h[h.Left=0]="Left",h[h.Middle=1]="Middle",h[h.Right=2]="Right",h[h.Back=3]="Back",h[h.Forward=4]="Forward",h))(Le||{});class Yn extends mt{constructor(e){super();p(this,"element");p(this,"enabled");p(this,"keyboardEnabled");p(this,"mouseDownPositionX");p(this,"mouseDownPositionY");p(this,"lastLeftPointerUpTime");p(this,"pointers");p(this,"handleClick");p(this,"handlePointerDown");p(this,"handlePointerMove");p(this,"handlePointerUp");p(this,"handlePointerCancel");p(this,"handleMouseWheel");p(this,"handleContextMenu");p(this,"handlePointerEnter");p(this,"handlePointerLeave");p(this,"handleResize");p(this,"handleKeydown");p(this,"handleKeyup");p(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,ji(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,ji(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const r=pe.getScreenCoordinateByEvent(i,this.element);s.x=r.x,s.y=r.y,s.movementX=i.movementX,s.movementY=i.movementY}else ji(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else ji(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 ji(h,t){return h[t]!==void 0}class oc{constructor(t){p(this,"CLEAR_COLOR");p(this,"CLEAR_COLOR_ALPHA");p(this,"EMPTY_MODEL_ID");p(this,"viewer");p(this,"raycaster");p(this,"pickingTexture");this.CLEAR_COLOR=new d.Color().setRGB(1,1,1),this.CLEAR_COLOR_ALPHA=1,this.EMPTY_MODEL_ID=255,this.viewer=t,this.raycaster=new d.Raycaster,this.pickingTexture=new d.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 r=this.pickObjects(t,e,i,s);if(r.length!==0)return r[0]}pickObjects(t,e,i,s=0){const r=pe.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const n=[],a=new Map,o=pe.screen2Ndc(t,this.camera,this.viewerContainer),l=pe.screen2Ndc({x:t.x+s,y:t.y},this.camera,this.viewerContainer),c=new d.Vector3(o.x,o.y,0).unproject(this.camera),u=new d.Vector3(l.x,l.y,0).unproject(this.camera),f=c.distanceTo(u),m=this.raycaster.params.Line.threshold;this.raycaster.params.Line.threshold=f,this.setLayerChannels(i);const g=8;for(let y=0;y<g;y++){const T=y/g*Math.PI*2,v=Math.cos(T)*s,b=Math.sin(T)*s,E={x:t.x+v,y:t.y+b},O=pe.screen2Ndc(E,this.camera,this.viewerContainer);this.raycaster.setFromCamera(O,this.camera),this.raycaster.layers.enableAll();const _=this.raycaster.intersectObjects(e,!0)||[];for(const C of _)C.object&&!a.has(C.object.uuid)&&(a.set(C.object.uuid,C),n.push(C))}this.raycaster.setFromCamera(o,this.camera);const x=this.raycaster.intersectObjects(e,!0)||[];for(const y of x)y.object&&!a.has(y.object.uuid)&&(a.set(y.object.uuid,y),n.push(y));if(this.raycaster.params.Line.threshold=m,n.length>1){const y=this.raycaster.ray.origin.clone();n.sort((T,v)=>{const b=T.point||T.object.getWorldPosition(new d.Vector3),E=v.point||v.object.getWorldPosition(new d.Vector3);return b.distanceTo(y)-E.distanceTo(y)})}return n}return this.pickObjectsByNdc(r,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]],r=Eh(s),n=_h(s);if(r!==this.EMPTY_MODEL_ID)return S.info("[PickMgr] Picked: tilesetId("+r+"), userId("+n+")"),{tilesetId:r,userId:n}}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:r,renderer:n,camera:a}=this;r.setSize(i,s);const o=n.getPixelRatio(),l=n.getContext().drawingBufferWidth,c=n.getContext().drawingBufferHeight,u=t.x*o|0,f=t.y*o|0;a.setViewOffset(l,c,u,f,i,s),n.setRenderTarget(r);const m=new d.Color;n.getClearColor(m);const g=n.getClearAlpha();n.setClearColor(this.CLEAR_COLOR,this.CLEAR_COLOR_ALPHA),n.render(e,a);const x=new Uint8Array(4*i*s);return n.readRenderTargetPixels(r,0,0,i,s,x),n.setRenderTarget(null),a.clearViewOffset(),n.setClearColor(m,g),x}}const Kr=new d.Vector3;class lc{constructor(t){p(this,"viewer");p(this,"scene");p(this,"renderer");p(this,"pmremGenerator");p(this,"lights");p(this,"modelGroup");this.viewer=t;const e=new d.Scene;e.matrixAutoUpdate=Ne,e.matrixWorldAutoUpdate=Ne,this.scene=e,this.modelGroup=new d.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:r}=t.container,n=new d.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0});n.setPixelRatio(window.devicePixelRatio),n.setSize(i,s),n.outputColorSpace=d.SRGBColorSpace,n.toneMappingExposure=1,n.localClippingEnabled=!0,n.shadowMap.enabled=!1,n.shadowMap.type=d.PCFSoftShadowMap,n.shadowMap.autoUpdate=!1,n.domElement.style.outlineWidth="0",r?.appendChild(n.domElement),this.renderer=n,z.printGpuInfo(n.getContext())}initLights(){const t=new d.Group;t.name="lights";const e=1.5,i=16777215,s=new d.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 r=new d.AmbientLight(i);r.name="ambient";const n=new d.HemisphereLight(i,14540253,.2);n.name="hemisphere",n.position.set(0,300,0);const a=new d.Group;a.name="lightHelpers",a.visible=!1;const o=new d.DirectionalLightHelper(s),l=new d.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(r),t.add(n),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new d.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 d.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 d.CameraHelper&&(t=i)}return t}async setEnvironmentFromData(t){this.pmremGenerator||this.initPMREMGenerator();const e=await pi.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await pi.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 d.Sphere;e.getBoundingSphere(i);const s=i.center,r=i.radius,n=t.shadow.camera;n.zoom=1,n.top=r,n.bottom=-r,n.right=r,n.left=-r,n.near=.1,n.far=2*r,n.updateProjectionMatrix();const a=new d.Vector3(-1,-.5,1);a.normalize().multiplyScalar(r),t.position.copy(s).addScaledVector(a,-1),t.target.position.copy(s),S.debug("[Scene] directionalLight.position",t.position),S.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),Kr.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Kr),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 hc{constructor(t){p(this,"history");p(this,"step");p(this,"maxCount");p(this,"isBatchCommand");p(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 Qi extends mt{constructor(e){super();p(this,"name");p(this,"viewerCfg");p(this,"clock");p(this,"targetMaxFps");p(this,"timeStamp");p(this,"renderEnabled");p(this,"requestAnimationFrameHandle");p(this,"container");p(this,"plugins");p(this,"loadedModels");p(this,"raf");p(this,"timeoutSymbol");p(this,"homeView");p(this,"inputManager");p(this,"cameraManager");p(this,"sceneManager");p(this,"fontManager");p(this,"pickManager");p(this,"undoManager");p(this,"overlayRender");p(this,"css2dRenderer");p(this,"spinner");p(this,"progressBar");p(this,"loaderHelper");p(this,"zoomToRectHelper");p(this,"_enableSelection");p(this,"enableRender");this.name=Be.BaseViewer,this.clock=new d.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new Un,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 Us(e.containerId),e.enableProgressBar&&(this.progressBar=new Hs(this.container)),this.spinner=new Ln(this.container),this.sceneManager=new lc(this),this.pickManager=new oc(this),this.overlayRender=new xi(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new Yn(this.viewerContainer),this.cameraManager=new jh(this),this.loaderHelper=new ut,this.undoManager=new hc,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&nn(e)}initLocalization(){const e=this.viewerCfg.language||on;Re.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 rn.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(re.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(re.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(re.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){ut.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=Ne,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new Ke),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let r=1;if(e.type==="OrthographicCamera"){const n=e;r=Math.max(n.right-n.left,n.top-n.bottom)/n.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const n=e,a=new d.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(r=2*(a.distanceTo(o)*Math.tan(n.fov/2*(Math.PI/180)))/s)}return r}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new Wn(this)),this.zoomToRectHelper.activate()}deactivateZoomRect(){this.zoomToRectHelper?.deactivate()}getUniqueModelId(e){let i=e;const s=r=>!!this.loadedModels.find(n=>n.modelId===r);if(s(i)){let r=1;for(;s(i+"_"+r);)r++;i=i+"_"+r,S.warn("[Viewer] Model '"+i+"' is loaded more than once!")}return i}getBBox(){const e=new d.Box3;return this.loadedModels.forEach(i=>{e.union(i.getBBox())}),e}flyToObject(e){this.cameraManager.flyToObject(e)}flyToObjects(e){const i=new d.Box3;e.forEach(r=>{const n=new d.Box3().setFromObject(r);i.union(n)});const s=new d.Sphere;i.getBoundingSphere(s),this.cameraManager.fitToSphere(s)}flyTo(e,i,s=!0){const r=this.camera;if(e.equals(i)){S.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!z.isVectorValid(e)||!z.isVectorValid(i)){S.error("[Viewer] invalid position or lookAt!");return}const n=e.distanceTo(i);n<r.near?(e=e.clone().sub(i).normalize().multiplyScalar(r.near*1.1),S.warn("[Viewer] camera could be too close to see the object!")):n>r.far&&(e=e.clone().sub(i).normalize().multiplyScalar(r.far*.9),S.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 d.Vector3);let r=Math.max(s.x,s.y,s.z)/2;r===0&&(r=1);const n=this.cameraManager.getDistanceToFitSphere(r),a=new d.Vector3;i.getCenter(a);const o=a.clone().add(e.clone().multiplyScalar(n));this.flyTo(o,a)}goToHomeView(){if(this.homeView)this.cameraManager.flyToViewpoint(this.homeView);else{const e=new d.Vector3(1,.5,1);this.flyToDirection(e)}}viewFitAll(){const e=this.getBBox(),i=new d.Sphere;e.getBoundingSphere(i),this.cameraManager.fitToSphere(i)}zoomToBBox(e){this.cameraManager.flyToBox(e)}pickObject(e,i,s){let r=this.pickManager.pickObject(e,this.getRaycastableObjects(),i,s);return this.renderer&&this.renderer.clippingPlanes.length>0&&this.renderer?.clippingPlanes?.every(a=>{r&&a.distanceToPoint(r.point)>0})&&(r=void 0),r}pickObjects(e,i){let s=this.pickManager.pickObjects(e,this.getRaycastableObjects(),i);return s&&this.renderer.clippingPlanes.length>0&&(s=s.filter(r=>this.renderer.clippingPlanes.every(n=>n.distanceToPoint(r.point)>0))),s}getRaycastableObjects(){return this.sceneManager.getRaycastableObjects()}setBackgroundColor(e,i,s){if(!this.scene.background&&(this.scene.background=new d.Color(e,i,s)),this.scene.background instanceof d.Color){const r=new d.Color;r.setRGB(e,i,s,this.renderer.outputColorSpace),this.scene.background.copy(r)}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)){S.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),S.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 Xn=-1e3,Bt=new d.Vector3,$r=new d.Matrix4,Jr=new d.Frustum,Ts=new d.Box3,Qr=new d.Matrix4;class Gs extends Qi{constructor(e){super(e);p(this,"name");p(this,"loadedModels");p(this,"masterModelId");p(this,"activeLayoutName");p(this,"dxfLayoutBar");p(this,"layoutInfos");p(this,"units");p(this,"enableHideVisuallySmallObjects");p(this,"sortedHidableObjects");p(this,"lastCameraZoom");p(this,"groundPlane");p(this,"raycastableObjects");p(this,"selectedObject");p(this,"loadingDxfCount");p(this,"textSearchHelper");p(this,"clickHighlightList");p(this,"_enableClickHighlight",!1);this.name=Be.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 Dh(this)),this.cameraManager.setProjection($e.Orthographic),this.cameraManager.setNavigationMode(He.Plan);const i=new d.Vector3(0,0,100),s=new d.Vector3(0,0,0);this.cameraManager.setCameraConfig({eye:i,look:s}),this.resize(),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.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===Le.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 r=new d.Vector2(s.x,s.y),n=this.getWorldPositionByMousePick(r),a=this.pickManager.pickObjects(r,this.getRaycastableObjects(),void 0,3);let o;for(const u of a){const f=this.resolveEntityFromPick(u);if(f){f.hit=u,o=f;break}}const l=o?.userData;if(this._enableClickHighlight&&o){const u=this.getEntityBoundingBox(o);u&&this.highlightEntityBox(u)}else this.clearClickHighlight();const c={event:s,position:r,worldPosition:n,pooo:n,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(re.MouseClick,c)})}resolveEntityFromPick(e){if(!e)return;const i=e.object,s=i.userData?.batches;if(s&&s.length>0){const n=i.geometry,a=i.isMesh===!0,o=e.index;let l;a&&typeof e.faceIndex=="number"&&(l=n?.index?n.index.getX(e.faceIndex*3):e.faceIndex*3);const c=s.find(u=>{const f=typeof o=="number"&&o>=u.indexStart&&o<u.indexStart+(u.indexCount||1),m=typeof o=="number"&&o>=u.positionStart&&o<u.positionStart+u.positionCount||typeof l=="number"&&l>=u.positionStart&&l<u.positionStart+u.positionCount;return f||m});if(c?.userData)return{userData:c.userData,batch:c,object:i}}let r=i;for(;r;){if(r.userData?.handle)return{userData:r.userData,object:r};r=r.parent??void 0}}getEntityBoundingBox(e){const i=e.object,s=i.geometry?.getAttribute?.("position");if(e.batch&&s){const n=new d.Box3,a=e.batch.positionStart||0,o=e.batch.positionCount||0;if(o>0){i.updateWorldMatrix(!0,!1),Qr.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Bt.fromBufferAttribute(s,l).applyMatrix4(Qr),n.expandByPoint(Bt);if(!n.isEmpty())return n}}const r=new d.Box3;return r.setFromObject(i),r.isEmpty()?void 0:r}highlightEntityBox(e){const i=this.getOverlayRender();i&&(!this.clickHighlightList&&(this.clickHighlightList=new bi("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new Je(z.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()}handleMouseClick(e){if(!this.enableSelection)return;const i=new d.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const r=this.overlayRender.getDrawablesByPosition(s)[0];if(r){this.selectedObject===r?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=r,this.selectedObject.selected=!0),this.enableRender();return}const n=this.pickObject(i,[ft]);if(n){const a=n?.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 r=this.getUniqueModelId(e.modelId||e.src);this.spinner.increaseJobCount(),this.loaderHelper.setFont(this.fontManager),this.masterModelId||(this.masterModelId=r);const n=r,a=Re.t("ProgressBar.Loading"),o=x=>{this.progressBar?.updateProgress(n,a,x),i?.(new ProgressEvent("LoadProgress",{loaded:x,total:100}))},l=(x,y,T)=>{let v=x.loaded*100/x.total;v=v*(T-y)/100+y,this.progressBar?.updateProgress(n,a,v),i?.(new ProgressEvent("LoadProgress",{loaded:v,total:100}))},c=x=>l(x,0,90);this.progressBar?.addProgressItem(n),o(0);const u=this.viewerCfg,f=await this.loaderHelper.loadDxfData(e.src,e.modelId,c,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:u.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),m=f.threejsObject;if(s&&s({threejsObject:m,llbMesh:f.llbMesh}),e.matrix&&e.matrix.length===16){const x=new d.Matrix4;x.elements=e.matrix,m.applyMatrix4(x)}const g=new Wt({modelId:r,dxfData:f});this.addModel(g),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(n),this.dispatchEvent(re.ModelLoad)}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(Y.MODEL_LAYOUT_NAME):this.handleOverlayDxf(i);const s=e.getBBox(),r=new d.Vector3;s.getCenter(r),this.cameraManager.adjustCameraByBBox(s);const n=this.getDxfUnits(e);this.masterModelId===i&&(this.units=n)}else{const s=e.getModelObject();this.activeLayoutName=Y.MODEL_LAYOUT_NAME;const r=new d.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:r,extent:r},s.matrixAutoUpdate=Ne,this.scene.add(s);const n=r.max.z;n>this.camera.position.z&&(this.camera.position.z=n,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():De.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(r=>e===r.modelId);if(!i){S.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(Y.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(Y.MODEL_LAYOUT_NAME)?.traverse(r=>{i.addSpatialFilterSection(r,i.dxfData)}),i.showLayoutObjects(Y.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 d.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof pt&&(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=[],r=(o,l,c)=>{s.push(new d.Vector3(o,l,c))},n=i.getSize(new d.Vector3),a=i.getCenter(new d.Vector3);if(r(-n.x/2,-n.y/2,0),r(n.x/2,-n.y/2,0),r(n.x/2,n.y/2,0),r(-n.x/2,n.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new d.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new d.MeshBasicMaterial({color:"#888",side:d.DoubleSide});this.groundPlane=new d.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-n.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=Xn,this.groundPlane.layers.enableAll(),$.disableLayerChannels(this.groundPlane,[ft]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===Y.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(r=>{r.object&&r.object.geometry&&e.push(r.object)}),s.transparent.forEach(r=>{r.object&&r.object.geometry&&e.push(r.object)}))}$r.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),Jr.setFromProjectionMatrix($r);for(const s of this.loadedModels){const r=s.getModelObject(),n=r.children.find(a=>a.name===this.activeLayoutName);n&&n.children.find(o=>o.name===Y.SNAP_GROUP_NAME)?.traverse(o=>{if($.isLeafObject(o)){if(Ts.makeEmpty(),Ts.expandByObject(o),!Jr.intersectsBox(Ts))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),S.debug("[Viewer] getRaycastableObjectsByMouse() from modelSpace"),this.raycastableObjects=e}else{const s=new WeakSet,r=this.getLayoutByName(this.activeLayoutName);r&&r.directAssociatedLeafObjectSet?.forEach(o=>{o.visible&&!s.has(o)&&(e.push(o),s.add(o))});const n=this.getViewportByPoint(this.pickManager.getRaycaster().ray.origin);n&&n.associatedLeafObjectSet?(n.associatedLeafObjectSet?.forEach(a=>{!s.has(a)&&(a.visible||a.userData.isSnapObject)&&(e.push(a),s.add(a))}),S.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",n.viewportId)):S.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return S.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===Y.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,r=this.loadedModels.find(a=>this.masterModelId===a.modelId);if(!r)return;const n=r.getFilteredViewports(i);for(let a=0,o=n.length;a<o;a++){const l=n[a];if(!s(l.psBBox))return l}}getWorldPositionByMousePick(e){const i=[];this.groundPlane&&i.push(this.groundPlane);for(const r of this.loadedModels){const n=r.getModelObject();n&&(i.push(n),n.traverse(a=>{(a.isMesh||a.isLine)&&i.push(a)}))}return this.pickManager.pickObject(e,i)?.point}activateLayout(e=Y.MODEL_LAYOUT_NAME){if(this.activeLayoutName===e||!this.masterModelId)return;const i=this.loadedModels.find(u=>this.masterModelId===u.modelId);if(!i)return;const s=i.getLayoutByName(e);if(!s)return;const r=this.getActiveLayoutInfo();if(this.groundPlane){const u=this.getCurrentViewExtent(),f=this.camera.position.z;r.lastViewExtent=new d.Box3(new d.Vector3(u.min.x,u.min.y,0),new d.Vector3(u.max.x,u.max.y,f))}const n=u=>!!this.layoutInfos[u]?.lastViewExtent,a=n(e);i?.activateLayout(e,a),this.activeLayoutName=e;const o=i.getFilteredViewports(s);if(S.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const u=this.camera.position.z;let f=0;o.forEach(g=>{const x=g?.msToPsMatrix?.elements[14];x&&x>f&&(f=x)});const m=this.cameraManager.getPosition();if(f>m.z+u){const g=Math.ceil(f+u);m.z=g,S.info("[Viewer] Changing camera's z value from "+m.z+" to "+g),this.cameraManager.setCameraPosition(m)}}const l=this.getActiveLayoutInfo();if(l.lastViewExtent)this.zoomToBBox(l.lastViewExtent);else{l.extent=this.getBBox();let u=this.getLayoutExtentEx(s);if(u){const g=u.max.x-u.min.x,x=u.max.y-u.min.y;(g<1e-16||x<1e-16||g>1e16||x>1e16)&&(S.warn("[Viewer] Got wired bbox, max: "+u.max.toArray()+", min: "+u.min.toArray()+", going to use the calculated one..."),u=l.extent)}else S.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),u=l.extent;l.homeViewExtent=u,this.zoomToBBox(u)}const c=i.getLayoutLevelObject(e);c&&this.setLayoutHidableObjectArray(c),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===Y.MODEL_LAYOUT_NAME?i.getModelSpaceExtent():i.getLayoutExtent(e)}getActiveLayoutInfo(){return this.getLayoutInfo(this.activeLayoutName)}getLayoutByName(e){let i;const s=this.loadedModels.find(n=>this.masterModelId===n.modelId);if(!s)return;const r=s.getLayouts();for(const n of r)if(n.layoutName===e){i=n;break}return i}getEntityCount(){let e=0;return this.loadedModels.forEach(i=>{e+=i.loadedEntityCount}),e}getLayoutNames(){const e=[];return(this.loadedModels.find(r=>this.masterModelId===r.modelId)?.getLayouts()||[]).forEach(r=>{e.push(r.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):S.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Bt),s=e.max.x-e.min.x,r=e.max.y-e.min.y,n=this.camera.right-this.camera.left,a=this.camera.top-this.camera.bottom;let o=Math.min(n/s,a/r);o/=1.1,this.cameraManager.cameraControls.moveTo(i.x,i.y,i.z),this.cameraManager.cameraControls.zoomTo(o)}getCurrentViewExtent(){const e=this.getHitResultByNdcCoordinate(new d.Vector2(-1,-1)),i=this.getHitResultByNdcCoordinate(new d.Vector2(1,1));return new d.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 r=s[0].point;return new d.Vector2(r.x,r.y)}}getHitResult(e){const i=this.viewerContainer,s=pe.getScreenCoordinateByEvent(e,i),r=pe.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(r)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new Is(this)),this.textSearchHelper.search(e,i)}focusText(e){!this.textSearchHelper&&(this.textSearchHelper=new Is(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)}getLayers(){const e=[];if(this.masterModelId){const i=this.loadedModels.find(r=>this.masterModelId===r.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 r=i.layers;r&&e.push({modelId:s,layers:r})}return e}setModelVisibility(e,i){const s=this.loadedModels.find(r=>e===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+e+"'!");s.setVisible(i),this.enableRender()}setLayerVisibility(e,i,s){const r=this.camera;s=s||this.masterModelId;const n=this.loadedModels.find(a=>s===a.modelId);if(!n)throw new Error("Failed to find layer by modelId '"+s+"'!");n.setLayerVisible(e,i,this.enableHideVisuallySmallObjects,r.zoom),this.raycastableObjects=void 0,this.enableRender()}setLayerOpacity(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");r.setLayerOpacity(e,i),this.enableRender()}setLayerColor(e,i,s){s=s||this.masterModelId;const r=this.loadedModels.find(n=>s===n.modelId);if(!r)throw new Error("Failed to find layer by modelId '"+s+"'!");this.clearSelection(),r.setLayerColor(e,i),this.enableRender()}resetLayerColor(e,i){i=i||this.masterModelId;const s=this.loadedModels.find(r=>i===r.modelId);if(!s)throw new Error("Failed to find model by modelId '"+i+"'!");this.clearSelection(),s.resetLayerColor(e),this.enableRender()}getVisiblePixelSize(e){const i=d.MathUtils.smoothstep(e,1e4,3e4)*6.5+.5;return S.debug("[Viewer] visiblePixelSize:",i),i}setLayoutHidableObjectArray(e){const i=this.camera;if(!this.enableHideVisuallySmallObjects||!i)return;const s=Date.now(),r=e.name;this.sortedHidableObjects[r]||(this.sortedHidableObjects[r]=[]);const n=this.sortedHidableObjects[r];this.cameraManager.update(0);const a=i.zoom;this.lastCameraZoom=a;let o=1;e.traverse(c=>{if(c.userData.isSnapObject||!$.isLeafObject(c))return;const u=c.geometry;u.boundingBox||u.computeBoundingBox();const f=u.boundingBox.clone();if(!f||!z.isBoxValid(f))return;f.applyMatrix4(c.matrixWorld),f.getSize(Bt);const m=Math.max(Bt.x,Bt.y),g=o/m;g<1/0?n.push({visibleMinZoom:g,object:c}):c instanceof d.Points?n.push({visibleMinZoom:o,object:c}):S.warn("[Viewer] The size of bbox is 0 ! ",c)}),o=this.getVisiblePixelSize(n.length);let l=0;n.forEach(c=>{const u=c.visibleMinZoom*o;c.visibleMinZoom=u,c.object.userData.visibleMinZoom=u,u>a&&(c.object.visible=!1,l++)}),n.sort((c,u)=>c.visibleMinZoom-u.visibleMinZoom),S.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||(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,!this.sortedHidableObjects[this.activeLayoutName]))return;const r=this.sortedHidableObjects[this.activeLayoutName];if(r.length===0)return;const n=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let c=0;for(let u=0;u<r.length;++u)if(r[u].object.userData.layerVisible!==!1){if(r[u].visibleMinZoom<a){l.push(r[u].object);continue}else if(r[u].visibleMinZoom>o)break;r[u].object.visible=n,n&&l.push(r[u].object),c++}this.lastCameraZoom=s,S.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+c+"(out of "+r.length+") objects changed to "+(n?"visible":"hidden"))}updateCameraZoomUniform(e){Y.CameraZoomUniform.value=e*this.container.height/50}}class Zn{constructor(t){p(this,"viewer");p(this,"fontManager");p(this,"loader");p(this,"loadingManager");p(this,"changes");p(this,"container");p(this,"spinner");p(this,"jobCount");p(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Gs(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Us(t.containerId);this.loadingProgressBar=new Hs(i);const s={ignorePaperSpace:!0};this.loader=new Y(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 Ke),await this.fontManager.loadFonts(t),S.info("[DxfCompareHelper] Font file(s) load time in "+(Date.now()-e)/1e3+"s")}async compare(t,e,i,s){const{src:r,modelId:n}=t,{src:a}=e;this.viewer.masterModelId=n||r;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=r+a,c=Re.t("ProgressBar.Comparing"),u=k=>{this.loadingProgressBar?.updateProgress(l,c,k),s&&s(new ProgressEvent("CompareProgress",{loaded:k,total:100}))},f=(k,B,L)=>{let q=k.loaded*100/k.total;q=q*(L-B)/100+B,this.loadingProgressBar?.updateProgress(l,c,q),s&&s(new ProgressEvent("CompareProgress",{loaded:q,total:100}))},m=k=>f(k,0,15),g=k=>f(k,15,30),x=k=>f(k,30,60),y=k=>f(k,60,95);z.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),u(0);let T=Date.now();const v=this.loader.parse(r,m),b=this.loader.parse(a,g),[E,O]=await Promise.allSettled([v,b]);if(E.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+a);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-T)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const _=E.value,C=O.value;T=Date.now();const w=await new Ue(_,C,i).compare(x);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-T)/1e3+"s"),S.debug("[DxfCompareHelper] Compared results:",w),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");z.printMemory("After getting the comparison results"),T=Date.now(),await this.loader.loadEntitiesForCompare(_,C,w,!0,y),z.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=w,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-T)/1e3+"s");const M=_,P=C;if(this.decreaseJobCount(),!Object.keys(w).length&&S.info("[DxfCompareHelper] No change found"),M.threejsObject?.children.length===0&&P.threejsObject?.children.length===0){const k="[DxfCompareHelper] Nothing was loaded from "+r+" and "+a;return S.warn(k),Promise.reject(k)}const A=M.threejsObject,I=P.threejsObject;return A.name=r,I.name=a,T=Date.now(),this.viewer.addModel(new Wt({modelId:t.modelId||t.src,dxfData:M})),this.viewer.flyToObject(A),z.printMemory("After adding first loaded Model to scene"),u(95),this.viewer.addModel(new Wt({modelId:e.modelId||e.src,dxfData:P})),z.printMemory("After adding second loaded Model to scene"),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-T)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+r+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),u(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 cc extends Zn{constructor(e,i){super(e);p(this,"viewer2");p(this,"syncCamera");p(this,"markupManager1");p(this,"markupManager2");p(this,"syncCameraControls");this.syncCamera=!1,this.syncCameraControls=(s,r,n)=>{const a=new d.Vector3,o=new d.Vector3,l=new d.Vector3;s.getPosition(o),s.getTarget(l),s.getFocalOffset(a),r.setLookAt(o.x,o.y,o.z,l.x,l.y,l.z),r.zoomTo(n),r.dispatchEvent({type:"control"})},this.viewer2=new Gs(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,r){const{src:n,modelId:a}=e,{src:o,modelId:l}=i;this.viewer.masterModelId=a||n,this.viewer2.masterModelId=l||o;const c=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 u=n+o,f=Re.t("ProgressBar.Comparing"),m=L=>{this.loadingProgressBar?.updateProgress(u,f,L),r&&r(new ProgressEvent("CompareProgress",{loaded:L,total:100}))},g=(L,q,me)=>{let ue=L.loaded*100/L.total;ue=ue*(me-q)/100+q,this.loadingProgressBar?.updateProgress(u,f,ue),r&&r(new ProgressEvent("CompareProgress",{loaded:ue,total:100}))},x=L=>g(L,0,15),y=L=>g(L,15,30),T=L=>g(L,30,60),v=L=>g(L,60,95);z.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(u),m(0);let b=Date.now();const E=this.loader.parse(n,x),O=this.loader.parse(o,y),[_,C]=await Promise.allSettled([E,O]);if(_.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+n);if(C.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+o);if(S.info("[DxfCompareHelper] loadFiles in "+(Date.now()-b)/1e3+"s"),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare loadFile aborted");const w=_.value,M=C.value;b=Date.now();const P=await new Ue(w,M,s).compare(T);if(S.info("[DxfCompareHelper] Compared in "+(Date.now()-b)/1e3+"s"),S.debug("Compared results:",P),this.loader.isAborted())return Promise.reject("[DxfCompareHelper] compare change aborted");z.printMemory("After getting the comparison results"),b=Date.now(),await this.loader.loadEntitiesForCompare(w,M,P,!1,v),z.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=P,S.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-b)/1e3+"s");const A=w,I=M;if(this.decreaseJobCount(),!Object.keys(P).length&&S.info("[DxfCompareHelper] No change found"),A.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const L="[DxfCompareHelper] Nothing was loaded from "+n+" and "+o;return S.warn(L),Promise.reject(L)}const k=A.threejsObject,B=I.threejsObject;return k.name=n,B.name=o,b=Date.now(),this.viewer.addModel(new Wt({modelId:e.modelId||e.src,dxfData:A})),z.printMemory("After adding first loaded Model to scene"),m(95),this.viewer2.addModel(new Wt({modelId:i.modelId||i.src,dxfData:I})),z.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),S.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-b)/1e3+"s"),S.info("[DxfCompareHelper] The comparison between "+n+"' and '"+o+"' is completed in "+(Date.now()-c)/1e3+"s !"),m(100),this.loadingProgressBar?.delayRemoveProgressItem(u),Promise.resolve()}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new As(this.viewer)),this.markupManager2??(this.markupManager2=new As(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 jt{constructor(t,e){p(this,"current");p(this,"next");p(this,"inNormal");p(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 jt.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return jt.offsetEdge(this.next,this.current,t,e)}inverse(){return new jt(this.next,this.current)}static offsetEdge(t,e,i,s){return new jt([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const ri=Array.isArray,en=(h,t)=>h[0]===t[0]&&h[1]===t[1],Cs=h=>Array.isArray(h)&&h.length,Kn=(h,t=0,e=!1)=>{let i,s;if(Cs(h)&&typeof h[0][0]=="number"){let r=0;const n=h;for(i=0,s=n.length;i<s;i++){const a=n[i],o=n[(i+1)%s];r+=a[0]*o[1],r-=o[0]*a[1]}(!e&&r>0||e&&r<0)&&n.reverse()}else for(i=0,s=h.length;i<s;i++)Kn(h[i],t+1,i>0);if(t===0&&Cs(h)&&Cs(h[0])&&typeof h[0][0][0]=="number"){const r=h[0].slice(0,1)[0];h[0].pop(),h[0].push([r[0],r[1]])}return h};class dc{constructor(t,e=5){p(this,"vertices");p(this,"edges");p(this,"arcSegments");p(this,"distance");if(this.distance=0,this.arcSegments=e,!ri(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],ri(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=Kn(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(ri(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,en(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new jt(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,r,n,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),c=Math.atan2(r[1]-e[1],r[0]-e[0]);n%2===0&&(n-=1),l<0&&(l+=o),c<0&&(c+=o);let u=l>c?l-c:l+o-c;const f=(a?-u:o-u)/n;t.push(s);for(let m=1;m<n;++m)u=l+f*m,t.push([e[0]+Math.cos(u)*i,e[1]+Math.sin(u)*i]);return t.push(r),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return en(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 r=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],n=[];for(let a=0,o=2;a<o;a++){const l=r[a],c=r[(a+o-1)%o];this.createArc(n,a===0?t:e,s,c.next,l.current,this.arcSegments,!0)}return n}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=Zt.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 Zt.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(ri(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,r=this.edges.length;s<r;s++){const n=this.offsetContour(this.vertices[s],this.edges[s]);n.length>0&&i.push(n)}i.length>0&&(e=i.length===1?i[0]:Zt.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,r=0;if(ri(t[0])&&typeof t[0][0]=="number"){for(s=0,r=t.length-1;s<r;s++){const n=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[n];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Zt.union(i[0],i.slice(1)))}else{const n=[];for(s=0,r=e.length;s<r;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&n.push(a)}n.length>0&&(i=n.length===1?n[0]:Zt.union(n[0],...n.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,r=this.distance;let n=0;e%2===0&&e++;for(let a=0;a<e;a++)n+=2*Math.PI/e,i.push([s[0]+r*Math.cos(n),s[1]+r*Math.sin(n)]);return[[this.ensureLastPoint(i)]]}}class $n{constructor(t){p(this,"viewer");p(this,"composerEnabled");p(this,"composer");p(this,"renderPass");p(this,"effectFxaaPass");p(this,"saoPass");p(this,"ssaoPass");p(this,"outlinePass");p(this,"ssaaRenderPass");p(this,"bloomPass");p(this,"unrealBloomPass");p(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Ba.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(re.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:r}=this.viewer.container;if(this.composer){if(t&&!this.renderPass){const n=new La.RenderPass(e,i);n.setSize(s,r),this.composer.addPass(n),this.renderPass=n}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 Ra.ShaderPass(Na.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,r=this.viewer.camera;if(this.composer){if(t&&!this.saoPass){const n=new Fa.SAOPass(s,r,new d.Vector2(1/e,1/i));n.setSize(e,i),n.params.output=0,n.params.saoBias=.5,n.params.saoIntensity=3e-4,n.params.saoScale=8,n.params.saoKernelRadius=40,n.params.saoMinResolution=0,this.composer.addPass(n),this.saoPass=n}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:r}=this.viewer.container;if(this.composer){if(t&&!this.ssaoPass){const n=new za.SSAOPass(e,i,s,r);n.kernelRadius=16,n.minDistance=1e-4,n.maxDistance=.3,this.composer.addPass(n),this.ssaoPass=n}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:r}=this.viewer.container;if(this.composer){if(t&&!this.outlinePass){const n=new ja.OutlinePass(new d.Vector2(s,r),e,i);n.edgeStrength=3,n.edgeGlow=0,n.edgeThickness=2,n.pulsePeriod=0,n.visibleEdgeColor.set(16711680),n.hiddenEdgeColor.set(16752768),this.composer.addPass(n),this.outlinePass=n}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 Va.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 Ua.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 Ha.UnrealBloomPass(new d.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 zs)if(t&&!s.edges){const r=s.getModelObject();r&&(S.debug("[Viewer] Generating outlines for model '"+r.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(r=>r.visible=t);else s instanceof Vs&&S.warn("[BimTiles] enableModelEdges() is not implemented for bimtiles yet.")}this.viewer.enableRender()}showVertexNormals(t,e=.1){t?(!this.vertexNormalsHelpers&&(this.vertexNormalsHelpers=new d.Group),this.viewer.scene.traverseVisible(i=>{const s=["SKYBOX","GROUND_GRID","GROUND_GRASS","BIM_VIEWER_BOX_HELPER"];if(i instanceof d.Mesh&&!s.includes(i.name)){if(!i.geometry.attributes.normal)return;const n=new Ga.VertexNormalsHelper(i,e,16711680);this.vertexNormalsHelpers?.add(n)}}),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 uc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"loadedModels");p(this,"distanceCullingFactor");p(this,"selectedObject");p(this,"effect");if(this.name=Be.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new $n(this),this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(He.Orbit),this.setupDefaultEvents(),this.setDefaultBackground()}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button;const m=new d.Vector2(f.x,f.y);c=this.pickObject(m),u=c?.object===this.selectedObject,f.button===Le.Left&&this.handleAnchorPoint(c)}),this.inputManager.addEventListener("pointermove",f=>{i!==void 0&&(e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0))}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?.object?this.flyToObject(c.object):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.selectedObject instanceof pt?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c?.object&&!u&&this.handleClickObject(c.object)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.renderer.setClearColor(11119017,1),this.sceneManager.setBackground(null),this.sceneManager.setEnvironmentFromData()}handleAnchorPoint(e){const i=new d.Vector3;this.selectedObject?new d.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=n=>!n.userData.modelId&&n.parent?i(n.parent):n.userData.modelId,s=i(e);this.loadedModels.find(n=>n.modelId===s)?.highlightObject(e),this.selectedObject=e,this.enableRender()}is3d(){return!0}async loadLocalModel(e,i,s,r){return this.loadModelInternal(i,r,!0,e,s)}async loadModel(e,i){return this.loadModelInternal(e,i)}async loadModelInternal(e,i,s,r,n){this.spinner.increaseJobCount();const a=e.modelId||e.src,o=Re.t("ProgressBar.Loading"),l=b=>{this.progressBar?.updateProgress(a,o,b),i?.(new ProgressEvent("LoadProgress",{loaded:b,total:100}))};let c=!1;const u=(b,E,O)=>{let _=b.loaded*100/b.total;_=_*(O-E)/100+E,_>O&&(c||(S.warn("[Progress] Invalid ProgressEvent:",b),c=!0),_=O),this.progressBar?.updateProgress(a,o,_),i?.(new ProgressEvent("LoadProgress",{loaded:_,total:100}))},f=b=>u(b,0,50);this.progressBar?.addProgressItem(a),l(0);let m;if(s?(this.loaderHelper.setLoadManager(n),m=await this.loaderHelper.loadLocalModel(r,e.src,i)):m=await this.loaderHelper.loadModel(e.src,e.fileFormat,f),e.matrix&&e.matrix.length===16){const b=new d.Matrix4;b.elements=e.matrix,m.applyMatrix4(b)}const g=this.getUniqueModelId(e.modelId||e.src),x=new zs({modelId:g,object:m});this.addModel(x),l(90);const y=x.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const v=new d.Vector3;y.getCenter(v),this.cameraManager.setOrbitPoint(v),this.spinner.decreaseJobCount(),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(re.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(r=>r.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(r=>r.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 pt&&(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(r=>r.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function tn(h){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),h)}function sn(h){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}),h)}function fc(h){const t={transform:new d.Matrix4,boundingVolume:new d.Box3};return Object.assign(Object.assign({},t),h)}class pc{constructor(t){p(this,"url");p(this,"metadata");p(this,"statistics");p(this,"view");this.url=t,this.metadata=tn(),this.statistics=sn(),this.view=fc()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(S.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=tn(t.metadata),this.statistics=sn(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 mc=0;class gc extends Qi{constructor(e,i){super(e);p(this,"name");p(this,"pickUsageScene");p(this,"effect");p(this,"loadedModels");p(this,"selectedObject");p(this,"enableHoverEffect");if(this.name=Be.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new $n(this),this.pickUsageScene=new d.Scene,this.sceneManager.enableLights(!0),i)this.setHomeView(i),this.cameraManager.flyToViewpoint(i);else{const s=new d.Vector3(100,50,100),r=new d.Vector3(0,0,0),n={eye:s,look:r};this.cameraManager.flyToViewpoint(n)}this.cameraManager.setProjection($e.Perspective),this.cameraManager.setNavigationMode(He.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(re.BeforeRender,()=>{this.update3dTiles()})}setupDefaultEvents(){let e=!1,i,s=0,r=0,n=0;const a=300,o=f=>r===-1||n===-1?!1:Math.abs(f.x-r)<5&&Math.abs(f.y-n)<5,l=f=>{const m=f.timestamp-s;return!!(f.button===Le.Left&&m<a&&o(f))};let c,u=!1;this.inputManager.addEventListener("pointerdown",f=>{e=!1,i=f.button,this.renderImmediately();const m=new d.Vector2(f.x,f.y);if(c=this.pickManager.pick(m,this.pickUsageScene),u=!!this.selectedObject&&c?.tilesetId===this.selectedObject?.tilesetId&&c?.userId===this.selectedObject?.userId,f.button===Le.Left){let g=this.pickUsageScene;if(c){const y=this.loadedModels.find(T=>T.modelId===""+c?.tilesetId);if(y){const T=y.getObjectByUserId(c.userId);T&&(g=T)}}const x=this.pickManager.pickObject(m,[g]);this.handleAnchorPoint(x)}}),this.inputManager.addEventListener("pointermove",f=>{if(i!==void 0)e=!o(f),i===Le.Left&&this.cameraManager.enableRotate&&this.cameraManager.setOrbitPointVisible(!0);else if(this.enableHoverEffect){const m=new d.Vector2(f.x,f.y),g=this.pickManager.pick(m,this.pickUsageScene),x=this.getHoveredObject();g?(!x||x.tilesetId!==g.tilesetId||x.userId!==g.userId)&&this.setObjectHoveredByUserId(g.tilesetId,g.userId,!0):x&&this.clearHovered()}this.handleMouseMove(f)}),this.inputManager.addEventListener("pointerup",f=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}f.button===Le.Left?l(f)?(c?this.flyToUserId(c.tilesetId,c.userId):this.viewFitAll(),s=0,r=-1,n=-1):(this.selectedObject&&(this.clearHighlight(),this.selectedObject=void 0),s=f.timestamp,r=f.x,n=f.y,c&&!u&&this.handleClickObject(c)):(f.button,Le.Right)})}setDefaultBackground(){this.sceneManager.setBackground(new d.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 d.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(r=>r.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){S.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){S.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(r=>r.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 pt&&(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(r=>r.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 pc(e.src);if(!await s.parse())return Promise.reject();let n=e.src.replace(/\/[^\\/]*\/?$/,"/");n=new URL(n,window.location.href).toString(),this.spinner.increaseJobCount();const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Vs({modelId:""+mc++,bbox:a},n,s),l=o.getTilesRenderer(),c=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=u=>{u.traverse(f=>{f.matrixAutoUpdate&&(f.matrixAutoUpdate=Ne,f.updateMatrix()),f.isMesh&&(f.castShadow=!0,f.receiveShadow=!0),f.geometry&&f.layers.enableAll()}),this.enableRender(),setTimeout(()=>this.spinner.decreaseJobCount(),100)},l.setCamera(this.camera),l.setResolutionFromRenderer(this.camera,this.renderer),l.update(),c){c.applyMatrix4(s.getView().transform),o.pickUsageGroup.applyMatrix4(s.getView().transform),this.pickUsageScene.add(o.pickUsageGroup),this.addModel(o),this.cameraManager.adjustCameraByBBox(a);const u=new d.Vector3;return a.getCenter(u),this.cameraManager.setOrbitPoint(u),this.loadedModels.length===1&&this.goToHomeView(),this.spinner.decreaseJobCount(),this.dispatchEvent(re.ModelLoad),Promise.resolve()}return this.spinner.decreaseJobCount(),Promise.reject()}setObjectHighlightedByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectHighlightedByUserIds(i,s),this.enableRender()}setObjectOpacityByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectOpacityByUserIds(i,s),this.enableRender()}setOtherObjectOpacityByUserIds(e,i,s){this.loadedModels.forEach(a=>{a.setOpacity(s)});const r=""+e;this.loadedModels.find(a=>a.modelId===r)?.clearObjectOpacityByUserIds(i),this.enableRender()}setObjectVisibleByUserIds(e,i,s){this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,s),this.enableRender()}setOtherObjectVisibleByUserIds(e,i,s){this.loadedModels.forEach(n=>{n.setVisible(s)}),this.loadedModels.find(n=>n.modelId===""+e)?.setObjectVisibleByUserIds(i,!s),this.enableRender()}setObjectHoveredByUserId(e,i,s){if(!this.enableHoverEffect)return;this.clearHovered(),this.loadedModels.find(n=>n.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(r=>r.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 r=this.pickUsageScene;if(s){const a=this.loadedModels.find(o=>o.modelId===""+s?.tilesetId);if(a){const o=a.getObjectByUserId(s.userId);o&&(r=o)}}let n=this.pickManager.pickObjects(e,[r],i);return n&&this.renderer.clippingPlanes.length>0&&(n=n.filter(a=>this.renderer.clippingPlanes.every(function(o){return o.distanceToPoint(a.point)>0}))),n}getErrorTarget(){return this.loadedModels.length>0?this.loadedModels[0].getTilesRenderer().errorTarget:8}setErrorTarget(e){this.loadedModels.forEach(i=>{i.getTilesRenderer().errorTarget=e})}}class yc extends mt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();p(this,"id");p(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}K.install({THREE:d});class xc extends K{constructor(e,i){super(e,i);p(this,"minZoom");p(this,"draggingSmoothTime");p(this,"dollySpeedBackup");p(this,"azimuthRotateSpeedBackup");p(this,"polarRotateSpeedBackup");p(this,"truckSpeedBackup");p(this,"onKeyDown");p(this,"onKeyUp");p(this,"keyTruckSpeed");p(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 Jn=(h=>(h[h.Browser=0]="Browser",h[h.Browserless=1]="Browserless",h[h.Headless=2]="Headless",h))(Jn||{});class bc{constructor(t,e,i){p(this,"containerOrCanvas");p(this,"glContext");p(this,"camera");p(this,"scene");p(this,"renderer");p(this,"renderTarget");p(this,"controls");p(this,"selectedObject");p(this,"loadedModels");p(this,"pmremGenerator");p(this,"clock");p(this,"viewerMode");p(this,"raycaster");p(this,"savedMaterialsForOpacity");p(this,"jobCount");p(this,"bbox");p(this,"outlineMaterial");p(this,"outlineRoot");p(this,"transparentObjectIds");p(this,"requestAnimationFrameHandle");p(this,"applyOptionsAndAddToScene");p(this,"getMeshes");if(this.scene=this.initScene(),this.selectedObject=void 0,this.loadedModels=[],this.clock=new d.Clock,this.viewerMode=0,this.raycaster=new d.Raycaster,this.savedMaterialsForOpacity=[],this.jobCount=0,this.bbox=new d.Box3,this.outlineMaterial=new d.LineBasicMaterial({color:1118481}),this.outlineRoot=new d.Group,this.transparentObjectIds=[],this.applyOptionsAndAddToScene=async(s,r,n,a)=>{if(S.info("[Viewer] '"+s+"' is loaded, adding to scene..."),n.matrix&&n.matrix.length===16){const f=new d.Matrix4;f.elements=n.matrix,r.applyMatrix4(f)}r.traverse(f=>{f.geometry&&f.layers.enableAll(),f instanceof d.Light&&(f.visible=!1)});let o;n.edges&&(o=await $.createOutlines(r,void 0,a));let l=n.modelId||n.src;const c=f=>!!this.loadedModels.find(m=>m.modelId===f);if(c(l)){let f=1;for(;c(l+"_"+f);)f++;l=l+"_"+f,S.warn("[Viewer] Model '"+l+"' is loaded more than once!")}const u={modelId:l,object:r,edges:o};this.addModel(u)},this.getMeshes=s=>{const r=[];return s instanceof d.Mesh?r.push(s):s.traverseVisible(n=>{n instanceof d.Mesh&&r.push(n)}),r},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(),S.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 d.Scene;return t.background=new d.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 d.WebGLRenderer(t);if(e){const s=this.containerOrCanvas.width,r=this.containerOrCanvas.height;S.info("[Viewer] Render target size: "+s+" x "+r),this.renderTarget=new d.WebGLRenderTarget(s,r,{minFilter:d.LinearFilter,magFilter:d.NearestFilter,format:d.RGBAFormat,type:d.UnsignedByteType}),i.setRenderTarget(this.renderTarget)}else{const s=this.containerOrCanvas.clientWidth,r=this.containerOrCanvas.clientHeight;this.containerOrCanvas.append(i.domElement),i.setPixelRatio(window.devicePixelRatio),i.setSize(s,r)}i.outputColorSpace=d.SRGBColorSpace,i.toneMappingExposure=1,i.setClearColor(11119017,1),i.shadowMap.enabled=!0,i.shadowMap.type=d.PCFSoftShadowMap,this.renderer=i,e||(this.pmremGenerator=new d.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 d.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 xc(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 d.DirectionalLight(t,e);i.position.set(-2,2,4);const s=new d.AmbientLight(3158064),r=new d.HemisphereLight(t,14540253,3);r.position.set(0,300,0),this.scene.add(i),this.scene.add(s),this.scene.add(r)}initPointerEvents(){if(!this.renderer||!this.camera||!this.controls)return;let t=!1,e=!1,i=-1,s=-1;this.renderer.domElement.addEventListener("pointerdown",r=>{i=r.x,s=r.y,t=!1}),this.renderer.domElement.addEventListener("pointermove",r=>{i>=0&&s>=0&&(Math.abs(r.x-i)>5||Math.abs(r.y-s)>5)&&(t=!0)}),this.renderer.domElement.addEventListener("pointerup",()=>{e&&setTimeout(()=>{e=!1},200),i=-1,s=-1}),this.renderer.domElement.addEventListener("dblclick",r=>{e=!0,t||(this.handleMouseClick(r),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 r=await new ut().loadLocalModel(t,e.src,i);return r?(await this.applyOptionsAndAddToScene(t,r,e),Promise.resolve()):Promise.reject()}async loadModel(t,e){this.increaseJobCount();const s=await new ut().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 ut().parseGltf(t,e.src,r=>{this.applyOptionsAndAddToScene(e.src,r,e),i&&i(r)},r=>{s&&s(r)})}addModel(t){if(!this.scene||!this.renderer)return;this.increaseJobCount();const e=new d.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,S.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 r=this.scene,n=[];this.loadedModels.forEach(a=>{const o=a.object.id;if(t){this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity);const l=$.setObjectOpacityById(r,o,e,i,s);n.push(...l)}else this.savedMaterialsForOpacity&&$.revertObjectOpacityById(r,o,this.savedMaterialsForOpacity)}),t?this.savedMaterialsForOpacity=n:this.savedMaterialsForOpacity=[]}hasTransparentObject(){return!!(this.savedMaterialsForOpacity&&this.savedMaterialsForOpacity.length>0)}getIntersections(t){if(!this.raycaster||!this.camera||!this.scene)return[];let e=new d.Vector2;t&&(e=pe.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=pe.screen2Ndc(e,this.camera,this.containerOrCanvas);this.raycaster.setFromCamera(i,this.camera);const s=[];return this.loadedModels.forEach(r=>{const n=r.object;n&&n.visible&&s.push(n)}),this.raycaster.intersectObjects(s,!0)||[]}handleMouseClick(t){this.raycaster&&this.raycaster.layers.set(ft);const i=this.getIntersections(t).find(r=>{const n=r.object;return n.visible&&n instanceof d.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(r=>r.dispose()):s instanceof d.Material&&s.dispose()}this.selectedObject.material=i.originalMaterial,delete i.originalMaterial}this.selectedObject=void 0}if(!this.scene||!t)return;const e=de.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 d.Box3;t.forEach(r=>{const n=rt.getBoundingBox(r);e.union(n)});const i=new d.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,r=this.controls;if(!s||!r)return;t=Array.isArray(t)?new d.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new d.Vector3(e[0],e[1],e[2]):e;const n=t,a=e;S.info("[Viewer] flyTo: ",z.vectorToString(n)),r.setPosition(n.x,n.y,n.z),r.setTarget(a.x,a.y,a.z),this.isBrowserMode()||this.renderer?.render(this.scene,s),i&&i()}goToHomeView(){const t=new d.Sphere;this.bbox.getBoundingSphere(t),this.controls?.fitToSphere(t,!0)}setEnvironmentFromDataArray(t){pi.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,r=e.max.x-e.min.x,n=e.max.y-e.min.y,a=e.max.z-e.min.z,o=Math.max(r,n,a),l=5,c=o/l,u=o*l;if(i>c||s<u){const f=m=>z.numberToString(m);S.info("[Viewer] BBox's longest side is: "+f(o)),i>c&&(S.warn("[Viewer] camera.near("+f(i)+") shouldn't bigger than "+f(c)+", will change it!"),t.near=c),s<u&&(S.warn("[Viewer] camera.far("+f(s)+") shouldn't smaller than "+f(u)+", will change it!"),t.far=u)}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 d.MeshBasicMaterial({color:16777215,transparent:!0,opacity:.1});this.loadedModels.forEach(n=>{const a=n.object.id;$.applyMaterialToObjectById(this.scene,a,s,i,e)}),this.outlineRoot.clear();let r=[];if(t.forEach(n=>{const a=n.modelId;let l=this.loadedModels.find(c=>c.modelId===a)?.object;l||(S.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(c=>{if(qs.includes(n.id,qs.get(c.userData,"UniqueId"))){const u=this.getMeshes(c);r=r.concat(u)}})}),r.length>0){r.forEach(a=>{const o=$.createOutline(a.geometry,this.outlineMaterial);o.applyMatrix4(a.matrixWorld),this.outlineRoot.add(o),o.updateWorldMatrix(!0,!1)});const n=r.map(a=>a.id);this.loadedModels.forEach(a=>{const o=a.object.id;$.revertAppliedMaterialToObjectById(this.scene,o,n)}),this.transparentObjectIds=n,this.flyToObjects(r)}else S.warn("[Viewer] No object found with uniqueIds: "+t.map(n=>n.id));this.isBrowserMode()||this.animate()}increaseJobCount(){++this.jobCount}decreaseJobCount(){--this.jobCount}computeBoundingBox(){const t=new d.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 d.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 Qn="1.0.0",ea="VERSION",ta=()=>window.localStorage.getItem(ea),ia=()=>{window.localStorage.setItem(ea,Qn)},vc=()=>ta()!==Qn?(ia(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>Se.Mesh});exports.BaseDxfCompareHelper=Zn;exports.BaseViewer=Qi;exports.BimTilesModel=Vs;exports.BimTilesRenderer=Bn;exports.BimTilesViewer=gc;exports.BinaryReader=vi;exports.BoxSelectHelper=$i;exports.ByBlock=mi;exports.ByLayer=Fs;exports.CSS2DObjectUtils=mo;exports.CameraProjection=$e;exports.CancelablePromise=uo;exports.CanvasRender=xi;exports.ColorUtils=qt;exports.CommonUtils=z;exports.CompareDrawable=Je;exports.Container=Us;exports.ControlsMode=He;exports.CoordinateUtils=pe;exports.DecimalPrecisionRange=an;exports.DefaultCameraFar=Hi;exports.DefaultCameraFov=hn;exports.DefaultCameraNear=Ui;exports.DefaultLanguage=on;exports.DefaultOpacity=Ls;exports.DefaultViewer3dConfig=Lh;exports.DeviceUtils=be;exports.Drawable=pt;exports.DrawableList=bi;exports.DxfChangeType=Te;exports.DxfCompare=Ue;exports.DxfCompareHelper=cc;exports.DxfCompareMarkupManager=As;exports.DxfLoader=Y;exports.DxfParser=Tn;exports.DxfRenderOrder=ge;exports.DxfUtils=et;exports.EdgeUtils=cn;exports.Event=mt;exports.ExportUtils=Ss;exports.FontManager=Ke;exports.FpsUtils=To;exports.GenerateMeshBvhWorker=Nn;exports.GeometryUtils=U;exports.GroundPlaneRenderOrder=Xn;exports.HighlightColor=Bs;exports.HighlightColorRgba=yo;exports.IconfontClass=xo;exports.IconfontClass2=bo;exports.InputManager=Yn;exports.InstantiateHelper=Nh;exports.LayerForHitableObjects=ln;exports.LayerForSelectableObjects=ft;exports.LayerForSnapableObjects=Ce;exports.Line=Ya;exports.LinePatternShaders=bn;exports.LoadingHelper=ut;exports.MaterialUtils=de;exports.MathUtils=R;exports.MatrixAutoUpdate=Ne;exports.MergeUtils=oe;exports.MeshBvhHelper=Ns;exports.MobileTouchHelperDrawable=ac;exports.Model=Ji;exports.Model2d=Wt;exports.Model3d=zs;exports.NestedCompareTypes=oi;exports.OSnapHelper=tc;exports.OSnapIconSize=Io;exports.OSnapMarkerType=it;exports.OSnapType=Gn;exports.ObjectPixelSizeHelper=Xh;exports.ObjectUtils=$;exports.Offset=dc;exports.OrbitControls=Fn;exports.OutlineColorRgba=Vi;exports.PickMarkupHelper=ic;exports.PlanControls=zn;exports.Plugin=yc;exports.Points=Xa;exports.PolygonUtils=Po;exports.ProgressBar=Hs;exports.RafHelper=Un;exports.SVGObjectUtils=ko;exports.SceneUtils=rt;exports.SectionUtils=dt;exports.ShaderChunk=co;exports.SimplifyUtils=Ao;exports.SnapDrawable=ye;exports.Spinner=Ln;exports.TextSearchHelper=Is;exports.TextureUtils=pi;exports.ThresholdAngleForEdge=Rs;exports.UnitConversionByMeter=Es;exports.UnitLabels=dn;exports.UnitScaleConversion=Yo;exports.UnitScaleToMeter=Ps;exports.Units=De;exports.Viewer2d=Gs;exports.Viewer3d=uc;exports.Viewer3dLite=bc;exports.Viewer3dUtils=Lo;exports.ViewerEvent=re;exports.ViewerMode=Jn;exports.ViewerName=Be;exports.Views=fn;exports.ZoomToRectHelper=Wn;exports.bspline=mn;exports.checkIsNewVersion=vc;exports.cn=Os;exports.createHatchPatternShaderMaterial=vn;exports.decodeDxfTextCharacterCodes=gn;exports.decodeDxfTextMbcsCharacterCodes=xn;exports.decodeDxfTextUnicodeCodePoints=yn;exports.en=Co;exports.getLengthValueByUnit=Bo;exports.getUnitStr=_s;exports.getVersionFromLocalStorage=ta;exports.i18n=Re;exports.log=S;exports.parseDxfMTextContent=li;exports.parseDxfTextContent=Ni;exports.round10=pn;exports.setIcon=po;exports.setLogLevel=nn;exports.setVersionToLocalStorage=ia;exports.showPrecisionValue=go;
1531
+ `,qo=Symbol("INITIAL_FRUSTUM_CULLED");function K1(c,t){c.traverse(e=>{e.frustumCulled=e[qo]&&t})}const zs=new p.Vector3,Vs=new p.Vector3,Un=new p.Box3;class Wo extends zl.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=hc.parse(Z1).root,this.propertyParser=new q1(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=>Na(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=>Na(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 S=new p.InstancedMesh(m,this.materialManager?.pickMaterial,f);return S.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16),{mesh:w,pickMesh:S,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:S}=o.userData.batchTable.find(_=>_.userId===d),M=m.itemSize,O=m.array.slice(x*M,x*M+S*M),E=new p.Float32BufferAttribute(O,M);f.setAttribute("position",E);const v=y.array.slice(x,x+S),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?_e.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 X1().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}),K1(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)&&(Un.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(Un.getCenter(zs),Un.getSize(Vs),e.cached.boundingVolume.setObbData([zs.x,zs.y,zs.z,Vs.x/2,0,0,0,Vs.y/2,0,0,0,Vs.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 N1(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 _r extends fn{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 Wo(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(Zt.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(Zt.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(Zt.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(Zt.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(Zt.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(Zt.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 $1(){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 J1{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(he.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 Q1(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 Q1{constructor(t,e){g(this,"viewer");g(this,"eventBus");g(this,"element");g(this,"resetActivate");g(this,"active");this.viewer=t,this.eventBus=$1(),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 Yo{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 Pr{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 Ar{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=Ke.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 Ye=(c=>(c.BaseViewer="BaseViewer",c.Viewer3d="Viewer3d",c.Viewer2d="Viewer2d",c.BimTilesViewer="BimTilesViewer",c))(Ye||{}),mt=(c=>(c.Perspective="Perspective",c.Orthographic="Orthographic",c))(mt||{});const eu={enableSpinner:!0,containerId:"myCanvas"},W={LEFT:1,RIGHT:2,MIDDLE:4},L=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 st(c){return c.isPerspectiveCamera}function ze(c){return c.isOrthographicCamera}class tu{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 ui=Math.PI*2,Ga=Math.PI/2;function Nn(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 Hn(c,t){return ze(c)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Xo=1e-5,qi=Math.PI/180;function wi(c,t,e){return Math.max(t,Math.min(e,c))}function ne(c,t=Xo){return Math.abs(c)<t}function se(c,t,e=Xo){return ne(c-t,e)}function qa(c,t){return Math.round(c/t)*t}function Wi(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function Yi(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function js(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=wi(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 Wa(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,S=x*x,M=f*f+m*m+b*b;if(M>S){const R=Math.sqrt(M);f=f/R*x,m=m/R*x,b=b/R*x}h=c.x-f,d=c.y-m,u=c.z-b;const O=(e.x+a*f)*n,E=(e.y+a*m)*n,v=(e.z+a*b)*n;e.x=(e.x-a*O)*l,e.y=(e.y-a*E)*l,e.z=(e.z-a*v)*l,r.x=h+(f+O)*l,r.y=d+(m+E)*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 Us=1/8,iu=Ie.isBrowser&&/Mac/.test(navigator.platform),su=!(Ie.isBrowser&&"PointerEvent"in window);let q,Ya,Ns,Gn,Le,Y,te,fi,dt,ut,Wt,Xa,Za,tt,Xi,pi,Ka,qn,$a,Wn,Yn,Hs;class $ extends tu{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=L.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=Ie.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,S,M)=>{if(st(this._camera)){const O=Y.copy(this._camera.position).sub(this._target),E=this._camera.getEffectiveFOV()*qi,v=O.length()*Math.tan(E*.5),T=this.truckSpeed*x*v/this._elementRect.height,_=this.truckSpeed*S*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(ze(this._camera)){const O=this._camera,E=this.truckSpeed*x*(O.right-O.left)/O.zoom/this._elementRect.width,v=this.truckSpeed*S*(O.top-O.bottom)/O.zoom/this._elementRect.height;M?this.setFocalOffset(this._focalOffsetEnd.x+E,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(E,v,!0)}},this._rotateInternal=(x,S)=>{const M=ui*this.azimuthRotateSpeed*x/this._elementRect.height,O=ui*this.polarRotateSpeed*S/this._elementRect.height;this.rotate(M,O,!0)},this._dollyInternal=(x,S,M)=>{const O=Math.pow(.95,-x*this.dollySpeed),E=this._sphericalEnd.radius*O,v=this._sphericalEnd.radius,T=v*(x>=0?-1:1);this.dollyTo(E),this.infinityDolly&&(E<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&&(E<this.minDistance||this.maxDistance===this.minDistance)&&(this._dollyControlAmount-=T),this._dollyControlCoord.set(S,M))},this._zoomInternal=(x,S,M)=>{const O=Math.pow(.95,x*this.dollySpeed),E=this._zoomEnd;this.zoomTo(this._zoom*O),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-E,this._dollyControlCoord.set(S,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,Ns),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=L.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:L.ROTATE,middle:L.DOLLY,right:L.TRUCK,wheel:st(this._camera)?L.DOLLY:ze(this._camera)?L.ZOOM:L.NONE},this.touches={one:L.TOUCH_ROTATE,two:st(this._camera)?L.TOUCH_DOLLY_TRUCK:ze(this._camera)?L.TOUCH_ZOOM_TRUCK:L.NONE,three:L.TOUCH_TRUCK};const s=new q.Vector2,n=new q.Vector2,r=new q.Vector2,a=x=>{if(!this._enabled||!this._domElement)return;const S=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(S!==null){const O=this._findPointerByMouseButton(S);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:S};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 S=(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(S!==null){const O=this._findPointerByMouseButton(S);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 S=x.pointerId,M=this._findPointerById(S);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 S=this._findPointerById(0);S&&(S.clientX=x.clientX,S.clientY=x.clientY,S.deltaX=x.movementX,S.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 S=x.pointerId,M=this._findPointerById(S);if(M&&this._activePointers.splice(this._activePointers.indexOf(M),1),x.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=L.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=L.NONE;w()},u=()=>{const x=this._findPointerById(0);x&&this._activePointers.splice(this._activePointers.indexOf(x),1),this._state=L.NONE,w()};let f=-1;const m=x=>{if(!this._enabled||this.mouseButtons.wheel===L.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===L.ROTATE||this.mouseButtons.wheel===L.TRUCK){const v=performance.now();f-v<1e3&&this._getClientRect(this._elementRect),f=v}const S=iu?-1:-3,M=x.deltaMode===1?x.deltaY/S:x.deltaY/(S*10),O=this.dollyToCursor?(x.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(x.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case L.ROTATE:{this._rotateInternal(x.deltaX,x.deltaY),this._isUserControllingRotate=!0;break}case L.TRUCK:{this._truckInternal(x.deltaX,x.deltaY,!1),this._isUserControllingTruck=!0;break}case L.OFFSET:{this._truckInternal(x.deltaX,x.deltaY,!0),this._isUserControllingOffset=!0;break}case L.DOLLY:{this._dollyInternal(-M,O,E),this._isUserControllingDolly=!0;break}case L.ZOOM:{this._zoomInternal(-M,O,E),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},b=x=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===$.ACTION.NONE){const S=x instanceof PointerEvent?x.pointerId:(x instanceof MouseEvent,0),M=this._findPointerById(S);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(Nn(this._activePointers,Le),this._getClientRect(this._elementRect),s.copy(Le),n.copy(Le),this._activePointers.length>=2){const M=Le.x-this._activePointers[1].clientX,O=Le.y-this._activePointers[1].clientY,E=Math.sqrt(M*M+O*O);r.set(0,E);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&L.ROTATE)===L.ROTATE||(this._state&L.TOUCH_ROTATE)===L.TOUCH_ROTATE||(this._state&L.TOUCH_DOLLY_ROTATE)===L.TOUCH_DOLLY_ROTATE||(this._state&L.TOUCH_ZOOM_ROTATE)===L.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&L.TRUCK)===L.TRUCK||(this._state&L.TOUCH_TRUCK)===L.TOUCH_TRUCK||(this._state&L.TOUCH_DOLLY_TRUCK)===L.TOUCH_DOLLY_TRUCK||(this._state&L.TOUCH_ZOOM_TRUCK)===L.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&L.DOLLY)===L.DOLLY||(this._state&L.TOUCH_DOLLY)===L.TOUCH_DOLLY||(this._state&L.TOUCH_DOLLY_TRUCK)===L.TOUCH_DOLLY_TRUCK||(this._state&L.TOUCH_DOLLY_OFFSET)===L.TOUCH_DOLLY_OFFSET||(this._state&L.TOUCH_DOLLY_ROTATE)===L.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&L.ZOOM)===L.ZOOM||(this._state&L.TOUCH_ZOOM)===L.TOUCH_ZOOM||(this._state&L.TOUCH_ZOOM_TRUCK)===L.TOUCH_ZOOM_TRUCK||(this._state&L.TOUCH_ZOOM_OFFSET)===L.TOUCH_ZOOM_OFFSET||(this._state&L.TOUCH_ZOOM_ROTATE)===L.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&L.OFFSET)===L.OFFSET||(this._state&L.TOUCH_OFFSET)===L.TOUCH_OFFSET||(this._state&L.TOUCH_DOLLY_OFFSET)===L.TOUCH_DOLLY_OFFSET||(this._state&L.TOUCH_ZOOM_OFFSET)===L.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},C=()=>{if(!this._enabled)return;Nn(this._activePointers,Le);const x=Ie.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,S=x?-this._activePointers[0].deltaX:n.x-Le.x,M=x?-this._activePointers[0].deltaY:n.y-Le.y;if(n.copy(Le),((this._state&L.ROTATE)===L.ROTATE||(this._state&L.TOUCH_ROTATE)===L.TOUCH_ROTATE||(this._state&L.TOUCH_DOLLY_ROTATE)===L.TOUCH_DOLLY_ROTATE||(this._state&L.TOUCH_ZOOM_ROTATE)===L.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(S,M),this._isUserControllingRotate=!0),(this._state&L.DOLLY)===L.DOLLY||(this._state&L.ZOOM)===L.ZOOM){const O=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&L.DOLLY)===L.DOLLY?(this._dollyInternal(M*Us,O,E),this._isUserControllingDolly=!0):(this._zoomInternal(M*Us,O,E),this._isUserControllingZoom=!0)}if((this._state&L.TOUCH_DOLLY)===L.TOUCH_DOLLY||(this._state&L.TOUCH_ZOOM)===L.TOUCH_ZOOM||(this._state&L.TOUCH_DOLLY_TRUCK)===L.TOUCH_DOLLY_TRUCK||(this._state&L.TOUCH_ZOOM_TRUCK)===L.TOUCH_ZOOM_TRUCK||(this._state&L.TOUCH_DOLLY_OFFSET)===L.TOUCH_DOLLY_OFFSET||(this._state&L.TOUCH_ZOOM_OFFSET)===L.TOUCH_ZOOM_OFFSET||(this._state&L.TOUCH_DOLLY_ROTATE)===L.TOUCH_DOLLY_ROTATE||(this._state&L.TOUCH_ZOOM_ROTATE)===L.TOUCH_ZOOM_ROTATE){const O=Le.x-this._activePointers[1].clientX,E=Le.y-this._activePointers[1].clientY,v=Math.sqrt(O*O+E*E),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&L.TOUCH_DOLLY)===L.TOUCH_DOLLY||(this._state&L.TOUCH_DOLLY_ROTATE)===L.TOUCH_DOLLY_ROTATE||(this._state&L.TOUCH_DOLLY_TRUCK)===L.TOUCH_DOLLY_TRUCK||(this._state&L.TOUCH_DOLLY_OFFSET)===L.TOUCH_DOLLY_OFFSET?(this._dollyInternal(T*Us,_,A),this._isUserControllingDolly=!0):(this._zoomInternal(T*Us,_,A),this._isUserControllingZoom=!0)}((this._state&L.TRUCK)===L.TRUCK||(this._state&L.TOUCH_TRUCK)===L.TOUCH_TRUCK||(this._state&L.TOUCH_DOLLY_TRUCK)===L.TOUCH_DOLLY_TRUCK||(this._state&L.TOUCH_ZOOM_TRUCK)===L.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(S,M,!1),this._isUserControllingTruck=!0),((this._state&L.OFFSET)===L.OFFSET||(this._state&L.TOUCH_OFFSET)===L.TOUCH_OFFSET||(this._state&L.TOUCH_DOLLY_OFFSET)===L.TOUCH_DOLLY_OFFSET||(this._state&L.TOUCH_ZOOM_OFFSET)===L.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(S,M,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},w=()=>{Nn(this._activePointers,Le),n.copy(Le),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),su&&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!==L.NONE&&(this._state=L.NONE,this._activePointers.length=0,w())},i&&this.connect(i),this.update(0)}static install(e){q=e.THREE,Ya=Object.freeze(new q.Vector3(0,0,0)),Ns=Object.freeze(new q.Vector3(0,1,0)),Gn=Object.freeze(new q.Vector3(0,0,1)),Le=new q.Vector2,Y=new q.Vector3,te=new q.Vector3,fi=new q.Vector3,dt=new q.Vector3,ut=new q.Vector3,Wt=new q.Vector3,Xa=new q.Vector3,Za=new q.Vector3,tt=new q.Spherical,Xi=new q.Spherical,pi=new q.Box3,Ka=new q.Box3,qn=new q.Sphere,$a=new q.Quaternion,Wn=new q.Quaternion,Yn=new q.Matrix4,Hs=new q.Raycaster}static get ACTION(){return L}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=wi(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=wi(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||se(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&se(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=wi(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=se(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||se(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=wi(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||se(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),dt.setFromMatrixColumn(this._camera.matrix,0),ut.setFromMatrixColumn(this._camera.matrix,1),dt.multiplyScalar(e),ut.multiplyScalar(-i);const n=Y.copy(dt).add(ut),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||se(this._target.x,this._targetEnd.x,this.restThreshold)&&se(this._target.y,this._targetEnd.y,this.restThreshold)&&se(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?pi.copy(e):pi.setFromObject(e);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const d=qa(this._sphericalEnd.theta,Ga),u=qa(this._sphericalEnd.phi,Ga);l.push(this.rotateTo(d,u,i));const f=Y.setFromSpherical(this._sphericalEnd).normalize(),m=$a.setFromUnitVectors(f,Gn),b=se(Math.abs(f.y),1);b&&m.multiply(Wn.setFromAxisAngle(Ns,d)),m.multiply(this._yAxisUpSpaceInverse);const y=Ka.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(Gn,f),b&&m.premultiply(Wn.invert()),m.premultiply(this._yAxisUpSpace);const C=y.getSize(Y),w=y.getCenter(te).applyQuaternion(m);if(st(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(ze(this._camera)){const x=this._camera,S=x.right-x.left,M=x.top-x.bottom,O=s?Math.max(S/C.x,M/C.y):Math.min(S/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)),st(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,i))}else if(ze(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||se(this._target.x,this._targetEnd.x,this.restThreshold)&&se(this._target.y,this._targetEnd.y,this.restThreshold)&&se(this._target.z,this._targetEnd.z,this.restThreshold)&&se(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&se(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&se(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);tt.setFromVector3(C.sub(y).applyQuaternion(this._yAxisUpSpace));const w=fi.set(d,u,f),x=te.set(o,l,h);Xi.setFromVector3(x.sub(w).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(y.lerp(w,m));const S=Xi.theta-tt.theta,M=Xi.phi-tt.phi,O=Xi.radius-tt.radius;this._sphericalEnd.set(tt.radius+O*m,tt.phi+M*m,tt.theta+S*m),this.normalizeRotations(),this._needsUpdate=!0,b||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const E=!b||se(this._target.x,this._targetEnd.x,this.restThreshold)&&se(this._target.y,this._targetEnd.y,this.restThreshold)&&se(this._target.z,this._targetEnd.z,this.restThreshold)&&se(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&se(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&se(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(E)}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=wi(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||se(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&se(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&se(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),dt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),ut.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Wt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=Y.set(e,i,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);dt.multiplyScalar(a.x),ut.multiplyScalar(a.y),Wt.multiplyScalar(a.z),Y.copy(dt).add(ut).add(Wt),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(Hn(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(Hn(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%ui,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=ui),this._spherical.theta+=ui*Math.round((this._sphericalEnd.theta-this._spherical.theta)/ui)}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,Ns),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=Xa.subVectors(this._targetEnd,this._target),a=Za.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(ne(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=js(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(ne(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=js(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(ne(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=js(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(ne(r.x)&&ne(r.y)&&ne(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Wa(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(ne(a.x)&&ne(a.y)&&ne(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Wa(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(st(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=fi.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(ze(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=fi.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 S=this._targetEnd.dot(w),M=w.multiplyScalar(S-x);this._targetEnd.sub(M)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(ne(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=js(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),(!ne(this._focalOffset.x)||!ne(this._focalOffset.y)||!ne(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),dt.setFromMatrixColumn(this._camera.matrix,0),ut.setFromMatrixColumn(this._camera.matrix,1),Wt.setFromMatrixColumn(this._camera.matrix,2),dt.multiplyScalar(this._focalOffset.x),ut.multiplyScalar(-this._focalOffset.y),Wt.multiplyScalar(this._focalOffset.z),Y.copy(dt).add(ut).add(Wt),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"}),ne(i,this.restThreshold)&&ne(s,this.restThreshold)&&ne(n,this.restThreshold)&&ne(r.x,this.restThreshold)&&ne(r.y,this.restThreshold)&&ne(r.z,this.restThreshold)&&ne(a.x,this.restThreshold)&&ne(a.y,this.restThreshold)&&ne(a.z,this.restThreshold)&&ne(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:Wi(this.maxDistance),minZoom:this.minZoom,maxZoom:Wi(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Wi(this.maxPolarAngle),minAzimuthAngle:Wi(this.minAzimuthAngle),maxAzimuthAngle:Wi(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=Yi(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=Yi(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=Yi(s.maxPolarAngle),this.minAzimuthAngle=Yi(s.minAzimuthAngle),this.maxAzimuthAngle=Yi(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),tt.setFromVector3(n.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(tt.theta,tt.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,fi).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(st(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(ze(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)||Hn(this._camera,"_collisionTest"))return e;const s=Y.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);Yn.lookAt(Ya,s,this._camera.up);for(let n=0;n<4;n++){const r=te.copy(this._nearPlaneCorners[n]);r.applyMatrix4(Yn);const a=fi.addVectors(this._target,r);Hs.set(a,s),Hs.far=this._spherical.radius+1;const o=Hs.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;pi.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&pi.expandByObject(a)}),pi.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 rt=(c=>(c[c.Orbit=0]="Orbit",c[c.FirstPerson=1]="FirstPerson",c[c.Plan=2]="Plan",c))(rt||{});class Zo{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=rt.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:st(t)?$.ACTION.DOLLY:ze(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_ROTATE,two:st(t)?$.ACTION.TOUCH_DOLLY_TRUCK:ze(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 Ko{constructor(t){g(this,"mode");g(this,"cameraManager");this.mode=rt.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:st(t)?$.ACTION.DOLLY:ze(t)?$.ACTION.ZOOM:$.ACTION.NONE},e.touches={one:$.ACTION.TOUCH_TRUCK,two:st(t)?$.ACTION.TOUCH_DOLLY_TRUCK:ze(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 mi=50,Xn=new p.Vector3;class nu{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=mt.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const n=this.cameraControls,r=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Ye.Viewer3d||this.viewer.name===Ye.BimTilesViewer;switch(s.code){case"ArrowLeft":a?n.rotate(.1,0,!0):this.viewer.name===Ye.Viewer2d&&n.truck(r,0,!0);break;case"ArrowRight":a?n.rotate(-.1,0,!0):this.viewer.name===Ye.Viewer2d&&n.truck(-r,0,!0);break;case"ArrowUp":a?n.rotate(0,.1,!0):this.viewer.name===Ye.Viewer2d&&n.truck(0,r,!0);break;case"ArrowDown":a?n.rotate(0,-.1,!0):this.viewer.name===Ye.Viewer2d&&n.truck(0,-r,!0);break;case"KeyW":a&&(ze(this.activeCamera)?n.zoom(.01,!0):n.dolly(1,!0));break;case"KeyA":a&&n.truck(-r,0,!0);break;case"KeyS":a&&(ze(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(vo,i,Js,Qs),this.orthographicCamera=new p.OrthographicCamera(mi*i/-2,mi*i/2,mi/2,mi/-2,Js,Qs),this.activeCamera=this.perspectiveCamera,this.setupCameras(),$.install({THREE:p}),this.cameraControls=new $(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[rt.Orbit]:new Zo(this),[rt.Plan]:new Ko(this)},this.activeControls=this.controlsMap[rt.Orbit],this.setupControls(),this.setProjection(mt.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=Se.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=mi*i/2,this.orthographicCamera.top=mi/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(he.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===rt.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=mt.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=mt.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(Xn)}getPosition(){return this.cameraControls.getPosition(Xn)}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===mt.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection(Xn)}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=Js,far:s=Qs,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 Qt=class Qt extends Vo{tableName(){return"fonts"}static instance(){return!Qt._instance&&(Qt._instance=new Qt),Qt._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(Qt,"_instance");let Ii=Qt;var $o=(c=>(c[c.Horizontal=0]="Horizontal",c[c.Vertical=1]="Vertical",c[c.All=2]="All",c))($o||{}),Ve=(c=>(c[c.Shapes=0]="Shapes",c[c.Bigfont=1]="Bigfont",c[c.Unifont=2]="Unifont",c))(Ve||{});class Jo extends Hl.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=$o.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)=>{Ii.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 Ii.instance().query(this.fileName)}releaseFontData(){this.data={}}}class Yt extends Jo{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=Ja(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return Ja("?",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 Ja(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 ln;function ru(){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(ln=new Uint16Array(65536),e=0;e<i.length;e++)ln[i.charCodeAt(e)]=t[e]}function au(c){!ln&&ru();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=ln[s];t[e++]=n&255,t[e++]=n>>8}}return t.subarray(0,e)}new p.Vector2;class cs 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 cs(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 cs(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 ft=class ft{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=au(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 Ve.Shapes:l++,d=e[l];break;case Ve.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 Ve.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=ft.CIRCLE_SPAN;u<0&&(C=-C,y=-y);const w=b*f,x=w+y,S=s.clone().sub(new p.Vector2(Math.cos(w)*d,Math.sin(w)*d));if(s=S.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(S.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 S=x*w,M=ft.CIRCLE_SPAN,O=1;y<0&&(M=-M,S=-S,O=-1);let E=x*C,v=E+S;E+=x*d/256*O,v+=x*u/256*O;const T=s.clone().sub(new p.Vector2(b*Math.cos(E),b*Math.sin(E)));if(s=T.clone().add(new p.Vector2(b*Math.cos(v),b*Math.sin(v))),o){let _=E;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(ft.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(ft.generateArcPoints(s.clone(),u,f/127))),s.add(u)}break;case 14:l=ft.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 cs(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 Ve.Shapes:i++;break;case Ve.Bigfont:i++,e[i]==0&&(i+=6);break;case Ve.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=ft.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(ft,"FILE_STOP_FLAG",["\r",`
1532
+ `,""]),g(ft,"CIRCLE_SPAN",Math.PI/18);let At=ft;const Zn={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]]]},Qa=new p.Matrix3,ns=class ns extends Jo{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=Ve.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new fs(i),n=At.parserHeader(s,At.FILE_STOP_FLAG),r=n.split(" ");switch(r[1]){case"shapes":this.parseShapeFont(s),this.fontType=Ve.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=Ve.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=Ve.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=At.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=ns.DEFAULT_SIZE/this.baseUp;r=At.parserCode(this,a,o),this.graphicData.set(e,r)}else if(Zn[e]){const a=[];for(let o=0;o<Zn[e].length;o++)a.push(Zn[e][o].map(l=>new p.Vector2(l[0],l[1])));r=new cs(new p.Vector2,a),this.graphicData.set(e,r)}}if(this.graphicData.has(e)){const a=i/ns.DEFAULT_SIZE;Qa.identity().scale(a,a),r=this.graphicData.get(e).transform(Qa)}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=ou(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===Ve.Bigfont&&(i=At.getCode("?")),this.fontType===Ve.Unifont&&(i=At.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||Ve.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(ns,"DEFAULT_SIZE",12);let It=ns;function ou(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 pt{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]:pt.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=pt.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 Yt(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new It(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new Yt(s,l)}}else if(pt.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new Yt(s,o)}else if(pt.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new It(s,o)}else if(pt.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new Yt(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&Ie.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 It)return n.toThreeGeometry();if(s instanceof Yt)return new Ul.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 It)return e.toThreeGeometry();if(i instanceof Yt)return new p.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!Ie.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=pt.getFileName(s.toLowerCase());const r=await Ii.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 Ii.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 It(s,i):r=new Yt(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 It}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 lu{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=ot,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 H.geometriesEqual(t,e)}}class Qo{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 cn{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 cn(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 Ki=(c=>(c[c.NULL=0]="NULL",c[c.POINT=1]="POINT",c[c.POLYLINE=3]="POLYLINE",c[c.POLYGON=5]="POLYGON",c))(Ki||{});class cu{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 hu{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===Ki.POLYLINE||n.type===Ki.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===Ki.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===Ki.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 cn(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 cn(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 du{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 cu,a=r.parse(n.response),o=new hu().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 rs=class rs{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 Wl.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Zl.OBJLoader(this.manager),s=new Xl.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 $l.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 du;return new Promise((s,n)=>{i.load(t,r=>{s(r)},e,r=>{n(r)})})}async loadDae(t,e){const i=new Gl.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 Kl.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 Yl.GLTFLoader(this.manager);const t=new ql.DRACOLoader(this.manager);t.setDecoderPath(rs.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};g(rs,"DecoderPath","libs/draco/gltf/"),g(rs,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let Lt=rs;const el=`(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
+ `,eo=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",el],{type:"text/javascript;charset=utf-8"});function uu(c){let t;try{if(t=eo&&(self.URL||self.webkitURL).createObjectURL(eo),!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(el),{name:c?.name})}}class tl{constructor(){g(this,"running");g(this,"worker");this.running=!1,this.worker=new uu,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=as.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 Ir{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 tl}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 as(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 Ir;return n.generate(s,e).then(()=>{n.dispose()})}}class fu{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=pu(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 pu=(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},Gs=new p.Vector2,qs=new p.Vector2,Ws=new p.Vector2,to=new p.Vector2,mu=new p.Vector2,gu=new p.Vector2,ye=class ye extends zt{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=Mt.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=Gs.set(s.x,s.y-n),a=qs.set(s.x-.87*n,s.y+n/1.4),o=Ws.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=Gs.set(s.x,s.y-n),a=qs.set(s.x-.87*n,s.y+n/2),o=Ws.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=Gs.set(s.x-n,s.y-n),a=qs.set(s.x+n,s.y+n),o=Ws.set(s.x+n,s.y-n),l=to.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=Gs.set(s.x,s.y),a=qs.set(s.x-n,s.y),o=Ws.set(s.x,s.y+n),l=to.set(s.x-n,s.y-n),h=mu.set(s.x-n,s.y+n),d=gu.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 Oe=ye;ds._registerDrawableClass(Oe);var il=(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))(il||{});const yu=1e-5,re=new p.Vector3,Ce=new p.Vector3,_i=new p.Vector3,ts=new p.Vector3,Xt=new p.Matrix4,is=new p.Line3;function xu(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 bu(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)),Xt.identity(),t instanceof p.InstancedMesh&&c.instanceId!==void 0&&t.getMatrixAt(c.instanceId,Xt),Xt.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=Mo.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];re.set(a[m*3],a[m*3+1],a[m*3+2]),re.applyMatrix4(Xt),Ce.set(a[b*3],a[b*3+1],a[b*3+2]),Ce.applyMatrix4(Xt),is.set(re,Ce),is.closestPointToPoint(c.point,!0,_i);const y=c.point.distanceTo(_i);y<l&&(h=f,l=y,ts.copy(_i))}const d=o[h],u=o[h+1];return re.set(a[d*3],a[d*3+1],a[d*3+2]),re.applyMatrix4(Xt),Ce.set(a[u*3],a[u*3+1],a[u*3+2]),Ce.applyMatrix4(Xt),{vertices:[re.clone(),Ce.clone()],vertex:ts.clone(),distance:l}}class wu{constructor(t){g(this,"drawableList",new us("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 Oe(Mt.TripleCross),e=new Oe(Mt.Square),i=new Oe(Mt.Triangle),s=new Oe(Mt.CircleWithCross),n=new Oe(Mt.Cross),r=new Oe(Mt.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 Pi.colorStr2Rgba(Oe.lineColor)}setMarkerLineColor(t){Oe.lineColor=Pi.rgba2Color(t)}getMarkerLineWidth(){return Oe.lineWidth}setMarkerLineWidth(t){Oe.lineWidth=t}getMarkerIconSize(){return Oe.iconSize}setMarkerIconSize(t){Oe.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=yu){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=bu(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=xu(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;re.copy(r.vertices[0]),re.add(r.vertices[1]),re.divideScalar(2);const l=re.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:re.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:F.floorNumber(m,7),type:16,point:f.clone()}}if(r<this.osnapTypePriorities[1])return;is.set(e,i),is.closestPointToPoint(t,!0,_i);const l=t.distanceTo(_i);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:F.floorNumber(f,7),type:1,point:m.clone()}}if(r<this.osnapTypePriorities[2])return;is.getCenter(ts);const u=t.distanceTo(ts);if(u<s&&this.isOSnapTypeEnabled(2))return{point:ts.clone(),distance:F.floorNumber(u,7),type:2};if(!(r<this.osnapTypePriorities[4])){if(n.line&&this.isOSnapTypeEnabled(32)){const f=H.getLineSegmentsIntersectingPoint(n.line,o);if(!f)return;const m=t.distanceTo(f)/2;return m<s?(n.line=void 0,{point:f.clone(),distance:F.floorNumber(m,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return n.line={start:e.clone(),end:i.clone()},{point:_i.clone(),distance:F.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),S=d.getX(C+1);re.fromBufferAttribute(u,x),Ce.fromBufferAttribute(u,S),re.applyMatrix4(l.matrixWorld),Ce.applyMatrix4(l.matrixWorld),!i&&(re.setZ(0),Ce.setZ(0));const M=this.getOsnapInfoFromSegment(t,re,Ce,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){re.fromBufferAttribute(u,C),Ce.fromBufferAttribute(u,C+1),re.applyMatrix4(l.matrixWorld),Ce.applyMatrix4(l.matrixWorld),!i&&(re.setZ(0),Ce.setZ(0));const x=this.getOsnapInfoFromSegment(t,re,Ce,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");re.fromBufferAttribute(a,e.index),re.applyMatrix4(r.matrixWorld),Ce.copy(t),!i&&(re.setZ(0),Ce.setZ(0));const o=Ce.distanceTo(re);if(o>s)return;const l={distance:o,point:re.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 sl{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 vu{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=Se.world2NormalizedScreen(n.min,this.camera,this.viewerContainer),a=Se.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(he.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new sl("pick-markup-tooltip",Ke.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=Ke.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(he.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(he.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(he.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 Ei=class Ei{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 sl("box-select-tooltip",Ke.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=Ke.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(he.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(he.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: ${Ei.BORDER_WIDTH} solid ${Ei.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(Ei,"BORDER_COLOR","#fff000"),g(Ei,"BORDER_WIDTH","2px");let hn=Ei;class nl{constructor(t){g(this,"viewer");g(this,"boxSelectHelper");g(this,"active",!1);this.viewer=t,this.boxSelectHelper=new hn(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 io(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 Ys=new p.Box3,Mu=new p.Vector3;function Tu(c,t){return c.trim().toLowerCase()===t?2e6:0}function Cu(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=io(o.textContent);if(!l||(Ys.makeEmpty(),Ys.setFromObject(a),Ys.isEmpty()))return;r(o.handle||"",l,o.layer||"0",this.findLayoutName(a),Ys);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=io(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"?Tu(o.text,i):Cu(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(Mu).length()*.5,1)))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new us("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new gt(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 Su extends zt{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 Xe=(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))(Xe||{});class rl extends Vt{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,Xs(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,Xs(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const n=Se.getScreenCoordinateByEvent(i,this.element);s.x=n.x,s.y=n.y,s.movementX=i.movementX,s.movementY=i.movementY}else Xs(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else Xs(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 Xs(c,t){return c[t]!==void 0}class Eu{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=Se.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const r=[],a=new Map,o=Se.screen2Ndc(t,this.camera,this.viewerContainer),l=Se.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,S={x:t.x+w,y:t.y+x},M=Se.screen2Ndc(S,this.camera,this.viewerContainer);this.raycaster.setFromCamera(M,this.camera),this.raycaster.layers.enableAll();const O=this.raycaster.intersectObjects(e,!0)||[];for(const E of O)E.object&&!a.has(E.object.uuid)&&(a.set(E.object.uuid,E),r.push(E))}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),S=w.point||w.object.getWorldPosition(new p.Vector3);return x.distanceTo(y)-S.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=W1(s),r=Y1(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 so=new p.Vector3;class Ou{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=ot,e.matrixWorldAutoUpdate=ot,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 os.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await os.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),so.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(so),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 _u{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 pn extends Vt{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=Ye.BaseViewer,this.clock=new p.Clock,this.targetMaxFps=60,this.timeStamp=0,this.renderEnabled=!0,this.plugins=[],this.loadedModels=[],this.raf=new Qo,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 Pr(e.containerId),e.enableProgressBar&&(this.progressBar=new Ar(this.container)),this.spinner=new Yo(this.container),this.sceneManager=new Ou(this),this.pickManager=new Eu(this),this.overlayRender=new ds(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new rl(this.viewerContainer),this.cameraManager=new nu(this),this.loaderHelper=new Lt,this.undoManager=new _u,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&yo(e)}initLocalization(){const e=this.viewerCfg.language||bo;Ke.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 ho.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(he.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(he.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(he.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){Lt.setDracoDecoderPath(e)}addModel(e){const i=e.getModelObject();i.name=e.modelId,this.sceneManager.addModel(e),i.matrixAutoUpdate=ot,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new pt),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 nl(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 al=-1e3,gi=new p.Vector3,no=new p.Matrix4,ro=new p.Frustum,Kn=new p.Box3,ao=new p.Matrix4;class Br extends pn{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);this.name=Ye.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 J1(this)),this.cameraManager.setProjection(mt.Orthographic),this.cameraManager.setNavigationMode(rt.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(he.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===Xe.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(he.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),ao.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)gi.fromBufferAttribute(s,l).applyMatrix4(ao),r.expandByPoint(gi);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 us("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new gt(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()}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,[Ft]);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=Ke.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}).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 Ai({modelId:n,dxfData:u});this.addModel(m),this.spinner.decreaseJobCount(),o(100),this.progressBar?.delayRemoveProgressItem(r),this.dispatchEvent(he.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=ot,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():We.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 zt&&(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=al,this.groundPlane.layers.enableAll(),J.disableLayerChannels(this.groundPlane,[Ft]),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)}))}no.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),ro.setFromProjectionMatrix(no);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(Kn.makeEmpty(),Kn.expandByObject(o),!ro.intersectsBox(Kn))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 m=d.max.x-d.min.x,b=d.max.y-d.min.y;(m<1e-16||b<1e-16||m>1e16||b>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;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(gi),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=Se.getScreenCoordinateByEvent(e,i),n=Se.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)}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(gi);const f=Math.max(gi.x,gi.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||(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,!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 ol{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 Br(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new Pr(t.containerId);this.loadingProgressBar=new Ar(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 pt),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=Ke.t("ProgressBar.Comparing"),d=B=>{this.loadingProgressBar?.updateProgress(l,h,B),s&&s(new ProgressEvent("CompareProgress",{loaded:B,total:100}))},u=(B,k,R)=>{let z=B.loaded*100/B.total;z=z*(R-k)/100+k,this.loadingProgressBar?.updateProgress(l,h,z),s&&s(new ProgressEvent("CompareProgress",{loaded:z,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),[S,M]=await Promise.allSettled([w,x]);if(S.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=S.value,E=M.value;C=Date.now();const v=await new nt(O,E,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,E,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,_=E;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 Ai({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 Ai({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 Pu extends ol{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 Br(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=Ke.t("ProgressBar.Comparing"),f=R=>{this.loadingProgressBar?.updateProgress(d,u,R),n&&n(new ProgressEvent("CompareProgress",{loaded:R,total:100}))},m=(R,z,oe)=>{let le=R.loaded*100/R.total;le=le*(oe-z)/100+z,this.loadingProgressBar?.updateProgress(d,u,le),n&&n(new ProgressEvent("CompareProgress",{loaded:le,total:100}))},b=R=>m(R,0,15),y=R=>m(R,15,30),C=R=>m(R,30,60),w=R=>m(R,60,95);j.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(d),f(0);let x=Date.now();const S=this.loader.parse(r,b),M=this.loader.parse(o,y),[O,E]=await Promise.allSettled([S,M]);if(O.status==="rejected")return Promise.reject("[DxfCompareHelper] Failed to parse "+r);if(E.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=E.value;x=Date.now();const _=await new nt(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 R="[DxfCompareHelper] Nothing was loaded from "+r+" and "+o;return P.warn(R),Promise.reject(R)}const B=A.threejsObject,k=I.threejsObject;return B.name=r,k.name=o,x=Date.now(),this.viewer.addModel(new Ai({modelId:e.modelId||e.src,dxfData:A})),j.printMemory("After adding first loaded Model to scene"),f(95),this.viewer2.addModel(new Ai({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 pr(this.viewer)),this.markupManager2??(this.markupManager2=new pr(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 Ti{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 Ti.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return Ti.offsetEdge(this.next,this.current,t,e)}inverse(){return new Ti(this.next,this.current)}static offsetEdge(t,e,i,s){return new Ti([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const Zi=Array.isArray,oo=(c,t)=>c[0]===t[0]&&c[1]===t[1],$n=c=>Array.isArray(c)&&c.length,ll=(c,t=0,e=!1)=>{let i,s;if($n(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++)ll(c[i],t+1,i>0);if(t===0&&$n(c)&&$n(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 Au{constructor(t,e=5){g(this,"vertices");g(this,"edges");g(this,"arcSegments");g(this,"distance");if(this.distance=0,this.arcSegments=e,!Zi(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],Zi(t)&&typeof t[0]=="number"?this.vertices=t:(this.vertices=ll(t),this.processContour(this.vertices,this.edges))}processContour(t,e){let i,s;if(Zi(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,oo(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new Ti(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 oo(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=ki.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 ki.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(Zi(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]:ki.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(Zi(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]]:ki.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]:ki.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 cl{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 Jl.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(he.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 Ql.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 ec.ShaderPass(oc.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 tc.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 ic.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 sc.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 nc.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 rc.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 ac.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 Er)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 _r&&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 lc.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 Iu extends pn{constructor(e,i){super(e);g(this,"name");g(this,"loadedModels");g(this,"distanceCullingFactor");g(this,"selectedObject");g(this,"effect");if(this.name=Ye.Viewer3d,this.loadedModels=[],this.distanceCullingFactor=150,this.effect=new cl(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(mt.Perspective),this.cameraManager.setNavigationMode(rt.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===Xe.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===Xe.Left&&this.handleAnchorPoint(h)}),this.inputManager.addEventListener("pointermove",u=>{i!==void 0&&(e=!o(u),i===Xe.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===Xe.Left?l(u)?(h?.object?this.flyToObject(h.object):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.selectedObject instanceof zt?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,Xe.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=Ke.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,S,M)=>{let O=x.loaded*100/x.total;O=O*(M-S)/100+S,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 Er({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(he.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 zt&&(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 lo(c){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),c)}function co(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 Bu(c){const t={transform:new p.Matrix4,boundingVolume:new p.Box3};return Object.assign(Object.assign({},t),c)}class ku{constructor(t){g(this,"url");g(this,"metadata");g(this,"statistics");g(this,"view");this.url=t,this.metadata=lo(),this.statistics=co(),this.view=Bu()}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=lo(t.metadata),this.statistics=co(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 Du=0;class Lu extends pn{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=Ye.BimTilesViewer,this.loadedModels=[],this.enableHoverEffect=!1,this.effect=new cl(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(mt.Perspective),this.cameraManager.setNavigationMode(rt.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(he.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===Xe.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===Xe.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===Xe.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===Xe.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,Xe.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 zt&&(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 ku(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 _r({modelId:""+Du++,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=ot,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(he.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 Ru extends Vt{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 Fu 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 hl=(c=>(c[c.Browser=0]="Browser",c[c.Browserless=1]="Browserless",c[c.Headless=2]="Headless",c))(hl||{});class zu{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 Fu(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 Lt().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 Lt().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 Lt().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=Se.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=Se.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(Ft);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=Ct.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){os.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(Dr.includes(r.id,Dr.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 dl="1.0.0",ul="VERSION",fl=()=>window.localStorage.getItem(ul),pl=()=>{window.localStorage.setItem(ul,dl)},Vu=()=>fl()!==dl?(pl(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>D.Mesh});exports.BaseDxfCompareHelper=ol;exports.BaseViewer=pn;exports.BimTilesModel=_r;exports.BimTilesRenderer=Wo;exports.BimTilesViewer=Lu;exports.BinaryReader=fs;exports.BoxSelectHelper=hn;exports.ByBlock=ls;exports.ByLayer=Sr;exports.CSS2DObjectUtils=Dh;exports.CameraProjection=mt;exports.CancelablePromise=Ih;exports.CanvasRender=ds;exports.ColorUtils=Pi;exports.CommonUtils=j;exports.CompareDrawable=gt;exports.Container=Pr;exports.ControlsMode=rt;exports.CoordinateUtils=Se;exports.DecimalPrecisionRange=xo;exports.DefaultCameraFar=Qs;exports.DefaultCameraFov=vo;exports.DefaultCameraNear=Js;exports.DefaultLanguage=bo;exports.DefaultOpacity=Tr;exports.DefaultViewer3dConfig=eu;exports.DeviceUtils=Ie;exports.Drawable=zt;exports.DrawableList=us;exports.DxfChangeType=Re;exports.DxfCompare=nt;exports.DxfCompareHelper=Pu;exports.DxfCompareMarkupManager=pr;exports.DxfLoader=X;exports.DxfParser=Lo;exports.DxfRenderOrder=Ee;exports.DxfUtils=bt;exports.EdgeUtils=Mo;exports.Event=Vt;exports.ExportUtils=cr;exports.FontManager=pt;exports.FpsUtils=Nh;exports.GenerateMeshBvhWorker=tl;exports.GeometryUtils=H;exports.GroundPlaneRenderOrder=al;exports.HighlightColor=Mr;exports.HighlightColorRgba=Rh;exports.IconfontClass=Fh;exports.IconfontClass2=zh;exports.InputManager=rl;exports.InstantiateHelper=lu;exports.LayerForHitableObjects=wo;exports.LayerForSelectableObjects=Ft;exports.LayerForSnapableObjects=Fe;exports.Line=dc;exports.LinePatternShaders=Io;exports.LoadingHelper=Lt;exports.MaterialUtils=xe;exports.MathUtils=F;exports.MatrixAutoUpdate=ot;exports.MergeUtils=fe;exports.MeshBvhHelper=Ir;exports.MobileTouchHelperDrawable=Su;exports.Model=fn;exports.Model2d=Ai;exports.Model3d=Er;exports.NestedCompareTypes=Qi;exports.OSnapHelper=wu;exports.OSnapIconSize=Kh;exports.OSnapMarkerType=Mt;exports.OSnapType=il;exports.ObjectPixelSizeHelper=fu;exports.ObjectUtils=J;exports.Offset=Au;exports.OrbitControls=Zo;exports.OutlineColorRgba=$s;exports.PickMarkupHelper=vu;exports.PlanControls=Ko;exports.Plugin=Ru;exports.Points=ph;exports.PolygonUtils=Xh;exports.ProgressBar=Ar;exports.RafHelper=Qo;exports.SVGObjectUtils=$h;exports.SceneUtils=Ct;exports.SectionUtils=Dt;exports.ShaderChunk=Ah;exports.SimplifyUtils=Zh;exports.SnapDrawable=Oe;exports.Spinner=Yo;exports.TextSearchHelper=mr;exports.TextureUtils=os;exports.ThresholdAngleForEdge=Cr;exports.UnitConversionByMeter=dr;exports.UnitLabels=To;exports.UnitScaleConversion=ud;exports.UnitScaleToMeter=fr;exports.Units=We;exports.Viewer2d=Br;exports.Viewer3d=Iu;exports.Viewer3dLite=zu;exports.Viewer3dUtils=ed;exports.ViewerEvent=he;exports.ViewerMode=hl;exports.ViewerName=Ye;exports.Views=So;exports.ZoomToRectHelper=nl;exports.bspline=Oo;exports.checkIsNewVersion=Vu;exports.cn=hr;exports.createHatchPatternShaderMaterial=Bo;exports.decodeDxfTextCharacterCodes=_o;exports.decodeDxfTextMbcsCharacterCodes=Ao;exports.decodeDxfTextUnicodeCodePoints=Po;exports.en=Hh;exports.getLengthValueByUnit=Qh;exports.getUnitStr=ur;exports.getVersionFromLocalStorage=fl;exports.i18n=Ke;exports.log=P;exports.parseDxfMTextContent=es;exports.parseDxfTextContent=en;exports.round10=Eo;exports.setIcon=kh;exports.setLogLevel=yo;exports.setVersionToLocalStorage=pl;exports.showPrecisionValue=Lh;