@maqiuyao/dxf-viewer 0.2.35 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dxf-viewer.cjs +19 -19
- package/dist/dxf-viewer.js +2217 -2147
- package/dist/src/dxfViewer/core/dxf-splitter/DxfSplitter.d.ts +26 -3
- package/package.json +1 -1
package/dist/dxf-viewer.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var ml=Object.defineProperty;var gl=(c,t,e)=>t in c?ml(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var x=(c,t,e)=>gl(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("three"),yl=require("loglevel"),lo=require("three/examples/jsm/renderers/CSS2DRenderer.js"),xl=require("three/examples/jsm/exporters/DRACOExporter.js"),bl=require("three/examples/jsm/exporters/GLTFExporter.js"),wl=require("three/examples/jsm/exporters/OBJExporter.js"),vl=require("three/examples/jsm/exporters/STLExporter.js"),Ml=require("poly-extrude"),Tl=require("i18next"),Ae=require("three/examples/jsm/utils/BufferGeometryUtils.js"),Cl=require("three/src/extras/Earcut.js"),Sl=require("2d-polygon-self-intersections"),El=require("three/examples/jsm/modifiers/SimplifyModifier.js"),Ol=require("three/examples/jsm/renderers/SVGRenderer.js"),_l=require("three/examples/jsm/loaders/RGBELoader.js"),Pl=require("js-base64"),Al=require("concaveman"),Il=require("polybooljs"),xs=require("jsbi"),Bl=require("3d-tiles-renderer"),kl=require("protobufjs"),Dl=require("three/examples/jsm/loaders/DDSLoader.js"),wr=require("pako"),Ll=require("three/examples/jsm/geometries/TextGeometry.js"),Rl=require("opentype.js"),Fl=require("three/examples/jsm/loaders/FontLoader.js"),zl=require("three/examples/jsm/loaders/ColladaLoader.js"),Vl=require("three/examples/jsm/loaders/DRACOLoader.js"),Ul=require("three/examples/jsm/loaders/FBXLoader.js"),jl=require("three/examples/jsm/loaders/GLTFLoader.js"),Nl=require("three/examples/jsm/loaders/MTLLoader.js"),Hl=require("three/examples/jsm/loaders/OBJLoader.js"),Gl=require("three/examples/jsm/loaders/PLYLoader.js"),ql=require("three/examples/jsm/loaders/STLLoader.js"),Ui=require("polygon-clipping"),Wl=require("three/examples/jsm/postprocessing/EffectComposer.js"),Yl=require("three/examples/jsm/postprocessing/RenderPass.js"),Xl=require("three/examples/jsm/postprocessing/ShaderPass.js"),Zl=require("three/examples/jsm/postprocessing/SAOPass.js"),Kl=require("three/examples/jsm/postprocessing/SSAOPass.js"),$l=require("three/examples/jsm/postprocessing/OutlinePass.js"),Jl=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),Ql=require("three/examples/jsm/postprocessing/BloomPass.js"),ec=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),tc=require("three/examples/jsm/shaders/FXAAShader.js"),ic=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),Fr=require("lodash");function ps(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=ps(L),zr=ps(yl),sc=ps(Pl),Zt=ps(Il),nc=ps(kl),Oi=1,ut=new p.Sphere,Mn=new p.Vector3,Tn=new p.Vector3,Vr=new p.Vector3,Ur=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(),ut.copy(e.boundingSphere),ut.applyMatrix4(i),ut.radius+=s,c.ray.intersectsSphere(ut)===!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(ut.copy(m.boundingSphere),ut.applyMatrix4(i),c.ray.intersectsSphere(ut)!==!1)for(let y=m.indexStart,g=m.indexStart+m.indexCount-1;y<g;y+=a){const M=o.getX(y),w=o.getX(y+1);if(bs(this,h,c,M,w,r,t)&&(t[t.length-1].index=y,t.length-d>=Oi))return}}else{const f=Math.max(0,n.start),m=Math.min(o.count,n.start+n.count);for(let y=f,g=m-1;y<g;y+=a){const M=o.getX(y),w=o.getX(y+1);if(bs(this,h,c,M,w,r,t)&&(t[t.length-1].index=y,t.length-d>=Oi))return}}}else{const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(ut.copy(m.boundingSphere),ut.applyMatrix4(i),c.ray.intersectsSphere(ut)!==!1){for(let y=m.positionStart,g=m.positionStart+m.positionCount-1;y<g;y+=a)if(bs(this,h,c,y,y+1,r,t)&&t.length-d>=Oi)return}}else{const f=Math.max(0,n.start),m=Math.min(h.count,n.start+n.count);for(let y=f,g=m-1;y<g;y+=a)if(bs(this,h,c,y,y+1,r,t)&&t.length-d>=Oi)return}}};function bs(c,t,e,i,s,n,r){if(Mn.fromBufferAttribute(t,i),Mn.applyMatrix4(c.matrixWorld),Tn.fromBufferAttribute(t,s),Tn.applyMatrix4(c.matrixWorld),e.ray.distanceSqToSegment(Mn,Tn,Ur,Vr)>n)return!1;const o=e.ray.origin.distanceTo(Ur);return o<e.near||o>e.far?!1:(r.push({distance:o,point:Vr.clone(),index:i,object:c}),!0)}const rc=p.Line,co=0,ac=1,oc=2,jr=2,Cn=1.25,Nr=1,Ie=32,Me=Ie/4,ho=65535,en=Math.pow(2,-24),vr=Symbol("SKIP_GENERATION"),uo={strategy:co,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[vr]:!1};function he(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 ir(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 Hr(c,t){t.set(c)}function Gr(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 ws(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 ji(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 ue(c,t){return t[c+15]===ho}function Se(c,t){return t[c+6]}function Be(c,t){return t[c+14]}function Te(c){return c+Me}function Ce(c,t){const e=t[c+6];return c+e*Me}function Mr(c,t){return t[c+7]}function Sn(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,y=-1/0,g=-1/0;const M=c.offset||0;for(let w=(t-M)*6,b=(t+e-M)*6;w<b;w+=6){const C=c[w+0],S=c[w+1],O=C-S,E=C+S;O<n&&(n=O),E>o&&(o=E),C<d&&(d=C),C>m&&(m=C);const v=c[w+2],T=c[w+3],_=v-T,P=v+T;_<r&&(r=_),P>l&&(l=P),v<u&&(u=v),v>y&&(y=v);const I=c[w+4],B=c[w+5],k=I-B,D=I+B;k<a&&(a=k),D>h&&(h=D),I<f&&(f=I),I>g&&(g=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]=y,s[5]=g}const Mt=32,lc=(c,t)=>c.candidate-t.candidate,Bt=new Array(Mt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),vs=new Float32Array(6);function cc(c,t,e,i,s,n){let r=-1,a=0;if(n===co)r=ir(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===ac)r=ir(c),r!==-1&&(a=hc(e,i,s,r));else if(n===oc){const o=ji(c);let l=Cn*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],M=(t[f+3]-m)/Mt;if(s<Mt/4){const w=[...Bt];w.length=s;let b=0;for(let S=d;S<u;S+=6,b++){const O=w[b];O.candidate=e[S+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;ws(S,e,E)}w.sort(lc);let C=s;for(let S=0;S<C;S++){const O=w[S];for(;S+1<C&&w[S+1].candidate===O.candidate;)w.splice(S+1,1),C--}for(let S=d;S<u;S+=6){const O=e[S+2*f];for(let E=0;E<C;E++){const v=w[E];O>=v.candidate?ws(S,e,v.rightCacheBounds):(ws(S,e,v.leftCacheBounds),v.count++)}}for(let S=0;S<C;S++){const O=w[S],E=O.count,v=s-O.count,T=O.leftCacheBounds,_=O.rightCacheBounds;let P=0;E!==0&&(P=ji(T)/o);let I=0;v!==0&&(I=ji(_)/o);const B=Nr+Cn*(P*E+I*v);B<l&&(r=f,l=B,a=O.candidate)}}else{for(let C=0;C<Mt;C++){const S=Bt[C];S.count=0,S.candidate=m+M+C*M;const O=S.bounds;for(let E=0;E<3;E++)O[E]=1/0,O[E+3]=-1/0}for(let C=d;C<u;C+=6){let E=~~((e[C+2*f]-m)/M);E>=Mt&&(E=Mt-1);const v=Bt[E];v.count++,ws(C,e,v.bounds)}const w=Bt[Mt-1];Hr(w.bounds,w.rightCacheBounds);for(let C=Mt-2;C>=0;C--){const S=Bt[C],O=Bt[C+1];Gr(S.bounds,O.rightCacheBounds,S.rightCacheBounds)}let b=0;for(let C=0;C<Mt-1;C++){const S=Bt[C],O=S.count,E=S.bounds,T=Bt[C+1].rightCacheBounds;O!==0&&(b===0?Hr(E,vs):Gr(E,vs,vs)),b+=O;let _=0,P=0;b!==0&&(_=ji(vs)/o);const I=s-b;I!==0&&(P=ji(T)/o);const B=Nr+Cn*(_*b+P*I);B<l&&(r=f,l=B,a=S.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function hc(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 En{constructor(){this.boundingData=new Float32Array(6)}}function dc(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 fo,tn,sr,po;const uc=Math.pow(2,32);function nr(c){return"count"in c?1:1+nr(c.left)+nr(c.right)}function fc(c,t,e){return fo=new Float32Array(e),tn=new Uint32Array(e),sr=new Uint16Array(e),po=new Uint8Array(e),rr(c,t)}function rr(c,t){const e=c/4,i=c/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)fo[e+r]=n[r];if(s)return t.buffer?(po.set(new Uint8Array(t.buffer),c),c+t.buffer.byteLength):(tn[e+6]=t.offset,sr[i+14]=t.count,sr[i+15]=ho,c+Ie);{const{left:r,right:a,splitAxis:o}=t,l=c+Ie;let h=rr(l,r);const d=c/Ie,f=h/Ie-d;if(f>uc)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return tn[e+6]=f,tn[e+7]=o,rr(h,a)}}function pc(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 y=!1;const g=new En;return Sn(t,e,i,g.boundingData,m),w(g,e,i,m),g;function M(b){d&&d((b-n.offset)/n.count)}function w(b,C,S,O=null,E=0){!y&&E>=r&&(y=!0,a&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const v=S>l;if(S<=o&&!v||E>=r)return M(C+S),b.offset=C,b.count=S,b;const T=cc(b.boundingData,O,t,C,S,h);let _=T.axis===-1?-1:dc(u,f,t,C,S,T);if(T.axis===-1||_===C||_===C+S){if(!v)return M(C+S),b.offset=C,b.count=S,b;T.axis=Math.max(0,ir(b.boundingData)),_=C+Math.max(1,Math.floor(S/2))}b.splitAxis=T.axis;const P=new En,I=C,B=_-C;b.left=P,Sn(t,I,B,P.boundingData,m),w(P,I,B,m,E+1);const k=new En,D=_,z=S-B;return b.right=k,Sn(t,D,z,k.boundingData,m),w(k,D,z,m,E+1),b}}function mc(c,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=c.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,c.computePrimitiveBounds(r.offset,r.count,a),c._roots=i.map(o=>{const l=pc(c,a,o.offset,o.count,t,r),h=nr(l),d=new e(Ie*h);return fc(0,l,d),d})}class Tr{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 gc{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const ne=new gc;let zt,_i;const li=[],Ms=new Tr(()=>new L.Box3);function yc(c,t,e,i,s,n){zt=Ms.getPrimitive(),_i=Ms.getPrimitive(),li.push(zt,_i),ne.setBuffer(c._roots[t]);const r=ar(0,c.geometry,e,i,s,n);ne.clearBuffer(),Ms.releasePrimitive(zt),Ms.releasePrimitive(_i),li.pop(),li.pop();const a=li.length;return a>0&&(_i=li[a-1],zt=li[a-2]),r}function ar(c,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:l}=ne;let h=c*2;if(ue(h,o)){const u=Se(c,l),f=Be(h,o);return he(c,a,zt),i(u,f,!1,r,n+c/Me,zt)}else{let _=function(I){const{uint16Array:B,uint32Array:k}=ne;let D=I*2;for(;!ue(D,B);)I=Te(I),D=I*2;return Se(I,k)},P=function(I){const{uint16Array:B,uint32Array:k}=ne;let D=I*2;for(;!ue(D,B);)I=Ce(I,k),D=I*2;return Se(I,k)+Be(D,B)};const u=Te(c),f=Ce(c,l);let m=u,y=f,g,M,w,b;if(s&&(w=zt,b=_i,he(m,a,w),he(y,a,b),g=s(w),M=s(b),M<g)){m=f,y=u;const I=g;g=M,M=I,w=b}w||(w=zt,he(m,a,w));const C=ue(m*2,o),S=e(w,C,g,r+1,n+m/Me);let O;if(S===jr){const I=_(m),k=P(m)-I;O=i(I,k,!0,r+1,n+m/Me,w)}else O=S&&ar(m,t,e,i,s,n,r+1);if(O)return!0;b=_i,he(y,a,b);const E=ue(y*2,o),v=e(b,E,M,r+1,n+y/Me);let T;if(v===jr){const I=_(y),k=P(y)-I;T=i(I,k,!0,r+1,n+y/Me,b)}else T=v&&ar(y,t,e,i,s,n,r+1);return!!T}}const ts=new ne.constructor,hn=new ne.constructor,Lt=new Tr(()=>new L.Box3),ci=new L.Box3,hi=new L.Box3,On=new L.Box3,_n=new L.Box3;let Pn=!1;function xc(c,t,e,i){if(Pn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Pn=!0;const s=c._roots,n=t._roots;let r,a=0,o=0;const l=new L.Matrix4().copy(e).invert();for(let h=0,d=s.length;h<d;h++){ts.setBuffer(s[h]),o=0;const u=Lt.getPrimitive();he(0,ts.float32Array,u),u.applyMatrix4(l);for(let f=0,m=n.length;f<m&&(hn.setBuffer(n[f]),r=ot(0,0,e,l,i,a,o,0,0,u),hn.clearBuffer(),o+=n[f].byteLength/Ie,!r);f++);if(Lt.releasePrimitive(u),ts.clearBuffer(),a+=s[h].byteLength/Ie,r)break}return Pn=!1,r}function ot(c,t,e,i,s,n=0,r=0,a=0,o=0,l=null,h=!1){let d,u;h?(d=hn,u=ts):(d=ts,u=hn);const f=d.float32Array,m=d.uint32Array,y=d.uint16Array,g=u.float32Array,M=u.uint32Array,w=u.uint16Array,b=c*2,C=t*2,S=ue(b,y),O=ue(C,w);let E=!1;if(O&&S)h?E=s(Se(t,M),Be(t*2,w),Se(c,m),Be(c*2,y),o,r+t/Me,a,n+c/Me):E=s(Se(c,m),Be(c*2,y),Se(t,M),Be(t*2,w),a,n+c/Me,o,r+t/Me);else if(O){const v=Lt.getPrimitive();he(t,g,v),v.applyMatrix4(e);const T=Te(c),_=Ce(c,m);he(T,f,ci),he(_,f,hi);const P=v.intersectsBox(ci),I=v.intersectsBox(hi);E=P&&ot(t,T,i,e,s,r,n,o,a+1,v,!h)||I&&ot(t,_,i,e,s,r,n,o,a+1,v,!h),Lt.releasePrimitive(v)}else{const v=Te(t),T=Ce(t,M);he(v,g,On),he(T,g,_n);const _=l.intersectsBox(On),P=l.intersectsBox(_n);if(_&&P)E=ot(c,v,e,i,s,n,r,a,o+1,l,h)||ot(c,T,e,i,s,n,r,a,o+1,l,h);else if(_)if(S)E=ot(c,v,e,i,s,n,r,a,o+1,l,h);else{const I=Lt.getPrimitive();I.copy(On).applyMatrix4(e);const B=Te(c),k=Ce(c,m);he(B,f,ci),he(k,f,hi);const D=I.intersectsBox(ci),z=I.intersectsBox(hi);E=D&&ot(v,B,i,e,s,r,n,o,a+1,I,!h)||z&&ot(v,k,i,e,s,r,n,o,a+1,I,!h),Lt.releasePrimitive(I)}else if(P)if(S)E=ot(c,T,e,i,s,n,r,a,o+1,l,h);else{const I=Lt.getPrimitive();I.copy(_n).applyMatrix4(e);const B=Te(c),k=Ce(c,m);he(B,f,ci),he(k,f,hi);const D=I.intersectsBox(ci),z=I.intersectsBox(hi);E=D&&ot(T,B,i,e,s,r,n,o,a+1,I,!h)||z&&ot(T,k,i,e,s,r,n,o,a+1,I,!h),Lt.releasePrimitive(I)}}return E}const An=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(;!ue(r,e);)n=Te(n),r=n*2;return Se(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!ue(r,e);)n=Ce(n,t),r=n*2;return Se(n,t)+Be(r,e)};const s=(n,r,a)=>{const o=r*2,l=ue(o,e);if(!n(a,l,r)&&!l){const d=Te(r),u=Ce(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=Mr(o,t);return n(r,a,new Float32Array(c,o*4,6),l)}})}}},qr=new L.Box3,di=new Float32Array(6);class bc{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...uo,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),mc(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0;for(let d=t,u=t+e;d<u;d++){this.writePrimitiveBounds(d,di,0);const[f,m,y,g,M,w]=di;f<n&&(n=f),g>o&&(o=g),m<r&&(r=m),M>l&&(l=M),y<a&&(a=y),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,di,0);const[a,o,l,h,d,u]=di,f=(a+h)/2,m=(o+d)/2,y=(l+u)/2,g=(h-a)/2,M=(d-o)/2,w=(u-l)/2,b=(n-s)*6;i[b+0]=f,i[b+1]=g+(Math.abs(f)+g)*en,i[b+2]=m,i[b+3]=M+(Math.abs(m)+M)*en,i[b+4]=y,i[b+5]=w+(Math.abs(y)+w)*en}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/Ie;for(let l=0;l<o;l++){const h=Me*l,d=2*h;ue(d,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){An.setBVH(this,e),An.traverse(t),An.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/Ie;for(let l=o-1;l>=0;l--){const h=l*Me,d=h*2;if(ue(d,r)){const f=Se(h,n),m=Be(d,r);this.writePrimitiveRangeBounds(f,m,di,0),a.set(di,h)}else{const f=Te(h),m=Ce(h,n);for(let y=0;y<3;y++){const g=a[f+y],M=a[f+y+3],w=a[m+y],b=a[m+y+3];a[h+y]=g<w?g:w,a[h+y+3]=M>b?M:b}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{he(0,new Float32Array(i),qr),t.union(qr)}),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,y,g)=>d(u,f,m,y,g)?!0:a(u,f,this,n,m,y,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=yc(this,d,i,s,e,l),o)break;l+=f.byteLength/Ie}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return xc(this,t,e,s)}}function wc(){return typeof SharedArrayBuffer<"u"}function Cr(c){return c.index?c.index.count:c.attributes.position.count}function gn(c){return Cr(c)/3}function vc(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function Mc(c,t){if(!c.index){const e=c.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=vc(e,i);c.setIndex(new L.BufferAttribute(s,1));for(let n=0;n<e;n++)s[n]=n}}function Tc(c,t,e){const i=Cr(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 Cc(c,t){return c.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Wr(c,t,e){const i=Tc(c,t,e),s=Cc(c,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Cr(c)/e,l=[];for(const u of s){const{offset:f,count:m}=u,y=f,g=isFinite(m)?m:o-f,M=f+g;y<a&&M>r&&(l.push({pos:Math.max(r,y),isStart:!0}),l.push({pos:Math.min(a,M),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 Sc(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 Ec extends bc{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&&!wc())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={...uo,...e},e[vr]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Wr(e,t.range,i),n=Sc(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else Mc(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new L.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Wr(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class At{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}}At.prototype.setFromBox=(function(){const c=new L.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 Oc=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.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),g=o.dot(o)*f-u*u;let M,w;g!==0?M=(d*u-m*f)/g:M=0,w=(d+M*u)/f,r.x=M,r.y=w}})(),Sr=(function(){const c=new L.Vector2,t=new L.Vector3,e=new L.Vector3;return function(s,n,r,a){Oc(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}}}})(),_c=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.Plane,i=new L.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 y=r.getPlane(e);if(Math.abs(y.distanceToPoint(o))<=a){const M=y.projectPoint(o,t);if(r.containsPoint(M))return!0}return!1}})(),Pc=["x","y","z"],Et=1e-15,Yr=Et*Et;function Ke(c){return Math.abs(c)<Et}class dt extends L.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new L.Vector3),this.satBounds=new Array(4).fill().map(()=>new At),this.points=[this.a,this.b,this.c],this.plane=new L.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new L.Line3,this.needsUpdate=!0}intersectsSphere(t){return _c(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 y=l.length(),g=d.length(),M=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,y<Et?g<Et||M<Et?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):g<Et?M<Et?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):M<Et&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}dt.prototype.closestPointToSegment=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.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]),Sr(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)}})();dt.prototype.intersectsTriangle=(function(){const c=new dt,t=new At,e=new At,i=new L.Vector3,s=new L.Vector3,n=new L.Vector3,r=new L.Vector3,a=new L.Line3,o=new L.Line3,l=new L.Vector3,h=new L.Vector2,d=new L.Vector2;function u(b,C,S,O){const E=i;!b.isDegenerateIntoPoint&&!b.isDegenerateIntoSegment?E.copy(b.plane.normal):E.copy(C.plane.normal);const v=b.satBounds,T=b.satAxes;for(let I=1;I<4;I++){const B=v[I],k=T[I];if(t.setFromPoints(k,C.points),B.isSeparated(t)||(r.copy(E).cross(k),t.setFromPoints(r,b.points),e.setFromPoints(r,C.points),t.isSeparated(e)))return!1}const _=C.satBounds,P=C.satAxes;for(let I=1;I<4;I++){const B=_[I],k=P[I];if(t.setFromPoints(k,b.points),B.isSeparated(t)||(r.crossVectors(E,k),t.setFromPoints(r,b.points),e.setFromPoints(r,C.points),t.isSeparated(e)))return!1}return S&&(O||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),S.start.set(0,0,0),S.end.set(0,0,0)),!0}function f(b,C,S,O,E,v,T,_,P,I,B){let k=T/(T-_);I.x=O+(E-O)*k,B.start.subVectors(C,b).multiplyScalar(k).add(b),k=T/(T-P),I.y=O+(v-O)*k,B.end.subVectors(S,b).multiplyScalar(k).add(b)}function m(b,C,S,O,E,v,T,_,P,I,B){if(E>0)f(b.c,b.a,b.b,O,C,S,P,T,_,I,B);else if(v>0)f(b.b,b.a,b.c,S,C,O,_,T,P,I,B);else if(_*P>0||T!=0)f(b.a,b.b,b.c,C,S,O,T,_,P,I,B);else if(_!=0)f(b.b,b.a,b.c,S,C,O,_,T,P,I,B);else if(P!=0)f(b.c,b.a,b.b,O,C,S,P,T,_,I,B);else return!0;return!1}function y(b,C,S,O){const E=C.degenerateSegment,v=b.plane.distanceToPoint(E.start),T=b.plane.distanceToPoint(E.end);return Ke(v)?Ke(T)?u(b,C,S,O):(S&&(S.start.copy(E.start),S.end.copy(E.start)),b.containsPoint(E.start)):Ke(T)?(S&&(S.start.copy(E.end),S.end.copy(E.end)),b.containsPoint(E.end)):b.plane.intersectLine(E,i)!=null?(S&&(S.start.copy(i),S.end.copy(i)),b.containsPoint(i)):!1}function g(b,C,S){const O=C.a;return Ke(b.plane.distanceToPoint(O))&&b.containsPoint(O)?(S&&(S.start.copy(O),S.end.copy(O)),!0):!1}function M(b,C,S){const O=b.degenerateSegment,E=C.a;return O.closestPointToPoint(E,!0,i),E.distanceToSquared(i)<Yr?(S&&(S.start.copy(E),S.end.copy(E)),!0):!1}function w(b,C,S,O){if(b.isDegenerateIntoSegment)if(C.isDegenerateIntoSegment){const E=b.degenerateSegment,v=C.degenerateSegment,T=s,_=n;E.delta(T),v.delta(_);const P=i.subVectors(v.start,E.start),I=T.x*_.y-T.y*_.x;if(Ke(I))return!1;const B=(P.x*_.y-P.y*_.x)/I,k=-(T.x*P.y-T.y*P.x)/I;if(B<0||B>1||k<0||k>1)return!1;const D=E.start.z+T.z*B,z=v.start.z+_.z*k;return Ke(D-z)?(S&&(S.start.copy(E.start).addScaledVector(T,B),S.end.copy(E.start).addScaledVector(T,B)),!0):!1}else return C.isDegenerateIntoPoint?M(b,C,S):y(C,b,S,O);else{if(b.isDegenerateIntoPoint)return C.isDegenerateIntoPoint?C.a.distanceToSquared(b.a)<Yr?(S&&(S.start.copy(b.a),S.end.copy(b.a)),!0):!1:C.isDegenerateIntoSegment?M(C,b,S):g(C,b,S);if(C.isDegenerateIntoPoint)return g(b,C,S);if(C.isDegenerateIntoSegment)return y(b,C,S,O)}}return function(C,S=null,O=!1){this.needsUpdate&&this.update(),C.isExtendedTriangle?C.needsUpdate&&C.update():(c.copy(C),c.update(),C=c);const E=w(this,C,S,O);if(E!==void 0)return E;const v=this.plane,T=C.plane;let _=T.distanceToPoint(this.a),P=T.distanceToPoint(this.b),I=T.distanceToPoint(this.c);Ke(_)&&(_=0),Ke(P)&&(P=0),Ke(I)&&(I=0);const B=_*P,k=_*I;if(B>0&&k>0)return!1;let D=v.distanceToPoint(C.a),z=v.distanceToPoint(C.b),se=v.distanceToPoint(C.c);Ke(D)&&(D=0),Ke(z)&&(z=0),Ke(se)&&(se=0);const re=D*z,Ue=D*se;if(re>0&&Ue>0)return!1;s.copy(v.normal),n.copy(T.normal);const De=s.cross(n);let de=0,zi=Math.abs(De.x);const st=Math.abs(De.y);st>zi&&(zi=st,de=1),Math.abs(De.z)>zi&&(de=2);const Le=Pc[de],It=this.a[Le],Vi=this.b[Le],qt=this.c[Le],Wt=C.a[Le],Yt=C.b[Le],Xt=C.c[Le];if(m(this,It,Vi,qt,B,k,_,P,I,h,a))return u(this,C,S,O);if(m(C,Wt,Yt,Xt,re,Ue,D,z,se,d,o))return u(this,C,S,O);if(h.y<h.x){const vn=h.y;h.y=h.x,h.x=vn,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(d.y<d.x){const vn=d.y;d.y=d.x,d.x=vn,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}return h.y<d.x||d.y<h.x?!1:(S&&(d.x>h.x?S.start.copy(o.start):S.start.copy(a.start),d.y<h.y?S.end.copy(o.end):S.end.copy(a.end)),!0)}})();dt.prototype.distanceToPoint=(function(){const c=new L.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();dt.prototype.distanceToTriangle=(function(){const c=new L.Vector3,t=new L.Vector3,e=["a","b","c"],i=new L.Line3,s=new L.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 y=this[f];r.closestPointToPoint(y,c),u=y.distanceToSquared(c),u<h&&(h=u,a&&a.copy(y),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 y=e[m],g=e[(m+1)%3];s.set(r[y],r[g]),Sr(i,s,c,t);const M=c.distanceToSquared(t);M<h&&(h=M,a&&a.copy(c),o&&o.copy(t))}}return Math.sqrt(h)}})();class ze{constructor(t,e,i){this.isOrientedBox=!0,this.min=new L.Vector3,this.max=new L.Vector3,this.matrix=new L.Matrix4,this.invMatrix=new L.Matrix4,this.points=new Array(8).fill().map(()=>new L.Vector3),this.satAxes=new Array(3).fill().map(()=>new L.Vector3),this.satBounds=new Array(3).fill().map(()=>new At),this.alignedSatBounds=new Array(3).fill().map(()=>new At),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}}ze.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}})();ze.prototype.intersectsBox=(function(){const c=new At;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}})();ze.prototype.intersectsTriangle=(function(){const c=new dt,t=new Array(3),e=new At,i=new At,s=new L.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 y=h[m];if(s.crossVectors(f,y),e.setFromPoints(s,t),i.setFromPoints(s,d),e.isSeparated(i))return!1}}return!0}})();ze.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}})();ze.prototype.distanceToPoint=(function(){const c=new L.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();ze.prototype.distanceToBox=(function(){const c=["x","y","z"],t=new Array(12).fill().map(()=>new L.Line3),e=new Array(12).fill().map(()=>new L.Line3),i=new L.Vector3,s=new L.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 g=0;g<8;g++){const M=f[g];s.copy(M).clamp(d,u);const w=M.distanceToSquared(s);if(w<m&&(m=w,o&&o.copy(M),l&&l.copy(s),w<h))return Math.sqrt(w)}let y=0;for(let g=0;g<3;g++)for(let M=0;M<=1;M++)for(let w=0;w<=1;w++){const b=(g+1)%3,C=(g+2)%3,S=M<<b|w<<C,O=1<<g|M<<b|w<<C,E=f[S],v=f[O];t[y].set(E,v);const _=c[g],P=c[b],I=c[C],B=e[y],k=B.start,D=B.end;k[_]=d[_],k[P]=M?d[P]:u[P],k[I]=w?d[I]:u[P],D[_]=u[_],D[P]=M?d[P]:u[P],D[I]=w?d[I]:u[P],y++}for(let g=0;g<=1;g++)for(let M=0;M<=1;M++)for(let w=0;w<=1;w++){s.x=g?u.x:d.x,s.y=M?u.y:d.y,s.z=w?u.z:d.z,this.closestPointToPoint(s,i);const b=s.distanceToSquared(i);if(b<m&&(m=b,o&&o.copy(i),l&&l.copy(s),b<h))return Math.sqrt(b)}for(let g=0;g<12;g++){const M=t[g];for(let w=0;w<12;w++){const b=e[w];Sr(M,b,i,s);const C=i.distanceToSquared(s);if(C<m&&(m=C,o&&o.copy(i),l&&l.copy(s),C<h))return Math.sqrt(C)}}return Math.sqrt(m)}})();class Ac extends Tr{constructor(){super(()=>new dt)}}const tt=new Ac,Ni=new L.Vector3,In=new L.Vector3;function Ic(c,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(c.shapecast({boundsTraverseOrder:h=>(Ni.copy(t).clamp(h.min,h.max),Ni.distanceToSquared(t)),intersectsBounds:(h,d,u)=>u<a&&u<r,intersectsTriangle:(h,d)=>{h.closestPointToPoint(t,Ni);const u=t.distanceToSquared(Ni);return u<a&&(In.copy(Ni),a=u,o=d),u<n}}),a===1/0)return null;const l=Math.sqrt(a);return e.point?e.point.copy(In):e.point=In.clone(),e.distance=l,e.faceIndex=o,e}const Ts=parseInt(L.REVISION)>=169,Bc=parseInt(L.REVISION)<=161,Kt=new L.Vector3,$t=new L.Vector3,Jt=new L.Vector3,Cs=new L.Vector2,Ss=new L.Vector2,Es=new L.Vector2,Xr=new L.Vector3,Zr=new L.Vector3,Kr=new L.Vector3,Hi=new L.Vector3;function kc(c,t,e,i,s,n,r,a){let o;if(n===L.BackSide?o=c.intersectTriangle(i,e,t,!0,s):o=c.intersectTriangle(t,e,i,n!==L.DoubleSide,s),o===null)return null;const l=c.origin.distanceTo(s);return l<r||l>a?null:{distance:l,point:s.clone()}}function $r(c,t,e,i,s,n,r,a,o,l,h){Kt.fromBufferAttribute(t,n),$t.fromBufferAttribute(t,r),Jt.fromBufferAttribute(t,a);const d=kc(c,Kt,$t,Jt,Hi,o,l,h);if(d){if(i){Cs.fromBufferAttribute(i,n),Ss.fromBufferAttribute(i,r),Es.fromBufferAttribute(i,a),d.uv=new L.Vector2;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Cs,Ss,Es,d.uv);Ts||(d.uv=f)}if(s){Cs.fromBufferAttribute(s,n),Ss.fromBufferAttribute(s,r),Es.fromBufferAttribute(s,a),d.uv1=new L.Vector2;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Cs,Ss,Es,d.uv1);Ts||(d.uv1=f),Bc&&(d.uv2=d.uv1)}if(e){Xr.fromBufferAttribute(e,n),Zr.fromBufferAttribute(e,r),Kr.fromBufferAttribute(e,a),d.normal=new L.Vector3;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Xr,Zr,Kr,d.normal);d.normal.dot(c.direction)>0&&d.normal.multiplyScalar(-1),Ts||(d.normal=f)}const u={a:n,b:r,c:a,normal:new L.Vector3,materialIndex:0};if(L.Triangle.getNormal(Kt,$t,Jt,u.normal),d.face=u,d.faceIndex=n,Ts){const f=new L.Vector3;L.Triangle.getBarycoord(Hi,Kt,$t,Jt,f),d.barycoord=f}}return d}function Jr(c){return c&&c.isMaterial?c.side:c}function yn(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:y,uv1:g}=c.attributes;if(Array.isArray(t)){const M=i*3;for(let w=0,b=u.length;w<b;w++){const{start:C,count:S,materialIndex:O}=u[w];if(M>=C&&M<C+S){const E=Jr(t[O]),v=$r(e,f,m,y,g,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 M=Jr(t),w=$r(e,f,m,y,g,o,l,h,M,n,r);if(w)if(w.faceIndex=i,w.face.materialIndex=0,s)s.push(w);else return w}return null}function ge(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 Dc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++)yn(o,t,e,h,n,r,a)}function Lc(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=yn(a,t,e,d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Rc(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,ge(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function Fc(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 y=u*2;if(ue(y,a)){const g=Se(u,r),M=Be(y,a);let w=1/0,b=1/0,C=1/0,S=-1/0,O=-1/0,E=-1/0;for(let v=3*g,T=3*(g+M);v<T;v++){let _=i[v];const P=s.getX(_),I=s.getY(_),B=s.getZ(_);P<w&&(w=P),P>S&&(S=P),I<b&&(b=I),I>O&&(O=I),B<C&&(C=B),B>E&&(E=B)}return o[u+0]!==w||o[u+1]!==b||o[u+2]!==C||o[u+3]!==S||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=b,o[u+2]=C,o[u+3]=S,o[u+4]=O,o[u+5]=E,!0):!1}else{const g=Te(u),M=Ce(u,r);let w=m,b=!1,C=!1;if(t){if(!w){const _=g/Me+f/Ie,P=M/Me+f/Ie;b=t.has(_),C=t.has(P),w=!b&&!C}}else b=!0,C=!0;const S=w||b,O=w||C;let E=!1;S&&(E=d(g,f,w));let v=!1;O&&(v=d(M,f,w));const T=E||v;if(T)for(let _=0;_<3;_++){const P=g+_,I=M+_,B=o[P],k=o[P+3],D=o[I],z=o[I+3];o[u+_]=B<D?B:D,o[u+_+3]=k>z?k:z}return T}}}function jt(c,t,e,i,s){let n,r,a,o,l,h;const d=1/e.direction.x,u=1/e.direction.y,f=1/e.direction.z,m=e.origin.x,y=e.origin.y,g=e.origin.z;let M=t[c],w=t[c+3],b=t[c+1],C=t[c+3+1],S=t[c+2],O=t[c+3+2];return d>=0?(n=(M-m)*d,r=(w-m)*d):(n=(w-m)*d,r=(M-m)*d),u>=0?(a=(b-y)*u,o=(C-y)*u):(a=(C-y)*u,o=(b-y)*u),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),f>=0?(l=(S-g)*f,h=(O-g)*f):(l=(O-g)*f,h=(S-g)*f),n>h||l>r)?!1:((l>n||n!==n)&&(n=l),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function zc(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;yn(o,t,e,u,n,r,a)}}function Vc(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=yn(a,t,e,o?o[d]:d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Uc(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),ge(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function jc(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),or(0,c,e,i,s,n,r),ne.clearBuffer()}function or(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(ue(h,o)){const u=Se(c,l),f=Be(h,o);Dc(t,e,i,u,f,s,n,r)}else{const u=Te(c);jt(u,a,i,n,r)&&or(u,t,e,i,s,n,r);const f=Ce(c,l);jt(f,a,i,n,r)&&or(f,t,e,i,s,n,r)}}const Nc=["x","y","z"];function Hc(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=lr(0,c,e,i,s,n);return ne.clearBuffer(),r}function lr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(ue(l,a)){const d=Se(c,o),u=Be(l,a);return Lc(t,e,i,d,u,s,n)}else{const d=Mr(c,o),u=Nc[d],m=i.direction[u]>=0;let y,g;m?(y=Te(c),g=Ce(c,o)):(y=Ce(c,o),g=Te(c));const w=jt(y,r,i,s,n)?lr(y,t,e,i,s,n):null;if(w){const S=w.point[u];if(m?S<=r[g+d]:S>=r[g+d+3])return w}const C=jt(g,r,i,s,n)?lr(g,t,e,i,s,n):null;return w&&C?w.distance<=C.distance?w:C:w||C||null}}const Os=new L.Box3,ui=new dt,fi=new dt,Gi=new L.Matrix4,Qr=new ze,_s=new ze;function Gc(c,t,e,i){ne.setBuffer(c._roots[t]);const s=cr(0,c,e,i);return ne.clearBuffer(),s}function cr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Qr.set(e.boundingBox.min,e.boundingBox.max,i),s=Qr),ue(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,y=Se(c,a),g=Be(o,r);if(Gi.copy(i).invert(),e.boundsTree)return he(c,n,_s),_s.matrix.copy(Gi),_s.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>_s.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let b=y*3,C=(g+y)*3;b<C;b+=3)if(ge(fi,b,d,u),fi.needsUpdate=!0,w.intersectsTriangle(fi))return!0;return!1}});{const M=gn(e);for(let w=y*3,b=(g+y)*3;w<b;w+=3){ge(ui,w,d,u),ui.a.applyMatrix4(Gi),ui.b.applyMatrix4(Gi),ui.c.applyMatrix4(Gi),ui.needsUpdate=!0;for(let C=0,S=M*3;C<S;C+=3)if(ge(fi,C,f,m),fi.needsUpdate=!0,ui.intersectsTriangle(fi))return!0}}}else{const h=Te(c),d=Ce(c,a);return he(h,n,Os),!!(s.intersectsBox(Os)&&cr(h,t,e,i,s)||(he(d,n,Os),s.intersectsBox(Os)&&cr(d,t,e,i,s)))}}const Ps=new L.Matrix4,Bn=new ze,qi=new ze,qc=new L.Vector3,Wc=new L.Vector3,Yc=new L.Vector3,Xc=new L.Vector3;function Zc(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Bn.set(t.boundingBox.min,t.boundingBox.max,e),Bn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=tt.getPrimitive(),f=tt.getPrimitive();let m=qc,y=Wc,g=null,M=null;s&&(g=Yc,M=Xc);let w=1/0,b=null,C=null;return Ps.copy(e).invert(),qi.matrix.copy(Ps),c.shapecast({boundsTraverseOrder:S=>Bn.distanceToBox(S),intersectsBounds:(S,O,E)=>E<w&&E<r?(O&&(qi.min.copy(S.min),qi.max.copy(S.max),qi.needsUpdate=!0),!0):!1,intersectsRange:(S,O)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:v=>qi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,P=v+T;_<P;_++){ge(f,3*_,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let I=S,B=S+O;I<B;I++){ge(u,3*I,l,o),u.needsUpdate=!0;const k=u.distanceToTriangle(f,m,g);if(k<w&&(y.copy(m),M&&M.copy(g),w=k,b=I,C=_),k<n)return!0}}}});{const E=gn(t);for(let v=0,T=E;v<T;v++){ge(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=S,P=S+O;_<P;_++){ge(u,3*_,l,o),u.needsUpdate=!0;const I=u.distanceToTriangle(f,m,g);if(I<w&&(y.copy(m),M&&M.copy(g),w=I,b=_,C=v),I<n)return!0}}}}}),tt.releasePrimitive(u),tt.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=w,i.faceIndex=b,s&&(s.point?s.point.copy(M):s.point=M.clone(),s.point.applyMatrix4(Ps),y.applyMatrix4(Ps),s.distance=y.sub(s.point).length(),s.faceIndex=C),i)}function Kc(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 y=u*2;if(ue(y,a)){const g=Se(u,r),M=Be(y,a);let w=1/0,b=1/0,C=1/0,S=-1/0,O=-1/0,E=-1/0;for(let v=g,T=g+M;v<T;v++){const _=3*c.resolveTriangleIndex(v);for(let P=0;P<3;P++){let I=_+P;I=i?i[I]:I;const B=s.getX(I),k=s.getY(I),D=s.getZ(I);B<w&&(w=B),B>S&&(S=B),k<b&&(b=k),k>O&&(O=k),D<C&&(C=D),D>E&&(E=D)}}return o[u+0]!==w||o[u+1]!==b||o[u+2]!==C||o[u+3]!==S||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=b,o[u+2]=C,o[u+3]=S,o[u+4]=O,o[u+5]=E,!0):!1}else{const g=Te(u),M=Ce(u,r);let w=m,b=!1,C=!1;if(t){if(!w){const _=g/Me+f/Ie,P=M/Me+f/Ie;b=t.has(_),C=t.has(P),w=!b&&!C}}else b=!0,C=!0;const S=w||b,O=w||C;let E=!1;S&&(E=d(g,f,w));let v=!1;O&&(v=d(M,f,w));const T=E||v;if(T)for(let _=0;_<3;_++){const P=g+_,I=M+_,B=o[P],k=o[P+3],D=o[I],z=o[I+3];o[u+_]=B<D?B:D,o[u+_+3]=k>z?k:z}return T}}}function $c(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),hr(0,c,e,i,s,n,r),ne.clearBuffer()}function hr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(ue(h,o)){const u=Se(c,l),f=Be(h,o);zc(t,e,i,u,f,s,n,r)}else{const u=Te(c);jt(u,a,i,n,r)&&hr(u,t,e,i,s,n,r);const f=Ce(c,l);jt(f,a,i,n,r)&&hr(f,t,e,i,s,n,r)}}const Jc=["x","y","z"];function Qc(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=dr(0,c,e,i,s,n);return ne.clearBuffer(),r}function dr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(ue(l,a)){const d=Se(c,o),u=Be(l,a);return Vc(t,e,i,d,u,s,n)}else{const d=Mr(c,o),u=Jc[d],m=i.direction[u]>=0;let y,g;m?(y=Te(c),g=Ce(c,o)):(y=Ce(c,o),g=Te(c));const w=jt(y,r,i,s,n)?dr(y,t,e,i,s,n):null;if(w){const S=w.point[u];if(m?S<=r[g+d]:S>=r[g+d+3])return w}const C=jt(g,r,i,s,n)?dr(g,t,e,i,s,n):null;return w&&C?w.distance<=C.distance?w:C:w||C||null}}const As=new L.Box3,pi=new dt,mi=new dt,Wi=new L.Matrix4,ea=new ze,Is=new ze;function eh(c,t,e,i){ne.setBuffer(c._roots[t]);const s=ur(0,c,e,i);return ne.clearBuffer(),s}function ur(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),ea.set(e.boundingBox.min,e.boundingBox.max,i),s=ea),ue(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,y=Se(c,a),g=Be(o,r);if(Wi.copy(i).invert(),e.boundsTree)return he(c,n,Is),Is.matrix.copy(Wi),Is.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Is.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let b=y,C=g+y;b<C;b++)if(ge(mi,3*t.resolveTriangleIndex(b),d,u),mi.needsUpdate=!0,w.intersectsTriangle(mi))return!0;return!1}});{const M=gn(e);for(let w=y,b=g+y;w<b;w++){const C=t.resolveTriangleIndex(w);ge(pi,3*C,d,u),pi.a.applyMatrix4(Wi),pi.b.applyMatrix4(Wi),pi.c.applyMatrix4(Wi),pi.needsUpdate=!0;for(let S=0,O=M*3;S<O;S+=3)if(ge(mi,S,f,m),mi.needsUpdate=!0,pi.intersectsTriangle(mi))return!0}}}else{const h=Te(c),d=Ce(c,a);return he(h,n,As),!!(s.intersectsBox(As)&&ur(h,t,e,i,s)||(he(d,n,As),s.intersectsBox(As)&&ur(d,t,e,i,s)))}}const Bs=new L.Matrix4,kn=new ze,Yi=new ze,th=new L.Vector3,ih=new L.Vector3,sh=new L.Vector3,nh=new L.Vector3;function rh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),kn.set(t.boundingBox.min,t.boundingBox.max,e),kn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=tt.getPrimitive(),f=tt.getPrimitive();let m=th,y=ih,g=null,M=null;s&&(g=sh,M=nh);let w=1/0,b=null,C=null;return Bs.copy(e).invert(),Yi.matrix.copy(Bs),c.shapecast({boundsTraverseOrder:S=>kn.distanceToBox(S),intersectsBounds:(S,O,E)=>E<w&&E<r?(O&&(Yi.min.copy(S.min),Yi.max.copy(S.max),Yi.needsUpdate=!0),!0):!1,intersectsRange:(S,O)=>{if(t.boundsTree){const E=t.boundsTree;return E.shapecast({boundsTraverseOrder:v=>Yi.distanceToBox(v),intersectsBounds:(v,T,_)=>_<w&&_<r,intersectsRange:(v,T)=>{for(let _=v,P=v+T;_<P;_++){const I=E.resolveTriangleIndex(_);ge(f,3*I,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=S,k=S+O;B<k;B++){const D=c.resolveTriangleIndex(B);ge(u,3*D,l,o),u.needsUpdate=!0;const z=u.distanceToTriangle(f,m,g);if(z<w&&(y.copy(m),M&&M.copy(g),w=z,b=B,C=_),z<n)return!0}}}})}else{const E=gn(t);for(let v=0,T=E;v<T;v++){ge(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let _=S,P=S+O;_<P;_++){const I=c.resolveTriangleIndex(_);ge(u,3*I,l,o),u.needsUpdate=!0;const B=u.distanceToTriangle(f,m,g);if(B<w&&(y.copy(m),M&&M.copy(g),w=B,b=_,C=v),B<n)return!0}}}}}),tt.releasePrimitive(u),tt.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(y):i.point=y.clone(),i.distance=w,i.faceIndex=b,s&&(s.point?s.point.copy(M):s.point=M.clone(),s.point.applyMatrix4(Bs),y.applyMatrix4(Bs),s.distance=y.sub(s.point).length(),s.faceIndex=C),i)}function ta(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 ks=new ze,Ds=new L.Ray,ia=new L.Vector3,sa=new L.Matrix4,na=new L.Vector3,Dn=["getX","getY","getZ"];class hs extends Ec{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 hs(e,{...i,[vr]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const l=e.getIndex();if(l===null){const h=new L.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,y=d.byteLength/Ie;m<y;m++){const g=Me*m,M=2*g;ue(M,f)||(u[g+6]=u[g+6]/Me-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[Dn[f]](h),y=r[Dn[f]](d),g=r[Dn[f]](u);let M=m;y<M&&(M=y),g<M&&(M=g);let w=m;y>w&&(w=y),g>w&&(w=g),e[i+f]=M,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,y=t+e;m<y;m++){const M=(n?n[m]:m)*3,w=(m-f)*6;let b=M+0,C=M+1,S=M+2;a&&(b=a[b],C=a[C],S=a[S]),o||(b=b*d+h,C=C*d+h,S=S*d+h);for(let O=0;O<3;O++){let E,v,T;o?(E=r[u[O]](b),v=r[u[O]](C),T=r[u[O]](S)):(E=l[b+O],v=l[C+O],T=l[S+O]);let _=E;v<_&&(_=v),T<_&&(_=T);let P=E;v>P&&(P=v),T>P&&(P=T);const I=(P-_)/2,B=O*2;i[w+B+0]=_+I,i[w+B+1]=I+(Math.abs(_)+I)*en}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;sa.copy(t.matrixWorld).invert(),Ds.copy(e.ray).applyMatrix4(sa),na.setFromMatrixScale(t.matrixWorld),ia.copy(Ds.direction).multiply(na);const n=ia.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(Ds,s,r,a);o=ta(o,t,e),o&&i.push(o)}else{const o=this.raycast(Ds,s,r,a);for(let l=0,h=o.length;l<h;l++){const d=ta(o[l],t,e);d&&i.push(d)}}return i}refit(t=null){return(this.indirect?Kc:Fc)(this,t)}raycast(t,e=L.FrontSide,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?$c:jc;for(let o=0,l=n.length;o<l;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=L.FrontSide,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?Qc:Hc;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?eh:Gc;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=tt.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Uc:Rc});return tt.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=tt.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,l=this.indirect?m=>{const y=this.resolveTriangleIndex(m);ge(r,y*3,a,o)}:m=>{ge(r,m*3,a,o)},h=tt.getPrimitive(),d=t.geometry.index,u=t.geometry.attributes.position,f=t.indirect?m=>{const y=t.resolveTriangleIndex(m);ge(h,y*3,d,u)}:m=>{ge(h,m*3,d,u)};if(n){if(!(t instanceof hs))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const m=(y,g,M,w,b,C,S,O)=>{for(let E=M,v=M+w;E<v;E++){f(E),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let T=y,_=y+g;T<_;T++)if(l(T),r.needsUpdate=!0,n(r,h,T,E,b,C,S,O))return!0}return!1};if(s){const y=s;s=function(g,M,w,b,C,S,O,E){return y(g,M,w,b,C,S,O,E)?!0:m(g,M,w,b,C,S,O,E)}}else s=m}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return ks.set(t.min,t.max,e),ks.needsUpdate=!0,this.shapecast({intersectsBounds:i=>ks.intersectsBox(i),intersectsTriangle:i=>ks.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?rh:Zc)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Ic(this,t,e,i,s)}}const Ci={Mesh:L.Mesh.prototype.raycast,Line:L.Line.prototype.raycast,LineSegments:L.LineSegments.prototype.raycast,LineLoop:L.LineLoop.prototype.raycast,Points:L.Points.prototype.raycast,BatchedMesh:L.BatchedMesh.prototype.raycast},Ee=new L.Mesh,Ls=[];function ah(c,t){if(this.isBatchedMesh)oh.call(this,c,t);else{const{geometry:e}=this;if(e.boundsTree)e.boundsTree.raycastObject3D(this,c,t);else{let i;if(this instanceof L.Mesh)i=Ci.Mesh;else if(this instanceof L.LineSegments)i=Ci.LineSegments;else if(this instanceof L.LineLoop)i=Ci.LineLoop;else if(this instanceof L.Line)i=Ci.Line;else if(this instanceof L.Points)i=Ci.Points;else throw new Error("BVH: Fallback raycast function not found.");i.call(this,c,t)}}}function oh(c,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,n=this.matrixWorld;Ee.material=this.material,Ee.geometry=this.geometry;const r=Ee.geometry.boundsTree,a=Ee.geometry.drawRange;Ee.geometry.boundingSphere===null&&(Ee.geometry.boundingSphere=new L.Sphere);for(let o=0,l=i.length;o<l;o++){if(!this.getVisibleAt(o))continue;const h=i[o].geometryIndex;if(Ee.geometry.boundsTree=e[h],this.getMatrixAt(o,Ee.matrixWorld).premultiply(n),!Ee.geometry.boundsTree){this.getBoundingBoxAt(h,Ee.geometry.boundingBox),this.getBoundingSphereAt(h,Ee.geometry.boundingSphere);const d=s[h];Ee.geometry.setDrawRange(d.start,d.count)}Ee.raycast(c,Ls);for(let d=0,u=Ls.length;d<u;d++){const f=Ls[d];f.object=this,f.batchId=o,t.push(f)}Ls.length=0}Ee.geometry.boundsTree=r,Ee.geometry.drawRange=a,Ee.material=null,Ee.geometry=null}else Ci.BatchedMesh.call(this,c,t)}L.Mesh.prototype.raycast=ah;const Rs=new p.Sphere,Fs=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(),Rs.copy(e.boundingSphere),Rs.applyMatrix4(i),Rs.radius+=s,c.ray.intersectsSphere(Rs)===!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 y=a.getX(f);if(Fs.fromBufferAttribute(l,y).applyMatrix4(i),ra(Fs,y,r,c,t,this),t.length-h>=Oi)return}}else{const d=Math.max(0,n.start),u=Math.min(l.count,n.start+n.count);for(let f=d,m=u;f<m;f++)if(Fs.fromBufferAttribute(l,f).applyMatrix4(i),ra(Fs,f,r,c,t,this),t.length-h>=Oi)return}};function ra(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 lh=p.Points,ch=`
|
|
1
|
+
"use strict";var ml=Object.defineProperty;var gl=(c,t,e)=>t in c?ml(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var y=(c,t,e)=>gl(c,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("three"),yl=require("loglevel"),lo=require("three/examples/jsm/renderers/CSS2DRenderer.js"),xl=require("three/examples/jsm/exporters/DRACOExporter.js"),bl=require("three/examples/jsm/exporters/GLTFExporter.js"),wl=require("three/examples/jsm/exporters/OBJExporter.js"),vl=require("three/examples/jsm/exporters/STLExporter.js"),Ml=require("poly-extrude"),Tl=require("i18next"),Ie=require("three/examples/jsm/utils/BufferGeometryUtils.js"),Cl=require("three/src/extras/Earcut.js"),Sl=require("2d-polygon-self-intersections"),El=require("three/examples/jsm/modifiers/SimplifyModifier.js"),Ol=require("three/examples/jsm/renderers/SVGRenderer.js"),Pl=require("three/examples/jsm/loaders/RGBELoader.js"),_l=require("js-base64"),Al=require("concaveman"),Il=require("polybooljs"),xs=require("jsbi"),Bl=require("3d-tiles-renderer"),kl=require("protobufjs"),Dl=require("three/examples/jsm/loaders/DDSLoader.js"),wr=require("pako"),Ll=require("three/examples/jsm/geometries/TextGeometry.js"),Rl=require("opentype.js"),Fl=require("three/examples/jsm/loaders/FontLoader.js"),zl=require("three/examples/jsm/loaders/ColladaLoader.js"),Vl=require("three/examples/jsm/loaders/DRACOLoader.js"),Ul=require("three/examples/jsm/loaders/FBXLoader.js"),jl=require("three/examples/jsm/loaders/GLTFLoader.js"),Nl=require("three/examples/jsm/loaders/MTLLoader.js"),Hl=require("three/examples/jsm/loaders/OBJLoader.js"),Gl=require("three/examples/jsm/loaders/PLYLoader.js"),ql=require("three/examples/jsm/loaders/STLLoader.js"),Ui=require("polygon-clipping"),Wl=require("three/examples/jsm/postprocessing/EffectComposer.js"),Yl=require("three/examples/jsm/postprocessing/RenderPass.js"),Xl=require("three/examples/jsm/postprocessing/ShaderPass.js"),Zl=require("three/examples/jsm/postprocessing/SAOPass.js"),Kl=require("three/examples/jsm/postprocessing/SSAOPass.js"),$l=require("three/examples/jsm/postprocessing/OutlinePass.js"),Jl=require("three/examples/jsm/postprocessing/SSAARenderPass.js"),Ql=require("three/examples/jsm/postprocessing/BloomPass.js"),ec=require("three/examples/jsm/postprocessing/UnrealBloomPass.js"),tc=require("three/examples/jsm/shaders/FXAAShader.js"),ic=require("three/examples/jsm/helpers/VertexNormalsHelper.js"),Fr=require("lodash");function ps(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=ps(L),zr=ps(yl),sc=ps(_l),Zt=ps(Il),nc=ps(kl),Oi=1,ft=new p.Sphere,Mn=new p.Vector3,Tn=new p.Vector3,Vr=new p.Vector3,Ur=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(),ft.copy(e.boundingSphere),ft.applyMatrix4(i),ft.radius+=s,c.ray.intersectsSphere(ft)===!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(ft.copy(m.boundingSphere),ft.applyMatrix4(i),c.ray.intersectsSphere(ft)!==!1)for(let x=m.indexStart,g=m.indexStart+m.indexCount-1;x<g;x+=a){const M=o.getX(x),w=o.getX(x+1);if(bs(this,h,c,M,w,r,t)&&(t[t.length-1].index=x,t.length-d>=Oi))return}}else{const f=Math.max(0,n.start),m=Math.min(o.count,n.start+n.count);for(let x=f,g=m-1;x<g;x+=a){const M=o.getX(x),w=o.getX(x+1);if(bs(this,h,c,M,w,r,t)&&(t[t.length-1].index=x,t.length-d>=Oi))return}}}else{const u=this.userData.batches;if(u&&u.length>0&&u[0].boundingSphere)for(let f=0;f<u.length;f++){const m=u[f];if(ft.copy(m.boundingSphere),ft.applyMatrix4(i),c.ray.intersectsSphere(ft)!==!1){for(let x=m.positionStart,g=m.positionStart+m.positionCount-1;x<g;x+=a)if(bs(this,h,c,x,x+1,r,t)&&t.length-d>=Oi)return}}else{const f=Math.max(0,n.start),m=Math.min(h.count,n.start+n.count);for(let x=f,g=m-1;x<g;x+=a)if(bs(this,h,c,x,x+1,r,t)&&t.length-d>=Oi)return}}};function bs(c,t,e,i,s,n,r){if(Mn.fromBufferAttribute(t,i),Mn.applyMatrix4(c.matrixWorld),Tn.fromBufferAttribute(t,s),Tn.applyMatrix4(c.matrixWorld),e.ray.distanceSqToSegment(Mn,Tn,Ur,Vr)>n)return!1;const o=e.ray.origin.distanceTo(Ur);return o<e.near||o>e.far?!1:(r.push({distance:o,point:Vr.clone(),index:i,object:c}),!0)}const rc=p.Line,co=0,ac=1,oc=2,jr=2,Cn=1.25,Nr=1,Be=32,Me=Be/4,ho=65535,en=Math.pow(2,-24),vr=Symbol("SKIP_GENERATION"),uo={strategy:co,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[vr]:!1};function he(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 ir(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 Hr(c,t){t.set(c)}function Gr(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 ws(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 ji(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 ue(c,t){return t[c+15]===ho}function Se(c,t){return t[c+6]}function ke(c,t){return t[c+14]}function Te(c){return c+Me}function Ce(c,t){const e=t[c+6];return c+e*Me}function Mr(c,t){return t[c+7]}function Sn(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,x=-1/0,g=-1/0;const M=c.offset||0;for(let w=(t-M)*6,b=(t+e-M)*6;w<b;w+=6){const C=c[w+0],S=c[w+1],O=C-S,E=C+S;O<n&&(n=O),E>o&&(o=E),C<d&&(d=C),C>m&&(m=C);const v=c[w+2],T=c[w+3],P=v-T,_=v+T;P<r&&(r=P),_>l&&(l=_),v<u&&(u=v),v>x&&(x=v);const I=c[w+4],B=c[w+5],k=I-B,D=I+B;k<a&&(a=k),D>h&&(h=D),I<f&&(f=I),I>g&&(g=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]=x,s[5]=g}const Tt=32,lc=(c,t)=>c.candidate-t.candidate,Bt=new Array(Tt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),vs=new Float32Array(6);function cc(c,t,e,i,s,n){let r=-1,a=0;if(n===co)r=ir(t),r!==-1&&(a=(t[r]+t[r+3])/2);else if(n===ac)r=ir(c),r!==-1&&(a=hc(e,i,s,r));else if(n===oc){const o=ji(c);let l=Cn*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],M=(t[f+3]-m)/Tt;if(s<Tt/4){const w=[...Bt];w.length=s;let b=0;for(let S=d;S<u;S+=6,b++){const O=w[b];O.candidate=e[S+2*f],O.count=0;const{bounds:E,leftCacheBounds:v,rightCacheBounds:T}=O;for(let P=0;P<3;P++)T[P]=1/0,T[P+3]=-1/0,v[P]=1/0,v[P+3]=-1/0,E[P]=1/0,E[P+3]=-1/0;ws(S,e,E)}w.sort(lc);let C=s;for(let S=0;S<C;S++){const O=w[S];for(;S+1<C&&w[S+1].candidate===O.candidate;)w.splice(S+1,1),C--}for(let S=d;S<u;S+=6){const O=e[S+2*f];for(let E=0;E<C;E++){const v=w[E];O>=v.candidate?ws(S,e,v.rightCacheBounds):(ws(S,e,v.leftCacheBounds),v.count++)}}for(let S=0;S<C;S++){const O=w[S],E=O.count,v=s-O.count,T=O.leftCacheBounds,P=O.rightCacheBounds;let _=0;E!==0&&(_=ji(T)/o);let I=0;v!==0&&(I=ji(P)/o);const B=Nr+Cn*(_*E+I*v);B<l&&(r=f,l=B,a=O.candidate)}}else{for(let C=0;C<Tt;C++){const S=Bt[C];S.count=0,S.candidate=m+M+C*M;const O=S.bounds;for(let E=0;E<3;E++)O[E]=1/0,O[E+3]=-1/0}for(let C=d;C<u;C+=6){let E=~~((e[C+2*f]-m)/M);E>=Tt&&(E=Tt-1);const v=Bt[E];v.count++,ws(C,e,v.bounds)}const w=Bt[Tt-1];Hr(w.bounds,w.rightCacheBounds);for(let C=Tt-2;C>=0;C--){const S=Bt[C],O=Bt[C+1];Gr(S.bounds,O.rightCacheBounds,S.rightCacheBounds)}let b=0;for(let C=0;C<Tt-1;C++){const S=Bt[C],O=S.count,E=S.bounds,T=Bt[C+1].rightCacheBounds;O!==0&&(b===0?Hr(E,vs):Gr(E,vs,vs)),b+=O;let P=0,_=0;b!==0&&(P=ji(vs)/o);const I=s-b;I!==0&&(_=ji(T)/o);const B=Nr+Cn*(P*b+_*I);B<l&&(r=f,l=B,a=S.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${n} used.`);return{axis:r,pos:a}}function hc(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 En{constructor(){this.boundingData=new Float32Array(6)}}function dc(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 fo,tn,sr,po;const uc=Math.pow(2,32);function nr(c){return"count"in c?1:1+nr(c.left)+nr(c.right)}function fc(c,t,e){return fo=new Float32Array(e),tn=new Uint32Array(e),sr=new Uint16Array(e),po=new Uint8Array(e),rr(c,t)}function rr(c,t){const e=c/4,i=c/2,s="count"in t,n=t.boundingData;for(let r=0;r<6;r++)fo[e+r]=n[r];if(s)return t.buffer?(po.set(new Uint8Array(t.buffer),c),c+t.buffer.byteLength):(tn[e+6]=t.offset,sr[i+14]=t.count,sr[i+15]=ho,c+Be);{const{left:r,right:a,splitAxis:o}=t,l=c+Be;let h=rr(l,r);const d=c/Be,f=h/Be-d;if(f>uc)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return tn[e+6]=f,tn[e+7]=o,rr(h,a)}}function pc(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 x=!1;const g=new En;return Sn(t,e,i,g.boundingData,m),w(g,e,i,m),g;function M(b){d&&d((b-n.offset)/n.count)}function w(b,C,S,O=null,E=0){!x&&E>=r&&(x=!0,a&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const v=S>l;if(S<=o&&!v||E>=r)return M(C+S),b.offset=C,b.count=S,b;const T=cc(b.boundingData,O,t,C,S,h);let P=T.axis===-1?-1:dc(u,f,t,C,S,T);if(T.axis===-1||P===C||P===C+S){if(!v)return M(C+S),b.offset=C,b.count=S,b;T.axis=Math.max(0,ir(b.boundingData)),P=C+Math.max(1,Math.floor(S/2))}b.splitAxis=T.axis;const _=new En,I=C,B=P-C;b.left=_,Sn(t,I,B,_.boundingData,m),w(_,I,B,m,E+1);const k=new En,D=P,z=S-B;return b.right=k,Sn(t,D,z,k.boundingData,m),w(k,D,z,m,E+1),b}}function mc(c,t){const e=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=c.getRootRanges(t.range),s=i[0],n=i[i.length-1],r={offset:s.offset,count:n.offset+n.count-s.offset},a=new Float32Array(6*r.count);a.offset=r.offset,c.computePrimitiveBounds(r.offset,r.count,a),c._roots=i.map(o=>{const l=pc(c,a,o.offset,o.count,t,r),h=nr(l),d=new e(Be*h);return fc(0,l,d),d})}class Tr{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 gc{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const t=[];let e=null;this.setBuffer=i=>{e&&t.push(e),e=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{e=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,t.length!==0&&this.setBuffer(t.pop())}}}const ne=new gc;let zt,Pi;const li=[],Ms=new Tr(()=>new L.Box3);function yc(c,t,e,i,s,n){zt=Ms.getPrimitive(),Pi=Ms.getPrimitive(),li.push(zt,Pi),ne.setBuffer(c._roots[t]);const r=ar(0,c.geometry,e,i,s,n);ne.clearBuffer(),Ms.releasePrimitive(zt),Ms.releasePrimitive(Pi),li.pop(),li.pop();const a=li.length;return a>0&&(Pi=li[a-1],zt=li[a-2]),r}function ar(c,t,e,i,s=null,n=0,r=0){const{float32Array:a,uint16Array:o,uint32Array:l}=ne;let h=c*2;if(ue(h,o)){const u=Se(c,l),f=ke(h,o);return he(c,a,zt),i(u,f,!1,r,n+c/Me,zt)}else{let P=function(I){const{uint16Array:B,uint32Array:k}=ne;let D=I*2;for(;!ue(D,B);)I=Te(I),D=I*2;return Se(I,k)},_=function(I){const{uint16Array:B,uint32Array:k}=ne;let D=I*2;for(;!ue(D,B);)I=Ce(I,k),D=I*2;return Se(I,k)+ke(D,B)};const u=Te(c),f=Ce(c,l);let m=u,x=f,g,M,w,b;if(s&&(w=zt,b=Pi,he(m,a,w),he(x,a,b),g=s(w),M=s(b),M<g)){m=f,x=u;const I=g;g=M,M=I,w=b}w||(w=zt,he(m,a,w));const C=ue(m*2,o),S=e(w,C,g,r+1,n+m/Me);let O;if(S===jr){const I=P(m),k=_(m)-I;O=i(I,k,!0,r+1,n+m/Me,w)}else O=S&&ar(m,t,e,i,s,n,r+1);if(O)return!0;b=Pi,he(x,a,b);const E=ue(x*2,o),v=e(b,E,M,r+1,n+x/Me);let T;if(v===jr){const I=P(x),k=_(x)-I;T=i(I,k,!0,r+1,n+x/Me,b)}else T=v&&ar(x,t,e,i,s,n,r+1);return!!T}}const ts=new ne.constructor,hn=new ne.constructor,Lt=new Tr(()=>new L.Box3),ci=new L.Box3,hi=new L.Box3,On=new L.Box3,Pn=new L.Box3;let _n=!1;function xc(c,t,e,i){if(_n)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");_n=!0;const s=c._roots,n=t._roots;let r,a=0,o=0;const l=new L.Matrix4().copy(e).invert();for(let h=0,d=s.length;h<d;h++){ts.setBuffer(s[h]),o=0;const u=Lt.getPrimitive();he(0,ts.float32Array,u),u.applyMatrix4(l);for(let f=0,m=n.length;f<m&&(hn.setBuffer(n[f]),r=lt(0,0,e,l,i,a,o,0,0,u),hn.clearBuffer(),o+=n[f].byteLength/Be,!r);f++);if(Lt.releasePrimitive(u),ts.clearBuffer(),a+=s[h].byteLength/Be,r)break}return _n=!1,r}function lt(c,t,e,i,s,n=0,r=0,a=0,o=0,l=null,h=!1){let d,u;h?(d=hn,u=ts):(d=ts,u=hn);const f=d.float32Array,m=d.uint32Array,x=d.uint16Array,g=u.float32Array,M=u.uint32Array,w=u.uint16Array,b=c*2,C=t*2,S=ue(b,x),O=ue(C,w);let E=!1;if(O&&S)h?E=s(Se(t,M),ke(t*2,w),Se(c,m),ke(c*2,x),o,r+t/Me,a,n+c/Me):E=s(Se(c,m),ke(c*2,x),Se(t,M),ke(t*2,w),a,n+c/Me,o,r+t/Me);else if(O){const v=Lt.getPrimitive();he(t,g,v),v.applyMatrix4(e);const T=Te(c),P=Ce(c,m);he(T,f,ci),he(P,f,hi);const _=v.intersectsBox(ci),I=v.intersectsBox(hi);E=_&<(t,T,i,e,s,r,n,o,a+1,v,!h)||I&<(t,P,i,e,s,r,n,o,a+1,v,!h),Lt.releasePrimitive(v)}else{const v=Te(t),T=Ce(t,M);he(v,g,On),he(T,g,Pn);const P=l.intersectsBox(On),_=l.intersectsBox(Pn);if(P&&_)E=lt(c,v,e,i,s,n,r,a,o+1,l,h)||lt(c,T,e,i,s,n,r,a,o+1,l,h);else if(P)if(S)E=lt(c,v,e,i,s,n,r,a,o+1,l,h);else{const I=Lt.getPrimitive();I.copy(On).applyMatrix4(e);const B=Te(c),k=Ce(c,m);he(B,f,ci),he(k,f,hi);const D=I.intersectsBox(ci),z=I.intersectsBox(hi);E=D&<(v,B,i,e,s,r,n,o,a+1,I,!h)||z&<(v,k,i,e,s,r,n,o,a+1,I,!h),Lt.releasePrimitive(I)}else if(_)if(S)E=lt(c,T,e,i,s,n,r,a,o+1,l,h);else{const I=Lt.getPrimitive();I.copy(Pn).applyMatrix4(e);const B=Te(c),k=Ce(c,m);he(B,f,ci),he(k,f,hi);const D=I.intersectsBox(ci),z=I.intersectsBox(hi);E=D&<(T,B,i,e,s,r,n,o,a+1,I,!h)||z&<(T,k,i,e,s,r,n,o,a+1,I,!h),Lt.releasePrimitive(I)}}return E}const An=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(;!ue(r,e);)n=Te(n),r=n*2;return Se(n,t)},this.getRangeEnd=n=>{let r=n*2;for(;!ue(r,e);)n=Ce(n,t),r=n*2;return Se(n,t)+ke(r,e)};const s=(n,r,a)=>{const o=r*2,l=ue(o,e);if(!n(a,l,r)&&!l){const d=Te(r),u=Ce(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=Mr(o,t);return n(r,a,new Float32Array(c,o*4,6),l)}})}}},qr=new L.Box3,di=new Float32Array(6);class bc{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(t){t={...uo,...t},"maxLeafSize"in t&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafSize}),mc(this,t)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(t,e,i,s){let n=1/0,r=1/0,a=1/0,o=-1/0,l=-1/0,h=-1/0;for(let d=t,u=t+e;d<u;d++){this.writePrimitiveBounds(d,di,0);const[f,m,x,g,M,w]=di;f<n&&(n=f),g>o&&(o=g),m<r&&(r=m),M>l&&(l=M),x<a&&(a=x),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,di,0);const[a,o,l,h,d,u]=di,f=(a+h)/2,m=(o+d)/2,x=(l+u)/2,g=(h-a)/2,M=(d-o)/2,w=(u-l)/2,b=(n-s)*6;i[b+0]=f,i[b+1]=g+(Math.abs(f)+g)*en,i[b+2]=m,i[b+3]=M+(Math.abs(m)+M)*en,i[b+4]=x,i[b+5]=w+(Math.abs(x)+w)*en}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/Be;for(let l=0;l<o;l++){const h=Me*l,d=2*h;ue(d,a)&&(r[h+6]+=t)}}}}traverse(t,e=0){An.setBVH(this,e),An.traverse(t),An.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/Be;for(let l=o-1;l>=0;l--){const h=l*Me,d=h*2;if(ue(d,r)){const f=Se(h,n),m=ke(d,r);this.writePrimitiveRangeBounds(f,m,di,0),a.set(di,h)}else{const f=Te(h),m=Ce(h,n);for(let x=0;x<3;x++){const g=a[f+x],M=a[f+x+3],w=a[m+x],b=a[m+x+3];a[h+x]=g<w?g:w,a[h+x+3]=M>b?M:b}}}}}getBoundingBox(t){return t.makeEmpty(),this._roots.forEach(i=>{he(0,new Float32Array(i),qr),t.union(qr)}),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,x,g)=>d(u,f,m,x,g)?!0:a(u,f,this,n,m,x,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=yc(this,d,i,s,e,l),o)break;l+=f.byteLength/Be}return o}bvhcast(t,e,i){let{intersectsRanges:s}=i;return xc(this,t,e,s)}}function wc(){return typeof SharedArrayBuffer<"u"}function Cr(c){return c.index?c.index.count:c.attributes.position.count}function gn(c){return Cr(c)/3}function vc(c,t=ArrayBuffer){return c>65535?new Uint32Array(new t(4*c)):new Uint16Array(new t(2*c))}function Mc(c,t){if(!c.index){const e=c.attributes.position.count,i=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=vc(e,i);c.setIndex(new L.BufferAttribute(s,1));for(let n=0;n<e;n++)s[n]=n}}function Tc(c,t,e){const i=Cr(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 Cc(c,t){return c.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Wr(c,t,e){const i=Tc(c,t,e),s=Cc(c,e);if(!s.length)return[i];const n=[],r=i.offset,a=i.offset+i.count,o=Cr(c)/e,l=[];for(const u of s){const{offset:f,count:m}=u,x=f,g=isFinite(m)?m:o-f,M=f+g;x<a&&M>r&&(l.push({pos:Math.max(r,x),isStart:!0}),l.push({pos:Math.min(a,M),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 Sc(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 Ec extends bc{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&&!wc())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={...uo,...e},e[vr]||this.init(e)}init(t){const{geometry:e,primitiveStride:i}=this;if(t.indirect){const s=Wr(e,t.range,i),n=Sc(s,t.useSharedArrayBuffer);this._indirectBuffer=n}else Mc(e,t);super.init(t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new L.Box3))}getRootRanges(t){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Wr(this.geometry,t,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class At{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}}At.prototype.setFromBox=(function(){const c=new L.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 Oc=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.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),g=o.dot(o)*f-u*u;let M,w;g!==0?M=(d*u-m*f)/g:M=0,w=(d+M*u)/f,r.x=M,r.y=w}})(),Sr=(function(){const c=new L.Vector2,t=new L.Vector3,e=new L.Vector3;return function(s,n,r,a){Oc(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}}}})(),Pc=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.Plane,i=new L.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 x=r.getPlane(e);if(Math.abs(x.distanceToPoint(o))<=a){const M=x.projectPoint(o,t);if(r.containsPoint(M))return!0}return!1}})(),_c=["x","y","z"],Et=1e-15,Yr=Et*Et;function $e(c){return Math.abs(c)<Et}class ut extends L.Triangle{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new L.Vector3),this.satBounds=new Array(4).fill().map(()=>new At),this.points=[this.a,this.b,this.c],this.plane=new L.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new L.Line3,this.needsUpdate=!0}intersectsSphere(t){return Pc(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 x=l.length(),g=d.length(),M=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,x<Et?g<Et||M<Et?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(i)):g<Et?M<Et?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(t)):M<Et&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(e)),this.plane.setFromNormalAndCoplanarPoint(a,t),this.needsUpdate=!1}}ut.prototype.closestPointToSegment=(function(){const c=new L.Vector3,t=new L.Vector3,e=new L.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]),Sr(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)}})();ut.prototype.intersectsTriangle=(function(){const c=new ut,t=new At,e=new At,i=new L.Vector3,s=new L.Vector3,n=new L.Vector3,r=new L.Vector3,a=new L.Line3,o=new L.Line3,l=new L.Vector3,h=new L.Vector2,d=new L.Vector2;function u(b,C,S,O){const E=i;!b.isDegenerateIntoPoint&&!b.isDegenerateIntoSegment?E.copy(b.plane.normal):E.copy(C.plane.normal);const v=b.satBounds,T=b.satAxes;for(let I=1;I<4;I++){const B=v[I],k=T[I];if(t.setFromPoints(k,C.points),B.isSeparated(t)||(r.copy(E).cross(k),t.setFromPoints(r,b.points),e.setFromPoints(r,C.points),t.isSeparated(e)))return!1}const P=C.satBounds,_=C.satAxes;for(let I=1;I<4;I++){const B=P[I],k=_[I];if(t.setFromPoints(k,b.points),B.isSeparated(t)||(r.crossVectors(E,k),t.setFromPoints(r,b.points),e.setFromPoints(r,C.points),t.isSeparated(e)))return!1}return S&&(O||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),S.start.set(0,0,0),S.end.set(0,0,0)),!0}function f(b,C,S,O,E,v,T,P,_,I,B){let k=T/(T-P);I.x=O+(E-O)*k,B.start.subVectors(C,b).multiplyScalar(k).add(b),k=T/(T-_),I.y=O+(v-O)*k,B.end.subVectors(S,b).multiplyScalar(k).add(b)}function m(b,C,S,O,E,v,T,P,_,I,B){if(E>0)f(b.c,b.a,b.b,O,C,S,_,T,P,I,B);else if(v>0)f(b.b,b.a,b.c,S,C,O,P,T,_,I,B);else if(P*_>0||T!=0)f(b.a,b.b,b.c,C,S,O,T,P,_,I,B);else if(P!=0)f(b.b,b.a,b.c,S,C,O,P,T,_,I,B);else if(_!=0)f(b.c,b.a,b.b,O,C,S,_,T,P,I,B);else return!0;return!1}function x(b,C,S,O){const E=C.degenerateSegment,v=b.plane.distanceToPoint(E.start),T=b.plane.distanceToPoint(E.end);return $e(v)?$e(T)?u(b,C,S,O):(S&&(S.start.copy(E.start),S.end.copy(E.start)),b.containsPoint(E.start)):$e(T)?(S&&(S.start.copy(E.end),S.end.copy(E.end)),b.containsPoint(E.end)):b.plane.intersectLine(E,i)!=null?(S&&(S.start.copy(i),S.end.copy(i)),b.containsPoint(i)):!1}function g(b,C,S){const O=C.a;return $e(b.plane.distanceToPoint(O))&&b.containsPoint(O)?(S&&(S.start.copy(O),S.end.copy(O)),!0):!1}function M(b,C,S){const O=b.degenerateSegment,E=C.a;return O.closestPointToPoint(E,!0,i),E.distanceToSquared(i)<Yr?(S&&(S.start.copy(E),S.end.copy(E)),!0):!1}function w(b,C,S,O){if(b.isDegenerateIntoSegment)if(C.isDegenerateIntoSegment){const E=b.degenerateSegment,v=C.degenerateSegment,T=s,P=n;E.delta(T),v.delta(P);const _=i.subVectors(v.start,E.start),I=T.x*P.y-T.y*P.x;if($e(I))return!1;const B=(_.x*P.y-_.y*P.x)/I,k=-(T.x*_.y-T.y*_.x)/I;if(B<0||B>1||k<0||k>1)return!1;const D=E.start.z+T.z*B,z=v.start.z+P.z*k;return $e(D-z)?(S&&(S.start.copy(E.start).addScaledVector(T,B),S.end.copy(E.start).addScaledVector(T,B)),!0):!1}else return C.isDegenerateIntoPoint?M(b,C,S):x(C,b,S,O);else{if(b.isDegenerateIntoPoint)return C.isDegenerateIntoPoint?C.a.distanceToSquared(b.a)<Yr?(S&&(S.start.copy(b.a),S.end.copy(b.a)),!0):!1:C.isDegenerateIntoSegment?M(C,b,S):g(C,b,S);if(C.isDegenerateIntoPoint)return g(b,C,S);if(C.isDegenerateIntoSegment)return x(b,C,S,O)}}return function(C,S=null,O=!1){this.needsUpdate&&this.update(),C.isExtendedTriangle?C.needsUpdate&&C.update():(c.copy(C),c.update(),C=c);const E=w(this,C,S,O);if(E!==void 0)return E;const v=this.plane,T=C.plane;let P=T.distanceToPoint(this.a),_=T.distanceToPoint(this.b),I=T.distanceToPoint(this.c);$e(P)&&(P=0),$e(_)&&(_=0),$e(I)&&(I=0);const B=P*_,k=P*I;if(B>0&&k>0)return!1;let D=v.distanceToPoint(C.a),z=v.distanceToPoint(C.b),se=v.distanceToPoint(C.c);$e(D)&&(D=0),$e(z)&&(z=0),$e(se)&&(se=0);const re=D*z,je=D*se;if(re>0&&je>0)return!1;s.copy(v.normal),n.copy(T.normal);const Le=s.cross(n);let de=0,zi=Math.abs(Le.x);const nt=Math.abs(Le.y);nt>zi&&(zi=nt,de=1),Math.abs(Le.z)>zi&&(de=2);const Re=_c[de],It=this.a[Re],Vi=this.b[Re],qt=this.c[Re],Wt=C.a[Re],Yt=C.b[Re],Xt=C.c[Re];if(m(this,It,Vi,qt,B,k,P,_,I,h,a))return u(this,C,S,O);if(m(C,Wt,Yt,Xt,re,je,D,z,se,d,o))return u(this,C,S,O);if(h.y<h.x){const vn=h.y;h.y=h.x,h.x=vn,l.copy(a.start),a.start.copy(a.end),a.end.copy(l)}if(d.y<d.x){const vn=d.y;d.y=d.x,d.x=vn,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}return h.y<d.x||d.y<h.x?!1:(S&&(d.x>h.x?S.start.copy(o.start):S.start.copy(a.start),d.y<h.y?S.end.copy(o.end):S.end.copy(a.end)),!0)}})();ut.prototype.distanceToPoint=(function(){const c=new L.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();ut.prototype.distanceToTriangle=(function(){const c=new L.Vector3,t=new L.Vector3,e=["a","b","c"],i=new L.Line3,s=new L.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 x=this[f];r.closestPointToPoint(x,c),u=x.distanceToSquared(c),u<h&&(h=u,a&&a.copy(x),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 x=e[m],g=e[(m+1)%3];s.set(r[x],r[g]),Sr(i,s,c,t);const M=c.distanceToSquared(t);M<h&&(h=M,a&&a.copy(c),o&&o.copy(t))}}return Math.sqrt(h)}})();class Ve{constructor(t,e,i){this.isOrientedBox=!0,this.min=new L.Vector3,this.max=new L.Vector3,this.matrix=new L.Matrix4,this.invMatrix=new L.Matrix4,this.points=new Array(8).fill().map(()=>new L.Vector3),this.satAxes=new Array(3).fill().map(()=>new L.Vector3),this.satBounds=new Array(3).fill().map(()=>new At),this.alignedSatBounds=new Array(3).fill().map(()=>new At),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}}Ve.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}})();Ve.prototype.intersectsBox=(function(){const c=new At;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}})();Ve.prototype.intersectsTriangle=(function(){const c=new ut,t=new Array(3),e=new At,i=new At,s=new L.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 x=h[m];if(s.crossVectors(f,x),e.setFromPoints(s,t),i.setFromPoints(s,d),e.isSeparated(i))return!1}}return!0}})();Ve.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}})();Ve.prototype.distanceToPoint=(function(){const c=new L.Vector3;return function(e){return this.closestPointToPoint(e,c),e.distanceTo(c)}})();Ve.prototype.distanceToBox=(function(){const c=["x","y","z"],t=new Array(12).fill().map(()=>new L.Line3),e=new Array(12).fill().map(()=>new L.Line3),i=new L.Vector3,s=new L.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 g=0;g<8;g++){const M=f[g];s.copy(M).clamp(d,u);const w=M.distanceToSquared(s);if(w<m&&(m=w,o&&o.copy(M),l&&l.copy(s),w<h))return Math.sqrt(w)}let x=0;for(let g=0;g<3;g++)for(let M=0;M<=1;M++)for(let w=0;w<=1;w++){const b=(g+1)%3,C=(g+2)%3,S=M<<b|w<<C,O=1<<g|M<<b|w<<C,E=f[S],v=f[O];t[x].set(E,v);const P=c[g],_=c[b],I=c[C],B=e[x],k=B.start,D=B.end;k[P]=d[P],k[_]=M?d[_]:u[_],k[I]=w?d[I]:u[_],D[P]=u[P],D[_]=M?d[_]:u[_],D[I]=w?d[I]:u[_],x++}for(let g=0;g<=1;g++)for(let M=0;M<=1;M++)for(let w=0;w<=1;w++){s.x=g?u.x:d.x,s.y=M?u.y:d.y,s.z=w?u.z:d.z,this.closestPointToPoint(s,i);const b=s.distanceToSquared(i);if(b<m&&(m=b,o&&o.copy(i),l&&l.copy(s),b<h))return Math.sqrt(b)}for(let g=0;g<12;g++){const M=t[g];for(let w=0;w<12;w++){const b=e[w];Sr(M,b,i,s);const C=i.distanceToSquared(s);if(C<m&&(m=C,o&&o.copy(i),l&&l.copy(s),C<h))return Math.sqrt(C)}}return Math.sqrt(m)}})();class Ac extends Tr{constructor(){super(()=>new ut)}}const it=new Ac,Ni=new L.Vector3,In=new L.Vector3;function Ic(c,t,e={},i=0,s=1/0){const n=i*i,r=s*s;let a=1/0,o=null;if(c.shapecast({boundsTraverseOrder:h=>(Ni.copy(t).clamp(h.min,h.max),Ni.distanceToSquared(t)),intersectsBounds:(h,d,u)=>u<a&&u<r,intersectsTriangle:(h,d)=>{h.closestPointToPoint(t,Ni);const u=t.distanceToSquared(Ni);return u<a&&(In.copy(Ni),a=u,o=d),u<n}}),a===1/0)return null;const l=Math.sqrt(a);return e.point?e.point.copy(In):e.point=In.clone(),e.distance=l,e.faceIndex=o,e}const Ts=parseInt(L.REVISION)>=169,Bc=parseInt(L.REVISION)<=161,Kt=new L.Vector3,$t=new L.Vector3,Jt=new L.Vector3,Cs=new L.Vector2,Ss=new L.Vector2,Es=new L.Vector2,Xr=new L.Vector3,Zr=new L.Vector3,Kr=new L.Vector3,Hi=new L.Vector3;function kc(c,t,e,i,s,n,r,a){let o;if(n===L.BackSide?o=c.intersectTriangle(i,e,t,!0,s):o=c.intersectTriangle(t,e,i,n!==L.DoubleSide,s),o===null)return null;const l=c.origin.distanceTo(s);return l<r||l>a?null:{distance:l,point:s.clone()}}function $r(c,t,e,i,s,n,r,a,o,l,h){Kt.fromBufferAttribute(t,n),$t.fromBufferAttribute(t,r),Jt.fromBufferAttribute(t,a);const d=kc(c,Kt,$t,Jt,Hi,o,l,h);if(d){if(i){Cs.fromBufferAttribute(i,n),Ss.fromBufferAttribute(i,r),Es.fromBufferAttribute(i,a),d.uv=new L.Vector2;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Cs,Ss,Es,d.uv);Ts||(d.uv=f)}if(s){Cs.fromBufferAttribute(s,n),Ss.fromBufferAttribute(s,r),Es.fromBufferAttribute(s,a),d.uv1=new L.Vector2;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Cs,Ss,Es,d.uv1);Ts||(d.uv1=f),Bc&&(d.uv2=d.uv1)}if(e){Xr.fromBufferAttribute(e,n),Zr.fromBufferAttribute(e,r),Kr.fromBufferAttribute(e,a),d.normal=new L.Vector3;const f=L.Triangle.getInterpolation(Hi,Kt,$t,Jt,Xr,Zr,Kr,d.normal);d.normal.dot(c.direction)>0&&d.normal.multiplyScalar(-1),Ts||(d.normal=f)}const u={a:n,b:r,c:a,normal:new L.Vector3,materialIndex:0};if(L.Triangle.getNormal(Kt,$t,Jt,u.normal),d.face=u,d.faceIndex=n,Ts){const f=new L.Vector3;L.Triangle.getBarycoord(Hi,Kt,$t,Jt,f),d.barycoord=f}}return d}function Jr(c){return c&&c.isMaterial?c.side:c}function yn(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:x,uv1:g}=c.attributes;if(Array.isArray(t)){const M=i*3;for(let w=0,b=u.length;w<b;w++){const{start:C,count:S,materialIndex:O}=u[w];if(M>=C&&M<C+S){const E=Jr(t[O]),v=$r(e,f,m,x,g,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 M=Jr(t),w=$r(e,f,m,x,g,o,l,h,M,n,r);if(w)if(w.faceIndex=i,w.face.materialIndex=0,s)s.push(w);else return w}return null}function ge(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 Dc(c,t,e,i,s,n,r,a){const{geometry:o,_indirectBuffer:l}=c;for(let h=i,d=i+s;h<d;h++)yn(o,t,e,h,n,r,a)}function Lc(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=yn(a,t,e,d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Rc(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,ge(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function Fc(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 x=u*2;if(ue(x,a)){const g=Se(u,r),M=ke(x,a);let w=1/0,b=1/0,C=1/0,S=-1/0,O=-1/0,E=-1/0;for(let v=3*g,T=3*(g+M);v<T;v++){let P=i[v];const _=s.getX(P),I=s.getY(P),B=s.getZ(P);_<w&&(w=_),_>S&&(S=_),I<b&&(b=I),I>O&&(O=I),B<C&&(C=B),B>E&&(E=B)}return o[u+0]!==w||o[u+1]!==b||o[u+2]!==C||o[u+3]!==S||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=b,o[u+2]=C,o[u+3]=S,o[u+4]=O,o[u+5]=E,!0):!1}else{const g=Te(u),M=Ce(u,r);let w=m,b=!1,C=!1;if(t){if(!w){const P=g/Me+f/Be,_=M/Me+f/Be;b=t.has(P),C=t.has(_),w=!b&&!C}}else b=!0,C=!0;const S=w||b,O=w||C;let E=!1;S&&(E=d(g,f,w));let v=!1;O&&(v=d(M,f,w));const T=E||v;if(T)for(let P=0;P<3;P++){const _=g+P,I=M+P,B=o[_],k=o[_+3],D=o[I],z=o[I+3];o[u+P]=B<D?B:D,o[u+P+3]=k>z?k:z}return T}}}function jt(c,t,e,i,s){let n,r,a,o,l,h;const d=1/e.direction.x,u=1/e.direction.y,f=1/e.direction.z,m=e.origin.x,x=e.origin.y,g=e.origin.z;let M=t[c],w=t[c+3],b=t[c+1],C=t[c+3+1],S=t[c+2],O=t[c+3+2];return d>=0?(n=(M-m)*d,r=(w-m)*d):(n=(w-m)*d,r=(M-m)*d),u>=0?(a=(b-x)*u,o=(C-x)*u):(a=(C-x)*u,o=(b-x)*u),n>o||a>r||((a>n||isNaN(n))&&(n=a),(o<r||isNaN(r))&&(r=o),f>=0?(l=(S-g)*f,h=(O-g)*f):(l=(O-g)*f,h=(S-g)*f),n>h||l>r)?!1:((l>n||n!==n)&&(n=l),(h<r||r!==r)&&(r=h),n<=s&&r>=i)}function zc(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;yn(o,t,e,u,n,r,a)}}function Vc(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=yn(a,t,e,o?o[d]:d,null,n,r),f&&f.distance<l&&(h=f,l=f.distance)}return h}function Uc(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),ge(r,u*3,o,l),r.needsUpdate=!0,i(r,u,s,n))return!0}return!1}function jc(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),or(0,c,e,i,s,n,r),ne.clearBuffer()}function or(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(ue(h,o)){const u=Se(c,l),f=ke(h,o);Dc(t,e,i,u,f,s,n,r)}else{const u=Te(c);jt(u,a,i,n,r)&&or(u,t,e,i,s,n,r);const f=Ce(c,l);jt(f,a,i,n,r)&&or(f,t,e,i,s,n,r)}}const Nc=["x","y","z"];function Hc(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=lr(0,c,e,i,s,n);return ne.clearBuffer(),r}function lr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(ue(l,a)){const d=Se(c,o),u=ke(l,a);return Lc(t,e,i,d,u,s,n)}else{const d=Mr(c,o),u=Nc[d],m=i.direction[u]>=0;let x,g;m?(x=Te(c),g=Ce(c,o)):(x=Ce(c,o),g=Te(c));const w=jt(x,r,i,s,n)?lr(x,t,e,i,s,n):null;if(w){const S=w.point[u];if(m?S<=r[g+d]:S>=r[g+d+3])return w}const C=jt(g,r,i,s,n)?lr(g,t,e,i,s,n):null;return w&&C?w.distance<=C.distance?w:C:w||C||null}}const Os=new L.Box3,ui=new ut,fi=new ut,Gi=new L.Matrix4,Qr=new Ve,Ps=new Ve;function Gc(c,t,e,i){ne.setBuffer(c._roots[t]);const s=cr(0,c,e,i);return ne.clearBuffer(),s}function cr(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),Qr.set(e.boundingBox.min,e.boundingBox.max,i),s=Qr),ue(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,x=Se(c,a),g=ke(o,r);if(Gi.copy(i).invert(),e.boundsTree)return he(c,n,Ps),Ps.matrix.copy(Gi),Ps.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Ps.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let b=x*3,C=(g+x)*3;b<C;b+=3)if(ge(fi,b,d,u),fi.needsUpdate=!0,w.intersectsTriangle(fi))return!0;return!1}});{const M=gn(e);for(let w=x*3,b=(g+x)*3;w<b;w+=3){ge(ui,w,d,u),ui.a.applyMatrix4(Gi),ui.b.applyMatrix4(Gi),ui.c.applyMatrix4(Gi),ui.needsUpdate=!0;for(let C=0,S=M*3;C<S;C+=3)if(ge(fi,C,f,m),fi.needsUpdate=!0,ui.intersectsTriangle(fi))return!0}}}else{const h=Te(c),d=Ce(c,a);return he(h,n,Os),!!(s.intersectsBox(Os)&&cr(h,t,e,i,s)||(he(d,n,Os),s.intersectsBox(Os)&&cr(d,t,e,i,s)))}}const _s=new L.Matrix4,Bn=new Ve,qi=new Ve,qc=new L.Vector3,Wc=new L.Vector3,Yc=new L.Vector3,Xc=new L.Vector3;function Zc(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),Bn.set(t.boundingBox.min,t.boundingBox.max,e),Bn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=it.getPrimitive(),f=it.getPrimitive();let m=qc,x=Wc,g=null,M=null;s&&(g=Yc,M=Xc);let w=1/0,b=null,C=null;return _s.copy(e).invert(),qi.matrix.copy(_s),c.shapecast({boundsTraverseOrder:S=>Bn.distanceToBox(S),intersectsBounds:(S,O,E)=>E<w&&E<r?(O&&(qi.min.copy(S.min),qi.max.copy(S.max),qi.needsUpdate=!0),!0):!1,intersectsRange:(S,O)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:v=>qi.distanceToBox(v),intersectsBounds:(v,T,P)=>P<w&&P<r,intersectsRange:(v,T)=>{for(let P=v,_=v+T;P<_;P++){ge(f,3*P,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let I=S,B=S+O;I<B;I++){ge(u,3*I,l,o),u.needsUpdate=!0;const k=u.distanceToTriangle(f,m,g);if(k<w&&(x.copy(m),M&&M.copy(g),w=k,b=I,C=P),k<n)return!0}}}});{const E=gn(t);for(let v=0,T=E;v<T;v++){ge(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let P=S,_=S+O;P<_;P++){ge(u,3*P,l,o),u.needsUpdate=!0;const I=u.distanceToTriangle(f,m,g);if(I<w&&(x.copy(m),M&&M.copy(g),w=I,b=P,C=v),I<n)return!0}}}}}),it.releasePrimitive(u),it.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=w,i.faceIndex=b,s&&(s.point?s.point.copy(M):s.point=M.clone(),s.point.applyMatrix4(_s),x.applyMatrix4(_s),s.distance=x.sub(s.point).length(),s.faceIndex=C),i)}function Kc(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 x=u*2;if(ue(x,a)){const g=Se(u,r),M=ke(x,a);let w=1/0,b=1/0,C=1/0,S=-1/0,O=-1/0,E=-1/0;for(let v=g,T=g+M;v<T;v++){const P=3*c.resolveTriangleIndex(v);for(let _=0;_<3;_++){let I=P+_;I=i?i[I]:I;const B=s.getX(I),k=s.getY(I),D=s.getZ(I);B<w&&(w=B),B>S&&(S=B),k<b&&(b=k),k>O&&(O=k),D<C&&(C=D),D>E&&(E=D)}}return o[u+0]!==w||o[u+1]!==b||o[u+2]!==C||o[u+3]!==S||o[u+4]!==O||o[u+5]!==E?(o[u+0]=w,o[u+1]=b,o[u+2]=C,o[u+3]=S,o[u+4]=O,o[u+5]=E,!0):!1}else{const g=Te(u),M=Ce(u,r);let w=m,b=!1,C=!1;if(t){if(!w){const P=g/Me+f/Be,_=M/Me+f/Be;b=t.has(P),C=t.has(_),w=!b&&!C}}else b=!0,C=!0;const S=w||b,O=w||C;let E=!1;S&&(E=d(g,f,w));let v=!1;O&&(v=d(M,f,w));const T=E||v;if(T)for(let P=0;P<3;P++){const _=g+P,I=M+P,B=o[_],k=o[_+3],D=o[I],z=o[I+3];o[u+P]=B<D?B:D,o[u+P+3]=k>z?k:z}return T}}}function $c(c,t,e,i,s,n,r){ne.setBuffer(c._roots[t]),hr(0,c,e,i,s,n,r),ne.clearBuffer()}function hr(c,t,e,i,s,n,r){const{float32Array:a,uint16Array:o,uint32Array:l}=ne,h=c*2;if(ue(h,o)){const u=Se(c,l),f=ke(h,o);zc(t,e,i,u,f,s,n,r)}else{const u=Te(c);jt(u,a,i,n,r)&&hr(u,t,e,i,s,n,r);const f=Ce(c,l);jt(f,a,i,n,r)&&hr(f,t,e,i,s,n,r)}}const Jc=["x","y","z"];function Qc(c,t,e,i,s,n){ne.setBuffer(c._roots[t]);const r=dr(0,c,e,i,s,n);return ne.clearBuffer(),r}function dr(c,t,e,i,s,n){const{float32Array:r,uint16Array:a,uint32Array:o}=ne;let l=c*2;if(ue(l,a)){const d=Se(c,o),u=ke(l,a);return Vc(t,e,i,d,u,s,n)}else{const d=Mr(c,o),u=Jc[d],m=i.direction[u]>=0;let x,g;m?(x=Te(c),g=Ce(c,o)):(x=Ce(c,o),g=Te(c));const w=jt(x,r,i,s,n)?dr(x,t,e,i,s,n):null;if(w){const S=w.point[u];if(m?S<=r[g+d]:S>=r[g+d+3])return w}const C=jt(g,r,i,s,n)?dr(g,t,e,i,s,n):null;return w&&C?w.distance<=C.distance?w:C:w||C||null}}const As=new L.Box3,pi=new ut,mi=new ut,Wi=new L.Matrix4,ea=new Ve,Is=new Ve;function eh(c,t,e,i){ne.setBuffer(c._roots[t]);const s=ur(0,c,e,i);return ne.clearBuffer(),s}function ur(c,t,e,i,s=null){const{float32Array:n,uint16Array:r,uint32Array:a}=ne;let o=c*2;if(s===null&&(e.boundingBox||e.computeBoundingBox(),ea.set(e.boundingBox.min,e.boundingBox.max,i),s=ea),ue(o,r)){const h=t.geometry,d=h.index,u=h.attributes.position,f=e.index,m=e.attributes.position,x=Se(c,a),g=ke(o,r);if(Wi.copy(i).invert(),e.boundsTree)return he(c,n,Is),Is.matrix.copy(Wi),Is.needsUpdate=!0,e.boundsTree.shapecast({intersectsBounds:w=>Is.intersectsBox(w),intersectsTriangle:w=>{w.a.applyMatrix4(i),w.b.applyMatrix4(i),w.c.applyMatrix4(i),w.needsUpdate=!0;for(let b=x,C=g+x;b<C;b++)if(ge(mi,3*t.resolveTriangleIndex(b),d,u),mi.needsUpdate=!0,w.intersectsTriangle(mi))return!0;return!1}});{const M=gn(e);for(let w=x,b=g+x;w<b;w++){const C=t.resolveTriangleIndex(w);ge(pi,3*C,d,u),pi.a.applyMatrix4(Wi),pi.b.applyMatrix4(Wi),pi.c.applyMatrix4(Wi),pi.needsUpdate=!0;for(let S=0,O=M*3;S<O;S+=3)if(ge(mi,S,f,m),mi.needsUpdate=!0,pi.intersectsTriangle(mi))return!0}}}else{const h=Te(c),d=Ce(c,a);return he(h,n,As),!!(s.intersectsBox(As)&&ur(h,t,e,i,s)||(he(d,n,As),s.intersectsBox(As)&&ur(d,t,e,i,s)))}}const Bs=new L.Matrix4,kn=new Ve,Yi=new Ve,th=new L.Vector3,ih=new L.Vector3,sh=new L.Vector3,nh=new L.Vector3;function rh(c,t,e,i={},s={},n=0,r=1/0){t.boundingBox||t.computeBoundingBox(),kn.set(t.boundingBox.min,t.boundingBox.max,e),kn.needsUpdate=!0;const a=c.geometry,o=a.attributes.position,l=a.index,h=t.attributes.position,d=t.index,u=it.getPrimitive(),f=it.getPrimitive();let m=th,x=ih,g=null,M=null;s&&(g=sh,M=nh);let w=1/0,b=null,C=null;return Bs.copy(e).invert(),Yi.matrix.copy(Bs),c.shapecast({boundsTraverseOrder:S=>kn.distanceToBox(S),intersectsBounds:(S,O,E)=>E<w&&E<r?(O&&(Yi.min.copy(S.min),Yi.max.copy(S.max),Yi.needsUpdate=!0),!0):!1,intersectsRange:(S,O)=>{if(t.boundsTree){const E=t.boundsTree;return E.shapecast({boundsTraverseOrder:v=>Yi.distanceToBox(v),intersectsBounds:(v,T,P)=>P<w&&P<r,intersectsRange:(v,T)=>{for(let P=v,_=v+T;P<_;P++){const I=E.resolveTriangleIndex(P);ge(f,3*I,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let B=S,k=S+O;B<k;B++){const D=c.resolveTriangleIndex(B);ge(u,3*D,l,o),u.needsUpdate=!0;const z=u.distanceToTriangle(f,m,g);if(z<w&&(x.copy(m),M&&M.copy(g),w=z,b=B,C=P),z<n)return!0}}}})}else{const E=gn(t);for(let v=0,T=E;v<T;v++){ge(f,3*v,d,h),f.a.applyMatrix4(e),f.b.applyMatrix4(e),f.c.applyMatrix4(e),f.needsUpdate=!0;for(let P=S,_=S+O;P<_;P++){const I=c.resolveTriangleIndex(P);ge(u,3*I,l,o),u.needsUpdate=!0;const B=u.distanceToTriangle(f,m,g);if(B<w&&(x.copy(m),M&&M.copy(g),w=B,b=P,C=v),B<n)return!0}}}}}),it.releasePrimitive(u),it.releasePrimitive(f),w===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=w,i.faceIndex=b,s&&(s.point?s.point.copy(M):s.point=M.clone(),s.point.applyMatrix4(Bs),x.applyMatrix4(Bs),s.distance=x.sub(s.point).length(),s.faceIndex=C),i)}function ta(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 ks=new Ve,Ds=new L.Ray,ia=new L.Vector3,sa=new L.Matrix4,na=new L.Vector3,Dn=["getX","getY","getZ"];class hs extends Ec{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 hs(e,{...i,[vr]:!0});if(a._roots=n,a._indirectBuffer=r||null,i.setIndex){const l=e.getIndex();if(l===null){const h=new L.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,x=d.byteLength/Be;m<x;m++){const g=Me*m,M=2*g;ue(M,f)||(u[g+6]=u[g+6]/Me-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[Dn[f]](h),x=r[Dn[f]](d),g=r[Dn[f]](u);let M=m;x<M&&(M=x),g<M&&(M=g);let w=m;x>w&&(w=x),g>w&&(w=g),e[i+f]=M,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,x=t+e;m<x;m++){const M=(n?n[m]:m)*3,w=(m-f)*6;let b=M+0,C=M+1,S=M+2;a&&(b=a[b],C=a[C],S=a[S]),o||(b=b*d+h,C=C*d+h,S=S*d+h);for(let O=0;O<3;O++){let E,v,T;o?(E=r[u[O]](b),v=r[u[O]](C),T=r[u[O]](S)):(E=l[b+O],v=l[C+O],T=l[S+O]);let P=E;v<P&&(P=v),T<P&&(P=T);let _=E;v>_&&(_=v),T>_&&(_=T);const I=(_-P)/2,B=O*2;i[w+B+0]=P+I,i[w+B+1]=I+(Math.abs(P)+I)*en}}return i}raycastObject3D(t,e,i=[]){const{material:s}=t;if(s===void 0)return;sa.copy(t.matrixWorld).invert(),Ds.copy(e.ray).applyMatrix4(sa),na.setFromMatrixScale(t.matrixWorld),ia.copy(Ds.direction).multiply(na);const n=ia.length(),r=e.near/n,a=e.far/n;if(e.firstHitOnly===!0){let o=this.raycastFirst(Ds,s,r,a);o=ta(o,t,e),o&&i.push(o)}else{const o=this.raycast(Ds,s,r,a);for(let l=0,h=o.length;l<h;l++){const d=ta(o[l],t,e);d&&i.push(d)}}return i}refit(t=null){return(this.indirect?Kc:Fc)(this,t)}raycast(t,e=L.FrontSide,i=0,s=1/0){const n=this._roots,r=[],a=this.indirect?$c:jc;for(let o=0,l=n.length;o<l;o++)a(this,o,e,t,r,i,s);return r}raycastFirst(t,e=L.FrontSide,i=0,s=1/0){const n=this._roots;let r=null;const a=this.indirect?Qc:Hc;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?eh:Gc;for(let r=0,a=s.length;r<a&&(i=n(this,r,t,e),!i);r++);return i}shapecast(t){const e=it.getPrimitive(),i=super.shapecast({...t,intersectsPrimitive:t.intersectsTriangle,scratchPrimitive:e,iterate:this.indirect?Uc:Rc});return it.releasePrimitive(e),i}bvhcast(t,e,i){let{intersectsRanges:s,intersectsTriangles:n}=i;const r=it.getPrimitive(),a=this.geometry.index,o=this.geometry.attributes.position,l=this.indirect?m=>{const x=this.resolveTriangleIndex(m);ge(r,x*3,a,o)}:m=>{ge(r,m*3,a,o)},h=it.getPrimitive(),d=t.geometry.index,u=t.geometry.attributes.position,f=t.indirect?m=>{const x=t.resolveTriangleIndex(m);ge(h,x*3,d,u)}:m=>{ge(h,m*3,d,u)};if(n){if(!(t instanceof hs))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const m=(x,g,M,w,b,C,S,O)=>{for(let E=M,v=M+w;E<v;E++){f(E),h.a.applyMatrix4(e),h.b.applyMatrix4(e),h.c.applyMatrix4(e),h.needsUpdate=!0;for(let T=x,P=x+g;T<P;T++)if(l(T),r.needsUpdate=!0,n(r,h,T,E,b,C,S,O))return!0}return!1};if(s){const x=s;s=function(g,M,w,b,C,S,O,E){return x(g,M,w,b,C,S,O,E)?!0:m(g,M,w,b,C,S,O,E)}}else s=m}return super.bvhcast(t,e,{intersectsRanges:s})}intersectsBox(t,e){return ks.set(t.min,t.max,e),ks.needsUpdate=!0,this.shapecast({intersectsBounds:i=>ks.intersectsBox(i),intersectsTriangle:i=>ks.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?rh:Zc)(this,t,e,i,s,n,r)}closestPointToPoint(t,e={},i=0,s=1/0){return Ic(this,t,e,i,s)}}const Ci={Mesh:L.Mesh.prototype.raycast,Line:L.Line.prototype.raycast,LineSegments:L.LineSegments.prototype.raycast,LineLoop:L.LineLoop.prototype.raycast,Points:L.Points.prototype.raycast,BatchedMesh:L.BatchedMesh.prototype.raycast},Ee=new L.Mesh,Ls=[];function ah(c,t){if(this.isBatchedMesh)oh.call(this,c,t);else{const{geometry:e}=this;if(e.boundsTree)e.boundsTree.raycastObject3D(this,c,t);else{let i;if(this instanceof L.Mesh)i=Ci.Mesh;else if(this instanceof L.LineSegments)i=Ci.LineSegments;else if(this instanceof L.LineLoop)i=Ci.LineLoop;else if(this instanceof L.Line)i=Ci.Line;else if(this instanceof L.Points)i=Ci.Points;else throw new Error("BVH: Fallback raycast function not found.");i.call(this,c,t)}}}function oh(c,t){if(this.boundsTrees){const e=this.boundsTrees,i=this._drawInfo||this._instanceInfo,s=this._drawRanges||this._geometryInfo,n=this.matrixWorld;Ee.material=this.material,Ee.geometry=this.geometry;const r=Ee.geometry.boundsTree,a=Ee.geometry.drawRange;Ee.geometry.boundingSphere===null&&(Ee.geometry.boundingSphere=new L.Sphere);for(let o=0,l=i.length;o<l;o++){if(!this.getVisibleAt(o))continue;const h=i[o].geometryIndex;if(Ee.geometry.boundsTree=e[h],this.getMatrixAt(o,Ee.matrixWorld).premultiply(n),!Ee.geometry.boundsTree){this.getBoundingBoxAt(h,Ee.geometry.boundingBox),this.getBoundingSphereAt(h,Ee.geometry.boundingSphere);const d=s[h];Ee.geometry.setDrawRange(d.start,d.count)}Ee.raycast(c,Ls);for(let d=0,u=Ls.length;d<u;d++){const f=Ls[d];f.object=this,f.batchId=o,t.push(f)}Ls.length=0}Ee.geometry.boundsTree=r,Ee.geometry.drawRange=a,Ee.material=null,Ee.geometry=null}else Ci.BatchedMesh.call(this,c,t)}L.Mesh.prototype.raycast=ah;const Rs=new p.Sphere,Fs=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(),Rs.copy(e.boundingSphere),Rs.applyMatrix4(i),Rs.radius+=s,c.ray.intersectsSphere(Rs)===!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 x=a.getX(f);if(Fs.fromBufferAttribute(l,x).applyMatrix4(i),ra(Fs,x,r,c,t,this),t.length-h>=Oi)return}}else{const d=Math.max(0,n.start),u=Math.min(l.count,n.start+n.count);for(let f=d,m=u;f<m;f++)if(Fs.fromBufferAttribute(l,f).applyMatrix4(i),ra(Fs,f,r,c,t,this),t.length-h>=Oi)return}};function ra(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 lh=p.Points,ch=`
|
|
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.
|
|
@@ -531,9 +531,9 @@ void main() {
|
|
|
531
531
|
|
|
532
532
|
gl_FragColor = tileObjectId2Color(vTileObjectId);
|
|
533
533
|
}
|
|
534
|
-
`,Ve=p.ShaderChunk;Ve.outline_bc_vertex=uh;Ve.outline_bc_fragment=fh;Ve.outline_bc_pars_fragment=ph;Ve.outline_bc_pars_vertex=mh;Ve.standard_ex_vertex=wh;Ve.standard_ex_fragment=vh;Ve.common_ex=ch;Ve.id_pars_vertex=hh;Ve.id_vertex=dh;Ve.state_pars_fragment=gh;Ve.state_fragment=yh;Ve.state_transparent_fragment=xh;Ve.state_highlight_fragment=bh;Ve.pick_ex_vertex=Mh;Ve.pick_ex_fragment=Th;const Ch=p.ShaderChunk;class Sh{constructor(t){x(this,"promise");x(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 Eh=zr.default??zr,A=Eh;A.setLevel("warn");const mo=c=>{try{A.setLevel(c)}catch(t){A.setLevel("error"),A.error(t)}},Ai=class Ai{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),r=/(?:iPhone)/.test(t)&&!n,a=!r&&!e,o=Ai.isTouchScreenDevice();e&&A.debug("[DI] is android"),i&&A.debug("[DI] is fireFox"),s&&A.debug("[DI] is chrome"),n&&A.debug("[DI] is tablet"),r&&A.debug("[DI] is iPhone"),a&&A.debug("[DI] is PC"),o&&A.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:()=>{}}}};x(Ai,"isMobile",/mobile/i.test(navigator.userAgent)),x(Ai,"isBrowser",typeof document<"u"),x(Ai,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let ke=Ai;const Ii=class Ii{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof p.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof p.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof p.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new p.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(t instanceof p.Vector2)return new p.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new p.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof p.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new p.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,n=(t.max.y-t.min.y)*e,r=(t.max.z-t.min.z)*e,a=new p.Vector3(i.x-s/2,i.y-n/2,i.z-r/2),o=new p.Vector3(i.x+s/2,i.y+n/2,i.z+r/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new p.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,n=t.max.y-t.min.y,r=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),n<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),r<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const n=Math.max(e.min.x,0),r=Math.max(e.min.y,0),a=Math.max(e.max.x-n,0),o=Math.max(e.max.y-r,0),l=t.getImageData(n,r,a,o),h=document.createElement("canvas");return h.width=a,h.height=o,h.getContext("2d").putImageData(l,0,0),h.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!ke.isBrowser)return;const e=performance.memory;if(!e){A.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);A.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+n+"M ")}static printGpuInfo(t){if(!ke.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);A.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ii.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,n=Date.now();n-e>s&&(await Ii.sleep(0),e=n)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async n=>{if(e&&(n%i===0||n===t-1)){e(new ProgressEvent("",{loaded:n+1,total:t}));const r=500,a=Date.now();(a-s>r||n===t-1)&&(await Ii.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return n=>{let r=n.loaded*100/n.total;r=r*(e-t)/100+t,r>e&&(s||(A.warn("[Progress] Invalid ProgressEvent:",n),s=!0),r=e),i&&i(new ProgressEvent(n.type,{loaded:r,total:100}))}}};x(Ii,"twinklingObjectIds",{});let N=Ii;const Oh=(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 Di{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 _e{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=_e.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=_e.world2Screen(s,e,i);return r.x/=i.clientWidth,r.y/=i.clientHeight,r}}class _h{static createCSS2DObject(t){const e=new lo.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 go={"Precision from file":99},Ph=(c,t)=>c.toFixed(t===go["Precision from file"]?2:t),yo="en",it=!1,xo=10,Ge=11,Nt=12,Er=583902,Ah=[.031,.906,.867,.5],sn=[.3,.3,.3,.8],Or=.5,nn=.1,rn=5e3,bo=45,Ih="x-viewer-iconfont",Bh="x-viewer-iconfont2",_r=10,aa=new p.Vector3,oa=new p.Vector3,la=new p.Vector3,is=new p.Vector3,_t=new p.Vector3,ca=new p.Triangle;function kh(c,t,e,i,s){const n=[],r={};let a,o,l,h;const u=Math.pow(10,4);let f,m,y=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]=y/3,e[y++]=a,e[y++]=o,e[y++]=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 Dh(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;aa.set(e[r],e[r+1],e[r+2]),oa.set(e[a],e[a+1],e[a+2]),la.set(e[o],e[o+1],e[o+2]),p.Triangle.getNormal(aa,oa,la,is),i.push({normal:is.clone()})}}const Ln=[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 Lh(c,t){return _t.addVectors(c,t),_t.x===0||_t.y===0||_t.z===0}class wo{static buildEdge(t,e,i=_r){const s=[],n=[],r=[];kh(t,e,s,n,r);const a=[];Dh(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 y=0;y<3;y++){const g=r[u+y],M=r[u+(y+1)%3],w=Math.min(g,M),b=Math.max(g,M),C=w+","+b;h[C]===void 0?h[C]={index1:w,index2:b,face1:m,face2:void 0}:h[C].face2=m}}for(const u in h){const f=h[u];if(f.face2!==void 0){const g=a[f.face1].normal,M=a[f.face2].normal;if(g.dot(M)>l)continue}const m=n[f.index1],y=n[f.index2];(!d&&m>65535||y>65535)&&(d=!0),o.push(m),o.push(y)}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=Ln.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={},y={};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:P,c:I}=ca;if(_.fromBufferAttribute(e,o[0]),P.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),ca.getNormal(is),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(P.x*s)+","+Math.round(P.y*s)+","+Math.round(P.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]){A.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 D=(k+1)%3,z=l[k],se=l[D],re=o[k],Ue=o[D];!u[re]&&(u[re]=new Set),u[re].add(Ue),!u[Ue]&&(u[Ue]=new Set),u[Ue].add(re);const De=z+"_"+se,de=se+"_"+z;if(de in y&&y[de]){if(y[de].outer){A.warn("[Edge] edge: "+de+" is already outer!");continue}is.dot(y[de].normal)<=n?y[de].outer=!0:y[de].find=!0}else De in y?A.warn("[Edge] "+De+" has existed in geometry!"):y[De]={startIndex:re,endIndex:Ue,normal:is.clone(),outer:!1,find:!1}}}for(const T in y)y[T]&&!y[T].find&&!y[T].outer&&(y[T].outer=!0);const g=[],M=[];for(const T in f)M.push(f[T]);let w=new Set;for(const T of M[0])w.add(T.a),w.add(T.b),w.add(T.c);let b=0;for(M.splice(b,1);;){let T=!1;for(let _=0;_<M.length&&!T;_++)for(const P of M[_])if(w.has(P.a)||w.has(P.b)||w.has(P.c)){b=_,T=!0;break}if(T){for(const _ of M[b])w.add(_.a),w.add(_.b),w.add(_.c);if(M.splice(b,1),b=0,M.length===0){g.push(w);break}}else if(!T)if(g.push(w),M.length>0){w=new Set;for(const _ of M[b])w.add(_.a),w.add(_.b),w.add(_.c);M.splice(b,1),b=0}else break}const C=new Set;for(let T=0;T<g.length;T++)g[T].forEach(P=>{C.has(P)?A.warn("[Edge] "+P+" is already in positionIndexSet!"):C.add(P)});const S=(T,_)=>{let P=!1;const I=m[T];if(!I)return console.warn(T+" is not in positionIndexHash!"),P;const B=m[_];if(!B)return console.warn(_+" is not in positionIndexHash!"),P;const k=I+"_"+B;if(y[k])P=y[k].outer;else{const D=B+"_"+I;y[D]&&(P=y[D].outer)}return P},O=(T,_,P)=>{const I=[];return I.push(S(T,_)),I.push(S(_,P)),I.push(S(P,T)),I.filter(B=>B===!0).length>=2},E=(T,_)=>{if(!u[T])return A.warn("[Edge] "+T+" position isn't used!"),!0;const P=u[T];for(const B of P){const k=S(T,B),D=d[B];if(!D.inited)continue;const z=Lh(_,D.point);if(k&&!z||!k&&z)return!1}const I=f[T];for(const B of I){const k=_;let D=d[B.b],z=d[B.c];if(B.b===T?D=d[B.a]:B.c===T&&(z=d[B.a]),O(B.a,B.b,B.c)&&(D.inited&&k.equals(D.point)||z.inited&&k.equals(z.point)))return!1;if(!(!D.inited||!z.inited)&&(_t.addVectors(k,D.point),_t.add(z.point),_t.x+_t.y+_t.z<2))return!1}return!0};let v=!1;for(let T=0;T<g.length;T++){const _=Array.from(g[T]);v=!1;let P=0,I=0;for(;I>=0;){P=_[I];let B=d[P].inited?d[P].barycentricIndex+1:0;for(;B<h&&!E(P,Ln[B]);B++);if(B<h)if(d[P].inited=!0,d[P].barycentricIndex=B,d[P].point.copy(Ln[B]),I==_.length-1){v=!0,A.debug("[Edge]",d);break}else I++;else d[P].inited=!1,I--}if(!v){A.warn("[Edge] no result: "+_+"!");break}}if(v){const T=[];for(let P=0;P<d.length;P++){!d[P].inited&&A.warn("[Edge] "+P+" is not initialized !");let I=0;I|=d[P].point.x,I|=d[P].point.y<<1,I|=d[P].point.z<<2,T.push(I)}const _=new p.Uint8BufferAttribute(T,1,!1);t.setAttribute("barycentric",_)}else A.warn("[Edge] No suitable barycentric found!");return v}}class Gt{constructor(){x(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 K=class K{static exportToGltf(t,e){K.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){K.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new bl.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,r=>{if(i.binary){e=K.addExtention(e,K.EXTENSION_GLB);const a=r;K.saveArrayBuffer(a,e)}else e=K.addExtention(e,K.EXTENSION_GLTF),K.saveJson(r,e)},r=>console.log(r),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_OBJ);const i=new wl.OBJExporter,s=i.parse(t);K.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_DRACO);const s=new xl.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const r=s.parse(t,i);K.saveArrayBuffer(r,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_STL);const s=new vl.STLExporter;if(i){const n={binary:!0},r=s.parse(t,n);K.saveDataView(r,e)}else{const n=s.parse(t);K.saveString(n,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(K.EXTENSION_JSON)||(e+=K.EXTENSION_JSON),K.saveJson(i,e)}static save(t,e){let i=K.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),K.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){K.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){K.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){K.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){K.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){K.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};x(K,"EXTENSION_GLTF",".gltf"),x(K,"EXTENSION_GLB",".glb"),x(K,"EXTENSION_OBJ",".obj"),x(K,"EXTENSION_DRACO",".drc"),x(K,"EXTENSION_JSON",".json"),x(K,"EXTENSION_STL",".stl"),x(K,"downloadLink");let fr=K;class Rh{constructor(){x(this,"prevTime");x(this,"beginTime");x(this,"frames");x(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 Rn=1e-15,ha=new p.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),da=new p.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class V{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 V.areNumbersEqual(t.x,e.x,i)&&V.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return V.areNumbersEqual(t.x,e.x,i)&&V.areNumbersEqual(t.y,e.y,i)&&V.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 V.areNumbersClose(t,e,Rn)?0:(t%=i,V.areNumbersClose(t,e%i,Rn)?i:(V.areNumbersClose(e,i,Rn)&&(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=V.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(V.getRelativeEps(t.x,e),V.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(ha.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(ha),e}static convertPointFromUEToRevit(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(da.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(da),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=V.convertPointFromGltfToUE(t.min),i=V.convertPointFromGltfToUE(t.max);return V.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=V.convertPointFromUEToGltf(t.min),i=V.convertPointFromUEToGltf(t.max);return V.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=V.convertPointFromRevitToUE(t.min),i=V.convertPointFromRevitToUE(t.max);return V.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=V.convertPointFromUEToRevit(t.min),i=V.convertPointFromUEToRevit(t.max);return V.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 V.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=V.fromSnorm(t.x,i),e.y=V.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))*V.signNotZero(s),e.y=(1-Math.abs(s))*V.signNotZero(e.y)}}}const Fn=1e7,ua=new p.Box2,fa=new p.Box2,pa=new p.Vector3,ma=new p.Vector3,ga=new p.Vector3,kt=new p.Triangle,Fh=/not find (pre|next) vertex|has repeat vertex|translateLine line eror|not find Intersection/;function zh(c){const t=console.error;console.error=(...e)=>{typeof e[0]=="string"&&Fh.test(e[0])||t.apply(console,e)};try{return c()}finally{console.error=t}}class G{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=pa.subVectors(s,i).normalize(),o=ma.subVectors(r,n).normalize();if(a.dot(o)===1)return null;const l=ga.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(V.areNumbersEqual(0,f))return;const m=d.clone().dot(h)/f,y=i.clone().add(a.multiplyScalar(m));return y.equals(i)||y.equals(s)?null:y}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:n}=e,r=pa.subVectors(s,n).length(),a=ma.subVectors(t,s).length(),o=ga.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(G.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)>Fn||Math.abs(t.y)>Fn||t instanceof p.Vector3&&Math.abs(t.z)>Fn}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)kt.a.fromBufferAttribute(i,s.getX(n)),kt.b.fromBufferAttribute(i,s.getX(n+1)),kt.c.fromBufferAttribute(i,s.getX(n+2)),e+=kt.getArea();else for(let n=0;n<i.count;n+=3)kt.a.fromBufferAttribute(i,n),kt.b.fromBufferAttribute(i,n+1),kt.c.fromBufferAttribute(i,n+2),e+=kt.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,G.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||(ua.setFromPoints(t),fa.setFromPoints(e),!ua.intersectsBox(fa)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&V.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 y=(u*h-l*f)/m,g=(o*f-d*h)/m;return new p.Vector2(y,g)}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=[],y=e/2;for(let b=0,C=t.length-1;b<C;b++)s=!b,n=b===t.length-2,i=this.getOffsetPoint(t[b],t[b+1],y),h=new p.Vector2(t[b].x+i.x,t[b].y+i.y),d=new p.Vector2(t[b+1].x+i.x,t[b+1].y+i.y),u=new p.Vector2(t[b].x-i.x,t[b].y-i.y),f=new p.Vector2(t[b+1].x-i.x,t[b+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 g=p.ShapeUtils.triangulateShape(m,[]),M=[];for(let b=0;b<g.length;b++)M.push(...g[b]);const w=new p.BufferGeometry().setFromPoints(m);return w.setIndex(M),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}=zh(()=>Ml.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++)V.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 vo={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"},WebGL:{NotAvailable:"Unable to create a WebGL context in this browser/GPU environment; the drawing cannot be rendered. A common cause is hardware acceleration (called 'graphics acceleration' in some browsers) being enabled while the GPU cannot keep up. Please turn OFF this option in your browser settings and restart the browser. If it still fails, update the graphics driver or try a different browser.",SettingsLink:"Open Chrome System Settings (chrome://settings/system)",CopyFallback:"请手动打开 chrome://settings/system 并关闭硬件加速(部分浏览器称为「图形加速」),然后重启浏览器。"}},Mo={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"},WebGL:{NotAvailable:"当前浏览器或显卡环境无法创建 WebGL 上下文,图纸无法渲染。常见原因是开启了浏览器的硬件加速(部分浏览器称为「图形加速」)但显卡性能不足:请在浏览器设置中关闭该选项,并重启浏览器。",SettingsLink:"打开 Chrome 系统设置(chrome://settings/system)",CopyFallback:"请手动打开 chrome://settings/system 并关闭硬件加速(部分浏览器称为「图形加速」),然后重启浏览器。"}},Fe=Tl.createInstance(),Vh="cn";Fe.init({lng:Vh,debug:!1,resources:{en:{translation:vo},cn:{translation:Mo}}});class ve{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(Er),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 Uh=new p.Vector3(0,1,0),$e=class $e{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&&A.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 $e.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);$e.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);$e.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);$e.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=N.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,y=(h+1)*90/r;d=N.getUpdateSubProgressFunc(m,y,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,_r),n=new p.LineSegments(s,e);return n.layers.enableAll(),$e.disableLayerChannels(n,[Nt,Ge]),n.userData.isOutline=!0,n.matrixAutoUpdate=it,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=ve.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=Uh;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++)$e.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++)$e.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++)$e.setLayerChannels(s[n],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(xo)}static isObjectSnapable(t){return t.layers.isEnabled(Ge)}static isObjectSelectable(t){return t.layers.isEnabled(Nt)}static disposeObject(t){t.traverse(e=>{const i=e;if(i.geometry){i.geometry.dispose(),(Array.isArray(i.material)?i.material:[i.material]).forEach(r=>r?.dispose());const n=e.userData?.originalMaterial;n&&(Array.isArray(n)?n:[n]).forEach(r=>r?.dispose())}})}};x($e,"OUTLINE_MATERIAL",new p.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),x($e,"BOX_FACE_MATERIAL",new p.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:p.FrontSide}));let Q=$e;const zs=new p.Matrix4,jh=new p.Matrix4,os=class os{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 y=f[m].indexes[0];if(u=this.tryHandleMergeableObjects(t,h,y,s,n),u)break}for(let m=n.length-1;!u&&m>=0;--m){const y=n[m];if(u=this.tryHandleMergeableObjects(t,h,y,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,y=0,g=0;const M=[];if(d.forEach(b=>{const C=t.children[b],S=C.geometry.clone();if(S.applyMatrix4(C.matrix),G.tryConvertInterleavedBufferAttributes(S),S.userData.isLineSegments=C.isLineSegments===!0,f.push(S),e){const O=C.name,E=S.attributes?.position?.count,v=S.index?.count||0,T={batchId:m,name:O,positionStart:y,positionCount:E,indexStart:g,indexCount:v};Object.keys(C.userData).length!==0&&(T.userData=C.userData),M.push(T),y+=E,g+=v,m++}}),f.length===0)return;let w;if(u.isMesh){const b=Ae.mergeGeometries(f);if(!b)return;b.userData={},w=new p.Mesh(b,u.material),r.push(w)}else if(u.isLine){const b=this.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,M);if(!b)return;w=new p.LineSegments(b,u.material),a.push(w)}else if(u.isPoints){const b=Ae.mergeGeometries(f);if(!b)return;b.userData={},w=new p.Points(b,u.material),o.push(w)}w&&(e?w.userData.batches=M:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.matrixAutoUpdate=it,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,w.visible=u.visible,l.push(...d)),f.forEach(b=>{b.dispose(),G.releaseGeometryManually(b)}),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)&&ve.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 g=0;g<t.length;++g){const M=t[g];if(M.isInstancedMesh||!M.geometry||!(M.geometry instanceof p.BufferGeometry))continue;let w=!1;const b=Object.values(o);for(let C=b.length-1;C>=0;--C){const S=b[C].indexes[0];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}for(let C=l.length-1;!w&&C>=0;--C){const S=l[C];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}!w&&l.push(g)}if(Object.keys(o).length<=0)return r;A.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(g=>{const M=g.indexes;if(M.length<2)return;const w=t[M[0]];let b=[],C=0,S=0,O=0;const E=[];if(M.forEach(T=>{const _=t[T],P=_.geometry.clone();if(w.material instanceof p.LineBasicMaterial&&P.deleteAttribute("lineDistance"),this.applyMatrix(P,_,e),P.userData.isLineSegments=_.isLineSegments===!0,b.push(P),n){const I=_.name,B=P.attributes?.position?.count,k=P.index?.count||0;let D;w.isLine&&(!P.boundingSphere&&P.computeBoundingSphere(),D=P.boundingSphere.clone());const z={batchId:C,name:I,positionStart:S,positionCount:B,indexStart:O,indexCount:k,boundingSphere:D};!_.parent.geometry&&Object.keys(_.parent.userData).length!==0&&(z.parentUserData=_.parent.userData),Object.keys(_.userData).length!==0&&(z.userData=_.userData),E.push(z),S+=B,O+=k,C++}}),b.length===0)return;let v;if(w.isMesh){const T=Ae.mergeGeometries(b);if(!T)return;T.userData={},v=new p.Mesh(T,w.material),h.push(v)}else if(w.isLine){const T=this.mergeLineGeometries(b,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=Ae.mergeGeometries(b);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=it,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,v.visible=w.visible,M.forEach(T=>f.push(T))),b.forEach(T=>{T.dispose(),G.releaseGeometryManually(T)}),b=[]}),A.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(g=>{const M=t[g];m.push(M),i&&M.removeFromParent()});const y=r.added;return[...h,...d,...u].forEach(g=>{y.push(g),i&&e&&(e.add(g),g.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&&Q.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(zs.identity();s&&s!==i&&(zs.premultiply(s.matrix),!!s.parent);)s=s.parent;return zs.equals(jh)?t:t.applyMatrix4(zs)}static mergeLineGeometries(t,e,i,s){let n;if(i)n=os.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(n=Ae.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 y=d.array[m];u?r.push(a+y):m>0&&r.push(a+d.array[m-1],a+y)}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&&(A.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),h=G.convertGeometryWithIndexedToNonIndexed(h));let u=0;for(const f in h.attributes){if(!s.has(f))return A.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 A.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=os.mergeBufferAttributesWithLinesToLineSegments(n[l],a);if(!h)return A.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 A.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 A.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 A.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,y=new i(f*m);let g=0;for(let M=0;M<d.count;M++){const w=M*m,b=M!==0&&M!==d.count-1&&!h;for(let C=0;C<m;C++)y[g+C]=d.array[w+C],b&&(y[g+m+C]=d.array[w+C]);g+=b?2*m:m}a.set(y,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 A.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 A.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 A.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 y in h){const g=h[y],M=g.itemSize,w=g.array.slice(o*M,l*M);a.setAttribute(y,new p.BufferAttribute(w,M,g.normalized))}if(i.boundsTree&&(r=i.userData.originalIndex,!r))return A.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 y=d;y<u&&y<r.length;++y)f[m++]=r[y]-e.positionStart;return a.setIndex(f),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};x(os,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let me=os;const Nh=.01;class Hh{static getFaces(t){const e=t.map(n=>n.toArray()).reduce((n,r)=>(n.push(...r),n),[]),i=[];return Cl.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()>Nh)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return Sl(e).length>0}}class Pt{static getVisibleObjectBoundingBox(t){const e=new p.Box3;return t.traverse(i=>{i.visible&&(i instanceof p.Mesh||i instanceof p.Line)&&Q.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=Pt.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 Pt.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=Pt.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(N.isMatrixValid(a.matrixWorld)){const o=Pt.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()&&N.isBoxValid(r)&&e.union(r)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=Pt.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class Vt{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=>{Vt.setMaterialSection(a,e,i,s)}):r&&Vt.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 Gh{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new El.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof p.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const qh=10;var Ot=(c=>(c.TripleCross="TripleCross",c.Square="Square",c.Triangle="Triangle",c.CircleWithCross="CircleWithCross",c.Cross="Cross",c.Perpendicular="Perpendicular",c))(Ot||{});class Wh{static createSVGObject(t){return new Ol.SVGObject(t)}}class ds{static async createEnvTexture(t,e){const i=new _l.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!")}}x(ds,"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 Yh(){if(ke.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 pr={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:Yh()},To={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},Co=c=>c===2?"²":c===3?"³":"",mr=(c,t=1)=>To[c]+Co(t),Xh=(c,t,e,i=1)=>(e==null&&(e=t),e===t?{value:c,unit:mr(e)}:{value:c*Math.pow(pr[t]/pr[e],i),unit:mr(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 Zh{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 ce=(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))(ce||{});const ya={};class ms extends Gt{constructor(e){super();x(this,"viewer");x(this,"drawableLists");x(this,"canvas");x(this,"context");x(this,"frustum");x(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;ya[i.prototype.getClassType()]=e}static createDrawable(e){const i=ya[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(ce.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(ke.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=ke.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 N.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 gs extends Gt{constructor(e){super();x(this,"category");x(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=ms.createDrawable(s);this.addDrawable(n)}}getDrawableByPosition(e,i){let s;for(const[,n]of this.drawableMap)if(n.visible&&n.isPointInPath(e,i)){s=n;break}return s}}class Ht extends Gt{constructor(e){super();x(this,"DEFAULT_LINE_WIDTH",1);x(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);x(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);x(this,"id");x(this,"lineWidth");x(this,"lineColor");x(this,"fillColor");x(this,"x");x(this,"y");x(this,"width");x(this,"height");x(this,"points");x(this,"userData");x(this,"tolerance");x(this,"visible");x(this,"selected");x(this,"renderOrder");x(this,"needsFrustumCulled");x(this,"editPointSize");x(this,"editPointFillColor");x(this,"editPointStrokeColor");x(this,"matrix");x(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||N.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?_e.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 zn=new p.Vector3;class wt extends Ht{constructor(e,i,s=[1,0,0,1],n,r=!1){super(e);x(this,"boxes");x(this,"lineSegments");x(this,"useCloudBorder");this.lineSegments=[],this.useCloudBorder=r,this.boxes=wt.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=n??[s[0],s[1],s[2],.12],this.lineWidth=2,r&&this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),n=s.getSize(zn),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=zn.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=zn.subVectors(h,l),u=d.length(),f=d.normalize(),m=Math.ceil(u/r);for(let y=0;y<m;y++)a.push(l.clone().add(f.clone().multiplyScalar(r*y)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=Di.rgba2Color(this.lineColor),e.fillStyle=Di.rgba2Color(this.fillColor);for(let s=0;s<(this.useCloudBorder?this.lineSegments.length:this.boxes.length);s++){const n=this.boxes[s];if(n&&this.fillRect(e,i,n),this.useCloudBorder){const r=this.lineSegments[s];this.drawBox(e,i,r)}else this.drawRoundedRect(e,i,n)}e.restore()}drawRoundedRect(e,i,s){if(!s)return;const n=this.transToScreenCoord(new p.Vector3(s.min.x,s.min.y),i),r=this.transToScreenCoord(new p.Vector3(s.max.x,s.min.y),i),a=this.transToScreenCoord(new p.Vector3(s.max.x,s.max.y),i),o=this.transToScreenCoord(new p.Vector3(s.min.x,s.max.y),i),l=Math.hypot(r.x-n.x,r.y-n.y),h=Math.hypot(o.x-n.x,o.y-n.y),d=Math.max(0,Math.min(8,l/2,h/2));e.beginPath(),e.moveTo(n.x+d,n.y),e.arcTo(r.x,r.y,a.x,a.y,d),e.arcTo(a.x,a.y,o.x,o.y,d),e.arcTo(o.x,o.y,n.x,n.y,d),e.arcTo(n.x,n.y,r.x,r.y,d),e.closePath(),e.stroke()}fillRect(e,i,s){const n=[new p.Vector3(s.min.x,s.min.y),new p.Vector3(s.max.x,s.min.y),new p.Vector3(s.max.x,s.max.y),new p.Vector3(s.min.x,s.max.y)];e.beginPath();for(let r=0;r<n.length;r++){const a=this.transToScreenCoord(n[r],i);r===0?e.moveTo(a.x,a.y):e.lineTo(a.x,a.y)}e.closePath(),e.fill()}drawBox(e,i,s){e.beginPath();for(let n=0;n<s.length-1;n++){const r=this.transToScreenCoord(s[n],i),a=this.transToScreenCoord(s[n+1],i),o=wt.getControlPointByTwoPoints(a,r);n===0&&e.moveTo(r.x,r.y),e.quadraticCurveTo(o.x,o.y,a.x,a.y)}e.stroke()}static getControlPointByTwoPoints(e,i){const s=new p.Vector2().subVectors(i,e),n=s.angle(),r=s.length(),a=p.MathUtils.degToRad(45),o=r/2/Math.cos(a);return new p.Vector2(e.x+o*Math.cos(a-n),e.y-o*Math.sin(a-n))}drawSelect(e,i){throw new Error("Method not implemented.")}isPointInPath(e){return!1}getBounds(){const e=new p.Box3;for(let i=0;i<this.boxes.length;i++){const s=this.boxes[i];e.union(s)}return e}getClassType(){return"CompareDrawable"}}ms._registerDrawableClass(wt);const Kh=[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],$h=["PROXY","REGION","INSERT","HATCH"];function oi(c){return Kh[c]}function F(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;let s=!1,n=!1,r=!1,a=!1;for(;!c.isEOF();){const o=e.code;if(o===i&&!s)t.x=e.value,s=!0;else if(o===i+10&&!n)t.y=e.value,n=!0;else if(o===i+20&&!r)t.z=e.value,r=!0;else if(o===42&&!a)t.bulge=e.value,a=!0;else return t;e=c.next()}return t}const Jh="OriginalHandle",Qh="OriginalType",ed="Outlines";function te(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(c.zdysx||(c.zdysx=""),c.zdysx+=t.value,t.value.includes(Jh)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalHandle=e[1]}if(t.value.includes(ed)&&(c.extendedData||(c.extendedData={}),c.extendedData.outlines=[]),t.value.includes(Qh)){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 Fi(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 Pr="BYLAYER",us="BYBLOCK";var be=(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.InsertLine=4.4]="InsertLine",c[c.InsertSymbol=4.6]="InsertSymbol",c[c.Text=5]="Text",c))(be||{});const ss=["INSERT","DIMENSION"];function td(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 id(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 xa(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 sd(c,t){const e=xa(c.text).plainText,i=xa(t.text).plainText;return e===i}var He=(c=>(c.Added="Added",c.Removed="Removed",c.Modified="Modified",c.NoChange="NoChange",c))(He||{});let Re=1;const Ct=class Ct{constructor(t,e,i={}){x(this,"dxf1");x(this,"dxf2");x(this,"changes");x(this,"comparedBlocks");x(this,"isComparingBlock");x(this,"isComparingDimension");x(this,"enableDetailComparision");if(this.changes={},this.comparedBlocks=new Map,this.isComparingBlock=!1,this.isComparingDimension=!1,this.enableDetailComparision=i.enableDetailComparision!=null?i.enableDetailComparision:!0,this.dxf1=t,this.dxf2=e,!t||!e)throw new Error("Invalid DXF data to compare!")}getLayerFrozen(t,e){const i=e.layer;if(!i)return;const s=t.tables?.layer?.layers;return s?s[i]?.frozen:void 0}async compare(t){this.changes={};const e=[],i=new Map;return this.dxf1.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf1,s)===!0;!Ct.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&e.push(s)}}),this.dxf2.entities.forEach(s=>{if(!s.inPaperSpace){const n=this.getLayerFrozen(this.dxf2,s)===!0;!Ct.ENTITY_TYPES_TO_IGNORE.includes(s.type)&&!n&&i.set(s.handle,s)}}),await this.compareEntities(e,i,t),Promise.resolve(this.changes)}isDimensionBlock(t){return t.includes("*D")}compareInsertOrDemensionEntities(t,e,i,s){if(!t.block||!e.block)return;const n=t.block;let r;if(this.isComparingBlock=!0,this.isDimensionBlock(n)){const a=this.dxf1.blocks[t.block],o=this.dxf2.blocks[e.block],l=Date.now();this.isComparingDimension=!0,r=this.compareBlock(t,e,a,o),this.isComparingDimension=!1,A.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),A.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[Re]={id:Re,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[Re]={id:Re,...a,parentHandles:o}),Re++}}),!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=N.getUpdateProgressFuncForLoop(t.length,i);for(let n=0;n<t.length;n++){const r=t[n].handle;if(!e.has(r))this.changes[Re]={id:Re,type:"Removed",handle:r},Re++;else{const a=t[n],o=e.get(r),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(ss.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(r),A.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[Re]={id:Re,type:"Modified",handle:r},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[Re].detailChanges=l),Re++}e.delete(r)}await s(n)}for(const n of e){const r=n[0];this.changes[Re]={id:Re,type:"Added",handle:r},Re++}}bIgnoreChildEntitiesOriginalType(t){return $h.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!==Pr&&t.lineType!==us)return t.lineType;if(t.lineType===us)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(!sd(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"?(A.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 A.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?V.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)}};x(Ct,"ENTITY_COLOR_ADDED",65280),x(Ct,"ENTITY_COLOR_REMOVED",16711680),x(Ct,"ENTITY_COLOR_NO_CHANGE",10066329),x(Ct,"ENTITY_COLOR_MARKUP",16744231),x(Ct,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let ct=Ct;var q=(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))(q||{});const Vn=new L.Box3,Un=new L.Matrix4;class U{constructor(t=0){x(this,"name");x(this,"type");x(this,"matrix");x(this,"parent");x(this,"children");x(this,"layers");x(this,"renderOrder");x(this,"userData");x(this,"material");x(this,"geometry");x(this,"matrixWorld");this.name="",this.type=0,this.matrix=new L.Matrix4,this.children=[],this.layers=new L.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 U().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 L.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=it,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(),Un.copy(t.matrix),i&&Un.premultiply(i),Vn.copy(t.geometry.boundingBox),Vn.applyMatrix4(Un),e.union(Vn);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new L.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 L.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new L.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 L.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 Vs=new p.Matrix4,nd=new p.Matrix4;class Tt{static resetMergeInfo(){this.MergeInfo.removedObjects=0,this.MergeInfo.mergedMeshes=0,this.MergeInfo.mergedLines=0,this.MergeInfo.mergedPoints=0,this.MergeInfo.mergedUnknownTypeObjects=0,this.MergeInfo.elapsedTime=0}static merge(t,e=!0){const i=Date.now();this.mergeInner(t,e),this.MergeInfo.elapsedTime+=Date.now()-i}static mergeInner(t,e=!0){if(!t.children||t.children.length<1)return;const i=t.children.length,s={},n=[];for(let h=0;h<i;++h){const d=t.children[h];if(d.children.length>0){this.mergeInner(d,e);continue}if(d.userData.relativeToCenter||!d.geometry)continue;let f=!1;const m=Object.values(s);for(let y=m.length-1;y>=0;--y){const g=m[y].indexes[0];if(f=this.tryHandleMergeableObjects(t,h,g,s,n),f)break}for(let y=n.length-1;!f&&y>=0;--y){const g=n[y];if(f=this.tryHandleMergeableObjects(t,h,g,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,y=0,g=0;const M=[];if(d.forEach(b=>{const C=t.children[b],S=C.geometry?.clone();if(S.applyMatrix4(C.matrix),S.userData.isLineSegments=C.type===q.LineSegment,f.push(S),e){const O=S.attributes?.position?.count,E=S.index?.count||0;M.push({batchId:m,positionStart:y,positionCount:O,indexStart:g,indexCount:E}),y+=O,g+=E,m++}}),f.length===0)return;let w;if(u.type===q.Mesh){const b=Ae.mergeGeometries(f);if(!b)return;b.userData={},w=new U(u.type),w.geometry=b,w.material=u.material,r.push(w)}else if(u.type===q.Line||u.type===q.LineSegment){const b=me.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,M);if(!b)return;w=new U(q.LineSegment),w.geometry=b,w.material=u.material,a.push(w)}else if(u.type===q.Point){const b=Ae.mergeGeometries(f);if(!b)return;b.userData={},w=new U(u.type),w.geometry=b,w.material=u.material,o.push(w)}w&&(e?w.userData.batches=M:(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(b=>{b.dispose(),G.releaseGeometryManually(b)}),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)&&me.areGeometriesMergeable(l.geometry,h.geometry)&&ve.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===q.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 g=0;g<t.length;++g){if(!t[g].geometry||this.isFilteredByOtherFactors(t[g],e))continue;let w=!1;const b=Object.values(o);for(let C=b.length-1;C>=0;--C){const S=b[C].indexes[0];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}for(let C=l.length-1;!w&&C>=0;--C){const S=l[C];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}!w&&l.push(g)}if(Object.keys(o).length<=0)return r;A.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(g=>{const M=g.indexes;if(M.length<2)return;const w=t[M[0]];let b=[],C=0,S=0,O=0;const E=[];if(M.forEach(T=>{const _=t[T],P=_.geometry?.clone();if(w.material instanceof p.LineBasicMaterial&&P.deleteAttribute("lineDistance"),this.applyMatrix(P,_,e),P.userData.isLineSegments=_.type===q.LineSegment,b.push(P),n){const I=P.attributes?.position?.count,B=P.index?.count||0;let k;(w.type===q.Line||w.type===q.LineSegment)&&(!P.boundingSphere&&P.computeBoundingSphere(),k=P.boundingSphere?.clone());const D={batchId:C,positionStart:S,positionCount:I,indexStart:O,indexCount:B,boundingSphere:k};Object.keys(_.userData).length!==0&&(D.userData=_.userData),E.push(D),S+=I,O+=B,C++}}),b.length===0)return;let v;if(w.type===q.Mesh){const T=Ae.mergeGeometries(b);if(!T)return;T.userData={},v=new U(w.type),v.geometry=T,v.material=w.material,h.push(v)}else if(w.type===q.Line||w.type===q.LineSegment){const T=me.mergeLineGeometries(b,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,E);if(!T)return;v=new U(q.LineSegment),v.geometry=T,v.material=w.material,d.push(v)}else if(w.type===q.Point){const T=Ae.mergeGeometries(b);if(!T)return;T.userData={},v=new U(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,M.forEach(T=>f.push(T))),b.forEach(T=>{T.dispose(),G.releaseGeometryManually(T)}),b=[]}),A.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(g=>{const M=t[g];m.push(M),i&&M.removeFromParent()});const y=r.added;return[...h,...d,...u].forEach(g=>{y.push(g),i&&e&&e.add(g)}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&Q.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Vs.identity();s&&s!==i&&(Vs.premultiply(s.matrix),!!s.parent);)s=s.parent;return Vs.equals(nd)?t:t.applyMatrix4(Vs)}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.userData.isConstructionLine||e.userData.isConstructionLine||t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===q.Line||t.type===q.LineSegment)&&(e.type===q.Line||e.type===q.LineSegment)}}x(Tt,"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 y=s?s[m]:1;for(let g=0;g<r;g++)d[m][g]=e[m][g]*y;d[m][r]=y}let u;for(let m=1;m<=t+1;m++)for(let y=h;y>h-t-1+m;y--){u=(c-i[y])/(i[y+t+1-m]-i[y]);for(let g=0;g<r+1;g++)d[y][g]=(1-u)*d[y-1][g]+u*d[y][g]}const f=[];for(let m=0;m<r;m++)f[m]=Eo(d[h][m]/d[h][r],-9);return f},rd={d:"°",c:"⌀",p:"±"},ns=(c,t)=>{if(!c)return[];c=c.replace(/%%(.)/g,(o,l)=>rd[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(ns(c.slice(h+1,o)));break}}else n==="\\"&&o++;break}}return s&&r.push(s),r},ad={d:"°",c:"⌀",p:"±"},
|
|
534
|
+
`,Ue=p.ShaderChunk;Ue.outline_bc_vertex=uh;Ue.outline_bc_fragment=fh;Ue.outline_bc_pars_fragment=ph;Ue.outline_bc_pars_vertex=mh;Ue.standard_ex_vertex=wh;Ue.standard_ex_fragment=vh;Ue.common_ex=ch;Ue.id_pars_vertex=hh;Ue.id_vertex=dh;Ue.state_pars_fragment=gh;Ue.state_fragment=yh;Ue.state_transparent_fragment=xh;Ue.state_highlight_fragment=bh;Ue.pick_ex_vertex=Mh;Ue.pick_ex_fragment=Th;const Ch=p.ShaderChunk;class Sh{constructor(t){y(this,"promise");y(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 Eh=zr.default??zr,A=Eh;A.setLevel("warn");const mo=c=>{try{A.setLevel(c)}catch(t){A.setLevel("error"),A.error(t)}},Ai=class Ai{static isTouchScreenDevice(){return"ontouchstart"in window}static printDeviceInfo(){const t=navigator.userAgent,e=/(?:Android)/.test(t),i=/(?:Firefox)/.test(t),s=/(?:Chrome|CriOS)/.test(t),n=/(?:iPad|PlayBook)/.test(t)||e&&!/(?:Mobile)/.test(t)||i&&/(?:Tablet)/.test(t),r=/(?:iPhone)/.test(t)&&!n,a=!r&&!e,o=Ai.isTouchScreenDevice();e&&A.debug("[DI] is android"),i&&A.debug("[DI] is fireFox"),s&&A.debug("[DI] is chrome"),n&&A.debug("[DI] is tablet"),r&&A.debug("[DI] is iPhone"),a&&A.debug("[DI] is PC"),o&&A.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:()=>{}}}};y(Ai,"isMobile",/mobile/i.test(navigator.userAgent)),y(Ai,"isBrowser",typeof document<"u"),y(Ai,"isNode",typeof process<"u"&&Object.prototype.toString.call(process)==="[object process]");let De=Ai;const Ii=class Ii{static isFullScreen(){return!!(document.fullscreenElement||document.mozFullScreenElement)}static fullScreen(t=document.documentElement){(t.requestFullscreen||t.mozRequestFullScreen||t.webkitRequestFullscreen||t.msRequestFullscreen).call(t)}static exitFullscreen(){(document.exitFullscreen||document.mozCancelFullscreen||document.webkitExitFullscreen||document.msExitFullscreen).call(document)}static joinStrings(...t){return t.join("")}static numberToString(t){let e=2;return Math.abs(t)<1e-6?e=2:Math.abs(t)<1e-5?e=7:Math.abs(t)<1e-4?e=6:Math.abs(t)<.001?e=5:Math.abs(t)<.01?e=4:Math.abs(t)<.1&&(e=3),t.toFixed(e)}static byteCountToString(t){let e=t;return t>1e9?(e=t/1e9,this.numberToString(e)+" G"):t>1e6?(e=t/1e6,this.numberToString(e)+" M"):t>1e3?(e=t/1e3,this.numberToString(e)+" K"):this.numberToString(e)}static hexToBase64(t){return btoa((t.match(/\w{2}/g)||[]).map(function(e){return String.fromCharCode(parseInt(e,16))}).join(""))}static vectorToString(t){return Array.isArray(t)?"("+this.numberToString(t[0])+", "+this.numberToString(t[1])+", "+this.numberToString(t[2])+")":t instanceof p.Vector3?"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+", "+this.numberToString(t.z)+")":"("+this.numberToString(t.x)+", "+this.numberToString(t.y)+")"}static arrayToVector2(t){if(t){if(t instanceof p.Vector2)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector2(t[0],t[1])}else return t}static arrayToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t.length>2?t[2]:0)}else return t}static arrayToEuler(t){if(t){if(t instanceof p.Euler)return t;if(Array.isArray(t)&&t.length>=3)return new p.Euler(t[0],t[1],t[2])}else return t}static arrayOrObjectToVector3(t){if(t){if(t instanceof p.Vector3)return t;if(t instanceof p.Vector2)return new p.Vector3(t.x,t.y,0);if(Array.isArray(t)&&t.length>=2)return new p.Vector3(t[0],t[1],t[2]||0)}else return t;const e=t;if(e.x!=null&&e.y!=null)return new p.Vector3(e.x,e.y,e.z||0)}static isVectorValid(t){let e=t&&!isNaN(t.x)&&!isNaN(t.y)&&isFinite(t.x)&&isFinite(t.y);return e&&t instanceof p.Vector3&&(e=!isNaN(t.z)&&isFinite(t.z)),e}static isBoxValid(t){return t&&!t.isEmpty()&&this.isVectorValid(t.min)&&this.isVectorValid(t.max)}static isMatrixValid(t){const e=t&&t.elements;if(!e||e.length<16)return!1;for(let i=0;i<16;++i){const s=e[i];if(Number.isNaN(s))return!1}return!0}static guid(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}static expandBoxByScale(t,e){const i=new p.Vector3;t.getCenter(i);const s=(t.max.x-t.min.x)*e,n=(t.max.y-t.min.y)*e,r=(t.max.z-t.min.z)*e,a=new p.Vector3(i.x-s/2,i.y-n/2,i.z-r/2),o=new p.Vector3(i.x+s/2,i.y+n/2,i.z+r/2);t.set(a,o)}static expandBoxByMinSize(t,e){const i=new p.Vector3;t.getCenter(i);const s=t.max.x-t.min.x,n=t.max.y-t.min.y,r=t.max.z-t.min.z;s<e&&(t.min.setX(i.x-e/2),t.max.setX(i.x+e/2)),n<e&&(t.min.setY(i.y-e/2),t.max.setY(i.y+e/2)),r<e&&(t.min.setZ(i.z-e/2),t.max.setZ(i.z+e/2))}static generateRandomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static roundNumber(t,e){return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}static convertDecimalToHex(t){return t==null?"#ffffff":"#"+t.toString(16).padStart(6,"0")}static canvasToImage(t){const e=t.toDataURL(),i=new Image;return i.src=e,new Promise(s=>{i.onload=function(){s(i)}})}static renderingContextToImage(t,e,i="image/png",s=.8){if(e){const n=Math.max(e.min.x,0),r=Math.max(e.min.y,0),a=Math.max(e.max.x-n,0),o=Math.max(e.max.y-r,0),l=t.getImageData(n,r,a,o),h=document.createElement("canvas");return h.width=a,h.height=o,h.getContext("2d").putImageData(l,0,0),h.toDataURL(i,s)}return t.canvas.toDataURL(i,s)}static printMemory(t){if(!De.isBrowser)return;const e=performance.memory;if(!e){A.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);A.info("[Util] "+t+". jsHeapSizeLimit: "+i+"M , totalJSHeapSize: "+s+"M , usedJSHeapSize: "+n+"M ")}static printGpuInfo(t){if(!De.isBrowser)return;const e=t.getExtension("webgl_debug_renderer_info"),i=t.getParameter(e.UNMASKED_RENDERER_WEBGL);A.info("[Util] gpu:",i)}static getExtension(t){return t.substring(t.lastIndexOf(".")+1)}static isBinaryFile(t){return Ii.getExtension(t)==="bin"}static isGzip(t){return t.length<=3?!1:t[0]==31&&t[1]==139&&t[2]==8}static async sleep(t){let e;await new Promise(i=>{e=setTimeout(()=>{i()},t)}),clearTimeout(e)}static async twinkle(t,e=500){const i=this.twinklingObjectIds;i[t.id]||(i[t.id]=!0,t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,await this.sleep(e),t.visible=!t.visible,delete i[t.id])}static getUpdateProgressFunc(t){return e=>{t&&t(new ProgressEvent("",{loaded:e,total:100}))}}static getUpdateProgressFuncAsync(t){let e=Date.now();return async i=>{if(t){t(new ProgressEvent("",{loaded:i,total:100}));const s=500,n=Date.now();n-e>s&&(await Ii.sleep(0),e=n)}}}static getUpdateProgressFuncForLoop(t,e){const i=Math.round(Math.pow(t,.5));let s=Date.now();return async n=>{if(e&&(n%i===0||n===t-1)){e(new ProgressEvent("",{loaded:n+1,total:t}));const r=500,a=Date.now();(a-s>r||n===t-1)&&(await Ii.sleep(0),s=a)}}}static getUpdateSubProgressFunc(t,e,i){let s=!1;return n=>{let r=n.loaded*100/n.total;r=r*(e-t)/100+t,r>e&&(s||(A.warn("[Progress] Invalid ProgressEvent:",n),s=!0),r=e),i&&i(new ProgressEvent(n.type,{loaded:r,total:100}))}}};y(Ii,"twinklingObjectIds",{});let N=Ii;const Oh=(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 Di{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 _e{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=_e.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=_e.world2Screen(s,e,i);return r.x/=i.clientWidth,r.y/=i.clientHeight,r}}class Ph{static createCSS2DObject(t){const e=new lo.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 go={"Precision from file":99},_h=(c,t)=>c.toFixed(t===go["Precision from file"]?2:t),yo="en",st=!1,xo=10,qe=11,Nt=12,Er=583902,Ah=[.031,.906,.867,.5],sn=[.3,.3,.3,.8],Or=.5,nn=.1,rn=5e3,bo=45,Ih="x-viewer-iconfont",Bh="x-viewer-iconfont2",Pr=10,aa=new p.Vector3,oa=new p.Vector3,la=new p.Vector3,is=new p.Vector3,Pt=new p.Vector3,ca=new p.Triangle;function kh(c,t,e,i,s){const n=[],r={};let a,o,l,h;const u=Math.pow(10,4);let f,m,x=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]=x/3,e[x++]=a,e[x++]=o,e[x++]=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 Dh(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;aa.set(e[r],e[r+1],e[r+2]),oa.set(e[a],e[a+1],e[a+2]),la.set(e[o],e[o+1],e[o+2]),p.Triangle.getNormal(aa,oa,la,is),i.push({normal:is.clone()})}}const Ln=[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 Lh(c,t){return Pt.addVectors(c,t),Pt.x===0||Pt.y===0||Pt.z===0}class wo{static buildEdge(t,e,i=Pr){const s=[],n=[],r=[];kh(t,e,s,n,r);const a=[];Dh(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 x=0;x<3;x++){const g=r[u+x],M=r[u+(x+1)%3],w=Math.min(g,M),b=Math.max(g,M),C=w+","+b;h[C]===void 0?h[C]={index1:w,index2:b,face1:m,face2:void 0}:h[C].face2=m}}for(const u in h){const f=h[u];if(f.face2!==void 0){const g=a[f.face1].normal,M=a[f.face2].normal;if(g.dot(M)>l)continue}const m=n[f.index1],x=n[f.index2];(!d&&m>65535||x>65535)&&(d=!0),o.push(m),o.push(x)}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=Ln.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={},x={};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:P,b:_,c:I}=ca;if(P.fromBufferAttribute(e,o[0]),_.fromBufferAttribute(e,o[1]),I.fromBufferAttribute(e,o[2]),ca.getNormal(is),m[o[0]]?l[0]=m[o[0]]:(l[0]=Math.round(P.x*s)+","+Math.round(P.y*s)+","+Math.round(P.z*s),m[o[0]]=l[0]),m[o[1]]?l[1]=m[o[1]]:(l[1]=Math.round(_.x*s)+","+Math.round(_.y*s)+","+Math.round(_.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]){A.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 D=(k+1)%3,z=l[k],se=l[D],re=o[k],je=o[D];!u[re]&&(u[re]=new Set),u[re].add(je),!u[je]&&(u[je]=new Set),u[je].add(re);const Le=z+"_"+se,de=se+"_"+z;if(de in x&&x[de]){if(x[de].outer){A.warn("[Edge] edge: "+de+" is already outer!");continue}is.dot(x[de].normal)<=n?x[de].outer=!0:x[de].find=!0}else Le in x?A.warn("[Edge] "+Le+" has existed in geometry!"):x[Le]={startIndex:re,endIndex:je,normal:is.clone(),outer:!1,find:!1}}}for(const T in x)x[T]&&!x[T].find&&!x[T].outer&&(x[T].outer=!0);const g=[],M=[];for(const T in f)M.push(f[T]);let w=new Set;for(const T of M[0])w.add(T.a),w.add(T.b),w.add(T.c);let b=0;for(M.splice(b,1);;){let T=!1;for(let P=0;P<M.length&&!T;P++)for(const _ of M[P])if(w.has(_.a)||w.has(_.b)||w.has(_.c)){b=P,T=!0;break}if(T){for(const P of M[b])w.add(P.a),w.add(P.b),w.add(P.c);if(M.splice(b,1),b=0,M.length===0){g.push(w);break}}else if(!T)if(g.push(w),M.length>0){w=new Set;for(const P of M[b])w.add(P.a),w.add(P.b),w.add(P.c);M.splice(b,1),b=0}else break}const C=new Set;for(let T=0;T<g.length;T++)g[T].forEach(_=>{C.has(_)?A.warn("[Edge] "+_+" is already in positionIndexSet!"):C.add(_)});const S=(T,P)=>{let _=!1;const I=m[T];if(!I)return console.warn(T+" is not in positionIndexHash!"),_;const B=m[P];if(!B)return console.warn(P+" is not in positionIndexHash!"),_;const k=I+"_"+B;if(x[k])_=x[k].outer;else{const D=B+"_"+I;x[D]&&(_=x[D].outer)}return _},O=(T,P,_)=>{const I=[];return I.push(S(T,P)),I.push(S(P,_)),I.push(S(_,T)),I.filter(B=>B===!0).length>=2},E=(T,P)=>{if(!u[T])return A.warn("[Edge] "+T+" position isn't used!"),!0;const _=u[T];for(const B of _){const k=S(T,B),D=d[B];if(!D.inited)continue;const z=Lh(P,D.point);if(k&&!z||!k&&z)return!1}const I=f[T];for(const B of I){const k=P;let D=d[B.b],z=d[B.c];if(B.b===T?D=d[B.a]:B.c===T&&(z=d[B.a]),O(B.a,B.b,B.c)&&(D.inited&&k.equals(D.point)||z.inited&&k.equals(z.point)))return!1;if(!(!D.inited||!z.inited)&&(Pt.addVectors(k,D.point),Pt.add(z.point),Pt.x+Pt.y+Pt.z<2))return!1}return!0};let v=!1;for(let T=0;T<g.length;T++){const P=Array.from(g[T]);v=!1;let _=0,I=0;for(;I>=0;){_=P[I];let B=d[_].inited?d[_].barycentricIndex+1:0;for(;B<h&&!E(_,Ln[B]);B++);if(B<h)if(d[_].inited=!0,d[_].barycentricIndex=B,d[_].point.copy(Ln[B]),I==P.length-1){v=!0,A.debug("[Edge]",d);break}else I++;else d[_].inited=!1,I--}if(!v){A.warn("[Edge] no result: "+P+"!");break}}if(v){const T=[];for(let _=0;_<d.length;_++){!d[_].inited&&A.warn("[Edge] "+_+" is not initialized !");let I=0;I|=d[_].point.x,I|=d[_].point.y<<1,I|=d[_].point.z<<2,T.push(I)}const P=new p.Uint8BufferAttribute(T,1,!1);t.setAttribute("barycentric",P)}else A.warn("[Edge] No suitable barycentric found!");return v}}class Gt{constructor(){y(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 K=class K{static exportToGltf(t,e){K.exportToGltfOrGlb(t,e,{binary:!1})}static exportToGlb(t,e){K.exportToGltfOrGlb(t,e,{binary:!0})}static exportToGltfOrGlb(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");const s=new bl.GLTFExporter;i=Object.assign({},{binary:!0,onlyVisible:!1,includeCustomExtensions:!1},i),s.parse(t,r=>{if(i.binary){e=K.addExtention(e,K.EXTENSION_GLB);const a=r;K.saveArrayBuffer(a,e)}else e=K.addExtention(e,K.EXTENSION_GLTF),K.saveJson(r,e)},r=>console.log(r),i)}static exportToObj(t,e){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_OBJ);const i=new wl.OBJExporter,s=i.parse(t);K.saveString(s,e)}static exportToDraco(t,e,i={}){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_DRACO);const s=new xl.DRACOExporter;i=Object.assign({},{encodeSpeed:5},i);const r=s.parse(t,i);K.saveArrayBuffer(r,e)}static exportToStl(t,e,i=!1){if(!t||!e)throw new Error("Invalid input or filename!");e=K.addExtention(e,K.EXTENSION_STL);const s=new vl.STLExporter;if(i){const n={binary:!0},r=s.parse(t,n);K.saveDataView(r,e)}else{const n=s.parse(t);K.saveString(n,e)}}static exportToThreeJsJson(t,e){const i=t.toJSON();e.toLowerCase().endsWith(K.EXTENSION_JSON)||(e+=K.EXTENSION_JSON),K.saveJson(i,e)}static save(t,e){let i=K.downloadLink;i||(i=document.createElement("a"),i.style.display="none",document.body.appendChild(i),K.downloadLink=i),i.href=URL.createObjectURL(t),i.download=e,i.click()}static saveArrayBuffer(t,e){K.save(new Blob([t],{type:"application/octet-stream"}),e)}static saveJson(t,e){K.saveJsonString(JSON.stringify(t),e)}static saveJsonString(t,e){K.save(new Blob([t],{type:"application/json"}),e)}static saveString(t,e){K.save(new Blob([t],{type:"text/plain"}),e)}static saveDataView(t,e){K.save(new Blob([t],{type:"application/octet-stream"}),e)}static addExtention(t,e){return t.toLowerCase().endsWith(e.toLowerCase())||(t+=e),t}};y(K,"EXTENSION_GLTF",".gltf"),y(K,"EXTENSION_GLB",".glb"),y(K,"EXTENSION_OBJ",".obj"),y(K,"EXTENSION_DRACO",".drc"),y(K,"EXTENSION_JSON",".json"),y(K,"EXTENSION_STL",".stl"),y(K,"downloadLink");let fr=K;class Rh{constructor(){y(this,"prevTime");y(this,"beginTime");y(this,"frames");y(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 Rn=1e-15,ha=new p.Matrix4().set(0,0,-1,0,1,0,0,0,0,1,0,0,0,0,0,1),da=new p.Matrix4().set(0,1,0,0,1,0,0,0,0,0,1,0,0,0,0,1);class V{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 V.areNumbersEqual(t.x,e.x,i)&&V.areNumbersEqual(t.y,e.y,i)}static areVector3sEqual(t,e,i=1e-7){return V.areNumbersEqual(t.x,e.x,i)&&V.areNumbersEqual(t.y,e.y,i)&&V.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 V.areNumbersClose(t,e,Rn)?0:(t%=i,V.areNumbersClose(t,e%i,Rn)?i:(V.areNumbersClose(e,i,Rn)&&(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=V.getIntegerPartLength(t);return Math.max(Math.pow(10,i)*e,e)}static getVector2RelativeEps(t,e=1e-7){return Math.min(V.getRelativeEps(t.x,e),V.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(ha.clone().invert()),e}static convertPointFromGltfToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(ha),e}static convertPointFromUEToRevit(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(da.clone().invert()),e}static convertPointFromRevitToUE(t){const e=new p.Vector3(t.x,t.y,t.z);return e.applyMatrix4(da),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=V.convertPointFromGltfToUE(t.min),i=V.convertPointFromGltfToUE(t.max);return V.getBox(e,i)}static convertBoxFromUEToGltf(t){const e=V.convertPointFromUEToGltf(t.min),i=V.convertPointFromUEToGltf(t.max);return V.getBox(e,i)}static convertBoxFromRevitToUE(t){const e=V.convertPointFromRevitToUE(t.min),i=V.convertPointFromRevitToUE(t.max);return V.getBox(e,i)}static convertBoxFromUEToRevit(t){const e=V.convertPointFromUEToRevit(t.min),i=V.convertPointFromUEToRevit(t.max);return V.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 V.clamp(t*(1/e),-1,1)}static OctDecode(t,e,i){if(e.x=V.fromSnorm(t.x,i),e.y=V.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))*V.signNotZero(s),e.y=(1-Math.abs(s))*V.signNotZero(e.y)}}}const Fn=1e7,ua=new p.Box2,fa=new p.Box2,pa=new p.Vector3,ma=new p.Vector3,ga=new p.Vector3,kt=new p.Triangle,Fh=/not find (pre|next) vertex|has repeat vertex|translateLine line eror|not find Intersection/;function zh(c){const t=console.error;console.error=(...e)=>{typeof e[0]=="string"&&Fh.test(e[0])||t.apply(console,e)};try{return c()}finally{console.error=t}}class G{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=pa.subVectors(s,i).normalize(),o=ma.subVectors(r,n).normalize();if(a.dot(o)===1)return null;const l=ga.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(V.areNumbersEqual(0,f))return;const m=d.clone().dot(h)/f,x=i.clone().add(a.multiplyScalar(m));return x.equals(i)||x.equals(s)?null:x}static isPointOnLineSegment(t,e,i=.001){const{start:s,end:n}=e,r=pa.subVectors(s,n).length(),a=ma.subVectors(t,s).length(),o=ga.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(G.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)>Fn||Math.abs(t.y)>Fn||t instanceof p.Vector3&&Math.abs(t.z)>Fn}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)kt.a.fromBufferAttribute(i,s.getX(n)),kt.b.fromBufferAttribute(i,s.getX(n+1)),kt.c.fromBufferAttribute(i,s.getX(n+2)),e+=kt.getArea();else for(let n=0;n<i.count;n+=3)kt.a.fromBufferAttribute(i,n),kt.b.fromBufferAttribute(i,n+1),kt.c.fromBufferAttribute(i,n+2),e+=kt.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,G.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||(ua.setFromPoints(t),fa.setFromPoints(e),!ua.intersectsBox(fa)))return!1;for(let i=0;i<t.length;){if(this.isPointInPolygon(t[i],e,!0))return!0;i<t.length-1&&V.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 x=(u*h-l*f)/m,g=(o*f-d*h)/m;return new p.Vector2(x,g)}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=[],x=e/2;for(let b=0,C=t.length-1;b<C;b++)s=!b,n=b===t.length-2,i=this.getOffsetPoint(t[b],t[b+1],x),h=new p.Vector2(t[b].x+i.x,t[b].y+i.y),d=new p.Vector2(t[b+1].x+i.x,t[b+1].y+i.y),u=new p.Vector2(t[b].x-i.x,t[b].y-i.y),f=new p.Vector2(t[b+1].x-i.x,t[b+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 g=p.ShapeUtils.triangulateShape(m,[]),M=[];for(let b=0;b<g.length;b++)M.push(...g[b]);const w=new p.BufferGeometry().setFromPoints(m);return w.setIndex(M),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}=zh(()=>Ml.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++)V.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 vo={ProgressBar:{Loading:"Loading",Comparing:"Comparing"},Tooltip:{boxSelect:"Box select an area to confirm the screenshot range",pickMarkup:"Click on a markup to confirm the screenshot range"},WebGL:{NotAvailable:"Unable to create a WebGL context in this browser/GPU environment; the drawing cannot be rendered. A common cause is hardware acceleration (called 'graphics acceleration' in some browsers) being enabled while the GPU cannot keep up. Please turn OFF this option in your browser settings and restart the browser. If it still fails, update the graphics driver or try a different browser.",SettingsLink:"Open Chrome System Settings (chrome://settings/system)",CopyFallback:"请手动打开 chrome://settings/system 并关闭硬件加速(部分浏览器称为「图形加速」),然后重启浏览器。"}},Mo={ProgressBar:{Loading:"正在加载",Comparing:"正在对比"},Tooltip:{boxSelect:"框选一个区域以确定截图范围",pickMarkup:"点击一个批注以确定截图范围"},WebGL:{NotAvailable:"当前浏览器或显卡环境无法创建 WebGL 上下文,图纸无法渲染。常见原因是开启了浏览器的硬件加速(部分浏览器称为「图形加速」)但显卡性能不足:请在浏览器设置中关闭该选项,并重启浏览器。",SettingsLink:"打开 Chrome 系统设置(chrome://settings/system)",CopyFallback:"请手动打开 chrome://settings/system 并关闭硬件加速(部分浏览器称为「图形加速」),然后重启浏览器。"}},ze=Tl.createInstance(),Vh="cn";ze.init({lng:Vh,debug:!1,resources:{en:{translation:vo},cn:{translation:Mo}}});class ve{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(Er),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 Uh=new p.Vector3(0,1,0),Je=class Je{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&&A.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 Je.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);Je.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);Je.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);Je.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=N.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,x=(h+1)*90/r;d=N.getUpdateSubProgressFunc(m,x,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,Pr),n=new p.LineSegments(s,e);return n.layers.enableAll(),Je.disableLayerChannels(n,[Nt,qe]),n.userData.isOutline=!0,n.matrixAutoUpdate=st,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=ve.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=Uh;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++)Je.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++)Je.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++)Je.setLayerChannels(s[n],e,!0)}}static isObjectHittable(t){return t.layers.isEnabled(xo)}static isObjectSnapable(t){return t.layers.isEnabled(qe)}static isObjectSelectable(t){return t.layers.isEnabled(Nt)}static disposeObject(t){t.traverse(e=>{const i=e;if(i.geometry){i.geometry.dispose(),(Array.isArray(i.material)?i.material:[i.material]).forEach(r=>r?.dispose());const n=e.userData?.originalMaterial;n&&(Array.isArray(n)?n:[n]).forEach(r=>r?.dispose())}})}};y(Je,"OUTLINE_MATERIAL",new p.LineBasicMaterial({name:"outline",color:0,transparent:!0,opacity:.2})),y(Je,"BOX_FACE_MATERIAL",new p.MeshPhongMaterial({color:11648971,transparent:!0,opacity:.3,side:p.FrontSide}));let Q=Je;const zs=new p.Matrix4,jh=new p.Matrix4,os=class os{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 x=f[m].indexes[0];if(u=this.tryHandleMergeableObjects(t,h,x,s,n),u)break}for(let m=n.length-1;!u&&m>=0;--m){const x=n[m];if(u=this.tryHandleMergeableObjects(t,h,x,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,x=0,g=0;const M=[];if(d.forEach(b=>{const C=t.children[b],S=C.geometry.clone();if(S.applyMatrix4(C.matrix),G.tryConvertInterleavedBufferAttributes(S),S.userData.isLineSegments=C.isLineSegments===!0,f.push(S),e){const O=C.name,E=S.attributes?.position?.count,v=S.index?.count||0,T={batchId:m,name:O,positionStart:x,positionCount:E,indexStart:g,indexCount:v};Object.keys(C.userData).length!==0&&(T.userData=C.userData),M.push(T),x+=E,g+=v,m++}}),f.length===0)return;let w;if(u.isMesh){const b=Ie.mergeGeometries(f);if(!b)return;b.userData={},w=new p.Mesh(b,u.material),r.push(w)}else if(u.isLine){const b=this.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,M);if(!b)return;w=new p.LineSegments(b,u.material),a.push(w)}else if(u.isPoints){const b=Ie.mergeGeometries(f);if(!b)return;b.userData={},w=new p.Points(b,u.material),o.push(w)}w&&(e?w.userData.batches=M:(w.userData=u.userData,w.userData.batches=void 0),w.userData.layerName=u.userData.layerName,w.name="[Merged] "+u.name,w.matrixAutoUpdate=st,w.renderOrder=u.renderOrder,w.layers.mask=u.layers.mask,w.visible=u.visible,l.push(...d)),f.forEach(b=>{b.dispose(),G.releaseGeometryManually(b)}),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)&&ve.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 g=0;g<t.length;++g){const M=t[g];if(M.isInstancedMesh||!M.geometry||!(M.geometry instanceof p.BufferGeometry))continue;let w=!1;const b=Object.values(o);for(let C=b.length-1;C>=0;--C){const S=b[C].indexes[0];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}for(let C=l.length-1;!w&&C>=0;--C){const S=l[C];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}!w&&l.push(g)}if(Object.keys(o).length<=0)return r;A.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(g=>{const M=g.indexes;if(M.length<2)return;const w=t[M[0]];let b=[],C=0,S=0,O=0;const E=[];if(M.forEach(T=>{const P=t[T],_=P.geometry.clone();if(w.material instanceof p.LineBasicMaterial&&_.deleteAttribute("lineDistance"),this.applyMatrix(_,P,e),_.userData.isLineSegments=P.isLineSegments===!0,b.push(_),n){const I=P.name,B=_.attributes?.position?.count,k=_.index?.count||0;let D;w.isLine&&(!_.boundingSphere&&_.computeBoundingSphere(),D=_.boundingSphere.clone());const z={batchId:C,name:I,positionStart:S,positionCount:B,indexStart:O,indexCount:k,boundingSphere:D};!P.parent.geometry&&Object.keys(P.parent.userData).length!==0&&(z.parentUserData=P.parent.userData),Object.keys(P.userData).length!==0&&(z.userData=P.userData),E.push(z),S+=B,O+=k,C++}}),b.length===0)return;let v;if(w.isMesh){const T=Ie.mergeGeometries(b);if(!T)return;T.userData={},v=new p.Mesh(T,w.material),h.push(v)}else if(w.isLine){const T=this.mergeLineGeometries(b,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=Ie.mergeGeometries(b);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=st,v.renderOrder=w.renderOrder,v.layers.mask=w.layers.mask,v.visible=w.visible,M.forEach(T=>f.push(T))),b.forEach(T=>{T.dispose(),G.releaseGeometryManually(T)}),b=[]}),A.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(g=>{const M=t[g];m.push(M),i&&M.removeFromParent()});const x=r.added;return[...h,...d,...u].forEach(g=>{x.push(g),i&&e&&(e.add(g),g.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&&Q.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(zs.identity();s&&s!==i&&(zs.premultiply(s.matrix),!!s.parent);)s=s.parent;return zs.equals(jh)?t:t.applyMatrix4(zs)}static mergeLineGeometries(t,e,i,s){let n;if(i)n=os.mergeBufferGeometriesWithLinesToLineSegments(t,e,s);else{if(n=Ie.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 x=d.array[m];u?r.push(a+x):m>0&&r.push(a+d.array[m-1],a+x)}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&&(A.debug("[Merge] Geometry '"+l+"' contains index buffer, going to convert it to non-indexed."),h=G.convertGeometryWithIndexedToNonIndexed(h));let u=0;for(const f in h.attributes){if(!s.has(f))return A.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 A.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=os.mergeBufferAttributesWithLinesToLineSegments(n[l],a);if(!h)return A.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 A.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 A.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 A.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,x=new i(f*m);let g=0;for(let M=0;M<d.count;M++){const w=M*m,b=M!==0&&M!==d.count-1&&!h;for(let C=0;C<m;C++)x[g+C]=d.array[w+C],b&&(x[g+m+C]=d.array[w+C]);g+=b?2*m:m}a.set(x,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 A.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 A.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 A.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 x in h){const g=h[x],M=g.itemSize,w=g.array.slice(o*M,l*M);a.setAttribute(x,new p.BufferAttribute(w,M,g.normalized))}if(i.boundsTree&&(r=i.userData.originalIndex,!r))return A.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 x=d;x<u&&x<r.length;++x)f[m++]=r[x]-e.positionStart;return a.setIndex(f),i.boundingBox&&a.computeBoundingBox(),i.boundingSphere&&a.computeBoundingSphere(),a}};y(os,"MergeInfo",{removedObjects:0,mergedMeshes:0,mergedLines:0,mergedPoints:0,mergedUnknownTypeObjects:0,elapsedTime:0});let me=os;const Nh=.01;class Hh{static getFaces(t){const e=t.map(n=>n.toArray()).reduce((n,r)=>(n.push(...r),n),[]),i=[];return Cl.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()>Nh)return!1;return!0}static isSelfIntersecting(t){const e=t.map(s=>s.toArray().slice(0,-1));return Sl(e).length>0}}class _t{static getVisibleObjectBoundingBox(t){const e=new p.Box3;return t.traverse(i=>{i.visible&&(i instanceof p.Mesh||i instanceof p.Line)&&Q.isObjectSelectable(i)&&e.expandByObject(i)}),e}static getObjectsBoundingBox(t,e,i){const s=new p.Box3;return e.forEach(n=>{const r=t.getObjectById(n);if(r){const a=_t.getBoundingBox(r,i);a.isEmpty()||s.union(a)}}),s}static getBoundingBox(t,e=!0){const i=new p.Box3;if(t instanceof p.InstancedMesh)return _t.getInstancedMeshBoundingBox(t);if(t.children.length===0)return i.expandByObject(t),i;const s=t.children.length;let n=1;s>20&&(n=3),s>100&&(n=5),s>200&&(n=10),s>1e3&&(n=100),t.updateMatrixWorld(!1);for(let r=0;r<s;++r){const a=t.children[r];if(!e||r%n===0)if(a.updateMatrix(),a instanceof p.InstancedMesh){const o=_t.getInstancedMeshBoundingBox(a);o.isEmpty()||i.union(o)}else if(N.isMatrixValid(a.matrixWorld)){const o=_t.getBoundingBox(a);o.isEmpty()||i.union(o)}else console.warn("[SceneUtils] Found object("+a.type+") with invalid matrix: "+a.matrixWorld.elements)}return t.geometry&&i.expandByObject(t),i}static getInstancedMeshBoundingBox(t){const e=new p.Box3,i=new p.Matrix4;for(let s=0;s<t.count;++s){t.getMatrixAt(s,i);const n=t.geometry.clone();if(n.boundingBox){const r=n.boundingBox.applyMatrix4(i);!r.isEmpty()&&N.isBoxValid(r)&&e.union(r)}}return e.applyMatrix4(t.matrixWorld),e}static getObjectCenter(t,e){const i=_t.getBoundingBox(t);i.getCenter(e),e.y=i.min.y}}class Vt{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=>{Vt.setMaterialSection(a,e,i,s)}):r&&Vt.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 Gh{static simplifyGeometry(t,e){const i=this.getNumberOfVerticesToRemove(t,e);return i>0?new El.SimplifyModifier().modify(t,i):t}static getNumberOfVerticesToRemove(t,e){let i=0;t instanceof p.BufferGeometry&&t.index&&(i=t.attributes.position.count);const s=Math.floor(i*e);return i<20?0:s}}const qh=10;var Ot=(c=>(c.TripleCross="TripleCross",c.Square="Square",c.Triangle="Triangle",c.CircleWithCross="CircleWithCross",c.Cross="Cross",c.Perpendicular="Perpendicular",c))(Ot||{});class Wh{static createSVGObject(t){return new Ol.SVGObject(t)}}class ds{static async createEnvTexture(t,e){const i=new Pl.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!")}}y(ds,"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 Yh(){if(De.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 pr={file:1,m:1,mm:.001,cm:.01,ft:.3048,in:.0254,pt:Yh()},To={file:"m",m:"m",mm:"mm",cm:"cm",ft:"ft",in:"in",pt:"pt"},Co=c=>c===2?"²":c===3?"³":"",mr=(c,t=1)=>To[c]+Co(t),Xh=(c,t,e,i=1)=>(e==null&&(e=t),e===t?{value:c,unit:mr(e)}:{value:c*Math.pow(pr[t]/pr[e],i),unit:mr(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 Zh{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 ce=(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))(ce||{});const ya={};class ms extends Gt{constructor(e){super();y(this,"viewer");y(this,"drawableLists");y(this,"canvas");y(this,"context");y(this,"frustum");y(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;ya[i.prototype.getClassType()]=e}static createDrawable(e){const i=ya[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(ce.AfterRender,()=>{this.projScreenMatrix.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),this.frustum.setFromProjectionMatrix(this.projScreenMatrix),this.render()})}initCanvas(){const e=this.viewer.getViewerConfig();if(De.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=De.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 N.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 gs extends Gt{constructor(e){super();y(this,"category");y(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=ms.createDrawable(s);this.addDrawable(n)}}getDrawableByPosition(e,i){let s;for(const[,n]of this.drawableMap)if(n.visible&&n.isPointInPath(e,i)){s=n;break}return s}}class Ht extends Gt{constructor(e){super();y(this,"DEFAULT_LINE_WIDTH",1);y(this,"DEFAULT_STROKE_STYLE",[0,0,0,1]);y(this,"DEFAULT_FILL_STYLE",[0,0,0,1]);y(this,"id");y(this,"lineWidth");y(this,"lineColor");y(this,"fillColor");y(this,"x");y(this,"y");y(this,"width");y(this,"height");y(this,"points");y(this,"userData");y(this,"tolerance");y(this,"visible");y(this,"selected");y(this,"renderOrder");y(this,"needsFrustumCulled");y(this,"editPointSize");y(this,"editPointFillColor");y(this,"editPointStrokeColor");y(this,"matrix");y(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||N.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?_e.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 zn=new p.Vector3;class vt extends Ht{constructor(e,i,s=[1,0,0,1],n,r=!1){super(e);y(this,"boxes");y(this,"lineSegments");y(this,"useCloudBorder");this.lineSegments=[],this.useCloudBorder=r,this.boxes=vt.expandBoxesWithGap(i),this.lineColor=s,this.fillColor=n??[s[0],s[1],s[2],.12],this.lineWidth=2,r&&this.calculateCloudLineSegments(this.boxes)}static expandBoxesWithGap(e){return e.map(i=>{const s=i.clone(),n=s.getSize(zn),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=zn.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=zn.subVectors(h,l),u=d.length(),f=d.normalize(),m=Math.ceil(u/r);for(let x=0;x<m;x++)a.push(l.clone().add(f.clone().multiplyScalar(r*x)))}a.push(a[0]),this.lineSegments?.push(a)}}draw(e,i){e.save(),e.lineWidth=this.lineWidth,e.strokeStyle=Di.rgba2Color(this.lineColor),e.fillStyle=Di.rgba2Color(this.fillColor);for(let s=0;s<(this.useCloudBorder?this.lineSegments.length:this.boxes.length);s++){const n=this.boxes[s];if(n&&this.fillRect(e,i,n),this.useCloudBorder){const r=this.lineSegments[s];this.drawBox(e,i,r)}else this.drawRoundedRect(e,i,n)}e.restore()}drawRoundedRect(e,i,s){if(!s)return;const n=this.transToScreenCoord(new p.Vector3(s.min.x,s.min.y),i),r=this.transToScreenCoord(new p.Vector3(s.max.x,s.min.y),i),a=this.transToScreenCoord(new p.Vector3(s.max.x,s.max.y),i),o=this.transToScreenCoord(new p.Vector3(s.min.x,s.max.y),i),l=Math.hypot(r.x-n.x,r.y-n.y),h=Math.hypot(o.x-n.x,o.y-n.y),d=Math.max(0,Math.min(8,l/2,h/2));e.beginPath(),e.moveTo(n.x+d,n.y),e.arcTo(r.x,r.y,a.x,a.y,d),e.arcTo(a.x,a.y,o.x,o.y,d),e.arcTo(o.x,o.y,n.x,n.y,d),e.arcTo(n.x,n.y,r.x,r.y,d),e.closePath(),e.stroke()}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=vt.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"}}ms._registerDrawableClass(vt);const Kh=[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],$h=["PROXY","REGION","INSERT","HATCH"];function oi(c){return Kh[c]}function F(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;let s=!1,n=!1,r=!1,a=!1;for(;!c.isEOF();){const o=e.code;if(o===i&&!s)t.x=e.value,s=!0;else if(o===i+10&&!n)t.y=e.value,n=!0;else if(o===i+20&&!r)t.z=e.value,r=!0;else if(o===42&&!a)t.bulge=e.value,a=!0;else return t;e=c.next()}return t}const Jh="OriginalHandle",Qh="OriginalType",ed="Outlines";function te(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(c.zdysx||(c.zdysx=""),c.zdysx+=t.value,t.value.includes(Jh)){const e=t.value.split(":").map(i=>i.trim());c.extendedData||(c.extendedData={}),c.extendedData.originalHandle=e[1]}if(t.value.includes(ed)&&(c.extendedData||(c.extendedData={}),c.extendedData.outlines=[]),t.value.includes(Qh)){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 Fi(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 _r="BYLAYER",us="BYBLOCK";var be=(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.InsertLine=4.4]="InsertLine",c[c.InsertSymbol=4.6]="InsertSymbol",c[c.Text=5]="Text",c))(be||{});const ss=["INSERT","DIMENSION"];function td(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 id(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 xa(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 sd(c,t){const e=xa(c.text).plainText,i=xa(t.text).plainText;return e===i}var Ge=(c=>(c.Added="Added",c.Removed="Removed",c.Modified="Modified",c.NoChange="NoChange",c))(Ge||{});let Fe=1;const St=class St{constructor(t,e,i={}){y(this,"dxf1");y(this,"dxf2");y(this,"changes");y(this,"comparedBlocks");y(this,"isComparingBlock");y(this,"isComparingDimension");y(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;!St.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;!St.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,A.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),A.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[Fe]={id:Fe,...a,parentHandles:o}:a.type==="Removed"&&(this.changes[Fe]={id:Fe,...a,parentHandles:o}),Fe++}}),!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=N.getUpdateProgressFuncForLoop(t.length,i);for(let n=0;n<t.length;n++){const r=t[n].handle;if(!e.has(r))this.changes[Fe]={id:Fe,type:"Removed",handle:r},Fe++;else{const a=t[n],o=e.get(r),l={};if(this.entitiesEqual(a,o,void 0,void 0,l)){if(ss.includes(a.type)){if(this.bIgnoreChildEntitiesOriginalType(a)){e.delete(r),A.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[Fe]={id:Fe,type:"Modified",handle:r},this.enableDetailComparision&&Object.keys(l).length>0&&(this.changes[Fe].detailChanges=l),Fe++}e.delete(r)}await s(n)}for(const n of e){const r=n[0];this.changes[Fe]={id:Fe,type:"Added",handle:r},Fe++}}bIgnoreChildEntitiesOriginalType(t){return $h.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!==_r&&t.lineType!==us)return t.lineType;if(t.lineType===us)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(!sd(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"?(A.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 A.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?V.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)}};y(St,"ENTITY_COLOR_ADDED",65280),y(St,"ENTITY_COLOR_REMOVED",16711680),y(St,"ENTITY_COLOR_NO_CHANGE",10066329),y(St,"ENTITY_COLOR_MARKUP",16744231),y(St,"ENTITY_TYPES_TO_IGNORE",["ATTRIB","SEQEND"]);let ht=St;var q=(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))(q||{});const Vn=new L.Box3,Un=new L.Matrix4;class U{constructor(t=0){y(this,"name");y(this,"type");y(this,"matrix");y(this,"parent");y(this,"children");y(this,"layers");y(this,"renderOrder");y(this,"userData");y(this,"material");y(this,"geometry");y(this,"matrixWorld");this.name="",this.type=0,this.matrix=new L.Matrix4,this.children=[],this.layers=new L.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 U().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 L.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=st,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(),Un.copy(t.matrix),i&&Un.premultiply(i),Vn.copy(t.geometry.boundingBox),Vn.applyMatrix4(Un),e.union(Vn);else if(t.children.length>0){!t.matrixWorld&&(t.matrixWorld=new L.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 L.Box3().makeEmpty();t.userData.boundingBoxs=[];const o=[];t.children.forEach(l=>{for(new L.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 L.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 Vs=new p.Matrix4,nd=new p.Matrix4;class Ct{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 x=m.length-1;x>=0;--x){const g=m[x].indexes[0];if(f=this.tryHandleMergeableObjects(t,h,g,s,n),f)break}for(let x=n.length-1;!f&&x>=0;--x){const g=n[x];if(f=this.tryHandleMergeableObjects(t,h,g,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,x=0,g=0;const M=[];if(d.forEach(b=>{const C=t.children[b],S=C.geometry?.clone();if(S.applyMatrix4(C.matrix),S.userData.isLineSegments=C.type===q.LineSegment,f.push(S),e){const O=S.attributes?.position?.count,E=S.index?.count||0;M.push({batchId:m,positionStart:x,positionCount:O,indexStart:g,indexCount:E}),x+=O,g+=E,m++}}),f.length===0)return;let w;if(u.type===q.Mesh){const b=Ie.mergeGeometries(f);if(!b)return;b.userData={},w=new U(u.type),w.geometry=b,w.material=u.material,r.push(w)}else if(u.type===q.Line||u.type===q.LineSegment){const b=me.mergeLineGeometries(f,e,u.material instanceof p.LineDashedMaterial||u.material instanceof p.ShaderMaterial,M);if(!b)return;w=new U(q.LineSegment),w.geometry=b,w.material=u.material,a.push(w)}else if(u.type===q.Point){const b=Ie.mergeGeometries(f);if(!b)return;b.userData={},w=new U(u.type),w.geometry=b,w.material=u.material,o.push(w)}w&&(e?w.userData.batches=M:(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(b=>{b.dispose(),G.releaseGeometryManually(b)}),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)&&me.areGeometriesMergeable(l.geometry,h.geometry)&&ve.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===q.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 g=0;g<t.length;++g){if(!t[g].geometry||this.isFilteredByOtherFactors(t[g],e))continue;let w=!1;const b=Object.values(o);for(let C=b.length-1;C>=0;--C){const S=b[C].indexes[0];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}for(let C=l.length-1;!w&&C>=0;--C){const S=l[C];if(w=this.tryHandleMergeableObjects(t,g,S,o,l),w)break}!w&&l.push(g)}if(Object.keys(o).length<=0)return r;A.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(g=>{const M=g.indexes;if(M.length<2)return;const w=t[M[0]];let b=[],C=0,S=0,O=0;const E=[];if(M.forEach(T=>{const P=t[T],_=P.geometry?.clone();if(w.material instanceof p.LineBasicMaterial&&_.deleteAttribute("lineDistance"),this.applyMatrix(_,P,e),_.userData.isLineSegments=P.type===q.LineSegment,b.push(_),n){const I=_.attributes?.position?.count,B=_.index?.count||0;let k;(w.type===q.Line||w.type===q.LineSegment)&&(!_.boundingSphere&&_.computeBoundingSphere(),k=_.boundingSphere?.clone());const D={batchId:C,positionStart:S,positionCount:I,indexStart:O,indexCount:B,boundingSphere:k};Object.keys(P.userData).length!==0&&(D.userData=P.userData),E.push(D),S+=I,O+=B,C++}}),b.length===0)return;let v;if(w.type===q.Mesh){const T=Ie.mergeGeometries(b);if(!T)return;T.userData={},v=new U(w.type),v.geometry=T,v.material=w.material,h.push(v)}else if(w.type===q.Line||w.type===q.LineSegment){const T=me.mergeLineGeometries(b,n,w.material instanceof p.LineDashedMaterial||w.material instanceof p.ShaderMaterial,E);if(!T)return;v=new U(q.LineSegment),v.geometry=T,v.material=w.material,d.push(v)}else if(w.type===q.Point){const T=Ie.mergeGeometries(b);if(!T)return;T.userData={},v=new U(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,M.forEach(T=>f.push(T))),b.forEach(T=>{T.dispose(),G.releaseGeometryManually(T)}),b=[]}),A.debug("[Merge] Ran deepMerge() in "+(Date.now()-a)/1e3+"s");const m=r.removed;f.forEach(g=>{const M=t[g];m.push(M),i&&M.removeFromParent()});const x=r.added;return[...h,...d,...u].forEach(g=>{x.push(g),i&&e&&e.add(g)}),this.MergeInfo.removedObjects+=f.length,this.MergeInfo.mergedMeshes+=h.length,this.MergeInfo.mergedLines+=d.length,this.MergeInfo.mergedPoints+=u.length,s&&e&&Q.removeEmptyObjects(e),r}static applyMatrix(t,e,i){let s=e;for(Vs.identity();s&&s!==i&&(Vs.premultiply(s.matrix),!!s.parent);)s=s.parent;return Vs.equals(nd)?t:t.applyMatrix4(Vs)}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.userData.isConstructionLine||e.userData.isConstructionLine||t.layers.mask!==e.layers.mask||t.renderOrder!==e.renderOrder||t.userData.layerName!==e.userData.layerName?!1:t.type===e.type?!0:(t.type===q.Line||t.type===q.LineSegment)&&(e.type===q.Line||e.type===q.LineSegment)}}y(Ct,"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 x=s?s[m]:1;for(let g=0;g<r;g++)d[m][g]=e[m][g]*x;d[m][r]=x}let u;for(let m=1;m<=t+1;m++)for(let x=h;x>h-t-1+m;x--){u=(c-i[x])/(i[x+t+1-m]-i[x]);for(let g=0;g<r+1;g++)d[x][g]=(1-u)*d[x-1][g]+u*d[x][g]}const f=[];for(let m=0;m<r;m++)f[m]=Eo(d[h][m]/d[h][r],-9);return f},rd={d:"°",c:"⌀",p:"±"},ns=(c,t)=>{if(!c)return[];c=c.replace(/%%(.)/g,(o,l)=>rd[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(ns(c.slice(h+1,o)));break}}else n==="\\"&&o++;break}}return s&&r.push(s),r},ad={d:"°",c:"⌀",p:"±"},Po=(c,t)=>(c=_o(c),t?Ao(c,t):c),_o=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)])))},an=(c,t)=>{c=Po(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=ad[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
|
|
|
@@ -788,14 +788,14 @@ void main() {
|
|
|
788
788
|
gl_FragColor = vec4(u_color * total, 1.0);
|
|
789
789
|
#include <colorspace_fragment>
|
|
790
790
|
}
|
|
791
|
-
`;return new p.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:a,clipping:!0})}var Je=(c=>(c.Unitless="Unitless",c.Inches="Inches",c.Feet="Feet",c.Millimeters="Millimeters",c.Centimeters="Centimeters",c.Meters="Meters",c))(Je||{});const gr=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),od=(c,t)=>gr(c)/gr(t);class ko{constructor(){x(this,"pointer");x(this,"eof");x(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class ys{constructor(t,e){x(this,"endian");x(this,"position");x(this,"data");x(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=xs.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,xs.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=xs.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,xs.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 ba=1e3;class ld extends ko{constructor(e){super();x(this,"reader");x(this,"decoder");x(this,"int8Array");x(this,"caches");this.int8Array=new Int8Array(ba),this.caches=new Map,this.reader=new ys(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 wa(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 wa(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>ba)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 wa(c){return Array.prototype.map.call(c,t=>("00"+t.toString(16)).slice(-2)).join("")}class va extends ko{constructor(e){super();x(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=cd(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 cd(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?hd(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 hd(c){if(c==="0")return!1;if(c==="1")return!0;throw TypeError("String '"+c+"' cannot be cast to Boolean type")}function dd(c){if(c==null)return!0;for(const t in c)if(Object.prototype.hasOwnProperty.call(c,t))return!1;return!0}function ud(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()}dd(a)||e.push(a),i=!1,s=!1}return e}class fd{constructor(){x(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=ud(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}const pd=9,md=6,Ma=7,gd=2,yd=3,xd=4,bd=5,wd=14,vd=33,Md=38;class Td{constructor(t){x(this,"data");x(this,"pos",0);x(this,"bit",0);x(this,"bad",!1);this.data=t}getBit(){if(this.pos>=this.data.length)return this.bad=!0,0;const t=this.data[this.pos]>>7-this.bit&1;return++this.bit===8&&(this.bit=0,this.pos++),t}get2(){const t=this.getBit();return this.bad?0:t<<1|this.getBit()}rawChar8(){if(this.bit===0)return this.pos>=this.data.length?(this.bad=!0,0):this.data[this.pos++];if(this.pos+1>=this.data.length)return this.bad=!0,0;let t=this.data[this.pos]<<this.bit&255;return t|=this.data[this.pos+1]>>8-this.bit,this.pos++,t&255}rawShort16(){return(this.rawChar8()|this.rawChar8()<<8)&65535}rawLong32(){const t=this.rawShort16();return(this.rawShort16()<<16|t)>>>0}rawDouble(){const t=new Uint8Array(8);for(let e=0;e<8;e++)t[e]=this.rawChar8();return this.bad?0:new DataView(t.buffer).getFloat64(0,!0)}bitShort(){const t=this.get2();return t===0?this.rawShort16():t===1?this.rawChar8():t===2?0:256}bitLong(){const t=this.get2();return t===0?this.rawLong32()|0:t===1?this.rawChar8():0}bitDouble(){const t=this.get2();return t===1?1:t===2?0:t===0?this.rawDouble():(this.bad=!0,0)}defaultDouble(t){const e=this.get2();if(this.bad)return 0;if(e===0)return t;if(e===1){const i=new Uint8Array(4);for(let n=0;n<4;n++)i[n]=this.rawChar8();if(this.bad)return 0;const s=new Uint8Array(8);return new DataView(s.buffer).setFloat64(0,t,!0),s.set(i,0),new DataView(s.buffer).getFloat64(0,!0)}if(e===2){const i=new Uint8Array(6);for(let n=0;n<6;n++)i[n]=this.rawChar8();if(this.bad)return 0;const s=new Uint8Array(8);new DataView(s.buffer).setFloat64(0,t,!0);for(let n=2;n<6;n++)s[n-2]=i[n];return s[4]=i[0],s[5]=i[1],new DataView(s.buffer).getFloat64(0,!0)}return this.rawDouble()}}function Cd(c){if(c.length<5)return null;const t=new Td(c.subarray(4)),e=t.bitShort();if(t.bad)return null;e&4&&t.bitDouble(),e&8&&t.bitDouble(),e&2&&t.bitDouble(),e&1&&(t.bitDouble(),t.bitDouble(),t.bitDouble());const i=(e&512)!==0,s=t.bitLong();if(s<=0||s>1e5)return null;let n=0;if(e&16&&(n=t.bitLong()),e&1024&&t.bitLong(),e&32&&t.bitLong(),t.bad)return null;let r=t.rawDouble(),a=t.rawDouble();if(t.bad)return null;const o=[{x:r,y:a}];for(let h=1;h<s&&!t.bad;h++)r=t.defaultDouble(r),a=t.defaultDouble(a),t.bad||o.push({x:r,y:a});if(o.length!==s)return null;let l=0;for(let h=0;h<n&&!t.bad;h++)l=t.bitDouble(),Math.abs(l)>1e-15&&h<o.length&&(o[h].bulge=l);return{points:o,closed:i}}function Sd(c){if(c.length<72)return null;const t=new DataView(c.buffer,c.byteOffset,c.byteLength),e=t.getFloat64(0,!0),i=t.getFloat64(8,!0),s=t.getFloat64(48,!0),n=t.getFloat64(56,!0);let r=72;for(;r+1<c.length&&!(c[r]===0&&c[r+1]===0);)r+=2;if(r+1>=c.length)return null;let a="";try{a=new TextDecoder("utf-16le").decode(c.subarray(72,r))}catch{return null}let o=r+2;if(o%4&&(o+=4-o%4),o+8+32>c.length)return null;const l=t.getFloat64(o+8,!0),h=t.getFloat64(o+16,!0),d=t.getUint32(o+40,!0),u=t.getUint32(o+44,!0);return!Number.isFinite(l)||l<=0||!a?null:{kind:"text",startPoint:{x:e,y:i},height:l,rotation:Math.atan2(n,s)*180/Math.PI,xScale:Number.isFinite(h)&&h>0?h:1,text:a,mirrored:2*(d?1:0)+4*(u?1:0)}}function Ed(c){const t=new Uint8Array(c.length>>1);for(let e=0;e<t.length;e++)t[e]=parseInt(c.substr(e*2,2),16);return t}function Ta(c,t,e){const i=2*(c.x*(t.y-e.y)+t.x*(e.y-c.y)+e.x*(c.y-t.y));if(!Number.isFinite(i)||Math.abs(i)<1e-12)return null;const s=c.x*c.x+c.y*c.y,n=t.x*t.x+t.y*t.y,r=e.x*e.x+e.y*e.y,a=(s*(t.y-e.y)+n*(e.y-c.y)+r*(c.y-t.y))/i,o=(s*(e.x-t.x)+n*(c.x-e.x)+r*(t.x-c.x))/i,l=Math.hypot(c.x-a,c.y-o);return!Number.isFinite(l)||l<=0?null:{center:{x:a,y:o},radius:l}}function Us(c){let t=c%(Math.PI*2);return t<0&&(t+=Math.PI*2),t}function Od(c){const t=new DataView(c.buffer,c.byteOffset,c.byteLength),e={},i=[];if(c.byteLength<8)return{prims:i,ops:e};const s=t.getInt32(0,!0),n=Math.min(s,c.byteLength);let r=256,a=8;const o=l=>({x:t.getFloat64(l,!0),y:t.getFloat64(l+8,!0)});for(;a+8<=n;){const l=t.getInt32(a,!0);if(l<8||a+l>n)break;const h=t.getInt32(a+4,!0);e[h]=(e[h]||0)+1;const d=a+8;try{switch(h){case md:case Ma:{const u=t.getInt32(d,!0);if(u>0&&d+4+u*24<=a+l){const f=[];for(let m=0;m<u;m++)f.push(o(d+4+m*24));f.every(m=>Number.isFinite(m.x)&&Number.isFinite(m.y))&&i.push({kind:"polyline",points:f,closed:h===Ma,colorIndex:r})}break}case gd:{const u=o(d),f=t.getFloat64(d+24,!0);Number.isFinite(f)&&f>0&&Number.isFinite(u.x)&&Number.isFinite(u.y)&&i.push({kind:"circle",center:u,radius:f,colorIndex:r});break}case yd:{const u=Ta(o(d),o(d+24),o(d+48));u&&i.push({kind:"circle",center:u.center,radius:u.radius,colorIndex:r});break}case xd:{const u=o(d),f=t.getFloat64(d+24,!0),m=o(d+56),y=t.getFloat64(d+80,!0);if(Number.isFinite(f)&&f>0&&Number.isFinite(y)&&Number.isFinite(u.x)&&Number.isFinite(u.y)){const g=Math.atan2(m.y,m.x);i.push({kind:"arc",center:u,radius:f,startAngle:g,endAngle:g+y,colorIndex:r})}break}case bd:{const u=o(d),f=o(d+24),m=o(d+48),y=Ta(u,f,m);if(y){const g=Math.atan2(u.y-y.center.y,u.x-y.center.x),M=Math.atan2(f.y-y.center.y,f.x-y.center.x);let w=Math.atan2(m.y-y.center.y,m.x-y.center.x),b=g+Us(w-g);Us(M-g)>Us(w-g)&&(b=g+Us(w-g)+Math.PI*2),i.push({kind:"arc",center:y.center,radius:y.radius,startAngle:g,endAngle:b,colorIndex:r})}break}case pd:{const u=t.getInt32(d,!0),f=d+4;if(u<=0||u>1e5||f+u*24>a+l)break;const m=[];let y=!1;for(let C=0;C<u;C++){const S=f+C*24,O=t.getFloat64(S,!0),E=t.getFloat64(S+8,!0);if(!Number.isFinite(O)||!Number.isFinite(E)){y=!0;break}m.push({x:O,y:E})}if(y)break;const g=f+u*24;if(g+4>a+l)break;const M=t.getInt32(g,!0);if(M<=0||M>1e6)break;let w=g+4,b=0;for(;b<M&&w+4<=a+l;){const C=t.getInt32(w,!0);w+=4;const S=C<0?-C:C;if(S>M-b-1||(b+=1+S,w+S*4>a+l))break;const O=[];for(let E=0;E<S;E++){const v=t.getInt32(w,!0);w+=4,v>=0&&v<u&&O.push(v)}O.length>=2&&i.push({kind:"polyline",points:O.map(E=>m[E]),closed:!0,colorIndex:r})}break}case vd:{const u=Cd(c.subarray(d,a+l));u&&u.points.every(f=>Number.isFinite(f.x)&&Number.isFinite(f.y))&&i.push({kind:"polyline",points:u.points,closed:u.closed,colorIndex:r});break}case Md:{const u=Sd(c.subarray(d,a+l));u&&i.push({...u,colorIndex:r});break}case wd:{const u=t.getUint32(d,!0);r=u===0||u===256?256:u;break}default:break}}catch{}a+=l}return{prims:i,ops:e}}function _d(c,t){return c.colorIndex===256?t.colorIndex??256:c.colorIndex}function Pd(c,t){const e=[];return c.forEach((i,s)=>{const n=_d(i,t),r={layer:t.layer||"0",colorIndex:n,color:oi(Math.abs(n)),lineType:"BYLAYER",handle:`${t.handle||"0"}-p${s}`,inPaperSpace:!1};i.kind==="polyline"?e.push({...r,type:"LWPOLYLINE",vertices:i.points,shape:i.closed,thickness:0}):i.kind==="circle"?e.push({...r,type:"CIRCLE",center:i.center,radius:i.radius,thickness:0}):i.kind==="text"?e.push({...r,type:"TEXT",startPoint:i.startPoint,textHeight:i.height,xScale:i.xScale,rotation:i.rotation,text:i.text,textStyle:"STANDARD",mirrored:i.mirrored,thickness:0}):e.push({...r,type:"ARC",center:i.center,radius:i.radius,startAngle:i.startAngle,endAngle:i.endAngle,thickness:0})}),e}class Ad{constructor(){x(this,"ForEntityName","ACAD_PROXY_ENTITY")}parseEntity(t,e){const i={type:e.value},s=[];for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===310?typeof e.value=="string"&&s.push(e.value):te(i,e),e=t.next();if(s.length)try{const n=Ed(s.join("")),{prims:r}=Od(n);i.decodedEntities=Pd(r,i)}catch{}return i}}class Id{constructor(){x(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=F(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:te(i,e),e=t.next();break}return i}}class Bd{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class kd{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class Dd{constructor(){x(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=F(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:te(i,e),e=t.next();break}return i}}class Ld{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.middleOfText=F(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=F(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=F(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=F(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=F(t),e=t.lastReadGroup;break;case 16:i.arcPoint=F(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:te(i,e),e=t.next();break}return i}}class Rd{constructor(){x(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(Ye(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=Ye(t),e=t.lastReadGroup;break;case 11:o.doglegVector=Ye(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=Ye(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 304:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=Ye(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=Ye(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=Ye(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=Ye(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=Ye(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=Fd(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=Ye(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=Ye(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=Ye(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=Ye(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:te(i,e),e=t.next();break}})(),i}}function Ye(c){const t={};let e=c.lastReadGroup||c.next(),i=!1,s=!1,n=!1,r=!1;for(;!c.isEOF();){const a=e.code,o=a>=10&&a<=16||a>=110&&a<=112,l=a>=20&&a<=26||a>=120&&a<=122,h=a>=30&&a<=36||a>=130&&a<=132;if(a===42&&!r)t.bulge=e.value,r=!0;else if(o&&!i)t.x=e.value,i=!0;else if(l&&!s)t.y=e.value,s=!0;else if(h&&!n)t.z=e.value,n=!0;else return t;e=c.next()}return t}function Fd(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 zd{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=F(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=F(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:te(i,e),e=t.next();break}return i}}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||{}),Si=(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))(Si||{});function Vd(c){const t={type:0,points:[],isClosed:!0};let e=c.next();e=c.next(),t.isClosed=e.value!==0,e=c.next();const i=e.value;e=c.next();for(let n=0;n<i;n++)t.points.push(F(c)),e=c.lastReadGroup;e=c.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const s=e.value;e=c.next();for(let n=0;n<s;n++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=c.next();return{edges:[t],pathTypeFlag:-1}}function Ud(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:F(t),endPoint:F(t)};i=t.lastReadGroup,e.push(r);break}case 2:{i=t.next();const r={type:2,center:F(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:F(t),majorAxisEndPoint:F(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 jd(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=Vd(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=Ud(r,t),n.pathTypeFlag=i,e.push(n),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function Nd(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 Hd(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 Gd{constructor(){x(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=Nd(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=jd(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=Hd(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:te(i,e),e=t.next();break}return i}}var on=(c=>(c[c.ShowImage=1]="ShowImage",c[c.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",c[c.UseClippingBoundary=4]="UseClippingBoundary",c[c.TransparencyIsOn=8]="TransparencyIsOn",c))(on||{});let qd=class{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.uPixel=F(t),e=t.lastReadGroup;break;case 12:i.vPixel=F(t),e=t.lastReadGroup;break;case 13:i.imageSize=F(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(F(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:te(i,e),e=t.next();break}return i}};class Wd{constructor(){x(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=F(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=F(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:te(i,e),e=t.next();break}return i}}function Yd(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 Xd{constructor(){x(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(F(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=Yd(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:te(i,e),e=t.next();break}return i}}class Zd{constructor(){x(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(F(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(F(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}function Kd(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 $d{constructor(){x(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(...Kd(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:te(i,e),e=t.next();break}return i}}class Jd{constructor(){x(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=F(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=F(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:te(i,e),e=t.next();break}return i}}class Qd{constructor(){x(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:te(i,e),e=t.next();break}return i}}class e1{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class t1{constructor(){x(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:te(i,e),e=t.next();break}return i}}function i1(c,t){const e=new t1,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"){s1(c,t);break}}return i}function s1(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 te(e,t),t=c.next();return e}class n1{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i.vertices=i1(t,e),i}}class r1{constructor(){x(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:te(i,e),e=t.next();break}return i}}class a1{constructor(){x(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(F(t)),e=t.lastReadGroup;break;case 11:i.directionVector=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class o1{constructor(){x(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(te(i,e),e=t.next());return i}}class l1{constructor(){x(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]=F(t),e=t.lastReadGroup;break;case 11:i.points[1]=F(t),e=t.lastReadGroup;break;case 12:i.points[2]=F(t),e=t.lastReadGroup;break;case 13:i.points[3]=F(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class c1{constructor(){x(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(F(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(F(t)),e=t.lastReadGroup;break;case 12:i.startTangent=F(t),e=t.lastReadGroup;break;case 13:i.endTangent=F(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=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}function h1(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 Ca(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){h1(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 d1{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.directionVector=F(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(Ca(e,t)):i.cells=[Ca(e,t)],e=t.lastReadGroup;break;default:te(i,e),e=t.next();break}return i}}class u1{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class f1{constructor(){x(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=F(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=F(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=F(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=F(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=F(t),e=t.lastReadGroup;break;case 16:i.viewDirection=F(t),e=t.lastReadGroup;break;case 17:i.viewTarget=F(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=F(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=F(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=F(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:te(i,e),e=t.next();break}return i}}class p1{constructor(){x(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(F(t)),e=t.lastReadGroup;break;case 11:i.directionVector=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class m1{constructor(){x(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:Fi(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 g1{constructor(){x(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=Sa(t),e=t.next();break;case 11:s.pixelSize=Sa(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:Fi(s,e),e=t.next();break}return s}}function Sa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class y1{constructor(){x(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=Dt(t),e=t.lastReadGroup;break;case 11:s.maxLimit=Dt(t),e=t.lastReadGroup;break;case 12:s.basePoint=Dt(t),e=t.lastReadGroup;break;case 13:s.origin=Dt(t),e=t.lastReadGroup;break;case 14:s.minExtent=Dt(t),e=t.lastReadGroup;break;case 15:s.maxExtent=Dt(t),e=t.lastReadGroup;break;case 16:s.XAxis=Dt(t),e=t.lastReadGroup;break;case 17:s.YAxis=Dt(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:Fi(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function Dt(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 x1{constructor(){x(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:Fi(s,e),e=t.next();break}return s}}class b1{constructor(){x(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=ln(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),n=ln(t),e=t.lastReadGroup,r=ln(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=w1(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=Ea(t,40),s.matrix=Ea(t,40),e=t.lastReadGroup;break;default:Fi(s,e),e=t.next();break}return s}}function w1(c,t){t.next();const e=[];for(;e.length<c;)e.push(ln(t));return e}function Ea(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 ln(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 v1{constructor(){x(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:Fi(s,e),e=t.next();break}return s}}function M1(c){c.registerEntityHandler(fd),c.registerEntityHandler(Ad),c.registerEntityHandler(Id),c.registerEntityHandler(Bd),c.registerEntityHandler(kd),c.registerEntityHandler(Dd),c.registerEntityHandler(Ld),c.registerEntityHandler(Rd),c.registerEntityHandler(zd),c.registerEntityHandler(Gd),c.registerEntityHandler(qd),c.registerEntityHandler(Wd),c.registerEntityHandler(Xd),c.registerEntityHandler(Zd),c.registerEntityHandler($d),c.registerEntityHandler(Jd),c.registerEntityHandler(Qd),c.registerEntityHandler(e1),c.registerEntityHandler(n1),c.registerEntityHandler(r1),c.registerEntityHandler(a1),c.registerEntityHandler(o1),c.registerEntityHandler(l1),c.registerEntityHandler(c1),c.registerEntityHandler(d1),c.registerEntityHandler(u1),c.registerEntityHandler(f1),c.registerEntityHandler(p1)}function T1(c){c.registerObjectHandler(m1),c.registerObjectHandler(g1),c.registerObjectHandler(y1),c.registerObjectHandler(x1),c.registerObjectHandler(b1),c.registerObjectHandler(v1)}function C1(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){x(this,"_entityHandlers",{});x(this,"_objectHandlers",{});x(this,"_layoutBlocks",{});x(this,"unhandledSections",{});x(this,"unhandledObjects",{});x(this,"unhandledEntities",{});x(this,"unsupportedLineTypes",{});x(this,"encoding");this.encoding=t,M1(this),T1(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new va(e);return this._parse(i)}else{let e;if(C1(t))e=new ld(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 va(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")A.trace("> HEADER"),e.header=a(),A.trace("<");else if(n.value==="TABLES")A.trace("> TABLES"),e.tables=h(),A.trace("<");else if(n.value==="BLOCKS")A.trace("> BLOCKS"),e.blocks=o(),A.trace("<");else if(n.value==="ENTITIES")A.trace("> ENTITIES"),e.entities=C(!1),A.trace("<");else if(n.value==="OBJECTS")A.trace("> OBJECTS"),e.objects=S(),A.trace("<");else if(n.value==="EOF")A.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(Xe(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"&&!Xe(n,0,"ENDSEC");)if(Xe(n,0,"BLOCK")){A.trace("block {");const v=l();A.trace("}"),O(v),v.name?E[v.name]=v:console.error("[DxfParser] Block with handle '"+v.handle+"' is missing a name, ignored!")}else vt(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=F(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=C(!0);break;default:vt(n),n=t.next();break}if(Xe(n,0,"ENDBLK")){n=t.next();break}}return E}function h(){const E={};for(n=t.next();n.value!=="EOF"&&!Xe(n,0,"ENDSEC");)Xe(n,0,"TABLE")?(n=t.next(),b[n.value]?(A.trace(n.value+" Table {"),E[b[n.value].tableName]=u(n),A.trace("}")):A.trace("Unhandled Table "+n.value)):n=t.next();return n=t.next(),E}const d="ENDTAB";function u(E){const v=b[E.value],T={};let _=0;for(n=t.next();!Xe(n,0,d);)switch(n.code){case 5:T.handle=n.value,n=t.next();break;case 330:T.ownerHandle=n.value,n=t.next();break;case 100:n.value==="AcDbSymbolTable"||vt(n),n=t.next();break;case 70:_=n.value,n=t.next();break;case 0:n.value===v.dxfSymbolName?T[v.tableRecordsProperty]=v.parseTableRecords():(vt(n),n=t.next());break;default:vt(n),n=t.next();break}const P=T[v.tableRecordsProperty];if(P){const I=(()=>{if(P.constructor===Array)return P.length;if(typeof P=="object")return Object.keys(P).length})();_!==I&&console.warn("[DxfParser] Parsed "+I+" "+v.dxfSymbolName+"s but expected "+_)}return n=t.next(),T}function f(){const E=[];let v={};for(A.trace("Viewport {"),n=t.next();!Xe(n,0,d);)switch(n.code){case 2:v.name=n.value,n=t.next();break;case 10:v.lowerLeftCorner=F(t),n=t.lastReadGroup;break;case 11:v.upperRightCorner=F(t),n=t.lastReadGroup;break;case 12:v.center=F(t),n=t.lastReadGroup;break;case 13:v.snapBasePoint=F(t),n=t.lastReadGroup;break;case 14:v.snapSpacing=F(t),n=t.lastReadGroup;break;case 15:v.gridSpacing=F(t),n=t.lastReadGroup;break;case 16:v.viewDirectionFromTarget=F(t),n=t.lastReadGroup;break;case 17:v.viewTarget=F(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=F(t),n=t.lastReadGroup;break;case 111:v.ucsXAxis=F(t),n=t.lastReadGroup;break;case 112:v.ucsYAxis=F(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"&&(A.trace("}"),E.push(v),A.trace("Viewport {"),v={},n=t.next());break;default:vt(n),n=t.next();break}return A.trace("}"),E.push(v),E}function m(){const E={};let v={},T=0,_="",P=!1;for(A.trace("LType {"),n=t.next();!Xe(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;P&&(I=Math.abs(I),P=!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&&(P=!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:A.trace("}"),T>0&&T!==v.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),E[_]=v,v={},A.trace("LType {"),n=t.next();break;default:n=t.next();break}return A.trace("}"),E[_]=v,E}function y(){const E={};let v={},T;for(A.trace("Layer {"),n=t.next();!Xe(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("Layer {"),v={},T=void 0,n=t.next());break;default:vt(n),n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function g(){const E={};let v={},T;for(A.trace("Style {"),n=t.next();!Xe(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("Style {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function M(){const E={};let v={},T;for(A.trace("DimStyle {"),n=t.next();!Xe(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("DimStyle {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function w(){const E={};let v={},T;for(A.trace("BlockRecord {"),n=t.next();!Xe(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"){A.trace("}"),T&&(E[T]=v);const P=v.layoutHandle;T&&P&&P.length>0&&P!=="0"&&(s._layoutBlocks[P]=v),A.trace("BlockRecord {"),v={},T=void 0,n=t.next()}else vt(n),n=t.next();break;default:vt(n),n=t.next();break}A.trace("}"),T&&(E[T]=v);const _=v.layoutHandle;return T&&_&&_.length>0&&_!=="0"&&(s._layoutBlocks[_]=v),E}const b={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:y},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:w},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:g},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:M}};function C(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){A.trace(n.value+" {");const P=_.parseEntity(t,n);if(P){P.layer||(P.layer="0"),P.colorIndex===void 0&&(P.colorIndex=256),P.lineType||(P.lineType="BYLAYER"),n=t.lastReadGroup,A.trace("}"),O(P),v.push(P);const I=P.decodedEntities;Array.isArray(I)&&I.length&&v.push(...I)}}else{const P=n.value;s.unhandledEntities[P]||(s.unhandledEntities[P]=0),s.unhandledEntities[P]++,n=t.next();continue}}else n=t.next();return T==="ENDSEC"&&(n=t.next()),v}function S(){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){A.trace(n.value+" {");const _=T.parseObject(t,n),P=n.value;n=t.lastReadGroup,A.trace("}"),O(_),E[P]||(E[P]=[]),E[P].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===`
|
|
791
|
+
`;return new p.ShaderMaterial({uniforms:n,vertexShader:r,fragmentShader:a,clipping:!0})}var Qe=(c=>(c.Unitless="Unitless",c.Inches="Inches",c.Feet="Feet",c.Millimeters="Millimeters",c.Centimeters="Centimeters",c.Meters="Meters",c))(Qe||{});const gr=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),od=(c,t)=>gr(c)/gr(t);class ko{constructor(){y(this,"pointer");y(this,"eof");y(this,"lastReadGroup");this.pointer=0,this.eof=!1}}class ys{constructor(t,e){y(this,"endian");y(this,"position");y(this,"data");y(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=xs.DataViewGetBigInt64(this.data,this.position,this.endian==="little");return this.position+=8,xs.toNumber(t)}readUint64(){if(this.data.byteLength<this.position+8)throw"range error";const t=xs.DataViewGetBigUint64(this.data,this.position,this.endian==="little");return this.position+=8,xs.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 ba=1e3;class ld extends ko{constructor(e){super();y(this,"reader");y(this,"decoder");y(this,"int8Array");y(this,"caches");this.int8Array=new Int8Array(ba),this.caches=new Map,this.reader=new ys(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 wa(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 wa(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>ba)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 wa(c){return Array.prototype.map.call(c,t=>("00"+t.toString(16)).slice(-2)).join("")}class va extends ko{constructor(e){super();y(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=cd(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 cd(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?hd(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 hd(c){if(c==="0")return!1;if(c==="1")return!0;throw TypeError("String '"+c+"' cannot be cast to Boolean type")}function dd(c){if(c==null)return!0;for(const t in c)if(Object.prototype.hasOwnProperty.call(c,t))return!1;return!0}function ud(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()}dd(a)||e.push(a),i=!1,s=!1}return e}class fd{constructor(){y(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=ud(t,e),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}const pd=9,md=6,Ma=7,gd=2,yd=3,xd=4,bd=5,wd=14,vd=33,Md=38;class Td{constructor(t){y(this,"data");y(this,"pos",0);y(this,"bit",0);y(this,"bad",!1);this.data=t}getBit(){if(this.pos>=this.data.length)return this.bad=!0,0;const t=this.data[this.pos]>>7-this.bit&1;return++this.bit===8&&(this.bit=0,this.pos++),t}get2(){const t=this.getBit();return this.bad?0:t<<1|this.getBit()}rawChar8(){if(this.bit===0)return this.pos>=this.data.length?(this.bad=!0,0):this.data[this.pos++];if(this.pos+1>=this.data.length)return this.bad=!0,0;let t=this.data[this.pos]<<this.bit&255;return t|=this.data[this.pos+1]>>8-this.bit,this.pos++,t&255}rawShort16(){return(this.rawChar8()|this.rawChar8()<<8)&65535}rawLong32(){const t=this.rawShort16();return(this.rawShort16()<<16|t)>>>0}rawDouble(){const t=new Uint8Array(8);for(let e=0;e<8;e++)t[e]=this.rawChar8();return this.bad?0:new DataView(t.buffer).getFloat64(0,!0)}bitShort(){const t=this.get2();return t===0?this.rawShort16():t===1?this.rawChar8():t===2?0:256}bitLong(){const t=this.get2();return t===0?this.rawLong32()|0:t===1?this.rawChar8():0}bitDouble(){const t=this.get2();return t===1?1:t===2?0:t===0?this.rawDouble():(this.bad=!0,0)}defaultDouble(t){const e=this.get2();if(this.bad)return 0;if(e===0)return t;if(e===1){const i=new Uint8Array(4);for(let n=0;n<4;n++)i[n]=this.rawChar8();if(this.bad)return 0;const s=new Uint8Array(8);return new DataView(s.buffer).setFloat64(0,t,!0),s.set(i,0),new DataView(s.buffer).getFloat64(0,!0)}if(e===2){const i=new Uint8Array(6);for(let n=0;n<6;n++)i[n]=this.rawChar8();if(this.bad)return 0;const s=new Uint8Array(8);new DataView(s.buffer).setFloat64(0,t,!0);for(let n=2;n<6;n++)s[n-2]=i[n];return s[4]=i[0],s[5]=i[1],new DataView(s.buffer).getFloat64(0,!0)}return this.rawDouble()}}function Cd(c){if(c.length<5)return null;const t=new Td(c.subarray(4)),e=t.bitShort();if(t.bad)return null;e&4&&t.bitDouble(),e&8&&t.bitDouble(),e&2&&t.bitDouble(),e&1&&(t.bitDouble(),t.bitDouble(),t.bitDouble());const i=(e&512)!==0,s=t.bitLong();if(s<=0||s>1e5)return null;let n=0;if(e&16&&(n=t.bitLong()),e&1024&&t.bitLong(),e&32&&t.bitLong(),t.bad)return null;let r=t.rawDouble(),a=t.rawDouble();if(t.bad)return null;const o=[{x:r,y:a}];for(let h=1;h<s&&!t.bad;h++)r=t.defaultDouble(r),a=t.defaultDouble(a),t.bad||o.push({x:r,y:a});if(o.length!==s)return null;let l=0;for(let h=0;h<n&&!t.bad;h++)l=t.bitDouble(),Math.abs(l)>1e-15&&h<o.length&&(o[h].bulge=l);return{points:o,closed:i}}function Sd(c){if(c.length<72)return null;const t=new DataView(c.buffer,c.byteOffset,c.byteLength),e=t.getFloat64(0,!0),i=t.getFloat64(8,!0),s=t.getFloat64(48,!0),n=t.getFloat64(56,!0);let r=72;for(;r+1<c.length&&!(c[r]===0&&c[r+1]===0);)r+=2;if(r+1>=c.length)return null;let a="";try{a=new TextDecoder("utf-16le").decode(c.subarray(72,r))}catch{return null}let o=r+2;if(o%4&&(o+=4-o%4),o+8+32>c.length)return null;const l=t.getFloat64(o+8,!0),h=t.getFloat64(o+16,!0),d=t.getUint32(o+40,!0),u=t.getUint32(o+44,!0);return!Number.isFinite(l)||l<=0||!a?null:{kind:"text",startPoint:{x:e,y:i},height:l,rotation:Math.atan2(n,s)*180/Math.PI,xScale:Number.isFinite(h)&&h>0?h:1,text:a,mirrored:2*(d?1:0)+4*(u?1:0)}}function Ed(c){const t=new Uint8Array(c.length>>1);for(let e=0;e<t.length;e++)t[e]=parseInt(c.substr(e*2,2),16);return t}function Ta(c,t,e){const i=2*(c.x*(t.y-e.y)+t.x*(e.y-c.y)+e.x*(c.y-t.y));if(!Number.isFinite(i)||Math.abs(i)<1e-12)return null;const s=c.x*c.x+c.y*c.y,n=t.x*t.x+t.y*t.y,r=e.x*e.x+e.y*e.y,a=(s*(t.y-e.y)+n*(e.y-c.y)+r*(c.y-t.y))/i,o=(s*(e.x-t.x)+n*(c.x-e.x)+r*(t.x-c.x))/i,l=Math.hypot(c.x-a,c.y-o);return!Number.isFinite(l)||l<=0?null:{center:{x:a,y:o},radius:l}}function Us(c){let t=c%(Math.PI*2);return t<0&&(t+=Math.PI*2),t}function Od(c){const t=new DataView(c.buffer,c.byteOffset,c.byteLength),e={},i=[];if(c.byteLength<8)return{prims:i,ops:e};const s=t.getInt32(0,!0),n=Math.min(s,c.byteLength);let r=256,a=8;const o=l=>({x:t.getFloat64(l,!0),y:t.getFloat64(l+8,!0)});for(;a+8<=n;){const l=t.getInt32(a,!0);if(l<8||a+l>n)break;const h=t.getInt32(a+4,!0);e[h]=(e[h]||0)+1;const d=a+8;try{switch(h){case md:case Ma:{const u=t.getInt32(d,!0);if(u>0&&d+4+u*24<=a+l){const f=[];for(let m=0;m<u;m++)f.push(o(d+4+m*24));f.every(m=>Number.isFinite(m.x)&&Number.isFinite(m.y))&&i.push({kind:"polyline",points:f,closed:h===Ma,colorIndex:r})}break}case gd:{const u=o(d),f=t.getFloat64(d+24,!0);Number.isFinite(f)&&f>0&&Number.isFinite(u.x)&&Number.isFinite(u.y)&&i.push({kind:"circle",center:u,radius:f,colorIndex:r});break}case yd:{const u=Ta(o(d),o(d+24),o(d+48));u&&i.push({kind:"circle",center:u.center,radius:u.radius,colorIndex:r});break}case xd:{const u=o(d),f=t.getFloat64(d+24,!0),m=o(d+56),x=t.getFloat64(d+80,!0);if(Number.isFinite(f)&&f>0&&Number.isFinite(x)&&Number.isFinite(u.x)&&Number.isFinite(u.y)){const g=Math.atan2(m.y,m.x);i.push({kind:"arc",center:u,radius:f,startAngle:g,endAngle:g+x,colorIndex:r})}break}case bd:{const u=o(d),f=o(d+24),m=o(d+48),x=Ta(u,f,m);if(x){const g=Math.atan2(u.y-x.center.y,u.x-x.center.x),M=Math.atan2(f.y-x.center.y,f.x-x.center.x);let w=Math.atan2(m.y-x.center.y,m.x-x.center.x),b=g+Us(w-g);Us(M-g)>Us(w-g)&&(b=g+Us(w-g)+Math.PI*2),i.push({kind:"arc",center:x.center,radius:x.radius,startAngle:g,endAngle:b,colorIndex:r})}break}case pd:{const u=t.getInt32(d,!0),f=d+4;if(u<=0||u>1e5||f+u*24>a+l)break;const m=[];let x=!1;for(let C=0;C<u;C++){const S=f+C*24,O=t.getFloat64(S,!0),E=t.getFloat64(S+8,!0);if(!Number.isFinite(O)||!Number.isFinite(E)){x=!0;break}m.push({x:O,y:E})}if(x)break;const g=f+u*24;if(g+4>a+l)break;const M=t.getInt32(g,!0);if(M<=0||M>1e6)break;let w=g+4,b=0;for(;b<M&&w+4<=a+l;){const C=t.getInt32(w,!0);w+=4;const S=C<0?-C:C;if(S>M-b-1||(b+=1+S,w+S*4>a+l))break;const O=[];for(let E=0;E<S;E++){const v=t.getInt32(w,!0);w+=4,v>=0&&v<u&&O.push(v)}O.length>=2&&i.push({kind:"polyline",points:O.map(E=>m[E]),closed:!0,colorIndex:r})}break}case vd:{const u=Cd(c.subarray(d,a+l));u&&u.points.every(f=>Number.isFinite(f.x)&&Number.isFinite(f.y))&&i.push({kind:"polyline",points:u.points,closed:u.closed,colorIndex:r});break}case Md:{const u=Sd(c.subarray(d,a+l));u&&i.push({...u,colorIndex:r});break}case wd:{const u=t.getUint32(d,!0);r=u===0||u===256?256:u;break}default:break}}catch{}a+=l}return{prims:i,ops:e}}function Pd(c,t){return c.colorIndex===256?t.colorIndex??256:c.colorIndex}function _d(c,t){const e=[];return c.forEach((i,s)=>{const n=Pd(i,t),r={layer:t.layer||"0",colorIndex:n,color:oi(Math.abs(n)),lineType:"BYLAYER",handle:`${t.handle||"0"}-p${s}`,inPaperSpace:!1};i.kind==="polyline"?e.push({...r,type:"LWPOLYLINE",vertices:i.points,shape:i.closed,thickness:0}):i.kind==="circle"?e.push({...r,type:"CIRCLE",center:i.center,radius:i.radius,thickness:0}):i.kind==="text"?e.push({...r,type:"TEXT",startPoint:i.startPoint,textHeight:i.height,xScale:i.xScale,rotation:i.rotation,text:i.text,textStyle:"STANDARD",mirrored:i.mirrored,thickness:0}):e.push({...r,type:"ARC",center:i.center,radius:i.radius,startAngle:i.startAngle,endAngle:i.endAngle,thickness:0})}),e}class Ad{constructor(){y(this,"ForEntityName","ACAD_PROXY_ENTITY")}parseEntity(t,e){const i={type:e.value},s=[];for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===310?typeof e.value=="string"&&s.push(e.value):te(i,e),e=t.next();if(s.length)try{const n=Ed(s.join("")),{prims:r}=Od(n);i.decodedEntities=_d(r,i)}catch{}return i}}class Id{constructor(){y(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=F(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:te(i,e),e=t.next();break}return i}}class Bd{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class kd{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class Dd{constructor(){y(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=F(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:te(i,e),e=t.next();break}return i}}class Ld{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.middleOfText=F(t),e=t.lastReadGroup;break;case 12:i.insertionPoint=F(t),e=t.lastReadGroup;break;case 13:i.linearOrAngularPoint1=F(t),e=t.lastReadGroup;break;case 14:i.linearOrAngularPoint2=F(t),e=t.lastReadGroup;break;case 15:i.diameterOrRadiusPoint=F(t),e=t.lastReadGroup;break;case 16:i.arcPoint=F(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:te(i,e),e=t.next();break}return i}}class Rd{constructor(){y(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(Xe(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=Xe(t),e=t.lastReadGroup;break;case 11:o.doglegVector=Xe(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=Xe(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 304:i.contextData.defaultTextContents=e.value,e=t.next();break;case 11:i.contextData.textNormalDirection=Xe(t),e=t.lastReadGroup;break;case 12:i.contextData.textLocation=Xe(t),e=t.lastReadGroup;break;case 13:i.contextData.textDirection=Xe(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=Xe(t),e=t.lastReadGroup;break;case 15:i.contextData.blockContentPosition=Xe(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=Fd(t,47),e=t.lastReadGroup;break;case 110:i.contextData.planeOriginPoint=Xe(t),e=t.lastReadGroup;break;case 111:i.contextData.planeXAxisDirection=Xe(t),e=t.lastReadGroup;break;case 112:i.contextData.planeYAxisDirection=Xe(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=Xe(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:te(i,e),e=t.next();break}})(),i}}function Xe(c){const t={};let e=c.lastReadGroup||c.next(),i=!1,s=!1,n=!1,r=!1;for(;!c.isEOF();){const a=e.code,o=a>=10&&a<=16||a>=110&&a<=112,l=a>=20&&a<=26||a>=120&&a<=122,h=a>=30&&a<=36||a>=130&&a<=132;if(a===42&&!r)t.bulge=e.value,r=!0;else if(o&&!i)t.x=e.value,i=!0;else if(l&&!s)t.y=e.value,s=!0;else if(h&&!n)t.z=e.value,n=!0;else return t;e=c.next()}return t}function Fd(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 zd{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.majorAxisEndPoint=F(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=F(t),e=t.lastReadGroup;break;case 2:i.name=e.value,e=t.next();break;default:te(i,e),e=t.next();break}return i}}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||{}),Si=(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))(Si||{});function Vd(c){const t={type:0,points:[],isClosed:!0};let e=c.next();e=c.next(),t.isClosed=e.value!==0,e=c.next();const i=e.value;e=c.next();for(let n=0;n<i;n++)t.points.push(F(c)),e=c.lastReadGroup;e=c.lastReadGroup,console.assert(e.code===97,"The reference count code 97 was expected.");const s=e.value;e=c.next();for(let n=0;n<s;n++)console.assert(e.code===330,"The reference handle code 330 was expected."),e=c.next();return{edges:[t],pathTypeFlag:-1}}function Ud(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:F(t),endPoint:F(t)};i=t.lastReadGroup,e.push(r);break}case 2:{i=t.next();const r={type:2,center:F(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:F(t),majorAxisEndPoint:F(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 jd(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=Vd(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=Ud(r,t),n.pathTypeFlag=i,e.push(n),s=t.lastReadGroup;break}default:s=t.next();break}}return e}function Nd(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 Hd(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 Gd{constructor(){y(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=Nd(e.value,t),e=t.lastReadGroup;break;case 91:i.boundaryPathsCount=e.value,i.boundaryPaths=jd(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=Hd(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:te(i,e),e=t.next();break}return i}}var on=(c=>(c[c.ShowImage=1]="ShowImage",c[c.ShowImageWhenNotAlignedWithScreen=2]="ShowImageWhenNotAlignedWithScreen",c[c.UseClippingBoundary=4]="UseClippingBoundary",c[c.TransparencyIsOn=8]="TransparencyIsOn",c))(on||{});let qd=class{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.uPixel=F(t),e=t.lastReadGroup;break;case 12:i.vPixel=F(t),e=t.lastReadGroup;break;case 13:i.imageSize=F(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(F(t)),e=t.lastReadGroup;break;case 290:i.clipMode=e.value,e=t.next();break;default:te(i,e),e=t.next();break}return i}};class Wd{constructor(){y(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=F(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=F(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:te(i,e),e=t.next();break}return i}}function Yd(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 Xd{constructor(){y(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(F(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=Yd(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:te(i,e),e=t.next();break}return i}}class Zd{constructor(){y(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(F(t)),e=t.lastReadGroup;break;case 11:i.vertices.push(F(t)),e=t.lastReadGroup;break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}function Kd(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 $d{constructor(){y(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(...Kd(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:te(i,e),e=t.next();break}return i}}class Jd{constructor(){y(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=F(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=F(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:te(i,e),e=t.next();break}return i}}class Qd{constructor(){y(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:te(i,e),e=t.next();break}return i}}class e1{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 39:i.thickness=e.value,e=t.next();break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class t1{constructor(){y(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:te(i,e),e=t.next();break}return i}}function i1(c,t){const e=new t1,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"){s1(c,t);break}}return i}function s1(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 te(e,t),t=c.next();return e}class n1{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i.vertices=i1(t,e),i}}class r1{constructor(){y(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:te(i,e),e=t.next();break}return i}}class a1{constructor(){y(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(F(t)),e=t.lastReadGroup;break;case 11:i.directionVector=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class o1{constructor(){y(this,"ForEntityName","SEQEND")}parseEntity(t,e){const i={type:e.value};for(e=t.next();!t.isEOF()&&e.code!==0;)e.code===-2||(te(i,e),e=t.next());return i}}class l1{constructor(){y(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]=F(t),e=t.lastReadGroup;break;case 11:i.points[1]=F(t),e=t.lastReadGroup;break;case 12:i.points[2]=F(t),e=t.lastReadGroup;break;case 13:i.points[3]=F(t),e=t.lastReadGroup;break;case 210:i.extrusionDirection=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class c1{constructor(){y(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(F(t)),e=t.lastReadGroup;break;case 11:i.fitPoints||(i.fitPoints=[]),i.fitPoints.push(F(t)),e=t.lastReadGroup;break;case 12:i.startTangent=F(t),e=t.lastReadGroup;break;case 13:i.endTangent=F(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=F(t),e=t.lastReadGroup;break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}function h1(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 Ca(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){h1(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 d1{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.directionVector=F(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(Ca(e,t)):i.cells=[Ca(e,t)],e=t.lastReadGroup;break;default:te(i,e),e=t.next();break}return i}}class u1{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 11:i.endPoint=F(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:te(i,e),e=t.next();break}return i}}class f1{constructor(){y(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=F(t),e=t.lastReadGroup;break;case 12:i.centerPoint_dcs=F(t),e=t.lastReadGroup;break;case 13:i.snapBasePoint_dcs=F(t),e=t.lastReadGroup;break;case 14:i.snapSpacing_dcs=F(t),e=t.lastReadGroup;break;case 15:i.gridSpacing_dcs=F(t),e=t.lastReadGroup;break;case 16:i.viewDirection=F(t),e=t.lastReadGroup;break;case 17:i.viewTarget=F(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=F(t),e=t.lastReadGroup;break;case 111:i.ucsXAxis=F(t),e=t.lastReadGroup;break;case 112:i.ucsYAxis=F(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:te(i,e),e=t.next();break}return i}}class p1{constructor(){y(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(F(t)),e=t.lastReadGroup;break;case 11:i.directionVector=F(t),e=t.lastReadGroup;break;case 100:e=t.next();break;case 101:for(;e.code!=0;)e=t.next();break;default:te(i,e),e=t.next();break}return i}}class m1{constructor(){y(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:Fi(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 g1{constructor(){y(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=Sa(t),e=t.next();break;case 11:s.pixelSize=Sa(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:Fi(s,e),e=t.next();break}return s}}function Sa(c){const t={};let e=c.lastReadGroup||c.next();const i=e.code;for(;!c.isEOF();){if(e.code===i)t.x=e.value;else if(e.code===i+10)t.y=e.value;else if(e.code===i+20)t.z=e.value;else if(e.code===42)t.bulge=e.value;else return t;e=c.next()}return t}class y1{constructor(){y(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=Dt(t),e=t.lastReadGroup;break;case 11:s.maxLimit=Dt(t),e=t.lastReadGroup;break;case 12:s.basePoint=Dt(t),e=t.lastReadGroup;break;case 13:s.origin=Dt(t),e=t.lastReadGroup;break;case 14:s.minExtent=Dt(t),e=t.lastReadGroup;break;case 15:s.maxExtent=Dt(t),e=t.lastReadGroup;break;case 16:s.XAxis=Dt(t),e=t.lastReadGroup;break;case 17:s.YAxis=Dt(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:Fi(s,e),e=t.next();break}return s.blockTableHandle=s.ownerHandle,s}}function Dt(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 x1{constructor(){y(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:Fi(s,e),e=t.next();break}return s}}class b1{constructor(){y(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=ln(t),e=t.lastReadGroup;break;case 70:s.numberOfPointsOnClipBoundary=e.value,s.numberOfPointsOnClipBoundary===2?(e=t.next(),n=ln(t),e=t.lastReadGroup,r=ln(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=w1(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=Ea(t,40),s.matrix=Ea(t,40),e=t.lastReadGroup;break;default:Fi(s,e),e=t.next();break}return s}}function w1(c,t){t.next();const e=[];for(;e.length<c;)e.push(ln(t));return e}function Ea(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 ln(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 v1{constructor(){y(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:Fi(s,e),e=t.next();break}return s}}function M1(c){c.registerEntityHandler(fd),c.registerEntityHandler(Ad),c.registerEntityHandler(Id),c.registerEntityHandler(Bd),c.registerEntityHandler(kd),c.registerEntityHandler(Dd),c.registerEntityHandler(Ld),c.registerEntityHandler(Rd),c.registerEntityHandler(zd),c.registerEntityHandler(Gd),c.registerEntityHandler(qd),c.registerEntityHandler(Wd),c.registerEntityHandler(Xd),c.registerEntityHandler(Zd),c.registerEntityHandler($d),c.registerEntityHandler(Jd),c.registerEntityHandler(Qd),c.registerEntityHandler(e1),c.registerEntityHandler(n1),c.registerEntityHandler(r1),c.registerEntityHandler(a1),c.registerEntityHandler(o1),c.registerEntityHandler(l1),c.registerEntityHandler(c1),c.registerEntityHandler(d1),c.registerEntityHandler(u1),c.registerEntityHandler(f1),c.registerEntityHandler(p1)}function T1(c){c.registerObjectHandler(m1),c.registerObjectHandler(g1),c.registerObjectHandler(y1),c.registerObjectHandler(x1),c.registerObjectHandler(b1),c.registerObjectHandler(v1)}function C1(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){y(this,"_entityHandlers",{});y(this,"_objectHandlers",{});y(this,"_layoutBlocks",{});y(this,"unhandledSections",{});y(this,"unhandledObjects",{});y(this,"unhandledEntities",{});y(this,"unsupportedLineTypes",{});y(this,"encoding");this.encoding=t,M1(this),T1(this)}parse(t){if(typeof t=="string"){const e=this.splitByLineSeparator(t),i=new va(e);return this._parse(i)}else{let e;if(C1(t))e=new ld(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 va(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")A.trace("> HEADER"),e.header=a(),A.trace("<");else if(n.value==="TABLES")A.trace("> TABLES"),e.tables=h(),A.trace("<");else if(n.value==="BLOCKS")A.trace("> BLOCKS"),e.blocks=o(),A.trace("<");else if(n.value==="ENTITIES")A.trace("> ENTITIES"),e.entities=C(!1),A.trace("<");else if(n.value==="OBJECTS")A.trace("> OBJECTS"),e.objects=S(),A.trace("<");else if(n.value==="EOF")A.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(Ze(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"&&!Ze(n,0,"ENDSEC");)if(Ze(n,0,"BLOCK")){A.trace("block {");const v=l();A.trace("}"),O(v),v.name?E[v.name]=v:console.error("[DxfParser] Block with handle '"+v.handle+"' is missing a name, ignored!")}else Mt(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=F(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=C(!0);break;default:Mt(n),n=t.next();break}if(Ze(n,0,"ENDBLK")){n=t.next();break}}return E}function h(){const E={};for(n=t.next();n.value!=="EOF"&&!Ze(n,0,"ENDSEC");)Ze(n,0,"TABLE")?(n=t.next(),b[n.value]?(A.trace(n.value+" Table {"),E[b[n.value].tableName]=u(n),A.trace("}")):A.trace("Unhandled Table "+n.value)):n=t.next();return n=t.next(),E}const d="ENDTAB";function u(E){const v=b[E.value],T={};let P=0;for(n=t.next();!Ze(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"||Mt(n),n=t.next();break;case 70:P=n.value,n=t.next();break;case 0:n.value===v.dxfSymbolName?T[v.tableRecordsProperty]=v.parseTableRecords():(Mt(n),n=t.next());break;default:Mt(n),n=t.next();break}const _=T[v.tableRecordsProperty];if(_){const I=(()=>{if(_.constructor===Array)return _.length;if(typeof _=="object")return Object.keys(_).length})();P!==I&&console.warn("[DxfParser] Parsed "+I+" "+v.dxfSymbolName+"s but expected "+P)}return n=t.next(),T}function f(){const E=[];let v={};for(A.trace("Viewport {"),n=t.next();!Ze(n,0,d);)switch(n.code){case 2:v.name=n.value,n=t.next();break;case 10:v.lowerLeftCorner=F(t),n=t.lastReadGroup;break;case 11:v.upperRightCorner=F(t),n=t.lastReadGroup;break;case 12:v.center=F(t),n=t.lastReadGroup;break;case 13:v.snapBasePoint=F(t),n=t.lastReadGroup;break;case 14:v.snapSpacing=F(t),n=t.lastReadGroup;break;case 15:v.gridSpacing=F(t),n=t.lastReadGroup;break;case 16:v.viewDirectionFromTarget=F(t),n=t.lastReadGroup;break;case 17:v.viewTarget=F(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=F(t),n=t.lastReadGroup;break;case 111:v.ucsXAxis=F(t),n=t.lastReadGroup;break;case 112:v.ucsYAxis=F(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"&&(A.trace("}"),E.push(v),A.trace("Viewport {"),v={},n=t.next());break;default:Mt(n),n=t.next();break}return A.trace("}"),E.push(v),E}function m(){const E={};let v={},T=0,P="",_=!1;for(A.trace("LType {"),n=t.next();!Ze(n,0,"ENDTAB");)switch(n.code){case 2:v.name=n.value.toUpperCase(),P=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;_&&(I=Math.abs(I),_=!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&&(_=!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:A.trace("}"),T>0&&T!==v.pattern.length&&console.warn("[DxfParser] lengths do not match on LTYPE pattern"),E[P]=v,v={},A.trace("LType {"),n=t.next();break;default:n=t.next();break}return A.trace("}"),E[P]=v,E}function x(){const E={};let v={},T;for(A.trace("Layer {"),n=t.next();!Ze(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("Layer {"),v={},T=void 0,n=t.next());break;default:Mt(n),n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function g(){const E={};let v={},T;for(A.trace("Style {"),n=t.next();!Ze(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("Style {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function M(){const E={};let v={},T;for(A.trace("DimStyle {"),n=t.next();!Ze(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"&&(A.trace("}"),T&&(E[T]=v),A.trace("DimStyle {"),v={},T=void 0,n=t.next());break;default:n=t.next();break}return A.trace("}"),T&&(E[T]=v),E}function w(){const E={};let v={},T;for(A.trace("BlockRecord {"),n=t.next();!Ze(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"){A.trace("}"),T&&(E[T]=v);const _=v.layoutHandle;T&&_&&_.length>0&&_!=="0"&&(s._layoutBlocks[_]=v),A.trace("BlockRecord {"),v={},T=void 0,n=t.next()}else Mt(n),n=t.next();break;default:Mt(n),n=t.next();break}A.trace("}"),T&&(E[T]=v);const P=v.layoutHandle;return T&&P&&P.length>0&&P!=="0"&&(s._layoutBlocks[P]=v),E}const b={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:x},BLOCK_RECORD:{tableRecordsProperty:"blockRecords",tableName:"blockRecord",dxfSymbolName:"BLOCK_RECORD",parseTableRecords:w},STYLE:{tableRecordsProperty:"styles",tableName:"style",dxfSymbolName:"STYLE",parseTableRecords:g},DIMSTYLE:{tableRecordsProperty:"dimStyles",tableName:"dimStyle",dxfSymbolName:"DIMSTYLE",parseTableRecords:M}};function C(E){const v=[],T=E?"ENDBLK":"ENDSEC";for(E||(n=t.next());;)if(n.code===0){if(n.value===T)break;const P=s._entityHandlers[n.value];if(P!=null){A.trace(n.value+" {");const _=P.parseEntity(t,n);if(_){_.layer||(_.layer="0"),_.colorIndex===void 0&&(_.colorIndex=256),_.lineType||(_.lineType="BYLAYER"),n=t.lastReadGroup,A.trace("}"),O(_),v.push(_);const I=_.decodedEntities;Array.isArray(I)&&I.length&&v.push(...I)}}else{const _=n.value;s.unhandledEntities[_]||(s.unhandledEntities[_]=0),s.unhandledEntities[_]++,n=t.next();continue}}else n=t.next();return T==="ENDSEC"&&(n=t.next()),v}function S(){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){A.trace(n.value+" {");const P=T.parseObject(t,n),_=n.value;n=t.lastReadGroup,A.trace("}"),O(P),E[_]||(E[_]=[]),E[_].push(P)}else{const P=n.value;s.unhandledObjects[P]||(s.unhandledObjects[P]=0),s.unhandledObjects[P]++,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,P)=>T.tabOrder-P.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
792
|
`){let a=t.substring(i,s);a&&a.indexOf("M+")>-1&&(a=id(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 Xe(c,t,e){return c.code===t&&c.value===e}function vt(c){A.trace("unhandled group "+Ro(c))}function Ro(c){return c.code+":"+c.value}const Fo="0.4.0",zo="VERSION",S1=()=>window.localStorage.getItem(zo),E1=()=>{window.localStorage.setItem(zo,Fo)},O1=()=>S1()!==Fo?(E1(),!0):!1,si=class si{constructor(){x(this,"DATABASE_NAME","x_viewer");x(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);x(this,"db");x(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!si._instance&&(si._instance=new si),si._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),O1()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,A.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,A.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,A.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{A.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=>{A.debug(n),i(n)},s.onsuccess=n=>{const r=n.target;A.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;A.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async getUpgradedDB(t){return new Promise((e,i)=>{A.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=>{A.debug("onblocked",n)},s.onupgradeneeded=n=>{const r=n.target.transaction;r.oncomplete=()=>{A.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)){A.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(()=>{A.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=n=>{const r=n.target.result;A.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})}),A.debug("[DB] Table "+e+" created."),n(t)})}};x(si,"_instance");let pe=si;class Vo{constructor(){x(this,"db");x(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,pe.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();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()}).catch(n=>{i&&i(n)})}save(t,e,i){const s=this.tableName();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()})}update(){pe.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}queryByIndex(t,e,i,s){const n=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}}const ni=class ni extends Vo{tableName(){return"dxf_data"}static instance(){return!ni._instance&&(ni._instance=new ni),ni._instance}query(t,e,i){const s=[],n=this.tableName();pe.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.get(t);o.onerror=l=>{i&&i(l),A.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{pe.instance().closeDatabase()})}};x(ni,"_instance");let dn=ni;const Ze=new p.Vector3(1,0,0),jn=new p.Vector3(0,1,0),gi=new p.Vector3(0,0,1),Oa=new p.Vector3(0,0,0),Ft=16777215,_1="CONTINUOUS",js=new p.PointsMaterial({color:Ft}),ye=new p.LineBasicMaterial({color:Ft}),yi=new p.MeshBasicMaterial({color:Ft}),_a=new p.BufferGeometry().setFromPoints([new p.Vector3]),Pa=new p.Matrix4,nt=new p.Matrix4,fe=new p.Matrix4,H=new p.Vector3,$=new p.Vector3,rt=new p.Vector3,Xi=new p.Vector2,xe=new p.Quaternion,Ns=new p.Object3D,ft=new p.Box3,Aa=new p.PointsMaterial({color:65280,size:5,depthTest:!1}),Ia=new p.PointsMaterial({color:65280,depthTest:!1}),Ba=new p.PointsMaterial({color:65280,depthTest:!1}),P1=c=>c.viewDirectionFromTarget!==void 0,A1=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 sc.decode(s)}}}return null},ka=(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)},Da=(c,t,e)=>({x:c.x+t*Math.cos(e),y:c.y+t*Math.sin(e)}),I1=(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=Da(c,a,ka(s,n)+(Math.PI/2-r/2));i=i||Math.max(Math.abs(Math.ceil(r/(Math.PI/18))),6);const l=ka(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=Da(o,Math.abs(a),l+h*u);d.push(new p.Vector3(f.x,f.y,0))}return d},La=(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{const a=Math.max(2,Math.round(i));for(let o=0;o<=a;o++){const l=Oo(o/a,t,r,e,s);n.push(new p.Vector3(l[0],l[1],0))}}catch{if(n.length===0)return n}return n},Nn=(c,t=!1)=>{const e=[],i=c.length;for(let s=0;s<i;s++){const n=c[s];if(!(!Number.isFinite(n.x)||!Number.isFinite(n.y)))if(n.bulge&&(s!==i-1||t)){const r=n.bulge,a=s+1<i?c[s+1]:e[0],o=I1(n,a,r);Number.isFinite(a.x)&&Number.isFinite(a.y)?e.push(...o):e.push(new p.Vector3(n.x,n.y,0))}else e.push(new p.Vector3(n.x,n.y,0))}return e},B1=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},k1=c=>{const t=[],e=[];c.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new p.Vector3(s.x,s.y,s.z)):e.push(B1(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},j=class j extends p.Loader{constructor(e,i){super(e);x(this,"timer");x(this,"ignorePaperSpace");x(this,"font");x(this,"encoding");x(this,"overrideColor");x(this,"overrideHatchPatternLineThickness");x(this,"angBase");x(this,"angDir");x(this,"header");x(this,"pointsMaterials");x(this,"lineBasicMaterials");x(this,"lineShaderMaterials");x(this,"meshBasicMaterials");x(this,"meshTextureMaterials");x(this,"hatchShaderMaterials");x(this,"entityCount");x(this,"curveCount");x(this,"averageCurveSize");x(this,"enableRenderOrder");x(this,"enableLocalCache");x(this,"enableReleaseData");x(this,"enableMerge");x(this,"enableRTC");x(this,"enablePlineWidth");x(this,"dxfDataId");x(this,"compareContext");x(this,"statsInfo");x(this,"llbDatas");x(this,"mtextDatas");x(this,"requestHeader");x(this,"blockReferencesCache");x(this,"blockRecordsCache");x(this,"entitiesCache");x(this,"blocksCache");x(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");x(this,"spatialFiltersCache");x(this,"entityThreejsCache");x(this,"entitiesByHandleIndex");x(this,"entitiesByHandleIndexData");x(this,"entityTypesAndTimes");x(this,"nonSnapableTypes");x(this,"layoutsSnapObjectsMap");x(this,"aborted");x(this,"entityHandlesWithRenderOrder");x(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=j.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.requestHeaders&&(this.requestHeader=i.requestHeaders),i.overrideColor!=null&&(this.overrideColor=Di.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[Ft]=js,this.lineBasicMaterials[Ft]=ye,this.meshBasicMaterials[Ft]=yi}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=A1(e);if(!s){const n=Date.now(),r=new p.FileLoader(this.manager);this.requestHeader&&Object.keys(this.requestHeader).length>0&&r.setRequestHeader(this.requestHeader),r.setResponseType("arraybuffer"),r.setPath(this.path),s=await r.loadAsync(e,i),A.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=N.getUpdateSubProgressFunc(0,50,i),n=N.getUpdateSubProgressFunc(50,100,i),r=N.getUpdateSubProgressFunc(10,100,i);if(ke.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),A.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){A.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=N.getUpdateProgressFunc(i),n=N.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(),A.info("[Dxf] Start parsing...");const a=new Lo(this.encoding).parseSync(r);if(this.tryFixDxfData(a),s(80),A.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&ke.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),A.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){A.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){A.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&A.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&&(A.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(A.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:j.MODEL_LAYOUT_NAME}]),!e.tables&&(A.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(b=>{this.entityCount+=e.blocks[b].entities?.length||0});const a=N.getUpdateProgressFuncForLoop(r,i);let o={};const l=b=>{const C=b.userData.layerName;let S=o[C];!S&&(S=[],o[C]=S),S.push(b)},h={},d={},u=new U;for(let b=0;b<r&&!this.aborted;b++){const C=e.entities[b];this.addViewport(C,h);const S=this.loadEntity(C,e);if(!S&&await a(b),!S)continue;const O=this.getLayout(e,C),E=O.layoutName;let v=u.children.find(T=>T.name===E);if(!v&&(v=new U,v.name=E,v.userData.isLayoutLevelObject=!0,u.add(v)),S.traverse(T=>{T.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[E]&&(this.layoutsSnapObjectsMap[E]=[]),this.layoutsSnapObjectsMap[E].push(T))}),this.enableMerge){Tt.merge(S,!1),!d[E]&&(d[E]={object:v,layerObjects:{}});const _=d[E];if(S.geometry){const P=S.userData.layerName;!_.layerObjects[P]&&(_.layerObjects[P]=[]),_.layerObjects[P].push(S),S.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else S.children.length>0&&(v.add(S),S.traverse(P=>{P.geometry&&l(P)}))}else v.add(S),S.traverse(T=>{T.geometry&&l(T)});n++,await a(b)}e.objects.LAYOUT.forEach(b=>{const C=b,S=C.layoutName;if(this.ignorePaperSpace&&S!==j.MODEL_LAYOUT_NAME)return;const O=C.associatedBlockName,E=e.blocks[O];E&&this.loadLayout(E,e,C,u,o,h)}),A.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const b in this.layoutsSnapObjectsMap){const C=u.children.find(E=>E.name===b),S=new U;S.name=j.SNAP_GROUP_NAME,S.userData.isSnapGroup=!0,C.add(S);const O=this.layoutsSnapObjectsMap[b];for(let E=0;E<O.length;E++){const v=O[E],T=v.userData.layerName;this.getLayerVisible(e,T)===!1&&v.layers.disable(Ge),j.SHOW_SNAP_OBJECT&&(v.layers.enableAll(),v.material instanceof p.PointsMaterial?v.material=Aa:v.material instanceof p.LineBasicMaterial?v.material=Ia:v.material instanceof p.MeshBasicMaterial&&(v.material=Ba));let _=v;const P=fe.identity();for(;_&&_.userData.isLayoutLevelObject!==!0;)P.premultiply(_.matrix),_=_.parent;v.matrix.copy(P),S.add(v)}}if(this.enableMerge)for(const b in d){const C=d[b],S=C.object;for(const O in C.layerObjects){const E=C.layerObjects[O],v=Tt.deepMerge(E,void 0,!1,!1,!0),T=v.added,_=v.removed;if(_.length!==E.length){let P=_;_.length>=100&&(P=new Set(_));const I=B=>Array.isArray(P)?P.indexOf(B)>=0:P.has(B);for(let B=0,k=E.length;B<k;B++){const D=E[B];!I(D)&&(S.add(D),l(D))}}for(let P=0;P<T.length;P++){const I=T[P];S.add(I),l(I)}C.layerObjects[O]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&j.mergeDxfObjects({root:u,layersAndObjects:o});const m=u.convertToThreejsObject();u.clear(),o={};const y={};e.objects.LAYOUT.forEach(b=>{const C=b;y[C.layoutName]=C});const g={},M=b=>{const C=b.userData.layerName;let S=g[C];!S&&(S=[],g[C]=S),S.push(b)};m.children.forEach(b=>{if(Q.setSharedVariablesOfObject(b),!b.userData.isLayoutLevelObject)return;const C=b.name;let S;if(C!==j.MODEL_LAYOUT_NAME){const O=y[C];!O.directAssociatedLeafObjectSet&&(O.directAssociatedLeafObjectSet=new Set),S=O.directAssociatedLeafObjectSet}b.traverse(O=>{if(Q.setSharedVariablesOfObject(O),O.userData.isSnapGroup&&(O.visible=j.SHOW_SNAP_OBJECT),O.geometry){const E=O.userData.layerName;this.getLayerVisible(e,E)===!1&&(O.visible=!1,O.userData.layerVisible=!1),M(O),S&&S.add(O)}})}),A.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const w=Object.assign(Object.assign({},e),{threejsObject:m,layersAndThreejsObjects:g,loadedEntityCount:n,layoutViewportsMap:h});if(j.LOADLLDATA){const b=m.children[0].children,C=[];for(let S=0;S<b.length;S++){const O=b[S];if(O?.userData?.llbData){const E=new p.Box3().setFromObject(O);E.getSize(new p.Vector3);const v=E.getCenter(new p.Vector3);C.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);C.push({...v,boundingBox:{max:T.max,min:T.min,center:_}})}}}w.llbMesh=C}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)}A.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 U,y=u?a:o;this.entityCount=y,Object.keys(f.blocks).forEach(v=>{this.entityCount+=f.blocks[v].entities?.length||0});const g=Math.round(Math.pow(y,.5));let M=Date.now();const w=async v=>{if(r&&(v%g===0||v===y-1)){let T=v+1;!u&&(T+=a),r(new ProgressEvent("parseProgress",{loaded:T,total:a+o}));const _=500,P=Date.now();(P-M>_||v===y-1)&&(await N.sleep(0),M=P)}};this.parseHeader(f.header);let b={};for(let v=0;v<y;v++){if(this.aborted)return;const T=f.entities[v],_=this.getLayout(f,T);if(_.layoutName!==j.MODEL_LAYOUT_NAME){await w(v);continue}const P=this.loadEntity(T,f);if(!P){await w(v);continue}let I=m.children.find(B=>B.name===j.MODEL_LAYOUT_NAME);!I&&(I=new U,I.name=j.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,m.add(I)),I.add(P),P.traverse(B=>{if(B.geometry){const k=B.userData.layerName,D=this.getLayerVisible(f,k);B.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[_.layoutName]&&(this.layoutsSnapObjectsMap[_.layoutName]=[]),this.layoutsSnapObjectsMap[_.layoutName].push(B),D===!1&&P.layers.disable(Ge));let z=b[k];!z&&(z=[],b[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===He.Added||T.type===He.Modified)&&(d.preservedHandles?.add(T.handle),T.parentHandles&&T.parentHandles.forEach(P=>d.preservedHandles?.add(P)));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:He.NoChange});continue}_=this.setObjectColorByChange(_,T)}if(T.type!==He.NoChange&&_){let P=_.parent;const I=fe.identity();for(;P&&P.userData.isLayoutLevelObject!==!0;)I.premultiply(P.matrix),P=P.parent;ft.makeEmpty();const B=U.getBox(_,ft);B.applyMatrix4(I),T.type===He.Added?!u&&(T.box=new p.Box3().copy(B)):T.type===He.Removed?u&&(T.box=new p.Box3().copy(B)):T.type===He.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 U;_.name=j.SNAP_GROUP_NAME,T.add(_);const P=this.layoutsSnapObjectsMap[v];for(let I=0;I<P.length;I++){const B=P[I];j.SHOW_SNAP_OBJECT&&(B.layers.enableAll(),B.material instanceof p.PointsMaterial?B.material=Aa:B.material instanceof p.LineBasicMaterial?B.material=Ia:B.material instanceof p.MeshBasicMaterial&&(B.material=Ba));let k=B;const D=fe.identity();for(;k&&k.userData.isLayoutLevelObject!==!0;)D.premultiply(k.matrix),k=k.parent;B.matrix.copy(D),_.add(B)}}this.enableMerge&&j.mergeDxfObjects({root:m,layersAndObjects:b});const C=m.convertToThreejsObject();m.clear(),b={};const S={},O=v=>{const T=v.userData.layerName;let _=S[T];!_&&(_=[],S[T]=_),_.push(v)};C.children.forEach(v=>{Q.setSharedVariablesOfObject(v),v.userData.isLayoutLevelObject&&v.traverse(T=>{if(Q.setSharedVariablesOfObject(T),T.userData.isSnapGroup&&(T.visible=j.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=C,E.layersAndThreejsObjects=S,E.layoutViewportsMap={}};let h=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},N.printMemory("Before loading entities for first dxf"),await l(),A.info("[Dxf] loadEntities for first dxf in "+(Date.now()-h)/1e3+"s"),N.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),N.printMemory("Before loading entities for second dxf"),h=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),A.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)),N.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=ct.ENTITY_COLOR_NO_CHANGE;return a.type===He.Added?o=ct.ENTITY_COLOR_ADDED:a.type===He.Removed?o=ct.ENTITY_COLOR_REMOVED:a.type===He.Modified&&(o=this.compareContext?.isTheFirstFile?ct.ENTITY_COLOR_REMOVED:ct.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();j.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)&&ss.includes(e.type)&&(n=!0),!n&&this.compareContext&&this.compareContext.preservedHandles&&!ss.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.type==="ATTDEF"&&!s)){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){if(!this.entitiesByHandleIndex||this.entitiesByHandleIndexData!==i){this.entitiesByHandleIndexData=i,this.entitiesByHandleIndex=new Map;for(let m=0;m<i.entities.length;m++){const y=i.entities[m];y.handle&&this.entitiesByHandleIndex.set(y.handle,{entity:y,index:m})}}if(e.ownerHandle){const m=this.entitiesByHandleIndex.get(e.ownerHandle);m?.entity.type==="INSERT"&&(s=m.entity)}if(!s){const m=e.handle?this.entitiesByHandleIndex.get(e.handle):void 0;if(m)for(let y=m.index-1;y>=0;y--){const g=i.entities[y];if(g.type==="INSERT"){s=g;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),m=e.zdysx;let y;if(m)try{y=JSON.parse(m)}catch{y=m}const g=e.type==="ATTRIB";if(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,!g&&y!==void 0&&(M.userData.xdata=y),this.setMaterial(M,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(M=>{M.layers.disable(Ge)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16))),e.type==="INSERT"&&!s&&!this.enableRenderOrder){const M=e.block?i.blocks[e.block]?.entities:void 0;let w=!0;if(M?.length)for(const O of M){const E=O;if(E.type==="ATTDEF"||E.type==="SEQEND")continue;if(!(E.type==="LINE"||E.type==="SPLINE"||(E.type==="LWPOLYLINE"||E.type==="POLYLINE")&&!E.shape)){w=!1;break}}else w=!1;const b=Math.min(parseInt(e.handle,16)||0,3999),C=w?be.InsertLine+b*1e-5:be.InsertSymbol+b*1e-4,S=!w&&M?.length?new Map(M.map((O,E)=>[O.type!=="HATCH"&&O.type!=="SOLID"?void 0:O.handle,E]).filter(([O])=>O!==void 0)):void 0;o.traverse(O=>{if(O.geometry&&O.renderOrder<be.Text&&(O.renderOrder=S?.has(O.userData.handle)?C-5e-5+S.get(O.userData.handle)*5e-7:C,w)){const E=O.geometry.getAttribute("position");if(E){let v=!1;for(let T=0;T<E.count;T++)E.getZ(T)!==0&&(E.setZ(T,0),v=!0);v&&(E.needsUpdate=!0,O.geometry.computeBoundingBox(),O.geometry.computeBoundingSphere())}}})}}const h=e.type,d=e.handle,u=ss.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),V.areNumbersEqual(n,r,1e-5))return A.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=V.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),y=d.getPoints(m),g=[],M=y.length;for(let E=0;E<M-1;E++)V.areVector2sEqual(y[E],y[E+1],1e-9)||g.push(y[E]);if(g.push(y[M-1]),g.length<2)return A.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const w=new p.Vector3;let b=!1;this.enableRTC&&(b=G.checkAndRebasePositionsOnRTC(g,w));const C=new p.BufferGeometry().setFromPoints(g),S=new U(q.Line);S.geometry=C,S.material=ye;const O=new U(q.Point);return O.geometry=_a,O.material=js,O.matrix.setPosition(e.center.x,e.center.y,e.center.z),O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(Ge),S.add(O),b&&(this.setRTCUserData(S),S.matrix.setPosition(w.x,w.y,0)),S.layers.enableAll(),S}loadMText(e,i,s){if(!e.text)return;if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] MText (handle '%s') has non-finite placement, ignored!",e.handle),void 0;if(!this.font)return A.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ns(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose($,xe,rt),e.position&&($.x+=e.position.x,$.y+=e.position.y,o.matrix.compose($,xe,rt)),ft.makeEmpty();const l=U.getBox(o,ft),h=l.getSize(H),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,y=0;switch(e.attachmentPoint){case 1:m=0,y=0;break;case 2:m-=d/2,y=0;break;case 3:m-=d,y=0;break;case 4:m=0,y+=f/2;break;case 5:m-=d/2,y+=f/2;break;case 6:m-=d,y+=f/2;break;case 7:m=0,y+=f;break;case 8:m-=d/2,y+=f;break;case 9:m-=d,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=u;break;case 4:break;case 5:break;default:return}o.traverse(_=>{_.geometry&&_.geometry.translate(m,y,0),_.layers.enableAll()});let g=0;if(e.rotation&&(g=e.rotation*Math.PI/180),e.directionVector){const _=e.directionVector,P=new p.Vector3(_.x,_.y,_.z),I=P.clone().cross(Ze),B=Ze.angleTo(P);g=I.z>0?-B:B}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(o),o.matrix.compose($,xe,rt);const M=e.position?$.clone().sub(e.position):$;nt.makeTranslation(-M.x,-M.y,0),fe.makeRotationZ(g),o.matrix.multiply(nt),o.matrix.multiply(fe),o.matrix.multiply(nt.invert()),o.userData||(o.userData={});const w=o.matrix.elements,b=w&&w[12]||0,C=w&&w[13]||0,S=w&&w[14]||0,O=new p.Box3;U.getBox(o,O);const E=new p.Vector3;O.getCenter(E);const v=new p.Vector3;O.getSize(v),o.userData.renderArea={position:{x:b,y:C,z:S},bbox:{min:{x:O.min.x,y:O.min.y,z:O.min.z},max:{x:O.max.x,y:O.max.y,z:O.max.z},center:{x:E.x,y:E.y,z:E.z},width:v.x,height:v.y,depth:v.z},textSize:{width:d,height:u},rotation:g,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const T=this;return o.userData.textContent=e.text||"",o.userData.cleanText=T.cleanMTextContent?T.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(_=>{_.geometry&&(_.userData.textContent=e.text||"",_.userData.dxfType="MTEXT",_.userData.layer=e.layer||"0",_.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return A.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ns(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose($,xe,rt),e.position&&($.x+=e.position.x,$.y+=e.position.y,o.matrix.compose($,xe,rt)),ft.makeEmpty();const l=U.getBox(o,ft),h=l.getSize(H),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,y=0;switch(e.attachmentPoint){case 1:m=0,y=0;break;case 2:m-=d/2,y=0;break;case 3:m-=d,y=0;break;case 4:m=0,y+=f/2;break;case 5:m-=d/2,y+=f/2;break;case 6:m-=d,y+=f/2;break;case 7:m=0,y+=f;break;case 8:m-=d/2,y+=f;break;case 9:m-=d,y+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:y+=u;break;case 4:break;case 5:break;default:return}o.traverse(w=>{w.geometry&&w.geometry.translate(m,y,0),w.layers.enableAll()});let g=0;if(e.rotation&&(g=e.rotation*Math.PI/180),e.directionVector){const w=e.directionVector,b=new p.Vector3(w.x,w.y,w.z),C=b.clone().cross(Ze),S=Ze.angleTo(b);g=C.z>0?-S:S}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(o),o.matrix.compose($,xe,rt);const M=e.position?$.clone().sub(e.position):$;return nt.makeTranslation(-M.x,-M.y,0),fe.makeRotationZ(g),o.matrix.multiply(nt),o.matrix.multiply(fe),o.matrix.multiply(nt.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 S=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[S]&&(this.statsInfo.unsupportedTextStyles[S]=0),this.statsInfo.unsupportedTextStyles[S]++}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 U;let m,y=s.fontFile,g=1,M=1,w=256,b=h*.8,C=b+h;for(let S=0;S<e.length;S++){const O=e[S];if(typeof O=="string"){const E=[],v=(P,I)=>{let B;if(P.forEach((k,D)=>{!k.boundingBox&&k.computeBoundingBox(),D===0?B=k.boundingBox:B.union(k.boundingBox)}),B)switch(d){case"Left":break;case"Center":P.forEach(k=>k.translate((u-I)/2,0,0));break;case"Right":P.forEach(k=>k.translate(u-I,0,0));break}E.push(...P)};let T;for(let P=0;P<O.length;P++){const I=O[P];if(I===`
|
|
794
|
-
`){const k=a;a=0,o-=C,l.length>0&&v(l,k),l=[];continue}if(b=h*.8,C=b+h,T=this.font?.getCharShape(I,y,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+M*(h/3.5);continue}a>(u||1/0)&&(l.length>0&&v(l,a),a=0,o-=C,l=[]),T.translate(a,o,0),T.scale(g,1,1),T.boundingBox||T.computeBoundingBox(),O.T&&(M=O.T);const B=td(I,T,h,M,y);a+=B,l.push(T)}l.length>0&&(v(l,a),l=[]);const _=new U;if(E.length>0){!m&&(m=i.colorIndex),w!==void 0&&w!==256?(i.color=oi(w),i.colorIndex=w):i.colorIndex=m;const P=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 U(q.Mesh);k.geometry=Ae.mergeGeometries(I),k.material=this.getMeshBasicMaterial(P),_.add(k)}if(B.length>0){const k=new U(q.LineSegment);k.geometry=Ae.mergeGeometries(B),k.material=this.getLineBasicMaterial(P),_.add(k)}}_.matrix.makeTranslation(0,-h,0),f.add(_),g=1,M=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&&(y=O.f,y&&y.includes(".shx")&&A.info("[Dxf] Doesn't support custom fonts: "+y)),O.C&&(w=O.C),O.W&&(O.W[1]==="x"?g=O.W[0]*i.width:g=O.W[0]),O.H&&(O.H[1]==="x"?h=O.H[0]*i.height:h=O.H[0]),O.T&&(M=O.T))}if(f.children.length!==0)return Tt.merge(f,!1),m&&(i.colorIndex=m),f.children.length===1?{object:f.children[0],hOffset:a,vOffset:o}:{object:f,hOffset:a,vOffset:o}}mtextContentAndFormattingToTextAndStyle(e,i){const s={horizontalAlignment:"",textHeight:i.height||i.contextData&&i.contextData.textHeight},n={};let r=1;const a=[];for(let o=0;o<e.length;o++){const l=e[o];if(typeof l=="string"){if(l.startsWith("\\pxq")&&l.endsWith(";"))l.indexOf("c")!==-1?s.horizontalAlignment="center":l.indexOf("l")!==-1?s.horizontalAlignment="left":l.indexOf("r")!==-1?s.horizontalAlignment="right":l.indexOf("j")!==-1&&(s.horizontalAlignment="justify");else if(!l.startsWith("pi")){if(!l.startsWith("pxt")){if(!l.startsWith("pt")){const h=this.getTextLineNum(l);a.push({font:n.f,colorIndex:n.C,text:l,lineNum:r}),r+=h}}}}else if(Array.isArray(l)){const h=this.mtextContentAndFormattingToTextAndStyle(l,i);h.text.forEach(d=>{a.push(d)}),r=h.lineLength}else if(typeof l=="object")if(l.S&&l.S.length===3){const h=l.S[0]+"/"+l.S[2],d=this.getTextLineNum(h);a.push({text:l.S[0]+"/"+l.S[2],lineNum:r}),r+=d}else l.C!==void 0?n.C=l.C:l.W!==void 0?n.W=l.W:l.H!==void 0?n.H=l.H:l.f!==void 0&&(n.f=l.f)}return{text:a,lineLength:r,style:s}}getTextLineNum(e){const i=e.match(new RegExp("\\n","g"));return i?i.length:0}load3DFace(e){if(!e.vertices||e.vertices.length===0)return A.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;!V.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new p.Vector3;let n=!1;this.enableRTC&&(n=G.checkAndRebasePositionsOnRTC(i,s));const r=new p.BufferGeometry().setFromPoints(i),a=new U(q.Line);return a.geometry=r,a.material=ye,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 A.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=La(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,d),f=new p.Vector3;let m=!1;this.enableRTC&&(m=G.checkAndRebasePositionsOnRTC(u,f));const y=G.getAdjacentNonRepeatPoints(u);if(y.length<2)return A.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const g=new p.BufferGeometry().setFromPoints(y),M=new U(q.Line);return M.geometry=g,M.material=ye,m&&(this.setRTCUserData(M),M.matrix.setPosition(f.x,f.y,0)),M.layers.enableAll(),M}loadXLine(e){if(!e.vertices||e.vertices.length===0)return A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=N.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=G.checkAndRebasePositionsOnRTC(n,r));const o=new p.BufferGeometry().setFromPoints(n),l=new U(q.Line);return l.geometry=o,l.material=ye,l.userData.isConstructionLine=!0,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 A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=N.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=G.checkAndRebasePositionsOnRTC(s,n));const a=new p.BufferGeometry().setFromPoints(s),o=new U(q.Line);return o.geometry=a,o.material=ye,o.userData.isConstructionLine=!0,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){A.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=k1(e.vertices);else{const h=Nn(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];V.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&&G.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(b=>{a?d.push(new p.Vector3(b.x-r.x,b.y-r.y,b.z-r.z)):d.push(b.clone())});for(let b=1;b<w.length;b++)u.push(f+b-1,f+b);f+=w.length});const m=this.getLineType(e,i),y=i.tables?.lineType?.lineTypes?.[m],g=new p.BufferGeometry().setFromPoints(d);let M=ye;if(y&&h(y)){let w=function(O){const E=O.attributes.position,v=E.count,T=new Float32Array(v);for(let _=0;_<v;_+=2){const P=_*3,I=(_+1)*3,B=E.array[I]-E.array[P],k=E.array[I+1]-E.array[P+1],D=E.array[I+2]-E.array[P+2],z=Math.sqrt(B*B+k*k+D*D);T[_]=_===0?0:T[_-1],T[_+1]=T[_]+z}O.setAttribute("lineDistance",new p.Float32BufferAttribute(T,1))};const b=y.pattern?.[0]||.5,C=y.pattern?.[1]||.5,S=.1;M=new p.LineDashedMaterial({color:ye.color,linewidth:ye.linewidth||1,dashSize:b*S,gapSize:C*S,scale:S}),w(g)}else g.setIndex(u);l=new U(q.LineSegment),l.geometry=g,l.material=M}if(n.length>0){a&&G.checkAndRebasePositionsOnRTC(n,r);const h=new p.BufferGeometry().setFromPoints(n),d=new U(q.Point);d.geometry=h,d.material=js,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){A.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){H.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const y=j.getOcsMatrix(H).invert(),g=e.elevation!==void 0?e.elevation:0;n.forEach(M=>{H.set(M.x,M.y,g).applyMatrix4(y),M.x=H.x,M.y=H.y})}let r=Nn(n,e.shape);if(e.shape&&r.length>0&&!V.areVector3sEqual(r[0],r[r.length-1])&&r.push(r[0]),r.length<2){A.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new U;const o=e.extendedData;if(o?.outlines){const y=o.outlines,g=[];y.forEach(b=>{const C=new p.Shape;b.forEach((S,O)=>{O===0?C.moveTo(S[0],S[1]):C.lineTo(S[0],S[1])}),C.closePath(),g.push(new p.ShapeGeometry(C))});const M=Ae.mergeGeometries(g),w=new U(q.Mesh);w.geometry=M,w.material=yi,w.layers.enableAll(),w.layers.disable(Ge),a.add(w)}let l=!1;const h=new p.Vector3;this.enableRTC&&(l=G.checkAndRebasePositionsOnRTC(r,h));const d=G.getAdjacentNonRepeatPoints(r);if(d.length<2){A.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const u=e.constantWidth,f=d.length>2&&V.areVector3sEqual(d[0],d[d.length-1]);if(this.enablePlineWidth&&!f){const y=n.some(g=>g.startWidth!==void 0||g.endWidth!==void 0);if(y||u!==void 0&&u>0){let g;const M=i.tables?.lineType?.lineTypes,w=this.getLineType(e,i,s),b=M?.[w];if(!b||!b.pattern||b.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,y?g=this.createTaperedPolylineGeometry(n,u):g=G.convertWidthLineToMeshGeometry(d,u),!g)A.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const C=new U(q.Mesh);C.geometry=g,C.material=yi,C.layers.enableAll(),C.layers.disable(Ge),a.add(C);const S=Q.createOutline(g,ye,C.matrix),O=new U(q.LineSegment);O.geometry=S.geometry,O.material=S.material,O.matrix=S.matrix,O.layers.enableAll(),O.layers.disable(Ge),a.add(O)}}}const m=new U(q.Line);return m.geometry=new p.BufferGeometry().setFromPoints(d),m.material=ye,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(h)),a}createTaperedPolylineGeometry(e,i){if(!e||e.length<2)return null;const s=[],n=[];for(let a=0;a<e.length-1;a++){const o=e[a],l=e[a+1],h=l.x-o.x,d=l.y-o.y,u=Math.hypot(h,d);if(u===0)continue;const f=o.startWidth??i??0,m=o.endWidth??i??0;if(f<=0&&m<=0)continue;const y=-d/u,g=h/u,M=f/2,w=m/2,b={x:o.x+y*M,y:o.y+g*M},C={x:o.x-y*M,y:o.y-g*M},S={x:l.x+y*w,y:l.y+g*w},O={x:l.x-y*w,y:l.y-g*w},E=s.length/3;s.push(b.x,b.y,0,C.x,C.y,0,S.x,S.y,0,O.x,O.y,0),n.push(E,E+1,E+2),n.push(E+1,E+3,E+2)}if(!n.length)return null;const r=new p.BufferGeometry;return r.setAttribute("position",new p.Float32BufferAttribute(s,3)),r.setIndex(n),r}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 U,o=ns(r),l=this.getTextStyle(i,e),h=this.getMTextGroup(o,e,l,i,s),d=h&&h.object;if(d){d.matrix.decompose($,xe,rt),e.contextData?.textLocation&&($.x+=e.contextData.textLocation.x,$.y+=e.contextData.textLocation.y,d.matrix.compose($,xe,rt)),ft.makeEmpty();const u=U.getBox(d,ft),f=u.getSize(H),m=f.x,y=f.y;let g=0,M=0;switch(e.contextData?.textAttachment){case 1:g=0,M=0;break;case 2:g-=m/2,M=0;break;case 3:g-=m,M=0;break;case 4:g=0,M+=y/2;break;case 5:g-=m/2,M+=y/2;break;case 6:g-=m,M+=y/2;break;case 7:g=0,M+=y;break;case 8:g-=m/2,M+=y;break;case 9:g-=m,M+=y;break;default:return}d.traverse(C=>{C.geometry&&C.geometry.translate(g,M,0)});let w=0;if(e.contextData?.textRotation&&(w=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const C=e.contextData.textDirection,S=new p.Vector3(C.x,C.y,C.z),O=S.clone().cross(Ze),E=Ze.angleTo(S);w+=O.z>0?-E:E}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(d),d.matrix.compose($,xe,rt),e.contextData?.textLocation?H.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):H.set(0,0,0);const b=$.clone().sub(H);nt.makeTranslation(-b.x,-b.y,0),fe.makeRotationZ(w),d.matrix.multiply(nt),d.matrix.multiply(fe),d.matrix.multiply(nt.invert()),d.renderOrder=be.Text,a.add(d)}if(e.leaderLineType!==0){const u=[],f=e.contextData?.leaders[0];if(!f)return a;const m=f.lastLeaderLinePoint;if(!m)return a;if(e.enableDogLeg&&f.doglegVector){const C=new p.Vector3(m.x,m.y,m.z),S=f.doglegLength,O=new p.Vector3(f.doglegVector.x,f.doglegVector.y,f.doglegVector.z),E=O.multiplyScalar(S),v=C.clone().add(E);u.push(v,C)}const y=e.contextData?.leaders[0].leaderLines||[];for(let C=0;C<y.length;C++){const S=y[C].vertices?.[0];if(!S||S.length===0)continue;const O=S.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];if(u.length<2)continue;const v=H.subVectors(u[0],u[1]).length(),T=e.arrowHeadSize||n.DIMASZ||2.5,_=e.arrowHeadScale||n.DIMSCALE||1,P=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 D=this.loadEntity(B.entities[k],i,e);if(D){const z=new p.Vector3(u[u.length-1].x,u[u.length-1].y,u[u.length-1].z),se=new p.Vector3(u[u.length-2].x,u[u.length-2].y,u[u.length-2].z),re=Math.atan2(z.y-se.y,z.x-se.x);H.copy(z),$.setScalar(P),xe.setFromAxisAngle(gi,re),D.matrix.compose(H,xe,$),a.add(D)}}}else this.loadDefaultLeadArrow(u[u.length-2],u[u.length-1],v/2e3,u)}const g=new p.Vector3;let M=!1;this.enableRTC&&(M=G.checkAndRebasePositionsOnRTC(u,g));const w=new p.BufferGeometry().setFromPoints(u),b=new U(q.LineSegment);b.geometry=w,b.material=ye,b.renderOrder=be.Line,M&&(this.setRTCUserData(b),b.matrix.setPosition(g.x,g.y,0)),a.add(b)}else return d?.traverse(u=>{u.layers.enableAll()}),d;return Tt.merge(a,!1),a.traverse(u=>{u.layers.enableAll()}),a.children.length===1?a.children[0]:a}loadLeader(e,i,s){const n=[];if(!e.vertices)return A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return A.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 M=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 b=new p.Vector3(1,0,0).multiplyScalar(M);a.push(b.add(w))}else{const b=new p.Vector3(-1,0,0).multiplyScalar(M);a.push(b.add(w))}}for(let M=0;M<a.length-1;M++){const w=a[M],b=a[M+1];n.push(w,b)}const o=H.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 U;if(e.arrowFlag===1){let M="";e.arrowHeadBlockHandle?M=e.arrowHeadBlockHandle:r&&r.DIMLDRBLK&&(M=r.DIMLDRBLK);const w=this.getBlockByHandle(i.blocks,M);if(w&&w.entities){r&&(e.colorIndex=r.DIMCLRD||256,e.color=oi(e.colorIndex));for(let b=0;b<w.entities.length;b++){const C=this.loadEntity(w.entities[b],i,e);if(C){const S=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(S.y-O.y,S.x-O.x);H.copy(S),$.setScalar(d),xe.setFromAxisAngle(gi,E),C.matrix.compose(H,xe,$),u.add(C)}}}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=G.checkAndRebasePositionsOnRTC(n,f));const y=new p.BufferGeometry().setFromPoints(n),g=new U(q.Line);return g.geometry=y,g.material=ye,g.renderOrder=be.Line,m&&(this.setRTCUserData(g),g.matrix.setPosition(f.x,f.y,0)),u.children.length>0?(u.add(g),Tt.merge(u,!1),u.traverse(M=>{M.layers.enableAll()}),u.children.length===1?u.children[0]:u):(g.layers.enableAll(),g)}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){A.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){A.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){A.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){A.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const n=new U,{cells:r,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:h}=e,d=[];let u=0;for(let g=0;g<a;g++){d[g]=[];for(let M=0;M<o;M++)d[g][M]=u<r.length?r[u++]:null}for(let g=0;g<a;g++)for(let M=0;M<o;M++){const w=d[g][M];if(!w||w.mergedValue!==0)continue;let b=1,C=1;for(;g+b<a&&d[g+b][M]&&d[g+b][M].mergedValue===1;)b++;for(;M+C<o&&d[g][M+C]&&d[g][M+C].mergedValue===1;)C++;w.rowSpan=b,w.colSpan=C}const f=[0];for(let g=0;g<a;g++)f.push(f[g]-l[g]);const m=[0];for(let g=0;g<o;g++)m.push(m[g]+h[g]);const y=[];for(let g=0;g<=a;g++){let M=m[0],w=!1;for(let b=0;b<o;b++){g>0&&d[g-1][b],g<a&&d[g][b];let C=!0;if(g===0||g===a)C=!0;else{const S=this._getMergeOwner(d,g-1,b,a,o),O=this._getMergeOwner(d,g,b,a,o);C=S!==O}C?w||(w=!0,M=m[b]):w&&(y.push(new p.Vector3(M,f[g],0),new p.Vector3(m[b],f[g],0)),w=!1)}w&&y.push(new p.Vector3(M,f[g],0),new p.Vector3(m[o],f[g],0))}for(let g=0;g<=o;g++){let M=f[0],w=!1;for(let b=0;b<a;b++){g>0&&d[b][g-1],g<o&&d[b][g];let C=!0;if(g===0||g===o)C=!0;else{const S=this._getMergeOwner(d,b,g-1,a,o),O=this._getMergeOwner(d,b,g,a,o);C=S!==O}C?w||(w=!0,M=f[b]):w&&(y.push(new p.Vector3(m[g],M,0),new p.Vector3(m[g],f[b],0)),w=!1)}w&&y.push(new p.Vector3(m[g],M,0),new p.Vector3(m[g],f[a],0))}if(y.length>0){const g=new p.BufferGeometry().setFromPoints(y),M=new U(q.LineSegment);M.geometry=g,M.material=ye,M.layers.enableAll(),n.add(M)}for(let g=0;g<a;g++)for(let M=0;M<o;M++){const w=d[g][M];if(!w||w.mergedValue!==0)continue;const b=m[M],C=f[g];let S=0;for(let T=0;T<(w.colSpan||1);T++)S+=h[M+T];let O=0;for(let T=0;T<(w.rowSpan||1);T++)O+=l[g+T];w.colorIndex=e.colorIndex,w.height=w.textHeight||2.5;const E=this.getTableTextOffset(w.attachmentPoint||1,S,O);H.set(b,C,0),H.add(E),w.position=H.clone();const v=this.loadMText(w,i,s);v&&n.add(v)}if(e.blockRecordHandle){const g=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(g&&g.entities)for(const M of g.entities){M.isTable=!0;const w=this.loadEntity(M,i,e);w&&n.add(w)}}return n.matrix.decompose(H,xe,rt),H.x+=e.startPoint.x,H.y+=e.startPoint.y,n.matrix.compose(H,xe,rt),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=j.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=j.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=H.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=V.getArcAngleSpanInRadian(i,s);const r=j.transformAngleByOcsMatrix(e,i),a=j.transformAngleByOcsMatrix(e,s);let o;if(V.areNumbersClose(n,Math.PI)){n=1;const l=j.transformAngleByOcsMatrix(e,i+n);o=V.getArcAngleSpanInRadian(r,l)}else{if(V.areNumbersClose(n,Math.PI*2))return[r,r+Math.PI*2];o=V.getArcAngleSpanInRadian(r,a)}return V.areNumbersClose(n,o,1e-5)?[r,a]:[a,r]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return A.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return A.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=j.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,V.areNumbersEqual(a,o,1e-6)))return;if(!V.areNumbersClose(V.getArcAngleSpanInRadian(a,o),Math.PI*2)){const O=j.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 y=!1;this.enableRTC&&(y=G.checkAndRebasePositionsOnRTC(f,m));const g=new p.BufferGeometry().setFromPoints(f),M=new U(q.Line);M.geometry=g,M.material=ye;const w=new p.Vector3;e.center&&(w.x=e.center.x,w.y=e.center.y);const b=new p.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(r.invert());w.x=b.x,w.y=b.y;const C=w,S=new U(q.Point);return S.geometry=_a,S.material=js,S.userData.handle=e.handle,S.userData.isSnapObject=!0,S.userData.type="CircleCenter",S.layers.set(Ge),M.add(S),y?(this.setRTCUserData(M),C.x+=m.x,C.y+=m.y):G.shouldRebasePositionOnRTC(C)&&this.setRTCUserData(M),M.matrix.setPosition(C),M.layers.enableAll(),M}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){H.set(0,0,e.extrusionDirection.z);const u=j.getOcsMatrix(H).invert();n.forEach(f=>{const m=H.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=G.checkAndRebasePositionsOnRTC(r,o));const h=new p.BufferGeometry().setFromPoints(r);h.setIndex(a);const d=new U(q.Mesh);return d.geometry=h,d.material=yi,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 U,d=[];let u=0,f=0;i?.xScale;const m=n+s,y=i?.fontFile||"",g=typeof y=="string"&&y.toLowerCase().endsWith(".shx"),M=g?s*.06:s*.04,w=[];for(let S=0;S<e.length;S++){const O=e[S];O!==" "&&O!==`
|
|
793
|
+
`&&s++,i=s+1}}return e.push(t.substring(i,t.length)),e}}function Ze(c,t,e){return c.code===t&&c.value===e}function Mt(c){A.trace("unhandled group "+Ro(c))}function Ro(c){return c.code+":"+c.value}const Fo="0.4.0",zo="VERSION",S1=()=>window.localStorage.getItem(zo),E1=()=>{window.localStorage.setItem(zo,Fo)},O1=()=>S1()!==Fo?(E1(),!0):!1,si=class si{constructor(){y(this,"DATABASE_NAME","x_viewer");y(this,"DEFAULT_TABLES",[{name:"dxf_data",options:{keyPath:"dxfDataId",autoIncrement:!1}},{name:"fonts",options:{keyPath:"fileName",autoIncrement:!0}}]);y(this,"db");y(this,"tables");this.db=void 0,this.tables=this.DEFAULT_TABLES}static instance(){return!si._instance&&(si._instance=new si),si._instance}setTables(t){this.tables=t}getTables(){return this.tables}async getDatabase(){let t=await this.getDB(this.DATABASE_NAME);return this.db||(t.close(),O1()&&await this.deleteDataBase(this.DATABASE_NAME),t=await this.getUpgradedDB(t)),t.onclose=()=>{this.db=void 0,A.debug("[DB] Db "+t.name+" is closed.")},t.onerror=e=>{this.db=void 0,A.debug("[DB] Db "+t.name+" encountered error.",e)},t.onabort=e=>{this.db=void 0,A.debug("[DB] Db "+t.name+" aborted.",e)},t.onversionchange=e=>{A.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=>{A.debug(n),i(n)},s.onsuccess=n=>{const r=n.target;A.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;A.debug("[DB] Db "+r.name+" opened (version "+r.version+")."),e(r)}})}async getUpgradedDB(t){return new Promise((e,i)=>{A.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=>{A.debug("onblocked",n)},s.onupgradeneeded=n=>{const r=n.target.transaction;r.oncomplete=()=>{A.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)){A.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(()=>{A.debug("[DB] All("+o.length+") tables created.")})},s.onsuccess=n=>{const r=n.target.result;A.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})}),A.debug("[DB] Table "+e+" created."),n(t)})}};y(si,"_instance");let pe=si;class Vo{constructor(){y(this,"db");y(this,"isCreatingTable");if(this.db=void 0,this.isCreatingTable=!1,pe.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();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.add(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()}).catch(n=>{i&&i(n)})}save(t,e,i){const s=this.tableName();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.put(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()})}delete(t,e,i){const s=this.tableName();pe.instance().getDatabase().then(n=>{const r=n.transaction([s],"readwrite").objectStore(s),a=r.delete(t);a.onsuccess=e,a.onerror=i}).finally(()=>{pe.instance().closeDatabase()})}update(){pe.instance().getDatabase().then(()=>{})}query(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}queryByIndex(t,e,i,s){const n=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}queryAll(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}clearAll(t,e){const i=this.tableName();pe.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(()=>{pe.instance().closeDatabase()})}}const ni=class ni extends Vo{tableName(){return"dxf_data"}static instance(){return!ni._instance&&(ni._instance=new ni),ni._instance}query(t,e,i){const s=[],n=this.tableName();pe.instance().getDatabase().then(r=>{const a=r.transaction([n],"readonly").objectStore(n),o=a.get(t);o.onerror=l=>{i&&i(l),A.info("[DxfDataTable] Failed to query !",l)},o.onsuccess=()=>{o.result&&s.push(o.result),e&&e(s)}}).finally(()=>{pe.instance().closeDatabase()})}};y(ni,"_instance");let dn=ni;const Ke=new p.Vector3(1,0,0),jn=new p.Vector3(0,1,0),gi=new p.Vector3(0,0,1),Oa=new p.Vector3(0,0,0),Ft=16777215,P1="CONTINUOUS",js=new p.PointsMaterial({color:Ft}),ye=new p.LineBasicMaterial({color:Ft}),yi=new p.MeshBasicMaterial({color:Ft}),Pa=new p.BufferGeometry().setFromPoints([new p.Vector3]),_a=new p.Matrix4,rt=new p.Matrix4,fe=new p.Matrix4,H=new p.Vector3,$=new p.Vector3,at=new p.Vector3,Xi=new p.Vector2,xe=new p.Quaternion,Ns=new p.Object3D,pt=new p.Box3,Aa=new p.PointsMaterial({color:65280,size:5,depthTest:!1}),Ia=new p.PointsMaterial({color:65280,depthTest:!1}),Ba=new p.PointsMaterial({color:65280,depthTest:!1}),_1=c=>c.viewDirectionFromTarget!==void 0,A1=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 sc.decode(s)}}}return null},ka=(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)},Da=(c,t,e)=>({x:c.x+t*Math.cos(e),y:c.y+t*Math.sin(e)}),I1=(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=Da(c,a,ka(s,n)+(Math.PI/2-r/2));i=i||Math.max(Math.abs(Math.ceil(r/(Math.PI/18))),6);const l=ka(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=Da(o,Math.abs(a),l+h*u);d.push(new p.Vector3(f.x,f.y,0))}return d},La=(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{const a=Math.max(2,Math.round(i));for(let o=0;o<=a;o++){const l=Oo(o/a,t,r,e,s);n.push(new p.Vector3(l[0],l[1],0))}}catch{if(n.length===0)return n}return n},Nn=(c,t=!1)=>{const e=[],i=c.length;for(let s=0;s<i;s++){const n=c[s];if(!(!Number.isFinite(n.x)||!Number.isFinite(n.y)))if(n.bulge&&(s!==i-1||t)){const r=n.bulge,a=s+1<i?c[s+1]:e[0],o=I1(n,a,r);Number.isFinite(a.x)&&Number.isFinite(a.y)?e.push(...o):e.push(new p.Vector3(n.x,n.y,0))}else e.push(new p.Vector3(n.x,n.y,0))}return e},B1=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},k1=c=>{const t=[],e=[];c.forEach(s=>{s.polyfaceMeshVertex&&(s.threeDPolylineMesh?t.push(new p.Vector3(s.x,s.y,s.z)):e.push(B1(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},j=class j extends p.Loader{constructor(e,i){super(e);y(this,"timer");y(this,"ignorePaperSpace");y(this,"font");y(this,"encoding");y(this,"overrideColor");y(this,"overrideHatchPatternLineThickness");y(this,"angBase");y(this,"angDir");y(this,"header");y(this,"pointsMaterials");y(this,"lineBasicMaterials");y(this,"lineShaderMaterials");y(this,"meshBasicMaterials");y(this,"meshTextureMaterials");y(this,"hatchShaderMaterials");y(this,"entityCount");y(this,"curveCount");y(this,"averageCurveSize");y(this,"enableRenderOrder");y(this,"enableLocalCache");y(this,"enableReleaseData");y(this,"enableMerge");y(this,"enableRTC");y(this,"enablePlineWidth");y(this,"dxfDataId");y(this,"compareContext");y(this,"statsInfo");y(this,"llbDatas");y(this,"mtextDatas");y(this,"requestHeader");y(this,"blockReferencesCache");y(this,"blockRecordsCache");y(this,"entitiesCache");y(this,"blocksCache");y(this,"dictionaryOwnerHandleAndSpatialFilterHandlesCache");y(this,"spatialFiltersCache");y(this,"entityThreejsCache");y(this,"entitiesByHandleIndex");y(this,"entitiesByHandleIndexData");y(this,"entityTypesAndTimes");y(this,"nonSnapableTypes");y(this,"layoutsSnapObjectsMap");y(this,"aborted");y(this,"entityHandlesWithRenderOrder");y(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=j.LOADLLDATA?!1:i.enableMerge!==!1,this.encoding=i.encoding||"UTF-8",i.requestHeaders&&(this.requestHeader=i.requestHeaders),i.overrideColor!=null&&(this.overrideColor=Di.rgb2Hex(i.overrideColor)),i.overrideHatchPatternLineThickness!=null&&(this.overrideHatchPatternLineThickness=i.overrideHatchPatternLineThickness)),this.pointsMaterials[Ft]=js,this.lineBasicMaterials[Ft]=ye,this.meshBasicMaterials[Ft]=yi}setRequestHeader(e){this.requestHeader=e}setFont(e){this.font=e}async download(e,i){let s=A1(e);if(!s){const n=Date.now(),r=new p.FileLoader(this.manager);this.requestHeader&&Object.keys(this.requestHeader).length>0&&r.setRequestHeader(this.requestHeader),r.setResponseType("arraybuffer"),r.setPath(this.path),s=await r.loadAsync(e,i),A.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=N.getUpdateSubProgressFunc(0,50,i),n=N.getUpdateSubProgressFunc(50,100,i),r=N.getUpdateSubProgressFunc(10,100,i);if(De.isBrowser&&this.enableLocalCache&&this.dxfDataId){let l;try{if(this.timer=Date.now(),l=await this.getDxfDataFromIndexedDb(this.dxfDataId),l){this.tryFixDxfData(l),A.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){A.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=N.getUpdateProgressFunc(i),n=N.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(),A.info("[Dxf] Start parsing...");const a=new Lo(this.encoding).parseSync(r);if(this.tryFixDxfData(a),s(80),A.info("[Dxf] Parsed in "+(Date.now()-this.timer)/1e3+"s, creating entities..."),this.aborted)return Promise.reject("[Dxf] Job aborted");if(a&&De.isBrowser&&this.enableLocalCache&&this.dxfDataId){const o=Date.now();try{await this.setDxfDataToIndexedDb(this.dxfDataId,a),A.info("[Dxf] Saved to indexedDb in "+(Date.now()-o)/1e3+"s")}catch(l){A.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){A.error("[Dxf]: Invalid header!");return}this.header=e;const i=e.$ACADVER.toString();i!=="AC1032"&&A.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&&(A.warn("[Dxf] No objects found, Will add one."),e.objects={}),!e.objects.LAYOUT&&(A.warn("[Dxf] No layout defined! Will add a default 'Model' layout!"),e.objects.LAYOUT=[{layoutName:j.MODEL_LAYOUT_NAME}]),!e.tables&&(A.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(b=>{this.entityCount+=e.blocks[b].entities?.length||0});const a=N.getUpdateProgressFuncForLoop(r,i);let o={};const l=b=>{const C=b.userData.layerName;let S=o[C];!S&&(S=[],o[C]=S),S.push(b)},h={},d={},u=new U;for(let b=0;b<r&&!this.aborted;b++){const C=e.entities[b];this.addViewport(C,h);const S=this.loadEntity(C,e);if(!S&&await a(b),!S)continue;const O=this.getLayout(e,C),E=O.layoutName;let v=u.children.find(T=>T.name===E);if(!v&&(v=new U,v.name=E,v.userData.isLayoutLevelObject=!0,u.add(v)),S.traverse(T=>{T.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[E]&&(this.layoutsSnapObjectsMap[E]=[]),this.layoutsSnapObjectsMap[E].push(T))}),this.enableMerge){Ct.merge(S,!1),!d[E]&&(d[E]={object:v,layerObjects:{}});const P=d[E];if(S.geometry){const _=S.userData.layerName;!P.layerObjects[_]&&(P.layerObjects[_]=[]),P.layerObjects[_].push(S),S.children.forEach(I=>{I.userData.isSnapObject&&l(I)})}else S.children.length>0&&(v.add(S),S.traverse(_=>{_.geometry&&l(_)}))}else v.add(S),S.traverse(T=>{T.geometry&&l(T)});n++,await a(b)}e.objects.LAYOUT.forEach(b=>{const C=b,S=C.layoutName;if(this.ignorePaperSpace&&S!==j.MODEL_LAYOUT_NAME)return;const O=C.associatedBlockName,E=e.blocks[O];E&&this.loadLayout(E,e,C,u,o,h)}),A.debug("[Dxf] Drew entities in "+(Date.now()-s)/1e3+"s");for(const b in this.layoutsSnapObjectsMap){const C=u.children.find(E=>E.name===b),S=new U;S.name=j.SNAP_GROUP_NAME,S.userData.isSnapGroup=!0,C.add(S);const O=this.layoutsSnapObjectsMap[b];for(let E=0;E<O.length;E++){const v=O[E],T=v.userData.layerName;this.getLayerVisible(e,T)===!1&&v.layers.disable(qe),j.SHOW_SNAP_OBJECT&&(v.layers.enableAll(),v.material instanceof p.PointsMaterial?v.material=Aa:v.material instanceof p.LineBasicMaterial?v.material=Ia:v.material instanceof p.MeshBasicMaterial&&(v.material=Ba));let P=v;const _=fe.identity();for(;P&&P.userData.isLayoutLevelObject!==!0;)_.premultiply(P.matrix),P=P.parent;v.matrix.copy(_),S.add(v)}}if(this.enableMerge)for(const b in d){const C=d[b],S=C.object;for(const O in C.layerObjects){const E=C.layerObjects[O],v=Ct.deepMerge(E,void 0,!1,!1,!0),T=v.added,P=v.removed;if(P.length!==E.length){let _=P;P.length>=100&&(_=new Set(P));const I=B=>Array.isArray(_)?_.indexOf(B)>=0:_.has(B);for(let B=0,k=E.length;B<k;B++){const D=E[B];!I(D)&&(S.add(D),l(D))}}for(let _=0;_<T.length;_++){const I=T[_];S.add(I),l(I)}C.layerObjects[O]=[]}}this.printStatsInfo(),this.enableReleaseData&&(this.releaseCachedData(),this.releaseDxfData(e)),this.enableMerge&&j.mergeDxfObjects({root:u,layersAndObjects:o});const m=u.convertToThreejsObject();u.clear(),o={};const x={};e.objects.LAYOUT.forEach(b=>{const C=b;x[C.layoutName]=C});const g={},M=b=>{const C=b.userData.layerName;let S=g[C];!S&&(S=[],g[C]=S),S.push(b)};m.children.forEach(b=>{if(Q.setSharedVariablesOfObject(b),!b.userData.isLayoutLevelObject)return;const C=b.name;let S;if(C!==j.MODEL_LAYOUT_NAME){const O=x[C];!O.directAssociatedLeafObjectSet&&(O.directAssociatedLeafObjectSet=new Set),S=O.directAssociatedLeafObjectSet}b.traverse(O=>{if(Q.setSharedVariablesOfObject(O),O.userData.isSnapGroup&&(O.visible=j.SHOW_SNAP_OBJECT),O.geometry){const E=O.userData.layerName;this.getLayerVisible(e,E)===!1&&(O.visible=!1,O.userData.layerVisible=!1),M(O),S&&S.add(O)}})}),A.info("[Dxf] loadEntities() done in "+(Date.now()-s)/1e3+"s");const w=Object.assign(Object.assign({},e),{threejsObject:m,layersAndThreejsObjects:g,loadedEntityCount:n,layoutViewportsMap:h});if(j.LOADLLDATA){const b=m.children[0].children,C=[];for(let S=0;S<b.length;S++){const O=b[S];if(O?.userData?.llbData){const E=new p.Box3().setFromObject(O);E.getSize(new p.Vector3);const v=E.getCenter(new p.Vector3);C.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 P=T.getCenter(new p.Vector3);C.push({...v,boundingBox:{max:T.max,min:T.min,center:P}})}}}w.llbMesh=C}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)}A.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 U,x=u?a:o;this.entityCount=x,Object.keys(f.blocks).forEach(v=>{this.entityCount+=f.blocks[v].entities?.length||0});const g=Math.round(Math.pow(x,.5));let M=Date.now();const w=async v=>{if(r&&(v%g===0||v===x-1)){let T=v+1;!u&&(T+=a),r(new ProgressEvent("parseProgress",{loaded:T,total:a+o}));const P=500,_=Date.now();(_-M>P||v===x-1)&&(await N.sleep(0),M=_)}};this.parseHeader(f.header);let b={};for(let v=0;v<x;v++){if(this.aborted)return;const T=f.entities[v],P=this.getLayout(f,T);if(P.layoutName!==j.MODEL_LAYOUT_NAME){await w(v);continue}const _=this.loadEntity(T,f);if(!_){await w(v);continue}let I=m.children.find(B=>B.name===j.MODEL_LAYOUT_NAME);!I&&(I=new U,I.name=j.MODEL_LAYOUT_NAME,I.userData.isLayoutLevelObject=!0,m.add(I)),I.add(_),_.traverse(B=>{if(B.geometry){const k=B.userData.layerName,D=this.getLayerVisible(f,k);B.userData.isSnapObject&&(!this.layoutsSnapObjectsMap[P.layoutName]&&(this.layoutsSnapObjectsMap[P.layoutName]=[]),this.layoutsSnapObjectsMap[P.layoutName].push(B),D===!1&&_.layers.disable(qe));let z=b[k];!z&&(z=[],b[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===Ge.Added||T.type===Ge.Modified)&&(d.preservedHandles?.add(T.handle),T.parentHandles&&T.parentHandles.forEach(_=>d.preservedHandles?.add(_)));let P=this.entityThreejsCache&&this.entityThreejsCache[T.handle];if(T.parentHandles&&(P=this.entityThreejsCache&&this.entityThreejsCache[T.parentHandles[T.parentHandles.length-1]]),P){if(P.parent&&P.parent.userData.originalType){this.setObjectColorByChange(P,{type:Ge.NoChange});continue}P=this.setObjectColorByChange(P,T)}if(T.type!==Ge.NoChange&&P){let _=P.parent;const I=fe.identity();for(;_&&_.userData.isLayoutLevelObject!==!0;)I.premultiply(_.matrix),_=_.parent;pt.makeEmpty();const B=U.getBox(P,pt);B.applyMatrix4(I),T.type===Ge.Added?!u&&(T.box=new p.Box3().copy(B)):T.type===Ge.Removed?u&&(T.box=new p.Box3().copy(B)):T.type===Ge.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),P=new U;P.name=j.SNAP_GROUP_NAME,T.add(P);const _=this.layoutsSnapObjectsMap[v];for(let I=0;I<_.length;I++){const B=_[I];j.SHOW_SNAP_OBJECT&&(B.layers.enableAll(),B.material instanceof p.PointsMaterial?B.material=Aa:B.material instanceof p.LineBasicMaterial?B.material=Ia:B.material instanceof p.MeshBasicMaterial&&(B.material=Ba));let k=B;const D=fe.identity();for(;k&&k.userData.isLayoutLevelObject!==!0;)D.premultiply(k.matrix),k=k.parent;B.matrix.copy(D),P.add(B)}}this.enableMerge&&j.mergeDxfObjects({root:m,layersAndObjects:b});const C=m.convertToThreejsObject();m.clear(),b={};const S={},O=v=>{const T=v.userData.layerName;let P=S[T];!P&&(P=[],S[T]=P),P.push(v)};C.children.forEach(v=>{Q.setSharedVariablesOfObject(v),v.userData.isLayoutLevelObject&&v.traverse(T=>{if(Q.setSharedVariablesOfObject(T),T.userData.isSnapGroup&&(T.visible=j.SHOW_SNAP_OBJECT),T.geometry){const P=T.userData.layerName;this.getLayerVisible(f,P)===!1&&(T.visible=!1,T.userData.layerVisible=!1),O(T)}})});const E=f;E.threejsObject=C,E.layersAndThreejsObjects=S,E.layoutViewportsMap={}};let h=Date.now();this.compareContext={changes:s,isTheFirstFile:!0},N.printMemory("Before loading entities for first dxf"),await l(),A.info("[Dxf] loadEntities for first dxf in "+(Date.now()-h)/1e3+"s"),N.printMemory("After loading entities for first dxf"),this.releaseCachedData(!1),this.releaseDxfData(e),N.printMemory("Before loading entities for second dxf"),h=Date.now(),this.compareContext.isTheFirstFile=!1,await l(),A.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)),N.printMemory("After loading entities for second dxf")}setObjectColorByChange(e,i){const s=a=>{let o=ht.ENTITY_COLOR_NO_CHANGE;return a.type===Ge.Added?o=ht.ENTITY_COLOR_ADDED:a.type===Ge.Removed?o=ht.ENTITY_COLOR_REMOVED:a.type===Ge.Modified&&(o=this.compareContext?.isTheFirstFile?ht.ENTITY_COLOR_REMOVED:ht.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();j.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)&&ss.includes(e.type)&&(n=!0),!n&&this.compareContext&&this.compareContext.preservedHandles&&!ss.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.type==="ATTDEF"&&!s)){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){if(!this.entitiesByHandleIndex||this.entitiesByHandleIndexData!==i){this.entitiesByHandleIndexData=i,this.entitiesByHandleIndex=new Map;for(let m=0;m<i.entities.length;m++){const x=i.entities[m];x.handle&&this.entitiesByHandleIndex.set(x.handle,{entity:x,index:m})}}if(e.ownerHandle){const m=this.entitiesByHandleIndex.get(e.ownerHandle);m?.entity.type==="INSERT"&&(s=m.entity)}if(!s){const m=e.handle?this.entitiesByHandleIndex.get(e.handle):void 0;if(m)for(let x=m.index-1;x>=0;x--){const g=i.entities[x];if(g.type==="INSERT"){s=g;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),m=e.zdysx;let x;if(m)try{x=JSON.parse(m)}catch{x=m}const g=e.type==="ATTRIB";if(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,!g&&x!==void 0&&(M.userData.xdata=x),this.setMaterial(M,e,i,s))}),!l&&(this.nonSnapableTypes.has(e.type)&&o.traverse(M=>{M.layers.disable(qe)}),this.enableRenderOrder&&(this.entityHandlesWithRenderOrder[e.handle]?o.renderOrder=parseInt(this.entityHandlesWithRenderOrder[e.handle],16)+.1:o.renderOrder=parseInt(e.handle,16))),e.type==="INSERT"&&!s&&!this.enableRenderOrder){const M=e.block?i.blocks[e.block]?.entities:void 0;let w=!0;if(M?.length)for(const O of M){const E=O;if(E.type==="ATTDEF"||E.type==="SEQEND")continue;if(!(E.type==="LINE"||E.type==="SPLINE"||(E.type==="LWPOLYLINE"||E.type==="POLYLINE")&&!E.shape)){w=!1;break}}else w=!1;const b=Math.min(parseInt(e.handle,16)||0,3999),C=w?be.InsertLine+b*1e-5:be.InsertSymbol+b*1e-4,S=!w&&M?.length?new Map(M.map((O,E)=>[O.type!=="HATCH"&&O.type!=="SOLID"?void 0:O.handle,E]).filter(([O])=>O!==void 0)):void 0;o.traverse(O=>{if(O.geometry&&O.renderOrder<be.Text&&(O.renderOrder=S?.has(O.userData.handle)?C-5e-5+S.get(O.userData.handle)*5e-7:C,w)){const E=O.geometry.getAttribute("position");if(E){let v=!1;for(let T=0;T<E.count;T++)E.getZ(T)!==0&&(E.setZ(T,0),v=!0);v&&(E.needsUpdate=!0,O.geometry.computeBoundingBox(),O.geometry.computeBoundingSphere())}}})}}const h=e.type,d=e.handle,u=ss.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),V.areNumbersEqual(n,r,1e-5))return A.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=V.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),x=d.getPoints(m),g=[],M=x.length;for(let E=0;E<M-1;E++)V.areVector2sEqual(x[E],x[E+1],1e-9)||g.push(x[E]);if(g.push(x[M-1]),g.length<2)return A.warn("[Dxf] Ellipse entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const w=new p.Vector3;let b=!1;this.enableRTC&&(b=G.checkAndRebasePositionsOnRTC(g,w));const C=new p.BufferGeometry().setFromPoints(g),S=new U(q.Line);S.geometry=C,S.material=ye;const O=new U(q.Point);return O.geometry=Pa,O.material=js,O.matrix.setPosition(e.center.x,e.center.y,e.center.z),O.userData.isSnapObject=!0,O.userData.type="CircleCenter",O.layers.set(qe),S.add(O),b&&(this.setRTCUserData(S),S.matrix.setPosition(w.x,w.y,0)),S.layers.enableAll(),S}loadMText(e,i,s){if(!e.text)return;if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] MText (handle '%s') has non-finite placement, ignored!",e.handle),void 0;if(!this.font)return A.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ns(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose($,xe,at),e.position&&($.x+=e.position.x,$.y+=e.position.y,o.matrix.compose($,xe,at)),pt.makeEmpty();const l=U.getBox(o,pt),h=l.getSize(H),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,x=0;switch(e.attachmentPoint){case 1:m=0,x=0;break;case 2:m-=d/2,x=0;break;case 3:m-=d,x=0;break;case 4:m=0,x+=f/2;break;case 5:m-=d/2,x+=f/2;break;case 6:m-=d,x+=f/2;break;case 7:m=0,x+=f;break;case 8:m-=d/2,x+=f;break;case 9:m-=d,x+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:x+=u;break;case 4:break;case 5:break;default:return}o.traverse(P=>{P.geometry&&P.geometry.translate(m,x,0),P.layers.enableAll()});let g=0;if(e.rotation&&(g=e.rotation*Math.PI/180),e.directionVector){const P=e.directionVector,_=new p.Vector3(P.x,P.y,P.z),I=_.clone().cross(Ke),B=Ke.angleTo(_);g=I.z>0?-B:B}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(o),o.matrix.compose($,xe,at);const M=e.position?$.clone().sub(e.position):$;rt.makeTranslation(-M.x,-M.y,0),fe.makeRotationZ(g),o.matrix.multiply(rt),o.matrix.multiply(fe),o.matrix.multiply(rt.invert()),o.userData||(o.userData={});const w=o.matrix.elements,b=w&&w[12]||0,C=w&&w[13]||0,S=w&&w[14]||0,O=new p.Box3;U.getBox(o,O);const E=new p.Vector3;O.getCenter(E);const v=new p.Vector3;O.getSize(v),o.userData.renderArea={position:{x:b,y:C,z:S},bbox:{min:{x:O.min.x,y:O.min.y,z:O.min.z},max:{x:O.max.x,y:O.max.y,z:O.max.z},center:{x:E.x,y:E.y,z:E.z},width:v.x,height:v.y,depth:v.z},textSize:{width:d,height:u},rotation:g,attachmentPoint:e.attachmentPoint||0,drawingDirection:e.drawingDirection||0};const T=this;return o.userData.textContent=e.text||"",o.userData.cleanText=T.cleanMTextContent?T.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(P=>{P.geometry&&(P.userData.textContent=e.text||"",P.userData.dxfType="MTEXT",P.userData.layer=e.layer||"0",P.userData.handle=e.handle||"")}),o.userData.entityId=e.entityId||e.handle,o}loadTableMText(e,i,s){if(!e.text)return;if(!this.font)return A.info("[Dxf] Font file not set, ignoring text entity."),void 0;const n=this.getTextStyle(i,e),r=ns(e.text,{encoding:this.getTextEncoding(n)}),a=this.getMTextGroup(r,e,n,i,s),o=a&&a.object;if(!o)return;o.matrix.decompose($,xe,at),e.position&&($.x+=e.position.x,$.y+=e.position.y,o.matrix.compose($,xe,at)),pt.makeEmpty();const l=U.getBox(o,pt),h=l.getSize(H),d=e.width||h.x,u=e.height||h.y,f=h.y>0?h.y:u;let m=0,x=0;switch(e.attachmentPoint){case 1:m=0,x=0;break;case 2:m-=d/2,x=0;break;case 3:m-=d,x=0;break;case 4:m=0,x+=f/2;break;case 5:m-=d/2,x+=f/2;break;case 6:m-=d,x+=f/2;break;case 7:m=0,x+=f;break;case 8:m-=d/2,x+=f;break;case 9:m-=d,x+=f;break;default:return}switch(e.drawingDirection){case 1:break;case 2:break;case 3:x+=u;break;case 4:break;case 5:break;default:return}o.traverse(w=>{w.geometry&&w.geometry.translate(m,x,0),w.layers.enableAll()});let g=0;if(e.rotation&&(g=e.rotation*Math.PI/180),e.directionVector){const w=e.directionVector,b=new p.Vector3(w.x,w.y,w.z),C=b.clone().cross(Ke),S=Ke.angleTo(b);g=C.z>0?-S:S}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(o),o.matrix.compose($,xe,at);const M=e.position?$.clone().sub(e.position):$;return rt.makeTranslation(-M.x,-M.y,0),fe.makeRotationZ(g),o.matrix.multiply(rt),o.matrix.multiply(fe),o.matrix.multiply(rt.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 S=s.fontFile+"_"+s.styleName;!this.statsInfo.unsupportedTextStyles[S]&&(this.statsInfo.unsupportedTextStyles[S]=0),this.statsInfo.unsupportedTextStyles[S]++}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 U;let m,x=s.fontFile,g=1,M=1,w=256,b=h*.8,C=b+h;for(let S=0;S<e.length;S++){const O=e[S];if(typeof O=="string"){const E=[],v=(_,I)=>{let B;if(_.forEach((k,D)=>{!k.boundingBox&&k.computeBoundingBox(),D===0?B=k.boundingBox:B.union(k.boundingBox)}),B)switch(d){case"Left":break;case"Center":_.forEach(k=>k.translate((u-I)/2,0,0));break;case"Right":_.forEach(k=>k.translate(u-I,0,0));break}E.push(..._)};let T;for(let _=0;_<O.length;_++){const I=O[_];if(I===`
|
|
794
|
+
`){const k=a;a=0,o-=C,l.length>0&&v(l,k),l=[];continue}if(b=h*.8,C=b+h,T=this.font?.getCharShape(I,x,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+M*(h/3.5);continue}a>(u||1/0)&&(l.length>0&&v(l,a),a=0,o-=C,l=[]),T.translate(a,o,0),T.scale(g,1,1),T.boundingBox||T.computeBoundingBox(),O.T&&(M=O.T);const B=td(I,T,h,M,x);a+=B,l.push(T)}l.length>0&&(v(l,a),l=[]);const P=new U;if(E.length>0){!m&&(m=i.colorIndex),w!==void 0&&w!==256?(i.color=oi(w),i.colorIndex=w):i.colorIndex=m;const _=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 U(q.Mesh);k.geometry=Ie.mergeGeometries(I),k.material=this.getMeshBasicMaterial(_),P.add(k)}if(B.length>0){const k=new U(q.LineSegment);k.geometry=Ie.mergeGeometries(B),k.material=this.getLineBasicMaterial(_),P.add(k)}}P.matrix.makeTranslation(0,-h,0),f.add(P),g=1,M=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&&(x=O.f,x&&x.includes(".shx")&&A.info("[Dxf] Doesn't support custom fonts: "+x)),O.C&&(w=O.C),O.W&&(O.W[1]==="x"?g=O.W[0]*i.width:g=O.W[0]),O.H&&(O.H[1]==="x"?h=O.H[0]*i.height:h=O.H[0]),O.T&&(M=O.T))}if(f.children.length!==0)return Ct.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 A.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;!V.areVector3sEqual(i[0],i[i.length-1])&&i.push(i[0]);const s=new p.Vector3;let n=!1;this.enableRTC&&(n=G.checkAndRebasePositionsOnRTC(i,s));const r=new p.BufferGeometry().setFromPoints(i),a=new U(q.Line);return a.geometry=r,a.material=ye,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 A.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=La(e.controlPoints,e.degreeOfSplineCurve,e.knotValues,d),f=new p.Vector3;let m=!1;this.enableRTC&&(m=G.checkAndRebasePositionsOnRTC(u,f));const x=G.getAdjacentNonRepeatPoints(u);if(x.length<2)return A.warn("[Dxf] Spline entity (handle '%s') contains less than 2 points, ignored!",e.handle),void 0;const g=new p.BufferGeometry().setFromPoints(x),M=new U(q.Line);return M.geometry=g,M.material=ye,m&&(this.setRTCUserData(M),M.matrix.setPosition(f.x,f.y,0)),M.layers.enableAll(),M}loadXLine(e){if(!e.vertices||e.vertices.length===0)return A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=N.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=G.checkAndRebasePositionsOnRTC(n,r));const o=new p.BufferGeometry().setFromPoints(n),l=new U(q.Line);return l.geometry=o,l.material=ye,l.userData.isConstructionLine=!0,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 A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;const i=N.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=G.checkAndRebasePositionsOnRTC(s,n));const a=new p.BufferGeometry().setFromPoints(s),o=new U(q.Line);return o.geometry=a,o.material=ye,o.userData.isConstructionLine=!0,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){A.warn("[Dxf] Entity is missing vertices:",e.handle);return}let s=[];if(e.isPolyfaceMesh)s=k1(e.vertices);else{const h=Nn(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];V.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&&G.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(b=>{a?d.push(new p.Vector3(b.x-r.x,b.y-r.y,b.z-r.z)):d.push(b.clone())});for(let b=1;b<w.length;b++)u.push(f+b-1,f+b);f+=w.length});const m=this.getLineType(e,i),x=i.tables?.lineType?.lineTypes?.[m],g=new p.BufferGeometry().setFromPoints(d);let M=ye;if(x&&h(x)){let w=function(O){const E=O.attributes.position,v=E.count,T=new Float32Array(v);for(let P=0;P<v;P+=2){const _=P*3,I=(P+1)*3,B=E.array[I]-E.array[_],k=E.array[I+1]-E.array[_+1],D=E.array[I+2]-E.array[_+2],z=Math.sqrt(B*B+k*k+D*D);T[P]=P===0?0:T[P-1],T[P+1]=T[P]+z}O.setAttribute("lineDistance",new p.Float32BufferAttribute(T,1))};const b=x.pattern?.[0]||.5,C=x.pattern?.[1]||.5,S=.1;M=new p.LineDashedMaterial({color:ye.color,linewidth:ye.linewidth||1,dashSize:b*S,gapSize:C*S,scale:S}),w(g)}else g.setIndex(u);l=new U(q.LineSegment),l.geometry=g,l.material=M}if(n.length>0){a&&G.checkAndRebasePositionsOnRTC(n,r);const h=new p.BufferGeometry().setFromPoints(n),d=new U(q.Point);d.geometry=h,d.material=js,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){A.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){H.set(e.extrusionDirectionX,e.extrusionDirectionY,e.extrusionDirectionZ);const x=j.getOcsMatrix(H).invert(),g=e.elevation!==void 0?e.elevation:0;n.forEach(M=>{H.set(M.x,M.y,g).applyMatrix4(x),M.x=H.x,M.y=H.y})}let r=Nn(n,e.shape);if(e.shape&&r.length>0&&!V.areVector3sEqual(r[0],r[r.length-1])&&r.push(r[0]),r.length<2){A.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}let a=new U;const o=e.extendedData;if(o?.outlines){const x=o.outlines,g=[];x.forEach(b=>{const C=new p.Shape;b.forEach((S,O)=>{O===0?C.moveTo(S[0],S[1]):C.lineTo(S[0],S[1])}),C.closePath(),g.push(new p.ShapeGeometry(C))});const M=Ie.mergeGeometries(g),w=new U(q.Mesh);w.geometry=M,w.material=yi,w.layers.enableAll(),w.layers.disable(qe),a.add(w)}let l=!1;const h=new p.Vector3;this.enableRTC&&(l=G.checkAndRebasePositionsOnRTC(r,h));const d=G.getAdjacentNonRepeatPoints(r);if(d.length<2){A.warn("[Dxf] Invalid LWPolyline entity (handle '%s'), ignored!",e.handle);return}const u=e.constantWidth,f=d.length>2&&V.areVector3sEqual(d[0],d[d.length-1]);if(this.enablePlineWidth&&!f){const x=n.some(g=>g.startWidth!==void 0||g.endWidth!==void 0);if(x||u!==void 0&&u>0){let g;const M=i.tables?.lineType?.lineTypes,w=this.getLineType(e,i,s),b=M?.[w];if(!b||!b.pattern||b.pattern.length===0)if(this.statsInfo.unsupportedPolylineCount++,x?g=this.createTaperedPolylineGeometry(n,u):g=G.convertWidthLineToMeshGeometry(d,u),!g)A.warn("[Dxf] Failed to convert line with width to mesh geometry: %s",e.handle);else{const C=new U(q.Mesh);C.geometry=g,C.material=yi,C.layers.enableAll(),C.layers.disable(qe),a.add(C);const S=Q.createOutline(g,ye,C.matrix),O=new U(q.LineSegment);O.geometry=S.geometry,O.material=S.material,O.matrix=S.matrix,O.layers.enableAll(),O.layers.disable(qe),a.add(O)}}}const m=new U(q.Line);return m.geometry=new p.BufferGeometry().setFromPoints(d),m.material=ye,m.layers.enableAll(),a.children.length>0?a.add(m):a=m,l&&(this.setRTCUserData(a),a.matrix.setPosition(h)),a}createTaperedPolylineGeometry(e,i){if(!e||e.length<2)return null;const s=[],n=[];for(let a=0;a<e.length-1;a++){const o=e[a],l=e[a+1],h=l.x-o.x,d=l.y-o.y,u=Math.hypot(h,d);if(u===0)continue;const f=o.startWidth??i??0,m=o.endWidth??i??0;if(f<=0&&m<=0)continue;const x=-d/u,g=h/u,M=f/2,w=m/2,b={x:o.x+x*M,y:o.y+g*M},C={x:o.x-x*M,y:o.y-g*M},S={x:l.x+x*w,y:l.y+g*w},O={x:l.x-x*w,y:l.y-g*w},E=s.length/3;s.push(b.x,b.y,0,C.x,C.y,0,S.x,S.y,0,O.x,O.y,0),n.push(E,E+1,E+2),n.push(E+1,E+3,E+2)}if(!n.length)return null;const r=new p.BufferGeometry;return r.setAttribute("position",new p.Float32BufferAttribute(s,3)),r.setIndex(n),r}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 U,o=ns(r),l=this.getTextStyle(i,e),h=this.getMTextGroup(o,e,l,i,s),d=h&&h.object;if(d){d.matrix.decompose($,xe,at),e.contextData?.textLocation&&($.x+=e.contextData.textLocation.x,$.y+=e.contextData.textLocation.y,d.matrix.compose($,xe,at)),pt.makeEmpty();const u=U.getBox(d,pt),f=u.getSize(H),m=f.x,x=f.y;let g=0,M=0;switch(e.contextData?.textAttachment){case 1:g=0,M=0;break;case 2:g-=m/2,M=0;break;case 3:g-=m,M=0;break;case 4:g=0,M+=x/2;break;case 5:g-=m/2,M+=x/2;break;case 6:g-=m,M+=x/2;break;case 7:g=0,M+=x;break;case 8:g-=m/2,M+=x;break;case 9:g-=m,M+=x;break;default:return}d.traverse(C=>{C.geometry&&C.geometry.translate(g,M,0)});let w=0;if(e.contextData?.textRotation&&(w=e.contextData.textRotation*Math.PI/180),e.contextData?.textDirection){const C=e.contextData.textDirection,S=new p.Vector3(C.x,C.y,C.z),O=S.clone().cross(Ke),E=Ke.angleTo(S);w+=O.z>0?-E:E}G.shouldRebasePositionOnRTC($)&&this.setRTCUserData(d),d.matrix.compose($,xe,at),e.contextData?.textLocation?H.set(e.contextData.textLocation.x,e.contextData.textLocation.y,0):H.set(0,0,0);const b=$.clone().sub(H);rt.makeTranslation(-b.x,-b.y,0),fe.makeRotationZ(w),d.matrix.multiply(rt),d.matrix.multiply(fe),d.matrix.multiply(rt.invert()),d.renderOrder=be.Text,a.add(d)}if(e.leaderLineType!==0){const u=[],f=e.contextData?.leaders[0];if(!f)return a;const m=f.lastLeaderLinePoint;if(!m)return a;if(e.enableDogLeg&&f.doglegVector){const C=new p.Vector3(m.x,m.y,m.z),S=f.doglegLength,O=new p.Vector3(f.doglegVector.x,f.doglegVector.y,f.doglegVector.z),E=O.multiplyScalar(S),v=C.clone().add(E);u.push(v,C)}const x=e.contextData?.leaders[0].leaderLines||[];for(let C=0;C<x.length;C++){const S=x[C].vertices?.[0];if(!S||S.length===0)continue;const O=S.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];if(u.length<2)continue;const v=H.subVectors(u[0],u[1]).length(),T=e.arrowHeadSize||n.DIMASZ||2.5,P=e.arrowHeadScale||n.DIMSCALE||1,_=T*P;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 D=this.loadEntity(B.entities[k],i,e);if(D){const z=new p.Vector3(u[u.length-1].x,u[u.length-1].y,u[u.length-1].z),se=new p.Vector3(u[u.length-2].x,u[u.length-2].y,u[u.length-2].z),re=Math.atan2(z.y-se.y,z.x-se.x);H.copy(z),$.setScalar(_),xe.setFromAxisAngle(gi,re),D.matrix.compose(H,xe,$),a.add(D)}}}else this.loadDefaultLeadArrow(u[u.length-2],u[u.length-1],v/2e3,u)}const g=new p.Vector3;let M=!1;this.enableRTC&&(M=G.checkAndRebasePositionsOnRTC(u,g));const w=new p.BufferGeometry().setFromPoints(u),b=new U(q.LineSegment);b.geometry=w,b.material=ye,b.renderOrder=be.Line,M&&(this.setRTCUserData(b),b.matrix.setPosition(g.x,g.y,0)),a.add(b)}else return d?.traverse(u=>{u.layers.enableAll()}),d;return Ct.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 A.warn("[Dxf] Entity is missing vertices:",e.handle),void 0;if(e.vertices.length<2)return A.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 M=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 b=new p.Vector3(1,0,0).multiplyScalar(M);a.push(b.add(w))}else{const b=new p.Vector3(-1,0,0).multiplyScalar(M);a.push(b.add(w))}}for(let M=0;M<a.length-1;M++){const w=a[M],b=a[M+1];n.push(w,b)}const o=H.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 U;if(e.arrowFlag===1){let M="";e.arrowHeadBlockHandle?M=e.arrowHeadBlockHandle:r&&r.DIMLDRBLK&&(M=r.DIMLDRBLK);const w=this.getBlockByHandle(i.blocks,M);if(w&&w.entities){r&&(e.colorIndex=r.DIMCLRD||256,e.color=oi(e.colorIndex));for(let b=0;b<w.entities.length;b++){const C=this.loadEntity(w.entities[b],i,e);if(C){const S=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(S.y-O.y,S.x-O.x);H.copy(S),$.setScalar(d),xe.setFromAxisAngle(gi,E),C.matrix.compose(H,xe,$),u.add(C)}}}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=G.checkAndRebasePositionsOnRTC(n,f));const x=new p.BufferGeometry().setFromPoints(n),g=new U(q.Line);return g.geometry=x,g.material=ye,g.renderOrder=be.Line,m&&(this.setRTCUserData(g),g.matrix.setPosition(f.x,f.y,0)),u.children.length>0?(u.add(g),Ct.merge(u,!1),u.traverse(M=>{M.layers.enableAll()}),u.children.length===1?u.children[0]:u):(g.layers.enableAll(),g)}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){A.warn("[Dxf] Entity is missing startPoint:",e.handle);return}if(e.cells.length===0){A.warn("[Dxf] Entity is missing cells:",e.handle);return}if(e.rowHeightArr.length===0){A.warn("[Dxf] Entity is missing rowHeightArr:",e.handle);return}if(e.columnWidthArr.length===0){A.warn("[Dxf] Entity is missing columnWidthArr:",e.handle);return}const n=new U,{cells:r,rowCount:a,columnCount:o,rowHeightArr:l,columnWidthArr:h}=e,d=[];let u=0;for(let g=0;g<a;g++){d[g]=[];for(let M=0;M<o;M++)d[g][M]=u<r.length?r[u++]:null}for(let g=0;g<a;g++)for(let M=0;M<o;M++){const w=d[g][M];if(!w||w.mergedValue!==0)continue;let b=1,C=1;for(;g+b<a&&d[g+b][M]&&d[g+b][M].mergedValue===1;)b++;for(;M+C<o&&d[g][M+C]&&d[g][M+C].mergedValue===1;)C++;w.rowSpan=b,w.colSpan=C}const f=[0];for(let g=0;g<a;g++)f.push(f[g]-l[g]);const m=[0];for(let g=0;g<o;g++)m.push(m[g]+h[g]);const x=[];for(let g=0;g<=a;g++){let M=m[0],w=!1;for(let b=0;b<o;b++){g>0&&d[g-1][b],g<a&&d[g][b];let C=!0;if(g===0||g===a)C=!0;else{const S=this._getMergeOwner(d,g-1,b,a,o),O=this._getMergeOwner(d,g,b,a,o);C=S!==O}C?w||(w=!0,M=m[b]):w&&(x.push(new p.Vector3(M,f[g],0),new p.Vector3(m[b],f[g],0)),w=!1)}w&&x.push(new p.Vector3(M,f[g],0),new p.Vector3(m[o],f[g],0))}for(let g=0;g<=o;g++){let M=f[0],w=!1;for(let b=0;b<a;b++){g>0&&d[b][g-1],g<o&&d[b][g];let C=!0;if(g===0||g===o)C=!0;else{const S=this._getMergeOwner(d,b,g-1,a,o),O=this._getMergeOwner(d,b,g,a,o);C=S!==O}C?w||(w=!0,M=f[b]):w&&(x.push(new p.Vector3(m[g],M,0),new p.Vector3(m[g],f[b],0)),w=!1)}w&&x.push(new p.Vector3(m[g],M,0),new p.Vector3(m[g],f[a],0))}if(x.length>0){const g=new p.BufferGeometry().setFromPoints(x),M=new U(q.LineSegment);M.geometry=g,M.material=ye,M.layers.enableAll(),n.add(M)}for(let g=0;g<a;g++)for(let M=0;M<o;M++){const w=d[g][M];if(!w||w.mergedValue!==0)continue;const b=m[M],C=f[g];let S=0;for(let T=0;T<(w.colSpan||1);T++)S+=h[M+T];let O=0;for(let T=0;T<(w.rowSpan||1);T++)O+=l[g+T];w.colorIndex=e.colorIndex,w.height=w.textHeight||2.5;const E=this.getTableTextOffset(w.attachmentPoint||1,S,O);H.set(b,C,0),H.add(E),w.position=H.clone();const v=this.loadMText(w,i,s);v&&n.add(v)}if(e.blockRecordHandle){const g=this.getBlockByHandle(i.blocks,e.blockRecordHandle);if(g&&g.entities)for(const M of g.entities){M.isTable=!0;const w=this.loadEntity(M,i,e);w&&n.add(w)}}return n.matrix.decompose(H,xe,at),H.x+=e.startPoint.x,H.y+=e.startPoint.y,n.matrix.compose(H,xe,at),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=j.CameraZoomUniform),e.uniforms.u_viewportScale&&(e.uniforms.u_viewportScale=j.ViewportScaleUniform))}static transformAngleByOcsMatrix(e,i){const s=H.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=V.getArcAngleSpanInRadian(i,s);const r=j.transformAngleByOcsMatrix(e,i),a=j.transformAngleByOcsMatrix(e,s);let o;if(V.areNumbersClose(n,Math.PI)){n=1;const l=j.transformAngleByOcsMatrix(e,i+n);o=V.getArcAngleSpanInRadian(r,l)}else{if(V.areNumbersClose(n,Math.PI*2))return[r,r+Math.PI*2];o=V.getArcAngleSpanInRadian(r,a)}return V.areNumbersClose(n,o,1e-5)?[r,a]:[a,r]}loadArc(e,i,s){if(!e.radius||e.radius<.001)return A.warn("[Dxf] The radius of arc (handle '"+e.handle+"') is undefined, ignored!"),void 0;if(!e.radius||e.radius<.001)return A.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=j.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,V.areNumbersEqual(a,o,1e-6)))return;if(!V.areNumbersClose(V.getArcAngleSpanInRadian(a,o),Math.PI*2)){const O=j.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 x=!1;this.enableRTC&&(x=G.checkAndRebasePositionsOnRTC(f,m));const g=new p.BufferGeometry().setFromPoints(f),M=new U(q.Line);M.geometry=g,M.material=ye;const w=new p.Vector3;e.center&&(w.x=e.center.x,w.y=e.center.y);const b=new p.Vector3(e.center?.x,e.center?.y,e.center?.z).applyMatrix4(r.invert());w.x=b.x,w.y=b.y;const C=w,S=new U(q.Point);return S.geometry=Pa,S.material=js,S.userData.handle=e.handle,S.userData.isSnapObject=!0,S.userData.type="CircleCenter",S.layers.set(qe),M.add(S),x?(this.setRTCUserData(M),C.x+=m.x,C.y+=m.y):G.shouldRebasePositionOnRTC(C)&&this.setRTCUserData(M),M.matrix.setPosition(C),M.layers.enableAll(),M}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){H.set(0,0,e.extrusionDirection.z);const u=j.getOcsMatrix(H).invert();n.forEach(f=>{const m=H.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=G.checkAndRebasePositionsOnRTC(r,o));const h=new p.BufferGeometry().setFromPoints(r);h.setIndex(a);const d=new U(q.Mesh);return d.geometry=h,d.material=yi,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 U,d=[];let u=0,f=0;i?.xScale;const m=n+s,x=i?.fontFile||"",g=typeof x=="string"&&x.toLowerCase().endsWith(".shx"),M=g?s*.06:s*.04,w=[];for(let S=0;S<e.length;S++){const O=e[S];O!==" "&&O!==`
|
|
795
795
|
`&&w.push(S)}const b=w.length;let C=0;for(let S=0;S<e.length;S++){const O=e[S];if(O===" "){u+=s*(g?.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(H).x,T=O.charCodeAt(0),P=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+M;C++,u+=P+(C===b?0:l)}d.push(E)}}if(d.length>0){const S=d.filter(E=>E instanceof p.ExtrudeGeometry),O=d.filter(E=>!(E instanceof p.ExtrudeGeometry));if(S.length>0){const E=new U(q.Mesh);E.geometry=Ae.mergeGeometries(S),E.material=yi,h.add(E)}if(O.length>0){const E=new U(q.LineSegment);E.geometry=Ae.mergeGeometries(O),E.material=ye,h.add(E)}}return h}transformTextMesh(e,i){ft.makeEmpty();const s=U.getBox(i,ft),n=s.getSize(H),{halign:r,valign:a}=e;i.matrix.decompose(Ns.position,Ns.quaternion,Ns.scale);const o=Ns,l=e.width||e.textWidth||n.x,h=e.height||e.textHeight||n.y,d=s.min.y+n.y/2;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 u=e.rotation*Math.PI/180;o.rotateZ(u)}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 u=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new p.Vector3().subVectors(u,f),y=m.length(),g=y/l;o.scale.multiplyScalar(g);const M=m.clone().cross(Ze),w=m.angleTo(Ze);o.rotateZ(M.z>0?Math.PI-w:w-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-d);break;case 5:if(e.startPoint&&e.endPoint){const u=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new p.Vector3().subVectors(u,f),y=m.length(),g=y/l,w=(e.text||"").length;if(w>1){const S=(y-l)/(w-1);o.userData.letterSpacing=S}else g<3&&o.scale.setX(g);const b=m.clone().cross(Ze),C=m.angleTo(Ze);o.rotateZ(b.z>0?Math.PI-C:C-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}addTextUnderscores(e,i,s){const n=[];let r=0,a=null;for(const y of e){const g=y.text.length;g<=0||(y.u&&a===null&&(a=r),!y.u&&a!==null&&(n.push([a,r]),a=null),r+=g)}if(a!==null&&n.push([a,r]),!n.length)return;const o=new p.Box3;if(i.traverse(y=>{y.geometry&&(y.geometry.computeBoundingBox(),y.geometry.boundingBox&&o.union(y.geometry.boundingBox))}),!Number.isFinite(o.min.x)||!Number.isFinite(o.max.x))return;const l=e.reduce((y,g)=>y+g.text.length,0);if(l<=0)return;const h=o.min.x,d=(o.max.x-o.min.x)/l,u=o.min.y-s*.12,f=Math.max(s*.06,1e-6);let m;i.traverse(y=>{!m&&y.material&&(m=y.material)});for(const[y,g]of n){const M=h+y*d,w=h+g*d;if(w-M<=1e-9)continue;const b=u,C=u+f,S=new p.BufferGeometry;S.setAttribute("position",new p.Float32BufferAttribute([M,b,0,w,b,0,w,C,0,M,b,0,w,C,0,M,C,0],3)),S.setIndex([0,1,2,3,4,5]);const O=new U(q.Mesh);O.geometry=S,O.material=m,i.add(O)}}loadText(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] Text (handle '%s') has non-finite placement, ignored!",e.handle),void 0;const n=e.text;if(!n)return;if(!this.font){A.info("[Dxf] Font file not set, ignoring text entity.");return}const r=this.getTextStyle(i,e),a=an(n,{encoding:this.getTextEncoding(r)}),o=a.map(d=>d.text).join(""),l=this.getTextMesh(o,e.textHeight,r,e);if(!l||l.children.length===0)return;this.addTextUnderscores(a,l,e.textHeight??1),this.transformTextMesh(e,l),H.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const h=G.shouldRebasePositionOnRTC(H);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 y=0;y<f.count;y+=3)m.push(y,y+1,y+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!h){const f=G.caculateGeometryCenter(u);f&&G.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(d)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] AttDef (handle '%s') has non-finite placement, ignored!",e.handle),void 0;let n=e.tag||e.text||e.prompt;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=an(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),H.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=G.shouldRebasePositionOnRTC(H);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=G.caculateGeometryCenter(d);u&&G.shouldRebasePositionOnRTC(u)&&this.setRTCUserData(h)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] Attrib (handle '%s') has non-finite placement, ignored!",e.handle),void 0;let n=e.text;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=an(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),H.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const d=G.shouldRebasePositionOnRTC(H);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"),y=[];for(let g=0;g<m.count;g+=3)y.push(g,g+1,g+2);f.setIndex(y)}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=G.caculateGeometryCenter(f);m&&G.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!j.isFinitePoint(e.position))return;const n=new p.BufferGeometry,r=[new p.Vector3(e.position.x,e.position.y,e.position.z)];H.set(0,0,0);const a=H;let o=!1;this.enableRTC&&(o=G.checkAndRebasePositionsOnRTC(r,a)),n.setFromPoints(r);const l=new U(q.Point);return l.geometry=n,l.material=ye,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 U;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 H.set(0,0,0),a&&H.set(a.x,a.y,0),G.shouldRebasePositionOnRTC(H)&&this.setRTCUserData(r),r.matrix.setPosition(H),r}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const n=i.objects.IMAGEDEF.filter(g=>g.handle===e.imageDefHandle)[0];if(!n)return;const r=e.imageSize.x,a=e.imageSize.y,o=new U;let l=!1;e.flags===on.ShowImageWhenNotAlignedWithScreen||e.flags===on.UseClippingBoundary||e.flags===on.TransparencyIsOn||(l=!0);const h=new p.PlaneGeometry(r,a);if(l){const g=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.")});g.colorSpace=p.SRGBColorSpace;const M=new p.MeshBasicMaterial({transparent:!0,side:p.FrontSide,map:g}),w=new U(q.Mesh);w.geometry=h,w.material=M,o.add(w)}const d=new p.EdgesGeometry(h),u=this.getColor(e,i,s),f=new U(q.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),y=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),$.set(m.x,y.y,1),H.set(0,0,0),e.position){const g=new p.Vector3(e.position.x,e.position.y,e.position.z);g.add(m.multiplyScalar(r/2)).add(y.multiplyScalar(a/2)),H.copy(g)}return G.shouldRebasePositionOnRTC(H)&&this.setRTCUserData(o),xe.identity(),o.matrix.compose(H,xe,$),o}loadInsert(e,i,s,n=!1){if(!e||!e.block)return;if(e.position&&!j.isFinitePoint(e.position))return A.warn("[Dxf] Insert (handle '%s') has non-finite position, ignored!",e.handle),void 0;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 U,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 y=this.loadEntity(r.entities[m],i,e,n);y&&(o&&j.LOADLLDATA&&(y.userData.llbData=o),l!==void 0&&y.traverse(g=>{g.geometry&&(g.userData.xdata=l)}),a.add(y))}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=H.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),xe.setFromEuler(d,!1);const u=$.set(0,0,0);e.position&&(u.x=e.position.x,u.y=e.position.y),fe.compose(u,xe,h),e.extrusionDirection&&e.extrusionDirection.z<0&&fe.premultiply(Pa.identity().makeScale(-1,1,1)),nt.copy(a.matrix),a.matrix.premultiply(fe),$.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),G.shouldRebasePositionOnRTC($)&&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),A.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;if(!Array.isArray(s)||s.length<12)return A.warn("[Dxf] Spatial filter (handle '"+e.handle+"') has no invertBlockMatrix, ignored!"),void 0;fe.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 A.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let h=[],d=-1;for(let m=0;m<o;m++){const y=n[m];for(let g=o-1;g>m;g--){const M=n[g];if(V.areVector3sEqual(y,M)&&m+1<g-1&&m+1<o-1&&V.areVector3sEqual(n[m+1],n[g-1])){h.push(y),d=g;break}}if(d>0)break;h.push(y)}if(d>0)for(let m=d+1;m<o;m++)h.push(n[m]);if(h.length<l)return A.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])}),!G.isConvex(u)){A.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const m=Al(f,1/0);h=[],m.forEach(y=>{h.push(new p.Vector3(y[0],y[1],0))})}!V.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=fe.clone(),i.clipPolylines=[],i.clipPolylines.push(r),a}loadLayout(e,i,s,n,r,a){if(!e.entities)return;const o=new U;for(let d=0;d<e.entities.length;d++){const u=e.entities[d];this.addViewport(u,a);const f=this.loadEntity(u,i);f&&(this.enableMerge&&Tt.merge(f,!1),o.add(f),f.traverse(m=>{if(m.geometry){const y=m.userData.layerName;let g=r[y];!g&&(g=[],r[y]=g),g.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 U,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;const s=e.type,n=r=>!!r&&Number.isFinite(r.x)&&Number.isFinite(r.y);switch(s){case Si.Line:{const r=e;if(!n(r.startPoint)||!n(r.endPoint))break;i.push(new p.Vector2(r.startPoint.x,r.startPoint.y)),i.push(new p.Vector2(r.endPoint.x,r.endPoint.y));break}case Si.Arc:{const r=e;if(!n(r.center)||!Number.isFinite(r.radius)||r.radius<=0||!Number.isFinite(r.startAngle)||!Number.isFinite(r.endAngle))break;let a=r.startAngle*p.MathUtils.DEG2RAD,o=r.endAngle*p.MathUtils.DEG2RAD;!r.bCounterclockwise&&(a=Math.PI*2-a,o=Math.PI*2-o);const l=new p.ArcCurve(r.center.x,r.center.y,r.radius,a,o,!r.bCounterclockwise),h=this.getDivision(a,o,r.radius),d=l.getPoints(h);e.startPoint=d[0],e.endPoint=d[d.length-1],i.push(...d);break}case Si.Ellipse:{const r=e;if(!n(r.center)||!n(r.majorAxisEndPoint)||!Number.isFinite(r.minorRatio)||!Number.isFinite(r.startAngle)||!Number.isFinite(r.endAngle))break;const a=Math.sqrt(Math.pow(r.majorAxisEndPoint.x,2)+Math.pow(r.majorAxisEndPoint.y,2)),o=a*r.minorRatio,l=Math.atan2(r.majorAxisEndPoint.y,r.majorAxisEndPoint.x);let h=r.startAngle*p.MathUtils.DEG2RAD,d=r.endAngle*p.MathUtils.DEG2RAD;!r.bCounterclockwise&&(h=Math.PI*2-h,d=Math.PI*2-d);const u=new p.EllipseCurve(r.center.x,r.center.y,a,o,h,d,!r.bCounterclockwise,l),f=this.getDivision(h,d,Math.max(a,o)),m=u.getPoints(f);e.startPoint=m[0],e.endPoint=m[m.length-1],i.push(...m);break}case Si.Spline:{const r=e,a=La(r.controlPoints,r.degreeOfSplineCurve,r.knotValues);if(a.length===0)break;e.startPoint=a[0],e.endPoint=a[a.length-1],i.push(...a);break}case Si.Polyline:{const r=e,a=Nn(r.points,r.isClosed);e.startPoint=a[0],e.endPoint=a[a.length-1],i.push(...a);break}}return i}loadHatch(e,i,s){const n=e;let r=[];function a(E,v){const{startPoint:T,endPoint:_}=E,{startPoint:P,endPoint:I}=v;if(!T||!_||!P||!I)return null;const B=_.x-T.x,k=_.y-T.y,D=I.x-P.x,z=I.y-P.y,se=B*z-k*D;if(Math.abs(se)<1e-10)return null;const re=T.x-P.x,Ue=T.y-P.y,De=(D*Ue-z*re)/se,de=(B*Ue-k*re)/se;return De>=0&&De<=1&&de>=0&&de<=1?{x:T.x+De*B,y:T.y+De*k}:null}function o(E){const{edges:v}=E,T=[],_=v.length;if({...E},_!==4)return[E];for(let P=0;P<_;P++)for(let I=P+2;I<_;I++){if(I===P+1||P===0&&I===_-1)continue;const B=a(v[P],v[I]);B&&T.push({edgeIndex1:P,edgeIndex2:I,point:{x:B.x,y:B.y}})}if(T.length&&T.length===1){const P=v[(T[0].edgeIndex1-1+_)%_],I={pathTypeFlag:E.pathTypeFlag,edges:[P,{startPoint:{...v[T[0].edgeIndex1].startPoint},endPoint:{x:T[0].point.x,y:T[0].point.y},type:v[T[0].edgeIndex1].type},{startPoint:{x:T[0].point.x,y:T[0].point.y},endPoint:{x:v[T[0].edgeIndex2].startPoint.x,y:v[T[0].edgeIndex2].startPoint.y},type:v[T[0].edgeIndex2].type}]},B={pathTypeFlag:E.pathTypeFlag,edges:[{startPoint:{x:T[0].point.x-1e-5,y:T[0].point.y-1e-5},endPoint:{...v[T[0].edgeIndex1].endPoint},type:v[T[0].edgeIndex1].type},{...v[T[0].edgeIndex2-1]},{startPoint:v[T[0].edgeIndex2].startPoint,endPoint:{x:T[0].point.x-1e-5,y:T[0].point.y-1e-5},type:v[T[0].edgeIndex2].type}]};return[I,B]}return[E]}if(n.boundaryPaths.length==0)return;for(let E=0;E<n.boundaryPaths.length;E++){const v=n.boundaryPaths[E],T=o(v);r=[...r,...T]}if(n.boundaryPaths=r,!n.solidFill&&!n.patternLines?.length){A.warn("[Dxf] Hatch entity(handle: '"+n.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],h=[],d=[],u=E=>{const v=[];let T=[];T.push(...this.convertEdgeToPoints(E[0]));for(let _=1;_<E.length;_++){const P=this.convertEdgeToPoints(E[_]);if(T.push(...P),T.length>2){const I=this.convertEdgeToPoints(E[_-1]);V.areVector2sEqual(I[I.length-1],P[0])?V.areVector2sEqual(T[0],P[P.length-1],1e-5)&&(v.push(T),T=[]):V.areVector2sEqual(I[0],P[P.length-1])?V.areVector2sEqual(T[1],P[0],1e-5)&&(v.push(T),T=[]):T=[]}}return v},f=E=>{for(let v=1;v<E.length;++v){const T=E[v-1].endPoint,_=E[v].startPoint;if(!T||!_||!V.areVector2sEqual(T,_))return!1}return!0},m=E=>{const v=[];let T=[];for(let _=0;_<E.length;_++){const P=this.convertEdgeToPoints(E[_]);if(!(P.length<2)){if(T.length>2&&V.areVector2sEqual(T[0],T[T.length-1],1e-5)){const I=T[T.length-1],B=V.areVector2sEqual(I,P[0],1e-5),k=V.areVector2sEqual(I,P[P.length-1],1e-5);!B&&!k&&(v.push(T),T=[])}T.length>0&&!V.areVector2sEqual(T[T.length-1],P[0],1e-5)&&V.areVector2sEqual(T[T.length-1],P[P.length-1],1e-5)&&P.reverse(),T.push(...P)}}return T.length>2&&v.push(T),v};if(n.boundaryPaths.forEach((E,v)=>{let T=[];if(this.IsfilteredByPathTypeFlag(E.pathTypeFlag)){A.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",E.pathTypeFlag,v,n.handle);return}const _=E.edges;if(_.length===0)return;const P=[];for(let I=0;I<_.length;I++){const B=this.convertEdgeToPoints(_[I]);if(B.length<2){A.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",I,v,n.handle);continue}P.push(...B)}if(P.length<3){A.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",v,n.handle);return}if(T.push(P),E.pathTypeFlag>Do.MaxFlags){if((!f(E.edges)||!n.associativity)&&(T=u(_),T.length<2)){A.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",v,n.handle);return}}else if(!f(E.edges)){const I=m(_);I.length>0&&(T=I)}T.forEach(I=>{!V.areVector2sEqual(I[0],I[I.length-1])&&I.push(I[0]);const B=I.map(k=>new p.Vector2(N.roundNumber(k.x,7),N.roundNumber(k.y,7)));if(B?.length>0){l.push(B);const k=new p.Box2().setFromPoints(B);h.push(k);const D=k.getSize(Xi),z=D.x*D.y;d.push({area:z,index:l.length-1})}})}),l.length===0)return;const y=new p.Vector2,g=this.checkAndRebasePolygonsOnRTC(l,y);d.sort((E,v)=>E.area-v.area);const M=[];d.forEach(E=>{M.push(E.index)});const w=this.buildContainHierarchyTree(l,h,M),b=[];this.buildHatchGeometry(l,w,b);let C;if(b.length>0&&(C=Ae.mergeGeometries(b)),!C||!C.getIndex()||C.getIndex()?.count===0)return A.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const S=new U(q.Mesh);S.geometry=C,S.material=yi,this.setHatchMaterial(S,n,i,y,s);const O=S;return g&&(this.setRTCUserData(O),O.matrix.setPosition(y.x,y.y,0)),O.traverse(E=>{E.layers.enableAll(),E.layers.disable(Ge)}),O}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=G.checkAndRebasePositionsOnRTC(o,l));const d=new p.BufferGeometry().setFromPoints(o),u=this.getLineBasicMaterial(16777215),f=new U(q.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 U;m.add(f);let y;const g=i.objects.DICTIONARY;for(const w of g)for(const b in w.entries)if(w.entries[b]===e.handle){y=b;break}let M;if(y)if(this.meshTextureMaterials[y])M=this.meshTextureMaterials[y];else for(let w=0;w<i.objects.XRECORD.length;w++){const b=i.objects.XRECORD[w];if(b.handle===y){const C=b.binaryData,S=N.hexToBase64(C),O="data:image/jpg;base64,"+S,E=new p.TextureLoader(this.manager).load(O);E.colorSpace=p.SRGBColorSpace;const v=new p.MeshBasicMaterial({transparent:!0,map:E});this.meshTextureMaterials[y]=v,M=v;break}}if(M){const w=new p.Box2().setFromPoints(o),b=w.getSize(Xi),C=new p.PlaneGeometry(b.x,b.y),S=new U(q.Mesh);S.geometry=C,S.material=M;const O=w.getCenter(Xi);H.set(O.x,O.y,0),h&&(this.setRTCUserData(S),H.x+=l.x,H.y+=l.y),S.matrix.setPosition(H),S.layers.enableAll(),m.add(S)}return m.children.length>1?m:f}static isFinitePoint(e){return!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&(e.z===void 0||Number.isFinite(e.z))}static hasFiniteTextPlacement(e){return e.position&&!j.isFinitePoint(e.position)||e.startPoint&&!j.isFinitePoint(e.startPoint)||e.endPoint&&!j.isFinitePoint(e.endPoint)?!1:Number.isFinite(e.rotation??0)}static getOcsMatrix(e){let i=Ze,s=jn,n=gi;const r=new p.Vector3(0,1,0),a=new p.Vector3(0,0,1);return V.areVectorsClose(e,a)?fe.identity():(n=e.clone().normalize(),!V.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()),fe.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;P1(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(V.roundNumber(s.x,7),V.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=gi.clone().cross(r),l.length()>0?(l.normalize(),h=d.clone().cross(l)):d.z<0?(l=Ze.clone().negate(),h=jn,d=gi.clone().negate()):(l=Ze,h=jn,d=gi);const u=new p.Matrix4,f=fe.identity();return f.makeBasis(l,h,d),u.premultiply(f),u.premultiply(fe.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=j.getDcs2WcsMatrix(e,this.angDir),d=new p.Matrix4;d.setPosition(Oa.clone().sub(r));const u=Pa.identity();u.scale(H.set(l,l,l));const f=nt.identity().setPosition(Oa.clone().sub(r));u.premultiply(f.clone().invert()).multiply(f),d.multiply(u);const m=fe.identity();m.setPosition(n),h.multiply(m);const y=fe.identity();return d.invert().multiply(y).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=G.checkAndRebasePositionsOnRTC(o,h));const d=new p.BufferGeometry().setFromPoints(o),u=new U(q.Line);u.geometry=d,u.material=ye,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 y=!1;const g=new p.Vector3;this.enableRTC&&(y=G.checkAndRebasePositionsOnRTC(m,g));const M=new p.BufferGeometry().setFromPoints(m),w=new U(q.Line);w.geometry=M,w.material=ye,w.userData.entityType=e.type,w.userData.inPaperSpace=[],w.layers.enableAll(),y&&(this.setRTCUserData(w),w.matrix.setPosition(g.x,g.y,0));const b=new U;return b.add(u),b.add(w),u}getColor(e,i,s){if(this.compareContext)return ct.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!";A.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=Ft;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 A.warn("[Dxf] Unknown colorIndex"),Ft}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==Pr&&e.lineType!==us)return e.lineType;if(e.lineType===us)return s?this.getLineType(s,i):e.lineType;const n=i.tables?.layer?.layers,r=_1;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=be.Text;return}if(i.type==="HATCH"){Xi.set(0,0),this.setHatchMaterial(e,i,s,Xi,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=be.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=be.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=be.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=be.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===q.Line||a.type===q.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=be.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(),j.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o))}else h=this.getHatchShaderMaterial(i,o,n);l=be.MeshWithPattern}!h&&(h=this.getMeshBasicMaterial(o),l=be.Mesh),a.material=h,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=be.Mesh:i.isLine?s=be.Line:i.isPoints&&(s=be.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,j.ViewportScaleUniform,j.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)),y=new p.Vector2(f.delta.x,f.delta.y).rotateAround(d,-p.MathUtils.degToRad(f.angle));if(y.y===0)return A.warn("[Dxf] delta.y is equal to zero !"),void 0;const g=f.dashPattern.length;let M=!0,w=0;for(let v=0;v<g;++v){const T=f.dashPattern[v];T>0&&(M=!1),w+=Math.abs(T)}const b=M?a:r,C=[],S=[];let O=0;S[0]=O;for(let v=0;v<g;++v)C[v]=f.dashPattern[v],C[v]===0&&(C[v]=b*w),O+=Math.abs(C[v]),S[v+1]=O;for(let v=g;v<o;++v)C[v]=0;for(let v=S.length;v<o+1;++v)S[v]=O;const E={origin:m,delta:y,angle:f.angle-e.patternAngle,pattern:C,patternSum:S,patternLength:O};if(l+=4,l+=o,l+=o+1,l>j.MaxFragmentUniforms){A.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,j.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)=>{dn.instance().add(s,()=>{A.info("[Dxf] Saved '"+e+"' to indexedDb"),n()},a=>{r(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{dn.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)&&G.isPointInPolygon(h[N.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{A.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 y={regions:[],inverted:!1};try{m.forEach((g,M)=>{if(Zt.epsilon(V.getVector2RelativeEps(e[g][0]),1e-6),M===0)y=Zt.segments({regions:[o(e[g])],inverted:!1});else{const w=Zt.segments({regions:[o(e[g])],inverted:!1}),b=Zt.combine(y,w);d=Zt.polygon(Zt.selectUnion(b)),d.regions.length>0?d.regions.forEach(C=>{if(C.length===0)return;const S=C.map(O=>new p.Vector2(O[0],O[1]));h.holes.push(new p.Path(S))}):A.warn("[Dxf] mergedHoles.regions is empty")}})}catch(g){A.warn("[Dxf] polybooljs has error: "+g+", epsilon is "+Zt.epsilon())}});const f=u.flat(2);for(let m=0;m<l[1].length;m++){const y=l[1][m];!f.includes(y)&&h.holes.push(new p.Path(e[y]))}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]];G.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&&G.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]&&A.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]&&A.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]:A.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===j.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();j.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else n&&(i.has(n.id)?r=i.get(n.id):(r=n.clone(),j.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 Je.Unitless;case 1:return Je.Inches;case 2:return Je.Feet;case 4:return Je.Millimeters;case 5:return Je.Centimeters;case 6:return Je.Meters;default:A.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return Je.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const n=e.matrixWorld;if(s.index&&(A.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=G.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){A.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)H.fromBufferAttribute(r,o).applyMatrix4(n),$.fromBufferAttribute(r,o+1).applyMatrix4(n),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+H.distanceTo($);else{a[0]=0;for(let o=1,l=r.count;o<l;o++)H.fromBufferAttribute(r,o-1).applyMatrix4(n),$.fromBufferAttribute(r,o).applyMatrix4(n),a[o]=a[o-1],a[o]+=H.distanceTo($)}s.setAttribute("lineDistance",new p.Float32BufferAttribute(a,1)),e.geometry=s}else A.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&&j.computeLineDistance(n)}),A.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];j.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={},y=[];for(const g of u){if(g.userData.isSnapObject){y.push(g);continue}let M,w=g;for(;w;){if(w.userData.isLayoutLevelObject){M=w;break}w=w.parent}if(!M)continue;const b=M.name;!m[b]&&(m[b]={object:M,children:[]}),m[b].children.push(g)}for(const g in m){const M=m[g],w=Tt.deepMerge(M.children,M.object,!1,!1,!0),b=w.added,C=w.removed;!s[g]&&(s[g]={object:M.object,children:[]}),!n[g]&&(n[g]={object:M.object,children:[]});const S=C.length>r;if(S){const O=Date.now();j.removeEmptyObjectsFromRemovingMarkedObjects2(C,M.object),o+=Date.now()-O}else a+=C.length;if(C.length===M.children.length)!S&&C.forEach(O=>{s[g].children.push(O)});else{let O=C;C.length>=100&&(O=new Set(C));const E=v=>Array.isArray(O)?O.indexOf(v)>=0:O.has(v);for(let v=0;v<M.children.length;v++){const T=M.children[v];E(T)?!S&&s[g].children.push(T):y.push(T)}}for(let O=0;O<b.length;O++){const E=b[O];y.push(E),n[g].children.push(E)}a>r&&l()}e.layersAndObjects[d]=y,A.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=[]}A.debug("[Dxf] MergeUtils.deepMerge took "+me.MergeInfo.elapsedTime/1e3+"s"),A.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),A.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const h=me.MergeInfo;A.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=N.getUpdateProgressFuncAsync(i),n={};e.objects.LAYOUT.forEach(g=>{const M=g;n[M.layoutName]=M,M.directAssociatedLeafObjectSet?.clear()});const r=Date.now(),a={},o={},l=15e3;let h=0,d=0;const u=()=>{const g=Date.now();for(const M in a){const w=a[M];j.removeEmptyObjectsFromRemovingMarkedObjects(w.children,w.object),w.children=[]}h=0,d+=Date.now()-g},f=Object.keys(e.layersAndThreejsObjects).length;let m=0;for(const g in e.layersAndThreejsObjects){const M=e.layersAndThreejsObjects[g];if(M.length<=1){await s(++m/f*100);continue}const w=Date.now(),b={},C=[];for(const E of M){if(E.userData.isSnapObject){C.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;!b[_]&&(b[_]={object:v,children:[]}),b[_].children.push(E)}const S=Object.keys(b).length;let O=0;for(const E in b){let v;if(E!==j.MODEL_LAYOUT_NAME){const k=n[E];!k.directAssociatedLeafObjectSet&&(k.directAssociatedLeafObjectSet=new Set),v=k.directAssociatedLeafObjectSet}const T=b[E],_=me.deepMerge(T.children,T.object,!1,!1,!0),P=_.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();j.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 D=z=>Array.isArray(k)?k.indexOf(z)>=0:k.has(z);for(let z=0;z<T.children.length;z++){const se=T.children[z];D(se)?!B&&a[E].children.push(se):(C.push(se),v&&v.add(se))}}for(let k=0;k<P.length;k++){const D=P[k];Q.setSharedVariablesOfObject(D),C.push(D),o[E].children.push(D),v&&v.add(D)}h>l&&u(),await s((m+ ++O/S)/f*100)}await s(++m/f*100),e.layersAndThreejsObjects[g]=C,A.debug("[Dxf] Merged layer '"+g+"' in "+(Date.now()-w)/1e3+"s")}h>0&&u();for(const g in o){const M=o[g],w=e.threejsObject.children.find(b=>b.name===g);if(w){const b=w.children.find(C=>C.name===j.SNAP_GROUP_NAME);if(b&&g!==j.MODEL_LAYOUT_NAME){const C=n[g];!C.directAssociatedLeafObjectSet&&(C.directAssociatedLeafObjectSet=new Set),b.children.forEach(S=>C.directAssociatedLeafObjectSet?.add(S))}}!w&&e.threejsObject.add(M.object),M.children.forEach(b=>{!b.visible&&(b.userData.layerVisible=!1),M.object.add(b),b.updateWorldMatrix(!1,!1)}),M.children=[]}A.debug("[Dxf] MergeUtils.deepMerge took "+me.MergeInfo.elapsedTime/1e3+"s"),A.debug("[Dxf] The remove operation of deep merge took "+d/1e3+"s"),A.debug("[Dxf] Deep merge totally took "+(Date.now()-r)/1e3+"s");const y=me.MergeInfo;A.debug("[Dxf] Totally merged "+y.removedObjects+" objects to "+y.mergedMeshes+"meshes, "+y.mergedLines+"lines, "+y.mergedPoints+"points, "+(y.mergedUnknownTypeObjects?y.mergedUnknownTypeObjects+" unknown type,":" ")+" "),s(100)}printStatsInfo(){const e=this.entityTypesAndTimes;for(const n in e)e[n].averageTime=e[n].totalTime/e[n].createCount;A.debug("[Dxf] Entity types and took how much time in ms:",e),A.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&&A.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const n=me.MergeInfo;A.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&&A.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)});A.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||Q.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===q.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}};x(j,"MODEL_LAYOUT_NAME","Model"),x(j,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),x(j,"SHOW_SNAP_OBJECT",!1),x(j,"CameraZoomUniform",{value:1}),x(j,"ViewportScaleUniform",{value:1}),x(j,"TransformMatrixUniform",{value:new p.Matrix4}),x(j,"ResolutionUniform",{value:new p.Vector2}),x(j,"LOADLLDATA",!1),x(j,"MaxFragmentUniforms",1024);let Z=j;class yr extends Gt{constructor(e){super();x(this,"viewer");x(this,"overlayRender");x(this,"drawableList");this.drawableList=new gs("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===He.Added?i.push(h):l.type===He.Removed?s.push(h):n.push(h))}const r=G.mergeBBoxes(i),a=G.mergeBBoxes(s),o=G.mergeBBoxes(n);this.drawableList.addDrawable(new wt(N.guid(),r,[.1,.9,.2,1])),this.drawableList.addDrawable(new wt(N.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new wt(N.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class xn{}const xi=new p.Matrix4,Hn=new p.Box3;class Li extends xn{constructor(e){super();x(this,"modelId");x(this,"modelData");x(this,"modelObject");x(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(),s=new p.Box3;i.updateWorldMatrix(!1,!0);const n=r=>{if(r.userData?.isSnapObject||r.userData?.isConstructionLine)return;const a=r.geometry;a&&(a.boundingBox||a.computeBoundingBox(),s.copy(a.boundingBox).applyMatrix4(r.matrixWorld),e.union(s));for(const o of r.children)n(o)};n(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return Je.Unitless;const e=this.dxfData.header;if(!e)return A.warn("DxfData or its header is undefined!"),Je.Unitless;const i=e.$INSUNITS;return Z.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new p.Vector3,s=new p.Vector3;if(!e){A.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,y=Z.getDcs2WcsMatrix(h,o),g=new p.Vector3(d.x,d.y,0);g.applyMatrix4(y),r={x:g.x-m/2,y:g.y-u/2,z:0},a={x:g.x+m/2,y:g.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(M=>parseInt(M.viewportId)===1);let d;h.length>0?d=h[0]:d=r[0];const{centerPoint:u,width_paperSpace:f,height_paperSpace:m}=d,y=Z.getDcs2WcsMatrix(d,l),g=new p.Vector3(u.x,u.y,0);g.applyMatrix4(y),a={x:g.x-f/2,y:g.y-m/2,z:0},o={x:g.x+f/2,y:g.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:A.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?Z.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(Ge):Z.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(Ge))}else A.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=ve.cloneMaterial(a.material));const o=ve.cloneMaterial(a.material);ve.setMaterialOpacity(o,i),Z.updateMaterialUniforms(o),a.material=o}}):A.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=ve.cloneMaterial(a.material));const o=ve.cloneMaterial(a.material);ve.setMaterialColor(o,new p.Color(i)),Z.updateMaterialUniforms(o),a.material=o}}):A.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)}):A.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(xi.identity(),!i||!N.isMatrixValid(i)||i.equals(xi))return;const s=this.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME);s&&(e===Z.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=Z.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!==Z.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 y=-1;const g=this.getObjectsByLayer(m);g&&(y=g.indexOf(f),y>=0&&g.splice(y,1)),y<0&&A.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+m+"', layout '"+e+"'")}}),d.forEach(u=>{u.removeFromParent()})}const l=this.getFilteredViewports(s);A.debug("[Viewer] Active layout:",e,", viewports:",l);const h=Date.now();l.forEach(d=>{this.generateObjectsByViewport(e,d,this)}),A.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!");Z.TransformMatrixUniform={value:r.msToPsMatrix},Z.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=Vt.generateSectionPlanesByBox(d),f=[],m=T=>(!f[T.id]&&(f[T.id]=T.clone(),this.setMaterialUniforms(f[T.id],s.dxfData),Vt.setMaterialSection(f[T.id],u)),f[T.id]),y=T=>{if(Array.isArray(T)){const _=[];return T.forEach(P=>{const I=m(P);_.push(I)}),_}else return m(T)},g=[...n,...i.frozenLayerHandles||[]];let M;if(e!==Z.MODEL_LAYOUT_NAME){const T=r;!T.associatedLeafObjectSet&&(T.associatedLeafObjectSet=new Set),M=T.associatedLeafObjectSet}const w=new p.Group;w.name=r.viewportId;const b=[];if(o.forEach(T=>{const _=T.clone();_.traverse(P=>{const I=P;if(I.material&&I.geometry){const B=I.userData.layerName;if(this.isLayerFrozenForViewport(B,g)){b.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=y(I.material),M?.add(I);const k=s.getObjectsByLayer(B);k?k.push(I):A.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+B+"', layout '"+e+"'")}}),w.add(_)}),M&&M.size===0)return;const C=s.getModelObject();let S=s.getLayoutLevelObject(e);!S&&(S=new p.Group,Q.setSharedVariablesOfObject(S),S.name=e,C?.add(S)),S.add(w),w.applyMatrix4(r.msToPsMatrix),w.updateMatrixWorld(!0);let O=S.children.find(T=>T.name===Z.SNAP_GROUP_NAME);!O&&(O=new p.Group,O.visible=Z.SHOW_SNAP_OBJECT,O.name=Z.SNAP_GROUP_NAME,S.add(O));const E=s.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME),v=E?.children.find(T=>T.name===Z.SNAP_GROUP_NAME);v&&v.traverse(T=>{if(!T.geometry)return;const _=T.userData.layerName;if(this.isLayerFrozenForViewport(_,g)||(Hn.makeEmpty(),Hn.expandByObject(T),!a.intersectsBox(Hn)))return;const P=T.clone();Q.setSharedVariablesOfObject(P);let I=P.parent;const B=xi.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)B.premultiply(I.matrix),I=I.parent;B.premultiply(r.msToPsMatrix),P.applyMatrix4(B),O?.add(P),M?.add(P);const k=s.getObjectsByLayer(_);k&&k.push(P)}),b.length>0&&Q.removeEmptyObjectsFromRemovingObjects(b,w),w.traverse(T=>{Q.setSharedVariablesOfObject(T),this.addSpatialFilterSection(T,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=Z.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=Z.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return A.warn("[Viewer] bbox is empty !"),i;const s=r=>{const a=Pt.getBoundingBox(r,!1);e.intersectsBox(a)&&i.push(r)},n=this.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME);return n&&n.children.forEach(r=>{r.name!==Z.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++}),A.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){A.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>Z.MaxFragmentUniforms},d=new Set,u=f=>{d.has(f.id)||(d.add(f.id),!h(f)&&Vt.setMaterialSection(f,l,r,a))};e.traverse(f=>{const m=f.material;Array.isArray(m)?m.forEach(y=>{u(y)}):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){A.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}xi.copy(i),e.localMatrix&&xi.multiply(e.localMatrix);const n=s.polyline,r=[];n.forEach(l=>{const h=l.clone().applyMatrix4(xi);r.push(new p.Vector2(h.x,h.y))});const a=p.ShapeUtils.isClockWise(r),o=!a&&!s.bReversed||a&&s.bReversed;return Vt.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=ve.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 Ar extends xn{constructor(e){super();x(this,"modelId");x(this,"bbox");x(this,"rootObject");x(this,"modelObject");x(this,"highlighUsage");x(this,"transparentUsage");x(this,"edges");x(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(Nt),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(Nt),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&Q.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&Q.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 Q.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(me.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(Er);if(e instanceof p.InstancedMesh&&s){const r=this.createInstanceMeshById(e,s,{depthTest:!1});r.material.opacity=.7,ve.setMaterialColor(r.material,n),e.userData.instanceId=s,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else if(me.isMergedMesh(e)&&i){const r=this.createBatchMeshById(e,i,{depthTest:!1});r.material.opacity=.7,ve.setMaterialColor(r.material,n),e.userData.batchId=i,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else{const r=ve.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=me.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+r?.name,r?.userData&&(a+=`
|
|
796
|
+
`){u=0,f-=m*.5;continue}let 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(H).x,T=O.charCodeAt(0),_=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+M;C++,u+=_+(C===b?0:l)}d.push(E)}}if(d.length>0){const S=d.filter(E=>E instanceof p.ExtrudeGeometry),O=d.filter(E=>!(E instanceof p.ExtrudeGeometry));if(S.length>0){const E=new U(q.Mesh);E.geometry=Ie.mergeGeometries(S),E.material=yi,h.add(E)}if(O.length>0){const E=new U(q.LineSegment);E.geometry=Ie.mergeGeometries(O),E.material=ye,h.add(E)}}return h}transformTextMesh(e,i){pt.makeEmpty();const s=U.getBox(i,pt),n=s.getSize(H),{halign:r,valign:a}=e;i.matrix.decompose(Ns.position,Ns.quaternion,Ns.scale);const o=Ns,l=e.width||e.textWidth||n.x,h=e.height||e.textHeight||n.y,d=s.min.y+n.y/2;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 u=e.rotation*Math.PI/180;o.rotateZ(u)}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 u=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new p.Vector3().subVectors(u,f),x=m.length(),g=x/l;o.scale.multiplyScalar(g);const M=m.clone().cross(Ke),w=m.angleTo(Ke);o.rotateZ(M.z>0?Math.PI-w:w-Math.PI),(e.mirrored===2||e.mirrored===4)&&o.rotateX(Math.PI)}break;case 4:o.translateX(-l/2),o.translateY(-d);break;case 5:if(e.startPoint&&e.endPoint){const u=new p.Vector3(e.startPoint.x,e.startPoint.y,e.startPoint.z),f=new p.Vector3(e.endPoint.x,e.endPoint.y,e.endPoint.z),m=new p.Vector3().subVectors(u,f),x=m.length(),g=x/l,w=(e.text||"").length;if(w>1){const S=(x-l)/(w-1);o.userData.letterSpacing=S}else g<3&&o.scale.setX(g);const b=m.clone().cross(Ke),C=m.angleTo(Ke);o.rotateZ(b.z>0?Math.PI-C:C-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}addTextUnderscores(e,i,s){const n=[];let r=0,a=null;for(const x of e){const g=x.text.length;g<=0||(x.u&&a===null&&(a=r),!x.u&&a!==null&&(n.push([a,r]),a=null),r+=g)}if(a!==null&&n.push([a,r]),!n.length)return;const o=new p.Box3;if(i.traverse(x=>{x.geometry&&(x.geometry.computeBoundingBox(),x.geometry.boundingBox&&o.union(x.geometry.boundingBox))}),!Number.isFinite(o.min.x)||!Number.isFinite(o.max.x))return;const l=e.reduce((x,g)=>x+g.text.length,0);if(l<=0)return;const h=o.min.x,d=(o.max.x-o.min.x)/l,u=o.min.y-s*.12,f=Math.max(s*.06,1e-6);let m;i.traverse(x=>{!m&&x.material&&(m=x.material)});for(const[x,g]of n){const M=h+x*d,w=h+g*d;if(w-M<=1e-9)continue;const b=u,C=u+f,S=new p.BufferGeometry;S.setAttribute("position",new p.Float32BufferAttribute([M,b,0,w,b,0,w,C,0,M,b,0,w,C,0,M,C,0],3)),S.setIndex([0,1,2,3,4,5]);const O=new U(q.Mesh);O.geometry=S,O.material=m,i.add(O)}}loadText(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] Text (handle '%s') has non-finite placement, ignored!",e.handle),void 0;const n=e.text;if(!n)return;if(!this.font){A.info("[Dxf] Font file not set, ignoring text entity.");return}const r=this.getTextStyle(i,e),a=an(n,{encoding:this.getTextEncoding(r)}),o=a.map(d=>d.text).join(""),l=this.getTextMesh(o,e.textHeight,r,e);if(!l||l.children.length===0)return;this.addTextUnderscores(a,l,e.textHeight??1),this.transformTextMesh(e,l),H.set(l.matrix.elements[12],l.matrix.elements[13],l.matrix.elements[14]);const h=G.shouldRebasePositionOnRTC(H);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 x=0;x<f.count;x+=3)m.push(x,x+1,x+2);u.setIndex(m)}if(u.hasAttribute("uv")&&u.deleteAttribute("uv"),u.hasAttribute("normal")&&u.deleteAttribute("normal"),!h){const f=G.caculateGeometryCenter(u);f&&G.shouldRebasePositionOnRTC(f)&&this.setRTCUserData(d)}}}),l.layers.enableAll(),l}loadAttDef(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] AttDef (handle '%s') has non-finite placement, ignored!",e.handle),void 0;let n=e.tag||e.text||e.prompt;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=an(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),H.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const l=G.shouldRebasePositionOnRTC(H);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=G.caculateGeometryCenter(d);u&&G.shouldRebasePositionOnRTC(u)&&this.setRTCUserData(h)}}}),o.layers.enableAll(),o}loadAttrib(e,i,s){if(!j.hasFiniteTextPlacement(e))return A.warn("[Dxf] Attrib (handle '%s') has non-finite placement, ignored!",e.handle),void 0;let n=e.text;if(!n||!this.font)return;const r=this.getTextStyle(i,e);n=an(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),H.set(o.matrix.elements[12],o.matrix.elements[13],o.matrix.elements[14]);const d=G.shouldRebasePositionOnRTC(H);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"),x=[];for(let g=0;g<m.count;g+=3)x.push(g,g+1,g+2);f.setIndex(x)}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=G.caculateGeometryCenter(f);m&&G.shouldRebasePositionOnRTC(m)&&this.setRTCUserData(u)}}}),o.layers.enableAll(),o}loadPoint(e,i,s){if(!j.isFinitePoint(e.position))return;const n=new p.BufferGeometry,r=[new p.Vector3(e.position.x,e.position.y,e.position.z)];H.set(0,0,0);const a=H;let o=!1;this.enableRTC&&(o=G.checkAndRebasePositionsOnRTC(r,a)),n.setFromPoints(r);const l=new U(q.Point);return l.geometry=n,l.material=ye,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 U;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 H.set(0,0,0),a&&H.set(a.x,a.y,0),G.shouldRebasePositionOnRTC(H)&&this.setRTCUserData(r),r.matrix.setPosition(H),r}loadImage(e,i,s){if(!e.imageSize||!i.objects.IMAGEDEF?.length)return;const n=i.objects.IMAGEDEF.filter(g=>g.handle===e.imageDefHandle)[0];if(!n)return;const r=e.imageSize.x,a=e.imageSize.y,o=new U;let l=!1;e.flags===on.ShowImageWhenNotAlignedWithScreen||e.flags===on.UseClippingBoundary||e.flags===on.TransparencyIsOn||(l=!0);const h=new p.PlaneGeometry(r,a);if(l){const g=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.")});g.colorSpace=p.SRGBColorSpace;const M=new p.MeshBasicMaterial({transparent:!0,side:p.FrontSide,map:g}),w=new U(q.Mesh);w.geometry=h,w.material=M,o.add(w)}const d=new p.EdgesGeometry(h),u=this.getColor(e,i,s),f=new U(q.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),x=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),$.set(m.x,x.y,1),H.set(0,0,0),e.position){const g=new p.Vector3(e.position.x,e.position.y,e.position.z);g.add(m.multiplyScalar(r/2)).add(x.multiplyScalar(a/2)),H.copy(g)}return G.shouldRebasePositionOnRTC(H)&&this.setRTCUserData(o),xe.identity(),o.matrix.compose(H,xe,$),o}loadInsert(e,i,s,n=!1){if(!e||!e.block)return;if(e.position&&!j.isFinitePoint(e.position))return A.warn("[Dxf] Insert (handle '%s') has non-finite position, ignored!",e.handle),void 0;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 U,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 x=this.loadEntity(r.entities[m],i,e,n);x&&(o&&j.LOADLLDATA&&(x.userData.llbData=o),l!==void 0&&x.traverse(g=>{g.geometry&&(g.userData.xdata=l)}),a.add(x))}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=H.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),xe.setFromEuler(d,!1);const u=$.set(0,0,0);e.position&&(u.x=e.position.x,u.y=e.position.y),fe.compose(u,xe,h),e.extrusionDirection&&e.extrusionDirection.z<0&&fe.premultiply(_a.identity().makeScale(-1,1,1)),rt.copy(a.matrix),a.matrix.premultiply(fe),$.set(a.matrix.elements[12],a.matrix.elements[13],a.matrix.elements[14]),G.shouldRebasePositionOnRTC($)&&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),A.debug("[Dxf] Spatial filter:",e.associatedSpatialFilter))}return a}loadSpatialFilter(e){const i=e;if(i.threejsObject)return i.threejsObject.clone();const s=e.invertBlockMatrix;if(!Array.isArray(s)||s.length<12)return A.warn("[Dxf] Spatial filter (handle '"+e.handle+"') has no invertBlockMatrix, ignored!"),void 0;fe.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 A.warn("[Dxf] Invalid clipBoundary: "+e.handle+" !"),void 0;let h=[],d=-1;for(let m=0;m<o;m++){const x=n[m];for(let g=o-1;g>m;g--){const M=n[g];if(V.areVector3sEqual(x,M)&&m+1<g-1&&m+1<o-1&&V.areVector3sEqual(n[m+1],n[g-1])){h.push(x),d=g;break}}if(d>0)break;h.push(x)}if(d>0)for(let m=d+1;m<o;m++)h.push(n[m]);if(h.length<l)return A.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])}),!G.isConvex(u)){A.warn("[Dxf] Concave polygon is not supported for spatial filter (handle '"+e.handle+"'), converting to convex polygon!");const m=Al(f,1/0);h=[],m.forEach(x=>{h.push(new p.Vector3(x[0],x[1],0))})}!V.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=fe.clone(),i.clipPolylines=[],i.clipPolylines.push(r),a}loadLayout(e,i,s,n,r,a){if(!e.entities)return;const o=new U;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&&Ct.merge(f,!1),o.add(f),f.traverse(m=>{if(m.geometry){const x=m.userData.layerName;let g=r[x];!g&&(g=[],r[x]=g),g.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 U,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;const s=e.type,n=r=>!!r&&Number.isFinite(r.x)&&Number.isFinite(r.y);switch(s){case Si.Line:{const r=e;if(!n(r.startPoint)||!n(r.endPoint))break;i.push(new p.Vector2(r.startPoint.x,r.startPoint.y)),i.push(new p.Vector2(r.endPoint.x,r.endPoint.y));break}case Si.Arc:{const r=e;if(!n(r.center)||!Number.isFinite(r.radius)||r.radius<=0||!Number.isFinite(r.startAngle)||!Number.isFinite(r.endAngle))break;let a=r.startAngle*p.MathUtils.DEG2RAD,o=r.endAngle*p.MathUtils.DEG2RAD;!r.bCounterclockwise&&(a=Math.PI*2-a,o=Math.PI*2-o);const l=new p.ArcCurve(r.center.x,r.center.y,r.radius,a,o,!r.bCounterclockwise),h=this.getDivision(a,o,r.radius),d=l.getPoints(h);e.startPoint=d[0],e.endPoint=d[d.length-1],i.push(...d);break}case Si.Ellipse:{const r=e;if(!n(r.center)||!n(r.majorAxisEndPoint)||!Number.isFinite(r.minorRatio)||!Number.isFinite(r.startAngle)||!Number.isFinite(r.endAngle))break;const a=Math.sqrt(Math.pow(r.majorAxisEndPoint.x,2)+Math.pow(r.majorAxisEndPoint.y,2)),o=a*r.minorRatio,l=Math.atan2(r.majorAxisEndPoint.y,r.majorAxisEndPoint.x);let h=r.startAngle*p.MathUtils.DEG2RAD,d=r.endAngle*p.MathUtils.DEG2RAD;!r.bCounterclockwise&&(h=Math.PI*2-h,d=Math.PI*2-d);const u=new p.EllipseCurve(r.center.x,r.center.y,a,o,h,d,!r.bCounterclockwise,l),f=this.getDivision(h,d,Math.max(a,o)),m=u.getPoints(f);e.startPoint=m[0],e.endPoint=m[m.length-1],i.push(...m);break}case Si.Spline:{const r=e,a=La(r.controlPoints,r.degreeOfSplineCurve,r.knotValues);if(a.length===0)break;e.startPoint=a[0],e.endPoint=a[a.length-1],i.push(...a);break}case Si.Polyline:{const r=e,a=Nn(r.points,r.isClosed);e.startPoint=a[0],e.endPoint=a[a.length-1],i.push(...a);break}}return i}loadHatch(e,i,s){const n=e;let r=[];function a(E,v){const{startPoint:T,endPoint:P}=E,{startPoint:_,endPoint:I}=v;if(!T||!P||!_||!I)return null;const B=P.x-T.x,k=P.y-T.y,D=I.x-_.x,z=I.y-_.y,se=B*z-k*D;if(Math.abs(se)<1e-10)return null;const re=T.x-_.x,je=T.y-_.y,Le=(D*je-z*re)/se,de=(B*je-k*re)/se;return Le>=0&&Le<=1&&de>=0&&de<=1?{x:T.x+Le*B,y:T.y+Le*k}:null}function o(E){const{edges:v}=E,T=[],P=v.length;if({...E},P!==4)return[E];for(let _=0;_<P;_++)for(let I=_+2;I<P;I++){if(I===_+1||_===0&&I===P-1)continue;const B=a(v[_],v[I]);B&&T.push({edgeIndex1:_,edgeIndex2:I,point:{x:B.x,y:B.y}})}if(T.length&&T.length===1){const _=v[(T[0].edgeIndex1-1+P)%P],I={pathTypeFlag:E.pathTypeFlag,edges:[_,{startPoint:{...v[T[0].edgeIndex1].startPoint},endPoint:{x:T[0].point.x,y:T[0].point.y},type:v[T[0].edgeIndex1].type},{startPoint:{x:T[0].point.x,y:T[0].point.y},endPoint:{x:v[T[0].edgeIndex2].startPoint.x,y:v[T[0].edgeIndex2].startPoint.y},type:v[T[0].edgeIndex2].type}]},B={pathTypeFlag:E.pathTypeFlag,edges:[{startPoint:{x:T[0].point.x-1e-5,y:T[0].point.y-1e-5},endPoint:{...v[T[0].edgeIndex1].endPoint},type:v[T[0].edgeIndex1].type},{...v[T[0].edgeIndex2-1]},{startPoint:v[T[0].edgeIndex2].startPoint,endPoint:{x:T[0].point.x-1e-5,y:T[0].point.y-1e-5},type:v[T[0].edgeIndex2].type}]};return[I,B]}return[E]}if(n.boundaryPaths.length==0)return;for(let E=0;E<n.boundaryPaths.length;E++){const v=n.boundaryPaths[E],T=o(v);r=[...r,...T]}if(n.boundaryPaths=r,!n.solidFill&&!n.patternLines?.length){A.warn("[Dxf] Hatch entity(handle: '"+n.handle+"') doesn't have solid fill, nor patternLines, ignored!");return}const l=[],h=[],d=[],u=E=>{const v=[];let T=[];T.push(...this.convertEdgeToPoints(E[0]));for(let P=1;P<E.length;P++){const _=this.convertEdgeToPoints(E[P]);if(T.push(..._),T.length>2){const I=this.convertEdgeToPoints(E[P-1]);V.areVector2sEqual(I[I.length-1],_[0])?V.areVector2sEqual(T[0],_[_.length-1],1e-5)&&(v.push(T),T=[]):V.areVector2sEqual(I[0],_[_.length-1])?V.areVector2sEqual(T[1],_[0],1e-5)&&(v.push(T),T=[]):T=[]}}return v},f=E=>{for(let v=1;v<E.length;++v){const T=E[v-1].endPoint,P=E[v].startPoint;if(!T||!P||!V.areVector2sEqual(T,P))return!1}return!0},m=E=>{const v=[];let T=[];for(let P=0;P<E.length;P++){const _=this.convertEdgeToPoints(E[P]);if(!(_.length<2)){if(T.length>2&&V.areVector2sEqual(T[0],T[T.length-1],1e-5)){const I=T[T.length-1],B=V.areVector2sEqual(I,_[0],1e-5),k=V.areVector2sEqual(I,_[_.length-1],1e-5);!B&&!k&&(v.push(T),T=[])}T.length>0&&!V.areVector2sEqual(T[T.length-1],_[0],1e-5)&&V.areVector2sEqual(T[T.length-1],_[_.length-1],1e-5)&&_.reverse(),T.push(..._)}}return T.length>2&&v.push(T),v};if(n.boundaryPaths.forEach((E,v)=>{let T=[];if(this.IsfilteredByPathTypeFlag(E.pathTypeFlag)){A.info("[Dxf] The %d path type flag is filtered at the %dth boundrayPath (hatch handle '%s')",E.pathTypeFlag,v,n.handle);return}const P=E.edges;if(P.length===0)return;const _=[];for(let I=0;I<P.length;I++){const B=this.convertEdgeToPoints(P[I]);if(B.length<2){A.warn("[Dxf] The %dth edge of the %dth boundaryPath (hatch handle '%s') has less than 2 points, ignored!",I,v,n.handle);continue}_.push(...B)}if(_.length<3){A.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has less than 3 points, ignored!",v,n.handle);return}if(T.push(_),E.pathTypeFlag>Do.MaxFlags){if((!f(E.edges)||!n.associativity)&&(T=u(P),T.length<2)){A.warn("[Dxf] The %dth boundaryPath (hatch handle '%s') has unknown path, ignored!",v,n.handle);return}}else if(!f(E.edges)){const I=m(P);I.length>0&&(T=I)}T.forEach(I=>{!V.areVector2sEqual(I[0],I[I.length-1])&&I.push(I[0]);const B=I.map(k=>new p.Vector2(N.roundNumber(k.x,7),N.roundNumber(k.y,7)));if(B?.length>0){l.push(B);const k=new p.Box2().setFromPoints(B);h.push(k);const D=k.getSize(Xi),z=D.x*D.y;d.push({area:z,index:l.length-1})}})}),l.length===0)return;const x=new p.Vector2,g=this.checkAndRebasePolygonsOnRTC(l,x);d.sort((E,v)=>E.area-v.area);const M=[];d.forEach(E=>{M.push(E.index)});const w=this.buildContainHierarchyTree(l,h,M),b=[];this.buildHatchGeometry(l,w,b);let C;if(b.length>0&&(C=Ie.mergeGeometries(b)),!C||!C.getIndex()||C.getIndex()?.count===0)return A.warn("[Dxf] Failed to convert hatch boundaries!"),void 0;const S=new U(q.Mesh);S.geometry=C,S.material=yi,this.setHatchMaterial(S,n,i,x,s);const O=S;return g&&(this.setRTCUserData(O),O.matrix.setPosition(x.x,x.y,0)),O.traverse(E=>{E.layers.enableAll(),E.layers.disable(qe)}),O}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=G.checkAndRebasePositionsOnRTC(o,l));const d=new p.BufferGeometry().setFromPoints(o),u=this.getLineBasicMaterial(16777215),f=new U(q.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 U;m.add(f);let x;const g=i.objects.DICTIONARY;for(const w of g)for(const b in w.entries)if(w.entries[b]===e.handle){x=b;break}let M;if(x)if(this.meshTextureMaterials[x])M=this.meshTextureMaterials[x];else for(let w=0;w<i.objects.XRECORD.length;w++){const b=i.objects.XRECORD[w];if(b.handle===x){const C=b.binaryData,S=N.hexToBase64(C),O="data:image/jpg;base64,"+S,E=new p.TextureLoader(this.manager).load(O);E.colorSpace=p.SRGBColorSpace;const v=new p.MeshBasicMaterial({transparent:!0,map:E});this.meshTextureMaterials[x]=v,M=v;break}}if(M){const w=new p.Box2().setFromPoints(o),b=w.getSize(Xi),C=new p.PlaneGeometry(b.x,b.y),S=new U(q.Mesh);S.geometry=C,S.material=M;const O=w.getCenter(Xi);H.set(O.x,O.y,0),h&&(this.setRTCUserData(S),H.x+=l.x,H.y+=l.y),S.matrix.setPosition(H),S.layers.enableAll(),m.add(S)}return m.children.length>1?m:f}static isFinitePoint(e){return!!e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&(e.z===void 0||Number.isFinite(e.z))}static hasFiniteTextPlacement(e){return e.position&&!j.isFinitePoint(e.position)||e.startPoint&&!j.isFinitePoint(e.startPoint)||e.endPoint&&!j.isFinitePoint(e.endPoint)?!1:Number.isFinite(e.rotation??0)}static getOcsMatrix(e){let i=Ke,s=jn,n=gi;const r=new p.Vector3(0,1,0),a=new p.Vector3(0,0,1);return V.areVectorsClose(e,a)?fe.identity():(n=e.clone().normalize(),!V.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()),fe.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;_1(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(V.roundNumber(s.x,7),V.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=gi.clone().cross(r),l.length()>0?(l.normalize(),h=d.clone().cross(l)):d.z<0?(l=Ke.clone().negate(),h=jn,d=gi.clone().negate()):(l=Ke,h=jn,d=gi);const u=new p.Matrix4,f=fe.identity();return f.makeBasis(l,h,d),u.premultiply(f),u.premultiply(fe.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=j.getDcs2WcsMatrix(e,this.angDir),d=new p.Matrix4;d.setPosition(Oa.clone().sub(r));const u=_a.identity();u.scale(H.set(l,l,l));const f=rt.identity().setPosition(Oa.clone().sub(r));u.premultiply(f.clone().invert()).multiply(f),d.multiply(u);const m=fe.identity();m.setPosition(n),h.multiply(m);const x=fe.identity();return d.invert().multiply(x).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=G.checkAndRebasePositionsOnRTC(o,h));const d=new p.BufferGeometry().setFromPoints(o),u=new U(q.Line);u.geometry=d,u.material=ye,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 x=!1;const g=new p.Vector3;this.enableRTC&&(x=G.checkAndRebasePositionsOnRTC(m,g));const M=new p.BufferGeometry().setFromPoints(m),w=new U(q.Line);w.geometry=M,w.material=ye,w.userData.entityType=e.type,w.userData.inPaperSpace=[],w.layers.enableAll(),x&&(this.setRTCUserData(w),w.matrix.setPosition(g.x,g.y,0));const b=new U;return b.add(u),b.add(w),u}getColor(e,i,s){if(this.compareContext)return ht.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!";A.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=Ft;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 A.warn("[Dxf] Unknown colorIndex"),Ft}getLineType(e,i,s){if(s&&s.type==="DIMENSION")return this.getLineType(s,i);if(e.lineType!==_r&&e.lineType!==us)return e.lineType;if(e.lineType===us)return s?this.getLineType(s,i):e.lineType;const n=i.tables?.layer?.layers,r=P1;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=be.Text;return}if(i.type==="HATCH"){Xi.set(0,0),this.setHatchMaterial(e,i,s,Xi,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=be.LineWithWidth):e.userData.isOutline&&(a=this.getLineBasicMaterial(o),e.renderOrder=be.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=be.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=be.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===q.Line||a.type===q.LineSegment){a.material=this.getLineBasicMaterial(o);return}let l=be.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(),j.updateMaterialUniforms(h),h.uniforms.u_color.value.set(o))}else h=this.getHatchShaderMaterial(i,o,n);l=be.MeshWithPattern}!h&&(h=this.getMeshBasicMaterial(o),l=be.Mesh),a.material=h,a.renderOrder=l}setRenderOrderByObjectType(e){const i=e;let s=0;i.isMesh?s=be.Mesh:i.isLine?s=be.Line:i.isPoints&&(s=be.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,j.ViewportScaleUniform,j.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)),x=new p.Vector2(f.delta.x,f.delta.y).rotateAround(d,-p.MathUtils.degToRad(f.angle));if(x.y===0)return A.warn("[Dxf] delta.y is equal to zero !"),void 0;const g=f.dashPattern.length;let M=!0,w=0;for(let v=0;v<g;++v){const T=f.dashPattern[v];T>0&&(M=!1),w+=Math.abs(T)}const b=M?a:r,C=[],S=[];let O=0;S[0]=O;for(let v=0;v<g;++v)C[v]=f.dashPattern[v],C[v]===0&&(C[v]=b*w),O+=Math.abs(C[v]),S[v+1]=O;for(let v=g;v<o;++v)C[v]=0;for(let v=S.length;v<o+1;++v)S[v]=O;const E={origin:m,delta:x,angle:f.angle-e.patternAngle,pattern:C,patternSum:S,patternLength:O};if(l+=4,l+=o,l+=o+1,l>j.MaxFragmentUniforms){A.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,j.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)=>{dn.instance().add(s,()=>{A.info("[Dxf] Saved '"+e+"' to indexedDb"),n()},a=>{r(a)})})}async getDxfDataFromIndexedDb(e){return new Promise((i,s)=>{dn.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)&&G.isPointInPolygon(h[N.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{A.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 x={regions:[],inverted:!1};try{m.forEach((g,M)=>{if(Zt.epsilon(V.getVector2RelativeEps(e[g][0]),1e-6),M===0)x=Zt.segments({regions:[o(e[g])],inverted:!1});else{const w=Zt.segments({regions:[o(e[g])],inverted:!1}),b=Zt.combine(x,w);d=Zt.polygon(Zt.selectUnion(b)),d.regions.length>0?d.regions.forEach(C=>{if(C.length===0)return;const S=C.map(O=>new p.Vector2(O[0],O[1]));h.holes.push(new p.Path(S))}):A.warn("[Dxf] mergedHoles.regions is empty")}})}catch(g){A.warn("[Dxf] polybooljs has error: "+g+", epsilon is "+Zt.epsilon())}});const f=u.flat(2);for(let m=0;m<l[1].length;m++){const x=l[1][m];!f.includes(x)&&h.holes.push(new p.Path(e[x]))}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]];G.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&&G.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]&&A.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]&&A.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]:A.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===j.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();j.updateMaterialUniforms(l),i.set(o.id,l),a.push(l)}})}else n&&(i.has(n.id)?r=i.get(n.id):(r=n.clone(),j.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 Qe.Unitless;case 1:return Qe.Inches;case 2:return Qe.Feet;case 4:return Qe.Millimeters;case 5:return Qe.Centimeters;case 6:return Qe.Meters;default:A.warn("[Dxf] Unsupported $INSUNITS '"+e+"'");break}return Qe.Unitless}static computeLineDistance(e){const i=e.isLineSegments===!0;let s=e.geometry;const n=e.matrixWorld;if(s.index&&(A.debug("[Dxf] Line with id '"+e.id+"' contains index buffer, going to convert it to non-indexed."),s=G.convertGeometryWithIndexedToNonIndexed(s),e.userData.batches&&e.userData.batches.length>0)){A.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)H.fromBufferAttribute(r,o).applyMatrix4(n),$.fromBufferAttribute(r,o+1).applyMatrix4(n),a[o]=o===0?0:a[o-1],a[o+1]=a[o]+H.distanceTo($);else{a[0]=0;for(let o=1,l=r.count;o<l;o++)H.fromBufferAttribute(r,o-1).applyMatrix4(n),$.fromBufferAttribute(r,o).applyMatrix4(n),a[o]=a[o-1],a[o]+=H.distanceTo($)}s.setAttribute("lineDistance",new p.Float32BufferAttribute(a,1)),e.geometry=s}else A.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&&j.computeLineDistance(n)}),A.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];j.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={},x=[];for(const g of u){if(g.userData.isSnapObject){x.push(g);continue}let M,w=g;for(;w;){if(w.userData.isLayoutLevelObject){M=w;break}w=w.parent}if(!M)continue;const b=M.name;!m[b]&&(m[b]={object:M,children:[]}),m[b].children.push(g)}for(const g in m){const M=m[g],w=Ct.deepMerge(M.children,M.object,!1,!1,!0),b=w.added,C=w.removed;!s[g]&&(s[g]={object:M.object,children:[]}),!n[g]&&(n[g]={object:M.object,children:[]});const S=C.length>r;if(S){const O=Date.now();j.removeEmptyObjectsFromRemovingMarkedObjects2(C,M.object),o+=Date.now()-O}else a+=C.length;if(C.length===M.children.length)!S&&C.forEach(O=>{s[g].children.push(O)});else{let O=C;C.length>=100&&(O=new Set(C));const E=v=>Array.isArray(O)?O.indexOf(v)>=0:O.has(v);for(let v=0;v<M.children.length;v++){const T=M.children[v];E(T)?!S&&s[g].children.push(T):x.push(T)}}for(let O=0;O<b.length;O++){const E=b[O];x.push(E),n[g].children.push(E)}a>r&&l()}e.layersAndObjects[d]=x,A.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=[]}A.debug("[Dxf] MergeUtils.deepMerge took "+me.MergeInfo.elapsedTime/1e3+"s"),A.debug("[Dxf] The remove operation of deep merge took "+o/1e3+"s"),A.debug("[Dxf] Deep merge totally took "+(Date.now()-i)/1e3+"s");const h=me.MergeInfo;A.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=N.getUpdateProgressFuncAsync(i),n={};e.objects.LAYOUT.forEach(g=>{const M=g;n[M.layoutName]=M,M.directAssociatedLeafObjectSet?.clear()});const r=Date.now(),a={},o={},l=15e3;let h=0,d=0;const u=()=>{const g=Date.now();for(const M in a){const w=a[M];j.removeEmptyObjectsFromRemovingMarkedObjects(w.children,w.object),w.children=[]}h=0,d+=Date.now()-g},f=Object.keys(e.layersAndThreejsObjects).length;let m=0;for(const g in e.layersAndThreejsObjects){const M=e.layersAndThreejsObjects[g];if(M.length<=1){await s(++m/f*100);continue}const w=Date.now(),b={},C=[];for(const E of M){if(E.userData.isSnapObject){C.push(E);continue}let v,T=E;for(;T;){if(T.userData.isLayoutLevelObject){v=T;break}T=T.parent}if(!v)continue;const P=v.name;!b[P]&&(b[P]={object:v,children:[]}),b[P].children.push(E)}const S=Object.keys(b).length;let O=0;for(const E in b){let v;if(E!==j.MODEL_LAYOUT_NAME){const k=n[E];!k.directAssociatedLeafObjectSet&&(k.directAssociatedLeafObjectSet=new Set),v=k.directAssociatedLeafObjectSet}const T=b[E],P=me.deepMerge(T.children,T.object,!1,!1,!0),_=P.added,I=P.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();j.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 D=z=>Array.isArray(k)?k.indexOf(z)>=0:k.has(z);for(let z=0;z<T.children.length;z++){const se=T.children[z];D(se)?!B&&a[E].children.push(se):(C.push(se),v&&v.add(se))}}for(let k=0;k<_.length;k++){const D=_[k];Q.setSharedVariablesOfObject(D),C.push(D),o[E].children.push(D),v&&v.add(D)}h>l&&u(),await s((m+ ++O/S)/f*100)}await s(++m/f*100),e.layersAndThreejsObjects[g]=C,A.debug("[Dxf] Merged layer '"+g+"' in "+(Date.now()-w)/1e3+"s")}h>0&&u();for(const g in o){const M=o[g],w=e.threejsObject.children.find(b=>b.name===g);if(w){const b=w.children.find(C=>C.name===j.SNAP_GROUP_NAME);if(b&&g!==j.MODEL_LAYOUT_NAME){const C=n[g];!C.directAssociatedLeafObjectSet&&(C.directAssociatedLeafObjectSet=new Set),b.children.forEach(S=>C.directAssociatedLeafObjectSet?.add(S))}}!w&&e.threejsObject.add(M.object),M.children.forEach(b=>{!b.visible&&(b.userData.layerVisible=!1),M.object.add(b),b.updateWorldMatrix(!1,!1)}),M.children=[]}A.debug("[Dxf] MergeUtils.deepMerge took "+me.MergeInfo.elapsedTime/1e3+"s"),A.debug("[Dxf] The remove operation of deep merge took "+d/1e3+"s"),A.debug("[Dxf] Deep merge totally took "+(Date.now()-r)/1e3+"s");const x=me.MergeInfo;A.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 n in e)e[n].averageTime=e[n].totalTime/e[n].createCount;A.debug("[Dxf] Entity types and took how much time in ms:",e),A.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&&A.debug("[Dxf] Totally rebased "+this.statsInfo.rebasedEntityCount+"(out of "+i+") entities"),this.enableMerge){const n=me.MergeInfo;A.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&&A.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)});A.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||Q.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===q.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}};y(j,"MODEL_LAYOUT_NAME","Model"),y(j,"SNAP_GROUP_NAME","InvisibleObjectGroupForOSnap"),y(j,"SHOW_SNAP_OBJECT",!1),y(j,"CameraZoomUniform",{value:1}),y(j,"ViewportScaleUniform",{value:1}),y(j,"TransformMatrixUniform",{value:new p.Matrix4}),y(j,"ResolutionUniform",{value:new p.Vector2}),y(j,"LOADLLDATA",!1),y(j,"MaxFragmentUniforms",1024);let Z=j;class yr extends Gt{constructor(e){super();y(this,"viewer");y(this,"overlayRender");y(this,"drawableList");this.drawableList=new gs("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===Ge.Added?i.push(h):l.type===Ge.Removed?s.push(h):n.push(h))}const r=G.mergeBBoxes(i),a=G.mergeBBoxes(s),o=G.mergeBBoxes(n);this.drawableList.addDrawable(new vt(N.guid(),r,[.1,.9,.2,1])),this.drawableList.addDrawable(new vt(N.guid(),a,[1,.15,.15,1])),this.drawableList.addDrawable(new vt(N.guid(),o,[1,.85,.1,1])),this.viewer.enableRender()}setCompareDrawableVisible(e){this.drawableList.getDrawables().forEach(i=>i.visible=e),this.viewer.enableRender()}}class xn{}const xi=new p.Matrix4,Hn=new p.Box3;class Li extends xn{constructor(e){super();y(this,"modelId");y(this,"modelData");y(this,"modelObject");y(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(),s=new p.Box3;i.updateWorldMatrix(!1,!0);const n=r=>{if(r.userData?.isSnapObject||r.userData?.isConstructionLine)return;const a=r.geometry;a&&(a.boundingBox||a.computeBoundingBox(),s.copy(a.boundingBox).applyMatrix4(r.matrixWorld),e.union(s));for(const o of r.children)n(o)};n(i),this.bbox=e}return this.bbox}getUnits(){if(!this.dxfData)return Qe.Unitless;const e=this.dxfData.header;if(!e)return A.warn("DxfData or its header is undefined!"),Qe.Unitless;const i=e.$INSUNITS;return Z.getDxfUnits(i)}getModelSpaceExtent(){const e=this.header,i=new p.Vector3,s=new p.Vector3;if(!e){A.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,x=Z.getDcs2WcsMatrix(h,o),g=new p.Vector3(d.x,d.y,0);g.applyMatrix4(x),r={x:g.x-m/2,y:g.y-u/2,z:0},a={x:g.x+m/2,y:g.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(M=>parseInt(M.viewportId)===1);let d;h.length>0?d=h[0]:d=r[0];const{centerPoint:u,width_paperSpace:f,height_paperSpace:m}=d,x=Z.getDcs2WcsMatrix(d,l),g=new p.Vector3(u.x,u.y,0);g.applyMatrix4(x),a={x:g.x-f/2,y:g.y-m/2,z:0},o={x:g.x+f/2,y:g.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:A.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?Z.SHOW_SNAP_OBJECT?l.layers.enableAll():l.layers.set(qe):Z.SHOW_SNAP_OBJECT?l.layers.disableAll():l.layers.disable(qe))}else A.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=ve.cloneMaterial(a.material));const o=ve.cloneMaterial(a.material);ve.setMaterialOpacity(o,i),Z.updateMaterialUniforms(o),a.material=o}}):A.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=ve.cloneMaterial(a.material));const o=ve.cloneMaterial(a.material);ve.setMaterialColor(o,new p.Color(i)),Z.updateMaterialUniforms(o),a.material=o}}):A.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)}):A.info("[Viewer] No object found for layer '"+e+"'")}switchTransformMs(e){const i=this.msTransformMatrix;if(xi.identity(),!i||!N.isMatrixValid(i)||i.equals(xi))return;const s=this.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME);s&&(e===Z.MODEL_LAYOUT_NAME?s.applyMatrix4(i):s.applyMatrix4(i.clone().invert()),s.updateMatrixWorld(!0))}activateLayout(e=Z.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!==Z.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 x=-1;const g=this.getObjectsByLayer(m);g&&(x=g.indexOf(f),x>=0&&g.splice(x,1)),x<0&&A.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+m+"', layout '"+e+"'")}}),d.forEach(u=>{u.removeFromParent()})}const l=this.getFilteredViewports(s);A.debug("[Viewer] Active layout:",e,", viewports:",l);const h=Date.now();l.forEach(d=>{this.generateObjectsByViewport(e,d,this)}),A.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!");Z.TransformMatrixUniform={value:r.msToPsMatrix},Z.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=Vt.generateSectionPlanesByBox(d),f=[],m=T=>(!f[T.id]&&(f[T.id]=T.clone(),this.setMaterialUniforms(f[T.id],s.dxfData),Vt.setMaterialSection(f[T.id],u)),f[T.id]),x=T=>{if(Array.isArray(T)){const P=[];return T.forEach(_=>{const I=m(_);P.push(I)}),P}else return m(T)},g=[...n,...i.frozenLayerHandles||[]];let M;if(e!==Z.MODEL_LAYOUT_NAME){const T=r;!T.associatedLeafObjectSet&&(T.associatedLeafObjectSet=new Set),M=T.associatedLeafObjectSet}const w=new p.Group;w.name=r.viewportId;const b=[];if(o.forEach(T=>{const P=T.clone();P.traverse(_=>{const I=_;if(I.material&&I.geometry){const B=I.userData.layerName;if(this.isLayerFrozenForViewport(B,g)){b.push(I);return}I.userData.layerVisible!==!1&&(I.visible=!0),I.material=x(I.material),M?.add(I);const k=s.getObjectsByLayer(B);k?k.push(I):A.warn("[Viewer] Failed to find object for modelId '"+this.modelId+"', layer '"+B+"', layout '"+e+"'")}}),w.add(P)}),M&&M.size===0)return;const C=s.getModelObject();let S=s.getLayoutLevelObject(e);!S&&(S=new p.Group,Q.setSharedVariablesOfObject(S),S.name=e,C?.add(S)),S.add(w),w.applyMatrix4(r.msToPsMatrix),w.updateMatrixWorld(!0);let O=S.children.find(T=>T.name===Z.SNAP_GROUP_NAME);!O&&(O=new p.Group,O.visible=Z.SHOW_SNAP_OBJECT,O.name=Z.SNAP_GROUP_NAME,S.add(O));const E=s.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME),v=E?.children.find(T=>T.name===Z.SNAP_GROUP_NAME);v&&v.traverse(T=>{if(!T.geometry)return;const P=T.userData.layerName;if(this.isLayerFrozenForViewport(P,g)||(Hn.makeEmpty(),Hn.expandByObject(T),!a.intersectsBox(Hn)))return;const _=T.clone();Q.setSharedVariablesOfObject(_);let I=_.parent;const B=xi.identity();for(;I&&I.userData.isLayoutLevelObject!==!0;)B.premultiply(I.matrix),I=I.parent;B.premultiply(r.msToPsMatrix),_.applyMatrix4(B),O?.add(_),M?.add(_);const k=s.getObjectsByLayer(P);k&&k.push(_)}),b.length>0&&Q.removeEmptyObjectsFromRemovingObjects(b,w),w.traverse(T=>{Q.setSharedVariablesOfObject(T),this.addSpatialFilterSection(T,s.dxfData,!0)})}setMaterialUniforms(e,i){e instanceof p.ShaderMaterial&&(e.uniforms.u_cameraZoom&&(e.uniforms.u_cameraZoom=Z.CameraZoomUniform),e.uniforms.u_viewportScale&&i?.header.$PSLTSCALE===1&&(e.uniforms.u_viewportScale=Z.ViewportScaleUniform))}getObjectsByBoundingBox(e){const i=[];if(e.isEmpty())return A.warn("[Viewer] bbox is empty !"),i;const s=r=>{const a=_t.getBoundingBox(r,!1);e.intersectsBox(a)&&i.push(r)},n=this.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME);return n&&n.children.forEach(r=>{r.name!==Z.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++}),A.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){A.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>Z.MaxFragmentUniforms},d=new Set,u=f=>{d.has(f.id)||(d.add(f.id),!h(f)&&Vt.setMaterialSection(f,l,r,a))};e.traverse(f=>{const m=f.material;Array.isArray(m)?m.forEach(x=>{u(x)}):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){A.warn("[Viewer] clipPolyline.bConcave = true is not supported yet in spatialFilter !");return}xi.copy(i),e.localMatrix&&xi.multiply(e.localMatrix);const n=s.polyline,r=[];n.forEach(l=>{const h=l.clone().applyMatrix4(xi);r.push(new p.Vector2(h.x,h.y))});const a=p.ShapeUtils.isClockWise(r),o=!a&&!s.bReversed||a&&s.bReversed;return Vt.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=ve.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 Ar extends xn{constructor(e){super();y(this,"modelId");y(this,"bbox");y(this,"rootObject");y(this,"modelObject");y(this,"highlighUsage");y(this,"transparentUsage");y(this,"edges");y(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(Nt),this.transparentUsage=new p.Group,this.transparentUsage.name="transparentUsage-"+this.modelId,this.transparentUsage.layers.disable(Nt),this.rootObject.add(this.modelObject),this.rootObject.add(this.highlighUsage),this.rootObject.add(this.transparentUsage)}setDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&Q.setDoubleSidedMaterialToObject(e)})}revertDoubleSidedMaterials(){this.getModelObject().traverse(e=>{e instanceof p.Mesh&&Q.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 Q.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(me.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(Er);if(e instanceof p.InstancedMesh&&s){const r=this.createInstanceMeshById(e,s,{depthTest:!1});r.material.opacity=.7,ve.setMaterialColor(r.material,n),e.userData.instanceId=s,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else if(me.isMergedMesh(e)&&i){const r=this.createBatchMeshById(e,i,{depthTest:!1});r.material.opacity=.7,ve.setMaterialColor(r.material,n),e.userData.batchId=i,e.userData.clonedMesh=r,this.highlighUsage.add(r)}else{const r=ve.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=me.getBatchByBatchId(e,i);let a="[Viewer] Clicked on merged mesh(id: "+e.id+").";a+=" batchId: "+i+", object name: "+r?.name,r?.userData&&(a+=`
|
|
797
797
|
userData: `+JSON.stringify(r.userData)),r?.parentUserData&&(a+=`
|
|
798
|
-
parentUserData: `+JSON.stringify(r.parentUserData)),A.info(a);const o=ve.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!n&&(o.depthTest=n,o.depthWrite=n,o.side=p.DoubleSide);const l=me.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=ve.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 Ra extends p.MeshStandardMaterial{constructor(e){super(e);
|
|
798
|
+
parentUserData: `+JSON.stringify(r.parentUserData)),A.info(a);const o=ve.cloneMaterial(e.material);o.opacity=s,o.transparent=s<1,!n&&(o.depthTest=n,o.depthWrite=n,o.side=p.DoubleSide);const l=me.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=ve.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 Ra extends p.MeshStandardMaterial{constructor(e){super(e);y(this,"isBimTilesMaterial");y(this,"type");y(this,"uniforms");y(this,"vertexShader");y(this,"fragmentShader");y(this,"stateTexture");y(this,"defaultOutlineColor");y(this,"useBCOutline");y(this,"outlineVisible");this.isBimTilesMaterial=!0,this.type="BimTilesMaterial",this.defaultOutlineColor=new p.Color(sn[0],sn[1],sn[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>",`
|
|
@@ -1342,7 +1342,7 @@ void main() {
|
|
|
1342
1342
|
|
|
1343
1343
|
#include <outline_bc_fragment>
|
|
1344
1344
|
}
|
|
1345
|
-
`;p.ShaderChunk.outline_bc_vertex=F1;p.ShaderChunk.outline_bc_fragment=z1;p.ShaderChunk.outline_bc_pars_fragment=V1;p.ShaderChunk.outline_bc_pars_vertex=U1;p.ShaderChunk.standard_ex_vertex=q1;p.ShaderChunk.standard_ex_fragment=W1;p.ShaderChunk.common_ex=D1;p.ShaderChunk.id_pars_vertex=L1;p.ShaderChunk.id_vertex=R1;p.ShaderChunk.state_pars_fragment=H1;p.ShaderChunk.state_fragment=j1;p.ShaderChunk.state_transparent_fragment=G1;p.ShaderChunk.state_highlight_fragment=N1;p.ShaderChunk.pick_ex_vertex=Uo;p.ShaderChunk.pick_ex_fragment=jo;class Y1 extends p.ShaderMaterial{constructor(e){super(e);
|
|
1345
|
+
`;p.ShaderChunk.outline_bc_vertex=F1;p.ShaderChunk.outline_bc_fragment=z1;p.ShaderChunk.outline_bc_pars_fragment=V1;p.ShaderChunk.outline_bc_pars_vertex=U1;p.ShaderChunk.standard_ex_vertex=q1;p.ShaderChunk.standard_ex_fragment=W1;p.ShaderChunk.common_ex=D1;p.ShaderChunk.id_pars_vertex=L1;p.ShaderChunk.id_vertex=R1;p.ShaderChunk.state_pars_fragment=H1;p.ShaderChunk.state_fragment=j1;p.ShaderChunk.state_transparent_fragment=G1;p.ShaderChunk.state_highlight_fragment=N1;p.ShaderChunk.pick_ex_vertex=Uo;p.ShaderChunk.pick_ex_fragment=jo;class Y1 extends p.ShaderMaterial{constructor(e){super(e);y(this,"isBimTilesPickMaterial");y(this,"type");y(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=Uo,this.fragmentShader=jo,this.clipping=!0}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class X1 extends p.MeshStandardMaterial{constructor(e){super(e);y(this,"isBimTilesHighlightMaterial");y(this,"type");y(this,"transparent");y(this,"opacity");y(this,"depthTest");y(this,"side");y(this,"uniforms");y(this,"vertexShader");y(this,"fragmentShader");y(this,"stateTexture");this.isBimTilesHighlightMaterial=!0,this.type="BimTilesHighlightMaterial",this.transparent=!0,this.opacity=Or,this.depthTest=!1,this.side=p.DoubleSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
|
|
1346
1346
|
#include <common>
|
|
1347
1347
|
#include <id_pars_vertex>`).replace("#include <begin_vertex>",`
|
|
1348
1348
|
#include <begin_vertex>
|
|
@@ -1352,7 +1352,7 @@ void main() {
|
|
|
1352
1352
|
#include <state_pars_fragment>
|
|
1353
1353
|
`).replace("#include <logdepthbuf_fragment>",`
|
|
1354
1354
|
#include <state_highlight_fragment>
|
|
1355
|
-
#include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class Z1 extends p.MeshStandardMaterial{constructor(e){super(e);
|
|
1355
|
+
#include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}class Z1 extends p.MeshStandardMaterial{constructor(e){super(e);y(this,"isBimTilesTransparentMaterial");y(this,"type");y(this,"transparent");y(this,"opacity");y(this,"side");y(this,"uniforms");y(this,"vertexShader");y(this,"fragmentShader");y(this,"stateTexture");this.isBimTilesTransparentMaterial=!0,this.type="BimTilesTransparentMaterial",this.transparent=!0,this.opacity=Or,this.side=p.FrontSide;const i=e.stateTexture;this.stateTexture=i;const{uniforms:s,fragmentShader:n,vertexShader:r}=p.ShaderLib.standard;this.uniforms=p.UniformsUtils.merge([s,{uTextureWidth:{value:i.image.width},uTextureHeight:{value:i.image.height}}]),this.uniforms.uStateTexture={value:i},this.vertexShader=r.replace("#include <common>",`
|
|
1356
1356
|
#include <common>
|
|
1357
1357
|
#include <id_pars_vertex>`).replace("#include <begin_vertex>",`
|
|
1358
1358
|
#include <begin_vertex>
|
|
@@ -1362,7 +1362,7 @@ void main() {
|
|
|
1362
1362
|
#include <state_pars_fragment>
|
|
1363
1363
|
`).replace("#include <logdepthbuf_fragment>",`
|
|
1364
1364
|
#include <state_transparent_fragment>
|
|
1365
|
-
#include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var ii=(c=>(c[c.Hidden=0]="Hidden",c[c.Transparent=1]="Transparent",c[c.Highlighted=2]="Highlighted",c[c.Hovered=3]="Hovered",c))(ii||{});class K1{constructor(t,e){x(this,"_pickMaterial");x(this,"_highlightMaterial");x(this,"_transparentMaterial");x(this,"stateTexture");x(this,"batchMaterialMap",new Map);x(this,"instanceMaterialMap",new Map);x(this,"tileRenderer");x(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 Ra(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 Ra(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 X1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new Z1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new Y1({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),A.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(),A.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){A.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 $1={9728:p.NearestFilter,9729:p.LinearFilter},J1={9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},Fa={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping};var cn=(c=>(c.Opaque="OPAQUE",c.Mask="MASK",c.Blend="BLEND",c))(cn||{});const No={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var Ir=(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))(Ir||{});class Q1{constructor(t,e){x(this,"baseUrl");x(this,"textureLoaderCache",new Map);x(this,"materialCache",new Map);x(this,"textureCache",new Map);x(this,"userDataCache",new Map);x(this,"familyInstanceIdCache",new Map);x(this,"familyInstanceAndUserIdsCache",new Map);x(this,"userIdAndUserDataCache",new Map);x(this,"userBoxCache",new Map);x(this,"protoRoot");x(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return N.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=wr.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 Dl.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=$1[u.magFilter]||p.LinearFilter,h.minFilter=J1[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=Fa[u.wrapS]||p.RepeatWrapping,h.wrapT=Fa[u.wrapT]||p.RepeatWrapping,o(h)},void 0,h=>{throw A.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||cn.Opaque;if(n===cn.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,n===cn.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(()=>{A.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 za(c,t){return((c&255)<<24)+(t&16777215)}function eu(c){return c[3]}function tu(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),V.OctDecode(n,r,e),r.toArray(a,o*3);return a}class Va{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(Ir[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}}const ri=class ri{constructor(){x(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){A.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 ys(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=wr.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(Ir[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!ri.instanceDataMap[t]){const s=await fetch(t).then(r=>r.arrayBuffer()),n=new Uint8Array(s);N.isGzip(n)&&i?ri.instanceDataMap[t]=this.parseInstanceProto(n,i):ri.instanceDataMap[t]=this.parseInstanceBuffer(s)}return ri.instanceDataMap[t][e]}};x(ri,"instanceDataMap",{});let un=ri;class iu{async parse(t,e,i){const s=new Uint8Array(t);return N.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new ys(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);A.debug("[BimTiles] Tile, magic("+s+"), version("+n+"), byteLength("+r+"), tileJson:",f);const m=t.slice(l,l+h),y=new Va().parse(m,f.batchedMeshes),g=await new un().parse(f.instancedMeshes,e);return{batchedMeshes:y,instancedMeshes:g}}async parseProto(t,e,i){const s=wr.inflate(t),n=i.lookupType("PBTileContent").decode(s),r=n.header;A.debug("[BimTiles] Tile, magic("+r.magic+"), version("+r.version+"), byteLength("+s.byteLength+"), tileJson:",n);const a=n.binaries.slice().buffer,o=new Va().parse(a,n.meshes),l=await new un().parse(n.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const su=`syntax = "proto3";\r
|
|
1365
|
+
#include <logdepthbuf_fragment>`)}setValues(e){this.stateTexture=e.stateTexture,super.setValues(e)}}var ii=(c=>(c[c.Hidden=0]="Hidden",c[c.Transparent=1]="Transparent",c[c.Highlighted=2]="Highlighted",c[c.Hovered=3]="Hovered",c))(ii||{});class K1{constructor(t,e){y(this,"_pickMaterial");y(this,"_highlightMaterial");y(this,"_transparentMaterial");y(this,"stateTexture");y(this,"batchMaterialMap",new Map);y(this,"instanceMaterialMap",new Map);y(this,"tileRenderer");y(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 Ra(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 Ra(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 X1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._highlightMaterial}get transparentMaterial(){return this._transparentMaterial||(this._transparentMaterial=new Z1({transparent:!0,color:0,stateTexture:this.stateTexture})),this._transparentMaterial}get pickMaterial(){return this._pickMaterial||(this._pickMaterial=new Y1({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),A.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(),A.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){A.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 $1={9728:p.NearestFilter,9729:p.LinearFilter},J1={9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},Fa={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping};var cn=(c=>(c.Opaque="OPAQUE",c.Mask="MASK",c.Blend="BLEND",c))(cn||{});const No={int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,float:Float32Array,double:Float64Array};var Ir=(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))(Ir||{});class Q1{constructor(t,e){y(this,"baseUrl");y(this,"textureLoaderCache",new Map);y(this,"materialCache",new Map);y(this,"textureCache",new Map);y(this,"userDataCache",new Map);y(this,"familyInstanceIdCache",new Map);y(this,"familyInstanceAndUserIdsCache",new Map);y(this,"userIdAndUserDataCache",new Map);y(this,"userBoxCache",new Map);y(this,"protoRoot");y(this,"preprocessURL",null);this.baseUrl=t,this.protoRoot=e}async getProperty(t,e,i){return N.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=wr.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 Dl.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=$1[u.magFilter]||p.LinearFilter,h.minFilter=J1[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=Fa[u.wrapS]||p.RepeatWrapping,h.wrapT=Fa[u.wrapT]||p.RepeatWrapping,o(h)},void 0,h=>{throw A.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||cn.Opaque;if(n===cn.Blend?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,n===cn.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(()=>{A.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 za(c,t){return((c&255)<<24)+(t&16777215)}function eu(c){return c[3]}function tu(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),V.OctDecode(n,r,e),r.toArray(a,o*3);return a}class Va{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(Ir[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}}const ri=class ri{constructor(){y(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){A.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 ys(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=wr.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(Ir[r]),l=No[a],h=t.slice(i,i+s);return new l(h,0,n*o)}async getInstancedMeshByUrlAndBlobId(t,e,i){if(!ri.instanceDataMap[t]){const s=await fetch(t).then(r=>r.arrayBuffer()),n=new Uint8Array(s);N.isGzip(n)&&i?ri.instanceDataMap[t]=this.parseInstanceProto(n,i):ri.instanceDataMap[t]=this.parseInstanceBuffer(s)}return ri.instanceDataMap[t][e]}};y(ri,"instanceDataMap",{});let un=ri;class iu{async parse(t,e,i){const s=new Uint8Array(t);return N.isGzip(s)?this.parseProto(s,e,i):this.parseBinary(t,e)}async parseBinary(t,e){const i=new ys(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);A.debug("[BimTiles] Tile, magic("+s+"), version("+n+"), byteLength("+r+"), tileJson:",f);const m=t.slice(l,l+h),x=new Va().parse(m,f.batchedMeshes),g=await new un().parse(f.instancedMeshes,e);return{batchedMeshes:x,instancedMeshes:g}}async parseProto(t,e,i){const s=wr.inflate(t),n=i.lookupType("PBTileContent").decode(s),r=n.header;A.debug("[BimTiles] Tile, magic("+r.magic+"), version("+r.version+"), byteLength("+s.byteLength+"), tileJson:",n);const a=n.binaries.slice().buffer,o=new Va().parse(a,n.meshes),l=await new un().parse(n.instanceMeshes,e,i);return{batchedMeshes:o,instancedMeshes:l}}}const su=`syntax = "proto3";\r
|
|
1366
1366
|
\r
|
|
1367
1367
|
package BimTiles;\r
|
|
1368
1368
|
\r
|
|
@@ -1528,16 +1528,16 @@ message PBTileContent {\r
|
|
|
1528
1528
|
repeated PBMesh meshes = 3;\r
|
|
1529
1529
|
bytes binaries = 4;\r
|
|
1530
1530
|
}\r
|
|
1531
|
-
`,qo=Symbol("INITIAL_FRUSTUM_CULLED");function nu(c,t){c.traverse(e=>{e.frustumCulled=e[qo]&&t})}const Hs=new p.Vector3,Gs=new p.Vector3,Gn=new p.Box3;class Wo extends Bl.TilesRenderer{constructor(e,i){super(e);x(this,"highlighUsage");x(this,"transparentUsage");x(this,"pickUsage");x(this,"materialManager");x(this,"baseUrl");x(this,"propertyParser");x(this,"tilesetId");x(this,"onBeforeParseTile");x(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=nc.parse(su).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(b=>za(this.tilesetId,b)),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 y=a.length>0;y&&f.setAttribute("barycentric",new p.BufferAttribute(a,1));const g=this.materialManager?.createBatchMaterial(l,m,y),M=new p.Mesh(f,g),w=new p.Mesh(f,this.materialManager?.pickMaterial);return{mesh:M,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(S=>za(this.tilesetId,S)),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 y=o.length>0;y&&m.setAttribute("barycentric",new p.BufferAttribute(o,1));const g=this.propertyParser.getMaterialParameters(d),M=this.materialManager?.createInstanceMaterial(d,g,y),w=new p.InstancedMesh(m,M,f);w.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16);let b=n;b.length===0&&(b=this.getVertexColorArray(f*3,g?.color)),w.instanceColor=new p.InstancedBufferAttribute(b,3);const C=new p.InstancedMesh(m,this.materialManager?.pickMaterial,f);return C.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16),{mesh:w,pickMesh:C,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"),y=o.geometry.index,g=o.geometry.getAttribute("tileObjectId");if(o instanceof p.InstancedMesh){const M=new p.Matrix4;o.getMatrixAt(u,M),f.setAttribute("position",m.clone());const w=g.array[u*g.itemSize];f.setAttribute("tileObjectId",new p.Int32BufferAttribute(new Array(m.array.length/3).fill(w),1)),y&&f.setIndex(y),f.applyMatrix4(M)}else{const{indexStart:M,indexCount:w,positionStart:b,positionCount:C}=o.userData.batchTable.find(_=>_.userId===d),S=m.itemSize,O=m.array.slice(b*S,b*S+C*S),E=new p.Float32BufferAttribute(O,S);f.setAttribute("position",E);const v=g.array.slice(b,b+C),T=new p.Int32BufferAttribute(v,1);if(f.setAttribute("tileObjectId",T),y){const _=y.array.slice(M,M+w);for(let P=0;P<_.length;P++)_[P]-=b;f.setIndex(new p.BufferAttribute(_,1))}}f.applyMatrix4(o.matrixWorld),s.push(f)}}}}),A.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?Ae.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 iu().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{A.debug("[BimTiles] batchedMeshes:",o),A.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:y,batchTable:g}=this.createBatchedMesh(f);h.add(m),m.userData.batchTable=g,m.userData.userIds=g.map(M=>M.userId),d.add(y)}),l.forEach(f=>{const{mesh:m,pickMesh:y,userIds:g}=this.createInstancedMesh(f);h.add(m),m.userData.userIds=g,d.add(y)});const u=f=>{f.applyMatrix4(r)};u(h),h.traverse(f=>{f[qo]=f.frustumCulled}),nu(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)&&(Gn.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(Gn.getCenter(Hs),Gn.getSize(Gs),e.cached.boundingVolume.setObbData([Hs.x,Hs.y,Hs.z,Gs.x/2,0,0,0,Gs.y/2,0,0,0,Gs.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 K1(this,{maxId:n.properties.userId.maxUserIdIndex})});return s.catch(n=>{A.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 y=u.pixelSize;m=e.geometricError/(y*f)}else{const y=a.distanceToPoint(u.position),g=y*f,M=u.sseDenominator;m=e.geometricError/(g*M),l=Math.min(l,g)}o=Math.max(o,m)}e.__distanceFromCamera=l,e.__error=o}}class Br extends xn{constructor(e,i,s){super();x(this,"modelId");x(this,"_bbox");x(this,"tilesRenderer");x(this,"metadata");x(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(ii.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(ii.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(ii.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(ii.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(ii.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(ii.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function ru(){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 au{constructor(t){x(this,"viewer");x(this,"element");x(this,"content");x(this,"itemList");x(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(ce.ModelLoad,()=>{this.init()})}init(){this.destroy();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 ou(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 ou{constructor(t,e){x(this,"viewer");x(this,"eventBus");x(this,"element");x(this,"resetActivate");x(this,"active");this.viewer=t,this.eventBus=ru(),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){x(this,"element");x(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 kr{constructor(t){x(this,"width");x(this,"height");x(this,"container");x(this,"viewerContainer");x(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(A.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 Dr{constructor(t){x(this,"element");x(this,"progressItems");x(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)&&A.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=Fe.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 Qe=(c=>(c.BaseViewer="BaseViewer",c.Viewer3d="Viewer3d",c.Viewer2d="Viewer2d",c.BimTilesViewer="BimTilesViewer",c))(Qe||{}),bt=(c=>(c.Perspective="Perspective",c.Orthographic="Orthographic",c))(bt||{});const lu={enableSpinner:!0,containerId:"myCanvas"},Y={LEFT:1,RIGHT:2,MIDDLE:4},R=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function lt(c){return c.isPerspectiveCamera}function qe(c){return c.isOrthographicCamera}class cu{constructor(){x(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 bi=Math.PI*2,Ua=Math.PI/2;function qn(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 Wn(c,t){return qe(c)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Xo=1e-5,Zi=Math.PI/180;function Ei(c,t,e){return Math.max(t,Math.min(e,c))}function oe(c,t=Xo){return Math.abs(c)<t}function ae(c,t,e=Xo){return oe(c-t,e)}function ja(c,t){return Math.round(c/t)*t}function Ki(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function $i(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function qs(c,t,e,i,s=1/0,n){i=Math.max(1e-4,i);const r=2/i,a=r*n,o=1/(1+a+.48*a*a+.235*a*a*a);let l=c-t;const h=t,d=s*i;l=Ei(l,-d,d),t=c-l;const u=(e.value+r*l)*n;e.value=(e.value-r*u)*o;let f=t+(l+u)*o;return h-c>0==f>h&&(f=h,e.value=(f-h)/n),f}function Na(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,y=c.z-u;const g=h,M=d,w=u,b=s*i,C=b*b,S=f*f+m*m+y*y;if(S>C){const D=Math.sqrt(S);f=f/D*b,m=m/D*b,y=y/D*b}h=c.x-f,d=c.y-m,u=c.z-y;const O=(e.x+a*f)*n,E=(e.y+a*m)*n,v=(e.z+a*y)*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+(y+v)*l;const T=g-c.x,_=M-c.y,P=w-c.z,I=r.x-g,B=r.y-M,k=r.z-w;return T*I+_*B+P*k>0&&(r.x=g,r.y=M,r.z=w,e.x=(r.x-g)/n,e.y=(r.y-M)/n,e.z=(r.z-w)/n),r}const Ws=1/8,hu=ke.isBrowser&&/Mac/.test(navigator.platform),du=!(ke.isBrowser&&"PointerEvent"in window);let W,Ha,Ys,Yn,je,X,ie,wi,pt,mt,Qt,Ga,qa,at,Ji,vi,Wa,Xn,Ya,Zn,Kn,Xs;class J extends cu{constructor(e,i){super();x(this,"minPolarAngle");x(this,"maxPolarAngle");x(this,"minAzimuthAngle");x(this,"maxAzimuthAngle");x(this,"minDistance");x(this,"maxDistance");x(this,"infinityDolly");x(this,"minZoom");x(this,"maxZoom");x(this,"smoothTime");x(this,"draggingSmoothTime");x(this,"maxSpeed");x(this,"azimuthRotateSpeed");x(this,"polarRotateSpeed");x(this,"dollySpeed");x(this,"truckSpeed");x(this,"dollyToCursor");x(this,"dragToOffset");x(this,"verticalDragToForward");x(this,"boundaryFriction");x(this,"restThreshold");x(this,"colliderMeshes");x(this,"mouseButtons");x(this,"touches");x(this,"cancel");x(this,"_enabled");x(this,"_camera");x(this,"_yAxisUpSpace");x(this,"_yAxisUpSpaceInverse");x(this,"_state");x(this,"_domElement");x(this,"_viewport");x(this,"_target");x(this,"_targetEnd");x(this,"_focalOffset");x(this,"_focalOffsetEnd");x(this,"_spherical");x(this,"_sphericalEnd");x(this,"_zoom");x(this,"_zoomEnd");x(this,"_target0");x(this,"_position0");x(this,"_zoom0");x(this,"_focalOffset0");x(this,"_dollyControlAmount");x(this,"_dollyControlCoord");x(this,"_nearPlaneCorners");x(this,"_hasRested");x(this,"_boundary");x(this,"_boundaryEnclosesCamera");x(this,"_needsUpdate");x(this,"_updatedLastTime");x(this,"_elementRect");x(this,"_activePointers");x(this,"_isUserControllingRotate");x(this,"_isUserControllingDolly");x(this,"_isUserControllingTruck");x(this,"_isUserControllingOffset");x(this,"_isUserControllingZoom");x(this,"_thetaVelocity");x(this,"_phiVelocity");x(this,"_radiusVelocity");x(this,"_targetVelocity");x(this,"_focalOffsetVelocity");x(this,"_zoomVelocity");x(this,"_truckInternal");x(this,"_rotateInternal");x(this,"_dollyInternal");x(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=R.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=ke.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 W.Vector3,this._focalOffsetVelocity=new W.Vector3,this._zoomVelocity={value:0},this._truckInternal=(b,C,S)=>{if(lt(this._camera)){const O=X.copy(this._camera.position).sub(this._target),E=this._camera.getEffectiveFOV()*Zi,v=O.length()*Math.tan(E*.5),T=this.truckSpeed*b*v/this._elementRect.height,_=this.truckSpeed*C*v/this._elementRect.height;this.verticalDragToForward?(S?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(T,0,!0),this.forward(-_,!0)):S?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y+_,this._focalOffsetEnd.z,!0):this.truck(T,_,!0)}else if(qe(this._camera)){const O=this._camera,E=this.truckSpeed*b*(O.right-O.left)/O.zoom/this._elementRect.width,v=this.truckSpeed*C*(O.top-O.bottom)/O.zoom/this._elementRect.height;S?this.setFocalOffset(this._focalOffsetEnd.x+E,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(E,v,!0)}},this._rotateInternal=(b,C)=>{const S=bi*this.azimuthRotateSpeed*b/this._elementRect.height,O=bi*this.polarRotateSpeed*C/this._elementRect.height;this.rotate(S,O,!0)},this._dollyInternal=(b,C,S)=>{const O=Math.pow(.95,-b*this.dollySpeed),E=this._sphericalEnd.radius*O,v=this._sphericalEnd.radius,T=v*(b>=0?-1:1);this.dollyTo(E),this.infinityDolly&&(E<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(X),this._targetEnd.add(X.normalize().multiplyScalar(T)),this._target.add(X.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(C,S))},this._zoomInternal=(b,C,S)=>{const O=Math.pow(.95,b*this.dollySpeed),E=this._zoomEnd;this.zoomTo(this._zoom*O),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-E,this._dollyControlCoord.set(C,S))},typeof W>"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 W.Quaternion().setFromUnitVectors(this._camera.up,Ys),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=R.NONE,this._target=new W.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new W.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new W.Spherical().setFromVector3(X.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new W.Vector3,new W.Vector3,new W.Vector3,new W.Vector3],this._updateNearPlaneCorners(),this._boundary=new W.Box3(new W.Vector3(-1/0,-1/0,-1/0),new W.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 W.Vector2,this.mouseButtons={left:R.ROTATE,middle:R.DOLLY,right:R.TRUCK,wheel:lt(this._camera)?R.DOLLY:qe(this._camera)?R.ZOOM:R.NONE},this.touches={one:R.TOUCH_ROTATE,two:lt(this._camera)?R.TOUCH_DOLLY_TRUCK:qe(this._camera)?R.TOUCH_ZOOM_TRUCK:R.NONE,three:R.TOUCH_TRUCK};const s=new W.Vector2,n=new W.Vector2,r=new W.Vector2,a=b=>{if(!this._enabled||!this._domElement)return;const C=b.pointerType!=="mouse"?null:(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.MIDDLE?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.RIGHT?Y.RIGHT:null;if(C!==null){const O=this._findPointerByMouseButton(C);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const S={pointerId:b.pointerId,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:C};this._activePointers.push(S),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",d),g(b)},o=b=>{if(!this._enabled||!this._domElement)return;const C=(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.MIDDLE?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.RIGHT?Y.RIGHT:null;if(C!==null){const O=this._findPointerByMouseButton(C);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const S={pointerId:0,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.LEFT?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.LEFT?Y.RIGHT:null};this._activePointers.push(S),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u),this._domElement.addEventListener("mousemove",h),this._domElement.addEventListener("mouseup",u),g(b)},l=b=>{const C=b.pointerId,S=this._findPointerById(C);if(S){if(S.clientX=b.clientX,S.clientY=b.clientY,S.deltaX=b.movementX,S.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&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right);M()}},h=b=>{const C=this._findPointerById(0);C&&(C.clientX=b.clientX,C.clientY=b.clientY,C.deltaX=b.movementX,C.deltaY=b.movementY,this._state=0,(b.buttons&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right),M())},d=b=>{const C=b.pointerId,S=this._findPointerById(C);if(S&&this._activePointers.splice(this._activePointers.indexOf(S),1),b.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=R.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=R.NONE;w()},u=()=>{const b=this._findPointerById(0);b&&this._activePointers.splice(this._activePointers.indexOf(b),1),this._state=R.NONE,w()};let f=-1;const m=b=>{if(!this._enabled||this.mouseButtons.wheel===R.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===R.ROTATE||this.mouseButtons.wheel===R.TRUCK){const v=performance.now();f-v<1e3&&this._getClientRect(this._elementRect),f=v}const C=hu?-1:-3,S=b.deltaMode===1?b.deltaY/C:b.deltaY/(C*10),O=this.dollyToCursor?(b.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(b.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case R.ROTATE:{this._rotateInternal(b.deltaX,b.deltaY),this._isUserControllingRotate=!0;break}case R.TRUCK:{this._truckInternal(b.deltaX,b.deltaY,!1),this._isUserControllingTruck=!0;break}case R.OFFSET:{this._truckInternal(b.deltaX,b.deltaY,!0),this._isUserControllingOffset=!0;break}case R.DOLLY:{this._dollyInternal(-S,O,E),this._isUserControllingDolly=!0;break}case R.ZOOM:{this._zoomInternal(-S,O,E),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},y=b=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===J.ACTION.NONE){const C=b instanceof PointerEvent?b.pointerId:(b instanceof MouseEvent,0),S=this._findPointerById(C);S&&this._activePointers.splice(this._activePointers.indexOf(S),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u);return}},g=b=>{if(!this._enabled)return;if(qn(this._activePointers,je),this._getClientRect(this._elementRect),s.copy(je),n.copy(je),this._activePointers.length>=2){const S=je.x-this._activePointers[1].clientX,O=je.y-this._activePointers[1].clientY,E=Math.sqrt(S*S+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 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&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&R.DOLLY)===R.DOLLY||(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&R.ZOOM)===R.ZOOM||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},M=()=>{if(!this._enabled)return;qn(this._activePointers,je);const b=ke.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,C=b?-this._activePointers[0].deltaX:n.x-je.x,S=b?-this._activePointers[0].deltaY:n.y-je.y;if(n.copy(je),((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(C,S),this._isUserControllingRotate=!0),(this._state&R.DOLLY)===R.DOLLY||(this._state&R.ZOOM)===R.ZOOM){const O=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.DOLLY)===R.DOLLY?(this._dollyInternal(S*Ws,O,E),this._isUserControllingDolly=!0):(this._zoomInternal(S*Ws,O,E),this._isUserControllingZoom=!0)}if((this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE){const O=je.x-this._activePointers[1].clientX,E=je.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,P=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET?(this._dollyInternal(T*Ws,_,P),this._isUserControllingDolly=!0):(this._zoomInternal(T*Ws,_,P),this._isUserControllingZoom=!0)}((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(C,S,!1),this._isUserControllingTruck=!0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(C,S,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},w=()=>{qn(this._activePointers,je),n.copy(je),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=b=>{this._domElement=b,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),du&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",d),this._domElement.addEventListener("wheel",m,{passive:!1}),this._domElement.addEventListener("contextmenu",y)},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",y),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u))},this.cancel=()=>{this._state!==R.NONE&&(this._state=R.NONE,this._activePointers.length=0,w())},i&&this.connect(i),this.update(0)}static install(e){W=e.THREE,Ha=Object.freeze(new W.Vector3(0,0,0)),Ys=Object.freeze(new W.Vector3(0,1,0)),Yn=Object.freeze(new W.Vector3(0,0,1)),je=new W.Vector2,X=new W.Vector3,ie=new W.Vector3,wi=new W.Vector3,pt=new W.Vector3,mt=new W.Vector3,Qt=new W.Vector3,Ga=new W.Vector3,qa=new W.Vector3,at=new W.Spherical,Ji=new W.Spherical,vi=new W.Box3,Wa=new W.Box3,Xn=new W.Sphere,Ya=new W.Quaternion,Zn=new W.Quaternion,Kn=new W.Matrix4,Xs=new W.Raycaster}static get ACTION(){return R}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const n=Ei(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=Ei(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,n=Ei(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=ae(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||ae(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Ei(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||ae(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),pt.multiplyScalar(e),mt.multiplyScalar(-i);const n=X.copy(pt).add(mt),r=ie.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,i=!1){X.setFromMatrixColumn(this._camera.matrix,0),X.crossVectors(this._camera.up,X),X.multiplyScalar(e);const s=ie.copy(this._targetEnd).add(X);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return X.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+X.x,this._targetEnd.y+X.y,this._targetEnd.z+X.z,i)}moveTo(e,i,s,n=!1){this._isUserControllingTruck=!1;const r=X.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||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,n=!1){const o=X.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?vi.copy(e):vi.setFromObject(e);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const d=ja(this._sphericalEnd.theta,Ua),u=ja(this._sphericalEnd.phi,Ua);l.push(this.rotateTo(d,u,i));const f=X.setFromSpherical(this._sphericalEnd).normalize(),m=Ya.setFromUnitVectors(f,Yn),y=ae(Math.abs(f.y),1);y&&m.multiply(Zn.setFromAxisAngle(Ys,d)),m.multiply(this._yAxisUpSpaceInverse);const g=Wa.makeEmpty();ie.copy(h.min).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setX(h.max.x).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setY(h.max.y).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setZ(h.min.z).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setZ(h.max.z).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setY(h.min.y).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setX(h.min.x).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).applyQuaternion(m),g.expandByPoint(ie),g.min.x-=n,g.min.y-=a,g.max.x+=r,g.max.y+=o,m.setFromUnitVectors(Yn,f),y&&m.premultiply(Zn.invert()),m.premultiply(this._yAxisUpSpace);const M=g.getSize(X),w=g.getCenter(ie).applyQuaternion(m);if(lt(this._camera)){const b=this.getDistanceToFitBox(M.x,M.y,M.z,s);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.dollyTo(b,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(qe(this._camera)){const b=this._camera,C=b.right-b.left,S=b.top-b.bottom,O=s?Math.max(C/M.x,S/M.y):Math.min(C/M.x,S/M.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 W.Sphere?Xn.copy(e):J.createBoundingSphere(e,Xn);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,i)),lt(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,i))}else if(qe(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=ie.set(n,r,a),h=X.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||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold)&&ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ae(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,y=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const g=X.set(n,r,a),M=ie.set(e,i,s);at.setFromVector3(M.sub(g).applyQuaternion(this._yAxisUpSpace));const w=wi.set(d,u,f),b=ie.set(o,l,h);Ji.setFromVector3(b.sub(w).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(g.lerp(w,m));const C=Ji.theta-at.theta,S=Ji.phi-at.phi,O=Ji.radius-at.radius;this._sphericalEnd.set(at.radius+O*m,at.phi+S*m,at.theta+C*m),this.normalizeRotations(),this._needsUpdate=!0,y||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const E=!y||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold)&&ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ae(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(X),a=this.setLookAt(r.x,r.y,r.z,e,i,s,n);return this._sphericalEnd.phi=Ei(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||ae(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&ae(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&ae(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),mt.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Qt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=X.set(e,i,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);pt.multiplyScalar(a.x),mt.multiplyScalar(a.y),Qt.multiplyScalar(a.z),X.copy(pt).add(mt).add(Qt),X.z=X.z+r,this.dollyTo(r,!1),this.setFocalOffset(-X.x,X.y,-X.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 W.Vector4,typeof e=="number"?this._viewport.set(e,i,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,n=!1){if(Wn(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/i,a=this._camera.getEffectiveFOV()*Zi,o=this._camera.aspect;return((n?r>o:r<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(Wn(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*Zi,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 W.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new W.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new W.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%bi,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=bi),this._spherical.theta+=bi*Math.round((this._sphericalEnd.theta-this._spherical.theta)/bi)}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,Ys),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=Ga.subVectors(this._targetEnd,this._target),a=qa.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(oe(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=qs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(oe(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=qs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(oe(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=qs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(oe(r.x)&&oe(r.y)&&oe(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Na(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(oe(a.x)&&oe(a.y)&&oe(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Na(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(lt(this._camera)){const u=this._camera,f=X.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),m=ie.copy(f).cross(u.up).normalize();m.lengthSq()===0&&(m.x=1);const y=wi.crossVectors(m,f),g=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*Zi*.5),w=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,b=X.copy(this._targetEnd).add(m.multiplyScalar(this._dollyControlCoord.x*g*u.aspect)).add(y.multiplyScalar(this._dollyControlCoord.y*g));this._targetEnd.lerp(b,w)}else if(qe(this._camera)){const u=this._camera,f=X.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),m=ie.set(0,0,-1).applyQuaternion(u.quaternion),y=wi.copy(f).add(m.multiplyScalar(-f.dot(u.up))),M=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,w=X.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),b=this._targetEnd.dot(w);this._targetEnd.lerp(y,M);const C=this._targetEnd.dot(w),S=w.multiplyScalar(C-b);this._targetEnd.sub(S)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(oe(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=qs(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),(!oe(this._focalOffset.x)||!oe(this._focalOffset.y)||!oe(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),pt.setFromMatrixColumn(this._camera.matrix,0),mt.setFromMatrixColumn(this._camera.matrix,1),Qt.setFromMatrixColumn(this._camera.matrix,2),pt.multiplyScalar(this._focalOffset.x),mt.multiplyScalar(-this._focalOffset.y),Qt.multiplyScalar(this._focalOffset.z),X.copy(pt).add(mt).add(Qt),this._camera.position.add(X)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),X.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"}),oe(i,this.restThreshold)&&oe(s,this.restThreshold)&&oe(n,this.restThreshold)&&oe(r.x,this.restThreshold)&&oe(r.y,this.restThreshold)&&oe(r.z,this.restThreshold)&&oe(a.x,this.restThreshold)&&oe(a.y,this.restThreshold)&&oe(a.z,this.restThreshold)&&oe(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:Ki(this.maxDistance),minZoom:this.minZoom,maxZoom:Ki(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Ki(this.maxPolarAngle),minAzimuthAngle:Ki(this.minAzimuthAngle),maxAzimuthAngle:Ki(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:X.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=X.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=$i(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=$i(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=$i(s.maxPolarAngle),this.minAzimuthAngle=$i(s.minAzimuthAngle),this.maxAzimuthAngle=$i(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),at.setFromVector3(n.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(at.theta,at.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=ie.copy(i).add(e),o=this._boundary.clampPoint(r,wi).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(ie.copy(i).multiplyScalar(h)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(lt(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*Zi,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(qe(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)||Wn(this._camera,"_collisionTest"))return e;const s=X.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);Kn.lookAt(Ha,s,this._camera.up);for(let n=0;n<4;n++){const r=ie.copy(this._nearPlaneCorners[n]);r.applyMatrix4(Kn);const a=wi.addVectors(this._target,r);Xs.set(a,s),Xs.far=this._spherical.radius+1;const o=Xs.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 W.Sphere){const s=i,n=s.center;vi.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&vi.expandByObject(a)}),vi.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++)X.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(X))}else{const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)X.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(X))}}),s.radius=Math.sqrt(r),s}}var ht=(c=>(c[c.Orbit=0]="Orbit",c[c.FirstPerson=1]="FirstPerson",c[c.Plan=2]="Plan",c))(ht||{});class Zo{constructor(t){x(this,"mode");x(this,"cameraManager");this.mode=ht.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:J.ACTION.ROTATE,middle:J.ACTION.DOLLY,right:J.ACTION.TRUCK,wheel:lt(t)?J.ACTION.DOLLY:qe(t)?J.ACTION.ZOOM:J.ACTION.NONE},e.touches={one:J.ACTION.TOUCH_ROTATE,two:lt(t)?J.ACTION.TOUCH_DOLLY_TRUCK:qe(t)?J.ACTION.TOUCH_ZOOM_TRUCK:J.ACTION.NONE,three:J.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){x(this,"mode");x(this,"cameraManager");this.mode=ht.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:J.ACTION.TRUCK,middle:J.ACTION.TRUCK,right:J.ACTION.TRUCK,wheel:lt(t)?J.ACTION.DOLLY:qe(t)?J.ACTION.ZOOM:J.ACTION.NONE},e.touches={one:J.ACTION.TOUCH_TRUCK,two:lt(t)?J.ACTION.TOUCH_DOLLY_TRUCK:qe(t)?J.ACTION.TOUCH_ZOOM_TRUCK:J.ACTION.NONE,three:J.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,$n=new p.Vector3;class uu{constructor(t){x(this,"viewer");x(this,"perspectiveCamera");x(this,"orthographicCamera");x(this,"activeCamera");x(this,"cameraControls");x(this,"previousDistance");x(this,"previousAzimuthRotateSpeed");x(this,"previousPolarRotateSpeed");x(this,"previousDollySpeed");x(this,"previousTruckSpeed");x(this,"previousMouseLeft");x(this,"enableKeyDown");x(this,"controlsMap");x(this,"activeControls");x(this,"projection");x(this,"anchor");x(this,"onKeyDown");x(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=J.ACTION.NONE,this.enableKeyDown=!0,this.projection=bt.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const n=this.cameraControls,r=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===Qe.Viewer3d||this.viewer.name===Qe.BimTilesViewer;switch(s.code){case"ArrowLeft":a?n.rotate(.1,0,!0):this.viewer.name===Qe.Viewer2d&&n.truck(r,0,!0);break;case"ArrowRight":a?n.rotate(-.1,0,!0):this.viewer.name===Qe.Viewer2d&&n.truck(-r,0,!0);break;case"ArrowUp":a?n.rotate(0,.1,!0):this.viewer.name===Qe.Viewer2d&&n.truck(0,r,!0);break;case"ArrowDown":a?n.rotate(0,-.1,!0):this.viewer.name===Qe.Viewer2d&&n.truck(0,-r,!0);break;case"KeyW":a&&(qe(this.activeCamera)?n.zoom(.01,!0):n.dolly(1,!0));break;case"KeyA":a&&n.truck(-r,0,!0);break;case"KeyS":a&&(qe(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(bo,i,nn,rn),this.orthographicCamera=new p.OrthographicCamera(Mi*i/-2,Mi*i/2,Mi/2,Mi/-2,nn,rn),this.activeCamera=this.perspectiveCamera,this.setupCameras(),J.install({THREE:p}),this.cameraControls=new J(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[ht.Orbit]:new Zo(this),[ht.Plan]:new Ko(this)},this.activeControls=this.controlsMap[ht.Orbit],this.setupControls(),this.setProjection(bt.Perspective),this.anchor=this.createAnchor()}get viewerContainer(){return this.viewer.viewerContainer}get inputManager(){return this.viewer.getInputManager()}createAnchor(){const t=document.createElement("div");return t.className="anchor",this.viewerContainer?.appendChild(t),this.cameraControls.addEventListener("control",()=>{if(this.isOrbitPointVisible()){const e=this.getTarget(),i=_e.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(ce.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===ht.FirstPerson)return;this.previousDistance=this.cameraControls.distance,this.cameraControls.distance=200;const{width:t,height:e}=this.getDims();this.setupOrthoCamera(e,t),this.activeCamera=this.orthographicCamera,this.projection=bt.Orthographic}getDims(){const t=new p.Vector3;this.perspectiveCamera.getWorldDirection(t);const e=new p.Vector3;this.cameraControls.getTarget(e);const i=e.clone().sub(this.perspectiveCamera.position),s=i.dot(t),{clientWidth:n,clientHeight:r}=this.viewer.viewerContainer,a=n/r,o=this.perspectiveCamera.fov,l=s*2*Math.atan(o*(Math.PI/180)/2);return{width:l*a,height:l}}setupOrthoCamera(t,e){this.cameraControls.mouseButtons.wheel=J.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=J.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=J.ACTION.DOLLY,this.activeCamera=e,this.projection=bt.Perspective,t.distance=this.previousDistance,t.zoomTo(1)}update(t){const e=this.cameraControls.update(t);return this.camera.updateMatrixWorld(),e}updateAspect(){const{clientWidth:t,clientHeight:e}=this.viewer.viewerContainer;this.perspectiveCamera.aspect=t/e,this.perspectiveCamera.updateProjectionMatrix(),this.setOrthoCameraAspect(t,e)}get camera(){return this.activeCamera}enableKeyControl(t){this.enableKeyDown=t}getTarget(){return this.cameraControls.getTarget($n)}getPosition(){return this.cameraControls.getPosition($n)}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=>N.numberToString(h);A.info("[Viewer] BBox's longest side is: "+l(n)),e>a&&(A.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(A.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=J.ACTION.NONE)}setCameraPosition(t){this.cameraControls.setPosition(t.x,t.y,t.z)}setCameraTarget(t){this.cameraControls.setTarget(t.x,t.y,t.z)}flyTo(t,e,i=!0){const s=this.cameraControls;s.setLookAt(t.x,t.y,t.z,e.x,e.y,e.z,i),s.setFocalOffset(0,0,0,!0)}flyToPosition(t,e,i){this.cameraControls.moveTo(t,e,i,!0)}flyToBox(t,e){const i=new p.Sphere;t.getBoundingSphere(i),this.cameraControls.fitToBox(t,!0,e)}fitToSphere(t){this.cameraControls.fitToSphere(t,!0)}flyToObject(t){const e=new p.Box3().setFromObject(t),i=new p.Sphere;e.getBoundingSphere(i),this.cameraControls.fitToSphere(i,!0)}flyToViewpoint(t){this.flyTo(t.eye,t.look),t.zoom!=null&&(this.orthographicCamera.zoom=t.zoom)}getDistanceToFitSphere(t){return this.cameraControls.getDistanceToFitSphere(t)}setNavigationMode(t){this.activeControls.mode!==t&&(this.activeControls=this.controlsMap[t],this.activeControls.setupControl())}getProjection(){return this.projection}setProjection(t){this.projection!==t&&(this.projection=t,t===bt.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection($n)}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=nn,far:s=rn,up:n=new p.Vector3(0,1,0),zoom:r=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(n.x,n.y,n.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(r),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const ai=class ai extends Vo{tableName(){return"fonts"}static instance(){return!ai._instance&&(ai._instance=new ai),ai._instance}query(t){let e;return new Promise((i,s)=>{super.query(n=>{if(!n){i(e);return}!n.value||n.value.fileName!==t||(e=n.value)},n=>{s(n)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};x(ai,"_instance");let Ri=ai;var $o=(c=>(c[c.Horizontal=0]="Horizontal",c[c.Vertical=1]="Vertical",c[c.All=2]="All",c))($o||{}),We=(c=>(c[c.Shapes=0]="Shapes",c[c.Bigfont=1]="Bigfont",c[c.Unifont=2]="Unifont",c))(We||{});class Jo extends Fl.Font{constructor(e,i){super(i);x(this,"info");x(this,"orientation");x(this,"baseUp");x(this,"baseDown");x(this,"fileHeader");x(this,"fileVersion");x(this,"fileName");x(this,"data");x(this,"order");x(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)=>{Ri.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 Ri.instance().query(this.fileName)}releaseFontData(){this.data={}}}class ei extends Jo{constructor(e,i){super(e,i);x(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=Xa(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return Xa("?",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 y={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(g){g.type.toLowerCase()==="c"&&(g.type="b"),y.o+=g.type.toLowerCase()+" ",g.x!==void 0&&g.y!==void 0&&(y.o+=a(g.x*l)+" "+a(g.y*l)+" "),g.x1!==void 0&&g.y1!==void 0&&(y.o+=a(g.x1*l)+" "+a(g.y1*l)+" "),g.x2!==void 0&&g.y2!==void 0&&(y.o+=a(g.x2*l)+" "+a(g.y2*l)+" ")}),o[String.fromCodePoint(m.unicode)]=y}}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(Rl.parse(e),this.reversed)}}function Xa(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 y=n._cachedOutline||(n._cachedOutline=n.o.split(" "));for(let g=0,M=y.length;g<M;)switch(y[g++]){case"m":a=y[g++]*t+e,o=y[g++]*t+i,r.moveTo(a,o);break;case"l":a=y[g++]*t+e,o=y[g++]*t+i,r.lineTo(a,o);break;case"q":l=y[g++]*t+e,h=y[g++]*t+i,d=y[g++]*t+e,u=y[g++]*t+i,r.quadraticCurveTo(d,u,l,h);break;case"b":l=y[g++]*t+e,h=y[g++]*t+i,d=y[g++]*t+e,u=y[g++]*t+i,f=y[g++]*t+e,m=y[g++]*t+i,r.bezierCurveTo(d,u,f,m,l,h);break}}return{offsetX:n.ha*t,path:r}}class ee{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(ee.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 fn;function fu(){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(fn=new Uint16Array(65536),e=0;e<i.length;e++)fn[i.charCodeAt(e)]=t[e]}function pu(c){!fn&&fu();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=fn[s];t[e++]=n&255,t[e++]=n>>8}}return t.subarray(0,e)}new p.Vector2;class fs extends p.Shape{constructor(e,i){super();x(this,"width");x(this,"lastPoint");x(this,"polylines");x(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 fs(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 fs(this.lastPoint.clone().applyMatrix3(e),i)}calcWidth(e){const i=this.bounds;for(let r=0;r<e.length;r++){const a=e[r];for(let o=0;o<a.length;o++){const l=a[o];i.expandByPoint(l)}}const s=i.min.x||0;return(i.max.x||0)-s}toThreeGeometry(){const e=this.polylines,i=[],s=[];let n=0;const r=new p.BufferGeometry;for(let a=0;a<e.length;a++){const o=e[a];for(let l=0;l<o.length;l++){const h=o[l];i.push(h.x,h.y,0),l===o.length-1||s.push(n,n+1),n++}}return r.userData={advanceWidth:this.width},r.setAttribute("position",new p.Float32BufferAttribute(i,3)),r.setIndex(s),r}}const yt=class yt{static parserHeader(t,e){let i="",s=!1,n=0;const r=!0;for(;r;){const a=t.readInt8(),o=String.fromCharCode(a);if(s)o===e[n]?n++:(s=!1,n=0);else{if(o===e[n]){s=!0,n++;continue}i+=o}if(s&&n===e.length)break}return i}static getCode(t){const e=pu(t);return e.length<2?e[0]:e.length<4?ee.ToUInt16(e,0):ee.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 We.Shapes:l++,d=e[l];break;case We.Bigfont:l++,d=e[l],d==0&&(l++,d=ee.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),m.x=e[l++]*i,m.y=e[l++]*i,f=e[l]*i);break;case We.Unifont:l+=2,d=ee.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=ee.byteTosbyte(e[++l]),d.y=ee.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=ee.byteTosbyte(e[++l]),u.y=ee.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=ee.byteTosbyte(e[++l]),f=(u&112)>>4;let m=u&7;m==0&&(m=8);const y=Math.PI/4;let g=y*m,M=yt.CIRCLE_SPAN;u<0&&(M=-M,g=-g);const w=y*f,b=w+g,C=s.clone().sub(new p.Vector2(Math.cos(w)*d,Math.sin(w)*d));if(s=C.clone().add(new p.Vector2(Math.cos(b)*d,Math.sin(b)*d)),o){let S=w;const O=!0;for(;O&&(S+=M,!!Number.isFinite(S));)if(u>=0&&S<b||u<0&&S>b)r.push(C.clone().add(new p.Vector2(d*Math.cos(S),d*Math.sin(S))));else break;r.push(s.clone())}}break;case 11:{const d=e[++l],u=e[++l],f=e[++l],m=e[++l],y=(f*255+m)*i,g=ee.byteTosbyte(e[++l]),M=(g&112)>>4;let w=g&7;w==0&&(w=8),u!=0&&w--;const b=Math.PI/4;let C=b*w,S=yt.CIRCLE_SPAN,O=1;g<0&&(S=-S,C=-C,O=-1);let E=b*M,v=E+C;E+=b*d/256*O,v+=b*u/256*O;const T=s.clone().sub(new p.Vector2(y*Math.cos(E),y*Math.sin(E)));if(s=T.clone().add(new p.Vector2(y*Math.cos(v),y*Math.sin(v))),o){let _=E;const P=!0;for(;P&&(_+=S,!!Number.isFinite(_));)if(g>0&&_<v||g<0&&_>v)r.push(T.clone().add(new p.Vector2(y*Math.cos(_),y*Math.sin(_))));else break;r.push(s.clone())}}break;case 12:{const d=new p.Vector2;d.x=ee.byteTosbyte(e[++l])*i,d.y=ee.byteTosbyte(e[++l])*i;let u=ee.byteTosbyte(e[++l]);u<-127&&(u=-127),o&&(u==0?r.push(s.clone().add(d)):r.push(yt.generateArcPoints(s,d,u/127))),s.add(d)}break;case 13:for(;;){const u=new p.Vector2;if(u.x=ee.byteTosbyte(e[++l])*i,u.y=ee.byteTosbyte(e[++l])*i,!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;let f=ee.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?r.push(s.clone().add(u)):r.push(yt.generateArcPoints(s.clone(),u,f/127))),s.add(u)}break;case 14:l=yt.skipCode(t,e,++l);break;default:if(h>15){const d=(h&240)>>4,u=h&15,f=new p.Vector2;switch(u){case 0:f.x=1;break;case 1:f.x=1,f.y=.5;break;case 2:f.x=1,f.y=1;break;case 3:f.x=.5,f.y=1;break;case 4:f.y=1;break;case 5:f.x=-.5,f.y=1;break;case 6:f.x=-1,f.y=1;break;case 7:f.x=-1,f.y=.5;break;case 8:f.x=-1;break;case 9:f.x=-1,f.y=-.5;break;case 10:f.x=-1,f.y=-1;break;case 11:f.x=-.5,f.y=-1;break;case 12:f.y=-1;break;case 13:f.x=.5,f.y=-1;break;case 14:f.x=1,f.y=-1;break;case 15:f.x=1,f.y=-.5;break}s.add(f.multiplyScalar(d*i)),o&&r.push(s.clone())}break}}return new fs(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 We.Shapes:i++;break;case We.Bigfont:i++,e[i]==0&&(i+=6);break;case We.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 y=Math.atan2(f.y,f.x);const g=Math.atan2(m.y,m.x);let M=yt.CIRCLE_SPAN;n?(M=-M,y<g&&(y+=2*Math.PI)):y>g&&(y-=2*Math.PI);let w=y;const b=!0;for(;b;){if(w+=M,!n&&w<g||n&&w>g)return u.add(new p.Vector2(d*Math.cos(w),d*Math.sin(w)));break}return s}};x(yt,"FILE_STOP_FLAG",["\r",`
|
|
1532
|
-
`,""]),x(yt,"CIRCLE_SPAN",Math.PI/18);let Rt=yt;const Jn={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]]]},Za=new p.Matrix3,ls=class ls extends Jo{constructor(e,i){super(e,i);x(this,"isExtend");x(this,"isUniCode");x(this,"isEmbedded");x(this,"fontType");x(this,"textShapesCache");x(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=We.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new ys(i),n=Rt.parserHeader(s,Rt.FILE_STOP_FLAG),r=n.split(" ");switch(r[1]){case"shapes":this.parseShapeFont(s),this.fontType=We.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=We.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=We.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=Rt.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=ls.DEFAULT_SIZE/this.baseUp;r=Rt.parserCode(this,a,o),this.graphicData.set(e,r)}else if(Jn[e]){const a=[];for(let o=0;o<Jn[e].length;o++)a.push(Jn[e][o].map(l=>new p.Vector2(l[0],l[1])));r=new fs(new p.Vector2,a),this.graphicData.set(e,r)}}if(this.graphicData.has(e)){const a=i/ls.DEFAULT_SIZE;Za.identity().scale(a,a),r=this.graphicData.get(e).transform(Za)}return r}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){ee.ToInt16(e.readBytes(2),0);const i=ee.ToInt16(e.readBytes(2),0),s=ee.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=ee.ToUInt16(new Uint8Array([h[1],h[0]]),0),u=ee.ToUInt16(h,2),f=ee.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=mu(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=ee.ToInt32(e.readBytes(4),0),s=ee.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=ee.ToUInt16(e.readBytes(2),0),h=ee.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(h)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=ee.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=ee.ToUInt16(e.readBytes(2),0),h=ee.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===We.Bigfont&&(i=Rt.getCode("?")),this.fontType===We.Unifont&&(i=Rt.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||We.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()}};x(ls,"DEFAULT_SIZE",12);let gt=ls;function mu(c){let t,e,i,s,n;t="";const r=c.length;for(e=0;e<r;)switch(i=c[e++],i>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:t+=String.fromCharCode(i);break;case 12:case 13:s=c[e++],t+=String.fromCharCode((i&31)<<6|s&63);break;case 14:s=c[e++],n=c[e++],t+=String.fromCharCode((i&15)<<12|(s&63)<<6|(n&63)<<0);break}return t}class xt{constructor(){x(this,"loader");x(this,"fontMap");x(this,"fileNames");x(this,"unsupportedChars");x(this,"missingFonts");x(this,"enableFontCache");this.fontMap=new Map,this.unsupportedChars={},this.missingFonts={},this.enableFontCache=!0,this.loader=new p.FileLoader}async loadFonts(t){if(t=Array.isArray(t)?t:[t],this.fileNames=t.map(e=>typeof e=="object"?Object.keys(e)[0]:xt.getFileName(e.toLowerCase())),!await this.checkAllFontsLoaded(t)){for(let e=0;e<t.length;e++){const i=t[e];let s=null,n=[],r=[];typeof i=="object"?(n=Object.keys(i),r=Object.values(i),s=n[0]):s=xt.getFileName(i.toLowerCase());let a;if(n.length){const o=n[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new gt(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}}else if(xt.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new ei(s,o)}else if(xt.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new gt(s,o)}else if(xt.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ei(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&ke.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){A.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){A.warn("[FontManager] no font loaded.");return}e==null&&(e="");const s=t.charCodeAt(0)>255,n=o=>{const l=o.getCharShape(t,i);if(l&&!(s&&o instanceof gt&&l.width<i*.5))return l};let r=this.fontMap.get(e.toLowerCase());if(!r){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,o]of this.fontMap)if(n(o)){r=o;break}}let a=r?.getCharShape(t,i);if(a&&s&&r instanceof gt&&a.width<i*.5&&(a=void 0),!a)for(const[,o]of this.fontMap){if(o===r)continue;const l=n(o);if(l){r=o,a=l;break}}if(a){if(r instanceof gt)return a.toThreeGeometry();if(r instanceof ei){const o=new Ll.TextGeometry(t,{font:r,depth:0,size:i||12,curveSegments:3,bevelSegments:3});o.computeBoundingBox();const l=o.boundingBox,h=l.min.x;return Number.isFinite(h)&&Math.abs(h)>1e-6&&o.translate(-h,0,0),o.userData.advanceWidth=Math.max(l.max.x-l.min.x,0),o}}}getNotFoundTextShape(t){let e,i;for(const[,s]of this.fontMap){const n=s.getNotFoundTextShape(t);if(n){e=n,i=s;break}}if(i instanceof gt)return e.toThreeGeometry();if(i instanceof ei)return new p.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!ke.isBrowser)return!1;let e=!1;for(let i=0;i<t.length;i++){const s=t[i];let n=null;typeof s=="object"?n=Object.keys(s)[0]:n=xt.getFileName(s.toLowerCase());const r=await Ri.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 Ri.instance().queryAll()).sort((e,i)=>e.order-i.order);for(let e=0;e<t.length;e++){const i=t[e],{fileName:s,fontType:n}=i;if(this.fileNames&&!this.fileNames.includes(s))continue;let r;n?r=new gt(s,i):r=new ei(s,i),this.fontMap.set(s,r)}A.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){A.warn("[FontManager] no font loaded.");return}let e=this.fontMap.get(t);return!e&&(e=this.fontMap.get(this.fontMap.keys().next().value),!this.missingFonts[t]&&(this.missingFonts[t]=0),this.missingFonts[t]++),e instanceof gt}getUnsupportedChar(){return this.fontMap.forEach(t=>{Object.assign(this.unsupportedChars,t.unsupportedChars)}),this.unsupportedChars}releaseFontData(){this.fontMap.forEach(t=>{t.releaseFontData()}),this.fontMap.clear()}destroy(){this.releaseFontData(),this.fontMap.clear()}static isShxFile(t){return N.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(N.getExtension(t).toUpperCase())}static isJsonFile(t){return N.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class gu{constructor(t){x(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)&&ve.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)&&ve.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=it,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 G.geometriesEqual(t,e)}}class Qo{constructor(){x(this,"TIMEOUT","timeout");x(this,"INTERVAL","interval");x(this,"timeoutMap",{});x(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 pn{constructor(t){x(this,"buffer");x(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 pn(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 es=(c=>(c[c.NULL=0]="NULL",c[c.POINT=1]="POINT",c[c.POLYLINE=3]="POLYLINE",c[c.POLYGON=5]="POLYGON",c))(es||{});class yu{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 xu{constructor(){x(this,"LINE_MATERIAL");x(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===es.POLYLINE||n.type===es.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===es.POLYGON){const y=p.ShapeUtils.triangulateShape(m,[]),g=[];y.forEach(b=>g.push(...b));const M=new p.BufferGeometry;M.setFromPoints(m),M.setIndex(g),e.push(M);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 y=new p.BufferGeometry;y.setFromPoints(m),i.push(y)}}}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===es.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 pn(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 pn(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 bu{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 yu,a=r.parse(n.response),o=new xu().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 cs=class cs{constructor(t){x(this,"gltfLoader");x(this,"font");x(this,"manager");x(this,"currentDxfLoader");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")?(A.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"))A.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 Ul.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Hl.OBJLoader(this.manager),s=new Nl.MTLLoader(this.manager),n=t.replace(".obj",".mtl"),r=await s.loadAsync(n,e);r.preload(),i.setMaterials(r);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new ql.STLLoader(this.manager),s=await i.loadAsync(t,e),n=new p.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),r=new p.Mesh(s,n);return Promise.resolve(r)}async loadShp(t,e){const i=new bu;return new Promise((s,n)=>{i.load(t,r=>{s(r)},e,r=>{n(r)})})}async loadDae(t,e){const i=new zl.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 Z(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 Gl.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 Z(this.manager,n);return this.currentDxfLoader=r,r.setFont(this.font),await this.font?.getFontFromIndexeddb(),r.manager.onLoad=()=>{s&&s()},r.loadEx(t,e,i)}abortDxfLoading(){this.currentDxfLoader?.abort(),this.currentDxfLoader=void 0}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new jl.GLTFLoader(this.manager);const t=new Vl.DRACOLoader(this.manager);t.setDecoderPath(cs.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};x(cs,"DecoderPath","libs/draco/gltf/"),x(cs,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let Ut=cs;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
|
-
`,Ka=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",el],{type:"text/javascript;charset=utf-8"});function wu(c){let t;try{if(t=Ka&&(self.URL||self.webkitURL).createObjectURL(Ka),!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(){x(this,"running");x(this,"worker");this.running=!1,this.worker=new wu,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){A.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){A.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=>{A.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)A.warn(h.error),o();else if(h.serialized){const{serialized:d,position:u,id:f}=h,m=s.get(f),y=hs.deserialize(d,m,{setIndex:!1}),g=Object.assign({setBoundingBox:!0},e);if(g.transferred&&(m.attributes.position.array=u),m.index)e.saveOriginalIndex&&!m.userData.originalIndex&&(m.userData.originalIndex=m.index.array),A.debug("before update, index:",m.index.array),m.index.array=d.index;else{const M=new L.BufferAttribute(d.index,1,!1);m.setIndex(M)}m.index&&(A.debug("after update, index:",m.index.array),m.index.needsUpdate=!0),g.setBoundingBox&&!m.boundingBox&&(m.boundingBox=y.getBoundingBox(new L.Box3)),m.boundsTree=y,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){A.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(y=>y.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Lr{constructor(t){x(this,"running");x(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){A.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){A.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;A.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&&me.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 hs(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&&me.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 Lr;return n.generate(s,e).then(()=>{n.dispose()})}}class vu{constructor(t,e,i,s,n){x(this,"object");x(this,"camera");x(this,"targetPixelHeight",100);x(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=Mu(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 Mu=(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},Zs=new p.Vector2,Ks=new p.Vector2,$s=new p.Vector2,$a=new p.Vector2,Tu=new p.Vector2,Cu=new p.Vector2,we=class we extends Ht{constructor(e){super(N.guid());x(this,"needsFrustumCulled");x(this,"renderOrder");x(this,"snapType");x(this,"osnapInfo");x(this,"drawSnapFunctions");x(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=Ot.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=we.FILL_COLOR_NONE,e.strokeStyle=we.lineColor,e.lineWidth=we.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=we.SNAP_LINE_COLOR,e.lineWidth=we.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=we.iconSize/1.6,r=Zs.set(s.x,s.y-n),a=Ks.set(s.x-.87*n,s.y+n/1.4),o=$s.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=we.iconSize,r=we.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=we.iconSize/1.6,r=Zs.set(s.x,s.y-n),a=Ks.set(s.x-.87*n,s.y+n/2),o=$s.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=we.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=we.iconSize/2,r=Zs.set(s.x-n,s.y-n),a=Ks.set(s.x+n,s.y+n),o=$s.set(s.x+n,s.y-n),l=$a.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=we.iconSize/2,r=Zs.set(s.x,s.y),a=Ks.set(s.x-n,s.y),o=$s.set(s.x,s.y+n),l=$a.set(s.x-n,s.y-n),h=Tu.set(s.x-n,s.y+n),d=Cu.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"}};x(we,"lineColor","rgba(255, 119, 0, 1)"),x(we,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),x(we,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),x(we,"lineWidth",2),x(we,"iconSize",14);let Pe=we;ms._registerDrawableClass(Pe);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 Su=1e-5,le=new p.Vector3,Oe=new p.Vector3,ki=new p.Vector3,rs=new p.Vector3,ti=new p.Matrix4,as=new p.Line3;function Eu(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 Ou(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=me.getBatchByFaceIndex(t,c.faceIndex);t.geometry.boundsTree&&(i=new p.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),ti.identity(),t instanceof p.InstancedMesh&&c.instanceId!==void 0&&t.getMatrixAt(c.instanceId,ti),ti.premultiply(t.matrixWorld);const n=t.geometry.drawRange;let r,a=e.array;if(i){let f=Math.max(0,n.start),m=Math.min(i.count,n.start+n.count);if(r=i.array,s){f=Math.max(f,s.indexStart),m=Math.min(m,s.indexStart+s.indexCount),r=i.array.slice(f,m),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let y=0;y<r.length;y++)r[y]=r[y]-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 y=a.length/3;r=y>65535?new Uint32Array(y):new Uint16Array(y);for(let g=0,M=y;g<M;g++)r[g]=g}const o=wo.buildEdge(a,r,20);let l=Number.MAX_VALUE,h=0;for(let f=0;f<o.length;f+=2){const m=o[f],y=o[f+1];le.set(a[m*3],a[m*3+1],a[m*3+2]),le.applyMatrix4(ti),Oe.set(a[y*3],a[y*3+1],a[y*3+2]),Oe.applyMatrix4(ti),as.set(le,Oe),as.closestPointToPoint(c.point,!0,ki);const g=c.point.distanceTo(ki);g<l&&(h=f,l=g,rs.copy(ki))}const d=o[h],u=o[h+1];return le.set(a[d*3],a[d*3+1],a[d*3+2]),le.applyMatrix4(ti),Oe.set(a[u*3],a[u*3+1],a[u*3+2]),Oe.applyMatrix4(ti),{vertices:[le.clone(),Oe.clone()],vertex:rs.clone(),distance:l}}class _u{constructor(t){x(this,"drawableList",new gs("snap"));x(this,"overlayRender");x(this,"markers",{});x(this,"activeOSnapType",0);x(this,"snapToleranceInWorldCoord",1);x(this,"intersectionLimit",10);x(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});x(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new Pe(Ot.TripleCross),e=new Pe(Ot.Square),i=new Pe(Ot.Triangle),s=new Pe(Ot.CircleWithCross),n=new Pe(Ot.Cross),r=new Pe(Ot.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 Di.colorStr2Rgba(Pe.lineColor)}setMarkerLineColor(t){Pe.lineColor=Di.rgba2Color(t)}getMarkerLineWidth(){return Pe.lineWidth}setMarkerLineWidth(t){Pe.lineWidth=t}getMarkerIconSize(){return Pe.iconSize}setMarkerIconSize(t){Pe.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}A.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||(A.warn("[OSnap] Potential to produce erroneous snap results"),r=s[0].point),A.debug("[OSnap] intersections:",s),A.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=Su){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;A.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=Ou(e);if(!r){A.warn("[OSnap] Failed to get edge !");return}const a=Date.now();A.debug("[OSnap] getEdgeSnappingInfo took "+(a-n)/1e3+"s "),A.debug("[OSnap] edge:",r);const o=Eu(r,t);if(A.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;le.copy(r.vertices[0]),le.add(r.vertices[1]),le.divideScalar(2);const l=le.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:le.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 A.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:V.floorNumber(m,7),type:16,point:f.clone()}}if(r<this.osnapTypePriorities[1])return;as.set(e,i),as.closestPointToPoint(t,!0,ki);const l=t.distanceTo(ki);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:V.floorNumber(f,7),type:1,point:m.clone()}}if(r<this.osnapTypePriorities[2])return;as.getCenter(rs);const u=t.distanceTo(rs);if(u<s&&this.isOSnapTypeEnabled(2))return{point:rs.clone(),distance:V.floorNumber(u,7),type:2};if(!(r<this.osnapTypePriorities[4])){if(n.line&&this.isOSnapTypeEnabled(32)){const f=G.getLineSegmentsIntersectingPoint(n.line,o);if(!f)return;const m=t.distanceTo(f)/2;return m<s?(n.line=void 0,{point:f.clone(),distance:V.floorNumber(m,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return n.line={start:e.clone(),end:i.clone()},{point:ki.clone(),distance:V.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=me.getBatchByLineIndex(l,e.index);if(d){let y=Math.max(0,f.start),g=Math.min(d.count,f.start+f.count);m&&(y=Math.max(y,m.indexStart),g=Math.min(g,m.indexStart+m.indexCount));for(let M=y,w=g;M<w-1;M+=h){const b=d.getX(M),C=d.getX(M+1);le.fromBufferAttribute(u,b),Oe.fromBufferAttribute(u,C),le.applyMatrix4(l.matrixWorld),Oe.applyMatrix4(l.matrixWorld),!i&&(le.setZ(0),Oe.setZ(0));const S=this.getOsnapInfoFromSegment(t,le,Oe,s,n,r,a);S&&(r=this.osnapTypePriorities[S.type],o.push(S))}}else{let y=Math.max(0,f.start),g=Math.min(u.count,f.start+f.count);m&&(y=Math.max(y,m.positionStart),g=Math.min(g,m.positionStart+m.positionCount));for(let M=y,w=g;M<w-1;M+=h){le.fromBufferAttribute(u,M),Oe.fromBufferAttribute(u,M+1),le.applyMatrix4(l.matrixWorld),Oe.applyMatrix4(l.matrixWorld),!i&&(le.setZ(0),Oe.setZ(0));const b=this.getOsnapInfoFromSegment(t,le,Oe,s,n,r,a);b&&(r=this.osnapTypePriorities[b.type],o.push(b))}}if(o.length!==0)return o.sort((y,g)=>{const M=this.osnapTypePriorities[y.type],w=this.osnapTypePriorities[g.type];return M!==w?M-w:y.distance-g.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,n){if(n<this.osnapTypePriorities[1])return;const r=e.object,a=r.geometry.getAttribute("position");le.fromBufferAttribute(a,e.index),le.applyMatrix4(r.matrixWorld),Oe.copy(t),!i&&(le.setZ(0),Oe.setZ(0));const o=Oe.distanceTo(le);if(o>s)return;const l={distance:o,point:le.clone(),type:1};if(r.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(A.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&&!Q.hasOutline(a,!1)){const o=Q.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)||[],A.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){x(this,"node");x(this,"parentNode");x(this,"target");x(this,"childNode");x(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});x(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));x(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));x(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 Pu{constructor(t){x(this,"viewer");x(this,"active",!1);x(this,"tooltip");x(this,"resolve");x(this,"reject");x(this,"isResolvedOrRejected",!1);x(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=_e.world2NormalizedScreen(n.min,this.camera,this.viewerContainer),a=_e.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()}}});x(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(ce.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new sl("pick-markup-tooltip",Fe.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=Fe.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(ce.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(ce.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(ce.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Bi=class Bi{constructor(t){x(this,"viewer");x(this,"input");x(this,"mouseDown",!1);x(this,"mouseMove",!1);x(this,"mouseDownPositionX",-1);x(this,"mouseDownPositionY",-1);x(this,"tempKey");x(this,"tempTouch");x(this,"tempEnableRotate",!1);x(this,"rectDom");x(this,"tooltip");x(this,"active",!1);x(this,"resolve");x(this,"reject");x(this,"isResolvedOrRejected",!1);x(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}});x(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)}});x(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});x(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",Fe.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=Fe.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(ce.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(ce.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Bi.BORDER_WIDTH} solid ${Bi.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};x(Bi,"BORDER_COLOR","#fff000"),x(Bi,"BORDER_WIDTH","2px");let mn=Bi;class nl{constructor(t){x(this,"viewer");x(this,"boxSelectHelper");x(this,"active",!1);this.viewer=t,this.boxSelectHelper=new mn(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 Ja(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 Js=new p.Box3,Au=new p.Vector3;function Iu(c,t){return c.trim().toLowerCase()===t?2e6:0}function Bu(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 xr{constructor(t){x(this,"viewer");x(this,"overlayRender");x(this,"drawableList");x(this,"indexedModelObject");x(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}invalidateIndex(){this.index=[],this.indexedModelObject=void 0}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=Ja(o.textContent);if(!l||(Js.makeEmpty(),Js.setFromObject(a),Js.isEmpty()))return;r(o.handle||"",l,o.layer||"0",this.findLayoutName(a),Js);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=Ja(d);if(!u)continue;const f=new p.Box3,m=h.positionStart||0,y=h.positionCount||0;for(let g=m;g<m+y;g++)s.fromBufferAttribute(l,g).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"?Iu(o.text,i):Bu(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,e=8){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const i=t.box.clone(),s=i.getSize(Au).length(),n=Math.max(s*e,s+2);this.viewer.zoomToBBox(i.expandByScalar((n-s)/2))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new gs("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new wt(N.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 ku extends Ht{constructor(e){super("MobileHelper");x(this,"position");x(this,"needsFrustumCulled");x(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 et=(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))(et||{});class rl extends Gt{constructor(e){super();x(this,"element");x(this,"enabled");x(this,"keyboardEnabled");x(this,"mouseDownPositionX");x(this,"mouseDownPositionY");x(this,"lastLeftPointerUpTime");x(this,"pointers");x(this,"handleClick");x(this,"handlePointerDown");x(this,"handlePointerMove");x(this,"handlePointerUp");x(this,"handlePointerCancel");x(this,"handleMouseWheel");x(this,"handleContextMenu");x(this,"handlePointerEnter");x(this,"handlePointerLeave");x(this,"handleResize");x(this,"handleKeydown");x(this,"handleKeyup");x(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,Qs(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,Qs(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const n=_e.getScreenCoordinateByEvent(i,this.element);s.x=n.x,s.y=n.y,s.movementX=i.movementX,s.movementY=i.movementY}else Qs(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else Qs(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 Qs(c,t){return c[t]!==void 0}class Du{constructor(t){x(this,"CLEAR_COLOR");x(this,"CLEAR_COLOR_ALPHA");x(this,"EMPTY_MODEL_ID");x(this,"viewer");x(this,"raycaster");x(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=_e.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const r=[],a=new Map,o=_e.screen2Ndc(t,this.camera,this.viewerContainer),l=_e.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 g=0;g<m;g++){const M=g/m*Math.PI*2,w=Math.cos(M)*s,b=Math.sin(M)*s,C={x:t.x+w,y:t.y+b},S=_e.screen2Ndc(C,this.camera,this.viewerContainer);this.raycaster.setFromCamera(S,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 y=this.raycaster.intersectObjects(e,!0)||[];for(const g of y)g.object&&!a.has(g.object.uuid)&&(a.set(g.object.uuid,g),r.push(g));if(this.raycaster.params.Line.threshold=f,r.length>1){const g=this.raycaster.ray.origin.clone();r.sort((M,w)=>{const b=M.point||M.object.getWorldPosition(new p.Vector3),C=w.point||w.object.getWorldPosition(new p.Vector3);return b.distanceTo(g)-C.distanceTo(g)})}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=eu(s),r=tu(s);if(n!==this.EMPTY_MODEL_ID)return A.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 y=new Uint8Array(4*i*s);return r.readRenderTargetPixels(n,0,0,i,s,y),r.setRenderTarget(null),a.clearViewOffset(),r.setClearColor(f,m),y}}const Qa=new p.Vector3;class Lu{constructor(t){x(this,"viewer");x(this,"scene");x(this,"renderer");x(this,"pmremGenerator");x(this,"lights");x(this,"modelGroup");this.viewer=t;const e=new p.Scene;e.matrixAutoUpdate=it,e.matrixWorldAutoUpdate=it,this.scene=e,this.modelGroup=new p.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:n}=t.container;let r;try{r=new p.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0})}catch{try{r=new p.WebGLRenderer,A.warn("WebGL context created with fallback settings (antialias disabled).")}catch(o){throw this.showWebGLUnavailable(n),new Error("WebGLUnavailable: failed to create WebGL context. "+o.message)}}r.setPixelRatio(window.devicePixelRatio),r.setSize(i,s),r.outputColorSpace=p.SRGBColorSpace,r.toneMappingExposure=1,r.localClippingEnabled=!0,r.shadowMap.enabled=!1,r.shadowMap.type=p.PCFSoftShadowMap,r.shadowMap.autoUpdate=!1,r.domElement.style.outlineWidth="0",n?.appendChild(r.domElement),this.renderer=r,N.printGpuInfo(r.getContext())}showWebGLUnavailable(t){if(!t)return;const e=document.createElement("div");e.style.cssText=["position:absolute","left:0","top:0","width:100%","height:100%","display:flex","align-items:center","justify-content:center","text-align:center","padding:0 24px","box-sizing:border-box","background:rgba(255,255,255,0.95)","color:#333","font-size:14px","line-height:1.8","z-index:9999"].join(";");const i=document.createElement("div");i.style.cssText="display:flex;flex-direction:column;align-items:center;gap:10px;max-width:560px";const s=document.createElement("span");s.style.cssText="text-align:center",s.textContent=Fe.t("WebGL.NotAvailable"),i.appendChild(s);const n="chrome://settings/system",r=document.createElement("a");r.href=n,r.textContent=Fe.t("WebGL.SettingsLink"),r.style.cssText="color:#1a73e8;text-decoration:underline;cursor:pointer;font-weight:bold";const a=document.createElement("span");a.style.cssText="color:#888;font-size:12px;text-align:center;display:none",r.addEventListener("click",o=>{o.preventDefault(),window.open(n,"_blank");try{const l=document.createElement("textarea");l.value=n,l.style.cssText="position:fixed;left:-9999px",document.body.appendChild(l),l.select(),document.execCommand("copy"),document.body.removeChild(l)}catch{}a.textContent=Fe.t("WebGL.CopyFallback"),a.style.display="block"}),i.appendChild(r),i.appendChild(a),e.appendChild(i),t.appendChild(e)}initLights(){const t=new p.Group;t.name="lights";const e=1.5,i=16777215,s=new p.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const n=new p.AmbientLight(i);n.name="ambient";const r=new p.HemisphereLight(i,14540253,.2);r.name="hemisphere",r.position.set(0,300,0);const a=new p.Group;a.name="lightHelpers",a.visible=!1;const o=new p.DirectionalLightHelper(s),l=new p.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(n),t.add(r),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new p.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}removeModel(t){this.modelGroup.remove(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 ds.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ds.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),A.debug("[Scene] directionalLight.position",t.position),A.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),Qa.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Qa),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 Ru{constructor(t){x(this,"history");x(this,"step");x(this,"maxCount");x(this,"isBatchCommand");x(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 bn extends Gt{constructor(e){super();x(this,"name");x(this,"viewerCfg");x(this,"clock");x(this,"targetMaxFps");x(this,"timeStamp");x(this,"renderEnabled");x(this,"requestAnimationFrameHandle");x(this,"container");x(this,"plugins");x(this,"loadedModels");x(this,"raf");x(this,"timeoutSymbol");x(this,"homeView");x(this,"inputManager");x(this,"cameraManager");x(this,"sceneManager");x(this,"fontManager");x(this,"pickManager");x(this,"undoManager");x(this,"overlayRender");x(this,"css2dRenderer");x(this,"spinner");x(this,"progressBar");x(this,"loaderHelper");x(this,"zoomToRectHelper");x(this,"_enableSelection");x(this,"enableRender");this.name=Qe.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 kr(e.containerId),e.enableProgressBar&&(this.progressBar=new Dr(this.container)),this.spinner=new Yo(this.container),this.sceneManager=new Lu(this),this.pickManager=new Du(this),this.overlayRender=new ms(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new rl(this.viewerContainer),this.cameraManager=new uu(this),this.loaderHelper=new Ut,this.undoManager=new Ru,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&mo(e)}initLocalization(){const e=this.viewerCfg.language||yo;Fe.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 lo.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(ce.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(ce.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(ce.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=it,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new xt),await this.fontManager.loadFonts(e)}is3d(){return!1}getPixelSizeInWorldCoord(){const e=this.camera,{clientWidth:i,clientHeight:s}=this.viewerContainer;let n=1;if(e.type==="OrthographicCamera"){const r=e;n=Math.max(r.right-r.left,r.top-r.bottom)/r.zoom/Math.max(i,s)}else if(e.type==="PerspectiveCamera"){const r=e,a=new p.Vector3;e.getWorldPosition(a);const o=this.cameraManager.getTarget();a&&o&&(n=2*(a.distanceTo(o)*Math.tan(r.fov/2*(Math.PI/180)))/s)}return n}zoomToRect(){!this.zoomToRectHelper&&(this.zoomToRectHelper=new 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,A.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)){A.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!N.isVectorValid(e)||!N.isVectorValid(i)){A.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),A.warn("[Viewer] camera could be too close to see the object!")):r>n.far&&(e=e.clone().sub(i).normalize().multiplyScalar(n.far*.9),A.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}}removeModel(e){const i=this.loadedModels.findIndex(n=>n.modelId===e);if(i===-1)return;const s=this.loadedModels.splice(i,1)[0];return this.sceneManager.removeModel(s),Q.disposeObject(s.getModelObject()),this.enableRender(),s}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.loaderHelper.abortDxfLoading(),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)){A.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),A.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,Ti=new p.Vector3,eo=new p.Matrix4,to=new p.Frustum,Qn=new p.Box3,io=new p.Matrix4;class Rr extends bn{constructor(e){super(e);x(this,"name");x(this,"loadedModels");x(this,"masterModelId");x(this,"activeLayoutName");x(this,"dxfLayoutBar");x(this,"layoutInfos");x(this,"units");x(this,"enableHideVisuallySmallObjects");x(this,"sortedHidableObjects");x(this,"lastCameraZoom");x(this,"groundPlane");x(this,"raycastableObjects");x(this,"selectedObject");x(this,"loadingDxfCount");x(this,"textSearchHelper");x(this,"clickHighlightList");x(this,"_enableClickHighlight",!1);x(this,"requestHeaders");x(this,"_printCaptureMode",!1);this.name=Qe.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects===!0,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new au(this)),this.cameraManager.setProjection(bt.Orthographic),this.cameraManager.setNavigationMode(ht.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(ce.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===et.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(ce.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),io.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Ti.fromBufferAttribute(s,l).applyMatrix4(io),r.expandByPoint(Ti);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 gs("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new wt(N.guid(),[e.clone()],[.031,.906,.867,1],[.031,.906,.867,.15])),this.enableRender())}get enableClickHighlight(){return this._enableClickHighlight}set enableClickHighlight(e){this._enableClickHighlight=e,e||this.clearClickHighlight()}clearClickHighlight(){this.clickHighlightList?.clear(),this.enableRender()}setRequestHeaders(e){this.requestHeaders=e}handleMouseClick(e){if(!this.enableSelection)return;const i=new p.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const n=this.overlayRender.getDrawablesByPosition(s)[0];if(n){this.selectedObject===n?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=n,this.selectedObject.selected=!0),this.enableRender();return}const r=this.pickObject(i,[Nt]);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){this.loaderHelper.abortDxfLoading();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=Fe.t("ProgressBar.Loading"),o=d=>{this.progressBar?.updateProgress(r,a,d),i?.(new ProgressEvent("LoadProgress",{loaded:d,total:100}))},l=(d,u,f)=>{let m=d.loaded*100/d.total;m=m*(f-u)/100+u,this.progressBar?.updateProgress(r,a,m),i?.(new ProgressEvent("LoadProgress",{loaded:m,total:100}))},h=d=>l(d,0,90);this.progressBar?.addProgressItem(r),o(0);try{this.loadingDxfCount++;const d=this.viewerCfg,u=await this.loaderHelper.loadDxfData(e.src,e.modelId,h,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:d.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor,requestHeaders:e.headers??this.requestHeaders}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),f=u.threejsObject;if(s&&s({threejsObject:f,llbMesh:u.llbMesh}),e.matrix&&e.matrix.length===16){const y=new p.Matrix4;y.elements=e.matrix,f.applyMatrix4(y)}const m=new Li({modelId:n,dxfData:u});this.addModel(m),o(100),this.progressBar?.delayRemoveProgressItem(r),this.dispatchEvent(ce.ModelLoad)}catch(d){throw this.progressBar?.removeProgressItem(r),A.error("[Viewer2d] Failed to load model '"+e.src+"'",d),d}finally{this.spinner.decreaseJobCount()}}removeModel(e){const i=super.removeModel(e);return i&&this.textSearchHelper?.invalidateIndex(),i&&this.loadedModels.length===0&&(this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0),i}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(Z.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=Z.MODEL_LAYOUT_NAME;const n=new p.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:n,extent:n},s.matrixAutoUpdate=it,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():Je.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(n=>e===n.modelId);if(!i){A.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(Z.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME)?.traverse(n=>{i.addSpatialFilterSection(n,i.dxfData)}),i.showLayoutObjects(Z.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof p.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clickHighlightList?.clear()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],n=(o,l,h)=>{s.push(new p.Vector3(o,l,h))},r=i.getSize(new p.Vector3),a=i.getCenter(new p.Vector3);if(n(-r.x/2,-r.y/2,0),n(r.x/2,-r.y/2,0),n(r.x/2,r.y/2,0),n(-r.x/2,r.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new p.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new p.MeshBasicMaterial({color:"#888",side:p.DoubleSide});this.groundPlane=new p.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=al,this.groundPlane.layers.enableAll(),Q.disableLayerChannels(this.groundPlane,[Nt]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===Z.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)}))}eo.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),to.setFromProjectionMatrix(eo);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===Z.SNAP_GROUP_NAME)?.traverse(o=>{if(Q.isLeafObject(o)){if(Qn.makeEmpty(),Qn.expandByObject(o),!to.intersectsBox(Qn))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),A.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))}),A.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",r.viewportId)):A.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return A.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===Z.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=Z.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(A.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const d=this.camera.position.z;let u=0;o.forEach(m=>{const y=m?.msToPsMatrix?.elements[14];y&&y>u&&(u=y)});const f=this.cameraManager.getPosition();if(u>f.z+d){const m=Math.ceil(u+d);f.z=m,A.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 y=d.max.x-d.min.x,g=d.max.y-d.min.y;(y<1e-16||g<1e-16||y>1e16||g>1e16)&&(A.warn("[Viewer] Got wired bbox, max: "+d.max.toArray()+", min: "+d.min.toArray()+", going to use the calculated one..."),d=l.extent)}else A.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),d=l.extent;const u=l.extent;if(d&&!u.isEmpty()){const f=d.max.x-d.min.x,m=d.max.y-d.min.y,y=u.max.x-u.min.x,g=u.max.y-u.min.y;y>0&&g>0&&y<=f*.5&&g<=m*.5?d=u.clone():d.intersectsBox(u)?d.union(u):(A.warn("[Viewer] Layout extent from header is far from actual geometry, using computed bbox instead."),d=u.clone())}l.homeViewExtent=d,this.zoomToBBox(d)}const h=i.getLayoutLevelObject(e);h&&this.setLayoutHidableObjectArray(h),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===Z.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):A.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Ti),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=_e.getScreenCoordinateByEvent(e,i),n=_e.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(n)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new xr(this)),this.textSearchHelper.search(e,i)}focusText(e,i){!this.textSearchHelper&&(this.textSearchHelper=new xr(this)),this.textSearchHelper.focus(e,i)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}async print(e={}){const{area:i="view",paperSize:s="A4",orientation:n="auto",invertColors:r=!1,fitToPage:a=!0,margins:o=10,title:l="图纸"}=e;if(!this.loadedModels.length){A.warn("[Viewer] print: no model loaded.");return}const h=this.capturePrintImage(i,r),d=new Image;await new Promise((f,m)=>{d.onload=()=>f(),d.onerror=()=>m(new Error("Failed to load captured print image.")),d.src=h});const u=n==="auto"?d.width>=d.height?"landscape":"portrait":n;this.printImageInIframe({dataUrl:h,width:d.width,height:d.height,paperSize:s,orientation:u,invertColors:r,fitToPage:a,margins:o,title:l})}capturePrintImage(e,i){const s=this.cameraManager.cameraControls,n=this.renderer,r=s.getPosition(new p.Vector3),a=s.getTarget(new p.Vector3),o=this.camera.zoom,l=n.getPixelRatio();let h;e==="extents"&&(h=this.getActiveLayoutInfo().homeViewExtent??this.getBBox(),this.zoomToBBox(h)),this._printCaptureMode=!0;const d=this.sortedHidableObjects[this.activeLayoutName],u=[];if(d)for(const O of d)O.object.userData?.layerVisible!==!1&&(u.push({object:O.object,visible:O.object.visible}),O.object.visible=!0);const{clientWidth:f,clientHeight:m}=this.viewerContainer,y=Math.min(n.capabilities.maxTextureSize||4096,8192),g=Math.min(4,y/Math.max(f,m));g>l&&n.setPixelRatio(g),this.cameraManager.update(0),this.dispatchEvent(ce.BeforeRender),n.render(this.scene,this.camera),this.dispatchEvent(ce.AfterRender);const M=n.domElement,w=this.overlayRender.getCanvas(),b=document.createElement("canvas");b.width=M.width,b.height=M.height;const C=b.getContext("2d");if(C.drawImage(M,0,0),w&&w.width>0&&w.height>0&&C.drawImage(w,0,0,b.width,b.height),i){const O=new p.Color(1973806);this.scene.background instanceof p.Color?O.copy(this.scene.background):n.getClearColor(O),O.convertLinearToSRGB(),this.invertForPrint(b,Math.max(1,Math.round(g/2)),{r:O.r*255,g:O.g*255,b:O.b*255})}let S=b.toDataURL("image/png");if(h&&this.camera.type==="OrthographicCamera"){const O=this.cropCanvasToBox(b,h);O&&(S=O)}this._printCaptureMode=!1;for(const{object:O,visible:E}of u)O.visible=E;return n.setPixelRatio(l),s.zoomTo(o),s.setLookAt(r.x,r.y,r.z,a.x,a.y,a.z),this.cameraManager.update(0),this.enableRender(),S}invertForPrint(e,i,s){const n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const r=e.width,a=e.height,o=n.getImageData(0,0,r,a),l=o.data,h=r*a,d=45,u=.72,f=new Float32Array(h);for(let E=0,v=0;E<h;E++,v+=4){const T=l[v],_=l[v+1],P=l[v+2],I=T-s.r,B=_-s.g,k=P-s.b;if(Math.sqrt(I*I+B*B+k*k)<d){l[v]=255,l[v+1]=255,l[v+2]=255,f[E]=255;continue}const D=T/255,z=_/255,se=P/255,re=Math.max(D,z,se),Ue=Math.min(D,z,se),De=(re+Ue)/2,de=re-Ue,zi=de===0?0:de/(1-Math.abs(2*De-1));let st=0;de!==0&&(re===D?st=(z-se)/de%6:re===z?st=(se-D)/de+2:st=(D-z)/de+4,st/=6,st<0&&(st+=1));const wn=Math.min(.55,(1-De)*u),Le=(1-Math.abs(2*wn-1))*zi,It=Le*(1-Math.abs(st*6%2-1)),Vi=wn-Le/2;let qt=0,Wt=0,Yt=0;const Xt=Math.floor(st*6)%6;Xt===0?(qt=Le,Wt=It):Xt===1?(qt=It,Wt=Le):Xt===2?(Wt=Le,Yt=It):Xt===3?(Wt=It,Yt=Le):Xt===4?(qt=It,Yt=Le):(qt=Le,Yt=It),l[v]=(qt+Vi)*255,l[v+1]=(Wt+Vi)*255,l[v+2]=(Yt+Vi)*255,f[E]=.299*l[v]+.587*l[v+1]+.114*l[v+2]}const m=Math.max(1,i),y=new Float32Array(h),g=new Uint8ClampedArray(h),M=new Uint8ClampedArray(h),w=new Uint8ClampedArray(h);for(let E=0;E<a;E++){const v=E*r;for(let T=0;T<r;T++){let _=255,P=v+T;const I=Math.max(0,T-m),B=Math.min(r-1,T+m);for(let k=I;k<=B;k++){const D=f[v+k];D<_&&(_=D,P=v+k)}y[v+T]=_,g[v+T]=l[P*4],M[v+T]=l[P*4+1],w[v+T]=l[P*4+2]}}const b=new Float32Array(h),C=new Uint8ClampedArray(h),S=new Uint8ClampedArray(h),O=new Uint8ClampedArray(h);for(let E=0;E<r;E++)for(let v=0;v<a;v++){let T=255,_=v*r+E;const P=Math.max(0,v-m),I=Math.min(a-1,v+m);for(let k=P;k<=I;k++){const D=y[k*r+E];D<T&&(T=D,_=k*r+E)}const B=v*r+E;b[B]=T,C[B]=g[_],S[B]=M[_],O[B]=w[_]}for(let E=0,v=0;E<h;E++,v+=4)f[E]>250&&b[E]<250&&(l[v]=C[E],l[v+1]=S[E],l[v+2]=O[E]);n.putImageData(o,0,0)}cropCanvasToBox(e,i){const s=this.camera,n=s.zoom||1,r=s.position.x,a=s.position.y,o=r+s.left/n,l=r+s.right/n,h=a+s.bottom/n,d=a+s.top/n,u=l-o,f=d-h;if(u<=0||f<=0)return;const m=v=>(v-o)/u*e.width,y=v=>(d-v)/f*e.height,g=Math.max(u,f)*.01,M=Math.max(0,Math.floor(m(i.min.x-g))),w=Math.min(e.width,Math.ceil(m(i.max.x+g))),b=Math.max(0,Math.floor(y(i.max.y+g))),C=Math.min(e.height,Math.ceil(y(i.min.y-g))),S=w-M,O=C-b;if(S<16||O<16)return;const E=document.createElement("canvas");return E.width=S,E.height=O,E.getContext("2d").drawImage(e,M,b,S,O,0,0,S,O),E.toDataURL("image/png")}printImageInIframe(e){const{dataUrl:i,width:s,height:n,paperSize:r,orientation:a,invertColors:o,fitToPage:l,margins:h,title:d}=e,u={A4:[210,297],A3:[297,420],A2:[420,594],A1:[594,841],A0:[841,1189],Letter:[215.9,279.4]};let[f,m]=u[r]??u.A4;a==="landscape"&&([f,m]=[m,f]);const y=document.createElement("iframe");y.setAttribute("aria-hidden","true");const g=96/25.4;y.style.cssText=`position:fixed;left:-20000px;top:0;border:0;visibility:hidden;width:${Math.ceil(f*g)}px;height:${Math.ceil(m*g)}px;`;const M=v=>v.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),w=l?"max-width:100%;max-height:100%;width:auto;height:auto;":"width:100%;height:auto;",b=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${M(d)}</title><style>@page{size:${r} ${a};margin:${h}mm;}html,body{margin:0;padding:0;background:#fff;}body{display:flex;align-items:center;justify-content:center;width:${f-2*h}mm;height:${m-2*h}mm;overflow:hidden;}img{display:block;${w}}</style></head><body><img src="${i}" alt="${M(d)}"></body></html>`;document.body.appendChild(y);const C=()=>{y.contentWindow?.removeEventListener("afterprint",C),setTimeout(()=>y.remove(),100)},S=y.contentDocument;S.open(),S.write(b),S.close();const O=S.querySelector("img"),E=()=>{const v=y.contentWindow;v.addEventListener("afterprint",C),v.focus(),v.print(),setTimeout(C,6e4)};O.complete?E():(O.onload=E,O.onerror=C)}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 A.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||!Q.isLeafObject(h))return;const d=h.geometry;d.boundingBox||d.computeBoundingBox();const u=d.boundingBox.clone();if(!u||!N.isBoxValid(u))return;u.applyMatrix4(h.matrixWorld),u.getSize(Ti);const f=Math.max(Ti.x,Ti.y),m=o/f;m<1/0?r.push({visibleMinZoom:m,object:h}):h instanceof p.Points?r.push({visibleMinZoom:o,object:h}):A.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),A.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5)return;if(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,this._printCaptureMode){this.lastCameraZoom=s;return}if(!this.sortedHidableObjects[this.activeLayoutName])return;const n=this.sortedHidableObjects[this.activeLayoutName];if(n.length===0)return;const r=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let h=0;for(let d=0;d<n.length;++d)if(n[d].object.userData.layerVisible!==!1){if(n[d].visibleMinZoom<a){l.push(n[d].object);continue}else if(n[d].visibleMinZoom>o)break;n[d].object.visible=r,r&&l.push(n[d].object),h++}this.lastCameraZoom=s,A.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+h+"(out of "+n.length+") objects changed to "+(r?"visible":"hidden"))}updateCameraZoomUniform(e){Z.CameraZoomUniform.value=e*this.container.height/50}}class ol{constructor(t){x(this,"viewer");x(this,"fontManager");x(this,"loader");x(this,"loadingManager");x(this,"changes");x(this,"container");x(this,"spinner");x(this,"jobCount");x(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Rr(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new kr(t.containerId);this.loadingProgressBar=new Dr(i);const s={ignorePaperSpace:!0};this.loader=new Z(this.loadingManager,s),this.initSpinner()}initSpinner(){const t=document.createElement("div");t.classList.add("x-spinner"),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),t.appendChild(document.createElement("span")),this.container.appendChild(t),this.spinner=t,this.setSpinnerVisibility(this.jobCount>0)}async setFont(t){const e=Date.now();!this.fontManager&&(this.fontManager=new xt),await this.fontManager.loadFonts(t),A.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();this.increaseJobCount();try{if(!this.fontManager)throw"[DxfCompareHelper] Should set font first!";this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=n+a,h=Fe.t("ProgressBar.Comparing"),d=B=>{this.loadingProgressBar?.updateProgress(l,h,B),s&&s(new ProgressEvent("CompareProgress",{loaded:B,total:100}))},u=(B,k,D)=>{let z=B.loaded*100/B.total;z=z*(D-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),y=B=>u(B,30,60),g=B=>u(B,60,95);N.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),d(0);let M=Date.now();const w=this.loader.parse(n,f),b=this.loader.parse(a,m),[C,S]=await Promise.allSettled([w,b]);if(C.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+n;if(S.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+a;if(A.info("[DxfCompareHelper] loadFiles in "+(Date.now()-M)/1e3+"s"),this.loader.isAborted())throw"[DxfCompareHelper] compare loadFile aborted";const O=C.value,E=S.value;M=Date.now();const v=await new ct(O,E,i).compare(y);if(A.info("[DxfCompareHelper] Compared in "+(Date.now()-M)/1e3+"s"),A.debug("[DxfCompareHelper] Compared results:",v),this.loader.isAborted())throw"[DxfCompareHelper] compare change aborted";N.printMemory("After getting the comparison results"),M=Date.now(),await this.loader.loadEntitiesForCompare(O,E,v,!0,g),N.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=v,A.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-M)/1e3+"s");const T=O,_=E;if(!Object.keys(v).length&&A.info("[DxfCompareHelper] No change found"),T.threejsObject?.children.length===0&&_.threejsObject?.children.length===0){const B="[DxfCompareHelper] Nothing was loaded from "+n+" and "+a;throw A.warn(B),B}const P=T.threejsObject,I=_.threejsObject;P.name=n,I.name=a,M=Date.now(),this.viewer.addModel(new Li({modelId:t.modelId||t.src,dxfData:T})),this.viewer.flyToObject(P),N.printMemory("After adding first loaded Model to scene"),d(95),this.viewer.addModel(new Li({modelId:e.modelId||e.src,dxfData:_})),N.printMemory("After adding second loaded Model to scene"),A.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-M)/1e3+"s"),A.info("[DxfCompareHelper] The comparison between "+n+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),d(100),this.loadingProgressBar?.delayRemoveProgressItem(l)}catch(l){throw this.loadingProgressBar?.removeProgressItem(n+a),l}finally{this.decreaseJobCount()}}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 Fu extends ol{constructor(e,i){super(e);x(this,"viewer2");x(this,"syncCamera");x(this,"markupManager1");x(this,"markupManager2");x(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 Rr(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();this.increaseJobCount();try{if(!this.fontManager)throw"[DxfCompareHelper] Should set font first!";this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const d=r+o,u=Fe.t("ProgressBar.Comparing"),f=D=>{this.loadingProgressBar?.updateProgress(d,u,D),n&&n(new ProgressEvent("CompareProgress",{loaded:D,total:100}))},m=(D,z,se)=>{let re=D.loaded*100/D.total;re=re*(se-z)/100+z,this.loadingProgressBar?.updateProgress(d,u,re),n&&n(new ProgressEvent("CompareProgress",{loaded:re,total:100}))},y=D=>m(D,0,15),g=D=>m(D,15,30),M=D=>m(D,30,60),w=D=>m(D,60,95);N.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(d),f(0);let b=Date.now();const C=this.loader.parse(r,y),S=this.loader.parse(o,g),[O,E]=await Promise.allSettled([C,S]);if(O.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+r;if(E.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+o;if(A.info("[DxfCompareHelper] loadFiles in "+(Date.now()-b)/1e3+"s"),this.loader.isAborted())throw"[DxfCompareHelper] compare loadFile aborted";const v=O.value,T=E.value;b=Date.now();const _=await new ct(v,T,s).compare(M);if(A.info("[DxfCompareHelper] Compared in "+(Date.now()-b)/1e3+"s"),A.debug("Compared results:",_),this.loader.isAborted())throw"[DxfCompareHelper] compare change aborted";N.printMemory("After getting the comparison results"),b=Date.now(),await this.loader.loadEntitiesForCompare(v,T,_,!1,w),N.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=_,A.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-b)/1e3+"s");const P=v,I=T;if(!Object.keys(_).length&&A.info("[DxfCompareHelper] No change found"),P.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const D="[DxfCompareHelper] Nothing was loaded from "+r+" and "+o;throw A.warn(D),D}const B=P.threejsObject,k=I.threejsObject;B.name=r,k.name=o,b=Date.now(),this.viewer.addModel(new Li({modelId:e.modelId||e.src,dxfData:P})),N.printMemory("After adding first loaded Model to scene"),f(95),this.viewer2.addModel(new Li({modelId:i.modelId||i.src,dxfData:I})),N.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),A.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-b)/1e3+"s"),A.info("[DxfCompareHelper] The comparison between "+r+"' and '"+o+"' is completed in "+(Date.now()-h)/1e3+"s !"),f(100),this.loadingProgressBar?.delayRemoveProgressItem(d)}catch(d){throw this.loadingProgressBar?.removeProgressItem(r+o),d}finally{this.decreaseJobCount()}}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new yr(this.viewer)),this.markupManager2??(this.markupManager2=new yr(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)))}}}const zu=["图框","图签","标题栏","title","tk","frame","border"],Vu=.02,Uu=10,so=.5,ju=.6;function Nu(c){return c.charCodeAt(0)===65279?c.slice(1):c}function Ne(c){return Math.max(0,c.maxX-c.minX)*Math.max(0,c.maxY-c.minY)}function er(c,t){return{minX:Math.max(c.minX,t.minX),minY:Math.max(c.minY,t.minY),maxX:Math.min(c.maxX,t.maxX),maxY:Math.min(c.maxY,t.maxY)}}function no(c,t,e,i=0){return t>=c.minX-i&&t<=c.maxX+i&&e>=c.minY-i&&e<=c.maxY+i}const St=class St{constructor(t,e){x(this,"lines");x(this,"options");x(this,"sections",[]);x(this,"entityBlocks",[]);x(this,"blockDefs",new Map);x(this,"drawingBBox",null);x(this,"frames",[]);x(this,"assignments",[]);x(this,"detected",!1);this.lines=Nu(t).split(/\r\n|\r|\n/),this.options={minAreaRatio:Vu,templateGroupThreshold:Uu,...e},this.scanSections(),this.scanBlockDefs(),this.scanEntityBlocks()}static async fromUrl(t,e){const i=await fetch(t);if(!i.ok)throw new Error(`[DxfSplitter] Failed to fetch dxf: ${i.status} ${t}`);return new St(await i.text(),e)}static async fromFile(t,e){return new St(await t.text(),e)}getFrames(){return this.frames}getUnassignedCount(){let t=0;for(const e of this.assignments)e<0&&t++;return t}detectFrames(){if(this.detected)return this.frames;this.detected=!0,this.report(5,"扫描实体");const t=this.collectCandidates();this.report(35,"筛选图框");const e=this.filterAndSortCandidates(t),i=this.frames.filter(n=>n.source==="manual"),s=i.reduce((n,r)=>Math.max(n,r.index+1),0);e.forEach((n,r)=>{n.index=s+r}),this.frames=[...e,...i],this.report(55,"归属实体"),this.assignEntities(e),this.report(85,"识别图纸名称"),this.applyTitleNames(e);for(const n of i)n.entityCount=this.reassignManualEntities(n);return this.report(100,`识别到 ${this.frames.length} 个图框`),this.frames}isTitleNoise(t){const e=t.replace(/\\P/g,"").replace(/%%[UOoCcdD]/g,"").replace(/\s+/g,"");return e.length<=1?!0:St.TITLE_NOISE.some(i=>i.test(e))}extractFrameTitle(t){const e=t.bbox,i=e.maxX-e.minX,s=e.maxY-e.minY,n=e.maxX-i*.5,r=e.minY,a=e.minY+s*.22,o=[],l=this.lines;for(let y=0;y<this.entityBlocks.length;y++){if(this.assignments[y]!==t.index)continue;const g=this.entityBlocks[y];if(g.type!=="TEXT"&&g.type!=="MTEXT")continue;let M,w,b=0,C="";for(let O=g.start+2;O+1<g.end;O+=2){const E=parseInt(l[O],10),v=l[O+1];E===10?M=parseFloat(v):E===20?w=parseFloat(v):E===40?b=parseFloat(v):(E===1||E===3)&&(C+=v)}if(M===void 0||w===void 0||!C||M<n||M>e.maxX||w<r||w>a)continue;const S=C.replace(/\\P/g,"").replace(/%%[UOoCcdD]/g,"").replace(/\s+/g,"");this.isTitleNoise(S)||o.push({x:M,y:w,hgt:b||2.5,txt:S})}if(!o.length)return null;o.sort((y,g)=>g.y-y.y);const h=[];for(const y of o){const g=h.find(M=>Math.abs(M[0].y-y.y)<=Math.max(M[0].hgt,y.hgt)*1.6);g?g.push(y):h.push([y])}const d=h.map(y=>{const{y:g,hgt:M}=y[0];y.sort((C,S)=>C.x-S.x);const w=y.filter(C=>!(St.DRAWING_NO.test(C.txt)&&/\d/.test(C.txt))),b=w.map(C=>C.txt).join("");return{txt:b,len:b.length,x:w.length?w[0].x:y[0].x,y:g,hgt:M,row:y}}).filter(y=>y.len>=2);if(!d.length)return null;const u=d.filter(y=>y.txt.includes("图")&&y.txt.length>=4),f=u.length?u.sort((y,g)=>g.len-y.len)[0]:d.sort((y,g)=>g.len-y.len)[0];let m=f.txt;if(f.txt.includes("图")){const y=d[d.indexOf(f)-1]?.row;if(y&&Math.abs(y[0].y-f.y)<=s*.06){const g=y.filter(M=>!(St.DRAWING_NO.test(M.txt)&&/\d/.test(M.txt))&&!M.txt.includes("图")&&M.txt.length<=15&&Math.abs(M.x-f.x)<=i*.05).sort((M,w)=>Math.abs(M.x-f.x)-Math.abs(w.x-f.x))[0];g&&(m=g.txt+f.txt)}}return m.slice(0,40).replace(/[\\/:*?"<>|]/g,"_")||null}applyTitleNames(t){for(const i of t){const s=this.extractFrameTitle(i);s&&(i.name=s)}const e=new Map;for(const i of t){const s=e.get(i.name)??0;e.set(i.name,s+1),s>0&&(i.name=`${i.name}(${s+1})`)}}addManualFrame(t){if(Ne(t)<=0)return null;const e=this.frames.reduce((a,o)=>Math.max(a,o.index+1),0),i=this.frames.filter(a=>a.source==="manual").length+1,s={index:e,name:`手工框选${i}`,source:"manual",bbox:{...t},entityCount:0},n=new Set(this.frames.map(a=>a.name));if(n.has(s.name)){let a=2;for(;n.has(`${s.name}(${a})`);)a++;s.name=`${s.name}(${a})`}this.frames.push(s),s.entityCount=this.reassignManualEntities(s);const r=this.extractFrameTitle(s);if(r&&r!==s.name&&(s.name=r,n.has(s.name))){let a=2;for(;n.has(`${s.name}(${a})`);)a++;s.name=`${s.name}(${a})`}return this.report(100,`手工框选「${s.name}」(${s.entityCount} 实体)`),s}reassignManualEntities(t){const e=t.bbox;let i=0;for(let s=0;s<this.entityBlocks.length;s++){const n=this.entityBlocks[s].bbox;if(!n)continue;const r=Ne(n);let a;if(r<=1e-12?a=no(e,(n.minX+n.maxX)/2,(n.minY+n.maxY)/2):a=Ne(er(n,e))/r>=so,!a)continue;const o=this.assignments[s];if(o!==t.index){if(o>=0){const l=this.frames.find(h=>h.index===o);l&&l.entityCount--}this.assignments[s]=t.index,i++}}return i}removeFrame(t){const e=this.frames.findIndex(i=>i.index===t);if(e<0)return!1;this.frames.splice(e,1);for(let i=0;i<this.assignments.length;i++)this.assignments[i]===t&&(this.assignments[i]=-1);return!0}updateFrameBBox(t,e){const i=this.frames.find(s=>s.index===t);if(!i||Ne(e)<=0)return null;i.bbox={...e};for(let s=0;s<this.assignments.length;s++)this.assignments[s]===t&&(this.assignments[s]=-1);return i.entityCount=this.reassignManualEntities(i),this.report(100,`调整图框「${i.name}」(${i.entityCount} 实体)`),i}split(t){if(this.detected||this.detectFrames(),this.frames.length===0)return[];const e=new Set(t?t.filter(u=>this.frames.some(f=>f.index===u)):this.frames.map(u=>u.index));if(e.size===0)return[];this.report(10,"组装子 DXF");const i=this.sections.find(u=>u.name==="HEADER"),s=[];if(i)for(let u=i.start;u<=i.end+1&&u<this.lines.length;u++)s.push(this.lines[u]);const n=[],r=[];let a=!1;for(const u of this.sections){if(u.name==="ENTITIES"){a=!0;continue}if(u.name==="HEADER")continue;const f=a?r:n;for(let m=u.start;m<=u.end+1&&m<this.lines.length;m++)f.push(this.lines[m])}const o=n.join(`\r
|
|
1531
|
+
`,qo=Symbol("INITIAL_FRUSTUM_CULLED");function nu(c,t){c.traverse(e=>{e.frustumCulled=e[qo]&&t})}const Hs=new p.Vector3,Gs=new p.Vector3,Gn=new p.Box3;class Wo extends Bl.TilesRenderer{constructor(e,i){super(e);y(this,"highlighUsage");y(this,"transparentUsage");y(this,"pickUsage");y(this,"materialManager");y(this,"baseUrl");y(this,"propertyParser");y(this,"tilesetId");y(this,"onBeforeParseTile");y(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=nc.parse(su).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(b=>za(this.tilesetId,b)),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 x=a.length>0;x&&f.setAttribute("barycentric",new p.BufferAttribute(a,1));const g=this.materialManager?.createBatchMaterial(l,m,x),M=new p.Mesh(f,g),w=new p.Mesh(f,this.materialManager?.pickMaterial);return{mesh:M,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(S=>za(this.tilesetId,S)),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 x=o.length>0;x&&m.setAttribute("barycentric",new p.BufferAttribute(o,1));const g=this.propertyParser.getMaterialParameters(d),M=this.materialManager?.createInstanceMaterial(d,g,x),w=new p.InstancedMesh(m,M,f);w.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16);let b=n;b.length===0&&(b=this.getVertexColorArray(f*3,g?.color)),w.instanceColor=new p.InstancedBufferAttribute(b,3);const C=new p.InstancedMesh(m,this.materialManager?.pickMaterial,f);return C.instanceMatrix=new p.InstancedBufferAttribute(new Float32Array(l),16),{mesh:w,pickMesh:C,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"),x=o.geometry.index,g=o.geometry.getAttribute("tileObjectId");if(o instanceof p.InstancedMesh){const M=new p.Matrix4;o.getMatrixAt(u,M),f.setAttribute("position",m.clone());const w=g.array[u*g.itemSize];f.setAttribute("tileObjectId",new p.Int32BufferAttribute(new Array(m.array.length/3).fill(w),1)),x&&f.setIndex(x),f.applyMatrix4(M)}else{const{indexStart:M,indexCount:w,positionStart:b,positionCount:C}=o.userData.batchTable.find(P=>P.userId===d),S=m.itemSize,O=m.array.slice(b*S,b*S+C*S),E=new p.Float32BufferAttribute(O,S);f.setAttribute("position",E);const v=g.array.slice(b,b+C),T=new p.Int32BufferAttribute(v,1);if(f.setAttribute("tileObjectId",T),x){const P=x.array.slice(M,M+w);for(let _=0;_<P.length;_++)P[_]-=b;f.setIndex(new p.BufferAttribute(P,1))}}f.applyMatrix4(o.matrixWorld),s.push(f)}}}}),A.info("[BimTiles] getGeometryByUserIds took "+(Date.now()-i)/1e3+"s"),s.length>1?Ie.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 iu().parse(e,this.baseUrl,this.protoRoot).then(({batchedMeshes:o,instancedMeshes:l})=>{A.debug("[BimTiles] batchedMeshes:",o),A.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:x,batchTable:g}=this.createBatchedMesh(f);h.add(m),m.userData.batchTable=g,m.userData.userIds=g.map(M=>M.userId),d.add(x)}),l.forEach(f=>{const{mesh:m,pickMesh:x,userIds:g}=this.createInstancedMesh(f);h.add(m),m.userData.userIds=g,d.add(x)});const u=f=>{f.applyMatrix4(r)};u(h),h.traverse(f=>{f[qo]=f.frustumCulled}),nu(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)&&(Gn.setFromArray(e.boundingVolume),e.cached&&e.cached.boundingVolume&&(Gn.getCenter(Hs),Gn.getSize(Gs),e.cached.boundingVolume.setObbData([Hs.x,Hs.y,Hs.z,Gs.x/2,0,0,0,Gs.y/2,0,0,0,Gs.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 K1(this,{maxId:n.properties.userId.maxUserIdIndex})});return s.catch(n=>{A.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 x=u.pixelSize;m=e.geometricError/(x*f)}else{const x=a.distanceToPoint(u.position),g=x*f,M=u.sseDenominator;m=e.geometricError/(g*M),l=Math.min(l,g)}o=Math.max(o,m)}e.__distanceFromCamera=l,e.__error=o}}class Br extends xn{constructor(e,i,s){super();y(this,"modelId");y(this,"_bbox");y(this,"tilesRenderer");y(this,"metadata");y(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(ii.Hovered,[e],i)}clearHovered(){this.materialManager.clearHovered()}setObjectHighlightedByUserIds(e,i){this.materialManager.updateState(ii.Highlighted,e,i)}clearHighlight(){this.materialManager.clearState(ii.Highlighted)}setDoubleSidedMaterials(){this.materialManager.setDoubleSidedMaterials()}revertDoubleSidedMaterials(){this.materialManager.revertDoubleSidedMaterials()}setObjectOpacityByUserIds(e,i){this.materialManager.updateState(ii.Transparent,e,!0,i)}clearObjectOpacityByUserIds(e){this.materialManager.updateState(ii.Transparent,e,!1)}setOpacity(e){this.materialManager.setOpacity(e)}clearOpacity(){this.materialManager.setOpacity(1)}setVisible(e){this.materialManager.setHidden(!e)}setObjectVisibleByUserIds(e,i){this.materialManager.updateState(ii.Hidden,e,!i)}hasVisibleObject(){return this.materialManager.hasVisibleObject()}hasInvisibleObject(){return this.materialManager.hasInvisibleObject()}getHoveredObject(){return this.materialManager?.getHoveredObject()}getBBoxByUserId(e){return this.propertyParser.getUserIdBox(e)}getUserDataByUserId(e){return this.propertyParser.getUserData(e)}getUserIds(){return this.propertyParser.getUserIds()}getUserId(e,i){return this.propertyParser.getUserIdsByFamilyInstanceId(e,i)}getUserData(e,i){const s=this.getUserId(e,i);if(s.length>0)return this.getUserDataByUserId(s[0])}getUserIdByFilter(e){return this.propertyParser.getUserIdByFilter(e)}setClipPlanes(e){this.materialManager.setClipPlanes(e)}}function ru(){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 au{constructor(t){y(this,"viewer");y(this,"element");y(this,"content");y(this,"itemList");y(this,"handleMouseWheel");this.viewer=t,this.itemList={},this.handleMouseWheel=e=>{e.preventDefault(),this.element&&(this.element.scrollLeft+=e.deltaY)},t.addEventListener(ce.ModelLoad,()=>{this.init()})}init(){this.destroy();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 ou(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 ou{constructor(t,e){y(this,"viewer");y(this,"eventBus");y(this,"element");y(this,"resetActivate");y(this,"active");this.viewer=t,this.eventBus=ru(),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){y(this,"element");y(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 kr{constructor(t){y(this,"width");y(this,"height");y(this,"container");y(this,"viewerContainer");y(this,"widgetContainer");this.width=0,this.height=0;let e=document.getElementById(t);e||(A.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 Dr{constructor(t){y(this,"element");y(this,"progressItems");y(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)&&A.error("[Viewer] ProgressItem with id "+t+" already exists!");const s=document.createElement("div");s.classList.add("progress-bar-item"),s.innerHTML=ze.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 et=(c=>(c.BaseViewer="BaseViewer",c.Viewer3d="Viewer3d",c.Viewer2d="Viewer2d",c.BimTilesViewer="BimTilesViewer",c))(et||{}),wt=(c=>(c.Perspective="Perspective",c.Orthographic="Orthographic",c))(wt||{});const lu={enableSpinner:!0,containerId:"myCanvas"},Y={LEFT:1,RIGHT:2,MIDDLE:4},R=Object.freeze({NONE:0,ROTATE:1,TRUCK:2,OFFSET:4,DOLLY:8,ZOOM:16,TOUCH_ROTATE:32,TOUCH_TRUCK:64,TOUCH_OFFSET:128,TOUCH_DOLLY:256,TOUCH_ZOOM:512,TOUCH_DOLLY_TRUCK:1024,TOUCH_DOLLY_OFFSET:2048,TOUCH_DOLLY_ROTATE:4096,TOUCH_ZOOM_TRUCK:8192,TOUCH_ZOOM_OFFSET:16384,TOUCH_ZOOM_ROTATE:32768});function ct(c){return c.isPerspectiveCamera}function We(c){return c.isOrthographicCamera}class cu{constructor(){y(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 bi=Math.PI*2,Ua=Math.PI/2;function qn(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 Wn(c,t){return We(c)?(console.warn(t+" is not supported in OrthographicCamera"),!0):!1}const Xo=1e-5,Zi=Math.PI/180;function Ei(c,t,e){return Math.max(t,Math.min(e,c))}function oe(c,t=Xo){return Math.abs(c)<t}function ae(c,t,e=Xo){return oe(c-t,e)}function ja(c,t){return Math.round(c/t)*t}function Ki(c){return isFinite(c)?c:c<0?-Number.MAX_VALUE:Number.MAX_VALUE}function $i(c){return Math.abs(c)<Number.MAX_VALUE?c:c*(1/0)}function qs(c,t,e,i,s=1/0,n){i=Math.max(1e-4,i);const r=2/i,a=r*n,o=1/(1+a+.48*a*a+.235*a*a*a);let l=c-t;const h=t,d=s*i;l=Ei(l,-d,d),t=c-l;const u=(e.value+r*l)*n;e.value=(e.value-r*u)*o;let f=t+(l+u)*o;return h-c>0==f>h&&(f=h,e.value=(f-h)/n),f}function Na(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,x=c.z-u;const g=h,M=d,w=u,b=s*i,C=b*b,S=f*f+m*m+x*x;if(S>C){const D=Math.sqrt(S);f=f/D*b,m=m/D*b,x=x/D*b}h=c.x-f,d=c.y-m,u=c.z-x;const O=(e.x+a*f)*n,E=(e.y+a*m)*n,v=(e.z+a*x)*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+(x+v)*l;const T=g-c.x,P=M-c.y,_=w-c.z,I=r.x-g,B=r.y-M,k=r.z-w;return T*I+P*B+_*k>0&&(r.x=g,r.y=M,r.z=w,e.x=(r.x-g)/n,e.y=(r.y-M)/n,e.z=(r.z-w)/n),r}const Ws=1/8,hu=De.isBrowser&&/Mac/.test(navigator.platform),du=!(De.isBrowser&&"PointerEvent"in window);let W,Ha,Ys,Yn,Ne,X,ie,wi,mt,gt,Qt,Ga,qa,ot,Ji,vi,Wa,Xn,Ya,Zn,Kn,Xs;class J extends cu{constructor(e,i){super();y(this,"minPolarAngle");y(this,"maxPolarAngle");y(this,"minAzimuthAngle");y(this,"maxAzimuthAngle");y(this,"minDistance");y(this,"maxDistance");y(this,"infinityDolly");y(this,"minZoom");y(this,"maxZoom");y(this,"smoothTime");y(this,"draggingSmoothTime");y(this,"maxSpeed");y(this,"azimuthRotateSpeed");y(this,"polarRotateSpeed");y(this,"dollySpeed");y(this,"truckSpeed");y(this,"dollyToCursor");y(this,"dragToOffset");y(this,"verticalDragToForward");y(this,"boundaryFriction");y(this,"restThreshold");y(this,"colliderMeshes");y(this,"mouseButtons");y(this,"touches");y(this,"cancel");y(this,"_enabled");y(this,"_camera");y(this,"_yAxisUpSpace");y(this,"_yAxisUpSpaceInverse");y(this,"_state");y(this,"_domElement");y(this,"_viewport");y(this,"_target");y(this,"_targetEnd");y(this,"_focalOffset");y(this,"_focalOffsetEnd");y(this,"_spherical");y(this,"_sphericalEnd");y(this,"_zoom");y(this,"_zoomEnd");y(this,"_target0");y(this,"_position0");y(this,"_zoom0");y(this,"_focalOffset0");y(this,"_dollyControlAmount");y(this,"_dollyControlCoord");y(this,"_nearPlaneCorners");y(this,"_hasRested");y(this,"_boundary");y(this,"_boundaryEnclosesCamera");y(this,"_needsUpdate");y(this,"_updatedLastTime");y(this,"_elementRect");y(this,"_activePointers");y(this,"_isUserControllingRotate");y(this,"_isUserControllingDolly");y(this,"_isUserControllingTruck");y(this,"_isUserControllingOffset");y(this,"_isUserControllingZoom");y(this,"_thetaVelocity");y(this,"_phiVelocity");y(this,"_radiusVelocity");y(this,"_targetVelocity");y(this,"_focalOffsetVelocity");y(this,"_zoomVelocity");y(this,"_truckInternal");y(this,"_rotateInternal");y(this,"_dollyInternal");y(this,"_zoomInternal");this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.minDistance=0,this.maxDistance=1/0,this.infinityDolly=!1,this.minZoom=.01,this.maxZoom=1/0,this.smoothTime=.25,this.draggingSmoothTime=.125,this.maxSpeed=1/0,this.azimuthRotateSpeed=1,this.polarRotateSpeed=1,this.dollySpeed=1,this.truckSpeed=2,this.dollyToCursor=!1,this.dragToOffset=!1,this.verticalDragToForward=!1,this.boundaryFriction=0,this.restThreshold=.01,this.colliderMeshes=[],this.cancel=()=>{},this._enabled=!0,this._state=R.NONE,this._viewport=null,this._dollyControlAmount=0,this._hasRested=!0,this._boundaryEnclosesCamera=!1,this._needsUpdate=!0,this._updatedLastTime=!1,this._elementRect=De.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 W.Vector3,this._focalOffsetVelocity=new W.Vector3,this._zoomVelocity={value:0},this._truckInternal=(b,C,S)=>{if(ct(this._camera)){const O=X.copy(this._camera.position).sub(this._target),E=this._camera.getEffectiveFOV()*Zi,v=O.length()*Math.tan(E*.5),T=this.truckSpeed*b*v/this._elementRect.height,P=this.truckSpeed*C*v/this._elementRect.height;this.verticalDragToForward?(S?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y,this._focalOffsetEnd.z,!0):this.truck(T,0,!0),this.forward(-P,!0)):S?this.setFocalOffset(this._focalOffsetEnd.x+T,this._focalOffsetEnd.y+P,this._focalOffsetEnd.z,!0):this.truck(T,P,!0)}else if(We(this._camera)){const O=this._camera,E=this.truckSpeed*b*(O.right-O.left)/O.zoom/this._elementRect.width,v=this.truckSpeed*C*(O.top-O.bottom)/O.zoom/this._elementRect.height;S?this.setFocalOffset(this._focalOffsetEnd.x+E,this._focalOffsetEnd.y+v,this._focalOffsetEnd.z,!0):this.truck(E,v,!0)}},this._rotateInternal=(b,C)=>{const S=bi*this.azimuthRotateSpeed*b/this._elementRect.height,O=bi*this.polarRotateSpeed*C/this._elementRect.height;this.rotate(S,O,!0)},this._dollyInternal=(b,C,S)=>{const O=Math.pow(.95,-b*this.dollySpeed),E=this._sphericalEnd.radius*O,v=this._sphericalEnd.radius,T=v*(b>=0?-1:1);this.dollyTo(E),this.infinityDolly&&(E<this.minDistance||this.maxDistance===this.minDistance)&&(this._camera.getWorldDirection(X),this._targetEnd.add(X.normalize().multiplyScalar(T)),this._target.add(X.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(C,S))},this._zoomInternal=(b,C,S)=>{const O=Math.pow(.95,b*this.dollySpeed),E=this._zoomEnd;this.zoomTo(this._zoom*O),this.dollyToCursor&&(this._dollyControlAmount+=this._zoomEnd-E,this._dollyControlCoord.set(C,S))},typeof W>"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 W.Quaternion().setFromUnitVectors(this._camera.up,Ys),this._yAxisUpSpaceInverse=this._yAxisUpSpace.clone().invert(),this._state=R.NONE,this._target=new W.Vector3,this._targetEnd=this._target.clone(),this._focalOffset=new W.Vector3,this._focalOffsetEnd=this._focalOffset.clone(),this._spherical=new W.Spherical().setFromVector3(X.copy(this._camera.position).applyQuaternion(this._yAxisUpSpace)),this._sphericalEnd=this._spherical.clone(),this._zoom=this._camera.zoom,this._zoomEnd=this._zoom,this._nearPlaneCorners=[new W.Vector3,new W.Vector3,new W.Vector3,new W.Vector3],this._updateNearPlaneCorners(),this._boundary=new W.Box3(new W.Vector3(-1/0,-1/0,-1/0),new W.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 W.Vector2,this.mouseButtons={left:R.ROTATE,middle:R.DOLLY,right:R.TRUCK,wheel:ct(this._camera)?R.DOLLY:We(this._camera)?R.ZOOM:R.NONE},this.touches={one:R.TOUCH_ROTATE,two:ct(this._camera)?R.TOUCH_DOLLY_TRUCK:We(this._camera)?R.TOUCH_ZOOM_TRUCK:R.NONE,three:R.TOUCH_TRUCK};const s=new W.Vector2,n=new W.Vector2,r=new W.Vector2,a=b=>{if(!this._enabled||!this._domElement)return;const C=b.pointerType!=="mouse"?null:(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.MIDDLE?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.RIGHT?Y.RIGHT:null;if(C!==null){const O=this._findPointerByMouseButton(C);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const S={pointerId:b.pointerId,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:C};this._activePointers.push(S),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.addEventListener("pointermove",l),this._domElement.addEventListener("pointerup",d),g(b)},o=b=>{if(!this._enabled||!this._domElement)return;const C=(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.MIDDLE?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.RIGHT?Y.RIGHT:null;if(C!==null){const O=this._findPointerByMouseButton(C);O&&this._activePointers.splice(this._activePointers.indexOf(O),1)}const S={pointerId:0,clientX:b.clientX,clientY:b.clientY,deltaX:0,deltaY:0,mouseButton:(b.buttons&Y.LEFT)===Y.LEFT?Y.LEFT:(b.buttons&Y.MIDDLE)===Y.LEFT?Y.MIDDLE:(b.buttons&Y.RIGHT)===Y.LEFT?Y.RIGHT:null};this._activePointers.push(S),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u),this._domElement.addEventListener("mousemove",h),this._domElement.addEventListener("mouseup",u),g(b)},l=b=>{const C=b.pointerId,S=this._findPointerById(C);if(S){if(S.clientX=b.clientX,S.clientY=b.clientY,S.deltaX=b.movementX,S.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&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right);M()}},h=b=>{const C=this._findPointerById(0);C&&(C.clientX=b.clientX,C.clientY=b.clientY,C.deltaX=b.movementX,C.deltaY=b.movementY,this._state=0,(b.buttons&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right),M())},d=b=>{const C=b.pointerId,S=this._findPointerById(C);if(S&&this._activePointers.splice(this._activePointers.indexOf(S),1),b.pointerType==="touch")switch(this._activePointers.length){case 0:this._state=R.NONE;break;case 1:this._state=this.touches.one;break;case 2:this._state=this.touches.two;break;case 3:this._state=this.touches.three;break}else this._state=R.NONE;w()},u=()=>{const b=this._findPointerById(0);b&&this._activePointers.splice(this._activePointers.indexOf(b),1),this._state=R.NONE,w()};let f=-1;const m=b=>{if(!this._enabled||this.mouseButtons.wheel===R.NONE)return;if(this.dollyToCursor||this.mouseButtons.wheel===R.ROTATE||this.mouseButtons.wheel===R.TRUCK){const v=performance.now();f-v<1e3&&this._getClientRect(this._elementRect),f=v}const C=hu?-1:-3,S=b.deltaMode===1?b.deltaY/C:b.deltaY/(C*10),O=this.dollyToCursor?(b.clientX-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(b.clientY-this._elementRect.y)/this._elementRect.height*-2+1:0;switch(this.mouseButtons.wheel){case R.ROTATE:{this._rotateInternal(b.deltaX,b.deltaY),this._isUserControllingRotate=!0;break}case R.TRUCK:{this._truckInternal(b.deltaX,b.deltaY,!1),this._isUserControllingTruck=!0;break}case R.OFFSET:{this._truckInternal(b.deltaX,b.deltaY,!0),this._isUserControllingOffset=!0;break}case R.DOLLY:{this._dollyInternal(-S,O,E),this._isUserControllingDolly=!0;break}case R.ZOOM:{this._zoomInternal(-S,O,E),this._isUserControllingZoom=!0;break}}this.dispatchEvent({type:"control"})},x=b=>{if(!(!this._domElement||!this._enabled)&&this.mouseButtons.right===J.ACTION.NONE){const C=b instanceof PointerEvent?b.pointerId:(b instanceof MouseEvent,0),S=this._findPointerById(C);S&&this._activePointers.splice(this._activePointers.indexOf(S),1),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("mouseup",u);return}},g=b=>{if(!this._enabled)return;if(qn(this._activePointers,Ne),this._getClientRect(this._elementRect),s.copy(Ne),n.copy(Ne),this._activePointers.length>=2){const S=Ne.x-this._activePointers[1].clientX,O=Ne.y-this._activePointers[1].clientY,E=Math.sqrt(S*S+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 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&Y.LEFT)===Y.LEFT&&(this._state=this._state|this.mouseButtons.left),(b.buttons&Y.MIDDLE)===Y.MIDDLE&&(this._state=this._state|this.mouseButtons.middle),(b.buttons&Y.RIGHT)===Y.RIGHT&&(this._state=this._state|this.mouseButtons.right);((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._sphericalEnd.theta=this._spherical.theta,this._sphericalEnd.phi=this._spherical.phi,this._thetaVelocity.value=0,this._phiVelocity.value=0),((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._targetEnd.copy(this._target),this._targetVelocity.set(0,0,0)),((this._state&R.DOLLY)===R.DOLLY||(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE)&&(this._sphericalEnd.radius=this._spherical.radius,this._radiusVelocity.value=0),((this._state&R.ZOOM)===R.ZOOM||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._zoomEnd=this._zoom,this._zoomVelocity.value=0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._focalOffsetEnd.copy(this._focalOffset),this._focalOffsetVelocity.set(0,0,0)),this.dispatchEvent({type:"controlstart"})},M=()=>{if(!this._enabled)return;qn(this._activePointers,Ne);const b=De.isBrowser?this._domElement&&document.pointerLockElement===this._domElement:!1,C=b?-this._activePointers[0].deltaX:n.x-Ne.x,S=b?-this._activePointers[0].deltaY:n.y-Ne.y;if(n.copy(Ne),((this._state&R.ROTATE)===R.ROTATE||(this._state&R.TOUCH_ROTATE)===R.TOUCH_ROTATE||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE)&&(this._rotateInternal(C,S),this._isUserControllingRotate=!0),(this._state&R.DOLLY)===R.DOLLY||(this._state&R.ZOOM)===R.ZOOM){const O=this.dollyToCursor?(s.x-this._elementRect.x)/this._elementRect.width*2-1:0,E=this.dollyToCursor?(s.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.DOLLY)===R.DOLLY?(this._dollyInternal(S*Ws,O,E),this._isUserControllingDolly=!0):(this._zoomInternal(S*Ws,O,E),this._isUserControllingZoom=!0)}if((this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_ZOOM)===R.TOUCH_ZOOM||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_ZOOM_ROTATE)===R.TOUCH_ZOOM_ROTATE){const O=Ne.x-this._activePointers[1].clientX,E=Ne.y-this._activePointers[1].clientY,v=Math.sqrt(O*O+E*E),T=r.y-v;r.set(0,v);const P=this.dollyToCursor?(n.x-this._elementRect.x)/this._elementRect.width*2-1:0,_=this.dollyToCursor?(n.y-this._elementRect.y)/this._elementRect.height*-2+1:0;(this._state&R.TOUCH_DOLLY)===R.TOUCH_DOLLY||(this._state&R.TOUCH_DOLLY_ROTATE)===R.TOUCH_DOLLY_ROTATE||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET?(this._dollyInternal(T*Ws,P,_),this._isUserControllingDolly=!0):(this._zoomInternal(T*Ws,P,_),this._isUserControllingZoom=!0)}((this._state&R.TRUCK)===R.TRUCK||(this._state&R.TOUCH_TRUCK)===R.TOUCH_TRUCK||(this._state&R.TOUCH_DOLLY_TRUCK)===R.TOUCH_DOLLY_TRUCK||(this._state&R.TOUCH_ZOOM_TRUCK)===R.TOUCH_ZOOM_TRUCK)&&(this._truckInternal(C,S,!1),this._isUserControllingTruck=!0),((this._state&R.OFFSET)===R.OFFSET||(this._state&R.TOUCH_OFFSET)===R.TOUCH_OFFSET||(this._state&R.TOUCH_DOLLY_OFFSET)===R.TOUCH_DOLLY_OFFSET||(this._state&R.TOUCH_ZOOM_OFFSET)===R.TOUCH_ZOOM_OFFSET)&&(this._truckInternal(C,S,!0),this._isUserControllingOffset=!0),this.dispatchEvent({type:"control"})},w=()=>{qn(this._activePointers,Ne),n.copy(Ne),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=b=>{this._domElement=b,this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none",this._domElement.addEventListener("pointerdown",a),du&&this._domElement.addEventListener("mousedown",o),this._domElement.addEventListener("pointercancel",d),this._domElement.addEventListener("wheel",m,{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",d),this._domElement.removeEventListener("wheel",m),this._domElement.removeEventListener("contextmenu",x),this._domElement.removeEventListener("pointermove",l),this._domElement.removeEventListener("mousemove",h),this._domElement.removeEventListener("pointerup",d),this._domElement.removeEventListener("mouseup",u))},this.cancel=()=>{this._state!==R.NONE&&(this._state=R.NONE,this._activePointers.length=0,w())},i&&this.connect(i),this.update(0)}static install(e){W=e.THREE,Ha=Object.freeze(new W.Vector3(0,0,0)),Ys=Object.freeze(new W.Vector3(0,1,0)),Yn=Object.freeze(new W.Vector3(0,0,1)),Ne=new W.Vector2,X=new W.Vector3,ie=new W.Vector3,wi=new W.Vector3,mt=new W.Vector3,gt=new W.Vector3,Qt=new W.Vector3,Ga=new W.Vector3,qa=new W.Vector3,ot=new W.Spherical,Ji=new W.Spherical,vi=new W.Box3,Wa=new W.Box3,Xn=new W.Sphere,Ya=new W.Quaternion,Zn=new W.Quaternion,Kn=new W.Matrix4,Xs=new W.Raycaster}static get ACTION(){return R}get camera(){return this._camera}set camera(e){this._camera=e,this.updateCameraUp(),this._camera.updateProjectionMatrix(),this._updateNearPlaneCorners(),this._needsUpdate=!0}get enabled(){return this._enabled}set enabled(e){this._enabled=e,this._domElement&&(e?(this._domElement.style.touchAction="none",this._domElement.style.userSelect="none",this._domElement.style.webkitUserSelect="none"):(this.cancel(),this._domElement.style.touchAction="",this._domElement.style.userSelect="",this._domElement.style.webkitUserSelect=""))}get active(){return!this._hasRested}get currentAction(){return this._state}get distance(){return this._spherical.radius}set distance(e){this._spherical.radius===e&&this._sphericalEnd.radius===e||(this._spherical.radius=e,this._sphericalEnd.radius=e,this._needsUpdate=!0)}get azimuthAngle(){return this._spherical.theta}set azimuthAngle(e){this._spherical.theta===e&&this._sphericalEnd.theta===e||(this._spherical.theta=e,this._sphericalEnd.theta=e,this._needsUpdate=!0)}get polarAngle(){return this._spherical.phi}set polarAngle(e){this._spherical.phi===e&&this._sphericalEnd.phi===e||(this._spherical.phi=e,this._sphericalEnd.phi=e,this._needsUpdate=!0)}get boundaryEnclosesCamera(){return this._boundaryEnclosesCamera}set boundaryEnclosesCamera(e){this._boundaryEnclosesCamera=e,this._needsUpdate=!0}addEventListener(e,i){super.addEventListener(e,i)}removeEventListener(e,i){super.removeEventListener(e,i)}rotate(e,i,s=!1){return this.rotateTo(this._sphericalEnd.theta+e,this._sphericalEnd.phi+i,s)}rotateAzimuthTo(e,i=!1){return this.rotateTo(e,this._sphericalEnd.phi,i)}rotatePolarTo(e,i=!1){return this.rotateTo(this._sphericalEnd.theta,e,i)}rotateTo(e,i,s=!1){this._isUserControllingRotate=!1;const n=Ei(e,this.minAzimuthAngle,this.maxAzimuthAngle),r=Ei(i,this.minPolarAngle,this.maxPolarAngle);this._sphericalEnd.theta=n,this._sphericalEnd.phi=r,this._sphericalEnd.makeSafe(),this._needsUpdate=!0,s||(this._spherical.theta=this._sphericalEnd.theta,this._spherical.phi=this._sphericalEnd.phi);const a=!s||ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold);return this._createOnRestPromise(a)}dolly(e,i=!1){return this.dollyTo(this._sphericalEnd.radius-e,i)}dollyTo(e,i=!1){this._isUserControllingDolly=!1;const s=this._sphericalEnd.radius,n=Ei(e,this.minDistance,this.maxDistance);if(this.colliderMeshes.length>=1){const o=this._collisionTest(),l=ae(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||ae(this._spherical.radius,this._sphericalEnd.radius,this.restThreshold);return this._createOnRestPromise(a)}zoom(e,i=!1){return this.zoomTo(this._zoomEnd+e,i)}zoomTo(e,i=!1){this._isUserControllingZoom=!1,this._zoomEnd=Ei(e,this.minZoom,this.maxZoom),this._needsUpdate=!0,i||(this._zoom=this._zoomEnd);const s=!i||ae(this._zoom,this._zoomEnd,this.restThreshold);return this._createOnRestPromise(s)}truck(e,i,s=!1){this._camera.updateMatrix(),mt.setFromMatrixColumn(this._camera.matrix,0),gt.setFromMatrixColumn(this._camera.matrix,1),mt.multiplyScalar(e),gt.multiplyScalar(-i);const n=X.copy(mt).add(gt),r=ie.copy(this._targetEnd).add(n);return this.moveTo(r.x,r.y,r.z,s)}forward(e,i=!1){X.setFromMatrixColumn(this._camera.matrix,0),X.crossVectors(this._camera.up,X),X.multiplyScalar(e);const s=ie.copy(this._targetEnd).add(X);return this.moveTo(s.x,s.y,s.z,i)}elevate(e,i=!1){return X.copy(this._camera.up).multiplyScalar(e),this.moveTo(this._targetEnd.x+X.x,this._targetEnd.y+X.y,this._targetEnd.z+X.z,i)}moveTo(e,i,s,n=!1){this._isUserControllingTruck=!1;const r=X.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||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold);return this._createOnRestPromise(a)}lookInDirectionOf(e,i,s,n=!1){const o=X.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?vi.copy(e):vi.setFromObject(e);h.isEmpty()&&(console.warn("camera-controls: fitTo() cannot be used with an empty box. Aborting"),Promise.resolve());const d=ja(this._sphericalEnd.theta,Ua),u=ja(this._sphericalEnd.phi,Ua);l.push(this.rotateTo(d,u,i));const f=X.setFromSpherical(this._sphericalEnd).normalize(),m=Ya.setFromUnitVectors(f,Yn),x=ae(Math.abs(f.y),1);x&&m.multiply(Zn.setFromAxisAngle(Ys,d)),m.multiply(this._yAxisUpSpaceInverse);const g=Wa.makeEmpty();ie.copy(h.min).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setX(h.max.x).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setY(h.max.y).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setZ(h.min.z).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.min).setZ(h.max.z).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setY(h.min.y).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).setX(h.min.x).applyQuaternion(m),g.expandByPoint(ie),ie.copy(h.max).applyQuaternion(m),g.expandByPoint(ie),g.min.x-=n,g.min.y-=a,g.max.x+=r,g.max.y+=o,m.setFromUnitVectors(Yn,f),x&&m.premultiply(Zn.invert()),m.premultiply(this._yAxisUpSpace);const M=g.getSize(X),w=g.getCenter(ie).applyQuaternion(m);if(ct(this._camera)){const b=this.getDistanceToFitBox(M.x,M.y,M.z,s);l.push(this.moveTo(w.x,w.y,w.z,i)),l.push(this.dollyTo(b,i)),l.push(this.setFocalOffset(0,0,0,i))}else if(We(this._camera)){const b=this._camera,C=b.right-b.left,S=b.top-b.bottom,O=s?Math.max(C/M.x,S/M.y):Math.min(C/M.x,S/M.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 W.Sphere?Xn.copy(e):J.createBoundingSphere(e,Xn);if(s.push(this.moveTo(r.center.x,r.center.y,r.center.z,i)),ct(this._camera)){const a=this.getDistanceToFitSphere(r.radius);s.push(this.dollyTo(a,i))}else if(We(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=ie.set(n,r,a),h=X.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||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold)&&ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ae(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,x=!1){this._isUserControllingRotate=!1,this._isUserControllingDolly=!1,this._isUserControllingTruck=!1;const g=X.set(n,r,a),M=ie.set(e,i,s);ot.setFromVector3(M.sub(g).applyQuaternion(this._yAxisUpSpace));const w=wi.set(d,u,f),b=ie.set(o,l,h);Ji.setFromVector3(b.sub(w).applyQuaternion(this._yAxisUpSpace)),this._targetEnd.copy(g.lerp(w,m));const C=Ji.theta-ot.theta,S=Ji.phi-ot.phi,O=Ji.radius-ot.radius;this._sphericalEnd.set(ot.radius+O*m,ot.phi+S*m,ot.theta+C*m),this.normalizeRotations(),this._needsUpdate=!0,x||(this._target.copy(this._targetEnd),this._spherical.copy(this._sphericalEnd));const E=!x||ae(this._target.x,this._targetEnd.x,this.restThreshold)&&ae(this._target.y,this._targetEnd.y,this.restThreshold)&&ae(this._target.z,this._targetEnd.z,this.restThreshold)&&ae(this._spherical.theta,this._sphericalEnd.theta,this.restThreshold)&&ae(this._spherical.phi,this._sphericalEnd.phi,this.restThreshold)&&ae(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(X),a=this.setLookAt(r.x,r.y,r.z,e,i,s,n);return this._sphericalEnd.phi=Ei(this.polarAngle,this.minPolarAngle,this.maxPolarAngle),a}setFocalOffset(e,i,s,n=!1){this._isUserControllingOffset=!1,this._focalOffsetEnd.set(e,i,s),this._needsUpdate=!0,n||this._focalOffset.copy(this._focalOffsetEnd);const r=!n||ae(this._focalOffset.x,this._focalOffsetEnd.x,this.restThreshold)&&ae(this._focalOffset.y,this._focalOffsetEnd.y,this.restThreshold)&&ae(this._focalOffset.z,this._focalOffsetEnd.z,this.restThreshold);return this._createOnRestPromise(r)}setOrbitPoint(e,i,s){this._camera.updateMatrixWorld(),mt.setFromMatrixColumn(this._camera.matrixWorldInverse,0),gt.setFromMatrixColumn(this._camera.matrixWorldInverse,1),Qt.setFromMatrixColumn(this._camera.matrixWorldInverse,2);const n=X.set(e,i,s),r=n.distanceTo(this._camera.position),a=n.sub(this._camera.position);mt.multiplyScalar(a.x),gt.multiplyScalar(a.y),Qt.multiplyScalar(a.z),X.copy(mt).add(gt).add(Qt),X.z=X.z+r,this.dollyTo(r,!1),this.setFocalOffset(-X.x,X.y,-X.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 W.Vector4,typeof e=="number"?this._viewport.set(e,i,s,n):this._viewport.copy(e)}getDistanceToFitBox(e,i,s,n=!1){if(Wn(this._camera,"getDistanceToFitBox"))return this._spherical.radius;const r=e/i,a=this._camera.getEffectiveFOV()*Zi,o=this._camera.aspect;return((n?r>o:r<o)?i:e/o)*.5/Math.tan(a*.5)+s*.5}getDistanceToFitSphere(e){if(Wn(this._camera,"getDistanceToFitSphere"))return this._spherical.radius;const i=this._camera.getEffectiveFOV()*Zi,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 W.Vector3).copy(this._targetEnd)}getPosition(e){return(e&&e.isVector3?e:new W.Vector3).setFromSpherical(this._sphericalEnd).applyQuaternion(this._yAxisUpSpaceInverse).add(this._targetEnd)}getFocalOffset(e){return(e&&e.isVector3?e:new W.Vector3).copy(this._focalOffsetEnd)}normalizeRotations(){this._sphericalEnd.theta=this._sphericalEnd.theta%bi,this._sphericalEnd.theta<0&&(this._sphericalEnd.theta+=bi),this._spherical.theta+=bi*Math.round((this._sphericalEnd.theta-this._spherical.theta)/bi)}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,Ys),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=Ga.subVectors(this._targetEnd,this._target),a=qa.subVectors(this._focalOffsetEnd,this._focalOffset),o=this._zoomEnd-this._zoom;if(oe(i))this._thetaVelocity.value=0,this._spherical.theta=this._sphericalEnd.theta;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.theta=qs(this._spherical.theta,this._sphericalEnd.theta,this._thetaVelocity,u,1/0,e),this._needsUpdate=!0}if(oe(s))this._phiVelocity.value=0,this._spherical.phi=this._sphericalEnd.phi;else{const u=this._isUserControllingRotate?this.draggingSmoothTime:this.smoothTime;this._spherical.phi=qs(this._spherical.phi,this._sphericalEnd.phi,this._phiVelocity,u,1/0,e),this._needsUpdate=!0}if(oe(n))this._radiusVelocity.value=0,this._spherical.radius=this._sphericalEnd.radius;else{const u=this._isUserControllingDolly?this.draggingSmoothTime:this.smoothTime;this._spherical.radius=qs(this._spherical.radius,this._sphericalEnd.radius,this._radiusVelocity,u,this.maxSpeed,e),this._needsUpdate=!0}if(oe(r.x)&&oe(r.y)&&oe(r.z))this._targetVelocity.set(0,0,0),this._target.copy(this._targetEnd);else{const u=this._isUserControllingTruck?this.draggingSmoothTime:this.smoothTime;Na(this._target,this._targetEnd,this._targetVelocity,u,this.maxSpeed,e,this._target),this._needsUpdate=!0}if(oe(a.x)&&oe(a.y)&&oe(a.z))this._focalOffsetVelocity.set(0,0,0),this._focalOffset.copy(this._focalOffsetEnd);else{const u=this._isUserControllingOffset?this.draggingSmoothTime:this.smoothTime;Na(this._focalOffset,this._focalOffsetEnd,this._focalOffsetVelocity,u,this.maxSpeed,e,this._focalOffset),this._needsUpdate=!0}if(this._dollyControlAmount!==0){if(ct(this._camera)){const u=this._camera,f=X.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),m=ie.copy(f).cross(u.up).normalize();m.lengthSq()===0&&(m.x=1);const x=wi.crossVectors(m,f),g=this._sphericalEnd.radius*Math.tan(u.getEffectiveFOV()*Zi*.5),w=(this._sphericalEnd.radius-this._dollyControlAmount-this._sphericalEnd.radius)/this._sphericalEnd.radius,b=X.copy(this._targetEnd).add(m.multiplyScalar(this._dollyControlCoord.x*g*u.aspect)).add(x.multiplyScalar(this._dollyControlCoord.y*g));this._targetEnd.lerp(b,w)}else if(We(this._camera)){const u=this._camera,f=X.set(this._dollyControlCoord.x,this._dollyControlCoord.y,(u.near+u.far)/(u.near-u.far)).unproject(u),m=ie.set(0,0,-1).applyQuaternion(u.quaternion),x=wi.copy(f).add(m.multiplyScalar(-f.dot(u.up))),M=-(this._zoom-this._dollyControlAmount-this._zoomEnd)/this._zoom,w=X.setFromSpherical(this._spherical).applyQuaternion(this._yAxisUpSpaceInverse).normalize().negate(),b=this._targetEnd.dot(w);this._targetEnd.lerp(x,M);const C=this._targetEnd.dot(w),S=w.multiplyScalar(C-b);this._targetEnd.sub(S)}this._target.copy(this._targetEnd),this._boundary.clampPoint(this._targetEnd,this._targetEnd),this._dollyControlAmount=0}if(oe(o))this._zoomVelocity.value=0,this._zoom=this._zoomEnd;else{const u=this._isUserControllingZoom?this.draggingSmoothTime:this.smoothTime;this._zoom=qs(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),(!oe(this._focalOffset.x)||!oe(this._focalOffset.y)||!oe(this._focalOffset.z))&&(this._camera.updateMatrixWorld(),mt.setFromMatrixColumn(this._camera.matrix,0),gt.setFromMatrixColumn(this._camera.matrix,1),Qt.setFromMatrixColumn(this._camera.matrix,2),mt.multiplyScalar(this._focalOffset.x),gt.multiplyScalar(-this._focalOffset.y),Qt.multiplyScalar(this._focalOffset.z),X.copy(mt).add(gt).add(Qt),this._camera.position.add(X)),this._boundaryEnclosesCamera&&this._encloseToBoundary(this._camera.position.copy(this._target),X.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"}),oe(i,this.restThreshold)&&oe(s,this.restThreshold)&&oe(n,this.restThreshold)&&oe(r.x,this.restThreshold)&&oe(r.y,this.restThreshold)&&oe(r.z,this.restThreshold)&&oe(a.x,this.restThreshold)&&oe(a.y,this.restThreshold)&&oe(a.z,this.restThreshold)&&oe(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:Ki(this.maxDistance),minZoom:this.minZoom,maxZoom:Ki(this.maxZoom),minPolarAngle:this.minPolarAngle,maxPolarAngle:Ki(this.maxPolarAngle),minAzimuthAngle:Ki(this.minAzimuthAngle),maxAzimuthAngle:Ki(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:X.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=X.fromArray(s.position);this.enabled=s.enabled,this.minDistance=s.minDistance,this.maxDistance=$i(s.maxDistance),this.minZoom=s.minZoom,this.maxZoom=$i(s.maxZoom),this.minPolarAngle=s.minPolarAngle,this.maxPolarAngle=$i(s.maxPolarAngle),this.minAzimuthAngle=$i(s.minAzimuthAngle),this.maxAzimuthAngle=$i(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),ot.setFromVector3(n.sub(this._targetEnd).applyQuaternion(this._yAxisUpSpace)),this.rotateTo(ot.theta,ot.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=ie.copy(i).add(e),o=this._boundary.clampPoint(r,wi).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(ie.copy(i).multiplyScalar(h)).add(o.multiplyScalar(1-s))}}_updateNearPlaneCorners(){if(ct(this._camera)){const e=this._camera,i=e.near,s=e.getEffectiveFOV()*Zi,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(We(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)||Wn(this._camera,"_collisionTest"))return e;const s=X.setFromSpherical(this._spherical).divideScalar(this._spherical.radius);Kn.lookAt(Ha,s,this._camera.up);for(let n=0;n<4;n++){const r=ie.copy(this._nearPlaneCorners[n]);r.applyMatrix4(Kn);const a=wi.addVectors(this._target,r);Xs.set(a,s),Xs.far=this._spherical.radius+1;const o=Xs.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 W.Sphere){const s=i,n=s.center;vi.makeEmpty(),e.traverseVisible(a=>{a.isMesh&&vi.expandByObject(a)}),vi.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++)X.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(X))}else{const d=l.attributes.position;for(let u=0,f=d.count;u<f;u++)X.fromBufferAttribute(d,u),r=Math.max(r,n.distanceToSquared(X))}}),s.radius=Math.sqrt(r),s}}var dt=(c=>(c[c.Orbit=0]="Orbit",c[c.FirstPerson=1]="FirstPerson",c[c.Plan=2]="Plan",c))(dt||{});class Zo{constructor(t){y(this,"mode");y(this,"cameraManager");this.mode=dt.Orbit,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:J.ACTION.ROTATE,middle:J.ACTION.DOLLY,right:J.ACTION.TRUCK,wheel:ct(t)?J.ACTION.DOLLY:We(t)?J.ACTION.ZOOM:J.ACTION.NONE},e.touches={one:J.ACTION.TOUCH_ROTATE,two:ct(t)?J.ACTION.TOUCH_DOLLY_TRUCK:We(t)?J.ACTION.TOUCH_ZOOM_TRUCK:J.ACTION.NONE,three:J.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){y(this,"mode");y(this,"cameraManager");this.mode=dt.Plan,this.cameraManager=t}setupControl(){const t=this.cameraManager.camera,e=this.cameraManager.cameraControls;e.mouseButtons={left:J.ACTION.TRUCK,middle:J.ACTION.TRUCK,right:J.ACTION.TRUCK,wheel:ct(t)?J.ACTION.DOLLY:We(t)?J.ACTION.ZOOM:J.ACTION.NONE},e.touches={one:J.ACTION.TOUCH_TRUCK,two:ct(t)?J.ACTION.TOUCH_DOLLY_TRUCK:We(t)?J.ACTION.TOUCH_ZOOM_TRUCK:J.ACTION.NONE,three:J.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,$n=new p.Vector3;class uu{constructor(t){y(this,"viewer");y(this,"perspectiveCamera");y(this,"orthographicCamera");y(this,"activeCamera");y(this,"cameraControls");y(this,"previousDistance");y(this,"previousAzimuthRotateSpeed");y(this,"previousPolarRotateSpeed");y(this,"previousDollySpeed");y(this,"previousTruckSpeed");y(this,"previousMouseLeft");y(this,"enableKeyDown");y(this,"controlsMap");y(this,"activeControls");y(this,"projection");y(this,"anchor");y(this,"onKeyDown");y(this,"onChange");this.previousDistance=-1,this.previousAzimuthRotateSpeed=1,this.previousPolarRotateSpeed=1,this.previousDollySpeed=1,this.previousTruckSpeed=2,this.previousMouseLeft=J.ACTION.NONE,this.enableKeyDown=!0,this.projection=wt.Perspective,this.onKeyDown=s=>{if(!this.enableKeyDown)return;const n=this.cameraControls,r=this.viewer.getPixelSizeInWorldCoord()*10,a=this.viewer.name===et.Viewer3d||this.viewer.name===et.BimTilesViewer;switch(s.code){case"ArrowLeft":a?n.rotate(.1,0,!0):this.viewer.name===et.Viewer2d&&n.truck(r,0,!0);break;case"ArrowRight":a?n.rotate(-.1,0,!0):this.viewer.name===et.Viewer2d&&n.truck(-r,0,!0);break;case"ArrowUp":a?n.rotate(0,.1,!0):this.viewer.name===et.Viewer2d&&n.truck(0,r,!0);break;case"ArrowDown":a?n.rotate(0,-.1,!0):this.viewer.name===et.Viewer2d&&n.truck(0,-r,!0);break;case"KeyW":a&&(We(this.activeCamera)?n.zoom(.01,!0):n.dolly(1,!0));break;case"KeyA":a&&n.truck(-r,0,!0);break;case"KeyS":a&&(We(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(bo,i,nn,rn),this.orthographicCamera=new p.OrthographicCamera(Mi*i/-2,Mi*i/2,Mi/2,Mi/-2,nn,rn),this.activeCamera=this.perspectiveCamera,this.setupCameras(),J.install({THREE:p}),this.cameraControls=new J(this.perspectiveCamera,t.getInputManager()),this.controlsMap={[dt.Orbit]:new Zo(this),[dt.Plan]:new Ko(this)},this.activeControls=this.controlsMap[dt.Orbit],this.setupControls(),this.setProjection(wt.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=_e.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(ce.ControlChange)),t.addEventListener("rest",()=>this.onChange),this.inputManager.addEventListener("keydown",this.onKeyDown)}setOrthoCamera(){if(this.activeControls.mode===dt.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=wt.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=J.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=J.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=J.ACTION.DOLLY,this.activeCamera=e,this.projection=wt.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($n)}getPosition(){return this.cameraControls.getPosition($n)}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=>N.numberToString(h);A.info("[Viewer] BBox's longest side is: "+l(n)),e>a&&(A.warn("[Viewer] camera.near("+l(e)+") shouldn't bigger than "+l(a)+", will change it!"),this.camera.near=a),i<o&&(A.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=J.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===wt.Orthographic?this.setOrthoCamera():this.setPerspectiveCamera())}setOrbitPoint(t){this.cameraControls.setOrbitPoint(t.x,t.y,t.z)}getCameraDirection(){return this.activeCamera.getWorldDirection($n)}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=nn,far:s=rn,up:n=new p.Vector3(0,1,0),zoom:r=1,eye:a,look:o}=t;this.activeCamera.near=i,this.activeCamera.far=s,this.activeCamera.up.set(n.x,n.y,n.z),this.activeCamera.updateProjectionMatrix(),e.updateCameraUp(),e.zoomTo(r),e.setLookAt(a.x,a.y,a.z,o.x,o.y,o.z,!0),e.setFocalOffset(0,0,0,!0)}destroy(){this.anchor.remove(),this.inputManager.removeEventListener("keydown",this.onKeyDown),this.perspectiveCamera.removeFromParent(),this.orthographicCamera.removeFromParent()}}const ai=class ai extends Vo{tableName(){return"fonts"}static instance(){return!ai._instance&&(ai._instance=new ai),ai._instance}query(t){let e;return new Promise((i,s)=>{super.query(n=>{if(!n){i(e);return}!n.value||n.value.fileName!==t||(e=n.value)},n=>{s(n)})})}queryAll(){const t=Object.create(null,{queryAll:{get:()=>super.queryAll}});return new Promise((e,i)=>{t.queryAll.call(this,s=>{e(s)},s=>{i(s)})})}};y(ai,"_instance");let Ri=ai;var $o=(c=>(c[c.Horizontal=0]="Horizontal",c[c.Vertical=1]="Vertical",c[c.All=2]="All",c))($o||{}),Ye=(c=>(c[c.Shapes=0]="Shapes",c[c.Bigfont=1]="Bigfont",c[c.Unifont=2]="Unifont",c))(Ye||{});class Jo extends Fl.Font{constructor(e,i){super(i);y(this,"info");y(this,"orientation");y(this,"baseUp");y(this,"baseDown");y(this,"fileHeader");y(this,"fileVersion");y(this,"fileName");y(this,"data");y(this,"order");y(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)=>{Ri.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 Ri.instance().query(this.fileName)}releaseFontData(){this.data={}}}class ei extends Jo{constructor(e,i){super(e,i);y(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=Xa(e,i,0,0,this.data)?.path;return!s&&this.addUnsupportedChar(e),s}getNotFoundTextShape(e){return Xa("?",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 x={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(g){g.type.toLowerCase()==="c"&&(g.type="b"),x.o+=g.type.toLowerCase()+" ",g.x!==void 0&&g.y!==void 0&&(x.o+=a(g.x*l)+" "+a(g.y*l)+" "),g.x1!==void 0&&g.y1!==void 0&&(x.o+=a(g.x1*l)+" "+a(g.y1*l)+" "),g.x2!==void 0&&g.y2!==void 0&&(x.o+=a(g.x2*l)+" "+a(g.y2*l)+" ")}),o[String.fromCodePoint(m.unicode)]=x}}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(Rl.parse(e),this.reversed)}}function Xa(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 x=n._cachedOutline||(n._cachedOutline=n.o.split(" "));for(let g=0,M=x.length;g<M;)switch(x[g++]){case"m":a=x[g++]*t+e,o=x[g++]*t+i,r.moveTo(a,o);break;case"l":a=x[g++]*t+e,o=x[g++]*t+i,r.lineTo(a,o);break;case"q":l=x[g++]*t+e,h=x[g++]*t+i,d=x[g++]*t+e,u=x[g++]*t+i,r.quadraticCurveTo(d,u,l,h);break;case"b":l=x[g++]*t+e,h=x[g++]*t+i,d=x[g++]*t+e,u=x[g++]*t+i,f=x[g++]*t+e,m=x[g++]*t+i,r.bezierCurveTo(d,u,f,m,l,h);break}}return{offsetX:n.ha*t,path:r}}class ee{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(ee.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 fn;function fu(){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(fn=new Uint16Array(65536),e=0;e<i.length;e++)fn[i.charCodeAt(e)]=t[e]}function pu(c){!fn&&fu();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=fn[s];t[e++]=n&255,t[e++]=n>>8}}return t.subarray(0,e)}new p.Vector2;class fs extends p.Shape{constructor(e,i){super();y(this,"width");y(this,"lastPoint");y(this,"polylines");y(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 fs(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 fs(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 xt=class xt{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=pu(t);return e.length<2?e[0]:e.length<4?ee.ToUInt16(e,0):ee.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 Ye.Shapes:l++,d=e[l];break;case Ye.Bigfont:l++,d=e[l],d==0&&(l++,d=ee.ToUInt16(new Uint8Array([e[l++],e[l++]]),0),m.x=e[l++]*i,m.y=e[l++]*i,f=e[l]*i);break;case Ye.Unifont:l+=2,d=ee.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=ee.byteTosbyte(e[++l]),d.y=ee.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=ee.byteTosbyte(e[++l]),u.y=ee.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=ee.byteTosbyte(e[++l]),f=(u&112)>>4;let m=u&7;m==0&&(m=8);const x=Math.PI/4;let g=x*m,M=xt.CIRCLE_SPAN;u<0&&(M=-M,g=-g);const w=x*f,b=w+g,C=s.clone().sub(new p.Vector2(Math.cos(w)*d,Math.sin(w)*d));if(s=C.clone().add(new p.Vector2(Math.cos(b)*d,Math.sin(b)*d)),o){let S=w;const O=!0;for(;O&&(S+=M,!!Number.isFinite(S));)if(u>=0&&S<b||u<0&&S>b)r.push(C.clone().add(new p.Vector2(d*Math.cos(S),d*Math.sin(S))));else break;r.push(s.clone())}}break;case 11:{const d=e[++l],u=e[++l],f=e[++l],m=e[++l],x=(f*255+m)*i,g=ee.byteTosbyte(e[++l]),M=(g&112)>>4;let w=g&7;w==0&&(w=8),u!=0&&w--;const b=Math.PI/4;let C=b*w,S=xt.CIRCLE_SPAN,O=1;g<0&&(S=-S,C=-C,O=-1);let E=b*M,v=E+C;E+=b*d/256*O,v+=b*u/256*O;const T=s.clone().sub(new p.Vector2(x*Math.cos(E),x*Math.sin(E)));if(s=T.clone().add(new p.Vector2(x*Math.cos(v),x*Math.sin(v))),o){let P=E;const _=!0;for(;_&&(P+=S,!!Number.isFinite(P));)if(g>0&&P<v||g<0&&P>v)r.push(T.clone().add(new p.Vector2(x*Math.cos(P),x*Math.sin(P))));else break;r.push(s.clone())}}break;case 12:{const d=new p.Vector2;d.x=ee.byteTosbyte(e[++l])*i,d.y=ee.byteTosbyte(e[++l])*i;let u=ee.byteTosbyte(e[++l]);u<-127&&(u=-127),o&&(u==0?r.push(s.clone().add(d)):r.push(xt.generateArcPoints(s,d,u/127))),s.add(d)}break;case 13:for(;;){const u=new p.Vector2;if(u.x=ee.byteTosbyte(e[++l])*i,u.y=ee.byteTosbyte(e[++l])*i,!Number.isFinite(u.x)||!Number.isFinite(u.y)||u.x==0&&u.y==0)break;let f=ee.byteTosbyte(e[++l]);f<-127&&(f=-127),o&&(f==0?r.push(s.clone().add(u)):r.push(xt.generateArcPoints(s.clone(),u,f/127))),s.add(u)}break;case 14:l=xt.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 fs(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 Ye.Shapes:i++;break;case Ye.Bigfont:i++,e[i]==0&&(i+=6);break;case Ye.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 x=Math.atan2(f.y,f.x);const g=Math.atan2(m.y,m.x);let M=xt.CIRCLE_SPAN;n?(M=-M,x<g&&(x+=2*Math.PI)):x>g&&(x-=2*Math.PI);let w=x;const b=!0;for(;b;){if(w+=M,!n&&w<g||n&&w>g)return u.add(new p.Vector2(d*Math.cos(w),d*Math.sin(w)));break}return s}};y(xt,"FILE_STOP_FLAG",["\r",`
|
|
1532
|
+
`,""]),y(xt,"CIRCLE_SPAN",Math.PI/18);let Rt=xt;const Jn={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]]]},Za=new p.Matrix3,ls=class ls extends Jo{constructor(e,i){super(e,i);y(this,"isExtend");y(this,"isUniCode");y(this,"isEmbedded");y(this,"fontType");y(this,"textShapesCache");y(this,"graphicData");if(this.isExtend=!1,this.isUniCode=!0,this.isEmbedded=!1,this.fontType=Ye.Unifont,this.textShapesCache=new Map,this.graphicData=new Map,i instanceof ArrayBuffer){const s=new ys(i),n=Rt.parserHeader(s,Rt.FILE_STOP_FLAG),r=n.split(" ");switch(r[1]){case"shapes":this.parseShapeFont(s),this.fontType=Ye.Shapes;break;case"bigfont":this.parseBigFont(s),this.fontType=Ye.Bigfont;break;case"unifont":this.parseUniFont(s),this.fontType=Ye.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=Rt.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=ls.DEFAULT_SIZE/this.baseUp;r=Rt.parserCode(this,a,o),this.graphicData.set(e,r)}else if(Jn[e]){const a=[];for(let o=0;o<Jn[e].length;o++)a.push(Jn[e][o].map(l=>new p.Vector2(l[0],l[1])));r=new fs(new p.Vector2,a),this.graphicData.set(e,r)}}if(this.graphicData.has(e)){const a=i/ls.DEFAULT_SIZE;Za.identity().scale(a,a),r=this.graphicData.get(e).transform(Za)}return r}getGraphicDataByCodeWithOffset(e,i,s){return this.getGraphicDataByCode(e,i)?.offset(s)}parseBigFont(e){ee.ToInt16(e.readBytes(2),0);const i=ee.ToInt16(e.readBytes(2),0),s=ee.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=ee.ToUInt16(new Uint8Array([h[1],h[0]]),0),u=ee.ToUInt16(h,2),f=ee.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=mu(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=ee.ToInt32(e.readBytes(4),0),s=ee.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=ee.ToUInt16(e.readBytes(2),0),h=ee.ToUInt16(e.readBytes(2),0);a[l]=e.readBytes(h)}this.data=a}parseShapeFont(e){e.readBytes(2),e.readBytes(2);const i=ee.ToInt16(e.readBytes(2),0),s=[];for(let o=0;o<i;o++){const l=ee.ToUInt16(e.readBytes(2),0),h=ee.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===Ye.Bigfont&&(i=Rt.getCode("?")),this.fontType===Ye.Unifont&&(i=Rt.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||Ye.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()}};y(ls,"DEFAULT_SIZE",12);let yt=ls;function mu(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 bt{constructor(){y(this,"loader");y(this,"fontMap");y(this,"fileNames");y(this,"unsupportedChars");y(this,"missingFonts");y(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]:bt.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=bt.getFileName(i.toLowerCase());let a;if(n.length){const o=n[0];if(o.lastIndexOf(".json")>-1){this.loader.setResponseType("json");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}else if(o.lastIndexOf(".shx")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new yt(s,l)}else if(o.lastIndexOf(".ttf")>-1){this.loader.setResponseType("arraybuffer");const l=await this.loader.loadAsync(r[0]);a=new ei(s,l)}}else if(bt.isJsonFile(i)){this.loader.setResponseType("json");const o=await this.loader.loadAsync(i);a=new ei(s,o)}else if(bt.isShxFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new yt(s,o)}else if(bt.isTtfFile(i)){this.loader.setResponseType("arraybuffer");const o=await this.loader.loadAsync(i);a=new ei(s,o)}a&&(a.order=e+1,this.fontMap.set(s,a))}this.enableFontCache&&De.isBrowser&&(this.fontMap.forEach(async e=>{await e.setFontDataToIndexedDb()}),this.releaseFontData())}}getTextShape(t,e,i){if(this.fontMap.size===0){A.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){A.warn("[FontManager] no font loaded.");return}e==null&&(e="");const s=t.charCodeAt(0)>255,n=o=>{const l=o.getCharShape(t,i);if(l&&!(s&&o instanceof yt&&l.width<i*.5))return l};let r=this.fontMap.get(e.toLowerCase());if(!r){!this.missingFonts[e]&&(this.missingFonts[e]=0),this.missingFonts[e]++;for(const[,o]of this.fontMap)if(n(o)){r=o;break}}let a=r?.getCharShape(t,i);if(a&&s&&r instanceof yt&&a.width<i*.5&&(a=void 0),!a)for(const[,o]of this.fontMap){if(o===r)continue;const l=n(o);if(l){r=o,a=l;break}}if(a){if(r instanceof yt)return a.toThreeGeometry();if(r instanceof ei){const o=new Ll.TextGeometry(t,{font:r,depth:0,size:i||12,curveSegments:3,bevelSegments:3});o.computeBoundingBox();const l=o.boundingBox,h=l.min.x;return Number.isFinite(h)&&Math.abs(h)>1e-6&&o.translate(-h,0,0),o.userData.advanceWidth=Math.max(l.max.x-l.min.x,0),o}}}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 yt)return e.toThreeGeometry();if(i instanceof ei)return new p.ExtrudeGeometry(e.toShapes(!1),{curveSegments:3,bevelSegments:3})}async checkAllFontsLoaded(t){if(!De.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=bt.getFileName(s.toLowerCase());const r=await Ri.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 Ri.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 yt(s,i):r=new ei(s,i),this.fontMap.set(s,r)}A.debug("[FontManager] Loaded font data from cache.")}isShxFont(t){if(this.fontMap.size===0){A.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 yt}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 N.getExtension(t)==="shx"}static isTtfFile(t){return["WOFF","OTF","TTF"].includes(N.getExtension(t).toUpperCase())}static isJsonFile(t){return N.getExtension(t)==="json"}static getFileName(t){const e=t.lastIndexOf("/");return t.substring(e+1)}}class gu{constructor(t){y(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)&&ve.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)&&ve.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=st,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 G.geometriesEqual(t,e)}}class Qo{constructor(){y(this,"TIMEOUT","timeout");y(this,"INTERVAL","interval");y(this,"timeoutMap",{});y(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 pn{constructor(t){y(this,"buffer");y(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 pn(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 es=(c=>(c[c.NULL=0]="NULL",c[c.POINT=1]="POINT",c[c.POLYLINE=3]="POLYLINE",c[c.POLYGON=5]="POLYGON",c))(es||{});class yu{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 xu{constructor(){y(this,"LINE_MATERIAL");y(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===es.POLYLINE||n.type===es.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===es.POLYGON){const x=p.ShapeUtils.triangulateShape(m,[]),g=[];x.forEach(b=>g.push(...b));const M=new p.BufferGeometry;M.setFromPoints(m),M.setIndex(g),e.push(M);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 x=new p.BufferGeometry;x.setFromPoints(m),i.push(x)}}}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===es.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 pn(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 pn(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 bu{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 yu,a=r.parse(n.response),o=new xu().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 cs=class cs{constructor(t){y(this,"gltfLoader");y(this,"font");y(this,"manager");y(this,"currentDxfLoader");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")?(A.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"))A.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 Ul.FBXLoader(this.manager),s=await i.loadAsync(t,e);return Promise.resolve(s)}async loadObj(t,e){const i=new Hl.OBJLoader(this.manager),s=new Nl.MTLLoader(this.manager),n=t.replace(".obj",".mtl"),r=await s.loadAsync(n,e);r.preload(),i.setMaterials(r);const a=await i.loadAsync(t,e);return Promise.resolve(a)}async loadStl(t,e){const i=new ql.STLLoader(this.manager),s=await i.loadAsync(t,e),n=new p.MeshStandardMaterial({color:11184810,metalness:.1,roughness:.8}),r=new p.Mesh(s,n);return Promise.resolve(r)}async loadShp(t,e){const i=new bu;return new Promise((s,n)=>{i.load(t,r=>{s(r)},e,r=>{n(r)})})}async loadDae(t,e){const i=new zl.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 Z(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 Gl.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 Z(this.manager,n);return this.currentDxfLoader=r,r.setFont(this.font),await this.font?.getFontFromIndexeddb(),r.manager.onLoad=()=>{s&&s()},r.loadEx(t,e,i)}abortDxfLoading(){this.currentDxfLoader?.abort(),this.currentDxfLoader=void 0}setFont(t){this.font=t}static setDracoDecoderPath(t){this.DecoderPath=t}static setRhino3dmLibraryPath(t){this.Rhino3dmLibraryPath=t}getGltfLoader(){if(!this.gltfLoader){this.gltfLoader=new jl.GLTFLoader(this.manager);const t=new Vl.DRACOLoader(this.manager);t.setDecoderPath(cs.DecoderPath),this.gltfLoader.setDRACOLoader(t)}return this.gltfLoader}};y(cs,"DecoderPath","libs/draco/gltf/"),y(cs,"Rhino3dmLibraryPath","https://unpkg.com/rhino3dm@8.0.0-beta2/");let Ut=cs;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
|
+
`,Ka=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",el],{type:"text/javascript;charset=utf-8"});function wu(c){let t;try{if(t=Ka&&(self.URL||self.webkitURL).createObjectURL(Ka),!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(){y(this,"running");y(this,"worker");this.running=!1,this.worker=new wu,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){A.warn("[GenerateMeshBVHWorker] Already running job.");return}if(!this.worker){A.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=>{A.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)A.warn(h.error),o();else if(h.serialized){const{serialized:d,position:u,id:f}=h,m=s.get(f),x=hs.deserialize(d,m,{setIndex:!1}),g=Object.assign({setBoundingBox:!0},e);if(g.transferred&&(m.attributes.position.array=u),m.index)e.saveOriginalIndex&&!m.userData.originalIndex&&(m.userData.originalIndex=m.index.array),A.debug("before update, index:",m.index.array),m.index.array=d.index;else{const M=new L.BufferAttribute(d.index,1,!1);m.setIndex(M)}m.index&&(A.debug("after update, index:",m.index.array),m.index.needsUpdate=!0),g.setBoundingBox&&!m.boundingBox&&(m.boundingBox=x.getBoundingBox(new L.Box3)),m.boundsTree=x,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){A.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(x=>x.buffer):[])}})}dispose(){this.worker.terminate(),this.worker=void 0}}class Lr{constructor(t){y(this,"running");y(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){A.warn("[BVHHelper] Already running job.");return}if(this.workers.length===0){A.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;A.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&&me.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 hs(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&&me.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 Lr;return n.generate(s,e).then(()=>{n.dispose()})}}class vu{constructor(t,e,i,s,n){y(this,"object");y(this,"camera");y(this,"targetPixelHeight",100);y(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=Mu(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 Mu=(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},Zs=new p.Vector2,Ks=new p.Vector2,$s=new p.Vector2,$a=new p.Vector2,Tu=new p.Vector2,Cu=new p.Vector2,we=class we extends Ht{constructor(e){super(N.guid());y(this,"needsFrustumCulled");y(this,"renderOrder");y(this,"snapType");y(this,"osnapInfo");y(this,"drawSnapFunctions");y(this,"snapLineVisible");this.needsFrustumCulled=!1,this.renderOrder=1e3,this.snapType=Ot.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=we.FILL_COLOR_NONE,e.strokeStyle=we.lineColor,e.lineWidth=we.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=we.SNAP_LINE_COLOR,e.lineWidth=we.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=we.iconSize/1.6,r=Zs.set(s.x,s.y-n),a=Ks.set(s.x-.87*n,s.y+n/1.4),o=$s.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=we.iconSize,r=we.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=we.iconSize/1.6,r=Zs.set(s.x,s.y-n),a=Ks.set(s.x-.87*n,s.y+n/2),o=$s.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=we.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=we.iconSize/2,r=Zs.set(s.x-n,s.y-n),a=Ks.set(s.x+n,s.y+n),o=$s.set(s.x+n,s.y-n),l=$a.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=we.iconSize/2,r=Zs.set(s.x,s.y),a=Ks.set(s.x-n,s.y),o=$s.set(s.x,s.y+n),l=$a.set(s.x-n,s.y-n),h=Tu.set(s.x-n,s.y+n),d=Cu.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"}};y(we,"lineColor","rgba(255, 119, 0, 1)"),y(we,"FILL_COLOR_NONE","rgba(0, 0, 0, 0)"),y(we,"SNAP_LINE_COLOR","rgba(255, 240, 0, 0.3)"),y(we,"lineWidth",2),y(we,"iconSize",14);let Ae=we;ms._registerDrawableClass(Ae);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 Su=1e-5,le=new p.Vector3,Pe=new p.Vector3,ki=new p.Vector3,rs=new p.Vector3,ti=new p.Matrix4,as=new p.Line3;function Eu(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 Ou(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=me.getBatchByFaceIndex(t,c.faceIndex);t.geometry.boundsTree&&(i=new p.BufferAttribute(t.geometry.userData.originalIndex,1,!1)),ti.identity(),t instanceof p.InstancedMesh&&c.instanceId!==void 0&&t.getMatrixAt(c.instanceId,ti),ti.premultiply(t.matrixWorld);const n=t.geometry.drawRange;let r,a=e.array;if(i){let f=Math.max(0,n.start),m=Math.min(i.count,n.start+n.count);if(r=i.array,s){f=Math.max(f,s.indexStart),m=Math.min(m,s.indexStart+s.indexCount),r=i.array.slice(f,m),a=e.array.slice(s.positionStart*3,(s.positionStart+s.positionCount)*3);for(let x=0;x<r.length;x++)r[x]=r[x]-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 x=a.length/3;r=x>65535?new Uint32Array(x):new Uint16Array(x);for(let g=0,M=x;g<M;g++)r[g]=g}const o=wo.buildEdge(a,r,20);let l=Number.MAX_VALUE,h=0;for(let f=0;f<o.length;f+=2){const m=o[f],x=o[f+1];le.set(a[m*3],a[m*3+1],a[m*3+2]),le.applyMatrix4(ti),Pe.set(a[x*3],a[x*3+1],a[x*3+2]),Pe.applyMatrix4(ti),as.set(le,Pe),as.closestPointToPoint(c.point,!0,ki);const g=c.point.distanceTo(ki);g<l&&(h=f,l=g,rs.copy(ki))}const d=o[h],u=o[h+1];return le.set(a[d*3],a[d*3+1],a[d*3+2]),le.applyMatrix4(ti),Pe.set(a[u*3],a[u*3+1],a[u*3+2]),Pe.applyMatrix4(ti),{vertices:[le.clone(),Pe.clone()],vertex:rs.clone(),distance:l}}class Pu{constructor(t){y(this,"drawableList",new gs("snap"));y(this,"overlayRender");y(this,"markers",{});y(this,"activeOSnapType",0);y(this,"snapToleranceInWorldCoord",1);y(this,"intersectionLimit",10);y(this,"osnapTypePriorities",{1:0,2:1,64:2,32:3,16:4,4:5,8:6,0:100});y(this,"enabledOSnapTypes",127);this.overlayRender=t,this.overlayRender?.addDrawableList(this.drawableList),this.initOSnapMarkers()}initOSnapMarkers(){const t=new Ae(Ot.TripleCross),e=new Ae(Ot.Square),i=new Ae(Ot.Triangle),s=new Ae(Ot.CircleWithCross),n=new Ae(Ot.Cross),r=new Ae(Ot.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 Di.colorStr2Rgba(Ae.lineColor)}setMarkerLineColor(t){Ae.lineColor=Di.rgba2Color(t)}getMarkerLineWidth(){return Ae.lineWidth}setMarkerLineWidth(t){Ae.lineWidth=t}getMarkerIconSize(){return Ae.iconSize}setMarkerIconSize(t){Ae.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}A.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||(A.warn("[OSnap] Potential to produce erroneous snap results"),r=s[0].point),A.debug("[OSnap] intersections:",s),A.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=Su){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;A.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=Ou(e);if(!r){A.warn("[OSnap] Failed to get edge !");return}const a=Date.now();A.debug("[OSnap] getEdgeSnappingInfo took "+(a-n)/1e3+"s "),A.debug("[OSnap] edge:",r);const o=Eu(r,t);if(A.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;le.copy(r.vertices[0]),le.add(r.vertices[1]),le.divideScalar(2);const l=le.distanceTo(t);return l<=i&&this.isOSnapTypeEnabled(2)?{distance:l,type:2,point:le.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 A.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:V.floorNumber(m,7),type:16,point:f.clone()}}if(r<this.osnapTypePriorities[1])return;as.set(e,i),as.closestPointToPoint(t,!0,ki);const l=t.distanceTo(ki);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:V.floorNumber(f,7),type:1,point:m.clone()}}if(r<this.osnapTypePriorities[2])return;as.getCenter(rs);const u=t.distanceTo(rs);if(u<s&&this.isOSnapTypeEnabled(2))return{point:rs.clone(),distance:V.floorNumber(u,7),type:2};if(!(r<this.osnapTypePriorities[4])){if(n.line&&this.isOSnapTypeEnabled(32)){const f=G.getLineSegmentsIntersectingPoint(n.line,o);if(!f)return;const m=t.distanceTo(f)/2;return m<s?(n.line=void 0,{point:f.clone(),distance:V.floorNumber(m,7),type:32}):void 0}if(this.isOSnapTypeEnabled(4))return n.line={start:e.clone(),end:i.clone()},{point:ki.clone(),distance:V.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=me.getBatchByLineIndex(l,e.index);if(d){let x=Math.max(0,f.start),g=Math.min(d.count,f.start+f.count);m&&(x=Math.max(x,m.indexStart),g=Math.min(g,m.indexStart+m.indexCount));for(let M=x,w=g;M<w-1;M+=h){const b=d.getX(M),C=d.getX(M+1);le.fromBufferAttribute(u,b),Pe.fromBufferAttribute(u,C),le.applyMatrix4(l.matrixWorld),Pe.applyMatrix4(l.matrixWorld),!i&&(le.setZ(0),Pe.setZ(0));const S=this.getOsnapInfoFromSegment(t,le,Pe,s,n,r,a);S&&(r=this.osnapTypePriorities[S.type],o.push(S))}}else{let x=Math.max(0,f.start),g=Math.min(u.count,f.start+f.count);m&&(x=Math.max(x,m.positionStart),g=Math.min(g,m.positionStart+m.positionCount));for(let M=x,w=g;M<w-1;M+=h){le.fromBufferAttribute(u,M),Pe.fromBufferAttribute(u,M+1),le.applyMatrix4(l.matrixWorld),Pe.applyMatrix4(l.matrixWorld),!i&&(le.setZ(0),Pe.setZ(0));const b=this.getOsnapInfoFromSegment(t,le,Pe,s,n,r,a);b&&(r=this.osnapTypePriorities[b.type],o.push(b))}}if(o.length!==0)return o.sort((x,g)=>{const M=this.osnapTypePriorities[x.type],w=this.osnapTypePriorities[g.type];return M!==w?M-w:x.distance-g.distance}),o[0]}getOsnapInfoListFromPoint(t,e,i,s,n){if(n<this.osnapTypePriorities[1])return;const r=e.object,a=r.geometry.getAttribute("position");le.fromBufferAttribute(a,e.index),le.applyMatrix4(r.matrixWorld),Pe.copy(t),!i&&(le.setZ(0),Pe.setZ(0));const o=Pe.distanceTo(le);if(o>s)return;const l={distance:o,point:le.clone(),type:1};if(r.userData.type==="CircleCenter"){if(!this.isOSnapTypeEnabled(64))return;l.type=64}else if(A.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&&!Q.hasOutline(a,!1)){const o=Q.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)||[],A.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){y(this,"node");y(this,"parentNode");y(this,"target");y(this,"childNode");y(this,"follow",t=>{this.node.style.left=t.offsetX+15+"px",this.node.style.top=t.offsetY-30+"px"});y(this,"show",()=>this.node.hasAttribute("hidden")&&this.node.removeAttribute("hidden"));y(this,"hide",()=>!this.node.hasAttribute("hidden")&&this.node.setAttribute("hidden",""));y(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 _u{constructor(t){y(this,"viewer");y(this,"active",!1);y(this,"tooltip");y(this,"resolve");y(this,"reject");y(this,"isResolvedOrRejected",!1);y(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=_e.world2NormalizedScreen(n.min,this.camera,this.viewerContainer),a=_e.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()}}});y(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(ce.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.addEventListener("keydown",this.keydown),this.tooltip=new sl("pick-markup-tooltip",ze.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=ze.t("Tooltip.pickMarkup");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(ce.PickMarkupActivate)}deactivate(){this.active=!1,this.viewer.removeEventListener(ce.MouseClick,this.mouseClicked),this.viewer.getInputManager()?.removeEventListener("keydown",this.keydown),this.tooltip?.hide(),this.tooltip?.destroy(),this.tooltip=void 0,this.viewer.dispatchEvent(ce.PickMarkupDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}async pick(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),!this.isResolvedOrRejected&&this.reject&&this.reject("PickMarkupHelper is not done for some reason!")}}const Bi=class Bi{constructor(t){y(this,"viewer");y(this,"input");y(this,"mouseDown",!1);y(this,"mouseMove",!1);y(this,"mouseDownPositionX",-1);y(this,"mouseDownPositionY",-1);y(this,"tempKey");y(this,"tempTouch");y(this,"tempEnableRotate",!1);y(this,"rectDom");y(this,"tooltip");y(this,"active",!1);y(this,"resolve");y(this,"reject");y(this,"isResolvedOrRejected",!1);y(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}});y(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)}});y(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});y(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",ze.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=ze.t("Tooltip.boxSelect");e&&this.tooltip&&this.tooltip?.setContent(e),this.viewer.dispatchEvent(ce.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(ce.BoxSelectDeactivate),this.resolve&&!this.isResolvedOrRejected&&(this.resolve(void 0),this.isResolvedOrRejected=!0)}drawRect(t,e){!this.rectDom&&(this.rectDom=document.createElement("div"),this.rectDom.style.cssText=`position: absolute;border: ${Bi.BORDER_WIDTH} solid ${Bi.BORDER_COLOR};`,this.viewerContainer.appendChild(this.rectDom)),this.setRectDomVisible(!0),this.rectDom.style.left=t.x+"px",this.rectDom.style.top=t.y+"px";const i=Math.abs(e.x-t.x),s=Math.abs(e.y-t.y);this.rectDom.style.width=i+"px",this.rectDom.style.height=s+"px"}setRectDomVisible(t){this.rectDom&&(this.rectDom.style.display=t?"inline-block":"none")}async select(){return new Promise((t,e)=>{this.resolve=t,this.reject=e,this.activate()})}destroy(){this.deactivate(),this.rectDom?.remove(),this.rectDom=void 0,!this.isResolvedOrRejected&&this.reject&&this.reject("BoxSelectHelper is not done for some reason!")}};y(Bi,"BORDER_COLOR","#fff000"),y(Bi,"BORDER_WIDTH","2px");let mn=Bi;class nl{constructor(t){y(this,"viewer");y(this,"boxSelectHelper");y(this,"active",!1);this.viewer=t,this.boxSelectHelper=new mn(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 Ja(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 Js=new p.Box3,Au=new p.Vector3;function Iu(c,t){return c.trim().toLowerCase()===t?2e6:0}function Bu(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 xr{constructor(t){y(this,"viewer");y(this,"overlayRender");y(this,"drawableList");y(this,"indexedModelObject");y(this,"index",[]);this.viewer=t,this.overlayRender=this.viewer.getOverlayRender()}getMasterModel(){return this.viewer.loadedModels.find(t=>this.viewer.masterModelId===t.modelId)}invalidateIndex(){this.index=[],this.indexedModelObject=void 0}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=Ja(o.textContent);if(!l||(Js.makeEmpty(),Js.setFromObject(a),Js.isEmpty()))return;r(o.handle||"",l,o.layer||"0",this.findLayoutName(a),Js);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=Ja(d);if(!u)continue;const f=new p.Box3,m=h.positionStart||0,x=h.positionCount||0;for(let g=m;g<m+x;g++)s.fromBufferAttribute(l,g).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"?Iu(o.text,i):Bu(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,e=8){if(!t)return;this.viewer.activateLayout(t.layoutName),this.highlight(t);const i=t.box.clone(),s=i.getSize(Au).length(),n=Math.max(s*e,s+2);this.viewer.zoomToBBox(i.expandByScalar((n-s)/2))}highlight(t){this.overlayRender&&(!this.drawableList&&(this.drawableList=new gs("text-search"),this.overlayRender.addDrawableList(this.drawableList)),this.clearHighlight(),this.drawableList.addDrawable(new vt(N.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 ku extends Ht{constructor(e){super("MobileHelper");y(this,"position");y(this,"needsFrustumCulled");y(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 tt=(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))(tt||{});class rl extends Gt{constructor(e){super();y(this,"element");y(this,"enabled");y(this,"keyboardEnabled");y(this,"mouseDownPositionX");y(this,"mouseDownPositionY");y(this,"lastLeftPointerUpTime");y(this,"pointers");y(this,"handleClick");y(this,"handlePointerDown");y(this,"handlePointerMove");y(this,"handlePointerUp");y(this,"handlePointerCancel");y(this,"handleMouseWheel");y(this,"handleContextMenu");y(this,"handlePointerEnter");y(this,"handlePointerLeave");y(this,"handleResize");y(this,"handleKeydown");y(this,"handleKeyup");y(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,Qs(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,Qs(i,"pointerId")){s.pointerType=i.pointerType,s.buttons=i.buttons,s.pageX=i.pageX,s.pageY=i.pageY,s.pointerId=i.pointerId;const n=_e.getScreenCoordinateByEvent(i,this.element);s.x=n.x,s.y=n.y,s.movementX=i.movementX,s.movementY=i.movementY}else Qs(i,"deltaX")&&(s.deltaMode=i.deltaMode,s.deltaX=i.deltaX,s.deltaY=i.deltaY);else Qs(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 Qs(c,t){return c[t]!==void 0}class Du{constructor(t){y(this,"CLEAR_COLOR");y(this,"CLEAR_COLOR_ALPHA");y(this,"EMPTY_MODEL_ID");y(this,"viewer");y(this,"raycaster");y(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=_e.screen2Ndc(t,this.camera,this.viewerContainer);if(s>0){const r=[],a=new Map,o=_e.screen2Ndc(t,this.camera,this.viewerContainer),l=_e.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 g=0;g<m;g++){const M=g/m*Math.PI*2,w=Math.cos(M)*s,b=Math.sin(M)*s,C={x:t.x+w,y:t.y+b},S=_e.screen2Ndc(C,this.camera,this.viewerContainer);this.raycaster.setFromCamera(S,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 x=this.raycaster.intersectObjects(e,!0)||[];for(const g of x)g.object&&!a.has(g.object.uuid)&&(a.set(g.object.uuid,g),r.push(g));if(this.raycaster.params.Line.threshold=f,r.length>1){const g=this.raycaster.ray.origin.clone();r.sort((M,w)=>{const b=M.point||M.object.getWorldPosition(new p.Vector3),C=w.point||w.object.getWorldPosition(new p.Vector3);return b.distanceTo(g)-C.distanceTo(g)})}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=eu(s),r=tu(s);if(n!==this.EMPTY_MODEL_ID)return A.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 x=new Uint8Array(4*i*s);return r.readRenderTargetPixels(n,0,0,i,s,x),r.setRenderTarget(null),a.clearViewOffset(),r.setClearColor(f,m),x}}const Qa=new p.Vector3;class Lu{constructor(t){y(this,"viewer");y(this,"scene");y(this,"renderer");y(this,"pmremGenerator");y(this,"lights");y(this,"modelGroup");this.viewer=t;const e=new p.Scene;e.matrixAutoUpdate=st,e.matrixWorldAutoUpdate=st,this.scene=e,this.modelGroup=new p.Group,this.modelGroup.name="models",this.scene.add(this.modelGroup);const{width:i,height:s,viewerContainer:n}=t.container;let r;try{r=new p.WebGLRenderer({antialias:!0,preserveDrawingBuffer:!0})}catch{try{r=new p.WebGLRenderer,A.warn("WebGL context created with fallback settings (antialias disabled).")}catch(o){throw this.showWebGLUnavailable(n),new Error("WebGLUnavailable: failed to create WebGL context. "+o.message)}}r.setPixelRatio(window.devicePixelRatio),r.setSize(i,s),r.outputColorSpace=p.SRGBColorSpace,r.toneMappingExposure=1,r.localClippingEnabled=!0,r.shadowMap.enabled=!1,r.shadowMap.type=p.PCFSoftShadowMap,r.shadowMap.autoUpdate=!1,r.domElement.style.outlineWidth="0",n?.appendChild(r.domElement),this.renderer=r,N.printGpuInfo(r.getContext())}showWebGLUnavailable(t){if(!t)return;const e=document.createElement("div");e.style.cssText=["position:absolute","left:0","top:0","width:100%","height:100%","display:flex","align-items:center","justify-content:center","text-align:center","padding:0 24px","box-sizing:border-box","background:rgba(255,255,255,0.95)","color:#333","font-size:14px","line-height:1.8","z-index:9999"].join(";");const i=document.createElement("div");i.style.cssText="display:flex;flex-direction:column;align-items:center;gap:10px;max-width:560px";const s=document.createElement("span");s.style.cssText="text-align:center",s.textContent=ze.t("WebGL.NotAvailable"),i.appendChild(s);const n="chrome://settings/system",r=document.createElement("a");r.href=n,r.textContent=ze.t("WebGL.SettingsLink"),r.style.cssText="color:#1a73e8;text-decoration:underline;cursor:pointer;font-weight:bold";const a=document.createElement("span");a.style.cssText="color:#888;font-size:12px;text-align:center;display:none",r.addEventListener("click",o=>{o.preventDefault(),window.open(n,"_blank");try{const l=document.createElement("textarea");l.value=n,l.style.cssText="position:fixed;left:-9999px",document.body.appendChild(l),l.select(),document.execCommand("copy"),document.body.removeChild(l)}catch{}a.textContent=ze.t("WebGL.CopyFallback"),a.style.display="block"}),i.appendChild(r),i.appendChild(a),e.appendChild(i),t.appendChild(e)}initLights(){const t=new p.Group;t.name="lights";const e=1.5,i=16777215,s=new p.DirectionalLight(i,e);s.name="sun",s.castShadow=!0,s.position.set(-2,2,4),s.shadow.autoUpdate=!1,s.shadow.mapSize.width=1024,s.shadow.mapSize.height=1024;const n=new p.AmbientLight(i);n.name="ambient";const r=new p.HemisphereLight(i,14540253,.2);r.name="hemisphere",r.position.set(0,300,0);const a=new p.Group;a.name="lightHelpers",a.visible=!1;const o=new p.DirectionalLightHelper(s),l=new p.CameraHelper(s.shadow.camera);return a.add(o),a.add(l),t.add(s),t.add(s.target),t.add(n),t.add(r),t.add(a),this.scene.add(t),this.lights=t,t}initPMREMGenerator(){this.pmremGenerator=new p.PMREMGenerator(this.renderer),this.pmremGenerator.compileEquirectangularShader()}get maxFragmentUniforms(){return this.renderer.capabilities.maxFragmentUniforms-20}addModel(t){this.modelGroup.add(t.getModelObject())}removeModel(t){this.modelGroup.remove(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 ds.createEnvTextureFromDataArray(this.pmremGenerator,t);this.scene.environment=e}async setEnvironment(t){this.pmremGenerator||this.initPMREMGenerator();const e=await ds.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),A.debug("[Scene] directionalLight.position",t.position),A.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),Qa.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Qa),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 Ru{constructor(t){y(this,"history");y(this,"step");y(this,"maxCount");y(this,"isBatchCommand");y(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 bn extends Gt{constructor(e){super();y(this,"name");y(this,"viewerCfg");y(this,"clock");y(this,"targetMaxFps");y(this,"timeStamp");y(this,"renderEnabled");y(this,"requestAnimationFrameHandle");y(this,"container");y(this,"plugins");y(this,"loadedModels");y(this,"raf");y(this,"timeoutSymbol");y(this,"homeView");y(this,"inputManager");y(this,"cameraManager");y(this,"sceneManager");y(this,"fontManager");y(this,"pickManager");y(this,"undoManager");y(this,"overlayRender");y(this,"css2dRenderer");y(this,"spinner");y(this,"progressBar");y(this,"loaderHelper");y(this,"zoomToRectHelper");y(this,"_enableSelection");y(this,"enableRender");this.name=et.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 kr(e.containerId),e.enableProgressBar&&(this.progressBar=new Dr(this.container)),this.spinner=new Yo(this.container),this.sceneManager=new Lu(this),this.pickManager=new Du(this),this.overlayRender=new ms(this),this.css2dRenderer=this.initCSS2DRenderer(),this.inputManager=new rl(this.viewerContainer),this.cameraManager=new uu(this),this.loaderHelper=new Ut,this.undoManager=new Ru,this.resize(),this.clock.start(),this.animate()}initLogLevel(){const e=this.viewerCfg.logLevel;e&&mo(e)}initLocalization(){const e=this.viewerCfg.language||yo;ze.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 lo.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(ce.BeforeRender),this.renderer.render(this.scene,this.camera),this.css2dRenderer.render(this.scene,this.camera),this.dispatchEvent(ce.AfterRender),this.renderEnabled=!1),this.requestAnimationFrameHandle=requestAnimationFrame(this.animate.bind(this)),this.timeStamp=Date.now(),this.dispatchEvent(ce.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=st,i.updateMatrix(),i.updateMatrixWorld(!0),this.loadedModels.push(e),this.enableRender(0)}async setFont(e){!this.fontManager&&(this.fontManager=new bt),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,A.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)){A.error("[Viewer] camera position and lookAt cannot be the same!");return}else if(!N.isVectorValid(e)||!N.isVectorValid(i)){A.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),A.warn("[Viewer] camera could be too close to see the object!")):r>n.far&&(e=e.clone().sub(i).normalize().multiplyScalar(n.far*.9),A.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}}removeModel(e){const i=this.loadedModels.findIndex(n=>n.modelId===e);if(i===-1)return;const s=this.loadedModels.splice(i,1)[0];return this.sceneManager.removeModel(s),Q.disposeObject(s.getModelObject()),this.enableRender(),s}destroy(){this.requestAnimationFrameHandle&&cancelAnimationFrame(this.requestAnimationFrameHandle),this.loaderHelper.abortDxfLoading(),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)){A.warn("[Viewer] Plugin already exist: "+e.id);return}this.plugins.push(e),A.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,Ti=new p.Vector3,eo=new p.Matrix4,to=new p.Frustum,Qn=new p.Box3,io=new p.Matrix4;class Rr extends bn{constructor(e){super(e);y(this,"name");y(this,"loadedModels");y(this,"masterModelId");y(this,"activeLayoutName");y(this,"dxfLayoutBar");y(this,"layoutInfos");y(this,"units");y(this,"enableHideVisuallySmallObjects");y(this,"sortedHidableObjects");y(this,"lastCameraZoom");y(this,"groundPlane");y(this,"raycastableObjects");y(this,"selectedObject");y(this,"loadingDxfCount");y(this,"textSearchHelper");y(this,"clickHighlightList");y(this,"_enableClickHighlight",!1);y(this,"requestHeaders");y(this,"_printCaptureMode",!1);this.name=et.Viewer2d,this.loadedModels=[],this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0,this.enableHideVisuallySmallObjects=e.enableHideVisuallySmallObjects===!0,this.sortedHidableObjects={},this.lastCameraZoom=1/0,this.loadingDxfCount=0,e.enableLayoutBar&&(this.dxfLayoutBar=new au(this)),this.cameraManager.setProjection(wt.Orthographic),this.cameraManager.setNavigationMode(dt.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(ce.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===tt.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(ce.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),io.copy(i.matrixWorld);for(let l=a;l<a+o&&l<s.count;l++)Ti.fromBufferAttribute(s,l).applyMatrix4(io),r.expandByPoint(Ti);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 gs("entity-click-highlight"),i.addDrawableList(this.clickHighlightList)),this.clickHighlightList.clear(),this.clickHighlightList.addDrawable(new vt(N.guid(),[e.clone()],[.031,.906,.867,1],[.031,.906,.867,.15])),this.enableRender())}get enableClickHighlight(){return this._enableClickHighlight}set enableClickHighlight(e){this._enableClickHighlight=e,e||this.clearClickHighlight()}clearClickHighlight(){this.clickHighlightList?.clear(),this.enableRender()}setRequestHeaders(e){this.requestHeaders=e}handleMouseClick(e){if(!this.enableSelection)return;const i=new p.Vector2(e.x,e.y),s=this.getWorldPositionByMousePick(i);if(!s)return;const n=this.overlayRender.getDrawablesByPosition(s)[0];if(n){this.selectedObject===n?(this.selectedObject.selected=!1,this.selectedObject=void 0):(this.selectedObject&&this.clearSelection(),this.selectedObject=n,this.selectedObject.selected=!0),this.enableRender();return}const r=this.pickObject(i,[Nt]);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){this.loaderHelper.abortDxfLoading();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=ze.t("ProgressBar.Loading"),o=d=>{this.progressBar?.updateProgress(r,a,d),i?.(new ProgressEvent("LoadProgress",{loaded:d,total:100}))},l=(d,u,f)=>{let m=d.loaded*100/d.total;m=m*(f-u)/100+u,this.progressBar?.updateProgress(r,a,m),i?.(new ProgressEvent("LoadProgress",{loaded:m,total:100}))},h=d=>l(d,0,90);this.progressBar?.addProgressItem(r),o(0);try{this.loadingDxfCount++;const d=this.viewerCfg,u=await this.loaderHelper.loadDxfData(e.src,e.modelId,h,void 0,{ignorePaperSpace:e.ignorePaperSpace,enableLocalCache:d.enableLocalCache,enableMerge:e.merge,encoding:e.encoding,overrideColor:e.overrideColor,requestHeaders:e.headers??this.requestHeaders}).finally(()=>{this.loadingDxfCount--,this.loadingDxfCount===0&&this.fontManager?.releaseFontData()}),f=u.threejsObject;if(s&&s({threejsObject:f,llbMesh:u.llbMesh}),e.matrix&&e.matrix.length===16){const x=new p.Matrix4;x.elements=e.matrix,f.applyMatrix4(x)}const m=new Li({modelId:n,dxfData:u});this.addModel(m),o(100),this.progressBar?.delayRemoveProgressItem(r),this.dispatchEvent(ce.ModelLoad)}catch(d){throw this.progressBar?.removeProgressItem(r),A.error("[Viewer2d] Failed to load model '"+e.src+"'",d),d}finally{this.spinner.decreaseJobCount()}}removeModel(e){const i=super.removeModel(e);return i&&this.textSearchHelper?.invalidateIndex(),i&&this.loadedModels.length===0&&(this.masterModelId="",this.activeLayoutName="",this.layoutInfos={},this.units=void 0),i}addModel(e){super.addModel(e);const i=e.modelId;if(e.dxfData){this.masterModelId===i?this.activateLayout(Z.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=Z.MODEL_LAYOUT_NAME;const n=new p.Box3().setFromObject(s);this.layoutInfos[this.activeLayoutName]={homeViewExtent:n,extent:n},s.matrixAutoUpdate=st,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():Qe.Unitless}handleOverlayDxf(e){const i=this.loadedModels.find(n=>e===n.modelId);if(!i){A.warn("[Viewer] Can't find model for modelId '"+e+"'!");return}i.switchTransformMs(Z.MODEL_LAYOUT_NAME),i.getLayoutLevelObject(Z.MODEL_LAYOUT_NAME)?.traverse(n=>{i.addSpatialFilterSection(n,i.dxfData)}),i.showLayoutObjects(Z.MODEL_LAYOUT_NAME)}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}setObjectUnHighlight(e){this.loadedModels.forEach(i=>i.unHighlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}clearSelection(){this.selectedObject instanceof p.Object3D&&this.setObjectUnHighlight(this.selectedObject),this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clickHighlightList?.clear()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}updateGroundPlane(){const e=this.getActiveLayoutInfo();if(!e.homeViewExtent)return;const i=e.homeViewExtent.clone(),s=[],n=(o,l,h)=>{s.push(new p.Vector3(o,l,h))},r=i.getSize(new p.Vector3),a=i.getCenter(new p.Vector3);if(n(-r.x/2,-r.y/2,0),n(r.x/2,-r.y/2,0),n(r.x/2,r.y/2,0),n(-r.x/2,r.y/2,0),this.groundPlane)this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.geometry.setFromPoints(s),this.groundPlane.geometry.computeBoundingSphere(),this.groundPlane.geometry.computeBoundingBox();else{const o=new p.BufferGeometry;o.setFromPoints(s),o.setIndex([0,3,2,0,2,1]);const l=new p.MeshBasicMaterial({color:"#888",side:p.DoubleSide});this.groundPlane=new p.Mesh(o,l),this.groundPlane.visible=!1,this.groundPlane.position.set(a.x,a.y,-r.z),this.groundPlane.scale.set(1e5,1e5,1),this.groundPlane.name="groundPlane",this.groundPlane.renderOrder=al,this.groundPlane.layers.enableAll(),Q.disableLayerChannels(this.groundPlane,[Nt]),this.scene.add(this.groundPlane)}this.groundPlane.updateMatrix(),this.groundPlane.updateMatrixWorld(!0)}getRaycastableObjects(){const e=[],i=Date.now();if(this.activeLayoutName===Z.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)}))}eo.multiplyMatrices(this.camera.projectionMatrix,this.camera.matrixWorldInverse),to.setFromProjectionMatrix(eo);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===Z.SNAP_GROUP_NAME)?.traverse(o=>{if(Q.isLeafObject(o)){if(Qn.makeEmpty(),Qn.expandByObject(o),!to.intersectsBox(Qn))return;e.push(o)}})}this.groundPlane&&e.push(this.groundPlane),A.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))}),A.debug("[Viewer] getRaycastableObjectsByMouse() from inside of viewport:",r.viewportId)):A.debug("[Viewer] getRaycastableObjectsByMouse() from out of viewport"),this.groundPlane&&e.push(this.groundPlane)}return A.debug("[Viewer] getRaycastableObjectsByMouse() took "+(Date.now()-i)/1e3+" s"),e}getViewportByPoint(e){if(this.activeLayoutName.length===0||this.activeLayoutName===Z.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=Z.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(A.debug("[Viewer] Active layout:",e,", viewports:",o),!a){const d=this.camera.position.z;let u=0;o.forEach(m=>{const x=m?.msToPsMatrix?.elements[14];x&&x>u&&(u=x)});const f=this.cameraManager.getPosition();if(u>f.z+d){const m=Math.ceil(u+d);f.z=m,A.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 x=d.max.x-d.min.x,g=d.max.y-d.min.y;(x<1e-16||g<1e-16||x>1e16||g>1e16)&&(A.warn("[Viewer] Got wired bbox, max: "+d.max.toArray()+", min: "+d.min.toArray()+", going to use the calculated one..."),d=l.extent)}else A.warn("[Viewer] Failed to get layout extent, going to use the calculated one..."),d=l.extent;const u=l.extent;if(d&&!u.isEmpty()){const f=d.max.x-d.min.x,m=d.max.y-d.min.y,x=u.max.x-u.min.x,g=u.max.y-u.min.y;x>0&&g>0&&x<=f*.5&&g<=m*.5?d=u.clone():d.intersectsBox(u)?d.union(u):(A.warn("[Viewer] Layout extent from header is far from actual geometry, using computed bbox instead."),d=u.clone())}l.homeViewExtent=d,this.zoomToBBox(d)}const h=i.getLayoutLevelObject(e);h&&this.setLayoutHidableObjectArray(h),this.enableRender()}getLayoutExtentEx(e){const i=this.loadedModels.find(s=>this.masterModelId===s.modelId);if(i)return e.layoutName===Z.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):A.error("[Viewer] Failed to find extent for "+this.activeLayoutName)}zoomToBBox(e){const i=e.getCenter(Ti),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=_e.getScreenCoordinateByEvent(e,i),n=_e.screen2Ndc(s,this.camera,i);return this.getHitResultByNdcCoordinate(n)}getActiveLayoutName(){return this.activeLayoutName}searchText(e,i){return!this.textSearchHelper&&(this.textSearchHelper=new xr(this)),this.textSearchHelper.search(e,i)}focusText(e,i){!this.textSearchHelper&&(this.textSearchHelper=new xr(this)),this.textSearchHelper.focus(e,i)}clearTextHighlight(){this.textSearchHelper?.clearHighlight()}zoomIn(e=.01){this.cameraManager.cameraControls.zoom(e)}zoomOut(e=.01){this.cameraManager.cameraControls.zoom(-e)}async print(e={}){const{area:i="view",paperSize:s="A4",orientation:n="auto",invertColors:r=!1,fitToPage:a=!0,margins:o=10,title:l="图纸"}=e;if(!this.loadedModels.length){A.warn("[Viewer] print: no model loaded.");return}const h=this.capturePrintImage(i,r),d=new Image;await new Promise((f,m)=>{d.onload=()=>f(),d.onerror=()=>m(new Error("Failed to load captured print image.")),d.src=h});const u=n==="auto"?d.width>=d.height?"landscape":"portrait":n;this.printImageInIframe({dataUrl:h,width:d.width,height:d.height,paperSize:s,orientation:u,invertColors:r,fitToPage:a,margins:o,title:l})}capturePrintImage(e,i){const s=this.cameraManager.cameraControls,n=this.renderer,r=s.getPosition(new p.Vector3),a=s.getTarget(new p.Vector3),o=this.camera.zoom,l=n.getPixelRatio();let h;e==="extents"&&(h=this.getActiveLayoutInfo().homeViewExtent??this.getBBox(),this.zoomToBBox(h)),this._printCaptureMode=!0;const d=this.sortedHidableObjects[this.activeLayoutName],u=[];if(d)for(const O of d)O.object.userData?.layerVisible!==!1&&(u.push({object:O.object,visible:O.object.visible}),O.object.visible=!0);const{clientWidth:f,clientHeight:m}=this.viewerContainer,x=Math.min(n.capabilities.maxTextureSize||4096,8192),g=Math.min(4,x/Math.max(f,m));g>l&&n.setPixelRatio(g),this.cameraManager.update(0),this.dispatchEvent(ce.BeforeRender),n.render(this.scene,this.camera),this.dispatchEvent(ce.AfterRender);const M=n.domElement,w=this.overlayRender.getCanvas(),b=document.createElement("canvas");b.width=M.width,b.height=M.height;const C=b.getContext("2d");if(C.drawImage(M,0,0),w&&w.width>0&&w.height>0&&C.drawImage(w,0,0,b.width,b.height),i){const O=new p.Color(1973806);this.scene.background instanceof p.Color?O.copy(this.scene.background):n.getClearColor(O),O.convertLinearToSRGB(),this.invertForPrint(b,Math.max(1,Math.round(g/2)),{r:O.r*255,g:O.g*255,b:O.b*255})}let S=b.toDataURL("image/png");if(h&&this.camera.type==="OrthographicCamera"){const O=this.cropCanvasToBox(b,h);O&&(S=O)}this._printCaptureMode=!1;for(const{object:O,visible:E}of u)O.visible=E;return n.setPixelRatio(l),s.zoomTo(o),s.setLookAt(r.x,r.y,r.z,a.x,a.y,a.z),this.cameraManager.update(0),this.enableRender(),S}invertForPrint(e,i,s){const n=e.getContext("2d",{willReadFrequently:!0});if(!n)return;const r=e.width,a=e.height,o=n.getImageData(0,0,r,a),l=o.data,h=r*a,d=45,u=.72,f=new Float32Array(h);for(let E=0,v=0;E<h;E++,v+=4){const T=l[v],P=l[v+1],_=l[v+2],I=T-s.r,B=P-s.g,k=_-s.b;if(Math.sqrt(I*I+B*B+k*k)<d){l[v]=255,l[v+1]=255,l[v+2]=255,f[E]=255;continue}const D=T/255,z=P/255,se=_/255,re=Math.max(D,z,se),je=Math.min(D,z,se),Le=(re+je)/2,de=re-je,zi=de===0?0:de/(1-Math.abs(2*Le-1));let nt=0;de!==0&&(re===D?nt=(z-se)/de%6:re===z?nt=(se-D)/de+2:nt=(D-z)/de+4,nt/=6,nt<0&&(nt+=1));const wn=Math.min(.55,(1-Le)*u),Re=(1-Math.abs(2*wn-1))*zi,It=Re*(1-Math.abs(nt*6%2-1)),Vi=wn-Re/2;let qt=0,Wt=0,Yt=0;const Xt=Math.floor(nt*6)%6;Xt===0?(qt=Re,Wt=It):Xt===1?(qt=It,Wt=Re):Xt===2?(Wt=Re,Yt=It):Xt===3?(Wt=It,Yt=Re):Xt===4?(qt=It,Yt=Re):(qt=Re,Yt=It),l[v]=(qt+Vi)*255,l[v+1]=(Wt+Vi)*255,l[v+2]=(Yt+Vi)*255,f[E]=.299*l[v]+.587*l[v+1]+.114*l[v+2]}const m=Math.max(1,i),x=new Float32Array(h),g=new Uint8ClampedArray(h),M=new Uint8ClampedArray(h),w=new Uint8ClampedArray(h);for(let E=0;E<a;E++){const v=E*r;for(let T=0;T<r;T++){let P=255,_=v+T;const I=Math.max(0,T-m),B=Math.min(r-1,T+m);for(let k=I;k<=B;k++){const D=f[v+k];D<P&&(P=D,_=v+k)}x[v+T]=P,g[v+T]=l[_*4],M[v+T]=l[_*4+1],w[v+T]=l[_*4+2]}}const b=new Float32Array(h),C=new Uint8ClampedArray(h),S=new Uint8ClampedArray(h),O=new Uint8ClampedArray(h);for(let E=0;E<r;E++)for(let v=0;v<a;v++){let T=255,P=v*r+E;const _=Math.max(0,v-m),I=Math.min(a-1,v+m);for(let k=_;k<=I;k++){const D=x[k*r+E];D<T&&(T=D,P=k*r+E)}const B=v*r+E;b[B]=T,C[B]=g[P],S[B]=M[P],O[B]=w[P]}for(let E=0,v=0;E<h;E++,v+=4)f[E]>250&&b[E]<250&&(l[v]=C[E],l[v+1]=S[E],l[v+2]=O[E]);n.putImageData(o,0,0)}cropCanvasToBox(e,i){const s=this.camera,n=s.zoom||1,r=s.position.x,a=s.position.y,o=r+s.left/n,l=r+s.right/n,h=a+s.bottom/n,d=a+s.top/n,u=l-o,f=d-h;if(u<=0||f<=0)return;const m=v=>(v-o)/u*e.width,x=v=>(d-v)/f*e.height,g=Math.max(u,f)*.01,M=Math.max(0,Math.floor(m(i.min.x-g))),w=Math.min(e.width,Math.ceil(m(i.max.x+g))),b=Math.max(0,Math.floor(x(i.max.y+g))),C=Math.min(e.height,Math.ceil(x(i.min.y-g))),S=w-M,O=C-b;if(S<16||O<16)return;const E=document.createElement("canvas");return E.width=S,E.height=O,E.getContext("2d").drawImage(e,M,b,S,O,0,0,S,O),E.toDataURL("image/png")}printImageInIframe(e){const{dataUrl:i,width:s,height:n,paperSize:r,orientation:a,invertColors:o,fitToPage:l,margins:h,title:d}=e,u={A4:[210,297],A3:[297,420],A2:[420,594],A1:[594,841],A0:[841,1189],Letter:[215.9,279.4]};let[f,m]=u[r]??u.A4;a==="landscape"&&([f,m]=[m,f]);const x=document.createElement("iframe");x.setAttribute("aria-hidden","true");const g=96/25.4;x.style.cssText=`position:fixed;left:-20000px;top:0;border:0;visibility:hidden;width:${Math.ceil(f*g)}px;height:${Math.ceil(m*g)}px;`;const M=v=>v.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),w=l?"max-width:100%;max-height:100%;width:auto;height:auto;":"width:100%;height:auto;",b=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${M(d)}</title><style>@page{size:${r} ${a};margin:${h}mm;}html,body{margin:0;padding:0;background:#fff;}body{display:flex;align-items:center;justify-content:center;width:${f-2*h}mm;height:${m-2*h}mm;overflow:hidden;}img{display:block;${w}}</style></head><body><img src="${i}" alt="${M(d)}"></body></html>`;document.body.appendChild(x);const C=()=>{x.contentWindow?.removeEventListener("afterprint",C),setTimeout(()=>x.remove(),100)},S=x.contentDocument;S.open(),S.write(b),S.close();const O=S.querySelector("img"),E=()=>{const v=x.contentWindow;v.addEventListener("afterprint",C),v.focus(),v.print(),setTimeout(C,6e4)};O.complete?E():(O.onload=E,O.onerror=C)}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 A.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||!Q.isLeafObject(h))return;const d=h.geometry;d.boundingBox||d.computeBoundingBox();const u=d.boundingBox.clone();if(!u||!N.isBoxValid(u))return;u.applyMatrix4(h.matrixWorld),u.getSize(Ti);const f=Math.max(Ti.x,Ti.y),m=o/f;m<1/0?r.push({visibleMinZoom:m,object:h}):h instanceof p.Points?r.push({visibleMinZoom:o,object:h}):A.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),A.debug("[Viewer] setLayoutHidableObjectArray took: "+(Date.now()-s)/1e3+"s, "+l+" objects changed to hidden")}updateRaycasterThreshold(){const e=this.getPixelSizeInWorldCoord()*3,i=this.getRaycaster().params;i.Line?i.Line.threshold=e:i.Line={threshold:e},i.Points?i.Points.threshold=e:i.Points={threshold:e}}updateHidableObjectsVisibility(){const e=this.camera,i=Date.now();this.cameraManager.update(0);const s=e.zoom;if(Math.abs(s-this.lastCameraZoom)<1e-5)return;if(this.updateRaycasterThreshold(),this.updateCameraZoomUniform(s),this.raycastableObjects=void 0,this._printCaptureMode){this.lastCameraZoom=s;return}if(!this.sortedHidableObjects[this.activeLayoutName])return;const n=this.sortedHidableObjects[this.activeLayoutName];if(n.length===0)return;const r=s>this.lastCameraZoom,a=Math.min(s,this.lastCameraZoom),o=Math.max(s,this.lastCameraZoom),l=[];let h=0;for(let d=0;d<n.length;++d)if(n[d].object.userData.layerVisible!==!1){if(n[d].visibleMinZoom<a){l.push(n[d].object);continue}else if(n[d].visibleMinZoom>o)break;n[d].object.visible=r,r&&l.push(n[d].object),h++}this.lastCameraZoom=s,A.debug("[Viewer] updateHidableObjectsVisibility took: "+(Date.now()-i)/1e3+"s, "+h+"(out of "+n.length+") objects changed to "+(r?"visible":"hidden"))}updateCameraZoomUniform(e){Z.CameraZoomUniform.value=e*this.container.height/50}}class ol{constructor(t){y(this,"viewer");y(this,"fontManager");y(this,"loader");y(this,"loadingManager");y(this,"changes");y(this,"container");y(this,"spinner");y(this,"jobCount");y(this,"loadingProgressBar");this.jobCount=0,this.viewer=new Rr(t);const e=document.getElementById(t.containerId);this.container=e?.parentElement||document.body;const i=new kr(t.containerId);this.loadingProgressBar=new Dr(i);const s={ignorePaperSpace:!0};this.loader=new Z(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 bt),await this.fontManager.loadFonts(t),A.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();this.increaseJobCount();try{if(!this.fontManager)throw"[DxfCompareHelper] Should set font first!";this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const l=n+a,h=ze.t("ProgressBar.Comparing"),d=B=>{this.loadingProgressBar?.updateProgress(l,h,B),s&&s(new ProgressEvent("CompareProgress",{loaded:B,total:100}))},u=(B,k,D)=>{let z=B.loaded*100/B.total;z=z*(D-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),x=B=>u(B,30,60),g=B=>u(B,60,95);N.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(l),d(0);let M=Date.now();const w=this.loader.parse(n,f),b=this.loader.parse(a,m),[C,S]=await Promise.allSettled([w,b]);if(C.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+n;if(S.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+a;if(A.info("[DxfCompareHelper] loadFiles in "+(Date.now()-M)/1e3+"s"),this.loader.isAborted())throw"[DxfCompareHelper] compare loadFile aborted";const O=C.value,E=S.value;M=Date.now();const v=await new ht(O,E,i).compare(x);if(A.info("[DxfCompareHelper] Compared in "+(Date.now()-M)/1e3+"s"),A.debug("[DxfCompareHelper] Compared results:",v),this.loader.isAborted())throw"[DxfCompareHelper] compare change aborted";N.printMemory("After getting the comparison results"),M=Date.now(),await this.loader.loadEntitiesForCompare(O,E,v,!0,g),N.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=v,A.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-M)/1e3+"s");const T=O,P=E;if(!Object.keys(v).length&&A.info("[DxfCompareHelper] No change found"),T.threejsObject?.children.length===0&&P.threejsObject?.children.length===0){const B="[DxfCompareHelper] Nothing was loaded from "+n+" and "+a;throw A.warn(B),B}const _=T.threejsObject,I=P.threejsObject;_.name=n,I.name=a,M=Date.now(),this.viewer.addModel(new Li({modelId:t.modelId||t.src,dxfData:T})),this.viewer.flyToObject(_),N.printMemory("After adding first loaded Model to scene"),d(95),this.viewer.addModel(new Li({modelId:e.modelId||e.src,dxfData:P})),N.printMemory("After adding second loaded Model to scene"),A.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-M)/1e3+"s"),A.info("[DxfCompareHelper] The comparison between "+n+"' and '"+a+"' is completed in "+(Date.now()-o)/1e3+"s !"),d(100),this.loadingProgressBar?.delayRemoveProgressItem(l)}catch(l){throw this.loadingProgressBar?.removeProgressItem(n+a),l}finally{this.decreaseJobCount()}}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 Fu extends ol{constructor(e,i){super(e);y(this,"viewer2");y(this,"syncCamera");y(this,"markupManager1");y(this,"markupManager2");y(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 Rr(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();this.increaseJobCount();try{if(!this.fontManager)throw"[DxfCompareHelper] Should set font first!";this.loader.setFont(this.fontManager),await this.fontManager.getFontFromIndexeddb();const d=r+o,u=ze.t("ProgressBar.Comparing"),f=D=>{this.loadingProgressBar?.updateProgress(d,u,D),n&&n(new ProgressEvent("CompareProgress",{loaded:D,total:100}))},m=(D,z,se)=>{let re=D.loaded*100/D.total;re=re*(se-z)/100+z,this.loadingProgressBar?.updateProgress(d,u,re),n&&n(new ProgressEvent("CompareProgress",{loaded:re,total:100}))},x=D=>m(D,0,15),g=D=>m(D,15,30),M=D=>m(D,30,60),w=D=>m(D,60,95);N.printMemory("Before comparing"),this.loadingProgressBar?.addProgressItem(d),f(0);let b=Date.now();const C=this.loader.parse(r,x),S=this.loader.parse(o,g),[O,E]=await Promise.allSettled([C,S]);if(O.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+r;if(E.status==="rejected")throw"[DxfCompareHelper] Failed to parse "+o;if(A.info("[DxfCompareHelper] loadFiles in "+(Date.now()-b)/1e3+"s"),this.loader.isAborted())throw"[DxfCompareHelper] compare loadFile aborted";const v=O.value,T=E.value;b=Date.now();const P=await new ht(v,T,s).compare(M);if(A.info("[DxfCompareHelper] Compared in "+(Date.now()-b)/1e3+"s"),A.debug("Compared results:",P),this.loader.isAborted())throw"[DxfCompareHelper] compare change aborted";N.printMemory("After getting the comparison results"),b=Date.now(),await this.loader.loadEntitiesForCompare(v,T,P,!1,w),N.printMemory("After Creating threejs objects based on comparison result"),this.fontManager?.releaseFontData(),this.changes=P,A.info("[DxfCompareHelper] Creates threejs objects based on comparison result in "+(Date.now()-b)/1e3+"s");const _=v,I=T;if(!Object.keys(P).length&&A.info("[DxfCompareHelper] No change found"),_.threejsObject?.children.length===0&&I.threejsObject?.children.length===0){const D="[DxfCompareHelper] Nothing was loaded from "+r+" and "+o;throw A.warn(D),D}const B=_.threejsObject,k=I.threejsObject;B.name=r,k.name=o,b=Date.now(),this.viewer.addModel(new Li({modelId:e.modelId||e.src,dxfData:_})),N.printMemory("After adding first loaded Model to scene"),f(95),this.viewer2.addModel(new Li({modelId:i.modelId||i.src,dxfData:I})),N.printMemory("After adding second loaded Model to scene"),this.drawCompareBoxes(),A.info("[DxfCompareHelper] Added compared objects to scene in "+(Date.now()-b)/1e3+"s"),A.info("[DxfCompareHelper] The comparison between "+r+"' and '"+o+"' is completed in "+(Date.now()-h)/1e3+"s !"),f(100),this.loadingProgressBar?.delayRemoveProgressItem(d)}catch(d){throw this.loadingProgressBar?.removeProgressItem(r+o),d}finally{this.decreaseJobCount()}}drawCompareBoxes(){this.changes&&(this.markupManager1??(this.markupManager1=new yr(this.viewer)),this.markupManager2??(this.markupManager2=new yr(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)))}}}const zu=["图框","图签","标题栏","title","tk","frame","border"],Vu=.02,Uu=10,so=.5,ju=.6;function Nu(c){return c.charCodeAt(0)===65279?c.slice(1):c}function He(c){return Math.max(0,c.maxX-c.minX)*Math.max(0,c.maxY-c.minY)}function er(c,t){return{minX:Math.max(c.minX,t.minX),minY:Math.max(c.minY,t.minY),maxX:Math.min(c.maxX,t.maxX),maxY:Math.min(c.maxY,t.maxY)}}function no(c,t,e,i=0){return t>=c.minX-i&&t<=c.maxX+i&&e>=c.minY-i&&e<=c.maxY+i}const Oe=class Oe{constructor(t,e){y(this,"lines");y(this,"options");y(this,"sections",[]);y(this,"entityBlocks",[]);y(this,"blockDefs",new Map);y(this,"drawingBBox",null);y(this,"frames",[]);y(this,"assignments",[]);y(this,"detected",!1);this.lines=Nu(t).split(/\r\n|\r|\n/),this.options={minAreaRatio:Vu,templateGroupThreshold:Uu,...e},this.scanSections(),this.scanBlockDefs(),this.scanEntityBlocks()}static async fromUrl(t,e){const i=await fetch(t);if(!i.ok)throw new Error(`[DxfSplitter] Failed to fetch dxf: ${i.status} ${t}`);return new Oe(await i.text(),e)}static async fromFile(t,e){return new Oe(await t.text(),e)}getFrames(){return this.frames}getUnassignedCount(){let t=0;for(const e of this.assignments)e<0&&t++;return t}detectFrames(){if(this.detected)return this.frames;this.detected=!0,this.report(5,"扫描实体");const t=this.collectCandidates();this.report(35,"筛选图框");const e=this.filterAndSortCandidates(t),i=this.frames.filter(n=>n.source==="manual"),s=i.reduce((n,r)=>Math.max(n,r.index+1),0);e.forEach((n,r)=>{n.index=s+r}),this.frames=[...e,...i],this.report(55,"归属实体"),this.assignEntities(e),this.report(85,"识别图纸名称"),this.applyTitleNames(e);for(const n of i)n.entityCount=this.reassignManualEntities(n);if(this.frames.length===1&&i.length===0){const n=this.frames[0];n.name==="图框01"&&this.options.defaultName&&(n.name=this.options.defaultName)}return this.report(100,`识别到 ${this.frames.length} 个图框`),this.frames}isTitleNoise(t){return t.length<=1?!0:Oe.TITLE_NOISE.some(e=>e.test(t))}isTitleRowNoise(t){return/^注/.test(t)||/^\d+[.、]/.test(t)||/[。;?!]/.test(t)||/[。,,;;::.]$/.test(t)}cleanTitleText(t){if(Oe.gbkDecoder===void 0)try{Oe.gbkDecoder=new TextDecoder("gbk")}catch{Oe.gbkDecoder=null}const e=Oe.gbkDecoder;return(e?t.replace(/\\M\+[1-9A-Fa-f]([0-9A-Fa-f]{4})/g,(s,n)=>{const r=new Uint8Array(2);r[0]=parseInt(n.slice(0,2),16),r[1]=parseInt(n.slice(2),16);try{return e.decode(r)}catch{return""}}):t.replace(/\\M\+[1-9A-Fa-f][0-9A-Fa-f]{4}/g,"")).replace(/\\P/gi," ").replace(/\\[A-Za-z][^;\\]*;/g,"").replace(/[{}]/g,"").replace(/%%[UOoCcdD]/g,"").replace(/\s+/g,"")}extractFrameTitle(t){const e=t.bbox,i=e.maxX-e.minX,s=e.maxY-e.minY,n=[{x0:e.maxX-i*.5,y0:e.minY,y1:e.minY+s*.25},{x0:e.maxX-i*.5,y0:e.maxY-s*.5,y1:e.maxY}];for(const r of n){const a=this.pickTitleInZone(t,r);if(a)return a}return null}pickTitleInZone(t,e){const i=t.bbox,s=i.maxX-i.minX,n=i.maxY-i.minY,r=[],a=this.lines;for(let f=0;f<this.entityBlocks.length;f++){if(this.assignments[f]!==t.index)continue;const m=this.entityBlocks[f];if(m.type==="INSERT"){let b=!1,C,S,O=0,E="";const v=()=>{E&&C!==void 0&&S!==void 0&&this.pushTitleToken(r,C,S,O||2.5,E,e),C=void 0,S=void 0,O=0,E=""};for(let T=m.start+2;T+1<m.end;T+=2){const P=parseInt(a[T],10),_=a[T+1];if(P===0){v(),b=_.trim()==="ATTRIB";continue}b&&(P===10?C=parseFloat(_):P===20?S=parseFloat(_):P===40?O=parseFloat(_):(P===1||P===3)&&(E+=_))}v();continue}if(m.type!=="TEXT"&&m.type!=="MTEXT")continue;let x,g,M=0,w="";for(let b=m.start+2;b+1<m.end;b+=2){const C=parseInt(a[b],10),S=a[b+1];C===10?x=parseFloat(S):C===20?g=parseFloat(S):C===40?M=parseFloat(S):(C===1||C===3)&&(w+=S)}x!==void 0&&g!==void 0&&this.pushTitleToken(r,x,g,M||2.5,w,e)}if(!r.length)return null;r.sort((f,m)=>m.y-f.y);const o=[];for(const f of r){const m=o.find(x=>Math.abs(x[0].y-f.y)<=Math.max(x[0].hgt,f.hgt)*1.6);m?m.push(f):o.push([f])}const h=o.map(f=>{const{y:m,hgt:x}=f[0];f.sort((C,S)=>C.x-S.x);const g=f.filter(C=>!(Oe.DRAWING_NO.test(C.txt)&&/\d/.test(C.txt))&&!this.isTitleRowNoise(C.txt));if(!g.length)return null;const M=g.reduce((C,S,O)=>S.txt.includes("图")&&(C<0||S.txt.length>g[C].txt.length)?O:C,-1);if(M<0)return null;const w=g[M];let b=w.txt;for(let C=M-1;C>=0&&!(g[C+1].x-g[C].x>6*Math.max(g[C].hgt,w.hgt)||Oe.ORG_NAME.test(g[C].txt));C--)b=g[C].txt+b;return{txt:b,len:b.length,x:w.x,y:m,hgt:x,row:f}}).filter(f=>f!==null&&f.len>=2).filter(f=>f.txt.includes("图")&&f.txt.length>=4&&!this.isTitleRowNoise(f.txt)).sort((f,m)=>m.len-f.len)[0];if(!h)return null;let d=h.txt;const u=o[o.indexOf(h.row)-1];if(u&&Math.abs(u[0].y-h.y)<=n*.06){const f=u.filter(m=>!(Oe.DRAWING_NO.test(m.txt)&&/\d/.test(m.txt))&&!this.isTitleRowNoise(m.txt)&&!Oe.ORG_NAME.test(m.txt)&&/[\u4e00-\u9fff]/.test(m.txt)&&!m.txt.includes("图")&&m.txt.length<=15&&Math.abs(m.x-h.x)<=s*.05).sort((m,x)=>Math.abs(m.x-h.x)-Math.abs(x.x-h.x))[0];f&&(d=f.txt+h.txt)}return d.slice(0,40).replace(/[\\/:*?"<>|]/g,"_")||null}pushTitleToken(t,e,i,s,n,r){const a=this.cleanTitleText(n);!a||a.length<=1||e<r.x0||i<r.y0||i>r.y1||this.isTitleNoise(a)||t.push({x:e,y:i,hgt:s,txt:a})}applyTitleNames(t){for(const i of t){const s=this.extractFrameTitle(i);s&&(i.name=s)}const e=new Map;for(const i of t){const s=e.get(i.name)??0;e.set(i.name,s+1),s>0&&(i.name=`${i.name}(${s+1})`)}}addManualFrame(t){if(He(t)<=0)return null;const e=this.frames.reduce((a,o)=>Math.max(a,o.index+1),0),i=this.frames.filter(a=>a.source==="manual").length+1,s={index:e,name:`手工框选${i}`,source:"manual",bbox:{...t},entityCount:0},n=new Set(this.frames.map(a=>a.name));if(n.has(s.name)){let a=2;for(;n.has(`${s.name}(${a})`);)a++;s.name=`${s.name}(${a})`}this.frames.push(s),s.entityCount=this.reassignManualEntities(s);const r=this.extractFrameTitle(s);if(r&&r!==s.name&&(s.name=r,n.has(s.name))){let a=2;for(;n.has(`${s.name}(${a})`);)a++;s.name=`${s.name}(${a})`}return this.report(100,`手工框选「${s.name}」(${s.entityCount} 实体)`),s}reassignManualEntities(t){const e=t.bbox;let i=0;for(let s=0;s<this.entityBlocks.length;s++){const n=this.entityBlocks[s].bbox;if(!n)continue;const r=He(n);let a;if(r<=1e-12?a=no(e,(n.minX+n.maxX)/2,(n.minY+n.maxY)/2):a=He(er(n,e))/r>=so,!a)continue;const o=this.assignments[s];if(o!==t.index){if(o>=0){const l=this.frames.find(h=>h.index===o);l&&l.entityCount--}this.assignments[s]=t.index,i++}}return i}removeFrame(t){const e=this.frames.findIndex(i=>i.index===t);if(e<0)return!1;this.frames.splice(e,1);for(let i=0;i<this.assignments.length;i++)this.assignments[i]===t&&(this.assignments[i]=-1);return!0}updateFrameBBox(t,e){const i=this.frames.find(s=>s.index===t);if(!i||He(e)<=0)return null;i.bbox={...e};for(let s=0;s<this.assignments.length;s++)this.assignments[s]===t&&(this.assignments[s]=-1);return i.entityCount=this.reassignManualEntities(i),this.report(100,`调整图框「${i.name}」(${i.entityCount} 实体)`),i}split(t){if(this.detected||this.detectFrames(),this.frames.length===0)return[];const e=new Set(t?t.filter(u=>this.frames.some(f=>f.index===u)):this.frames.map(u=>u.index));if(e.size===0)return[];this.report(10,"组装子 DXF");const i=this.sections.find(u=>u.name==="HEADER"),s=[];if(i)for(let u=i.start;u<=i.end+1&&u<this.lines.length;u++)s.push(this.lines[u]);const n=[],r=[];let a=!1;for(const u of this.sections){if(u.name==="ENTITIES"){a=!0;continue}if(u.name==="HEADER")continue;const f=a?r:n;for(let m=u.start;m<=u.end+1&&m<this.lines.length;m++)f.push(this.lines[m])}const o=n.join(`\r
|
|
1534
1534
|
`),l=r.length?`\r
|
|
1535
1535
|
${r.join(`\r
|
|
1536
1536
|
`)}`:"",h=new Map;for(const u of e)h.set(u,[]);for(let u=0;u<this.entityBlocks.length;u++){const f=this.assignments[u];if(f>=0&&h.has(f)){const m=this.entityBlocks[u];h.get(f).push(this.lines.slice(m.start,m.end).join(`\r
|
|
1537
|
-
`))}}const d=[];for(const u of e){const f=this.frames.find(w=>w.index===u),
|
|
1537
|
+
`))}}const d=[];for(const u of e){const f=this.frames.find(w=>w.index===u),x=[i?this.rewriteHeaderExtent(s,f.bbox).join(`\r
|
|
1538
1538
|
`):"",o].filter(w=>w.length>0).join(`\r
|
|
1539
1539
|
`),g=h.get(u).join(`\r
|
|
1540
|
-
`),M=`${
|
|
1540
|
+
`),M=`${x}\r
|
|
1541
1541
|
0\r
|
|
1542
1542
|
SECTION\r
|
|
1543
1543
|
2\r
|
|
@@ -1546,6 +1546,6 @@ ${g}\r
|
|
|
1546
1546
|
0\r
|
|
1547
1547
|
ENDSEC${l}\r
|
|
1548
1548
|
0\r
|
|
1549
|
-
EOF`;d.push({frame:f,text:this.stripReactors(M)})}return this.report(100,`已生成 ${d.length} 张子 DXF`),d}rewriteHeaderExtent(t,e){const i=(e.maxX-e.minX)*.02,s=(e.maxY-e.minY)*.02,n=e.minX-i,r=e.maxX+i,a=e.minY-s,o=e.maxY+s,l=(n+r)/2,h=(a+o)/2,d=(o-a)*1.1,u=
|
|
1549
|
+
EOF`;d.push({frame:f,text:this.stripReactors(M)})}return this.report(100,`已生成 ${d.length} 张子 DXF`),d}rewriteHeaderExtent(t,e){const i=(e.maxX-e.minX)*.02,s=(e.maxY-e.minY)*.02,n=e.minX-i,r=e.maxX+i,a=e.minY-s,o=e.maxY+s,l=(n+r)/2,h=(a+o)/2,d=(o-a)*1.1,u=x=>String(Number(x.toFixed(6))),f=[];let m="";for(let x=0;x+1<t.length;x+=2){const g=t[x].trim();if(g==="9"){m=t[x+1].trim().toUpperCase(),f.push(t[x],t[x+1]);continue}if(m==="$EXTMIN"||m==="$EXTMAX"||m==="$VIEWCTR"){if(g==="10"){f.push(t[x],String(u(m==="$EXTMAX"?r:m==="$EXTMIN"?n:l)));continue}if(g==="20"){f.push(t[x],String(u(m==="$EXTMAX"?o:m==="$EXTMIN"?a:h)));continue}if(g==="30"){f.push(t[x],"0.0");continue}}if(m==="$VIEWSIZE"&&g==="40"){f.push(t[x],u(d));continue}f.push(t[x],t[x+1])}return f}stripReactors(t){const e=t.split(`\r
|
|
1550
1550
|
`),i=[];for(let s=0;s+1<e.length;s+=2){const n=e[s].trim(),r=e[s+1].trim();if(n==="102"&&(r==="{ACAD_REACTORS"||r==="{BLKREFS")){for(s+=2;s+1<e.length&&!(e[s].trim()==="102"&&e[s+1].trim()==="}");)s+=2;continue}i.push(e[s],e[s+1])}return i.join(`\r
|
|
1551
|
-
`)}scanSections(){const t=this.lines,e=t.length;let i=0;for(;i+1<e;)if(i%2===0&&t[i].trim()==="0"&&t[i+1].trim()==="SECTION"){const s=i,n=i+3<e?t[i+3].trim():"";let r=i+4;for(;r+1<e&&!(r%2===0&&t[r].trim()==="0"&&t[r+1].trim()==="ENDSEC");)r+=2;this.sections.push({name:n,start:s,end:Math.min(r,e-1)}),i=r+2}else i+=2}findSection(t){return this.sections.find(e=>e.name===t)}scanBlockDefs(){const t=this.findSection("BLOCKS");if(!t)return;const e=this.lines,i=t.end;let s=t.start+4;for(;s+1<i;)if(s%2===0&&e[s].trim()==="0"&&e[s+1].trim()==="BLOCK"){let n,r=0,a=0,o=s+2;for(;o+1<i&&!(o%2===0&&e[o].trim()==="0");){if(o%2===0){const h=parseInt(e[o],10);h===2&&n===void 0?n=e[o+1].trim():h===10?r=parseFloat(e[o+1]):h===20&&(a=parseFloat(e[o+1]))}o+=2}let l=o;for(;l+1<i&&!(l%2===0&&e[l].trim()==="0"&&e[l+1].trim()==="ENDBLK");)l+=2;if(n){const h=this.bboxOfRawRange(o,Math.min(l,i));h&&this.blockDefs.set(n,{bbox:{minX:h.minX-r,minY:h.minY-a,maxX:h.maxX-r,maxY:h.maxY-a}})}s=Math.min(l,i)+2}else s+=2}scanEntityBlocks(){const t=this.findSection("ENTITIES");if(!t)return;const e=this.lines,i=t.end;let s=t.start+4;for(;s+1<i;)if(s%2===0&&e[s].trim()==="0"){const n=e[s+1].trim();let r=s+2;if(n==="POLYLINE")for(;r+1<i;){if(r%2===0&&e[r].trim()==="0"){const a=e[r+1].trim();if(r+=2,a==="SEQEND"){for(;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;break}continue}r+=2}else if(n==="INSERT")for(;r+1<i;){if(r%2===0&&e[r].trim()==="0"){const a=e[r+1].trim();if(a==="ATTRIB"){r+=2;continue}if(a==="SEQEND"){for(r+=2;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;break}break}r+=2}else for(;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;this.entityBlocks.push({start:s,end:Math.min(r,i),type:n,bbox:null}),s=Math.min(r,i)}else s+=2;for(const n of this.entityBlocks)n.bbox=this.computeEntityBBox(n),n.type==="INSERT"&&!n.insertName&&(n.insertName=this.extractGeometry(n.start,n.end).insertName);for(const n of this.entityBlocks)if(n.bbox)if(!this.drawingBBox)this.drawingBBox={...n.bbox};else{const r=this.drawingBBox,a=n.bbox;r.minX=Math.min(r.minX,a.minX),r.minY=Math.min(r.minY,a.minY),r.maxX=Math.max(r.maxX,a.maxX),r.maxY=Math.max(r.maxY,a.maxY)}}computeEntityBBox(t){if(t.type==="POLYLINE"){const i=this.parsePolylineVertices(t);if(i.length>0)return this.bboxFromPoints(i.map(s=>s.x),i.map(s=>s.y),0)}const e=this.extractGeometry(t.start,t.end);if(t.type==="INSERT"&&e.insertName){const i=this.blockDefs.get(e.insertName),s=e.scaleX??1,n=e.scaleY??1,r=e.points[0][0]??0,a=e.points[1][0]??0;return i&&i.bbox?{minX:Math.min(r+i.bbox.minX*s,r),minY:Math.min(a+i.bbox.minY*n,a),maxX:Math.max(r+i.bbox.maxX*s,r),maxY:Math.max(a+i.bbox.maxY*n,a)}:this.bboxFromPoints([r],[a],0)}return this.bboxFromPoints(e.points[0],e.points[1],e.radius??0)}parsePolylineVertices(t){const e=this.lines,i=[];let s=!1,n=null;for(let r=t.start+2;r+1<t.end;r+=2){const a=parseInt(e[r],10),o=e[r+1].trim();if(a===0){if(o==="SEQEND")break;s=o==="VERTEX"}else s&&(a===10?n={x:parseFloat(o)}:a===20&&n&&(n.y=parseFloat(o),i.push(n),n=null))}return i}extractGeometry(t,e){const i=this.lines,s=[],n=[],r=[],a=[],o=[],l=[],h=[],d=[];let u,f,m,y,g;for(let b=t+2;b+1<e;b+=2){const C=parseInt(i[b],10);if(isNaN(C))continue;const S=i[b+1].trim();switch(C){case 10:s.push(parseFloat(S));break;case 20:n.push(parseFloat(S));break;case 11:r.push(parseFloat(S));break;case 21:a.push(parseFloat(S));break;case 13:o.push(parseFloat(S));break;case 23:l.push(parseFloat(S));break;case 14:h.push(parseFloat(S));break;case 24:d.push(parseFloat(S));break;case 40:u===void 0&&(u=parseFloat(S));break;case 41:y===void 0&&(y=parseFloat(S));break;case 42:g===void 0&&(g=parseFloat(S));break;case 70:f===void 0&&(f=parseInt(S,10));break;case 2:m===void 0&&(m=S);break}}const M=s.concat(r,o,h),w=n.concat(a,l,d);return{points:[M,w],radius:u,flags:f,insertName:m,scaleX:y,scaleY:g}}bboxFromPoints(t,e,i){const s=Math.min(t.length,e.length);if(s===0&&!(i>0))return null;let n=1/0,r=1/0,a=-1/0,o=-1/0;for(let l=0;l<s;l++){const h=t[l],d=e[l];!isFinite(h)||!isFinite(d)||(h<n&&(n=h),d<r&&(r=d),h>a&&(a=h),d>o&&(o=d))}return i>0&&s>0&&(n-=i,r-=i,a+=i,o+=i),isFinite(n)?{minX:n,minY:r,maxX:a,maxY:o}:null}bboxOfRawRange(t,e){const i=[],s=[];let n=0;const r=this.lines;for(let a=t+2;a+1<e;a+=2){if(a%2!==0)continue;const o=parseInt(r[a],10);if(isNaN(o))continue;const l=r[a+1].trim();o===10?i.push(parseFloat(l)):o===20?s.push(parseFloat(l)):o===40&&n===0&&(n=parseFloat(l)||0)}return this.bboxFromPoints(i,s,n)}collectCandidates(){const t=[],e=this.resolveMinEdge(),i=(this.options.frameKeywords??zu).map(s=>s.toUpperCase());for(const s of this.entityBlocks){if(s.type!=="INSERT"||!s.bbox)continue;const n=s.bbox.maxX-s.bbox.minX,r=s.bbox.maxY-s.bbox.minY;if(n<e||r<e)continue;const a=s.insertName??"",o=i.some(h=>a.toUpperCase().includes(h)),l=Math.min(n,r)/Math.max(n,r);(o||l>=.3)&&t.push({bbox:s.bbox,source:"insert",name:o?a:void 0})}for(const s of this.entityBlocks){if(s.type!=="LWPOLYLINE"&&s.type!=="POLYLINE"||!s.bbox)continue;if(s.type==="POLYLINE"){const o=this.parsePolylineVertices(s);if(o.length<4)continue;let l=0;for(let w=s.start+2;w+1<s.end;w+=2){const b=parseInt(this.lines[w],10),C=this.lines[w+1].trim();if(b===0&&C==="VERTEX")break;b===70&&l===0&&(l=parseInt(C,10)||0)}const h=this.drawingBBox?Math.max(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY):1e3,d=Math.max(1,h*1e-6),u=o[0],f=o[o.length-1];let m;if(Math.abs(u.x-f.x)<=d&&Math.abs(u.y-f.y)<=d)m=o.slice(0,-1);else if((l&1)!==0)m=o;else continue;if(m.length!==4)continue;let y=!0;for(let w=0;w<4;w++){const b=m[w],C=m[(w+1)%4];if(Math.abs(b.x-C.x)>d&&Math.abs(b.y-C.y)>d){y=!1;break}}if(!y)continue;const g=s.bbox.maxX-s.bbox.minX,M=s.bbox.maxY-s.bbox.minY;if(g<e||M<e)continue;t.push({bbox:s.bbox,source:"closed-polyline"});continue}const n=this.extractGeometry(s.start,s.end);if(n.flags===void 0||(n.flags&1)===0)continue;const r=s.bbox.maxX-s.bbox.minX,a=s.bbox.maxY-s.bbox.minY;r<e||a<e||t.push({bbox:s.bbox,source:"closed-polyline"})}for(const s of this.detectLineRects(e))t.push({bbox:s,source:"line-rect"});return t}resolveMinEdge(){if(this.options.minEdge!==void 0)return this.options.minEdge;if(!this.drawingBBox)return 50;const t=Math.min(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY);return Math.max(50,t*.04)}detectLineRects(t){if(!this.drawingBBox)return[];const i=Math.max(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY,1)*1e-6,s=[],n=[];for(const g of this.entityBlocks){if(g.type!=="LINE"||!g.bbox)continue;const M=this.extractGeometry(g.start,g.end),[w,b]=M.points;if(w.length<2)continue;const C=Math.abs(w[1]-w[0]),S=Math.abs(b[1]-b[0]);S<=i&&C>=t?s.push({a:Math.min(w[0],w[1]),b:Math.max(w[0],w[1]),fixed:b[0]}):C<=i&&S>=t&&n.push({a:Math.min(b[0],b[1]),b:Math.max(b[0],b[1]),fixed:w[0]})}if(s.length<2||n.length<2)return[];const r=g=>{if(g.length<=4e3)return t;const M=g.map(w=>w.b-w.a).sort((w,b)=>w-b);return Math.max(t,M[Math.floor(M.length/2)])},a=r(s),o=r(n),l=s.filter(g=>g.b-g.a>=a),h=n.filter(g=>g.b-g.a>=o),d=Math.max(i*10,a/1e3),u=new Map;for(const g of h){const M=Math.round(g.fixed/d);let w=u.get(M);w||u.set(M,w=[]),w.push(g)}const f=(g,M,w)=>{const b=Math.round(g/d);for(let C=-1;C<=1;C++){const S=u.get(b+C);if(S){for(const O of S)if(Math.abs(O.fixed-g)<=d&&O.a<=M+i&&O.b>=w-i)return O}}},m=l.slice().sort((g,M)=>M.fixed-g.fixed),y=[];for(let g=0;g<m.length;g++){const M=m[g];for(let w=g+1;w<m.length;w++){const b=m[w];if(M.fixed-b.fixed<a||Math.min(M.b,b.b)-Math.max(M.a,b.a)<Math.min(M.b-M.a,b.b-b.a)*.98-i)continue;const O=Math.max(M.a,b.a),E=Math.min(M.b,b.b);if(E-O<a)continue;const v=f(O,b.fixed,M.fixed);if(!v)continue;const T=f(E,b.fixed,M.fixed);!T||T===v||y.push({minX:Math.min(v.fixed,T.fixed),minY:b.fixed,maxX:Math.max(v.fixed,T.fixed),maxY:M.fixed})}}return y}filterAndSortCandidates(t){const e=t.filter(d=>Ne(d.bbox)>0).sort((d,u)=>{const f=d.name?0:1,m=u.name?0:1;return f!==m?f-m:Ne(u.bbox)-Ne(d.bbox)}),i=[];for(const d of e){const u=Ne(d.bbox);let f=!1;for(const m of i)if(Ne(er(m.bbox,d.bbox))/Math.min(Ne(m.bbox),u)>=ju){f=!0;break}f||i.push(d)}if(i.length===0)return[];let s=i;const n=this.options.templateGroupThreshold;if(n>0){const d=new Set,u=[],f=i.filter(m=>m.source!=="insert");for(let m=0;m<f.length;m++){if(d.has(f[m]))continue;const y=f[m].bbox,g=y.maxY-y.minY,M=[f[m]];for(let w=m+1;w<f.length;w++){if(d.has(f[w]))continue;const b=f[w].bbox,C=b.maxY-b.minY;Math.abs(g-C)>Math.min(g,C)*.01||Math.min(y.maxY,b.maxY)-Math.max(y.minY,b.minY)<Math.min(g,C)*.5||M.push(f[w])}if(M.length>=n){let w=1/0,b=-1/0;for(const C of M)d.add(C),w=Math.min(w,C.bbox.minX),b=Math.max(b,C.bbox.maxX);u.push({h:g,minX:w,maxX:b})}}if(u.length>0)for(const m of f){if(d.has(m))continue;const y=m.bbox,g=y.maxY-y.minY;for(const M of u){const w=(M.maxX-M.minX)*.05;if(Math.abs(g-M.h)<=M.h*.01&&y.minX>=M.minX-w&&y.maxX<=M.maxX+w){d.add(m);break}}}d.size>0&&(s=i.filter(m=>!d.has(m)))}if(s.length===0)return[];const r=Ne(s[0].bbox),o=s.filter(d=>Ne(d.bbox)>=r*this.options.minAreaRatio).map(d=>{const u=d.bbox;return{cand:d,cx:(u.minX+u.maxX)/2,cy:(u.minY+u.maxY)/2,h:u.maxY-u.minY}});o.sort((d,u)=>u.cy-d.cy);const l=[];for(const d of o){const u=l.find(f=>Math.abs(f[0].cy-d.cy)<=Math.min(f[0].h,d.h)*.5);u?u.push(d):l.push([d])}const h=[];for(const d of l){d.sort((u,f)=>u.cx-f.cx);for(const u of d)h.push(u.cand)}return h.map((d,u)=>({index:u,name:d.name??`图框${String(u+1).padStart(2,"0")}`,source:d.source,bbox:d.bbox,entityCount:0}))}assignEntities(t){this.assignments=new Array(this.entityBlocks.length).fill(-1);for(const e of t)e.entityCount=0;if(t.length!==0)for(let e=0;e<this.entityBlocks.length;e++){const i=this.entityBlocks[e].bbox;if(!i)continue;const s=Ne(i);let n=-1,r=0;if(s<=1e-12){const a=(i.minX+i.maxX)/2,o=(i.minY+i.maxY)/2;let l=-1;for(let h=0;h<t.length;h++)if(no(t[h].bbox,a,o)){l=h;break}n=l}else{for(let a=0;a<t.length;a++){const o=Ne(er(i,t[a].bbox));if(o<=0)continue;const l=o/s;l>r&&(r=l,n=a)}r<so&&(n=-1)}n>=0?(this.assignments[e]=t[n].index,t[n].entityCount++):this.assignments[e]=-1}}report(t,e){this.options.onProgress?.(t,e)}};x(St,"TITLE_NOISE",[/^(制图|复核|审核)(人|者)?$/,/^(日\s*期|比例|图号|设计|批准|审定|版本|阶段|专业|工程|单位|负责|会签|联动|车间)$/,/^(第)?\d+(\s*[-~—]\s*\d+)?\s*(页|张)?$/,/^\d{4}\s*年(\d{1,2}\s*月)?(\d{1,2}\s*日)?$/,/^[\d\s.,%±~—-]+$/]),x(St,"DRAWING_NO",/^[A-Za-z0-9]+(-[A-Za-z0-9]+)+$/);let br=St;class Pi{constructor(t,e){x(this,"current");x(this,"next");x(this,"inNormal");x(this,"outNormal");this.current=t,this.next=e,this.inNormal=this.inwardsNormal(),this.outNormal=this.outwardsNormal()}outwardsNormal(){const t=this.inwardsNormal();return[-t[0],-t[1]]}inwardsNormal(){const t=this.next[0]-this.current[0],e=this.next[1]-this.current[1],i=Math.sqrt(t*t+e*e);if(i===0)throw new Error("Vertices overlap");return[-e/i,t/i]}offset(t,e){return Pi.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return Pi.offsetEdge(this.next,this.current,t,e)}inverse(){return new Pi(this.next,this.current)}static offsetEdge(t,e,i,s){return new Pi([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const Qi=Array.isArray,ro=(c,t)=>c[0]===t[0]&&c[1]===t[1],tr=c=>Array.isArray(c)&&c.length,ll=(c,t=0,e=!1)=>{let i,s;if(tr(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&&tr(c)&&tr(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 Hu{constructor(t,e=5){x(this,"vertices");x(this,"edges");x(this,"arcSegments");x(this,"distance");if(this.distance=0,this.arcSegments=e,!Qi(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],Qi(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(Qi(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,ro(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new Pi(t[i],t[(i+1)%s]));else for(t=t,e=e,i=0,s=t.length;i<s;i++)e.push([]),this.processContour(t[i],e[e.length-1])}setArcSegments(t){return this.arcSegments=t,this}createArc(t,e,i,s,n,r,a){const o=Math.PI*2;let l=Math.atan2(s[1]-e[1],s[0]-e[0]),h=Math.atan2(n[1]-e[1],n[0]-e[0]);r%2===0&&(r-=1),l<0&&(l+=o),h<0&&(h+=o);let d=l>h?l-h:l+o-h;const u=(a?-d:o-d)/r;t.push(s);for(let f=1;f<r;++f)d=l+u*f,t.push([e[0]+Math.cos(d)*i,e[1]+Math.sin(d)*i]);return t.push(n),t}setDistance(t){return this.distance=t,this}ensureLastPoint(t){return ro(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const n=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],r=[];for(let a=0,o=2;a<o;a++){const l=n[a],h=n[(a+o-1)%o];this.createArc(r,a===0?t:e,s,h.next,l.current,this.arcSegments,!0)}return r}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Ui.union(this.vertices,e),e}padding(t){if(this.setDistance(t),this.distance===0)return this.vertices;if(this.vertices.length===2&&typeof this.vertices[0]=="number")return this.vertices;const e=this.offsetLines(this.distance);return Ui.difference(this.vertices,e)}offsetLine(t){return t===0?this.vertices:this.offsetLines(t)}offsetLines(t){if(t<0)throw new Error("Cannot apply negative margin to the line");this.setDistance(t);let e=[];if(Qi(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,n=this.edges.length;s<n;s++){const r=this.offsetContour(this.vertices[s],this.edges[s]);r.length>0&&i.push(r)}i.length>0&&(e=i.length===1?i[0]:Ui.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,n=0;if(Qi(t[0])&&typeof t[0][0]=="number"){for(s=0,n=t.length-1;s<n;s++){const r=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[r];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Ui.union(i[0],i.slice(1)))}else{const r=[];for(s=0,n=e.length;s<n;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&r.push(a)}r.length>0&&(i=r.length===1?r[0]:Ui.union(r[0],...r.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,n=this.distance;let r=0;e%2===0&&e++;for(let a=0;a<e;a++)r+=2*Math.PI/e,i.push([s[0]+n*Math.cos(r),s[1]+n*Math.sin(r)]);return[[this.ensureLastPoint(i)]]}}class cl{constructor(t){x(this,"viewer");x(this,"composerEnabled");x(this,"composer");x(this,"renderPass");x(this,"effectFxaaPass");x(this,"saoPass");x(this,"ssaoPass");x(this,"outlinePass");x(this,"ssaaRenderPass");x(this,"bloomPass");x(this,"unrealBloomPass");x(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Wl.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(ce.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 Yl.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 Xl.ShaderPass(tc.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 Zl.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 Kl.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 $l.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 Jl.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 Ql.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 ec.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 Ar)if(t&&!s.edges){const n=s.getModelObject();n&&(A.debug("[Viewer] Generating outlines for model '"+n.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(n=>n.visible=t);else s instanceof Br&&A.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 ic.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 Gu extends bn{constructor(e,i){super(e);x(this,"name");x(this,"loadedModels");x(this,"distanceCullingFactor");x(this,"selectedObject");x(this,"effect");if(this.name=Qe.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(bt.Perspective),this.cameraManager.setNavigationMode(ht.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===et.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===et.Left&&this.handleAnchorPoint(h)}),this.inputManager.addEventListener("pointermove",u=>{i!==void 0&&(e=!o(u),i===et.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===et.Left?l(u)?(h?.object?this.flyToObject(h.object):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.selectedObject instanceof Ht?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h?.object&&!d&&this.handleClickObject(h.object)):(u.button,et.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=Fe.t("ProgressBar.Loading"),l=f=>{this.progressBar?.updateProgress(a,o,f),i?.(new ProgressEvent("LoadProgress",{loaded:f,total:100}))};let h=!1;const d=(f,m,y)=>{let g=f.loaded*100/f.total;g=g*(y-m)/100+m,g>y&&(h||(A.warn("[Progress] Invalid ProgressEvent:",f),h=!0),g=y),this.progressBar?.updateProgress(a,o,g),i?.(new ProgressEvent("LoadProgress",{loaded:g,total:100}))},u=f=>d(f,0,50);this.progressBar?.addProgressItem(a),l(0);try{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 b=new p.Matrix4;b.elements=e.matrix,f.applyMatrix4(b)}const m=this.getUniqueModelId(e.modelId||e.src),y=new Ar({modelId:m,object:f});this.addModel(y),l(90);const g=y.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const w=new p.Vector3;g.getCenter(w),this.cameraManager.setOrbitPoint(w),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(ce.ModelLoad)}catch(f){throw this.progressBar?.removeProgressItem(a),A.error("[Viewer3d] Failed to load model '"+e.src+"'",f),f}finally{this.spinner.decreaseJobCount()}}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(n=>n.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function ao(c){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),c)}function oo(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 qu(c){const t={transform:new p.Matrix4,boundingVolume:new p.Box3};return Object.assign(Object.assign({},t),c)}class Wu{constructor(t){x(this,"url");x(this,"metadata");x(this,"statistics");x(this,"view");this.url=t,this.metadata=ao(),this.statistics=oo(),this.view=qu()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(A.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=ao(t.metadata),this.statistics=oo(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 Yu=0;class Xu extends bn{constructor(e,i){super(e);x(this,"name");x(this,"pickUsageScene");x(this,"effect");x(this,"loadedModels");x(this,"selectedObject");x(this,"enableHoverEffect");if(this.name=Qe.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(bt.Perspective),this.cameraManager.setNavigationMode(ht.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(ce.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===et.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===et.Left){let m=this.pickUsageScene;if(h){const g=this.loadedModels.find(M=>M.modelId===""+h?.tilesetId);if(g){const M=g.getObjectByUserId(h.userId);M&&(m=M)}}const y=this.pickManager.pickObject(f,[m]);this.handleAnchorPoint(y)}}),this.inputManager.addEventListener("pointermove",u=>{if(i!==void 0)e=!o(u),i===et.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),y=this.getHoveredObject();m?(!y||y.tilesetId!==m.tilesetId||y.userId!==m.userId)&&this.setObjectHoveredByUserId(m.tilesetId,m.userId,!0):y&&this.clearHovered()}this.handleMouseMove(u)}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===et.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,et.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){A.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){A.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(n=>n.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new Wu(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();try{const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Br({modelId:""+Yu++,bbox:a},r,s),l=o.getTilesRenderer(),h=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=d=>{d.traverse(u=>{!it&&u.matrixAutoUpdate&&(u.matrixAutoUpdate=it,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.dispatchEvent(ce.ModelLoad),Promise.resolve()}return Promise.reject()}finally{this.spinner.decreaseJobCount()}}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 Zu extends Gt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();x(this,"id");x(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}J.install({THREE:p});class Ku extends J{constructor(e,i){super(e,i);x(this,"minZoom");x(this,"draggingSmoothTime");x(this,"dollySpeedBackup");x(this,"azimuthRotateSpeedBackup");x(this,"polarRotateSpeedBackup");x(this,"truckSpeedBackup");x(this,"onKeyDown");x(this,"onKeyUp");x(this,"keyTruckSpeed");x(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 $u{constructor(t,e,i){x(this,"containerOrCanvas");x(this,"glContext");x(this,"camera");x(this,"scene");x(this,"renderer");x(this,"renderTarget");x(this,"controls");x(this,"selectedObject");x(this,"loadedModels");x(this,"pmremGenerator");x(this,"clock");x(this,"viewerMode");x(this,"raycaster");x(this,"savedMaterialsForOpacity");x(this,"jobCount");x(this,"bbox");x(this,"outlineMaterial");x(this,"outlineRoot");x(this,"transparentObjectIds");x(this,"requestAnimationFrameHandle");x(this,"applyOptionsAndAddToScene");x(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(A.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 Q.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,A.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(),A.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new p.Scene;return t.background=new p.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});let i;try{i=new p.WebGLRenderer(t)}catch(s){if(e||!t.antialias)throw s;i=new p.WebGLRenderer({canvas:this.containerOrCanvas}),A.warn("WebGL context created with fallback settings (antialias disabled).")}if(e){const s=this.containerOrCanvas.width,n=this.containerOrCanvas.height;A.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 Ku(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 Ut().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 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,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,A.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&&Q.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity);const l=Q.setObjectOpacityById(n,o,e,i,s);r.push(...l)}else this.savedMaterialsForOpacity&&Q.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=_e.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=_e.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(Nt);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=ve.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=Pt.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;A.info("[Viewer] flyTo: ",N.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){ds.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=>N.numberToString(f);A.info("[Viewer] BBox's longest side is: "+u(o)),i>h&&(A.warn("[Viewer] camera.near("+u(i)+") shouldn't bigger than "+u(h)+", will change it!"),t.near=h),s<d&&(A.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;Q.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||(A.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(h=>{if(Fr.includes(r.id,Fr.get(h.userData,"UniqueId"))){const d=this.getMeshes(h);n=n.concat(d)}})}),n.length>0){n.forEach(a=>{const o=Q.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;Q.revertAppliedMaterialToObjectById(this.scene,o,r)}),this.transparentObjectIds=r,this.flyToObjects(n)}else A.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)},Ju=()=>fl()!==dl?(pl(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>L.Mesh});exports.BaseDxfCompareHelper=ol;exports.BaseViewer=bn;exports.BimTilesModel=Br;exports.BimTilesRenderer=Wo;exports.BimTilesViewer=Xu;exports.BinaryReader=ys;exports.BoxSelectHelper=mn;exports.ByBlock=us;exports.ByLayer=Pr;exports.CSS2DObjectUtils=_h;exports.CameraProjection=bt;exports.CancelablePromise=Sh;exports.CanvasRender=ms;exports.ColorUtils=Di;exports.CommonUtils=N;exports.CompareDrawable=wt;exports.Container=kr;exports.ControlsMode=ht;exports.CoordinateUtils=_e;exports.DecimalPrecisionRange=go;exports.DefaultCameraFar=rn;exports.DefaultCameraFov=bo;exports.DefaultCameraNear=nn;exports.DefaultLanguage=yo;exports.DefaultOpacity=Or;exports.DefaultViewer3dConfig=lu;exports.DeviceUtils=ke;exports.Drawable=Ht;exports.DrawableList=gs;exports.DxfChangeType=He;exports.DxfCompare=ct;exports.DxfCompareHelper=Fu;exports.DxfCompareMarkupManager=yr;exports.DxfLoader=Z;exports.DxfParser=Lo;exports.DxfRenderOrder=be;exports.DxfSplitter=br;exports.DxfUtils=Tt;exports.EdgeUtils=wo;exports.Event=Gt;exports.ExportUtils=fr;exports.FontManager=xt;exports.FpsUtils=Rh;exports.GenerateMeshBvhWorker=tl;exports.GeometryUtils=G;exports.GroundPlaneRenderOrder=al;exports.HighlightColor=Er;exports.HighlightColorRgba=Ah;exports.IconfontClass=Ih;exports.IconfontClass2=Bh;exports.InputManager=rl;exports.InstantiateHelper=gu;exports.LayerForHitableObjects=xo;exports.LayerForSelectableObjects=Nt;exports.LayerForSnapableObjects=Ge;exports.Line=rc;exports.LinePatternShaders=Io;exports.LoadingHelper=Ut;exports.MaterialUtils=ve;exports.MathUtils=V;exports.MatrixAutoUpdate=it;exports.MergeUtils=me;exports.MeshBvhHelper=Lr;exports.MobileTouchHelperDrawable=ku;exports.Model=xn;exports.Model2d=Li;exports.Model3d=Ar;exports.NestedCompareTypes=ss;exports.OSnapHelper=_u;exports.OSnapIconSize=qh;exports.OSnapMarkerType=Ot;exports.OSnapType=il;exports.ObjectPixelSizeHelper=vu;exports.ObjectUtils=Q;exports.Offset=Hu;exports.OrbitControls=Zo;exports.OutlineColorRgba=sn;exports.PickMarkupHelper=Pu;exports.PlanControls=Ko;exports.Plugin=Zu;exports.Points=lh;exports.PolygonUtils=Hh;exports.ProgressBar=Dr;exports.RafHelper=Qo;exports.SVGObjectUtils=Wh;exports.SceneUtils=Pt;exports.SectionUtils=Vt;exports.ShaderChunk=Ch;exports.SimplifyUtils=Gh;exports.SnapDrawable=Pe;exports.Spinner=Yo;exports.TextSearchHelper=xr;exports.TextureUtils=ds;exports.ThresholdAngleForEdge=_r;exports.UnitConversionByMeter=pr;exports.UnitLabels=To;exports.UnitScaleConversion=od;exports.UnitScaleToMeter=gr;exports.Units=Je;exports.Viewer2d=Rr;exports.Viewer3d=Gu;exports.Viewer3dLite=$u;exports.Viewer3dUtils=Zh;exports.ViewerEvent=ce;exports.ViewerMode=hl;exports.ViewerName=Qe;exports.Views=So;exports.ZoomToRectHelper=nl;exports.bspline=Oo;exports.checkIsNewVersion=Ju;exports.cn=Mo;exports.createHatchPatternShaderMaterial=Bo;exports.decodeDxfTextCharacterCodes=_o;exports.decodeDxfTextMbcsCharacterCodes=Ao;exports.decodeDxfTextUnicodeCodePoints=Po;exports.en=vo;exports.getLengthValueByUnit=Xh;exports.getUnitStr=mr;exports.getVersionFromLocalStorage=fl;exports.i18n=Fe;exports.log=A;exports.parseDxfMTextContent=ns;exports.parseDxfTextContent=an;exports.round10=Eo;exports.setIcon=Oh;exports.setLogLevel=mo;exports.setVersionToLocalStorage=pl;exports.showPrecisionValue=Ph;
|
|
1551
|
+
`)}scanSections(){const t=this.lines,e=t.length;let i=0;for(;i+1<e;)if(i%2===0&&t[i].trim()==="0"&&t[i+1].trim()==="SECTION"){const s=i,n=i+3<e?t[i+3].trim():"";let r=i+4;for(;r+1<e&&!(r%2===0&&t[r].trim()==="0"&&t[r+1].trim()==="ENDSEC");)r+=2;this.sections.push({name:n,start:s,end:Math.min(r,e-1)}),i=r+2}else i+=2}findSection(t){return this.sections.find(e=>e.name===t)}scanBlockDefs(){const t=this.findSection("BLOCKS");if(!t)return;const e=this.lines,i=t.end;let s=t.start+4;for(;s+1<i;)if(s%2===0&&e[s].trim()==="0"&&e[s+1].trim()==="BLOCK"){let n,r=0,a=0,o=s+2;for(;o+1<i&&!(o%2===0&&e[o].trim()==="0");){if(o%2===0){const h=parseInt(e[o],10);h===2&&n===void 0?n=e[o+1].trim():h===10?r=parseFloat(e[o+1]):h===20&&(a=parseFloat(e[o+1]))}o+=2}let l=o;for(;l+1<i&&!(l%2===0&&e[l].trim()==="0"&&e[l+1].trim()==="ENDBLK");)l+=2;if(n){const h=this.bboxOfRawRange(o,Math.min(l,i));h&&this.blockDefs.set(n,{bbox:{minX:h.minX-r,minY:h.minY-a,maxX:h.maxX-r,maxY:h.maxY-a}})}s=Math.min(l,i)+2}else s+=2}scanEntityBlocks(){const t=this.findSection("ENTITIES");if(!t)return;const e=this.lines,i=t.end;let s=t.start+4;for(;s+1<i;)if(s%2===0&&e[s].trim()==="0"){const n=e[s+1].trim();let r=s+2;if(n==="POLYLINE")for(;r+1<i;){if(r%2===0&&e[r].trim()==="0"){const a=e[r+1].trim();if(r+=2,a==="SEQEND"){for(;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;break}continue}r+=2}else if(n==="INSERT")for(;r+1<i;){if(r%2===0&&e[r].trim()==="0"){const a=e[r+1].trim();if(a==="ATTRIB"){r+=2;continue}if(a==="SEQEND"){for(r+=2;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;break}break}r+=2}else for(;r+1<i&&!(r%2===0&&e[r].trim()==="0");)r+=2;this.entityBlocks.push({start:s,end:Math.min(r,i),type:n,bbox:null}),s=Math.min(r,i)}else s+=2;for(const n of this.entityBlocks)n.bbox=this.computeEntityBBox(n),n.type==="INSERT"&&!n.insertName&&(n.insertName=this.extractGeometry(n.start,n.end).insertName);for(const n of this.entityBlocks)if(n.bbox)if(!this.drawingBBox)this.drawingBBox={...n.bbox};else{const r=this.drawingBBox,a=n.bbox;r.minX=Math.min(r.minX,a.minX),r.minY=Math.min(r.minY,a.minY),r.maxX=Math.max(r.maxX,a.maxX),r.maxY=Math.max(r.maxY,a.maxY)}}computeEntityBBox(t){if(t.type==="POLYLINE"){const i=this.parsePolylineVertices(t);if(i.length>0)return this.bboxFromPoints(i.map(s=>s.x),i.map(s=>s.y),0)}const e=this.extractGeometry(t.start,t.end);if(t.type==="INSERT"&&e.insertName){const i=this.blockDefs.get(e.insertName),s=e.scaleX??1,n=e.scaleY??1,r=e.points[0][0]??0,a=e.points[1][0]??0;return i&&i.bbox?{minX:Math.min(r+i.bbox.minX*s,r),minY:Math.min(a+i.bbox.minY*n,a),maxX:Math.max(r+i.bbox.maxX*s,r),maxY:Math.max(a+i.bbox.maxY*n,a)}:this.bboxFromPoints([r],[a],0)}return this.bboxFromPoints(e.points[0],e.points[1],e.radius??0)}parsePolylineVertices(t){const e=this.lines,i=[];let s=!1,n=null;for(let r=t.start+2;r+1<t.end;r+=2){const a=parseInt(e[r],10),o=e[r+1].trim();if(a===0){if(o==="SEQEND")break;s=o==="VERTEX"}else s&&(a===10?n={x:parseFloat(o)}:a===20&&n&&(n.y=parseFloat(o),i.push(n),n=null))}return i}extractGeometry(t,e){const i=this.lines,s=[],n=[],r=[],a=[],o=[],l=[],h=[],d=[];let u,f,m,x,g;for(let b=t+2;b+1<e;b+=2){const C=parseInt(i[b],10);if(isNaN(C))continue;const S=i[b+1].trim();switch(C){case 10:s.push(parseFloat(S));break;case 20:n.push(parseFloat(S));break;case 11:r.push(parseFloat(S));break;case 21:a.push(parseFloat(S));break;case 13:o.push(parseFloat(S));break;case 23:l.push(parseFloat(S));break;case 14:h.push(parseFloat(S));break;case 24:d.push(parseFloat(S));break;case 40:u===void 0&&(u=parseFloat(S));break;case 41:x===void 0&&(x=parseFloat(S));break;case 42:g===void 0&&(g=parseFloat(S));break;case 70:f===void 0&&(f=parseInt(S,10));break;case 2:m===void 0&&(m=S);break}}const M=s.concat(r,o,h),w=n.concat(a,l,d);return{points:[M,w],radius:u,flags:f,insertName:m,scaleX:x,scaleY:g}}bboxFromPoints(t,e,i){const s=Math.min(t.length,e.length);if(s===0&&!(i>0))return null;let n=1/0,r=1/0,a=-1/0,o=-1/0;for(let l=0;l<s;l++){const h=t[l],d=e[l];!isFinite(h)||!isFinite(d)||(h<n&&(n=h),d<r&&(r=d),h>a&&(a=h),d>o&&(o=d))}return i>0&&s>0&&(n-=i,r-=i,a+=i,o+=i),isFinite(n)?{minX:n,minY:r,maxX:a,maxY:o}:null}bboxOfRawRange(t,e){const i=[],s=[];let n=0;const r=this.lines;for(let a=t+2;a+1<e;a+=2){if(a%2!==0)continue;const o=parseInt(r[a],10);if(isNaN(o))continue;const l=r[a+1].trim();o===10?i.push(parseFloat(l)):o===20?s.push(parseFloat(l)):o===40&&n===0&&(n=parseFloat(l)||0)}return this.bboxFromPoints(i,s,n)}collectCandidates(){const t=[],e=this.resolveMinEdge(),i=(this.options.frameKeywords??zu).map(s=>s.toUpperCase());for(const s of this.entityBlocks){if(s.type!=="INSERT"||!s.bbox)continue;const n=s.bbox.maxX-s.bbox.minX,r=s.bbox.maxY-s.bbox.minY;if(n<e||r<e)continue;const a=s.insertName??"",o=i.some(h=>a.toUpperCase().includes(h)),l=Math.min(n,r)/Math.max(n,r);(o||l>=.3)&&t.push({bbox:s.bbox,source:"insert",name:o?a:void 0})}for(const s of this.entityBlocks){if(s.type!=="LWPOLYLINE"&&s.type!=="POLYLINE"||!s.bbox)continue;if(s.type==="POLYLINE"){const o=this.parsePolylineVertices(s);if(o.length<4)continue;let l=0;for(let w=s.start+2;w+1<s.end;w+=2){const b=parseInt(this.lines[w],10),C=this.lines[w+1].trim();if(b===0&&C==="VERTEX")break;b===70&&l===0&&(l=parseInt(C,10)||0)}const h=this.drawingBBox?Math.max(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY):1e3,d=Math.max(1,h*1e-6),u=o[0],f=o[o.length-1];let m;if(Math.abs(u.x-f.x)<=d&&Math.abs(u.y-f.y)<=d)m=o.slice(0,-1);else if((l&1)!==0)m=o;else continue;if(m.length!==4)continue;let x=!0;for(let w=0;w<4;w++){const b=m[w],C=m[(w+1)%4];if(Math.abs(b.x-C.x)>d&&Math.abs(b.y-C.y)>d){x=!1;break}}if(!x)continue;const g=s.bbox.maxX-s.bbox.minX,M=s.bbox.maxY-s.bbox.minY;if(g<e||M<e)continue;t.push({bbox:s.bbox,source:"closed-polyline"});continue}const n=this.extractGeometry(s.start,s.end);if(n.flags===void 0||(n.flags&1)===0)continue;const r=s.bbox.maxX-s.bbox.minX,a=s.bbox.maxY-s.bbox.minY;r<e||a<e||t.push({bbox:s.bbox,source:"closed-polyline"})}for(const s of this.detectLineRects(e))t.push({bbox:s,source:"line-rect"});return t}resolveMinEdge(){if(this.options.minEdge!==void 0)return this.options.minEdge;if(!this.drawingBBox)return 50;const t=Math.min(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY);return Math.max(50,t*.04)}detectLineRects(t){if(!this.drawingBBox)return[];const i=Math.max(this.drawingBBox.maxX-this.drawingBBox.minX,this.drawingBBox.maxY-this.drawingBBox.minY,1)*1e-6,s=[],n=[];for(const g of this.entityBlocks){if(g.type!=="LINE"||!g.bbox)continue;const M=this.extractGeometry(g.start,g.end),[w,b]=M.points;if(w.length<2)continue;const C=Math.abs(w[1]-w[0]),S=Math.abs(b[1]-b[0]);S<=i&&C>=t?s.push({a:Math.min(w[0],w[1]),b:Math.max(w[0],w[1]),fixed:b[0]}):C<=i&&S>=t&&n.push({a:Math.min(b[0],b[1]),b:Math.max(b[0],b[1]),fixed:w[0]})}if(s.length<2||n.length<2)return[];const r=g=>{if(g.length<=4e3)return t;const M=g.map(w=>w.b-w.a).sort((w,b)=>w-b);return Math.max(t,M[Math.floor(M.length/2)])},a=r(s),o=r(n),l=s.filter(g=>g.b-g.a>=a),h=n.filter(g=>g.b-g.a>=o),d=Math.max(i*10,a/1e3),u=new Map;for(const g of h){const M=Math.round(g.fixed/d);let w=u.get(M);w||u.set(M,w=[]),w.push(g)}const f=(g,M,w)=>{const b=Math.round(g/d);for(let C=-1;C<=1;C++){const S=u.get(b+C);if(S){for(const O of S)if(Math.abs(O.fixed-g)<=d&&O.a<=M+i&&O.b>=w-i)return O}}},m=l.slice().sort((g,M)=>M.fixed-g.fixed),x=[];for(let g=0;g<m.length;g++){const M=m[g];for(let w=g+1;w<m.length;w++){const b=m[w];if(M.fixed-b.fixed<a||Math.min(M.b,b.b)-Math.max(M.a,b.a)<Math.min(M.b-M.a,b.b-b.a)*.98-i)continue;const O=Math.max(M.a,b.a),E=Math.min(M.b,b.b);if(E-O<a)continue;const v=f(O,b.fixed,M.fixed);if(!v)continue;const T=f(E,b.fixed,M.fixed);!T||T===v||x.push({minX:Math.min(v.fixed,T.fixed),minY:b.fixed,maxX:Math.max(v.fixed,T.fixed),maxY:M.fixed})}}return x}filterAndSortCandidates(t){const e=t.filter(d=>He(d.bbox)>0).sort((d,u)=>{const f=d.name?0:1,m=u.name?0:1;return f!==m?f-m:He(u.bbox)-He(d.bbox)}),i=[];for(const d of e){const u=He(d.bbox);let f=!1;for(const m of i)if(He(er(m.bbox,d.bbox))/Math.min(He(m.bbox),u)>=ju){f=!0;break}f||i.push(d)}if(i.length===0)return[];let s=i;const n=this.options.templateGroupThreshold;if(n>0){const d=new Set,u=[],f=i.filter(m=>m.source!=="insert");for(let m=0;m<f.length;m++){if(d.has(f[m]))continue;const x=f[m].bbox,g=x.maxY-x.minY,M=[f[m]];for(let w=m+1;w<f.length;w++){if(d.has(f[w]))continue;const b=f[w].bbox,C=b.maxY-b.minY;Math.abs(g-C)>Math.min(g,C)*.01||Math.min(x.maxY,b.maxY)-Math.max(x.minY,b.minY)<Math.min(g,C)*.5||M.push(f[w])}if(M.length>=n){let w=1/0,b=-1/0;for(const C of M)d.add(C),w=Math.min(w,C.bbox.minX),b=Math.max(b,C.bbox.maxX);u.push({h:g,minX:w,maxX:b})}}if(u.length>0)for(const m of f){if(d.has(m))continue;const x=m.bbox,g=x.maxY-x.minY;for(const M of u){const w=(M.maxX-M.minX)*.05;if(Math.abs(g-M.h)<=M.h*.01&&x.minX>=M.minX-w&&x.maxX<=M.maxX+w){d.add(m);break}}}d.size>0&&(s=i.filter(m=>!d.has(m)))}if(s.length===0)return[];const r=He(s[0].bbox),o=s.filter(d=>He(d.bbox)>=r*this.options.minAreaRatio).map(d=>{const u=d.bbox;return{cand:d,cx:(u.minX+u.maxX)/2,cy:(u.minY+u.maxY)/2,h:u.maxY-u.minY}});o.sort((d,u)=>u.cy-d.cy);const l=[];for(const d of o){const u=l.find(f=>Math.abs(f[0].cy-d.cy)<=Math.min(f[0].h,d.h)*.5);u?u.push(d):l.push([d])}const h=[];for(const d of l){d.sort((u,f)=>u.cx-f.cx);for(const u of d)h.push(u.cand)}return h.map((d,u)=>({index:u,name:d.name??`图框${String(u+1).padStart(2,"0")}`,source:d.source,bbox:d.bbox,entityCount:0}))}assignEntities(t){this.assignments=new Array(this.entityBlocks.length).fill(-1);for(const e of t)e.entityCount=0;if(t.length!==0)for(let e=0;e<this.entityBlocks.length;e++){const i=this.entityBlocks[e].bbox;if(!i)continue;const s=He(i);let n=-1,r=0;if(s<=1e-12){const a=(i.minX+i.maxX)/2,o=(i.minY+i.maxY)/2;let l=-1;for(let h=0;h<t.length;h++)if(no(t[h].bbox,a,o)){l=h;break}n=l}else{for(let a=0;a<t.length;a++){const o=He(er(i,t[a].bbox));if(o<=0)continue;const l=o/s;l>r&&(r=l,n=a)}r<so&&(n=-1)}n>=0?(this.assignments[e]=t[n].index,t[n].entityCount++):this.assignments[e]=-1}}report(t,e){this.options.onProgress?.(t,e)}};y(Oe,"TITLE_NOISE",[/^(制图|复核|审核)(人|者)?$/,/^(日\s*期|比例|图号|设计|批准|审定|版本|阶段|专业|工程|单位|负责|会签|联动|车间)$/,/^(订正|修[改正]|变[更换更]|作废|替换|版[本次])$/,/^(第)?\d+(\s*[-~—]\s*\d+)?\s*(页|张)?$/,/^\d{4}\s*年(\d{1,2}\s*月)?(\d{1,2}\s*日)?$/,/^[\d\s.,%±~—-]+$/]),y(Oe,"DRAWING_NO",/^[A-Za-z0-9]+(-[A-Za-z0-9]+)+$/),y(Oe,"ORG_NAME",/(铁路|局|集团|公司|院|所|段|中心|处|厂)/),y(Oe,"gbkDecoder");let br=Oe;class _i{constructor(t,e){y(this,"current");y(this,"next");y(this,"inNormal");y(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 _i.offsetEdge(this.current,this.next,t,e)}inverseOffset(t,e){return _i.offsetEdge(this.next,this.current,t,e)}inverse(){return new _i(this.next,this.current)}static offsetEdge(t,e,i,s){return new _i([t[0]+i,t[1]+s],[e[0]+i,e[1]+s])}}const Qi=Array.isArray,ro=(c,t)=>c[0]===t[0]&&c[1]===t[1],tr=c=>Array.isArray(c)&&c.length,ll=(c,t=0,e=!1)=>{let i,s;if(tr(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&&tr(c)&&tr(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 Hu{constructor(t,e=5){y(this,"vertices");y(this,"edges");y(this,"arcSegments");y(this,"distance");if(this.distance=0,this.arcSegments=e,!Qi(t))throw new Error("Offset requires at least one coodinate to work with");this.edges=[],Qi(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(Qi(t[0])&&typeof t[0][0]=="number")for(t=t,e=e,s=t.length,ro(t[0],t[s-1])&&(s-=1),i=0;i<s;i++)e.push(new _i(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 ro(t[0],t[t.length-1])||t.push([t[0][0],t[0][1]]),t}offset(t){return this.setDistance(t),this.distance===0?this.vertices:this.distance>0?this.margin(this.distance):this.padding(-this.distance)}offsetSegment(t,e,i,s){const n=[i.offset(i.inNormal[0]*s,i.inNormal[1]*s),i.inverseOffset(i.outNormal[0]*s,i.outNormal[1]*s)],r=[];for(let a=0,o=2;a<o;a++){const l=n[a],h=n[(a+o-1)%o];this.createArc(r,a===0?t:e,s,h.next,l.current,this.arcSegments,!0)}return r}margin(t){if(this.setDistance(t),typeof this.vertices[0]=="number")return this.offsetPoint(this.distance);if(t===0)return this.vertices;let e=this.offsetLines(this.distance);return e=Ui.union(this.vertices,e),e}padding(t){if(this.setDistance(t),this.distance===0)return this.vertices;if(this.vertices.length===2&&typeof this.vertices[0]=="number")return this.vertices;const e=this.offsetLines(this.distance);return Ui.difference(this.vertices,e)}offsetLine(t){return t===0?this.vertices:this.offsetLines(t)}offsetLines(t){if(t<0)throw new Error("Cannot apply negative margin to the line");this.setDistance(t);let e=[];if(Qi(this.vertices[0])&&typeof this.vertices[0][0]!="number"){const i=[];for(let s=0,n=this.edges.length;s<n;s++){const r=this.offsetContour(this.vertices[s],this.edges[s]);r.length>0&&i.push(r)}i.length>0&&(e=i.length===1?i[0]:Ui.union(i[0],...i.slice(1)))}else e=this.vertices.length===1?this.offsetPoint(t):this.offsetContour(this.vertices,this.edges);return e}offsetContour(t,e){let i=[],s=0,n=0;if(Qi(t[0])&&typeof t[0][0]=="number"){for(s=0,n=t.length-1;s<n;s++){const r=this.ensureLastPoint(this.offsetSegment(t[s],t[s+1],e[s],this.distance)),a=[r];i.push(a)}i.length>0&&(i=i.length===1?[i[0]]:Ui.union(i[0],i.slice(1)))}else{const r=[];for(s=0,n=e.length;s<n;s++){const a=this.offsetContour(t[s],e[s]);a.length>0&&r.push(a)}r.length>0&&(i=r.length===1?r[0]:Ui.union(r[0],...r.slice(1)))}return i}offsetPoint(t){this.setDistance(t);let e=this.arcSegments*2;const i=[],s=this.vertices,n=this.distance;let r=0;e%2===0&&e++;for(let a=0;a<e;a++)r+=2*Math.PI/e,i.push([s[0]+n*Math.cos(r),s[1]+n*Math.sin(r)]);return[[this.ensureLastPoint(i)]]}}class cl{constructor(t){y(this,"viewer");y(this,"composerEnabled");y(this,"composer");y(this,"renderPass");y(this,"effectFxaaPass");y(this,"saoPass");y(this,"ssaoPass");y(this,"outlinePass");y(this,"ssaaRenderPass");y(this,"bloomPass");y(this,"unrealBloomPass");y(this,"vertexNormalsHelpers");this.composerEnabled=!0,this.viewer=t,this.composer=new Wl.EffectComposer(this.viewer.renderer),this.viewer.addEventListener(ce.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 Yl.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 Xl.ShaderPass(tc.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 Zl.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 Kl.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 $l.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 Jl.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 Ql.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 ec.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 Ar)if(t&&!s.edges){const n=s.getModelObject();n&&(A.debug("[Viewer] Generating outlines for model '"+n.id+"'"),s.enableOutline(t))}else s.edges&&s.edges.forEach(n=>n.visible=t);else s instanceof Br&&A.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 ic.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 Gu extends bn{constructor(e,i){super(e);y(this,"name");y(this,"loadedModels");y(this,"distanceCullingFactor");y(this,"selectedObject");y(this,"effect");if(this.name=et.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(wt.Perspective),this.cameraManager.setNavigationMode(dt.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===tt.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===tt.Left&&this.handleAnchorPoint(h)}),this.inputManager.addEventListener("pointermove",u=>{i!==void 0&&(e=!o(u),i===tt.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===tt.Left?l(u)?(h?.object?this.flyToObject(h.object):this.viewFitAll(),s=0,n=-1,r=-1):(this.selectedObject&&(this.selectedObject instanceof Ht?this.selectedObject.selected=!1:this.clearHighlight(),this.selectedObject=void 0),s=u.timestamp,n=u.x,r=u.y,h?.object&&!d&&this.handleClickObject(h.object)):(u.button,tt.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=ze.t("ProgressBar.Loading"),l=f=>{this.progressBar?.updateProgress(a,o,f),i?.(new ProgressEvent("LoadProgress",{loaded:f,total:100}))};let h=!1;const d=(f,m,x)=>{let g=f.loaded*100/f.total;g=g*(x-m)/100+m,g>x&&(h||(A.warn("[Progress] Invalid ProgressEvent:",f),h=!0),g=x),this.progressBar?.updateProgress(a,o,g),i?.(new ProgressEvent("LoadProgress",{loaded:g,total:100}))},u=f=>d(f,0,50);this.progressBar?.addProgressItem(a),l(0);try{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 b=new p.Matrix4;b.elements=e.matrix,f.applyMatrix4(b)}const m=this.getUniqueModelId(e.modelId||e.src),x=new Ar({modelId:m,object:f});this.addModel(x),l(90);const g=x.getBBox();this.loadedModels.length===1&&setTimeout(()=>this.goToHomeView(),0);const w=new p.Vector3;g.getCenter(w),this.cameraManager.setOrbitPoint(w),l(100),this.progressBar?.delayRemoveProgressItem(a),this.dispatchEvent(ce.ModelLoad)}catch(f){throw this.progressBar?.removeProgressItem(a),A.error("[Viewer3d] Failed to load model '"+e.src+"'",f),f}finally{this.spinner.decreaseJobCount()}}setDistanceCullingFactor(e){this.distanceCullingFactor=e}getDistanceCullingFactor(){return this.distanceCullingFactor}setObjectOpacity(e,i){this.loadedModels.forEach(s=>s.setObjectOpacity(e,i)),this.enableRender()}setOtherObjectsOpacity(e,i){this.loadedModels.forEach(s=>{s.setOpacity(i),s.clearObjectOpacity(e)}),this.enableRender()}clearObjectOpacity(e){this.loadedModels.forEach(i=>i.clearObjectOpacity(e)),this.enableRender()}setModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.setOpacity(),this.enableRender()}clearModelOpacity(e){this.loadedModels.find(s=>s.modelId===e)?.clearOpacity(),this.enableRender()}setModelsOpacity(e){this.loadedModels.forEach(i=>i.setOpacity(e)),this.enableRender()}clearModelsOpacity(){this.loadedModels.forEach(e=>e.clearOpacity()),this.enableRender()}setObjectVisible(e,i){this.loadedModels.forEach(s=>s.setObjectVisible(e,i)),this.enableRender()}hideOtherObjects(e){this.loadedModels.forEach(i=>{i.setVisible(!1),i.setObjectVisible(e,!0)}),this.enableRender()}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}enableModelOutline(e,i){this.loadedModels.find(n=>n.modelId===e)?.enableOutline(i),this.enableRender()}enableModelsOutline(e){this.loadedModels.forEach(i=>i.enableOutline(e)),this.enableRender()}setObjectHighlight(e){this.loadedModels.forEach(i=>i.highlightObject(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}hasVisibleObject(){for(const e of this.loadedModels)if(e.hasVisibleObject())return!0;return!1}hasInvisibleObject(){for(const e of this.loadedModels)if(e.hasInvisibleObject())return!0;return!1}enableSsao(e){this.effect.enabled=e,this.effect.renderPassEnabled=e,this.effect.ssaaPassEnabled=e,this.effect.ssaoPassEnabled=e}getSsaoEnabled(){return this.effect.enabled&&this.effect.ssaoPassEnabled}async setEnvironmentData(e){await this.sceneManager.setEnvironmentFromData(e),this.enableRender()}async setEnvironment(e){await this.sceneManager.setEnvironment(e),this.enableRender()}showVertexNormals(e,i=.1){this.effect.showVertexNormals(e,i)}getLights(){return{sun:this.sceneManager.directionalLight,ambient:this.sceneManager.ambientLight,hemisphere:this.sceneManager.hemisphereLight}}debugLights(e){this.sceneManager.debugLights(e)}setModelClipPlanes(e,i){this.loadedModels.find(n=>n.modelId===""+e)?.setClipPlanes(i),this.enableRender()}setGlobalClipPlanes(e){const i=e.length>0;this.sceneManager.enableClipping(i),this.sceneManager.setClipPlanes(e)}}function ao(c){return Object.assign(Object.assign({},{asset:"",version:"",datetime:"",root:"",modelSize:0,generateTool:""}),c)}function oo(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 qu(c){const t={transform:new p.Matrix4,boundingVolume:new p.Box3};return Object.assign(Object.assign({},t),c)}class Wu{constructor(t){y(this,"url");y(this,"metadata");y(this,"statistics");y(this,"view");this.url=t,this.metadata=ao(),this.statistics=oo(),this.view=qu()}async parse(){return await fetch(this.url).then(t=>t.ok?t.json():(A.error('[BimTiles] Failed to request "'+this.url+'", status '+t.status+" : "+t.statusText),Promise.reject(!1))).then(t=>(this.metadata=ao(t.metadata),this.statistics=oo(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 Yu=0;class Xu extends bn{constructor(e,i){super(e);y(this,"name");y(this,"pickUsageScene");y(this,"effect");y(this,"loadedModels");y(this,"selectedObject");y(this,"enableHoverEffect");if(this.name=et.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(wt.Perspective),this.cameraManager.setNavigationMode(dt.Orbit),this.setupDefaultEvents(),this.setDefaultBackground(),this.addEventListener(ce.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===tt.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===tt.Left){let m=this.pickUsageScene;if(h){const g=this.loadedModels.find(M=>M.modelId===""+h?.tilesetId);if(g){const M=g.getObjectByUserId(h.userId);M&&(m=M)}}const x=this.pickManager.pickObject(f,[m]);this.handleAnchorPoint(x)}}),this.inputManager.addEventListener("pointermove",u=>{if(i!==void 0)e=!o(u),i===tt.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),x=this.getHoveredObject();m?(!x||x.tilesetId!==m.tilesetId||x.userId!==m.userId)&&this.setObjectHoveredByUserId(m.tilesetId,m.userId,!0):x&&this.clearHovered()}this.handleMouseMove(u)}),this.inputManager.addEventListener("pointerup",u=>{if(i=void 0,this.cameraManager.setOrbitPointVisible(!1),e){e=!1;return}u.button===tt.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,tt.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){A.warn("Outline for bimtiles is not implemented yet.")}enableModelsOutline(e){A.warn("Outline for bimtiles is not implemented yet.")}setModelVisible(e,i){this.loadedModels.find(n=>n.modelId===e)?.setVisible(i),this.enableRender()}setModelsVisible(e){this.loadedModels.forEach(i=>i.setVisible(e)),this.enableRender()}clearHighlight(){this.loadedModels.forEach(e=>e.clearHighlight()),this.enableRender()}setDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.setDoubleSidedMaterials()),this.enableRender()}revertDoubleSidedMaterials(){this.loadedModels.forEach(e=>e.revertDoubleSidedMaterials()),this.enableRender()}clearSelection(){this.selectedObject instanceof Ht&&(this.selectedObject.selected=!1),this.selectedObject=void 0,this.clearHighlight()}get enableSelection(){return this._enableSelection}set enableSelection(e){e||this.clearSelection(),this._enableSelection=e}flyToUserId(e,i){const s=this.getBoxByUserId(e,i);s&&this.cameraManager.flyToBox(s)}getBoxByUserId(e,i){const s=this.loadedModels.find(n=>n.modelId===""+e);if(s)return s.getBBoxByUserId(i)}handleMouseMove(e){}update3dTiles(){if(!this.camera)return;const e=this.loadedModels.filter(i=>!!i.tilesRenderer);e.length!==0&&(this.camera.updateMatrixWorld(),e.forEach(i=>{i.tilesRenderer.update()}))}async loadModel(e,i){if(e.src.length===0)return Promise.reject();const s=new Wu(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();try{const a=s.getView().boundingVolume.clone();a.applyMatrix4(s.getView().transform);const o=new Br({modelId:""+Yu++,bbox:a},r,s),l=o.getTilesRenderer(),h=l.group;if(l.onBeforeParseTile=()=>{this.spinner.increaseJobCount()},l.onLoadModel=d=>{d.traverse(u=>{!st&&u.matrixAutoUpdate&&(u.matrixAutoUpdate=st,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.dispatchEvent(ce.ModelLoad),Promise.resolve()}return Promise.reject()}finally{this.spinner.decreaseJobCount()}}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 Zu extends Gt{constructor(e,i){if(!i.id)throw new Error("[Plugin] Missing plugin id!");super();y(this,"id");y(this,"viewer");this.id=i.id,this.viewer=e,e.addPlugin(this)}destroy(){this.viewer.removePlugin(this)}}J.install({THREE:p});class Ku extends J{constructor(e,i){super(e,i);y(this,"minZoom");y(this,"draggingSmoothTime");y(this,"dollySpeedBackup");y(this,"azimuthRotateSpeedBackup");y(this,"polarRotateSpeedBackup");y(this,"truckSpeedBackup");y(this,"onKeyDown");y(this,"onKeyUp");y(this,"keyTruckSpeed");y(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 $u{constructor(t,e,i){y(this,"containerOrCanvas");y(this,"glContext");y(this,"camera");y(this,"scene");y(this,"renderer");y(this,"renderTarget");y(this,"controls");y(this,"selectedObject");y(this,"loadedModels");y(this,"pmremGenerator");y(this,"clock");y(this,"viewerMode");y(this,"raycaster");y(this,"savedMaterialsForOpacity");y(this,"jobCount");y(this,"bbox");y(this,"outlineMaterial");y(this,"outlineRoot");y(this,"transparentObjectIds");y(this,"requestAnimationFrameHandle");y(this,"applyOptionsAndAddToScene");y(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(A.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 Q.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,A.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(),A.info("[Viewer] Initialized"),this.animate()}init(){this.initRenderer(),this.initCamera(),this.initControls(),this.initLights(),this.initPointerEvents(),this.scene.add(this.outlineRoot)}initScene(){const t=new p.Scene;return t.background=new p.Color(7112861),t.matrixAutoUpdate=!0,t}isBrowserlessMode(){return this.viewerMode===1}isBrowserMode(){return this.viewerMode===0}initRenderer(){const t={antialias:!0,preserveDrawingBuffer:!0},e=this.isBrowserlessMode();e&&Object.assign(t,{canvas:this.containerOrCanvas,context:this.glContext});let i;try{i=new p.WebGLRenderer(t)}catch(s){if(e||!t.antialias)throw s;i=new p.WebGLRenderer({canvas:this.containerOrCanvas}),A.warn("WebGL context created with fallback settings (antialias disabled).")}if(e){const s=this.containerOrCanvas.width,n=this.containerOrCanvas.height;A.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 Ku(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 Ut().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 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,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,A.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&&Q.revertObjectOpacityById(n,o,this.savedMaterialsForOpacity);const l=Q.setObjectOpacityById(n,o,e,i,s);r.push(...l)}else this.savedMaterialsForOpacity&&Q.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=_e.getScreenCoordinateByEvent(t,this.containerOrCanvas));const i=_e.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(Nt);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=ve.clonedHighlightMaterials(t);e&&(this.selectedObject=t,this.selectedObject.userData.originalMaterial=this.selectedObject.material,this.selectedObject.material=e)}clearSelection(){this.selectObject()}flyToObjects(t){if(!t||t.length===0||!this.camera)return;const e=new p.Box3;t.forEach(n=>{const r=_t.getBoundingBox(n);e.union(r)});const i=new p.Sphere;e.getBoundingSphere(i),this.controls?.fitToSphere(i,!0)}flyToObject(t){this.flyToObjects([t])}flyToSelectedObject(){this.selectedObject&&this.flyToObject(this.selectedObject)}flyTo(t,e,i){const s=this.camera,n=this.controls;if(!s||!n)return;t=Array.isArray(t)?new p.Vector3(t[0],t[1],t[2]):t,e=Array.isArray(e)?new p.Vector3(e[0],e[1],e[2]):e;const r=t,a=e;A.info("[Viewer] flyTo: ",N.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){ds.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=>N.numberToString(f);A.info("[Viewer] BBox's longest side is: "+u(o)),i>h&&(A.warn("[Viewer] camera.near("+u(i)+") shouldn't bigger than "+u(h)+", will change it!"),t.near=h),s<d&&(A.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;Q.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||(A.warn("[Viewer] The ModelId of "+a+" has no corresponding model."),l=this.scene),l.traverse(h=>{if(Fr.includes(r.id,Fr.get(h.userData,"UniqueId"))){const d=this.getMeshes(h);n=n.concat(d)}})}),n.length>0){n.forEach(a=>{const o=Q.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;Q.revertAppliedMaterialToObjectById(this.scene,o,r)}),this.transparentObjectIds=r,this.flyToObjects(n)}else A.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)},Ju=()=>fl()!==dl?(pl(),!0):!1;Object.defineProperty(exports,"Mesh",{enumerable:!0,get:()=>L.Mesh});exports.BaseDxfCompareHelper=ol;exports.BaseViewer=bn;exports.BimTilesModel=Br;exports.BimTilesRenderer=Wo;exports.BimTilesViewer=Xu;exports.BinaryReader=ys;exports.BoxSelectHelper=mn;exports.ByBlock=us;exports.ByLayer=_r;exports.CSS2DObjectUtils=Ph;exports.CameraProjection=wt;exports.CancelablePromise=Sh;exports.CanvasRender=ms;exports.ColorUtils=Di;exports.CommonUtils=N;exports.CompareDrawable=vt;exports.Container=kr;exports.ControlsMode=dt;exports.CoordinateUtils=_e;exports.DecimalPrecisionRange=go;exports.DefaultCameraFar=rn;exports.DefaultCameraFov=bo;exports.DefaultCameraNear=nn;exports.DefaultLanguage=yo;exports.DefaultOpacity=Or;exports.DefaultViewer3dConfig=lu;exports.DeviceUtils=De;exports.Drawable=Ht;exports.DrawableList=gs;exports.DxfChangeType=Ge;exports.DxfCompare=ht;exports.DxfCompareHelper=Fu;exports.DxfCompareMarkupManager=yr;exports.DxfLoader=Z;exports.DxfParser=Lo;exports.DxfRenderOrder=be;exports.DxfSplitter=br;exports.DxfUtils=Ct;exports.EdgeUtils=wo;exports.Event=Gt;exports.ExportUtils=fr;exports.FontManager=bt;exports.FpsUtils=Rh;exports.GenerateMeshBvhWorker=tl;exports.GeometryUtils=G;exports.GroundPlaneRenderOrder=al;exports.HighlightColor=Er;exports.HighlightColorRgba=Ah;exports.IconfontClass=Ih;exports.IconfontClass2=Bh;exports.InputManager=rl;exports.InstantiateHelper=gu;exports.LayerForHitableObjects=xo;exports.LayerForSelectableObjects=Nt;exports.LayerForSnapableObjects=qe;exports.Line=rc;exports.LinePatternShaders=Io;exports.LoadingHelper=Ut;exports.MaterialUtils=ve;exports.MathUtils=V;exports.MatrixAutoUpdate=st;exports.MergeUtils=me;exports.MeshBvhHelper=Lr;exports.MobileTouchHelperDrawable=ku;exports.Model=xn;exports.Model2d=Li;exports.Model3d=Ar;exports.NestedCompareTypes=ss;exports.OSnapHelper=Pu;exports.OSnapIconSize=qh;exports.OSnapMarkerType=Ot;exports.OSnapType=il;exports.ObjectPixelSizeHelper=vu;exports.ObjectUtils=Q;exports.Offset=Hu;exports.OrbitControls=Zo;exports.OutlineColorRgba=sn;exports.PickMarkupHelper=_u;exports.PlanControls=Ko;exports.Plugin=Zu;exports.Points=lh;exports.PolygonUtils=Hh;exports.ProgressBar=Dr;exports.RafHelper=Qo;exports.SVGObjectUtils=Wh;exports.SceneUtils=_t;exports.SectionUtils=Vt;exports.ShaderChunk=Ch;exports.SimplifyUtils=Gh;exports.SnapDrawable=Ae;exports.Spinner=Yo;exports.TextSearchHelper=xr;exports.TextureUtils=ds;exports.ThresholdAngleForEdge=Pr;exports.UnitConversionByMeter=pr;exports.UnitLabels=To;exports.UnitScaleConversion=od;exports.UnitScaleToMeter=gr;exports.Units=Qe;exports.Viewer2d=Rr;exports.Viewer3d=Gu;exports.Viewer3dLite=$u;exports.Viewer3dUtils=Zh;exports.ViewerEvent=ce;exports.ViewerMode=hl;exports.ViewerName=et;exports.Views=So;exports.ZoomToRectHelper=nl;exports.bspline=Oo;exports.checkIsNewVersion=Ju;exports.cn=Mo;exports.createHatchPatternShaderMaterial=Bo;exports.decodeDxfTextCharacterCodes=Po;exports.decodeDxfTextMbcsCharacterCodes=Ao;exports.decodeDxfTextUnicodeCodePoints=_o;exports.en=vo;exports.getLengthValueByUnit=Xh;exports.getUnitStr=mr;exports.getVersionFromLocalStorage=fl;exports.i18n=ze;exports.log=A;exports.parseDxfMTextContent=ns;exports.parseDxfTextContent=an;exports.round10=Eo;exports.setIcon=Oh;exports.setLogLevel=mo;exports.setVersionToLocalStorage=pl;exports.showPrecisionValue=_h;
|